agora-agents 2.1.1 → 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.
Files changed (188) hide show
  1. package/README.md +49 -27
  2. package/dist/cjs/AgoraPoolClient.d.ts +9 -6
  3. package/dist/cjs/AgoraPoolClient.js +1 -0
  4. package/dist/cjs/BaseClient.js +2 -2
  5. package/dist/cjs/agentkit/Agent.d.ts +52 -51
  6. package/dist/cjs/agentkit/Agent.js +51 -51
  7. package/dist/cjs/agentkit/AgentSession.d.ts +11 -9
  8. package/dist/cjs/agentkit/AgentSession.js +10 -5
  9. package/dist/cjs/agentkit/__tests__/area-aware-vendors.test.d.ts +1 -0
  10. package/dist/cjs/agentkit/__tests__/area-aware-vendors.test.js +57 -0
  11. package/dist/cjs/agentkit/__tests__/readme-examples.test.d.ts +1 -0
  12. package/dist/cjs/agentkit/__tests__/readme-examples.test.js +126 -0
  13. package/dist/cjs/agentkit/__tests__/type-safety.test.js +24 -17
  14. package/dist/cjs/agentkit/area.d.ts +4 -0
  15. package/dist/cjs/agentkit/area.js +2 -0
  16. package/dist/cjs/agentkit/avatar-types.d.ts +28 -2
  17. package/dist/cjs/agentkit/avatar-types.js +24 -2
  18. package/dist/cjs/agentkit/index.d.ts +8 -5
  19. package/dist/cjs/agentkit/index.js +27 -2
  20. package/dist/cjs/agentkit/presets.js +11 -4
  21. package/dist/cjs/agentkit/region-vendors.d.ts +15 -0
  22. package/dist/cjs/agentkit/region-vendors.js +2 -0
  23. package/dist/cjs/agentkit/token.d.ts +3 -2
  24. package/dist/cjs/agentkit/token.js +3 -2
  25. package/dist/cjs/agentkit/types.d.ts +29 -6
  26. package/dist/cjs/agentkit/vendors/avatar.d.ts +9 -4
  27. package/dist/cjs/agentkit/vendors/avatar.js +6 -3
  28. package/dist/cjs/agentkit/vendors/base.d.ts +38 -5
  29. package/dist/cjs/agentkit/vendors/base.js +60 -6
  30. package/dist/cjs/agentkit/vendors/cn.d.ts +251 -0
  31. package/dist/cjs/agentkit/vendors/cn.js +293 -0
  32. package/dist/cjs/agentkit/vendors/llm.d.ts +4 -2
  33. package/dist/cjs/agentkit/vendors/llm.js +10 -5
  34. package/dist/cjs/agentkit/vendors/mllm.d.ts +8 -4
  35. package/dist/cjs/agentkit/vendors/mllm.js +8 -4
  36. package/dist/cjs/agentkit/vendors/stt.d.ts +4 -6
  37. package/dist/cjs/agentkit/vendors/stt.js +48 -62
  38. package/dist/cjs/agentkit/vendors/tts.d.ts +3 -3
  39. package/dist/cjs/agentkit/vendors/tts.js +1 -1
  40. package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.d.ts +5 -2
  41. package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.js +4 -0
  42. package/dist/cjs/api/types/Asr.d.ts +16 -1
  43. package/dist/cjs/api/types/BytedanceDuplexTts.d.ts +9 -0
  44. package/dist/cjs/api/types/BytedanceDuplexTts.js +3 -0
  45. package/dist/cjs/api/types/BytedanceDuplexTtsParams.d.ts +13 -0
  46. package/dist/cjs/api/types/BytedanceDuplexTtsParams.js +3 -0
  47. package/dist/cjs/api/types/BytedanceTts.d.ts +9 -0
  48. package/dist/cjs/api/types/BytedanceTts.js +3 -0
  49. package/dist/cjs/api/types/BytedanceTtsParams.d.ts +23 -0
  50. package/dist/cjs/api/types/BytedanceTtsParams.js +3 -0
  51. package/dist/cjs/api/types/CosyvoiceTts.d.ts +9 -0
  52. package/dist/cjs/api/types/CosyvoiceTts.js +3 -0
  53. package/dist/cjs/api/types/CosyvoiceTtsParams.d.ts +15 -0
  54. package/dist/cjs/api/types/CosyvoiceTtsParams.js +3 -0
  55. package/dist/cjs/api/types/DeepgramAsr.d.ts +0 -2
  56. package/dist/cjs/api/types/DeepgramAsrParams.d.ts +1 -1
  57. package/dist/cjs/api/types/FengmingAsr.d.ts +11 -0
  58. package/dist/cjs/api/types/FengmingAsr.js +3 -0
  59. package/dist/cjs/api/types/MinimaxTtsParams.d.ts +52 -3
  60. package/dist/cjs/api/types/SensetimeAvatarParams.d.ts +48 -0
  61. package/dist/cjs/api/types/SensetimeAvatarParams.js +3 -0
  62. package/dist/cjs/api/types/StepfunTts.d.ts +9 -0
  63. package/dist/cjs/api/types/StepfunTts.js +3 -0
  64. package/dist/cjs/api/types/StepfunTtsParams.d.ts +13 -0
  65. package/dist/cjs/api/types/StepfunTtsParams.js +3 -0
  66. package/dist/cjs/api/types/TencentAsr.d.ts +10 -0
  67. package/dist/cjs/api/types/TencentAsr.js +3 -0
  68. package/dist/cjs/api/types/TencentAsrParams.d.ts +17 -0
  69. package/dist/cjs/api/types/TencentAsrParams.js +3 -0
  70. package/dist/cjs/api/types/TencentTts.d.ts +9 -0
  71. package/dist/cjs/api/types/TencentTts.js +3 -0
  72. package/dist/cjs/api/types/TencentTtsParams.d.ts +23 -0
  73. package/dist/cjs/api/types/TencentTtsParams.js +3 -0
  74. package/dist/cjs/api/types/Tts.d.ts +16 -1
  75. package/dist/cjs/api/types/XfyunAsr.d.ts +10 -0
  76. package/dist/cjs/api/types/XfyunAsr.js +3 -0
  77. package/dist/cjs/api/types/XfyunAsrParams.d.ts +15 -0
  78. package/dist/cjs/api/types/XfyunAsrParams.js +3 -0
  79. package/dist/cjs/api/types/XfyunBigmodelAsr.d.ts +10 -0
  80. package/dist/cjs/api/types/XfyunBigmodelAsr.js +3 -0
  81. package/dist/cjs/api/types/XfyunBigmodelAsrParams.d.ts +17 -0
  82. package/dist/cjs/api/types/XfyunBigmodelAsrParams.js +3 -0
  83. package/dist/cjs/api/types/XfyunDialectAsr.d.ts +10 -0
  84. package/dist/cjs/api/types/XfyunDialectAsr.js +3 -0
  85. package/dist/cjs/api/types/XfyunDialectAsrParams.d.ts +15 -0
  86. package/dist/cjs/api/types/XfyunDialectAsrParams.js +3 -0
  87. package/dist/cjs/api/types/index.d.ts +20 -0
  88. package/dist/cjs/api/types/index.js +20 -0
  89. package/dist/cjs/core/domain/index.d.ts +2 -1
  90. package/dist/cjs/core/domain/index.js +5 -3
  91. package/dist/cjs/index.d.ts +3 -2
  92. package/dist/cjs/index.js +26 -2
  93. package/dist/cjs/version.d.ts +1 -1
  94. package/dist/cjs/version.js +1 -1
  95. package/dist/esm/AgoraPoolClient.d.mts +9 -6
  96. package/dist/esm/AgoraPoolClient.mjs +1 -0
  97. package/dist/esm/BaseClient.mjs +2 -2
  98. package/dist/esm/agentkit/Agent.d.mts +52 -51
  99. package/dist/esm/agentkit/Agent.mjs +51 -51
  100. package/dist/esm/agentkit/AgentSession.d.mts +11 -9
  101. package/dist/esm/agentkit/AgentSession.mjs +11 -6
  102. package/dist/esm/agentkit/__tests__/area-aware-vendors.test.d.mts +1 -0
  103. package/dist/esm/agentkit/__tests__/area-aware-vendors.test.mjs +55 -0
  104. package/dist/esm/agentkit/__tests__/readme-examples.test.d.mts +1 -0
  105. package/dist/esm/agentkit/__tests__/readme-examples.test.mjs +124 -0
  106. package/dist/esm/agentkit/__tests__/type-safety.test.mjs +24 -17
  107. package/dist/esm/agentkit/area.d.mts +4 -0
  108. package/dist/esm/agentkit/area.mjs +1 -0
  109. package/dist/esm/agentkit/avatar-types.d.mts +28 -2
  110. package/dist/esm/agentkit/avatar-types.mjs +23 -2
  111. package/dist/esm/agentkit/index.d.mts +8 -5
  112. package/dist/esm/agentkit/index.mjs +3 -2
  113. package/dist/esm/agentkit/presets.mjs +11 -4
  114. package/dist/esm/agentkit/region-vendors.d.mts +15 -0
  115. package/dist/esm/agentkit/region-vendors.mjs +1 -0
  116. package/dist/esm/agentkit/token.d.mts +3 -2
  117. package/dist/esm/agentkit/token.mjs +3 -2
  118. package/dist/esm/agentkit/types.d.mts +29 -6
  119. package/dist/esm/agentkit/vendors/avatar.d.mts +9 -4
  120. package/dist/esm/agentkit/vendors/avatar.mjs +6 -3
  121. package/dist/esm/agentkit/vendors/base.d.mts +38 -5
  122. package/dist/esm/agentkit/vendors/base.mjs +55 -5
  123. package/dist/esm/agentkit/vendors/cn.d.mts +251 -0
  124. package/dist/esm/agentkit/vendors/cn.mjs +272 -0
  125. package/dist/esm/agentkit/vendors/llm.d.mts +4 -2
  126. package/dist/esm/agentkit/vendors/llm.mjs +10 -5
  127. package/dist/esm/agentkit/vendors/mllm.d.mts +8 -4
  128. package/dist/esm/agentkit/vendors/mllm.mjs +8 -4
  129. package/dist/esm/agentkit/vendors/stt.d.mts +4 -6
  130. package/dist/esm/agentkit/vendors/stt.mjs +48 -62
  131. package/dist/esm/agentkit/vendors/tts.d.mts +3 -3
  132. package/dist/esm/agentkit/vendors/tts.mjs +1 -1
  133. package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.d.mts +5 -2
  134. package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.mjs +4 -0
  135. package/dist/esm/api/types/Asr.d.mts +16 -1
  136. package/dist/esm/api/types/BytedanceDuplexTts.d.mts +9 -0
  137. package/dist/esm/api/types/BytedanceDuplexTts.mjs +2 -0
  138. package/dist/esm/api/types/BytedanceDuplexTtsParams.d.mts +13 -0
  139. package/dist/esm/api/types/BytedanceDuplexTtsParams.mjs +2 -0
  140. package/dist/esm/api/types/BytedanceTts.d.mts +9 -0
  141. package/dist/esm/api/types/BytedanceTts.mjs +2 -0
  142. package/dist/esm/api/types/BytedanceTtsParams.d.mts +23 -0
  143. package/dist/esm/api/types/BytedanceTtsParams.mjs +2 -0
  144. package/dist/esm/api/types/CosyvoiceTts.d.mts +9 -0
  145. package/dist/esm/api/types/CosyvoiceTts.mjs +2 -0
  146. package/dist/esm/api/types/CosyvoiceTtsParams.d.mts +15 -0
  147. package/dist/esm/api/types/CosyvoiceTtsParams.mjs +2 -0
  148. package/dist/esm/api/types/DeepgramAsr.d.mts +0 -2
  149. package/dist/esm/api/types/DeepgramAsrParams.d.mts +1 -1
  150. package/dist/esm/api/types/FengmingAsr.d.mts +11 -0
  151. package/dist/esm/api/types/FengmingAsr.mjs +2 -0
  152. package/dist/esm/api/types/MinimaxTtsParams.d.mts +52 -3
  153. package/dist/esm/api/types/SensetimeAvatarParams.d.mts +48 -0
  154. package/dist/esm/api/types/SensetimeAvatarParams.mjs +2 -0
  155. package/dist/esm/api/types/StepfunTts.d.mts +9 -0
  156. package/dist/esm/api/types/StepfunTts.mjs +2 -0
  157. package/dist/esm/api/types/StepfunTtsParams.d.mts +13 -0
  158. package/dist/esm/api/types/StepfunTtsParams.mjs +2 -0
  159. package/dist/esm/api/types/TencentAsr.d.mts +10 -0
  160. package/dist/esm/api/types/TencentAsr.mjs +2 -0
  161. package/dist/esm/api/types/TencentAsrParams.d.mts +17 -0
  162. package/dist/esm/api/types/TencentAsrParams.mjs +2 -0
  163. package/dist/esm/api/types/TencentTts.d.mts +9 -0
  164. package/dist/esm/api/types/TencentTts.mjs +2 -0
  165. package/dist/esm/api/types/TencentTtsParams.d.mts +23 -0
  166. package/dist/esm/api/types/TencentTtsParams.mjs +2 -0
  167. package/dist/esm/api/types/Tts.d.mts +16 -1
  168. package/dist/esm/api/types/XfyunAsr.d.mts +10 -0
  169. package/dist/esm/api/types/XfyunAsr.mjs +2 -0
  170. package/dist/esm/api/types/XfyunAsrParams.d.mts +15 -0
  171. package/dist/esm/api/types/XfyunAsrParams.mjs +2 -0
  172. package/dist/esm/api/types/XfyunBigmodelAsr.d.mts +10 -0
  173. package/dist/esm/api/types/XfyunBigmodelAsr.mjs +2 -0
  174. package/dist/esm/api/types/XfyunBigmodelAsrParams.d.mts +17 -0
  175. package/dist/esm/api/types/XfyunBigmodelAsrParams.mjs +2 -0
  176. package/dist/esm/api/types/XfyunDialectAsr.d.mts +10 -0
  177. package/dist/esm/api/types/XfyunDialectAsr.mjs +2 -0
  178. package/dist/esm/api/types/XfyunDialectAsrParams.d.mts +15 -0
  179. package/dist/esm/api/types/XfyunDialectAsrParams.mjs +2 -0
  180. package/dist/esm/api/types/index.d.mts +20 -0
  181. package/dist/esm/api/types/index.mjs +20 -0
  182. package/dist/esm/core/domain/index.d.mts +2 -1
  183. package/dist/esm/core/domain/index.mjs +4 -2
  184. package/dist/esm/index.d.mts +3 -2
  185. package/dist/esm/index.mjs +6 -6
  186. package/dist/esm/version.d.mts +1 -1
  187. package/dist/esm/version.mjs +1 -1
  188. package/package.json +1 -1
