@yukino.js/yukino 0.0.5 → 0.0.7

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.
Files changed (54) hide show
  1. package/README.md +35 -30
  2. package/dist/{acp-LOU6R4C7.js → acp-76S2XII3.js} +1 -1
  3. package/dist/anthropic-WK6EYMUE.js +4 -0
  4. package/dist/chunk-3OULXPVI.js +5 -0
  5. package/dist/chunk-7PPWFSIC.js +4 -0
  6. package/dist/chunk-7ZBAF7M4.js +4 -0
  7. package/dist/{chunk-BPA7URET.js → chunk-HWDSXNX4.js} +2 -2
  8. package/dist/{chunk-GYBJR2RB.js → chunk-IW5L5276.js} +2 -2
  9. package/dist/chunk-NG62ISUV.js +61 -0
  10. package/dist/chunk-P6DHMU7R.js +4 -0
  11. package/dist/{chunk-YVLW4WBA.js → chunk-QQZCYWYI.js} +20 -20
  12. package/dist/chunk-QRO6H32L.js +1031 -0
  13. package/dist/lib/{anthropic-UC7XIWCM.js → anthropic-CDPTNR5L.js} +2 -6
  14. package/dist/lib/{chunk-DXUJGZ5F.js → chunk-6NYUYSER.js} +3 -3
  15. package/dist/lib/{chunk-GAWWN3TY.js → chunk-EO23VPDZ.js} +416 -39
  16. package/dist/lib/chunk-HE4RUUZP.js +1342 -0
  17. package/dist/lib/{chunk-64Z3SMSG.js → chunk-PEV5NGQ2.js} +84 -44
  18. package/dist/lib/{chunk-WDO5MWH2.js → chunk-TKCJSTWI.js} +1 -1
  19. package/dist/lib/index.d.ts +113 -119
  20. package/dist/lib/index.js +6305 -1810
  21. package/dist/lib/{openai-OL5HXQUU.js → openai-TEFKPV7T.js} +2 -4
  22. package/dist/lib/{providers-N35WJDJM.js → providers-2X5JB2JX.js} +1 -1
  23. package/dist/lib/{seatbelt-G5Z5QEDD.js → seatbelt-VE3I3EGH.js} +1 -1
  24. package/dist/main.js +198 -198
  25. package/dist/{openai-NIBMRDVB.js → openai-RYXW7AKZ.js} +15 -15
  26. package/dist/{providers-TG3LGHNS.js → providers-YG2HYIG6.js} +1 -1
  27. package/dist/{seatbelt-IOLIYZZX.js → seatbelt-3YN3GMQO.js} +1 -1
  28. package/dist/server-66HLMSUR.js +4 -0
  29. package/package.json +8 -24
  30. package/dist/agent-5NW5ZV5P.js +0 -4
  31. package/dist/anthropic-UXFSBFXM.js +0 -4
  32. package/dist/chunk-2HUCPWD6.js +0 -29
  33. package/dist/chunk-3EQYWNP6.js +0 -4
  34. package/dist/chunk-3SPUH3TD.js +0 -164
  35. package/dist/chunk-5HF4GLFR.js +0 -865
  36. package/dist/chunk-HBXZ6MB4.js +0 -4
  37. package/dist/chunk-MQAQBW7F.js +0 -35
  38. package/dist/chunk-OFC2GD5K.js +0 -4
  39. package/dist/chunk-SDXAS44V.js +0 -4
  40. package/dist/chunk-TJVN4NL5.js +0 -5
  41. package/dist/chunk-VM26JJ6N.js +0 -4
  42. package/dist/chunk-WNHTKUKK.js +0 -4
  43. package/dist/chunk-ZPYQCXWT.js +0 -5
  44. package/dist/lib/agent-UGEA6EVB.js +0 -16
  45. package/dist/lib/chunk-65EUCQOF.js +0 -259
  46. package/dist/lib/chunk-F2YJG72O.js +0 -150
  47. package/dist/lib/chunk-NIJXTKNM.js +0 -3628
  48. package/dist/lib/chunk-OCTB6YMC.js +0 -625
  49. package/dist/lib/chunk-R3NJ2EET.js +0 -540
  50. package/dist/lib/chunk-UKINFW65.js +0 -652
  51. package/dist/lib/chunk-V2EYBIAU.js +0 -323
  52. package/dist/lib/permissions-EAKP6IZ3.js +0 -23
  53. package/dist/permissions-5EQWZS7O.js +0 -4
  54. package/dist/server-7ENYPCYC.js +0 -4
