agora-agents 2.12.0 → 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 +38 -3
- package/dist/cjs/AgoraPoolClient.d.ts +15 -27
- package/dist/cjs/AgoraPoolClient.js +75 -54
- package/dist/cjs/BaseClient.js +3 -2
- package/dist/cjs/agentkit/Agent.d.ts +14 -1
- package/dist/cjs/agentkit/Agent.js +126 -9
- package/dist/cjs/agentkit/AgentSession.d.ts +11 -2
- package/dist/cjs/agentkit/AgentSession.js +134 -22
- package/dist/cjs/agentkit/index.d.ts +4 -1
- package/dist/cjs/agentkit/index.js +12 -2
- package/dist/cjs/agentkit/session-backend.d.ts +25 -0
- package/dist/cjs/agentkit/session-backend.js +197 -0
- package/dist/cjs/agentkit/types.d.ts +27 -4
- package/dist/cjs/agentkit/v3.d.ts +70 -0
- package/dist/cjs/agentkit/v3.js +700 -0
- package/dist/cjs/agentkit/vendors/avatar.d.ts +24 -12
- package/dist/cjs/agentkit/vendors/avatar.js +48 -3
- package/dist/cjs/agentkit/vendors/base.d.ts +8 -0
- package/dist/cjs/agentkit/vendors/base.js +33 -7
- 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/core/publicHeaders.d.ts +2 -0
- package/dist/cjs/core/publicHeaders.js +8 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +14 -1
- package/dist/cjs/v3/campaign-schema.d.ts +1 -0
- package/dist/cjs/v3/campaign-schema.js +18 -0
- package/dist/cjs/v3/campaigns.d.ts +50 -0
- package/dist/cjs/v3/campaigns.js +81 -0
- package/dist/cjs/v3/contract.d.ts +1 -0
- package/dist/cjs/v3/contract.js +9115 -0
- package/dist/cjs/v3/index.d.ts +15 -0
- package/dist/cjs/v3/index.js +56 -0
- package/dist/cjs/v3/resources.d.ts +121 -0
- package/dist/cjs/v3/resources.js +186 -0
- package/dist/cjs/v3/session-lifecycle.d.ts +51 -0
- package/dist/cjs/v3/session-lifecycle.js +127 -0
- package/dist/cjs/v3/session-schema.d.ts +1 -0
- package/dist/cjs/v3/session-schema.js +18 -0
- package/dist/cjs/v3/transport.d.ts +36 -0
- package/dist/cjs/v3/transport.js +161 -0
- package/dist/cjs/v3/types.d.ts +1004 -0
- package/dist/cjs/v3/types.js +2 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/AgoraPoolClient.d.mts +15 -27
- package/dist/esm/AgoraPoolClient.mjs +69 -48
- package/dist/esm/BaseClient.mjs +3 -2
- package/dist/esm/agentkit/Agent.d.mts +14 -1
- package/dist/esm/agentkit/Agent.mjs +126 -9
- package/dist/esm/agentkit/AgentSession.d.mts +11 -2
- package/dist/esm/agentkit/AgentSession.mjs +134 -22
- package/dist/esm/agentkit/index.d.mts +4 -1
- package/dist/esm/agentkit/index.mjs +2 -0
- package/dist/esm/agentkit/session-backend.d.mts +25 -0
- package/dist/esm/agentkit/session-backend.mjs +191 -0
- package/dist/esm/agentkit/types.d.mts +27 -4
- package/dist/esm/agentkit/v3.d.mts +70 -0
- package/dist/esm/agentkit/v3.mjs +687 -0
- package/dist/esm/agentkit/vendors/avatar.d.mts +24 -12
- package/dist/esm/agentkit/vendors/avatar.mjs +45 -6
- package/dist/esm/agentkit/vendors/base.d.mts +8 -0
- package/dist/esm/agentkit/vendors/base.mjs +33 -7
- 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/core/publicHeaders.d.mts +2 -0
- package/dist/esm/core/publicHeaders.mjs +5 -0
- package/dist/esm/index.d.mts +5 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/v3/campaign-schema.d.mts +1 -0
- package/dist/esm/v3/campaign-schema.mjs +2 -0
- package/dist/esm/v3/campaigns.d.mts +50 -0
- package/dist/esm/v3/campaigns.mjs +77 -0
- package/dist/esm/v3/contract.d.mts +1 -0
- package/dist/esm/v3/contract.mjs +9112 -0
- package/dist/esm/v3/index.d.mts +15 -0
- package/dist/esm/v3/index.mjs +15 -0
- package/dist/esm/v3/resources.d.mts +121 -0
- package/dist/esm/v3/resources.mjs +179 -0
- package/dist/esm/v3/session-lifecycle.d.mts +51 -0
- package/dist/esm/v3/session-lifecycle.mjs +121 -0
- package/dist/esm/v3/session-schema.d.mts +1 -0
- package/dist/esm/v3/session-schema.mjs +2 -0
- package/dist/esm/v3/transport.d.mts +36 -0
- package/dist/esm/v3/transport.mjs +151 -0
- package/dist/esm/v3/types.d.mts +1004 -0
- package/dist/esm/v3/types.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/openapi.yaml +8917 -0
- package/package.json +7 -4
- package/reference.md +3 -0
|
@@ -14,13 +14,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
17
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
29
|
exports.AgentSession = void 0;
|
|
19
30
|
const index_js_1 = require("../errors/index.js");
|
|
31
|
+
const transport_js_1 = require("../v3/transport.js");
|
|
20
32
|
const avatar_types_js_1 = require("./avatar-types.js");
|
|
21
33
|
const debug_js_1 = require("./debug.js");
|
|
22
34
|
const presets_js_1 = require("./presets.js");
|
|
23
35
|
const client_js_1 = require("./preview/client.js");
|
|
36
|
+
const session_backend_js_1 = require("./session-backend.js");
|
|
24
37
|
const token_js_1 = require("./token.js");
|
|
25
38
|
/**
|
|
26
39
|
* AgentSession class for managing agent lifecycle and interactions.
|
|
@@ -56,14 +69,28 @@ const token_js_1 = require("./token.js");
|
|
|
56
69
|
* ```
|
|
57
70
|
*/
|
|
58
71
|
class AgentSession {
|
|
72
|
+
_beginLifecycle() {
|
|
73
|
+
const revision = ++this._lifecycleRevision;
|
|
74
|
+
this._pendingLifecycle = revision;
|
|
75
|
+
return revision;
|
|
76
|
+
}
|
|
77
|
+
_finishLifecycle(revision) {
|
|
78
|
+
if (revision !== undefined && this._pendingLifecycle === revision) {
|
|
79
|
+
this._pendingLifecycle = undefined;
|
|
80
|
+
++this._lifecycleRevision;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
59
83
|
constructor(options) {
|
|
60
84
|
var _a, _b;
|
|
61
85
|
this._previewFeatures = [];
|
|
62
86
|
this._agentId = null;
|
|
63
87
|
this._status = "idle";
|
|
88
|
+
this._lifecycleRevision = 0;
|
|
89
|
+
this._infoReadRevision = 0;
|
|
64
90
|
this._eventHandlers = new Map();
|
|
65
91
|
this._client = options.client;
|
|
66
92
|
this._agent = options.agent;
|
|
93
|
+
this._backend = options.backend;
|
|
67
94
|
this._appId = options.appId;
|
|
68
95
|
this._appCertificate = options.appCertificate;
|
|
69
96
|
this._name = options.name;
|
|
@@ -78,8 +105,8 @@ class AgentSession {
|
|
|
78
105
|
this._expiresIn = options.expiresIn;
|
|
79
106
|
this._debug = options.debug;
|
|
80
107
|
this._warn = (_a = options.warn) !== null && _a !== void 0 ? _a : ((msg) => console.warn(msg));
|
|
81
|
-
// Read authMode from pool client if available, else
|
|
82
|
-
this._authMode = (_b = options.client.authMode) !== null && _b !== void 0 ? _b : "
|
|
108
|
+
// Read authMode from pool client if available, else leave authorization to the supplied client
|
|
109
|
+
this._authMode = (_b = options.client.authMode) !== null && _b !== void 0 ? _b : "token";
|
|
83
110
|
this._agentsClient = options.client.agents;
|
|
84
111
|
this._agentManagementClient = options.client.agentManagement;
|
|
85
112
|
this._sessionBaseUrl = this._clientCurrentUrl();
|
|
@@ -157,6 +184,8 @@ class AgentSession {
|
|
|
157
184
|
* The agent configuration.
|
|
158
185
|
*/
|
|
159
186
|
get agent() {
|
|
187
|
+
if (!this._agent)
|
|
188
|
+
throw new Error("This session uses a saved agent; no local configuration is available");
|
|
160
189
|
return this._agent;
|
|
161
190
|
}
|
|
162
191
|
/**
|
|
@@ -185,19 +214,23 @@ class AgentSession {
|
|
|
185
214
|
* ```
|
|
186
215
|
*/
|
|
187
216
|
get raw() {
|
|
217
|
+
if (this._backend)
|
|
218
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("raw running-agent client");
|
|
188
219
|
return this._agentsClient;
|
|
189
220
|
}
|
|
190
221
|
/**
|
|
191
222
|
* Direct access to the underlying Fern-generated AgentManagement client.
|
|
192
223
|
*/
|
|
193
224
|
get rawAgentManagement() {
|
|
225
|
+
if (this._backend)
|
|
226
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("rawAgentManagement");
|
|
194
227
|
return this._agentManagementClient;
|
|
195
228
|
}
|
|
196
229
|
/**
|
|
197
230
|
* Returns true when the agent is configured for MLLM (multimodal end-to-end audio).
|
|
198
231
|
*/
|
|
199
232
|
_isMllmMode() {
|
|
200
|
-
const mllm = this.
|
|
233
|
+
const mllm = this.agent.mllm;
|
|
201
234
|
if ((mllm === null || mllm === void 0 ? void 0 : mllm.enable) === true) {
|
|
202
235
|
return true;
|
|
203
236
|
}
|
|
@@ -213,10 +246,10 @@ class AgentSession {
|
|
|
213
246
|
*/
|
|
214
247
|
_warnOnDroppedMllmInstructions() {
|
|
215
248
|
var _a;
|
|
216
|
-
if (!this._isMllmMode() || this.
|
|
249
|
+
if (!this._isMllmMode() || this.agent.instructions === undefined) {
|
|
217
250
|
return;
|
|
218
251
|
}
|
|
219
|
-
const params = (_a = this.
|
|
252
|
+
const params = (_a = this.agent.mllm) === null || _a === void 0 ? void 0 : _a.params;
|
|
220
253
|
if (typeof (params === null || params === void 0 ? void 0 : params.instructions) === "string" && params.instructions.length > 0) {
|
|
221
254
|
return;
|
|
222
255
|
}
|
|
@@ -233,9 +266,9 @@ class AgentSession {
|
|
|
233
266
|
* @throws {Error} If configuration is invalid
|
|
234
267
|
*/
|
|
235
268
|
_validateAvatarConfig() {
|
|
236
|
-
const agentConfig = this.
|
|
269
|
+
const agentConfig = this.agent.config;
|
|
237
270
|
const avatar = agentConfig.avatar;
|
|
238
|
-
const tts = this.
|
|
271
|
+
const tts = this.agent.tts;
|
|
239
272
|
// Skip validation if no avatar is configured
|
|
240
273
|
if (!avatar || avatar.enable === false) {
|
|
241
274
|
return;
|
|
@@ -379,13 +412,13 @@ class AgentSession {
|
|
|
379
412
|
}
|
|
380
413
|
}
|
|
381
414
|
}
|
|
382
|
-
if ((0, presets_js_1.inferAsrPreset)(this.
|
|
415
|
+
if ((0, presets_js_1.inferAsrPreset)(this.agent.stt)) {
|
|
383
416
|
skipVendorValidationCategories.add("asr");
|
|
384
417
|
}
|
|
385
|
-
if ((0, presets_js_1.inferLlmPreset)(this.
|
|
418
|
+
if ((0, presets_js_1.inferLlmPreset)(this.agent.llm)) {
|
|
386
419
|
skipVendorValidationCategories.add("llm");
|
|
387
420
|
}
|
|
388
|
-
if ((0, presets_js_1.inferTtsPreset)(this.
|
|
421
|
+
if ((0, presets_js_1.inferTtsPreset)(this.agent.tts)) {
|
|
389
422
|
skipVendorValidationCategories.add("tts");
|
|
390
423
|
}
|
|
391
424
|
return { skipVendorValidationCategories, allowMissingVendorCategories };
|
|
@@ -404,6 +437,25 @@ class AgentSession {
|
|
|
404
437
|
if (this._status !== "idle" && this._status !== "stopped" && this._status !== "error") {
|
|
405
438
|
throw new Error(`Cannot start session in ${this._status} state`);
|
|
406
439
|
}
|
|
440
|
+
if (this._backend) {
|
|
441
|
+
const lifecycle = this._beginLifecycle();
|
|
442
|
+
this._agentId = null;
|
|
443
|
+
this._status = "starting";
|
|
444
|
+
try {
|
|
445
|
+
const started = yield this._backend.start();
|
|
446
|
+
this._agentId = started.id;
|
|
447
|
+
this._status = started.status;
|
|
448
|
+
this._finishLifecycle(lifecycle);
|
|
449
|
+
this._emit("started", { agentId: this._agentId, sessionId: this._agentId });
|
|
450
|
+
return this._agentId;
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
this._status = "error";
|
|
454
|
+
this._finishLifecycle(lifecycle);
|
|
455
|
+
this._emit("error", error);
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
407
459
|
// Validate avatar configuration before starting
|
|
408
460
|
this._validateAvatarConfig();
|
|
409
461
|
this._warnOnDroppedMllmInstructions();
|
|
@@ -414,7 +466,7 @@ class AgentSession {
|
|
|
414
466
|
}
|
|
415
467
|
this._status = "starting";
|
|
416
468
|
try {
|
|
417
|
-
const pipelineId = (_a = this._pipelineId) !== null && _a !== void 0 ? _a : this.
|
|
469
|
+
const pipelineId = (_a = this._pipelineId) !== null && _a !== void 0 ? _a : this.agent.pipelineId;
|
|
418
470
|
// appCertificate presence is guaranteed by the guard above when no token is provided.
|
|
419
471
|
let expiresIn = this._expiresIn;
|
|
420
472
|
if (expiresIn !== undefined) {
|
|
@@ -428,7 +480,7 @@ class AgentSession {
|
|
|
428
480
|
expiresIn,
|
|
429
481
|
};
|
|
430
482
|
const { skipVendorValidationCategories, allowMissingVendorCategories } = this._vendorValidationCategories(pipelineId);
|
|
431
|
-
const properties = this.
|
|
483
|
+
const properties = this.agent.toProperties(Object.assign({ channel: this._channel, agentUid: this._agentUid, remoteUids: this._remoteUids, idleTimeout: this._idleTimeout, enableStringUid: this._enableStringUid, skipVendorValidationCategories,
|
|
432
484
|
allowMissingVendorCategories }, tokenOpts));
|
|
433
485
|
const resolved = (0, presets_js_1.resolveSessionPresets)({
|
|
434
486
|
preset: this._preset,
|
|
@@ -484,29 +536,47 @@ class AgentSession {
|
|
|
484
536
|
*/
|
|
485
537
|
stop() {
|
|
486
538
|
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
-
if (this._status !== "running") {
|
|
539
|
+
if (this._status !== "running" && !(this._backend && this._status === "starting")) {
|
|
488
540
|
throw new Error(`Cannot stop session in ${this._status} state`);
|
|
489
541
|
}
|
|
490
542
|
if (!this._agentId) {
|
|
491
543
|
throw new Error("No agent ID available");
|
|
492
544
|
}
|
|
545
|
+
const lifecycle = this._backend ? this._beginLifecycle() : undefined;
|
|
493
546
|
this._status = "stopping";
|
|
494
547
|
try {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
548
|
+
if (this._backend)
|
|
549
|
+
yield this._backend.stop(this._agentId);
|
|
550
|
+
else
|
|
551
|
+
yield this._agentsClient.stop({
|
|
552
|
+
appid: this._appId,
|
|
553
|
+
agentId: this._agentId,
|
|
554
|
+
}, { headers: this._requestHeaders() });
|
|
499
555
|
this._status = "stopped";
|
|
500
|
-
this.
|
|
556
|
+
this._finishLifecycle(lifecycle);
|
|
557
|
+
this._emit("stopped", Object.assign({ agentId: this._agentId }, (this._backend ? { sessionId: this._agentId } : {})));
|
|
501
558
|
}
|
|
502
559
|
catch (error) {
|
|
503
560
|
// Handle 404 "task not found" gracefully - agent is already stopped
|
|
504
|
-
if (error instanceof index_js_1.AgoraError && error.statusCode === 404) {
|
|
561
|
+
if (!this._backend && error instanceof index_js_1.AgoraError && error.statusCode === 404) {
|
|
505
562
|
this._status = "stopped";
|
|
506
|
-
this._emit("stopped", { agentId: this._agentId });
|
|
563
|
+
this._emit("stopped", Object.assign({ agentId: this._agentId }, (this._backend ? { sessionId: this._agentId } : {})));
|
|
507
564
|
return; // Don't throw - agent is already stopped
|
|
508
565
|
}
|
|
509
|
-
|
|
566
|
+
const reason = error instanceof transport_js_1.V3Error &&
|
|
567
|
+
error.statusCode === 409 &&
|
|
568
|
+
error.body !== null &&
|
|
569
|
+
typeof error.body === "object" &&
|
|
570
|
+
"reason" in error.body
|
|
571
|
+
? error.body.reason
|
|
572
|
+
: undefined;
|
|
573
|
+
this._status =
|
|
574
|
+
this._backend && reason === "TaskNotRunning"
|
|
575
|
+
? "stopped"
|
|
576
|
+
: this._backend && reason === "TaskConflict"
|
|
577
|
+
? "stopping"
|
|
578
|
+
: "error";
|
|
579
|
+
this._finishLifecycle(lifecycle);
|
|
510
580
|
this._emit("error", error);
|
|
511
581
|
throw error;
|
|
512
582
|
}
|
|
@@ -520,6 +590,8 @@ class AgentSession {
|
|
|
520
590
|
*/
|
|
521
591
|
say(text, options) {
|
|
522
592
|
return __awaiter(this, void 0, void 0, function* () {
|
|
593
|
+
if (this._backend)
|
|
594
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("say");
|
|
523
595
|
if (this._status !== "running") {
|
|
524
596
|
throw new Error(`Cannot say in ${this._status} state`);
|
|
525
597
|
}
|
|
@@ -540,6 +612,8 @@ class AgentSession {
|
|
|
540
612
|
*/
|
|
541
613
|
interrupt() {
|
|
542
614
|
return __awaiter(this, void 0, void 0, function* () {
|
|
615
|
+
if (this._backend)
|
|
616
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("interrupt");
|
|
543
617
|
if (this._status !== "running") {
|
|
544
618
|
throw new Error(`Cannot interrupt in ${this._status} state`);
|
|
545
619
|
}
|
|
@@ -557,6 +631,8 @@ class AgentSession {
|
|
|
557
631
|
*/
|
|
558
632
|
think(text, options) {
|
|
559
633
|
return __awaiter(this, void 0, void 0, function* () {
|
|
634
|
+
if (this._backend)
|
|
635
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("think");
|
|
560
636
|
if (this._status !== "running") {
|
|
561
637
|
throw new Error(`Cannot think in ${this._status} state`);
|
|
562
638
|
}
|
|
@@ -582,16 +658,28 @@ class AgentSession {
|
|
|
582
658
|
*/
|
|
583
659
|
update(config) {
|
|
584
660
|
return __awaiter(this, void 0, void 0, function* () {
|
|
661
|
+
var _a;
|
|
585
662
|
if (this._status !== "running") {
|
|
586
663
|
throw new Error(`Cannot update in ${this._status} state`);
|
|
587
664
|
}
|
|
588
665
|
if (!this._agentId) {
|
|
589
666
|
throw new Error("No agent ID available");
|
|
590
667
|
}
|
|
668
|
+
if (this._backend) {
|
|
669
|
+
yield this._backend.update(this._agentId, config);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
let properties = config;
|
|
673
|
+
if ((config === null || config === void 0 ? void 0 : config.messages) !== undefined) {
|
|
674
|
+
if (((_a = config.llm) === null || _a === void 0 ? void 0 : _a.system_messages) !== undefined)
|
|
675
|
+
throw new Error("Provide messages or llm.system_messages, not both");
|
|
676
|
+
const { messages } = config, remaining = __rest(config, ["messages"]);
|
|
677
|
+
properties = Object.assign(Object.assign({}, remaining), { llm: Object.assign(Object.assign({}, remaining.llm), { system_messages: messages }) });
|
|
678
|
+
}
|
|
591
679
|
yield this._agentsClient.update({
|
|
592
680
|
appid: this._appId,
|
|
593
681
|
agentId: this._agentId,
|
|
594
|
-
properties
|
|
682
|
+
properties,
|
|
595
683
|
}, { headers: this._requestHeaders() });
|
|
596
684
|
});
|
|
597
685
|
}
|
|
@@ -602,6 +690,8 @@ class AgentSession {
|
|
|
602
690
|
*/
|
|
603
691
|
getHistory() {
|
|
604
692
|
return __awaiter(this, void 0, void 0, function* () {
|
|
693
|
+
if (this._backend)
|
|
694
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("getHistory");
|
|
605
695
|
if (!this._agentId) {
|
|
606
696
|
throw new Error("No agent ID available");
|
|
607
697
|
}
|
|
@@ -618,6 +708,8 @@ class AgentSession {
|
|
|
618
708
|
*/
|
|
619
709
|
getTurns(options) {
|
|
620
710
|
return __awaiter(this, void 0, void 0, function* () {
|
|
711
|
+
if (this._backend)
|
|
712
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("getTurns");
|
|
621
713
|
if (!this._agentId) {
|
|
622
714
|
throw new Error("No agent ID available");
|
|
623
715
|
}
|
|
@@ -638,6 +730,8 @@ class AgentSession {
|
|
|
638
730
|
getAllTurns(options) {
|
|
639
731
|
return __awaiter(this, void 0, void 0, function* () {
|
|
640
732
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
733
|
+
if (this._backend)
|
|
734
|
+
throw new session_backend_js_1.UnsupportedSessionOperationError("getAllTurns");
|
|
641
735
|
let page = yield this.getTurns({ page_index: 1, page_size: options === null || options === void 0 ? void 0 : options.page_size });
|
|
642
736
|
const allTurns = [...((_a = page.turns) !== null && _a !== void 0 ? _a : [])];
|
|
643
737
|
let currentPage = (_c = (_b = page.pagination) === null || _b === void 0 ? void 0 : _b.page_index) !== null && _c !== void 0 ? _c : 1;
|
|
@@ -678,9 +772,27 @@ class AgentSession {
|
|
|
678
772
|
*/
|
|
679
773
|
getInfo() {
|
|
680
774
|
return __awaiter(this, void 0, void 0, function* () {
|
|
775
|
+
var _a;
|
|
681
776
|
if (!this._agentId) {
|
|
682
777
|
throw new Error("No agent ID available");
|
|
683
778
|
}
|
|
779
|
+
if (this._backend) {
|
|
780
|
+
const id = this._agentId;
|
|
781
|
+
const lifecycle = this._lifecycleRevision;
|
|
782
|
+
const read = ++this._infoReadRevision;
|
|
783
|
+
const info = yield this._backend.getInfo(id);
|
|
784
|
+
if (this._pendingLifecycle !== undefined ||
|
|
785
|
+
lifecycle !== this._lifecycleRevision ||
|
|
786
|
+
read !== this._infoReadRevision ||
|
|
787
|
+
id !== this._agentId)
|
|
788
|
+
return info;
|
|
789
|
+
const status = (_a = info.status) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
790
|
+
if (status === "failed")
|
|
791
|
+
this._status = "error";
|
|
792
|
+
else if (status && ["idle", "starting", "running", "stopping", "stopped"].includes(status))
|
|
793
|
+
this._status = status;
|
|
794
|
+
return info;
|
|
795
|
+
}
|
|
684
796
|
return this._agentsClient.get({
|
|
685
797
|
appid: this._appId,
|
|
686
798
|
agentId: this._agentId,
|
|
@@ -34,9 +34,12 @@ export { createPreviewRoute, PREVIEW_API_BASE_URL, PREVIEW_FEATURE_HEADER, Previ
|
|
|
34
34
|
export type { GeminiTTSConfig, GeminiTTSModel, GeminiTTSOptions } from "./preview/gemini-tts.js";
|
|
35
35
|
export { GeminiTTS, GeminiTTSModels } from "./preview/gemini-tts.js";
|
|
36
36
|
export type { AvatarVendor, CNAvatarVendor, CNLlmVendor, CNMllmVendor, CNSttVendor, CNTtsVendor, GlobalAvatarVendor, GlobalLlmVendor, GlobalMllmVendor, GlobalSttVendor, GlobalTtsVendor, LlmVendor, SttVendor, TtsVendor, } from "./region-vendors.js";
|
|
37
|
+
export { UnsupportedSessionOperationError } from "./session-backend.js";
|
|
37
38
|
export type { GenerateConvoAITokenOptions, GenerateTokenOptions, } from "./token.js";
|
|
38
39
|
export { ExpiresIn, generateConvoAIToken, generateRtcToken, MAX_EXPIRY_SECONDS, } from "./token.js";
|
|
39
|
-
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
|
+
export type { AssignNumberOptions, DeployOptions, SaveOptions, SecretRef, VariableDefinition } from "./v3.js";
|
|
42
|
+
export { DeployedAgent, NumberNotFoundError, SavedAgent, SecretRefNotSupportedError, secretRef, UnsupportedFieldError, } from "./v3.js";
|
|
40
43
|
export type { AkoolAvatarOptions, AnamAvatarOptions, GenericAvatarOptions, HeyGenAvatarOptions, LemonSliceOptions, LiveAvatarAvatarOptions, ProtofaceOptions, TavusOptions, } from "./vendors/avatar.js";
|
|
41
44
|
export { AkoolAvatar, AnamAvatar, GenericAvatar, HeyGenAvatar, LemonSlice, LiveAvatarAvatar, Protoface, Tavus, } from "./vendors/avatar.js";
|
|
42
45
|
export type { AkoolSampleRate, CartesiaSampleRate, ElevenLabsSampleRate, HeyGenSampleRate, LiveAvatarSampleRate, MicrosoftSampleRate, SampleRate, } from "./vendors/base.js";
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.PREVIEW_FEATURE_HEADER = exports.PREVIEW_API_BASE_URL = exports.createPreviewRoute = exports.normalizePresetInput = exports.AgentPresets = exports.redactSecrets = exports.redactHeadersForDebug = exports.REDACTED = exports.TurnDetectionTypeValues = exports.ThinkOnThinkingActionInterrupt = exports.ThinkOnThinkingActionIgnore = exports.ThinkOnSpeakingActionInterrupt = exports.ThinkOnSpeakingActionIgnore = exports.ThinkOnListeningActionInterrupt = exports.ThinkOnListeningActionInject = exports.ThinkOnListeningActionIgnore = exports.SpeakPriorityValues = exports.SpeakPriorityInterrupt = exports.SpeakPriorityIgnore = exports.SpeakPriorityAppend = exports.SilenceActionValues = exports.SalModeValues = exports.MllmTurnDetectionModeValues = exports.MllmTurnDetectionModeServerVad = exports.MllmTurnDetectionModeSemanticVad = exports.MllmTurnDetectionModeAgoraVad = exports.InterruptionModeValues = exports.InterruptionModeStartOfSpeech = exports.InterruptionModeKeywords = exports.InterruptionDisabledStrategyIgnore = exports.InterruptionDisabledStrategyAppend = exports.InterruptionDisabledStrategy = exports.Geofence = exports.FillerWordsSelectionRule = exports.DataChannel = exports.CredentialMode = exports.AudioScenario = exports.validateTtsSampleRate = exports.validateAvatarConfig = exports.toBaseAvatarConfig = exports.isSpatiusAvatar = exports.isSensetimeAvatar = exports.isLiveAvatarAvatar = exports.isHeyGenAvatar = exports.isGenericAvatar = exports.isAvatarTokenManaged = exports.isAnamAvatar = exports.isAkoolAvatar = exports.AgentSession = exports.Agent = void 0;
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
24
|
+
exports.TencentTTS = exports.TencentSTT = exports.TencentLLM = exports.StepFunTTS = exports.SpatiusAvatar = exports.SensetimeAvatar = exports.MiniMaxCNTTS = exports.MicrosoftCNTTS = exports.MicrosoftCNSTT = exports.FengmingSTT = exports.DeepSeekLLM = exports.CosyVoiceTTS = exports.BytedanceTTS = exports.BytedanceLLM = exports.BytedanceDuplexTTS = exports.AliyunLLM = exports.BaseTTS = exports.BaseSTT = exports.BaseMLLM = exports.BaseLLM = exports.BaseCNTTS = exports.BaseCNSTT = exports.BaseCNMLLM = exports.BaseCNLLM = exports.BaseCNAvatar = exports.BaseAvatar = exports.Tavus = exports.Protoface = exports.LiveAvatarAvatar = exports.LemonSlice = exports.HeyGenAvatar = exports.GenericAvatar = exports.AnamAvatar = exports.AkoolAvatar = exports.UnsupportedFieldError = exports.secretRef = exports.SecretRefNotSupportedError = exports.SavedAgent = exports.NumberNotFoundError = exports.DeployedAgent = exports.MAX_EXPIRY_SECONDS = exports.generateRtcToken = exports.generateConvoAIToken = exports.ExpiresIn = exports.UnsupportedSessionOperationError = exports.GeminiTTSModels = exports.GeminiTTS = exports.requiredPreviewFeatures = exports.previewRequestHeaders = exports.PreviewFeatures = void 0;
|
|
25
|
+
exports.MistralTTS = exports.MiniMaxTTS = exports.MicrosoftTTS = exports.HumeAITTS = exports.GradiumTTS = exports.GoogleTTS = exports.GenericTTS = exports.FishAudioTTS = exports.ElevenLabsTTS = exports.DeepgramTTS = exports.CartesiaTTS = exports.AmazonTTS = exports.XAiSTT = exports.SpeechmaticsSTT = exports.SmallestAISTT = exports.SarvamSTT = exports.OpenAISTT = exports.MicrosoftSTT = exports.GoogleSTT = exports.GeminiTranscriptionMode = exports.GeminiSTTModels = exports.GeminiSTT = exports.DeepgramSTT = exports.AssemblyAISTT = exports.AresSTT = exports.AmazonSTT = exports.XaiGrok = exports.VertexAI = exports.QwenOmni = exports.OpenAIRealtime = exports.OpenAIGPTLive = exports.GeminiThinkingLevels = exports.GeminiLiveModels = exports.GeminiLive = exports.GEMINI_PREVIEW_MLLM_URL = exports.GEMINI_MLLM_URL = exports.GEMINI_MLLM_DEFAULT_MODEL = exports.AzureOpenAIRealtime = exports.VertexAILLM = exports.OpenAI = exports.Groq = exports.Gemini = exports.Dify = exports.CustomLLM = exports.AzureOpenAI = exports.Anthropic = exports.AmazonBedrock = exports.XfyunSTT = exports.XfyunDialectSTT = exports.XfyunBigModelSTT = void 0;
|
|
26
|
+
exports.XAiTTS = exports.TypecastTTS = exports.SmallestAITTS = exports.SarvamTTS = exports.RimeTTS = exports.OpenAITTS = exports.MurfTTS = void 0;
|
|
26
27
|
// Core classes
|
|
27
28
|
var Agent_js_1 = require("./Agent.js");
|
|
28
29
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return Agent_js_1.Agent; } });
|
|
@@ -88,12 +89,21 @@ Object.defineProperty(exports, "requiredPreviewFeatures", { enumerable: true, ge
|
|
|
88
89
|
var gemini_tts_js_1 = require("./preview/gemini-tts.js");
|
|
89
90
|
Object.defineProperty(exports, "GeminiTTS", { enumerable: true, get: function () { return gemini_tts_js_1.GeminiTTS; } });
|
|
90
91
|
Object.defineProperty(exports, "GeminiTTSModels", { enumerable: true, get: function () { return gemini_tts_js_1.GeminiTTSModels; } });
|
|
92
|
+
var session_backend_js_1 = require("./session-backend.js");
|
|
93
|
+
Object.defineProperty(exports, "UnsupportedSessionOperationError", { enumerable: true, get: function () { return session_backend_js_1.UnsupportedSessionOperationError; } });
|
|
91
94
|
// Token generation
|
|
92
95
|
var token_js_1 = require("./token.js");
|
|
93
96
|
Object.defineProperty(exports, "ExpiresIn", { enumerable: true, get: function () { return token_js_1.ExpiresIn; } });
|
|
94
97
|
Object.defineProperty(exports, "generateConvoAIToken", { enumerable: true, get: function () { return token_js_1.generateConvoAIToken; } });
|
|
95
98
|
Object.defineProperty(exports, "generateRtcToken", { enumerable: true, get: function () { return token_js_1.generateRtcToken; } });
|
|
96
99
|
Object.defineProperty(exports, "MAX_EXPIRY_SECONDS", { enumerable: true, get: function () { return token_js_1.MAX_EXPIRY_SECONDS; } });
|
|
100
|
+
var v3_js_1 = require("./v3.js");
|
|
101
|
+
Object.defineProperty(exports, "DeployedAgent", { enumerable: true, get: function () { return v3_js_1.DeployedAgent; } });
|
|
102
|
+
Object.defineProperty(exports, "NumberNotFoundError", { enumerable: true, get: function () { return v3_js_1.NumberNotFoundError; } });
|
|
103
|
+
Object.defineProperty(exports, "SavedAgent", { enumerable: true, get: function () { return v3_js_1.SavedAgent; } });
|
|
104
|
+
Object.defineProperty(exports, "SecretRefNotSupportedError", { enumerable: true, get: function () { return v3_js_1.SecretRefNotSupportedError; } });
|
|
105
|
+
Object.defineProperty(exports, "secretRef", { enumerable: true, get: function () { return v3_js_1.secretRef; } });
|
|
106
|
+
Object.defineProperty(exports, "UnsupportedFieldError", { enumerable: true, get: function () { return v3_js_1.UnsupportedFieldError; } });
|
|
97
107
|
// Avatar vendor classes
|
|
98
108
|
var avatar_js_1 = require("./vendors/avatar.js");
|
|
99
109
|
Object.defineProperty(exports, "AkoolAvatar", { enumerable: true, get: function () { return avatar_js_1.AkoolAvatar; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Internal adapter for session identities, without mixing them with running-agent IDs. */
|
|
2
|
+
import type { AgoraClient } from "../AgoraPoolClient.js";
|
|
3
|
+
import type { AgentCreateRequest, TelephonyTransport } from "../v3/types.js";
|
|
4
|
+
import type { Agent } from "./Agent.js";
|
|
5
|
+
import { AgentSession } from "./AgentSession.js";
|
|
6
|
+
import type { AgentConfigUpdate, CallOptions, SessionInfo, SessionOptions } from "./types.js";
|
|
7
|
+
export interface SessionBackend {
|
|
8
|
+
start(): Promise<{
|
|
9
|
+
id: string;
|
|
10
|
+
status: "starting" | "running";
|
|
11
|
+
}>;
|
|
12
|
+
stop(id: string): Promise<void>;
|
|
13
|
+
update(id: string, config: AgentConfigUpdate): Promise<void>;
|
|
14
|
+
getInfo(id: string): Promise<SessionInfo>;
|
|
15
|
+
}
|
|
16
|
+
export declare class UnsupportedSessionOperationError extends Error {
|
|
17
|
+
constructor(operation: string);
|
|
18
|
+
}
|
|
19
|
+
/** Validate mixed transports before replacing internal RTC placeholders. */
|
|
20
|
+
export declare function callSessionOptions(options: CallOptions): SessionOptions;
|
|
21
|
+
export declare function createStoredSession(client: AgoraClient, options: SessionOptions, source: {
|
|
22
|
+
agent_id: string;
|
|
23
|
+
} | {
|
|
24
|
+
agent: Omit<AgentCreateRequest, "agent_name">;
|
|
25
|
+
}, config?: Agent, telephony?: TelephonyTransport): AgentSession;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UnsupportedSessionOperationError = void 0;
|
|
13
|
+
exports.callSessionOptions = callSessionOptions;
|
|
14
|
+
exports.createStoredSession = createStoredSession;
|
|
15
|
+
const session_lifecycle_js_1 = require("../v3/session-lifecycle.js");
|
|
16
|
+
const AgentSession_js_1 = require("./AgentSession.js");
|
|
17
|
+
const token_js_1 = require("./token.js");
|
|
18
|
+
class UnsupportedSessionOperationError extends Error {
|
|
19
|
+
constructor(operation) {
|
|
20
|
+
super(`${operation} is not supported by this session backend; start, stop, getInfo and update are available`);
|
|
21
|
+
this.name = "UnsupportedSessionOperationError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.UnsupportedSessionOperationError = UnsupportedSessionOperationError;
|
|
25
|
+
/** Validate mixed transports before replacing internal RTC placeholders. */
|
|
26
|
+
function callSessionOptions(options) {
|
|
27
|
+
for (const key of [
|
|
28
|
+
"channel",
|
|
29
|
+
"remoteUids",
|
|
30
|
+
"agentUid",
|
|
31
|
+
"token",
|
|
32
|
+
"encryption",
|
|
33
|
+
"audioScenario",
|
|
34
|
+
"geofence",
|
|
35
|
+
"enableStringUid",
|
|
36
|
+
"expiresIn",
|
|
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"]) {
|
|
46
|
+
if (key in options && options[key] !== undefined)
|
|
47
|
+
throw new Error(`${key} is not supported by this session backend`);
|
|
48
|
+
}
|
|
49
|
+
const lifecycle = {};
|
|
50
|
+
for (const [key, wire] of [
|
|
51
|
+
["idleTimeout", "idle_timeout_ms"],
|
|
52
|
+
["maxDuration", "max_duration_ms"],
|
|
53
|
+
]) {
|
|
54
|
+
if (options[key] !== undefined)
|
|
55
|
+
lifecycle[wire] = options[key] * 1000;
|
|
56
|
+
}
|
|
57
|
+
if (options.gracefulStop !== undefined)
|
|
58
|
+
lifecycle.graceful_stop = options.gracefulStop;
|
|
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 : {
|
|
60
|
+
type: "rtc",
|
|
61
|
+
channel: options.channel,
|
|
62
|
+
uid: options.agentUid,
|
|
63
|
+
subscribe_uids: options.remoteUids,
|
|
64
|
+
token: options.token,
|
|
65
|
+
encryption: options.encryption,
|
|
66
|
+
audio_scenario: options.audioScenario,
|
|
67
|
+
geofence: options.geofence,
|
|
68
|
+
} }), (Object.keys(lifecycle).length ? { lifecycle } : {}))));
|
|
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;
|
|
89
|
+
let successfullyStarted = false;
|
|
90
|
+
const backend = {
|
|
91
|
+
start() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
if (payload.idempotencyKey && successfullyStarted)
|
|
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
|
+
}
|
|
124
|
+
const result = "agent_id" in payload
|
|
125
|
+
? yield client.v3.sessions.start(payload)
|
|
126
|
+
: yield client.v3.sessions.startEphemeral(payload);
|
|
127
|
+
if (typeof result.agent_session_id !== "string" || !result.agent_session_id.trim()) {
|
|
128
|
+
throw new Error("Session start response is missing agent_session_id");
|
|
129
|
+
}
|
|
130
|
+
successfullyStarted = true;
|
|
131
|
+
return { id: result.agent_session_id, status: result.status === "STARTING" ? "starting" : "running" };
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
stop(id) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
yield client.v3.sessions.stop({ agentSessionId: id });
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
update(id, config) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
var _a, _b, _c;
|
|
142
|
+
const input = config;
|
|
143
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
144
|
+
throw new Error("Invalid session update");
|
|
145
|
+
for (const key of Object.keys(input))
|
|
146
|
+
if (!["token", "messages", "llm"].includes(key))
|
|
147
|
+
throw new Error(`Unsupported session update field: ${key}`);
|
|
148
|
+
if (input.messages !== undefined && ((_a = input.llm) === null || _a === void 0 ? void 0 : _a.system_messages) !== undefined)
|
|
149
|
+
throw new Error("Provide messages or llm.system_messages, not both");
|
|
150
|
+
const patch = {};
|
|
151
|
+
if (input.token !== undefined) {
|
|
152
|
+
if (typeof input.token !== "string" || !input.token)
|
|
153
|
+
throw new Error("token must be a string");
|
|
154
|
+
patch.transport = { token: input.token };
|
|
155
|
+
}
|
|
156
|
+
const overrides = {};
|
|
157
|
+
const messages = (_b = input.messages) !== null && _b !== void 0 ? _b : (_c = input.llm) === null || _c === void 0 ? void 0 : _c.system_messages;
|
|
158
|
+
if (messages !== undefined) {
|
|
159
|
+
if (!Array.isArray(messages) ||
|
|
160
|
+
messages.some((message) => !message ||
|
|
161
|
+
!["system", "user", "assistant"].includes(message.role) ||
|
|
162
|
+
typeof message.content !== "string" ||
|
|
163
|
+
Object.keys(message).some((key) => !["role", "content"].includes(key))))
|
|
164
|
+
throw new Error("Invalid session messages");
|
|
165
|
+
overrides.messages = messages;
|
|
166
|
+
}
|
|
167
|
+
for (const kind of ["llm"])
|
|
168
|
+
if (input[kind] !== undefined) {
|
|
169
|
+
const module = input[kind];
|
|
170
|
+
if (!module ||
|
|
171
|
+
typeof module !== "object" ||
|
|
172
|
+
Array.isArray(module) ||
|
|
173
|
+
Object.keys(module).some((key) => !["params", ...(kind === "llm" ? ["system_messages"] : [])].includes(key)))
|
|
174
|
+
throw new Error(`Invalid ${kind} update`);
|
|
175
|
+
if (module.params !== undefined) {
|
|
176
|
+
if (!module.params || typeof module.params !== "object" || Array.isArray(module.params))
|
|
177
|
+
throw new Error("params must be an object");
|
|
178
|
+
if (Object.keys(module.params).some((key) => ["url", "base_url", "api_base_url", "endpoint"].includes(key.toLowerCase())))
|
|
179
|
+
throw new Error("Runtime endpoint aliases are not mutable");
|
|
180
|
+
overrides.pipeline = { [kind]: { params: module.params } };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (Object.keys(overrides).length)
|
|
184
|
+
patch.agent = { overrides };
|
|
185
|
+
yield client.v3.sessions.update(Object.assign({ agentSessionId: id }, patch));
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
getInfo(id) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
const info = yield client.v3.sessions.get({ agentSessionId: id });
|
|
192
|
+
return Object.assign(Object.assign({}, info), { message: (_a = info.message) !== null && _a !== void 0 ? _a : undefined, stop_ts: (_b = info.stop_ts) !== null && _b !== void 0 ? _b : undefined });
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
return new AgentSession_js_1.AgentSession(Object.assign(Object.assign({ client, agent: config, backend, appId: client.appId, name: (_a = options.name) !== null && _a !== void 0 ? _a : "session" }, options), { agentUid: (_b = options.agentUid) !== null && _b !== void 0 ? _b : "0" }));
|
|
197
|
+
}
|