Files
Genarrative/src/components/image-editor/EditorAgentConversation/MessageBubble.test.tsx
T
k88936 f5368c825f Editor agent refactored (#76)
重构了editor agent.
使得它能进行多轮工具调用, 把工具调用的结果嵌入到上下文里。
对于上下文的图片, 使用哈希后的id用来引用,不暴露细节信息to llm。
当前实现, 状态直接维护在json doc里, 需要对整个doc加锁,任务目前只能串行。
把SSE改成一个简单请求( 因为生图工具耗时需要二次确认, 不需要再实时展示给用户进度)。
增加确认/取消生图操作。
把tool的参数和错误情况做了反馈。

TODO:  工具调用的规范/prompt还可以改进。

改用external job来做素材生成, 针对来自editor agent 的生成会把生成资产的引用加入到结果json里,
客户端轮询 external job 确定生成状态, 发现结束了或者失败了就 重新get 会话,后端重新提供会话的时候把 结果插入回会话历史里,用来让 ai 引用 以及显示

---------

Co-authored-by: 段舒康 <kdletters@qq.com>
Reviewed-on: https://git.genarrative.world/git/GenarrativeAI/Genarrative/pulls/76
Reviewed-by: 段舒康 <kdletters@qq.com>
Co-authored-by: 王德宇 <kvtodev@outlook.com>
Co-committed-by: 王德宇 <kvtodev@outlook.com>
2026-07-17 21:03:15 +08:00

54 lines
1.5 KiB
TypeScript

/* @vitest-environment jsdom */
import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import type { EditorAgentMessage } from '@/packages/shared/src/contracts';
import { MessageBubble } from './MessageBubble.tsx';
function renderMessage(message: EditorAgentMessage) {
return render(
<MessageBubble
message={message}
busyAction={null}
onConfirmToolCall={vi.fn()}
onCancelToolCall={vi.fn()}
/>,
);
}
describe('MessageBubble', () => {
it('shows prefixed system errors as red Agent errors without the wire prefix', () => {
renderMessage({
id: 2,
role: 'system',
text: 'ERROR planning failed',
attachments: [],
toolCall: null,
createdAt: '2026-07-16T00:00:00Z',
});
const error = screen.getByLabelText('Agent错误');
expect(error.textContent).toContain('planning failed');
expect(error.textContent).not.toContain('ERROR');
expect(error.firstElementChild?.classList.contains('bg-red-50')).toBe(true);
expect(error.firstElementChild?.classList.contains('text-red-700')).toBe(
true,
);
});
it('continues to hide internal system messages without the error prefix', () => {
const { container } = renderMessage({
id: 3,
role: 'system',
text: 'internal attachment bookkeeping',
attachments: [],
toolCall: null,
createdAt: '2026-07-16T00:00:00Z',
});
expect(container.childElementCount).toBe(0);
});
});