@framers/agentos-ext-streaming-stt-deepgram 0.2.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.
@@ -0,0 +1,351 @@
1
+ /**
2
+ * @file DeepgramStreamSession.ts
3
+ * @description Active streaming STT session backed by the Deepgram WebSocket API.
4
+ *
5
+ * {@link DeepgramStreamSession} implements the {@link StreamingSTTSession} interface
6
+ * (which extends `EventEmitter`) and adds Deepgram-specific convenience events:
7
+ *
8
+ * | Event | Payload | Description |
9
+ * |-----------------------|----------------------|-------------------------------------------------------|
10
+ * | `'transcript'` | `TranscriptEvent` | Every hypothesis (interim + final, per base interface)|
11
+ * | `'interim_transcript'`| `TranscriptEvent` | Non-final hypothesis only |
12
+ * | `'final_transcript'` | `TranscriptEvent` | Final (stable) hypothesis |
13
+ * | `'speech_start'` | — | First non-empty word received in this utterance |
14
+ * | `'speech_end'` | — | Deepgram `speech_final` flag fired |
15
+ * | `'error'` | `Error` | Unrecoverable provider error |
16
+ * | `'close'` | — | Session fully terminated |
17
+ *
18
+ * ### Auto-reconnect
19
+ * On an unexpected WebSocket close (code ≠ 1000/1001), the session buffers
20
+ * incoming audio frames (up to 5 s worth at 16 kHz / 512 samples per frame)
21
+ * and reattempts the connection with exponential back-off starting at 100 ms,
22
+ * doubling each attempt up to a cap of 5 000 ms.
23
+ *
24
+ * @module streaming-stt-deepgram/DeepgramStreamSession
25
+ */
26
+ import { EventEmitter } from 'node:events';
27
+ import WebSocket from 'ws';
28
+ import { extractSpeakerFromWords, mapDeepgramWord } from './DeepgramDiarizationAdapter.js';
29
+ // ---------------------------------------------------------------------------
30
+ // Constants
31
+ // ---------------------------------------------------------------------------
32
+ /** Deepgram WebSocket entry point for streaming recognition. */
33
+ const DEEPGRAM_WS_BASE = 'wss://api.deepgram.com/v1/listen';
34
+ /** Maximum number of audio frames to buffer during reconnect (~5 s at 16 kHz/512). */
35
+ const MAX_BUFFER_FRAMES = 500;
36
+ /** Initial reconnect back-off delay in milliseconds. */
37
+ const BACKOFF_INITIAL_MS = 100;
38
+ /** Maximum reconnect back-off delay in milliseconds. */
39
+ const BACKOFF_MAX_MS = 5_000;
40
+ // ---------------------------------------------------------------------------
41
+ // Helpers
42
+ // ---------------------------------------------------------------------------
43
+ /**
44
+ * Convert a Float32Array of normalised PCM samples to a 16-bit signed integer
45
+ * PCM Buffer (little-endian), as required by the Deepgram `linear16` encoding.
46
+ *
47
+ * Samples are clamped to [-1, 1] before scaling to prevent wrap-around on
48
+ * values outside the normalised range.
49
+ *
50
+ * @param samples - Float32 PCM input, each sample in [-1, 1].
51
+ * @returns Node.js `Buffer` of Int16 samples (2 bytes each, little-endian).
52
+ */
53
+ function float32ToInt16Buffer(samples) {
54
+ const buf = Buffer.allocUnsafe(samples.length * 2);
55
+ for (let i = 0; i < samples.length; i++) {
56
+ // Clamp to [-1, 1] then scale to the Int16 range.
57
+ const clamped = Math.max(-1, Math.min(1, samples[i]));
58
+ buf.writeInt16LE(Math.round(clamped * 0x7fff), i * 2);
59
+ }
60
+ return buf;
61
+ }
62
+ /**
63
+ * Build the Deepgram WebSocket URL from the resolved configuration.
64
+ *
65
+ * @param cfg - Resolved Deepgram streaming configuration.
66
+ * @returns Full `wss://` URL with query parameters.
67
+ */
68
+ function buildWsUrl(cfg) {
69
+ const params = new URLSearchParams({
70
+ model: cfg.model,
71
+ language: cfg.language,
72
+ punctuate: String(cfg.punctuate),
73
+ interim_results: String(cfg.interimResults),
74
+ diarize: String(cfg.diarize),
75
+ encoding: 'linear16',
76
+ sample_rate: '16000',
77
+ channels: '1',
78
+ });
79
+ if (cfg.keywords && cfg.keywords.length > 0) {
80
+ for (const kw of cfg.keywords) {
81
+ params.append('keywords', kw);
82
+ }
83
+ }
84
+ if (cfg.endpointing !== false && cfg.endpointing !== undefined) {
85
+ params.set('endpointing', String(cfg.endpointing));
86
+ }
87
+ return `${DEEPGRAM_WS_BASE}?${params.toString()}`;
88
+ }
89
+ // ---------------------------------------------------------------------------
90
+ // Main class
91
+ // ---------------------------------------------------------------------------
92
+ /**
93
+ * Active streaming STT session backed by a Deepgram WebSocket connection.
94
+ *
95
+ * Construct via {@link DeepgramStreamingSTT.startSession} rather than directly.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const session = new DeepgramStreamSession({ apiKey: process.env.DEEPGRAM_API_KEY! });
100
+ *
101
+ * session.on('interim_transcript', (evt) => process.stdout.write(`\r${evt.text}`));
102
+ * session.on('final_transcript', (evt) => console.log(`FINAL: ${evt.text}`));
103
+ * session.on('speech_end', () => console.log('utterance ended'));
104
+ *
105
+ * // Push audio frames from a microphone source:
106
+ * microphone.on('frame', (frame) => session.pushAudio(frame));
107
+ *
108
+ * // Signal end of utterance:
109
+ * await session.flush();
110
+ * session.close();
111
+ * ```
112
+ */
113
+ export class DeepgramStreamSession extends EventEmitter {
114
+ // -------------------------------------------------------------------------
115
+ // Private state
116
+ // -------------------------------------------------------------------------
117
+ /** Resolved configuration with all defaults applied. */
118
+ cfg;
119
+ /** Current WebSocket connection (replaced on reconnect). */
120
+ ws = null;
121
+ /** `true` once the first non-empty transcript arrives in this utterance. */
122
+ speechStarted = false;
123
+ /** `true` after {@link close} is called — prevents reconnect attempts. */
124
+ closed = false;
125
+ /**
126
+ * Ring buffer of audio frames accumulated while the WebSocket is
127
+ * reconnecting. Capped at {@link MAX_BUFFER_FRAMES} to bound memory.
128
+ */
129
+ reconnectBuffer = [];
130
+ /** Current reconnect back-off delay in milliseconds. */
131
+ backoffMs = BACKOFF_INITIAL_MS;
132
+ /** Active reconnect timer handle. */
133
+ reconnectTimer = null;
134
+ /** `true` while the WebSocket is open and ready to accept binary data. */
135
+ wsReady = false;
136
+ // -------------------------------------------------------------------------
137
+ // Constructor
138
+ // -------------------------------------------------------------------------
139
+ /**
140
+ * @param config - Deepgram streaming configuration. `apiKey` is required;
141
+ * all other fields have sensible defaults.
142
+ */
143
+ constructor(config) {
144
+ super();
145
+ // Apply defaults.
146
+ this.cfg = {
147
+ model: 'nova-2',
148
+ language: 'en-US',
149
+ punctuate: true,
150
+ interimResults: true,
151
+ diarize: false,
152
+ ...config,
153
+ };
154
+ this.connect();
155
+ }
156
+ // -------------------------------------------------------------------------
157
+ // StreamingSTTSession interface
158
+ // -------------------------------------------------------------------------
159
+ /**
160
+ * Push a raw PCM audio frame into the recognition stream.
161
+ *
162
+ * Converts Float32 samples to Int16 linear PCM and transmits them as binary
163
+ * over the WebSocket. Frames received while the socket is reconnecting are
164
+ * queued in {@link reconnectBuffer} (up to {@link MAX_BUFFER_FRAMES}).
165
+ *
166
+ * @param frame - Audio frame with normalised Float32 samples at any sample rate.
167
+ * Frames are sent as-is; resample to 16 kHz before calling if
168
+ * the source differs from the Deepgram session's `sample_rate`.
169
+ */
170
+ pushAudio(frame) {
171
+ if (this.closed)
172
+ return;
173
+ const pcmBuffer = float32ToInt16Buffer(frame.samples);
174
+ if (this.wsReady && this.ws) {
175
+ this.ws.send(pcmBuffer);
176
+ }
177
+ else {
178
+ // Buffer frames during reconnect — drop the oldest when full.
179
+ if (this.reconnectBuffer.length >= MAX_BUFFER_FRAMES) {
180
+ this.reconnectBuffer.shift();
181
+ }
182
+ this.reconnectBuffer.push(frame);
183
+ }
184
+ }
185
+ /**
186
+ * Signal end-of-utterance to Deepgram.
187
+ *
188
+ * Sends the JSON `{"type":"CloseStream"}` control message, instructing
189
+ * Deepgram to flush any buffered audio and emit a final transcript before
190
+ * closing the connection from their side.
191
+ *
192
+ * @returns A promise that resolves immediately after the message is enqueued.
193
+ */
194
+ async flush() {
195
+ if (this.ws && this.wsReady) {
196
+ this.ws.send(JSON.stringify({ type: 'CloseStream' }));
197
+ }
198
+ }
199
+ /**
200
+ * Immediately terminate the session without waiting for a final result.
201
+ *
202
+ * Cancels any pending reconnect timer, marks the session as closed, and
203
+ * terminates the underlying WebSocket. After `close()` no further events
204
+ * are emitted.
205
+ */
206
+ close() {
207
+ this.closed = true;
208
+ if (this.reconnectTimer !== null) {
209
+ clearTimeout(this.reconnectTimer);
210
+ this.reconnectTimer = null;
211
+ }
212
+ if (this.ws) {
213
+ this.ws.terminate();
214
+ this.ws = null;
215
+ }
216
+ this.wsReady = false;
217
+ this.emit('close');
218
+ }
219
+ // -------------------------------------------------------------------------
220
+ // Internal — WebSocket lifecycle
221
+ // -------------------------------------------------------------------------
222
+ /**
223
+ * Open (or reopen) the Deepgram WebSocket connection.
224
+ *
225
+ * Attaches `open`, `message`, `error`, and `close` handlers. On successful
226
+ * open the reconnect buffer is drained in order.
227
+ */
228
+ connect() {
229
+ if (this.closed)
230
+ return;
231
+ const url = buildWsUrl(this.cfg);
232
+ const socket = new WebSocket(url, {
233
+ headers: {
234
+ Authorization: `Token ${this.cfg.apiKey}`,
235
+ },
236
+ });
237
+ this.ws = socket;
238
+ socket.on('open', () => {
239
+ this.wsReady = true;
240
+ this.backoffMs = BACKOFF_INITIAL_MS; // reset on successful connect
241
+ // Drain buffered frames accumulated during the reconnect window.
242
+ const buffered = this.reconnectBuffer.splice(0);
243
+ for (const frame of buffered) {
244
+ const pcm = float32ToInt16Buffer(frame.samples);
245
+ socket.send(pcm);
246
+ }
247
+ });
248
+ socket.on('message', (data) => {
249
+ try {
250
+ const msg = JSON.parse(data.toString());
251
+ this.handleMessage(msg);
252
+ }
253
+ catch {
254
+ // Ignore malformed frames — Deepgram occasionally sends keep-alive
255
+ // empty strings or non-JSON control bytes.
256
+ }
257
+ });
258
+ socket.on('error', (err) => {
259
+ this.emit('error', err);
260
+ });
261
+ socket.on('close', (code) => {
262
+ this.wsReady = false;
263
+ this.ws = null;
264
+ // Normal closure (1000 = Normal, 1001 = Going Away) or explicit close().
265
+ const isNormal = code === 1000 || code === 1001;
266
+ if (isNormal || this.closed) {
267
+ if (!this.closed) {
268
+ // Deepgram closed normally after a CloseStream — emit session close.
269
+ this.emit('close');
270
+ }
271
+ return;
272
+ }
273
+ // Unexpected drop — schedule reconnect with exponential back-off.
274
+ this.scheduleReconnect();
275
+ });
276
+ }
277
+ /**
278
+ * Schedule a reconnect attempt after the current {@link backoffMs} delay,
279
+ * then double the delay for the next attempt (capped at {@link BACKOFF_MAX_MS}).
280
+ */
281
+ scheduleReconnect() {
282
+ if (this.closed)
283
+ return;
284
+ const delay = this.backoffMs;
285
+ this.backoffMs = Math.min(this.backoffMs * 2, BACKOFF_MAX_MS);
286
+ this.reconnectTimer = setTimeout(() => {
287
+ this.reconnectTimer = null;
288
+ this.connect();
289
+ }, delay);
290
+ }
291
+ // -------------------------------------------------------------------------
292
+ // Internal — message parsing
293
+ // -------------------------------------------------------------------------
294
+ /**
295
+ * Process a parsed Deepgram WebSocket message and emit the appropriate events.
296
+ *
297
+ * Deepgram sends two primary result types:
298
+ * - `Results` — transcript hypotheses with `is_final` and `speech_final` flags.
299
+ * - `Metadata` — session-level metadata (ignored here).
300
+ *
301
+ * @param msg - Parsed Deepgram JSON message.
302
+ */
303
+ handleMessage(msg) {
304
+ if (msg.type !== 'Results')
305
+ return;
306
+ const alt = msg.channel?.alternatives?.[0];
307
+ if (!alt)
308
+ return;
309
+ const text = alt.transcript ?? '';
310
+ const confidence = alt.confidence ?? 0;
311
+ const rawWords = alt.words ?? [];
312
+ const words = rawWords.map(mapDeepgramWord);
313
+ // Determine majority speaker when diarization is enabled.
314
+ const majoritySpeaker = this.cfg.diarize
315
+ ? extractSpeakerFromWords(rawWords)
316
+ : undefined;
317
+ // Suppress empty interim frames — Deepgram emits these as silence padding.
318
+ if (text.trim() === '' && !msg.is_final)
319
+ return;
320
+ // Emit 'speech_start' on the first non-empty transcript in this utterance.
321
+ if (!this.speechStarted && text.trim() !== '') {
322
+ this.speechStarted = true;
323
+ this.emit('speech_start');
324
+ }
325
+ const event = {
326
+ text,
327
+ confidence,
328
+ words,
329
+ isFinal: msg.is_final ?? false,
330
+ durationMs: msg.duration !== undefined ? Math.round(msg.duration * 1000) : undefined,
331
+ };
332
+ // Attach majority speaker to the event as a convenience property.
333
+ if (majoritySpeaker) {
334
+ event.speaker = majoritySpeaker;
335
+ }
336
+ // Base interface event — always emitted for both interim and final results.
337
+ this.emit('transcript', event);
338
+ if (msg.is_final) {
339
+ this.emit('final_transcript', event);
340
+ // Reset speech-started tracker for the next utterance.
341
+ this.speechStarted = false;
342
+ if (msg.speech_final) {
343
+ this.emit('speech_end');
344
+ }
345
+ }
346
+ else {
347
+ this.emit('interim_transcript', event);
348
+ }
349
+ }
350
+ }
351
+ //# sourceMappingURL=DeepgramStreamSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeepgramStreamSession.js","sourceRoot":"","sources":["../src/DeepgramStreamSession.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAiC3F,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,gEAAgE;AAChE,MAAM,gBAAgB,GAAG,kCAAkC,CAAC;AAE5D,sFAAsF;AACtF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,wDAAwD;AACxD,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,wDAAwD;AACxD,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,SAAS,oBAAoB,CAAC,OAAqB;IACjD,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,kDAAkD;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,C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
+ /**
2
+ * @file DeepgramStreamingSTT.ts
3
+ * @description {@link IStreamingSTT} factory implementation backed by Deepgram.
4
+ *
5
+ * {@link DeepgramStreamingSTT} is a thin factory that creates
6
+ * {@link DeepgramStreamSession} instances on demand. It holds no persistent
7
+ * state other than the API key and a reference count used to implement
8
+ * {@link isStreaming}.
9
+ *
10
+ * @module streaming-stt-deepgram/DeepgramStreamingSTT
11
+ */
12
+ import { DeepgramStreamSession } from './DeepgramStreamSession.js';
13
+ /** Minimal re-export of the StreamingSTTConfig shape used by this adapter. */
14
+ export interface StreamingSTTConfig {
15
+ language?: string;
16
+ interimResults?: boolean;
17
+ punctuate?: boolean;
18
+ profanityFilter?: boolean;
19
+ providerOptions?: Record<string, unknown>;
20
+ }
21
+ /**
22
+ * {@link IStreamingSTT}-compatible factory for Deepgram streaming sessions.
23
+ *
24
+ * Instantiate once per agent and reuse for the lifetime of the voice pipeline.
25
+ * Each call to {@link startSession} opens an independent WebSocket connection
26
+ * to Deepgram so that multiple concurrent sessions are supported.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const stt = new DeepgramStreamingSTT(process.env.DEEPGRAM_API_KEY!);
31
+ * const session = await stt.startSession({ language: 'fr-FR' });
32
+ *
33
+ * session.on('final_transcript', (evt) => console.log(evt.text));
34
+ * microphone.on('frame', (f) => session.pushAudio(f));
35
+ * ```
36
+ */
37
+ export declare class DeepgramStreamingSTT {
38
+ private readonly apiKey;
39
+ /**
40
+ * Stable provider identifier used by the voice pipeline to select between
41
+ * registered STT implementations.
42
+ */
43
+ readonly providerId = "deepgram-streaming";
44
+ /** `true` while at least one session has been created and not yet closed. */
45
+ get isStreaming(): boolean;
46
+ /** Count of sessions opened but not yet closed. */
47
+ private _activeSessions;
48
+ /**
49
+ * @param apiKey - Deepgram API key. Passed through to every session.
50
+ */
51
+ constructor(apiKey: string);
52
+ /**
53
+ * Open a new streaming recognition session.
54
+ *
55
+ * Provider-specific options can be forwarded via `config.providerOptions`
56
+ * under the following keys:
57
+ * - `model` — Deepgram model name (default `'nova-2'`).
58
+ * - `diarize` — Enable speaker diarization (default `false`).
59
+ * - `keywords` — Custom keyword list (default `[]`).
60
+ * - `endpointing` — Native endpointing duration ms, or `false`.
61
+ *
62
+ * @param config - Generic session config merged with Deepgram defaults.
63
+ * @returns A ready-to-use {@link DeepgramStreamSession}.
64
+ */
65
+ startSession(config?: StreamingSTTConfig): Promise<DeepgramStreamSession>;
66
+ }
67
+ //# sourceMappingURL=DeepgramStreamingSTT.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeepgramStreamingSTT.d.ts","sourceRoot":"","sources":["../src/DeepgramStreamingSTT.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,oBAAoB;IAkBnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAjBnC;;;OAGG;IACH,QAAQ,CAAC,UAAU,wBAAwB;IAE3C,6EAA6E;IAC7E,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,mDAAmD;IACnD,OAAO,CAAC,eAAe,CAAK;IAE5B;;OAEG;gBAC0B,MAAM,EAAE,MAAM;IAE3C;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAuBhF"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @file DeepgramStreamingSTT.ts
3
+ * @description {@link IStreamingSTT} factory implementation backed by Deepgram.
4
+ *
5
+ * {@link DeepgramStreamingSTT} is a thin factory that creates
6
+ * {@link DeepgramStreamSession} instances on demand. It holds no persistent
7
+ * state other than the API key and a reference count used to implement
8
+ * {@link isStreaming}.
9
+ *
10
+ * @module streaming-stt-deepgram/DeepgramStreamingSTT
11
+ */
12
+ import { DeepgramStreamSession } from './DeepgramStreamSession.js';
13
+ /**
14
+ * {@link IStreamingSTT}-compatible factory for Deepgram streaming sessions.
15
+ *
16
+ * Instantiate once per agent and reuse for the lifetime of the voice pipeline.
17
+ * Each call to {@link startSession} opens an independent WebSocket connection
18
+ * to Deepgram so that multiple concurrent sessions are supported.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const stt = new DeepgramStreamingSTT(process.env.DEEPGRAM_API_KEY!);
23
+ * const session = await stt.startSession({ language: 'fr-FR' });
24
+ *
25
+ * session.on('final_transcript', (evt) => console.log(evt.text));
26
+ * microphone.on('frame', (f) => session.pushAudio(f));
27
+ * ```
28
+ */
29
+ export class DeepgramStreamingSTT {
30
+ apiKey;
31
+ /**
32
+ * Stable provider identifier used by the voice pipeline to select between
33
+ * registered STT implementations.
34
+ */
35
+ providerId = 'deepgram-streaming';
36
+ /** `true` while at least one session has been created and not yet closed. */
37
+ get isStreaming() {
38
+ return this._activeSessions > 0;
39
+ }
40
+ /** Count of sessions opened but not yet closed. */
41
+ _activeSessions = 0;
42
+ /**
43
+ * @param apiKey - Deepgram API key. Passed through to every session.
44
+ */
45
+ constructor(apiKey) {
46
+ this.apiKey = apiKey;
47
+ }
48
+ /**
49
+ * Open a new streaming recognition session.
50
+ *
51
+ * Provider-specific options can be forwarded via `config.providerOptions`
52
+ * under the following keys:
53
+ * - `model` — Deepgram model name (default `'nova-2'`).
54
+ * - `diarize` — Enable speaker diarization (default `false`).
55
+ * - `keywords` — Custom keyword list (default `[]`).
56
+ * - `endpointing` — Native endpointing duration ms, or `false`.
57
+ *
58
+ * @param config - Generic session config merged with Deepgram defaults.
59
+ * @returns A ready-to-use {@link DeepgramStreamSession}.
60
+ */
61
+ async startSession(config) {
62
+ const provOpts = (config?.providerOptions ?? {});
63
+ const sessionConfig = {
64
+ apiKey: this.apiKey,
65
+ language: config?.language ?? provOpts.language,
66
+ punctuate: config?.punctuate ?? provOpts.punctuate,
67
+ interimResults: config?.interimResults ?? provOpts.interimResults,
68
+ model: provOpts.model,
69
+ diarize: provOpts.diarize,
70
+ keywords: provOpts.keywords,
71
+ endpointing: provOpts.endpointing,
72
+ };
73
+ const session = new DeepgramStreamSession(sessionConfig);
74
+ this._activeSessions++;
75
+ session.once('close', () => {
76
+ this._activeSessions = Math.max(0, this._activeSessions - 1);
77
+ });
78
+ return session;
79
+ }
80
+ }
81
+ //# sourceMappingURL=DeepgramStreamingSTT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeepgramStreamingSTT.js","sourceRoot":"","sources":["../src/DeepgramStreamingSTT.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAYnE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,oBAAoB;IAkBF;IAjB7B;;;OAGG;IACM,UAAU,GAAG,oBAAoB,CAAC;IAE3C,6EAA6E;IAC7E,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,mDAAmD;IAC3C,eAAe,GAAG,CAAC,CAAC;IAE5B;;OAEG;IACH,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,YAAY,CAAC,MAA2B;QAC5C,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,eAAe,IAAI,EAAE,CAAqC,CAAC;QAErF,MAAM,aAAa,GAA4B;YAC7C,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,QAAQ,CAAC,QAAQ;YAC/C,SAAS,EAAE,MAAM,EAAE,SAAS,IAAI,QAAQ,CAAC,SAAS;YAClD,cAAc,EAAE,MAAM,EAAE,cAAc,IAAI,QAAQ,CAAC,cAAc;YACjE,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,WAAW,EAAE,QAAQ,CAAC,WAAW;SAClC,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,aAAa,CAAC,CAAC;QAEzD,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;YACzB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Pack factory for the Deepgram Streaming STT extension pack.
4
+ *
5
+ * This module exports the main {@link createDeepgramStreamingSTT} factory
6
+ * function and the {@link createExtensionPack} bridge function that conforms
7
+ * to the AgentOS manifest factory convention.
8
+ *
9
+ * ### Usage (direct)
10
+ * ```ts
11
+ * import { createDeepgramStreamingSTT } from '@framers/agentos-ext-streaming-stt-deepgram';
12
+ *
13
+ * const stt = createDeepgramStreamingSTT(process.env.DEEPGRAM_API_KEY!);
14
+ * const session = await stt.startSession({ language: 'en-US' });
15
+ * ```
16
+ *
17
+ * ### Usage (manifest-driven)
18
+ * ```json
19
+ * { "packs": [{ "module": "@framers/agentos-ext-streaming-stt-deepgram" }] }
20
+ * ```
21
+ *
22
+ * @module streaming-stt-deepgram
23
+ */
24
+ import { DeepgramStreamingSTT } from './DeepgramStreamingSTT.js';
25
+ /** Subset of ExtensionDescriptor required by this pack. */
26
+ interface ExtensionDescriptor {
27
+ id: string;
28
+ kind: string;
29
+ payload: unknown;
30
+ enableByDefault?: boolean;
31
+ metadata?: Record<string, unknown>;
32
+ }
33
+ /** Subset of ExtensionPack required by this pack. */
34
+ interface ExtensionPack {
35
+ id: string;
36
+ descriptors: ExtensionDescriptor[];
37
+ }
38
+ /** Subset of ExtensionPackContext required by this pack. */
39
+ interface ExtensionPackContext {
40
+ getSecret?: (id: string) => string | undefined;
41
+ options?: Record<string, unknown>;
42
+ }
43
+ /**
44
+ * Create a standalone {@link DeepgramStreamingSTT} instance.
45
+ *
46
+ * Use this when composing the provider programmatically outside of the
47
+ * AgentOS extension system.
48
+ *
49
+ * @param apiKey - Deepgram API key.
50
+ * @returns Configured {@link DeepgramStreamingSTT}.
51
+ */
52
+ export declare function createDeepgramStreamingSTT(apiKey: string): DeepgramStreamingSTT;
53
+ /**
54
+ * AgentOS manifest factory function.
55
+ *
56
+ * Reads the `DEEPGRAM_API_KEY` secret from the context and returns an
57
+ * {@link ExtensionPack} containing a single `streaming-stt-provider`
58
+ * descriptor backed by {@link DeepgramStreamingSTT}.
59
+ *
60
+ * @param context - Pack context supplied by the extension manager.
61
+ * @returns A fully configured {@link ExtensionPack}.
62
+ */
63
+ export declare function createExtensionPack(context: ExtensionPackContext): ExtensionPack;
64
+ export * from './types.js';
65
+ export { DeepgramStreamingSTT } from './DeepgramStreamingSTT.js';
66
+ export { DeepgramStreamSession } from './DeepgramStreamSession.js';
67
+ export { extractSpeakerFromWords, mapDeepgramWord, } from './DeepgramDiarizationAdapter.js';
68
+ export type { DeepgramWord } from './DeepgramDiarizationAdapter.js';
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAOjE,2DAA2D;AAC3D,UAAU,mBAAmB;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,qDAAqD;AACrD,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAED,4DAA4D;AAC5D,UAAU,oBAAoB;IAC5B,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AASD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAE/E;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAgBhF;AAMD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACL,uBAAuB,EACvB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @file index.ts
3
+ * @description Pack factory for the Deepgram Streaming STT extension pack.
4
+ *
5
+ * This module exports the main {@link createDeepgramStreamingSTT} factory
6
+ * function and the {@link createExtensionPack} bridge function that conforms
7
+ * to the AgentOS manifest factory convention.
8
+ *
9
+ * ### Usage (direct)
10
+ * ```ts
11
+ * import { createDeepgramStreamingSTT } from '@framers/agentos-ext-streaming-stt-deepgram';
12
+ *
13
+ * const stt = createDeepgramStreamingSTT(process.env.DEEPGRAM_API_KEY!);
14
+ * const session = await stt.startSession({ language: 'en-US' });
15
+ * ```
16
+ *
17
+ * ### Usage (manifest-driven)
18
+ * ```json
19
+ * { "packs": [{ "module": "@framers/agentos-ext-streaming-stt-deepgram" }] }
20
+ * ```
21
+ *
22
+ * @module streaming-stt-deepgram
23
+ */
24
+ import { DeepgramStreamingSTT } from './DeepgramStreamingSTT.js';
25
+ /** Kind constant matching packages/agentos/src/extensions/types.ts line ~410. */
26
+ const EXTENSION_KIND_STREAMING_STT = 'streaming-stt-provider';
27
+ // ---------------------------------------------------------------------------
28
+ // Factory
29
+ // ---------------------------------------------------------------------------
30
+ /**
31
+ * Create a standalone {@link DeepgramStreamingSTT} instance.
32
+ *
33
+ * Use this when composing the provider programmatically outside of the
34
+ * AgentOS extension system.
35
+ *
36
+ * @param apiKey - Deepgram API key.
37
+ * @returns Configured {@link DeepgramStreamingSTT}.
38
+ */
39
+ export function createDeepgramStreamingSTT(apiKey) {
40
+ return new DeepgramStreamingSTT(apiKey);
41
+ }
42
+ /**
43
+ * AgentOS manifest factory function.
44
+ *
45
+ * Reads the `DEEPGRAM_API_KEY` secret from the context and returns an
46
+ * {@link ExtensionPack} containing a single `streaming-stt-provider`
47
+ * descriptor backed by {@link DeepgramStreamingSTT}.
48
+ *
49
+ * @param context - Pack context supplied by the extension manager.
50
+ * @returns A fully configured {@link ExtensionPack}.
51
+ */
52
+ export function createExtensionPack(context) {
53
+ const apiKey = context.getSecret?.('DEEPGRAM_API_KEY') ?? '';
54
+ const stt = new DeepgramStreamingSTT(apiKey);
55
+ return {
56
+ id: 'streaming-stt-deepgram',
57
+ descriptors: [
58
+ {
59
+ id: 'deepgram-streaming-stt',
60
+ kind: EXTENSION_KIND_STREAMING_STT,
61
+ payload: stt,
62
+ enableByDefault: true,
63
+ metadata: { providerId: 'deepgram-streaming' },
64
+ },
65
+ ],
66
+ };
67
+ }
68
+ // ---------------------------------------------------------------------------
69
+ // Re-exports
70
+ // ---------------------------------------------------------------------------
71
+ export * from './types.js';
72
+ export { DeepgramStreamingSTT } from './DeepgramStreamingSTT.js';
73
+ export { DeepgramStreamSession } from './DeepgramStreamSession.js';
74
+ export { extractSpeakerFromWords, mapDeepgramWord, } from './DeepgramDiarizationAdapter.js';
75
+ //# sourceMappingURL=index.js.map