openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 7.49 kB
JavaScript
import{r as resolveAgentConfig}from"./agent-scope-config-CG9CFpGX.mjs";import{t as AuthProfileAuthorizationError}from"./authorization-contract-DUr5-0ES.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{d as isConfiguredKeyAuthSource}from"./provider-model-route-auth-ClM4Emo4.mjs";import{o as resolveProviderModelAuthPolicy}from"./model-runtime-policy-DJvvlwBk.mjs";import{t as isCliProvider}from"./model-selection-cli-K7oSL0Pc.mjs";import{c as resolveCliRuntimeExecutionProvider}from"./model-runtime-aliases-BFQ__k4Y.mjs";import{i as resolveSessionRuntimeOverrideForProvider}from"./session-runtime-compat-DGwJiPrH.mjs";import{o as resolveEffectiveAgentRuntime}from"./thinking-runtime-V6V09nGt.mjs";import{i as ensureAuthProfileStoreAsync}from"./store-runtime-GNz-2GjY.mjs";import{r as resolveAgentHarnessSelectionDecision}from"./selection-decision-n4kDZTQq.mjs";import{i as resolveCliExecutionAuthSelection,n as cliBackendAcceptsAuthProfileForwarding}from"./cli-execution-auth-C5lp_Ebz.mjs";import{r as resolveSessionAuthSelection}from"./session-override-CpXY_45d.mjs";import{n as workerInferencePlacement}from"./inference-placement-BT7fCd4s.mjs";import{r as prepareAgentRuntimeAuth}from"./prepare-auth-CkYiXkUT.mjs";import{n as resolveCronModelSelectionOwner,t as resolveCronModelSelection}from"./model-selection-DaIqsunw.mjs";import{t as captureAuthProfileAuthorization}from"./authorization-D4T0_zjk.mjs";import{t as resolveCronCandidateExecution}from"./candidate-execution-UQZUpvhJ.mjs";
//!src/cron/inference-binding.runtime.ts
async function captureCronInferenceBinding(e){const t=await resolveCronModelSelectionOwner({cfg:e.cfg,agentId:e.agentId,requiredAgentId:e.agentId});const{config:n,agentId:r,agentDir:i,workspaceDir:a}=t;const o=await resolveCronModelSelection({cfg:n,owner:t,agentConfigOverride:resolveAgentConfig(n,r),agentId:r,agentDir:i,workspaceDir:a,payloadModel:e.model,sessionEntry:e.executionSessionEntry??{},isGmailHook:e.isGmailHook===true});if(!o.ok)throw new Error(o.error);const s=resolveCliRuntimeExecutionProvider({cfg:n,agentId:r,provider:o.provider,modelId:o.model,authProfileId:o.configuredProfileId});const resolveExecution=e=>resolveCronCandidateExecution({cfg:n,agentId:r,provider:o.provider,model:o.model,sessionRuntimeOverride:resolveSessionRuntimeOverrideForProvider({provider:o.provider,entry:e,cfg:n}),sessionEntry:e,authProfileId:o.configuredProfileId},{isCliProvider,resolveEffectiveAgentRuntime});if(s&&!cliBackendAcceptsAuthProfileForwarding({provider:s,config:n,agentId:r}))return;const c=e.sessionEntry?.providerOverride??e.sessionEntry?.modelProvider;const l=c&&c!==o.provider?void 0:e.sessionEntry;let u;if(s){const t=o.configuredProfileId??l?.authProfileOverride;const r=await resolveCliExecutionAuthSelection({cliExecutionProvider:s,authProfileProvider:o.provider,config:n,agentDir:i,selected:t?{authProfileId:t,authProfileIdSource:o.configuredProfileId||l?.authProfileOverrideSource===`user`||l?.authProfileOverrideSource===`user-link`?`user`:`auto`}:void 0});if(r?.kind===`native`&&o.configuredProfileId){const{runtime:t,executionProvider:n,cliExecution:r}=resolveExecution(e.runtimeSessionEntry);if(!r||n!==s||t!==s)throw new Error(`The selected native account is unavailable on automation runtime ${t}.`);if(e.recordedRuntime&&e.recordedRuntime!==t)throw new Error(`The automation runs on runtime ${e.recordedRuntime}, which is unavailable for this account; the edit would move it to runtime ${t}.`);return null}if(r?.kind!==`stored`)return;u={profileId:r.profileId,source:o.configuredProfileId?`user`:`auto`,routeRequirement:void 0}}else u=await resolveSessionAuthSelection({cfg:n,agentId:r,agentDir:i,provider:o.provider,modelId:o.model,configuredProfileId:o.configuredProfileId??l?.authProfileOverride,sessionEntry:o.configuredProfileId?void 0:l,isNewSession:false});const d=n.cloudWorkers?.requiredProfile;const f=d?n.cloudWorkers?.profiles?.[d]:void 0;if(!u&&f&&workerInferencePlacement({providerId:f.provider,profileSnapshot:f})===`worker`)return;const p=await ensureAuthProfileStoreAsync(i,{profileId:u?.profileId,allowKeychainPrompt:false,config:n});if(!u){const t=resolveAgentHarnessSelectionDecision({provider:o.provider,modelId:o.model,config:n,agentId:r});const[a]=prepareAgentRuntimeAuth({provider:o.provider,modelId:o.model,config:n,agentId:r,agentDir:i,authProfileStore:p,harnessId:t.selectedHarnessId,harnessRuntime:t.selectedHarnessId,harnessAuthBootstrap:t.harness?.authBootstrap}).attempts;if(a?.kind!==`profile`){const t=a?.plan.credentialSource;if(e.recoverConfiguredKeyFrom&&!Object.hasOwn(p.profiles,e.recoverConfiguredKeyFrom)&&t?.kind===`direct`&&(t.evidence===`environment`||t.evidence===`provider-config`)){const{runtime:t}=resolveExecution(e.runtimeSessionEntry);if(e.recordedRuntime&&e.recordedRuntime!==t)throw new Error(`The automation runs on runtime ${e.recordedRuntime}, which is unavailable for this account; the edit would move it to runtime ${t}.`);return null}if(t?.kind===`direct`&&!isConfiguredKeyAuthSource(t))throw new Error(`Automation requires a stored inference account or a key in the environment or provider config. Select an account with model@profile.`);return}u={profileId:a.profileId,source:a.plan.forwardedAuthProfileSource??`auto`,routeRequirement:a.plan.modelRoute?.authRequirement}}const m=await e.authorizeProfile?.(u.profileId,!o.configuredProfileId&&u.profileId===l?.authProfileOverride);const h=p.profiles[u.profileId];if(!h)throw new Error(`Automation requires an available stored inference account.`);const g=u.routeRequirement??resolveProviderModelAuthPolicy({provider:o.provider,mode:h.type,authFlow:h.type===`oauth`?h.authFlow:void 0}).authRequirement;if(!g)throw new Error(`Automation requires a supported stored inference authentication route.`);const{runtime:_}=resolveExecution(e.recordedRuntime?{agentRuntimeOverride:e.recordedRuntime}:e.runtimeSessionEntry);const v=await captureAuthProfileAuthorization({profileId:u.profileId,agentDir:i,cfg:n,assertCurrent:m??(()=>{})});let y=false;try{v.assertCurrent();e.retainAuthorization?.(v);y=e.retainAuthorization!==void 0;return{version:1,provider:o.provider,profileId:u.profileId,authorizationId:v.authorizationId,authRequirement:g,runtime:_,source:o.configuredProfileId||l?.authProfileOverrideSource===`user`||l?.authProfileOverrideSource===`user-link`||!l?.authProfileOverride&&u.source===`user`?`user`:`auto`}}finally{if(!y)v.dispose()}}async function acquireCronInferenceAuthorization(e){const t=e.job?`Automation ${e.job.name?.trim()?`"${e.job.name.trim()}" (${e.job.id})`:e.job.id}`:`This automation`;const n=e.job?.id??`<jobId>`;let r;try{r=await captureAuthProfileAuthorization({profileId:e.binding.profileId,agentDir:e.agentDir,cfg:e.cfg,assertCurrent(){}});if(r.authorizationId!==e.binding.authorizationId)throw new Error(`${t} runs on account ${e.binding.profileId}, which was signed in again or replaced since the job recorded it. To keep using it: openclaw automations edit ${n} --model <provider/model>@${e.binding.profileId}.`);r.assertCurrent();return r}catch(i){r?.dispose();if(i instanceof AuthProfileAuthorizationError&&i.code===`MCP_AUTHORIZATION_RETIRED`)throw new Error(`${t} runs on account ${e.binding.profileId}, which was removed or signed out. Sign in again, or choose another account: openclaw automations edit ${n} --model <provider/model>@<profileId> (list accounts: openclaw models auth list).`,{cause:i});throw i}}export{captureCronInferenceBinding as n,acquireCronInferenceAuthorization as t};