@aiti-ai/aiti-codex-agent 0.1.12 → 0.1.13

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.
@@ -404,3 +404,28 @@ test("codexContextWindow: gpt-4 族 128K / gpt-5 族与未知 272K", async () =>
404
404
  assert.equal(codexContextWindow("gpt-4.1"), 128_000);
405
405
  assert.equal(codexContextWindow(undefined), 272_000);
406
406
  });
407
+
408
+ // ============================================================================
409
+ // Image mirroring: the host compares its optimistic bubble with the loaded copy
410
+ // via userMessageKey, which hashes image blocks.
411
+ // ============================================================================
412
+
413
+ test("镜像带图: prompt(images) → liveHistory 落宿主同形 base64 块(无图仍是字符串)", async () => {
414
+ const stubDir = join(ROOT, "img-stubs");
415
+ mkdirSync(stubDir, { recursive: true });
416
+ const registered = await setup(writeStub(stubDir, "img.cjs", 5));
417
+ const handle = await registered.createSession({ cwd: ROOT });
418
+ const users = async () => (await handle.getMessages()).filter((m) => m.role === "user");
419
+
420
+ const p = handle.prompt("这张图怎么回事", { images: [{ data: "QUJD", mimeType: "image/png" }] });
421
+ assert.deepEqual((await users()).at(-1).content, [
422
+ { type: "text", text: "这张图怎么回事" },
423
+ { type: "image", source: { type: "base64", media_type: "image/png", data: "QUJD" } },
424
+ ], "镜像与宿主乐观气泡同形(否则纯文本版顶替,图消失)");
425
+ await p;
426
+
427
+ const p2 = handle.prompt("纯文字");
428
+ assert.equal((await users()).at(-1).content, "纯文字", "无图保持老形状(字符串 content)");
429
+ await p2;
430
+ await handle.dispose();
431
+ });
package/index.ts CHANGED
@@ -148,6 +148,26 @@ function codexToolResultText(item: Record<string, unknown>, isError: boolean): s
148
148
  return text.trim().slice(0, TOOL_RESULT_TEXT_CAP) || (isError ? EMPTY_TOOL_ERROR : EMPTY_TOOL_OUTPUT);
149
149
  }
150
150
 
151
+ /**
152
+ * pi-native user content for the live mirror (host `UserMessage` shape: text block +
153
+ * base64 image blocks). The host compares its optimistic bubble with the loaded copy
154
+ * through `userMessageKey()`, which hashes every image block — a text-only mirror fails
155
+ * that comparison, so the bubble (with its pictures) is replaced by a picture-less one.
156
+ * Cold replay has nothing to recover from: codex rollouts record the prompt text only
157
+ * (the `-i` attachments are files outside the transcript).
158
+ */
159
+ function userHistoryContent(
160
+ text: string,
161
+ images?: Array<{ data: string; mimeType: string }>,
162
+ ): string | Array<Record<string, unknown>> {
163
+ if (!images?.length) return text;
164
+ const content: Array<Record<string, unknown>> = text ? [{ type: "text", text }] : [];
165
+ for (const img of images) {
166
+ content.push({ type: "image", source: { type: "base64", media_type: img.mimeType, data: img.data } });
167
+ }
168
+ return content;
169
+ }
170
+
151
171
  /**
152
172
  * codex 模型族上下文窗口(getContextUsage 换算用):GPT-5 系(gpt-5/gpt-5-codex/
153
173
  * gpt-5.1…,codex 默认族)272K;GPT-4 系 128K;未知回 272K(当前缺省族,宁近似
@@ -527,7 +547,7 @@ class CodexHandle {
527
547
  return;
528
548
  }
529
549
  this.running = true;
530
- this.liveHistory.push({ role: "user", content: text });
550
+ this.liveHistory.push({ role: "user", content: userHistoryContent(text, options?.images) });
531
551
  // 受理即发:前端 spinner「等待模型」立刻出现(CLI 冷启动可能数秒)。
532
552
  // wire 层丢弃 turn_started,前端流式态只认 agent_start/agent_end 对。
533
553
  this.emit({ type: "agent_start" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiti-ai/aiti-codex-agent",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "OpenAI Codex CLI driver — exec --json + resume integrated into All Sessions; dual-track auth (auth.json OAuth / openrouter env), live streaming and cold replay render identically-shaped native tool cards",
5
5
  "displayNameI18n": {
6
6
  "en": "Codex Session Backend"
@@ -26,7 +26,7 @@
26
26
  "@aiti-ai/ext-shared": "^0.1.12"
27
27
  },
28
28
  "license": "MIT",
29
- "contentHash": "f0da0454915c2161",
29
+ "contentHash": "dff30a2e64fba7a6",
30
30
  "repository": {
31
31
  "type": "git",
32
32
  "url": "git+https://github.com/aiti-ai/aiti-ai.git",