mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 06:41:37 +00:00
fix(models): split scoped catalog preparation
This commit is contained in:
@@ -50,6 +50,9 @@ vi.mock("./prepared-model-runtime.js", () => {
|
||||
|
||||
vi.mock("./prepared-model-runtime.facts.js", () => ({
|
||||
isPreparedModelCatalogFull: (...args: unknown[]) => mocks.isFullCatalog(...args),
|
||||
}));
|
||||
|
||||
vi.mock("./prepared-model-runtime.scoped-catalog.js", () => ({
|
||||
prepareScopedReadOnlyModelCatalog: (...args: unknown[]) => mocks.prepareScopedCatalog(...args),
|
||||
}));
|
||||
|
||||
|
||||
@@ -12,10 +12,7 @@ import type { ModelCatalogEntry, ModelCatalogSnapshot } from "./model-catalog.ty
|
||||
import { resolvePublishedModelCatalogOwner } from "./prepared-model-catalog-owner.js";
|
||||
import { PreparedModelCatalogConfigReplacedError } from "./prepared-model-catalog.errors.js";
|
||||
import type { ResolvedPublishedModelCatalogOwner } from "./prepared-model-catalog.types.js";
|
||||
import {
|
||||
isPreparedModelCatalogFull,
|
||||
prepareScopedReadOnlyModelCatalog,
|
||||
} from "./prepared-model-runtime.facts.js";
|
||||
import { isPreparedModelCatalogFull } from "./prepared-model-runtime.facts.js";
|
||||
import {
|
||||
acquireAgentRunPreparedModelRuntime,
|
||||
acquireReadOnlyPreparedModelRuntime,
|
||||
@@ -27,6 +24,7 @@ import {
|
||||
type PreparedModelRuntimeInput,
|
||||
type PreparedModelRuntimeSnapshot,
|
||||
} from "./prepared-model-runtime.js";
|
||||
import { prepareScopedReadOnlyModelCatalog } from "./prepared-model-runtime.scoped-catalog.js";
|
||||
|
||||
export type LoadPreparedModelCatalogParams = {
|
||||
agentId?: string;
|
||||
|
||||
@@ -500,30 +500,6 @@ export function isPreparedModelCatalogFull(snapshot: ModelCatalogSnapshot): bool
|
||||
return fullModelCatalogSnapshots.has(snapshot);
|
||||
}
|
||||
|
||||
/** Builds a request-scoped read-only catalog from configured and auth-candidate providers. */
|
||||
export async function prepareScopedReadOnlyModelCatalog(
|
||||
input: PreparedModelRuntimeInput,
|
||||
providerDiscoveryProviderIds: readonly string[],
|
||||
): Promise<ModelCatalogSnapshot> {
|
||||
const scopedInput = input.readOnly ? input : { ...input, readOnly: true };
|
||||
const { agentFacts, workspaceFacts } = await prepareWorkspaceBuildGroup([scopedInput], "static", {
|
||||
providerDiscoveryProviderIds,
|
||||
});
|
||||
const agentFactsForInput = agentFacts[0];
|
||||
if (!agentFactsForInput) {
|
||||
throw new Error("scoped prepared model catalog facts are missing");
|
||||
}
|
||||
const catalogSource = await prepareAgentCatalogSource(
|
||||
agentFactsForInput,
|
||||
workspaceFacts,
|
||||
"static",
|
||||
false,
|
||||
);
|
||||
return (
|
||||
await prepareFullCatalogFacts(agentFactsForInput, workspaceFacts, "static", catalogSource)
|
||||
).modelCatalog;
|
||||
}
|
||||
|
||||
function modelCatalogEntryKey(entry: Pick<ModelCatalogEntry, "id" | "provider">): string {
|
||||
return `${normalizeProviderId(entry.provider)}\0${entry.id.trim().toLowerCase()}`;
|
||||
}
|
||||
|
||||
31
src/agents/prepared-model-runtime.scoped-catalog.ts
Normal file
31
src/agents/prepared-model-runtime.scoped-catalog.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { ModelCatalogSnapshot } from "./model-catalog.types.js";
|
||||
import {
|
||||
prepareAgentCatalogSource,
|
||||
prepareFullCatalogFacts,
|
||||
prepareWorkspaceBuildGroup,
|
||||
} from "./prepared-model-runtime.facts.js";
|
||||
import type { PreparedModelRuntimeInput } from "./prepared-model-runtime.types.js";
|
||||
|
||||
/** Builds a request-scoped read-only catalog from configured and auth-candidate providers. */
|
||||
export async function prepareScopedReadOnlyModelCatalog(
|
||||
input: PreparedModelRuntimeInput,
|
||||
providerDiscoveryProviderIds: readonly string[],
|
||||
): Promise<ModelCatalogSnapshot> {
|
||||
const scopedInput = input.readOnly ? input : { ...input, readOnly: true };
|
||||
const { agentFacts, workspaceFacts } = await prepareWorkspaceBuildGroup([scopedInput], "static", {
|
||||
providerDiscoveryProviderIds,
|
||||
});
|
||||
const agentFactsForInput = agentFacts[0];
|
||||
if (!agentFactsForInput) {
|
||||
throw new Error("scoped prepared model catalog facts are missing");
|
||||
}
|
||||
const catalogSource = await prepareAgentCatalogSource(
|
||||
agentFactsForInput,
|
||||
workspaceFacts,
|
||||
"static",
|
||||
false,
|
||||
);
|
||||
return (
|
||||
await prepareFullCatalogFacts(agentFactsForInput, workspaceFacts, "static", catalogSource)
|
||||
).modelCatalog;
|
||||
}
|
||||
@@ -163,7 +163,8 @@ vi.mock("../logging/subsystem.js", () => ({
|
||||
|
||||
const { getPreparedModelRuntimeSnapshot, refreshPreparedModelRuntimeSnapshots } =
|
||||
await import("./prepared-model-runtime.js");
|
||||
const { prepareScopedReadOnlyModelCatalog } = await import("./prepared-model-runtime.facts.js");
|
||||
const { prepareScopedReadOnlyModelCatalog } =
|
||||
await import("./prepared-model-runtime.scoped-catalog.js");
|
||||
const { resetPreparedModelRuntimeSnapshotsForTest } =
|
||||
await import("./prepared-model-runtime.test-support.js");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user