@cartanova/qgrid-cli 2.19.0 → 2.19.1

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 (23) hide show
  1. package/bundle/dist/application/qgrid/qgrid-response-format.js +14 -5
  2. package/bundle/dist/application/qgrid/qgrid-run-lifecycle.js +8 -3
  3. package/bundle/dist/application/qgrid/qgrid.frame.js +3 -2
  4. package/bundle/src/application/qgrid/qgrid-response-format.test.ts +14 -4
  5. package/bundle/src/application/qgrid/qgrid-response-format.ts +18 -2
  6. package/bundle/src/application/qgrid/qgrid-run-lifecycle.test.ts +23 -1
  7. package/bundle/src/application/qgrid/qgrid-run-lifecycle.ts +14 -2
  8. package/bundle/src/application/qgrid/qgrid.frame.ts +3 -1
  9. package/bundle/web-dist/client/assets/{index-DYYtV8Qx.js → index-DvW4Yb82.js} +3 -3
  10. package/bundle/web-dist/client/assets/{logs-CbDtQif1.js → logs-DAif2re1.js} +1 -1
  11. package/bundle/web-dist/client/assets/{monit-DtW8o_yF.js → monit-DYczkiu0.js} +1 -1
  12. package/bundle/web-dist/client/assets/{routes-Dw227enb.js → routes--6kS1pgJ.js} +1 -1
  13. package/bundle/web-dist/client/assets/{settings-BXmAToY1.js → settings-Dah87LB2.js} +1 -1
  14. package/bundle/web-dist/client/assets/{show-5qj6wFgp.js → show-DQWFaVDW.js} +1 -1
  15. package/bundle/web-dist/client/assets/{tokens-D8L8AC4v.js → tokens-CIHja806.js} +1 -1
  16. package/bundle/web-dist/client/assets/{use-oauth-login-flow-BcEUkszt.js → use-oauth-login-flow-DeJCqHDJ.js} +1 -1
  17. package/bundle/web-dist/client/assets/{use-update-token-mutation-Ca0n_WnM.js → use-update-token-mutation-Cn_Po_rH.js} +1 -1
  18. package/bundle/web-dist/client/assets/{voice-D-c1Eyp3.js → voice-6i785ieC.js} +1 -1
  19. package/bundle/web-dist/client/index.html +1 -1
  20. package/bundle/web-dist/server/entry-server.generated.js +1 -1
  21. package/package.json +1 -1
  22. package/skills/qgrid/references/decision-rationale.md +1 -1
  23. package/skills/qgrid/references/request-log-run-lifecycle.md +1 -1
@@ -11,7 +11,7 @@ it("logs observed standalone settings separately from requested controls without
11
11
  };
12
12
  const [step] = buildImageGenerationToolSteps({
13
13
  prompt: "draw", model: "openai/gpt-5.5", imageGenerationOptions: requestedOptions,
14
- }, [{ type: "image", data: "png", generation }], 0);
14
+ }, [{ type: "image", data: "png", generation }], 0, true);
15
15
  const args = JSON.parse(step!.tool_args);
16
16
  expect(args.requestedOptions).toEqual(requestedOptions);
17
17
  expect(args.observedGeneration).toEqual(generation);
@@ -45,7 +45,7 @@ describe("qgrid response log formatting", () => {
45
45
  expect(args.pricingAssumption).not.toHaveProperty("background");
46
46
  });
47
47
 
