mirror of
https://github.com/teamchong/pxpipe.git
synced 2026-07-22 02:02:51 +02:00
6cbdea584b
Adds a third tee branch in createProxy that walks the response body and counts Unicode code units across text_delta / thinking_delta / input_json_delta / tool_use blocks, plus a redacted_thinking block count. Same shape on streaming (SSE) and non-stream (content[]) responses. Numbers are independent of Anthropic's usage.output_tokens - they give a real ruler against the redacted_thinking-inflated bill that surfaced in the May-2026 weekly-meter audit (#22). Wiring: OutputMeasurement type in proxy.ts (textChars, thinkingChars, toolUseChars, redactedBlockCount) teeForUsage now returns measurementPromise alongside usagePromise + errorBodyPromise; Promise.all in handle() awaits all three ProxyEvent gains optional measurement: OutputMeasurement TrackEvent gains text_chars_measured / thinking_chars_measured / tool_use_chars_measured / redacted_block_count_measured (optional, non-breaking JSONL shape) toTrackEvent() copies them through Tests (6 new in proxy-usage.test.ts): text_delta count across multi-event SSE message_delta output_tokens overrides message_start placeholder thinking_delta + redacted_thinking block count tool_use input_json_delta reassembly non-stream content[] walks same shape 5xx no-body path leaves measurement undefined 288 tests pass, tsc --noEmit clean, dist/node.js builds. Dashboard surfacing lands in a follow-up so the wire-up stays reviewable. Refs #22