blun-king-cli 9.1.192 → 9.1.193
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/bin/repeated-user-message-projection.cjs +41 -0
- package/blun.mjs +31 -8
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const LONG_DUPLICATE_MIN_CHARS = 512;
|
|
4
|
+
const TELEGRAM_DELIVERY_LEDGER_LIMIT = 2_048;
|
|
4
5
|
|
|
5
6
|
function userMessageText(message) {
|
|
6
7
|
if (
|
|
@@ -31,6 +32,43 @@ function telegramDeliveryIdentity(text) {
|
|
|
31
32
|
return `${chatId}:${messageId}`;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
function telegramDeliveryIdentityFromParts(input) {
|
|
36
|
+
if (!Array.isArray(input)) return '';
|
|
37
|
+
for (const part of input) {
|
|
38
|
+
if (part?.type !== 'text' || typeof part.text !== 'string') continue;
|
|
39
|
+
const identity = telegramDeliveryIdentity(part.text);
|
|
40
|
+
if (identity) return identity;
|
|
41
|
+
}
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class TelegramDeliveryLedger {
|
|
46
|
+
constructor(limit = TELEGRAM_DELIVERY_LEDGER_LIMIT) {
|
|
47
|
+
this.limit = Math.max(1, Number.isInteger(limit) ? limit : TELEGRAM_DELIVERY_LEDGER_LIMIT);
|
|
48
|
+
this.identities = new Set();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
identity(input, origin) {
|
|
52
|
+
if (origin?.kind !== 'user') return '';
|
|
53
|
+
return telegramDeliveryIdentityFromParts(input);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
isDuplicate(input, origin) {
|
|
57
|
+
const identity = this.identity(input, origin);
|
|
58
|
+
return identity ? this.identities.has(identity) : false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
remember(input, origin) {
|
|
62
|
+
const identity = this.identity(input, origin);
|
|
63
|
+
if (!identity || this.identities.has(identity)) return identity;
|
|
64
|
+
this.identities.add(identity);
|
|
65
|
+
while (this.identities.size > this.limit) {
|
|
66
|
+
this.identities.delete(this.identities.values().next().value);
|
|
67
|
+
}
|
|
68
|
+
return identity;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
34
72
|
function repeatedUserMessageKey(message) {
|
|
35
73
|
const text = userMessageText(message);
|
|
36
74
|
if (!text) return '';
|
|
@@ -62,7 +100,10 @@ function dedupeRepeatedUserMessages(messages) {
|
|
|
62
100
|
|
|
63
101
|
module.exports = {
|
|
64
102
|
LONG_DUPLICATE_MIN_CHARS,
|
|
103
|
+
TELEGRAM_DELIVERY_LEDGER_LIMIT,
|
|
104
|
+
TelegramDeliveryLedger,
|
|
65
105
|
dedupeRepeatedUserMessages,
|
|
66
106
|
telegramDeliveryIdentity,
|
|
107
|
+
telegramDeliveryIdentityFromParts,
|
|
67
108
|
userMessageText,
|
|
68
109
|
};
|
package/blun.mjs
CHANGED
|
@@ -234922,7 +234922,7 @@ function restoreAgentRecord(agent, input) {
|
|
|
234922
234922
|
agent.goal.restoreForked(input);
|
|
234923
234923
|
return;
|
|
234924
234924
|
case "turn.prompt":
|
|
234925
|
-
agent.turn.restorePrompt();
|
|
234925
|
+
agent.turn.restorePrompt(input.input, input.origin);
|
|
234926
234926
|
return;
|
|
234927
234927
|
case "turn.steer":
|
|
234928
234928
|
agent.turn.restoreSteer(input.input, input.origin);
|
|
@@ -261209,7 +261209,7 @@ function toolResultText(result) {
|
|
|
261209
261209
|
function abandonedToolResultOutput(ended) {
|
|
261210
261210
|
return `Tool call did not complete: ${ended.reason === "cancelled" ? "the turn was cancelled" : ended.reason === "failed" ? `the turn failed${ended.error !== void 0 ? ` (${ended.error.message})` : ""}` : "the turn ended"} before its result was recorded. Do not assume the tool completed successfully.`;
|
|
261211
261211
|
}
|
|
261212
|
-
var BLUN_CORE_TOOL_NAMES, BLUN_LEAN_TOOL_NAMES, BLUN_ATTACHMENT_MARKER_RE, BLUN_TELEGRAM_OUTBOUND_TOOL_RE, BLUN_TELEGRAM_CHANNEL_RE, BLUN_TOOL_BUDGET_RATIO, createDeferredToolLoader, mediaGenerationToolNamesForText, toolSchemaBudgetTokens, projectRecurringCronHistory, LLM_NOT_SET_MESSAGE, GOAL_CONTINUATION_ORIGIN, GOAL_COMPLETION_REMINDER_NAME, GOAL_BLOCKED_REMINDER_NAME, GOAL_RATE_LIMIT_PAUSE_REASON, GOAL_PROVIDER_CONNECTION_PAUSE_PREFIX, GOAL_PROVIDER_AUTH_PAUSE_PREFIX, GOAL_PROVIDER_API_PAUSE_PREFIX, GOAL_MODEL_CONFIG_PAUSE_PREFIX, GOAL_RUNTIME_PAUSE_PREFIX, GOAL_PROVIDER_FILTERED_PAUSE_REASON, GOAL_CONTINUATION_PROMPT, TurnFlow;
|
|
261212
|
+
var BLUN_CORE_TOOL_NAMES, BLUN_LEAN_TOOL_NAMES, BLUN_ATTACHMENT_MARKER_RE, BLUN_TELEGRAM_OUTBOUND_TOOL_RE, BLUN_TELEGRAM_CHANNEL_RE, BLUN_TOOL_BUDGET_RATIO, createDeferredToolLoader, mediaGenerationToolNamesForText, toolSchemaBudgetTokens, projectRecurringCronHistory, TelegramDeliveryLedger, LLM_NOT_SET_MESSAGE, GOAL_CONTINUATION_ORIGIN, GOAL_COMPLETION_REMINDER_NAME, GOAL_BLOCKED_REMINDER_NAME, GOAL_RATE_LIMIT_PAUSE_REASON, GOAL_PROVIDER_CONNECTION_PAUSE_PREFIX, GOAL_PROVIDER_AUTH_PAUSE_PREFIX, GOAL_PROVIDER_API_PAUSE_PREFIX, GOAL_MODEL_CONFIG_PAUSE_PREFIX, GOAL_RUNTIME_PAUSE_PREFIX, GOAL_PROVIDER_FILTERED_PAUSE_REASON, GOAL_CONTINUATION_PROMPT, TurnFlow;
|
|
261213
261213
|
var init_turn = __esmMin((() => {
|
|
261214
261214
|
init_dist$4();
|
|
261215
261215
|
init_src$4();
|
|
@@ -261228,6 +261228,7 @@ var init_turn = __esmMin((() => {
|
|
|
261228
261228
|
init_assistant_message_offload();
|
|
261229
261229
|
({ CORE_TOOL_NAMES: BLUN_CORE_TOOL_NAMES, createDeferredToolLoader, mediaGenerationToolNamesForText, toolSchemaBudgetTokens } = createRequire(import.meta.url)("./bin/turn-tool-performance-policy.cjs"));
|
|
261230
261230
|
({ projectRecurringCronHistory } = createRequire(import.meta.url)("./bin/recurring-cron-history-policy.cjs"));
|
|
261231
|
+
({ TelegramDeliveryLedger } = createRequire(import.meta.url)("./bin/repeated-user-message-projection.cjs"));
|
|
261231
261232
|
BLUN_LEAN_TOOL_NAMES = new Set(BLUN_CORE_TOOL_NAMES);
|
|
261232
261233
|
BLUN_ATTACHMENT_MARKER_RE = /\b(?:attachment_file_id|telegram-anhang|telegram attachment)\b/i;
|
|
261233
261234
|
BLUN_TELEGRAM_OUTBOUND_TOOL_RE = /^mcp__[^\s]*telegram[^\s]*__(?:reply|react|edit_message)$/i;
|
|
@@ -261275,6 +261276,7 @@ var init_turn = __esmMin((() => {
|
|
|
261275
261276
|
TurnFlow = class {
|
|
261276
261277
|
agent;
|
|
261277
261278
|
loadedToolNames = /* @__PURE__ */ new Set();
|
|
261279
|
+
telegramDeliveryLedger = new TelegramDeliveryLedger();
|
|
261278
261280
|
steerBuffer = [];
|
|
261279
261281
|
nextSteerSequence = 0;
|
|
261280
261282
|
turnId = -1;
|
|
@@ -261298,16 +261300,25 @@ var init_turn = __esmMin((() => {
|
|
|
261298
261300
|
return this.promptWithAcceptance(input, origin).turnId;
|
|
261299
261301
|
}
|
|
261300
261302
|
promptWithAcceptance(input, origin = USER_PROMPT_ORIGIN) {
|
|
261301
|
-
this.
|
|
261302
|
-
|
|
261303
|
-
|
|
261304
|
-
|
|
261305
|
-
|
|
261303
|
+
if (this.telegramDeliveryLedger.isDuplicate(input, origin)) {
|
|
261304
|
+
this.agent.telemetry.track("telegram_delivery_duplicate_dropped", { intake: "prompt" });
|
|
261305
|
+
return {
|
|
261306
|
+
accepted: true,
|
|
261307
|
+
buffered: false,
|
|
261308
|
+
turnId: null
|
|
261309
|
+
};
|
|
261310
|
+
}
|
|
261306
261311
|
if (this.activeTurn !== null) return {
|
|
261307
261312
|
accepted: false,
|
|
261308
261313
|
buffered: false,
|
|
261309
261314
|
turnId: null
|
|
261310
261315
|
};
|
|
261316
|
+
this.telegramDeliveryLedger.remember(input, origin);
|
|
261317
|
+
this.agent.records.logRecord({
|
|
261318
|
+
type: "turn.prompt",
|
|
261319
|
+
input,
|
|
261320
|
+
origin
|
|
261321
|
+
});
|
|
261311
261322
|
const buffered = this.agent.fullCompaction.isCompacting;
|
|
261312
261323
|
const turnId = this.launch(input, origin);
|
|
261313
261324
|
return {
|
|
@@ -261317,6 +261328,11 @@ var init_turn = __esmMin((() => {
|
|
|
261317
261328
|
};
|
|
261318
261329
|
}
|
|
261319
261330
|
steer(input, origin = USER_PROMPT_ORIGIN) {
|
|
261331
|
+
if (this.telegramDeliveryLedger.isDuplicate(input, origin)) {
|
|
261332
|
+
this.agent.telemetry.track("telegram_delivery_duplicate_dropped", { intake: "steer" });
|
|
261333
|
+
return null;
|
|
261334
|
+
}
|
|
261335
|
+
this.telegramDeliveryLedger.remember(input, origin);
|
|
261320
261336
|
this.agent.records.logRecord({
|
|
261321
261337
|
type: "turn.steer",
|
|
261322
261338
|
input,
|
|
@@ -261332,6 +261348,11 @@ var init_turn = __esmMin((() => {
|
|
|
261332
261348
|
steerActive(input, expectedTurnId, origin = USER_PROMPT_ORIGIN) {
|
|
261333
261349
|
const active = this.activeTurn;
|
|
261334
261350
|
if (active === null || active === "resuming" || !active.acceptingSteers || expectedTurnId !== void 0 && expectedTurnId !== this.currentId) return null;
|
|
261351
|
+
if (this.telegramDeliveryLedger.isDuplicate(input, origin)) {
|
|
261352
|
+
this.agent.telemetry.track("telegram_delivery_duplicate_dropped", { intake: "active_steer" });
|
|
261353
|
+
return this.currentId;
|
|
261354
|
+
}
|
|
261355
|
+
this.telegramDeliveryLedger.remember(input, origin);
|
|
261335
261356
|
this.agent.records.logRecord({
|
|
261336
261357
|
type: "turn.steer",
|
|
261337
261358
|
input,
|
|
@@ -261378,7 +261399,8 @@ var init_turn = __esmMin((() => {
|
|
|
261378
261399
|
this.turnId += 1;
|
|
261379
261400
|
return this.turnId;
|
|
261380
261401
|
}
|
|
261381
|
-
restorePrompt() {
|
|
261402
|
+
restorePrompt(input, origin) {
|
|
261403
|
+
this.telegramDeliveryLedger.remember(input, origin);
|
|
261382
261404
|
if (this.activeTurn) return;
|
|
261383
261405
|
this.turnId += 1;
|
|
261384
261406
|
this.activeTurn = "resuming";
|
|
@@ -261396,6 +261418,7 @@ var init_turn = __esmMin((() => {
|
|
|
261396
261418
|
if (Number.isInteger(turnId) && turnId > this.turnId) this.turnId = turnId;
|
|
261397
261419
|
}
|
|
261398
261420
|
restoreSteer(input, origin) {
|
|
261421
|
+
this.telegramDeliveryLedger.remember(input, origin);
|
|
261399
261422
|
if (this.activeTurn) {
|
|
261400
261423
|
this.bufferSteer(input, origin);
|
|
261401
261424
|
return;
|