mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 08:00:59 +00:00
feat(coding-agent): add model_select extension hook
Fires when the model changes via /model command, model cycling (Ctrl+P), or session restore. Includes source field and previousModel. Add model-status.ts example extension demonstrating status bar updates. closes #628
This commit is contained in:
parent
a1696e338b
commit
a20c6efe17
2 changed files with 33 additions and 0 deletions
|
|
@ -507,6 +507,8 @@ pi.on("model_select", async (event, ctx) => {
|
||||||
|
|
||||||
Use this to update UI elements (status bars, footers) or perform model-specific initialization when the active model changes.
|
Use this to update UI elements (status bars, footers) or perform model-specific initialization when the active model changes.
|
||||||
|
|
||||||
|
**Examples:** [model-status.ts](../examples/extensions/model-status.ts)
|
||||||
|
|
||||||
### Tool Events
|
### Tool Events
|
||||||
|
|
||||||
#### tool_call
|
#### tool_call
|
||||||
|
|
|
||||||
31
packages/coding-agent/examples/extensions/model-status.ts
Normal file
31
packages/coding-agent/examples/extensions/model-status.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* Model status extension - shows model changes in the status bar.
|
||||||
|
*
|
||||||
|
* Demonstrates the `model_select` hook which fires when the model changes
|
||||||
|
* via /model command, Ctrl+P cycling, or session restore.
|
||||||
|
*
|
||||||
|
* Usage: pi -e ./model-status.ts
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
||||||
|
|
||||||
|
export default function (pi: ExtensionAPI) {
|
||||||
|
pi.on("model_select", async (event, ctx) => {
|
||||||
|
const { model, previousModel, source } = event;
|
||||||
|
|
||||||
|
// Format model identifiers
|
||||||
|
const next = `${model.provider}/${model.id}`;
|
||||||
|
const prev = previousModel ? `${previousModel.provider}/${previousModel.id}` : "none";
|
||||||
|
|
||||||
|
// Show notification on change
|
||||||
|
if (source !== "restore") {
|
||||||
|
ctx.ui.notify(`Model: ${next}`, "info");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update status bar with current model
|
||||||
|
ctx.ui.setStatus("model", `🤖 ${model.id}`);
|
||||||
|
|
||||||
|
// Log change details (visible in debug output)
|
||||||
|
console.log(`[model_select] ${prev} → ${next} (${source})`);
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue