blun-king-cli 9.1.353 → 9.1.355
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,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function createLlmConfigChangeDetector(options = {}) {
|
|
4
|
+
const serializeParameters = options.serializeParameters ?? JSON.stringify;
|
|
5
|
+
if (typeof serializeParameters !== 'function') {
|
|
6
|
+
throw new TypeError('serializeParameters must be a function');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let previous;
|
|
10
|
+
|
|
11
|
+
return function shouldLogConfig(input) {
|
|
12
|
+
const tools = Array.isArray(input.tools) ? input.tools : [];
|
|
13
|
+
const sameScalars = previous !== undefined
|
|
14
|
+
&& previous.provider === input.provider
|
|
15
|
+
&& previous.model === input.model
|
|
16
|
+
&& previous.modelAlias === input.modelAlias
|
|
17
|
+
&& previous.thinkingEffort === input.thinkingEffort
|
|
18
|
+
&& previous.systemPrompt === input.systemPrompt;
|
|
19
|
+
|
|
20
|
+
if (sameScalars && previous.tools.length === tools.length) {
|
|
21
|
+
let exactToolMatch = true;
|
|
22
|
+
for (let index = 0; index < tools.length; index += 1) {
|
|
23
|
+
const tool = tools[index];
|
|
24
|
+
const prior = previous.tools[index];
|
|
25
|
+
if (
|
|
26
|
+
prior.tool !== tool
|
|
27
|
+
|| prior.name !== tool.name
|
|
28
|
+
|| prior.description !== tool.description
|
|
29
|
+
|| prior.parameters !== tool.parameters
|
|
30
|
+
) {
|
|
31
|
+
exactToolMatch = false;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (exactToolMatch) return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let toolsChanged = previous === undefined || previous.tools.length !== tools.length;
|
|
39
|
+
const toolSnapshot = tools.map((tool, index) => {
|
|
40
|
+
const prior = previous?.tools[index];
|
|
41
|
+
const parametersJson = prior?.parameters === tool.parameters
|
|
42
|
+
? prior.parametersJson
|
|
43
|
+
: serializeParameters(tool.parameters);
|
|
44
|
+
if (
|
|
45
|
+
prior === undefined
|
|
46
|
+
|| prior.name !== tool.name
|
|
47
|
+
|| prior.description !== tool.description
|
|
48
|
+
|| prior.parametersJson !== parametersJson
|
|
49
|
+
) {
|
|
50
|
+
toolsChanged = true;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
tool,
|
|
54
|
+
name: tool.name,
|
|
55
|
+
description: tool.description,
|
|
56
|
+
parameters: tool.parameters,
|
|
57
|
+
parametersJson,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const changed = !sameScalars || toolsChanged;
|
|
62
|
+
previous = {
|
|
63
|
+
provider: input.provider,
|
|
64
|
+
model: input.model,
|
|
65
|
+
modelAlias: input.modelAlias,
|
|
66
|
+
thinkingEffort: input.thinkingEffort,
|
|
67
|
+
systemPrompt: input.systemPrompt,
|
|
68
|
+
tools: toolSnapshot,
|
|
69
|
+
};
|
|
70
|
+
return changed;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = {
|
|
75
|
+
createLlmConfigChangeDetector,
|
|
76
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function createToolSchemaTokenEstimator(estimateTextTokens) {
|
|
4
|
+
if (typeof estimateTextTokens !== 'function') {
|
|
5
|
+
throw new TypeError('estimateTextTokens must be a function');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const toolSchemaTokenEstimateCache = new WeakMap();
|
|
9
|
+
|
|
10
|
+
return function estimateToolSchemas(tools) {
|
|
11
|
+
let total = 0;
|
|
12
|
+
for (const tool of tools) {
|
|
13
|
+
const cached = toolSchemaTokenEstimateCache.get(tool);
|
|
14
|
+
if (
|
|
15
|
+
cached !== undefined
|
|
16
|
+
&& cached.name === tool.name
|
|
17
|
+
&& cached.description === tool.description
|
|
18
|
+
&& cached.parameters === tool.parameters
|
|
19
|
+
) {
|
|
20
|
+
total += cached.tokens;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const tokens = estimateTextTokens(tool.name)
|
|
25
|
+
+ estimateTextTokens(tool.description)
|
|
26
|
+
+ estimateTextTokens(JSON.stringify(tool.parameters));
|
|
27
|
+
toolSchemaTokenEstimateCache.set(tool, {
|
|
28
|
+
name: tool.name,
|
|
29
|
+
description: tool.description,
|
|
30
|
+
parameters: tool.parameters,
|
|
31
|
+
tokens,
|
|
32
|
+
});
|
|
33
|
+
total += tokens;
|
|
34
|
+
}
|
|
35
|
+
return total;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
createToolSchemaTokenEstimator,
|
|
41
|
+
};
|
package/blun.mjs
CHANGED
|
@@ -30966,15 +30966,6 @@ function estimateTokensForMessages(messages) {
|
|
|
30966
30966
|
for (const message of messages) total += estimateTokensForMessage(message);
|
|
30967
30967
|
return total;
|
|
30968
30968
|
}
|
|
30969
|
-
function estimateTokensForTools(tools) {
|
|
30970
|
-
let total = 0;
|
|
30971
|
-
for (const tool of tools) {
|
|
30972
|
-
total += estimateTokens$1(tool.name);
|
|
30973
|
-
total += estimateTokens$1(tool.description);
|
|
30974
|
-
total += estimateTokens$1(JSON.stringify(tool.parameters));
|
|
30975
|
-
}
|
|
30976
|
-
return total;
|
|
30977
|
-
}
|
|
30978
30969
|
function estimateTokensForMessage(message) {
|
|
30979
30970
|
const cached = messageTokenEstimateCache.get(message);
|
|
30980
30971
|
if (cached !== void 0) return cached;
|
|
@@ -31028,9 +31019,11 @@ function estimateTokensForContentPart(part) {
|
|
|
31028
31019
|
default: return 0;
|
|
31029
31020
|
}
|
|
31030
31021
|
}
|
|
31031
|
-
var messageTokenEstimateCache, MEDIA_TOKEN_ESTIMATE, MAX_IMAGE_HEADER_BYTES;
|
|
31022
|
+
var createToolSchemaTokenEstimator, estimateTokensForTools, messageTokenEstimateCache, MEDIA_TOKEN_ESTIMATE, MAX_IMAGE_HEADER_BYTES;
|
|
31032
31023
|
var init_tokens = __esmMin((() => {
|
|
31033
31024
|
init_file_type$1();
|
|
31025
|
+
({ createToolSchemaTokenEstimator } = createRequire(import.meta.url)("./bin/tool-schema-token-cache-policy.cjs"));
|
|
31026
|
+
estimateTokensForTools = createToolSchemaTokenEstimator(estimateTokens$1);
|
|
31034
31027
|
messageTokenEstimateCache = /* @__PURE__ */ new WeakMap();
|
|
31035
31028
|
MEDIA_TOKEN_ESTIMATE = 2e3;
|
|
31036
31029
|
MAX_IMAGE_HEADER_BYTES = 1024 * 1024;
|
|
@@ -264960,23 +264953,15 @@ function splitGenerateOptions(options) {
|
|
|
264960
264953
|
generateOptions
|
|
264961
264954
|
};
|
|
264962
264955
|
}
|
|
264963
|
-
|
|
264964
|
-
return tools.map(({ name, description, parameters }) => ({
|
|
264965
|
-
name,
|
|
264966
|
-
description,
|
|
264967
|
-
parameters
|
|
264968
|
-
}));
|
|
264969
|
-
}
|
|
264970
|
-
function fingerprint(content) {
|
|
264971
|
-
return createHash("sha256").update(content).digest("hex");
|
|
264972
|
-
}
|
|
264973
|
-
var LlmRequestLogger;
|
|
264956
|
+
var createLlmConfigChangeDetector, LlmRequestLogger;
|
|
264974
264957
|
var init_llm_request_logger = __esmMin((() => {
|
|
264958
|
+
createLlmConfigChangeDetector = createRequire(import.meta.url)("./bin/llm-config-log-dedup-policy.cjs").createLlmConfigChangeDetector;
|
|
264975
264959
|
LlmRequestLogger = class {
|
|
264976
264960
|
log;
|
|
264977
|
-
|
|
264961
|
+
shouldLogConfig;
|
|
264978
264962
|
constructor(log) {
|
|
264979
264963
|
this.log = log;
|
|
264964
|
+
this.shouldLogConfig = createLlmConfigChangeDetector();
|
|
264980
264965
|
}
|
|
264981
264966
|
logRequest(input) {
|
|
264982
264967
|
const { provider, modelAlias, systemPrompt, tools, messages, fields } = input;
|
|
@@ -264989,13 +264974,11 @@ var init_llm_request_logger = __esmMin((() => {
|
|
|
264989
264974
|
systemPromptChars: systemPrompt.length,
|
|
264990
264975
|
toolCount: tools.length
|
|
264991
264976
|
};
|
|
264992
|
-
|
|
264977
|
+
if (this.shouldLogConfig({
|
|
264993
264978
|
...config,
|
|
264994
|
-
|
|
264995
|
-
|
|
264996
|
-
})
|
|
264997
|
-
if (signature !== this.lastConfigLogSignature) {
|
|
264998
|
-
this.lastConfigLogSignature = signature;
|
|
264979
|
+
systemPrompt,
|
|
264980
|
+
tools
|
|
264981
|
+
})) {
|
|
264999
264982
|
this.log.info("llm config", {
|
|
265000
264983
|
...requestLogFields,
|
|
265001
264984
|
...config
|