agora-agents 2.12.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +30 -1
  2. package/dist/cjs/AgoraPoolClient.d.ts +12 -24
  3. package/dist/cjs/AgoraPoolClient.js +73 -54
  4. package/dist/cjs/BaseClient.js +3 -2
  5. package/dist/cjs/agentkit/Agent.d.ts +7 -0
  6. package/dist/cjs/agentkit/Agent.js +104 -10
  7. package/dist/cjs/agentkit/AgentSession.d.ts +11 -2
  8. package/dist/cjs/agentkit/AgentSession.js +134 -22
  9. package/dist/cjs/agentkit/index.d.ts +3 -0
  10. package/dist/cjs/agentkit/index.js +12 -2
  11. package/dist/cjs/agentkit/session-backend.d.ts +23 -0
  12. package/dist/cjs/agentkit/session-backend.js +136 -0
  13. package/dist/cjs/agentkit/types.d.ts +21 -4
  14. package/dist/cjs/agentkit/v3.d.ts +66 -0
  15. package/dist/cjs/agentkit/v3.js +658 -0
  16. package/dist/cjs/agentkit/vendors/base.d.ts +8 -0
  17. package/dist/cjs/agentkit/vendors/base.js +33 -7
  18. package/dist/cjs/core/publicHeaders.d.ts +2 -0
  19. package/dist/cjs/core/publicHeaders.js +8 -0
  20. package/dist/cjs/index.d.ts +5 -0
  21. package/dist/cjs/index.js +14 -1
  22. package/dist/cjs/v3/campaign-schema.d.ts +1 -0
  23. package/dist/cjs/v3/campaign-schema.js +18 -0
  24. package/dist/cjs/v3/campaigns.d.ts +50 -0
  25. package/dist/cjs/v3/campaigns.js +81 -0
  26. package/dist/cjs/v3/contract.d.ts +1 -0
  27. package/dist/cjs/v3/contract.js +9006 -0
  28. package/dist/cjs/v3/index.d.ts +15 -0
  29. package/dist/cjs/v3/index.js +56 -0
  30. package/dist/cjs/v3/resources.d.ts +121 -0
  31. package/dist/cjs/v3/resources.js +187 -0
  32. package/dist/cjs/v3/session-lifecycle.d.ts +51 -0
  33. package/dist/cjs/v3/session-lifecycle.js +127 -0
  34. package/dist/cjs/v3/session-schema.d.ts +1 -0
  35. package/dist/cjs/v3/session-schema.js +18 -0
  36. package/dist/cjs/v3/transport.d.ts +36 -0
  37. package/dist/cjs/v3/transport.js +161 -0
  38. package/dist/cjs/v3/types.d.ts +992 -0
  39. package/dist/cjs/v3/types.js +2 -0
  40. package/dist/cjs/version.d.ts +1 -1
  41. package/dist/cjs/version.js +1 -1
  42. package/dist/esm/AgoraPoolClient.d.mts +12 -24
  43. package/dist/esm/AgoraPoolClient.mjs +67 -48
  44. package/dist/esm/BaseClient.mjs +3 -2
  45. package/dist/esm/agentkit/Agent.d.mts +7 -0
  46. package/dist/esm/agentkit/Agent.mjs +104 -10
  47. package/dist/esm/agentkit/AgentSession.d.mts +11 -2
  48. package/dist/esm/agentkit/AgentSession.mjs +134 -22
  49. package/dist/esm/agentkit/index.d.mts +3 -0
  50. package/dist/esm/agentkit/index.mjs +2 -0
  51. package/dist/esm/agentkit/session-backend.d.mts +23 -0
  52. package/dist/esm/agentkit/session-backend.mjs +131 -0
  53. package/dist/esm/agentkit/types.d.mts +21 -4
  54. package/dist/esm/agentkit/v3.d.mts +66 -0
  55. package/dist/esm/agentkit/v3.mjs +645 -0
  56. package/dist/esm/agentkit/vendors/base.d.mts +8 -0
  57. package/dist/esm/agentkit/vendors/base.mjs +33 -7
  58. package/dist/esm/core/publicHeaders.d.mts +2 -0
  59. package/dist/esm/core/publicHeaders.mjs +5 -0
  60. package/dist/esm/index.d.mts +5 -0
  61. package/dist/esm/index.mjs +3 -0
  62. package/dist/esm/v3/campaign-schema.d.mts +1 -0
  63. package/dist/esm/v3/campaign-schema.mjs +2 -0
  64. package/dist/esm/v3/campaigns.d.mts +50 -0
  65. package/dist/esm/v3/campaigns.mjs +77 -0
  66. package/dist/esm/v3/contract.d.mts +1 -0
  67. package/dist/esm/v3/contract.mjs +9003 -0
  68. package/dist/esm/v3/index.d.mts +15 -0
  69. package/dist/esm/v3/index.mjs +15 -0
  70. package/dist/esm/v3/resources.d.mts +121 -0
  71. package/dist/esm/v3/resources.mjs +180 -0
  72. package/dist/esm/v3/session-lifecycle.d.mts +51 -0
  73. package/dist/esm/v3/session-lifecycle.mjs +121 -0
  74. package/dist/esm/v3/session-schema.d.mts +1 -0
  75. package/dist/esm/v3/session-schema.mjs +2 -0
  76. package/dist/esm/v3/transport.d.mts +36 -0
  77. package/dist/esm/v3/transport.mjs +151 -0
  78. package/dist/esm/v3/types.d.mts +992 -0
  79. package/dist/esm/v3/types.mjs +1 -0
  80. package/dist/esm/version.d.mts +1 -1
  81. package/dist/esm/version.mjs +1 -1
  82. package/openapi.yaml +8848 -0
  83. package/package.json +3 -2
  84. package/reference.md +3 -0
