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
package/README.md
CHANGED
|
@@ -15,19 +15,11 @@ npm install agora-agents
|
|
|
15
15
|
|
|
16
16
|
## Quick Start
|
|
17
17
|
|
|
18
|
-
Start with the `Agent` builder: create a client with app credentials,
|
|
18
|
+
Start with the `Agent` builder: create a client with app credentials, configure ASR, LLM, and TTS with vendor classes, then start a session. Omit vendor API keys for supported Agora-managed models, or provide keys when you want BYOK.
|
|
19
19
|
Set Agora interaction language with `turnDetection.language`; provider-specific STT language values remain under `asr.params`. Ares uses only the REST `asr.language` value sourced from `turnDetection.language`.
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import {
|
|
23
|
-
AgoraClient,
|
|
24
|
-
Agent,
|
|
25
|
-
Area,
|
|
26
|
-
DeepgramSTT,
|
|
27
|
-
ExpiresIn,
|
|
28
|
-
MiniMaxTTS,
|
|
29
|
-
OpenAI,
|
|
30
|
-
} from 'agora-agents';
|
|
22
|
+
import { AgoraClient, Agent, Area, DeepgramSTT, ExpiresIn, MiniMaxTTS, OpenAI } from 'agora-agents';
|
|
31
23
|
|
|
32
24
|
const AGENT_PROMPT = `You are a concise, technically credible voice assistant. Keep replies short unless the user asks for detail.`;
|
|
33
25
|
|
|
@@ -44,7 +36,7 @@ export async function startConversation(): Promise<string> {
|
|
|
44
36
|
});
|
|
45
37
|
|
|
46
38
|
const agent = new Agent({
|
|
47
|
-
|
|
39
|
+
client,
|
|
48
40
|
turnDetection: {
|
|
49
41
|
language: 'en-US',
|
|
50
42
|
config: {
|
|
@@ -100,9 +92,10 @@ export async function startConversation(): Promise<string> {
|
|
|
100
92
|
}),
|
|
101
93
|
);
|
|
102
94
|
|
|
103
|
-
const session = agent.createSession(
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
const session = agent.createSession({
|
|
96
|
+
name: `conversation-${Date.now()}`,
|
|
97
|
+
channel: `demo-channel-${Date.now()}`, // Unique channel name
|
|
98
|
+
agentUid: '123456', // Unique agent UID. Can be a random number or a specific user ID.
|
|
106
99
|
remoteUids: ['*'], // '*' is a wildcard, or use a specific user ID.
|
|
107
100
|
idleTimeout: 30,
|
|
108
101
|
expiresIn: ExpiresIn.hours(1),
|
|
@@ -115,20 +108,33 @@ export async function startConversation(): Promise<string> {
|
|
|
115
108
|
|
|
116
109
|
### Why no token or vendor key in the example?
|
|
117
110
|
|
|
118
|
-
`AgoraClient` generates the required ConvoAI REST auth and RTC join tokens automatically when you provide `appId` and `appCertificate`. For supported Agora-managed models, leave vendor API keys unset; provide keys when you want BYOK.
|
|
111
|
+
`AgoraClient` generates the required ConvoAI REST auth and RTC join tokens automatically when you provide `appId` and `appCertificate`. For supported Agora-managed global models, leave vendor API keys unset; provide keys when you want BYOK. CN MiniMax TTS is not Agora-managed and always requires `key`. CN custom LLM routing reuses `CustomLLM`, so `apiKey` is also required.
|
|
112
|
+
|
|
113
|
+
### Regional agent builders
|
|
114
|
+
|
|
115
|
+
`client.area` controls API routing only. You may combine any supported vendor class with any area. See [`docs/guides/regional-routing.md`](./docs/guides/regional-routing.md) for examples.
|
|
119
116
|
|
|
120
117
|
## AI Studio pipeline IDs
|
|
121
118
|
|
|
122
119
|
Use `pipelineId` when you want a published AI Studio pipeline to provide the base agent configuration:
|
|
123
120
|
|
|
124
121
|
```typescript
|
|
122
|
+
import { AgoraClient, Agent, Area } from 'agora-agents';
|
|
123
|
+
|
|
124
|
+
const client = new AgoraClient({
|
|
125
|
+
area: Area.US,
|
|
126
|
+
appId: process.env.AGORA_APP_ID!,
|
|
127
|
+
appCertificate: process.env.AGORA_APP_CERTIFICATE!,
|
|
128
|
+
});
|
|
129
|
+
|
|
125
130
|
const agent = new Agent({
|
|
126
|
-
|
|
131
|
+
client,
|
|
127
132
|
pipelineId: 'studio-pipeline-id',
|
|
128
133
|
});
|
|
129
134
|
|
|
130
|
-
const session = agent.createSession(
|
|
131
|
-
|
|
135
|
+
const session = agent.createSession({
|
|
136
|
+
name: `conversation-${Date.now()}`,
|
|
137
|
+
channel: `demo-channel-${Date.now()}`,
|
|
132
138
|
agentUid: '1',
|
|
133
139
|
remoteUids: ['100'],
|
|
134
140
|
});
|
|
@@ -137,8 +143,9 @@ const session = agent.createSession(client, {
|
|
|
137
143
|
You can override it per session:
|
|
138
144
|
|
|
139
145
|
```typescript
|
|
140
|
-
const session = agent.createSession(
|
|
141
|
-
|
|
146
|
+
const session = agent.createSession({
|
|
147
|
+
name: `conversation-${Date.now()}`,
|
|
148
|
+
channel: `demo-channel-${Date.now()}`,
|
|
142
149
|
agentUid: '1',
|
|
143
150
|
remoteUids: ['100'],
|
|
144
151
|
pipelineId: 'session-pipeline-id',
|
|
@@ -152,7 +159,18 @@ AgentKit sends the resolved value as the top-level `/join` field `pipeline_id`,
|
|
|
152
159
|
Use the same `Agent` builder shape, but provide credentials explicitly when you want vendor-managed billing and routing instead of Agora-managed models.
|
|
153
160
|
|
|
154
161
|
```typescript
|
|
155
|
-
|
|
162
|
+
import { AgoraClient, Agent, Area, DeepgramSTT, MiniMaxTTS, OpenAI } from 'agora-agents';
|
|
163
|
+
|
|
164
|
+
const client = new AgoraClient({
|
|
165
|
+
area: Area.US,
|
|
166
|
+
appId: process.env.AGORA_APP_ID!,
|
|
167
|
+
appCertificate: process.env.AGORA_APP_CERTIFICATE!,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const SUPPORT_PROMPT = 'You are a concise support assistant.';
|
|
171
|
+
const GREETING = 'Hi there! I am your Agora voice assistant. How can I help?';
|
|
172
|
+
|
|
173
|
+
const agent = new Agent({ client, turnDetection: { language: 'en-US' } })
|
|
156
174
|
.withStt(
|
|
157
175
|
new DeepgramSTT({
|
|
158
176
|
apiKey: process.env.DEEPGRAM_API_KEY!,
|
|
@@ -174,8 +192,6 @@ const agent = new Agent({ turnDetection: { language: 'en-US' } })
|
|
|
174
192
|
)
|
|
175
193
|
.withTts(
|
|
176
194
|
new MiniMaxTTS({
|
|
177
|
-
key: process.env.MINIMAX_API_KEY!,
|
|
178
|
-
groupId: process.env.MINIMAX_GROUP_ID!,
|
|
179
195
|
model: 'speech_2_6_turbo',
|
|
180
196
|
voiceId: 'English_captivating_female1',
|
|
181
197
|
}),
|
|
@@ -195,9 +211,15 @@ If you want to bring your own vendor credentials instead of using Agora-managed
|
|
|
195
211
|
Use `withMllm()` for OpenAI Realtime, Gemini Live, Vertex AI, or xAI Grok — no STT, LLM, or TTS vendor needed. MLLM mode is enabled automatically.
|
|
196
212
|
|
|
197
213
|
```typescript
|
|
198
|
-
import { Agent, OpenAIRealtime } from 'agora-agents';
|
|
214
|
+
import { AgoraClient, Agent, Area, OpenAIRealtime } from 'agora-agents';
|
|
215
|
+
|
|
216
|
+
const client = new AgoraClient({
|
|
217
|
+
area: Area.US,
|
|
218
|
+
appId: process.env.AGORA_APP_ID!,
|
|
219
|
+
appCertificate: process.env.AGORA_APP_CERTIFICATE!,
|
|
220
|
+
});
|
|
199
221
|
|
|
200
|
-
const agent = new Agent({
|
|
222
|
+
const agent = new Agent({ client }).withMllm(
|
|
201
223
|
new OpenAIRealtime({
|
|
202
224
|
apiKey: process.env.OPENAI_API_KEY!,
|
|
203
225
|
model: 'gpt-4o-realtime-preview',
|
|
@@ -212,7 +234,7 @@ See the [MLLM Flow guide](./docs/guides/mllm-flow.md) for full examples with Gem
|
|
|
212
234
|
|
|
213
235
|
## Avatars
|
|
214
236
|
|
|
215
|
-
AgentKit supports LiveAvatar, Generic Avatar, Anam, Akool, and deprecated HeyGen. Avatar `agoraToken` is optional: when omitted, `session.start()` generates a token using the same ConvoAI token format as the agent token, scoped to the avatar `agoraUid`. Avatars require the cascading ASR + LLM + TTS pipeline (not MLLM).
|
|
237
|
+
AgentKit supports LiveAvatar, Generic Avatar, Anam, Akool, SenseTime (CN), and deprecated HeyGen. Avatar `agoraToken` is optional: when omitted, `session.start()` generates a token using the same ConvoAI token format as the agent token, scoped to the avatar `agoraUid`. Avatars require the cascading ASR + LLM + TTS pipeline (not MLLM).
|
|
216
238
|
|
|
217
239
|
See the [Avatar Integration guide](./docs/guides/avatars.md) for sample-rate requirements and Generic Avatar setup.
|
|
218
240
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { AgoraArea } from "./agentkit/area.js";
|
|
1
2
|
import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
|
|
2
3
|
import { AgoraClient as BaseAgoraClient } from "./Client.js";
|
|
3
|
-
import {
|
|
4
|
+
import { Pool } from "./core/domain/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* Auth mode for the client:
|
|
6
7
|
* - `basic`: Customer ID + Secret for REST API (HTTP Basic Auth)
|
|
@@ -10,10 +11,10 @@ import { type Area, Pool } from "./core/domain/index.js";
|
|
|
10
11
|
*/
|
|
11
12
|
export type AgoraAuthMode = "basic" | "token" | "app-credentials";
|
|
12
13
|
export declare namespace AgoraClient {
|
|
13
|
-
type Options = BaseOptions & AuthOptions;
|
|
14
|
-
interface BaseOptions extends Omit<BaseClientOptions, "baseUrl" | "environment" | "username" | "password" | "authorization"> {
|
|
14
|
+
type Options<TArea extends AgoraArea = AgoraArea> = BaseOptions<TArea> & AuthOptions;
|
|
15
|
+
interface BaseOptions<TArea extends AgoraArea = AgoraArea> extends Omit<BaseClientOptions, "baseUrl" | "environment" | "username" | "password" | "authorization"> {
|
|
15
16
|
/** The area to use for regional URL selection */
|
|
16
|
-
area:
|
|
17
|
+
area: TArea;
|
|
17
18
|
/** Agora App ID — used as the `appid` path parameter and for RTC token generation */
|
|
18
19
|
appId: string;
|
|
19
20
|
/** Agora App Certificate — used to sign RTC tokens. Keep this secret. */
|
|
@@ -81,7 +82,7 @@ export declare namespace AgoraClient {
|
|
|
81
82
|
* });
|
|
82
83
|
* ```
|
|
83
84
|
*/
|
|
84
|
-
export declare class AgoraClient extends BaseAgoraClient {
|
|
85
|
+
export declare class AgoraClient<TArea extends AgoraArea = AgoraArea> extends BaseAgoraClient {
|
|
85
86
|
protected readonly _pool: Pool;
|
|
86
87
|
/** Agora App ID */
|
|
87
88
|
readonly appId: string;
|
|
@@ -89,7 +90,9 @@ export declare class AgoraClient extends BaseAgoraClient {
|
|
|
89
90
|
readonly appCertificate: string;
|
|
90
91
|
/** The active authentication mode */
|
|
91
92
|
readonly authMode: AgoraAuthMode;
|
|
92
|
-
|
|
93
|
+
/** The configured routing area */
|
|
94
|
+
readonly area: TArea;
|
|
95
|
+
constructor(options: AgoraClient.Options<TArea>);
|
|
93
96
|
/**
|
|
94
97
|
* Get the underlying domain pool for advanced usage.
|
|
95
98
|
* You can use this to manually cycle regions or select the best domain.
|
|
@@ -105,6 +105,7 @@ class AgoraClient extends Client_js_1.AgoraClient {
|
|
|
105
105
|
this.appId = options.appId;
|
|
106
106
|
this.appCertificate = options.appCertificate;
|
|
107
107
|
this.authMode = authMode;
|
|
108
|
+
this.area = options.area;
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
111
|
* Get the underlying domain pool for advanced usage.
|
|
@@ -2,22 +2,25 @@
|
|
|
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
|
*/
|
|
8
|
+
import type { AgoraClient } from "../AgoraPoolClient.js";
|
|
7
9
|
import type * as Agora from "../api/index.js";
|
|
8
|
-
import type { AgoraClient } from "../Client.js";
|
|
9
10
|
import { AgentSession } from "./AgentSession.js";
|
|
11
|
+
import type { AgoraArea } from "./area.js";
|
|
12
|
+
import type { AvatarVendor, LlmVendor, SttVendor, TtsVendor } from "./region-vendors.js";
|
|
10
13
|
import type { AdvancedFeatures, AvatarConfig, FillerWordsConfig, GeofenceConfig, InterruptionConfig, Labels, LlmConfig, LlmGreetingConfigs, MllmConfig, ParametersAudioScenario, RtcConfig, SalConfig, SessionOptions, SessionParamsInput, SttConfig, TtsConfig, TurnDetectionConfig } from "./types.js";
|
|
11
|
-
import type {
|
|
14
|
+
import type { BaseMLLM } from "./vendors/base.js";
|
|
12
15
|
/**
|
|
13
16
|
* Configuration options for creating an Agent.
|
|
14
17
|
*
|
|
15
18
|
* Use the fluent builder methods (.withLlm(), .withTts(), .withStt(), .withMllm())
|
|
16
19
|
* to configure vendor settings after construction.
|
|
17
20
|
*/
|
|
18
|
-
export interface AgentOptions {
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
+
export interface AgentOptions<TArea extends AgoraArea = AgoraArea> {
|
|
22
|
+
/** Agora client bound to this agent. Required for `createSession()`. */
|
|
23
|
+
client: AgoraClient<TArea>;
|
|
21
24
|
/**
|
|
22
25
|
* Published AI Studio pipeline ID to use as this agent's base configuration.
|
|
23
26
|
* Explicit Agent config such as .withLlm(), .withTts(), .withStt(),
|
|
@@ -81,14 +84,21 @@ export interface AgentOptions {
|
|
|
81
84
|
* import { Agent, OpenAI, MicrosoftTTS, DeepgramSTT } from 'agora-agents';
|
|
82
85
|
*
|
|
83
86
|
* // Use the fluent builder pattern to configure vendors
|
|
84
|
-
* const agent = new Agent({ instructions: 'You are helpful.' })
|
|
87
|
+
* const agent = new Agent({ client, instructions: 'You are helpful.' })
|
|
85
88
|
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
86
89
|
* .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
87
90
|
* .withStt(new DeepgramSTT({ apiKey: '...', model: 'nova-2' }));
|
|
91
|
+
*
|
|
92
|
+
* const session = agent.createSession({
|
|
93
|
+
* name: `conversation-${Date.now()}`,
|
|
94
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
95
|
+
* agentUid: '1',
|
|
96
|
+
* remoteUids: ['100'],
|
|
97
|
+
* });
|
|
88
98
|
* ```
|
|
89
99
|
*/
|
|
90
|
-
export declare class Agent<TTSSampleRate extends number = number> {
|
|
91
|
-
private
|
|
100
|
+
export declare class Agent<TTSSampleRate extends number = number, TArea extends AgoraArea = AgoraArea> {
|
|
101
|
+
private _client;
|
|
92
102
|
private _pipelineId?;
|
|
93
103
|
private _llm?;
|
|
94
104
|
private _tts?;
|
|
@@ -109,13 +119,13 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
109
119
|
private _rtc?;
|
|
110
120
|
private _fillerWords?;
|
|
111
121
|
private _greetingConfigs?;
|
|
112
|
-
constructor(options
|
|
122
|
+
constructor(options: AgentOptions<TArea>);
|
|
113
123
|
/**
|
|
114
124
|
* Returns a new Agent with the specified LLM vendor.
|
|
115
125
|
*
|
|
116
126
|
* @param vendor - LLM vendor instance (e.g., new OpenAI({ apiKey: '...', model: 'gpt-4', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
117
127
|
*/
|
|
118
|
-
withLlm(vendor:
|
|
128
|
+
withLlm(vendor: LlmVendor): Agent<TTSSampleRate, TArea>;
|
|
119
129
|
/**
|
|
120
130
|
* Returns a new Agent with the specified TTS vendor.
|
|
121
131
|
*
|
|
@@ -125,7 +135,7 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
125
135
|
* @param vendor - TTS vendor instance (e.g., new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
126
136
|
* @returns Agent with tracked sample rate type
|
|
127
137
|
*/
|
|
128
|
-
withTts<SR extends number>(vendor:
|
|
138
|
+
withTts<SR extends number>(vendor: TtsVendor<SR>): Agent<SR, TArea>;
|
|
129
139
|
/**
|
|
130
140
|
* Returns a new Agent with the specified STT vendor.
|
|
131
141
|
*
|
|
@@ -141,7 +151,7 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
141
151
|
* }));
|
|
142
152
|
* ```
|
|
143
153
|
*/
|
|
144
|
-
withStt(vendor:
|
|
154
|
+
withStt(vendor: SttVendor): Agent<TTSSampleRate, TArea>;
|
|
145
155
|
/**
|
|
146
156
|
* Returns a new Agent with the specified MLLM vendor.
|
|
147
157
|
*
|
|
@@ -156,7 +166,7 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
156
166
|
*
|
|
157
167
|
* @param vendor - MLLM vendor instance (e.g., new VertexAI({ model: '...', projectId: '...', ... }))
|
|
158
168
|
*/
|
|
159
|
-
withMllm(vendor: BaseMLLM): Agent<TTSSampleRate>;
|
|
169
|
+
withMllm(vendor: BaseMLLM): Agent<TTSSampleRate, TArea>;
|
|
160
170
|
/**
|
|
161
171
|
* Returns a new Agent with the specified Avatar vendor.
|
|
162
172
|
*
|
|
@@ -180,7 +190,8 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
180
190
|
* ```typescript
|
|
181
191
|
* import { HeyGenAvatar, ElevenLabsTTS } from 'agora-agents';
|
|
182
192
|
*
|
|
183
|
-
* const
|
|
193
|
+
* const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
|
|
194
|
+
* const agent = new Agent({ client })
|
|
184
195
|
* .withTts(new ElevenLabsTTS({
|
|
185
196
|
* key: '...',
|
|
186
197
|
* modelId: '...',
|
|
@@ -195,27 +206,27 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
195
206
|
* }));
|
|
196
207
|
* ```
|
|
197
208
|
*/
|
|
198
|
-
withAvatar<RequiredSR extends number>(this: Agent<RequiredSR>, vendor:
|
|
209
|
+
withAvatar<RequiredSR extends number>(this: Agent<RequiredSR, TArea>, vendor: AvatarVendor<RequiredSR>): Agent<RequiredSR, TArea>;
|
|
199
210
|
/**
|
|
200
211
|
* Returns a new Agent with the specified turn detection configuration.
|
|
201
212
|
*/
|
|
202
|
-
withTurnDetection(config: TurnDetectionConfig): Agent<TTSSampleRate>;
|
|
213
|
+
withTurnDetection(config: TurnDetectionConfig): Agent<TTSSampleRate, TArea>;
|
|
203
214
|
/**
|
|
204
215
|
* Returns a new Agent with unified interruption control configured.
|
|
205
216
|
*/
|
|
206
|
-
withInterruption(config: InterruptionConfig): Agent<TTSSampleRate>;
|
|
217
|
+
withInterruption(config: InterruptionConfig): Agent<TTSSampleRate, TArea>;
|
|
207
218
|
/**
|
|
208
219
|
* Returns a new Agent with the specified instructions.
|
|
209
220
|
*
|
|
210
221
|
* @deprecated Configure system messages on the LLM vendor instead.
|
|
211
222
|
*/
|
|
212
|
-
withInstructions(instructions: string): Agent<TTSSampleRate>;
|
|
223
|
+
withInstructions(instructions: string): Agent<TTSSampleRate, TArea>;
|
|
213
224
|
/**
|
|
214
225
|
* Returns a new Agent with the specified greeting message.
|
|
215
226
|
*
|
|
216
227
|
* @deprecated Configure the greeting on the LLM or MLLM vendor instead.
|
|
217
228
|
*/
|
|
218
|
-
withGreeting(greeting: string): Agent<TTSSampleRate>;
|
|
229
|
+
withGreeting(greeting: string): Agent<TTSSampleRate, TArea>;
|
|
219
230
|
/**
|
|
220
231
|
* Returns a new Agent with the specified greeting playback configuration.
|
|
221
232
|
*
|
|
@@ -224,35 +235,31 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
224
235
|
*
|
|
225
236
|
* @deprecated Configure greeting playback on the LLM vendor instead.
|
|
226
237
|
*/
|
|
227
|
-
withGreetingConfigs(configs: LlmGreetingConfigs): Agent<TTSSampleRate>;
|
|
228
|
-
/**
|
|
229
|
-
* Returns a new Agent with the specified name.
|
|
230
|
-
*/
|
|
231
|
-
withName(name: string): Agent<TTSSampleRate>;
|
|
238
|
+
withGreetingConfigs(configs: LlmGreetingConfigs): Agent<TTSSampleRate, TArea>;
|
|
232
239
|
/**
|
|
233
240
|
* Returns a new Agent with the specified SAL (Selective Attention Locking) configuration.
|
|
234
241
|
*/
|
|
235
|
-
withSal(config: SalConfig): Agent<TTSSampleRate>;
|
|
242
|
+
withSal(config: SalConfig): Agent<TTSSampleRate, TArea>;
|
|
236
243
|
/**
|
|
237
244
|
* Returns a new Agent with the specified advanced features configuration.
|
|
238
245
|
*
|
|
239
246
|
* Use this to enable features like RTM and others.
|
|
240
247
|
*/
|
|
241
|
-
withAdvancedFeatures(features: AdvancedFeatures): Agent<TTSSampleRate>;
|
|
248
|
+
withAdvancedFeatures(features: AdvancedFeatures): Agent<TTSSampleRate, TArea>;
|
|
242
249
|
/**
|
|
243
250
|
* Returns a new Agent with MCP tool invocation enabled or disabled.
|
|
244
251
|
*/
|
|
245
|
-
withTools(enabled?: boolean): Agent<TTSSampleRate>;
|
|
252
|
+
withTools(enabled?: boolean): Agent<TTSSampleRate, TArea>;
|
|
246
253
|
/**
|
|
247
254
|
* Returns a new Agent with the specified session parameters.
|
|
248
255
|
*
|
|
249
256
|
* Use this to configure silence behaviour, graceful hang-up, data channel, and more.
|
|
250
257
|
*/
|
|
251
|
-
withParameters(parameters: SessionParamsInput): Agent<TTSSampleRate>;
|
|
258
|
+
withParameters(parameters: SessionParamsInput): Agent<TTSSampleRate, TArea>;
|
|
252
259
|
/**
|
|
253
260
|
* Returns a new Agent with the specified RTC audio scenario.
|
|
254
261
|
*/
|
|
255
|
-
withAudioScenario(audioScenario: ParametersAudioScenario): Agent<TTSSampleRate>;
|
|
262
|
+
withAudioScenario(audioScenario: ParametersAudioScenario): Agent<TTSSampleRate, TArea>;
|
|
256
263
|
/**
|
|
257
264
|
* Returns a new Agent with the specified failure message.
|
|
258
265
|
*
|
|
@@ -260,40 +267,36 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
260
267
|
*
|
|
261
268
|
* @deprecated Configure the failure message on the LLM or MLLM vendor instead.
|
|
262
269
|
*/
|
|
263
|
-
withFailureMessage(message: string): Agent<TTSSampleRate>;
|
|
270
|
+
withFailureMessage(message: string): Agent<TTSSampleRate, TArea>;
|
|
264
271
|
/**
|
|
265
272
|
* Returns a new Agent with the specified maximum conversation history length.
|
|
266
273
|
* Applies to the standard LLM pipeline only; the v2.7 MLLM core schema has no max_history field.
|
|
267
274
|
*
|
|
268
275
|
* @deprecated Configure max history on the LLM vendor instead.
|
|
269
276
|
*/
|
|
270
|
-
withMaxHistory(maxHistory: number): Agent<TTSSampleRate>;
|
|
277
|
+
withMaxHistory(maxHistory: number): Agent<TTSSampleRate, TArea>;
|
|
271
278
|
/**
|
|
272
279
|
* Returns a new Agent with the specified geofence configuration.
|
|
273
280
|
*
|
|
274
281
|
* Restricts which geographic regions the agent's backend servers may run in.
|
|
275
282
|
*/
|
|
276
|
-
withGeofence(geofence: GeofenceConfig): Agent<TTSSampleRate>;
|
|
283
|
+
withGeofence(geofence: GeofenceConfig): Agent<TTSSampleRate, TArea>;
|
|
277
284
|
/**
|
|
278
285
|
* Returns a new Agent with the specified custom labels.
|
|
279
286
|
*
|
|
280
287
|
* Labels are key-value pairs attached to the agent and returned in notification callbacks.
|
|
281
288
|
*/
|
|
282
|
-
withLabels(labels: Labels): Agent<TTSSampleRate>;
|
|
289
|
+
withLabels(labels: Labels): Agent<TTSSampleRate, TArea>;
|
|
283
290
|
/**
|
|
284
291
|
* Returns a new Agent with the specified RTC configuration.
|
|
285
292
|
*/
|
|
286
|
-
withRtc(rtc: RtcConfig): Agent<TTSSampleRate>;
|
|
293
|
+
withRtc(rtc: RtcConfig): Agent<TTSSampleRate, TArea>;
|
|
287
294
|
/**
|
|
288
295
|
* Returns a new Agent with the specified filler words configuration.
|
|
289
296
|
*
|
|
290
297
|
* Filler words are played while the agent waits for the LLM to respond.
|
|
291
298
|
*/
|
|
292
|
-
withFillerWords(fillerWords: FillerWordsConfig): Agent<TTSSampleRate>;
|
|
293
|
-
/**
|
|
294
|
-
* Get the agent name.
|
|
295
|
-
*/
|
|
296
|
-
get name(): string | undefined;
|
|
299
|
+
withFillerWords(fillerWords: FillerWordsConfig): Agent<TTSSampleRate, TArea>;
|
|
297
300
|
/**
|
|
298
301
|
* Get the AI Studio pipeline ID used as this agent's base configuration.
|
|
299
302
|
*/
|
|
@@ -388,18 +391,19 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
388
391
|
/**
|
|
389
392
|
* Creates a new session from this agent configuration.
|
|
390
393
|
*
|
|
391
|
-
* @param client - The Agora client instance (must have appId and appCertificate properties)
|
|
392
394
|
* @param options - Session connection options
|
|
393
395
|
* @returns A new AgentSession instance ready to start
|
|
394
396
|
*
|
|
395
397
|
* @example
|
|
396
398
|
* ```typescript
|
|
397
|
-
* const
|
|
398
|
-
*
|
|
399
|
-
* .
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
399
|
+
* const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
|
|
400
|
+
* const agent = new Agent({ client })
|
|
401
|
+
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
402
|
+
* .withTts(new MiniMaxTTS({ model: 'speech_2_6_turbo', voiceId: 'English_captivating_female1' }));
|
|
403
|
+
*
|
|
404
|
+
* const session = agent.createSession({
|
|
405
|
+
* name: `conversation-${Date.now()}`,
|
|
406
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
403
407
|
* agentUid: '1',
|
|
404
408
|
* remoteUids: ['100'],
|
|
405
409
|
* idleTimeout: 120,
|
|
@@ -408,10 +412,7 @@ export declare class Agent<TTSSampleRate extends number = number> {
|
|
|
408
412
|
* const agentId = await session.start();
|
|
409
413
|
* ```
|
|
410
414
|
*/
|
|
411
|
-
createSession(
|
|
412
|
-
readonly appId: string;
|
|
413
|
-
readonly appCertificate?: string;
|
|
414
|
-
}, options: SessionOptions): AgentSession;
|
|
415
|
+
createSession(options: SessionOptions): AgentSession;
|
|
415
416
|
/**
|
|
416
417
|
* Converts the Agent configuration to the Fern request properties format.
|
|
417
418
|
*
|
|
@@ -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.
|
|
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([
|
|
@@ -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.
|
|
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
|
|
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
|
-
|
|
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
|
|
558
|
-
*
|
|
559
|
-
* .
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
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(
|
|
572
|
-
var _a
|
|
573
|
-
const name = (
|
|
574
|
-
return new AgentSession_js_1.AgentSession(Object.assign(Object.assign({ client, agent: this, appId:
|
|
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
|
|
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
|
-
|
|
618
|
-
|
|
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((
|
|
653
|
-
const allowMissingCategories = new Set((
|
|
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);
|
|
@@ -673,7 +675,7 @@ class Agent {
|
|
|
673
675
|
? this._llm.system_messages
|
|
674
676
|
: this._instructions
|
|
675
677
|
? [{ role: "system", content: this._instructions }]
|
|
676
|
-
: undefined, greeting_message: (
|
|
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;
|
|
677
679
|
const turnDetectionConfig = this._resolveTurnDetectionConfig();
|
|
678
680
|
const asrConfig = this._stt !== undefined || !allowMissingAsr
|
|
679
681
|
? this._resolveAsrConfig(turnDetectionConfig)
|
|
@@ -691,8 +693,7 @@ class Agent {
|
|
|
691
693
|
* If a new private field is added to Agent, it MUST also be added here.
|
|
692
694
|
*/
|
|
693
695
|
_clone() {
|
|
694
|
-
const newAgent = new Agent();
|
|
695
|
-
newAgent._name = this._name;
|
|
696
|
+
const newAgent = new Agent({ client: this._client });
|
|
696
697
|
newAgent._pipelineId = this._pipelineId;
|
|
697
698
|
newAgent._llm = this._llm;
|
|
698
699
|
newAgent._tts = this._tts;
|