blun-king-cli 9.1.219 → 9.1.220
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.
|
@@ -10,6 +10,7 @@ const INTRA_MESSAGE_MIN_BLOCK_CHARS = 40;
|
|
|
10
10
|
const INTRA_MESSAGE_MIN_SAVED_CHARS = 1_000;
|
|
11
11
|
const INTRA_MESSAGE_SIMILARITY_THRESHOLD = 0.88;
|
|
12
12
|
const INTRA_MESSAGE_REPEAT_PLACEHOLDER = '[Exact repeated assistant paragraphs omitted from model projection; raw history preserved.]';
|
|
13
|
+
const intraMessageProjectionCache = new WeakMap();
|
|
13
14
|
|
|
14
15
|
function isUserPrompt(message) {
|
|
15
16
|
if (message?.role !== 'user') return false;
|
|
@@ -132,8 +133,24 @@ function compactRepeatedAssistantParagraphs(message) {
|
|
|
132
133
|
)) return null;
|
|
133
134
|
|
|
134
135
|
const text = textParts[0].text;
|
|
136
|
+
const cached = intraMessageProjectionCache.get(message);
|
|
137
|
+
if (
|
|
138
|
+
cached?.content === message.content
|
|
139
|
+
&& cached.textPart === textParts[0]
|
|
140
|
+
&& cached.text === text
|
|
141
|
+
) return cached.projected;
|
|
142
|
+
|
|
143
|
+
const cacheProjection = (projected) => {
|
|
144
|
+
intraMessageProjectionCache.set(message, {
|
|
145
|
+
content: message.content,
|
|
146
|
+
projected,
|
|
147
|
+
text,
|
|
148
|
+
textPart: textParts[0],
|
|
149
|
+
});
|
|
150
|
+
return projected;
|
|
151
|
+
};
|
|
135
152
|
const blocks = text.split(/\n\s*\n/u).map((block) => block.trim()).filter(Boolean);
|
|
136
|
-
if (blocks.length < INTRA_MESSAGE_MIN_REPEATS + 1) return null;
|
|
153
|
+
if (blocks.length < INTRA_MESSAGE_MIN_REPEATS + 1) return cacheProjection(null);
|
|
137
154
|
const protectedIndexes = fencedBlockIndexes(blocks);
|
|
138
155
|
|
|
139
156
|
const clusters = [];
|
|
@@ -150,7 +167,7 @@ function compactRepeatedAssistantParagraphs(message) {
|
|
|
150
167
|
const repeatedIndexes = new Set(clusters
|
|
151
168
|
.filter((cluster) => cluster.indexes.length >= INTRA_MESSAGE_MIN_REPEATS)
|
|
152
169
|
.flatMap((cluster) => cluster.indexes.slice(1)));
|
|
153
|
-
if (repeatedIndexes.size === 0) return null;
|
|
170
|
+
if (repeatedIndexes.size === 0) return cacheProjection(null);
|
|
154
171
|
|
|
155
172
|
const projectedBlocks = [];
|
|
156
173
|
let markerAdded = false;
|
|
@@ -166,13 +183,13 @@ function compactRepeatedAssistantParagraphs(message) {
|
|
|
166
183
|
}
|
|
167
184
|
|
|
168
185
|
const projectedText = projectedBlocks.join('\n\n');
|
|
169
|
-
if (text.length - projectedText.length < INTRA_MESSAGE_MIN_SAVED_CHARS) return null;
|
|
170
|
-
return {
|
|
186
|
+
if (text.length - projectedText.length < INTRA_MESSAGE_MIN_SAVED_CHARS) return cacheProjection(null);
|
|
187
|
+
return cacheProjection({
|
|
171
188
|
...message,
|
|
172
189
|
content: message.content.map((part) => (
|
|
173
190
|
part === textParts[0] ? { ...part, text: projectedText } : part
|
|
174
191
|
)),
|
|
175
|
-
};
|
|
192
|
+
});
|
|
176
193
|
}
|
|
177
194
|
|
|
178
195
|
function projectRepeatedAssistantResponses(history) {
|