openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 10.9 kB
JavaScript
import{r as settleWithCleanup}from"./error-graph-internal-Bt2pFJBM.mjs";import{l as trackAsyncWork}from"./async-work-scope-DBcxYU4O.mjs";import{t as createLegacyPluginSdkReplyDispatch}from"./legacy-sdk-reply-dispatch-BBfp03px.mjs";import{l as withPluginRuntimeGatewayRequestScope,o as getPluginRuntimeGatewayRequestScope}from"./gateway-request-scope-7deHmsb_.mjs";import{i as getLegacyPluginSdkResourceHost,n as bindLegacyPluginSdkResourceHost,r as getBoundLegacyPluginSdkResourceHost,t as LegacyPluginSdkResourceHost}from"./legacy-sdk-resource-host-9HMZFK01.mjs";import{i as listAgentIds}from"./agent-roster-4XrgUgPK.mjs";import"./agent-scope-config-CG9CFpGX.mjs";import{a as getOpenClawDatabaseMaintenanceScope}from"./openclaw-state-maintenance-context-D-pYfco8.mjs";import{t as _usingCtx}from"./usingCtx-CUVyQ_FT.mjs";import{t as createSubsystemLogger}from"./subsystem-DLCDFvCH.mjs";import{t as GatewayScheduler}from"./gateway-scheduler-C24cnvAu.mjs";import{h as readRuntimeConfig}from"./runtime-snapshot-Bg5K4JNu.mjs";import{s as withPluginRetentionOwner}from"./plugin-setup-module-DKdTsN2H.mjs";import{C as withAgentRunLifecycleGeneration,r as captureAgentRunLifecycleGeneration}from"./agent-events-Dz03BVGI.mjs";import{n as withPluginRuntimeGenerationScope}from"./generation-scope-CxHnQlew.mjs";import"./io-Di_yuX3t.mjs";import{t as createAgentRuntimeApprovalAuthorityValidator}from"./agent-runtime-approval-authority-cp7kvQ_b.mjs";import{t as bindSessionRowProjection}from"./session-row-projection-access-w2LnU_PB.mjs";import{i as scopePreparedModelRuntimeLease}from"./prepared-model-runtime-generation-scope-Cf2EOaL7.mjs";import{t as ensureGlobalHookRunner}from"./hook-runner-global-DNCi6wD6.mjs";import{t as acquireAgentRunPreparedModelRuntime}from"./prepared-model-runtime-Bq1P9DhS.mjs";import{n as readPreparedServerMethodModelCatalogs}from"./optional-model-catalog-DpWWaFJW.mjs";import{r as registerGatewayModelCatalogPrivateAccess}from"./server-model-catalog-auth-DgYxoyva.mjs";import{i as createChatRunState}from"./server-chat-state-CvHqVUAH.mjs";import{r as runAgentCleanupStep}from"./run-cleanup-timeout-B__J_Jbc.mjs";import{d as createCronCreatorAuthorityCapability,p as runWithCronCreatorAuthorityCapability}from"./cron-creator-authority-context-C9CHxQOU.mjs";import{a as readPreparedGatewayModelCatalogBatch,i as readPreparedGatewayModelCatalog,n as loadGatewayModelCatalogSnapshot,o as readPreparedGatewayModelCatalogOwnerSnapshot,r as loadPreparedGatewayModelCatalogSnapshot,t as loadGatewayModelCatalog}from"./server-model-catalog-BK09_SMU.mjs";import{p as resolveAgentCommandDeps}from"./runtime-loaders-BSSaM1bq.mjs";import{t as measureAgentStartup}from"./startup-timing-CsYAzFF_.mjs";import{t as prepareAgentCommandExecution}from"./prepare-BefXqcQr.mjs";import{t as withLocalAgentCronJobsRemoved}from"./local-service-CBXX4sjU.mjs";import{t as loadGatewayConfigRevisionProjector}from"./config-revision-token-Caa8t3k-.mjs";import{t as NodeRegistry}from"./node-registry-Bx9seCKj.mjs";import{t as resolveSessionRequestTargets}from"./session-request-targets-BysfKasL.mjs";
//!src/gateway/local-request-context.ts
async function cronUnavailable(){throw new Error(`Cron is unavailable in local embedded agent gateway context.`)}const unavailableCron={start:cronUnavailable,stop:()=>{},pauseScheduling:()=>{},resumeScheduling:()=>{},status:cronUnavailable,list:cronUnavailable,listPage:cronUnavailable,add:cronUnavailable,update:cronUnavailable,updateWithPrecondition:cronUnavailable,remove:cronUnavailable,removeStaleJobFamily:cronUnavailable,removeAgentJobsTransactional:cronUnavailable,quiesceJobs:cronUnavailable,run:cronUnavailable,enqueueRun:cronUnavailable,readEventSources:cronUnavailable,runEvent:cronUnavailable,waitForManualRun:cronUnavailable,getJob:()=>void 0,getLoadedJobs:()=>void 0,readJob:async()=>void 0,readScratch:cronUnavailable,writeScratch:cronUnavailable,getDefaultAgentId:()=>void 0,wake:async()=>({ok:false,reason:`unwakeable-session-key`})};async function createLocalGatewayRequestContext(e){const t=createSubsystemLogger(`gateway/local`);const n=getLegacyPluginSdkResourceHost();const r={...unavailableCron,removeAgentJobsTransactional:async(t,n)=>await withLocalAgentCronJobsRemoved(t,e.getRuntimeConfig,n)};const i=/* @__PURE__ */ new Set;const a=createChatRunState();const loadCatalogSnapshot=t=>loadGatewayModelCatalogSnapshot({...t,getConfig:e.getRuntimeConfig});registerGatewayModelCatalogPrivateAccess(loadCatalogSnapshot,{loadDeferred:t=>loadPreparedGatewayModelCatalogSnapshot({...t,getConfig:e.getRuntimeConfig}),readPrepared:t=>readPreparedGatewayModelCatalogOwnerSnapshot({...t,getConfig:e.getRuntimeConfig})});const o={localEmbedded:true,trackExecution:trackAsyncWork,deps:e.deps,configRevisionProjector:await loadGatewayConfigRevisionProjector({env:process.env}),cron:r,cronStorePath:``,getRuntimeConfig:e.getRuntimeConfig,validateAgentRuntimeApprovalAuthority:createAgentRuntimeApprovalAuthorityValidator(),resolveSessionRequestTargets:e=>resolveSessionRequestTargets({...e,context:o}),isConfigReloadSettled:()=>false,resolveTerminalLaunchPolicy:()=>({ok:false,block:{kind:`disabled`}}),isTerminalEnabled:()=>false,loadGatewayModelCatalog:t=>loadGatewayModelCatalog({...t,getConfig:e.getRuntimeConfig}),loadGatewayModelCatalogSnapshot:loadCatalogSnapshot,readPreparedGatewayModelCatalog:t=>readPreparedGatewayModelCatalog({...t,getConfig:e.getRuntimeConfig}),readPreparedGatewayModelCatalogBatch:(t,n)=>readPreparedGatewayModelCatalogBatch(t,{...n,getConfig:e.getRuntimeConfig}),readChatMetadata:async()=>{throw new Error(`Chat metadata is unavailable in local embedded agent gateway context.`)},getHealthCache:()=>null,refreshHealthSnapshot:async()=>({}),logHealth:{error:e=>t.error(e)},logGateway:t,publishPresence:()=>{},getPresenceSnapshot:()=>{throw new Error(`Presence requires a running Gateway connection.`)},broadcast:()=>{},broadcastToConnIds:()=>{},nodeSendToSession:()=>{},nodeSendToAllSubscribed:()=>{},nodeSubscribe:()=>{},nodeUnsubscribe:()=>{},nodeUnsubscribeAll:()=>{},hasConnectedTalkNode:async()=>false,nodeRegistry:new NodeRegistry,agentRunSeq:/* @__PURE__ */ new Map,chatRunState:a,addChatRun:a.registry.add,removeChatRun:a.registry.remove,subscribeSessionEvents:e=>{i.add(e)},unsubscribeSessionEvents:e=>{i.delete(e)},forgetConnectionAncestors:()=>{},subscribeSessionMessageEvents:()=>void 0,unsubscribeSessionMessageEvents:()=>{},unsubscribeAllSessionEvents:e=>{i.delete(e)},getSessionEventSubscriberConnIds:()=>i,registerToolEventRecipient:()=>{},dedupe:/* @__PURE__ */ new Map,wizardSessions:/* @__PURE__ */ new Map,systemAgentSessions:/* @__PURE__ */ new Map,findRunningWizard:()=>null,purgeWizardSession:()=>{},getRuntimeSnapshot:()=>({}),startChannel:async()=>{throw new Error(`Channel start is unavailable in local embedded agent gateway context.`)},stopChannel:async()=>{throw new Error(`Channel stop is unavailable in local embedded agent gateway context.`)},markChannelLoggedOut:()=>{},wizardRunner:async()=>{throw new Error(`Onboarding wizard is unavailable in local embedded agent gateway context.`)},channelWizardRunner:async()=>{throw new Error(`Channel setup wizard is unavailable in local embedded agent gateway context.`)},broadcastVoiceWakeChanged:()=>{},broadcastVoiceWakeRoutingChanged:()=>{},unavailableGatewayMethods:/* @__PURE__ */ new Set};let s;let c;bindSessionRowProjection(o,()=>s);o.ensureSessionRowProjection=()=>{if(!c){const release=async()=>{await c?.catch(()=>{});s?.dispose();await s?.ensureMaterialized()};const t=getOpenClawDatabaseMaintenanceScope();if(t)t.own(o,`agent-resources`,release);else n.adopt(o,{release});c=import(`./session-row-projection-CFOfCltS.mjs`).then(async({createSessionRowProjection:t})=>{s=await t({cfg:e.getRuntimeConfig(),getConfig:e.getRuntimeConfig,getModelCatalog:()=>readPreparedServerMethodModelCatalogs(o,listAgentIds(e.getRuntimeConfig())),context:o})})}return c};o.createAgentTurnFacade=async e=>{const{createInternalAgentTurnFacade:t}=await import(`./internal-facade.runtime-Cm-dnVYy.mjs`);return t({...e,getContext:()=>o})};return o}async function withLocalGatewayRequestScope(e,t){const n=getPluginRuntimeGatewayRequestScope();if(n?.context||n?.resolveGatewayContext)return await t();const r=await createLocalGatewayRequestContext(e);const resolveGatewayContext=()=>r;r.resolveGatewayContext=resolveGatewayContext;bindLegacyPluginSdkResourceHost(resolveGatewayContext,getLegacyPluginSdkResourceHost());return await withPluginRuntimeGatewayRequestScope({...n,context:r,resolveGatewayContext,isWebchatConnect:n?.isWebchatConnect??(()=>false)},t)}
//!src/agents/agent-command-local.ts
async function runLocalAgentCommand(e){const t=getBoundLegacyPluginSdkResourceHost();const n=t?t.scheduler:new GatewayScheduler;const r=t??new LegacyPluginSdkResourceHost(createLegacyPluginSdkReplyDispatch());if(!t)r.bindScheduler(n);return settleWithCleanup(r.run(async()=>{const n=await measureAgentStartup(`command-dependencies`,()=>resolveAgentCommandDeps(e.deps));const r=e.opts.lifecycleGeneration??captureAgentRunLifecycleGeneration(e.opts.runId??``);return await withAgentRunLifecycleGeneration(r,()=>withLocalGatewayRequestScope({deps:n,getRuntimeConfig:readRuntimeConfig},async()=>{const i={...e.opts,lifecycleGeneration:r,senderIsOwner:e.opts.senderIsOwner??true,allowModelOverride:e.opts.allowModelOverride??true,cleanupBundleMcpOnRunEnd:t?e.opts.cleanupBundleMcpOnRunEnd:true};const a=await measureAgentStartup(`command-prepare`,()=>prepareAgentCommandExecution(i,e.runtime));try{const t=e.operatorAuthority&&a.opts.senderIsOwner===true?createCronCreatorAuthorityCapability(a.runId,{kind:`local`}):void 0;const r=t?{...a,opts:{...a.opts,cronCreatorAuthorityCapability:t}}:a;const run=()=>withPluginRetentionOwner({agentId:a.sessionAgentId,sessionKey:a.sessionKey,runId:a.runId},async()=>{try{var t=_usingCtx();const o=t.a(scopePreparedModelRuntimeLease(await acquireAgentRunPreparedModelRuntime({config:r.cfg,agentId:r.sessionAgentId,agentDir:r.agentDir,workspaceDir:r.workspaceDir},{abortSignal:r.opts.abortSignal})));ensureGlobalHookRunner();return await withPluginRuntimeGenerationScope(o.snapshot,()=>o.run(async()=>{try{return await e.run({...r,commandRuntimeContext:{config:o.snapshot.config,pluginGeneration:o.pluginGeneration}},n)}finally{if(i.cleanupMemoryOnRunEnd)await runAgentCleanupStep({runId:a.runId,sessionId:a.sessionId,step:`memory-search-managers`,cleanup:async()=>{const{closeActiveMemorySearchManagersCore:e}=await import(`./memory-runtime-BGiZHnsE.mjs`);await e()},log:{warn:t=>e.runtime.error(t)}})}}))}catch(e){t.e=e}finally{await t.d()}});return t?await runWithCronCreatorAuthorityCapability(t,run,r.opts.abortSignal):await run()}finally{await a.runLease?.release()}}))}),async()=>{if(!t){await n.stop();await r.close()}},`Local agent command and resource cleanup failed.`)}export{withLocalGatewayRequestScope as n,runLocalAgentCommand as t};