@@ -4,12 +4,8 @@ import {
4
4
  markLastUserTailForCache,
5
5
  markToolsForCache,
6
6
  needsToolSearchBeta
7
- } from "./chunk-GAWWN3TY.js";
8
- import "./chunk-F2YJG72O.js";
9
- import "./chunk-65EUCQOF.js";
10
- import "./chunk-R3NJ2EET.js";
11
- import "./chunk-V2EYBIAU.js";
12
- import "./chunk-UKINFW65.js";
7
+ } from "./chunk-EO23VPDZ.js";
8
+ import "./chunk-HE4RUUZP.js";
13
9
  import "./chunk-MLKGABMK.js";
14
10
  export {
15
11
  AnthropicClient,
@@ -7,7 +7,7 @@ var seatbelt_exports = {};
7
7
  __export(seatbelt_exports, {
8
8
  SeatbeltSandbox: () => SeatbeltSandbox
9
9
  });
10
- import { existsSync, realpathSync, statSync } from "fs";
10
+ import { existsSync, realpathSync } from "fs";
11
11
  var SANDBOX_EXEC_PATH = "/usr/bin/sandbox-exec";
12
12
  var SeatbeltSandbox = class {
13
13
  implementation = "seatbelt";
@@ -44,8 +44,8 @@ function buildProfile(config) {
44
44
  }
45
45
  for (const path of config.denyWrite) {
46
46
  for (const variant of pathVariants(path)) {
47
- const matcher = existsSync(variant) && statSync(variant).isDirectory() ? "subpath" : "literal";
48
- lines.push(`(deny file-write* (${matcher} "${variant}"))`);
47
+ lines.push(`(deny file-write* (literal "${variant}"))`);
48
+ lines.push(`(deny file-write* (subpath "${variant}"))`);
49
49
  }
50
50
  }
51
51
  if (config.networkEnabled) {
@@ -1,13 +1,3 @@
1
- import {
2
- normalizeToolResultContentBlock
3
- } from "./chunk-F2YJG72O.js";
4
- import {
5
- MCP_TOOL_PREFIX,
6
- isMcpToolLike
7
- } from "./chunk-65EUCQOF.js";
8
- import {
9
- resolveAPIKey
10
- } from "./chunk-R3NJ2EET.js";
11
1
  import {
12
2
  AuthenticationError,
13
3
  ContextTooLongError,
@@ -15,25 +5,24 @@ import {
15
5
  MIN_THINKING_ANSWER_TOKENS,
16
6
  NetworkError,
17
7
  RateLimitError,
8
+ asErrorString,
9
+ asRecord,
10
+ asString,
18
11
  clampThinkingLevel,
19
12
  containsContextLengthError,
13
+ contentToText,
14
+ createChildLogger,
20
15
  ensureToolPairing,
21
16
  getMaxOutputTokens,
22
17
  getSupportedThinkingLevels,
23
18
  getThinkingLevel,
19
+ parseToolArguments,
20
+ resolveAPIKey,
21
+ strArg,
24
22
  thinkingBudgetForLevel,
25
23
  toAnthropicThinkingEffort,
26
24
  toReasoningEffort
27
- } from "./chunk-V2EYBIAU.js";
28
- import {
29
- asErrorString,
30
- asRecord,
31
- asString,
32
- contentToText,
33
- createChildLogger,
34
- isRecord,
35
- strArg
36
- } from "./chunk-UKINFW65.js";
25
+ } from "./chunk-HE4RUUZP.js";
37
26
  import {
38
27
  __export
39
28
  } from "./chunk-MLKGABMK.js";
@@ -62,6 +51,246 @@ __export(strategy_exports, {
62
51
  isOfficialAnthropicEndpoint: () => isOfficialAnthropicEndpoint,
63
52
  measureSchemaChars: () => measureSchemaChars
64
53
  });
54
+
55
+ // src/mcp/tool-wrapper.ts
56
+ var tool_wrapper_exports = {};
57
+ __export(tool_wrapper_exports, {
58
+ MCPToolWrapper: () => MCPToolWrapper,
59
+ MCP_NAME_SEP: () => MCP_NAME_SEP,
60
+ MCP_TOOL_PREFIX: () => MCP_TOOL_PREFIX,
61
+ buildMcpToolName: () => buildMcpToolName,
62
+ mcpToolNamePrefix: () => mcpToolNamePrefix,
63
+ sanitizeSegment: () => sanitizeSegment
64
+ });
65
+ var log = createChildLogger({ module: "mcp" });
66
+ var MCP_TOOL_PREFIX = "mcp__";
67
+ var MCP_NAME_SEP = "__";
68
+ function sanitizeSegment(s) {
69
+ return s.replace(/[^a-zA-Z0-9_]/g, "_");
70
+ }
71
+ function mcpToolNamePrefix(serverName) {
72
+ return MCP_TOOL_PREFIX + sanitizeSegment(serverName) + MCP_NAME_SEP;
73
+ }
74
+ function buildMcpToolName(serverName, toolName) {
75
+ return mcpToolNamePrefix(serverName) + sanitizeSegment(toolName);
76
+ }
77
+ var MCPToolWrapper = class {
78
+ name;
79
+ description;
80
+ category = "command";
81
+ // MCP tools are lazily loaded by default to avoid cramming all schemas into the prompt
82
+ deferred = true;
83
+ mcpServerName;
84
+ client;
85
+ originalName;
86
+ inputSchema;
87
+ constructor(client, serverName, tool) {
88
+ this.name = buildMcpToolName(serverName, tool.name);
89
+ this.description = tool.description;
90
+ this.originalName = tool.name;
91
+ this.client = client;
92
+ this.inputSchema = tool.inputSchema;
93
+ this.mcpServerName = serverName;
94
+ }
95
+ /** Original JSON schema. McpCall's argument coercion walks it layer by layer. */
96
+ mcpInputSchema() {
97
+ return this.inputSchema ?? {};
98
+ }
99
+ /** In eager mode the defer flag is cleared so MCP tools go straight into tools[]. */
100
+ setDeferLoading(on) {
101
+ this.deferred = on;
102
+ }
103
+ schema() {
104
+ return {
105
+ name: this.name,
106
+ description: this.description,
107
+ input_schema: this.inputSchema
108
+ };
109
+ }
110
+ async execute(ctx, args) {
111
+ try {
112
+ return await this.client.callTool(
113
+ this.originalName,
114
+ args,
115
+ ctx.abortSignal
116
+ );
117
+ } catch (err) {
118
+ log.error({ err }, "mcp operation failed");
119
+ return {
120
+ output: `MCP tool error: ${asErrorString(err)}`,
121
+ isError: true
122
+ };
123
+ }
124
+ }
125
+ };
126
+
127
+ // src/tools/mcp-call.ts
128
+ var mcp_call_exports = {};
129
+ __export(mcp_call_exports, {
130
+ McpCallTool: () => McpCallTool,
131
+ coerceBySchema: () => coerceBySchema,
132
+ isMcpToolLike: () => isMcpToolLike,
133
+ mcpCallPermissionContent: () => mcpCallPermissionContent
134
+ });
135
+ function coerceScalar(value, want) {
136
+ if (want === "string" && typeof value === "number" && Number.isFinite(value)) {
137
+ return String(value);
138
+ }
139
+ if ((want === "integer" || want === "number") && typeof value === "string") {
140
+ const text = value.trim();
141
+ if (text === "") {
142
+ return value;
143
+ }
144
+ const shape = want === "integer" ? /^[+-]?\d+$/ : /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
145
+ if (!shape.test(text)) {
146
+ return value;
147
+ }
148
+ const parsed = want === "integer" ? Number.parseInt(text, 10) : Number.parseFloat(text);
149
+ return Number.isFinite(parsed) ? parsed : value;
150
+ }
151
+ if (want === "boolean" && typeof value === "string") {
152
+ const low = value.trim().toLowerCase();
153
+ if (low === "true") {
154
+ return true;
155
+ }
156
+ if (low === "false") {
157
+ return false;
158
+ }
159
+ }
160
+ return value;
161
+ }
162
+ function coerceBySchema(value, schema) {
163
+ if (typeof schema !== "object" || schema === null) {
164
+ return value;
165
+ }
166
+ const schemaObj = asRecord(schema);
167
+ const want = strArg(schemaObj, "type", "");
168
+ if (want === "object" && typeof value === "object" && value !== null && !Array.isArray(value)) {
169
+ const props = asRecord(schemaObj.properties ?? {});
170
+ const out = {};
171
+ for (const [key, item] of Object.entries(value)) {
172
+ out[key] = key in props ? coerceBySchema(item, props[key]) : item;
173
+ }
174
+ return out;
175
+ }
176
+ if (want === "array") {
177
+ const itemSchema = schemaObj.items ?? {};
178
+ let working = value;
179
+ if (typeof working === "object" && working !== null && !Array.isArray(working)) {
180
+ const entries = Object.values(working);
181
+ if (entries.length === 1 && Array.isArray(entries[0])) {
182
+ working = entries[0];
183
+ }
184
+ } else if (typeof working === "string") {
185
+ working = working.split(",").map((p) => p.trim()).filter((p) => p !== "");
186
+ }
187
+ if (Array.isArray(working)) {
188
+ return working.map((item) => coerceBySchema(item, itemSchema));
189
+ }
190
+ return working;
191
+ }
192
+ if (want !== "") {
193
+ return coerceScalar(value, want);
194
+ }
195
+ return value;
196
+ }
197
+ function mcpCallPermissionContent(server, tool) {
198
+ if (tool.startsWith(MCP_TOOL_PREFIX)) {
199
+ const rest = tool.slice(MCP_TOOL_PREFIX.length);
200
+ const idx = rest.indexOf(MCP_NAME_SEP);
201
+ if (idx >= 0) {
202
+ return sanitizeSegment(rest.slice(0, idx)) + MCP_NAME_SEP + sanitizeSegment(rest.slice(idx + MCP_NAME_SEP.length));
203
+ }
204
+ }
205
+ return sanitizeSegment(server) + MCP_NAME_SEP + sanitizeSegment(tool);
206
+ }
207
+ function isMcpToolLike(tool) {
208
+ return "mcpInputSchema" in tool && typeof tool.mcpInputSchema === "function";
209
+ }
210
+ var McpCallTool = class {
211
+ constructor(registry) {
212
+ this.registry = registry;
213
+ }
214
+ registry;
215
+ name = "McpCall";
216
+ description = "Invoke a tool on a connected MCP server. Call ToolSearch first to load the tool's schema, then pass its arguments here exactly as that schema requires, using the same JSON types.";
217
+ category = "command";
218
+ // This tool must stay in tools[] itself, otherwise the model has no entry point
219
+ deferred = false;
220
+ schema() {
221
+ return {
222
+ name: this.name,
223
+ description: this.description,
224
+ input_schema: {
225
+ type: "object",
226
+ properties: {
227
+ server: {
228
+ type: "string",
229
+ description: "MCP server name, e.g. 'linear'."
230
+ },
231
+ tool: {
232
+ type: "string",
233
+ description: "Full tool name as returned by ToolSearch, e.g. 'mcp__linear__create_issue'."
234
+ },
235
+ arguments: {
236
+ type: "object",
237
+ description: "The target tool's arguments. Must match that tool's input_schema exactly, including JSON types: bare numbers for integer fields, bare true/false for boolean fields, quoted strings for string fields, and plain JSON arrays for array fields."
238
+ }
239
+ },
240
+ required: ["server", "tool", "arguments"]
241
+ }
242
+ };
243
+ }
244
+ resolveTarget(args) {
245
+ const server = strArg(args, "server");
246
+ const name = strArg(args, "tool");
247
+ if (!server || !name) {
248
+ return void 0;
249
+ }
250
+ const fullName = name.startsWith(MCP_TOOL_PREFIX) ? name : buildMcpToolName(server, name);
251
+ const target = this.registry.get(fullName);
252
+ return target && isMcpToolLike(target) && sanitizeSegment(target.mcpServerName) === sanitizeSegment(server) ? target : void 0;
253
+ }
254
+ availableNames() {
255
+ return this.registry.listTools().filter((t) => t.name.startsWith(MCP_TOOL_PREFIX)).map((t) => t.name).sort();
256
+ }
257
+ async execute(ctx, args) {
258
+ const server = strArg(args, "server", "");
259
+ const tool = strArg(args, "tool", "");
260
+ if (tool === "") {
261
+ return { output: "McpCall requires a 'tool' name", isError: true };
262
+ }
263
+ const target = this.resolveTarget(args);
264
+ if (!target) {
265
+ const names = this.availableNames();
266
+ const hint = names.length > 0 ? names.join(", ") : "(none connected)";
267
+ return {
268
+ output: `Unknown MCP tool '${tool}' on server '${server}'. Available tools: ${hint}`,
269
+ isError: true
270
+ };
271
+ }
272
+ if (typeof args.arguments !== "object" || args.arguments === null || Array.isArray(args.arguments)) {
273
+ return {
274
+ output: "McpCall requires an 'arguments' object matching the target schema",
275
+ isError: true
276
+ };
277
+ }
278
+ let inner = asRecord(args.arguments);
279
+ if (isMcpToolLike(target)) {
280
+ const schema = target.mcpInputSchema();
281
+ if (Object.keys(schema).length > 0) {
282
+ const fixed = coerceBySchema(inner, schema);
283
+ if (typeof fixed === "object" && fixed !== null && !Array.isArray(fixed)) {
284
+ inner = asRecord(fixed);
285
+ }
286
+ }
287
+ }
288
+ ctx.abortSignal?.throwIfAborted();
289
+ return target.execute(ctx, inner);
290
+ }
291
+ };
292
+
293
+ // src/mcp/strategy.ts
65
294
  var DEFAULT_EAGER_THRESHOLD_PERCENT = 10;
66
295
  var CHARS_PER_TOKEN = 2.5;
67
296
  var NATIVE_TOOL_USE_BETA = "advanced-tool-use-2025-11-20";
@@ -83,7 +312,7 @@ function estimateSchemaTokens(schemaChars) {
83
312
  function decideMode(baseUrl, protocol, contextWindow, mcpSchemaChars, thresholdPercent = DEFAULT_EAGER_THRESHOLD_PERCENT) {
84
313
  const override = (process.env[ENV_OVERRIDE] ?? "").trim().toLowerCase();
85
314
  if (override === "eager" || override === "native" || override === "dispatch") {
86
- return override;
315
+ return override === "native" && protocol !== "anthropic" ? "dispatch" : override;
87
316
  }
88
317
  if (mcpSchemaChars <= 0) {
89
318
  return "eager";
@@ -131,6 +360,147 @@ function decideAndApply(registry, baseUrl, protocol, contextWindow) {
131
360
  return mode;
132
361
  }
133
362
 
363
+ // src/tools/types.ts
364
+ var types_exports = {};
365
+ __export(types_exports, {
366
+ SKIP_DIRS: () => SKIP_DIRS,
367
+ isToolResultContentBlock: () => isToolResultContentBlock,
368
+ normalizeToolResultContentBlock: () => normalizeToolResultContentBlock
369
+ });
370
+ function isRecord(value) {
371
+ return typeof value === "object" && value !== null && !Array.isArray(value);
372
+ }
373
+ var IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
374
+ "image/jpeg",
375
+ "image/png",
376
+ "image/gif",
377
+ "image/webp"
378
+ ]);
379
+ function isImageMediaType(value) {
380
+ return IMAGE_MEDIA_TYPES.has(value);
381
+ }
382
+ function normalizeTextBlock(value) {
383
+ return isRecord(value) && value.type === "text" && typeof value.text === "string" ? { type: "text", text: value.text } : null;
384
+ }
385
+ function normalizeImageBlock(value) {
386
+ if (!isRecord(value) || value.type !== "image" || !isRecord(value.source)) {
387
+ return null;
388
+ }
389
+ if (value.source.type === "url" && typeof value.source.url === "string") {
390
+ return { type: "image", source: { type: "url", url: value.source.url } };
391
+ }
392
+ if (value.source.type === "base64" && typeof value.source.media_type === "string" && isImageMediaType(value.source.media_type) && typeof value.source.data === "string") {
393
+ return {
394
+ type: "image",
395
+ source: {
396
+ type: "base64",
397
+ media_type: value.source.media_type,
398
+ data: value.source.data
399
+ }
400
+ };
401
+ }
402
+ return null;
403
+ }
404
+ function normalizeDocumentBlock(value) {
405
+ if (value.type !== "document" || !isRecord(value.source)) {
406
+ return null;
407
+ }
408
+ let source = null;
409
+ if (value.source.type === "url" && typeof value.source.url === "string") {
410
+ source = { type: "url", url: value.source.url };
411
+ } else if (value.source.type === "base64" && value.source.media_type === "application/pdf" && typeof value.source.data === "string") {
412
+ source = {
413
+ type: "base64",
414
+ media_type: "application/pdf",
415
+ data: value.source.data
416
+ };
417
+ } else if (value.source.type === "text" && value.source.media_type === "text/plain" && typeof value.source.data === "string") {
418
+ source = {
419
+ type: "text",
420
+ media_type: "text/plain",
421
+ data: value.source.data
422
+ };
423
+ } else if (value.source.type === "content") {
424
+ if (typeof value.source.content === "string") {
425
+ source = { type: "content", content: value.source.content };
426
+ } else if (Array.isArray(value.source.content)) {
427
+ const content = [];
428
+ for (const raw of value.source.content) {
429
+ const block = normalizeTextBlock(raw) ?? normalizeImageBlock(raw);
430
+ if (!block) {
431
+ return null;
432
+ }
433
+ content.push(block);
434
+ }
435
+ source = { type: "content", content };
436
+ }
437
+ }
438
+ if (!source) {
439
+ return null;
440
+ }
441
+ return {
442
+ type: "document",
443
+ source,
444
+ ...typeof value.title === "string" || value.title === null ? { title: value.title } : {},
445
+ ...typeof value.context === "string" || value.context === null ? { context: value.context } : {}
446
+ };
447
+ }
448
+ function normalizeToolResultContentBlock(value) {
449
+ const text = normalizeTextBlock(value);
450
+ if (text) {
451
+ return text;
452
+ }
453
+ const image = normalizeImageBlock(value);
454
+ if (image) {
455
+ return image;
456
+ }
457
+ if (!isRecord(value)) {
458
+ return null;
459
+ }
460
+ if (value.type === "tool_reference" && typeof value.tool_name === "string") {
461
+ return { type: "tool_reference", tool_name: value.tool_name };
462
+ }
463
+ if (value.type === "search_result" && typeof value.source === "string" && typeof value.title === "string" && Array.isArray(value.content)) {
464
+ const content = [];
465
+ for (const raw of value.content) {
466
+ const block = normalizeTextBlock(raw);
467
+ if (!block) {
468
+ return null;
469
+ }
470
+ content.push(block);
471
+ }
472
+ return {
473
+ type: "search_result",
474
+ source: value.source,
475
+ title: value.title,
476
+ content
477
+ };
478
+ }
479
+ return normalizeDocumentBlock(value);
480
+ }
481
+ function isToolResultContentBlock(value) {
482
+ return normalizeToolResultContentBlock(value) !== null;
483
+ }
484
+ var SKIP_DIRS = /* @__PURE__ */ new Set([
485
+ ".agents",
486
+ ".git",
487
+ // Git
488
+ ".yukino",
489
+ // Yukino
490
+ ".next",
491
+ // Next.js
492
+ ".venv",
493
+ // Python venv
494
+ ".mypy_cache",
495
+ // Python mypy
496
+ "__pycache__",
497
+ // Python
498
+ "dist",
499
+ // Webpack, Vite
500
+ "node_modules"
501
+ // Node.js
502
+ ]);
503
+
134
504
  // src/llm/anthropic.ts
135
505
  function markToolsForCache(tools) {
136
506
  for (let i = tools.length - 1; i >= 0; i--) {
@@ -164,7 +534,7 @@ function toAnthropicToolSchema(schema, useExplicitCustomType) {
164
534
  "Anthropic received a tool schema serialized for another protocol."
165
535
  );
166
536
  }
167
- var log = createChildLogger({ module: "llm" });
537
+ var log2 = createChildLogger({ module: "llm" });
168
538
  function userBlocksFor(content) {
169
539
  if (typeof content === "string") {
170
540
  return [{ type: "text", text: content }];
@@ -236,13 +606,9 @@ function buildAnthropicMessages(messages) {
236
606
  });
237
607
  continue;
238
608
  }
239
- let canMerge = false;
240
609
  const prev = result[result.length - 1];
241
610
  let content = prev.content;
242
- if (prev.role === "user" && (typeof content === "string" || Array.isArray(content) && content.length > 0 && (content[0].type === "text" || content[0].type === "image"))) {
243
- canMerge = true;
244
- }
245
- if (canMerge) {
611
+ if (prev.role === "user") {
246
612
  if (typeof content === "string") {
247
613
  content = prev.content = content.trim().length > 0 ? [
248
614
  {
@@ -390,6 +756,11 @@ var AnthropicClient = class {
390
756
  thinkingAccumulate = "";
391
757
  thinkingSignature = "";
392
758
  } else if (block.type === "tool_use") {
759
+ if (!block.id || !block.name) {
760
+ throw new NetworkError(
761
+ "Anthropic tool call started without a valid id or name"
762
+ );
763
+ }
393
764
  currentToolId = block.id;
394
765
  currentToolName = block.name === "computer" ? "ComputerUse" : block.name;
395
766
  jsonAccumulate = "";
@@ -417,6 +788,11 @@ var AnthropicClient = class {
417
788
  text: delta.text
418
789
  };
419
790
  } else if (delta.type === "input_json_delta") {
791
+ if (!currentToolId || !currentToolName) {
792
+ throw new NetworkError(
793
+ "Anthropic tool arguments arrived before a valid tool call"
794
+ );
795
+ }
420
796
  jsonAccumulate += delta.partial_json;
421
797
  yield {
422
798
  type: "tool_call_delta",
@@ -435,21 +811,13 @@ var AnthropicClient = class {
435
811
  inThinking = false;
436
812
  }
437
813
  if (currentToolName) {
438
- let args = {};
439
- if (jsonAccumulate) {
440
- try {
441
- const parsed = JSON.parse(jsonAccumulate);
442
- args = isRecord(parsed) ? asRecord(parsed) : {};
443
- } catch (err) {
444
- log.error({ err }, "llm operation failed");
445
- args = {};
446
- }
447
- }
814
+ const parsed = parseToolArguments(jsonAccumulate);
448
815
  yield {
449
816
  type: "tool_call_complete",
450
817
  toolId: currentToolId,
451
818
  toolName: currentToolName,
452
- arguments: args
819
+ arguments: parsed.arguments,
820
+ ...parsed.parseError ? { parseError: parsed.parseError } : {}
453
821
  };
454
822
  currentToolName = "";
455
823
  currentToolId = "";
@@ -505,7 +873,7 @@ var AnthropicClient = class {
505
873
  }
506
874
  };
507
875
  } catch (err) {
508
- log.error({ err }, "llm operation failed");
876
+ log2.error({ err }, "llm operation failed");
509
877
  throw classifyAnthropicError(err);
510
878
  }
511
879
  }
@@ -575,6 +943,15 @@ function classifyAnthropicError(err) {
575
943
  }
576
944
 
577
945
  export {
946
+ normalizeToolResultContentBlock,
947
+ SKIP_DIRS,
948
+ types_exports,
949
+ MCP_TOOL_PREFIX,
950
+ MCPToolWrapper,
951
+ tool_wrapper_exports,
952
+ mcpCallPermissionContent,
953
+ McpCallTool,
954
+ mcp_call_exports,
578
955
  decideAndApply,
579
956
  strategy_exports,
580
957
  markToolsForCache,