(taskId: string, getAppState: () => {
tasks?: Record<string, TaskState>;
}, timeoutMs: number, abortController?: AbortController)
| 116 | |
| 117 | // Wait for task to complete |
| 118 | async function waitForTaskCompletion(taskId: string, getAppState: () => { |
| 119 | tasks?: Record<string, TaskState>; |
| 120 | }, timeoutMs: number, abortController?: AbortController): Promise<TaskState | null> { |
| 121 | const startTime = Date.now(); |
| 122 | while (Date.now() - startTime < timeoutMs) { |
| 123 | // Check abort signal |
| 124 | if (abortController?.signal.aborted) { |
| 125 | throw new AbortError(); |
| 126 | } |
| 127 | const state = getAppState(); |
| 128 | const task = state.tasks?.[taskId] as TaskState | undefined; |
| 129 | if (!task) { |
| 130 | return null; |
| 131 | } |
| 132 | if (task.status !== 'running' && task.status !== 'pending') { |
| 133 | return task; |
| 134 | } |
| 135 | |
| 136 | // Wait before polling again |
| 137 | await sleep(100); |
| 138 | } |
| 139 | |
| 140 | // Timeout - return current state |
| 141 | const finalState = getAppState(); |
| 142 | return finalState.tasks?.[taskId] as TaskState ?? null; |
| 143 | } |
| 144 | export const TaskOutputTool: Tool<InputSchema, TaskOutputToolOutput> = buildTool({ |
| 145 | name: TASK_OUTPUT_TOOL_NAME, |
| 146 | searchHint: 'read output/logs from a background task', |
no test coverage detected