{"version":3,"file":"errors.cjs","names":["ContextOverflowError","stampRetryable"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\n/* oxlint-disable no-param-reassign */\n\nimport { ContextOverflowError, stampRetryable } from \"@langchain/core/errors\";\n\n// Duplicate of core\n// TODO: Remove once we stop supporting 0.2.x core versions\nexport type LangChainErrorCodes =\n  | \"CONTEXT_OVERFLOW\"\n  | \"INVALID_PROMPT_INPUT\"\n  | \"INVALID_TOOL_RESULTS\"\n  | \"MESSAGE_COERCION_FAILURE\"\n  | \"MODEL_AUTHENTICATION\"\n  | \"MODEL_NOT_FOUND\"\n  | \"MODEL_RATE_LIMIT\"\n  | \"OUTPUT_PARSING_FAILURE\";\n\nexport function addLangChainErrorFields(\n  error: any,\n  lc_error_code: LangChainErrorCodes\n) {\n  (error as any).lc_error_code = lc_error_code;\n  error.message = `${error.message}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/${lc_error_code}/\\n`;\n  return error;\n}\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nexport function wrapAnthropicClientError(e: any) {\n  let error;\n  if (\n    e.status === 400 &&\n    typeof e.message === \"string\" &&\n    e.message.includes(\"prompt is too long\")\n  ) {\n    // ContextOverflowError marks itself non-retryable at construction.\n    error = addLangChainErrorFields(\n      ContextOverflowError.fromError(e),\n      \"CONTEXT_OVERFLOW\"\n    );\n  } else if (e.status === 400 && e.message.includes(\"tool\")) {\n    error = stampRetryable(\n      addLangChainErrorFields(e, \"INVALID_TOOL_RESULTS\"),\n      false\n    );\n  } else if (e.status === 401) {\n    error = stampRetryable(\n      addLangChainErrorFields(e, \"MODEL_AUTHENTICATION\"),\n      false\n    );\n  } else if (e.status === 404) {\n    error = stampRetryable(\n      addLangChainErrorFields(e, \"MODEL_NOT_FOUND\"),\n      false\n    );\n  } else if (e.status === 429) {\n    // AsyncCaller runs after this and re-marks false if it's quota exhaustion.\n    error = stampRetryable(\n      addLangChainErrorFields(e, \"MODEL_RATE_LIMIT\"),\n      true\n    );\n  } else {\n    error = e;\n  }\n  return error;\n}\n"],"mappings":";;AAiBA,SAAgB,wBACd,OACA,eACA;CACA,MAAe,gBAAgB;CAC/B,MAAM,UAAU,GAAG,MAAM,QAAQ,sFAAsF,cAAc;CACrI,OAAO;AACT;AAGA,SAAgB,yBAAyB,GAAQ;CAC/C,IAAI;CACJ,IACE,EAAE,WAAW,OACb,OAAO,EAAE,YAAY,YACrB,EAAE,QAAQ,SAAS,oBAAoB,GAGvC,QAAQ,wBACNA,uBAAAA,qBAAqB,UAAU,CAAC,GAChC,kBACF;MACK,IAAI,EAAE,WAAW,OAAO,EAAE,QAAQ,SAAS,MAAM,GACtD,SAAA,GAAQC,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,sBAAsB,GACjD,KACF;MACK,IAAI,EAAE,WAAW,KACtB,SAAA,GAAQA,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,sBAAsB,GACjD,KACF;MACK,IAAI,EAAE,WAAW,KACtB,SAAA,GAAQA,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,iBAAiB,GAC5C,KACF;MACK,IAAI,EAAE,WAAW,KAEtB,SAAA,GAAQA,uBAAAA,eAAAA,CACN,wBAAwB,GAAG,kBAAkB,GAC7C,IACF;MAEA,QAAQ;CAEV,OAAO;AACT"}