Repository navigation
fix(catalog): compute combo context_length from known targets only #3304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3f30ea1
dcb5e88
914bdcc
b7c2b4a
712a971
432f388
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -129,16 +129,22 @@ export interface OmniRouteProviderOptions { | |||||||||||||||||||
| apiKey: string; | ||||||||||||||||||||
| /** Override the display name shown in OpenCode. Default: `"OmniRoute"`. */ | ||||||||||||||||||||
| displayName?: string; | ||||||||||||||||||||
| /** Override the model catalog. Defaults to `OMNIROUTE_DEFAULT_OPENCODE_MODELS`. */ | ||||||||||||||||||||
| models?: readonly string[]; | ||||||||||||||||||||
| /** Override the model catalog. Accepts model ids (strings) or live model entries from `fetchLiveModels`. When entries carry a `contextLength`, it is used directly — no hardcoded map needed. */ | ||||||||||||||||||||
| models?: readonly (string | { id: string; contextLength?: number })[]; | ||||||||||||||||||||
| /** Optional human-readable labels keyed by model id. Overridden by `modelCapabilities[id].label`. */ | ||||||||||||||||||||
| modelLabels?: Record<string, string>; | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Optional capability overrides keyed by model id. Merged on top of | ||||||||||||||||||||
| * `OMNIROUTE_DEFAULT_MODEL_CAPABILITIES` for ids in the default catalog; | ||||||||||||||||||||
| * for custom ids the override is used verbatim. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| modelCapabilities?: Record<string, ModelCapabilities>; | ||||||||||||||||||||
| modelCapabilities?: Record<string, ModelCapabilities>; | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Optional per-model context-length overrides (tokens). Takes precedence | ||||||||||||||||||||
| * over the static `OMNIROUTE_DEFAULT_MODEL_CONTEXT_LENGTHS` map but is | ||||||||||||||||||||
| * superseded by `contextLength` on live model entries passed via `models`. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| modelContextLengths?: Record<string, string | number>; | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Primary model for OpenCode (top-level `model` key). | ||||||||||||||||||||
| * Emitted as `"omniroute/<id>"`. When omitted the key is not written. | ||||||||||||||||||||
|
|
@@ -248,7 +254,12 @@ export function createOmniRouteProvider(options: OmniRouteProviderOptions): Open | |||||||||||||||||||
| const models: Record<string, OpenCodeModelEntry> = {}; | ||||||||||||||||||||
| const seen = new Set<string>(); | ||||||||||||||||||||
| for (const raw of modelList) { | ||||||||||||||||||||
| const id = typeof raw === "string" ? raw.trim() : ""; | ||||||||||||||||||||
| const id = | ||||||||||||||||||||
| typeof raw === "object" && raw !== null && "id" in raw | ||||||||||||||||||||
| ? (raw as { id: string }).id.trim() | ||||||||||||||||||||
| : typeof raw === "string" | ||||||||||||||||||||
| ? raw.trim() | ||||||||||||||||||||
| : ""; | ||||||||||||||||||||
| if (!id || seen.has(id)) continue; | ||||||||||||||||||||
| seen.add(id); | ||||||||||||||||||||
| const defaults = OMNIROUTE_DEFAULT_MODEL_CAPABILITIES[id] ?? {}; | ||||||||||||||||||||
|
|
@@ -266,9 +277,11 @@ export function createOmniRouteProvider(options: OmniRouteProviderOptions): Open | |||||||||||||||||||
| if (typeof merged.temperature === "boolean") entry.temperature = merged.temperature; | ||||||||||||||||||||
| if (typeof merged.tool_call === "boolean") entry.tool_call = merged.tool_call; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Include context window limit when known — OpenCode reads this to | ||||||||||||||||||||
| // determine usable context length for compaction & overflow detection. | ||||||||||||||||||||
| const contextLength = OMNIROUTE_DEFAULT_MODEL_CONTEXT_LENGTHS[id]; | ||||||||||||||||||||
| // Context window: live model entry (from API catalog) > modelContextLengths > static defaults | ||||||||||||||||||||
| const liveContext = typeof raw === "object" && raw !== null | ||||||||||||||||||||
| ? (raw as { contextLength?: number }).contextLength | ||||||||||||||||||||
| : undefined; | ||||||||||||||||||||
| const contextLength = liveContext ?? options.modelContextLengths?.[id] ?? OMNIROUTE_DEFAULT_MODEL_CONTEXT_LENGTHS[id]; | ||||||||||||||||||||
| if (typeof contextLength === "number" && contextLength > 0) { | ||||||||||||||||||||
| entry.limit = { context: contextLength }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
|
||||||||||||||||||||
|
|
@@ -508,7 +521,7 @@ export interface OmniRouteLiveModel { | |||||||||||||||||||
| * const config = buildOmniRouteOpenCodeConfig({ | ||||||||||||||||||||
| * baseURL: "http://localhost:20128", | ||||||||||||||||||||
| * apiKey: "sk_omniroute", | ||||||||||||||||||||
| * models: models.map((m) => m.id), | ||||||||||||||||||||
| * models, // OmniRouteLiveModel[] — contextLength auto-extracted | ||||||||||||||||||||
| * modelLabels: Object.fromEntries(models.map((m) => [m.id, m.name])), | ||||||||||||||||||||
| * }); | ||||||||||||||||||||
| * ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
rawis an object and contains anidproperty, butraw.idis not a string (e.g., a number, null, or undefined), calling.trim()on it will throw a runtimeTypeError. We should explicitly verify thatraw.idis a string before attempting to trim it.