MCPcopy Create free account
hub / github.com/cortexkit/magic-context / tokensToPiUsage

Function tokensToPiUsage

packages/cli/src/commands/migrate.ts:300–314  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

298 * Pi's footer aggregator handles missing cost gracefully.
299 */
300function 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
316function makeMessageEntry(
317 role: "user" | "assistant",

Callers 1

buildPiEntriesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected