@lunora/solid 1.0.0-alpha.11 → 1.0.0-alpha.110

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 (45) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +25 -17
  3. package/dist/index.d.mts +1019 -236
  4. package/dist/index.d.ts +1019 -236
  5. package/dist/index.mjs +1 -13
  6. package/dist/packem_shared/AuthLoading-DKoQs-9J.mjs +1 -0
  7. package/dist/packem_shared/LunoraContext-dPcjtn6R.mjs +1 -0
  8. package/dist/packem_shared/LunoraProvider-BKWckcDR.mjs +1 -0
  9. package/dist/packem_shared/createAction-M4s8XBXV.mjs +1 -0
  10. package/dist/packem_shared/createAgent-4wFKlDvV.mjs +1 -0
  11. package/dist/packem_shared/createAgentChat-BcOUF-3C.mjs +1 -0
  12. package/dist/packem_shared/createAgentState-KojjkWsi.mjs +1 -0
  13. package/dist/packem_shared/createAgentToolEvents-DUAkn3eP.mjs +1 -0
  14. package/dist/packem_shared/createConnectionStatus-BnlXYWeE.mjs +1 -0
  15. package/dist/packem_shared/createFlag-JN9dYhDQ.mjs +1 -0
  16. package/dist/packem_shared/createInfiniteQuery-BuxNVHct.mjs +1 -0
  17. package/dist/packem_shared/createMutation-DcSsIbGF.mjs +1 -0
  18. package/dist/packem_shared/createMutator-q9cMjGKv.mjs +1 -0
  19. package/dist/packem_shared/createPresence-Bu4loG39.mjs +1 -0
  20. package/dist/packem_shared/createQuery-aadhebsp.mjs +1 -0
  21. package/dist/packem_shared/createRateLimit-CIVWrD5H.mjs +1 -0
  22. package/dist/packem_shared/createStream-Dx7SnivS.mjs +1 -0
  23. package/dist/packem_shared/createSubscription-DK6JFpEA.mjs +1 -0
  24. package/dist/packem_shared/createVoiceAgent-C4uRX2Ca.mjs +1 -0
  25. package/dist/packem_shared/hydratePreloaded-Bhxdstm1.mjs +1 -0
  26. package/dist/packem_shared/reactive-args-DwYuo-jL.mjs +1 -0
  27. package/dist/packem_shared/solid-compat-ByG5HD_F.mjs +1 -0
  28. package/dist/server.mjs +1 -1
  29. package/dist/upload.d.mts +2 -0
  30. package/dist/upload.d.ts +2 -0
  31. package/dist/upload.mjs +1 -0
  32. package/package.json +10 -4
  33. package/dist/packem_shared/AuthLoading-RMT5Q_eE.mjs +0 -73
  34. package/dist/packem_shared/LunoraContext-C9SpKj54.mjs +0 -12
  35. package/dist/packem_shared/LunoraProvider-B5BJFk3K.mjs +0 -17
  36. package/dist/packem_shared/createConnectionStatus-D8GPatZX.mjs +0 -14
  37. package/dist/packem_shared/createFlag-BDunYuaH.mjs +0 -106
  38. package/dist/packem_shared/createInfiniteQuery-DyMvQ2Qy.mjs +0 -196
  39. package/dist/packem_shared/createMutation-C7BxzO0y.mjs +0 -36
  40. package/dist/packem_shared/createMutator-foSnPJPt.mjs +0 -24
  41. package/dist/packem_shared/createPresence-DiAak1Jw.mjs +0 -78
  42. package/dist/packem_shared/createQuery-D8mdHfyQ.mjs +0 -28
  43. package/dist/packem_shared/createRateLimit-BA2f8XyF.mjs +0 -76
  44. package/dist/packem_shared/createSubscription-BM2fw8hw.mjs +0 -39
  45. package/dist/packem_shared/hydratePreloaded-CaT1kDBH.mjs +0 -25
package/dist/index.d.mts CHANGED
@@ -1,104 +1,614 @@
1
- import { LunoraClient, User, ConnectionStatus, FunctionReference, 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, JSX, Accessor } from 'solid-js';
1
+ import { LunoraClient, FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, SubscriptionErrorCallback, User, ConnectionStatus, MutationCallOptions, MutatorHandle, SubscriptionError, Preloaded } from '@lunora/client';
2
+ export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, SubscriptionError, SubscriptionErrorCallback, Unsubscribe } from '@lunora/client';
3
+ import { Context, Accessor } from 'solid-js';
4
+ import { AuthStatus } from '@lunora/client/auth';
4
5
  import { PaginationStatus } from '@lunora/client/pagination';
5
6
  import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
6
7
  /**
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
- */
8
+ * Solid context carrying the framework-neutral {@link LunoraClient}. Every
9
+ * reactive primitive in this adapter (`createQuery`, `createMutation`,
10
+ * `hydratePreloaded`) reads the client from here, so a single
11
+ * `<LunoraProvider client={…}>` at the root of the tree wires the whole app.
12
+ *
13
+ * Defaults to `undefined` so {@link useLunora} can throw a helpful error when a
14
+ * primitive is used outside a provider rather than dereferencing it. Solid 2
15
+ * refuses to hand back an `undefined` default at all — see {@link useLunora}.
16
+ */
15
17
  declare const LunoraContext: Context<LunoraClient | undefined>;
16
18
  /**
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
- */
19
+ * Read the {@link LunoraClient} from the nearest `<LunoraProvider>`.
20
+ *
21
+ * Throws when called outside a provider — the client is required to open the
22
+ * HTTP/WS transport, so there is no sensible fallback. The React adapter's
23
+ * `useLunora` has the same contract.
24
+ */
23
25
  declare const useLunora: () => LunoraClient;
