@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
56 lines • 4 kB
TypeScript
import type { NestedRequest, PlaneHandler } from "@earendil-works/pi-agent-core";
import { RuntimeUiBroker } from "../runtime/ui-broker.ts";
import { type ExtensionRunner } from "./runner.ts";
import type { ExtensionUIContext } from "./types.ts";
/**
* The presentation port (brain/hand split S30). UI an extension produces on the hand while it runs a call (widgets,
* notices, status, titles, editor text, ...) goes to the loop that owns the call as requests on the call's nested
* plane, in the order it was produced, and that loop's UI presents it: the UI of the session the client is attached to.
* Dialogs are not presentations; they stay on the UI broker and the remote dialog path. A fused session never builds
* the port: its extensions call the attached UI directly.
*/
export declare const UI_PRESENTATION_PLANE = "ui-presentation";
/** The `ExtensionUIContext` calls that present something and answer nothing, so a port can carry them. */
declare const PRESENTATION_METHODS: readonly ["notify", "setStatus", "setSubagentCost", "setWorkingMessage", "setWorkingVisible", "setWorkingIndicator", "setHiddenThinkingLabel", "setWidget", "setTitle", "setProgramStatus", "pasteToEditor", "setEditorText", "setToolsExpanded"];
export type PresentationMethod = (typeof PRESENTATION_METHODS)[number];
/**
* A port presents, but it cannot answer a dialog, so a runner whose UI is a port reports `hasUI` false: an extension
* that asks only when there is a UI keeps the path it takes without one, as before the port.
*/
export declare const isPresentationOnly: (ui: ExtensionUIContext | undefined) => boolean;
/** One call's port: the UI its handlers and tool see, and the drain the call awaits before it ends. */
export interface PresentationPort {
readonly ui: ExtensionUIContext;
/** Waits for every presentation made so far to be presented; never rejects. */
close(): Promise<void>;
}
/**
* Opens the port for one running call. Presentations are sent one at a time, in order; dialogs, reads and anything
* that does not survive the plane stay on `base` (the UI the hand had before the port). After `close`, presentations
* fall back to `base` too: the call they belonged to has ended, and with it the plane they would have ridden.
*
* Presentation is best-effort relative to the call: it never changes the call's result or error. When the loop cannot
* take a presentation (a loop that serves no `ui-presentation` plane, a refused request), that one and every later one
* are presented on `base` instead, as without the port, and the failure goes to `onUndelivered`, once.
*/
export declare function openPresentationPort(nested: NestedRequest, base?: ExtensionUIContext, onUndelivered?: (error: unknown) => void): PresentationPort;
/** Where the loop runs: presents a forwarded presentation on this runner's UI (the attached client's). */
export declare function servePresentation(runner: ExtensionRunner): PlaneHandler;
/**
* The hand's UI broker: while a call that carries its nested plane runs, its extensions' UI is that call's port, and
* the call ends only after its presentations are presented. Outside such a call it is the broker it extends: unbound
* until a presenter attaches, exactly as before.
*/
export declare class PresentationBroker extends RuntimeUiBroker {
#private;
/**
* `onUndelivered` hears each call's first presentation the loop could not take; the call itself is unaffected.
* `lateNotify` (H3) takes the notices made outside any call, or after the call that made them ended, which would
* otherwise reach no UI: on a hand it is the wake route to the loop. Without a presenter it never answers a dialog.
*/
constructor(onUndelivered: (error: unknown) => void, lateNotify?: ExtensionUIContext["notify"]);
get presenter(): ExtensionUIContext | undefined;
present<T>(nested: NestedRequest | undefined, run: () => Promise<T>): Promise<T>;
}
export {};
//# sourceMappingURL=ui-presentation.d.ts.map