dsh-chat-comprehension 0.3.2 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -114
- package/client.js +399 -23
- package/lib/index.js +125 -0
- package/lib/net.mjs +97 -0
- package/lib/qqbot-0.5.3-patches.json +42 -1
- package/lib/qqbot-patch.mjs +17 -9
- package/lib/setup.mjs +431 -0
- package/lib/video.mjs +47 -2
- package/package.json +1 -1
- package/vendor/dsh-agent-md/lib/chat-models.js +116 -0
- package/vendor/dsh-agent-md/lib/chat-persona.js +207 -0
- package/vendor/dsh-agent-md/lib/chat-workspaces.js +81 -0
- package/vendor/dsh-agent-md/lib/index.js +108 -0
- package/vendor/dsh-bili-scroll/index.js +15 -6
- package/vendor/dsh-bili-scroll/prompts/duty.md +6 -3
- package/vendor/dsh-meme/memes.js +1003 -998
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chat-persona.js —— 按「QQ 会话」分开的人格(私聊 / 每个群各自一份)。
|
|
3
|
+
*
|
|
4
|
+
* 背景(2026-11-07 用户要求):QQ 网关可以同时接私聊和多个群,每个群都是一个独立对话;
|
|
5
|
+
* 但人格是按「项目目录(cwd)」注入的,QQ 的这些对话 cwd 都一样 ⇒ 它们共用同一份人格,
|
|
6
|
+
* 分不开。
|
|
7
|
+
*
|
|
8
|
+
* 做法:
|
|
9
|
+
* 1. 网关的 `model-prefs.json.sessionIds` 里有 `<peerKey> → sessionId`;
|
|
10
|
+
* 2. 人格文件存在 `<agentsRoot>/chats/<slug>.md`,登记表在 `<agentsRoot>/chat-personas.json`;
|
|
11
|
+
* 3. 注入时先拿当前会话 id 反查 peerKey:有这个人格就用它(默认**替换**项目人格),
|
|
12
|
+
* 没有就照旧用项目人格。
|
|
13
|
+
*
|
|
14
|
+
* 只 import node: 内置模块与同目录 ./persona.js、./qq.js。
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
17
|
+
import { join } from 'node:path'
|
|
18
|
+
|
|
19
|
+
import { agentsRoot, isEffectivelyEmpty, stripComments } from './persona.js'
|
|
20
|
+
import { qqPrefsPath } from './qq.js'
|
|
21
|
+
|
|
22
|
+
/** 会话人格目录。 */
|
|
23
|
+
export function chatsDir() {
|
|
24
|
+
return join(agentsRoot(), 'chats')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 登记表路径。 */
|
|
28
|
+
export function chatRegistryPath() {
|
|
29
|
+
return join(agentsRoot(), 'chat-personas.json')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** peerKey 转成安全的文件名(去掉冒号与不合法字符)。 */
|
|
33
|
+
export function slugForPeer(peerKey) {
|
|
34
|
+
const cleaned = String(peerKey || '').replace(/[^0-9a-zA-Z_-]+/g, '-').replace(/^-+|-+$/g, '')
|
|
35
|
+
return cleaned === '' ? 'unknown' : cleaned.slice(0, 80)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 读登记表。 */
|
|
39
|
+
export function readChatRegistry() {
|
|
40
|
+
try {
|
|
41
|
+
const raw = readFileSync(chatRegistryPath(), 'utf8')
|
|
42
|
+
const parsed = JSON.parse(raw)
|
|
43
|
+
return parsed !== null && typeof parsed === 'object' ? parsed : {}
|
|
44
|
+
} catch {
|
|
45
|
+
return {}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 写登记表(原子写)。 */
|
|
50
|
+
export function writeChatRegistry(registry) {
|
|
51
|
+
const file = chatRegistryPath()
|
|
52
|
+
mkdirSync(agentsRoot(), { recursive: true })
|
|
53
|
+
const tmp = `${file}.tmp-${process.pid}`
|
|
54
|
+
writeFileSync(tmp, `${JSON.stringify(registry, null, 2)}\n`, 'utf8')
|
|
55
|
+
try {
|
|
56
|
+
writeFileSync(file, readFileSync(tmp))
|
|
57
|
+
unlinkSync(tmp)
|
|
58
|
+
} catch {
|
|
59
|
+
writeFileSync(file, `${JSON.stringify(registry, null, 2)}\n`, 'utf8')
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 读网关的 sessionIds 映射:{ peerKey → sessionId }。 */
|
|
64
|
+
export function readQqSessions() {
|
|
65
|
+
try {
|
|
66
|
+
const raw = readFileSync(qqPrefsPath(), 'utf8')
|
|
67
|
+
const parsed = JSON.parse(raw)
|
|
68
|
+
const ids = parsed?.sessionIds
|
|
69
|
+
return ids !== null && typeof ids === 'object' ? ids : {}
|
|
70
|
+
} catch {
|
|
71
|
+
return {}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** peerKey → { scope, peerId }(`qqbot:<appId>:<scope>:<peerId>`)。 */
|
|
76
|
+
export function parsePeerKey(peerKey) {
|
|
77
|
+
const parts = String(peerKey || '').split(':')
|
|
78
|
+
if (parts.length < 4) return null
|
|
79
|
+
return { appId: parts[1], scope: parts[2], peerId: parts.slice(3).join(':') }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 会话 id → peerKey(反查)。 */
|
|
83
|
+
export function peerKeyForSession(sessionId) {
|
|
84
|
+
const id = String(sessionId || '')
|
|
85
|
+
if (id === '') return ''
|
|
86
|
+
const sessions = readQqSessions()
|
|
87
|
+
for (const [key, value] of Object.entries(sessions)) {
|
|
88
|
+
if (String(value) === id) return key
|
|
89
|
+
}
|
|
90
|
+
return ''
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 一份会话人格的文件路径。 */
|
|
94
|
+
export function chatPersonaFile(peerKey) {
|
|
95
|
+
return join(chatsDir(), `${slugForPeer(peerKey)}.md`)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 读一份会话人格正文(没有/为空返回 null)。 */
|
|
99
|
+
export function readChatPersona(peerKey) {
|
|
100
|
+
const file = chatPersonaFile(peerKey)
|
|
101
|
+
if (!existsSync(file)) return null
|
|
102
|
+
try {
|
|
103
|
+
const raw = readFileSync(file, 'utf8')
|
|
104
|
+
if (isEffectivelyEmpty(raw)) return null
|
|
105
|
+
return { peerKey, path: file, content: raw, chars: stripComments(raw).length }
|
|
106
|
+
} catch {
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 当前会话(按 sessionId)实际生效的会话人格。 */
|
|
112
|
+
export function resolveChatPersonaForSession(sessionId) {
|
|
113
|
+
const peerKey = peerKeyForSession(sessionId)
|
|
114
|
+
if (peerKey === '') return null
|
|
115
|
+
const found = readChatPersona(peerKey)
|
|
116
|
+
if (found === null) return null
|
|
117
|
+
return { ...found, ...(parsePeerKey(peerKey) || {}) }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 保存一份会话人格。 */
|
|
121
|
+
export function saveChatPersona(peerKey, text) {
|
|
122
|
+
if (typeof peerKey !== 'string' || peerKey.trim() === '') throw Object.assign(new Error('缺少 peerKey'), { status: 400 })
|
|
123
|
+
const body = String(text ?? '')
|
|
124
|
+
mkdirSync(chatsDir(), { recursive: true })
|
|
125
|
+
writeFileSync(chatPersonaFile(peerKey), body, 'utf8')
|
|
126
|
+
const registry = readChatRegistry()
|
|
127
|
+
const meta = parsePeerKey(peerKey) || {}
|
|
128
|
+
registry[peerKey] = {
|
|
129
|
+
...registry[peerKey],
|
|
130
|
+
...meta,
|
|
131
|
+
updatedAt: new Date().toISOString(),
|
|
132
|
+
chars: stripComments(body).length,
|
|
133
|
+
}
|
|
134
|
+
writeChatRegistry(registry)
|
|
135
|
+
return { ok: true, path: chatPersonaFile(peerKey), chars: stripComments(body).length }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 删除一份会话人格。 */
|
|
139
|
+
export function removeChatPersona(peerKey) {
|
|
140
|
+
const file = chatPersonaFile(peerKey)
|
|
141
|
+
try { if (existsSync(file)) unlinkSync(file) } catch { /* 删不掉就算了 */ }
|
|
142
|
+
const registry = readChatRegistry()
|
|
143
|
+
if (registry[peerKey] !== undefined) {
|
|
144
|
+
delete registry[peerKey]
|
|
145
|
+
writeChatRegistry(registry)
|
|
146
|
+
}
|
|
147
|
+
return { ok: true }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 列出所有 QQ 会话(私聊 + 每个群),带人格状态;给设置页用。 */
|
|
151
|
+
export function listChats() {
|
|
152
|
+
const sessions = readQqSessions()
|
|
153
|
+
const registry = readChatRegistry()
|
|
154
|
+
const out = []
|
|
155
|
+
for (const [peerKey, sessionId] of Object.entries(sessions)) {
|
|
156
|
+
const meta = parsePeerKey(peerKey) || {}
|
|
157
|
+
const found = readChatPersona(peerKey)
|
|
158
|
+
const reg = registry[peerKey] || {}
|
|
159
|
+
out.push({
|
|
160
|
+
peerKey,
|
|
161
|
+
scope: meta.scope || '',
|
|
162
|
+
peerId: meta.peerId || '',
|
|
163
|
+
appId: meta.appId || '',
|
|
164
|
+
sessionId: String(sessionId || ''),
|
|
165
|
+
label: reg.label || '',
|
|
166
|
+
hasPersona: found !== null,
|
|
167
|
+
chars: found === null ? 0 : found.chars,
|
|
168
|
+
updatedAt: reg.updatedAt || null,
|
|
169
|
+
file: chatPersonaFile(peerKey),
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
out.sort((a, b) => (a.scope === b.scope ? String(a.peerId).localeCompare(String(b.peerId)) : a.scope.localeCompare(b.scope)))
|
|
173
|
+
return out
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 把一个已存在但没登记的人格文件补进登记表(迁移用,幂等)。
|
|
178
|
+
* 只扫 chats 目录里能对上 peerKey slug 的。
|
|
179
|
+
*/
|
|
180
|
+
export function syncChatRegistry() {
|
|
181
|
+
const registry = readChatRegistry()
|
|
182
|
+
const sessions = readQqSessions()
|
|
183
|
+
let changed = false
|
|
184
|
+
for (const peerKey of Object.keys(sessions)) {
|
|
185
|
+
if (registry[peerKey] !== undefined) continue
|
|
186
|
+
if (!existsSync(chatPersonaFile(peerKey))) continue
|
|
187
|
+
registry[peerKey] = { ...(parsePeerKey(peerKey) || {}), updatedAt: new Date().toISOString() }
|
|
188
|
+
changed = true
|
|
189
|
+
}
|
|
190
|
+
if (changed) writeChatRegistry(registry)
|
|
191
|
+
return changed
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** 会话人格合成成注入正文。 */
|
|
195
|
+
export function composeChatPersona(found) {
|
|
196
|
+
const body = stripComments(found.content)
|
|
197
|
+
const where = found.scope === 'group' ? '这个 QQ 群' : 'QQ 私聊'
|
|
198
|
+
const text = [
|
|
199
|
+
'## 人格设定(这个 QQ 会话专属)',
|
|
200
|
+
`以下是使用者为**${where}**单独写下的角色/性格设定(${found.peerKey}),是「你是谁、怎么说话、怎么做事」的第一依据,请始终照此扮演:`,
|
|
201
|
+
'',
|
|
202
|
+
body,
|
|
203
|
+
'',
|
|
204
|
+
'约束:人格设定只决定语气、风格与行事偏好,不改变安全规则、工具用法与任务事实;两者冲突时以安全规则和事实为准。',
|
|
205
|
+
].join('\n')
|
|
206
|
+
return text
|
|
207
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chat-workspaces.js —— 给每个 QQ 对话指定它跑在哪个「工作区」。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要:人格是按工作区(会话 cwd)注入的;QQ 网关默认用同一个 cwd,
|
|
5
|
+
* 于是 QQ 的私聊 / 各个群全都套用同一个工作区的人格。把每个 peer 指定到不同工作区后,
|
|
6
|
+
* 新建的会话会用那个工作区的目录(和它的人格)。
|
|
7
|
+
*
|
|
8
|
+
* 存:<agentsRoot>/chat-workspaces.json { "<peerKey>": "<绝对路径>" }
|
|
9
|
+
* 读:QQ 网关的会话管理器在建新会话时按 peerKey 取(见 qqbot 补丁 v3)。
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { isAbsolute, join } from 'node:path'
|
|
13
|
+
|
|
14
|
+
import { agentsRoot } from './persona.js'
|
|
15
|
+
import { parsePeerKey, readQqSessions } from './chat-persona.js'
|
|
16
|
+
|
|
17
|
+
export function chatWorkspacesPath() {
|
|
18
|
+
return join(agentsRoot(), 'chat-workspaces.json')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function readChatWorkspaces() {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(readFileSync(chatWorkspacesPath(), 'utf8'))
|
|
24
|
+
return parsed !== null && typeof parsed === 'object' ? parsed : {}
|
|
25
|
+
} catch {
|
|
26
|
+
return {}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function writeChatWorkspaces(map) {
|
|
31
|
+
const file = chatWorkspacesPath()
|
|
32
|
+
mkdirSync(agentsRoot(), { recursive: true })
|
|
33
|
+
const body = `${JSON.stringify(map, null, 2)}\n`
|
|
34
|
+
const tmp = `${file}.tmp-${process.pid}`
|
|
35
|
+
writeFileSync(tmp, body, 'utf8')
|
|
36
|
+
try {
|
|
37
|
+
writeFileSync(file, readFileSync(tmp))
|
|
38
|
+
unlinkSync(tmp)
|
|
39
|
+
} catch {
|
|
40
|
+
writeFileSync(file, body, 'utf8')
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 某个 peer 指定的工作区(没有返回 '')。 */
|
|
45
|
+
export function chatWorkspaceOf(peerKey) {
|
|
46
|
+
const map = readChatWorkspaces()
|
|
47
|
+
const cwd = map[peerKey]
|
|
48
|
+
return typeof cwd === 'string' ? cwd : ''
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 保存;cwd 为空表示清除(回到网关默认)。 */
|
|
52
|
+
export function saveChatWorkspace(peerKey, cwd) {
|
|
53
|
+
if (typeof peerKey !== 'string' || peerKey.trim() === '') throw Object.assign(new Error('缺少 peerKey'), { status: 400 })
|
|
54
|
+
const map = readChatWorkspaces()
|
|
55
|
+
const value = String(cwd || '').trim()
|
|
56
|
+
if (value === '') {
|
|
57
|
+
delete map[peerKey]
|
|
58
|
+
writeChatWorkspaces(map)
|
|
59
|
+
return { ok: true, peerKey, cwd: '' }
|
|
60
|
+
}
|
|
61
|
+
if (!isAbsolute(value)) throw Object.assign(new Error('工作区必须是绝对路径'), { status: 400 })
|
|
62
|
+
if (!existsSync(value)) throw Object.assign(new Error('这个目录不存在:' + value), { status: 400 })
|
|
63
|
+
let isDir = false
|
|
64
|
+
try { isDir = statSync(value).isDirectory() } catch { isDir = false }
|
|
65
|
+
if (!isDir) throw Object.assign(new Error('不是目录:' + value), { status: 400 })
|
|
66
|
+
map[peerKey] = value
|
|
67
|
+
writeChatWorkspaces(map)
|
|
68
|
+
return { ok: true, peerKey, cwd: value }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 列表:每个 QQ 会话 + 它指定到哪个工作区。 */
|
|
72
|
+
export function listChatWorkspaces() {
|
|
73
|
+
const sessions = readQqSessions()
|
|
74
|
+
const map = readChatWorkspaces()
|
|
75
|
+
return Object.keys(sessions).map((peerKey) => ({
|
|
76
|
+
peerKey,
|
|
77
|
+
...(parsePeerKey(peerKey) || {}),
|
|
78
|
+
sessionId: String(sessions[peerKey] || ''),
|
|
79
|
+
cwd: typeof map[peerKey] === 'string' ? map[peerKey] : '',
|
|
80
|
+
}))
|
|
81
|
+
}
|
|
@@ -43,6 +43,17 @@ import {
|
|
|
43
43
|
writeTextFile,
|
|
44
44
|
} from './persona.js'
|
|
45
45
|
import { bindQqPeer, parsePeerKey, qqStatus, unbindQqPeer } from './qq.js'
|
|
46
|
+
import {
|
|
47
|
+
composeChatPersona,
|
|
48
|
+
listChats,
|
|
49
|
+
readChatPersona,
|
|
50
|
+
removeChatPersona,
|
|
51
|
+
resolveChatPersonaForSession,
|
|
52
|
+
saveChatPersona,
|
|
53
|
+
syncChatRegistry,
|
|
54
|
+
} from './chat-persona.js'
|
|
55
|
+
import { chatModelForSession, globalModel, listChatModels, readChatModels, removeChatModel, saveChatModel } from './chat-models.js'
|
|
56
|
+
import { chatWorkspaceOf, listChatWorkspaces, saveChatWorkspace } from './chat-workspaces.js'
|
|
46
57
|
|
|
47
58
|
export const name = 'agent-md'
|
|
48
59
|
|
|
@@ -64,6 +75,9 @@ const DEFAULT_CONFIG = {
|
|
|
64
75
|
enabled: true,
|
|
65
76
|
includeGlobal: false,
|
|
66
77
|
projectPersonaEnabled: true,
|
|
78
|
+
// 按 QQ 会话分开的人格 / 模型(2026-11-07)
|
|
79
|
+
chatPersonaEnabled: true,
|
|
80
|
+
chatModelEnabled: true,
|
|
67
81
|
localNames: ['AGENT.md'],
|
|
68
82
|
showInSettings: true,
|
|
69
83
|
}
|
|
@@ -124,6 +138,8 @@ function loadConfig() {
|
|
|
124
138
|
// 全局人格已移除:无论旧配置写什么,都强制不注入。
|
|
125
139
|
config.includeGlobal = false
|
|
126
140
|
if (typeof parsed.projectPersonaEnabled === 'boolean') config.projectPersonaEnabled = parsed.projectPersonaEnabled
|
|
141
|
+
if (typeof parsed.chatPersonaEnabled === 'boolean') config.chatPersonaEnabled = parsed.chatPersonaEnabled
|
|
142
|
+
if (typeof parsed.chatModelEnabled === 'boolean') config.chatModelEnabled = parsed.chatModelEnabled
|
|
127
143
|
if (typeof parsed.showInSettings === 'boolean') config.showInSettings = parsed.showInSettings
|
|
128
144
|
if (Array.isArray(parsed.localNames)) {
|
|
129
145
|
const names = parsed.localNames.filter((n) => typeof n === 'string' && n.trim() !== '' && !n.includes('/') && !n.includes('\\') && !n.includes('..'))
|
|
@@ -374,6 +390,20 @@ export function apply(ctx) {
|
|
|
374
390
|
if (!config.enabled) return ''
|
|
375
391
|
const cwd = context?.agent?.session?.header?.cwd
|
|
376
392
|
const resolvedCwd = typeof cwd === 'string' ? cwd : ''
|
|
393
|
+
const sessionId = String(context?.agent?.id || context?.agent?.session?.id || '')
|
|
394
|
+
// 这个会话是 QQ 接进来的、并且单独写了人格 ⇒ 用它(替代项目人格),不同群/私聊互不干扰
|
|
395
|
+
if (config.chatPersonaEnabled !== false && sessionId !== '') {
|
|
396
|
+
try {
|
|
397
|
+
const chat = resolveChatPersonaForSession(sessionId)
|
|
398
|
+
if (chat !== null) {
|
|
399
|
+
const text = composeChatPersona(chat)
|
|
400
|
+
if (text !== '') {
|
|
401
|
+
recordInjection({ at: new Date().toISOString(), cwd: resolvedCwd, sessionId, chatPeer: chat.peerKey, chars: text.length, sources: [{ label: 'QQ 会话', path: chat.path, chars: chat.chars, kind: 'chat' }] })
|
|
402
|
+
return text
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
} catch { /* 会话人格坏了不能影响项目人格 */ }
|
|
406
|
+
}
|
|
377
407
|
const composed = composePersona({ cwd: resolvedCwd, config })
|
|
378
408
|
// 留痕:这一回合到底注入了什么(文本没变就不重复记)
|
|
379
409
|
if (composed.text !== '') {
|
|
@@ -393,6 +423,30 @@ export function apply(ctx) {
|
|
|
393
423
|
}
|
|
394
424
|
}, 'dsh-agent-md: persona context')
|
|
395
425
|
|
|
426
|
+
// ---- 1b. 按 QQ 会话指定模型(agent 创建时应用一次,只影响这个会话) ----------
|
|
427
|
+
ctx.effect(() => {
|
|
428
|
+
const handler = ({ agent }) => {
|
|
429
|
+
try {
|
|
430
|
+
if (!config.chatModelEnabled || config.enabled === false) return
|
|
431
|
+
const sessionId = String(agent?.id || '')
|
|
432
|
+
if (sessionId === '') return
|
|
433
|
+
// 会话专属模型优先;否则用「默认模型(全局)」——这样 QQ 的私聊/群也跟着全局走
|
|
434
|
+
const wanted = chatModelForSession(sessionId) || globalModel()
|
|
435
|
+
if (wanted === null) return
|
|
436
|
+
const current = typeof agent.model?.current === 'function' ? agent.model.current() : undefined
|
|
437
|
+
if (current !== undefined && current.provider === wanted.provider && current.model === wanted.model) return
|
|
438
|
+
agent.model.select(wanted.reasoningEffort === undefined
|
|
439
|
+
? { provider: wanted.provider, model: wanted.model }
|
|
440
|
+
: { provider: wanted.provider, model: wanted.model, reasoningEffort: wanted.reasoningEffort })
|
|
441
|
+
console.log(`[agent-md] 会话 ${sessionId.slice(0, 20)}… 使用指定模型 ${wanted.provider}/${wanted.model}`)
|
|
442
|
+
} catch (error) {
|
|
443
|
+
console.warn('[agent-md] 应用会话模型失败:' + String((error && error.message) || error))
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
const off = ctx.on('agent/created', handler)
|
|
447
|
+
return typeof off === 'function' ? off : () => {}
|
|
448
|
+
}, 'dsh-agent-md: chat model per session')
|
|
449
|
+
|
|
396
450
|
// ---- 2. 同源 API(仅网页宿主有 webServer;headless 宿主跳过) ------------
|
|
397
451
|
// webServer 是可选依赖:它只服务设置页。cordis 里没写进 inject 的服务,ctx.get 与
|
|
398
452
|
// ctx.webServer 都拿不到(回 undefined / 抛异常),所以只能走 ctx.inject 延迟注册——
|
|
@@ -681,6 +735,60 @@ export function apply(ctx) {
|
|
|
681
735
|
// 网关(@tencent-connect/dsh-qqbot)只有在**本进程**里跑,才能和网页
|
|
682
736
|
// 共享同一个 live agent:QQ 消息进这个对话、这个对话的回复再发回 QQ。
|
|
683
737
|
// 绑定关系落在网关自己的 prefs(~/.dsh-qqbot/model-prefs.json)里。
|
|
738
|
+
// ---- 按 QQ 会话分开的人格 / 模型(2026-11-07)----
|
|
739
|
+
if (route === '/chats' && req.method === 'GET') {
|
|
740
|
+
syncChatRegistry()
|
|
741
|
+
const providers = (() => {
|
|
742
|
+
try {
|
|
743
|
+
const list = typeof ctx.llm?.listProviders === 'function' ? ctx.llm.listProviders() : []
|
|
744
|
+
return (Array.isArray(list) ? list : []).map((p) => ({ id: p.id ?? p.provider ?? p.name ?? '', label: p.label ?? p.name ?? p.id ?? '' }))
|
|
745
|
+
} catch { return [] }
|
|
746
|
+
})()
|
|
747
|
+
const models = {}
|
|
748
|
+
for (const p of providers) {
|
|
749
|
+
try {
|
|
750
|
+
const list = await (typeof ctx.llm?.listModels === 'function' ? ctx.llm.listModels(p.id) : [])
|
|
751
|
+
models[p.id] = (Array.isArray(list) ? list : []).map((m) => ({ id: m.id ?? m.model ?? '', label: m.label ?? m.name ?? m.id ?? '' }))
|
|
752
|
+
} catch { models[p.id] = [] }
|
|
753
|
+
}
|
|
754
|
+
return sendJson(res, 200, {
|
|
755
|
+
enabled: config.chatPersonaEnabled !== false,
|
|
756
|
+
modelEnabled: config.chatModelEnabled !== false,
|
|
757
|
+
chats: listChats().map((c) => ({ ...c, cwd: chatWorkspaceOf(c.peerKey) })),
|
|
758
|
+
models: listChatModels(),
|
|
759
|
+
workspaces: (() => { try { return listWorkspaces() } catch { return [] } })(),
|
|
760
|
+
providers,
|
|
761
|
+
providerModels: models,
|
|
762
|
+
dedupe: {},
|
|
763
|
+
})
|
|
764
|
+
}
|
|
765
|
+
if (route === '/chats/persona' && req.method === 'POST') {
|
|
766
|
+
const body = await readBody(req)
|
|
767
|
+
const peerKey = String(body.peerKey || '')
|
|
768
|
+
if (typeof body.text !== 'string') throw Object.assign(new Error('缺少 text'), { status: 400 })
|
|
769
|
+
const saved = saveChatPersona(peerKey, body.text)
|
|
770
|
+
return sendJson(res, 200, { ok: true, ...saved, chats: listChats() })
|
|
771
|
+
}
|
|
772
|
+
if (route === '/chats/persona/delete' && req.method === 'POST') {
|
|
773
|
+
const body = await readBody(req)
|
|
774
|
+
const removed = removeChatPersona(String(body.peerKey || ''))
|
|
775
|
+
return sendJson(res, 200, { ...removed, chats: listChats() })
|
|
776
|
+
}
|
|
777
|
+
if (route === '/chats/workspace' && req.method === 'POST') {
|
|
778
|
+
const body = await readBody(req)
|
|
779
|
+
const saved = saveChatWorkspace(String(body.peerKey || ''), String(body.cwd || ''))
|
|
780
|
+
return sendJson(res, 200, { ...saved, chats: listChats().map((c) => ({ ...c, cwd: chatWorkspaceOf(c.peerKey) })) })
|
|
781
|
+
}
|
|
782
|
+
if (route === '/chats/model' && req.method === 'POST') {
|
|
783
|
+
const body = await readBody(req)
|
|
784
|
+
const saved = saveChatModel(String(body.peerKey || ''), { provider: body.provider, model: body.model, reasoningEffort: body.reasoningEffort })
|
|
785
|
+
return sendJson(res, 200, { ...saved, models: listChatModels() })
|
|
786
|
+
}
|
|
787
|
+
if (route === '/chats/model/delete' && req.method === 'POST') {
|
|
788
|
+
const body = await readBody(req)
|
|
789
|
+
const removed = removeChatModel(String(body.peerKey || ''))
|
|
790
|
+
return sendJson(res, 200, { ...removed, models: listChatModels() })
|
|
791
|
+
}
|
|
684
792
|
if (route === '/qq' && req.method === 'GET') {
|
|
685
793
|
return sendJson(res, 200, { qq: qqStatus(ctx) })
|
|
686
794
|
}
|
|
@@ -101,6 +101,10 @@ export const Config = !z ? undefined : z.object({
|
|
|
101
101
|
focusTopics: z.string().default('').extra('volatile', true),
|
|
102
102
|
/** 人设来源:「人格」页(dsh-agent-md)的性格/语气 */
|
|
103
103
|
personaFromPage: z.boolean().default(true).extra('volatile', true),
|
|
104
|
+
/** 值班轮用的 provider(留空 = 跟当前默认模型) */
|
|
105
|
+
roundProvider: z.string().default('').extra('volatile', true),
|
|
106
|
+
/** 值班轮用的 model(留空 = 跟当前默认模型) */
|
|
107
|
+
roundModel: z.string().default('').extra('volatile', true),
|
|
104
108
|
/** 「人格」页对应的项目目录 */
|
|
105
109
|
personaCwd: z.string().default('/home/aaa/文档/ds HARNESS').extra('volatile', true),
|
|
106
110
|
/** 「别像 AI」那段文字(使用者自己写;留空就不加) */
|
|
@@ -266,7 +270,7 @@ function reportMeta() {
|
|
|
266
270
|
personaPrompt: '',
|
|
267
271
|
perDay: 5, peakValley: false, noon: true, night: true, autoComment: false, transcribe: false, asrModel: 'small',
|
|
268
272
|
dmMode: 'only', dmUid: 0,
|
|
269
|
-
keywords: [], commentPerRound: 1, mentionName: '', pythonPath: 'python', dshBin: '', headlessProfile: 'headless', overlayMcp: true, workspace: '', reportLevel: 'full', replyToComments: false, replyPerRound: 1, favFolderId: 0,
|
|
273
|
+
keywords: [], roundProvider: '', roundModel: '', commentPerRound: 1, mentionName: '', pythonPath: 'python', dshBin: '', headlessProfile: 'headless', overlayMcp: true, workspace: '', reportLevel: 'full', replyToComments: false, replyPerRound: 1, favFolderId: 0,
|
|
270
274
|
customTimes: '', timeSync: true, focusFollowings: true, focusLimit: 12, focusTopicsEnabled: false, focusTopics: '', personaFromPage: true, personaCwd: '/home/aaa/文档/ds HARNESS', extraPrompt: '', memoryExcerpt: true,
|
|
271
275
|
}
|
|
272
276
|
const normalize = (src, base) => {
|
|
@@ -964,7 +968,7 @@ function reportMeta() {
|
|
|
964
968
|
tool({
|
|
965
969
|
name: 'bili_config',
|
|
966
970
|
description: '读 / 改「刷B站」的设置。不给 `patch` 就是读;给了就改(只认 schema 里的字段)。\n'
|
|
967
|
-
+ '例:`{"perDay":5,"peakValley":true,"noon":true,"night":true,"autoComment":false,"transcribe":false,"keywords":["
|
|
971
|
+
+ '例:`{"perDay":5,"peakValley":true,"noon":true,"night":true,"autoComment":false,"transcribe":false,"keywords":["技术评测"]}`;'
|
|
968
972
|
+ '私信投递:`{"dmMode":"only","dmUid":12345678}`(dmMode = off / only / both)。',
|
|
969
973
|
parameters: { patch: { type: 'object', additionalProperties: true, description: '要改的字段(可省)' } },
|
|
970
974
|
async execute(args) {
|
|
@@ -1508,8 +1512,11 @@ function reportMeta() {
|
|
|
1508
1512
|
// ⇒ overlay 里补一条 agent-default-model,**优先跟随用户当前选的模型**;拿不到就不写(保持原行为)✓
|
|
1509
1513
|
try {
|
|
1510
1514
|
const sel = ctx.get('agentDefaultModel')?.currentSelection?.() ?? null
|
|
1511
|
-
|
|
1512
|
-
const
|
|
1515
|
+
// ⭐ 2026-11-07(用户要求):值班轮可以有自己独立的模型,和 QQ / 网页默认互不干扰。
|
|
1516
|
+
const cfgProvider = String(cfg.roundProvider || '').trim()
|
|
1517
|
+
const cfgModel = String(cfg.roundModel || '').trim()
|
|
1518
|
+
const selProvider = cfgProvider !== '' ? cfgProvider : (sel?.provider ?? sel?.providerId)
|
|
1519
|
+
const selModel = cfgModel !== '' ? cfgModel : (sel?.model ?? sel?.modelId)
|
|
1513
1520
|
if (selProvider && selModel) {
|
|
1514
1521
|
yml.push(
|
|
1515
1522
|
'- id: agent-default-model',
|
|
@@ -2703,7 +2710,7 @@ function reportMeta() {
|
|
|
2703
2710
|
out.steps.push('登录有效')
|
|
2704
2711
|
} catch (e) { out.error = '登录检查失败:' + (e?.message ?? e); return out }
|
|
2705
2712
|
try {
|
|
2706
|
-
const s = await call('bili_search', { keyword: '
|
|
2713
|
+
const s = await call('bili_search', { keyword: 'B站', num: 3 })
|
|
2707
2714
|
const t = typeof s === 'string' ? s : JSON.stringify(s)
|
|
2708
2715
|
out.sample = t.slice(0, 160)
|
|
2709
2716
|
out.steps.push('能搜到东西')
|
|
@@ -2745,6 +2752,8 @@ function reportMeta() {
|
|
|
2745
2752
|
focusFollowings: Boolean(cfg.focusFollowings),
|
|
2746
2753
|
focusCount: focusCache.list.length,
|
|
2747
2754
|
personaFromPage: true,
|
|
2755
|
+
roundProvider: String(cfg.roundProvider || ''),
|
|
2756
|
+
roundModel: String(cfg.roundModel || ''),
|
|
2748
2757
|
personaChars: (() => { try { return personaPageText().length } catch { return 0 } })(),
|
|
2749
2758
|
personaCwd: cfg.personaCwd,
|
|
2750
2759
|
memoryExcerpt: Boolean(cfg.memoryExcerpt),
|
|
@@ -2838,7 +2847,7 @@ function reportMeta() {
|
|
|
2838
2847
|
for (const k of ['perDay', 'peakValley', 'noon', 'night', 'autoComment', 'transcribe', 'asrModel',
|
|
2839
2848
|
'commentPerRound', 'mentionName', 'dmMode', 'dmUid',
|
|
2840
2849
|
'keywords', 'pythonPath', 'dshBin', 'headlessProfile', 'workspace', 'reportLevel', 'replyToComments', 'replyPerRound', 'personaPrompt', 'dmWatch', 'dmWatchMinutes', 'dmReplyPerDay', 'dmOwnerUid',
|
|
2841
|
-
'customTimes', 'timeSync', 'focusFollowings', 'focusLimit', 'focusTopicsEnabled', 'focusTopics', 'personaFromPage', 'personaCwd', 'extraPrompt', 'memoryExcerpt',
|
|
2850
|
+
'customTimes', 'timeSync', 'focusFollowings', 'focusLimit', 'focusTopicsEnabled', 'focusTopics', 'roundProvider', 'roundModel', 'personaFromPage', 'personaCwd', 'extraPrompt', 'memoryExcerpt',
|
|
2842
2851
|
'dmWatch', 'dmWatchMinutes', 'dmReplyPerDay', 'dmOwnerUid', 'dmReadImages', 'dmVisionModel']) {
|
|
2843
2852
|
if (k in body) patch[k] = body[k]
|
|
2844
2853
|
}
|
|
@@ -98,7 +98,8 @@
|
|
|
98
98
|
评论区就会堆成一片"同款插件互相报到"。推荐流按各自的账号画像推,天然散开。
|
|
99
99
|
· 从返回里**随机挑几条**(别固定取前 N —— 画像相近的人还是会撞车)
|
|
100
100
|
· 推荐流里混着娱乐 / 带货 / 直播切片,**不感兴趣的直接跳过**,不用勉强
|
|
101
|
-
· ⚠️
|
|
101
|
+
· ⚠️ 推荐流里如果出现「讲 DSH / 插件 / 使用者自己项目」的视频 —— **除非关注范围明确写了,否则跳过**
|
|
102
|
+
(他每天在做的就是这个,不需要在 B站 再看一遍 ✗)
|
|
102
103
|
- **填了关键词** ⇒ 用 **`bili_search(keyword=…)`** 搜(近 7 天优先),一个词一轮,别一次搜五遍
|
|
103
104
|
2. 从结果里挑出**值得的**,条数看设置页的「定量刷(每天几条)」;**判重** —— 已经看过的跳过。
|
|
104
105
|
⭐ **判重表用 `duty_seen_append(bvid, title, up, status)` 写**(一行一条;路径由工具自己定,你不用管)。
|
|
@@ -263,8 +264,10 @@
|
|
|
263
264
|
|
|
264
265
|
## 判据
|
|
265
266
|
|
|
266
|
-
-
|
|
267
|
-
-
|
|
267
|
+
- **值得**:跟「这一轮关注什么」对得上(关注 UP 的新投稿 / 使用者自己写的题材)、有新信息、有实操细节、几天内的新视频
|
|
268
|
+
- **不值得**:跟关注范围无关的、入门教程、纯流量标题党、吵架的场子、早就知道的旧闻
|
|
269
|
+
- 🔴 **不要因为「这跟 DSH / 插件 / 使用者正在做的项目有关」就挑它**:他刷 B站 是想看自己关注的东西,
|
|
270
|
+
不是想再听一遍自己天天在做的项目。除非关注范围里明确写了这个题材,否则**一律不挑** ✓
|
|
268
271
|
- 一句话:**这条值不值得占用他一次注意力?**
|
|
269
272
|
|
|
270
273
|
## 产物
|