feat: 集成 AI 对话与只读查询工具
This commit is contained in:
33
apps/admin/src/components/AiChat/message-mappers.ts
Normal file
33
apps/admin/src/components/AiChat/message-mappers.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { MessageInfo } from '@ant-design/x-sdk';
|
||||
import type { AiChatMessage, AiChatMessageStatus, AiMessageRecord, AiToolRun } from './types';
|
||||
|
||||
function mapStatus(record: AiMessageRecord): AiChatMessageStatus {
|
||||
if (record.status === 'pending') return 'loading';
|
||||
if (record.status === 'failed') return 'error';
|
||||
if (record.status === 'cancelled') return 'abort';
|
||||
return record.role === 'user' ? 'local' : 'success';
|
||||
}
|
||||
|
||||
function normalizeToolRun(tool: AiToolRun): AiToolRun {
|
||||
return {
|
||||
...tool,
|
||||
status: tool.status === 'error' ? 'failed' : tool.status,
|
||||
summary: tool.resultSummary ?? tool.argumentsSummary ?? tool.summary,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapHistoryMessage(record: AiMessageRecord): MessageInfo<AiChatMessage> {
|
||||
return {
|
||||
id: record.id,
|
||||
status: mapStatus(record),
|
||||
message: {
|
||||
id: record.id,
|
||||
role: record.role,
|
||||
content: record.content || '',
|
||||
reasoningContent: record.reasoningContent || '',
|
||||
toolRuns: (record.toolRuns || []).map(normalizeToolRun),
|
||||
error: record.status === 'failed' ? record.errorCode || 'AI 回答生成失败' : undefined,
|
||||
cancelled: record.status === 'cancelled',
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user