feat: 全新智能体功能
- 基于先进智能体框架,增加智能体编排功能 - 增加智能体聊天,并对接持久化
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
import {
|
||||
ChatTimeHistoryMapper,
|
||||
ChatTimeTimelineBuilder,
|
||||
} from '../chat-time';
|
||||
import {ChatTimeHistoryMapper, ChatTimeTimelineBuilder,} from '../chat-time';
|
||||
|
||||
describe('chat-time timeline builder', () => {
|
||||
it('builds assistant thinking and message in the same assistant item', () => {
|
||||
@@ -29,6 +26,37 @@ describe('chat-time timeline builder', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('appends markdown deltas without altering repeated symbols', () => {
|
||||
const items: any[] = [];
|
||||
|
||||
ChatTimeTimelineBuilder.appendThinkingDelta(items, '先想一下', 1);
|
||||
ChatTimeTimelineBuilder.appendMessageDelta(items, '## 标题\n', 2);
|
||||
ChatTimeTimelineBuilder.appendMessageDelta(items, '| 模型 | 说明 |\n', 3);
|
||||
ChatTimeTimelineBuilder.appendMessageDelta(items, '| --- | --- |\n', 4);
|
||||
ChatTimeTimelineBuilder.appendMessageDelta(items, '| ACL | 访问控制列表 |\n', 5);
|
||||
ChatTimeTimelineBuilder.appendMessageDelta(
|
||||
items,
|
||||
'Final Answer: ```echartsoption',
|
||||
6,
|
||||
);
|
||||
|
||||
expect(items).toHaveLength(1);
|
||||
expect(items[0]).toMatchObject({
|
||||
content:
|
||||
'## 标题\n| 模型 | 说明 |\n| --- | --- |\n| ACL | 访问控制列表 |\nFinal Answer: ```echartsoption',
|
||||
role: 'assistant',
|
||||
typing: true,
|
||||
});
|
||||
expect(items[0].segments).toMatchObject([
|
||||
{ content: '先想一下', status: 'end', type: 'thinking' },
|
||||
{
|
||||
content:
|
||||
'## 标题\n| 模型 | 说明 |\n| --- | --- |\n| ACL | 访问控制列表 |\nFinal Answer: ```echartsoption',
|
||||
type: 'text',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('creates a new assistant item after tool result', () => {
|
||||
const items: any[] = [];
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
ChatTimeToolStatus,
|
||||
} from '../../../types/src/chat-time';
|
||||
|
||||
import { uuid } from './uuid';
|
||||
import {uuid} from './uuid';
|
||||
|
||||
type ChatTimeToolMeta = {
|
||||
arguments?: string;
|
||||
@@ -159,6 +159,35 @@ class ChatTimeTimelineBuilder {
|
||||
assistant.typing = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用最终完整回答替换当前 assistant 文本。
|
||||
*/
|
||||
static replaceMessageContent(
|
||||
items: ChatTimeTimelineItem[],
|
||||
content?: string,
|
||||
created?: number | string,
|
||||
meta?: ChatTimeRoundMeta,
|
||||
) {
|
||||
const normalizedContent = normalizeAssistantText(content);
|
||||
if (!normalizedContent) {
|
||||
return;
|
||||
}
|
||||
prepareRoundVariant(items, meta);
|
||||
const assistant = ensureAssistantTail(items, created, meta);
|
||||
stopThinkingForAssistant(assistant);
|
||||
assistant.content = normalizedContent;
|
||||
assistant.segments = [
|
||||
...assistant.segments.filter((segment) => segment.type !== 'text'),
|
||||
{
|
||||
content: normalizedContent,
|
||||
id: uuid(),
|
||||
type: 'text' as const,
|
||||
},
|
||||
];
|
||||
assistant.loading = false;
|
||||
assistant.typing = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前 assistant 的思考态。
|
||||
*/
|
||||
@@ -1003,9 +1032,7 @@ function normalizePositiveInteger(value: any) {
|
||||
}
|
||||
|
||||
function normalizeAssistantText(value: any) {
|
||||
return normalizePlainText(value)
|
||||
.replace(/^Final Answer:\s*/i, '')
|
||||
.replaceAll('```echartsoption', '```echarts\noption');
|
||||
return normalizePlainText(value);
|
||||
}
|
||||
|
||||
function normalizePayloadValue(value: any) {
|
||||
|
||||
Reference in New Issue
Block a user