fix(models): split scoped catalog preparation

This commit is contained in:
Vincent Koc
2026-08-01 11:40:54 +02:00
parent efe83bcefa
commit 05e95346bd
5 changed files with 38 additions and 29 deletions

View File

@@ -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),
}));

View File

@@ -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;

View File

@@ -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()}`;
}

View 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;
}

View File

@@ -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");