Files
simstudioai--sim/apps/sim/lib/copilot/tool-executor/register-handlers.ts
T
wehub-resource-sync d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

207 lines
7.3 KiB
TypeScript

import { createLogger } from '@sim/logger'
import {
CheckDeploymentStatus,
CompleteScheduledTask,
CreateWorkflow,
CreateWorkspaceMcpServer,
DeleteWorkflow,
DeleteWorkspaceMcpServer,
DeployApi,
DeployChat,
DeployCustomBlock,
DeployMcp,
DiffWorkflows,
FunctionExecute,
GenerateApiKey,
GetBlockOutputs,
GetBlockUpstreamReferences,
GetDeployedWorkflowState,
GetDeploymentLog,
GetPlatformActions,
GetWorkflowData,
GetWorkflowRunOptions,
Glob as GlobTool,
Grep as GrepTool,
ListIntegrationTools,
ListUserWorkspaces,
ListWorkspaceMcpServers,
LoadDeployment,
ManageCredential,
ManageCustomTool,
ManageFolder,
ManageMcpTool,
ManageScheduledTask,
ManageSkill,
MaterializeFile,
MoveWorkflow,
OauthGetAuthLink,
OauthRequestAccess,
OpenResource,
PromoteToLive,
Read as ReadTool,
Redeploy,
RenameWorkflow,
RestoreResource,
RunBlock,
RunFromBlock,
RunWorkflow,
RunWorkflowUntilBlock,
SetBlockEnabled,
SetGlobalWorkflowVariables,
UpdateDeploymentVersion,
UpdateScheduledTaskHistory,
UpdateWorkspaceMcpServer,
} from '@/lib/copilot/generated/tool-catalog-v1'
import { createServerToolHandler } from '@/lib/copilot/tools/registry/server-tool-adapter'
import { getRegisteredServerToolNames } from '@/lib/copilot/tools/server/router'
import { executeDeployCustomBlock } from '../tools/handlers/deployment/custom-block'
import {
executeDeployApi,
executeDeployChat,
executeDeployMcp,
executeRedeploy,
} from '../tools/handlers/deployment/deploy'
import {
executeCheckDeploymentStatus,
executeCreateWorkspaceMcpServer,
executeDeleteWorkspaceMcpServer,
executeDiffWorkflows,
executeGetDeploymentLog,
executeListWorkspaceMcpServers,
executeLoadDeployment,
executePromoteToLive,
executeUpdateDeploymentVersion,
executeUpdateWorkspaceMcpServer,
} from '../tools/handlers/deployment/manage'
import { executeFunctionExecute } from '../tools/handlers/function-execute'
import { executeListIntegrationTools } from '../tools/handlers/integration-tools'
import {
executeCompleteJob,
executeManageJob,
executeUpdateJobHistory,
} from '../tools/handlers/jobs'
import { executeManageCredential } from '../tools/handlers/management/manage-credential'
import { executeManageCustomTool } from '../tools/handlers/management/manage-custom-tool'
import { executeManageMcpTool } from '../tools/handlers/management/manage-mcp-tool'
import { executeManageSkill } from '../tools/handlers/management/manage-skill'
import { executeMaterializeFile } from '../tools/handlers/materialize-file'
import { executeOAuthGetAuthLink, executeOAuthRequestAccess } from '../tools/handlers/oauth'
import { executeGetPlatformActions } from '../tools/handlers/platform'
import { executeOpenResource } from '../tools/handlers/resources'
import { executeRestoreResource } from '../tools/handlers/restore-resource'
import { executeVfsGlob, executeVfsGrep, executeVfsRead } from '../tools/handlers/vfs'
import {
executeCreateWorkflow,
executeDeleteWorkflow,
executeGenerateApiKey,
executeManageFolder,
executeMoveWorkflow,
executeRenameWorkflow,
executeRunBlock,
executeRunFromBlock,
executeRunWorkflow,
executeRunWorkflowUntilBlock,
executeSetBlockEnabled,
executeSetGlobalWorkflowVariables,
} from '../tools/handlers/workflow/mutations'
import {
executeGetBlockOutputs,
executeGetBlockUpstreamReferences,
executeGetDeployedWorkflowState,
executeGetWorkflowData,
executeGetWorkflowRunOptions,
executeListUserWorkspaces,
} from '../tools/handlers/workflow/queries'
import { registerHandlers } from './executor'
import type { ToolHandler } from './types'
const logger = createLogger('ToolHandlerRegistration')
let registered = false
export function ensureHandlersRegistered(): void {
if (registered) return
registered = true
registerHandlers(buildHandlerMap())
logger.info('Tool handlers registered')
}
// Bridge: handler implementations accept specific param types (e.g. CreateWorkflowParams)
// while ToolHandler accepts Record<string, unknown>. The params are cast internally by
// each implementation. ExecutionContext extends ToolExecutionContext so context is compatible.
function h(fn: (params: any, context: any) => Promise<any>): ToolHandler {
return fn as ToolHandler
}
function buildHandlerMap(): Record<string, ToolHandler> {
return {
[ListUserWorkspaces.id]: h((_p, c) => executeListUserWorkspaces(c)),
[GetWorkflowData.id]: h(executeGetWorkflowData),
[GetWorkflowRunOptions.id]: h(executeGetWorkflowRunOptions),
[GetBlockOutputs.id]: h(executeGetBlockOutputs),
[GetBlockUpstreamReferences.id]: h(executeGetBlockUpstreamReferences),
[GetDeployedWorkflowState.id]: h(executeGetDeployedWorkflowState),
[CreateWorkflow.id]: h(executeCreateWorkflow),
[DeleteWorkflow.id]: h(executeDeleteWorkflow),
[RenameWorkflow.id]: h(executeRenameWorkflow),
[MoveWorkflow.id]: h(executeMoveWorkflow),
[ManageFolder.id]: h(executeManageFolder),
[RunWorkflow.id]: h(executeRunWorkflow),
[RunWorkflowUntilBlock.id]: h(executeRunWorkflowUntilBlock),
[RunFromBlock.id]: h(executeRunFromBlock),
[RunBlock.id]: h(executeRunBlock),
[SetBlockEnabled.id]: h(executeSetBlockEnabled),
[GenerateApiKey.id]: h(executeGenerateApiKey),
[SetGlobalWorkflowVariables.id]: h(executeSetGlobalWorkflowVariables),
[DeployApi.id]: h(executeDeployApi),
[DeployChat.id]: h(executeDeployChat),
[DeployMcp.id]: h(executeDeployMcp),
[DeployCustomBlock.id]: h(executeDeployCustomBlock),
[Redeploy.id]: h(executeRedeploy),
[CheckDeploymentStatus.id]: h(executeCheckDeploymentStatus),
[ListWorkspaceMcpServers.id]: h(executeListWorkspaceMcpServers),
[CreateWorkspaceMcpServer.id]: h(executeCreateWorkspaceMcpServer),
[UpdateWorkspaceMcpServer.id]: h(executeUpdateWorkspaceMcpServer),
[DeleteWorkspaceMcpServer.id]: h(executeDeleteWorkspaceMcpServer),
[GetDeploymentLog.id]: h(executeGetDeploymentLog),
[DiffWorkflows.id]: h(executeDiffWorkflows),
[LoadDeployment.id]: h(executeLoadDeployment),
[PromoteToLive.id]: h(executePromoteToLive),
[UpdateDeploymentVersion.id]: h(executeUpdateDeploymentVersion),
[ManageScheduledTask.id]: h(executeManageJob),
[CompleteScheduledTask.id]: h(executeCompleteJob),
[UpdateScheduledTaskHistory.id]: h(executeUpdateJobHistory),
[GrepTool.id]: h(executeVfsGrep),
[GlobTool.id]: h(executeVfsGlob),
[ReadTool.id]: h(executeVfsRead),
[ManageCustomTool.id]: h(executeManageCustomTool),
[ManageMcpTool.id]: h(executeManageMcpTool),
[ManageSkill.id]: h(executeManageSkill),
[ManageCredential.id]: h(executeManageCredential),
[OauthGetAuthLink.id]: h(executeOAuthGetAuthLink),
[OauthRequestAccess.id]: h(executeOAuthRequestAccess),
[OpenResource.id]: h(executeOpenResource),
[RestoreResource.id]: h(executeRestoreResource),
[GetPlatformActions.id]: h(executeGetPlatformActions),
[ListIntegrationTools.id]: h(executeListIntegrationTools),
[MaterializeFile.id]: h(executeMaterializeFile),
[FunctionExecute.id]: h(executeFunctionExecute),
...buildServerToolHandlers(),
}
}
function buildServerToolHandlers(): Record<string, ToolHandler> {
const toolNames = getRegisteredServerToolNames()
const handlers: Record<string, ToolHandler> = {}
for (const toolId of toolNames) {
handlers[toolId] = createServerToolHandler(toolId)
}
return handlers
}