pi-mono/apps/p2/plugins/prompt/composer.ts
Mario Zechner 05dc8d239d feat: add apps/p2 (imported from pi-private at 7dadff697)
p2 (Pi Mobile on Chord v2) moves from pi-private into pi as one commit. Root scripts that loop all workspaces
use --if-present; npm test, ./test.sh and the release script cover packages/* only (p2: cd apps/p2 && npm test);
sync-versions also updates apps' workspace pins.
2026-11-03 13:39:06 +00:00

18 lines
802 B
TypeScript

// The web composer's expander for prompt templates and skills (p2-tui-port.md 10.8): `/name args` and
// `/skill:name args` are expanded on the session worker before a send, as in the TUI.
import { BACKGROUND_CONTEXT, ComposerExpanders, defineFacet } from "@p2/app/v1";
import { PromptResources } from "./contract.ts";
/** The web facet: contributes the `prompt` expander. */
export const promptComposer = defineFacet((_host, self) =>
self.contribute(ComposerExpanders, {
prompt: async (client, session, conversation, text) => {
const ref = await client.get(PromptResources, { session, conversation }, BACKGROUND_CONTEXT);
try {
return ref.variant === "participant" ? (await ref.expand({ text }, BACKGROUND_CONTEXT)).text : undefined;
} finally {
ref.release();
}
},
}),
);