Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
CR5: 回复的本轮图片复用共享工具结果解析并认 xdt_media_produced 账本
nanaf267a367310a
diff --git a/apps/desktop/src/main/companion-cloud/__tests__/replyArtifacts.test.ts b/apps/desktop/src/main/companion-cloud/__tests__/replyArtifacts.test.tsindex 8d2ddc133a..0d6e6dc5a8 100644--- a/apps/desktop/src/main/companion-cloud/__tests__/replyArtifacts.test.ts+++ b/apps/desktop/src/main/companion-cloud/__tests__/replyArtifacts.test.ts@@ -105,6 +105,11 @@ describe('images made by tools during the turn', () => {expect(toolResultImageUrls(JSON.stringify(result))).toEqual([url('a'), url('b')]);expect(toolResultImageUrls(JSON.stringify(JSON.stringify(result)))).toEqual([url('a'), url('b')]);expect(toolResultImageUrls(JSON.stringify({ ...result, _xdt_render_image: false }))).toEqual([]);+ // The host's own ledger of produced media counts when the tool named no image field, also inside the ghost_call envelope.+ const ledger = { xdt_media_produced: [url('c'), `cindy-media://blobs/${'d'.repeat(64)}.mp4`, 'https://example.com/x.png'] };+ expect(toolResultImageUrls(JSON.stringify(ledger))).toEqual([url('c')]);+ expect(toolResultImageUrls(JSON.stringify({ ok: true, result: ledger }))).toEqual([url('c')]);+ expect(toolResultImageUrls(JSON.stringify({ ok: true, result: { ...ledger, _xdt_render_image: false } }))).toEqual([]);expect(toolResultImageUrls('not json')).toEqual([]);expect(toolResultImageUrls(null)).toEqual([]);});diff --git a/apps/desktop/src/main/companion-cloud/replyArtifacts.ts b/apps/desktop/src/main/companion-cloud/replyArtifacts.tsindex 072b01d84c..9fad59cfd6 100644--- a/apps/desktop/src/main/companion-cloud/replyArtifacts.ts+++ b/apps/desktop/src/main/companion-cloud/replyArtifacts.ts@@ -8,12 +8,14 @@import fs from 'node:fs/promises';import path from 'node:path';import { createHash } from 'node:crypto';+import { parseToolResultPayload } from '@cindy/maker-shared/payload-summary';import { buildLooseUrl, extractLoosePath } from '../session-share/mediaUrlRewrite.pure.js';import type { CompanionMirrorAttachment } from './mirror.js';/** A reply sends at most this many files to the room. */export const REPLY_ARTIFACTS_MAX = 8;+const PRODUCED_IMAGE_EXT = /\.(png|jpe?g|gif|webp)$/i;const BLOB_URL = /\bcindy-media:\/\/blobs\/[0-9a-f]{64}\.[a-z0-9]+/g;/*** Only deliverables go to the room, whatever form the path is written in: documents, spreadsheets,@@ -77,15 +79,19 @@ export function collectReplyReferences(text: string): ReplyReferences {* to be shown (`_xdt_render_image: false`) and any address that is not a stored blob give nothing.*/export function toolResultImageUrls(rawContent: string | null): string[] {- let value: unknown = rawContent;- // A result is stored as JSON, often a JSON string holding the tool's own JSON.- for (let depth = 0; depth < 2 && typeof value === 'string'; depth += 1) {- try { value = JSON.parse(value); } catch { return []; }- }- if (!value || typeof value !== 'object' || Array.isArray(value)) return [];- const record = value as Record<string, unknown>;- if (record._xdt_render_image === false) return [];- const candidates = [record.xdt_image_url, ...(Array.isArray(record.xdt_image_urls) ? record.xdt_image_urls : [])];+ if (!rawContent) return [];+ let text = rawContent;+ // A result is stored as JSON, sometimes as a JSON string holding the tool's own JSON.+ try {+ const once: unknown = JSON.parse(text);+ if (typeof once === 'string') text = once;+ } catch { return []; }+ // The same reading as the other channels: the ghost_call envelope is opened, and the host's own+ // ledger of produced media (`xdt_media_produced`) counts although the tool named no image field.+ const record = parseToolResultPayload(text);+ if (!record || record._xdt_render_image === false) return [];+ const produced = Array.isArray(record.xdt_media_produced) ? record.xdt_media_produced.filter(url => typeof url === 'string' && PRODUCED_IMAGE_EXT.test(url)) : [];+ const candidates = [record.xdt_image_url, ...(Array.isArray(record.xdt_image_urls) ? record.xdt_image_urls : []), ...produced];return [...new Set(candidates.filter((url): url is string => typeof url === 'string' && /^cindy-media:\/\/blobs\/[0-9a-f]{64}\.[a-z0-9]+$/.test(url)))];}diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.mdindex c6d888bf26..f45c0e5317 100644--- a/docs/product-rules/cloud-companions.md+++ b/docs/product-rules/cloud-companions.md@@ -139,7 +139,7 @@`src/keys/service-account.json` 都不会上云);符号链接按真实路径再判一次扩展名。文件必须真实存在于该任务自己的工作目录内(符号链接按真实路径复核,隐藏文件与目录如 `.env`、`.git` 不上传,目录外与 UNC 路径不读),单个不超过 25 MB,每条回复最多 8 个;经与主人附件同一条房间附件通道上传,永久 / 暂时失败的区分与主人附件一致(暂时失败这一轮停下重试,永久失败只发正文)。- 工具在这一轮生成并存入媒体仓的图片(工具结果里的 `xdt_image_url` / `xdt_image_urls`,聊天里作为这一轮的图片独立显示,回复正文可以不提)同样作为附件随回复上云:取上一条用户 / 伙伴消息之后到这条回复为止的工具结果,落在其后第一条被导入的回复上,计入每条回复 8 个的上限,只带图片本身,不带工具调用明细(§1 第 2 条);结果要求不显示(`_xdt_render_image: false`)或不是媒体仓地址的不带。+ 工具在这一轮生成并存入媒体仓的图片(工具结果里的 `xdt_image_url` / `xdt_image_urls`,以及主机注入的 `xdt_media_produced` 账本里的图片,ghost_call 外层信封按 `parseToolResultPayload` 同一口径展开;聊天里作为这一轮的图片独立显示,回复正文可以不提)同样作为附件随回复上云:取上一条**会被镜像**的用户 / 伙伴消息(与 `mirrorMessageText` 同一判据,过程旁白、子 Agent 与私有回复不算)之后到这条回复为止的工具结果,落在其后第一条被导入的回复上,计入每条回复 8 个的上限,只带图片本身,不带工具调用明细(§1 第 2 条);结果要求不显示(`_xdt_render_image: false`)或不是媒体仓地址的不带。换电脑导入时,房间里的附件先下载并入库(图片入媒体仓,同一字节得到同一个 `cindy-media://` 地址)、挂上任务引用,再写消息,所以回复里原有的 `cindy-media://` 图片在新电脑直接显示;正文没提到的图片和非图片文件作为链接追加在回复下面(文件按房间附件落盘方式保存在本机,链接指向它),不再只写 `[附件: …]` 占位。