feat: AI 对话支持 A2UI 表单/审查/图表与 Excel 读取
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
import type { MessageInfo } from '@ant-design/x-sdk';
|
||||
import type { AiChatMessage, AiChatMessageStatus, AiMessageRecord, AiToolRun } from './types';
|
||||
import type {
|
||||
AiChatMessage,
|
||||
AiChatMessageStatus,
|
||||
AiChartSchema,
|
||||
AiFormSchema,
|
||||
AiMessageRecord,
|
||||
AiReviewSchema,
|
||||
AiToolRun,
|
||||
} from './types';
|
||||
|
||||
function mapStatus(record: AiMessageRecord): AiChatMessageStatus {
|
||||
if (record.status === 'pending') return 'loading';
|
||||
@@ -16,6 +24,32 @@ function normalizeToolRun(tool: AiToolRun): AiToolRun {
|
||||
};
|
||||
}
|
||||
|
||||
function historyForms(record: AiMessageRecord): AiFormSchema[] | undefined {
|
||||
const a2uiForm = record.metadata?.a2uiForm;
|
||||
if (!a2uiForm || typeof a2uiForm !== 'object' || Array.isArray(a2uiForm)) return undefined;
|
||||
return [a2uiForm as AiFormSchema];
|
||||
}
|
||||
|
||||
function historyReviews(record: AiMessageRecord): AiReviewSchema[] | undefined {
|
||||
const a2uiReview = record.metadata?.a2uiReview;
|
||||
if (!a2uiReview || typeof a2uiReview !== 'object' || Array.isArray(a2uiReview)) {
|
||||
return undefined;
|
||||
}
|
||||
return [a2uiReview as AiReviewSchema];
|
||||
}
|
||||
|
||||
function historyCharts(record: AiMessageRecord): AiChartSchema[] | undefined {
|
||||
const a2uiChart = record.metadata?.a2uiChart;
|
||||
if (Array.isArray(a2uiChart)) {
|
||||
return a2uiChart.filter(
|
||||
(item): item is AiChartSchema =>
|
||||
Boolean(item) && typeof item === 'object' && typeof (item as AiChartSchema).id === 'string',
|
||||
);
|
||||
}
|
||||
if (!a2uiChart || typeof a2uiChart !== 'object') return undefined;
|
||||
return [a2uiChart as AiChartSchema];
|
||||
}
|
||||
|
||||
export function mapHistoryMessage(record: AiMessageRecord): MessageInfo<AiChatMessage> {
|
||||
return {
|
||||
id: record.id,
|
||||
@@ -27,6 +61,9 @@ export function mapHistoryMessage(record: AiMessageRecord): MessageInfo<AiChatMe
|
||||
reasoningContent: record.reasoningContent || '',
|
||||
toolRuns: (record.toolRuns || []).map(normalizeToolRun),
|
||||
attachments: record.attachments ?? [],
|
||||
forms: historyForms(record),
|
||||
reviews: historyReviews(record),
|
||||
charts: historyCharts(record),
|
||||
replyToMessageId: record.replyToMessageId,
|
||||
feedback: record.feedback,
|
||||
feedbackReason: record.feedbackReason,
|
||||
|
||||
Reference in New Issue
Block a user