Skip to content

feat(js/plugins/compat-oai): add responsesModel() opt-in and dual-transport dispatch - #6160

Open
cabljac wants to merge 11 commits into
feat/compat-oai-responses-slice2from
feat/compat-oai-responses-slice3
Open

cabljac wants to merge 11 commits into
feat/compat-oai-responses-slice2from
feat/compat-oai-responses-slice3

Conversation

@cabljac

@cabljac cabljac commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #6002, closes #6005. Slice 3 of the Responses API stack, on top of #6148.

  • openAI.responsesModel(name): typed ref pinned to config: { transport: 'responses' }; withConfig/withVersion re-wrapped so the pin survives chaining.
  • Dual-transport dispatch: chat-registered OpenAI models route a request carrying config: { transport: 'responses' } to the Responses runner, so the opt-in also works from dotprompt frontmatter. Providers that do not opt in keep the INVALID_ARGUMENT rejection.
  • Responses config schema declares previousResponseId, reasoningEffort, reasoningSummary, mapped to previous_response_id and reasoning: { effort, summary } on the wire; declared fields compose over a raw passthrough reasoning object.
  • README: automatic routing for Responses-only models, the opt-in, built-in tools via config.tools, stateless default and opting into server-side threading.

Review hardening applied on top: chat-only config keys (frequencyPenalty etc.) are dropped from the Responses wire; dispatch-capable registrations default supports.constrained to 'all' so an output schema reaches the Responses wire natively instead of being simulated into the prompt, while middleware re-applies the simulation to Chat Completions requests on models that never declared constrained support, keeping the plain chat path byte-identical to before; near-miss transport values (e.g. 'Responses') throw INVALID_ARGUMENT instead of silently serving Chat Completions ('auto' stays accepted, as in #6006); declared previousResponseId wins over a raw previous_response_id passthrough, matching the reasoning fields.

Tests: 230 passing. Stack rebased onto current main.

Known limitations, noted deliberately:

  • responsesModel()'s config type inherits .passthrough() from the schema, so unknown keys (typos included) compile and pass to the wire. Cost of keeping the passthrough escape hatch; consistent with model().
  • The registered action for a dual-transport model advertises the Chat Completions config schema, so schema-driven tooling (Dev UI config forms) does not offer previousResponseId/reasoningEffort/reasoningSummary on it. Runtime honors them regardless; inherent to one action serving two transports.
  • Dispatch-capable actions advertise supports.constrained: 'all' even when their Chat Completions API would reject response_format: json_schema; runtime behavior is correct on both transports (see above), the metadata over-claim is display-only.

Live smoke checklist before un-drafting:

  • config.tools: [{ type: 'web_search' }] passthrough (type absent from the pinned SDK union).
  • previousResponseId under the default store: false (unverified whether OpenAI accepts the combination).
  • A non-reasoning model over the dispatch (responsesModel('gpt-4o')): confirms the reasoning-gated encrypted-content include.
  • A text-only reasoning turn replayed stateless with reasoningSummary on (multi-turn, no tools): the assistant message replays without its msg_ id next to an id-carrying reasoning item; one shape passed live already, ecosystem reports 400s on close variants.

@github-actions github-actions Bot added docs Improvements or additions to documentation js labels Aug 25, 2026
@cabljac cabljac changed the title feat/compat oai responses slice3 feat(js/plugins/compat-oai): add responsesModel() opt-in and dual-transport dispatch Aug 25, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the OpenAI Responses API in the compat-oai plugin, allowing automatic routing for specific models and manual opt-in via openAI.responsesModel(). It also adds configuration schemas for parameters like previousResponseId, reasoningEffort, and reasoningSummary, along with comprehensive tests. Feedback on the changes suggests avoiding in-place mutation of the ref object in pinResponsesTransport to prevent side effects and preserve the this context, as well as defensively checking that body.reasoning is a non-null object before spreading it to handle potential non-object values.

Comment thread js/plugins/compat-oai/src/responses.ts Resolved
@cabljac
cabljac force-pushed the feat/compat-oai-responses-slice3 branch from 73f6b6d to d5eb1e0 Compare August 25, 2026 13:59
@cabljac
cabljac force-pushed the feat/compat-oai-responses-slice3 branch from d5eb1e0 to a7ba1b8 Compare August 25, 2026 14:16
@cabljac
cabljac force-pushed the feat/compat-oai-responses-slice3 branch 2 times, most recently from 8148836 to 5125bb5 Compare August 25, 2026 15:47
@cabljac
cabljac force-pushed the feat/compat-oai-responses-slice3 branch from 5125bb5 to 29475bb Compare August 25, 2026 17:13
@cabljac
cabljac force-pushed the feat/compat-oai-responses-slice3 branch from 29475bb to db1da1c Compare August 26, 2026 14:29

@adesinah adesinah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went through this against the ticket. The dispatch design holds up well — I checked the ref pinning against core's modelRef and it's correct for the right reasons (arrow functions so the unbound method extraction is safe, withVersion spreads the original options so the pin survives, withConfig replaces wholesale hence the re-injection). transport is also stripped on both wire builders, so nothing leaks to either API. Typecheck clean, 199 tests pass.

Five notes inline — mostly documentation rather than code changes.

Comment on lines +758 to +766
const use: ModelMiddleware[] | undefined =
params.responsesTransport && !ownConstrained
? [
(req, next) =>
req.config?.transport === 'responses'
? next(req)
: simulateConstrainedGeneration()(req, next),
]
: undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth pulling into Known Limitations: core runs use middleware before augmentWithContext(), but its own simulator runs after it. So a request carrying both context docs and an output schema now gets its injected text in a different order than before this PR.

You spotted this in 1aacfe0's commit message, but right now it only lives in a test comment. It's also wider than it looks — only MULTIMODAL_MODEL_INFO declares constrained, so this path covers ~19 of the 30 curated chat refs (all of GPT-5, GPT-4 non-multimodal, GPT-4-vision, GPT-3.5), not just edge cases.

Nothing to fix in code — core always prepends use — just worth saying out loud in the description.

// dispatch runs. Models that never declared constrained still need that
// simulation on their Chat Completions requests, so the middleware below
// re-applies it for exactly those.
const ownConstrained = modelRef?.info?.supports?.constrained;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latent, not actionable today: ownConstrained ?? 'all' treats any declared value as "no compensation needed".

If a dispatch-capable model ever declared constrained: 'no-tools', core's simulator would fire for tool-carrying requests on both transports — simulating a schema into the prompt on the Responses path, where it's supported natively.

Unreachable right now (only openai sets responsesTransport, and no chat info declares 'no-tools'), so just a note for whoever extends this.

client,
pluginOptions,
modelRef,
responsesTransport: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listActions above builds its metadata straight from modelRef.info, so it never picks up the constrained: 'all' override that defineCompatOpenAIModel applies here. Net effect: gpt-5 lists as no-constrained but registers as 'all'.

The description calls the over-claim display-only, which is fair — just flagging that the two display surfaces disagree with each other.

Comment on lines +101 to +103
reasoningEffort: z
.enum(['none', 'minimal', 'low', 'medium', 'high', 'xhigh'])
.optional(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pinned SDK types ReasoningEffort as 'low' | 'medium' | 'high' | null, so none, minimal and xhigh sit outside its union and pass straight through to the wire.

Same risk class as the config.tools: [{ type: 'web_search' }] passthrough that's already on the live-smoke checklist — and since this landed in the last commit on the branch, it's had the least live exercise. Probably worth its own line on that checklist.

).rejects.toThrow(expect.objectContaining({ status: 'INVALID_ARGUMENT' }));
});

