@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.
Files changed (157) hide show
  1. package/bundle/dist/application/qgrid/qgrid.frame.js +168 -12
  2. package/bundle/dist/application/qgrid/qgrid.types.js +6 -3
  3. package/bundle/dist/application/request-log/request-log.model.js +4 -3
  4. package/bundle/dist/application/sonamu.generated.js +20 -5
  5. package/bundle/dist/application/sonamu.generated.sso.js +5 -3
  6. package/bundle/dist/i18n/en.js +2 -1
  7. package/bundle/dist/i18n/ko.js +2 -1
  8. package/bundle/dist/i18n/sd.generated.js +6 -1
  9. package/bundle/dist/migrations/20261109110340_alter_request_logs_add1_alter1.js +15 -0
  10. package/bundle/dist/utils/providers/grok/grok-types.js +1 -1
  11. package/bundle/dist/utils/providers/grok/grok-voice-client.js +4 -2
  12. package/bundle/dist/utils/providers/openai/openai-backend-protocol.js +6 -54
  13. package/bundle/dist/utils/providers/openai/openai-direct-client.js +2 -2
  14. package/bundle/dist/utils/providers/openai/openai-dispatcher.js +47 -19
  15. package/bundle/dist/utils/providers/openai/openai-image-generation.js +1 -2
  16. package/bundle/dist/utils/providers/openai/openai-realtime-protocol.js +389 -0
  17. package/bundle/dist/utils/providers/openai/openai-voice-client.js +460 -0
  18. package/bundle/src/application/qgrid/qgrid.frame.test.ts +43 -6
  19. package/bundle/src/application/qgrid/qgrid.frame.ts +246 -14
  20. package/bundle/src/application/qgrid/qgrid.types.ts +14 -2
  21. package/bundle/src/application/request-log/request-log.entity.json +17 -2
  22. package/bundle/src/application/request-log/request-log.model.test.ts +17 -0
  23. package/bundle/src/application/request-log/request-log.model.ts +11 -3
  24. package/bundle/src/application/sonamu.generated.http +2 -0
  25. package/bundle/src/application/sonamu.generated.sso.ts +2 -0
  26. package/bundle/src/application/sonamu.generated.ts +14 -0
  27. package/bundle/src/i18n/en.ts +1 -0
  28. package/bundle/src/i18n/ko.ts +1 -0
  29. package/bundle/src/i18n/sd.generated.ts +6 -0
  30. package/bundle/src/migrations/20261109110340_alter_request_logs_add1_alter1.ts +15 -0
  31. package/bundle/src/utils/providers/grok/grok-types.ts +2 -0
  32. package/bundle/src/utils/providers/grok/grok-voice-client.test.ts +2 -0
  33. package/bundle/src/utils/providers/grok/grok-voice-client.ts +2 -0
  34. package/bundle/src/utils/providers/openai/openai-backend-protocol.test.ts +8 -69
  35. package/bundle/src/utils/providers/openai/openai-backend-protocol.ts +7 -86
  36. package/bundle/src/utils/providers/openai/openai-direct-client.test.ts +0 -15
  37. package/bundle/src/utils/providers/openai/openai-direct-client.ts +3 -1
  38. package/bundle/src/utils/providers/openai/openai-dispatcher.test.ts +19 -93
  39. package/bundle/src/utils/providers/openai/openai-dispatcher.ts +98 -47
  40. package/bundle/src/utils/providers/openai/openai-image-generation.test.ts +6 -4
  41. package/bundle/src/utils/providers/openai/openai-image-generation.ts +0 -6
  42. package/bundle/src/utils/providers/openai/openai-realtime-protocol.ts +550 -0
  43. package/bundle/src/utils/providers/openai/openai-voice-client.test.ts +582 -0
  44. package/bundle/src/utils/providers/openai/openai-voice-client.ts +744 -0
  45. package/bundle/web-dist/client/assets/index-DyrPRt6O.css +1 -0
  46. package/bundle/web-dist/client/assets/index-Wi8Wxte6.js +104 -0
  47. package/bundle/web-dist/client/assets/{logs-Dw-GrMuH.js → logs-Bdg3wJV2.js} +1 -1
  48. package/bundle/web-dist/client/assets/{monit-BaFFiVKs.js → monit-DcwHRAKu.js} +1 -1
  49. package/bundle/web-dist/client/assets/{routes-R1xBZYVT.js → routes-lxVC1DDJ.js} +1 -1
  50. package/bundle/web-dist/client/assets/{settings-Bw_NXAx8.js → settings-C0VCdd1C.js} +1 -1
  51. package/bundle/web-dist/client/assets/{show-BH7nfFtF.js → show-B7QRPxsY.js} +2 -2
  52. package/bundle/web-dist/client/assets/{tokens-BPmRr7mD.js → tokens-CNRSm9sc.js} +1 -1
  53. package/bundle/web-dist/client/assets/{use-oauth-login-flow-B_MGbC3a.js → use-oauth-login-flow-eQnMzp8A.js} +1 -1
  54. package/bundle/web-dist/client/assets/{use-update-token-mutation-Dcq7Yv2R.js → use-update-token-mutation-KnwyYQjb.js} +1 -1
  55. package/bundle/web-dist/client/assets/voice-BydIuS0A.js +1 -0
  56. package/bundle/web-dist/client/index.html +2 -2
  57. package/bundle/web-dist/client/voice-samples/grok/altair.mp3 +0 -0
  58. package/bundle/web-dist/client/voice-samples/grok/ara.mp3 +0 -0
  59. package/bundle/web-dist/client/voice-samples/grok/atlas.mp3 +0 -0
  60. package/bundle/web-dist/client/voice-samples/grok/aurora.mp3 +0 -0
  61. package/bundle/web-dist/client/voice-samples/grok/carina.mp3 +0 -0
  62. package/bundle/web-dist/client/voice-samples/grok/castor.mp3 +0 -0
  63. package/bundle/web-dist/client/voice-samples/grok/celeste.mp3 +0 -0
  64. package/bundle/web-dist/client/voice-samples/grok/cosmo.mp3 +0 -0
  65. package/bundle/web-dist/client/voice-samples/grok/eve.mp3 +0 -0
  66. package/bundle/web-dist/client/voice-samples/grok/helios.mp3 +0 -0
  67. package/bundle/web-dist/client/voice-samples/grok/helix.mp3 +0 -0
  68. package/bundle/web-dist/client/voice-samples/grok/iris.mp3 +0 -0
  69. package/bundle/web-dist/client/voice-samples/grok/kepler.mp3 +0 -0
  70. package/bundle/web-dist/client/voice-samples/grok/leo.mp3 +0 -0
  71. package/bundle/web-dist/client/voice-samples/grok/liora.mp3 +0 -0
  72. package/bundle/web-dist/client/voice-samples/grok/lumen.mp3 +0 -0
  73. package/bundle/web-dist/client/voice-samples/grok/luna.mp3 +0 -0
  74. package/bundle/web-dist/client/voice-samples/grok/lux.mp3 +0 -0
  75. package/bundle/web-dist/client/voice-samples/grok/naksh.mp3 +0 -0
  76. package/bundle/web-dist/client/voice-samples/grok/orion.mp3 +0 -0
  77. package/bundle/web-dist/client/voice-samples/grok/perseus.mp3 +0 -0
  78. package/bundle/web-dist/client/voice-samples/grok/rex.mp3 +0 -0
  79. package/bundle/web-dist/client/voice-samples/grok/rigel.mp3 +0 -0
  80. package/bundle/web-dist/client/voice-samples/grok/sal.mp3 +0 -0
  81. package/bundle/web-dist/client/voice-samples/grok/sirius.mp3 +0 -0
  82. package/bundle/web-dist/client/voice-samples/grok/ursa.mp3 +0 -0
  83. package/bundle/web-dist/client/voice-samples/grok/zagan.mp3 +0 -0
  84. package/bundle/web-dist/client/voice-samples/grok/zenith.mp3 +0 -0
  85. package/bundle/web-dist/client/voice-samples/openai/alloy.mp3 +0 -0
  86. package/bundle/web-dist/client/voice-samples/openai/ash.mp3 +0 -0
  87. package/bundle/web-dist/client/voice-samples/openai/ballad.mp3 +0 -0
  88. package/bundle/web-dist/client/voice-samples/openai/cedar.mp3 +0 -0
  89. package/bundle/web-dist/client/voice-samples/openai/coral.mp3 +0 -0
  90. package/bundle/web-dist/client/voice-samples/openai/echo.mp3 +0 -0
  91. package/bundle/web-dist/client/voice-samples/openai/marin.mp3 +0 -0
  92. package/bundle/web-dist/client/voice-samples/openai/sage.mp3 +0 -0
  93. package/bundle/web-dist/client/voice-samples/openai/shimmer.mp3 +0 -0
  94. package/bundle/web-dist/client/voice-samples/openai/verse.mp3 +0 -0
  95. package/bundle/web-dist/server/assets/link-DrdV092C.js +4919 -0
  96. package/bundle/web-dist/server/assets/{logs-6289J29J.js → logs-BmBpBe-j.js} +13 -6
  97. package/bundle/web-dist/server/assets/{monit-YVvwJuAF.js → monit-Db1WrIls.js} +2 -2
  98. package/bundle/web-dist/server/assets/{plus-z5Hy__3C.js → plus-CW9y_K7l.js} +1 -1
  99. package/bundle/web-dist/server/assets/{refresh-cw-CNm0CERy.js → refresh-cw-CRgcH5bT.js} +1 -1
  100. package/bundle/web-dist/server/assets/{request-model-DIuPZZwu.js → request-model-DRF7hmJC.js} +1 -1
  101. package/bundle/web-dist/server/assets/{routes-DVWRvqn0.js → routes-CARZj7or.js} +4 -4
  102. package/bundle/web-dist/server/assets/{services.generated-CqS8DCjT.js → services.generated-B6QpnL_N.js} +7 -0
  103. package/bundle/web-dist/server/assets/{settings-CXwnKiMG.js → settings-B4jdpP5N.js} +4 -4
  104. package/bundle/web-dist/server/assets/{show-G1t8dOEh.js → show-D8r2sVK0.js} +17 -9
  105. package/bundle/web-dist/server/assets/{tokens-Di1vDwm5.js → tokens-TDQguTdh.js} +5 -5
  106. package/bundle/web-dist/server/assets/{use-oauth-login-flow-BUAcW_pK.js → use-oauth-login-flow-du7pOh_H.js} +1 -1
  107. package/bundle/web-dist/server/assets/{use-update-token-mutation-oH0O0n-g.js → use-update-token-mutation-DA6HiiWS.js} +1 -1
  108. package/bundle/web-dist/server/assets/voice-C2HfwkGp.js +668 -0
  109. package/bundle/web-dist/server/entry-server.generated.js +125 -4989
  110. package/bundle/web-dist/server/voice-samples/grok/altair.mp3 +0 -0
  111. package/bundle/web-dist/server/voice-samples/grok/ara.mp3 +0 -0
  112. package/bundle/web-dist/server/voice-samples/grok/atlas.mp3 +0 -0
  113. package/bundle/web-dist/server/voice-samples/grok/aurora.mp3 +0 -0
  114. package/bundle/web-dist/server/voice-samples/grok/carina.mp3 +0 -0
  115. package/bundle/web-dist/server/voice-samples/grok/castor.mp3 +0 -0
  116. package/bundle/web-dist/server/voice-samples/grok/celeste.mp3 +0 -0
  117. package/bundle/web-dist/server/voice-samples/grok/cosmo.mp3 +0 -0
  118. package/bundle/web-dist/server/voice-samples/grok/eve.mp3 +0 -0
  119. package/bundle/web-dist/server/voice-samples/grok/helios.mp3 +0 -0
  120. package/bundle/web-dist/server/voice-samples/grok/helix.mp3 +0 -0
  121. package/bundle/web-dist/server/voice-samples/grok/iris.mp3 +0 -0
  122. package/bundle/web-dist/server/voice-samples/grok/kepler.mp3 +0 -0
  123. package/bundle/web-dist/server/voice-samples/grok/leo.mp3 +0 -0
  124. package/bundle/web-dist/server/voice-samples/grok/liora.mp3 +0 -0
  125. package/bundle/web-dist/server/voice-samples/grok/lumen.mp3 +0 -0
  126. package/bundle/web-dist/server/voice-samples/grok/luna.mp3 +0 -0
  127. package/bundle/web-dist/server/voice-samples/grok/lux.mp3 +0 -0
  128. package/bundle/web-dist/server/voice-samples/grok/naksh.mp3 +0 -0
  129. package/bundle/web-dist/server/voice-samples/grok/orion.mp3 +0 -0
  130. package/bundle/web-dist/server/voice-samples/grok/perseus.mp3 +0 -0
  131. package/bundle/web-dist/server/voice-samples/grok/rex.mp3 +0 -0
  132. package/bundle/web-dist/server/voice-samples/grok/rigel.mp3 +0 -0
  133. package/bundle/web-dist/server/voice-samples/grok/sal.mp3 +0 -0
  134. package/bundle/web-dist/server/voice-samples/grok/sirius.mp3 +0 -0
  135. package/bundle/web-dist/server/voice-samples/grok/ursa.mp3 +0 -0
  136. package/bundle/web-dist/server/voice-samples/grok/zagan.mp3 +0 -0
  137. package/bundle/web-dist/server/voice-samples/grok/zenith.mp3 +0 -0
  138. package/bundle/web-dist/server/voice-samples/openai/alloy.mp3 +0 -0
  139. package/bundle/web-dist/server/voice-samples/openai/ash.mp3 +0 -0
  140. package/bundle/web-dist/server/voice-samples/openai/ballad.mp3 +0 -0
  141. package/bundle/web-dist/server/voice-samples/openai/cedar.mp3 +0 -0
  142. package/bundle/web-dist/server/voice-samples/openai/coral.mp3 +0 -0
  143. package/bundle/web-dist/server/voice-samples/openai/echo.mp3 +0 -0
  144. package/bundle/web-dist/server/voice-samples/openai/marin.mp3 +0 -0
  145. package/bundle/web-dist/server/voice-samples/openai/sage.mp3 +0 -0
  146. package/bundle/web-dist/server/voice-samples/openai/shimmer.mp3 +0 -0
  147. package/bundle/web-dist/server/voice-samples/openai/verse.mp3 +0 -0
  148. package/package.json +1 -1
  149. package/skills/qgrid/SKILL.md +5 -5
  150. package/skills/qgrid/references/ai-sdk-provider-contract.md +4 -0
  151. package/skills/qgrid/references/decision-rationale.md +13 -3
  152. package/skills/qgrid/references/openai-codex-runtime.md +17 -5
  153. package/skills/qgrid/references/request-log-run-lifecycle.md +7 -2
  154. package/skills/qgrid/references/sonamu-api-web-flow.md +6 -2
  155. package/skills/qgrid/references/verification-and-debugging.md +3 -3
  156. package/bundle/web-dist/client/assets/index-BakMhnHZ.js +0 -104
  157. 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
