openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
35 lines (34 loc) • 1.88 kB
JavaScript
import { C as parseStrictNonNegativeInteger } from "./number-coercion-CLj0HTDM.js";
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CIXf7egm.js";
import { o as callGateway } from "./call-BWR5pPgw.js";
import { t as formatRunLabel } from "./subagents-utils-ChHH_ZbO.js";
import { n as stripToolMessages } from "./chat-history-text-C2UOMgRe.js";
import { n as commandReply } from "./command-gates-B4tlStPI.js";
import { i as resolveSubagentEntryForToken, n as formatLogLines } from "./shared-Cn64ilNP.js";
//#region src/auto-reply/reply/commands-subagents/action-log.ts
async function handleSubagentsLogAction(ctx) {
const { runs, restTokens } = ctx;
const target = restTokens[0];
if (!target) return commandReply("📜 Usage: /subagents log <id|#> [limit]");
const includeTools = restTokens.some((token) => normalizeLowercaseStringOrEmpty(token) === "tools");
const limitToken = restTokens.slice(1).find((token) => parseStrictNonNegativeInteger(token) !== void 0);
const parsedLimit = parseStrictNonNegativeInteger(limitToken);
const limit = parsedLimit === void 0 ? 20 : Math.min(200, Math.max(1, parsedLimit));
const targetResolution = resolveSubagentEntryForToken(runs, target);
if ("reply" in targetResolution) return targetResolution.reply;
const history = await callGateway({
method: "chat.history",
params: {
sessionKey: targetResolution.entry.childSessionKey,
limit
}
});
const rawMessages = Array.isArray(history?.messages) ? history.messages : [];
const filtered = includeTools ? rawMessages : stripToolMessages(rawMessages);
const lines = formatLogLines(filtered);
const header = `📜 Subagent log: ${formatRunLabel(targetResolution.entry)}`;
if (lines.length === 0) return commandReply(`${header}\n(no messages)`);
return commandReply([header, ...lines].join("\n"));
}
//#endregion
export { handleSubagentsLogAction };