mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 20:01:24 +00:00
docs(coding-agent): improve extensions.md, add missing examples
- Add cross-links to session.md, keybindings.md, themes.md - Document truncateLine, highlightCode, getLanguageFromPath utilities - Add examples for previously undocumented APIs: - message-renderer.ts: registerMessageRenderer with Box styling - session-name.ts: setSessionName/getSessionName - event-bus.ts: pi.events for inter-extension communication - bookmark.ts: setLabel for entry bookmarking - Update examples table in extensions.md and README.md
This commit is contained in:
parent
c565fa9af8
commit
930207130b
6 changed files with 285 additions and 68 deletions
43
packages/coding-agent/examples/extensions/event-bus.ts
Normal file
43
packages/coding-agent/examples/extensions/event-bus.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Inter-extension event bus example.
|
||||
*
|
||||
* Shows pi.events for communication between extensions. One extension
|
||||
* can emit events that other extensions listen to.
|
||||
*
|
||||
* Usage: /emit [event-name] [data] - emit an event on the bus
|
||||
*/
|
||||
|
||||
import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
|
||||
|
||||
export default function (pi: ExtensionAPI) {
|
||||
// Store ctx for use in event handler
|
||||
let currentCtx: ExtensionContext | undefined;
|
||||
|
||||
pi.on("session_start", async (_event, ctx) => {
|
||||
currentCtx = ctx;
|
||||
});
|
||||
|
||||
// Listen for events from other extensions
|
||||
pi.events.on("my:notification", (data) => {
|
||||
const { message, from } = data as { message: string; from: string };
|
||||
currentCtx?.ui.notify(`Event from ${from}: ${message}`, "info");
|
||||
});
|
||||
|
||||
// Command to emit events (emits "my:notification" which the listener above receives)
|
||||
pi.registerCommand("emit", {
|
||||
description: "Emit my:notification event (usage: /emit message)",
|
||||
handler: async (args, _ctx) => {
|
||||
const message = args.trim() || "hello";
|
||||
pi.events.emit("my:notification", { message, from: "/emit command" });
|
||||
// Listener above will show the notification
|
||||
},
|
||||
});
|
||||
|
||||
// Example: emit on session start
|
||||
pi.on("session_start", async () => {
|
||||
pi.events.emit("my:notification", {
|
||||
message: "Session started",
|
||||
from: "event-bus-example",
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue