dsh-onebot-genji 0.12.0 → 0.12.2
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/lib/bridge.js +9 -140
- package/lib/client.js +125 -117
- package/lib/inbound.js +4 -36
- package/lib/index.js +5 -2
- package/lib/interim.js +1 -10
- package/lib/outbound.js +7 -15
- package/lib/prompt.js +2 -0
- package/lib/settings-remote.js +11 -6
- package/lib/split.js +0 -50
- package/lib/tools.js +0 -2
- package/lib/types/bridge.d.ts +2 -0
- package/lib/types/index.d.ts +1 -0
- package/package.json +110 -110
package/lib/bridge.js
CHANGED
|
@@ -9,10 +9,6 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
11
11
|
import { realpath } from 'node:fs/promises';
|
|
12
|
-
// 2026-11-17 本地补丁:会话标题按昵称/群名定名——同步日志 + 文件名工具。
|
|
13
|
-
const __qqTitleNickPatched = true;
|
|
14
|
-
import { appendFileSync as __qqTitleAppend } from 'node:fs';
|
|
15
|
-
import { homedir as __qqTitleHome } from 'node:os';
|
|
16
12
|
import { transcriptLabel } from './stt.js';
|
|
17
13
|
import { buildChatId, classifyUserRole, splitChatId } from './chat.js';
|
|
18
14
|
import { buildPlatformPrompt } from './prompt.js';
|
|
@@ -41,19 +37,6 @@ import { currentTrace, newTraceId, runWithTrace, TRACE_REASONS } from './trace.j
|
|
|
41
37
|
import { runInjectRound, currentInjectRound, isWriteAction, INTERCEPTED_MESSAGE_ID } from './inject.js';
|
|
42
38
|
import { healthReport, exportDiagnostics } from './health.js';
|
|
43
39
|
import { FailureRefRegistry, failureRefSuffix } from './ref.js';
|
|
44
|
-
// ── 回合形式掷骰(2026-11-16 重打;0.11.0 把老 turn-form.js 整个删了)──────
|
|
45
|
-
// 私聊 / 群聊同一套:语音 10%、表情包 39%,其余纯文字。主人 2026-11-13 定。
|
|
46
|
-
const VOICE_PROB = 0.10;
|
|
47
|
-
const STICKER_PROB = 0.39;
|
|
48
|
-
const VOICE_HINT = '(插件掷骰:本轮形式 = 语音)\n'
|
|
49
|
-
+ '这一回合把回复做成一条语音条:先在 D:\\Software\\dsh-workspace\\voice-lab 下用 cosy-venv 的 python 跑 '
|
|
50
|
-
+ 'say.py "<要说的内容>" <唯一文件名> 生成 silk,再用 qq_send_voice 发出去。\n'
|
|
51
|
-
+ '语音内容要像开口说话:短、口语、有语气,别念稿。\n'
|
|
52
|
-
+ '⚠️ 语音就是这一轮要说的话:**不要再用 qq_send_text 把同一句打一遍**(对方会听一遍看一遍)。'
|
|
53
|
-
+ '真要张口招呼,最多半句不带内容的「来了」「等下」;语音里念过的意思,文字里一个字都别重复。';
|
|
54
|
-
const STICKER_HINT = '(插件掷骰:本轮形式 = 表情包)\n'
|
|
55
|
-
+ '这一回合文字照常短着说,另外从 D:\\Software\\dsh-workspace\\stickers\\<分类>\\ 里挑一张贴题的表情包,'
|
|
56
|
-
+ '用 qq_send_image 发出来。挑不到合适的就跳过,别硬凑一张不搭的。';
|
|
57
40
|
/** T2 (P1): the queue notice sent to a chat when a message arrives while its
|
|
58
41
|
* task is running under the default 'queue' policy — at most ONE per running
|
|
59
42
|
* turn (the flag resets at turn/end) so a burst of queued messages never
|
|
@@ -247,8 +230,6 @@ export class ChatBridge {
|
|
|
247
230
|
this.interim = new InterimTracker({
|
|
248
231
|
sendToChat: (chatId, text, options) => this.sendToChat(chatId, text, options),
|
|
249
232
|
sendMsg: (chatId, segments, options) => this.sendMsg(chatId, segments, options),
|
|
250
|
-
// 2026-11-16 双发闸:本回合已用工具发过东西 → 终稿正文不再发。
|
|
251
|
-
toolWroteThisTurn: chatId => this.toolWroteThisTurn(chatId),
|
|
252
233
|
call: (action, params) => this.guardedConnectionCall(action, params),
|
|
253
234
|
chainTail: chatId => this.outbound.chainTail(chatId),
|
|
254
235
|
relayHostCards: (chatId, content) => this.relayHostCards(chatId, content),
|
|
@@ -431,8 +412,6 @@ export class ChatBridge {
|
|
|
431
412
|
* @returns the sent message id.
|
|
432
413
|
*/
|
|
433
414
|
sendSegments(chatId, segments) {
|
|
434
|
-
// 2026-11-16 双发闸:图片/语音/视频/文件/分段的统一出口,先记一笔。
|
|
435
|
-
this.noteToolWrite(chatId);
|
|
436
415
|
return this.outbound.sendSegments(chatId, segments);
|
|
437
416
|
}
|
|
438
417
|
/**
|
|
@@ -600,96 +579,23 @@ export class ChatBridge {
|
|
|
600
579
|
* - refresh 后台执行不 await 主流程;get/refresh 同步抛或拒绝都只
|
|
601
580
|
* warn(标题是辅助功能,失败静默降级,不冒泡进派发主流程)。 */
|
|
602
581
|
syncSessionTitle(chat) {
|
|
603
|
-
|
|
604
|
-
try {
|
|
605
|
-
__qqTitleAppend(__qqTitleHome() + '\\.dsh\\onebot-title-sync.log', '[' + new Date().toISOString() + '] ' + msg + '\n');
|
|
606
|
-
}
|
|
607
|
-
catch {
|
|
608
|
-
/* 日志失败不影响同步 */
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
if (this.deps.config.titleSyncEnabled !== true) {
|
|
612
|
-
dbg('skip: titleSyncEnabled=' + String(this.deps.config.titleSyncEnabled) + ' chat=' + chat.chatId);
|
|
582
|
+
if (this.deps.config.titleSyncEnabled !== true)
|
|
613
583
|
return;
|
|
614
|
-
}
|
|
615
584
|
const service = this.deps.sessionTitle;
|
|
616
|
-
if (service === undefined)
|
|
617
|
-
dbg('skip: no sessionTitle service chat=' + chat.chatId);
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
const session = chat.agent?.session;
|
|
621
|
-
if (session === undefined) {
|
|
622
|
-
dbg('skip: no session chat=' + chat.chatId);
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
// 本地补丁 2026-11-17:先按身份定名(私聊=昵称(QQ号),群聊=群名(群号)),
|
|
626
|
-
// 定不了才退回官方 LLM refresh。身份标题的 source 是 user,所以后续比较
|
|
627
|
-
// 标题文本本身:昵称/群名没变就一次都不重写。
|
|
628
|
-
const applyTitle = (desired) => {
|
|
629
|
-
const title = typeof desired === 'string' ? desired.trim() : '';
|
|
630
|
-
if (title === '')
|
|
631
|
-
return false;
|
|
632
|
-
try {
|
|
633
|
-
const current = service.get(session);
|
|
634
|
-
if (current?.title === title) {
|
|
635
|
-
dbg('title ok: ' + title);
|
|
636
|
-
return true;
|
|
637
|
-
}
|
|
638
|
-
service.rename(session, title);
|
|
639
|
-
dbg('rename ok: ' + title + ' (was ' + JSON.stringify(current?.title ?? null) + ') chat=' + chat.chatId);
|
|
640
|
-
return true;
|
|
641
|
-
}
|
|
642
|
-
catch (error) {
|
|
643
|
-
dbg('rename fail: ' + describeError(error) + ' chat=' + chat.chatId);
|
|
644
|
-
this.deps.log('warn', '会话标题写入失败 (' + chat.sessionId + '): ' + describeError(error));
|
|
645
|
-
return false;
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
const ref = splitChatId(chat.chatId);
|
|
649
|
-
if (ref.kind === 'group') {
|
|
650
|
-
const titles = this.__qqGroupTitles ?? (this.__qqGroupTitles = {});
|
|
651
|
-
const cached = titles[ref.target];
|
|
652
|
-
if (typeof cached === 'string' && applyTitle(cached + '(' + ref.target + ')'))
|
|
653
|
-
return;
|
|
654
|
-
void this.guardedConnectionCall('get_group_info', { group_id: Number(ref.target) }, chat.chatId)
|
|
655
|
-
.then((info) => {
|
|
656
|
-
const rawName = info?.group_name;
|
|
657
|
-
const name = typeof rawName === 'string' ? rawName.trim() : '';
|
|
658
|
-
if (name === '') {
|
|
659
|
-
dbg('group name empty: ' + ref.target);
|
|
660
|
-
return false;
|
|
661
|
-
}
|
|
662
|
-
titles[ref.target] = name;
|
|
663
|
-
return applyTitle(name + '(' + ref.target + ')');
|
|
664
|
-
})
|
|
665
|
-
.catch((error) => {
|
|
666
|
-
dbg('group info fail: ' + describeError(error));
|
|
667
|
-
return false;
|
|
668
|
-
})
|
|
669
|
-
.then((done) => {
|
|
670
|
-
if (done === true)
|
|
671
|
-
return;
|
|
672
|
-
void service.refresh(session).catch((error) => {
|
|
673
|
-
dbg('refresh fail: ' + describeError(error));
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
const nickname = typeof chat.lastNickname === 'string' ? chat.lastNickname.trim() : '';
|
|
679
|
-
if (nickname !== '' && applyTitle(nickname + '(' + ref.target + ')'))
|
|
585
|
+
if (service === undefined)
|
|
680
586
|
return;
|
|
587
|
+
const session = chat.agent.session;
|
|
681
588
|
try {
|
|
682
|
-
|
|
589
|
+
const snapshot = service.get(session);
|
|
590
|
+
if (snapshot?.source?.kind === 'user')
|
|
683
591
|
return;
|
|
592
|
+
void service.refresh(session).catch((error) => {
|
|
593
|
+
this.deps.log('warn', '会话标题刷新失败 (' + chat.sessionId + '): ' + describeError(error));
|
|
594
|
+
});
|
|
684
595
|
}
|
|
685
596
|
catch (error) {
|
|
686
|
-
dbg('get fail: ' + describeError(error));
|
|
687
|
-
}
|
|
688
|
-
dbg('fallback refresh chat=' + chat.chatId);
|
|
689
|
-
void service.refresh(session).catch((error) => {
|
|
690
|
-
dbg('refresh fail: ' + describeError(error));
|
|
691
597
|
this.deps.log('warn', '会话标题刷新失败 (' + chat.sessionId + '): ' + describeError(error));
|
|
692
|
-
}
|
|
598
|
+
}
|
|
693
599
|
}
|
|
694
600
|
/**
|
|
695
601
|
* 群聊旁观 (#58):把一条未通过 @ 门控的群消息喂进旁听缓冲;规则触发命中
|
|
@@ -737,49 +643,12 @@ export class ChatBridge {
|
|
|
737
643
|
* so the agent's own plan-mode instruction section governs planning. */
|
|
738
644
|
prefixTurn(chatId, text) {
|
|
739
645
|
let out = text;
|
|
740
|
-
// 2026-11-16 重打:这里同时是回合起点——回合序号 +1,双发闸据此比对。
|
|
741
|
-
this.bumpTurnSeq(chatId);
|
|
742
646
|
const goal = this.registry.getSettings(chatId).goal;
|
|
743
647
|
if (goal !== undefined && goal.trim() !== '') {
|
|
744
648
|
out = '【当前目标】' + goal + '\n' + out;
|
|
745
649
|
}
|
|
746
|
-
// 2026-11-16 重打:每回合掷一次形式(语音 / 表情包 / 纯文字)。
|
|
747
|
-
// 老实现按 dm|group 分叉,2026-11-13 主人要求两边一致,所以一律同一套概率。
|
|
748
|
-
const form = this.rollTurnForm();
|
|
749
|
-
if (form !== '')
|
|
750
|
-
out = out + '\n' + form;
|
|
751
650
|
return out.trim();
|
|
752
651
|
}
|
|
753
|
-
/** 掷本轮形式;空串 = 纯文字。 */
|
|
754
|
-
rollTurnForm() {
|
|
755
|
-
const r = Math.random();
|
|
756
|
-
if (r < VOICE_PROB)
|
|
757
|
-
return VOICE_HINT;
|
|
758
|
-
if (r < VOICE_PROB + STICKER_PROB)
|
|
759
|
-
return STICKER_HINT;
|
|
760
|
-
return '';
|
|
761
|
-
}
|
|
762
|
-
// ── 双发闸(2026-11-16 重打;0.11.0 官方把这套删了)──────────────────
|
|
763
|
-
// 语义:本回合只要用 qq_* 工具发过东西(文字/图/语音/文件),回合末那条
|
|
764
|
-
// 「终稿正文」就不再发一遍,免得同一句话出现两次。回合号每回合 +1。
|
|
765
|
-
/** chatId → 当前回合号。 */
|
|
766
|
-
turnSeqByChat = new Map();
|
|
767
|
-
/** chatId → 最近一次用工具发东西时的回合号。 */
|
|
768
|
-
toolWroteTurnByChat = new Map();
|
|
769
|
-
bumpTurnSeq(chatId) {
|
|
770
|
-
const n = (this.turnSeqByChat.get(chatId) ?? 0) + 1;
|
|
771
|
-
this.turnSeqByChat.set(chatId, n);
|
|
772
|
-
return n;
|
|
773
|
-
}
|
|
774
|
-
/** 工具出了一条 → 记下它属于哪一回合。 */
|
|
775
|
-
noteToolWrite(chatId) {
|
|
776
|
-
this.toolWroteTurnByChat.set(chatId, this.turnSeqByChat.get(chatId) ?? 0);
|
|
777
|
-
}
|
|
778
|
-
/** 本回合是否已经用工具发过东西。 */
|
|
779
|
-
toolWroteThisTurn(chatId) {
|
|
780
|
-
const seq = this.turnSeqByChat.get(chatId) ?? 0;
|
|
781
|
-
return seq > 0 && this.toolWroteTurnByChat.get(chatId) === seq;
|
|
782
|
-
}
|
|
783
652
|
/** Per-chat outbound-mode override (/mode), falling back to the global config. */
|
|
784
653
|
effectiveInterim(chatId) {
|
|
785
654
|
return this.registry.getSettings(chatId).interimOverride ?? this.deps.config.interimMessages;
|