dsh-chat-comprehension 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -12
- package/client.js +374 -47
- package/lib/engines.mjs +36 -5
- package/lib/index.js +198 -17
- package/lib/qqbot-0.5.3-patches.json +31 -1
- package/lib/qqbot-patch.mjs +1 -1
- package/lib/video.mjs +1 -1
- package/package.json +1 -1
- package/vendor/dsh-agent-md/lib/chat-persona.js +9 -3
- package/vendor/dsh-agent-md/lib/index.js +26 -8
- package/vendor/dsh-agent-md/lib/qq.js +64 -0
- package/vendor/dsh-bili-scroll/index.js +25 -9
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* 以真实路径解析,裸包名会解析失败)。
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { randomUUID } from 'node:crypto'
|
|
24
25
|
import { spawnSync } from 'node:child_process'
|
|
25
26
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from 'node:fs'
|
|
26
27
|
import { homedir } from 'node:os'
|
|
@@ -365,6 +366,59 @@ export function peerKeyFor(appId, scope, peerId) {
|
|
|
365
366
|
return `${KEY_PREFIX}${appId}:${scope}:${peerId}`
|
|
366
367
|
}
|
|
367
368
|
|
|
369
|
+
/**
|
|
370
|
+
* 把「这个 QQ 聊天用哪个模型」写进网关自己的 per-peer 覆盖表。
|
|
371
|
+
* 网关建会话/恢复会话时会读它,所以新建的群也能一开口就用对模型。
|
|
372
|
+
* @param {string} peerKey `qqbot:<appId>:<scope>:<peerId>`
|
|
373
|
+
* @param {{provider:string,model:string,reasoningEffort?:string}|null} route null 表示删掉覆盖
|
|
374
|
+
*/
|
|
375
|
+
export function setQqModelOverride(peerKey, route) {
|
|
376
|
+
const key = String(peerKey || '')
|
|
377
|
+
if (parsePeerKey(key) === null) return false
|
|
378
|
+
const prefs = readQqPrefs()
|
|
379
|
+
if (route && String(route.provider || '') !== '' && String(route.model || '') !== '') {
|
|
380
|
+
prefs.overrides[key] = {
|
|
381
|
+
provider: String(route.provider),
|
|
382
|
+
model: String(route.model),
|
|
383
|
+
...(String(route.reasoningEffort || '') !== '' ? { reasoningEffort: String(route.reasoningEffort) } : {}),
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
delete prefs.overrides[key]
|
|
387
|
+
}
|
|
388
|
+
writeQqPrefs(prefs)
|
|
389
|
+
return true
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 让人格 / 工作区改动立刻作用到这个 QQ 聊天:
|
|
394
|
+
* 1. 网关补丁 v6 有 companionQq.resetSession 时,让它 fork 到新目录(保留历史);
|
|
395
|
+
* 2. 没有的话退回「换一个新的 sessionId + 重启网关」,下一条消息会按新工作区新建会话
|
|
396
|
+
* (更早的对话仍然在 QQ 记忆里,不会被忘掉)。
|
|
397
|
+
* @returns {Promise<{ok:boolean, rebuilt?:boolean, error?:string}>}
|
|
398
|
+
*/
|
|
399
|
+
export async function resetQqPeerSession(ctx, peerKey) {
|
|
400
|
+
const key = String(peerKey || '')
|
|
401
|
+
if (parsePeerKey(key) === null) return { ok: false, error: '不是合法的 QQ 会话 key' }
|
|
402
|
+
try {
|
|
403
|
+
const qq = ctx && typeof ctx.get === 'function' ? ctx.get('companionQq') : null
|
|
404
|
+
if (qq && typeof qq.resetSession === 'function') {
|
|
405
|
+
const r = await qq.resetSession(key)
|
|
406
|
+
if (r && r.ok) return r
|
|
407
|
+
}
|
|
408
|
+
} catch { /* 老补丁没有这个方法 */ }
|
|
409
|
+
try {
|
|
410
|
+
const prefs = readQqPrefs()
|
|
411
|
+
prefs.sessionIds[key] = randomUUID()
|
|
412
|
+
writeQqPrefs(prefs)
|
|
413
|
+
const { entry } = findQqEntry(ctx)
|
|
414
|
+
await stopGatewayEntry(entry)
|
|
415
|
+
const reload = await startGatewayEntry(ctx, entry)
|
|
416
|
+
return { ok: true, rebuilt: false, reload }
|
|
417
|
+
} catch (error) {
|
|
418
|
+
return { ok: false, error: String((error && error.message) || error) }
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
368
422
|
/**
|
|
369
423
|
* 列出网关已经记下的 QQ 账号(= prefs.sessionIds 的 key)。
|
|
370
424
|
*
|
|
@@ -374,11 +428,21 @@ export function peerKeyFor(appId, scope, peerId) {
|
|
|
374
428
|
export function listQqPeers(prefs) {
|
|
375
429
|
const table = (prefs || readQqPrefs()).sessionIds
|
|
376
430
|
const peers = []
|
|
431
|
+
const seen = new Set()
|
|
377
432
|
for (const [key, sessionId] of Object.entries(table)) {
|
|
378
433
|
const info = parsePeerKey(key)
|
|
379
434
|
if (info === null) continue
|
|
435
|
+
seen.add(info.key)
|
|
380
436
|
peers.push({ ...info, sessionId: typeof sessionId === 'string' ? sessionId : '' })
|
|
381
437
|
}
|
|
438
|
+
// 网关卡(补丁 v5 写)里有、但 prefs 还没登记的聊天(比如第一次说话的群)也要列出来,
|
|
439
|
+
// 否则页面里根本看不到这个群,人格/工作区/模型都没地方设。
|
|
440
|
+
for (const [key, row] of Object.entries(readQqPeers())) {
|
|
441
|
+
const info = parsePeerKey(key)
|
|
442
|
+
if (info === null || seen.has(info.key)) continue
|
|
443
|
+
seen.add(info.key)
|
|
444
|
+
peers.push({ ...info, sessionId: row && typeof row.current === 'string' ? row.current : '' })
|
|
445
|
+
}
|
|
382
446
|
peers.sort((a, b) => (a.scope === b.scope ? a.peerId.localeCompare(b.peerId) : a.scope === 'c2c' ? -1 : 1))
|
|
383
447
|
return peers
|
|
384
448
|
}
|
|
@@ -77,7 +77,7 @@ export const Config = !z ? undefined : z.object({
|
|
|
77
77
|
/** 关注关键词(空了用章程里默认那几组) */
|
|
78
78
|
keywords: z.array(z.string()).default([]).extra('volatile', true),
|
|
79
79
|
/** Python:指向 venv 里的那个最好 */
|
|
80
|
-
pythonPath: z.string().default('python').extra('volatile', true),
|
|
80
|
+
pythonPath: z.string().default(process.platform === 'win32' ? 'python' : 'python3').extra('volatile', true),
|
|
81
81
|
/** dsh 的 bin.js(不填就试自动探测,再退化成 shell 里的 dsh) */
|
|
82
82
|
dshBin: z.string().default('').extra('volatile', true),
|
|
83
83
|
/** headless 那一轮用哪个 profile */
|
|
@@ -106,7 +106,7 @@ export const Config = !z ? undefined : z.object({
|
|
|
106
106
|
/** 值班轮用的 model(留空 = 跟当前默认模型) */
|
|
107
107
|
roundModel: z.string().default('').extra('volatile', true),
|
|
108
108
|
/** 「人格」页对应的项目目录 */
|
|
109
|
-
personaCwd: z.string().default('
|
|
109
|
+
personaCwd: z.string().default('').extra('volatile', true),
|
|
110
110
|
/** 「别像 AI」那段文字(使用者自己写;留空就不加) */
|
|
111
111
|
extraPrompt: z.string().default('').extra('volatile', true),
|
|
112
112
|
/** 带上 QQ 对话的记忆摘要(<DSH_HOME>/agents/qq-memory.md) */
|
|
@@ -270,8 +270,8 @@ function reportMeta() {
|
|
|
270
270
|
personaPrompt: '',
|
|
271
271
|
perDay: 5, peakValley: false, noon: true, night: true, autoComment: false, transcribe: false, asrModel: 'small',
|
|
272
272
|
dmMode: 'only', dmUid: 0,
|
|
273
|
-
keywords: [], roundProvider: '', roundModel: '', commentPerRound: 1, mentionName: '', pythonPath: 'python', dshBin: '', headlessProfile: 'headless', overlayMcp: true, workspace: '', reportLevel: 'full', replyToComments: false, replyPerRound: 1, favFolderId: 0,
|
|
274
|
-
customTimes: '', timeSync: true, focusFollowings: true, focusLimit: 12, focusTopicsEnabled: false, focusTopics: '', personaFromPage: true, personaCwd: '
|
|
273
|
+
keywords: [], roundProvider: '', roundModel: '', commentPerRound: 1, mentionName: '', pythonPath: process.platform === 'win32' ? 'python' : 'python3', dshBin: '', headlessProfile: 'headless', overlayMcp: true, workspace: '', reportLevel: 'full', replyToComments: false, replyPerRound: 1, favFolderId: 0,
|
|
274
|
+
customTimes: '', timeSync: true, focusFollowings: true, focusLimit: 12, focusTopicsEnabled: false, focusTopics: '', personaFromPage: true, personaCwd: '', extraPrompt: '', memoryExcerpt: true,
|
|
275
275
|
}
|
|
276
276
|
const normalize = (src, base) => {
|
|
277
277
|
const out = { ...base }
|
|
@@ -473,7 +473,7 @@ function reportMeta() {
|
|
|
473
473
|
*/
|
|
474
474
|
const personaPageText = () => {
|
|
475
475
|
try {
|
|
476
|
-
const file = join(dshHomeDir(), 'agents', 'projects', `${slugForCwd(cfg.personaCwd)}.md`)
|
|
476
|
+
const file = join(dshHomeDir(), 'agents', 'projects', `${slugForCwd(cfg.personaCwd || cfg.workspace)}.md`)
|
|
477
477
|
let text = readFileSync(file, 'utf8')
|
|
478
478
|
text = text.replace(/<!--[\s\S]*?-->/g, '').trim()
|
|
479
479
|
const parts = text.split(/(?=【[^】]+】)/)
|
|
@@ -649,7 +649,7 @@ function reportMeta() {
|
|
|
649
649
|
if (!existsSync(script)) throw new Error(`家里没有 mcp_server.py(应有 ${script})—— 装上插件后重启一次 dsh 会自动铺好`)
|
|
650
650
|
mcpKey = mcpKeyNow()
|
|
651
651
|
mcp = new McpClient({
|
|
652
|
-
command: cfg.pythonPath || 'python',
|
|
652
|
+
command: cfg.pythonPath || (process.platform === 'win32' ? 'python' : 'python3'),
|
|
653
653
|
args: [script],
|
|
654
654
|
cwd: stateDir, // 凭证落在家里 ✓
|
|
655
655
|
// ⭐ 这个内置的 Python MCP 会往 stdout 打中文(ensure_ascii=False);
|
|
@@ -1512,18 +1512,34 @@ function reportMeta() {
|
|
|
1512
1512
|
// ⇒ overlay 里补一条 agent-default-model,**优先跟随用户当前选的模型**;拿不到就不写(保持原行为)✓
|
|
1513
1513
|
try {
|
|
1514
1514
|
const sel = ctx.get('agentDefaultModel')?.currentSelection?.() ?? null
|
|
1515
|
+
// companion 的「默认模型(全局)」:只作用于 QQ 和 B站 值班,绝不改 DSH 网页对话的默认模型。
|
|
1516
|
+
// (0.5.0 起不再通过改 agentDefaultModel 实现,所以在这里直接读那份文件。)
|
|
1517
|
+
const companion = (() => {
|
|
1518
|
+
try {
|
|
1519
|
+
const home = String(process.env.DSH_HOME || '').trim() || join(homedir(), '.dsh')
|
|
1520
|
+
const raw = readJson(join(home, 'agents', 'companion-model.json'), {}) || {}
|
|
1521
|
+
const provider = String(raw.provider || '').trim()
|
|
1522
|
+
const model = String(raw.model || '').trim()
|
|
1523
|
+
return provider !== '' && model !== '' ? { provider, model, reasoningEffort: String(raw.reasoningEffort || '').trim() } : null
|
|
1524
|
+
} catch { return null }
|
|
1525
|
+
})()
|
|
1515
1526
|
// ⭐ 2026-11-07(用户要求):值班轮可以有自己独立的模型,和 QQ / 网页默认互不干扰。
|
|
1516
1527
|
const cfgProvider = String(cfg.roundProvider || '').trim()
|
|
1517
1528
|
const cfgModel = String(cfg.roundModel || '').trim()
|
|
1518
|
-
|
|
1519
|
-
|
|
1529
|
+
// headless 值班 profile 里只保证有 deepseek-account 这条路由;companion 默认若是别的
|
|
1530
|
+
// (比如 packyapi),headless 里没有 adapter,照搬会直接 NO_ADAPTER。所以只在可用时沿用。
|
|
1531
|
+
const useCompanion = companion !== null && cfgProvider === '' && cfgModel === ''
|
|
1532
|
+
&& /^deepseek-account$/.test(String(companion.provider || ''))
|
|
1533
|
+
const selProvider = cfgProvider !== '' ? cfgProvider : (useCompanion ? companion.provider : (sel?.provider ?? sel?.providerId))
|
|
1534
|
+
const selModel = cfgModel !== '' ? cfgModel : (useCompanion ? companion.model : (sel?.model ?? sel?.modelId))
|
|
1535
|
+
const selEffort = useCompanion ? companion.reasoningEffort : String(sel?.reasoningEffort ?? '')
|
|
1520
1536
|
if (selProvider && selModel) {
|
|
1521
1537
|
yml.push(
|
|
1522
1538
|
'- id: agent-default-model',
|
|
1523
1539
|
' config:',
|
|
1524
1540
|
' provider: ' + String(selProvider),
|
|
1525
1541
|
' model: ' + String(selModel),
|
|
1526
|
-
...(
|
|
1542
|
+
...(selEffort ? [' reasoningEffort: ' + String(selEffort)] : []),
|
|
1527
1543
|
'',
|
|
1528
1544
|
)
|
|
1529
1545
|
}
|