@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
39 lines • 2.15 kB
JavaScript
import { Text } from "@earendil-works/pi-tui";
import { toolResultUserWords } from "../../../tool-result-user-words.js";
import { TOOL_NAMES } from "./family.js";
import { resolveUserWordReferences } from "./user-words.js";
export const renderCall = (args, theme) => {
const values = typeof args === "object" && args !== null ? args : {};
const headers = "questions" in values && Array.isArray(values.questions)
? values.questions
.map((q) => typeof q === "object" && q !== null && "header" in q ? `[${q.header}]` : "[Question]")
.join(" ")
: "Question";
const wait = ("waitForAnswer" in values && values.waitForAnswer === true) ||
("wait_for_answer" in values && values.wait_for_answer === true);
return new Text(`${theme.fg("toolTitle", headers)} ${wait ? "wait for answer" : "answer later"}`, 0, 0);
};
export const renderResult = (result) => {
const details = result.details;
let summary = "";
const words = toolResultUserWords({ details });
if (typeof details === "object" && details !== null && "status" in details) {
summary = String(details.status);
if ("answers" in details && typeof details.answers === "object" && details.answers !== null)
summary += `; ${Object.keys(details.answers).length} answered`;
if ("unanswered" in details && Array.isArray(details.unanswered))
summary += `; ${details.unanswered.length} unanswered`;
}
return new Text([summary, ...result.content.flatMap((c) => (c.type === "text" ? [resolveUserWordReferences(c.text, words)] : []))]
.filter(Boolean)
.join("\n"), 0, 0);
};
/**
* Renderers for a question card whose tool definition is not resolvable: the tools are registered
* when the session synchronizes them, so a card streamed while a reload is in flight - or replayed
* in a session where ask-user is disabled - would otherwise fall back to a raw argument dump.
*/
export function askUserRenderers(toolName) {
return Object.values(TOOL_NAMES).includes(toolName) ? { renderCall, renderResult } : undefined;
}
//# sourceMappingURL=render.js.map