MCPcopy Create free account
hub / github.com/Noumena-Network/code / waitForTaskCompletion

Function waitForTaskCompletion

src/tools/TaskOutputTool/TaskOutputTool.tsx:136–161  ·  view source on GitHub ↗
(taskId: string, getAppState: () => {
  tasks?: Record<string, TaskState>;
}, timeoutMs: number, abortController?: AbortController)

Source from the content-addressed store, hash-verified

134
135// Wait for task to complete
136async function waitForTaskCompletion(taskId: string, getAppState: () => {
137 tasks?: Record<string, TaskState>;
138}, timeoutMs: number, abortController?: AbortController): Promise<TaskState | null> {
139 const startTime = Date.now();
140 while (Date.now() - startTime < timeoutMs) {
141 // Check abort signal
142 if (abortController?.signal.aborted) {
143 throw new AbortError();
144 }
145 const state = getAppState();
146 const task = state.tasks?.[taskId] as TaskState | undefined;
147 if (!task) {
148 return null;
149 }
150 if (task.status !== 'running' && task.status !== 'pending') {
151 return task;
152 }
153
154 // Wait before polling again
155 await sleep(100);
156 }
157
158 // Timeout - return current state
159 const finalState = getAppState();
160 return finalState.tasks?.[taskId] as TaskState ?? null;
161}
162export const TaskOutputTool: Tool<InputSchema, TaskOutputToolOutput> = buildTool({
163 name: TASK_OUTPUT_TOOL_NAME,
164 searchHint: 'read output/logs from a background task',

Callers 1

callFunction · 0.85

Calls 2

getAppStateFunction · 0.50
sleepFunction · 0.50

Tested by

no test coverage detected