@deepgram/sdk 5.0.0-alpha.1 → 5.0.0-alpha.3

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 (49) hide show
  1. package/README.md +44 -1
  2. package/dist/browser/index.global.js +8821 -0
  3. package/dist/cjs/BaseClient.js +3 -0
  4. package/dist/cjs/CustomClient.d.ts +9 -1
  5. package/dist/cjs/CustomClient.js +232 -21
  6. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1Settings.d.ts +3 -43
  7. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.ts +26 -0
  8. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.js +3 -0
  9. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.d.ts +28 -13
  10. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.js +19 -17
  11. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.d.ts +28 -13
  12. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.js +19 -17
  13. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.d.ts +115 -0
  14. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.js +57 -0
  15. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.d.ts +18 -3
  16. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.js +2 -0
  17. package/dist/cjs/api/resources/agent/resources/v1/types/index.d.ts +2 -0
  18. package/dist/cjs/api/resources/agent/resources/v1/types/index.js +2 -0
  19. package/dist/cjs/api/resources/listen/resources/v1/types/ListenV1Results.d.ts +3 -3
  20. package/dist/cjs/api/types/SpeakV1SampleRate.d.ts +1 -1
  21. package/dist/cjs/api/types/SpeakV1SampleRate.js +1 -1
  22. package/dist/cjs/core/websocket/ws.d.ts +0 -1
  23. package/dist/cjs/core/websocket/ws.js +9 -47
  24. package/dist/cjs/version.d.ts +1 -0
  25. package/dist/cjs/version.js +4 -0
  26. package/dist/esm/BaseClient.mjs +3 -0
  27. package/dist/esm/CustomClient.d.mts +9 -1
  28. package/dist/esm/CustomClient.mjs +232 -21
  29. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1Settings.d.mts +3 -43
  30. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.mts +26 -0
  31. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.mjs +2 -0
  32. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.d.mts +28 -13
  33. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.mjs +19 -17
  34. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.d.mts +28 -13
  35. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.mjs +19 -17
  36. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.d.mts +115 -0
  37. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.mjs +54 -0
  38. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.d.mts +18 -3
  39. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.mjs +2 -0
  40. package/dist/esm/api/resources/agent/resources/v1/types/index.d.mts +2 -0
  41. package/dist/esm/api/resources/agent/resources/v1/types/index.mjs +2 -0
  42. package/dist/esm/api/resources/listen/resources/v1/types/ListenV1Results.d.mts +3 -3
  43. package/dist/esm/api/types/SpeakV1SampleRate.d.mts +1 -1
  44. package/dist/esm/api/types/SpeakV1SampleRate.mjs +1 -1
  45. package/dist/esm/core/websocket/ws.d.mts +0 -1
  46. package/dist/esm/core/websocket/ws.mjs +9 -47
  47. package/dist/esm/version.d.mts +1 -0
  48. package/dist/esm/version.mjs +1 -0
  49. package/package.json +1 -28
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDK_VERSION = void 0;
4
+ exports.SDK_VERSION = "0.0.228";
@@ -5,6 +5,9 @@ import * as core from "./core/index.mjs";
5
5
  export function normalizeClientOptions(options) {
6
6
  const headers = mergeHeaders({
7
7
  "X-Fern-Language": "JavaScript",
8
+ "X-Fern-SDK-Name": "",
9
+ "X-Fern-SDK-Version": "0.0.228",
10
+ "User-Agent": "/0.0.228",
8
11
  "X-Fern-Runtime": core.RUNTIME.type,
9
12
  "X-Fern-Runtime-Version": core.RUNTIME.version,
10
13
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -2,6 +2,7 @@ import { DeepgramClient } from "./Client";
2
2
  import type { AgentClient } from "./api/resources/agent/client/Client.mjs";
3
3
  import type { ListenClient } from "./api/resources/listen/client/Client.mjs";
4
4
  import type { SpeakClient } from "./api/resources/speak/client/Client.mjs";
5
+ import * as core from "./core/index.mjs";
5
6
  /**
6
7
  * Custom wrapper around DeepgramClient that ensures the custom websocket implementation
7
8
  * from ws.ts is always used, even if the auto-generated code changes.
@@ -10,7 +11,14 @@ export declare class CustomDeepgramClient extends DeepgramClient {
10
11
  private _customAgent;
11
12
  private _customListen;
12
13
  private _customSpeak;
13
- constructor(options?: DeepgramClient.Options);
14
+ private readonly _sessionId;
15
+ constructor(options?: DeepgramClient.Options & {
16
+ accessToken?: core.Supplier<string | undefined>;
17
+ });
18
+ /**
19
+ * Get the session ID that was generated for this client instance.
20
+ */
21
+ get sessionId(): string;
14
22
  /**
15
23
  * Override the agent getter to return a wrapped client that ensures
16
24
  * the custom websocket implementation is used.
@@ -24,13 +24,92 @@ import { mergeHeaders, mergeOnlyDefinedHeaders } from "./core/headers.mjs";
24
24
  import { fromJson } from "./core/json.mjs";
25
25
  import * as core from "./core/index.mjs";
26
26
  import * as environments from "./environments.mjs";
27
+ import { RUNTIME } from "./core/runtime/index.mjs";
28
+ // Import ws library for Node.js (will be undefined in browser)
29
+ let NodeWebSocket;
30
+ try {
31
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
32
+ NodeWebSocket = require("ws");
33
+ // Handle both default export and named export
34
+ NodeWebSocket = NodeWebSocket.WebSocket || NodeWebSocket.default || NodeWebSocket;
35
+ }
36
+ catch (_a) {
37
+ // ws not available (e.g., in browser)
38
+ NodeWebSocket = undefined;
39
+ }
40
+ // Helper function to generate UUID that works in both Node.js and browser
41
+ function generateUUID() {
42
+ // In Node.js, use the crypto module
43
+ if (RUNTIME.type === "node") {
44
+ try {
45
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
46
+ const crypto = require("crypto");
47
+ return crypto.randomUUID();
48
+ }
49
+ catch (_a) {
50
+ // Fallback if crypto module is not available
51
+ }
52
+ }
53
+ // In browser or as fallback, use global crypto if available
54
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
55
+ return crypto.randomUUID();
56
+ }
57
+ // Fallback UUID generation (RFC4122 version 4)
58
+ // This is a simple fallback that should work everywhere
59
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
60
+ const r = (Math.random() * 16) | 0;
61
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
62
+ return v.toString(16);
63
+ });
64
+ }
65
+ /**
66
+ * Wrapper auth provider that checks for accessToken first (Bearer scheme)
67
+ * before falling back to the original auth provider (Token scheme for API keys).
68
+ */
69
+ class AccessTokenAuthProviderWrapper {
70
+ constructor(originalProvider, accessToken) {
71
+ this.originalProvider = originalProvider;
72
+ this.accessToken = accessToken;
73
+ }
74
+ getAuthRequest(arg) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ var _a, _b;
77
+ // Check for access token first (highest priority)
78
+ // Access tokens use Bearer scheme, API keys use Token scheme
79
+ const accessToken = (_a = (yield core.Supplier.get(this.accessToken))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.DEEPGRAM_ACCESS_TOKEN;
80
+ if (accessToken != null) {
81
+ return {
82
+ headers: { Authorization: `Bearer ${accessToken}` },
83
+ };
84
+ }
85
+ // Fall back to original provider (which handles API keys)
86
+ return this.originalProvider.getAuthRequest(arg);
87
+ });
88
+ }
89
+ }
27
90
  /**
28
91
  * Custom wrapper around DeepgramClient that ensures the custom websocket implementation
29
92
  * from ws.ts is always used, even if the auto-generated code changes.
30
93
  */
31
94
  export class CustomDeepgramClient extends DeepgramClient {
32
95
  constructor(options = {}) {
33
- super(options);
96
+ // Generate a UUID for the session ID
97
+ const sessionId = generateUUID();
98
+ // Add the session ID to headers so it's included in all REST requests
99
+ const optionsWithSessionId = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { "x-deepgram-session-id": sessionId }) });
100
+ super(optionsWithSessionId);
101
+ this._sessionId = sessionId;
102
+ // Wrap the auth provider to handle accessToken if provided
103
+ // This ensures accessToken takes priority over apiKey/env var
104
+ if (options.accessToken != null) {
105
+ this._options.authProvider = new AccessTokenAuthProviderWrapper(this._options.authProvider, options.accessToken);
106
+ }
107
+ }
108
+ /**
109
+ * Get the session ID that was generated for this client instance.
110
+ */
111
+ get sessionId() {
112
+ return this._sessionId;
34
113
  }
