openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
112 lines (111 loc) • 4.56 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { r as inferToolMetaFromArgsCore } from "./tool-display-BQXZgFy6.mjs";
import "./agent-harness-runtime-BCklzcv7.mjs";
import { c as truncateNativeToolTranscriptText, i as TOOL_TRANSCRIPT_OUTPUT_MAX_CHARS } from "./projection-tool-output-DX3_Ng9b.mjs";
import { u as sanitizeToolResult } from "./embedded-agent-tool-results-DbtxSr9V.mjs";
import "./agent-harness-attempt-runtime-DFFgKWgF.mjs";
//#region extensions/agentsapi/agentsapi-native-items.ts
function agentsApiNativeTool(e, t) {
let n;
let r;
if (e.type === "command_execution") {
n = "bash";
r = {
...e.command !== void 0 ? { command: e.command } : {},
...e.cwd != null ? { cwd: e.cwd } : {}
};
} else if (e.type === "mcp_call") {
n = e.server_label ? `${e.server_label}.${e.name ?? "mcp"}` : e.name ?? "mcp";
r = asOptionalRecord(e.arguments) ?? (e.arguments === void 0 ? {} : { arguments: e.arguments });
} else if (e.type === "web_search_call") {
n = "web_search";
r = e.action ?? {};
} else return;
const i = inferToolMetaFromArgsCore(n, r, { detailMode: t.toolProgressDetail === "raw" ? "raw" : "explain" });
return {
name: n,
args: r,
...i ? { meta: i } : {},
commandBearing: e.type === "command_execution"
};
}
function agentsApiNativeToolOutcome(e, t) {
const n = e.error === null || e.error === void 0 ? void 0 : e.error;
const r = asOptionalRecord(n);
const i = typeof r?.code === "string" ? r.code : void 0;
const a = n === void 0 ? void 0 : nativeValueText(n);
const o = e.type === "command_execution" && e.exit_code != null && e.exit_code !== 0;
let s;
if (e.status === "failed" || n !== void 0 || o) s = "failed";
else if (e.status === "completed") s = e.type === "command_execution" && e.exit_code == null ? "unknown" : "completed";
else if (e.status === "in_progress" && t === void 0) s = "running";
else if ((e.status === "incomplete" || e.status === "in_progress") && t === "cancelled") s = "cancelled";
else s = "unknown";
const c = s === "failed" ? a || (o ? `Command exited with code ${e.exit_code}` : "Agents API native tool failed") : s === "cancelled" ? "Agents API native tool was cancelled" : s === "unknown" ? "Agents API native tool outcome is unavailable" : void 0;
return {
status: s,
isError: s !== "completed" && s !== "running",
outcomeUnknown: s === "unknown",
...c ? { error: c } : {},
...i ? { errorCode: i } : {}
};
}
function agentsApiNativeToolDetails(e, t, n, r, i) {
const a = n.output ?? i;
const o = a === void 0 || a === null ? void 0 : boundedNativeValue(a);
return {
status: r.status,
native: {
backend: "agentsapi",
sessionId: e,
turnId: t,
itemId: n.id,
itemType: n.type,
status: n.status ?? null
},
...n.exit_code != null ? { exitCode: n.exit_code } : {},
...n.duration_ms != null ? { durationMs: n.duration_ms } : {},
...n.cwd != null ? { cwd: n.cwd } : {},
...n.server_label ? { serverLabel: n.server_label } : {},
...n.type === "web_search_call" ? {
...n.action ? { action: n.action } : {},
resultAvailability: "unavailable"
} : {
outputAvailability: o === void 0 ? "unavailable" : n.output == null ? "partial" : "canonical",
...o ? {
output: o.value,
...o.truncated ? { outputTruncated: true } : {}
} : {}
},
...n.error != null ? { nativeError: boundedNativeValue(n.error).value } : {},
...r.error ? { error: r.error } : {},
...r.errorCode ? { errorCode: r.errorCode } : {},
...r.outcomeUnknown ? { outcomeUnknown: true } : {}
};
}
function agentsApiNativeToolOutput(e, t) {
if (e.type === "web_search_call") return;
return e.output !== void 0 && e.output !== null ? nativeValueText(e.output) : t;
}
function nativeValueText(e) {
const t = sanitizeNativeValue(e);
const n = typeof t === "string" ? t : JSON.stringify(t, null, 2) ?? "";
return truncateNativeToolTranscriptText(n, "Agents API");
}
function boundedNativeValue(e) {
const t = sanitizeNativeValue(e);
const n = typeof t === "string" ? t : JSON.stringify(t, null, 2) ?? "";
return n.length <= 1e4 ? {
value: t,
truncated: false
} : {
value: truncateNativeToolTranscriptText(n, "Agents API"),
truncated: true
};
}
function sanitizeNativeValue(e) {
return Array.isArray(e) ? asOptionalRecord(sanitizeToolResult({ content: e }))?.content : sanitizeToolResult(e);
}
//#endregion
export { agentsApiNativeToolOutput as i, agentsApiNativeToolDetails as n, agentsApiNativeToolOutcome as r, agentsApiNativeTool as t };