openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
89 lines (88 loc) • 3.79 kB
JavaScript
import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs";
import { Bc as validateModelsAuthOrderSetParams } from "./src-BX8OAe1J.mjs";
import { i as resolveProviderIdForAuth } from "./provider-auth-aliases-CgGlzANu.mjs";
import { t as ErrorCodes } from "./gateway-error-details-B69XiHdh.mjs";
import { p as errorShape } from "./error-codes-BzF7aRQ0.mjs";
import { m as resolveExplicitAuthOrderSelection } from "./order-jOvee2J6.mjs";
import { n as readPreparedCatalog } from "./server-model-catalog-auth-DPSO0-N0.mjs";
import { t as formatForLog } from "./ws-log-CbOV6uhk.mjs";
import { r as respondUnavailableOnThrow } from "./response-C7fEiIN1.mjs";
import { n as defineValidatedGatewayHandler } from "./validation-DwNk6A-B.mjs";
import { o as setAuthProfileOrder } from "./profiles-DbLHYG1P.mjs";
import "./auth-profiles-VRLhewIH.mjs";
import { t as resolveModelAuthAgentScope } from "./model-auth-agent-scope-D5aeJRSp.mjs";
import { t as refreshModelAuthStateAfterMutation } from "./model-auth-refresh-0zj3uFap.mjs";
import { t as resolveConfigBoundProfileIds } from "./models-auth-status-config-DnhTF941.mjs";
//#region src/gateway/server-methods/models-auth-order.ts
const log = createSubsystemLogger("models-auth-order");
const modelsAuthOrderHandlers = { "models.authOrderSet": defineValidatedGatewayHandler("models.authOrderSet", validateModelsAuthOrderSetParams, async ({ params: e, respond: t, context: n }) => {
const r = e.provider;
const i = e.profileIds ?? null;
const rejectInvalidOrder = (e) => t(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, e));
await respondUnavailableOnThrow(t, async () => {
const a = n.getRuntimeConfig();
const o = resolveModelAuthAgentScope(a, e.agentId);
if (!o.ok) {
t(false, void 0, o.error);
return;
}
const s = await readPreparedCatalog(n, o.agentId);
if (!s) throw new Error(`prepared model auth owner is unavailable (${o.agentId})`);
const c = {
config: s.config,
workspaceDir: s.workspaceDir,
metadataSnapshot: s.metadataSnapshot,
includeUntrustedWorkspacePlugins: false
};
const l = resolveProviderIdForAuth(r, c);
const u = resolveExplicitAuthOrderSelection({
storeOrder: s.authStore.order,
configuredOrder: s.config.auth?.order,
providerKey: r,
providerAuthKey: l
});
if (i && u.order !== void 0 && !u.fromStore) {
rejectInvalidOrder(`profile priority for provider ${r} is controlled by auth configuration`);
return;
}
const d = Object.entries(s.authStore.profiles).filter(([, e]) => resolveProviderIdForAuth(e.provider, {
...c,
storedCredential: true
}) === l).map(([e]) => e);
const f = resolveConfigBoundProfileIds(s.config, s.authStore, c);
if (i && d.some((e) => f.has(e))) {
rejectInvalidOrder(`profile priority for provider ${r} is controlled by provider configuration`);
return;
}
const p = i?.find((e) => !d.includes(e));
if (p) {
rejectInvalidOrder(`profileId ${p} is unavailable for provider ${r}`);
return;
}
if (i && i.length !== d.length) {
rejectInvalidOrder(`profileIds must include every available profile for provider ${r}`);
return;
}
if (!await setAuthProfileOrder({
agentDir: s.agentDir,
provider: l,
order: i
})) {
t(false, void 0, errorShape(ErrorCodes.UNAVAILABLE, "auth profile order is temporarily unavailable"));
return;
}
const m = {
provider: r,
profileIds: i
};
try {
await refreshModelAuthStateAfterMutation(n.getRuntimeConfig, o.agentId);
} catch (e) {
log.warn(`auth profile order saved but runtime publication failed: ${formatForLog(e)}`);
m.warning = "Profile priority saved. Live status is unavailable; refresh Models or restart the Gateway.";
}
t(true, m, void 0);
});
}) };
//#endregion
export { modelsAuthOrderHandlers };