MCPcopy
hub / github.com/coder/mux / createWorkflowRunTool

Function createWorkflowRunTool

src/node/services/tools/workflow_run.ts:81–186  ·  view source on GitHub ↗
(config: ToolConfiguration)

Source from the content-addressed store, hash-verified

79}
80
81export const createWorkflowRunTool: ToolFactory = (config: ToolConfiguration) => {
82 return tool({
83 description: TOOL_DEFINITIONS.workflow_run.description,
84 inputSchema: TOOL_DEFINITIONS.workflow_run.schema,
85 execute: async (args, options): Promise<unknown> => {
86 const workspaceId = requireWorkspaceId(config, "workflow_run");
87 const workflowService = requireWorkflowService(config);
88 const toolCallId = options.toolCallId;
89
90 const script = await resolveWorkflowScript({
91 scriptPath: args.script_path,
92 scriptSource: args.script_source,
93 runtime: config.runtime,
94 workspacePath: config.cwd,
95 projectTrusted: config.trusted === true,
96 ...(config.agentSkillsRoots != null ? { roots: config.agentSkillsRoots } : {}),
97 });
98 const createdRun: { id: string | null } = { id: null };
99 const startInput = {
100 script,
101 workspaceId,
102 projectTrusted: config.trusted === true,
103 args: args.args ?? {},
104 onRunCreated: async (event: { runId: string; run: unknown }) => {
105 createdRun.id = event.runId;
106 await emitWorkflowRunAttachedEvent({
107 config,
108 workspaceId,
109 toolCallId,
110 runId: event.runId,
111 run: event.run,
112 });
113 },
114 };
115 const invocationStartedAtMs = Date.now();
116 let result: { runId: string; status: string; result: unknown };
117 try {
118 result =
119 args.run_in_background === true
120 ? await requireBackgroundWorkflowStart(workflowService)({
121 ...startInput,
122 // Background runs are non-blocking; terminal result is delivered by
123 // AIService.onBackgroundRunTerminal rather than a forced task_await.
124 attentionPolicy: "notify_on_terminal",
125 })
126 : await requireForegroundWorkflowStart(workflowService)({
127 ...startInput,
128 ...(options.abortSignal != null ? { abortSignal: options.abortSignal } : {}),
129 });
130 } catch (error: unknown) {
131 const createdRunId = createdRun.id;
132 if (createdRunId == null) {
133 throw error;
134 }
135 if (workflowService.getRun == null) {
136 throw new Error(
137 `${getErrorMessage(error)} (workflow_run created durable run ${createdRunId} before failing)`
138 );

Callers 2

getToolsForModelFunction · 0.90

Tested by

no test coverage detected