@@ -3,11 +3,13 @@
3
3
  * Agent class - A reusable agent definition.
4
4
  *
5
5
  * This class represents an agent configuration that can be used to create
6
- * multiple sessions. It provides a fluent builder pattern for configuration.
6
+ * multiple sessions. Set the unique agent instance `name` in
7
+ * {@link Agent.createSession}, not on the Agent itself.
7
8
  */
8
9
  Object.defineProperty(exports, "__esModule", { value: true });
9
10
  exports.Agent = void 0;
10
11
  const AgentSession_js_1 = require("./AgentSession.js");
12
+ const constants_js_1 = require("./constants.js");
11
13
  const token_js_1 = require("./token.js");
12
14
  const DEFAULT_TURN_DETECTION_LANGUAGE = "en-US";
13
15
  const INTERACTION_LANGUAGES = new Set([
@@ -49,7 +51,7 @@ function isTurnDetectionLanguage(value) {
49
51
  }
50
52
  function assertTurnDetectionLanguage(value) {
51
53
  if (!isTurnDetectionLanguage(value)) {
52
- throw new Error(`Invalid interaction language: ${value}`);
54
+ throw new Error(`Invalid turnDetection.language: ${value}`);
53
55
  }
54
56
  }
55
57
  /**
@@ -62,15 +64,22 @@ function assertTurnDetectionLanguage(value) {
62
64
  * import { Agent, OpenAI, MicrosoftTTS, DeepgramSTT } from 'agora-agents';
63
65
  *
64
66
  * // Use the fluent builder pattern to configure vendors
65
- * const agent = new Agent({ instructions: 'You are helpful.' })
67
+ * const agent = new Agent({ client, instructions: 'You are helpful.' })
66
68
  * .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4', url: 'https://api.openai.com/v1/chat/completions' }))
67
69
  * .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
68
70
  * .withStt(new DeepgramSTT({ apiKey: '...', model: 'nova-2' }));
71
+ *
72
+ * const session = agent.createSession({
73
+ * name: `conversation-${Date.now()}`,
74
+ * channel: `demo-channel-${Date.now()}`,
75
+ * agentUid: '1',
76
+ * remoteUids: ['100'],
77
+ * });
69
78
  * ```
70
79
  */
71
80
  class Agent {
72
- constructor(options = {}) {
73
- this._name = options.name;
81
+ constructor(options) {
82
+ this._client = options.client;
74
83
  this._pipelineId = options.pipelineId;
75
84
  this._instructions = options.instructions;
76
85
  this._greeting = options.greeting;
@@ -205,7 +214,8 @@ class Agent {
205
214
  * ```typescript
206
215
  * import { HeyGenAvatar, ElevenLabsTTS } from 'agora-agents';
207
216
  *
208
- * const agent = new Agent({ name: 'avatar-assistant' })
217
+ * const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
218
+ * const agent = new Agent({ client })
209
219
  * .withTts(new ElevenLabsTTS({
210
220
  * key: '...',
211
221
  * modelId: '...',
@@ -276,14 +286,6 @@ class Agent {
276
286
  newAgent._greetingConfigs = configs;
277
287
  return newAgent;
278
288
  }
279
- /**
280
- * Returns a new Agent with the specified name.
281
- */
282
- withName(name) {
283
- const newAgent = this._clone();
284
- newAgent._name = name;
285
- return newAgent;
286
- }
287
289
  /**
288
290
  * Returns a new Agent with the specified SAL (Selective Attention Locking) configuration.
289
291
  */
@@ -389,12 +391,6 @@ class Agent {
389
391
  newAgent._fillerWords = fillerWords;
390
392
  return newAgent;
391
393
  }
392
- /**
393
- * Get the agent name.
394
- */
395
- get name() {
396
- return this._name;
397
- }
398
394
  /**
399
395
  * Get the AI Studio pipeline ID used as this agent's base configuration.
400
396
  */
@@ -522,7 +518,7 @@ class Agent {
522
518
  */
523
519
  get config() {
524
520
  return {
525
- name: this._name,
521
+ client: this._client,
526
522
  pipelineId: this._pipelineId,
527
523
  instructions: this._instructions,
528
524
  turnDetection: this._turnDetection,
@@ -548,18 +544,19 @@ class Agent {
548
544
  /**
549
545
  * Creates a new session from this agent configuration.
550
546
  *
551
- * @param client - The Agora client instance (must have appId and appCertificate properties)
552
547
  * @param options - Session connection options
553
548
  * @returns A new AgentSession instance ready to start
554
549
  *
555
550
  * @example
556
551
  * ```typescript
557
- * const agent = new Agent({ name: 'my-assistant', instructions: '...' })
558
- * .withLlm({ ... })
559
- * .withTts({ ... });
560
- *
561
- * const session = agent.createSession(client, {
562
- * channel: 'room-123',
552
+ * const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
553
+ * const agent = new Agent({ client })
554
+ * .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
555
+ * .withTts(new MiniMaxTTS({ model: 'speech_2_6_turbo', voiceId: 'English_captivating_female1' }));
556
+ *
557
+ * const session = agent.createSession({
558
+ * name: `conversation-${Date.now()}`,
559
+ * channel: `demo-channel-${Date.now()}`,
563
560
  * agentUid: '1',
564
561
  * remoteUids: ['100'],
565
562
  * idleTimeout: 120,
@@ -568,10 +565,10 @@ class Agent {
568
565
  * const agentId = await session.start();
569
566
  * ```
570
567
  */
571
- createSession(client, options) {
572
- var _a, _b;
573
- const name = (_b = (_a = options.name) !== null && _a !== void 0 ? _a : this._name) !== null && _b !== void 0 ? _b : `agent-${Date.now()}`;
574
- return new AgentSession_js_1.AgentSession(Object.assign(Object.assign({ client, agent: this, appId: client.appId, appCertificate: client.appCertificate }, options), { name }));
568
+ createSession(options) {
569
+ var _a;
570
+ const name = (_a = options.name) !== null && _a !== void 0 ? _a : `agent-${Date.now()}`;
571
+ return new AgentSession_js_1.AgentSession(Object.assign(Object.assign({ client: this._client, agent: this, appId: this._client.appId, appCertificate: this._client.appCertificate }, options), { name }));
575
572
  }
576
573
  /**
577
574
  * Converts the Agent configuration to the Fern request properties format.
@@ -581,7 +578,7 @@ class Agent {
581
578
  * and RTM privileges (required for RTM-enabled sessions).
582
579
  */
583
580
  toProperties(opts) {
584
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
581
+ var _a, _b, _c, _d, _e, _f, _g, _h;
585
582
  // In MLLM mode the backend handles audio end-to-end; LLM, TTS, and ASR
586
583
  // are not required.
587
584
  const isMllmMode = ((_a = this._mllm) === null || _a === void 0 ? void 0 : _a.enable) === true || this._mllm !== undefined;
@@ -614,8 +611,13 @@ class Agent {
614
611
  // When RTM is enabled, data_channel must also be 'rtm' for the client
615
612
  // to receive transcripts and state events. Default it automatically so
616
613
  // callers only need to set advancedFeatures.enable_rtm: true.
617
- const resolvedParameters = ((_b = this._advancedFeatures) === null || _b === void 0 ? void 0 : _b.enable_rtm) && !((_c = this._parameters) === null || _c === void 0 ? void 0 : _c.data_channel)
618
- ? Object.assign(Object.assign({}, this._parameters), { data_channel: "rtm" }) : this._parameters;
614
+ let resolvedParameters = this._parameters;
615
+ if (((_b = this._advancedFeatures) === null || _b === void 0 ? void 0 : _b.enable_rtm) && !(resolvedParameters === null || resolvedParameters === void 0 ? void 0 : resolvedParameters.data_channel)) {
616
+ resolvedParameters = Object.assign(Object.assign({}, resolvedParameters), { data_channel: "rtm" });
617
+ }
618
+ if ((resolvedParameters === null || resolvedParameters === void 0 ? void 0 : resolvedParameters.audio_scenario) === undefined) {
619
+ resolvedParameters = Object.assign(Object.assign({}, resolvedParameters), { audio_scenario: constants_js_1.AudioScenario.Default });
620
+ }
619
621
  const base = {
620
622
  channel: opts.channel,
621
623
  token,
@@ -649,8 +651,8 @@ class Agent {
649
651
  }
650
652
  return Object.assign(Object.assign({}, base), { mllm: mllmConfig, turn_detection: this._turnDetection });
651
653
  }
652
- const skipCategories = new Set((_d = opts.skipVendorValidationCategories) !== null && _d !== void 0 ? _d : []);
653
- const allowMissingCategories = new Set((_e = opts.allowMissingVendorCategories) !== null && _e !== void 0 ? _e : []);
654
+ const skipCategories = new Set((_c = opts.skipVendorValidationCategories) !== null && _c !== void 0 ? _c : []);
655
+ const allowMissingCategories = new Set((_d = opts.allowMissingVendorCategories) !== null && _d !== void 0 ? _d : []);
654
656
  if (opts.skipVendorValidation) {
655
657
  for (const category of ["asr", "llm", "tts"]) {
656
658
  skipCategories.add(category);
@@ -669,13 +671,15 @@ class Agent {
669
671
  throw new Error("LLM configuration is required. Use withLlm() to set it.");
670
672
  }
671
673
  const llmConfig = this._llm
672
- ? Object.assign(Object.assign({}, this._llm), { system_messages: this._instructions
673
- ? [{ role: "system", content: this._instructions }]
674
- : this._llm.system_messages, greeting_message: (_f = this._greeting) !== null && _f !== void 0 ? _f : this._llm.greeting_message, greeting_configs: (_g = this._greetingConfigs) !== null && _g !== void 0 ? _g : this._llm.greeting_configs, failure_message: (_h = this._failureMessage) !== null && _h !== void 0 ? _h : this._llm.failure_message, max_history: (_j = this._maxHistory) !== null && _j !== void 0 ? _j : this._llm.max_history }) : undefined;
674
+ ? Object.assign(Object.assign({}, this._llm), { system_messages: this._llm.system_messages !== undefined
675
+ ? this._llm.system_messages
676
+ : this._instructions
677
+ ? [{ role: "system", content: this._instructions }]
678
+ : 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;
679
+ const turnDetectionConfig = this._resolveTurnDetectionConfig();
675
680
  const asrConfig = this._stt !== undefined || !allowMissingAsr
676
- ? this._resolveAsrConfig()
681
+ ? this._resolveAsrConfig(turnDetectionConfig)
677
682
  : undefined;
678
- const turnDetectionConfig = this._resolveTurnDetectionConfig();
679
683
  const ttsConfig = this._tts;
680
684
  return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, base), { turn_detection: turnDetectionConfig }), (llmConfig && { llm: llmConfig })), (ttsConfig && { tts: ttsConfig })), (asrConfig && { asr: asrConfig }));
681
685
  }
@@ -689,8 +693,7 @@ class Agent {
689
693
  * If a new private field is added to Agent, it MUST also be added here.
690
694
  */
691
695
  _clone() {
692
- const newAgent = new Agent();
693
- newAgent._name = this._name;
696
+ const newAgent = new Agent({ client: this._client });
694
697
  newAgent._pipelineId = this._pipelineId;
695
698
  newAgent._llm = this._llm;
696
699
  newAgent._tts = this._tts;
@@ -713,23 +716,20 @@ class Agent {
713
716
  newAgent._greetingConfigs = this._greetingConfigs;
714
717
  return newAgent;
715
718
  }
716
- _resolveAsrConfig() {
719
+ _resolveAsrConfig(turnDetectionConfig) {
717
720
  var _a;
718
721
  const asrConfig = Object.assign({}, ((_a = this._stt) !== null && _a !== void 0 ? _a : {}));
719
722
  if (this._stt === undefined) {
720
723
  asrConfig.vendor = "ares";
721
724
  }
722
- delete asrConfig.language;
725
+ asrConfig.language = turnDetectionConfig.language;
723
726
  return Object.keys(asrConfig).length > 0 ? asrConfig : undefined;
724
727
  }
725
728
  _resolveTurnDetectionConfig() {
726
- var _a, _b;
729
+ var _a;
727
730
  const turnDetection = Object.assign({}, ((_a = this._turnDetection) !== null && _a !== void 0 ? _a : {}));
728
731
  const existingTurnDetectionLanguage = turnDetection.language;
729
- const existingAsrLanguage = (_b = this._stt) === null || _b === void 0 ? void 0 : _b.language;
730
- const language = existingTurnDetectionLanguage !== null && existingTurnDetectionLanguage !== void 0 ? existingTurnDetectionLanguage : (existingAsrLanguage !== undefined && isTurnDetectionLanguage(existingAsrLanguage)
731
- ? existingAsrLanguage
732
- : DEFAULT_TURN_DETECTION_LANGUAGE);
732
+ const language = existingTurnDetectionLanguage !== null && existingTurnDetectionLanguage !== void 0 ? existingTurnDetectionLanguage : DEFAULT_TURN_DETECTION_LANGUAGE;
733
733
  assertTurnDetectionLanguage(language);
734
734
  turnDetection.language = language;
735
735
  return turnDetection;
@@ -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.js";
7
8
  import type { AgentManagementClient } from "../api/resources/agentManagement/client/Client.js";
8
9
  import type { AgentsClient } from "../api/resources/agents/client/Client.js";
9
- import type { AgoraClient } from "../Client.js";
10
10
  import type { Agent } from "./Agent.js";
11
+ import type { AgoraArea } from "./area.js";
11
12
  import { type PresetInput } from "./presets.js";
12
13
  import type { AgentConfigUpdate, ConversationHistory, ConversationTurns, GetTurnsOptions, SayOptions, SessionInfo, ThinkOptions, ThinkResponse } from "./types.js";
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 for this agent instance */
34
+ /** Unique agent instance name (set via {@link Agent.createSession}) */
34
35
  name: string;
35
36
  /** The channel to join */
36
37
  channel: string;
@@ -77,13 +78,14 @@ export interface AgentSessionOptions {
77
78
  * appCertificate: '...',
78
79
  * });
79
80
  *
80
- * const agent = new Agent({ name: 'support-assistant', instructions: 'You are a helpful voice assistant.' })
81
+ * const agent = new Agent({ client, instructions: 'You are a helpful voice assistant.' })
81
82
  * .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
82
83
  * .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
83
84
  * .withStt(new DeepgramSTT({ apiKey: '...', language: 'en-US' }));
84
85
  *
85
- * const session = agent.createSession(client, {
86
- * channel: 'support-room-123',
86
+ * const session = agent.createSession({
87
+ * name: `conversation-${Date.now()}`,
88
+ * channel: `demo-channel-${Date.now()}`,
87
89
  * agentUid: '1',
88
90
  * remoteUids: ['100'],
89
91
  * });
@@ -136,7 +138,7 @@ export declare class AgentSession {
136
138
  /**
137
139
  * The agent configuration.
138
140
  */
139
- get agent(): Agent;
141
+ get agent(): Agent<number, AgoraArea>;
140
142
  /**
141
143
  * The App ID for this session.
142
144
  */
@@ -183,7 +185,7 @@ export declare class AgentSession {
183
185
  * Fills session-derived avatar fields and generates avatar ConvoAI tokens.
184
186
  *
185
187
  * Token management is gated to vendors that publish a separate RTC video
186
- * identity (HeyGen, LiveAvatar, Generic). Other vendors (Akool, Anam) do
188
+ * identity (HeyGen, LiveAvatar, Generic, SenseTime). Other vendors (Akool, Anam) do
187
189
  * not run a separate publisher and never receive an auto-generated token.
188
190
  */
189
191
  private _enrichAvatarParams;
@@ -35,13 +35,14 @@ const token_js_1 = require("./token.js");
35
35
  * appCertificate: '...',
36
36
  * });
37
37
  *
38
- * const agent = new Agent({ name: 'support-assistant', instructions: 'You are a helpful voice assistant.' })
38
+ * const agent = new Agent({ client, instructions: 'You are a helpful voice assistant.' })
39
39
  * .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
40
40
  * .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
41
41
  * .withStt(new DeepgramSTT({ apiKey: '...', language: 'en-US' }));
42
42
  *
43
- * const session = agent.createSession(client, {
44
- * channel: 'support-room-123',
43
+ * const session = agent.createSession({
44
+ * name: `conversation-${Date.now()}`,
45
+ * channel: `demo-channel-${Date.now()}`,
45
46
  * agentUid: '1',
46
47
  * remoteUids: ['100'],
47
48
  * });
@@ -193,6 +194,7 @@ class AgentSession {
193
194
  // are filled by `_enrichAvatarParams()` and validated separately.
194
195
  if ((0, avatar_types_js_1.isHeyGenAvatar)(strictAvatar) ||
195
196
  (0, avatar_types_js_1.isLiveAvatarAvatar)(strictAvatar) ||
197
+ (0, avatar_types_js_1.isSensetimeAvatar)(strictAvatar) ||
196
198
  (0, avatar_types_js_1.isAkoolAvatar)(strictAvatar) ||
197
199
  (0, avatar_types_js_1.isAnamAvatar)(strictAvatar) ||
198
200
  (0, avatar_types_js_1.isGenericAvatar)(strictAvatar)) {
@@ -228,7 +230,7 @@ class AgentSession {
228
230
  * Fills session-derived avatar fields and generates avatar ConvoAI tokens.
229
231
  *
230
232
  * Token management is gated to vendors that publish a separate RTC video
231
- * identity (HeyGen, LiveAvatar, Generic). Other vendors (Akool, Anam) do
233
+ * identity (HeyGen, LiveAvatar, Generic, SenseTime). Other vendors (Akool, Anam) do
232
234
  * not run a separate publisher and never receive an auto-generated token.
233
235
  */
234
236
  _enrichAvatarParams(properties, expirySeconds) {
@@ -279,10 +281,13 @@ class AgentSession {
279
281
  const strictAvatar = avatar;
280
282
  if ((0, avatar_types_js_1.isHeyGenAvatar)(strictAvatar) ||
281
283
  (0, avatar_types_js_1.isLiveAvatarAvatar)(strictAvatar) ||
284
+ (0, avatar_types_js_1.isSensetimeAvatar)(strictAvatar) ||
282
285
  (0, avatar_types_js_1.isAkoolAvatar)(strictAvatar) ||
283
286
  (0, avatar_types_js_1.isAnamAvatar)(strictAvatar) ||
284
287
  (0, avatar_types_js_1.isGenericAvatar)(strictAvatar)) {
285
- (0, avatar_types_js_1.validateAvatarConfig)(strictAvatar, { requireSessionFields: (0, avatar_types_js_1.isGenericAvatar)(strictAvatar) });
288
+ (0, avatar_types_js_1.validateAvatarConfig)(strictAvatar, {
289
+ requireSessionFields: (0, avatar_types_js_1.isGenericAvatar)(strictAvatar),
290
+ });
286
291
  }
287
292
  if (!(0, avatar_types_js_1.isAvatarTokenManaged)(strictAvatar)) {
288
293
  return;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AgoraPoolClient_js_1 = require("../../AgoraPoolClient.js");
4
+ const index_js_1 = require("../../core/domain/index.js");
5
+ const Agent_js_1 = require("../Agent.js");
6
+ const cn_js_1 = require("../vendors/cn.js");
7
+ const llm_js_1 = require("../vendors/llm.js");
8
+ const stt_js_1 = require("../vendors/stt.js");
9
+ const tts_js_1 = require("../vendors/tts.js");
10
+ const client = new AgoraPoolClient_js_1.AgoraClient({
11
+ area: index_js_1.Area.US,
12
+ appId: "app-id",
13
+ appCertificate: "app-certificate",
14
+ });
15
+ new Agent_js_1.Agent({ client, turnDetection: { language: "en-US" } })
16
+ .withStt(new stt_js_1.DeepgramSTT({ model: "nova-3", language: "en-US" }))
17
+ .withLlm(new llm_js_1.OpenAI({ model: "gpt-5-mini" }))
18
+ .withTts(new tts_js_1.MiniMaxTTS({ model: "speech-2.6-turbo", voiceId: "English_captivating_female1" }))
19
+ .createSession({
20
+ name: "assistant",
21
+ channel: "test-room",
22
+ agentUid: "1",
23
+ remoteUids: ["100"],
24
+ });
25
+ // Area and provider may differ.
26
+ new Agent_js_1.Agent({ client }).withStt(new cn_js_1.FengmingSTT());
27
+ new Agent_js_1.Agent({ client }).withLlm(new cn_js_1.AliyunLLM({ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", model: "qwen-plus" }));
28
+ new Agent_js_1.Agent({ client }).withTts(new cn_js_1.MiniMaxCNTTS({ key: "minimax-key", model: "speech-01-turbo", voiceSetting: { voice_id: "female-shaonv" } }));
29
+ {
30
+ const client = new AgoraPoolClient_js_1.AgoraClient({
31
+ area: index_js_1.Area.CN,
32
+ appId: "app-id",
33
+ appCertificate: "app-certificate",
34
+ });
35
+ new Agent_js_1.Agent({ client, turnDetection: { language: "zh-CN" } })
36
+ .withStt(new cn_js_1.FengmingSTT())
37
+ .withLlm(new cn_js_1.AliyunLLM({
38
+ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
39
+ model: "qwen-plus",
40
+ }))
41
+ .withTts(new cn_js_1.MiniMaxCNTTS({
42
+ key: "minimax-key",
43
+ model: "speech-01-turbo",
44
+ voiceSetting: { voice_id: "female-shaonv" },
45
+ audioSetting: { sample_rate: 16000 },
46
+ }))
47
+ .createSession({
48
+ name: "assistant",
49
+ channel: "cn-room",
50
+ agentUid: "1",
51
+ remoteUids: ["100"],
52
+ });
53
+ new Agent_js_1.Agent({ client }).withStt(new stt_js_1.DeepgramSTT({ model: "nova-3", language: "en-US" }));
54
+ new Agent_js_1.Agent({ client }).withLlm(new llm_js_1.OpenAI({ model: "gpt-5-mini" }));
55
+ new Agent_js_1.Agent({ client }).withTts(new tts_js_1.MiniMaxTTS({ model: "speech-2.6-turbo", voiceId: "English_captivating_female1" }));
56
+ }
57
+ new Agent_js_1.Agent({ client }).withStt(new stt_js_1.DeepgramSTT({ model: "nova-3", language: "en-US" }));
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AgoraPoolClient_js_1 = require("../../AgoraPoolClient.js");
4
+ const index_js_1 = require("../../core/domain/index.js");
5
+ const Agent_js_1 = require("../Agent.js");
6
+ const cn_js_1 = require("../vendors/cn.js");
7
+ const llm_js_1 = require("../vendors/llm.js");
8
+ const stt_js_1 = require("../vendors/stt.js");
9
+ const tts_js_1 = require("../vendors/tts.js");
10
+ const AGENT_PROMPT = "You are a concise, technically credible voice assistant. Keep replies short unless the user asks for detail.";
11
+ const GREETING = "Hi there! I am your Agora voice assistant. How can I help?";
12
+ const SUPPORT_PROMPT = "You are a concise support assistant.";
13
+ const client = new AgoraPoolClient_js_1.AgoraClient({
14
+ area: index_js_1.Area.US,
15
+ appId: "app-id",
16
+ appCertificate: "app-certificate",
17
+ });
18
+ new Agent_js_1.Agent({
19
+ client,
20
+ turnDetection: {
21
+ language: "en-US",
22
+ config: {
23
+ speech_threshold: 0.5,
24
+ start_of_speech: {
25
+ mode: "vad",
26
+ vad_config: {
27
+ interrupt_duration_ms: 160,
28
+ prefix_padding_ms: 300,
29
+ },
30
+ },
31
+ end_of_speech: {
32
+ mode: "vad",
33
+ vad_config: {
34
+ silence_duration_ms: 480,
35
+ },
36
+ },
37
+ },
38
+ },
39
+ advancedFeatures: {
40
+ enable_rtm: true,
41
+ enable_tools: true,
42
+ },
43
+ parameters: {
44
+ data_channel: "rtm",
45
+ enable_error_message: true,
46
+ },
47
+ })
48
+ .withStt(new stt_js_1.DeepgramSTT({ model: "nova-3", language: "en" }))
49
+ .withLlm(new llm_js_1.OpenAI({
50
+ model: "gpt-4o-mini",
51
+ systemMessages: [{ role: "system", content: AGENT_PROMPT }],
52
+ greetingMessage: GREETING,
53
+ failureMessage: "Please wait a moment.",
54
+ maxHistory: 50,
55
+ params: {
56
+ max_tokens: 1024,
57
+ temperature: 0.7,
58
+ top_p: 0.95,
59
+ },
60
+ }))
61
+ .withTts(new tts_js_1.MiniMaxTTS({
62
+ model: "speech_2_6_turbo",
63
+ voiceId: "English_captivating_female1",
64
+ }))
65
+ .createSession({
66
+ name: `conversation-${Date.now()}`,
67
+ channel: `demo-channel-${Date.now()}`,
68
+ agentUid: "123456",
69
+ remoteUids: ["*"],
70
+ idleTimeout: 30,
71
+ });
72
+ {
73
+ const client = new AgoraPoolClient_js_1.AgoraClient({
74
+ area: index_js_1.Area.CN,
75
+ appId: "app-id",
76
+ appCertificate: "app-certificate",
77
+ });
78
+ new Agent_js_1.Agent({
79
+ client,
80
+ turnDetection: { language: "zh-CN" },
81
+ })
82
+ .withStt(new cn_js_1.FengmingSTT())
83
+ .withLlm(new cn_js_1.AliyunLLM({
84
+ url: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
85
+ model: "qwen-plus",
86
+ }))
87
+ .withTts(new cn_js_1.MiniMaxCNTTS({
88
+ key: "minimax-key",
89
+ model: "speech-01-turbo",
90
+ voiceSetting: { voice_id: "female-shaonv" },
91
+ audioSetting: { sample_rate: 16000 },
92
+ }))
93
+ .createSession({
94
+ name: `conversation-${Date.now()}`,
95
+ channel: `demo-channel-${Date.now()}`,
96
+ agentUid: "1001",
97
+ remoteUids: ["100"],
98
+ });
99
+ }
100
+ {
101
+ const client = new AgoraPoolClient_js_1.AgoraClient({
102
+ area: index_js_1.Area.US,
103
+ appId: "app-id",
104
+ appCertificate: "app-certificate",
105
+ });
106
+ new Agent_js_1.Agent({ client, turnDetection: { language: "en-US" } })
107
+ .withStt(new stt_js_1.DeepgramSTT({
108
+ apiKey: "deepgram-key",
109
+ model: "nova-3",
110
+ language: "en",
111
+ }))
112
+ .withLlm(new llm_js_1.OpenAI({
113
+ apiKey: "openai-key",
114
+ url: "https://api.openai.com/v1/chat/completions",
115
+ model: "gpt-4o-mini",
116
+ systemMessages: [{ role: "system", content: SUPPORT_PROMPT }],
117
+ greetingMessage: GREETING,
118
+ maxTokens: 1024,
119
+ temperature: 0.7,
120
+ topP: 0.95,
121
+ }))
122
+ .withTts(new tts_js_1.MiniMaxTTS({
123
+ model: "speech_2_6_turbo",
124
+ voiceId: "English_captivating_female1",
125
+ }));
126
+ }