@deepgram/sdk 5.3.0 → 5.5.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 (87) hide show
  1. package/dist/browser/index.global.js +474 -18
  2. package/dist/cjs/BaseClient.d.ts +3 -0
  3. package/dist/cjs/BaseClient.js +20 -2
  4. package/dist/cjs/CustomClient.d.ts +75 -6
  5. package/dist/cjs/CustomClient.js +421 -15
  6. package/dist/cjs/api/errors/BadRequestError.js +1 -1
  7. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.ts +7 -3
  8. package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.js +1 -7
  9. package/dist/cjs/api/resources/listen/resources/v1/client/Client.d.ts +1 -0
  10. package/dist/cjs/api/resources/listen/resources/v1/client/Client.js +2 -1
  11. package/dist/cjs/api/resources/listen/resources/v1/resources/media/client/requests/ListenV1RequestUrl.d.ts +2 -2
  12. package/dist/cjs/api/resources/listen/resources/v1/resources/media/client/requests/MediaTranscribeRequestOctetStream.d.ts +2 -2
  13. package/dist/cjs/api/resources/listen/resources/v1/types/DiarizeModel.d.ts +5 -0
  14. package/dist/cjs/api/{types/CreateKeyV1RequestOne.js → resources/listen/resources/v1/types/DiarizeModel.js} +5 -0
  15. package/dist/cjs/api/resources/listen/resources/v1/types/index.d.ts +1 -0
  16. package/dist/cjs/api/resources/listen/resources/v1/types/index.js +1 -0
  17. package/dist/cjs/api/resources/listen/resources/v2/client/Client.d.ts +1 -0
  18. package/dist/cjs/api/resources/listen/resources/v2/client/Client.js +2 -1
  19. package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2CloseStream.d.ts +2 -1
  20. package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2CloseStream.js +5 -1
  21. package/dist/cjs/api/resources/listen/resources/v2/types/ListenV2TurnInfo.d.ts +4 -0
  22. package/dist/cjs/api/types/DeepgramListenProviderV2.d.ts +7 -1
  23. package/dist/cjs/api/types/ListenV1Diarize.d.ts +1 -1
  24. package/dist/cjs/api/types/ListenV1Diarize.js +1 -1
  25. package/dist/cjs/api/types/ListenV2ProfanityFilter.d.ts +6 -0
  26. package/dist/cjs/api/types/ListenV2ProfanityFilter.js +9 -0
  27. package/dist/cjs/api/types/index.d.ts +1 -0
  28. package/dist/cjs/api/types/index.js +1 -0
  29. package/dist/cjs/auth/HeaderAuthProvider.js +2 -1
  30. package/dist/cjs/core/auth/AuthProvider.d.ts +1 -0
  31. package/dist/cjs/core/auth/AuthProvider.js +7 -0
  32. package/dist/cjs/core/auth/index.d.ts +1 -1
  33. package/dist/cjs/core/auth/index.js +3 -1
  34. package/dist/cjs/core/fetcher/getResponseBody.js +11 -0
  35. package/dist/cjs/core/fetcher/requestWithRetries.js +4 -1
  36. package/dist/cjs/core/fetcher/signals.js +9 -1
  37. package/dist/cjs/errors/DeepgramError.js +1 -1
  38. package/dist/cjs/errors/DeepgramTimeoutError.js +1 -1
  39. package/dist/cjs/index.d.ts +2 -0
  40. package/dist/cjs/index.js +1 -0
  41. package/dist/cjs/version.d.ts +1 -1
  42. package/dist/cjs/version.js +1 -1
  43. package/dist/esm/BaseClient.d.mts +3 -0
  44. package/dist/esm/BaseClient.mjs +20 -2
  45. package/dist/esm/CustomClient.d.mts +75 -6
  46. package/dist/esm/CustomClient.mjs +421 -15
  47. package/dist/esm/api/errors/BadRequestError.mjs +1 -1
  48. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.mts +7 -3
  49. package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.mjs +1 -7
  50. package/dist/esm/api/resources/listen/resources/v1/client/Client.d.mts +1 -0
  51. package/dist/esm/api/resources/listen/resources/v1/client/Client.mjs +2 -1
  52. package/dist/esm/api/resources/listen/resources/v1/resources/media/client/requests/ListenV1RequestUrl.d.mts +2 -2
  53. package/dist/esm/api/resources/listen/resources/v1/resources/media/client/requests/MediaTranscribeRequestOctetStream.d.mts +2 -2
  54. package/dist/esm/api/resources/listen/resources/v1/types/DiarizeModel.d.mts +5 -0
  55. package/dist/esm/api/resources/listen/resources/v1/types/DiarizeModel.mjs +5 -0
  56. package/dist/esm/api/resources/listen/resources/v1/types/index.d.mts +1 -0
  57. package/dist/esm/api/resources/listen/resources/v1/types/index.mjs +1 -0
  58. package/dist/esm/api/resources/listen/resources/v2/client/Client.d.mts +1 -0
  59. package/dist/esm/api/resources/listen/resources/v2/client/Client.mjs +2 -1
  60. package/dist/esm/api/resources/listen/resources/v2/types/ListenV2CloseStream.d.mts +2 -1
  61. package/dist/esm/api/resources/listen/resources/v2/types/ListenV2CloseStream.mjs +5 -1
  62. package/dist/esm/api/resources/listen/resources/v2/types/ListenV2TurnInfo.d.mts +4 -0
  63. package/dist/esm/api/types/DeepgramListenProviderV2.d.mts +7 -1
  64. package/dist/esm/api/types/ListenV1Diarize.d.mts +1 -1
  65. package/dist/esm/api/types/ListenV1Diarize.mjs +1 -1
  66. package/dist/esm/api/types/ListenV2ProfanityFilter.d.mts +6 -0
  67. package/dist/esm/api/types/ListenV2ProfanityFilter.mjs +6 -0
  68. package/dist/esm/api/types/index.d.mts +1 -0
  69. package/dist/esm/api/types/index.mjs +1 -0
  70. package/dist/esm/auth/HeaderAuthProvider.mjs +2 -1
  71. package/dist/esm/core/auth/AuthProvider.d.mts +1 -0
  72. package/dist/esm/core/auth/AuthProvider.mjs +6 -1
  73. package/dist/esm/core/auth/index.d.mts +1 -1
  74. package/dist/esm/core/auth/index.mjs +1 -0
  75. package/dist/esm/core/fetcher/getResponseBody.mjs +11 -0
  76. package/dist/esm/core/fetcher/requestWithRetries.mjs +4 -1
  77. package/dist/esm/core/fetcher/signals.mjs +9 -1
  78. package/dist/esm/errors/DeepgramError.mjs +1 -1
  79. package/dist/esm/errors/DeepgramTimeoutError.mjs +1 -1
  80. package/dist/esm/index.d.mts +2 -0
  81. package/dist/esm/index.mjs +1 -0
  82. package/dist/esm/version.d.mts +1 -1
  83. package/dist/esm/version.mjs +1 -1
  84. package/package.json +1 -1
  85. package/dist/cjs/api/types/CreateKeyV1RequestOne.d.ts +0 -1
  86. package/dist/esm/api/types/CreateKeyV1RequestOne.d.mts +0 -1
  87. package/dist/esm/api/types/CreateKeyV1RequestOne.mjs +0 -2
