@lunora/angular 1.0.0-alpha.4 → 1.0.0-alpha.41

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 (43) hide show
  1. package/README.md +27 -0
  2. package/dist/index.d.mts +1214 -279
  3. package/dist/index.d.ts +1214 -279
  4. package/dist/index.mjs +1 -13
  5. package/dist/packem_shared/LUNORA_CLIENT-B0toApHY.mjs +1 -0
  6. package/dist/packem_shared/agent-BPvUvuXh.mjs +1 -0
  7. package/dist/packem_shared/agentChat-BgD9zNFw.mjs +1 -0
  8. package/dist/packem_shared/agentState-BBAruY2b.mjs +1 -0
  9. package/dist/packem_shared/agentToolEvents-CUwrn-Nu.mjs +1 -0
  10. package/dist/packem_shared/auth-BgwruT_M.mjs +1 -0
  11. package/dist/packem_shared/connectionStatus-UhmuwzMa.mjs +1 -0
  12. package/dist/packem_shared/flag-orUoJY7A.mjs +1 -0
  13. package/dist/packem_shared/hydratePreloaded-C8lNoww0.mjs +1 -0
  14. package/dist/packem_shared/infiniteQuery-CIprZdJt.mjs +1 -0
  15. package/dist/packem_shared/liveQuery-BvA2co81.mjs +1 -0
  16. package/dist/packem_shared/mutate-BZvLQLyu.mjs +1 -0
  17. package/dist/packem_shared/mutator-DjG1yGk8.mjs +1 -0
  18. package/dist/packem_shared/platform-I2VyCEIl.mjs +1 -0
  19. package/dist/packem_shared/presence-vJUxsR5f.mjs +1 -0
  20. package/dist/packem_shared/rateLimit-B3h9qzh-.mjs +1 -0
  21. package/dist/packem_shared/runAction-BfiPq4Xz.mjs +1 -0
  22. package/dist/packem_shared/stream-CcjYdpzt.mjs +1 -0
  23. package/dist/packem_shared/subscription-DqtYnats.mjs +1 -0
  24. package/dist/packem_shared/voiceAgent-CzyUcUKj.mjs +1 -0
  25. package/dist/server.d.mts +1 -0
  26. package/dist/server.d.ts +1 -0
  27. package/dist/server.mjs +1 -0
  28. package/dist/upload.d.mts +57 -0
  29. package/dist/upload.d.ts +57 -0
  30. package/dist/upload.mjs +1 -0
  31. package/package.json +12 -3
  32. package/dist/packem_shared/LUNORA_CLIENT-DHUfNu9x.mjs +0 -23
  33. package/dist/packem_shared/auth-Df9N87Z4.mjs +0 -27
  34. package/dist/packem_shared/connectionStatus-BlLodleK.mjs +0 -15
  35. package/dist/packem_shared/flag-CGBo90HJ.mjs +0 -70
  36. package/dist/packem_shared/hydratePreloaded-ClRc-7rL.mjs +0 -29
  37. package/dist/packem_shared/infiniteQuery-DUV60k-n.mjs +0 -200
  38. package/dist/packem_shared/liveQuery-D5VQBOgf.mjs +0 -28
  39. package/dist/packem_shared/mutate-D3rEHwbb.mjs +0 -8
  40. package/dist/packem_shared/mutator-BHL8bakL.mjs +0 -19
  41. package/dist/packem_shared/presence-h2xonCZM.mjs +0 -59
  42. package/dist/packem_shared/rateLimit-CKcAig4M.mjs +0 -60
  43. package/dist/packem_shared/subscription-Dd9dQiBB.mjs +0 -37
package/dist/index.d.mts CHANGED
@@ -1,15 +1,504 @@
1
- import { DestroyRef, Signal, InjectionToken, EnvironmentProviders } from '@angular/core';
2
- import { LunoraClient, User, LunoraClientOptions, ConnectionStatus, SubscriptionError, Preloaded, FunctionReference, ArgsOf, ReturnOf, MutationCallOptions, MutatorHandle } from '@lunora/client';
3
- export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, LunoraClientOptions, MutationCallOptions, ReturnOf, SubscriptionError, Unsubscribe } from '@lunora/client';
1
+ import { DestroyRef, Signal, InjectionToken, EnvironmentProviders, Injector } from '@angular/core';
2
+ import { FunctionReference, LunoraClient, SubscriptionError, User, LunoraClientOptions, ConnectionStatus, Preloaded, ArgsOf, ReturnOf, MutationCallOptions, MutatorHandle, ActionCallOptions } from '@lunora/client';
3
+ export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, LunoraClientOptions, MutationCallOptions, Preloaded, ReturnOf, SubscriptionError, Unsubscribe } from '@lunora/client';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
5
5
  import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
6
6
  export { SKIP } from '@lunora/client/query';
