@mastra/voice-openai-realtime 0.10.2 → 0.10.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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/voice-openai-realtime@0.10.2-alpha.1 build /home/runner/work/mastra/mastra/voice/openai-realtime-api
2
+ > @mastra/voice-openai-realtime@0.10.3-alpha.0 build /home/runner/work/mastra/mastra/voice/openai-realtime-api
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 10108ms
9
+ TSC ⚡️ Build success in 9461ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/voice/openai-realtime-api/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/voice/openai-realtime-api/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 12169ms
16
+ DTS ⚡️ Build success in 11698ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 19.31 KB
21
- ESM ⚡️ Build success in 831ms
22
- CJS dist/index.cjs 19.37 KB
23
- CJS ⚡️ Build success in 832ms
20
+ CJS dist/index.cjs 19.43 KB
21
+ CJS ⚡️ Build success in 1264ms
22
+ ESM dist/index.js 19.38 KB
23
+ ESM ⚡️ Build success in 1264ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @mastra/voice-openai-realtime
2
2
 
3
+ ## 0.10.3
4
+
5
+ ### Patch Changes
6
+
7
+ - e724b23: Added support for Int16Array
8
+ - Updated dependencies [9dda1ac]
9
+ - Updated dependencies [c984582]
10
+ - Updated dependencies [7e801dd]
11
+ - Updated dependencies [a606c75]
12
+ - Updated dependencies [7aa70a4]
13
+ - Updated dependencies [764f86a]
14
+ - Updated dependencies [1760a1c]
15
+ - Updated dependencies [038e5ae]
16
+ - Updated dependencies [7dda16a]
17
+ - Updated dependencies [5ebfcdd]
18
+ - Updated dependencies [b2d0c91]
19
+ - Updated dependencies [4e809ad]
20
+ - Updated dependencies [57929df]
21
+ - Updated dependencies [b7852ed]
22
+ - Updated dependencies [6320a61]
23
+ - @mastra/core@0.10.9
24
+
25
+ ## 0.10.3-alpha.0
26
+
27
+ ### Patch Changes
28
+
29
+ - e724b23: Added support for Int16Array
30
+ - Updated dependencies [9dda1ac]
31
+ - Updated dependencies [c984582]
32
+ - Updated dependencies [7e801dd]
33
+ - Updated dependencies [a606c75]
34
+ - Updated dependencies [7aa70a4]
35
+ - Updated dependencies [764f86a]
36
+ - Updated dependencies [1760a1c]
37
+ - Updated dependencies [038e5ae]
38
+ - Updated dependencies [7dda16a]
39
+ - Updated dependencies [5ebfcdd]
40
+ - Updated dependencies [b2d0c91]
41
+ - Updated dependencies [4e809ad]
42
+ - Updated dependencies [57929df]
43
+ - Updated dependencies [b7852ed]
44
+ - Updated dependencies [6320a61]
45
+ - @mastra/core@0.10.9-alpha.0
46
+
3
47
  ## 0.10.2
4
48
 
5
49
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -381,7 +381,8 @@ var OpenAIRealtimeVoice = class extends voice.MastraVoice {
381
381
  });
382
382
  } else if (audioData instanceof Int16Array) {
383
383
  try {
384
- this.sendEvent("input_audio_buffer.append", { audio: audioData, event_id: eventId });
384
+ const base64Audio = this.int16ArrayToBase64(audioData);
385
+ this.sendEvent("input_audio_buffer.append", { audio: base64Audio, event_id: eventId });
385
386
  } catch (err) {
386
387
  this.emit("error", err);
387
388
  }
package/dist/index.js CHANGED
@@ -379,7 +379,8 @@ var OpenAIRealtimeVoice = class extends MastraVoice {
379
379
  });
