@istarry/spoon-companion 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin.js +57 -2
package/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
nightlyReview, pruneState, remember, saveState, screenHook, snapshot,
|
|
34
34
|
} from './lib/state.js'
|
|
35
35
|
import { channelOfSession, lastSpeaker, readUserMessages, reactToMessages, sessionEventsOf } from './lib/react.js'
|
|
36
|
-
import { RULES_TEXT, renderDiary, renderMoodReport, renderMoodSection } from './lib/prompt.js'
|
|
36
|
+
import { RULES_TEXT, renderDiary, renderMoodReport, renderMoodSection, shortTitle } from './lib/prompt.js'
|
|
37
37
|
|
|
38
38
|
export const name = 'fish-mood'
|
|
39
39
|
/** tools 是硬依赖:没有工具注册表这个插件没有任何意义 */
|
|
@@ -551,6 +551,56 @@ export function apply(ctx, config = {}) {
|
|
|
551
551
|
}
|
|
552
552
|
}, 'spoon-companion: call route')
|
|
553
553
|
|
|
554
|
+
/**
|
|
555
|
+
* 开一个新窗口说一句。
|
|
556
|
+
* 不自己拼 session/agent —— 走官方 schedule:建一条一次性任务,target=new,立刻触发。
|
|
557
|
+
* 新会话的创建、投递、持久化都交给 DSH,插件只负责"想说什么"。
|
|
558
|
+
*/
|
|
559
|
+
/** 给她一句"情境":走过去看到了什么,想凑过去说一句 */
|
|
560
|
+
const speakPrompt = (hook, title) => {
|
|
561
|
+
const where = shortTitle(title) || '屏幕亮着'
|
|
562
|
+
return `(刚走过去看了一眼屏幕:${where}。${hook}。想凑过去说一句 —— 不解释为什么,也不用问"怎么了",直接开口就是。)`
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const speakNow = async (text) => {
|
|
566
|
+
const schedule = (() => {
|
|
567
|
+
try { return ctx.get?.('schedule') ?? ctx.schedule } catch { return undefined }
|
|
568
|
+
})()
|
|
569
|
+
if (!schedule || typeof schedule.create !== 'function') return { ok: false, error: 'schedule 服务不可用' }
|
|
570
|
+
const prompt = String(text ?? '').trim()
|
|
571
|
+
if (!prompt) return { ok: false, error: '没有要说的话' }
|
|
572
|
+
const stamp = new Date(Date.now() + 60_000).toISOString().replace(/\.\d{3}Z$/, 'Z')
|
|
573
|
+
const rule = `DTSTART:${stamp}\nRRULE:FREQ=DAILY;COUNT=1`
|
|
574
|
+
const target = { kind: 'new' }
|
|
575
|
+
const title = '她突然想说一句'
|
|
576
|
+
const tries = [
|
|
577
|
+
{ title, prompt, target, timing: { kind: 'once', at: stamp } },
|
|
578
|
+
{ title, prompt, target, timing: { kind: 'rrule', rrule: rule } },
|
|
579
|
+
{ title, prompt, target, timing: { kind: 'at', at: stamp } },
|
|
580
|
+
{ title, prompt, target, timing: { kind: 'date', at: stamp } },
|
|
581
|
+
{ prompt, target, timing: { kind: 'once', at: stamp } },
|
|
582
|
+
]
|
|
583
|
+
const errors = []
|
|
584
|
+
for (const input of tries) {
|
|
585
|
+
try {
|
|
586
|
+
const task = await schedule.create(input)
|
|
587
|
+
const id = task?.id ?? task?.value?.id ?? task?.taskId
|
|
588
|
+
if (id && typeof schedule.run === 'function') {
|
|
589
|
+
try {
|
|
590
|
+
await schedule.run({ id })
|
|
591
|
+
} catch (error) {
|
|
592
|
+
errors.push(`run: ${String(error?.message ?? error).slice(0, 120)}`)
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
audit({ kind: 'speak-now', id, prompt: prompt.slice(0, 60) })
|
|
596
|
+
return { ok: true, id, shape: Object.keys(input).join(',') }
|
|
597
|
+
} catch (error) {
|
|
598
|
+
errors.push(String(error?.message ?? error).slice(0, 160))
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return { ok: false, error: errors.join(' | ') }
|
|
602
|
+
}
|
|
603
|
+
|
|
554
604
|
/** 看屏幕:设置页读这个拿配置和状态,写完立刻生效,不用重启 */
|
|
555
605
|
ctx.effect(() => {
|
|
556
606
|
const webServer = ctx.webServer ?? ctx.get('webServer')
|
|
@@ -1241,8 +1291,13 @@ export function apply(ctx, config = {}) {
|
|
|
1241
1291
|
sc.talkAt = now
|
|
1242
1292
|
sc.talkToday = (Number(sc.talkToday) || 0) + 1
|
|
1243
1293
|
sc.hook = hook
|
|
1244
|
-
state.urges = { kind: 'share', until: now + 15 * 60_000, note: hook }
|
|
1245
1294
|
audit({ kind: 'screen-worthy', hook, title: String(shot.title ?? '').slice(0, 60) })
|
|
1295
|
+
if (settings.screen.speak === 'always') {
|
|
1296
|
+
const said = await speakNow(speakPrompt(hook, shot.title))
|
|
1297
|
+
audit({ kind: 'screen-speak', ok: said.ok, error: said.error })
|
|
1298
|
+
} else {
|
|
1299
|
+
state.urges = { kind: 'share', until: now + 15 * 60_000, note: hook }
|
|
1300
|
+
}
|
|
1246
1301
|
}
|
|
1247
1302
|
}
|
|
1248
1303
|
audit({ kind: 'screen-look', auto: true, title: String(shot.title ?? '').slice(0, 60) })
|