agents 0.22.0 → 0.23.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.
- package/README.md +20 -1
- package/dist/{agent-routing-CnkaHb-v.d.ts → agent-routing-DE5zmCQ8.d.ts} +1038 -394
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +26 -26
- package/dist/{agent-tools-C0XJqWzB.d.ts → agent-tools-DtXMTDGM.d.ts} +7 -7
- package/dist/agent-tools.d.ts +21 -21
- package/dist/browser/ai.js +4 -1
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/tanstack-ai.js.map +1 -1
- package/dist/callable-decorator-DP__HhBA.d.ts +72 -0
- package/dist/callable-decorator.d.ts +18 -0
- package/dist/callable-decorator.js +71 -0
- package/dist/callable-decorator.js.map +1 -0
- package/dist/capability-BjSKYpzg.js.map +1 -1
- package/dist/capability-runner-Be_-PLR1.d.ts +459 -0
- package/dist/channel-Bnm4S7T2.d.ts +491 -0
- package/dist/channels/ai-sdk.d.ts +46 -0
- package/dist/channels/ai-sdk.js +120 -0
- package/dist/channels/ai-sdk.js.map +1 -0
- package/dist/channels/email.d.ts +95 -0
- package/dist/channels/email.js +323 -0
- package/dist/channels/email.js.map +1 -0
- package/dist/channels/index.d.ts +233 -0
- package/dist/channels/index.js +608 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/slack.d.ts +140 -0
- package/dist/channels/slack.js +614 -0
- package/dist/channels/slack.js.map +1 -0
- package/dist/channels/tanstack-ai.d.ts +39 -0
- package/dist/channels/tanstack-ai.js +17 -0
- package/dist/channels/tanstack-ai.js.map +1 -0
- package/dist/channels/telegram.d.ts +106 -0
- package/dist/channels/telegram.js +427 -0
- package/dist/channels/telegram.js.map +1 -0
- package/dist/channels/voice.d.ts +45 -0
- package/dist/channels/voice.js +122 -0
- package/dist/channels/voice.js.map +1 -0
- package/dist/chat/index.d.ts +2325 -2019
- package/dist/chat/index.js +888 -518
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +7 -7
- package/dist/chat-sdk/index.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/context/index.d.ts +216 -0
- package/dist/context/index.js +454 -0
- package/dist/context/index.js.map +1 -0
- package/dist/{current-agent-CuMErtly.d.ts → current-agent-Da_C9a3b.d.ts} +90 -107
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{diagnostics-CaBjfz4J.js → diagnostics-BzvaX2UT.js} +5 -1
- package/dist/diagnostics-BzvaX2UT.js.map +1 -0
- package/dist/diagnostics-C4jcz3VK.js +360 -0
- package/dist/diagnostics-C4jcz3VK.js.map +1 -0
- package/dist/index-BB0kqhIz.d.ts +101 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-XDkuQ7zm.d.ts +89 -0
- package/dist/{index-DcSAZKsB.d.ts → index-YSKgfgg9.d.ts} +3 -1
- package/dist/index.d.ts +91 -82
- package/dist/index.js +3 -2
- package/dist/ingress-BfetZbMO.js +83 -0
- package/dist/ingress-BfetZbMO.js.map +1 -0
- package/dist/internal-CYlgHl1l.js +59 -0
- package/dist/internal-CYlgHl1l.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +35 -17
- package/dist/lifecycle/index.js +1 -1
- package/dist/lifecycle-CMRGjZdw.js +1299 -0
- package/dist/lifecycle-CMRGjZdw.js.map +1 -0
- package/dist/mcp/client/index.d.ts +20 -20
- package/dist/mcp/index.d.ts +35 -35
- package/dist/mcp/index.js +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.js +1 -1
- package/dist/react.d.ts +4 -4
- package/dist/{retries-CAvxtG9d.d.ts → retries-D9Ds-1lz.d.ts} +17 -6
- package/dist/retries.d.ts +8 -6
- package/dist/retries.js +13 -1
- package/dist/retries.js.map +1 -1
- package/dist/routing/index.d.ts +137 -0
- package/dist/routing/index.js +244 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sanitize-D9TujEK8.js +79 -0
- package/dist/sanitize-D9TujEK8.js.map +1 -0
- package/dist/scheduler-DD9NdYbF.js +665 -0
- package/dist/scheduler-DD9NdYbF.js.map +1 -0
- package/dist/{scheduler-DQoTGoAW.d.ts → scheduler-Dwh85ZGl.d.ts} +21 -22
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/sentence-chunker-BAidJ4DA.d.ts +68 -0
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +441 -0
- package/dist/sessions/index.js +2063 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/skills/index.d.ts +99 -0
- package/dist/skills/index.js +254 -5
- package/dist/skills/index.js.map +1 -1
- package/dist/{src-5W6JNKVb.js → src-DlSHshb2.js} +1460 -1110
- package/dist/src-DlSHshb2.js.map +1 -0
- package/dist/streams/index.d.ts +120 -0
- package/dist/streams/index.js +107 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams-D6tJ0NN9.d.ts +370 -0
- package/dist/streams-DZKgAj9b.js +709 -0
- package/dist/streams-DZKgAj9b.js.map +1 -0
- package/dist/sub-routing.d.ts +12 -12
- package/dist/surface-bZZJqBka.js +17 -0
- package/dist/surface-bZZJqBka.js.map +1 -0
- package/dist/tasks/index.d.ts +64 -0
- package/dist/tasks/index.js +2 -0
- package/dist/tasks-BRJ5zgya.d.ts +517 -0
- package/dist/tasks-ylZgBjhj.js +1656 -0
- package/dist/tasks-ylZgBjhj.js.map +1 -0
- package/dist/text-segment-joiner-BtAFQSA_.js +57 -0
- package/dist/text-segment-joiner-BtAFQSA_.js.map +1 -0
- package/dist/text-stream-CpdiKrJB.js +272 -0
- package/dist/text-stream-CpdiKrJB.js.map +1 -0
- package/dist/tokens-nHAKcN6M.js +52 -0
- package/dist/tokens-nHAKcN6M.js.map +1 -0
- package/dist/tool-schema-CBjGPrsQ.js +31 -0
- package/dist/tool-schema-CBjGPrsQ.js.map +1 -0
- package/dist/types-B7LojTe4.d.ts +202 -0
- package/dist/types-_Faxb570.d.ts +439 -0
- package/dist/voice/client.d.ts +226 -0
- package/dist/voice/client.js +932 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/errors.d.ts +43 -0
- package/dist/voice/errors.js +41 -0
- package/dist/voice/errors.js.map +1 -0
- package/dist/voice/index.d.ts +271 -0
- package/dist/voice/index.js +1812 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/react.d.ts +167 -0
- package/dist/voice/react.js +234 -0
- package/dist/voice/react.js.map +1 -0
- package/dist/voice/sfu.d.ts +71 -0
- package/dist/voice/sfu.js +157 -0
- package/dist/voice/sfu.js.map +1 -0
- package/dist/voice/text.d.ts +6 -0
- package/dist/voice/text.js +2 -0
- package/dist/voice/types.d.ts +58 -0
- package/dist/voice/types.js +18 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/workers-ai.d.ts +136 -0
- package/dist/voice/workers-ai.js +568 -0
- package/dist/voice/workers-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +192 -0
- package/dist/websockets/index.js +2 -0
- package/dist/websockets-DUfRHPRq.js +502 -0
- package/dist/websockets-DUfRHPRq.js.map +1 -0
- package/dist/workflow-types.d.ts +25 -25
- package/dist/workflows.d.ts +21 -21
- package/dist/workflows.js +1 -1
- package/docs/agent-class.md +2 -2
- package/docs/agent-tools.md +2 -1
- package/docs/channels.md +323 -0
- package/docs/chat-agents.md +6 -13
- package/docs/context.md +131 -0
- package/docs/index.md +15 -12
- package/docs/lifecycle.md +102 -55
- package/docs/long-running-agents.md +2 -2
- package/docs/mcp-servers.md +5 -1
- package/docs/resumable-streaming.md +1 -1
- package/docs/routing.md +105 -0
- package/docs/sessions.md +237 -871
- package/docs/streams.md +213 -0
- package/docs/sub-agents.md +184 -124
- package/docs/tasks.md +246 -0
- package/docs/voice.md +745 -0
- package/package.json +115 -13
- package/dist/capability-runner-CvHGZqUu.d.ts +0 -150
- package/dist/compaction-helpers-iiKMr2TQ.js +0 -340
- package/dist/compaction-helpers-iiKMr2TQ.js.map +0 -1
- package/dist/compaction-helpers-wUz6M3us.d.ts +0 -621
- package/dist/diagnostics-CaBjfz4J.js.map +0 -1
- package/dist/durable-object-lifecycle-D6nNQJJd.js +0 -862
- package/dist/durable-object-lifecycle-D6nNQJJd.js.map +0 -1
- package/dist/experimental/memory/session/index.d.ts +0 -671
- package/dist/experimental/memory/session/index.js +0 -2379
- package/dist/experimental/memory/session/index.js.map +0 -1
- package/dist/experimental/memory/utils/index.d.ts +0 -96
- package/dist/experimental/memory/utils/index.js +0 -79
- package/dist/experimental/memory/utils/index.js.map +0 -1
- package/dist/scheduler-CR9RHGos.js +0 -857
- package/dist/scheduler-CR9RHGos.js.map +0 -1
- package/dist/src-5W6JNKVb.js.map +0 -1
- package/dist/tool-output-truncation-CNnnGZQ3.js +0 -98
- package/dist/tool-output-truncation-CNnnGZQ3.js.map +0 -1
|
@@ -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
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import {
|
|
2
|
+
C as VoiceTransport,
|
|
3
|
+
D as VoiceTurnSource,
|
|
4
|
+
E as VoiceTurnOutcome,
|
|
5
|
+
S as VoiceStatus,
|
|
6
|
+
T as VoiceTurnMetrics,
|
|
7
|
+
_ as VoiceErrorStage,
|
|
8
|
+
b as VoiceRole,
|
|
9
|
+
c as VoiceAudioFormat,
|
|
10
|
+
d as VoiceCompletionOutcome,
|
|
11
|
+
f as VoiceCompletionOutcomeCode,
|
|
12
|
+
g as VoiceErrorCode,
|
|
13
|
+
h as VoiceError,
|
|
14
|
+
l as VoiceAudioInput,
|
|
15
|
+
m as VoiceDiagnosticsOptions,
|
|
16
|
+
o as TranscriptMessage,
|
|
17
|
+
p as VoiceDiagnosticEvent,
|
|
18
|
+
s as VOICE_PROTOCOL_VERSION,
|
|
19
|
+
v as VoiceModelFinishReason,
|
|
20
|
+
w as VoiceTransportCloseInfo,
|
|
21
|
+
y as VoicePipelineMetrics
|
|
22
|
+
} from "../types-_Faxb570.js";
|
|
23
|
+
|
|
24
|
+
//#region src/voice/client.d.ts
|
|
25
|
+
interface VoiceClientOptions {
|
|
26
|
+
/** Agent name (matches the server-side Durable Object class). */
|
|
27
|
+
agent: string;
|
|
28
|
+
/** Instance name for the agent. @default "default" */
|
|
29
|
+
name?: string;
|
|
30
|
+
/** Host to connect to. @default window.location.host */
|
|
31
|
+
host?: string;
|
|
32
|
+
/** Query parameters appended to the WebSocket URL. */
|
|
33
|
+
query?: Record<string, string | null | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Custom transport for sending/receiving data.
|
|
36
|
+
* Defaults to a WebSocket transport via PartySocket.
|
|
37
|
+
* Provide a custom implementation for WebRTC, SFU, or other transports.
|
|
38
|
+
*/
|
|
39
|
+
transport?: VoiceTransport;
|
|
40
|
+
/**
|
|
41
|
+
* Custom audio input source. When provided, VoiceClient does NOT
|
|
42
|
+
* use its built-in AudioWorklet mic capture. The audio input is
|
|
43
|
+
* responsible for capturing and routing audio to the server.
|
|
44
|
+
* It must report audio levels via `onAudioLevel` for silence and
|
|
45
|
+
* interrupt detection to work.
|
|
46
|
+
*/
|
|
47
|
+
audioInput?: VoiceAudioInput;
|
|
48
|
+
/**
|
|
49
|
+
* Preferred audio format for server responses. Sent in `start_call`
|
|
50
|
+
* as a hint — the server may ignore it if it cannot produce that format.
|
|
51
|
+
* The actual format is declared in the server's `audio_config` message.
|
|
52
|
+
*/
|
|
53
|
+
preferredFormat?: VoiceAudioFormat;
|
|
54
|
+
/** RMS threshold below which audio is considered silence. @default 0.04 */
|
|
55
|
+
silenceThreshold?: number;
|
|
56
|
+
/** How long silence must last before sending end_of_speech (ms). @default 500 */
|
|
57
|
+
silenceDurationMs?: number;
|
|
58
|
+
/** RMS threshold for detecting user speech during agent playback. @default 0.05 */
|
|
59
|
+
interruptThreshold?: number;
|
|
60
|
+
/** Consecutive high-RMS chunks needed to trigger an interrupt. @default 2 */
|
|
61
|
+
interruptChunks?: number;
|
|
62
|
+
/** Maximum transcript messages to keep in memory. @default 200 */
|
|
63
|
+
maxTranscriptMessages?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Preferred audio output device for assistant playback.
|
|
66
|
+
* Pass a MediaDeviceInfo.deviceId from an audiooutput device.
|
|
67
|
+
* Unsupported browsers continue playing through the default output.
|
|
68
|
+
* @default "default"
|
|
69
|
+
*/
|
|
70
|
+
outputDeviceId?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Low-level browser transport information for diagnosing connection failures.
|
|
74
|
+
* Error causes stay as the raw `unknown` value because browsers do not
|
|
75
|
+
* guarantee useful fields on WebSocket error events. The SDK does not
|
|
76
|
+
* serialize or log this local event; consumers must narrow it before use.
|
|
77
|
+
*/
|
|
78
|
+
type VoiceConnectionDiagnostic =
|
|
79
|
+
| {
|
|
80
|
+
type: "error";
|
|
81
|
+
cause: unknown;
|
|
82
|
+
}
|
|
83
|
+
| ({
|
|
84
|
+
type: "close";
|
|
85
|
+
} & VoiceTransportCloseInfo);
|
|
86
|
+
/** Maps each event name to the data type passed to its listeners. */
|
|
87
|
+
interface VoiceClientEventMap {
|
|
88
|
+
statuschange: VoiceStatus;
|
|
89
|
+
transcriptchange: TranscriptMessage[];
|
|
90
|
+
interimtranscript: string | null;
|
|
91
|
+
metricschange: VoicePipelineMetrics | null;
|
|
92
|
+
turnmetrics: VoiceTurnMetrics;
|
|
93
|
+
audiolevelchange: number;
|
|
94
|
+
connectionchange: boolean;
|
|
95
|
+
connectiondiagnostic: VoiceConnectionDiagnostic;
|
|
96
|
+
voiceerror: VoiceError;
|
|
97
|
+
completionoutcome: VoiceCompletionOutcome;
|
|
98
|
+
error: string | null;
|
|
99
|
+
outputdeviceerror: string | null;
|
|
100
|
+
mutechange: boolean;
|
|
101
|
+
custommessage: unknown;
|
|
102
|
+
}
|
|
103
|
+
type VoiceClientEvent = keyof VoiceClientEventMap;
|
|
104
|
+
/**
|
|
105
|
+
* Default VoiceTransport backed by PartySocket (reconnecting WebSocket).
|
|
106
|
+
* Created automatically when no custom transport is provided.
|
|
107
|
+
*/
|
|
108
|
+
declare class WebSocketVoiceTransport implements VoiceTransport {
|
|
109
|
+
#private;
|
|
110
|
+
onopen: (() => void) | null;
|
|
111
|
+
onclose: ((info?: VoiceTransportCloseInfo) => void) | null;
|
|
112
|
+
onerror: ((error?: unknown) => void) | null;
|
|
113
|
+
onmessage: ((data: string | ArrayBuffer | Blob) => void) | null;
|
|
114
|
+
constructor(options: {
|
|
115
|
+
agent: string;
|
|
116
|
+
name?: string;
|
|
117
|
+
host?: string;
|
|
118
|
+
query?: Record<string, string | null | undefined>;
|
|
119
|
+
});
|
|
120
|
+
get connected(): boolean;
|
|
121
|
+
sendJSON(data: Record<string, unknown>): void;
|
|
122
|
+
sendBinary(data: ArrayBuffer): void;
|
|
123
|
+
connect(): void;
|
|
124
|
+
disconnect(): void;
|
|
125
|
+
}
|
|
126
|
+
declare class VoiceClient {
|
|
127
|
+
#private;
|
|
128
|
+
constructor(options: VoiceClientOptions);
|
|
129
|
+
get status(): VoiceStatus;
|
|
130
|
+
get transcript(): TranscriptMessage[];
|
|
131
|
+
get metrics(): VoicePipelineMetrics | null;
|
|
132
|
+
/** Last stable terminal summary received for any speech or text turn. */
|
|
133
|
+
get turnMetrics(): VoiceTurnMetrics | null;
|
|
134
|
+
get audioLevel(): number;
|
|
135
|
+
get isMuted(): boolean;
|
|
136
|
+
get connected(): boolean;
|
|
137
|
+
get error(): string | null;
|
|
138
|
+
get outputDeviceError(): string | null;
|
|
139
|
+
/**
|
|
140
|
+
* The current interim (partial) transcript from streaming STT.
|
|
141
|
+
* Updates in real time as the user speaks. Cleared when the final
|
|
142
|
+
* transcript is produced or the call reaches a terminal reset.
|
|
143
|
+
* null when no interim text is available.
|
|
144
|
+
*/
|
|
145
|
+
get interimTranscript(): string | null;
|
|
146
|
+
/**
|
|
147
|
+
* The protocol version reported by the server.
|
|
148
|
+
* null until the server sends its welcome message.
|
|
149
|
+
*/
|
|
150
|
+
get serverProtocolVersion(): number | null;
|
|
151
|
+
addEventListener<K extends VoiceClientEvent>(
|
|
152
|
+
event: K,
|
|
153
|
+
listener: (data: VoiceClientEventMap[K]) => void
|
|
154
|
+
): void;
|
|
155
|
+
removeEventListener<K extends VoiceClientEvent>(
|
|
156
|
+
event: K,
|
|
157
|
+
listener: (data: VoiceClientEventMap[K]) => void
|
|
158
|
+
): void;
|
|
159
|
+
connect(): void;
|
|
160
|
+
disconnect(): void;
|
|
161
|
+
startCall(): Promise<void>;
|
|
162
|
+
endCall(): void;
|
|
163
|
+
toggleMute(): void;
|
|
164
|
+
/**
|
|
165
|
+
* Send a text message to the agent. The agent processes it through
|
|
166
|
+
* `onTurn()` (bypassing STT) and responds with text transcript and
|
|
167
|
+
* TTS audio (if in a call) or text-only (if not).
|
|
168
|
+
*/
|
|
169
|
+
sendText(text: string): void;
|
|
170
|
+
/**
|
|
171
|
+
* Send arbitrary JSON to the agent. Use this for app-level messages
|
|
172
|
+
* that are not part of the voice protocol (e.g. `{ type: "kick_speaker" }`).
|
|
173
|
+
* The server receives these in the consumer's `onMessage()` handler.
|
|
174
|
+
*/
|
|
175
|
+
sendJSON(data: Record<string, unknown>): void;
|
|
176
|
+
/**
|
|
177
|
+
* Set the preferred audio output device for assistant playback.
|
|
178
|
+
* Unsupported browsers continue playing through the default output.
|
|
179
|
+
*/
|
|
180
|
+
setOutputDevice(outputDeviceId?: string): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* The last custom (non-voice-protocol) message received from the server.
|
|
183
|
+
* Listen for the `"custommessage"` event to be notified when this changes.
|
|
184
|
+
*/
|
|
185
|
+
get lastCustomMessage(): unknown;
|
|
186
|
+
/**
|
|
187
|
+
* The audio format the server declared for binary payloads.
|
|
188
|
+
* Set when the server sends `audio_config` at call start.
|
|
189
|
+
*/
|
|
190
|
+
get audioFormat(): VoiceAudioFormat | null;
|
|
191
|
+
/**
|
|
192
|
+
* The sample rate (Hz) the server declared for raw pcm16 payloads.
|
|
193
|
+
* Set when the server sends `audio_config` at call start. Defaults to 16000.
|
|
194
|
+
*/
|
|
195
|
+
get sampleRate(): number;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export {
|
|
199
|
+
type TranscriptMessage,
|
|
200
|
+
VOICE_PROTOCOL_VERSION,
|
|
201
|
+
type VoiceAudioFormat,
|
|
202
|
+
type VoiceAudioInput,
|
|
203
|
+
VoiceClient,
|
|
204
|
+
VoiceClientEvent,
|
|
205
|
+
VoiceClientEventMap,
|
|
206
|
+
VoiceClientOptions,
|
|
207
|
+
type VoiceCompletionOutcome,
|
|
208
|
+
type VoiceCompletionOutcomeCode,
|
|
209
|
+
VoiceConnectionDiagnostic,
|
|
210
|
+
type VoiceDiagnosticEvent,
|
|
211
|
+
type VoiceDiagnosticsOptions,
|
|
212
|
+
type VoiceError,
|
|
213
|
+
type VoiceErrorCode,
|
|
214
|
+
type VoiceErrorStage,
|
|
215
|
+
type VoiceModelFinishReason,
|
|
216
|
+
type VoicePipelineMetrics,
|
|
217
|
+
type VoiceRole,
|
|
218
|
+
type VoiceStatus,
|
|
219
|
+
type VoiceTransport,
|
|
220
|
+
type VoiceTransportCloseInfo,
|
|
221
|
+
type VoiceTurnMetrics,
|
|
222
|
+
type VoiceTurnOutcome,
|
|
223
|
+
type VoiceTurnSource,
|
|
224
|
+
WebSocketVoiceTransport
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=client.d.ts.map
|