@@ -59,6 +59,7 @@ const Socket_js_4 = require("./api/resources/speak/resources/v1/client/Socket.js
59
59
  const headers_js_1 = require("./core/headers.js");
60
60
  const json_js_1 = require("./core/json.js");
61
61
  const core = __importStar(require("./core/index.js"));
62
+ const websocketEvents = __importStar(require("./core/websocket/events.js"));
62
63
  const environments = __importStar(require("./environments.js"));
63
64
  const index_js_1 = require("./core/runtime/index.js");
64
65
  // Default WebSocket connection timeout in milliseconds
@@ -68,6 +69,7 @@ const DEFAULT_CONNECTION_TIMEOUT_MS = 10000;
68
69
  const WEBSOCKET_OPTION_KEYS = new Set([
69
70
  "Authorization",
70
71
  "headers",
72
+ "protocols",
71
73
  "debug",
72
74
  "reconnectAttempts",
73
75
  "connectionTimeoutInSeconds",
@@ -187,18 +189,21 @@ class AccessTokenAuthProviderWrapper {
187
189
  });
188
190
  }
189
191
  }
190
- /**
191
- * Custom wrapper around DeepgramClient that ensures the custom websocket implementation
192
- * from ws.ts is always used, even if the auto-generated code changes.
193
- */
194
192
  class CustomDeepgramClient extends Client_js_1.DeepgramClient {
195
193
  constructor(options = {}) {
194
+ var _a;
196
195
  // Generate a UUID for the session ID
197
196
  const sessionId = generateUUID();
198
197
  // Add the session ID to headers so it's included in all REST requests
199
- const optionsWithSessionId = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { "x-deepgram-session-id": sessionId }) });
198
+ // Auto-disable wrapper-level reconnect when a custom transportFactory
199
+ // is in use: those transports own their retry lifecycle, and stacking
200
+ // a second retry layer on top causes storm-on-storm under burst load.
201
+ // Callers can still opt back in by explicitly passing reconnect: true.
202
+ const reconnect = (_a = options.reconnect) !== null && _a !== void 0 ? _a : options.transportFactory == null;
203
+ const optionsWithSessionId = Object.assign(Object.assign({}, options), { reconnect, headers: Object.assign(Object.assign({}, options.headers), { "x-deepgram-session-id": sessionId }) });
200
204
  super(optionsWithSessionId);
201
205
  this._sessionId = sessionId;
206
+ this._reconnect = reconnect;
202
207
  // Always wrap the auth provider to add "Token " prefix to API keys
203
208
  // The auto-generated HeaderAuthProvider doesn't add the prefix
