openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.27 kB
JavaScript
import{s as isGatewayTransportError}from"./transport-error-COMVGbZH.mjs";import{f as isImplicitLocalGatewayTarget,g as GatewayLocalBackendSharedAuthUnavailableError,l as isGatewayClientRequestError,r as callGateway}from"./call-CVqWsTxX.mjs";
//!src/commands/models/auth-refresh.ts
async function refreshProviderAuthAfterLogin(e){if(!e.refreshAfterLogin)return refreshRunningGatewayAuthState(e.agentId,`login`,e.runtime);try{await e.refreshAfterLogin(e.agentId);return`refreshed`}catch{e.signal?.throwIfAborted();e.assertCurrent?.();return`gateway-rejected`}}async function refreshSavedAuthAfterSettingsFailure(e){try{e.signal?.throwIfAborted();e.assertCurrent?.();await refreshProviderAuthAfterLogin(e)}catch{}}async function refreshRunningGatewayAuthState(e,t,n){let r=false;let i;try{i=await isImplicitLocalGatewayTarget({});if((await callGateway({method:`models.authRefresh`,params:{operation:t,...e?{agentId:e}:{}},timeoutMs:3e3,requireLocalBackendSharedAuth:true,onHelloOk:()=>{r=true}})).refreshed)return`refreshed`}catch(t){if(isGatewayClientRequestError(t)&&t.gatewayCode===`INVALID_REQUEST`&&t.message===`unknown method: models.authRefresh`)await callGateway({method:`models.authStatus`,params:{refresh:true,...e?{agentId:e}:{}},timeoutMs:3e3,requireLocalBackendSharedAuth:true}).catch(()=>void 0);if(t instanceof GatewayLocalBackendSharedAuthUnavailableError&&i===false){n.error(`Warning: Model auth changes were saved on this host, but the configured Gateway does not share this auth state. Run the auth command on the Gateway host (the far end of any SSH tunnel).`);return`gateway-rejected`}if(i===true&&!r&&isGatewayTransportError(t)&&t.kind===`closed`&&t.code===void 0&&t.reason?.includes(`ECONNREFUSED`))return`gateway-unreachable`}n.error(i===true?`Warning: Model auth changes were saved, but the ${r?`running`:`local`} Gateway could not refresh them. Run \`openclaw gateway restart\` to apply the saved changes.`:`Warning: Model auth changes were saved, but the configured Gateway could not be identified or refreshed. Apply the auth change on the Gateway host, or restart it there.`);return r?`gateway-rejected`:`gateway-unreachable`}export{refreshRunningGatewayAuthState as n,refreshSavedAuthAfterSettingsFailure as r,refreshProviderAuthAfterLogin as t};