UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.48 kB
import{a as asOptionalRecord}from"./record-coerce-BTbqdJ3-.mjs";import{Et as _enum,Fn as object,Jn as string,Lt as boolean,Nt as array,Pn as number,sr as unknown,xn as literal}from"./schemas-DuCQi-Qb.mjs";import{i as compile}from"./compile-CzTmaA66.mjs";import{r as unwrapToolCallForDisplay}from"./tool-display-call-CqUrC2DS.mjs";import{n as readCollectedSubagentCompletions,r as readCollectionErrorCount}from"./subagent-completion-Bc4JhLbw.mjs";import{t as boundedJsonUtf8Bytes}from"./json-utf8-bytes-BzjXgHQ3.mjs"; //!src/sessions/nested-tool-activity.ts const NESTED_TOOL_ACTIVITY_CUSTOM_TYPE=`openclaw.nested-tool.v1`;const omittedResultText=`[Nested tool output omitted: exceeds display limit]`;const correlationId=string().min(1).max(1024);const activityDetails=object({runId:correlationId,scopeId:correlationId,afterEntryId:correlationId.nullable(),startOrder:number().int().nonnegative(),parentToolCallId:correlationId.optional(),toolCallId:correlationId,toolName:string().min(1).max(256),input:unknown(),subagentCompletions:array(object({runId:correlationId,sessionKey:correlationId,label:string().optional(),outcome:_enum([`failed`,`killed`,`timeout`]).optional()})).optional(),subagentCollectionErrors:number().int().positive().optional(),result:object({content:array(unknown()),details:unknown().optional()}),isError:boolean(),startedAt:number().finite(),timestamp:number().finite()}).strict();const activitySchema=object({role:literal(`custom`),customType:literal(NESTED_TOOL_ACTIVITY_CUSTOM_TYPE),display:literal(true),excludeFromContext:literal(true),content:literal(``),details:activityDetails,timestamp:number().finite()});let compiledActivitySchema;function getActivitySchema(){return compiledActivitySchema??=compile(activitySchema)}function readNestedToolActivity(e){if(asOptionalRecord(e)?.customType!==`openclaw.nested-tool.v1`)return;const t=getActivitySchema().safeParse(e);return t.success?t.data:void 0}function readOwnNestedToolActivity(e){const t=asOptionalRecord(e);return readNestedToolActivity(t?.display===false?{...t,display:true}:e)}function createNestedToolActivity(e){const t=unwrapToolCallForDisplay({name:e.toolName,args:e.input}).name===`agents_wait`;const n=t?readCollectedSubagentCompletions(e.result):[];const r=t?readCollectionErrorCount(e.result):0;const i=boundedJsonUtf8Bytes(e.input,8192).complete?structuredClone(e.input):`[Nested tool input omitted: exceeds display limit]`;const a=boundedJsonUtf8Bytes(e.result,32768).complete?e.result:{content:[{type:`text`,text:omittedResultText}]};return getActivitySchema().parse({role:`custom`,customType:NESTED_TOOL_ACTIVITY_CUSTOM_TYPE,display:true,excludeFromContext:true,content:``,details:{...e,input:i,result:a,...n.length?{subagentCompletions:n}:{},...r?{subagentCollectionErrors:r}:{}},timestamp:e.startedAt})}function nestedToolActivityContent({details:e}){const{input:t,result:n,...r}=e;return[{type:`toolCall`,id:r.toolCallId,runId:r.runId,name:r.toolName,arguments:t,parentToolCallId:r.parentToolCallId,timestamp:r.startedAt},{...r,...n,type:`toolResult`}]}function projectNestedToolActivityForHooks(e,t){return[...e,...t.map(e=>({...e,content:JSON.stringify({scopeId:e.details.scopeId,toolCallId:e.details.toolCallId,toolName:e.details.toolName,isError:e.details.isError})}))]}export{readNestedToolActivity as a,projectNestedToolActivityForHooks as i,createNestedToolActivity as n,readOwnNestedToolActivity as o,nestedToolActivityContent as r,NESTED_TOOL_ACTIVITY_CUSTOM_TYPE as t};