35
114
  /**
36
115
  * Override the agent getter to return a wrapped client that ensures
@@ -93,24 +172,113 @@ class WrappedSpeakClient extends SpeakClientImpl {
93
172
  return new WrappedSpeakV1Client(this._options);
94
173
  }
95
174
  }
175
+ /**
176
+ * Helper function to resolve Suppliers in headers to their actual values.
177
+ */
178
+ function resolveHeaders(headers) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ const resolved = {};
181
+ for (const [key, value] of Object.entries(headers)) {
182
+ if (value == null) {
183
+ continue;
184
+ }
185
+ // Resolve Supplier if it's a Supplier, otherwise use the value directly
186
+ const resolvedValue = yield core.Supplier.get(value);
187
+ if (resolvedValue != null) {
188
+ resolved[key] = resolvedValue;
189
+ }
190
+ }
191
+ return resolved;
192
+ });
193
+ }
194
+ /**
195
+ * Helper function to get WebSocket class and handle headers/protocols based on runtime.
196
+ * In Node.js, use the 'ws' library which supports headers.
197
+ * In browser, use Sec-WebSocket-Protocol for authentication since headers aren't supported.
198
+ */
199
+ function getWebSocketOptions(headers) {
200
+ const options = {};
201
+ // Check if we're in a browser environment (browser or web-worker)
202
+ const isBrowser = RUNTIME.type === "browser" || RUNTIME.type === "web-worker";
203
+ // Extract session ID header
204
+ const sessionIdHeader = headers["x-deepgram-session-id"] || headers["X-Deepgram-Session-Id"];
205
+ // In Node.js, ensure we use the 'ws' library which supports headers
206
+ if (RUNTIME.type === "node" && NodeWebSocket) {
207
+ options.WebSocket = NodeWebSocket;
208
+ options.headers = headers;
209
+ }
210
+ else if (isBrowser) {
211
+ // In browser, native WebSocket doesn't support custom headers
212
+ // Extract Authorization header and use Sec-WebSocket-Protocol instead
213
+ const authHeader = headers.Authorization || headers.authorization;
214
+ const browserHeaders = Object.assign({}, headers);
215
+ // Remove Authorization and session ID from headers since they won't work in browser
216
+ delete browserHeaders.Authorization;
217
+ delete browserHeaders.authorization;
218
+ delete browserHeaders["x-deepgram-session-id"];
219
+ delete browserHeaders["X-Deepgram-Session-Id"];
220
+ options.headers = browserHeaders;
221
+ // Build protocols array for browser WebSocket
222
+ const protocols = [];
223
+ // If we have an Authorization header, extract the token and format as protocols
224
+ // Deepgram expects:
225
+ // - For API keys: Sec-WebSocket-Protocol: token,API_KEY_GOES_HERE
226
+ // - For Bearer tokens: Sec-WebSocket-Protocol: bearer,TOKEN_GOES_HERE
227
+ // The comma separates multiple protocols, so we pass them as an array
228
+ if (authHeader && typeof authHeader === "string") {
229
+ if (authHeader.startsWith("Token ")) {
230
+ // API key: "Token API_KEY" -> ["token", "API_KEY"]
231
+ const apiKey = authHeader.substring(6); // Remove "Token " prefix
232
+ protocols.push("token", apiKey);
233
+ }
234
+ else if (authHeader.startsWith("Bearer ")) {
235
+ // Access token: "Bearer TOKEN" -> ["bearer", "TOKEN"]
236
+ const token = authHeader.substring(7); // Remove "Bearer " prefix
237
+ protocols.push("bearer", token);
238
+ }
239
+ else {
240
+ // Fallback: use the entire header value if it doesn't match expected format
241
+ protocols.push(authHeader);
242
+ }
243
+ }
244
+ // Add session ID as a protocol for browser WebSocket
245
+ if (sessionIdHeader && typeof sessionIdHeader === "string") {
246
+ protocols.push("x-deepgram-session-id", sessionIdHeader);
247
+ }
248
+ if (protocols.length > 0) {
249
+ options.protocols = protocols;
250
+ }
251
+ }
252
+ else {
253
+ // Fallback for other environments
254
+ options.headers = headers;
255
+ }
256
+ return options;
257
+ }
96
258
  /**
97
259
  * Wrapper for Agent V1Client that overrides connect to use custom websocket.
98
260
  */
