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

Function createTaskAwaitTool

src/node/services/tools/task_await.ts:243–994  ·  view source on GitHub ↗
(config: ToolConfiguration)

Source from the content-addressed store, hash-verified

241}
242
243export const createTaskAwaitTool: ToolFactory = (config: ToolConfiguration) => {
244 return tool({
245 description: TOOL_DEFINITIONS.task_await.description,
246 inputSchema: TOOL_DEFINITIONS.task_await.schema,
247 execute: async (args, { abortSignal }): Promise<unknown> => {
248 const workspaceId = requireWorkspaceId(config, "task_await");
249 const taskService = requireTaskService(config, "task_await");
250
251 const timeoutMs = coerceTimeoutMs(args.timeout_secs);
252 // Preserve the documented 600s default when the model sends null
253 // (Zod .default() only replaces undefined, not null).
254 const timeoutSecsForBash = args.timeout_secs ?? 600;
255
256 const requestedIds: string[] | null =
257 args.task_ids && args.task_ids.length > 0 ? args.task_ids : null;
258
259 const activeDescendantAgentTaskIds = taskService.listActiveDescendantAgentTaskIds(
260 workspaceId,
261 { excludeWorkflowTasks: true }
262 );
263 const isWorkflowOwnedDescendantAgentTask = async (taskId: string): Promise<boolean> =>
264 (await taskService.isWorkflowOwnedDescendantAgentTask?.(workspaceId, taskId)) ?? false;
265
266 const listInScopeBackgroundBashTaskIds = async (): Promise<string[]> => {
267 if (!config.backgroundProcessManager) {
268 return [];
269 }
270
271 const bashTaskIds: string[] = [];
272 const processes = await config.backgroundProcessManager.list();
273 for (const proc of processes) {
274 if (proc.status !== "running") continue;
275 const inScope =
276 proc.workspaceId === workspaceId ||
277 (await taskService.isDescendantAgentTask(workspaceId, proc.workspaceId));
278 if (!inScope) continue;
279 if (
280 proc.workspaceId !== workspaceId &&
281 (await isWorkflowOwnedDescendantAgentTask(proc.workspaceId))
282 ) {
283 continue;
284 }
285
286 bashTaskIds.push(toBashTaskId(proc.id));
287 }
288
289 return dedupeStrings(bashTaskIds);
290 };
291 const listInScopeWorkflowRunIds = async (): Promise<string[]> => {
292 if (config.workflowService?.listRuns == null) {
293 return [];
294 }
295
296 const workflowRunIds: string[] = [];
297 const runs = await config.workflowService.listRuns({ workspaceId });
298 for (const rawRun of runs) {
299 const parsed = WorkflowRunRecordSchema.safeParse(rawRun);
300 if (

Callers 3

getToolsForModelFunction · 0.90
task.bash.test.tsFile · 0.90
task_await.test.tsFile · 0.90

Calls 15

requireWorkspaceIdFunction · 0.90
requireTaskServiceFunction · 0.90
dedupeStringsFunction · 0.90
isWorkflowRunTaskIdFunction · 0.90
isWorkspaceTurnTaskIdFunction · 0.90
getErrorMessageFunction · 0.90
parseToolResultFunction · 0.90
coerceTimeoutMsFunction · 0.85
awaitOneFunction · 0.85

Tested by

no test coverage detected