( opts: SessionChatStoreOptions, input: ChatToolStatusUpdate, )
| 496 | } |
| 497 | |
| 498 | export function appendSessionToolStatus( |
| 499 | opts: SessionChatStoreOptions, |
| 500 | input: ChatToolStatusUpdate, |
| 501 | ): void { |
| 502 | const row = listSessionChatMessages(opts, input.designId).find( |
| 503 | (message) => message.seq === input.seq, |
| 504 | ); |
| 505 | if (row?.kind !== 'tool_call') return; |
| 506 | const manager = openSession(opts, input.designId); |
| 507 | const toolName = |
| 508 | typeof (row.payload as { toolName?: unknown } | null)?.toolName === 'string' |
| 509 | ? ((row.payload as { toolName: string }).toolName ?? 'unknown') |
| 510 | : 'unknown'; |
| 511 | const stored: StoredToolStatusUpdate = { |
| 512 | schemaVersion: 1, |
| 513 | seq: input.seq, |
| 514 | status: input.status, |
| 515 | ...(input.result !== undefined |
| 516 | ? { result: compactToolResultForHistory(toolName, input.result) } |
| 517 | : {}), |
| 518 | ...(input.durationMs !== undefined ? { durationMs: input.durationMs } : {}), |
| 519 | ...(input.errorMessage !== undefined ? { errorMessage: input.errorMessage } : {}), |
| 520 | }; |
| 521 | const entryId = manager.appendCustomEntry(CHAT_TOOL_STATUS_CUSTOM_TYPE, stored); |
| 522 | const entry = manager.getEntry(entryId); |
| 523 | flushSession(manager); |
| 524 | touchDesignActivity(opts.db, input.designId, entry?.timestamp ?? new Date().toISOString()); |
| 525 | } |
| 526 | |
| 527 | export function readSessionDesignBrief( |
| 528 | opts: SessionChatStoreOptions, |
no test coverage detected