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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +44 -0
  2. package/dist/index.d.mts +1218 -278
  3. package/dist/index.d.ts +1218 -278
  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-qIhLP3Uo.mjs +1 -0
  13. package/dist/packem_shared/hydratePreloaded-C8lNoww0.mjs +1 -0
  14. package/dist/packem_shared/infiniteQuery-B5Q21vgn.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.ts 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';
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
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,78 +615,110 @@ 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>;
628
+ /** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
629
+ type FlagContext$1 = Record<string, unknown>;
103
630
  /** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
104
- type FlagValue = boolean | number | string | Record<string, unknown> | unknown[] | null;
105
- /** Targeting context bag forwarded to the OpenFeature provider. */
106
- type FlagContext = Record<string, unknown>;
631
+ type FlagValue$1 = boolean | number | string | {
632
+ [key: string]: unknown;
633
+ } | unknown[] | null;
634
+ /**
635
+ * The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags.
636
+ * @experimental
637
+ */
638
+ type FlagValue = FlagValue$1;
639
+ /**
640
+ * Targeting context bag forwarded to the OpenFeature provider.
641
+ * @experimental
642
+ */
643
+ type FlagContext = FlagContext$1;
644
+ /**
645
+ * `FlagOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
646
+ * @experimental
647
+ */
107
648
  interface FlagOptions {
108
649
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
109
650
  client?: LunoraClient;
110
651
  /**
111
- * Per-call targeting context merged on top of the app's default `identify`
112
- * targeting key.
113
- */
652
+ * Per-call targeting context merged on top of the app's default `identify`
653
+ * targeting key.
654
+ */
114
655
  context?: FlagContext;
115
656
  /** `DestroyRef` whose `onDestroy` tears down the subscription. Defaults to `inject(DestroyRef)`. */
116
657
  destroyRef?: DestroyRef;
117
658
  }
118
659
  /**
119
- * Subscribe to a single feature flag, live over Lunora's WebSocket.
120
- *
121
- * The returned signal holds `defaultValue` until the first evaluation lands, then
122
- * the server's resolved value — re-pushed whenever the provider re-evaluates.
123
- * The flag's kind is inferred from `defaultValue`'s runtime type, so
124
- * `flag("dark", false)` reads a boolean and `flag("hero", "control")` a string.
125
- *
126
- * Evaluation runs through whatever OpenFeature provider the app wired in
127
- * `lunora/flags.ts`; the read never throws — a provider error resolves the
128
- * default (the same fail-open contract as server-side `ctx.flags`).
129
- *
130
- * Call from an injection context:
131
- * ```ts
132
- * readonly darkMode = flag("dark-mode", false);
133
- * ```
134
- */
660
+ * Subscribe to a single feature flag, live over Lunora's WebSocket.
661
+ *
662
+ * The returned signal holds `defaultValue` until the first evaluation lands, then
663
+ * the server's resolved value — re-pushed whenever the provider re-evaluates.
664
+ * The flag's kind is inferred from `defaultValue`'s runtime type, so
665
+ * `flag("dark", false)` reads a boolean and `flag("hero", "control")` a string.
666
+ *
667
+ * Evaluation runs through whatever OpenFeature provider the app wired in
668
+ * `lunora/flags.ts`; the read never throws — a provider error resolves the
669
+ * default (the same fail-open contract as server-side `ctx.flags`). No
670
+ * subscription opens during SSR; the signal stays at `defaultValue`.
671
+ *
672
+ * Call from an injection context:
673
+ * ```ts
674
+ * readonly darkMode = flag("dark-mode", false);
675
+ * ```
676
+ * @experimental
677
+ */
135
678
  declare const flag: <T extends FlagValue>(key: string, defaultValue: T, options?: FlagOptions) => Signal<T>;
679
+ /**
680
+ * `FlagsOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
681
+ * @experimental
682
+ */
136
683
  interface FlagsOptions {
137
684
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
138
685
  client?: LunoraClient;
139
686
  /**
140
- * Targeting context shared by every flag in the set, merged on top of the
141
- * app's default `identify` targeting key.
142
- */
687
+ * Targeting context shared by every flag in the set, merged on top of the
688
+ * app's default `identify` targeting key.
689
+ */
143
690
  context?: FlagContext;
144
691
  /** `DestroyRef` whose `onDestroy` tears down the subscriptions. Defaults to `inject(DestroyRef)`. */
145
692
  destroyRef?: DestroyRef;
146
693
  }
147
694
  /**
148
- * Subscribe to several feature flags at once, live over Lunora's WebSocket.
149
- *
150
- * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
151
- * default, and the returned signal holds the same-shaped record with resolved
152
- * values (the defaults until each evaluation lands).
153
- *
154
- * Call from an injection context:
155
- * ```ts
156
- * readonly features = flags({ "dark-mode": false, "new-editor": false });
157
- * ```
158
- */
695
+ * Subscribe to several feature flags at once, live over Lunora's WebSocket.
696
+ *
697
+ * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
698
+ * default, and the returned signal holds the same-shaped record with resolved
699
+ * values (the defaults until each evaluation lands).
700
+ *
701
+ * Call from an injection context:
702
+ * ```ts
703
+ * readonly features = flags({ "dark-mode": false, "new-editor": false });
704
+ * ```
705
+ * @experimental
706
+ */
159
707
  declare const flags: <T extends Record<string, FlagValue>>(flagDefaults: T, options?: FlagsOptions) => Signal<T>;
708
+ /**
709
+ * `HydratePreloadedOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
710
+ * @experimental
711
+ */
160
712
  interface HydratePreloadedOptions {
161
713
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
162
714
  client?: LunoraClient;
163
715
  /** `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to `inject(DestroyRef)`. */
164
716
  destroyRef?: DestroyRef;
165
717
  }
