dsh-world 0.6.6 → 0.7.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 +39 -0
- package/CONTRIBUTING.md +163 -161
- package/NOTES.md +184 -152
- package/README.md +237 -227
- package/client/index.js +894 -738
- package/lib/archive.d.ts +3 -1
- package/lib/archive.js +6 -4
- package/lib/compaction.js +8 -0
- package/lib/compactionSwap.d.ts +29 -2
- package/lib/compactionSwap.js +62 -7
- package/lib/console/homeApply.d.ts +11 -2
- package/lib/console/homeApply.js +36 -7
- package/lib/console/routes.d.ts +13 -0
- package/lib/console/routes.js +43 -0
- package/lib/console/snapshot.d.ts +8 -0
- package/lib/console/snapshot.js +4 -2
- package/lib/ecosystem/bridge/route.d.ts +7 -0
- package/lib/ecosystem/bridge/route.js +30 -0
- package/lib/ecosystem/qq/route.d.ts +2 -1
- package/lib/ecosystem/qq/route.js +10 -2
- package/lib/ecosystem/qq-native/batch.d.ts +2 -0
- package/lib/ecosystem/qq-native/batch.js +3 -1
- package/lib/ecosystem/qq-native/index.d.ts +2 -0
- package/lib/ecosystem/qq-native/index.js +4 -0
- package/lib/ecosystem/qq-native/replies.d.ts +6 -1
- package/lib/ecosystem/qq-native/replies.js +19 -1
- package/lib/ecosystem/shared/context.d.ts +1 -1
- package/lib/ecosystem/shared/context.js +1 -1
- package/lib/ecosystem/shared/identity.d.ts +12 -0
- package/lib/ecosystem/shared/identity.js +17 -1
- package/lib/ecosystem/shared/turn.d.ts +8 -5
- package/lib/ecosystem/shared/turn.js +16 -17
- package/lib/ecosystem/wechat/archive.d.ts +2 -0
- package/lib/ecosystem/wechat/archive.js +3 -1
- package/lib/ecosystem/wechat/home.js +9 -4
- package/lib/ecosystem/wechat/messages.d.ts +11 -0
- package/lib/ecosystem/wechat/messages.js +9 -1
- package/lib/ecosystem/wechat/sending.js +36 -9
- package/lib/ecosystem/wechat/supervisor.d.ts +11 -2
- package/lib/ecosystem/wechat/supervisor.js +90 -9
- package/lib/history.d.ts +6 -4
- package/lib/history.js +61 -12
- package/lib/hostContract.d.ts +1 -0
- package/lib/index.js +41 -14
- package/lib/life/activity.d.ts +2 -0
- package/lib/life/activity.js +1 -1
- package/lib/life/alarm.d.ts +12 -4
- package/lib/life/alarm.js +21 -6
- package/lib/life/diary.d.ts +6 -0
- package/lib/life/diary.js +23 -2
- package/lib/life/runtime.d.ts +1 -0
- package/lib/life/runtime.js +57 -9
- package/lib/life/toolRegistry.d.ts +4 -3
- package/lib/life/toolRegistry.js +13 -3
- package/lib/life/types.d.ts +6 -1
- package/lib/memory.d.ts +57 -0
- package/lib/memory.js +207 -0
- package/lib/memoryFiles.d.ts +50 -0
- package/lib/memoryFiles.js +168 -0
- package/lib/memoryStore.d.ts +112 -0
- package/lib/memoryStore.js +159 -0
- package/lib/memoryTools.d.ts +31 -0
- package/lib/memoryTools.js +106 -0
- package/lib/promptSection.d.ts +2 -0
- package/lib/runtime.d.ts +1 -1
- package/lib/runtime.js +62 -75
- package/lib/sourceArchive.d.ts +1 -0
- package/lib/sourceArchive.js +4 -5
- package/lib/store.d.ts +15 -1
- package/lib/store.js +12 -2
- package/lib/types.d.ts +1 -4
- package/lib/worldPrompt.d.ts +6 -0
- package/lib/worldPrompt.js +8 -2
- package/lib/worldSwitch.d.ts +9 -1
- package/lib/worldSwitch.js +14 -1
- package/package.json +128 -117
- package/scripts/compact-home.mjs +29 -0
- package/scripts/update-world.mjs +6 -4
- package/src/ecosystem/wechat/windows/README.md +7 -5
- package/src/ecosystem/wechat/windows/adapter.py +86 -31
- package/src/ecosystem/wechat/windows/engine/NOTICE.md +1 -1
- package/src/ecosystem/wechat/windows/engine/bridge.cpp +9 -1
- package/src/ecosystem/wechat/windows/engine/build.ps1 +8 -2
- package/src/ecosystem/wechat/windows/engine/profiles.json +56 -0
- package/src/ecosystem/wechat/windows/native.py +4 -1
- package/src/ecosystem/wechat/windows/outgoing.py +21 -0
- package/src/ecosystem/wechat/windows/sender.py +26 -6
- package/templates/alarm.md +3 -4
- package/templates/world-prompt-memory.md +10 -0
- package/templates/world-prompt.md +7 -2
package/client/index.js
CHANGED
|
@@ -1,738 +1,894 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-world — 浏览器半侧:设置里的「世界控制台」。
|
|
3
|
-
* 模块 id 必须等于 bundle 行名 dsh-world;数据来自宿主半侧的 /dsh-world/console/* 路由。
|
|
4
|
-
* 读取是 GET;会改变东西的(开始、停止、人设、世界提示词、额度、记忆轮数)是带 x-dsh-world 头的 JSON POST。
|
|
5
|
-
*/
|
|
6
|
-
window.__ModuleLoader__.load({
|
|
7
|
-
id: 'dsh-world',
|
|
8
|
-
factory: (require) => {
|
|
9
|
-
var react = require('react')
|
|
10
|
-
var h = react.createElement
|
|
11
|
-
var useState = react.useState
|
|
12
|
-
var useEffect = react.useEffect
|
|
13
|
-
var useRef = react.useRef
|
|
14
|
-
|
|
15
|
-
function settle(r) {
|
|
16
|
-
return r.json().then(function (body) { return { body: body } }, function () { return null }).then(function (parsed) {
|
|
17
|
-
var body = parsed && parsed.body
|
|
18
|
-
if (!r.ok) { var err = new Error((body && body.error) || ('HTTP ' + r.status)); err.status = r.status; throw err }
|
|
19
|
-
if (!parsed) { var bad = new Error('回复不是 JSON'); bad.notJson = true; throw bad }
|
|
20
|
-
return body
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
function getFrom(base, path) { return fetch(base + path, { cache: 'no-store' }).then(settle) }
|
|
24
|
-
function postTo(base, path, body) {
|
|
25
|
-
return fetch(base + path, { method: 'POST', cache: 'no-store', headers: { 'content-type': 'application/json', 'x-dsh-world': '1' }, body: JSON.stringify(body || {}) }).then(settle)
|
|
26
|
-
}
|
|
27
|
-
function api(path) { return getFrom('/dsh-world/console/', path) }
|
|
28
|
-
function post(path, body) { return postTo('/dsh-world/console/', path, body) }
|
|
29
|
-
/** QQ 那几扇门在自己的前缀下(/dsh-world/qq/*),不和 console 混在一起。 */
|
|
30
|
-
function qqGet(path) { return getFrom('/dsh-world/qq/', path) }
|
|
31
|
-
function qqPost(path, body) { return postTo('/dsh-world/qq/', path, body) }
|
|
32
|
-
/** 保存没成时的那句话。 */
|
|
33
|
-
function failedTo(setMsg) { return function (e) { setMsg('保存失败:' + (e.message || e)) } }
|
|
34
|
-
/** 设置卡下面那行状态:没成(失败、请填…)标红,其余灰色。 */
|
|
35
|
-
function Status(props) { return props.msg ? h('div', { role: 'status', className: /失败|请填/.test(props.msg) ? 'dw-bad' : 'dw-muted' }, props.msg) : null }
|
|
36
|
-
/** 快照,或 null 表示控制台不在(404、不是 JSON 的页面、没有 life 字段的回复)。 */
|
|
37
|
-
function loadSnapshot() {
|
|
38
|
-
return api('snapshot').then(function (s) {
|
|
39
|
-
return s && typeof s === 'object' && typeof s.life === 'object' ? s : null
|
|
40
|
-
}, function (e) { if (e && (e.status === 404 || e.notJson)) return null; throw e })
|
|
41
|
-
}
|
|
42
|
-
function clock(iso, zone) {
|
|
43
|
-
try { return new Date(iso).toLocaleTimeString('zh-CN', { timeZone: zone, hourCycle: 'h23', hour: '2-digit', minute: '2-digit' }) } catch (e) { return String(iso) }
|
|
44
|
-
}
|
|
45
|
-
function local(iso, zone) {
|
|
46
|
-
if (!iso) return '—'
|
|
47
|
-
try { return new Date(iso).toLocaleString('zh-CN', { timeZone: zone, hourCycle: 'h23', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' }) } catch (e) { return iso }
|
|
48
|
-
}
|
|
49
|
-
function remaining(iso) {
|
|
50
|
-
var ms = Date.parse(iso) - Date.now()
|
|
51
|
-
if (!(ms > 0)) return '马上'
|
|
52
|
-
var m = Math.round(ms / 60000), d = Math.floor(m / 1440), hr = Math.floor(m % 1440 / 60), mi = m % 60
|
|
53
|
-
return (d ? d + ' 天 ' : '') + (hr ? hr + ' 小时 ' : '') + mi + ' 分'
|
|
54
|
-
}
|
|
55
|
-
function list(value) { return Array.isArray(value) ? value : [] }
|
|
56
|
-
var sourceLabel = { first: '新家', return: '回来', plan: '闹钟', fallback: '早上兜底', review: '回顾' }
|
|
57
|
-
var statusLabel = { running: '正在做事', idle: '空闲', cold: '休息中' }
|
|
58
|
-
|
|
59
|
-
var LAYERS = [
|
|
60
|
-
{ key: '名字', hint: '她叫什么。家的标题、记忆里她的署名都用它。', rows: 1 },
|
|
61
|
-
{ key: '她是谁', hint: '一句话:她是什么样的存在。', rows: 2 },
|
|
62
|
-
{ key: '性格', hint: '她的脾气、偏好和小习惯。', rows: 4 },
|
|
63
|
-
{ key: '说话方式', hint: '口吻、句子长短、会不会用表情。', rows: 3 },
|
|
64
|
-
{ key: '愿景', hint: '你希望她成为什么样子。', rows: 4 },
|
|
65
|
-
{ key: '补充', hint: '其他想让她知道的:底线、默契、约定。', rows: 3 },
|
|
66
|
-
]
|
|
67
|
-
/** 和宿主半侧 renderPersona 一样拼:她读到的就是这段。 */
|
|
68
|
-
function renderPersona(p) {
|
|
69
|
-
var opening = (p['名字'] ? '我是' + p['名字'] + '。' : '') + (p['她是谁'] || '')
|
|
70
|
-
var parts = [opening]
|
|
71
|
-
;['性格', '说话方式', '愿景'].forEach(function (k) { if (p[k]) parts.push('# ' + k + '\n' + p[k]) })
|
|
72
|
-
parts.push(p['补充'] || '')
|
|
73
|
-
return parts.filter(Boolean).join('\n\n')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
var CSS = [
|
|
77
|
-
'.dw{--ink:var(--dsw-alias-label-primary,#2a2620);--soft:var(--dsw-alias-label-tertiary,#8b8475);--gold:#c49a52;',
|
|
78
|
-
'--line:color-mix(in srgb,currentColor 13%,transparent);--paper:color-mix(in srgb,currentColor 3.5%,transparent);',
|
|
79
|
-
'--glow:color-mix(in srgb,var(--gold) 22%,transparent);--warn:#c4553a;--serif:"Noto Serif SC","Source Han Serif SC","Songti SC","STSong","SimSun",serif;',
|
|
80
|
-
'max-width:780px;display:flex;flex-direction:column;gap:18px;font-size:13px;line-height:1.65;color:var(--ink)}',
|
|
81
|
-
'.dw *{box-sizing:border-box}',
|
|
82
|
-
'.dw-head{position:relative;display:flex;align-items:flex-end;gap:16px;padding:18px 20px 16px;border:1px solid var(--line);border-radius:14px;',
|
|
83
|
-
'background:radial-gradient(120% 140% at 100% 0%,var(--glow),transparent 55%),var(--paper);overflow:hidden}',
|
|
84
|
-
'.dw-head:after{content:"";position:absolute;left:20px;right:20px;bottom:0;height:1px;background:linear-gradient(90deg,transparent,var(--gold),transparent);opacity:.55}',
|
|
85
|
-
'.dw-title{flex:1;min-width:0}.dw-title small{display:block;letter-spacing:.24em;font-size:10px;text-transform:uppercase;color:var(--soft)}',
|
|
86
|
-
'.dw-title h2{margin:2px 0 0;font:600 24px/1.25 var(--serif);letter-spacing:.04em}',
|
|
87
|
-
'.dw-state{display:inline-flex;align-items:center;gap:7px;font-size:12px;color:var(--soft);margin-top:6px}',
|
|
88
|
-
'.dw-dot{width:8px;height:8px;border-radius:50%;background:var(--soft);opacity:.6}',
|
|
89
|
-
'.dw-on .dw-dot{background:var(--gold);opacity:1;box-shadow:0 0 0 0 var(--glow);animation:dw-breathe 2.6s ease-in-out infinite}',
|
|
90
|
-
'@keyframes dw-breathe{0%,100%{box-shadow:0 0 0 0 var(--glow)}50%{box-shadow:0 0 0 7px transparent}}',
|
|
91
|
-
'.dw-power{font:600 13px var(--serif);letter-spacing:.2em;padding:9px 20px 9px 22px;border-radius:999px;cursor:pointer;transition:transform .15s,box-shadow .2s,background .2s;',
|
|
92
|
-
'border:1px solid var(--gold);background:var(--gold);color:#fffaf0;box-shadow:0 6px 18px -8px var(--gold)}',
|
|
93
|
-
'.dw-power:hover{transform:translateY(-1px);box-shadow:0 10px 22px -8px var(--gold)}',
|
|
94
|
-
'.dw-power.stop{background:transparent;color:var(--ink);border-color:var(--line);box-shadow:none}.dw-power.stop:hover{border-color:var(--warn);color:var(--warn)}',
|
|
95
|
-
'.dw-power:disabled{opacity:.5;cursor:default;transform:none}',
|
|
96
|
-
'.dw-tabs{display:flex;flex-wrap:wrap;gap:4px;border-bottom:1px solid var(--line);padding:0 6px}',
|
|
97
|
-
'.dw-tab{position:relative;font:500 13px var(--serif);letter-spacing:.12em;padding:8px 14px 10px;background:none;border:0;color:var(--soft);cursor:pointer}',
|
|
98
|
-
'.dw-tab:after{content:"";position:absolute;left:50%;right:50%;bottom:-1px;height:2px;background:var(--gold);transition:left .25s,right .25s}',
|
|
99
|
-
'.dw-tab.on{color:var(--ink)}.dw-tab.on:after{left:12px;right:12px}',
|
|
100
|
-
'.dw-pane{display:flex;flex-direction:column;gap:14px}',
|
|
101
|
-
'.dw-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:14px}',
|
|
102
|
-
'.dw-card{min-width:0;border:1px solid var(--line);border-radius:12px;padding:14px 16px;background:var(--paper);animation:dw-rise .45s both}',
|
|
103
|
-
'@keyframes dw-rise{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}',
|
|
104
|
-
'.dw-card h4{margin:0 0 10px;font:600 13px var(--serif);letter-spacing:.14em;display:flex;align-items:center;gap:8px}',
|
|
105
|
-
'.dw-card h4:before{content:"";width:14px;height:1px;background:var(--gold)}',
|
|
106
|
-
'.dw-kv{display:grid;grid-template-columns:auto 1fr;gap:4px 14px}.dw-kv dt{color:var(--soft);white-space:nowrap}.dw-kv dd{margin:0;min-width:0;overflow-wrap:anywhere}',
|
|
107
|
-
'.dw-big{font:600 20px/1.2 var(--serif)}.dw-muted{color:var(--soft)}.dw-bad{color:var(--warn)}.dw-ok{color:var(--gold)}',
|
|
108
|
-
'.dw-quote{border-left:2px solid var(--gold);padding:2px 0 2px 10px;margin:8px 0 0;font-family:var(--serif)}',
|
|
109
|
-
'.dw-meter{height:4px;border-radius:4px;background:var(--line);overflow:hidden;margin:8px 0 4px}.dw-meter i{display:block;height:100%;background:linear-gradient(90deg,var(--gold),color-mix(in srgb,var(--gold) 55%,#fff))}',
|
|
110
|
-
'.dw-trail{display:flex;flex-wrap:wrap;gap:6px 14px;margin-top:4px}.dw-trail span{display:inline-flex;align-items:center;gap:6px}.dw-trail span:before{content:"";width:5px;height:5px;border-radius:50%;background:var(--gold)}',
|
|
111
|
-
'.dw-welcome{text-align:center;padding:30px 20px}.dw-welcome h3{font:600 20px var(--serif);margin:0 0 8px;letter-spacing:.06em}',
|
|
112
|
-
'.dw-steps{display:inline-flex;flex-direction:column;gap:6px;text-align:left;margin-top:12px;counter-reset:s}',
|
|
113
|
-
'.dw-steps li{list-style:none;counter-increment:s;display:flex;gap:10px}.dw-steps li:before{content:counter(s);font:600 12px var(--serif);color:var(--gold);border:1px solid var(--gold);border-radius:50%;width:20px;height:20px;display:inline-grid;place-items:center;flex:none}',
|
|
114
|
-
'.dw-layer{display:grid;grid-template-columns:96px 1fr;gap:4px 16px;padding:14px 0;border-bottom:1px dashed var(--line)}',
|
|
115
|
-
'.dw-layer:last-child{border-bottom:0}.dw-layer label{font:600 14px var(--serif);letter-spacing:.1em;padding-top:6px}',
|
|
116
|
-
'.dw-layer small{grid-column:2;color:var(--soft);font-size:11.5px}',
|
|
117
|
-
'.dw textarea,.dw input[type=text]{width:100%;font:inherit;color:inherit;background:color-mix(in srgb,currentColor 2%,transparent);border:1px solid var(--line);border-radius:8px;padding:8px 10px;resize:vertical;transition:border-color .2s,box-shadow .2s}',
|
|
118
|
-
'.dw textarea:focus,.dw input[type=text]:focus{outline:none;border-color:var(--gold);box-shadow:0 0 0 3px var(--glow)}',
|
|
119
|
-
'.dw input.dw-name{font:600 18px var(--serif);letter-spacing:.06em}',
|
|
120
|
-
'.dw-code{font-family:ui-monospace,"Cascadia Mono",Consolas,monospace;font-size:12px;line-height:1.6;min-height:340px}',
|
|
121
|
-
'.dw-bar{position:sticky;bottom:0;display:flex;align-items:center;gap:10px;padding:10px 0 2px;background:linear-gradient(transparent,var(--dsw-alias-background-primary,transparent) 40%)}',
|
|
122
|
-
'.dw-btn{flex-shrink:0;white-space:nowrap;font:inherit;cursor:pointer;border:1px solid var(--line);background:transparent;color:inherit;border-radius:8px;padding:6px 14px;transition:border-color .2s,background .2s}',
|
|
123
|
-
'.dw-btn:hover{border-color:var(--gold)}.dw-btn.primary{background:var(--gold);border-color:var(--gold);color:#fffaf0}.dw-btn:disabled{opacity:.45;cursor:default}',
|
|
124
|
-
'.dw-preview{white-space:pre-wrap;font-family:var(--serif);font-size:12.5px;margin:0;max-height:260px;overflow:auto}',
|
|
125
|
-
'.dw-chip{display:inline-block;font-size:11px;padding:1px 8px;border-radius:999px;border:1px solid var(--line);color:var(--soft)}',
|
|
126
|
-
'.dw table{width:100%;border-collapse:collapse}.dw td{padding:3px 6px;vertical-align:top;border-bottom:1px solid color-mix(in srgb,currentColor 6%,transparent)}',
|
|
127
|
-
'.dw-activity{table-layout:fixed}.dw-activity td{overflow:hidden;overflow-wrap:anywhere}.dw-activity td:first-child{white-space:nowrap}',
|
|
128
|
-
'.dw-clamp{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;font-family:ui-monospace,"Cascadia Mono",Consolas,monospace;font-size:12px}',
|
|
129
|
-
'.dw-
|
|
130
|
-
'.dw-setting
|
|
131
|
-
'.dw
|
|
132
|
-
'.dw
|
|
133
|
-
'
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var
|
|
150
|
-
var
|
|
151
|
-
var
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
function (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
h('
|
|
167
|
-
|
|
168
|
-
h('
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var
|
|
175
|
-
var
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
function (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var
|
|
193
|
-
var
|
|
194
|
-
var
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
h('
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
h('div', { className: 'dw-
|
|
211
|
-
|
|
212
|
-
h('
|
|
213
|
-
h('
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
var
|
|
219
|
-
var
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
h('
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
h('div', { className: 'dw-
|
|
243
|
-
|
|
244
|
-
h('
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
var
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
h('
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
h(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
var
|
|
312
|
-
var
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
h('div', { key: '
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
h('button', { className: 'dw-btn', onClick:
|
|
337
|
-
h(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
h(
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
var
|
|
391
|
-
var
|
|
392
|
-
var
|
|
393
|
-
var
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
//
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
function
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
function
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
})
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
h('
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
h('
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
h('
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
h('
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
function
|
|
615
|
-
var
|
|
616
|
-
var
|
|
617
|
-
var
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
h(
|
|
638
|
-
h(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
var
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
h('
|
|
673
|
-
h('
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
? h(
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
1
|
+
/**
|
|
2
|
+
* dsh-world — 浏览器半侧:设置里的「世界控制台」。
|
|
3
|
+
* 模块 id 必须等于 bundle 行名 dsh-world;数据来自宿主半侧的 /dsh-world/console/* 路由。
|
|
4
|
+
* 读取是 GET;会改变东西的(开始、停止、人设、世界提示词、额度、记忆轮数)是带 x-dsh-world 头的 JSON POST。
|
|
5
|
+
*/
|
|
6
|
+
window.__ModuleLoader__.load({
|
|
7
|
+
id: 'dsh-world',
|
|
8
|
+
factory: (require) => {
|
|
9
|
+
var react = require('react')
|
|
10
|
+
var h = react.createElement
|
|
11
|
+
var useState = react.useState
|
|
12
|
+
var useEffect = react.useEffect
|
|
13
|
+
var useRef = react.useRef
|
|
14
|
+
|
|
15
|
+
function settle(r) {
|
|
16
|
+
return r.json().then(function (body) { return { body: body } }, function () { return null }).then(function (parsed) {
|
|
17
|
+
var body = parsed && parsed.body
|
|
18
|
+
if (!r.ok) { var err = new Error((body && body.error) || ('HTTP ' + r.status)); err.status = r.status; if (body && body.code) err.code = body.code; throw err }
|
|
19
|
+
if (!parsed) { var bad = new Error('回复不是 JSON'); bad.notJson = true; throw bad }
|
|
20
|
+
return body
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
function getFrom(base, path) { return fetch(base + path, { cache: 'no-store' }).then(settle) }
|
|
24
|
+
function postTo(base, path, body) {
|
|
25
|
+
return fetch(base + path, { method: 'POST', cache: 'no-store', headers: { 'content-type': 'application/json', 'x-dsh-world': '1' }, body: JSON.stringify(body || {}) }).then(settle)
|
|
26
|
+
}
|
|
27
|
+
function api(path) { return getFrom('/dsh-world/console/', path) }
|
|
28
|
+
function post(path, body) { return postTo('/dsh-world/console/', path, body) }
|
|
29
|
+
/** QQ 那几扇门在自己的前缀下(/dsh-world/qq/*),不和 console 混在一起。 */
|
|
30
|
+
function qqGet(path) { return getFrom('/dsh-world/qq/', path) }
|
|
31
|
+
function qqPost(path, body) { return postTo('/dsh-world/qq/', path, body) }
|
|
32
|
+
/** 保存没成时的那句话。 */
|
|
33
|
+
function failedTo(setMsg) { return function (e) { setMsg('保存失败:' + (e.message || e)) } }
|
|
34
|
+
/** 设置卡下面那行状态:没成(失败、请填…)标红,其余灰色。 */
|
|
35
|
+
function Status(props) { return props.msg ? h('div', { role: 'status', className: /失败|请填/.test(props.msg) ? 'dw-bad' : 'dw-muted' }, props.msg) : null }
|
|
36
|
+
/** 快照,或 null 表示控制台不在(404、不是 JSON 的页面、没有 life 字段的回复)。 */
|
|
37
|
+
function loadSnapshot() {
|
|
38
|
+
return api('snapshot').then(function (s) {
|
|
39
|
+
return s && typeof s === 'object' && typeof s.life === 'object' ? s : null
|
|
40
|
+
}, function (e) { if (e && (e.status === 404 || e.notJson)) return null; throw e })
|
|
41
|
+
}
|
|
42
|
+
function clock(iso, zone) {
|
|
43
|
+
try { return new Date(iso).toLocaleTimeString('zh-CN', { timeZone: zone, hourCycle: 'h23', hour: '2-digit', minute: '2-digit' }) } catch (e) { return String(iso) }
|
|
44
|
+
}
|
|
45
|
+
function local(iso, zone) {
|
|
46
|
+
if (!iso) return '—'
|
|
47
|
+
try { return new Date(iso).toLocaleString('zh-CN', { timeZone: zone, hourCycle: 'h23', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' }) } catch (e) { return iso }
|
|
48
|
+
}
|
|
49
|
+
function remaining(iso) {
|
|
50
|
+
var ms = Date.parse(iso) - Date.now()
|
|
51
|
+
if (!(ms > 0)) return '马上'
|
|
52
|
+
var m = Math.round(ms / 60000), d = Math.floor(m / 1440), hr = Math.floor(m % 1440 / 60), mi = m % 60
|
|
53
|
+
return (d ? d + ' 天 ' : '') + (hr ? hr + ' 小时 ' : '') + mi + ' 分'
|
|
54
|
+
}
|
|
55
|
+
function list(value) { return Array.isArray(value) ? value : [] }
|
|
56
|
+
var sourceLabel = { first: '新家', return: '回来', plan: '闹钟', fallback: '早上兜底', review: '回顾' }
|
|
57
|
+
var statusLabel = { running: '正在做事', idle: '空闲', cold: '休息中' }
|
|
58
|
+
|
|
59
|
+
var LAYERS = [
|
|
60
|
+
{ key: '名字', hint: '她叫什么。家的标题、记忆里她的署名都用它。', rows: 1 },
|
|
61
|
+
{ key: '她是谁', hint: '一句话:她是什么样的存在。', rows: 2 },
|
|
62
|
+
{ key: '性格', hint: '她的脾气、偏好和小习惯。', rows: 4 },
|
|
63
|
+
{ key: '说话方式', hint: '口吻、句子长短、会不会用表情。', rows: 3 },
|
|
64
|
+
{ key: '愿景', hint: '你希望她成为什么样子。', rows: 4 },
|
|
65
|
+
{ key: '补充', hint: '其他想让她知道的:底线、默契、约定。', rows: 3 },
|
|
66
|
+
]
|
|
67
|
+
/** 和宿主半侧 renderPersona 一样拼:她读到的就是这段。 */
|
|
68
|
+
function renderPersona(p) {
|
|
69
|
+
var opening = (p['名字'] ? '我是' + p['名字'] + '。' : '') + (p['她是谁'] || '')
|
|
70
|
+
var parts = [opening]
|
|
71
|
+
;['性格', '说话方式', '愿景'].forEach(function (k) { if (p[k]) parts.push('# ' + k + '\n' + p[k]) })
|
|
72
|
+
parts.push(p['补充'] || '')
|
|
73
|
+
return parts.filter(Boolean).join('\n\n')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
var CSS = [
|
|
77
|
+
'.dw{--ink:var(--dsw-alias-label-primary,#2a2620);--soft:var(--dsw-alias-label-tertiary,#8b8475);--gold:#c49a52;',
|
|
78
|
+
'--line:color-mix(in srgb,currentColor 13%,transparent);--paper:color-mix(in srgb,currentColor 3.5%,transparent);',
|
|
79
|
+
'--glow:color-mix(in srgb,var(--gold) 22%,transparent);--warn:#c4553a;--serif:"Noto Serif SC","Source Han Serif SC","Songti SC","STSong","SimSun",serif;',
|
|
80
|
+
'max-width:780px;display:flex;flex-direction:column;gap:18px;font-size:13px;line-height:1.65;color:var(--ink)}',
|
|
81
|
+
'.dw *{box-sizing:border-box}',
|
|
82
|
+
'.dw-head{position:relative;display:flex;align-items:flex-end;gap:16px;padding:18px 20px 16px;border:1px solid var(--line);border-radius:14px;',
|
|
83
|
+
'background:radial-gradient(120% 140% at 100% 0%,var(--glow),transparent 55%),var(--paper);overflow:hidden}',
|
|
84
|
+
'.dw-head:after{content:"";position:absolute;left:20px;right:20px;bottom:0;height:1px;background:linear-gradient(90deg,transparent,var(--gold),transparent);opacity:.55}',
|
|
85
|
+
'.dw-title{flex:1;min-width:0}.dw-title small{display:block;letter-spacing:.24em;font-size:10px;text-transform:uppercase;color:var(--soft)}',
|
|
86
|
+
'.dw-title h2{margin:2px 0 0;font:600 24px/1.25 var(--serif);letter-spacing:.04em}',
|
|
87
|
+
'.dw-state{display:inline-flex;align-items:center;gap:7px;font-size:12px;color:var(--soft);margin-top:6px}',
|
|
88
|
+
'.dw-dot{width:8px;height:8px;border-radius:50%;background:var(--soft);opacity:.6}',
|
|
89
|
+
'.dw-on .dw-dot{background:var(--gold);opacity:1;box-shadow:0 0 0 0 var(--glow);animation:dw-breathe 2.6s ease-in-out infinite}',
|
|
90
|
+
'@keyframes dw-breathe{0%,100%{box-shadow:0 0 0 0 var(--glow)}50%{box-shadow:0 0 0 7px transparent}}',
|
|
91
|
+
'.dw-power{font:600 13px var(--serif);letter-spacing:.2em;padding:9px 20px 9px 22px;border-radius:999px;cursor:pointer;transition:transform .15s,box-shadow .2s,background .2s;',
|
|
92
|
+
'border:1px solid var(--gold);background:var(--gold);color:#fffaf0;box-shadow:0 6px 18px -8px var(--gold)}',
|
|
93
|
+
'.dw-power:hover{transform:translateY(-1px);box-shadow:0 10px 22px -8px var(--gold)}',
|
|
94
|
+
'.dw-power.stop{background:transparent;color:var(--ink);border-color:var(--line);box-shadow:none}.dw-power.stop:hover{border-color:var(--warn);color:var(--warn)}',
|
|
95
|
+
'.dw-power:disabled{opacity:.5;cursor:default;transform:none}',
|
|
96
|
+
'.dw-tabs{display:flex;flex-wrap:wrap;gap:4px;border-bottom:1px solid var(--line);padding:0 6px}',
|
|
97
|
+
'.dw-tab{position:relative;font:500 13px var(--serif);letter-spacing:.12em;padding:8px 14px 10px;background:none;border:0;color:var(--soft);cursor:pointer}',
|
|
98
|
+
'.dw-tab:after{content:"";position:absolute;left:50%;right:50%;bottom:-1px;height:2px;background:var(--gold);transition:left .25s,right .25s}',
|
|
99
|
+
'.dw-tab.on{color:var(--ink)}.dw-tab.on:after{left:12px;right:12px}',
|
|
100
|
+
'.dw-pane{display:flex;flex-direction:column;gap:14px}',
|
|
101
|
+
'.dw-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:14px}',
|
|
102
|
+
'.dw-card{min-width:0;border:1px solid var(--line);border-radius:12px;padding:14px 16px;background:var(--paper);animation:dw-rise .45s both}',
|
|
103
|
+
'@keyframes dw-rise{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}',
|
|
104
|
+
'.dw-card h4{margin:0 0 10px;font:600 13px var(--serif);letter-spacing:.14em;display:flex;align-items:center;gap:8px}',
|
|
105
|
+
'.dw-card h4:before{content:"";width:14px;height:1px;background:var(--gold)}',
|
|
106
|
+
'.dw-kv{display:grid;grid-template-columns:auto 1fr;gap:4px 14px}.dw-kv dt{color:var(--soft);white-space:nowrap}.dw-kv dd{margin:0;min-width:0;overflow-wrap:anywhere}',
|
|
107
|
+
'.dw-big{font:600 20px/1.2 var(--serif)}.dw-muted{color:var(--soft)}.dw-bad{color:var(--warn)}.dw-ok{color:var(--gold)}',
|
|
108
|
+
'.dw-quote{border-left:2px solid var(--gold);padding:2px 0 2px 10px;margin:8px 0 0;font-family:var(--serif)}',
|
|
109
|
+
'.dw-meter{height:4px;border-radius:4px;background:var(--line);overflow:hidden;margin:8px 0 4px}.dw-meter i{display:block;height:100%;background:linear-gradient(90deg,var(--gold),color-mix(in srgb,var(--gold) 55%,#fff))}',
|
|
110
|
+
'.dw-trail{display:flex;flex-wrap:wrap;gap:6px 14px;margin-top:4px}.dw-trail span{display:inline-flex;align-items:center;gap:6px}.dw-trail span:before{content:"";width:5px;height:5px;border-radius:50%;background:var(--gold)}',
|
|
111
|
+
'.dw-welcome{text-align:center;padding:30px 20px}.dw-welcome h3{font:600 20px var(--serif);margin:0 0 8px;letter-spacing:.06em}',
|
|
112
|
+
'.dw-steps{display:inline-flex;flex-direction:column;gap:6px;text-align:left;margin-top:12px;counter-reset:s}',
|
|
113
|
+
'.dw-steps li{list-style:none;counter-increment:s;display:flex;gap:10px}.dw-steps li:before{content:counter(s);font:600 12px var(--serif);color:var(--gold);border:1px solid var(--gold);border-radius:50%;width:20px;height:20px;display:inline-grid;place-items:center;flex:none}',
|
|
114
|
+
'.dw-layer{display:grid;grid-template-columns:96px 1fr;gap:4px 16px;padding:14px 0;border-bottom:1px dashed var(--line)}',
|
|
115
|
+
'.dw-layer:last-child{border-bottom:0}.dw-layer label{font:600 14px var(--serif);letter-spacing:.1em;padding-top:6px}',
|
|
116
|
+
'.dw-layer small{grid-column:2;color:var(--soft);font-size:11.5px}',
|
|
117
|
+
'.dw textarea,.dw input[type=text]{width:100%;font:inherit;color:inherit;background:color-mix(in srgb,currentColor 2%,transparent);border:1px solid var(--line);border-radius:8px;padding:8px 10px;resize:vertical;transition:border-color .2s,box-shadow .2s}',
|
|
118
|
+
'.dw textarea:focus,.dw input[type=text]:focus{outline:none;border-color:var(--gold);box-shadow:0 0 0 3px var(--glow)}',
|
|
119
|
+
'.dw input.dw-name{font:600 18px var(--serif);letter-spacing:.06em}',
|
|
120
|
+
'.dw-code{font-family:ui-monospace,"Cascadia Mono",Consolas,monospace;font-size:12px;line-height:1.6;min-height:340px}',
|
|
121
|
+
'.dw-bar{position:sticky;bottom:0;display:flex;align-items:center;gap:10px;padding:10px 0 2px;background:linear-gradient(transparent,var(--dsw-alias-background-primary,transparent) 40%)}',
|
|
122
|
+
'.dw-btn{flex-shrink:0;white-space:nowrap;font:inherit;cursor:pointer;border:1px solid var(--line);background:transparent;color:inherit;border-radius:8px;padding:6px 14px;transition:border-color .2s,background .2s}',
|
|
123
|
+
'.dw-btn:hover{border-color:var(--gold)}.dw-btn.primary{background:var(--gold);border-color:var(--gold);color:#fffaf0}.dw-btn:disabled{opacity:.45;cursor:default}',
|
|
124
|
+
'.dw-preview{white-space:pre-wrap;font-family:var(--serif);font-size:12.5px;margin:0;max-height:260px;overflow:auto}',
|
|
125
|
+
'.dw-chip{display:inline-block;font-size:11px;padding:1px 8px;border-radius:999px;border:1px solid var(--line);color:var(--soft)}',
|
|
126
|
+
'.dw table{width:100%;border-collapse:collapse}.dw td{padding:3px 6px;vertical-align:top;border-bottom:1px solid color-mix(in srgb,currentColor 6%,transparent)}',
|
|
127
|
+
'.dw-activity{table-layout:fixed}.dw-activity td{overflow:hidden;overflow-wrap:anywhere}.dw-activity td:first-child{white-space:nowrap}',
|
|
128
|
+
'.dw-clamp{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;font-family:ui-monospace,"Cascadia Mono",Consolas,monospace;font-size:12px}',
|
|
129
|
+
'.dw-hit{padding:10px 0;border-top:1px solid var(--line);min-width:0}.dw-hit .dw-diary{max-height:320px;overflow:auto}',
|
|
130
|
+
'.dw-setting{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px;align-items:center}.dw-setting input[type=text]{flex:1 1 120px;max-width:200px;min-width:0}',
|
|
131
|
+
'.dw-setting select{flex:1 1 140px;max-width:100%;min-width:0}',
|
|
132
|
+
'.dw pre.dw-diary{white-space:pre-wrap;margin:10px 0 0;font-family:var(--serif)}',
|
|
133
|
+
'.dw select{font:inherit;color:inherit;background:transparent;border:1px solid var(--line);border-radius:6px;padding:2px 6px}',
|
|
134
|
+
'@media (prefers-reduced-motion:reduce){.dw *{animation:none!important;transition:none!important}}',
|
|
135
|
+
].join('')
|
|
136
|
+
function ensureStyle() {
|
|
137
|
+
if (document.getElementById('dsh-world-console-style')) return
|
|
138
|
+
var tag = document.createElement('style'); tag.id = 'dsh-world-console-style'; tag.textContent = CSS; document.head.appendChild(tag)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function Card(props) {
|
|
142
|
+
return h('section', { className: 'dw-card', style: { animationDelay: (props.delay || 0) + 'ms' } }, props.title ? h('h4', null, props.title) : null, props.children)
|
|
143
|
+
}
|
|
144
|
+
function KV(rows) {
|
|
145
|
+
return h('dl', { className: 'dw-kv' }, rows.filter(Boolean).map(function (row, i) { return [h('dt', { key: 'k' + i }, row[0]), h('dd', { key: 'v' + i }, row[1])] }))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function Activity(props) {
|
|
149
|
+
var days = props.days, zone = props.zone
|
|
150
|
+
var dayState = useState(days[0] || ''), day = dayState[0], setDay = dayState[1]
|
|
151
|
+
var outsideState = useState(false), outside = outsideState[0], setOutside = outsideState[1]
|
|
152
|
+
var rowsState = useState([]), rows = rowsState[0], setRows = rowsState[1]
|
|
153
|
+
var errState = useState(null), err = errState[0], setErr = errState[1]
|
|
154
|
+
useEffect(function () {
|
|
155
|
+
if (!day) return
|
|
156
|
+
var alive = true
|
|
157
|
+
api('activity?day=' + encodeURIComponent(day) + (outside ? '&outside=1' : '')).then(
|
|
158
|
+
function (r) { if (alive) { setRows(r); setErr(null) } },
|
|
159
|
+
function (e) { if (alive) { setRows([]); setErr(String(e.message || e)) } })
|
|
160
|
+
return function () { alive = false }
|
|
161
|
+
}, [day, outside, props.tick])
|
|
162
|
+
return h(Card, { title: '活动记录' },
|
|
163
|
+
days.length === 0 ? h('div', { className: 'dw-muted' }, '还没有活动记录') : h('div', null,
|
|
164
|
+
h('select', { value: day, onChange: function (e) { setDay(e.target.value) } }, days.map(function (d) { return h('option', { key: d, value: d }, d) })),
|
|
165
|
+
' ', h('label', { className: 'dw-muted' }, h('input', { type: 'checkbox', checked: outside, onChange: function (e) { setOutside(e.target.checked) } }), ' 只看房间外'),
|
|
166
|
+
err ? h('div', { className: 'dw-bad' }, '读取失败:' + err) : null,
|
|
167
|
+
h('table', { className: 'dw-activity' },
|
|
168
|
+
h('colgroup', null, h('col', { style: { width: 48 } }), h('col', { style: { width: '22%' } }), h('col'), h('col', { style: { width: 40 } }), h('col', { style: { width: 64 } })),
|
|
169
|
+
h('tbody', null, rows.map(function (r) {
|
|
170
|
+
return h('tr', { key: r.callId + r.time }, h('td', { className: 'dw-muted' }, clock(r.time, zone)), h('td', null, r.tool), h('td', { title: r.summary }, h('div', { className: 'dw-clamp' }, r.summary)), h('td', { className: 'dw-bad' }, r.status === 'error' ? '失败' : ''), h('td', { className: r.outside ? 'dw-bad' : 'dw-muted' }, (r.gapBefore ? '(此前有缺口)' : '') + (r.outside ? '房间外' : '')))
|
|
171
|
+
})))))
|
|
172
|
+
}
|
|
173
|
+
function Diary(props) {
|
|
174
|
+
var openState = useState(null), open = openState[0], setOpen = openState[1]
|
|
175
|
+
var textState = useState(''), text = textState[0], setText = textState[1]
|
|
176
|
+
var errState = useState(null), err = errState[0], setErr = errState[1]
|
|
177
|
+
var wanted = useRef(null)
|
|
178
|
+
function show(date) {
|
|
179
|
+
wanted.current = date; setOpen(date); setText(''); setErr(null)
|
|
180
|
+
api('diary?date=' + encodeURIComponent(date)).then(
|
|
181
|
+
function (b) { if (wanted.current === date) setText(String(b.text || '')) },
|
|
182
|
+
function (e) { if (wanted.current === date) setErr(String(e.message || e)) })
|
|
183
|
+
}
|
|
184
|
+
return h(Card, { title: '日记' },
|
|
185
|
+
props.dates.length === 0 ? h('div', { className: 'dw-muted' }, '还没有日记') : h('div', null,
|
|
186
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 6 } }, props.dates.map(function (d) { return h('button', { key: d, className: 'dw-btn' + (open === d ? ' primary' : ''), onClick: function () { show(d) } }, d) })),
|
|
187
|
+
err ? h('div', { className: 'dw-bad' }, '读取失败:' + err) : null,
|
|
188
|
+
open && !err ? h('pre', { className: 'dw-diary' }, text) : null))
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function PhotoAlbum(props) {
|
|
192
|
+
var pageState = useState({ photos: [], total: 0, hasMore: false }), page = pageState[0], setPage = pageState[1]
|
|
193
|
+
var offsetState = useState(0), offset = offsetState[0], setOffset = offsetState[1]
|
|
194
|
+
var openState = useState(null), open = openState[0], setOpen = openState[1]
|
|
195
|
+
var errorState = useState(''), error = errorState[0], setError = errorState[1]
|
|
196
|
+
useEffect(function () {
|
|
197
|
+
var alive = true
|
|
198
|
+
api('photos?limit=12&offset=' + offset).then(function (value) { if (alive) { setPage(value); setError('') } }, function (e) { if (alive) setError(String(e.message || e)) })
|
|
199
|
+
return function () { alive = false }
|
|
200
|
+
}, [offset, props.tick])
|
|
201
|
+
return h('div', { className: 'dw-pane' },
|
|
202
|
+
h(Card, { title: '她收藏的照片' },
|
|
203
|
+
h('div', { className: 'dw-muted' }, '由她用 keep_photo 决定收藏。列表只读取说明,点开才加载图片。'),
|
|
204
|
+
error ? h('div', { className: 'dw-bad', role: 'alert' }, error) : null,
|
|
205
|
+
page.photos.length ? page.photos.map(function (photo) {
|
|
206
|
+
return h('div', { className: 'dw-setting', key: photo.id },
|
|
207
|
+
h('span', { style: { flex: '1 1 180px', overflowWrap: 'anywhere' } }, photo.description || '未写说明', ' · ', photo.width + '×' + photo.height, ' · ', local(photo.savedAt, props.zone), photo.tags.length ? ' · ' + photo.tags.join('、') : ''),
|
|
208
|
+
h('button', { className: 'dw-btn', onClick: function () { setOpen(open === photo.id ? null : photo.id) } }, open === photo.id ? '收起照片' : '查看照片'),
|
|
209
|
+
open === photo.id ? h('img', { src: '/dsh-world/console/photo?id=' + encodeURIComponent(photo.id), alt: photo.description || '收藏的照片', style: { display: 'block', width: '100%', maxHeight: 480, objectFit: 'contain' }, onError: function () { setError('照片读取失败,请刷新后重试。') } }) : null)
|
|
210
|
+
}) : h('div', { className: 'dw-muted' }, '她还没有收藏照片。'),
|
|
211
|
+
h('div', { className: 'dw-setting' },
|
|
212
|
+
h('button', { className: 'dw-btn', disabled: offset === 0, onClick: function () { setOffset(Math.max(0, offset - 12)); setOpen(null) } }, '上一页'),
|
|
213
|
+
h('span', { className: 'dw-muted' }, '共 ' + page.total + ' 张 · 第 ' + (Math.floor(offset / 12) + 1) + ' 页'),
|
|
214
|
+
h('button', { className: 'dw-btn', disabled: !page.hasMore, onClick: function () { setOffset(offset + 12); setOpen(null) } }, '下一页'))))
|
|
215
|
+
}
|
|
216
|
+
/** 分层人设:每层一张卡,右边是她实际读到的样子。 */
|
|
217
|
+
function PersonaEditor(props) {
|
|
218
|
+
var state = useState(null), persona = state[0], setPersona = state[1]
|
|
219
|
+
var savedState = useState(null), saved = savedState[0], setSaved = savedState[1]
|
|
220
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
221
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
222
|
+
useEffect(function () {
|
|
223
|
+
api('prompts').then(function (b) { setPersona(b.persona); setSaved(b.persona) }, function (e) { setMsg('读取失败:' + (e.message || e)) })
|
|
224
|
+
}, [])
|
|
225
|
+
if (!persona) return h('div', { className: 'dw-muted' }, msg || '读取中…')
|
|
226
|
+
var dirty = JSON.stringify(persona) !== JSON.stringify(saved)
|
|
227
|
+
function set(key, value) { var next = Object.assign({}, persona); next[key] = value; setPersona(next); setMsg('') }
|
|
228
|
+
function save() {
|
|
229
|
+
setBusy(true)
|
|
230
|
+
post('persona', persona).then(function () { setSaved(persona); setMsg('已保存。新会话或下次压缩后生效,也可点击「应用并压缩家会话」。'); if (props.onSaved) props.onSaved() },
|
|
231
|
+
failedTo(setMsg)).then(function () { setBusy(false) })
|
|
232
|
+
}
|
|
233
|
+
var preview = renderPersona(persona)
|
|
234
|
+
return h('div', { className: 'dw-pane' },
|
|
235
|
+
h(Card, { title: '她是谁' }, h('div', { className: 'dw-muted' }, '这里写的会取代 DSH 自带的那句默认身份(“You are an AI agent powered by DeepSeek Harness.”);如果你在 DSH 里已经设过系统人设,它原样保留,这里写的排在它后面。'), LAYERS.map(function (layer) {
|
|
236
|
+
var common = { id: 'dw-' + layer.key, value: persona[layer.key] || '', onChange: function (e) { set(layer.key, e.target.value) } }
|
|
237
|
+
return h('div', { className: 'dw-layer', key: layer.key },
|
|
238
|
+
h('label', { htmlFor: common.id }, layer.key),
|
|
239
|
+
layer.rows === 1 ? h('input', Object.assign({ type: 'text', className: 'dw-name', placeholder: '比如:鲸鲸' }, common)) : h('textarea', Object.assign({ rows: layer.rows }, common)),
|
|
240
|
+
h('small', null, layer.hint))
|
|
241
|
+
})),
|
|
242
|
+
h(Card, { title: '她读到的样子', delay: 80 }, preview ? h('pre', { className: 'dw-preview' }, preview) : h('div', { className: 'dw-muted' }, '还什么都没写。没写的时候,她沿用 DSH 自带的默认身份和你在 DSH 里设的系统人设。')),
|
|
243
|
+
h('div', { className: 'dw-bar' },
|
|
244
|
+
h('button', { className: 'dw-btn primary', disabled: !dirty || busy, onClick: save }, busy ? '保存中…' : '保存人设'),
|
|
245
|
+
h('span', { className: msg.indexOf('失败') >= 0 ? 'dw-bad' : 'dw-muted' }, msg || (dirty ? '有改动还没保存' : ''))))
|
|
246
|
+
}
|
|
247
|
+
/** 世界提示词模板:自己的一份,或插件自带的。 */
|
|
248
|
+
function PromptEditor() {
|
|
249
|
+
var state = useState(null), prompt = state[0], setPrompt = state[1]
|
|
250
|
+
var textState = useState(''), text = textState[0], setText = textState[1]
|
|
251
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
252
|
+
function load() { api('prompts').then(function (b) { setPrompt(b.worldPrompt); setText(b.worldPrompt.text) }, function (e) { setMsg('读取失败:' + (e.message || e)) }) }
|
|
253
|
+
useEffect(load, [])
|
|
254
|
+
if (!prompt) return h('div', { className: 'dw-muted' }, msg || '读取中…')
|
|
255
|
+
function save(value, done) {
|
|
256
|
+
post('world-prompt', { text: value }).then(function () { setMsg(done); load() }, failedTo(setMsg))
|
|
257
|
+
}
|
|
258
|
+
return h('div', { className: 'dw-pane' },
|
|
259
|
+
h(Card, { title: '世界提示词' },
|
|
260
|
+
h('div', { style: { marginBottom: 8 } }, h('span', { className: 'dw-chip' }, prompt.custom ? '你自己的一份' : '插件自带'), ' ',
|
|
261
|
+
h('span', { className: 'dw-muted' }, '可用 {{name}} {{partner}} {{homeTitle}} {{roomDir}} {{diaryDir}} {{selfFile}} {{self}} 和 {{#home}}…{{/home}} 等,见 README')),
|
|
262
|
+
h('textarea', { className: 'dw-code', value: text, onChange: function (e) { setText(e.target.value); setMsg('') } })),
|
|
263
|
+
prompt.memory && list(prompt.memory.missing).length ? h(Card, { title: '这份提示词还没提到新的记忆能力' },
|
|
264
|
+
h('div', { className: 'dw-muted' }, '你自己的这份没有用到:' + list(prompt.memory.missing).join('、') + '。工具照样可用,但她在提示里读不到它们的来历。想加的话,把下面这段贴进去;插件不会自动改你的模板。'),
|
|
265
|
+
h('pre', { className: 'dw-diary' }, prompt.memory.snippet)) : null,
|
|
266
|
+
h('div', { className: 'dw-bar' },
|
|
267
|
+
h('button', { className: 'dw-btn primary', disabled: text === prompt.text, onClick: function () { save(text, '已保存。新会话或下次压缩后生效,也可点击「应用并压缩家会话」。') } }, '保存'),
|
|
268
|
+
prompt.custom ? h('button', { className: 'dw-btn', onClick: function () { if (window.confirm('删掉你自己的这份,换回插件自带的模板?')) save('', '已换回插件自带的模板。') } }, '恢复默认') : null,
|
|
269
|
+
h('span', { className: msg.indexOf('失败') >= 0 ? 'dw-bad' : 'dw-muted' }, msg)))
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function HomeApply(props) {
|
|
273
|
+
var snap = props.snap, state = snap.homeApply || {}
|
|
274
|
+
var sendingState = useState(false), sending = sendingState[0], setSending = sendingState[1]
|
|
275
|
+
var errorState = useState(''), error = errorState[0], setError = errorState[1]
|
|
276
|
+
var waiting = state.status === 'waiting', compacting = state.status === 'compacting'
|
|
277
|
+
function apply() {
|
|
278
|
+
setSending(true); setError('')
|
|
279
|
+
post('apply-home').then(function () { props.refresh() }, function (e) { setError(String(e.message || e)) }).then(function () { setSending(false) })
|
|
280
|
+
}
|
|
281
|
+
return h(Card, { title: '应用已保存配置' },
|
|
282
|
+
h('div', { className: 'dw-muted' }, '先保存人设和世界提示词,再提交。等待家空闲后压缩一次;压缩会调用模型并重建上下文缓存。'),
|
|
283
|
+
h('div', { className: 'dw-setting' },
|
|
284
|
+
h('button', { className: 'dw-btn', disabled: sending || waiting || compacting || !snap.running || !snap.life || !snap.homeApply, onClick: apply }, waiting ? '等待家空闲…' : compacting ? '正在压缩家会话…' : sending ? '提交中…' : '应用并压缩家会话'),
|
|
285
|
+
h('span', { role: 'status', 'aria-live': 'polite', className: error || state.status === 'failed' ? 'dw-bad' : 'dw-muted' }, error || (waiting ? '已排队,不打断当前对话。' : compacting ? '正在执行,请稍候。' : state.message) || (!snap.running || !snap.life ? '请先启动世界生活线。' : ''))))
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** 今天家里花了多少,和每天的额度(留空不限)。 */
|
|
289
|
+
function Budget(props) {
|
|
290
|
+
var budget = props.budget || {}, daily = budget.daily, today = budget.today
|
|
291
|
+
var spent = today ? today.yuan : 0
|
|
292
|
+
var draftState = useState(daily == null ? '' : String(daily)), draft = draftState[0], setDraft = draftState[1]
|
|
293
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
294
|
+
function save() {
|
|
295
|
+
var text = String(draft).trim(), value = text === '' ? null : Number(text)
|
|
296
|
+
if (value !== null && !(value >= 0)) { setMsg('请填一个不小于 0 的数,或留空表示不限'); return }
|
|
297
|
+
post('budget', { daily: value }).then(function () { setMsg(value === null ? '已改为不限' : '已保存'); if (props.onSaved) props.onSaved() }, failedTo(setMsg))
|
|
298
|
+
}
|
|
299
|
+
var over = daily != null && spent >= daily
|
|
300
|
+
return h(Card, { title: '今日花费', delay: 240 },
|
|
301
|
+
h('div', null, h('span', { className: 'dw-big' + (over ? ' dw-bad' : '') }, '¥' + spent.toFixed(2)), h('span', { className: 'dw-muted' }, daily == null ? ' · 不限额' : ' / ¥' + Number(daily).toFixed(2) + ' 每天')),
|
|
302
|
+
daily != null ? h('div', { className: 'dw-meter' }, h('i', { style: { width: Math.min(100, daily > 0 ? Math.round(spent / daily * 100) : 100) + '%' } })) : null,
|
|
303
|
+
h('div', { className: 'dw-muted', style: { marginTop: 4 } }, '只算家里;按 DeepSeek 官方价与峰谷时段估算。超过后提醒她一次。'),
|
|
304
|
+
h('div', { className: 'dw-setting' },
|
|
305
|
+
h('input', { type: 'text', inputMode: 'decimal', placeholder: '每天额度(元),留空不限', value: draft, onChange: function (e) { setDraft(e.target.value); setMsg('') } }),
|
|
306
|
+
h('button', { className: 'dw-btn', onClick: save }, '保存')),
|
|
307
|
+
h(Status, { msg: msg }))
|
|
308
|
+
}
|
|
309
|
+
/** 记忆块带最近几轮:默认 200,下次开始对话或压缩之后生效。 */
|
|
310
|
+
function Memory(props) {
|
|
311
|
+
var mem = props.mem, window_ = mem && mem.windowTurns || 200
|
|
312
|
+
var activeScope = mem && mem.archiveScope || 'workspace'
|
|
313
|
+
var scopeNames = { home: '仅家会话', workspace: '家所在工作区' }
|
|
314
|
+
var scopeState = useState(mem && mem.selectedArchiveScope || activeScope), scope = scopeState[0], setScope = scopeState[1]
|
|
315
|
+
var draftState = useState(String(window_)), draft = draftState[0], setDraft = draftState[1]
|
|
316
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
317
|
+
function save() {
|
|
318
|
+
var text = String(draft).trim(), value = text === '' ? null : Number(text)
|
|
319
|
+
if (value !== null && !(Number.isInteger(value) && value >= 1)) { setMsg('请填一个不小于 1 的整数,留空恢复默认 200'); return }
|
|
320
|
+
post('memory', { turns: value }).then(function () { setMsg('已保存。下次开始对话或压缩之后生效。'); if (value === null) setDraft('200'); if (props.onSaved) props.onSaved() }, failedTo(setMsg))
|
|
321
|
+
}
|
|
322
|
+
function saveScope() {
|
|
323
|
+
post('archive-scope', { scope: scope }).then(function (result) {
|
|
324
|
+
setMsg(result.restartRequired ? '已保存。请重启 DSH,启动后按新范围和消息时间重建记忆块。' : '归档范围已保存。')
|
|
325
|
+
if (props.onSaved) props.onSaved()
|
|
326
|
+
}, failedTo(setMsg))
|
|
327
|
+
}
|
|
328
|
+
return h(Card, { title: '记忆', delay: 180 }, mem ? [
|
|
329
|
+
h('div', { key: 'm' }, h('span', { className: 'dw-big' }, mem.turns), h('span', { className: 'dw-muted' }, ' / ' + window_ + ' 轮')),
|
|
330
|
+
h('div', { key: 'b', className: 'dw-meter' }, h('i', { style: { width: Math.min(100, Math.round((mem.turns || 0) / window_ * 100)) + '%' } })),
|
|
331
|
+
h('div', { key: 'd', className: 'dw-muted' }, '约 ' + mem.approxTokens + ' token · 归档 ' + mem.records + ' 条 · 来自 ' + mem.sessions + ' 个会话'),
|
|
332
|
+
h('div', { key: 'active', className: 'dw-muted' }, '当前归档:' + scopeNames[activeScope]),
|
|
333
|
+
h('div', { key: 'scope', className: 'dw-setting' },
|
|
334
|
+
h('select', { value: scope, 'aria-label': '记忆归档范围', onChange: function (e) { setScope(e.target.value); setMsg('') } },
|
|
335
|
+
h('option', { value: 'home' }, '仅家会话'), h('option', { value: 'workspace' }, '家所在工作区')),
|
|
336
|
+
h('button', { className: 'dw-btn', onClick: saveScope }, '保存范围')),
|
|
337
|
+
mem.restartRequired ? h('div', { key: 'restart', className: 'dw-muted', role: 'status' }, '范围已修改,请重启 DSH。重启前继续使用当前范围。') : null,
|
|
338
|
+
h('div', { key: 's', className: 'dw-setting' },
|
|
339
|
+
h('input', { type: 'text', inputMode: 'numeric', 'aria-label': '记忆带最近几轮', placeholder: '最近几轮,留空为 200', value: draft, onChange: function (e) { setDraft(e.target.value); setMsg('') } }),
|
|
340
|
+
h('button', { className: 'dw-btn', onClick: save }, '保存')),
|
|
341
|
+
h(Status, { key: 'x', msg: msg }),
|
|
342
|
+
] : h('div', { className: 'dw-muted' }, '—'))
|
|
343
|
+
}
|
|
344
|
+
function WorkspacePermission(props) {
|
|
345
|
+
var workspace = props.workspace, permission = workspace && workspace.defaultPermission
|
|
346
|
+
var selectionState = useState({ saved: permission, draft: permission }), selection = selectionState[0], setSelection = selectionState[1]
|
|
347
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
348
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
349
|
+
useEffect(function () {
|
|
350
|
+
setSelection(function (current) { return current.saved === permission ? current : { saved: permission, draft: current.draft === current.saved ? permission : current.draft } })
|
|
351
|
+
}, [permission])
|
|
352
|
+
if (!workspace) return null
|
|
353
|
+
var draft = selection.draft, selected = workspace.options.find(function (option) { return option.value === draft })
|
|
354
|
+
function save() {
|
|
355
|
+
setBusy(true)
|
|
356
|
+
post('workspace-permission', { permission: draft }).then(function () {
|
|
357
|
+
setSelection({ saved: draft, draft: draft }); setMsg('已保存。新建会话将使用所选权限。')
|
|
358
|
+
if (props.onSaved) props.onSaved()
|
|
359
|
+
}, failedTo(setMsg)).then(function () { setBusy(false) })
|
|
360
|
+
}
|
|
361
|
+
return h(Card, { title: '工作区权限' },
|
|
362
|
+
h('div', { className: 'dw-muted' }, '仅用于此工作区新建的会话;已有会话保留各自的权限。'),
|
|
363
|
+
h('div', { className: 'dw-setting' },
|
|
364
|
+
h('select', { value: draft, disabled: busy, 'aria-label': '新建会话默认权限', onChange: function (e) { setSelection({ saved: selection.saved, draft: e.target.value }); setMsg('') } },
|
|
365
|
+
workspace.options.map(function (option) { return h('option', { key: option.value, value: option.value, title: option.description }, option.name) })),
|
|
366
|
+
h('button', { className: 'dw-btn', disabled: busy || draft === selection.saved || !selected, onClick: save }, busy ? '保存中…' : '保存')),
|
|
367
|
+
selected && selected.description ? h('div', { className: 'dw-muted' }, selected.description) : null,
|
|
368
|
+
h(Status, { msg: msg }))
|
|
369
|
+
}
|
|
370
|
+
/** 回顾之后是否自动应用她改过的“我是谁”:开关即存,不需要再点保存。 */
|
|
371
|
+
function CompactAfterReview(props) {
|
|
372
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
373
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
374
|
+
function toggle(on) {
|
|
375
|
+
setBusy(true)
|
|
376
|
+
post('compact-after-review', { on: on }).then(function () {
|
|
377
|
+
setMsg(on ? '已开启。每晚回顾后会自动应用并压缩家会话。' : '已关闭。“我是谁”要等下一次压缩才生效。')
|
|
378
|
+
if (props.onSaved) props.onSaved()
|
|
379
|
+
}, failedTo(setMsg)).then(function () { setBusy(false) })
|
|
380
|
+
}
|
|
381
|
+
return h(Card, { title: '回顾后自动压缩' },
|
|
382
|
+
h('div', { className: 'dw-muted' }, '每晚回顾结束、家空闲后,自动应用并压缩一次家会话,让她刚改写的“我是谁”生效;压缩后最近的聊天会重新放回她眼前。'),
|
|
383
|
+
h('label', { className: 'dw-setting' },
|
|
384
|
+
h('input', { type: 'checkbox', checked: props.on, disabled: busy, 'aria-label': '回顾后自动压缩', onChange: function (e) { toggle(e.target.checked) } }),
|
|
385
|
+
' ', props.on ? '已开启' : '已关闭'),
|
|
386
|
+
h(Status, { msg: msg }))
|
|
387
|
+
}
|
|
388
|
+
/** 每日回顾和早上兜底的时间:留空恢复默认;保存后已排好的回顾和早上闹钟立刻改到新时间。 */
|
|
389
|
+
function Schedule(props) {
|
|
390
|
+
var s = props.schedule
|
|
391
|
+
var reviewState = useState(s.review), review = reviewState[0], setReview = reviewState[1]
|
|
392
|
+
var wakeState = useState(s.wake), wake = wakeState[0], setWake = wakeState[1]
|
|
393
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
394
|
+
function save() {
|
|
395
|
+
var values = [String(review).trim(), String(wake).trim()]
|
|
396
|
+
if (values.some(function (v) { return v !== '' && !/^([01]\d|2[0-3]):[0-5]\d$/.test(v) })) { setMsg('请填 HH:MM 格式的时间(00:00–23:59),留空恢复默认'); return }
|
|
397
|
+
post('schedule', { review: values[0] || null, wake: values[1] || null }).then(function () {
|
|
398
|
+
if (!values[0]) setReview(s.defaults.review); if (!values[1]) setWake(s.defaults.wake)
|
|
399
|
+
setMsg('已保存。已排好的回顾和早上闹钟已改到新时间,她自己定的闹钟不变。')
|
|
400
|
+
if (props.onSaved) props.onSaved()
|
|
401
|
+
}, failedTo(setMsg))
|
|
402
|
+
}
|
|
403
|
+
return h(Card, { title: '作息' },
|
|
404
|
+
h('div', { className: 'dw-muted' }, '每日回顾:她回头看一天、写日记的时间,定在中午以前就回顾前一天。早上:她没定闹钟时醒来的时间。留空恢复默认(回顾 ' + s.defaults.review + ',早上 ' + s.defaults.wake + ')。'),
|
|
405
|
+
h('div', { className: 'dw-setting' },
|
|
406
|
+
h('label', null, '每日回顾 ', h('input', { type: 'time', 'aria-label': '每日回顾时间', value: review, onChange: function (e) { setReview(e.target.value); setMsg('') } })),
|
|
407
|
+
h('label', null, '早上 ', h('input', { type: 'time', 'aria-label': '早上醒来时间', value: wake, onChange: function (e) { setWake(e.target.value); setMsg('') } })),
|
|
408
|
+
h('button', { className: 'dw-btn', onClick: save }, '保存')),
|
|
409
|
+
h('div', { className: 'dw-muted' }, '她看到的工具说明里写的早上时间,要等新开的会话或重启 DSH 后才更新。'),
|
|
410
|
+
h(Status, { msg: msg }))
|
|
411
|
+
}
|
|
412
|
+
/** 微信:适配器每约 2 秒来问一次,最近一次来问的时间就是连接状态;两个读取参数在它下次来问时同步。 */
|
|
413
|
+
function Wechat(props) {
|
|
414
|
+
var w = props.wechat, zone = props.zone
|
|
415
|
+
var contextState = useState(String(w.contextMessages)), context = contextState[0], setContext = contextState[1]
|
|
416
|
+
var bufferState = useState(String(w.bufferSeconds)), buffer = bufferState[0], setBuffer = bufferState[1]
|
|
417
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
418
|
+
var age = w.lastContactAt ? Date.now() - new Date(w.lastContactAt).getTime() : null
|
|
419
|
+
var contacted = age != null && age < 30000, offline = contacted && w.account === 'offline'
|
|
420
|
+
var ad = w.adapter
|
|
421
|
+
var blocked = ad && ad.needsHuman
|
|
422
|
+
var stateText = blocked ? '● 有消息待核对,适配器已停' : !contacted ? (ad && ad.building ? '● 正在重新构建原生桥' : ad && ad.running ? '● 适配器启动中' : ad && ad.error ? '● 适配器没能启动' : w.lastContactAt ? '● 适配器已断开' : '● 等待适配器') : offline ? '● 微信离线,等待重新登录' : '● 已连接'
|
|
423
|
+
var adMsgState = useState(''), adMsg = adMsgState[0], setAdMsg = adMsgState[1]
|
|
424
|
+
function restartAdapter() {
|
|
425
|
+
setAdMsg('正在重启…')
|
|
426
|
+
post('wechat-adapter', {}).then(function () { setAdMsg('已重启'); if (props.onSaved) props.onSaved() }, function (e) { setAdMsg('重启失败:' + (e.message || e)) })
|
|
427
|
+
}
|
|
428
|
+
function save() {
|
|
429
|
+
var c = String(context).trim() === '' ? null : Number(context), b = String(buffer).trim() === '' ? null : Number(buffer)
|
|
430
|
+
if (c !== null && !(Number.isInteger(c) && c >= 1 && c <= 20)) { setMsg('请填 1–20 的整数,留空恢复默认 8'); return }
|
|
431
|
+
if (b !== null && !(b >= 0 && b <= 30)) { setMsg('请填 0–30 秒,留空恢复默认 3'); return }
|
|
432
|
+
post('wechat', { contextMessages: c, bufferSeconds: b }).then(function () {
|
|
433
|
+
setMsg('已保存。适配器下次轮询时同步,当前这一批沿用原值。')
|
|
434
|
+
if (c === null) setContext('8'); if (b === null) setBuffer('3')
|
|
435
|
+
if (props.onSaved) props.onSaved()
|
|
436
|
+
}, failedTo(setMsg))
|
|
437
|
+
}
|
|
438
|
+
return h(Card, { title: '微信', delay: 300 },
|
|
439
|
+
h('div', null, h('span', { className: 'dw-big ' + (contacted && !offline ? 'dw-ok' : 'dw-bad') }, stateText)),
|
|
440
|
+
KV([
|
|
441
|
+
['最近联系', w.lastContactAt ? local(w.lastContactAt, zone) : '—'],
|
|
442
|
+
['绑定账号', w.accountId || '—'],
|
|
443
|
+
ad ? ['适配器', ad.running ? '由插件管理 · 运行中' + (ad.restarts ? '(已重启 ' + ad.restarts + ' 次)' : '') : '由插件管理 · 已退出' + (ad.error ? ':' + ad.error : ad.lastExit ? '(' + ad.lastExit + '),等待重启' : '')] : null,
|
|
444
|
+
['聊天', w.accountId ? w.chats + ' 个' : '—'],
|
|
445
|
+
['待发送', String(w.pending)],
|
|
446
|
+
['待核对', h('span', { className: w.uncertain ? 'dw-bad' : '' }, String(w.uncertain))],
|
|
447
|
+
]),
|
|
448
|
+
w.uncertain ? h('div', { className: 'dw-muted' }, '发送结果不明的消息不会自动重发,请在微信里核对后用适配器 acknowledge 确认。') : null,
|
|
449
|
+
blocked ? h('div', { className: 'dw-bad' }, '上次有消息处理到一半、结果不明。先在微信里核对是否真的发出,再用适配器的 acknowledge 确认(见适配器 README),然后点下面的重启。') : null,
|
|
450
|
+
ad ? h('div', { className: 'dw-bar' }, h('button', { className: 'dw-btn', onClick: restartAdapter }, '重启适配器'), adMsg ? h('span', { className: adMsg.indexOf('失败') >= 0 ? 'dw-bad' : 'dw-muted' }, adMsg) : null) : null,
|
|
451
|
+
h('div', { className: 'dw-setting' },
|
|
452
|
+
h('input', { type: 'text', inputMode: 'numeric', 'aria-label': '群聊读取上文条数', placeholder: '上文条数,默认 8', value: context, onChange: function (e) { setContext(e.target.value); setMsg('') } }),
|
|
453
|
+
h('input', { type: 'text', inputMode: 'decimal', 'aria-label': '消息缓冲秒数', placeholder: '缓冲秒数,默认 3', value: buffer, onChange: function (e) { setBuffer(e.target.value); setMsg('') } }),
|
|
454
|
+
h('button', { className: 'dw-btn', onClick: save }, '保存')),
|
|
455
|
+
h('div', { className: 'dw-muted' }, '上文按消息条数算(群聊被 @ 时带上之前几条);缓冲是收到消息后等对方说完的秒数:同一个人在这段时间里又发来消息就重新计时,安静下来再合成一条交给她(最长等 30 秒),0 = 不等。与共享记忆的 200 轮无关。'),
|
|
456
|
+
h(Status, { msg: msg }))
|
|
457
|
+
}
|
|
458
|
+
/** QQ:她自己那条 OneBot 通道(原生),以及 SnowLuma 控制台的入口。 */
|
|
459
|
+
function Qq(props) {
|
|
460
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
461
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
462
|
+
// 两个控制台都带 X-Frame-Options: DENY,塞不进 iframe,所以交给系统浏览器开。
|
|
463
|
+
// 地址和令牌由宿主半侧现给(/dsh-world/qq/console),所以打开就是登录态。
|
|
464
|
+
function openDoor(kind) {
|
|
465
|
+
var label = 'SnowLuma'
|
|
466
|
+
setBusy(true); setMsg('')
|
|
467
|
+
qqGet('console').then(function (res) {
|
|
468
|
+
var door = res && res[kind]
|
|
469
|
+
// 还差密码的门也带着地址,先认这件事,别把登录页当成品打开。
|
|
470
|
+
if (door && door.needs === 'password') { if (props.onNeedPassword) props.onNeedPassword(kind); return null }
|
|
471
|
+
if (door && door.url) {
|
|
472
|
+
return qqPost('open', { kind: kind }).then(function (r) {
|
|
473
|
+
setMsg(r && r.opened ? '已在浏览器打开 ' + label + ' 控制台' : '失败:' + ((r && r.error) || '打不开'))
|
|
474
|
+
})
|
|
475
|
+
}
|
|
476
|
+
setMsg('失败:' + ((door && door.error) || '宿主没给地址'))
|
|
477
|
+
return null
|
|
478
|
+
}, function (e) { setMsg('失败:' + ((e && e.message) || e)) }).then(function () { setBusy(false) })
|
|
479
|
+
}
|
|
480
|
+
/** 改通道的开关:一次给的几项一起生效;`done` 拿到通道的新状态,说一句结果。 */
|
|
481
|
+
function change(body, done) {
|
|
482
|
+
setBusy(true); setMsg('')
|
|
483
|
+
qqPost('native', body).then(function (state) {
|
|
484
|
+
setMsg(done ? done(state) : '')
|
|
485
|
+
if (props.onSaved) props.onSaved()
|
|
486
|
+
}, function (e) { setMsg('失败:' + ((e && e.message) || e)) }).then(function () { setBusy(false) })
|
|
487
|
+
}
|
|
488
|
+
// 阳台:拨端口就是开关(0 是关)。
|
|
489
|
+
function flipBridge(port) { change({ bridge: { port: port } }) }
|
|
490
|
+
function flipNative(autoReply) { change({ autoReply: autoReply }) }
|
|
491
|
+
// 静默:给一个时间点,到点前只收不回,到点自己醒;null 立刻恢复。
|
|
492
|
+
var muteState = useState(''), muteAt = muteState[0], setMuteAt = muteState[1]
|
|
493
|
+
function muteUntil(local) {
|
|
494
|
+
var at = new Date(local)
|
|
495
|
+
if (isNaN(at.getTime())) { setMsg('这个时间看不懂,重挑一下'); return }
|
|
496
|
+
change({ mutedUntil: at.toISOString() })
|
|
497
|
+
}
|
|
498
|
+
// 合批窗口:同一个人在这么多秒内连发几句,合成一次问。填 0 就是每句单独回。
|
|
499
|
+
var quietState = useState(''), quiet = quietState[0], setQuiet = quietState[1]
|
|
500
|
+
useEffect(function () {
|
|
501
|
+
var ms = props.native && typeof props.native.batchQuietMs === 'number' ? String(Math.round(props.native.batchQuietMs / 1000)) : ''
|
|
502
|
+
setQuiet(function (cur) { return cur === '' ? ms : cur })
|
|
503
|
+
}, [props.native && props.native.batchQuietMs])
|
|
504
|
+
function saveQuiet() {
|
|
505
|
+
var sec = Number(String(quiet).trim())
|
|
506
|
+
if (!isFinite(sec) || sec < 0 || sec > 30) { setMsg('填 0 到 30 之间的秒数(一批最多等 30 秒)'); return }
|
|
507
|
+
change({ batchQuietMs: Math.round(sec * 1000) })
|
|
508
|
+
}
|
|
509
|
+
// 白名单:谁的话能进来。打开时填上现有的名单,之后不覆盖正在改的字。
|
|
510
|
+
var ids = props.native ? [(props.native.allowPrivateIds || []).join(', '), (props.native.allowGroupsIds || []).join(', ')] : ['', '']
|
|
511
|
+
var allowState = useState({ from: '', people: '', groups: '' }), allow = allowState[0], setAllow = allowState[1]
|
|
512
|
+
useEffect(function () {
|
|
513
|
+
var from = ids.join('|')
|
|
514
|
+
setAllow(function (current) { return current.from === from ? current : { from: from, people: ids[0], groups: ids[1] } })
|
|
515
|
+
}, [ids[0], ids[1]])
|
|
516
|
+
function saveAllow() {
|
|
517
|
+
function split(text) { return String(text).split(/[\s,,、;;]+/).filter(Boolean) }
|
|
518
|
+
var people = split(allow.people), groups = split(allow.groups), wrong = people.concat(groups).find(function (id) { return !/^[0-9]+$/.test(id) })
|
|
519
|
+
if (wrong) { setMsg('请填 QQ 号:「' + wrong + '」不是号码'); return }
|
|
520
|
+
change({ allowPrivate: people, allowGroups: groups }, function () { return people.length || groups.length ? '名单存好了:私聊 ' + people.length + ' 个、群 ' + groups.length + ' 个' : '名单存好了:现在谁的话都不收' })
|
|
521
|
+
}
|
|
522
|
+
function startSnowluma() {
|
|
523
|
+
change({ startSnowluma: true }, function (state) {
|
|
524
|
+
var r = state && state.launch
|
|
525
|
+
if (!r || !r.started) return '没起来:' + ((r && r.error) || '原因不明')
|
|
526
|
+
return '已经让 SnowLuma 起来' + (r.how === 'spawn' ? '(直接起的,这条线只活到 DSH 退出)' : '') + (r.error ? ';' + r.error : '')
|
|
527
|
+
})
|
|
528
|
+
}
|
|
529
|
+
function copyLine(text) {
|
|
530
|
+
if (!text) { setMsg('这条命令还没生出来'); return }
|
|
531
|
+
if (!navigator.clipboard) { setMsg('这个浏览器不给复制,自己选上面那行'); return }
|
|
532
|
+
navigator.clipboard.writeText(text).then(function () { setMsg('命令已复制') }, function () { setMsg('复制失败,自己选上面那行') })
|
|
533
|
+
}
|
|
534
|
+
return h(Card, { title: 'QQ', delay: 240 }, [
|
|
535
|
+
props.native ? (function (n) {
|
|
536
|
+
if (!n) return h('div', { key: 'n', className: 'dw-muted' }, '她自己的通道:没开')
|
|
537
|
+
return h('div', { key: 'n' }, [
|
|
538
|
+
h('span', { key: 'a', className: n.connected ? 'dw-ok' : 'dw-muted' }, n.connected ? '● 她自己连着 ' + n.url : '● 她自己的通道没连上'),
|
|
539
|
+
h('span', { key: 'b', className: 'dw-muted' }, ' · 收 ' + (n.conversations || 0) + ' 个会话 · 发 ' + (n.sent || 0) + ' 条' + (n.failed ? ' · 失败 ' + n.failed : '') + (n.outbox ? ' · 排队待发 ' + n.outbox : '') + (n.blocked ? ' · 挡下 ' + n.blocked : '') + (n.autoReply ? ' · 会自己回' : ' · 只看不回')),
|
|
540
|
+
n.lastError ? h('span', { key: 'c', className: 'dw-bad' }, ' · ' + n.lastError) : null,
|
|
541
|
+
])
|
|
542
|
+
})(props.native) : h('div', { key: 'n', className: 'dw-muted' }, '她自己的通道:没开(配置里 qqNative.enabled)'),
|
|
543
|
+
(function (n) {
|
|
544
|
+
if (!n) return null
|
|
545
|
+
return h('label', { key: 'nt', className: 'dw-setting', style: { cursor: 'pointer' } }, [
|
|
546
|
+
h('input', { key: 'c', type: 'checkbox', checked: n.autoReply === true, disabled: busy,
|
|
547
|
+
onChange: function (e) { flipNative(e.target.checked) } }),
|
|
548
|
+
h('span', { key: 't' }, n.autoReply === true ? ' 会自己回话' : ' 只看不回'),
|
|
549
|
+
])
|
|
550
|
+
})(props.native),
|
|
551
|
+
(function (n) {
|
|
552
|
+
if (!n) return null
|
|
553
|
+
var ms = typeof n.batchQuietMs === 'number' ? n.batchQuietMs : 10000
|
|
554
|
+
return h('div', { key: 'quiet', className: 'dw-setting' }, [
|
|
555
|
+
h('span', { key: 's', className: 'dw-muted' }, ms ? '连着发几句:' + (ms / 1000) + ' 秒内合成一次问' : '连着发几句:每句单独回'),
|
|
556
|
+
h('input', { key: 'i', type: 'number', min: 0, max: 30, step: 1, 'aria-label': '合批窗口(秒)', style: { width: 64 }, disabled: busy, value: quiet, onChange: function (e) { setQuiet(e.target.value) } }),
|
|
557
|
+
h('button', { key: 'b', className: 'dw-btn', disabled: busy, onClick: saveQuiet }, '存'),
|
|
558
|
+
])
|
|
559
|
+
})(props.native),
|
|
560
|
+
(function (n) {
|
|
561
|
+
if (!n) return null
|
|
562
|
+
return h('div', { key: 'mute', className: 'dw-setting' }, [
|
|
563
|
+
h('span', { key: 's', className: n.mutedUntil ? 'dw-bad' : 'dw-muted' }, n.mutedUntil ? '静默到 ' + new Date(n.mutedUntil).toLocaleString() + '(只收不回)' : '现在会出声'),
|
|
564
|
+
h('input', { key: 'i', type: 'datetime-local', 'aria-label': '静默到', disabled: busy, value: muteAt, onChange: function (e) { setMuteAt(e.target.value) } }),
|
|
565
|
+
h('button', { key: 'b', className: 'dw-btn', disabled: busy || !muteAt, onClick: function () { muteUntil(muteAt) } }, '静默到这个点'),
|
|
566
|
+
n.mutedUntil ? h('button', { key: 'r', className: 'dw-btn', disabled: busy, onClick: function () { change({ mutedUntil: null }) } }, '立刻恢复') : null,
|
|
567
|
+
])
|
|
568
|
+
})(props.native),
|
|
569
|
+
props.native ? h('div', { key: 'allow', className: 'dw-setting' }, [
|
|
570
|
+
h('input', { key: 'p', type: 'text', 'aria-label': '私聊白名单', placeholder: '私聊 QQ 号', disabled: busy, value: allow.people, onChange: function (e) { setAllow({ from: allow.from, people: e.target.value, groups: allow.groups }) } }),
|
|
571
|
+
h('input', { key: 'g', type: 'text', 'aria-label': '群白名单', placeholder: '群号', disabled: busy, value: allow.groups, onChange: function (e) { setAllow({ from: allow.from, people: allow.people, groups: e.target.value }) } }),
|
|
572
|
+
h('button', { key: 'b', className: 'dw-btn', disabled: busy, onClick: saveAllow }, '存名单'),
|
|
573
|
+
h('div', { key: 'h', className: 'dw-muted', style: { width: '100%' } }, '多个用逗号隔开;留空就是谁的话都不收。改完不用重启。'),
|
|
574
|
+
]) : null,
|
|
575
|
+
(function (n) {
|
|
576
|
+
if (!n) return null
|
|
577
|
+
var b = n.bridge
|
|
578
|
+
if (!b) return h('div', { key: 'nb', className: 'dw-setting' }, [
|
|
579
|
+
h('span', { key: 's', className: 'dw-muted' }, '阳台:关着(要用就在这儿打开)'),
|
|
580
|
+
h('button', { key: 'b', className: 'dw-btn', disabled: busy, onClick: function () { flipBridge(3210) } }, '开这条线(3210)'),
|
|
581
|
+
])
|
|
582
|
+
return h('div', { key: 'nb' }, [
|
|
583
|
+
h('div', { key: 'l', className: 'dw-muted' },
|
|
584
|
+
h('span', { className: b.serving ? 'dw-ok' : 'dw-muted' }, b.serving ? '● 阳台开着 ' + (b.url || '') : '● 阳台关着'),
|
|
585
|
+
' · ' + ((b.lines || 0) ? '连着 ' + b.lines + ' 条线' : '还没人敲门')
|
|
586
|
+
+ ' · 收了 ' + (b.received || 0) + ' 句、回了 ' + (b.relayed || 0) + ' 句、她开口 ' + (b.spoken || 0) + ' 次'),
|
|
587
|
+
b.lastError ? h('div', { key: 'e', className: 'dw-bad' }, ' · ' + b.lastError) : null,
|
|
588
|
+
h('div', { key: 'c', className: 'dw-muted', style: { wordBreak: 'break-all', fontSize: 12 } }, b.line || ''),
|
|
589
|
+
h('div', { key: 'y', className: 'dw-setting' }, [
|
|
590
|
+
h('button', { key: 'c', className: 'dw-btn', disabled: busy, onClick: function () { copyLine(b.line) } }, '复制这条命令'),
|
|
591
|
+
h('button', { key: 'x', className: 'dw-btn', disabled: busy, onClick: function () { flipBridge(0) } }, '关掉这条线'),
|
|
592
|
+
]),
|
|
593
|
+
])
|
|
594
|
+
})(props.native),
|
|
595
|
+
(function (sv) {
|
|
596
|
+
if (!sv) return null
|
|
597
|
+
return h('div', { key: 'sv', className: sv.lastError ? 'dw-bad' : 'dw-muted' },
|
|
598
|
+
(sv.watching ? '● 看门狗盯着' : '○ 看门狗没开') + (sv.lastCheckAt ? ' · SnowLuma ' + (sv.alive ? '通着' : '不通') : '')
|
|
599
|
+
+ (sv.restarts ? ' · 已拉起 ' + sv.restarts + ' 次' : '') + (sv.lastError ? ' · ' + sv.lastError : ''))
|
|
600
|
+
})(props.native && props.native.supervisor),
|
|
601
|
+
h('div', { key: 'k', className: 'dw-setting' },
|
|
602
|
+
h('button', { className: 'dw-btn', disabled: busy, onClick: function () { openDoor('snowluma') } }, '打开 SnowLuma 控制台'),
|
|
603
|
+
props.native ? h('button', { className: 'dw-btn', disabled: busy, onClick: startSnowluma }, '拉起 SnowLuma') : null),
|
|
604
|
+
h('div', { key: 'b', className: 'dw-setting' },
|
|
605
|
+
h('button', { className: 'dw-btn', disabled: busy, onClick: function () { if (props.onSaved) props.onSaved() } }, '刷新')),
|
|
606
|
+
h(Status, { key: 'x', msg: msg }),
|
|
607
|
+
])
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* 第一次打开 SnowLuma 控制台时,得先用面板密码换一个会话令牌:那令牌只活在那边的进程内存里,重启就没了。
|
|
611
|
+
* 密码不在浏览器里存着,填完就交给宿主半侧,换到令牌后由宿主把系统浏览器拉起来。
|
|
612
|
+
* 两个控制台都发 X-Frame-Options: DENY,塞不进 iframe,所以只能这样开。
|
|
613
|
+
*/
|
|
614
|
+
function Panel(props) {
|
|
615
|
+
var passState = useState(''), pass = passState[0], setPass = passState[1]
|
|
616
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
617
|
+
var errState = useState(''), err = errState[0], setErr = errState[1]
|
|
618
|
+
function signIn() {
|
|
619
|
+
if (!pass) { setErr('先填密码'); return }
|
|
620
|
+
setBusy(true); setErr('')
|
|
621
|
+
qqPost('panel-password', { password: pass }).then(function (body) {
|
|
622
|
+
var next = body && body.snowluma
|
|
623
|
+
if (!next || !next.url) { setErr((next && next.error) || '登录失败'); return null }
|
|
624
|
+
setPass('')
|
|
625
|
+
return qqPost('open', { kind: 'snowluma' }).then(function (r) {
|
|
626
|
+
if (r && r.opened) { if (props.onClose) props.onClose() } else setErr((r && r.error) || '打不开浏览器')
|
|
627
|
+
})
|
|
628
|
+
}, function (e) { setErr(String((e && e.message) || e)) }).then(function () { setBusy(false) })
|
|
629
|
+
}
|
|
630
|
+
return h('div', { style: { position: 'fixed', left: 0, top: 0, width: '100%', height: '100%', zIndex: 60, background: 'rgba(10,14,20,.66)', display: 'flex', alignItems: 'center', justifyContent: 'center' } },
|
|
631
|
+
h('div', { style: { width: 480, maxWidth: '92%', background: '#141b25', border: '1px solid rgba(255,255,255,.1)', borderRadius: 12, padding: 20, boxSizing: 'border-box' } },
|
|
632
|
+
h('h3', { style: { margin: '0 0 8px', color: '#e8edf4' } }, '第一次打开 SnowLuma 控制台'),
|
|
633
|
+
h('div', { className: 'dw-muted', style: { marginBottom: 16, lineHeight: 1.6 } }, '它只认密码、没有账号名这回事;会话令牌只存在进程内存里,过期就没了,所以要用面板密码换一次。密码留在你这台机器上,不会回传浏览器。'),
|
|
634
|
+
h('label', { style: { display: 'block', marginBottom: 16, color: '#c7d2de' } }, '密码 ',
|
|
635
|
+
h('input', { type: 'password', value: pass, onChange: function (e) { setPass(e.target.value) }, onKeyDown: function (e) { if (e.key === 'Enter') signIn() }, style: { width: 220 } })),
|
|
636
|
+
err ? h('div', { className: 'dw-bad', style: { marginBottom: 12 } }, '● ' + err) : null,
|
|
637
|
+
h('button', { className: 'dw-btn', disabled: busy, onClick: signIn }, busy ? '……' : '登录并打开'),
|
|
638
|
+
h('button', { className: 'dw-btn', style: { marginLeft: 10 }, onClick: function () { if (props.onClose) props.onClose() } }, '取消')))
|
|
639
|
+
}
|
|
640
|
+
/** 接入:微信和 QQ 各一个开关,关闭即撤下通道,状态记在 world.json。 */
|
|
641
|
+
function Modules(props) {
|
|
642
|
+
var m = props.modules
|
|
643
|
+
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
644
|
+
var busyState = useState(''), busy = busyState[0], setBusy = busyState[1]
|
|
645
|
+
function flip(name, value) {
|
|
646
|
+
var body = {}; body[name] = value
|
|
647
|
+
setBusy(name); setMsg('')
|
|
648
|
+
post('modules', body).then(function (result) { setBusy(''); if (result.message) setMsg(result.message); if (props.onSaved) props.onSaved() }, function (e) { setBusy(''); setMsg('切换失败:' + (e.message || e)) })
|
|
649
|
+
}
|
|
650
|
+
function row(name, label, info, onText, offText) {
|
|
651
|
+
var state = busy === name ? (name === 'qq' ? '正在检查或安装 SDK…' : '切换中…') : !info.available ? '未配置' : info.restartRequired ? 'SDK 已安装,请重启 DSH' : !info.enabled ? '已关闭' : info.running ? '运行中' : props.running ? '启动中' : '已开启,世界启动后生效'
|
|
652
|
+
return h('div', { key: name, className: 'dw-setting' },
|
|
653
|
+
h('span', null, h('b', null, label), h('span', { className: 'dw-muted' }, ' · ' + state)),
|
|
654
|
+
h('button', { className: 'dw-btn', disabled: !info.available || busy === name, onClick: function () { flip(name, !info.enabled) } }, info.enabled ? '关闭' : '开启'),
|
|
655
|
+
h('div', { className: 'dw-muted', style: { flexBasis: '100%' } }, info.enabled ? onText : offText))
|
|
656
|
+
}
|
|
657
|
+
return h(Card, { title: '接入', delay: 270 },
|
|
658
|
+
row('wechat', '微信', m.wechat, '已注册 wechat_chats、wechat_history、wechat_send、wechat_delivery,可先看群聊再发言,并随之启动适配器。关闭会撤掉它们并停掉适配器。', '工具未注册,适配器已停。开启后立即注册,无需重启。'),
|
|
659
|
+
row('qq', 'QQ', m.qq, '插件自己直连 OneBot:状态和设置在 QQ 页面。关闭就断开这条通道。', '开启时检查 SDK;缺少时按需安装并提示重启 DSH。'),
|
|
660
|
+
msg ? h('div', { className: msg.indexOf('失败') >= 0 ? 'dw-bad' : 'dw-muted', role: 'status' }, msg) : null)
|
|
661
|
+
}
|
|
662
|
+
function Overview(props) {
|
|
663
|
+
var snap = props.snap, zone = snap.timeZone, life = snap.life, alarm = life && life.alarm, mem = snap.memory
|
|
664
|
+
var health = list(snap.health), wakes = life ? list(life.recentWakes) : []
|
|
665
|
+
var welcome = !snap.running && !life
|
|
666
|
+
return h('div', { className: 'dw-pane' },
|
|
667
|
+
welcome ? h(Card, null, h('div', { className: 'dw-welcome' },
|
|
668
|
+
h('h3', null, '她还没有住进来'),
|
|
669
|
+
h('div', { className: 'dw-muted' }, '先写下她是谁,再按右上角的「开始」。'),
|
|
670
|
+
h('ol', { className: 'dw-steps' },
|
|
671
|
+
h('li', null, '在「人设」里写她的名字、性格和你对她的愿景'),
|
|
672
|
+
h('li', null, '需要的话,在「世界提示词」里写你想对她说的话'),
|
|
673
|
+
h('li', null, '按「开始」:插件建好她的房间和家,叫醒她')))) : null,
|
|
674
|
+
life ? h('div', { className: 'dw-grid' },
|
|
675
|
+
h(Card, { title: '此刻', delay: 0 },
|
|
676
|
+
h('div', { className: 'dw-big' }, statusLabel[life.status] || life.status),
|
|
677
|
+
alarm ? h('div', { style: { marginTop: 8 } }, h('span', { className: 'dw-muted' }, (sourceLabel[alarm.source] || '闹钟') + ' · '), local(alarm.at, zone), h('span', { className: 'dw-muted' }, '(还有 ' + remaining(alarm.at) + ')')) : h('div', { className: 'dw-muted' }, '没有待定的闹钟'),
|
|
678
|
+
alarm && alarm.note ? h('blockquote', { className: 'dw-quote' }, alarm.note) : null),
|
|
679
|
+
h(Card, { title: '家', delay: 60 }, KV([
|
|
680
|
+
['会话', String(life.homeSessionId || '还没有家').replace(/^session-/, '').slice(0, 8)],
|
|
681
|
+
['下次回顾', life.review ? local(life.review.at, zone) : '—'],
|
|
682
|
+
['最近', wakes.length ? h('div', { className: 'dw-trail' }, wakes.map(function (w, i) { return h('span', { key: i }, local(w.deliveredAt, zone) + ' ' + (sourceLabel[w.source] || w.source) + (w.lateMs >= 120000 ? ' · 晚 ' + Math.round(w.lateMs / 60000) + ' 分' : '')) })) : '—'],
|
|
683
|
+
]))) : null,
|
|
684
|
+
h('div', { className: 'dw-grid' },
|
|
685
|
+
h(Card, { title: '健康', delay: 120 }, health.length ? health.map(function (f, i) { return h('div', { key: i, className: 'dw-bad' }, '● ' + f) }) : h('div', { className: 'dw-ok' }, '● 一切正常')),
|
|
686
|
+
h(Memory, { mem: mem, onSaved: props.refresh }),
|
|
687
|
+
h(Budget, { budget: snap.budget, onSaved: props.refresh }),
|
|
688
|
+
snap.workspace ? h(WorkspacePermission, { workspace: snap.workspace, onSaved: props.refresh }) : null,
|
|
689
|
+
typeof snap.compactAfterReview === 'boolean' ? h(CompactAfterReview, { on: snap.compactAfterReview, onSaved: props.refresh }) : null,
|
|
690
|
+
snap.schedule ? h(Schedule, { schedule: snap.schedule, onSaved: props.refresh }) : null,
|
|
691
|
+
snap.modules && (snap.modules.wechat.available || snap.modules.qq.available) ? h(Modules, { modules: snap.modules, running: snap.running, onSaved: props.refresh }) : null))
|
|
692
|
+
}
|
|
693
|
+
function Records(props) {
|
|
694
|
+
var snap = props.snap, zone = snap.timeZone, life = snap.life, compactions = list(snap.compactions)
|
|
695
|
+
return h('div', { className: 'dw-pane' },
|
|
696
|
+
h(Activity, { days: list(snap.activityDays), zone: zone, tick: props.tick }),
|
|
697
|
+
h(Diary, { dates: list(snap.diaryDates) }),
|
|
698
|
+
h(Card, { title: '压缩' }, compactions.length ? h('table', null, h('tbody', null, compactions.map(function (c, i) {
|
|
699
|
+
return h('tr', { key: i }, h('td', { className: 'dw-muted' }, local(c.time, zone)), h('td', null, life && c.sessionId === life.homeSessionId ? '家' : String(c.sessionId || '').slice(-8)), h('td', { className: c.ok ? 'dw-ok' : 'dw-bad' }, c.ok ? '成功' : '失败:' + (c.error || '')), h('td', { className: 'dw-muted' }, c.shadowedTokens ? '缩掉约 ' + c.shadowedTokens + ' token' : ''))
|
|
700
|
+
}))) : h('div', { className: 'dw-muted' }, '还没有压缩记录')))
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** 只认最后一次发出的请求:条件变了,迟到的旧回复不能盖掉新结果。 */
|
|
704
|
+
function latest() {
|
|
705
|
+
var n = 0
|
|
706
|
+
return { next: function () { return ++n }, current: function (id) { return id === n } }
|
|
707
|
+
}
|
|
708
|
+
function searchMemory(guard, path, query, done, fail) {
|
|
709
|
+
var id = guard.next()
|
|
710
|
+
return api(path + '?' + query).then(function (b) { if (guard.current(id)) done(b) }, function (e) { if (guard.current(id)) fail(e) })
|
|
711
|
+
}
|
|
712
|
+
function zoneOffsetMs(at, zone) {
|
|
713
|
+
var parts = {}
|
|
714
|
+
new Intl.DateTimeFormat('en-US', { timeZone: zone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hourCycle: 'h23' }).formatToParts(new Date(at)).forEach(function (p) { parts[p.type] = p.value })
|
|
715
|
+
return Date.UTC(+parts.year, +parts.month - 1, +parts.day, +parts.hour, +parts.minute, +parts.second) - Math.floor(at / 1000) * 1000
|
|
716
|
+
}
|
|
717
|
+
/** 配置时区里某一天的零点,写成 UTC 的 ISO 时间;date 是 YYYY-MM-DD,plusDays 取后面的日子。 */
|
|
718
|
+
function dayStartIso(date, zone, plusDays) {
|
|
719
|
+
var guess = Date.parse(date + 'T00:00:00Z') + (plusDays || 0) * 86400000
|
|
720
|
+
var ms = guess - zoneOffsetMs(guess, zone)
|
|
721
|
+
ms = guess - zoneOffsetMs(ms, zone)
|
|
722
|
+
return new Date(ms).toISOString()
|
|
723
|
+
}
|
|
724
|
+
var KINDS = [['conversation', '聊天'], ['diary', '日记']]
|
|
725
|
+
var basisLabel = { message: '发言时间', diaryDate: '日记日期', fileObserved: '看到文件的时间' }
|
|
726
|
+
/** 筛选条件变成 memory/find 的查询串;结束日期含当天。 */
|
|
727
|
+
function memoryQuery(f, zone, cursor) {
|
|
728
|
+
var q = []
|
|
729
|
+
function add(k, v) { q.push(k + '=' + encodeURIComponent(v)) }
|
|
730
|
+
if (f.query) add('query', f.query)
|
|
731
|
+
if (f.kinds && f.kinds.length) add('kinds', f.kinds.join(','))
|
|
732
|
+
if (f.from) add('from', dayStartIso(f.from, zone))
|
|
733
|
+
if (f.to) add('to', dayStartIso(f.to, zone, 1))
|
|
734
|
+
if (f.sourceId) add('sourceId', f.sourceId)
|
|
735
|
+
if (f.turnId) add('turnId', f.turnId)
|
|
736
|
+
if (f.linkedTo) add('linkedTo', f.linkedTo)
|
|
737
|
+
if (f.order === 'oldest') add('order', 'oldest')
|
|
738
|
+
add('limit', '20')
|
|
739
|
+
if (cursor) add('cursor', cursor)
|
|
740
|
+
return q.join('&')
|
|
741
|
+
}
|
|
742
|
+
function MemorySearch(props) {
|
|
743
|
+
var zone = props.zone
|
|
744
|
+
var formState = useState({ query: '', kinds: [], from: '', to: '', sourceId: '', turnId: '', linkedTo: '', order: 'newest' }), form = formState[0], setForm = formState[1]
|
|
745
|
+
var resultState = useState(null), result = resultState[0], setResult = resultState[1]
|
|
746
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
747
|
+
var errState = useState(''), err = errState[0], setErr = errState[1]
|
|
748
|
+
var openState = useState(null), open = openState[0], setOpen = openState[1]
|
|
749
|
+
var guards = useRef(null)
|
|
750
|
+
if (!guards.current) guards.current = { find: latest(), read: latest() }
|
|
751
|
+
function change(patch) { setForm(Object.assign({}, form, patch)); setResult(null); setErr(''); guards.current.find.next() }
|
|
752
|
+
function run(next, cursor) {
|
|
753
|
+
setBusy(true); setErr('')
|
|
754
|
+
searchMemory(guards.current.find, 'memory/find', memoryQuery(next, zone, cursor), function (b) {
|
|
755
|
+
setBusy(false); setResult(cursor && result ? { items: result.items.concat(b.items), nextCursor: b.nextCursor, coverage: b.coverage, search: b.search } : b)
|
|
756
|
+
}, function (e) {
|
|
757
|
+
setBusy(false)
|
|
758
|
+
if (e && e.code === 'cursorExpired') { setResult(null); setErr('资料或范围有变化,请重新查询。') } else setErr('查找失败:' + (e.message || e))
|
|
759
|
+
})
|
|
760
|
+
}
|
|
761
|
+
function show(item, offset) {
|
|
762
|
+
setOpen({ ref: item.ref, title: item.title, loading: true, content: '' })
|
|
763
|
+
searchMemory(guards.current.read, 'memory/read', 'ref=' + encodeURIComponent(item.ref) + (offset ? '&offset=' + offset : ''), function (b) {
|
|
764
|
+
setOpen({ ref: item.ref, title: item.title, loading: false, content: (offset && open && open.ref === item.ref ? open.content : '') + b.content, nextOffset: b.nextOffset, total: b.totalChars, version: b.version, turnId: b.turnId, current: b.current, item: item })
|
|
765
|
+
}, function (e) {
|
|
766
|
+
setOpen({ ref: item.ref, title: item.title, loading: false, content: '', error: e.code === 'sourceChanged' ? '这条聊天后来被修订过,旧版正文没有保留。' : String(e.message || e) })
|
|
767
|
+
})
|
|
768
|
+
}
|
|
769
|
+
function kindsToggle(kind) { change({ kinds: form.kinds.indexOf(kind) >= 0 ? form.kinds.filter(function (k) { return k !== kind }) : form.kinds.concat([kind]) }) }
|
|
770
|
+
var cov = result && result.coverage
|
|
771
|
+
return h('div', { className: 'dw-pane' },
|
|
772
|
+
h(Card, { title: '总归档查找' },
|
|
773
|
+
h('div', { className: 'dw-muted' }, '查她的聊天原文和日记。关键词按原文字面匹配、区分大小写;这里只读。'),
|
|
774
|
+
h('form', { className: 'dw-setting', onSubmit: function (e) { if (e && e.preventDefault) e.preventDefault(); run(form) } },
|
|
775
|
+
h('input', { type: 'text', 'aria-label': '关键词', placeholder: '关键词(可留空,按时间翻)', value: form.query, style: { maxWidth: 'none' }, onChange: function (e) { change({ query: e.target.value }) } }),
|
|
776
|
+
h('button', { className: 'dw-btn primary', type: 'submit', disabled: busy }, busy ? '查找中…' : '查找')),
|
|
777
|
+
h('div', { className: 'dw-setting' }, KINDS.map(function (k) {
|
|
778
|
+
return h('label', { key: k[0], className: 'dw-muted' }, h('input', { type: 'checkbox', checked: form.kinds.indexOf(k[0]) >= 0, onChange: function () { kindsToggle(k[0]) } }), ' ' + k[1])
|
|
779
|
+
})),
|
|
780
|
+
h('div', { className: 'dw-setting' },
|
|
781
|
+
h('label', { className: 'dw-muted' }, '从 ', h('input', { type: 'date', value: form.from, onChange: function (e) { change({ from: e.target.value }) } })),
|
|
782
|
+
h('label', { className: 'dw-muted' }, '到 ', h('input', { type: 'date', value: form.to, onChange: function (e) { change({ to: e.target.value }) } })),
|
|
783
|
+
h('select', { value: form.order, 'aria-label': '排序', onChange: function (e) { change({ order: e.target.value }) } }, h('option', { value: 'newest' }, '新的在前'), h('option', { value: 'oldest' }, '旧的在前'))),
|
|
784
|
+
form.sourceId || form.turnId || form.linkedTo ? h('div', { className: 'dw-setting' },
|
|
785
|
+
form.sourceId ? h('button', { className: 'dw-btn', onClick: function () { change({ sourceId: '' }) } }, '来源:' + form.sourceId + ' ×') : null,
|
|
786
|
+
form.turnId ? h('button', { className: 'dw-btn', onClick: function () { change({ turnId: '', order: 'oldest' }) } }, '同一轮:' + form.turnId + ' ×') : null,
|
|
787
|
+
form.linkedTo ? h('button', { className: 'dw-btn', onClick: function () { change({ linkedTo: '' }) } }, '只看关联的内容 ×') : null) : null,
|
|
788
|
+
err ? h('div', { className: 'dw-bad', role: 'alert' }, err) : null,
|
|
789
|
+
cov && cov.state !== 'ready' ? h('div', { className: 'dw-muted', role: 'status' }, '有来源没能读到,零结果不代表没发生过:', list(cov.failures).map(function (f) { return ' ' + f.sourceId + ':' + f.message }).join(';')) : null,
|
|
790
|
+
result ? h('div', { className: 'dw-muted' }, result.items.length ? '已显示 ' + result.items.length + ' 条' : '没有找到。' + (cov && cov.state === 'ready' ? '(范围内完整查过了)' : '')) : null,
|
|
791
|
+
result ? result.items.map(function (item) {
|
|
792
|
+
return h('div', { className: 'dw-hit', key: item.ref },
|
|
793
|
+
h('div', { className: 'dw-muted' }, [(KINDS.filter(function (k) { return k[0] === item.kind })[0] || [0, item.kind])[1], item.title, item.time + '(' + (basisLabel[item.timeBasis] || item.timeBasis) + ')', item.current ? '' : '旧版本'].filter(Boolean).join(' · ')),
|
|
794
|
+
h('div', { style: { overflowWrap: 'anywhere', whiteSpace: 'pre-wrap' } }, item.excerpt),
|
|
795
|
+
h('div', { className: 'dw-setting' },
|
|
796
|
+
h('button', { className: 'dw-btn', onClick: function () { show(item, 0) } }, '读原文'),
|
|
797
|
+
h('button', { className: 'dw-btn', onClick: function () { change({ linkedTo: item.ref }); run(Object.assign({}, form, { linkedTo: item.ref })) } }, '看关联'),
|
|
798
|
+
item.turnId ? h('button', { className: 'dw-btn', onClick: function () { var next = Object.assign({}, form, { turnId: item.turnId, order: 'oldest' }); change({ turnId: item.turnId, order: 'oldest' }); run(next) } }, '同一轮') : null,
|
|
799
|
+
h('button', { className: 'dw-btn', onClick: function () { var next = Object.assign({}, form, { sourceId: item.sourceId }); change({ sourceId: item.sourceId }); run(next) } }, '只看这个来源')),
|
|
800
|
+
open && open.ref === item.ref ? h('div', null,
|
|
801
|
+
open.loading ? h('div', { className: 'dw-muted' }, '读取中…') : null,
|
|
802
|
+
open.error ? h('div', { className: 'dw-bad', role: 'alert' }, open.error) : null,
|
|
803
|
+
open.content ? h('pre', { className: 'dw-diary' }, open.content) : null,
|
|
804
|
+
open.nextOffset ? h('button', { className: 'dw-btn', onClick: function () { show(item, open.nextOffset) } }, '继续读(共 ' + open.total + ' 字)') : null) : null)
|
|
805
|
+
}) : null,
|
|
806
|
+
result && result.nextCursor ? h('button', { className: 'dw-btn', disabled: busy, onClick: function () { run(form, result.nextCursor) } }, '更多') : null))
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
var TABS = [['overview', '概览'], ['persona', '人设'], ['prompt', '世界提示词'], ['records', '记录'], ['archive', '档案'], ['photos', '相册'], ['qq', 'QQ'], ['wechat', '微信']]
|
|
810
|
+
/** 一份快照的画面;life 为 null(停着,或生活线没能启动)或缺了哪一块都不会崩。 */
|
|
811
|
+
function View(props) {
|
|
812
|
+
var snap = props.snap, error = props.error
|
|
813
|
+
var tabState = useState('overview'), tab = tabState[0], setTab = tabState[1]
|
|
814
|
+
var panelState = useState(null), panel = panelState[0], setPanel = panelState[1]
|
|
815
|
+
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
816
|
+
var failState = useState(null), fail = failState[0], setFail = failState[1]
|
|
817
|
+
var running = snap.running === true
|
|
818
|
+
var name = snap.name && snap.name !== 'TA' ? snap.name : ''
|
|
819
|
+
function power() {
|
|
820
|
+
if (running && !window.confirm('停止后,她不会再被叫醒,记忆块、人设和世界提示词都会撤下,这段时间的对话也不记。要停止吗?')) return
|
|
821
|
+
setBusy(true); setFail(null)
|
|
822
|
+
post(running ? 'stop' : 'start').then(function () { props.refresh() }, function (e) { setFail(String(e.message || e)) }).then(function () { setBusy(false) })
|
|
823
|
+
}
|
|
824
|
+
return h('div', { className: 'dw' },
|
|
825
|
+
h('header', { className: 'dw-head' + (running ? ' dw-on' : '') },
|
|
826
|
+
h('div', { className: 'dw-title' },
|
|
827
|
+
h('small', null, 'world · ' + snap.worldId),
|
|
828
|
+
h('h2', null, (name || '她') + '的世界'),
|
|
829
|
+
h('div', { className: 'dw-state' }, h('i', { className: 'dw-dot' }), running ? '运行中' : '已停止', ' · ', local(snap.now, snap.timeZone),
|
|
830
|
+
error ? h('span', { className: 'dw-bad' }, ' · 刷新失败:' + error) : null,
|
|
831
|
+
fail ? h('span', { className: 'dw-bad' }, ' · ' + fail) : null)),
|
|
832
|
+
h('button', { className: 'dw-power' + (running ? ' stop' : ''), disabled: busy, onClick: power }, busy ? '……' : running ? '停止' : '开始')),
|
|
833
|
+
h('nav', { className: 'dw-tabs' }, TABS.map(function (t) { return h('button', { key: t[0], className: 'dw-tab' + (tab === t[0] ? ' on' : ''), onClick: function () { setTab(t[0]) } }, t[1]) })),
|
|
834
|
+
tab === 'persona' || tab === 'prompt' ? h('div', { className: 'dw-pane' },
|
|
835
|
+
h(HomeApply, { snap: snap, refresh: props.refresh }),
|
|
836
|
+
tab === 'persona' ? h(PersonaEditor, { onSaved: props.refresh }) : h(PromptEditor)) : null,
|
|
837
|
+
tab === 'overview' ? h(Overview, { snap: snap, refresh: props.refresh }) : null,
|
|
838
|
+
tab === 'records' ? h(Records, { snap: snap, tick: props.tick }) : null,
|
|
839
|
+
tab === 'archive' ? h(MemorySearch, { zone: snap.timeZone }) : null,
|
|
840
|
+
tab === 'photos' ? h(PhotoAlbum, { tick: props.tick, zone: snap.timeZone }) : null,
|
|
841
|
+
tab === 'qq' ? h('div', { className: 'dw-pane' }, snap.native
|
|
842
|
+
? h(Qq, { native: snap.native, onSaved: props.refresh, onNeedPassword: setPanel })
|
|
843
|
+
: h(Card, { title: 'QQ' }, h('div', { className: 'dw-muted' }, 'QQ 通道未开启,请在概览的「接入」中检查配置和开关。'))) : null,
|
|
844
|
+
tab === 'wechat' ? h('div', { className: 'dw-pane' }, snap.wechat
|
|
845
|
+
? h(Wechat, { wechat: snap.wechat, zone: snap.timeZone, onSaved: props.refresh })
|
|
846
|
+
: h(Card, { title: '微信' }, h('div', { className: 'dw-muted' }, '微信通道未开启,请在概览的「接入」中检查配置和开关。'))) : null,
|
|
847
|
+
panel ? h(Panel, { kind: panel, onClose: function () { setPanel(null) } }) : null)
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function Console() {
|
|
851
|
+
var snapState = useState(null), snap = snapState[0], setSnap = snapState[1]
|
|
852
|
+
var errorState = useState(null), error = errorState[0], setError = errorState[1]
|
|
853
|
+
var offState = useState(false), off = offState[0], setOff = offState[1]
|
|
854
|
+
var tickState = useState(0), tick = tickState[0], setTick = tickState[1]
|
|
855
|
+
var loadRef = useRef(null)
|
|
856
|
+
useEffect(function () {
|
|
857
|
+
ensureStyle()
|
|
858
|
+
var alive = true, pending = false, timer = null
|
|
859
|
+
function load() {
|
|
860
|
+
if (!alive || pending) return
|
|
861
|
+
pending = true
|
|
862
|
+
loadSnapshot().then(function (s) {
|
|
863
|
+
pending = false
|
|
864
|
+
if (!alive) return
|
|
865
|
+
if (s === null) { setOff(true); if (timer) { clearInterval(timer); timer = null } return }
|
|
866
|
+
setSnap(s); setError(null); setTick(function (t) { return t + 1 })
|
|
867
|
+
}, function (e) {
|
|
868
|
+
pending = false
|
|
869
|
+
if (alive) setError(String((e && e.message) || e))
|
|
870
|
+
})
|
|
871
|
+
}
|
|
872
|
+
function onVisible() { if (document.visibilityState === 'visible') load() }
|
|
873
|
+
loadRef.current = load
|
|
874
|
+
load()
|
|
875
|
+
timer = setInterval(onVisible, 10000)
|
|
876
|
+
document.addEventListener('visibilitychange', onVisible)
|
|
877
|
+
return function () { alive = false; loadRef.current = null; if (timer) clearInterval(timer); document.removeEventListener('visibilitychange', onVisible) }
|
|
878
|
+
}, [])
|
|
879
|
+
if (off) return h('div', { className: 'dw' }, h('div', { className: 'dw-muted' }, '世界控制台需要桌面版宿主'))
|
|
880
|
+
if (!snap) return h('div', { className: 'dw' }, error ? h('div', { className: 'dw-bad' }, '读取失败:' + error) : h('div', { className: 'dw-muted' }, '读取中…'))
|
|
881
|
+
return h(View, { snap: snap, error: error, tick: tick, refresh: function () { if (loadRef.current) loadRef.current() } })
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
var exports = { inject: ['slots'] }
|
|
885
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
886
|
+
exports.apply = function (ctx) {
|
|
887
|
+
ctx.slots.inject('settings.section', function () {
|
|
888
|
+
return ctx.slots.register({ name: 'settings.section', id: 'world-console', order: 28, label: '世界控制台' }, function () { return h(Console) })
|
|
889
|
+
})
|
|
890
|
+
}
|
|
891
|
+
Object.defineProperty(exports, '__test', { value: { MemorySearch: MemorySearch, latest: latest, searchMemory: searchMemory, memoryQuery: memoryQuery, dayStartIso: dayStartIso, WorkspacePermission: WorkspacePermission, CompactAfterReview: CompactAfterReview, Schedule: Schedule, Modules: Modules, HomeApply: HomeApply, PhotoAlbum: PhotoAlbum, Wechat: Wechat, Activity: Activity, Diary: Diary, Qq: Qq, Panel: Panel, View: View, Overview: Overview, PersonaEditor: PersonaEditor, PromptEditor: PromptEditor, loadSnapshot: loadSnapshot, renderPersona: renderPersona }, enumerable: false })
|
|
892
|
+
return exports
|
|
893
|
+
},
|
|
894
|
+
})
|