(input: {
toolCallId: string
status: Extract<CopilotAsyncToolStatus, 'completed' | 'failed' | 'cancelled'>
result?: AsyncCompletionData | null
error?: string | null
})
| 372 | } |
| 373 | |
| 374 | export async function completeAsyncToolCall(input: { |
| 375 | toolCallId: string |
| 376 | status: Extract<CopilotAsyncToolStatus, 'completed' | 'failed' | 'cancelled'> |
| 377 | result?: AsyncCompletionData | null |
| 378 | error?: string | null |
| 379 | }) { |
| 380 | const existing = await getAsyncToolCall(input.toolCallId) |
| 381 | |
| 382 | if (!existing) { |
| 383 | logger.warn('completeAsyncToolCall called before pending row existed', { |
| 384 | toolCallId: input.toolCallId, |
| 385 | status: input.status, |
| 386 | }) |
| 387 | return null |
| 388 | } |
| 389 | |
| 390 | if (isTerminalAsyncStatus(existing.status) || isDeliveredAsyncStatus(existing.status)) { |
| 391 | return existing |
| 392 | } |
| 393 | |
| 394 | return markAsyncToolStatus(input.toolCallId, input.status, { |
| 395 | claimedBy: null, |
| 396 | claimedAt: null, |
| 397 | result: input.result ?? null, |
| 398 | error: input.error ?? null, |
| 399 | completedAt: new Date(), |
| 400 | }) |
| 401 | } |
| 402 | |
| 403 | export async function markAsyncToolDelivered(toolCallId: string) { |
| 404 | return markAsyncToolStatus(toolCallId, ASYNC_TOOL_STATUS.delivered, { |
no test coverage detected