@lunora/angular 1.0.0-alpha.7 → 1.0.0-alpha.71

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