@cartanova/qgrid-cli 2.19.0 → 2.19.2
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/bundle/dist/application/qgrid/qgrid-response-format.js +14 -5
- package/bundle/dist/application/qgrid/qgrid-run-lifecycle.js +12 -4
- package/bundle/dist/application/qgrid/qgrid.dispatcher.js +3 -1
- package/bundle/dist/application/qgrid/qgrid.frame.js +215 -6
- package/bundle/dist/application/qgrid/qgrid.types.js +65 -2
- package/bundle/dist/application/request-log/request-log.model.js +11 -1
- package/bundle/dist/application/sonamu.generated.js +5 -3
- package/bundle/dist/i18n/sd.generated.js +3 -2
- package/bundle/dist/utils/providers/common/model-cost.js +8 -2
- package/bundle/dist/utils/providers/openai/openai-dispatcher.js +18 -1
- package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +112 -2
- package/bundle/dist/utils/providers/openai/openai-voice-client.js +183 -6
- package/bundle/src/application/qgrid/qgrid-response-format.test.ts +14 -4
- package/bundle/src/application/qgrid/qgrid-response-format.ts +18 -2
- package/bundle/src/application/qgrid/qgrid-run-lifecycle.test.ts +36 -1
- package/bundle/src/application/qgrid/qgrid-run-lifecycle.ts +25 -3
- package/bundle/src/application/qgrid/qgrid.dispatcher.test.ts +17 -0
- package/bundle/src/application/qgrid/qgrid.dispatcher.ts +8 -0
- package/bundle/src/application/qgrid/qgrid.frame.test.ts +187 -0
- package/bundle/src/application/qgrid/qgrid.frame.ts +287 -3
- package/bundle/src/application/qgrid/qgrid.types.ts +103 -0
- package/bundle/src/application/request-log/request-log.entity.json +3 -2
- package/bundle/src/application/request-log/request-log.model.test.ts +19 -0
- package/bundle/src/application/request-log/request-log.model.ts +20 -1
- package/bundle/src/application/sonamu.generated.http +22 -0
- package/bundle/src/application/sonamu.generated.ts +2 -1
- package/bundle/src/i18n/sd.generated.ts +2 -1
- package/bundle/src/utils/providers/common/model-cost.ts +15 -0
- package/bundle/src/utils/providers/openai/openai-dispatcher.test.ts +16 -0
- package/bundle/src/utils/providers/openai/openai-dispatcher.ts +26 -0
- package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +125 -0
- package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +184 -0
- package/bundle/src/utils/providers/openai/openai-voice-client.ts +277 -5
- package/bundle/web-dist/client/assets/index-BeceW0U9.js +104 -0
- package/bundle/web-dist/client/assets/index-hUNCpC11.css +1 -0
- package/bundle/web-dist/client/assets/logs-jMJnTwZn.js +1 -0
- package/bundle/web-dist/client/assets/monit-B1xRKwua.js +1 -0
- package/bundle/web-dist/client/assets/{routes-Dw227enb.js → routes-fsiyivXx.js} +2 -2
- package/bundle/web-dist/client/assets/{settings-BXmAToY1.js → settings-CHX44roa.js} +1 -1
- package/bundle/web-dist/client/assets/show-BDMwKfEY.js +2 -0
- package/bundle/web-dist/client/assets/{tokens-D8L8AC4v.js → tokens-zGl36OfE.js} +1 -1
- package/bundle/web-dist/client/assets/{use-oauth-login-flow-BcEUkszt.js → use-oauth-login-flow-DYWj4645.js} +1 -1
- package/bundle/web-dist/client/assets/use-update-token-mutation-BRXXrEf5.js +1 -0
- package/bundle/web-dist/client/assets/{vendor-tanstack-6B86itGS.js → vendor-tanstack-DMgmqjm4.js} +1 -1
- package/bundle/web-dist/client/assets/voice-Bwcp-KAu.js +1 -0
- package/bundle/web-dist/client/index.html +3 -3
- package/bundle/web-dist/server/assets/{TimedPlayer-DAwjkP4z.js → TimedPlayer-COqaTQSl.js} +1 -1
- package/bundle/web-dist/server/assets/{logs-BmBpBe-j.js → logs-HPho1SkC.js} +5 -6
- package/bundle/web-dist/server/assets/{monit-Db1WrIls.js → monit-Bl2kSkSF.js} +3 -3
- package/bundle/web-dist/server/assets/{plus-CW9y_K7l.js → plus-CQ8AHpih.js} +1 -1
- package/bundle/web-dist/server/assets/{refresh-cw-CRgcH5bT.js → refresh-cw-pYSuvt4c.js} +1 -1
- package/bundle/web-dist/server/assets/{request-model-DRF7hmJC.js → request-model-ZulJMbGm.js} +1 -1
- package/bundle/web-dist/server/assets/{routes-CARZj7or.js → routes-BNHCX4VI.js} +4 -4
- package/bundle/web-dist/server/assets/{services.generated-B6QpnL_N.js → services.generated-C3b31_vt.js} +23209 -22930
- package/bundle/web-dist/server/assets/{settings-B4jdpP5N.js → settings-NJUyaSrJ.js} +4 -4
- package/bundle/web-dist/server/assets/{show-CnLDFCtW.js → show-Dz5QGL7l.js} +8 -9
- package/bundle/web-dist/server/assets/{tokens-TDQguTdh.js → tokens-BPQvjIGq.js} +5 -5
- package/bundle/web-dist/server/assets/{use-oauth-login-flow-du7pOh_H.js → use-oauth-login-flow-CCc8LEmn.js} +1 -1
- package/bundle/web-dist/server/assets/{use-update-token-mutation-DA6HiiWS.js → use-update-token-mutation-Ba-sEhq1.js} +1 -1
- package/bundle/web-dist/server/assets/{voice-BvAl-vTr.js → voice-V-E3tRqD.js} +289 -22
- package/bundle/web-dist/server/entry-server.generated.js +5581 -71
- package/package.json +1 -1
- package/skills/qgrid/references/decision-rationale.md +5 -1
- package/skills/qgrid/references/openai-codex-runtime.md +15 -0
- package/skills/qgrid/references/request-log-run-lifecycle.md +3 -2
- package/skills/qgrid/references/sonamu-api-web-flow.md +2 -2
- package/bundle/web-dist/client/assets/index-Co8uAhSV.css +0 -1
- package/bundle/web-dist/client/assets/index-DYYtV8Qx.js +0 -104
- package/bundle/web-dist/client/assets/logs-CbDtQif1.js +0 -1
- package/bundle/web-dist/client/assets/monit-DtW8o_yF.js +0 -1
- package/bundle/web-dist/client/assets/show-5qj6wFgp.js +0 -2
- package/bundle/web-dist/client/assets/use-update-token-mutation-Ca0n_WnM.js +0 -1
- package/bundle/web-dist/client/assets/voice-D-c1Eyp3.js +0 -1
- package/bundle/web-dist/server/assets/link-DrdV092C.js +0 -4919
|
@@ -33,6 +33,8 @@ import { handleChatgptAuthTokensRefresh } from "./openai-refresh";
|
|
|
33
33
|
import { type OpenAITransportKind, resolveOpenAITransportKind } from "./openai-transport-config";
|
|
34
34
|
import {
|
|
35
35
|
isUnauthorizedRealtimeError,
|
|
36
|
+
type OpenAILiveCall,
|
|
37
|
+
type OpenAILiveCallRequest,
|
|
36
38
|
type OpenAISpeakRequest,
|
|
37
39
|
type OpenAISpeechResult,
|
|
38
40
|
type OpenAITranscribeRequest,
|
|
@@ -246,6 +248,12 @@ const AUTO_IMAGE_TOOL: OpenAIResponseItem = {
|
|
|
246
248
|
},
|
|
247
249
|
};
|
|
248
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Hosted web search as Codex sends it (tools/src/tool_spec.rs); `external_web_access` asks for
|
|
253
|
+
* live search rather than the cached index. Answered on the subscription route (2026-11-10).
|
|
254
|
+
*/
|
|
255
|
+
const WEB_SEARCH_TOOL: OpenAIResponseItem = { type: "web_search", external_web_access: true };
|
|
256
|
+
|
|
249
257
|
function requestOptions(req: GenerateRequest): OpenAIResponsesOptions {
|
|
250
258
|
const { outputFormat, ...imageControls } = req.imageGenerationOptions ?? {};
|
|
251
259
|
const auto = req.imageGeneration === "auto";
|
|
@@ -271,6 +279,11 @@ function requestOptions(req: GenerateRequest): OpenAIResponsesOptions {
|
|
|
271
279
|
options.tools = [AUTO_IMAGE_TOOL];
|
|
272
280
|
}
|
|
273
281
|
|
|
282
|
+
// Function tools reach OpenAI through qgrid's tool emulation; only hosted search goes native.
|
|
283
|
+
if (req.tools?.some((tool) => tool.type === "web_search")) {
|
|
284
|
+
options.tools = [...(options.tools ?? []), WEB_SEARCH_TOOL];
|
|
285
|
+
}
|
|
286
|
+
|
|
274
287
|
const reasoning = asReasoning(req);
|
|
275
288
|
|
|
276
289
|
if (reasoning) options.reasoning = reasoning;
|
|
@@ -356,6 +369,18 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
356
369
|
);
|
|
357
370
|
}
|
|
358
371
|
|
|
372
|
+
async startLive(
|
|
373
|
+
request: OpenAILiveCallRequest & OpenAIVoiceSelection,
|
|
374
|
+
): Promise<OpenAIVoiceDispatchResult<OpenAILiveCall>> {
|
|
375
|
+
const { preferredTokenId, requirePreferredToken, ...liveRequest } = request;
|
|
376
|
+
|
|
377
|
+
return this.runVoice(
|
|
378
|
+
{ preferredTokenId, requirePreferredToken },
|
|
379
|
+
request.signal,
|
|
380
|
+
(credentials) => this.voiceClient.createLiveCall(credentials, liveRequest),
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
359
384
|
/**
|
|
360
385
|
* Selects a token, runs the realtime call, and on one 401 refreshes that token's credentials and
|
|
361
386
|
* retries once (as the Responses transports do). Any other failure propagates: a realtime
|
|
@@ -416,6 +441,7 @@ export class OpenAIDispatcher implements ProviderDispatcher {
|
|
|
416
441
|
}
|
|
417
442
|
|
|
418
443
|
async stop(): Promise<void> {
|
|
444
|
+
this.voiceClient.closeLiveSessions();
|
|
419
445
|
this.clients.forEach(({ client }) => client.close?.());
|
|
420
446
|
this.clients.clear();
|
|
421
447
|
this.retiredClients.forEach((entry) => entry.client.close?.());
|
|
@@ -81,6 +81,131 @@ export const OPENAI_TRANSCRIPTION_MODELS_WITHOUT_PROMPT: ReadonlySet<string> = n
|
|
|
81
81
|
*/
|
|
82
82
|
export const OPENAI_SPEECH_MODELS = ["gpt-realtime-2.1-mini", "gpt-realtime-2.1"] as const;
|
|
83
83
|
|
|
84
|
+
// GPT-Live (Codex realtime v3, "frameless") on a ChatGPT subscription, mirroring openai/codex main
|
|
85
|
+
// @ 2026-11-10. The caller's own WebRTC peer carries the audio; qgrid only exchanges its SDP offer
|
|
86
|
+
// through /realtime/calls and watches the call's sideband for the transcript and usage. The direct
|
|
87
|
+
// /v1/live sockets refuse the subscription token ("Voice session access denied"), as Codex expects
|
|
88
|
+
// (core/src/realtime_conversation.rs realtime_api_key). Probe notes: SON-591, SON-592.
|
|
89
|
+
|
|
90
|
+
/** codex-api/src/endpoint/realtime_call.rs configure_realtime_call_request (backend shape + v3). */
|
|
91
|
+
export const OPENAI_LIVE_CALLS_QUERY = "intent=quicksilver&architecture=avas";
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Undocumented; Codex sends it for v3 (core/src/realtime_conversation.rs realtime_request_headers).
|
|
95
|
+
* Required on both the /calls POST (else 400 invalid_quicksilver_alpha_header) and the sideband.
|
|
96
|
+
*/
|
|
97
|
+
export const OPENAI_LIVE_ALPHA_HEADER = { "OpenAI-Alpha": "quicksilver=v2" } as const;
|
|
98
|
+
|
|
99
|
+
/** Sideband base: wss://api.openai.com/v1/live/<rtc_id> (realtime_websocket/methods.rs). */
|
|
100
|
+
export const OPENAI_LIVE_WS_URL = "wss://api.openai.com/v1/live" as const;
|
|
101
|
+
|
|
102
|
+
/** The only live model qgrid exposes. */
|
|
103
|
+
export const OPENAI_LIVE_MODEL = "gpt-live-1";
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Sent as session.model, as Codex does (DEFAULT_FRAMELESS_REALTIME_MODEL). The backend ignores the
|
|
107
|
+
* field on this route: made-up names opened a session too (2026-11-10).
|
|
108
|
+
*/
|
|
109
|
+
const OPENAI_LIVE_WIRE_MODEL = "gpt-live-1-codex";
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* protocol/src/protocol.rs RealtimeVoicesList::builtin v3; Codex's live default is cove. Any other
|
|
113
|
+
* voice still gets a 201 from /calls, but the session never starts (sideband 404).
|
|
114
|
+
*/
|
|
115
|
+
export const OPENAI_LIVE_VOICES = [
|
|
116
|
+
"cove",
|
|
117
|
+
"juniper",
|
|
118
|
+
"maple",
|
|
119
|
+
"spruce",
|
|
120
|
+
"ember",
|
|
121
|
+
"vale",
|
|
122
|
+
"breeze",
|
|
123
|
+
"arbor",
|
|
124
|
+
"sol",
|
|
125
|
+
"aube",
|
|
126
|
+
"bubbie",
|
|
127
|
+
"haetsal",
|
|
128
|
+
"hanul",
|
|
129
|
+
"himari",
|
|
130
|
+
"leher",
|
|
131
|
+
"miko",
|
|
132
|
+
"neer",
|
|
133
|
+
"porto",
|
|
134
|
+
"rindo",
|
|
135
|
+
"rio",
|
|
136
|
+
"rivage",
|
|
137
|
+
"selva",
|
|
138
|
+
"sonna",
|
|
139
|
+
"tinta",
|
|
140
|
+
"viola",
|
|
141
|
+
] as const;
|
|
142
|
+
|
|
143
|
+
export const OPENAI_LIVE_DEFAULT_VOICE = "cove";
|
|
144
|
+
|
|
145
|
+
export function isOpenAILiveVoice(value: string): boolean {
|
|
146
|
+
return OPENAI_LIVE_VOICES.some((voice) => voice === value);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** codex-api methods_frameless_bidi.rs session_json, without initial items or handoffs. */
|
|
150
|
+
export function buildLiveSession(options: { voice: string; instructions?: string }): JsonValue {
|
|
151
|
+
return {
|
|
152
|
+
model: OPENAI_LIVE_WIRE_MODEL,
|
|
153
|
+
instructions: options.instructions ?? "",
|
|
154
|
+
audio: { output: { voice: options.voice } },
|
|
155
|
+
delegation: { type: "client" },
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** One finished turn; the sideband also mirrors both audio streams, which qgrid skips. */
|
|
160
|
+
export const liveTurnDoneEvent = z.looseObject({
|
|
161
|
+
type: z.literal("turn.done"),
|
|
162
|
+
turn: z.looseObject({
|
|
163
|
+
role: z.string(),
|
|
164
|
+
transcript: z.string(),
|
|
165
|
+
start_ms: z.number(),
|
|
166
|
+
end_ms: z.number(),
|
|
167
|
+
}),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* With `delegation.type: "client"` the voice model hands work it cannot do itself (lookups,
|
|
172
|
+
* reasoning) to the client and keeps talking until the answer arrives; Codex runs it as a turn of
|
|
173
|
+
* its own agent (core/src/realtime_conversation.rs route_realtime_text_input). Left unanswered,
|
|
174
|
+
* the voice stalls with filler indefinitely (SON-592). `responses` delegation, where OpenAI runs
|
|
175
|
+
* the backend, fails on the subscription route (2026-11-10).
|
|
176
|
+
*/
|
|
177
|
+
export const liveDelegationCreatedEvent = z.looseObject({
|
|
178
|
+
type: z.literal("delegation.created"),
|
|
179
|
+
item: z.looseObject({
|
|
180
|
+
id: z.string(),
|
|
181
|
+
target: z.literal("client"),
|
|
182
|
+
content: z.array(z.looseObject({ type: z.string(), text: z.string().optional() })),
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
/** The answer to a delegation; no channel means speakable (codex-api methods_frameless_bidi.rs). */
|
|
187
|
+
export function liveDelegationAnswerEvent(delegationItemId: string, text: string): JsonValue {
|
|
188
|
+
return {
|
|
189
|
+
type: "delegation.context.append",
|
|
190
|
+
delegation_item_id: delegationItemId,
|
|
191
|
+
content: [{ type: "input_text", text }],
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const liveUsage = z.looseObject({ audio_duration_ms: z.number() });
|
|
196
|
+
|
|
197
|
+
/** Running usage, about every 15 s; the last one stands in when the session ends without close. */
|
|
198
|
+
export const liveUsageUpdatedEvent = z.looseObject({
|
|
199
|
+
type: z.literal("session.usage.updated"),
|
|
200
|
+
usage: liveUsage,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
export const liveSessionClosedEvent = z.looseObject({
|
|
204
|
+
type: z.literal("session.closed"),
|
|
205
|
+
reason: z.string().optional(),
|
|
206
|
+
usage: liveUsage.optional(),
|
|
207
|
+
});
|
|
208
|
+
|
|
84
209
|
/**
|
|
85
210
|
* A minimal Opus-only SDP offer. Codex sends a real WebRTC offer; qgrid has no RTP peer and only
|
|
86
211
|
* needs the call id from the response. The server has accepted this offer on every probe
|
|
@@ -3,10 +3,12 @@ import { describe, expect, it, vi } from "vitest";
|
|
|
3
3
|
import { CODEX_CLI_ORIGINATOR } from "./openai-backend-protocol";
|
|
4
4
|
import type { OpenAIWebSocketFactory, OpenAIWebSocketLike } from "./openai-direct-client";
|
|
5
5
|
import {
|
|
6
|
+
buildLiveSession,
|
|
6
7
|
buildOpenAIRealtimeHeaders,
|
|
7
8
|
buildSpeechSession,
|
|
8
9
|
buildTranscriptionSession,
|
|
9
10
|
decodeWav,
|
|
11
|
+
OPENAI_LIVE_WS_URL,
|
|
10
12
|
OPENAI_REALTIME_CALLS_URL,
|
|
11
13
|
OPENAI_REALTIME_WS_URL,
|
|
12
14
|
prepareRealtimeInput,
|
|
@@ -580,3 +582,185 @@ describe("OpenAIVoiceClient.speak", () => {
|
|
|
580
582
|
});
|
|
581
583
|
});
|
|
582
584
|
|
|
585
|
+
describe("OpenAIVoiceClient.createLiveCall", () => {
|
|
586
|
+
// Shapes observed live on 2026-11-10 (SON-592): a browser peer in conversation with gpt-live-1.
|
|
587
|
+
const userTurn = {
|
|
588
|
+
type: "turn.done",
|
|
589
|
+
turn: { id: "turn_u", role: "user", start_ms: 600, end_ms: 5800, transcript: "Hi there?" },
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
const assistantTurn = {
|
|
593
|
+
type: "turn.done",
|
|
594
|
+
turn: { id: "turn_a", role: "assistant", start_ms: 5600, end_ms: 9400, transcript: "Hello!" },
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
it("exchanges the offer through /calls with the alpha header and summarizes the sideband", async () => {
|
|
598
|
+
const fetchMock = vi.fn(async () => callsResponse("rtc_live"));
|
|
599
|
+
const ws = mockedWebSocket();
|
|
600
|
+
|
|
601
|
+
const client = new OpenAIVoiceClient({
|
|
602
|
+
fetch: fetchMock as unknown as typeof fetch,
|
|
603
|
+
webSocketFactory: ws.factory,
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
const progress: number[] = [];
|
|
607
|
+
|
|
608
|
+
const call = await client.createLiveCall(credentials, {
|
|
609
|
+
sdp: "v=0\r\noffer",
|
|
610
|
+
voice: "hanul",
|
|
611
|
+
instructions: "Be brief.",
|
|
612
|
+
onTurn: (turns) => progress.push(turns.length),
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const [url, init] = fetchMock.mock.calls[0] as unknown as [string, RequestInit];
|
|
616
|
+
expect(url).toBe(`${OPENAI_REALTIME_CALLS_URL}?intent=quicksilver&architecture=avas`);
|
|
617
|
+
const headers = init.headers as Record<string, string>;
|
|
618
|
+
expect(headers["OpenAI-Alpha"]).toBe("quicksilver=v2");
|
|
619
|
+
expect(headers.Authorization).toBe("Bearer access");
|
|
620
|
+
|
|
621
|
+
expect(JSON.parse(String(init.body))).toEqual({
|
|
622
|
+
sdp: "v=0\r\noffer",
|
|
623
|
+
session: {
|
|
624
|
+
model: "gpt-live-1-codex",
|
|
625
|
+
instructions: "Be brief.",
|
|
626
|
+
audio: { output: { voice: "hanul" } },
|
|
627
|
+
delegation: { type: "client" },
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
expect(buildLiveSession({ voice: "cove" })).toMatchObject({ instructions: "" });
|
|
632
|
+
expect(call).toMatchObject({ sdp: "v=0", callId: "rtc_live" });
|
|
633
|
+
expect(call.quotaHeaders.get("x-codex-primary-used-percent")).toBe("88");
|
|
634
|
+
expect(ws.calls[0]?.url).toBe(`${OPENAI_LIVE_WS_URL}/rtc_live`);
|
|
635
|
+
expect(ws.calls[0]?.headers["OpenAI-Alpha"]).toBe("quicksilver=v2");
|
|
636
|
+
|
|
637
|
+
const socket = ws.sockets[0]!;
|
|
638
|
+
socket.emit("open");
|
|
639
|
+
socket.message({ type: "session.started", session: { id: "rtc_live", expires_at: 1 } });
|
|
640
|
+
socket.message({ type: "session.input_audio.append", audio: "AAAA" });
|
|
641
|
+
socket.message(userTurn);
|
|
642
|
+
socket.message({ type: "session.output_audio.delta", delta: "AAAA" });
|
|
643
|
+
socket.message(assistantTurn);
|
|
644
|
+
socket.message({ type: "session.usage.updated", usage: { audio_duration_ms: 5000 } });
|
|
645
|
+
|
|
646
|
+
socket.message({
|
|
647
|
+
type: "session.closed",
|
|
648
|
+
reason: "client_request",
|
|
649
|
+
usage: { audio_duration_ms: 9400 },
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
await expect(call.ended).resolves.toMatchObject({
|
|
653
|
+
turns: [
|
|
654
|
+
{ role: "user", transcript: "Hi there?", startMs: 600, endMs: 5800 },
|
|
655
|
+
{ role: "assistant", transcript: "Hello!", startMs: 5600, endMs: 9400 },
|
|
656
|
+
],
|
|
657
|
+
audioDurationMs: 9400,
|
|
658
|
+
endReason: "client_request",
|
|
659
|
+
});
|
|
660
|
+
expect(progress).toEqual([1, 2]);
|
|
661
|
+
// The session belongs to the caller's peer: qgrid sends nothing on the sideband.
|
|
662
|
+
expect(socket.sent).toHaveLength(0);
|
|
663
|
+
expect(socket.closed?.code).toBe(1000);
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
it("answers a delegation on the sideband and keeps the session's events", async () => {
|
|
667
|
+
const ws = mockedWebSocket();
|
|
668
|
+
|
|
669
|
+
const client = new OpenAIVoiceClient({
|
|
670
|
+
fetch: (async () => callsResponse("rtc_live")) as unknown as typeof fetch,
|
|
671
|
+
webSocketFactory: ws.factory,
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
const onDelegation = vi.fn(async () => "Nvidia is in today's top story.");
|
|
675
|
+
const call = await client.createLiveCall(credentials, { sdp: "v=0", onDelegation });
|
|
676
|
+
const socket = ws.sockets[0]!;
|
|
677
|
+
socket.emit("open");
|
|
678
|
+
socket.message({ type: "session.input_audio.append", audio: "AAAA" });
|
|
679
|
+
socket.message({ type: "turn.delta", delta: " news", turn_id: "turn_u" });
|
|
680
|
+
|
|
681
|
+
socket.message({
|
|
682
|
+
type: "delegation.created",
|
|
683
|
+
item: {
|
|
684
|
+
id: "item_d",
|
|
685
|
+
type: "delegation",
|
|
686
|
+
target: "client",
|
|
687
|
+
handoff_id: "handoff_1",
|
|
688
|
+
content: [{ type: "input_text", text: "Look up today's top tech news" }],
|
|
689
|
+
},
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
await tick();
|
|
693
|
+
await tick();
|
|
694
|
+
|
|
695
|
+
expect(onDelegation).toHaveBeenCalledWith({ itemId: "item_d", text: "Look up today's top tech news" });
|
|
696
|
+
expect(socket.sentEvents()).toEqual([
|
|
697
|
+
{
|
|
698
|
+
type: "delegation.context.append",
|
|
699
|
+
delegation_item_id: "item_d",
|
|
700
|
+
content: [{ type: "input_text", text: "Nvidia is in today's top story." }],
|
|
701
|
+
},
|
|
702
|
+
]);
|
|
703
|
+
|
|
704
|
+
socket.message({ type: "session.closed", reason: "client_request", usage: { audio_duration_ms: 1 } });
|
|
705
|
+
const summary = await call.ended;
|
|
706
|
+
|
|
707
|
+
// Audio copies and word-level text are skipped; qgrid's own answer is logged with them.
|
|
708
|
+
expect(summary.events.map(({ event }) => (event as { type: string }).type)).toEqual([
|
|
709
|
+
"delegation.created",
|
|
710
|
+
"delegation.context.append",
|
|
711
|
+
"session.closed",
|
|
712
|
+
]);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
it("ends at a bare sideband close with the last reported usage", async () => {
|
|
716
|
+
const ws = mockedWebSocket();
|
|
717
|
+
|
|
718
|
+
const client = new OpenAIVoiceClient({
|
|
719
|
+
fetch: (async () => callsResponse("rtc_live")) as unknown as typeof fetch,
|
|
720
|
+
webSocketFactory: ws.factory,
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
const call = await client.createLiveCall(credentials, { sdp: "v=0" });
|
|
724
|
+
const socket = ws.sockets[0]!;
|
|
725
|
+
socket.emit("open");
|
|
726
|
+
socket.message(userTurn);
|
|
727
|
+
socket.message({ type: "session.usage.updated", usage: { audio_duration_ms: 27_400 } });
|
|
728
|
+
socket.emit("close", 1006, Buffer.from(""));
|
|
729
|
+
|
|
730
|
+
await expect(call.ended).resolves.toMatchObject({
|
|
731
|
+
turns: [{ role: "user" }],
|
|
732
|
+
audioDurationMs: 27_400,
|
|
733
|
+
endReason: "sideband closed (1006)",
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
it("resolves, never rejects, when the sideband handshake fails", async () => {
|
|
738
|
+
const ws = mockedWebSocket();
|
|
739
|
+
|
|
740
|
+
const client = new OpenAIVoiceClient({
|
|
741
|
+
fetch: (async () => callsResponse("rtc_live")) as unknown as typeof fetch,
|
|
742
|
+
webSocketFactory: ws.factory,
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
const call = await client.createLiveCall(credentials, { sdp: "v=0" });
|
|
746
|
+
ws.sockets[0]!.emit("unexpected-response", {}, { statusCode: 404 });
|
|
747
|
+
|
|
748
|
+
await expect(call.ended).resolves.toEqual({
|
|
749
|
+
turns: [],
|
|
750
|
+
events: [],
|
|
751
|
+
audioDurationMs: undefined,
|
|
752
|
+
endReason: "sideband error",
|
|
753
|
+
error: "realtime socket handshake rejected with HTTP 404",
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
it("rejects voices outside the live list before any network call", async () => {
|
|
758
|
+
const fetchMock = vi.fn();
|
|
759
|
+
const client = new OpenAIVoiceClient({ fetch: fetchMock as unknown as typeof fetch });
|
|
760
|
+
|
|
761
|
+
await expect(
|
|
762
|
+
client.createLiveCall(credentials, { sdp: "v=0", voice: "marin" }),
|
|
763
|
+
).rejects.toBeInstanceOf(OpenAIVoiceInputError);
|
|
764
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
765
|
+
});
|
|
766
|
+
});
|