package/README.md CHANGED
@@ -7,10 +7,18 @@
7
7
 
8
8
  The Agora Agents SDK for TypeScript lets you build real-time voice agents on Agora Conversational AI with a high-level `Agent` / `AgentSession` API and a generated REST client.
9
9
 
10
+ ## Configure once, then run or save
11
+
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
+
14
+ **Saving agents and project provisioning are part of SDK preview `3.0.0-alpha.1`.** 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
+
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
+
10
18
  ## Installation
11
19
 
12
20
  ```sh
13
- npm install agora-agents
21
+ npm install agora-agents@3.0.0-alpha.1
14
22
  ```
15
23
 
16
24
  ## Quick Start
@@ -208,6 +216,9 @@ If you want to bring your own vendor credentials instead of using Agora-managed
208
216
 
209
217
  ## MLLM (Realtime / Multimodal)
210
218
 
219
+ MLLM is supported for existing inline sessions. Saved agents and ephemeral preview sessions support cascaded pipelines only; saving an MLLM configuration or using preview-only session options with it fails before HTTP.
220
+
221
+
211
222
  Use `withMllm()` for OpenAI Realtime, Gemini Live, Vertex AI, or xAI Grok — no STT, LLM, or TTS vendor needed. MLLM mode is enabled automatically.
212
223
 
213
224
  ```typescript
@@ -228,6 +239,21 @@ const agent = new Agent({ client }).withMllm(
228
239
  );
229
240
  ```
230
241
 
242
+ For Gemini 3.8 Live Extended Thinking, use the same single `GeminiLive` class as the regular Live model:
243
+
244
+ ```typescript
245
+ import { GeminiLive } from 'agora-agents';
246
+
247
+ const geminiAgent = new Agent({ client }).withMllm(new GeminiLive({
248
+ apiKey: process.env.GOOGLE_API_KEY!,
249
+ model: 'models/gemini-3.8-live-extended-thinking',
250
+ thinkingLevel: 'medium',
251
+ greetingMessage: 'Hello! Ready to chat.',
252
+ }));
253
+ ```
254
+
255
+ Use `models/gemini-3.8-live` without `thinkingLevel` for the lower-latency model. Gemini sessions use the preview gateway and `agora-feature: gemini-live`; the Google key is sent as `mllm.api_key`. See the [Preview Endpoint guide](./docs/guides/preview-endpoint.md).
256
+
231
257
  See the [MLLM Flow guide](./docs/guides/mllm-flow.md) for full examples with Gemini Live, Vertex AI, and xAI Grok.
232
258
 
233
259
  > Avatars are not supported with MLLM. The avatar publisher requires the cascading ASR + LLM + TTS pipeline; combining `withMllm()` with `withAvatar()` throws at `Agent.toProperties()` and `AgentSession.start()`.
