feat: prepare Zhinian desktop client for pilot release

This commit is contained in:
inman
2026-04-29 10:23:20 +08:00
parent f9361e686a
commit 47b83b79fc
149 changed files with 15341 additions and 3590 deletions

View File

@@ -185,4 +185,71 @@ describe('chat target routing', () => {
expect(payload.message).toBe('Process the attached file(s).');
expect(payload.media[0]?.filePath).toBe('/tmp/design.png');
});
it('injects knowledge-base file references when requested', async () => {
hostApiFetchMock.mockImplementation(async (url: string, options?: { body?: string }) => {
if (url === '/api/knowledge/context') {
const body = JSON.parse(String(options?.body ?? '{}')) as { workspaceId?: string; documentIds?: string[] };
expect(body).toEqual({
workspaceId: 'workspace-1',
documentIds: ['kb-1'],
});
return {
success: true,
context: [
'[知识库上下文]',
'## handbook.docx',
'Refunds are available within 7 days.',
].join('\n'),
documents: [
{
id: 'kb-1',
name: 'handbook.docx',
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
storedPath: '/kb/files/handbook.docx',
textPath: '/kb/texts/handbook.txt',
},
],
};
}
return { success: true, result: { runId: 'run-media' } };
});
const { useChatStore } = await import('@/stores/chat');
useChatStore.setState({
currentSessionKey: 'agent:main:main',
currentAgentId: 'main',
sessions: [{ key: 'agent:main:main' }],
messages: [],
sessionLabels: {},
sessionLastActivity: {},
sending: false,
activeRunId: null,
streamingText: '',
streamingMessage: null,
streamingTools: [],
pendingFinal: false,
lastUserMessageAt: null,
pendingToolImages: [],
error: null,
loading: false,
thinkingLevel: null,
});
await useChatStore.getState().sendMessage('What is our refund policy?', undefined, null, {
useKnowledgeBase: true,
workspaceId: 'workspace-1',
selectedKnowledgeDocumentIds: ['kb-1'],
});
const sendCall = gatewayRpcMock.mock.calls.find(([method]) => method === 'chat.send');
expect(sendCall?.[1]).toMatchObject({
sessionKey: 'agent:main:main',
deliver: false,
});
expect((sendCall?.[1] as { message: string }).message).toContain('What is our refund policy?');
expect((sendCall?.[1] as { message: string }).message).toContain('[知识库上下文]');
expect((sendCall?.[1] as { message: string }).message).toContain('handbook.docx');
expect((sendCall?.[1] as { message: string }).message).toContain('Refunds are available within 7 days.');
});
});