/** * Model cost display extension - shows cost info in status bar. * * Format: "$X.XX (Y.YY) in" where Y.YY is cache write cost if present. * * Usage: pi -e ./model-cost.ts */ import type { ExtensionAPI, ModelSelectEvent, UIContext, } from "@earendil-works/pi-coding-agent"; export default function (pi: ExtensionAPI) { const modelSelectHandler = async ( event: ModelSelectEvent, ctx: UIContext, ) => { const { model } = event; // Get cost data from model config const cost = getModelCost(model); if (cost) { ctx.ui.setStatus("model", cost); } else { ctx.ui.setStatus("model", ""); } }; pi.on("model_select", modelSelectHandler); } function getModelCost(model: any): string { if (!model?.cost) return ""; const { input, output, cacheRead, cacheWrite } = model.cost; // Only show if there's actual cost data const hasCost = input !== 0 || output !== 0 || cacheRead !== 0 || cacheWrite !== 0; if (!hasCost) return ""; // Format: "$X.XX (Y.YY) in" const parts: string[] = []; if (input !== 0) { const cachePrefix = cacheRead > 0 ? ` (↙${cacheRead}) ` : ""; parts.push(`$${input}${cachePrefix}in`); } if (output !== 0) { const cachePrefix = cacheWrite > 0 ? ` (↗${cacheWrite}) ` : ""; parts.push(`$${output}${cachePrefix}out`); } if (parts.length === 0) return ""; return parts.join(" / "); }