agora-agents 3.0.0-alpha.1 → 3.0.0-alpha.2
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 +10 -4
- package/dist/cjs/AgoraPoolClient.d.ts +3 -3
- package/dist/cjs/AgoraPoolClient.js +3 -1
- package/dist/cjs/agentkit/Agent.d.ts +7 -1
- package/dist/cjs/agentkit/Agent.js +70 -47
- package/dist/cjs/agentkit/index.d.ts +1 -1
- package/dist/cjs/agentkit/session-backend.d.ts +5 -3
- package/dist/cjs/agentkit/session-backend.js +69 -8
- package/dist/cjs/agentkit/types.d.ts +8 -2
- package/dist/cjs/agentkit/v3.d.ts +5 -1
- package/dist/cjs/agentkit/v3.js +59 -17
- package/dist/cjs/agentkit/vendors/avatar.d.ts +24 -12
- package/dist/cjs/agentkit/vendors/avatar.js +48 -3
- package/dist/cjs/agentkit/vendors/llm.d.ts +7 -7
- package/dist/cjs/agentkit/vendors/llm.js +26 -22
- package/dist/cjs/agentkit/vendors/tts.d.ts +20 -0
- package/dist/cjs/agentkit/vendors/tts.js +5 -2
- package/dist/cjs/v3/contract.js +113 -4
- package/dist/cjs/v3/resources.js +0 -1
- package/dist/cjs/v3/types.d.ts +13 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/AgoraPoolClient.d.mts +3 -3
- package/dist/esm/AgoraPoolClient.mjs +3 -1
- package/dist/esm/agentkit/Agent.d.mts +7 -1
- package/dist/esm/agentkit/Agent.mjs +71 -48
- package/dist/esm/agentkit/index.d.mts +1 -1
- package/dist/esm/agentkit/session-backend.d.mts +5 -3
- package/dist/esm/agentkit/session-backend.mjs +68 -8
- package/dist/esm/agentkit/types.d.mts +8 -2
- package/dist/esm/agentkit/v3.d.mts +5 -1
- package/dist/esm/agentkit/v3.mjs +60 -18
- package/dist/esm/agentkit/vendors/avatar.d.mts +24 -12
- package/dist/esm/agentkit/vendors/avatar.mjs +45 -6
- package/dist/esm/agentkit/vendors/llm.d.mts +7 -7
- package/dist/esm/agentkit/vendors/llm.mjs +26 -22
- package/dist/esm/agentkit/vendors/tts.d.mts +20 -0
- package/dist/esm/agentkit/vendors/tts.mjs +5 -2
- package/dist/esm/v3/contract.mjs +113 -4
- package/dist/esm/v3/resources.mjs +0 -1
- package/dist/esm/v3/types.d.mts +13 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/openapi.yaml +73 -4
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -11,14 +11,14 @@ The Agora Agents SDK for TypeScript lets you build real-time voice agents on Ago
|
|
|
11
11
|
|
|
12
12
|
`Agent` is the configuration builder. Choose `config.createSession(...).start()` for a running conversation, or `await config.save({name})` for a `SavedAgent`. Continue with the returned session or saved handle: `saved.update(revisedConfig)`, `assignNumber()`, `unassignNumber()`, `listNumbers()`, and `delete()`.
|
|
13
13
|
|
|
14
|
-
**Saving agents and project provisioning are part of SDK preview `3.0.0-alpha.
|
|
14
|
+
**Saving agents and project provisioning are part of SDK preview `3.0.0-alpha.2`.** Existing session behavior is unchanged. Use `client.secrets` and `secretRef()` for stored credentials, `withVariable()` for template/extraction definitions, and `client.numbers` to register numbers. Number listing scans project pages and filters assignments locally. `client.campaigns` provides typed campaign creation, reads, updates, pause/resume/cancel, and deletion.
|
|
15
15
|
|
|
16
16
|
Start with [Saving agents](docs/guides/saved-agents.md). Use `saved.createSession(...).start()` to run a saved configuration. Builders with secret references or variable definitions automatically start an ephemeral session without saving first. These sessions support values, labels, optional RTC token/encryption, retention, graceful stop, start, stop, and get-info. Runtime updates support RTC token, messages, and complete model params replacement; conversation actions remain unavailable. The public client uses token authentication and the public preview origin; no internal gateway headers are needed. Advanced users can access 32 operations, ETags, raw headers, pagination, and project session reads and start/stop/update through the [transport reference](docs/reference/v3.md). [Staging setup and mapping limits](docs/guides/v3-preview.md) remain documented separately.
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
|
-
npm install agora-agents@3.0.0-alpha.
|
|
21
|
+
npm install agora-agents@3.0.0-alpha.2
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## Quick Start
|
|
@@ -260,9 +260,9 @@ See the [MLLM Flow guide](./docs/guides/mllm-flow.md) for full examples with Gem
|
|
|
260
260
|
|
|
261
261
|
## Avatars
|
|
262
262
|
|
|
263
|
-
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).
|
|
263
|
+
AgentKit supports LiveAvatar, Generic Avatar (including Tavus, Protoface, and LemonSlice), 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).
|
|
264
264
|
|
|
265
|
-
See the [Avatar Integration guide](./docs/guides/avatars.md) for sample-rate requirements and Generic Avatar setup.
|
|
265
|
+
See the [Avatar Integration guide](./docs/guides/avatars.md) for sample-rate requirements, provider URL defaults, LemonSlice image/agent selectors and aspect ratios, and Generic Avatar setup.
|
|
266
266
|
|
|
267
267
|
## Documentation
|
|
268
268
|
|
|
@@ -280,3 +280,9 @@ See the [Avatar Integration guide](./docs/guides/avatars.md) for sample-rate req
|
|
|
280
280
|
|
|
281
281
|
- [SDK Reference](./reference.md)
|
|
282
282
|
- [Agora Conversational AI Docs](https://docs.agora.io/en/conversational-ai/overview)
|
|
283
|
+
|
|
284
|
+
### Installing a preview checkout
|
|
285
|
+
|
|
286
|
+
The v3 alpha preview is distributed separately from stable 2.x packages. This checkout targets `3.0.0-alpha.2`. Git installs run `prepare` to build importable CommonJS/ESM output; lifecycle scripts and development dependencies must be enabled. To build a checkout on Windows, PowerShell, Command Prompt, macOS, or Linux, run `npm install` then `npm run build` (the clean step uses Node).
|
|
287
|
+
|
|
288
|
+
Use `agent.createEphemeralSession(options)` to explicitly start an unsaved Platform configuration. Use `agent.call(options)` or `saved.call(options)` for an outbound phone session, then call `start()` on the returned handle.
|
|
@@ -19,11 +19,10 @@ export declare namespace AgoraClient {
|
|
|
19
19
|
v3?: V3Options;
|
|
20
20
|
/** Agora App ID — used as the `appid` path parameter and for RTC token generation */
|
|
21
21
|
appId: string;
|
|
22
|
-
/** Agora App Certificate — used to sign RTC tokens. Keep this secret. */
|
|
23
|
-
appCertificate: string;
|
|
24
22
|
}
|
|
25
23
|
/** Use a pre-built Agora token for REST API authentication. Pass the raw token; the SDK sets `Authorization: agora token=<authToken>` automatically. */
|
|
26
24
|
interface TokenAuthOptions {
|
|
25
|
+
appCertificate?: string;
|
|
27
26
|
authToken: string;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
@@ -31,6 +30,7 @@ export declare namespace AgoraClient {
|
|
|
31
30
|
* ConvoAI token per API call — no Customer Secret required.
|
|
32
31
|
*/
|
|
33
32
|
interface AppCredentialsOptions {
|
|
33
|
+
appCertificate: string;
|
|
34
34
|
authToken?: never;
|
|
35
35
|
}
|
|
36
36
|
type AuthOptions = TokenAuthOptions | AppCredentialsOptions;
|
|
@@ -75,7 +75,7 @@ export declare class AgoraClient<TArea extends AgoraArea = AgoraArea> extends Ba
|
|
|
75
75
|
/** Agora App ID */
|
|
76
76
|
readonly appId: string;
|
|
77
77
|
/** Agora App Certificate (used for RTC token signing) */
|
|
78
|
-
readonly appCertificate: string;
|
|
78
|
+
readonly appCertificate: string | undefined;
|
|
79
79
|
/** The active authentication mode */
|
|
80
80
|
readonly authMode: AgoraAuthMode;
|
|
81
81
|
/** The configured routing area */
|
|
@@ -122,9 +122,11 @@ class AgoraClient extends Client_js_1.AgoraClient {
|
|
|
122
122
|
}
|
|
123
123
|
const authMode = options.authToken !== undefined ? "token" : "app-credentials";
|
|
124
124
|
const { authToken, appId, appCertificate } = options, rest = __rest(options, ["authToken", "appId", "appCertificate"]);
|
|
125
|
+
if (authMode === "app-credentials" && !appCertificate)
|
|
126
|
+
throw new Error("appCertificate or authToken is required");
|
|
125
127
|
const authorization = () => authMode === "token"
|
|
126
128
|
? `agora token=${authToken}`
|
|
127
|
-
: `agora token=${(0, token_js_1.generateConvoAIToken)({ appId, appCertificate, channelName: "", uid: 0 })}`;
|
|
129
|
+
: `agora token=${(0, token_js_1.generateConvoAIToken)({ appId, appCertificate: appCertificate, channelName: "", uid: 0 })}`;
|
|
128
130
|
const originalFetch = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalThis.fetch;
|
|
129
131
|
const tokenOnlyFetch = (input, init) => __awaiter(this, void 0, void 0, function* () {
|
|
130
132
|
const finalHeaders = new Headers(input instanceof Request ? input.headers : undefined);
|
|
@@ -11,7 +11,7 @@ import type * as Agora from "../api/index.js";
|
|
|
11
11
|
import { AgentSession } from "./AgentSession.js";
|
|
12
12
|
import type { AgoraArea } from "./area.js";
|
|
13
13
|
import type { AvatarVendor, CNMllmVendor, GlobalMllmVendor, LlmVendor, SttVendor, TtsVendor } from "./region-vendors.js";
|
|
14
|
-
import type { AdvancedFeatures, AvatarConfig, FillerWordsConfig, GeofenceConfig, InterruptionConfig, Labels, LlmConfig, LlmGreetingConfigs, MllmConfig, ParametersAudioScenario, RtcConfig, SalConfig, SessionOptions, SessionParamsInput, SttConfig, TtsConfig, TurnDetectionConfig } from "./types.js";
|
|
14
|
+
import type { AdvancedFeatures, AvatarConfig, CallOptions, FillerWordsConfig, GeofenceConfig, InterruptionConfig, Labels, LlmConfig, LlmGreetingConfigs, MllmConfig, ParametersAudioScenario, RtcConfig, SalConfig, SessionOptions, SessionParamsInput, SttConfig, TtsConfig, TurnDetectionConfig } from "./types.js";
|
|
15
15
|
/**
|
|
16
16
|
* Configuration options for creating an Agent.
|
|
17
17
|
*
|
|
@@ -420,6 +420,11 @@ export declare class Agent<TTSSampleRate extends number = number, TArea extends
|
|
|
420
420
|
/** Compatibility alias for save(). */
|
|
421
421
|
deploy(options?: DeployOptions): Promise<DeployedAgent>;
|
|
422
422
|
createSession(options: SessionOptions): AgentSession;
|
|
423
|
+
/** Start an unsaved configuration explicitly through the Platform API. */
|
|
424
|
+
createEphemeralSession(options: SessionOptions): AgentSession;
|
|
425
|
+
/** Create an outbound phone-call session from this unsaved configuration. */
|
|
426
|
+
call(options: CallOptions): AgentSession;
|
|
427
|
+
private _createPlatformSession;
|
|
423
428
|
/**
|
|
424
429
|
* Converts the Agent configuration to the Fern request properties format.
|
|
425
430
|
*
|
|
@@ -463,6 +468,7 @@ export declare class Agent<TTSSampleRate extends number = number, TArea extends
|
|
|
463
468
|
* If a new private field is added to Agent, it MUST also be added here.
|
|
464
469
|
*/
|
|
465
470
|
private _clone;
|
|
471
|
+
private _resolvePlatformAsrConfig;
|
|
466
472
|
private _resolveAsrConfig;
|
|
467
473
|
private _resolveTurnDetectionConfig;
|
|
468
474
|
}
|
|
@@ -591,8 +591,8 @@ class Agent {
|
|
|
591
591
|
var _a, _b;
|
|
592
592
|
const config = this.config;
|
|
593
593
|
if (config.mllm === undefined && (config.stt !== undefined || ((_a = config.turnDetection) === null || _a === void 0 ? void 0 : _a.language) !== undefined)) {
|
|
594
|
-
//
|
|
595
|
-
config.stt = this.
|
|
594
|
+
// Keep Platform language precedence separate from legacy interaction defaults.
|
|
595
|
+
config.stt = this._resolvePlatformAsrConfig();
|
|
596
596
|
}
|
|
597
597
|
return (0, v3_js_1.deployAgent)(this._client, (0, v3_js_1.buildV3Agent)(config, this._variables, (_b = options.name) !== null && _b !== void 0 ? _b : `agent-${Date.now()}`), options);
|
|
598
598
|
}
|
|
@@ -601,10 +601,10 @@ class Agent {
|
|
|
601
601
|
return this.save(options);
|
|
602
602
|
}
|
|
603
603
|
createSession(options) {
|
|
604
|
-
var _a, _b
|
|
604
|
+
var _a, _b;
|
|
605
605
|
if ("clientReference" in options || "client_reference" in options)
|
|
606
606
|
throw new Error("client_reference is being removed; use the returned session ID for correlation");
|
|
607
|
-
const
|
|
607
|
+
const _c = this.config, { client: _client } = _c, config = __rest(_c, ["client"]);
|
|
608
608
|
let requiresStoredSession = Object.keys(this._variables).length > 0 ||
|
|
609
609
|
options.values !== undefined ||
|
|
610
610
|
options.idempotencyKey !== undefined ||
|
|
@@ -624,50 +624,66 @@ class Agent {
|
|
|
624
624
|
else
|
|
625
625
|
throw error;
|
|
626
626
|
}
|
|
627
|
-
if (requiresStoredSession)
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
normalized.parameters = Object.keys(params).length ? params : undefined;
|
|
658
|
-
if (normalized.labels !== undefined) {
|
|
659
|
-
(_e = sessionOptions.labels) !== null && _e !== void 0 ? _e : (sessionOptions.labels = normalized.labels);
|
|
660
|
-
normalized.labels = undefined;
|
|
661
|
-
}
|
|
662
|
-
if (normalized.mllm === undefined &&
|
|
663
|
-
(normalized.stt !== undefined || ((_f = normalized.turnDetection) === null || _f === void 0 ? void 0 : _f.language) !== undefined)) {
|
|
664
|
-
normalized.stt = this._resolveAsrConfig(this._resolveTurnDetectionConfig());
|
|
665
|
-
}
|
|
666
|
-
const _l = (0, v3_js_1.buildV3Agent)(normalized, this._variables, (_g = options.name) !== null && _g !== void 0 ? _g : "ephemeral"), { agent_name: _name } = _l, agent = __rest(_l, ["agent_name"]);
|
|
667
|
-
return (0, session_backend_js_1.createStoredSession)(this._client, sessionOptions, { agent }, this);
|
|
627
|
+
if (requiresStoredSession)
|
|
628
|
+
return this.createEphemeralSession(options);
|
|
629
|
+
const name = (_a = options.name) !== null && _a !== void 0 ? _a : `agent-${Date.now()}`;
|
|
630
|
+
return new AgentSession_js_1.AgentSession(Object.assign(Object.assign({ client: this._client, agent: this, appId: this._client.appId, appCertificate: this._client.appCertificate }, options), { agentUid: (_b = options.agentUid) !== null && _b !== void 0 ? _b : "0", name }));
|
|
631
|
+
}
|
|
632
|
+
/** Start an unsaved configuration explicitly through the Platform API. */
|
|
633
|
+
createEphemeralSession(options) {
|
|
634
|
+
return this._createPlatformSession(options);
|
|
635
|
+
}
|
|
636
|
+
/** Create an outbound phone-call session from this unsaved configuration. */
|
|
637
|
+
call(options) {
|
|
638
|
+
return this._createPlatformSession((0, session_backend_js_1.callSessionOptions)(options), {
|
|
639
|
+
type: "telephony",
|
|
640
|
+
from: options.from,
|
|
641
|
+
to: options.to,
|
|
642
|
+
call_policy: options.callPolicy,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
_createPlatformSession(options, transport) {
|
|
646
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
647
|
+
const normalized = this.config;
|
|
648
|
+
const sessionOptions = Object.assign({}, options);
|
|
649
|
+
if (normalized.geofence !== undefined) {
|
|
650
|
+
(_a = sessionOptions.geofence) !== null && _a !== void 0 ? _a : (sessionOptions.geofence = Object.assign({ area: normalized.geofence.area.toLowerCase() }, (normalized.geofence.exclude_area === undefined
|
|
651
|
+
? {}
|
|
652
|
+
: {
|
|
653
|
+
exclude_area: normalized.geofence.exclude_area.toLowerCase(),
|
|
654
|
+
})));
|
|
655
|
+
normalized.geofence = undefined;
|
|
668
656
|
}
|
|
669
|
-
const
|
|
670
|
-
|
|
657
|
+
const params = Object.assign({}, normalized.parameters);
|
|
658
|
+
if (params.opt_out !== undefined) {
|
|
659
|
+
(_b = sessionOptions.dataPolicy) !== null && _b !== void 0 ? _b : (sessionOptions.dataPolicy = { retention: params.opt_out ? "none" : "30_days" });
|
|
660
|
+
delete params.opt_out;
|
|
661
|
+
}
|
|
662
|
+
if (params.farewell_config !== undefined) {
|
|
663
|
+
const farewell = params.farewell_config;
|
|
664
|
+
(_c = sessionOptions.gracefulStop) !== null && _c !== void 0 ? _c : (sessionOptions.gracefulStop = {
|
|
665
|
+
enabled: farewell.graceful_enabled,
|
|
666
|
+
timeout_ms: farewell.graceful_timeout_seconds === undefined
|
|
667
|
+
? undefined
|
|
668
|
+
: farewell.graceful_timeout_seconds * 1000,
|
|
669
|
+
});
|
|
670
|
+
delete params.farewell_config;
|
|
671
|
+
}
|
|
672
|
+
if (params.audio_scenario !== undefined) {
|
|
673
|
+
(_d = sessionOptions.audioScenario) !== null && _d !== void 0 ? _d : (sessionOptions.audioScenario = params.audio_scenario === "default" ? "aiserver" : params.audio_scenario);
|
|
674
|
+
delete params.audio_scenario;
|
|
675
|
+
}
|
|
676
|
+
normalized.parameters = Object.keys(params).length ? params : undefined;
|
|
677
|
+
if (normalized.labels !== undefined) {
|
|
678
|
+
(_e = sessionOptions.labels) !== null && _e !== void 0 ? _e : (sessionOptions.labels = normalized.labels);
|
|
679
|
+
normalized.labels = undefined;
|
|
680
|
+
}
|
|
681
|
+
if (normalized.mllm === undefined &&
|
|
682
|
+
(normalized.stt !== undefined || ((_f = normalized.turnDetection) === null || _f === void 0 ? void 0 : _f.language) !== undefined)) {
|
|
683
|
+
normalized.stt = this._resolvePlatformAsrConfig();
|
|
684
|
+
}
|
|
685
|
+
const _h = (0, v3_js_1.buildV3Agent)(normalized, this._variables, (_g = options.name) !== null && _g !== void 0 ? _g : "ephemeral"), { agent_name: _name } = _h, agent = __rest(_h, ["agent_name"]);
|
|
686
|
+
return (0, session_backend_js_1.createStoredSession)(this._client, sessionOptions, { agent }, this, transport);
|
|
671
687
|
}
|
|
672
688
|
/**
|
|
673
689
|
* Converts the Agent configuration to the Fern request properties format.
|
|
@@ -827,6 +843,13 @@ class Agent {
|
|
|
827
843
|
newAgent._greetingConfigs = this._greetingConfigs;
|
|
828
844
|
return newAgent;
|
|
829
845
|
}
|
|
846
|
+
_resolvePlatformAsrConfig() {
|
|
847
|
+
var _a, _b, _c, _d;
|
|
848
|
+
const config = this._stt ? Object.assign({}, this._stt) : { vendor: this._client.area === index_js_1.Area.CN ? "fengming" : "ares" };
|
|
849
|
+
const params = config.params;
|
|
850
|
+
const language = (_d = (_c = (_b = (_a = this._turnDetection) === null || _a === void 0 ? void 0 : _a.language) !== null && _b !== void 0 ? _b : config.language) !== null && _c !== void 0 ? _c : params === null || params === void 0 ? void 0 : params.language) !== null && _d !== void 0 ? _d : (["ares", "fengming"].includes(config.vendor) ? DEFAULT_TURN_DETECTION_LANGUAGE : undefined);
|
|
851
|
+
return Object.assign(Object.assign({}, config), (typeof language === "string" ? { language } : {}));
|
|
852
|
+
}
|
|
830
853
|
_resolveAsrConfig(turnDetectionConfig) {
|
|
831
854
|
const asrConfig = this._stt !== undefined
|
|
832
855
|
? Object.assign({}, this._stt)
|
|
@@ -37,7 +37,7 @@ export type { AvatarVendor, CNAvatarVendor, CNLlmVendor, CNMllmVendor, CNSttVend
|
|
|
37
37
|
export { UnsupportedSessionOperationError } from "./session-backend.js";
|
|
38
38
|
export type { GenerateConvoAITokenOptions, GenerateTokenOptions, } from "./token.js";
|
|
39
39
|
export { ExpiresIn, generateConvoAIToken, generateRtcToken, MAX_EXPIRY_SECONDS, } from "./token.js";
|
|
40
|
-
export type { AdvancedFeatures, AgentConfig, AgentConfigUpdate, AmazonTts, AmazonTtsParams, AsrConfig, AsrVendorName, AvatarConfig, AvatarWireVendor, CartesiaTts, CartesiaTtsParams, ConversationHistory, ConversationRole, ConversationSessionTurn, ConversationTurn, ConversationTurns, Eagerness, ElevenLabsTts, ElevenLabsTtsParams, EndOfSpeechConfig, EndOfSpeechMode, EndOfSpeechSemanticConfig, EndOfSpeechVadConfig, FarewellConfig, FillerWordsConfig, FillerWordsContent, FillerWordsContentGeneratedConfig, FillerWordsContentSelectionRule, FillerWordsContentStaticConfig, FillerWordsGeneratedLlmProvider, FillerWordsTrigger, FillerWordsTriggerFixedTimeConfig, FishAudioTts, FishAudioTtsParams, GeminiAsrParams, GenericTts, GenericTtsParams, GeofenceArea, GeofenceConfig, GeofenceExcludeArea, GetTurnsOptions, GoogleTts, GoogleTtsParams, GradiumTts, GradiumTtsParams, HumeAiTts, HumeAiTtsParams, InterruptionConfig, InterruptionMode, InterruptMode, Labels, LlmConfig, LlmGreetingConfigs, LlmGreetingConfigsMode, LlmStyle, LlmTool, LlmToolExecution, LlmToolFunction, LlmToolServer, McpServer, McpServersItem, MicrosoftTts, MicrosoftTtsParams, MinimaxTts, MinimaxTtsParams, MistralTts, MistralTtsParams, MllmConfig, MllmTurnDetectionConfig, MllmTurnDetectionMode, MllmVendor, MurfTts, MurfTtsParams, OpenAiTts, OpenAiTtsParams, ParametersAudioScenario, ParametersDataChannel, RimeTts, RimeTtsParams, RtcConfig, SalConfig, SalMode, SarvamTts, SarvamTtsParams, SayOptions, SessionInfo, SessionListResponse, SessionOptions, SessionParams, SessionParamsInput, SessionStatus, SessionSummary, SilenceAction, SilenceConfig, SmallestAiAsr, SmallestAiAsrParams, SmallestAiTts, SmallestAiTtsParams, SpatiusAvatarParams, SpeakPriority, StartOfSpeechConfig, StartOfSpeechDisabledConfig, StartOfSpeechDisabledConfigStrategy, StartOfSpeechKeywordsConfig, StartOfSpeechMode, StartOfSpeechVadConfig, SttConfig, ThinkOnListeningAction, ThinkOnSpeakingAction, ThinkOnThinkingAction, ThinkOptions, ThinkResponse, TtsConfig, TurnDetectionConfig, TurnDetectionLanguage, TurnDetectionNestedConfig, TurnDetectionType, TypecastTts, TypecastTtsParams, XAiAsr, XAiAsrParams, XAiTts, XAiTtsParams, } from "./types.js";
|
|
40
|
+
export type { AdvancedFeatures, AgentConfig, AgentConfigUpdate, AmazonTts, AmazonTtsParams, AsrConfig, AsrVendorName, AvatarConfig, AvatarWireVendor, CallOptions, CartesiaTts, CartesiaTtsParams, ConversationHistory, ConversationRole, ConversationSessionTurn, ConversationTurn, ConversationTurns, Eagerness, ElevenLabsTts, ElevenLabsTtsParams, EndOfSpeechConfig, EndOfSpeechMode, EndOfSpeechSemanticConfig, EndOfSpeechVadConfig, FarewellConfig, FillerWordsConfig, FillerWordsContent, FillerWordsContentGeneratedConfig, FillerWordsContentSelectionRule, FillerWordsContentStaticConfig, FillerWordsGeneratedLlmProvider, FillerWordsTrigger, FillerWordsTriggerFixedTimeConfig, FishAudioTts, FishAudioTtsParams, GeminiAsrParams, GenericTts, GenericTtsParams, GeofenceArea, GeofenceConfig, GeofenceExcludeArea, GetTurnsOptions, GoogleTts, GoogleTtsParams, GradiumTts, GradiumTtsParams, HumeAiTts, HumeAiTtsParams, InterruptionConfig, InterruptionMode, InterruptMode, Labels, LlmConfig, LlmGreetingConfigs, LlmGreetingConfigsMode, LlmStyle, LlmTool, LlmToolExecution, LlmToolFunction, LlmToolServer, McpServer, McpServersItem, MicrosoftTts, MicrosoftTtsParams, MinimaxTts, MinimaxTtsParams, MistralTts, MistralTtsParams, MllmConfig, MllmTurnDetectionConfig, MllmTurnDetectionMode, MllmVendor, MurfTts, MurfTtsParams, OpenAiTts, OpenAiTtsParams, ParametersAudioScenario, ParametersDataChannel, RimeTts, RimeTtsParams, RtcConfig, SalConfig, SalMode, SarvamTts, SarvamTtsParams, SayOptions, SessionInfo, SessionListResponse, SessionOptions, SessionParams, SessionParamsInput, SessionStatus, SessionSummary, SilenceAction, SilenceConfig, SmallestAiAsr, SmallestAiAsrParams, SmallestAiTts, SmallestAiTtsParams, SpatiusAvatarParams, SpeakPriority, StartOfSpeechConfig, StartOfSpeechDisabledConfig, StartOfSpeechDisabledConfigStrategy, StartOfSpeechKeywordsConfig, StartOfSpeechMode, StartOfSpeechVadConfig, SttConfig, ThinkOnListeningAction, ThinkOnSpeakingAction, ThinkOnThinkingAction, ThinkOptions, ThinkResponse, TtsConfig, TurnDetectionConfig, TurnDetectionLanguage, TurnDetectionNestedConfig, TurnDetectionType, TypecastTts, TypecastTtsParams, XAiAsr, XAiAsrParams, XAiTts, XAiTtsParams, } from "./types.js";
|
|
41
41
|
export type { AssignNumberOptions, DeployOptions, SaveOptions, SecretRef, VariableDefinition } from "./v3.js";
|
|
42
42
|
export { DeployedAgent, NumberNotFoundError, SavedAgent, SecretRefNotSupportedError, secretRef, UnsupportedFieldError, } from "./v3.js";
|
|
43
43
|
export type { AkoolAvatarOptions, AnamAvatarOptions, GenericAvatarOptions, HeyGenAvatarOptions, LemonSliceOptions, LiveAvatarAvatarOptions, ProtofaceOptions, TavusOptions, } from "./vendors/avatar.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Internal adapter for session identities, without mixing them with running-agent IDs. */
|
|
2
2
|
import type { AgoraClient } from "../AgoraPoolClient.js";
|
|
3
|
-
import type { AgentCreateRequest } from "../v3/types.js";
|
|
3
|
+
import type { AgentCreateRequest, TelephonyTransport } from "../v3/types.js";
|
|
4
4
|
import type { Agent } from "./Agent.js";
|
|
5
5
|
import { AgentSession } from "./AgentSession.js";
|
|
6
|
-
import type { AgentConfigUpdate, SessionInfo, SessionOptions } from "./types.js";
|
|
6
|
+
import type { AgentConfigUpdate, CallOptions, SessionInfo, SessionOptions } from "./types.js";
|
|
7
7
|
export interface SessionBackend {
|
|
8
8
|
start(): Promise<{
|
|
9
9
|
id: string;
|
|
@@ -16,8 +16,10 @@ export interface SessionBackend {
|
|
|
16
16
|
export declare class UnsupportedSessionOperationError extends Error {
|
|
17
17
|
constructor(operation: string);
|
|
18
18
|
}
|
|
19
|
+
/** Validate mixed transports before replacing internal RTC placeholders. */
|
|
20
|
+
export declare function callSessionOptions(options: CallOptions): SessionOptions;
|
|
19
21
|
export declare function createStoredSession(client: AgoraClient, options: SessionOptions, source: {
|
|
20
22
|
agent_id: string;
|
|
21
23
|
} | {
|
|
22
24
|
agent: Omit<AgentCreateRequest, "agent_name">;
|
|
23
|
-
}, config?: Agent): AgentSession;
|
|
25
|
+
}, config?: Agent, telephony?: TelephonyTransport): AgentSession;
|
|
@@ -10,9 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.UnsupportedSessionOperationError = void 0;
|
|
13
|
+
exports.callSessionOptions = callSessionOptions;
|
|
13
14
|
exports.createStoredSession = createStoredSession;
|
|
14
15
|
const session_lifecycle_js_1 = require("../v3/session-lifecycle.js");
|
|
15
16
|
const AgentSession_js_1 = require("./AgentSession.js");
|
|
17
|
+
const token_js_1 = require("./token.js");
|
|
16
18
|
class UnsupportedSessionOperationError extends Error {
|
|
17
19
|
constructor(operation) {
|
|
18
20
|
super(`${operation} is not supported by this session backend; start, stop, getInfo and update are available`);
|
|
@@ -20,16 +22,27 @@ class UnsupportedSessionOperationError extends Error {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
exports.UnsupportedSessionOperationError = UnsupportedSessionOperationError;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
/** Validate mixed transports before replacing internal RTC placeholders. */
|
|
26
|
+
function callSessionOptions(options) {
|
|
25
27
|
for (const key of [
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
28
|
+
"channel",
|
|
29
|
+
"remoteUids",
|
|
30
|
+
"agentUid",
|
|
31
|
+
"token",
|
|
32
|
+
"encryption",
|
|
33
|
+
"audioScenario",
|
|
34
|
+
"geofence",
|
|
29
35
|
"enableStringUid",
|
|
30
|
-
"
|
|
31
|
-
"pipelineId",
|
|
36
|
+
"expiresIn",
|
|
32
37
|
]) {
|
|
38
|
+
if (options[key] !== undefined)
|
|
39
|
+
throw new Error(`Phone calls do not accept RTC option ${key}`);
|
|
40
|
+
}
|
|
41
|
+
return Object.assign(Object.assign({}, options), { channel: "", remoteUids: [] });
|
|
42
|
+
}
|
|
43
|
+
function createStoredSession(client, options, source, config, telephony) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
for (const key of ["clientReference", "client_reference", "enableStringUid", "preset", "pipelineId"]) {
|
|
33
46
|
if (key in options && options[key] !== undefined)
|
|
34
47
|
throw new Error(`${key} is not supported by this session backend`);
|
|
35
48
|
}
|
|
@@ -43,7 +56,7 @@ function createStoredSession(client, options, source, config) {
|
|
|
43
56
|
}
|
|
44
57
|
if (options.gracefulStop !== undefined)
|
|
45
58
|
lifecycle.graceful_stop = options.gracefulStop;
|
|
46
|
-
const payload = JSON.parse(JSON.stringify(Object.assign(Object.assign(Object.assign({}, source), { values: options.values, idempotencyKey: options.idempotencyKey, data_policy: options.dataPolicy, labels: options.labels, transport: {
|
|
59
|
+
const payload = JSON.parse(JSON.stringify(Object.assign(Object.assign(Object.assign({}, source), { values: options.values, idempotencyKey: options.idempotencyKey, data_policy: options.dataPolicy, labels: options.labels, transport: telephony !== null && telephony !== void 0 ? telephony : {
|
|
47
60
|
type: "rtc",
|
|
48
61
|
channel: options.channel,
|
|
49
62
|
uid: options.agentUid,
|
|
@@ -54,12 +67,60 @@ function createStoredSession(client, options, source, config) {
|
|
|
54
67
|
geofence: options.geofence,
|
|
55
68
|
} }), (Object.keys(lifecycle).length ? { lifecycle } : {}))));
|
|
56
69
|
(0, session_lifecycle_js_1.validateSessionStart)(payload);
|
|
70
|
+
if (options.expiresIn !== undefined &&
|
|
71
|
+
(!Number.isInteger(options.expiresIn) || !Number.isFinite(options.expiresIn)))
|
|
72
|
+
throw new Error("expiresIn must be a whole number of seconds");
|
|
73
|
+
if (telephony &&
|
|
74
|
+
[options.agentUid, options.token, options.encryption, options.audioScenario, options.geofence].some((value) => value !== undefined))
|
|
75
|
+
throw new Error("RTC options are not supported for phone calls");
|
|
76
|
+
const expiry = options.expiresIn === undefined ? undefined : token_js_1.ExpiresIn.seconds(options.expiresIn);
|
|
77
|
+
const signing = !telephony &&
|
|
78
|
+
options.token === undefined &&
|
|
79
|
+
client.appCertificate &&
|
|
80
|
+
options.agentUid !== undefined &&
|
|
81
|
+
!/^0+$/.test(options.agentUid)
|
|
82
|
+
? {
|
|
83
|
+
appId: client.appId,
|
|
84
|
+
appCertificate: client.appCertificate,
|
|
85
|
+
channel: options.channel,
|
|
86
|
+
uid: options.agentUid,
|
|
87
|
+
}
|
|
88
|
+
: undefined;
|
|
57
89
|
let successfullyStarted = false;
|
|
58
90
|
const backend = {
|
|
59
91
|
start() {
|
|
60
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
93
|
if (payload.idempotencyKey && successfullyStarted)
|
|
62
94
|
throw new Error("This idempotency key already started a session; create a new handle with a new key for another session");
|
|
95
|
+
if (successfullyStarted && !payload.idempotencyKey) {
|
|
96
|
+
// A new unkeyed session needs a fresh token. Failed starts retain
|
|
97
|
+
// their request snapshot, and keyed starts cannot be reused.
|
|
98
|
+
if (signing)
|
|
99
|
+
delete payload.transport.token;
|
|
100
|
+
successfullyStarted = false;
|
|
101
|
+
}
|
|
102
|
+
if (signing &&
|
|
103
|
+
payload.transport.token === undefined &&
|
|
104
|
+
(!/^\d+$/.test(signing.uid) ||
|
|
105
|
+
(Number.isSafeInteger(Number(signing.uid)) && Number(signing.uid) <= 4294967295))) {
|
|
106
|
+
// Larger numeric identities remain opaque; the service provisions
|
|
107
|
+
// their token instead of coercing them through the local signer.
|
|
108
|
+
payload.transport.token = /^\d+$/.test(signing.uid)
|
|
109
|
+
? (0, token_js_1.generateConvoAIToken)({
|
|
110
|
+
appId: signing.appId,
|
|
111
|
+
appCertificate: signing.appCertificate,
|
|
112
|
+
channelName: signing.channel,
|
|
113
|
+
uid: Number(signing.uid),
|
|
114
|
+
tokenExpire: expiry,
|
|
115
|
+
})
|
|
116
|
+
: (0, token_js_1.generateRtcTokenWithAccount)({
|
|
117
|
+
appId: signing.appId,
|
|
118
|
+
appCertificate: signing.appCertificate,
|
|
119
|
+
channel: signing.channel,
|
|
120
|
+
account: signing.uid,
|
|
121
|
+
expirySeconds: expiry,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
63
124
|
const result = "agent_id" in payload
|
|
64
125
|
? yield client.v3.sessions.start(payload)
|
|
65
126
|
: yield client.v3.sessions.startEphemeral(payload);
|
|
@@ -279,14 +279,20 @@ export interface SessionOptions {
|
|
|
279
279
|
/** Optional warning logger. Defaults to console.warn. Set to a no-op to silence warnings. */
|
|
280
280
|
warn?: (message: string) => void;
|
|
281
281
|
}
|
|
282
|
+
/** Outbound telephony options; from is a registered number ID, to is an E.164 number. */
|
|
283
|
+
export type CallOptions = Pick<SessionOptions, "name" | "values" | "idempotencyKey" | "labels" | "maxDuration" | "idleTimeout" | "gracefulStop" | "dataPolicy" | "debug" | "warn"> & {
|
|
284
|
+
from: string;
|
|
285
|
+
to: string;
|
|
286
|
+
callPolicy?: import("../v3/types.js").CallPolicy;
|
|
287
|
+
};
|
|
282
288
|
/** Session status */
|
|
283
289
|
export type SessionStatus = ListAgentsResponse.Data.List.Item.Status;
|
|
284
290
|
/** Session info (from get endpoint) */
|
|
285
291
|
export type SessionInfo = GetAgentsResponse & {
|
|
286
292
|
agent_session_id?: string;
|
|
287
293
|
agent_name?: string;
|
|
288
|
-
/**
|
|
289
|
-
analysis?:
|
|
294
|
+
/** Extraction analysis, when returned by the service. */
|
|
295
|
+
analysis?: import("../v3/types.js").SessionAnalysis | null;
|
|
290
296
|
};
|
|
291
297
|
/** Session list response */
|
|
292
298
|
export type SessionListResponse = ListAgentsResponse;
|
|
@@ -2,7 +2,7 @@ import type { AgoraClient } from "../AgoraPoolClient.js";
|
|
|
2
2
|
import type * as V3 from "../v3/types.js";
|
|
3
3
|
import type { Agent, AgentOptions } from "./Agent.js";
|
|
4
4
|
import type { AgentSession } from "./AgentSession.js";
|
|
5
|
-
import type { LlmConfig, MllmConfig, SessionOptions, SttConfig, TtsConfig } from "./types.js";
|
|
5
|
+
import type { CallOptions, LlmConfig, MllmConfig, SessionOptions, SttConfig, TtsConfig } from "./types.js";
|
|
6
6
|
export type SecretRef = string & {
|
|
7
7
|
readonly __secretRef: unique symbol;
|
|
8
8
|
};
|
|
@@ -41,6 +41,8 @@ export declare function deployAgent(client: AgoraClient, body: V3.AgentCreateReq
|
|
|
41
41
|
export interface AssignNumberOptions {
|
|
42
42
|
maxCallDurationSeconds?: number;
|
|
43
43
|
maxSilenceDurationMs?: number;
|
|
44
|
+
/** Full inbound policy, including end_call. Named duration options take precedence. */
|
|
45
|
+
callPolicy?: V3.InboundCallPolicy;
|
|
44
46
|
}
|
|
45
47
|
export declare class SavedAgent {
|
|
46
48
|
private readonly client;
|
|
@@ -51,6 +53,8 @@ export declare class SavedAgent {
|
|
|
51
53
|
constructor(client: AgoraClient, data: V3.AgentResponse, etag: string);
|
|
52
54
|
static get(client: AgoraClient, agentId: string): Promise<SavedAgent>;
|
|
53
55
|
createSession(options: SessionOptions): AgentSession;
|
|
56
|
+
/** Create an outbound phone-call session using this saved agent. */
|
|
57
|
+
call(options: CallOptions): AgentSession;
|
|
54
58
|
/** Save a revised configuration to this stored identity, preserving its name by default. */
|
|
55
59
|
update(config: Agent, options?: {
|
|
56
60
|
name?: string;
|
package/dist/cjs/agentkit/v3.js
CHANGED
|
@@ -102,11 +102,31 @@ const moved = [
|
|
|
102
102
|
"turn_detection",
|
|
103
103
|
];
|
|
104
104
|
function toV3Module(config, kind, errors = []) {
|
|
105
|
-
var _a, _b, _c, _d, _e, _f;
|
|
105
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
106
106
|
const c = Object.assign({}, config), params = Object.assign({}, c.params);
|
|
107
107
|
const path = `pipeline.${kind}`;
|
|
108
|
+
if (kind === "avatar" && c.vendor === "heygen")
|
|
109
|
+
c.vendor = "liveavatar";
|
|
110
|
+
if (kind === "asr" && c.keywords !== undefined) {
|
|
111
|
+
params.keywords = c.keywords;
|
|
112
|
+
delete c.keywords;
|
|
113
|
+
}
|
|
114
|
+
if (kind === "asr") {
|
|
115
|
+
(_a = c.language) !== null && _a !== void 0 ? _a : (c.language = (_b = params.language) !== null && _b !== void 0 ? _b : (c.vendor === "ares" ? "en-US" : undefined));
|
|
116
|
+
delete params.language;
|
|
117
|
+
}
|
|
118
|
+
if (kind === "llm" && (c.vendor === "gemini" || c.style === "gemini") && c.url) {
|
|
119
|
+
// Legacy Gemini uses a query key; Platform credentials must never live in URLs.
|
|
120
|
+
const url = new URL(c.url);
|
|
121
|
+
const key = url.searchParams.get("key");
|
|
122
|
+
if (key !== null) {
|
|
123
|
+
(_c = c.api_key) !== null && _c !== void 0 ? _c : (c.api_key = key);
|
|
124
|
+
url.searchParams.delete("key");
|
|
125
|
+
c.url = url.toString();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
108
128
|
if (kind === "llm" && c.style === "bedrock") {
|
|
109
|
-
(
|
|
129
|
+
(_d = c.vendor) !== null && _d !== void 0 ? _d : (c.vendor = "amazon");
|
|
110
130
|
for (const key of ["access_key", "secret_key", "region"]) {
|
|
111
131
|
if (c[key] !== undefined) {
|
|
112
132
|
if (params[key] !== undefined && params[key] !== c[key])
|
|
@@ -194,15 +214,28 @@ function toV3Module(config, kind, errors = []) {
|
|
|
194
214
|
if (params[key] !== undefined)
|
|
195
215
|
errors.push(`${path}.params.${key}`);
|
|
196
216
|
}
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
217
|
+
const endpointAlias = kind === "asr"
|
|
218
|
+
? c.vendor === "assemblyai"
|
|
219
|
+
? "ws_url"
|
|
220
|
+
: c.vendor === "speechmatics"
|
|
221
|
+
? "uri"
|
|
222
|
+
: undefined
|
|
223
|
+
: undefined;
|
|
224
|
+
const url = kind === "avatar"
|
|
225
|
+
? undefined
|
|
226
|
+
: ((_h = (_g = (_f = (_e = c.url) !== null && _e !== void 0 ? _e : (endpointAlias ? params[endpointAlias] : undefined)) !== null && _f !== void 0 ? _f : params.url) !== null && _g !== void 0 ? _g : params.base_url) !== null && _h !== void 0 ? _h : params.api_base_url);
|
|
227
|
+
if (kind !== "avatar") {
|
|
228
|
+
delete params.url;
|
|
229
|
+
delete params.base_url;
|
|
230
|
+
delete params.api_base_url;
|
|
231
|
+
if (endpointAlias)
|
|
232
|
+
delete params[endpointAlias];
|
|
233
|
+
}
|
|
201
234
|
const result = clean(Object.fromEntries(allowed.map((key) => [key, c[key]])));
|
|
202
235
|
if (url !== undefined)
|
|
203
236
|
result.url = url;
|
|
204
237
|
if ((kind === "llm" || kind === "asr") && params.model !== undefined) {
|
|
205
|
-
result.model = (
|
|
238
|
+
result.model = (_j = c.model) !== null && _j !== void 0 ? _j : params.model;
|
|
206
239
|
delete params.model;
|
|
207
240
|
}
|
|
208
241
|
if (kind === "tts" && c._minimaxPresetModel !== undefined)
|
|
@@ -210,7 +243,7 @@ function toV3Module(config, kind, errors = []) {
|
|
|
210
243
|
if (kind === "avatar") {
|
|
211
244
|
if (!["akool", "liveavatar", "anam", "generic", "sensetime", "spatius"].includes(c.vendor))
|
|
212
245
|
errors.push(`${path}.vendor`);
|
|
213
|
-
result.enabled = (
|
|
246
|
+
result.enabled = (_k = c.enable) !== null && _k !== void 0 ? _k : true;
|
|
214
247
|
}
|
|
215
248
|
else if (c.enable === false)
|
|
216
249
|
errors.push(`${path}.enable`);
|
|
@@ -556,6 +589,15 @@ class SavedAgent {
|
|
|
556
589
|
createSession(options) {
|
|
557
590
|
return (0, session_backend_js_1.createStoredSession)(this.client, options, { agent_id: this.id });
|
|
558
591
|
}
|
|
592
|
+
/** Create an outbound phone-call session using this saved agent. */
|
|
593
|
+
call(options) {
|
|
594
|
+
return (0, session_backend_js_1.createStoredSession)(this.client, (0, session_backend_js_1.callSessionOptions)(options), { agent_id: this.id }, undefined, {
|
|
595
|
+
type: "telephony",
|
|
596
|
+
from: options.from,
|
|
597
|
+
to: options.to,
|
|
598
|
+
call_policy: options.callPolicy,
|
|
599
|
+
});
|
|
600
|
+
}
|
|
559
601
|
/** Save a revised configuration to this stored identity, preserving its name by default. */
|
|
560
602
|
update(config, options = {}) {
|
|
561
603
|
var _a;
|
|
@@ -603,10 +645,8 @@ class SavedAgent {
|
|
|
603
645
|
setNumber(number_1, agent_1) {
|
|
604
646
|
return __awaiter(this, arguments, void 0, function* (number, agent, options = {}) {
|
|
605
647
|
var _a, e_2, _b, _c;
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
max_silence_duration_ms: options.maxSilenceDurationMs,
|
|
609
|
-
});
|
|
648
|
+
var _d, _e, _f, _g;
|
|
649
|
+
const policy = clean(Object.assign(Object.assign({}, options.callPolicy), { max_call_duration_seconds: (_d = options.maxCallDurationSeconds) !== null && _d !== void 0 ? _d : (_e = options.callPolicy) === null || _e === void 0 ? void 0 : _e.max_call_duration_seconds, max_silence_duration_ms: (_f = options.maxSilenceDurationMs) !== null && _f !== void 0 ? _f : (_g = options.callPolicy) === null || _g === void 0 ? void 0 : _g.max_silence_duration_ms }));
|
|
610
650
|
let id;
|
|
611
651
|
if (typeof number === "object")
|
|
612
652
|
id = number.number_id;
|
|
@@ -614,9 +654,9 @@ class SavedAgent {
|
|
|
614
654
|
const normalize = (v) => v.replace(/[\s().-]/g, "");
|
|
615
655
|
let found;
|
|
616
656
|
try {
|
|
617
|
-
for (var
|
|
618
|
-
_c =
|
|
619
|
-
|
|
657
|
+
for (var _h = true, _j = __asyncValues(this.client.v3.numbers.listAll({ limit: 100 })), _k; _k = yield _j.next(), _a = _k.done, !_a; _h = true) {
|
|
658
|
+
_c = _k.value;
|
|
659
|
+
_h = false;
|
|
620
660
|
const candidate = _c;
|
|
621
661
|
if (normalize(candidate.number) === normalize(number)) {
|
|
622
662
|
found = candidate;
|
|
@@ -627,7 +667,7 @@ class SavedAgent {
|
|
|
627
667
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
628
668
|
finally {
|
|
629
669
|
try {
|
|
630
|
-
if (!
|
|
670
|
+
if (!_h && !_a && (_b = _j.return)) yield _b.call(_j);
|
|
631
671
|
}
|
|
632
672
|
finally { if (e_2) throw e_2.error; }
|
|
633
673
|
}
|
|
@@ -643,7 +683,9 @@ class SavedAgent {
|
|
|
643
683
|
return yield this.client.v3.numbers.update({
|
|
644
684
|
id,
|
|
645
685
|
ifMatch: etag(current),
|
|
646
|
-
inbound: Object.assign({ agent }, (Object.keys(policy).length
|
|
686
|
+
inbound: Object.assign({ agent }, (options.callPolicy !== undefined || Object.keys(policy).length
|
|
687
|
+
? { call_policy: policy }
|
|
688
|
+
: {})),
|
|
647
689
|
});
|
|
648
690
|
}
|
|
649
691
|
catch (error) {
|