123 lines
3.7 KiB
JavaScript
123 lines
3.7 KiB
JavaScript
const fs = require('fs')
|
|
const p = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/renderer/src/chat/ChatBar.tsx'
|
|
let c = fs.readFileSync(p, 'utf8')
|
|
|
|
function rep(from, to) {
|
|
if (!c.includes(from)) {
|
|
console.log('MISS ::', from.slice(0, 70).replace(/\n/g, '\\n'))
|
|
return
|
|
}
|
|
c = c.replace(from, to)
|
|
}
|
|
|
|
// 状态:服务端预设列表
|
|
rep(
|
|
" const [feedback, setFeedback] = useState('')",
|
|
` const [feedback, setFeedback] = useState('')
|
|
const [presetList, setPresetList] = useState<
|
|
Array<{ id: string; text: string; textNormal: string; kind: string }>
|
|
>([])
|
|
const [nextAt, setNextAt] = useState(0)`
|
|
)
|
|
|
|
// 取列表的方法与定时刷新
|
|
rep(
|
|
` const list = state
|
|
? suggestions(state, flavor)
|
|
: flavor === 'normal'
|
|
? PRESETS_NORMAL
|
|
: PRESETS_CHEM
|
|
const presets: PresetDialogue[] = presetsFor(flavor)`,
|
|
` const list = state
|
|
? suggestions(state, flavor)
|
|
: flavor === 'normal'
|
|
? PRESETS_NORMAL
|
|
: PRESETS_CHEM`
|
|
)
|
|
|
|
rep(
|
|
` const [flavor, setFlavor] = useState<'chemistry' | 'normal'>('chemistry')`,
|
|
` const [flavor, setFlavor] = useState<'chemistry' | 'normal'>('chemistry')
|
|
useEffect(() => {
|
|
const load = (): void => {
|
|
void api()
|
|
?.getChatPresets()
|
|
.then((r) => {
|
|
setPresetList(r.presets)
|
|
setNextAt(r.nextAt)
|
|
})
|
|
}
|
|
load()
|
|
const t = window.setInterval(load, 60_000)
|
|
return () => window.clearInterval(t)
|
|
}, [flavor])`
|
|
)
|
|
|
|
// 列表渲染:服务端预设 + 空状态
|
|
rep(
|
|
` {presets.map((p) => (
|
|
<button
|
|
key={p.id}
|
|
className="chat-suggest-item"
|
|
onClick={() => {
|
|
setOpen(false)
|
|
void api()
|
|
?.chatPreset(p.id)
|
|
.then((r) => {
|
|
if (r?.message) {
|
|
setFeedback(r.message)
|
|
window.setTimeout(() => {
|
|
setFeedback('')
|
|
api()?.setChatExpanded(false)
|
|
}, 2800)
|
|
} else {
|
|
api()?.setChatExpanded(false)
|
|
}
|
|
})
|
|
}}
|
|
>
|
|
🎲 {flavor === 'normal' ? p.textNormal : p.text}
|
|
</button>
|
|
))}`,
|
|
` {presetList.map((p) => (
|
|
<button
|
|
key={p.id}
|
|
className="chat-suggest-item"
|
|
onClick={() => {
|
|
setOpen(false)
|
|
void api()
|
|
?.chatPreset(p.id)
|
|
.then((r) => {
|
|
if (r?.presets) setPresetList(r.presets)
|
|
if (r?.message) {
|
|
setFeedback(r.message)
|
|
window.setTimeout(() => {
|
|
setFeedback('')
|
|
api()?.setChatExpanded(false)
|
|
}, 2800)
|
|
} else {
|
|
api()?.setChatExpanded(false)
|
|
}
|
|
})
|
|
}}
|
|
>
|
|
🎲 {flavor === 'normal' ? p.textNormal : p.text}
|
|
</button>
|
|
))}
|
|
{presetList.length === 0 && (
|
|
<div className="chat-suggest-empty">
|
|
(这批预设都选完啦,约{' '}
|
|
{Math.max(1, Math.round((nextAt - Date.now()) / 60000))} 分钟后刷新)
|
|
</div>
|
|
)}`
|
|
)
|
|
|
|
// 不再需要 PresetDialogue 导入
|
|
rep(
|
|
"import { presetsFor, suggestions, type PresetDialogue } from '../../../shared/dialogue'",
|
|
"import { suggestions } from '../../../shared/dialogue'"
|
|
)
|
|
|
|
fs.writeFileSync(p, c, 'utf8')
|
|
console.log('chat preset rotation ui patched')
|