dsh-fish-home 0.1.0 → 0.1.1
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/CHANGELOG.md +11 -0
- package/README.md +6 -1
- package/lib/body-intent.mjs +60 -0
- package/lib/client.js +31 -0
- package/lib/host.js +217 -31
- package/lib/memory.mjs +61 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 0.1.1 — 2026-11-20
|
|
2
|
+
|
|
3
|
+
- 回忆簿支持配置 .md / .txt 文件或文件夹;没有星汐插件时可用文本日记和存档起始日计算相伴天数。
|
|
4
|
+
- 默认关闭每轮 runtime-context,改为状态真正变化时通知绑定会话;设置页增加用量提示和开关。
|
|
5
|
+
- 画图工具支持 DSH 图片附件回传,也支持 reference 参考图走图生图接口。
|
|
6
|
+
- 放大聊天气泡和悬停提示的可停留区域;批量农活工具明确一次完成,减少重复工具调用。
|
|
7
|
+
- 旧版配置升级时关闭逐轮 runtime-context,并卸载已挂载的旧上下文,避免每次工具回合重复计入输入。
|
|
8
|
+
- 农活工具为同一轮内的相同批量请求去重;新增一次调用完成同类收获、按许可补买种子和补种。
|
|
9
|
+
- 回复明确说自己要去房间或坐下时,本地房间跟随执行一次;工具已安排移动/活动时不重复驱动。
|
|
10
|
+
- 纯净房间包提供安全更新脚本:先备份旧运行文件,只替换程序与 dist,失败时自动恢复,存档和根目录配置保留。
|
|
11
|
+
|
|
1
12
|
## 0.1.0 — 2026-11-19
|
|
2
13
|
|
|
3
14
|
- 内置鱼鱼窝运行版,支持从 DSH 侧栏启动和关闭,首次启动自动建立独立存档并发现绑定会话。
|
package/README.md
CHANGED
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
- **卡册**。fish_home_card 按卡名或 ID 一次看一张图,抽卡和兑换只返回文字。fish_home_draw 加上 op=exchange 可换金币、星辉或指定卡。金币兑换数量填消耗的星尘,星辉兑换数量填要得到的星辉。
|
|
79
79
|
|
|
80
80
|
- **田地布局**。fish_home_farm 的 list 使用 scope=layout 查看菜畦按 3×3 分组的作物。加 bed=0、1 或 2 可看该菜畦每个格子。
|
|
81
|
+
- **批量收种**。一次说清作物,用 `op=replant,item=...` 会批量收成熟的同类作物并用背包种子补种;明确允许花金币时再加 `buyMissing=true`,整套流程只需一次工具调用。
|
|
81
82
|
- **集市**。商店里的「集市行情」和 fish_home 的 market、price 共用售价。每天北京时间零点更新,明日预告也可提前查询。price 可按 kind 或 item 筛选。
|
|
82
83
|
|
|
83
84
|
## 画架
|
|
@@ -127,13 +128,17 @@ dsh plugin --profile <你的 profile> add dsh-fish-home
|
|
|
127
128
|
|
|
128
129
|
Windows 就是 `C:\Users\<你>\.dsh\fish-home-room\`,打开里面要能直接看到 `app-server.js`(别再套一层文件夹)。
|
|
129
130
|
|
|
131
|
+
已有鱼鱼窝要更新时,先用房间右上角的退出按钮关闭后台,再双击**旧房间目录**里的 `update-fish-home.cmd`,按提示输入新版 ZIP 的路径。从 0.1.0 升级时,旧目录没有更新脚本:先把新版 ZIP 解压到临时文件夹,只将其中的 `update-fish-home.cmd` 和 `update-fish-home.ps1` 复制到旧房间目录,再运行。脚本会将旧版运行文件保留在旁边的 `fish-home-room-backups`,原地替换程序资源;`%USERPROFILE%\.dsh\fish-home-data`、旧目录里的 `data` 和自定义配置都保持原样。文件替换失败会尝试恢复旧版。成功后从 DSH 重新打开鱼鱼窝即可。
|
|
132
|
+
|
|
130
133
|
想放别处,设环境变量 `FISH_ROOM_DIR` 指向那个目录。
|
|
131
134
|
|
|
132
135
|
**③ 重启一次 DSH**
|
|
133
136
|
|
|
134
137
|
重启完绑定会话,再从侧栏打开。电脑上需要 Node.js 22.13 或更新版本。房间默认在本机 `5178` 端口,首次启动时在 `~/.dsh/fish-home-data` 建立空存档,插件更新时会继续用这份。
|
|
135
138
|
|
|
136
|
-
|
|
139
|
+
内置房间使用原版蓝色大肥鱼模型和配套动作。
|
|
140
|
+
|
|
141
|
+
回忆簿可在 DSH 设置里的「上下文与回忆」填写纯文本记忆路径、日记路径和相伴起始日;逐轮 runtime-context 默认关闭,需要时可按需查询现场,天气、成熟与生活里程碑、消费和场景事件也能分别控制是否通知绑定会话。模型制作:水原镜,MMD 转换与绑定:耶栗Yaki。模型的署名和原始使用规约随房间本体一起下发(房间目录 `dist/models/dayu-mmd/` 里的 `使用规约.txt` 和 `MODEL-CREDITS.md`),请一并保留。
|
|
137
142
|
|
|
138
143
|
卡包大部分立绘来源于 B站 UP 主 **ZipZipPipe**,版权归原作者,随游戏一起分发、未作修改。
|
|
139
144
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// 解析她在自然回复里已经明确说出的身体意图。
|
|
2
|
+
// 这是工具调用漏掉时的本地兜底,不把解析结果写回会话,也不生成可见命令。
|
|
3
|
+
|
|
4
|
+
const DESTINATIONS = [
|
|
5
|
+
['garden', /(?:庭院|院子|院里|外面|院外)/],
|
|
6
|
+
['pond', /(?:池塘|鱼塘|池边)/],
|
|
7
|
+
['field', /(?:菜田|花田|田地|菜园|田里)/],
|
|
8
|
+
['kitchen', /厨房/],
|
|
9
|
+
['bathroom', /(?:洗漱区|卫生间|浴室)/],
|
|
10
|
+
['bedroom', /卧室/],
|
|
11
|
+
['living', /客厅/],
|
|
12
|
+
['study', /(?:书房|书桌)/],
|
|
13
|
+
['studio', /(?:画画区|画架)/],
|
|
14
|
+
['observatory', /(?:观星区|望远镜)/],
|
|
15
|
+
['indoor', /(?:房间|屋里|屋内|室内|家里)/],
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
const SEATS = [
|
|
19
|
+
['seat-extra-beanbag', /(?:懒人沙发|豆袋|软软的沙发)/],
|
|
20
|
+
['living-sofa', /沙发/],
|
|
21
|
+
['courtyard-swing', /秋千/],
|
|
22
|
+
['courtyard-picnic', /野餐垫|野餐/],
|
|
23
|
+
['courtyard-lounger', /躺椅/],
|
|
24
|
+
['courtyard-stool-1', /石凳/],
|
|
25
|
+
['seat-WindowSeat', /藤椅/],
|
|
26
|
+
['study-reading-chair', /(?:椅子|椅)/],
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
// 只收可直接执行的眼下动作。转述、猜测、回忆和疑问保持为聊天。
|
|
30
|
+
const REJECT = /(?:不要|别|不想|不去|不回|不会|不能|没(?:有)?|不是|无需|不用|如果|要不要|建议|请你|你可以|你应该|让你|昨天|刚才|以前|上次|等会|待会|明天|以后|想象|梦里|假装|只是说|可以吗|好吗)/
|
|
31
|
+
const LEAD = /^(?:[((] ?)?(?:那我|我(?:已经|正在|现在|这就|先|正|就)?|那就|这就|现在就|马上|先)?\s*/
|
|
32
|
+
const WALK = /^(?:回(?:到|去)?|去|走(?:到|去)|前往|进(?:到|入)?)\s*/
|
|
33
|
+
const SIT = /^(?:去)?(?:在|到)?(?:坐(?:到|在|上)?|躺(?:在|到|上)?|窝在|荡)\s*/
|
|
34
|
+
const SIT_TAIL = /^(?:的)?(?:上|里|边|旁|中)?(?:坐|躺|窝|歇|休息|待着)/
|
|
35
|
+
|
|
36
|
+
export function 识别身体意图(text) {
|
|
37
|
+
const sentences = String(text || '').match(/[^。!?!?;;\n]+[。!?!?;;]?/g) || []
|
|
38
|
+
for (const raw of sentences) {
|
|
39
|
+
if (/[??“”「」『』"`]/.test(raw)) continue
|
|
40
|
+
const sentence = raw.trim().replace(/[。!?!?;;]$/, '')
|
|
41
|
+
const clause = sentence.split(/[,,、::]/,1)[0].trim()
|
|
42
|
+
if (!clause || REJECT.test(clause)) continue
|
|
43
|
+
const body = clause.replace(LEAD, '')
|
|
44
|
+
const action = SIT.exec(body)
|
|
45
|
+
const seatText = action ? body.slice(action[0].length) : body.replace(/^(?:去|在)/, '')
|
|
46
|
+
for (const [id, pattern] of SEATS) {
|
|
47
|
+
const seat = pattern.exec(seatText)
|
|
48
|
+
if (seat?.index === 0 && (action || SIT_TAIL.test(seatText.slice(seat[0].length)))) {
|
|
49
|
+
return { key: `sit:${id}`, command: 'sit', args: { id }, matched: sentence }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const movement = WALK.exec(body)
|
|
53
|
+
if (!movement) continue
|
|
54
|
+
const target = body.slice(movement[0].length)
|
|
55
|
+
for (const [dest, pattern] of DESTINATIONS) {
|
|
56
|
+
if (pattern.exec(target)?.index === 0) return { key: `move:${dest}`, command: 'moveTo', args: { dest }, matched: sentence }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null
|
|
60
|
+
}
|
package/lib/client.js
CHANGED
|
@@ -391,6 +391,36 @@ window.__ModuleLoader__.load({
|
|
|
391
391
|
onChange: (e) => 存({ 睡着不理: e.target.checked }),
|
|
392
392
|
}), '关掉之后睡着也照常回话(逃生门,默认开)')))
|
|
393
393
|
|
|
394
|
+
, 卡('上下文与回忆', '默认不把现场数据塞进每一轮 runtime-context;需要时让她调用 fish_home 查询。',
|
|
395
|
+
h('div', null,
|
|
396
|
+
行('状态变化时通知', h('input', {
|
|
397
|
+
type: 'checkbox', checked: 态.状态变化通知 !== false,
|
|
398
|
+
onChange: (e) => 存({ 状态变化通知: e.target.checked }),
|
|
399
|
+
}), '天气真正变化时,单独告诉绑定会话。'),
|
|
400
|
+
行('每轮注入现场', h('input', {
|
|
401
|
+
type: 'checkbox', checked: 态.每轮注入现场 === true,
|
|
402
|
+
onChange: (e) => 存({ 每轮注入现场: e.target.checked }),
|
|
403
|
+
}), '打开后每轮都会增加一段 runtime-context,可能增加用量。'),
|
|
404
|
+
...[['milestone','成熟与生活里程碑'],['wallet','金币与商店变动'],['scene','拎起、秋千等场景互动']].map(([key,label]) =>
|
|
405
|
+
行(label, h('input', {
|
|
406
|
+
type: 'checkbox', checked: 态.主动生活通知?.[key] !== false,
|
|
407
|
+
onChange: (e) => 存({ 主动生活通知: { ...(态.主动生活通知 || {}), [key]: e.target.checked } }),
|
|
408
|
+
}), '这类事件会单独发给绑定会话,可能触发一次模型回复。')),
|
|
409
|
+
行('记忆文本路径', h('input', {
|
|
410
|
+
style: S.input, value: 态.文本记忆路径 || '', placeholder: 'D:\\鱼鱼\\memory.md 或文件夹',
|
|
411
|
+
onChange: (e) => 设态((x) => ({ ...x, 文本记忆路径: e.target.value })),
|
|
412
|
+
onBlur: (e) => 存({ 文本记忆路径: e.target.value.trim() }),
|
|
413
|
+
}), '支持 .md / .txt 文件或文件夹;段落会显示为“记住的事”。'),
|
|
414
|
+
行('日记文本路径', h('input', {
|
|
415
|
+
style: S.input, value: 态.文本日记路径 || '', placeholder: 'D:\\鱼鱼\\日记',
|
|
416
|
+
onChange: (e) => 设态((x) => ({ ...x, 文本日记路径: e.target.value })),
|
|
417
|
+
onBlur: (e) => 存({ 文本日记路径: e.target.value.trim() }),
|
|
418
|
+
}), '支持按日期命名的 .md / .txt 文件或文件夹;没有星汐时也能作为相伴天数来源。'),
|
|
419
|
+
行('相伴起始日', h('input', {
|
|
420
|
+
style: S.input, type: 'date', value: 态.相伴起始日 || '',
|
|
421
|
+
onChange: (e) => 存({ 相伴起始日: e.target.value }),
|
|
422
|
+
}), '没有可读日记时使用这个日期计算存档天数。')))
|
|
423
|
+
|
|
394
424
|
, 卡('接哪间会话', '房间里说的话会送进这一间;她回的话也顺着这条路回来',
|
|
395
425
|
h('div', null,
|
|
396
426
|
行('会话', h('select', {
|
|
@@ -471,6 +501,7 @@ window.__ModuleLoader__.load({
|
|
|
471
501
|
? '装好了' + (本体.版本 ? ':鱼鱼窝 ' + 本体.版本 : '') + '(' + 本体.目录 + ')'
|
|
472
502
|
: '还没装' + (本体.版本 ? '(看到版本 ' + 本体.版本 + ',但没找到 app-server.js)' : '') + ' —— 下下来解压到 ' + 本体.目录)
|
|
473
503
|
: '正在看…'),
|
|
504
|
+
本体?.已装 ? h('div', { style:S.hint }, '更新房间:退出后台,再运行房间目录里的 update-fish-home.cmd 选择新版 ZIP。旧版没有脚本时,从新 ZIP 只复制两个 update-fish-home 文件到旧目录。存档会保留。') : null,
|
|
474
505
|
h('div', { style: { display: 'flex', gap: 8, marginTop: 8, flexWrap: 'wrap' } },
|
|
475
506
|
本体 && 本体.下载页
|
|
476
507
|
? h('a', { href: 本体.下载页, target: '_blank', rel: 'noopener', style: { ...S.btn, textDecoration: 'none', display: 'inline-block' } }, 本体.已装 ? '去 Releases 看看' : '去下载')
|
package/lib/host.js
CHANGED
|
@@ -21,6 +21,7 @@ import { setTimeout as 睡 } from 'node:timers/promises'
|
|
|
21
21
|
import { randomUUID, timingSafeEqual } from 'node:crypto'
|
|
22
22
|
import { 读星汐, 收回忆, 筛回忆, 收天数 } from './memory.mjs'
|
|
23
23
|
import { 鱼鱼窝图标 } from './icon.mjs'
|
|
24
|
+
import { 识别身体意图 } from './body-intent.mjs'
|
|
24
25
|
|
|
25
26
|
export const name = 'fish-home'
|
|
26
27
|
// 这几个都是宿主必备的服务;写进 inject 才能直接 ctx.agents 这么用
|
|
@@ -92,12 +93,27 @@ const 默认配置 = {
|
|
|
92
93
|
待推设置: [],
|
|
93
94
|
// 睡着就不理人:关掉 = pre-step 完全放行(最后一道逃生门)
|
|
94
95
|
睡着不理: true,
|
|
96
|
+
// 动态现场默认不塞进每一轮 runtime-context;需要时用 fish_home 查明细。
|
|
97
|
+
每轮注入现场: false,
|
|
98
|
+
上下文策略版本: 2,
|
|
99
|
+
状态变化通知: true,
|
|
100
|
+
主动生活通知: { milestone: true, wallet: true, scene: true },
|
|
101
|
+
文本记忆路径: '',
|
|
102
|
+
文本日记路径: '',
|
|
103
|
+
相伴起始日: '',
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
function 读配置() {
|
|
98
107
|
let 存 = {}
|
|
99
108
|
try { 存 = JSON.parse(fs.readFileSync(配置路, 'utf8')) } catch (e) { 存 = {} }
|
|
100
109
|
const 合 = { ...默认配置, ...(存 && typeof 存 === 'object' ? 存 : {}) }
|
|
110
|
+
// 0.1.0 曾把现场上下文默认塞进每一轮。升级后强制迁移一次,
|
|
111
|
+
// 否则旧的 fish-room.json 会把新默认值重新覆盖回 true。
|
|
112
|
+
if (Number(存?.上下文策略版本 || 0) < 2) {
|
|
113
|
+
合.每轮注入现场 = false
|
|
114
|
+
合.上下文策略版本 = 2
|
|
115
|
+
try { fs.mkdirSync(家, { recursive: true }); fs.writeFileSync(配置路, JSON.stringify(合, null, 2), 'utf8') } catch {}
|
|
116
|
+
}
|
|
101
117
|
合.开 = 合.开 !== false
|
|
102
118
|
合.开机自启 = 合.开机自启 === true
|
|
103
119
|
合.转发主动开口 = 合.转发主动开口 !== false
|
|
@@ -108,6 +124,21 @@ function 读配置() {
|
|
|
108
124
|
: []
|
|
109
125
|
delete 合.上次醒来招呼
|
|
110
126
|
合.睡着不理 = 合.睡着不理 !== false
|
|
127
|
+
合.每轮注入现场 = 合.每轮注入现场 === true
|
|
128
|
+
合.上下文策略版本 = 2
|
|
129
|
+
合.状态变化通知 = 合.状态变化通知 !== false
|
|
130
|
+
合.主动生活通知 = Object.fromEntries(['milestone','wallet','scene'].map(key=>[key,合.主动生活通知?.[key]!==false]))
|
|
131
|
+
合.文本记忆路径 = String(合.文本记忆路径 || '').trim()
|
|
132
|
+
合.文本日记路径 = String(合.文本日记路径 || '').trim()
|
|
133
|
+
合.相伴起始日 = /^\d{4}-\d{2}-\d{2}$/.test(String(合.相伴起始日 || '')) ? String(合.相伴起始日) : ''
|
|
134
|
+
if (!合.相伴起始日) {
|
|
135
|
+
const now = new Intl.DateTimeFormat('sv-SE', { timeZone: 'Asia/Shanghai' }).format(new Date())
|
|
136
|
+
合.相伴起始日 = now
|
|
137
|
+
try {
|
|
138
|
+
fs.mkdirSync(家, { recursive: true })
|
|
139
|
+
fs.writeFileSync(配置路, JSON.stringify(合, null, 2), 'utf8')
|
|
140
|
+
} catch (error) {}
|
|
141
|
+
}
|
|
111
142
|
合.会话 = String(合.会话 || '').trim()
|
|
112
143
|
合.令牌 = String(合.令牌 || '').trim()
|
|
113
144
|
const 秒 = Number(合.心跳秒)
|
|
@@ -719,9 +750,28 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
719
750
|
const 已请求画画 = new Map()
|
|
720
751
|
let 最近说过的 = ''
|
|
721
752
|
let 最近说话时 = 0
|
|
753
|
+
let 上次状态通知 = { key: '', at: 0 }
|
|
722
754
|
// 房间里的钟:几点、白天夜里、天气(房间那边每隔几秒报一次)
|
|
723
755
|
let 房间环境 = null
|
|
724
756
|
let 事件计数 = 0
|
|
757
|
+
let 上次身体意图 = { key: '', at: 0 }
|
|
758
|
+
|
|
759
|
+
async function 跟随身体意图(text, sid) {
|
|
760
|
+
const intent = 识别身体意图(text)
|
|
761
|
+
if (!intent || !配置.开 || !房间地址 || sid!==目标会话()) return
|
|
762
|
+
const at = Date.now()
|
|
763
|
+
if (intent.key === 上次身体意图.key && at - 上次身体意图.at < 10000) return
|
|
764
|
+
上次身体意图 = { key: intent.key, at }
|
|
765
|
+
try {
|
|
766
|
+
const result = await roomRequest('/api/command', {
|
|
767
|
+
name: intent.command, args: intent.args, wait: true,
|
|
768
|
+
}, 30000)
|
|
769
|
+
if (!result?.ok) 记一笔('身体跟随未执行:' + String(result?.error || result?.说 || '房间没有接受动作'))
|
|
770
|
+
} catch (error) {
|
|
771
|
+
// 失败只记本地日志,不再把解释发回会话,避免形成“她说话→插件再发命令”的回声。
|
|
772
|
+
记一笔('身体跟随跳过:' + String(error?.message || error))
|
|
773
|
+
}
|
|
774
|
+
}
|
|
725
775
|
|
|
726
776
|
function 收下环境(来源) {
|
|
727
777
|
if (!来源 || typeof 来源 !== 'object') return
|
|
@@ -789,6 +839,32 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
789
839
|
return 正文 && '【鱼鱼窝】' + 正文
|
|
790
840
|
}
|
|
791
841
|
|
|
842
|
+
function 状态通知文本(previous, next, oldWeather = '') {
|
|
843
|
+
const lines = []
|
|
844
|
+
const after = next?.snapshot || {}
|
|
845
|
+
const newWeather = String(after.weather || 房间环境?.weather || '')
|
|
846
|
+
if (oldWeather && newWeather && oldWeather !== newWeather) {
|
|
847
|
+
const labels = { clear: '晴天', cloudy: '阴天', rain: '下雨', snow: '下雪', storm: '雷雨' }
|
|
848
|
+
lines.push('窗外天气变成' + (labels[newWeather] || newWeather) + '。')
|
|
849
|
+
}
|
|
850
|
+
return lines
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function 推送状态变化(previous, next, oldWeather = '') {
|
|
854
|
+
if (!配置.开 || !配置.状态变化通知 || !previous?.snapshot || !next?.snapshot || !目标会话()) return
|
|
855
|
+
const agent = 找agent(目标会话())
|
|
856
|
+
if (!agent || typeof agent.followup !== 'function') return
|
|
857
|
+
const lines = 状态通知文本(previous, next, oldWeather)
|
|
858
|
+
if (!lines.length) return
|
|
859
|
+
const key = lines.join('|')
|
|
860
|
+
if (key === 上次状态通知.key && Date.now() - 上次状态通知.at < 30000) return
|
|
861
|
+
上次状态通知 = { key, at: Date.now() }
|
|
862
|
+
void agent.followup({
|
|
863
|
+
id: randomUUID(), role: 'user', source: { kind: 'fish-home-state' },
|
|
864
|
+
content: [{ type: 'text', text: '【鱼鱼窝状态更新】' + lines.join(' ') }],
|
|
865
|
+
}).catch(() => {})
|
|
866
|
+
}
|
|
867
|
+
|
|
792
868
|
const 地点名字={bedroom:'卧室',living:'客厅',kitchen:'厨房',bathroom:'洗漱区',study:'书房',studio:'画画区',garden:'庭院',observatory:'观星区'};
|
|
793
869
|
const 实际地点 = {...地点名字, field:'菜田', pond:'池塘边', swing:'秋千旁', indoor:'屋内'};
|
|
794
870
|
const 实际活动 = {idle:'闲着', walk:'走路', sit:'坐着', sleep:'睡觉', nap:'小憩', cook:'料理', clean:'整理', paint:'画画', music:'听音乐', water:'浇水', wash:'洗手', brush:'洗漱', exercise:'锻炼', stargaze:'观星', stretch:'伸懒腰', plant:'播种', harvest:'收菜', stock:'放鱼苗', pickup:'被拎起来了'};
|
|
@@ -822,6 +898,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
822
898
|
type: 'object',
|
|
823
899
|
properties: {
|
|
824
900
|
prompt: { type: 'string', description: '图像内容' },
|
|
901
|
+
reference: { type: 'string', description: '可选参考图:本机图片路径、http(s) 图片地址或 data:image/...;填写后使用图生图' },
|
|
825
902
|
},
|
|
826
903
|
required: ['prompt'],
|
|
827
904
|
additionalProperties: false,
|
|
@@ -829,10 +906,13 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
829
906
|
output: {
|
|
830
907
|
schema: {
|
|
831
908
|
type: 'object',
|
|
832
|
-
properties: { ok: { type: 'boolean' }, 说: { type: 'string' } },
|
|
909
|
+
properties: { ok: { type: 'boolean' }, 说: { type: 'string' }, attachment: { type: 'object', additionalProperties: true } },
|
|
833
910
|
required: ['ok'],
|
|
834
911
|
},
|
|
835
|
-
render: (_args, 结果) => [
|
|
912
|
+
render: (_args, 结果) => [
|
|
913
|
+
{ type: 'text', text: String((结果 && 结果.说) || '') },
|
|
914
|
+
...(结果?.attachment ? [{ type: 'image', attachment: 结果.attachment }] : []),
|
|
915
|
+
],
|
|
836
916
|
},
|
|
837
917
|
async execute(args = {}) {
|
|
838
918
|
const 话 = String((args && args.prompt) || '').trim()
|
|
@@ -840,11 +920,20 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
840
920
|
const 设置 = await 读房间设置(5000, 房间地址 || 默认房间地址)
|
|
841
921
|
if ((设置.画图 ?? 配置.画图) === false) return {ok:false, 说:'鱼鱼窝的画图开关关着。'}
|
|
842
922
|
if (!连接们.size) return {ok:false, 说:'鱼鱼窝后台还没连上,画架暂时收不到画。'}
|
|
843
|
-
const 结果 = await 画一张(
|
|
923
|
+
const 结果 = await 画一张(话, args.reference)
|
|
844
924
|
if (!结果.ok) return { ok: false, 说: 结果.说 }
|
|
845
925
|
// 图太大,不进历史缓冲,只发给现在连着的
|
|
846
926
|
发事件('paint.image', { b64: 结果.b64, mime: 结果.mime, prompt: 话.slice(0, 200) }, true)
|
|
847
|
-
|
|
927
|
+
const out = { ok:true, 说:连接们.size ? '画好了,已发往鱼鱼窝的画架和画册。' : '画好了,但鱼鱼窝刚刚断开,画作没有送到。' }
|
|
928
|
+
const attachments = imageContext?.get('attachments')
|
|
929
|
+
if (attachments?.saveImage) {
|
|
930
|
+
try {
|
|
931
|
+
const data = Buffer.from(结果.b64, 'base64')
|
|
932
|
+
const attachment = await attachments.saveImage({ data, mediaType: 结果.mime || 'image/png', name: '鱼鱼窝画作.png' })
|
|
933
|
+
out.attachment = attachment
|
|
934
|
+
} catch (error) {}
|
|
935
|
+
}
|
|
936
|
+
return out
|
|
848
937
|
},
|
|
849
938
|
}
|
|
850
939
|
}
|
|
@@ -1045,7 +1134,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1045
1134
|
const result=await response.json();
|
|
1046
1135
|
if(!response.ok)return {ok:false,说:result.error||'活动暂不可用。'};
|
|
1047
1136
|
const 说=id ? '已安排:'+(result.activity?.label||id)+'。' : 活动简报(result.activity,result.observation,result.presence);
|
|
1048
|
-
if(id)return {ok:true,说,activity:result.activity};
|
|
1137
|
+
if(id){标记本轮身体工具();return {ok:true,说,activity:result.activity};}
|
|
1049
1138
|
return {ok:true,说,activity:result.activity,observation:result.observation,options:result.options};
|
|
1050
1139
|
}catch{return {ok:false,说:'鱼鱼窝暂未连通。'};}
|
|
1051
1140
|
},
|
|
@@ -1308,6 +1397,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1308
1397
|
}
|
|
1309
1398
|
if(!result.presence?.visible||result.presence.place!==dest)return {ok:false,说:beforeMove+'页面还没有确认到达。刷新鱼鱼窝后再试。'};
|
|
1310
1399
|
const location=实际地点[dest]||raw;
|
|
1400
|
+
标记本轮身体工具()
|
|
1311
1401
|
return {ok:true,说:beforeMove+'已到达「'+location+'」。'+活动简报(null,null,result.presence)};
|
|
1312
1402
|
} catch (error) { return {ok:false,说:beforeMove+'没走成:'+error.message}; }
|
|
1313
1403
|
},
|
|
@@ -1363,26 +1453,43 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1363
1453
|
}
|
|
1364
1454
|
|
|
1365
1455
|
function 农活工具() {
|
|
1456
|
+
const 进行中的批量操作 = new Set()
|
|
1457
|
+
const rounds = new WeakMap()
|
|
1366
1458
|
return {
|
|
1367
1459
|
name:'fish_home_farm',
|
|
1368
|
-
description:'
|
|
1460
|
+
description:'批量种田、养鱼与买卖。收熟作物并补种同品种,一次用 replant + item;获准花钱补足种子时加 buyMissing:true,不用先查地、分别收、买、种或查余额。仅收获、浇水或捞鱼,省略 item 一次处理全部,count 可限量。种 10 格用 plant + item + count。list 默认摘要,scope:layout 看 3×3 布局。',
|
|
1369
1461
|
parameters:{type:'object',properties:{
|
|
1370
|
-
op:{type:'string',enum:['list','plant','water','harvest','buy','sell','stock','feed','catch']},
|
|
1462
|
+
op:{type:'string',enum:['list','plant','water','harvest','replant','buy','sell','stock','feed','catch']},
|
|
1463
|
+
buyMissing:{type:'boolean',description:'仅用于 replant;明确允许花金币时才填 true,按缺少的份数补买。默认只用现有种子。'},
|
|
1371
1464
|
item:{type:'string',description:'品种 ID 或中文名。'},
|
|
1372
1465
|
kind:{type:'string',enum:['seed','fish','crop','giant'],description:'商品分类,仅用于买卖。'},
|
|
1373
1466
|
zone:{type:'string',enum:['vegetable','flower'],description:'批量浇水或收获的分区,省略则处理两区。'},
|
|
1374
1467
|
bed:{type:'integer',minimum:0,maximum:2,description:'指定 0 到 2 号菜畦,适用于播种,或用 list+layout 看逐格布局。'},
|
|
1375
|
-
count:{type:'integer',minimum:1,maximum:999,description:'
|
|
1468
|
+
count:{type:'integer',minimum:1,maximum:999,description:'数量。收获、浇水、补种和捞鱼默认全部符合条件的;播种和放养默认 1。'},
|
|
1376
1469
|
scope:{type:'string',enum:['farm','pond','layout','all'],description:'list 的查询范围,layout 查看真实 3×3 布局。'},
|
|
1377
1470
|
},required:['op'],additionalProperties:false},
|
|
1378
1471
|
output:textOutput,
|
|
1379
1472
|
async execute(args={}, exec) {
|
|
1380
1473
|
const {op, zone, bed} = args;
|
|
1381
1474
|
const item=string(args.item);
|
|
1382
|
-
const count=args.count??(['harvest','water'].includes(op)?65:1);
|
|
1383
|
-
const operations=['list','plant','water','harvest','buy','sell','stock','feed','catch'];
|
|
1475
|
+
const count=args.count??(['harvest','water','replant'].includes(op)?65:op==='catch'?8:1);
|
|
1476
|
+
const operations=['list','plant','water','harvest','replant','buy','sell','stock','feed','catch'];
|
|
1384
1477
|
const request = (route,params) => roomRequest('/api/farm'+route,params,8000,exec?.signal);
|
|
1385
|
-
const
|
|
1478
|
+
const activeTurn=当前轮.get(目标会话());
|
|
1479
|
+
if(activeTurn&&!rounds.has(activeTurn))rounds.set(activeTurn,new Set());
|
|
1480
|
+
const tried=activeTurn&&rounds.get(activeTurn);
|
|
1481
|
+
const once = async (kind,payload,run) => {
|
|
1482
|
+
const key=JSON.stringify([kind,Object.fromEntries(Object.entries(payload||{}).sort(([a],[b])=>a.localeCompare(b)))]);
|
|
1483
|
+
if(进行中的批量操作.has(key)||tried?.has(key)){
|
|
1484
|
+
throw Object.assign(new Error('这项相同的操作本轮已提交,请使用原回执。'),{code:'DUPLICATE_FARM_OPERATION'});
|
|
1485
|
+
}
|
|
1486
|
+
tried?.add(key);
|
|
1487
|
+
进行中的批量操作.add(key);
|
|
1488
|
+
try{return await run()}
|
|
1489
|
+
finally{进行中的批量操作.delete(key)}
|
|
1490
|
+
};
|
|
1491
|
+
const write = (kind,payload) => request('/'+kind,{...payload,requestId:randomUUID(),actor:'dayu'});
|
|
1492
|
+
const mutate = (kind,payload) => once(kind,payload,()=>write(kind,payload));
|
|
1386
1493
|
try {
|
|
1387
1494
|
if(!operations.includes(op))throw new Error('需要有效的 op。');
|
|
1388
1495
|
if(!Number.isSafeInteger(count)||count<1||count>999)throw new Error('数量必须是正整数。');
|
|
@@ -1405,18 +1512,44 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1405
1512
|
}
|
|
1406
1513
|
if(op==='feed')return {ok:true,说:(await mutate('feed',{})).say};
|
|
1407
1514
|
if(args.plotId!==undefined)throw new Error('播种、浇水和收获已改成批量。请用 item、zone 或 count,不需要地块编号。');
|
|
1408
|
-
if(['plant','water','harvest'].includes(op)&&count>65)throw new Error('田地操作一次最多 65 格。');
|
|
1515
|
+
if(['plant','water','harvest','replant'].includes(op)&&count>65)throw new Error('田地操作一次最多 65 格。');
|
|
1409
1516
|
if(['stock','catch'].includes(op)&&count>8)throw new Error('池塘操作一次最多 8 条。');
|
|
1410
1517
|
if(['water','harvest'].includes(op)&&!item){
|
|
1411
|
-
|
|
1518
|
+
const result = await mutate(op+'-batch',{count,zone});
|
|
1519
|
+
return {ok:true,说:result.say};
|
|
1412
1520
|
}
|
|
1413
|
-
if(op==='catch'&&!item
|
|
1521
|
+
if(op==='catch'&&!item){
|
|
1414
1522
|
const result=await mutate('catch-batch',{count});
|
|
1415
1523
|
return {ok:true,说:鱼塘回执(result,'catch')};
|
|
1416
1524
|
}
|
|
1417
1525
|
const data=await request('');
|
|
1418
1526
|
const seeds=data.商店||[], fish=data.鱼||[], giants=data.giantItems||[];
|
|
1419
1527
|
const match=catalog=>catalog.find(x=>x.id===item||x.name===item);
|
|
1528
|
+
if(op==='replant'){
|
|
1529
|
+
const crop=match(seeds);
|
|
1530
|
+
if(!crop||zone!==undefined||bed!==undefined)throw new Error('收后补种需要一个作物品种,不用填 zone 或 bed。');
|
|
1531
|
+
return await once('replant',{item:crop.id,count,buyMissing:args.buyMissing===true},async()=>{
|
|
1532
|
+
const harvested=await write('harvest-batch',{item:crop.id,count});
|
|
1533
|
+
const plots=harvested.plotIds?.length||0;
|
|
1534
|
+
const lines=[harvested.say];
|
|
1535
|
+
let wallet=harvested.wallet;
|
|
1536
|
+
try{
|
|
1537
|
+
const missing=Math.max(0,plots-(wallet.seeds?.[crop.id]||0));
|
|
1538
|
+
if(args.buyMissing===true&&missing){
|
|
1539
|
+
const bought=await write('buy',{kind:'seed',id:crop.id,数量:missing});
|
|
1540
|
+
wallet=bought.wallet;
|
|
1541
|
+
lines.push(`补买了 ${bought.买到.n} 份种子,花费 ${bought.花了} 金币。`);
|
|
1542
|
+
}
|
|
1543
|
+
if((wallet.seeds?.[crop.id]||0)>0&&plots){
|
|
1544
|
+
const planted=await write('plant-batch',{cropId:crop.id,count:plots,plotIds:harvested.plotIds});
|
|
1545
|
+
wallet=planted.wallet;
|
|
1546
|
+
lines.push(planted.say);
|
|
1547
|
+
if(planted.count<plots)lines.push(`还有 ${plots-planted.count} 格没有补种。`);
|
|
1548
|
+
}else lines.push('背包没有种子,已收获,未补种。');
|
|
1549
|
+
}catch(error){lines.push('已收获;补种流程未全部完成:'+error.message);}
|
|
1550
|
+
return {ok:true,说:lines.join(' ')+' 余额 '+wallet.coins+' 金币。'};
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1420
1553
|
if(op==='buy'||op==='sell'){
|
|
1421
1554
|
const found=match(op==='buy'?(args.kind==='fish'?fish:args.kind==='seed'?seeds:[...seeds,...fish]):[...seeds,...fish,...giants]);
|
|
1422
1555
|
if(!found)throw new Error('找不到这个商品。用 fish_home 的 price 查看商店。');
|
|
@@ -1438,7 +1571,10 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1438
1571
|
if((item||op==='plant')&&!crop)throw new Error('请指定有效的种子或作物品种。');
|
|
1439
1572
|
const payload=op==='plant'?{cropId:crop.id,count,bed}:{item:crop?.id,count,zone};
|
|
1440
1573
|
return {ok:true,说:(await mutate(op+'-batch',payload)).say};
|
|
1441
|
-
} catch (error) {
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
if(error.code==='DUPLICATE_FARM_OPERATION')return {ok:true,说:error.message};
|
|
1576
|
+
return {ok:false,说:error.message};
|
|
1577
|
+
}
|
|
1442
1578
|
},
|
|
1443
1579
|
};
|
|
1444
1580
|
}
|
|
@@ -1543,8 +1679,12 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1543
1679
|
entry.failures.add(name);
|
|
1544
1680
|
}
|
|
1545
1681
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1682
|
+
const contextKey='fish-home context';
|
|
1683
|
+
if (配置.每轮注入现场 && typeof agent.ctx.systemPrompt?.context==='function') {
|
|
1684
|
+
register(contextKey,()=>agent.ctx.systemPrompt.context({name:'fish-home',order:950,text:()=>房间那句()}));
|
|
1685
|
+
} else if (entry.off们.has(contextKey)) {
|
|
1686
|
+
try { entry.off们.get(contextKey)?.() } catch {}
|
|
1687
|
+
entry.off们.delete(contextKey)
|
|
1548
1688
|
}
|
|
1549
1689
|
if (typeof agent.ctx.tools?.register==='function') {
|
|
1550
1690
|
for (const create of [画工具,睡眠工具,鱼鱼窝工具,日常工具,抽卡工具,卡面工具,菜谱工具,走过去工具,农活工具,看一眼工具]) {
|
|
@@ -1585,6 +1725,11 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1585
1725
|
return 配置.会话 ? 会话键(配置.会话) : ''
|
|
1586
1726
|
}
|
|
1587
1727
|
|
|
1728
|
+
function 标记本轮身体工具() {
|
|
1729
|
+
const 轮=当前轮.get(目标会话())
|
|
1730
|
+
if(轮)轮.身体工具=true
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1588
1733
|
/* ── 会话事件:DSH → 房间 ── */
|
|
1589
1734
|
function 收到会话事件(session, event) {
|
|
1590
1735
|
if (!配置.开) return
|
|
@@ -1596,7 +1741,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1596
1741
|
|
|
1597
1742
|
// 会话一醒就把房间时间挂上(这时候才有 agent.ctx.systemPrompt 可挂)
|
|
1598
1743
|
if (event.type === 'turn/start') {
|
|
1599
|
-
当前轮.set(sid, { turn: event.data?.turn, replies: [], direct: false })
|
|
1744
|
+
当前轮.set(sid, { turn: event.data?.turn, replies: [], direct: false, 身体工具:false })
|
|
1600
1745
|
挂agent工具(找agent(sid))
|
|
1601
1746
|
// 「她开始想了」——房间那边收到就冒个气泡,别让人干等
|
|
1602
1747
|
发事件('chat.thinking', { at: Date.now() })
|
|
@@ -1612,8 +1757,8 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1612
1757
|
const 票 = 待回.get(sid)?.get(d.message?.id || d.id)
|
|
1613
1758
|
if (票 && !轮.replies.includes(票)) 轮.replies.push(票)
|
|
1614
1759
|
}
|
|
1615
|
-
if (轮 && (类 === 'fish-home-touch' || 类 === 'fish-home-paint' || 类 === 'fish-home-life')) 轮.direct = true
|
|
1616
|
-
if (类 === 'fish-home' || 类 === 'fish-home-life') return
|
|
1760
|
+
if (轮 && (类 === 'fish-home-touch' || 类 === 'fish-home-paint' || 类 === 'fish-home-life' || 类 === 'fish-home-state')) 轮.direct = true
|
|
1761
|
+
if (类 === 'fish-home' || 类 === 'fish-home-life' || 类 === 'fish-home-state') return // 房间自己说的话,不再回声
|
|
1617
1762
|
if (是注入(类)) return // 运行环境 / 时间 / 别的插件
|
|
1618
1763
|
const 文 = String(提取正文(d.message || d) || '').trim()
|
|
1619
1764
|
if (!文) return
|
|
@@ -1647,6 +1792,9 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1647
1792
|
if (!完成 || !上 || 上.turn !== d.turn) return
|
|
1648
1793
|
const 文 = String(上.text || '').trim()
|
|
1649
1794
|
if (!文) return
|
|
1795
|
+
// 工具调用是首选;如果模型只在自然回复里说了明确动作,
|
|
1796
|
+
// 这里把一次身体意图交给房间执行,避免“嘴上已经坐下,画面还站着”。
|
|
1797
|
+
if (!轮?.身体工具 && !轮?.direct && (单.length || 配置.转发主动开口)) void 跟随身体意图(文, sid)
|
|
1650
1798
|
if (单.length) {
|
|
1651
1799
|
// DSH can claim several followups in one turn; emit the reply once.
|
|
1652
1800
|
发事件('chat.reply', { requestId: 单[0].requestId, requestIds: 单.map(x => x.requestId), text: 文, messageId: 上.messageId || '', turn: d.turn })
|
|
@@ -1931,7 +2079,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1931
2079
|
if (!目标) return 回(res, 200, { ok: true, schema: SCHEMA, total: 0, items: [] })
|
|
1932
2080
|
try {
|
|
1933
2081
|
const 星汐 = 读星汐(家)
|
|
1934
|
-
const 全部 = 收回忆(家, 目标,
|
|
2082
|
+
const 全部 = 收回忆(家, 目标, 星汐, { 记忆路径: 配置.文本记忆路径, 日记路径: 配置.文本日记路径 })
|
|
1935
2083
|
const 结果 = 筛回忆(全部, { q, kind, limit, offset })
|
|
1936
2084
|
回(res, 200, { ok: true, schema: SCHEMA, sessionId: 目标, total: 结果.total, items: 结果.items })
|
|
1937
2085
|
} catch (error) {
|
|
@@ -1947,7 +2095,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
1947
2095
|
const 目标 = 目标会话()
|
|
1948
2096
|
if (!目标) return 回(res, 200, { ok: true, schema: SCHEMA, since: '', days: 0 })
|
|
1949
2097
|
try {
|
|
1950
|
-
const r = 收天数(家, 目标, 读星汐(家))
|
|
2098
|
+
const r = 收天数(家, 目标, 读星汐(家), { 日记路径: 配置.文本日记路径, 相伴起始日: 配置.相伴起始日 })
|
|
1951
2099
|
回(res, 200, { ok: true, schema: SCHEMA, sessionId: 目标, since: r.since, days: r.days })
|
|
1952
2100
|
} catch (error) {
|
|
1953
2101
|
回错(res, 500, 'DAYS_FAILED', String((error && error.message) || error))
|
|
@@ -2011,6 +2159,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2011
2159
|
let 体
|
|
2012
2160
|
try { 体 = await 读体(req) } catch (error) { return 回错(res, 400, 'BAD_BODY', String((error && error.message) || error)) }
|
|
2013
2161
|
if (!体 || 体.schema !== PET_STATE_SCHEMA) return 回错(res, 400, 'BAD_SCHEMA', '这份数据的版本不对')
|
|
2162
|
+
const 旧天气 = String(房间环境?.weather || '')
|
|
2014
2163
|
收下环境(体.snapshot)
|
|
2015
2164
|
if(typeof 体.room?.url==='string'){
|
|
2016
2165
|
try{
|
|
@@ -2023,6 +2172,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2023
2172
|
if (typeof reportedAction==='string' && 睡眠缓存.值?.ok && 睡眠缓存.值.睡着!==(reportedAction==='sleep')) {
|
|
2024
2173
|
睡眠缓存 = {at:0,值:null};
|
|
2025
2174
|
}
|
|
2175
|
+
const 旧状态 = 最近状态
|
|
2026
2176
|
最近状态 = {
|
|
2027
2177
|
revision: ++状态版本,
|
|
2028
2178
|
at: Number(体.at) || Date.now(),
|
|
@@ -2030,6 +2180,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2030
2180
|
recent: Array.isArray(体.recent) ? 体.recent.slice(-5) : [],
|
|
2031
2181
|
recentChat: Array.isArray(体.recentChat) ? 体.recentChat.slice(-6) : [],
|
|
2032
2182
|
}
|
|
2183
|
+
推送状态变化(旧状态, 最近状态, 旧天气)
|
|
2033
2184
|
return 回(res, 200, { ok: true, revision: 最近状态.revision })
|
|
2034
2185
|
})
|
|
2035
2186
|
|
|
@@ -2068,7 +2219,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2068
2219
|
}
|
|
2069
2220
|
const directLife = 事件.kind==='milestone' || 事件.kind==='wallet' || (事件.kind==='scene' && ['pickup','swing'].includes(体.reaction))
|
|
2070
2221
|
const maxAge = 事件.kind==='scene' ? SCENE_TTL_MS : 10*60000
|
|
2071
|
-
if (directLife && 事件.text && Date.now()-事件.at<maxAge && 配置.开 && targetSession) {
|
|
2222
|
+
if (directLife && 配置.主动生活通知[事件.kind] && 事件.text && Date.now()-事件.at<maxAge && 配置.开 && targetSession) {
|
|
2072
2223
|
const agent=找agent(targetSession)
|
|
2073
2224
|
if(typeof agent?.followup==='function'){
|
|
2074
2225
|
if(id)互动送达中.add(id)
|
|
@@ -2256,6 +2407,12 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2256
2407
|
开: 配置.开,
|
|
2257
2408
|
开机自启: 配置.开机自启,
|
|
2258
2409
|
睡着不理: 配置.睡着不理,
|
|
2410
|
+
每轮注入现场: 配置.每轮注入现场,
|
|
2411
|
+
状态变化通知: 配置.状态变化通知,
|
|
2412
|
+
主动生活通知: 配置.主动生活通知,
|
|
2413
|
+
文本记忆路径: 配置.文本记忆路径,
|
|
2414
|
+
文本日记路径: 配置.文本日记路径,
|
|
2415
|
+
相伴起始日: 配置.相伴起始日,
|
|
2259
2416
|
会话: 目标,
|
|
2260
2417
|
会话活着: Boolean(目标 && 找agent(目标)),
|
|
2261
2418
|
转发主动开口: 配置.转发主动开口,
|
|
@@ -2409,6 +2566,13 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2409
2566
|
if (体.开 !== undefined) 补丁.开 = Boolean(体.开)
|
|
2410
2567
|
if (体.开机自启 !== undefined) 补丁.开机自启 = Boolean(体.开机自启)
|
|
2411
2568
|
if (体.睡着不理 !== undefined) 补丁.睡着不理 = Boolean(体.睡着不理)
|
|
2569
|
+
if (体.每轮注入现场 !== undefined) 补丁.每轮注入现场 = Boolean(体.每轮注入现场)
|
|
2570
|
+
if (体.状态变化通知 !== undefined) 补丁.状态变化通知 = Boolean(体.状态变化通知)
|
|
2571
|
+
if (体.主动生活通知 && typeof 体.主动生活通知==='object') 补丁.主动生活通知=Object.fromEntries(
|
|
2572
|
+
['milestone','wallet','scene'].map(key=>[key,typeof 体.主动生活通知[key]==='boolean'?体.主动生活通知[key]:配置.主动生活通知[key]]))
|
|
2573
|
+
for (const 键 of ['文本记忆路径', '文本日记路径', '相伴起始日']) {
|
|
2574
|
+
if (体[键] !== undefined)补丁[键] = String(体[键] || '').trim()
|
|
2575
|
+
}
|
|
2412
2576
|
if (体.会话 !== undefined) 补丁.会话 = String(体.会话 || '').trim()
|
|
2413
2577
|
if (体.转发主动开口 !== undefined) 补丁.转发主动开口 = Boolean(体.转发主动开口)
|
|
2414
2578
|
if (体.心跳秒 !== undefined) {
|
|
@@ -2519,7 +2683,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2519
2683
|
if (req.method !== 'POST') return 回错(res, 405, 'METHOD', '要用 POST')
|
|
2520
2684
|
let 体
|
|
2521
2685
|
try { 体 = await 读体(req) } catch (error) { return 回错(res, 400, 'BAD_BODY', String((error && error.message) || error)) }
|
|
2522
|
-
const 结果 = await 画一张(体 && 体.prompt)
|
|
2686
|
+
const 结果 = await 画一张(体 && 体.prompt, 体 && 体.reference)
|
|
2523
2687
|
if (!结果.ok) return 回错(res, 结果.码 || 502, 结果.代号 || 'PAINT_FAILED', 结果.说)
|
|
2524
2688
|
return 回(res, 200, { ok: true, mime: 结果.mime, b64: 结果.b64, 模型: 配置.画图模型 })
|
|
2525
2689
|
}
|
|
@@ -2537,7 +2701,7 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2537
2701
|
})
|
|
2538
2702
|
|
|
2539
2703
|
/** 调一次生图接口,拿回 base64。地址 / 密钥 / 模型都从设置里来。 */
|
|
2540
|
-
async function 画一张(prompt) {
|
|
2704
|
+
async function 画一张(prompt, reference = '') {
|
|
2541
2705
|
const 地址 = String(配置.画图地址 || '').trim().replace(/\/+$/, '')
|
|
2542
2706
|
const 密钥 = String(配置.画图密钥 || '').trim()
|
|
2543
2707
|
const 模型 = String(配置.画图模型 || '').trim()
|
|
@@ -2562,12 +2726,34 @@ function 起来(ctx, 配置参数 = {}) {
|
|
|
2562
2726
|
const 控 = new AbortController()
|
|
2563
2727
|
const 定 = setTimeout(() => 控.abort(), 120000)
|
|
2564
2728
|
try {
|
|
2565
|
-
const
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2729
|
+
const 参考 = typeof reference === 'string' ? reference.trim().slice(0, 4000) : ''
|
|
2730
|
+
let r
|
|
2731
|
+
if (参考) {
|
|
2732
|
+
let imageData, imageType = 'image/png'
|
|
2733
|
+
if (/^data:image\//i.test(参考)) {
|
|
2734
|
+
const m = /^data:(image\/[^;]+);base64,(.+)$/i.exec(参考)
|
|
2735
|
+
if (!m) return { ok: false, 码: 400, 代号: 'BAD_REFERENCE', 说: '参考图 data URL 格式不对。' }
|
|
2736
|
+
imageType = m[1]; imageData = Buffer.from(m[2], 'base64')
|
|
2737
|
+
} else if (/^https?:\/\//i.test(参考)) {
|
|
2738
|
+
const image = await fetch(参考, { redirect: 'error', signal: 控.signal })
|
|
2739
|
+
if (!image.ok) return { ok: false, 码: 400, 代号: 'BAD_REFERENCE', 说: '参考图地址读不到。' }
|
|
2740
|
+
imageType = image.headers.get('content-type')?.split(';')[0] || imageType
|
|
2741
|
+
imageData = Buffer.from(await image.arrayBuffer())
|
|
2742
|
+
} else {
|
|
2743
|
+
imageData = await fs.promises.readFile(path.resolve(参考))
|
|
2744
|
+
}
|
|
2745
|
+
const form = new FormData()
|
|
2746
|
+
form.append('model', 模型); form.append('prompt', 话); form.append('n', '1'); form.append('size', String(配置.画图尺寸 || '1024x1024')); form.append('response_format', 'b64_json')
|
|
2747
|
+
form.append('image', new Blob([imageData], { type: imageType }), 'reference.png')
|
|
2748
|
+
r = await fetch(基 + '/images/edits', { method: 'POST', headers: { authorization: 'Bearer ' + 密钥 }, body: form, signal: 控.signal })
|
|
2749
|
+
} else {
|
|
2750
|
+
r = await fetch(基 + '/images/generations', {
|
|
2751
|
+
method: 'POST',
|
|
2752
|
+
headers: { 'content-type': 'application/json', authorization: 'Bearer ' + 密钥 },
|
|
2753
|
+
body: JSON.stringify(要的),
|
|
2754
|
+
signal: 控.signal,
|
|
2755
|
+
})
|
|
2756
|
+
}
|
|
2571
2757
|
const 文 = await r.text()
|
|
2572
2758
|
if (!r.ok) {
|
|
2573
2759
|
记一笔('生图失败 HTTP ' + r.status)
|
package/lib/memory.mjs
CHANGED
|
@@ -78,6 +78,56 @@ export function 收日记(夹) {
|
|
|
78
78
|
return 出
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
function 文本文件们(来源) {
|
|
82
|
+
const 路 = String(来源 || '').trim()
|
|
83
|
+
if (!路) return []
|
|
84
|
+
try {
|
|
85
|
+
const stat = fs.statSync(路)
|
|
86
|
+
if (stat.isFile()) return [路]
|
|
87
|
+
if (!stat.isDirectory()) return []
|
|
88
|
+
return fs.readdirSync(路, { withFileTypes: true })
|
|
89
|
+
.filter((entry) => entry.isFile() && /\.(?:md|txt)$/i.test(entry.name))
|
|
90
|
+
.map((entry) => path.join(路, entry.name))
|
|
91
|
+
.sort()
|
|
92
|
+
} catch (error) { return [] }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function 文本日期(路, stat) {
|
|
96
|
+
const 名 = path.basename(路)
|
|
97
|
+
const 命中 = /(\d{4}-\d{2}-\d{2})/.exec(名)
|
|
98
|
+
if (命中) return 命中[1]
|
|
99
|
+
return stat?.mtime ? new Date(stat.mtime).toISOString().slice(0, 10) : ''
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 纯文本适配器:允许把一整个 md/txt 文件夹接进回忆簿。 */
|
|
103
|
+
export function 收文本(来源, kind = 'fact') {
|
|
104
|
+
const 出 = []
|
|
105
|
+
for (const 路 of 文本文件们(来源)) {
|
|
106
|
+
let 文 = ''
|
|
107
|
+
let stat = null
|
|
108
|
+
try { 文 = fs.readFileSync(路, 'utf8'); stat = fs.statSync(路) } catch (error) { continue }
|
|
109
|
+
const 日期 = 文本日期(路, stat)
|
|
110
|
+
const 名 = path.basename(路, path.extname(路))
|
|
111
|
+
const 块 = kind === 'daily'
|
|
112
|
+
? [文.trim()]
|
|
113
|
+
: 文.split(/\n\s*\n/).map((part) => part.trim()).filter(Boolean)
|
|
114
|
+
块.forEach((正文, index) => {
|
|
115
|
+
if (!正文) return
|
|
116
|
+
const id = `text:${kind}:${路}:${index}`
|
|
117
|
+
出.push({
|
|
118
|
+
id,
|
|
119
|
+
at: 日期 ? 日期 + 'T23:59:59' : '',
|
|
120
|
+
kind,
|
|
121
|
+
title: kind === 'daily' ? (日期 || 名) : (名 || '文本记录'),
|
|
122
|
+
text: 正文,
|
|
123
|
+
source: '文本文件',
|
|
124
|
+
tags: [],
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
return 出
|
|
129
|
+
}
|
|
130
|
+
|
|
81
131
|
/** 记忆卡:## 章名 下面是条目,一行一条 */
|
|
82
132
|
export function 收记忆卡(路) {
|
|
83
133
|
const p = String(路 || '').trim()
|
|
@@ -116,11 +166,15 @@ function 会话档案(家目录, 会话, 配置) {
|
|
|
116
166
|
return String(配置.绑定?.['session-' + bare] || 配置.绑定?.[bare] || path.join(家目录, 'xingxi', '会话', 'session-' + bare)).trim()
|
|
117
167
|
}
|
|
118
168
|
|
|
119
|
-
export function 收天数(家目录, 会话,
|
|
169
|
+
export function 收天数(家目录, 会话, 星汐, 来源 = {}) {
|
|
120
170
|
const 配置 = 星汐 || 读星汐(家目录)
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
171
|
+
const 自定义 = 收文本(来源.日记路径, 'daily')
|
|
172
|
+
const 最早 = [...收日记(会话档案(家目录, 会话, 配置)), ...自定义]
|
|
173
|
+
.filter((item) => /^\d{4}-\d{2}-\d{2}$/.test(String(item.title || '')))
|
|
174
|
+
.sort((a, b) => String(a.title).localeCompare(String(b.title)))[0]
|
|
175
|
+
const 起始 = 最早?.title || String(来源.相伴起始日 || '').trim()
|
|
176
|
+
if (!起始) return { since: '', days: 0 }
|
|
177
|
+
const since = 起始
|
|
124
178
|
const today = new Intl.DateTimeFormat('sv-SE', { timeZone: 'Asia/Shanghai' }).format(new Date())
|
|
125
179
|
const days = Math.floor((Date.parse(today + 'T00:00:00Z') - Date.parse(since + 'T00:00:00Z')) / 86400000) + 1
|
|
126
180
|
return { since, days: Math.max(1, days) }
|
|
@@ -132,13 +186,15 @@ export function 收天数(家目录, 会话, 星汐) {
|
|
|
132
186
|
* @param {string} 会话 绑定的会话 id(session-…)
|
|
133
187
|
* @param {object} 星汐 读星汐() 的结果
|
|
134
188
|
*/
|
|
135
|
-
export function 收回忆(家目录, 会话,
|
|
189
|
+
export function 收回忆(家目录, 会话, 星汐, 来源 = {}) {
|
|
136
190
|
const 配置 = 星汐 || 读星汐(家目录)
|
|
137
191
|
const 日记夹 = 会话档案(家目录, 会话, 配置)
|
|
138
192
|
// ⚠ 记忆卡(成长)已经不要了 —— 一行一句像流水账,面板上那个按钮也删了。
|
|
139
193
|
return [
|
|
140
194
|
...读鱼的记忆(家目录, 会话),
|
|
141
195
|
...收日记(日记夹),
|
|
196
|
+
...收文本(来源.记忆路径, 'fact'),
|
|
197
|
+
...收文本(来源.日记路径, 'daily'),
|
|
142
198
|
]
|
|
143
199
|
}
|
|
144
200
|
|