Skip to content

Instantly share code, notes, and snippets.

@aliou
Created April 27, 2026 16:49
Show Gist options
  • Select an option

  • Save aliou/a97d1dea4e5af8cccd015dd180cbda03 to your computer and use it in GitHub Desktop.

Select an option

Save aliou/a97d1dea4e5af8cccd015dd180cbda03 to your computer and use it in GitHub Desktop.
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
export default function tpsEditorWidget(pi: ExtensionAPI) {
pi.on("session_start", (_event, ctx) => {
if (!ctx.hasUI) return;
pi.events.on("tps:telemetry", (data) => {
const t = data as {
tps: number | null;
tokens: { input: number; output: number };
timing: { totalMs: number; ttftMs: number | null };
};
const parts: string[] = [];
if (t.tps !== null) parts.push(`TPS ${t.tps.toFixed(1)} tok/s`);
if (t.timing.ttftMs !== null) parts.push(`TTFT ${(t.timing.ttftMs / 1000).toFixed(1)}s`);
parts.push(`${(t.timing.totalMs / 1000).toFixed(1)}s`);
parts.push(`out ${t.tokens.output.toLocaleString()}`);
parts.push(`in ${t.tokens.input.toLocaleString()}`);
ctx.ui.setWidget("tps-widget", [parts.join(" · ")], { placement: "aboveEditor" });
});
});
}
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
export default function tpsStatusWidget(pi: ExtensionAPI) {
pi.on("session_start", (_event, ctx) => {
if (!ctx.hasUI) return;
pi.events.on("tps:telemetry", (data) => {
const t = data as {
tps: number | null;
tokens: { input: number; output: number };
timing: { totalMs: number; ttftMs: number | null };
};
const parts: string[] = [];
if (t.tps !== null) parts.push(`TPS ${t.tps.toFixed(1)}`);
if (t.timing.ttftMs !== null) parts.push(`TTFT ${(t.timing.ttftMs / 1000).toFixed(1)}s`);
parts.push(`${(t.timing.totalMs / 1000).toFixed(1)}s`);
parts.push(`out ${t.tokens.output}`);
parts.push(`in ${t.tokens.input}`);
const theme = ctx.ui.theme;
ctx.ui.setStatus("tps-widget", theme.fg("dim", parts.join(" · ")));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment