@kuralle-syrinx/grok 4.4.1 → 4.5.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/dist/from-grok-realtime.d.ts +31 -0
- package/dist/from-grok-realtime.d.ts.map +1 -0
- package/dist/from-grok-realtime.js +88 -0
- package/dist/from-grok-realtime.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/stt.d.ts +17 -0
- package/dist/stt.d.ts.map +1 -0
- package/dist/stt.js +179 -0
- package/dist/stt.js.map +1 -0
- package/dist/tts.d.ts +10 -0
- package/dist/tts.d.ts.map +1 -0
- package/dist/tts.js +178 -0
- package/dist/tts.js.map +1 -0
- package/package.json +32 -13
- package/src/edge-safety.test.ts +146 -0
- package/src/from-grok-realtime.test.ts +317 -0
- package/src/stt.test.ts +418 -0
- package/src/tts.test.ts +320 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
//
|
|
3
|
+
// Regression gate — the grok package must run on workerd without Buffer, process,
|
|
4
|
+
// or node:* imports. Reintroducing any Node-only primitive in src/ should fail.
|
|
5
|
+
|
|
6
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
|
|
12
|
+
import type { ManagedSocket, SocketData, SocketFactory } from "@kuralle-syrinx/ws";
|
|
13
|
+
|
|
14
|
+
import { bytesToBase64, fromGrokRealtime } from "./from-grok-realtime.js";
|
|
15
|
+
import type { RealtimeEvent } from "@kuralle-syrinx/realtime";
|
|
16
|
+
|
|
17
|
+
const srcDir = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
|
|
19
|
+
interface EdgeMockHarness {
|
|
20
|
+
readonly factory: SocketFactory;
|
|
21
|
+
readonly sent: string[];
|
|
22
|
+
inject(msg: Record<string, unknown>): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createEdgeMockHarness(): EdgeMockHarness {
|
|
26
|
+
const sent: string[] = [];
|
|
27
|
+
let messageHandler: ((data: SocketData, isBinary: boolean) => void) | null = null;
|
|
28
|
+
|
|
29
|
+
const socket: ManagedSocket = {
|
|
30
|
+
get isOpen() {
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
send: (data: SocketData) => {
|
|
34
|
+
sent.push(typeof data === "string" ? data : "");
|
|
35
|
+
},
|
|
36
|
+
keepAlivePing: () => {},
|
|
37
|
+
verify: async () => true,
|
|
38
|
+
dispose: () => {},
|
|
39
|
+
onOpen: (handler) => {
|
|
40
|
+
queueMicrotask(() => handler());
|
|
41
|
+
},
|
|
42
|
+
onMessage: (handler) => {
|
|
43
|
+
messageHandler = handler;
|
|
44
|
+
},
|
|
45
|
+
onClose: () => {},
|
|
46
|
+
onError: () => {},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
factory: () => socket,
|
|
51
|
+
sent,
|
|
52
|
+
inject: (msg) => messageHandler?.(JSON.stringify(msg), false),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function collectSourceFiles(dir: string): string[] {
|
|
57
|
+
const out: string[] = [];
|
|
58
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
59
|
+
const full = path.join(dir, entry.name);
|
|
60
|
+
if (entry.isDirectory()) {
|
|
61
|
+
out.push(...collectSourceFiles(full));
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (entry.name.endsWith(".ts") && !entry.name.endsWith(".test.ts")) {
|
|
65
|
+
out.push(full);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function collectEvents(
|
|
72
|
+
events: AsyncIterable<RealtimeEvent>,
|
|
73
|
+
max = 2,
|
|
74
|
+
): Promise<RealtimeEvent[]> {
|
|
75
|
+
const out: RealtimeEvent[] = [];
|
|
76
|
+
for await (const event of events) {
|
|
77
|
+
out.push(event);
|
|
78
|
+
if (out.length >= max) break;
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function waitFor(predicate: () => boolean, timeoutMs = 2000): Promise<void> {
|
|
84
|
+
const startedAt = Date.now();
|
|
85
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
86
|
+
if (predicate()) return;
|
|
87
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
88
|
+
}
|
|
89
|
+
throw new Error("Timed out waiting for condition");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
describe("edge safety (grok)", () => {
|
|
93
|
+
it("src/ contains no Buffer, process, or node:* imports", () => {
|
|
94
|
+
const forbidden = [
|
|
95
|
+
/\bfrom\s+["']node:/,
|
|
96
|
+
/\brequire\s*\(\s*["']node:/,
|
|
97
|
+
/\bglobalThis\.Buffer\b/,
|
|
98
|
+
/\bglobalThis\.process\b/,
|
|
99
|
+
/\bprocess\.env\b/,
|
|
100
|
+
/\bBuffer\.from\b/,
|
|
101
|
+
/\bBuffer\.alloc\b/,
|
|
102
|
+
];
|
|
103
|
+
const hits: string[] = [];
|
|
104
|
+
for (const file of collectSourceFiles(srcDir)) {
|
|
105
|
+
const text = readFileSync(file, "utf8");
|
|
106
|
+
for (const pattern of forbidden) {
|
|
107
|
+
if (pattern.test(text)) {
|
|
108
|
+
hits.push(`${path.relative(srcDir, file)}: ${pattern.source}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
expect(hits).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("fromGrokRealtime round-trips audio via runtime-agnostic helpers", async () => {
|
|
116
|
+
const mock = createEdgeMockHarness();
|
|
117
|
+
const adapter = fromGrokRealtime({
|
|
118
|
+
apiKey: "edge-test-key",
|
|
119
|
+
socketFactory: mock.factory,
|
|
120
|
+
url: () => "wss://example.test/realtime?model=grok-voice-latest",
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const eventsTask = collectEvents(adapter.events, 2);
|
|
124
|
+
const openTask = adapter.open(new AbortController().signal);
|
|
125
|
+
await waitFor(() => mock.sent.length > 0);
|
|
126
|
+
mock.inject({ type: "session.updated" });
|
|
127
|
+
await openTask;
|
|
128
|
+
|
|
129
|
+
const providerPcm = new Uint8Array([100, 200, 300, 400]);
|
|
130
|
+
mock.inject({ type: "response.created" });
|
|
131
|
+
mock.inject({
|
|
132
|
+
type: "response.output_audio.delta",
|
|
133
|
+
delta: bytesToBase64(providerPcm),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const events = await eventsTask;
|
|
137
|
+
expect(events[0]).toEqual({ type: "response_started" });
|
|
138
|
+
expect(events[1]).toEqual({
|
|
139
|
+
type: "audio",
|
|
140
|
+
pcm16: providerPcm,
|
|
141
|
+
sampleRateHz: 24_000,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await adapter.close();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import type { ManagedSocket, SocketData, SocketFactory } from "@kuralle-syrinx/ws";
|
|
6
|
+
|
|
7
|
+
import type { RealtimeEvent } from "@kuralle-syrinx/realtime";
|
|
8
|
+
|
|
9
|
+
import { bytesToBase64, fromGrokRealtime } from "./from-grok-realtime.js";
|
|
10
|
+
|
|
11
|
+
interface MockSocketHarness {
|
|
12
|
+
readonly factory: SocketFactory;
|
|
13
|
+
readonly sent: string[];
|
|
14
|
+
inject(msg: Record<string, unknown>): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function createMockSocketHarness(): MockSocketHarness {
|
|
18
|
+
const sent: string[] = [];
|
|
19
|
+
let messageHandler: ((data: SocketData, isBinary: boolean) => void) | null = null;
|
|
20
|
+
|
|
21
|
+
const socket: ManagedSocket = {
|
|
22
|
+
get isOpen() {
|
|
23
|
+
return true;
|
|
24
|
+
},
|
|
25
|
+
send: (data: SocketData) => {
|
|
26
|
+
sent.push(typeof data === "string" ? data : "");
|
|
27
|
+
},
|
|
28
|
+
keepAlivePing: () => {},
|
|
29
|
+
verify: async () => true,
|
|
30
|
+
dispose: () => {},
|
|
31
|
+
onOpen: (handler) => {
|
|
32
|
+
queueMicrotask(() => handler());
|
|
33
|
+
},
|
|
34
|
+
onMessage: (handler) => {
|
|
35
|
+
messageHandler = handler;
|
|
36
|
+
},
|
|
37
|
+
onClose: () => {},
|
|
38
|
+
onError: () => {},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
factory: () => socket,
|
|
43
|
+
sent,
|
|
44
|
+
inject: (msg) => messageHandler?.(JSON.stringify(msg), false),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function collectEvents(
|
|
49
|
+
events: AsyncIterable<RealtimeEvent>,
|
|
50
|
+
max = 8,
|
|
51
|
+
): Promise<RealtimeEvent[]> {
|
|
52
|
+
const out: RealtimeEvent[] = [];
|
|
53
|
+
for await (const event of events) {
|
|
54
|
+
out.push(event);
|
|
55
|
+
if (out.length >= max) break;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function waitFor(predicate: () => boolean, timeoutMs = 2000): Promise<void> {
|
|
61
|
+
const startedAt = Date.now();
|
|
62
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
63
|
+
if (predicate()) return;
|
|
64
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
65
|
+
}
|
|
66
|
+
throw new Error("Timed out waiting for condition");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe("fromGrokRealtime", () => {
|
|
70
|
+
it("sends Grok session.update and client control messages", async () => {
|
|
71
|
+
const mock = createMockSocketHarness();
|
|
72
|
+
const adapter = fromGrokRealtime({
|
|
73
|
+
apiKey: "test-key",
|
|
74
|
+
socketFactory: mock.factory,
|
|
75
|
+
url: () => "wss://example.test/realtime?model=grok-voice-latest",
|
|
76
|
+
voice: "eve",
|
|
77
|
+
instructions: "Be concise.",
|
|
78
|
+
turnDetection: { type: "server_vad" },
|
|
79
|
+
tools: [
|
|
80
|
+
{
|
|
81
|
+
name: "lookup",
|
|
82
|
+
description: "Look up facts.",
|
|
83
|
+
parameters: { type: "object", properties: { q: { type: "string" } }, required: ["q"] },
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const openTask = adapter.open(new AbortController().signal);
|
|
89
|
+
await waitFor(() => mock.sent.length > 0);
|
|
90
|
+
mock.inject({ type: "session.updated" });
|
|
91
|
+
await openTask;
|
|
92
|
+
|
|
93
|
+
expect(JSON.parse(mock.sent[0]!)).toEqual({
|
|
94
|
+
type: "session.update",
|
|
95
|
+
session: {
|
|
96
|
+
voice: "eve",
|
|
97
|
+
instructions: "Be concise.",
|
|
98
|
+
turn_detection: { type: "server_vad" },
|
|
99
|
+
tools: [
|
|
100
|
+
{
|
|
101
|
+
type: "function",
|
|
102
|
+
name: "lookup",
|
|
103
|
+
description: "Look up facts.",
|
|
104
|
+
parameters: { type: "object", properties: { q: { type: "string" } }, required: ["q"] },
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
audio: {
|
|
108
|
+
input: { format: { type: "audio/pcm", rate: 24000 } },
|
|
109
|
+
output: { format: { type: "audio/pcm", rate: 24000 }, voice: "eve" },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const pcm = new Uint8Array([0, 1, 2, 3]);
|
|
115
|
+
adapter.sendAudio(pcm);
|
|
116
|
+
expect(JSON.parse(mock.sent[1]!)).toEqual({
|
|
117
|
+
type: "input_audio_buffer.append",
|
|
118
|
+
audio: bytesToBase64(pcm),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
mock.inject({ type: "response.created" });
|
|
122
|
+
adapter.cancelResponse(420);
|
|
123
|
+
expect(JSON.parse(mock.sent[2]!)).toEqual({ type: "response.cancel" });
|
|
124
|
+
expect(
|
|
125
|
+
mock.sent
|
|
126
|
+
.map((raw) => JSON.parse(raw) as Record<string, unknown>)
|
|
127
|
+
.some((msg) => msg["type"] === "conversation.item.truncate"),
|
|
128
|
+
).toBe(false);
|
|
129
|
+
|
|
130
|
+
adapter.injectToolResult("call_abc", "result text");
|
|
131
|
+
expect(JSON.parse(mock.sent[3]!)).toEqual({
|
|
132
|
+
type: "conversation.item.create",
|
|
133
|
+
item: {
|
|
134
|
+
type: "function_call_output",
|
|
135
|
+
call_id: "call_abc",
|
|
136
|
+
output: "result text",
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
expect(mock.sent).toHaveLength(4);
|
|
140
|
+
|
|
141
|
+
mock.inject({ type: "response.done", response: {} });
|
|
142
|
+
expect(JSON.parse(mock.sent[4]!)).toEqual({ type: "response.create" });
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("normalizes provider server events into RealtimeEvent", async () => {
|
|
146
|
+
const mock = createMockSocketHarness();
|
|
147
|
+
const adapter = fromGrokRealtime({
|
|
148
|
+
apiKey: "test-key",
|
|
149
|
+
socketFactory: mock.factory,
|
|
150
|
+
url: () => "wss://example.test/realtime?model=grok-voice-latest",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const eventsTask = collectEvents(adapter.events, 7);
|
|
154
|
+
const openTask = adapter.open(new AbortController().signal);
|
|
155
|
+
await waitFor(() => mock.sent.length > 0);
|
|
156
|
+
mock.inject({ type: "session.updated" });
|
|
157
|
+
await openTask;
|
|
158
|
+
|
|
159
|
+
const audioBytes = new Uint8Array([9, 10, 11, 12]);
|
|
160
|
+
mock.inject({ type: "response.created" });
|
|
161
|
+
mock.inject({ type: "response.output_audio.delta", delta: bytesToBase64(audioBytes) });
|
|
162
|
+
mock.inject({
|
|
163
|
+
type: "conversation.item.input_audio_transcription.updated",
|
|
164
|
+
transcript: "hello there",
|
|
165
|
+
});
|
|
166
|
+
mock.inject({ type: "response.output_audio_transcript.delta", delta: "Sure, " });
|
|
167
|
+
mock.inject({
|
|
168
|
+
type: "response.output_audio_transcript.done",
|
|
169
|
+
transcript: "Sure, I can help.",
|
|
170
|
+
});
|
|
171
|
+
mock.inject({
|
|
172
|
+
type: "response.done",
|
|
173
|
+
response: {
|
|
174
|
+
output: [
|
|
175
|
+
{
|
|
176
|
+
type: "function_call",
|
|
177
|
+
call_id: "call_123",
|
|
178
|
+
name: "lookup",
|
|
179
|
+
arguments: JSON.stringify({ q: "hours" }),
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const events = await eventsTask;
|
|
186
|
+
expect(events.slice(0, 6)).toEqual([
|
|
187
|
+
{ type: "response_started" },
|
|
188
|
+
{ type: "audio", pcm16: audioBytes, sampleRateHz: 24000 },
|
|
189
|
+
{ type: "transcript", role: "user", text: "hello there", final: true },
|
|
190
|
+
{ type: "transcript", role: "assistant", text: "Sure, ", final: false },
|
|
191
|
+
{ type: "transcript", role: "assistant", text: "Sure, I can help.", final: true },
|
|
192
|
+
{
|
|
193
|
+
type: "tool_call",
|
|
194
|
+
toolId: "call_123",
|
|
195
|
+
toolName: "lookup",
|
|
196
|
+
args: { q: "hours" },
|
|
197
|
+
},
|
|
198
|
+
]);
|
|
199
|
+
expect(events[6]).toEqual({ type: "response_done" });
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("B1: does not send response.create while response is active (cancel-in-flight, no truncate)", async () => {
|
|
203
|
+
const mock = createMockSocketHarness();
|
|
204
|
+
const adapter = fromGrokRealtime({
|
|
205
|
+
apiKey: "test-key",
|
|
206
|
+
socketFactory: mock.factory,
|
|
207
|
+
url: () => "wss://example.test/realtime?model=grok-voice-latest",
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const openTask = adapter.open(new AbortController().signal);
|
|
211
|
+
await waitFor(() => mock.sent.length > 0);
|
|
212
|
+
mock.inject({ type: "session.updated" });
|
|
213
|
+
await openTask;
|
|
214
|
+
|
|
215
|
+
mock.inject({ type: "response.created" });
|
|
216
|
+
adapter.cancelResponse(420);
|
|
217
|
+
expect(JSON.parse(mock.sent[1]!)).toEqual({ type: "response.cancel" });
|
|
218
|
+
expect(
|
|
219
|
+
mock.sent
|
|
220
|
+
.map((raw) => JSON.parse(raw) as Record<string, unknown>)
|
|
221
|
+
.some((msg) => msg["type"] === "conversation.item.truncate"),
|
|
222
|
+
).toBe(false);
|
|
223
|
+
|
|
224
|
+
adapter.injectToolResult("call_abc", "result text");
|
|
225
|
+
const typesAfterInject = mock.sent.map(
|
|
226
|
+
(raw) => (JSON.parse(raw) as Record<string, unknown>)["type"],
|
|
227
|
+
);
|
|
228
|
+
expect(typesAfterInject).toContain("conversation.item.create");
|
|
229
|
+
expect(typesAfterInject).not.toContain("response.create");
|
|
230
|
+
|
|
231
|
+
mock.inject({ type: "response.done", response: {} });
|
|
232
|
+
expect(JSON.parse(mock.sent[mock.sent.length - 1]!)).toEqual({ type: "response.create" });
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("B1: does not send response.create while response is active (direct inject without cancel)", async () => {
|
|
236
|
+
const mock = createMockSocketHarness();
|
|
237
|
+
const adapter = fromGrokRealtime({
|
|
238
|
+
apiKey: "test-key",
|
|
239
|
+
socketFactory: mock.factory,
|
|
240
|
+
url: () => "wss://example.test/realtime?model=grok-voice-latest",
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const openTask = adapter.open(new AbortController().signal);
|
|
244
|
+
await waitFor(() => mock.sent.length > 0);
|
|
245
|
+
mock.inject({ type: "session.updated" });
|
|
246
|
+
await openTask;
|
|
247
|
+
|
|
248
|
+
mock.inject({ type: "response.created" });
|
|
249
|
+
|
|
250
|
+
adapter.injectToolResult("call_xyz", "inline result");
|
|
251
|
+
const typesAfterInject = mock.sent.map(
|
|
252
|
+
(raw) => (JSON.parse(raw) as Record<string, unknown>)["type"],
|
|
253
|
+
);
|
|
254
|
+
expect(typesAfterInject).toContain("conversation.item.create");
|
|
255
|
+
expect(typesAfterInject).not.toContain("response.create");
|
|
256
|
+
|
|
257
|
+
mock.inject({ type: "response.done", response: {} });
|
|
258
|
+
expect(
|
|
259
|
+
mock.sent.map((raw) => (JSON.parse(raw) as Record<string, unknown>)["type"]),
|
|
260
|
+
).toContain("response.create");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("exposes Grok capability flags", () => {
|
|
264
|
+
const mock = createMockSocketHarness();
|
|
265
|
+
const adapter = fromGrokRealtime({
|
|
266
|
+
apiKey: "test-key",
|
|
267
|
+
socketFactory: mock.factory,
|
|
268
|
+
inputRateHz: 16000,
|
|
269
|
+
outputRateHz: 16000,
|
|
270
|
+
});
|
|
271
|
+
expect(adapter.caps).toEqual({
|
|
272
|
+
inputSampleRateHz: 16000,
|
|
273
|
+
outputSampleRateHz: 16000,
|
|
274
|
+
supportsConcurrentToolAudio: false,
|
|
275
|
+
supportsTruncate: false,
|
|
276
|
+
emitsServerSpeechStarted: false,
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("cfg-flex: formats, transcription, temperature, modalities, toolChoice, sessionConfig reach session.update", async () => {
|
|
281
|
+
const mock = createMockSocketHarness();
|
|
282
|
+
const adapter = fromGrokRealtime({
|
|
283
|
+
apiKey: "test-key",
|
|
284
|
+
socketFactory: mock.factory,
|
|
285
|
+
url: () => "wss://example.test/realtime?model=grok-voice-latest",
|
|
286
|
+
inputAudioFormat: { type: "audio/pcmu", rate: 8000 },
|
|
287
|
+
outputAudioFormat: { type: "audio/pcmu", rate: 8000 },
|
|
288
|
+
inputTranscription: { model: "grok-asr" },
|
|
289
|
+
temperature: 0.55,
|
|
290
|
+
modalities: ["audio", "text"],
|
|
291
|
+
toolChoice: "required",
|
|
292
|
+
sessionConfig: { speed: 1.05, custom_field: "x" },
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const openTask = adapter.open(new AbortController().signal);
|
|
296
|
+
await waitFor(() => mock.sent.length > 0);
|
|
297
|
+
mock.inject({ type: "session.updated" });
|
|
298
|
+
await openTask;
|
|
299
|
+
|
|
300
|
+
const session = (JSON.parse(mock.sent[0]!) as { session: Record<string, unknown> }).session;
|
|
301
|
+
expect(session["temperature"]).toBe(0.55);
|
|
302
|
+
expect(session["output_modalities"]).toEqual(["audio", "text"]);
|
|
303
|
+
expect(session["tool_choice"]).toBe("required");
|
|
304
|
+
expect(session["speed"]).toBe(1.05);
|
|
305
|
+
expect(session["custom_field"]).toBe("x");
|
|
306
|
+
// Default turn detection preserved when not overridden.
|
|
307
|
+
expect(session["turn_detection"]).toEqual({ type: "server_vad" });
|
|
308
|
+
expect(session["voice"]).toBe("eve");
|
|
309
|
+
const audio = session["audio"] as {
|
|
310
|
+
input: Record<string, unknown>;
|
|
311
|
+
output: Record<string, unknown>;
|
|
312
|
+
};
|
|
313
|
+
expect(audio.input["format"]).toEqual({ type: "audio/pcmu", rate: 8000 });
|
|
314
|
+
expect(audio.input["transcription"]).toEqual({ model: "grok-asr" });
|
|
315
|
+
expect(audio.output["format"]).toEqual({ type: "audio/pcmu", rate: 8000 });
|
|
316
|
+
});
|
|
317
|
+
});
|