agora-agents 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/AgoraPoolClient.js +7 -2
  3. package/dist/cjs/BaseClient.js +2 -2
  4. package/dist/cjs/Client.js +16 -8
  5. package/dist/cjs/agentkit/Agent.d.ts +7 -2
  6. package/dist/cjs/agentkit/Agent.js +33 -20
  7. package/dist/cjs/agentkit/AgentSession.d.ts +2 -0
  8. package/dist/cjs/agentkit/AgentSession.js +33 -4
  9. package/dist/cjs/agentkit/presets.d.ts +30 -0
  10. package/dist/cjs/agentkit/presets.js +20 -6
  11. package/dist/cjs/agentkit/types.d.ts +3 -1
  12. package/dist/cjs/agentkit/vendors/avatar.d.ts +3 -1
  13. package/dist/cjs/agentkit/vendors/llm.d.ts +4 -2
  14. package/dist/cjs/agentkit/vendors/llm.js +10 -5
  15. package/dist/cjs/agentkit/vendors/stt.d.ts +4 -6
  16. package/dist/cjs/agentkit/vendors/stt.js +44 -63
  17. package/dist/cjs/agentkit/vendors/tts.js +1 -1
  18. package/dist/cjs/api/types/DeepgramAsr.d.ts +0 -2
  19. package/dist/cjs/api/types/DeepgramAsrParams.d.ts +1 -1
  20. package/dist/cjs/api/types/OpenAiTtsParams.d.ts +1 -1
  21. package/dist/cjs/core/base64.js +5 -1
  22. package/dist/cjs/version.d.ts +1 -1
  23. package/dist/cjs/version.js +1 -1
  24. package/dist/esm/AgoraPoolClient.mjs +7 -2
  25. package/dist/esm/BaseClient.mjs +2 -2
  26. package/dist/esm/Client.mjs +16 -8
  27. package/dist/esm/agentkit/Agent.d.mts +7 -2
  28. package/dist/esm/agentkit/Agent.mjs +33 -20
  29. package/dist/esm/agentkit/AgentSession.d.mts +2 -0
  30. package/dist/esm/agentkit/AgentSession.mjs +34 -5
  31. package/dist/esm/agentkit/presets.d.mts +30 -0
  32. package/dist/esm/agentkit/presets.mjs +20 -10
  33. package/dist/esm/agentkit/types.d.mts +3 -1
  34. package/dist/esm/agentkit/vendors/avatar.d.mts +3 -1
  35. package/dist/esm/agentkit/vendors/llm.d.mts +4 -2
  36. package/dist/esm/agentkit/vendors/llm.mjs +10 -5
  37. package/dist/esm/agentkit/vendors/stt.d.mts +4 -6
  38. package/dist/esm/agentkit/vendors/stt.mjs +44 -63
  39. package/dist/esm/agentkit/vendors/tts.mjs +1 -1
  40. package/dist/esm/api/types/DeepgramAsr.d.mts +0 -2
  41. package/dist/esm/api/types/DeepgramAsrParams.d.mts +1 -1
  42. package/dist/esm/api/types/OpenAiTtsParams.d.mts +1 -1
  43. package/dist/esm/core/base64.mjs +5 -1
  44. package/dist/esm/version.d.mts +1 -1
  45. package/dist/esm/version.mjs +1 -1
  46. package/package.json +2 -1
@@ -6,45 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SarvamSTT = exports.AresSTT = exports.AssemblyAISTT = exports.AmazonSTT = exports.GoogleSTT = exports.OpenAISTT = exports.MicrosoftSTT = exports.DeepgramSTT = exports.SpeechmaticsSTT = void 0;
7
7
  const presets_js_1 = require("../presets.js");
8
8
  const base_js_1 = require("./base.js");
9
- const INTERACTION_LANGUAGES = new Set([
10
- "ar-EG",
11
- "ar-JO",
12
- "ar-SA",
13
- "ar-AE",
14
- "bn-IN",
15
- "zh-CN",
16
- "zh-HK",
17
- "zh-TW",
18
- "nl-NL",
19
- "en-IN",
20
- "en-US",
21
- "fil-PH",
22
- "fr-FR",
23
- "de-DE",
24
- "gu-IN",
25
- "he-IL",
26
- "hi-IN",
27
- "id-ID",
28
- "it-IT",
29
- "ja-JP",
30
- "kn-IN",
31
- "ko-KR",
32
- "ms-MY",
33
- "fa-IR",
34
- "pt-PT",
35
- "ru-RU",
36
- "es-ES",
37
- "ta-IN",
38
- "te-IN",
39
- "th-TH",
40
- "tr-TR",
41
- "vi-VN",
42
- ]);
43
- function toTurnDetectionLanguage(language) {
44
- return language !== undefined && INTERACTION_LANGUAGES.has(language)
45
- ? language
46
- : undefined;
47
- }
48
9
  function isDeepgramManagedModel(model) {
49
10
  return model !== undefined && presets_js_1.DeepgramPresetModels.includes(model.trim().toLowerCase());
50
11
  }
