diff --git a/src/plugin-sdk/provider-entry.ts b/src/plugin-sdk/provider-entry.ts index 3fe4e84aa93..755a82703e2 100644 --- a/src/plugin-sdk/provider-entry.ts +++ b/src/plugin-sdk/provider-entry.ts @@ -1,5 +1,6 @@ import type { UnifiedModelCatalogEntry } from "../model-catalog/types.js"; import { createProviderApiKeyAuthMethod } from "../plugins/provider-api-key-auth.js"; +import { projectProviderCatalogResultToUnifiedTextRows } from "../plugins/provider-catalog-unified-text.js"; import type { ProviderPlugin, ProviderCatalogContext, @@ -109,33 +110,6 @@ function resolveEnvVars(params: { return combined.length > 0 ? uniqueStrings(combined) : undefined; } -function projectProviderCatalogResultToUnifiedTextRows(params: { - providerId: string; - result: ProviderCatalogResult; - source: UnifiedModelCatalogEntry["source"]; -}): UnifiedModelCatalogEntry[] { - if (!params.result) { - return []; - } - const providers = - "provider" in params.result - ? { [params.providerId]: params.result.provider } - : params.result.providers; - const rows: UnifiedModelCatalogEntry[] = []; - for (const [providerId, providerConfig] of Object.entries(providers)) { - for (const model of providerConfig.models ?? []) { - rows.push({ - kind: "text", - provider: providerId, - model: model.id, - ...(model.name ? { label: model.name } : {}), - source: params.source, - }); - } - } - return rows; -} - async function runUnifiedTextCatalog(params: { providerId: string; catalog: ProviderPluginCatalog; diff --git a/src/plugins/model-catalog-registration.ts b/src/plugins/model-catalog-registration.ts index 6c0529052c2..7643acac879 100644 --- a/src/plugins/model-catalog-registration.ts +++ b/src/plugins/model-catalog-registration.ts @@ -15,9 +15,9 @@ import type { import { normalizeOptionalString } from "../shared/string-coerce.js"; import { uniqueValues } from "../shared/string-normalization.js"; import type { PluginDiagnostic } from "./manifest-types.js"; +import { projectProviderCatalogResultToUnifiedTextRows } from "./provider-catalog-unified-text.js"; import type { PluginRecord, PluginRegistry } from "./registry-types.js"; import type { - ProviderCatalogResult, ProviderPlugin, UnifiedModelCatalogProviderContext, UnifiedModelCatalogProviderPlugin, @@ -58,33 +58,6 @@ function mergeModelCatalogHooks( }; } -function projectProviderCatalogResultToUnifiedTextRows(params: { - providerId: string; - result: ProviderCatalogResult; - source: UnifiedModelCatalogEntry["source"]; -}): UnifiedModelCatalogEntry[] { - if (!params.result) { - return []; - } - const providers = - "provider" in params.result - ? { [params.providerId]: params.result.provider } - : params.result.providers; - const rows: UnifiedModelCatalogEntry[] = []; - for (const [providerId, providerConfig] of Object.entries(providers)) { - for (const model of providerConfig.models ?? []) { - rows.push({ - kind: "text", - provider: providerId, - model: model.id, - ...(model.name ? { label: model.name } : {}), - source: params.source, - }); - } - } - return rows; -} - export function createModelCatalogRegistrationHandlers(params: { registry: PluginRegistry; pushDiagnostic: (diagnostic: PluginDiagnostic) => void; diff --git a/src/plugins/provider-catalog-unified-text.ts b/src/plugins/provider-catalog-unified-text.ts new file mode 100644 index 00000000000..7428df58fdc --- /dev/null +++ b/src/plugins/provider-catalog-unified-text.ts @@ -0,0 +1,29 @@ +import type { UnifiedModelCatalogEntry } from "../model-catalog/types.js"; +import type { ProviderCatalogResult } from "./types.js"; + +export function projectProviderCatalogResultToUnifiedTextRows(params: { + providerId: string; + result: ProviderCatalogResult; + source: UnifiedModelCatalogEntry["source"]; +}): UnifiedModelCatalogEntry[] { + if (!params.result) { + return []; + } + const providers = + "provider" in params.result + ? { [params.providerId]: params.result.provider } + : params.result.providers; + const rows: UnifiedModelCatalogEntry[] = []; + for (const [providerId, providerConfig] of Object.entries(providers)) { + for (const model of providerConfig.models ?? []) { + rows.push({ + kind: "text", + provider: providerId, + model: model.id, + ...(model.name ? { label: model.name } : {}), + source: params.source, + }); + } + } + return rows; +}