| | |
| | | SelectInput, |
| | | TextInput, |
| | | useNotify, |
| | | useTranslate, |
| | | } from "react-admin"; |
| | | import { Alert, Button, Grid, Stack, Typography } from "@mui/material"; |
| | | import StatusSelectInput from "@/page/components/StatusSelectInput"; |
| | |
| | | |
| | | const AiMcpDraftTestSection = ({ formData, readOnly }) => { |
| | | const notify = useNotify(); |
| | | const translate = useTranslate(); |
| | | const [loading, setLoading] = useState(false); |
| | | const [result, setResult] = useState(null); |
| | | |
| | |
| | | try { |
| | | const data = await validateDraftMcpConnectivity(formData); |
| | | setResult(data); |
| | | notify(data?.message || "草稿连通性测试完成"); |
| | | notify(data?.message || translate("ai.mcp.connectivity.success")); |
| | | } catch (error) { |
| | | const nextResult = { |
| | | healthStatus: "UNHEALTHY", |
| | | message: error?.message || "草稿连通性测试失败", |
| | | message: error?.message || translate("ai.mcp.connectivity.failed"), |
| | | }; |
| | | setResult(nextResult); |
| | | notify(nextResult.message, { type: "error" }); |
| | |
| | | <Grid item xs={12}> |
| | | <Stack direction="row" spacing={1} alignItems="center"> |
| | | <Button variant="outlined" onClick={handleValidate} disabled={loading}> |
| | | {loading ? "测试中..." : "保存前测试"} |
| | | {loading ? translate("ai.common.testing") : translate("ai.mcp.form.testBeforeSave")} |
| | | </Button> |
| | | <Typography variant="body2" color="text.secondary"> |
| | | 用当前草稿配置直接校验连通性,不会落库。 |
| | | {translate("ai.mcp.form.testDescription")} |
| | | </Typography> |
| | | </Stack> |
| | | </Grid> |
| | |
| | | ); |
| | | }; |
| | | |
| | | const AiMcpMountForm = ({ readOnly = false }) => ( |
| | | const AiMcpMountForm = ({ readOnly = false }) => { |
| | | const translate = useTranslate(); |
| | | |
| | | return ( |
| | | <Grid container spacing={2} width={{ xs: "100%", xl: "80%" }}> |
| | | <Grid item xs={12}> |
| | | <Typography variant="h6">MCP 挂载配置</Typography> |
| | | <Typography variant="h6">{translate("ai.mcp.form.sections.main")}</Typography> |
| | | </Grid> |
| | | <Grid item xs={12} md={6}> |
| | | <TextInput source="name" label="名称" fullWidth disabled={readOnly} /> |
| | | <TextInput source="name" label="common.field.name" fullWidth disabled={readOnly} /> |
| | | </Grid> |
| | | <Grid item xs={12} md={6}> |
| | | <SelectInput source="transportType" label="传输类型" choices={transportChoices} fullWidth disabled={readOnly} /> |
| | | <SelectInput source="transportType" label="ai.mcp.fields.transportType" choices={transportChoices} fullWidth disabled={readOnly} /> |
| | | </Grid> |
| | | <FormDataConsumer> |
| | | {({ formData }) => ( |
| | |
| | | <Grid item xs={12}> |
| | | <SelectInput |
| | | source="builtinCode" |
| | | label="内置 MCP" |
| | | label="ai.mcp.fields.builtinCode" |
| | | choices={[ |
| | | { id: "RSF_WMS", name: "RSF_WMS" }, |
| | | { id: "RSF_WMS_STOCK", name: "RSF_WMS_STOCK" }, |
| | |
| | | {formData.transportType === "SSE_HTTP" && ( |
| | | <> |
| | | <Grid item xs={12}> |
| | | <TextInput source="serverUrl" label="服务地址" fullWidth disabled={readOnly} /> |
| | | <TextInput source="serverUrl" label="ai.mcp.fields.serverUrl" fullWidth disabled={readOnly} /> |
| | | </Grid> |
| | | <Grid item xs={12}> |
| | | <TextInput source="endpoint" label="SSE Endpoint" fullWidth disabled={readOnly} /> |
| | |
| | | {formData.transportType === "STDIO" && ( |
| | | <> |
| | | <Grid item xs={12}> |
| | | <TextInput source="command" label="命令" fullWidth disabled={readOnly} /> |
| | | <TextInput source="command" label="ai.mcp.fields.command" fullWidth disabled={readOnly} /> |
| | | </Grid> |
| | | <Grid item xs={12}> |
| | | <TextInput source="argsJson" label="Args JSON" fullWidth multiline minRows={4} disabled={readOnly} /> |
| | |
| | | <NumberInput source="requestTimeoutMs" label="Timeout(ms)" fullWidth disabled={readOnly} /> |
| | | </Grid> |
| | | <Grid item xs={12} md={4}> |
| | | <NumberInput source="sort" label="排序" fullWidth disabled={readOnly} /> |
| | | <NumberInput source="sort" label="ai.mcp.fields.sort" fullWidth disabled={readOnly} /> |
| | | </Grid> |
| | | <Grid item xs={12} md={4}> |
| | | <StatusSelectInput disabled={readOnly} /> |
| | | </Grid> |
| | | <Grid item xs={12}> |
| | | <TextInput source="memo" label="备注" fullWidth multiline minRows={3} disabled={readOnly} /> |
| | | <TextInput source="memo" label="common.field.memo" fullWidth multiline minRows={3} disabled={readOnly} /> |
| | | </Grid> |
| | | <FormDataConsumer> |
| | | {({ formData }) => <AiMcpDraftTestSection formData={formData} readOnly={readOnly} />} |
| | | </FormDataConsumer> |
| | | <Grid item xs={12}> |
| | | <Typography variant="h6">运行态信息</Typography> |
| | | <Typography variant="h6">{translate("ai.mcp.form.sections.runtime")}</Typography> |
| | | </Grid> |
| | | <Grid item xs={12} md={4}> |
| | | <TextInput source="healthStatus" label="健康状态" fullWidth disabled /> |
| | | <TextInput source="healthStatus" label="ai.mcp.fields.healthStatus" fullWidth disabled /> |
| | | </Grid> |
| | | <Grid item xs={12} md={4}> |
| | | <TextInput source="lastInitElapsedMs" label="最近初始化耗时(ms)" fullWidth disabled /> |
| | | <TextInput source="lastInitElapsedMs" label="ai.mcp.fields.lastInitElapsedMs" fullWidth disabled /> |
| | | </Grid> |
| | | <Grid item xs={12} md={4}> |
| | | <TextInput source="lastTestTime$" label="最近测试时间" fullWidth disabled /> |
| | | <TextInput source="lastTestTime$" label="ai.mcp.fields.lastTestTime" fullWidth disabled /> |
| | | </Grid> |
| | | <Grid item xs={12}> |
| | | <TextInput source="lastTestMessage" label="最近测试结果" fullWidth multiline minRows={3} disabled /> |
| | | <TextInput source="lastTestMessage" label="ai.mcp.fields.lastTestMessage" fullWidth multiline minRows={3} disabled /> |
| | | </Grid> |
| | | <Grid item xs={12} md={6}> |
| | | <TextInput source="updateBy" label="最近更新人" fullWidth disabled /> |
| | | <TextInput source="updateBy" label="ai.common.lastUpdatedBy" fullWidth disabled /> |
| | | </Grid> |
| | | <Grid item xs={12} md={6}> |
| | | <TextInput source="updateTime$" label="最近更新时间" fullWidth disabled /> |
| | | <TextInput source="updateTime$" label="ai.common.lastUpdatedAt" fullWidth disabled /> |
| | | </Grid> |
| | | </Grid> |
| | | ); |
| | | ); |
| | | }; |
| | | |
| | | export default AiMcpMountForm; |