dsh-plugin-cyrene-live2d 0.2.9 → 0.3.0
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/README.md +8 -2
- package/assets/default-prefs.json +8 -8
- package/assets/icon.svg +89 -89
- package/assets/locale/notes/en.json +6 -6
- package/assets/locale/notes/zh-CN.json +6 -6
- package/assets/locale/reminder/en.json +6 -6
- package/assets/locale/reminder/zh-CN.json +6 -6
- package/assets/model/Cyrene.model3.json +441 -441
- package/assets/model/bongo-standard/Live2d_expression0.exp3.json +9 -9
- package/assets/model/bongo-standard/cat.cdi3.json +296 -296
- package/assets/model/bongo-standard/cat.model3.json +33 -33
- package/assets/model/bongo-standard/cat.physics3.json +232 -232
- package/assets/model/expressions/0.exp3.json +24 -24
- package/assets/model/expressions/1.exp3.json +11 -11
- package/assets/model/expressions/10.exp3.json +9 -9
- package/assets/model/expressions/11.exp3.json +9 -9
- package/assets/model/expressions/2.exp3.json +9 -9
- package/assets/model/expressions/3.exp3.json +9 -9
- package/assets/model/expressions/4.exp3.json +11 -11
- package/assets/model/expressions/5.exp3.json +11 -11
- package/assets/model/expressions/6.exp3.json +11 -11
- package/assets/model/expressions/7.exp3.json +11 -11
- package/assets/model/expressions/8.exp3.json +11 -11
- package/assets/model/expressions/9.exp3.json +9 -9
- package/assets/model/model.physics3.json +641 -641
- package/assets/model/motions/Tick3_3.motion3.json +1347 -1347
- package/assets/model/motions//345/212/250/344/275/2346_0.motion3.json +699 -699
- package/assets/model/motions//345/212/250/344/275/2346_1.motion3.json +1241 -1241
- package/assets/model/motions//345/212/250/344/275/2346_2.motion3.json +1117 -1117
- package/assets/model/motions//345/212/250/344/275/2346_3.motion3.json +1106 -1106
- package/assets/model/we-q/expressions/FileReferences_Expressions_0_File_0.exp3.json +19 -19
- package/assets/model/we-q/expressions/FileReferences_Expressions_1_File_0.exp3.json +41 -41
- package/assets/model/we-q/expressions/FileReferences_Expressions_2_File_0.exp3.json +104 -104
- package/assets/model/we-q/model0.model3.json +245 -245
- package/assets/model/we-q/motions/FileReferences_Motions_shake#1_0_File_0.motion3.json +520 -520
- package/assets/model/we-q/motions/FileReferences_Motions_talk#1_0_File_0.motion3.json +499 -499
- package/assets/model/we-q/motions/FileReferences_Motions_talk#1_1_File_0.motion3.json +453 -453
- package/assets/model/we-q/motions/FileReferences_Motions_wink#1_0_File_0.motion3.json +478 -478
- package/assets/model/we-q/motions/FileReferences_Motions_/346/212/254/346/211/213_0_File_0.motion3.json +450 -450
- package/assets/model/we-q/motions/FileReferences_Motions_/346/212/254/346/211/213_1_File_0.motion3.json +450 -450
- package/assets/model/we-q/motions/idle/FileReferences_Motions_Idleidle_0_File_0.motion3.json +422 -422
- package/assets/model/we-q/physics/FileReferences_Physics_0.physic3.json +236 -236
- package/assets/runtime/live2dcubismcore.min.js +8 -8
- package/assets/stickers.json +84 -84
- package/assets/vendor/cubism4.min.js +1 -1
- package/assets/vendor/pixi.min.js +9 -9
- package/assets/vendor/theme-cyrene-factory.js +4314 -4314
- package/assets/vendor/theme-cyrene.js +4317 -4317
- package/assets/voice/angry-00.opus +0 -0
- package/assets/voice/angry-02.opus +0 -0
- package/assets/voice/approval-00.opus +0 -0
- package/assets/voice/approval-01.opus +0 -0
- package/assets/voice/approval-02.opus +0 -0
- package/assets/voice/askAck-00.opus +0 -0
- package/assets/voice/away-01.opus +0 -0
- package/assets/voice/away-02.opus +0 -0
- package/assets/voice/away-03.opus +0 -0
- package/assets/voice/away-05.opus +0 -0
- package/assets/voice/back-00.opus +0 -0
- package/assets/voice/back-01.opus +0 -0
- package/assets/voice/backLong-05.opus +0 -0
- package/assets/voice/backShort-03.opus +0 -0
- package/assets/voice/backShort-04.opus +0 -0
- package/assets/voice/backShort-07.opus +0 -0
- package/assets/voice/backVeryLong-01.opus +0 -0
- package/assets/voice/backVeryLong-02.opus +0 -0
- package/assets/voice/backVeryLong-03.opus +0 -0
- package/assets/voice/backVeryLong-04.opus +0 -0
- package/assets/voice/backVeryLong-05.opus +0 -0
- package/assets/voice/backVeryLong-07.opus +0 -0
- package/assets/voice/backVeryLong-08.opus +0 -0
- package/assets/voice/balLow-00.opus +0 -0
- package/assets/voice/balLow-01.opus +0 -0
- package/assets/voice/birthday-02.opus +0 -0
- package/assets/voice/click-00.opus +0 -0
- package/assets/voice/click-01.opus +0 -0
- package/assets/voice/click-07.opus +0 -0
- package/assets/voice/click-10.opus +0 -0
- package/assets/voice/click-11.opus +0 -0
- package/assets/voice/click-12.opus +0 -0
- package/assets/voice/click-16.opus +0 -0
- package/assets/voice/click-17.opus +0 -0
- package/assets/voice/click-18.opus +0 -0
- package/assets/voice/comfort-03.opus +0 -0
- package/assets/voice/comfort-04.opus +0 -0
- package/assets/voice/cost10-00.opus +0 -0
- package/assets/voice/cost2-00.opus +0 -0
- package/assets/voice/cost5-00.opus +0 -0
- package/assets/voice/costTurn-01.opus +0 -0
- package/assets/voice/costTurn-02.opus +0 -0
- package/assets/voice/ctxFull-01.opus +0 -0
- package/assets/voice/ctxHigh-00.opus +0 -0
- package/assets/voice/dawn-01.opus +0 -0
- package/assets/voice/dawn-04.opus +0 -0
- package/assets/voice/dawn-06.opus +0 -0
- package/assets/voice/dawn-07.opus +0 -0
- package/assets/voice/deepWake-03.opus +0 -0
- package/assets/voice/deepWake-04.opus +0 -0
- package/assets/voice/deepWake-06.opus +0 -0
- package/assets/voice/deepWake-07.opus +0 -0
- package/assets/voice/done-05.opus +0 -0
- package/assets/voice/done-08.opus +0 -0
- package/assets/voice/done-09.opus +0 -0
- package/assets/voice/done-11.opus +0 -0
- package/assets/voice/empty-00.opus +0 -0
- package/assets/voice/encourage-02.opus +0 -0
- package/assets/voice/failed-01.opus +0 -0
- package/assets/voice/failed-05.opus +0 -0
- package/assets/voice/failkind-auth-01.opus +0 -0
- package/assets/voice/failkind-auth-02.opus +0 -0
- package/assets/voice/failkind-ctx-00.opus +0 -0
- package/assets/voice/failkind-missing-01.opus +0 -0
- package/assets/voice/focusEnd-02.opus +0 -0
- package/assets/voice/focusEnd-04.opus +0 -0
- package/assets/voice/forgive-00.opus +0 -0
- package/assets/voice/hello-00.opus +0 -0
- package/assets/voice/hello-03.opus +0 -0
- package/assets/voice/hold-00.opus +0 -0
- package/assets/voice/idleTap-00.opus +0 -0
- package/assets/voice/idleTapLong-02.opus +0 -0
- package/assets/voice/lateNight-00.opus +0 -0
- package/assets/voice/lateNight-02.opus +0 -0
- package/assets/voice/lateNight-03.opus +0 -0
- package/assets/voice/lateNight-06.opus +0 -0
- package/assets/voice/lateNight-07.opus +0 -0
- package/assets/voice/murmur-04.opus +0 -0
- package/assets/voice/night-01.opus +0 -0
- package/assets/voice/night-03.opus +0 -0
- package/assets/voice/night-05.opus +0 -0
- package/assets/voice/noon-04.opus +0 -0
- package/assets/voice/petArm-02.opus +0 -0
- package/assets/voice/petCheek-00.opus +0 -0
- package/assets/voice/petCheek-01.opus +0 -0
- package/assets/voice/petCheek-02.opus +0 -0
- package/assets/voice/petHead-01.opus +0 -0
- package/assets/voice/petHead-03.opus +0 -0
- package/assets/voice/petHead-04.opus +0 -0
- package/assets/voice/praised-01.opus +0 -0
- package/assets/voice/praised-03.opus +0 -0
- package/assets/voice/question-00.opus +0 -0
- package/assets/voice/question-03.opus +0 -0
- package/assets/voice/question-04.opus +0 -0
- package/assets/voice/question-06.opus +0 -0
- package/assets/voice/shy-00.opus +0 -0
- package/assets/voice/spot-0-0.opus +0 -0
- package/assets/voice/spot-0-1.opus +0 -0
- package/assets/voice/spot-0-2.opus +0 -0
- package/assets/voice/spot-3-0.opus +0 -0
- package/assets/voice/spot-4-0.opus +0 -0
- package/assets/voice/spot-4-2.opus +0 -0
- package/assets/voice/spot-5-2.opus +0 -0
- package/assets/voice/spot-6-0.opus +0 -0
- package/assets/voice/spot-6-1.opus +0 -0
- package/assets/voice/spot-7-0.opus +0 -0
- package/assets/voice/spot-7-2.opus +0 -0
- package/assets/voice/spot-8-1.opus +0 -0
- package/assets/voice/tagent-00.opus +0 -0
- package/assets/voice/thinkFast-01.opus +0 -0
- package/assets/voice/thinkFast-02.opus +0 -0
- package/assets/voice/thinkFast-03.opus +0 -0
- package/assets/voice/thinkSlow-01.opus +0 -0
- package/assets/voice/thinkSlow-03.opus +0 -0
- package/assets/voice/thinking-01.opus +0 -0
- package/assets/voice/thinking-02.opus +0 -0
- package/assets/voice/thinking-03.opus +0 -0
- package/assets/voice/thinking-09.opus +0 -0
- package/assets/voice/tread-00.opus +0 -0
- package/assets/voice/tread-01.opus +0 -0
- package/assets/voice/trun-02.opus +0 -0
- package/assets/voice/tsun-00.opus +0 -0
- package/assets/voice/tsun-01.opus +0 -0
- package/assets/voice/tsun-04.opus +0 -0
- package/assets/voice/twrite-00.opus +0 -0
- package/assets/voice/unknown-01.opus +0 -0
- package/assets/voice/waitApproval-00.opus +0 -0
- package/assets/voice/waitApproval-01.opus +0 -0
- package/assets/voice/waitApproval-02.opus +0 -0
- package/assets/voice/waitApproval-03.opus +0 -0
- package/assets/voice/waitApprovalLate-02.opus +0 -0
- package/assets/voice/waitApprovalLate-03.opus +0 -0
- package/assets/voice/waitAsk-00.opus +0 -0
- package/assets/voice/waitAsk-02.opus +0 -0
- package/assets/voice/waitAskLate-03.opus +0 -0
- package/assets/voice/wake-03.opus +0 -0
- package/assets/voice/wake-04.opus +0 -0
- package/assets/voice/wake-05.opus +0 -0
- package/assets/voice/wake-06.opus +0 -0
- package/lib/client.js +7 -7
- package/lib/features/notes.js +172 -172
- package/lib/features/reminder.js +216 -216
- package/lib/l2d-plan.js +295 -295
- package/lib/l2d-tools.js +293 -293
- package/lib/ledger.js +163 -163
- package/lib/mys/config.js +183 -183
- package/lib/mys/ds.js +209 -209
- package/lib/mys/http.js +85 -85
- package/lib/mys/mys.js +419 -419
- package/lib/mys/qr.js +434 -434
- package/lib/mys/scheduler.js +206 -206
- package/lib/mys/store.js +248 -248
- package/lib/mys/tz.js +174 -174
- package/lib/wavtrim.js +245 -245
- package/lib/worldbook/NOTICE.md +18 -18
- package/lib/worldbook/data/Cyrene.md +111 -111
- package/lib/worldbook/data/_glossary.md +181 -181
- package/lib/worldbook/data/characters.md +289 -289
- package/lib/worldbook/data/story.md +130 -130
- package/lib/worldbook/data/world.md +182 -182
- package/lib/worldbook.js +189 -189
- package/package.json +72 -69
package/lib/worldbook.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 世界书 · 翁法罗斯设定注入
|
|
3
|
-
*
|
|
4
|
-
* 数据来自 Cyrene-Agent(MIT,Copyright (c) 2026 Playa),经由
|
|
5
|
-
* https://github.com/Cyrene-xl/DSH-Cyrene 的 worldbook/data 转手,
|
|
6
|
-
* 条目格式(`- 触发词:` / `- 常驻:` / `- 优先级:`)沿用上游定义。
|
|
7
|
-
* 详见同目录 worldbook/data 上层的 NOTICE。
|
|
8
|
-
*
|
|
9
|
-
* 这里只做三件事:解析 md、按关键词挑条目、拼成一段注入文本。
|
|
10
|
-
* 不碰任何 DSH API —— 注入时机在 index.js 里,保持这一层可以单独测。
|
|
11
|
-
*/
|
|
12
|
-
import fs from 'node:fs'
|
|
13
|
-
import path from 'node:path'
|
|
14
|
-
import { fileURLToPath } from 'node:url'
|
|
15
|
-
|
|
16
|
-
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
17
|
-
const DATA_DIR = path.join(HERE, 'worldbook', 'data')
|
|
18
|
-
|
|
19
|
-
/** 常驻块(每轮都注入)与命中块(按关键词)各自的字数上限,超了就按优先级截断。 */
|
|
20
|
-
const ALWAYS_MAX = 1800
|
|
21
|
-
const HIT_MAX = 3000
|
|
22
|
-
/** 参与匹配的最近对话文本上限,防止把整段历史当关键词池。 */
|
|
23
|
-
const HAY_MAX = 1500
|
|
24
|
-
|
|
25
|
-
const META = /^[-*]\s*(触发词|常驻|内在价值|优先级|连带触发词)\s*[::]\s*(.*)$/
|
|
26
|
-
|
|
27
|
-
/** 拆关键词:英文逗号、中文逗号、顿号都算分隔符。 */
|
|
28
|
-
function splitKeywords(s) {
|
|
29
|
-
return String(s || '')
|
|
30
|
-
.split(/[,,、]/)
|
|
31
|
-
.map((x) => x.trim())
|
|
32
|
-
.filter((x) => x !== '' && x !== '无')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 解析一份世界书 md。
|
|
37
|
-
* 约定:`## 标题` 起一条;紧随其前的元数据行进字段,其余行进正文;
|
|
38
|
-
* 单独的 `---` 只是分隔线,不进正文。
|
|
39
|
-
*/
|
|
40
|
-
export function parseEntries(text, file = '') {
|
|
41
|
-
const out = []
|
|
42
|
-
let cur = null
|
|
43
|
-
const flush = () => {
|
|
44
|
-
if (cur && cur.body.join('').trim() !== '') out.push(cur)
|
|
45
|
-
cur = null
|
|
46
|
-
}
|
|
47
|
-
for (const raw of String(text).replace(/\r\n/g, '\n').split('\n')) {
|
|
48
|
-
if (/^##\s+/.test(raw)) {
|
|
49
|
-
flush()
|
|
50
|
-
cur = {
|
|
51
|
-
title: raw.replace(/^##\s+/, '').trim(),
|
|
52
|
-
keywords: [],
|
|
53
|
-
always: false,
|
|
54
|
-
priority: 0,
|
|
55
|
-
value: 0,
|
|
56
|
-
chain: [],
|
|
57
|
-
body: [],
|
|
58
|
-
file,
|
|
59
|
-
}
|
|
60
|
-
continue
|
|
61
|
-
}
|
|
62
|
-
if (cur === null) continue
|
|
63
|
-
if (/^-{3,}\s*$/.test(raw)) continue
|
|
64
|
-
const m = META.exec(raw)
|
|
65
|
-
if (m) {
|
|
66
|
-
const key = m[1]
|
|
67
|
-
const val = m[2].trim()
|
|
68
|
-
if (key === '触发词') cur.keywords = splitKeywords(val)
|
|
69
|
-
else if (key === '常驻') cur.always = val === '是' || val === 'true' || val === 'yes'
|
|
70
|
-
else if (key === '内在价值') cur.value = Number(val) || 0
|
|
71
|
-
else if (key === '优先级') cur.priority = Number(val) || 0
|
|
72
|
-
else if (key === '连带触发词') cur.chain = splitKeywords(val)
|
|
73
|
-
continue
|
|
74
|
-
}
|
|
75
|
-
cur.body.push(raw)
|
|
76
|
-
}
|
|
77
|
-
flush()
|
|
78
|
-
return out
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** 把整个 data 目录读成条目表。读不到就返回空数组 —— 世界书是可选增强,不该拖垮插件。 */
|
|
82
|
-
export function loadWorldbook(dir = DATA_DIR) {
|
|
83
|
-
const all = []
|
|
84
|
-
let files = []
|
|
85
|
-
try {
|
|
86
|
-
files = fs.readdirSync(dir).filter((f) => f.toLowerCase().endsWith('.md'))
|
|
87
|
-
} catch {
|
|
88
|
-
return { entries: [], files: [] }
|
|
89
|
-
}
|
|
90
|
-
// _glossary 排前面:称谓类条目优先级最高,截断时不该被后读的文件挤掉。
|
|
91
|
-
files.sort((a, b) => {
|
|
92
|
-
const ga = a.startsWith('_') ? 0 : 1
|
|
93
|
-
const gb = b.startsWith('_') ? 0 : 1
|
|
94
|
-
return ga - gb || a.localeCompare(b)
|
|
95
|
-
})
|
|
96
|
-
for (const f of files) {
|
|
97
|
-
try {
|
|
98
|
-
const text = fs.readFileSync(path.join(dir, f), 'utf8')
|
|
99
|
-
for (const e of parseEntries(text, f)) all.push(e)
|
|
100
|
-
} catch {
|
|
101
|
-
// 单份文件坏掉不影响其他
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return { entries: all, files }
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* 数据目录的指纹(文件名 + 大小 + mtime)。
|
|
109
|
-
* 用来判断「条目是不是被改过」—— 改了就重读,不必重启 DSH。
|
|
110
|
-
*/
|
|
111
|
-
export function dataStamp(dir = DATA_DIR) {
|
|
112
|
-
try {
|
|
113
|
-
const files = fs
|
|
114
|
-
.readdirSync(dir)
|
|
115
|
-
.filter((f) => f.toLowerCase().endsWith('.md'))
|
|
116
|
-
.sort()
|
|
117
|
-
let out = ''
|
|
118
|
-
for (const f of files) {
|
|
119
|
-
const st = fs.statSync(path.join(dir, f))
|
|
120
|
-
out += `${f}:${st.size}:${Math.floor(st.mtimeMs)};`
|
|
121
|
-
}
|
|
122
|
-
return out
|
|
123
|
-
} catch {
|
|
124
|
-
return ''
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 挑条目并渲染。
|
|
130
|
-
* @param {object[]} entries loadWorldbook().entries
|
|
131
|
-
* @param {string} haystack 最近的对话文本(用户 + 助手都算,命中更稳)
|
|
132
|
-
*/
|
|
133
|
-
export function renderSection(entries, haystack) {
|
|
134
|
-
if (!Array.isArray(entries) || entries.length === 0) return ''
|
|
135
|
-
const hay = String(haystack || '').slice(-HAY_MAX).toLowerCase()
|
|
136
|
-
|
|
137
|
-
const always = []
|
|
138
|
-
const hits = []
|
|
139
|
-
for (const e of entries) {
|
|
140
|
-
if (e.always) {
|
|
141
|
-
always.push(e)
|
|
142
|
-
continue
|
|
143
|
-
}
|
|
144
|
-
if (hay === '') continue
|
|
145
|
-
const kws = e.keywords.concat(e.chain)
|
|
146
|
-
for (const k of kws) {
|
|
147
|
-
if (k !== '' && hay.includes(k.toLowerCase())) {
|
|
148
|
-
hits.push(e)
|
|
149
|
-
break
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// 同一条目可能被多个文件重复定义,按标题去重。
|
|
155
|
-
const seen = new Set()
|
|
156
|
-
const uniq = (arr) =>
|
|
157
|
-
arr
|
|
158
|
-
.filter((e) => {
|
|
159
|
-
const key = e.title
|
|
160
|
-
if (seen.has(key)) return false
|
|
161
|
-
seen.add(key)
|
|
162
|
-
return true
|
|
163
|
-
})
|
|
164
|
-
.sort((a, b) => b.priority - a.priority || b.value - a.value)
|
|
165
|
-
|
|
166
|
-
const picked = []
|
|
167
|
-
let used = 0
|
|
168
|
-
const take = (arr, cap) => {
|
|
169
|
-
for (const e of arr) {
|
|
170
|
-
const block = `## ${e.title}\n${e.body.join('\n').trim()}`
|
|
171
|
-
if (used + block.length > cap) continue
|
|
172
|
-
used += block.length + 2
|
|
173
|
-
picked.push(block)
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
take(uniq(always), ALWAYS_MAX)
|
|
177
|
-
take(uniq(hits), ALWAYS_MAX + HIT_MAX)
|
|
178
|
-
|
|
179
|
-
if (picked.length === 0) return ''
|
|
180
|
-
|
|
181
|
-
const head = [
|
|
182
|
-
'【翁法罗斯设定 · 世界书】',
|
|
183
|
-
'以下是与当前对话相关的设定条目,供你回答时依据。用你自己的话说出来,',
|
|
184
|
-
'不要整段照抄,也不要提「世界书」「条目」「资料」这些词;',
|
|
185
|
-
'没有条目覆盖的内容,仍然按「不确定就说不确定」处理,不要现编。',
|
|
186
|
-
'',
|
|
187
|
-
].join('\n')
|
|
188
|
-
return head + picked.join('\n\n')
|
|
189
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 世界书 · 翁法罗斯设定注入
|
|
3
|
+
*
|
|
4
|
+
* 数据来自 Cyrene-Agent(MIT,Copyright (c) 2026 Playa),经由
|
|
5
|
+
* https://github.com/Cyrene-xl/DSH-Cyrene 的 worldbook/data 转手,
|
|
6
|
+
* 条目格式(`- 触发词:` / `- 常驻:` / `- 优先级:`)沿用上游定义。
|
|
7
|
+
* 详见同目录 worldbook/data 上层的 NOTICE。
|
|
8
|
+
*
|
|
9
|
+
* 这里只做三件事:解析 md、按关键词挑条目、拼成一段注入文本。
|
|
10
|
+
* 不碰任何 DSH API —— 注入时机在 index.js 里,保持这一层可以单独测。
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
import { fileURLToPath } from 'node:url'
|
|
15
|
+
|
|
16
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
17
|
+
const DATA_DIR = path.join(HERE, 'worldbook', 'data')
|
|
18
|
+
|
|
19
|
+
/** 常驻块(每轮都注入)与命中块(按关键词)各自的字数上限,超了就按优先级截断。 */
|
|
20
|
+
const ALWAYS_MAX = 1800
|
|
21
|
+
const HIT_MAX = 3000
|
|
22
|
+
/** 参与匹配的最近对话文本上限,防止把整段历史当关键词池。 */
|
|
23
|
+
const HAY_MAX = 1500
|
|
24
|
+
|
|
25
|
+
const META = /^[-*]\s*(触发词|常驻|内在价值|优先级|连带触发词)\s*[::]\s*(.*)$/
|
|
26
|
+
|
|
27
|
+
/** 拆关键词:英文逗号、中文逗号、顿号都算分隔符。 */
|
|
28
|
+
function splitKeywords(s) {
|
|
29
|
+
return String(s || '')
|
|
30
|
+
.split(/[,,、]/)
|
|
31
|
+
.map((x) => x.trim())
|
|
32
|
+
.filter((x) => x !== '' && x !== '无')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 解析一份世界书 md。
|
|
37
|
+
* 约定:`## 标题` 起一条;紧随其前的元数据行进字段,其余行进正文;
|
|
38
|
+
* 单独的 `---` 只是分隔线,不进正文。
|
|
39
|
+
*/
|
|
40
|
+
export function parseEntries(text, file = '') {
|
|
41
|
+
const out = []
|
|
42
|
+
let cur = null
|
|
43
|
+
const flush = () => {
|
|
44
|
+
if (cur && cur.body.join('').trim() !== '') out.push(cur)
|
|
45
|
+
cur = null
|
|
46
|
+
}
|
|
47
|
+
for (const raw of String(text).replace(/\r\n/g, '\n').split('\n')) {
|
|
48
|
+
if (/^##\s+/.test(raw)) {
|
|
49
|
+
flush()
|
|
50
|
+
cur = {
|
|
51
|
+
title: raw.replace(/^##\s+/, '').trim(),
|
|
52
|
+
keywords: [],
|
|
53
|
+
always: false,
|
|
54
|
+
priority: 0,
|
|
55
|
+
value: 0,
|
|
56
|
+
chain: [],
|
|
57
|
+
body: [],
|
|
58
|
+
file,
|
|
59
|
+
}
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
if (cur === null) continue
|
|
63
|
+
if (/^-{3,}\s*$/.test(raw)) continue
|
|
64
|
+
const m = META.exec(raw)
|
|
65
|
+
if (m) {
|
|
66
|
+
const key = m[1]
|
|
67
|
+
const val = m[2].trim()
|
|
68
|
+
if (key === '触发词') cur.keywords = splitKeywords(val)
|
|
69
|
+
else if (key === '常驻') cur.always = val === '是' || val === 'true' || val === 'yes'
|
|
70
|
+
else if (key === '内在价值') cur.value = Number(val) || 0
|
|
71
|
+
else if (key === '优先级') cur.priority = Number(val) || 0
|
|
72
|
+
else if (key === '连带触发词') cur.chain = splitKeywords(val)
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
cur.body.push(raw)
|
|
76
|
+
}
|
|
77
|
+
flush()
|
|
78
|
+
return out
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 把整个 data 目录读成条目表。读不到就返回空数组 —— 世界书是可选增强,不该拖垮插件。 */
|
|
82
|
+
export function loadWorldbook(dir = DATA_DIR) {
|
|
83
|
+
const all = []
|
|
84
|
+
let files = []
|
|
85
|
+
try {
|
|
86
|
+
files = fs.readdirSync(dir).filter((f) => f.toLowerCase().endsWith('.md'))
|
|
87
|
+
} catch {
|
|
88
|
+
return { entries: [], files: [] }
|
|
89
|
+
}
|
|
90
|
+
// _glossary 排前面:称谓类条目优先级最高,截断时不该被后读的文件挤掉。
|
|
91
|
+
files.sort((a, b) => {
|
|
92
|
+
const ga = a.startsWith('_') ? 0 : 1
|
|
93
|
+
const gb = b.startsWith('_') ? 0 : 1
|
|
94
|
+
return ga - gb || a.localeCompare(b)
|
|
95
|
+
})
|
|
96
|
+
for (const f of files) {
|
|
97
|
+
try {
|
|
98
|
+
const text = fs.readFileSync(path.join(dir, f), 'utf8')
|
|
99
|
+
for (const e of parseEntries(text, f)) all.push(e)
|
|
100
|
+
} catch {
|
|
101
|
+
// 单份文件坏掉不影响其他
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { entries: all, files }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 数据目录的指纹(文件名 + 大小 + mtime)。
|
|
109
|
+
* 用来判断「条目是不是被改过」—— 改了就重读,不必重启 DSH。
|
|
110
|
+
*/
|
|
111
|
+
export function dataStamp(dir = DATA_DIR) {
|
|
112
|
+
try {
|
|
113
|
+
const files = fs
|
|
114
|
+
.readdirSync(dir)
|
|
115
|
+
.filter((f) => f.toLowerCase().endsWith('.md'))
|
|
116
|
+
.sort()
|
|
117
|
+
let out = ''
|
|
118
|
+
for (const f of files) {
|
|
119
|
+
const st = fs.statSync(path.join(dir, f))
|
|
120
|
+
out += `${f}:${st.size}:${Math.floor(st.mtimeMs)};`
|
|
121
|
+
}
|
|
122
|
+
return out
|
|
123
|
+
} catch {
|
|
124
|
+
return ''
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 挑条目并渲染。
|
|
130
|
+
* @param {object[]} entries loadWorldbook().entries
|
|
131
|
+
* @param {string} haystack 最近的对话文本(用户 + 助手都算,命中更稳)
|
|
132
|
+
*/
|
|
133
|
+
export function renderSection(entries, haystack) {
|
|
134
|
+
if (!Array.isArray(entries) || entries.length === 0) return ''
|
|
135
|
+
const hay = String(haystack || '').slice(-HAY_MAX).toLowerCase()
|
|
136
|
+
|
|
137
|
+
const always = []
|
|
138
|
+
const hits = []
|
|
139
|
+
for (const e of entries) {
|
|
140
|
+
if (e.always) {
|
|
141
|
+
always.push(e)
|
|
142
|
+
continue
|
|
143
|
+
}
|
|
144
|
+
if (hay === '') continue
|
|
145
|
+
const kws = e.keywords.concat(e.chain)
|
|
146
|
+
for (const k of kws) {
|
|
147
|
+
if (k !== '' && hay.includes(k.toLowerCase())) {
|
|
148
|
+
hits.push(e)
|
|
149
|
+
break
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 同一条目可能被多个文件重复定义,按标题去重。
|
|
155
|
+
const seen = new Set()
|
|
156
|
+
const uniq = (arr) =>
|
|
157
|
+
arr
|
|
158
|
+
.filter((e) => {
|
|
159
|
+
const key = e.title
|
|
160
|
+
if (seen.has(key)) return false
|
|
161
|
+
seen.add(key)
|
|
162
|
+
return true
|
|
163
|
+
})
|
|
164
|
+
.sort((a, b) => b.priority - a.priority || b.value - a.value)
|
|
165
|
+
|
|
166
|
+
const picked = []
|
|
167
|
+
let used = 0
|
|
168
|
+
const take = (arr, cap) => {
|
|
169
|
+
for (const e of arr) {
|
|
170
|
+
const block = `## ${e.title}\n${e.body.join('\n').trim()}`
|
|
171
|
+
if (used + block.length > cap) continue
|
|
172
|
+
used += block.length + 2
|
|
173
|
+
picked.push(block)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
take(uniq(always), ALWAYS_MAX)
|
|
177
|
+
take(uniq(hits), ALWAYS_MAX + HIT_MAX)
|
|
178
|
+
|
|
179
|
+
if (picked.length === 0) return ''
|
|
180
|
+
|
|
181
|
+
const head = [
|
|
182
|
+
'【翁法罗斯设定 · 世界书】',
|
|
183
|
+
'以下是与当前对话相关的设定条目,供你回答时依据。用你自己的话说出来,',
|
|
184
|
+
'不要整段照抄,也不要提「世界书」「条目」「资料」这些词;',
|
|
185
|
+
'没有条目覆盖的内容,仍然按「不确定就说不确定」处理,不要现编。',
|
|
186
|
+
'',
|
|
187
|
+
].join('\n')
|
|
188
|
+
return head + picked.join('\n\n')
|
|
189
|
+
}
|
package/package.json
CHANGED
|
@@ -1,69 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-plugin-cyrene-live2d",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "在 DSH Web GUI 里挂一只昔涟(Live2D 桌宠 + 粉白主题 + 欢迎页立绘 + 定时提醒)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"icon": "assets/icon.webp",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": { "type": "git", "url": "git+https://github.com/chelly4/dsh-plugin-cyrene-live2d.git" },
|
|
10
|
+
"keywords": [
|
|
11
|
+
"dsh",
|
|
12
|
+
"dsh-plugin",
|
|
13
|
+
"deepseek-harness",
|
|
14
|
+
"desktop-pet",
|
|
15
|
+
"live2d",
|
|
16
|
+
"cyrene"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./lib/index.js",
|
|
20
|
+
"./client": "./lib/client.js",
|
|
21
|
+
"./icon": "./assets/icon.webp",
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
"./features/reminder": "./lib/features/reminder.js",
|
|
24
|
+
"./features/reminder/icon": "./assets/icon-reminder.webp",
|
|
25
|
+
"./features/notes": "./lib/features/notes.js",
|
|
26
|
+
"./features/notes/icon": "./assets/icon-notes.webp",
|
|
27
|
+
"./features/reminder/locale/en.json": "./assets/locale/reminder/en.json",
|
|
28
|
+
"./features/notes/locale/en.json": "./assets/locale/notes/en.json",
|
|
29
|
+
"./features/reminder/locale/zh-CN.json": "./assets/locale/reminder/zh-CN.json",
|
|
30
|
+
"./features/notes/locale/zh-CN.json": "./assets/locale/notes/zh-CN.json"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"lib",
|
|
34
|
+
"cordis.patch.yml",
|
|
35
|
+
"docs",
|
|
36
|
+
"assets"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": "\u003e=18",
|
|
40
|
+
"dsh": "\u003e=0.2.1-rc.1 \u003c0.3.0-0"
|
|
41
|
+
},
|
|
42
|
+
"dsh": {
|
|
43
|
+
"bundle": {
|
|
44
|
+
"patch": "./cordis.patch.yml"
|
|
45
|
+
},
|
|
46
|
+
"client": {
|
|
47
|
+
"inject": [
|
|
48
|
+
|
|
49
|
+
],
|
|
50
|
+
"platform": "web"
|
|
51
|
+
},
|
|
52
|
+
"catalog": {
|
|
53
|
+
"category": "ui",
|
|
54
|
+
"summary": {
|
|
55
|
+
"en": "A pink-white Cyrene theme for DeepSeek Harness: a Live2D desktop pet that blinks, follows the cursor and talks, plus a full-page skin, a crossfade wallpaper, a welcome-page illustration and scheduled reminders. Everything lives in the page; uninstalling it leaves the host untouched.",
|
|
56
|
+
"zh": "昔涟主题(粉白):一只会眨眼、跟着鼠标看、会说话的 Live2D 桌宠,外加整页皮肤、交叉淡入的背景图、欢迎页立绘与定时提醒。全部活在页面里,卸载后宿主一个文件都不动。"
|
|
57
|
+
},
|
|
58
|
+
"capabilities": [
|
|
59
|
+
"webserver",
|
|
60
|
+
"storage",
|
|
61
|
+
"child-process",
|
|
62
|
+
"network:127.0.0.1",
|
|
63
|
+
"network:api.deepseek.com",
|
|
64
|
+
"network:*.mihoyo.com",
|
|
65
|
+
"network:*.miyoushe.com"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"check:sync": "node tools/check-sync.mjs"
|
|
71
|
+
}
|
|
72
|
+
}
|