- ["png", "iVBORw0KGgo=", "image/png"],
48
- ["jpeg", "/9j/", "image/jpeg"],
49
- ["webp", "UklGRgAAAABXRUJQ", "image/webp"],
50
- ])("preserves %s output MIME type", (format, result, mimeType) => {
51
- expect(normalizeOpenAIEvent({
52
- type: "response.output_item.done",
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 and generated images", () => {
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
- const item = event.item;
389
- const result = jsonString(item.result);
390
-
391
- if (item.type === "image_generation_call" && result !== undefined) {
392
- return imageEvent(item, result);
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
- if (options.model === "gpt-image-2" || requestsTransparentImage(options.imageGeneration)) {
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(["png", "jpeg", "webp"] as const)("forwards %s format and preserves returned MIME", async (outputFormat) => {
131
- const args = QueryInput.parse({ prompt: "draw", imageGeneration: true, imageGenerationOptions: { outputFormat } });
132
- let body: ReturnType<typeof buildOpenAIResponsesRequest> | undefined;
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
- body = buildOpenAIResponsesRequest(options);
135
- return events({ type: "image", base64: "data", mimeType: `image/${outputFormat}` }, { type: "completed", responseId: "r" });
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
- expect(body?.tools).toEqual([{ type: "image_generation", output_format: outputFormat }]);
140
- expect(result.images).toMatchObject([{ mediaType: `image/${outputFormat}` }]);
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 hosted images with one driver request", async () => {
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"])("does not treat completed %s metadata as hosted image execution", async (metadata) => {
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" }));