(
toolCallId: string,
status: CopilotAsyncToolStatus,
updates: {
claimedBy?: string | null
claimedAt?: Date | null
result?: AsyncCompletionData | null
error?: string | null
completedAt?: Date | null
} = {}
)
| 320 | } |
| 321 | |
| 322 | async function markAsyncToolStatus( |
| 323 | toolCallId: string, |
| 324 | status: CopilotAsyncToolStatus, |
| 325 | updates: { |
| 326 | claimedBy?: string | null |
| 327 | claimedAt?: Date | null |
| 328 | result?: AsyncCompletionData | null |
| 329 | error?: string | null |
| 330 | completedAt?: Date | null |
| 331 | } = {} |
| 332 | ) { |
| 333 | return withDbSpan( |
| 334 | TraceSpan.CopilotAsyncRunsMarkAsyncToolStatus, |
| 335 | 'UPDATE', |
| 336 | 'copilot_async_tool_calls', |
| 337 | { |
| 338 | [TraceAttr.ToolCallId]: toolCallId, |
| 339 | [TraceAttr.CopilotAsyncToolStatus]: status, |
| 340 | [TraceAttr.CopilotAsyncToolHasError]: !!updates.error, |
| 341 | [TraceAttr.CopilotAsyncToolClaimedBy]: updates.claimedBy ?? undefined, |
| 342 | }, |
| 343 | async () => { |
| 344 | const claimedAt = |
| 345 | updates.claimedAt !== undefined |
| 346 | ? updates.claimedAt |
| 347 | : status === 'running' && updates.claimedBy |
| 348 | ? new Date() |
| 349 | : undefined |
| 350 | |
| 351 | const [row] = await db |
| 352 | .update(copilotAsyncToolCalls) |
| 353 | .set({ |
| 354 | status, |
| 355 | claimedBy: updates.claimedBy, |
| 356 | claimedAt, |
| 357 | result: updates.result, |
| 358 | error: updates.error, |
| 359 | completedAt: updates.completedAt, |
| 360 | updatedAt: new Date(), |
| 361 | }) |
| 362 | .where(eq(copilotAsyncToolCalls.toolCallId, toolCallId)) |
| 363 | .returning() |
| 364 | |
| 365 | return row ?? null |
| 366 | } |
| 367 | ) |
| 368 | } |
| 369 | |
| 370 | export async function markAsyncToolRunning(toolCallId: string, claimedBy: string) { |
| 371 | return markAsyncToolStatus(toolCallId, 'running', { claimedBy }) |
no test coverage detected