UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.31 kB
import{t as createSubsystemLogger}from"./subsystem-DLCDFvCH.mjs";import{qc as validateModelsAuthOrderSetParams}from"./src-BDZMFmKa.mjs";import{i as resolveProviderIdForAuth}from"./provider-auth-aliases-BRA1A5Vm.mjs";import{i as ErrorCodes}from"./missing-scope-error-CkgBgh6d.mjs";import{p as errorShape}from"./error-codes-CQNGhXT-.mjs";import{m as resolveExplicitAuthOrderSelection}from"./order-B8e_5ABM.mjs";import{n as readPreparedCatalog}from"./server-model-catalog-auth-DgYxoyva.mjs";import{t as formatForLog}from"./ws-log-DRCSDKLv.mjs";import{r as respondUnavailableOnThrow}from"./response-BYbuAh7a.mjs";import{n as defineValidatedGatewayHandler}from"./validation-CM41YclJ.mjs";import{o as setAuthProfileOrder}from"./profiles-Bp0-JifZ.mjs";import"./auth-profiles-nMUErGRQ.mjs";import{t as resolveModelAuthAgentScope}from"./model-auth-agent-scope-dS6ga2Rp.mjs";import{t as refreshModelAuthStateAfterMutation}from"./model-auth-refresh-DuOWCz8I.mjs";import{t as resolveConfigBoundProfileIds}from"./models-auth-status-config-8ZIDvApC.mjs"; //!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)})})};export{modelsAuthOrderHandlers};