@@ -246,6 +272,9 @@ See the [Avatar Integration guide](./docs/guides/avatars.md) for sample-rate req
246
272
  - [BYOK Guide](./docs/guides/byok.md)
247
273
  - [MLLM Flow](./docs/guides/mllm-flow.md)
248
274
  - [Low-Level API](./docs/guides/low-level-api.md)
275
+ - [Saving agents](./docs/guides/saved-agents.md)
276
+ - [v3 Preview Guide](./docs/guides/v3-preview.md)
277
+ - [v3 Preview Reference](./docs/reference/v3.md)
249
278
 
250
279
  ## Reference
251
280
 
@@ -1,47 +1,39 @@
1
+ import { V3Client, type V3Options } from "./v3/index.js";
1
2
  import type { AgoraArea } from "./agentkit/area.js";
2
3
  import type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
3
4
  import { AgoraClient as BaseAgoraClient } from "./Client.js";
4
5
  import { Pool } from "./core/domain/index.js";
5
6
  /**
6
7
  * Auth mode for the client:
7
- * - `basic`: Customer ID + Secret for REST API (HTTP Basic Auth)
8
8
  * - `token`: Pre-built `agora token=<value>` auth header
9
9
  * - `app-credentials`: appId + appCertificate only; AgentSession generates
10
10
  * a fresh ConvoAI token per API call
11
11
  */
12
- export type AgoraAuthMode = "basic" | "token" | "app-credentials";
12
+ export type AgoraAuthMode = "token" | "app-credentials";
13
13
  export declare namespace AgoraClient {
14
14
  type Options<TArea extends AgoraArea = AgoraArea> = BaseOptions<TArea> & AuthOptions;
15
15
  interface BaseOptions<TArea extends AgoraArea = AgoraArea> extends Omit<BaseClientOptions, "baseUrl" | "environment" | "username" | "password" | "authorization"> {
16
16
  /** The area to use for regional URL selection */
17
17
  area: TArea;
18
+ /** Optional public origin override; baseUrl is a host, without the API prefix. */
19
+ v3?: V3Options;
18
20
  /** Agora App ID — used as the `appid` path parameter and for RTC token generation */
19
21
  appId: string;
20
22
  /** Agora App Certificate — used to sign RTC tokens. Keep this secret. */
21
23
  appCertificate: string;
22
24
  }
23
- /** Use Customer ID + Secret for REST API authentication (HTTP Basic Auth) */
24
- interface BasicAuthOptions {
25
- customerId: string;
26
- customerSecret: string;
27
- authToken?: never;
28
- }
29
25
  /** Use a pre-built Agora token for REST API authentication. Pass the raw token; the SDK sets `Authorization: agora token=<authToken>` automatically. */
30
26
  interface TokenAuthOptions {
31
27
  authToken: string;
32
- customerId?: never;
33
- customerSecret?: never;
34
28
  }
35
29
  /**
36
30
  * Use only appId + appCertificate. AgentSession generates a fresh
37
31
  * ConvoAI token per API call — no Customer Secret required.
38
32
  */
39
33
  interface AppCredentialsOptions {
40
- customerId?: never;
41
- customerSecret?: never;
42
34
  authToken?: never;
43
35
  }
44
- type AuthOptions = BasicAuthOptions | TokenAuthOptions | AppCredentialsOptions;
36
+ type AuthOptions = TokenAuthOptions | AppCredentialsOptions;
45
37
  interface RequestOptions extends BaseRequestOptions {
46
38
  }
47
39
  }
@@ -49,7 +41,7 @@ export declare namespace AgoraClient {
49
41
  * AgoraClient extends the base client with domain pool support for
50
42
  * regional URL cycling and automatic domain selection.
51
43
  *
52
- * Three authentication modes are supported:
44
+ * Two authentication modes are supported:
53
45
  *
54
46
  * **App credentials (recommended)** — no Customer Secret needed; AgentSession
55
47
  * generates a short-lived ConvoAI token per API call:
@@ -71,19 +63,15 @@ export declare namespace AgoraClient {
71
63
  * });
