Skip to content

refactor(chat/responses): canonicalize input at the entry boundary#136

Draft
Menci wants to merge 1 commit into
floway/inline-pick-into-servefrom
floway/canonicalize-responses-input
Draft

refactor(chat/responses): canonicalize input at the entry boundary#136
Menci wants to merge 1 commit into
floway/inline-pick-into-servefrom
floway/canonicalize-responses-input

Conversation

@Menci

@Menci Menci commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Wire `ResponsesPayload.input` is `string | InputItem[]`. The HTTP/WS entries normalize a bare-string `input` to a single synthetic user-role message immediately on parse, so every internal reader sees array-only input. Encoded in the type system via `CanonicalResponsesPayload = Omit<ResponsesPayload, 'input'> & { input: ResponsesInputItem[] }`.

Plumbed through every signature past the entry: `ResponsesServeGenerateArgs`, `ResponsesServeCompactArgs`, `ResponsesAttemptInvokeArgs`, `ResponsesInvocation` (the gateway-internal interceptor variant — provider-package `ResponsesInvocation` stays wire-shaped), `ResponsesServePlan.prepared`, `RewrittenResponsesPayload`, `expandPreviousResponseId`, `normalizeAssistantInputText`. Cross-protocol entries (messages/gemini translating to responses) re-canonicalize the translated payload via the exported `canonicalizeResponsesPayload` helper.

Removes every internal `typeof input === 'string'` branch: `expandPreviousResponseId`, `expandShimCompactionItems`, `simulateCompaction` (the shim's `originalInputItems` materialization), `containsCompactionTrigger`, `withInterleavedSystemDemotedToUser`, plus the matching obsolete tests.

Test plan

  • `pnpm typecheck`
  • `pnpm lint`
  • `pnpm test`

Wire `ResponsesPayload.input` is `string | InputItem[]`. The HTTP/WS
entries normalize a bare-string `input` to a single synthetic
user-role message immediately on parse, so every internal reader sees
array-only input. Encoded in the type system via a new
`CanonicalResponsesPayload = Omit<ResponsesPayload, 'input'> &
{ input: ResponsesInputItem[] }`.

Plumbed through every signature past the entry: ResponsesServeGenerateArgs,
ResponsesServeCompactArgs, ResponsesAttemptInvokeArgs, ResponsesInvocation
(the gateway-internal interceptor variant — provider-package
ResponsesInvocation stays wire-shaped), ResponsesServePlan.prepared,
RewrittenResponsesPayload, expandPreviousResponseId, normalizeAssistantInputText.
Cross-protocol entries (messages/gemini translating to responses)
re-canonicalize the translated payload via the exported
`canonicalizeResponsesPayload` helper.

Removes every internal `typeof input === 'string'` branch:
expandPreviousResponseId, expandShimCompactionItems, simulateCompaction
(the shim's `originalInputItems` materialization), containsCompactionTrigger,
withInterleavedSystemDemotedToUser. Drops `materializeInput` in serve-prep
(input is already array). Drops the matching obsolete tests.
@Menci Menci marked this pull request as draft June 28, 2026 20:29
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from 88cd186 to ce88d6a Compare June 28, 2026 23:25
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from 2789279 to e8ea938 Compare June 28, 2026 23:44
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from ce88d6a to 87e1ce3 Compare June 29, 2026 03:25
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from e8ea938 to 1cd85a8 Compare June 29, 2026 03:25
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from 87e1ce3 to 0c05f80 Compare June 29, 2026 03:55
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from 1cd85a8 to 5037202 Compare June 29, 2026 03:55
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from 0c05f80 to 5db19d3 Compare June 29, 2026 04:21
@Menci Menci force-pushed the floway/canonicalize-responses-input branch 2 times, most recently from 5b2a41a to 9539807 Compare June 29, 2026 08:22
@Menci Menci force-pushed the floway/inline-pick-into-serve branch 2 times, most recently from 046b62e to c3ba39e Compare June 29, 2026 08:32
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from 9539807 to e0ca637 Compare June 29, 2026 08:32
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from c3ba39e to d6913b4 Compare June 29, 2026 10:52
@Menci Menci force-pushed the floway/canonicalize-responses-input branch 2 times, most recently from b9e938e to d8c7a48 Compare June 30, 2026 03:46
@Menci Menci force-pushed the floway/inline-pick-into-serve branch 2 times, most recently from 7d8f28f to afd2d8d Compare June 30, 2026 04:19
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from d8c7a48 to e8f031e Compare June 30, 2026 04:19
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from afd2d8d to eb646be Compare June 30, 2026 06:39
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from e8f031e to fa7a3b6 Compare June 30, 2026 06:39
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from eb646be to 4b78b8d Compare June 30, 2026 07:52
@Menci Menci force-pushed the floway/canonicalize-responses-input branch 2 times, most recently from 22ea872 to feaa92c Compare June 30, 2026 07:53
@Menci Menci force-pushed the floway/inline-pick-into-serve branch 2 times, most recently from f8c9e6e to 9753aa9 Compare June 30, 2026 08:51
@Menci Menci force-pushed the floway/canonicalize-responses-input branch 2 times, most recently from 141056c to c14d814 Compare June 30, 2026 08:53
@Menci Menci force-pushed the floway/inline-pick-into-serve branch 2 times, most recently from 3fd8b66 to a00cf7c Compare June 30, 2026 10:33
@Menci Menci force-pushed the floway/canonicalize-responses-input branch 3 times, most recently from e95e773 to dd6d30f Compare June 30, 2026 11:01
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from a00cf7c to 4d16702 Compare June 30, 2026 11:01
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from dd6d30f to b1b3830 Compare June 30, 2026 11:27
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from 4d16702 to 69a13dd Compare June 30, 2026 11:27
@Menci Menci force-pushed the floway/canonicalize-responses-input branch from b1b3830 to e5d21ad Compare June 30, 2026 16:10
@Menci Menci force-pushed the floway/inline-pick-into-serve branch from 69a13dd to 977e529 Compare June 30, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant