// Vue 3 adapter (0.31.0) — `@pouchy_ai/companion-sdk/vue`. // Thin binding of adapter-core onto a shallowRef; behavior lives (and is // tested) in adapter-core.ts. // // const { snapshot, sendText } = useCompanion(client); // snapshot.value.transcript / snapshot.value.streamState // // Inside a component/effect scope the subscription is torn down automatically // (onScopeDispose); outside any scope, call dispose() yourself. import { getCurrentScope, onScopeDispose, shallowRef, type ShallowRef } from 'vue'; import type { CompanionClient } from './client'; import { createCompanionView, type CompanionView, type CompanionViewOptions, type CompanionViewSnapshot } from './adapter-core'; export interface UseCompanionReturn { /** Reactive, immutable view snapshot (replaced wholesale per change). */ snapshot: ShallowRef; sendText: CompanionView['sendText']; confirmAction: CompanionView['confirmAction']; /** Manual teardown for use outside an effect scope. */ dispose(): void; client: CompanionClient; } /** Reactive companion view state for a host-owned client. */ export function useCompanion( client: CompanionClient, opts?: CompanionViewOptions ): UseCompanionReturn { const view = createCompanionView(client, opts); const snapshot = shallowRef(view.getSnapshot()); const unsub = view.subscribe(() => { snapshot.value = view.getSnapshot(); }); const dispose = () => { unsub(); view.dispose(); }; if (getCurrentScope()) onScopeDispose(dispose); return { snapshot, sendText: view.sendText, confirmAction: view.confirmAction, dispose, client }; }