blun-king-cli 9.1.355 → 9.1.357
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.
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function joinSystemPrompt(base, append) {
|
|
4
|
+
if (append.length === 0) return base;
|
|
5
|
+
return base.length === 0 ? append : `${base}\n\n${append}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function createEffectiveSystemPromptResolver(joinPrompts = joinSystemPrompt) {
|
|
9
|
+
if (typeof joinPrompts !== 'function') {
|
|
10
|
+
throw new TypeError('joinPrompts must be a function');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let initialized = false;
|
|
14
|
+
let cachedBase = '';
|
|
15
|
+
let cachedAppend = '';
|
|
16
|
+
let cachedPrompt = '';
|
|
17
|
+
|
|
18
|
+
return function resolveEffectiveSystemPrompt(base, append) {
|
|
19
|
+
if (initialized && base === cachedBase && append === cachedAppend) {
|
|
20
|
+
return cachedPrompt;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
cachedPrompt = joinPrompts(base, append);
|
|
24
|
+
cachedBase = base;
|
|
25
|
+
cachedAppend = append;
|
|
26
|
+
initialized = true;
|
|
27
|
+
return cachedPrompt;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
createEffectiveSystemPromptResolver,
|
|
33
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_MAX_ENTRIES = 4;
|
|
4
|
+
const DEFAULT_MAX_PROMPT_CHARS = 500_000;
|
|
5
|
+
const DEFAULT_MAX_TOTAL_CHARS = 1_000_000;
|
|
6
|
+
|
|
7
|
+
function positiveInteger(value, fallback, name) {
|
|
8
|
+
const resolved = value === undefined ? fallback : value;
|
|
9
|
+
if (!Number.isSafeInteger(resolved) || resolved < 1) {
|
|
10
|
+
throw new TypeError(`${name} must be a positive integer`);
|
|
11
|
+
}
|
|
12
|
+
return resolved;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function createSystemPromptTokenEstimator(estimateTextTokens, options = {}) {
|
|
16
|
+
if (typeof estimateTextTokens !== 'function') {
|
|
17
|
+
throw new TypeError('estimateTextTokens must be a function');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const maxEntries = positiveInteger(options.maxEntries, DEFAULT_MAX_ENTRIES, 'maxEntries');
|
|
21
|
+
const maxPromptChars = positiveInteger(
|
|
22
|
+
options.maxPromptChars,
|
|
23
|
+
DEFAULT_MAX_PROMPT_CHARS,
|
|
24
|
+
'maxPromptChars',
|
|
25
|
+
);
|
|
26
|
+
const maxTotalChars = positiveInteger(
|
|
27
|
+
options.maxTotalChars,
|
|
28
|
+
DEFAULT_MAX_TOTAL_CHARS,
|
|
29
|
+
'maxTotalChars',
|
|
30
|
+
);
|
|
31
|
+
const cache = new Map();
|
|
32
|
+
let cachedChars = 0;
|
|
33
|
+
|
|
34
|
+
return function estimateSystemPrompt(prompt) {
|
|
35
|
+
const cached = cache.get(prompt);
|
|
36
|
+
if (cached !== undefined) {
|
|
37
|
+
cache.delete(prompt);
|
|
38
|
+
cache.set(prompt, cached);
|
|
39
|
+
return cached;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const tokens = estimateTextTokens(prompt);
|
|
43
|
+
if (prompt.length > maxPromptChars || prompt.length > maxTotalChars) return tokens;
|
|
44
|
+
|
|
45
|
+
while (cache.size >= maxEntries || cachedChars + prompt.length > maxTotalChars) {
|
|
46
|
+
const oldestPrompt = cache.keys().next().value;
|
|
47
|
+
if (oldestPrompt === undefined) break;
|
|
48
|
+
cachedChars -= oldestPrompt.length;
|
|
49
|
+
cache.delete(oldestPrompt);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cache.set(prompt, tokens);
|
|
53
|
+
cachedChars += prompt.length;
|
|
54
|
+
return tokens;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
createSystemPromptTokenEstimator,
|
|
60
|
+
};
|
package/blun.mjs
CHANGED
|
@@ -31019,11 +31019,13 @@ function estimateTokensForContentPart(part) {
|
|
|
31019
31019
|
default: return 0;
|
|
31020
31020
|
}
|
|
31021
31021
|
}
|
|
31022
|
-
var createToolSchemaTokenEstimator, estimateTokensForTools, messageTokenEstimateCache, MEDIA_TOKEN_ESTIMATE, MAX_IMAGE_HEADER_BYTES;
|
|
31022
|
+
var createToolSchemaTokenEstimator, createSystemPromptTokenEstimator, estimateTokensForTools, estimateSystemPromptTokens, messageTokenEstimateCache, MEDIA_TOKEN_ESTIMATE, MAX_IMAGE_HEADER_BYTES;
|
|
31023
31023
|
var init_tokens = __esmMin((() => {
|
|
31024
31024
|
init_file_type$1();
|
|
31025
31025
|
({ createToolSchemaTokenEstimator } = createRequire(import.meta.url)("./bin/tool-schema-token-cache-policy.cjs"));
|
|
31026
|
+
({ createSystemPromptTokenEstimator } = createRequire(import.meta.url)("./bin/system-prompt-token-cache-policy.cjs"));
|
|
31026
31027
|
estimateTokensForTools = createToolSchemaTokenEstimator(estimateTokens$1);
|
|
31028
|
+
estimateSystemPromptTokens = createSystemPromptTokenEstimator(estimateTokens$1);
|
|
31027
31029
|
messageTokenEstimateCache = /* @__PURE__ */ new WeakMap();
|
|
31028
31030
|
MEDIA_TOKEN_ESTIMATE = 2e3;
|
|
31029
31031
|
MAX_IMAGE_HEADER_BYTES = 1024 * 1024;
|
|
@@ -74736,7 +74738,7 @@ var init_kosong_llm = __esmMin((() => {
|
|
|
74736
74738
|
const outgoingMessages = downgradeUnsupportedMedia(enrichedMessages, this.capability, (dropped) => {
|
|
74737
74739
|
this.notifyMediaDropped(dropped);
|
|
74738
74740
|
});
|
|
74739
|
-
const outgoingRequestTokens =
|
|
74741
|
+
const outgoingRequestTokens = estimateSystemPromptTokens(this.systemPrompt) + estimateTokensForTools(tools) + estimateTokensForMessages(outgoingMessages);
|
|
74740
74742
|
const reportedContextTokens = this.reportedContextTokens?.() ?? 0;
|
|
74741
74743
|
const usedContextTokens = Math.max(outgoingRequestTokens, reportedContextTokens);
|
|
74742
74744
|
completionBudget = applyCompletionBudgetWithDetails({
|
|
@@ -75454,7 +75456,7 @@ var init_full = __esmMin((() => {
|
|
|
75454
75456
|
return this.agent.context.tokenCountWithPending;
|
|
75455
75457
|
}
|
|
75456
75458
|
estimateRequestTokens(messages, systemPrompt = this.agent.effectiveSystemPrompt, tools = this.agent.tools.loopTools) {
|
|
75457
|
-
return
|
|
75459
|
+
return estimateSystemPromptTokens(systemPrompt) + estimateTokensForTools(tools) + estimateTokensForMessages(messages);
|
|
75458
75460
|
}
|
|
75459
75461
|
resetForTurn() {
|
|
75460
75462
|
this.compactionCountInTurn = 0;
|
|
@@ -265002,7 +265004,7 @@ var init_llm_request_logger = __esmMin((() => {
|
|
|
265002
265004
|
function normalizeRuntimeSystemPromptAppend(value) {
|
|
265003
265005
|
return value?.trim().slice(0, 16e3) ?? "";
|
|
265004
265006
|
}
|
|
265005
|
-
var PINNED_MODEL_ALIASES, resolveProviderIdleTimeoutMs, capCompletionBudgetForAdaptiveEffort, capTurnCompletionTokens, selectThinkingEffortForBufferedSteer, selectThinkingEffortForWorkStep, selectThinkingEffortForTurn, Agent$1;
|
|
265007
|
+
var PINNED_MODEL_ALIASES, createEffectiveSystemPromptResolver, resolveProviderIdleTimeoutMs, capCompletionBudgetForAdaptiveEffort, capTurnCompletionTokens, selectThinkingEffortForBufferedSteer, selectThinkingEffortForWorkStep, selectThinkingEffortForTurn, Agent$1;
|
|
265006
265008
|
var init_agent = __esmMin((() => {
|
|
265007
265009
|
init_dist$6();
|
|
265008
265010
|
init_config$4();
|
|
@@ -265039,6 +265041,7 @@ var init_agent = __esmMin((() => {
|
|
|
265039
265041
|
init_goal$1();
|
|
265040
265042
|
init_session_loop();
|
|
265041
265043
|
init_error_memory();
|
|
265044
|
+
({ createEffectiveSystemPromptResolver } = createRequire(import.meta.url)("./bin/effective-system-prompt-cache-policy.cjs"));
|
|
265042
265045
|
({ resolveProviderIdleTimeoutMs } = createRequire(import.meta.url)("./bin/provider-idle-timeout-policy.cjs"));
|
|
265043
265046
|
({ capCompletionBudgetForAdaptiveEffort, capTurnCompletionTokens, selectThinkingEffortForBufferedSteer, selectThinkingEffortForWorkStep, selectThinkingEffortForTurn } = createRequire(import.meta.url)("./bin/turn-thinking-policy.cjs"));
|
|
265044
265047
|
PINNED_MODEL_ALIASES = new Set(["king-blun", "pruefstand"]);
|
|
@@ -265096,6 +265099,7 @@ var init_agent = __esmMin((() => {
|
|
|
265096
265099
|
allowModelFallback = true;
|
|
265097
265100
|
personalMemoryHostCapabilityEnabled = false;
|
|
265098
265101
|
runtimeSystemPromptAppend = "";
|
|
265102
|
+
resolveEffectiveSystemPrompt = createEffectiveSystemPromptResolver();
|
|
265099
265103
|
systemPromptContextProvider;
|
|
265100
265104
|
systemPromptTimestamp = new Date();
|
|
265101
265105
|
systemPromptContextFingerprint = "";
|
|
@@ -265262,9 +265266,7 @@ var init_agent = __esmMin((() => {
|
|
|
265262
265266
|
this.emitStatusUpdated();
|
|
265263
265267
|
}
|
|
265264
265268
|
get effectiveSystemPrompt() {
|
|
265265
|
-
|
|
265266
|
-
if (this.runtimeSystemPromptAppend.length === 0) return base;
|
|
265267
|
-
return base.length === 0 ? this.runtimeSystemPromptAppend : `${base}\n\n${this.runtimeSystemPromptAppend}`;
|
|
265269
|
+
return this.resolveEffectiveSystemPrompt(this.config.systemPrompt, this.runtimeSystemPromptAppend);
|
|
265268
265270
|
}
|
|
265269
265271
|
get fastConversationSystemPrompt() {
|
|
265270
265272
|
return [personaSystemBlock(), soulSystemBlock(), identitySystemBlock(), naturalPresenceSystemBlock(), conductSystemBlock(), `## Fast conversation mode
|
|
@@ -265521,7 +265523,7 @@ var init_agent = __esmMin((() => {
|
|
|
265521
265523
|
projectedTokenCount: this.fullCompaction.estimateCurrentRequestTokens(),
|
|
265522
265524
|
effectiveMaxContextTokens: this.fullCompaction.getEffectiveMaxContextTokens(),
|
|
265523
265525
|
compactionBudgetTokens: this.fullCompaction.getCompactionBudgetTokens(),
|
|
265524
|
-
systemPromptTokens:
|
|
265526
|
+
systemPromptTokens: estimateSystemPromptTokens(systemPrompt),
|
|
265525
265527
|
personalityPromptTokens,
|
|
265526
265528
|
socialPromptTokens,
|
|
265527
265529
|
skillPromptTokens: includedTokens(skillPrompt),
|