agents 0.22.0 → 0.24.0

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 (215) hide show
  1. package/README.md +20 -1
  2. package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-B2XLNMxq.d.ts} +1094 -443
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +26 -26
  5. package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-Dj5Mzlw7.d.ts} +7 -7
  6. package/dist/agent-tools.d.ts +21 -21
  7. package/dist/browser/ai.js +4 -1
  8. package/dist/browser/ai.js.map +1 -1
  9. package/dist/browser/tanstack-ai.js.map +1 -1
  10. package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
  11. package/dist/callable-decorator.d.ts +18 -0
  12. package/dist/callable-decorator.js +71 -0
  13. package/dist/callable-decorator.js.map +1 -0
  14. package/dist/{capability-BjSKYpzg.js → capability-B4WbF81e.js} +2 -1
  15. package/dist/capability-B4WbF81e.js.map +1 -0
  16. package/dist/capability-runner-BUBa6Ake.d.ts +484 -0
  17. package/dist/channel-Bnm4S7T2.d.ts +491 -0
  18. package/dist/channels/ai-sdk.d.ts +46 -0
  19. package/dist/channels/ai-sdk.js +120 -0
  20. package/dist/channels/ai-sdk.js.map +1 -0
  21. package/dist/channels/email.d.ts +95 -0
  22. package/dist/channels/email.js +323 -0
  23. package/dist/channels/email.js.map +1 -0
  24. package/dist/channels/index.d.ts +233 -0
  25. package/dist/channels/index.js +608 -0
  26. package/dist/channels/index.js.map +1 -0
  27. package/dist/channels/slack.d.ts +140 -0
  28. package/dist/channels/slack.js +614 -0
  29. package/dist/channels/slack.js.map +1 -0
  30. package/dist/channels/tanstack-ai.d.ts +39 -0
  31. package/dist/channels/tanstack-ai.js +17 -0
  32. package/dist/channels/tanstack-ai.js.map +1 -0
  33. package/dist/channels/telegram.d.ts +106 -0
  34. package/dist/channels/telegram.js +427 -0
  35. package/dist/channels/telegram.js.map +1 -0
  36. package/dist/channels/voice.d.ts +45 -0
  37. package/dist/channels/voice.js +122 -0
  38. package/dist/channels/voice.js.map +1 -0
  39. package/dist/chat/index.d.ts +2319 -2010
  40. package/dist/chat/index.js +892 -518
  41. package/dist/chat/index.js.map +1 -1
  42. package/dist/chat-sdk/index.d.ts +7 -7
  43. package/dist/chat-sdk/index.js +1 -1
  44. package/dist/client-BxdkCuVy.d.ts +411 -0
  45. package/dist/client-C9DAjZIY.js +518 -0
  46. package/dist/client-C9DAjZIY.js.map +1 -0
  47. package/dist/{client-jagG8a9_.js → client-fyQrLGkD.js} +2 -2
  48. package/dist/{client-jagG8a9_.js.map → client-fyQrLGkD.js.map} +1 -1
  49. package/dist/client.d.ts +27 -283
  50. package/dist/client.js +2 -274
  51. package/dist/context/index.d.ts +216 -0
  52. package/dist/context/index.js +454 -0
  53. package/dist/context/index.js.map +1 -0
  54. package/dist/current-agent-C4w86kcN.d.ts +93 -0
  55. package/dist/current-agent-DhoDkSnH.js.map +1 -1
  56. package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
  57. package/dist/diagnostics-BzvaX2UT.js.map +1 -0
  58. package/dist/diagnostics-C4jcz3VK.js +360 -0
  59. package/dist/diagnostics-C4jcz3VK.js.map +1 -0
  60. package/dist/durable-object-lifecycle-ei7M7lqB.d.ts +157 -0
  61. package/dist/index-BB0kqhIz.d.ts +101 -0
  62. package/dist/index-BVVgDSdq.d.ts +1 -0
  63. package/dist/index-Dlgtd3Mj.d.ts +78 -0
  64. package/dist/index-XDkuQ7zm.d.ts +89 -0
  65. package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
  66. package/dist/index.d.ts +92 -83
  67. package/dist/index.js +4 -3
  68. package/dist/ingress-BfetZbMO.js +83 -0
  69. package/dist/ingress-BfetZbMO.js.map +1 -0
  70. package/dist/internal-CYlgHl1l.js +59 -0
  71. package/dist/internal-CYlgHl1l.js.map +1 -0
  72. package/dist/internal_context.d.ts +1 -1
  73. package/dist/lifecycle/index.d.ts +39 -19
  74. package/dist/lifecycle/index.js +2 -2
  75. package/dist/lifecycle-Mm_jQh7r.js +1314 -0
  76. package/dist/lifecycle-Mm_jQh7r.js.map +1 -0
  77. package/dist/mcp/client/index.d.ts +20 -20
  78. package/dist/mcp/client/index.js +1 -1
  79. package/dist/mcp/index.d.ts +35 -35
  80. package/dist/mcp/index.js +2 -2
  81. package/dist/observability/index.d.ts +1 -1
  82. package/dist/observability/index.js +1 -1
  83. package/dist/queue/index.d.ts +123 -0
  84. package/dist/queue/index.js +2 -0
  85. package/dist/queue-BC9F5cUo.js +406 -0
  86. package/dist/queue-BC9F5cUo.js.map +1 -0
  87. package/dist/react.d.ts +34 -16
  88. package/dist/react.js +31 -8
  89. package/dist/react.js.map +1 -1
  90. package/dist/{retries-CAvxtG9d.d.ts → retries-D9B2UCq3.d.ts} +23 -6
  91. package/dist/retries.d.ts +10 -6
  92. package/dist/retries.js +21 -1
  93. package/dist/retries.js.map +1 -1
  94. package/dist/routing/index.d.ts +137 -0
  95. package/dist/routing/index.js +244 -0
  96. package/dist/routing/index.js.map +1 -0
  97. package/dist/sanitize-D9TujEK8.js +79 -0
  98. package/dist/sanitize-D9TujEK8.js.map +1 -0
  99. package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-BGq6M5Kd.d.ts} +20 -21
  100. package/dist/scheduler-D_KHqxBa.js +658 -0
  101. package/dist/scheduler-D_KHqxBa.js.map +1 -0
  102. package/dist/schedules/index.d.ts +1 -1
  103. package/dist/schedules/index.js +1 -1
  104. package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
  105. package/dist/serializable.d.ts +1 -1
  106. package/dist/sessions/index.d.ts +441 -0
  107. package/dist/sessions/index.js +2063 -0
  108. package/dist/sessions/index.js.map +1 -0
  109. package/dist/skills/index.d.ts +99 -0
  110. package/dist/skills/index.js +254 -5
  111. package/dist/skills/index.js.map +1 -1
  112. package/dist/{src-5W6JNKVb.js → src-BNU3ZiJM.js} +1524 -1441
  113. package/dist/src-BNU3ZiJM.js.map +1 -0
  114. package/dist/state/index.d.ts +6 -0
  115. package/dist/state/index.js +137 -0
  116. package/dist/state/index.js.map +1 -0
  117. package/dist/streams/index.d.ts +120 -0
  118. package/dist/streams/index.js +107 -0
  119. package/dist/streams/index.js.map +1 -0
  120. package/dist/streams-BcE8JP2X.d.ts +370 -0
  121. package/dist/streams-CCPRV6dt.js +709 -0
  122. package/dist/streams-CCPRV6dt.js.map +1 -0
  123. package/dist/sub-routing.d.ts +12 -12
  124. package/dist/surface-bZZJqBka.js +17 -0
  125. package/dist/surface-bZZJqBka.js.map +1 -0
  126. package/dist/tasks/index.d.ts +64 -0
  127. package/dist/tasks/index.js +2 -0
  128. package/dist/tasks-D4nLqVSI.js +1656 -0
  129. package/dist/tasks-D4nLqVSI.js.map +1 -0
  130. package/dist/tasks-V2lCT8ZV.d.ts +517 -0
  131. package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
  132. package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
  133. package/dist/text-stream-CpdiKrJB.js +272 -0
  134. package/dist/text-stream-CpdiKrJB.js.map +1 -0
  135. package/dist/tokens-nHAKcN6M.js +52 -0
  136. package/dist/tokens-nHAKcN6M.js.map +1 -0
  137. package/dist/tool-schema-CBjGPrsQ.js +31 -0
  138. package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
  139. package/dist/transport-protocol-BxyngQ_R.js +25 -0
  140. package/dist/transport-protocol-BxyngQ_R.js.map +1 -0
  141. package/dist/transport-protocol-ZTew5Wso.d.ts +27 -0
  142. package/dist/types-B7LojTe4.d.ts +202 -0
  143. package/dist/types-DCD6BNZH.d.ts +70 -0
  144. package/dist/types-_Faxb570.d.ts +439 -0
  145. package/dist/voice/client.d.ts +226 -0
  146. package/dist/voice/client.js +932 -0
  147. package/dist/voice/client.js.map +1 -0
  148. package/dist/voice/errors.d.ts +43 -0
  149. package/dist/voice/errors.js +41 -0
  150. package/dist/voice/errors.js.map +1 -0
  151. package/dist/voice/index.d.ts +271 -0
  152. package/dist/voice/index.js +1812 -0
  153. package/dist/voice/index.js.map +1 -0
  154. package/dist/voice/react.d.ts +167 -0
  155. package/dist/voice/react.js +234 -0
  156. package/dist/voice/react.js.map +1 -0
  157. package/dist/voice/sfu.d.ts +71 -0
  158. package/dist/voice/sfu.js +157 -0
  159. package/dist/voice/sfu.js.map +1 -0
  160. package/dist/voice/text.d.ts +6 -0
  161. package/dist/voice/text.js +2 -0
  162. package/dist/voice/types.d.ts +58 -0
  163. package/dist/voice/types.js +18 -0
  164. package/dist/voice/types.js.map +1 -0
  165. package/dist/voice/workers-ai.d.ts +136 -0
  166. package/dist/voice/workers-ai.js +568 -0
  167. package/dist/voice/workers-ai.js.map +1 -0
  168. package/dist/websockets/index.d.ts +301 -0
  169. package/dist/websockets/index.js +3 -0
  170. package/dist/websockets-D7IzWbZb.js +1005 -0
  171. package/dist/websockets-D7IzWbZb.js.map +1 -0
  172. package/dist/workflow-types.d.ts +25 -25
  173. package/dist/workflows.d.ts +21 -21
  174. package/dist/workflows.js +1 -1
  175. package/docs/agent-class.md +4 -4
  176. package/docs/agent-tools.md +2 -1
  177. package/docs/channels.md +323 -0
  178. package/docs/chat-agents.md +6 -13
  179. package/docs/client-sdk.md +30 -0
  180. package/docs/context.md +131 -0
  181. package/docs/index.md +16 -13
  182. package/docs/lifecycle.md +179 -57
  183. package/docs/long-running-agents.md +2 -2
  184. package/docs/mcp-servers.md +5 -1
  185. package/docs/queue.md +135 -241
  186. package/docs/resumable-streaming.md +1 -1
  187. package/docs/retries.md +1 -1
  188. package/docs/routing.md +105 -0
  189. package/docs/sessions.md +237 -871
  190. package/docs/streams.md +213 -0
  191. package/docs/sub-agents.md +184 -124
  192. package/docs/tasks.md +246 -0
  193. package/docs/voice.md +745 -0
  194. package/package.json +126 -14
  195. package/dist/capability-BjSKYpzg.js.map +0 -1
  196. package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
  197. package/dist/client.js.map +0 -1
  198. package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
  199. package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
  200. package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
  201. package/dist/current-agent-CuMErtly.d.ts +0 -283
  202. package/dist/diagnostics-CaBjfz4J.js.map +0 -1
  203. package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
  204. package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
  205. package/dist/experimental/memory/session/index.d.ts +0 -671
  206. package/dist/experimental/memory/session/index.js +0 -2379
  207. package/dist/experimental/memory/session/index.js.map +0 -1
  208. package/dist/experimental/memory/utils/index.d.ts +0 -96
  209. package/dist/experimental/memory/utils/index.js +0 -79
  210. package/dist/experimental/memory/utils/index.js.map +0 -1
  211. package/dist/scheduler-CR9RHGos.js +0 -857
  212. package/dist/scheduler-CR9RHGos.js.map +0 -1
  213. package/dist/src-5W6JNKVb.js.map +0 -1
  214. package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
  215. package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