7
+ /**
8
+ * The lifecycle status stored on an agent thread. Client-safe mirror of
9
+ * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
10
+ * so this Angular entry never pulls in the server-only `@lunora/agent` module graph
11
+ * (the adapter stays Angular + `@lunora/client` only). Keep in sync with
12
+ * `packages/agent/src/types.ts`.
13
+ * @experimental
14
+ */
15
+ type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "running";
16
+ /**
17
+ * The live thread record surfaced by the `agents:agentThread` query. A structural
18
+ * subset of the persisted thread row — every field beyond `status` is optional so
19
+ * the shape stays forgiving as the server schema grows. Keep in sync with the
20
+ * `agent_threads` table in `packages/agent/src/component.ts`.
21
+ * @experimental
22
+ */
23
+ interface AgentThreadRecord {
24
+ createdAt?: number;
25
+ /** The failure message when `status === "error"`. */
26
+ error?: string;
27
+ /** The workflow instance id of the in-flight run — the handle `cancel` targets. */
28
+ instanceId?: string;
29
+ messageCount?: number;
30
+ /** The verified thread owner, when the run was started with one. */
31
+ owner?: string;
32
+ status: AgentThreadStatus;
33
+ title?: string;
34
+ updatedAt?: number;
35
+ }
36
+ /**
37
+ * One persisted (or optimistic) thread message, as `agents:agentMessages`
38
+ * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
39
+ * re-declared here (rather than imported) so this Angular entry never pulls in the
40
+ * server-only `@lunora/agent` module graph. Keep in sync with the
41
+ * `agent_messages` table in `packages/agent/src/component.ts`.
42
+ * @experimental
43
+ */
44
+ interface AgentChatMessage {
45
+ content: string;
46
+ createdAt?: number;
47
+ /**
48
+ * `true` for a client-side optimistic user message not yet acknowledged by
49
+ * the server. Cleared once the durable history carries the matching user turn.
50
+ */
51
+ optimistic?: boolean;
52
+ role: "assistant" | "system" | "tool" | "user";
53
+ seq: number;
54
+ /** Approval lifecycle marker on a human-in-the-loop tool message. */
55
+ status?: "approved" | "awaiting_approval" | "rejected";
56
+ toolCallId?: string;
57
+ toolCalls?: ReadonlyArray<{
58
+ id: string;
59
+ input: unknown;
60
+ name: string;
61
+ }>;
62
+ toolName?: string;
63
+ }
64
+ /**
65
+ * A live token delta streamed while a turn is generating. Client-safe mirror of
66
+ * `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed the chat surface's
67
+ * streaming text live and are never replayed; the persisted assistant message
68
+ * stays the single source of truth.
69
+ * @experimental
70
+ */
71
+ interface AgentTokenDelta {
72
+ /** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
73
+ kind?: "token";
74
+ /** The incremental text chunk the model just produced. */
75
+ text: string;
76
+ /** The thread this delta belongs to. */
77
+ threadKey: string;
78
+ /** The zero-based index of the turn producing the delta. */
79
+ turn: number;
80
+ }
81
+ /**
82
+ * A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
83
+ * mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
84
+ * surfaced by `agentToolEvents`, ignored by the chat surface's streaming text.
85
+ * @experimental
86
+ */
87
+ interface AgentProgressEvent {
88
+ /** The arbitrary, JSON-serializable payload the tool reported. */
89
+ data: unknown;
90
+ /** Discriminates the progress arm of {@link AgentLiveEvent}. */
91
+ kind: "progress";
92
+ /** The thread this event belongs to. */
93
+ threadKey: string;
94
+ /** The tool call this progress belongs to. */
95
+ toolCallId: string;
96
+ }
97
+ /**
98
+ * A single event on the agent's live-only channel — a streamed token delta or a
99
+ * tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
100
+ * Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
101
+ * it unset).
102
+ * @experimental
103
+ */
104
+ type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
105
+ /**
106
+ * The `agents.agentThread` reference the primitive subscribes to for live thread
107
+ * state (status + the in-flight `instanceId`). A structural subset of the
108
+ * generated `api.agents` surface, so the whole generated `api` object is
109
+ * assignable.
110
+ * @experimental
111
+ */
112
+ interface AgentApi {
113
+ agents: {
114
+ agentThread: FunctionReference<"query", {
115
+ key: string;
116
+ }, Record<string, unknown> | undefined>;
117
+ };
118
+ }
119
+ /**
120
+ * `AgentOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
121
+ * @experimental
122
+ */
123
+ interface AgentOptions {
124
+ /** The generated `api` — its `agents.agentThread` query drives live thread state. */
125
+ api: AgentApi;
126
+ /**
127
+ * Optional app mutation over the agent's cancel path
128
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
129
+ * When omitted (or no run is in flight) {@link AgentResult.cancel} is a no-op.
130
+ */
131
+ cancel?: FunctionReference<"mutation">;
132
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
133
+ client?: LunoraClient;
134
+ /**
135
+ * `DestroyRef` whose `onDestroy` tears the live subscription down. Defaults to
136
+ * `inject(DestroyRef)` — the calling component/service.
137
+ */
138
+ destroyRef?: DestroyRef;
139
+ /**
140
+ * The app mutation that starts (or continues) a run — a thin wrapper over
141
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
142
+ * {@link AgentOptions.runArgs} and the per-call args.
143
+ */
144
+ run: FunctionReference<"mutation">;
145
+ /** Extra args merged into every `run` call (e.g. an `owner` or `title`). */
146
+ runArgs?: Record<string, unknown>;
147
+ /** The thread to observe and drive. */
148
+ threadKey: string;
149
+ }
150
+ /**
151
+ * `AgentResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
152
+ * @experimental
153
+ */
154
+ interface AgentResult {
155
+ /**
156
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
157
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
158
+ */
159
+ cancel: () => Promise<void>;
160
+ /** `true` while a `run` invocation is in flight. */
161
+ pending: Signal<boolean>;
162
+ /** Start (or continue) a run with a user message; extra args merge over `runArgs`. */
163
+ run: (input: string, args?: Record<string, unknown>) => Promise<void>;
164
+ /** The live thread status, or `undefined` before the thread exists. */
165
+ status: Signal<AgentThreadStatus | undefined>;
166
+ /** The live thread record (status, `instanceId`, …), or `undefined` before it exists. */
167
+ thread: Signal<AgentThreadRecord | undefined>;
168
+ }
169
+ /**
170
+ * A thin agent handle: live thread `status` plus `run` / `cancel`, without the
171
+ * chat message surface. Composes `subscription(api.agents.agentThread)` for live
172
+ * state and drives the run/cancel writes straight on the client — the Angular
173
+ * counterpart to React's `useAgent`, re-expressed with signals. For the full
174
+ * conversation surface (durable history + streaming + approvals) use `agentChat`.
175
+ *
176
+ * `run` and `cancel` stay generic over the app-defined mutations that wrap
177
+ * `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
178
+ * names beyond the `agents:*` surface.
179
+ *
180
+ * Call from an injection context (component/service field or constructor); pass an
181
+ * explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
182
+ * @experimental
183
+ */
184
+ declare const agent: (options: AgentOptions) => AgentResult;
185
+ /** The `agents:agentMessages` reference — live durable thread history. */
186
+ type AgentMessagesReference$1 = FunctionReference<"query", {
187
+ key: string;
188
+ limit?: number;
189
+ }, ReadonlyArray<Record<string, unknown>>>;
190
+ /** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
191
+ type AgentApprovalReference = FunctionReference<"mutation", {
192
+ decision: "approve" | "reject";
193
+ instanceId: string;
194
+ note?: string;
195
+ threadKey: string;
196
+ toolCallId: string;
197
+ }, {
198
+ resolved: boolean;
199
+ }>;
200
+ /** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
201
+ type AgentThreadReference = FunctionReference<"query", {
202
+ key: string;
203
+ }, Record<string, unknown> | undefined>;
204
+ /**
205
+ * An app stream reference that tees the agent's in-flight live events, keyed by
206
+ * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
207
+ * sink — tool progress events; this primitive consumes only the token arm.
208
+ * @experimental
209
+ */
210
+ type AgentTokenStreamReference = FunctionReference<"stream", {
211
+ key: string;
212
+ }, AgentLiveEvent>;
213
+ /**
214
+ * The `agents.*` reference surface the chat primitive reads. A structural subset
215
+ * of the generated `api.agents`, so the whole generated `api` object is
216
+ * assignable.
217
+ * @experimental
218
+ */
219
+ interface AgentChatApi {
220
+ agents: {
221
+ agentMessages: AgentMessagesReference$1;
222
+ agentResolveApproval: AgentApprovalReference;
223
+ agentThread: AgentThreadReference;
224
+ };
225
+ }
226
+ /**
227
+ * `AgentChatOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
228
+ * @experimental
229
+ */
230
+ interface AgentChatOptions {
231
+ /** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
232
+ api: AgentChatApi;
233
+ /**
234
+ * Optional app mutation over the agent's cancel path
235
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
236
+ * When omitted (or no run is in flight) {@link AgentChatResult.cancel} is a
237
+ * no-op.
238
+ */
239
+ cancel?: FunctionReference<"mutation">;
240
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
241
+ client?: LunoraClient;
242
+ /**
243
+ * `DestroyRef` whose `onDestroy` tears the subscriptions + stream down. Defaults
244
+ * to `inject(DestroyRef)` — the calling component/service.
245
+ */
246
+ destroyRef?: DestroyRef;
247
+ /** History depth forwarded to `agents:agentMessages`. */
248
+ limit?: number;
249
+ /**
250
+ * The app mutation that starts (or continues) a run — a thin wrapper over
251
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
252
+ * {@link AgentChatOptions.sendArgs} and the per-call args.
253
+ */
254
+ send: FunctionReference<"mutation">;
255
+ /** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
256
+ sendArgs?: Record<string, unknown>;
257
+ /**
258
+ * Optional live token-delta stream — an app stream function that tees the
259
+ * agent's in-flight deltas. When omitted {@link AgentChatResult.streamingText}
260
+ * stays empty and the UI updates message-by-message from durable history.
261
+ */
262
+ stream?: AgentTokenStreamReference;
263
+ /** The thread to observe and continue. */
264
+ threadKey: string;
265
+ }
266
+ /**
267
+ * `AgentChatResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
268
+ * @experimental
269
+ */
270
+ interface AgentChatResult {
271
+ /** Approve a paused human-in-the-loop tool call (optionally with a note). */
272
+ approve: (toolCallId: string, note?: string) => Promise<void>;
273
+ /**
274
+ * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
275
+ * no-op when no `cancel` mutation was supplied or no run is in flight.
276
+ */
277
+ cancel: () => Promise<void>;
278
+ /** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
279
+ messages: Signal<ReadonlyArray<AgentChatMessage>>;
280
+ /** Reject a paused human-in-the-loop tool call (optionally with a reason). */
281
+ reject: (toolCallId: string, note?: string) => Promise<void>;
282
+ /** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
283
+ send: (input: string, args?: Record<string, unknown>) => Promise<void>;
284
+ /** The live thread status, or `undefined` before the thread exists. */
285
+ status: Signal<AgentThreadStatus | undefined>;
286
+ /** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
287
+ streamingText: Signal<string>;
288
+ }
289
+ /**
290
+ * A first-class agent chat surface: live durable history + in-flight token
291
+ * streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
292
+ * the Angular counterpart to React's `useAgentChat`, re-expressed with signals.
293
+ *
294
+ * It composes the existing primitives rather than adding transport:
295
+ * `subscription(api.agents.agentMessages)` for durable history,
296
+ * `subscription(api.agents.agentThread)` for live status + the in-flight
297
+ * `instanceId`, {@link stream} over an app token stream for in-flight deltas, and
298
+ * the client's own `mutation` for the writes (`api.agents.agentResolveApproval` for
299
+ * approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*` surface
300
+ * is hard-coded — `send`/`cancel`/`stream` stay generic references.
301
+ *
302
+ * A `send` optimistically appends the user turn so it renders immediately; the
303
+ * optimistic row clears once the durable history carries the acknowledged turn.
304
+ * `streamingText` is live-only: it holds the current turn's streamed text and
305
+ * empties as soon as that turn's assistant message lands in `messages` (the
306
+ * persisted message is the source of truth), consistent with the loop's
307
+ * replay-safe, live-only delta design.
308
+ *
309
+ * Call from an injection context (component/service field or constructor); pass an
310
+ * explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
311
+ * @experimental
312
+ */
313
+ declare const agentChat: (options: AgentChatOptions) => AgentChatResult;
314
+ /**
315
+ * The `agents.agentState` reference the primitive subscribes to for the thread's
316
+ * live synced state. A structural subset of the generated `api.agents` surface
317
+ * (like `AgentApi` for `agentThread`), so the whole generated `api` object is
318
+ * assignable. Client-safe: no `@lunora/agent` import — the per-agent state type is
319
+ * mirrored by the primitive's generic `T`, since codegen pins the reference return
320
+ * as an optional record (it never evaluates agent config).
321
+ * @experimental
322
+ */
323
+ interface AgentStateApi {
324
+ agents: {
325
+ agentState: FunctionReference<"query", {
326
+ key: string;
327
+ }, Record<string, unknown> | undefined>;
328
+ };
329
+ }
330
+ /**
331
+ * `AgentStateOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
332
+ * @experimental
333
+ */
334
+ interface AgentStateOptions {
335
+ /** The generated `api` — its `agents.agentState` query drives live thread state. */
336
+ api: AgentStateApi;
337
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
338
+ client?: LunoraClient;
339
+ /**
340
+ * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
341
+ * `inject(DestroyRef)` — the calling component/service.
342
+ */
343
+ destroyRef?: DestroyRef;
344
+ /** The thread whose synced state to observe. */
345
+ threadKey: string;
346
+ }
347
+ /**
348
+ * `AgentStateResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
349
+ * @experimental
350
+ */
351
+ interface AgentStateResult<T> {
352
+ /** The subscription error, if the live channel reported one. */
353
+ error: Signal<SubscriptionError | undefined>;
354
+ /** The live synced state, or `undefined` before it is seeded/first pushed. */
355
+ state: Signal<T | undefined>;
356
+ }
357
+ /**
358
+ * Subscribe to an agent thread's synced state — the `setState`-style value a tool
359
+ * writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
360
+ * thin wrapper over `subscription(api.agents.agentState, { key })`: the server
361
+ * pushes a fresh frame whenever the state changes (the dedicated query's per-socket
362
+ * JSON memo suppresses no-op pushes on unrelated thread writes), so `state` updates
363
+ * only on a real `setState`. The Angular counterpart to React's `useAgentState`,
364
+ * re-expressed with signals.
365
+ *
366
+ * Generic over the app's state shape (`agentState<SupportState>(...)`, itself a
367
+ * record) — the reference is typed as an optional record because codegen cannot see
368
+ * the per-agent state type; the generic casts to `T`. The `extends` bound (not a
369
+ * bare unbounded type parameter) is required: this `.ts` file is parsed JSX-aware by
370
+ * the bundler, where an unbounded type-param arrow is ambiguous with a JSX element.
371
+ *
372
+ * Call from an injection context (component/service field or constructor); pass an
373
+ * explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
374
+ * @experimental
375
+ */
376
+ declare const agentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: AgentStateOptions) => AgentStateResult<T>;
377
+ /** The `agents:agentMessages` reference — live durable thread history. */
378
+ type AgentMessagesReference = FunctionReference<"query", {
379
+ key: string;
380
+ limit?: number;
381
+ }, ReadonlyArray<Record<string, unknown>>>;
382
+ /**
383
+ * An app stream reference that tees the agent's in-flight live events, keyed by
384
+ * thread. Carries token deltas and tool progress events; this primitive consumes
385
+ * only the progress arm (`kind === "progress"`).
386
+ */
387
+ type AgentLiveStreamReference = FunctionReference<"stream", {
388
+ key: string;
389
+ }, AgentLiveEvent>;
390
+ /**
391
+ * The `agents.*` reference surface the tool-events primitive reads. A structural
392
+ * subset of the generated `api.agents`, so the whole generated `api` object is
393
+ * assignable.
394
+ * @experimental
395
+ */
396
+ interface AgentToolEventsApi {
397
+ agents: {
398
+ agentMessages: AgentMessagesReference;
399
+ };
400
+ }
401
+ /**
402
+ * `AgentToolEventsOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
403
+ * @experimental
404
+ */
405
+ interface AgentToolEventsOptions {
406
+ /** The generated `api` — its `agents.agentMessages` query provides the durable tool lifecycle. */
407
+ api: AgentToolEventsApi;
408
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
409
+ client?: LunoraClient;
410
+ /**
411
+ * `DestroyRef` whose `onDestroy` tears the subscription + stream down. Defaults
412
+ * to `inject(DestroyRef)` — the calling component/service.
413
+ */
414
+ destroyRef?: DestroyRef;
415
+ /** History depth forwarded to `agents:agentMessages`. */
416
+ limit?: number;
417
+ /**
418
+ * Optional live event stream — the same app stream function `agentChat` uses.
419
+ * When supplied, ephemeral `ctx.reportProgress(...)` events for the thread are
420
+ * surfaced as `{ type: "progress" }` entries; when omitted only the durable
421
+ * lifecycle (call / result / awaiting-approval) is returned.
422
+ */
423
+ stream?: AgentLiveStreamReference;
424
+ /** The thread whose tool activity to observe. */
425
+ threadKey: string;
426
+ }
427
+ /**
428
+ * A single tool-lifecycle event for a thread. The durable arms
429
+ * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
430
+ * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
431
+ * stream and has no `seq`. Discriminate on `type`.
432
+ * @experimental
433
+ */
434
+ type AgentToolEvent = {
435
+ data: unknown;
436
+ toolCallId: string;
437
+ type: "progress";
438
+ } | {
439
+ input: unknown;
440
+ seq: number;
441
+ toolCallId: string;
442
+ toolName: string;
443
+ type: "call";
444
+ } | {
445
+ output: string;
446
+ seq: number;
447
+ status?: "approved" | "rejected";
448
+ toolCallId?: string;
449
+ toolName?: string;
450
+ type: "result";
451
+ } | {
452
+ seq: number;
453
+ toolCallId?: string;
454
+ toolName?: string;
455
+ type: "awaiting-approval";
456
+ };
457
+ /**
458
+ * `AgentToolEventsResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
459
+ * @experimental
460
+ */
461
+ interface AgentToolEventsResult {
462
+ /**
463
+ * The thread's tool events: the durable lifecycle (oldest first, by `seq`)
464
+ * followed by any in-flight ephemeral progress events, recomputed from the live
465
+ * subscription + stream. Treat as derived, not identity-stable.
466
+ */
467
+ events: Signal<ReadonlyArray<AgentToolEvent>>;
468
+ }
469
+ /**
470
+ * A focused view of a thread's tool activity: tool calls, their results,
471
+ * human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
472
+ * without the full chat message surface. The Angular counterpart to React's
473
+ * `useAgentToolEvents`, re-expressed as a `computed` signal.
474
+ *
475
+ * It composes the existing primitives rather than adding transport:
476
+ * `subscription(api.agents.agentMessages)` for the durable lifecycle and
477
+ * {@link stream} over the optional app event stream for ephemeral progress.
478
+ * Progress events are live-only (the durable path never emits them): they ride the
479
+ * same sink as token deltas and are surfaced here, correlated to their tool call by
480
+ * `toolCallId`. For the conversational surface (messages + streaming text +
481
+ * approvals) use `agentChat`; this primitive is the tool-observability slice.
482
+ *
483
+ * Call from an injection context (component/service field or constructor); pass an
484
+ * explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
485
+ * @experimental
486
+ */
487
+ declare const agentToolEvents: (options: AgentToolEventsOptions) => AgentToolEventsResult;
488
+ /**
489
+ * `AuthOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
490
+ * @experimental
491
+ */
7
492
  interface AuthOptions {
8
493
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
9
494
  client?: LunoraClient;
10
495
  /** `DestroyRef` whose `onDestroy` removes the listeners. Defaults to `inject(DestroyRef)`. */
11
496
  destroyRef?: DestroyRef;
12
497
  }
