| | |
| | | import React, { useEffect, useState } from "react"; |
| | | import { useTranslate } from "react-admin"; |
| | | import { Alert, Box, Card, CardContent, Chip, CircularProgress, Grid, Stack, Typography } from "@mui/material"; |
| | | import { getAiConfigSummary } from "@/api/ai/configCenter"; |
| | | |
| | | const AiRuntimeSummary = ({ promptCode = "home.default" }) => { |
| | | const translate = useTranslate(); |
| | | const [summary, setSummary] = useState(null); |
| | | const [loading, setLoading] = useState(true); |
| | | const [error, setError] = useState(""); |
| | |
| | | if (!active) { |
| | | return; |
| | | } |
| | | setError(err?.message || "获取运行态摘要失败"); |
| | | setError(err?.message || translate("ai.runtimeSummary.fetchFailed")); |
| | | }) |
| | | .finally(() => { |
| | | if (active) { |
| | |
| | | <CardContent> |
| | | <Stack direction="row" justifyContent="space-between" alignItems="center" mb={2}> |
| | | <Box> |
| | | <Typography variant="h6">当前运行态</Typography> |
| | | <Typography variant="h6">{translate("ai.runtimeSummary.title")}</Typography> |
| | | <Typography variant="body2" color="text.secondary"> |
| | | 展示当前生效的模型、Prompt 与 MCP 挂载信息。 |
| | | {translate("ai.runtimeSummary.description")} |
| | | </Typography> |
| | | </Box> |
| | | {loading && <CircularProgress size={24} />} |
| | |
| | | {!loading && !error && summary && ( |
| | | <Grid container spacing={2}> |
| | | <Grid item xs={12} md={4}> |
| | | <Typography variant="caption" color="text.secondary">当前模型</Typography> |
| | | <Typography variant="caption" color="text.secondary">{translate("ai.runtimeSummary.currentModel")}</Typography> |
| | | <Typography variant="body1">{summary.activeModel || "--"}</Typography> |
| | | <Typography variant="body2" color="text.secondary"> |
| | | {summary.activeParamName || "--"} |
| | | </Typography> |
| | | <Stack direction="row" spacing={1} mt={1} flexWrap="wrap" useFlexGap> |
| | | <Chip size="small" label={`校验 ${summary.activeParamValidateStatus || "--"}`} /> |
| | | <Chip size="small" variant="outlined" label={summary.activeParamValidatedAt || "未校验"} /> |
| | | <Chip size="small" label={translate("ai.runtimeSummary.validateStatus", { status: summary.activeParamValidateStatus || "--" })} /> |
| | | <Chip size="small" variant="outlined" label={summary.activeParamValidatedAt || translate("ai.common.notValidated")} /> |
| | | </Stack> |
| | | </Grid> |
| | | <Grid item xs={12} md={4}> |
| | | <Typography variant="caption" color="text.secondary">当前 Prompt</Typography> |
| | | <Typography variant="caption" color="text.secondary">{translate("ai.runtimeSummary.currentPrompt")}</Typography> |
| | | <Typography variant="body1">{summary.promptName || "--"}</Typography> |
| | | <Typography variant="body2" color="text.secondary"> |
| | | {summary.promptCode || "--"} / {summary.promptScene || "--"} |
| | | </Typography> |
| | | <Typography variant="body2" color="text.secondary" mt={1}> |
| | | 最近更新:{summary.activePromptUpdatedAt || "--"} / {summary.activePromptUpdatedBy || "--"} |
| | | {translate("ai.runtimeSummary.lastUpdated", { |
| | | time: summary.activePromptUpdatedAt || "--", |
| | | user: summary.activePromptUpdatedBy || "--", |
| | | })} |
| | | </Typography> |
| | | </Grid> |
| | | <Grid item xs={12} md={4}> |
| | | <Typography variant="caption" color="text.secondary">已启用 MCP</Typography> |
| | | <Typography variant="body1">{summary.enabledMcpCount ?? 0} 个</Typography> |
| | | <Typography variant="caption" color="text.secondary">{translate("ai.runtimeSummary.enabledMcp")}</Typography> |
| | | <Typography variant="body1">{translate("ai.runtimeSummary.enabledMcpCount", { count: summary.enabledMcpCount ?? 0 })}</Typography> |
| | | <Stack direction="row" spacing={1} mt={1} flexWrap="wrap" useFlexGap> |
| | | {(summary.enabledMcpNames || []).map((name) => ( |
| | | <Chip key={name} size="small" variant="outlined" label={name} /> |