Refactor AI chat: streaming, tool calls, UI polish
All checks were successful
CI / check (pull_request) Successful in 3m25s

This commit is contained in:
2026-07-24 16:27:50 +08:00
parent e605586fc9
commit 8656394b9b
55 changed files with 2774 additions and 460 deletions

View File

@@ -25,6 +25,7 @@ function createService(conversationOverrides: Record<string, unknown> = {}) {
{} as never,
{} as never,
{} as never,
{} as never,
);
return { service, conversations };
}
@@ -82,7 +83,13 @@ describe('AiChatService', () => {
{ abort: false, expectedStatus: 'failed', expectedCode: 'UPSTREAM_ERROR' },
{ abort: true, expectedStatus: 'cancelled', expectedCode: 'CLIENT_ABORTED' },
])('流中断后保存已生成内容和 $expectedStatus 状态', async ({ abort, expectedStatus, expectedCode }) => {
const conversation = { id: 3, userId: 7, title: '测试', lastMessageAt: null };
const conversation = {
id: 3,
userId: 7,
title: '测试',
lockedSkillKey: null,
lastMessageAt: null,
};
const assistant = {
id: 12,
conversationId: 3,
@@ -123,15 +130,25 @@ describe('AiChatService', () => {
messages as never,
{ save: jest.fn() } as never,
{ transaction: jest.fn(async (callback) => callback(manager)) } as never,
{ getRuntimeConfig: jest.fn().mockResolvedValue({}) } as never,
{ getRuntimeConfig: jest.fn().mockResolvedValue({ supportsVision: false }) } as never,
{ listAvailable: jest.fn().mockReturnValue([]) } as never,
modelStream as never,
{
requireReadyOwned: jest.fn().mockResolvedValue([]),
toModelParts: jest.fn().mockResolvedValue([]),
serialize: jest.fn((value) => value),
} as never,
);
const emitted: Array<{ event: string; data: Record<string, unknown> }> = [];
const run = service.streamMessage(
authenticatedUser as never,
3,
'查询',
{
message: '查询',
attachmentIds: [],
skillKey: null,
clientRequestId: '6a8bc680-3cb5-4f2d-85ee-974974e0f194',
},
abortController.signal,
(event, data) => emitted.push({ event, data }),
jest.fn(),