You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c6d5360
Browse filesBrowse the repository at this point in the historyBrowse files
authored
refactor(providers): map xAI tool_choice to the Responses API shape with a typed request body (#2036)
* refactor(providers): map xAI tool_choice to the Responses API shape with a typed request body
Extracted from the abort-signal series unit (PR 1293) at reviewer
request so that unit stays abort-wiring only:
- xai: replace the `as any` tool_choice cast with an explicit
mapToolChoice mapping (Chat Completions nests named-tool references
under function/custom; the Responses API puts the name at the top
level; allowed_tools entries are flattened).
- xai: type the request body as ResponseCreateParamsStreaming (drops
five lint suppressions) and send max_output_tokens/temperature
unconditionally - getModel() always resolves them.
- anthropic-vertex: drop the no-op content_block_stop case (the
comment itself noted no action is needed; NativeToolCallParser
handles tool-call completion).
Verification: 75/75 green in xai.spec.ts + anthropic-vertex.spec.ts;
tsc --noEmit 0 errors; eslint --max-warnings=0 clean on touched files
(xai.ts suppression count 7 -> 2); prettier clean.
* Address review: reject malformed allowed_tools function entries
Chat Completions allowlist entries are open records, so a function entry
can arrive with a missing or non-string name. Forwarding such an entry
unchanged would send the nested Chat Completions shape to the Responses
API, which cannot express that allowlist entry, and how xAI handles the
malformed payload is unspecified. mapToolChoice now rejects function
entries without a valid string name at the boundary (before
responses.create); non-function entries still pass through unchanged.
The pass-through test now pins only the non-function case; a new test
rejects four malformed function-entry shapes (null name, null ref,
function value, non-string name) and asserts no request is issued
(negative control verified: reverting the throw to a pass-through fails
the new test).
Verification at this head: 25/25 green in xai.spec.ts; tsc --noEmit 0
errors; eslint --max-warnings=0 clean on touched files; prettier clean.
* chore(lint): take upstream baseline suppressions for xai.ts
The merge brings main xai responses-create code whose as-any casts main suppresses (count 7 in upstream eslint-suppressions.json). Locally the auto-merge kept the older count 2, so compile lint flagged the inherited casts. Use the upstream baseline instead of leaving the branch red.
* chore(lint): right-size the xai suppression to the merged any count
The merge keeps five as-any occurrences in xai.ts (two in the mapResponseTools signature, three in the responses create call); the upstream baseline of seven would leave stale suppressions, which eslint rejects. Set the count to the actual five.
* test(xai): assert request options without the extra call-argument shape
The merge with main makes responses.create take a second options argument. Rewriting the assertions to inspect mock.calls[0][0] left the old second expectation argument in place, which failed type-check (toEqual takes one argument). Each assertion now checks the request body and the separate options argument explicitly (signal/timeout, forwarded timeout, absent options). xai.spec.ts 49 passed; tsc clean for the file.
* fix(xai): bridge the abort signal only after request construction
Review follow-up: mapToolChoice throws for malformed allowed_tools entries, and the abort bridge cleanup only covers the request that follows. The bridge now registers after the whole request body (including the tool-choice mapping) is built, so a construction failure cannot leave a listener on metadata.abortSignal. The malformed-entry test now passes an abortSignal and asserts addEventListener was never called. xai.spec.ts 49 passed; tsc clean.
* chore(lint): flag unneeded type assertions in api/
---------
Co-authored-by: Eason Liang <easonliang28@gmail.com>
Co-authored-by: Elliott de Launay <edelauna@gmail.com>
0 commit comments