204
209
  this._options.authProvider = new ApiKeyAuthProviderWrapper(this._options.authProvider);
@@ -214,6 +219,16 @@ class CustomDeepgramClient extends Client_js_1.DeepgramClient {
214
219
  get sessionId() {
215
220
  return this._sessionId;
216
221
  }
222
+ /**
223
+ * Whether the SDK will retry streaming connections at the wrapper level
224
+ * after a transport-side failure. Returns `false` when a `transportFactory`
225
+ * was supplied without an explicit `reconnect: true` override, signalling
226
+ * that the custom transport is expected to manage its own reconnect
227
+ * lifecycle.
228
+ */
229
+ get reconnect() {
230
+ return this._reconnect;
231
+ }
217
232
  /**
218
233
  * Override the agent getter to return a wrapped client that ensures
219
234
  * the custom websocket implementation is used.
@@ -328,12 +343,364 @@ function buildQueryParams(args) {
328
343
  }
329
344
  return result;
330
345
  }
346
+ function normalizeProtocols(protocols) {
347
+ if (protocols == null) {
348
+ return [];
349
+ }
350
+ return Array.isArray(protocols) ? protocols : [protocols];
351
+ }
352
+ function stringifyHeaders(headers) {
353
+ const result = {};
354
+ for (const [key, value] of Object.entries(headers)) {
355
+ result[key] = String(value);
356
+ }
357
+ return result;
358
+ }
359
+ function buildWebSocketUrl(url, queryParams) {
360
+ const queryString = core.url.toQueryString(queryParams, { arrayFormat: "repeat" });
361
+ return queryString ? `${url}?${queryString}` : url;
362
+ }
363
+ function getTransportFactory(options) {
364
+ return options.transportFactory;
365
+ }
366
+ function getReconnect(options) {
367
+ return options.reconnect !== false;
368
+ }
369
+ class TransportWebSocketAdapter {
370
+ constructor(args) {
371
+ this._listeners = {
372
+ error: [],
373
+ message: [],
374
+ open: [],
375
+ close: [],
376
+ };
377
+ this._retryCount = -1;
378
+ this._shouldReconnect = true;
379
+ this._connectLock = false;
380
+ this._binaryType = "blob";
381
+ this._closeCalled = false;
382
+ this._messageQueue = [];
383
+ this.CONNECTING = ws_js_1.ReconnectingWebSocket.CONNECTING;
384
+ this.OPEN = ws_js_1.ReconnectingWebSocket.OPEN;
385
+ this.CLOSING = ws_js_1.ReconnectingWebSocket.CLOSING;
386
+ this.CLOSED = ws_js_1.ReconnectingWebSocket.CLOSED;
387
+ this.onclose = null;
388
+ this.onerror = null;
389
+ this.onmessage = null;
390
+ this.onopen = null;
391
+ this._handleAbort = () => {
392
+ if (this._closeCalled) {
393
+ return;
394
+ }
395
+ this._debug("abort signal fired");
396
+ this._closeCalled = true;
397
+ this._shouldReconnect = false;
398
+ this._clearConnectTimeout();
399
+ const transport = this._transport;
400
+ this._transport = undefined;
401
+ this._setTransportHandle(undefined);
402
+ if (transport) {
403
+ void transport.close(1000, "aborted");
404
+ }
405
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CLOSED;
406
+ this._emitClose(1000, "aborted");
407
+ };
408
+ this._factory = args.factory;
409
+ this._request = args.request;
410
+ this._reconnect = args.reconnect !== false;
411
+ this._readyState = args.startClosed
412
+ ? ws_js_1.ReconnectingWebSocket.ReadyState.CLOSED
413
+ : ws_js_1.ReconnectingWebSocket.ReadyState.CONNECTING;
414
+ if (this._request.abortSignal) {
415
+ this._request.abortSignal.addEventListener("abort", this._handleAbort, { once: true });
416
+ }
417
+ if (!args.startClosed) {
418
+ void this._connect();
419
+ }
420
+ }
421
+ get binaryType() {
422
+ return this._binaryType;
423
+ }
424
+ set binaryType(value) {
425
+ this._binaryType = value;
426
+ }
427
+ get retryCount() {
428
+ return Math.max(this._retryCount, 0);
429
+ }
430
+ get bufferedAmount() {
431
+ return this._messageQueue.reduce((acc, message) => {
432
+ if (typeof message === "string") {
433
+ return acc + message.length;
434
+ }
435
+ if (message instanceof Blob) {
436
+ return acc + message.size;
437
+ }
438
+ return acc + message.byteLength;
439
+ }, 0);
440
+ }
441
+ get extensions() {
442
+ return "";
443
+ }
444
+ get protocol() {
445
+ var _a;
446
+ return (_a = this._request.protocols[0]) !== null && _a !== void 0 ? _a : "";
447
+ }
448
+ get readyState() {
449
+ return this._readyState;
450
+ }
451
+ get url() {
452
+ return this._request.url;
453
+ }
454
+ close(code = 1000, reason) {
455
+ this._closeCalled = true;
456
+ this._shouldReconnect = false;
457
+ this._clearConnectTimeout();
458
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CLOSING;
459
+ const transport = this._transport;
460
+ this._transport = undefined;
461
+ this._setTransportHandle(undefined);
462
+ if (!transport) {
463
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CLOSED;
464
+ return;
465
+ }
466
+ void transport.close(code, reason);
467
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CLOSED;
468
+ }
469
+ reconnect(code, reason) {
470
+ this._shouldReconnect = true;
471
+ this._closeCalled = false;
472
+ this._retryCount = -1;
473
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CONNECTING;
474
+ const transport = this._transport;
475
+ this._transport = undefined;
476
+ this._setTransportHandle(undefined);
477
+ if (transport) {
478
+ void transport.close(code, reason);
479
+ }
480
+ void this._connect();
481
+ }
482
+ send(data) {
483
+ var _a;
484
+ if ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.isOpen()) {
485
+ void this._transport.send(data);
486
+ return;
487
+ }
488
+ this._messageQueue.push(data);
489
+ }
490
+ addEventListener(type, listener) {
491
+ if (this._listeners[type]) {
492
+ this._listeners[type].push(listener);
493
+ }
494
+ }
495
+ dispatchEvent(event) {
496
+ const listeners = this._listeners[event.type];
497
+ if (listeners) {
498
+ for (const listener of listeners) {
499
+ this._callEventListener(event, listener);
500
+ }
501
+ }
502
+ return true;
503
+ }
504
+ removeEventListener(type, listener) {
505
+ if (this._listeners[type]) {
506
+ this._listeners[type] = this._listeners[type].filter((registered) => registered !== listener);
507
+ }
508
+ }
509
+ _debug(...args) {
510
+ if (this._request.debug) {
511
+ // biome-ignore lint/suspicious/noConsole: transport debug logging mirrors websocket debug logging
512
+ console.log.apply(console, ["DG-TRANSPORT>", ...args]);
513
+ }
514
+ }
515
+ _connect() {
516
+ return __awaiter(this, void 0, void 0, function* () {
517
+ var _a, _b;
518
+ if (this._connectLock || !this._shouldReconnect || ((_a = this._request.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted)) {
519
+ return;
520
+ }
521
+ // When wrapper-level reconnect is disabled, allow only the initial
522
+ // attempt (_retryCount starts at -1 and increments to 0 on first
523
+ // _connect). Any subsequent re-entry from _handleError must short out
524
+ // so the transport's own retry logic is the single source of truth.
525
+ if (!this._reconnect && this._retryCount >= 0) {
526
+ this._debug("reconnect disabled, skipping retry");
527
+ return;
528
+ }
529
+ if (this._retryCount >= this._request.reconnectAttempts) {
530
+ this._debug("max retries reached", this._retryCount, ">=", this._request.reconnectAttempts);
531
+ return;
532
+ }
533
+ this._connectLock = true;
534
+ this._retryCount++;
535
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CONNECTING;
536
+ this._clearConnectTimeout();
537
+ try {
538
+ const transport = yield this._factory(this._request.url, this._request.headers, this._request);
539
+ if (this._closeCalled || ((_b = this._request.abortSignal) === null || _b === void 0 ? void 0 : _b.aborted)) {
540
+ this._connectLock = false;
541
+ yield transport.close(1000, "aborted");
542
+ return;
543
+ }
544
+ this._transport = transport;
545
+ this._setTransportHandle(transport);
546
+ this._bindTransport(transport);
547
+ this._armConnectTimeout();
548
+ this._connectLock = false;
549
+ if (transport.isOpen()) {
550
+ this._handleOpen(transport);
551
+ }
552
+ }
553
+ catch (error) {
554
+ this._connectLock = false;
555
+ this._handleError(error instanceof Error ? error : new Error(String(error)));
556
+ }
557
+ });
558
+ }
559
+ _bindTransport(transport) {
560
+ transport.onOpen(() => {
561
+ if (this._transport !== transport) {
562
+ return;
563
+ }
564
+ this._handleOpen(transport);
565
+ });
566
+ transport.onMessage((message) => {
567
+ if (this._transport !== transport) {
568
+ return;
569
+ }
570
+ this._handleMessage(message);
571
+ });
572
+ transport.onError((error) => {
573
+ if (this._transport !== transport) {
574
+ return;
575
+ }
576
+ this._handleError(error);
577
+ });
578
+ transport.onClose((event) => {
579
+ var _a, _b;
580
+ if (this._transport !== transport) {
581
+ return;
582
+ }
583
+ this._handleClose((_a = event.code) !== null && _a !== void 0 ? _a : 1000, (_b = event.reason) !== null && _b !== void 0 ? _b : "");
584
+ });
585
+ }
586
+ _armConnectTimeout() {
587
+ const timeoutMs = this._request.connectionTimeoutInSeconds != null
588
+ ? this._request.connectionTimeoutInSeconds * 1000
589
+ : DEFAULT_CONNECTION_TIMEOUT_MS;
590
+ this._connectTimeout = setTimeout(() => {
591
+ this._handleError(new Error("TIMEOUT"));
592
+ }, timeoutMs);
593
+ }
594
+ _clearConnectTimeout() {
595
+ if (this._connectTimeout != null) {
596
+ clearTimeout(this._connectTimeout);
597
+ this._connectTimeout = undefined;
598
+ }
599
+ }
600
+ _handleOpen(transport) {
601
+ if (this._transport !== transport || this._readyState === ws_js_1.ReconnectingWebSocket.ReadyState.OPEN) {
602
+ return;
603
+ }
604
+ this._debug("open event");
605
+ this._clearConnectTimeout();
606
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.OPEN;
607
+ const queued = [...this._messageQueue];
608
+ this._messageQueue = [];
609
+ for (const message of queued) {
610
+ void transport.send(message);
611
+ }
612
+ const event = new websocketEvents.Event("open", this);
613
+ if (this.onopen) {
614
+ this.onopen(event);
615
+ }
616
+ this._listeners.open.forEach((listener) => this._callEventListener(event, listener));
617
+ }
618
+ _handleMessage(message) {
619
+ const event = { type: "message", data: message, target: this };
620
+ if (this.onmessage) {
621
+ this.onmessage(event);
622
+ }
623
+ this._listeners.message.forEach((listener) => this._callEventListener(event, listener));
624
+ }
625
+ _handleError(error) {
626
+ this._debug("error event", error.message);
627
+ this._clearConnectTimeout();
628
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CLOSED;
629
+ const event = new websocketEvents.ErrorEvent(error, this);
630
+ if (this.onerror) {
631
+ this.onerror(event);
632
+ }
633
+ this._listeners.error.forEach((listener) => this._callEventListener(event, listener));
634
+ const transport = this._transport;
635
+ this._transport = undefined;
636
+ this._setTransportHandle(undefined);
637
+ if (transport) {
638
+ void transport.close(1011, error.message);
639
+ }
640
+ if (this._shouldReconnect && !this._closeCalled) {
641
+ void this._connect();
642
+ }
643
+ }
644
+ _handleClose(code, reason) {
645
+ this._debug("close event", code, reason);
646
+ this._clearConnectTimeout();
647
+ this._transport = undefined;
648
+ this._readyState = ws_js_1.ReconnectingWebSocket.ReadyState.CLOSED;
649
+ this._setTransportHandle(undefined);
650
+ if (code === 1000) {
651
+ this._shouldReconnect = false;
652
+ }
653
+ this._emitClose(code, reason);
654
+ if (this._shouldReconnect && !this._closeCalled) {
655
+ void this._connect();
656
+ }
657
+ }
658
+ _emitClose(code, reason) {
659
+ const event = new websocketEvents.CloseEvent(code, reason, this);
660
+ if (this.onclose) {
661
+ this.onclose(event);
662
+ }
663
+ this._listeners.close.forEach((listener) => this._callEventListener(event, listener));
664
+ }
665
+ _setTransportHandle(transport) {
666
+ if (!transport) {
667
+ this._ws = undefined;
668
+ return;
669
+ }
670
+ this._ws = {
671
+ OPEN: this.OPEN,
672
+ get readyState() {
673
+ return transport.isOpen()
674
+ ? ws_js_1.ReconnectingWebSocket.ReadyState.OPEN
675
+ : ws_js_1.ReconnectingWebSocket.ReadyState.CLOSED;
676
+ },
677
+ ping: transport.ping
678
+ ? (data) => {
679
+ var _a;
680
+ void ((_a = transport.ping) === null || _a === void 0 ? void 0 : _a.call(transport, data));
681
+ }
682
+ : undefined,
683
+ };
684
+ }
685
+ _callEventListener(event, listener) {
686
+ if (typeof listener === "object" && listener && "handleEvent" in listener) {
687
+ listener.handleEvent(event);
688
+ }
689
+ else {
690
+ listener(event);
691
+ }
692
+ }
693
+ }
694
+ TransportWebSocketAdapter.CONNECTING = ws_js_1.ReconnectingWebSocket.CONNECTING;
695
+ TransportWebSocketAdapter.OPEN = ws_js_1.ReconnectingWebSocket.OPEN;
696
+ TransportWebSocketAdapter.CLOSING = ws_js_1.ReconnectingWebSocket.CLOSING;
697
+ TransportWebSocketAdapter.CLOSED = ws_js_1.ReconnectingWebSocket.CLOSED;
331
698
  /**
332
699
  * Helper function to get WebSocket class and handle headers/protocols based on runtime.
333
700
  * In Node.js, use the 'ws' library which supports headers.
334
701
  * In browser, use Sec-WebSocket-Protocol for authentication since headers aren't supported.
335
702
  */
336
- function getWebSocketOptions(headers) {
703
+ function getWebSocketOptions(headers, requestedProtocols) {
337
704
  const options = {};
338
705
  // Check if we're in a browser environment (browser or web-worker)
339
706
  const isBrowser = index_js_1.RUNTIME.type === "browser" || index_js_1.RUNTIME.type === "web-worker";
@@ -343,6 +710,9 @@ function getWebSocketOptions(headers) {
343
710
  if (index_js_1.RUNTIME.type === "node" && NodeWebSocket) {
344
711
  options.WebSocket = NodeWebSocket;
345
712
  options.headers = headers;
713
+ if (requestedProtocols.length > 0) {
714
+ options.protocols = requestedProtocols;
715
+ }
346
716
  }
347
717
  else if (isBrowser) {
348
718
  // In browser, native WebSocket doesn't support custom headers
@@ -356,7 +726,7 @@ function getWebSocketOptions(headers) {
356
726
  delete browserHeaders["X-Deepgram-Session-Id"];
357
727
  options.headers = browserHeaders;
358
728
  // Build protocols array for browser WebSocket
359
- const protocols = [];
729
+ const protocols = [...requestedProtocols];
360
730
  // If we have an Authorization header, extract the token and format as protocols
361
731
  // Deepgram expects:
362
732
  // - For API keys: Sec-WebSocket-Protocol: token,API_KEY_GOES_HERE
@@ -389,6 +759,9 @@ function getWebSocketOptions(headers) {
389
759
  else {
390
760
  // Fallback for other environments
391
761
  options.headers = headers;
762
+ if (requestedProtocols.length > 0) {
763
+ options.protocols = requestedProtocols;
764
+ }
392
765
  }
393
766
  return options;
394
767
  }
@@ -465,7 +838,7 @@ function resetSocketConnectionState(socket) {
465
838
  * This reduces duplication across all Wrapped*Client classes.
466
839
  */
467
840
  function createWebSocketConnection(_a) {
468
- return __awaiter(this, arguments, void 0, function* ({ options, urlPath, environmentKey, queryParams, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, }) {
841
+ return __awaiter(this, arguments, void 0, function* ({ options, urlPath, environmentKey, queryParams, protocols, service, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, }) {
469
842
  var _b, _c, _d, _e, _f, _g;
470
843
  // Ensure ws is loaded for Node.js environments (no-op after first call)
471
844
  yield loadNodeWebSocket();
@@ -475,13 +848,38 @@ function createWebSocketConnection(_a) {
475
848
  const mergedHeaders = (0, headers_js_1.mergeHeaders)((_c = options.headers) !== null && _c !== void 0 ? _c : {}, (_d = authRequest === null || authRequest === void 0 ? void 0 : authRequest.headers) !== null && _d !== void 0 ? _d : {}, headers);
476
849
  // Resolve any Suppliers in headers to actual values
477
850
  const _headers = yield resolveHeaders(mergedHeaders);
478
- // Get WebSocket options with proper header handling
479
- const wsOptions = getWebSocketOptions(_headers);
851
+ const normalizedProtocols = normalizeProtocols(protocols);
480
852
  // Get the appropriate base URL for the environment
481
853
  const baseUrl = (_e = (yield core.Supplier.get(options.baseUrl))) !== null && _e !== void 0 ? _e : ((_f = (yield core.Supplier.get(options.environment))) !== null && _f !== void 0 ? _f : environments.DeepgramEnvironment.Production)[environmentKey];
854
+ const url = core.url.join(baseUrl, urlPath);
855
+ const fullUrl = buildWebSocketUrl(url, queryParams);
856
+ const transportFactory = getTransportFactory(options);
857
+ const reconnect = getReconnect(options);
858
+ if (transportFactory) {
859
+ const request = {
860
+ url: fullUrl,
861
+ headers: stringifyHeaders(_headers),
862
+ protocols: normalizedProtocols,
863
+ path: urlPath,
864
+ service,
865
+ queryParams,
866
+ debug: debug !== null && debug !== void 0 ? debug : false,
867
+ reconnectAttempts: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
868
+ connectionTimeoutInSeconds,
869
+ abortSignal,
870
+ };
871
+ return new TransportWebSocketAdapter({
872
+ factory: transportFactory,
873
+ request,
874
+ startClosed: true,
875
+ reconnect,
876
+ });
877
+ }
878
+ // Get WebSocket options with proper header handling
879
+ const wsOptions = getWebSocketOptions(_headers, normalizedProtocols);
482
880
  // Create and return the ReconnectingWebSocket
483
881
  return new ws_js_1.ReconnectingWebSocket({
484
- url: core.url.join(baseUrl, urlPath),
882
+ url,
485
883
  protocols: (_g = wsOptions.protocols) !== null && _g !== void 0 ? _g : [],
486
884
  queryParameters: queryParams,
487
885
  headers: wsOptions.headers,
@@ -507,12 +905,14 @@ function createWebSocketConnection(_a) {
507
905
  class WrappedAgentV1Client extends Client_js_5.V1Client {
508
906
  connect() {
509
907
  return __awaiter(this, arguments, void 0, function* (args = {}) {
510
- const { headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
908
+ const { headers, protocols, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
511
909
  const socket = yield createWebSocketConnection({
512
910
  options: this._options,
513
911
  urlPath: "/v1/agent/converse",
514
912
  environmentKey: "agent",
515
913
  queryParams: buildQueryParams(args),
914
+ protocols,
915
+ service: "agent.v1",
516
916
  headers,
517
917
  debug,
518
918
  reconnectAttempts,
@@ -584,12 +984,14 @@ class WrappedAgentV1Socket extends Socket_js_1.V1Socket {
584
984
  class WrappedListenV1Client extends Client_js_6.V1Client {
585
985
  connect(args) {
586
986
  return __awaiter(this, void 0, void 0, function* () {
587
- const { headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
987
+ const { headers, protocols, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
588
988
  const socket = yield createWebSocketConnection({
589
989
  options: this._options,
590
990
  urlPath: "/v1/listen",
591
991
  environmentKey: "production",
592
992
  queryParams: buildQueryParams(args),
993
+ protocols,
994
+ service: "listen.v1",
593
995
  headers,
594
996
  debug,
595
997
  reconnectAttempts,
@@ -660,12 +1062,14 @@ class WrappedListenV1Socket extends Socket_js_2.V1Socket {
660
1062
  class WrappedListenV2Client extends Client_js_7.V2Client {
661
1063
  connect(args) {
662
1064
  return __awaiter(this, void 0, void 0, function* () {
663
- const { headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
1065
+ const { headers, protocols, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
664
1066
  const socket = yield createWebSocketConnection({
665
1067
  options: this._options,
666
1068
  urlPath: "/v2/listen",
667
1069
  environmentKey: "production",
668
1070
  queryParams: buildQueryParams(args),
1071
+ protocols,
1072
+ service: "listen.v2",
669
1073
  headers,
670
1074
  debug,
671
1075
  reconnectAttempts,
@@ -767,12 +1171,14 @@ class WrappedListenV2Socket extends Socket_js_3.V2Socket {
767
1171
  class WrappedSpeakV1Client extends Client_js_8.V1Client {
768
1172
  connect(args) {
769
1173
  return __awaiter(this, void 0, void 0, function* () {
770
- const { headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
1174
+ const { headers, protocols, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal } = args;
771
1175
  const socket = yield createWebSocketConnection({
772
1176
  options: this._options,
773
1177
  urlPath: "/v1/speak",
774
1178
  environmentKey: "production",
775
1179
  queryParams: buildQueryParams(args),
1180
+ protocols,
1181
+ service: "speak.v1",
776
1182
  headers,
777
1183
  debug,
778
1184
  reconnectAttempts,
@@ -48,7 +48,7 @@ class BadRequestError extends errors.DeepgramError {
48
48
  if (Error.captureStackTrace) {
49
49
  Error.captureStackTrace(this, this.constructor);
50
50
  }
51
- this.name = this.constructor.name;
51
+ this.name = "BadRequestError";
52
52
  }
53
53
  }
54
54
  exports.BadRequestError = BadRequestError;
@@ -1,6 +1,10 @@
1
1
  import type * as Deepgram from "../../../../../index.js";
2
- export type AgentV1SettingsAgentListenProvider = Deepgram.agent.AgentV1SettingsAgentContextListenProvider;
2
+ export type AgentV1SettingsAgentListenProvider = Deepgram.agent.AgentV1SettingsAgentListenProvider.V1 | Deepgram.agent.AgentV1SettingsAgentListenProvider.V2;
3
3
  export declare namespace AgentV1SettingsAgentListenProvider {
4
- type V1 = Deepgram.agent.AgentV1SettingsAgentContextListenProvider.V1;
5
- type V2 = Deepgram.agent.AgentV1SettingsAgentContextListenProvider.V2;
4
+ interface V1 extends Deepgram.DeepgramListenProviderV1 {
5
+ version: "v1";
6
+ }
7
+ interface V2 extends Deepgram.DeepgramListenProviderV2 {
8
+ version: "v2";
9
+ }
6
10
  }
@@ -1,9 +1,3 @@
1
1
  "use strict";
2
- // Backward-compat alias for the type renamed by the 2026-05-06 regen to
3
- // `AgentV1SettingsAgentContextListenProvider`. The new V2 only adds an optional
4
- // `language_hint` field, so this alias is purely additive: every literal that
5
- // satisfied the old V2 still satisfies the new V2, and pinned-name callers
6
- // (`const p: AgentV1SettingsAgentListenProvider = ...`) keep compiling without
7
- // a cast. See AGENTS.md for the patch rationale; regression coverage in
8
- // tests/unit/compat-aliases.test.ts.
2
+ // This file was auto-generated by Fern from our API Definition.
9
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -11,6 +11,7 @@ export declare namespace V1Client {
11
11
  channels?: Deepgram.ListenV1Channels | undefined;
12
12
  detect_entities?: Deepgram.ListenV1DetectEntities;
13
13
  diarize?: Deepgram.ListenV1Diarize;
14
+ diarize_model?: Deepgram.listen.DiarizeModel;
14
15
  dictation?: Deepgram.ListenV1Dictation;
15
16
  encoding?: Deepgram.ListenV1Encoding;
16
17
  endpointing?: Deepgram.ListenV1Endpointing | undefined;
@@ -62,13 +62,14 @@ class V1Client {
62
62
  connect(args) {
63
63
  return __awaiter(this, void 0, void 0, function* () {
64
64
  var _a, _b, _c;
65
- const { callback, callback_method: callbackMethod, channels, detect_entities: detectEntities, 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, protocols, queryParams, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, } = args;
65
+ const { callback, callback_method: callbackMethod, channels, detect_entities: detectEntities, diarize, diarize_model: diarizeModel, 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, protocols, queryParams, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, } = args;
66
66
  const _queryParams = {
67
67
  callback: callback != null ? (typeof callback === "string" ? callback : (0, json_js_1.toJson)(callback)) : undefined,
68
68
  callback_method: callbackMethod != null ? callbackMethod : undefined,
69
69
  channels: channels != null ? (typeof channels === "string" ? channels : (0, json_js_1.toJson)(channels)) : undefined,
70
70
  detect_entities: detectEntities != null ? detectEntities : undefined,
71
71
  diarize: diarize != null ? diarize : undefined,
72
+ diarize_model: diarizeModel != null ? diarizeModel : undefined,
72
73
  dictation: dictation != null ? dictation : undefined,
73
74
  encoding: encoding != null ? encoding : undefined,
74
75
  endpointing: endpointing != null ? (typeof endpointing === "string" ? endpointing : (0, json_js_1.toJson)(endpointing)) : undefined,
@@ -71,9 +71,9 @@ export interface ListenV1RequestUrl {
71
71
  detect_entities?: boolean;
72
72
  /** Identifies the dominant language spoken in submitted audio */
73
73
  detect_language?: boolean;
74
- /** Recognize speaker changes. Each word in the transcript will be assigned a speaker number starting at 0 */
74
+ /** Deprecated: use `diarize_model` instead. Recognize speaker changes. Each word in the transcript will be assigned a speaker number starting at 0. */
75
75
  diarize?: boolean;
76
- /** Select and enable a specific batch diarization model version. If specifying this parameter, you should not set the deprecated `diarize=true` parameter. Not accepted on streaming requests. */
76
+ /** Select and enable a specific diarization model version. Specifying this parameter enables diarization and selects the model — you do not need to also set the deprecated `diarize=true` parameter. For batch, supported values are `latest` (currently v2), `v1`, and `v2`. For streaming, supported values are `latest` (currently v1) and `v1`; `v2` returns a validation error on streaming requests. */
77
77
  diarize_model?: Deepgram.listen.v1.MediaTranscribeRequestDiarizeModel;
78
78
  /** Dictation mode for controlling formatting with dictated speech */
79
79
  dictation?: boolean;
@@ -32,9 +32,9 @@ export interface MediaTranscribeRequestOctetStream {
32
32
  detect_entities?: boolean;
33
33
  /** Identifies the dominant language spoken in submitted audio */
34
34
  detect_language?: boolean;
35
- /** Recognize speaker changes. Each word in the transcript will be assigned a speaker number starting at 0 */
35
+ /** Deprecated: use `diarize_model` instead. Recognize speaker changes. Each word in the transcript will be assigned a speaker number starting at 0. */
36
36
  diarize?: boolean;
37
- /** Select and enable a specific batch diarization model version. If specifying this parameter, you should not set the deprecated `diarize=true` parameter. Not accepted on streaming requests. */
37
+ /** Select and enable a specific diarization model version. Specifying this parameter enables diarization and selects the model — you do not need to also set the deprecated `diarize=true` parameter. For batch, supported values are `latest` (currently v2), `v1`, and `v2`. For streaming, supported values are `latest` (currently v1) and `v1`; `v2` returns a validation error on streaming requests. */
38
38
  diarize_model?: Deepgram.listen.v1.MediaTranscribeRequestDiarizeModel;
39
39
  /** Dictation mode for controlling formatting with dictated speech */
40
40
  dictation?: boolean;
@@ -0,0 +1,5 @@
1
+ export declare const DiarizeModel: {
2
+ readonly Latest: "latest";
3
+ readonly V1: "v1";
4
+ };
5
+ export type DiarizeModel = (typeof DiarizeModel)[keyof typeof DiarizeModel] | string;
@@ -1,3 +1,8 @@
1
1
  "use strict";
2
2
  // This file was auto-generated by Fern from our API Definition.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DiarizeModel = void 0;
5
+ exports.DiarizeModel = {
6
+ Latest: "latest",
7
+ V1: "v1",
8
+ };