48
- it("includes input images in image-generation tool args", () => {
48
+ it("records input image metadata in tool args; the run's input_images keeps the bytes", () => {
49
49
  expect(
50
50
  JSON.parse(
51
51
  imageGenerationToolArgs({
@@ -59,7 +59,7 @@ describe("qgrid response log formatting", () => {
59
59
  ),
60
60
  ).toMatchObject({
61
61
  prompt: "stage this room",
62
- inputImages: [{ mediaType: "image/webp", data: "UklGRg==", byteSize: 4 }],
62
+ inputImages: [{ mediaType: "image/webp", byteSize: 4 }],
63
63
  });
64
64
  });
65
65
 
@@ -105,10 +105,11 @@ describe("qgrid response log formatting", () => {
105
105
  { type: "image", data: "second", revisedPrompt: "second" },
106
106
  ],
107
107
  2,
108
+ true,
108
109
  );
109
110
 
110
111
  expect(JSON.parse(steps[0]!.tool_args).inputImages).toEqual([
111
- { mediaType: "image/webp", data: "UklGRg==", byteSize: 4 },
112
+ { mediaType: "image/webp", byteSize: 4 },
112
113
  ]);
113
114
  expect(JSON.parse(steps[1]!.tool_args).inputImages).toBeUndefined();
114
115
  expect(steps.map((step) => step.tool_call_id)).toEqual([
@@ -116,4 +117,13 @@ describe("qgrid response log formatting", () => {
116
117
  "image_generation:2:1",
117
118
  ]);
118
119
  });
120
+
121
+ it("keeps image bytes in a step only when the run's response does not carry them", () => {
122
+ const image = { type: "image" as const, data: "iVBORw0KGgo=", revisedPrompt: "dot" };
123
+ const [inResponse] = buildImageGenerationToolSteps({ prompt: "draw" }, [image], 0, true);
124
+ const [beforeToolCalls] = buildImageGenerationToolSteps({ prompt: "draw" }, [image], 0, false);
125
+
126
+ expect(inResponse!.tool_result).toBe("[image image/png 8 bytes, shown in the response]");
127
+ expect(beforeToolCalls!.tool_result).toBe(formatImagePartForLog(image));
128
+ });
119
129
  });
@@ -46,14 +46,26 @@ export function formatImagePartForLog(image: Extract<QgridContent, { type: "imag
46
46
  return `<img src="data:${image.mediaType ?? "image/png"};base64,${image.data}" alt="${alt}" />`;
47
47
  }
48
48
 
49
+ /** Stands in for an image the run's response already carries, so the request log stores it once. */
50
+ export function imagePlaceholderForLog(mediaType: string | undefined, base64: string): string {
51
+ return `[image ${mediaType ?? "image/png"} ${base64ByteSize(base64)} bytes, shown in the response]`;
52
+ }
53
+
49
54
  export function imageGenerationToolArgs(
50
55
  args: QueryInput,
51
56
  options: { includeInputImages?: boolean; generation?: ImageGenerationMetadata } = {},
52
57
  ): string {
53
58
  const resolved = resolveImageGenerationOptions(args.imageGenerationOptions);
54
59
 
60
+ // The run's input_images column keeps the bytes; the step keeps only what was sent.
55
61
  const inputImages =
56
- options.includeInputImages === false ? [] : extractInputImagesForToolArgs(args);
62
+ options.includeInputImages === false
63
+ ? []
64
+ : extractInputImagesForToolArgs(args).map(({ mediaType, url, byteSize }) => ({
65
+ mediaType,
66
+ url,
67
+ byteSize,
68
+ }));
57
69
 
58
70
  // Keys are assigned in their serialized order; request logs store this JSON text.
59
71
  const toolArgs: Record<string, JsonValue> = {};
@@ -94,10 +106,12 @@ export function imageGenerationToolArgs(
94
106
  return JSON.stringify(toolArgs);
95
107
  }
96
108
 
109
+ /** `imagesInResponse`: the run's response stores these images, so the steps keep placeholders. */
97
110
  export function buildImageGenerationToolSteps(
98
111
  args: QueryInput,
99
112
  images: Extract<QgridContent, { type: "image" }>[],
100
113
  stepIndex: number,
114
+ imagesInResponse: boolean,
101
115
  ): Array<{
102
116
  step_index: number;
103
117
  type: "tool_call";
@@ -119,7 +133,9 @@ export function buildImageGenerationToolSteps(
119
133
  includeInputImages: index === 0,
120
134
  generation: image.generation,
121
135
  }),
122
- tool_result: formatImagePartForLog(image),
136
+ tool_result: imagesInResponse
137
+ ? imagePlaceholderForLog(image.mediaType, image.data)
138
+ : formatImagePartForLog(image),
123
139
  }));
124
140
  }
125
141
 
@@ -119,6 +119,27 @@ describe("qgrid run lifecycle start", () => {
119
119
  vi.restoreAllMocks();
120
120
  });
121
121
 
122
+ it("stores history images as their length only", async () => {
123
+ const image = "data:image/png;base64,iVBORw0KGgo=";
124
+ const history = JSON.stringify([
125
+ { type: "message", role: "user", content: [{ type: "input_image", image_url: image }] },
126
+ ]);
127
+
128
+ await beforeQuery({ prompt: "edit it", history });
129
+
130
+ expect(createRunMock).toHaveBeenCalledWith(
131
+ expect.objectContaining({
132
+ history: [
133
+ {
134
+ type: "message",
135
+ role: "user",
136
+ content: [{ type: "input_image", image_url: `[data-url ${image.length} chars]` }],
137
+ },
138
+ ],
139
+ }),
140
+ );
141
+ });
142
+
122
143
  it("creates a running parent with the full requested model before an initial query", async () => {
123
144
  const history = JSON.stringify([
124
145
  { type: "message", role: "user", content: "earlier" },
@@ -519,7 +540,8 @@ describe("qgrid run lifecycle TTFT", () => {
519
540
  size: "1536x1024",
520
541
  },
521
542
  }),
522
- tool_result: '<img src="data:image/png;base64,iVBORw0KGgoBAgM" alt="green triangle" />',
543
+ // The run's response carries the image itself.
544
+ tool_result: "[image image/png 11 bytes, shown in the response]",
523
545
  }),
524
546
  );
525
547
  });
