* Persist terminal durable tool status, then publish a wakeup event. * * `background` remains a live detach signal in the current browser workflow * runtime, so it should not rewrite the durable async row.
( existing: NonNullable<Awaited<ReturnType<typeof getAsyncToolCall>>>, status: AsyncConfirmationStatus, message?: string, data?: AsyncCompletionData )
| 38 | * runtime, so it should not rewrite the durable async row. |
| 39 | */ |
| 40 | async function updateToolCallStatus( |
| 41 | existing: NonNullable<Awaited<ReturnType<typeof getAsyncToolCall>>>, |
| 42 | status: AsyncConfirmationStatus, |
| 43 | message?: string, |
| 44 | data?: AsyncCompletionData |
| 45 | ): Promise<boolean> { |
| 46 | const toolCallId = existing.toolCallId |
| 47 | if (status === ASYNC_TOOL_CONFIRMATION_STATUS.background) { |
| 48 | publishToolConfirmation({ |
| 49 | toolCallId, |
| 50 | status, |
| 51 | message: message || undefined, |
| 52 | timestamp: new Date().toISOString(), |
| 53 | data, |
| 54 | }) |
| 55 | return true |
| 56 | } |
| 57 | const durableStatus = |
| 58 | status === 'success' |
| 59 | ? ASYNC_TOOL_STATUS.completed |
| 60 | : status === 'cancelled' |
| 61 | ? ASYNC_TOOL_STATUS.cancelled |
| 62 | : status === 'error' |
| 63 | ? ASYNC_TOOL_STATUS.failed |
| 64 | : ASYNC_TOOL_STATUS.pending |
| 65 | try { |
| 66 | if ( |
| 67 | durableStatus === ASYNC_TOOL_STATUS.completed || |
| 68 | durableStatus === ASYNC_TOOL_STATUS.failed || |
| 69 | durableStatus === ASYNC_TOOL_STATUS.cancelled |
| 70 | ) { |
| 71 | await completeAsyncToolCall({ |
| 72 | toolCallId, |
| 73 | status: durableStatus, |
| 74 | result: data ?? null, |
| 75 | error: status === 'success' ? null : message || status, |
| 76 | }) |
| 77 | } else if (existing.runId) { |
| 78 | await upsertAsyncToolCall({ |
| 79 | runId: existing.runId, |
| 80 | checkpointId: existing.checkpointId ?? null, |
| 81 | toolCallId, |
| 82 | toolName: existing.toolName || 'client_tool', |
| 83 | args: (existing.args as Record<string, unknown> | null) ?? {}, |
| 84 | status: durableStatus, |
| 85 | }) |
| 86 | } |
| 87 | publishToolConfirmation({ |
| 88 | toolCallId, |
| 89 | status, |
| 90 | message: message || undefined, |
| 91 | timestamp: new Date().toISOString(), |
| 92 | data, |
| 93 | }) |
| 94 | return true |
| 95 | } catch (error) { |
| 96 | logger.error('Failed to update tool call status', { |
| 97 | toolCallId, |
no test coverage detected