498
+ /**
499
+ * `AuthResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
500
+ * @experimental
501
+ */
13
502
  interface AuthResult {
14
503
  /** Set the auth token (sign-in / sign-out). */
15
504
  setToken: (token: string | null) => void;
@@ -19,71 +508,106 @@ interface AuthResult {
19
508
  user: Signal<User | null>;
20
509
  }
21
510
  /**
22
- * Token + identity plumbing for Angular. `token` is a signal tracking the
23
- * client's auth token; `user` is a signal resolved from `getCurrentUser()`
24
- * whenever the token changes. `setToken(jwt)` after sign-in makes subsequent
25
- * RPC calls carry the `Authorization` header.
26
- *
27
- * Multiple `auth` instances on the same client share a single per-client
28
- * identity store (from `@lunora/client/auth`) — a `setToken` from one component
29
- * re-renders every watcher with the freshly-resolved user.
30
- *
31
- * Call from an injection context (component/service field or constructor):
32
- * ```ts
33
- * const { token, user, setToken } = auth();
34
- * ```
35
- */
511
+ * Token + identity plumbing for Angular. `token` is a signal tracking the
512
+ * client's auth token; `user` is a signal resolved from `getCurrentUser()`
513
+ * whenever the token changes. `setToken(jwt)` after sign-in makes subsequent
514
+ * RPC calls carry the `Authorization` header.
515
+ *
516
+ * Multiple `auth` instances on the same client share a single per-client
517
+ * identity store (from `@lunora/client/auth`) — a `setToken` from one component
518
+ * re-renders every watcher with the freshly-resolved user.
519
+ *
520
+ * Call from an injection context (component/service field or constructor):
521
+ * ```ts
522
+ * const { token, user, setToken } = auth();
523
+ * ```
524
+ * @experimental
525
+ */
36
526
  declare const auth: (options?: AuthOptions) => AuthResult;
37
527
  /**
38
- * DI token carrying the framework-neutral {@link LunoraClient}. Every reactive
39
- * primitive in this adapter (`liveQuery`, `mutate`, `connectionStatus`) reads the
40
- * client from here, so a single {@link provideLunora} in the application config
41
- * wires the whole app.
42
- *
43
- * The token has a root-scoped default factory, so it resolves even without
44
- * {@link provideLunora}: it builds one same-origin browser client (which opens
45
- * its WebSocket lazily on the first subscription). Call {@link provideLunora} to
46
- * point it at a remote URL or hand it a pre-built client.
47
- */
528
+ * `AuthGateResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
529
+ * @experimental
530
+ */
531
+ interface AuthGateResult {
532
+ /** `true` once a token is set and the user has resolved. */
533
+ isAuthenticated: Signal<boolean>;
534
+ /** `true` while a token is set but the user hasn't resolved yet. */
535
+ isLoading: Signal<boolean>;
536
+ }
537
+ /**
538
+ * Derived auth-gate signals for template gating (Angular's `\@if` control
539
+ * flow), built on {@link auth}. Angular has no JSX-style `Authenticated` slot
540
+ * component the way React/Vue/Solid do, so this exposes the same three-state
541
+ * logic as two booleans instead: a token with no resolved user yet is
542
+ * `isLoading`; a token with a resolved user is `isAuthenticated`; no token is
543
+ * neither (the signed-out state a template checks for with a plain `\@else`).
544
+ *
545
+ * Call from an injection context (component/service field or constructor):
546
+ * ```ts
547
+ * protected readonly authState = authGate();
548
+ * // template: \@if (authState.isAuthenticated()) { ... } \@else if (authState.isLoading()) { ... }
549
+ * ```
550
+ * @experimental
551
+ */
552
+ declare const authGate: (options?: AuthOptions) => AuthGateResult;
553
+ /**
554
+ * DI token carrying the framework-neutral {@link LunoraClient}. Every reactive
555
+ * primitive in this adapter (`liveQuery`, `mutate`, `connectionStatus`) reads the
556
+ * client from here, so a single {@link provideLunora} in the application config
557
+ * wires the whole app.
558
+ *
559
+ * The token has a root-scoped default factory, so it resolves even without
560
+ * {@link provideLunora}: it builds one same-origin browser client (which opens
561
+ * its WebSocket lazily on the first subscription). Call {@link provideLunora} to
562
+ * point it at a remote URL or hand it a pre-built client.
563
+ * @experimental
564
+ */
48
565
  declare const LUNORA_CLIENT: InjectionToken<LunoraClient>;
49
566
  /**
50
- * Options accepted by {@link provideLunora}. Identical to {@link LunoraClientOptions}
51
- * except `url` is optional — it defaults to the page origin in the browser (and to
52
- * `""` on the server; pass an explicit `url` for SSR data-loading — see
53
- * {@link sameOriginUrl}).
54
- */
567
+ * Options accepted by {@link provideLunora}. Identical to {@link LunoraClientOptions}
568
+ * except `url` is optional — it defaults to the page origin in the browser (and to
569
+ * `""` on the server; pass an explicit `url` for SSR data-loading — see
570
+ * {@link sameOriginUrl}).
571
+ * @experimental
572
+ */
55
573
  type ProvideLunoraOptions = Omit<LunoraClientOptions, "url"> & {
56
574
  url?: string;
57
575
  };
58
576
  /**
59
- * Wire a {@link LunoraClient} into the application injector. Add the result to the
60
- * `providers` array of an Angular application config (or any `EnvironmentProviders`
61
- * consumer):
62
- *
63
- * ```ts
64
- * export const appConfig: ApplicationConfig = {
65
- * providers: [provideLunora({ url: "https://api.example.com" })],
66
- * };
67
- * ```
68
- *
69
- * Pass {@link LunoraClientOptions} to configure a fresh client (URL defaults to
70
- * the page origin), or hand in an already-constructed {@link LunoraClient} to
71
- * share one instance (e.g. a client you also preload against during SSR).
72
- */
577
+ * Wire a {@link LunoraClient} into the application injector. Add the result to the
578
+ * `providers` array of an Angular application config (or any `EnvironmentProviders`
579
+ * consumer):
580
+ *
581
+ * ```ts
582
+ * export const appConfig: ApplicationConfig = {
583
+ * providers: [provideLunora({ url: "https://api.example.com" })],
584
+ * };
585
+ * ```
586
+ *
587
+ * Pass {@link LunoraClientOptions} to configure a fresh client (URL defaults to
588
+ * the page origin), or hand in an already-constructed {@link LunoraClient} to
589
+ * share one instance (e.g. a client you also preload against during SSR).
590
+ * @experimental
591
+ */
73
592
  declare const provideLunora: (optionsOrClient?: LunoraClient | ProvideLunoraOptions) => EnvironmentProviders;
74
593
  /**
75
- * Read the {@link LunoraClient} from the current injector. Call inside an
76
- * injection context (a component/service field initializer or constructor, or a
77
- * `runInInjectionContext` callback). Use it to hold the client for imperative
78
- * calls — e.g. `mutation`/`action` from event handlers, which run outside an
79
- * injection context:
80
- *
81
- * ```ts
82
- * private readonly client = injectLunoraClient();
83
- * send = (text: string) => this.client.mutation(api.messages.send, { text });
84
- * ```
85
- */
594
+ * Read the {@link LunoraClient} from the current injector. Call inside an
595
+ * injection context (a component/service field initializer or constructor, or a
596
+ * `runInInjectionContext` callback). Use it to hold the client for imperative
597
+ * calls — e.g. `mutation`/`action` from event handlers, which run outside an
598
+ * injection context:
599
+ *
600
+ * ```ts
601
+ * private readonly client = injectLunoraClient();
602
+ * send = (text: string) => this.client.mutation(api.messages.send, { text });
603
+ * ```
604
+ * @experimental
605
+ */
86
606
  declare const injectLunoraClient: () => LunoraClient;
607
+ /**
608
+ * `ConnectionStatusOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
609
+ * @experimental
610
+ */
87
611
  interface ConnectionStatusOptions {
88
612
  /** Client to observe. Defaults to the injected `LUNORA_CLIENT`. */
89
613
  client?: LunoraClient;
@@ -91,76 +615,103 @@ interface ConnectionStatusOptions {
91
615
  destroyRef?: DestroyRef;
92
616
  }
93
617
  /**
94
- * A `signal` of the client's aggregate live-socket status across all shard
95
- * connections. Reads the current status synchronously and updates on every
96
- * transition (`idle` → `connecting` → `connected` → `offline`). The Angular
97
- * equivalent of `@lunora/react`'s `useConnectionStatus`.
98
- *
99
- * The listener is removed when the owning `DestroyRef` fires. Call from an
100
- * injection context (component/service field or constructor).
101
- */
618
+ * A `signal` of the client's aggregate live-socket status across all shard
619
+ * connections. Reads the current status synchronously and updates on every
620
+ * transition (`idle` → `connecting` → `connected` → `offline`). The Angular
621
+ * equivalent of `@lunora/react`'s `useConnectionStatus`.
622
+ *
623
+ * The listener is removed when the owning `DestroyRef` fires. Call from an
624
+ * injection context (component/service field or constructor).
625
+ * @experimental
626
+ */
102
627
  declare const connectionStatus: (options?: ConnectionStatusOptions) => Signal<ConnectionStatus>;
103
- /** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
628
+ /**
629
+ * The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags.
630
+ * @experimental
631
+ */
104
632
  type FlagValue = boolean | number | string | Record<string, unknown> | unknown[] | null;
633
+ /**
634
+ * Targeting context bag forwarded to the OpenFeature provider.
635
+ * @experimental
636
+ */
637
+ type FlagContext = Record<string, unknown>;
638
+ /**
639
+ * `FlagOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
640
+ * @experimental
641
+ */
105
642
  interface FlagOptions {
106
643
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
107
644
  client?: LunoraClient;
108
645
  /**
109
- * Per-call targeting context merged on top of the app's default `identify`
110
- * targeting key.
111
- */
112
- context?: Record<string, unknown>;
646
+ * Per-call targeting context merged on top of the app's default `identify`
647
+ * targeting key.
648
+ */
649
+ context?: FlagContext;
113
650
  /** `DestroyRef` whose `onDestroy` tears down the subscription. Defaults to `inject(DestroyRef)`. */
114
651
  destroyRef?: DestroyRef;
115
652
  }
116
653
  /**
117
- * Subscribe to a single feature flag, live over Lunora's WebSocket.
118
- *
119
- * The returned signal holds `defaultValue` until the first evaluation lands, then
120
- * the server's resolved value — re-pushed whenever the provider re-evaluates.
121
- * The flag's kind is inferred from `defaultValue`'s runtime type, so
122
- * `flag("dark", false)` reads a boolean and `flag("hero", "control")` a string.
123
- *
124
- * Evaluation runs through whatever OpenFeature provider the app wired in
125
- * `lunora/flags.ts`; the read never throws — a provider error resolves the
126
- * default (the same fail-open contract as server-side `ctx.flags`).
127
- *
128
- * Call from an injection context:
129
- * ```ts
130
- * readonly darkMode = flag("dark-mode", false);
131
- * ```
132
- */
654
+ * Subscribe to a single feature flag, live over Lunora's WebSocket.
655
+ *
656
+ * The returned signal holds `defaultValue` until the first evaluation lands, then
657
+ * the server's resolved value — re-pushed whenever the provider re-evaluates.
658
+ * The flag's kind is inferred from `defaultValue`'s runtime type, so
659
+ * `flag("dark", false)` reads a boolean and `flag("hero", "control")` a string.
660
+ *
661
+ * Evaluation runs through whatever OpenFeature provider the app wired in
662
+ * `lunora/flags.ts`; the read never throws — a provider error resolves the
663
+ * default (the same fail-open contract as server-side `ctx.flags`).
664
+ *
665
+ * Call from an injection context:
666
+ * ```ts
667
+ * readonly darkMode = flag("dark-mode", false);
668
+ * ```
669
+ * @experimental
670
+ */
133
671
  declare const flag: <T extends FlagValue>(key: string, defaultValue: T, options?: FlagOptions) => Signal<T>;
672
+ /**
673
+ * `FlagsOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
674
+ * @experimental
675
+ */
134
676
  interface FlagsOptions {
135
677
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
136
678
  client?: LunoraClient;
137
679
  /**
138
- * Targeting context shared by every flag in the set, merged on top of the
139
- * app's default `identify` targeting key.
140
- */
141
- context?: Record<string, unknown>;
680
+ * Targeting context shared by every flag in the set, merged on top of the
681
+ * app's default `identify` targeting key.
682
+ */
683
+ context?: FlagContext;
142
684
  /** `DestroyRef` whose `onDestroy` tears down the subscriptions. Defaults to `inject(DestroyRef)`. */
143
685
  destroyRef?: DestroyRef;
144
686
  }
145
687
  /**
146
- * Subscribe to several feature flags at once, live over Lunora's WebSocket.
147
- *
148
- * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
149
- * default, and the returned signal holds the same-shaped record with resolved
150
- * values (the defaults until each evaluation lands).
151
- *
152
- * Call from an injection context:
153
- * ```ts
154
- * readonly features = flags({ "dark-mode": false, "new-editor": false });
155
- * ```
156
- */
688
+ * Subscribe to several feature flags at once, live over Lunora's WebSocket.
689
+ *
690
+ * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
691
+ * default, and the returned signal holds the same-shaped record with resolved
692
+ * values (the defaults until each evaluation lands).
693
+ *
694
+ * Call from an injection context:
695
+ * ```ts
696
+ * readonly features = flags({ "dark-mode": false, "new-editor": false });
697
+ * ```
698
+ * @experimental
699
+ */
157
700
  declare const flags: <T extends Record<string, FlagValue>>(flagDefaults: T, options?: FlagsOptions) => Signal<T>;
701
+ /**
702
+ * `HydratePreloadedOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
703
+ * @experimental
704
+ */
158
705
  interface HydratePreloadedOptions {
159
706
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
160
707
  client?: LunoraClient;
161
708
  /** `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to `inject(DestroyRef)`. */
162
709
  destroyRef?: DestroyRef;
163
710
  }
711
+ /**
712
+ * `HydratePreloadedResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
713
+ * @experimental
714
+ */
164
715
  interface HydratePreloadedResult<T> {
165
716
  /** The latest value pushed by the server. Seeded synchronously from the preloaded value. */
166
717
  data: Signal<T | undefined>;
@@ -168,99 +719,131 @@ interface HydratePreloadedResult<T> {
168
719
  error: Signal<SubscriptionError | undefined>;
169
720
  }
170
721
  /**
171
- * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
172
- * during SSR, then keep it live — the Angular half of the reactive-loader
173
- * handoff.
174
- *
175
- * The returned signal is seeded **synchronously** from `preloaded.value`, so the
176
- * very first read (during hydration) shows the server value: no loading flash,
177
- * no hydration mismatch. After seeding it opens a WebSocket subscription on the
178
- * same `(functionPath, args, shardKey)` the SSR loader used, so every later
179
- * server delta updates the signal exactly like `liveQuery`.
180
- *
181
- * The subscription tears down when the owning `DestroyRef` fires.
182
- *
183
- * Call from an injection context:
184
- * ```ts
185
- * readonly { data, error } = hydratePreloaded(preloadedMessages);
186
- * ```
187
- */
722
+ * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
723
+ * during SSR, then keep it live — the Angular half of the reactive-loader
724
+ * handoff.
725
+ *
726
+ * The returned signal is seeded **synchronously** from `preloaded.value`, so the
727
+ * very first read (during hydration) shows the server value: no loading flash,
728
+ * no hydration mismatch. After seeding it opens a WebSocket subscription on the
729
+ * same `(functionPath, args, shardKey)` the SSR loader used, so every later
730
+ * server delta updates the signal exactly like `liveQuery`.
731
+ *
732
+ * The subscription tears down when the owning `DestroyRef` fires.
733
+ *
734
+ * Call from an injection context:
735
+ * ```ts
736
+ * readonly { data, error } = hydratePreloaded(preloadedMessages);
737
+ * ```
738
+ * @experimental
739
+ */
188
740
  declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, options?: HydratePreloadedOptions) => HydratePreloadedResult<T>;
741
+ /**
742
+ * `LiveQueryOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
743
+ * @experimental
744
+ */
189
745
  interface LiveQueryOptions {
190
746
  /**
191
- * Client to bind to. Defaults to the injected `LUNORA_CLIENT`; pass one
192
- * explicitly to use `liveQuery` outside an injection context (or in a test).
193
- */
747
+ * Client to bind to. Defaults to the injected `LUNORA_CLIENT`; pass one
748
+ * explicitly to use `liveQuery` outside an injection context (or in a test).
749
+ */
194
750
  client?: LunoraClient;
195
751
  /**
196
- * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
197
- * `inject(DestroyRef)` — the calling component/service — so it closes when that
198
- * component is destroyed. Pass one explicitly to control the lifetime yourself.
199
- */
752
+ * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
753
+ * `inject(DestroyRef)` — the calling component/service — so it closes when that
754
+ * component is destroyed. Pass one explicitly to control the lifetime yourself.
755
+ */
200
756
  destroyRef?: DestroyRef;
201
757
  /**
202
- * Called when the subscription errors after the initial attach — the async
203
- * error channel `createQuerySubscription` only wires when a sink is present.
204
- * Without it, a post-attach failure is dropped silently: the signal simply
205
- * stops updating with no error state exposed. Pass a handler to surface it
206
- * (log, toast, set an error signal of your own).
207
- */
758
+ * `Injector` to create the reactive-args `effect()` from. Only needed when
759
+ * `args` is a function/`Signal` AND `liveQuery` is called outside an injection
760
+ * context (an explicit `destroyRef` is also being passed e.g. from
761
+ * `ngOnInit`, or from a test with no `TestBed`) `effect()` cannot resolve an
762
+ * injector on its own there. Defaults to the ambient injection context, the
763
+ * same source `inject(DestroyRef)` already relies on. Unused for the static
764
+ * `args` form, which never creates an `effect()`.
765
+ */
766
+ injector?: Injector;
767
+ /**
768
+ * Called when the subscription errors after the initial attach — the async
769
+ * error channel `createQuerySubscription` only wires when a sink is present.
770
+ * Without it, a post-attach failure is dropped silently: the signal simply
771
+ * stops updating with no error state exposed. Pass a handler to surface it
772
+ * (log, toast, set an error signal of your own).
773
+ */
208
774
  onError?: (error: SubscriptionError) => void;
209
775
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
210
776
  shardKey?: string;
211
777
  }
212
778
  /**
213
- * Subscribe to a server query and mirror its value into an Angular `signal`.
214
- *
215
- * Reads `undefined` until the first server frame lands, then updates on every
216
- * delta the WebSocket pushes. The underlying subscription is torn down
217
- * automatically when the owning `DestroyRef` fires (the component/service is
218
- * destroyed), so there is no leaked socket subscription.
219
- *
220
- * Call it from an injection context (a component/service field initializer or
221
- * constructor) so the default `inject(DestroyRef)` resolves the caller's
222
- * lifetime:
223
- *
224
- * ```ts
225
- * export class MessagesComponent {
226
- * readonly messages = liveQuery(api.messages.list, { channelId: "general" });
227
- * }
228
- * ```
229
- *
230
- * Pass `"skip"` (the `SKIP` sentinel from `@lunora/client/query`) as `args` to
231
- * short-circuit — no network call, no socket; the signal stays `undefined`. To
232
- * call outside an injection context (e.g. lazily in `ngOnInit`), supply `client`
233
- * and `destroyRef` via {@link LiveQueryOptions}.
234
- */
235
- declare const liveQuery: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip", options?: LiveQueryOptions) => Signal<ReturnOf<F> | undefined>;
779
+ * Subscribe to a server query and mirror its value into an Angular `signal`.
780
+ *
781
+ * Reads `undefined` until the first server frame lands, then updates on every
782
+ * delta the WebSocket pushes. The underlying subscription is torn down
783
+ * automatically when the owning `DestroyRef` fires (the component/service is
784
+ * destroyed), so there is no leaked socket subscription.
785
+ *
786
+ * Call it from an injection context (a component/service field initializer or
787
+ * constructor) so the default `inject(DestroyRef)` resolves the caller's
788
+ * lifetime:
789
+ *
790
+ * ```ts
791
+ * export class MessagesComponent {
792
+ * readonly messages = liveQuery(api.messages.list, { channelId: "general" });
793
+ * }
794
+ * ```
795
+ *
796
+ * Pass `"skip"` (the `SKIP` sentinel from `@lunora/client/query`) as `args` to
797
+ * short-circuit — no network call, no socket; the signal stays `undefined`. To
798
+ * call outside an injection context (e.g. lazily in `ngOnInit`), supply `client`
799
+ * and `destroyRef` via {@link LiveQueryOptions}.
800
+ *
801
+ * `args` also accepts a function/`Signal` `() => ({ channelId: channelId() })`
802
+ * — to make the subscription reactive: an args change tears the old
803
+ * subscription down and opens a fresh one for the new args, mirroring
804
+ * `@lunora/solid`'s `createQuery`/`@lunora/vue`'s `useQuery`. A static (plain
805
+ * object) `args` resolves once and never re-runs — no `effect()` is created for
806
+ * it, so it carries none of the reactive form's DI requirement.
807
+ * @experimental
808
+ */
809
+ declare const liveQuery: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip" | (() => ArgsOf<F> | "skip"), options?: LiveQueryOptions) => Signal<ReturnOf<F> | undefined>;
810
+ /**
811
+ * `MutateOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
812
+ * @experimental
813
+ */
236
814
  interface MutateOptions<F extends FunctionReference> extends MutationCallOptions<unknown, unknown, ArgsOf<F>> {
237
815
  /**
238
- * Client to run the mutation on. Defaults to the injected `LUNORA_CLIENT`.
239
- * Because mutations usually fire from event handlers — which run *outside* an
240
- * injection context — capture the client once (`injectLunoraClient()` in a
241
- * field) and pass it here, or call `client.mutation(...)` directly.
242
- */
816
+ * Client to run the mutation on. Defaults to the injected `LUNORA_CLIENT`.
817
+ * Because mutations usually fire from event handlers — which run *outside* an
818
+ * injection context — capture the client once (`injectLunoraClient()` in a
819
+ * field) and pass it here, or call `client.mutation(...)` directly.
820
+ */
243
821
  client?: LunoraClient;
244
822
  }
245
823
  /**
246
- * Run a Lunora mutation and resolve with the server result (rejects on failure).
247
- *
248
- * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
249
- * call options pass straight through to `client.mutation`, which applies and
250
- * rolls them back against the live subscription cache — the same cache
251
- * `liveQuery` reads, so an optimistic write reflects immediately and
252
- * reverts on failure. The client's offline queue also engages when the socket is
253
- * down, so the write stays durable across reconnects.
254
- *
255
- * ```ts
256
- * private readonly client = injectLunoraClient();
257
- * send = (text: string) => mutate(api.messages.send, { text }, { client: this.client });
258
- * ```
259
- *
260
- * When called from within an injection context you may omit `client` and let it
261
- * resolve from the injector.
262
- */
824
+ * Run a Lunora mutation and resolve with the server result (rejects on failure).
825
+ *
826
+ * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
827
+ * call options pass straight through to `client.mutation`, which applies and
828
+ * rolls them back against the live subscription cache — the same cache
829
+ * `liveQuery` reads, so an optimistic write reflects immediately and
830
+ * reverts on failure. The client's offline queue also engages when the socket is
831
+ * down, so the write stays durable across reconnects.
832
+ *
833
+ * ```ts
834
+ * private readonly client = injectLunoraClient();
835
+ * send = (text: string) => mutate(api.messages.send, { text }, { client: this.client });
836
+ * ```
837
+ *
838
+ * When called from within an injection context you may omit `client` and let it
839
+ * resolve from the injector.
840
+ * @experimental
841
+ */
263
842
  declare const mutate: <F extends FunctionReference>(reference: F, args: ArgsOf<F>, options?: MutateOptions<F>) => Promise<ReturnOf<F>>;
843
+ /**
844
+ * `MutatorResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
845
+ * @experimental
846
+ */
264
847
  interface MutatorResult<TArgs> {
265
848
  /** The latest invocation's error, or `undefined`. */
266
849
  error: Signal<Error | undefined>;
@@ -274,22 +857,23 @@ interface MutatorResult<TArgs> {
274
857
  reset: () => void;
275
858
  }
276
859
  /**
277
- * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
278
- * custom-mutator handle from `` `@lunora/db` ``'s `bindMutators` — the Angular
279
- * equivalent of `` `@lunora/react` ``'s `useMutator`. The optimistic overlay and
280
- * server-authoritative push are owned by the bound handle; this function only
281
- * surfaces reactive state for the in-flight/error lifecycle.
282
- *
283
- * `pending` is ref-counted across overlapping invocations of THIS handle, so it
284
- * clears only once every concurrent call has settled.
285
- *
286
- * Does NOT require an injection context — it works with plain signals.
287
- *
288
- * ```ts
289
- * private readonly collection = bindMutators(collections);
290
- * readonly mutator = mutator(this.collection.insert);
291
- * ```
292
- */
860
+ * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
861
+ * custom-mutator handle from `` `@lunora/db` ``'s `bindMutators` — the Angular
862
+ * equivalent of `` `@lunora/react` ``'s `useMutator`. The optimistic overlay and
863
+ * server-authoritative push are owned by the bound handle; this function only
864
+ * surfaces reactive state for the in-flight/error lifecycle.
865
+ *
866
+ * `pending` is ref-counted across overlapping invocations of THIS handle, so it
867
+ * clears only once every concurrent call has settled.
868
+ *
869
+ * Does NOT require an injection context — it works with plain signals.
870
+ *
871
+ * ```ts
872
+ * private readonly collection = bindMutators(collections);
873
+ * readonly mutator = mutator(this.collection.insert);
874
+ * ```
875
+ * @experimental
876
+ */
293
877
  declare const mutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorResult<TArgs>;
294
878
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
295
879
  type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOfRaw<F>, "paginationOpts">;
@@ -299,6 +883,10 @@ type PageItemOf<F extends FunctionReference> = ReturnTypeOf<F> extends {
299
883
  } ? T : unknown;
300
884
  type ArgsOfRaw<F extends FunctionReference> = F extends FunctionReference<"query", infer A> ? A : never;
301
885
  type ReturnTypeOf<F extends FunctionReference> = F extends FunctionReference<"query", unknown, infer R> ? R : never;
886
+ /**
887
+ * Options for the paginated query — part of the experimental `@lunora/angular` API and may change without a major version bump.
888
+ * @experimental
889
+ */
302
890
  interface PaginatedQueryOptions {
303
891
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
304
892
  client?: LunoraClient;
@@ -306,9 +894,20 @@ interface PaginatedQueryOptions {
306
894
  destroyRef?: DestroyRef;
307
895
  /** Page size for the first page (and the default for `loadMore`). */
308
896
  initialNumItems: number;
897
+ /**
898
+ * `Injector` to create the reactive-args `effect()` from. Only needed when
899
+ * `args` is a function/`Signal` AND the call is outside an injection context
900
+ * (an explicit `destroyRef` is also being passed). Defaults to the ambient
901
+ * injection context. Unused for the static `args` form.
902
+ */
903
+ injector?: Injector;
309
904
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
310
905
  shardKey?: string;
311
906
  }
907
+ /**
908
+ * `PaginatedQueryResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
909
+ * @experimental
910
+ */
312
911
  interface PaginatedQueryResult<T> {
313
912
  /** `true` while the first page or a `loadMore` page is in flight. */
314
913
  isLoading: Signal<boolean>;
@@ -319,6 +918,10 @@ interface PaginatedQueryResult<T> {
319
918
  /** The pagination status. */
320
919
  status: Signal<PaginationStatus>;
321
920
  }
921
+ /**
922
+ * `InfiniteQueryResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
923
+ * @experimental
924
+ */
322
925
  interface InfiniteQueryResult<T> {
323
926
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
324
927
  fetchNextPage: (numberItems?: number) => void;
@@ -334,43 +937,64 @@ interface InfiniteQueryResult<T> {
334
937
  status: Signal<PaginationStatus>;
335
938
  }
336
939
  /**
337
- * Subscribe to a reactively-paginated query and grow the feed page by page.
338
- *
339
- * The query function must accept a `paginationOpts: { numItems, cursor,
340
- * endCursor }` arg and return a `PaginationResult`. Pages are tracked as an
341
- * ordered list of stable boundary cursors; each loaded page is a live
342
- * subscription over a FIXED `(lower, upper]` range.
343
- *
344
- * `loadMore` appends the next page off the open-ended tail's `continueCursor`;
345
- * it is a no-op unless `status === "CanLoadMore"`.
346
- *
347
- * Call from an injection context:
348
- * ```ts
349
- * readonly messages = paginatedQuery(api.messages.list, {}, { initialNumItems: 20 });
350
- * ```
351
- */
352
- declare const paginatedQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip", options: PaginatedQueryOptions) => PaginatedQueryResult<PageItemOf<F>>;
353
- /**
354
- * Subscribe to a reactively-paginated query and expose its pages discretely.
355
- *
356
- * Shares `paginatedQuery`'s reactive-pagination engine but keeps each page as
357
- * its own inner array rather than flattening them, and adds the TanStack-Query-
358
- * style `fetchNextPage` / `hasNextPage` / `isFetchingNextPage` shape.
359
- *
360
- * Call from an injection context:
361
- * ```ts
362
- * readonly feed = infiniteQuery(api.messages.list, {}, { initialNumItems: 20 });
363
- * ```
364
- */
365
- declare const infiniteQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip", options: PaginatedQueryOptions) => InfiniteQueryResult<PageItemOf<F>>;
940
+ * Subscribe to a reactively-paginated query and grow the feed page by page.
941
+ *
942
+ * The query function must accept a `paginationOpts: { numItems, cursor,
943
+ * endCursor }` arg and return a `PaginationResult`. Pages are tracked as an
944
+ * ordered list of stable boundary cursors; each loaded page is a live
945
+ * subscription over a FIXED `(lower, upper]` range.
946
+ *
947
+ * `loadMore` appends the next page off the open-ended tail's `continueCursor`;
948
+ * it is a no-op unless `status === "CanLoadMore"`.
949
+ *
950
+ * Call from an injection context:
951
+ * ```ts
952
+ * readonly messages = paginatedQuery(api.messages.list, {}, { initialNumItems: 20 });
953
+ * ```
954
+ *
955
+ * `args` also accepts a function/`Signal` to make the query reactive an args
956
+ * change disposes the current pagination engine and builds a fresh one for the
957
+ * new args. A static (plain object) `args` resolves once and never re-runs.
958
+ * @experimental
959
+ */
960
+ declare const paginatedQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip" | (() => PaginatedArgs<F> | "skip"), options: PaginatedQueryOptions) => PaginatedQueryResult<PageItemOf<F>>;
961
+ /**
962
+ * Subscribe to a reactively-paginated query and expose its pages discretely.
963
+ *
964
+ * Shares `paginatedQuery`'s reactive-pagination engine but keeps each page as
965
+ * its own inner array rather than flattening them, and adds the TanStack-Query-
966
+ * style `fetchNextPage` / `hasNextPage` / `isFetchingNextPage` shape.
967
+ *
968
+ * Call from an injection context:
969
+ * ```ts
970
+ * readonly feed = infiniteQuery(api.messages.list, {}, { initialNumItems: 20 });
971
+ * ```
972
+ *
973
+ * `args` also accepts a function/`Signal` to make the query reactive — see
974
+ * `paginatedQuery`'s equivalent note.
975
+ * @experimental
976
+ */
977
+ declare const infiniteQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip" | (() => PaginatedArgs<F> | "skip"), options: PaginatedQueryOptions) => InfiniteQueryResult<PageItemOf<F>>;
978
+ /**
979
+ * `HeartbeatReference` is part of the experimental `@lunora/angular` API and may change without a major version bump.
980
+ * @experimental
981
+ */
366
982
  type HeartbeatReference = FunctionReference<"mutation", {
367
983
  data?: Record<string, unknown>;
368
984
  roomId: string;
369
985
  sessionId: string;
370
986
  }>;
987
+ /**
988
+ * `ListPresentReference` is part of the experimental `@lunora/angular` API and may change without a major version bump.
989
+ * @experimental
990
+ */
371
991
  type ListPresentReference = FunctionReference<"query", {
372
992
  roomId: string;
373
993
  }>;
994
+ /**
995
+ * `PresenceOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
996
+ * @experimental
997
+ */
374
998
  interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentReference> {
375
999
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
376
1000
  client?: LunoraClient;
@@ -385,13 +1009,17 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
385
1009
  /** The `api.*` reference for the presence listPresent query. */
386
1010
  listPresent: L;
387
1011
  /**
388
- * Stable id for this presence row. Defaults to a fresh per-call id.
389
- * Pass a user/connection id to control deduping across tabs.
390
- */
1012
+ * Stable id for this presence row. Defaults to a fresh per-call id.
1013
+ * Pass a user/connection id to control deduping across tabs.
1014
+ */
391
1015
  sessionId?: string;
392
1016
  /** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
393
1017
  shardKey?: string;
394
1018
  }
1019
+ /**
1020
+ * `PresenceResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1021
+ * @experimental
1022
+ */
395
1023
  interface PresenceResult<L extends ListPresentReference> {
396
1024
  /** The present members for the room. `undefined` until the first push. */
397
1025
  present: Signal<ReturnOf<L> | undefined>;
@@ -401,35 +1029,44 @@ interface PresenceResult<L extends ListPresentReference> {
401
1029
  setData: (data: Record<string, unknown> | undefined) => void;
402
1030
  }
403
1031
  /**
404
- * `presence` — collaborative-awareness primitive, the client half of the
405
- * `@lunora/server` `definePresence` preset.
406
- *
407
- * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
408
- * subscribes to the live `listPresent` query for the given room.
409
- *
410
- * Call from an injection context (component/service field or constructor):
411
- * ```ts
412
- * readonly roomPresence = presence("room:general", {
413
- * heartbeat: api.presence.heartbeat,
414
- * listPresent: api.presence.listPresent,
415
- * });
416
- * ```
417
- */
1032
+ * `presence` — collaborative-awareness primitive, the client half of the
1033
+ * `@lunora/server` `definePresence` preset.
1034
+ *
1035
+ * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
1036
+ * subscribes to the live `listPresent` query for the given room.
1037
+ *
1038
+ * Call from an injection context (component/service field or constructor):
1039
+ * ```ts
1040
+ * readonly roomPresence = presence("room:general", {
1041
+ * heartbeat: api.presence.heartbeat,
1042
+ * listPresent: api.presence.listPresent,
1043
+ * });
1044
+ * ```
1045
+ * @experimental
1046
+ */
418
1047
  declare const presence: <H extends HeartbeatReference, L extends ListPresentReference>(roomId: string, options: PresenceOptions<H, L>) => PresenceResult<L>;
1048
+ /**
1049
+ * `RateLimitOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1050
+ * @experimental
1051
+ */
419
1052
  interface RateLimitOptions {
420
1053
  /**
421
- * `DestroyRef` whose `onDestroy` clears the interval. Defaults to
422
- * `inject(DestroyRef)` — the calling component/service.
423
- */
1054
+ * `DestroyRef` whose `onDestroy` clears the interval. Defaults to
1055
+ * `inject(DestroyRef)` — the calling component/service.
1056
+ */
424
1057
  destroyRef?: DestroyRef;
425
1058
  /** Clock injection for tests. Defaults to `Date.now`. */
426
1059
  now?: () => number;
427
1060
  /**
428
- * Re-render cadence in milliseconds while throttled, so `retryAfter` ticks
429
- * down and `disabled` flips back automatically. Defaults to `1000`.
430
- */
1061
+ * Re-render cadence in milliseconds while throttled, so `retryAfter` ticks
1062
+ * down and `disabled` flips back automatically. Defaults to `1000`.
1063
+ */
431
1064
  tickMs?: number;
432
1065
  }
1066
+ /**
1067
+ * `RateLimitResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1068
+ * @experimental
1069
+ */
433
1070
  interface RateLimitResult {
434
1071
  /** Would consuming `count` (default 1) succeed right now? Does not consume. */
435
1072
  check: (count?: number) => boolean;
@@ -445,35 +1082,143 @@ interface RateLimitResult {
445
1082
  retryAfter: Signal<number>;
446
1083
  }
447
1084
  /**
448
- * Client-side mirror of a rate limit for instant UX — disable a button or show
449
- * a countdown without a round-trip. It runs the same token-bucket / fixed-window
450
- * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
451
- * authoritative check; the server remains the source of truth.
452
- *
453
- * Requires an Angular injection context unless a `DestroyRef` is passed
454
- * explicitly via `options.destroyRef`.
455
- *
456
- * ```ts
457
- * readonly sendLimit = rateLimit({ kind: "token bucket", period: 1000, rate: 10 });
458
- * ```
459
- */
1085
+ * Client-side mirror of a rate limit for instant UX — disable a button or show
1086
+ * a countdown without a round-trip. It runs the same token-bucket / fixed-window
1087
+ * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
1088
+ * authoritative check; the server remains the source of truth.
1089
+ *
1090
+ * Requires an Angular injection context unless a `DestroyRef` is passed
1091
+ * explicitly via `options.destroyRef`.
1092
+ *
1093
+ * ```ts
1094
+ * readonly sendLimit = rateLimit({ kind: "token bucket", period: 1000, rate: 10 });
1095
+ * ```
1096
+ * @experimental
1097
+ */
460
1098
  declare const rateLimit: (config: RateLimitConfig, options?: RateLimitOptions) => RateLimitResult;
1099
+ /**
1100
+ * `RunActionOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1101
+ * @experimental
1102
+ */
1103
+ interface RunActionOptions extends ActionCallOptions {
1104
+ /**
1105
+ * Client to run the action on. Defaults to the injected `LUNORA_CLIENT`.
1106
+ * Because actions usually fire from event handlers — which run *outside* an
1107
+ * injection context — capture the client once (`injectLunoraClient()` in a
1108
+ * field) and pass it here, or call `client.action(...)` directly.
1109
+ */
1110
+ client?: LunoraClient;
1111
+ }
1112
+ /**
1113
+ * Run a Lunora action and resolve with the server result (rejects on failure).
1114
+ *
1115
+ * The sibling of `mutate`, and a plain function for the same reason: Angular's
1116
+ * adapter models writes as calls rather than reactive handles, because they fire
1117
+ * from event handlers where a signal-returning primitive has nothing to bind to.
1118
+ * The other adapters return a reactive `{ call, pending, … }` handle because
1119
+ * their idioms make that natural; this one does not.
1120
+ *
1121
+ * Unlike `mutate` there are no `optimistic` / `optimisticUpdate` options. An
1122
+ * optimistic update patches the subscription cache on the assumption a write
1123
+ * will land; an action is not a write — it runs in the Worker, may call a third
1124
+ * party, and has no declared effect on any query.
1125
+ *
1126
+ * ```ts
1127
+ * private readonly client = injectLunoraClient();
1128
+ * verify = () => runAction(api.commands.run, { command: "lunora", args: ["verify"] }, { client: this.client });
1129
+ * ```
1130
+ *
1131
+ * When called from within an injection context you may omit `client` and let it
1132
+ * resolve from the injector.
1133
+ * @experimental
1134
+ */
1135
+ declare const runAction: <F extends FunctionReference>(reference: F, args: ArgsOf<F>, options?: RunActionOptions) => Promise<ReturnOf<F>>;
1136
+ /**
1137
+ * The lifecycle of a stream the primitive is observing.
1138
+ * @experimental
1139
+ */
1140
+ type StreamStatus = "complete" | "error" | "idle" | "streaming";
1141
+ /**
1142
+ * `StreamOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1143
+ * @experimental
1144
+ */
1145
+ interface StreamOptions {
1146
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
1147
+ client?: LunoraClient;
1148
+ /**
1149
+ * `DestroyRef` whose `onDestroy` cancels the stream. Defaults to
1150
+ * `inject(DestroyRef)` — the calling component/service.
1151
+ */
1152
+ destroyRef?: DestroyRef;
1153
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
1154
+ maxBuffer?: number;
1155
+ /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
1156
+ shardKey?: string;
1157
+ }
1158
+ /**
1159
+ * `StreamResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1160
+ * @experimental
1161
+ */
1162
+ interface StreamResult<T> {
1163
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
1164
+ cancel: () => void;
1165
+ /** Chunks the server has pushed so far, in arrival order. */
1166
+ chunks: Signal<ReadonlyArray<T>>;
1167
+ /** The stream error, or `undefined`. */
1168
+ error: Signal<Error | undefined>;
1169
+ /** The stream lifecycle. */
1170
+ status: Signal<StreamStatus>;
1171
+ }
1172
+ /**
1173
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
1174
+ * lifecycle status and a `cancel` function, all as signals.
1175
+ *
1176
+ * Unlike `subscription`, which tracks the latest value, `stream` accumulates every
1177
+ * chunk the server pushes — use it for token-by-token deltas and other append-only
1178
+ * feeds. Pass `"skip"` as `args` to keep the primitive mounted without opening a
1179
+ * stream (mirrors `subscription`); the stream tears down when the owning
1180
+ * `DestroyRef` fires. The Angular counterpart to React's `useStream`, re-expressed
1181
+ * with signals.
1182
+ *
1183
+ * Call from an injection context (component/service field or constructor):
1184
+ * ```ts
1185
+ * readonly tokens = stream(api.chat.liveEvents, { key: "thread-1" });
1186
+ * ```
1187
+ * @experimental
1188
+ */
1189
+ declare const stream: <F extends FunctionReference<"stream">>(reference: F, args: ArgsOf<F> | "skip", options?: StreamOptions) => StreamResult<ReturnOf<F>>;
1190
+ /**
1191
+ * `SubscriptionOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1192
+ * @experimental
1193
+ */
461
1194
  interface SubscriptionOptions {
462
1195
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
463
1196
  client?: LunoraClient;
464
1197
  /**
465
- * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
466
- * `inject(DestroyRef)` — the calling component/service.
467
- */
1198
+ * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
1199
+ * `inject(DestroyRef)` — the calling component/service.
1200
+ */
468
1201
  destroyRef?: DestroyRef;
469
1202
  /**
470
- * Called when the subscription errors after the initial attach. Without it,
471
- * a post-attach failure is dropped silently.
472
- */
1203
+ * `Injector` to create the reactive-args `effect()` from. Only needed when
1204
+ * `args` is a function/`Signal` AND `subscription` is called outside an
1205
+ * injection context (an explicit `destroyRef` is also being passed).
1206
+ * Defaults to the ambient injection context. Unused for the static `args`
1207
+ * form, which never creates an `effect()`.
1208
+ */
1209
+ injector?: Injector;
1210
+ /**
1211
+ * Called when the subscription errors after the initial attach. Without it,
1212
+ * a post-attach failure is dropped silently.
1213
+ */
473
1214
  onError?: (error: SubscriptionError) => void;
474
1215
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
475
1216
  shardKey?: string;
476
1217
  }
1218
+ /**
1219
+ * `SubscriptionResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1220
+ * @experimental
1221
+ */
477
1222
  interface SubscriptionResult<T> {
478
1223
  /** The latest value pushed by the server. `undefined` before the first frame. */
479
1224
  data: Signal<T | undefined>;
@@ -481,20 +1226,210 @@ interface SubscriptionResult<T> {
481
1226
  error: Signal<SubscriptionError | undefined>;
482
1227
  }
483
1228
  /**
484
- * Subscribe to a reactive server push stream. Returns `{ data, error }` signals
485
- * that update whenever the server emits a new value.
486
- *
487
- * Unlike `liveQuery`, which tracks a single value, `subscription` also
488
- * exposes an `error` signal for the async error channel. Use it for ephemeral,
489
- * high-frequency streams where you need error visibility.
490
- *
491
- * Pass `"skip"` as `args` to short-circuit — no network call, no socket.
492
- * The subscription tears down when the owning `DestroyRef` fires.
493
- *
494
- * Call from an injection context (component/service field or constructor):
495
- * ```ts
496
- * readonly stream = subscription(api.events.stream, { roomId: "general" });
497
- * ```
498
- */
499
- declare const subscription: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip", options?: SubscriptionOptions) => SubscriptionResult<ReturnOf<F>>;
500
- export { type AuthOptions, type AuthResult, type ConnectionStatusOptions, type FlagOptions, type FlagsOptions, type HydratePreloadedOptions, type HydratePreloadedResult, type InfiniteQueryResult, LUNORA_CLIENT, type LiveQueryOptions, type MutateOptions, type MutatorResult, type PaginatedQueryOptions, type PaginatedQueryResult, type PresenceOptions, type PresenceResult, type ProvideLunoraOptions, type RateLimitOptions, type RateLimitResult, type SubscriptionOptions, type SubscriptionResult, auth, connectionStatus, flag, flags, hydratePreloaded, infiniteQuery, injectLunoraClient, liveQuery, mutate, mutator, paginatedQuery, presence, provideLunora, rateLimit, subscription };
1229
+ * Subscribe to a reactive server push stream. Returns `{ data, error }` signals
1230
+ * that update whenever the server emits a new value.
1231
+ *
1232
+ * Unlike `liveQuery`, which tracks a single value, `subscription` also
1233
+ * exposes an `error` signal for the async error channel. Use it for ephemeral,
1234
+ * high-frequency streams where you need error visibility.
1235
+ *
1236
+ * Pass `"skip"` as `args` to short-circuit — no network call, no socket.
1237
+ * The subscription tears down when the owning `DestroyRef` fires.
1238
+ *
1239
+ * Call from an injection context (component/service field or constructor):
1240
+ * ```ts
1241
+ * readonly stream = subscription(api.events.stream, { roomId: "general" });
1242
+ * ```
1243
+ *
1244
+ * `args` also accepts a function/`Signal` to make the subscription reactive
1245
+ * an args change tears the old subscription down and opens a fresh one for the
1246
+ * new args. A static (plain object) `args` resolves once and never re-runs.
1247
+ * @experimental
1248
+ */
1249
+ declare const subscription: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip" | (() => ArgsOf<F> | "skip"), options?: SubscriptionOptions) => SubscriptionResult<ReturnOf<F>>;
1250
+ /**
1251
+ * Browser Web Audio subsystems for `voiceAgent` — the default microphone capture
1252
+ * and speaker playback implementations injected into the primitive via its
1253
+ * `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
1254
+ * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
1255
+ * primitive's transport + signal-state logic and remains mockable in a
1256
+ * non-browser test env.
1257
+ */
1258
+ /**
1259
+ * The negotiated audio format the voice DO streams back. Mirrors
1260
+ * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
1261
+ * imported) so this Angular package never pulls in the server-only `@lunora/agent`
1262
+ * module graph.
1263
+ * @experimental
1264
+ */
1265
+ type VoiceAudioFormat = "mp3" | "wav";
1266
+ /** Captures microphone audio and reports level / turn boundaries back to the primitive. */
1267
+ interface VoiceMicrophone {
1268
+ /** Mute/unmute the mic without tearing down the capture graph. */
1269
+ setMuted: (muted: boolean) => void;
1270
+ /** Stop capture and release the media stream + audio graph. */
1271
+ stop: () => void;
1272
+ }
1273
+ /** Plays the server's streamed audio chunks and supports a mid-utterance barge-in. */
1274
+ interface VoiceSpeaker {
1275
+ /** Queue a decoded audio chunk for gap-minimized playback. */
1276
+ enqueue: (audio: Uint8Array) => void;
1277
+ /** Drop everything queued and stop the current chunk (barge-in). */
1278
+ interrupt: () => void;
1279
+ /** Release the playback audio context. */
1280
+ stop: () => void;
1281
+ }
1282
+ /** Config passed to a {@link CreateMicrophone} factory. */
1283
+ interface MicrophoneConfig {
1284
+ /** The consecutive above-threshold chunk count that counts as a barge-in. */
1285
+ interruptChunks: number;
1286
+ /** RMS above which the user is considered to be barging in while the agent speaks. */
1287
+ interruptThreshold: number;
1288
+ /** `true` while `status === "speaking"` — gates barge-in detection. */
1289
+ isSpeaking: () => boolean;
1290
+ /** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
1291
+ onAudio: (pcm: Uint8Array) => void;
1292
+ /** A barge-in was detected (RMS spike while the agent is speaking). */
1293
+ onInterrupt: () => void;
1294
+ /** The current input RMS (0–1), for a level meter. */
1295
+ onLevel: (rms: number) => void;
1296
+ /** A spoken utterance ended (speech followed by `silenceDurationMs` of silence). */
1297
+ onSilence: () => void;
1298
+ /** Milliseconds of sub-threshold audio (after speech) that closes an utterance. */
1299
+ silenceDurationMs: number;
1300
+ /** RMS below which audio counts as silence. */
1301
+ silenceThreshold: number;
1302
+ }
1303
+ type CreateMicrophone = (config: MicrophoneConfig) => Promise<VoiceMicrophone>;
1304
+ type CreateSpeaker = (config: {
1305
+ audioFormat: VoiceAudioFormat;
1306
+ }) => VoiceSpeaker;
1307
+ /**
1308
+ * The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
1309
+ * live, WS-backed session keyed by `threadKey`. A structural subset of the
1310
+ * generated member, so passing `api.agents.<name>Voice` type-checks.
1311
+ * @experimental
1312
+ */
1313
+ type VoiceReference = FunctionReference<"stream", {
1314
+ threadKey: string;
1315
+ }, Record<string, unknown>>;
1316
+ /**
1317
+ * The lifecycle of a voice call, mirrored to the UI.
1318
+ * @experimental
1319
+ */
1320
+ type VoiceStatus = "idle" | "listening" | "speaking" | "thinking";
1321
+ /** A minimal structural subset of the DOM `WebSocket` the primitive drives. */
1322
+ interface VoiceSocket {
1323
+ binaryType: string;
1324
+ close: () => void;
1325
+ onclose: ((event: unknown) => void) | null;
1326
+ onerror: ((event: unknown) => void) | null;
1327
+ onmessage: ((event: {
1328
+ data: unknown;
1329
+ }) => void) | null;
1330
+ onopen: ((event: unknown) => void) | null;
1331
+ readonly readyState: number;
1332
+ send: (data: ArrayBufferView | ArrayBufferLike | string) => void;
1333
+ }
1334
+ type CreateSocket = (url: string) => VoiceSocket;
1335
+ /**
1336
+ * `VoiceAgentOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1337
+ * @experimental
1338
+ */
1339
+ interface VoiceAgentOptions {
1340
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
1341
+ client?: LunoraClient;
1342
+ /**
1343
+ * Advanced/test seam: build the microphone capture subsystem. Defaults to a
1344
+ * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
1345
+ * Audio graph stays isolated (and mockable in a non-browser test env).
1346
+ */
1347
+ createMicrophone?: CreateMicrophone;
1348
+ /** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
1349
+ createSocket?: CreateSocket;
1350
+ /** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
1351
+ createSpeaker?: CreateSpeaker;
1352
+ /**
1353
+ * `DestroyRef` whose `onDestroy` tears the call down. Defaults to
1354
+ * `inject(DestroyRef)` — the calling component/service.
1355
+ */
1356
+ destroyRef?: DestroyRef;
1357
+ /** Consecutive above-`interruptThreshold` chunks that trigger a barge-in. Default `3`. */
1358
+ interruptChunks?: number;
1359
+ /** Input RMS above which the user is treated as barging in while the agent speaks. Default `0.15`. */
1360
+ interruptThreshold?: number;
1361
+ /** Milliseconds of silence (after speech) that auto-commits an utterance. Default `1200`. */
1362
+ silenceDurationMs?: number;
1363
+ /** Input RMS below which audio counts as silence. Default `0.01`. */
1364
+ silenceThreshold?: number;
1365
+ /** The thread to converse on — shared with the agent's text turns. Resolved when the call opens. */
1366
+ threadKey: string;
1367
+ /** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
1368
+ voice: VoiceReference;
1369
+ }
1370
+ /**
1371
+ * `VoiceAgentResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1372
+ * @experimental
1373
+ */
1374
+ interface VoiceAgentResult {
1375
+ /** The current input RMS (0–1) — drive a mic level meter. */
1376
+ audioLevel: Signal<number>;
1377
+ /** `true` once the WS `ready` handshake completed. */
1378
+ connected: Signal<boolean>;
1379
+ /** Tear down the call: close the socket, stop the mic, release audio. Idempotent. */
1380
+ endCall: () => void;
1381
+ /** The last transport/pipeline error, or `undefined`. */
1382
+ error: Signal<Error | undefined>;
1383
+ /** The live assistant text for the in-flight turn (grows via deltas; finalized on done). */
1384
+ interimTranscript: Signal<string>;
1385
+ /** `true` while the mic is muted. */
1386
+ isMuted: Signal<boolean>;
1387
+ /** Send a typed turn (no audio) — a text message spoken back by the agent. */
1388
+ sendText: (text: string) => void;
1389
+ /** Open the mic, connect the socket, and start the conversation. Idempotent while active. */
1390
+ startCall: () => Promise<void>;
1391
+ /** The current call lifecycle. */
1392
+ status: Signal<VoiceStatus>;
1393
+ /** Mute/unmute the microphone. Returns the new muted state. */
1394
+ toggleMute: () => boolean;
1395
+ /** The last finalized user utterance (STT result). */
1396
+ transcript: Signal<string>;
1397
+ }
1398
+ /**
1399
+ * A first-class voice-call surface for a voice-enabled agent: it opens a
1400
+ * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1401
+ * streams the agent's synthesized speech back through the browser's audio output,
1402
+ * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1403
+ * `audioLevel`) to Angular signals. Pass the generated `api.agents.<name>Voice`
1404
+ * reference (never a string), matching `agentChat`'s reference-passing style. The
1405
+ * Angular counterpart to React's `useVoiceAgent`, re-expressed with signals; the
1406
+ * per-call connection lives in a closure variable (the primitive runs once per
1407
+ * component, so no signal-of-connection indirection is needed).
1408
+ *
1409
+ * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
1410
+ * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
1411
+ * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
1412
+ * `createSocket`) so the primitive is drivable outside a browser.
1413
+ *
1414
+ * Call from an injection context (component/service field or constructor); pass an
1415
+ * explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
1416
+ * @experimental
1417
+ */
1418
+ declare const voiceAgent: (options: VoiceAgentOptions) => VoiceAgentResult;
1419
+ export { type AgentApi, type AgentChatApi, type AgentChatMessage, type AgentChatOptions, type AgentChatResult, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentResult, type AgentStateApi, type AgentStateOptions, type AgentStateResult, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentTokenStreamReference, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsOptions, type AgentToolEventsResult, type AuthGateResult, type AuthOptions, type AuthResult, type ConnectionStatusOptions, type FlagContext, type FlagOptions, type FlagValue, type FlagsOptions, type HeartbeatReference, type HydratePreloadedOptions, type HydratePreloadedResult, type InfiniteQueryResult, LUNORA_CLIENT, type ListPresentReference, type LiveQueryOptions, type MutateOptions, type MutatorResult, type PaginatedQueryOptions, type PaginatedQueryResult, type PresenceOptions, type PresenceResult,
1420
+ /**
1421
+ * The Angular adapter for Lunora.
1422
+ *
1423
+ * Thin, idiomatic glue over the framework-neutral `@lunora/client`. Angular
1424
+ * signals map directly onto Lunora's per-subscription deltas, so a live query is
1425
+ * just a `signal` the WebSocket writes to.
1426
+ *
1427
+ * `provideLunora` / `LUNORA_CLIENT` / `injectLunoraClient` are the injectable
1428
+ * provider carrying one `LunoraClient` (opens its socket lazily), wired once in the
1429
+ * application config. `liveQuery` is a live-query `signal` that opens a
1430
+ * subscription and updates on every delta, torn down automatically on
1431
+ * `DestroyRef.onDestroy`. `mutate` runs a mutation (optimistic updates + offline
1432
+ * queue pass through to the client). `connectionStatus` is a `signal` of the
1433
+ * aggregate live-socket status.
1434
+ */
1435
+ type ProvideLunoraOptions, type RateLimitOptions, type RateLimitResult, type RunActionOptions, type StreamOptions, type StreamResult, type StreamStatus, type SubscriptionOptions, type SubscriptionResult, type VoiceAgentOptions, type VoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags, hydratePreloaded, infiniteQuery, injectLunoraClient, liveQuery, mutate, mutator, paginatedQuery, presence, provideLunora, rateLimit, runAction, stream, subscription, voiceAgent };