@lunora/solid 1.0.0-alpha.6 → 1.0.0-alpha.60

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