@cartanova/qgrid-cli 2.15.3 → 2.15.5
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.frame.js +168 -12
- package/bundle/dist/application/qgrid/qgrid.types.js +6 -3
- package/bundle/dist/application/request-log/request-log.model.js +4 -3
- package/bundle/dist/application/sonamu.generated.js +20 -5
- package/bundle/dist/application/sonamu.generated.sso.js +5 -3
- package/bundle/dist/i18n/en.js +2 -1
- package/bundle/dist/i18n/ko.js +2 -1
- package/bundle/dist/i18n/sd.generated.js +6 -1
- package/bundle/dist/migrations/20261109110340_alter_request_logs_add1_alter1.js +15 -0
- package/bundle/dist/utils/providers/grok/grok-types.js +1 -1
- package/bundle/dist/utils/providers/grok/grok-voice-client.js +4 -2
- package/bundle/dist/utils/providers/openai/openai-backend-protocol.js +6 -54
- package/bundle/dist/utils/providers/openai/openai-direct-client.js +2 -2
- package/bundle/dist/utils/providers/openai/openai-dispatcher.js +47 -19
- package/bundle/dist/utils/providers/openai/openai-image-generation.js +1 -2
- package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +389 -0
- package/bundle/dist/utils/providers/openai/openai-voice-client.js +460 -0
- package/bundle/src/application/qgrid/qgrid.frame.test.ts +43 -6
- package/bundle/src/application/qgrid/qgrid.frame.ts +246 -14
- package/bundle/src/application/qgrid/qgrid.types.ts +14 -2
- package/bundle/src/application/request-log/request-log.entity.json +17 -2
- package/bundle/src/application/request-log/request-log.model.test.ts +17 -0
- package/bundle/src/application/request-log/request-log.model.ts +11 -3
- package/bundle/src/application/sonamu.generated.http +2 -0
- package/bundle/src/application/sonamu.generated.sso.ts +2 -0
- package/bundle/src/application/sonamu.generated.ts +14 -0
- package/bundle/src/i18n/en.ts +1 -0
- package/bundle/src/i18n/ko.ts +1 -0
- package/bundle/src/i18n/sd.generated.ts +6 -0
- package/bundle/src/migrations/20261109110340_alter_request_logs_add1_alter1.ts +15 -0
- package/bundle/src/utils/providers/grok/grok-types.ts +2 -0
- package/bundle/src/utils/providers/grok/grok-voice-client.test.ts +2 -0
- package/bundle/src/utils/providers/grok/grok-voice-client.ts +2 -0
- package/bundle/src/utils/providers/openai/openai-backend-protocol.test.ts +8 -69
- package/bundle/src/utils/providers/openai/openai-backend-protocol.ts +7 -86
- package/bundle/src/utils/providers/openai/openai-direct-client.test.ts +0 -15
- package/bundle/src/utils/providers/openai/openai-direct-client.ts +3 -1
- package/bundle/src/utils/providers/openai/openai-dispatcher.test.ts +19 -93
- package/bundle/src/utils/providers/openai/openai-dispatcher.ts +98 -47
- package/bundle/src/utils/providers/openai/openai-image-generation.test.ts +6 -4
- package/bundle/src/utils/providers/openai/openai-image-generation.ts +0 -6
- package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +550 -0
- package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +582 -0
- package/bundle/src/utils/providers/openai/openai-voice-client.ts +744 -0
- package/bundle/web-dist/client/assets/index-DyrPRt6O.css +1 -0
- package/bundle/web-dist/client/assets/index-Wi8Wxte6.js +104 -0
- package/bundle/web-dist/client/assets/{logs-Dw-GrMuH.js → logs-Bdg3wJV2.js} +1 -1
- package/bundle/web-dist/client/assets/{monit-BaFFiVKs.js → monit-DcwHRAKu.js} +1 -1
- package/bundle/web-dist/client/assets/{routes-R1xBZYVT.js → routes-lxVC1DDJ.js} +1 -1
- package/bundle/web-dist/client/assets/{settings-Bw_NXAx8.js → settings-C0VCdd1C.js} +1 -1
- package/bundle/web-dist/client/assets/{show-BH7nfFtF.js → show-B7QRPxsY.js} +2 -2
- package/bundle/web-dist/client/assets/{tokens-BPmRr7mD.js → tokens-CNRSm9sc.js} +1 -1
- package/bundle/web-dist/client/assets/{use-oauth-login-flow-B_MGbC3a.js → use-oauth-login-flow-eQnMzp8A.js} +1 -1
- package/bundle/web-dist/client/assets/{use-update-token-mutation-Dcq7Yv2R.js → use-update-token-mutation-KnwyYQjb.js} +1 -1
- package/bundle/web-dist/client/assets/voice-BydIuS0A.js +1 -0
- package/bundle/web-dist/client/index.html +2 -2
- package/bundle/web-dist/client/voice-samples/grok/altair.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/ara.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/atlas.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/aurora.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/carina.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/castor.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/celeste.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/cosmo.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/eve.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/helios.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/helix.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/iris.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/kepler.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/leo.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/liora.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/lumen.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/luna.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/lux.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/naksh.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/orion.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/perseus.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/rex.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/rigel.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/sal.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/sirius.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/ursa.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/zagan.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/grok/zenith.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/alloy.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/ash.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/ballad.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/cedar.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/coral.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/echo.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/marin.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/sage.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/shimmer.mp3 +0 -0
- package/bundle/web-dist/client/voice-samples/openai/verse.mp3 +0 -0
- package/bundle/web-dist/server/assets/link-DrdV092C.js +4919 -0
- package/bundle/web-dist/server/assets/{logs-6289J29J.js → logs-BmBpBe-j.js} +13 -6
- package/bundle/web-dist/server/assets/{monit-YVvwJuAF.js → monit-Db1WrIls.js} +2 -2
- package/bundle/web-dist/server/assets/{plus-z5Hy__3C.js → plus-CW9y_K7l.js} +1 -1
- package/bundle/web-dist/server/assets/{refresh-cw-CNm0CERy.js → refresh-cw-CRgcH5bT.js} +1 -1
- package/bundle/web-dist/server/assets/{request-model-DIuPZZwu.js → request-model-DRF7hmJC.js} +1 -1
- package/bundle/web-dist/server/assets/{routes-DVWRvqn0.js → routes-CARZj7or.js} +4 -4
- package/bundle/web-dist/server/assets/{services.generated-CqS8DCjT.js → services.generated-B6QpnL_N.js} +7 -0
- package/bundle/web-dist/server/assets/{settings-CXwnKiMG.js → settings-B4jdpP5N.js} +4 -4
- package/bundle/web-dist/server/assets/{show-G1t8dOEh.js → show-D8r2sVK0.js} +17 -9
- package/bundle/web-dist/server/assets/{tokens-Di1vDwm5.js → tokens-TDQguTdh.js} +5 -5
- package/bundle/web-dist/server/assets/{use-oauth-login-flow-BUAcW_pK.js → use-oauth-login-flow-du7pOh_H.js} +1 -1
- package/bundle/web-dist/server/assets/{use-update-token-mutation-oH0O0n-g.js → use-update-token-mutation-DA6HiiWS.js} +1 -1
- package/bundle/web-dist/server/assets/voice-C2HfwkGp.js +668 -0
- package/bundle/web-dist/server/entry-server.generated.js +125 -4989
- package/bundle/web-dist/server/voice-samples/grok/altair.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/ara.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/atlas.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/aurora.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/carina.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/castor.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/celeste.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/cosmo.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/eve.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/helios.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/helix.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/iris.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/kepler.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/leo.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/liora.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/lumen.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/luna.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/lux.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/naksh.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/orion.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/perseus.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/rex.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/rigel.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/sal.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/sirius.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/ursa.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/zagan.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/grok/zenith.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/alloy.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/ash.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/ballad.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/cedar.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/coral.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/echo.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/marin.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/sage.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/shimmer.mp3 +0 -0
- package/bundle/web-dist/server/voice-samples/openai/verse.mp3 +0 -0
- package/package.json +1 -1
- package/skills/qgrid/SKILL.md +5 -5
- package/skills/qgrid/references/ai-sdk-provider-contract.md +4 -0
- package/skills/qgrid/references/decision-rationale.md +13 -3
- package/skills/qgrid/references/openai-codex-runtime.md +17 -5
- package/skills/qgrid/references/request-log-run-lifecycle.md +7 -2
- package/skills/qgrid/references/sonamu-api-web-flow.md +6 -2
- package/skills/qgrid/references/verification-and-debugging.md +3 -3
- package/bundle/web-dist/client/assets/index-BakMhnHZ.js +0 -104
- package/bundle/web-dist/client/assets/index-DLo1QCw7.css +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Knex } from "knex";
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
await knex.schema.alterTable("request_logs", (table) => {
|
|
5
|
+
// add
|
|
6
|
+
table.text("media_kind").nullable();
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function down(knex: Knex): Promise<void> {
|
|
11
|
+
await knex.schema.alterTable("request_logs", (table) => {
|
|
12
|
+
// rollback - add
|
|
13
|
+
table.dropColumns("media_kind");
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -364,6 +364,8 @@ export interface GrokTranscribeRequest {
|
|
|
364
364
|
export interface GrokSpeechResult {
|
|
365
365
|
audio: Uint8Array;
|
|
366
366
|
mediaType: string;
|
|
367
|
+
/** Epoch ms when the response headers arrived; /tts is not streamed, so this is first byte. */
|
|
368
|
+
firstByteAt?: number;
|
|
367
369
|
}
|
|
368
370
|
|
|
369
371
|
export interface GrokVoicePort {
|
|
@@ -187,10 +187,12 @@ describe("GrokVoiceClient.speak", () => {
|
|
|
187
187
|
() => new Response(mp3, { status: 200, headers: { "content-type": "audio/mpeg" } }),
|
|
188
188
|
);
|
|
189
189
|
const client = new GrokVoiceClient({ fetch: fake.impl, platform });
|
|
190
|
+
const before = Date.now();
|
|
190
191
|
const result = await client.speak("tok", { text: "hello", voice: "ara" });
|
|
191
192
|
|
|
192
193
|
expect(result.mediaType).toBe("audio/mpeg");
|
|
193
194
|
expect(result.audio).toEqual(mp3);
|
|
195
|
+
expect(result.firstByteAt).toBeGreaterThanOrEqual(before);
|
|
194
196
|
expect(fake.calls).toHaveLength(1);
|
|
195
197
|
const { url, init } = fake.calls[0]!;
|
|
196
198
|
expect(url).toBe("https://api.x.ai/v1/tts");
|
|
@@ -211,6 +211,7 @@ export class GrokVoiceClient implements GrokVoicePort {
|
|
|
211
211
|
};
|
|
212
212
|
|
|
213
213
|
return this.post("/tts", headers, JSON.stringify(body), request.signal, async (response) => {
|
|
214
|
+
const firstByteAt = Date.now();
|
|
214
215
|
const mediaType = contentMediaType(response);
|
|
215
216
|
|
|
216
217
|
if (mediaType === "application/json" || mediaType?.startsWith("text/"))
|
|
@@ -228,6 +229,7 @@ export class GrokVoiceClient implements GrokVoicePort {
|
|
|
228
229
|
return {
|
|
229
230
|
audio,
|
|
230
231
|
mediaType: mediaType ?? MEDIA_TYPE_BY_FORMAT.get(body.format) ?? "application/octet-stream",
|
|
232
|
+
firstByteAt,
|
|
231
233
|
};
|
|
232
234
|
});
|
|
233
235
|
}
|
|
@@ -4,54 +4,23 @@ import {
|
|
|
4
4
|
buildCodexIdentityHeaders,
|
|
5
5
|
buildOpenAIResponsesRequest,
|
|
6
6
|
codexCliUserAgent,
|
|
7
|
+
imageMimeType,
|
|
7
8
|
normalizeOpenAIEvent,
|
|
8
9
|
} from "./openai-backend-protocol";
|
|
9
10
|
|
|
10
11
|
describe("OpenAI Codex backend protocol", () => {
|
|
11
|
-
it.each(["png", "jpeg", "webp"])("preserves reported hosted %s generation settings", (output_format) => {
|
|
12
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
13
|
-
type: "image_generation_call", result: "aGVsbG8=", output_format,
|
|
14
|
-
size: "841x1870", quality: "low", background: "opaque",
|
|
15
|
-
} })).toMatchObject({ generation: {
|
|
16
|
-
route: "codex-responses", size: "841x1870", quality: "low", background: "opaque",
|
|
17
|
-
} });
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("reports PNG byte dimensions instead of a conflicting backend size", () => {
|
|
21
|
-
const bytes = Buffer.alloc(24);
|
|
22
|
-
Buffer.from("89504e470d0a1a0a", "hex").copy(bytes);
|
|
23
|
-
bytes.writeUInt32BE(841, 16);
|
|
24
|
-
bytes.writeUInt32BE(1870, 20);
|
|
25
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
26
|
-
type: "image_generation_call", result: bytes.toString("base64"), size: "1152x2560",
|
|
27
|
-
} })).toMatchObject({ generation: { route: "codex-responses", size: "841x1870" } });
|
|
28
|
-
});
|
|
29
12
|
it("distinguishes partial function items from completed arguments", () => {
|
|
30
13
|
const item = { type: "function_call", call_id: "call", name: "generate_image", arguments: "{}" };
|
|
31
14
|
expect(normalizeOpenAIEvent({ type: "response.output_item.added", item })).toEqual({ type: "output-item", item, completed: false });
|
|
32
15
|
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item })).toEqual({ type: "output-item", item, completed: true });
|
|
33
16
|
});
|
|
34
|
-
it("uses returned bytes rather than a mismatched format label", () => {
|
|
35
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
36
|
-
type: "image_generation_call", result: "UklGRgAAAABXRUJQ", output_format: "png",
|
|
37
|
-
} })).toMatchObject({ mimeType: "image/webp" });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("detects JPEG when the format label is absent", () => {
|
|
41
|
-
expect(normalizeOpenAIEvent({ type: "response.output_item.done", item: {
|
|
42
|
-
type: "image_generation_call", result: "/9j/",
|
|
43
|
-
} })).toMatchObject({ mimeType: "image/jpeg" });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
17
|
it.each([
|
|
47
|
-
["
|
|
48
|
-
["
|
|
49
|
-
["
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
item: { type: "image_generation_call", result, output_format: format },
|
|
54
|
-
})).toMatchObject({ type: "image", mimeType });
|
|
18
|
+
["iVBORw0KGgo=", "jpeg", "image/png"],
|
|
19
|
+
["UklGRgAAAABXRUJQ", "png", "image/webp"],
|
|
20
|
+
["/9j/", undefined, "image/jpeg"],
|
|
21
|
+
["aGVsbG8=", "webp", "image/webp"],
|
|
22
|
+
])("detects history image MIME from bytes before the format label: %s", (base64, format, mimeType) => {
|
|
23
|
+
expect(imageMimeType(base64, format)).toBe(mimeType);
|
|
55
24
|
});
|
|
56
25
|
|
|
57
26
|
it("preserves raw history and pins Responses controls", () => {
|
|
@@ -64,13 +33,11 @@ describe("OpenAI Codex backend protocol", () => {
|
|
|
64
33
|
serviceTier: "priority",
|
|
65
34
|
promptCacheKey: "thread-1",
|
|
66
35
|
outputSchema: { schema: { type: "object", additionalProperties: false } },
|
|
67
|
-
imageGeneration: true,
|
|
68
36
|
});
|
|
69
37
|
|
|
70
38
|
expect(request).toEqual({
|
|
71
39
|
model: "gpt-5.2-codex",
|
|
72
40
|
input: history,
|
|
73
|
-
tools: [{ type: "image_generation" }],
|
|
74
41
|
tool_choice: "auto",
|
|
75
42
|
parallel_tool_calls: true,
|
|
76
43
|
reasoning: { effort: "high", summary: "auto" },
|
|
@@ -122,7 +89,7 @@ describe("OpenAI Codex backend protocol", () => {
|
|
|
122
89
|
});
|
|
123
90
|
});
|
|
124
91
|
|
|
125
|
-
it("normalizes usage
|
|
92
|
+
it("normalizes usage", () => {
|
|
126
93
|
expect(
|
|
127
94
|
normalizeOpenAIEvent({
|
|
128
95
|
type: "response.completed",
|
|
@@ -142,33 +109,5 @@ describe("OpenAI Codex backend protocol", () => {
|
|
|
142
109
|
responseId: "r1",
|
|
143
110
|
usage: { inputTokens: 4, cachedInputTokens: 2, outputTokens: 3, reasoningTokens: 1, totalTokens: 7 },
|
|
144
111
|
});
|
|
145
|
-
expect(
|
|
146
|
-
normalizeOpenAIEvent({
|
|
147
|
-
type: "response.output_item.done",
|
|
148
|
-
item: { type: "image_generation_call", id: "img", result: "aGVsbG8=", revised_prompt: "better" },
|
|
149
|
-
}),
|
|
150
|
-
).toEqual({ type: "image", id: "img", base64: "aGVsbG8=", mimeType: "image/png", revisedPrompt: "better", generation: { route: "codex-responses" } });
|
|
151
112
|
});
|
|
152
|
-
|
|
153
|
-
it("preserves zero image-tool usage without treating it as missing", () => {
|
|
154
|
-
const usage = { input_tokens: 0, output_tokens: 0, total_tokens: 0 };
|
|
155
|
-
expect(normalizeOpenAIEvent({ type: "response.completed", response: {
|
|
156
|
-
id: "r", tool_usage: { image_gen: usage },
|
|
157
|
-
} })).toEqual({
|
|
158
|
-
type: "completed", responseId: "r",
|
|
159
|
-
imageGeneration: { route: "codex-responses", usage },
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it.each([undefined, null, {}, { input_tokens: "4", output_tokens: 1, total_tokens: 5 }, { input_tokens: -1, output_tokens: 1, total_tokens: 0 }])(
|
|
164
|
-
"ignores missing or malformed image-tool usage: %j", (usage) => {
|
|
165
|
-
expect(normalizeOpenAIEvent({ type: "response.completed", response: {
|
|
166
|
-
id: "r", tool_usage: { image_gen: usage },
|
|
167
|
-
tools: [{ type: "image_generation", model: "gpt-image-2-codex", size: "auto", quality: "auto" }],
|
|
168
|
-
} })).toEqual({
|
|
169
|
-
type: "completed", responseId: "r",
|
|
170
|
-
imageGeneration: { route: "codex-responses", model: "gpt-image-2-codex" },
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
113
|
});
|
|
@@ -2,7 +2,7 @@ import os from "node:os";
|
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
|
-
import { ImageGenerationMetadata } from "../../../application/qgrid/qgrid.types";
|
|
5
|
+
import { type ImageGenerationMetadata } from "../../../application/qgrid/qgrid.types";
|
|
6
6
|
import { type OpenAIEffort } from "../common/effort";
|
|
7
7
|
import {
|
|
8
8
|
isJsonObject,
|
|
@@ -73,6 +73,7 @@ export interface OpenAIResponsesOptions {
|
|
|
73
73
|
serviceTier?: string;
|
|
74
74
|
promptCacheKey?: string;
|
|
75
75
|
outputSchema?: OpenAIOutputSchema;
|
|
76
|
+
/** Sends the request to standalone Images instead of Responses; see `OpenAIDirectClient`. */
|
|
76
77
|
imageGeneration?: boolean | OpenAIResponseItem;
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -107,14 +108,6 @@ export function buildOpenAIResponsesRequest(
|
|
|
107
108
|
): OpenAIResponsesRequest {
|
|
108
109
|
const tools = options.tools ? [...options.tools] : [];
|
|
109
110
|
|
|
110
|
-
if (options.imageGeneration) {
|
|
111
|
-
tools.push(
|
|
112
|
-
options.imageGeneration === true
|
|
113
|
-
? { type: "image_generation" }
|
|
114
|
-
: { type: "image_generation", ...options.imageGeneration },
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
111
|
const request: OpenAIResponsesRequest = {
|
|
119
112
|
model: options.model,
|
|
120
113
|
// Copy the array, not its items: raw items must arrive byte-for-byte equivalent.
|
|
@@ -216,7 +209,6 @@ export type OpenAINormalizedEvent =
|
|
|
216
209
|
responseId: string;
|
|
217
210
|
usage?: OpenAIUsage;
|
|
218
211
|
model?: string;
|
|
219
|
-
imageGeneration?: ImageGenerationMetadata;
|
|
220
212
|
}
|
|
221
213
|
| { type: "error"; error: OpenAIProtocolError };
|
|
222
214
|
|
|
@@ -275,68 +267,9 @@ export function imageMimeType(
|
|
|
275
267
|
throw new OpenAIProtocolError(`Unsupported image output format: ${label}`);
|
|
276
268
|
}
|
|
277
269
|
|
|
278
|
-
type OpenAIImageEvent = Extract<OpenAINormalizedEvent, { type: "image" }>;
|
|
279
|
-
|
|
280
|
-
function imageEvent(item: JsonObject, result: string): OpenAIImageEvent {
|
|
281
|
-
// PNG exposes dimensions in its fixed header. Other formats retain the
|
|
282
|
-
// backend's observed size; never substitute requested image controls.
|
|
283
|
-
const header = Buffer.from(result.slice(0, 32), "base64");
|
|
284
|
-
|
|
285
|
-
const pngSize =
|
|
286
|
-
header.length >= 24 &&
|
|
287
|
-
header.subarray(0, 8).equals(Buffer.from("89504e470d0a1a0a", "hex")) &&
|
|
288
|
-
header.readUInt32BE(16) > 0 &&
|
|
289
|
-
header.readUInt32BE(20) > 0
|
|
290
|
-
? `${header.readUInt32BE(16)}x${header.readUInt32BE(20)}`
|
|
291
|
-
: undefined;
|
|
292
|
-
|
|
293
|
-
const reportedSize = jsonString(item.size);
|
|
294
|
-
|
|
295
|
-
const size =
|
|
296
|
-
pngSize ??
|
|
297
|
-
(reportedSize !== undefined && /^[1-9]\d*x[1-9]\d*$/.test(reportedSize)
|
|
298
|
-
? reportedSize
|
|
299
|
-
: undefined);
|
|
300
|
-
|
|
301
|
-
const id = jsonString(item.id);
|
|
302
|
-
const model = jsonString(item.model);
|
|
303
|
-
const quality = jsonString(item.quality);
|
|
304
|
-
const background = jsonString(item.background);
|
|
305
|
-
const revisedPrompt = jsonString(item.revised_prompt) ?? jsonString(item.revisedPrompt);
|
|
306
|
-
const generation: ImageGenerationMetadata = { route: "codex-responses" };
|
|
307
|
-
|
|
308
|
-
if (size) generation.size = size;
|
|
309
|
-
|
|
310
|
-
if (model !== undefined) generation.model = model;
|
|
311
|
-
|
|
312
|
-
if (quality !== undefined) generation.quality = quality;
|
|
313
|
-
|
|
314
|
-
if (background !== undefined) generation.background = background;
|
|
315
|
-
|
|
316
|
-
const event: OpenAIImageEvent = { type: "image", base64: result, mimeType: "image/png" };
|
|
317
|
-
|
|
318
|
-
if (id !== undefined) event.id = id;
|
|
319
|
-
event.base64 = result;
|
|
320
|
-
event.mimeType = imageMimeType(result, item.output_format);
|
|
321
|
-
event.generation = generation;
|
|
322
|
-
|
|
323
|
-
if (revisedPrompt !== undefined) event.revisedPrompt = revisedPrompt;
|
|
324
|
-
|
|
325
|
-
return event;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
270
|
type OpenAICompletedEvent = Extract<OpenAINormalizedEvent, { type: "completed" }>;
|
|
329
271
|
|
|
330
272
|
function completedEvent(response: JsonObject): OpenAICompletedEvent {
|
|
331
|
-
const toolUsage = jsonObjectOrEmpty(response.tool_usage);
|
|
332
|
-
const parsedImageUsage = ImageGenerationMetadata.shape.usage.safeParse(toolUsage.image_gen);
|
|
333
|
-
const imageUsage = parsedImageUsage.success ? parsedImageUsage.data : undefined;
|
|
334
|
-
|
|
335
|
-
const imageTool = Array.isArray(response.tools)
|
|
336
|
-
? response.tools.find((tool) => isJsonObject(tool) && tool.type === "image_generation")
|
|
337
|
-
: undefined;
|
|
338
|
-
|
|
339
|
-
const imageModel = isJsonObject(imageTool) ? jsonString(imageTool.model) : undefined;
|
|
340
273
|
const model = jsonString(response.model);
|
|
341
274
|
|
|
342
275
|
const event: OpenAICompletedEvent = {
|
|
@@ -348,15 +281,6 @@ function completedEvent(response: JsonObject): OpenAICompletedEvent {
|
|
|
348
281
|
|
|
349
282
|
if (model !== undefined) event.model = model;
|
|
350
283
|
|
|
351
|
-
if (imageUsage || imageModel) {
|
|
352
|
-
const imageGeneration: ImageGenerationMetadata = { route: "codex-responses" };
|
|
353
|
-
|
|
354
|
-
if (imageModel) imageGeneration.model = imageModel;
|
|
355
|
-
|
|
356
|
-
if (imageUsage) imageGeneration.usage = imageUsage;
|
|
357
|
-
event.imageGeneration = imageGeneration;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
284
|
return event;
|
|
361
285
|
}
|
|
362
286
|
|
|
@@ -385,14 +309,11 @@ export function normalizeOpenAIEvent(raw: JsonValue): OpenAINormalizedEvent | un
|
|
|
385
309
|
(type === "response.output_item.added" || type === "response.output_item.done") &&
|
|
386
310
|
isJsonObject(event.item)
|
|
387
311
|
) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return { type: "output-item", item, completed: type === "response.output_item.done" };
|
|
312
|
+
return {
|
|
313
|
+
type: "output-item",
|
|
314
|
+
item: event.item,
|
|
315
|
+
completed: type === "response.output_item.done",
|
|
316
|
+
};
|
|
396
317
|
}
|
|
397
318
|
|
|
398
319
|
if (type === "response.completed") return completedEvent(jsonObjectOrEmpty(event.response));
|
|
@@ -33,21 +33,6 @@ async function collect<T>(iterable: AsyncIterable<T>): Promise<T[]> {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
describe("OpenAI direct HTTPS client", () => {
|
|
36
|
-
it.each([true, { background: "opaque" }])("keeps chat-model images on Responses (%j)", async (imageGeneration) => {
|
|
37
|
-
const fetchMock = vi.fn<typeof fetch>(async () =>
|
|
38
|
-
sse({ type: "response.completed", response: { id: "hosted-image" } }),
|
|
39
|
-
);
|
|
40
|
-
const client = new OpenAIDirectClient({
|
|
41
|
-
credentials: { accessToken: "access", accountId: "acct" }, fetch: fetchMock,
|
|
42
|
-
});
|
|
43
|
-
await collect(client.responses({ model: "gpt-6-luna", history: [], imageGeneration }));
|
|
44
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
45
|
-
expect(fetchMock.mock.calls[0]?.[0]).toBe(CHATGPT_CODEX_RESPONSES_URL);
|
|
46
|
-
expect(JSON.parse(String(fetchMock.mock.calls[0]?.[1]?.body))).toMatchObject({
|
|
47
|
-
model: "gpt-6-luna", tools: [expect.objectContaining({ type: "image_generation" })],
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
36
|
it("posts the pinned body and Codex identity without live calls", async () => {
|
|
52
37
|
const fetchMock = vi.fn<typeof fetch>(async () =>
|
|
53
38
|
sse(
|
|
@@ -535,7 +535,9 @@ export class OpenAIDirectClient {
|
|
|
535
535
|
}
|
|
536
536
|
|
|
537
537
|
responses(options: OpenAIResponsesOptions, signal?: AbortSignal): OpenAIEventStream {
|
|
538
|
-
|
|
538
|
+
// Hosted Responses image tools turn driver reasoning effort into an unsupported
|
|
539
|
+
// `complexity` (2026-11-09 probe), so every image request uses standalone Images.
|
|
540
|
+
if (options.model === "gpt-image-2" || options.imageGeneration) {
|
|
539
541
|
return this.standaloneImages(options, signal);
|
|
540
542
|
}
|
|
541
543
|
|
|
@@ -127,17 +127,27 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
127
127
|
expect(run).toHaveBeenCalledOnce();
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
-
it.each([
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
it.each([
|
|
131
|
+
{ background: "transparent", size: "1024x1024" },
|
|
132
|
+
{ background: "opaque", size: "1152x2560" },
|
|
133
|
+
{ background: "auto", size: "auto" },
|
|
134
|
+
] as const)("passes explicit chat-model image controls to standalone Images: %j", async (controls) => {
|
|
135
|
+
const args = QueryInput.parse({
|
|
136
|
+
model: "openai/gpt-test", prompt: "an isolated red circle", imageGeneration: true,
|
|
137
|
+
imageGenerationOptions: { ...controls, quality: "high", outputFormat: "png" },
|
|
138
|
+
});
|
|
139
|
+
const generation = { route: "codex-images" as const, model: "gpt-image-2", size: "841x1870", quality: "low" };
|
|
140
|
+
let received: OpenAIResponsesOptions | undefined;
|
|
133
141
|
const d = dispatcher((options) => {
|
|
134
|
-
|
|
135
|
-
return events({ type: "image", base64: "
|
|
142
|
+
received = options;
|
|
143
|
+
return events({ type: "image", base64: "png", mimeType: "image/png", generation }, { type: "completed", responseId: "r", model: "gpt-image-2" });
|
|
136
144
|
});
|
|
137
145
|
await d.onTokenAdded(1, "one", credentials);
|
|
138
146
|
const result = await d.generate(request({ imageGeneration: args.imageGeneration, imageGenerationOptions: args.imageGenerationOptions }));
|
|
139
|
-
|
|
140
|
-
expect(
|
|
147
|
+
const direct = buildStandaloneImageRequest(received!);
|
|
148
|
+
expect(direct.url).toMatch(/\/images\/generations$/);
|
|
149
|
+
expect(direct.body).toMatchObject({ model: "gpt-image-2", ...controls, quality: "high" });
|
|
150
|
+
expect(result).toMatchObject({ model: "gpt-image-2", requestedModel: "gpt-test", images: [{ mediaType: "image/png", generation }] });
|
|
141
151
|
});
|
|
142
152
|
|
|
143
153
|
it("rejects unsupported output formats and non-PNG transparent requests", () => {
|
|
@@ -146,18 +156,6 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
146
156
|
}
|
|
147
157
|
});
|
|
148
158
|
|
|
149
|
-
it.each(["auto", "1152x2560"])("forwards %s size hints and preserves hosted observations", async (size) => {
|
|
150
|
-
const args = QueryInput.parse({ prompt: "draw in 9:20", imageGeneration: true, imageGenerationOptions: { size } });
|
|
151
|
-
const generation = { route: "codex-responses" as const, size: "841x1870", quality: "low" };
|
|
152
|
-
const d = dispatcher((options) => {
|
|
153
|
-
expect(buildOpenAIResponsesRequest(options).tools).toContainEqual({ type: "image_generation", size });
|
|
154
|
-
return events({ type: "image", base64: "data", mimeType: "image/png", generation }, { type: "completed", responseId: "r" });
|
|
155
|
-
});
|
|
156
|
-
await d.onTokenAdded(1, "one", credentials);
|
|
157
|
-
const result = await d.generate(request({ imageGeneration: args.imageGeneration, imageGenerationOptions: args.imageGenerationOptions }));
|
|
158
|
-
expect(result.images).toMatchObject([{ generation }]);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
159
|
beforeEach(() => { refreshMock.mockReset(); });
|
|
162
160
|
|
|
163
161
|
it("refreshes a quota 401 once, shares the recovery, and uses the new credentials", async () => {
|
|
@@ -253,34 +251,6 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
253
251
|
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
254
252
|
});
|
|
255
253
|
|
|
256
|
-
it.each(["transparent", "opaque", "auto"] as const)(
|
|
257
|
-
"preserves %s background through validation and Responses serialization",
|
|
258
|
-
async (background) => {
|
|
259
|
-
const args = QueryInput.parse({
|
|
260
|
-
model: "openai/gpt-test",
|
|
261
|
-
prompt: "an isolated red circle",
|
|
262
|
-
imageGeneration: true,
|
|
263
|
-
imageGenerationOptions: { background, quality: "high", size: "1024x1024" },
|
|
264
|
-
});
|
|
265
|
-
let body: ReturnType<typeof buildOpenAIResponsesRequest> | undefined;
|
|
266
|
-
const d = dispatcher((options) => {
|
|
267
|
-
body = buildOpenAIResponsesRequest(options);
|
|
268
|
-
return events(
|
|
269
|
-
{ type: "image", id: "i", base64: "png", mimeType: "image/png" },
|
|
270
|
-
{ type: "completed", responseId: "r" },
|
|
271
|
-
);
|
|
272
|
-
});
|
|
273
|
-
await d.onTokenAdded(1, "one", credentials);
|
|
274
|
-
await d.generate(request({
|
|
275
|
-
imageGeneration: args.imageGeneration,
|
|
276
|
-
imageGenerationOptions: args.imageGenerationOptions,
|
|
277
|
-
}));
|
|
278
|
-
expect(body?.tools).toEqual([{
|
|
279
|
-
type: "image_generation", background, quality: "high", size: "1024x1024",
|
|
280
|
-
}]);
|
|
281
|
-
},
|
|
282
|
-
);
|
|
283
|
-
|
|
284
254
|
it("rejects unsupported image backgrounds", () => {
|
|
285
255
|
expect(QueryInput.safeParse({
|
|
286
256
|
prompt: "a circle", imageGeneration: true,
|
|
@@ -418,7 +388,7 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
418
388
|
expect(onError).toHaveBeenCalledWith(failure);
|
|
419
389
|
});
|
|
420
390
|
|
|
421
|
-
it("returns multiple
|
|
391
|
+
it("returns multiple images from one image request", async () => {
|
|
422
392
|
const run = vi.fn(() => events(
|
|
423
393
|
{ type: "image", id: "first", base64: "first", mimeType: "image/png" },
|
|
424
394
|
{ type: "image", id: "second", base64: "second", mimeType: "image/webp" },
|
|
@@ -431,47 +401,6 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
431
401
|
expect(run).toHaveBeenCalledTimes(1);
|
|
432
402
|
});
|
|
433
403
|
|
|
434
|
-
it.each([true, false])("preserves aggregate hosted image usage separately from driver usage (driver usage: %s)", async (withDriverUsage) => {
|
|
435
|
-
const imageUsage = {
|
|
436
|
-
input_tokens: 2260,
|
|
437
|
-
input_tokens_details: { image_tokens: 2012, text_tokens: 248 },
|
|
438
|
-
output_tokens: 1415,
|
|
439
|
-
output_tokens_details: { image_tokens: 1415, text_tokens: 0 },
|
|
440
|
-
total_tokens: 3675,
|
|
441
|
-
};
|
|
442
|
-
const rawEvents = [
|
|
443
|
-
...["first", "second"].map((id) => ({ type: "response.output_item.done", item: {
|
|
444
|
-
id, type: "image_generation_call", result: "UklGRgAAAABXRUJQ",
|
|
445
|
-
size: "1037x1516", quality: "medium", background: "opaque", output_format: "webp",
|
|
446
|
-
} })),
|
|
447
|
-
{ type: "response.completed", response: {
|
|
448
|
-
id: "r", model: "gpt-6-luna",
|
|
449
|
-
...(withDriverUsage ? { usage: { input_tokens: 10, output_tokens: 3, total_tokens: 13 } } : {}),
|
|
450
|
-
tool_usage: { image_gen: imageUsage },
|
|
451
|
-
tools: [{ type: "image_generation", model: "gpt-image-2-codex", quality: "auto", size: "auto", background: "auto", output_format: "webp", n: 1 }],
|
|
452
|
-
} },
|
|
453
|
-
];
|
|
454
|
-
const d = dispatcher((options) => {
|
|
455
|
-
expect(buildOpenAIResponsesRequest(options).tools).toEqual([{
|
|
456
|
-
type: "image_generation", quality: "high", size: "1024x1536", output_format: "webp",
|
|
457
|
-
}]);
|
|
458
|
-
return events(...rawEvents.map(normalizeOpenAIEvent).filter((event): event is OpenAINormalizedEvent => event !== undefined));
|
|
459
|
-
});
|
|
460
|
-
await d.onTokenAdded(1, "one", credentials);
|
|
461
|
-
const result = await d.generate(request({ model: "gpt-6-luna", imageGeneration: true,
|
|
462
|
-
imageGenerationOptions: { quality: "high", size: "1024x1536", outputFormat: "webp" },
|
|
463
|
-
}));
|
|
464
|
-
expect(result.usage).toMatchObject({
|
|
465
|
-
inputTokens: withDriverUsage ? 10 : 0,
|
|
466
|
-
outputTokens: withDriverUsage ? 3 : 0,
|
|
467
|
-
totalTokens: withDriverUsage ? 13 : 0,
|
|
468
|
-
});
|
|
469
|
-
const generation = { route: "codex-responses", model: "gpt-image-2-codex", size: "1037x1516", quality: "medium", background: "opaque" };
|
|
470
|
-
expect(result.images?.map((image) => image.generation)).toEqual([
|
|
471
|
-
{ ...generation, usage: imageUsage }, generation,
|
|
472
|
-
]);
|
|
473
|
-
});
|
|
474
|
-
|
|
475
404
|
it("registers only the internal image function and allows text-only replies", async () => {
|
|
476
405
|
const run = vi.fn((options: OpenAIResponsesOptions) => {
|
|
477
406
|
const body = buildOpenAIResponsesRequest(options);
|
|
@@ -500,7 +429,7 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
500
429
|
expect(result.images).toBeUndefined();
|
|
501
430
|
});
|
|
502
431
|
|
|
503
|
-
it.each(["zero-usage", "model-config"])("
|
|
432
|
+
it.each(["zero-usage", "model-config"])("keeps automatic text-only replies when completed responses carry %s image metadata", async (metadata) => {
|
|
504
433
|
const completed = normalizeOpenAIEvent({
|
|
505
434
|
type: "response.completed",
|
|
506
435
|
response: {
|
|
@@ -517,7 +446,6 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
517
446
|
output: [{ type: "message" }],
|
|
518
447
|
},
|
|
519
448
|
});
|
|
520
|
-
expect(completed).toMatchObject({ type: "completed", imageGeneration: { route: "codex-responses" } });
|
|
521
449
|
const run = vi.fn(() => events({ type: "text-delta", text: "hello" }, completed!));
|
|
522
450
|
const d = dispatcher(run);
|
|
523
451
|
await d.onTokenAdded(1, "one", credentials);
|
|
@@ -613,8 +541,6 @@ describe("OpenAIDispatcher direct runtime", () => {
|
|
|
613
541
|
[{ ...done, item: { ...item, call_id: "" } }],
|
|
614
542
|
[{ ...done, item: { ...item, name: "unexpected" } }],
|
|
615
543
|
[done, { type: "image", base64: "png", mimeType: "image/png" }],
|
|
616
|
-
[{ type: "output-item", item: { type: "image_generation_call" }, completed: false }],
|
|
617
|
-
[{ type: "completed", responseId: "native", imageGeneration: { route: "codex-responses", usage: { input_tokens: 1, output_tokens: 0, total_tokens: 1 } } }],
|
|
618
544
|
];
|
|
619
545
|
for (const stream of badEvents) {
|
|
620
546
|
const run = vi.fn(() => events(...stream, { type: "completed", responseId: "driver" }));
|