Repository navigation
refactor(sse): type the rerank response adapter's options parameter - #8528
Merged
diegosouzapw merged 1 commit intoJul 26, 2026
Conversation
This was referenced Jul 25, 2026
backryun
force-pushed
the
chore/ts7-types-rerank-handler
branch
from
July 25, 2026 08:26
eefee80 to
9c56d19
Compare
`transformResponseFromProvider(providerConfig, data, options = {})` annotated
nothing, so TS inferred `options` as `{}` from its default value and rejected
every read of it: `top_n` x6, `documents` x4, `return_documents` x2 across the
DeepInfra and Voyage adapters. All 12 of the file's diagnostics, one cause.
Declared `RerankResponseOptions` from the JSDoc that already documents these
fields on handleRerank, with `documents` as `Array<string | { text?: string }>`
— the two forms the Cohere-compatible API accepts and the adapters already
branch on. `providerConfig` and `data` stay unannotated; only `options` was
producing errors and only `options` is touched.
280 -> 268, zero new, on a line-number-agnostic diff of the full tsc error set.
Tests: `{ text }` documents were only ever exercised through the *request*
adapter (cheaper-inference#5332, cheaper-inference#7809) — every response-adapter test passed plain strings, so
the `typeof doc === "string" ? doc : doc?.text` branch on the response side was
uncovered, and that branch is exactly what gives the declared type its union.
Added rerank-object-documents-response-path.test.ts (5 tests): object-form
documents resolved through both adapters, a mixed string/object array, the
`{}`-without-text fallback, and Voyage's index remap across an empty `{ text: "" }`
document. They pass against the parent commit's rerank.ts too — no behavior
change. 43/43 across the 6 rerank/media-cost suites.
backryun
force-pushed
the
chore/ts7-types-rerank-handler
branch
from
July 25, 2026 21:08
9c56d19 to
50cf723
Compare
diegosouzapw
merged commit Jul 26, 2026
2cf462c
into
cheaper-inference:release/v3.8.49
5 checks passed
Collaborator
|
Thanks @backryun — merged into |
Merged
HouMinXi
pushed a commit
to HouMinXi/OmniRoute
that referenced
this pull request
Aug 2, 2026
…heaper-inference#8528) `transformResponseFromProvider(providerConfig, data, options = {})` annotated nothing, so TS inferred `options` as `{}` from its default value and rejected every read of it: `top_n` x6, `documents` x4, `return_documents` x2 across the DeepInfra and Voyage adapters. All 12 of the file's diagnostics, one cause. Declared `RerankResponseOptions` from the JSDoc that already documents these fields on handleRerank, with `documents` as `Array<string | { text?: string }>` — the two forms the Cohere-compatible API accepts and the adapters already branch on. `providerConfig` and `data` stay unannotated; only `options` was producing errors and only `options` is touched. 280 -> 268, zero new, on a line-number-agnostic diff of the full tsc error set. Tests: `{ text }` documents were only ever exercised through the *request* adapter (cheaper-inference#5332, cheaper-inference#7809) — every response-adapter test passed plain strings, so the `typeof doc === "string" ? doc : doc?.text` branch on the response side was uncovered, and that branch is exactly what gives the declared type its union. Added rerank-object-documents-response-path.test.ts (5 tests): object-form documents resolved through both adapters, a mixed string/object array, the `{}`-without-text fallback, and Voyage's index remap across an empty `{ text: "" }` document. They pass against the parent commit's rerank.ts too — no behavior change. 43/43 across the 6 rerank/media-cost suites. Co-authored-by: backryun <busan011@ormbiz.co.kr>
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…heaper-inference#8528) `transformResponseFromProvider(providerConfig, data, options = {})` annotated nothing, so TS inferred `options` as `{}` from its default value and rejected every read of it: `top_n` x6, `documents` x4, `return_documents` x2 across the DeepInfra and Voyage adapters. All 12 of the file's diagnostics, one cause. Declared `RerankResponseOptions` from the JSDoc that already documents these fields on handleRerank, with `documents` as `Array<string | { text?: string }>` — the two forms the Cohere-compatible API accepts and the adapters already branch on. `providerConfig` and `data` stay unannotated; only `options` was producing errors and only `options` is touched. 280 -> 268, zero new, on a line-number-agnostic diff of the full tsc error set. Tests: `{ text }` documents were only ever exercised through the *request* adapter (cheaper-inference#5332, cheaper-inference#7809) — every response-adapter test passed plain strings, so the `typeof doc === "string" ? doc : doc?.text` branch on the response side was uncovered, and that branch is exactly what gives the declared type its union. Added rerank-object-documents-response-path.test.ts (5 tests): object-form documents resolved through both adapters, a mixed string/object array, the `{}`-without-text fallback, and Voyage's index remap across an empty `{ text: "" }` document. They pass against the parent commit's rerank.ts too — no behavior change. 43/43 across the 6 rerank/media-cost suites. Co-authored-by: backryun <busan011@ormbiz.co.kr>
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.
Part of #8484. Type-only, no toolchain changes. First slice into
open-sse/handlers— see the scope note at the bottom, because that area turned out not to be what the tracking issue said it was.One untyped parameter, 12 diagnostics
No annotation, so TS infers
optionsas{}from the default value. Every read of it fails:Six of those are
top_nalone, because the DeepInfra and Voyage branches each spell it three times in one expression.Fix
Declared the shape the JSDoc on
handleRerankalready documents:All fields optional — the parameter defaults to
{}, and the existing suites call it with subsets ({ documents: ["a", "b"] }).RerankDocumentis a union rather thanstring[]because the Cohere-compatible API accepts both forms and both adapters already branch on it:providerConfiganddataare left unannotated. Onlyoptionsproduced errors — it is the one parameter with a default value, which is what handed TS the{}— so onlyoptionsis touched.Verification
280 → 268, zero new errors, on a line-number-agnostic diff of the full
tscerror set (with the worktree path normalized out — TS embeds absolute paths in some messages, which otherwise reads as phantom regressions).npm run typecheck:core— cleaneslinton both changed files — cleanrerank,rerank-providers-5332,rerank-voyage-7809,rerank-openrouter-6574,rerank-proxy-pinning-7350,media-cost-headers-handlers)Tests — the union had a real hole
Existing coverage of these three options is genuinely good:
top_ntruncation, descending sort,return_documents: falseomitting text, and Voyage's index remapping are all asserted on both adapters. My first read was that there was nothing worth adding.That was wrong, and the distinction matters. The
{ text }document form is tested — but only through the request adapter:#5332 deepinfra request adapter → {queries,documents} (string + {text})#7809 voyage request adapter handles {text} object documentsEvery response-adapter test passes plain strings. So
typeof doc === "string" ? doc : doc?.texton the response side had no coverage — and that branch is precisely what makesRerankDocumenta union rather thanstring. Nothing would have caught a later "simplification" todocuments?: string[].tests/unit/rerank-object-documents-response-path.test.ts, 5 tests:{ text }documents["plain string", { text: "object form" }]both resolve{}with notext"", neverundefined{ text }documents{ text: "" }As with the other slices in this campaign these are preservation guards, not TDD red/green — there is no bug. I verified that by reverting
rerank.tsto the parent commit and re-running: 5/5 pass there too.Scope note on
open-sse/handlers#8484 previously described this area as "121 diagnostics — chatCore/stream, standalone, last, heaviest validation". Measured, that is wrong: only 39 are in
chatCore.ts. The other 82 are peripheral handlers with no dependency on it —rerank.ts(12),designerWeb.ts(10),audioTranscription.ts(8),responsesHandler.ts(5), and so on. They are sliceable now rather than blocked behind the chatCore work.They do not share a root cause with each other, though —
audioTranscriptionis mostly TS2769 overloads,imageGenerationis TS2554 arity plus aBuffer→BlobPartmismatch.rerank.tsis the only clean single-cause cluster in the group, which is why it goes first. The rest slice per-file. Issue body updated with the breakdown.