@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.
- package/README.md +44 -1
- package/dist/browser/index.global.js +8821 -0
- package/dist/cjs/BaseClient.js +3 -0
- package/dist/cjs/CustomClient.d.ts +9 -1
- package/dist/cjs/CustomClient.js +232 -21
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1Settings.d.ts +3 -43
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.ts +26 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.js +3 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.d.ts +28 -13
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.js +19 -17
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.d.ts +28 -13
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.js +19 -17
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.d.ts +115 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.js +57 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.d.ts +18 -3
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.js +2 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/index.d.ts +2 -0
- package/dist/cjs/api/resources/agent/resources/v1/types/index.js +2 -0
- package/dist/cjs/api/resources/listen/resources/v1/types/ListenV1Results.d.ts +3 -3
- package/dist/cjs/api/types/SpeakV1SampleRate.d.ts +1 -1
- package/dist/cjs/api/types/SpeakV1SampleRate.js +1 -1
- package/dist/cjs/core/websocket/ws.d.ts +0 -1
- package/dist/cjs/core/websocket/ws.js +9 -47
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +4 -0
- package/dist/esm/BaseClient.mjs +3 -0
- package/dist/esm/CustomClient.d.mts +9 -1
- package/dist/esm/CustomClient.mjs +232 -21
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1Settings.d.mts +3 -43
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.mts +26 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.mjs +2 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.d.mts +28 -13
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakEndpointProvider.mjs +19 -17
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.d.mts +28 -13
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentSpeakOneItemProvider.mjs +19 -17
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.d.mts +115 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1SettingsAgentThinkProvider.mjs +54 -0
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.d.mts +18 -3
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateSpeakSpeakProvider.mjs +2 -0
- package/dist/esm/api/resources/agent/resources/v1/types/index.d.mts +2 -0
- package/dist/esm/api/resources/agent/resources/v1/types/index.mjs +2 -0
- package/dist/esm/api/resources/listen/resources/v1/types/ListenV1Results.d.mts +3 -3
- package/dist/esm/api/types/SpeakV1SampleRate.d.mts +1 -1
- package/dist/esm/api/types/SpeakV1SampleRate.mjs +1 -1
- package/dist/esm/core/websocket/ws.d.mts +0 -1
- package/dist/esm/core/websocket/ws.mjs +9 -47
- package/dist/esm/version.d.mts +1 -0
- package/dist/esm/version.mjs +1 -0
- package/package.json +1 -28
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -42,6 +42,9 @@ const core = __importStar(require("./core/index.js"));
|
|
|
42
42
|
function normalizeClientOptions(options) {
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
|
+
"X-Fern-SDK-Name": "",
|
|
46
|
+
"X-Fern-SDK-Version": "0.0.228",
|
|
47
|
+
"User-Agent": "/0.0.228",
|
|
45
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
46
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
47
50
|
}, 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.js";
|
|
3
3
|
import type { ListenClient } from "./api/resources/listen/client/Client.js";
|
|
4
4
|
import type { SpeakClient } from "./api/resources/speak/client/Client.js";
|
|
5
|
+
import * as core from "./core/index.js";
|
|
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
|
-
|
|
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.
|
package/dist/cjs/CustomClient.js
CHANGED
|
@@ -60,13 +60,92 @@ 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
62
|
const environments = __importStar(require("./environments.js"));
|
|
63
|
+
const index_js_1 = require("./core/runtime/index.js");
|
|
64
|
+
// Import ws library for Node.js (will be undefined in browser)
|
|
65
|
+
let NodeWebSocket;
|
|
66
|
+
try {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
68
|
+
NodeWebSocket = require("ws");
|
|
69
|
+
// Handle both default export and named export
|
|
70
|
+
NodeWebSocket = NodeWebSocket.WebSocket || NodeWebSocket.default || NodeWebSocket;
|
|
71
|
+
}
|
|
72
|
+
catch (_a) {
|
|
73
|
+
// ws not available (e.g., in browser)
|
|
74
|
+
NodeWebSocket = undefined;
|
|
75
|
+
}
|
|
76
|
+
// Helper function to generate UUID that works in both Node.js and browser
|
|
77
|
+
function generateUUID() {
|
|
78
|
+
// In Node.js, use the crypto module
|
|
79
|
+
if (index_js_1.RUNTIME.type === "node") {
|
|
80
|
+
try {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
82
|
+
const crypto = require("crypto");
|
|
83
|
+
return crypto.randomUUID();
|
|
84
|
+
}
|
|
85
|
+
catch (_a) {
|
|
86
|
+
// Fallback if crypto module is not available
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// In browser or as fallback, use global crypto if available
|
|
90
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
91
|
+
return crypto.randomUUID();
|
|
92
|
+
}
|
|
93
|
+
// Fallback UUID generation (RFC4122 version 4)
|
|
94
|
+
// This is a simple fallback that should work everywhere
|
|
95
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
96
|
+
const r = (Math.random() * 16) | 0;
|
|
97
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
98
|
+
return v.toString(16);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Wrapper auth provider that checks for accessToken first (Bearer scheme)
|
|
103
|
+
* before falling back to the original auth provider (Token scheme for API keys).
|
|
104
|
+
*/
|
|
105
|
+
class AccessTokenAuthProviderWrapper {
|
|
106
|
+
constructor(originalProvider, accessToken) {
|
|
107
|
+
this.originalProvider = originalProvider;
|
|
108
|
+
this.accessToken = accessToken;
|
|
109
|
+
}
|
|
110
|
+
getAuthRequest(arg) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
var _a, _b;
|
|
113
|
+
// Check for access token first (highest priority)
|
|
114
|
+
// Access tokens use Bearer scheme, API keys use Token scheme
|
|
115
|
+
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;
|
|
116
|
+
if (accessToken != null) {
|
|
117
|
+
return {
|
|
118
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// Fall back to original provider (which handles API keys)
|
|
122
|
+
return this.originalProvider.getAuthRequest(arg);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
63
126
|
/**
|
|
64
127
|
* Custom wrapper around DeepgramClient that ensures the custom websocket implementation
|
|
65
128
|
* from ws.ts is always used, even if the auto-generated code changes.
|
|
66
129
|
*/
|
|
67
130
|
class CustomDeepgramClient extends Client_1.DeepgramClient {
|
|
68
131
|
constructor(options = {}) {
|
|
69
|
-
|
|
132
|
+
// Generate a UUID for the session ID
|
|
133
|
+
const sessionId = generateUUID();
|
|
134
|
+
// Add the session ID to headers so it's included in all REST requests
|
|
135
|
+
const optionsWithSessionId = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { "x-deepgram-session-id": sessionId }) });
|
|
136
|
+
super(optionsWithSessionId);
|
|
137
|
+
this._sessionId = sessionId;
|
|
138
|
+
// Wrap the auth provider to handle accessToken if provided
|
|
139
|
+
// This ensures accessToken takes priority over apiKey/env var
|
|
140
|
+
if (options.accessToken != null) {
|
|
141
|
+
this._options.authProvider = new AccessTokenAuthProviderWrapper(this._options.authProvider, options.accessToken);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get the session ID that was generated for this client instance.
|
|
146
|
+
*/
|
|
147
|
+
get sessionId() {
|
|
148
|
+
return this._sessionId;
|
|
70
149
|
}
|
|
71
150
|
/**
|
|
72
151
|
* Override the agent getter to return a wrapped client that ensures
|
|
@@ -130,24 +209,113 @@ class WrappedSpeakClient extends Client_js_3.SpeakClient {
|
|
|
130
209
|
return new WrappedSpeakV1Client(this._options);
|
|
131
210
|
}
|
|
132
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Helper function to resolve Suppliers in headers to their actual values.
|
|
214
|
+
*/
|
|
215
|
+
function resolveHeaders(headers) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
const resolved = {};
|
|
218
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
219
|
+
if (value == null) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
// Resolve Supplier if it's a Supplier, otherwise use the value directly
|
|
223
|
+
const resolvedValue = yield core.Supplier.get(value);
|
|
224
|
+
if (resolvedValue != null) {
|
|
225
|
+
resolved[key] = resolvedValue;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return resolved;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Helper function to get WebSocket class and handle headers/protocols based on runtime.
|
|
233
|
+
* In Node.js, use the 'ws' library which supports headers.
|
|
234
|
+
* In browser, use Sec-WebSocket-Protocol for authentication since headers aren't supported.
|
|
235
|
+
*/
|
|
236
|
+
function getWebSocketOptions(headers) {
|
|
237
|
+
const options = {};
|
|
238
|
+
// Check if we're in a browser environment (browser or web-worker)
|
|
239
|
+
const isBrowser = index_js_1.RUNTIME.type === "browser" || index_js_1.RUNTIME.type === "web-worker";
|
|
240
|
+
// Extract session ID header
|
|
241
|
+
const sessionIdHeader = headers["x-deepgram-session-id"] || headers["X-Deepgram-Session-Id"];
|
|
242
|
+
// In Node.js, ensure we use the 'ws' library which supports headers
|
|
243
|
+
if (index_js_1.RUNTIME.type === "node" && NodeWebSocket) {
|
|
244
|
+
options.WebSocket = NodeWebSocket;
|
|
245
|
+
options.headers = headers;
|
|
246
|
+
}
|
|
247
|
+
else if (isBrowser) {
|
|
248
|
+
// In browser, native WebSocket doesn't support custom headers
|
|
249
|
+
// Extract Authorization header and use Sec-WebSocket-Protocol instead
|
|
250
|
+
const authHeader = headers.Authorization || headers.authorization;
|
|
251
|
+
const browserHeaders = Object.assign({}, headers);
|
|
252
|
+
// Remove Authorization and session ID from headers since they won't work in browser
|
|
253
|
+
delete browserHeaders.Authorization;
|
|
254
|
+
delete browserHeaders.authorization;
|
|
255
|
+
delete browserHeaders["x-deepgram-session-id"];
|
|
256
|
+
delete browserHeaders["X-Deepgram-Session-Id"];
|
|
257
|
+
options.headers = browserHeaders;
|
|
258
|
+
// Build protocols array for browser WebSocket
|
|
259
|
+
const protocols = [];
|
|
260
|
+
// If we have an Authorization header, extract the token and format as protocols
|
|
261
|
+
// Deepgram expects:
|
|
262
|
+
// - For API keys: Sec-WebSocket-Protocol: token,API_KEY_GOES_HERE
|
|
263
|
+
// - For Bearer tokens: Sec-WebSocket-Protocol: bearer,TOKEN_GOES_HERE
|
|
264
|
+
// The comma separates multiple protocols, so we pass them as an array
|
|
265
|
+
if (authHeader && typeof authHeader === "string") {
|
|
266
|
+
if (authHeader.startsWith("Token ")) {
|
|
267
|
+
// API key: "Token API_KEY" -> ["token", "API_KEY"]
|
|
268
|
+
const apiKey = authHeader.substring(6); // Remove "Token " prefix
|
|
269
|
+
protocols.push("token", apiKey);
|
|
270
|
+
}
|
|
271
|
+
else if (authHeader.startsWith("Bearer ")) {
|
|
272
|
+
// Access token: "Bearer TOKEN" -> ["bearer", "TOKEN"]
|
|
273
|
+
const token = authHeader.substring(7); // Remove "Bearer " prefix
|
|
274
|
+
protocols.push("bearer", token);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
// Fallback: use the entire header value if it doesn't match expected format
|
|
278
|
+
protocols.push(authHeader);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Add session ID as a protocol for browser WebSocket
|
|
282
|
+
if (sessionIdHeader && typeof sessionIdHeader === "string") {
|
|
283
|
+
protocols.push("x-deepgram-session-id", sessionIdHeader);
|
|
284
|
+
}
|
|
285
|
+
if (protocols.length > 0) {
|
|
286
|
+
options.protocols = protocols;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
// Fallback for other environments
|
|
291
|
+
options.headers = headers;
|
|
292
|
+
}
|
|
293
|
+
return options;
|
|
294
|
+
}
|
|
133
295
|
/**
|
|
134
296
|
* Wrapper for Agent V1Client that overrides connect to use custom websocket.
|
|
135
297
|
*/
|
|
136
298
|
class WrappedAgentV1Client extends Client_js_4.V1Client {
|
|
137
299
|
connect() {
|
|
138
300
|
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
139
|
-
var _a, _b, _c, _d;
|
|
301
|
+
var _a, _b, _c, _d, _e, _f;
|
|
140
302
|
const { headers, debug, reconnectAttempts } = args;
|
|
141
303
|
// Get Authorization from authProvider (matching the working version)
|
|
142
304
|
const authRequest = yield ((_a = this._options.authProvider) === null || _a === void 0 ? void 0 : _a.getAuthRequest());
|
|
143
|
-
|
|
305
|
+
// Merge headers from options (which includes session ID), auth headers, and request headers
|
|
306
|
+
const mergedHeaders = (0, headers_js_1.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);
|
|
307
|
+
// Resolve any Suppliers in headers to actual values
|
|
308
|
+
const _headers = yield resolveHeaders(mergedHeaders);
|
|
309
|
+
// Get WebSocket options with proper header handling
|
|
310
|
+
const wsOptions = getWebSocketOptions(_headers);
|
|
144
311
|
// Explicitly use the custom ReconnectingWebSocket from ws.ts
|
|
145
312
|
const socket = new ws_js_1.ReconnectingWebSocket({
|
|
146
|
-
url: core.url.join((
|
|
147
|
-
protocols: [],
|
|
313
|
+
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"),
|
|
314
|
+
protocols: (_f = wsOptions.protocols) !== null && _f !== void 0 ? _f : [],
|
|
148
315
|
queryParameters: {},
|
|
149
|
-
headers:
|
|
316
|
+
headers: wsOptions.headers,
|
|
150
317
|
options: {
|
|
318
|
+
WebSocket: wsOptions.WebSocket,
|
|
151
319
|
debug: debug !== null && debug !== void 0 ? debug : false,
|
|
152
320
|
maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
|
|
153
321
|
startClosed: true,
|
|
@@ -203,6 +371,13 @@ class WrappedAgentV1Socket extends Socket_js_1.V1Socket {
|
|
|
203
371
|
}
|
|
204
372
|
}
|
|
205
373
|
connect() {
|
|
374
|
+
// Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
|
|
375
|
+
// by closing and reconnecting
|
|
376
|
+
if (this.socket.readyState === this.socket.CLOSED) {
|
|
377
|
+
// Force a fresh reconnect to ensure _connectLock is reset
|
|
378
|
+
this.socket._connectLock = false;
|
|
379
|
+
this.socket._shouldReconnect = true;
|
|
380
|
+
}
|
|
206
381
|
// Call parent connect, but then ensure our binary handler is still active
|
|
207
382
|
super.connect();
|
|
208
383
|
// Re-setup binary handling in case connect() re-registered handlers
|
|
@@ -216,7 +391,7 @@ class WrappedAgentV1Socket extends Socket_js_1.V1Socket {
|
|
|
216
391
|
class WrappedListenV1Client extends Client_js_5.V1Client {
|
|
217
392
|
connect(args) {
|
|
218
393
|
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
var _a, _b;
|
|
394
|
+
var _a, _b, _c, _d;
|
|
220
395
|
// Extract all the args (same as the original implementation)
|
|
221
396
|
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;
|
|
222
397
|
// Build query params (same as original)
|
|
@@ -276,14 +451,20 @@ class WrappedListenV1Client extends Client_js_5.V1Client {
|
|
|
276
451
|
_queryParams.version = version;
|
|
277
452
|
// Get Authorization from authProvider (matching the working version)
|
|
278
453
|
const authRequest = yield this._options.authProvider.getAuthRequest();
|
|
279
|
-
|
|
454
|
+
// Merge headers from options (which includes session ID), auth headers, and request headers
|
|
455
|
+
const mergedHeaders = (0, headers_js_1.mergeHeaders)((_a = this._options.headers) !== null && _a !== void 0 ? _a : {}, authRequest.headers, headers);
|
|
456
|
+
// Resolve any Suppliers in headers to actual values
|
|
457
|
+
const _headers = yield resolveHeaders(mergedHeaders);
|
|
458
|
+
// Get WebSocket options with proper header handling
|
|
459
|
+
const wsOptions = getWebSocketOptions(_headers);
|
|
280
460
|
// Explicitly use the custom ReconnectingWebSocket from ws.ts
|
|
281
461
|
const socket = new ws_js_1.ReconnectingWebSocket({
|
|
282
|
-
url: core.url.join((
|
|
283
|
-
protocols: [],
|
|
462
|
+
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"),
|
|
463
|
+
protocols: (_d = wsOptions.protocols) !== null && _d !== void 0 ? _d : [],
|
|
284
464
|
queryParameters: _queryParams,
|
|
285
|
-
headers:
|
|
465
|
+
headers: wsOptions.headers,
|
|
286
466
|
options: {
|
|
467
|
+
WebSocket: wsOptions.WebSocket,
|
|
287
468
|
debug: debug !== null && debug !== void 0 ? debug : false,
|
|
288
469
|
maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
|
|
289
470
|
startClosed: true,
|
|
@@ -335,6 +516,12 @@ class WrappedListenV1Socket extends Socket_js_2.V1Socket {
|
|
|
335
516
|
}
|
|
336
517
|
}
|
|
337
518
|
connect() {
|
|
519
|
+
// Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
|
|
520
|
+
if (this.socket.readyState === this.socket.CLOSED) {
|
|
521
|
+
// Force a fresh reconnect to ensure _connectLock is reset
|
|
522
|
+
this.socket._connectLock = false;
|
|
523
|
+
this.socket._shouldReconnect = true;
|
|
524
|
+
}
|
|
338
525
|
super.connect();
|
|
339
526
|
this.setupBinaryHandling();
|
|
340
527
|
return this;
|
|
@@ -346,7 +533,7 @@ class WrappedListenV1Socket extends Socket_js_2.V1Socket {
|
|
|
346
533
|
class WrappedListenV2Client extends Client_js_6.V2Client {
|
|
347
534
|
connect(args) {
|
|
348
535
|
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
-
var _a, _b, _c, _d;
|
|
536
|
+
var _a, _b, _c, _d, _e, _f;
|
|
350
537
|
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;
|
|
351
538
|
const _queryParams = {};
|
|
352
539
|
_queryParams.model = model;
|
|
@@ -368,14 +555,20 @@ class WrappedListenV2Client extends Client_js_6.V2Client {
|
|
|
368
555
|
_queryParams.tag = tag;
|
|
369
556
|
// Get Authorization from authProvider (matching the working version)
|
|
370
557
|
const authRequest = yield ((_a = this._options.authProvider) === null || _a === void 0 ? void 0 : _a.getAuthRequest());
|
|
371
|
-
|
|
558
|
+
// Merge headers from options (which includes session ID), auth headers, and request headers
|
|
559
|
+
const mergedHeaders = (0, headers_js_1.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);
|
|
560
|
+
// Resolve any Suppliers in headers to actual values
|
|
561
|
+
const _headers = yield resolveHeaders(mergedHeaders);
|
|
562
|
+
// Get WebSocket options with proper header handling
|
|
563
|
+
const wsOptions = getWebSocketOptions(_headers);
|
|
372
564
|
// Explicitly use the custom ReconnectingWebSocket from ws.ts
|
|
373
565
|
const socket = new ws_js_1.ReconnectingWebSocket({
|
|
374
|
-
url: core.url.join((
|
|
375
|
-
protocols: [],
|
|
566
|
+
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"),
|
|
567
|
+
protocols: (_f = wsOptions.protocols) !== null && _f !== void 0 ? _f : [],
|
|
376
568
|
queryParameters: _queryParams,
|
|
377
|
-
headers:
|
|
569
|
+
headers: wsOptions.headers,
|
|
378
570
|
options: {
|
|
571
|
+
WebSocket: wsOptions.WebSocket,
|
|
379
572
|
debug: debug !== null && debug !== void 0 ? debug : false,
|
|
380
573
|
maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
|
|
381
574
|
startClosed: true,
|
|
@@ -427,6 +620,12 @@ class WrappedListenV2Socket extends Socket_js_3.V2Socket {
|
|
|
427
620
|
}
|
|
428
621
|
}
|
|
429
622
|
connect() {
|
|
623
|
+
// Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
|
|
624
|
+
if (this.socket.readyState === this.socket.CLOSED) {
|
|
625
|
+
// Force a fresh reconnect to ensure _connectLock is reset
|
|
626
|
+
this.socket._connectLock = false;
|
|
627
|
+
this.socket._shouldReconnect = true;
|
|
628
|
+
}
|
|
430
629
|
super.connect();
|
|
431
630
|
this.setupBinaryHandling();
|
|
432
631
|
return this;
|
|
@@ -438,7 +637,7 @@ class WrappedListenV2Socket extends Socket_js_3.V2Socket {
|
|
|
438
637
|
class WrappedSpeakV1Client extends Client_js_7.V1Client {
|
|
439
638
|
connect(args) {
|
|
440
639
|
return __awaiter(this, void 0, void 0, function* () {
|
|
441
|
-
var _a, _b;
|
|
640
|
+
var _a, _b, _c, _d;
|
|
442
641
|
const { encoding, mip_opt_out: mipOptOut, model, sample_rate: sampleRate, headers, debug, reconnectAttempts, } = args;
|
|
443
642
|
const _queryParams = {};
|
|
444
643
|
if (encoding != null)
|
|
@@ -451,14 +650,20 @@ class WrappedSpeakV1Client extends Client_js_7.V1Client {
|
|
|
451
650
|
_queryParams.sample_rate = sampleRate;
|
|
452
651
|
// Get Authorization from authProvider (matching the working version)
|
|
453
652
|
const authRequest = yield this._options.authProvider.getAuthRequest();
|
|
454
|
-
|
|
653
|
+
// Merge headers from options (which includes session ID), auth headers, and request headers
|
|
654
|
+
const mergedHeaders = (0, headers_js_1.mergeHeaders)((_a = this._options.headers) !== null && _a !== void 0 ? _a : {}, authRequest.headers, headers);
|
|
655
|
+
// Resolve any Suppliers in headers to actual values
|
|
656
|
+
const _headers = yield resolveHeaders(mergedHeaders);
|
|
657
|
+
// Get WebSocket options with proper header handling
|
|
658
|
+
const wsOptions = getWebSocketOptions(_headers);
|
|
455
659
|
// Explicitly use the custom ReconnectingWebSocket from ws.ts
|
|
456
660
|
const socket = new ws_js_1.ReconnectingWebSocket({
|
|
457
|
-
url: core.url.join((
|
|
458
|
-
protocols: [],
|
|
661
|
+
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"),
|
|
662
|
+
protocols: (_d = wsOptions.protocols) !== null && _d !== void 0 ? _d : [],
|
|
459
663
|
queryParameters: _queryParams,
|
|
460
|
-
headers:
|
|
664
|
+
headers: wsOptions.headers,
|
|
461
665
|
options: {
|
|
666
|
+
WebSocket: wsOptions.WebSocket,
|
|
462
667
|
debug: debug !== null && debug !== void 0 ? debug : false,
|
|
463
668
|
maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
|
|
464
669
|
startClosed: true,
|
|
@@ -510,6 +715,12 @@ class WrappedSpeakV1Socket extends Socket_js_4.V1Socket {
|
|
|
510
715
|
}
|
|
511
716
|
}
|
|
512
717
|
connect() {
|
|
718
|
+
// Ensure socket is ready to connect - if _connectLock is stuck, force reconnect
|
|
719
|
+
if (this.socket.readyState === this.socket.CLOSED) {
|
|
720
|
+
// Force a fresh reconnect to ensure _connectLock is reset
|
|
721
|
+
this.socket._connectLock = false;
|
|
722
|
+
this.socket._shouldReconnect = true;
|
|
723
|
+
}
|
|
513
724
|
super.connect();
|
|
514
725
|
this.setupBinaryHandling();
|
|
515
726
|
return this;
|
|
@@ -73,7 +73,7 @@ export declare namespace AgentV1Settings {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
interface Agent {
|
|
76
|
-
/**
|
|
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?:
|
|
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:
|
|
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
|
*/
|
package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1SettingsAgentListenProvider.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type * as Deepgram from "../../../../../index.js";
|
|
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
|
+
}
|
|
@@ -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:
|
|
9
|
+
model: Deepgram.Model;
|
|
8
10
|
}
|
|
9
|
-
namespace
|
|
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:
|
|
82
|
-
/**
|
|
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
|
|
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:
|
|
98
|
-
voice:
|
|
105
|
+
model_id: Cartesia.ModelId;
|
|
106
|
+
voice: Cartesia.Voice;
|
|
99
107
|
/** Cartesia language code */
|
|
100
108
|
language?: string;
|
|
101
109
|
}
|
|
102
|
-
namespace
|
|
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:
|
|
132
|
+
model: OpenAi.Model;
|
|
120
133
|
/** OpenAI voice */
|
|
121
|
-
voice:
|
|
134
|
+
voice: OpenAi.Voice;
|
|
122
135
|
}
|
|
123
|
-
namespace
|
|
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
|
|
146
|
-
|
|
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
|
}
|