-
Notifications
You must be signed in to change notification settings - Fork 755
fix(providers): recover static model discovery #1714
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import type { OcxProviderConfig } from "../types"; | ||
| import { | ||
| getProviderRegistryEntry, | ||
| providerMatchesRegistryTransport, | ||
| type ProviderRegistryEntry, | ||
| } from "./registry"; | ||
|
|
||
| const STATIC_MODEL_CATALOG_PROVIDER_IDS = new Set(["cline-pass", "mimo-free"]); | ||
|
|
||
| function normalizedEndpoint(value: string): string { | ||
| const trimmed = value.trim(); | ||
| try { | ||
| const parsed = new URL(trimmed); | ||
| parsed.pathname = parsed.pathname.replace(/\/+$/, "") || "/"; | ||
| return parsed.toString().replace(/\/$/, ""); | ||
| } catch { | ||
| return trimmed.replace(/\/+$/, ""); | ||
| } | ||
| } | ||
|
|
||
| function exactRegistryTransportMatch( | ||
| entry: ProviderRegistryEntry, | ||
| provider: Pick<OcxProviderConfig, "baseUrl" | "adapter"> & Partial<Pick<OcxProviderConfig, "authMode">>, | ||
| options: { allowLegacyMimoLocal?: boolean } = {}, | ||
| ): boolean { | ||
| if (entry.allowBaseUrlOverride || /\{[^}]*\}/.test(entry.baseUrl)) return false; | ||
| if (typeof provider.baseUrl !== "string" || provider.adapter !== entry.adapter) return false; | ||
| const legacyMimoLocal = options.allowLegacyMimoLocal === true | ||
| && entry.id === "mimo-free" | ||
| && provider.authMode === "local"; | ||
| if (provider.authMode !== undefined && provider.authMode !== "key" && !legacyMimoLocal) return false; | ||
| return normalizedEndpoint(provider.baseUrl) === normalizedEndpoint(entry.baseUrl); | ||
| } | ||
|
|
||
| /** Registry policy for providers whose maintained model list is authoritative. */ | ||
| export function registryEntrySupportsLiveModelDiscovery(entry: ProviderRegistryEntry): boolean { | ||
| return !STATIC_MODEL_CATALOG_PROVIDER_IDS.has(entry.id); | ||
| } | ||
|
|
||
| /** | ||
| * Static-catalog authority is tied to canonical provider identity and exact transport. | ||
| * Renamed/custom rows stay operator-owned: Cline and ClinePass intentionally share a transport, | ||
| * so destination matching alone cannot safely identify a renamed ClinePass configuration. | ||
| */ | ||
| export function staticModelCatalogEntryForProvider( | ||
| name: string, | ||
| provider: OcxProviderConfig, | ||
| ): ProviderRegistryEntry | undefined { | ||
| const entry = getProviderRegistryEntry(name); | ||
| if (!entry || !STATIC_MODEL_CATALOG_PROVIDER_IDS.has(entry.id)) return undefined; | ||
| return exactRegistryTransportMatch(entry, provider, { allowLegacyMimoLocal: true }) | ||
| ? entry | ||
| : undefined; | ||
| } | ||
|
|
||
| export function providerSupportsLiveModelDiscovery(name: string, provider: OcxProviderConfig): boolean { | ||
| return staticModelCatalogEntryForProvider(name, provider) === undefined; | ||
| } | ||
|
|
||
| /** | ||
| * MiMo Free predates collision preservation in the registry. Keep same-named custom rows out of | ||
| * registry ownership without broadening the generic transport matcher to other key providers. | ||
| */ | ||
| export function providerMatchesRegistryTransportWithStaticGuards( | ||
| name: string, | ||
| provider: Pick<OcxProviderConfig, "baseUrl" | "adapter"> & Partial<Pick<OcxProviderConfig, "authMode">>, | ||
| ): boolean { | ||
| if (name !== "mimo-free") return providerMatchesRegistryTransport(name, provider); | ||
| const entry = getProviderRegistryEntry(name); | ||
| return entry !== undefined | ||
| && exactRegistryTransportMatch(entry, provider, { allowLegacyMimoLocal: true }); | ||
| } | ||
|
|
||
| /** Repair only registry-owned legacy state; operator-owned model lists stay untouched. */ | ||
| export function repairStaticModelCatalogProvider(name: string, provider: OcxProviderConfig): void { | ||
| const entry = staticModelCatalogEntryForProvider(name, provider); | ||
| if (!entry) return; | ||
| provider.liveModels = false; | ||
| if ( | ||
| name === "mimo-free" | ||
| && entry.id === "mimo-free" | ||
| && (provider.authMode === undefined || provider.authMode === "local") | ||
| ) { | ||
| provider.authMode = "key"; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.