agora-agents 2.2.0 → 2.3.1
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 +48 -26
- package/dist/cjs/AgoraPoolClient.d.ts +9 -6
- package/dist/cjs/AgoraPoolClient.js +1 -0
- package/dist/cjs/agentkit/Agent.d.ts +52 -51
- package/dist/cjs/agentkit/Agent.js +40 -39
- package/dist/cjs/agentkit/AgentSession.d.ts +11 -10
- package/dist/cjs/agentkit/AgentSession.js +10 -6
- package/dist/cjs/agentkit/__tests__/area-aware-vendors.test.d.ts +1 -0
- package/dist/cjs/agentkit/__tests__/area-aware-vendors.test.js +57 -0
- package/dist/cjs/agentkit/__tests__/readme-examples.test.d.ts +1 -0
- package/dist/cjs/agentkit/__tests__/readme-examples.test.js +126 -0
- package/dist/cjs/agentkit/__tests__/type-safety.test.js +24 -17
- package/dist/cjs/agentkit/area.d.ts +4 -0
- package/dist/cjs/agentkit/area.js +2 -0
- package/dist/cjs/agentkit/avatar-types.d.ts +28 -2
- package/dist/cjs/agentkit/avatar-types.js +24 -2
- package/dist/cjs/agentkit/index.d.ts +8 -5
- package/dist/cjs/agentkit/index.js +27 -2
- package/dist/cjs/agentkit/region-vendors.d.ts +15 -0
- package/dist/cjs/agentkit/region-vendors.js +2 -0
- package/dist/cjs/agentkit/token.d.ts +3 -2
- package/dist/cjs/agentkit/token.js +3 -2
- package/dist/cjs/agentkit/types.d.ts +26 -5
- package/dist/cjs/agentkit/vendors/avatar.d.ts +6 -3
- package/dist/cjs/agentkit/vendors/avatar.js +6 -3
- package/dist/cjs/agentkit/vendors/base.d.ts +38 -5
- package/dist/cjs/agentkit/vendors/base.js +60 -6
- package/dist/cjs/agentkit/vendors/cn.d.ts +251 -0
- package/dist/cjs/agentkit/vendors/cn.js +293 -0
- package/dist/cjs/agentkit/vendors/mllm.d.ts +8 -4
- package/dist/cjs/agentkit/vendors/mllm.js +8 -4
- package/dist/cjs/agentkit/vendors/stt.js +5 -0
- package/dist/cjs/agentkit/vendors/tts.d.ts +3 -3
- package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.d.ts +5 -2
- package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.js +4 -0
- package/dist/cjs/api/types/Asr.d.ts +16 -1
- package/dist/cjs/api/types/BytedanceDuplexTts.d.ts +9 -0
- package/dist/cjs/api/types/BytedanceDuplexTts.js +3 -0
- package/dist/cjs/api/types/BytedanceDuplexTtsParams.d.ts +13 -0
- package/dist/cjs/api/types/BytedanceDuplexTtsParams.js +3 -0
- package/dist/cjs/api/types/BytedanceTts.d.ts +9 -0
- package/dist/cjs/api/types/BytedanceTts.js +3 -0
- package/dist/cjs/api/types/BytedanceTtsParams.d.ts +23 -0
- package/dist/cjs/api/types/BytedanceTtsParams.js +3 -0
- package/dist/cjs/api/types/CosyvoiceTts.d.ts +9 -0
- package/dist/cjs/api/types/CosyvoiceTts.js +3 -0
- package/dist/cjs/api/types/CosyvoiceTtsParams.d.ts +15 -0
- package/dist/cjs/api/types/CosyvoiceTtsParams.js +3 -0
- package/dist/cjs/api/types/FengmingAsr.d.ts +11 -0
- package/dist/cjs/api/types/FengmingAsr.js +3 -0
- package/dist/cjs/api/types/MinimaxTtsParams.d.ts +52 -3
- package/dist/cjs/api/types/OpenAiTtsParams.d.ts +1 -1
- package/dist/cjs/api/types/SensetimeAvatarParams.d.ts +48 -0
- package/dist/cjs/api/types/SensetimeAvatarParams.js +3 -0
- package/dist/cjs/api/types/StepfunTts.d.ts +9 -0
- package/dist/cjs/api/types/StepfunTts.js +3 -0
- package/dist/cjs/api/types/StepfunTtsParams.d.ts +13 -0
- package/dist/cjs/api/types/StepfunTtsParams.js +3 -0
- package/dist/cjs/api/types/TencentAsr.d.ts +10 -0
- package/dist/cjs/api/types/TencentAsr.js +3 -0
- package/dist/cjs/api/types/TencentAsrParams.d.ts +17 -0
- package/dist/cjs/api/types/TencentAsrParams.js +3 -0
- package/dist/cjs/api/types/TencentTts.d.ts +9 -0
- package/dist/cjs/api/types/TencentTts.js +3 -0
- package/dist/cjs/api/types/TencentTtsParams.d.ts +23 -0
- package/dist/cjs/api/types/TencentTtsParams.js +3 -0
- package/dist/cjs/api/types/Tts.d.ts +16 -1
- package/dist/cjs/api/types/XfyunAsr.d.ts +10 -0
- package/dist/cjs/api/types/XfyunAsr.js +3 -0
- package/dist/cjs/api/types/XfyunAsrParams.d.ts +15 -0
- package/dist/cjs/api/types/XfyunAsrParams.js +3 -0
- package/dist/cjs/api/types/XfyunBigmodelAsr.d.ts +10 -0
- package/dist/cjs/api/types/XfyunBigmodelAsr.js +3 -0
- package/dist/cjs/api/types/XfyunBigmodelAsrParams.d.ts +17 -0
- package/dist/cjs/api/types/XfyunBigmodelAsrParams.js +3 -0
- package/dist/cjs/api/types/XfyunDialectAsr.d.ts +10 -0
- package/dist/cjs/api/types/XfyunDialectAsr.js +3 -0
- package/dist/cjs/api/types/XfyunDialectAsrParams.d.ts +15 -0
- package/dist/cjs/api/types/XfyunDialectAsrParams.js +3 -0
- package/dist/cjs/api/types/index.d.ts +20 -0
- package/dist/cjs/api/types/index.js +20 -0
- package/dist/cjs/core/domain/index.d.ts +2 -1
- package/dist/cjs/core/domain/index.js +5 -3
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.js +26 -2
- package/dist/esm/AgoraPoolClient.d.mts +9 -6
- package/dist/esm/AgoraPoolClient.mjs +1 -0
- package/dist/esm/agentkit/Agent.d.mts +52 -51
- package/dist/esm/agentkit/Agent.mjs +40 -39
- package/dist/esm/agentkit/AgentSession.d.mts +11 -10
- package/dist/esm/agentkit/AgentSession.mjs +11 -7
- package/dist/esm/agentkit/__tests__/area-aware-vendors.test.d.mts +1 -0
- package/dist/esm/agentkit/__tests__/area-aware-vendors.test.mjs +55 -0
- package/dist/esm/agentkit/__tests__/readme-examples.test.d.mts +1 -0
- package/dist/esm/agentkit/__tests__/readme-examples.test.mjs +124 -0
- package/dist/esm/agentkit/__tests__/type-safety.test.mjs +24 -17
- package/dist/esm/agentkit/area.d.mts +4 -0
- package/dist/esm/agentkit/area.mjs +1 -0
- package/dist/esm/agentkit/avatar-types.d.mts +28 -2
- package/dist/esm/agentkit/avatar-types.mjs +23 -2
- package/dist/esm/agentkit/index.d.mts +8 -5
- package/dist/esm/agentkit/index.mjs +3 -2
- package/dist/esm/agentkit/region-vendors.d.mts +15 -0
- package/dist/esm/agentkit/region-vendors.mjs +1 -0
- package/dist/esm/agentkit/token.d.mts +3 -2
- package/dist/esm/agentkit/token.mjs +3 -2
- package/dist/esm/agentkit/types.d.mts +26 -5
- package/dist/esm/agentkit/vendors/avatar.d.mts +6 -3
- package/dist/esm/agentkit/vendors/avatar.mjs +6 -3
- package/dist/esm/agentkit/vendors/base.d.mts +38 -5
- package/dist/esm/agentkit/vendors/base.mjs +55 -5
- package/dist/esm/agentkit/vendors/cn.d.mts +251 -0
- package/dist/esm/agentkit/vendors/cn.mjs +272 -0
- package/dist/esm/agentkit/vendors/mllm.d.mts +8 -4
- package/dist/esm/agentkit/vendors/mllm.mjs +8 -4
- package/dist/esm/agentkit/vendors/stt.mjs +5 -0
- package/dist/esm/agentkit/vendors/tts.d.mts +3 -3
- package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.d.mts +5 -2
- package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.mjs +4 -0
- package/dist/esm/api/types/Asr.d.mts +16 -1
- package/dist/esm/api/types/BytedanceDuplexTts.d.mts +9 -0
- package/dist/esm/api/types/BytedanceDuplexTts.mjs +2 -0
- package/dist/esm/api/types/BytedanceDuplexTtsParams.d.mts +13 -0
- package/dist/esm/api/types/BytedanceDuplexTtsParams.mjs +2 -0
- package/dist/esm/api/types/BytedanceTts.d.mts +9 -0
- package/dist/esm/api/types/BytedanceTts.mjs +2 -0
- package/dist/esm/api/types/BytedanceTtsParams.d.mts +23 -0
- package/dist/esm/api/types/BytedanceTtsParams.mjs +2 -0
- package/dist/esm/api/types/CosyvoiceTts.d.mts +9 -0
- package/dist/esm/api/types/CosyvoiceTts.mjs +2 -0
- package/dist/esm/api/types/CosyvoiceTtsParams.d.mts +15 -0
- package/dist/esm/api/types/CosyvoiceTtsParams.mjs +2 -0
- package/dist/esm/api/types/FengmingAsr.d.mts +11 -0
- package/dist/esm/api/types/FengmingAsr.mjs +2 -0
- package/dist/esm/api/types/MinimaxTtsParams.d.mts +52 -3
- package/dist/esm/api/types/OpenAiTtsParams.d.mts +1 -1
- package/dist/esm/api/types/SensetimeAvatarParams.d.mts +48 -0
- package/dist/esm/api/types/SensetimeAvatarParams.mjs +2 -0
- package/dist/esm/api/types/StepfunTts.d.mts +9 -0
- package/dist/esm/api/types/StepfunTts.mjs +2 -0
- package/dist/esm/api/types/StepfunTtsParams.d.mts +13 -0
- package/dist/esm/api/types/StepfunTtsParams.mjs +2 -0
- package/dist/esm/api/types/TencentAsr.d.mts +10 -0
- package/dist/esm/api/types/TencentAsr.mjs +2 -0
- package/dist/esm/api/types/TencentAsrParams.d.mts +17 -0
- package/dist/esm/api/types/TencentAsrParams.mjs +2 -0
- package/dist/esm/api/types/TencentTts.d.mts +9 -0
- package/dist/esm/api/types/TencentTts.mjs +2 -0
- package/dist/esm/api/types/TencentTtsParams.d.mts +23 -0
- package/dist/esm/api/types/TencentTtsParams.mjs +2 -0
- package/dist/esm/api/types/Tts.d.mts +16 -1
- package/dist/esm/api/types/XfyunAsr.d.mts +10 -0
- package/dist/esm/api/types/XfyunAsr.mjs +2 -0
- package/dist/esm/api/types/XfyunAsrParams.d.mts +15 -0
- package/dist/esm/api/types/XfyunAsrParams.mjs +2 -0
- package/dist/esm/api/types/XfyunBigmodelAsr.d.mts +10 -0
- package/dist/esm/api/types/XfyunBigmodelAsr.mjs +2 -0
- package/dist/esm/api/types/XfyunBigmodelAsrParams.d.mts +17 -0
- package/dist/esm/api/types/XfyunBigmodelAsrParams.mjs +2 -0
- package/dist/esm/api/types/XfyunDialectAsr.d.mts +10 -0
- package/dist/esm/api/types/XfyunDialectAsr.mjs +2 -0
- package/dist/esm/api/types/XfyunDialectAsrParams.d.mts +15 -0
- package/dist/esm/api/types/XfyunDialectAsrParams.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +20 -0
- package/dist/esm/api/types/index.mjs +20 -0
- package/dist/esm/core/domain/index.d.mts +2 -1
- package/dist/esm/core/domain/index.mjs +4 -2
- package/dist/esm/index.d.mts +3 -2
- package/dist/esm/index.mjs +6 -6
- package/package.json +1 -1
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Agent class - A reusable agent definition.
|
|
3
3
|
*
|
|
4
4
|
* This class represents an agent configuration that can be used to create
|
|
5
|
-
* multiple sessions.
|
|
5
|
+
* multiple sessions. Set the unique agent instance `name` in
|
|
6
|
+
* {@link Agent.createSession}, not on the Agent itself.
|
|
6
7
|
*/
|
|
7
8
|
import { AgentSession } from "./AgentSession.mjs";
|
|
9
|
+
import { AudioScenario } from "./constants.mjs";
|
|
8
10
|
import { generateConvoAIToken } from "./token.mjs";
|
|
9
11
|
const DEFAULT_TURN_DETECTION_LANGUAGE = "en-US";
|
|
10
12
|
const INTERACTION_LANGUAGES = new Set([
|
|
@@ -59,15 +61,22 @@ function assertTurnDetectionLanguage(value) {
|
|
|
59
61
|
* import { Agent, OpenAI, MicrosoftTTS, DeepgramSTT } from 'agora-agents';
|
|
60
62
|
*
|
|
61
63
|
* // Use the fluent builder pattern to configure vendors
|
|
62
|
-
* const agent = new Agent({ instructions: 'You are helpful.' })
|
|
64
|
+
* const agent = new Agent({ client, instructions: 'You are helpful.' })
|
|
63
65
|
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
64
66
|
* .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
65
67
|
* .withStt(new DeepgramSTT({ apiKey: '...', model: 'nova-2' }));
|
|
68
|
+
*
|
|
69
|
+
* const session = agent.createSession({
|
|
70
|
+
* name: `conversation-${Date.now()}`,
|
|
71
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
72
|
+
* agentUid: '1',
|
|
73
|
+
* remoteUids: ['100'],
|
|
74
|
+
* });
|
|
66
75
|
* ```
|
|
67
76
|
*/
|
|
68
77
|
export class Agent {
|
|
69
|
-
constructor(options
|
|
70
|
-
this.
|
|
78
|
+
constructor(options) {
|
|
79
|
+
this._client = options.client;
|
|
71
80
|
this._pipelineId = options.pipelineId;
|
|
72
81
|
this._instructions = options.instructions;
|
|
73
82
|
this._greeting = options.greeting;
|
|
@@ -202,7 +211,8 @@ export class Agent {
|
|
|
202
211
|
* ```typescript
|
|
203
212
|
* import { HeyGenAvatar, ElevenLabsTTS } from 'agora-agents';
|
|
204
213
|
*
|
|
205
|
-
* const
|
|
214
|
+
* const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
|
|
215
|
+
* const agent = new Agent({ client })
|
|
206
216
|
* .withTts(new ElevenLabsTTS({
|
|
207
217
|
* key: '...',
|
|
208
218
|
* modelId: '...',
|
|
@@ -273,14 +283,6 @@ export class Agent {
|
|
|
273
283
|
newAgent._greetingConfigs = configs;
|
|
274
284
|
return newAgent;
|
|
275
285
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Returns a new Agent with the specified name.
|
|
278
|
-
*/
|
|
279
|
-
withName(name) {
|
|
280
|
-
const newAgent = this._clone();
|
|
281
|
-
newAgent._name = name;
|
|
282
|
-
return newAgent;
|
|
283
|
-
}
|
|
284
286
|
/**
|
|
285
287
|
* Returns a new Agent with the specified SAL (Selective Attention Locking) configuration.
|
|
286
288
|
*/
|
|
@@ -386,12 +388,6 @@ export class Agent {
|
|
|
386
388
|
newAgent._fillerWords = fillerWords;
|
|
387
389
|
return newAgent;
|
|
388
390
|
}
|
|
389
|
-
/**
|
|
390
|
-
* Get the agent name.
|
|
391
|
-
*/
|
|
392
|
-
get name() {
|
|
393
|
-
return this._name;
|
|
394
|
-
}
|
|
395
391
|
/**
|
|
396
392
|
* Get the AI Studio pipeline ID used as this agent's base configuration.
|
|
397
393
|
*/
|
|
@@ -519,7 +515,7 @@ export class Agent {
|
|
|
519
515
|
*/
|
|
520
516
|
get config() {
|
|
521
517
|
return {
|
|
522
|
-
|
|
518
|
+
client: this._client,
|
|
523
519
|
pipelineId: this._pipelineId,
|
|
524
520
|
instructions: this._instructions,
|
|
525
521
|
turnDetection: this._turnDetection,
|
|
@@ -545,18 +541,19 @@ export class Agent {
|
|
|
545
541
|
/**
|
|
546
542
|
* Creates a new session from this agent configuration.
|
|
547
543
|
*
|
|
548
|
-
* @param client - The Agora client instance (must have appId and appCertificate properties)
|
|
549
544
|
* @param options - Session connection options
|
|
550
545
|
* @returns A new AgentSession instance ready to start
|
|
551
546
|
*
|
|
552
547
|
* @example
|
|
553
548
|
* ```typescript
|
|
554
|
-
* const
|
|
555
|
-
*
|
|
556
|
-
* .
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
549
|
+
* const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
|
|
550
|
+
* const agent = new Agent({ client })
|
|
551
|
+
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
552
|
+
* .withTts(new MiniMaxTTS({ model: 'speech_2_6_turbo', voiceId: 'English_captivating_female1' }));
|
|
553
|
+
*
|
|
554
|
+
* const session = agent.createSession({
|
|
555
|
+
* name: `conversation-${Date.now()}`,
|
|
556
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
560
557
|
* agentUid: '1',
|
|
561
558
|
* remoteUids: ['100'],
|
|
562
559
|
* idleTimeout: 120,
|
|
@@ -565,10 +562,10 @@ export class Agent {
|
|
|
565
562
|
* const agentId = await session.start();
|
|
566
563
|
* ```
|
|
567
564
|
*/
|
|
568
|
-
createSession(
|
|
569
|
-
var _a
|
|
570
|
-
const name = (
|
|
571
|
-
return new AgentSession(Object.assign(Object.assign({ client, agent: this, appId:
|
|
565
|
+
createSession(options) {
|
|
566
|
+
var _a;
|
|
567
|
+
const name = (_a = options.name) !== null && _a !== void 0 ? _a : `agent-${Date.now()}`;
|
|
568
|
+
return new AgentSession(Object.assign(Object.assign({ client: this._client, agent: this, appId: this._client.appId, appCertificate: this._client.appCertificate }, options), { name }));
|
|
572
569
|
}
|
|
573
570
|
/**
|
|
574
571
|
* Converts the Agent configuration to the Fern request properties format.
|
|
@@ -578,7 +575,7 @@ export class Agent {
|
|
|
578
575
|
* and RTM privileges (required for RTM-enabled sessions).
|
|
579
576
|
*/
|
|
580
577
|
toProperties(opts) {
|
|
581
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
578
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
582
579
|
// In MLLM mode the backend handles audio end-to-end; LLM, TTS, and ASR
|
|
583
580
|
// are not required.
|
|
584
581
|
const isMllmMode = ((_a = this._mllm) === null || _a === void 0 ? void 0 : _a.enable) === true || this._mllm !== undefined;
|
|
@@ -611,8 +608,13 @@ export class Agent {
|
|
|
611
608
|
// When RTM is enabled, data_channel must also be 'rtm' for the client
|
|
612
609
|
// to receive transcripts and state events. Default it automatically so
|
|
613
610
|
// callers only need to set advancedFeatures.enable_rtm: true.
|
|
614
|
-
|
|
615
|
-
|
|
611
|
+
let resolvedParameters = this._parameters;
|
|
612
|
+
if (((_b = this._advancedFeatures) === null || _b === void 0 ? void 0 : _b.enable_rtm) && !(resolvedParameters === null || resolvedParameters === void 0 ? void 0 : resolvedParameters.data_channel)) {
|
|
613
|
+
resolvedParameters = Object.assign(Object.assign({}, resolvedParameters), { data_channel: "rtm" });
|
|
614
|
+
}
|
|
615
|
+
if ((resolvedParameters === null || resolvedParameters === void 0 ? void 0 : resolvedParameters.audio_scenario) === undefined) {
|
|
616
|
+
resolvedParameters = Object.assign(Object.assign({}, resolvedParameters), { audio_scenario: AudioScenario.Default });
|
|
617
|
+
}
|
|
616
618
|
const base = {
|
|
617
619
|
channel: opts.channel,
|
|
618
620
|
token,
|
|
@@ -646,8 +648,8 @@ export class Agent {
|
|
|
646
648
|
}
|
|
647
649
|
return Object.assign(Object.assign({}, base), { mllm: mllmConfig, turn_detection: this._turnDetection });
|
|
648
650
|
}
|
|
649
|
-
const skipCategories = new Set((
|
|
650
|
-
const allowMissingCategories = new Set((
|
|
651
|
+
const skipCategories = new Set((_c = opts.skipVendorValidationCategories) !== null && _c !== void 0 ? _c : []);
|
|
652
|
+
const allowMissingCategories = new Set((_d = opts.allowMissingVendorCategories) !== null && _d !== void 0 ? _d : []);
|
|
651
653
|
if (opts.skipVendorValidation) {
|
|
652
654
|
for (const category of ["asr", "llm", "tts"]) {
|
|
653
655
|
skipCategories.add(category);
|
|
@@ -670,7 +672,7 @@ export class Agent {
|
|
|
670
672
|
? this._llm.system_messages
|
|
671
673
|
: this._instructions
|
|
672
674
|
? [{ role: "system", content: this._instructions }]
|
|
673
|
-
: undefined, greeting_message: (
|
|
675
|
+
: undefined, greeting_message: (_e = this._llm.greeting_message) !== null && _e !== void 0 ? _e : this._greeting, greeting_configs: (_f = this._llm.greeting_configs) !== null && _f !== void 0 ? _f : this._greetingConfigs, failure_message: (_g = this._llm.failure_message) !== null && _g !== void 0 ? _g : this._failureMessage, max_history: (_h = this._llm.max_history) !== null && _h !== void 0 ? _h : this._maxHistory }) : undefined;
|
|
674
676
|
const turnDetectionConfig = this._resolveTurnDetectionConfig();
|
|
675
677
|
const asrConfig = this._stt !== undefined || !allowMissingAsr
|
|
676
678
|
? this._resolveAsrConfig(turnDetectionConfig)
|
|
@@ -688,8 +690,7 @@ export class Agent {
|
|
|
688
690
|
* If a new private field is added to Agent, it MUST also be added here.
|
|
689
691
|
*/
|
|
690
692
|
_clone() {
|
|
691
|
-
const newAgent = new Agent();
|
|
692
|
-
newAgent._name = this._name;
|
|
693
|
+
const newAgent = new Agent({ client: this._client });
|
|
693
694
|
newAgent._pipelineId = this._pipelineId;
|
|
694
695
|
newAgent._llm = this._llm;
|
|
695
696
|
newAgent._tts = this._tts;
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* This class provides a high-level interface for managing agent sessions,
|
|
5
5
|
* including starting, stopping, and interacting with the agent.
|
|
6
6
|
*/
|
|
7
|
+
import type { AgoraClient } from "../AgoraPoolClient.mjs";
|
|
7
8
|
import type { AgentManagementClient } from "../api/resources/agentManagement/client/Client.mjs";
|
|
8
9
|
import type { AgentsClient } from "../api/resources/agents/client/Client.mjs";
|
|
9
|
-
import type { AgoraClient } from "../Client.mjs";
|
|
10
10
|
import type { Agent } from "./Agent.mjs";
|
|
11
|
+
import type { AgoraArea } from "./area.mjs";
|
|
11
12
|
import { type PresetInput } from "./presets.mjs";
|
|
12
13
|
import type { AgentConfigUpdate, ConversationHistory, ConversationTurns, GetTurnsOptions, SayOptions, SessionInfo, ThinkOptions, ThinkResponse } from "./types.mjs";
|
|
13
14
|
/**
|
|
@@ -23,14 +24,14 @@ export type AgentSessionEventHandler<T = unknown> = (data: T) => void;
|
|
|
23
24
|
*/
|
|
24
25
|
export interface AgentSessionOptions {
|
|
25
26
|
/** The Agora client instance */
|
|
26
|
-
client: AgoraClient
|
|
27
|
+
client: AgoraClient<AgoraArea>;
|
|
27
28
|
/** The agent configuration */
|
|
28
|
-
agent: Agent
|
|
29
|
+
agent: Agent<number, AgoraArea>;
|
|
29
30
|
/** The App ID */
|
|
30
31
|
appId: string;
|
|
31
32
|
/** The App Certificate — enables automatic RTC token generation when starting sessions */
|
|
32
33
|
appCertificate?: string;
|
|
33
|
-
/** Unique name
|
|
34
|
+
/** Unique agent instance name (set via {@link Agent.createSession}) */
|
|
34
35
|
name: string;
|
|
35
36
|
/** The channel to join */
|
|
36
37
|
channel: string;
|
|
@@ -73,18 +74,18 @@ export interface AgentSessionOptions {
|
|
|
73
74
|
*
|
|
74
75
|
* const client = new AgoraClient({
|
|
75
76
|
* area: Area.US,
|
|
76
|
-
|
|
77
77
|
* appId: '...',
|
|
78
78
|
* appCertificate: '...',
|
|
79
79
|
* });
|
|
80
80
|
*
|
|
81
|
-
* const agent = new Agent({
|
|
81
|
+
* const agent = new Agent({ client, instructions: 'You are a helpful voice assistant.' })
|
|
82
82
|
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
83
83
|
* .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
84
84
|
* .withStt(new DeepgramSTT({ apiKey: '...', language: 'en-US' }));
|
|
85
85
|
*
|
|
86
|
-
* const session = agent.createSession(
|
|
87
|
-
*
|
|
86
|
+
* const session = agent.createSession({
|
|
87
|
+
* name: `conversation-${Date.now()}`,
|
|
88
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
88
89
|
* agentUid: '1',
|
|
89
90
|
* remoteUids: ['100'],
|
|
90
91
|
* });
|
|
@@ -137,7 +138,7 @@ export declare class AgentSession {
|
|
|
137
138
|
/**
|
|
138
139
|
* The agent configuration.
|
|
139
140
|
*/
|
|
140
|
-
get agent(): Agent
|
|
141
|
+
get agent(): Agent<number, AgoraArea>;
|
|
141
142
|
/**
|
|
142
143
|
* The App ID for this session.
|
|
143
144
|
*/
|
|
@@ -184,7 +185,7 @@ export declare class AgentSession {
|
|
|
184
185
|
* Fills session-derived avatar fields and generates avatar ConvoAI tokens.
|
|
185
186
|
*
|
|
186
187
|
* Token management is gated to vendors that publish a separate RTC video
|
|
187
|
-
* identity (HeyGen, LiveAvatar, Generic). Other vendors (Akool, Anam) do
|
|
188
|
+
* identity (HeyGen, LiveAvatar, Generic, SenseTime). Other vendors (Akool, Anam) do
|
|
188
189
|
* not run a separate publisher and never receive an auto-generated token.
|
|
189
190
|
*/
|
|
190
191
|
private _enrichAvatarParams;
|
|
@@ -14,7 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
import { AgoraError } from "../errors/index.mjs";
|
|
17
|
-
import { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
|
|
17
|
+
import { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, isSensetimeAvatar, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
|
|
18
18
|
import { getPresetCategory, inferAsrPreset, inferLlmPreset, inferTtsPreset, normalizePresetInput, resolveSessionPresets, } from "./presets.mjs";
|
|
19
19
|
import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs";
|
|
20
20
|
/**
|
|
@@ -28,18 +28,18 @@ import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs"
|
|
|
28
28
|
*
|
|
29
29
|
* const client = new AgoraClient({
|
|
30
30
|
* area: Area.US,
|
|
31
|
-
|
|
32
31
|
* appId: '...',
|
|
33
32
|
* appCertificate: '...',
|
|
34
33
|
* });
|
|
35
34
|
*
|
|
36
|
-
* const agent = new Agent({
|
|
35
|
+
* const agent = new Agent({ client, instructions: 'You are a helpful voice assistant.' })
|
|
37
36
|
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
38
37
|
* .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
39
38
|
* .withStt(new DeepgramSTT({ apiKey: '...', language: 'en-US' }));
|
|
40
39
|
*
|
|
41
|
-
* const session = agent.createSession(
|
|
42
|
-
*
|
|
40
|
+
* const session = agent.createSession({
|
|
41
|
+
* name: `conversation-${Date.now()}`,
|
|
42
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
43
43
|
* agentUid: '1',
|
|
44
44
|
* remoteUids: ['100'],
|
|
45
45
|
* });
|
|
@@ -191,6 +191,7 @@ export class AgentSession {
|
|
|
191
191
|
// are filled by `_enrichAvatarParams()` and validated separately.
|
|
192
192
|
if (isHeyGenAvatar(strictAvatar) ||
|
|
193
193
|
isLiveAvatarAvatar(strictAvatar) ||
|
|
194
|
+
isSensetimeAvatar(strictAvatar) ||
|
|
194
195
|
isAkoolAvatar(strictAvatar) ||
|
|
195
196
|
isAnamAvatar(strictAvatar) ||
|
|
196
197
|
isGenericAvatar(strictAvatar)) {
|
|
@@ -226,7 +227,7 @@ export class AgentSession {
|
|
|
226
227
|
* Fills session-derived avatar fields and generates avatar ConvoAI tokens.
|
|
227
228
|
*
|
|
228
229
|
* Token management is gated to vendors that publish a separate RTC video
|
|
229
|
-
* identity (HeyGen, LiveAvatar, Generic). Other vendors (Akool, Anam) do
|
|
230
|
+
* identity (HeyGen, LiveAvatar, Generic, SenseTime). Other vendors (Akool, Anam) do
|
|
230
231
|
* not run a separate publisher and never receive an auto-generated token.
|
|
231
232
|
*/
|
|
232
233
|
_enrichAvatarParams(properties, expirySeconds) {
|
|
@@ -277,10 +278,13 @@ export class AgentSession {
|
|
|
277
278
|
const strictAvatar = avatar;
|
|
278
279
|
if (isHeyGenAvatar(strictAvatar) ||
|
|
279
280
|
isLiveAvatarAvatar(strictAvatar) ||
|
|
281
|
+
isSensetimeAvatar(strictAvatar) ||
|
|
280
282
|
isAkoolAvatar(strictAvatar) ||
|
|
281
283
|
isAnamAvatar(strictAvatar) ||
|
|
282
284
|
isGenericAvatar(strictAvatar)) {
|
|
283
|
-
validateAvatarConfig(strictAvatar, {
|
|
285
|
+
validateAvatarConfig(strictAvatar, {
|
|
286
|
+
requireSessionFields: isGenericAvatar(strictAvatar),
|
|
287
|
+
});
|
|
284
288
|
}
|
|
285
289
|
if (!isAvatarTokenManaged(strictAvatar)) {
|
|
286
290
|
return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AgoraClient } from "../../AgoraPoolClient.mjs";
|
|
2
|
+
import { Area } from "../../core/domain/index.mjs";
|
|
3
|
+
import { Agent } from "../Agent.mjs";
|
|
4
|
+
import { AliyunLLM, FengmingSTT, MiniMaxCNTTS } from "../vendors/cn.mjs";
|
|
5
|
+
import { OpenAI } from "../vendors/llm.mjs";
|
|
6
|
+
import { DeepgramSTT } from "../vendors/stt.mjs";
|
|
7
|
+
import { MiniMaxTTS } from "../vendors/tts.mjs";
|
|
8
|
+
const client = new AgoraClient({
|
|
9
|
+
area: Area.US,
|
|
10
|
+
appId: "app-id",
|
|
11
|
+
appCertificate: "app-certificate",
|
|
12
|
+
});
|
|
13
|
+
new Agent({ client, turnDetection: { language: "en-US" } })
|
|
14
|
+
.withStt(new DeepgramSTT({ model: "nova-3", language: "en-US" }))
|
|
15
|
+
.withLlm(new OpenAI({ model: "gpt-5-mini" }))
|
|
16
|
+
.withTts(new MiniMaxTTS({ model: "speech-2.6-turbo", voiceId: "English_captivating_female1" }))
|
|
17
|
+
.createSession({
|
|
18
|
+
name: "assistant",
|
|
19
|
+
channel: "test-room",
|
|
20
|
+
agentUid: "1",
|
|
21
|
+
remoteUids: ["100"],
|
|
22
|
+
});
|
|
23
|
+
// Area and provider may differ.
|
|
24
|
+
new Agent({ client }).withStt(new FengmingSTT());
|
|
25
|
+
new Agent({ client }).withLlm(new AliyunLLM({ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", model: "qwen-plus" }));
|
|
26
|
+
new Agent({ client }).withTts(new MiniMaxCNTTS({ key: "minimax-key", model: "speech-01-turbo", voiceSetting: { voice_id: "female-shaonv" } }));
|
|
27
|
+
{
|
|
28
|
+
const client = new AgoraClient({
|
|
29
|
+
area: Area.CN,
|
|
30
|
+
appId: "app-id",
|
|
31
|
+
appCertificate: "app-certificate",
|
|
32
|
+
});
|
|
33
|
+
new Agent({ client, turnDetection: { language: "zh-CN" } })
|
|
34
|
+
.withStt(new FengmingSTT())
|
|
35
|
+
.withLlm(new AliyunLLM({
|
|
36
|
+
url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
|
|
37
|
+
model: "qwen-plus",
|
|
38
|
+
}))
|
|
39
|
+
.withTts(new MiniMaxCNTTS({
|
|
40
|
+
key: "minimax-key",
|
|
41
|
+
model: "speech-01-turbo",
|
|
42
|
+
voiceSetting: { voice_id: "female-shaonv" },
|
|
43
|
+
audioSetting: { sample_rate: 16000 },
|
|
44
|
+
}))
|
|
45
|
+
.createSession({
|
|
46
|
+
name: "assistant",
|
|
47
|
+
channel: "cn-room",
|
|
48
|
+
agentUid: "1",
|
|
49
|
+
remoteUids: ["100"],
|
|
50
|
+
});
|
|
51
|
+
new Agent({ client }).withStt(new DeepgramSTT({ model: "nova-3", language: "en-US" }));
|
|
52
|
+
new Agent({ client }).withLlm(new OpenAI({ model: "gpt-5-mini" }));
|
|
53
|
+
new Agent({ client }).withTts(new MiniMaxTTS({ model: "speech-2.6-turbo", voiceId: "English_captivating_female1" }));
|
|
54
|
+
}
|
|
55
|
+
new Agent({ client }).withStt(new DeepgramSTT({ model: "nova-3", language: "en-US" }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { AgoraClient } from "../../AgoraPoolClient.mjs";
|
|
2
|
+
import { Area } from "../../core/domain/index.mjs";
|
|
3
|
+
import { Agent } from "../Agent.mjs";
|
|
4
|
+
import { AliyunLLM, FengmingSTT, MiniMaxCNTTS } from "../vendors/cn.mjs";
|
|
5
|
+
import { OpenAI } from "../vendors/llm.mjs";
|
|
6
|
+
import { DeepgramSTT } from "../vendors/stt.mjs";
|
|
7
|
+
import { MiniMaxTTS } from "../vendors/tts.mjs";
|
|
8
|
+
const AGENT_PROMPT = "You are a concise, technically credible voice assistant. Keep replies short unless the user asks for detail.";
|
|
9
|
+
const GREETING = "Hi there! I am your Agora voice assistant. How can I help?";
|
|
10
|
+
const SUPPORT_PROMPT = "You are a concise support assistant.";
|
|
11
|
+
const client = new AgoraClient({
|
|
12
|
+
area: Area.US,
|
|
13
|
+
appId: "app-id",
|
|
14
|
+
appCertificate: "app-certificate",
|
|
15
|
+
});
|
|
16
|
+
new Agent({
|
|
17
|
+
client,
|
|
18
|
+
turnDetection: {
|
|
19
|
+
language: "en-US",
|
|
20
|
+
config: {
|
|
21
|
+
speech_threshold: 0.5,
|
|
22
|
+
start_of_speech: {
|
|
23
|
+
mode: "vad",
|
|
24
|
+
vad_config: {
|
|
25
|
+
interrupt_duration_ms: 160,
|
|
26
|
+
prefix_padding_ms: 300,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
end_of_speech: {
|
|
30
|
+
mode: "vad",
|
|
31
|
+
vad_config: {
|
|
32
|
+
silence_duration_ms: 480,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
advancedFeatures: {
|
|
38
|
+
enable_rtm: true,
|
|
39
|
+
enable_tools: true,
|
|
40
|
+
},
|
|
41
|
+
parameters: {
|
|
42
|
+
data_channel: "rtm",
|
|
43
|
+
enable_error_message: true,
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
.withStt(new DeepgramSTT({ model: "nova-3", language: "en" }))
|
|
47
|
+
.withLlm(new OpenAI({
|
|
48
|
+
model: "gpt-4o-mini",
|
|
49
|
+
systemMessages: [{ role: "system", content: AGENT_PROMPT }],
|
|
50
|
+
greetingMessage: GREETING,
|
|
51
|
+
failureMessage: "Please wait a moment.",
|
|
52
|
+
maxHistory: 50,
|
|
53
|
+
params: {
|
|
54
|
+
max_tokens: 1024,
|
|
55
|
+
temperature: 0.7,
|
|
56
|
+
top_p: 0.95,
|
|
57
|
+
},
|
|
58
|
+
}))
|
|
59
|
+
.withTts(new MiniMaxTTS({
|
|
60
|
+
model: "speech_2_6_turbo",
|
|
61
|
+
voiceId: "English_captivating_female1",
|
|
62
|
+
}))
|
|
63
|
+
.createSession({
|
|
64
|
+
name: `conversation-${Date.now()}`,
|
|
65
|
+
channel: `demo-channel-${Date.now()}`,
|
|
66
|
+
agentUid: "123456",
|
|
67
|
+
remoteUids: ["*"],
|
|
68
|
+
idleTimeout: 30,
|
|
69
|
+
});
|
|
70
|
+
{
|
|
71
|
+
const client = new AgoraClient({
|
|
72
|
+
area: Area.CN,
|
|
73
|
+
appId: "app-id",
|
|
74
|
+
appCertificate: "app-certificate",
|
|
75
|
+
});
|
|
76
|
+
new Agent({
|
|
77
|
+
client,
|
|
78
|
+
turnDetection: { language: "zh-CN" },
|
|
79
|
+
})
|
|
80
|
+
.withStt(new FengmingSTT())
|
|
81
|
+
.withLlm(new AliyunLLM({
|
|
82
|
+
url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
|
|
83
|
+
model: "qwen-plus",
|
|
84
|
+
}))
|
|
85
|
+
.withTts(new MiniMaxCNTTS({
|
|
86
|
+
key: "minimax-key",
|
|
87
|
+
model: "speech-01-turbo",
|
|
88
|
+
voiceSetting: { voice_id: "female-shaonv" },
|
|
89
|
+
audioSetting: { sample_rate: 16000 },
|
|
90
|
+
}))
|
|
91
|
+
.createSession({
|
|
92
|
+
name: `conversation-${Date.now()}`,
|
|
93
|
+
channel: `demo-channel-${Date.now()}`,
|
|
94
|
+
agentUid: "1001",
|
|
95
|
+
remoteUids: ["100"],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
{
|
|
99
|
+
const client = new AgoraClient({
|
|
100
|
+
area: Area.US,
|
|
101
|
+
appId: "app-id",
|
|
102
|
+
appCertificate: "app-certificate",
|
|
103
|
+
});
|
|
104
|
+
new Agent({ client, turnDetection: { language: "en-US" } })
|
|
105
|
+
.withStt(new DeepgramSTT({
|
|
106
|
+
apiKey: "deepgram-key",
|
|
107
|
+
model: "nova-3",
|
|
108
|
+
language: "en",
|
|
109
|
+
}))
|
|
110
|
+
.withLlm(new OpenAI({
|
|
111
|
+
apiKey: "openai-key",
|
|
112
|
+
url: "https://api.openai.com/v1/chat/completions",
|
|
113
|
+
model: "gpt-4o-mini",
|
|
114
|
+
systemMessages: [{ role: "system", content: SUPPORT_PROMPT }],
|
|
115
|
+
greetingMessage: GREETING,
|
|
116
|
+
maxTokens: 1024,
|
|
117
|
+
temperature: 0.7,
|
|
118
|
+
topP: 0.95,
|
|
119
|
+
}))
|
|
120
|
+
.withTts(new MiniMaxTTS({
|
|
121
|
+
model: "speech_2_6_turbo",
|
|
122
|
+
voiceId: "English_captivating_female1",
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
@@ -11,17 +11,24 @@
|
|
|
11
11
|
* 2. Run: npm run build
|
|
12
12
|
* 3. TypeScript should show errors for the uncommented invalid sections
|
|
13
13
|
*/
|
|
14
|
+
import { AgoraClient } from "../../AgoraPoolClient.mjs";
|
|
15
|
+
import { Area } from "../../core/domain/index.mjs";
|
|
14
16
|
import { Agent } from "../Agent.mjs";
|
|
15
17
|
import { AkoolAvatar, LiveAvatarAvatar } from "../vendors/avatar.mjs";
|
|
16
18
|
import { OpenAI } from "../vendors/llm.mjs";
|
|
17
19
|
import { DeepgramSTT } from "../vendors/stt.mjs";
|
|
18
20
|
import { CartesiaTTS, ElevenLabsTTS, MicrosoftTTS, MiniMaxTTS, OpenAITTS } from "../vendors/tts.mjs";
|
|
21
|
+
const TEST_AGENT_CLIENT = new AgoraClient({
|
|
22
|
+
area: Area.US,
|
|
23
|
+
appId: "test-app-id",
|
|
24
|
+
appCertificate: "test-app-certificate",
|
|
25
|
+
});
|
|
19
26
|
// ============================================
|
|
20
27
|
// ✅ VALID CONFIGURATIONS
|
|
21
28
|
// ============================================
|
|
22
29
|
// Example 1: ElevenLabs 24kHz + HeyGen avatar
|
|
23
30
|
function _validExample1() {
|
|
24
|
-
return new Agent({ instructions: "Test" })
|
|
31
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
25
32
|
.withTts(new ElevenLabsTTS({
|
|
26
33
|
key: "test",
|
|
27
34
|
modelId: "eleven_flash_v2_5",
|
|
@@ -37,7 +44,7 @@ function _validExample1() {
|
|
|
37
44
|
}
|
|
38
45
|
// Example 2: ElevenLabs 16kHz + Akool avatar
|
|
39
46
|
function _validExample2() {
|
|
40
|
-
return new Agent({ instructions: "Test" })
|
|
47
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
41
48
|
.withTts(new ElevenLabsTTS({
|
|
42
49
|
key: "test",
|
|
43
50
|
modelId: "eleven_flash_v2_5",
|
|
@@ -51,7 +58,7 @@ function _validExample2() {
|
|
|
51
58
|
}
|
|
52
59
|
// Example 3: Microsoft 24kHz + HeyGen avatar
|
|
53
60
|
function _validExample3() {
|
|
54
|
-
return new Agent({ instructions: "Test" })
|
|
61
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
55
62
|
.withTts(new MicrosoftTTS({
|
|
56
63
|
key: "test",
|
|
57
64
|
region: "eastus",
|
|
@@ -66,7 +73,7 @@ function _validExample3() {
|
|
|
66
73
|
}
|
|
67
74
|
// Example 4: OpenAI (fixed 24kHz) + HeyGen avatar
|
|
68
75
|
function _validExample4() {
|
|
69
|
-
return new Agent({ instructions: "Test" })
|
|
76
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
70
77
|
.withTts(new OpenAITTS({
|
|
71
78
|
apiKey: "test",
|
|
72
79
|
voice: "alloy",
|
|
@@ -81,7 +88,7 @@ function _validExample4() {
|
|
|
81
88
|
}
|
|
82
89
|
// Example 5: Cartesia 16kHz + Akool avatar
|
|
83
90
|
function _validExample5() {
|
|
84
|
-
return new Agent({ instructions: "Test" })
|
|
91
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
85
92
|
.withTts(new CartesiaTTS({
|
|
86
93
|
apiKey: "test",
|
|
87
94
|
voiceId: "test",
|
|
@@ -129,7 +136,7 @@ new MiniMaxTTS({
|
|
|
129
136
|
/*
|
|
130
137
|
// @ts-expect-error - HeyGen requires 24kHz, but TTS is configured for 16kHz
|
|
131
138
|
function invalidMismatch1(): Agent<24000> {
|
|
132
|
-
return new Agent({ instructions: "Test" })
|
|
139
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
133
140
|
.withTts(
|
|
134
141
|
new ElevenLabsTTS({
|
|
135
142
|
key: "test",
|
|
@@ -151,7 +158,7 @@ function invalidMismatch1(): Agent<24000> {
|
|
|
151
158
|
/*
|
|
152
159
|
// @ts-expect-error - Akool requires 16kHz, but TTS is configured for 24kHz
|
|
153
160
|
function invalidMismatch2(): Agent<16000> {
|
|
154
|
-
return new Agent({ instructions: "Test" })
|
|
161
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
155
162
|
.withTts(
|
|
156
163
|
new ElevenLabsTTS({
|
|
157
164
|
key: "test",
|
|
@@ -171,7 +178,7 @@ function invalidMismatch2(): Agent<16000> {
|
|
|
171
178
|
/*
|
|
172
179
|
// @ts-expect-error - HeyGen requires 24kHz, not 48kHz
|
|
173
180
|
function invalidMismatch3(): Agent<24000> {
|
|
174
|
-
return new Agent({ instructions: "Test" })
|
|
181
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
175
182
|
.withTts(
|
|
176
183
|
new MicrosoftTTS({
|
|
177
184
|
key: "test",
|
|
@@ -196,7 +203,7 @@ function invalidMismatch3(): Agent<24000> {
|
|
|
196
203
|
/*
|
|
197
204
|
// @ts-expect-error - 25000 is not a valid ElevenLabs sample rate
|
|
198
205
|
function invalidEnum1() {
|
|
199
|
-
return new Agent({ instructions: "Test" }).withTts(
|
|
206
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(
|
|
200
207
|
new ElevenLabsTTS({
|
|
201
208
|
key: "test",
|
|
202
209
|
modelId: "eleven_flash_v2_5",
|
|
@@ -210,7 +217,7 @@ function invalidEnum1() {
|
|
|
210
217
|
/*
|
|
211
218
|
// @ts-expect-error - 8000 is not a valid Microsoft sample rate
|
|
212
219
|
function invalidEnum2() {
|
|
213
|
-
return new Agent({ instructions: "Test" }).withTts(
|
|
220
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(
|
|
214
221
|
new MicrosoftTTS({
|
|
215
222
|
key: "test",
|
|
216
223
|
region: "eastus",
|
|
@@ -223,7 +230,7 @@ function invalidEnum2() {
|
|
|
223
230
|
/*
|
|
224
231
|
// @ts-expect-error - 32000 is not a valid Cartesia sample rate
|
|
225
232
|
function invalidEnum3() {
|
|
226
|
-
return new Agent({ instructions: "Test" }).withTts(
|
|
233
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(
|
|
227
234
|
new CartesiaTTS({
|
|
228
235
|
key: "test",
|
|
229
236
|
voiceId: "test",
|
|
@@ -238,7 +245,7 @@ function invalidEnum3() {
|
|
|
238
245
|
// ============================================
|
|
239
246
|
// Avatar without TTS configured (allowed)
|
|
240
247
|
function _edgeCase1() {
|
|
241
|
-
return new Agent({ instructions: "Test" }).withAvatar(new LiveAvatarAvatar({
|
|
248
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withAvatar(new LiveAvatarAvatar({
|
|
242
249
|
apiKey: "test",
|
|
243
250
|
quality: "high",
|
|
244
251
|
agoraUid: "12345",
|
|
@@ -246,7 +253,7 @@ function _edgeCase1() {
|
|
|
246
253
|
}
|
|
247
254
|
// TTS without avatar (allowed)
|
|
248
255
|
function _edgeCase2() {
|
|
249
|
-
return new Agent({ instructions: "Test" }).withTts(new ElevenLabsTTS({
|
|
256
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new ElevenLabsTTS({
|
|
250
257
|
key: "test",
|
|
251
258
|
modelId: "eleven_flash_v2_5",
|
|
252
259
|
voiceId: "test",
|
|
@@ -256,7 +263,7 @@ function _edgeCase2() {
|
|
|
256
263
|
}
|
|
257
264
|
// Method chaining preserves type tracking
|
|
258
265
|
function _edgeCase3() {
|
|
259
|
-
return new Agent({ instructions: "Test" })
|
|
266
|
+
return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
|
|
260
267
|
.withTts(new ElevenLabsTTS({
|
|
261
268
|
key: "test",
|
|
262
269
|
modelId: "eleven_flash_v2_5",
|
|
@@ -276,7 +283,7 @@ function _edgeCase3() {
|
|
|
276
283
|
// Type inference verification
|
|
277
284
|
// ============================================
|
|
278
285
|
function _typeInference1() {
|
|
279
|
-
const agentWith24k = new Agent({ instructions: "Test" }).withTts(new ElevenLabsTTS({
|
|
286
|
+
const agentWith24k = new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new ElevenLabsTTS({
|
|
280
287
|
key: "test",
|
|
281
288
|
modelId: "eleven_flash_v2_5",
|
|
282
289
|
voiceId: "test",
|
|
@@ -288,7 +295,7 @@ function _typeInference1() {
|
|
|
288
295
|
return agentWith24k;
|
|
289
296
|
}
|
|
290
297
|
function _typeInference2() {
|
|
291
|
-
const agentWith16k = new Agent({ instructions: "Test" }).withTts(new ElevenLabsTTS({
|
|
298
|
+
const agentWith16k = new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new ElevenLabsTTS({
|
|
292
299
|
key: "test",
|
|
293
300
|
modelId: "eleven_flash_v2_5",
|
|
294
301
|
voiceId: "test",
|
|
@@ -300,7 +307,7 @@ function _typeInference2() {
|
|
|
300
307
|
return agentWith16k;
|
|
301
308
|
}
|
|
302
309
|
function _typeInference3() {
|
|
303
|
-
const openAIAgent = new Agent({ instructions: "Test" }).withTts(new OpenAITTS({
|
|
310
|
+
const openAIAgent = new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new OpenAITTS({
|
|
304
311
|
apiKey: "test",
|
|
305
312
|
voice: "alloy",
|
|
306
313
|
model: "gpt-4o-mini-tts",
|