@deepgram/sdk 5.0.0-beta.3 → 5.0.0-beta.4
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 +50 -9
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/CustomClient.js +7 -0
- package/dist/cjs/api/resources/agent/resources/v1/client/Client.d.ts +2 -0
- package/dist/cjs/api/resources/agent/resources/v1/client/Client.js +2 -2
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1Settings.d.ts +2 -32
- package/dist/cjs/api/resources/agent/resources/v1/types/AgentV1UpdateSpeak.d.ts +2 -11
- package/dist/cjs/api/resources/listen/resources/v1/client/Client.d.ts +2 -0
- package/dist/cjs/api/resources/listen/resources/v1/client/Client.js +2 -2
- package/dist/cjs/api/resources/listen/resources/v2/client/Client.d.ts +2 -0
- package/dist/cjs/api/resources/listen/resources/v2/client/Client.js +2 -2
- package/dist/cjs/api/resources/speak/resources/v1/client/Client.d.ts +2 -0
- package/dist/cjs/api/resources/speak/resources/v1/client/Client.js +2 -2
- package/dist/cjs/api/types/OpenAiSpeakProvider.d.ts +27 -0
- package/dist/cjs/api/types/OpenAiSpeakProvider.js +21 -0
- package/dist/cjs/api/types/OpenAiThinkProvider.d.ts +23 -0
- package/dist/cjs/api/types/OpenAiThinkProvider.js +18 -0
- package/dist/cjs/api/types/SpeakSettingsV1Provider.d.ts +1 -1
- package/dist/cjs/api/types/ThinkSettingsV1.d.ts +2 -2
- package/dist/cjs/api/types/ThinkSettingsV1Provider.d.ts +19 -0
- package/dist/cjs/api/types/ThinkSettingsV1Provider.js +3 -0
- package/dist/cjs/api/types/index.d.ts +3 -1
- package/dist/cjs/api/types/index.js +3 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/middleware/adapters/express.d.ts +103 -0
- package/dist/cjs/middleware/adapters/express.js +141 -0
- package/dist/cjs/middleware/adapters/fastify.d.ts +32 -0
- package/dist/cjs/middleware/adapters/fastify.js +194 -0
- package/dist/cjs/middleware/adapters/http.d.ts +153 -0
- package/dist/cjs/middleware/adapters/http.js +192 -0
- package/dist/cjs/middleware/core/ProxyHandler.d.ts +35 -0
- package/dist/cjs/middleware/core/ProxyHandler.js +225 -0
- package/dist/cjs/middleware/core/TokenManager.d.ts +29 -0
- package/dist/cjs/middleware/core/TokenManager.js +110 -0
- package/dist/cjs/middleware/core/WebSocketProxy.d.ts +32 -0
- package/dist/cjs/middleware/core/WebSocketProxy.js +169 -0
- package/dist/cjs/middleware/core/jwt.d.ts +71 -0
- package/dist/cjs/middleware/core/jwt.js +136 -0
- package/dist/cjs/middleware/core/types.d.ts +37 -0
- package/dist/cjs/middleware/core/types.js +2 -0
- package/dist/cjs/middleware/index.d.ts +55 -0
- package/dist/cjs/middleware/index.js +75 -0
- package/dist/cjs/tests/manual/test-custom-baseurl.js +124 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/CustomClient.mjs +7 -0
- package/dist/esm/api/resources/agent/resources/v1/client/Client.d.mts +2 -0
- package/dist/esm/api/resources/agent/resources/v1/client/Client.mjs +2 -2
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1Settings.d.mts +2 -32
- package/dist/esm/api/resources/agent/resources/v1/types/AgentV1UpdateSpeak.d.mts +2 -11
- package/dist/esm/api/resources/listen/resources/v1/client/Client.d.mts +2 -0
- package/dist/esm/api/resources/listen/resources/v1/client/Client.mjs +2 -2
- package/dist/esm/api/resources/listen/resources/v2/client/Client.d.mts +2 -0
- package/dist/esm/api/resources/listen/resources/v2/client/Client.mjs +2 -2
- package/dist/esm/api/resources/speak/resources/v1/client/Client.d.mts +2 -0
- package/dist/esm/api/resources/speak/resources/v1/client/Client.mjs +2 -2
- package/dist/esm/api/types/OpenAiSpeakProvider.d.mts +27 -0
- package/dist/esm/api/types/OpenAiSpeakProvider.mjs +18 -0
- package/dist/esm/api/types/OpenAiThinkProvider.d.mts +23 -0
- package/dist/esm/api/types/OpenAiThinkProvider.mjs +15 -0
- package/dist/esm/api/types/SpeakSettingsV1Provider.d.mts +1 -1
- package/dist/esm/api/types/ThinkSettingsV1.d.mts +2 -2
- package/dist/esm/api/types/ThinkSettingsV1Provider.d.mts +19 -0
- package/dist/esm/api/types/ThinkSettingsV1Provider.mjs +2 -0
- package/dist/esm/api/types/index.d.mts +3 -1
- package/dist/esm/api/types/index.mjs +3 -1
- package/dist/esm/index.d.mts +2 -0
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/middleware/adapters/express.d.mts +103 -0
- package/dist/esm/middleware/adapters/express.mjs +136 -0
- package/dist/esm/middleware/adapters/fastify.d.mts +32 -0
- package/dist/esm/middleware/adapters/fastify.mjs +157 -0
- package/dist/esm/middleware/adapters/http.d.mts +153 -0
- package/dist/esm/middleware/adapters/http.mjs +187 -0
- package/dist/esm/middleware/core/ProxyHandler.d.mts +35 -0
- package/dist/esm/middleware/core/ProxyHandler.mjs +218 -0
- package/dist/esm/middleware/core/TokenManager.d.mts +29 -0
- package/dist/esm/middleware/core/TokenManager.mjs +106 -0
- package/dist/esm/middleware/core/WebSocketProxy.d.mts +32 -0
- package/dist/esm/middleware/core/WebSocketProxy.mjs +162 -0
- package/dist/esm/middleware/core/jwt.d.mts +71 -0
- package/dist/esm/middleware/core/jwt.mjs +99 -0
- package/dist/esm/middleware/core/types.d.mts +37 -0
- package/dist/esm/middleware/core/types.mjs +1 -0
- package/dist/esm/middleware/index.d.mts +55 -0
- package/dist/esm/middleware/index.mjs +59 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -214,9 +214,9 @@ const deepgramClient = new DeepgramClient({
|
|
|
214
214
|
});
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
#### Proxy requests in the browser
|
|
217
|
+
#### Proxy requests in the browser (Required)
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
Due to CORS header restrictions in the Deepgram API, you must use a proxy server when making REST API calls from browsers. To set up your proxy, you configure the SDK like so:
|
|
220
220
|
|
|
221
221
|
```js
|
|
222
222
|
import { DeepgramClient } from "@deepgram/sdk";
|
|
@@ -233,6 +233,8 @@ Your proxy service should replace the Authorization header with `Authorization:
|
|
|
233
233
|
|
|
234
234
|
Check out our example Node-based proxy here: [Deepgram Node Proxy](https://github.com/deepgram-devs/deepgram-node-proxy).
|
|
235
235
|
|
|
236
|
+
**Why is a proxy required?** The SDK sends custom headers (`X-Fern-Runtime-Version`, etc.) that are not whitelisted by the Deepgram API's CORS configuration, causing preflight requests to fail. A proxy bypasses this limitation while also keeping your API key secure.
|
|
237
|
+
|
|
236
238
|
#### Set custom headers for fetch
|
|
237
239
|
|
|
238
240
|
Useful for many things.
|
|
@@ -258,9 +260,11 @@ The SDK works in modern browsers with some considerations:
|
|
|
258
260
|
|
|
259
261
|
### REST API Features (Proxy Required)
|
|
260
262
|
|
|
261
|
-
- **Pre-recorded Transcription**: ⚠️ Requires proxy due to CORS
|
|
262
|
-
- **Text Intelligence**: ⚠️ Requires proxy due to CORS
|
|
263
|
-
- **Management APIs**: ⚠️ Requires proxy due to CORS
|
|
263
|
+
- **Pre-recorded Transcription**: ⚠️ Requires proxy due to CORS header restrictions
|
|
264
|
+
- **Text Intelligence**: ⚠️ Requires proxy due to CORS header restrictions
|
|
265
|
+
- **Management APIs**: ⚠️ Requires proxy due to CORS header restrictions
|
|
266
|
+
|
|
267
|
+
> **Important:** The SDK sends custom headers that are not allowed by the Deepgram API's CORS policy. You must use a proxy server (see setup instructions above) to make REST API calls from browsers.
|
|
264
268
|
|
|
265
269
|
### Setup Options
|
|
266
270
|
|
|
@@ -328,7 +332,7 @@ const deepgramClient = new DeepgramClient({ apiKey: "YOUR_API_KEY" });
|
|
|
328
332
|
|
|
329
333
|
#### Option 4: Proxy for REST APIs
|
|
330
334
|
|
|
331
|
-
See [proxy requests in the browser](#proxy-requests-in-the-browser)
|
|
335
|
+
See [proxy requests in the browser](#proxy-requests-in-the-browser-optional) to hide your API key from client-side code.
|
|
332
336
|
|
|
333
337
|
## Transcription
|
|
334
338
|
|
|
@@ -984,17 +988,54 @@ project, let us know! You can either:
|
|
|
984
988
|
|
|
985
989
|
## Request And Response Types
|
|
986
990
|
|
|
987
|
-
The SDK exports all request and response types as TypeScript interfaces.
|
|
988
|
-
|
|
991
|
+
The SDK exports all request and response types as TypeScript interfaces. You can import them in two ways:
|
|
992
|
+
|
|
993
|
+
### Direct Import (Recommended)
|
|
994
|
+
|
|
995
|
+
Import types directly for better IDE autocomplete and discoverability:
|
|
996
|
+
|
|
997
|
+
```typescript
|
|
998
|
+
import {
|
|
999
|
+
ListenV1Response,
|
|
1000
|
+
SpeakV1Response,
|
|
1001
|
+
ReadV1Response,
|
|
1002
|
+
GetProjectV1Response,
|
|
1003
|
+
CreateKeyV1Response,
|
|
1004
|
+
UsageV1Response,
|
|
1005
|
+
} from "@deepgram/sdk";
|
|
1006
|
+
|
|
1007
|
+
// Use types directly
|
|
1008
|
+
async function handleTranscription(response: ListenV1Response) {
|
|
1009
|
+
console.log(response.metadata);
|
|
1010
|
+
console.log(response.results);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
async function handleProject(project: GetProjectV1Response) {
|
|
1014
|
+
console.log(project.projectId);
|
|
1015
|
+
console.log(project.name);
|
|
1016
|
+
}
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
### Namespace Import
|
|
1020
|
+
|
|
1021
|
+
Alternatively, import types via the `Deepgram` namespace:
|
|
989
1022
|
|
|
990
1023
|
```typescript
|
|
991
1024
|
import { Deepgram } from "@deepgram/sdk";
|
|
992
1025
|
|
|
1026
|
+
// Use types via namespace
|
|
1027
|
+
async function handleTranscription(response: Deepgram.ListenV1Response) {
|
|
1028
|
+
console.log(response.metadata);
|
|
1029
|
+
console.log(response.results);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
993
1032
|
const request: Deepgram.GrantV1Request = {
|
|
994
|
-
|
|
1033
|
+
// ...
|
|
995
1034
|
};
|
|
996
1035
|
```
|
|
997
1036
|
|
|
1037
|
+
Both import styles refer to the same types and can be used interchangeably or mixed in the same file.
|
|
1038
|
+
|
|
998
1039
|
## Exception Handling
|
|
999
1040
|
|
|
1000
1041
|
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
|
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
|
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
45
|
"X-Fern-SDK-Name": "",
|
|
46
|
-
"X-Fern-SDK-Version": "0.0.
|
|
47
|
-
"User-Agent": "/0.0.
|
|
46
|
+
"X-Fern-SDK-Version": "0.0.320",
|
|
47
|
+
"User-Agent": "/0.0.320",
|
|
48
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
49
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
50
50
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
package/dist/cjs/CustomClient.js
CHANGED
|
@@ -834,6 +834,13 @@ class WrappedSpeakV1Client extends Client_js_8.V1Client {
|
|
|
834
834
|
class WrappedSpeakV1Socket extends Socket_js_4.V1Socket {
|
|
835
835
|
constructor(args) {
|
|
836
836
|
super(args);
|
|
837
|
+
// CRITICAL: Remove the autogenerated handleMessage that tries to parse EVERYTHING as JSON!
|
|
838
|
+
// The autogenerated Socket class assumes all messages are text/JSON, but TTS sends binary audio.
|
|
839
|
+
// We must remove that broken handler immediately after the parent constructor runs.
|
|
840
|
+
const socketAny = this;
|
|
841
|
+
if (socketAny.handleMessage) {
|
|
842
|
+
this.socket.removeEventListener("message", socketAny.handleMessage);
|
|
843
|
+
}
|
|
837
844
|
this.setupBinaryHandling();
|
|
838
845
|
}
|
|
839
846
|
setupBinaryHandling() {
|
|
@@ -6,6 +6,8 @@ export declare namespace V1Client {
|
|
|
6
6
|
type Options = BaseClientOptions;
|
|
7
7
|
interface ConnectArgs {
|
|
8
8
|
Authorization: string;
|
|
9
|
+
/** Additional query parameters to send with the websocket connect request. */
|
|
10
|
+
queryParams?: Record<string, unknown>;
|
|
9
11
|
/** Arbitrary headers to send with the websocket connect request. */
|
|
10
12
|
headers?: Record<string, string>;
|
|
11
13
|
/** Enable debug mode on the websocket. Defaults to false. */
|
|
@@ -61,12 +61,12 @@ class V1Client {
|
|
|
61
61
|
connect(args) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
63
|
var _a, _b;
|
|
64
|
-
const { headers, debug, reconnectAttempts } = args;
|
|
64
|
+
const { queryParams, headers, debug, reconnectAttempts } = args;
|
|
65
65
|
const _headers = (0, headers_js_1.mergeHeaders)((0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: args.Authorization }), headers);
|
|
66
66
|
const socket = new core.ReconnectingWebSocket({
|
|
67
67
|
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).agent, "/v1/agent/converse"),
|
|
68
68
|
protocols: [],
|
|
69
|
-
queryParameters: {},
|
|
69
|
+
queryParameters: queryParams !== null && queryParams !== void 0 ? queryParams : {},
|
|
70
70
|
headers: _headers,
|
|
71
71
|
options: { debug: debug !== null && debug !== void 0 ? debug : false, maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30 },
|
|
72
72
|
});
|
|
@@ -122,37 +122,7 @@ export declare namespace AgentV1Settings {
|
|
|
122
122
|
interface Listen {
|
|
123
123
|
provider?: Deepgram.agent.AgentV1SettingsAgentListenProvider;
|
|
124
124
|
}
|
|
125
|
-
type Think =
|
|
126
|
-
|
|
127
|
-
endpoint?: {
|
|
128
|
-
url?: string | undefined;
|
|
129
|
-
headers?: Record<string, string> | undefined;
|
|
130
|
-
} | undefined;
|
|
131
|
-
functions?: Record<string, unknown>[] | undefined;
|
|
132
|
-
prompt?: string | undefined;
|
|
133
|
-
context_length?: ("max" | number) | undefined;
|
|
134
|
-
} | {
|
|
135
|
-
provider: Record<string, unknown>;
|
|
136
|
-
endpoint?: {
|
|
137
|
-
url?: string | undefined;
|
|
138
|
-
headers?: Record<string, string> | undefined;
|
|
139
|
-
} | undefined;
|
|
140
|
-
functions?: Record<string, unknown>[] | undefined;
|
|
141
|
-
prompt?: string | undefined;
|
|
142
|
-
context_length?: ("max" | number) | undefined;
|
|
143
|
-
}[];
|
|
144
|
-
type Speak = {
|
|
145
|
-
provider: Record<string, unknown>;
|
|
146
|
-
endpoint?: {
|
|
147
|
-
url?: string | undefined;
|
|
148
|
-
headers?: Record<string, string> | undefined;
|
|
149
|
-
} | undefined;
|
|
150
|
-
} | {
|
|
151
|
-
provider: Record<string, unknown>;
|
|
152
|
-
endpoint?: {
|
|
153
|
-
url?: string | undefined;
|
|
154
|
-
headers?: Record<string, string> | undefined;
|
|
155
|
-
} | undefined;
|
|
156
|
-
}[];
|
|
125
|
+
type Think = Deepgram.ThinkSettingsV1 | Deepgram.ThinkSettingsV1[];
|
|
126
|
+
type Speak = Deepgram.SpeakSettingsV1 | Deepgram.SpeakSettingsV1[];
|
|
157
127
|
}
|
|
158
128
|
}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
+
import type * as Deepgram from "../../../../../index.js";
|
|
1
2
|
export interface AgentV1UpdateSpeak {
|
|
2
3
|
/** Message type identifier for updating the speak model */
|
|
3
4
|
type: "UpdateSpeak";
|
|
4
5
|
speak: AgentV1UpdateSpeak.Speak;
|
|
5
6
|
}
|
|
6
7
|
export declare namespace AgentV1UpdateSpeak {
|
|
7
|
-
|
|
8
|
-
/** TTS provider configuration (Deepgram, ElevenLabs, Cartesia, OpenAI, or AWS Polly) */
|
|
9
|
-
provider: Record<string, unknown>;
|
|
10
|
-
endpoint?: Speak.Endpoint;
|
|
11
|
-
}
|
|
12
|
-
namespace Speak {
|
|
13
|
-
interface Endpoint {
|
|
14
|
-
url?: string;
|
|
15
|
-
headers?: Record<string, string>;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
8
|
+
type Speak = Deepgram.SpeakSettingsV1 | Deepgram.SpeakSettingsV1[];
|
|
18
9
|
}
|
|
@@ -34,6 +34,8 @@ export declare namespace V1Client {
|
|
|
34
34
|
vad_events?: string;
|
|
35
35
|
version?: string;
|
|
36
36
|
Authorization: string;
|
|
37
|
+
/** Additional query parameters to send with the websocket connect request. */
|
|
38
|
+
queryParams?: Record<string, unknown>;
|
|
37
39
|
/** Arbitrary headers to send with the websocket connect request. */
|
|
38
40
|
headers?: Record<string, string>;
|
|
39
41
|
/** Enable debug mode on the websocket. Defaults to false. */
|
|
@@ -61,7 +61,7 @@ class V1Client {
|
|
|
61
61
|
connect(args) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
63
|
var _a, _b;
|
|
64
|
-
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, headers, debug, reconnectAttempts, } = args;
|
|
64
|
+
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, queryParams, headers, debug, reconnectAttempts, } = args;
|
|
65
65
|
const _queryParams = {
|
|
66
66
|
callback,
|
|
67
67
|
callback_method: callbackMethod,
|
|
@@ -96,7 +96,7 @@ class V1Client {
|
|
|
96
96
|
const socket = new core.ReconnectingWebSocket({
|
|
97
97
|
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"),
|
|
98
98
|
protocols: [],
|
|
99
|
-
queryParameters: _queryParams,
|
|
99
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), queryParams),
|
|
100
100
|
headers: _headers,
|
|
101
101
|
options: { debug: debug !== null && debug !== void 0 ? debug : false, maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30 },
|
|
102
102
|
});
|
|
@@ -14,6 +14,8 @@ export declare namespace V2Client {
|
|
|
14
14
|
mip_opt_out?: string;
|
|
15
15
|
tag?: string;
|
|
16
16
|
Authorization: string;
|
|
17
|
+
/** Additional query parameters to send with the websocket connect request. */
|
|
18
|
+
queryParams?: Record<string, unknown>;
|
|
17
19
|
/** Arbitrary headers to send with the websocket connect request. */
|
|
18
20
|
headers?: Record<string, string>;
|
|
19
21
|
/** Enable debug mode on the websocket. Defaults to false. */
|
|
@@ -56,7 +56,7 @@ class V2Client {
|
|
|
56
56
|
connect(args) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
58
|
var _a, _b;
|
|
59
|
-
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;
|
|
59
|
+
const { model, encoding, sample_rate: sampleRate, eager_eot_threshold: eagerEotThreshold, eot_threshold: eotThreshold, eot_timeout_ms: eotTimeoutMs, keyterm, mip_opt_out: mipOptOut, tag, queryParams, headers, debug, reconnectAttempts, } = args;
|
|
60
60
|
const _queryParams = {
|
|
61
61
|
model,
|
|
62
62
|
encoding,
|
|
@@ -72,7 +72,7 @@ class V2Client {
|
|
|
72
72
|
const socket = new core.ReconnectingWebSocket({
|
|
73
73
|
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, "/v2/listen"),
|
|
74
74
|
protocols: [],
|
|
75
|
-
queryParameters: _queryParams,
|
|
75
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), queryParams),
|
|
76
76
|
headers: _headers,
|
|
77
77
|
options: { debug: debug !== null && debug !== void 0 ? debug : false, maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30 },
|
|
78
78
|
});
|
|
@@ -10,6 +10,8 @@ export declare namespace V1Client {
|
|
|
10
10
|
model?: string;
|
|
11
11
|
sample_rate?: string;
|
|
12
12
|
Authorization: string;
|
|
13
|
+
/** Additional query parameters to send with the websocket connect request. */
|
|
14
|
+
queryParams?: Record<string, unknown>;
|
|
13
15
|
/** Arbitrary headers to send with the websocket connect request. */
|
|
14
16
|
headers?: Record<string, string>;
|
|
15
17
|
/** Enable debug mode on the websocket. Defaults to false. */
|
|
@@ -61,7 +61,7 @@ class V1Client {
|
|
|
61
61
|
connect(args) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
63
|
var _a, _b;
|
|
64
|
-
const { encoding, mip_opt_out: mipOptOut, model, sample_rate: sampleRate, headers, debug, reconnectAttempts, } = args;
|
|
64
|
+
const { encoding, mip_opt_out: mipOptOut, model, sample_rate: sampleRate, queryParams, headers, debug, reconnectAttempts, } = args;
|
|
65
65
|
const _queryParams = {
|
|
66
66
|
encoding,
|
|
67
67
|
mip_opt_out: mipOptOut,
|
|
@@ -72,7 +72,7 @@ class V1Client {
|
|
|
72
72
|
const socket = new core.ReconnectingWebSocket({
|
|
73
73
|
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"),
|
|
74
74
|
protocols: [],
|
|
75
|
-
queryParameters: _queryParams,
|
|
75
|
+
queryParameters: Object.assign(Object.assign({}, _queryParams), queryParams),
|
|
76
76
|
headers: _headers,
|
|
77
77
|
options: { debug: debug !== null && debug !== void 0 ? debug : false, maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30 },
|
|
78
78
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface OpenAiSpeakProvider {
|
|
2
|
+
type: "open_ai";
|
|
3
|
+
/** The REST API version for the OpenAI text-to-speech API */
|
|
4
|
+
version?: "v1";
|
|
5
|
+
/** OpenAI TTS model */
|
|
6
|
+
model: OpenAiSpeakProvider.Model;
|
|
7
|
+
/** OpenAI voice */
|
|
8
|
+
voice: OpenAiSpeakProvider.Voice;
|
|
9
|
+
}
|
|
10
|
+
export declare namespace OpenAiSpeakProvider {
|
|
11
|
+
/** OpenAI TTS model */
|
|
12
|
+
const Model: {
|
|
13
|
+
readonly Tts1: "tts-1";
|
|
14
|
+
readonly Tts1Hd: "tts-1-hd";
|
|
15
|
+
};
|
|
16
|
+
type Model = (typeof Model)[keyof typeof Model] | string;
|
|
17
|
+
/** OpenAI voice */
|
|
18
|
+
const Voice: {
|
|
19
|
+
readonly Alloy: "alloy";
|
|
20
|
+
readonly Echo: "echo";
|
|
21
|
+
readonly Fable: "fable";
|
|
22
|
+
readonly Onyx: "onyx";
|
|
23
|
+
readonly Nova: "nova";
|
|
24
|
+
readonly Shimmer: "shimmer";
|
|
25
|
+
};
|
|
26
|
+
type Voice = (typeof Voice)[keyof typeof Voice] | string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OpenAiSpeakProvider = void 0;
|
|
5
|
+
var OpenAiSpeakProvider;
|
|
6
|
+
(function (OpenAiSpeakProvider) {
|
|
7
|
+
/** OpenAI TTS model */
|
|
8
|
+
OpenAiSpeakProvider.Model = {
|
|
9
|
+
Tts1: "tts-1",
|
|
10
|
+
Tts1Hd: "tts-1-hd",
|
|
11
|
+
};
|
|
12
|
+
/** OpenAI voice */
|
|
13
|
+
OpenAiSpeakProvider.Voice = {
|
|
14
|
+
Alloy: "alloy",
|
|
15
|
+
Echo: "echo",
|
|
16
|
+
Fable: "fable",
|
|
17
|
+
Onyx: "onyx",
|
|
18
|
+
Nova: "nova",
|
|
19
|
+
Shimmer: "shimmer",
|
|
20
|
+
};
|
|
21
|
+
})(OpenAiSpeakProvider || (exports.OpenAiSpeakProvider = OpenAiSpeakProvider = {}));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface OpenAiThinkProvider {
|
|
2
|
+
type: "open_ai";
|
|
3
|
+
/** The REST API version for the OpenAI chat completions API */
|
|
4
|
+
version?: "v1";
|
|
5
|
+
/** OpenAI model to use */
|
|
6
|
+
model: OpenAiThinkProvider.Model;
|
|
7
|
+
/** OpenAI temperature (0-2) */
|
|
8
|
+
temperature?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare namespace OpenAiThinkProvider {
|
|
11
|
+
/** OpenAI model to use */
|
|
12
|
+
const Model: {
|
|
13
|
+
readonly Gpt5: "gpt-5";
|
|
14
|
+
readonly Gpt5Mini: "gpt-5-mini";
|
|
15
|
+
readonly Gpt5Nano: "gpt-5-nano";
|
|
16
|
+
readonly Gpt41: "gpt-4.1";
|
|
17
|
+
readonly Gpt41Mini: "gpt-4.1-mini";
|
|
18
|
+
readonly Gpt41Nano: "gpt-4.1-nano";
|
|
19
|
+
readonly Gpt4O: "gpt-4o";
|
|
20
|
+
readonly Gpt4OMini: "gpt-4o-mini";
|
|
21
|
+
};
|
|
22
|
+
type Model = (typeof Model)[keyof typeof Model] | string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OpenAiThinkProvider = void 0;
|
|
5
|
+
var OpenAiThinkProvider;
|
|
6
|
+
(function (OpenAiThinkProvider) {
|
|
7
|
+
/** OpenAI model to use */
|
|
8
|
+
OpenAiThinkProvider.Model = {
|
|
9
|
+
Gpt5: "gpt-5",
|
|
10
|
+
Gpt5Mini: "gpt-5-mini",
|
|
11
|
+
Gpt5Nano: "gpt-5-nano",
|
|
12
|
+
Gpt41: "gpt-4.1",
|
|
13
|
+
Gpt41Mini: "gpt-4.1-mini",
|
|
14
|
+
Gpt41Nano: "gpt-4.1-nano",
|
|
15
|
+
Gpt4O: "gpt-4o",
|
|
16
|
+
Gpt4OMini: "gpt-4o-mini",
|
|
17
|
+
};
|
|
18
|
+
})(OpenAiThinkProvider || (exports.OpenAiThinkProvider = OpenAiThinkProvider = {}));
|
|
@@ -10,7 +10,7 @@ export declare namespace SpeakSettingsV1Provider {
|
|
|
10
10
|
interface Cartesia extends Deepgram.Cartesia {
|
|
11
11
|
type: "cartesia";
|
|
12
12
|
}
|
|
13
|
-
interface OpenAi extends Deepgram.
|
|
13
|
+
interface OpenAi extends Deepgram.OpenAiSpeakProvider {
|
|
14
14
|
type: "open_ai";
|
|
15
15
|
}
|
|
16
16
|
interface AwsPolly extends Deepgram.AwsPollySpeakProvider {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type * as Deepgram from "../index.js";
|
|
1
2
|
export interface ThinkSettingsV1 {
|
|
2
|
-
|
|
3
|
-
provider: Record<string, unknown>;
|
|
3
|
+
provider: Deepgram.ThinkSettingsV1Provider;
|
|
4
4
|
/** Optional for non-Deepgram LLM providers. When present, must include url field and headers object */
|
|
5
5
|
endpoint?: ThinkSettingsV1.Endpoint;
|
|
6
6
|
functions?: ThinkSettingsV1.Functions.Item[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as Deepgram from "../index.js";
|
|
2
|
+
export type ThinkSettingsV1Provider = Deepgram.ThinkSettingsV1Provider.OpenAi | Deepgram.ThinkSettingsV1Provider.AwsBedrock | Deepgram.ThinkSettingsV1Provider.Anthropic | Deepgram.ThinkSettingsV1Provider.Google | Deepgram.ThinkSettingsV1Provider.Groq;
|
|
3
|
+
export declare namespace ThinkSettingsV1Provider {
|
|
4
|
+
interface OpenAi extends Deepgram.OpenAiThinkProvider {
|
|
5
|
+
type: "open_ai";
|
|
6
|
+
}
|
|
7
|
+
interface AwsBedrock extends Deepgram.AwsBedrockThinkProvider {
|
|
8
|
+
type: "aws_bedrock";
|
|
9
|
+
}
|
|
10
|
+
interface Anthropic extends Deepgram.Anthropic {
|
|
11
|
+
type: "anthropic";
|
|
12
|
+
}
|
|
13
|
+
interface Google extends Deepgram.Google {
|
|
14
|
+
type: "google";
|
|
15
|
+
}
|
|
16
|
+
interface Groq extends Deepgram.Groq {
|
|
17
|
+
type: "groq";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -88,7 +88,8 @@ export * from "./ListProjectMembersV1Response.js";
|
|
|
88
88
|
export * from "./ListProjectPurchasesV1Response.js";
|
|
89
89
|
export * from "./ListProjectRequestsV1Response.js";
|
|
90
90
|
export * from "./ListProjectsV1Response.js";
|
|
91
|
-
export * from "./
|
|
91
|
+
export * from "./OpenAiSpeakProvider.js";
|
|
92
|
+
export * from "./OpenAiThinkProvider.js";
|
|
92
93
|
export * from "./ProjectRequestResponse.js";
|
|
93
94
|
export * from "./ReadV1Request.js";
|
|
94
95
|
export * from "./ReadV1RequestText.js";
|
|
@@ -108,6 +109,7 @@ export * from "./SpeakV1Model.js";
|
|
|
108
109
|
export * from "./SpeakV1Response.js";
|
|
109
110
|
export * from "./SpeakV1SampleRate.js";
|
|
110
111
|
export * from "./ThinkSettingsV1.js";
|
|
112
|
+
export * from "./ThinkSettingsV1Provider.js";
|
|
111
113
|
export * from "./UpdateProjectMemberScopesV1Response.js";
|
|
112
114
|
export * from "./UpdateProjectV1Response.js";
|
|
113
115
|
export * from "./UsageBreakdownV1Response.js";
|
|
@@ -104,7 +104,8 @@ __exportStar(require("./ListProjectMembersV1Response.js"), exports);
|
|
|
104
104
|
__exportStar(require("./ListProjectPurchasesV1Response.js"), exports);
|
|
105
105
|
__exportStar(require("./ListProjectRequestsV1Response.js"), exports);
|
|
106
106
|
__exportStar(require("./ListProjectsV1Response.js"), exports);
|
|
107
|
-
__exportStar(require("./
|
|
107
|
+
__exportStar(require("./OpenAiSpeakProvider.js"), exports);
|
|
108
|
+
__exportStar(require("./OpenAiThinkProvider.js"), exports);
|
|
108
109
|
__exportStar(require("./ProjectRequestResponse.js"), exports);
|
|
109
110
|
__exportStar(require("./ReadV1Request.js"), exports);
|
|
110
111
|
__exportStar(require("./ReadV1RequestText.js"), exports);
|
|
@@ -124,6 +125,7 @@ __exportStar(require("./SpeakV1Model.js"), exports);
|
|
|
124
125
|
__exportStar(require("./SpeakV1Response.js"), exports);
|
|
125
126
|
__exportStar(require("./SpeakV1SampleRate.js"), exports);
|
|
126
127
|
__exportStar(require("./ThinkSettingsV1.js"), exports);
|
|
128
|
+
__exportStar(require("./ThinkSettingsV1Provider.js"), exports);
|
|
127
129
|
__exportStar(require("./UpdateProjectMemberScopesV1Response.js"), exports);
|
|
128
130
|
__exportStar(require("./UpdateProjectV1Response.js"), exports);
|
|
129
131
|
__exportStar(require("./UsageBreakdownV1Response.js"), exports);
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * as Deepgram from "./api/index.js";
|
|
2
|
+
export * from "./api/types/index.js";
|
|
3
|
+
export * from "./api/resources/index.js";
|
|
2
4
|
export type { BaseClientOptions, BaseRequestOptions } from "./BaseClient.js";
|
|
3
5
|
export { DeepgramClient as DefaultDeepgramClient } from "./Client.js";
|
|
4
6
|
export { CustomDeepgramClient as DeepgramClient } from "./CustomClient.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -37,7 +37,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.DeepgramTimeoutError = exports.DeepgramError = exports.DeepgramEnvironment = exports.DeepgramClient = exports.DefaultDeepgramClient = exports.Deepgram = void 0;
|
|
40
|
+
// Export everything under Deepgram namespace for backwards compatibility
|
|
40
41
|
exports.Deepgram = __importStar(require("./api/index.js"));
|
|
42
|
+
// ALSO export all types directly for better discoverability and IDE autocomplete
|
|
43
|
+
// This allows: import { ListenV1Response } from "@deepgram/sdk"
|
|
44
|
+
// While still supporting: import { Deepgram } from "@deepgram/sdk"; type Response = Deepgram.ListenV1Response;
|
|
45
|
+
__exportStar(require("./api/types/index.js"), exports);
|
|
46
|
+
__exportStar(require("./api/resources/index.js"), exports);
|
|
41
47
|
var Client_js_1 = require("./Client.js");
|
|
42
48
|
Object.defineProperty(exports, "DefaultDeepgramClient", { enumerable: true, get: function () { return Client_js_1.DeepgramClient; } });
|
|
43
49
|
var CustomClient_js_1 = require("./CustomClient.js");
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express middleware for proxying Deepgram API requests.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*
|
|
6
|
+
* **Peer Dependencies Required:**
|
|
7
|
+
* ```bash
|
|
8
|
+
* npm install express
|
|
9
|
+
* # or
|
|
10
|
+
* pnpm add express
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* This module provides Express-compatible middleware for proxying requests to the
|
|
14
|
+
* Deepgram API, including REST endpoints and WebSocket connections.
|
|
15
|
+
*/
|
|
16
|
+
import type { IncomingMessage, Server, ServerResponse } from "node:http";
|
|
17
|
+
import type { Duplex } from "node:stream";
|
|
18
|
+
import type { MiddlewareOptions } from "../core/types.js";
|
|
19
|
+
/**
|
|
20
|
+
* Express middleware type
|
|
21
|
+
*/
|
|
22
|
+
export type ExpressMiddleware = (req: IncomingMessage, res: ServerResponse, next: (error?: Error) => void) => void | Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* WebSocket upgrade handler type
|
|
25
|
+
*/
|
|
26
|
+
export type UpgradeHandler = (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Create Express middleware for proxying Deepgram API requests
|
|
29
|
+
*
|
|
30
|
+
* @param options - Middleware configuration options
|
|
31
|
+
* @returns Express middleware function
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import express from 'express';
|
|
36
|
+
* import { createDeepgramProxy, createWebSocketHandler } from '@deepgram/sdk';
|
|
37
|
+
*
|
|
38
|
+
* const app = express();
|
|
39
|
+
* const proxyOptions = {
|
|
40
|
+
* apiKey: process.env.DEEPGRAM_API_KEY!,
|
|
41
|
+
* enableTokenAuth: true
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* // REST API proxy
|
|
45
|
+
* app.use('/api/deepgram', createDeepgramProxy(proxyOptions));
|
|
46
|
+
*
|
|
47
|
+
* // WebSocket upgrade handler
|
|
48
|
+
* const server = app.listen(3000);
|
|
49
|
+
* server.on('upgrade', createWebSocketHandler(proxyOptions));
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function createDeepgramProxy(options: MiddlewareOptions): ExpressMiddleware;
|
|
53
|
+
/**
|
|
54
|
+
* Create WebSocket upgrade handler for Express
|
|
55
|
+
*
|
|
56
|
+
* This must be registered on the HTTP server, not the Express app.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Middleware configuration options
|
|
59
|
+
* @returns Upgrade handler function
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import express from 'express';
|
|
64
|
+
* import { createWebSocketHandler } from '@deepgram/sdk';
|
|
65
|
+
*
|
|
66
|
+
* const app = express();
|
|
67
|
+
* const server = app.listen(3000);
|
|
68
|
+
*
|
|
69
|
+
* // Register WebSocket handler on the server
|
|
70
|
+
* server.on('upgrade', createWebSocketHandler({
|
|
71
|
+
* apiKey: process.env.DEEPGRAM_API_KEY!
|
|
72
|
+
* }));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function createWebSocketHandler(options: MiddlewareOptions): UpgradeHandler;
|
|
76
|
+
/**
|
|
77
|
+
* Combined helper that returns both middleware and upgrade handler
|
|
78
|
+
*
|
|
79
|
+
* @param options - Middleware configuration options
|
|
80
|
+
* @returns Object with middleware and upgrade handler
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import express from 'express';
|
|
85
|
+
* import { createDeepgramMiddleware } from '@deepgram/sdk';
|
|
86
|
+
*
|
|
87
|
+
* const app = express();
|
|
88
|
+
* const { middleware, upgradeHandler } = createDeepgramMiddleware({
|
|
89
|
+
* apiKey: process.env.DEEPGRAM_API_KEY!,
|
|
90
|
+
* enableTokenAuth: true
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* app.use('/api/deepgram', middleware);
|
|
94
|
+
*
|
|
95
|
+
* const server = app.listen(3000);
|
|
96
|
+
* server.on('upgrade', upgradeHandler);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function createDeepgramMiddleware(options: MiddlewareOptions): {
|
|
100
|
+
middleware: ExpressMiddleware;
|
|
101
|
+
upgradeHandler: UpgradeHandler;
|
|
102
|
+
server: (httpServer: Server) => void;
|
|
103
|
+
};
|