This commit is contained in:
2026-08-03 11:19:58 +01:00
parent cce3c78ae5
commit a93ff98461
2 changed files with 67 additions and 1 deletions
+61
View File
@@ -0,0 +1,61 @@
/**
* 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(" / ");
}
+6 -1
View File
@@ -188,7 +188,12 @@
home.file.".pi/agent/extensions/model-filter.ts" = {
source = ./model-filter.ts;
};
# Show model cost in status bar
home.file.".pi/agent/extensions/model-cost.ts" = {
source = ./model-cost.ts;
};
# Model filter config: per-provider filters applied by model-filter.ts
home.file.".pi/agent/model-filters.json" = {
text = builtins.toJSON {