// Svelte adapter (0.31.0) — `@pouchy_ai/companion-sdk/svelte`. // Implements the Svelte STORE CONTRACT (subscribe(run) → unsubscribe) by hand, // so it needs no `svelte` import and works from Svelte 3 through 5 (`$store` // auto-subscription, or `fromStore()` in runes mode). Behavior lives in // adapter-core.ts. // // const companion = companionStore(client); // $companion.transcript / $companion.draft / $companion.streamState // companion.sendText('hi'); import type { CompanionClient } from './client'; import { createCompanionView, type CompanionView, type CompanionViewOptions, type CompanionViewSnapshot } from './adapter-core'; /** Svelte-store-contract readable of the companion view snapshot. */ export interface CompanionStore { /** Store contract: calls `run` with the current snapshot immediately and on * every change. Returns unsubscribe. */ subscribe(run: (snapshot: CompanionViewSnapshot) => void): () => void; sendText: CompanionView['sendText']; confirmAction: CompanionView['confirmAction']; /** Detach from the client (does not close it). */ dispose(): void; client: CompanionClient; } /** Wrap a host-owned client as a Svelte-compatible readable store. */ export function companionStore( client: CompanionClient, opts?: CompanionViewOptions ): CompanionStore { const view = createCompanionView(client, opts); return { subscribe(run) { run(view.getSnapshot()); return view.subscribe(() => run(view.getSnapshot())); }, sendText: view.sendText, confirmAction: view.confirmAction, dispose: view.dispose, client }; }