agora-agents 2.6.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/cjs/agentkit/Agent.js +9 -0
  2. package/dist/cjs/agentkit/AgentSession.d.ts +27 -0
  3. package/dist/cjs/agentkit/AgentSession.js +95 -23
  4. package/dist/cjs/agentkit/__tests__/area-aware-vendors.test.js +2 -2
  5. package/dist/cjs/agentkit/__tests__/preview-types.test.d.ts +7 -0
  6. package/dist/cjs/agentkit/__tests__/preview-types.test.js +57 -0
  7. package/dist/cjs/agentkit/__tests__/readme-examples.test.js +3 -3
  8. package/dist/cjs/agentkit/__tests__/type-safety.test.js +1 -1
  9. package/dist/cjs/agentkit/debug.d.ts +33 -0
  10. package/dist/cjs/agentkit/debug.js +134 -0
  11. package/dist/cjs/agentkit/index.d.ts +4 -1
  12. package/dist/cjs/agentkit/index.js +16 -3
  13. package/dist/cjs/agentkit/preview/client.d.ts +58 -0
  14. package/dist/cjs/agentkit/preview/client.js +89 -0
  15. package/dist/cjs/agentkit/preview/index.d.ts +11 -0
  16. package/dist/cjs/agentkit/preview/index.js +20 -0
  17. package/dist/cjs/agentkit/preview/vendors.d.ts +72 -0
  18. package/dist/cjs/agentkit/preview/vendors.js +53 -0
  19. package/dist/cjs/agentkit/token.js +32 -3
  20. package/dist/cjs/agentkit/types.d.ts +39 -0
  21. package/dist/cjs/index.d.ts +2 -2
  22. package/dist/cjs/index.js +13 -3
  23. package/dist/esm/agentkit/Agent.mjs +9 -0
  24. package/dist/esm/agentkit/AgentSession.d.mts +27 -0
  25. package/dist/esm/agentkit/AgentSession.mjs +95 -23
  26. package/dist/esm/agentkit/__tests__/area-aware-vendors.test.mjs +2 -2
  27. package/dist/esm/agentkit/__tests__/preview-types.test.d.mts +7 -0
  28. package/dist/esm/agentkit/__tests__/preview-types.test.mjs +55 -0
  29. package/dist/esm/agentkit/__tests__/readme-examples.test.mjs +3 -3
  30. package/dist/esm/agentkit/__tests__/type-safety.test.mjs +1 -1
  31. package/dist/esm/agentkit/debug.d.mts +33 -0
  32. package/dist/esm/agentkit/debug.mjs +129 -0
  33. package/dist/esm/agentkit/index.d.mts +4 -1
  34. package/dist/esm/agentkit/index.mjs +2 -0
  35. package/dist/esm/agentkit/preview/client.d.mts +58 -0
  36. package/dist/esm/agentkit/preview/client.mjs +83 -0
  37. package/dist/esm/agentkit/preview/index.d.mts +11 -0
  38. package/dist/esm/agentkit/preview/index.mjs +9 -0
  39. package/dist/esm/agentkit/preview/vendors.d.mts +72 -0
  40. package/dist/esm/agentkit/preview/vendors.mjs +49 -0
  41. package/dist/esm/agentkit/token.mjs +32 -3
  42. package/dist/esm/agentkit/types.d.mts +39 -0
  43. package/dist/esm/index.d.mts +2 -2
  44. package/dist/esm/index.mjs +3 -3
  45. package/package.json +1 -1