718
+ /**
719
+ * `HydratePreloadedResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
720
+ * @experimental
721
+ */
166
722
  interface HydratePreloadedResult<T> {
167
723
  /** The latest value pushed by the server. Seeded synchronously from the preloaded value. */
168
724
  data: Signal<T | undefined>;
@@ -170,99 +726,131 @@ interface HydratePreloadedResult<T> {
170
726
  error: Signal<SubscriptionError | undefined>;
171
727
  }
172
728
  /**
173
- * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
174
- * during SSR, then keep it live — the Angular half of the reactive-loader
175
- * handoff.
176
- *
177
- * The returned signal is seeded **synchronously** from `preloaded.value`, so the
178
- * very first read (during hydration) shows the server value: no loading flash,
179
- * no hydration mismatch. After seeding it opens a WebSocket subscription on the
180
- * same `(functionPath, args, shardKey)` the SSR loader used, so every later
181
- * server delta updates the signal exactly like `liveQuery`.
182
- *
183
- * The subscription tears down when the owning `DestroyRef` fires.
184
- *
185
- * Call from an injection context:
186
- * ```ts
187
- * readonly { data, error } = hydratePreloaded(preloadedMessages);
188
- * ```
189
- */
729
+ * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
730
+ * during SSR, then keep it live — the Angular half of the reactive-loader
731
+ * handoff.
732
+ *
733
+ * The returned signal is seeded **synchronously** from `preloaded.value`, so the
734
+ * very first read (during hydration) shows the server value: no loading flash,
735
+ * no hydration mismatch. After seeding it opens a WebSocket subscription on the
736
+ * same `(functionPath, args, shardKey)` the SSR loader used, so every later
737
+ * server delta updates the signal exactly like `liveQuery`.
738
+ *
739
+ * The subscription tears down when the owning `DestroyRef` fires.
740
+ *
741
+ * Call from an injection context:
742
+ * ```ts
743
+ * readonly { data, error } = hydratePreloaded(preloadedMessages);
744
+ * ```
745
+ * @experimental
746
+ */
190
747
  declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, options?: HydratePreloadedOptions) => HydratePreloadedResult<T>;
748
+ /**
749
+ * `LiveQueryOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
750
+ * @experimental
751
+ */
191
752
  interface LiveQueryOptions {
192
753
  /**
193
- * Client to bind to. Defaults to the injected `LUNORA_CLIENT`; pass one
194
- * explicitly to use `liveQuery` outside an injection context (or in a test).
195
- */
754
+ * Client to bind to. Defaults to the injected `LUNORA_CLIENT`; pass one
755
+ * explicitly to use `liveQuery` outside an injection context (or in a test).
756
+ */
196
757
  client?: LunoraClient;
197
758
  /**
198
- * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
199
- * `inject(DestroyRef)` — the calling component/service — so it closes when that
200
- * component is destroyed. Pass one explicitly to control the lifetime yourself.
201
- */
759
+ * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
760
+ * `inject(DestroyRef)` — the calling component/service — so it closes when that
761
+ * component is destroyed. Pass one explicitly to control the lifetime yourself.
762
+ */
202
763
  destroyRef?: DestroyRef;
203
764
  /**
204
- * Called when the subscription errors after the initial attach — the async
205
- * error channel `createQuerySubscription` only wires when a sink is present.
206
- * Without it, a post-attach failure is dropped silently: the signal simply
207
- * stops updating with no error state exposed. Pass a handler to surface it
208
- * (log, toast, set an error signal of your own).
209
- */
765
+ * `Injector` to create the reactive-args `effect()` from. Only needed when
766
+ * `args` is a function/`Signal` AND `liveQuery` is called outside an injection
767
+ * context (an explicit `destroyRef` is also being passed — e.g. from
768
+ * `ngOnInit`, or from a test with no `TestBed`) — `effect()` cannot resolve an
769
+ * injector on its own there. Defaults to the ambient injection context, the
770
+ * same source `inject(DestroyRef)` already relies on. Unused for the static
771
+ * `args` form, which never creates an `effect()`.
772
+ */
773
+ injector?: Injector;
774
+ /**
775
+ * Called when the subscription errors after the initial attach — the async
776
+ * error channel `createQuerySubscription` only wires when a sink is present.
777
+ * Without it, a post-attach failure is dropped silently: the signal simply
778
+ * stops updating with no error state exposed. Pass a handler to surface it
779
+ * (log, toast, set an error signal of your own).
780
+ */
210
781
  onError?: (error: SubscriptionError) => void;
211
782
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
212
783
  shardKey?: string;
213
784
  }
