Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): preserve captions and incomplete chart source in group bodies

ylliuuu66dc8134e5b988
diff --git a/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts b/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts
index 5c6f0ad818..c539e45ea4 100644
--- a/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts
+++ b/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts
@@ -161,6 +161,29 @@ describe('queue lanes', () => {
// #6550: display-only projection. Existing presentation tests had no component bodies.
describe('group body component display', () => {
const rich = (...nodes: Array<Record<string, unknown>>) => '```cindy-ui\n' + nodes.map((node, i) => JSON.stringify({ version: 1, seq: i + 1, op: 'create', id: `n${i}`, ...node })).join('\n') + '\n```';
+ it('preserves a code caption as literal text after the code', () => {
+ const content = rich({ kind: 'code', props: { text: 'const x = 1;', language: 'js', caption: '<name> *literal*' } });
+ expect(botGroupBodyParts(content, 'bot')).toEqual([
+ { kind: 'markdown', content: '```js\nconst x = 1;\n```' },
+ { kind: 'text', content: '<name> *literal*' },
+ ]);
+ });
+ it('retains the source block when a chart has an unavailable item', () => {
+ const block = rich({ kind: 'chart', props: { label: 'Totals', data: [
+ { label: 'Known', value: 3 }, { label: 'Missing', value: { ref: 'missing' } },
+ ] } });
+ expect(botGroupBodyParts('Before\n\n' + block + '\nAfter', 'bot')).toEqual([
+ { kind: 'markdown', content: 'Before\n\n' },
+ { kind: 'markdown', content: block + '\n' },
+ { kind: 'markdown', content: 'After' },
+ ]);
+ });
+ it('still projects a fully resolved chart including zero', () => {
+ const content = rich({ kind: 'chart', props: { label: 'Totals', data: [
+ { label: 'Zero', value: 0 }, { label: 'Known', value: 3 },
+ ] } });
+ expect(botGroupBodyParts(content, 'bot')).toEqual([{ kind: 'text', content: 'Totals\nZero: 0\nKnown: 3' }]);
+ });
it('keeps literal text literal, Markdown authored formatting, and surrounding prose in order', () => {
const content = 'Before\n\n' + rich({ kind: 'text', props: { text: '<name> *literal* & \n indented' } }, { kind: 'markdown', props: { text: '**bold**' } }) + '\nAfter';
expect(botGroupBodyParts(content, 'bot')).toEqual([
diff --git a/packages/maker-shared/src/botGroupPresentation.ts b/packages/maker-shared/src/botGroupPresentation.ts
index 58efd3735c..272c2afd8f 100644
--- a/packages/maker-shared/src/botGroupPresentation.ts
+++ b/packages/maker-shared/src/botGroupPresentation.ts
@@ -3,7 +3,7 @@
* 排序、成员名单、轮次标记与分工(安排、下一步、交接文件)的判定,以及提示 / 报错
* 该用哪一句文案(各端按自己的 i18n 命名空间拼 key)。只依赖群聊契约,不碰 React 与 IPC。
*/
-import { RichAnswerStream, splitRichAnswer, richMarkdown, richString, richLabel, richResolvedValues, richChart, richOptions } from './richAnswer.js';
+import { RichAnswerStream, splitRichAnswer, richMarkdown, richString, richLabel, richResolvedValues, richChart, richOptions, richCalculationUnavailable } from './richAnswer.js';
import {
isBotGroupPlanOpen,
type BotGroupDetail,
@@ -359,6 +359,7 @@ export function botGroupBodyParts(content: string, authorKind?: BotGroupMessageV
// Preserve malformed or empty answers rather than silently dropping source content.
if (doc.issues) return [{ kind: 'markdown' as const, content: source }];
const values = richResolvedValues(doc);
+ let unavailableChart = false;
const result: Array<{ kind: 'text' | 'markdown'; content: string }> = [];
const add = (text: string, kind: 'text' | 'markdown' = 'text') => {
if (text.trim()) result.push({ kind, content: text });
@@ -372,10 +373,16 @@ export function botGroupBodyParts(content: string, authorKind?: BotGroupMessageV
add([label, richString(node, 'alt'), richString(node, 'caption'), richString(node, 'src')].filter(Boolean).join('\n'));
} else {
const markdown = richMarkdown(node);
- if (markdown !== null) add(markdown, 'markdown');
+ if (markdown !== null) {
+ add(markdown, 'markdown');
+ add(richString(node, 'caption'));
+ }
else if (['text', 'heading'].includes(node.kind)) add(richLabel(node, values));
else if (node.kind === 'stat') add([label, richLabel(node, values)].filter(Boolean).join(': '));
- else if (node.kind === 'chart') add([label, ...richChart(node, values).map(item => `${item.label}: ${item.value}`)].filter(Boolean).join('\n'));
+ else if (node.kind === 'chart') {
+ unavailableChart ||= richCalculationUnavailable(node, values);
+ add([label, ...richChart(node, values).map(item => `${item.label}: ${item.value}`)].filter(Boolean).join('\n'));
+ }
else if (node.kind === 'icon') add([label, richString(node, 'text')].filter(Boolean).join('\n'));
else if (node.kind === 'divider') add('---', 'markdown');
else {
@@ -389,6 +396,7 @@ export function botGroupBodyParts(content: string, authorKind?: BotGroupMessageV
node.children.forEach(visit);
};
doc.roots.forEach(visit);
- return result.length ? result : [{ kind: 'markdown' as const, content: source }];
+ // Do not present a partial chart as complete data; preserve its source block.
+ return result.length && !unavailableChart ? result : [{ kind: 'markdown' as const, content: source }];
});
}