agora-agents 2.6.1 → 2.8.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 (88) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/BaseClient.js +2 -2
  3. package/dist/cjs/agentkit/Agent.d.ts +1 -1
  4. package/dist/cjs/agentkit/Agent.js +28 -4
  5. package/dist/cjs/agentkit/AgentSession.d.ts +24 -0
  6. package/dist/cjs/agentkit/AgentSession.js +95 -23
  7. package/dist/cjs/agentkit/debug.d.ts +31 -0
  8. package/dist/cjs/agentkit/debug.js +143 -0
  9. package/dist/cjs/agentkit/index.d.ts +8 -3
  10. package/dist/cjs/agentkit/index.js +19 -3
  11. package/dist/cjs/agentkit/preview/client.d.ts +59 -0
  12. package/dist/cjs/agentkit/preview/client.js +94 -0
  13. package/dist/cjs/agentkit/preview/index.d.ts +12 -0
  14. package/dist/cjs/agentkit/preview/index.js +22 -0
  15. package/dist/cjs/agentkit/preview/vendors.d.ts +74 -0
  16. package/dist/cjs/agentkit/preview/vendors.js +88 -0
  17. package/dist/cjs/agentkit/token.js +32 -3
  18. package/dist/cjs/agentkit/types.d.ts +27 -6
  19. package/dist/cjs/agentkit/vendors/base.d.ts +6 -2
  20. package/dist/cjs/agentkit/vendors/base.js +4 -0
  21. package/dist/cjs/agentkit/vendors/cn.js +7 -5
  22. package/dist/cjs/agentkit/vendors/llm.js +8 -1
  23. package/dist/cjs/agentkit/vendors/stt.d.ts +45 -2
  24. package/dist/cjs/agentkit/vendors/stt.js +53 -5
  25. package/dist/cjs/agentkit/vendors/tts.js +1 -1
  26. package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.d.ts +12 -20
  27. package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.js +1 -1
  28. package/dist/cjs/api/types/Asr.d.ts +4 -1
  29. package/dist/cjs/api/types/GeminiAsr.d.ts +10 -0
  30. package/dist/cjs/api/types/GeminiAsr.js +3 -0
  31. package/dist/cjs/api/types/GeminiAsrParams.d.ts +33 -0
  32. package/dist/cjs/api/types/GeminiAsrParams.js +12 -0
  33. package/dist/cjs/api/types/index.d.ts +2 -0
  34. package/dist/cjs/api/types/index.js +2 -0
  35. package/dist/cjs/index.d.ts +2 -2
  36. package/dist/cjs/index.js +15 -3
  37. package/dist/cjs/version.d.ts +1 -1
  38. package/dist/cjs/version.js +1 -1
  39. package/dist/esm/BaseClient.mjs +2 -2
  40. package/dist/esm/agentkit/Agent.d.mts +1 -1
  41. package/dist/esm/agentkit/Agent.mjs +28 -4
  42. package/dist/esm/agentkit/AgentSession.d.mts +24 -0
  43. package/dist/esm/agentkit/AgentSession.mjs +95 -23
  44. package/dist/esm/agentkit/debug.d.mts +31 -0
  45. package/dist/esm/agentkit/debug.mjs +138 -0
  46. package/dist/esm/agentkit/index.d.mts +8 -3
  47. package/dist/esm/agentkit/index.mjs +4 -1
  48. package/dist/esm/agentkit/preview/client.d.mts +59 -0
  49. package/dist/esm/agentkit/preview/client.mjs +88 -0
  50. package/dist/esm/agentkit/preview/index.d.mts +12 -0
  51. package/dist/esm/agentkit/preview/index.mjs +9 -0
  52. package/dist/esm/agentkit/preview/vendors.d.mts +74 -0
  53. package/dist/esm/agentkit/preview/vendors.mjs +83 -0
  54. package/dist/esm/agentkit/token.mjs +32 -3
  55. package/dist/esm/agentkit/types.d.mts +27 -6
  56. package/dist/esm/agentkit/vendors/base.d.mts +6 -2
  57. package/dist/esm/agentkit/vendors/base.mjs +4 -0
  58. package/dist/esm/agentkit/vendors/cn.mjs +7 -5
  59. package/dist/esm/agentkit/vendors/llm.mjs +8 -1
  60. package/dist/esm/agentkit/vendors/stt.d.mts +45 -2
  61. package/dist/esm/agentkit/vendors/stt.mjs +51 -4
  62. package/dist/esm/agentkit/vendors/tts.mjs +1 -1
  63. package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.d.mts +12 -20
  64. package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.mjs +1 -1
  65. package/dist/esm/api/types/Asr.d.mts +4 -1
  66. package/dist/esm/api/types/GeminiAsr.d.mts +10 -0
  67. package/dist/esm/api/types/GeminiAsr.mjs +2 -0
  68. package/dist/esm/api/types/GeminiAsrParams.d.mts +33 -0
  69. package/dist/esm/api/types/GeminiAsrParams.mjs +9 -0
  70. package/dist/esm/api/types/index.d.mts +2 -0
  71. package/dist/esm/api/types/index.mjs +2 -0
  72. package/dist/esm/index.d.mts +2 -2
  73. package/dist/esm/index.mjs +4 -4
  74. package/dist/esm/version.d.mts +1 -1
  75. package/dist/esm/version.mjs +1 -1
  76. package/package.json +4 -2
  77. package/dist/cjs/agentkit/__tests__/area-aware-vendors.test.d.ts +0 -1
  78. package/dist/cjs/agentkit/__tests__/area-aware-vendors.test.js +0 -87
  79. package/dist/cjs/agentkit/__tests__/readme-examples.test.d.ts +0 -1
  80. package/dist/cjs/agentkit/__tests__/readme-examples.test.js +0 -126
  81. package/dist/cjs/agentkit/__tests__/type-safety.test.d.ts +0 -14
  82. package/dist/cjs/agentkit/__tests__/type-safety.test.js +0 -321
  83. package/dist/esm/agentkit/__tests__/area-aware-vendors.test.d.mts +0 -1
  84. package/dist/esm/agentkit/__tests__/area-aware-vendors.test.mjs +0 -85
  85. package/dist/esm/agentkit/__tests__/readme-examples.test.d.mts +0 -1
  86. package/dist/esm/agentkit/__tests__/readme-examples.test.mjs +0 -124
  87. package/dist/esm/agentkit/__tests__/type-safety.test.d.mts +0 -14
  88. package/dist/esm/agentkit/__tests__/type-safety.test.mjs +0 -319