214
785
  /**
215
- * Subscribe to a server query and mirror its value into an Angular `signal`.
216
- *
217
- * Reads `undefined` until the first server frame lands, then updates on every
218
- * delta the WebSocket pushes. The underlying subscription is torn down
219
- * automatically when the owning `DestroyRef` fires (the component/service is
220
- * destroyed), so there is no leaked socket subscription.
221
- *
222
- * Call it from an injection context (a component/service field initializer or
223
- * constructor) so the default `inject(DestroyRef)` resolves the caller's
224
- * lifetime:
225
- *
226
- * ```ts
227
- * export class MessagesComponent {
228
- * readonly messages = liveQuery(api.messages.list, { channelId: "general" });
229
- * }
230
- * ```
231
- *
232
- * Pass `"skip"` (the `SKIP` sentinel from `@lunora/client/query`) as `args` to
233
- * short-circuit — no network call, no socket; the signal stays `undefined`. To
234
- * call outside an injection context (e.g. lazily in `ngOnInit`), supply `client`
235
- * and `destroyRef` via {@link LiveQueryOptions}.
236
- */
237
- declare const liveQuery: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip", options?: LiveQueryOptions) => Signal<ReturnOf<F> | undefined>;
786
+ * Subscribe to a server query and mirror its value into an Angular `signal`.
787
+ *
788
+ * Reads `undefined` until the first server frame lands, then updates on every
789
+ * delta the WebSocket pushes. The underlying subscription is torn down
790
+ * automatically when the owning `DestroyRef` fires (the component/service is
791
+ * destroyed), so there is no leaked socket subscription.
792
+ *
793
+ * Call it from an injection context (a component/service field initializer or
794
+ * constructor) so the default `inject(DestroyRef)` resolves the caller's
795
+ * lifetime:
796
+ *
797
+ * ```ts
798
+ * export class MessagesComponent {
799
+ * readonly messages = liveQuery(api.messages.list, { channelId: "general" });
800
+ * }
801
+ * ```
802
+ *
803
+ * Pass `"skip"` (the `SKIP` sentinel from `@lunora/client/query`) as `args` to
804
+ * short-circuit — no network call, no socket; the signal stays `undefined`. To
805
+ * call outside an injection context (e.g. lazily in `ngOnInit`), supply `client`
806
+ * and `destroyRef` via {@link LiveQueryOptions}.
807
+ *
808
+ * `args` also accepts a function/`Signal` — `() => ({ channelId: channelId() })`
809
+ * — to make the subscription reactive: an args change tears the old
810
+ * subscription down and opens a fresh one for the new args, mirroring
811
+ * `@lunora/solid`'s `createQuery`/`@lunora/vue`'s `useQuery`. A static (plain
812
+ * object) `args` resolves once and never re-runs — no `effect()` is created for
813
+ * it, so it carries none of the reactive form's DI requirement.
814
+ * @experimental
815
+ */
816
+ declare const liveQuery: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip" | (() => ArgsOf<F> | "skip"), options?: LiveQueryOptions) => Signal<ReturnOf<F> | undefined>;
817
+ /**
818
+ * `MutateOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
819
+ * @experimental
820
+ */
238
821
  interface MutateOptions<F extends FunctionReference> extends MutationCallOptions<unknown, unknown, ArgsOf<F>> {
239
822
  /**
240
- * Client to run the mutation on. Defaults to the injected `LUNORA_CLIENT`.
241
- * Because mutations usually fire from event handlers — which run *outside* an
242
- * injection context — capture the client once (`injectLunoraClient()` in a
243
- * field) and pass it here, or call `client.mutation(...)` directly.
244
- */
823
+ * Client to run the mutation on. Defaults to the injected `LUNORA_CLIENT`.
824
+ * Because mutations usually fire from event handlers — which run *outside* an
825
+ * injection context — capture the client once (`injectLunoraClient()` in a
826
+ * field) and pass it here, or call `client.mutation(...)` directly.
827
+ */
245
828
  client?: LunoraClient;
246
829
  }
247
830
  /**
248
- * Run a Lunora mutation and resolve with the server result (rejects on failure).
249
- *
250
- * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
251
- * call options pass straight through to `client.mutation`, which applies and
252
- * rolls them back against the live subscription cache — the same cache
253
- * `liveQuery` reads, so an optimistic write reflects immediately and
254
- * reverts on failure. The client's offline queue also engages when the socket is
255
- * down, so the write stays durable across reconnects.
256
- *
257
- * ```ts
258
- * private readonly client = injectLunoraClient();
259
- * send = (text: string) => mutate(api.messages.send, { text }, { client: this.client });
260
- * ```
261
- *
262
- * When called from within an injection context you may omit `client` and let it
263
- * resolve from the injector.
264
- */
831
+ * Run a Lunora mutation and resolve with the server result (rejects on failure).
832
+ *
833
+ * Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
834
+ * call options pass straight through to `client.mutation`, which applies and
835
+ * rolls them back against the live subscription cache — the same cache
836
+ * `liveQuery` reads, so an optimistic write reflects immediately and
837
+ * reverts on failure. The client's offline queue also engages when the socket is
838
+ * down, so the write stays durable across reconnects.
839
+ *
840
+ * ```ts
841
+ * private readonly client = injectLunoraClient();
842
+ * send = (text: string) => mutate(api.messages.send, { text }, { client: this.client });
843
+ * ```
844
+ *
845
+ * When called from within an injection context you may omit `client` and let it
846
+ * resolve from the injector.
847
+ * @experimental
848
+ */
265
849
  declare const mutate: <F extends FunctionReference>(reference: F, args: ArgsOf<F>, options?: MutateOptions<F>) => Promise<ReturnOf<F>>;
