@livekit/agents-plugin-deepgram 1.6.4 → 1.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livekit/agents-plugin-deepgram",
3
- "version": "1.6.4",
3
+ "version": "1.7.0",
4
4
  "description": "Deepgram plugin for LiveKit Agents for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "require": "dist/index.cjs",
@@ -28,22 +28,22 @@
28
28
  "README.md"
29
29
  ],
30
30
  "devDependencies": {
31
- "@livekit/rtc-node": "^0.13.33",
32
- "@microsoft/api-extractor": "^7.35.0",
31
+ "@livekit/rtc-node": "^0.13.34",
32
+ "@microsoft/api-extractor": "^7.58.12",
33
33
  "@types/ws": "^8.5.10",
34
34
  "tsup": "^8.3.5",
35
35
  "typescript": "^5.0.0",
36
- "@livekit/agents": "1.6.4",
37
- "@livekit/agents-plugin-openai": "^1.6.4",
38
- "@livekit/agents-plugin-silero": "1.6.4",
39
- "@livekit/agents-plugins-test": "1.6.4"
36
+ "@livekit/agents": "1.7.0",
37
+ "@livekit/agents-plugin-openai": "^1.7.0",
38
+ "@livekit/agents-plugin-silero": "1.7.0",
39
+ "@livekit/agents-plugins-test": "1.7.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "ws": "^8.21.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@livekit/rtc-node": "^0.13.33",
46
- "@livekit/agents": "1.6.4"
45
+ "@livekit/rtc-node": "^0.13.34",
46
+ "@livekit/agents": "1.7.0"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsup --onSuccess \"pnpm build:types\"",
package/src/stt.ts CHANGED
@@ -551,7 +551,9 @@ export class SpeechStream extends stt.SpeechStream {
551
551
  break;
552
552
  }
553
553
  default: {
554
- this.#logger.child({ msg: json }).warn('received unexpected message from Deepgram');
554
+ this.#logger
555
+ .child({ 'lk.pii.message': json })
556
+ .warn('received unexpected message from Deepgram');
555
557
  break;
556
558
  }
557
559
  }
@@ -560,7 +562,10 @@ export class SpeechStream extends stt.SpeechStream {
560
562
  resolve();
561
563
  }
562
564
  } catch (err) {
563
- this.#logger.error(`STT: Error processing message: ${msg}`);
565
+ this.#logger.error(
566
+ { error: err, 'lk.pii.message': msg.toString() },
567
+ 'Deepgram STT failed to process message',
568
+ );
564
569
  reject(err);
565
570
  }
566
571
  });
@@ -0,0 +1,78 @@
1
+ // SPDX-FileCopyrightText: 2026 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { log } from '@livekit/agents';
5
+ import { once } from 'node:events';
6
+ import { afterEach, describe, expect, it, vi } from 'vitest';
7
+ import { type WebSocket, WebSocketServer } from 'ws';
8
+ import { STT } from './stt.js';
9
+ import { STTv2 } from './stt_v2.js';
10
+
11
+ const servers: WebSocketServer[] = [];
12
+ const streams: Array<{ close(): void }> = [];
13
+
14
+ async function startServer(onConnection?: (socket: WebSocket) => void): Promise<string> {
15
+ const server = new WebSocketServer({ host: '127.0.0.1', port: 0 });
16
+ servers.push(server);
17
+ await once(server, 'listening');
18
+ if (onConnection) server.on('connection', onConnection);
19
+
20
+ const address = server.address();
21
+ if (address === null || typeof address === 'string') {
22
+ throw new Error('expected a TCP address');
23
+ }
24
+ return `ws://127.0.0.1:${address.port}`;
25
+ }
26
+
27
+ afterEach(async () => {
28
+ for (const stream of streams.splice(0)) stream.close();
29
+ await Promise.all(
30
+ servers.splice(0).map(async (server) => {
31
+ for (const client of server.clients) client.terminate();
32
+ await new Promise<void>((resolve) => server.close(() => resolve()));
33
+ }),
34
+ );
35
+ vi.restoreAllMocks();
36
+ });
37
+
38
+ describe('Deepgram STT logging', () => {
39
+ it('logs invalid messages as text with the parse error', async () => {
40
+ const errorSpy = vi.spyOn(log(), 'error');
41
+ const baseUrl = await startServer((socket) => {
42
+ setTimeout(() => socket.send('not-json'), 10);
43
+ });
44
+ const recognizer = new STT({ apiKey: 'test', baseUrl });
45
+ const stream = recognizer.stream();
46
+ streams.push(stream);
47
+
48
+ await vi.waitFor(() => {
49
+ expect(errorSpy).toHaveBeenCalledWith(
50
+ {
51
+ error: expect.any(SyntaxError),
52
+ 'lk.pii.message': 'not-json',
53
+ },
54
+ 'Deepgram STT failed to process message',
55
+ );
56
+ });
57
+ });
58
+
59
+ it('does not log the v2 connection URL', async () => {
60
+ const debugSpy = vi.spyOn(log(), 'debug');
61
+ const baseUrl = await startServer();
62
+ const recognizer = new STTv2({
63
+ apiKey: 'test',
64
+ endpointUrl: `${baseUrl}/v2/listen`,
65
+ keyterms: ['private-keyterm'],
66
+ });
67
+ const stream = recognizer.stream();
68
+ streams.push(stream);
69
+
70
+ await vi.waitFor(() => {
71
+ const connectionCalls = debugSpy.mock.calls.filter((call) =>
72
+ call.includes('connecting to Deepgram'),
73
+ );
74
+ expect(connectionCalls).toEqual([['connecting to Deepgram']]);
75
+ expect(JSON.stringify(connectionCalls)).not.toContain('private-keyterm');
76
+ });
77
+ });
78
+ });
package/src/stt_v2.ts CHANGED
@@ -314,7 +314,7 @@ class SpeechStreamv2 extends stt.SpeechStream {
314
314
  this.#reconnectEvent.clear();
315
315
 
316
316
  const url = this.#getDeepgramUrl();
317
- this.#logger.debug(`Connecting to Deepgram: ${url}`);
317
+ this.#logger.debug('connecting to Deepgram');
318
318
 
319
319
  this.#ws = new WebSocket(url, {
320
320
  headers: { Authorization: `Token ${this.#opts.apiKey}` },
@@ -506,7 +506,7 @@ class SpeechStreamv2 extends stt.SpeechStream {
506
506
  this.#onEndOfSpeech();
507
507
  }
508
508
  } else if (data.type === 'Error') {
509
- this.#logger.warn('deepgram sent an error', { data });
509
+ this.#logger.warn({ 'lk.pii.data': data }, 'deepgram sent an error');
510
510
  const desc = (data.description as string) || 'unknown error from deepgram';
511
511
  throw new Error(`Deepgram API Error: ${desc}`);
512
512
  }
package/src/tts.ts CHANGED
@@ -422,7 +422,7 @@ export class SynthesizeStream extends tts.SynthesizeStream {
422
422
  reject(new APIError('Deepgram TTS returned error', { body: message }));
423
423
  return;
424
424
  } else if (message.type !== 'Metadata') {
425
- this.#logger.warn({ message }, 'Unknown Deepgram message type');
425
+ this.#logger.warn({ 'lk.pii.message': message }, 'Unknown Deepgram message type');
426
426
  }
427
427
 
428
428
  resetMessageTimeout(reject);