model-status.ts 957 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Model status extension - shows model changes in the status bar.
  3. *
  4. * Demonstrates the `model_select` hook which fires when the model changes
  5. * via /model command, Ctrl+P cycling, or session restore.
  6. *
  7. * Usage: pi -e ./model-status.ts
  8. */
  9. import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
  10. export default function (pi: ExtensionAPI) {
  11. pi.on("model_select", async (event, ctx) => {
  12. const { model, previousModel, source } = event;
  13. // Format model identifiers
  14. const next = `${model.provider}/${model.id}`;
  15. const prev = previousModel ? `${previousModel.provider}/${previousModel.id}` : "none";
  16. // Show notification on change
  17. if (source !== "restore") {
  18. ctx.ui.notify(`Model: ${next}`, "info");
  19. }
  20. // Update status bar with current model
  21. ctx.ui.setStatus("model", `🤖 ${model.id}`);
  22. // Log change details (visible in debug output)
  23. console.log(`[model_select] ${prev} → ${next} (${source})`);
  24. });
  25. }