72
64
  * ```
73
65
  *
74
- * **Basic auth** — Customer ID + Secret from Agora Console:
75
- * ```typescript
76
- * const client = new AgoraClient({
77
- * area: Area.US,
78
- * appId: "your-app-id",
79
- * appCertificate: "your-app-certificate",
80
- * customerId: "your-customer-id",
81
- * customerSecret: "your-customer-secret",
82
- * });
83
- * ```
84
66
  */
85
67
  export declare class AgoraClient<TArea extends AgoraArea = AgoraArea> extends BaseAgoraClient {
86
68
  protected readonly _pool: Pool;
69
+ readonly v3: V3Client;
70
+ get campaigns(): V3Client["campaigns"];
71
+ /** Project secrets shared with the advanced resource client. */
72
+ get secrets(): V3Client["secrets"];
73
+ /** Registered project numbers shared with the advanced resource client. */
74
+ get numbers(): V3Client["numbers"];
87
75
  /** Agora App ID */
88
76
  readonly appId: string;
89
77
  /** Agora App Certificate (used for RTC token signing) */
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // This file was auto-generated by Fern from our API Definition.
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -22,10 +21,12 @@ var __rest = (this && this.__rest) || function (s, e) {
22
21
  };
23
22
  Object.defineProperty(exports, "__esModule", { value: true });
24
23
  exports.AgoraClient = void 0;
24
+ const index_js_1 = require("./v3/index.js");
25
25
  const token_js_1 = require("./agentkit/token.js");
26
26
  const Client_js_1 = require("./Client.js");
27
- const index_js_1 = require("./core/domain/index.js");
28
- const index_js_2 = require("./errors/index.js");
27
+ const index_js_2 = require("./core/domain/index.js");
28
+ const publicHeaders_js_1 = require("./core/publicHeaders.js");
29
+ const index_js_3 = require("./errors/index.js");
29
30
  const API_BASE_URL_ENV = "AGORA_AGENTS_API_BASE_URL";
30
31
  function getConfiguredApiBaseUrl() {
31
32
  var _a;
@@ -41,11 +42,11 @@ function buildApiUrl(baseUrl, area) {
41
42
  const message = error instanceof Error ? error.message : String(error);
42
43
  throw new Error(`invalid ${API_BASE_URL_ENV}: ${message}`);
43
44
  }
44
- const apiPath = area === index_js_1.Area.CN ? index_js_1.CNAPIPath : index_js_1.GlobalAPIPath;
45
+ const apiPath = area === index_js_2.Area.CN ? index_js_2.CNAPIPath : index_js_2.GlobalAPIPath;
45
46
  parsedUrl.pathname = `${parsedUrl.pathname.replace(/\/+$/, "")}${apiPath}`;
46
47
  return parsedUrl.toString();
47
48
  }
48
- class ConfiguredBaseUrlPool extends index_js_1.Pool {
49
+ class ConfiguredBaseUrlPool extends index_js_2.Pool {
49
50
  constructor(area, configuredBaseUrl) {
50
51
  super(area);
51
52
  this.configuredBaseUrl = configuredBaseUrl;
@@ -62,13 +63,13 @@ class ConfiguredBaseUrlPool extends index_js_1.Pool {
62
63
  }
63
64
  function createClientPool(area) {
64
65
  const configuredBaseUrl = getConfiguredApiBaseUrl();
65
- return configuredBaseUrl ? new ConfiguredBaseUrlPool(area, buildApiUrl(configuredBaseUrl, area)) : new index_js_1.Pool(area);
66
+ return configuredBaseUrl ? new ConfiguredBaseUrlPool(area, buildApiUrl(configuredBaseUrl, area)) : new index_js_2.Pool(area);
66
67
  }
67
68
  /**
68
69
  * AgoraClient extends the base client with domain pool support for
69
70
  * regional URL cycling and automatic domain selection.
70
71
  *
71
- * Three authentication modes are supported:
72
+ * Two authentication modes are supported:
72
73
  *
73
74
  * **App credentials (recommended)** — no Customer Secret needed; AgentSession
74
75
  * generates a short-lived ConvoAI token per API call:
@@ -90,60 +91,78 @@ function createClientPool(area) {
90
91
  * });
91
92
  * ```
92
93
  *
93
- * **Basic auth** — Customer ID + Secret from Agora Console:
94
- * ```typescript
95
- * const client = new AgoraClient({
96
- * area: Area.US,
97
- * appId: "your-app-id",
98
- * appCertificate: "your-app-certificate",
99
- * customerId: "your-customer-id",
100
- * customerSecret: "your-customer-secret",
101
- * });
102
- * ```
103
94
  */