test('rejects a near-miss transport value instead of serving it silently', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This drives openAIModelRunner directly, so it skips the action + config-schema layer. The scenario in the description is dotprompt frontmatter, which does go through that layer, and transport is a z.enum there.

An end-to-end case would pin down which layer actually rejects 'Responses' — otherwise a later change to config validation could relocate the behavior without failing anything.

…sponses API on config opt-in

A chat-registered model with responsesTransport enabled routes a request
carrying config.transport === 'responses' to the Responses runner instead
of throwing; the openAI plugin enables it for its Chat Completions models
and declares the transport key on their config schema. Providers that do
not opt in keep the INVALID_ARGUMENT rejection.
Typed ref pinned to the Responses transport for dual-transport models,
with withConfig/withVersion re-wrapped so the pin survives chaining.
Declares previousResponseId and reasoning effort/summary on the Responses
config schema and maps them onto their wire fields, composing declared
reasoning fields over any raw passthrough object.
…sponses wire

frequencyPenalty, presencePenalty, logProbs and topLogProbs are declared
on the dual-transport chat schema but have no Responses equivalent, so a
working chat config opting into the Responses transport would 400 on the
unknown camelCase fields. Drop them like topK/stopSequences, and pin the
passthrough-wins precedence for previous_response_id.
GenerateResponse.raw is typed unknown, so the snippet did not compile.
…ive constrained support

A dual-transport action inherits its chat info, and most of those infos
leave supports.constrained unset, so genkit wrapped the action in
simulateConstrainedGeneration and stripped output.schema into the prompt
before the transport dispatch ran. Default constrained to 'all' on
dispatch-capable registrations; both wire formats carry the schema
natively.
…at path

'Responses' or any other near-miss was silently destructured off the wire
and served over Chat Completions, while every other cell of the transport
matrix throws. 'chat_completions' stays accepted as the explicit chat pin.
…-wins precedence as the reasoning fields

The two mapped-key features introduced together resolved a declared-vs-raw
collision in opposite directions; a declared key now wins both times, and
a raw passthrough still works when the declared key is absent.
… plain chat path

Defaulting supports.constrained at registration also disarmed core's
simulator for Chat Completions requests, so legacy models that reject
response_format json_schema (gpt-3.5, gpt-4) went from working simulation
to an OpenAI 400 with no transport opt-in anywhere. Dispatch-capable
models that never declared constrained now re-apply the simulator via
middleware on every non-Responses request, and the chat schema's
transport enum gains the 'chat_completions' value the builder accepts.
Simulation now runs before context augmentation, so with docs present the
injected part order differs from the pre-dispatch chain.
… range

Adds none and xhigh; xhigh is the flagship setting for the codex line
this plugin registers, and the old enum could not express either.
Also note the plugin timeout option for the slow pro models.
@adesinah
adesinah force-pushed the feat/compat-oai-responses-slice3 branch from e4c8004 to 9284e7a Compare November 19, 2026 12:19
@adesinah
adesinah marked this pull request as ready for review November 19, 2026 12:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JS] compat-oai: responsesModel() opt-in, discovery, docs

2 participants