Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companion-cloud): D7 show imported teammate replies as text, not a JSON block array
nana7b98d8c3bd9f
diff --git a/apps/desktop/src/main/companion-cloud/host.ts b/apps/desktop/src/main/companion-cloud/host.tsindex c3a79a9880..245ffef003 100644--- a/apps/desktop/src/main/companion-cloud/host.ts+++ b/apps/desktop/src/main/companion-cloud/host.ts@@ -280,8 +280,8 @@ function createMaterializer(input: {fence.assertCurrent();}await createMessage(sessionId, { clientId: row.clientId, role: row.role, createdAt: row.createdAt,- content: row.role === 'user' ? { text: row.text, images, files: others }- : [{ type: 'text', text: replyTextWithFiles(row.text, files) }] });+ // An assistant row holds its reply as a plain string, like every other reply the chat shows.+ content: row.role === 'user' ? { text: row.text, images, files: others } : replyTextWithFiles(row.text, files) });},rebuildContext: sessionId => input.rebuildContext(sessionId),};diff --git a/apps/desktop/src/main/localDb/__tests__/mapperCitation.test.ts b/apps/desktop/src/main/localDb/__tests__/mapperCitation.test.tsindex 7af2d8357a..7ea05fca6f 100644--- a/apps/desktop/src/main/localDb/__tests__/mapperCitation.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/mapperCitation.test.ts@@ -89,3 +89,24 @@ describe('message mapper internal citation compatibility', () => {expect(extractMessagePreview(bounded, 'user')).toBeNull();});});++describe('message mapper imported cloud replies', () => {+ const row = (clientId: string, content: unknown, role = 'assistant') => ({+ id: 'message-1', clientId, sessionId: 'session-1', role, content: JSON.stringify(content),+ toolUseId: null, agentMeta: null, agentKind: null, createdAt: 1, rewindAt: null,+ }) as Parameters<typeof messageToCamel>[0];++ it('reads a reply imported as text blocks (stored by earlier versions) as plain text', () => {+ const blocks = [{ type: 'text', text: '你好,' }, { type: 'text', text: '这是回复' }];+ expect(messageToCamel(row('cloud-history:m1', blocks)).content).toBe('你好,这是回复');+ expect(messageToCamel(row('cloud-history:m1', 'plain')).content).toBe('plain');+ });++ it('leaves other block content and other rows untouched', () => {+ const blocks = [{ type: 'text', text: 'a' }];+ expect(messageToCamel(row('client-1', blocks)).content).toEqual(blocks);+ const mixed = [{ type: 'text', text: 'a' }, { type: 'image', url: 'x' }];+ expect(messageToCamel(row('cloud-history:m2', mixed)).content).toEqual(mixed);+ expect(messageToCamel(row('cloud-history:m3', blocks, 'user')).content).toEqual(blocks);+ });+});diff --git a/apps/desktop/src/main/localDb/mapper.ts b/apps/desktop/src/main/localDb/mapper.tsindex 04190be471..e8db07bf66 100644--- a/apps/desktop/src/main/localDb/mapper.ts+++ b/apps/desktop/src/main/localDb/mapper.ts@@ -313,6 +313,17 @@ export function sessionToCamel(row: SessionRowWithCount): Session {return { ...base, ...projectSessionRuntimeFields({ ...base, scheduledModelBaseline: row.scheduledModelBaseline }) };}+function importedReplyText(content: unknown): unknown {+ if (!Array.isArray(content) || !content.length) return content;+ const texts: string[] = [];+ for (const block of content) {+ const record = block && typeof block === 'object' ? (block as { type?: unknown; text?: unknown }) : null;+ if (record?.type !== 'text' || typeof record.text !== 'string') return content;+ texts.push(record.text);+ }+ return texts.join('');+}+export function messageToCamel(row: MessageRow): Message {let content: unknown = row.content;try {@@ -321,6 +332,11 @@ export function messageToCamel(row: MessageRow): Message {// 容错:极端情况下 content 可能不是合法 JSON(例如旧手工写入),保留原字符串content = row.content;}+ // Replies imported from the cloud room (`cloud-history:`, companion-cloud/mirror.ts) were once+ // stored as text blocks; every reader expects a reply as a plain string, so they read as one.+ if (row.role === 'assistant' && row.clientId?.startsWith('cloud-history:')) {+ content = importedReplyText(content);+ }if (row.role === 'assistant' && typeof content === 'string') {content = stripInternalWebCitations(content);}diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.mdindex 8d96147401..c86e8e455c 100644--- a/docs/product-rules/cloud-companions.md+++ b/docs/product-rules/cloud-companions.md@@ -170,6 +170,7 @@看到云端伙伴已停用时,把本机副本转为降级:隐藏、只读、不运行。- 接管时导入房间里的全部对话为本机历史(读到房间第一条为止,读不完整则这次接管失败、稍后重试;合并 Cindy 同样如此;云端对话查看最多读最近约 5 万条),附件一起下载。服务器不回传导入来源 ID,本机按「角色 + 消息时间(毫秒)」识别这台电脑当初导入上去的消息;已插入的云端历史(`cloud-history:<消息>`)和房间里直接发给伙伴、已投递进本机主任务的消息(`chat-direct:<执行>:<消息>`)按房间消息 ID 识别,都不重复插入(接管中途失败重试时,同一时间的拆分片段不会被误跳过);之后像「重启伙伴」一样从历史重建上下文,伙伴还有一轮在跑时等它结束再重建,期间副本保持降级。+- 导入的伙伴回复(`cloud-history:` 行)在本机和别的伙伴回复一样存为纯文本。早期版本把它存成文本块数组,聊天里会显示成原始 JSON;这些存量行不迁移数据库,读取时(`messageToCamel`)把全是文本块的数组还原成文本,所有读者(聊天、手机、搜索)看到的一致。- 已降级的本机副本:不领取执行、不上传、不导入对话,不同步名字与头像,不出现在伙伴列表、主入口选择、Cindy 多设备合并、本机 `list_agents` 和远程资源 `teammates` 列表(因此也不出现在其他设备的 `list_agents`),例行任务跳过但定义保留。主任务的所有发送通路(界面、内部派发、插件、队列出队)都在真正发送前拒绝。降级名单另存于账号隔离的 `companion-cloud/shadowed.json`,切换账号后的第一次读取就换成新账号的名单(不沿用上一个账号的主力电脑与降级状态),启动后、服务器不可达