104
95
  class AgoraClient extends Client_js_1.AgoraClient {
96
+ get campaigns() {
97
+ return this.v3.campaigns;
98
+ }
99
+ /** Project secrets shared with the advanced resource client. */
100
+ get secrets() {
101
+ return this.v3.secrets;
102
+ }
103
+ /** Registered project numbers shared with the advanced resource client. */
104
+ get numbers() {
105
+ return this.v3.numbers;
106
+ }
105
107
  constructor(options) {
108
+ var _a, _b, _c, _d;
106
109
  const pool = createClientPool(options.area);
107
- let authMode;
108
- let username;
109
- let password;
110
- let authToken = "";
111
- const opts = options;
112
- if (opts.customerId != null && opts.customerSecret != null) {
113
- authMode = "basic";
114
- username = opts.customerId;
115
- password = opts.customerSecret;
116
- }
117
- else if (opts.customerId != null) {
118
- throw new Error("customerSecret is required when customerId is provided");
119
- }
120
- else if (opts.authToken != null) {
121
- authMode = "token";
122
- authToken = opts.authToken;
123
- username = "";
124
- password = "";
125
- }
126
- else {
127
- authMode = "app-credentials";
128
- username = "";
129
- password = "";
110
+ for (const key of Object.keys(options)) {
111
+ if ([
112
+ "customerid",
113
+ "customersecret",
114
+ "clientid",
115
+ "clientsecret",
116
+ "username",
117
+ "password",
118
+ "authorization",
119
+ ].includes(key.replace(/_/g, "").toLowerCase())) {
120
+ throw new Error(`${key} is not supported; use appId/appCertificate or authToken`);
121
+ }
130
122
  }
131
- const { customerId: _cid, customerSecret: _cs, authToken: _at } = opts, rest = __rest(opts, ["customerId", "customerSecret", "authToken"]);
132
- // _getCustomAuthorizationHeaders() in the generated client spreads { Authorization }
133
- // after _getAuthorizationHeader(), so it overrides the Basic header on every request.
134
- const authorization = authMode === "basic"
135
- ? `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`
136
- : authMode === "token"
137
- ? `agora token=${authToken}`
138
- : "";
139
- super(Object.assign(Object.assign({}, rest), { username,
140
- password,
141
- authorization, baseUrl: () => pool.getCurrentURL() }));
123
+ const authMode = options.authToken !== undefined ? "token" : "app-credentials";
124
+ const { authToken, appId, appCertificate } = options, rest = __rest(options, ["authToken", "appId", "appCertificate"]);
125
+ const authorization = () => authMode === "token"
126
+ ? `agora token=${authToken}`
127
+ : `agora token=${(0, token_js_1.generateConvoAIToken)({ appId, appCertificate, channelName: "", uid: 0 })}`;
128
+ const originalFetch = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalThis.fetch;
129
+ const tokenOnlyFetch = (input, init) => __awaiter(this, void 0, void 0, function* () {
130
+ const finalHeaders = new Headers(input instanceof Request ? input.headers : undefined);
131
+ new Headers(init === null || init === void 0 ? void 0 : init.headers).forEach((value, key) => finalHeaders.set(key, value));
132
+ const auth = finalHeaders.get("authorization");
133
+ if (auth !== null && !/^agora token=\S+$/i.test(auth))
134
+ throw new Error("Only Agora token authorization is supported");
135
+ for (const name of finalHeaders.keys())
136
+ if ((0, publicHeaders_js_1.isInternalHeader)(name))
137
+ throw new Error(`${name} is an internal header and is not supported`);
138
+ return originalFetch(input, init);
139
+ });
140
+ super(Object.assign(Object.assign({}, rest), { fetch: tokenOnlyFetch, username: "", password: "", authorization, baseUrl: () => pool.getCurrentURL() }));
142
141
  this._pool = pool;
143
- this.appId = options.appId;
144
- this.appCertificate = options.appCertificate;
142
+ this.appId = appId;
143
+ this.appCertificate = appCertificate;
145
144
  this.authMode = authMode;
146
145
  this.area = options.area;
146
+ const v3Base = (_c = (_b = options.v3) === null || _b === void 0 ? void 0 : _b.baseUrl) !== null && _c !== void 0 ? _c : process.env.AGORA_AGENTS_V3_BASE_URL;
147
+ if (v3Base !== undefined) {
148
+ let origin;
149
+ try {
150
+ origin = new URL(v3Base);
151
+ }
152
+ catch (_e) {
153
+ throw new Error("v3.baseUrl must be an HTTP(S) origin");
154
+ }
155
+ if (!["http:", "https:"].includes(origin.protocol) ||
156
+ origin.username ||
157
+ origin.password ||
158
+ origin.pathname !== "/" ||
159
+ origin.search ||
160
+ origin.hash ||
161
+ v3Base.includes("?") ||
162
+ v3Base.includes("#"))
163
+ throw new Error("v3.baseUrl must be an HTTP(S) origin without credentials, path, query or fragment");
164
+ }
165
+ this.v3 = new index_js_1.V3Client(new index_js_1.V3Transport(this._options, this.appId, () => v3Base !== null && v3Base !== void 0 ? v3Base : "https://preview.ai.agora.io", authorization, (_d = options.v3) === null || _d === void 0 ? void 0 : _d.headers));
147
166
  }
148
167
  /**
149
168
  * Get the underlying domain pool for advanced usage.
@@ -207,7 +226,7 @@ class AgoraClient extends Client_js_1.AgoraClient {
207
226
  yield this.agents.stop({ appid: this.appId, agentId }, { headers });
208
227
  }
209
228
  catch (error) {
210
- if (error instanceof index_js_2.AgoraError && error.statusCode === 404) {
229
+ if (error instanceof index_js_3.AgoraError && error.statusCode === 404) {
211
230
  return; // Agent already stopped — treat as success
212
231
  }
213
232
  throw error;
@@ -37,12 +37,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.normalizeClientOptions = normalizeClientOptions;
38
38
  const headers_js_1 = require("./core/headers.js");
39
39
  const core = __importStar(require("./core/index.js"));
40
+ const version_js_1 = require("./version.js");
40
41
  function normalizeClientOptions(options) {
41
42
  const headers = (0, headers_js_1.mergeHeaders)({
42
43
  "X-Fern-Language": "JavaScript",
43
44
  "X-Fern-SDK-Name": "agora-agents",
44
- "X-Fern-SDK-Version": "v2.12.0",
45
- "User-Agent": "agora-agents/v2.12.0",
45
+ "X-Fern-SDK-Version": version_js_1.SDK_VERSION,
46
+ "User-Agent": `agora-agents/${version_js_1.SDK_VERSION}`,
46
47
  "X-Fern-Runtime": core.RUNTIME.type,
47
48
  "X-Fern-Runtime-Version": core.RUNTIME.version,
48
49
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -1,3 +1,4 @@
1
+ import { type DeployedAgent, type DeployOptions, type SavedAgent, type SaveOptions, type VariableDefinition } from "./v3.js";
1
2
  /**
2
3
  * Agent class - A reusable agent definition.
3
4
  *
@@ -97,6 +98,7 @@ export interface AgentOptions<TArea extends AgoraArea = AgoraArea> {
97
98
  * ```
98
99
  */
99
100
  export declare class Agent<TTSSampleRate extends number = number, TArea extends AgoraArea = AgoraArea> {
101
+ private _variables;
100
102
  private _client;
101
103
  private _pipelineId?;
102
104
  private _llm?;
@@ -412,6 +414,11 @@ export declare class Agent<TTSSampleRate extends number = number, TArea extends
412
414
  * const agentId = await session.start();
413
415
  * ```
414
416
  */
417
+ withVariable(name: string, definition: VariableDefinition): Agent<TTSSampleRate, TArea>;
418
+ /** Persist this configuration and return a stored-agent handle. Does not start a session. */
419
+ save(options?: SaveOptions): Promise<SavedAgent>;
420
+ /** Compatibility alias for save(). */
421
+ deploy(options?: DeployOptions): Promise<DeployedAgent>;
415
422
  createSession(options: SessionOptions): AgentSession;
416
423
  /**
417
424
  * Converts the Agent configuration to the Fern request properties format.
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
- /**
3
- * Agent class - A reusable agent definition.
4
- *
5
- * This class represents an agent configuration that can be used to create
6
- * multiple sessions. Set the unique agent instance `name` in
7
- * {@link Agent.createSession}, not on the Agent itself.
8
- */
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
9
13
  Object.defineProperty(exports, "__esModule", { value: true });
10
14
  exports.Agent = void 0;
15
+ const session_backend_js_1 = require("./session-backend.js");
16
+ const v3_js_1 = require("./v3.js");
11
17
  const index_js_1 = require("../core/domain/index.js");
12
18
  const AgentSession_js_1 = require("./AgentSession.js");
13
19
  const constants_js_1 = require("./constants.js");
@@ -86,6 +92,7 @@ function assertTurnDetectionLanguage(value) {
86
92
  */
87
93
  class Agent {
88
94
  constructor(options) {
95
+ this._variables = {};
89
96
  this._client = options.client;
90
97
  this._pipelineId = options.pipelineId;
91
98
  this._instructions = options.instructions;
@@ -573,10 +580,94 @@ class Agent {
573
580
  * const agentId = await session.start();
574
581
  * ```
575
582
  */
583
+ withVariable(name, definition) {
584
+ (0, v3_js_1.validateVariable)(name, definition);
585
+ const next = this._clone();
586
+ next._variables = Object.assign(Object.assign({}, this._variables), { [name]: Object.assign(Object.assign({}, definition), (definition.options ? { options: [...definition.options] } : {})) });
587
+ return next;
588
+ }
589
+ /** Persist this configuration and return a stored-agent handle. Does not start a session. */
590
+ save(options = {}) {
591
+ var _a, _b;
592
+ const config = this.config;
593
+ if (config.mllm === undefined && (config.stt !== undefined || ((_a = config.turnDetection) === null || _a === void 0 ? void 0 : _a.language) !== undefined)) {
594
+ // Reuse v2's ASR language precedence only when ASR or language was configured.
595
+ config.stt = this._resolveAsrConfig(this._resolveTurnDetectionConfig());
596
+ }
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
+ }
599
+ /** Compatibility alias for save(). */
600
+ deploy(options = {}) {
601
+ return this.save(options);
602
+ }
576
603
  createSession(options) {
577
- var _a;
578
- const name = (_a = options.name) !== null && _a !== void 0 ? _a : `agent-${Date.now()}`;
579
- return new AgentSession_js_1.AgentSession(Object.assign(Object.assign({ client: this._client, agent: this, appId: this._client.appId, appCertificate: this._client.appCertificate }, options), { name }));
604
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
605
+ if ("clientReference" in options || "client_reference" in options)
606
+ throw new Error("client_reference is being removed; use the returned session ID for correlation");
607
+ const _k = this.config, { client: _client } = _k, config = __rest(_k, ["client"]);
608
+ let requiresStoredSession = Object.keys(this._variables).length > 0 ||
609
+ options.values !== undefined ||
610
+ options.idempotencyKey !== undefined ||
611
+ options.encryption !== undefined ||
612
+ options.audioScenario !== undefined ||
613
+ options.geofence !== undefined ||
614
+ options.gracefulStop !== undefined ||
615
+ options.dataPolicy !== undefined ||
616
+ options.labels !== undefined ||
617
+ options.maxDuration !== undefined;
618
+ try {
619
+ (0, v3_js_1.assertNoSecretRefs)(config);
620
+ }
621
+ catch (error) {
622
+ if (error instanceof v3_js_1.SecretRefNotSupportedError)
623
+ requiresStoredSession = true;
624
+ else
625
+ throw error;
626
+ }
627
+ if (requiresStoredSession) {
628
+ const normalized = this.config;
629
+ const sessionOptions = Object.assign({}, options);
630
+ if (normalized.geofence !== undefined) {
631
+ (_a = sessionOptions.geofence) !== null && _a !== void 0 ? _a : (sessionOptions.geofence = Object.assign({ area: normalized.geofence.area.toLowerCase() }, (normalized.geofence.exclude_area === undefined
632
+ ? {}
633
+ : {
634
+ exclude_area: normalized.geofence.exclude_area.toLowerCase(),
635
+ })));
636
+ normalized.geofence = undefined;
637
+ }
638
+ const params = Object.assign({}, normalized.parameters);
639
+ if (params.opt_out !== undefined) {
640
+ (_b = sessionOptions.dataPolicy) !== null && _b !== void 0 ? _b : (sessionOptions.dataPolicy = { retention: params.opt_out ? "none" : "30_days" });
641
+ delete params.opt_out;
642
+ }
643
+ if (params.farewell_config !== undefined) {
644
+ const farewell = params.farewell_config;
645
+ (_c = sessionOptions.gracefulStop) !== null && _c !== void 0 ? _c : (sessionOptions.gracefulStop = {
646
+ enabled: farewell.graceful_enabled,
647
+ timeout_ms: farewell.graceful_timeout_seconds === undefined
648
+ ? undefined
649
+ : farewell.graceful_timeout_seconds * 1000,
650
+ });
651
+ delete params.farewell_config;
652
+ }
653
+ if (params.audio_scenario !== undefined) {
654
+ (_d = sessionOptions.audioScenario) !== null && _d !== void 0 ? _d : (sessionOptions.audioScenario = params.audio_scenario === "default" ? "aiserver" : params.audio_scenario);
655
+ delete params.audio_scenario;
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);
668
+ }
669
+ const name = (_h = options.name) !== null && _h !== void 0 ? _h : `agent-${Date.now()}`;
670
+ 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: (_j = options.agentUid) !== null && _j !== void 0 ? _j : "0", name }));
580
671
  }
