mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-01 12:26:47 +00:00
refactor: share provider catalog projection
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
29
src/plugins/provider-catalog-unified-text.ts
Normal file
29
src/plugins/provider-catalog-unified-text.ts
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user