@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.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +44 -0
- package/dist/index.cjs +2 -1
- package/dist/index.js +2 -1
- package/package.json +6 -6
- package/src/index.test.ts +22 -28
- package/src/index.ts +2 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/voice-openai-realtime@0.10.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 9461ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/voice/openai-realtime-api/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/voice/openai-realtime-api/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 11698ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m19.43 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1264ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m19.38 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ 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.
|
|
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.
|
|
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.
|
|
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.
|
|
31
|
+
"eslint": "^9.29.0",
|
|
32
32
|
"tsup": "^8.5.0",
|
|
33
33
|
"typescript": "^5.8.3",
|
|
34
|
-
"vitest": "^2.
|
|
35
|
-
"zod": "^3.25.
|
|
36
|
-
"@internal/lint": "0.0.
|
|
37
|
-
"@mastra/core": "0.10.
|
|
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
|
-
|
|
37
|
+
voice.waitForOpen = () => Promise.resolve();
|
|
38
|
+
voice.waitForSessionCreated = () => Promise.resolve();
|
|
32
39
|
});
|
|
33
40
|
|
|
34
41
|
afterEach(() => {
|
|
35
|
-
voice?.
|
|
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.
|
|
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
|
}
|