(taskId: string, getAppState: () => {
tasks?: Record<string, TaskState>;
}, timeoutMs: number, abortController?: AbortController)
| 134 | |
| 135 | // Wait for task to complete |
| 136 | async 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 | } |
| 162 | export const TaskOutputTool: Tool<InputSchema, TaskOutputToolOutput> = buildTool({ |
| 163 | name: TASK_OUTPUT_TOOL_NAME, |
| 164 | searchHint: 'read output/logs from a background task', |
no test coverage detected