@@ -66,8 +27,10 @@ class SpeechmaticsSTT extends base_js_1.BaseSTT {
66
27
  }
67
28
  toConfig() {
68
29
  const { apiKey, language, model, uri, additionalParams } = this.options;
69
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
70
- return Object.assign(Object.assign({ vendor: "speechmatics" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), { api_key: apiKey, language }), (model !== undefined && { model })), (uri !== undefined && { uri })) });
30
+ return {
31
+ vendor: "speechmatics",
32
+ params: Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), { api_key: apiKey, language }), (model !== undefined && { model })), (uri !== undefined && { uri })),
33
+ };
71
34
  }
72
35
  }
73
36
  exports.SpeechmaticsSTT = SpeechmaticsSTT;
@@ -92,9 +55,11 @@ class DeepgramSTT extends base_js_1.BaseSTT {
92
55
  this.options = options !== null && options !== void 0 ? options : {};
93
56
  }
94
57
  toConfig() {
95
- const { apiKey, model, language, smartFormat, punctuation, additionalParams } = this.options;
96
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
97
- return Object.assign(Object.assign({ vendor: "deepgram" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), (apiKey && { key: apiKey })), (model && { model })), (language && { language })), (smartFormat !== undefined && { smart_format: smartFormat })), (punctuation !== undefined && { punctuation })) });
58
+ const { apiKey, model, language, smartFormat, punctuation, keyterm, additionalParams } = this.options;
59
+ return {
60
+ vendor: "deepgram",
61
+ params: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), (apiKey && { key: apiKey })), (model && { model })), (language && { language })), (smartFormat !== undefined && { smart_format: smartFormat })), (punctuation !== undefined && { punctuation })), (keyterm && { keyterm })),
62
+ };
98
63
  }
99
64
  }
100
65
  exports.DeepgramSTT = DeepgramSTT;
@@ -117,9 +82,11 @@ class MicrosoftSTT extends base_js_1.BaseSTT {
117
82
  }
118
83
  toConfig() {
119
84
  const { key, region, language, additionalParams } = this.options;
120
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
121
- return Object.assign(Object.assign({ vendor: "microsoft" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign(Object.assign({}, additionalParams), { key,
122
- region }), (language && { language })) });
85
+ return {
86
+ vendor: "microsoft",
87
+ params: Object.assign(Object.assign(Object.assign({}, additionalParams), { key,
88
+ region }), (language && { language })),
89
+ };
123
90
  }
124
91
  }
125
92
  exports.MicrosoftSTT = MicrosoftSTT;
@@ -140,9 +107,17 @@ class OpenAISTT extends base_js_1.BaseSTT {
140
107
  }
141
108
  toConfig() {
142
109
  const { apiKey, model, language, prompt, inputAudioTranscription, additionalParams } = this.options;
143
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
144
- const transcription = Object.assign(Object.assign(Object.assign(Object.assign({ model: "whisper-1" }, inputAudioTranscription), (model && { model })), (prompt && { prompt })), (language && { language }));
145
- return Object.assign(Object.assign({ vendor: "openai" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign({}, additionalParams), { api_key: apiKey, input_audio_transcription: transcription }) });
110
+ const transcription = Object.assign(Object.assign(Object.assign(Object.assign({ model: "gpt-4o-mini-transcribe" }, inputAudioTranscription), (model && { model })), (prompt && { prompt })), (language && { language }));
111
+ if (!transcription.model)
112
+ throw new Error("OpenAISTT: inputAudioTranscription.model is required");
113
+ if (!transcription.prompt)
114
+ throw new Error("OpenAISTT: inputAudioTranscription.prompt is required");
115
+ if (!transcription.language)
116
+ throw new Error("OpenAISTT: inputAudioTranscription.language is required");
117
+ return {
118
+ vendor: "openai",
119
+ params: Object.assign(Object.assign({}, additionalParams), { api_key: apiKey, input_audio_transcription: transcription }),
120
+ };
146
121
  }
147
122
  }
148
123
  exports.OpenAISTT = OpenAISTT;
@@ -166,8 +141,10 @@ class GoogleSTT extends base_js_1.BaseSTT {
166
141
  }
167
142
  toConfig() {
168
143
  const { projectId, location, adcCredentialsString, language, model, additionalParams } = this.options;
169
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
170
- return Object.assign(Object.assign({ vendor: "google" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), { project_id: projectId, location, adc_credentials_string: adcCredentialsString }), (language && { language })), (model && { model })) });
144
+ return {
145
+ vendor: "google",
146
+ params: Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), { project_id: projectId, location, adc_credentials_string: adcCredentialsString }), (language && { language })), (model && { model })),
147
+ };
171
148
  }
172
149
  }
173
150
  exports.GoogleSTT = GoogleSTT;