@@ -0,0 +1,202 @@
1
+ //#region src/sessions/types.d.ts
2
+ /**
3
+ * Types for the Sessions capability.
4
+ *
5
+ * @experimental The whole `agents/sessions` surface may change before
6
+ * stabilizing.
7
+ */
8
+ /**
9
+ * Minimal message part shape used by Sessions internals.
10
+ * Vercel AI SDK's `UIMessagePart` is structurally compatible.
11
+ */
12
+ interface SessionMessagePart {
13
+ type: string;
14
+ text?: string;
15
+ reasoning?: string;
16
+ toolCallId?: string;
17
+ toolName?: string;
18
+ input?: unknown;
19
+ output?: unknown;
20
+ state?: string;
21
+ result?: unknown;
22
+ /** File parts (AI SDK `FileUIPart`): IANA media type of the payload. */
23
+ mediaType?: string;
24
+ /** File parts: a `data:` URL or a remote URL. */
25
+ url?: string;
26
+ /** File parts: original filename, when one was supplied. */
27
+ filename?: string;
28
+ }
29
+ /**
30
+ * Minimal message shape used by Sessions internals.
31
+ * Vercel AI SDK's `UIMessage` is structurally compatible — you can pass
32
+ * `UIMessage` objects directly without conversion.
33
+ */
34
+ interface SessionMessage {
35
+ id: string;
36
+ role: string;
37
+ parts: SessionMessagePart[];
38
+ metadata?: unknown;
39
+ createdAt?: Date;
40
+ }
41
+ interface SearchResult {
42
+ id: string;
43
+ role: string;
44
+ content: string;
45
+ createdAt?: string;
46
+ sessionId?: string;
47
+ }
48
+ interface StoredCompaction {
49
+ id: string;
50
+ summary: string;
51
+ fromMessageId: string;
52
+ toMessageId: string;
53
+ createdAt: string;
54
+ }
55
+ /** Per-row info for the active branch path, root → leaf order. */
56
+ interface SessionRowStat {
57
+ id: string;
58
+ /** Stored message role (e.g. "user" / "assistant"). */
59
+ role: string;
60
+ /**
61
+ * Serialized size in bytes: the message row, every continuation row it
62
+ * was split across, and the payloads it points at as they read back.
63
+ */
64
+ bytes: number;
65
+ /** Token estimate stamped when the row was written. */
66
+ tokenEstimate: number;
67
+ }
68
+ /** Result of a byte-budgeted history read. */
69
+ interface RecentHistoryResult {
70
+ /**
71
+ * The most recent messages on the active branch path whose stored bytes
72
+ * fit `maxContentBytes`, root → leaf order, with compaction overlays
73
+ * applied within the window. The window always covers at least the leaf
74
+ * row; rows whose stored content fails to parse are skipped.
75
+ */
76
+ messages: SessionMessage[];
77
+ /** True when older messages were left out to satisfy the byte budget. */
78
+ truncated: boolean;
79
+ /** Summed stored size of the FULL path, in bytes. */
80
+ totalContentBytes: number;
81
+ }
82
+ /** Result of an append/upsert write. */
83
+ interface AppendResult {
84
+ /** False when the id already existed and the write was an idempotent no-op. */
85
+ inserted: boolean;
86
+ /** The STORED form of the message (sanitized). */
87
+ message: SessionMessage;
88
+ }
89
+ /** Change-feed events dispatched after each durable write. */
90
+ type SessionChangeEvent =
91
+ | {
92
+ type: "append";
93
+ sessionId: string;
94
+ message: SessionMessage;
95
+ parentId?: string | null;
96
+ inserted: boolean;
97
+ }
98
+ | {
99
+ type: "update";
100
+ sessionId: string;
101
+ message: SessionMessage;
102
+ }
103
+ | {
104
+ type: "delete";
105
+ sessionId: string;
106
+ messageIds: string[];
107
+ }
108
+ | {
109
+ type: "clear";
110
+ sessionId: string;
111
+ }
112
+ | {
113
+ type: "compact";
114
+ sessionId: string;
115
+ }
116
+ /**
117
+ * A row written verbatim by `importMessage()`. A host cache should treat
118
+ * the path as changed underneath it rather than patch itself: imports come
119
+ * in bulk with explicit parents, so re-deriving once later is the cheap
120
+ * response.
121
+ */
122
+ | {
123
+ type: "import";
124
+ sessionId: string;
125
+ message: SessionMessage;
126
+ parentId: string | null;
127
+ } /** An overlay stored directly through `addCompaction()`. */
128
+ | {
129
+ type: "compaction";
130
+ sessionId: string;
131
+ compaction: StoredCompaction;
132
+ };
133
+ type SessionChangeListener = (
134
+ event: SessionChangeEvent
135
+ ) => void | Promise<void>;
136
+ /** Options accepted by history reads. */
137
+ interface HistoryReadOptions {
138
+ /** Read the path ending at this leaf instead of the active leaf. */
139
+ leafId?: string | null;
140
+ /** Abort a streamed read between chunks. */
141
+ signal?: AbortSignal;
142
+ /**
143
+ * Yield the path leaf → root instead of root → leaf. Content is still
144
+ * fetched in bounded windows, newest window first, so a consumer that
145
+ * stops after the message it was looking for reads only the newest rows.
146
+ */
147
+ newestFirst?: boolean;
148
+ }
149
+ /** Options accepted by batched history reads. */
150
+ interface HistoryBatchReadOptions extends HistoryReadOptions {
151
+ /** Maximum messages per yielded batch. Default 50. */
152
+ batchSize?: number;
153
+ /**
154
+ * Maximum serialized bytes per yielded batch. Default 4 MiB. A single
155
+ * message larger than the limit is yielded alone.
156
+ */
157
+ maxBatchBytes?: number;
158
+ }
159
+ /** Policy for a Sessions capability. */
160
+ interface SessionsOptions {
161
+ /**
162
+ * Message-metadata keys reserved for server-side writers. Stripped from
163
+ * writes marked `source: "client"`. Default: none.
164
+ */
165
+ readonly reservedMetadataKeys?: readonly string[];
166
+ }
167
+ /** Trust policy shared by append and update writes. */
168
+ interface WriteOptions {
169
+ /**
170
+ * `"client"` marks untrusted intake: reserved metadata keys are stripped.
171
+ * Default `"server"`.
172
+ */
173
+ source?: "client" | "server";
174
+ }
175
+ /** Options accepted by append writes. */
176
+ interface AppendOptions extends WriteOptions {
177
+ /**
178
+ * - `undefined` / omitted → auto-detect: attach to the current latest leaf.
179
+ * - `null` → create a root message with no parent.
180
+ * - string → attach to the given parent id (falls back to root when the
181
+ * parent does not belong to this session).
182
+ */
183
+ parentId?: string | null;
184
+ }
185
+ //#endregion
186
+ export {
187
+ RecentHistoryResult as a,
188
+ SessionChangeListener as c,
189
+ SessionRowStat as d,
190
+ SessionsOptions as f,
191
+ HistoryReadOptions as i,
192
+ SessionMessage as l,
193
+ WriteOptions as m,
194
+ AppendResult as n,
195
+ SearchResult as o,
196
+ StoredCompaction as p,
197
+ HistoryBatchReadOptions as r,
198
+ SessionChangeEvent as s,
199
+ AppendOptions as t,
200
+ SessionMessagePart as u
201
+ };
202
+ //# sourceMappingURL=types-B7LojTe4.d.ts.map
@@ -0,0 +1,70 @@
1
+ import { t as RetryOptions } from "./retries-D9B2UCq3.js";
2
+
3
+ //#region src/queue/types.d.ts
4
+ /**
5
+ * One durable background task waiting in a Queue.
6
+ *
7
+ * @template T Type of the callback payload.
8
+ */
9
+ type QueueItem<T = unknown> = {
10
+ /** Unique item identifier. */ id: string /** Name of the callback invoked with the payload. */;
11
+ callback: string /** Data passed to the callback. */;
12
+ payload: T /** Creation time as a Unix timestamp in seconds. */;
13
+ createdAt: number /** Retry policy applied when the callback throws. */;
14
+ retry?: RetryOptions;
15
+ };
16
+ /**
17
+ * Constraint for a Queue's registered callback map: named handlers receiving
18
+ * the parsed payload and the item being processed.
19
+ *
20
+ * @experimental The API surface may change before stabilizing.
21
+ */
22
+ type QueueHandlers = Record<string, (payload: never, item: never) => unknown>;
23
+ /**
24
+ * Default callback surface for a Queue constructed without registered
25
+ * callbacks: any name compiles with an untyped payload. At runtime a name
26
+ * must be registered or supplied by a composition-root resolver (the
27
+ * aperture behind Agent's name-based queue API); a bare Queue rejects it
28
+ * otherwise.
29
+ *
30
+ * @experimental The API surface may change before stabilizing.
31
+ */
32
+ type QueueCallbacks = Record<
33
+ string,
34
+ (payload: unknown, item: QueueItem<unknown>) => unknown
35
+ >;
36
+ /**
37
+ * The payload type a registered queue callback accepts.
38
+ *
39
+ * @experimental The API surface may change before stabilizing.
40
+ */
41
+ type QueuePayload<Handler> = Handler extends (
42
+ payload: infer Payload,
43
+ ...rest: never[]
44
+ ) => unknown
45
+ ? Payload
46
+ : never;
47
+ /** Options accepted when pushing one item. */
48
+ type QueuePushOptions = {
49
+ /**
50
+ * Stable item id. A push with an existing id replaces that item in place
51
+ * (and supersedes a dispatch of it that is still in flight). Omitted ids
52
+ * are generated.
53
+ */
54
+ id?: string /** Retry policy for callback execution, overriding the Queue default. */;
55
+ retry?: RetryOptions;
56
+ };
57
+ /** Filters accepted by `list()`. */
58
+ type QueueCriteria = {
59
+ /** Only items addressed to this callback. */ callback?: string;
60
+ };
61
+ //#endregion
62
+ export {
63
+ QueuePayload as a,
64
+ QueueItem as i,
65
+ QueueCriteria as n,
66
+ QueuePushOptions as o,
67
+ QueueHandlers as r,
68
+ QueueCallbacks as t
69
+ };
70
+ //# sourceMappingURL=types-DCD6BNZH.d.ts.map
@@ -0,0 +1,439 @@
1
+ //#region src/voice/types.d.ts
2
+ /**
3
+ * Shared types for the voice pipeline.
4
+ *
5
+ * Used by both the server (index.ts) and client (client.ts)
6
+ * to ensure protocol consistency.
7
+ */
8
+ /**
9
+ * Current voice protocol version.
10
+ * Bump this when making backwards-incompatible wire protocol changes.
11
+ * The server sends this in the initial `welcome` message so clients
12
+ * can detect version mismatches.
13
+ */
14
+ declare const VOICE_PROTOCOL_VERSION = 1;
15
+ type VoiceStatus = "idle" | "listening" | "thinking" | "speaking";
16
+ /** Server-side diagnostic configuration shared by both voice mixins. */
17
+ interface VoiceDiagnosticsOptions {
18
+ /** Forward safe server diagnostics and enable browser console logging. */
19
+ browserConsole?: boolean;
20
+ }
21
+ /**
22
+ * A bounded diagnostic record forwarded by the voice protocol.
23
+ * Event names and metadata are intentionally open and are not stable API.
24
+ */
25
+ interface VoiceDiagnosticEvent {
26
+ event: string;
27
+ timestamp: number;
28
+ data?: Record<string, unknown>;
29
+ }
30
+ type VoiceTurnSource = "speech" | "text";
31
+ type VoiceTurnOutcome =
32
+ | "completed"
33
+ | "no_output"
34
+ | "output_limit"
35
+ | "content_filtered"
36
+ | "model_error"
37
+ | "tts_error"
38
+ | "aborted"
39
+ | "skipped"
40
+ | "error";
41
+ /**
42
+ * Stable, content-free summary of one allocated voice turn.
43
+ *
44
+ * `turnId`, `source`, and `outcome` are dimensions used to correlate and
45
+ * interpret the measurements; every other field is a duration. Optional
46
+ * timings are omitted when their lifecycle landmark was not reached. Timings
47
+ * use one server clock, overlap, and are not additive. Browser playback timing
48
+ * is excluded because browser and Worker clocks are independent.
49
+ */
50
+ interface VoiceTurnMetrics {
51
+ /** SDK-assigned correlation ID for this turn. */
52
+ turnId: string;
53
+ /** Whether the turn originated from finalized speech or a text message. */
54
+ source: VoiceTurnSource;
55
+ /** Terminal result, emitted exactly once for the allocated turn. */
56
+ outcome: VoiceTurnOutcome;
57
+ /** Turn allocation to terminal summary, in milliseconds. */
58
+ turnTotalMs: number;
59
+ /** Provider speech start to the first interim transcript. */
60
+ speechStartToFirstInterimMs?: number;
61
+ /** Provider speech start to the finalized transcript. */
62
+ speechStartToFinalMs?: number;
63
+ /** Time spent in the server's `afterTranscribe` hook. */
64
+ afterTranscribeMs?: number;
65
+ /** Model invocation to the first non-whitespace text delta. */
66
+ modelToFirstTextMs?: number;
67
+ /** Cumulative duration of reasoning blocks exposed by the model stream. */
68
+ exposedReasoningMs?: number;
69
+ /** Model invocation through normalized stream consumption. */
70
+ modelStreamConsumptionMs?: number;
71
+ /** Finalized input through the first server audio send. */
72
+ finalInputToFirstAudioMs?: number;
73
+ /** First TTS provider invocation through the first server audio send. */
74
+ ttsToFirstAudioMs?: number;
75
+ /** First TTS provider invocation through completion of all sentence work. */
76
+ ttsWallMs?: number;
77
+ /** Cumulative overlapping TTS sentence hook and provider work. */
78
+ ttsWorkMs?: number;
79
+ }
80
+ /** Audio format the server uses for binary audio payloads. */
81
+ type VoiceAudioFormat = "mp3" | "pcm16" | "wav" | "opus";
82
+ type VoiceRole = "user" | "assistant";
83
+ /** Stable machine-readable error codes emitted by the voice protocol. */
84
+ type VoiceErrorCode = "stt_startup_failed" | "stt_connection_lost";
85
+ /** Stable pipeline stage associated with a structured voice error. */
86
+ type VoiceErrorStage = "stt";
87
+ /** Client-safe error detail. `message` remains for string-event compatibility. */
88
+ interface VoiceError {
89
+ message: string;
90
+ code?: VoiceErrorCode;
91
+ stage?: VoiceErrorStage;
92
+ retryable?: boolean;
93
+ }
94
+ /** Stable machine-readable outcomes for non-ordinary LLM completions. */
95
+ type VoiceCompletionOutcomeCode =
96
+ | "no_output"
97
+ | "output_limit"
98
+ | "content_filtered"
99
+ | "model_error";
100
+ /** Normalized finish reasons emitted by the supported AI SDK stream shape. */
101
+ type VoiceModelFinishReason =
102
+ | "stop"
103
+ | "length"
104
+ | "content-filter"
105
+ | "tool-calls"
106
+ | "error"
107
+ | "other";
108
+ /** Bounded completion metadata exposed by the voice protocol. */
109
+ interface VoiceCompletionOutcome {
110
+ code: VoiceCompletionOutcomeCode;
111
+ stage: "llm";
112
+ finishReason?: VoiceModelFinishReason;
113
+ partialOutput: boolean;
114
+ }
115
+ type VoiceClientMessage =
116
+ | {
117
+ type: "hello";
118
+ protocol_version?: number;
119
+ }
120
+ | {
121
+ type: "start_call";
122
+ preferred_format?: VoiceAudioFormat;
123
+ }
124
+ | {
125
+ type: "end_call";
126
+ }
127
+ | {
128
+ type: "start_of_speech";
129
+ }
130
+ | {
131
+ type: "end_of_speech";
132
+ }
133
+ | {
134
+ type: "interrupt";
135
+ }
136
+ | {
137
+ type: "text_message";
138
+ text: string;
139
+ };
140
+ type VoiceServerMessage =
141
+ | {
142
+ type: "welcome";
143
+ protocol_version: number;
144
+ diagnostics?: {
145
+ browser_console: true;
146
+ };
147
+ }
148
+ | ({
149
+ type: "diagnostic";
150
+ } & VoiceDiagnosticEvent)
151
+ | {
152
+ type: "status";
153
+ status: VoiceStatus;
154
+ }
155
+ | {
156
+ type: "audio_config";
157
+ format: VoiceAudioFormat;
158
+ sampleRate?: number;
159
+ }
160
+ | {
161
+ type: "transcript";
162
+ role: VoiceRole;
163
+ text: string;
164
+ }
165
+ | {
166
+ type: "transcript_start";
167
+ role: VoiceRole;
168
+ }
169
+ | {
170
+ type: "transcript_delta";
171
+ text: string;
172
+ }
173
+ | {
174
+ type: "transcript_end";
175
+ text: string;
176
+ }
177
+ | {
178
+ type: "transcript_interim";
179
+ text: string;
180
+ }
181
+ | {
182
+ type: "playback_interrupt";
183
+ }
184
+ | {
185
+ type: "metrics";
186
+ llm_ms: number;
187
+ tts_ms: number;
188
+ first_audio_ms: number;
189
+ total_ms: number;
190
+ }
191
+ | ({
192
+ type: "turn_metrics";
193
+ } & VoiceTurnMetrics)
194
+ | ({
195
+ type: "completion_outcome";
196
+ } & VoiceCompletionOutcome)
197
+ | ({
198
+ type: "error";
199
+ } & VoiceError);
200
+ /**
201
+ * Compact compatibility summary for successful, non-empty speech turns.
202
+ * These overlapping latency landmarks and work totals are not additive.
203
+ * Use `VoiceTurnMetrics` for stable detailed timing and terminal summaries of
204
+ * unsuccessful, aborted, skipped, or text turns.
205
+ */
206
+ interface VoicePipelineMetrics {
207
+ /**
208
+ * Time from immediately before `onTurn()` until normalized model-stream
209
+ * consumption completes. This can include tool work and consumer waits while
210
+ * consuming the stream. It is not time to first text.
211
+ */
212
+ llm_ms: number;
213
+ /**
214
+ * Cumulative per-sentence work from immediately before `beforeSynthesize`
215
+ * until that sentence's synthesis and hook work settles. Sentence work can
216
+ * overlap both other sentences and model consumption, so this value can
217
+ * exceed wall time and overlaps the other metrics.
218
+ */
219
+ tts_ms: number;
220
+ /**
221
+ * Time from turn-pipeline start, before `afterTranscribe`, to the first server
222
+ * audio send. Includes post-STT hooks, model work, and TTS, but excludes STT
223
+ * and browser playback. `0` means the server sent no audio.
224
+ */
225
+ first_audio_ms: number;
226
+ /**
227
+ * Time from the same turn-pipeline start until model consumption and TTS
228
+ * draining complete. Measured before final context, persistence, and status
229
+ * work. Excludes STT and browser playback.
230
+ */
231
+ total_ms: number;
232
+ }
233
+ interface TranscriptMessage {
234
+ role: VoiceRole;
235
+ text: string;
236
+ timestamp: number;
237
+ }
238
+ interface TTSProvider {
239
+ synthesize(text: string, signal?: AbortSignal): Promise<ArrayBuffer | null>;
240
+ }
241
+ interface StreamingTTSProvider {
242
+ synthesizeStream(
243
+ text: string,
244
+ signal?: AbortSignal
245
+ ): AsyncGenerator<ArrayBuffer>;
246
+ }
247
+ /**
248
+ * Continuous speech-to-text provider.
249
+ *
250
+ * Creates a per-call session that receives audio continuously from
251
+ * `start_call` to `end_call`. The model handles turn detection
252
+ * internally — there is no client-side speech boundary signaling
253
+ * required for STT.
254
+ *
255
+ * The session fires `onUtterance` when the model detects a complete
256
+ * utterance (e.g. Flux `EndOfTurn`, Nova 3 `speech_final` +
257
+ * endpointing). The voice pipeline maps this to `onTurn` (withVoice)
258
+ * or `onTranscript` (withVoiceInput).
259
+ */
260
+ interface Transcriber {
261
+ /** Create a new transcription session for one call. */
262
+ createSession(options?: TranscriberSessionOptions): TranscriberSession;
263
+ }
264
+ interface TranscriberSessionOptions {
265
+ /** Language code (e.g. "en"). */
266
+ language?: string;
267
+ /**
268
+ * Called when the provider produces an interim (unstable) transcript.
269
+ * This text may change as more audio arrives.
270
+ */
271
+ onInterim?: (text: string) => void;
272
+ /**
273
+ * Called when the model detects the start of user speech.
274
+ *
275
+ * Providers can use this for low-latency barge-in before a final
276
+ * utterance is available. The transcript may be omitted or unstable.
277
+ */
278
+ onSpeechStart?: (text?: string) => void;
279
+ /**
280
+ * Called when the model detects a complete utterance.
281
+ * The transcript is the stable text for this turn.
282
+ *
283
+ * For Flux: fires on `EndOfTurn`.
284
+ * For Nova 3: fires on `Results` with `speech_final: true`.
285
+ */
286
+ onUtterance?: (transcript: string) => void;
287
+ /**
288
+ * Called when the session can no longer transcribe because its provider
289
+ * connection failed or closed unexpectedly. Providers must not call this
290
+ * for teardown initiated by {@link TranscriberSession.close}.
291
+ */
292
+ onFatalError?: (error: Error) => void;
293
+ }
294
+ /**
295
+ * A per-call transcription session. Lives for the entire call duration.
296
+ *
297
+ * Unlike per-utterance sessions, this session is never finished or
298
+ * aborted mid-call. It receives all audio continuously and the model
299
+ * handles speech boundary detection. On interrupt, the LLM+TTS
300
+ * pipeline is aborted but the transcriber session stays alive.
301
+ */
302
+ interface TranscriberSession {
303
+ /**
304
+ * Feed raw PCM audio (16kHz mono 16-bit LE).
305
+ * Fire-and-forget — the session buffers internally as needed.
306
+ */
307
+ feed(chunk: ArrayBuffer): void;
308
+ /**
309
+ * Resolves when the session is ready to accept audio and emit transcripts.
310
+ * Optional so existing custom transcribers can start synchronously.
311
+ */
312
+ waitUntilReady?(): Promise<void>;
313
+ /**
314
+ * Optional. Provide the agent's most recent spoken reply (the text sent to
315
+ * TTS) as conversational context for the next user turn.
316
+ *
317
+ * The pipeline calls this after the agent finishes speaking each reply and
318
+ * greeting. Providers that support context carryover (e.g. AssemblyAI's
319
+ * `agent_context`) use it to better recognize short or contextual answers
320
+ * ("yes", "7pm", an email spelled aloud). Providers that don't support it
321
+ * simply omit this method — it is a no-op for them.
322
+ */
323
+ updateAgentContext?(text: string): void;
324
+ /**
325
+ * Close the session and release resources.
326
+ * Called at end_call or disconnect — not on interrupt.
327
+ */
328
+ close(): void;
329
+ }
330
+ /**
331
+ * Pluggable audio input source for VoiceClient.
332
+ *
333
+ * When provided via `VoiceClientOptions.audioInput`, VoiceClient delegates
334
+ * mic capture to this object instead of using its built-in AudioWorklet.
335
+ * The audio input is responsible for capturing audio and routing it to the
336
+ * server (however it chooses — WebRTC, SFU, direct binary, etc.).
337
+ *
338
+ * It must call `onAudioLevel` with RMS values so VoiceClient can run
339
+ * silence detection, interrupt detection, and update the audio level UI.
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * class SFUAudioInput implements VoiceAudioInput {
344
+ * onAudioLevel: ((rms: number) => void) | null = null;
345
+ * async start() {
346
+ * // Set up WebRTC peer connection, SFU session, etc.
347
+ * // In a monitoring loop, call this.onAudioLevel?.(rms)
348
+ * }
349
+ * stop() {
350
+ * // Tear down WebRTC
351
+ * }
352
+ * }
353
+ * ```
354
+ */
355
+ interface VoiceAudioInput {
356
+ /** Start capturing audio. Called by VoiceClient on startCall(). */
357
+ start(): Promise<void>;
358
+ /** Stop capturing audio. Called by VoiceClient on endCall() or disconnect(). */
359
+ stop(): void;
360
+ /**
361
+ * Set by VoiceClient before start(). The audio input must call this
362
+ * with RMS audio level values on each frame so VoiceClient can run
363
+ * silence detection, interrupt detection, and update the UI.
364
+ */
365
+ onAudioLevel: ((rms: number) => void) | null;
366
+ /**
367
+ * Set by VoiceClient before start(). If the audio input provides
368
+ * raw PCM audio (16kHz mono 16-bit LE), call this callback and
369
+ * VoiceClient will forward the data to the server via its transport.
370
+ *
371
+ * This is needed when audio reaches the server through the same
372
+ * WebSocket as protocol messages (e.g. SFU in local dev where the
373
+ * SFU adapter can't connect back to localhost).
374
+ *
375
+ * If the audio input routes audio to the server through an external
376
+ * path (e.g. SFU WebSocket adapter in production), this can be left
377
+ * unused — the audio will arrive on a separate connection.
378
+ */
379
+ onAudioData?: ((pcm: ArrayBuffer) => void) | null;
380
+ }
381
+ /** Details a transport can provide when its connection closes. */
382
+ interface VoiceTransportCloseInfo {
383
+ code?: number;
384
+ reason?: string;
385
+ wasClean?: boolean;
386
+ }
387
+ /**
388
+ * Abstraction over the data channel between client and server.
389
+ * The default implementation wraps PartySocket (WebSocket).
390
+ * Implement this interface to use WebRTC, SFU, or other transports.
391
+ */
392
+ interface VoiceTransport {
393
+ /** Send a JSON-serializable message to the server. */
394
+ sendJSON(data: Record<string, unknown>): void;
395
+ /** Send raw binary audio to the server. */
396
+ sendBinary(data: ArrayBuffer): void;
397
+ /** Open the connection. */
398
+ connect(): void;
399
+ /** Close the connection and release resources. */
400
+ disconnect(): void;
401
+ /** Whether the transport is currently connected and ready to send. */
402
+ readonly connected: boolean;
403
+ onopen: (() => void) | null;
404
+ onclose: ((info?: VoiceTransportCloseInfo) => void) | null;
405
+ onerror: ((error?: unknown) => void) | null;
406
+ /** Called when a JSON string message arrives from the server. */
407
+ onmessage: ((data: string | ArrayBuffer | Blob) => void) | null;
408
+ }
409
+ //#endregion
410
+ export {
411
+ VoiceTransport as C,
412
+ VoiceTurnSource as D,
413
+ VoiceTurnOutcome as E,
414
+ VoiceStatus as S,
415
+ VoiceTurnMetrics as T,
416
+ VoiceErrorStage as _,
417
+ TranscriberSessionOptions as a,
418
+ VoiceRole as b,
419
+ VoiceAudioFormat as c,
420
+ VoiceCompletionOutcome as d,
421
+ VoiceCompletionOutcomeCode as f,
422
+ VoiceErrorCode as g,
423
+ VoiceError as h,
424
+ TranscriberSession as i,
425
+ VoiceAudioInput as l,
426
+ VoiceDiagnosticsOptions as m,
427
+ TTSProvider as n,
428
+ TranscriptMessage as o,
429
+ VoiceDiagnosticEvent as p,
430
+ Transcriber as r,
431
+ VOICE_PROTOCOL_VERSION as s,
432
+ StreamingTTSProvider as t,
433
+ VoiceClientMessage as u,
434
+ VoiceModelFinishReason as v,
435
+ VoiceTransportCloseInfo as w,
436
+ VoiceServerMessage as x,
437
+ VoicePipelineMetrics as y
438
+ };
439
+ //# sourceMappingURL=types-_Faxb570.d.ts.map