@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
51 lines • 2.33 kB
JavaScript
import { Text } from "@earendil-works/pi-tui";
import { truncateToVisualLines } from "../../../../../modes/interactive/components/visual-truncate.js";
import { isModelOnlyText } from "../../../../tools/model-only-text.js";
import { formatJobWidgetLine, jobWidgetLineStyle } from "../../job-widgets/tui-line.js";
const OUTPUT_PREVIEW_LINES = 8;
function jobWidgetOf(details) {
const entry = details?.jobWidget;
return typeof entry?.view?.title === "string" && Array.isArray(entry.view.blocks) ? entry : undefined;
}
class BashOutputResultComponent {
#text = "";
#isPartial = false;
#expanded = false;
#jobWidget;
#style;
setResult(result, options, style) {
this.#jobWidget = jobWidgetOf(result.details);
this.#style = style;
this.#text = result.content
.filter((content) => content.type === "text" && !isModelOnlyText(content))
.map((content) => (content.type === "text" ? content.text : ""))
.join("\n");
this.#isPartial = options.isPartial;
this.#expanded = options.expanded;
}
render(width) {
const summary = this.#jobWidget && this.#style
? formatJobWidgetLine(this.#jobWidget, width, this.#style, { showId: false })
: undefined;
const output = !this.#isPartial || this.#expanded
? this.#text.split("\n")
: truncateToVisualLines(this.#text, OUTPUT_PREVIEW_LINES, Math.max(1, width)).visualLines.map((line) => line.trimEnd());
return summary === undefined ? output : [summary, ...output];
}
invalidate() { }
}
export function renderBashOutputCall(args, theme) {
return new Text(theme.fg("toolTitle", theme.bold(`bash_output ${args.bash_id}`)), 0, 0);
}
export function renderMonitorCall(args, theme) {
const label = args.action === "rearm"
? `monitor rearm ${args.bash_id ?? ""}`.trimEnd()
: `monitor ${args.description ?? args.command ?? ""}`.trimEnd();
return new Text(theme.fg("toolTitle", theme.bold(label)), 0, 0);
}
export function renderBashOutputResult(result, options, theme, context) {
const component = context.lastComponent ?? new BashOutputResultComponent();
component.setResult(result, options, jobWidgetLineStyle(theme));
return component;
}
//# sourceMappingURL=render.js.map