@lunora/angular 1.0.0-alpha.6 → 1.0.0-alpha.61

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