dsh-ta 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +111 -1
- package/README.md +325 -140
- package/cordis.patch.yml +5 -35
- package/docs/RELEASE.md +63 -46
- package/docs/USAGE.md +25 -9
- package/docs/presets.example.yml +7 -43
- package/index.js +3 -170
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +6 -19
- package/src/client/client.js +3176 -0
- package/{config.js → src/host/config.js} +39 -4
- package/src/host/constants.js +7 -0
- package/src/host/gates.js +34 -0
- package/src/host/identity.js +145 -0
- package/{im → src/host/im}/bindings.js +1 -1
- package/src/host/index.js +173 -0
- package/{jurisdiction.js → src/host/jurisdiction.js} +1 -1
- package/src/host/maintenance/collect.js +362 -0
- package/src/host/maintenance/completions.js +56 -0
- package/src/host/maintenance/consumption.js +67 -0
- package/src/host/maintenance/cursors.js +53 -0
- package/src/host/maintenance/engine.js +392 -0
- package/src/host/maintenance/llm.js +381 -0
- package/src/host/maintenance/lock.js +105 -0
- package/src/host/maintenance/prompts.js +255 -0
- package/src/host/maintenance/runs.js +47 -0
- package/src/host/maintenance/schedule.js +173 -0
- package/src/host/maintenance/session-cleanup.js +289 -0
- package/src/host/maintenance/session-watcher.js +107 -0
- package/src/host/maintenance/sleep.js +3 -0
- package/src/host/maintenance/stages.js +241 -0
- package/src/host/maintenance/state.js +192 -0
- package/src/host/prompts.js +96 -0
- package/src/host/records.js +175 -0
- package/{reme.js → src/host/reme.js} +3 -1
- package/src/host/runtime-manager.js +281 -0
- package/{runtime.js → src/host/runtime.js} +28 -50
- package/src/host/settings/defaults.js +55 -0
- package/src/host/settings/errors.js +29 -0
- package/src/host/settings/home.js +316 -0
- package/src/host/settings/http.js +164 -0
- package/src/host/settings/im.js +148 -0
- package/src/host/settings/lifecycle.js +373 -0
- package/src/host/settings/persona.js +113 -0
- package/src/host/settings/routes.js +229 -0
- package/src/host/settings/status.js +192 -0
- package/src/host/state/appraisals.js +56 -0
- package/src/host/state/feel.js +78 -0
- package/src/host/state/index.js +9 -0
- package/src/host/state/mood.js +103 -0
- package/src/host/state/notes.js +18 -0
- package/{life.js → src/host/state/outing.js} +13 -136
- package/src/host/state/values.js +9 -0
- package/{stickers → src/host/stickers}/tool.js +1 -1
- package/src/host/storage/fs.js +29 -0
- package/src/host/storage/index.js +8 -0
- package/src/host/storage/paths.js +20 -0
- package/src/host/storage/revision.js +5 -0
- package/src/host/storage/session-state.js +38 -0
- package/src/host/storage/time.js +127 -0
- package/src/host/tools/index.js +152 -0
- package/src/host/tools/read.js +252 -0
- package/src/host/tools/shared.js +23 -0
- package/src/host/tools/wiki.js +35 -0
- package/src/host/tools/write.js +164 -0
- package/{usage → src/host/usage}/aggregate.js +4 -1
- package/src/host/usage/ledger.js +186 -0
- package/src/host/usage/serve.js +116 -0
- package/client.js +0 -618
- package/gates.js +0 -18
- package/identity.js +0 -97
- package/prompts.js +0 -28
- package/storage.js +0 -95
- package/tools.js +0 -540
- package/usage/ledger.js +0 -126
- package/usage/serve.js +0 -38
- /package/{im → src/host/im}/say.js +0 -0
- /package/{memory → src/host/memory}/capture.js +0 -0
- /package/{memory → src/host/memory}/messages.js +0 -0
- /package/{memory → src/host/memory}/outbox.js +0 -0
- /package/{stickers → src/host/stickers}/load.js +0 -0
- /package/{stickers → src/host/stickers}/select.js +0 -0
- /package/{stickers → src/host/stickers}/serve.js +0 -0
- /package/{usage → src/host/usage}/pricing.js +0 -0
package/client.js
DELETED
|
@@ -1,618 +0,0 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({
|
|
2
|
-
id: 'dsh-ta',
|
|
3
|
-
factory(require) {
|
|
4
|
-
const React = require('react')
|
|
5
|
-
const h = React.createElement
|
|
6
|
-
|
|
7
|
-
const DEFAULTS = {
|
|
8
|
-
taHome: '~/TATA/home',
|
|
9
|
-
remeEndpoint: 'http://127.0.0.1:2333',
|
|
10
|
-
jurisdictions: ['~/dsh'],
|
|
11
|
-
captureEnabled: true,
|
|
12
|
-
captureInterval: 5,
|
|
13
|
-
heartbeatEnabled: false,
|
|
14
|
-
heartbeatActiveStart: '08:00',
|
|
15
|
-
heartbeatActiveEnd: '23:00',
|
|
16
|
-
dreamEnabled: true,
|
|
17
|
-
outingCleanupEnabled: true,
|
|
18
|
-
jurisdictionOutingEnabled: true,
|
|
19
|
-
jurisdictionOutingTime: '22:45',
|
|
20
|
-
timezone: 'Asia/Shanghai',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const FIELD_KEYS = [
|
|
24
|
-
'taHome',
|
|
25
|
-
'remeEndpoint',
|
|
26
|
-
'jurisdictions',
|
|
27
|
-
'captureEnabled',
|
|
28
|
-
'captureInterval',
|
|
29
|
-
'heartbeatEnabled',
|
|
30
|
-
'heartbeatActiveStart',
|
|
31
|
-
'heartbeatActiveEnd',
|
|
32
|
-
'dreamEnabled',
|
|
33
|
-
'outingCleanupEnabled',
|
|
34
|
-
'jurisdictionOutingEnabled',
|
|
35
|
-
'jurisdictionOutingTime',
|
|
36
|
-
'timezone',
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
const inputStyle = {
|
|
40
|
-
width: '100%',
|
|
41
|
-
boxSizing: 'border-box',
|
|
42
|
-
padding: '7px 9px',
|
|
43
|
-
border: '1px solid var(--dsw-alias-border-l4, var(--dsw-alias-border-l1, rgba(127,127,127,.28)))',
|
|
44
|
-
borderRadius: 7,
|
|
45
|
-
background: 'var(--dsw-alias-bg-layer-1, rgba(127,127,127,.06))',
|
|
46
|
-
color: 'inherit',
|
|
47
|
-
font: 'inherit',
|
|
48
|
-
fontSize: 13,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function parseJurisdictions(text) {
|
|
52
|
-
return String(text ?? '').split(/\r?\n/).map(item => item.trim()).filter(Boolean)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
inject: ['slots', 'conversation', 'uiWorkspace', 'workspaces', 'configForms'],
|
|
57
|
-
apply(ctx) {
|
|
58
|
-
const uiWorkspace = ctx.uiWorkspace || ctx.get('uiWorkspace')
|
|
59
|
-
const workspaces = ctx.workspaces || ctx.get('workspaces')
|
|
60
|
-
const configForms = ctx.configForms || ctx.get('configForms')
|
|
61
|
-
|
|
62
|
-
function configuredHome() {
|
|
63
|
-
try {
|
|
64
|
-
const value = configForms?.get('dsh-ta')?.getSnapshot?.().value
|
|
65
|
-
return typeof value?.taHome === 'string' && value.taHome ? value.taHome : DEFAULTS.taHome
|
|
66
|
-
} catch {
|
|
67
|
-
return DEFAULTS.taHome
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function TaEntry({ wide }) {
|
|
72
|
-
const [busy, setBusy] = React.useState(false)
|
|
73
|
-
const [error, setError] = React.useState('')
|
|
74
|
-
|
|
75
|
-
async function openTa() {
|
|
76
|
-
if (busy) return
|
|
77
|
-
if (!uiWorkspace || !workspaces) {
|
|
78
|
-
setError('会话服务未就绪')
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
setBusy(true)
|
|
82
|
-
setError('')
|
|
83
|
-
try {
|
|
84
|
-
const home = configuredHome()
|
|
85
|
-
const suffix = home.replace(/^~\/?/, '').replace(/\/+$/, '')
|
|
86
|
-
const workspace = workspaces?.list?.getSnapshot?.().items
|
|
87
|
-
?.find(item => item.path === home
|
|
88
|
-
|| (suffix && item.path?.endsWith(`/${suffix}`)))
|
|
89
|
-
if (!workspace) {
|
|
90
|
-
setError(`没有找到 ${home} 工作区`)
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
await uiWorkspace.openWorkspace(workspace.workspaceId, undefined, { agentPreset: 'ta' })
|
|
94
|
-
} catch (cause) {
|
|
95
|
-
setError(cause instanceof Error ? cause.message : String(cause))
|
|
96
|
-
} finally {
|
|
97
|
-
setBusy(false)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return h('button', {
|
|
102
|
-
type: 'button',
|
|
103
|
-
title: error || '去找Ta',
|
|
104
|
-
'aria-label': '去找Ta',
|
|
105
|
-
disabled: busy,
|
|
106
|
-
onClick: openTa,
|
|
107
|
-
style: {
|
|
108
|
-
display: 'inline-flex',
|
|
109
|
-
alignItems: 'center',
|
|
110
|
-
justifyContent: 'center',
|
|
111
|
-
gap: 6,
|
|
112
|
-
height: 30,
|
|
113
|
-
width: wide ? 'auto' : 30,
|
|
114
|
-
padding: wide ? '0 9px' : 0,
|
|
115
|
-
border: '1px solid var(--dsw-alias-border-l2, var(--dsw-alias-border-l1, rgba(127,127,127,.28)))',
|
|
116
|
-
borderRadius: 8,
|
|
117
|
-
background: 'transparent',
|
|
118
|
-
color: 'inherit',
|
|
119
|
-
font: 'inherit',
|
|
120
|
-
fontSize: 12,
|
|
121
|
-
cursor: busy ? 'default' : 'pointer',
|
|
122
|
-
opacity: busy ? 0.6 : 1,
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
h('span', { 'aria-hidden': true, style: { fontSize: 14, lineHeight: 1 } }, '✦'),
|
|
126
|
-
wide ? h('span', null, error || '去找Ta') : null)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function Field({ label, hint, children }) {
|
|
130
|
-
return h('label', {
|
|
131
|
-
style: { display: 'grid', gap: 5, marginBottom: 15 },
|
|
132
|
-
},
|
|
133
|
-
h('span', { style: { fontSize: 13, fontWeight: 600 } }, label),
|
|
134
|
-
children,
|
|
135
|
-
hint ? h('span', {
|
|
136
|
-
style: { fontSize: 11, lineHeight: 1.45, opacity: 0.62 },
|
|
137
|
-
}, hint) : null)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function Toggle({ label, hint, checked, disabled, onChange }) {
|
|
141
|
-
return h('label', {
|
|
142
|
-
style: {
|
|
143
|
-
display: 'flex',
|
|
144
|
-
alignItems: 'flex-start',
|
|
145
|
-
gap: 9,
|
|
146
|
-
marginBottom: 12,
|
|
147
|
-
cursor: disabled ? 'default' : 'pointer',
|
|
148
|
-
opacity: disabled ? 0.55 : 1,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
h('input', {
|
|
152
|
-
type: 'checkbox',
|
|
153
|
-
checked: Boolean(checked),
|
|
154
|
-
disabled,
|
|
155
|
-
onChange: event => onChange(event.target.checked),
|
|
156
|
-
style: { marginTop: 2, accentColor: 'var(--dsw-alias-brand-primary, #4d6bfe)' },
|
|
157
|
-
}),
|
|
158
|
-
h('span', null,
|
|
159
|
-
h('span', { style: { display: 'block', fontSize: 13, fontWeight: 600 } }, label),
|
|
160
|
-
hint ? h('span', {
|
|
161
|
-
style: { display: 'block', marginTop: 2, fontSize: 11, lineHeight: 1.45, opacity: 0.62 },
|
|
162
|
-
}, hint) : null))
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function Section({ title, children }) {
|
|
166
|
-
return h('section', {
|
|
167
|
-
style: {
|
|
168
|
-
padding: '15px 16px 2px',
|
|
169
|
-
marginBottom: 14,
|
|
170
|
-
border: '1px solid var(--dsw-alias-border-l2, var(--dsw-alias-border-l1, rgba(127,127,127,.2)))',
|
|
171
|
-
borderRadius: 10,
|
|
172
|
-
background: 'var(--dsw-alias-bg-layer-1, rgba(127,127,127,.035))',
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
h('h3', {
|
|
176
|
-
style: { margin: '0 0 13px', fontSize: 13, letterSpacing: '.02em', opacity: 0.82 },
|
|
177
|
-
}, title),
|
|
178
|
-
children)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function TaSettings() {
|
|
182
|
-
const [form, setForm] = React.useState(null)
|
|
183
|
-
const [draft, setDraft] = React.useState({ ...DEFAULTS })
|
|
184
|
-
const [baseline, setBaseline] = React.useState({ ...DEFAULTS })
|
|
185
|
-
const [jurisdictionText, setJurisdictionText] = React.useState(DEFAULTS.jurisdictions.join('\n'))
|
|
186
|
-
const [state, setState] = React.useState('loading')
|
|
187
|
-
const [message, setMessage] = React.useState('')
|
|
188
|
-
const saving = React.useRef(false)
|
|
189
|
-
const editing = React.useRef(false)
|
|
190
|
-
|
|
191
|
-
React.useEffect(() => {
|
|
192
|
-
if (!configForms) {
|
|
193
|
-
setState('unavailable')
|
|
194
|
-
setMessage('配置服务不可用')
|
|
195
|
-
return undefined
|
|
196
|
-
}
|
|
197
|
-
let bound
|
|
198
|
-
let ready = false
|
|
199
|
-
const timeout = setTimeout(() => {
|
|
200
|
-
if (!ready) {
|
|
201
|
-
setState('unavailable')
|
|
202
|
-
setMessage('读取配置超时,请刷新页面重试')
|
|
203
|
-
}
|
|
204
|
-
}, 10000)
|
|
205
|
-
try {
|
|
206
|
-
bound = configForms.get('dsh-ta')
|
|
207
|
-
setForm(bound)
|
|
208
|
-
} catch (cause) {
|
|
209
|
-
ready = true
|
|
210
|
-
setState('unavailable')
|
|
211
|
-
setMessage(cause instanceof Error ? cause.message : String(cause))
|
|
212
|
-
return undefined
|
|
213
|
-
}
|
|
214
|
-
const read = () => {
|
|
215
|
-
const snapshot = bound.getSnapshot()
|
|
216
|
-
if (snapshot.status === 'unavailable') {
|
|
217
|
-
ready = true
|
|
218
|
-
setState('unavailable')
|
|
219
|
-
setMessage('当前 profile 没有提供 dsh-ta 配置')
|
|
220
|
-
return
|
|
221
|
-
}
|
|
222
|
-
if (snapshot.status === 'loading' && !snapshot.value) return
|
|
223
|
-
if (snapshot.value && !saving.current && !editing.current) {
|
|
224
|
-
const next = { ...DEFAULTS, ...snapshot.value }
|
|
225
|
-
setDraft(next)
|
|
226
|
-
setBaseline(next)
|
|
227
|
-
setJurisdictionText((next.jurisdictions ?? DEFAULTS.jurisdictions).join('\n'))
|
|
228
|
-
ready = true
|
|
229
|
-
setState('ready')
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
read()
|
|
233
|
-
const unsubscribe = bound.subscribe(read)
|
|
234
|
-
return () => {
|
|
235
|
-
clearTimeout(timeout)
|
|
236
|
-
unsubscribe()
|
|
237
|
-
}
|
|
238
|
-
}, [])
|
|
239
|
-
|
|
240
|
-
const update = (field, value) => {
|
|
241
|
-
if (saving.current) return
|
|
242
|
-
editing.current = true
|
|
243
|
-
setDraft(previous => ({ ...previous, [field]: value }))
|
|
244
|
-
setMessage('')
|
|
245
|
-
setState(previous => previous === 'error' ? 'ready' : previous)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const save = async () => {
|
|
249
|
-
if (!form || saving.current) return
|
|
250
|
-
const target = {
|
|
251
|
-
...draft,
|
|
252
|
-
jurisdictions: parseJurisdictions(jurisdictionText),
|
|
253
|
-
}
|
|
254
|
-
target.taHome = String(target.taHome ?? '').trim()
|
|
255
|
-
if (!target.taHome) {
|
|
256
|
-
setState('error')
|
|
257
|
-
setMessage('Ta 的家目录不能为空')
|
|
258
|
-
return
|
|
259
|
-
}
|
|
260
|
-
if (target.taHome === '/' || target.taHome === '~') {
|
|
261
|
-
setState('error')
|
|
262
|
-
setMessage('Ta 的家目录不能是 / 或 ~')
|
|
263
|
-
return
|
|
264
|
-
}
|
|
265
|
-
if (target.jurisdictions.length === 0) {
|
|
266
|
-
setState('error')
|
|
267
|
-
setMessage('至少保留一个只读辖区')
|
|
268
|
-
return
|
|
269
|
-
}
|
|
270
|
-
if (target.jurisdictions.some(root => root === '/' || root === '~')) {
|
|
271
|
-
setState('error')
|
|
272
|
-
setMessage('辖区不能是 / 或 ~')
|
|
273
|
-
return
|
|
274
|
-
}
|
|
275
|
-
if (!Number.isInteger(target.captureInterval) || target.captureInterval < 1 || target.captureInterval > 60) {
|
|
276
|
-
setState('error')
|
|
277
|
-
setMessage('捕获间隔必须是 1–60 的整数')
|
|
278
|
-
return
|
|
279
|
-
}
|
|
280
|
-
try {
|
|
281
|
-
const endpoint = new URL(target.remeEndpoint)
|
|
282
|
-
if (endpoint.protocol !== 'http:' && endpoint.protocol !== 'https:') throw new Error('协议')
|
|
283
|
-
} catch {
|
|
284
|
-
setState('error')
|
|
285
|
-
setMessage('ReMe 地址必须是 http(s) URL')
|
|
286
|
-
return
|
|
287
|
-
}
|
|
288
|
-
for (const clock of [target.heartbeatActiveStart, target.heartbeatActiveEnd, target.jurisdictionOutingTime]) {
|
|
289
|
-
if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(clock)) {
|
|
290
|
-
setState('error')
|
|
291
|
-
setMessage(`时间格式应为 HH:MM,当前是 ${clock}`)
|
|
292
|
-
return
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
try {
|
|
296
|
-
new Intl.DateTimeFormat('en-US', { timeZone: target.timezone })
|
|
297
|
-
} catch {
|
|
298
|
-
setState('error')
|
|
299
|
-
setMessage(`无效时区:${target.timezone}`)
|
|
300
|
-
return
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const snapshot = form.getSnapshot()
|
|
304
|
-
if (snapshot.writable === false) {
|
|
305
|
-
setState('error')
|
|
306
|
-
setMessage('当前 profile 不允许写入配置')
|
|
307
|
-
return
|
|
308
|
-
}
|
|
309
|
-
const changed = FIELD_KEYS.filter(field => JSON.stringify(target[field]) !== JSON.stringify(baseline[field]))
|
|
310
|
-
if (changed.length === 0) {
|
|
311
|
-
setState('ready')
|
|
312
|
-
setMessage('没有修改')
|
|
313
|
-
return
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
saving.current = true
|
|
317
|
-
setState('saving')
|
|
318
|
-
setMessage('')
|
|
319
|
-
try {
|
|
320
|
-
const ops = changed.map(field => ({ op: 'set', path: [field], value: target[field] }))
|
|
321
|
-
const accepted = await form.mutate(ops, snapshot.revision)
|
|
322
|
-
if (!accepted) throw new Error('宿主拒绝了这次配置写入')
|
|
323
|
-
editing.current = false
|
|
324
|
-
setDraft(target)
|
|
325
|
-
setBaseline(target)
|
|
326
|
-
setJurisdictionText(target.jurisdictions.join('\n'))
|
|
327
|
-
setState('ready')
|
|
328
|
-
setMessage('已保存。配置已即时生效。')
|
|
329
|
-
} catch (cause) {
|
|
330
|
-
setState('error')
|
|
331
|
-
setMessage(cause instanceof Error ? cause.message : String(cause))
|
|
332
|
-
} finally {
|
|
333
|
-
saving.current = false
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const reset = () => {
|
|
338
|
-
editing.current = false
|
|
339
|
-
setDraft({ ...baseline })
|
|
340
|
-
setJurisdictionText((baseline.jurisdictions ?? DEFAULTS.jurisdictions).join('\n'))
|
|
341
|
-
setState('ready')
|
|
342
|
-
setMessage('')
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
if (state === 'loading') {
|
|
346
|
-
return h('div', { style: { padding: 24, fontSize: 13, opacity: 0.68 } }, '正在读取 Ta 配置…')
|
|
347
|
-
}
|
|
348
|
-
if (state === 'unavailable' || !form) {
|
|
349
|
-
return h('div', { style: { maxWidth: 760, padding: '8px 4px' } },
|
|
350
|
-
h('h2', { style: { margin: '0 0 8px', fontSize: 18 } }, 'TA 的家'),
|
|
351
|
-
h('p', { style: { margin: 0, fontSize: 13, lineHeight: 1.6, opacity: 0.68 } },
|
|
352
|
-
message || '当前 profile 没有提供 dsh-ta 配置,无法编辑。'),
|
|
353
|
-
h('p', { style: { margin: '12px 0 0', fontSize: 12, lineHeight: 1.55, opacity: 0.56 } },
|
|
354
|
-
'请先在 profile 中启用 dsh-ta 配置,然后刷新设置页。'))
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const disabled = state === 'saving'
|
|
358
|
-
const dirty = FIELD_KEYS.some(field => JSON.stringify(draft[field]) !== JSON.stringify(baseline[field]))
|
|
359
|
-
|| JSON.stringify(parseJurisdictions(jurisdictionText)) !== JSON.stringify(baseline.jurisdictions)
|
|
360
|
-
const text = (field, placeholder) => h('input', {
|
|
361
|
-
style: inputStyle,
|
|
362
|
-
value: draft[field] ?? '',
|
|
363
|
-
placeholder,
|
|
364
|
-
disabled,
|
|
365
|
-
onChange: event => update(field, event.target.value),
|
|
366
|
-
})
|
|
367
|
-
const number = (field, min, max) => h('input', {
|
|
368
|
-
type: 'number',
|
|
369
|
-
min,
|
|
370
|
-
max,
|
|
371
|
-
style: inputStyle,
|
|
372
|
-
value: draft[field] ?? '',
|
|
373
|
-
disabled,
|
|
374
|
-
onChange: event => update(field, Number(event.target.value)),
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
return h('div', {
|
|
378
|
-
style: { maxWidth: 760, padding: '8px 4px 28px', color: 'inherit' },
|
|
379
|
-
},
|
|
380
|
-
h('div', { style: { marginBottom: 18 } },
|
|
381
|
-
h('h2', { style: { margin: '0 0 5px', fontSize: 18 } }, 'TA 的家'),
|
|
382
|
-
h('p', {
|
|
383
|
-
style: { margin: 0, fontSize: 12, lineHeight: 1.55, opacity: 0.64 },
|
|
384
|
-
}, '身份、记忆、辖区与夜间回顾。保存会写入当前 profile;配置字段即时生效。')),
|
|
385
|
-
h(UsageCard),
|
|
386
|
-
|
|
387
|
-
state === 'error' ? h('div', {
|
|
388
|
-
role: 'alert',
|
|
389
|
-
style: {
|
|
390
|
-
marginBottom: 14,
|
|
391
|
-
padding: '9px 11px',
|
|
392
|
-
border: '1px solid var(--dsw-alias-state-error-primary, rgba(220,80,80,.35))',
|
|
393
|
-
borderRadius: 8,
|
|
394
|
-
color: 'var(--dsw-alias-state-error-primary, #c44)',
|
|
395
|
-
fontSize: 12,
|
|
396
|
-
lineHeight: 1.45,
|
|
397
|
-
},
|
|
398
|
-
}, message || '配置不可用') : null,
|
|
399
|
-
|
|
400
|
-
h(Section, { title: '位置' },
|
|
401
|
-
h(Field, { label: 'Ta 的家', hint: '必须与 ta / ta-review 会话的工作目录一致。' },
|
|
402
|
-
text('taHome', '~/TATA/home')),
|
|
403
|
-
h(Field, { label: 'ReMe 地址', hint: '建议只指向本机回环地址;capture 会把对话写入这里。' },
|
|
404
|
-
text('remeEndpoint', 'http://127.0.0.1:2333'))),
|
|
405
|
-
|
|
406
|
-
h(Section, { title: '记忆与辖区' },
|
|
407
|
-
h(Field, { label: '只读辖区', hint: '每行一个根目录;不能填 / 或 ~。' },
|
|
408
|
-
h('textarea', {
|
|
409
|
-
style: { ...inputStyle, minHeight: 64, resize: 'vertical', lineHeight: 1.5 },
|
|
410
|
-
value: jurisdictionText,
|
|
411
|
-
disabled,
|
|
412
|
-
onChange: event => {
|
|
413
|
-
editing.current = true
|
|
414
|
-
setJurisdictionText(event.target.value)
|
|
415
|
-
setMessage('')
|
|
416
|
-
setState(previous => previous === 'error' ? 'ready' : previous)
|
|
417
|
-
},
|
|
418
|
-
})),
|
|
419
|
-
h(Toggle, {
|
|
420
|
-
label: '捕获完成的聊天',
|
|
421
|
-
hint: '关闭后不把日常对话送入长期记忆。',
|
|
422
|
-
checked: draft.captureEnabled,
|
|
423
|
-
disabled,
|
|
424
|
-
onChange: value => update('captureEnabled', value),
|
|
425
|
-
}),
|
|
426
|
-
h(Field, { label: '每几轮封一批', hint: '1–60。' },
|
|
427
|
-
number('captureInterval', 1, 60))),
|
|
428
|
-
|
|
429
|
-
h(Section, { title: '夜间回顾' },
|
|
430
|
-
h(Toggle, {
|
|
431
|
-
label: '22:30 ReMe 整理',
|
|
432
|
-
checked: draft.dreamEnabled,
|
|
433
|
-
disabled,
|
|
434
|
-
onChange: value => update('dreamEnabled', value),
|
|
435
|
-
}),
|
|
436
|
-
h(Toggle, {
|
|
437
|
-
label: '02:00 清理旧出门记录',
|
|
438
|
-
checked: draft.outingCleanupEnabled,
|
|
439
|
-
disabled,
|
|
440
|
-
onChange: value => update('outingCleanupEnabled', value),
|
|
441
|
-
}),
|
|
442
|
-
h(Toggle, {
|
|
443
|
-
label: '22:45 辖区人格化查看',
|
|
444
|
-
hint: '由 Ta 自己读当天文件和对话,写一份辖区出门记录,供回顾使用。',
|
|
445
|
-
checked: draft.jurisdictionOutingEnabled,
|
|
446
|
-
disabled,
|
|
447
|
-
onChange: value => update('jurisdictionOutingEnabled', value),
|
|
448
|
-
}),
|
|
449
|
-
h(Field, { label: '辖区查看时间', hint: '24 小时制,例如 22:45。' },
|
|
450
|
-
text('jurisdictionOutingTime', '22:45')),
|
|
451
|
-
h(Field, { label: '时区' },
|
|
452
|
-
text('timezone', 'Asia/Shanghai'))),
|
|
453
|
-
|
|
454
|
-
h(Section, { title: '主动消息' },
|
|
455
|
-
h(Toggle, {
|
|
456
|
-
label: '启用心跳',
|
|
457
|
-
hint: '默认关闭。开启后只在活跃时段、inbox 非空时创建 life 会话。',
|
|
458
|
-
checked: draft.heartbeatEnabled,
|
|
459
|
-
disabled,
|
|
460
|
-
onChange: value => update('heartbeatEnabled', value),
|
|
461
|
-
}),
|
|
462
|
-
h(Field, { label: '活跃开始' }, text('heartbeatActiveStart', '08:00')),
|
|
463
|
-
h(Field, { label: '活跃结束' }, text('heartbeatActiveEnd', '23:00'))),
|
|
464
|
-
|
|
465
|
-
h('div', { style: { display: 'flex', alignItems: 'center', gap: 9, marginTop: 18 } },
|
|
466
|
-
h('button', {
|
|
467
|
-
type: 'button',
|
|
468
|
-
onClick: save,
|
|
469
|
-
disabled: disabled,
|
|
470
|
-
style: {
|
|
471
|
-
padding: '7px 14px',
|
|
472
|
-
border: 0,
|
|
473
|
-
borderRadius: 7,
|
|
474
|
-
background: 'var(--dsw-alias-button-primary-fill, var(--dsw-alias-brand-primary, #4d6bfe))',
|
|
475
|
-
color: 'var(--dsw-alias-label-primary-foreground, #fff)',
|
|
476
|
-
font: 'inherit',
|
|
477
|
-
fontSize: 12,
|
|
478
|
-
fontWeight: 600,
|
|
479
|
-
cursor: disabled ? 'default' : 'pointer',
|
|
480
|
-
opacity: disabled ? 0.55 : 1,
|
|
481
|
-
},
|
|
482
|
-
}, state === 'saving' ? '保存中…' : '保存'),
|
|
483
|
-
h('button', {
|
|
484
|
-
type: 'button',
|
|
485
|
-
onClick: reset,
|
|
486
|
-
disabled,
|
|
487
|
-
style: {
|
|
488
|
-
padding: '7px 12px',
|
|
489
|
-
border: '1px solid var(--dsw-alias-border-l1, rgba(127,127,127,.28))',
|
|
490
|
-
borderRadius: 7,
|
|
491
|
-
background: 'transparent',
|
|
492
|
-
color: 'inherit',
|
|
493
|
-
font: 'inherit',
|
|
494
|
-
fontSize: 12,
|
|
495
|
-
cursor: disabled ? 'default' : 'pointer',
|
|
496
|
-
},
|
|
497
|
-
}, '还原修改'),
|
|
498
|
-
(message || dirty) ? h('span', {
|
|
499
|
-
role: 'status',
|
|
500
|
-
'aria-live': 'polite',
|
|
501
|
-
style: { fontSize: 11, opacity: 0.65 },
|
|
502
|
-
}, message || '有未保存修改') : null))
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function TaStickerCard({ block, phase }) {
|
|
506
|
-
const text = Array.isArray(block?.content)
|
|
507
|
-
? block.content.find(part => part?.type === 'text')?.text
|
|
508
|
-
: undefined
|
|
509
|
-
let value
|
|
510
|
-
try {
|
|
511
|
-
const marker = typeof text === 'string' ? text.indexOf('STICKER:') : -1
|
|
512
|
-
value = marker >= 0 ? JSON.parse(text.slice(marker + 'STICKER:'.length)) : undefined
|
|
513
|
-
} catch {
|
|
514
|
-
value = undefined
|
|
515
|
-
}
|
|
516
|
-
if (phase === 'preparing' || phase === 'start') {
|
|
517
|
-
return h('span', { style: { fontSize: 12, opacity: 0.65 } }, '正在准备表情…')
|
|
518
|
-
}
|
|
519
|
-
if (block?.isError) {
|
|
520
|
-
return h('span', { role: 'alert', style: { fontSize: 12, color: 'var(--dsw-alias-state-error-primary, #d9534f)' } },
|
|
521
|
-
block?.error?.message || '表情发送失败')
|
|
522
|
-
}
|
|
523
|
-
return h('span', { style: { fontSize: 12, opacity: 0.7 } }, value?.text ? `表情已发送 · ${value.text}` : '表情已发送')
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
function UsageCard() {
|
|
527
|
-
const [report, setReport] = React.useState(null)
|
|
528
|
-
const [error, setError] = React.useState('')
|
|
529
|
-
React.useEffect(() => {
|
|
530
|
-
let alive = true
|
|
531
|
-
const controller = new AbortController()
|
|
532
|
-
const timeout = setTimeout(() => controller.abort(), 8000)
|
|
533
|
-
fetch('/api/dsh-ta/usage', { cache: 'no-store', signal: controller.signal })
|
|
534
|
-
.then(response => response.ok ? response.json() : Promise.reject(new Error(`HTTP ${response.status}`)))
|
|
535
|
-
.then(value => { if (alive) setReport(value) })
|
|
536
|
-
.catch(cause => { if (alive) setError(cause instanceof Error ? cause.message : String(cause)) })
|
|
537
|
-
.finally(() => clearTimeout(timeout))
|
|
538
|
-
return () => {
|
|
539
|
-
alive = false
|
|
540
|
-
clearTimeout(timeout)
|
|
541
|
-
controller.abort()
|
|
542
|
-
}
|
|
543
|
-
}, [])
|
|
544
|
-
if (error) return h('div', { role: 'alert', style: { padding: '8px 0', fontSize: 12, opacity: 0.65 } }, `花销接口暂不可用:${error}`)
|
|
545
|
-
if (!report) return h('div', { style: { padding: '8px 0', fontSize: 12, opacity: 0.6 } }, '正在读取花销…')
|
|
546
|
-
const money = value => value == null ? '—' : `${report.currency === 'CNY' || report.currency == null ? '¥' : `${report.currency} `}${Number(value).toFixed(3)}`
|
|
547
|
-
const tokens = value => Number(value || 0).toLocaleString('zh-CN')
|
|
548
|
-
const total = report.total || { tokens: {}, costCny: null }
|
|
549
|
-
const allTokens = (total.tokens.uncachedInput || 0) + (total.tokens.cacheRead || 0) + (total.tokens.cacheWrite || 0) + (total.tokens.output || 0)
|
|
550
|
-
return h('section', {
|
|
551
|
-
style: {
|
|
552
|
-
marginBottom: 16,
|
|
553
|
-
padding: '14px 16px',
|
|
554
|
-
border: '1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.2))',
|
|
555
|
-
borderRadius: 10,
|
|
556
|
-
background: 'var(--dsw-alias-bg-layer-1, rgba(127,127,127,.035))',
|
|
557
|
-
},
|
|
558
|
-
},
|
|
559
|
-
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 12, flexWrap: 'wrap' } },
|
|
560
|
-
h('h3', { style: { margin: 0, fontSize: 13 } }, '花销'),
|
|
561
|
-
h('span', { style: { fontSize: 18, fontWeight: 700 } }, money(total.costCny)),
|
|
562
|
-
h('span', { style: { fontSize: 11, opacity: 0.6 } }, `${tokens(allTokens)} tokens · ${total.turns || 0} 轮${total.unpricedTurns ? ` · ${total.unpricedTurns} 轮未定价` : ''}`)),
|
|
563
|
-
h('div', { style: { display: 'flex', gap: 12, marginTop: 8, fontSize: 11, opacity: 0.65, flexWrap: 'wrap' } },
|
|
564
|
-
h('span', null, 'DSH agent 估算'),
|
|
565
|
-
h('a', { href: '/api/dsh-ta/usage/export.csv', style: { color: 'inherit' } }, '导出 CSV'),
|
|
566
|
-
h('a', { href: '/api/dsh-ta/usage/export.json', style: { color: 'inherit' } }, '导出 JSON')),
|
|
567
|
-
h('div', { style: { marginTop: 10, display: 'grid', gap: 4, fontSize: 11, opacity: 0.72 } },
|
|
568
|
-
...Object.entries(report.byCategory || {}).map(([name, value]) => h('div', { key: name, style: { display: 'flex', justifyContent: 'space-between' } },
|
|
569
|
-
h('span', null, name), h('span', null, `${money(value.costCny)} · ${tokens(Object.values(value.tokens || {}).reduce((a, b) => a + Number(b || 0), 0))} tok`)))))
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
function TaIcon({ size, active }) {
|
|
573
|
-
return h('svg', {
|
|
574
|
-
'aria-hidden': true,
|
|
575
|
-
viewBox: '0 0 24 24',
|
|
576
|
-
width: size,
|
|
577
|
-
height: size,
|
|
578
|
-
fill: 'none',
|
|
579
|
-
stroke: 'currentColor',
|
|
580
|
-
strokeWidth: 1.9,
|
|
581
|
-
strokeLinecap: 'round',
|
|
582
|
-
strokeLinejoin: 'round',
|
|
583
|
-
style: { opacity: active ? 1 : 0.82, display: 'block' },
|
|
584
|
-
},
|
|
585
|
-
h('path', { d: 'M4.5 20.5h15' }),
|
|
586
|
-
h('path', { d: 'M6 20.5V9.5L12 4.5l6 5v11' }),
|
|
587
|
-
h('path', { d: 'M12 9.2l.65 1.8 1.8.65-1.8.65-.65 1.8-.65-1.8-1.8-.65 1.8-.65z', strokeWidth: 1.4 }))
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
ctx.slots.inject('tool.call.toolview', () => ctx.slots.register({
|
|
591
|
-
name: 'tool.call.toolview',
|
|
592
|
-
key: 'ta_sticker',
|
|
593
|
-
}, TaStickerCard))
|
|
594
|
-
|
|
595
|
-
ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register({
|
|
596
|
-
name: 'sidebar.footer.action',
|
|
597
|
-
id: 'dsh-ta-entry',
|
|
598
|
-
order: 20,
|
|
599
|
-
label: '去找Ta',
|
|
600
|
-
}, TaEntry))
|
|
601
|
-
|
|
602
|
-
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
603
|
-
name: 'settings.section',
|
|
604
|
-
id: 'dsh-ta',
|
|
605
|
-
order: 30,
|
|
606
|
-
label: () => 'TA 的家',
|
|
607
|
-
}, TaSettings))
|
|
608
|
-
|
|
609
|
-
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
610
|
-
name: 'settings.section.icon',
|
|
611
|
-
id: 'dsh-ta',
|
|
612
|
-
order: 30,
|
|
613
|
-
label: () => 'TA 的家',
|
|
614
|
-
}, TaIcon))
|
|
615
|
-
},
|
|
616
|
-
}
|
|
617
|
-
},
|
|
618
|
-
})
|
package/gates.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { normalizeConfig } from './config.js'
|
|
2
|
-
import { realPath } from './storage.js'
|
|
3
|
-
|
|
4
|
-
export function isTaSession(ctx, session, config = {}) {
|
|
5
|
-
const settings = normalizeConfig(config)
|
|
6
|
-
const header = session?.header
|
|
7
|
-
if (!header || header.origin !== undefined) return false
|
|
8
|
-
if (typeof header.cwd !== 'string' || header.cwd.length === 0) return false
|
|
9
|
-
if (realPath(header.cwd) !== realPath(settings.taHome)) return false
|
|
10
|
-
let preset
|
|
11
|
-
try {
|
|
12
|
-
preset = ctx?.agentPresets?.presetForSession?.(session)
|
|
13
|
-
} catch {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
return typeof preset === 'string' && settings.presets.includes(preset)
|
|
17
|
-
}
|
|
18
|
-
|