99
261
  class WrappedAgentV1Client extends AgentV1Client {
100
262
  connect() {
101
263
  return __awaiter(this, arguments, void 0, function* (args = {}) {
102
- var _a, _b, _c, _d;
264
+ var _a, _b, _c, _d, _e, _f;
103
265
  const { headers, debug, reconnectAttempts } = args;
104
266
  // Get Authorization from authProvider (matching the working version)
105
267
  const authRequest = yield ((_a = this._options.authProvider) === null || _a === void 0 ? void 0 : _a.getAuthRequest());
106
- const _headers = mergeHeaders((_b = authRequest === null || authRequest === void 0 ? void 0 : authRequest.headers) !== null && _b !== void 0 ? _b : {}, headers);
268
+ // Merge headers from options (which includes session ID), auth headers, and request headers
269
+ const mergedHeaders = mergeHeaders((_b = this._options.headers) !== null && _b !== void 0 ? _b : {}, (_c = authRequest === null || authRequest === void 0 ? void 0 : authRequest.headers) !== null && _c !== void 0 ? _c : {}, headers);
270
+ // Resolve any Suppliers in headers to actual values
271
+ const _headers = yield resolveHeaders(mergedHeaders);
272
+ // Get WebSocket options with proper header handling
273
+ const wsOptions = getWebSocketOptions(_headers);
107
274
  // Explicitly use the custom ReconnectingWebSocket from ws.ts
108
275
  const socket = new ReconnectingWebSocket({
109
- url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.DeepgramEnvironment.Production).agent, "/v1/agent/converse"),
110
- protocols: [],
276
+ url: core.url.join((_d = (yield core.Supplier.get(this._options.baseUrl))) !== null && _d !== void 0 ? _d : ((_e = (yield core.Supplier.get(this._options.environment))) !== null && _e !== void 0 ? _e : environments.DeepgramEnvironment.Production).agent, "/v1/agent/converse"),
277
+ protocols: (_f = wsOptions.protocols) !== null && _f !== void 0 ? _f : [],
111
278
  queryParameters: {},
112
- headers: _headers,
279
+ headers: wsOptions.headers,
113
280
  options: {
281
+ WebSocket: wsOptions.WebSocket,
114
282
  debug: debug !== null && debug !== void 0 ? debug : false,
115
283
  maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
116
284
  startClosed: true,
@@ -166,6 +334,13 @@ class WrappedAgentV1Socket extends AgentV1Socket {
166
334
  }
167
335
  }
168
336
  connect() {
337
+ // Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
338
+ // by closing and reconnecting
339
+ if (this.socket.readyState === this.socket.CLOSED) {
340
+ // Force a fresh reconnect to ensure _connectLock is reset
341
+ this.socket._connectLock = false;
342
+ this.socket._shouldReconnect = true;
343
+ }
169
344
  // Call parent connect, but then ensure our binary handler is still active
170
345
  super.connect();
171
346
  // Re-setup binary handling in case connect() re-registered handlers
@@ -179,7 +354,7 @@ class WrappedAgentV1Socket extends AgentV1Socket {
179
354
  class WrappedListenV1Client extends ListenV1Client {
180
355
  connect(args) {
181
356
  return __awaiter(this, void 0, void 0, function* () {
182
- var _a, _b;
357
+ var _a, _b, _c, _d;
183
358
  // Extract all the args (same as the original implementation)
184
359
  const { callback, callback_method: callbackMethod, channels, diarize, dictation, encoding, endpointing, extra, interim_results: interimResults, keyterm, keywords, language, mip_opt_out: mipOptOut, model, multichannel, numerals, profanity_filter: profanityFilter, punctuate, redact, replace, sample_rate: sampleRate, search, smart_format: smartFormat, tag, utterance_end_ms: utteranceEndMs, vad_events: vadEvents, version, headers, debug, reconnectAttempts, } = args;
185
360
  // Build query params (same as original)
@@ -239,14 +414,20 @@ class WrappedListenV1Client extends ListenV1Client {
239
414
  _queryParams.version = version;
240
415
  // Get Authorization from authProvider (matching the working version)
241
416
  const authRequest = yield this._options.authProvider.getAuthRequest();
242
- const _headers = mergeHeaders(authRequest.headers, headers);
417
+ // Merge headers from options (which includes session ID), auth headers, and request headers
418
+ const mergedHeaders = mergeHeaders((_a = this._options.headers) !== null && _a !== void 0 ? _a : {}, authRequest.headers, headers);
419
+ // Resolve any Suppliers in headers to actual values
420
+ const _headers = yield resolveHeaders(mergedHeaders);
421
+ // Get WebSocket options with proper header handling
422
+ const wsOptions = getWebSocketOptions(_headers);
243
423
  // Explicitly use the custom ReconnectingWebSocket from ws.ts
244
424
  const socket = new ReconnectingWebSocket({
245
- url: core.url.join((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.DeepgramEnvironment.Production).production, "/v1/listen"),
246
- protocols: [],
425
+ url: core.url.join((_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.DeepgramEnvironment.Production).production, "/v1/listen"),
426
+ protocols: (_d = wsOptions.protocols) !== null && _d !== void 0 ? _d : [],
247
427
  queryParameters: _queryParams,
248
- headers: _headers,
428
+ headers: wsOptions.headers,
249
429
  options: {
430
+ WebSocket: wsOptions.WebSocket,
250
431
  debug: debug !== null && debug !== void 0 ? debug : false,
251
432
  maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
252
433
  startClosed: true,
@@ -298,6 +479,12 @@ class WrappedListenV1Socket extends ListenV1Socket {
298
479
  }
299
480
  }
300
481
  connect() {
482
+ // Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
483
+ if (this.socket.readyState === this.socket.CLOSED) {
484
+ // Force a fresh reconnect to ensure _connectLock is reset
485
+ this.socket._connectLock = false;
486
+ this.socket._shouldReconnect = true;
487
+ }
301
488
  super.connect();
302
489
  this.setupBinaryHandling();
303
490
  return this;
@@ -309,7 +496,7 @@ class WrappedListenV1Socket extends ListenV1Socket {
309
496
  class WrappedListenV2Client extends ListenV2Client {
310
497
  connect(args) {
311
498
  return __awaiter(this, void 0, void 0, function* () {
312
- var _a, _b, _c, _d;
499
+ var _a, _b, _c, _d, _e, _f;
313
500
  const { model, encoding, sample_rate: sampleRate, eager_eot_threshold: eagerEotThreshold, eot_threshold: eotThreshold, eot_timeout_ms: eotTimeoutMs, keyterm, mip_opt_out: mipOptOut, tag, headers, debug, reconnectAttempts, } = args;
314
501
  const _queryParams = {};
315
502
  _queryParams.model = model;
@@ -331,14 +518,20 @@ class WrappedListenV2Client extends ListenV2Client {
331
518
  _queryParams.tag = tag;
332
519
  // Get Authorization from authProvider (matching the working version)
333
520
  const authRequest = yield ((_a = this._options.authProvider) === null || _a === void 0 ? void 0 : _a.getAuthRequest());
334
- const _headers = mergeHeaders((_b = authRequest === null || authRequest === void 0 ? void 0 : authRequest.headers) !== null && _b !== void 0 ? _b : {}, headers);
521
+ // Merge headers from options (which includes session ID), auth headers, and request headers
522
+ const mergedHeaders = mergeHeaders((_b = this._options.headers) !== null && _b !== void 0 ? _b : {}, (_c = authRequest === null || authRequest === void 0 ? void 0 : authRequest.headers) !== null && _c !== void 0 ? _c : {}, headers);
523
+ // Resolve any Suppliers in headers to actual values
524
+ const _headers = yield resolveHeaders(mergedHeaders);
525
+ // Get WebSocket options with proper header handling
526
+ const wsOptions = getWebSocketOptions(_headers);
335
527
  // Explicitly use the custom ReconnectingWebSocket from ws.ts
336
528
  const socket = new ReconnectingWebSocket({
337
- url: core.url.join((_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : ((_d = (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.DeepgramEnvironment.Production).production, "/v2/listen"),
338
- protocols: [],
529
+ url: core.url.join((_d = (yield core.Supplier.get(this._options.baseUrl))) !== null && _d !== void 0 ? _d : ((_e = (yield core.Supplier.get(this._options.environment))) !== null && _e !== void 0 ? _e : environments.DeepgramEnvironment.Production).production, "/v2/listen"),
530
+ protocols: (_f = wsOptions.protocols) !== null && _f !== void 0 ? _f : [],
339
531
  queryParameters: _queryParams,
340
- headers: _headers,
532
+ headers: wsOptions.headers,
341
533
  options: {
534
+ WebSocket: wsOptions.WebSocket,
342
535
  debug: debug !== null && debug !== void 0 ? debug : false,
343
536
  maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
344
537
  startClosed: true,
@@ -390,6 +583,12 @@ class WrappedListenV2Socket extends ListenV2Socket {
390
583
  }
391
584
  }
392
585
  connect() {
586
+ // Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
587
+ if (this.socket.readyState === this.socket.CLOSED) {
588
+ // Force a fresh reconnect to ensure _connectLock is reset
589
+ this.socket._connectLock = false;
590
+ this.socket._shouldReconnect = true;
591
+ }
393
592
  super.connect();
394
593
  this.setupBinaryHandling();
395
594
  return this;
@@ -401,7 +600,7 @@ class WrappedListenV2Socket extends ListenV2Socket {
401
600
  class WrappedSpeakV1Client extends SpeakV1Client {
402
601
  connect(args) {
403
602
  return __awaiter(this, void 0, void 0, function* () {
404
- var _a, _b;
603
+ var _a, _b, _c, _d;
405
604
  const { encoding, mip_opt_out: mipOptOut, model, sample_rate: sampleRate, headers, debug, reconnectAttempts, } = args;
406
605
  const _queryParams = {};
407
606
  if (encoding != null)
@@ -414,14 +613,20 @@ class WrappedSpeakV1Client extends SpeakV1Client {
414
613
  _queryParams.sample_rate = sampleRate;
415
614
  // Get Authorization from authProvider (matching the working version)
416
615
  const authRequest = yield this._options.authProvider.getAuthRequest();
417
- const _headers = mergeHeaders(authRequest.headers, headers);
616
+ // Merge headers from options (which includes session ID), auth headers, and request headers
617
+ const mergedHeaders = mergeHeaders((_a = this._options.headers) !== null && _a !== void 0 ? _a : {}, authRequest.headers, headers);
618
+ // Resolve any Suppliers in headers to actual values
619
+ const _headers = yield resolveHeaders(mergedHeaders);
620
+ // Get WebSocket options with proper header handling
621
+ const wsOptions = getWebSocketOptions(_headers);
418
622
  // Explicitly use the custom ReconnectingWebSocket from ws.ts
419
623
  const socket = new ReconnectingWebSocket({
420
- url: core.url.join((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.DeepgramEnvironment.Production).production, "/v1/speak"),
421
- protocols: [],
624
+ url: core.url.join((_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.DeepgramEnvironment.Production).production, "/v1/speak"),
625
+ protocols: (_d = wsOptions.protocols) !== null && _d !== void 0 ? _d : [],
422
626
  queryParameters: _queryParams,
423
- headers: _headers,
627
+ headers: wsOptions.headers,
424
628
  options: {
629
+ WebSocket: wsOptions.WebSocket,
425
630
  debug: debug !== null && debug !== void 0 ? debug : false,
426
631
  maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
427
632
  startClosed: true,
@@ -473,6 +678,12 @@ class WrappedSpeakV1Socket extends SpeakV1Socket {
473
678
  }
474
679
  }
475
680
  connect() {
681
+ // Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
682
+ if (this.socket.readyState === this.socket.CLOSED) {
683
+ // Force a fresh reconnect to ensure _connectLock is reset
684
+ this.socket._connectLock = false;
685
+ this.socket._shouldReconnect = true;
686
+ }
476
687
  super.connect();
477
688
  this.setupBinaryHandling();
478
689
  return this;
@@ -73,7 +73,7 @@ export declare namespace AgentV1Settings {
73
73
  }
74
74
  }
75
75
  interface Agent {
76
- /** Agent language */
76
+ /** Deprecated. Use `listen.provider.language` and `speak.provider.language` fields instead. */
77
77
  language?: string;
78
78
  /** Conversation context including the history of messages and function calls */
79
79
  context?: Agent.Context;
@@ -120,22 +120,10 @@ export declare namespace AgentV1Settings {
120
120
  }
121
121
  }
122
122
  interface Listen {
123
- provider?: Listen.Provider;
124
- }
125
- namespace Listen {
126
- interface Provider {
127
- /** Provider type for speech-to-text */
128
- type: "deepgram";
129
- /** Model to use for speech to text */
130
- model?: string;
131
- /** Prompt key-term recognition (nova-3 'en' only) */
132
- keyterms?: string[];
133
- /** Applies smart formatting to improve transcript readability (Deepgram providers only) */
134
- smart_format?: boolean;
135
- }
123
+ provider?: Deepgram.agent.AgentV1SettingsAgentListenProvider;
136
124
  }
137
125
  interface Think {
138
- provider: Think.Provider;
126
+ provider: Deepgram.agent.AgentV1SettingsAgentThinkProvider;
139
127
  /** Optional for non-Deepgram LLM providers. When present, must include url field and headers object */
140
128
  endpoint?: Think.Endpoint;
141
129
  functions?: Think.Functions.Item[];
@@ -144,34 +132,6 @@ export declare namespace AgentV1Settings {
144
132
  context_length?: Think.ContextLength;
145
133
  }
146
134
  namespace Think {
147
- type Provider = {
148
- type?: "open_ai" | undefined;
149
- model?: ("gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini") | undefined;
150
- temperature?: number | undefined;
151
- } | {
152
- type?: "aws_bedrock" | undefined;
153
- model?: ("anthropic/claude-3-5-sonnet-20240620-v1:0" | "anthropic/claude-3-5-haiku-20240307-v1:0") | undefined;
154
- temperature?: number | undefined;
155
- credentials?: {
156
- type?: ("sts" | "iam") | undefined;
157
- region?: string | undefined;
158
- access_key_id?: string | undefined;
159
- secret_access_key?: string | undefined;
160
- session_token?: string | undefined;
161
- } | undefined;
162
- } | {
163
- type?: "anthropic" | undefined;
164
- model?: ("claude-3-5-haiku-latest" | "claude-sonnet-4-20250514") | undefined;
165
- temperature?: number | undefined;
166
- } | {
167
- type?: "google" | undefined;
168
- model?: ("gemini-2.0-flash" | "gemini-2.0-flash-lite" | "gemini-2.5-flash") | undefined;
169
- temperature?: number | undefined;
170
- } | {
171
- type?: "groq" | undefined;
172
- model?: "openai/gpt-oss-20b" | undefined;
173
- temperature?: number | undefined;
174
- };
175
135
  /**
176
136
  * Optional for non-Deepgram LLM providers. When present, must include url field and headers object
177
137
  */
@@ -0,0 +1,26 @@
1
+ import type * as Deepgram from "../../../../../index.mjs";
2
+ export type AgentV1SettingsAgentListenProvider = Deepgram.agent.AgentV1SettingsAgentListenProvider.V1 | Deepgram.agent.AgentV1SettingsAgentListenProvider.V2;
3
+ export declare namespace AgentV1SettingsAgentListenProvider {
4
+ interface V1 {
5
+ version: "v1";
6
+ /** Provider type for speech-to-text */
7
+ type: "deepgram";
8
+ /** Model to use for speech to text using the V1 API (e.g. Nova-3, Nova-2) */
9
+ model?: string;
10
+ /** Language code to use for speech-to-text. Can be a BCP-47 language tag (e.g. `en`), or `multi` for code-switching transcription */
11
+ language?: string;
12
+ /** Prompt keyterm recognition to improve Keyword Recall Rate */
13
+ keyterms?: string[];
14
+ /** Applies smart formatting to improve transcript readability */
15
+ smart_format?: boolean;
16
+ }
17
+ interface V2 {
18
+ version: "v2";
19
+ /** Provider type for speech-to-text */
20
+ type: "deepgram";
21
+ /** Model to use for speech to text using the V2 API (e.g. flux-general-en) */
22
+ model: string;
23
+ /** Prompt keyterm recognition to improve Keyword Recall Rate */
24
+ keyterms?: string[];
25
+ }
26
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -3,10 +3,12 @@ export type AgentV1SettingsAgentSpeakEndpointProvider = Deepgram.agent.AgentV1Se
3
3
  export declare namespace AgentV1SettingsAgentSpeakEndpointProvider {
4
4
  interface Deepgram {
5
5
  type: "deepgram";
6
+ /** The REST API version for the Deepgram text-to-speech API */
7
+ version?: "v1";
6
8
  /** Deepgram TTS model */
7
- model: AgentV1SettingsAgentSpeakEndpointProviderDeepgram.Model;
9
+ model: Deepgram.Model;
8
10
  }
9
- namespace AgentV1SettingsAgentSpeakEndpointProviderDeepgram {
11
+ namespace Deepgram {
10
12
  /** Deepgram TTS model */
11
13
  const Model: {
12
14
  readonly AuraAsteriaEn: "aura-asteria-en";
@@ -77,12 +79,16 @@ export declare namespace AgentV1SettingsAgentSpeakEndpointProvider {
77
79
  }
78
80
  interface ElevenLabs {
79
81
  type: "eleven_labs";
82
+ /** The REST API version for the Deepgram text-to-speech API */
83
+ version?: "v1";
80
84
  /** Eleven Labs model ID */
81
- model_id: AgentV1SettingsAgentSpeakEndpointProviderElevenLabs.ModelId;
82
- /** Eleven Labs optional language code */
85
+ model_id: ElevenLabs.ModelId;
86
+ /** Optional language to use, e.g. 'en-US'. Corresponds to the `language_code` parameter in the ElevenLabs API */
87
+ language?: string;
88
+ /** Use the `language` field instead. */
83
89
  language_code?: string;
84
90
  }
85
- namespace AgentV1SettingsAgentSpeakEndpointProviderElevenLabs {
91
+ namespace ElevenLabs {
86
92
  /** Eleven Labs model ID */
87
93
  const ModelId: {
88
94
  readonly ElevenTurboV25: "eleven_turbo_v2_5";
@@ -93,13 +99,18 @@ export declare namespace AgentV1SettingsAgentSpeakEndpointProvider {
93
99
  }
94
100
  interface Cartesia {
95
101
  type: "cartesia";
102
+ /** The API version header for the Cartesia text-to-speech API */
103
+ version?: Cartesia.Version;
96
104
  /** Cartesia model ID */
97
- model_id: AgentV1SettingsAgentSpeakEndpointProviderCartesia.ModelId;
98
- voice: AgentV1SettingsAgentSpeakEndpointProviderCartesia.Voice;
105
+ model_id: Cartesia.ModelId;
106
+ voice: Cartesia.Voice;
99
107
  /** Cartesia language code */
100
108
  language?: string;
101
109
  }
102
- namespace AgentV1SettingsAgentSpeakEndpointProviderCartesia {
110
+ namespace Cartesia {
111
+ /** The API version header for the Cartesia text-to-speech API */
112
+ const Version: {};
113
+ type Version = (typeof Version)[keyof typeof Version];
103
114
  /** Cartesia model ID */
104
115
  const ModelId: {
105
116
  readonly Sonic2: "sonic-2";
@@ -115,12 +126,14 @@ export declare namespace AgentV1SettingsAgentSpeakEndpointProvider {
115
126
  }
116
127
  interface OpenAi {
117
128
  type: "open_ai";
129
+ /** The REST API version for the OpenAI text-to-speech API */
130
+ version?: "v1";
118
131
  /** OpenAI TTS model */
119
- model: AgentV1SettingsAgentSpeakEndpointProviderOpenAi.Model;
132
+ model: OpenAi.Model;
120
133
  /** OpenAI voice */
121
- voice: AgentV1SettingsAgentSpeakEndpointProviderOpenAi.Voice;
134
+ voice: OpenAi.Voice;
122
135
  }
123
- namespace AgentV1SettingsAgentSpeakEndpointProviderOpenAi {
136
+ namespace OpenAi {
124
137
  /** OpenAI TTS model */
125
138
  const Model: {
126
139
  readonly Tts1: "tts-1";
@@ -142,8 +155,10 @@ export declare namespace AgentV1SettingsAgentSpeakEndpointProvider {
142
155
  type: "aws_polly";
143
156
  /** AWS Polly voice name */
144
157
  voice: AgentV1SettingsAgentSpeakEndpointProviderAwsPolly.Voice;
145
- /** Language code (e.g., "en-US") */
146
- language_code: string;
158
+ /** Language to use, e.g. 'en-US'. Corresponds to the `language_code` parameter in the AWS Polly API */
159
+ language: string;
160
+ /** Use the `language` field instead. */
161
+ language_code?: string;
147
162
  engine: AgentV1SettingsAgentSpeakEndpointProviderAwsPolly.Engine;
148
163
  credentials: AgentV1SettingsAgentSpeakEndpointProviderAwsPolly.Credentials;
149
164
  }