Download src/components/panels/SettingsPanel.jsx from cheumk/studio: direct link, hf CLI and curl.
- Browser
- Download file 4.61 kB
-
https://huggingface.co/spaces/cheumk/studio/resolve/main/src/components/panels/SettingsPanel.jsx
- Command line
-
hf download hf://spaces/cheumk/studio/src/components/panels/SettingsPanel.jsx
-
curl -L -o SettingsPanel.jsx https://huggingface.co/spaces/cheumk/studio/resolve/main/src/components/panels/SettingsPanel.jsx
4.61 kB
| import { useState } from 'react' | |
| import { Sun, Moon, Download, Upload, RotateCcw } from 'lucide-react' | |
| import { useStore } from '../../store/useStore' | |
| import { Btn, Field, Section, inputCls, download, pickJsonFile, stamp } from '../ui' | |
| export default function SettingsPanel() { | |
| const settings = useStore((s) => s.settings) | |
| const st = useStore.getState() | |
| const [includeKeys, setIncludeKeys] = useState(true) | |
| const [msg, setMsg] = useState('') | |
| const up = (patch) => st.updateSettings(patch) | |
| const doExport = (scope) => { | |
| const data = st.exportData(scope, { includeKeys }) | |
| download(`agent-studio-${scope === 'all' ? 'backup' : 'settings'}-${stamp()}.json`, JSON.stringify(data, null, 2)) | |
| setMsg(scope === 'all' ? '已匯出全部(設定 + 專案 + 對話)' : '已匯出設定') | |
| } | |
| const doImport = async () => { | |
| setMsg('') | |
| try { | |
| const json = await pickJsonFile() | |
| let mode = 'merge' | |
| if (json?.type === 'all') { | |
| mode = confirm('這是完整備份。\n按「確定」= 完全取代目前資料\n按「取消」= 合併(同 id 覆蓋,其餘保留)') ? 'replace' : 'merge' | |
| } | |
| setMsg(st.importData(json, mode)) | |
| } catch (e) { | |
| setMsg(`匯入失敗:${e.message}`) | |
| } | |
| } | |
| return ( | |
| <div> | |
| <Section title="一鍵匯入 / 匯出"> | |
| <div className="grid grid-cols-2 gap-2"> | |
| <Btn variant="primary" onClick={() => doExport('all')}><Download className="w-4 h-4" /> 匯出全部</Btn> | |
| <Btn variant="primary" onClick={doImport}><Upload className="w-4 h-4" /> 匯入</Btn> | |
| <Btn className="col-span-2" onClick={() => doExport('settings')}><Download className="w-4 h-4" /> 只匯出設定(供應商、Agent、工具)</Btn> | |
| </div> | |
| <label className="flex items-center gap-2 text-xs text-muted"> | |
| <input type="checkbox" checked={includeKeys} onChange={(e) => setIncludeKeys(e.target.checked)} /> | |
| 匯出時包含 API 金鑰(分享給別人前請取消勾選) | |
| </label> | |
| <p className="text-[11px] text-muted"> | |
| 匯入會自動辨識檔案類型:完整備份、設定、單一專案、單一對話(也相容舊版匯出的對話 JSON)。單一專案 / 對話也可在「專案」「對話」頁匯出。 | |
| </p> | |
| {msg && <p className="text-xs text-emerald-500">{msg}</p>} | |
| </Section> | |
| <Section title="外觀"> | |
| <div className="grid grid-cols-2 gap-2"> | |
| <Btn variant={settings.theme === 'dark' ? 'primary' : 'ghost'} onClick={() => up({ theme: 'dark' })}><Moon className="w-4 h-4" /> 深色</Btn> | |
| <Btn variant={settings.theme === 'light' ? 'primary' : 'ghost'} onClick={() => up({ theme: 'light' })}><Sun className="w-4 h-4" /> 亮色</Btn> | |
| </div> | |
| </Section> | |
| <Section title="Agent 執行"> | |
| <Field label="每輪最多工具步數" hint="模型每呼叫一次工具算一步。全程串流,不設逾時,可隨時按停止。"> | |
| <input type="number" min={1} max={50} className={inputCls} value={settings.maxSteps} onChange={(e) => up({ maxSteps: e.target.value })} /> | |
| </Field> | |
| <Field label="Temperature" hint="留空 = 用模型預設值。"> | |
| <input type="number" step="0.1" min={0} max={2} className={inputCls} value={settings.temperature} onChange={(e) => up({ temperature: e.target.value })} placeholder="預設" /> | |
| </Field> | |
| </Section> | |
| <Section title="搜尋與讀網頁(選填)"> | |
| <Field label="Tavily API Key" hint="填了之後 web_search 會用 Tavily 做真正的全網搜尋(免費額度每月 1000 次,tavily.com)。不填則用 Wikipedia + DuckDuckGo。"> | |
| <input type="password" className={inputCls} value={settings.tavilyKey} onChange={(e) => up({ tavilyKey: e.target.value })} placeholder="tvly-..." /> | |
| </Field> | |
| <Field label="Jina Reader API Key" hint="fetch_url 透過 Jina Reader 讀任意網頁(jina.ai 可領免費金鑰)。不填時只能讀有開 CORS 的網址。"> | |
| <input type="password" className={inputCls} value={settings.jinaKey} onChange={(e) => up({ jinaKey: e.target.value })} placeholder="jina_..." /> | |
| </Field> | |
| </Section> | |
| <Section title="危險區" defaultOpen={false}> | |
| <Btn variant="danger" className="w-full" onClick={() => { | |
| if (confirm('清除所有專案、對話與設定?建議先「匯出全部」備份。')) st.resetAll() | |
| }}> | |
| <RotateCcw className="w-4 h-4" /> 重設所有資料 | |
| </Btn> | |
| </Section> | |
| </div> | |
| ) | |
| } | |