@bunny-agent/runner-cli 0.9.50 → 0.9.51-beta.1
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/dist/bundle.mjs +100 -17
- package/package.json +3 -3
package/dist/bundle.mjs
CHANGED
|
@@ -5349,12 +5349,79 @@ function serializeResult(result) {
|
|
|
5349
5349
|
|
|
5350
5350
|
// ../../packages/runner-pi/dist/pi-runner.js
|
|
5351
5351
|
var LOG_PREFIX2 = "[bunny-agent:pi]";
|
|
5352
|
+
var LLM_THOUGHT_SIGNATURE_SEPARATOR = "__thought__";
|
|
5352
5353
|
function applyAllowedTools(tools, allowedTools) {
|
|
5353
5354
|
if (!allowedTools)
|
|
5354
5355
|
return tools;
|
|
5355
5356
|
const allowed = new Set(allowedTools);
|
|
5356
5357
|
return tools.filter((tool) => allowed.has(tool.name));
|
|
5357
5358
|
}
|
|
5359
|
+
function shouldStripLLMThoughtSignaturesForModel(model) {
|
|
5360
|
+
const id = (model.id ?? "").toLowerCase();
|
|
5361
|
+
return !id.includes("gemini");
|
|
5362
|
+
}
|
|
5363
|
+
function stripLLMThoughtSignatureFromId(id) {
|
|
5364
|
+
const separatorIndex = id.indexOf(LLM_THOUGHT_SIGNATURE_SEPARATOR);
|
|
5365
|
+
if (separatorIndex === -1)
|
|
5366
|
+
return id;
|
|
5367
|
+
return id.slice(0, separatorIndex);
|
|
5368
|
+
}
|
|
5369
|
+
function stripLLMThoughtSignaturesFromSessionManager(sessionManager, model) {
|
|
5370
|
+
if (!shouldStripLLMThoughtSignaturesForModel(model))
|
|
5371
|
+
return;
|
|
5372
|
+
const manager = sessionManager;
|
|
5373
|
+
const entries = manager.getEntries?.();
|
|
5374
|
+
if (Array.isArray(entries)) {
|
|
5375
|
+
for (const entry of entries) {
|
|
5376
|
+
if (entry == null || typeof entry !== "object")
|
|
5377
|
+
continue;
|
|
5378
|
+
const message = entry.message;
|
|
5379
|
+
if (entry.type === "message") {
|
|
5380
|
+
stripLLMThoughtSignaturesFromMessage(message);
|
|
5381
|
+
}
|
|
5382
|
+
}
|
|
5383
|
+
return;
|
|
5384
|
+
}
|
|
5385
|
+
const context = sessionManager.buildSessionContext?.();
|
|
5386
|
+
const messages = context?.messages;
|
|
5387
|
+
if (!Array.isArray(messages))
|
|
5388
|
+
return;
|
|
5389
|
+
for (const message of messages) {
|
|
5390
|
+
stripLLMThoughtSignaturesFromMessage(message);
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
function stripLLMThoughtSignaturesFromMessage(message) {
|
|
5394
|
+
if (message == null || typeof message !== "object")
|
|
5395
|
+
return;
|
|
5396
|
+
const msg = message;
|
|
5397
|
+
if (typeof msg.toolCallId === "string") {
|
|
5398
|
+
msg.toolCallId = stripLLMThoughtSignatureFromId(msg.toolCallId);
|
|
5399
|
+
}
|
|
5400
|
+
if (typeof msg.tool_call_id === "string") {
|
|
5401
|
+
msg.tool_call_id = stripLLMThoughtSignatureFromId(msg.tool_call_id);
|
|
5402
|
+
}
|
|
5403
|
+
if (!Array.isArray(msg.content))
|
|
5404
|
+
return;
|
|
5405
|
+
for (const block of msg.content) {
|
|
5406
|
+
if (block == null || typeof block !== "object")
|
|
5407
|
+
continue;
|
|
5408
|
+
const contentBlock = block;
|
|
5409
|
+
if (contentBlock.type !== "toolCall")
|
|
5410
|
+
continue;
|
|
5411
|
+
if (typeof contentBlock.id === "string") {
|
|
5412
|
+
contentBlock.id = stripLLMThoughtSignatureFromId(contentBlock.id);
|
|
5413
|
+
}
|
|
5414
|
+
if (typeof contentBlock.toolCallId === "string") {
|
|
5415
|
+
contentBlock.toolCallId = stripLLMThoughtSignatureFromId(contentBlock.toolCallId);
|
|
5416
|
+
}
|
|
5417
|
+
if (typeof contentBlock.tool_call_id === "string") {
|
|
5418
|
+
contentBlock.tool_call_id = stripLLMThoughtSignatureFromId(contentBlock.tool_call_id);
|
|
5419
|
+
}
|
|
5420
|
+
if (typeof contentBlock.call_id === "string") {
|
|
5421
|
+
contentBlock.call_id = stripLLMThoughtSignatureFromId(contentBlock.call_id);
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
}
|
|
5358
5425
|
function parseModelSpec(model) {
|
|
5359
5426
|
const trimmed = model.trim();
|
|
5360
5427
|
const separator = trimmed.indexOf(":");
|
|
@@ -5504,6 +5571,7 @@ function createPiRunner(options = {}) {
|
|
|
5504
5571
|
}
|
|
5505
5572
|
return SessionManager2.create(cwd);
|
|
5506
5573
|
})();
|
|
5574
|
+
stripLLMThoughtSignaturesFromSessionManager(sessionManager, model);
|
|
5507
5575
|
const resourceLoader = options.skillPaths ? new BunnyAgentResourceLoader({
|
|
5508
5576
|
cwd,
|
|
5509
5577
|
skillPaths: options.skillPaths,
|
|
@@ -5537,7 +5605,9 @@ function createPiRunner(options = {}) {
|
|
|
5537
5605
|
]
|
|
5538
5606
|
});
|
|
5539
5607
|
const eventQueue = [];
|
|
5540
|
-
let
|
|
5608
|
+
let promptSettled = false;
|
|
5609
|
+
let promptError;
|
|
5610
|
+
let finalAgentEnd = void 0;
|
|
5541
5611
|
let aborted = false;
|
|
5542
5612
|
let wakeConsumer = null;
|
|
5543
5613
|
const notify = () => {
|
|
@@ -5546,15 +5616,11 @@ function createPiRunner(options = {}) {
|
|
|
5546
5616
|
};
|
|
5547
5617
|
const unsubscribe = session.subscribe((e) => {
|
|
5548
5618
|
eventQueue.push(e);
|
|
5549
|
-
if (e.type === "agent_end") {
|
|
5550
|
-
isComplete = true;
|
|
5551
|
-
}
|
|
5552
5619
|
notify();
|
|
5553
5620
|
});
|
|
5554
5621
|
const abortSignal = options.abortController?.signal;
|
|
5555
5622
|
const abortHandler = () => {
|
|
5556
5623
|
aborted = true;
|
|
5557
|
-
isComplete = true;
|
|
5558
5624
|
void session.abort();
|
|
5559
5625
|
notify();
|
|
5560
5626
|
};
|
|
@@ -5568,6 +5634,14 @@ function createPiRunner(options = {}) {
|
|
|
5568
5634
|
traceRawMessage(cwd, null, true, options.env);
|
|
5569
5635
|
const promptText = userInput;
|
|
5570
5636
|
const promptPromise = session.prompt(promptText);
|
|
5637
|
+
void promptPromise.then(() => {
|
|
5638
|
+
promptSettled = true;
|
|
5639
|
+
notify();
|
|
5640
|
+
}, (error) => {
|
|
5641
|
+
promptError = error;
|
|
5642
|
+
promptSettled = true;
|
|
5643
|
+
notify();
|
|
5644
|
+
});
|
|
5571
5645
|
const streamConverter = new PiAISDKStreamConverter({
|
|
5572
5646
|
sessionId: session.sessionId,
|
|
5573
5647
|
model,
|
|
@@ -5575,10 +5649,14 @@ function createPiRunner(options = {}) {
|
|
|
5575
5649
|
getUsageFromAgentEndMessages,
|
|
5576
5650
|
getErrorFromAgentEndMessages
|
|
5577
5651
|
});
|
|
5578
|
-
while (!
|
|
5652
|
+
while (!promptSettled && !aborted || eventQueue.length > 0) {
|
|
5579
5653
|
while (eventQueue.length > 0) {
|
|
5580
5654
|
const event = eventQueue.shift();
|
|
5581
5655
|
traceRawMessage(cwd, event, false, options.env);
|
|
5656
|
+
if (event.type === "agent_end") {
|
|
5657
|
+
finalAgentEnd = event;
|
|
5658
|
+
continue;
|
|
5659
|
+
}
|
|
5582
5660
|
const chunks = streamConverter.handleEvent(event, aborted);
|
|
5583
5661
|
for (const chunk of chunks) {
|
|
5584
5662
|
yield chunk;
|
|
@@ -5590,30 +5668,35 @@ function createPiRunner(options = {}) {
|
|
|
5590
5668
|
}
|
|
5591
5669
|
break;
|
|
5592
5670
|
}
|
|
5593
|
-
if (!
|
|
5671
|
+
if (!promptSettled && !aborted && eventQueue.length === 0) {
|
|
5594
5672
|
await new Promise((resolve4) => {
|
|
5595
5673
|
wakeConsumer = resolve4;
|
|
5596
5674
|
});
|
|
5597
5675
|
}
|
|
5598
5676
|
}
|
|
5599
|
-
if (
|
|
5677
|
+
if (aborted) {
|
|
5600
5678
|
return;
|
|
5601
5679
|
}
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
const message = error instanceof Error ? error.message : "Pi agent run failed.";
|
|
5607
|
-
for (const chunk of streamConverter.forceError(message)) {
|
|
5608
|
-
yield chunk;
|
|
5609
|
-
}
|
|
5680
|
+
if (promptError !== void 0) {
|
|
5681
|
+
const message = promptError instanceof Error ? promptError.message : "Pi agent run failed.";
|
|
5682
|
+
for (const chunk of streamConverter.forceError(message)) {
|
|
5683
|
+
yield chunk;
|
|
5610
5684
|
}
|
|
5611
5685
|
return;
|
|
5612
5686
|
}
|
|
5613
|
-
if (
|
|
5687
|
+
if (finalAgentEnd) {
|
|
5688
|
+
const chunks = streamConverter.handleEvent(finalAgentEnd, false);
|
|
5689
|
+
for (const chunk of chunks) {
|
|
5690
|
+
yield chunk;
|
|
5691
|
+
}
|
|
5692
|
+
} else if (session.agent.state.errorMessage) {
|
|
5614
5693
|
for (const chunk of streamConverter.forceError(session.agent.state.errorMessage)) {
|
|
5615
5694
|
yield chunk;
|
|
5616
5695
|
}
|
|
5696
|
+
} else {
|
|
5697
|
+
for (const chunk of streamConverter.forceError("Pi agent run completed without an agent_end event.")) {
|
|
5698
|
+
yield chunk;
|
|
5699
|
+
}
|
|
5617
5700
|
}
|
|
5618
5701
|
} finally {
|
|
5619
5702
|
if (abortSignal) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bunny-agent/runner-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.51-beta.1",
|
|
4
4
|
"description": "BunnyAgent Runner CLI - Like gemini-cli or claude-code, runs in your local terminal with AI SDK UI streaming",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"esbuild": "^0.27.2",
|
|
54
54
|
"typescript": "^5.3.0",
|
|
55
55
|
"vitest": "^1.6.1",
|
|
56
|
+
"@bunny-agent/runner-claude": "0.6.2",
|
|
56
57
|
"@bunny-agent/runner-harness": "0.1.1-beta.0",
|
|
58
|
+
"@bunny-agent/runner-codex": "0.6.2",
|
|
57
59
|
"@bunny-agent/runner-gemini": "0.6.2",
|
|
58
|
-
"@bunny-agent/runner-claude": "0.6.2",
|
|
59
60
|
"@bunny-agent/runner-opencode": "0.6.2",
|
|
60
|
-
"@bunny-agent/runner-codex": "0.6.2",
|
|
61
61
|
"@bunny-agent/runner-pi": "0.6.4-beta.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|