@lunora/solid 1.0.0-alpha.4 → 1.0.0-alpha.41

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.
Files changed (41) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +2 -0
  3. package/dist/index.d.mts +813 -175
  4. package/dist/index.d.ts +813 -175
  5. package/dist/index.mjs +1 -11
  6. package/dist/packem_shared/AuthLoading-D6A1mBRs.mjs +1 -0
  7. package/dist/packem_shared/LunoraContext-CVOsskhY.mjs +1 -0
  8. package/dist/packem_shared/LunoraProvider-cifsrLab.mjs +1 -0
  9. package/dist/packem_shared/createAgent-BbHVxEpf.mjs +1 -0
  10. package/dist/packem_shared/createAgentChat-B79ZiHfq.mjs +1 -0
  11. package/dist/packem_shared/createAgentState-CbE2MP_H.mjs +1 -0
  12. package/dist/packem_shared/createAgentToolEvents-DOU_J3JT.mjs +1 -0
  13. package/dist/packem_shared/createConnectionStatus-B9ly5m1x.mjs +1 -0
  14. package/dist/packem_shared/createFlag-qBxuQ5hP.mjs +1 -0
  15. package/dist/packem_shared/createInfiniteQuery-Cq1TI1WK.mjs +1 -0
  16. package/dist/packem_shared/createMutation-9i34uh8U.mjs +1 -0
  17. package/dist/packem_shared/createMutator-zzxMk2QQ.mjs +1 -0
  18. package/dist/packem_shared/createPresence-DNVSvTzP.mjs +1 -0
  19. package/dist/packem_shared/createQuery-CFb7mUGW.mjs +1 -0
  20. package/dist/packem_shared/createRateLimit-BdVo3eNW.mjs +1 -0
  21. package/dist/packem_shared/createStream-DozkYNOc.mjs +1 -0
  22. package/dist/packem_shared/createSubscription-KbQk0ohZ.mjs +1 -0
  23. package/dist/packem_shared/createVoiceAgent-CzXF9acz.mjs +1 -0
  24. package/dist/packem_shared/hydratePreloaded-BbGFlPEb.mjs +1 -0
  25. package/dist/packem_shared/stable-key-BSG0zK_E.mjs +1 -0
  26. package/dist/server.mjs +1 -1
  27. package/dist/upload.d.mts +2 -0
  28. package/dist/upload.d.ts +2 -0
  29. package/dist/upload.mjs +1 -0
  30. package/package.json +9 -3
  31. package/dist/packem_shared/AuthLoading-RMT5Q_eE.mjs +0 -73
  32. package/dist/packem_shared/LunoraContext-C9SpKj54.mjs +0 -12
  33. package/dist/packem_shared/LunoraProvider-B5BJFk3K.mjs +0 -17
  34. package/dist/packem_shared/createConnectionStatus-D8GPatZX.mjs +0 -14
  35. package/dist/packem_shared/createInfiniteQuery-DyMvQ2Qy.mjs +0 -196
  36. package/dist/packem_shared/createMutation-C7BxzO0y.mjs +0 -36
  37. package/dist/packem_shared/createPresence-DiAak1Jw.mjs +0 -78
  38. package/dist/packem_shared/createQuery-D8mdHfyQ.mjs +0 -28
  39. package/dist/packem_shared/createRateLimit-BA2f8XyF.mjs +0 -76
  40. package/dist/packem_shared/createSubscription-BM2fw8hw.mjs +0 -39
  41. package/dist/packem_shared/hydratePreloaded-CaT1kDBH.mjs +0 -25
