import React from "react";
|
import {
|
CreateBase,
|
useTranslate,
|
TextInput,
|
NumberInput,
|
SaveButton,
|
SelectInput,
|
Toolbar,
|
useNotify,
|
Form,
|
} from 'react-admin';
|
import {
|
Dialog,
|
DialogActions,
|
DialogContent,
|
DialogTitle,
|
Grid,
|
Box,
|
} from '@mui/material';
|
import DialogCloseButton from "@/page/components/DialogCloseButton";
|
import StatusSelectInput from "@/page/components/StatusSelectInput";
|
import MemoInput from "@/page/components/MemoInput";
|
|
const transportChoices = [
|
{ id: 'INTERNAL', name: '内部工具集' },
|
{ id: 'HTTP', name: 'Streamable HTTP' },
|
{ id: 'SSE', name: 'SSE MCP' },
|
];
|
|
const enabledChoices = [
|
{ id: 1, name: '启用' },
|
{ id: 0, name: '停用' },
|
];
|
|
const AiMcpMountCreate = (props) => {
|
const { open, setOpen } = props;
|
const translate = useTranslate();
|
const notify = useNotify();
|
|
const handleClose = (event, reason) => {
|
if (reason !== "backdropClick") {
|
setOpen(false);
|
}
|
};
|
|
const handleSuccess = async () => {
|
setOpen(false);
|
notify('common.response.success');
|
};
|
|
const handleError = async (error) => {
|
notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } });
|
};
|
|
return (
|
<CreateBase
|
record={{ transportType: 'INTERNAL', enabledFlag: 1, timeoutMs: 10000, status: 1 }}
|
mutationOptions={{ onSuccess: handleSuccess, onError: handleError }}
|
>
|
<Dialog open={open} onClose={handleClose} fullWidth disableRestoreFocus maxWidth="md">
|
<Form>
|
<DialogTitle sx={{ position: 'sticky', top: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
|
{translate('create.title')}
|
<Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}>
|
<DialogCloseButton onClose={handleClose} />
|
</Box>
|
</DialogTitle>
|
<DialogContent sx={{ mt: 2 }}>
|
<Grid container rowSpacing={2} columnSpacing={2}>
|
<Grid item xs={6}><TextInput source="name" label="挂载名称" fullWidth /></Grid>
|
<Grid item xs={6}><TextInput source="mountCode" label="挂载编码" fullWidth /></Grid>
|
<Grid item xs={6}><SelectInput source="transportType" label="传输类型" choices={transportChoices} fullWidth /></Grid>
|
<Grid item xs={6}><SelectInput source="enabledFlag" label="启用" choices={enabledChoices} fullWidth /></Grid>
|
<Grid item xs={6}><NumberInput source="timeoutMs" label="超时毫秒" fullWidth /></Grid>
|
<Grid item xs={6}><StatusSelectInput fullWidth /></Grid>
|
<Grid item xs={12}><TextInput source="url" label="地址" fullWidth helperText="内部工具集会自动写入 /ai/mcp;外部挂载可填写远程 Streamable HTTP 或 SSE MCP 地址" /></Grid>
|
<Grid item xs={12}><MemoInput /></Grid>
|
</Grid>
|
</DialogContent>
|
<DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
|
<Toolbar sx={{ width: '100%', justifyContent: 'space-between' }}>
|
<SaveButton />
|
</Toolbar>
|
</DialogActions>
|
</Form>
|
</Dialog>
|
</CreateBase>
|
)
|
}
|
|
export default AiMcpMountCreate;
|