@livekit/agents 1.0.35 → 1.0.36
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/voice/agent_activity.cjs +19 -19
- 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 +19 -19
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +64 -25
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +25 -1
- package/dist/voice/agent_session.d.ts +25 -1
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +64 -25
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/index.cjs +14 -1
- 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 +3 -1
- package/dist/voice/index.js.map +1 -1
- package/dist/voice/room_io/room_io.cjs +1 -0
- package/dist/voice/room_io/room_io.cjs.map +1 -1
- package/dist/voice/room_io/room_io.d.ts.map +1 -1
- package/dist/voice/room_io/room_io.js +1 -0
- package/dist/voice/room_io/room_io.js.map +1 -1
- package/dist/voice/speech_handle.cjs +12 -3
- package/dist/voice/speech_handle.cjs.map +1 -1
- package/dist/voice/speech_handle.d.cts +12 -2
- package/dist/voice/speech_handle.d.ts +12 -2
- package/dist/voice/speech_handle.d.ts.map +1 -1
- package/dist/voice/speech_handle.js +10 -2
- package/dist/voice/speech_handle.js.map +1 -1
- package/dist/voice/testing/index.cjs +52 -0
- package/dist/voice/testing/index.cjs.map +1 -0
- package/dist/voice/testing/index.d.cts +20 -0
- package/dist/voice/testing/index.d.ts +20 -0
- package/dist/voice/testing/index.d.ts.map +1 -0
- package/dist/voice/testing/index.js +31 -0
- package/dist/voice/testing/index.js.map +1 -0
- package/dist/voice/testing/run_result.cjs +477 -0
- package/dist/voice/testing/run_result.cjs.map +1 -0
- package/dist/voice/testing/run_result.d.cts +226 -0
- package/dist/voice/testing/run_result.d.ts +226 -0
- package/dist/voice/testing/run_result.d.ts.map +1 -0
- package/dist/voice/testing/run_result.js +451 -0
- package/dist/voice/testing/run_result.js.map +1 -0
- package/dist/voice/testing/types.cjs +46 -0
- package/dist/voice/testing/types.cjs.map +1 -0
- package/dist/voice/testing/types.d.cts +83 -0
- package/dist/voice/testing/types.d.ts +83 -0
- package/dist/voice/testing/types.d.ts.map +1 -0
- package/dist/voice/testing/types.js +19 -0
- package/dist/voice/testing/types.js.map +1 -0
- package/package.json +3 -3
- package/src/voice/agent_activity.ts +24 -22
- package/src/voice/agent_session.ts +73 -28
- package/src/voice/index.ts +1 -0
- package/src/voice/room_io/room_io.ts +1 -0
- package/src/voice/speech_handle.ts +24 -4
- package/src/voice/testing/index.ts +49 -0
- package/src/voice/testing/run_result.ts +576 -0
- package/src/voice/testing/types.ts +118 -0
|
@@ -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 { 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 await this.doneFut.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 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,iBAAS,IAAI;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA,EAhCA,OAAO,sBAAsB;AAAA;AAAA,EAE7B,OAAO,yBAAyB;AAAA;AAAA,EAEhC,OAAO,uBAAuB;AAAA,EAEtB,eAAe,IAAI,oBAAa;AAAA,EAChC,kBAAkB,IAAI,mBAAM;AAAA,EAC5B,eAAe,IAAI,oBAAa;AAAA,EAChC,UAAU,IAAI,oBAAa;AAAA,EAE3B,cAA8B,CAAC;AAAA;AAAA,EAEvC,SAAuB,CAAC;AAAA,EAChB,aAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EAEZ,qBAAoD,oBAAI,IAAI;AAAA,EAC5D,gBAAiD,oBAAI,IA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K,YAAY,WAAW,GAAG;AACjC,YAAM,IAAI,MAAM,mEAAmE;AAAA,IACrF;AAEA,UAAM,iBAAiB,KAAK,YAAY,KAAK,YAAY,SAAS,CAAC;AACnE,QAAI,kBAAkB,CAAC,eAAe,MAAM;AAC1C,qBAAe,QAAQ;AAAA,IACzB;AAAA,EACF;AAAA;AAAA,EAGA,YAAkB;AAChB,QAAI,CAAC,KAAK,QAAQ,MAAM;AACtB,WAAK,QAAQ,QAAQ;AACrB,UAAI,KAAK,YAAY,SAAS,GAAG;AAC/B,aAAK,oBAAoB;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAAA;AAAA,EAGA,iBAAuB;AACrB,QAAI,CAAC,KAAK,aAAa,MAAM;AAC3B,WAAK,aAAa,QAAQ;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA,EAGA,sBAAsB,UAA0C;AAC9D,SAAK,mBAAmB,IAAI,QAAQ;AAAA,EACtC;AAAA;AAAA,EAGA,yBAAyB,UAA0C;AACjE,SAAK,mBAAmB,OAAO,QAAQ;AAAA,EACzC;AAAA;AAAA,EAGA,WAAW,OAAyB;AAClC,eAAW,QAAQ,OAAO;AACxB,iBAAW,MAAM,KAAK,oBAAoB;AACxC,WAAG,IAAI;AAAA,MACT;AACA,WAAK,WAAW,KAAK,IAAI;AAAA,IAC3B;AAAA,EACF;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 type { Task } from '../utils.js';\nimport { Event, Future, shortuuid } from '../utils.js';\nimport { asyncLocalStorage } from './agent.js';\n\n/** Symbol used to identify SpeechHandle instances */\nconst SPEECH_HANDLE_SYMBOL = Symbol.for('livekit.agents.SpeechHandle');\n\n/**\n * Type guard to check if a value is a SpeechHandle.\n */\nexport function isSpeechHandle(value: unknown): value is SpeechHandle {\n return (\n typeof value === 'object' &&\n value !== null &&\n SPEECH_HANDLE_SYMBOL in value &&\n (value as Record<symbol, boolean>)[SPEECH_HANDLE_SYMBOL] === true\n );\n}\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 private generations: Future<void>[] = [];\n private _chatItems: ChatItem[] = [];\n\n /** @internal */\n _tasks: Task<void>[] = [];\n\n /** @internal */\n _numSteps = 1;\n\n private itemAddedCallbacks: Set<(item: ChatItem) => void> = new Set();\n private doneCallbacks: Set<(sh: SpeechHandle) => void> = new Set();\n\n /** @internal Symbol marker for type identification */\n readonly [SPEECH_HANDLE_SYMBOL] = true;\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 await this.doneFut.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 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;AAAA;AAKA,mBAAyC;AACzC,mBAAkC;AAGlC,MAAM,uBAAuB,OAAO,IAAI,6BAA6B;AA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;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA,EAGA,sBAAsB,UAA0C;AAC9D,SAAK,mBAAmB,IAAI,QAAQ;AAAA,EACtC;AAAA;AAAA,EAGA,yBAAyB,UAA0C;AACjE,SAAK,mBAAmB,OAAO,QAAQ;AAAA,EACzC;AAAA;AAAA,EAGA,WAAW,OAAyB;AAClC,eAAW,QAAQ,OAAO;AACxB,iBAAW,MAAM,KAAK,oBAAoB;AACxC,WAAG,IAAI;AAAA,MACT;AACA,WAAK,WAAW,KAAK,IAAI;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ChatItem } from '../llm/index.js';
|
|
2
2
|
import type { Task } from '../utils.js';
|
|
3
|
+
/** Symbol used to identify SpeechHandle instances */
|
|
4
|
+
declare const SPEECH_HANDLE_SYMBOL: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if a value is a SpeechHandle.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isSpeechHandle(value: unknown): value is SpeechHandle;
|
|
3
9
|
export declare class SpeechHandle {
|
|
4
10
|
private _id;
|
|
5
11
|
private _allowInterruptions;
|
|
@@ -17,12 +23,15 @@ export declare class SpeechHandle {
|
|
|
17
23
|
private scheduledFut;
|
|
18
24
|
private doneFut;
|
|
19
25
|
private generations;
|
|
26
|
+
private _chatItems;
|
|
20
27
|
/** @internal */
|
|
21
28
|
_tasks: Task<void>[];
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
/** @internal */
|
|
30
|
+
_numSteps: number;
|
|
24
31
|
private itemAddedCallbacks;
|
|
25
32
|
private doneCallbacks;
|
|
33
|
+
/** @internal Symbol marker for type identification */
|
|
34
|
+
readonly [SPEECH_HANDLE_SYMBOL] = true;
|
|
26
35
|
constructor(_id: string, _allowInterruptions: boolean,
|
|
27
36
|
/** @internal */
|
|
28
37
|
_stepIndex: number, parent?: SpeechHandle | undefined);
|
|
@@ -94,4 +103,5 @@ export declare class SpeechHandle {
|
|
|
94
103
|
/** @internal */
|
|
95
104
|
_itemAdded(items: ChatItem[]): void;
|
|
96
105
|
}
|
|
106
|
+
export {};
|
|
97
107
|
//# sourceMappingURL=speech_handle.d.ts.map
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ChatItem } from '../llm/index.js';
|
|
2
2
|
import type { Task } from '../utils.js';
|
|
3
|
+
/** Symbol used to identify SpeechHandle instances */
|
|
4
|
+
declare const SPEECH_HANDLE_SYMBOL: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if a value is a SpeechHandle.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isSpeechHandle(value: unknown): value is SpeechHandle;
|
|
3
9
|
export declare class SpeechHandle {
|
|
4
10
|
private _id;
|
|
5
11
|
private _allowInterruptions;
|
|
@@ -17,12 +23,15 @@ export declare class SpeechHandle {
|
|
|
17
23
|
private scheduledFut;
|
|
18
24
|
private doneFut;
|
|
19
25
|
private generations;
|
|
26
|
+
private _chatItems;
|
|
20
27
|
/** @internal */
|
|
21
28
|
_tasks: Task<void>[];
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
/** @internal */
|
|
30
|
+
_numSteps: number;
|
|
24
31
|
private itemAddedCallbacks;
|
|
25
32
|
private doneCallbacks;
|
|
33
|
+
/** @internal Symbol marker for type identification */
|
|
34
|
+
readonly [SPEECH_HANDLE_SYMBOL] = true;
|
|
26
35
|
constructor(_id: string, _allowInterruptions: boolean,
|
|
27
36
|
/** @internal */
|
|
28
37
|
_stepIndex: number, parent?: SpeechHandle | undefined);
|
|
@@ -94,4 +103,5 @@ export declare class SpeechHandle {
|
|
|
94
103
|
/** @internal */
|
|
95
104
|
_itemAdded(items: ChatItem[]): void;
|
|
96
105
|
}
|
|
106
|
+
export {};
|
|
97
107
|
//# 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,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"speech_handle.d.ts","sourceRoot":"","sources":["../../src/voice/speech_handle.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAIxC,qDAAqD;AACrD,QAAA,MAAM,oBAAoB,eAA4C,CAAC;AAEvE;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAOpE;AAED,qBAAa,YAAY;IA4BrB,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,mBAAmB;IAC3B,gBAAgB;IACT,UAAU,EAAE,MAAM;IACzB,QAAQ,CAAC,MAAM,CAAC;IA/BlB,wFAAwF;IACxF,MAAM,CAAC,mBAAmB,SAAK;IAC/B,0EAA0E;IAC1E,MAAM,CAAC,sBAAsB,SAAK;IAClC,2EAA2E;IAC3E,MAAM,CAAC,oBAAoB,SAAM;IAEjC,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,UAAU,CAAkB;IAEpC,gBAAgB;IAChB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAM;IAE1B,gBAAgB;IAChB,SAAS,SAAK;IAEd,OAAO,CAAC,kBAAkB,CAA4C;IACtE,OAAO,CAAC,aAAa,CAA8C;IAEnE,sDAAsD;IACtD,QAAQ,CAAC,CAAC,oBAAoB,CAAC,QAAQ;gBAG7B,GAAG,EAAE,MAAM,EACX,mBAAmB,EAAE,OAAO;IACpC,gBAAgB;IACT,UAAU,EAAE,MAAM,E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AI;IAW3B,gBAAgB;IAChB,SAAS,IAAI,IAAI;IASjB,gBAAgB;IAChB,cAAc,IAAI,IAAI;IAMtB,gBAAgB;IAChB,qBAAqB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAAG,IAAI;IAI/D,gBAAgB;IAChB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAAG,IAAI;IAIlE,gBAAgB;IAChB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI;CAQpC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Event, Future, shortuuid } from "../utils.js";
|
|
2
2
|
import { asyncLocalStorage } from "./agent.js";
|
|
3
|
+
const SPEECH_HANDLE_SYMBOL = Symbol.for("livekit.agents.SpeechHandle");
|
|
4
|
+
function isSpeechHandle(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && SPEECH_HANDLE_SYMBOL in value && value[SPEECH_HANDLE_SYMBOL] === true;
|
|
6
|
+
}
|
|
3
7
|
class SpeechHandle {
|
|
4
8
|
constructor(_id, _allowInterruptions, _stepIndex, parent) {
|
|
5
9
|
this._id = _id;
|
|
@@ -23,12 +27,15 @@ class SpeechHandle {
|
|
|
23
27
|
scheduledFut = new Future();
|
|
24
28
|
doneFut = new Future();
|
|
25
29
|
generations = [];
|
|
30
|
+
_chatItems = [];
|
|
26
31
|
/** @internal */
|
|
27
32
|
_tasks = [];
|
|
28
|
-
|
|
33
|
+
/** @internal */
|
|
29
34
|
_numSteps = 1;
|
|
30
35
|
itemAddedCallbacks = /* @__PURE__ */ new Set();
|
|
31
36
|
doneCallbacks = /* @__PURE__ */ new Set();
|
|
37
|
+
/** @internal Symbol marker for type identification */
|
|
38
|
+
[SPEECH_HANDLE_SYMBOL] = true;
|
|
32
39
|
static create(options) {
|
|
33
40
|
const { allowInterruptions = true, stepIndex = 0, parent } = options ?? {};
|
|
34
41
|
return new SpeechHandle(shortuuid("speech_"), allowInterruptions, stepIndex, parent);
|
|
@@ -199,6 +206,7 @@ To wait for the assistant's spoken response prior to running this tool, use RunC
|
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
208
|
export {
|
|
202
|
-
SpeechHandle
|
|
209
|
+
SpeechHandle,
|
|
210
|
+
isSpeechHandle
|
|
203
211
|
};
|
|
204
212
|
//# sourceMappingURL=speech_handle.js.map
|
|
@@ -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 { 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 await this.doneFut.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 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":"AAIA,SAAS,OAAO,QAAQ,iBAAiB;AAEzC,SAAS,yBAAyB;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,iBAAS,IAAI;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA,EAhCA,OAAO,sBAAsB;AAAA;AAAA,EAE7B,OAAO,yBAAyB;AAAA;AAAA,EAEhC,OAAO,uBAAuB;AAAA,EAEtB,eAAe,IAAI,OAAa;AAAA,EAChC,kBAAkB,IAAI,MAAM;AAAA,EAC5B,eAAe,IAAI,OAAa;AAAA,EAChC,UAAU,IAAI,OAAa;AAAA,EAE3B,cAA8B,CAAC;AAAA;AAAA,EAEvC,SAAuB,CAAC;AAAA,EAChB,aAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EAEZ,qBAAoD,oBAAI,IAAI;AAAA,EAC5D,gBAAiD,oBAAI,IAAI;AAAA,EAgBjE,OAAO,OAAO,SAIX;AACD,UAAM,EAAE,qBAAqB,MAAM,YAAY,GAAG,OAAO,IAAI,WAAW,CAAC;AAEzE,WAAO,IAAI,aAAa,UAAU,SAAS,GAAG,oBAAoB,WAAW,MAAM;AAAA,EACrF;AAAA,EAEA,IAAI,cAAuB;AACzB,WAAO,KAAK,aAAa;AAAA,EAC3B;AAAA,EAEA,IAAI,WAAmB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,KAAa;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAqB;AACvB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EACF;AAAA;AAAA,EAGA,iBAAuB;AACrB,QAAI,CAAC,KAAK,aAAa,MAAM;AAC3B,WAAK,aAAa,QAAQ;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA,EAGA,sBAAsB,UAA0C;AAC9D,SAAK,mBAAmB,IAAI,QAAQ;AAAA,EACtC;AAAA;AAAA,EAGA,yBAAyB,UAA0C;AACjE,SAAK,mBAAmB,OAAO,QAAQ;AAAA,EACzC;AAAA;AAAA,EAGA,WAAW,OAAyB;AAClC,eAAW,QAAQ,OAAO;AACxB,iBAAW,MAAM,KAAK,oBAAoB;AACxC,WAAG,IAAI;AAAA,MACT;AACA,WAAK,WAAW,KAAK,IAAI;AAAA,IAC3B;AAAA,EACF;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 type { Task } from '../utils.js';\nimport { Event, Future, shortuuid } from '../utils.js';\nimport { asyncLocalStorage } from './agent.js';\n\n/** Symbol used to identify SpeechHandle instances */\nconst SPEECH_HANDLE_SYMBOL = Symbol.for('livekit.agents.SpeechHandle');\n\n/**\n * Type guard to check if a value is a SpeechHandle.\n */\nexport function isSpeechHandle(value: unknown): value is SpeechHandle {\n return (\n typeof value === 'object' &&\n value !== null &&\n SPEECH_HANDLE_SYMBOL in value &&\n (value as Record<symbol, boolean>)[SPEECH_HANDLE_SYMBOL] === true\n );\n}\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 private generations: Future<void>[] = [];\n private _chatItems: ChatItem[] = [];\n\n /** @internal */\n _tasks: Task<void>[] = [];\n\n /** @internal */\n _numSteps = 1;\n\n private itemAddedCallbacks: Set<(item: ChatItem) => void> = new Set();\n private doneCallbacks: Set<(sh: SpeechHandle) => void> = new Set();\n\n /** @internal Symbol marker for type identification */\n readonly [SPEECH_HANDLE_SYMBOL] = true;\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 await this.doneFut.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 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":"AAKA,SAAS,OAAO,QAAQ,iBAAiB;AACzC,SAAS,yBAAyB;AAGlC,MAAM,uBAAuB,OAAO,IAAI,6BAA6B;AAK9D,SAAS,eAAe,OAAuC;AACpE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,wBAAwB,SACvB,MAAkC,oBAAoB,MAAM;AAEjE;AAEO,MAAM,aAAa;AAAA,EA2BxB,YACU,KACA,qBAED,YACE,QACT;AALQ;AACA;AAED;AACE;AAET,SAAK,QAAQ,MAAM,QAAQ,MAAM;AAC/B,iBAAW,YAAY,KAAK,eAAe;AACzC,iBAAS,IAAI;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA,EArCA,OAAO,sBAAsB;AAAA;AAAA,EAE7B,OAAO,yBAAyB;AAAA;AAAA,EAEhC,OAAO,uBAAuB;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
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var testing_exports = {};
|
|
20
|
+
__export(testing_exports, {
|
|
21
|
+
AgentHandoffAssert: () => import_run_result.AgentHandoffAssert,
|
|
22
|
+
AssertionError: () => import_run_result.AssertionError,
|
|
23
|
+
EventAssert: () => import_run_result.EventAssert,
|
|
24
|
+
FunctionCallAssert: () => import_run_result.FunctionCallAssert,
|
|
25
|
+
FunctionCallOutputAssert: () => import_run_result.FunctionCallOutputAssert,
|
|
26
|
+
MessageAssert: () => import_run_result.MessageAssert,
|
|
27
|
+
RunAssert: () => import_run_result.RunAssert,
|
|
28
|
+
RunResult: () => import_run_result.RunResult,
|
|
29
|
+
isAgentHandoffEvent: () => import_types.isAgentHandoffEvent,
|
|
30
|
+
isChatMessageEvent: () => import_types.isChatMessageEvent,
|
|
31
|
+
isFunctionCallEvent: () => import_types.isFunctionCallEvent,
|
|
32
|
+
isFunctionCallOutputEvent: () => import_types.isFunctionCallOutputEvent
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(testing_exports);
|
|
35
|
+
var import_run_result = require("./run_result.cjs");
|
|
36
|
+
var import_types = require("./types.cjs");
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
AgentHandoffAssert,
|
|
40
|
+
AssertionError,
|
|
41
|
+
EventAssert,
|
|
42
|
+
FunctionCallAssert,
|
|
43
|
+
FunctionCallOutputAssert,
|
|
44
|
+
MessageAssert,
|
|
45
|
+
RunAssert,
|
|
46
|
+
RunResult,
|
|
47
|
+
isAgentHandoffEvent,
|
|
48
|
+
isChatMessageEvent,
|
|
49
|
+
isFunctionCallEvent,
|
|
50
|
+
isFunctionCallOutputEvent
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/voice/testing/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Testing utilities for agent evaluation.\n *\n * @example\n * ```typescript\n * import { AgentSession, Agent, voice } from '@livekit/agents';\n *\n * const session = new AgentSession({ llm });\n * await session.start(agent);\n *\n * const result = await session.run({ userInput: 'Hello' });\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.noMoreEvents();\n * ```\n *\n * @packageDocumentation\n */\n\nexport {\n AgentHandoffAssert,\n AssertionError,\n EventAssert,\n FunctionCallAssert,\n FunctionCallOutputAssert,\n MessageAssert,\n RunAssert,\n RunResult,\n} from './run_result.js';\n\nexport {\n isAgentHandoffEvent,\n isChatMessageEvent,\n isFunctionCallEvent,\n isFunctionCallOutputEvent,\n type AgentHandoffAssertOptions,\n type AgentHandoffEvent,\n type ChatMessageEvent,\n type EventType,\n type FunctionCallAssertOptions,\n type FunctionCallEvent,\n type FunctionCallOutputAssertOptions,\n type FunctionCallOutputEvent,\n type MessageAssertOptions,\n type RunEvent,\n} from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,wBASO;AAEP,mBAeO;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utilities for agent evaluation.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { AgentSession, Agent, voice } from '@livekit/agents';
|
|
7
|
+
*
|
|
8
|
+
* const session = new AgentSession({ llm });
|
|
9
|
+
* await session.start(agent);
|
|
10
|
+
*
|
|
11
|
+
* const result = await session.run({ userInput: 'Hello' });
|
|
12
|
+
* result.expect.nextEvent().isMessage({ role: 'assistant' });
|
|
13
|
+
* result.expect.noMoreEvents();
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export { AgentHandoffAssert, AssertionError, EventAssert, FunctionCallAssert, FunctionCallOutputAssert, MessageAssert, RunAssert, RunResult, } from './run_result.js';
|
|
19
|
+
export { isAgentHandoffEvent, isChatMessageEvent, isFunctionCallEvent, isFunctionCallOutputEvent, type AgentHandoffAssertOptions, type AgentHandoffEvent, type ChatMessageEvent, type EventType, type FunctionCallAssertOptions, type FunctionCallEvent, type FunctionCallOutputAssertOptions, type FunctionCallOutputEvent, type MessageAssertOptions, type RunEvent, } from './types.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing utilities for agent evaluation.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { AgentSession, Agent, voice } from '@livekit/agents';
|
|
7
|
+
*
|
|
8
|
+
* const session = new AgentSession({ llm });
|
|
9
|
+
* await session.start(agent);
|
|
10
|
+
*
|
|
11
|
+
* const result = await session.run({ userInput: 'Hello' });
|
|
12
|
+
* result.expect.nextEvent().isMessage({ role: 'assistant' });
|
|
13
|
+
* result.expect.noMoreEvents();
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export { AgentHandoffAssert, AssertionError, EventAssert, FunctionCallAssert, FunctionCallOutputAssert, MessageAssert, RunAssert, RunResult, } from './run_result.js';
|
|
19
|
+
export { isAgentHandoffEvent, isChatMessageEvent, isFunctionCallEvent, isFunctionCallOutputEvent, type AgentHandoffAssertOptions, type AgentHandoffEvent, type ChatMessageEvent, type EventType, type FunctionCallAssertOptions, type FunctionCallEvent, type FunctionCallOutputAssertOptions, type FunctionCallOutputEvent, type MessageAssertOptions, type RunEvent, } from './types.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/voice/testing/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,SAAS,EACT,SAAS,GACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,+BAA+B,EACpC,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentHandoffAssert,
|
|
3
|
+
AssertionError,
|
|
4
|
+
EventAssert,
|
|
5
|
+
FunctionCallAssert,
|
|
6
|
+
FunctionCallOutputAssert,
|
|
7
|
+
MessageAssert,
|
|
8
|
+
RunAssert,
|
|
9
|
+
RunResult
|
|
10
|
+
} from "./run_result.js";
|
|
11
|
+
import {
|
|
12
|
+
isAgentHandoffEvent,
|
|
13
|
+
isChatMessageEvent,
|
|
14
|
+
isFunctionCallEvent,
|
|
15
|
+
isFunctionCallOutputEvent
|
|
16
|
+
} from "./types.js";
|
|
17
|
+
export {
|
|
18
|
+
AgentHandoffAssert,
|
|
19
|
+
AssertionError,
|
|
20
|
+
EventAssert,
|
|
21
|
+
FunctionCallAssert,
|
|
22
|
+
FunctionCallOutputAssert,
|
|
23
|
+
MessageAssert,
|
|
24
|
+
RunAssert,
|
|
25
|
+
RunResult,
|
|
26
|
+
isAgentHandoffEvent,
|
|
27
|
+
isChatMessageEvent,
|
|
28
|
+
isFunctionCallEvent,
|
|
29
|
+
isFunctionCallOutputEvent
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/voice/testing/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Testing utilities for agent evaluation.\n *\n * @example\n * ```typescript\n * import { AgentSession, Agent, voice } from '@livekit/agents';\n *\n * const session = new AgentSession({ llm });\n * await session.start(agent);\n *\n * const result = await session.run({ userInput: 'Hello' });\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.noMoreEvents();\n * ```\n *\n * @packageDocumentation\n */\n\nexport {\n AgentHandoffAssert,\n AssertionError,\n EventAssert,\n FunctionCallAssert,\n FunctionCallOutputAssert,\n MessageAssert,\n RunAssert,\n RunResult,\n} from './run_result.js';\n\nexport {\n isAgentHandoffEvent,\n isChatMessageEvent,\n isFunctionCallEvent,\n isFunctionCallOutputEvent,\n type AgentHandoffAssertOptions,\n type AgentHandoffEvent,\n type ChatMessageEvent,\n type EventType,\n type FunctionCallAssertOptions,\n type FunctionCallEvent,\n type FunctionCallOutputAssertOptions,\n type FunctionCallOutputEvent,\n type MessageAssertOptions,\n type RunEvent,\n} from './types.js';\n"],"mappings":"AAsBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAWK;","names":[]}
|