@corbat-tech/coco 2.5.1 → 2.5.2

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/index.js CHANGED
@@ -17,8 +17,8 @@ import { promisify } from 'util';
17
17
  import { z } from 'zod';
18
18
  import { Logger } from 'tslog';
19
19
  import Anthropic from '@anthropic-ai/sdk';
20
- import OpenAI from 'openai';
21
20
  import { jsonrepair } from 'jsonrepair';
21
+ import OpenAI from 'openai';
22
22
  import 'http';
23
23
  import { GoogleGenerativeAI, FunctionCallingMode } from '@google/generative-ai';
24
24
  import JSON5 from 'json5';
@@ -8401,6 +8401,12 @@ var ToolRegistry = class {
8401
8401
  return `${field} (${issue.message.toLowerCase()})`;
8402
8402
  });
8403
8403
  errorMessage = `Invalid tool input \u2014 ${fields.join(", ")}`;
8404
+ const allUndefined = error.issues.every(
8405
+ (i) => i.message.toLowerCase().includes("received undefined")
8406
+ );
8407
+ if (allUndefined && error.issues.length > 1) {
8408
+ errorMessage += ". All parameters are missing \u2014 this is likely a JSON serialization error on our side. Please retry with the same arguments.";
8409
+ }
8404
8410
  } else {
8405
8411
  const rawMessage = error instanceof Error ? error.message : String(error);
8406
8412
  errorMessage = humanizeError(rawMessage, name);
@@ -11813,10 +11819,21 @@ var AnthropicProvider = class {
11813
11819
  try {
11814
11820
  currentToolCall.input = currentToolInputJson ? JSON.parse(currentToolInputJson) : {};
11815
11821
  } catch {
11816
- getLogger().warn(
11817
- `Failed to parse tool call arguments: ${currentToolInputJson?.slice(0, 100)}`
11818
- );
11819
- currentToolCall.input = {};
11822
+ let repaired = false;
11823
+ if (currentToolInputJson) {
11824
+ try {
11825
+ currentToolCall.input = JSON.parse(jsonrepair(currentToolInputJson));
11826
+ repaired = true;
11827
+ getLogger().debug(`Repaired JSON for tool ${currentToolCall.name}`);
11828
+ } catch {
11829
+ }
11830
+ }
11831
+ if (!repaired) {
11832
+ getLogger().warn(
11833
+ `Failed to parse tool call arguments for ${currentToolCall.name}: ${currentToolInputJson?.slice(0, 300)}`
11834
+ );
11835
+ currentToolCall.input = {};
11836
+ }
11820
11837
  }
11821
11838
  yield {
11822
11839
  type: "tool_use_end",
@@ -12419,7 +12436,7 @@ var OpenAIProvider = class {
12419
12436
  input = builder.arguments ? JSON.parse(builder.arguments) : {};
12420
12437
  } catch (error) {
12421
12438
  console.warn(
12422
- `[${this.name}] Failed to parse tool call arguments for ${builder.name}: ${builder.arguments?.slice(0, 100)}`
12439
+ `[${this.name}] Failed to parse tool call arguments for ${builder.name}: ${builder.arguments?.slice(0, 300)}`
12423
12440
  );
12424
12441
  try {
12425
12442
  if (builder.arguments) {