@@ -191,8 +168,10 @@ class AmazonSTT extends base_js_1.BaseSTT {
191
168
  }
192
169
  toConfig() {
193
170
  const { accessKey, secretKey, region, language, additionalParams } = this.options;
194
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
195
- return Object.assign(Object.assign({ vendor: "amazon" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign(Object.assign({}, additionalParams), { access_key_id: accessKey, secret_access_key: secretKey, region }), (language && { language_code: language })) });
171
+ return {
172
+ vendor: "amazon",
173
+ params: Object.assign(Object.assign(Object.assign({}, additionalParams), { access_key_id: accessKey, secret_access_key: secretKey, region }), (language && { language_code: language })),
174
+ };
196
175
  }
197
176
  }
198
177
  exports.AmazonSTT = AmazonSTT;
@@ -214,8 +193,10 @@ class AssemblyAISTT extends base_js_1.BaseSTT {
214
193
  }
215
194
  toConfig() {
216
195
  const { apiKey, language, uri, additionalParams } = this.options;
217
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
218
- return Object.assign(Object.assign({ vendor: "assemblyai" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), { api_key: apiKey }), (language && { language })), (uri && { uri })) });
196
+ return {
197
+ vendor: "assemblyai",
198
+ params: Object.assign(Object.assign(Object.assign(Object.assign({}, additionalParams), { api_key: apiKey }), (language && { language })), (uri && { uri })),
199
+ };
219
200
  }
220
201
  }
221
202
  exports.AssemblyAISTT = AssemblyAISTT;
@@ -224,9 +205,7 @@ exports.AssemblyAISTT = AssemblyAISTT;
224
205
  *
225
206
  * @example
226
207
  * ```typescript
227
- * const stt = new AresSTT({
228
- * language: 'en-US',
229
- * });
208
+ * const stt = new AresSTT();
230
209
  * ```
231
210
  */
232
211
  class AresSTT extends base_js_1.BaseSTT {
@@ -235,8 +214,8 @@ class AresSTT extends base_js_1.BaseSTT {
235
214
  this.options = options;
236
215
  }
237
216
  toConfig() {
238
- const { language, additionalParams } = this.options;
239
- return Object.assign(Object.assign({ vendor: "ares" }, (language && { language })), (additionalParams && Object.keys(additionalParams).length > 0 && { params: additionalParams }));
217
+ const { additionalParams } = this.options;
218
+ return Object.assign({ vendor: "ares" }, (additionalParams && Object.keys(additionalParams).length > 0 && { params: additionalParams }));
240
219
  }
241
220
  }
242
221
  exports.AresSTT = AresSTT;
@@ -258,8 +237,10 @@ class SarvamSTT extends base_js_1.BaseSTT {
258
237
  }
259
238
  toConfig() {
260
239
  const { apiKey, language, model, additionalParams } = this.options;
261
- const turnDetectionLanguage = toTurnDetectionLanguage(language);
262
- return Object.assign(Object.assign({ vendor: "sarvam" }, (turnDetectionLanguage && { language: turnDetectionLanguage })), { params: Object.assign(Object.assign(Object.assign({}, additionalParams), { api_key: apiKey, language }), (model !== undefined && { model })) });
240
+ return {
241
+ vendor: "sarvam",
242
+ params: Object.assign(Object.assign(Object.assign({}, additionalParams), { api_key: apiKey, language }), (model !== undefined && { model })),
243
+ };
263
244
  }
264
245
  }
265
246
  exports.SarvamSTT = SarvamSTT;
@@ -295,7 +295,7 @@ class MiniMaxTTS extends base_js_1.BaseTTS {
295
295
  }
296
296
  toConfig() {
297
297
  const { key, groupId, model, voiceId, url, skipPatterns } = this.options;
298
- return Object.assign({ vendor: "minimax", params: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (key && { key })), (groupId && { group_id: groupId })), { model }), (voiceId && { voice_setting: { voice_id: voiceId } })), (url && { url })) }, (skipPatterns && { skip_patterns: skipPatterns }));
298
+ return Object.assign(Object.assign({ vendor: "minimax", params: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (key && { key })), (key && groupId && { group_id: groupId })), (key && { model })), (voiceId && { voice_setting: { voice_id: voiceId } })), (key && url && { url })) }, (!key && { _minimaxPresetModel: model })), (skipPatterns && { skip_patterns: skipPatterns }));
299
299
  }
300
300
  }
301
301
  exports.MiniMaxTTS = MiniMaxTTS;
@@ -5,8 +5,6 @@ import type * as Agora from "../index.js";
5
5
  export interface DeepgramAsr {
6
6
  language?: Agora.AsrLanguage;
7
7
  params: Agora.DeepgramAsrParams;
8
- /** Boost specialized terms and brands for preset-backed Deepgram usage. */
9
- keyterm?: string;
10
8
  /** Accepts any additional properties */
11
9
  [key: string]: any;
12
10
  }
