@lunora/solid 1.0.0-alpha.9 → 1.0.0-alpha.91

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