blun-king-cli 9.1.353 → 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.
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.353",
3
+ "version": "9.1.354",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {