UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

101 lines (100 loc) 4.86 kB
import { n as getPreparedModelFullCatalogAuth, o as setPreparedModelFullCatalogAuth } from "./prepared-model-runtime-auth-CnrySjUa.js"; import { t as dedupeByKey } from "./dedupe-by-key-BUZiazge.js"; import { a as completeConfiguredRuntimeModels, l as discoverModels, o as modelCatalogEntryKey, t as buildPreparedPluginModelCatalog } from "./prepared-model-runtime.plugin-generation-t_16307i.js"; import { r as loadBundledProviderStaticCatalogContextModels } from "./model.static-catalog-BVUjxJLz.js"; import { o as toStaticCatalogEntry } from "./prepared-model-runtime.configured-fNJibGQY.js"; //#region src/agents/prepared-model-runtime.full-catalog.ts const fullModelCatalogSnapshots = /* @__PURE__ */ new WeakSet(); /** Builds complete inventory before generation-specific runtime capability projection. */ async function prepareFullCatalogFacts(agentFacts, pluginGeneration, catalogMode, catalogSource) { const { env, input, templateAuthStorage } = agentFacts; const { pluginMetadataSnapshot, preparedStaticProviderCatalog } = pluginGeneration; const templateModelRegistry = discoverModels(templateAuthStorage, input.agentDir, { config: input.config, ...input.workspaceDir ? { workspaceDir: input.workspaceDir } : {}, pluginMetadataSnapshot, ...catalogMode === "static" ? { normalizeModels: false } : {}, ...catalogSource ? { includePluginCatalogs: true, modelsJsonContents: catalogSource.modelsJsonContents, pluginCatalogs: catalogSource.pluginCatalogs } : {} }); const modelCatalog = await buildPreparedPluginModelCatalog({ agentFacts, catalogMode, modelRegistry: templateModelRegistry, pluginGeneration }); const providerStaticModels = pluginGeneration.providerStaticModels ?? await loadBundledProviderStaticCatalogContextModels({ cfg: input.config, env, metadataSnapshot: pluginMetadataSnapshot, ...preparedStaticProviderCatalog ? { preparedStaticProviderCatalog } : {}, ...input.workspaceDir ? { workspaceDir: input.workspaceDir } : {} }); const configuredRuntimeModels = completeConfiguredRuntimeModels(agentFacts, pluginGeneration, templateModelRegistry); const staticModels = [...configuredRuntimeModels.map(({ model }) => model), ...providerStaticModels]; const providerOutcomes = catalogSource?.providerOutcomes ?? []; const completeModelCatalog = { ...modelCatalog, staticEntries: dedupeByKey(staticModels, modelCatalogEntryKey).map(toStaticCatalogEntry), ...providerOutcomes.length > 0 ? { providerOutcomes } : {} }; if (catalogMode === "live") fullModelCatalogSnapshots.add(completeModelCatalog); return { templateModelRegistry, modelCatalog: completeModelCatalog, configuredRuntimeModels, inlineProviderModels: pluginGeneration.inlineProviderModels }; } /** Reprojects retained inventory without carrying capabilities from a retired runtime. */ function materializePreparedModelCatalog(snapshot, runtimeCapabilityModels) { const materialized = { ...snapshot }; const sourceEntries = snapshot.entries; const runtimeByKey = new Map(runtimeCapabilityModels.map(({ provider, modelId, model }) => [modelCatalogEntryKey({ provider, id: modelId }), toStaticCatalogEntry(model)])); const project = (entries) => entries.map((entry) => { const runtime = runtimeByKey.get(modelCatalogEntryKey(entry)); if (!runtime) return entry; const thinkingPolicyProvider = runtime.provider; if (entry.configuredReasoning !== void 0) return { ...entry, thinkingPolicyProvider }; const params = runtime.params || entry.params ? { ...runtime.params, ...entry.params } : void 0; const compat = runtime.compat || entry.compat ? { ...runtime.compat, ...entry.compat } : void 0; return { ...entry, thinkingPolicyProvider, ...runtime.reasoning !== void 0 ? { reasoning: runtime.reasoning } : {}, ...params ? { params } : {}, ...compat ? { compat } : {} }; }); materialized.entries = project(sourceEntries); materialized.routeVariants = project(snapshot.routeVariants); if (snapshot.staticEntries) materialized.staticEntries = project(snapshot.staticEntries); if (isPreparedModelCatalogFull(snapshot)) markPreparedModelCatalogFull(materialized); const auth = getPreparedModelFullCatalogAuth(snapshot); if (auth) setPreparedModelFullCatalogAuth(materialized, auth); return materialized; } /** Reports whether a catalog came from the complete prepared-catalog build path. */ const isPreparedModelCatalogFull = (snapshot) => fullModelCatalogSnapshots.has(snapshot); /** Restores process-local provenance after a complete catalog crosses a worker boundary. */ function markPreparedModelCatalogFull(snapshot) { fullModelCatalogSnapshots.add(snapshot); return snapshot; } //#endregion export { prepareFullCatalogFacts as i, markPreparedModelCatalogFull as n, materializePreparedModelCatalog as r, isPreparedModelCatalogFull as t };