UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

23 lines (22 loc) • 1.62 kB
export const ACTIONS_COMMANDS_CAP = 20; export const ACTIONS_TOOLS_CAP = 16; export function subagentActionsLine(a) { const tools = a.byTool.length > 0 ? `: ${a.byTool.map((t) => `${t.tool} ${t.calls}`).join(", ")}` : ""; const commands = a.commands.length === 0 ? "none" : `${a.commands.map((c) => `\`${c.command}\`${c.exitCode !== undefined ? ` (exit ${c.exitCode})` : ""}`).join(" · ")}${a.commandsUnlisted !== undefined ? ` · and ${a.commandsUnlisted} more` : ""}`; const files = a.filesEdited.length === 0 ? "none" : a.filesEdited.map((f) => `${f.path}${f.edits > 1 ? ` (×${f.edits})` : ""}`).join(", "); return `tool calls ${a.toolCalls}${tools} · commands: ${commands} · files edited: ${files}`; } const isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0; export function isSubagentActions(v) { if (v === null || typeof v !== "object" || Array.isArray(v)) return false; const a = v; const list = (l, item) => Array.isArray(l) && l.every((e) => e !== null && typeof e === "object" && !Array.isArray(e) && item(e)); return (isCount(a["toolCalls"]) && list(a["byTool"], (e) => typeof e["tool"] === "string" && isCount(e["calls"])) && list(a["commands"], (e) => typeof e["command"] === "string" && (e["exitCode"] === undefined || (typeof e["exitCode"] === "number" && Number.isInteger(e["exitCode"])))) && (a["commandsUnlisted"] === undefined || (isCount(a["commandsUnlisted"]) && a["commandsUnlisted"] > 0)) && list(a["filesEdited"], (e) => typeof e["path"] === "string" && isCount(e["edits"]))); }