@@ -1,319 +0,0 @@
1
- /**
2
- * Type safety demonstrations for sample rate enforcement.
3
- *
4
- * This file demonstrates compile-time type checking for:
5
- * 1. Invalid sample rates (e.g., 25000 Hz)
6
- * 2. Avatar/TTS sample rate mismatches (e.g., 16kHz TTS + HeyGen 24kHz avatar)
7
- * 3. Valid configurations that compile successfully
8
- *
9
- * To verify type checking works:
10
- * 1. Uncomment sections marked with @ts-expect-error
11
- * 2. Run: npm run build
12
- * 3. TypeScript should show errors for the uncommented invalid sections
13
- */
14
- import { AgoraClient } from "../../AgoraPoolClient.mjs";
15
- import { Area } from "../../core/domain/index.mjs";
16
- import { Agent } from "../Agent.mjs";
17
- import { AkoolAvatar, LiveAvatarAvatar } from "../vendors/avatar.mjs";
18
- import { OpenAI } from "../vendors/llm.mjs";
19
- import { DeepgramSTT } from "../vendors/stt.mjs";
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
- });
26
- // ============================================
27
- // ✅ VALID CONFIGURATIONS
28
- // ============================================
29
- // Example 1: ElevenLabs 24kHz + HeyGen avatar
30
- function _validExample1() {
31
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
32
- .withTts(new ElevenLabsTTS({
33
- key: "test",
34
- modelId: "eleven_flash_v2_5",
35
- voiceId: "test",
36
- baseUrl: "wss://api.elevenlabs.io/v1",
37
- sampleRate: 24000,
38
- }))
39
- .withAvatar(new LiveAvatarAvatar({
40
- apiKey: "test",
41
- quality: "high",
42
- agoraUid: "12345",
43
- }));
44
- }
45
- // Example 2: ElevenLabs 16kHz + Akool avatar
46
- function _validExample2() {
47
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
48
- .withTts(new ElevenLabsTTS({
49
- key: "test",
50
- modelId: "eleven_flash_v2_5",
51
- voiceId: "test",
52
- baseUrl: "wss://api.elevenlabs.io/v1",
53
- sampleRate: 16000,
54
- }))
55
- .withAvatar(new AkoolAvatar({
56
- apiKey: "test",
57
- }));
58
- }
59
- // Example 3: Microsoft 24kHz + HeyGen avatar
60
- function _validExample3() {
61
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
62
- .withTts(new MicrosoftTTS({
63
- key: "test",
64
- region: "eastus",
65
- voiceName: "en-US-JennyNeural",
66
- sampleRate: 24000,
67
- }))
68
- .withAvatar(new LiveAvatarAvatar({
69
- apiKey: "test",
70
- quality: "high",
71
- agoraUid: "12345",
72
- }));
73
- }
74
- // Example 4: OpenAI (fixed 24kHz) + HeyGen avatar
75
- function _validExample4() {
76
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
77
- .withTts(new OpenAITTS({
78
- apiKey: "test",
79
- voice: "alloy",
80
- model: "gpt-4o-mini-tts",
81
- baseUrl: "https://api.openai.com/v1",
82
- }))
83
- .withAvatar(new LiveAvatarAvatar({
84
- apiKey: "test",
85
- quality: "high",
86
- agoraUid: "12345",
87
- }));
88
- }
89
- // Example 5: Cartesia 16kHz + Akool avatar
90
- function _validExample5() {
91
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
92
- .withTts(new CartesiaTTS({
93
- apiKey: "test",
94
- voiceId: "test",
95
- modelId: "sonic-2",
96
- sampleRate: 16000,
97
- }))
98
- .withAvatar(new AkoolAvatar({
99
- apiKey: "test",
100
- }));
101
- }
102
- // Agora-managed models may omit credentials.
103
- new DeepgramSTT({ model: "nova-3" });
104
- new OpenAI({ model: "gpt-5-mini" });
105
- new OpenAITTS({ voice: "alloy" });
106
- new OpenAI({
107
- apiKey: "test",
108
- model: "gpt-5-mini",
109
- url: "https://api.openai.com/v1/chat/completions",
110
- vendor: "custom",
111
- });
112
- new MiniMaxTTS({
113
- model: "speech-2.6-turbo",
114
- });
115
- // @ts-expect-error Missing apiKey is only allowed for Agora-managed Deepgram models.
116
- new DeepgramSTT({ model: "enhanced" });
117
- // @ts-expect-error Missing apiKey is only allowed for Agora-managed OpenAI models.
118
- new OpenAI({ model: "gpt-4o" });
119
- // @ts-expect-error Missing apiKey cannot be combined with a custom vendor hint.
120
- new OpenAI({ model: "gpt-5-mini", vendor: "custom" });
121
- // @ts-expect-error Missing apiKey cannot be combined with a custom URL.
122
- new OpenAI({ model: "gpt-5-mini", url: "https://proxy.example.com/chat" });
123
- // @ts-expect-error Missing apiKey is only allowed for the openai_tts_1 preset model.
124
- new OpenAITTS({ voice: "alloy", model: "tts-1-hd" });
125
- // @ts-expect-error Missing key is only allowed for supported MiniMax preset models.
126
- new MiniMaxTTS({
127
- groupId: "group",
128
- model: "speech-02-turbo",
129
- voiceId: "voice",
130
- url: "wss://example.com",
131
- });
132
- // ============================================
133
- // ❌ INVALID: Sample rate mismatches
134
- // Uncomment to verify compile errors
135
- // ============================================
136
- /*
137
- // @ts-expect-error - HeyGen requires 24kHz, but TTS is configured for 16kHz
138
- function invalidMismatch1(): Agent<24000> {
139
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
140
- .withTts(
141
- new ElevenLabsTTS({
142
- key: "test",
143
- modelId: "eleven_flash_v2_5",
144
- voiceId: "test",
145
- baseUrl: "wss://api.elevenlabs.io/v1",
146
- sampleRate: 16000, // ❌ Wrong rate for HeyGen
147
- })
148
- )
149
- .withAvatar(
150
- new LiveAvatarAvatar({
151
- apiKey: "test",
152
- quality: "high",
153
- agoraUid: "12345",
154
- })
155
- );
156
- }
157
- */
158
- /*
159
- // @ts-expect-error - Akool requires 16kHz, but TTS is configured for 24kHz
160
- function invalidMismatch2(): Agent<16000> {
161
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
162
- .withTts(
163
- new ElevenLabsTTS({
164
- key: "test",
165
- modelId: "eleven_flash_v2_5",
166
- voiceId: "test",
167
- baseUrl: "wss://api.elevenlabs.io/v1",
168
- sampleRate: 24000, // ❌ Wrong rate for Akool
169
- })
170
- )
171
- .withAvatar(
172
- new AkoolAvatar({
173
- apiKey: "test",
174
- })
175
- );
176
- }
177
- */
178
- /*
179
- // @ts-expect-error - HeyGen requires 24kHz, not 48kHz
180
- function invalidMismatch3(): Agent<24000> {
181
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
182
- .withTts(
183
- new MicrosoftTTS({
184
- key: "test",
185
- region: "eastus",
186
- voiceName: "en-US-JennyNeural",
187
- sampleRate: 48000, // ❌ Wrong rate for HeyGen
188
- })
189
- )
190
- .withAvatar(
191
- new LiveAvatarAvatar({
192
- apiKey: "test",
193
- quality: "high",
194
- agoraUid: "12345",
195
- })
196
- );
197
- }
198
- */
199
- // ============================================
200
- // ❌ INVALID: Invalid enum values
201
- // Uncomment to verify compile errors
202
- // ============================================
203
- /*
204
- // @ts-expect-error - 25000 is not a valid ElevenLabs sample rate
205
- function invalidEnum1() {
206
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(
207
- new ElevenLabsTTS({
208
- key: "test",
209
- modelId: "eleven_flash_v2_5",
210
- voiceId: "test",
211
- baseUrl: "wss://api.elevenlabs.io/v1",
212
- sampleRate: 25000, // ❌ Not in enum: 16000, 22050, 24000, 44100
213
- })
214
- );
215
- }
216
- */
217
- /*
218
- // @ts-expect-error - 8000 is not a valid Microsoft sample rate
219
- function invalidEnum2() {
220
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(
221
- new MicrosoftTTS({
222
- key: "test",
223
- region: "eastus",
224
- voiceName: "en-US-JennyNeural",
225
- sampleRate: 8000, // ❌ Not in enum: 16000, 24000, 48000
226
- })
227
- );
228
- }
229
- */
230
- /*
231
- // @ts-expect-error - 32000 is not a valid Cartesia sample rate
232
- function invalidEnum3() {
233
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(
234
- new CartesiaTTS({
235
- key: "test",
236
- voiceId: "test",
237
- baseUrl: "wss://api.elevenlabs.io/v1",
238
- sampleRate: 32000, // ❌ Not in enum: 8000-48000 (specific values)
239
- })
240
- );
241
- }
242
- */
243
- // ============================================
244
- // ✅ VALID: Edge cases
245
- // ============================================
246
- // Avatar without TTS configured (allowed)
247
- function _edgeCase1() {
248
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withAvatar(new LiveAvatarAvatar({
249
- apiKey: "test",
250
- quality: "high",
251
- agoraUid: "12345",
252
- }));
253
- }
254
- // TTS without avatar (allowed)
255
- function _edgeCase2() {
256
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new ElevenLabsTTS({
257
- key: "test",
258
- modelId: "eleven_flash_v2_5",
259
- voiceId: "test",
260
- baseUrl: "wss://api.elevenlabs.io/v1",
261
- sampleRate: 16000,
262
- }));
263
- }
264
- // Method chaining preserves type tracking
265
- function _edgeCase3() {
266
- return new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" })
267
- .withTts(new ElevenLabsTTS({
268
- key: "test",
269
- modelId: "eleven_flash_v2_5",
270
- voiceId: "test",
271
- baseUrl: "wss://api.elevenlabs.io/v1",
272
- sampleRate: 24000,
273
- }))
274
- .withInstructions("Updated instructions")
275
- .withGreeting("Hello!")
276
- .withAvatar(new LiveAvatarAvatar({
277
- apiKey: "test",
278
- quality: "high",
279
- agoraUid: "12345",
280
- }));
281
- }
282
- // ============================================
283
- // Type inference verification
284
- // ============================================
285
- function _typeInference1() {
286
- const agentWith24k = new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new ElevenLabsTTS({
287
- key: "test",
288
- modelId: "eleven_flash_v2_5",
289
- voiceId: "test",
290
- baseUrl: "wss://api.elevenlabs.io/v1",
291
- sampleRate: 24000,
292
- }));
293
- // Verify: Type should be Agent<24000>
294
- const _typeCheck = agentWith24k;
295
- return agentWith24k;
296
- }
297
- function _typeInference2() {
298
- const agentWith16k = new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new ElevenLabsTTS({
299
- key: "test",
300
- modelId: "eleven_flash_v2_5",
301
- voiceId: "test",
302
- baseUrl: "wss://api.elevenlabs.io/v1",
303
- sampleRate: 16000,
304
- }));
305
- // Verify: Type should be Agent<16000>
306
- const _typeCheck = agentWith16k;
307
- return agentWith16k;
308
- }
309
- function _typeInference3() {
310
- const openAIAgent = new Agent({ client: TEST_AGENT_CLIENT, instructions: "Test" }).withTts(new OpenAITTS({
311
- apiKey: "test",
312
- voice: "alloy",
313
- model: "gpt-4o-mini-tts",
314
- baseUrl: "https://api.openai.com/v1",
315
- }));
316
- // Verify: OpenAI is fixed at 24kHz, so type should be Agent<24000>
317
- const _typeCheck = openAIAgent;
318
- return openAIAgent;
319
- }