@@ -113,11 +113,16 @@ export declare class AgentSession {
113
113
  private readonly _expiresIn?;
114
114
  private readonly _debug?;
115
115
  private readonly _authMode;
116
+ private _agentsClient;
117
+ private _agentManagementClient;
118
+ private _previewFeatures;
119
+ private _sessionBaseUrl?;
116
120
  private _agentId;
117
121
  private _status;
118
122
  private _eventHandlers;
119
123
  private readonly _warn;
120
124
  constructor(options: AgentSessionOptions);
125
+ private _clientCurrentUrl;
121
126
  /**
122
127
  * Builds per-request headers for app-credentials auth mode.
123
128
  *
@@ -127,6 +132,19 @@ export declare class AgentSession {
127
132
  * Returns undefined for basic and pre-built-token modes (the client handles those).
128
133
  */
129
134
  private _convoAIHeaders;
135
+ /** Auth plus the route gate, with the gate pinned last. */
136
+ private _requestHeaders;
137
+ /**
138
+ * Client-level default headers, for debug logging only.
139
+ *
140
+ * These carry the preview `agora-feature` gate, which the generated client
141
+ * merges in below the SDK's view — so without this the header that decides
142
+ * whether a request reaches a preview provider is invisible in debug output.
143
+ * Reaches into `_options` the same way `authMode` is read in the constructor;
144
+ * supplier-valued headers are skipped rather than resolved, since debug
145
+ * logging must not trigger side effects.
146
+ */
147
+ private _clientDefaultHeaders;
130
148
  /**
131
149
  * The current agent ID (null if not started).
132
150
  */
@@ -171,6 +189,15 @@ export declare class AgentSession {
171
189
  * Returns true when the agent is configured for MLLM (multimodal end-to-end audio).
172
190
  */
173
191
  private _isMllmMode;
192
+ /**
193
+ * Warns when agent-level `instructions` would be silently discarded.
194
+ *
195
+ * `instructions` is only serialized into `llm.system_messages`, which does
196
+ * not exist in an MLLM pipeline — the Go and Python SDKs drop it the same
197
+ * way. Without this warning the agent starts with no system prompt at all
198
+ * and the only symptom is off-persona replies.
199
+ */
200
+ private _warnOnDroppedMllmInstructions;
174
201
  /**
175
202
  * Validates avatar and TTS configuration before starting.
176
203
  *
@@ -15,7 +15,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  };
16
16
  import { AgoraError } from "../errors/index.mjs";
17
17
  import { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, isSensetimeAvatar, isSpatiusAvatar, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
18
+ import { redactHeadersForDebug, redactSecrets } from "./debug.mjs";
18
19
  import { getPresetCategory, inferAsrPreset, inferLlmPreset, inferTtsPreset, normalizePresetInput, resolveSessionPresets, } from "./presets.mjs";
20
+ import { createPreviewRoute, previewRequestHeaders, requiredPreviewFeatures, } from "./preview/client.mjs";
19
21
  import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs";
20
22
  /**
21
23
  * AgentSession class for managing agent lifecycle and interactions.
@@ -53,6 +55,7 @@ import { ExpiresIn as ExpiresInHelper, generateConvoAIToken } from "./token.mjs"
53
55
  export class AgentSession {
54
56
  constructor(options) {
55
57
  var _a, _b;
58
+ this._previewFeatures = [];
56
59
  this._agentId = null;
57
60
  this._status = "idle";
58
61
  this._eventHandlers = new Map();
@@ -74,6 +77,13 @@ export class AgentSession {
74
77
  this._warn = (_a = options.warn) !== null && _a !== void 0 ? _a : ((msg) => console.warn(msg));
75
78
  // Read authMode from pool client if available, else fall back to basic
76
79
  this._authMode = (_b = options.client.authMode) !== null && _b !== void 0 ? _b : "basic";
80
+ this._agentsClient = options.client.agents;
81
+ this._agentManagementClient = options.client.agentManagement;
82
+ this._sessionBaseUrl = this._clientCurrentUrl();
83
+ }
84
+ _clientCurrentUrl() {
85
+ const getCurrentURL = this._client.getCurrentURL;
86
+ return typeof getCurrentURL === "function" ? getCurrentURL.call(this._client) : undefined;
77
87
  }
78
88
  /**
79
89
  * Builds per-request headers for app-credentials auth mode.
@@ -99,6 +109,35 @@ export class AgentSession {
99
109
  });
100
110
  return { Authorization: `agora token=${token}` };
101
111
  }
112
+ /** Auth plus the route gate, with the gate pinned last. */
113
+ _requestHeaders() {
114
+ const headers = this._convoAIHeaders();
115
+ return this._previewFeatures.length > 0 ? previewRequestHeaders(this._previewFeatures, headers) : headers;
116
+ }
117
+ /**
118
+ * Client-level default headers, for debug logging only.
119
+ *
120
+ * These carry the preview `agora-feature` gate, which the generated client
121
+ * merges in below the SDK's view — so without this the header that decides
122
+ * whether a request reaches a preview provider is invisible in debug output.
123
+ * Reaches into `_options` the same way `authMode` is read in the constructor;
124
+ * supplier-valued headers are skipped rather than resolved, since debug
125
+ * logging must not trigger side effects.
126
+ */
127
+ _clientDefaultHeaders() {
128
+ var _a;
129
+ const headers = (_a = this._client._options) === null || _a === void 0 ? void 0 : _a.headers;
130
+ if (!headers) {
131
+ return {};
132
+ }
133
+ const result = {};
134
+ for (const [key, value] of Object.entries(headers)) {
135
+ if (typeof value === "string") {
136
+ result[key] = value;
137
+ }
138
+ }
139
+ return result;
140
+ }
102
141
  /**
103
142
  * The current agent ID (null if not started).
104
143
  */
@@ -143,13 +182,13 @@ export class AgentSession {
143
182
  * ```
144
183
  */
145
184
  get raw() {
146
- return this._client.agents;
185
+ return this._agentsClient;
147
186
  }
148
187
  /**
149
188
  * Direct access to the underlying Fern-generated AgentManagement client.
150
189
  */
151
190
  get rawAgentManagement() {
152
- return this._client.agentManagement;
191
+ return this._agentManagementClient;
153
192
  }
154
193
  /**
155
194
  * Returns true when the agent is configured for MLLM (multimodal end-to-end audio).
@@ -161,6 +200,26 @@ export class AgentSession {
161
200
  }
162
201
  return mllm !== undefined;
163
202
  }
203
+ /**
204
+ * Warns when agent-level `instructions` would be silently discarded.
205
+ *
206
+ * `instructions` is only serialized into `llm.system_messages`, which does
207
+ * not exist in an MLLM pipeline — the Go and Python SDKs drop it the same
208
+ * way. Without this warning the agent starts with no system prompt at all
209
+ * and the only symptom is off-persona replies.
210
+ */
211
+ _warnOnDroppedMllmInstructions() {
212
+ var _a;
213
+ if (!this._isMllmMode() || this._agent.instructions === undefined) {
214
+ return;
215
+ }
216
+ const params = (_a = this._agent.mllm) === null || _a === void 0 ? void 0 : _a.params;
217
+ if (typeof (params === null || params === void 0 ? void 0 : params.instructions) === "string" && params.instructions.length > 0) {
218
+ return;
219
+ }
220
+ this._warn("Warning: agent-level `instructions` is ignored in MLLM mode and this agent will start with no " +
221
+ "system prompt. Pass `instructions` to the MLLM vendor instead (it serializes to mllm.params.instructions).");
222
+ }
164
223
  /**
165
224
  * Validates avatar and TTS configuration before starting.
166
225
  *
@@ -344,6 +403,7 @@ export class AgentSession {
344
403
  }
345
404
  // Validate avatar configuration before starting
346
405
  this._validateAvatarConfig();
406
+ this._warnOnDroppedMllmInstructions();
347
407
  // Validate that we can generate a token if one is not provided
348
408
  if (!this._token && !this._appCertificate) {
349
409
  throw new Error("Cannot auto-generate RTC token: appCertificate is required when a pre-built token is not provided. " +
@@ -373,6 +433,18 @@ export class AgentSession {
373
433
  });
374
434
  const enrichedProperties = this._enrichAvatarParams(resolved.properties, expiresIn);
375
435
  this._validateEnrichedAvatarConfig(enrichedProperties);
436
+ this._previewFeatures = requiredPreviewFeatures(enrichedProperties);
437
+ if (this._previewFeatures.length > 0) {
438
+ const route = createPreviewRoute(this._client, this._previewFeatures);
439
+ this._agentsClient = route.agents;
440
+ this._agentManagementClient = route.agentManagement;
441
+ this._sessionBaseUrl = route.baseUrl;
442
+ }
443
+ else {
444
+ this._agentsClient = this._client.agents;
445
+ this._agentManagementClient = this._client.agentManagement;
446
+ this._sessionBaseUrl = this._clientCurrentUrl();
447
+ }
376
448
  const request = {
377
449
  appid: this._appId,
378
450
  name: this._name,
@@ -380,14 +452,14 @@ export class AgentSession {
380
452
  pipeline_id: pipelineId,
381
453
  properties: enrichedProperties,
382
454
  };
455
+ const requestHeaders = this._requestHeaders();
383
456
  if (this._debug) {
384
457
  console.log("[Agora Debug] Starting agent session...");
385
- if ("getCurrentURL" in this._client && typeof this._client.getCurrentURL === "function") {
386
- console.log("[Agora Debug] API Endpoint:", this._client.getCurrentURL());
387
- }
388
- console.log("[Agora Debug] Request:", JSON.stringify(request, null, 2));
458
+ console.log("[Agora Debug] API Endpoint:", this._sessionBaseUrl);
459
+ console.log("[Agora Debug] Headers:", JSON.stringify(redactHeadersForDebug(Object.assign(Object.assign({}, this._clientDefaultHeaders()), requestHeaders)), null, 2));
460
+ console.log("[Agora Debug] Request:", JSON.stringify(redactSecrets(request), null, 2));
389
461
  }
390
- const response = yield this._client.agents.start(request, { headers: this._convoAIHeaders() });
462
+ const response = yield this._agentsClient.start(request, { headers: requestHeaders });
391
463
  this._agentId = (_b = response.agent_id) !== null && _b !== void 0 ? _b : null;
392
464
  this._status = "running";
393
465
  this._emit("started", { agentId: this._agentId });
@@ -416,10 +488,10 @@ export class AgentSession {
416
488
  }
417
489
  this._status = "stopping";
418
490
  try {
419
- yield this._client.agents.stop({
491
+ yield this._agentsClient.stop({
420
492
  appid: this._appId,
421
493
  agentId: this._agentId,
422
- }, { headers: this._convoAIHeaders() });
494
+ }, { headers: this._requestHeaders() });
423
495
  this._status = "stopped";
424
496
  this._emit("stopped", { agentId: this._agentId });
425
497
  }
@@ -450,13 +522,13 @@ export class AgentSession {
450
522
  if (!this._agentId) {
451
523
  throw new Error("No agent ID available");
452
524
  }
453
- yield this._client.agents.speak({
525
+ yield this._agentsClient.speak({
454
526
  appid: this._appId,
455
527
  agentId: this._agentId,
456
528
  text,
457
529
  priority: options === null || options === void 0 ? void 0 : options.priority,
458
530
  interruptable: options === null || options === void 0 ? void 0 : options.interruptable,
459
- }, { headers: this._convoAIHeaders() });
531
+ }, { headers: this._requestHeaders() });
460
532
  });
461
533
  }
462
534
  /**
@@ -470,10 +542,10 @@ export class AgentSession {
470
542
  if (!this._agentId) {
471
543
  throw new Error("No agent ID available");
472
544
  }
473
- yield this._client.agents.interrupt({
545
+ yield this._agentsClient.interrupt({
474
546
  appid: this._appId,
475
547
  agentId: this._agentId,
476
- }, { headers: this._convoAIHeaders() });
548
+ }, { headers: this._requestHeaders() });
477
549
  });
478
550
  }
479
551
  /**
@@ -487,7 +559,7 @@ export class AgentSession {
487
559
  if (!this._agentId) {
488
560
  throw new Error("No agent ID available");
489
561
  }
490
- return this._client.agentManagement.agentThink({
562
+ return this._agentManagementClient.agentThink({
491
563
  appid: this._appId,
492
564
  agentId: this._agentId,
493
565
  text,
@@ -496,7 +568,7 @@ export class AgentSession {
496
568
  on_speaking_action: options === null || options === void 0 ? void 0 : options.on_speaking_action,
497
569
  interruptable: options === null || options === void 0 ? void 0 : options.interruptable,
498
570
  metadata: options === null || options === void 0 ? void 0 : options.metadata,
499
- }, { headers: this._convoAIHeaders() });
571
+ }, { headers: this._requestHeaders() });
500
572
  });
501
573
  }
502
574
  /**
@@ -512,11 +584,11 @@ export class AgentSession {
512
584
  if (!this._agentId) {
513
585
  throw new Error("No agent ID available");
514
586
  }
515
- yield this._client.agents.update({
587
+ yield this._agentsClient.update({
516
588
  appid: this._appId,
517
589
  agentId: this._agentId,
518
590
  properties: config,
519
- }, { headers: this._convoAIHeaders() });
591
+ }, { headers: this._requestHeaders() });
520
592
  });
521
593
  }
522
594
  /**
@@ -529,10 +601,10 @@ export class AgentSession {
529
601
  if (!this._agentId) {
530
602
  throw new Error("No agent ID available");
531
603
  }
532
- return this._client.agents.getHistory({
604
+ return this._agentsClient.getHistory({
533
605
  appid: this._appId,
534
606
  agentId: this._agentId,
535
- }, { headers: this._convoAIHeaders() });
607
+ }, { headers: this._requestHeaders() });
536
608
  });
537
609
  }
538
610
  /**
@@ -545,12 +617,12 @@ export class AgentSession {
545
617
  if (!this._agentId) {
546
618
  throw new Error("No agent ID available");
547
619
  }
548
- return this._client.agents.getTurns({
620
+ return this._agentsClient.getTurns({
549
621
  appid: this._appId,
550
622
  agentId: this._agentId,
551
623
  page_index: options === null || options === void 0 ? void 0 : options.page_index,
552
624
  page_size: options === null || options === void 0 ? void 0 : options.page_size,
553
- }, { headers: this._convoAIHeaders() });
625
+ }, { headers: this._requestHeaders() });
554
626
  });
555
627
  }
556
628
  /**
@@ -605,10 +677,10 @@ export class AgentSession {
605
677
  if (!this._agentId) {
606
678
  throw new Error("No agent ID available");
607
679
  }
608
- return this._client.agents.get({
680
+ return this._agentsClient.get({
609
681
  appid: this._appId,
610
682
  agentId: this._agentId,
611
- }, { headers: this._convoAIHeaders() });
683
+ }, { headers: this._requestHeaders() });
612
684
  });
613
685
  }
614
686
  /**
@@ -9,7 +9,7 @@ import { GenericTTS, MiniMaxTTS } from "../vendors/tts.mjs";
9
9
  const client = new AgoraClient({
10
10
  area: Area.US,
11
11
  appId: "app-id",
12
- appCertificate: "app-certificate",
12
+ appCertificate: "app-certificate-0123456789abcdef",
13
13
  });
14
14
  new Agent({ client, turnDetection: { language: "en-US" } })
15
15
  .withStt(new DeepgramSTT({ model: "nova-3", language: "en-US" }))
@@ -44,7 +44,7 @@ const _invalidGlobalMllm = new QwenOmni({
44
44
  const client = new AgoraClient({
45
45
  area: Area.CN,
46
46
  appId: "app-id",
47
- appCertificate: "app-certificate",
47
+ appCertificate: "app-certificate-0123456789abcdef",
48
48
  });
49
49
  new Agent({ client, turnDetection: { language: "zh-CN" } })
50
50
  .withStt(new FengmingSTT())
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Compile-time type checks for the preview providers.
3
+ *
4
+ * This file is type-checked by `tsc` (it is under `src`), not executed by
5
+ * vitest. A regression here fails `pnpm build`.
6
+ */
7
+ export {};
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Compile-time type checks for the preview providers.
3
+ *
4
+ * This file is type-checked by `tsc` (it is under `src`), not executed by
5
+ * vitest. A regression here fails `pnpm build`.
6
+ */
7
+ import { AgoraClient } from "../../AgoraPoolClient.mjs";
8
+ import { Area } from "../../core/domain/index.mjs";
9
+ import { Agent } from "../Agent.mjs";
10
+ import { GeminiSTT } from "../preview/index.mjs";
11
+ const CLIENT = new AgoraClient({
12
+ area: Area.US,
13
+ appId: "test-app-id",
14
+ appCertificate: "test-app-certificate-01234567890",
15
+ });
16
+ // ============================================
17
+ // ✅ VALID CONFIGURATIONS
18
+ // ============================================
19
+ function _validTranscribeStt() {
20
+ return new Agent({ client: CLIENT }).withStt(new GeminiSTT({
21
+ apiKey: "test",
22
+ model: "gemini-3.5-transcribe-live",
23
+ languageCodes: ["en-US"],
24
+ customVocabulary: ["Agora"],
25
+ sampleRate: 16000,
26
+ wordTimestamp: false,
27
+ }));
28
+ }
29
+ /** The preview ASR variant is part of `SttConfig`, so hand-written configs type-check too. */
30
+ const _handWrittenAsr = {
31
+ vendor: "gemini",
32
+ language: "en-US",
33
+ params: {
34
+ api_key: "test",
35
+ model: "gemini-3.5-transcribe-live",
36
+ sample_rate: 16000,
37
+ language_codes: ["en-US"],
38
+ custom_vocabulary: ["Agora"],
39
+ word_timestamp: false,
40
+ },
41
+ };
42
+ // ============================================
43
+ // ❌ INVALID CONFIGURATIONS
44
+ // ============================================
45
+ /** The API key is required — it is the only credential these providers accept. */
46
+ function _transcribeRequiresApiKey() {
47
+ // @ts-expect-error - apiKey is required
48
+ return new GeminiSTT({ languageCodes: ["en-US"] });
49
+ }
50
+ /** ASR params must carry a model; the preview gateway rejects a bare vendor. */
51
+ // @ts-expect-error - params.model is required
52
+ const _asrRequiresModel = {
53
+ vendor: "gemini",
54
+ params: { api_key: "test" },
55
+ };
@@ -11,7 +11,7 @@ const SUPPORT_PROMPT = "You are a concise support assistant.";
11
11
  const client = new AgoraClient({
12
12
  area: Area.US,
13
13
  appId: "app-id",
14
- appCertificate: "app-certificate",
14
+ appCertificate: "app-certificate-0123456789abcdef",
15
15
  });
16
16
  new Agent({
17
17
  client,
@@ -71,7 +71,7 @@ new Agent({
71
71
  const client = new AgoraClient({
72
72
  area: Area.CN,
73
73
  appId: "app-id",
74
- appCertificate: "app-certificate",
74
+ appCertificate: "app-certificate-0123456789abcdef",
75
75
  });
76
76
  new Agent({
77
77
  client,
@@ -99,7 +99,7 @@ new Agent({
99
99
  const client = new AgoraClient({
100
100
  area: Area.US,
101
101
  appId: "app-id",
102
- appCertificate: "app-certificate",
102
+ appCertificate: "app-certificate-0123456789abcdef",
103
103
  });
104
104
  new Agent({ client, turnDetection: { language: "en-US" } })
105
105
  .withStt(new DeepgramSTT({
@@ -21,7 +21,7 @@ import { CartesiaTTS, ElevenLabsTTS, MicrosoftTTS, MiniMaxTTS, OpenAITTS } from
21
21
  const TEST_AGENT_CLIENT = new AgoraClient({
22
22
  area: Area.US,
23
23
  appId: "test-app-id",
24
- appCertificate: "test-app-certificate",
24
+ appCertificate: "test-app-certificate-01234567890",
25
25
  });
26
26
  // ============================================
27
27
  // ✅ VALID CONFIGURATIONS
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Redaction for `debug: true` session logging.
3
+ *
4
+ * The debug dump is routinely pasted into issues and chat threads, so it must
5
+ * never carry a usable credential. The generated fetcher redacts headers, query
6
+ * params, and URLs, but nothing redacts the request body — which is where
7
+ * vendor API keys and RTC tokens live.
8
+ *
9
+ * Uses the same `[REDACTED]` marker as `core/fetcher/Fetcher.ts` for
10
+ * consistency, but is deliberately independent of it: that file is generated by
11
+ * Fern and its helpers are module-local.
12
+ */
13
+ /** Marker substituted for a redacted value. Matches the generated fetcher. */
14
+ export declare const REDACTED = "[REDACTED]";
15
+ /**
16
+ * Deep-copies `value`, replacing credential fields with {@link REDACTED}.
17
+ *
18
+ * Empty strings are left visible on purpose: `""` is the signature of an unset
19
+ * environment variable, and hiding it behind `[REDACTED]` would disguise the
20
+ * exact misconfiguration the debug output exists to surface.
21
+ *
22
+ * Never mutates the input — the request that goes on the wire is untouched.
23
+ */
24
+ export declare function redactSecrets(value: unknown): unknown;
25
+ /**
26
+ * Redacts request headers for debug logging.
27
+ *
28
+ * `agora-feature` and the SDK identification headers are kept — they are what
29
+ * makes a preview request identifiable, and no header carries a secret except
30
+ * the authorization scheme's credential, whose scheme name is preserved so the
31
+ * active auth mode stays visible.
32
+ */
33
+ export declare function redactHeadersForDebug(headers: Record<string, string>): Record<string, string>;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Redaction for `debug: true` session logging.
3
+ *
4
+ * The debug dump is routinely pasted into issues and chat threads, so it must
5
+ * never carry a usable credential. The generated fetcher redacts headers, query
6
+ * params, and URLs, but nothing redacts the request body — which is where
7
+ * vendor API keys and RTC tokens live.
8
+ *
9
+ * Uses the same `[REDACTED]` marker as `core/fetcher/Fetcher.ts` for
10
+ * consistency, but is deliberately independent of it: that file is generated by
11
+ * Fern and its helpers are module-local.
12
+ */
13
+ /** Marker substituted for a redacted value. Matches the generated fetcher. */
14
+ export const REDACTED = "[REDACTED]";
15
+ /**
16
+ * Body fields whose values are credentials or account identifiers.
17
+ *
18
+ * Compared case-insensitively, and matched on both snake_case and camelCase
19
+ * spellings so this keeps working if a caller hand-builds a config.
20
+ */
21
+ const SENSITIVE_BODY_KEYS = new Set([
22
+ // Vendor credentials
23
+ "api_key",
24
+ "apikey",
25
+ "key",
26
+ "secret",
27
+ "api_secret",
28
+ "apisecret",
29
+ "password",
30
+ "access_key_id",
31
+ "accesskeyid",
32
+ "secret_access_key",
33
+ "secretaccesskey",
34
+ "adc_credentials_string",
35
+ "adccredentialsstring",
36
+ "credentials",
37
+ "subscription_key",
38
+ "subscriptionkey",
39
+ // Agora credentials and account identifiers
40
+ "token",
41
+ "agora_token",
42
+ "agoratoken",
43
+ "authorization",
44
+ "appid",
45
+ "app_id",
46
+ "agora_appid",
47
+ "agoraappid",
48
+ "app_certificate",
49
+ "appcertificate",
50
+ "customer_secret",
51
+ "customersecret",
52
+ ]);
53
+ function isSensitiveKey(key) {
54
+ return SENSITIVE_BODY_KEYS.has(key.toLowerCase());
55
+ }
56
+ function redactQueryKeys(value) {
57
+ let parsed;
58
+ try {
59
+ parsed = new URL(value);
60
+ }
61
+ catch (_a) {
62
+ return value;
63
+ }
64
+ let changed = false;
65
+ for (const key of [...parsed.searchParams.keys()]) {
66
+ if (key.toLowerCase() !== "key") {
67
+ continue;
68
+ }
69
+ const current = parsed.searchParams.getAll(key);
70
+ if (current.some((item) => item.length > 0)) {
71
+ parsed.searchParams.delete(key);
72
+ for (const item of current) {
73
+ parsed.searchParams.append(key, item.length > 0 ? REDACTED : item);
74
+ }
75
+ changed = true;
76
+ }
77
+ }
78
+ return changed ? parsed.toString() : value;
79
+ }
80
+ /**
81
+ * Deep-copies `value`, replacing credential fields with {@link REDACTED}.
82
+ *
83
+ * Empty strings are left visible on purpose: `""` is the signature of an unset
84
+ * environment variable, and hiding it behind `[REDACTED]` would disguise the
85
+ * exact misconfiguration the debug output exists to surface.
86
+ *
87
+ * Never mutates the input — the request that goes on the wire is untouched.
88
+ */
89
+ export function redactSecrets(value) {
90
+ if (Array.isArray(value)) {
91
+ return value.map((item) => redactSecrets(item));
92
+ }
93
+ if (value === null || typeof value !== "object") {
94
+ return value;
95
+ }
96
+ const result = {};
97
+ for (const [key, item] of Object.entries(value)) {
98
+ if (isSensitiveKey(key) && typeof item === "string" && item.length > 0) {
99
+ result[key] = REDACTED;
100
+ }
101
+ else if (typeof item === "string") {
102
+ result[key] = redactQueryKeys(item);
103
+ }
104
+ else {
105
+ result[key] = redactSecrets(item);
106
+ }
107
+ }
108
+ return result;
109
+ }
110
+ /**
111
+ * Redacts request headers for debug logging.
112
+ *
113
+ * `agora-feature` and the SDK identification headers are kept — they are what
114
+ * makes a preview request identifiable, and no header carries a secret except
115
+ * the authorization scheme's credential, whose scheme name is preserved so the
116
+ * active auth mode stays visible.
117
+ */
118
+ export function redactHeadersForDebug(headers) {
119
+ const result = {};
120
+ for (const [key, value] of Object.entries(headers)) {
121
+ if (key.toLowerCase() !== "authorization") {
122
+ result[key] = value;
123
+ continue;
124
+ }
125
+ const scheme = value.split(/[\s=]/, 1)[0];
126
+ result[key] = scheme && scheme !== value ? `${scheme} ${REDACTED}` : REDACTED;
127
+ }
128
+ return result;
129
+ }
@@ -26,12 +26,15 @@ export { AgentSession } from "./AgentSession.mjs";
26
26
  export type { AkoolAvatarConfig, AnamAvatarConfig, GenericAvatarConfig, HeyGenAvatarConfig, LiveAvatarAvatarConfig, SensetimeAvatarConfig, SpatiusAvatarConfig, StrictAvatarConfig, } from "./avatar-types.mjs";
27
27
  export { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, isSensetimeAvatar, isSpatiusAvatar, toBaseAvatarConfig, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
28
28
  export { AudioScenario, CredentialMode, DataChannel, FillerWordsSelectionRule, Geofence, InterruptionDisabledStrategy, InterruptionDisabledStrategyAppend, InterruptionDisabledStrategyIgnore, InterruptionModeKeywords, InterruptionModeStartOfSpeech, InterruptionModeValues, MllmTurnDetectionModeAgoraVad, MllmTurnDetectionModeSemanticVad, MllmTurnDetectionModeServerVad, MllmTurnDetectionModeValues, SalModeValues, SilenceActionValues, SpeakPriorityAppend, SpeakPriorityIgnore, SpeakPriorityInterrupt, SpeakPriorityValues, ThinkOnListeningActionIgnore, ThinkOnListeningActionInject, ThinkOnListeningActionInterrupt, ThinkOnSpeakingActionIgnore, ThinkOnSpeakingActionInterrupt, ThinkOnThinkingActionIgnore, ThinkOnThinkingActionInterrupt, TurnDetectionTypeValues, } from "./constants.mjs";
29
+ export { REDACTED, redactHeadersForDebug, redactSecrets } from "./debug.mjs";
29
30
  export type { AgentPreset, AsrPreset, DeepgramPresetModel, LlmPreset, MiniMaxPresetModel, OpenAIPresetModel, OpenAITtsPresetModel, PresetCategory, PresetInput, TtsPreset, } from "./presets.mjs";
30
31
  export { AgentPresets, normalizePresetInput } from "./presets.mjs";
32
+ export type { GeminiSTTModel, GeminiSTTOptions, PreviewFeature, PreviewRoute, } from "./preview/index.mjs";
33
+ export { createPreviewRoute, GeminiSTT, GeminiSTTModels, PREVIEW_API_BASE_URL, PREVIEW_FEATURE_HEADER, PreviewFeatures, previewRequestHeaders, requiredPreviewFeatures, } from "./preview/index.mjs";
31
34
  export type { AvatarVendor, CNAvatarVendor, CNLlmVendor, CNMllmVendor, CNSttVendor, CNTtsVendor, GlobalAvatarVendor, GlobalLlmVendor, GlobalMllmVendor, GlobalSttVendor, GlobalTtsVendor, LlmVendor, SttVendor, TtsVendor, } from "./region-vendors.mjs";
32
35
  export type { GenerateConvoAITokenOptions, GenerateTokenOptions, } from "./token.mjs";
33
36
  export { ExpiresIn, generateConvoAIToken, generateRtcToken, MAX_EXPIRY_SECONDS, } from "./token.mjs";
34
- 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, FillerWordsContentSelectionRule, FillerWordsContentStaticConfig, FillerWordsTrigger, FillerWordsTriggerFixedTimeConfig, FishAudioTts, FishAudioTtsParams, GenericTts, GenericTtsParams, GeofenceArea, GeofenceConfig, GeofenceExcludeArea, GetTurnsOptions, GoogleTts, GoogleTtsParams, GradiumTts, GradiumTtsParams, HumeAiTts, HumeAiTtsParams, InterruptionConfig, InterruptionMode, InterruptMode, Labels, LlmConfig, LlmGreetingConfigs, LlmGreetingConfigsMode, LlmStyle, 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, 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.mjs";
37
+ 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, FillerWordsContentSelectionRule, FillerWordsContentStaticConfig, 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, 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, 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.mjs";
35
38
  export type { AkoolAvatarOptions, AnamAvatarOptions, GenericAvatarOptions, HeyGenAvatarOptions, LiveAvatarAvatarOptions, } from "./vendors/avatar.mjs";
36
39
  export { AkoolAvatar, AnamAvatar, GenericAvatar, HeyGenAvatar, LiveAvatarAvatar, } from "./vendors/avatar.mjs";
37
40
  export type { AkoolSampleRate, CartesiaSampleRate, ElevenLabsSampleRate, HeyGenSampleRate, LiveAvatarSampleRate, MicrosoftSampleRate, SampleRate, } from "./vendors/base.mjs";
@@ -24,7 +24,9 @@ export { AgentSession } from "./AgentSession.mjs";
24
24
  export { isAkoolAvatar, isAnamAvatar, isAvatarTokenManaged, isGenericAvatar, isHeyGenAvatar, isLiveAvatarAvatar, isSensetimeAvatar, isSpatiusAvatar, toBaseAvatarConfig, validateAvatarConfig, validateTtsSampleRate, } from "./avatar-types.mjs";
25
25
  // Type-safe constants
26
26
  export { AudioScenario, CredentialMode, DataChannel, FillerWordsSelectionRule, Geofence, InterruptionDisabledStrategy, InterruptionDisabledStrategyAppend, InterruptionDisabledStrategyIgnore, InterruptionModeKeywords, InterruptionModeStartOfSpeech, InterruptionModeValues, MllmTurnDetectionModeAgoraVad, MllmTurnDetectionModeSemanticVad, MllmTurnDetectionModeServerVad, MllmTurnDetectionModeValues, SalModeValues, SilenceActionValues, SpeakPriorityAppend, SpeakPriorityIgnore, SpeakPriorityInterrupt, SpeakPriorityValues, ThinkOnListeningActionIgnore, ThinkOnListeningActionInject, ThinkOnListeningActionInterrupt, ThinkOnSpeakingActionIgnore, ThinkOnSpeakingActionInterrupt, ThinkOnThinkingActionIgnore, ThinkOnThinkingActionInterrupt, TurnDetectionTypeValues, } from "./constants.mjs";
27
+ export { REDACTED, redactHeadersForDebug, redactSecrets } from "./debug.mjs";
27
28
  export { AgentPresets, normalizePresetInput } from "./presets.mjs";
29
+ export { createPreviewRoute, GeminiSTT, GeminiSTTModels, PREVIEW_API_BASE_URL, PREVIEW_FEATURE_HEADER, PreviewFeatures, previewRequestHeaders, requiredPreviewFeatures, } from "./preview/index.mjs";
28
30
  // Token generation
29
31
  export { ExpiresIn, generateConvoAIToken, generateRtcToken, MAX_EXPIRY_SECONDS, } from "./token.mjs";
30
32
  // Avatar vendor classes