Skip to content

Commit 801332a

Browse files
committed
fix: recover Kimi bash text tool calls
1 parent 8268cb5 commit 801332a

6 files changed

Lines changed: 128825 additions & 131647 deletions

File tree

dist/cli.js

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82115,6 +82115,31 @@ function callFromGptObject(parsed) {
8211582115
if (!isPlainObject(params)) return null;
8211682116
return { name: name.trim(), args: normalizeGptArgs(params) };
8211782117
}
82118+
function callFromBashCmdObject(parsed) {
82119+
if (!isPlainObject(parsed) || !Array.isArray(parsed.cmd)) return null;
82120+
const [bin, flag, command, ...rest] = parsed.cmd;
82121+
if (rest.length > 0 || typeof bin !== "string" || typeof flag !== "string" || typeof command !== "string") {
82122+
return null;
82123+
}
82124+
if (bin.split("/").pop() !== "bash" || flag !== "-lc" || command.trim() === "") return null;
82125+
const args = { command };
82126+
if (typeof parsed.timeout === "number" && Number.isFinite(parsed.timeout)) {
82127+
args.timeout = parsed.timeout;
82128+
}
82129+
return { name: "terminal", args };
82130+
}
82131+
function callFromNarratedWebSearchObject(parsed, prefix) {
82132+
if (!isPlainObject(parsed) || typeof parsed.query !== "string" || parsed.query.trim() === "") {
82133+
return null;
82134+
}
82135+
if (!/\bweb[_-]?search\b/i.test(prefix)) return null;
82136+
const args = { query: parsed.query };
82137+
for (const key2 of ["top_n", "recency_days"]) {
82138+
const value = parsed[key2];
82139+
if (typeof value === "number" && Number.isFinite(value)) args[key2] = value;
82140+
}
82141+
return { name: "web_search", args, consumeProse: true };
82142+
}
8211882143
function findTrailingJsonObject(content) {
8211982144
let end = content.length;
8212082145
while (end > 0 && /\s/.test(content[end - 1])) end--;
@@ -82167,14 +82192,17 @@ function extractGptCalls(content) {
8216782192
}
8216882193
const trailing = findTrailingJsonObject(content);
8216982194
if (trailing) {
82170-
const built = callFromGptObject(trailing.parsed);
82195+
const prefix = content.slice(0, trailing.start);
82196+
const built = callFromGptObject(trailing.parsed) ?? callFromBashCmdObject(trailing.parsed) ?? callFromNarratedWebSearchObject(trailing.parsed, prefix);
8217182197
if (built) {
82172-
const hasProseBefore = content.slice(0, trailing.start).trim() !== "";
82198+
const hasProseBefore = prefix.trim() !== "";
8217382199
const typeIsFunction = trailing.parsed.type === "function";
82174-
if (!hasProseBefore || typeIsFunction) {
82200+
const isBashCmd = built.name === "terminal" && callFromBashCmdObject(trailing.parsed) !== null;
82201+
const consumeProse = "consumeProse" in built && built.consumeProse === true;
82202+
if (!hasProseBefore || typeIsFunction || isBashCmd || consumeProse) {
8217582203
return {
8217682204
calls: [makeCall(built.name, built.args)],
82177-
matches: [{ start: hasProseBefore ? trailing.start : 0, end: content.length }]
82205+
matches: [{ start: hasProseBefore && !consumeProse ? trailing.start : 0, end: content.length }]
8217882206
};
8217982207
}
8218082208
}
@@ -216355,23 +216383,14 @@ function sanitizeErrorResponse(errorBody) {
216355216383
code: typeof body.code === "string" ? body.code : void 0
216356216384
};
216357216385
}
216358-
function resolveDefaultTimeout() {
216359-
const envVal = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_CHAT_TIMEOUT : void 0;
216360-
if (envVal !== void 0) {
216361-
const seconds = Number(envVal);
216362-
if (Number.isFinite(seconds) && seconds > 0) {
216363-
return seconds * 1e3;
216364-
}
216365-
}
216366-
return 6e5;
216367-
}
216368216386
function sleep2(ms) {
216369216387
return new Promise((r2) => setTimeout(r2, ms));
216370216388
}
216371-
var BlockrunError, PaymentError, APIError, BASE_CHAIN_ID2, USDC_BASE2, USDC_DOMAIN, TRANSFER_TYPES, LOCALHOST_DOMAINS, BLOCKRUN_DIR2, COST_LOG_FILE, DEFAULT_TIMEOUT, SDK_VERSION, USER_AGENT2, PHONE_PRICES, DEFAULT_API_URL13, DEFAULT_TIMEOUT13, DEFAULT_POLL_INTERVAL_MS, DEFAULT_POLL_BUDGET_MS, MAX_SIGNED_AUTH_SECONDS, BlockrunClient, WALLET_DIR2, WALLET_FILE3, WALLET_DIR22, SOLANA_WALLET_FILE, SDK_VERSION2, USER_AGENT22, CACHE_DIR, DATA_DIR, COST_LOG_FILE2, DEFAULT_TTL;
216389+
var BlockrunError, PaymentError, APIError, BASE_CHAIN_ID2, USDC_BASE2, USDC_DOMAIN, TRANSFER_TYPES, LOCALHOST_DOMAINS, BLOCKRUN_DIR2, COST_LOG_FILE, SDK_VERSION, USER_AGENT2, PHONE_PRICES, DEFAULT_API_URL14, DEFAULT_TIMEOUT14, DEFAULT_POLL_INTERVAL_MS, DEFAULT_POLL_BUDGET_MS, MAX_SIGNED_AUTH_SECONDS, BlockrunClient, WALLET_DIR2, WALLET_FILE3, WALLET_DIR22, SOLANA_WALLET_FILE, SDK_VERSION2, USER_AGENT22, CACHE_DIR, DATA_DIR, COST_LOG_FILE2, DEFAULT_TTL;
216372216390
var init_dist6 = __esm({
216373216391
"node_modules/@blockrun/llm/dist/index.js"() {
216374216392
"use strict";
216393+
init_index();
216375216394
init_accounts();
216376216395
init_accounts();
216377216396
BlockrunError = class extends Error {
@@ -216417,7 +216436,6 @@ var init_dist6 = __esm({
216417216436
LOCALHOST_DOMAINS = ["localhost", "127.0.0.1"];
216418216437
BLOCKRUN_DIR2 = path2.join(os2.homedir(), ".blockrun");
216419216438
COST_LOG_FILE = path2.join(BLOCKRUN_DIR2, "cost_log.jsonl");
216420-
DEFAULT_TIMEOUT = resolveDefaultTimeout();
216421216439
SDK_VERSION = "1.5.0";
216422216440
USER_AGENT2 = `blockrun-ts/${SDK_VERSION}`;
216423216441
PHONE_PRICES = Object.freeze({
@@ -216428,8 +216446,8 @@ var init_dist6 = __esm({
216428216446
"numbers/list": 1e-3,
216429216447
"numbers/release": 0
216430216448
});
216431-
DEFAULT_API_URL13 = "https://blockrun.ai/api";
216432-
DEFAULT_TIMEOUT13 = 6e4;
216449+
DEFAULT_API_URL14 = "https://blockrun.ai/api";
216450+
DEFAULT_TIMEOUT14 = 6e4;
216433216451
DEFAULT_POLL_INTERVAL_MS = 5e3;
216434216452
DEFAULT_POLL_BUDGET_MS = 3e5;
216435216453
MAX_SIGNED_AUTH_SECONDS = 600;
@@ -216451,10 +216469,10 @@ var init_dist6 = __esm({
216451216469
validatePrivateKey(privateKey);
216452216470
this.privateKey = privateKey;
216453216471
this.account = privateKeyToAccount(privateKey);
216454-
const apiUrl = options.apiUrl || DEFAULT_API_URL13;
216472+
const apiUrl = options.apiUrl || DEFAULT_API_URL14;
216455216473
validateApiUrl(apiUrl);
216456216474
this.apiUrl = apiUrl.replace(/\/$/, "");
216457-
this.timeout = options.timeout || DEFAULT_TIMEOUT13;
216475+
this.timeout = options.timeout || DEFAULT_TIMEOUT14;
216458216476
}
216459216477
/**
216460216478
* GET a BlockRun endpoint. `path` is everything after `/api` (a leading
@@ -216810,6 +216828,7 @@ var init_dist6 = __esm({
216810216828
DATA_DIR = path4.join(os4.homedir(), ".blockrun", "data");
216811216829
COST_LOG_FILE2 = path4.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
216812216830
DEFAULT_TTL = {
216831+
"/v1/x/": 3600 * 1e3,
216813216832
"/v1/partner/": 3600 * 1e3,
216814216833
"/v1/pm/": 1800 * 1e3,
216815216834
"/v1/chat/": 0,

0 commit comments

Comments
 (0)