import type { CompanionClient } from './client.js'; import type { CompanionStreamState } from './client.js'; import type { ConfirmRequestPayload, MessageAttachment } from './protocol.js'; /** One rendered line of the conversation, in arrival order. `'assistant'` * matches the industry role vocabulary and this package's own voice-call * transcript + `@pouchy_ai/react`'s ChatMessage (0.33.0 — was 'companion'). */ export interface CompanionTranscriptEntry { role: 'user' | 'assistant'; text: string; /** Client wall-clock ms when the entry was appended. */ at: number; /** Files an assistant reply produced (CR-731) — from the live * `companion.message` envelope, or from `history()` on a restore (CR-729). * Absent when the reply produced none; render a download link from it. */ attachments?: readonly MessageAttachment[]; } /** Immutable view snapshot. A new object per change — safe to hand to * useSyncExternalStore / $state / shallowRef without defensive copies. */ export interface CompanionViewSnapshot { streamState: CompanionStreamState; /** Rolling transcript, oldest first, capped at `transcriptCap`. */ transcript: readonly CompanionTranscriptEntry[]; /** The in-flight streamed reply (token deltas), '' when none. */ draft: string; typing: boolean; /** Confirm requests that arrived on the stream and haven't been resolved * through this view yet. Rebuild after a reload via client.pendingConfirms() * — confirm_request events are not replayed. */ pendingConfirms: readonly ConfirmRequestPayload[]; /** Sends queued while offline (0.34.0 — the client's `queueOffline` * option): `client.pendingOutbox().length`, live-updated. Always 0 on a * client from an older SDK bundle without the offline queue. */ outbox: number; /** Set when the `restore` history load REJECTED (CR-784). A brand-new * session resolves with no turns and leaves this unset — so a value here is * always a real failure: `not_connected` (restore ran before `connect()`), * `missing_scope` (the token lacks `chat`), a 429 or a 5xx. `code` is the * CompanionError code, or `'unknown'` for an uncoded rejection. */ restoreError?: { code: string; message: string; }; } export interface CompanionViewOptions { /** Max transcript entries kept (oldest dropped). Default 200. */ transcriptCap?: number; /** Restore up to this many recent turns from `client.history()` on * creation, so a reloaded tab isn't blank (same semantic as * `@pouchy_ai/react`'s useMessages). Requires a connected client (a * session must exist). Restored turns land ONLY while the live transcript * is still empty — they never clobber messages that arrived first. * Default 0 (off). */ restore?: number; } export interface CompanionView { /** Stable-reference snapshot (useSyncExternalStore contract). */ getSnapshot(): CompanionViewSnapshot; /** Subscribe to snapshot changes. Returns unsubscribe. */ subscribe(listener: () => void): () => void; /** sendText that also appends the user turn to the transcript. Typed as * the client's own overloaded signature (CR-1054): `Parameters` / * `ReturnType` see only the LAST overload, so an `awaitReply: true` send * was typed as the plain ack and its reply `text` did not type-check. */ sendText: CompanionClient['sendText']; /** confirmAction that also removes the confirm from `pendingConfirms` * (on approve AND deny — both resolve the card server-side). */ confirmAction(confirmId: string, approve: boolean, opts?: { signal?: AbortSignal; }): ReturnType; /** Detach every client subscription. The view goes inert (snapshot frozen, * listeners dropped); the client itself is NOT closed — it belongs to the * host. Idempotent. */ dispose(): void; /** The underlying client, for everything the view doesn't wrap. */ readonly client: CompanionClient; } /** Wire a client into an immutable-snapshot view. Adapters bind this to their * framework; hosts using none of the adapters can consume it directly. */ export declare function createCompanionView(client: CompanionClient, opts?: CompanionViewOptions): CompanionView; //# sourceMappingURL=adapter-core.d.ts.map