581
672
  /**
582
673
  * Converts the Agent configuration to the Fern request properties format.
@@ -587,6 +678,8 @@ class Agent {
587
678
  */
588
679
  toProperties(opts) {
589
680
  var _a, _b, _c, _d, _e, _f, _g, _h;
681
+ const _j = this.config, { client: _client } = _j, config = __rest(_j, ["client"]);
682
+ (0, v3_js_1.assertNoSecretRefs)(config);
590
683
  // In MLLM mode the backend handles audio end-to-end; LLM, TTS, and ASR
591
684
  // are not required.
592
685
  const isMllmMode = ((_a = this._mllm) === null || _a === void 0 ? void 0 : _a.enable) === true || this._mllm !== undefined;
@@ -711,6 +804,7 @@ class Agent {
711
804
  */
712
805
  _clone() {
713
806
  const newAgent = new Agent({ client: this._client });
807
+ newAgent._variables = Object.assign({}, this._variables);
714
808
  newAgent._pipelineId = this._pipelineId;
715
809
  newAgent._llm = this._llm;
716
810
  newAgent._tts = this._tts;
@@ -10,6 +10,7 @@ import type { AgentsClient } from "../api/resources/agents/client/Client.js";
10
10
  import type { Agent } from "./Agent.js";
11
11
  import type { AgoraArea } from "./area.js";
12
12
  import { type PresetInput } from "./presets.js";
13
+ import { type SessionBackend } from "./session-backend.js";
13
14
  import type { AgentConfigUpdate, ConversationHistory, ConversationTurns, GetTurnsOptions, SayOptions, SessionInfo, ThinkOptions, ThinkResponse } from "./types.js";
14
15
  /**
15
16
  * Event types that can be emitted by AgentSession.
@@ -26,7 +27,9 @@ export interface AgentSessionOptions {
26
27
  /** The Agora client instance */
27
28
  client: AgoraClient<AgoraArea>;
28
29
  /** The agent configuration */
29
- agent: Agent<number, AgoraArea>;
30
+ agent?: Agent<number, AgoraArea>;
31
+ /** @internal Transport adapter for stored/ephemeral session identities. */
32
+ backend?: SessionBackend;
30
33
  /** The App ID */
31
34
  appId: string;
32
35
  /** The App Certificate — enables automatic RTC token generation when starting sessions */
@@ -98,7 +101,8 @@ export interface AgentSessionOptions {
98
101
  */
99
102
  export declare class AgentSession {
100
103
  private readonly _client;
101
- private readonly _agent;
104
+ private readonly _agent?;
105
+ private readonly _backend?;
102
106
  private readonly _appId;
103
107
  private readonly _appCertificate?;
104
108
  private readonly _name;
@@ -119,6 +123,11 @@ export declare class AgentSession {
119
123
  private _sessionBaseUrl?;
120
124
  private _agentId;
121
125
  private _status;
126
+ private _lifecycleRevision;
127
+ private _infoReadRevision;
128
+ private _pendingLifecycle;
129
+ private _beginLifecycle;
130
+ private _finishLifecycle;
122
131
  private _eventHandlers;
123
132
  private readonly _warn;
124
133
  constructor(options: AgentSessionOptions);