Download packages/coding-agent/examples/extensions/file-trigger.ts from SaylorTwift/pi: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/examples/extensions/file-trigger.ts
- Command line
-
hf download hf://SaylorTwift/pi/packages/coding-agent/examples/extensions/file-trigger.ts
-
curl -L -o file-trigger.ts https://huggingface.co/SaylorTwift/pi/resolve/main/packages/coding-agent/examples/extensions/file-trigger.ts
1.03 kB
| /** | |
| * File Trigger Extension | |
| * | |
| * Watches a trigger file and injects its contents into the conversation. | |
| * Useful for external systems to send messages to the agent. | |
| * | |
| * Usage: | |
| * echo "Run the tests" > /tmp/agent-trigger.txt | |
| */ | |
| import * as fs from "node:fs"; | |
| import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; | |
| export default function (pi: ExtensionAPI) { | |
| pi.on("session_start", async (_event, ctx) => { | |
| const triggerFile = "/tmp/agent-trigger.txt"; | |
| fs.watch(triggerFile, () => { | |
| try { | |
| const content = fs.readFileSync(triggerFile, "utf-8").trim(); | |
| if (content) { | |
| pi.sendMessage( | |
| { | |
| customType: "file-trigger", | |
| content: `External trigger: ${content}`, | |
| display: true, | |
| }, | |
| { triggerTurn: true }, // triggerTurn - get LLM to respond | |
| ); | |
| fs.writeFileSync(triggerFile, ""); // Clear after reading | |
| } | |
| } catch { | |
| // File might not exist yet | |
| } | |
| }); | |
| if (ctx.hasUI) { | |
| ctx.ui.notify(`Watching ${triggerFile}`, "info"); | |
| } | |
| }); | |
| } | |