blun-king-cli 9.1.157 → 9.1.159
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/LIESMICH.txt +4 -0
- package/bin/assistant-message-offload-policy.cjs +91 -0
- package/blun.mjs +5 -2
- package/package.json +1 -1
package/LIESMICH.txt
CHANGED
|
@@ -153,6 +153,10 @@ Ab BLUN King 9.1.156 wiederholen gespeicherte Verweise auf Nutzernachrichten au
|
|
|
153
153
|
|
|
154
154
|
Ab BLUN King 9.1.157 werden geeignete erfolgreiche, rein textbasierte Werkzeugausgaben außerhalb der neuesten 20 Nachrichten in der Modellprojektion durch einen kurzen Abschlussvermerk ersetzt. Fehlerausgaben, Medien, ausgelagerte Dateiverweise, die neuesten 20 Nachrichten, Rohverlauf und Exporte bleiben unverändert. In Fredriks stabil vermessenem Sitzungsschnappschuss werden 43 alte Ergebnisse verkleinert. Das spart 9.680 Zeichen beziehungsweise rund 2.420 geschätzte Eingabetoken pro gleich aufgebauter Anfrage.
|
|
155
155
|
|
|
156
|
+
Ab BLUN King 9.1.158 werden reine Statusnachrichten, die unmittelbar auf eine abgeschlossene Telegram-Antwort folgen, außerhalb der neuesten 20 Nachrichten in der Modellprojektion durch einen kurzen Vermerk ersetzt. Der versendete Antwortaufruf und sein Ergebnis, aktuelle Nachrichten, Zusammenfassungen nach anderen Werkzeugen, gemischte Inhalte, Rohverlauf und Exporte bleiben unverändert. In Fredriks stabil vermessenem Sitzungsschnappschuss werden sechs historische Statusnachrichten um 1.837 Zeichen verkleinert. Das spart rund 460 geschätzte Eingabetoken pro gleich aufgebauter Anfrage.
|
|
157
|
+
|
|
158
|
+
Ab BLUN King 9.1.159 werden gültige JSON-Argumente abgeschlossener Werkzeugaufrufe außerhalb der neuesten 12 Nachrichten in der Modellprojektion durch einen kurzen Vermerk ersetzt. Das zugehörige Werkzeugergebnis, die neuesten 12 Nachrichten, nicht abgeschlossene Aufrufe, kleine oder ungültige Argumente, Rohverlauf und Exporte bleiben unverändert. In Fredriks stabil vermessenem Sitzungsschnappschuss werden drei Argumente abgeschlossener Werkzeugaufrufe von 2.849 auf 165 Zeichen verkleinert. Das spart 2.684 Zeichen beziehungsweise rund 671 geschätzte Eingabetoken pro gleich aufgebauter Anfrage.
|
|
159
|
+
|
|
156
160
|
Ab BLUN King 9.1.155 werden gespeicherte Verweise auf Nutzernachrichten wiederhergestellt, bevor Textprojektionen den Hash der ursprünglichen Nachricht verändern können. Bestehende Auslagerungen bleiben dadurch wirksam, statt unbemerkt auf die projizierte vollständige Nachricht zurückzufallen. Rohverlauf, wiederlesbare Dateiverweise, die neuesten 20 Nachrichten, Medien und Exporte bleiben unverändert. In Fredriks stabil vermessenem Schnappschuss sinkt die Modellprojektion von 105.810 auf 99.143 Zeichen. Das spart weitere 6.667 Zeichen beziehungsweise rund 1.667 geschätzte Eingabetoken pro gleich aufgebauter Anfrage.
|
|
157
161
|
|
|
158
162
|
Ab BLUN King 9.1.154 werden adressierte Telegram-Kanalabschnitte außerhalb der neuesten 20 Nachrichten auf eine 500 statt 1.000 Zeichen lange Vorschau mit Anfang und Ende begrenzt. Vollständige Kanalmetadaten, Anfang und Ende des Nachrichteninhalts, die neuesten 20 Nachrichten, Anhänge, Rohverlauf und Exporte bleiben unverändert. In Fredriks stabil vermessenem Schnappschuss werden sieben zusätzliche historische adressierte Abschnitte verkleinert. Das spart 3.500 Zeichen beziehungsweise rund 875 geschätzte Token pro wiederholter Anfrage.
|
|
@@ -7,6 +7,13 @@ const ASSISTANT_MESSAGE_PREVIEW_LINE_CHARS = 1_000;
|
|
|
7
7
|
const ASSISTANT_MESSAGE_OFFLOAD_MARKER = '[Assistant message offloaded]';
|
|
8
8
|
const ASSISTANT_TOOL_NARRATION_MIN_CHARS = 120;
|
|
9
9
|
const ASSISTANT_TOOL_NARRATION_MARKER = '[Earlier completed tool-step narration compacted]';
|
|
10
|
+
const ASSISTANT_POST_TELEGRAM_REPLY_MARKER = '[Earlier post-reply status compacted]';
|
|
11
|
+
const ASSISTANT_TOOL_ARGUMENT_KEEP_RECENT_MESSAGES = 12;
|
|
12
|
+
const ASSISTANT_TOOL_ARGUMENT_MIN_TOKENS = 100;
|
|
13
|
+
const ASSISTANT_TOOL_ARGUMENT_MARKER = JSON.stringify({
|
|
14
|
+
_blun_compacted: '[Old tool call arguments cleared]',
|
|
15
|
+
});
|
|
16
|
+
const TELEGRAM_REPLY_TOOL_RE = /^mcp__[^\s]*telegram[^\s]*__reply$/iu;
|
|
10
17
|
|
|
11
18
|
function shouldOffloadHistoricalAssistantMessage(options = {}) {
|
|
12
19
|
const historyIndex = Number(options.historyIndex);
|
|
@@ -65,6 +72,84 @@ function shouldCompactHistoricalAssistantToolNarration(options = {}) {
|
|
|
65
72
|
&& completedToolCallCount === toolCallCount;
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
function compactHistoricalPostTelegramReplyNarration(messages) {
|
|
76
|
+
if (!Array.isArray(messages) || messages.length === 0) return messages;
|
|
77
|
+
|
|
78
|
+
const toolNameByCallId = new Map(messages.flatMap((message) => (
|
|
79
|
+
message?.role === 'assistant' && Array.isArray(message.toolCalls)
|
|
80
|
+
? message.toolCalls.map((call) => [call?.id, call?.name])
|
|
81
|
+
: []
|
|
82
|
+
)).filter(([id, name]) => typeof id === 'string' && typeof name === 'string'));
|
|
83
|
+
const recentStart = Math.max(0, messages.length - ASSISTANT_MESSAGE_KEEP_RECENT_MESSAGES);
|
|
84
|
+
let changed = false;
|
|
85
|
+
const projected = messages.map((message, historyIndex) => {
|
|
86
|
+
if (
|
|
87
|
+
historyIndex >= recentStart
|
|
88
|
+
|| message?.role !== 'assistant'
|
|
89
|
+
|| (message.toolCalls?.length ?? 0) !== 0
|
|
90
|
+
|| !Array.isArray(message.content)
|
|
91
|
+
|| !message.content.every((part) => part?.type === 'text' && typeof part.text === 'string')
|
|
92
|
+
) return message;
|
|
93
|
+
|
|
94
|
+
const previous = messages[historyIndex - 1];
|
|
95
|
+
const toolName = previous?.role === 'tool'
|
|
96
|
+
? toolNameByCallId.get(previous.toolCallId)
|
|
97
|
+
: undefined;
|
|
98
|
+
if (!TELEGRAM_REPLY_TOOL_RE.test(toolName ?? '')) return message;
|
|
99
|
+
const textChars = message.content.reduce((sum, part) => sum + part.text.length, 0);
|
|
100
|
+
if (textChars <= ASSISTANT_POST_TELEGRAM_REPLY_MARKER.length) return message;
|
|
101
|
+
changed = true;
|
|
102
|
+
return {
|
|
103
|
+
...message,
|
|
104
|
+
content: [{ type: 'text', text: ASSISTANT_POST_TELEGRAM_REPLY_MARKER }],
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return changed ? projected : messages;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function compactHistoricalCompletedToolCallArguments(messages) {
|
|
112
|
+
if (!Array.isArray(messages) || messages.length === 0) return messages;
|
|
113
|
+
|
|
114
|
+
const completedToolCallIds = new Set(messages
|
|
115
|
+
.filter((message) => message?.role === 'tool' && message.toolCallId !== undefined)
|
|
116
|
+
.map((message) => message.toolCallId));
|
|
117
|
+
const recentStart = Math.max(
|
|
118
|
+
0,
|
|
119
|
+
messages.length - ASSISTANT_TOOL_ARGUMENT_KEEP_RECENT_MESSAGES,
|
|
120
|
+
);
|
|
121
|
+
let changed = false;
|
|
122
|
+
const projected = messages.map((message, historyIndex) => {
|
|
123
|
+
if (
|
|
124
|
+
historyIndex >= recentStart
|
|
125
|
+
|| message?.role !== 'assistant'
|
|
126
|
+
|| !Array.isArray(message.toolCalls)
|
|
127
|
+
|| message.toolCalls.length === 0
|
|
128
|
+
) return message;
|
|
129
|
+
|
|
130
|
+
let toolCallsChanged = false;
|
|
131
|
+
const toolCalls = message.toolCalls.map((call) => {
|
|
132
|
+
if (
|
|
133
|
+
!completedToolCallIds.has(call?.id)
|
|
134
|
+
|| typeof call?.arguments !== 'string'
|
|
135
|
+
|| Math.ceil(call.arguments.length / 4) < ASSISTANT_TOOL_ARGUMENT_MIN_TOKENS
|
|
136
|
+
) return call;
|
|
137
|
+
try {
|
|
138
|
+
JSON.parse(call.arguments);
|
|
139
|
+
} catch {
|
|
140
|
+
return call;
|
|
141
|
+
}
|
|
142
|
+
toolCallsChanged = true;
|
|
143
|
+
return { ...call, arguments: ASSISTANT_TOOL_ARGUMENT_MARKER };
|
|
144
|
+
});
|
|
145
|
+
if (!toolCallsChanged) return message;
|
|
146
|
+
changed = true;
|
|
147
|
+
return { ...message, toolCalls };
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return changed ? projected : messages;
|
|
151
|
+
}
|
|
152
|
+
|
|
68
153
|
module.exports = {
|
|
69
154
|
ASSISTANT_MESSAGE_KEEP_RECENT_MESSAGES,
|
|
70
155
|
ASSISTANT_MESSAGE_MAX_CHARS,
|
|
@@ -73,6 +158,12 @@ module.exports = {
|
|
|
73
158
|
ASSISTANT_MESSAGE_PREVIEW_LINE_CHARS,
|
|
74
159
|
ASSISTANT_TOOL_NARRATION_MARKER,
|
|
75
160
|
ASSISTANT_TOOL_NARRATION_MIN_CHARS,
|
|
161
|
+
ASSISTANT_POST_TELEGRAM_REPLY_MARKER,
|
|
162
|
+
ASSISTANT_TOOL_ARGUMENT_KEEP_RECENT_MESSAGES,
|
|
163
|
+
ASSISTANT_TOOL_ARGUMENT_MARKER,
|
|
164
|
+
ASSISTANT_TOOL_ARGUMENT_MIN_TOKENS,
|
|
165
|
+
compactHistoricalCompletedToolCallArguments,
|
|
166
|
+
compactHistoricalPostTelegramReplyNarration,
|
|
76
167
|
createAssistantMessagePreview,
|
|
77
168
|
shouldCompactHistoricalAssistantToolNarration,
|
|
78
169
|
shouldOffloadHistoricalAssistantMessage,
|
package/blun.mjs
CHANGED
|
@@ -260750,7 +260750,7 @@ function renderPersistedAssistantMessage(text, outputPath) {
|
|
|
260750
260750
|
createAssistantMessagePreview(text)
|
|
260751
260751
|
].join("\n");
|
|
260752
260752
|
}
|
|
260753
|
-
var ASSISTANT_MESSAGE_MAX_CHARS, ASSISTANT_MESSAGE_OFFLOAD_MARKER, ASSISTANT_TOOL_NARRATION_MARKER, shouldOffloadHistoricalAssistantMessage, shouldCompactHistoricalAssistantToolNarration, createAssistantMessagePreview;
|
|
260753
|
+
var ASSISTANT_MESSAGE_MAX_CHARS, ASSISTANT_MESSAGE_OFFLOAD_MARKER, ASSISTANT_TOOL_NARRATION_MARKER, shouldOffloadHistoricalAssistantMessage, shouldCompactHistoricalAssistantToolNarration, compactHistoricalPostTelegramReplyNarration, compactHistoricalCompletedToolCallArguments, createAssistantMessagePreview;
|
|
260754
260754
|
var init_assistant_message_offload = __esmMin((() => {
|
|
260755
260755
|
const policy = createRequire(import.meta.url)("./bin/assistant-message-offload-policy.cjs");
|
|
260756
260756
|
ASSISTANT_MESSAGE_MAX_CHARS = policy.ASSISTANT_MESSAGE_MAX_CHARS;
|
|
@@ -260758,6 +260758,8 @@ var init_assistant_message_offload = __esmMin((() => {
|
|
|
260758
260758
|
ASSISTANT_TOOL_NARRATION_MARKER = policy.ASSISTANT_TOOL_NARRATION_MARKER;
|
|
260759
260759
|
shouldOffloadHistoricalAssistantMessage = policy.shouldOffloadHistoricalAssistantMessage;
|
|
260760
260760
|
shouldCompactHistoricalAssistantToolNarration = policy.shouldCompactHistoricalAssistantToolNarration;
|
|
260761
|
+
compactHistoricalPostTelegramReplyNarration = policy.compactHistoricalPostTelegramReplyNarration;
|
|
260762
|
+
compactHistoricalCompletedToolCallArguments = policy.compactHistoricalCompletedToolCallArguments;
|
|
260761
260763
|
createAssistantMessagePreview = policy.createAssistantMessagePreview;
|
|
260762
260764
|
}));
|
|
260763
260765
|
var AssistantMessageOffload = class {
|
|
@@ -260843,7 +260845,8 @@ var AssistantMessageOffload = class {
|
|
|
260843
260845
|
changed = true;
|
|
260844
260846
|
return { ...message, content: replacement.content };
|
|
260845
260847
|
});
|
|
260846
|
-
|
|
260848
|
+
const narrationProjected = compactHistoricalPostTelegramReplyNarration(changed ? projected : messages);
|
|
260849
|
+
return compactHistoricalCompletedToolCallArguments(narrationProjected);
|
|
260847
260850
|
}
|
|
260848
260851
|
reset(history = this.agent.context?.history ?? []) {
|
|
260849
260852
|
const activeHashes = new Set(history.map((message) => {
|