@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
|
@@ -15,9 +15,11 @@ const {
|
|
|
15
15
|
finishRunMock,
|
|
16
16
|
createRunMock,
|
|
17
17
|
expireStaleToolWaitingRunsMock,
|
|
18
|
+
expireStaleLiveRunsMock,
|
|
18
19
|
continueToolRunMock,
|
|
19
20
|
recordRunProgressMock,
|
|
20
21
|
} = vi.hoisted(() => ({
|
|
22
|
+
expireStaleLiveRunsMock: vi.fn(),
|
|
21
23
|
recordRunProgressMock: vi.fn(),
|
|
22
24
|
appendStepMock: vi.fn(),
|
|
23
25
|
aggregateStepUsageMock: vi.fn(),
|
|
@@ -34,6 +36,7 @@ vi.mock("../request-log/request-log.model", () => ({
|
|
|
34
36
|
finishRun: finishRunMock,
|
|
35
37
|
createRun: createRunMock,
|
|
36
38
|
expireStaleToolWaitingRuns: expireStaleToolWaitingRunsMock,
|
|
39
|
+
expireStaleLiveRuns: expireStaleLiveRunsMock,
|
|
37
40
|
continueToolRun: continueToolRunMock,
|
|
38
41
|
recordRunProgress: recordRunProgressMock,
|
|
39
42
|
},
|
|
@@ -102,6 +105,7 @@ describe("qgrid run lifecycle start", () => {
|
|
|
102
105
|
vi.spyOn(Date, "now").mockReturnValue(lifecycleNow);
|
|
103
106
|
createRunMock.mockReset().mockResolvedValue(10);
|
|
104
107
|
expireStaleToolWaitingRunsMock.mockReset().mockResolvedValue([]);
|
|
108
|
+
expireStaleLiveRunsMock.mockReset().mockResolvedValue(0);
|
|
105
109
|
continueToolRunMock.mockReset().mockResolvedValue(3);
|
|
106
110
|
aggregateStepUsageMock.mockReset().mockResolvedValue({
|
|
107
111
|
input_tokens: 0,
|
|
@@ -119,6 +123,27 @@ describe("qgrid run lifecycle start", () => {
|
|
|
119
123
|
vi.restoreAllMocks();
|
|
120
124
|
});
|
|
121
125
|
|
|
126
|
+
it("stores history images as their length only", async () => {
|
|
127
|
+
const image = "data:image/png;base64,iVBORw0KGgo=";
|
|
128
|
+
const history = JSON.stringify([
|
|
129
|
+
{ type: "message", role: "user", content: [{ type: "input_image", image_url: image }] },
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
await beforeQuery({ prompt: "edit it", history });
|
|
133
|
+
|
|
134
|
+
expect(createRunMock).toHaveBeenCalledWith(
|
|
135
|
+
expect.objectContaining({
|
|
136
|
+
history: [
|
|
137
|
+
{
|
|
138
|
+
type: "message",
|
|
139
|
+
role: "user",
|
|
140
|
+
content: [{ type: "input_image", image_url: `[data-url ${image.length} chars]` }],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
122
147
|
it("creates a running parent with the full requested model before an initial query", async () => {
|
|
123
148
|
const history = JSON.stringify([
|
|
124
149
|
{ type: "message", role: "user", content: "earlier" },
|
|
@@ -263,6 +288,15 @@ describe("qgrid run lifecycle start", () => {
|
|
|
263
288
|
expect(finishRunMock).not.toHaveBeenCalled();
|
|
264
289
|
});
|
|
265
290
|
|
|
291
|
+
it("closes live sessions only after their two-hour limit and the watcher's margin", async () => {
|
|
292
|
+
await beforeQuery({ prompt: "hi", model: "openai/gpt-5-codex" });
|
|
293
|
+
|
|
294
|
+
expect(expireStaleLiveRunsMock).toHaveBeenCalledWith(
|
|
295
|
+
new Date(lifecycleNow - (2 * 60 + 15) * 60 * 1000),
|
|
296
|
+
"live session: the server stopped before the session ended",
|
|
297
|
+
);
|
|
298
|
+
});
|
|
299
|
+
|
|
266
300
|
it("throttles stale cleanup while still creating every requested run", async () => {
|
|
267
301
|
await beforeQuery({ prompt: "one", model: "openai/gpt-5-codex" });
|
|
268
302
|
await beforeQuery({ prompt: "two", model: "openai/gpt-5-codex" });
|
|
@@ -519,7 +553,8 @@ describe("qgrid run lifecycle TTFT", () => {
|
|
|
519
553
|
size: "1536x1024",
|
|
520
554
|
},
|
|
521
555
|
}),
|
|
522
|
-
|
|
556
|
+
// The run's response carries the image itself.
|
|
557
|
+
tool_result: "[image image/png 11 bytes, shown in the response]",
|
|
523
558
|
}),
|
|
524
559
|
);
|
|
525
560
|
});
|
|
@@ -18,6 +18,11 @@ import { composeSystemWithSchemaContract } from "./schema-prompt";
|
|
|
18
18
|
|
|
19
19
|
const logger = getLogger(["qgrid", "run-lifecycle"]);
|
|
20
20
|
const STALE_RUN_THRESHOLD_MS = 30 * 60 * 1000;
|
|
21
|
+
|
|
22
|
+
// Live voice sessions expire two hours after creation and their watcher gives up five minutes
|
|
23
|
+
// later (OPENAI_LIVE_WATCH_LIMIT_MS); a live run still running after this lost its server.
|
|
24
|
+
const STALE_LIVE_RUN_THRESHOLD_MS = (2 * 60 + 15) * 60 * 1000;
|
|
25
|
+
|
|
21
26
|
const STALE_CLEANUP_INTERVAL_MS = 60 * 1000;
|
|
22
27
|
let staleCleanupInFlight: Promise<void> | undefined;
|
|
23
28
|
let lastStaleCleanupStartedAt = 0;
|
|
@@ -46,13 +51,22 @@ const StoredHistoryMessage = z.looseObject({
|
|
|
46
51
|
|
|
47
52
|
type StoredHistoryMessage = z.infer<typeof StoredHistoryMessage>;
|
|
48
53
|
|
|
54
|
+
// Images in history were stored with the run that sent or generated them, and nothing reads them
|
|
55
|
+
// back from here: keep only their length. Base64 has no quotes or escapes, so a match is exactly one
|
|
56
|
+
// JSON string value.
|
|
57
|
+
const DATA_URL_STRING = /"data:[^",;\\]*;base64,[A-Za-z0-9+/=]*"/g;
|
|
58
|
+
|
|
59
|
+
function maskDataUrls(rawHistory: string): string {
|
|
60
|
+
return rawHistory.replace(DATA_URL_STRING, (match) => `"[data-url ${match.length - 2} chars]"`);
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
function filterHistoryForStorage(
|
|
50
64
|
rawHistory: string | undefined,
|
|
51
65
|
): StoredHistoryMessage[] | undefined {
|
|
52
66
|
if (!rawHistory) return undefined;
|
|
53
67
|
|
|
54
68
|
try {
|
|
55
|
-
const items = z.array(z.unknown()).parse(JSON.parse(rawHistory));
|
|
69
|
+
const items = z.array(z.unknown()).parse(JSON.parse(maskDataUrls(rawHistory)));
|
|
56
70
|
|
|
57
71
|
const filtered = items.flatMap((item) => {
|
|
58
72
|
const message = StoredHistoryMessage.safeParse(item);
|
|
@@ -223,7 +237,10 @@ export async function afterQuery(
|
|
|
223
237
|
? 0
|
|
224
238
|
: estimateImageGenerationCostMicroUsd(result, args.imageGenerationOptions);
|
|
225
239
|
|
|
226
|
-
|
|
240
|
+
// A tool-calls step ends without a response, so only then do its steps keep the image bytes.
|
|
241
|
+
const imagesInResponse = result.finishReason !== "tool-calls";
|
|
242
|
+
|
|
243
|
+
for (const step of buildImageGenerationToolSteps(args, imageParts, stepIndex, imagesInResponse)) {
|
|
227
244
|
await RequestLogModel.appendStep(requestLogId, step);
|
|
228
245
|
}
|
|
229
246
|
|
|
@@ -402,7 +419,12 @@ async function performStaleRunCleanup(): Promise<void> {
|
|
|
402
419
|
errorMessage,
|
|
403
420
|
);
|
|
404
421
|
|
|
405
|
-
const
|
|
422
|
+
const liveCount = await RequestLogModel.expireStaleLiveRuns(
|
|
423
|
+
new Date(Date.now() - STALE_LIVE_RUN_THRESHOLD_MS),
|
|
424
|
+
"live session: the server stopped before the session ended",
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
const cleanedCount = staleIds.length + liveCount;
|
|
406
428
|
|
|
407
429
|
if (cleanedCount > 0) {
|
|
408
430
|
logger.info(`cleaned up ${cleanedCount} stale running request logs`);
|
|
@@ -287,6 +287,23 @@ describe("QgridDispatcherClass", () => {
|
|
|
287
287
|
expect(dispatcher.getStats().map((row) => row.requests)).toEqual([2, 2]);
|
|
288
288
|
});
|
|
289
289
|
|
|
290
|
+
it("passes server-side web search to direct providers and refuses it for Claude Code", async () => {
|
|
291
|
+
const dispatcher = new QgridDispatcherClass();
|
|
292
|
+
const generate = vi.fn(async (_request: GenerateRequest) => providerResult({ tokenName: "t" }));
|
|
293
|
+
dispatcher.openaiDispatcher = { generate } as never;
|
|
294
|
+
dispatcher.anthropicDispatcher = { generate } as never;
|
|
295
|
+
|
|
296
|
+
await dispatcher.query({ prompt: "news?", model: "openai/gpt-6-luna", webSearch: true });
|
|
297
|
+
await dispatcher.query({ prompt: "hi", model: "openai/gpt-6-luna" });
|
|
298
|
+
|
|
299
|
+
expect(generate.mock.calls[0]?.[0]).toMatchObject({ tools: [{ type: "web_search" }] });
|
|
300
|
+
expect(generate.mock.calls[1]?.[0]).not.toHaveProperty("tools");
|
|
301
|
+
await expect(
|
|
302
|
+
dispatcher.query({ prompt: "news?", model: "anthropic/claude-sonnet-5", webSearch: true }),
|
|
303
|
+
).rejects.toThrow("web search is not available");
|
|
304
|
+
expect(generate).toHaveBeenCalledTimes(2);
|
|
305
|
+
});
|
|
306
|
+
|
|
290
307
|
const toolsAndSchema = {
|
|
291
308
|
tools: [
|
|
292
309
|
{
|
|
@@ -52,6 +52,11 @@ export type InternalQueryInput = QueryInput & {
|
|
|
52
52
|
preferredTokenId?: number;
|
|
53
53
|
requirePreferredToken?: boolean;
|
|
54
54
|
onProgress?: GenerateRequest["onProgress"];
|
|
55
|
+
/**
|
|
56
|
+
* Server-side only (GPT-Live delegation): turns on the provider's hosted web search. OpenAI and
|
|
57
|
+
* Grok direct models; the Claude Code runtime has no such tool.
|
|
58
|
+
*/
|
|
59
|
+
webSearch?: boolean;
|
|
55
60
|
};
|
|
56
61
|
|
|
57
62
|
// qgrid 상위가 provider 에 요구하는 실행 계약. 스트리밍은 공통 ProviderDispatcher 에 아직 없어서
|
|
@@ -214,6 +219,7 @@ export class QgridDispatcherClass {
|
|
|
214
219
|
const { provider, dispatcher } = this.resolveDispatcher(input, route.provider);
|
|
215
220
|
|
|
216
221
|
if (provider === "anthropic") {
|
|
222
|
+
if (input.webSearch) throw new Error("web search is not available on anthropic/ models");
|
|
217
223
|
const decision = decideConvRouting(input);
|
|
218
224
|
|
|
219
225
|
const result = await dispatcher.generate({
|
|
@@ -399,6 +405,8 @@ function buildDirectRequest(
|
|
|
399
405
|
onProgress: input.onProgress,
|
|
400
406
|
};
|
|
401
407
|
|
|
408
|
+
if (input.webSearch) request.tools = [{ type: "web_search" }];
|
|
409
|
+
|
|
402
410
|
// Opaque namespaces; the Grok dispatcher reads `xai`, OpenAI ignores it.
|
|
403
411
|
if (input.providerOptions?.xai) {
|
|
404
412
|
request.providerOptions = { xai: { ...input.providerOptions.xai } };
|
|
@@ -47,6 +47,7 @@ const {
|
|
|
47
47
|
requestLogFinishRunMock,
|
|
48
48
|
appendStepMock,
|
|
49
49
|
continueToolRunMock,
|
|
50
|
+
recordRunProgressMock,
|
|
50
51
|
dispatcherQueryMock,
|
|
51
52
|
dispatcherQueryStreamMock,
|
|
52
53
|
beforeQueryMock,
|
|
@@ -75,6 +76,7 @@ const {
|
|
|
75
76
|
requestLogFinishRunMock: vi.fn(),
|
|
76
77
|
appendStepMock: vi.fn(),
|
|
77
78
|
continueToolRunMock: vi.fn(),
|
|
79
|
+
recordRunProgressMock: vi.fn(),
|
|
78
80
|
dispatcherQueryMock: vi.fn(),
|
|
79
81
|
dispatcherQueryStreamMock: vi.fn(),
|
|
80
82
|
beforeQueryMock: vi.fn(),
|
|
@@ -126,6 +128,7 @@ vi.mock("../request-log/request-log.model", () => ({
|
|
|
126
128
|
finishRun: requestLogFinishRunMock,
|
|
127
129
|
appendStep: appendStepMock,
|
|
128
130
|
continueToolRun: continueToolRunMock,
|
|
131
|
+
recordRunProgress: recordRunProgressMock,
|
|
129
132
|
},
|
|
130
133
|
}));
|
|
131
134
|
|
|
@@ -2394,6 +2397,190 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2394
2397
|
});
|
|
2395
2398
|
});
|
|
2396
2399
|
|
|
2400
|
+
describe("GPT-Live call", () => {
|
|
2401
|
+
type Summary = { turns: object[]; audioDurationMs?: number; endReason: string; error?: string };
|
|
2402
|
+
let endSession: (summary: Summary) => void;
|
|
2403
|
+
let startLive: ReturnType<typeof vi.fn>;
|
|
2404
|
+
|
|
2405
|
+
beforeEach(() => {
|
|
2406
|
+
recordRunProgressMock.mockReset().mockResolvedValue(undefined);
|
|
2407
|
+
dispatcherQueryMock.mockReset();
|
|
2408
|
+
const ended = new Promise<Summary>((resolve) => (endSession = resolve));
|
|
2409
|
+
startLive = vi.fn().mockResolvedValue({
|
|
2410
|
+
result: { sdp: "v=0 answer", callId: "rtc_x", quotaHeaders: new Map(), ended },
|
|
2411
|
+
tokenName: "openai/a",
|
|
2412
|
+
});
|
|
2413
|
+
Object.assign(QgridDispatcher, { openaiDispatcher: { startLive } });
|
|
2414
|
+
});
|
|
2415
|
+
|
|
2416
|
+
afterEach(() => {
|
|
2417
|
+
Object.assign(QgridDispatcher, { openaiDispatcher: null });
|
|
2418
|
+
});
|
|
2419
|
+
|
|
2420
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
2421
|
+
|
|
2422
|
+
it("answers at once, fills the running log turn by turn, and finishes it at the end", async () => {
|
|
2423
|
+
const out = await QgridFrame.liveCall({ sdp: "v=0 offer", instructions: "Be brief.", projectName: "p" });
|
|
2424
|
+
|
|
2425
|
+
expect(out).toEqual({
|
|
2426
|
+
sdp: "v=0 answer",
|
|
2427
|
+
callId: "rtc_x",
|
|
2428
|
+
model: "openai/gpt-live-1",
|
|
2429
|
+
voice: "cove",
|
|
2430
|
+
tokenName: "openai/a",
|
|
2431
|
+
requestLogId: 77,
|
|
2432
|
+
});
|
|
2433
|
+
expect(startLive).toHaveBeenCalledWith(
|
|
2434
|
+
expect.objectContaining({ sdp: "v=0 offer", voice: "cove", instructions: "Be brief." }),
|
|
2435
|
+
);
|
|
2436
|
+
expect(requestLogCreateRunMock).toHaveBeenCalledWith(
|
|
2437
|
+
expect.objectContaining({ media_kind: "live", system_prompt: "Be brief.", requested_model_name: "openai/gpt-live-1" }),
|
|
2438
|
+
);
|
|
2439
|
+
// A resolved step: a pending one would fall to the 30-minute tool-wait cleanup.
|
|
2440
|
+
expect(appendStepMock).toHaveBeenCalledWith(
|
|
2441
|
+
77,
|
|
2442
|
+
expect.objectContaining({
|
|
2443
|
+
tool_name: "live_session",
|
|
2444
|
+
tool_call_id: "live_session:rtc_x",
|
|
2445
|
+
tool_result: JSON.stringify({ status: "live", callId: "rtc_x" }),
|
|
2446
|
+
}),
|
|
2447
|
+
);
|
|
2448
|
+
expect(recordRunProgressMock).toHaveBeenCalledWith(77, { token_name: "openai/a" });
|
|
2449
|
+
|
|
2450
|
+
// The watcher reports each finished turn; the running row's conversation follows it.
|
|
2451
|
+
const { onTurn } = startLive.mock.calls[0]![0] as { onTurn: (turns: object[]) => void };
|
|
2452
|
+
onTurn([{ role: "user", transcript: "Hi there?", startMs: 600, endMs: 5800 }]);
|
|
2453
|
+
await settle();
|
|
2454
|
+
expect(recordRunProgressMock).toHaveBeenLastCalledWith(77, { response: "**user** 0:00 \nHi there?" });
|
|
2455
|
+
expect(requestLogFinishRunMock).not.toHaveBeenCalled();
|
|
2456
|
+
|
|
2457
|
+
const summary = {
|
|
2458
|
+
turns: [
|
|
2459
|
+
{ role: "user", transcript: "Hi there?", startMs: 600, endMs: 5800 },
|
|
2460
|
+
{ role: "assistant", transcript: " Hello!", startMs: 65_600, endMs: 69_400 },
|
|
2461
|
+
],
|
|
2462
|
+
audioDurationMs: 60_000,
|
|
2463
|
+
endReason: "client_request",
|
|
2464
|
+
};
|
|
2465
|
+
endSession(summary);
|
|
2466
|
+
await settle();
|
|
2467
|
+
|
|
2468
|
+
expect(continueToolRunMock).toHaveBeenCalledWith(77, [
|
|
2469
|
+
{ toolCallId: "live_session:rtc_x", output: JSON.stringify(summary), isError: false },
|
|
2470
|
+
]);
|
|
2471
|
+
expect(requestLogFinishRunMock).toHaveBeenCalledWith(
|
|
2472
|
+
77,
|
|
2473
|
+
expect.objectContaining({
|
|
2474
|
+
status: "succeeded",
|
|
2475
|
+
token_name: "openai/a",
|
|
2476
|
+
response: "**user** 0:00 \nHi there?\n\n**assistant** 1:05 \nHello!",
|
|
2477
|
+
// One minute of session audio at $0.05/min.
|
|
2478
|
+
cost_usd: 50_000,
|
|
2479
|
+
cost_source: "pricing_table",
|
|
2480
|
+
}),
|
|
2481
|
+
);
|
|
2482
|
+
});
|
|
2483
|
+
|
|
2484
|
+
type LiveHooks = {
|
|
2485
|
+
onTurn: (turns: object[]) => void;
|
|
2486
|
+
onDelegation: (delegation: { itemId: string; text: string }) => Promise<string>;
|
|
2487
|
+
};
|
|
2488
|
+
|
|
2489
|
+
const hooks = () => startLive.mock.calls[0]![0] as LiveHooks;
|
|
2490
|
+
|
|
2491
|
+
it("answers delegations with a query on the session's model and logs each as a step", async () => {
|
|
2492
|
+
await QgridFrame.liveCall({
|
|
2493
|
+
sdp: "v=0 offer",
|
|
2494
|
+
instructions: "Be a tutor.",
|
|
2495
|
+
delegation: { model: "grok/grok-4.7", effort: "medium", webSearch: true },
|
|
2496
|
+
});
|
|
2497
|
+
dispatcherQueryMock.mockResolvedValueOnce({
|
|
2498
|
+
text: "Here is today's news.",
|
|
2499
|
+
model: "grok-4.7",
|
|
2500
|
+
tokenName: "grok/a",
|
|
2501
|
+
usage: { input_tokens: 10, output_tokens: 5 },
|
|
2502
|
+
costUsd: 0.002,
|
|
2503
|
+
});
|
|
2504
|
+
|
|
2505
|
+
hooks().onTurn([{ role: "user", transcript: "What's new?", startMs: 0, endMs: 1000 }]);
|
|
2506
|
+
const reply = await hooks().onDelegation({ itemId: "item_d", text: "Look up the news" });
|
|
2507
|
+
|
|
2508
|
+
expect(reply).toBe("Here is today's news.");
|
|
2509
|
+
expect(dispatcherQueryMock).toHaveBeenCalledWith(
|
|
2510
|
+
expect.objectContaining({
|
|
2511
|
+
model: "grok/grok-4.7",
|
|
2512
|
+
effort: "medium",
|
|
2513
|
+
webSearch: true,
|
|
2514
|
+
prompt: "Conversation so far:\nuser: What's new?\n\nRequest from the voice assistant:\nLook up the news",
|
|
2515
|
+
system: expect.stringContaining("The voice assistant's instructions:\nBe a tutor."),
|
|
2516
|
+
}),
|
|
2517
|
+
);
|
|
2518
|
+
expect(appendStepMock).toHaveBeenLastCalledWith(
|
|
2519
|
+
77,
|
|
2520
|
+
expect.objectContaining({
|
|
2521
|
+
tool_name: "delegation",
|
|
2522
|
+
tool_call_id: "delegation:item_d",
|
|
2523
|
+
tool_call_index: 1,
|
|
2524
|
+
tool_result: expect.stringContaining("Here is today's news."),
|
|
2525
|
+
}),
|
|
2526
|
+
);
|
|
2527
|
+
|
|
2528
|
+
// The run's cost is the session audio plus every delegation's backend call.
|
|
2529
|
+
endSession({ turns: [], audioDurationMs: 60_000, endReason: "client_request" });
|
|
2530
|
+
await settle();
|
|
2531
|
+
expect(requestLogFinishRunMock).toHaveBeenCalledWith(77, expect.objectContaining({ cost_usd: 52_000 }));
|
|
2532
|
+
});
|
|
2533
|
+
|
|
2534
|
+
it("tells the voice when a delegation fails instead of leaving it waiting", async () => {
|
|
2535
|
+
await QgridFrame.liveCall({ sdp: "v=0 offer" });
|
|
2536
|
+
dispatcherQueryMock.mockRejectedValueOnce(new Error("quota exceeded"));
|
|
2537
|
+
|
|
2538
|
+
const reply = await hooks().onDelegation({ itemId: "item_d", text: "Look up the news" });
|
|
2539
|
+
|
|
2540
|
+
expect(dispatcherQueryMock).toHaveBeenCalledWith(
|
|
2541
|
+
expect.objectContaining({ model: "openai/gpt-6-luna", effort: "low", webSearch: false }),
|
|
2542
|
+
);
|
|
2543
|
+
expect(reply).toContain("could not answer (quota exceeded)");
|
|
2544
|
+
expect(appendStepMock).toHaveBeenLastCalledWith(
|
|
2545
|
+
77,
|
|
2546
|
+
expect.objectContaining({ tool_name: "delegation", error: "quota exceeded" }),
|
|
2547
|
+
);
|
|
2548
|
+
});
|
|
2549
|
+
|
|
2550
|
+
it("rejects an unserved delegation model or anthropic web search before logging or dispatch", async () => {
|
|
2551
|
+
await expect(
|
|
2552
|
+
QgridFrame.liveCall({ sdp: "v=0", delegation: { model: "openai/gpt-5.5" } }),
|
|
2553
|
+
).rejects.toMatchObject({ statusCode: 400 });
|
|
2554
|
+
await expect(
|
|
2555
|
+
QgridFrame.liveCall({
|
|
2556
|
+
sdp: "v=0",
|
|
2557
|
+
delegation: { model: "anthropic/claude-sonnet-5", webSearch: true },
|
|
2558
|
+
}),
|
|
2559
|
+
).rejects.toMatchObject({ statusCode: 400 });
|
|
2560
|
+
expect(requestLogCreateRunMock).not.toHaveBeenCalled();
|
|
2561
|
+
expect(startLive).not.toHaveBeenCalled();
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2564
|
+
it("records a sideband that failed before any turn as an error run", async () => {
|
|
2565
|
+
await QgridFrame.liveCall({ sdp: "v=0 offer", voice: "hanul" });
|
|
2566
|
+
endSession({ turns: [], endReason: "sideband error", error: "handshake rejected with HTTP 404" });
|
|
2567
|
+
await settle();
|
|
2568
|
+
|
|
2569
|
+
expect(requestLogFinishRunMock).toHaveBeenCalledWith(
|
|
2570
|
+
77,
|
|
2571
|
+
expect.objectContaining({ status: "error", error_message: "handshake rejected with HTTP 404" }),
|
|
2572
|
+
);
|
|
2573
|
+
});
|
|
2574
|
+
|
|
2575
|
+
it("rejects any model but openai/gpt-live-1 before logging or dispatch", async () => {
|
|
2576
|
+
await expect(
|
|
2577
|
+
QgridFrame.liveCall({ model: "openai/gpt-realtime-2.1", sdp: "v=0" } as never),
|
|
2578
|
+
).rejects.toMatchObject({ statusCode: 400 });
|
|
2579
|
+
expect(requestLogCreateRunMock).not.toHaveBeenCalled();
|
|
2580
|
+
expect(startLive).not.toHaveBeenCalled();
|
|
2581
|
+
});
|
|
2582
|
+
});
|
|
2583
|
+
|
|
2397
2584
|
it("speak keeps the byte-count placeholder for audio a browser cannot play", async () => {
|
|
2398
2585
|
grok.speak!.mockResolvedValueOnce({
|
|
2399
2586
|
result: { audio: new Uint8Array(6), mediaType: "audio/pcm" },
|