feat: unify installation model catalog

This commit is contained in:
Codex
2026-09-02 18:45:33 +02:00
parent ae053961a3
commit 7b7927bfe5
169 changed files with 3696 additions and 4572 deletions
+2 -57
View File
@@ -6,7 +6,7 @@ import {
type AuthOperationPrecondition,
} from "../auth/authOperation";
import { getSettings } from "./settings";
import { getWorkspace, listWorkspaces } from "./workspaces";
import { listWorkspaces } from "./workspaces";
import {
WORKSPACE_POLICY_ERROR, WORKSPACE_SUMMARY_ERROR, WorkspaceSelectionError, workspacePolicyGate,
workspacePreferences, type WorkspacePreference,
@@ -34,24 +34,6 @@ async function selectedPreferences(precondition?: AuthOperationPrecondition): Pr
});
}
function reconcileWorkspacePolicy(preferences: WorkspacePreference, allowed: readonly string[], defaultModel?: string) {
if (allowed.length === 0) throw new WorkspaceSelectionError(WORKSPACE_POLICY_ERROR);
const selected = preferences.provider && preferences.model
? `${preferences.provider}/${preferences.model}`
: undefined;
if (selected && allowed.includes(selected)) return preferences;
const replacement = defaultModel && allowed.includes(defaultModel) ? defaultModel : allowed[0];
const separator = replacement.indexOf("/");
if (separator <= 0 || separator === replacement.length - 1) {
throw new WorkspaceSelectionError(WORKSPACE_POLICY_ERROR);
}
return workspacePreferences.save({
...preferences,
provider: replacement.slice(0, separator),
model: replacement.slice(separator + 1),
});
}
async function ensureWorkspaceSelectionPolicy(precondition?: AuthOperationPrecondition): Promise<WorkspacePreference> {
while (true) {
requireAuthOperationPrecondition(precondition);
@@ -104,45 +86,8 @@ async function ensureWorkspaceSelectionPolicy(precondition?: AuthOperationPrecon
throw new WorkspaceSelectionError(WORKSPACE_POLICY_ERROR);
}
workspacePolicyGate.select(workspaceId);
const outcome = await Promise.race([
getWorkspace(workspaceId).then(
(record) => ({ kind: "record" as const, record }),
() => ({ kind: "error" as const }),
),
workspacePolicyGate.waitForCurrent(() => workspacePreferences.load()).then(
(selection) => ({ kind: "selection" as const, selection }),
),
]);
requireAuthOperationPrecondition(precondition);
if (outcome.kind === "selection") {
if (outcome.selection.workspaceId !== workspaceId) continue;
return outcome.selection;
}
if (outcome.kind === "error") {
requireAuthOperationPrecondition(precondition);
if (workspacePreferences.load().workspaceId !== workspaceId) continue;
workspacePolicyGate.reject(workspaceId);
throw new WorkspaceSelectionError(WORKSPACE_POLICY_ERROR);
}
const { record } = outcome;
requireAuthOperationPrecondition(precondition);
if (workspacePreferences.load().workspaceId !== workspaceId) continue;
let selection: WorkspacePreference;
try {
selection = reconcileWorkspacePolicy(
preferences,
record.workspace.llm_policy.allowed,
record.workspace.llm_policy.default,
);
} catch (error) {
requireAuthOperationPrecondition(precondition);
workspacePolicyGate.reject(workspaceId);
throw error;
}
requireAuthOperationPrecondition(precondition);
workspacePolicyGate.resolve(workspaceId);
requireAuthOperationPrecondition(precondition);
if (workspacePreferences.load().workspaceId === workspaceId) return selection;
return workspacePreferences.load();
}
}