import { html, type TemplateResult } from "@mariozechner/mini-lit"; import type { ToolResultMessage } from "@mariozechner/pi-ai"; import { i18n } from "../../utils/i18n.js"; import type { ToolRenderer } from "../types.js"; interface CalculateParams { expression: string; } // Calculate tool has undefined details (only uses output) export class CalculateRenderer implements ToolRenderer { renderParams(params: CalculateParams, isStreaming?: boolean): TemplateResult { if (isStreaming && !params.expression) { return html`
${i18n("Writing expression...")}
`; } return html`
${i18n("Calculating")} ${params.expression}
`; } renderResult(_params: CalculateParams, result: ToolResultMessage): TemplateResult { // Parse the output to make it look nicer const output = result.output || ""; const isError = result.isError === true; if (isError) { return html`
${output}
`; } // Try to split on = to show expression and result separately const parts = output.split(" = "); if (parts.length === 2) { return html`
${parts[0]} = ${parts[1]}
`; } // Fallback to showing the whole output return html`
${output}
`; } }