import { themeChange } from "theme-change"; import { useRef, useCallback } from "react"; import { useContext, useEffect, useState, Dispatch } from "react"; import React from "react"; import { clearTotalCost, getTotalCost } from "@/utils/totalCost"; import { ChatStore, TemplateChatStore, TemplateTools } from "@/types/chatstore"; import { models } from "@/types/models"; import { tr, Tr, langCodeContext, LANG_OPTIONS } from "@/translate"; import { isVailedJSON } from "@/utils/isVailedJSON"; import { SetAPIsTemplate } from "@/components/setAPIsTemplate"; import { autoHeight } from "@/utils/textAreaHelp"; import { getDefaultParams } from "@/utils/getDefaultParam"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Checkbox } from "@/components/ui/checkbox"; import { Badge } from "@/components/ui/badge"; import { Textarea } from "@/components/ui/textarea"; import { BanIcon, CheckIcon, CircleEllipsisIcon, CogIcon, EyeIcon, InfoIcon, KeyIcon, ListIcon, MoveHorizontalIcon, SaveIcon, TriangleAlertIcon, } from "lucide-react"; import { Separator } from "@/components/ui/separator"; import { Slider } from "@/components/ui/slider"; import { NonOverflowScrollArea, ScrollArea } from "@/components/ui/scroll-area"; import { AppChatStoreContext, AppContext } from "@/pages/App"; import { toast } from "@/hooks/use-toast"; import { title } from "process"; const TTS_VOICES: string[] = [ "alloy", "echo", "fable", "onyx", "nova", "shimmer", ]; const TTS_FORMAT: string[] = ["mp3", "opus", "aac", "flac"]; const Help = (props: { children: any; help: string; field: string }) => { return (
); }; const SelectModel = (props: { help: string }) => { const { chatStore, setChatStore } = useContext(AppChatStoreContext); let shouldIUseCustomModel: boolean = true; for (const model in models) { if (chatStore.model === model) { shouldIUseCustomModel = false; } } const [useCustomModel, setUseCustomModel] = useState(shouldIUseCustomModel); return (
setUseCustomModel(!useCustomModel)} />
{useCustomModel ? ( ) => { chatStore.model = e.target.value; setChatStore({ ...chatStore }); }} /> ) : ( )}
); }; const LongInput = React.memo( (props: { field: "systemMessageContent" | "toolsString"; label: string; help: string; }) => { const { chatStore, setChatStore } = useContext(AppChatStoreContext); const textareaRef = useRef(null); const [localValue, setLocalValue] = useState(chatStore[props.field]); // Update height when value changes useEffect(() => { if (textareaRef.current) { autoHeight(textareaRef.current); } }, [localValue]); // Sync local value with chatStore when it changes externally useEffect(() => { setLocalValue(chatStore[props.field]); }, [chatStore[props.field]]); const handleChange = (event: React.ChangeEvent) => { setLocalValue(event.target.value); }; const handleBlur = () => { if (localValue !== chatStore[props.field]) { chatStore[props.field] = localValue; setChatStore({ ...chatStore }); } }; return (