zhou zhou
14 小时以前 287a666e1b2bb155e86aa88ebace201d1e8a51f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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("");
 
    useEffect(() => {
        let active = true;
        setLoading(true);
        setError("");
        getAiConfigSummary(promptCode)
            .then((data) => {
                if (!active) {
                    return;
                }
                setSummary(data);
            })
            .catch((err) => {
                if (!active) {
                    return;
                }
                setError(err?.message || translate("ai.runtimeSummary.fetchFailed"));
            })
            .finally(() => {
                if (active) {
                    setLoading(false);
                }
            });
        return () => {
            active = false;
        };
    }, [promptCode]);
 
    return (
        <Box px={2} pt={2}>
            <Card
                variant="outlined"
                sx={{
                    borderRadius: 3,
                    boxShadow: "0 8px 24px rgba(15, 23, 42, 0.06)",
                }}
            >
                <CardContent>
                    <Stack direction="row" justifyContent="space-between" alignItems="center" mb={2}>
                        <Box>
                            <Typography variant="h6">{translate("ai.runtimeSummary.title")}</Typography>
                            <Typography variant="body2" color="text.secondary">
                                {translate("ai.runtimeSummary.description")}
                            </Typography>
                        </Box>
                        {loading && <CircularProgress size={24} />}
                    </Stack>
                    {error && <Alert severity="error">{error}</Alert>}
                    {!loading && !error && summary && (
                        <Grid container spacing={2}>
                            <Grid item xs={12} md={4}>
                                <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={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">{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}>
                                    {translate("ai.runtimeSummary.lastUpdated", {
                                        time: summary.activePromptUpdatedAt || "--",
                                        user: summary.activePromptUpdatedBy || "--",
                                    })}
                                </Typography>
                            </Grid>
                            <Grid item xs={12} md={4}>
                                <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} />
                                    ))}
                                </Stack>
                            </Grid>
                            {summary.activeParamValidateMessage && (
                                <Grid item xs={12}>
                                    <Alert severity={summary.activeParamValidateStatus === "VALID" ? "success" : "warning"}>
                                        {summary.activeParamValidateMessage}
                                    </Alert>
                                </Grid>
                            )}
                        </Grid>
                    )}
                </CardContent>
            </Card>
        </Box>
    );
};
 
export default AiRuntimeSummary;