openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
107 lines (106 loc) • 3.61 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import { Fn as object, Jn as string, Lt as boolean, Nt as array, Pn as number, sr as unknown, xn as literal } from "./schemas-Cy6abvsu.mjs";
import { i as compile } from "./compile-BPxT0I0w.mjs";
import { t as boundedJsonUtf8Bytes } from "./json-utf8-bytes-DNwtq2cu.mjs";
//#region src/sessions/nested-tool-activity.ts
const NESTED_TOOL_ACTIVITY_CUSTOM_TYPE = "openclaw.nested-tool.v1";
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(),
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);
}
/** Validate correlation slots separately from the payloads that always require redaction. */
function readNestedToolActivity(e) {
if (asOptionalRecord(e)?.customType !== "openclaw.nested-tool.v1") return;
const t = getActivitySchema().safeParse(e);
return t.success ? t.data : void 0;
}
/**
* Reads the run's own activity even after a hidden turn (for example child coordination)
* cleared its display flag. Display readers keep using readNestedToolActivity.
*/
function readOwnNestedToolActivity(e) {
const t = asOptionalRecord(e);
return readNestedToolActivity(t?.display === false ? {
...t,
display: true
} : e);
}
/** Keep each terminal activity bounded independently of provider context. */
function createNestedToolActivity(e) {
const t = boundedJsonUtf8Bytes(e.input, 8192).complete ? structuredClone(e.input) : "[Nested tool input omitted: exceeds display limit]";
const n = boundedJsonUtf8Bytes(e.result, 32768).complete ? e.result : { content: [{
type: "text",
text: "[Nested tool output omitted: exceeds display limit]"
}] };
return getActivitySchema().parse({
role: "custom",
customType: NESTED_TOOL_ACTIVITY_CUSTOM_TYPE,
display: true,
excludeFromContext: true,
content: "",
details: {
...e,
input: t,
result: n
},
timestamp: e.startedAt
});
}
/** Tool-card content for public history. */
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"
}];
}
/** Hooks retain call/result evidence; model snapshots and context engines stay unchanged. */
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
})
}))];
}
//#endregion
export { readNestedToolActivity as a, projectNestedToolActivityForHooks as i, createNestedToolActivity as n, readOwnNestedToolActivity as o, nestedToolActivityContent as r, NESTED_TOOL_ACTIVITY_CUSTOM_TYPE as t };