@livekit/agents 1.0.2 → 1.0.4
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/dist/index.cjs +2 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/ipc/job_proc_lazy_main.cjs +3 -2
- package/dist/ipc/job_proc_lazy_main.cjs.map +1 -1
- package/dist/ipc/job_proc_lazy_main.js +4 -3
- package/dist/ipc/job_proc_lazy_main.js.map +1 -1
- package/dist/job.cjs +20 -14
- package/dist/job.cjs.map +1 -1
- package/dist/job.d.cts +11 -5
- package/dist/job.d.ts +11 -5
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +17 -12
- package/dist/job.js.map +1 -1
- package/dist/tokenize/basic/hyphenator.cjs.map +1 -1
- package/dist/tokenize/basic/hyphenator.js.map +1 -1
- package/dist/utils.cjs +77 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +21 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +76 -1
- package/dist/utils.js.map +1 -1
- package/dist/voice/agent_activity.cjs +112 -71
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +112 -71
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +9 -2
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +9 -2
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/avatar/datastream_io.cjs +204 -0
- package/dist/voice/avatar/datastream_io.cjs.map +1 -0
- package/dist/voice/avatar/datastream_io.d.cts +37 -0
- package/dist/voice/avatar/datastream_io.d.ts +37 -0
- package/dist/voice/avatar/datastream_io.d.ts.map +1 -0
- package/dist/voice/avatar/datastream_io.js +188 -0
- package/dist/voice/avatar/datastream_io.js.map +1 -0
- package/dist/{multimodal → voice/avatar}/index.cjs +4 -4
- package/dist/voice/avatar/index.cjs.map +1 -0
- package/dist/voice/avatar/index.d.cts +2 -0
- package/dist/voice/avatar/index.d.ts +2 -0
- package/dist/voice/avatar/index.d.ts.map +1 -0
- package/dist/voice/avatar/index.js +2 -0
- package/dist/voice/avatar/index.js.map +1 -0
- package/dist/voice/index.cjs +2 -0
- package/dist/voice/index.cjs.map +1 -1
- package/dist/voice/index.d.cts +1 -0
- package/dist/voice/index.d.ts +1 -0
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +1 -0
- package/dist/voice/index.js.map +1 -1
- package/dist/voice/io.cjs.map +1 -1
- package/dist/voice/io.d.cts +1 -1
- package/dist/voice/io.d.ts +1 -1
- package/dist/voice/io.d.ts.map +1 -1
- package/dist/voice/io.js.map +1 -1
- package/dist/voice/room_io/_input.cjs +2 -1
- package/dist/voice/room_io/_input.cjs.map +1 -1
- package/dist/voice/room_io/_input.d.ts.map +1 -1
- package/dist/voice/room_io/_input.js +2 -1
- package/dist/voice/room_io/_input.js.map +1 -1
- package/dist/voice/run_context.cjs +13 -0
- package/dist/voice/run_context.cjs.map +1 -1
- package/dist/voice/run_context.d.cts +10 -0
- package/dist/voice/run_context.d.ts +10 -0
- package/dist/voice/run_context.d.ts.map +1 -1
- package/dist/voice/run_context.js +13 -0
- package/dist/voice/run_context.js.map +1 -1
- package/dist/voice/speech_handle.cjs +152 -30
- package/dist/voice/speech_handle.cjs.map +1 -1
- package/dist/voice/speech_handle.d.cts +67 -16
- package/dist/voice/speech_handle.d.ts +67 -16
- package/dist/voice/speech_handle.d.ts.map +1 -1
- package/dist/voice/speech_handle.js +153 -31
- package/dist/voice/speech_handle.js.map +1 -1
- package/dist/worker.cjs +4 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +4 -1
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -3
- package/src/ipc/job_proc_lazy_main.ts +6 -3
- package/src/job.ts +27 -12
- package/src/tokenize/basic/hyphenator.ts +1 -1
- package/src/utils.ts +121 -1
- package/src/voice/agent_activity.ts +128 -78
- package/src/voice/agent_session.ts +11 -2
- package/src/voice/avatar/datastream_io.ts +247 -0
- package/src/voice/avatar/index.ts +4 -0
- package/src/voice/index.ts +2 -0
- package/src/voice/io.ts +1 -1
- package/src/voice/room_io/_input.ts +8 -3
- package/src/voice/run_context.ts +16 -2
- package/src/voice/speech_handle.ts +183 -38
- package/src/worker.ts +5 -1
- package/dist/multimodal/agent_playout.cjs +0 -233
- package/dist/multimodal/agent_playout.cjs.map +0 -1
- package/dist/multimodal/agent_playout.d.cts +0 -34
- package/dist/multimodal/agent_playout.d.ts +0 -34
- package/dist/multimodal/agent_playout.d.ts.map +0 -1
- package/dist/multimodal/agent_playout.js +0 -207
- package/dist/multimodal/agent_playout.js.map +0 -1
- package/dist/multimodal/index.cjs.map +0 -1
- package/dist/multimodal/index.d.cts +0 -2
- package/dist/multimodal/index.d.ts +0 -2
- package/dist/multimodal/index.d.ts.map +0 -1
- package/dist/multimodal/index.js +0 -2
- package/dist/multimodal/index.js.map +0 -1
- package/src/multimodal/agent_playout.ts +0 -266
- package/src/multimodal/index.ts +0 -4
|
@@ -22,12 +22,18 @@ __export(speech_handle_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(speech_handle_exports);
|
|
24
24
|
var import_utils = require("../utils.cjs");
|
|
25
|
+
var import_agent = require("./agent.cjs");
|
|
25
26
|
class SpeechHandle {
|
|
26
|
-
constructor(
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
27
|
+
constructor(_id, _allowInterruptions, _stepIndex, parent) {
|
|
28
|
+
this._id = _id;
|
|
29
|
+
this._allowInterruptions = _allowInterruptions;
|
|
30
|
+
this._stepIndex = _stepIndex;
|
|
30
31
|
this.parent = parent;
|
|
32
|
+
this.doneFut.await.finally(() => {
|
|
33
|
+
for (const callback of this.doneCallbacks) {
|
|
34
|
+
callback(this);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
31
37
|
}
|
|
32
38
|
/** Priority for messages that should be played after all other messages in the queue */
|
|
33
39
|
static SPEECH_PRIORITY_LOW = 0;
|
|
@@ -36,21 +42,58 @@ class SpeechHandle {
|
|
|
36
42
|
/** Priority for important messages that should be played before others. */
|
|
37
43
|
static SPEECH_PRIORITY_HIGH = 10;
|
|
38
44
|
interruptFut = new import_utils.Future();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
authorizedEvent = new import_utils.Event();
|
|
46
|
+
scheduledFut = new import_utils.Future();
|
|
47
|
+
doneFut = new import_utils.Future();
|
|
48
|
+
generations = [];
|
|
49
|
+
/** @internal */
|
|
50
|
+
_tasks = [];
|
|
51
|
+
_chatItems = [];
|
|
52
|
+
_numSteps = 1;
|
|
53
|
+
itemAddedCallbacks = /* @__PURE__ */ new Set();
|
|
54
|
+
doneCallbacks = /* @__PURE__ */ new Set();
|
|
42
55
|
static create(options) {
|
|
43
|
-
const { allowInterruptions =
|
|
56
|
+
const { allowInterruptions = true, stepIndex = 0, parent } = options ?? {};
|
|
44
57
|
return new SpeechHandle((0, import_utils.shortuuid)("speech_"), allowInterruptions, stepIndex, parent);
|
|
45
58
|
}
|
|
46
59
|
get interrupted() {
|
|
47
60
|
return this.interruptFut.done;
|
|
48
61
|
}
|
|
49
|
-
get
|
|
50
|
-
return this.
|
|
62
|
+
get numSteps() {
|
|
63
|
+
return this._numSteps;
|
|
64
|
+
}
|
|
65
|
+
get id() {
|
|
66
|
+
return this._id;
|
|
67
|
+
}
|
|
68
|
+
get scheduled() {
|
|
69
|
+
return this.scheduledFut.done;
|
|
70
|
+
}
|
|
71
|
+
get allowInterruptions() {
|
|
72
|
+
return this._allowInterruptions;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Allow or disallow interruptions on this SpeechHandle.
|
|
76
|
+
*
|
|
77
|
+
* When set to false, the SpeechHandle will no longer accept any incoming
|
|
78
|
+
* interruption requests until re-enabled. If the handle is already
|
|
79
|
+
* interrupted, clearing interruptions is not allowed.
|
|
80
|
+
*
|
|
81
|
+
* @param value - true to allow interruptions, false to disallow
|
|
82
|
+
* @throws Error If attempting to disable interruptions when already interrupted
|
|
83
|
+
*/
|
|
84
|
+
set allowInterruptions(value) {
|
|
85
|
+
if (this.interrupted && !value) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
"Cannot set allow_interruptions to False, the SpeechHandle is already interrupted"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
this._allowInterruptions = value;
|
|
91
|
+
}
|
|
92
|
+
done() {
|
|
93
|
+
return this.doneFut.done;
|
|
51
94
|
}
|
|
52
|
-
get
|
|
53
|
-
return this.
|
|
95
|
+
get chatItems() {
|
|
96
|
+
return this._chatItems;
|
|
54
97
|
}
|
|
55
98
|
/**
|
|
56
99
|
* Interrupt the current speech generation.
|
|
@@ -59,43 +102,122 @@ class SpeechHandle {
|
|
|
59
102
|
*
|
|
60
103
|
* @returns The same speech handle that was interrupted.
|
|
61
104
|
*/
|
|
62
|
-
interrupt() {
|
|
63
|
-
if (!this.allowInterruptions) {
|
|
64
|
-
throw new Error("
|
|
105
|
+
interrupt(force = false) {
|
|
106
|
+
if (!force && !this.allowInterruptions) {
|
|
107
|
+
throw new Error("This generation handle does not allow interruptions");
|
|
65
108
|
}
|
|
66
|
-
|
|
67
|
-
this.interruptFut.resolve();
|
|
109
|
+
this._cancel();
|
|
68
110
|
return this;
|
|
69
111
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Waits for the entire assistant turn to complete playback.
|
|
114
|
+
*
|
|
115
|
+
* This method waits until the assistant has fully finished speaking,
|
|
116
|
+
* including any finalization steps beyond initial response generation.
|
|
117
|
+
* This is appropriate to call when you want to ensure the speech output
|
|
118
|
+
* has entirely played out, including any tool calls and response follow-ups.
|
|
119
|
+
*/
|
|
73
120
|
async waitForPlayout() {
|
|
74
|
-
|
|
121
|
+
const store = import_agent.asyncLocalStorage.getStore();
|
|
122
|
+
if (store && (store == null ? void 0 : store.functionCall)) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Cannot call 'SpeechHandle.waitForPlayout()' from inside the function tool '${store.functionCall.name}'. This creates a circular wait: the speech handle is waiting for the function tool to complete, while the function tool is simultaneously waiting for the speech handle.
|
|
125
|
+
To wait for the assistant's spoken response prior to running this tool, use RunContext.wait_for_playout() instead.`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
75
128
|
}
|
|
76
129
|
async waitIfNotInterrupted(aw) {
|
|
77
130
|
const allTasksPromise = Promise.all(aw);
|
|
78
131
|
const fs = [allTasksPromise, this.interruptFut.await];
|
|
79
132
|
await Promise.race(fs);
|
|
80
133
|
}
|
|
134
|
+
addDoneCallback(callback) {
|
|
135
|
+
this.doneCallbacks.add(callback);
|
|
136
|
+
}
|
|
137
|
+
removeDoneCallback(callback) {
|
|
138
|
+
this.doneCallbacks.delete(callback);
|
|
139
|
+
}
|
|
81
140
|
/** @internal */
|
|
82
|
-
|
|
83
|
-
if (this.done) {
|
|
84
|
-
|
|
141
|
+
_cancel() {
|
|
142
|
+
if (this.done()) {
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
if (!this.interruptFut.done) {
|
|
146
|
+
this.interruptFut.resolve();
|
|
85
147
|
}
|
|
86
|
-
this
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
/** @internal */
|
|
151
|
+
_authorizeGeneration() {
|
|
152
|
+
const fut = new import_utils.Future();
|
|
153
|
+
this.generations.push(fut);
|
|
154
|
+
this.authorizedEvent.set();
|
|
87
155
|
}
|
|
88
156
|
/** @internal */
|
|
89
|
-
|
|
90
|
-
this.
|
|
157
|
+
_clearAuthorization() {
|
|
158
|
+
this.authorizedEvent.clear();
|
|
91
159
|
}
|
|
92
160
|
/** @internal */
|
|
93
161
|
async _waitForAuthorization() {
|
|
94
|
-
|
|
162
|
+
await this.authorizedEvent.wait();
|
|
95
163
|
}
|
|
96
164
|
/** @internal */
|
|
97
|
-
|
|
98
|
-
this.
|
|
165
|
+
async _waitForGeneration(stepIdx = -1) {
|
|
166
|
+
if (this.generations.length === 0) {
|
|
167
|
+
throw new Error("cannot use wait_for_generation: no active generation is running.");
|
|
168
|
+
}
|
|
169
|
+
const index = stepIdx === -1 ? this.generations.length - 1 : stepIdx;
|
|
170
|
+
const generation = this.generations[index];
|
|
171
|
+
if (!generation) {
|
|
172
|
+
throw new Error(`Generation at index ${index} not found.`);
|
|
173
|
+
}
|
|
174
|
+
return generation.await;
|
|
175
|
+
}
|
|
176
|
+
/** @internal */
|
|
177
|
+
async _waitForScheduled() {
|
|
178
|
+
return this.scheduledFut.await;
|
|
179
|
+
}
|
|
180
|
+
/** @internal */
|
|
181
|
+
_markGenerationDone() {
|
|
182
|
+
if (this.generations.length === 0) {
|
|
183
|
+
throw new Error("cannot use mark_generation_done: no active generation is running.");
|
|
184
|
+
}
|
|
185
|
+
const lastGeneration = this.generations[this.generations.length - 1];
|
|
186
|
+
if (lastGeneration && !lastGeneration.done) {
|
|
187
|
+
lastGeneration.resolve();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** @internal */
|
|
191
|
+
_markDone() {
|
|
192
|
+
if (!this.doneFut.done) {
|
|
193
|
+
this.doneFut.resolve();
|
|
194
|
+
if (this.generations.length > 0) {
|
|
195
|
+
this._markGenerationDone();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** @internal */
|
|
200
|
+
_markScheduled() {
|
|
201
|
+
if (!this.scheduledFut.done) {
|
|
202
|
+
this.scheduledFut.resolve();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** @internal */
|
|
206
|
+
_addItemAddedCallback(callback) {
|
|
207
|
+
this.itemAddedCallbacks.add(callback);
|
|
208
|
+
}
|
|
209
|
+
/** @internal */
|
|
210
|
+
_removeItemAddedCallback(callback) {
|
|
211
|
+
this.itemAddedCallbacks.delete(callback);
|
|
212
|
+
}
|
|
213
|
+
/** @internal */
|
|
214
|
+
_itemAdded(items) {
|
|
215
|
+
for (const item of items) {
|
|
216
|
+
for (const cb of this.itemAddedCallbacks) {
|
|
217
|
+
cb(item);
|
|
218
|
+
}
|
|
219
|
+
this._chatItems.push(item);
|
|
220
|
+
}
|
|
99
221
|
}
|
|
100
222
|
}
|
|
101
223
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/voice/speech_handle.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChatMessage } from '../llm/index.js';\nimport { Future, shortuuid } from '../utils.js';\n\nexport class SpeechHandle {\n /** Priority for messages that should be played after all other messages in the queue */\n static SPEECH_PRIORITY_LOW = 0;\n /** Every speech generates by the VoiceAgent defaults to this priority. */\n static SPEECH_PRIORITY_NORMAL = 5;\n /** Priority for important messages that should be played before others. */\n static SPEECH_PRIORITY_HIGH = 10;\n\n private interruptFut = new Future();\n private authorizeFut = new Future();\n private playoutDoneFut = new Future();\n\n private _chatMessage?: ChatMessage;\n\n constructor(\n readonly id: string,\n readonly allowInterruptions: boolean,\n readonly stepIndex: number,\n readonly parent?: SpeechHandle,\n ) {}\n\n static create(options: {\n allowInterruptions?: boolean;\n stepIndex?: number;\n parent?: SpeechHandle;\n }) {\n const { allowInterruptions = false, stepIndex = 0, parent } = options ?? {};\n\n return new SpeechHandle(shortuuid('speech_'), allowInterruptions, stepIndex, parent);\n }\n\n get interrupted(): boolean {\n return this.interruptFut.done;\n }\n\n get done(): boolean {\n return this.playoutDoneFut.done;\n }\n\n get chatMessage(): ChatMessage | undefined {\n return this._chatMessage;\n }\n\n /**\n * Interrupt the current speech generation.\n *\n * @throws Error If this speech handle does not allow interruptions.\n *\n * @returns The same speech handle that was interrupted.\n */\n interrupt(): SpeechHandle {\n if (!this.allowInterruptions) {\n throw new Error('interruptions are not allowed');\n }\n\n if (this.done) return this;\n\n this.interruptFut.resolve();\n return this;\n }\n\n then(callback: (sh: SpeechHandle) => void) {\n return this.playoutDoneFut.await.finally(() => callback(this));\n }\n\n async waitForPlayout() {\n return this.playoutDoneFut.await;\n }\n\n async waitIfNotInterrupted(aw: Promise<unknown>[]): Promise<void> {\n const allTasksPromise = Promise.all(aw);\n const fs: Promise<unknown>[] = [allTasksPromise, this.interruptFut.await];\n await Promise.race(fs);\n }\n\n /** @internal */\n _setChatMessage(chatMessage: ChatMessage) {\n if (this.done) {\n throw new Error('cannot set chat message after speech has been played');\n }\n this._chatMessage = chatMessage;\n }\n\n /** @internal */\n _authorizePlayout() {\n this.authorizeFut.resolve();\n }\n\n /** @internal */\n async _waitForAuthorization() {\n return this.authorizeFut.await;\n }\n\n /** @internal */\n _markPlayoutDone() {\n this.playoutDoneFut.resolve();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAkC;AAE3B,MAAM,aAAa;AAAA,EAcxB,YACW,IACA,oBACA,WACA,QACT;AAJS;AACA;AACA;AACA;AAAA,EACR;AAAA;AAAA,EAjBH,OAAO,sBAAsB;AAAA;AAAA,EAE7B,OAAO,yBAAyB;AAAA;AAAA,EAEhC,OAAO,uBAAuB;AAAA,EAEtB,eAAe,IAAI,oBAAO;AAAA,EAC1B,eAAe,IAAI,oBAAO;AAAA,EAC1B,iBAAiB,IAAI,oBAAO;AAAA,EAE5B;AAAA,EASR,OAAO,OAAO,SAIX;AACD,UAAM,EAAE,qBAAqB,OAAO,YAAY,GAAG,OAAO,IAAI,WAAW,CAAC;AAE1E,WAAO,IAAI,iBAAa,wBAAU,SAAS,GAAG,oBAAoB,WAAW,MAAM;AAAA,EACrF;AAAA,EAEA,IAAI,cAAuB;AACzB,WAAO,KAAK,aAAa;AAAA,EAC3B;AAAA,EAEA,IAAI,OAAgB;AAClB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,cAAuC;AACzC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAA0B;AACxB,QAAI,CAAC,KAAK,oBAAoB;AAC5B,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AAEA,QAAI,KAAK,KAAM,QAAO;AAEtB,SAAK,aAAa,QAAQ;AAC1B,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,UAAsC;AACzC,WAAO,KAAK,eAAe,MAAM,QAAQ,MAAM,SAAS,IAAI,CAAC;AAAA,EAC/D;AAAA,EAEA,MAAM,iBAAiB;AACrB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,qBAAqB,IAAuC;AAChE,UAAM,kBAAkB,QAAQ,IAAI,EAAE;AACtC,UAAM,KAAyB,CAAC,iBAAiB,KAAK,aAAa,KAAK;AACxE,UAAM,QAAQ,KAAK,EAAE;AAAA,EACvB;AAAA;AAAA,EAGA,gBAAgB,aAA0B;AACxC,QAAI,KAAK,MAAM;AACb,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AACA,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,oBAAoB;AAClB,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA;AAAA,EAGA,MAAM,wBAAwB;AAC5B,WAAO,KAAK,aAAa;AAAA,EAC3B;AAAA;AAAA,EAGA,mBAAmB;AACjB,SAAK,eAAe,QAAQ;AAAA,EAC9B;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/voice/speech_handle.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChatItem } from '../llm/index.js';\nimport { Event, Future, shortuuid } from '../utils.js';\nimport type { Task } from '../utils.js';\nimport { asyncLocalStorage } from './agent.js';\n\nexport class SpeechHandle {\n /** Priority for messages that should be played after all other messages in the queue */\n static SPEECH_PRIORITY_LOW = 0;\n /** Every speech generates by the VoiceAgent defaults to this priority. */\n static SPEECH_PRIORITY_NORMAL = 5;\n /** Priority for important messages that should be played before others. */\n static SPEECH_PRIORITY_HIGH = 10;\n\n private interruptFut = new Future<void>();\n private authorizedEvent = new Event();\n private scheduledFut = new Future<void>();\n private doneFut = new Future<void>();\n\n private generations: Future<void>[] = [];\n /** @internal */\n _tasks: Task<void>[] = [];\n private _chatItems: ChatItem[] = [];\n private _numSteps = 1;\n\n private itemAddedCallbacks: Set<(item: ChatItem) => void> = new Set();\n private doneCallbacks: Set<(sh: SpeechHandle) => void> = new Set();\n\n constructor(\n private _id: string,\n private _allowInterruptions: boolean,\n /** @internal */\n public _stepIndex: number,\n readonly parent?: SpeechHandle,\n ) {\n this.doneFut.await.finally(() => {\n for (const callback of this.doneCallbacks) {\n callback(this);\n }\n });\n }\n\n static create(options?: {\n allowInterruptions?: boolean;\n stepIndex?: number;\n parent?: SpeechHandle;\n }) {\n const { allowInterruptions = true, stepIndex = 0, parent } = options ?? {};\n\n return new SpeechHandle(shortuuid('speech_'), allowInterruptions, stepIndex, parent);\n }\n\n get interrupted(): boolean {\n return this.interruptFut.done;\n }\n\n get numSteps(): number {\n return this._numSteps;\n }\n\n get id(): string {\n return this._id;\n }\n\n get scheduled(): boolean {\n return this.scheduledFut.done;\n }\n\n get allowInterruptions(): boolean {\n return this._allowInterruptions;\n }\n\n /**\n * Allow or disallow interruptions on this SpeechHandle.\n *\n * When set to false, the SpeechHandle will no longer accept any incoming\n * interruption requests until re-enabled. If the handle is already\n * interrupted, clearing interruptions is not allowed.\n *\n * @param value - true to allow interruptions, false to disallow\n * @throws Error If attempting to disable interruptions when already interrupted\n */\n set allowInterruptions(value: boolean) {\n if (this.interrupted && !value) {\n throw new Error(\n 'Cannot set allow_interruptions to False, the SpeechHandle is already interrupted',\n );\n }\n this._allowInterruptions = value;\n }\n\n done(): boolean {\n return this.doneFut.done;\n }\n\n get chatItems(): ChatItem[] {\n return this._chatItems;\n }\n\n /**\n * Interrupt the current speech generation.\n *\n * @throws Error If this speech handle does not allow interruptions.\n *\n * @returns The same speech handle that was interrupted.\n */\n interrupt(force: boolean = false): SpeechHandle {\n if (!force && !this.allowInterruptions) {\n throw new Error('This generation handle does not allow interruptions');\n }\n\n this._cancel();\n return this;\n }\n\n /**\n * Waits for the entire assistant turn to complete playback.\n *\n * This method waits until the assistant has fully finished speaking,\n * including any finalization steps beyond initial response generation.\n * This is appropriate to call when you want to ensure the speech output\n * has entirely played out, including any tool calls and response follow-ups.\n */\n async waitForPlayout(): Promise<void> {\n const store = asyncLocalStorage.getStore();\n if (store && store?.functionCall) {\n throw new Error(\n `Cannot call 'SpeechHandle.waitForPlayout()' from inside the function tool '${store.functionCall.name}'. ` +\n 'This creates a circular wait: the speech handle is waiting for the function tool to complete, ' +\n 'while the function tool is simultaneously waiting for the speech handle.\\n' +\n \"To wait for the assistant's spoken response prior to running this tool, use RunContext.wait_for_playout() instead.\",\n );\n }\n }\n\n async waitIfNotInterrupted(aw: Promise<unknown>[]): Promise<void> {\n const allTasksPromise = Promise.all(aw);\n const fs: Promise<unknown>[] = [allTasksPromise, this.interruptFut.await];\n await Promise.race(fs);\n }\n\n addDoneCallback(callback: (sh: SpeechHandle) => void) {\n this.doneCallbacks.add(callback);\n }\n\n removeDoneCallback(callback: (sh: SpeechHandle) => void) {\n this.doneCallbacks.delete(callback);\n }\n\n /** @internal */\n _cancel(): SpeechHandle {\n if (this.done()) {\n return this;\n }\n\n if (!this.interruptFut.done) {\n this.interruptFut.resolve();\n }\n\n return this;\n }\n\n /** @internal */\n _authorizeGeneration(): void {\n const fut = new Future<void>();\n this.generations.push(fut);\n this.authorizedEvent.set();\n }\n\n /** @internal */\n _clearAuthorization(): void {\n this.authorizedEvent.clear();\n }\n\n /** @internal */\n async _waitForAuthorization(): Promise<void> {\n await this.authorizedEvent.wait();\n }\n\n /** @internal */\n async _waitForGeneration(stepIdx: number = -1): Promise<void> {\n if (this.generations.length === 0) {\n throw new Error('cannot use wait_for_generation: no active generation is running.');\n }\n\n const index = stepIdx === -1 ? this.generations.length - 1 : stepIdx;\n const generation = this.generations[index];\n if (!generation) {\n throw new Error(`Generation at index ${index} not found.`);\n }\n return generation.await;\n }\n\n /** @internal */\n async _waitForScheduled(): Promise<void> {\n return this.scheduledFut.await;\n }\n\n /** @internal */\n _markGenerationDone(): void {\n if (this.generations.length === 0) {\n throw new Error('cannot use mark_generation_done: no active generation is running.');\n }\n\n const lastGeneration = this.generations[this.generations.length - 1];\n if (lastGeneration && !lastGeneration.done) {\n lastGeneration.resolve();\n }\n }\n\n /** @internal */\n _markDone(): void {\n if (!this.doneFut.done) {\n this.doneFut.resolve();\n if (this.generations.length > 0) {\n this._markGenerationDone(); // preemptive generation could be cancelled before being scheduled\n }\n }\n }\n\n /** @internal */\n _markScheduled(): void {\n if (!this.scheduledFut.done) {\n this.scheduledFut.resolve();\n }\n }\n\n /** @internal */\n _addItemAddedCallback(callback: (item: ChatItem) => void): void {\n this.itemAddedCallbacks.add(callback);\n }\n\n /** @internal */\n _removeItemAddedCallback(callback: (item: ChatItem) => void): void {\n this.itemAddedCallbacks.delete(callback);\n }\n\n /** @internal */\n _itemAdded(items: ChatItem[]): void {\n for (const item of items) {\n for (const cb of this.itemAddedCallbacks) {\n cb(item);\n }\n this._chatItems.push(item);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAyC;AAEzC,mBAAkC;AAE3B,MAAM,aAAa;AAAA,EAsBxB,YACU,KACA,qBAED,YACE,QACT;AALQ;AACA;AAED;AACE;AAET,SAAK,QAAQ,MAAM,QAAQ,MAAM;AAC/B,iBAAW,YAAY,KAAK,eAAe;AACzC,iBAA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AA,IAC3B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChatItem } from '../llm/index.js';
|
|
2
|
+
import type { Task } from '../utils.js';
|
|
2
3
|
export declare class SpeechHandle {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
private _id;
|
|
5
|
+
private _allowInterruptions;
|
|
6
|
+
/** @internal */
|
|
7
|
+
_stepIndex: number;
|
|
6
8
|
readonly parent?: SpeechHandle | undefined;
|
|
7
9
|
/** Priority for messages that should be played after all other messages in the queue */
|
|
8
10
|
static SPEECH_PRIORITY_LOW: number;
|
|
@@ -11,18 +13,42 @@ export declare class SpeechHandle {
|
|
|
11
13
|
/** Priority for important messages that should be played before others. */
|
|
12
14
|
static SPEECH_PRIORITY_HIGH: number;
|
|
13
15
|
private interruptFut;
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
private authorizedEvent;
|
|
17
|
+
private scheduledFut;
|
|
18
|
+
private doneFut;
|
|
19
|
+
private generations;
|
|
20
|
+
/** @internal */
|
|
21
|
+
_tasks: Task<void>[];
|
|
22
|
+
private _chatItems;
|
|
23
|
+
private _numSteps;
|
|
24
|
+
private itemAddedCallbacks;
|
|
25
|
+
private doneCallbacks;
|
|
26
|
+
constructor(_id: string, _allowInterruptions: boolean,
|
|
27
|
+
/** @internal */
|
|
28
|
+
_stepIndex: number, parent?: SpeechHandle | undefined);
|
|
29
|
+
static create(options?: {
|
|
19
30
|
allowInterruptions?: boolean;
|
|
20
31
|
stepIndex?: number;
|
|
21
32
|
parent?: SpeechHandle;
|
|
22
33
|
}): SpeechHandle;
|
|
23
34
|
get interrupted(): boolean;
|
|
24
|
-
get
|
|
25
|
-
get
|
|
35
|
+
get numSteps(): number;
|
|
36
|
+
get id(): string;
|
|
37
|
+
get scheduled(): boolean;
|
|
38
|
+
get allowInterruptions(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Allow or disallow interruptions on this SpeechHandle.
|
|
41
|
+
*
|
|
42
|
+
* When set to false, the SpeechHandle will no longer accept any incoming
|
|
43
|
+
* interruption requests until re-enabled. If the handle is already
|
|
44
|
+
* interrupted, clearing interruptions is not allowed.
|
|
45
|
+
*
|
|
46
|
+
* @param value - true to allow interruptions, false to disallow
|
|
47
|
+
* @throws Error If attempting to disable interruptions when already interrupted
|
|
48
|
+
*/
|
|
49
|
+
set allowInterruptions(value: boolean);
|
|
50
|
+
done(): boolean;
|
|
51
|
+
get chatItems(): ChatItem[];
|
|
26
52
|
/**
|
|
27
53
|
* Interrupt the current speech generation.
|
|
28
54
|
*
|
|
@@ -30,17 +56,42 @@ export declare class SpeechHandle {
|
|
|
30
56
|
*
|
|
31
57
|
* @returns The same speech handle that was interrupted.
|
|
32
58
|
*/
|
|
33
|
-
interrupt(): SpeechHandle;
|
|
34
|
-
|
|
59
|
+
interrupt(force?: boolean): SpeechHandle;
|
|
60
|
+
/**
|
|
61
|
+
* Waits for the entire assistant turn to complete playback.
|
|
62
|
+
*
|
|
63
|
+
* This method waits until the assistant has fully finished speaking,
|
|
64
|
+
* including any finalization steps beyond initial response generation.
|
|
65
|
+
* This is appropriate to call when you want to ensure the speech output
|
|
66
|
+
* has entirely played out, including any tool calls and response follow-ups.
|
|
67
|
+
*/
|
|
35
68
|
waitForPlayout(): Promise<void>;
|
|
36
69
|
waitIfNotInterrupted(aw: Promise<unknown>[]): Promise<void>;
|
|
70
|
+
addDoneCallback(callback: (sh: SpeechHandle) => void): void;
|
|
71
|
+
removeDoneCallback(callback: (sh: SpeechHandle) => void): void;
|
|
72
|
+
/** @internal */
|
|
73
|
+
_cancel(): SpeechHandle;
|
|
37
74
|
/** @internal */
|
|
38
|
-
|
|
75
|
+
_authorizeGeneration(): void;
|
|
39
76
|
/** @internal */
|
|
40
|
-
|
|
77
|
+
_clearAuthorization(): void;
|
|
41
78
|
/** @internal */
|
|
42
79
|
_waitForAuthorization(): Promise<void>;
|
|
43
80
|
/** @internal */
|
|
44
|
-
|
|
81
|
+
_waitForGeneration(stepIdx?: number): Promise<void>;
|
|
82
|
+
/** @internal */
|
|
83
|
+
_waitForScheduled(): Promise<void>;
|
|
84
|
+
/** @internal */
|
|
85
|
+
_markGenerationDone(): void;
|
|
86
|
+
/** @internal */
|
|
87
|
+
_markDone(): void;
|
|
88
|
+
/** @internal */
|
|
89
|
+
_markScheduled(): void;
|
|
90
|
+
/** @internal */
|
|
91
|
+
_addItemAddedCallback(callback: (item: ChatItem) => void): void;
|
|
92
|
+
/** @internal */
|
|
93
|
+
_removeItemAddedCallback(callback: (item: ChatItem) => void): void;
|
|
94
|
+
/** @internal */
|
|
95
|
+
_itemAdded(items: ChatItem[]): void;
|
|
45
96
|
}
|
|
46
97
|
//# sourceMappingURL=speech_handle.d.ts.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChatItem } from '../llm/index.js';
|
|
2
|
+
import type { Task } from '../utils.js';
|
|
2
3
|
export declare class SpeechHandle {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
private _id;
|
|
5
|
+
private _allowInterruptions;
|
|
6
|
+
/** @internal */
|
|
7
|
+
_stepIndex: number;
|
|
6
8
|
readonly parent?: SpeechHandle | undefined;
|
|
7
9
|
/** Priority for messages that should be played after all other messages in the queue */
|
|
8
10
|
static SPEECH_PRIORITY_LOW: number;
|
|
@@ -11,18 +13,42 @@ export declare class SpeechHandle {
|
|
|
11
13
|
/** Priority for important messages that should be played before others. */
|
|
12
14
|
static SPEECH_PRIORITY_HIGH: number;
|
|
13
15
|
private interruptFut;
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
private authorizedEvent;
|
|
17
|
+
private scheduledFut;
|
|
18
|
+
private doneFut;
|
|
19
|
+
private generations;
|
|
20
|
+
/** @internal */
|
|
21
|
+
_tasks: Task<void>[];
|
|
22
|
+
private _chatItems;
|
|
23
|
+
private _numSteps;
|
|
24
|
+
private itemAddedCallbacks;
|
|
25
|
+
private doneCallbacks;
|
|
26
|
+
constructor(_id: string, _allowInterruptions: boolean,
|
|
27
|
+
/** @internal */
|
|
28
|
+
_stepIndex: number, parent?: SpeechHandle | undefined);
|
|
29
|
+
static create(options?: {
|
|
19
30
|
allowInterruptions?: boolean;
|
|
20
31
|
stepIndex?: number;
|
|
21
32
|
parent?: SpeechHandle;
|
|
22
33
|
}): SpeechHandle;
|
|
23
34
|
get interrupted(): boolean;
|
|
24
|
-
get
|
|
25
|
-
get
|
|
35
|
+
get numSteps(): number;
|
|
36
|
+
get id(): string;
|
|
37
|
+
get scheduled(): boolean;
|
|
38
|
+
get allowInterruptions(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Allow or disallow interruptions on this SpeechHandle.
|
|
41
|
+
*
|
|
42
|
+
* When set to false, the SpeechHandle will no longer accept any incoming
|
|
43
|
+
* interruption requests until re-enabled. If the handle is already
|
|
44
|
+
* interrupted, clearing interruptions is not allowed.
|
|
45
|
+
*
|
|
46
|
+
* @param value - true to allow interruptions, false to disallow
|
|
47
|
+
* @throws Error If attempting to disable interruptions when already interrupted
|
|
48
|
+
*/
|
|
49
|
+
set allowInterruptions(value: boolean);
|
|
50
|
+
done(): boolean;
|
|
51
|
+
get chatItems(): ChatItem[];
|
|
26
52
|
/**
|
|
27
53
|
* Interrupt the current speech generation.
|
|
28
54
|
*
|
|
@@ -30,17 +56,42 @@ export declare class SpeechHandle {
|
|
|
30
56
|
*
|
|
31
57
|
* @returns The same speech handle that was interrupted.
|
|
32
58
|
*/
|
|
33
|
-
interrupt(): SpeechHandle;
|
|
34
|
-
|
|
59
|
+
interrupt(force?: boolean): SpeechHandle;
|
|
60
|
+
/**
|
|
61
|
+
* Waits for the entire assistant turn to complete playback.
|
|
62
|
+
*
|
|
63
|
+
* This method waits until the assistant has fully finished speaking,
|
|
64
|
+
* including any finalization steps beyond initial response generation.
|
|
65
|
+
* This is appropriate to call when you want to ensure the speech output
|
|
66
|
+
* has entirely played out, including any tool calls and response follow-ups.
|
|
67
|
+
*/
|
|
35
68
|
waitForPlayout(): Promise<void>;
|
|
36
69
|
waitIfNotInterrupted(aw: Promise<unknown>[]): Promise<void>;
|
|
70
|
+
addDoneCallback(callback: (sh: SpeechHandle) => void): void;
|
|
71
|
+
removeDoneCallback(callback: (sh: SpeechHandle) => void): void;
|
|
72
|
+
/** @internal */
|
|
73
|
+
_cancel(): SpeechHandle;
|
|
37
74
|
/** @internal */
|
|
38
|
-
|
|
75
|
+
_authorizeGeneration(): void;
|
|
39
76
|
/** @internal */
|
|
40
|
-
|
|
77
|
+
_clearAuthorization(): void;
|
|
41
78
|
/** @internal */
|
|
42
79
|
_waitForAuthorization(): Promise<void>;
|
|
43
80
|
/** @internal */
|
|
44
|
-
|
|
81
|
+
_waitForGeneration(stepIdx?: number): Promise<void>;
|
|
82
|
+
/** @internal */
|
|
83
|
+
_waitForScheduled(): Promise<void>;
|
|
84
|
+
/** @internal */
|
|
85
|
+
_markGenerationDone(): void;
|
|
86
|
+
/** @internal */
|
|
87
|
+
_markDone(): void;
|
|
88
|
+
/** @internal */
|
|
89
|
+
_markScheduled(): void;
|
|
90
|
+
/** @internal */
|
|
91
|
+
_addItemAddedCallback(callback: (item: ChatItem) => void): void;
|
|
92
|
+
/** @internal */
|
|
93
|
+
_removeItemAddedCallback(callback: (item: ChatItem) => void): void;
|
|
94
|
+
/** @internal */
|
|
95
|
+
_itemAdded(items: ChatItem[]): void;
|
|
45
96
|
}
|
|
46
97
|
//# sourceMappingURL=speech_handle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech_handle.d.ts","sourceRoot":"","sources":["../../src/voice/speech_handle.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"speech_handle.d.ts","sourceRoot":"","sources":["../../src/voice/speech_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