agora-agents 2.2.0 → 2.4.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.
- package/README.md +48 -26
- package/dist/cjs/AgoraPoolClient.d.ts +9 -6
- package/dist/cjs/AgoraPoolClient.js +1 -0
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/Client.js +8 -16
- package/dist/cjs/agentkit/Agent.d.ts +52 -51
- package/dist/cjs/agentkit/Agent.js +46 -44
- package/dist/cjs/agentkit/AgentSession.d.ts +11 -10
- package/dist/cjs/agentkit/AgentSession.js +12 -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 +43 -4
- package/dist/cjs/agentkit/avatar-types.js +52 -2
- package/dist/cjs/agentkit/index.d.ts +12 -9
- package/dist/cjs/agentkit/index.js +32 -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 +47 -9
- package/dist/cjs/agentkit/vendors/avatar.d.ts +9 -6
- package/dist/cjs/agentkit/vendors/avatar.js +9 -6
- package/dist/cjs/agentkit/vendors/base.d.ts +42 -5
- package/dist/cjs/agentkit/vendors/base.js +64 -6
- package/dist/cjs/agentkit/vendors/cn.d.ts +269 -0
- package/dist/cjs/agentkit/vendors/cn.js +313 -0
- package/dist/cjs/agentkit/vendors/llm.d.ts +1 -1
- package/dist/cjs/agentkit/vendors/llm.js +13 -3
- package/dist/cjs/agentkit/vendors/mllm.d.ts +8 -4
- package/dist/cjs/agentkit/vendors/mllm.js +10 -6
- package/dist/cjs/agentkit/vendors/stt.d.ts +31 -0
- package/dist/cjs/agentkit/vendors/stt.js +31 -1
- package/dist/cjs/agentkit/vendors/tts.d.ts +63 -3
- package/dist/cjs/agentkit/vendors/tts.js +42 -1
- package/dist/cjs/api/resources/agents/client/requests/ListAgentsRequest.d.ts +2 -3
- package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.d.ts +23 -3
- package/dist/cjs/api/resources/agents/client/requests/StartAgentsRequest.js +12 -0
- package/dist/cjs/api/resources/agents/types/GetHistoryAgentsResponse.d.ts +6 -0
- package/dist/cjs/api/resources/agents/types/index.d.ts +0 -1
- package/dist/cjs/api/resources/agents/types/index.js +0 -1
- package/dist/cjs/api/types/Asr.d.ts +19 -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/GenericTts.d.ts +13 -0
- package/dist/cjs/api/types/GenericTts.js +3 -0
- package/dist/cjs/api/types/GenericTtsParams.d.ts +21 -0
- package/dist/cjs/api/types/GenericTtsParams.js +3 -0
- package/dist/cjs/api/types/Llm.d.ts +24 -1
- package/dist/cjs/api/types/Llm.js +8 -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/SpatiusAvatarParams.d.ts +23 -0
- package/dist/cjs/api/types/SpatiusAvatarParams.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 +22 -1
- package/dist/cjs/api/types/XAiAsr.d.ts +10 -0
- package/dist/cjs/api/types/XAiAsr.js +3 -0
- package/dist/cjs/api/types/XAiAsrParams.d.ts +15 -0
- package/dist/cjs/api/types/XAiAsrParams.js +3 -0
- package/dist/cjs/api/types/XAiTts.d.ts +9 -0
- package/dist/cjs/api/types/XAiTts.js +3 -0
- package/dist/cjs/api/types/XAiTtsParams.d.ts +15 -0
- package/dist/cjs/api/types/XAiTtsParams.js +3 -0
- 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 +27 -0
- package/dist/cjs/api/types/index.js +27 -0
- package/dist/cjs/core/base64.js +1 -5
- 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 +31 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/AgoraPoolClient.d.mts +9 -6
- package/dist/esm/AgoraPoolClient.mjs +1 -0
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/Client.mjs +8 -16
- package/dist/esm/agentkit/Agent.d.mts +52 -51
- package/dist/esm/agentkit/Agent.mjs +46 -44
- package/dist/esm/agentkit/AgentSession.d.mts +11 -10
- package/dist/esm/agentkit/AgentSession.mjs +13 -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 +43 -4
- package/dist/esm/agentkit/avatar-types.mjs +50 -2
- package/dist/esm/agentkit/index.d.mts +12 -9
- package/dist/esm/agentkit/index.mjs +5 -4
- 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 +47 -9
- package/dist/esm/agentkit/vendors/avatar.d.mts +9 -6
- package/dist/esm/agentkit/vendors/avatar.mjs +9 -6
- package/dist/esm/agentkit/vendors/base.d.mts +42 -5
- package/dist/esm/agentkit/vendors/base.mjs +59 -5
- package/dist/esm/agentkit/vendors/cn.d.mts +269 -0
- package/dist/esm/agentkit/vendors/cn.mjs +291 -0
- package/dist/esm/agentkit/vendors/llm.d.mts +1 -1
- package/dist/esm/agentkit/vendors/llm.mjs +13 -3
- package/dist/esm/agentkit/vendors/mllm.d.mts +8 -4
- package/dist/esm/agentkit/vendors/mllm.mjs +10 -6
- package/dist/esm/agentkit/vendors/stt.d.mts +31 -0
- package/dist/esm/agentkit/vendors/stt.mjs +29 -0
- package/dist/esm/agentkit/vendors/tts.d.mts +63 -3
- package/dist/esm/agentkit/vendors/tts.mjs +39 -0
- package/dist/esm/api/resources/agents/client/requests/ListAgentsRequest.d.mts +2 -3
- package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.d.mts +23 -3
- package/dist/esm/api/resources/agents/client/requests/StartAgentsRequest.mjs +12 -0
- package/dist/esm/api/resources/agents/types/GetHistoryAgentsResponse.d.mts +6 -0
- package/dist/esm/api/resources/agents/types/index.d.mts +0 -1
- package/dist/esm/api/resources/agents/types/index.mjs +0 -1
- package/dist/esm/api/types/Asr.d.mts +19 -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/GenericTts.d.mts +13 -0
- package/dist/esm/api/types/GenericTts.mjs +2 -0
- package/dist/esm/api/types/GenericTtsParams.d.mts +21 -0
- package/dist/esm/api/types/GenericTtsParams.mjs +2 -0
- package/dist/esm/api/types/Llm.d.mts +24 -1
- package/dist/esm/api/types/Llm.mjs +8 -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/SpatiusAvatarParams.d.mts +23 -0
- package/dist/esm/api/types/SpatiusAvatarParams.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 +22 -1
- package/dist/esm/api/types/XAiAsr.d.mts +10 -0
- package/dist/esm/api/types/XAiAsr.mjs +2 -0
- package/dist/esm/api/types/XAiAsrParams.d.mts +15 -0
- package/dist/esm/api/types/XAiAsrParams.mjs +2 -0
- package/dist/esm/api/types/XAiTts.d.mts +9 -0
- package/dist/esm/api/types/XAiTts.mjs +2 -0
- package/dist/esm/api/types/XAiTtsParams.d.mts +15 -0
- package/dist/esm/api/types/XAiTtsParams.mjs +2 -0
- 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 +27 -0
- package/dist/esm/api/types/index.mjs +27 -0
- package/dist/esm/core/base64.mjs +1 -5
- 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/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/dist/cjs/api/resources/agents/types/ListAgentsRequestState.d.ts +0 -10
- package/dist/cjs/api/resources/agents/types/ListAgentsRequestState.js +0 -13
- package/dist/esm/api/resources/agents/types/ListAgentsRequestState.d.mts +0 -10
- package/dist/esm/api/resources/agents/types/ListAgentsRequestState.mjs +0 -10
|
@@ -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.mjs";
|
|
7
9
|
import type * as Agora from "../api/index.mjs";
|
|
8
|
-
import type { AgoraClient } from "../Client.mjs";
|
|
9
10
|
import { AgentSession } from "./AgentSession.mjs";
|
|
11
|
+
import type { AgoraArea } from "./area.mjs";
|
|
12
|
+
import type { AvatarVendor, LlmVendor, SttVendor, TtsVendor } from "./region-vendors.mjs";
|
|
10
13
|
import type { AdvancedFeatures, AvatarConfig, FillerWordsConfig, GeofenceConfig, InterruptionConfig, Labels, LlmConfig, LlmGreetingConfigs, MllmConfig, ParametersAudioScenario, RtcConfig, SalConfig, SessionOptions, SessionParamsInput, SttConfig, TtsConfig, TurnDetectionConfig } from "./types.mjs";
|
|
11
|
-
import type {
|
|
14
|
+
import type { BaseMLLM } from "./vendors/base.mjs";
|
|
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
|
*
|
|
@@ -2,9 +2,12 @@
|
|
|
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 { Area } from "../core/domain/index.mjs";
|
|
7
9
|
import { AgentSession } from "./AgentSession.mjs";
|
|
10
|
+
import { AudioScenario } from "./constants.mjs";
|
|
8
11
|
import { generateConvoAIToken } from "./token.mjs";
|
|
9
12
|
const DEFAULT_TURN_DETECTION_LANGUAGE = "en-US";
|
|
10
13
|
const INTERACTION_LANGUAGES = new Set([
|
|
@@ -59,15 +62,22 @@ function assertTurnDetectionLanguage(value) {
|
|
|
59
62
|
* import { Agent, OpenAI, MicrosoftTTS, DeepgramSTT } from 'agora-agents';
|
|
60
63
|
*
|
|
61
64
|
* // Use the fluent builder pattern to configure vendors
|
|
62
|
-
* const agent = new Agent({ instructions: 'You are helpful.' })
|
|
65
|
+
* const agent = new Agent({ client, instructions: 'You are helpful.' })
|
|
63
66
|
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
64
67
|
* .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
65
68
|
* .withStt(new DeepgramSTT({ apiKey: '...', model: 'nova-2' }));
|
|
69
|
+
*
|
|
70
|
+
* const session = agent.createSession({
|
|
71
|
+
* name: `conversation-${Date.now()}`,
|
|
72
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
73
|
+
* agentUid: '1',
|
|
74
|
+
* remoteUids: ['100'],
|
|
75
|
+
* });
|
|
66
76
|
* ```
|
|
67
77
|
*/
|
|
68
78
|
export class Agent {
|
|
69
|
-
constructor(options
|
|
70
|
-
this.
|
|
79
|
+
constructor(options) {
|
|
80
|
+
this._client = options.client;
|
|
71
81
|
this._pipelineId = options.pipelineId;
|
|
72
82
|
this._instructions = options.instructions;
|
|
73
83
|
this._greeting = options.greeting;
|
|
@@ -202,7 +212,8 @@ export class Agent {
|
|
|
202
212
|
* ```typescript
|
|
203
213
|
* import { HeyGenAvatar, ElevenLabsTTS } from 'agora-agents';
|
|
204
214
|
*
|
|
205
|
-
* const
|
|
215
|
+
* const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
|
|
216
|
+
* const agent = new Agent({ client })
|
|
206
217
|
* .withTts(new ElevenLabsTTS({
|
|
207
218
|
* key: '...',
|
|
208
219
|
* modelId: '...',
|
|
@@ -273,14 +284,6 @@ export class Agent {
|
|
|
273
284
|
newAgent._greetingConfigs = configs;
|
|
274
285
|
return newAgent;
|
|
275
286
|
}
|
|
276
|
-
/**
|
|
277
|
-
* Returns a new Agent with the specified name.
|
|
278
|
-
*/
|
|
279
|
-
withName(name) {
|
|
280
|
-
const newAgent = this._clone();
|
|
281
|
-
newAgent._name = name;
|
|
282
|
-
return newAgent;
|
|
283
|
-
}
|
|
284
287
|
/**
|
|
285
288
|
* Returns a new Agent with the specified SAL (Selective Attention Locking) configuration.
|
|
286
289
|
*/
|
|
@@ -386,12 +389,6 @@ export class Agent {
|
|
|
386
389
|
newAgent._fillerWords = fillerWords;
|
|
387
390
|
return newAgent;
|
|
388
391
|
}
|
|
389
|
-
/**
|
|
390
|
-
* Get the agent name.
|
|
391
|
-
*/
|
|
392
|
-
get name() {
|
|
393
|
-
return this._name;
|
|
394
|
-
}
|
|
395
392
|
/**
|
|
396
393
|
* Get the AI Studio pipeline ID used as this agent's base configuration.
|
|
397
394
|
*/
|
|
@@ -519,7 +516,7 @@ export class Agent {
|
|
|
519
516
|
*/
|
|
520
517
|
get config() {
|
|
521
518
|
return {
|
|
522
|
-
|
|
519
|
+
client: this._client,
|
|
523
520
|
pipelineId: this._pipelineId,
|
|
524
521
|
instructions: this._instructions,
|
|
525
522
|
turnDetection: this._turnDetection,
|
|
@@ -545,18 +542,19 @@ export class Agent {
|
|
|
545
542
|
/**
|
|
546
543
|
* Creates a new session from this agent configuration.
|
|
547
544
|
*
|
|
548
|
-
* @param client - The Agora client instance (must have appId and appCertificate properties)
|
|
549
545
|
* @param options - Session connection options
|
|
550
546
|
* @returns A new AgentSession instance ready to start
|
|
551
547
|
*
|
|
552
548
|
* @example
|
|
553
549
|
* ```typescript
|
|
554
|
-
* const
|
|
555
|
-
*
|
|
556
|
-
* .
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
550
|
+
* const client = new AgoraClient({ area: Area.US, appId: '...', appCertificate: '...' });
|
|
551
|
+
* const agent = new Agent({ client })
|
|
552
|
+
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
553
|
+
* .withTts(new MiniMaxTTS({ model: 'speech_2_6_turbo', voiceId: 'English_captivating_female1' }));
|
|
554
|
+
*
|
|
555
|
+
* const session = agent.createSession({
|
|
556
|
+
* name: `conversation-${Date.now()}`,
|
|
557
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
560
558
|
* agentUid: '1',
|
|
561
559
|
* remoteUids: ['100'],
|
|
562
560
|
* idleTimeout: 120,
|
|
@@ -565,10 +563,10 @@ export class Agent {
|
|
|
565
563
|
* const agentId = await session.start();
|
|
566
564
|
* ```
|
|
567
565
|
*/
|
|
568
|
-
createSession(
|
|
569
|
-
var _a
|
|
570
|
-
const name = (
|
|
571
|
-
return new AgentSession(Object.assign(Object.assign({ client, agent: this, appId:
|
|
566
|
+
createSession(options) {
|
|
567
|
+
var _a;
|
|
568
|
+
const name = (_a = options.name) !== null && _a !== void 0 ? _a : `agent-${Date.now()}`;
|
|
569
|
+
return new AgentSession(Object.assign(Object.assign({ client: this._client, agent: this, appId: this._client.appId, appCertificate: this._client.appCertificate }, options), { name }));
|
|
572
570
|
}
|
|
573
571
|
/**
|
|
574
572
|
* Converts the Agent configuration to the Fern request properties format.
|
|
@@ -578,7 +576,7 @@ export class Agent {
|
|
|
578
576
|
* and RTM privileges (required for RTM-enabled sessions).
|
|
579
577
|
*/
|
|
580
578
|
toProperties(opts) {
|
|
581
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
579
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
582
580
|
// In MLLM mode the backend handles audio end-to-end; LLM, TTS, and ASR
|
|
583
581
|
// are not required.
|
|
584
582
|
const isMllmMode = ((_a = this._mllm) === null || _a === void 0 ? void 0 : _a.enable) === true || this._mllm !== undefined;
|
|
@@ -611,8 +609,13 @@ export class Agent {
|
|
|
611
609
|
// When RTM is enabled, data_channel must also be 'rtm' for the client
|
|
612
610
|
// to receive transcripts and state events. Default it automatically so
|
|
613
611
|
// callers only need to set advancedFeatures.enable_rtm: true.
|
|
614
|
-
|
|
615
|
-
|
|
612
|
+
let resolvedParameters = this._parameters;
|
|
613
|
+
if (((_b = this._advancedFeatures) === null || _b === void 0 ? void 0 : _b.enable_rtm) && !(resolvedParameters === null || resolvedParameters === void 0 ? void 0 : resolvedParameters.data_channel)) {
|
|
614
|
+
resolvedParameters = Object.assign(Object.assign({}, resolvedParameters), { data_channel: "rtm" });
|
|
615
|
+
}
|
|
616
|
+
if ((resolvedParameters === null || resolvedParameters === void 0 ? void 0 : resolvedParameters.audio_scenario) === undefined) {
|
|
617
|
+
resolvedParameters = Object.assign(Object.assign({}, resolvedParameters), { audio_scenario: AudioScenario.Default });
|
|
618
|
+
}
|
|
616
619
|
const base = {
|
|
617
620
|
channel: opts.channel,
|
|
618
621
|
token,
|
|
@@ -646,8 +649,8 @@ export class Agent {
|
|
|
646
649
|
}
|
|
647
650
|
return Object.assign(Object.assign({}, base), { mllm: mllmConfig, turn_detection: this._turnDetection });
|
|
648
651
|
}
|
|
649
|
-
const skipCategories = new Set((
|
|
650
|
-
const allowMissingCategories = new Set((
|
|
652
|
+
const skipCategories = new Set((_c = opts.skipVendorValidationCategories) !== null && _c !== void 0 ? _c : []);
|
|
653
|
+
const allowMissingCategories = new Set((_d = opts.allowMissingVendorCategories) !== null && _d !== void 0 ? _d : []);
|
|
651
654
|
if (opts.skipVendorValidation) {
|
|
652
655
|
for (const category of ["asr", "llm", "tts"]) {
|
|
653
656
|
skipCategories.add(category);
|
|
@@ -670,7 +673,7 @@ export class Agent {
|
|
|
670
673
|
? this._llm.system_messages
|
|
671
674
|
: this._instructions
|
|
672
675
|
? [{ role: "system", content: this._instructions }]
|
|
673
|
-
: undefined, greeting_message: (
|
|
676
|
+
: undefined, greeting_message: (_e = this._llm.greeting_message) !== null && _e !== void 0 ? _e : this._greeting, greeting_configs: (_f = this._llm.greeting_configs) !== null && _f !== void 0 ? _f : this._greetingConfigs, failure_message: (_g = this._llm.failure_message) !== null && _g !== void 0 ? _g : this._failureMessage, max_history: (_h = this._llm.max_history) !== null && _h !== void 0 ? _h : this._maxHistory }) : undefined;
|
|
674
677
|
const turnDetectionConfig = this._resolveTurnDetectionConfig();
|
|
675
678
|
const asrConfig = this._stt !== undefined || !allowMissingAsr
|
|
676
679
|
? this._resolveAsrConfig(turnDetectionConfig)
|
|
@@ -688,8 +691,7 @@ export class Agent {
|
|
|
688
691
|
* If a new private field is added to Agent, it MUST also be added here.
|
|
689
692
|
*/
|
|
690
693
|
_clone() {
|
|
691
|
-
const newAgent = new Agent();
|
|
692
|
-
newAgent._name = this._name;
|
|
694
|
+
const newAgent = new Agent({ client: this._client });
|
|
693
695
|
newAgent._pipelineId = this._pipelineId;
|
|
694
696
|
newAgent._llm = this._llm;
|
|
695
697
|
newAgent._tts = this._tts;
|
|
@@ -713,11 +715,11 @@ export class Agent {
|
|
|
713
715
|
return newAgent;
|
|
714
716
|
}
|
|
715
717
|
_resolveAsrConfig(turnDetectionConfig) {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
718
|
+
const asrConfig = this._stt !== undefined
|
|
719
|
+
? Object.assign({}, this._stt)
|
|
720
|
+
: {
|
|
721
|
+
vendor: this._client.area === Area.CN ? "fengming" : "ares",
|
|
722
|
+
};
|
|
721
723
|
asrConfig.language = turnDetectionConfig.language;
|
|
722
724
|
return Object.keys(asrConfig).length > 0 ? asrConfig : undefined;
|
|
723
725
|
}
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* This class provides a high-level interface for managing agent sessions,
|
|
5
5
|
* including starting, stopping, and interacting with the agent.
|
|
6
6
|
*/
|
|
7
|
+
import type { AgoraClient } from "../AgoraPoolClient.mjs";
|
|
7
8
|
import type { AgentManagementClient } from "../api/resources/agentManagement/client/Client.mjs";
|
|
8
9
|
import type { AgentsClient } from "../api/resources/agents/client/Client.mjs";
|
|
9
|
-
import type { AgoraClient } from "../Client.mjs";
|
|
10
10
|
import type { Agent } from "./Agent.mjs";
|
|
11
|
+
import type { AgoraArea } from "./area.mjs";
|
|
11
12
|
import { type PresetInput } from "./presets.mjs";
|
|
12
13
|
import type { AgentConfigUpdate, ConversationHistory, ConversationTurns, GetTurnsOptions, SayOptions, SessionInfo, ThinkOptions, ThinkResponse } from "./types.mjs";
|
|
13
14
|
/**
|
|
@@ -23,14 +24,14 @@ export type AgentSessionEventHandler<T = unknown> = (data: T) => void;
|
|
|
23
24
|
*/
|
|
24
25
|
export interface AgentSessionOptions {
|
|
25
26
|
/** The Agora client instance */
|
|
26
|
-
client: AgoraClient
|
|
27
|
+
client: AgoraClient<AgoraArea>;
|
|
27
28
|
/** The agent configuration */
|
|
28
|
-
agent: Agent
|
|
29
|
+
agent: Agent<number, AgoraArea>;
|
|
29
30
|
/** The App ID */
|
|
30
31
|
appId: string;
|
|
31
32
|
/** The App Certificate — enables automatic RTC token generation when starting sessions */
|
|
32
33
|
appCertificate?: string;
|
|
33
|
-
/** Unique name
|
|
34
|
+
/** Unique agent instance name (set via {@link Agent.createSession}) */
|
|
34
35
|
name: string;
|
|
35
36
|
/** The channel to join */
|
|
36
37
|
channel: string;
|
|
@@ -73,18 +74,18 @@ export interface AgentSessionOptions {
|
|
|
73
74
|
*
|
|
74
75
|
* const client = new AgoraClient({
|
|
75
76
|
* area: Area.US,
|
|
76
|
-
|
|
77
77
|
* appId: '...',
|
|
78
78
|
* appCertificate: '...',
|
|
79
79
|
* });
|
|
80
80
|
*
|
|
81
|
-
* const agent = new Agent({
|
|
81
|
+
* const agent = new Agent({ client, instructions: 'You are a helpful voice assistant.' })
|
|
82
82
|
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
83
83
|
* .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
84
84
|
* .withStt(new DeepgramSTT({ apiKey: '...', language: 'en-US' }));
|
|
85
85
|
*
|
|
86
|
-
* const session = agent.createSession(
|
|
87
|
-
*
|
|
86
|
+
* const session = agent.createSession({
|
|
87
|
+
* name: `conversation-${Date.now()}`,
|
|
88
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
88
89
|
* agentUid: '1',
|
|
89
90
|
* remoteUids: ['100'],
|
|
90
91
|
* });
|
|
@@ -137,7 +138,7 @@ export declare class AgentSession {
|
|
|
137
138
|
/**
|
|
138
139
|
* The agent configuration.
|
|
139
140
|
*/
|
|
140
|
-
get agent(): Agent
|
|
141
|
+
get agent(): Agent<number, AgoraArea>;
|
|
141
142
|
/**
|
|
142
143
|
* The App ID for this session.
|
|
143
144
|
*/
|
|
@@ -184,7 +185,7 @@ export declare class AgentSession {
|
|
|
184
185
|
* Fills session-derived avatar fields and generates avatar ConvoAI tokens.
|
|
185
186
|
*
|
|
186
187
|
* Token management is gated to vendors that publish a separate RTC video
|
|
187
|
-
* identity (HeyGen, LiveAvatar, Generic). Other vendors (Akool, Anam) do
|
|
188
|
+
* identity (HeyGen, LiveAvatar, Generic, SenseTime). Other vendors (Akool, Anam) do
|
|
188
189
|
* not run a separate publisher and never receive an auto-generated token.
|
|
189
190
|
*/
|
|
190
191
|
private _enrichAvatarParams;
|
|
@@ -14,7 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
import { AgoraError } from "../errors/index.mjs";
|
|
17
|
-
import { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
|
|
17
|
+
import { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, isSensetimeAvatar, isSpatiusAvatar, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
|
|
18
18
|
import { getPresetCategory, inferAsrPreset, inferLlmPreset, inferTtsPreset, normalizePresetInput, resolveSessionPresets, } from "./presets.mjs";
|
|
19
19
|
import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs";
|
|
20
20
|
/**
|
|
@@ -28,18 +28,18 @@ import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs"
|
|
|
28
28
|
*
|
|
29
29
|
* const client = new AgoraClient({
|
|
30
30
|
* area: Area.US,
|
|
31
|
-
|
|
32
31
|
* appId: '...',
|
|
33
32
|
* appCertificate: '...',
|
|
34
33
|
* });
|
|
35
34
|
*
|
|
36
|
-
* const agent = new Agent({
|
|
35
|
+
* const agent = new Agent({ client, instructions: 'You are a helpful voice assistant.' })
|
|
37
36
|
* .withLlm(new OpenAI({ apiKey: '...', model: 'gpt-4o-mini', url: 'https://api.openai.com/v1/chat/completions' }))
|
|
38
37
|
* .withTts(new ElevenLabsTTS({ key: '...', modelId: '...', voiceId: '...', baseUrl: 'wss://api.elevenlabs.io/v1', sampleRate: 24000 }))
|
|
39
38
|
* .withStt(new DeepgramSTT({ apiKey: '...', language: 'en-US' }));
|
|
40
39
|
*
|
|
41
|
-
* const session = agent.createSession(
|
|
42
|
-
*
|
|
40
|
+
* const session = agent.createSession({
|
|
41
|
+
* name: `conversation-${Date.now()}`,
|
|
42
|
+
* channel: `demo-channel-${Date.now()}`,
|
|
43
43
|
* agentUid: '1',
|
|
44
44
|
* remoteUids: ['100'],
|
|
45
45
|
* });
|
|
@@ -191,6 +191,8 @@ export class AgentSession {
|
|
|
191
191
|
// are filled by `_enrichAvatarParams()` and validated separately.
|
|
192
192
|
if (isHeyGenAvatar(strictAvatar) ||
|
|
193
193
|
isLiveAvatarAvatar(strictAvatar) ||
|
|
194
|
+
isSensetimeAvatar(strictAvatar) ||
|
|
195
|
+
isSpatiusAvatar(strictAvatar) ||
|
|
194
196
|
isAkoolAvatar(strictAvatar) ||
|
|
195
197
|
isAnamAvatar(strictAvatar) ||
|
|
196
198
|
isGenericAvatar(strictAvatar)) {
|
|
@@ -226,7 +228,7 @@ export class AgentSession {
|
|
|
226
228
|
* Fills session-derived avatar fields and generates avatar ConvoAI tokens.
|
|
227
229
|
*
|
|
228
230
|
* Token management is gated to vendors that publish a separate RTC video
|
|
229
|
-
* identity (HeyGen, LiveAvatar, Generic). Other vendors (Akool, Anam) do
|
|
231
|
+
* identity (HeyGen, LiveAvatar, Generic, SenseTime). Other vendors (Akool, Anam) do
|
|
230
232
|
* not run a separate publisher and never receive an auto-generated token.
|
|
231
233
|
*/
|
|
232
234
|
_enrichAvatarParams(properties, expirySeconds) {
|
|
@@ -277,10 +279,14 @@ export class AgentSession {
|
|
|
277
279
|
const strictAvatar = avatar;
|
|
278
280
|
if (isHeyGenAvatar(strictAvatar) ||
|
|
279
281
|
isLiveAvatarAvatar(strictAvatar) ||
|
|
282
|
+
isSensetimeAvatar(strictAvatar) ||
|
|
283
|
+
isSpatiusAvatar(strictAvatar) ||
|
|
280
284
|
isAkoolAvatar(strictAvatar) ||
|
|
281
285
|
isAnamAvatar(strictAvatar) ||
|
|
282
286
|
isGenericAvatar(strictAvatar)) {
|
|
283
|
-
validateAvatarConfig(strictAvatar, {
|
|
287
|
+
validateAvatarConfig(strictAvatar, {
|
|
288
|
+
requireSessionFields: isGenericAvatar(strictAvatar),
|
|
289
|
+
});
|
|
284
290
|
}
|
|
285
291
|
if (!isAvatarTokenManaged(strictAvatar)) {
|
|
286
292
|
return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|