Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 保留旧端标注队列文本编辑
DavidShencb0fd9dd4bcc
diff --git a/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.ts b/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.tsindex 14b186b418..7df696c8cb 100644--- a/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.ts+++ b/apps/desktop/src/renderer/__tests__/pendingQueueDefer.test.ts@@ -799,6 +799,121 @@ describe('renderer input queue facade', () => {expect(input.updateText).toHaveBeenCalledWith(sid, item.clientId, 'edited text', undefined);});+ it('falls back for an unchanged annotation on an old target but rejects changed strokes', async () => {+ const sid = `legacy-annotation-${Math.random().toString(36).slice(2, 8)}`;+ const deviceId = 'dev-legacy-annotation';+ const sourceUrl = 'xdt-image://session/legacy-source.jpg';+ const burnedUrl = 'xdt-image://session/legacy-burned.png';+ const rematerializedUrl = 'xdt-image://session/legacy-rematerialized.png';+ const strokes = [{ points: [{ x: 0.2, y: 0.8 }] }];+ const item = queued('q-legacy-annotation', 'old text');+ item.files = [{+ id: 'legacy-annotation',+ name: 'legacy-burned.png',+ originalName: 'legacy-burned.png',+ path: 'C:\\images\\legacy-burned.png',+ ext: '.png',+ size: 123,+ category: 'image',+ mimeType: 'image/png',+ url: burnedUrl,+ annotated: true,+ }];+ item.chatMessage.retryFiles = [{+ ...item.files[0],+ annotationSourceUrl: sourceUrl,+ annotationStrokes: strokes,+ }];+ const editableFile: AttachedFile = {+ ...item.files[0],+ path: sourceUrl,+ url: sourceUrl,+ ext: '.jpg',+ mimeType: 'image/jpeg',+ annotated: undefined,+ annotationStrokes: strokes.map((stroke) => ({+ points: stroke.points.map((point) => ({ ...point })),+ })),+ cacheUrlShared: true,+ stagedPathShared: true,+ };+ makerChatStore.initGlobalListeners();+ projectionHandler?.(projection(sid, { pendingQueue: [item] }));+ remoteProjectsStore.setDeviceSessions(deviceId, 'Remote Mac', [{ id: sid } as never]);+ annotationBurnInMocks.materialize.mockResolvedValueOnce([{+ ...editableFile,+ name: 'legacy-rematerialized.png',+ originalName: 'legacy-rematerialized.png',+ url: rematerializedUrl,+ ext: '.png',+ mimeType: 'image/png',+ annotated: true,+ annotationStrokes: undefined,+ }]);+ remoteInvoke.mockImplementation(async (_deviceId, channel) => {+ if (channel === 'maker:input:update-content') {+ throw new Error('[DEVICE_LINK_CHANNEL_NOT_ALLOWED] update-content unavailable');+ }+ expect(channel).toBe('maker:input:update-text');+ return projection(sid, {+ pendingQueue: [{+ ...item,+ text: 'edited text',+ persistedContent: item.persistedContent,+ chatMessage: { ...item.chatMessage, content: 'edited text' },+ }],+ });+ });++ const saved = await makerChatStore.updateQueueItemContent(sid, item.clientId, {+ content: {+ text: 'edited text',+ mentions: [],+ hasQuotes: false,+ agentReferences: [],+ pastedTextRanges: [],+ slashCommandRanges: [],+ },+ files: [editableFile],+ });++ expect(saved).toBe(true);+ expect(remoteInvoke).toHaveBeenCalledWith(+ deviceId,+ 'maker:input:update-content',+ expect.any(Array),+ );+ expect(remoteInvoke).toHaveBeenCalledWith(+ deviceId,+ 'maker:input:update-text',+ expect.any(Array),+ );+ expect(cleanupCachedImages).toHaveBeenCalledWith([rematerializedUrl]);++ const updateTextCalls = remoteInvoke.mock.calls.filter(+ ([, channel]) => channel === 'maker:input:update-text',+ ).length;+ await expect(+ makerChatStore.updateQueueItemContent(sid, item.clientId, {+ content: {+ text: 'edited again',+ mentions: [],+ hasQuotes: false,+ agentReferences: [],+ pastedTextRanges: [],+ slashCommandRanges: [],+ },+ files: [{+ ...editableFile,+ annotationStrokes: [{ points: [{ x: 0.4, y: 0.6 }] }],+ }],+ }),+ ).rejects.toThrow('update-content unavailable');+ expect(+ remoteInvoke.mock.calls.filter(([, channel]) => channel === 'maker:input:update-text'),+ ).toHaveLength(updateTextCalls);+ });+it('does not fall back to update-text when queue edit attachments change', async () => {const sid = `legacy-attachment-${Math.random().toString(36).slice(2, 8)}`;const item = queued('q-legacy-attachment', 'keep text');diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 28fdebd9b0..b8d5a3dc51 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -79,7 +79,13 @@ import { normalizeAutoTitle } from '@cindy/maker-shared/session-title';import { parseToolLoopErrorDetails } from '@cindy/maker-shared/tool-loop-error';import type { ToolLoopErrorDetails } from '@cindy/maker-core';import type { AgentMeta, MessageRole, Message, MessageAutomationOrigin } from '@/lib/ccAgent.types';-import type { AttachedFile, MentionedResource, SerializedAttachedFile } from '@/lib/fileTypes';+import {+ extractExt,+ getMimeType,+ type AttachedFile,+ type MentionedResource,+ type SerializedAttachedFile,+} from '@/lib/fileTypes';import type {AgentInputCreateOpts,AgentInputProjection,@@ -13776,13 +13782,48 @@ function queueEditFilesMatch(return JSON.stringify(stable(left)) === JSON.stringify(stable(right));}+function queueEditFilesRemainUnchanged(+ queued: QueuedMessage,+ editedFiles: readonly AttachedFile[],+): boolean {+ if (queueEditFilesMatch(queued.files, editedFiles)) return true;+ const retryFilesById = new Map(+ (queued.chatMessage.retryFiles ?? []).map((file) => [file.id, file]),+ );+ const editableQueuedFiles = (queued.files ?? []).map((file) => {+ const retryFile = retryFilesById.get(file.id);+ const annotationSourceUrl =+ file.annotated === true &&+ retryFile?.annotated === true &&+ retryFile.path === file.path &&+ retryFile.url === file.url &&+ retryFile.annotationSourceUrl &&+ retryFile.annotationStrokes?.length+ ? retryFile.annotationSourceUrl+ : null;+ if (!annotationSourceUrl || !retryFile?.annotationStrokes) return file;+ const sourceExt = extractExt(annotationSourceUrl) || file.ext;+ const editableFile = { ...file };+ delete editableFile.annotated;+ return {+ ...editableFile,+ path: annotationSourceUrl,+ url: annotationSourceUrl,+ ext: sourceExt,+ mimeType: getMimeType(sourceExt, 'image'),+ annotationStrokes: retryFile.annotationStrokes,+ };+ });+ return queueEditFilesMatch(editableQueuedFiles, editedFiles);+}+function canFallbackQueueEditToText(queued: QueuedMessage,replacement: QueuedMessage,content: QueueItemContentUpdate['content'],files: readonly AttachedFile[],): boolean {- if (!content.text.trim() || !queueEditFilesMatch(queued.files, files)) return false;+ if (!content.text.trim() || !queueEditFilesRemainUnchanged(queued, files)) return false;if (JSON.stringify(queued.mentions ?? []) !== JSON.stringify(content.mentions ?? [])) return false;if ((queued.chatMessage.quotesEncoded === true) !== content.hasQuotes) return false;if ((queued.chatMessage.agentReferences?.length ?? 0) > 0) return false;@@ -13863,6 +13904,7 @@ async function updateQueueItemContent(else delete replacement.sessionRefs;const boundaryOpts = getRemoteInputClearBoundaryOpts(sessionId);let projection: AgentInputProjection;+ let usedTextFallback = false;try {({ projection } = await runInputProjectionOperation(sessionId, (input) =>boundaryOpts@@ -13872,7 +13914,7 @@ async function updateQueueItemContent(} catch (error) {if (extractIpcError(error)?.code === 'DEVICE_LINK_CHANNEL_NOT_ALLOWED' &&- canFallbackQueueEditToText(queued, replacement, content, preparedFiles)+ canFallbackQueueEditToText(queued, replacement, content, files)) {try {({ projection } = await runInputProjectionOperation(sessionId, (input) =>@@ -13887,6 +13929,7 @@ async function updateQueueItemContent(): input.updateText(sessionId, clientId, content.text, replacement.sessionRefs),));+ usedTextFallback = true;} catch (fallbackError) {cleanupUnacceptedQueueEditMaterialization(files, preparedFiles);throw fallbackError;@@ -13897,21 +13940,28 @@ async function updateQueueItemContent(}}const accepted = projection.pendingQueue.find((item) => item.clientId === clientId);- const updated = queuedContentProjectionMatches(accepted, replacement);+ const acceptedReplacement = usedTextFallback+ ? { ...replacement, files: queued.files }+ : replacement;+ const updated = queuedContentProjectionMatches(accepted, acceptedReplacement);if (updated && accepted) {- cleanupAcceptedQueueEditReplacements(- queued.files ?? [],- queued.chatMessage.retryFiles ?? [],- preparedFiles,- accepted.files ?? [],- );- cleanupAcceptedQueueEditMaterializationSources(- queued.files ?? [],- files,- preparedFiles,- accepted.files ?? [],- remoteMediaSession,- );+ if (usedTextFallback) {+ cleanupUnacceptedQueueEditMaterialization(files, preparedFiles);+ } else {+ cleanupAcceptedQueueEditReplacements(+ queued.files ?? [],+ queued.chatMessage.retryFiles ?? [],+ preparedFiles,+ accepted.files ?? [],+ );+ cleanupAcceptedQueueEditMaterializationSources(+ queued.files ?? [],+ files,+ preparedFiles,+ accepted.files ?? [],+ remoteMediaSession,+ );+ }} else {cleanupUnacceptedQueueEditMaterialization(files, preparedFiles);}