feat(proxy): clamp max_tokens, fix Responses content shape, surface reasoning#38
Open
GoDiao wants to merge 1 commit into
Open
feat(proxy): clamp max_tokens, fix Responses content shape, surface reasoning#38GoDiao wants to merge 1 commit into
GoDiao wants to merge 1 commit into
Conversation
…easoning - Add provider maxOutputTokens config (Saved/Create/Update schemas); clamp Anthropic max_tokens to the provider's known limit instead of always omitting it. Claude Code sends 128K which exceeds many providers (DeepSeek: 8192, etc.); without a configured cap we still omit the field. - Fix OpenAI Responses API content parts: emit input_text/input_image instead of reusing Chat-shaped image_url objects, and correct the flush logic so accumulated content is not dropped. - Stream reasoning items from OpenAI Responses (response.reasoning_*. delta/done and reasoning_summary_part.done) into Anthropic thinking content blocks, with lazy open for providers that omit output_item.added. - Map prompt_tokens_details.cached_tokens -> cache_read_input_tokens on both Chat and Responses streaming paths (previously only output_tokens were forwarded). - Extract shared extractToolResultContent helper; non-text tool_result blocks (images, nested tool_use, thinking) now produce placeholders instead of being silently dropped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OpenAI-compatible proxy quality fixes for the Anthropic↔OpenAI translation layer.
Changes
maxOutputTokensprovider config + clamp: Add optionalmaxOutputTokenstoSavedProviderSchema/CreateProviderSchema/UpdateProviderSchema(int, positive, ≤10,000,000). When configured, Anthropicmax_tokensis clamped viaMath.minbefore forwarding to OpenAI endpoints. Without a cap, the field is still omitted. Fixes Claude Code sending 128Kmax_tokensthat exceeds provider limits (DeepSeek: 8192, etc.).input_text/input_imagecontent parts (the correct Responses shape) instead of reusing Chat-shapedimage_urlobjects. Corrects the flush logic so accumulated content is not dropped when a tool block follows text/image.response.reasoning_summary_text.delta/response.reasoning_text.delta/*.done/reasoning_summary_part.doneand thereasoningoutput item, mapping them to Anthropicthinkingcontent blocks. Includes lazy open for providers that omit theoutput_item.addedevent. All reasoning blocks are closed beforemessage_deltaper Anthropic spec.prompt_tokens_details.cached_tokens→cache_read_input_tokenson both Chat and Responses streaming paths (previously onlyoutput_tokenswas reported).extractToolResultContent: Dedupe the tool_result content extraction in both transform paths; non-text blocks (images, nested tool_use, thinking) now produce placeholders like[image omitted: …]instead of being silently dropped.Files
src/server/types/provider.ts— addmaxOutputTokensto schemassrc/server/services/providerService.ts— threadmaxOutputTokensthroughgetProviderForProxysrc/server/proxy/handler.ts— passmaxOutputTokensto both transformssrc/server/proxy/transform/anthropicToOpenaiChat.ts— clampmax_tokens, use shared helpersrc/server/proxy/transform/anthropicToOpenaiResponses.ts— clampmax_output_tokens, correct content part shape, use shared helpersrc/server/proxy/transform/toolArguments.ts— newextractToolResultContentsrc/server/proxy/transform/types.ts— addOpenAIResponsesContentPartsrc/server/proxy/streaming/openaiChatStreamToAnthropic.ts—mapStreamUsagewith cached tokenssrc/server/proxy/streaming/openaiResponsesStreamToAnthropic.ts— reasoning block handling + cached tokensdesktop/src-tauri/Cargo.lock— followdreamcoder-desktop0.4.0→0.4.5 version bumpsrc/server/__tests__/proxy-streaming.test.ts/proxy-transform.test.ts— coverage for the aboveValidation
Note:
providers.test.ts/provider-presets.test.tshave 4 pre-existing failures onclean-master(verified by running tests against the unmodified branch); this PR does not touch the preset data or activation env logic those tests cover.