@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,9 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContextTooLongError
|
|
3
|
+
} from "./chunk-OO2CLOEE.js";
|
|
1
4
|
import {
|
|
2
5
|
asErrorString,
|
|
3
6
|
contentToText,
|
|
4
7
|
createChildLogger,
|
|
5
8
|
strArg
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EY7HE52Q.js";
|
|
7
10
|
|
|
8
11
|
// src/conversation/conversation.ts
|
|
9
12
|
var ConversationManager = class {
|
|
@@ -38,11 +41,18 @@ var ConversationManager = class {
|
|
|
38
41
|
toolUses: toolUses.length > 0 ? toolUses : void 0
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
|
-
addToolResultMessage(toolUseId, content, isError) {
|
|
44
|
+
addToolResultMessage(toolUseId, content, isError, contentBlocks) {
|
|
42
45
|
this.history.push({
|
|
43
46
|
role: "user",
|
|
44
47
|
content: "",
|
|
45
|
-
toolResults: [
|
|
48
|
+
toolResults: [
|
|
49
|
+
{
|
|
50
|
+
toolUseId,
|
|
51
|
+
content,
|
|
52
|
+
...contentBlocks?.length ? { contentBlocks } : {},
|
|
53
|
+
isError
|
|
54
|
+
}
|
|
55
|
+
]
|
|
46
56
|
});
|
|
47
57
|
}
|
|
48
58
|
addToolResultsMessage(results) {
|
|
@@ -108,6 +118,9 @@ ${body}
|
|
|
108
118
|
this.history.unshift({ role: "user", content: wrapped });
|
|
109
119
|
this.longTermMemoryInjected = true;
|
|
110
120
|
}
|
|
121
|
+
appendMessages(msgs) {
|
|
122
|
+
this.history.push(...msgs);
|
|
123
|
+
}
|
|
111
124
|
len() {
|
|
112
125
|
return this.history.length;
|
|
113
126
|
}
|
|
@@ -168,6 +181,137 @@ ${body}
|
|
|
168
181
|
}
|
|
169
182
|
};
|
|
170
183
|
|
|
184
|
+
// src/tools/types.ts
|
|
185
|
+
function isRecord(value) {
|
|
186
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
187
|
+
}
|
|
188
|
+
var IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
189
|
+
"image/jpeg",
|
|
190
|
+
"image/png",
|
|
191
|
+
"image/gif",
|
|
192
|
+
"image/webp"
|
|
193
|
+
]);
|
|
194
|
+
function isImageMediaType(value) {
|
|
195
|
+
return IMAGE_MEDIA_TYPES.has(value);
|
|
196
|
+
}
|
|
197
|
+
function normalizeTextBlock(value) {
|
|
198
|
+
return isRecord(value) && value.type === "text" && typeof value.text === "string" ? { type: "text", text: value.text } : null;
|
|
199
|
+
}
|
|
200
|
+
function normalizeImageBlock(value) {
|
|
201
|
+
if (!isRecord(value) || value.type !== "image" || !isRecord(value.source)) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
if (value.source.type === "url" && typeof value.source.url === "string") {
|
|
205
|
+
return { type: "image", source: { type: "url", url: value.source.url } };
|
|
206
|
+
}
|
|
207
|
+
if (value.source.type === "base64" && typeof value.source.media_type === "string" && isImageMediaType(value.source.media_type) && typeof value.source.data === "string") {
|
|
208
|
+
return {
|
|
209
|
+
type: "image",
|
|
210
|
+
source: {
|
|
211
|
+
type: "base64",
|
|
212
|
+
media_type: value.source.media_type,
|
|
213
|
+
data: value.source.data
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function normalizeDocumentBlock(value) {
|
|
220
|
+
if (value.type !== "document" || !isRecord(value.source)) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
let source = null;
|
|
224
|
+
if (value.source.type === "url" && typeof value.source.url === "string") {
|
|
225
|
+
source = { type: "url", url: value.source.url };
|
|
226
|
+
} else if (value.source.type === "base64" && value.source.media_type === "application/pdf" && typeof value.source.data === "string") {
|
|
227
|
+
source = { type: "base64", media_type: "application/pdf", data: value.source.data };
|
|
228
|
+
} else if (value.source.type === "text" && value.source.media_type === "text/plain" && typeof value.source.data === "string") {
|
|
229
|
+
source = { type: "text", media_type: "text/plain", data: value.source.data };
|
|
230
|
+
} else if (value.source.type === "content") {
|
|
231
|
+
if (typeof value.source.content === "string") {
|
|
232
|
+
source = { type: "content", content: value.source.content };
|
|
233
|
+
} else if (Array.isArray(value.source.content)) {
|
|
234
|
+
const content = [];
|
|
235
|
+
for (const raw of value.source.content) {
|
|
236
|
+
const block = normalizeTextBlock(raw) ?? normalizeImageBlock(raw);
|
|
237
|
+
if (!block) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
content.push(block);
|
|
241
|
+
}
|
|
242
|
+
source = { type: "content", content };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!source) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
type: "document",
|
|
250
|
+
source,
|
|
251
|
+
...typeof value.title === "string" || value.title === null ? { title: value.title } : {},
|
|
252
|
+
...typeof value.context === "string" || value.context === null ? { context: value.context } : {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function normalizeToolResultContentBlock(value) {
|
|
256
|
+
const text = normalizeTextBlock(value);
|
|
257
|
+
if (text) {
|
|
258
|
+
return text;
|
|
259
|
+
}
|
|
260
|
+
const image = normalizeImageBlock(value);
|
|
261
|
+
if (image) {
|
|
262
|
+
return image;
|
|
263
|
+
}
|
|
264
|
+
if (!isRecord(value)) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
if (value.type === "tool_reference" && typeof value.tool_name === "string") {
|
|
268
|
+
return { type: "tool_reference", tool_name: value.tool_name };
|
|
269
|
+
}
|
|
270
|
+
if (value.type === "search_result" && typeof value.source === "string" && typeof value.title === "string" && Array.isArray(value.content)) {
|
|
271
|
+
const content = [];
|
|
272
|
+
for (const raw of value.content) {
|
|
273
|
+
const block = normalizeTextBlock(raw);
|
|
274
|
+
if (!block) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
content.push(block);
|
|
278
|
+
}
|
|
279
|
+
return { type: "search_result", source: value.source, title: value.title, content };
|
|
280
|
+
}
|
|
281
|
+
return normalizeDocumentBlock(value);
|
|
282
|
+
}
|
|
283
|
+
function isToolResultContentBlock(value) {
|
|
284
|
+
return normalizeToolResultContentBlock(value) !== null;
|
|
285
|
+
}
|
|
286
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
287
|
+
".claude",
|
|
288
|
+
// Claude Code
|
|
289
|
+
".git",
|
|
290
|
+
// Git
|
|
291
|
+
".swifty",
|
|
292
|
+
// Swifty
|
|
293
|
+
".next",
|
|
294
|
+
// Next.js
|
|
295
|
+
".venv",
|
|
296
|
+
// Python venv
|
|
297
|
+
".mypy_cache",
|
|
298
|
+
// Python mypy
|
|
299
|
+
".tox",
|
|
300
|
+
// Python tox
|
|
301
|
+
"__pycache__",
|
|
302
|
+
// Python
|
|
303
|
+
"build",
|
|
304
|
+
// C++
|
|
305
|
+
"dist",
|
|
306
|
+
// Webpack, Vite
|
|
307
|
+
"node_modules",
|
|
308
|
+
// Node.js
|
|
309
|
+
"vendor",
|
|
310
|
+
// Go
|
|
311
|
+
"venv"
|
|
312
|
+
// Python venv
|
|
313
|
+
]);
|
|
314
|
+
|
|
171
315
|
// src/session/session.ts
|
|
172
316
|
import { randomBytes } from "crypto";
|
|
173
317
|
import {
|
|
@@ -193,6 +337,7 @@ var ContentSchema = z.union([z.string(), z.array(z.record(z.string(), z.unknown(
|
|
|
193
337
|
var ToolResultRecordSchema = z.object({
|
|
194
338
|
tool_use_id: z.string(),
|
|
195
339
|
content: ContentSchema,
|
|
340
|
+
content_blocks: z.array(z.unknown()).optional(),
|
|
196
341
|
is_error: z.boolean().optional()
|
|
197
342
|
});
|
|
198
343
|
var SessionMessageSchema = z.object({
|
|
@@ -220,6 +365,7 @@ function toolResultsToRecords(toolResults) {
|
|
|
220
365
|
return (toolResults ?? []).map((tr) => ({
|
|
221
366
|
tool_use_id: tr.toolUseId,
|
|
222
367
|
content: tr.content,
|
|
368
|
+
...tr.contentBlocks?.length ? { content_blocks: tr.contentBlocks } : {},
|
|
223
369
|
...tr.isError ? { is_error: true } : {}
|
|
224
370
|
}));
|
|
225
371
|
}
|
|
@@ -293,12 +439,30 @@ function recordsToCamelUses(recs) {
|
|
|
293
439
|
arguments: tu.arguments
|
|
294
440
|
}));
|
|
295
441
|
}
|
|
442
|
+
function validContentBlocks(value) {
|
|
443
|
+
if (!value) {
|
|
444
|
+
return void 0;
|
|
445
|
+
}
|
|
446
|
+
const blocks = [];
|
|
447
|
+
for (const raw of value) {
|
|
448
|
+
const block = normalizeToolResultContentBlock(raw);
|
|
449
|
+
if (block) {
|
|
450
|
+
blocks.push(block);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return blocks.length > 0 ? blocks : void 0;
|
|
454
|
+
}
|
|
296
455
|
function recordsToCamelResults(recs) {
|
|
297
|
-
return recs?.map((tr) =>
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
456
|
+
return recs?.map((tr) => {
|
|
457
|
+
const legacyBlocks = Array.isArray(tr.content) ? validContentBlocks(tr.content) : void 0;
|
|
458
|
+
const contentBlocks = validContentBlocks(tr.content_blocks) ?? legacyBlocks;
|
|
459
|
+
return {
|
|
460
|
+
toolUseId: tr.tool_use_id,
|
|
461
|
+
content: typeof tr.content === "string" ? tr.content : contentToText(tr.content),
|
|
462
|
+
...contentBlocks ? { contentBlocks } : {},
|
|
463
|
+
isError: tr.is_error ?? false
|
|
464
|
+
};
|
|
465
|
+
});
|
|
302
466
|
}
|
|
303
467
|
function rebuildFromSession(saved) {
|
|
304
468
|
let lastBoundary = -1;
|
|
@@ -495,6 +659,59 @@ function contentChars(content) {
|
|
|
495
659
|
}
|
|
496
660
|
return chars;
|
|
497
661
|
}
|
|
662
|
+
function toolResultBlocksChars(blocks) {
|
|
663
|
+
let textChars = 0;
|
|
664
|
+
let richChars = 0;
|
|
665
|
+
for (const block of blocks) {
|
|
666
|
+
switch (block.type) {
|
|
667
|
+
case "text": {
|
|
668
|
+
textChars += block.text.length;
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
case "image": {
|
|
672
|
+
richChars += IMAGE_CHAR_EQUIV;
|
|
673
|
+
break;
|
|
674
|
+
}
|
|
675
|
+
case "tool_reference": {
|
|
676
|
+
richChars += block.tool_name.length;
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
case "search_result": {
|
|
680
|
+
richChars += block.source.length + block.title.length;
|
|
681
|
+
richChars += block.content.reduce((sum, content) => sum + content.text.length, 0);
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
case "document": {
|
|
685
|
+
switch (block.source.type) {
|
|
686
|
+
case "base64": {
|
|
687
|
+
richChars += IMAGE_CHAR_EQUIV;
|
|
688
|
+
break;
|
|
689
|
+
}
|
|
690
|
+
case "url": {
|
|
691
|
+
richChars += block.source.url.length;
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
case "text": {
|
|
695
|
+
richChars += block.source.data.length;
|
|
696
|
+
break;
|
|
697
|
+
}
|
|
698
|
+
case "content": {
|
|
699
|
+
if (typeof block.source.content === "string") {
|
|
700
|
+
richChars += block.source.content.length;
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
for (const content of block.source.content) {
|
|
704
|
+
richChars += content.type === "text" ? content.text.length : IMAGE_CHAR_EQUIV;
|
|
705
|
+
}
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
break;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return { textChars, richChars };
|
|
714
|
+
}
|
|
498
715
|
function estimateMessages(messages) {
|
|
499
716
|
let totalChars = 0;
|
|
500
717
|
for (const msg of messages) {
|
|
@@ -504,7 +721,12 @@ function estimateMessages(messages) {
|
|
|
504
721
|
}
|
|
505
722
|
if (msg.toolResults) {
|
|
506
723
|
for (const tr of msg.toolResults) {
|
|
507
|
-
|
|
724
|
+
if (tr.contentBlocks?.length) {
|
|
725
|
+
const blockChars = toolResultBlocksChars(tr.contentBlocks);
|
|
726
|
+
totalChars += Math.max(tr.content.length, blockChars.textChars) + blockChars.richChars;
|
|
727
|
+
} else {
|
|
728
|
+
totalChars += tr.content.length;
|
|
729
|
+
}
|
|
508
730
|
}
|
|
509
731
|
}
|
|
510
732
|
if (msg.thinkingBlocks) {
|
|
@@ -743,10 +965,49 @@ function serializePrefixText(messages) {
|
|
|
743
965
|
if (m.toolUses) {
|
|
744
966
|
text += `
|
|
745
967
|
[tools: ${m.toolUses.map((t) => t.toolName).join(", ")}]`;
|
|
968
|
+
}
|
|
969
|
+
if (m.toolResults) {
|
|
970
|
+
text += `
|
|
971
|
+
[tool results]
|
|
972
|
+
${m.toolResults.map((result) => result.content).join("\n")}`;
|
|
746
973
|
}
|
|
747
974
|
return text;
|
|
748
975
|
}).join("\n\n");
|
|
749
976
|
}
|
|
977
|
+
function formatCompactSummary(raw) {
|
|
978
|
+
const summaryMatch = /<summary>([\s\S]*?)<\/summary>/.exec(raw);
|
|
979
|
+
if (summaryMatch) {
|
|
980
|
+
return summaryMatch[1].trim();
|
|
981
|
+
}
|
|
982
|
+
const analysisMatch = /<analysis>[\s\S]*?<\/analysis>/.exec(raw);
|
|
983
|
+
if (analysisMatch) {
|
|
984
|
+
return raw.replace(analysisMatch[0], "").trim();
|
|
985
|
+
}
|
|
986
|
+
return raw.trim();
|
|
987
|
+
}
|
|
988
|
+
async function callSummaryWithCacheSharing(client, messages, toolSchemas) {
|
|
989
|
+
let lastAssistant = -1;
|
|
990
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
991
|
+
if (messages[i].role === "assistant") {
|
|
992
|
+
lastAssistant = i;
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (lastAssistant < 0) {
|
|
997
|
+
throw new Error("no assistant message found for cache-sharing compact");
|
|
998
|
+
}
|
|
999
|
+
const summaryConv = new ConversationManager();
|
|
1000
|
+
summaryConv.appendMessages(messages.slice(0, lastAssistant + 1));
|
|
1001
|
+
summaryConv.addUserMessage(SUMMARY_SYSTEM_PROMPT);
|
|
1002
|
+
let summaryText = "";
|
|
1003
|
+
const stream = client.stream(summaryConv, toolSchemas);
|
|
1004
|
+
for await (const event of stream) {
|
|
1005
|
+
if (event.type === "text_delta") {
|
|
1006
|
+
summaryText += event.text;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return formatCompactSummary(summaryText);
|
|
1010
|
+
}
|
|
750
1011
|
async function requestSummaryWithPTLRetry(client, prefix, toolSchemas) {
|
|
751
1012
|
let currentPrefix = prefix;
|
|
752
1013
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -761,8 +1022,7 @@ async function requestSummaryWithPTLRetry(client, prefix, toolSchemas) {
|
|
|
761
1022
|
summaryText += event.text;
|
|
762
1023
|
}
|
|
763
1024
|
}
|
|
764
|
-
|
|
765
|
-
return match ? match[1].trim() : summaryText;
|
|
1025
|
+
return formatCompactSummary(summaryText);
|
|
766
1026
|
} catch (e) {
|
|
767
1027
|
const msg = e instanceof Error ? e.message.toLowerCase() : "";
|
|
768
1028
|
const isPTL = msg.includes("prompt") && msg.includes("long") || msg.includes("too many") || msg.includes("context_length");
|
|
@@ -789,7 +1049,15 @@ async function doCompact(conv, client, recoveryState, toolSchemaNames, toolSchem
|
|
|
789
1049
|
}
|
|
790
1050
|
const toSummarize = estimationMessages.slice(0, keepStart);
|
|
791
1051
|
const toKeep = estimationMessages.slice(keepStart);
|
|
792
|
-
|
|
1052
|
+
let summary;
|
|
1053
|
+
try {
|
|
1054
|
+
summary = await callSummaryWithCacheSharing(client, estimationMessages, toolSchemas);
|
|
1055
|
+
} catch (err) {
|
|
1056
|
+
if (!(err instanceof ContextTooLongError)) {
|
|
1057
|
+
throw err;
|
|
1058
|
+
}
|
|
1059
|
+
summary = await requestSummaryWithPTLRetry(client, toSummarize, toolSchemas);
|
|
1060
|
+
}
|
|
793
1061
|
const recoveryAttachment = recoveryState ? recoveryState.buildRecoveryAttachment(toolSchemaNames) : "";
|
|
794
1062
|
let summaryContent = "This session continues from a previous conversation, which has been compressed due to context limitations. Here is a summary of the earlier messages:\n\n" + summary;
|
|
795
1063
|
if (toKeep.length > 0) {
|
|
@@ -827,6 +1095,9 @@ ${recoveryAttachment}`;
|
|
|
827
1095
|
|
|
828
1096
|
export {
|
|
829
1097
|
ConversationManager,
|
|
1098
|
+
normalizeToolResultContentBlock,
|
|
1099
|
+
isToolResultContentBlock,
|
|
1100
|
+
SKIP_DIRS,
|
|
830
1101
|
COMPACT_BOUNDARY,
|
|
831
1102
|
toolUsesToRecords,
|
|
832
1103
|
toolResultsToRecords,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createChildLogger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EY7HE52Q.js";
|
|
4
4
|
|
|
5
5
|
// src/config/config.ts
|
|
6
6
|
import { existsSync, readFileSync } from "fs";
|
|
@@ -75,7 +75,7 @@ async function getContextWindowAsync(p, fetcher) {
|
|
|
75
75
|
let fetched = fetchedWindowCache.get(key);
|
|
76
76
|
if (fetched === void 0) {
|
|
77
77
|
try {
|
|
78
|
-
const fn = fetcher ?? (await import("./anthropic-
|
|
78
|
+
const fn = fetcher ?? (await import("./anthropic-RYPJDHQM.js")).fetchModelContextWindow;
|
|
79
79
|
fetched = await fn(p);
|
|
80
80
|
} catch (err) {
|
|
81
81
|
log.error({ err }, "config operation failed");
|
|
@@ -230,7 +230,6 @@ function errSerializer(err) {
|
|
|
230
230
|
|
|
231
231
|
// src/utils/index.ts
|
|
232
232
|
var log = createChildLogger({ module: "utils" });
|
|
233
|
-
var DANGEROUSLY_JSON = "dangerouslyJson";
|
|
234
233
|
function contentToText(content) {
|
|
235
234
|
if (typeof content === "string") {
|
|
236
235
|
return content;
|
|
@@ -238,12 +237,21 @@ function contentToText(content) {
|
|
|
238
237
|
const parts = [];
|
|
239
238
|
for (const block of content) {
|
|
240
239
|
if (block.type === "text" && typeof block.text === "string") {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const b = block;
|
|
245
|
-
const mediaType = b.source.type === "base64" ? b.source.media_type : "image";
|
|
240
|
+
parts.push(block.text);
|
|
241
|
+
} else if (block.type === "image" && isRecord(block.source)) {
|
|
242
|
+
const mediaType = block.source.type === "base64" && typeof block.source.media_type === "string" ? block.source.media_type : "image";
|
|
246
243
|
parts.push(`[Image: ${mediaType}]`);
|
|
244
|
+
} else if (block.type === "tool_reference" && typeof block.tool_name === "string") {
|
|
245
|
+
parts.push(`[Tool reference: ${block.tool_name}]`);
|
|
246
|
+
} else if (block.type === "search_result") {
|
|
247
|
+
const title = typeof block.title === "string" ? block.title : "search result";
|
|
248
|
+
const source = typeof block.source === "string" ? ` (${block.source})` : "";
|
|
249
|
+
const nested = Array.isArray(block.content) ? contentToText(block.content.filter(isRecord)) : "";
|
|
250
|
+
parts.push(`${title}${source}${nested ? `
|
|
251
|
+
${nested}` : ""}`);
|
|
252
|
+
} else if (block.type === "document") {
|
|
253
|
+
const title = typeof block.title === "string" ? block.title : "document";
|
|
254
|
+
parts.push(`[Document: ${title}]`);
|
|
247
255
|
}
|
|
248
256
|
}
|
|
249
257
|
return parts.join("\n");
|
|
@@ -359,7 +367,6 @@ export {
|
|
|
359
367
|
closeLogger,
|
|
360
368
|
logger,
|
|
361
369
|
createChildLogger,
|
|
362
|
-
DANGEROUSLY_JSON,
|
|
363
370
|
contentToText,
|
|
364
371
|
isRecord,
|
|
365
372
|
asRecord,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mcpCallPermissionContent
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PZ42NAFA.js";
|
|
4
4
|
import {
|
|
5
5
|
createChildLogger,
|
|
6
6
|
strArg
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-EY7HE52Q.js";
|
|
8
8
|
import {
|
|
9
9
|
MCP_CALL_TOOL_NAME
|
|
10
10
|
} from "./chunk-GHF2PSEW.js";
|
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
// src/llm/errors.ts
|
|
2
|
+
var LLMError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "LLMError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var AuthenticationError = class extends LLMError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "AuthenticationError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var RateLimitError = class extends LLMError {
|
|
15
|
+
retryAfter;
|
|
16
|
+
constructor(message, retryAfter) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "RateLimitError";
|
|
19
|
+
this.retryAfter = retryAfter;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var NetworkError = class extends LLMError {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "NetworkError";
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var ContextTooLongError = class extends LLMError {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "ContextTooLongError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
1
35
|
// src/conversation/pairing.ts
|
|
2
36
|
var INTERRUPTED_TOOL_RESULT = "Tool execution was interrupted. The tool may or may not have completed; verify before relying on its effects.";
|
|
3
37
|
var REJECTED_TOOL_RESULT = "The user rejected this tool use. Nothing was changed (for file edits, the new content was NOT written).";
|
|
@@ -42,47 +76,13 @@ function ensureToolPairing(messages) {
|
|
|
42
76
|
return out;
|
|
43
77
|
}
|
|
44
78
|
|
|
45
|
-
// src/llm/errors.ts
|
|
46
|
-
var LLMError = class extends Error {
|
|
47
|
-
constructor(message) {
|
|
48
|
-
super(message);
|
|
49
|
-
this.name = "LLMError";
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var AuthenticationError = class extends LLMError {
|
|
53
|
-
constructor(message) {
|
|
54
|
-
super(message);
|
|
55
|
-
this.name = "AuthenticationError";
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var RateLimitError = class extends LLMError {
|
|
59
|
-
retryAfter;
|
|
60
|
-
constructor(message, retryAfter) {
|
|
61
|
-
super(message);
|
|
62
|
-
this.name = "RateLimitError";
|
|
63
|
-
this.retryAfter = retryAfter;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
var NetworkError = class extends LLMError {
|
|
67
|
-
constructor(message) {
|
|
68
|
-
super(message);
|
|
69
|
-
this.name = "NetworkError";
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var ContextTooLongError = class extends LLMError {
|
|
73
|
-
constructor(message) {
|
|
74
|
-
super(message);
|
|
75
|
-
this.name = "ContextTooLongError";
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
79
|
export {
|
|
80
|
-
INTERRUPTED_TOOL_RESULT,
|
|
81
|
-
REJECTED_TOOL_RESULT,
|
|
82
|
-
ensureToolPairing,
|
|
83
80
|
LLMError,
|
|
84
81
|
AuthenticationError,
|
|
85
82
|
RateLimitError,
|
|
86
83
|
NetworkError,
|
|
87
|
-
ContextTooLongError
|
|
84
|
+
ContextTooLongError,
|
|
85
|
+
INTERRUPTED_TOOL_RESULT,
|
|
86
|
+
REJECTED_TOOL_RESULT,
|
|
87
|
+
ensureToolPairing
|
|
88
88
|
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
asRecord,
|
|
4
4
|
createChildLogger,
|
|
5
5
|
strArg
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-EY7HE52Q.js";
|
|
7
7
|
import {
|
|
8
8
|
MCP_CALL_TOOL_NAME
|
|
9
9
|
} from "./chunk-GHF2PSEW.js";
|
|
@@ -56,8 +56,7 @@ var MCPToolWrapper = class {
|
|
|
56
56
|
}
|
|
57
57
|
async execute(_ctx, args) {
|
|
58
58
|
try {
|
|
59
|
-
|
|
60
|
-
return { output, isError };
|
|
59
|
+
return await this.client.callTool(this.originalName, args);
|
|
61
60
|
} catch (err) {
|
|
62
61
|
log.error({ err }, "mcp operation failed");
|
|
63
62
|
return {
|