(calls: Call[], value: unknown, now: number)
| 4 | import { writeFile } from "node:fs/promises"; |
| 5 | |
| 6 | export function observe(calls: Call[], value: unknown, now: number): void { |
| 7 | const event = record(value); |
| 8 | if (event.type !== "tool.execution_start" && event.type !== "tool.execution_complete") return; |
| 9 | const data = record(event.data); |
| 10 | if (typeof data.toolCallId !== "string") throw new Error("SDK tool event is missing its call ID"); |
| 11 | const id = `tool:${data.toolCallId}`; |
| 12 | if (event.type === "tool.execution_start") { |
| 13 | if (calls.some(call => call.id === id)) throw new Error("Duplicate SDK tool call ID"); |
| 14 | calls.push({ id, kind: "tool", arguments: data.arguments, startedAt: now }); |
| 15 | } else { |
| 16 | const call = calls.find(item => item.id === id); |
| 17 | if (!call) throw new Error("SDK completed an unknown tool call"); |
| 18 | call.endedAt = now; |
| 19 | call.success = data.success === true; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | export class CommandObserver { |
| 24 | private readonly server: Server; |
no test coverage detected