import { useEffect, useState } from 'react' import { Btn, SettingRow, SettingsGroup } from '@ui' import { api } from '../api' const services = [ ['models.chat', '主模型'], ['models.lightweight', '轻量模型'], ['models.embedding', 'Embedding'], ['models.rerank', 'Reranker'], ['tools.tavily', 'Tavily'], ] as const type Secret = { id: string; service: string; label: string; active: boolean; mask: string } type Entry = { id: string; keys: string[]; content: string; constant: boolean; logic: string } type Cmd = { id: string; name: string; title: string; template: string } export function BorrowPanels() { const [secrets, setSecrets] = useState([]) const [entries, setEntries] = useState([]) const [cmds, setCmds] = useState([]) const [service, setService] = useState(services[0][0]) const [label, setLabel] = useState('') const [value, setValue] = useState('') const [keys, setKeys] = useState('') const [content, setContent] = useState('') const [constant, setConstant] = useState(false) const [cmdName, setCmdName] = useState('/summary') const [cmdTitle, setCmdTitle] = useState('总结') const [cmdBody, setCmdBody] = useState('请总结以上内容。\n{{input}}') const reload = () => { api.listSecrets().then(setSecrets).catch(() => undefined) api.listContextEntries().then(setEntries).catch(() => undefined) api.listPromptCommands().then(setCmds).catch(() => undefined) } useEffect(() => { reload() }, []) return ( <> setLabel(e.target.value)} /> setValue(e.target.value)} /> { if (!value.trim()) return await api.createSecret(service, label || '未命名', value.trim()) setValue(''); setLabel(''); reload() }}>添加 {secrets.map(s => ( {!s.active && { await api.activateSecret(s.id); reload() }}>启用} { await api.deleteSecret(s.id); reload() }}>删除 ))} setKeys(e.target.value)} />