Files
EvoScientist-WebUI/src/app/components/ConfigDialog.tsx
T
Xi Zhang 047da86b14 Update
2026-05-31 23:10:33 +01:00

92 lines
2.4 KiB
TypeScript

"use client";
import { useState, useEffect } from "react";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { DEFAULT_ASSISTANT_ID, DeploymentConfig } from "@/lib/config";
interface ConfigDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onSave: (config: DeploymentConfig) => void;
initialConfig?: DeploymentConfig;
}
export function ConfigDialog({
open,
onOpenChange,
onSave,
initialConfig,
}: ConfigDialogProps) {
const [deploymentUrl, setDeploymentUrl] = useState(
initialConfig?.deploymentUrl || "http://127.0.0.1:6174"
);
useEffect(() => {
if (open && initialConfig) {
setDeploymentUrl(initialConfig.deploymentUrl);
}
}, [open, initialConfig]);
const handleSave = () => {
if (!deploymentUrl) {
alert("Please enter the deployment URL");
return;
}
onSave({
deploymentUrl,
// Fixed to the EvoScientist main agent (see DEFAULT_ASSISTANT_ID).
assistantId: DEFAULT_ASSISTANT_ID,
});
onOpenChange(false);
};
return (
<Dialog
open={open}
onOpenChange={onOpenChange}
>
<DialogContent className="sm:max-w-[525px]">
<DialogHeader>
<DialogTitle>Configuration</DialogTitle>
<DialogDescription>
Enter the URL of your EvoScientist deployment (from{" "}
<code>EvoSci deploy</code>). This is saved in your browser&apos;s
local storage.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid gap-2">
<Label htmlFor="deploymentUrl">Deployment URL</Label>
<Input
id="deploymentUrl"
placeholder="http://127.0.0.1:6174"
value={deploymentUrl}
onChange={(e) => setDeploymentUrl(e.target.value)}
/>
</div>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => onOpenChange(false)}
>
Cancel
</Button>
<Button onClick={handleSave}>Save</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}