@lunora/solid 1.0.0-alpha.23 → 1.0.0-alpha.25

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,6 +1,6 @@
1
- import { LunoraClient, User, ConnectionStatus, FunctionReference, ArgsOf, MutationCallOptions, ReturnOf, MutatorHandle, Preloaded } from '@lunora/client';
1
+ import { LunoraClient, FunctionReference, User, ConnectionStatus, ArgsOf, MutationCallOptions, ReturnOf, MutatorHandle, Preloaded } from '@lunora/client';
2
2
  export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
3
- import { Context, JSX, Accessor } from 'solid-js';
3
+ import { Context, Accessor, JSX } from 'solid-js';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
5
5
  import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
6
6
  /**
@@ -21,6 +21,410 @@ declare const LunoraContext: Context<LunoraClient | undefined>;
21
21
  * `useLunora` has the same contract.
22
22
  */
23
23
  declare const useLunora: () => LunoraClient;
24
+ /**
25
+ * The lifecycle status stored on an agent thread. Client-safe mirror of
26
+ * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
27
+ * so this Solid entry never pulls in the server-only `@lunora/agent` module graph
28
+ * (the adapter stays Solid + `@lunora/client` only). Keep in sync with
29
+ * `packages/agent/src/types.ts`.
30
+ */
31
+ type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "running";
32
+ /**
33
+ * The live thread record surfaced by the `agents:agentThread` query. A structural
34
+ * subset of the persisted thread row — every field beyond `status` is optional so
35
+ * the shape stays forgiving as the server schema grows. Keep in sync with the
36
+ * `agent_threads` table in `packages/agent/src/component.ts`.
37
+ */
38
+ interface AgentThreadRecord {
39
+ createdAt?: number;
40
+ /** The failure message when `status === "error"`. */
41
+ error?: string;
42
+ /** The workflow instance id of the in-flight run — the handle `cancel` targets. */
43
+ instanceId?: string;
44
+ messageCount?: number;
45
+ /** The verified thread owner, when the run was started with one. */
46
+ owner?: string;
47
+ status: AgentThreadStatus;
48
+ title?: string;
49
+ updatedAt?: number;
50
+ }
51
+ /** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
52
+ type MaybeAccessor$1<T> = Accessor<T> | T;
53
+ /**
54
+ * The `agents.agentThread` reference the primitive subscribes to for live thread
55
+ * state (status + the in-flight `instanceId`). A structural subset of the
56
+ * generated `api.agents` surface, so the whole generated `api` object is
57
+ * assignable.
58
+ */
59
+ interface CreateAgentApi {
60
+ agents: {
61
+ agentThread: FunctionReference<"query", {
62
+ key: string;
63
+ }, Record<string, unknown> | undefined>;
64
+ };
65
+ }
66
+ interface CreateAgentOptions {
67
+ /** The generated `api` — its `agents.agentThread` query drives live thread state. */
68
+ api: CreateAgentApi;
69
+ /**
70
+ * Optional app mutation over the agent's cancel path
71
+ * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
72
+ * When omitted (or no run is in flight) {@link CreateAgentResult.cancel} is a
73
+ * no-op.
74
+ */
75
+ cancel?: FunctionReference<"mutation">;
76
+ /**
77
+ * The app mutation that starts (or continues) a run — a thin wrapper over
78
+ * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
79
+ * {@link CreateAgentOptions.runArgs} and the per-call args.
80
+ */
81
+ run: FunctionReference<"mutation">;
82
+ /** Extra args merged into every `run` call (e.g. an `owner` or `title`). */
83
+ runArgs?: Record<string, unknown>;
84
+ /** The thread to observe and drive — a plain value or accessor (an accessor re-subscribes on change). */
85
+ threadKey: MaybeAccessor$1<string>;
86
+ }
87
+ interface CreateAgentResult {
88
+ /**
89
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
90
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
91
+ */
92
+ cancel: () => Promise<void>;
93
+ /** `true` while a `run` invocation is in flight. */
94
+ pending: Accessor<boolean>;
95
+ /** Start (or continue) a run with a user message; extra args merge over `runArgs`. */
96
+ run: (input: string, args?: Record<string, unknown>) => Promise<void>;
97
+ /** The live thread status, or `undefined` before the thread exists. */
98
+ status: Accessor<AgentThreadStatus | undefined>;
99
+ /** The live thread record (status, `instanceId`, …), or `undefined` before it exists. */
100
+ thread: Accessor<AgentThreadRecord | undefined>;
101
+ }
102
+ /**
103
+ * A placeholder mutation reference so `createMutation` is called unconditionally
104
+ * even when the caller supplies no `cancel` mutation. Its `__lunoraRef` is never
105
+ * dispatched — `cancel()` short-circuits before invoking it unless a real
106
+ * reference was provided.
107
+ */
108
+ /**
109
+ * A thin agent handle: live thread `status` plus `run` / `cancel`, without the
110
+ * chat message surface. Composes `createSubscription(api.agents.agentThread)` for
111
+ * live state and `createMutation` for the run/cancel writes — the Solid
112
+ * counterpart to React's `useAgent`, re-expressed with signals. For the full
113
+ * conversation surface (durable history + streaming + approvals) use
114
+ * `createAgentChat`.
115
+ *
116
+ * `run` and `cancel` stay generic over the app-defined mutations that wrap
117
+ * `ctx.agents.&lt;name>.run` / `.cancel`, so the primitive hard-codes no function
118
+ * names beyond the `agents:*` surface. `threadKey` may be an accessor — a changing
119
+ * key re-subscribes to the new thread.
120
+ */
121
+ declare const createAgent: (options: CreateAgentOptions) => CreateAgentResult;
122
+ /**
123
+ * One persisted (or optimistic) thread message, as `agents:agentMessages`
124
+ * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
125
+ * re-declared here (rather than imported) so this Solid entry never pulls in the
126
+ * server-only `@lunora/agent` module graph. Keep in sync with the
127
+ * `agent_messages` table in `packages/agent/src/component.ts`.
128
+ */
129
+ interface AgentChatMessage {
130
+ content: string;
131
+ createdAt?: number;
132
+ /**
133
+ * `true` for a client-side optimistic user message not yet acknowledged by
134
+ * the server. Cleared once the durable history carries the matching user turn.
135
+ */
136
+ optimistic?: boolean;
137
+ role: "assistant" | "system" | "tool" | "user";
138
+ seq: number;
139
+ /** Approval lifecycle marker on a human-in-the-loop tool message. */
140
+ status?: "approved" | "awaiting_approval" | "rejected";
141
+ toolCallId?: string;
142
+ toolCalls?: ReadonlyArray<{
143
+ id: string;
144
+ input: unknown;
145
+ name: string;
146
+ }>;
147
+ toolName?: string;
148
+ }
149
+ /**
150
+ * A live token delta streamed while a turn is generating. Client-safe mirror of
151
+ * `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
152
+ * {@link CreateAgentChatResult.streamingText} live and are never replayed; the
153
+ * persisted assistant message stays the single source of truth.
154
+ */
155
+ interface AgentTokenDelta {
156
+ /** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
157
+ kind?: "token";
158
+ /** The incremental text chunk the model just produced. */
159
+ text: string;
160
+ /** The thread this delta belongs to. */
161
+ threadKey: string;
162
+ /** The zero-based index of the turn producing the delta. */
163
+ turn: number;
164
+ }
165
+ /**
166
+ * A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
167
+ * mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
168
+ * surfaced by `createAgentToolEvents`, ignored by {@link CreateAgentChatResult.streamingText}.
169
+ */
170
+ interface AgentProgressEvent {
171
+ /** The arbitrary, JSON-serializable payload the tool reported. */
172
+ data: unknown;
173
+ /** Discriminates the progress arm of {@link AgentLiveEvent}. */
174
+ kind: "progress";
175
+ /** The thread this event belongs to. */
176
+ threadKey: string;
177
+ /** The tool call this progress belongs to. */
178
+ toolCallId: string;
179
+ }
180
+ /**
181
+ * A single event on the agent's live-only channel — a streamed token delta or a
182
+ * tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
183
+ * Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
184
+ * it unset).
185
+ */
186
+ type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
187
+ /** The `agents:agentMessages` reference — live durable thread history. */
188
+ type AgentMessagesReference$1 = FunctionReference<"query", {
189
+ key: string;
190
+ limit?: number;
191
+ }, ReadonlyArray<Record<string, unknown>>>;
192
+ /** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
193
+ type AgentApprovalReference = FunctionReference<"mutation", {
194
+ decision: "approve" | "reject";
195
+ instanceId: string;
196
+ note?: string;
197
+ threadKey: string;
198
+ toolCallId: string;
199
+ }, {
200
+ resolved: boolean;
201
+ }>;
202
+ /** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
203
+ type AgentThreadReference = FunctionReference<"query", {
204
+ key: string;
205
+ }, Record<string, unknown> | undefined>;
206
+ /**
207
+ * An app stream reference that tees the agent's in-flight live events, keyed by
208
+ * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
209
+ * sink — tool progress events; this primitive consumes only the token arm.
210
+ */
211
+ type AgentTokenStreamReference = FunctionReference<"stream", {
212
+ key: string;
213
+ }, AgentLiveEvent>;
214
+ /**
215
+ * The `agents.*` reference surface the chat primitive reads. A structural subset
216
+ * of the generated `api.agents`, so the whole generated `api` object is
217
+ * assignable.
218
+ */
219
+ interface CreateAgentChatApi {
220
+ agents: {
221
+ agentMessages: AgentMessagesReference$1;
222
+ agentResolveApproval: AgentApprovalReference;
223
+ agentThread: AgentThreadReference;
224
+ };
225
+ }
226
+ interface CreateAgentChatOptions {
227
+ /** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
228
+ api: CreateAgentChatApi;
229
+ /**
230
+ * Optional app mutation over the agent's cancel path
231
+ * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
232
+ * When omitted (or no run is in flight) {@link CreateAgentChatResult.cancel} is
233
+ * a no-op.
234
+ */
235
+ cancel?: FunctionReference<"mutation">;
236
+ /** History depth forwarded to `agents:agentMessages`. */
237
+ limit?: number;
238
+ /**
239
+ * The app mutation that starts (or continues) a run — a thin wrapper over
240
+ * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
241
+ * {@link CreateAgentChatOptions.sendArgs} and the per-call args.
242
+ */
243
+ send: FunctionReference<"mutation">;
244
+ /** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
245
+ sendArgs?: Record<string, unknown>;
246
+ /**
247
+ * Optional live token-delta stream — an app stream function that tees the
248
+ * agent's in-flight deltas. When omitted {@link CreateAgentChatResult.streamingText}
249
+ * stays empty and the UI updates message-by-message from durable history.
250
+ */
251
+ stream?: AgentTokenStreamReference;
252
+ /** The thread to observe and continue — a plain value or accessor (an accessor re-subscribes on change). */
253
+ threadKey: MaybeAccessor$1<string>;
254
+ }
255
+ interface CreateAgentChatResult {
256
+ /** Approve a paused human-in-the-loop tool call (optionally with a note). */
257
+ approve: (toolCallId: string, note?: string) => Promise<void>;
258
+ /**
259
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
260
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
261
+ */
262
+ cancel: () => Promise<void>;
263
+ /** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
264
+ messages: Accessor<ReadonlyArray<AgentChatMessage>>;
265
+ /** Reject a paused human-in-the-loop tool call (optionally with a reason). */
266
+ reject: (toolCallId: string, note?: string) => Promise<void>;
267
+ /** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
268
+ send: (input: string, args?: Record<string, unknown>) => Promise<void>;
269
+ /** The live thread status, or `undefined` before the thread exists. */
270
+ status: Accessor<AgentThreadStatus | undefined>;
271
+ /** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
272
+ streamingText: Accessor<string>;
273
+ }
274
+ /**
275
+ * A first-class agent chat surface: live durable history + in-flight token
276
+ * streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
277
+ * the Solid counterpart to React's `useAgentChat`, re-expressed with signals.
278
+ *
279
+ * It composes the existing primitives rather than adding transport:
280
+ * `createSubscription(api.agents.agentMessages)` for durable history,
281
+ * `createSubscription(api.agents.agentThread)` for live status + the in-flight
282
+ * `instanceId`, {@link createStream} over an app token stream for in-flight deltas,
283
+ * and `createMutation` for the writes (`api.agents.agentResolveApproval` for
284
+ * approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*`
285
+ * surface is hard-coded — `send`/`cancel`/`stream` stay generic references.
286
+ *
287
+ * A `send` optimistically appends the user turn so it renders immediately; the
288
+ * optimistic row clears once the durable history carries the acknowledged turn.
289
+ * `streamingText` is live-only: it holds the current turn's streamed text and
290
+ * empties as soon as that turn's assistant message lands in `messages` (the
291
+ * persisted message is the source of truth), consistent with the loop's
292
+ * replay-safe, live-only delta design.
293
+ */
294
+ declare const createAgentChat: (options: CreateAgentChatOptions) => CreateAgentChatResult;
295
+ /**
296
+ * The `agents.agentState` reference the primitive subscribes to for the thread's
297
+ * live synced state. A structural subset of the generated `api.agents` surface
298
+ * (like `CreateAgentApi` for `agentThread`), so the whole generated `api` object
299
+ * is assignable. Client-safe: no `@lunora/agent` import — the per-agent state type
300
+ * is mirrored by the primitive's generic `T`, since codegen pins the reference
301
+ * return as an optional record (it never evaluates agent config).
302
+ */
303
+ interface CreateAgentStateApi {
304
+ agents: {
305
+ agentState: FunctionReference<"query", {
306
+ key: string;
307
+ }, Record<string, unknown> | undefined>;
308
+ };
309
+ }
310
+ interface CreateAgentStateOptions {
311
+ /** The generated `api` — its `agents.agentState` query drives live thread state. */
312
+ api: CreateAgentStateApi;
313
+ /** The thread whose synced state to observe — a plain value or accessor (an accessor re-subscribes on change). */
314
+ threadKey: MaybeAccessor$1<string>;
315
+ }
316
+ interface CreateAgentStateResult<T> {
317
+ /** The subscription error, if the live channel reported one. */
318
+ error: Accessor<Error | undefined>;
319
+ /** The live synced state, or `undefined` before it is seeded/first pushed. */
320
+ state: Accessor<T | undefined>;
321
+ }
322
+ /**
323
+ * Subscribe to an agent thread's synced state — the `setState`-style value a tool
324
+ * writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
325
+ * thin wrapper over `createSubscription(api.agents.agentState, { key })`: the
326
+ * server pushes a fresh frame whenever the state changes (the dedicated query's
327
+ * per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
328
+ * `state` updates only on a real `setState`. The Solid counterpart to React's
329
+ * `useAgentState`, re-expressed with signals.
330
+ *
331
+ * Generic over the app's state shape (`createAgentState` with a `SupportState`
332
+ * type argument, itself a record) — the reference is typed as an optional record
333
+ * because codegen cannot see the per-agent state type; the generic casts to `T`.
334
+ * The `extends` bound (not a bare unbounded type parameter) is required so the
335
+ * reference's optional-record return casts cleanly to `T`.
336
+ */
337
+ declare const createAgentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: CreateAgentStateOptions) => CreateAgentStateResult<T>;
338
+ /** The `agents:agentMessages` reference — live durable thread history. */
339
+ type AgentMessagesReference = FunctionReference<"query", {
340
+ key: string;
341
+ limit?: number;
342
+ }, ReadonlyArray<Record<string, unknown>>>;
343
+ /**
344
+ * An app stream reference that tees the agent's in-flight live events, keyed by
345
+ * thread. Carries token deltas and tool progress events; this primitive consumes
346
+ * only the progress arm (`kind === "progress"`).
347
+ */
348
+ type AgentLiveStreamReference = FunctionReference<"stream", {
349
+ key: string;
350
+ }, AgentLiveEvent>;
351
+ /**
352
+ * The `agents.*` reference surface the tool-events primitive reads. A structural
353
+ * subset of the generated `api.agents`, so the whole generated `api` object is
354
+ * assignable.
355
+ */
356
+ interface CreateAgentToolEventsApi {
357
+ agents: {
358
+ agentMessages: AgentMessagesReference;
359
+ };
360
+ }
361
+ interface CreateAgentToolEventsOptions {
362
+ /** The generated `api` — its `agents.agentMessages` query provides the durable tool lifecycle. */
363
+ api: CreateAgentToolEventsApi;
364
+ /** History depth forwarded to `agents:agentMessages`. */
365
+ limit?: number;
366
+ /**
367
+ * Optional live event stream — the same app stream function `createAgentChat`
368
+ * uses. When supplied, ephemeral `ctx.reportProgress(...)` events for the
369
+ * thread are surfaced as `{ type: "progress" }` entries; when omitted only the
370
+ * durable lifecycle (call / result / awaiting-approval) is returned.
371
+ */
372
+ stream?: AgentLiveStreamReference;
373
+ /** The thread whose tool activity to observe — a plain value or accessor (an accessor re-subscribes on change). */
374
+ threadKey: MaybeAccessor$1<string>;
375
+ }
376
+ /**
377
+ * A single tool-lifecycle event for a thread. The durable arms
378
+ * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
379
+ * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
380
+ * stream and has no `seq`. Discriminate on `type`.
381
+ */
382
+ type AgentToolEvent = {
383
+ data: unknown;
384
+ toolCallId: string;
385
+ type: "progress";
386
+ } | {
387
+ input: unknown;
388
+ seq: number;
389
+ toolCallId: string;
390
+ toolName: string;
391
+ type: "call";
392
+ } | {
393
+ output: string;
394
+ seq: number;
395
+ status?: "approved" | "rejected";
396
+ toolCallId?: string;
397
+ toolName?: string;
398
+ type: "result";
399
+ } | {
400
+ seq: number;
401
+ toolCallId?: string;
402
+ toolName?: string;
403
+ type: "awaiting-approval";
404
+ };
405
+ interface CreateAgentToolEventsResult {
406
+ /**
407
+ * The thread's tool events: the durable lifecycle (oldest first, by `seq`)
408
+ * followed by any in-flight ephemeral progress events, recomputed from the live
409
+ * subscription + stream. Treat as derived, not identity-stable.
410
+ */
411
+ events: Accessor<ReadonlyArray<AgentToolEvent>>;
412
+ }
413
+ /**
414
+ * A focused view of a thread's tool activity: tool calls, their results,
415
+ * human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
416
+ * without the full chat message surface. The Solid counterpart to React's
417
+ * `useAgentToolEvents`, re-expressed as a memo.
418
+ *
419
+ * It composes the existing primitives rather than adding transport:
420
+ * `createSubscription(api.agents.agentMessages)` for the durable lifecycle and
421
+ * {@link createStream} over the optional app event stream for ephemeral progress.
422
+ * Progress events are live-only (the durable path never emits them): they ride
423
+ * the same sink as token deltas and are surfaced here, correlated to their tool
424
+ * call by `toolCallId`. For the conversational surface (messages + streaming text
425
+ * + approvals) use `createAgentChat`; this primitive is the tool-observability slice.
426
+ */
427
+ declare const createAgentToolEvents: (options: CreateAgentToolEventsOptions) => CreateAgentToolEventsResult;
24
428
  interface UseAuthResult {
25
429
  setToken: (token: string | null) => void;
26
430
  token: Accessor<string | null>;
@@ -340,6 +744,32 @@ interface CreateRateLimitResult {
340
744
  * the derived memos stay settled.
341
745
  */
342
746
  declare const createRateLimit: (config: RateLimitConfig, options?: CreateRateLimitOptions) => CreateRateLimitResult;
747
+ /** The lifecycle of a stream the primitive is observing. */
748
+ type CreateStreamStatus = "complete" | "error" | "idle" | "streaming";
749
+ interface CreateStreamResult<T> {
750
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
751
+ cancel: () => void;
752
+ /** Chunks the server has pushed so far, in arrival order. */
753
+ chunks: Accessor<ReadonlyArray<T>>;
754
+ error: Accessor<Error | undefined>;
755
+ status: Accessor<CreateStreamStatus>;
756
+ }
757
+ interface CreateStreamOptions {
758
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
759
+ maxBuffer?: number;
760
+ shardKey?: string;
761
+ }
762
+ /**
763
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
764
+ * lifecycle status and a cancel function, all as accessors. Changing the
765
+ * resolved `args` resets the stream — the previous iterator is cancelled and a
766
+ * fresh one opens with empty `chunks`.
767
+ *
768
+ * `args` may be a plain value or an accessor; resolving it to `"skip"` keeps the
769
+ * primitive mounted without opening a stream (mirrors `createSubscription`). The
770
+ * Solid counterpart to React's `useStream`, re-expressed with signals.
771
+ */
772
+ declare const createStream: <F extends FunctionReference<"stream">>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: CreateStreamOptions) => CreateStreamResult<ReturnOf<F>>;
343
773
  interface CreateSubscriptionResult<T> {
344
774
  data: Accessor<T | undefined>;
345
775
  error: Accessor<Error | undefined>;
@@ -353,6 +783,156 @@ declare const createSubscription: <F extends FunctionReference>(function_: F, ar
353
783
  shardKey?: string;
354
784
  }) => CreateSubscriptionResult<ReturnOf<F>>;
355
785
  /**
786
+ * Browser Web Audio subsystems for `createVoiceAgent` — the default microphone
787
+ * capture and speaker playback implementations injected into the primitive via
788
+ * its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
789
+ * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
790
+ * primitive's transport + reactive-state logic and remains mockable in a
791
+ * non-browser test env.
792
+ */
793
+ /**
794
+ * The negotiated audio format the voice DO streams back. Mirrors
795
+ * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
796
+ * imported) so this Solid package never pulls in the server-only `@lunora/agent`
797
+ * module graph.
798
+ */
799
+ type VoiceAudioFormat = "mp3" | "wav";
800
+ /** Captures microphone audio and reports level / turn boundaries back to the primitive. */
801
+ interface VoiceMicrophone {
802
+ /** Mute/unmute the mic without tearing down the capture graph. */
803
+ setMuted: (muted: boolean) => void;
804
+ /** Stop capture and release the media stream + audio graph. */
805
+ stop: () => void;
806
+ }
807
+ /** Plays the server's streamed audio chunks and supports a mid-utterance barge-in. */
808
+ interface VoiceSpeaker {
809
+ /** Queue a decoded audio chunk for gap-minimized playback. */
810
+ enqueue: (audio: Uint8Array) => void;
811
+ /** Drop everything queued and stop the current chunk (barge-in). */
812
+ interrupt: () => void;
813
+ /** Release the playback audio context. */
814
+ stop: () => void;
815
+ }
816
+ /** Config passed to a {@link CreateMicrophone} factory. */
817
+ interface MicrophoneConfig {
818
+ /** The consecutive above-threshold chunk count that counts as a barge-in. */
819
+ interruptChunks: number;
820
+ /** RMS above which the user is considered to be barging in while the agent speaks. */
821
+ interruptThreshold: number;
822
+ /** `true` while `status === "speaking"` — gates barge-in detection. */
823
+ isSpeaking: () => boolean;
824
+ /** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
825
+ onAudio: (pcm: Uint8Array) => void;
826
+ /** A barge-in was detected (RMS spike while the agent is speaking). */
827
+ onInterrupt: () => void;
828
+ /** The current input RMS (0–1), for a level meter. */
829
+ onLevel: (rms: number) => void;
830
+ /** A spoken utterance ended (speech followed by `silenceDurationMs` of silence). */
831
+ onSilence: () => void;
832
+ /** Milliseconds of sub-threshold audio (after speech) that closes an utterance. */
833
+ silenceDurationMs: number;
834
+ /** RMS below which audio counts as silence. */
835
+ silenceThreshold: number;
836
+ }
837
+ type CreateMicrophone = (config: MicrophoneConfig) => Promise<VoiceMicrophone>;
838
+ type CreateSpeaker = (config: {
839
+ audioFormat: VoiceAudioFormat;
840
+ }) => VoiceSpeaker;
841
+ /**
842
+ * The default browser microphone: `getUserMedia` → a Web Audio `ScriptProcessor`
843
+ * that tees 16 kHz PCM frames, tracks input RMS, auto-commits an utterance after
844
+ * a silence gap, and flags a barge-in while the agent is speaking.
845
+ */
846
+ /**
847
+ * The `agents.&lt;name>Voice` reference codegen emits for a voice-enabled agent — a
848
+ * live, WS-backed session keyed by `threadKey`. A structural subset of the
849
+ * generated member, so passing `api.agents.&lt;name>Voice` type-checks.
850
+ */
851
+ type VoiceReference = FunctionReference<"stream", {
852
+ threadKey: string;
853
+ }, Record<string, unknown>>;
854
+ /** The lifecycle of a voice call, mirrored to the UI. */
855
+ type VoiceStatus = "idle" | "listening" | "speaking" | "thinking";
856
+ /** A minimal structural subset of the DOM `WebSocket` the primitive drives. */
857
+ interface VoiceSocket {
858
+ binaryType: string;
859
+ close: () => void;
860
+ onclose: ((event: unknown) => void) | null;
861
+ onerror: ((event: unknown) => void) | null;
862
+ onmessage: ((event: {
863
+ data: unknown;
864
+ }) => void) | null;
865
+ onopen: ((event: unknown) => void) | null;
866
+ readonly readyState: number;
867
+ send: (data: ArrayBufferView | ArrayBufferLike | string) => void;
868
+ }
869
+ type CreateSocket = (url: string) => VoiceSocket;
870
+ interface CreateVoiceAgentOptions {
871
+ /**
872
+ * Advanced/test seam: build the microphone capture subsystem. Defaults to a
873
+ * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
874
+ * Audio graph stays isolated (and mockable in a non-browser test env).
875
+ */
876
+ createMicrophone?: CreateMicrophone;
877
+ /** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
878
+ createSocket?: CreateSocket;
879
+ /** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
880
+ createSpeaker?: CreateSpeaker;
881
+ /** Consecutive above-`interruptThreshold` chunks that trigger a barge-in. Default `3`. */
882
+ interruptChunks?: number;
883
+ /** Input RMS above which the user is treated as barging in while the agent speaks. Default `0.15`. */
884
+ interruptThreshold?: number;
885
+ /** Milliseconds of silence (after speech) that auto-commits an utterance. Default `1200`. */
886
+ silenceDurationMs?: number;
887
+ /** Input RMS below which audio counts as silence. Default `0.01`. */
888
+ silenceThreshold?: number;
889
+ /** The thread to converse on — shared with the agent's text turns. May be a plain value or accessor (resolved when the call opens). */
890
+ threadKey: MaybeAccessor$1<string>;
891
+ /** The generated `api.agents.&lt;name>Voice` reference — identifies the voice DO endpoint. */
892
+ voice: VoiceReference;
893
+ }
894
+ interface CreateVoiceAgentResult {
895
+ /** The current input RMS (0–1) — drive a mic level meter. */
896
+ audioLevel: Accessor<number>;
897
+ /** `true` once the WS `ready` handshake completed. */
898
+ connected: Accessor<boolean>;
899
+ /** Tear down the call: close the socket, stop the mic, release audio. Idempotent. */
900
+ endCall: () => void;
901
+ /** The last transport/pipeline error, or `undefined`. */
902
+ error: Accessor<Error | undefined>;
903
+ /** The live assistant text for the in-flight turn (grows via deltas; finalized on done). */
904
+ interimTranscript: Accessor<string>;
905
+ /** `true` while the mic is muted. */
906
+ isMuted: Accessor<boolean>;
907
+ /** Send a typed turn (no audio) — a text message spoken back by the agent. */
908
+ sendText: (text: string) => void;
909
+ /** Open the mic, connect the socket, and start the conversation. Idempotent while active. */
910
+ startCall: () => Promise<void>;
911
+ /** The current call lifecycle. */
912
+ status: Accessor<VoiceStatus>;
913
+ /** Mute/unmute the microphone. Returns the new muted state. */
914
+ toggleMute: () => boolean;
915
+ /** The last finalized user utterance (STT result). */
916
+ transcript: Accessor<string>;
917
+ }
918
+ /**
919
+ * A first-class voice-call surface for a voice-enabled agent: it opens a
920
+ * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
921
+ * streams the agent's synthesized speech back through the browser's audio output,
922
+ * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
923
+ * `audioLevel`) to Solid signals. Pass the generated `api.agents.&lt;name>Voice`
924
+ * reference (never a string), matching `createAgentChat`'s reference-passing style.
925
+ * The Solid counterpart to React's `useVoiceAgent`, re-expressed with signals; the
926
+ * per-call connection lives in a closure variable (a primitive runs once per
927
+ * component, so no signal-of-signal indirection is needed).
928
+ *
929
+ * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
930
+ * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
931
+ * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
932
+ * `createSocket`) so the primitive is drivable outside a browser.
933
+ */
934
+ declare const createVoiceAgent: (options: CreateVoiceAgentOptions) => CreateVoiceAgentResult;
935
+ /**
356
936
  * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
357
937
  * during SSR, then keep it live.
358
938
  *
@@ -405,4 +985,4 @@ interface LunoraProviderProps {
405
985
  * ```
406
986
  */
407
987
  declare const LunoraProvider: (props: LunoraProviderProps) => JSX.Element;
408
- export { AuthLoading, Authenticated, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateSubscriptionResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider, type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createSubscription, hydratePreloaded, useLunora };
988
+ export { type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, Authenticated, type CreateAgentApi, type CreateAgentChatApi, type CreateAgentChatOptions, type CreateAgentChatResult, type CreateAgentOptions, type CreateAgentResult, type CreateAgentStateApi, type CreateAgentStateOptions, type CreateAgentStateResult, type CreateAgentToolEventsApi, type CreateAgentToolEventsOptions, type CreateAgentToolEventsResult, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateStreamOptions, type CreateStreamResult, type CreateStreamStatus, type CreateSubscriptionResult, type CreateVoiceAgentOptions, type CreateVoiceAgentResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider, type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createAgent, createAgentChat, createAgentState, createAgentToolEvents, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createStream, createSubscription, createVoiceAgent, hydratePreloaded, useLunora };