mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 21:30:17 +08:00
693c36a12a
* fix(dashscope): enhance usage parsing robustness to prevent VSCode crashes Enhanced build_anthropic_usage_from_responses() to handle null, missing, empty, and partial usage fields gracefully. This prevents VSCode Extension crashes with "Cannot read properties of null (reading 'output_tokens')" when connecting to DashScope (Alibaba Cloud Bailian) models. Changes: - Added defensive null checks and empty object detection - Implemented OpenAI field name fallbacks (prompt_tokens/completion_tokens) - Added comprehensive logging for malformed usage scenarios - Fixed streaming SSE event handlers with null-safe usage access - Preserved cache token fields even when input/output tokens are missing This ensures the proxy never crashes on malformed Responses API usage objects, returning valid Anthropic-compatible usage structures (input_tokens/output_tokens) in all cases. * fix(proxy): tighten Responses API usage fix per review - Drop redundant fallback in streaming.rs Chat Completions path; the existing if-let-Some guard already prevents usage:null, so the extra layer was dead code and caused a fmt-breaking indentation issue. - Demote partial-usage warn to debug. Streaming chunks legitimately arrive with partial token counts and the warn-level log was noisy. - Rewrite CHANGELOG entry: reference #2422, broaden scope from DashScope-only to all api_format=openai_responses users (Codex OAuth is the strongest signal; DashScope compatible-mode/v1/responses is the original report). - cargo fmt to clear 12 formatting differences vs main. --------- Co-authored-by: Jason <farion1231@gmail.com>