-
Notifications
You must be signed in to change notification settings - Fork 470
fix(catalog): carry Together /models array fix onto dev2-go (#639) #682
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 all commits
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 |
|---|---|---|
|
|
@@ -71,6 +71,32 @@ export function isProviderModelsApiItems(value: unknown): value is ProviderModel | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Normalize OpenAI-compatible /models payloads for catalog discovery. | ||
| * Supports `{ data: [...] }` and top-level arrays (Together AI `#617`). | ||
| * Google's `{ models: [...] }` is handled by the connectivity probe only — catalog | ||
| * discovery must not treat a stray `models` key on openai-chat responses as valid. | ||
| */ | ||
| export function providerModelsListFromResponse(json: unknown): unknown { | ||
| if (Array.isArray(json)) return json; | ||
| if (json !== null && typeof json === "object" && !Array.isArray(json)) { | ||
| const data = (json as { data?: unknown }).data; | ||
| if (Array.isArray(data)) return data; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| /** Connectivity-probe shape: also accepts Google `{ models: [...] }`. */ | ||
| export function providerModelsListFromProbeResponse(json: unknown): unknown { | ||
| if (Array.isArray(json)) return json; | ||
| if (json !== null && typeof json === "object" && !Array.isArray(json)) { | ||
| const obj = json as { data?: unknown; models?: unknown }; | ||
| if (Array.isArray(obj.data)) return obj.data; | ||
| if (Array.isArray(obj.models)) return obj.models; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| export function configuredContextWindow(prov: OcxProviderConfig, id: string): number | undefined { | ||
| const configured = modelRecordValue(prov.modelContextWindows, id) ?? prov.contextWindow; | ||
| return typeof configured === "number" && configured > 0 ? configured : undefined; | ||
|
|
@@ -366,9 +392,7 @@ export async function fetchProviderModels(name: string, prov: OcxProviderConfig, | |
| } | ||
| return models; | ||
| } | ||
| const data = json !== null && typeof json === "object" && !Array.isArray(json) | ||
| ? (json as { data?: unknown }).data | ||
| : undefined; | ||
| const data = providerModelsListFromResponse(json); | ||
|
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.
The new Bun test exercises AGENTS.md reference: src/AGENTS.md:L22-L25 Useful? React with 👍 / 👎. |
||
| if (!isProviderModelsApiItems(data)) { | ||
| const { models, fallback, shouldLog } = failedDiscoveryFallback({ reason: "invalid_response" }); | ||
| if (shouldLog) { | ||
|
|
||
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.
When a top-level
/modelsarray containsnull,{}, or an entry whoseidis blank, unmarshalling into[]ProviderModelsAPIItemsucceeds and this branch reports the payload as valid.FetchProviderModelsthen skips those rows, marks discovery successful, and caches an empty or partial authoritative catalog instead of retaining the stale/configured fallback; the TypeScript path rejects the entire malformed list. Validate every decoded item has a nonblank ID before returning success.Useful? React with 👍 / 👎.