fix: companion 指令 status 改名 info,避免與內建 /status 撞名
撞名使 session.start 例外中斷,companion 無法初始化。 註冊失敗改為略過單一指令,版本號改為 0.0.3。 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
4aba330877
commit
fe2ccb619b
@@ -14,7 +14,7 @@ const TICK_MS = 60_000
|
||||
const TYPING_MS = 5_000
|
||||
|
||||
const COMMANDS: Record<string, { description: string; argumentHint?: string }> = {
|
||||
status: { description: '查看目前角色、心情、好感與待辦數量' },
|
||||
info: { description: '查看目前角色、心情、好感與待辦數量' },
|
||||
switch: { description: '切換角色;不給角色會列出可用角色', argumentHint: '<角色>' },
|
||||
disable: { description: '關閉陪伴,所有資料保留' },
|
||||
setup: { description: '顯示或儲存使用者設定', argumentHint: '[key=value…]' },
|
||||
@@ -23,9 +23,13 @@ const COMMANDS: Record<string, { description: string; argumentHint?: string }> =
|
||||
materials: { description: '外部素材(天氣、新聞)的快取狀態;list 列出新聞', argumentHint: '[list]' },
|
||||
}
|
||||
|
||||
// 註冊名稱與內部子指令不同者(status 與內建 /status 撞名;disable 對應 off)
|
||||
const INTERNAL: Record<string, string> = { info: 'status', disable: 'off' }
|
||||
|
||||
export const register: Register = on => {
|
||||
on('session.start', async ($, e, next) => {
|
||||
for (const [name, c] of Object.entries(COMMANDS)) await $.command.register({ name, ...c })
|
||||
// 單一指令撞名被拒絕時不能擋下後面的初始化
|
||||
for (const [name, c] of Object.entries(COMMANDS)) await $.command.register({ name, ...c }).catch(() => {})
|
||||
const home = await $.env.get('HOME')
|
||||
companion = createCompanion({ fs: engineFs({ read: p => $.fs.read(p), write: (p, t) => $.fs.write(p, t), list: p => $.fs.list(p) }), clock: { now: Date.now }, root: `${home ?? ''}/.companion` })
|
||||
const first = await companion.ensureActivated()
|
||||
@@ -45,7 +49,7 @@ export const register: Register = on => {
|
||||
|
||||
for (const command of Object.keys(COMMANDS))
|
||||
on('command.run', { command }, async ($, e) => ({
|
||||
text: companion ? await companion.command(`${command === 'disable' ? 'off' : command} ${e.args}`.trim()) : '尚未就緒。',
|
||||
text: companion ? await companion.command(`${INTERNAL[command] ?? command} ${e.args}`.trim()) : '尚未就緒。',
|
||||
}))
|
||||
|
||||
// 角色卡附加在 system prompt 尾端(session 區段),語氣才會進到模型
|
||||
|
||||
Reference in New Issue
Block a user