@@ -10,7 +10,7 @@ export interface DeepgramAsrParams {
10
10
  model?: string | null;
11
11
  /** Language code for speech recognition */
12
12
  language?: string | null;
13
- /** Boost specialized terms and brands */
13
+ /** Boost specialized terms and brands for Deepgram. */
14
14
  keyterm?: string | null;
15
15
  /** Accepts any additional properties */
16
16
  [key: string]: any;
@@ -2,7 +2,7 @@
2
2
  * OpenAI TTS configuration parameters.
3
3
  */
4
4
  export interface OpenAiTtsParams {
5
- /** OpenAI API key. Optional for preset-backed OpenAI TTS usage. */
5
+ /** OpenAI API key. Optional for Agora-managed OpenAI TTS usage. */
6
6
  api_key?: string;
7
7
  /** Endpoint URL for the OpenAI TTS service. */
8
8
  base_url?: string;
@@ -4,7 +4,11 @@ exports.base64Encode = base64Encode;
4
4
  exports.base64Decode = base64Decode;
5
5
  function base64ToBytes(base64) {
6
6
  const binString = atob(base64);
7
- return Uint8Array.from(binString, (m) => m.codePointAt(0));
7
+ const bytes = new Uint8Array(binString.length);
8
+ for (let i = 0; i < binString.length; i++) {
9
+ bytes[i] = binString.charCodeAt(i);
10
+ }
11
+ return bytes;
8
12
  }
9
13
  function bytesToBase64(bytes) {
10
14
  const binString = String.fromCodePoint(...bytes);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "v2.1.0";
1
+ export declare const SDK_VERSION = "v2.2.0";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "v2.1.0";
4
+ exports.SDK_VERSION = "v2.2.0";
@@ -66,14 +66,19 @@ export class AgoraClient extends BaseAgoraClient {
66
66
  let authMode;
67
67
  let username;
68
68
  let password;
69
+ let authToken = "";
69
70
  const opts = options;
70
- if (opts.customerId != null) {
71
+ if (opts.customerId != null && opts.customerSecret != null) {
71
72
  authMode = "basic";
72
73
  username = opts.customerId;
73
74
  password = opts.customerSecret;
74
75
  }
76
+ else if (opts.customerId != null) {
77
+ throw new Error("customerSecret is required when customerId is provided");
78
+ }
75
79
  else if (opts.authToken != null) {
76
80
  authMode = "token";
81
+ authToken = opts.authToken;
77
82
  username = "";
78
83
  password = "";
79
84
  }
@@ -88,7 +93,7 @@ export class AgoraClient extends BaseAgoraClient {
88
93
  const authorization = authMode === "basic"
89
94
  ? `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`
90
95
  : authMode === "token"
91
- ? `agora token=${opts.authToken}`
96
+ ? `agora token=${authToken}`
92
97
  : "";
93
98
  super(Object.assign(Object.assign({}, rest), { username,
94
99
  password,
@@ -5,8 +5,8 @@ export function normalizeClientOptions(options) {
5
5
  const headers = mergeHeaders({
6
6
  "X-Fern-Language": "JavaScript",
7
7
  "X-Fern-SDK-Name": "agora-agents",
8
- "X-Fern-SDK-Version": "v2.1.0",
9
- "User-Agent": "agora-agents/v2.1.0",
8
+ "X-Fern-SDK-Version": "v2.2.0",
9
+ "User-Agent": "agora-agents/v2.2.0",
10
10
  "X-Fern-Runtime": core.RUNTIME.type,
11
11
  "X-Fern-Runtime-Version": core.RUNTIME.version,
12
12
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -9,19 +9,27 @@ export class AgoraClient {
9
9
  this._options = normalizeClientOptions(options);
10
10
  }
11
11
  get agents() {
12
- var _a;
13
- return ((_a = this._agents) !== null && _a !== void 0 ? _a : (this._agents = new AgentsClient(this._options)));
12
+ if (this._agents == null) {
13
+ this._agents = new AgentsClient(this._options);
14
+ }
15
+ return this._agents;
14
16
  }
15
17
  get agentManagement() {
16
- var _a;
17
- return ((_a = this._agentManagement) !== null && _a !== void 0 ? _a : (this._agentManagement = new AgentManagementClient(this._options)));
18
+ if (this._agentManagement == null) {
19
+ this._agentManagement = new AgentManagementClient(this._options);
20
+ }
21
+ return this._agentManagement;
18
22
  }
19
23
  get telephony() {
20
- var _a;
21
- return ((_a = this._telephony) !== null && _a !== void 0 ? _a : (this._telephony = new TelephonyClient(this._options)));
24
+ if (this._telephony == null) {
25
+ this._telephony = new TelephonyClient(this._options);
26
+ }
27
+ return this._telephony;
22
28
  }
23
29
  get phoneNumbers() {
24
- var _a;
25
- return ((_a = this._phoneNumbers) !== null && _a !== void 0 ? _a : (this._phoneNumbers = new PhoneNumbersClient(this._options)));
30
+ if (this._phoneNumbers == null) {
31
+ this._phoneNumbers = new PhoneNumbersClient(this._options);
32
+ }
33
+ return this._phoneNumbers;
26
34
  }
27
35
  }
@@ -426,10 +426,15 @@ export declare class Agent<TTSSampleRate extends number = number> {
426
426
  idleTimeout?: number;
427
427
  enableStringUid?: boolean;
428
428
  /**
429
- * Skip the LLM and TTS required-field guards. Set this when `preset` or
430
- * `pipeline_id` is in use — those fields supply the vendor config server-side.
429
+ * @deprecated Use `skipVendorValidationCategories` and
430
+ * `allowMissingVendorCategories` instead. This broad escape hatch will be
431
+ * removed in a future release.
431
432
  */
432
433
  skipVendorValidation?: boolean;
434
+ /** Skip generated request-shape validation for the listed provider categories. */
435
+ skipVendorValidationCategories?: ReadonlySet<"asr" | "llm" | "tts">;
436
+ /** Allow the listed provider categories to be omitted from properties. */
437
+ allowMissingVendorCategories?: ReadonlySet<"asr" | "llm" | "tts">;
433
438
  } & ({
434
439
  token: string;
435
440
  appId?: undefined;
@@ -46,7 +46,7 @@ function isTurnDetectionLanguage(value) {
46
46
  }
47
47
  function assertTurnDetectionLanguage(value) {
48
48
  if (!isTurnDetectionLanguage(value)) {
49
- throw new Error(`Invalid interaction language: ${value}`);
49
+ throw new Error(`Invalid turnDetection.language: ${value}`);
50
50
  }
51
51
  }
52
52
  /**
@@ -578,7 +578,7 @@ export class Agent {
578
578
  * and RTM privileges (required for RTM-enabled sessions).
579
579
  */
580
580
  toProperties(opts) {
581
- var _a, _b, _c, _d, _e, _f, _g;
581
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
582
582
  // In MLLM mode the backend handles audio end-to-end; LLM, TTS, and ASR
583
583
  // are not required.
584
584
  const isMllmMode = ((_a = this._mllm) === null || _a === void 0 ? void 0 : _a.enable) === true || this._mllm !== undefined;
@@ -646,21 +646,37 @@ export class Agent {
646
646
  }
647
647
  return Object.assign(Object.assign({}, base), { mllm: mllmConfig, turn_detection: this._turnDetection });
648
648
  }
649
- if (!opts.skipVendorValidation) {
650
- if (!this._tts) {
651
- throw new Error("TTS configuration is required. Use withTts() to set it.");
652
- }
653
- if (!this._llm) {
654
- throw new Error("LLM configuration is required. Use withLlm() to set it.");
649
+ const skipCategories = new Set((_d = opts.skipVendorValidationCategories) !== null && _d !== void 0 ? _d : []);
650
+ const allowMissingCategories = new Set((_e = opts.allowMissingVendorCategories) !== null && _e !== void 0 ? _e : []);
651
+ if (opts.skipVendorValidation) {
652
+ for (const category of ["asr", "llm", "tts"]) {
653
+ skipCategories.add(category);
654
+ allowMissingCategories.add(category);
655
655
  }
656
656
  }
657
+ const skipLlmValidation = skipCategories.has("llm");
658
+ const skipTtsValidation = skipCategories.has("tts");
659
+ const allowMissingAsr = allowMissingCategories.has("asr");
660
+ const allowMissingLlm = allowMissingCategories.has("llm");
661
+ const allowMissingTts = allowMissingCategories.has("tts");
662
+ if (!this._tts && !(skipTtsValidation || allowMissingTts)) {
663
+ throw new Error("TTS configuration is required. Use withTts() to set it.");
664
+ }
665
+ if (!this._llm && !(skipLlmValidation || allowMissingLlm)) {
666
+ throw new Error("LLM configuration is required. Use withLlm() to set it.");
667
+ }
657
668
  const llmConfig = this._llm
658
- ? Object.assign(Object.assign({}, this._llm), { system_messages: this._instructions
659
- ? [{ role: "system", content: this._instructions }]
660
- : this._llm.system_messages, greeting_message: (_d = this._greeting) !== null && _d !== void 0 ? _d : this._llm.greeting_message, greeting_configs: (_e = this._greetingConfigs) !== null && _e !== void 0 ? _e : this._llm.greeting_configs, failure_message: (_f = this._failureMessage) !== null && _f !== void 0 ? _f : this._llm.failure_message, max_history: (_g = this._maxHistory) !== null && _g !== void 0 ? _g : this._llm.max_history }) : undefined;
661
- const asrConfig = this._resolveAsrConfig();
669
+ ? Object.assign(Object.assign({}, this._llm), { system_messages: this._llm.system_messages !== undefined
670
+ ? this._llm.system_messages
671
+ : this._instructions
672
+ ? [{ role: "system", content: this._instructions }]
673
+ : undefined, greeting_message: (_f = this._llm.greeting_message) !== null && _f !== void 0 ? _f : this._greeting, greeting_configs: (_g = this._llm.greeting_configs) !== null && _g !== void 0 ? _g : this._greetingConfigs, failure_message: (_h = this._llm.failure_message) !== null && _h !== void 0 ? _h : this._failureMessage, max_history: (_j = this._llm.max_history) !== null && _j !== void 0 ? _j : this._maxHistory }) : undefined;
662
674
  const turnDetectionConfig = this._resolveTurnDetectionConfig();
663
- return Object.assign(Object.assign({}, base), { turn_detection: turnDetectionConfig, llm: llmConfig, tts: this._tts, asr: asrConfig });
675
+ const asrConfig = this._stt !== undefined || !allowMissingAsr
676
+ ? this._resolveAsrConfig(turnDetectionConfig)
677
+ : undefined;
678
+ const ttsConfig = this._tts;
679
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, base), { turn_detection: turnDetectionConfig }), (llmConfig && { llm: llmConfig })), (ttsConfig && { tts: ttsConfig })), (asrConfig && { asr: asrConfig }));
664
680
  }
665
681
  /**
666
682
  * Creates a shallow copy of this Agent, preserving the TTSSampleRate type
@@ -696,23 +712,20 @@ export class Agent {
696
712
  newAgent._greetingConfigs = this._greetingConfigs;
697
713
  return newAgent;
698
714
  }
699
- _resolveAsrConfig() {
715
+ _resolveAsrConfig(turnDetectionConfig) {
700
716
  var _a;
701
717
  const asrConfig = Object.assign({}, ((_a = this._stt) !== null && _a !== void 0 ? _a : {}));
702
718
  if (this._stt === undefined) {
703
719
  asrConfig.vendor = "ares";
704
720
  }
705
- delete asrConfig.language;
721
+ asrConfig.language = turnDetectionConfig.language;
706
722
  return Object.keys(asrConfig).length > 0 ? asrConfig : undefined;
707
723
  }
708
724
  _resolveTurnDetectionConfig() {
709
- var _a, _b;
725
+ var _a;
710
726
  const turnDetection = Object.assign({}, ((_a = this._turnDetection) !== null && _a !== void 0 ? _a : {}));
711
727
  const existingTurnDetectionLanguage = turnDetection.language;
712
- const existingAsrLanguage = (_b = this._stt) === null || _b === void 0 ? void 0 : _b.language;
713
- const language = existingTurnDetectionLanguage !== null && existingTurnDetectionLanguage !== void 0 ? existingTurnDetectionLanguage : (existingAsrLanguage !== undefined && isTurnDetectionLanguage(existingAsrLanguage)
714
- ? existingAsrLanguage
715
- : DEFAULT_TURN_DETECTION_LANGUAGE);
728
+ const language = existingTurnDetectionLanguage !== null && existingTurnDetectionLanguage !== void 0 ? existingTurnDetectionLanguage : DEFAULT_TURN_DETECTION_LANGUAGE;
716
729
  assertTurnDetectionLanguage(language);
717
730
  turnDetection.language = language;
718
731
  return turnDetection;
@@ -73,6 +73,7 @@ export interface AgentSessionOptions {
73
73
  *
74
74
  * const client = new AgoraClient({
75
75
  * area: Area.US,
76
+
76
77
  * appId: '...',
77
78
  * appCertificate: '...',
78
79
  * });
@@ -188,6 +189,7 @@ export declare class AgentSession {
188
189
  */
189
190
  private _enrichAvatarParams;
190
191
  private _validateEnrichedAvatarConfig;
192
+ private _vendorValidationCategories;
191
193
  /**
192
194
  * Start the agent session.
193
195
  *
@@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  };
16
16
  import { AgoraError } from "../errors/index.mjs";
17
17
  import { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
18
- import { resolveSessionPresets } from "./presets.mjs";
18
+ import { getPresetCategory, inferAsrPreset, inferLlmPreset, inferTtsPreset, normalizePresetInput, resolveSessionPresets, } from "./presets.mjs";
19
19
  import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs";
20
20
  /**
21
21
  * AgentSession class for managing agent lifecycle and interactions.
@@ -28,6 +28,7 @@ import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs"
28
28
  *
29
29
  * const client = new AgoraClient({
30
30
  * area: Area.US,
31
+
31
32
  * appId: '...',
32
33
  * appCertificate: '...',
33
34
  * });
@@ -292,6 +293,35 @@ export class AgentSession {
292
293
  "Pass agoraToken on the avatar vendor or provide appCertificate for automatic token generation.");
293
294
  }
294
295
  }
296
+ _vendorValidationCategories(pipelineId) {
297
+ const skipVendorValidationCategories = new Set();
298
+ const allowMissingVendorCategories = new Set();
299
+ if (pipelineId) {
300
+ allowMissingVendorCategories.add("asr");
301
+ allowMissingVendorCategories.add("llm");
302
+ allowMissingVendorCategories.add("tts");
303
+ }
304
+ const normalizedPreset = normalizePresetInput(this._preset);
305
+ if (normalizedPreset) {
306
+ for (const item of normalizedPreset.split(",")) {
307
+ const category = getPresetCategory(item);
308
+ if (category) {
309
+ skipVendorValidationCategories.add(category);
310
+ allowMissingVendorCategories.add(category);
311
+ }
312
+ }
313
+ }
314
+ if (inferAsrPreset(this._agent.stt)) {
315
+ skipVendorValidationCategories.add("asr");
316
+ }
317
+ if (inferLlmPreset(this._agent.llm)) {
318
+ skipVendorValidationCategories.add("llm");
319
+ }
320
+ if (inferTtsPreset(this._agent.tts)) {
321
+ skipVendorValidationCategories.add("tts");
322
+ }
323
+ return { skipVendorValidationCategories, allowMissingVendorCategories };
324
+ }
295
325
  /**
296
326
  * Start the agent session.
297
327
  *
@@ -328,10 +358,9 @@ export class AgentSession {
328
358
  appCertificate: this._appCertificate,
329
359
  expiresIn,
330
360
  };
331
- const properties = this._agent.toProperties(Object.assign({ channel: this._channel, agentUid: this._agentUid, remoteUids: this._remoteUids, idleTimeout: this._idleTimeout, enableStringUid: this._enableStringUid,
332
- // When a preset or pipeline_id is supplied, ASR/LLM/TTS vendor
333
- // config is optional — the backend fills it from the preset/pipeline.
334
- skipVendorValidation: !!(this._preset || pipelineId) }, tokenOpts));
361
+ const { skipVendorValidationCategories, allowMissingVendorCategories } = this._vendorValidationCategories(pipelineId);
362
+ const properties = this._agent.toProperties(Object.assign({ channel: this._channel, agentUid: this._agentUid, remoteUids: this._remoteUids, idleTimeout: this._idleTimeout, enableStringUid: this._enableStringUid, skipVendorValidationCategories,
363
+ allowMissingVendorCategories }, tokenOpts));
335
364
  const resolved = resolveSessionPresets({
336
365
  preset: this._preset,
337
366
  properties,
@@ -29,6 +29,35 @@ export type DeepgramPresetModel = (typeof DeepgramPresetModels)[number];
29
29
  export type OpenAIPresetModel = (typeof OpenAIPresetModels)[number];
30
30
  export type OpenAITtsPresetModel = (typeof OpenAITtsPresetModels)[number];
31
31
  export type MiniMaxPresetModel = (typeof MiniMaxPresetModels)[number];
32
+ export type PresetCategory = "asr" | "llm" | "tts";
33
+ type AsrInference = {
34
+ category: "asr";
35
+ preset: AsrPreset;
36
+ stripModel: boolean;
37
+ };
38
+ type LlmInference = {
39
+ category: "llm";
40
+ preset: LlmPreset;
41
+ stripModel: boolean;
42
+ stripDefaultUrl: boolean;
43
+ };
44
+ type OpenAITtsInference = {
45
+ category: "tts";
46
+ preset: typeof AgentPresets.tts.openaiTts1;
47
+ vendor: "openai";
48
+ stripModel: boolean;
49
+ };
50
+ type MiniMaxTtsInference = {
51
+ category: "tts";
52
+ preset: TtsPreset;
53
+ vendor: "minimax";
54
+ stripModel: boolean;
55
+ };
56
+ type TtsInference = OpenAITtsInference | MiniMaxTtsInference;
57
+ export declare function getPresetCategory(preset: string): PresetCategory | undefined;
58
+ export declare function inferAsrPreset(asr?: Agora.Asr): AsrInference | undefined;
59
+ export declare function inferLlmPreset(llm?: Agora.Llm): LlmInference | undefined;
60
+ export declare function inferTtsPreset(tts?: Agora.Tts): TtsInference | undefined;
32
61
  export declare function normalizePresetInput(preset?: PresetInput | readonly string[]): string | undefined;
33
62
  export declare function resolveSessionPresets(args: {
34
63
  preset?: PresetInput;
@@ -37,3 +66,4 @@ export declare function resolveSessionPresets(args: {
37
66
  preset?: string;
38
67
  properties: Agora.StartAgentsRequest.Properties;
39
68
  };
69
+ export {};
@@ -53,9 +53,12 @@ const minimaxModelToPreset = {
53
53
  speech_2_8_turbo: AgentPresets.tts.minimaxSpeech28Turbo,
54
54
  };
55
55
  function normalizeModelName(value) {
56
- return typeof value === "string" ? value.trim().toLowerCase() : undefined;
56
+ if (typeof value !== "string")
57
+ return undefined;
58
+ const normalized = value.trim().toLowerCase();
59
+ return normalized.length > 0 ? normalized : undefined;
57
60
  }
58
- function getPresetCategory(preset) {
61
+ export function getPresetCategory(preset) {
59
62
  if (Object.values(AgentPresets.asr).includes(preset))
60
63
  return "asr";
61
64
  if (Object.values(AgentPresets.llm).includes(preset))
@@ -80,9 +83,9 @@ function omitUndefinedKeys(value) {
80
83
  const next = Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
81
84
  return Object.keys(next).length > 0 ? next : undefined;
82
85
  }
83
- function inferAsrPreset(asr) {
86
+ export function inferAsrPreset(asr) {
84
87
  var _a, _b, _c;
85
- if (!asr || asr.vendor !== "deepgram" || ((_a = asr.params) === null || _a === void 0 ? void 0 : _a.api_key))
88
+ if (!asr || asr.vendor !== "deepgram" || ((_a = asr.params) === null || _a === void 0 ? void 0 : _a.key))
86
89
  return undefined;
87
90
  const preset = deepgramModelToPreset[(_c = normalizeModelName((_b = asr.params) === null || _b === void 0 ? void 0 : _b.model)) !== null && _c !== void 0 ? _c : ""];
88
91
  if (!preset)
@@ -93,7 +96,7 @@ function inferAsrPreset(asr) {
93
96
  stripModel: true,
94
97
  };
95
98
  }
96
- function inferLlmPreset(llm) {
99
+ export function inferLlmPreset(llm) {
97
100
  var _a, _b;
98
101
  if (!llm || llm.api_key)
99
102
  return undefined;
@@ -111,8 +114,8 @@ function inferLlmPreset(llm) {
111
114
  stripDefaultUrl: true,
112
115
  };
113
116
  }
114
- function inferTtsPreset(tts) {
115
- var _a, _b, _c, _d, _e, _f;
117
+ export function inferTtsPreset(tts) {
118
+ var _a, _b, _c, _d, _e, _f, _g;
116
119
  if (!tts)
117
120
  return undefined;
118
121
  if (tts.vendor === "openai") {
@@ -131,7 +134,9 @@ function inferTtsPreset(tts) {
131
134
  if (tts.vendor === "minimax") {
132
135
  if ((_d = tts.params) === null || _d === void 0 ? void 0 : _d.key)
133
136
  return undefined;
134
- const preset = minimaxModelToPreset[(_f = normalizeModelName((_e = tts.params) === null || _e === void 0 ? void 0 : _e.model)) !== null && _f !== void 0 ? _f : ""];
137
+ // Model is no longer in params for the preset path; fall back to the top-level hint.
138
+ const model = (_g = (_f = normalizeModelName((_e = tts.params) === null || _e === void 0 ? void 0 : _e.model)) !== null && _f !== void 0 ? _f : normalizeModelName(tts._minimaxPresetModel)) !== null && _g !== void 0 ? _g : "";
139
+ const preset = minimaxModelToPreset[model];
135
140
  if (!preset)
136
141
  return undefined;
137
142
  return {
@@ -163,10 +168,15 @@ function stripInferredPresetFields(properties, inferred) {
163
168
  tts = Object.assign(Object.assign({}, tts), { params: omitUndefinedKeys(Object.assign(Object.assign({}, tts.params), { api_key: undefined, model: ttsInference.stripModel ? undefined : (_c = tts.params) === null || _c === void 0 ? void 0 : _c.model })) });
164
169
  }
165
170
  else if (ttsInference.vendor === "minimax" && tts.vendor === "minimax") {
166
- tts = Object.assign(Object.assign({}, tts), { params: omitUndefinedKeys(Object.assign(Object.assign({}, tts.params), { key: undefined, group_id: undefined, url: undefined, model: ttsInference.stripModel ? undefined : (_d = tts.params) === null || _d === void 0 ? void 0 : _d.model })) });
171
+ const _e = tts, { _minimaxPresetModel: _stripped } = _e, ttsWithoutHint = __rest(_e, ["_minimaxPresetModel"]);
172
+ tts = Object.assign(Object.assign({}, ttsWithoutHint), { params: omitUndefinedKeys(Object.assign(Object.assign({}, tts.params), { key: undefined, group_id: undefined, url: undefined, model: ttsInference.stripModel ? undefined : (_d = tts.params) === null || _d === void 0 ? void 0 : _d.model })) });
167
173
  }
168
174
  }
169
- return Object.assign(Object.assign({}, properties), { asr, llm, tts });
175
+ if (tts && "_minimaxPresetModel" in tts) {
176
+ const _f = tts, { _minimaxPresetModel: _discarded } = _f, rest = __rest(_f, ["_minimaxPresetModel"]);
177
+ tts = rest;
178
+ }
179
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, properties), (asr && { asr })), (llm && { llm })), (tts && { tts }));
170
180
  }
171
181
  export function normalizePresetInput(preset) {
172
182
  const entries = parsePresetInput(preset);