Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(im): collect rich answer images before text delivery
nana5b08b17f53da
diff --git a/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.ts b/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.tsindex 367409981d..2e4b730879 100644--- a/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.ts+++ b/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.ts@@ -3168,7 +3168,9 @@ describe('turnRunner send outcome policy (feishu adapter characterization)', ()}});- it('materializes local Markdown images before committing chunked-text output', async () => {+ // #7125 review: image components must reach the existing attachment pipeline,+ // including error finalization; otherwise WeChat removes the projected image.+ it.each(['markdown', 'component', 'component-error'] as const)('materializes %s images before committing chunked-text output', async (kind) => {const previousOutput = fakeAdapter.output;const commitFinal = vi.fn(async () => undefined);fakeAdapter.output = {@@ -3185,15 +3187,22 @@ describe('turnRunner send outcome policy (feishu adapter characterization)', ()const { turnPromise } = await startDefaultTurn();await turnPromise;+ const markdown = '';+ const source = kind === 'markdown' ? markdown : '```cindy-ui\n' + JSON.stringify({+ version: 1, seq: 1, op: 'create', id: 'image', kind: 'image',+ props: { src: 'F:\\XDMaker\\generated.png', alt: '测试图片' },+ }) + '\n```';h.emit({type: 'text',- data: { text: '', isFinal: true },+ data: { text: source, isFinal: true },});- h.emit({ type: 'done', data: {} });+ h.emit(kind === 'component-error'+ ? { type: 'error', data: { message: 'process exited', isTerminal: true } }+ : { type: 'done', data: {} });await flushMicrotasks();expect(mocks.materializeLocalMarkdownImages).toHaveBeenCalledWith({- text: '',+ text: kind === 'markdown' ? markdown : '',workingDir: 'F:\\XDMaker',sessionId: 'feishu-session',maxImages: 4,@@ -3201,8 +3210,9 @@ describe('turnRunner send outcome policy (feishu adapter characterization)', ()});expect(commitFinal).toHaveBeenCalledWith({userId: 'ou_user',- text: '测试图片',- terminal: 'done',+ text: kind === 'component-error' ? expect.stringMatching(/测试图片[\s\S]*process exited/) : '测试图片',+ terminal: kind === 'component-error' ? 'error' : 'done',+ ...(kind === 'component-error' ? { errorCode: 'agent_turn_error' } : {}),threadTs: undefined,mediaAbsPaths: ['C:\\cindy-media\\generated.png'],allowedFileRoots: ['F:\\XDMaker'],diff --git a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.tsindex fe70317232..b5ad1c07f4 100644--- a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts+++ b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts@@ -57,6 +57,10 @@ const mocks = vi.hoisted(() => ({generateAndPersistFbotTitle: vi.fn(),dbSelect: vi.fn(),readRemoteRoute: vi.fn(),+ materializeLocalMarkdownImages: vi.fn(),+}));+vi.mock('../localMarkdownImages', () => ({+ materializeLocalMarkdownImages: mocks.materializeLocalMarkdownImages,}));vi.mock('../../remoteProviderRoute', () => ({ readImRemoteProviderRoute: mocks.readRemoteRoute }));@@ -286,6 +290,9 @@ beforeEach(() => {mocks.bindingGetAttachCardMessageId.mockReturnValue(null);mocks.generateAndPersistFbotTitle.mockResolvedValue(null);mocks.takePendingInteractionsForSession.mockReturnValue([]);+ mocks.materializeLocalMarkdownImages.mockImplementation(async ({ text }: { text: string }) => ({+ text, absPaths: [],+ }));// maker.createSession: 按 id 返回独立 harness(多 session 并行的关键)mocks.getMaker.mockReturnValue({getSession: vi.fn((id: string) => harnesses.get(id)?.session),@@ -1104,6 +1111,40 @@ describe('turnRunner 自动任务转播(scheduler turn → 远程控制 thread)'const withOrigin = (e: Partial<AgentEvent>): AgentEvent =>({ ...e, turnOrigin: schedulerOrigin }) as AgentEvent;+ // #7125 review, unit: a lone image component used to miss attachment collection.+ // Exercise background delivery through the runner; only file import is stubbed.+ it('delivers background image components as chunked-text attachments', async () => {+ const previousOutput = fakeAdapter.output;+ fakeAdapter.output = {+ kind: 'chunked-text', im: mocks.slackIm as unknown as ChannelIM, commitFinal: vi.fn(async () => undefined),+ };+ await runner.disposeAllSessions();+ runner = createTurnRunner(fakeAdapter, fakeRepo, fakeCards);+ try {+ const h = await attachAndIdle();+ const imagePath = path.join('/tmp', 'desktop-wd', 'chart.png');+ const managedPath = path.join('/tmp', 'test-media', 'chart.png');+ mocks.materializeLocalMarkdownImages.mockResolvedValue({ text: 'Chart', absPaths: [managedPath] });+ const source = '```cindy-ui\n' + JSON.stringify({+ version: 1, seq: 1, op: 'create', id: 'image', kind: 'image', props: { src: imagePath, alt: 'Chart' },+ }) + '\n```';+ h.emit(withOrigin({ type: 'text', data: { text: source, isFinal: true } }));+ h.emit(withOrigin({ type: 'done', data: {} }));+ await vi.waitFor(() => expect(mocks.slackIm.sendFile).toHaveBeenCalledWith(+ 'U1', managedPath, undefined, { threadTs: '300.3' },+ ));+ expect(mocks.materializeLocalMarkdownImages).toHaveBeenCalledWith(expect.objectContaining({+ text: ``,+ }));+ expect(mocks.slackIm.sendMarkdownText).toHaveBeenCalledWith(+ 'U1', expect.stringContaining('Chart'), { threadTs: '300.3' },+ );+ } finally {+ await runner.disposeAllSessions();+ fakeAdapter.output = previousOutput;+ }+ });+// #6884, unit: the same component fence must be projected for background// streaming/final delivery. Existing relay tests only covered plain Markdown.it.each(['rich-card', 'chunked-text'] as const)('projects background rich answers for %s', async (kind) => {diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.tsindex e4b8551b9d..2b4e0580ac 100644--- a/apps/desktop/src/main/im/shared/turnRunner.ts+++ b/apps/desktop/src/main/im/shared/turnRunner.ts@@ -3202,9 +3202,12 @@ export function createTurnRunner(return;}if (silenced && !t.streamingHandlePromise) return;- if (output.kind === 'chunked-text' && !state.makerSession.remoteHostId && t.buffer.includes('![')) {+ // Component images become Markdown only after projection. Collect from the+ // outbound copy so the text channel cannot strip an uncollected image.+ const projectedBody = composeOutboundBody(t.buffer, true);+ if (output.kind === 'chunked-text' && !state.makerSession.remoteHostId && projectedBody.includes('![')) {const materialized = await materializeLocalMarkdownImages({- text: t.buffer, workingDir: state.workingDir, sessionId: state.makerSession.id,+ text: projectedBody, workingDir: state.workingDir, sessionId: state.makerSession.id,maxImages: 4, existingAbsPaths: t.mediaAbsPaths,});t.buffer = materialized.text;@@ -3911,14 +3914,15 @@ export function createTurnRunner(async function materializeTurnLocalImages(state: SessionState, turn: TurnState): Promise<void> {if (output.kind !== 'chunked-text' ||- turn.allowedFileRoots.length === 0 ||- !turn.presenter.wholeText().includes('![')+ turn.allowedFileRoots.length === 0) {return;}+ const projectedBody = composeOutboundBody(turn.presenter.wholeText(), true);+ if (!projectedBody.includes('![')) return;try {const materialized = await materializeLocalMarkdownImages({- text: turn.presenter.wholeText(),+ text: projectedBody,workingDir: state.workingDir,sessionId: state.makerSession.id,maxImages: 4,