Repository navigation
feat(responses): OpenAI Responses API frontend for Grok Build - #42
Merged
Merged
Conversation
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.
Implements
POST /v1/responsesso Grok Build (api_backend = "responses") can run against cline-proxy with Cline as the upstream transport. Closes #41.What
Ported the verified Responses implementation from
codebuddy-proxyand adapted it to cline-proxy's policy and infrastructure:src/responses/request.rs- Responses request normalization to the same OpenAI Chat Completions body the Anthropic frontend emits: string/arrayinput,function_callhistory with preservedcall_ids,function_call_output->role=tool, flat tools -> nested (schemas byte-identical),tool_choice,max_output_tokens->max_tokens,reasoning.effortmapping,prompt_cache_keyforwarding. Hosted backend tools (web_search,x_search, ...) are dropped, never faked.item_referencerejected. Historicalreasoningitems never replayed.src/responses/stream.rs- chat SSE -> Responses SSE converter with exact typed event shapes, monotonicsequence_number, and the invariant Grok Build requires:response.output_item.added(function_call, with call_id + name) always precedes its argument deltas. Terminal frames:response.completed/response.incomplete(length) /response.failed(never a replay). Terminal response object reconstructs full output for next-turn replay. Usage:input_tokensis the FULL prompt count, cached tokens a subset. Reasoning exposed only whenreasoning.summaryrequested.src/responses_pump.rs- streaming pump and non-stream aggregation. SameStreamWatchtimers, SSE comment keepalive (: ping, never a synthetic frame), bounded buffers, no-replay-after-commit, and client-disconnect cancellation as the Anthropic pump. Non-stream uses ONE upstream streaming generation aggregated locally. Reasoning shadow store bookkeeping with the same epoch rules.src/server.rs-/v1/responsesroute behind the same auth middleware; OpenAI error envelope; model aliases; GLM policy (optimize_request) + prefix telemetry + canonical tool JSON + exact-token telemetry slot; reasoning shadow restore/clear on epoch boundaries.src/cache.rs-responses_session_fingerprint(domain-separated HMAC so Responses keys can never collide with Anthropic fingerprints) andresponses_session_raw_id(prompt_cache_key->metadata.session_id/user_idfallback). Raw keys are never logged.src/obs.rs-request_idfield onStreamSummaryso the Responses pump can emit the standard single per-request summary withprotocol: "responses".Safety invariants preserved
Tests
15 offline integration tests (
tests/responses_api.rs) against a scripted loopback mock: non-stream object shape, tool-call id round-trip, typed stream lifecycle, item-added-before-delta ordering, GLM policy application (explicit effort, output cap), hosted-tool drop, tool history replay, shadow restore without wire reasoning, unrequested-reasoning gating, effective-429 failover without replay, non-429 no-rotation, auth, invalid request shapes, length->incomplete, domain-separated fingerprints. Plus unit tests insrc/responses/*(usage mapping, ids, conversion, stream lifecycle/tool/reasoning/length/failed).Gates: fmt OK, check OK, clippy
-D warningsOK, 304 tests debug OK, 304 tests release OK.Docs
README: new "Grok Build (OpenAI Responses API)" section + route list + curl examples.
docs/DEVELOPMENT_STATE.mdupdated with the new current target.