package/dist/index.d.mts CHANGED
@@ -1,67 +1,502 @@
1
- import { LunoraClient, User, ConnectionStatus, FunctionReference, ArgsOf, MutationCallOptions, ReturnOf, Preloaded } from '@lunora/client';
2
- export type { ArgsOf, FunctionReference, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
3
- import { Context, JSX, Accessor } from 'solid-js';
1
+ import { LunoraClient, FunctionReference, User, ConnectionStatus, ArgsOf, MutationCallOptions, ReturnOf, MutatorHandle, Preloaded } from '@lunora/client';
2
+ export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
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
  /**
7
- * Solid context carrying the framework-neutral {@link LunoraClient}. Every
8
- * reactive primitive in this adapter (`createQuery`, `createMutation`,
9
- * `hydratePreloaded`) reads the client from here, so a single
10
- * `<LunoraProvider client={…}>` at the root of the tree wires the whole app.
11
- *
12
- * Defaults to `undefined` so {@link useLunora} can throw a helpful error when a
13
- * primitive is used outside a provider rather than dereferencing it.
14
- */
7
+ * Solid context carrying the framework-neutral {@link LunoraClient}. Every
8
+ * reactive primitive in this adapter (`createQuery`, `createMutation`,
9
+ * `hydratePreloaded`) reads the client from here, so a single
10
+ * `<LunoraProvider client={…}>` at the root of the tree wires the whole app.
11
+ *
12
+ * Defaults to `undefined` so {@link useLunora} can throw a helpful error when a
13
+ * primitive is used outside a provider rather than dereferencing it.
14
+ */
15
15
  declare const LunoraContext: Context<LunoraClient | undefined>;
16
16
  /**
17
- * Read the {@link LunoraClient} from the nearest `&lt;LunoraProvider>`.
18
- *
19
- * Throws when called outside a provider — the client is required to open the
20
- * HTTP/WS transport, so there is no sensible fallback. The React adapter's
21
- * `useLunora` has the same contract.
22
- */
17
+ * Read the {@link LunoraClient} from the nearest `<LunoraProvider>`.
18
+ *
19
+ * Throws when called outside a provider — the client is required to open the
20
+ * HTTP/WS transport, so there is no sensible fallback. The React adapter's
21
+ * `useLunora` has the same contract.
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.<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.<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 thin agent handle: live thread `status` plus `run` / `cancel`, without the
104
+ * chat message surface. Composes `createSubscription(api.agents.agentThread)` for
105
+ * live state and `createMutation` for the run/cancel writes — the Solid
106
+ * counterpart to React's `useAgent`, re-expressed with signals. For the full
107
+ * conversation surface (durable history + streaming + approvals) use
108
+ * `createAgentChat`.
109
+ *
110
+ * `run` and `cancel` stay generic over the app-defined mutations that wrap
111
+ * `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
112
+ * names beyond the `agents:*` surface. `threadKey` may be an accessor — a changing
113
+ * key re-subscribes to the new thread.
114
+ */
115
+ declare const createAgent: (options: CreateAgentOptions) => CreateAgentResult;
116
+ /**
117
+ * One persisted (or optimistic) thread message, as `agents:agentMessages`
118
+ * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
119
+ * re-declared here (rather than imported) so this Solid entry never pulls in the
120
+ * server-only `@lunora/agent` module graph. Keep in sync with the
121
+ * `agent_messages` table in `packages/agent/src/component.ts`.
122
+ */
123
+ interface AgentChatMessage {
124
+ content: string;
125
+ createdAt?: number;
126
+ /**
127
+ * `true` for a client-side optimistic user message not yet acknowledged by
128
+ * the server. Cleared once the durable history carries the matching user turn.
129
+ */
130
+ optimistic?: boolean;
131
+ role: "assistant" | "system" | "tool" | "user";
132
+ seq: number;
133
+ /** Approval lifecycle marker on a human-in-the-loop tool message. */
134
+ status?: "approved" | "awaiting_approval" | "rejected";
135
+ toolCallId?: string;
136
+ toolCalls?: ReadonlyArray<{
137
+ id: string;
138
+ input: unknown;
139
+ name: string;
140
+ }>;
141
+ toolName?: string;
142
+ }
143
+ /**
144
+ * A live token delta streamed while a turn is generating. Client-safe mirror of
145
+ * `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
146
+ * {@link CreateAgentChatResult.streamingText} live and are never replayed; the
147
+ * persisted assistant message stays the single source of truth.
148
+ */
149
+ interface AgentTokenDelta {
150
+ /** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
151
+ kind?: "token";
152
+ /** The incremental text chunk the model just produced. */
153
+ text: string;
154
+ /** The thread this delta belongs to. */
155
+ threadKey: string;
156
+ /** The zero-based index of the turn producing the delta. */
157
+ turn: number;
158
+ }
159
+ /**
160
+ * A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
161
+ * mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
162
+ * surfaced by `createAgentToolEvents`, ignored by {@link CreateAgentChatResult.streamingText}.
163
+ */
164
+ interface AgentProgressEvent {
165
+ /** The arbitrary, JSON-serializable payload the tool reported. */
166
+ data: unknown;
167
+ /** Discriminates the progress arm of {@link AgentLiveEvent}. */
168
+ kind: "progress";
169
+ /** The thread this event belongs to. */
170
+ threadKey: string;
171
+ /** The tool call this progress belongs to. */
172
+ toolCallId: string;
173
+ }
174
+ /**
175
+ * A single event on the agent's live-only channel — a streamed token delta or a
176
+ * tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
177
+ * Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
178
+ * it unset).
179
+ */
180
+ type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
181
+ /** The `agents:agentMessages` reference — live durable thread history. */
182
+ type AgentMessagesReference$1 = FunctionReference<"query", {
183
+ key: string;
184
+ limit?: number;
185
+ }, ReadonlyArray<Record<string, unknown>>>;
186
+ /** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
187
+ type AgentApprovalReference = FunctionReference<"mutation", {
188
+ decision: "approve" | "reject";
189
+ instanceId: string;
190
+ note?: string;
191
+ threadKey: string;
192
+ toolCallId: string;
193
+ }, {
194
+ resolved: boolean;
195
+ }>;
196
+ /** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
197
+ type AgentThreadReference = FunctionReference<"query", {
198
+ key: string;
199
+ }, Record<string, unknown> | undefined>;
200
+ /**
201
+ * An app stream reference that tees the agent's in-flight live events, keyed by
202
+ * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
203
+ * sink — tool progress events; this primitive consumes only the token arm.
204
+ */
205
+ type AgentTokenStreamReference = FunctionReference<"stream", {
206
+ key: string;
207
+ }, AgentLiveEvent>;
208
+ /**
209
+ * The `agents.*` reference surface the chat primitive reads. A structural subset
210
+ * of the generated `api.agents`, so the whole generated `api` object is
211
+ * assignable.
212
+ */
213
+ interface CreateAgentChatApi {
214
+ agents: {
215
+ agentMessages: AgentMessagesReference$1;
216
+ agentResolveApproval: AgentApprovalReference;
217
+ agentThread: AgentThreadReference;
218
+ };
219
+ }
220
+ interface CreateAgentChatOptions {
221
+ /** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
222
+ api: CreateAgentChatApi;
223
+ /**
224
+ * Optional app mutation over the agent's cancel path
225
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
226
+ * When omitted (or no run is in flight) {@link CreateAgentChatResult.cancel} is
227
+ * a no-op.
228
+ */
229
+ cancel?: FunctionReference<"mutation">;
230
+ /** History depth forwarded to `agents:agentMessages`. */
231
+ limit?: number;
232
+ /**
233
+ * The app mutation that starts (or continues) a run — a thin wrapper over
234
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
235
+ * {@link CreateAgentChatOptions.sendArgs} and the per-call args.
236
+ */
237
+ send: FunctionReference<"mutation">;
238
+ /** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
239
+ sendArgs?: Record<string, unknown>;
240
+ /**
241
+ * Optional live token-delta stream — an app stream function that tees the
242
+ * agent's in-flight deltas. When omitted {@link CreateAgentChatResult.streamingText}
243
+ * stays empty and the UI updates message-by-message from durable history.
244
+ */
245
+ stream?: AgentTokenStreamReference;
246
+ /** The thread to observe and continue — a plain value or accessor (an accessor re-subscribes on change). */
247
+ threadKey: MaybeAccessor$1<string>;
248
+ }
249
+ interface CreateAgentChatResult {
250
+ /** Approve a paused human-in-the-loop tool call (optionally with a note). */
251
+ approve: (toolCallId: string, note?: string) => Promise<void>;
252
+ /**
253
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
254
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
255
+ */
256
+ cancel: () => Promise<void>;
257
+ /** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
258
+ messages: Accessor<ReadonlyArray<AgentChatMessage>>;
259
+ /** Reject a paused human-in-the-loop tool call (optionally with a reason). */
260
+ reject: (toolCallId: string, note?: string) => Promise<void>;
261
+ /** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
262
+ send: (input: string, args?: Record<string, unknown>) => Promise<void>;
263
+ /** The live thread status, or `undefined` before the thread exists. */
264
+ status: Accessor<AgentThreadStatus | undefined>;
265
+ /** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
266
+ streamingText: Accessor<string>;
267
+ }
268
+ /**
269
+ * A first-class agent chat surface: live durable history + in-flight token
270
+ * streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
271
+ * the Solid counterpart to React's `useAgentChat`, re-expressed with signals.
272
+ *
273
+ * It composes the existing primitives rather than adding transport:
274
+ * `createSubscription(api.agents.agentMessages)` for durable history,
275
+ * `createSubscription(api.agents.agentThread)` for live status + the in-flight
276
+ * `instanceId`, {@link createStream} over an app token stream for in-flight deltas,
277
+ * and `createMutation` for the writes (`api.agents.agentResolveApproval` for
278
+ * approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*`
279
+ * surface is hard-coded — `send`/`cancel`/`stream` stay generic references.
280
+ *
281
+ * A `send` optimistically appends the user turn so it renders immediately; the
282
+ * optimistic row clears once the durable history carries the acknowledged turn.
283
+ * `streamingText` is live-only: it holds the current turn's streamed text and
284
+ * empties as soon as that turn's assistant message lands in `messages` (the
285
+ * persisted message is the source of truth), consistent with the loop's
286
+ * replay-safe, live-only delta design.
287
+ */
288
+ declare const createAgentChat: (options: CreateAgentChatOptions) => CreateAgentChatResult;
289
+ /**
290
+ * The `agents.agentState` reference the primitive subscribes to for the thread's
291
+ * live synced state. A structural subset of the generated `api.agents` surface
292
+ * (like `CreateAgentApi` for `agentThread`), so the whole generated `api` object
293
+ * is assignable. Client-safe: no `@lunora/agent` import — the per-agent state type
294
+ * is mirrored by the primitive's generic `T`, since codegen pins the reference
295
+ * return as an optional record (it never evaluates agent config).
296
+ */
297
+ interface CreateAgentStateApi {
298
+ agents: {
299
+ agentState: FunctionReference<"query", {
300
+ key: string;
301
+ }, Record<string, unknown> | undefined>;
302
+ };
303
+ }
304
+ interface CreateAgentStateOptions {
305
+ /** The generated `api` — its `agents.agentState` query drives live thread state. */
306
+ api: CreateAgentStateApi;
307
+ /** The thread whose synced state to observe — a plain value or accessor (an accessor re-subscribes on change). */
308
+ threadKey: MaybeAccessor$1<string>;
309
+ }
310
+ interface CreateAgentStateResult<T> {
311
+ /** The subscription error, if the live channel reported one. */
312
+ error: Accessor<Error | undefined>;
313
+ /** The live synced state, or `undefined` before it is seeded/first pushed. */
314
+ state: Accessor<T | undefined>;
315
+ }
316
+ /**
317
+ * Subscribe to an agent thread's synced state — the `setState`-style value a tool
318
+ * writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
319
+ * thin wrapper over `createSubscription(api.agents.agentState, { key })`: the
320
+ * server pushes a fresh frame whenever the state changes (the dedicated query's
321
+ * per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
322
+ * `state` updates only on a real `setState`. The Solid counterpart to React's
323
+ * `useAgentState`, re-expressed with signals.
324
+ *
325
+ * Generic over the app's state shape (`createAgentState` with a `SupportState`
326
+ * type argument, itself a record) — the reference is typed as an optional record
327
+ * because codegen cannot see the per-agent state type; the generic casts to `T`.
328
+ * The `extends` bound (not a bare unbounded type parameter) is required so the
329
+ * reference's optional-record return casts cleanly to `T`.
330
+ */
331
+ declare const createAgentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: CreateAgentStateOptions) => CreateAgentStateResult<T>;
332
+ /** The `agents:agentMessages` reference — live durable thread history. */
333
+ type AgentMessagesReference = FunctionReference<"query", {
334
+ key: string;
335
+ limit?: number;
336
+ }, ReadonlyArray<Record<string, unknown>>>;
337
+ /**
338
+ * An app stream reference that tees the agent's in-flight live events, keyed by
339
+ * thread. Carries token deltas and tool progress events; this primitive consumes
340
+ * only the progress arm (`kind === "progress"`).
341
+ */
342
+ type AgentLiveStreamReference = FunctionReference<"stream", {
343
+ key: string;
344
+ }, AgentLiveEvent>;
345
+ /**
346
+ * The `agents.*` reference surface the tool-events primitive reads. A structural
347
+ * subset of the generated `api.agents`, so the whole generated `api` object is
348
+ * assignable.
349
+ */
350
+ interface CreateAgentToolEventsApi {
351
+ agents: {
352
+ agentMessages: AgentMessagesReference;
353
+ };
354
+ }
355
+ interface CreateAgentToolEventsOptions {
356
+ /** The generated `api` — its `agents.agentMessages` query provides the durable tool lifecycle. */
357
+ api: CreateAgentToolEventsApi;
358
+ /** History depth forwarded to `agents:agentMessages`. */
359
+ limit?: number;
360
+ /**
361
+ * Optional live event stream — the same app stream function `createAgentChat`
362
+ * uses. When supplied, ephemeral `ctx.reportProgress(...)` events for the
363
+ * thread are surfaced as `{ type: "progress" }` entries; when omitted only the
364
+ * durable lifecycle (call / result / awaiting-approval) is returned.
365
+ */
366
+ stream?: AgentLiveStreamReference;
367
+ /** The thread whose tool activity to observe — a plain value or accessor (an accessor re-subscribes on change). */
368
+ threadKey: MaybeAccessor$1<string>;
369
+ }
370
+ /**
371
+ * A single tool-lifecycle event for a thread. The durable arms
372
+ * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
373
+ * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
374
+ * stream and has no `seq`. Discriminate on `type`.
375
+ */
376
+ type AgentToolEvent = {
377
+ data: unknown;
378
+ toolCallId: string;
379
+ type: "progress";
380
+ } | {
381
+ input: unknown;
382
+ seq: number;
383
+ toolCallId: string;
384
+ toolName: string;
385
+ type: "call";
386
+ } | {
387
+ output: string;
388
+ seq: number;
389
+ status?: "approved" | "rejected";
390
+ toolCallId?: string;
391
+ toolName?: string;
392
+ type: "result";
393
+ } | {
394
+ seq: number;
395
+ toolCallId?: string;
396
+ toolName?: string;
397
+ type: "awaiting-approval";
398
+ };
399
+ interface CreateAgentToolEventsResult {
400
+ /**
401
+ * The thread's tool events: the durable lifecycle (oldest first, by `seq`)
402
+ * followed by any in-flight ephemeral progress events, recomputed from the live
403
+ * subscription + stream. Treat as derived, not identity-stable.
404
+ */
405
+ events: Accessor<ReadonlyArray<AgentToolEvent>>;
406
+ }
407
+ /**
408
+ * A focused view of a thread's tool activity: tool calls, their results,
409
+ * human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
410
+ * without the full chat message surface. The Solid counterpart to React's
411
+ * `useAgentToolEvents`, re-expressed as a memo.
412
+ *
413
+ * It composes the existing primitives rather than adding transport:
414
+ * `createSubscription(api.agents.agentMessages)` for the durable lifecycle and
415
+ * {@link createStream} over the optional app event stream for ephemeral progress.
416
+ * Progress events are live-only (the durable path never emits them): they ride
417
+ * the same sink as token deltas and are surfaced here, correlated to their tool
418
+ * call by `toolCallId`. For the conversational surface (messages + streaming text
419
+ * + approvals) use `createAgentChat`; this primitive is the tool-observability slice.
420
+ */
421
+ declare const createAgentToolEvents: (options: CreateAgentToolEventsOptions) => CreateAgentToolEventsResult;
24
422
  interface UseAuthResult {
25
423
  setToken: (token: string | null) => void;
26
424
  token: Accessor<string | null>;
27
425
  user: Accessor<User | null>;
28
426
  }
29
427
  /**
30
- * Token + identity plumbing for Solid. Returns `{ token, user, setToken }`
31
- * where `token` and `user` are fine-grained signals. `setToken(jwt)` after
32
- * sign-in updates the shared client token; `user` resolves asynchronously via
33
- * `client.getCurrentUser()` and updates on every token change.
34
- */
428
+ * Token + identity plumbing for Solid. Returns `{ token, user, setToken }`
429
+ * where `token` and `user` are fine-grained signals. `setToken(jwt)` after
430
+ * sign-in updates the shared client token; `user` resolves asynchronously via
431
+ * `client.getCurrentUser()` and updates on every token change.
432
+ */
35
433
  declare const createAuth: () => UseAuthResult;
36
434
  interface AuthGateProps {
37
435
  children: JSX.Element;
38
436
  }
39
437
  /**
40
- * Render `children` only after authentication has settled and a token + user
41
- * are both present.
42
- */
438
+ * Render `children` only after authentication has settled and a token + user
439
+ * are both present.
440
+ */
43
441
  declare const Authenticated: (props: AuthGateProps) => JSX.Element;
44
442
  /**
45
- * Render `children` while authentication is still in progress — token is set
46
- * but the user has not yet resolved.
47
- */
443
+ * Render `children` while authentication is still in progress — token is set
444
+ * but the user has not yet resolved.
445
+ */
48
446
  declare const AuthLoading: (props: AuthGateProps) => JSX.Element;
49
447
  /**
50
- * Render `children` only when auth has settled and no token is present (the
51
- * signed-out state).
52
- */
448
+ * Render `children` only when auth has settled and no token is present (the
449
+ * signed-out state).
450
+ */
53
451
  declare const Unauthenticated: (props: AuthGateProps) => JSX.Element;
54
452
  /**
55
- * Reactive accessor of the client's aggregate live-socket status across all
56
- * shard connections. Reads the current status synchronously and updates on
57
- * every transition (`idle` → `connecting` → `connected` → `offline`) — Solid's
58
- * fine-grained signals mean only the components that read the accessor
59
- * re-render. The Solid equivalent of `@lunora/react`'s `useConnectionStatus`.
60
- *
61
- * The status listener is torn down via `onCleanup` when the owning reactive
62
- * scope disposes (component unmount). Call inside a component / reactive root.
63
- */
453
+ * Reactive accessor of the client's aggregate live-socket status across all
454
+ * shard connections. Reads the current status synchronously and updates on
455
+ * every transition (`idle` → `connecting` → `connected` → `offline`) — Solid's
456
+ * fine-grained signals mean only the components that read the accessor
457
+ * re-render. The Solid equivalent of `@lunora/react`'s `useConnectionStatus`.
458
+ *
459
+ * The status listener is torn down via `onCleanup` when the owning reactive
460
+ * scope disposes (component unmount). Call inside a component / reactive root.
461
+ */
64
462
  declare const createConnectionStatus: () => Accessor<ConnectionStatus>;
463
+ /** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
464
+ type FlagContext = Record<string, unknown>;
465
+ /** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
466
+ type FlagValue = boolean | number | string | {
467
+ [key: string]: unknown;
468
+ } | unknown[] | null;
469
+ /** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
470
+ type MaybeAccessor<T> = Accessor<T> | T;
471
+ /**
472
+ * Subscribe to a single feature flag and return a reactive accessor of its value.
473
+ *
474
+ * The accessor reads `defaultValue` until the first evaluation lands, then the
475
+ * server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
476
+ * flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
477
+ * `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
478
+ * and `createFlag("hero", "control")` a string.
479
+ *
480
+ * `key` and `context` may be plain values or accessors; passing an accessor makes
481
+ * the subscription reactive — when it changes the old subscription is torn down
482
+ * (via `onCleanup`) and a fresh one opens. `context` supplies a per-call targeting
483
+ * context merged on top of the app's default `identify` targeting key.
484
+ *
485
+ * Evaluation runs through whatever OpenFeature provider the app wired in
486
+ * `lunora/flags.ts`; the read never throws — a provider error resolves the
487
+ * default (the same fail-open contract as server-side `ctx.flags`).
488
+ */
489
+ declare const createFlag: <T extends FlagValue>(key: MaybeAccessor<string>, defaultValue: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
490
+ /**
491
+ * Subscribe to several feature flags at once and return a reactive accessor of
492
+ * the resolved record.
493
+ *
494
+ * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
495
+ * default, and the accessor reads the same-shaped record with resolved values
496
+ * (the defaults until each evaluation lands). A single `context` applies to every
497
+ * flag and may be an accessor. This is the batched form of {@link createFlag}.
498
+ */
499
+ declare const createFlags: <T extends Record<string, FlagValue>>(flags: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
65
500
  interface MutationHandle<F extends FunctionReference> {
66
501
  /** The latest invocation's resolved value, or `undefined` before the first success. */
67
502
  data: Accessor<ReturnOf<F> | undefined>;
@@ -75,38 +510,70 @@ interface MutationHandle<F extends FunctionReference> {
75
510
  reset: () => void;
76
511
  }
77
512
  /**
78
- * The transport surface {@link createMutation} actually needs — just
79
- * `client.mutation`. Narrowed so the primitive can be exercised against a stub
80
- * in tests without constructing a full `LunoraClient`.
81
- */
513
+ * The transport surface {@link createMutation} actually needs — just
514
+ * `client.mutation`. Narrowed so the primitive can be exercised against a stub
515
+ * in tests without constructing a full `LunoraClient`.
516
+ */
82
517
  interface MutationClient<F extends FunctionReference> {
83
518
  mutation: (function_: F, args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>>) => Promise<ReturnOf<F>>;
84
519
  }
85
520
  /**
86
- * Build a mutation handle bound to an explicit client. Internal seam used by the
87
- * provider-bound {@link createMutation}; exported for tests that inject a stub.
88
- * The ref-counted pending + error-normalize orchestration is the shared
89
- * `createMutationRunner` from `@lunora/client`; only the reactive sinks (Solid
90
- * signals) are adapter-specific.
91
- */
521
+ * Build a mutation handle bound to an explicit client. Internal seam used by the
522
+ * provider-bound {@link createMutation}; exported for tests that inject a stub.
523
+ * The ref-counted pending + error-normalize orchestration is the shared
524
+ * `createMutationRunner` from `@lunora/client`; only the reactive sinks (Solid
525
+ * signals) are adapter-specific.
526
+ */
92
527
  declare const createMutationForClient: <F extends FunctionReference>(client: MutationClient<F>, function_: F) => MutationHandle<F>;
93
528
  /**
94
- * Returns a reactive handle `{ mutate, pending, data, error, reset }` for the
95
- * given mutation reference, bound to the `LunoraClient` from the nearest
96
- * `&lt;LunoraProvider>`.
97
- *
98
- * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
99
- * call options pass straight through to `client.mutation`, which applies and
100
- * rolls them back against the live Lunora subscription cache — the same
101
- * machinery `createQuery`/`hydratePreloaded` subscribe to, so an optimistic
102
- * write reflects in those accessors immediately and reverts on failure.
103
- *
104
- * `pending` is ref-counted across overlapping invocations of *this* handle, so
105
- * it only flips back to `false` once every concurrent call has settled. The
106
- * mutation also engages `@lunora/client`'s offline queue when the socket is
107
- * down, so `mutate` stays durable across reconnects.
108
- */
529
+ * Returns a reactive handle `{ mutate, pending, data, error, reset }` for the
530
+ * given mutation reference, bound to the `LunoraClient` from the nearest
531
+ * `<LunoraProvider>`.
532
+ *
533
+ * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
534
+ * call options pass straight through to `client.mutation`, which applies and
535
+ * rolls them back against the live Lunora subscription cache — the same
536
+ * machinery `createQuery`/`hydratePreloaded` subscribe to, so an optimistic
537
+ * write reflects in those accessors immediately and reverts on failure.
538
+ *
539
+ * `pending` is ref-counted across overlapping invocations of *this* handle, so
540
+ * it only flips back to `false` once every concurrent call has settled. The
541
+ * mutation also engages `@lunora/client`'s offline queue when the socket is
542
+ * down, so `mutate` stays durable across reconnects.
543
+ */
109
544
  declare const createMutation: <F extends FunctionReference>(function_: F) => MutationHandle<F>;
545
+ /**
546
+ * The reactive handle returned by {@link createMutator} — the Solid counterpart
547
+ * to `@lunora/react`'s `useMutator`, re-expressed with signals.
548
+ * `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
549
+ * resolves once the write is persisted (or rejects).
550
+ */
551
+ interface MutatorHook<TArgs> {
552
+ /** The latest invocation's error, or `undefined`. */
553
+ error: Accessor<Error | undefined>;
554
+ /** `true` when the latest invocation rejected. */
555
+ isError: Accessor<boolean>;
556
+ /** Run the mutator; resolves once the write is persisted, rejects on failure. */
557
+ mutate: (args: TArgs) => Promise<void>;
558
+ /** `true` while ANY invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
559
+ pending: Accessor<boolean>;
560
+ /** Clear the latest `error` back to idle. */
561
+ reset: () => void;
562
+ }
563
+ /**
564
+ * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
565
+ * custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
566
+ * equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
567
+ * server-authoritative push are owned by the bound handle (and TanStack DB's
568
+ * optimistic-transaction layer rebases pending overlays on every sync tick);
569
+ * this primitive only surfaces signal state for the in-flight/error lifecycle.
570
+ * Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
571
+ * needed.
572
+ *
573
+ * `pending` is ref-counted across overlapping invocations of THIS handle, so it
574
+ * clears only once every concurrent call has settled.
575
+ */
576
+ declare const createMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
110
577
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
111
578
  type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
112
579
  /** The element type of the `page` array a paginated query returns. */
@@ -146,46 +613,46 @@ interface CreateInfiniteQueryResult<T> {
146
613
  status: Accessor<PaginationStatus>;
147
614
  }
148
615
  /**
149
- * Subscribe to a reactively-paginated query and grow the feed page by page.
150
- *
151
- * The query function must accept a `paginationOpts: { numItems, cursor,
152
- * endCursor }` arg and return a `PaginationResult`. `loadMore` appends the next
153
- * page off the open-ended tail's `continueCursor`; it is a no-op unless
154
- * `status === "CanLoadMore"`.
155
- *
156
- * Call inside a reactive context (component / `createRoot`).
157
- */
616
+ * Subscribe to a reactively-paginated query and grow the feed page by page.
617
+ *
618
+ * The query function must accept a `paginationOpts: { numItems, cursor,
619
+ * endCursor }` arg and return a `PaginationResult`. `loadMore` appends the next
620
+ * page off the open-ended tail's `continueCursor`; it is a no-op unless
621
+ * `status === "CanLoadMore"`.
622
+ *
623
+ * Call inside a reactive context (component / `createRoot`).
624
+ */
158
625
  declare const createPaginatedQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreatePaginatedQueryOptions) => CreatePaginatedQueryResult<PageItemOf<F>>;
159
626
  /**
160
- * Subscribe to a reactively-paginated query and expose its pages discretely.
161
- *
162
- * Shares `createPaginatedQuery`'s pagination engine but keeps each page as its
163
- * own inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
164
- *
165
- * Call inside a reactive context (component / `createRoot`).
166
- */
627
+ * Subscribe to a reactively-paginated query and expose its pages discretely.
628
+ *
629
+ * Shares `createPaginatedQuery`'s pagination engine but keeps each page as its
630
+ * own inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
631
+ *
632
+ * Call inside a reactive context (component / `createRoot`).
633
+ */
167
634
  declare const createInfiniteQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreateInfiniteQueryOptions) => CreateInfiniteQueryResult<PageItemOf<F>>;
168
635
  /**
169
- * `createPresence` — collaborative-awareness primitive, the client half of the
170
- * `@lunora/server` `definePresence` preset.
171
- *
172
- * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
173
- * subscribes to the live `listPresent` query for the given room.
174
- *
175
- * Call inside a reactive context (component / `createRoot`).
176
- */
177
- /**
178
- * A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
179
- */
636
+ * `createPresence` — collaborative-awareness primitive, the client half of the
637
+ * `@lunora/server` `definePresence` preset.
638
+ *
639
+ * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
640
+ * subscribes to the live `listPresent` query for the given room.
641
+ *
642
+ * Call inside a reactive context (component / `createRoot`).
643
+ */
644
+ /**
645
+ * A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
646
+ */
180
647
  type HeartbeatReference = FunctionReference<"mutation", {
181
648
  data?: Record<string, unknown>;
182
649
  roomId: string;
183
650
  sessionId: string;
184
651
  }>;
185
652
  /**
186
- * A listPresent query reference: takes `{ roomId }` and returns the array of
187
- * present members.
188
- */
653
+ * A listPresent query reference: takes `{ roomId }` and returns the array of
654
+ * present members.
655
+ */
189
656
  type ListPresentReference = FunctionReference<"query", {
190
657
  roomId: string;
191
658
  }>;
@@ -199,9 +666,9 @@ interface CreatePresenceOptions<H extends HeartbeatReference, L extends ListPres
199
666
  /** The `api.*` reference for the presence listPresent query. */
200
667
  listPresent: L;
201
668
  /**
202
- * Stable id for this presence row. Defaults to a fresh per-mount id.
203
- * Pass a user/connection id to control deduping across tabs.
204
- */
669
+ * Stable id for this presence row. Defaults to a fresh per-mount id.
670
+ * Pass a user/connection id to control deduping across tabs.
671
+ */
205
672
  sessionId?: string;
206
673
  /** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
207
674
  shardKey?: string;
@@ -220,31 +687,31 @@ interface CreateQueryOptions {
220
687
  shardKey?: string;
221
688
  }
222
689
  /**
223
- * Subscribe to a server query and return a reactive accessor of its value.
224
- *
225
- * The accessor reads `undefined` until the first server frame lands, then
226
- * updates on every delta the WebSocket pushes — Solid's fine-grained signals
227
- * mean only the components that read the accessor re-render, which maps cleanly
228
- * onto Lunora's per-subscription delta model.
229
- *
230
- * `args` may be a plain value or an accessor; passing an accessor makes the
231
- * subscription reactive — when the args change the old subscription is torn down
232
- * (via `onCleanup`) and a fresh one opens for the new args. Pass `"skip"` (or an
233
- * accessor returning `"skip"`) to short-circuit: no network call, no socket.
234
- *
235
- * ```tsx
236
- * const messages = createQuery(api.messages.list, () => ({ channelId: channelId() }));
237
- * return &lt;For each={messages()?.messages}>{(m) => &lt;li>{m.text}&lt;/li>}&lt;/For>;
238
- * ```
239
- */
690
+ * Subscribe to a server query and return a reactive accessor of its value.
691
+ *
692
+ * The accessor reads `undefined` until the first server frame lands, then
693
+ * updates on every delta the WebSocket pushes — Solid's fine-grained signals
694
+ * mean only the components that read the accessor re-render, which maps cleanly
695
+ * onto Lunora's per-subscription delta model.
696
+ *
697
+ * `args` may be a plain value or an accessor; passing an accessor makes the
698
+ * subscription reactive — when the args change the old subscription is torn down
699
+ * (via `onCleanup`) and a fresh one opens for the new args. Pass `"skip"` (or an
700
+ * accessor returning `"skip"`) to short-circuit: no network call, no socket.
701
+ *
702
+ * ```tsx
703
+ * const messages = createQuery(api.messages.list, () => ({ channelId: channelId() }));
704
+ * return <For each={messages()?.messages}>{(m) => <li>{m.text}</li>}</For>;
705
+ * ```
706
+ */
240
707
  declare const createQuery: <F extends FunctionReference>(function_: F, args: (ArgsOf<F> | "skip") | Accessor<ArgsOf<F> | "skip">, options?: CreateQueryOptions) => Accessor<ReturnOf<F> | undefined>;
241
708
  interface CreateRateLimitOptions {
242
709
  /** Clock injection for tests. Defaults to `Date.now`. */
243
710
  now?: () => number;
244
711
  /**
245
- * Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
246
- * ticks down and `disabled` flips back automatically. Defaults to `1000`.
247
- */
712
+ * Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
713
+ * ticks down and `disabled` flips back automatically. Defaults to `1000`.
714
+ */
248
715
  tickMs?: number;
249
716
  }
250
717
  interface CreateRateLimitResult {
@@ -262,78 +729,249 @@ interface CreateRateLimitResult {
262
729
  retryAfter: () => number;
263
730
  }
264
731
  /**
265
- * Client-side mirror of a rate limit for instant UX — disable a button or show
266
- * a countdown without a round-trip. It runs the same token-bucket / fixed-window
267
- * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
268
- * authoritative check; the server remains the source of truth.
269
- *
270
- * `config` is read on every call; pass a stable reference (module constant) so
271
- * the derived memos stay settled.
272
- */
732
+ * Client-side mirror of a rate limit for instant UX — disable a button or show
733
+ * a countdown without a round-trip. It runs the same token-bucket / fixed-window
734
+ * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
735
+ * authoritative check; the server remains the source of truth.
736
+ *
737
+ * `config` is read on every call; pass a stable reference (module constant) so
738
+ * the derived memos stay settled.
739
+ */
273
740
  declare const createRateLimit: (config: RateLimitConfig, options?: CreateRateLimitOptions) => CreateRateLimitResult;
741
+ /** The lifecycle of a stream the primitive is observing. */
742
+ type CreateStreamStatus = "complete" | "error" | "idle" | "streaming";
743
+ interface CreateStreamResult<T> {
744
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
745
+ cancel: () => void;
746
+ /** Chunks the server has pushed so far, in arrival order. */
747
+ chunks: Accessor<ReadonlyArray<T>>;
748
+ error: Accessor<Error | undefined>;
749
+ status: Accessor<CreateStreamStatus>;
750
+ }
751
+ interface CreateStreamOptions {
752
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
753
+ maxBuffer?: number;
754
+ shardKey?: string;
755
+ }
756
+ /**
757
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
758
+ * lifecycle status and a cancel function, all as accessors. Changing the
759
+ * resolved `args` resets the stream — the previous iterator is cancelled and a
760
+ * fresh one opens with empty `chunks`.
761
+ *
762
+ * `args` may be a plain value or an accessor; resolving it to `"skip"` keeps the
763
+ * primitive mounted without opening a stream (mirrors `createSubscription`). The
764
+ * Solid counterpart to React's `useStream`, re-expressed with signals.
765
+ */
766
+ declare const createStream: <F extends FunctionReference<"stream">>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: CreateStreamOptions) => CreateStreamResult<ReturnOf<F>>;
274
767
  interface CreateSubscriptionResult<T> {
275
768
  data: Accessor<T | undefined>;
276
769
  error: Accessor<Error | undefined>;
277
770
  }
278
771
  /**
279
- * Subscribe to a reactive server push stream. Returns `{ data, error }`
280
- * accessors that update whenever the server emits. Passing `"skip"` as `args`
281
- * (or an accessor that resolves to `"skip"`) tears down the subscription.
282
- */
772
+ * Subscribe to a reactive server push stream. Returns `{ data, error }`
773
+ * accessors that update whenever the server emits. Passing `"skip"` as `args`
774
+ * (or an accessor that resolves to `"skip"`) tears down the subscription.
775
+ */
283
776
  declare const createSubscription: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: {
284
777
  shardKey?: string;
285
778
  }) => CreateSubscriptionResult<ReturnOf<F>>;
286
779
  /**
287
- * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
288
- * during SSR, then keep it live.
289
- *
290
- * This is the client half of PLAN4's "your loaders are live" handoff. The
291
- * returned accessor is seeded **synchronously** from `preloaded.value`, so the
292
- * very first read — during hydration — returns the server-rendered value with
293
- * no loading flash and no `Suspense` fallback (unlike `createResource`, which
294
- * always starts pending). After the component mounts, a WebSocket subscription
295
- * attaches in an effect and every subsequent server delta flows into the same
296
- * signal, so the UI goes live with zero refetch.
297
- *
298
- * ```tsx
299
- * // route loader (server): const preloaded = await preloadQuery(client, api.messages.list, args);
300
- * const messages = hydratePreloaded(preloaded); // seeded from SSR, then live
301
- * return &lt;pre>{JSON.stringify(messages())}&lt;/pre>;
302
- * ```
303
- *
304
- * Effects do not run on the server during SSR (Solid only runs them after
305
- * hydration), so the subscription is strictly client-side the seed is the
306
- * only value the server render ever sees.
307
- */
780
+ * Browser Web Audio subsystems for `createVoiceAgent` the default microphone
781
+ * capture and speaker playback implementations injected into the primitive via
782
+ * its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
783
+ * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
784
+ * primitive's transport + reactive-state logic and remains mockable in a
785
+ * non-browser test env.
786
+ */
787
+ /**
788
+ * The negotiated audio format the voice DO streams back. Mirrors
789
+ * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` re-declared (not
790
+ * imported) so this Solid package never pulls in the server-only `@lunora/agent`
791
+ * module graph.
792
+ */
793
+ type VoiceAudioFormat = "mp3" | "wav";
794
+ /** Captures microphone audio and reports level / turn boundaries back to the primitive. */
795
+ interface VoiceMicrophone {
796
+ /** Mute/unmute the mic without tearing down the capture graph. */
797
+ setMuted: (muted: boolean) => void;
798
+ /** Stop capture and release the media stream + audio graph. */
799
+ stop: () => void;
800
+ }
801
+ /** Plays the server's streamed audio chunks and supports a mid-utterance barge-in. */
802
+ interface VoiceSpeaker {
803
+ /** Queue a decoded audio chunk for gap-minimized playback. */
804
+ enqueue: (audio: Uint8Array) => void;
805
+ /** Drop everything queued and stop the current chunk (barge-in). */
806
+ interrupt: () => void;
807
+ /** Release the playback audio context. */
808
+ stop: () => void;
809
+ }
810
+ /** Config passed to a {@link CreateMicrophone} factory. */
811
+ interface MicrophoneConfig {
812
+ /** The consecutive above-threshold chunk count that counts as a barge-in. */
813
+ interruptChunks: number;
814
+ /** RMS above which the user is considered to be barging in while the agent speaks. */
815
+ interruptThreshold: number;
816
+ /** `true` while `status === "speaking"` — gates barge-in detection. */
817
+ isSpeaking: () => boolean;
818
+ /** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
819
+ onAudio: (pcm: Uint8Array) => void;
820
+ /** A barge-in was detected (RMS spike while the agent is speaking). */
821
+ onInterrupt: () => void;
822
+ /** The current input RMS (0–1), for a level meter. */
823
+ onLevel: (rms: number) => void;
824
+ /** A spoken utterance ended (speech followed by `silenceDurationMs` of silence). */
825
+ onSilence: () => void;
826
+ /** Milliseconds of sub-threshold audio (after speech) that closes an utterance. */
827
+ silenceDurationMs: number;
828
+ /** RMS below which audio counts as silence. */
829
+ silenceThreshold: number;
830
+ }
831
+ type CreateMicrophone = (config: MicrophoneConfig) => Promise<VoiceMicrophone>;
832
+ type CreateSpeaker = (config: {
833
+ audioFormat: VoiceAudioFormat;
834
+ }) => VoiceSpeaker;
835
+ /**
836
+ * The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
837
+ * live, WS-backed session keyed by `threadKey`. A structural subset of the
838
+ * generated member, so passing `api.agents.<name>Voice` type-checks.
839
+ */
840
+ type VoiceReference = FunctionReference<"stream", {
841
+ threadKey: string;
842
+ }, Record<string, unknown>>;
843
+ /** The lifecycle of a voice call, mirrored to the UI. */
844
+ type VoiceStatus = "idle" | "listening" | "speaking" | "thinking";
845
+ /** A minimal structural subset of the DOM `WebSocket` the primitive drives. */
846
+ interface VoiceSocket {
847
+ binaryType: string;
848
+ close: () => void;
849
+ onclose: ((event: unknown) => void) | null;
850
+ onerror: ((event: unknown) => void) | null;
851
+ onmessage: ((event: {
852
+ data: unknown;
853
+ }) => void) | null;
854
+ onopen: ((event: unknown) => void) | null;
855
+ readonly readyState: number;
856
+ send: (data: ArrayBufferView | ArrayBufferLike | string) => void;
857
+ }
858
+ type CreateSocket = (url: string) => VoiceSocket;
859
+ interface CreateVoiceAgentOptions {
860
+ /**
861
+ * Advanced/test seam: build the microphone capture subsystem. Defaults to a
862
+ * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
863
+ * Audio graph stays isolated (and mockable in a non-browser test env).
864
+ */
865
+ createMicrophone?: CreateMicrophone;
866
+ /** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
867
+ createSocket?: CreateSocket;
868
+ /** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
869
+ createSpeaker?: CreateSpeaker;
870
+ /** Consecutive above-`interruptThreshold` chunks that trigger a barge-in. Default `3`. */
871
+ interruptChunks?: number;
872
+ /** Input RMS above which the user is treated as barging in while the agent speaks. Default `0.15`. */
873
+ interruptThreshold?: number;
874
+ /** Milliseconds of silence (after speech) that auto-commits an utterance. Default `1200`. */
875
+ silenceDurationMs?: number;
876
+ /** Input RMS below which audio counts as silence. Default `0.01`. */
877
+ silenceThreshold?: number;
878
+ /** The thread to converse on — shared with the agent's text turns. May be a plain value or accessor (resolved when the call opens). */
879
+ threadKey: MaybeAccessor$1<string>;
880
+ /** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
881
+ voice: VoiceReference;
882
+ }
883
+ interface CreateVoiceAgentResult {
884
+ /** The current input RMS (0–1) — drive a mic level meter. */
885
+ audioLevel: Accessor<number>;
886
+ /** `true` once the WS `ready` handshake completed. */
887
+ connected: Accessor<boolean>;
888
+ /** Tear down the call: close the socket, stop the mic, release audio. Idempotent. */
889
+ endCall: () => void;
890
+ /** The last transport/pipeline error, or `undefined`. */
891
+ error: Accessor<Error | undefined>;
892
+ /** The live assistant text for the in-flight turn (grows via deltas; finalized on done). */
893
+ interimTranscript: Accessor<string>;
894
+ /** `true` while the mic is muted. */
895
+ isMuted: Accessor<boolean>;
896
+ /** Send a typed turn (no audio) — a text message spoken back by the agent. */
897
+ sendText: (text: string) => void;
898
+ /** Open the mic, connect the socket, and start the conversation. Idempotent while active. */
899
+ startCall: () => Promise<void>;
900
+ /** The current call lifecycle. */
901
+ status: Accessor<VoiceStatus>;
902
+ /** Mute/unmute the microphone. Returns the new muted state. */
903
+ toggleMute: () => boolean;
904
+ /** The last finalized user utterance (STT result). */
905
+ transcript: Accessor<string>;
906
+ }
907
+ /**
908
+ * A first-class voice-call surface for a voice-enabled agent: it opens a
909
+ * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
910
+ * streams the agent's synthesized speech back through the browser's audio output,
911
+ * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
912
+ * `audioLevel`) to Solid signals. Pass the generated `api.agents.<name>Voice`
913
+ * reference (never a string), matching `createAgentChat`'s reference-passing style.
914
+ * The Solid counterpart to React's `useVoiceAgent`, re-expressed with signals; the
915
+ * per-call connection lives in a closure variable (a primitive runs once per
916
+ * component, so no signal-of-signal indirection is needed).
917
+ *
918
+ * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
919
+ * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
920
+ * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
921
+ * `createSocket`) so the primitive is drivable outside a browser.
922
+ */
923
+ declare const createVoiceAgent: (options: CreateVoiceAgentOptions) => CreateVoiceAgentResult;
924
+ /**
925
+ * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
926
+ * during SSR, then keep it live.
927
+ *
928
+ * This is the client half of PLAN4's "your loaders are live" handoff. The
929
+ * returned accessor is seeded **synchronously** from `preloaded.value`, so the
930
+ * very first read — during hydration — returns the server-rendered value with
931
+ * no loading flash and no `Suspense` fallback (unlike `createResource`, which
932
+ * always starts pending). After the component mounts, a WebSocket subscription
933
+ * attaches in an effect and every subsequent server delta flows into the same
934
+ * signal, so the UI goes live with zero refetch.
935
+ *
936
+ * ```tsx
937
+ * // route loader (server): const preloaded = await preloadQuery(client, api.messages.list, args);
938
+ * const messages = hydratePreloaded(preloaded); // seeded from SSR, then live
939
+ * return <pre>{JSON.stringify(messages())}</pre>;
940
+ * ```
941
+ *
942
+ * Effects do not run on the server during SSR (Solid only runs them after
943
+ * hydration), so the subscription is strictly client-side — the seed is the
944
+ * only value the server render ever sees.
945
+ */
308
946
  declare const hydratePreloaded: <T>(preloaded: Preloaded<T>) => Accessor<T>;
309
947
  interface LunoraProviderProps {
310
948
  children: JSX.Element;
311
949
  /**
312
- * The framework-neutral transport. Build it once at the app root with
313
- * `new LunoraClient({ url })` (or `createServerClient` during SSR) and pass
314
- * it here — the provider does not own its lifecycle, so the same instance
315
- * survives across route navigations.
316
- */
950
+ * The framework-neutral transport. Build it once at the app root with
951
+ * `new LunoraClient({ url })` (or `createServerClient` during SSR) and pass
952
+ * it here — the provider does not own its lifecycle, so the same instance
953
+ * survives across route navigations.
954
+ */
317
955
  client: LunoraClient;
318
956
  }
319
957
  /**
320
- * Provides a {@link LunoraClient} to the Solid tree via {@link LunoraContext}.
321
- *
322
- * Solid's context is reactive-graph scoped rather than render scoped, so unlike
323
- * the React provider there is no QueryClient to detect or lazily create — the
324
- * adapter's reactive primitives (`createQuery`, `createMutation`,
325
- * `hydratePreloaded`) own their own signals and read the client straight from
326
- * context. Drop one of these at the root of your app:
327
- *
328
- * ```tsx
329
- * const client = new LunoraClient({ url: window.location.origin });
330
- *
331
- * render(() => (
332
- * &lt;LunoraProvider client={client}>
333
- * &lt;App />
334
- * &lt;/LunoraProvider>
335
- * ), root);
336
- * ```
337
- */
958
+ * Provides a {@link LunoraClient} to the Solid tree via {@link LunoraContext}.
959
+ *
960
+ * Solid's context is reactive-graph scoped rather than render scoped, so unlike
961
+ * the React provider there is no QueryClient to detect or lazily create — the
962
+ * adapter's reactive primitives (`createQuery`, `createMutation`,
963
+ * `hydratePreloaded`) own their own signals and read the client straight from
964
+ * context. Drop one of these at the root of your app:
965
+ *
966
+ * ```tsx
967
+ * const client = new LunoraClient({ url: window.location.origin });
968
+ *
969
+ * render(() => (
970
+ * <LunoraProvider client={client}>
971
+ * <App />
972
+ * </LunoraProvider>
973
+ * ), root);
974
+ * ```
975
+ */
338
976
  declare const LunoraProvider: (props: LunoraProviderProps) => JSX.Element;
339
- export { AuthLoading, Authenticated, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateSubscriptionResult, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider, type LunoraProviderProps, type MutationClient, type MutationHandle, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, createAuth, createConnectionStatus, createInfiniteQuery, createMutation, createMutationForClient, createPaginatedQuery, createPresence, createQuery, createRateLimit, createSubscription, hydratePreloaded, useLunora };
977
+ 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 };