openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.7 kB
JavaScript
import{X as e}from"./openclaw-state-read-map-size-DJbMcZYM.mjs";import{f as t,l as n,p as r}from"./openclaw-state-read-home-dir-BQZX1pD2.mjs";import{a as i}from"./openclaw-state-read-record-coerce-D1s3ReAs.mjs";import{t as a}from"./openclaw-state-read-json-coercion-DgTIp8OM.mjs";import{r as o}from"./openclaw-state-read-account-id-BXncLhZ8.mjs";import{t as s}from"./openclaw-state-read-message-channel-core-VkoqSJSs.mjs";import{t as c}from"./openclaw-state-read-agent-run-terminal-reply-4GCOQgEl.mjs";function normalizeChannelRouteRef(e){if(!e)return;let i=n(e.channel),a=typeof e.accountId==`string`?o(e.accountId):void 0,s=t(e.to),c=t(e.rawTo),l=r(e.threadId);if(i||s||a||l!=null)return{...i?{channel:i}:{},...a?{accountId:a}:{},...s?{target:{to:s,...c&&c!==s?{rawTo:c}:{},...e.chatType?{chatType:e.chatType}:{}}}:{},...l==null?{}:{thread:{id:l,...e.threadKind?{kind:e.threadKind}:{},...e.threadSource?{source:e.threadSource}:{}}}}}function channelRouteTarget(e){return e?.target?.to}function channelRouteThreadId(e){return e?.thread?.id}function normalizeChannelRouteTarget(e){return e?normalizeChannelRouteRef(e):void 0}function normalizeDeliveryContext(e){if(!e)return;let t=normalizeChannelRouteTarget({channel:typeof e.channel==`string`?s(e.channel)??e.channel.trim():void 0,to:e.to,accountId:e.accountId,threadId:e.threadId});if(!t)return;let n={channel:t.channel,to:channelRouteTarget(t),accountId:o(t.accountId)},r=channelRouteThreadId(t);return r!=null&&(n.threadId=r),n}function projectSubagentRunForSessionList(e){return{runId:e.runId,taskRunId:e.taskRunId,pauseReason:e.pauseReason||void 0,swarmRunId:e.swarmRunId||void 0,schedulerSlotId:e.schedulerSlotId||void 0,swarmLaunchReplayKey:e.swarmLaunchReplayKey||void 0,childSessionKey:e.childSessionKey,childAgentId:e.childAgentId||void 0,controllerSessionKey:e.controllerSessionKey||void 0,requesterSessionKey:e.requesterSessionKey,requesterStorePath:e.requesterStorePath,controllerStorePath:e.controllerStorePath,collect:e.collect||void 0,groupId:e.collect?e.groupId:void 0,swarmRequesterSessionKey:e.collect?e.swarmRequesterSessionKey:void 0,collectorCompletion:e.collectorCompletion&&{status:e.collectorCompletion.status},requesterAgentId:e.requesterAgentId||void 0,model:e.model||void 0,generation:e.generation,createdAt:e.createdAt,execution:{status:e.execution.status,startedAt:e.execution.startedAt,endedAt:e.execution.endedAt,outcome:e.execution.outcome&&{status:e.execution.outcome.status}},sessionStartedAt:e.sessionStartedAt,accumulatedRuntimeMs:e.accumulatedRuntimeMs,runTimeoutSeconds:e.runTimeoutSeconds,endedReason:e.endedReason||void 0,cleanupCompletedAt:e.cleanupCompletedAt,delivery:e.delivery&&{status:e.delivery.status,requesterDelivery:e.delivery.requesterDelivery,disposition:e.delivery.disposition||void 0,suspendedAt:e.delivery.suspendedAt}}}function projectSubagentRunForMaintenance(e){return{runId:e.runId,childSessionKey:e.childSessionKey,...e.childAgentId?{childAgentId:e.childAgentId}:{},requesterSessionKey:e.requesterSessionKey,createdAt:e.createdAt,cleanupCompletedAt:e.cleanupCompletedAt,requesterSettleWake:e.requesterSettleWake?{status:e.requesterSettleWake.status}:void 0,expectsCompletionMessage:e.expectsCompletionMessage,killIntent:e.killIntent?{...e.killIntent}:e.killIntent,killReconciliation:e.killReconciliation?{...e.killReconciliation}:e.killReconciliation,execution:{status:e.execution.status,endedAt:e.execution.endedAt},delivery:e.delivery?{status:e.delivery.status,suspendedAt:e.delivery.suspendedAt}:void 0}}function normalizeSubagentRunState(n){n.taskRunId=t(n.taskRunId);let r=t(n.requesterTurnRunId);n.requesterTurnRunId=r,n.requesterTurnYielded=r&&n.requesterTurnYielded===!0?!0:void 0,n.retireAfterRequesterTurn=r&&n.retireAfterRequesterTurn===!0?!0:void 0,n.generation=e(n.generation),n.deleteCleanupDispatchedAt=Number.isFinite(n.deleteCleanupDispatchedAt)?n.deleteCleanupDispatchedAt:void 0,n.suppressCompletionDelivery=n.suppressCompletionDelivery===!0||void 0,n.completion&&(n.completion.terminalReply=c(n.completion.terminalReply));let i=n.killReconciliation;!i||typeof i!=`object`||!Number.isFinite(i.killedAt)?delete n.killReconciliation:n.killReconciliation={killedAt:i.killedAt,taskCancellationAccepted:i.taskCancellationAccepted===!0||void 0,suppressTaskDelivery:i.suppressTaskDelivery===!0||void 0,supersededAt:Number.isFinite(i.supersededAt)?i.supersededAt:void 0};let a=n.killIntent;return!a||typeof a!=`object`||!Number.isFinite(a.requestedAt)||typeof a.reason!=`string`||!a.reason.trim()?delete n.killIntent:n.killIntent={requestedAt:a.requestedAt,reason:a.reason.trim(),lifecycleGeneration:t(a.lifecycleGeneration),sessionId:t(a.sessionId),sessionLifecycleRevision:t(a.sessionLifecycleRevision),suppressTaskDelivery:a.suppressTaskDelivery===!0||void 0},n.delivery?.status===`in_progress`&&!n.delivery.queueId&&(n.delivery={...n.delivery,status:`pending`}),n.cleanupHandled===!0&&typeof n.cleanupCompletedAt!=`number`&&n.delivery?.status!==`discarded`&&(n.cleanupHandled=!1),n}const l=new Set(`queued running interrupted terminal`.split(` `)),u=new Set(`not_required pending in_progress delivered failed suspended discarded`.split(` `));function hasStateStatus(e,t){return i(e)&&typeof e.status==`string`&&t.has(e.status)}function isCanonicalSubagentRunRecord(e){return i(e)&&hasStateStatus(e.execution,l)&&i(e.completion)&&typeof e.completion.required==`boolean`&&hasStateStatus(e.delivery,u)&&!(`handoffLeaseId`in e.delivery||`handoffLeasedAt`in e.delivery||`handoffInjectedAt`in e.delivery)}function rowToSubagentRunRecord(e){let t=e.payload_json?a(e.payload_json):void 0,n=i(t)&&i(t.parentCompletion)&&t.parentCompletion.completionTarget===`parent`?t.parentCompletion:t;if(!isCanonicalSubagentRunRecord(n))return null;n.runId=e.run_id,n.childSessionKey=e.child_session_key,n.requesterSessionKey=e.requester_session_key,n.requesterStorePath=e.requester_store_path??void 0,n.controllerStorePath=e.controller_store_path??void 0,Reflect.deleteProperty(n,`operatorRecoverySource`),Reflect.deleteProperty(n,`queuedLaunch`),Reflect.deleteProperty(n.execution,`restartRecovery`),Reflect.deleteProperty(n.execution,`interruptionReason`),Reflect.deleteProperty(n.execution,`interruptedAt`),Reflect.deleteProperty(n,`terminalOwner`);let r=e.controller_session_key?.trim();r?n.controllerSessionKey=r:delete n.controllerSessionKey,n.requesterOrigin&&=normalizeDeliveryContext(n.requesterOrigin),n.expectsCompletionMessage===!1&&(n.delivery.status=`not_required`);let o=normalizeSubagentRunState(n);return!o.runId||!o.childSessionKey||!o.requesterSessionKey?null:o}export{projectSubagentRunForMaintenance as n,projectSubagentRunForSessionList as r,rowToSubagentRunRecord as t};