Luigit
repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

extensions/ephemlets/src/types.ts

Raw
import type { Usage } from "@earendil-works/pi-ai";
import type {
	ExtensionAPI,
	ExtensionContext,
	Theme,
} from "@earendil-works/pi-coding-agent";
import type {
	Component,
	KeybindingsManager,
	TUI,
} from "@earendil-works/pi-tui";

export type Json =
	| null
	| boolean
	| number
	| string
	| Json[]
	| { [key: string]: Json };
export type Ephemlet = {
	id: string;
	title: string;
	purpose: string;
	kind: "markdown" | "interactive";
	revision: number;
	status: "building" | "ready" | "failed";
	source: string;
	state: Json;
	error: string | null;
	jobId: string | null;
	fallback?: { kind: "markdown" | "interactive"; source: string; state: Json };
};

/** A native Pi component, not an extension factory. Dispose everything it starts. */
export type EphemletComponent = Component & {
	focused?: boolean;
	dispose?(): void;
};
export type MountContext = {
	pi: ExtensionAPI;
	/** Always the current session context; do not retain a tool-call context. */
	readonly ctx: ExtensionContext;
	tui: TUI;
	theme: Theme;
	keybindings: KeybindingsManager;
	readonly state: Json;
	setState(state: Json): void;
	viewport(): { width: number; height: number };
	signal: AbortSignal;
};
export type EphemletFactory = (
	context: MountContext,
) => EphemletComponent | Promise<EphemletComponent>;
export type BuildRequest = {
	id: string;
	title: string;
	purpose: string;
	brief: string;
	state: Json;
	source: string;
	model?: string;
};
export type BuildResult = { source: string; usage: Usage };