26
+ interface ActionHandle<F extends FunctionReference> {
27
+ /** Invoke the action. Resolves with the server result; rejects on failure. */
28
+ call: (args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
29
+ /** The latest invocation's resolved value, or `undefined` before the first success. */
30
+ data: Accessor<ReturnOf<F> | undefined>;
31
+ /** The latest invocation's error, or `undefined`. */
32
+ error: Accessor<Error | undefined>;
33
+ /** `true` while any invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
34
+ pending: Accessor<boolean>;
35
+ /** Clear `data`/`error` back to idle. */
36
+ reset: () => void;
37
+ }
38
+ /**
39
+ * The transport surface {@link createAction} actually needs — just
40
+ * `client.action`. Narrowed so the primitive can be exercised against a stub in
41
+ * tests without constructing a full `LunoraClient`.
42
+ */
43
+ interface ActionClient<F extends FunctionReference> {
44
+ action: (function_: F, args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
45
+ }
46
+ /**
47
+ * Build an action handle bound to an explicit client. Internal seam used by the
48
+ * provider-bound {@link createAction}; exported for tests that inject a stub.
49
+ * The ref-counted pending + error-normalize orchestration is the shared
50
+ * `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
51
+ * signals) are adapter-specific.
52
+ *
53
+ * `data`/`error` follow the adapter-wide contract: both track the LATEST
54
+ * invocation (an earlier call settling later cannot clobber a newer one), a
55
+ * success clears `error`, and a failure leaves the previous `data` in place.
56
+ * `reset()` clears both; it does not cancel an in-flight call.
57
+ */
58
+ declare const createActionForClient: <F extends FunctionReference>(client: ActionClient<F>, function_: F) => ActionHandle<F>;
59
+ /**
60
+ * Returns a reactive handle `{ call, pending, data, error, reset }` for the
61
+ * given action reference, bound to the `LunoraClient` from the nearest
62
+ * `<LunoraProvider>`.
63
+ *
64
+ * **Narrower than `createMutation` on purpose:** no `optimistic` /
65
+ * `optimisticUpdate` call options. An optimistic update patches the subscription
66
+ * cache on the assumption a write will land; an action is not a write — it runs
67
+ * in the Worker, may call a third party, and has no declared effect on any
68
+ * query. Offering the option would imply a rollback guarantee nothing can
69
+ * honour.
70
+ */
71
+ declare const createAction: <F extends FunctionReference>(function_: F) => ActionHandle<F>;
72
+ /**
73
+ * The lifecycle status stored on an agent thread. Client-safe mirror of
74
+ * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
75
+ * so this Solid entry never pulls in the server-only `@lunora/agent` module graph
76
+ * (the adapter stays Solid + `@lunora/client` only). Keep in sync with
77
+ * `packages/agent/src/types.ts`.
78
+ */
79
+ type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "running";
80
+ /**
81
+ * The live thread record surfaced by the `agents:agentThread` query. A structural
82
+ * subset of the persisted thread row — every field beyond `status` is optional so
83
+ * the shape stays forgiving as the server schema grows. Keep in sync with the
84
+ * `agent_threads` table in `packages/agent/src/component.ts`.
85
+ */
86
+ interface AgentThreadRecord {
87
+ createdAt?: number;
88
+ /** The failure message when `status === "error"`. */
89
+ error?: string;
90
+ /** The workflow instance id of the in-flight run — the handle `cancel` targets. */
91
+ instanceId?: string;
92
+ messageCount?: number;
93
+ /** The verified thread owner, when the run was started with one. */
94
+ owner?: string;
95
+ status: AgentThreadStatus;
96
+ title?: string;
97
+ updatedAt?: number;
98
+ }
99
+ /** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
100
+ type MaybeAccessor<T> = Accessor<T> | T;
101
+ /**
102
+ * The `agents.agentThread` reference the primitive subscribes to for live thread
103
+ * state (status + the in-flight `instanceId`). A structural subset of the
104
+ * generated `api.agents` surface, so the whole generated `api` object is
105
+ * assignable.
106
+ */
107
+ interface CreateAgentApi {
108
+ agents: {
109
+ agentThread: FunctionReference<"query", {
110
+ key: string;
111
+ }, Record<string, unknown> | undefined>;
112
+ };
113
+ }
114
+ interface CreateAgentOptions {
115
+ /** The generated `api` — its `agents.agentThread` query drives live thread state. */
116
+ api: CreateAgentApi;
117
+ /**
118
+ * Optional app mutation over the agent's cancel path
119
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
120
+ * When omitted (or no run is in flight) {@link CreateAgentResult.cancel} is a
121
+ * no-op.
122
+ */
123
+ cancel?: FunctionReference<"mutation">;
124
+ /**
125
+ * Called when the live thread subscription reports an error (a session
126
+ * expiry, an RLS denial). Without it — and without reading `error` — such a
127
+ * failure is invisible and `thread` / `status` are cleared until a later frame arrives.
128
+ */
129
+ onError?: SubscriptionErrorCallback;
130
+ /**
131
+ * The app mutation that starts (or continues) a run — a thin wrapper over
132
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
133
+ * {@link CreateAgentOptions.runArgs} and the per-call args.
134
+ */
135
+ run: FunctionReference<"mutation">;
136
+ /** Extra args merged into every `run` call (e.g. an `owner` or `title`). */
137
+ runArgs?: Record<string, unknown>;
138
+ /** The thread to observe and drive — a plain value or accessor (an accessor re-subscribes on change). */
139
+ threadKey: MaybeAccessor<string>;
140
+ }
141
+ interface CreateAgentResult {
142
+ /**
143
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
144
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
145
+ */
146
+ cancel: () => Promise<void>;
147
+ /** The live thread subscription's last error, or `undefined`. */
148
+ error: Accessor<Error | undefined>;
149
+ /** `true` while a `run` invocation is in flight. */
150
+ pending: Accessor<boolean>;
151
+ /** Start (or continue) a run with a user message; extra args merge over `runArgs`. */
152
+ run: (input: string, args?: Record<string, unknown>) => Promise<void>;
153
+ /** The live thread status, or `undefined` before the thread exists. */
154
+ status: Accessor<AgentThreadStatus | undefined>;
155
+ /** The live thread record (status, `instanceId`, …), or `undefined` before it exists. */
156
+ thread: Accessor<AgentThreadRecord | undefined>;
157
+ }
158
+ /**
159
+ * A thin agent handle: live thread `status` plus `run` / `cancel`, without the
160
+ * chat message surface. Composes `createSubscription(api.agents.agentThread)` for
161
+ * live state and `createMutation` for the run/cancel writes — the Solid
162
+ * counterpart to React's `useAgent`, re-expressed with signals. For the full
163
+ * conversation surface (durable history + streaming + approvals) use
164
+ * `createAgentChat`.
165
+ *
166
+ * `run` and `cancel` stay generic over the app-defined mutations that wrap
167
+ * `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
168
+ * names beyond the `agents:*` surface. `threadKey` may be an accessor — a changing
169
+ * key re-subscribes to the new thread.
170
+ */
171
+ declare const createAgent: (options: CreateAgentOptions) => CreateAgentResult;
172
+ /**
173
+ * One persisted (or optimistic) thread message, as `agents:agentMessages`
174
+ * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
175
+ * re-declared here (rather than imported) so this Solid entry never pulls in the
176
+ * server-only `@lunora/agent` module graph. Keep in sync with the
177
+ * `agent_messages` table in `packages/agent/src/component.ts`.
178
+ */
179
+ interface AgentChatMessage {
180
+ content: string;
181
+ createdAt?: number;
182
+ /**
183
+ * `true` for a client-side optimistic user message not yet acknowledged by
184
+ * the server. Cleared once the durable history carries the matching user turn.
185
+ */
186
+ optimistic?: boolean;
187
+ role: "assistant" | "system" | "tool" | "user";
188
+ seq: number;
189
+ /** Approval lifecycle marker on a human-in-the-loop tool message. */
190
+ status?: "approved" | "awaiting_approval" | "rejected";
191
+ toolCallId?: string;
192
+ toolCalls?: ReadonlyArray<{
193
+ id: string;
194
+ input: unknown;
195
+ name: string;
196
+ }>;
197
+ toolName?: string;
198
+ }
199
+ /**
200
+ * A live token delta streamed while a turn is generating. Client-safe mirror of
201
+ * `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
202
+ * {@link CreateAgentChatResult.streamingText} live and are never replayed; the
203
+ * persisted assistant message stays the single source of truth.
204
+ */
205
+ interface AgentTokenDelta {
206
+ /** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
207
+ kind?: "token";
208
+ /** The incremental text chunk the model just produced. */
209
+ text: string;
210
+ /** The thread this delta belongs to. */
211
+ threadKey: string;
212
+ /** The zero-based index of the turn producing the delta. */
213
+ turn: number;
214
+ }
215
+ /**
216
+ * A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
217
+ * mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
218
+ * surfaced by `createAgentToolEvents`, ignored by {@link CreateAgentChatResult.streamingText}.
219
+ */
220
+ interface AgentProgressEvent {
221
+ /** The arbitrary, JSON-serializable payload the tool reported. */
222
+ data: unknown;
223
+ /** Discriminates the progress arm of {@link AgentLiveEvent}. */
224
+ kind: "progress";
225
+ /** The thread this event belongs to. */
226
+ threadKey: string;
227
+ /** The tool call this progress belongs to. */
228
+ toolCallId: string;
229
+ }
230
+ /**
231
+ * A single event on the agent's live-only channel — a streamed token delta or a
232
+ * tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
233
+ * Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
234
+ * it unset).
235
+ */
236
+ type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
237
+ /** The `agents:agentMessages` reference — live durable thread history. */
238
+ type AgentMessagesReference$1 = FunctionReference<"query", {
239
+ key: string;
240
+ limit?: number;
241
+ }, ReadonlyArray<Record<string, unknown>>>;
242
+ /** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
243
+ type AgentApprovalReference = FunctionReference<"mutation", {
244
+ decision: "approve" | "reject";
245
+ instanceId: string;
246
+ note?: string;
247
+ threadKey: string;
248
+ toolCallId: string;
249
+ }, {
250
+ resolved: boolean;
251
+ }>;
252
+ /** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
253
+ type AgentThreadReference = FunctionReference<"query", {
254
+ key: string;
255
+ }, Record<string, unknown> | undefined>;
256
+ /**
257
+ * An app stream reference that tees the agent's in-flight live events, keyed by
258
+ * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
259
+ * sink — tool progress events; this primitive consumes only the token arm.
260
+ */
261
+ type AgentTokenStreamReference = FunctionReference<"stream", {
262
+ key: string;
263
+ }, AgentLiveEvent>;
264
+ /**
265
+ * The `agents.*` reference surface the chat primitive reads. A structural subset
266
+ * of the generated `api.agents`, so the whole generated `api` object is
267
+ * assignable.
268
+ */
269
+ interface CreateAgentChatApi {
270
+ agents: {
271
+ agentMessages: AgentMessagesReference$1;
272
+ agentResolveApproval: AgentApprovalReference;
273
+ agentThread: AgentThreadReference;
274
+ };
275
+ }
276
+ interface CreateAgentChatOptions {
277
+ /** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
278
+ api: CreateAgentChatApi;
279
+ /**
280
+ * Optional app mutation over the agent's cancel path
281
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
282
+ * When omitted (or no run is in flight) {@link CreateAgentChatResult.cancel} is
283
+ * a no-op.
284
+ */
285
+ cancel?: FunctionReference<"mutation">;
286
+ /** History depth forwarded to `agents:agentMessages`. */
287
+ limit?: number;
288
+ /**
289
+ * Called when the live history or thread subscription reports an error (a
290
+ * session expiry, an RLS denial). Without it — and without reading `error` —
291
+ * such a failure is invisible and `messages` / `status` are cleared until a later frame arrives.
292
+ */
293
+ onError?: SubscriptionErrorCallback;
294
+ /**
295
+ * The app mutation that starts (or continues) a run — a thin wrapper over
296
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
297
+ * {@link CreateAgentChatOptions.sendArgs} and the per-call args.
298
+ */
299
+ send: FunctionReference<"mutation">;
300
+ /** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
301
+ sendArgs?: Record<string, unknown>;
302
+ /**
303
+ * Optional live token-delta stream — an app stream function that tees the
304
+ * agent's in-flight deltas. When omitted {@link CreateAgentChatResult.streamingText}
305
+ * stays empty and the UI updates message-by-message from durable history.
306
+ */
307
+ stream?: AgentTokenStreamReference;
308
+ /** The thread to observe and continue — a plain value or accessor (an accessor re-subscribes on change). */
309
+ threadKey: MaybeAccessor<string>;
310
+ }
311
+ interface CreateAgentChatResult {
312
+ /** Approve a paused human-in-the-loop tool call (optionally with a note). */
313
+ approve: (toolCallId: string, note?: string) => Promise<void>;
314
+ /**
315
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
316
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
317
+ */
318
+ cancel: () => Promise<void>;
319
+ /** The history or thread subscription's last error, or `undefined`. */
320
+ error: Accessor<Error | undefined>;
321
+ /** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
322
+ messages: Accessor<ReadonlyArray<AgentChatMessage>>;
323
+ /** Reject a paused human-in-the-loop tool call (optionally with a reason). */
324
+ reject: (toolCallId: string, note?: string) => Promise<void>;
325
+ /** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
326
+ send: (input: string, args?: Record<string, unknown>) => Promise<void>;
327
+ /** The live thread status, or `undefined` before the thread exists. */
328
+ status: Accessor<AgentThreadStatus | undefined>;
329
+ /** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
330
+ streamingText: Accessor<string>;
331
+ }
332
+ /**
333
+ * A first-class agent chat surface: live durable history + in-flight token
334
+ * streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
335
+ * the Solid counterpart to React's `useAgentChat`, re-expressed with signals.
336
+ *
337
+ * It composes the existing primitives rather than adding transport:
338
+ * `createSubscription(api.agents.agentMessages)` for durable history,
339
+ * `createSubscription(api.agents.agentThread)` for live status + the in-flight
340
+ * `instanceId`, {@link createStream} over an app token stream for in-flight deltas,
341
+ * and `createMutation` for the writes (`api.agents.agentResolveApproval` for
342
+ * approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*`
343
+ * surface is hard-coded — `send`/`cancel`/`stream` stay generic references.
344
+ *
345
+ * A `send` optimistically appends the user turn so it renders immediately; the
346
+ * optimistic row clears once the durable history carries the acknowledged turn.
347
+ * `streamingText` is live-only: it holds the current turn's streamed text and
348
+ * empties as soon as that turn's assistant message lands in `messages` (the
349
+ * persisted message is the source of truth), consistent with the loop's
350
+ * replay-safe, live-only delta design.
351
+ */
352
+ declare const createAgentChat: (options: CreateAgentChatOptions) => CreateAgentChatResult;
353
+ /**
354
+ * The `agents.agentState` reference the primitive subscribes to for the thread's
355
+ * live synced state. A structural subset of the generated `api.agents` surface
356
+ * (like `CreateAgentApi` for `agentThread`), so the whole generated `api` object
357
+ * is assignable. Client-safe: no `@lunora/agent` import — the per-agent state type
358
+ * is mirrored by the primitive's generic `T`, since codegen pins the reference
359
+ * return as an optional record (it never evaluates agent config).
360
+ */
361
+ interface CreateAgentStateApi {
362
+ agents: {
363
+ agentState: FunctionReference<"query", {
364
+ key: string;
365
+ }, Record<string, unknown> | undefined>;
366
+ };
367
+ }
368
+ interface CreateAgentStateOptions {
369
+ /** The generated `api` — its `agents.agentState` query drives live thread state. */
370
+ api: CreateAgentStateApi;
371
+ /** The thread whose synced state to observe — a plain value or accessor (an accessor re-subscribes on change). */
372
+ threadKey: MaybeAccessor<string>;
373
+ }
374
+ interface CreateAgentStateResult<T> {
375
+ /** The subscription error, if the live channel reported one. */
376
+ error: Accessor<Error | undefined>;
377
+ /** The live synced state, or `undefined` before it is seeded/first pushed. */
378
+ state: Accessor<T | undefined>;
379
+ }
380
+ /**
381
+ * Subscribe to an agent thread's synced state — the `setState`-style value a tool
382
+ * writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
383
+ * thin wrapper over `createSubscription(api.agents.agentState, { key })`: the
384
+ * server pushes a fresh frame whenever the state changes (the dedicated query's
385
+ * per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
386
+ * `state` updates only on a real `setState`. The Solid counterpart to React's
387
+ * `useAgentState`, re-expressed with signals.
388
+ *
389
+ * Generic over the app's state shape (`createAgentState` with a `SupportState`
390
+ * type argument, itself a record) — the reference is typed as an optional record
391
+ * because codegen cannot see the per-agent state type; the generic casts to `T`.
392
+ * The `extends` bound (not a bare unbounded type parameter) is required so the
393
+ * reference's optional-record return casts cleanly to `T`.
394
+ */
395
+ declare const createAgentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: CreateAgentStateOptions) => CreateAgentStateResult<T>;
396
+ /** The `agents:agentMessages` reference — live durable thread history. */
397
+ type AgentMessagesReference = FunctionReference<"query", {
398
+ key: string;
399
+ limit?: number;
400
+ }, ReadonlyArray<Record<string, unknown>>>;
401
+ /**
402
+ * An app stream reference that tees the agent's in-flight live events, keyed by
403
+ * thread. Carries token deltas and tool progress events; this primitive consumes
404
+ * only the progress arm (`kind === "progress"`).
405
+ */
406
+ type AgentLiveStreamReference = FunctionReference<"stream", {
407
+ key: string;
408
+ }, AgentLiveEvent>;
409
+ /**
410
+ * The `agents.*` reference surface the tool-events primitive reads. A structural
411
+ * subset of the generated `api.agents`, so the whole generated `api` object is
412
+ * assignable.
413
+ */
414
+ interface CreateAgentToolEventsApi {
415
+ agents: {
416
+ agentMessages: AgentMessagesReference;
417
+ };
418
+ }
419
+ interface CreateAgentToolEventsOptions {
420
+ /** The generated `api` — its `agents.agentMessages` query provides the durable tool lifecycle. */
421
+ api: CreateAgentToolEventsApi;
422
+ /** History depth forwarded to `agents:agentMessages`. */
423
+ limit?: number;
424
+ /**
425
+ * Optional live event stream — the same app stream function `createAgentChat`
426
+ * uses. When supplied, ephemeral `ctx.reportProgress(...)` events for the
427
+ * thread are surfaced as `{ type: "progress" }` entries; when omitted only the
428
+ * durable lifecycle (call / result / awaiting-approval) is returned.
429
+ */
430
+ stream?: AgentLiveStreamReference;
431
+ /** The thread whose tool activity to observe — a plain value or accessor (an accessor re-subscribes on change). */
432
+ threadKey: MaybeAccessor<string>;
433
+ }
434
+ /**
435
+ * A single tool-lifecycle event for a thread. The durable arms
436
+ * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
437
+ * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
438
+ * stream and has no `seq`. Discriminate on `type`.
439
+ */
440
+ type AgentToolEvent = {
441
+ data: unknown;
442
+ toolCallId: string;
443
+ type: "progress";
444
+ } | {
445
+ input: unknown;
446
+ seq: number;
447
+ toolCallId: string;
448
+ toolName: string;
449
+ type: "call";
450
+ } | {
451
+ output: string;
452
+ seq: number;
453
+ status?: "approved" | "rejected";
454
+ toolCallId?: string;
455
+ toolName?: string;
456
+ type: "result";
457
+ } | {
458
+ seq: number;
459
+ toolCallId?: string;
460
+ toolName?: string;
461
+ type: "awaiting-approval";
462
+ };
463
+ interface CreateAgentToolEventsResult {
464
+ /**
465
+ * The thread's tool events: the durable lifecycle (oldest first, by `seq`)
466
+ * followed by any in-flight ephemeral progress events, recomputed from the live
467
+ * subscription + stream. Treat as derived, not identity-stable.
468
+ */
469
+ events: Accessor<ReadonlyArray<AgentToolEvent>>;
470
+ }
471
+ /**
472
+ * A focused view of a thread's tool activity: tool calls, their results,
473
+ * human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
474
+ * without the full chat message surface. The Solid counterpart to React's
475
+ * `useAgentToolEvents`, re-expressed as a memo.
476
+ *
477
+ * It composes the existing primitives rather than adding transport:
478
+ * `createSubscription(api.agents.agentMessages)` for the durable lifecycle and
479
+ * {@link createStream} over the optional app event stream for ephemeral progress.
480
+ * Progress events are live-only (the durable path never emits them): they ride
481
+ * the same sink as token deltas and are surfaced here, correlated to their tool
482
+ * call by `toolCallId`. For the conversational surface (messages + streaming text
483
+ * + approvals) use `createAgentChat`; this primitive is the tool-observability slice.
484
+ */
485
+ declare const createAgentToolEvents: (options: CreateAgentToolEventsOptions) => CreateAgentToolEventsResult;
486
+ /**
487
+ * Children accepted by this adapter's components.
488
+ *
489
+ * Structurally identical to Solid 2.0's `Element`, which is in turn a widening
490
+ * of 1.x's `JSX.Element` (a DOM `Node` satisfies `object` with no
491
+ * `call`/`apply`/`bind`). Children are contravariant, so one union that accepts
492
+ * both majors' element types is enough — no `any` required here.
493
+ */
494
+ type SolidChildren = SolidChildrenArray | boolean | null | number | (object & {
495
+ readonly apply?: never;
496
+ readonly bind?: never;
497
+ readonly call?: never;
498
+ }) | (string & {}) | undefined;
499
+ interface SolidChildrenArray extends Array<SolidChildren> {}
500
+ /**
501
+ * The return type of this adapter's components.
502
+ *
503
+ * Deliberately `any`, and the one place in the package where that is the right
504
+ * answer. TypeScript checks a component's return type against the *renderer's*
505
+ * `JSX.Element`, and the two majors define that incompatibly — 1.x's is rooted
506
+ * in the DOM `Node` interface, 2.0's in an opaque `RenderedElement`. Neither is
507
+ * assignable to the other, so no concrete type satisfies both, and a structural
508
+ * union (as used for {@link SolidChildren}) fails in the return position. `any`
509
+ * is what lets one set of `.d.ts` files type-check inside a 1.x app and a 2.x
510
+ * app alike.
511
+ */
512
+ type SolidElement = any;
24
513
  interface UseAuthResult {
25
514
  setToken: (token: string | null) => void;
515
+ /**
516
+ * The resolved auth state. Branch on this, not on `user() === null` — see the
517
+ * contract in `@lunora/client/auth`; `user` is `null` both when signed out
518
+ * and when a held credential's identity could not be resolved.
519
+ */
520
+ status: Accessor<AuthStatus>;
26
521
  token: Accessor<string | null>;
27
522
  user: Accessor<User | null>;
28
523
  }
29
524
  /**
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
- */
525
+ * Token + identity plumbing for Solid. Returns `{ token, user, setToken }`
526
+ * where `token` and `user` are fine-grained signals. `setToken(jwt)` after
527
+ * sign-in updates the shared client token; `user` resolves asynchronously via
528
+ * `client.getCurrentUser()` and updates on every token change.
529
+ */
35
530
  declare const createAuth: () => UseAuthResult;
36
531
  interface AuthGateProps {
37
- children: JSX.Element;
38
- }
39
- /**
40
- * Render `children` only after authentication has settled and a token + user
41
- * are both present.
42
- */
43
- declare const Authenticated: (props: AuthGateProps) => JSX.Element;
44
- /**
45
- * Render `children` while authentication is still in progress — token is set
46
- * but the user has not yet resolved.
47
- */
48
- declare const AuthLoading: (props: AuthGateProps) => JSX.Element;
49
- /**
50
- * Render `children` only when auth has settled and no token is present (the
51
- * signed-out state).
52
- */
53
- declare const Unauthenticated: (props: AuthGateProps) => JSX.Element;
54
- /**
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
- */
532
+ children: SolidChildren;
533
+ }
534
+ /** An auth-gate component: renders its children only while the gate's condition holds. */
535
+ type AuthGate = (props: AuthGateProps) => SolidElement;
536
+ /**
537
+ * Render `children` once authentication has settled in the caller's favour — a
538
+ * credential is held and nothing has contradicted it.
539
+ *
540
+ * Gated on the shared `AuthStatus` contract in `@lunora/client/auth`, not on
541
+ * `user() !== null`: an unreachable identity endpoint leaves `user` at `null`
542
+ * while the credential is still perfectly valid.
543
+ */
544
+ declare const Authenticated: AuthGate;
545
+ /**
546
+ * Render `children` while authentication is still in progress — a credential is
547
+ * held and the first identity resolve has not come back yet.
548
+ */
549
+ declare const AuthLoading: AuthGate;
550
+ /**
551
+ * Render `children` only when auth has settled and there is no session — no
552
+ * credential, or the server answered that the credential has none.
553
+ */
554
+ declare const Unauthenticated: AuthGate;
555
+ /**
556
+ * Reactive accessor of the client's aggregate live-socket status across all
557
+ * shard connections. Reads the current status synchronously and updates on
558
+ * every transition (`idle` → `connecting` → `connected` → `offline`) — Solid's
559
+ * fine-grained signals mean only the components that read the accessor
560
+ * re-render. The Solid equivalent of `@lunora/react`'s `useConnectionStatus`.
561
+ *
562
+ * The listener is registered at **mount**, not in the component body, because
563
+ * `onConnectionStatus` invokes it synchronously on subscribe: Solid 2 rejects a
564
+ * signal write inside an owned scope (`REACTIVE_WRITE_IN_OWNED_SCOPE`) and — since
565
+ * the throw escapes render — halts the reactive system for the whole page, not
566
+ * just this component. Nothing is missed by waiting: the initial value comes
567
+ * from `client.connectionStatus()`, and the immediate callback re-syncs at
568
+ * mount. Torn down when the owning scope disposes. Call inside a component /
569
+ * reactive root.
570
+ */
64
571
  declare const createConnectionStatus: () => Accessor<ConnectionStatus>;
65
- /** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
66
- type FlagContext = Record<string, unknown>;
67
572
  /** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
68
573
  type FlagValue = boolean | number | string | {
69
574
  [key: string]: unknown;
70
575
  } | unknown[] | null;
71
- /** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
72
- type MaybeAccessor<T> = Accessor<T> | T;
73
576
  /**
74
- * Subscribe to a single feature flag and return a reactive accessor of its value.
75
- *
76
- * The accessor reads `defaultValue` until the first evaluation lands, then the
77
- * server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
78
- * flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
79
- * `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
80
- * and `createFlag("hero", "control")` a string.
81
- *
82
- * `key` and `context` may be plain values or accessors; passing an accessor makes
83
- * the subscription reactive — when it changes the old subscription is torn down
84
- * (via `onCleanup`) and a fresh one opens. `context` supplies a per-call targeting
85
- * context merged on top of the app's default `identify` targeting key.
86
- *
87
- * Evaluation runs through whatever OpenFeature provider the app wired in
88
- * `lunora/flags.ts`; the read never throws — a provider error resolves the
89
- * default (the same fail-open contract as server-side `ctx.flags`).
90
- */
91
- declare const createFlag: <T extends FlagValue>(key: MaybeAccessor<string>, defaultValue: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
92
- /**
93
- * Subscribe to several feature flags at once and return a reactive accessor of
94
- * the resolved record.
95
- *
96
- * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
97
- * default, and the accessor reads the same-shaped record with resolved values
98
- * (the defaults until each evaluation lands). A single `context` applies to every
99
- * flag and may be an accessor. This is the batched form of {@link createFlag}.
100
- */
101
- declare const createFlags: <T extends Record<string, FlagValue>>(flags: T, context?: MaybeAccessor<FlagContext | undefined>) => Accessor<T>;
577
+ * Subscribe to a single feature flag and return a reactive accessor of its value.
578
+ *
579
+ * The accessor reads `defaultValue` until the first evaluation lands, then the
580
+ * server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
581
+ * flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
582
+ * `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
583
+ * and `createFlag("hero", "control")` a string.
584
+ *
585
+ * `key` may be a plain value or an accessor; passing an accessor makes the
586
+ * subscription reactive — when it changes the old subscription is torn down (via
587
+ * `onCleanup`) and a fresh one opens.
588
+ *
589
+ * The reactive channel is public, so the server evaluates every flag under the
590
+ * socket's own verified identity — the targeting key your `defineFlags({
591
+ * identify })` derives — and accepts no client-supplied targeting context. For
592
+ * evaluation under a context you compute, call `ctx.flags.*` inside a query,
593
+ * mutation, or action and return the resolved value.
594
+ *
595
+ * Evaluation runs through whatever OpenFeature provider the app wired in
596
+ * `lunora/flags.ts`; the read never throws — a provider error resolves the
597
+ * default (the same fail-open contract as server-side `ctx.flags`).
598
+ */
599
+ declare const createFlag: <T extends FlagValue>(key: MaybeAccessor<string>, defaultValue: T) => Accessor<T>;
600
+ /**
601
+ * Subscribe to several feature flags at once and return a reactive accessor of
602
+ * the resolved record.
603
+ *
604
+ * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
605
+ * default, and the accessor reads the same-shaped record with resolved values
606
+ * (the defaults until each evaluation lands). This is the batched form of
607
+ * {@link createFlag}, and evaluates under the socket's server-verified identity
608
+ * only. The flag set is fixed for the primitive's lifetime, so nothing here is
609
+ * reactive — the subscriptions open on mount and tear down on cleanup.
610
+ */
611
+ declare const createFlags: <T extends Record<string, FlagValue>>(flags: T) => Accessor<T>;
102
612
  interface MutationHandle<F extends FunctionReference> {
103
613
  /** The latest invocation's resolved value, or `undefined` before the first success. */
104
614
  data: Accessor<ReturnOf<F> | undefined>;
@@ -112,44 +622,49 @@ interface MutationHandle<F extends FunctionReference> {
112
622
  reset: () => void;
113
623
  }
114
624
  /**
115
- * The transport surface {@link createMutation} actually needs — just
116
- * `client.mutation`. Narrowed so the primitive can be exercised against a stub
117
- * in tests without constructing a full `LunoraClient`.
118
- */
625
+ * The transport surface {@link createMutation} actually needs — just
626
+ * `client.mutation`. Narrowed so the primitive can be exercised against a stub
627
+ * in tests without constructing a full `LunoraClient`.
628
+ */
119
629
  interface MutationClient<F extends FunctionReference> {
120
630
  mutation: (function_: F, args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>>) => Promise<ReturnOf<F>>;
121
631
  }
122
632
  /**
123
- * Build a mutation handle bound to an explicit client. Internal seam used by the
124
- * provider-bound {@link createMutation}; exported for tests that inject a stub.
125
- * The ref-counted pending + error-normalize orchestration is the shared
126
- * `createMutationRunner` from `@lunora/client`; only the reactive sinks (Solid
127
- * signals) are adapter-specific.
128
- */
633
+ * Build a mutation handle bound to an explicit client. Internal seam used by the
634
+ * provider-bound {@link createMutation}; exported for tests that inject a stub.
635
+ * The ref-counted pending + error-normalize orchestration is the shared
636
+ * `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
637
+ * signals) are adapter-specific.
638
+ *
639
+ * `data`/`error` follow the adapter-wide contract: both track the LATEST
640
+ * invocation (an earlier call settling later cannot clobber a newer one), a
641
+ * success clears `error`, and a failure leaves the previous `data` in place.
642
+ * `reset()` clears both; it does not cancel an in-flight call.
643
+ */
129
644
  declare const createMutationForClient: <F extends FunctionReference>(client: MutationClient<F>, function_: F) => MutationHandle<F>;
130
645
  /**
131
- * Returns a reactive handle `{ mutate, pending, data, error, reset }` for the
132
- * given mutation reference, bound to the `LunoraClient` from the nearest
133
- * `&lt;LunoraProvider>`.
134
- *
135
- * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
136
- * call options pass straight through to `client.mutation`, which applies and
137
- * rolls them back against the live Lunora subscription cache — the same
138
- * machinery `createQuery`/`hydratePreloaded` subscribe to, so an optimistic
139
- * write reflects in those accessors immediately and reverts on failure.
140
- *
141
- * `pending` is ref-counted across overlapping invocations of *this* handle, so
142
- * it only flips back to `false` once every concurrent call has settled. The
143
- * mutation also engages `@lunora/client`'s offline queue when the socket is
144
- * down, so `mutate` stays durable across reconnects.
145
- */
646
+ * Returns a reactive handle `{ mutate, pending, data, error, reset }` for the
647
+ * given mutation reference, bound to the `LunoraClient` from the nearest
648
+ * `<LunoraProvider>`.
649
+ *
650
+ * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
651
+ * call options pass straight through to `client.mutation`, which applies and
652
+ * rolls them back against the live Lunora subscription cache — the same
653
+ * machinery `createQuery`/`hydratePreloaded` subscribe to, so an optimistic
654
+ * write reflects in those accessors immediately and reverts on failure.
655
+ *
656
+ * `pending` is ref-counted across overlapping invocations of *this* handle, so
657
+ * it only flips back to `false` once every concurrent call has settled. The
658
+ * mutation also engages `@lunora/client`'s offline queue when the socket is
659
+ * down, so `mutate` stays durable across reconnects.
660
+ */
146
661
  declare const createMutation: <F extends FunctionReference>(function_: F) => MutationHandle<F>;
147
662
  /**
148
- * The reactive handle returned by {@link createMutator} — the Solid counterpart
149
- * to `@lunora/react`'s `useMutator`, re-expressed with signals.
150
- * `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
151
- * resolves once the write is persisted (or rejects).
152
- */
663
+ * The reactive handle returned by {@link createMutator} — the Solid counterpart
664
+ * to `@lunora/react`'s `useMutator`, re-expressed with signals.
665
+ * `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
666
+ * resolves once the write is persisted (or rejects).
667
+ */
153
668
  interface MutatorHook<TArgs> {
154
669
  /** The latest invocation's error, or `undefined`. */
155
670
  error: Accessor<Error | undefined>;
@@ -163,18 +678,18 @@ interface MutatorHook<TArgs> {
163
678
  reset: () => void;
164
679
  }
165
680
  /**
166
- * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
167
- * custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
168
- * equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
169
- * server-authoritative push are owned by the bound handle (and TanStack DB's
170
- * optimistic-transaction layer rebases pending overlays on every sync tick);
171
- * this primitive only surfaces signal state for the in-flight/error lifecycle.
172
- * Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
173
- * needed.
174
- *
175
- * `pending` is ref-counted across overlapping invocations of THIS handle, so it
176
- * clears only once every concurrent call has settled.
177
- */
681
+ * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
682
+ * custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
683
+ * equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
684
+ * server-authoritative push are owned by the bound handle (and TanStack DB's
685
+ * optimistic-transaction layer rebases pending overlays on every sync tick);
686
+ * this primitive only surfaces signal state for the in-flight/error lifecycle.
687
+ * Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
688
+ * needed.
689
+ *
690
+ * `pending` is ref-counted across overlapping invocations of THIS handle, so it
691
+ * clears only once every concurrent call has settled.
692
+ */
178
693
  declare const createMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
179
694
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
180
695
  type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
@@ -185,9 +700,18 @@ type PageItemOf<F extends FunctionReference> = ReturnOf<F> extends {
185
700
  interface CreatePaginatedQueryOptions {
186
701
  /** Page size for the first page (and the default for `loadMore`). */
187
702
  initialNumItems: number;
703
+ /** Called when a page subscription reports an error (also surfaced on the `error` accessor). */
704
+ onError?: SubscriptionErrorCallback;
188
705
  shardKey?: string;
189
706
  }
190
707
  interface CreatePaginatedQueryResult<T> {
708
+ /**
709
+ * The last page subscription error, or `undefined`. A tail page that fails
710
+ * before its first frame is dropped so `status` returns to `"CanLoadMore"`
711
+ * and `loadMore` can retry it; cleared by the next successful frame,
712
+ * `loadMore`, or an args change.
713
+ */
714
+ error: Accessor<SubscriptionError | undefined>;
191
715
  /** `true` while the first page or a `loadMore` page is in flight. */
192
716
  isLoading: Accessor<boolean>;
193
717
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
@@ -199,9 +723,13 @@ interface CreatePaginatedQueryResult<T> {
199
723
  interface CreateInfiniteQueryOptions {
200
724
  /** Page size for the first page (and the default for `fetchNextPage`). */
201
725
  initialNumItems: number;
726
+ /** Called when a page subscription reports an error (also surfaced on the `error` accessor). */
727
+ onError?: SubscriptionErrorCallback;
202
728
  shardKey?: string;
203
729
  }
204
730
  interface CreateInfiniteQueryResult<T> {
731
+ /** The last page subscription error, or `undefined` — see `CreatePaginatedQueryResult.error`. */
732
+ error: Accessor<SubscriptionError | undefined>;
205
733
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
206
734
  fetchNextPage: (numberItems?: number) => void;
207
735
  /** `true` when the loaded tail reports it can load another page. */
@@ -215,46 +743,46 @@ interface CreateInfiniteQueryResult<T> {
215
743
  status: Accessor<PaginationStatus>;
216
744
  }
217
745
  /**
218
- * Subscribe to a reactively-paginated query and grow the feed page by page.
219
- *
220
- * The query function must accept a `paginationOpts: { numItems, cursor,
221
- * endCursor }` arg and return a `PaginationResult`. `loadMore` appends the next
222
- * page off the open-ended tail's `continueCursor`; it is a no-op unless
223
- * `status === "CanLoadMore"`.
224
- *
225
- * Call inside a reactive context (component / `createRoot`).
226
- */
746
+ * Subscribe to a reactively-paginated query and grow the feed page by page.
747
+ *
748
+ * The query function must accept a `paginationOpts: { numItems, cursor,
749
+ * endCursor }` arg and return a `PaginationResult`. `loadMore` appends the next
750
+ * page off the open-ended tail's `continueCursor`; it is a no-op unless
751
+ * `status === "CanLoadMore"`.
752
+ *
753
+ * Call inside a reactive context (component / `createRoot`).
754
+ */
227
755
  declare const createPaginatedQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreatePaginatedQueryOptions) => CreatePaginatedQueryResult<PageItemOf<F>>;
228
756
  /**
229
- * Subscribe to a reactively-paginated query and expose its pages discretely.
230
- *
231
- * Shares `createPaginatedQuery`'s pagination engine but keeps each page as its
232
- * own inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
233
- *
234
- * Call inside a reactive context (component / `createRoot`).
235
- */
757
+ * Subscribe to a reactively-paginated query and expose its pages discretely.
758
+ *
759
+ * Shares `createPaginatedQuery`'s pagination engine but keeps each page as its
760
+ * own inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
761
+ *
762
+ * Call inside a reactive context (component / `createRoot`).
763
+ */
236
764
  declare const createInfiniteQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreateInfiniteQueryOptions) => CreateInfiniteQueryResult<PageItemOf<F>>;
237
765
  /**
238
- * `createPresence` — collaborative-awareness primitive, the client half of the
239
- * `@lunora/server` `definePresence` preset.
240
- *
241
- * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
242
- * subscribes to the live `listPresent` query for the given room.
243
- *
244
- * Call inside a reactive context (component / `createRoot`).
245
- */
246
- /**
247
- * A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
248
- */
766
+ * `createPresence` — collaborative-awareness primitive, the client half of the
767
+ * `@lunora/server` `definePresence` preset.
768
+ *
769
+ * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
770
+ * subscribes to the live `listPresent` query for the given room.
771
+ *
772
+ * Call inside a reactive context (component / `createRoot`).
773
+ */
774
+ /**
775
+ * A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
776
+ */
249
777
  type HeartbeatReference = FunctionReference<"mutation", {
250
778
  data?: Record<string, unknown>;
251
779
  roomId: string;
252
780
  sessionId: string;
253
781
  }>;
254
782
  /**
255
- * A listPresent query reference: takes `{ roomId }` and returns the array of
256
- * present members.
257
- */
783
+ * A listPresent query reference: takes `{ roomId }` and returns the array of
784
+ * present members.
785
+ */
258
786
  type ListPresentReference = FunctionReference<"query", {
259
787
  roomId: string;
260
788
  }>;
@@ -268,14 +796,22 @@ interface CreatePresenceOptions<H extends HeartbeatReference, L extends ListPres
268
796
  /** The `api.*` reference for the presence listPresent query. */
269
797
  listPresent: L;
270
798
  /**
271
- * Stable id for this presence row. Defaults to a fresh per-mount id.
272
- * Pass a user/connection id to control deduping across tabs.
273
- */
799
+ * Called when the `listPresent` subscription reports an error (a session
800
+ * expiry, an RLS denial). Without it — and without reading `error` — such a
801
+ * failure is invisible and `present` is cleared until a later frame arrives.
802
+ */
803
+ onError?: SubscriptionErrorCallback;
804
+ /**
805
+ * Stable id for this presence row. Defaults to a fresh per-mount id.
806
+ * Pass a user/connection id to control deduping across tabs.
807
+ */
274
808
  sessionId?: string;
275
809
  /** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
276
810
  shardKey?: string;
277
811
  }
278
812
  interface CreatePresenceResult<L extends ListPresentReference> {
813
+ /** The `listPresent` subscription's last error, or `undefined`. */
814
+ error: () => SubscriptionError | undefined;
279
815
  /** The present members for the room. `undefined` until the first push. */
280
816
  present: () => ReturnOf<L> | undefined;
281
817
  /** This mount's session id (generated when not supplied). */
@@ -285,35 +821,46 @@ interface CreatePresenceResult<L extends ListPresentReference> {
285
821
  }
286
822
  declare const createPresence: <H extends HeartbeatReference, L extends ListPresentReference>(roomId: string, options: CreatePresenceOptions<H, L>) => CreatePresenceResult<L>;
287
823
  interface CreateQueryOptions {
824
+ /**
825
+ * Called when the server pushes a subscription-scoped error (an RLS denial, a
826
+ * query that starts failing server-side). Without a handler such an error has
827
+ * nowhere to go and the accessor simply freezes at its last good value.
828
+ */
829
+ onError?: SubscriptionErrorCallback;
288
830
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
289
831
  shardKey?: string;
290
832
  }
291
833
  /**
292
- * Subscribe to a server query and return a reactive accessor of its value.
293
- *
294
- * The accessor reads `undefined` until the first server frame lands, then
295
- * updates on every delta the WebSocket pushes — Solid's fine-grained signals
296
- * mean only the components that read the accessor re-render, which maps cleanly
297
- * onto Lunora's per-subscription delta model.
298
- *
299
- * `args` may be a plain value or an accessor; passing an accessor makes the
300
- * subscription reactive — when the args change the old subscription is torn down
301
- * (via `onCleanup`) and a fresh one opens for the new args. Pass `"skip"` (or an
302
- * accessor returning `"skip"`) to short-circuit: no network call, no socket.
303
- *
304
- * ```tsx
305
- * const messages = createQuery(api.messages.list, () => ({ channelId: channelId() }));
306
- * return &lt;For each={messages()?.messages}>{(m) => &lt;li>{m.text}&lt;/li>}&lt;/For>;
307
- * ```
308
- */
834
+ * Subscribe to a server query and return a reactive accessor of its value.
835
+ *
836
+ * The accessor reads `undefined` until the first server frame lands, then
837
+ * updates on every delta the WebSocket pushes — Solid's fine-grained signals
838
+ * mean only the components that read the accessor re-render, which maps cleanly
839
+ * onto Lunora's per-subscription delta model.
840
+ *
841
+ * `args` may be a plain value or an accessor; passing an accessor makes the
842
+ * subscription reactive — when the args change the old subscription is torn down
843
+ * (via `onCleanup`), the accessor resets to `undefined`, and a fresh one opens for
844
+ * the new args. Pass `"skip"` (or an
845
+ * accessor returning `"skip"`) to short-circuit: no network call, no socket.
846
+ *
847
+ * ```tsx
848
+ * const messages = createQuery(api.messages.list, () => ({ channelId: channelId() }));
849
+ * return <For each={messages()?.messages}>{(m) => <li>{m.text}</li>}</For>;
850
+ * ```
851
+ *
852
+ * Pass `onError` to surface a subscription-scoped error the server pushes (an RLS
853
+ * denial, a query that starts failing server-side). Without it such an error is
854
+ * dropped and the accessor just freezes at its last good value.
855
+ */
309
856
  declare const createQuery: <F extends FunctionReference>(function_: F, args: (ArgsOf<F> | "skip") | Accessor<ArgsOf<F> | "skip">, options?: CreateQueryOptions) => Accessor<ReturnOf<F> | undefined>;
310
857
  interface CreateRateLimitOptions {
311
858
  /** Clock injection for tests. Defaults to `Date.now`. */
312
859
  now?: () => number;
313
860
  /**
314
- * Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
315
- * ticks down and `disabled` flips back automatically. Defaults to `1000`.
316
- */
861
+ * Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
862
+ * ticks down and `disabled` flips back automatically. Defaults to `1000`.
863
+ */
317
864
  tickMs?: number;
318
865
  }
319
866
  interface CreateRateLimitResult {
@@ -331,78 +878,314 @@ interface CreateRateLimitResult {
331
878
  retryAfter: () => number;
332
879
  }
333
880
  /**
334
- * Client-side mirror of a rate limit for instant UX — disable a button or show
335
- * a countdown without a round-trip. It runs the same token-bucket / fixed-window
336
- * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
337
- * authoritative check; the server remains the source of truth.
338
- *
339
- * `config` is read on every call; pass a stable reference (module constant) so
340
- * the derived memos stay settled.
341
- */
881
+ * Client-side mirror of a rate limit for instant UX — disable a button or show
882
+ * a countdown without a round-trip. It runs the same token-bucket / fixed-window
883
+ * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
884
+ * authoritative check; the server remains the source of truth.
885
+ *
886
+ * `config` is read on every call; pass a stable reference (module constant) so
887
+ * the derived memos stay settled.
888
+ */
342
889
  declare const createRateLimit: (config: RateLimitConfig, options?: CreateRateLimitOptions) => CreateRateLimitResult;
890
+ /** The lifecycle of a stream the primitive is observing. */
891
+ type CreateStreamStatus = "complete" | "error" | "idle" | "streaming";
892
+ interface CreateStreamResult<T> {
893
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
894
+ cancel: () => void;
895
+ /** Chunks the server has pushed so far, in arrival order. */
896
+ chunks: Accessor<ReadonlyArray<T>>;
897
+ error: Accessor<Error | undefined>;
898
+ status: Accessor<CreateStreamStatus>;
899
+ }
900
+ interface CreateStreamOptions {
901
+ /**
902
+ * Opt into resume-on-reconnect for a stream the server declared `durable`.
903
+ * The chunks already received are kept and the socket re-attaches to the same
904
+ * run, so a dropped connection mid-generation continues instead of surfacing
905
+ * `STREAM_DISCONNECTED`. Has no effect on an ephemeral stream.
906
+ */
907
+ durable?: boolean;
908
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
909
+ maxBuffer?: number;
910
+ shardKey?: string;
911
+ }
912
+ /**
913
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
914
+ * lifecycle status and a cancel function, all as accessors. Changing the
915
+ * resolved `args` resets the stream — the previous iterator is cancelled and a
916
+ * fresh one opens with empty `chunks`.
917
+ *
918
+ * `args` may be a plain value or an accessor; resolving it to `"skip"` keeps the
919
+ * primitive mounted without opening a stream (mirrors `createSubscription`). The
920
+ * Solid counterpart to React's `useStream`, re-expressed with signals.
921
+ */
922
+ declare const createStream: <F extends FunctionReference<"stream">>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: CreateStreamOptions) => CreateStreamResult<ReturnOf<F>>;
343
923
  interface CreateSubscriptionResult<T> {
344
924
  data: Accessor<T | undefined>;
345
925
  error: Accessor<Error | undefined>;
346
926
  }
347
927
  /**
348
- * Subscribe to a reactive server push stream. Returns `{ data, error }`
349
- * accessors that update whenever the server emits. Passing `"skip"` as `args`
350
- * (or an accessor that resolves to `"skip"`) tears down the subscription.
351
- */
928
+ * Subscribe to a reactive server push stream. Returns `{ data, error }`
929
+ * accessors that update whenever the server emits. Passing `"skip"` as `args`
930
+ * (or an accessor that resolves to `"skip"`) tears down the subscription.
931
+ *
932
+ * `onError` mirrors the other adapters' subscription primitives: it receives the
933
+ * raw wire-level subscription error (code included) alongside the normalised
934
+ * `error` accessor.
935
+ */
352
936
  declare const createSubscription: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: {
937
+ onError?: SubscriptionErrorCallback;
353
938
  shardKey?: string;
354
939
  }) => CreateSubscriptionResult<ReturnOf<F>>;
355
940
  /**
356
- * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
357
- * during SSR, then keep it live.
358
- *
359
- * This is the client half of PLAN4's "your loaders are live" handoff. The
360
- * returned accessor is seeded **synchronously** from `preloaded.value`, so the
361
- * very first read — during hydration — returns the server-rendered value with
362
- * no loading flash and no `Suspense` fallback (unlike `createResource`, which
363
- * always starts pending). After the component mounts, a WebSocket subscription
364
- * attaches in an effect and every subsequent server delta flows into the same
365
- * signal, so the UI goes live with zero refetch.
366
- *
367
- * ```tsx
368
- * // route loader (server): const preloaded = await preloadQuery(client, api.messages.list, args);
369
- * const messages = hydratePreloaded(preloaded); // seeded from SSR, then live
370
- * return &lt;pre>{JSON.stringify(messages())}&lt;/pre>;
371
- * ```
372
- *
373
- * Effects do not run on the server during SSR (Solid only runs them after
374
- * hydration), so the subscription is strictly client-side — the seed is the
375
- * only value the server render ever sees.
376
- */
377
- declare const hydratePreloaded: <T>(preloaded: Preloaded<T>) => Accessor<T>;
941
+ * Browser Web Audio subsystems for `createVoiceAgent` — the default microphone
942
+ * capture and speaker playback implementations injected into the primitive via
943
+ * its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
944
+ * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
945
+ * primitive's transport + reactive-state logic and remains mockable in a
946
+ * non-browser test env.
947
+ */
948
+ /**
949
+ * The negotiated audio format the voice DO streams back. Mirrors
950
+ * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
951
+ * imported) so this Solid package never pulls in the server-only `@lunora/agent`
952
+ * module graph.
953
+ */
954
+ type VoiceAudioFormat = "mp3" | "wav";
955
+ /** Captures microphone audio and reports level / turn boundaries back to the primitive. */
956
+ interface VoiceMicrophone {
957
+ /** Mute/unmute the mic without tearing down the capture graph. */
958
+ setMuted: (muted: boolean) => void;
959
+ /** Stop capture and release the media stream + audio graph. */
960
+ stop: () => void;
961
+ }
962
+ /** Plays the server's streamed audio chunks and supports a mid-utterance barge-in. */
963
+ interface VoiceSpeaker {
964
+ /** Queue a decoded audio chunk for gap-minimized playback. */
965
+ enqueue: (audio: Uint8Array) => void;
966
+ /** Drop everything queued and stop the current chunk (barge-in). */
967
+ interrupt: () => void;
968
+ /** Release the playback audio context. */
969
+ stop: () => void;
970
+ }
971
+ /** Config passed to a {@link CreateMicrophone} factory. */
972
+ interface MicrophoneConfig {
973
+ /** The consecutive above-threshold chunk count that counts as a barge-in. */
974
+ interruptChunks: number;
975
+ /** RMS above which the user is considered to be barging in while the agent speaks. */
976
+ interruptThreshold: number;
977
+ /**
978
+ * `true` from the moment a turn is committed until it completes — the whole
979
+ * `thinking` + `speaking` window, not just the audible half.
980
+ *
981
+ * It gates BOTH branches below, and the wider span is the point. Gated only
982
+ * on "audibly speaking", turn detection kept running through the entire
983
+ * STT+LLM window after a `commit`: room noise at the (deliberately low)
984
+ * `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
985
+ * `commit`, and the DO refused it with "a turn is already in progress" —
986
+ * a refusal that returns before draining the audio buffer, so the PCM
987
+ * captured since the first commit leaked into the next utterance.
988
+ *
989
+ * A genuine barge-in still works in that window: it routes through the
990
+ * `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
991
+ * `interruptThreshold` — an order of magnitude above `silenceThreshold` —
992
+ * and `interrupt` is exactly what the DO tells the client to send.
993
+ */
994
+ isTurnActive: () => boolean;
995
+ /** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
996
+ onAudio: (pcm: Uint8Array) => void;
997
+ /** A barge-in was detected (RMS spike while the agent is speaking). */
998
+ onInterrupt: () => void;
999
+ /** The current input RMS (0–1), for a level meter. */
1000
+ onLevel: (rms: number) => void;
1001
+ /** A spoken utterance ended (speech followed by `silenceDurationMs` of silence). */
1002
+ onSilence: () => void;
1003
+ /** Milliseconds of sub-threshold audio (after speech) that closes an utterance. */
1004
+ silenceDurationMs: number;
1005
+ /** RMS below which audio counts as silence. */
1006
+ silenceThreshold: number;
1007
+ }
1008
+ type CreateMicrophone = (config: MicrophoneConfig) => Promise<VoiceMicrophone>;
1009
+ type CreateSpeaker = (config: {
1010
+ audioFormat: VoiceAudioFormat;
1011
+ }) => VoiceSpeaker;
1012
+ /**
1013
+ * The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
1014
+ * live, WS-backed session keyed by `threadKey`. A structural subset of the
1015
+ * generated member, so passing `api.agents.<name>Voice` type-checks.
1016
+ */
1017
+ type VoiceReference = FunctionReference<"stream", {
1018
+ threadKey: string;
1019
+ }, Record<string, unknown>>;
1020
+ /** The lifecycle of a voice call, mirrored to the UI. */
1021
+ type VoiceStatus = "idle" | "listening" | "speaking" | "thinking";
1022
+ /** A minimal structural subset of the DOM `WebSocket` the primitive drives. */
1023
+ interface VoiceSocket {
1024
+ binaryType: string;
1025
+ close: () => void;
1026
+ onclose: ((event: unknown) => void) | null;
1027
+ onerror: ((event: unknown) => void) | null;
1028
+ onmessage: ((event: {
1029
+ data: unknown;
1030
+ }) => void) | null;
1031
+ onopen: ((event: unknown) => void) | null;
1032
+ readonly readyState: number;
1033
+ send: (data: ArrayBufferView | ArrayBufferLike | string) => void;
1034
+ }
1035
+ type CreateSocket = (url: string) => VoiceSocket;
1036
+ interface CreateVoiceAgentOptions {
1037
+ /**
1038
+ * Advanced/test seam: build the microphone capture subsystem. Defaults to a
1039
+ * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
1040
+ * Audio graph stays isolated (and mockable in a non-browser test env).
1041
+ */
1042
+ createMicrophone?: CreateMicrophone;
1043
+ /**
1044
+ * Advanced/test seam: open the transport. Defaults to the WebSocket
1045
+ * implementation the client was built with (`client.getWebSocketImpl()`),
1046
+ * NOT a raw `globalThis.WebSocket`.
1047
+ */
1048
+ createSocket?: CreateSocket;
1049
+ /** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
1050
+ createSpeaker?: CreateSpeaker;
1051
+ /** Consecutive above-`interruptThreshold` chunks that trigger a barge-in. Default `3`. */
1052
+ interruptChunks?: number;
1053
+ /** Input RMS above which the user is treated as barging in while the agent speaks. Default `0.15`. */
1054
+ interruptThreshold?: number;
1055
+ /** Milliseconds of silence (after speech) that auto-commits an utterance. Default `1200`. */
1056
+ silenceDurationMs?: number;
1057
+ /** Input RMS below which audio counts as silence. Default `0.01`. */
1058
+ silenceThreshold?: number;
1059
+ /** The thread to converse on — shared with the agent's text turns. May be a plain value or accessor (resolved when the call opens). */
1060
+ threadKey: MaybeAccessor<string>;
1061
+ /** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
1062
+ voice: VoiceReference;
1063
+ }
1064
+ interface CreateVoiceAgentResult {
1065
+ /** The current input RMS (0–1) — drive a mic level meter. */
1066
+ audioLevel: Accessor<number>;
1067
+ /** `true` once the WS `ready` handshake completed. */
1068
+ connected: Accessor<boolean>;
1069
+ /** Tear down the call: close the socket, stop the mic, release audio. Idempotent. */
1070
+ endCall: () => void;
1071
+ /** The last transport/pipeline error, or `undefined`. */
1072
+ error: Accessor<Error | undefined>;
1073
+ /** The live assistant text for the in-flight turn (grows via deltas; finalized on done). */
1074
+ interimTranscript: Accessor<string>;
1075
+ /** `true` while the mic is muted. */
1076
+ isMuted: Accessor<boolean>;
1077
+ /** Send a typed turn (no audio) — a text message spoken back by the agent. */
1078
+ sendText: (text: string) => void;
1079
+ /** Open the mic, connect the socket, and start the conversation. Idempotent while active. */
1080
+ startCall: () => Promise<void>;
1081
+ /** The current call lifecycle. */
1082
+ status: Accessor<VoiceStatus>;
1083
+ /** Mute/unmute the microphone. Returns the new muted state. */
1084
+ toggleMute: () => boolean;
1085
+ /** The last finalized user utterance (STT result). */
1086
+ transcript: Accessor<string>;
1087
+ }
1088
+ /**
1089
+ * A first-class voice-call surface for a voice-enabled agent: it opens a
1090
+ * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1091
+ * streams the agent's synthesized speech back through the browser's audio output,
1092
+ * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1093
+ * `audioLevel`) to Solid signals. Pass the generated `api.agents.<name>Voice`
1094
+ * reference (never a string), matching `createAgentChat`'s reference-passing style.
1095
+ * The Solid counterpart to React's `useVoiceAgent`, re-expressed with signals; the
1096
+ * per-call connection lives in a closure variable (a primitive runs once per
1097
+ * component, so no signal-of-signal indirection is needed).
1098
+ *
1099
+ * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
1100
+ * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
1101
+ * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
1102
+ * `createSocket`) so the primitive is drivable outside a browser.
1103
+ */
1104
+ declare const createVoiceAgent: (options: CreateVoiceAgentOptions) => CreateVoiceAgentResult;
1105
+ /**
1106
+ * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
1107
+ * during SSR, then keep it live.
1108
+ *
1109
+ * This is the client half of PLAN4's "your loaders are live" handoff. The
1110
+ * returned accessor is seeded **synchronously** from `preloaded.value`, so the
1111
+ * very first read — during hydration — returns the server-rendered value with
1112
+ * no loading flash and no `Suspense` fallback (unlike `createResource`, which
1113
+ * always starts pending). Once the component mounts, a WebSocket subscription
1114
+ * attaches and every subsequent server delta flows into the same signal, so the
1115
+ * UI goes live with zero refetch.
1116
+ *
1117
+ * ```tsx
1118
+ * // route loader (server): const preloaded = await preloadQuery(client, api.messages.list, args);
1119
+ * const messages = hydratePreloaded(preloaded); // seeded from SSR, then live
1120
+ * return <pre>{JSON.stringify(messages())}</pre>;
1121
+ * ```
1122
+ *
1123
+ * Mount callbacks do not run on the server during SSR (both Solid majors defer
1124
+ * them until after hydration), so the subscription is strictly client-side —
1125
+ * the seed is the only value the server render ever sees.
1126
+ *
1127
+ * Pass `onError` to surface a subscription-scoped error the server pushes (a
1128
+ * session expiry, an RLS denial). Without it such an error is dropped and the
1129
+ * accessor keeps rendering the SSR snapshot as if it were live.
1130
+ */
1131
+ declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, options?: {
1132
+ onError?: SubscriptionErrorCallback;
1133
+ }) => Accessor<T>;
378
1134
  interface LunoraProviderProps {
379
- children: JSX.Element;
1135
+ children: SolidChildren;
380
1136
  /**
381
- * The framework-neutral transport. Build it once at the app root with
382
- * `new LunoraClient({ url })` (or `createServerClient` during SSR) and pass
383
- * it here — the provider does not own its lifecycle, so the same instance
384
- * survives across route navigations.
385
- */
1137
+ * The framework-neutral transport. Build it once at the app root with
1138
+ * `new LunoraClient({ url })` (or `createServerClient` during SSR) and pass
1139
+ * it here — the provider does not own its lifecycle, so the same instance
1140
+ * survives across route navigations.
1141
+ */
386
1142
  client: LunoraClient;
387
1143
  }
388
1144
  /**
389
- * Provides a {@link LunoraClient} to the Solid tree via {@link LunoraContext}.
390
- *
391
- * Solid's context is reactive-graph scoped rather than render scoped, so unlike
392
- * the React provider there is no QueryClient to detect or lazily create — the
393
- * adapter's reactive primitives (`createQuery`, `createMutation`,
394
- * `hydratePreloaded`) own their own signals and read the client straight from
395
- * context. Drop one of these at the root of your app:
396
- *
397
- * ```tsx
398
- * const client = new LunoraClient({ url: window.location.origin });
399
- *
400
- * render(() => (
401
- * &lt;LunoraProvider client={client}>
402
- * &lt;App />
403
- * &lt;/LunoraProvider>
404
- * ), root);
405
- * ```
406
- */
407
- 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 };
1145
+ * Provides a {@link LunoraClient} to the Solid tree via {@link LunoraContext}.
1146
+ *
1147
+ * Solid's context is reactive-graph scoped rather than render scoped, so unlike
1148
+ * the React provider there is no QueryClient to detect or lazily create — the
1149
+ * adapter's reactive primitives (`createQuery`, `createMutation`,
1150
+ * `hydratePreloaded`) own their own signals and read the client straight from
1151
+ * context. Drop one of these at the root of your app:
1152
+ *
1153
+ * ```tsx
1154
+ * const client = new LunoraClient({ url: window.location.origin });
1155
+ *
1156
+ * render(() => (
1157
+ * <LunoraProvider client={client}>
1158
+ * <App />
1159
+ * </LunoraProvider>
1160
+ * ), root);
1161
+ * ```
1162
+ *
1163
+ * Written with `createComponent` rather than JSX on purpose. Solid 1.x and 2.0
1164
+ * compile JSX against different runtimes (`solid-js/web` vs `@solidjs/web`), so
1165
+ * a JSX source file would force this package to ship two builds; `createComponent`
1166
+ * is exported from the `solid-js` root in both majors, and the provider component
1167
+ * itself is resolved per-major by {@link providerOf}. The `get` accessors keep
1168
+ * both props lazy, so swapping the `client` prop re-provides the new value to
1169
+ * descendants exactly as the JSX form did.
1170
+ */
1171
+ declare const LunoraProvider: (props: LunoraProviderProps) => SolidElement;
1172
+ export { type ActionClient, type ActionHandle, 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 FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider,
1173
+ /**
1174
+ * SolidJS adapter for Lunora.
1175
+ *
1176
+ * Thin, idiomatic glue over the framework-neutral `@lunora/client`. Solid's
1177
+ * fine-grained signals map directly onto Lunora's per-subscription deltas, so a
1178
+ * live query is just a signal the WebSocket writes to. The adapter exposes
1179
+ * `LunoraProvider` / `useLunora` (context carrying the `LunoraClient`),
1180
+ * `createQuery` (a live query accessor that opens a subscription and updates on
1181
+ * every delta), `createMutation` (an optimistic mutation handle), and
1182
+ * `hydratePreloaded` (seed a query from an SSR `Preloaded` token synchronously —
1183
+ * no loading flash — then attach the live subscription; the client half of
1184
+ * PLAN4's "your loaders are live" reactive-loader handoff).
1185
+ *
1186
+ * Server-side preloading (`createServerClient`, `preloadQuery`) lives in the
1187
+ * socket-free `@lunora/solid/server` entry (a re-export of `@lunora/client/ssr`, the
1188
+ * framework-neutral server contract) — call it from your SolidStart route loader
1189
+ * and hand the resulting `Preloaded` token to `hydratePreloaded`.
1190
+ */
1191
+ type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, type SolidChildren, Unauthenticated, type UseAuthResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createAction, createActionForClient, createAgent, createAgentChat, createAgentState, createAgentToolEvents, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createStream, createSubscription, createVoiceAgent, hydratePreloaded, useLunora };