@lunora/vue 1.0.0-alpha.35 → 1.0.0-alpha.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Component, Ref, InjectionKey, App, DeepReadonly, MaybeRefOrGetter, ComputedRef, ShallowRef } from 'vue';
2
- import { Preloaded, LunoraClient, User, ConnectionStatus, FunctionReference, ReturnOf, ArgsOf, MutationCallOptions, MutatorHandle } from '@lunora/client';
1
+ import { Component, Ref, InjectionKey, App, MaybeRefOrGetter, ComputedRef, DeepReadonly, ShallowRef } from 'vue';
2
+ import { Preloaded, LunoraClient, FunctionReference, User, ConnectionStatus, ReturnOf, ArgsOf, MutationCallOptions, MutatorHandle } from '@lunora/client';
3
3
  export type { ArgsOf, FunctionReference, LunoraClient, MutationCallOptions, MutatorHandle, MutatorTransaction, OptimisticLocalStore, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe, User } from '@lunora/client';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
5
5
  export type { PaginationResult, PaginationStatus } from '@lunora/client/pagination';
@@ -72,6 +72,409 @@ interface UseQueryOptions {
72
72
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
73
73
  shardKey?: string;
74
74
  }
75
+ /**
76
+ * The lifecycle status stored on an agent thread. Client-safe mirror of
77
+ * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
78
+ * so this Vue entry never pulls in the server-only `@lunora/agent` module graph
79
+ * (the adapter stays Vue + `@lunora/client` only). Keep in sync with
80
+ * `packages/agent/src/types.ts`.
81
+ */
82
+ type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "running";
83
+ /**
84
+ * The live thread record surfaced by the `agents:agentThread` query. A structural
85
+ * subset of the persisted thread row — every field beyond `status` is optional so
86
+ * the shape stays forgiving as the server schema grows. Keep in sync with the
87
+ * `agent_threads` table in `packages/agent/src/component.ts`.
88
+ */
89
+ interface AgentThreadRecord {
90
+ createdAt?: number;
91
+ /** The failure message when `status === "error"`. */
92
+ error?: string;
93
+ /** The workflow instance id of the in-flight run — the handle `cancel` targets. */
94
+ instanceId?: string;
95
+ messageCount?: number;
96
+ /** The verified thread owner, when the run was started with one. */
97
+ owner?: string;
98
+ status: AgentThreadStatus;
99
+ title?: string;
100
+ updatedAt?: number;
101
+ }
102
+ /**
103
+ * The `agents.agentThread` reference the composable subscribes to for live thread
104
+ * state (status + the in-flight `instanceId`). A structural subset of the
105
+ * generated `api.agents` surface, so the whole generated `api` object is
106
+ * assignable.
107
+ */
108
+ interface UseAgentApi {
109
+ agents: {
110
+ agentThread: FunctionReference<"query", {
111
+ key: string;
112
+ }, Record<string, unknown> | undefined>;
113
+ };
114
+ }
115
+ interface UseAgentOptions {
116
+ /** The generated `api` — its `agents.agentThread` query drives live thread state. */
117
+ api: UseAgentApi;
118
+ /**
119
+ * Optional app mutation over the agent's cancel path
120
+ * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
121
+ * When omitted (or no run is in flight) {@link UseAgentResult.cancel} is a
122
+ * no-op.
123
+ */
124
+ cancel?: FunctionReference<"mutation">;
125
+ /**
126
+ * The app mutation that starts (or continues) a run — a thin wrapper over
127
+ * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
128
+ * {@link UseAgentOptions.runArgs} and the per-call args.
129
+ */
130
+ run: FunctionReference<"mutation">;
131
+ /** Extra args merged into every `run` call (e.g. an `owner` or `title`). */
132
+ runArgs?: Record<string, unknown>;
133
+ /** The thread to observe and drive — may be a plain value, `ref`, or getter (a reactive source re-subscribes). */
134
+ threadKey: MaybeRefOrGetter<string>;
135
+ }
136
+ interface UseAgentResult {
137
+ /**
138
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
139
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
140
+ */
141
+ cancel: () => Promise<void>;
142
+ /** `true` while a `run` invocation is in flight. */
143
+ pending: Readonly<Ref<boolean>>;
144
+ /** Start (or continue) a run with a user message; extra args merge over `runArgs`. */
145
+ run: (input: string, args?: Record<string, unknown>) => Promise<void>;
146
+ /** The live thread status, or `undefined` before the thread exists. */
147
+ status: ComputedRef<AgentThreadStatus | undefined>;
148
+ /** The live thread record (status, `instanceId`, …), or `undefined` before it exists. */
149
+ thread: ComputedRef<AgentThreadRecord | undefined>;
150
+ }
151
+ /**
152
+ * A placeholder mutation reference so `useMutation` is called unconditionally even
153
+ * when the caller supplies no `cancel` mutation. Its `__lunoraRef` is never
154
+ * dispatched — `cancel()` short-circuits before invoking it unless a real
155
+ * reference was provided.
156
+ */
157
+ /**
158
+ * A thin agent handle: live thread `status` plus `run` / `cancel`, without the
159
+ * chat message surface. Composes `useSubscription(api.agents.agentThread)` for
160
+ * live state and `useMutation` for the run/cancel writes — the Vue counterpart to
161
+ * React's `useAgent`, re-expressed with refs. For the full conversation surface
162
+ * (durable history + streaming + approvals) use `useAgentChat`.
163
+ *
164
+ * `run` and `cancel` stay generic over the app-defined mutations that wrap
165
+ * `ctx.agents.&lt;name>.run` / `.cancel`, so the composable hard-codes no function
166
+ * names beyond the `agents:*` surface. `threadKey` may be reactive — a changing
167
+ * key re-subscribes to the new thread.
168
+ */
169
+ declare const useAgent: (options: UseAgentOptions) => UseAgentResult;
170
+ /**
171
+ * One persisted (or optimistic) thread message, as `agents:agentMessages`
172
+ * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
173
+ * re-declared here (rather than imported) so this Vue entry never pulls in the
174
+ * server-only `@lunora/agent` module graph. Keep in sync with the
175
+ * `agent_messages` table in `packages/agent/src/component.ts`.
176
+ */
177
+ interface AgentChatMessage {
178
+ content: string;
179
+ createdAt?: number;
180
+ /**
181
+ * `true` for a client-side optimistic user message not yet acknowledged by
182
+ * the server. Cleared once the durable history carries the matching user turn.
183
+ */
184
+ optimistic?: boolean;
185
+ role: "assistant" | "system" | "tool" | "user";
186
+ seq: number;
187
+ /** Approval lifecycle marker on a human-in-the-loop tool message. */
188
+ status?: "approved" | "awaiting_approval" | "rejected";
189
+ toolCallId?: string;
190
+ toolCalls?: ReadonlyArray<{
191
+ id: string;
192
+ input: unknown;
193
+ name: string;
194
+ }>;
195
+ toolName?: string;
196
+ }
197
+ /**
198
+ * A live token delta streamed while a turn is generating. Client-safe mirror of
199
+ * `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
200
+ * {@link UseAgentChatResult.streamingText} live and are never replayed; the
201
+ * persisted assistant message stays the single source of truth.
202
+ */
203
+ interface AgentTokenDelta {
204
+ /** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
205
+ kind?: "token";
206
+ /** The incremental text chunk the model just produced. */
207
+ text: string;
208
+ /** The thread this delta belongs to. */
209
+ threadKey: string;
210
+ /** The zero-based index of the turn producing the delta. */
211
+ turn: number;
212
+ }
213
+ /**
214
+ * A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
215
+ * mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
216
+ * surfaced by `useAgentToolEvents`, ignored by {@link UseAgentChatResult.streamingText}.
217
+ */
218
+ interface AgentProgressEvent {
219
+ /** The arbitrary, JSON-serializable payload the tool reported. */
220
+ data: unknown;
221
+ /** Discriminates the progress arm of {@link AgentLiveEvent}. */
222
+ kind: "progress";
223
+ /** The thread this event belongs to. */
224
+ threadKey: string;
225
+ /** The tool call this progress belongs to. */
226
+ toolCallId: string;
227
+ }
228
+ /**
229
+ * A single event on the agent's live-only channel — a streamed token delta or a
230
+ * tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
231
+ * Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
232
+ * it unset).
233
+ */
234
+ type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
235
+ /** The `agents:agentMessages` reference — live durable thread history. */
236
+ type AgentMessagesReference$1 = FunctionReference<"query", {
237
+ key: string;
238
+ limit?: number;
239
+ }, ReadonlyArray<Record<string, unknown>>>;
240
+ /** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
241
+ type AgentApprovalReference = FunctionReference<"mutation", {
242
+ decision: "approve" | "reject";
243
+ instanceId: string;
244
+ note?: string;
245
+ threadKey: string;
246
+ toolCallId: string;
247
+ }, {
248
+ resolved: boolean;
249
+ }>;
250
+ /** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
251
+ type AgentThreadReference = FunctionReference<"query", {
252
+ key: string;
253
+ }, Record<string, unknown> | undefined>;
254
+ /**
255
+ * An app stream reference that tees the agent's in-flight live events, keyed by
256
+ * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
257
+ * sink — tool progress events; this composable consumes only the token arm.
258
+ */
259
+ type AgentTokenStreamReference = FunctionReference<"stream", {
260
+ key: string;
261
+ }, AgentLiveEvent>;
262
+ /**
263
+ * The `agents.*` reference surface the chat composable reads. A structural subset
264
+ * of the generated `api.agents`, so the whole generated `api` object is
265
+ * assignable.
266
+ */
267
+ interface UseAgentChatApi {
268
+ agents: {
269
+ agentMessages: AgentMessagesReference$1;
270
+ agentResolveApproval: AgentApprovalReference;
271
+ agentThread: AgentThreadReference;
272
+ };
273
+ }
274
+ interface UseAgentChatOptions {
275
+ /** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
276
+ api: UseAgentChatApi;
277
+ /**
278
+ * Optional app mutation over the agent's cancel path
279
+ * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
280
+ * When omitted (or no run is in flight) {@link UseAgentChatResult.cancel} is a
281
+ * no-op.
282
+ */
283
+ cancel?: FunctionReference<"mutation">;
284
+ /** History depth forwarded to `agents:agentMessages`. */
285
+ limit?: number;
286
+ /**
287
+ * The app mutation that starts (or continues) a run — a thin wrapper over
288
+ * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
289
+ * {@link UseAgentChatOptions.sendArgs} and the per-call args.
290
+ */
291
+ send: FunctionReference<"mutation">;
292
+ /** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
293
+ sendArgs?: Record<string, unknown>;
294
+ /**
295
+ * Optional live token-delta stream — an app stream function that tees the
296
+ * agent's in-flight deltas. When omitted {@link UseAgentChatResult.streamingText}
297
+ * stays empty and the UI updates message-by-message from durable history.
298
+ */
299
+ stream?: AgentTokenStreamReference;
300
+ /** The thread to observe and continue — may be a plain value, `ref`, or getter (a reactive source re-subscribes). */
301
+ threadKey: MaybeRefOrGetter<string>;
302
+ }
303
+ interface UseAgentChatResult {
304
+ /** Approve a paused human-in-the-loop tool call (optionally with a note). */
305
+ approve: (toolCallId: string, note?: string) => Promise<void>;
306
+ /**
307
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
308
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
309
+ */
310
+ cancel: () => Promise<void>;
311
+ /** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
312
+ messages: ComputedRef<ReadonlyArray<AgentChatMessage>>;
313
+ /** Reject a paused human-in-the-loop tool call (optionally with a reason). */
314
+ reject: (toolCallId: string, note?: string) => Promise<void>;
315
+ /** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
316
+ send: (input: string, args?: Record<string, unknown>) => Promise<void>;
317
+ /** The live thread status, or `undefined` before the thread exists. */
318
+ status: ComputedRef<AgentThreadStatus | undefined>;
319
+ /** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
320
+ streamingText: ComputedRef<string>;
321
+ }
322
+ /**
323
+ * A first-class agent chat surface: live durable history + in-flight token
324
+ * streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
325
+ * the Vue counterpart to React's `useAgentChat`, re-expressed with refs.
326
+ *
327
+ * It composes the existing primitives rather than adding transport:
328
+ * `useSubscription(api.agents.agentMessages)` for durable history,
329
+ * `useSubscription(api.agents.agentThread)` for live status + the in-flight
330
+ * `instanceId`, {@link useStream} over an app token stream for in-flight deltas,
331
+ * and `useMutation` for the writes (`api.agents.agentResolveApproval` for
332
+ * approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*`
333
+ * surface is hard-coded — `send`/`cancel`/`stream` stay generic references.
334
+ *
335
+ * A `send` optimistically appends the user turn so it renders immediately; the
336
+ * optimistic row clears once the durable history carries the acknowledged turn.
337
+ * `streamingText` is live-only: it holds the current turn's streamed text and
338
+ * empties as soon as that turn's assistant message lands in `messages` (the
339
+ * persisted message is the source of truth), consistent with the loop's
340
+ * replay-safe, live-only delta design.
341
+ */
342
+ declare const useAgentChat: (options: UseAgentChatOptions) => UseAgentChatResult;
343
+ /**
344
+ * The `agents.agentState` reference the composable subscribes to for the thread's
345
+ * live synced state. A structural subset of the generated `api.agents` surface
346
+ * (like `UseAgentApi` for `agentThread`), so the whole generated `api` object is
347
+ * assignable. Client-safe: no `@lunora/agent` import — the per-agent state type is
348
+ * mirrored by the composable's generic `T`, since codegen pins the reference
349
+ * return as an optional record (it never evaluates agent config).
350
+ */
351
+ interface UseAgentStateApi {
352
+ agents: {
353
+ agentState: FunctionReference<"query", {
354
+ key: string;
355
+ }, Record<string, unknown> | undefined>;
356
+ };
357
+ }
358
+ interface UseAgentStateOptions {
359
+ /** The generated `api` — its `agents.agentState` query drives live thread state. */
360
+ api: UseAgentStateApi;
361
+ /** The thread whose synced state to observe — may be a plain value, `ref`, or getter (a reactive source re-subscribes). */
362
+ threadKey: MaybeRefOrGetter<string>;
363
+ }
364
+ interface UseAgentStateResult<T> {
365
+ /** The subscription error, if the live channel reported one. */
366
+ error: Ref<Error | undefined>;
367
+ /** The live synced state, or `undefined` before it is seeded/first pushed. */
368
+ state: ComputedRef<T | undefined>;
369
+ }
370
+ /**
371
+ * Subscribe to an agent thread's synced state — the `setState`-style value a tool
372
+ * writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
373
+ * thin wrapper over `useSubscription(api.agents.agentState, { key })`: the server
374
+ * pushes a fresh frame whenever the state changes (the dedicated query's
375
+ * per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
376
+ * `state` updates only on a real `setState`. The Vue counterpart to React's
377
+ * `useAgentState`, re-expressed with refs.
378
+ *
379
+ * Generic over the app's state shape (`useAgentState` with a `SupportState` type
380
+ * argument, itself a record) — the reference is typed as an optional record
381
+ * because codegen cannot see the per-agent state type; the generic casts to `T`.
382
+ * The `extends` bound (not
383
+ * a bare unbounded type parameter) is required: this `.ts` file is parsed
384
+ * JSX-aware by the bundler, where an unbounded type-param arrow is ambiguous with
385
+ * a JSX element.
386
+ */
387
+ declare const useAgentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: UseAgentStateOptions) => UseAgentStateResult<T>;
388
+ /** The `agents:agentMessages` reference — live durable thread history. */
389
+ type AgentMessagesReference = FunctionReference<"query", {
390
+ key: string;
391
+ limit?: number;
392
+ }, ReadonlyArray<Record<string, unknown>>>;
393
+ /**
394
+ * An app stream reference that tees the agent's in-flight live events, keyed by
395
+ * thread. Carries token deltas and tool progress events; this composable consumes
396
+ * only the progress arm (`kind === "progress"`).
397
+ */
398
+ type AgentLiveStreamReference = FunctionReference<"stream", {
399
+ key: string;
400
+ }, AgentLiveEvent>;
401
+ /**
402
+ * The `agents.*` reference surface the tool-events composable reads. A structural
403
+ * subset of the generated `api.agents`, so the whole generated `api` object is
404
+ * assignable.
405
+ */
406
+ interface UseAgentToolEventsApi {
407
+ agents: {
408
+ agentMessages: AgentMessagesReference;
409
+ };
410
+ }
411
+ interface UseAgentToolEventsOptions {
412
+ /** The generated `api` — its `agents.agentMessages` query provides the durable tool lifecycle. */
413
+ api: UseAgentToolEventsApi;
414
+ /** History depth forwarded to `agents:agentMessages`. */
415
+ limit?: number;
416
+ /**
417
+ * Optional live event stream — the same app stream function `useAgentChat`
418
+ * uses. When supplied, ephemeral `ctx.reportProgress(...)` events for the
419
+ * thread are surfaced as `{ type: "progress" }` entries; when omitted only the
420
+ * durable lifecycle (call / result / awaiting-approval) is returned.
421
+ */
422
+ stream?: AgentLiveStreamReference;
423
+ /** The thread whose tool activity to observe — may be a plain value, `ref`, or getter (a reactive source re-subscribes). */
424
+ threadKey: MaybeRefOrGetter<string>;
425
+ }
426
+ /**
427
+ * A single tool-lifecycle event for a thread. The durable arms
428
+ * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
429
+ * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
430
+ * stream and has no `seq`. Discriminate on `type`.
431
+ */
432
+ type AgentToolEvent = {
433
+ data: unknown;
434
+ toolCallId: string;
435
+ type: "progress";
436
+ } | {
437
+ input: unknown;
438
+ seq: number;
439
+ toolCallId: string;
440
+ toolName: string;
441
+ type: "call";
442
+ } | {
443
+ output: string;
444
+ seq: number;
445
+ status?: "approved" | "rejected";
446
+ toolCallId?: string;
447
+ toolName?: string;
448
+ type: "result";
449
+ } | {
450
+ seq: number;
451
+ toolCallId?: string;
452
+ toolName?: string;
453
+ type: "awaiting-approval";
454
+ };
455
+ interface UseAgentToolEventsResult {
456
+ /**
457
+ * The thread's tool events: the durable lifecycle (oldest first, by `seq`)
458
+ * followed by any in-flight ephemeral progress events, recomputed from the live
459
+ * subscription + stream. Treat as derived, not identity-stable.
460
+ */
461
+ events: ComputedRef<ReadonlyArray<AgentToolEvent>>;
462
+ }
463
+ /**
464
+ * A focused view of a thread's tool activity: tool calls, their results,
465
+ * human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
466
+ * without the full chat message surface. The Vue counterpart to React's
467
+ * `useAgentToolEvents`, re-expressed as a `computed`.
468
+ *
469
+ * It composes the existing primitives rather than adding transport:
470
+ * `useSubscription(api.agents.agentMessages)` for the durable lifecycle and
471
+ * {@link useStream} over the optional app event stream for ephemeral progress.
472
+ * Progress events are live-only (the durable path never emits them): they ride
473
+ * the same sink as token deltas and are surfaced here, correlated to their tool
474
+ * call by `toolCallId`. For the conversational surface (messages + streaming text
475
+ * + approvals) use `useAgentChat`; this composable is the tool-observability slice.
476
+ */
477
+ declare const useAgentToolEvents: (options: UseAgentToolEventsOptions) => UseAgentToolEventsResult;
75
478
  interface UseAuthResult {
76
479
  setToken: (token: string | null) => void;
77
480
  token: DeepReadonly<Ref<string | null>>;
@@ -399,6 +802,32 @@ interface UseRateLimitResult {
399
802
  * constant) so the reactive derived values stay settled.
400
803
  */
401
804
  declare const useRateLimit: (config: MaybeRefOrGetter<RateLimitConfig>, options?: UseRateLimitOptions) => UseRateLimitResult;
805
+ /** The lifecycle of a stream the composable is observing. */
806
+ type UseStreamStatus = "complete" | "error" | "idle" | "streaming";
807
+ interface UseStreamResult<T> {
808
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
809
+ cancel: () => void;
810
+ /** Chunks the server has pushed so far, in arrival order. */
811
+ chunks: Ref<ReadonlyArray<T>>;
812
+ error: Ref<Error | undefined>;
813
+ status: Ref<UseStreamStatus>;
814
+ }
815
+ interface UseStreamOptions {
816
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
817
+ maxBuffer?: number;
818
+ shardKey?: string;
819
+ }
820
+ /**
821
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
822
+ * lifecycle status and a cancel function, all as refs. Changing the resolved
823
+ * `args` resets the stream — the previous iterator is cancelled and a fresh one
824
+ * opens with empty `chunks`.
825
+ *
826
+ * `args` may be a plain value, `ref`, or getter; resolving it to `"skip"` keeps
827
+ * the composable mounted without opening a stream (mirrors `useSubscription`).
828
+ * The Vue counterpart to React's `useStream`, re-expressed with refs.
829
+ */
830
+ declare const useStream: <F extends FunctionReference<"stream">>(function_: F, args: MaybeRefOrGetter<"skip" | ArgsOf<F>>, options?: UseStreamOptions) => UseStreamResult<ReturnOf<F>>;
402
831
  interface UseSubscriptionResult<T> {
403
832
  data: Ref<T | undefined>;
404
833
  error: Ref<Error | undefined>;
@@ -414,4 +843,154 @@ interface UseSubscriptionResult<T> {
414
843
  * high-frequency streams.
415
844
  */
416
845
  declare const useSubscription: <F extends FunctionReference>(function_: F, args: MaybeRefOrGetter<ArgsOf<F> | "skip">, options?: UseQueryOptions) => UseSubscriptionResult<ReturnOf<F>>;
417
- export { AuthLoading, Authenticated, type FlagContext, type FlagValue, type HeartbeatReference, LUNORA_INJECTION_KEY, type ListPresentReference, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseSubscriptionResult, createLunora, hydratePreloaded, provideLunora, subscribeToQuery, useAuth, useConnectionStatus, useFlag, useFlags, useInfiniteQuery, useLunora, useMutation, useMutator, usePaginatedQuery, usePresence, useQuery, useRateLimit, useSubscription };
846
+ /**
847
+ * Browser Web Audio subsystems for `useVoiceAgent` — the default microphone
848
+ * capture and speaker playback implementations injected into the composable via
849
+ * its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
850
+ * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
851
+ * composable's transport + reactive-state logic and remains mockable in a
852
+ * non-browser test env.
853
+ */
854
+ /**
855
+ * The negotiated audio format the voice DO streams back. Mirrors
856
+ * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
857
+ * imported) so this Vue package never pulls in the server-only `@lunora/agent`
858
+ * module graph.
859
+ */
860
+ type VoiceAudioFormat = "mp3" | "wav";
861
+ /** Captures microphone audio and reports level / turn boundaries back to the composable. */
862
+ interface VoiceMicrophone {
863
+ /** Mute/unmute the mic without tearing down the capture graph. */
864
+ setMuted: (muted: boolean) => void;
865
+ /** Stop capture and release the media stream + audio graph. */
866
+ stop: () => void;
867
+ }
868
+ /** Plays the server's streamed audio chunks and supports a mid-utterance barge-in. */
869
+ interface VoiceSpeaker {
870
+ /** Queue a decoded audio chunk for gap-minimized playback. */
871
+ enqueue: (audio: Uint8Array) => void;
872
+ /** Drop everything queued and stop the current chunk (barge-in). */
873
+ interrupt: () => void;
874
+ /** Release the playback audio context. */
875
+ stop: () => void;
876
+ }
877
+ /** Config passed to a {@link CreateMicrophone} factory. */
878
+ interface MicrophoneConfig {
879
+ /** The consecutive above-threshold chunk count that counts as a barge-in. */
880
+ interruptChunks: number;
881
+ /** RMS above which the user is considered to be barging in while the agent speaks. */
882
+ interruptThreshold: number;
883
+ /** `true` while `status === "speaking"` — gates barge-in detection. */
884
+ isSpeaking: () => boolean;
885
+ /** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
886
+ onAudio: (pcm: Uint8Array) => void;
887
+ /** A barge-in was detected (RMS spike while the agent is speaking). */
888
+ onInterrupt: () => void;
889
+ /** The current input RMS (0–1), for a level meter. */
890
+ onLevel: (rms: number) => void;
891
+ /** A spoken utterance ended (speech followed by `silenceDurationMs` of silence). */
892
+ onSilence: () => void;
893
+ /** Milliseconds of sub-threshold audio (after speech) that closes an utterance. */
894
+ silenceDurationMs: number;
895
+ /** RMS below which audio counts as silence. */
896
+ silenceThreshold: number;
897
+ }
898
+ type CreateMicrophone = (config: MicrophoneConfig) => Promise<VoiceMicrophone>;
899
+ type CreateSpeaker = (config: {
900
+ audioFormat: VoiceAudioFormat;
901
+ }) => VoiceSpeaker;
902
+ /**
903
+ * The default browser microphone: `getUserMedia` → a Web Audio `ScriptProcessor`
904
+ * that tees 16 kHz PCM frames, tracks input RMS, auto-commits an utterance after
905
+ * a silence gap, and flags a barge-in while the agent is speaking.
906
+ */
907
+ /**
908
+ * The `agents.&lt;name>Voice` reference codegen emits for a voice-enabled agent — a
909
+ * live, WS-backed session keyed by `threadKey`. A structural subset of the
910
+ * generated member, so passing `api.agents.&lt;name>Voice` type-checks.
911
+ */
912
+ type VoiceReference = FunctionReference<"stream", {
913
+ threadKey: string;
914
+ }, Record<string, unknown>>;
915
+ /** The lifecycle of a voice call, mirrored to the UI. */
916
+ type VoiceStatus = "idle" | "listening" | "speaking" | "thinking";
917
+ /** A minimal structural subset of the DOM `WebSocket` the composable drives. */
918
+ interface VoiceSocket {
919
+ binaryType: string;
920
+ close: () => void;
921
+ onclose: ((event: unknown) => void) | null;
922
+ onerror: ((event: unknown) => void) | null;
923
+ onmessage: ((event: {
924
+ data: unknown;
925
+ }) => void) | null;
926
+ onopen: ((event: unknown) => void) | null;
927
+ readonly readyState: number;
928
+ send: (data: ArrayBufferView | ArrayBufferLike | string) => void;
929
+ }
930
+ type CreateSocket = (url: string) => VoiceSocket;
931
+ interface UseVoiceAgentOptions {
932
+ /**
933
+ * Advanced/test seam: build the microphone capture subsystem. Defaults to a
934
+ * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
935
+ * Audio graph stays isolated (and mockable in a non-browser test env).
936
+ */
937
+ createMicrophone?: CreateMicrophone;
938
+ /** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
939
+ createSocket?: CreateSocket;
940
+ /** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
941
+ createSpeaker?: CreateSpeaker;
942
+ /** Consecutive above-`interruptThreshold` chunks that trigger a barge-in. Default `3`. */
943
+ interruptChunks?: number;
944
+ /** Input RMS above which the user is treated as barging in while the agent speaks. Default `0.15`. */
945
+ interruptThreshold?: number;
946
+ /** Milliseconds of silence (after speech) that auto-commits an utterance. Default `1200`. */
947
+ silenceDurationMs?: number;
948
+ /** Input RMS below which audio counts as silence. Default `0.01`. */
949
+ silenceThreshold?: number;
950
+ /** The thread to converse on — shared with the agent's text turns. May be a plain value, `ref`, or getter (resolved when the call opens). */
951
+ threadKey: MaybeRefOrGetter<string>;
952
+ /** The generated `api.agents.&lt;name>Voice` reference — identifies the voice DO endpoint. */
953
+ voice: VoiceReference;
954
+ }
955
+ interface UseVoiceAgentResult {
956
+ /** The current input RMS (0–1) — drive a mic level meter. */
957
+ audioLevel: Readonly<Ref<number>>;
958
+ /** `true` once the WS `ready` handshake completed. */
959
+ connected: Readonly<Ref<boolean>>;
960
+ /** Tear down the call: close the socket, stop the mic, release audio. Idempotent. */
961
+ endCall: () => void;
962
+ /** The last transport/pipeline error, or `undefined`. */
963
+ error: Readonly<Ref<Error | undefined>>;
964
+ /** The live assistant text for the in-flight turn (grows via deltas; finalized on done). */
965
+ interimTranscript: Readonly<Ref<string>>;
966
+ /** `true` while the mic is muted. */
967
+ isMuted: Readonly<Ref<boolean>>;
968
+ /** Send a typed turn (no audio) — a text message spoken back by the agent. */
969
+ sendText: (text: string) => void;
970
+ /** Open the mic, connect the socket, and start the conversation. Idempotent while active. */
971
+ startCall: () => Promise<void>;
972
+ /** The current call lifecycle. */
973
+ status: Readonly<Ref<VoiceStatus>>;
974
+ /** Mute/unmute the microphone. Returns the new muted state. */
975
+ toggleMute: () => boolean;
976
+ /** The last finalized user utterance (STT result). */
977
+ transcript: Readonly<Ref<string>>;
978
+ }
979
+ /**
980
+ * A first-class voice-call surface for a voice-enabled agent: it opens a
981
+ * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
982
+ * streams the agent's synthesized speech back through the browser's audio output,
983
+ * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
984
+ * `audioLevel`) to Vue refs. Pass the generated `api.agents.&lt;name>Voice`
985
+ * reference (never a string), matching `useAgentChat`'s reference-passing style.
986
+ * The Vue counterpart to React's `useVoiceAgent`, re-expressed with refs; the
987
+ * per-call connection lives in a closure variable (a composable runs once per
988
+ * component, so no `ref`-of-ref indirection is needed).
989
+ *
990
+ * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
991
+ * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
992
+ * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
993
+ * `createSocket`) so the composable is drivable outside a browser.
994
+ */
995
+ declare const useVoiceAgent: (options: UseVoiceAgentOptions) => UseVoiceAgentResult;
996
+ export { type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, Authenticated, type FlagContext, type FlagValue, type HeartbeatReference, LUNORA_INJECTION_KEY, type ListPresentReference, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAgentApi, type UseAgentChatApi, type UseAgentChatOptions, type UseAgentChatResult, type UseAgentOptions, type UseAgentResult, type UseAgentStateApi, type UseAgentStateOptions, type UseAgentStateResult, type UseAgentToolEventsApi, type UseAgentToolEventsOptions, type UseAgentToolEventsResult, type UseAuthResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, type UseVoiceAgentOptions, type UseVoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createLunora, hydratePreloaded, provideLunora, subscribeToQuery, useAgent, useAgentChat, useAgentState, useAgentToolEvents, useAuth, useConnectionStatus, useFlag, useFlags, useInfiniteQuery, useLunora, useMutation, useMutator, usePaginatedQuery, usePresence, useQuery, useRateLimit, useStream, useSubscription, useVoiceAgent };