blun-king-cli 9.1.352 → 9.1.354
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/tool-schema-token-cache-policy.cjs +41 -0
- package/blun.mjs +12 -14
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -507329,14 +507322,16 @@ var SubAgentEventHandler = class {
|
|
|
507329
507322
|
for (const progress of this.agentSwarmProgress.values()) progress.setActivitySpinnerText(spinner === void 0 ? void 0 : (width) => spinner.renderInline(width));
|
|
507330
507323
|
}
|
|
507331
507324
|
handleAgentSwarmToolCallStarted(toolCallId, args) {
|
|
507325
|
+
this.clearSwarmDeltaRenderTimer();
|
|
507332
507326
|
this.ensureAgentSwarmProgress(toolCallId, args).markInputComplete();
|
|
507333
507327
|
this.requestRender();
|
|
507334
507328
|
}
|
|
507335
|
-
handleAgentSwarmToolCallDelta(toolCallId, args, options) {
|
|
507329
|
+
handleAgentSwarmToolCallDelta(toolCallId, args, options, deltaChars) {
|
|
507336
507330
|
this.ensureAgentSwarmProgress(toolCallId, args, options);
|
|
507337
|
-
this.
|
|
507331
|
+
this.scheduleSwarmDeltaRender(deltaChars);
|
|
507338
507332
|
}
|
|
507339
507333
|
handleAgentSwarmToolResult(toolCallId, resultData, isError) {
|
|
507334
|
+
this.clearSwarmDeltaRenderTimer();
|
|
507340
507335
|
const progress = this.agentSwarmProgress.get(toolCallId);
|
|
507341
507336
|
if (progress === void 0) return;
|
|
507342
507337
|
if (isError && isUserCancelledSubagentError(resultData.output)) if (progress.isRequestStreaming()) this.removeAgentSwarmProgress(toolCallId, progress);
|
|
@@ -507365,7 +507360,10 @@ var SubAgentEventHandler = class {
|
|
|
507365
507360
|
progress.markActiveCancelled();
|
|
507366
507361
|
updated = true;
|
|
507367
507362
|
}
|
|
507368
|
-
if (updated)
|
|
507363
|
+
if (updated) {
|
|
507364
|
+
this.clearSwarmDeltaRenderTimer();
|
|
507365
|
+
this.requestRender();
|
|
507366
|
+
}
|
|
507369
507367
|
}
|
|
507370
507368
|
handleSubagentSpawned(event) {
|
|
507371
507369
|
this.rememberSubagent(event);
|
|
@@ -508286,7 +508284,7 @@ var SessionEventHandler = class {
|
|
|
508286
508284
|
hasAgentSwarmProgress: this.subAgentEventHandler.hasAgentSwarmProgress(event.toolCallId)
|
|
508287
508285
|
})) {
|
|
508288
508286
|
const preview = streamingUI.getStreamingToolCallPreview(event.toolCallId);
|
|
508289
|
-
if (preview !== void 0) this.subAgentEventHandler.handleAgentSwarmToolCallDelta(event.toolCallId, preview.args, { streamingArguments: preview.argumentsText });
|
|
508287
|
+
if (preview !== void 0) this.subAgentEventHandler.handleAgentSwarmToolCallDelta(event.toolCallId, preview.args, { streamingArguments: preview.argumentsText }, event.argumentsPart.length);
|
|
508290
508288
|
}
|
|
508291
508289
|
this.host.patchLivePane({
|
|
508292
508290
|
mode: "tool",
|