/** * The TUI's own extension registry. * * The harness is a plugin system, and this frontend is one plugin inside it — * but its own parts are plugins too. The status line, the approval prompt, the * model picker, and the composer do not know about each other: each registers a * view into a named slot, and the runner composes the live region from whatever * is registered. Adding a footer widget or replacing the approval prompt is a * registration, not an edit to the runner. * * The web client does the same thing with `ctx.slots`; this is the terminal's * equivalent, deliberately smaller — the live region is a list of lines, so a * slot contributes lines rather than a component tree. * @module dshline/slots */ import { Service } from '@deepseek-ai/cordis'; import type { Context } from '@deepseek-ai/cordis'; import type { Key, LiveCursor } from '@dshline/renderer'; declare module '@deepseek-ai/cordis' { interface Context { tuiSlots: TuiSlots; } } /** * Slots the runner composes into the live region, in this order top to bottom. * The names are positional on purpose: a view chooses where it sits by naming a * slot, so reordering the chrome never means editing the runner. This is * experimental pre-1.0 extension vocabulary, not a stable plugin API. */ export type TuiSlotName = 'stream' | 'composer' | 'completion' | 'timing' | 'status'; /** * A registered contributor of live-region lines. * * Experimental pre-1.0 extension vocabulary; third-party persistent rows must * wait for a global live-region layout budget. */ export interface TuiSlotView { /** * Lines this view contributes right now. * * `rows` is what is LEFT of the terminal at this point in the composition, not * the terminal's own height: the views above this one have already been * rendered and their lines subtracted. A view that bounds itself against the * whole screen would be budgeting against space another view has already * spent — which is how a tall composer plus a suggestion list grew the live * region past the screen. * @param columns - the terminal's current width, for views that fit content. * @param rows - the rows still unspent below this point, when the view bounds * itself. What remains below THIS view is still its own to account for. * @returns logical lines; the screen wraps them. */ render(columns: number, rows?: number): readonly string[]; /** * Where the terminal cursor belongs inside THIS view's own lines, for the one * view that owns text entry. Row 0 is the view's first line, so a view can be * moved or reordered without the runner recomputing anything. * * At most one registered view should answer; the first that does wins. * @param columns - the terminal's current width. * @param rows - the same unspent-row figure {@link TuiSlotView.render} received. * A self-bounding view has to slice what it draws and place its cursor inside * that ONE window; two calculations of it agree everywhere except the short * terminal where they must, and there the disagreement puts the cursor on * chrome below this view instead of on its text. * @returns the placement, or undefined when this view wants no cursor. */ cursor?(columns: number, rows?: number): LiveCursor | undefined; } /** * A view that takes over the whole live region and every keystroke while it is * mounted: an approval prompt, a question, a picker. Overlays stack, and only * the topmost one renders and receives keys, so a question raised while an * approval is pending does not interleave with it. Experimental pre-1.0: * overlays are the supported temporary extension seam, not a stable SDK. */ export interface TuiOverlay extends TuiSlotView { /** * Consume one keystroke. The overlay is responsible for dismissing itself by * disposing its own registration. * @param key - the decoded keystroke. */ handleKey(key: Key): void; /** Called after the overlay becomes mounted. */ mounted?(): void; /** Called once when the overlay is removed, for temporary resources. */ dispose?(): void; } /** * Live-region composition registry. Every mutation notifies the runner through * `tui/render`, so a view that changes its own content asks for a redraw by * calling {@link TuiSlots.invalidate} rather than reaching for the screen. * Experimental pre-1.0: registrations are not yet a public plugin SDK. */ export declare class TuiSlots extends Service { private readonly slots; private readonly overlays; constructor(ctx: Context); /** * Contribute lines to a slot. * @param name - the slot to fill. * @param view - the contributor. * @param priority - higher renders later (further down) within the slot. * @returns the disposer removing this contribution. */ register(name: TuiSlotName, view: TuiSlotView, priority?: number): () => void; /** * Mount an overlay on top of the stack, taking over rendering and input. * * The registration this call makes is transactional: a `mounted()` hook that * throws, or the initial redraw it requests, removes this overlay again and * disposes it once, so the failed overlay's registration is rolled back * before the failure propagates. Side effects the hook performs on its own — * pushing another overlay, for instance — are their own registrations and * outside this contract. The overlay is removed by identity BEFORE its * disposal runs, so a throwing disposer cannot leave it registered for * teardown to dispose a second time. * @param overlay - the overlay to mount. * @returns the disposer unmounting it; safe to call more than once. * @throws the `mounted()` or initial-invalidation failure, or an * `AggregateError` carrying it with any rollback disposal or invalidation * failure. */ pushOverlay(overlay: TuiOverlay): () => void; /** The overlay owning rendering and input, or undefined when none is mounted. */ get activeOverlay(): TuiOverlay | undefined; /** * Compose the live region. * * An overlay replaces the whole region and takes every key, so it contributes * no cursor: text entry belongs to the composer, which is not on screen while * an overlay is up. * * Each slot view is asked for its lines with the rows the views above it have * NOT already spent. The live region must never exceed the screen — rows that * have scrolled off cannot be climbed back to and erased — and no single view * can enforce that alone, because none of them knows how tall the others are. * Subtracting as it goes is what makes a self-bounding view's budget true. * @param columns - the terminal's current width. * @param rows - the terminal's current height; defaults for older callers. * @returns the lines to draw top to bottom, and where the cursor belongs. */ compose(columns: number, rows?: number): { lines: string[]; cursor: LiveCursor | undefined; }; /** * Enforce the live region's height as a last resort. * * Every view is handed the rows the views above it have not spent, but a view * that ignores its budget — or one added by a future capability — would push * the region past the screen, where the first rows have scrolled off and can * never be climbed back to or erased. * * The cut yields to the cursor. When a view owns the cursor, the row it points * at is the interactive surface a person is typing into. Rows ABOVE the cursor * (earlier slots: the stream, and the composer's own upper rows) are * surrendered first, then any excess from the bottom ends; what survives is the * cursor row and the rows immediately below it, which are the later slots the * top-drop policy already preferred (completion, timing, status). The cursor is * translated by the same amounts and is never mapped onto unrelated surviving * content. A region with no cursor keeps the simpler policy of dropping from * the top. * @param lines - the composed lines, mutated in place. * @param cursor - the composed cursor, in those lines. * @param rows - the terminal's height. * @returns the same lines, bounded, and a cursor that still names a drawn row. */ private boundHeight; /** Ask the runner to redraw. */ invalidate(): void; } declare module '@deepseek-ai/cordis' { interface Events { /** The live region's content changed and should be redrawn. */ 'tui/render': () => void; } } //# sourceMappingURL=slots.d.ts.map