@qwen-code/qwen-harness 0.1.9 → 0.1.10

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/README.md CHANGED
@@ -142,6 +142,9 @@ The concrete adaptations are:
142
142
  still apply. REPL state survives cells;
143
143
  compaction, Notes handoff, session replacement/resume, cancellation, and execution
144
144
  errors reset it. Unawaited work is cancelled when a cell ends.
145
+ Emitted images use Pi codemode's Base64 and format-signature checks; the actual
146
+ image signature determines the MIME type. Invalid output returns a tool error
147
+ so the model can correct it before another request.
145
148
  - **C2:** follows the local Qwen Code branch
146
149
  `dragon/local-notes-compaction@7ee219f032`: `session_notes` saves a versioned
147
150
  checkpoint, `new_context` stages a switch using that revision, and
@@ -348,13 +348,19 @@ function emittedContent(value, maxOutputChars) {
348
348
  continue;
349
349
  }
350
350
  if (candidate.type === "image" && typeof candidate.data === "string" && typeof candidate.mimeType === "string") {
351
- if (Buffer.byteLength(candidate.data, "base64") > MAX_IMAGE_BYTES) {
351
+ const data = candidate.data.replace(/\s+/gu, "");
352
+ if (data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/u.test(data)) {
353
+ throw new Error("Invalid image output: image data is not valid base64 (truncated or mixed with tool text?).");
354
+ }
355
+ const signature = IMAGE_SIGNATURES.find(([, pattern]) => pattern.test(data.slice(0, 16)));
356
+ if (!signature) throw new Error("Invalid image output: expected PNG, JPEG, GIF, or WebP image data.");
357
+ if (Buffer.byteLength(data, "base64") > MAX_IMAGE_BYTES) {
352
358
  throw new Error("run_code image output exceeds the 20 MiB limit");
353
359
  }
354
360
  content.push({
355
361
  type: "image",
356
- data: candidate.data,
357
- mimeType: candidate.mimeType
362
+ data,
363
+ mimeType: signature[0]
358
364
  });
359
365
  }
360
366
  }
@@ -618,7 +624,7 @@ function createProgrammaticToolCallingCapability(cwd = process.cwd(), options =
618
624
  extensionFactories: [createProgrammaticToolCallingExtension(cwd, options)]
619
625
  };
620
626
  }
621
- var RUN_CODE_TOOL_NAME, DEFAULT_IDLE_TIMEOUT_MS, DEFAULT_SYNC_TIMEOUT_MS, MAX_TIMEOUT_MS, DEFAULT_MAX_OUTPUT_CHARS, MAX_OUTPUT_CHARS, MAX_IMAGE_BYTES, TRUNCATION_MARKER, RUN_CODE_CHILD_PATH, runCodeSchema, createCodeModeCapability;
627
+ var RUN_CODE_TOOL_NAME, DEFAULT_IDLE_TIMEOUT_MS, DEFAULT_SYNC_TIMEOUT_MS, MAX_TIMEOUT_MS, DEFAULT_MAX_OUTPUT_CHARS, MAX_OUTPUT_CHARS, MAX_IMAGE_BYTES, IMAGE_SIGNATURES, TRUNCATION_MARKER, RUN_CODE_CHILD_PATH, runCodeSchema, createCodeModeCapability;
622
628
  var init_programmatic_tool_calling = __esm({
623
629
  "src/capabilities/tools/programmatic-tool-calling/index.ts"() {
624
630
  "use strict";
@@ -630,6 +636,12 @@ var init_programmatic_tool_calling = __esm({
630
636
  DEFAULT_MAX_OUTPUT_CHARS = 5e4;
631
637
  MAX_OUTPUT_CHARS = 2e5;
632
638
  MAX_IMAGE_BYTES = 20 * 1024 * 1024;
639
+ IMAGE_SIGNATURES = [
640
+ ["image/png", /^iVBORw0KGg/u],
641
+ ["image/jpeg", /^[/]9j[/](?!9)/u],
642
+ ["image/gif", /^R0lGOD[dl]h/u],
643
+ ["image/webp", /^UklG.{8}RUJQ/u]
644
+ ];
633
645
  TRUNCATION_MARKER = "\n... run_code output truncated ...\n";
634
646
  RUN_CODE_CHILD_PATH = fileURLToPath3(new URL("./child-runtime.js", import.meta.url));
635
647
  runCodeSchema = Type21.Object({