openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
7 lines • 8.1 kB
JavaScript
import{t as AUTOMATIONS_TOOL_NAME}from"./automations-tool-name-CptnbJ9-.mjs";import{r as normalizeCronScheduledToolCallerOrigin,s as resolveCronScheduledToolPolicy}from"./scheduled-tool-policy-uo_Vc05h.mjs";import{a as isRuntimeToolAllowed}from"./tool-policy-match-D9XrfLbh.mjs";import{t as decodeGatewayOperatorRecoverySource}from"./operator-run-recovery-source.codec-DkQhl9C9.mjs";import{c as resolveCronSessionTargetSessionKey}from"./session-target-BE2kgjYz.mjs";import{n as resolveCronRunAdmissionSource}from"./run-authority-Cnp8Am6B.mjs";
//!src/agents/knowledge-conversation-scribe.ts
const KNOWLEDGE_CONVERSATION_SCRIBE=`knowledge:scribe:conversations`;
//!src/cron/human-owner.ts
function hasTransferredCronOwner(e){if(!e.ownerProfileId)return false;const t=e.createdActor;return t?.type!==`human`||t.source!==`profile`||t.id!==e.ownerProfileId}function cronExecutionActor(e){return e.ownerProfileId?{type:`human`,source:`profile`,id:e.ownerProfileId}:e.createdActor}function resolveCronOwnerTransferRecoveryError(e){if(e.ownerTransferPending&&(e.payload.kind===`agentTurn`||e.payload.kind===`systemEvent`))return`This automation needs fresh execution authority. Select an inference account or reauthorize it from an authenticated owner turn before running it.`}function retireTransferredCronAuthority(e){e.enabled=false;e.ownerTransferPending=true;delete e.state.nextRunAtMs;delete e.operatorSource;delete e.inferenceBinding;delete e.runtimeAuthority;e.runtimeAuthorityRecoveryRequired=true;delete e.toolsAllowProvenance}
//!src/cron/execution-context.ts
function resolveScheduledRequester(e){if(e.operatorSource)return{kind:`operator-source`,source:decodeGatewayOperatorRecoverySource(e.operatorSource.source)};const t=e.toolsAllowProvenance?.channelRequester;if(t)return{kind:`channel`,requester:t};const n=e.ownerProfileId??profileIdOf(e.createdActor);return n?{kind:`profile`,profileId:n}:{kind:`unknown`}}function profileIdOf(e){return e?.type===`human`&&e.source===`profile`?e.id:void 0}function resolveScheduledPrincipal(e,t){if(t.trigger===`event`)return t.ingress?{kind:`ingress`,ingress:t.ingress}:{error:`event-triggered runs must name their ingress`};if(e.operatorSource){let t;try{t=decodeGatewayOperatorRecoverySource(e.operatorSource.source)}catch{return{error:`stored operator source is invalid`}}const n=t.kind===`gateway`?e.sourceConversation:t;if(!n)return{kind:`operator`,basis:`operator-source`};return{kind:`parent`,parent:{agentId:t.agentId,sessionKey:n.sessionKey},requester:{kind:`operator-source`,source:t}}}const n=e.sourceConversation;if(n)return{kind:`parent`,parent:{agentId:t.agentId,sessionKey:n.sessionKey},requester:resolveScheduledRequester(e)};const r=e.scheduledToolPolicy;const i=(r?.mode===`account`?r.ownerSessionKey:void 0)??e.owner?.sessionKey;if(i&&r?.mode!==`trusted`)return{kind:`unbound-parent`,parentSessionKey:i};return{kind:`operator`,basis:r?.mode===`trusted`?`trusted-policy`:`unlinked-legacy`}}function classifyScheduledParent(e){if(e.missing)return`removed`;return e.archived?`archived`:e}function resolveAuthority(e,t,n){const r=n.trigger===`cron`?resolveCronRunAdmissionSource(e):void 0;const withSource=(e,t)=>({owner:e,basis:t,...r?{admissionSource:r}:{}});if(n.trigger===`cron`&&e.operatorSource)return withSource(n.requesterCheck?.owner===true,`operator-source`);if(n.trigger===`cron`&&hasTransferredCronOwner(e)&&!e.operatorSource){const e=n.requesterCheck?.owner===true;return withSource(e,e?`profile-role`:`none`)}if(t.kind===`parent`){const{requester:r}=t;if(r.kind===`unknown`)return e.scheduledToolPolicy?.mode===`trusted`?withSource(true,`trusted-policy`):withSource(false,`none`);const i=n.requesterCheck?.owner===true;const a=r.kind===`operator-source`?`operator-source`:r.kind===`channel`?`channel-owner`:`profile-role`;return withSource(i,i?a:`none`)}if(t.kind===`unbound-parent`||t.kind===`operator`)return withSource(true,`legacy`);return withSource(false,`none`)}function resolvePlacement(e,t){if(e.sessionTarget===`main`||resolveCronSessionTargetSessionKey(e.sessionTarget))return`in-session`;return t.kind===`parent`?`child`:`detached`}function resolveAutomationsScope(e,t,n,r){if(!isRuntimeToolAllowed(`automations`,r))return{scope:`none`};if(t.kind===`parent`&&n.owner)return{scope:`self-and-parent-wake`,jobId:e.id,parentSessionKey:t.parent.sessionKey};return{scope:`self`,jobId:e.id}}function resolveInference(e){if(e.inferenceBinding)return{kind:`bound`,binding:e.inferenceBinding};if(e.runtimeAuthority)return{kind:`runtime`,authority:e.runtimeAuthority};if(e.runtimeAuthorityRecoveryRequired)return{kind:`runtime-recovery-required`};return{kind:`none`}}function bindScheduledParent(e,t){if(e.kind!==`parent`)return{principal:e};if(!t)return{status:`fail`,error:`parent session facts are required for a parent-linked job`};const n=classifyScheduledParent(t);if(typeof n===`string`)return{status:`pause`,reason:n,parentSessionKey:e.parent.sessionKey};const r={...e.parent,sessionId:n.sessionId,...n.lifecycleRevision?{lifecycleRevision:n.lifecycleRevision}:{}};return{principal:{...e,parent:r},liveRow:n}}function buildScheduledExecutionContext(e,t){const n=resolveScheduledPrincipal(e,t);if(`error`in n)return{status:`fail`,error:n.error};const r=bindScheduledParent(n,t.parentRow);if(`status`in r)return r;const{principal:i,liveRow:a}=r;if(a?.worktree&&!a.worktree.exists&&i.kind===`parent`)return{status:`pause`,reason:`worktree-missing`,parentSessionKey:i.parent.sessionKey,worktreePath:a.worktree.path};const o=resolvePlacement(e,i);const s=resolveAuthority(e,i,t);const c=t.resolvedToolsAllow??(e.payload.kind===`agentTurn`?e.payload.toolsAllow:void 0);const l=resolveCronScheduledToolPolicy({toolsAllow:e.payload.kind===`agentTurn`?e.payload.toolsAllow:void 0,scheduledToolPolicy:e.scheduledToolPolicy,owner:e.owner});const u=i.kind===`parent`&&o===`child`;const d=o===`detached`;const f=u?i.parent.sessionKey:t.runSessionKey;const p=[];if(t.agentSandboxMode===`all`||t.agentSandboxMode===`non-main`&&t.runSessionKey!==t.agentMainSessionKey)p.push(`agent-config`);if(t.creatorRoleSandbox===`required`)p.push(`creator-role`);if(a?.sandboxRequired)p.push(`parent-row`);const m=e.toolsAllowProvenance?.channelRequester;const h=l?.mode===`account`?l.ownerAccountId:void 0;let g={source:`run-session`};if(i.kind===`parent`)g={source:`parent`,parent:i.parent,owner:s.owner};else if(i.kind===`unbound-parent`&&d&&t.parentRow&&!hasTransferredCronOwner(e)){const e=classifyScheduledParent(t.parentRow);if(typeof e!==`string`)g={source:`parent`,parent:{agentId:t.agentId,sessionKey:i.parentSessionKey,sessionId:e.sessionId,...e.lifecycleRevision?{lifecycleRevision:e.lifecycleRevision}:{}},owner:t.requesterCheck?.owner===true}}return{status:`ready`,facts:{version:1,jobId:e.id,occurrence:t.occurrence,principal:i,placement:o,authority:s,toolPolicy:{...c?{allow:c}:{},...l?{policy:l}:{},callerOrigin:normalizeCronScheduledToolCallerOrigin(e.toolsAllowProvenance?.callerOrigin),...e.toolsAllowExecTarget?{execTarget:e.toolsAllowExecTarget}:{},...e.declarationKey===`knowledge:scribe:conversations`?{sessionReadAgentOnly:true}:{},automations:resolveAutomationsScope(e,i,s,c)},resources:{memory:g,boardSessionKey:f,mediaSessionKey:f,eventTargetSessionKey:d?t.agentMainSessionKey:f,workspace:u&&a?.workspaceDir?{source:`parent-row`,dir:a.workspaceDir,...a.cwd?{cwd:a.cwd}:{},...a.worktree?{worktreePath:a.worktree.path}:{}}:{source:`run-session`},fileScope:o===`in-session`?`session`:`root`,bootstrap:d?`cron-allowlist`:`default`,sandbox:{required:p.length>0,basis:p},...e.toolsAllowExecTarget?{execHost:e.toolsAllowExecTarget}:{},messageAccounts:{...h?{ownerAccountId:h}:{},...m?{channelRequester:m}:{}},delivery:e.sourceConversation?{sourceConversation:e.sourceConversation}:{}},inference:resolveInference(e)}}}export{cronExecutionActor as a,retireTransferredCronAuthority as c,resolveScheduledRequester as i,KNOWLEDGE_CONVERSATION_SCRIBE as l,classifyScheduledParent as n,hasTransferredCronOwner as o,resolveScheduledPrincipal as r,resolveCronOwnerTransferRecoveryError as s,buildScheduledExecutionContext as t};