import type { Identity } from "../crypto/identity"; import type { Listener, PipeupDocument } from "../document"; import type { SignedOp, Thread } from "../model/types"; import { type ComposerTool } from "./composer"; import type { Ctx } from "./context"; import type { ViewState } from "./here"; /** Bumped only for breaking changes to the add-on object, the host, AddonDocument or the data slots. */ export declare const ADDON_API = 1; export type Teardown = () => void; export type Off = () => void; export type Capability = "sync" | "menu" | "notify" | "note" | "composer" | "panel" | "styles" | "status" | "overlay" | "here" | "sign" | "listnote" | "commentmark" | "reactions" | "identity" | "dialog" | "paste" | "place" | "post"; export interface NetworkUse { when: "never" | "after-consent" | "page-configured"; /** Hosts; "page" is an address the page names. */ to: readonly string[]; /** One plain sentence: what leaves the device, and who sees what. */ says: string; } export interface AddonInfo { id: string; version: string; network: NetworkUse; /** waiting: registered, Pipeup not mounted yet (or unmounted). */ state: "waiting" | "on" | "off" | "failed"; /** Why it is off or failed, in words. */ reason?: string; } export interface PipeupAddon { /** /^[a-z][a-z0-9-]{1,23}$/; also the source of everything it merges. */ readonly id: string; /** The add-on API it was written for; must equal ADDON_API while 0.x. */ readonly api: number; readonly version: string; /** Slots it can't work without. A missing one keeps it off, with a reason. */ readonly needs: readonly Capability[]; /** What it sends where: for people, docs and `pipeup check`. */ readonly network: NetworkUse; /** Once per mount. May return a teardown for what the add-on itself opened. */ setup(host: AddonHost): void | Teardown | Promise; } export type { Listener }; /** What add-ons see of the document: read only. Ops from elsewhere go in through `host.merge`. */ export interface AddonDocument { readonly id: string; /** This reviewer's public key: share sends only ops with author === me. */ readonly me: string; /** This reviewer's name; "" until they add one (they show as their animal). */ readonly name: string; threads(): readonly Thread[]; ops(): readonly SignedOp[]; /** The ways people chose to be reached (an email address, or `gh:`), by writer's key. */ contacts(): ReadonlyMap; onChange(fn: Listener): Off; } export interface MenuItem { id: string; /** 24-unit SVG path data, drawn by Pipeup; never markup. */ icon: readonly string[]; /** Short: the menu is 290 px wide and truncates. */ label(): string; /** Tooltip and aria-description. */ hint(): string; /** Present: a switch row that keeps the menu open. */ checked?(): boolean; /** Short end text, such as "3". */ count?(): string; select(): void | Promise; } export interface ItemHandle { update(): void; remove(): void; } export interface PanelOptions { label: string; onClose?(): void; } export interface PanelHandle { close(): void; } export interface Status { /** Plain words: "Live with 2 others". */ text: string; people?: readonly { key: string; name: string; view?: ViewState; }[]; } /** A quiet line under the All comments header: words, and optionally one text button ("Check for replies"). */ export interface ListNote { text: string; action?: { label: string; run(): Promise; }; } export interface UiSnapshot { /** Comments are showing. */ shown: boolean; commentMode: boolean; /** All comments is open. */ allOpen: boolean; dark: boolean; view: ViewState | undefined; /** null: not writing; "": the new-comment box; else that thread's reply line. */ writing: string | null; } import type { ReactionPicker } from "./reactions"; export type { ReactionPicker } from "./reactions"; export type { ComposerHandle, ComposerTool, Dictation } from "./composer"; export interface DialogHandle { close(): void; } /** This reviewer's identity, for an add-on that backs it up or replaces it (the add-on is trusted with it, as with any script on the page). */ export interface IdentityAccess { /** The identity was made portable: its key can be backed up. An ordinary one can't leave the browser. */ readonly portable: boolean; /** The 32-byte seed of a portable identity; null for an ordinary one. */ seed(): Promise; /** Keeps `key`, an extractable Ed25519 private key, as this browser's identity from the next load on. */ use(key: CryptoKey): Promise; /** Shares how to reach this reviewer (an email address or `gh:name`) with everyone who has the comments; false if it isn't one. */ share(contact: string): Promise; /** Stops sharing it. */ unshare(): Promise; } /** What the reviewer sent from an add-on's own place or panel (§11b): a new thread on a block, a reply, or a change to their own comment. */ export interface PostOptions { /** A new thread's block: an element the author marked for the add-on (`data-pipeup-ask` or `data-pipeup-inline`). */ anchor?: Element; text: string; /** What the reviewer saw there (an ask's question), kept with a new thread instead of the block's own words. */ excerpt?: string; /** The comment answered. */ replyTo?: string; /** The reviewer's own comment, changed to `text`. */ edit?: string; /** The reviewer's own comment, deleted as Delete does (a thread's first comment takes its replies); `text` is unused. */ remove?: string; } /** Small values kept by whatever adds Pipeup (the browser extension's own storage), out of the site's reach. */ export interface Keep { get(key: string): Promise; set(key: string, value: unknown): Promise; } export interface AddonHost { readonly api: number; /** The core's version, for diagnostics only. */ readonly version: string; readonly document: AddonDocument; /** The area people comment on. */ readonly root: Element; /** This browser can't keep comments (they are held in memory). */ readonly ephemeral: boolean; /** * Where this add-on keeps its choices when whatever added Pipeup keeps them (the browser extension), so the site can * neither read nor set them. Absent on a page that loads Pipeup itself. */ readonly keep?: Keep; /** Aborted at teardown: pass it to fetch, timers and sockets. */ readonly signal: AbortSignal; has(c: Capability): boolean; /** Says the add-on can't work here (no speech engine, nothing configured): it stays off, with this reason. */ off(reason: string): void; /** Verifies and merges ops from elsewhere, as a feedback file's are; the source is this add-on's id. */ merge(ops: readonly unknown[]): Promise; addMenuItem(item: MenuItem): ItemHandle; notify(text: string): void; announce(text: string): void; setComposerNote(text: string | null): void; /** * Shows `text` at the end of a thread as a reply being written (an AI's, streaming in); null removes it. It is * only shown: the real reply is a signed op the add-on merges when it is finished. */ setThreadNote(thread: string, text: string | null): void; /** A quiet line at the end of a thread, with a still AI ring ("Reviewed by AI · nothing to add"); null removes it. */ setThreadMark(thread: string, text: string | null, again?: () => void): void; /** * A quiet mark on one comment, a root or a reply: under its words in an open thread, and as a small glyph beside its * time on a closed card, with `tip` as its tooltip ("Only in this browser"); null removes it. Capability `commentmark`. */ setCommentMark(comment: string, mark: { text: string; tip?: string; } | null): void; addComposerTool(tool: ComposerTool): Off; openPanel(content: Node, options: PanelOptions): PanelHandle; addStyles(css: string): Off; setStatus(status: Status | null): void; /** Shows (or, with null, removes) this add-on's line under the All comments header. */ setListNote(note: ListNote | null): void; /** Offers the full set of emoji for reactions: the quick row then ends with a button that opens it. */ setReactionPicker(picker: ReactionPicker | null): void; overlay(): HTMLElement; onFrame(fn: () => void): Off; /** What a comment on `at` would save. */ where(at?: Node): ViewState | undefined; /** The rule threads follow: this view is where the reviewer is. */ isHere(view?: ViewState): boolean; /** Goes to `view`; true once there. */ go(view: ViewState): Promise; /** Called at once, then on every change. */ onUi(fn: (ui: UiSnapshot) => void): Off; avatar(key: string, name: string): HTMLElement; sign(name: string, data: string): Promise; readonly identity: IdentityAccess; /** A small dialog over the page, labelled `label`; Escape closes it, and it goes with the add-on. */ openDialog(content: Node, label: string): DialogHandle; /** * Adds an agent's reply the reviewer pasted (and, with `note`, marks the thread addressed): signed by the reviewer, * under the agent's name, so it shows as "pasted by you". It never resolves, reopens, edits or deletes. */ paste(thread: string, agent: string, text: string, note?: string): Promise; /** * A shadow root to draw in, inside `element`: one the author marked for add-ons (`data-pipeup-ask` or * `data-pipeup-inline`), and nothing else (it throws). The same element gives the same root. It follows Pipeup's * light and dark looks, comment mode leaves it to the add-on, and it is gone, with the page as it was, at teardown. */ place(element: Element): ShadowRoot; /** * Posts what the reviewer wrote or chose and sent themselves, from this add-on's own place or panel: it is refused * (rejects) unless a press or key there started it. Resolves to the new comment's id (or, for `edit` and `remove`, * the one changed or deleted). */ post(o: PostOptions): Promise; } /** * Everything add-ons put on the page, held by the app (not by the views) so it survives layout rebuilds. Each * thing belongs to one add-on and is removed with it. */ export declare class Surface { readonly ctx: Ctx; private readonly shadow; private readonly after; /** Bumped when the set of menu rows changes. */ rev: number; readonly menuRows: MenuItem[]; readonly notes: Map; /** The threads each add-on is writing into, so its notes go with it. */ private readonly writing; private readonly marked; private paint; readonly statuses: Map; readonly listNotes: Map; /** The emoji picker an add-on brought, if any (the latest to set one). */ picker: ReactionPicker | null; private pickerOwner; private readonly toolList; private readonly frames; private readonly uis; private readonly subs; private readonly overlays; private readonly pending; /** How to take away each thing an add-on added, so everything one add-on added goes with it. */ private readonly undo; private remote; private last; private timer; private uiKey; /** Where each add-on draws in the page: marked element → its . */ private readonly places; /** Each place's shadow root (closed, as Pipeup's own, when the host keeps Pipeup from the page). */ private readonly placeRoots; private aside; private looked; /** Where the reviewer's latest press or key happened: `post` is only for what they sent from the add-on's own UI. */ private pressed; private readonly onPress; constructor(ctx: Ctx, shadow: ShadowRoot, after: Node); subscribe(fn: (structure: boolean) => void): Off; private changed; /** Remembers how to remove something an add-on added; returns the add-on's own `Off` for it. */ private own; /** The add-ons' statuses, one line. */ statusText(): string; rowFor(id: string, item: MenuItem): ItemHandle; /** Shows (or, with null, removes) the reply an add-on is writing into a thread; the views pick it up next frame. */ setThread(id: string, thread: string, text: string | null): void; setMark(id: string, thread: string, text: string | null, again?: () => void): void; /** One mark per comment: the latest add-on to set it owns it, and only the owner's null (or removal) takes it away. */ setCommentMark(id: string, comment: string, mark: { text: string; tip?: string; } | null): void; private repaint; /** Sets (or, with null, removes) one add-on's note or status. */ setIn(map: Map, id: string, value: T | null): void; setPicker(id: string, picker: ReactionPicker | null): void; addTool(id: string, tool: ComposerTool): Off; /** Comments are closed: only the control shows, so a notice waits for the reviewer to open Pipeup. */ private closed; notice(id: string, text: string): void; /** Shows the latest notice kept while comments were closed. Called when the menu or comments open. */ flush(): void; /** A reviewer is writing: a Pipeup line has words or focus. */ private isWriting; /** * An add-on's own words (state changes such as "Listening") are heard at once, while comments are showing: * they answer something the reviewer just did, so they don't wait for them to stop writing. */ addSay(text: string): void; /** Other people's new comments are announced as one coalesced sentence. */ heard(added: readonly SignedOp[], source: string): void; private pump; ovFor(id: string): HTMLElement; addSheet(id: string, css: string): Off; /** Adds a callback to one of the sets; the add-on's `Off` takes it away. */ addTo(id: string, set: Set, fn: T): Off; onTick(id: string, fn: () => void): Off; onSnap(id: string, fn: (ui: UiSnapshot) => void): Off; uiState(): UiSnapshot; /** The data-pipeup-id of each block an add-on draws in: its threads show there, not in the margin. */ inPlace(): Set; place(id: string, el: Element): ShadowRoot; /** Gives a place Pipeup's look as it is now, light or dark: the colours and easing add-ons use (`--pu-text`…). */ private colour; /** A stylesheet for the page itself, without adding an element where it can (a constructed sheet). */ private pageSheet; /** The reviewer's latest press or key was in this add-on's place or panel, and the browser still counts it. */ private sentFrom; post(id: string, o: PostOptions): Promise; /** Runs once per animation frame, after the views; a callback that throws is removed. */ frame(): void; private call; /** A side panel: the rest of Pipeup's UI is inert while it is open; Escape closes it before anything else. */ panel(id: string, content: Node, o: PanelOptions): PanelHandle; dialog(id: string, content: Node, label: string): DialogHandle; /** Removes everything one add-on added. */ clear(id: string): void; destroy(): void; } interface Live { surface: Surface; doc: PipeupDocument; root: Element; ephemeral: boolean; keep?: Keep; version: string; active: boolean; /** Keeps another identity for this browser, used from the next load. */ onIdentity(identity: Identity): Promise; } /** * A Pipeup already on the page when this copy loaded (the classic build assigns its global only when it ends, so * this is read at load): the first copy owns the registry, the queue and the mount; this one hands over to it. */ export declare const firstCore: { VERSION: string; use(a: PipeupAddon): void; addons(): readonly AddonInfo[]; mount(o?: unknown): Promise; } | null; export declare function addons(): readonly AddonInfo[]; /** Registers an add-on: it sets up now if Pipeup is mounted, else when it mounts. */ export declare function use(addon: PipeupAddon): void; /** * Takes the add-ons scripts queued before Pipeup loaded, and makes later pushes register at once. Idempotent; * returns false when another core owns the queue. */ export declare function drainQueue(): boolean; /** Sets up every waiting add-on for this mount, in registration order. Returns the function that tears them down. */ export declare function attachAddons(o: Omit): () => void;