* Build a Pi-shaped `usage` object from OpenCode `message.tokens`. * * OpenCode shape: `{ total, input, output, reasoning, cache: { read, write } }`. * Pi shape: `{ input, output, cacheRead, cacheWrite, totalTokens, cost: {...} }`. * * Pi's interactive footer reads `entry.message.usage.input` o
(tokens: OpenCodeMessageTokens | undefined)
| 298 | * Pi's footer aggregator handles missing cost gracefully. |
| 299 | */ |
| 300 | function tokensToPiUsage(tokens: OpenCodeMessageTokens | undefined): Record<string, unknown> { |
| 301 | const input = tokens?.input ?? 0; |
| 302 | const output = tokens?.output ?? 0; |
| 303 | const cacheRead = tokens?.cache?.read ?? 0; |
| 304 | const cacheWrite = tokens?.cache?.write ?? 0; |
| 305 | const total = tokens?.total ?? input + output + cacheRead + cacheWrite; |
| 306 | return { |
| 307 | input, |
| 308 | output, |
| 309 | cacheRead, |
| 310 | cacheWrite, |
| 311 | totalTokens: total, |
| 312 | cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }, |
| 313 | }; |
| 314 | } |
| 315 | |
| 316 | function makeMessageEntry( |
| 317 | role: "user" | "assistant", |