380
380
  } else if (audioData instanceof Int16Array) {
381
381
  try {
382
- this.sendEvent("input_audio_buffer.append", { audio: audioData, event_id: eventId });
382
+ const base64Audio = this.int16ArrayToBase64(audioData);
383
+ this.sendEvent("input_audio_buffer.append", { audio: base64Audio, event_id: eventId });
383
384
  } catch (err) {
384
385
  this.emit("error", err);
385
386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/voice-openai-realtime",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "Mastra OpenAI Realtime API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,13 +28,13 @@
28
28
  "@microsoft/api-extractor": "^7.52.8",
29
29
  "@types/node": "^20.19.0",
30
30
  "@types/ws": "^8.18.1",
31
- "eslint": "^9.28.0",
31
+ "eslint": "^9.29.0",
32
32
  "tsup": "^8.5.0",
33
33
  "typescript": "^5.8.3",
34
- "vitest": "^2.1.9",
35
- "zod": "^3.25.57",
36
- "@internal/lint": "0.0.13",
37
- "@mastra/core": "0.10.6"
34
+ "vitest": "^3.2.4",
35
+ "zod": "^3.25.67",
36
+ "@internal/lint": "0.0.16",
37
+ "@mastra/core": "0.10.9"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@mastra/core": "^0.10.0-alpha.0",
package/src/index.test.ts CHANGED
@@ -9,9 +9,6 @@ vi.mock('openai-realtime-api', () => {
9
9
  disconnect: vi.fn(),
10
10
  waitForSessionCreated: vi.fn().mockResolvedValue(undefined),
11
11
  updateSession: vi.fn(),
12
- realtime: {
13
- send: vi.fn(),
14
- },
15
12
  appendInputAudio: vi.fn(),
16
13
  on: vi.fn(),
17
14
  emit: vi.fn(),
@@ -19,26 +16,35 @@ vi.mock('openai-realtime-api', () => {
19
16
  };
20
17
  });
21
18
 
19
+ vi.mock('ws', () => {
20
+ return {
21
+ WebSocket: vi.fn().mockImplementation(() => ({
22
+ send: vi.fn(),
23
+ close: vi.fn(),
24
+ on: vi.fn(),
25
+ })),
26
+ };
27
+ });
28
+
22
29
  describe('OpenAIRealtimeVoice', () => {
23
30
  let voice: OpenAIRealtimeVoice;
24
- let mockClient: any; // TODO: Replace with proper type once we have better type definitions
25
31
 
26
32
  beforeEach(() => {
27
33
  vi.clearAllMocks();
28
34
  voice = new OpenAIRealtimeVoice({
29
35
  apiKey: 'test-api-key',
30
36
  });
31
- mockClient = (voice as any).client;
37
+ voice.waitForOpen = () => Promise.resolve();
38
+ voice.waitForSessionCreated = () => Promise.resolve();
32
39
  });
33
40
 
34
41
  afterEach(() => {
35
- voice?.leave();
42
+ voice?.disconnect();
36
43
  });
37
44
 
38
45
  describe('initialization', () => {
39
46
  it('should initialize with default values', () => {
40
47
  expect(voice).toBeInstanceOf(OpenAIRealtimeVoice);
41
- expect(mockClient).toBeDefined();
42
48
  });
43
49
 
44
50
  it('should initialize with custom speaker', () => {
@@ -58,31 +64,10 @@ describe('OpenAIRealtimeVoice', () => {
58
64
  });
59
65
  });
60
66
 
61
- describe('huddle and leave', () => {
62
- it('should connect and update state on huddle', async () => {
63
- await voice.huddle();
64
- expect(mockClient.connect).toHaveBeenCalled();
65
- expect(mockClient.waitForSessionCreated).toHaveBeenCalled();
66
- expect((voice as any).state).toBe('huddle');
67
- });
68
-
69
- it('should disconnect and update state on leave', () => {
70
- voice.leave();
71
- expect(mockClient.disconnect).toHaveBeenCalled();
72
- expect((voice as any).state).toBe('leave');
73
- });
74
- });
75
-
76
67
  describe('speak', () => {
77
68
  it('should handle string input', async () => {
78
69
  const testText = 'Hello, world!';
79
70
  await voice.speak(testText);
80
- expect(mockClient.realtime.send).toHaveBeenCalledWith('response.create', {
81
- response: {
82
- instructions: `Repeat the following text: ${testText}`,
83
- voice: undefined,
84
- },
85
- });
86
71
  });
87
72
 
88
73
  it('should throw error on empty input', async () => {
@@ -90,6 +75,15 @@ describe('OpenAIRealtimeVoice', () => {
90
75
  });
91
76
  });
92
77
 
78
+ describe('send', () => {
79
+ it('should handle Int16Array input', async () => {
80
+ const testArray = new Int16Array([1, 2, 3]);
81
+
82
+ await voice.connect();
83
+ voice.send(testArray);
84
+ });
85
+ });
86
+
93
87
  describe('event handling', () => {
94
88
  it('should register and trigger event listeners', () => {
95
89
  const mockCallback = vi.fn();
package/src/index.ts CHANGED
@@ -441,7 +441,8 @@ export class OpenAIRealtimeVoice extends MastraVoice {
441
441
  });
442
442
  } else if (audioData instanceof Int16Array) {
443
443
  try {
444
- this.sendEvent('input_audio_buffer.append', { audio: audioData, event_id: eventId });
444
+ const base64Audio = this.int16ArrayToBase64(audioData);
445
+ this.sendEvent('input_audio_buffer.append', { audio: base64Audio, event_id: eventId });
445
446
  } catch (err) {
446
447
  this.emit('error', err);
447
448
  }