{"version":3,"file":"errors.cjs","names":[],"sources":["../../src/agents/errors.ts"],"sourcesContent":["/* oxlint-disable no-instanceof/no-instanceof */\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport { isGraphBubbleUp } from \"@langchain/langgraph\";\n\nexport class MultipleToolsBoundError extends Error {\n  constructor() {\n    super(\n      \"The provided LLM already has bound tools. \" +\n        \"Please provide an LLM without bound tools to createAgent. \" +\n        \"The agent will bind the tools provided in the 'tools' parameter.\"\n    );\n  }\n}\n\n/**\n * Raised when model returns multiple structured output tool calls when only one is expected.\n */\nexport class MultipleStructuredOutputsError extends Error {\n  public readonly toolNames: string[];\n\n  constructor(toolNames: string[]) {\n    super(\n      `The model has called multiple tools: ${toolNames.join(\n        \", \"\n      )} to return a structured output. ` +\n        \"This is not supported. Please provide a single structured output.\"\n    );\n    this.toolNames = toolNames;\n  }\n}\n\n/**\n * Raised when structured output tool call arguments fail to parse according to the schema.\n */\nexport class StructuredOutputParsingError extends Error {\n  public readonly toolName: string;\n\n  public readonly errors: string[];\n\n  constructor(toolName: string, errors: string[]) {\n    super(\n      `Failed to parse structured output for tool '${toolName}':${errors\n        .map((e) => `\\n  - ${e}`)\n        .join(\"\")}.`\n    );\n    this.toolName = toolName;\n    this.errors = errors;\n  }\n}\n\n/**\n * Raised when a tool call is throwing an error.\n */\nexport class ToolInvocationError extends Error {\n  public readonly toolCall: ToolCall;\n\n  public readonly toolError: Error;\n\n  constructor(toolError: unknown, toolCall: ToolCall) {\n    const error =\n      toolError instanceof Error ? toolError : new Error(String(toolError));\n    const toolArgs = JSON.stringify(toolCall.args);\n    super(\n      `Error invoking tool '${toolCall.name}' with kwargs ${toolArgs} with error: ${error.stack}\\n Please fix the error and try again.`\n    );\n\n    this.toolCall = toolCall;\n    this.toolError = error;\n  }\n}\n\n/**\n * Error thrown when a middleware fails.\n *\n * Use `MiddlewareError.wrap()` to create instances. The constructor is private\n * to ensure that GraphBubbleUp errors (like GraphInterrupt) are never wrapped.\n */\nexport class MiddlewareError extends Error {\n  static readonly \"~brand\" = \"MiddlewareError\";\n\n  private constructor(error: unknown, middlewareName: string) {\n    const errorMessage = error instanceof Error ? error.message : String(error);\n    super(errorMessage);\n    this.name =\n      error instanceof Error\n        ? error.name\n        : `${middlewareName[0].toUpperCase() + middlewareName.slice(1)}Error`;\n\n    if (error instanceof Error) {\n      this.cause = error;\n    }\n  }\n\n  /**\n   * Wrap an error in a MiddlewareError, unless it's a GraphBubbleUp error\n   * (like GraphInterrupt) which should propagate unchanged.\n   *\n   * @param error - The error to wrap\n   * @param middlewareName - The name of the middleware that threw the error\n   * @returns The original error if it's a GraphBubbleUp, otherwise a new MiddlewareError\n   */\n  static wrap(error: unknown, middlewareName: string): Error {\n    // Don't wrap GraphBubbleUp errors (GraphInterrupt, NodeInterrupt, etc.)\n    // These are control flow mechanisms that need to bubble up unchanged\n    if (isGraphBubbleUp(error)) {\n      return error;\n    }\n    return new MiddlewareError(error, middlewareName);\n  }\n\n  /**\n   * Check if the error is a MiddlewareError.\n   * @param error - The error to check\n   * @returns Whether the error is a MiddlewareError\n   */\n  static isInstance(error: unknown): error is MiddlewareError {\n    return (\n      error instanceof Error &&\n      \"~brand\" in error &&\n      error[\"~brand\"] === \"MiddlewareError\"\n    );\n  }\n}\n"],"mappings":";;;AAIA,IAAa,0BAAb,cAA6C,MAAM;CACjD,cAAc;AACZ,QACE,uKAGD;;;;;;AAOL,IAAa,iCAAb,cAAoD,MAAM;CACxD;CAEA,YAAY,WAAqB;AAC/B,QACE,wCAAwC,UAAU,KAChD,KACD,CAAC,mGAEH;AACD,OAAK,YAAY;;;;;;AAOrB,IAAa,+BAAb,cAAkD,MAAM;CACtD;CAEA;CAEA,YAAY,UAAkB,QAAkB;AAC9C,QACE,+CAA+C,SAAS,IAAI,OACzD,KAAK,MAAM,SAAS,IAAI,CACxB,KAAK,GAAG,CAAC,GACb;AACD,OAAK,WAAW;AAChB,OAAK,SAAS;;;;;;AAOlB,IAAa,sBAAb,cAAyC,M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