UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.7 kB
import{_ as resolveDefaultAgentId,a as resolveAgentDir,f as resolveAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{c as resolveCliRuntimeCanonicalProvider}from"./cli-backends-BDgFsc0L.mjs";import{c as resolveCliRuntimeExecutionProvider,i as isCliRuntimeAliasForProvider}from"./model-runtime-aliases-BFQ__k4Y.mjs";import{r as listModelCatalogObservedRoutes,t as createModelCatalogSnapshotView}from"./model-catalog-view-Dlcu0aHX.mjs";import{r as resolveAgentHarnessSelectionDecision}from"./selection-decision-n4kDZTQq.mjs";import{n as resolveEmbeddedCliBackendDispatchEligibilityAsync}from"./cli-backend-dispatch-eligibility-BenldZy7.mjs";import{i as preparedAgentRuntimeProfileAttemptHasCandidate,n as canRunPreparedAgentRuntimeAuthAttempt,r as prepareAgentRuntimeAuth}from"./prepare-auth-CkYiXkUT.mjs"; //!src/agents/isolated-completion-route.ts function resolveIsolatedCompletionProvider(e){const t=resolveCliRuntimeCanonicalProvider({runtime:e.provider,config:e.config,includeSetupRegistry:true});const n=e.agentHarnessRuntimeOverride??(t?e.provider:void 0);return{provider:t??e.provider,...n?{runtimeOverride:n}:{}}}async function resolveIsolatedCompletionRoute(e){const t=resolveAgentHarnessSelectionDecision({provider:e.provider,modelId:e.model,config:e.config,agentId:e.agentId,agentHarnessRuntimeOverride:e.runtimeOverride});const n=e.runtimeOverride??t.policy.runtime;if(isCliRuntimeAliasForProvider({runtime:n,provider:e.provider,cfg:e.config}))return{selection:t,cliOwner:n};if(e.explicitRuntimeOverride)return{selection:t};const r=resolveCliRuntimeExecutionProvider({provider:e.provider,cfg:e.config,agentId:e.agentId,modelId:e.model,authProfileId:e.authProfileId,preparedAuthStore:e.preparedAuthStore})??(await resolveEmbeddedCliBackendDispatchEligibilityAsync({provider:e.provider,model:e.model,agentId:e.agentId,authProfileId:e.authProfileId,config:e.config,agentDir:e.agentDir,workspaceDir:e.workspaceDir,preparedAuthStore:e.preparedAuthStore}))?.provider;return r?{selection:t,cliOwner:r}:{selection:t}}function selectIsolatedHarnessAuthAttempt(e){if(e.kind!==`profile`)return e;return{...e,plan:{...e.plan,forwardedAuthProfileId:e.profileId,forwardedAuthProfileCandidateIds:[e.profileId]}}}function resolveIsolatedCompletionAuthorizationOwner(e){return e?.harnessAuthProvider&&(e.modelRoute?.authRequirement!==`api-key`||e.selectedAuthMode===`oauth`)?`harness`:`host`}async function resolveIsolatedCompletionRuntime(e){const t=e.config??{};try{const n=e.agentId??resolveDefaultAgentId(t);const{provider:r,runtimeOverride:i}=resolveIsolatedCompletionProvider({provider:e.provider,config:t,agentHarnessRuntimeOverride:e.agentHarnessRuntimeOverride});const a=await resolveIsolatedCompletionRoute({config:t,provider:r,model:e.model,authProfileId:e.authProfileId,agentId:n,agentDir:e.agentDir??resolveAgentDir(t,n),workspaceDir:e.workspaceDir??resolveAgentWorkspaceDir(t,n),runtimeOverride:i,explicitRuntimeOverride:e.agentHarnessRuntimeOverride,preparedAuthStore:e.preparedAuth?.preparedAuthStore});if(a.cliOwner)return{id:a.cliOwner,kind:`cli`};const{harness:o,selectedHarnessId:s}=a.selection;if(!o)return{id:s,kind:`api`};if(!o.runIsolatedCompletionV2&&!o.runIsolatedCompletion)return;if(o.resolveIsolatedCompletionRuntime){let i=`host`;if(o.runIsolatedCompletionV2&&o.authBootstrap===`harness`){const a=e.preparedAuth;if(!a)return;const s=createModelCatalogSnapshotView(t,a.snapshot).variantsOf({provider:r,id:e.model});const{attempts:c}=prepareAgentRuntimeAuth({provider:r,modelId:e.model,observedRoutes:s?listModelCatalogObservedRoutes(s):void 0,config:t,agentId:n,agentDir:e.agentDir,workspaceDir:e.workspaceDir,metadataSnapshot:a.metadataSnapshot,authProfileStore:a.preparedAuthStore,sessionAuthProfileId:e.authProfileId,sessionAuthProfileSource:e.authProfileId?`user`:void 0,...e.authProfileId?{allowAuthProfileFallback:false}:{},harnessId:o.id,harnessRuntime:o.id,harnessAuthBootstrap:o.authBootstrap});const l=c.find(t=>{const n=selectIsolatedHarnessAuthAttempt(t);return canRunPreparedAgentRuntimeAuthAttempt({attempt:n,priorProfileAttempted:false})&&(n.kind!==`profile`||preparedAgentRuntimeProfileAttemptHasCandidate({attempt:n,store:a.preparedAuthStore,modelId:e.model}))});if(!l)return;i=resolveIsolatedCompletionAuthorizationOwner(l.plan)}if(o.resolveIsolatedCompletionRuntime({authorizationOwner:i})===`openclaw`)return{id:`openclaw`,kind:`api`}}return{id:s,kind:`harness`,harnessLabel:o.label}}catch{return}}export{selectIsolatedHarnessAuthAttempt as a,resolveIsolatedCompletionRuntime as i,resolveIsolatedCompletionProvider as n,resolveIsolatedCompletionRoute as r,resolveIsolatedCompletionAuthorizationOwner as t};