@lunora/angular 1.0.0-alpha.7 → 1.0.0-alpha.9
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.
- package/README.md +2 -0
- package/dist/index.d.mts +820 -4
- package/dist/index.d.ts +820 -4
- package/dist/index.mjs +6 -0
- package/dist/packem_shared/agent-DDKvrG4u.mjs +31 -0
- package/dist/packem_shared/agentChat-C7kUEwO9.mjs +96 -0
- package/dist/packem_shared/agentState-C8GWf3t3.mjs +10 -0
- package/dist/packem_shared/agentToolEvents-sXgYggvi.mjs +59 -0
- package/dist/packem_shared/stream-PL64AghO.mjs +47 -0
- package/dist/packem_shared/voiceAgent-DwbrDnB9.mjs +401 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,504 @@
|
|
|
1
1
|
import { DestroyRef, Signal, InjectionToken, EnvironmentProviders } from '@angular/core';
|
|
2
|
-
import { LunoraClient, User, LunoraClientOptions, ConnectionStatus,
|
|
2
|
+
import { FunctionReference, LunoraClient, SubscriptionError, User, LunoraClientOptions, ConnectionStatus, Preloaded, ArgsOf, ReturnOf, MutationCallOptions, MutatorHandle } from '@lunora/client';
|
|
3
3
|
export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, LunoraClientOptions, MutationCallOptions, Preloaded, ReturnOf, SubscriptionError, Unsubscribe } from '@lunora/client';
|
|
4
4
|
import { PaginationStatus } from '@lunora/client/pagination';
|
|
5
5
|
import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
|
|
6
6
|
export { SKIP } from '@lunora/client/query';
|
|
7
|
+
/**
|
|
8
|
+
* The lifecycle status stored on an agent thread. Client-safe mirror of
|
|
9
|
+
* `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
|
|
10
|
+
* so this Angular entry never pulls in the server-only `@lunora/agent` module graph
|
|
11
|
+
* (the adapter stays Angular + `@lunora/client` only). Keep in sync with
|
|
12
|
+
* `packages/agent/src/types.ts`.
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "running";
|
|
16
|
+
/**
|
|
17
|
+
* The live thread record surfaced by the `agents:agentThread` query. A structural
|
|
18
|
+
* subset of the persisted thread row — every field beyond `status` is optional so
|
|
19
|
+
* the shape stays forgiving as the server schema grows. Keep in sync with the
|
|
20
|
+
* `agent_threads` table in `packages/agent/src/component.ts`.
|
|
21
|
+
* @experimental
|
|
22
|
+
*/
|
|
23
|
+
interface AgentThreadRecord {
|
|
24
|
+
createdAt?: number;
|
|
25
|
+
/** The failure message when `status === "error"`. */
|
|
26
|
+
error?: string;
|
|
27
|
+
/** The workflow instance id of the in-flight run — the handle `cancel` targets. */
|
|
28
|
+
instanceId?: string;
|
|
29
|
+
messageCount?: number;
|
|
30
|
+
/** The verified thread owner, when the run was started with one. */
|
|
31
|
+
owner?: string;
|
|
32
|
+
status: AgentThreadStatus;
|
|
33
|
+
title?: string;
|
|
34
|
+
updatedAt?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* One persisted (or optimistic) thread message, as `agents:agentMessages`
|
|
38
|
+
* surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
|
|
39
|
+
* re-declared here (rather than imported) so this Angular entry never pulls in the
|
|
40
|
+
* server-only `@lunora/agent` module graph. Keep in sync with the
|
|
41
|
+
* `agent_messages` table in `packages/agent/src/component.ts`.
|
|
42
|
+
* @experimental
|
|
43
|
+
*/
|
|
44
|
+
interface AgentChatMessage {
|
|
45
|
+
content: string;
|
|
46
|
+
createdAt?: number;
|
|
47
|
+
/**
|
|
48
|
+
* `true` for a client-side optimistic user message not yet acknowledged by
|
|
49
|
+
* the server. Cleared once the durable history carries the matching user turn.
|
|
50
|
+
*/
|
|
51
|
+
optimistic?: boolean;
|
|
52
|
+
role: "assistant" | "system" | "tool" | "user";
|
|
53
|
+
seq: number;
|
|
54
|
+
/** Approval lifecycle marker on a human-in-the-loop tool message. */
|
|
55
|
+
status?: "approved" | "awaiting_approval" | "rejected";
|
|
56
|
+
toolCallId?: string;
|
|
57
|
+
toolCalls?: ReadonlyArray<{
|
|
58
|
+
id: string;
|
|
59
|
+
input: unknown;
|
|
60
|
+
name: string;
|
|
61
|
+
}>;
|
|
62
|
+
toolName?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A live token delta streamed while a turn is generating. Client-safe mirror of
|
|
66
|
+
* `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed the chat surface's
|
|
67
|
+
* streaming text live and are never replayed; the persisted assistant message
|
|
68
|
+
* stays the single source of truth.
|
|
69
|
+
* @experimental
|
|
70
|
+
*/
|
|
71
|
+
interface AgentTokenDelta {
|
|
72
|
+
/** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
|
|
73
|
+
kind?: "token";
|
|
74
|
+
/** The incremental text chunk the model just produced. */
|
|
75
|
+
text: string;
|
|
76
|
+
/** The thread this delta belongs to. */
|
|
77
|
+
threadKey: string;
|
|
78
|
+
/** The zero-based index of the turn producing the delta. */
|
|
79
|
+
turn: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
|
|
83
|
+
* mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
|
|
84
|
+
* surfaced by `agentToolEvents`, ignored by the chat surface's streaming text.
|
|
85
|
+
* @experimental
|
|
86
|
+
*/
|
|
87
|
+
interface AgentProgressEvent {
|
|
88
|
+
/** The arbitrary, JSON-serializable payload the tool reported. */
|
|
89
|
+
data: unknown;
|
|
90
|
+
/** Discriminates the progress arm of {@link AgentLiveEvent}. */
|
|
91
|
+
kind: "progress";
|
|
92
|
+
/** The thread this event belongs to. */
|
|
93
|
+
threadKey: string;
|
|
94
|
+
/** The tool call this progress belongs to. */
|
|
95
|
+
toolCallId: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A single event on the agent's live-only channel — a streamed token delta or a
|
|
99
|
+
* tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
|
|
100
|
+
* Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
|
|
101
|
+
* it unset).
|
|
102
|
+
* @experimental
|
|
103
|
+
*/
|
|
104
|
+
type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
|
|
105
|
+
/**
|
|
106
|
+
* The `agents.agentThread` reference the primitive subscribes to for live thread
|
|
107
|
+
* state (status + the in-flight `instanceId`). A structural subset of the
|
|
108
|
+
* generated `api.agents` surface, so the whole generated `api` object is
|
|
109
|
+
* assignable.
|
|
110
|
+
* @experimental
|
|
111
|
+
*/
|
|
112
|
+
interface AgentApi {
|
|
113
|
+
agents: {
|
|
114
|
+
agentThread: FunctionReference<"query", {
|
|
115
|
+
key: string;
|
|
116
|
+
}, Record<string, unknown> | undefined>;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* `AgentOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
121
|
+
* @experimental
|
|
122
|
+
*/
|
|
123
|
+
interface AgentOptions {
|
|
124
|
+
/** The generated `api` — its `agents.agentThread` query drives live thread state. */
|
|
125
|
+
api: AgentApi;
|
|
126
|
+
/**
|
|
127
|
+
* Optional app mutation over the agent's cancel path
|
|
128
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
129
|
+
* When omitted (or no run is in flight) {@link AgentResult.cancel} is a no-op.
|
|
130
|
+
*/
|
|
131
|
+
cancel?: FunctionReference<"mutation">;
|
|
132
|
+
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
133
|
+
client?: LunoraClient;
|
|
134
|
+
/**
|
|
135
|
+
* `DestroyRef` whose `onDestroy` tears the live subscription down. Defaults to
|
|
136
|
+
* `inject(DestroyRef)` — the calling component/service.
|
|
137
|
+
*/
|
|
138
|
+
destroyRef?: DestroyRef;
|
|
139
|
+
/**
|
|
140
|
+
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
141
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
142
|
+
* {@link AgentOptions.runArgs} and the per-call args.
|
|
143
|
+
*/
|
|
144
|
+
run: FunctionReference<"mutation">;
|
|
145
|
+
/** Extra args merged into every `run` call (e.g. an `owner` or `title`). */
|
|
146
|
+
runArgs?: Record<string, unknown>;
|
|
147
|
+
/** The thread to observe and drive. */
|
|
148
|
+
threadKey: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* `AgentResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
152
|
+
* @experimental
|
|
153
|
+
*/
|
|
154
|
+
interface AgentResult {
|
|
155
|
+
/**
|
|
156
|
+
* Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
|
|
157
|
+
* no-op when no `cancel` mutation was supplied or no run is in flight.
|
|
158
|
+
*/
|
|
159
|
+
cancel: () => Promise<void>;
|
|
160
|
+
/** `true` while a `run` invocation is in flight. */
|
|
161
|
+
pending: Signal<boolean>;
|
|
162
|
+
/** Start (or continue) a run with a user message; extra args merge over `runArgs`. */
|
|
163
|
+
run: (input: string, args?: Record<string, unknown>) => Promise<void>;
|
|
164
|
+
/** The live thread status, or `undefined` before the thread exists. */
|
|
165
|
+
status: Signal<AgentThreadStatus | undefined>;
|
|
166
|
+
/** The live thread record (status, `instanceId`, …), or `undefined` before it exists. */
|
|
167
|
+
thread: Signal<AgentThreadRecord | undefined>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* A thin agent handle: live thread `status` plus `run` / `cancel`, without the
|
|
171
|
+
* chat message surface. Composes `subscription(api.agents.agentThread)` for live
|
|
172
|
+
* state and drives the run/cancel writes straight on the client — the Angular
|
|
173
|
+
* counterpart to React's `useAgent`, re-expressed with signals. For the full
|
|
174
|
+
* conversation surface (durable history + streaming + approvals) use `agentChat`.
|
|
175
|
+
*
|
|
176
|
+
* `run` and `cancel` stay generic over the app-defined mutations that wrap
|
|
177
|
+
* `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
|
|
178
|
+
* names beyond the `agents:*` surface.
|
|
179
|
+
*
|
|
180
|
+
* Call from an injection context (component/service field or constructor); pass an
|
|
181
|
+
* explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
|
|
182
|
+
* @experimental
|
|
183
|
+
*/
|
|
184
|
+
declare const agent: (options: AgentOptions) => AgentResult;
|
|
185
|
+
/** The `agents:agentMessages` reference — live durable thread history. */
|
|
186
|
+
type AgentMessagesReference$1 = FunctionReference<"query", {
|
|
187
|
+
key: string;
|
|
188
|
+
limit?: number;
|
|
189
|
+
}, ReadonlyArray<Record<string, unknown>>>;
|
|
190
|
+
/** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
|
|
191
|
+
type AgentApprovalReference = FunctionReference<"mutation", {
|
|
192
|
+
decision: "approve" | "reject";
|
|
193
|
+
instanceId: string;
|
|
194
|
+
note?: string;
|
|
195
|
+
threadKey: string;
|
|
196
|
+
toolCallId: string;
|
|
197
|
+
}, {
|
|
198
|
+
resolved: boolean;
|
|
199
|
+
}>;
|
|
200
|
+
/** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
|
|
201
|
+
type AgentThreadReference = FunctionReference<"query", {
|
|
202
|
+
key: string;
|
|
203
|
+
}, Record<string, unknown> | undefined>;
|
|
204
|
+
/**
|
|
205
|
+
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
206
|
+
* thread. Carries token deltas and — since `ctx.reportProgress` rides the same
|
|
207
|
+
* sink — tool progress events; this primitive consumes only the token arm.
|
|
208
|
+
* @experimental
|
|
209
|
+
*/
|
|
210
|
+
type AgentTokenStreamReference = FunctionReference<"stream", {
|
|
211
|
+
key: string;
|
|
212
|
+
}, AgentLiveEvent>;
|
|
213
|
+
/**
|
|
214
|
+
* The `agents.*` reference surface the chat primitive reads. A structural subset
|
|
215
|
+
* of the generated `api.agents`, so the whole generated `api` object is
|
|
216
|
+
* assignable.
|
|
217
|
+
* @experimental
|
|
218
|
+
*/
|
|
219
|
+
interface AgentChatApi {
|
|
220
|
+
agents: {
|
|
221
|
+
agentMessages: AgentMessagesReference$1;
|
|
222
|
+
agentResolveApproval: AgentApprovalReference;
|
|
223
|
+
agentThread: AgentThreadReference;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* `AgentChatOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
228
|
+
* @experimental
|
|
229
|
+
*/
|
|
230
|
+
interface AgentChatOptions {
|
|
231
|
+
/** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
|
|
232
|
+
api: AgentChatApi;
|
|
233
|
+
/**
|
|
234
|
+
* Optional app mutation over the agent's cancel path
|
|
235
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
236
|
+
* When omitted (or no run is in flight) {@link AgentChatResult.cancel} is a
|
|
237
|
+
* no-op.
|
|
238
|
+
*/
|
|
239
|
+
cancel?: FunctionReference<"mutation">;
|
|
240
|
+
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
241
|
+
client?: LunoraClient;
|
|
242
|
+
/**
|
|
243
|
+
* `DestroyRef` whose `onDestroy` tears the subscriptions + stream down. Defaults
|
|
244
|
+
* to `inject(DestroyRef)` — the calling component/service.
|
|
245
|
+
*/
|
|
246
|
+
destroyRef?: DestroyRef;
|
|
247
|
+
/** History depth forwarded to `agents:agentMessages`. */
|
|
248
|
+
limit?: number;
|
|
249
|
+
/**
|
|
250
|
+
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
251
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
252
|
+
* {@link AgentChatOptions.sendArgs} and the per-call args.
|
|
253
|
+
*/
|
|
254
|
+
send: FunctionReference<"mutation">;
|
|
255
|
+
/** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
|
|
256
|
+
sendArgs?: Record<string, unknown>;
|
|
257
|
+
/**
|
|
258
|
+
* Optional live token-delta stream — an app stream function that tees the
|
|
259
|
+
* agent's in-flight deltas. When omitted {@link AgentChatResult.streamingText}
|
|
260
|
+
* stays empty and the UI updates message-by-message from durable history.
|
|
261
|
+
*/
|
|
262
|
+
stream?: AgentTokenStreamReference;
|
|
263
|
+
/** The thread to observe and continue. */
|
|
264
|
+
threadKey: string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* `AgentChatResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
268
|
+
* @experimental
|
|
269
|
+
*/
|
|
270
|
+
interface AgentChatResult {
|
|
271
|
+
/** Approve a paused human-in-the-loop tool call (optionally with a note). */
|
|
272
|
+
approve: (toolCallId: string, note?: string) => Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
|
|
275
|
+
* no-op when no `cancel` mutation was supplied or no run is in flight.
|
|
276
|
+
*/
|
|
277
|
+
cancel: () => Promise<void>;
|
|
278
|
+
/** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
|
|
279
|
+
messages: Signal<ReadonlyArray<AgentChatMessage>>;
|
|
280
|
+
/** Reject a paused human-in-the-loop tool call (optionally with a reason). */
|
|
281
|
+
reject: (toolCallId: string, note?: string) => Promise<void>;
|
|
282
|
+
/** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
|
|
283
|
+
send: (input: string, args?: Record<string, unknown>) => Promise<void>;
|
|
284
|
+
/** The live thread status, or `undefined` before the thread exists. */
|
|
285
|
+
status: Signal<AgentThreadStatus | undefined>;
|
|
286
|
+
/** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
|
|
287
|
+
streamingText: Signal<string>;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* A first-class agent chat surface: live durable history + in-flight token
|
|
291
|
+
* streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
|
|
292
|
+
* the Angular counterpart to React's `useAgentChat`, re-expressed with signals.
|
|
293
|
+
*
|
|
294
|
+
* It composes the existing primitives rather than adding transport:
|
|
295
|
+
* `subscription(api.agents.agentMessages)` for durable history,
|
|
296
|
+
* `subscription(api.agents.agentThread)` for live status + the in-flight
|
|
297
|
+
* `instanceId`, {@link stream} over an app token stream for in-flight deltas, and
|
|
298
|
+
* the client's own `mutation` for the writes (`api.agents.agentResolveApproval` for
|
|
299
|
+
* approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*` surface
|
|
300
|
+
* is hard-coded — `send`/`cancel`/`stream` stay generic references.
|
|
301
|
+
*
|
|
302
|
+
* A `send` optimistically appends the user turn so it renders immediately; the
|
|
303
|
+
* optimistic row clears once the durable history carries the acknowledged turn.
|
|
304
|
+
* `streamingText` is live-only: it holds the current turn's streamed text and
|
|
305
|
+
* empties as soon as that turn's assistant message lands in `messages` (the
|
|
306
|
+
* persisted message is the source of truth), consistent with the loop's
|
|
307
|
+
* replay-safe, live-only delta design.
|
|
308
|
+
*
|
|
309
|
+
* Call from an injection context (component/service field or constructor); pass an
|
|
310
|
+
* explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
|
|
311
|
+
* @experimental
|
|
312
|
+
*/
|
|
313
|
+
declare const agentChat: (options: AgentChatOptions) => AgentChatResult;
|
|
314
|
+
/**
|
|
315
|
+
* The `agents.agentState` reference the primitive subscribes to for the thread's
|
|
316
|
+
* live synced state. A structural subset of the generated `api.agents` surface
|
|
317
|
+
* (like `AgentApi` for `agentThread`), so the whole generated `api` object is
|
|
318
|
+
* assignable. Client-safe: no `@lunora/agent` import — the per-agent state type is
|
|
319
|
+
* mirrored by the primitive's generic `T`, since codegen pins the reference return
|
|
320
|
+
* as an optional record (it never evaluates agent config).
|
|
321
|
+
* @experimental
|
|
322
|
+
*/
|
|
323
|
+
interface AgentStateApi {
|
|
324
|
+
agents: {
|
|
325
|
+
agentState: FunctionReference<"query", {
|
|
326
|
+
key: string;
|
|
327
|
+
}, Record<string, unknown> | undefined>;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* `AgentStateOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
332
|
+
* @experimental
|
|
333
|
+
*/
|
|
334
|
+
interface AgentStateOptions {
|
|
335
|
+
/** The generated `api` — its `agents.agentState` query drives live thread state. */
|
|
336
|
+
api: AgentStateApi;
|
|
337
|
+
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
338
|
+
client?: LunoraClient;
|
|
339
|
+
/**
|
|
340
|
+
* `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to
|
|
341
|
+
* `inject(DestroyRef)` — the calling component/service.
|
|
342
|
+
*/
|
|
343
|
+
destroyRef?: DestroyRef;
|
|
344
|
+
/** The thread whose synced state to observe. */
|
|
345
|
+
threadKey: string;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* `AgentStateResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
349
|
+
* @experimental
|
|
350
|
+
*/
|
|
351
|
+
interface AgentStateResult<T> {
|
|
352
|
+
/** The subscription error, if the live channel reported one. */
|
|
353
|
+
error: Signal<SubscriptionError | undefined>;
|
|
354
|
+
/** The live synced state, or `undefined` before it is seeded/first pushed. */
|
|
355
|
+
state: Signal<T | undefined>;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Subscribe to an agent thread's synced state — the `setState`-style value a tool
|
|
359
|
+
* writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
|
|
360
|
+
* thin wrapper over `subscription(api.agents.agentState, { key })`: the server
|
|
361
|
+
* pushes a fresh frame whenever the state changes (the dedicated query's per-socket
|
|
362
|
+
* JSON memo suppresses no-op pushes on unrelated thread writes), so `state` updates
|
|
363
|
+
* only on a real `setState`. The Angular counterpart to React's `useAgentState`,
|
|
364
|
+
* re-expressed with signals.
|
|
365
|
+
*
|
|
366
|
+
* Generic over the app's state shape (`agentState<SupportState>(...)`, itself a
|
|
367
|
+
* record) — the reference is typed as an optional record because codegen cannot see
|
|
368
|
+
* the per-agent state type; the generic casts to `T`. The `extends` bound (not a
|
|
369
|
+
* bare unbounded type parameter) is required: this `.ts` file is parsed JSX-aware by
|
|
370
|
+
* the bundler, where an unbounded type-param arrow is ambiguous with a JSX element.
|
|
371
|
+
*
|
|
372
|
+
* Call from an injection context (component/service field or constructor); pass an
|
|
373
|
+
* explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
|
|
374
|
+
* @experimental
|
|
375
|
+
*/
|
|
376
|
+
declare const agentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: AgentStateOptions) => AgentStateResult<T>;
|
|
377
|
+
/** The `agents:agentMessages` reference — live durable thread history. */
|
|
378
|
+
type AgentMessagesReference = FunctionReference<"query", {
|
|
379
|
+
key: string;
|
|
380
|
+
limit?: number;
|
|
381
|
+
}, ReadonlyArray<Record<string, unknown>>>;
|
|
382
|
+
/**
|
|
383
|
+
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
384
|
+
* thread. Carries token deltas and tool progress events; this primitive consumes
|
|
385
|
+
* only the progress arm (`kind === "progress"`).
|
|
386
|
+
*/
|
|
387
|
+
type AgentLiveStreamReference = FunctionReference<"stream", {
|
|
388
|
+
key: string;
|
|
389
|
+
}, AgentLiveEvent>;
|
|
390
|
+
/**
|
|
391
|
+
* The `agents.*` reference surface the tool-events primitive reads. A structural
|
|
392
|
+
* subset of the generated `api.agents`, so the whole generated `api` object is
|
|
393
|
+
* assignable.
|
|
394
|
+
* @experimental
|
|
395
|
+
*/
|
|
396
|
+
interface AgentToolEventsApi {
|
|
397
|
+
agents: {
|
|
398
|
+
agentMessages: AgentMessagesReference;
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* `AgentToolEventsOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
403
|
+
* @experimental
|
|
404
|
+
*/
|
|
405
|
+
interface AgentToolEventsOptions {
|
|
406
|
+
/** The generated `api` — its `agents.agentMessages` query provides the durable tool lifecycle. */
|
|
407
|
+
api: AgentToolEventsApi;
|
|
408
|
+
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
409
|
+
client?: LunoraClient;
|
|
410
|
+
/**
|
|
411
|
+
* `DestroyRef` whose `onDestroy` tears the subscription + stream down. Defaults
|
|
412
|
+
* to `inject(DestroyRef)` — the calling component/service.
|
|
413
|
+
*/
|
|
414
|
+
destroyRef?: DestroyRef;
|
|
415
|
+
/** History depth forwarded to `agents:agentMessages`. */
|
|
416
|
+
limit?: number;
|
|
417
|
+
/**
|
|
418
|
+
* Optional live event stream — the same app stream function `agentChat` uses.
|
|
419
|
+
* When supplied, ephemeral `ctx.reportProgress(...)` events for the thread are
|
|
420
|
+
* surfaced as `{ type: "progress" }` entries; when omitted only the durable
|
|
421
|
+
* lifecycle (call / result / awaiting-approval) is returned.
|
|
422
|
+
*/
|
|
423
|
+
stream?: AgentLiveStreamReference;
|
|
424
|
+
/** The thread whose tool activity to observe. */
|
|
425
|
+
threadKey: string;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* A single tool-lifecycle event for a thread. The durable arms
|
|
429
|
+
* (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
|
|
430
|
+
* and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
|
|
431
|
+
* stream and has no `seq`. Discriminate on `type`.
|
|
432
|
+
* @experimental
|
|
433
|
+
*/
|
|
434
|
+
type AgentToolEvent = {
|
|
435
|
+
data: unknown;
|
|
436
|
+
toolCallId: string;
|
|
437
|
+
type: "progress";
|
|
438
|
+
} | {
|
|
439
|
+
input: unknown;
|
|
440
|
+
seq: number;
|
|
441
|
+
toolCallId: string;
|
|
442
|
+
toolName: string;
|
|
443
|
+
type: "call";
|
|
444
|
+
} | {
|
|
445
|
+
output: string;
|
|
446
|
+
seq: number;
|
|
447
|
+
status?: "approved" | "rejected";
|
|
448
|
+
toolCallId?: string;
|
|
449
|
+
toolName?: string;
|
|
450
|
+
type: "result";
|
|
451
|
+
} | {
|
|
452
|
+
seq: number;
|
|
453
|
+
toolCallId?: string;
|
|
454
|
+
toolName?: string;
|
|
455
|
+
type: "awaiting-approval";
|
|
456
|
+
};
|
|
457
|
+
/**
|
|
458
|
+
* `AgentToolEventsResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
459
|
+
* @experimental
|
|
460
|
+
*/
|
|
461
|
+
interface AgentToolEventsResult {
|
|
462
|
+
/**
|
|
463
|
+
* The thread's tool events: the durable lifecycle (oldest first, by `seq`)
|
|
464
|
+
* followed by any in-flight ephemeral progress events, recomputed from the live
|
|
465
|
+
* subscription + stream. Treat as derived, not identity-stable.
|
|
466
|
+
*/
|
|
467
|
+
events: Signal<ReadonlyArray<AgentToolEvent>>;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* A focused view of a thread's tool activity: tool calls, their results,
|
|
471
|
+
* human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
|
|
472
|
+
* without the full chat message surface. The Angular counterpart to React's
|
|
473
|
+
* `useAgentToolEvents`, re-expressed as a `computed` signal.
|
|
474
|
+
*
|
|
475
|
+
* It composes the existing primitives rather than adding transport:
|
|
476
|
+
* `subscription(api.agents.agentMessages)` for the durable lifecycle and
|
|
477
|
+
* {@link stream} over the optional app event stream for ephemeral progress.
|
|
478
|
+
* Progress events are live-only (the durable path never emits them): they ride the
|
|
479
|
+
* same sink as token deltas and are surfaced here, correlated to their tool call by
|
|
480
|
+
* `toolCallId`. For the conversational surface (messages + streaming text +
|
|
481
|
+
* approvals) use `agentChat`; this primitive is the tool-observability slice.
|
|
482
|
+
*
|
|
483
|
+
* Call from an injection context (component/service field or constructor); pass an
|
|
484
|
+
* explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
|
|
485
|
+
* @experimental
|
|
486
|
+
*/
|
|
487
|
+
declare const agentToolEvents: (options: AgentToolEventsOptions) => AgentToolEventsResult;
|
|
488
|
+
/**
|
|
489
|
+
* `AuthOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
490
|
+
* @experimental
|
|
491
|
+
*/
|
|
7
492
|
interface AuthOptions {
|
|
8
493
|
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
9
494
|
client?: LunoraClient;
|
|
10
495
|
/** `DestroyRef` whose `onDestroy` removes the listeners. Defaults to `inject(DestroyRef)`. */
|
|
11
496
|
destroyRef?: DestroyRef;
|
|
12
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* `AuthResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
500
|
+
* @experimental
|
|
501
|
+
*/
|
|
13
502
|
interface AuthResult {
|
|
14
503
|
/** Set the auth token (sign-in / sign-out). */
|
|
15
504
|
setToken: (token: string | null) => void;
|
|
@@ -32,6 +521,7 @@ interface AuthResult {
|
|
|
32
521
|
* ```ts
|
|
33
522
|
* const { token, user, setToken } = auth();
|
|
34
523
|
* ```
|
|
524
|
+
* @experimental
|
|
35
525
|
*/
|
|
36
526
|
declare const auth: (options?: AuthOptions) => AuthResult;
|
|
37
527
|
/**
|
|
@@ -44,6 +534,7 @@ declare const auth: (options?: AuthOptions) => AuthResult;
|
|
|
44
534
|
* {@link provideLunora}: it builds one same-origin browser client (which opens
|
|
45
535
|
* its WebSocket lazily on the first subscription). Call {@link provideLunora} to
|
|
46
536
|
* point it at a remote URL or hand it a pre-built client.
|
|
537
|
+
* @experimental
|
|
47
538
|
*/
|
|
48
539
|
declare const LUNORA_CLIENT: InjectionToken<LunoraClient>;
|
|
49
540
|
/**
|
|
@@ -51,6 +542,7 @@ declare const LUNORA_CLIENT: InjectionToken<LunoraClient>;
|
|
|
51
542
|
* except `url` is optional — it defaults to the page origin in the browser (and to
|
|
52
543
|
* `""` on the server; pass an explicit `url` for SSR data-loading — see
|
|
53
544
|
* {@link sameOriginUrl}).
|
|
545
|
+
* @experimental
|
|
54
546
|
*/
|
|
55
547
|
type ProvideLunoraOptions = Omit<LunoraClientOptions, "url"> & {
|
|
56
548
|
url?: string;
|
|
@@ -69,6 +561,7 @@ type ProvideLunoraOptions = Omit<LunoraClientOptions, "url"> & {
|
|
|
69
561
|
* Pass {@link LunoraClientOptions} to configure a fresh client (URL defaults to
|
|
70
562
|
* the page origin), or hand in an already-constructed {@link LunoraClient} to
|
|
71
563
|
* share one instance (e.g. a client you also preload against during SSR).
|
|
564
|
+
* @experimental
|
|
72
565
|
*/
|
|
73
566
|
declare const provideLunora: (optionsOrClient?: LunoraClient | ProvideLunoraOptions) => EnvironmentProviders;
|
|
74
567
|
/**
|
|
@@ -82,8 +575,13 @@ declare const provideLunora: (optionsOrClient?: LunoraClient | ProvideLunoraOpti
|
|
|
82
575
|
* private readonly client = injectLunoraClient();
|
|
83
576
|
* send = (text: string) => this.client.mutation(api.messages.send, { text });
|
|
84
577
|
* ```
|
|
578
|
+
* @experimental
|
|
85
579
|
*/
|
|
86
580
|
declare const injectLunoraClient: () => LunoraClient;
|
|
581
|
+
/**
|
|
582
|
+
* `ConnectionStatusOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
583
|
+
* @experimental
|
|
584
|
+
*/
|
|
87
585
|
interface ConnectionStatusOptions {
|
|
88
586
|
/** Client to observe. Defaults to the injected `LUNORA_CLIENT`. */
|
|
89
587
|
client?: LunoraClient;
|
|
@@ -98,12 +596,23 @@ interface ConnectionStatusOptions {
|
|
|
98
596
|
*
|
|
99
597
|
* The listener is removed when the owning `DestroyRef` fires. Call from an
|
|
100
598
|
* injection context (component/service field or constructor).
|
|
599
|
+
* @experimental
|
|
101
600
|
*/
|
|
102
601
|
declare const connectionStatus: (options?: ConnectionStatusOptions) => Signal<ConnectionStatus>;
|
|
103
|
-
/**
|
|
602
|
+
/**
|
|
603
|
+
* The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags.
|
|
604
|
+
* @experimental
|
|
605
|
+
*/
|
|
104
606
|
type FlagValue = boolean | number | string | Record<string, unknown> | unknown[] | null;
|
|
105
|
-
/**
|
|
607
|
+
/**
|
|
608
|
+
* Targeting context bag forwarded to the OpenFeature provider.
|
|
609
|
+
* @experimental
|
|
610
|
+
*/
|
|
106
611
|
type FlagContext = Record<string, unknown>;
|
|
612
|
+
/**
|
|
613
|
+
* `FlagOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
614
|
+
* @experimental
|
|
615
|
+
*/
|
|
107
616
|
interface FlagOptions {
|
|
108
617
|
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
109
618
|
client?: LunoraClient;
|
|
@@ -131,8 +640,13 @@ interface FlagOptions {
|
|
|
131
640
|
* ```ts
|
|
132
641
|
* readonly darkMode = flag("dark-mode", false);
|
|
133
642
|
* ```
|
|
643
|
+
* @experimental
|
|
134
644
|
*/
|
|
135
645
|
declare const flag: <T extends FlagValue>(key: string, defaultValue: T, options?: FlagOptions) => Signal<T>;
|
|
646
|
+
/**
|
|
647
|
+
* `FlagsOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
648
|
+
* @experimental
|
|
649
|
+
*/
|
|
136
650
|
interface FlagsOptions {
|
|
137
651
|
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
138
652
|
client?: LunoraClient;
|
|
@@ -155,14 +669,23 @@ interface FlagsOptions {
|
|
|
155
669
|
* ```ts
|
|
156
670
|
* readonly features = flags({ "dark-mode": false, "new-editor": false });
|
|
157
671
|
* ```
|
|
672
|
+
* @experimental
|
|
158
673
|
*/
|
|
159
674
|
declare const flags: <T extends Record<string, FlagValue>>(flagDefaults: T, options?: FlagsOptions) => Signal<T>;
|
|
675
|
+
/**
|
|
676
|
+
* `HydratePreloadedOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
677
|
+
* @experimental
|
|
678
|
+
*/
|
|
160
679
|
interface HydratePreloadedOptions {
|
|
161
680
|
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
162
681
|
client?: LunoraClient;
|
|
163
682
|
/** `DestroyRef` whose `onDestroy` tears the subscription down. Defaults to `inject(DestroyRef)`. */
|
|
164
683
|
destroyRef?: DestroyRef;
|
|
165
684
|
}
|
|
685
|
+
/**
|
|
686
|
+
* `HydratePreloadedResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
687
|
+
* @experimental
|
|
688
|
+
*/
|
|
166
689
|
interface HydratePreloadedResult<T> {
|
|
167
690
|
/** The latest value pushed by the server. Seeded synchronously from the preloaded value. */
|
|
168
691
|
data: Signal<T | undefined>;
|
|
@@ -186,8 +709,13 @@ interface HydratePreloadedResult<T> {
|
|
|
186
709
|
* ```ts
|
|
187
710
|
* readonly { data, error } = hydratePreloaded(preloadedMessages);
|
|
188
711
|
* ```
|
|
712
|
+
* @experimental
|
|
189
713
|
*/
|
|
190
714
|
declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, options?: HydratePreloadedOptions) => HydratePreloadedResult<T>;
|
|
715
|
+
/**
|
|
716
|
+
* `LiveQueryOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
717
|
+
* @experimental
|
|
718
|
+
*/
|
|
191
719
|
interface LiveQueryOptions {
|
|
192
720
|
/**
|
|
193
721
|
* Client to bind to. Defaults to the injected `LUNORA_CLIENT`; pass one
|
|
@@ -233,8 +761,13 @@ interface LiveQueryOptions {
|
|
|
233
761
|
* short-circuit — no network call, no socket; the signal stays `undefined`. To
|
|
234
762
|
* call outside an injection context (e.g. lazily in `ngOnInit`), supply `client`
|
|
235
763
|
* and `destroyRef` via {@link LiveQueryOptions}.
|
|
764
|
+
* @experimental
|
|
236
765
|
*/
|
|
237
766
|
declare const liveQuery: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip", options?: LiveQueryOptions) => Signal<ReturnOf<F> | undefined>;
|
|
767
|
+
/**
|
|
768
|
+
* `MutateOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
769
|
+
* @experimental
|
|
770
|
+
*/
|
|
238
771
|
interface MutateOptions<F extends FunctionReference> extends MutationCallOptions<unknown, unknown, ArgsOf<F>> {
|
|
239
772
|
/**
|
|
240
773
|
* Client to run the mutation on. Defaults to the injected `LUNORA_CLIENT`.
|
|
@@ -261,8 +794,13 @@ interface MutateOptions<F extends FunctionReference> extends MutationCallOptions
|
|
|
261
794
|
*
|
|
262
795
|
* When called from within an injection context you may omit `client` and let it
|
|
263
796
|
* resolve from the injector.
|
|
797
|
+
* @experimental
|
|
264
798
|
*/
|
|
265
799
|
declare const mutate: <F extends FunctionReference>(reference: F, args: ArgsOf<F>, options?: MutateOptions<F>) => Promise<ReturnOf<F>>;
|
|
800
|
+
/**
|
|
801
|
+
* `MutatorResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
802
|
+
* @experimental
|
|
803
|
+
*/
|
|
266
804
|
interface MutatorResult<TArgs> {
|
|
267
805
|
/** The latest invocation's error, or `undefined`. */
|
|
268
806
|
error: Signal<Error | undefined>;
|
|
@@ -291,6 +829,7 @@ interface MutatorResult<TArgs> {
|
|
|
291
829
|
* private readonly collection = bindMutators(collections);
|
|
292
830
|
* readonly mutator = mutator(this.collection.insert);
|
|
293
831
|
* ```
|
|
832
|
+
* @experimental
|
|
294
833
|
*/
|
|
295
834
|
declare const mutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorResult<TArgs>;
|
|
296
835
|
/** The args a paginated query exposes minus the framework-supplied page cursor. */
|
|
@@ -301,6 +840,10 @@ type PageItemOf<F extends FunctionReference> = ReturnTypeOf<F> extends {
|
|
|
301
840
|
} ? T : unknown;
|
|
302
841
|
type ArgsOfRaw<F extends FunctionReference> = F extends FunctionReference<"query", infer A> ? A : never;
|
|
303
842
|
type ReturnTypeOf<F extends FunctionReference> = F extends FunctionReference<"query", unknown, infer R> ? R : never;
|
|
843
|
+
/**
|
|
844
|
+
* Options for the paginated query — part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
845
|
+
* @experimental
|
|
846
|
+
*/
|
|
304
847
|
interface PaginatedQueryOptions {
|
|
305
848
|
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
306
849
|
client?: LunoraClient;
|
|
@@ -311,6 +854,10 @@ interface PaginatedQueryOptions {
|
|
|
311
854
|
/** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
|
|
312
855
|
shardKey?: string;
|
|
313
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* `PaginatedQueryResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
859
|
+
* @experimental
|
|
860
|
+
*/
|
|
314
861
|
interface PaginatedQueryResult<T> {
|
|
315
862
|
/** `true` while the first page or a `loadMore` page is in flight. */
|
|
316
863
|
isLoading: Signal<boolean>;
|
|
@@ -321,6 +868,10 @@ interface PaginatedQueryResult<T> {
|
|
|
321
868
|
/** The pagination status. */
|
|
322
869
|
status: Signal<PaginationStatus>;
|
|
323
870
|
}
|
|
871
|
+
/**
|
|
872
|
+
* `InfiniteQueryResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
873
|
+
* @experimental
|
|
874
|
+
*/
|
|
324
875
|
interface InfiniteQueryResult<T> {
|
|
325
876
|
/** Request the next page. A no-op unless `status === "CanLoadMore"`. */
|
|
326
877
|
fetchNextPage: (numberItems?: number) => void;
|
|
@@ -350,6 +901,7 @@ interface InfiniteQueryResult<T> {
|
|
|
350
901
|
* ```ts
|
|
351
902
|
* readonly messages = paginatedQuery(api.messages.list, {}, { initialNumItems: 20 });
|
|
352
903
|
* ```
|
|
904
|
+
* @experimental
|
|
353
905
|
*/
|
|
354
906
|
declare const paginatedQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip", options: PaginatedQueryOptions) => PaginatedQueryResult<PageItemOf<F>>;
|
|
355
907
|
/**
|
|
@@ -363,16 +915,29 @@ declare const paginatedQuery: <F extends FunctionReference>(reference: F, args:
|
|
|
363
915
|
* ```ts
|
|
364
916
|
* readonly feed = infiniteQuery(api.messages.list, {}, { initialNumItems: 20 });
|
|
365
917
|
* ```
|
|
918
|
+
* @experimental
|
|
366
919
|
*/
|
|
367
920
|
declare const infiniteQuery: <F extends FunctionReference>(reference: F, args: PaginatedArgs<F> | "skip", options: PaginatedQueryOptions) => InfiniteQueryResult<PageItemOf<F>>;
|
|
921
|
+
/**
|
|
922
|
+
* `HeartbeatReference` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
923
|
+
* @experimental
|
|
924
|
+
*/
|
|
368
925
|
type HeartbeatReference = FunctionReference<"mutation", {
|
|
369
926
|
data?: Record<string, unknown>;
|
|
370
927
|
roomId: string;
|
|
371
928
|
sessionId: string;
|
|
372
929
|
}>;
|
|
930
|
+
/**
|
|
931
|
+
* `ListPresentReference` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
932
|
+
* @experimental
|
|
933
|
+
*/
|
|
373
934
|
type ListPresentReference = FunctionReference<"query", {
|
|
374
935
|
roomId: string;
|
|
375
936
|
}>;
|
|
937
|
+
/**
|
|
938
|
+
* `PresenceOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
939
|
+
* @experimental
|
|
940
|
+
*/
|
|
376
941
|
interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentReference> {
|
|
377
942
|
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
378
943
|
client?: LunoraClient;
|
|
@@ -394,6 +959,10 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
|
|
|
394
959
|
/** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
|
|
395
960
|
shardKey?: string;
|
|
396
961
|
}
|
|
962
|
+
/**
|
|
963
|
+
* `PresenceResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
964
|
+
* @experimental
|
|
965
|
+
*/
|
|
397
966
|
interface PresenceResult<L extends ListPresentReference> {
|
|
398
967
|
/** The present members for the room. `undefined` until the first push. */
|
|
399
968
|
present: Signal<ReturnOf<L> | undefined>;
|
|
@@ -416,8 +985,13 @@ interface PresenceResult<L extends ListPresentReference> {
|
|
|
416
985
|
* listPresent: api.presence.listPresent,
|
|
417
986
|
* });
|
|
418
987
|
* ```
|
|
988
|
+
* @experimental
|
|
419
989
|
*/
|
|
420
990
|
declare const presence: <H extends HeartbeatReference, L extends ListPresentReference>(roomId: string, options: PresenceOptions<H, L>) => PresenceResult<L>;
|
|
991
|
+
/**
|
|
992
|
+
* `RateLimitOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
993
|
+
* @experimental
|
|
994
|
+
*/
|
|
421
995
|
interface RateLimitOptions {
|
|
422
996
|
/**
|
|
423
997
|
* `DestroyRef` whose `onDestroy` clears the interval. Defaults to
|
|
@@ -432,6 +1006,10 @@ interface RateLimitOptions {
|
|
|
432
1006
|
*/
|
|
433
1007
|
tickMs?: number;
|
|
434
1008
|
}
|
|
1009
|
+
/**
|
|
1010
|
+
* `RateLimitResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
1011
|
+
* @experimental
|
|
1012
|
+
*/
|
|
435
1013
|
interface RateLimitResult {
|
|
436
1014
|
/** Would consuming `count` (default 1) succeed right now? Does not consume. */
|
|
437
1015
|
check: (count?: number) => boolean;
|
|
@@ -458,8 +1036,67 @@ interface RateLimitResult {
|
|
|
458
1036
|
* ```ts
|
|
459
1037
|
* readonly sendLimit = rateLimit({ kind: "token bucket", period: 1000, rate: 10 });
|
|
460
1038
|
* ```
|
|
1039
|
+
* @experimental
|
|
461
1040
|
*/
|
|
462
1041
|
declare const rateLimit: (config: RateLimitConfig, options?: RateLimitOptions) => RateLimitResult;
|
|
1042
|
+
/**
|
|
1043
|
+
* The lifecycle of a stream the primitive is observing.
|
|
1044
|
+
* @experimental
|
|
1045
|
+
*/
|
|
1046
|
+
type StreamStatus = "complete" | "error" | "idle" | "streaming";
|
|
1047
|
+
/**
|
|
1048
|
+
* `StreamOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
1049
|
+
* @experimental
|
|
1050
|
+
*/
|
|
1051
|
+
interface StreamOptions {
|
|
1052
|
+
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
1053
|
+
client?: LunoraClient;
|
|
1054
|
+
/**
|
|
1055
|
+
* `DestroyRef` whose `onDestroy` cancels the stream. Defaults to
|
|
1056
|
+
* `inject(DestroyRef)` — the calling component/service.
|
|
1057
|
+
*/
|
|
1058
|
+
destroyRef?: DestroyRef;
|
|
1059
|
+
/** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
|
|
1060
|
+
maxBuffer?: number;
|
|
1061
|
+
/** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
|
|
1062
|
+
shardKey?: string;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* `StreamResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
1066
|
+
* @experimental
|
|
1067
|
+
*/
|
|
1068
|
+
interface StreamResult<T> {
|
|
1069
|
+
/** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
|
|
1070
|
+
cancel: () => void;
|
|
1071
|
+
/** Chunks the server has pushed so far, in arrival order. */
|
|
1072
|
+
chunks: Signal<ReadonlyArray<T>>;
|
|
1073
|
+
/** The stream error, or `undefined`. */
|
|
1074
|
+
error: Signal<Error | undefined>;
|
|
1075
|
+
/** The stream lifecycle. */
|
|
1076
|
+
status: Signal<StreamStatus>;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Subscribe to a streaming query. Returns the chunks pushed so far plus a
|
|
1080
|
+
* lifecycle status and a `cancel` function, all as signals.
|
|
1081
|
+
*
|
|
1082
|
+
* Unlike `subscription`, which tracks the latest value, `stream` accumulates every
|
|
1083
|
+
* chunk the server pushes — use it for token-by-token deltas and other append-only
|
|
1084
|
+
* feeds. Pass `"skip"` as `args` to keep the primitive mounted without opening a
|
|
1085
|
+
* stream (mirrors `subscription`); the stream tears down when the owning
|
|
1086
|
+
* `DestroyRef` fires. The Angular counterpart to React's `useStream`, re-expressed
|
|
1087
|
+
* with signals.
|
|
1088
|
+
*
|
|
1089
|
+
* Call from an injection context (component/service field or constructor):
|
|
1090
|
+
* ```ts
|
|
1091
|
+
* readonly tokens = stream(api.chat.liveEvents, { key: "thread-1" });
|
|
1092
|
+
* ```
|
|
1093
|
+
* @experimental
|
|
1094
|
+
*/
|
|
1095
|
+
declare const stream: <F extends FunctionReference<"stream">>(reference: F, args: ArgsOf<F> | "skip", options?: StreamOptions) => StreamResult<ReturnOf<F>>;
|
|
1096
|
+
/**
|
|
1097
|
+
* `SubscriptionOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
1098
|
+
* @experimental
|
|
1099
|
+
*/
|
|
463
1100
|
interface SubscriptionOptions {
|
|
464
1101
|
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
465
1102
|
client?: LunoraClient;
|
|
@@ -476,6 +1113,10 @@ interface SubscriptionOptions {
|
|
|
476
1113
|
/** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
|
|
477
1114
|
shardKey?: string;
|
|
478
1115
|
}
|
|
1116
|
+
/**
|
|
1117
|
+
* `SubscriptionResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
1118
|
+
* @experimental
|
|
1119
|
+
*/
|
|
479
1120
|
interface SubscriptionResult<T> {
|
|
480
1121
|
/** The latest value pushed by the server. `undefined` before the first frame. */
|
|
481
1122
|
data: Signal<T | undefined>;
|
|
@@ -497,6 +1138,181 @@ interface SubscriptionResult<T> {
|
|
|
497
1138
|
* ```ts
|
|
498
1139
|
* readonly stream = subscription(api.events.stream, { roomId: "general" });
|
|
499
1140
|
* ```
|
|
1141
|
+
* @experimental
|
|
500
1142
|
*/
|
|
501
1143
|
declare const subscription: <F extends FunctionReference>(reference: F, args: ArgsOf<F> | "skip", options?: SubscriptionOptions) => SubscriptionResult<ReturnOf<F>>;
|
|
502
|
-
|
|
1144
|
+
/**
|
|
1145
|
+
* Browser Web Audio subsystems for `voiceAgent` — the default microphone capture
|
|
1146
|
+
* and speaker playback implementations injected into the primitive via its
|
|
1147
|
+
* `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
|
|
1148
|
+
* heavy Web Audio graph (and its structural DOM typings) stays isolated from the
|
|
1149
|
+
* primitive's transport + signal-state logic and remains mockable in a
|
|
1150
|
+
* non-browser test env.
|
|
1151
|
+
*/
|
|
1152
|
+
/**
|
|
1153
|
+
* The negotiated audio format the voice DO streams back. Mirrors
|
|
1154
|
+
* `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
|
|
1155
|
+
* imported) so this Angular package never pulls in the server-only `@lunora/agent`
|
|
1156
|
+
* module graph.
|
|
1157
|
+
* @experimental
|
|
1158
|
+
*/
|
|
1159
|
+
type VoiceAudioFormat = "mp3" | "wav";
|
|
1160
|
+
/** Captures microphone audio and reports level / turn boundaries back to the primitive. */
|
|
1161
|
+
interface VoiceMicrophone {
|
|
1162
|
+
/** Mute/unmute the mic without tearing down the capture graph. */
|
|
1163
|
+
setMuted: (muted: boolean) => void;
|
|
1164
|
+
/** Stop capture and release the media stream + audio graph. */
|
|
1165
|
+
stop: () => void;
|
|
1166
|
+
}
|
|
1167
|
+
/** Plays the server's streamed audio chunks and supports a mid-utterance barge-in. */
|
|
1168
|
+
interface VoiceSpeaker {
|
|
1169
|
+
/** Queue a decoded audio chunk for gap-minimized playback. */
|
|
1170
|
+
enqueue: (audio: Uint8Array) => void;
|
|
1171
|
+
/** Drop everything queued and stop the current chunk (barge-in). */
|
|
1172
|
+
interrupt: () => void;
|
|
1173
|
+
/** Release the playback audio context. */
|
|
1174
|
+
stop: () => void;
|
|
1175
|
+
}
|
|
1176
|
+
/** Config passed to a {@link CreateMicrophone} factory. */
|
|
1177
|
+
interface MicrophoneConfig {
|
|
1178
|
+
/** The consecutive above-threshold chunk count that counts as a barge-in. */
|
|
1179
|
+
interruptChunks: number;
|
|
1180
|
+
/** RMS above which the user is considered to be barging in while the agent speaks. */
|
|
1181
|
+
interruptThreshold: number;
|
|
1182
|
+
/** `true` while `status === "speaking"` — gates barge-in detection. */
|
|
1183
|
+
isSpeaking: () => boolean;
|
|
1184
|
+
/** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
|
|
1185
|
+
onAudio: (pcm: Uint8Array) => void;
|
|
1186
|
+
/** A barge-in was detected (RMS spike while the agent is speaking). */
|
|
1187
|
+
onInterrupt: () => void;
|
|
1188
|
+
/** The current input RMS (0–1), for a level meter. */
|
|
1189
|
+
onLevel: (rms: number) => void;
|
|
1190
|
+
/** A spoken utterance ended (speech followed by `silenceDurationMs` of silence). */
|
|
1191
|
+
onSilence: () => void;
|
|
1192
|
+
/** Milliseconds of sub-threshold audio (after speech) that closes an utterance. */
|
|
1193
|
+
silenceDurationMs: number;
|
|
1194
|
+
/** RMS below which audio counts as silence. */
|
|
1195
|
+
silenceThreshold: number;
|
|
1196
|
+
}
|
|
1197
|
+
type CreateMicrophone = (config: MicrophoneConfig) => Promise<VoiceMicrophone>;
|
|
1198
|
+
type CreateSpeaker = (config: {
|
|
1199
|
+
audioFormat: VoiceAudioFormat;
|
|
1200
|
+
}) => VoiceSpeaker;
|
|
1201
|
+
/**
|
|
1202
|
+
* The default browser microphone: `getUserMedia` → a Web Audio `ScriptProcessor`
|
|
1203
|
+
* that tees 16 kHz PCM frames, tracks input RMS, auto-commits an utterance after
|
|
1204
|
+
* a silence gap, and flags a barge-in while the agent is speaking.
|
|
1205
|
+
*/
|
|
1206
|
+
/**
|
|
1207
|
+
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
1208
|
+
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
1209
|
+
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
1210
|
+
* @experimental
|
|
1211
|
+
*/
|
|
1212
|
+
type VoiceReference = FunctionReference<"stream", {
|
|
1213
|
+
threadKey: string;
|
|
1214
|
+
}, Record<string, unknown>>;
|
|
1215
|
+
/**
|
|
1216
|
+
* The lifecycle of a voice call, mirrored to the UI.
|
|
1217
|
+
* @experimental
|
|
1218
|
+
*/
|
|
1219
|
+
type VoiceStatus = "idle" | "listening" | "speaking" | "thinking";
|
|
1220
|
+
/** A minimal structural subset of the DOM `WebSocket` the primitive drives. */
|
|
1221
|
+
interface VoiceSocket {
|
|
1222
|
+
binaryType: string;
|
|
1223
|
+
close: () => void;
|
|
1224
|
+
onclose: ((event: unknown) => void) | null;
|
|
1225
|
+
onerror: ((event: unknown) => void) | null;
|
|
1226
|
+
onmessage: ((event: {
|
|
1227
|
+
data: unknown;
|
|
1228
|
+
}) => void) | null;
|
|
1229
|
+
onopen: ((event: unknown) => void) | null;
|
|
1230
|
+
readonly readyState: number;
|
|
1231
|
+
send: (data: ArrayBufferView | ArrayBufferLike | string) => void;
|
|
1232
|
+
}
|
|
1233
|
+
type CreateSocket = (url: string) => VoiceSocket;
|
|
1234
|
+
/**
|
|
1235
|
+
* `VoiceAgentOptions` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
1236
|
+
* @experimental
|
|
1237
|
+
*/
|
|
1238
|
+
interface VoiceAgentOptions {
|
|
1239
|
+
/** Client to bind to. Defaults to the injected `LUNORA_CLIENT`. */
|
|
1240
|
+
client?: LunoraClient;
|
|
1241
|
+
/**
|
|
1242
|
+
* Advanced/test seam: build the microphone capture subsystem. Defaults to a
|
|
1243
|
+
* `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
|
|
1244
|
+
* Audio graph stays isolated (and mockable in a non-browser test env).
|
|
1245
|
+
*/
|
|
1246
|
+
createMicrophone?: CreateMicrophone;
|
|
1247
|
+
/** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
|
|
1248
|
+
createSocket?: CreateSocket;
|
|
1249
|
+
/** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
|
|
1250
|
+
createSpeaker?: CreateSpeaker;
|
|
1251
|
+
/**
|
|
1252
|
+
* `DestroyRef` whose `onDestroy` tears the call down. Defaults to
|
|
1253
|
+
* `inject(DestroyRef)` — the calling component/service.
|
|
1254
|
+
*/
|
|
1255
|
+
destroyRef?: DestroyRef;
|
|
1256
|
+
/** Consecutive above-`interruptThreshold` chunks that trigger a barge-in. Default `3`. */
|
|
1257
|
+
interruptChunks?: number;
|
|
1258
|
+
/** Input RMS above which the user is treated as barging in while the agent speaks. Default `0.15`. */
|
|
1259
|
+
interruptThreshold?: number;
|
|
1260
|
+
/** Milliseconds of silence (after speech) that auto-commits an utterance. Default `1200`. */
|
|
1261
|
+
silenceDurationMs?: number;
|
|
1262
|
+
/** Input RMS below which audio counts as silence. Default `0.01`. */
|
|
1263
|
+
silenceThreshold?: number;
|
|
1264
|
+
/** The thread to converse on — shared with the agent's text turns. Resolved when the call opens. */
|
|
1265
|
+
threadKey: string;
|
|
1266
|
+
/** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
|
|
1267
|
+
voice: VoiceReference;
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* `VoiceAgentResult` is part of the experimental `@lunora/angular` API and may change without a major version bump.
|
|
1271
|
+
* @experimental
|
|
1272
|
+
*/
|
|
1273
|
+
interface VoiceAgentResult {
|
|
1274
|
+
/** The current input RMS (0–1) — drive a mic level meter. */
|
|
1275
|
+
audioLevel: Signal<number>;
|
|
1276
|
+
/** `true` once the WS `ready` handshake completed. */
|
|
1277
|
+
connected: Signal<boolean>;
|
|
1278
|
+
/** Tear down the call: close the socket, stop the mic, release audio. Idempotent. */
|
|
1279
|
+
endCall: () => void;
|
|
1280
|
+
/** The last transport/pipeline error, or `undefined`. */
|
|
1281
|
+
error: Signal<Error | undefined>;
|
|
1282
|
+
/** The live assistant text for the in-flight turn (grows via deltas; finalized on done). */
|
|
1283
|
+
interimTranscript: Signal<string>;
|
|
1284
|
+
/** `true` while the mic is muted. */
|
|
1285
|
+
isMuted: Signal<boolean>;
|
|
1286
|
+
/** Send a typed turn (no audio) — a text message spoken back by the agent. */
|
|
1287
|
+
sendText: (text: string) => void;
|
|
1288
|
+
/** Open the mic, connect the socket, and start the conversation. Idempotent while active. */
|
|
1289
|
+
startCall: () => Promise<void>;
|
|
1290
|
+
/** The current call lifecycle. */
|
|
1291
|
+
status: Signal<VoiceStatus>;
|
|
1292
|
+
/** Mute/unmute the microphone. Returns the new muted state. */
|
|
1293
|
+
toggleMute: () => boolean;
|
|
1294
|
+
/** The last finalized user utterance (STT result). */
|
|
1295
|
+
transcript: Signal<string>;
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* A first-class voice-call surface for a voice-enabled agent: it opens a
|
|
1299
|
+
* WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
|
|
1300
|
+
* streams the agent's synthesized speech back through the browser's audio output,
|
|
1301
|
+
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
1302
|
+
* `audioLevel`) to Angular signals. Pass the generated `api.agents.<name>Voice`
|
|
1303
|
+
* reference (never a string), matching `agentChat`'s reference-passing style. The
|
|
1304
|
+
* Angular counterpart to React's `useVoiceAgent`, re-expressed with signals; the
|
|
1305
|
+
* per-call connection lives in a closure variable (the primitive runs once per
|
|
1306
|
+
* component, so no signal-of-connection indirection is needed).
|
|
1307
|
+
*
|
|
1308
|
+
* v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
|
|
1309
|
+
* turn detection and client-side RMS barge-in. The heavy Web Audio capture and
|
|
1310
|
+
* playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
|
|
1311
|
+
* `createSocket`) so the primitive is drivable outside a browser.
|
|
1312
|
+
*
|
|
1313
|
+
* Call from an injection context (component/service field or constructor); pass an
|
|
1314
|
+
* explicit `client` / `destroyRef` to drive it outside one (e.g. in a test).
|
|
1315
|
+
* @experimental
|
|
1316
|
+
*/
|
|
1317
|
+
declare const voiceAgent: (options: VoiceAgentOptions) => VoiceAgentResult;
|
|
1318
|
+
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 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 StreamOptions, type StreamResult, type StreamStatus, type SubscriptionOptions, type SubscriptionResult, type VoiceAgentOptions, type VoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, connectionStatus, flag, flags, hydratePreloaded, infiniteQuery, injectLunoraClient, liveQuery, mutate, mutator, paginatedQuery, presence, provideLunora, rateLimit, stream, subscription, voiceAgent };
|