@lunora/svelte 1.0.0-alpha.39 → 1.0.0-alpha.40

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 (3) hide show
  1. package/dist/index.d.mts +464 -475
  2. package/dist/index.d.ts +464 -475
  3. package/package.json +5 -5
package/dist/index.d.mts CHANGED
@@ -4,19 +4,19 @@ import { Readable } from 'svelte/store';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
5
5
  import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
6
6
  /**
7
- * The lifecycle status stored on an agent thread. Client-safe mirror of
8
- * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
9
- * so this Svelte entry never pulls in the server-only `@lunora/agent` module graph
10
- * (the adapter stays Svelte + `@lunora/client` only). Keep in sync with
11
- * `packages/agent/src/types.ts`.
12
- */
7
+ * The lifecycle status stored on an agent thread. Client-safe mirror of
8
+ * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
9
+ * so this Svelte entry never pulls in the server-only `@lunora/agent` module graph
10
+ * (the adapter stays Svelte + `@lunora/client` only). Keep in sync with
11
+ * `packages/agent/src/types.ts`.
12
+ */
13
13
  type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "running";
14
14
  /**
15
- * The live thread record surfaced by the `agents:agentThread` query. A structural
16
- * subset of the persisted thread row — every field beyond `status` is optional so
17
- * the shape stays forgiving as the server schema grows. Keep in sync with the
18
- * `agent_threads` table in `packages/agent/src/component.ts`.
19
- */
15
+ * The live thread record surfaced by the `agents:agentThread` query. A structural
16
+ * subset of the persisted thread row — every field beyond `status` is optional so
17
+ * the shape stays forgiving as the server schema grows. Keep in sync with the
18
+ * `agent_threads` table in `packages/agent/src/component.ts`.
19
+ */
20
20
  interface AgentThreadRecord {
21
21
  createdAt?: number;
22
22
  /** The failure message when `status === "error"`. */
@@ -31,11 +31,11 @@ interface AgentThreadRecord {
31
31
  updatedAt?: number;
32
32
  }
33
33
  /**
34
- * The `agents.agentThread` reference the handle subscribes to for live thread
35
- * state (status + the in-flight `instanceId`). A structural subset of the
36
- * generated `api.agents` surface, so the whole generated `api` object is
37
- * assignable.
38
- */
34
+ * The `agents.agentThread` reference the handle subscribes to for live thread
35
+ * state (status + the in-flight `instanceId`). A structural subset of the
36
+ * generated `api.agents` surface, so the whole generated `api` object is
37
+ * assignable.
38
+ */
39
39
  interface AgentApi {
40
40
  agents: {
41
41
  agentThread: FunctionReference<"query", {
@@ -47,16 +47,16 @@ interface AgentOptions {
47
47
  /** The generated `api` — its `agents.agentThread` query drives live thread state. */
48
48
  api: AgentApi;
49
49
  /**
50
- * Optional app mutation over the agent's cancel path
51
- * (`ctx.agents[name].cancel(id)`). Called with `{ instanceId, threadKey }`.
52
- * When omitted (or no run is in flight) {@link AgentHandle.cancel} is a no-op.
53
- */
50
+ * Optional app mutation over the agent's cancel path
51
+ * (`ctx.agents[name].cancel(id)`). Called with `{ instanceId, threadKey }`.
52
+ * When omitted (or no run is in flight) {@link AgentHandle.cancel} is a no-op.
53
+ */
54
54
  cancel?: FunctionReference<"mutation">;
55
55
  /**
56
- * The app mutation that starts (or continues) a run — a thin wrapper over
57
- * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
58
- * {@link AgentOptions.runArgs} and the per-call args.
59
- */
56
+ * The app mutation that starts (or continues) a run — a thin wrapper over
57
+ * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
58
+ * {@link AgentOptions.runArgs} and the per-call args.
59
+ */
60
60
  run: FunctionReference<"mutation">;
61
61
  /** Extra args merged into every `run` call (e.g. an `owner` or `title`). */
62
62
  runArgs?: Record<string, unknown>;
@@ -65,9 +65,9 @@ interface AgentOptions {
65
65
  }
66
66
  interface AgentHandle {
67
67
  /**
68
- * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
69
- * no-op when no `cancel` mutation was supplied or no run is in flight.
70
- */
68
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
69
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
70
+ */
71
71
  cancel: () => Promise<void>;
72
72
  /** `true` while a `run` invocation is in flight. Read with `$pending`. */
73
73
  pending: Readable<boolean>;
@@ -76,50 +76,44 @@ interface AgentHandle {
76
76
  /** The live thread status, or `undefined` before the thread exists. Read with `$status`. */
77
77
  status: Readable<AgentThreadStatus | undefined>;
78
78
  /**
79
- * Stop the live thread subscription. Call in `onDestroy`
80
- * (`onDestroy(handle.teardown)`).
81
- */
79
+ * Stop the live thread subscription. Call in `onDestroy`
80
+ * (`onDestroy(handle.teardown)`).
81
+ */
82
82
  teardown: () => void;
83
83
  /** The live thread record (status, `instanceId`, …), or `undefined` before it exists. Read with `$thread`. */
84
84
  thread: Readable<AgentThreadRecord | undefined>;
85
85
  }
86
86
  /**
87
- * A placeholder mutation reference so {@link mutation} is called unconditionally
88
- * even when the caller supplies no `cancel` mutation. Its `__lunoraRef` is never
89
- * dispatched `cancel()` short-circuits before invoking it unless a real
90
- * reference was provided.
91
- */
92
- /**
93
- * A thin agent handle: live thread `status` plus `run` / `cancel`, without the
94
- * chat message surface the Svelte counterpart to React's `useAgent`,
95
- * re-expressed as stores you read with `$`. Composes `client.subscribe` for live
96
- * thread state and {@link mutation} for the run/cancel writes. For the full
97
- * conversation surface (durable history + approvals) use `agentChat`.
98
- *
99
- * `run` and `cancel` stay generic over the app-defined mutations that wrap
100
- * `ctx.agents[name].run` / `.cancel`, so the handle hard-codes no function names
101
- * beyond the `agents:*` surface. The subscription opens eagerly on the call and
102
- * runs until {@link AgentHandle.teardown} — call `onDestroy(handle.teardown)`.
103
- *
104
- * Pass `client` explicitly, or omit it to resolve the ambient client published by
105
- * `setLunoraClient`.
106
- */
87
+ * A thin agent handle: live thread `status` plus `run` / `cancel`, without the
88
+ * chat message surface the Svelte counterpart to React's `useAgent`,
89
+ * re-expressed as stores you read with `$`. Composes `client.subscribe` for live
90
+ * thread state and {@link mutation} for the run/cancel writes. For the full
91
+ * conversation surface (durable history + approvals) use `agentChat`.
92
+ *
93
+ * `run` and `cancel` stay generic over the app-defined mutations that wrap
94
+ * `ctx.agents[name].run` / `.cancel`, so the handle hard-codes no function names
95
+ * beyond the `agents:*` surface. The subscription opens eagerly on the call and
96
+ * runs until {@link AgentHandle.teardown} call `onDestroy(handle.teardown)`.
97
+ *
98
+ * Pass `client` explicitly, or omit it to resolve the ambient client published by
99
+ * `setLunoraClient`.
100
+ */
107
101
  declare function agent(options: AgentOptions): AgentHandle;
108
102
  declare function agent(client: LunoraClient, options: AgentOptions): AgentHandle;
109
103
  /**
110
- * One persisted (or optimistic) thread message, as `agents:agentMessages`
111
- * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
112
- * re-declared here (rather than imported) so this Svelte entry never pulls in the
113
- * server-only `@lunora/agent` module graph. Keep in sync with the
114
- * `agent_messages` table in `packages/agent/src/component.ts`.
115
- */
104
+ * One persisted (or optimistic) thread message, as `agents:agentMessages`
105
+ * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
106
+ * re-declared here (rather than imported) so this Svelte entry never pulls in the
107
+ * server-only `@lunora/agent` module graph. Keep in sync with the
108
+ * `agent_messages` table in `packages/agent/src/component.ts`.
109
+ */
116
110
  interface AgentChatMessage {
117
111
  content: string;
118
112
  createdAt?: number;
119
113
  /**
120
- * `true` for a client-side optimistic user message not yet acknowledged by
121
- * the server. Cleared once the durable history carries the matching user turn.
122
- */
114
+ * `true` for a client-side optimistic user message not yet acknowledged by
115
+ * the server. Cleared once the durable history carries the matching user turn.
116
+ */
123
117
  optimistic?: boolean;
124
118
  role: "assistant" | "system" | "tool" | "user";
125
119
  seq: number;
@@ -134,11 +128,11 @@ interface AgentChatMessage {
134
128
  toolName?: string;
135
129
  }
136
130
  /**
137
- * A live token delta streamed while a turn is generating. Client-safe mirror of
138
- * `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
139
- * {@link AgentChatHandle.streamingText} live and are never replayed; the
140
- * persisted assistant message stays the single source of truth.
141
- */
131
+ * A live token delta streamed while a turn is generating. Client-safe mirror of
132
+ * `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
133
+ * {@link AgentChatHandle.streamingText} live and are never replayed; the
134
+ * persisted assistant message stays the single source of truth.
135
+ */
142
136
  interface AgentTokenDelta {
143
137
  /** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
144
138
  kind?: "token";
@@ -150,10 +144,10 @@ interface AgentTokenDelta {
150
144
  turn: number;
151
145
  }
152
146
  /**
153
- * A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
154
- * mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
155
- * surfaced by `agentToolEvents`, ignored by {@link AgentChatHandle.streamingText}.
156
- */
147
+ * A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
148
+ * mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
149
+ * surfaced by `agentToolEvents`, ignored by {@link AgentChatHandle.streamingText}.
150
+ */
157
151
  interface AgentProgressEvent {
158
152
  /** The arbitrary, JSON-serializable payload the tool reported. */
159
153
  data: unknown;
@@ -165,11 +159,11 @@ interface AgentProgressEvent {
165
159
  toolCallId: string;
166
160
  }
167
161
  /**
168
- * A single event on the agent's live-only channel — a streamed token delta or a
169
- * tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
170
- * Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
171
- * it unset).
172
- */
162
+ * A single event on the agent's live-only channel — a streamed token delta or a
163
+ * tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
164
+ * Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
165
+ * it unset).
166
+ */
173
167
  type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
174
168
  /** The `agents:agentMessages` reference — live durable thread history. */
175
169
  type AgentMessagesReference$1 = FunctionReference<"query", {
@@ -191,17 +185,17 @@ type AgentThreadReference = FunctionReference<"query", {
191
185
  key: string;
192
186
  }, Record<string, unknown> | undefined>;
193
187
  /**
194
- * An app stream reference that tees the agent's in-flight live events, keyed by
195
- * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
196
- * sink — tool progress events; this handle consumes only the token arm.
197
- */
188
+ * An app stream reference that tees the agent's in-flight live events, keyed by
189
+ * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
190
+ * sink — tool progress events; this handle consumes only the token arm.
191
+ */
198
192
  type AgentTokenStreamReference = FunctionReference<"stream", {
199
193
  key: string;
200
194
  }, AgentLiveEvent>;
201
195
  /**
202
- * The `agents.*` reference surface the chat handle reads. A structural subset of
203
- * the generated `api.agents`, so the whole generated `api` object is assignable.
204
- */
196
+ * The `agents.*` reference surface the chat handle reads. A structural subset of
197
+ * the generated `api.agents`, so the whole generated `api` object is assignable.
198
+ */
205
199
  interface AgentChatApi {
206
200
  agents: {
207
201
  agentMessages: AgentMessagesReference$1;
@@ -213,27 +207,27 @@ interface AgentChatOptions {
213
207
  /** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
214
208
  api: AgentChatApi;
215
209
  /**
216
- * Optional app mutation over the agent's cancel path
217
- * (`ctx.agents[name].cancel(id)`). Called with `{ instanceId, threadKey }`.
218
- * When omitted (or no run is in flight) {@link AgentChatHandle.cancel} is a
219
- * no-op.
220
- */
210
+ * Optional app mutation over the agent's cancel path
211
+ * (`ctx.agents[name].cancel(id)`). Called with `{ instanceId, threadKey }`.
212
+ * When omitted (or no run is in flight) {@link AgentChatHandle.cancel} is a
213
+ * no-op.
214
+ */
221
215
  cancel?: FunctionReference<"mutation">;
222
216
  /** History depth forwarded to `agents:agentMessages`. */
223
217
  limit?: number;
224
218
  /**
225
- * The app mutation that starts (or continues) a run — a thin wrapper over
226
- * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
227
- * {@link AgentChatOptions.sendArgs} and the per-call args.
228
- */
219
+ * The app mutation that starts (or continues) a run — a thin wrapper over
220
+ * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
221
+ * {@link AgentChatOptions.sendArgs} and the per-call args.
222
+ */
229
223
  send: FunctionReference<"mutation">;
230
224
  /** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
231
225
  sendArgs?: Record<string, unknown>;
232
226
  /**
233
- * Optional live token-delta stream — an app stream function that tees the
234
- * agent's in-flight deltas. When omitted {@link AgentChatHandle.streamingText}
235
- * stays empty and the UI updates message-by-message from durable history.
236
- */
227
+ * Optional live token-delta stream — an app stream function that tees the
228
+ * agent's in-flight deltas. When omitted {@link AgentChatHandle.streamingText}
229
+ * stays empty and the UI updates message-by-message from durable history.
230
+ */
237
231
  stream?: AgentTokenStreamReference;
238
232
  /** The thread to observe and continue. */
239
233
  threadKey: string;
@@ -242,9 +236,9 @@ interface AgentChatHandle {
242
236
  /** Approve a paused human-in-the-loop tool call (optionally with a note). */
243
237
  approve: (toolCallId: string, note?: string) => Promise<void>;
244
238
  /**
245
- * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
246
- * no-op when no `cancel` mutation was supplied or no run is in flight.
247
- */
239
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
240
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
241
+ */
248
242
  cancel: () => Promise<void>;
249
243
  /** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. Read with `$messages`. */
250
244
  messages: Readable<ReadonlyArray<AgentChatMessage>>;
@@ -255,54 +249,54 @@ interface AgentChatHandle {
255
249
  /** The live thread status, or `undefined` before the thread exists. Read with `$status`. */
256
250
  status: Readable<AgentThreadStatus | undefined>;
257
251
  /**
258
- * The in-flight turn's streamed text — live-only, `""` once the turn persists
259
- * to `messages`. Populated when a `stream` reference is supplied (via the
260
- * {@link stream} primitive); with no reference it stays `""` and the UI advances
261
- * message-by-message from durable history. Read with `$streamingText`.
262
- */
252
+ * The in-flight turn's streamed text — live-only, `""` once the turn persists
253
+ * to `messages`. Populated when a `stream` reference is supplied (via the
254
+ * {@link stream} primitive); with no reference it stays `""` and the UI advances
255
+ * message-by-message from durable history. Read with `$streamingText`.
256
+ */
263
257
  streamingText: Readable<string>;
264
258
  /**
265
- * Stop the live history + thread subscriptions (and the token stream, if any).
266
- * Call in `onDestroy` (`onDestroy(handle.teardown)`).
267
- */
259
+ * Stop the live history + thread subscriptions (and the token stream, if any).
260
+ * Call in `onDestroy` (`onDestroy(handle.teardown)`).
261
+ */
268
262
  teardown: () => void;
269
263
  }
270
264
  /**
271
- * A first-class agent chat surface: live durable history + in-flight token
272
- * streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
273
- * the Svelte counterpart to React's `useAgentChat`, re-expressed as stores you
274
- * read with `$`.
275
- *
276
- * It composes the existing primitives rather than adding transport:
277
- * `client.subscribe(api.agents.agentMessages)` for durable history,
278
- * `client.subscribe(api.agents.agentThread)` for live status + the in-flight
279
- * `instanceId`, {@link stream} over an app token stream for in-flight deltas, and
280
- * {@link mutation} for the writes (`api.agents.agentResolveApproval` for approvals;
281
- * app-defined wrappers for `send`/`cancel`). Only the `agents:*` surface is
282
- * hard-coded — `send`/`cancel`/`stream` stay generic references.
283
- *
284
- * A `send` optimistically appends the user turn so it renders immediately; the
285
- * optimistic row clears once the durable history carries the acknowledged turn.
286
- * `streamingText` is live-only: it holds the current turn's streamed text and
287
- * empties as soon as that turn's assistant message lands in `messages` (the
288
- * persisted message is the source of truth); with no `stream` reference it stays
289
- * `""` and the UI advances message-by-message from durable history. The
290
- * subscriptions (and the token stream, if any) open eagerly and run until
291
- * {@link AgentChatHandle.teardown} — call `onDestroy(handle.teardown)`.
292
- *
293
- * Pass `client` explicitly, or omit it to resolve the ambient client published by
294
- * `setLunoraClient`.
295
- */
265
+ * A first-class agent chat surface: live durable history + in-flight token
266
+ * streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
267
+ * the Svelte counterpart to React's `useAgentChat`, re-expressed as stores you
268
+ * read with `$`.
269
+ *
270
+ * It composes the existing primitives rather than adding transport:
271
+ * `client.subscribe(api.agents.agentMessages)` for durable history,
272
+ * `client.subscribe(api.agents.agentThread)` for live status + the in-flight
273
+ * `instanceId`, {@link stream} over an app token stream for in-flight deltas, and
274
+ * {@link mutation} for the writes (`api.agents.agentResolveApproval` for approvals;
275
+ * app-defined wrappers for `send`/`cancel`). Only the `agents:*` surface is
276
+ * hard-coded — `send`/`cancel`/`stream` stay generic references.
277
+ *
278
+ * A `send` optimistically appends the user turn so it renders immediately; the
279
+ * optimistic row clears once the durable history carries the acknowledged turn.
280
+ * `streamingText` is live-only: it holds the current turn's streamed text and
281
+ * empties as soon as that turn's assistant message lands in `messages` (the
282
+ * persisted message is the source of truth); with no `stream` reference it stays
283
+ * `""` and the UI advances message-by-message from durable history. The
284
+ * subscriptions (and the token stream, if any) open eagerly and run until
285
+ * {@link AgentChatHandle.teardown} — call `onDestroy(handle.teardown)`.
286
+ *
287
+ * Pass `client` explicitly, or omit it to resolve the ambient client published by
288
+ * `setLunoraClient`.
289
+ */
296
290
  declare function agentChat(options: AgentChatOptions): AgentChatHandle;
297
291
  declare function agentChat(client: LunoraClient, options: AgentChatOptions): AgentChatHandle;
298
292
  /**
299
- * The `agents.agentState` reference the handle subscribes to for the thread's live
300
- * synced state. A structural subset of the generated `api.agents` surface (like
301
- * `AgentApi` for `agentThread`), so the whole generated `api` object is
302
- * assignable. Client-safe: no `@lunora/agent` import — the per-agent state type is
303
- * mirrored by the handle's generic `T`, since codegen pins the reference return as
304
- * an optional record (it never evaluates agent config).
305
- */
293
+ * The `agents.agentState` reference the handle subscribes to for the thread's live
294
+ * synced state. A structural subset of the generated `api.agents` surface (like
295
+ * `AgentApi` for `agentThread`), so the whole generated `api` object is
296
+ * assignable. Client-safe: no `@lunora/agent` import — the per-agent state type is
297
+ * mirrored by the handle's generic `T`, since codegen pins the reference return as
298
+ * an optional record (it never evaluates agent config).
299
+ */
306
300
  interface AgentStateApi {
307
301
  agents: {
308
302
  agentState: FunctionReference<"query", {
@@ -323,23 +317,23 @@ interface AgentStateHandle<T> {
323
317
  state: Readable<T | undefined>;
324
318
  }
325
319
  /**
326
- * Subscribe to an agent thread's synced state — the `setState`-style value a tool
327
- * writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
328
- * thin wrapper over {@link subscription} against `api.agents.agentState`: the
329
- * server pushes a fresh frame whenever the state changes (the dedicated query's
330
- * per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
331
- * `state` updates only on a real `setState`. The Svelte counterpart to React's
332
- * `useAgentState`, re-expressed as stores you read with `$`.
333
- *
334
- * Generic over the app's state shape (`agentState&lt;SupportState>(...)`, itself a
335
- * record) — the reference is typed as an optional record because codegen cannot
336
- * see the per-agent state type; the generic casts to `T`. The `state`/`error`
337
- * stores are lazy, so the subscription opens on the first subscriber to `state`
338
- * and tears down when the last one leaves — there is no `teardown` to call.
339
- *
340
- * Pass `client` explicitly, or omit it to resolve the ambient client published by
341
- * `setLunoraClient`.
342
- */
320
+ * Subscribe to an agent thread's synced state — the `setState`-style value a tool
321
+ * writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
322
+ * thin wrapper over {@link subscription} against `api.agents.agentState`: the
323
+ * server pushes a fresh frame whenever the state changes (the dedicated query's
324
+ * per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
325
+ * `state` updates only on a real `setState`. The Svelte counterpart to React's
326
+ * `useAgentState`, re-expressed as stores you read with `$`.
327
+ *
328
+ * Generic over the app's state shape (`agentState&lt;SupportState>(...)`, itself a
329
+ * record) — the reference is typed as an optional record because codegen cannot
330
+ * see the per-agent state type; the generic casts to `T`. The `state`/`error`
331
+ * stores are lazy, so the subscription opens on the first subscriber to `state`
332
+ * and tears down when the last one leaves — there is no `teardown` to call.
333
+ *
334
+ * Pass `client` explicitly, or omit it to resolve the ambient client published by
335
+ * `setLunoraClient`.
336
+ */
343
337
  declare function agentState<T extends Record<string, unknown> = Record<string, unknown>>(options: AgentStateOptions): AgentStateHandle<T>;
344
338
  declare function agentState<T extends Record<string, unknown> = Record<string, unknown>>(client: LunoraClient, options: AgentStateOptions): AgentStateHandle<T>;
345
339
  /** The `agents:agentMessages` reference — live durable thread history. */
@@ -348,18 +342,18 @@ type AgentMessagesReference = FunctionReference<"query", {
348
342
  limit?: number;
349
343
  }, ReadonlyArray<Record<string, unknown>>>;
350
344
  /**
351
- * An app stream reference that tees the agent's in-flight live events, keyed by
352
- * thread. Carries token deltas and tool progress events; this handle consumes only
353
- * the progress arm (`kind === "progress"`).
354
- */
345
+ * An app stream reference that tees the agent's in-flight live events, keyed by
346
+ * thread. Carries token deltas and tool progress events; this handle consumes only
347
+ * the progress arm (`kind === "progress"`).
348
+ */
355
349
  type AgentLiveStreamReference = FunctionReference<"stream", {
356
350
  key: string;
357
351
  }, AgentLiveEvent>;
358
352
  /**
359
- * The `agents.*` reference surface the tool-events handle reads. A structural
360
- * subset of the generated `api.agents`, so the whole generated `api` object is
361
- * assignable.
362
- */
353
+ * The `agents.*` reference surface the tool-events handle reads. A structural
354
+ * subset of the generated `api.agents`, so the whole generated `api` object is
355
+ * assignable.
356
+ */
363
357
  interface AgentToolEventsApi {
364
358
  agents: {
365
359
  agentMessages: AgentMessagesReference;
@@ -371,21 +365,21 @@ interface AgentToolEventsOptions {
371
365
  /** History depth forwarded to `agents:agentMessages`. */
372
366
  limit?: number;
373
367
  /**
374
- * Optional live event stream — the same app stream function `agentChat` uses.
375
- * When supplied, ephemeral `ctx.reportProgress(...)` events for the thread are
376
- * surfaced as `{ type: "progress" }` entries; when omitted only the durable
377
- * lifecycle (call / result / awaiting-approval) is returned.
378
- */
368
+ * Optional live event stream — the same app stream function `agentChat` uses.
369
+ * When supplied, ephemeral `ctx.reportProgress(...)` events for the thread are
370
+ * surfaced as `{ type: "progress" }` entries; when omitted only the durable
371
+ * lifecycle (call / result / awaiting-approval) is returned.
372
+ */
379
373
  stream?: AgentLiveStreamReference;
380
374
  /** The thread whose tool activity to observe. */
381
375
  threadKey: string;
382
376
  }
383
377
  /**
384
- * A single tool-lifecycle event for a thread. The durable arms
385
- * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
386
- * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
387
- * stream and has no `seq`. Discriminate on `type`.
388
- */
378
+ * A single tool-lifecycle event for a thread. The durable arms
379
+ * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
380
+ * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
381
+ * stream and has no `seq`. Discriminate on `type`.
382
+ */
389
383
  type AgentToolEvent = {
390
384
  data: unknown;
391
385
  toolCallId: string;
@@ -411,58 +405,58 @@ type AgentToolEvent = {
411
405
  };
412
406
  interface AgentToolEventsHandle {
413
407
  /**
414
- * The thread's tool events: the durable lifecycle (oldest first, by `seq`)
415
- * followed by any in-flight ephemeral progress events, recomputed from the live
416
- * subscription + stream. Read with `$events`. With no `stream` reference only
417
- * the durable lifecycle is surfaced. Treat as derived, not identity-stable.
418
- */
408
+ * The thread's tool events: the durable lifecycle (oldest first, by `seq`)
409
+ * followed by any in-flight ephemeral progress events, recomputed from the live
410
+ * subscription + stream. Read with `$events`. With no `stream` reference only
411
+ * the durable lifecycle is surfaced. Treat as derived, not identity-stable.
412
+ */
419
413
  events: Readable<ReadonlyArray<AgentToolEvent>>;
420
414
  }
421
415
  /**
422
- * A focused view of a thread's tool activity: tool calls, their results,
423
- * human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
424
- * without the full chat message surface. The Svelte counterpart to React's
425
- * `useAgentToolEvents`, re-expressed as a readable store you read with `$`.
426
- *
427
- * It composes the existing primitives rather than adding transport:
428
- * {@link subscription} over `api.agents.agentMessages` for the durable lifecycle
429
- * and {@link stream} over the optional app event stream for ephemeral progress,
430
- * combined through `derived`. Progress events are live-only (the durable path never
431
- * emits them): they ride the same sink as token deltas and are surfaced here,
432
- * correlated to their tool call by `toolCallId`. For the conversational surface
433
- * (messages + streaming text + approvals) use `agentChat`; this handle is the
434
- * tool-observability slice.
435
- *
436
- * The underlying subscription and stream are lazy — they open when `events` gains
437
- * its first subscriber and tear down when the last one leaves — so there is no
438
- * `teardown` to call (unlike the write-bearing `agentChat`).
439
- *
440
- * Pass `client` explicitly, or omit it to resolve the ambient client published by
441
- * `setLunoraClient`.
442
- */
416
+ * A focused view of a thread's tool activity: tool calls, their results,
417
+ * human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
418
+ * without the full chat message surface. The Svelte counterpart to React's
419
+ * `useAgentToolEvents`, re-expressed as a readable store you read with `$`.
420
+ *
421
+ * It composes the existing primitives rather than adding transport:
422
+ * {@link subscription} over `api.agents.agentMessages` for the durable lifecycle
423
+ * and {@link stream} over the optional app event stream for ephemeral progress,
424
+ * combined through `derived`. Progress events are live-only (the durable path never
425
+ * emits them): they ride the same sink as token deltas and are surfaced here,
426
+ * correlated to their tool call by `toolCallId`. For the conversational surface
427
+ * (messages + streaming text + approvals) use `agentChat`; this handle is the
428
+ * tool-observability slice.
429
+ *
430
+ * The underlying subscription and stream are lazy — they open when `events` gains
431
+ * its first subscriber and tear down when the last one leaves — so there is no
432
+ * `teardown` to call (unlike the write-bearing `agentChat`).
433
+ *
434
+ * Pass `client` explicitly, or omit it to resolve the ambient client published by
435
+ * `setLunoraClient`.
436
+ */
443
437
  declare function agentToolEvents(options: AgentToolEventsOptions): AgentToolEventsHandle;
444
438
  declare function agentToolEvents(client: LunoraClient, options: AgentToolEventsOptions): AgentToolEventsHandle;
445
439
  /**
446
- * Publish a {@link LunoraClient} on the Svelte component context so that
447
- * descendant components can read it with {@link getLunoraClient} (or implicitly,
448
- * via the default-client lookups inside `query`/`mutation`/`hydratePreloaded`).
449
- *
450
- * Call this once, high in the tree (typically your root `+layout.svelte` or
451
- * `App.svelte`), during component initialisation — `setContext` must run while
452
- * the component is being constructed, exactly like React's provider mounts once.
453
- * This is the Svelte analogue of mounting `LunoraProvider`.
454
- */
440
+ * Publish a {@link LunoraClient} on the Svelte component context so that
441
+ * descendant components can read it with {@link getLunoraClient} (or implicitly,
442
+ * via the default-client lookups inside `query`/`mutation`/`hydratePreloaded`).
443
+ *
444
+ * Call this once, high in the tree (typically your root `+layout.svelte` or
445
+ * `App.svelte`), during component initialisation — `setContext` must run while
446
+ * the component is being constructed, exactly like React's provider mounts once.
447
+ * This is the Svelte analogue of mounting `LunoraProvider`.
448
+ */
455
449
  declare const setLunoraClient: (client: LunoraClient) => LunoraClient;
456
450
  /**
457
- * Read the {@link LunoraClient} published by {@link setLunoraClient} from the
458
- * nearest ancestor. Throws if no provider is mounted, mirroring `useLunora`'s
459
- * "must be used inside a LunoraProvider" guard so the failure is loud and
460
- * early rather than a confusing `undefined` deref later.
461
- *
462
- * Must be called during component initialisation (Svelte's `getContext`
463
- * constraint); the live stores returned by `query`/`hydratePreloaded` resolve
464
- * the client eagerly at call time for exactly this reason.
465
- */
451
+ * Read the {@link LunoraClient} published by {@link setLunoraClient} from the
452
+ * nearest ancestor. Throws if no provider is mounted, mirroring `useLunora`'s
453
+ * "must be used inside a LunoraProvider" guard so the failure is loud and
454
+ * early rather than a confusing `undefined` deref later.
455
+ *
456
+ * Must be called during component initialisation (Svelte's `getContext`
457
+ * constraint); the live stores returned by `query`/`hydratePreloaded` resolve
458
+ * the client eagerly at call time for exactly this reason.
459
+ */
466
460
  declare const getLunoraClient: () => LunoraClient;
467
461
  interface AuthStore {
468
462
  /** Set the auth token on the underlying `LunoraClient`. */
@@ -473,31 +467,31 @@ interface AuthStore {
473
467
  user: Readable<User | null>;
474
468
  }
475
469
  /**
476
- * Create a pair of Svelte readable stores tracking the auth token and the
477
- * resolved user identity. The stores are lazy: subscriptions open on the first
478
- * reader and close when the last unsubscribes. Calling `setToken(jwt)` after
479
- * sign-in refreshes both stores.
480
- *
481
- * Pass an explicit client to bypass the ambient context (useful in tests).
482
- */
470
+ * Create a pair of Svelte readable stores tracking the auth token and the
471
+ * resolved user identity. The stores are lazy: subscriptions open on the first
472
+ * reader and close when the last unsubscribes. Calling `setToken(jwt)` after
473
+ * sign-in refreshes both stores.
474
+ *
475
+ * Pass an explicit client to bypass the ambient context (useful in tests).
476
+ */
483
477
  declare const auth: (explicitClient?: ReturnType<typeof getLunoraClient>) => AuthStore;
484
478
  /** The shape held by a {@link connectionStatus} store: the latest aggregate live-socket status. */
485
479
  type ConnectionStatusStore = Readable<ConnectionStatus>;
486
480
  /**
487
- * Expose the client's aggregate live-socket status as a Svelte readable store.
488
- * Read it with the `$store` idiom (`{$status}`) and it stays current: the value
489
- * transitions through `idle` → `connecting` → `connected` → `offline` as
490
- * sockets open and drop — the Svelte equivalent of `@lunora/react`'s
491
- * `useConnectionStatus`. Use it to drive a connection indicator.
492
- *
493
- * The status listener attaches inside `readable`'s start callback (on the first
494
- * `$`-read / `.subscribe()`) and is released by the returned stop function when
495
- * the last subscriber goes away, so a store that's never read attaches nothing.
496
- *
497
- * Pass `client` explicitly, or omit it to resolve the ambient client published
498
- * by `setLunoraClient` (which must therefore be called during component init,
499
- * before this runs).
500
- */
481
+ * Expose the client's aggregate live-socket status as a Svelte readable store.
482
+ * Read it with the `$store` idiom (`{$status}`) and it stays current: the value
483
+ * transitions through `idle` → `connecting` → `connected` → `offline` as
484
+ * sockets open and drop — the Svelte equivalent of `@lunora/react`'s
485
+ * `useConnectionStatus`. Use it to drive a connection indicator.
486
+ *
487
+ * The status listener attaches inside `readable`'s start callback (on the first
488
+ * `$`-read / `.subscribe()`) and is released by the returned stop function when
489
+ * the last subscriber goes away, so a store that's never read attaches nothing.
490
+ *
491
+ * Pass `client` explicitly, or omit it to resolve the ambient client published
492
+ * by `setLunoraClient` (which must therefore be called during component init,
493
+ * before this runs).
494
+ */
501
495
  declare const connectionStatus: (client?: LunoraClient) => ConnectionStatusStore;
502
496
  /** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
503
497
  type FlagContext = Record<string, unknown>;
@@ -506,105 +500,105 @@ type FlagValue = boolean | number | string | {
506
500
  [key: string]: unknown;
507
501
  } | unknown[] | null;
508
502
  /**
509
- * Open a single feature flag as a Svelte readable store, live over Lunora's
510
- * WebSocket. Read it with the `$store` idiom (`{$darkMode}`).
511
- *
512
- * The store holds `defaultValue` until the first evaluation lands, then the
513
- * server's resolved value — re-emitted whenever the provider re-evaluates (e.g. a
514
- * flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
515
- * `defaultValue`'s runtime type, so `flag("dark", false)` reads a boolean and
516
- * `flag("hero", "control")` a string. `context` supplies a per-call targeting
517
- * context merged on top of the app's default `identify` targeting key.
518
- *
519
- * The subscription opens lazily on the first `$`-read and tears down when the
520
- * last subscriber detaches. Pass `client` explicitly, or omit it to resolve the
521
- * ambient client published by `setLunoraClient`. Evaluation never throws — a
522
- * provider error resolves the default (the same fail-open contract as `ctx.flags`).
523
- */
503
+ * Open a single feature flag as a Svelte readable store, live over Lunora's
504
+ * WebSocket. Read it with the `$store` idiom (`{$darkMode}`).
505
+ *
506
+ * The store holds `defaultValue` until the first evaluation lands, then the
507
+ * server's resolved value — re-emitted whenever the provider re-evaluates (e.g. a
508
+ * flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
509
+ * `defaultValue`'s runtime type, so `flag("dark", false)` reads a boolean and
510
+ * `flag("hero", "control")` a string. `context` supplies a per-call targeting
511
+ * context merged on top of the app's default `identify` targeting key.
512
+ *
513
+ * The subscription opens lazily on the first `$`-read and tears down when the
514
+ * last subscriber detaches. Pass `client` explicitly, or omit it to resolve the
515
+ * ambient client published by `setLunoraClient`. Evaluation never throws — a
516
+ * provider error resolves the default (the same fail-open contract as `ctx.flags`).
517
+ */
524
518
  declare function flag<T extends FlagValue>(key: string, defaultValue: T, context?: FlagContext): Readable<T>;
525
519
  declare function flag<T extends FlagValue>(client: LunoraClient, key: string, defaultValue: T, context?: FlagContext): Readable<T>;
526
520
  /**
527
- * Open several feature flags at once as a single Svelte readable store of the
528
- * resolved record, live over Lunora's WebSocket.
529
- *
530
- * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
531
- * default, and the store holds the same-shaped record with resolved values (the
532
- * defaults until each evaluation lands). A single `context` applies to every
533
- * flag. This is the batched form of {@link flag} — one store, one subscription
534
- * per key, torn down together when the last subscriber detaches.
535
- *
536
- * Pass `client` explicitly, or omit it to resolve the ambient client published
537
- * by `setLunoraClient`.
538
- */
521
+ * Open several feature flags at once as a single Svelte readable store of the
522
+ * resolved record, live over Lunora's WebSocket.
523
+ *
524
+ * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
525
+ * default, and the store holds the same-shaped record with resolved values (the
526
+ * defaults until each evaluation lands). A single `context` applies to every
527
+ * flag. This is the batched form of {@link flag} — one store, one subscription
528
+ * per key, torn down together when the last subscriber detaches.
529
+ *
530
+ * Pass `client` explicitly, or omit it to resolve the ambient client published
531
+ * by `setLunoraClient`.
532
+ */
539
533
  declare function flags<T extends Record<string, FlagValue>>(flagDefaults: T, context?: FlagContext): Readable<T>;
540
534
  declare function flags<T extends Record<string, FlagValue>>(client: LunoraClient, flagDefaults: T, context?: FlagContext): Readable<T>;
541
535
  /**
542
- * Hydrate a query store from a {@link Preloaded} token produced by
543
- * `preloadQuery` during SSR, then keep it live — the reactive-loader handoff.
544
- *
545
- * The store is seeded **synchronously** with `preloaded.value`, so the very
546
- * first read (`$store` during hydration) returns the server value with no
547
- * loading flash and no hydration mismatch — there is no `undefined` window and
548
- * no refetch. When the store gains its first subscriber on the client, a live
549
- * WS subscription attaches and every subsequent delta re-emits, exactly like a
550
- * plain `query` store. This is the Svelte equivalent of React's
551
- * `usePreloadedQuery`.
552
- *
553
- * Pass `client` explicitly, or omit it to resolve the ambient client published
554
- * by `setLunoraClient`.
555
- *
556
- * Note on SSR: `readable`'s start callback only runs when the store is actually
557
- * subscribed (the browser), so on the server the store simply holds the seeded
558
- * value and opens no socket. The token's `value` is the single source of truth
559
- * for the first paint either way.
560
- */
536
+ * Hydrate a query store from a {@link Preloaded} token produced by
537
+ * `preloadQuery` during SSR, then keep it live — the reactive-loader handoff.
538
+ *
539
+ * The store is seeded **synchronously** with `preloaded.value`, so the very
540
+ * first read (`$store` during hydration) returns the server value with no
541
+ * loading flash and no hydration mismatch — there is no `undefined` window and
542
+ * no refetch. When the store gains its first subscriber on the client, a live
543
+ * WS subscription attaches and every subsequent delta re-emits, exactly like a
544
+ * plain `query` store. This is the Svelte equivalent of React's
545
+ * `usePreloadedQuery`.
546
+ *
547
+ * Pass `client` explicitly, or omit it to resolve the ambient client published
548
+ * by `setLunoraClient`.
549
+ *
550
+ * Note on SSR: `readable`'s start callback only runs when the store is actually
551
+ * subscribed (the browser), so on the server the store simply holds the seeded
552
+ * value and opens no socket. The token's `value` is the single source of truth
553
+ * for the first paint either way.
554
+ */
561
555
  declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, client?: LunoraClient) => Readable<T>;
562
556
  /**
563
- * The reactive handle returned by {@link mutation} — the Svelte counterpart to
564
- * React's `useMutation`, re-expressed as stores you read with `$`. The surface
565
- * is identical across the Lunora adapters (`@lunora/solid`, `/vue`):
566
- * `data`/`error`/`pending` are readable stores and `mutate` is an awaitable.
567
- */
557
+ * The reactive handle returned by {@link mutation} — the Svelte counterpart to
558
+ * React's `useMutation`, re-expressed as stores you read with `$`. The surface
559
+ * is identical across the Lunora adapters (`@lunora/solid`, `/vue`):
560
+ * `data`/`error`/`pending` are readable stores and `mutate` is an awaitable.
561
+ */
568
562
  interface MutationHandle<F extends FunctionReference> {
569
563
  /** The latest invocation's resolved value, or `undefined` before the first success. */
570
564
  data: Readable<ReturnOf<F> | undefined>;
571
565
  /** The latest invocation's error, or `undefined`. */
572
566
  error: Readable<Error | undefined>;
573
567
  /**
574
- * Run the mutation. Resolves with the server result and rejects on failure
575
- * (errors propagate — there is no swallowing). Optimistic updates passed in
576
- * `options` are applied and rolled back by the client against the live query
577
- * subscriptions, exactly as in the React adapter.
578
- */
568
+ * Run the mutation. Resolves with the server result and rejects on failure
569
+ * (errors propagate — there is no swallowing). Optimistic updates passed in
570
+ * `options` are applied and rolled back by the client against the live query
571
+ * subscriptions, exactly as in the React adapter.
572
+ */
579
573
  mutate: (args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>>) => Promise<ReturnOf<F>>;
580
574
  /**
581
- * `true` while any invocation from this handle is in flight. Ref-counted, so
582
- * overlapping calls compose and it only flips back to `false` once the last
583
- * one settles. Read it with `$pending` in a component to disable a button.
584
- */
575
+ * `true` while any invocation from this handle is in flight. Ref-counted, so
576
+ * overlapping calls compose and it only flips back to `false` once the last
577
+ * one settles. Read it with `$pending` in a component to disable a button.
578
+ */
585
579
  pending: Readable<boolean>;
586
580
  /** Clear `data`/`error` back to idle. */
587
581
  reset: () => void;
588
582
  }
589
583
  /**
590
- * Create an optimistic {@link MutationHandle} for a mutation reference. The
591
- * Svelte counterpart to React's `useMutation`: returns
592
- * `{ data, error, pending, mutate, reset }` of readable stores plus an awaitable
593
- * `mutate`. The ref-counted pending + error-normalize orchestration is the
594
- * shared `createMutationRunner` from `@lunora/client`; only the stores are
595
- * adapter-specific.
596
- *
597
- * Pass `client` explicitly, or omit it to resolve the ambient client published
598
- * by `setLunoraClient`.
599
- */
584
+ * Create an optimistic {@link MutationHandle} for a mutation reference. The
585
+ * Svelte counterpart to React's `useMutation`: returns
586
+ * `{ data, error, pending, mutate, reset }` of readable stores plus an awaitable
587
+ * `mutate`. The ref-counted pending + error-normalize orchestration is the
588
+ * shared `createMutationRunner` from `@lunora/client`; only the stores are
589
+ * adapter-specific.
590
+ *
591
+ * Pass `client` explicitly, or omit it to resolve the ambient client published
592
+ * by `setLunoraClient`.
593
+ */
600
594
  declare function mutation<F extends FunctionReference>(function_: F): MutationHandle<F>;
601
595
  declare function mutation<F extends FunctionReference>(client: LunoraClient, function_: F): MutationHandle<F>;
602
596
  /**
603
- * The reactive handle returned by {@link mutator} — the Svelte counterpart to
604
- * `@lunora/react`'s `useMutator`, re-expressed as stores you read with `$`.
605
- * `error`/`isError`/`pending` are readable stores and `mutate` is an awaitable
606
- * that resolves once the write is persisted (or rejects).
607
- */
597
+ * The reactive handle returned by {@link mutator} — the Svelte counterpart to
598
+ * `@lunora/react`'s `useMutator`, re-expressed as stores you read with `$`.
599
+ * `error`/`isError`/`pending` are readable stores and `mutate` is an awaitable
600
+ * that resolves once the write is persisted (or rejects).
601
+ */
608
602
  interface MutatorHandleStore<TArgs> {
609
603
  /** The latest invocation's error, or `undefined`. */
610
604
  error: Readable<Error | undefined>;
@@ -618,17 +612,17 @@ interface MutatorHandleStore<TArgs> {
618
612
  reset: () => void;
619
613
  }
620
614
  /**
621
- * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
622
- * custom-mutator handle from `@lunora/db`'s `bindMutators` — the Svelte
623
- * equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
624
- * server-authoritative push are owned by the bound handle (and TanStack DB's
625
- * optimistic-transaction layer rebases pending overlays on every sync tick);
626
- * this helper only surfaces store state for the in-flight/error lifecycle. Reads
627
- * stay on the existing TanStack `useLiveQuery`; no new query store is needed.
628
- *
629
- * `pending` is ref-counted across overlapping invocations of THIS handle, so it
630
- * clears only once every concurrent call has settled.
631
- */
615
+ * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
616
+ * custom-mutator handle from `@lunora/db`'s `bindMutators` — the Svelte
617
+ * equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
618
+ * server-authoritative push are owned by the bound handle (and TanStack DB's
619
+ * optimistic-transaction layer rebases pending overlays on every sync tick);
620
+ * this helper only surfaces store state for the in-flight/error lifecycle. Reads
621
+ * stay on the existing TanStack `useLiveQuery`; no new query store is needed.
622
+ *
623
+ * `pending` is ref-counted across overlapping invocations of THIS handle, so it
624
+ * clears only once every concurrent call has settled.
625
+ */
632
626
  declare const mutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHandleStore<TArgs>;
633
627
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
634
628
  type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
@@ -669,46 +663,46 @@ interface InfiniteQueryHandle<T> {
669
663
  status: Readable<PaginationStatus>;
670
664
  }
671
665
  /**
672
- * Open a live paginated query as Svelte stores. The first page opens when
673
- * called; call `loadMore(n)` to append the next page. Results are flattened
674
- * across all loaded pages.
675
- *
676
- * Pass `client` explicitly, or omit it to resolve the ambient client from the
677
- * Svelte context.
678
- */
666
+ * Open a live paginated query as Svelte stores. The first page opens when
667
+ * called; call `loadMore(n)` to append the next page. Results are flattened
668
+ * across all loaded pages.
669
+ *
670
+ * Pass `client` explicitly, or omit it to resolve the ambient client from the
671
+ * Svelte context.
672
+ */
679
673
  declare function paginatedQuery<F extends FunctionReference>(function_: F, args: "skip" | PaginatedArgs<F>, options: PaginatedQueryOptions): PaginatedQueryHandle<PageItemOf<F>>;
680
674
  declare function paginatedQuery<F extends FunctionReference>(client: LunoraClient, function_: F, args: "skip" | PaginatedArgs<F>, options: PaginatedQueryOptions): PaginatedQueryHandle<PageItemOf<F>>;
681
675
  /**
682
- * Open a live paginated query as Svelte stores, keeping each page as its own
683
- * inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
684
- *
685
- * Pass `client` explicitly, or omit it to resolve the ambient client from the
686
- * Svelte context.
687
- */
676
+ * Open a live paginated query as Svelte stores, keeping each page as its own
677
+ * inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
678
+ *
679
+ * Pass `client` explicitly, or omit it to resolve the ambient client from the
680
+ * Svelte context.
681
+ */
688
682
  declare function infiniteQuery<F extends FunctionReference>(function_: F, args: "skip" | PaginatedArgs<F>, options: InfiniteQueryOptions): InfiniteQueryHandle<PageItemOf<F>>;
689
683
  declare function infiniteQuery<F extends FunctionReference>(client: LunoraClient, function_: F, args: "skip" | PaginatedArgs<F>, options: InfiniteQueryOptions): InfiniteQueryHandle<PageItemOf<F>>;
690
684
  /**
691
- * `presence` — collaborative-awareness stores, the client half of the
692
- * `@lunora/server` `definePresence` preset.
693
- *
694
- * Drives the heartbeat mutation (on call, interval, and tab re-focus) and
695
- * subscribes to the live `listPresent` query for the given room.
696
- *
697
- * Pass `client` explicitly, or omit it to resolve the ambient client from the
698
- * Svelte context.
699
- */
685
+ * `presence` — collaborative-awareness stores, the client half of the
686
+ * `@lunora/server` `definePresence` preset.
687
+ *
688
+ * Drives the heartbeat mutation (on call, interval, and tab re-focus) and
689
+ * subscribes to the live `listPresent` query for the given room.
690
+ *
691
+ * Pass `client` explicitly, or omit it to resolve the ambient client from the
692
+ * Svelte context.
693
+ */
700
694
  /**
701
- * A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
702
- */
695
+ * A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
696
+ */
703
697
  type HeartbeatReference = FunctionReference<"mutation", {
704
698
  data?: Record<string, unknown>;
705
699
  roomId: string;
706
700
  sessionId: string;
707
701
  }>;
708
702
  /**
709
- * A listPresent query reference: takes `{ roomId }` and returns the array of
710
- * present members.
711
- */
703
+ * A listPresent query reference: takes `{ roomId }` and returns the array of
704
+ * present members.
705
+ */
712
706
  type ListPresentReference = FunctionReference<"query", {
713
707
  roomId: string;
714
708
  }>;
@@ -722,9 +716,9 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
722
716
  /** The `api.*` reference for the presence listPresent query. */
723
717
  listPresent: L;
724
718
  /**
725
- * Stable id for this presence row. Defaults to a fresh per-mount id.
726
- * Pass a user/connection id to control deduping across tabs.
727
- */
719
+ * Stable id for this presence row. Defaults to a fresh per-mount id.
720
+ * Pass a user/connection id to control deduping across tabs.
721
+ */
728
722
  sessionId?: string;
729
723
  /** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
730
724
  shardKey?: string;
@@ -740,18 +734,18 @@ interface PresenceHandle<L extends ListPresentReference> {
740
734
  teardown: () => void;
741
735
  }
742
736
  /**
743
- * Open a live presence handle.
744
- *
745
- * Pass `client` explicitly, or omit it to resolve the ambient client from the
746
- * Svelte context (requires calling inside a component's `&lt;script>` block or
747
- * inside a function called during component initialisation).
748
- *
749
- * Teardown (stop heartbeats, remove the visibility listener, release the
750
- * connection context) is wired automatically to the component's `onDestroy`
751
- * when called during component initialisation. Outside a component call
752
- * `handle.teardown()` yourself. `teardown()` is idempotent, so an explicit
753
- * `onDestroy(handle.teardown)` on top of the auto-wiring is safe.
754
- */
737
+ * Open a live presence handle.
738
+ *
739
+ * Pass `client` explicitly, or omit it to resolve the ambient client from the
740
+ * Svelte context (requires calling inside a component's `&lt;script>` block or
741
+ * inside a function called during component initialisation).
742
+ *
743
+ * Teardown (stop heartbeats, remove the visibility listener, release the
744
+ * connection context) is wired automatically to the component's `onDestroy`
745
+ * when called during component initialisation. Outside a component call
746
+ * `handle.teardown()` yourself. `teardown()` is idempotent, so an explicit
747
+ * `onDestroy(handle.teardown)` on top of the auto-wiring is safe.
748
+ */
755
749
  declare function presence<H extends HeartbeatReference, L extends ListPresentReference>(roomId: string, options: PresenceOptions<H, L>): PresenceHandle<L>;
756
750
  declare function presence<H extends HeartbeatReference, L extends ListPresentReference>(client: LunoraClient, roomId: string, options: PresenceOptions<H, L>): PresenceHandle<L>;
757
751
  /** Options accepted by {@link query}. */
@@ -762,40 +756,40 @@ interface QueryStoreOptions {
762
756
  shardKey?: string;
763
757
  }
764
758
  /**
765
- * The shape held by a {@link query} store: the latest server value (`undefined`
766
- * until the first response lands, mirroring React's `useQuery`).
767
- */
759
+ * The shape held by a {@link query} store: the latest server value (`undefined`
760
+ * until the first response lands, mirroring React's `useQuery`).
761
+ */
768
762
  type QueryStore<F extends FunctionReference> = Readable<ReturnOf<F> | undefined>;
769
763
  /**
770
- * Open a live query as a Svelte readable store. Read it with the `$store`
771
- * idiom in a component (`{$messages}`) and it stays current: a WS subscription
772
- * attaches the moment the store gains its first subscriber and the value
773
- * re-emits on every server delta — the Svelte equivalent of React's `useQuery`.
774
- *
775
- * The subscription is opened lazily (inside `readable`'s start callback, on the
776
- * first `$`-read / `.subscribe()`) and torn down by the returned stop function
777
- * when the last subscriber goes away — so a store that's never read opens no
778
- * socket, and a component that unmounts releases its subscription. Sharing one
779
- * store across several components shares a single underlying subscription
780
- * (the `LunoraClient` de-dupes by `(fn, args, shardKey)`).
781
- *
782
- * Pass `"skip"` as `args` to keep the store connected but the subscription
783
- * dormant (the value stays `undefined`, no socket opens) — useful for a query
784
- * gated on auth or a route param, matching React/Vue/Solid's `useQuery`.
785
- *
786
- * Pass `client` explicitly, or omit it to resolve the ambient client published
787
- * by `setLunoraClient` (which must therefore be called during component init,
788
- * before this runs).
789
- */
764
+ * Open a live query as a Svelte readable store. Read it with the `$store`
765
+ * idiom in a component (`{$messages}`) and it stays current: a WS subscription
766
+ * attaches the moment the store gains its first subscriber and the value
767
+ * re-emits on every server delta — the Svelte equivalent of React's `useQuery`.
768
+ *
769
+ * The subscription is opened lazily (inside `readable`'s start callback, on the
770
+ * first `$`-read / `.subscribe()`) and torn down by the returned stop function
771
+ * when the last subscriber goes away — so a store that's never read opens no
772
+ * socket, and a component that unmounts releases its subscription. Sharing one
773
+ * store across several components shares a single underlying subscription
774
+ * (the `LunoraClient` de-dupes by `(fn, args, shardKey)`).
775
+ *
776
+ * Pass `"skip"` as `args` to keep the store connected but the subscription
777
+ * dormant (the value stays `undefined`, no socket opens) — useful for a query
778
+ * gated on auth or a route param, matching React/Vue/Solid's `useQuery`.
779
+ *
780
+ * Pass `client` explicitly, or omit it to resolve the ambient client published
781
+ * by `setLunoraClient` (which must therefore be called during component init,
782
+ * before this runs).
783
+ */
790
784
  declare function query<F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: QueryStoreOptions): QueryStore<F>;
791
785
  declare function query<F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F> | "skip", options?: QueryStoreOptions): QueryStore<F>;
792
786
  interface RateLimitOptions {
793
787
  /** Clock injection for tests. Defaults to `Date.now`. */
794
788
  now?: () => number;
795
789
  /**
796
- * Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
797
- * ticks down and `disabled` flips back automatically. Defaults to `1000`.
798
- */
790
+ * Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
791
+ * ticks down and `disabled` flips back automatically. Defaults to `1000`.
792
+ */
799
793
  tickMs?: number;
800
794
  }
801
795
  interface RateLimitHandle {
@@ -815,16 +809,16 @@ interface RateLimitHandle {
815
809
  teardown: () => void;
816
810
  }
817
811
  /**
818
- * Client-side mirror of a rate limit for instant UX — disable a button or show
819
- * a countdown without a round-trip. It runs the same token-bucket / fixed-window
820
- * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
821
- * authoritative check; the server remains the source of truth.
822
- *
823
- * `config` is read on every call; pass a stable reference (module constant).
824
- *
825
- * Call `teardown()` when the component is destroyed to stop the auto-tick
826
- * interval (`onDestroy(handle.teardown)`).
827
- */
812
+ * Client-side mirror of a rate limit for instant UX — disable a button or show
813
+ * a countdown without a round-trip. It runs the same token-bucket / fixed-window
814
+ * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
815
+ * authoritative check; the server remains the source of truth.
816
+ *
817
+ * `config` is read on every call; pass a stable reference (module constant).
818
+ *
819
+ * Call `teardown()` when the component is destroyed to stop the auto-tick
820
+ * interval (`onDestroy(handle.teardown)`).
821
+ */
828
822
  declare const rateLimit: (config: RateLimitConfig, options?: RateLimitOptions) => RateLimitHandle;
829
823
  /** The lifecycle of a stream the store is observing. */
830
824
  type StreamStatus = "complete" | "error" | "idle" | "streaming";
@@ -843,27 +837,27 @@ interface StreamHandle<T> {
843
837
  /** Svelte readable store of the stream lifecycle status. */
844
838
  status: Readable<StreamStatus>;
845
839
  /**
846
- * Stop the stream and release the iterator. Call in `onDestroy`
847
- * (`onDestroy(handle.teardown)`) when you consume `chunks` eagerly; when you
848
- * read `chunks` with `$` the store tears itself down as the last subscriber
849
- * leaves.
850
- */
840
+ * Stop the stream and release the iterator. Call in `onDestroy`
841
+ * (`onDestroy(handle.teardown)`) when you consume `chunks` eagerly; when you
842
+ * read `chunks` with `$` the store tears itself down as the last subscriber
843
+ * leaves.
844
+ */
851
845
  teardown: () => void;
852
846
  }
853
847
  /**
854
- * Open a streaming query and expose its chunks, lifecycle status, and last error
855
- * as Svelte readable stores. The `chunks` store is lazy: the stream opens on the
856
- * first subscriber to `chunks` and is cancelled when the last one leaves (its
857
- * chunks reset on the next open). `status` and `error` mirror that same stream.
858
- *
859
- * Passing `"skip"` as `args` keeps the stores connected but the stream dormant
860
- * (`chunks` stays empty, `status` stays `"idle"`). The Svelte counterpart to
861
- * React's `useStream`, re-expressed as stores you read with `$`.
862
- *
863
- * Pass an explicit `client` as the first argument to bypass the ambient context
864
- * (useful in tests), or omit it to resolve the client published by
865
- * `setLunoraClient`.
866
- */
848
+ * Open a streaming query and expose its chunks, lifecycle status, and last error
849
+ * as Svelte readable stores. The `chunks` store is lazy: the stream opens on the
850
+ * first subscriber to `chunks` and is cancelled when the last one leaves (its
851
+ * chunks reset on the next open). `status` and `error` mirror that same stream.
852
+ *
853
+ * Passing `"skip"` as `args` keeps the stores connected but the stream dormant
854
+ * (`chunks` stays empty, `status` stays `"idle"`). The Svelte counterpart to
855
+ * React's `useStream`, re-expressed as stores you read with `$`.
856
+ *
857
+ * Pass an explicit `client` as the first argument to bypass the ambient context
858
+ * (useful in tests), or omit it to resolve the client published by
859
+ * `setLunoraClient`.
860
+ */
867
861
  declare function stream<F extends FunctionReference<"stream">>(function_: F, args: ArgsOf<F> | "skip", options?: StreamStoreOptions): StreamHandle<ReturnOf<F>>;
868
862
  declare function stream<F extends FunctionReference<"stream">>(client: LunoraClient, function_: F, args: ArgsOf<F> | "skip", options?: StreamStoreOptions): StreamHandle<ReturnOf<F>>;
869
863
  interface SubscriptionStoreOptions {
@@ -877,31 +871,31 @@ interface SubscriptionHandle<T> {
877
871
  error: Readable<Error | undefined>;
878
872
  }
879
873
  /**
880
- * Create a pair of Svelte readable stores that open a live subscription
881
- * against the Lunora backend. `data` updates on every server push; `error`
882
- * captures the last subscription error. Both stores are lazy: the subscription
883
- * opens on the first subscriber to `data` and tears down when it stops.
884
- *
885
- * Passing `"skip"` as `args` keeps the stores connected but the subscription
886
- * dormant (`data` stays `undefined`). Pass an explicit `client` as the first
887
- * argument to bypass the ambient context (useful in tests).
888
- */
874
+ * Create a pair of Svelte readable stores that open a live subscription
875
+ * against the Lunora backend. `data` updates on every server push; `error`
876
+ * captures the last subscription error. Both stores are lazy: the subscription
877
+ * opens on the first subscriber to `data` and tears down when it stops.
878
+ *
879
+ * Passing `"skip"` as `args` keeps the stores connected but the subscription
880
+ * dormant (`data` stays `undefined`). Pass an explicit `client` as the first
881
+ * argument to bypass the ambient context (useful in tests).
882
+ */
889
883
  declare function subscription<F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
890
884
  declare function subscription<F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F> | "skip", options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
891
885
  /**
892
- * Browser Web Audio subsystems for `useVoiceAgent` — the default microphone
893
- * capture and speaker playback implementations injected into the composable via
894
- * its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
895
- * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
896
- * composable's transport + reactive-state logic and remains mockable in a
897
- * non-browser test env.
898
- */
886
+ * Browser Web Audio subsystems for `useVoiceAgent` — the default microphone
887
+ * capture and speaker playback implementations injected into the composable via
888
+ * its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
889
+ * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
890
+ * composable's transport + reactive-state logic and remains mockable in a
891
+ * non-browser test env.
892
+ */
899
893
  /**
900
- * The negotiated audio format the voice DO streams back. Mirrors
901
- * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
902
- * imported) so this Svelte package never pulls in the server-only `@lunora/agent`
903
- * module graph.
904
- */
894
+ * The negotiated audio format the voice DO streams back. Mirrors
895
+ * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
896
+ * imported) so this Svelte package never pulls in the server-only `@lunora/agent`
897
+ * module graph.
898
+ */
905
899
  type VoiceAudioFormat = "mp3" | "wav";
906
900
  /** Captures microphone audio and reports level / turn boundaries back to the composable. */
907
901
  interface VoiceMicrophone {
@@ -945,15 +939,10 @@ type CreateSpeaker = (config: {
945
939
  audioFormat: VoiceAudioFormat;
946
940
  }) => VoiceSpeaker;
947
941
  /**
948
- * The default browser microphone: `getUserMedia` a Web Audio `ScriptProcessor`
949
- * that tees 16 kHz PCM frames, tracks input RMS, auto-commits an utterance after
950
- * a silence gap, and flags a barge-in while the agent is speaking.
951
- */
952
- /**
953
- * The `agents.&lt;name>Voice` reference codegen emits for a voice-enabled agent — a
954
- * live, WS-backed session keyed by `threadKey`. A structural subset of the
955
- * generated member, so passing `api.agents.&lt;name>Voice` type-checks.
956
- */
942
+ * The `agents.&lt;name>Voice` reference codegen emits for a voice-enabled agent — a
943
+ * live, WS-backed session keyed by `threadKey`. A structural subset of the
944
+ * generated member, so passing `api.agents.&lt;name>Voice` type-checks.
945
+ */
957
946
  type VoiceReference = FunctionReference<"stream", {
958
947
  threadKey: string;
959
948
  }, Record<string, unknown>>;
@@ -975,10 +964,10 @@ interface VoiceSocket {
975
964
  type CreateSocket = (url: string) => VoiceSocket;
976
965
  interface VoiceAgentOptions {
977
966
  /**
978
- * Advanced/test seam: build the microphone capture subsystem. Defaults to a
979
- * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
980
- * Audio graph stays isolated (and mockable in a non-browser test env).
981
- */
967
+ * Advanced/test seam: build the microphone capture subsystem. Defaults to a
968
+ * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
969
+ * Audio graph stays isolated (and mockable in a non-browser test env).
970
+ */
982
971
  createMicrophone?: CreateMicrophone;
983
972
  /** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
984
973
  createSocket?: CreateSocket;
@@ -1022,29 +1011,29 @@ interface VoiceAgentHandle {
1022
1011
  transcript: Readable<string>;
1023
1012
  }
1024
1013
  /**
1025
- * A first-class voice-call surface for a voice-enabled agent: it opens a
1026
- * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1027
- * streams the agent's synthesized speech back through the browser's audio output,
1028
- * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1029
- * `audioLevel`) to Svelte readable stores you read with `$`. Pass the generated
1030
- * `api.agents.&lt;name>Voice` reference (never a string), matching `agentChat`'s
1031
- * reference-passing style. The Svelte counterpart to React's `useVoiceAgent`,
1032
- * re-expressed as stores; the per-call connection lives in a closure variable (a
1033
- * handle is created once per component, so no store-of-store indirection is
1034
- * needed).
1035
- *
1036
- * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
1037
- * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
1038
- * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
1039
- * `createSocket`) so the handle is drivable outside a browser.
1040
- *
1041
- * There is no auto-dispose in Svelte — call `endCall` in `onDestroy`
1042
- * (`onDestroy(handle.endCall)`) to tear the call down if the component unmounts
1043
- * mid-call.
1044
- *
1045
- * Pass `client` explicitly, or omit it to resolve the ambient client published by
1046
- * `setLunoraClient`.
1047
- */
1014
+ * A first-class voice-call surface for a voice-enabled agent: it opens a
1015
+ * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1016
+ * streams the agent's synthesized speech back through the browser's audio output,
1017
+ * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1018
+ * `audioLevel`) to Svelte readable stores you read with `$`. Pass the generated
1019
+ * `api.agents.&lt;name>Voice` reference (never a string), matching `agentChat`'s
1020
+ * reference-passing style. The Svelte counterpart to React's `useVoiceAgent`,
1021
+ * re-expressed as stores; the per-call connection lives in a closure variable (a
1022
+ * handle is created once per component, so no store-of-store indirection is
1023
+ * needed).
1024
+ *
1025
+ * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
1026
+ * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
1027
+ * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
1028
+ * `createSocket`) so the handle is drivable outside a browser.
1029
+ *
1030
+ * There is no auto-dispose in Svelte — call `endCall` in `onDestroy`
1031
+ * (`onDestroy(handle.endCall)`) to tear the call down if the component unmounts
1032
+ * mid-call.
1033
+ *
1034
+ * Pass `client` explicitly, or omit it to resolve the ambient client published by
1035
+ * `setLunoraClient`.
1036
+ */
1048
1037
  declare function voiceAgent(options: VoiceAgentOptions): VoiceAgentHandle;
1049
1038
  declare function voiceAgent(client: LunoraClient, options: VoiceAgentOptions): VoiceAgentHandle;
1050
1039
  export { type AgentApi, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, connectionStatus, flag, flags, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, mutator, paginatedQuery, presence, query, rateLimit, setLunoraClient, stream, subscription, voiceAgent };