dsh-chat-comprehension 0.3.7 → 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 +73 -27
- package/client.js +441 -53
- package/lib/engines.mjs +174 -7
- package/lib/index.js +316 -35
- package/lib/models.mjs +166 -0
- package/lib/qq-cards.mjs +16 -8
- package/lib/qqbot-0.5.3-patches.json +60 -4
- package/lib/qqbot-patch.mjs +1 -1
- package/lib/video.mjs +1 -1
- package/package.json +2 -2
- package/vendor/dsh-agent-md/lib/chat-persona.js +29 -4
- package/vendor/dsh-agent-md/lib/index.js +80 -8
- package/vendor/dsh-agent-md/lib/qq.js +288 -44
- package/vendor/dsh-bili-scroll/index.js +25 -9
- package/vendor/dsh-meme/index.js +2 -2
- package/vendor/dsh-meme/memes.js +3 -1
- package/vendor/dsh-world/lib/qqScope.js +65 -17
- package/vendor/dsh-world/lib/runtime.js +17 -5
|
@@ -6,6 +6,7 @@ import { Faults } from "./faults.js";
|
|
|
6
6
|
import { createHistory, excludePresentMessages, renderHistory } from "./history.js";
|
|
7
7
|
import { createPromptSections } from "./promptSection.js";
|
|
8
8
|
import { belongsToWorld, createSourceArchive } from "./sourceArchive.js";
|
|
9
|
+
import { qqGroupOf, qqPeerOf } from "./qqScope.js";
|
|
9
10
|
import { worldNames } from "./worldPrompt.js";
|
|
10
11
|
import { DEFAULT_MEMORY_TURNS } from "./worldSwitch.js";
|
|
11
12
|
const memorySource = 'dsh-world-history';
|
|
@@ -85,10 +86,14 @@ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () =
|
|
|
85
86
|
/** Retires the blocks still on the surface (they must be found, or the session would carry two) and builds a fresh one without the messages already present. */
|
|
86
87
|
async function freshBlock(session, state) {
|
|
87
88
|
const messages = session.deriveMessages();
|
|
88
|
-
|
|
89
|
+
// QQ 作用域:每个 QQ 聊天(私聊 / 每个群)只读自己那组会话的记忆,互不串
|
|
90
|
+
const includes = config.scope === 'qq'
|
|
91
|
+
? (() => { const group = qqGroupOf(session.id, config.qqSessionsFile); return (id) => group.has(String(id)); })()
|
|
92
|
+
: archivedByScope;
|
|
93
|
+
const turns = await history.loadRecentTurns(config.worldId, memoryTurns(), includes);
|
|
89
94
|
const present = new Set(messages.filter(message => message.role === 'assistant' || message.source.kind === 'user').map(message => message.id));
|
|
90
95
|
const text = renderHistory(excludePresentMessages(turns, present), config.timeZone, names, config.archiveScope === 'home');
|
|
91
|
-
writeQqMirror(text);
|
|
96
|
+
writeQqMirror(text, session.id);
|
|
92
97
|
const oldBlocks = messages.filter(message => message.source.kind === memorySource);
|
|
93
98
|
for (const [index, message] of oldBlocks.entries()) {
|
|
94
99
|
const seq = state.injected.get(message.id);
|
|
@@ -106,12 +111,19 @@ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () =
|
|
|
106
111
|
* A readable copy of the exact block the QQ conversation receives. Only the QQ-bound session builds a
|
|
107
112
|
* block, so only it writes this file; a failed mirror never disturbs the memory itself.
|
|
108
113
|
*/
|
|
109
|
-
function writeQqMirror(text) {
|
|
114
|
+
function writeQqMirror(text, sessionId) {
|
|
110
115
|
if (config.scope !== 'qq' || !config.qqMirrorFile || !text)
|
|
111
116
|
return;
|
|
112
117
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
// 私聊(或旧版单清单)写 qq-memory.md;群写 qq-memory-group-<群号后8位>.md —— 每个聊天一份
|
|
119
|
+
const peer = qqPeerOf(sessionId, config.qqSessionsFile);
|
|
120
|
+
const parts = peer.split(':');
|
|
121
|
+
const isGroup = parts.length >= 4 && parts[2] === 'group';
|
|
122
|
+
const file = isGroup
|
|
123
|
+
? config.qqMirrorFile.replace(/\.md$/i, '') + '-group-' + parts.slice(3).join(':').replace(/[^A-Za-z0-9]/g, '').slice(-8) + '.md'
|
|
124
|
+
: config.qqMirrorFile;
|
|
125
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
126
|
+
writeFileSync(file, `<!-- dsh-world: QQ ${isGroup ? '群' : '私聊'}对话的近期记忆 · ${peer || 'legacy'} · ${new Date().toISOString()} -->\n\n${text}\n`, 'utf8');
|
|
115
127
|
}
|
|
116
128
|
catch { /* the mirror is a convenience, never a dependency */ }
|
|
117
129
|
}
|