feat: 集成 AI 对话与只读查询工具
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { mapHistoryMessage } from './message-mappers';
|
||||
|
||||
describe('AI chat history mapper', () => {
|
||||
it('restores reasoning, tool summaries and completed status', () => {
|
||||
const mapped = mapHistoryMessage({
|
||||
id: 3,
|
||||
role: 'assistant',
|
||||
content: '回答',
|
||||
reasoningContent: '思考',
|
||||
status: 'completed',
|
||||
errorCode: null,
|
||||
createdAt: '2026-07-23T00:00:00.000Z',
|
||||
toolRuns: [
|
||||
{
|
||||
toolCallId: 'tool-1',
|
||||
toolName: 'search_rooms',
|
||||
status: 'success',
|
||||
resultSummary: '共 4 间',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(mapped.status).toBe('success');
|
||||
expect(mapped.message.reasoningContent).toBe('思考');
|
||||
expect(mapped.message.toolRuns[0].summary).toBe('共 4 间');
|
||||
});
|
||||
|
||||
it('maps failed and cancelled history to X SDK statuses', () => {
|
||||
const base = {
|
||||
id: 4,
|
||||
role: 'assistant' as const,
|
||||
content: '',
|
||||
reasoningContent: null,
|
||||
errorCode: 'UPSTREAM_ERROR',
|
||||
createdAt: '2026-07-23T00:00:00.000Z',
|
||||
};
|
||||
expect(mapHistoryMessage({ ...base, status: 'failed' }).status).toBe('error');
|
||||
expect(mapHistoryMessage({ ...base, status: 'cancelled' }).status).toBe('abort');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user