@swifty.js/swifty 0.0.22 → 0.0.24
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/{agent-5T7KNC7V.js → agent-24XMR2WX.js} +1 -1
- package/dist/anthropic-7QRAPLOY.js +4 -0
- package/dist/{checker-OJFS2MZY.js → checker-3RWAYF2U.js} +1 -1
- package/dist/{chunk-HJIGA37J.js → chunk-5KXBVL2A.js} +1 -1
- package/dist/chunk-FAJYJI6T.js +389 -0
- package/dist/chunk-MWZIARZE.js +130 -0
- package/dist/{chunk-GUXBLUNR.js → chunk-NR62AA5K.js} +1 -1
- package/dist/chunk-QN27QEFS.js +4 -0
- package/dist/{chunk-LX2LK3TF.js → chunk-SIWLMWHH.js} +12 -11
- package/dist/{chunk-NEAR6YPZ.js → chunk-VQUWSKQQ.js} +21 -20
- package/dist/{chunk-NLNH3IRT.js → chunk-W37Y53LX.js} +1 -1
- package/dist/lib/agent-U42LS73D.js +9 -0
- package/dist/lib/{anthropic-GFWP3ORB.js → anthropic-RYPJDHQM.js} +6 -6
- package/dist/lib/{checker-IIXJXQCB.js → checker-6BW4222R.js} +3 -3
- package/dist/lib/{chunk-LUEP4JMF.js → chunk-2AUSNVIB.js} +8 -12
- package/dist/lib/{chunk-C7IHCJZ3.js → chunk-2QILP24G.js} +283 -12
- package/dist/lib/{chunk-6GOWRPYS.js → chunk-3LU4APFB.js} +2 -2
- package/dist/lib/{chunk-EJLGB2EJ.js → chunk-EY7HE52Q.js} +14 -7
- package/dist/lib/{chunk-7URDLWQN.js → chunk-GNI7YX6F.js} +2 -2
- package/dist/lib/{chunk-UMFNTXKA.js → chunk-OO2CLOEE.js} +38 -38
- package/dist/lib/{chunk-GNBXECZN.js → chunk-PZ42NAFA.js} +2 -3
- package/dist/lib/{chunk-RR2CZ6CY.js → chunk-XFSN4LMA.js} +94 -75
- package/dist/lib/{chunk-UHVO63Y7.js → chunk-XG6NELJH.js} +69 -38
- package/dist/lib/index.d.ts +234 -237
- package/dist/lib/index.js +212 -224
- package/dist/lib/{openai-HXRMPNB7.js → openai-VX5VBXZ4.js} +4 -4
- package/dist/main.js +197 -465
- package/dist/{openai-TVUUHRG7.js → openai-6MXNADYN.js} +15 -15
- package/dist/{server-ZTLHJWEQ.js → server-NJ2NXAOI.js} +16 -16
- package/package.json +5 -5
- package/dist/anthropic-P2R4GW6F.js +0 -4
- package/dist/chunk-L73IHJF4.js +0 -386
- package/dist/chunk-YQQVB6VB.js +0 -127
- package/dist/chunk-ZZQE743W.js +0 -4
- package/dist/lib/agent-2AGRYN3R.js +0 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getMaxOutputTokens,
|
|
3
3
|
resolveAPIKey
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3LU4APFB.js";
|
|
5
5
|
import {
|
|
6
6
|
AuthenticationError,
|
|
7
7
|
ContextTooLongError,
|
|
@@ -9,16 +9,15 @@ import {
|
|
|
9
9
|
NetworkError,
|
|
10
10
|
RateLimitError,
|
|
11
11
|
ensureToolPairing
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-OO2CLOEE.js";
|
|
13
13
|
import {
|
|
14
|
-
DANGEROUSLY_JSON,
|
|
15
14
|
asRecord,
|
|
16
15
|
asString,
|
|
17
16
|
contentToText,
|
|
18
17
|
createChildLogger,
|
|
19
18
|
isRecord,
|
|
20
19
|
strArg
|
|
21
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-EY7HE52Q.js";
|
|
22
21
|
|
|
23
22
|
// src/llm/openai.ts
|
|
24
23
|
import OpenAI from "openai";
|
|
@@ -124,12 +123,10 @@ var OpenAIClient = class {
|
|
|
124
123
|
if (jsonAccumulate) {
|
|
125
124
|
try {
|
|
126
125
|
const parsed = JSON.parse(jsonAccumulate);
|
|
127
|
-
args = isRecord(parsed) ? asRecord(parsed) : {
|
|
126
|
+
args = isRecord(parsed) ? asRecord(parsed) : {};
|
|
128
127
|
} catch (err) {
|
|
129
128
|
log.error({ err }, "llm operation failed");
|
|
130
|
-
args = {
|
|
131
|
-
[DANGEROUSLY_JSON]: jsonAccumulate
|
|
132
|
-
};
|
|
129
|
+
args = {};
|
|
133
130
|
}
|
|
134
131
|
}
|
|
135
132
|
yield {
|
|
@@ -183,72 +180,104 @@ var OpenAIClient = class {
|
|
|
183
180
|
}
|
|
184
181
|
};
|
|
185
182
|
function imageDataUrl(block) {
|
|
186
|
-
if (block.type !== "image") {
|
|
183
|
+
if (!isRecord(block) || block.type !== "image" || !isRecord(block.source)) {
|
|
187
184
|
return null;
|
|
188
185
|
}
|
|
189
|
-
|
|
190
|
-
|
|
186
|
+
if (block.source.type === "url") {
|
|
187
|
+
return strArg(block.source, "url") || null;
|
|
188
|
+
}
|
|
189
|
+
if (block.source.type !== "base64") {
|
|
191
190
|
return null;
|
|
192
191
|
}
|
|
193
|
-
const mediaType = strArg(source, "media_type");
|
|
194
|
-
const data = strArg(source, "data");
|
|
195
|
-
|
|
192
|
+
const mediaType = strArg(block.source, "media_type");
|
|
193
|
+
const data = strArg(block.source, "data");
|
|
194
|
+
return mediaType && data ? `data:${mediaType};base64,${data}` : null;
|
|
195
|
+
}
|
|
196
|
+
function documentForResponses(block) {
|
|
197
|
+
if (!isRecord(block) || block.type !== "document" || !isRecord(block.source)) {
|
|
196
198
|
return null;
|
|
197
199
|
}
|
|
198
|
-
|
|
200
|
+
const title = typeof block.title === "string" && block.title ? block.title : "tool-result";
|
|
201
|
+
if (block.source.type === "url") {
|
|
202
|
+
const fileUrl = strArg(block.source, "url");
|
|
203
|
+
return fileUrl ? { type: "input_file", file_url: fileUrl } : null;
|
|
204
|
+
}
|
|
205
|
+
if (block.source.type === "base64") {
|
|
206
|
+
const data = strArg(block.source, "data");
|
|
207
|
+
return data ? { type: "input_file", file_data: data, filename: `${title}.pdf` } : null;
|
|
208
|
+
}
|
|
209
|
+
if (block.source.type === "text") {
|
|
210
|
+
const data = strArg(block.source, "data");
|
|
211
|
+
return data ? {
|
|
212
|
+
type: "input_file",
|
|
213
|
+
file_data: Buffer.from(data, "utf-8").toString("base64"),
|
|
214
|
+
filename: `${title}.txt`
|
|
215
|
+
} : null;
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
199
218
|
}
|
|
200
|
-
function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return [];
|
|
219
|
+
function documentForChat(block) {
|
|
220
|
+
if (!isRecord(block) || block.type !== "document" || !isRecord(block.source)) {
|
|
221
|
+
return null;
|
|
204
222
|
}
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
images.push({
|
|
210
|
-
type: "input_image",
|
|
211
|
-
image_url: url,
|
|
212
|
-
detail: "auto"
|
|
213
|
-
});
|
|
214
|
-
}
|
|
223
|
+
const title = typeof block.title === "string" && block.title ? block.title : "tool-result";
|
|
224
|
+
if (block.source.type === "base64") {
|
|
225
|
+
const data = strArg(block.source, "data");
|
|
226
|
+
return data ? { type: "file", file: { file_data: data, filename: `${title}.pdf` } } : null;
|
|
215
227
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
228
|
+
if (block.source.type === "text") {
|
|
229
|
+
const data = strArg(block.source, "data");
|
|
230
|
+
return data ? {
|
|
231
|
+
type: "file",
|
|
232
|
+
file: {
|
|
233
|
+
file_data: Buffer.from(data, "utf-8").toString("base64"),
|
|
234
|
+
filename: `${title}.txt`
|
|
235
|
+
}
|
|
236
|
+
} : null;
|
|
218
237
|
}
|
|
219
|
-
return
|
|
220
|
-
{
|
|
221
|
-
type: "input_text",
|
|
222
|
-
text: `[Image(s) returned by tool call ${toolUseId}]`
|
|
223
|
-
},
|
|
224
|
-
...images
|
|
225
|
-
];
|
|
238
|
+
return null;
|
|
226
239
|
}
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
|
|
240
|
+
function toolOutputForResponses(tr) {
|
|
241
|
+
if (!tr.contentBlocks?.length) {
|
|
242
|
+
return tr.content;
|
|
243
|
+
}
|
|
244
|
+
const rich = [];
|
|
245
|
+
if (tr.content) {
|
|
246
|
+
rich.push({ type: "input_text", text: tr.content });
|
|
247
|
+
}
|
|
248
|
+
for (const block of tr.contentBlocks) {
|
|
249
|
+
const imageUrl = imageDataUrl(block);
|
|
250
|
+
if (imageUrl) {
|
|
251
|
+
rich.push({ type: "input_image", image_url: imageUrl, detail: "auto" });
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const file = documentForResponses(block);
|
|
255
|
+
if (file) {
|
|
256
|
+
rich.push(file);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return rich.length > 0 ? rich : tr.content;
|
|
260
|
+
}
|
|
261
|
+
function collectRichParts(tr) {
|
|
262
|
+
if (!tr.contentBlocks?.length) {
|
|
230
263
|
return [];
|
|
231
264
|
}
|
|
232
|
-
const
|
|
233
|
-
for (const block of
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
265
|
+
const rich = [];
|
|
266
|
+
for (const block of tr.contentBlocks) {
|
|
267
|
+
const imageUrl = imageDataUrl(block);
|
|
268
|
+
if (imageUrl) {
|
|
269
|
+
rich.push({ type: "image_url", image_url: { url: imageUrl } });
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const file = documentForChat(block);
|
|
273
|
+
if (file) {
|
|
274
|
+
rich.push(file);
|
|
240
275
|
}
|
|
241
276
|
}
|
|
242
|
-
if (
|
|
277
|
+
if (rich.length === 0) {
|
|
243
278
|
return [];
|
|
244
279
|
}
|
|
245
|
-
return [
|
|
246
|
-
{
|
|
247
|
-
type: "text",
|
|
248
|
-
text: `[Image(s) returned by tool call ${toolUseId}]`
|
|
249
|
-
},
|
|
250
|
-
...images
|
|
251
|
-
];
|
|
280
|
+
return [{ type: "text", text: `[Rich content returned by tool call ${tr.toolUseId}]` }, ...rich];
|
|
252
281
|
}
|
|
253
282
|
function userContentsFor(content) {
|
|
254
283
|
if (typeof content === "string") {
|
|
@@ -313,19 +342,11 @@ function buildOpenAIInput(messages) {
|
|
|
313
342
|
});
|
|
314
343
|
}
|
|
315
344
|
} else if (m.toolResults && m.toolResults.length > 0) {
|
|
316
|
-
const pendingImageContents = [];
|
|
317
345
|
for (const tr of m.toolResults) {
|
|
318
346
|
result.push({
|
|
319
347
|
type: "function_call_output",
|
|
320
348
|
call_id: tr.toolUseId,
|
|
321
|
-
output:
|
|
322
|
-
});
|
|
323
|
-
pendingImageContents.push(...collectImageContents(tr));
|
|
324
|
-
}
|
|
325
|
-
if (pendingImageContents.length > 0) {
|
|
326
|
-
result.push({
|
|
327
|
-
role: "user",
|
|
328
|
-
content: pendingImageContents
|
|
349
|
+
output: toolOutputForResponses(tr)
|
|
329
350
|
});
|
|
330
351
|
}
|
|
331
352
|
} else if (m.role === "assistant") {
|
|
@@ -474,12 +495,10 @@ var OpenAICompatClient = class {
|
|
|
474
495
|
if (jsonArgs) {
|
|
475
496
|
try {
|
|
476
497
|
const parsed = JSON.parse(jsonArgs);
|
|
477
|
-
args = isRecord(parsed) ? asRecord(parsed) : {
|
|
498
|
+
args = isRecord(parsed) ? asRecord(parsed) : {};
|
|
478
499
|
} catch (err) {
|
|
479
500
|
log.error({ err }, "llm operation failed");
|
|
480
|
-
args = {
|
|
481
|
-
[DANGEROUSLY_JSON]: jsonArgs
|
|
482
|
-
};
|
|
501
|
+
args = {};
|
|
483
502
|
}
|
|
484
503
|
yield {
|
|
485
504
|
type: "tool_call_complete",
|
|
@@ -552,19 +571,19 @@ function buildChatCompletionMessages(messages) {
|
|
|
552
571
|
}))
|
|
553
572
|
});
|
|
554
573
|
} else if (m.toolResults && m.toolResults.length > 0) {
|
|
555
|
-
const
|
|
574
|
+
const pendingRichParts = [];
|
|
556
575
|
for (const tr of m.toolResults) {
|
|
557
576
|
params.push({
|
|
558
577
|
role: "tool",
|
|
559
578
|
tool_call_id: tr.toolUseId,
|
|
560
|
-
content:
|
|
579
|
+
content: tr.content
|
|
561
580
|
});
|
|
562
|
-
|
|
581
|
+
pendingRichParts.push(...collectRichParts(tr));
|
|
563
582
|
}
|
|
564
|
-
if (
|
|
583
|
+
if (pendingRichParts.length > 0) {
|
|
565
584
|
params.push({
|
|
566
585
|
role: "user",
|
|
567
|
-
content:
|
|
586
|
+
content: pendingRichParts
|
|
568
587
|
});
|
|
569
588
|
}
|
|
570
589
|
} else if (m.role === "assistant") {
|
|
@@ -6,24 +6,19 @@ import {
|
|
|
6
6
|
saveMessage,
|
|
7
7
|
toolResultsToRecords,
|
|
8
8
|
toolUsesToRecords
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-2QILP24G.js";
|
|
10
10
|
import {
|
|
11
11
|
ContextTooLongError,
|
|
12
12
|
REJECTED_TOOL_RESULT,
|
|
13
13
|
RateLimitError
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-OO2CLOEE.js";
|
|
15
15
|
import {
|
|
16
16
|
asErrorString,
|
|
17
17
|
asRecord,
|
|
18
|
-
asString,
|
|
19
|
-
contentToText,
|
|
20
18
|
createChildLogger,
|
|
21
19
|
isObject,
|
|
22
20
|
strArg
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
|
|
25
|
-
// src/agent/agent.ts
|
|
26
|
-
import { readFile } from "fs/promises";
|
|
21
|
+
} from "./chunk-EY7HE52Q.js";
|
|
27
22
|
|
|
28
23
|
// src/compact/recovery.ts
|
|
29
24
|
var RECOVERY_FILE_LIMIT = 5;
|
|
@@ -48,13 +43,29 @@ function truncateByTokens(s, tokenBudget) {
|
|
|
48
43
|
if (maxChars <= 0 || maxChars >= s.length) {
|
|
49
44
|
return s;
|
|
50
45
|
}
|
|
51
|
-
|
|
46
|
+
const suffix = "\n\u2026 (content truncated)";
|
|
47
|
+
if (maxChars <= suffix.length) {
|
|
48
|
+
return suffix.slice(0, maxChars);
|
|
49
|
+
}
|
|
50
|
+
return s.slice(0, maxChars - suffix.length) + suffix;
|
|
52
51
|
}
|
|
53
52
|
var RecoveryState = class {
|
|
54
53
|
files = /* @__PURE__ */ new Map();
|
|
55
54
|
skills = /* @__PURE__ */ new Map();
|
|
56
55
|
recordFileRead(path, content) {
|
|
57
|
-
this.files.
|
|
56
|
+
this.files.delete(path);
|
|
57
|
+
this.files.set(path, {
|
|
58
|
+
path,
|
|
59
|
+
content: truncateByTokens(content, RECOVERY_TOKENS_PER_FILE),
|
|
60
|
+
timestamp: Date.now()
|
|
61
|
+
});
|
|
62
|
+
while (this.files.size > RECOVERY_FILE_LIMIT) {
|
|
63
|
+
const oldestPath = this.files.keys().next().value;
|
|
64
|
+
if (typeof oldestPath !== "string") {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
this.files.delete(oldestPath);
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
recordSkillInvocation(name, body) {
|
|
60
71
|
this.skills.set(name, { name, body, timestamp: Date.now() });
|
|
@@ -465,6 +476,7 @@ import { writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
|
465
476
|
import { join as join2, resolve as resolve2 } from "path";
|
|
466
477
|
var log2 = createChildLogger({ module: "tool-result" });
|
|
467
478
|
var MESSAGE_AGGREGATE_LIMIT = 2e5;
|
|
479
|
+
var TOOL_RESULT_PREVIEW_CHARS = 2e3;
|
|
468
480
|
function spillDir(workDir, sessionId) {
|
|
469
481
|
const id = sessionId || "default";
|
|
470
482
|
return join2(workDir, ".swifty", "sessions", id, "tool-results");
|
|
@@ -483,11 +495,26 @@ function writeSpill(workDir, sessionId, toolUseId, content) {
|
|
|
483
495
|
}
|
|
484
496
|
return path;
|
|
485
497
|
}
|
|
486
|
-
|
|
498
|
+
function toDisplayPreview(content) {
|
|
499
|
+
if (content.length <= TOOL_RESULT_PREVIEW_CHARS) {
|
|
500
|
+
return content;
|
|
501
|
+
}
|
|
502
|
+
return content.slice(0, TOOL_RESULT_PREVIEW_CHARS) + `
|
|
503
|
+
\u2026 ${String(content.length - TOOL_RESULT_PREVIEW_CHARS)} chars omitted from transcript`;
|
|
504
|
+
}
|
|
505
|
+
function replaceToolResultContent(result, content) {
|
|
506
|
+
result.content = content;
|
|
507
|
+
if (result.contentBlocks?.length) {
|
|
508
|
+
result.contentBlocks = [
|
|
509
|
+
{ type: "text", text: content },
|
|
510
|
+
...result.contentBlocks.filter((block) => block.type !== "text")
|
|
511
|
+
];
|
|
512
|
+
}
|
|
513
|
+
}
|
|
487
514
|
function buildSpillPreview(content, spillPath) {
|
|
488
515
|
const sizeKB = Math.floor(content.length / 1024);
|
|
489
|
-
const preview = content.slice(0,
|
|
490
|
-
const hasMore = content.length >
|
|
516
|
+
const preview = content.slice(0, TOOL_RESULT_PREVIEW_CHARS);
|
|
517
|
+
const hasMore = content.length > TOOL_RESULT_PREVIEW_CHARS;
|
|
491
518
|
let msg = `<persisted-output>
|
|
492
519
|
`;
|
|
493
520
|
msg += `Output too large (${String(sizeKB)}KB). Full content saved to:
|
|
@@ -513,17 +540,11 @@ function isSpillReadback(toolName, args, workDir, sessionId) {
|
|
|
513
540
|
return resolve2(raw).startsWith(resolve2(spillDir(workDir, sessionId)));
|
|
514
541
|
}
|
|
515
542
|
function applyBudget(toolResults, workDir, sessionId, exemptIds) {
|
|
516
|
-
|
|
517
|
-
let total = spillable.reduce(
|
|
518
|
-
(sum, r) => sum + (typeof r.content === "string" ? r.content.length : 0),
|
|
519
|
-
0
|
|
520
|
-
);
|
|
543
|
+
let total = toolResults.reduce((sum, result) => sum + result.content.length, 0);
|
|
521
544
|
if (total <= MESSAGE_AGGREGATE_LIMIT) {
|
|
522
545
|
return;
|
|
523
546
|
}
|
|
524
|
-
const sorted =
|
|
525
|
-
(a, b) => asString(b.content).length - asString(a.content).length
|
|
526
|
-
);
|
|
547
|
+
const sorted = toolResults.toSorted((a, b) => b.content.length - a.content.length);
|
|
527
548
|
for (const r of sorted) {
|
|
528
549
|
if (total <= MESSAGE_AGGREGATE_LIMIT) {
|
|
529
550
|
break;
|
|
@@ -531,8 +552,8 @@ function applyBudget(toolResults, workDir, sessionId, exemptIds) {
|
|
|
531
552
|
if (exemptIds?.has(r.toolUseId)) {
|
|
532
553
|
continue;
|
|
533
554
|
}
|
|
534
|
-
const content =
|
|
535
|
-
if (content.length <=
|
|
555
|
+
const content = r.content;
|
|
556
|
+
if (content.length <= TOOL_RESULT_PREVIEW_CHARS) {
|
|
536
557
|
continue;
|
|
537
558
|
}
|
|
538
559
|
let spillPath;
|
|
@@ -543,7 +564,7 @@ function applyBudget(toolResults, workDir, sessionId, exemptIds) {
|
|
|
543
564
|
}
|
|
544
565
|
const replacement = buildSpillPreview(content, spillPath);
|
|
545
566
|
total -= content.length - replacement.length;
|
|
546
|
-
r
|
|
567
|
+
replaceToolResultContent(r, replacement);
|
|
547
568
|
}
|
|
548
569
|
}
|
|
549
570
|
function persistLargeResult(workDir, sessionId, toolUseId, content) {
|
|
@@ -959,16 +980,25 @@ var Agent = class {
|
|
|
959
980
|
const toolResults = [];
|
|
960
981
|
for (const r of results) {
|
|
961
982
|
if (r.type === "tool_result") {
|
|
962
|
-
|
|
963
|
-
if (typeof content === "string" && content.length > MAX_OUTPUT_CHARS && !exemptIds.has(r.toolId)) {
|
|
964
|
-
content = persistLargeResult(this.workDir, this.sessionId, r.toolId, content);
|
|
965
|
-
exemptIds.add(r.toolId);
|
|
966
|
-
}
|
|
967
|
-
toolResults.push({
|
|
983
|
+
const toolResult = {
|
|
968
984
|
toolUseId: r.toolId,
|
|
969
|
-
content,
|
|
985
|
+
content: r.output,
|
|
986
|
+
...r.contentBlocks?.length ? { contentBlocks: r.contentBlocks } : {},
|
|
970
987
|
isError: r.isError
|
|
971
|
-
}
|
|
988
|
+
};
|
|
989
|
+
if (toolResult.content.length > MAX_OUTPUT_CHARS && !exemptIds.has(r.toolId)) {
|
|
990
|
+
const replacement = persistLargeResult(
|
|
991
|
+
this.workDir,
|
|
992
|
+
this.sessionId,
|
|
993
|
+
r.toolId,
|
|
994
|
+
toolResult.content
|
|
995
|
+
);
|
|
996
|
+
if (replacement !== toolResult.content) {
|
|
997
|
+
replaceToolResultContent(toolResult, replacement);
|
|
998
|
+
}
|
|
999
|
+
exemptIds.add(r.toolId);
|
|
1000
|
+
}
|
|
1001
|
+
toolResults.push(toolResult);
|
|
972
1002
|
}
|
|
973
1003
|
}
|
|
974
1004
|
applyBudget(toolResults, this.workDir, this.sessionId, exemptIds);
|
|
@@ -1158,14 +1188,11 @@ var Agent = class {
|
|
|
1158
1188
|
// processToolResult handles a single executor result: records file-read
|
|
1159
1189
|
// snapshots, emits the tool_result event, and fires post-tool hooks.
|
|
1160
1190
|
async processToolResult(r, toolUses, events) {
|
|
1161
|
-
if (!r.result.isError && r.toolName === "ReadFile" &&
|
|
1191
|
+
if (!r.result.isError && r.toolName === "ReadFile" && !r.result.contentBlocks?.length) {
|
|
1162
1192
|
const tu = toolUses.find((t) => t.toolUseId === r.toolId);
|
|
1163
1193
|
const p = strArg(tu?.arguments ?? {}, "file_path");
|
|
1164
1194
|
if (p) {
|
|
1165
|
-
|
|
1166
|
-
this.recoveryState.recordFileRead(p, await readFile(p, "utf-8"));
|
|
1167
|
-
} catch {
|
|
1168
|
-
}
|
|
1195
|
+
this.recoveryState.recordFileRead(p, r.result.output);
|
|
1169
1196
|
}
|
|
1170
1197
|
}
|
|
1171
1198
|
events.push({
|
|
@@ -1173,6 +1200,7 @@ var Agent = class {
|
|
|
1173
1200
|
toolName: r.toolName,
|
|
1174
1201
|
toolId: r.toolId,
|
|
1175
1202
|
output: r.result.output,
|
|
1203
|
+
...r.result.contentBlocks?.length ? { contentBlocks: r.result.contentBlocks } : {},
|
|
1176
1204
|
isError: r.result.isError,
|
|
1177
1205
|
elapsed: r.elapsed
|
|
1178
1206
|
});
|
|
@@ -1180,7 +1208,7 @@ var Agent = class {
|
|
|
1180
1208
|
const hookResults = await this.hookEngine.fire("post_tool_use", {
|
|
1181
1209
|
event: "post_tool_use",
|
|
1182
1210
|
toolName: r.toolName,
|
|
1183
|
-
message:
|
|
1211
|
+
message: r.result.output
|
|
1184
1212
|
});
|
|
1185
1213
|
for (const hr of hookResults) {
|
|
1186
1214
|
if (hr.output) {
|
|
@@ -1238,6 +1266,9 @@ export {
|
|
|
1238
1266
|
buildPlanModeReminder,
|
|
1239
1267
|
buildPlanModeExitReminder,
|
|
1240
1268
|
buildPlanModeReentryReminder,
|
|
1269
|
+
TOOL_RESULT_PREVIEW_CHARS,
|
|
1270
|
+
toDisplayPreview,
|
|
1271
|
+
replaceToolResultContent,
|
|
1241
1272
|
isSpillReadback,
|
|
1242
1273
|
applyBudget,
|
|
1243
1274
|
persistLargeResult,
|