import { useEffect, useState } from "react"; import { Dialog } from "../ui/Dialog"; import { Button } from "../ui/Button"; import { useToast } from "../ui/Toast"; import { getMyJarvis, saveMyJarvis, type JarvisConfig, GATEWAY, getToken } from "../lib/api"; import { defaultLocalDirs, localExecEnabled, localRunnerAvailable, localRunnerStatus, setLocalExecEnabled, startLocalRunner, stopLocalRunner, } from "../lib/desktop"; // 每用户 JARVIS 设置:名字 / 人设 / (高级)自带豆包配置。 // 名字与人设归用户自己;豆包配置齐全则语音走用户的账号,否则走系统兜底。 export function JarvisSettings({ open, onClose }: { open: boolean; onClose: () => void }) { const toast = useToast(); const [cfg, setCfg] = useState(null); const [saving, setSaving] = useState(false); const [advanced, setAdvanced] = useState(false); useEffect(() => { if (!open) return; setCfg(null); getMyJarvis() .then(setCfg) .catch((e) => toast.push("error", (e as Error).message)); }, [open, toast]); const set = (k: keyof JarvisConfig, v: string) => setCfg((c) => (c ? { ...c, [k]: v } : c)); const onSave = async () => { if (!cfg) return; setSaving(true); try { await saveMyJarvis({ name: cfg.name, persona: cfg.persona, api_key: cfg.api_key.includes("•") ? "" : cfg.api_key, // 掩码=没改动,留空沿用已存 asr_resource_id: cfg.asr_resource_id, tts_resource_id: cfg.tts_resource_id, tts_voice_type: cfg.tts_voice_type, }); toast.push("success", "已保存,下次说话即生效"); onClose(); } catch (e) { toast.push("error", (e as Error).message); } finally { setSaving(false); } }; return ( } > {!cfg ? (
加载中…
) : (