@lunora/solid 1.0.0-alpha.5 → 1.0.0-alpha.51

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