@@ -46,13 +46,22 @@ const StoredHistoryMessage = z.looseObject({
46
46
 
47
47
  type StoredHistoryMessage = z.infer<typeof StoredHistoryMessage>;
48
48
 
49
+ // Images in history were stored with the run that sent or generated them, and nothing reads them
50
+ // back from here: keep only their length. Base64 has no quotes or escapes, so a match is exactly one
51
+ // JSON string value.
52
+ const DATA_URL_STRING = /"data:[^",;\\]*;base64,[A-Za-z0-9+/=]*"/g;
53
+
54
+ function maskDataUrls(rawHistory: string): string {
55
+ return rawHistory.replace(DATA_URL_STRING, (match) => `"[data-url ${match.length - 2} chars]"`);
56
+ }
57
+
49
58
  function filterHistoryForStorage(
50
59
  rawHistory: string | undefined,
51
60
  ): StoredHistoryMessage[] | undefined {
52
61
  if (!rawHistory) return undefined;
53
62
 
54
63
  try {
55
- const items = z.array(z.unknown()).parse(JSON.parse(rawHistory));
64
+ const items = z.array(z.unknown()).parse(JSON.parse(maskDataUrls(rawHistory)));
56
65
 
57
66
  const filtered = items.flatMap((item) => {
58
67
  const message = StoredHistoryMessage.safeParse(item);
@@ -223,7 +232,10 @@ export async function afterQuery(
223
232
  ? 0
224
233
  : estimateImageGenerationCostMicroUsd(result, args.imageGenerationOptions);
225
234
 
226
- for (const step of buildImageGenerationToolSteps(args, imageParts, stepIndex)) {
235
+ // A tool-calls step ends without a response, so only then do its steps keep the image bytes.
236
+ const imagesInResponse = result.finishReason !== "tool-calls";
237
+
238
+ for (const step of buildImageGenerationToolSteps(args, imageParts, stepIndex, imagesInResponse)) {
227
239
  await RequestLogModel.appendStep(requestLogId, step);
228
240
  }
229
241
 
@@ -116,6 +116,7 @@ import {
116
116
  RefreshFailedError,
117
117
  } from "./oauth";
118
118
  import { CODEX_IMAGE_GENERATION_MODEL } from "./qgrid-image-generation";
119
+ import { imagePlaceholderForLog } from "./qgrid-response-format";
119
120
  import {
120
121
  afterQuery,
121
122
  beforeQuery,
@@ -2091,7 +2092,8 @@ class QgridFrameClass extends BaseFrameClass {
2091
2092
  return {
2092
2093
  toolCallId: `image_generation:0:${index}`,
2093
2094
  args,
2094
- result: imageTagForLog(image.b64, image.mimeType, image.revisedPrompt),
2095
+ // The run's response already holds this image.
2096
+ result: imagePlaceholderForLog(image.mimeType, image.b64),
2095
2097
  };
2096
2098
  }),
2097
2099
  };