Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(agent-island): 将富组件回复转换为可读活动摘要
Dashfb0399533974
diff --git a/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts b/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.tsindex 66aab66a3e..4ccc66ef9d 100644--- a/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts@@ -4,6 +4,7 @@ import {AGENT_ISLAND_ACTIVITY_TEXT_MAX_LENGTH,appendActivityTextStream,createActivityTextStreamState,+ normalizeActivityText,type ActivityTextStreamMetrics,} from '../activityTextStream.js';@@ -70,6 +71,44 @@ function legacyExtractTextFromStructuredContent(value: unknown): string | null {}describe('Agent Island activity text stream', () => {+ // Regression: Island preferred raw activity over the already-readable companion preview.+ // Unit tier; exercise the production normalizer/stream with a minimal rich answer.+ const richAnswer = '```cindy-ui\n'+ + '{"version":1,"seq":1,"op":"create","id":"answer","kind":"text","props":{"text":"网络检查完成"}}\n'+ + '```';++ it('extracts component text before truncating final activity previews', () => {+ expect(normalizeActivityText(richAnswer)).toBe('网络检查完成');+ expect(normalizeActivityText(JSON.stringify({ content: richAnswer }))).toBe('网络检查完成');+ expect(normalizeActivityText(`检查结果\n${richAnswer}\n可以继续使用。`))+ .toBe('检查结果 网络检查完成 可以继续使用。');+ });++ it('keeps rich protocol out of streamed previews across delta boundaries', () => {+ const stream = createActivityTextStreamState();+ for (const chunk of ['```cindy-', 'ui\n', '{"version":1,',+ '"seq":1,"op":"create","id":"answer","kind":"text","props":{"text":"网络检查完成"}}\n', '```']) {+ expect(appendActivityTextStream(stream, chunk)).not.toMatch(/cindy-|version|seq|create|props/);+ }+ expect(appendActivityTextStream(stream, '')).toBe('网络检查完成');+ });++ it('preserves ordinary code and explicitly quoted rich protocol examples', () => {+ const example = `\`\`\`\`markdown\n${richAnswer}\n\`\`\`\``;+ expect(normalizeActivityText(example)).toBe(legacyNormalizeActivityText(example));+ const code = '```json\n{"status":"ok"}\n```';+ expect(normalizeActivityText(code)).toBe(legacyNormalizeActivityText(code));+ });++ it('hides a truncated rich operation until the full final text is available', () => {+ const source = '```cindy-ui\n'+ + JSON.stringify({ version: 1, seq: 1, op: 'create', id: 'answer', kind: 'text',+ props: { style: { padding: 12 }, text: '检查完成。'.repeat(100) } }) + '\n```';+ const stream = createActivityTextStreamState();+ expect(appendActivityTextStream(stream, source)).toBe('');+ expect(normalizeActivityText(source)).toBe('检查完成。'.repeat(100).slice(0, AGENT_ISLAND_ACTIVITY_TEXT_MAX_LENGTH));+ });+it('preserves the existing display text across whitespace, markdown, emoji, and the 280-code-unit boundary', () => {expectEveryStreamingStepToMatchLegacyNormalization(['\n ',diff --git a/apps/desktop/src/main/agent-island/__tests__/state.test.ts b/apps/desktop/src/main/agent-island/__tests__/state.test.tsindex a008d949d2..bd40b6756d 100644--- a/apps/desktop/src/main/agent-island/__tests__/state.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/state.test.ts@@ -941,6 +941,27 @@ describe('Agent Island display state', () => {expect(display.sessions[0]?.compactDetail).toBe('我已经完成了第一步,并且正在继续处理后续内容。');});+ // Unit regression: the real display builder must use readable rich-answer activity+ // both during output and after done, not expose the component transport in the island.+ it('shows readable rich answers in running and completed companion cards', () => {+ const state = createAgentIslandState();+ const meta = { sessionId: 's1', companion: { name: '电脑管家', hue: 'blue' as const, glyph: '电', glyphIsInitial: true } };+ const source = '```cindy-ui\n'+ + '{"version":1,"seq":1,"op":"create","id":"answer","kind":"text","props":{"text":"网络检查完成"}}\n```';+ applyAgentIslandEvent(state, meta, statusEvent(true, 'Generating...'), 1_000);+ for (const character of source) {+ applyAgentIslandEvent(state, meta, textDeltaEvent(character), 1_050);+ const preview = buildAgentIslandDisplayState(state, 1_060).sessions[0]?.compactDetail ?? '';+ expect(preview).not.toMatch(/cindy|version|seq|create|props|`/);+ }+ applyAgentIslandEvent(state, meta, finalTextEvent(source), 1_100);+ expect(buildAgentIslandDisplayState(state, 1_200).sessions[0])+ .toMatchObject({ compactDetail: '网络检查完成', phase: 'running' });+ applyAgentIslandEvent(state, meta, doneEvent(), 1_300);+ expect(buildAgentIslandDisplayState(state, 1_400).sessions[0])+ .toMatchObject({ compactDetail: '网络检查完成', phase: 'completed' });+ });+it('keeps generic running status behind assistant text in compact detail', () => {const state = createAgentIslandState();diff --git a/apps/desktop/src/main/agent-island/activityTextStream.ts b/apps/desktop/src/main/agent-island/activityTextStream.tsindex 73e2a6891c..cc82badbd1 100644--- a/apps/desktop/src/main/agent-island/activityTextStream.ts+++ b/apps/desktop/src/main/agent-island/activityTextStream.ts@@ -1,3 +1,5 @@+import { richAnswerText } from '@cindy/maker-shared/rich-answer';+export const AGENT_ISLAND_ACTIVITY_TEXT_MAX_LENGTH = 280;type ActivityTextStreamMode = 'pending' | 'plain' | 'structured' | 'structured-extracted';@@ -7,6 +9,7 @@ export interface ActivityTextStreamState {rawChunks: string[];rawPreview: string;rawPreviewHasPendingWhitespace: boolean;+ rawPreviewHasPendingNewline: boolean;jsonClosingStack: Array<'}' | ']'>;jsonInString: boolean;jsonEscapePending: boolean;@@ -27,6 +30,7 @@ export function createActivityTextStreamState(): ActivityTextStreamState {rawChunks: [],rawPreview: '',rawPreviewHasPendingWhitespace: false,+ rawPreviewHasPendingNewline: false,jsonClosingStack: [],jsonInString: false,jsonEscapePending: false,@@ -96,7 +100,7 @@ export function appendActivityTextStream(if (extracted) {state.mode = 'structured-extracted';if (metrics) metrics.normalizationCodeUnits += extracted.length;- state.structuredDisplayText = normalizePlainActivityText(extracted);+ state.structuredDisplayText = normalizePlainActivityText(richAnswerText(extracted));releaseStructuredParserState(state);return state.structuredDisplayText;}@@ -127,7 +131,7 @@ function appendRetainedRawChunk(state: ActivityTextStreamState, chunk: string):}export function normalizeActivityText(text: string): string {- return normalizePlainActivityText(extractActivityDisplayText(text));+ return normalizePlainActivityText(richAnswerText(extractActivityDisplayText(text)));}function appendRawPreview(@@ -142,12 +146,16 @@ function appendRawPreview(const codeUnit = chunk[index] ?? '';if (/\s/.test(codeUnit)) {if (state.rawPreview) state.rawPreviewHasPendingWhitespace = true;+ if (codeUnit === '\n' || codeUnit === '\r') state.rawPreviewHasPendingNewline = true;continue;}if (state.rawPreviewHasPendingWhitespace) {- state.rawPreview += ' ';+ // Keep fence/operation boundaries until rich content has been projected to text.+ // The retained prefix remains bounded; final events normalize the full answer.+ state.rawPreview += state.rawPreviewHasPendingNewline ? '\n' : ' ';state.rawPreviewHasPendingWhitespace = false;+ state.rawPreviewHasPendingNewline = false;if (state.rawPreview.length >= AGENT_ISLAND_ACTIVITY_TEXT_MAX_LENGTH) return;}@@ -230,7 +238,12 @@ function releaseStructuredParserState(state: ActivityTextStreamState): void {}function rawPreviewText(state: ActivityTextStreamState): string {- return state.rawPreview.trim();+ // A fence header may itself arrive in several deltas. Do not leave that+ // temporary header as the last visible activity when the rich block is empty.+ const source = state.rawPreview.replace(/(^|\n)(`{1,3}|~{1,3})([^\n]*)$/, (line, _boundary, _fence, language: string) =>+ 'cindy-ui'.startsWith(language.trim()) ? '' : line,+ );+ return normalizePlainActivityText(richAnswerText(source));}function normalizePlainActivityText(text: string): string {