850
+ /**
851
+ * `MutatorResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
852
+ * @experimental
853
+ */
266
854
  interface MutatorResult<TArgs> {
267
855
  /** The latest invocation's error, or `undefined`. */
268
856
  error: Signal<Error | undefined>;
@@ -276,22 +864,23 @@ interface MutatorResult<TArgs> {
276
864
  reset: () => void;
277
865
  }
278
866
  /**
279
- * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
280
- * custom-mutator handle from `` `@lunora/db` ``'s `bindMutators` — the Angular
281
- * equivalent of `` `@lunora/react` ``'s `useMutator`. The optimistic overlay and
282
- * server-authoritative push are owned by the bound handle; this function only
283
- * surfaces reactive state for the in-flight/error lifecycle.
284
- *
285
- * `pending` is ref-counted across overlapping invocations of THIS handle, so it
286
- * clears only once every concurrent call has settled.
287
- *
288
- * Does NOT require an injection context — it works with plain signals.
289
- *
290
- * ```ts
291
- * private readonly collection = bindMutators(collections);
292
- * readonly mutator = mutator(this.collection.insert);
293
- * ```
294
- */
867
+ * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
868
+ * custom-mutator handle from `` `@lunora/db` ``'s `bindMutators` — the Angular
869
+ * equivalent of `` `@lunora/react` ``'s `useMutator`. The optimistic overlay and
870
+ * server-authoritative push are owned by the bound handle; this function only
871
+ * surfaces reactive state for the in-flight/error lifecycle.
872
+ *
873
+ * `pending` is ref-counted across overlapping invocations of THIS handle, so it
874
+ * clears only once every concurrent call has settled.
875
+ *
876
+ * Does NOT require an injection context — it works with plain signals.
877
+ *
878
+ * ```ts
879
+ * private readonly collection = bindMutators(collections);
880
+ * readonly mutator = mutator(this.collection.insert);
881
+ * ```
882
+ * @experimental
883
+ */
295
884
  declare const mutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorResult<TArgs>;
296
885
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
297
886
  type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOfRaw<F>, "paginationOpts">;
@@ -301,6 +890,10 @@ type PageItemOf<F extends FunctionReference> = ReturnTypeOf<F> extends {
301
890
  } ? T : unknown;
302
891
  type ArgsOfRaw<F extends FunctionReference> = F extends FunctionReference<"query", infer A> ? A : never;
303
892
  type ReturnTypeOf<F extends FunctionReference> = F extends FunctionReference<"query", unknown, infer R> ? R : never;
893
+ /**
894
+ * Options for the paginated query — part of the experimental `@lunora/angular` API and may change without a major version bump.
895
+ * @experimental
896
+ */
304
897
  interface PaginatedQueryOptions {
305
898
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
306
899
  client?: LunoraClient;
@@ -308,9 +901,20 @@ interface PaginatedQueryOptions {
308
901
  destroyRef?: DestroyRef;
309
902
  /** Page size for the first page (and the default for `loadMore`). */
310
903
  initialNumItems: number;
904
+ /**
905
+ * `Injector` to create the reactive-args `effect()` from. Only needed when
906
+ * `args` is a function/`Signal` AND the call is outside an injection context
907
+ * (an explicit `destroyRef` is also being passed). Defaults to the ambient
908
+ * injection context. Unused for the static `args` form.
909
+ */
910
+ injector?: Injector;
311
911
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
312
912
  shardKey?: string;
313
913
  }
914
+ /**
915
+ * `PaginatedQueryResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
916
+ * @experimental
917
+ */
314
918
  interface PaginatedQueryResult<T> {
315
919
  /** `true` while the first page or a `loadMore` page is in flight. */
316
920
  isLoading: Signal<boolean>;
@@ -321,6 +925,10 @@ interface PaginatedQueryResult<T> {
321
925
  /** The pagination status. */
322
926
  status: Signal<PaginationStatus>;
323
927
  }
928
+ /**
929
+ * `InfiniteQueryResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
930
+ * @experimental
931
+ */
324
932
  interface InfiniteQueryResult<T> {
325
933
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
326
934
  fetchNextPage: (numberItems?: number) => void;
@@ -336,43 +944,64 @@ interface InfiniteQueryResult<T> {
336
944
  status: Signal<PaginationStatus>;
337
945
  }
338
946
  /**
339
- * Subscribe to a reactively-paginated query and grow the feed page by page.
340
- *
341
- * The query function must accept a `paginationOpts: { numItems, cursor,
342
- * endCursor }` arg and return a `PaginationResult`. Pages are tracked as an
343
- * ordered list of stable boundary cursors; each loaded page is a live
344
- * subscription over a FIXED `(lower, upper]` range.
345
- *
346
- * `loadMore` appends the next page off the open-ended tail's `continueCursor`;
347
- * it is a no-op unless `status === "CanLoadMore"`.
348
- *
349
- * Call from an injection context:
350
- * ```ts
351
- * readonly messages = paginatedQuery(api.messages.list, {}, { initialNumItems: 20 });
352
- * ```
353
- */
354
- declare const paginatedQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip", options: PaginatedQueryOptions) => PaginatedQueryResult<PageItemOf<F>>;
355
- /**
356
- * Subscribe to a reactively-paginated query and expose its pages discretely.
357
- *
358
- * Shares `paginatedQuery`'s reactive-pagination engine but keeps each page as
359
- * its own inner array rather than flattening them, and adds the TanStack-Query-
360
- * style `fetchNextPage` / `hasNextPage` / `isFetchingNextPage` shape.
361
- *
362
- * Call from an injection context:
363
- * ```ts
364
- * readonly feed = infiniteQuery(api.messages.list, {}, { initialNumItems: 20 });
365
- * ```
366
- */
367
- declare const infiniteQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip", options: PaginatedQueryOptions) => InfiniteQueryResult<PageItemOf<F>>;
947
+ * Subscribe to a reactively-paginated query and grow the feed page by page.
948
+ *
949
+ * The query function must accept a `paginationOpts: { numItems, cursor,
950
+ * endCursor }` arg and return a `PaginationResult`. Pages are tracked as an
951
+ * ordered list of stable boundary cursors; each loaded page is a live
952
+ * subscription over a FIXED `(lower, upper]` range.
953
+ *
954
+ * `loadMore` appends the next page off the open-ended tail's `continueCursor`;
955
+ * it is a no-op unless `status === "CanLoadMore"`.
956
+ *
957
+ * Call from an injection context:
958
+ * ```ts
959
+ * readonly messages = paginatedQuery(api.messages.list, {}, { initialNumItems: 20 });
960
+ * ```
961
+ *
962
+ * `args` also accepts a function/`Signal` to make the query reactive — an args
963
+ * change disposes the current pagination engine and builds a fresh one for the
964
+ * new args. A static (plain object) `args` resolves once and never re-runs.
965
+ * @experimental
966
+ */
967
+ declare const paginatedQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip" | (() => PaginatedArgs<F> | "skip"), options: PaginatedQueryOptions) => PaginatedQueryResult<PageItemOf<F>>;
968
+ /**
969
+ * Subscribe to a reactively-paginated query and expose its pages discretely.
970
+ *
971
+ * Shares `paginatedQuery`'s reactive-pagination engine but keeps each page as
972
+ * its own inner array rather than flattening them, and adds the TanStack-Query-
973
+ * style `fetchNextPage` / `hasNextPage` / `isFetchingNextPage` shape.
974
+ *
975
+ * Call from an injection context:
976
+ * ```ts
977
+ * readonly feed = infiniteQuery(api.messages.list, {}, { initialNumItems: 20 });
978
+ * ```
979
+ *
980
+ * `args` also accepts a function/`Signal` to make the query reactive — see
981
+ * `paginatedQuery`'s equivalent note.
982
+ * @experimental
983
+ */
984
+ declare const infiniteQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip" | (() => PaginatedArgs<F> | "skip"), options: PaginatedQueryOptions) => InfiniteQueryResult<PageItemOf<F>>;
985
+ /**
986
+ * `HeartbeatReference` is part of the experimental `@lunora/angular` API and may change without a major version bump.
987
+ * @experimental
988
+ */
368
989
  type HeartbeatReference = FunctionReference<"mutation", {
369
990
  data?: Record<string, unknown>;
370
991
  roomId: string;
371
992
  sessionId: string;
372
993
  }>;
994
+ /**
995
+ * `ListPresentReference` is part of the experimental `@lunora/angular` API and may change without a major version bump.
996
+ * @experimental
997
+ */
373
998
  type ListPresentReference = FunctionReference<"query", {
374
999
  roomId: string;
375
1000
  }>;
1001
+ /**
1002
+ * `PresenceOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1003
+ * @experimental
1004
+ */
376
1005
  interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentReference> {
377
1006
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
378
1007
  client?: LunoraClient;
@@ -387,13 +1016,17 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
387
1016
  /** The `api.*` reference for the presence listPresent query. */
388
1017
  listPresent: L;
389
1018
  /**
390
- * Stable id for this presence row. Defaults to a fresh per-call id.
391
- * Pass a user/connection id to control deduping across tabs.
392
- */
1019
+ * Stable id for this presence row. Defaults to a fresh per-call id.
1020
+ * Pass a user/connection id to control deduping across tabs.
1021
+ */
393
1022
  sessionId?: string;
394
1023
  /** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
395
1024
  shardKey?: string;
396
1025
  }
1026
+ /**
1027
+ * `PresenceResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1028
+ * @experimental
1029
+ */
397
1030
  interface PresenceResult<L extends ListPresentReference> {
398
1031
  /** The present members for the room. `undefined` until the first push. */
399
1032
  present: Signal<ReturnOf<L> | undefined>;
@@ -403,35 +1036,44 @@ interface PresenceResult<L extends ListPresentReference> {
403
1036
  setData: (data: Record<string, unknown> | undefined) => void;
404
1037
  }
405
1038
  /**
406
- * `presence` — collaborative-awareness primitive, the client half of the
407
- * `@lunora/server` `definePresence` preset.
408
- *
409
- * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
410
- * subscribes to the live `listPresent` query for the given room.
411
- *
412
- * Call from an injection context (component/service field or constructor):
413
- * ```ts
414
- * readonly roomPresence = presence("room:general", {
415
- * heartbeat: api.presence.heartbeat,
416
- * listPresent: api.presence.listPresent,
417
- * });
418
- * ```
419
- */
1039
+ * `presence` — collaborative-awareness primitive, the client half of the
1040
+ * `@lunora/server` `definePresence` preset.
1041
+ *
1042
+ * Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
1043
+ * subscribes to the live `listPresent` query for the given room.
1044
+ *
1045
+ * Call from an injection context (component/service field or constructor):
1046
+ * ```ts
1047
+ * readonly roomPresence = presence("room:general", {
1048
+ * heartbeat: api.presence.heartbeat,
1049
+ * listPresent: api.presence.listPresent,
1050
+ * });
1051
+ * ```
1052
+ * @experimental
1053
+ */
420
1054
  declare const presence: <H extends HeartbeatReference, L extends ListPresentReference>(roomId: string, options: PresenceOptions<H, L>) => PresenceResult<L>;
1055
+ /**
1056
+ * `RateLimitOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1057
+ * @experimental
1058
+ */
421
1059
  interface RateLimitOptions {
422
1060
  /**
423
- * `DestroyRef` whose `onDestroy` clears the interval. Defaults to
424
- * `inject(DestroyRef)` — the calling component/service.
425
- */
1061
+ * `DestroyRef` whose `onDestroy` clears the interval. Defaults to
1062
+ * `inject(DestroyRef)` — the calling component/service.
1063
+ */
426
1064
  destroyRef?: DestroyRef;
427
1065
  /** Clock injection for tests. Defaults to `Date.now`. */
428
1066
  now?: () => number;
429
1067
  /**
430
- * Re-render cadence in milliseconds while throttled, so `retryAfter` ticks
431
- * down and `disabled` flips back automatically. Defaults to `1000`.
432
- */
1068
+ * Re-render cadence in milliseconds while throttled, so `retryAfter` ticks
1069
+ * down and `disabled` flips back automatically. Defaults to `1000`.
1070
+ */
433
1071
  tickMs?: number;
434
1072
  }
1073
+ /**
1074
+ * `RateLimitResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1075
+ * @experimental
1076
+ */
435
1077
  interface RateLimitResult {
436
1078
  /** Would consuming `count` (default 1) succeed right now? Does not consume. */
437
1079
  check: (count?: number) => boolean;
@@ -447,35 +1089,143 @@ interface RateLimitResult {
447
1089
  retryAfter: Signal<number>;
448
1090
  }
449
1091
  /**
450
- * Client-side mirror of a rate limit for instant UX — disable a button or show
451
- * a countdown without a round-trip. It runs the same token-bucket / fixed-window
452
- * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
453
- * authoritative check; the server remains the source of truth.
454
- *
455
- * Requires an Angular injection context unless a `DestroyRef` is passed
456
- * explicitly via `options.destroyRef`.
457
- *
458
- * ```ts
459
- * readonly sendLimit = rateLimit({ kind: "token bucket", period: 1000, rate: 10 });
460
- * ```
461
- */
1092
+ * Client-side mirror of a rate limit for instant UX — disable a button or show
1093
+ * a countdown without a round-trip. It runs the same token-bucket / fixed-window
1094
+ * math as `@lunora/ratelimit` on the server, so the prediction agrees with the
1095
+ * authoritative check; the server remains the source of truth.
1096
+ *
1097
+ * Requires an Angular injection context unless a `DestroyRef` is passed
1098
+ * explicitly via `options.destroyRef`.
1099
+ *
1100
+ * ```ts
1101
+ * readonly sendLimit = rateLimit({ kind: "token bucket", period: 1000, rate: 10 });
1102
+ * ```
1103
+ * @experimental
1104
+ */
462
1105
  declare const rateLimit: (config: RateLimitConfig, options?: RateLimitOptions) => RateLimitResult;
1106
+ /**
1107
+ * `RunActionOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1108
+ * @experimental
1109
+ */
1110
+ interface RunActionOptions extends ActionCallOptions {
1111
+ /**
1112
+ * Client to run the action on. Defaults to the injected `LUNORA_CLIENT`.
1113
+ * Because actions usually fire from event handlers — which run *outside* an
1114
+ * injection context — capture the client once (`injectLunoraClient()` in a
1115
+ * field) and pass it here, or call `client.action(...)` directly.
1116
+ */
1117
+ client?: LunoraClient;
1118
+ }
1119
+ /**
1120
+ * Run a Lunora action and resolve with the server result (rejects on failure).
1121
+ *
1122
+ * The sibling of `mutate`, and a plain function for the same reason: Angular's
1123
+ * adapter models writes as calls rather than reactive handles, because they fire
1124
+ * from event handlers where a signal-returning primitive has nothing to bind to.
1125
+ * The other adapters return a reactive `{ call, pending, … }` handle because
1126
+ * their idioms make that natural; this one does not.
1127
+ *
1128
+ * Unlike `mutate` there are no `optimistic` / `optimisticUpdate` options. An
1129
+ * optimistic update patches the subscription cache on the assumption a write
1130
+ * will land; an action is not a write — it runs in the Worker, may call a third
1131
+ * party, and has no declared effect on any query.
1132
+ *
1133
+ * ```ts
1134
+ * private readonly client = injectLunoraClient();
1135
+ * verify = () => runAction(api.commands.run, { command: "lunora", args: ["verify"] }, { client: this.client });
1136
+ * ```
1137
+ *
1138
+ * When called from within an injection context you may omit `client` and let it
1139
+ * resolve from the injector.
1140
+ * @experimental
1141
+ */
1142
+ declare const runAction: <F extends FunctionReference>(reference: F, args: ArgsOf<F>, options?: RunActionOptions) => Promise<ReturnOf<F>>;
1143
+ /**
1144
+ * The lifecycle of a stream the primitive is observing.
1145
+ * @experimental
1146
+ */
1147
+ type StreamStatus = "complete" | "error" | "idle" | "streaming";
1148
+ /**
1149
+ * `StreamOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1150
+ * @experimental
1151
+ */
1152
+ interface StreamOptions {
1153
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
1154
+ client?: LunoraClient;
1155
+ /**
1156
+ * `DestroyRef` whose `onDestroy` cancels the stream. Defaults to
1157
+ * `inject(DestroyRef)` — the calling component/service.
1158
+ */
1159
+ destroyRef?: DestroyRef;
1160
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
1161
+ maxBuffer?: number;
1162
+ /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
1163
+ shardKey?: string;
1164
+ }
1165
+ /**
1166
+ * `StreamResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1167
+ * @experimental
1168
+ */
1169
+ interface StreamResult<T> {
1170
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
1171
+ cancel: () => void;
1172
+ /** Chunks the server has pushed so far, in arrival order. */
1173
+ chunks: Signal<ReadonlyArray<T>>;
1174
+ /** The stream error, or `undefined`. */
1175
+ error: Signal<Error | undefined>;
1176
+ /** The stream lifecycle. */
1177
+ status: Signal<StreamStatus>;
1178
+ }
1179
+ /**
1180
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
1181
+ * lifecycle status and a `cancel` function, all as signals.
1182
+ *
1183
+ * Unlike `subscription`, which tracks the latest value, `stream` accumulates every
1184
+ * chunk the server pushes — use it for token-by-token deltas and other append-only
1185
+ * feeds. Pass `"skip"` as `args` to keep the primitive mounted without opening a
1186
+ * stream (mirrors `subscription`); the stream tears down when the owning
1187
+ * `DestroyRef` fires. The Angular counterpart to React's `useStream`, re-expressed
1188
+ * with signals.
1189
+ *
1190
+ * Call from an injection context (component/service field or constructor):
1191
+ * ```ts
1192
+ * readonly tokens = stream(api.chat.liveEvents, { key: "thread-1" });
1193
+ * ```
1194
+ * @experimental
1195
+ */
1196
+ declare const stream: <F extends FunctionReference<"stream">>(reference: F, args: ArgsOf<F> | "skip", options?: StreamOptions) => StreamResult<ReturnOf<F>>;
1197
+ /**
1198
+ * `SubscriptionOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1199
+ * @experimental
1200
+ */
463
1201
  interface SubscriptionOptions {
464
1202
  /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
465
1203
  client?: LunoraClient;
466
1204
  /**
467
- * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
468
- * `inject(DestroyRef)` — the calling component/service.
469
- */
1205
+ * `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
1206
+ * `inject(DestroyRef)` — the calling component/service.
1207
+ */
470
1208
  destroyRef?: DestroyRef;
471
1209
  /**
472
- * Called when the subscription errors after the initial attach. Without it,
473
- * a post-attach failure is dropped silently.
474
- */
1210
+ * `Injector` to create the reactive-args `effect()` from. Only needed when
1211
+ * `args` is a function/`Signal` AND `subscription` is called outside an
1212
+ * injection context (an explicit `destroyRef` is also being passed).
1213
+ * Defaults to the ambient injection context. Unused for the static `args`
1214
+ * form, which never creates an `effect()`.
1215
+ */
1216
+ injector?: Injector;
1217
+ /**
1218
+ * Called when the subscription errors after the initial attach. Without it,
1219
+ * a post-attach failure is dropped silently.
1220
+ */
475
1221
  onError?: (error: SubscriptionError) => void;
476
1222
  /** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
477
1223
  shardKey?: string;
478
1224
  }
1225
+ /**
1226
+ * `SubscriptionResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1227
+ * @experimental
1228
+ */
479
1229
  interface SubscriptionResult<T> {
480
1230
  /** The latest value pushed by the server. `undefined` before the first frame. */
481
1231
  data: Signal<T | undefined>;
@@ -483,20 +1233,210 @@ interface SubscriptionResult<T> {
483
1233
  error: Signal<SubscriptionError | undefined>;
484
1234
  }
485
1235
  /**
486
- * Subscribe to a reactive server push stream. Returns `{ data, error }` signals
487
- * that update whenever the server emits a new value.
488
- *
489
- * Unlike `liveQuery`, which tracks a single value, `subscription` also
490
- * exposes an `error` signal for the async error channel. Use it for ephemeral,
491
- * high-frequency streams where you need error visibility.
492
- *
493
- * Pass `"skip"` as `args` to short-circuit — no network call, no socket.
494
- * The subscription tears down when the owning `DestroyRef` fires.
495
- *
496
- * Call from an injection context (component/service field or constructor):
497
- * ```ts
498
- * readonly stream = subscription(api.events.stream, { roomId: "general" });
499
- * ```
500
- */
501
- declare const subscription: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip", options?: SubscriptionOptions) => SubscriptionResult<ReturnOf<F>>;
502
- export { 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, 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 };
1236
+ * Subscribe to a reactive server push stream. Returns `{ data, error }` signals
1237
+ * that update whenever the server emits a new value.
1238
+ *
1239
+ * Unlike `liveQuery`, which tracks a single value, `subscription` also
1240
+ * exposes an `error` signal for the async error channel. Use it for ephemeral,
1241
+ * high-frequency streams where you need error visibility.
1242
+ *
1243
+ * Pass `"skip"` as `args` to short-circuit — no network call, no socket.
1244
+ * The subscription tears down when the owning `DestroyRef` fires.
1245
+ *
1246
+ * Call from an injection context (component/service field or constructor):
1247
+ * ```ts
1248
+ * readonly stream = subscription(api.events.stream, { roomId: "general" });
1249
+ * ```
1250
+ *
1251
+ * `args` also accepts a function/`Signal` to make the subscription reactive —
1252
+ * an args change tears the old subscription down and opens a fresh one for the
1253
+ * new args. A static (plain object) `args` resolves once and never re-runs.
1254
+ * @experimental
1255
+ */
1256
+ declare const subscription: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip" | (() => ArgsOf<F> | "skip"), options?: SubscriptionOptions) => SubscriptionResult<ReturnOf<F>>;
1257
+ /**
1258
+ * Browser Web Audio subsystems for `voiceAgent` — the default microphone capture
1259
+ * and speaker playback implementations injected into the primitive via its
1260
+ * `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
1261
+ * heavy Web Audio graph (and its structural DOM typings) stays isolated from the
1262
+ * primitive's transport + signal-state logic and remains mockable in a
1263
+ * non-browser test env.
1264
+ */
1265
+ /**
1266
+ * The negotiated audio format the voice DO streams back. Mirrors
1267
+ * `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
1268
+ * imported) so this Angular package never pulls in the server-only `@lunora/agent`
1269
+ * module graph.
1270
+ * @experimental
1271
+ */
1272
+ type VoiceAudioFormat = "mp3" | "wav";
1273
+ /** Captures microphone audio and reports level / turn boundaries back to the primitive. */
1274
+ interface VoiceMicrophone {
1275
+ /** Mute/unmute the mic without tearing down the capture graph. */
1276
+ setMuted: (muted: boolean) => void;
1277
+ /** Stop capture and release the media stream + audio graph. */
1278
+ stop: () => void;
1279
+ }
1280
+ /** Plays the server's streamed audio chunks and supports a mid-utterance barge-in. */
1281
+ interface VoiceSpeaker {
1282
+ /** Queue a decoded audio chunk for gap-minimized playback. */
1283
+ enqueue: (audio: Uint8Array) => void;
1284
+ /** Drop everything queued and stop the current chunk (barge-in). */
1285
+ interrupt: () => void;
1286
+ /** Release the playback audio context. */
1287
+ stop: () => void;
1288
+ }
1289
+ /** Config passed to a {@link CreateMicrophone} factory. */
1290
+ interface MicrophoneConfig {
1291
+ /** The consecutive above-threshold chunk count that counts as a barge-in. */
1292
+ interruptChunks: number;
1293
+ /** RMS above which the user is considered to be barging in while the agent speaks. */
1294
+ interruptThreshold: number;
1295
+ /** `true` while `status === "speaking"` — gates barge-in detection. */
1296
+ isSpeaking: () => boolean;
1297
+ /** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
1298
+ onAudio: (pcm: Uint8Array) => void;
1299
+ /** A barge-in was detected (RMS spike while the agent is speaking). */
1300
+ onInterrupt: () => void;
1301
+ /** The current input RMS (0–1), for a level meter. */
1302
+ onLevel: (rms: number) => void;
1303
+ /** A spoken utterance ended (speech followed by `silenceDurationMs` of silence). */
1304
+ onSilence: () => void;
1305
+ /** Milliseconds of sub-threshold audio (after speech) that closes an utterance. */
1306
+ silenceDurationMs: number;
1307
+ /** RMS below which audio counts as silence. */
1308
+ silenceThreshold: number;
1309
+ }
1310
+ type CreateMicrophone = (config: MicrophoneConfig) => Promise<VoiceMicrophone>;
1311
+ type CreateSpeaker = (config: {
1312
+ audioFormat: VoiceAudioFormat;
1313
+ }) => VoiceSpeaker;
1314
+ /**
1315
+ * The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
1316
+ * live, WS-backed session keyed by `threadKey`. A structural subset of the
1317
+ * generated member, so passing `api.agents.<name>Voice` type-checks.
1318
+ * @experimental
1319
+ */
1320
+ type VoiceReference = FunctionReference<"stream", {
1321
+ threadKey: string;
1322
+ }, Record<string, unknown>>;
1323
+ /**
1324
+ * The lifecycle of a voice call, mirrored to the UI.
1325
+ * @experimental
1326
+ */
1327
+ type VoiceStatus = "idle" | "listening" | "speaking" | "thinking";
1328
+ /** A minimal structural subset of the DOM `WebSocket` the primitive drives. */
1329
+ interface VoiceSocket {
1330
+ binaryType: string;
1331
+ close: () => void;
1332
+ onclose: ((event: unknown) => void) | null;
1333
+ onerror: ((event: unknown) => void) | null;
1334
+ onmessage: ((event: {
1335
+ data: unknown;
1336
+ }) => void) | null;
1337
+ onopen: ((event: unknown) => void) | null;
1338
+ readonly readyState: number;
1339
+ send: (data: ArrayBufferView | ArrayBufferLike | string) => void;
1340
+ }
1341
+ type CreateSocket = (url: string) => VoiceSocket;
1342
+ /**
1343
+ * `VoiceAgentOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1344
+ * @experimental
1345
+ */
1346
+ interface VoiceAgentOptions {
1347
+ /** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
1348
+ client?: LunoraClient;
1349
+ /**
1350
+ * Advanced/test seam: build the microphone capture subsystem. Defaults to a
1351
+ * `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
1352
+ * Audio graph stays isolated (and mockable in a non-browser test env).
1353
+ */
1354
+ createMicrophone?: CreateMicrophone;
1355
+ /** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
1356
+ createSocket?: CreateSocket;
1357
+ /** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
1358
+ createSpeaker?: CreateSpeaker;
1359
+ /**
1360
+ * `DestroyRef` whose `onDestroy` tears the call down. Defaults to
1361
+ * `inject(DestroyRef)` — the calling component/service.
1362
+ */
1363
+ destroyRef?: DestroyRef;
1364
+ /** Consecutive above-`interruptThreshold` chunks that trigger a barge-in. Default `3`. */
1365
+ interruptChunks?: number;
1366
+ /** Input RMS above which the user is treated as barging in while the agent speaks. Default `0.15`. */
1367
+ interruptThreshold?: number;
1368
+ /** Milliseconds of silence (after speech) that auto-commits an utterance. Default `1200`. */
1369
+ silenceDurationMs?: number;
1370
+ /** Input RMS below which audio counts as silence. Default `0.01`. */
1371
+ silenceThreshold?: number;
1372
+ /** The thread to converse on — shared with the agent's text turns. Resolved when the call opens. */
1373
+ threadKey: string;
1374
+ /** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
1375
+ voice: VoiceReference;
1376
+ }
1377
+ /**
1378
+ * `VoiceAgentResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
1379
+ * @experimental
1380
+ */
1381
+ interface VoiceAgentResult {
1382
+ /** The current input RMS (0–1) — drive a mic level meter. */
1383
+ audioLevel: Signal<number>;
1384
+ /** `true` once the WS `ready` handshake completed. */
1385
+ connected: Signal<boolean>;
1386
+ /** Tear down the call: close the socket, stop the mic, release audio. Idempotent. */
1387
+ endCall: () => void;
1388
+ /** The last transport/pipeline error, or `undefined`. */
1389
+ error: Signal<Error | undefined>;
1390
+ /** The live assistant text for the in-flight turn (grows via deltas; finalized on done). */
1391
+ interimTranscript: Signal<string>;
1392
+ /** `true` while the mic is muted. */
1393
+ isMuted: Signal<boolean>;
1394
+ /** Send a typed turn (no audio) — a text message spoken back by the agent. */
1395
+ sendText: (text: string) => void;
1396
+ /** Open the mic, connect the socket, and start the conversation. Idempotent while active. */
1397
+ startCall: () => Promise<void>;
1398
+ /** The current call lifecycle. */
1399
+ status: Signal<VoiceStatus>;
1400
+ /** Mute/unmute the microphone. Returns the new muted state. */
1401
+ toggleMute: () => boolean;
1402
+ /** The last finalized user utterance (STT result). */
1403
+ transcript: Signal<string>;
1404
+ }
1405
+ /**
1406
+ * A first-class voice-call surface for a voice-enabled agent: it opens a
1407
+ * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1408
+ * streams the agent's synthesized speech back through the browser's audio output,
1409
+ * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1410
+ * `audioLevel`) to Angular signals. Pass the generated `api.agents.<name>Voice`
1411
+ * reference (never a string), matching `agentChat`'s reference-passing style. The
1412
+ * Angular counterpart to React's `useVoiceAgent`, re-expressed with signals; the
1413
+ * per-call connection lives in a closure variable (the primitive runs once per
1414
+ * component, so no signal-of-connection indirection is needed).
1415
+ *
1416
+ * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
1417
+ * turn detection and client-side RMS barge-in. The heavy Web Audio capture and
1418
+ * playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
1419
+ * `createSocket`) so the primitive is drivable outside a browser.
1420
+ *
1421
+ * Call from an injection context (component/service field or constructor); pass an
1422
+ * explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
1423
+ * @experimental
1424
+ */
1425
+ declare const voiceAgent: (options: VoiceAgentOptions) => VoiceAgentResult;
1426
+ 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,
1427
+ /**
1428
+ * The Angular adapter for Lunora.
1429
+ *
1430
+ * Thin, idiomatic glue over the framework-neutral `@lunora/client`. Angular
1431
+ * signals map directly onto Lunora's per-subscription deltas, so a live query is
1432
+ * just a `signal` the WebSocket writes to.
1433
+ *
1434
+ * `provideLunora` / `LUNORA_CLIENT` / `injectLunoraClient` are the injectable
1435
+ * provider carrying one `LunoraClient` (opens its socket lazily), wired once in the
1436
+ * application config. `liveQuery` is a live-query `signal` that opens a
1437
+ * subscription and updates on every delta, torn down automatically on
1438
+ * `DestroyRef.onDestroy`. `mutate` runs a mutation (optimistic updates + offline
1439
+ * queue pass through to the client). `connectionStatus` is a `signal` of the
1440
+ * aggregate live-socket status.
1441
+ */
1442
+ 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 };