@ai-sdk/anthropic 3.0.16 → 3.0.17

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.
@@ -1574,7 +1574,7 @@ async function convertToAnthropicMessagesPrompt({
1574
1574
  cacheControlValidator,
1575
1575
  toolNameMapping
1576
1576
  }) {
1577
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1577
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1578
1578
  const betas = /* @__PURE__ */ new Set();
1579
1579
  const blocks = groupIntoBlocks(prompt);
1580
1580
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2127,13 +2127,25 @@ async function convertToAnthropicMessagesPrompt({
2127
2127
  if (providerToolName === "web_fetch") {
2128
2128
  const output = part.output;
2129
2129
  if (output.type === "error-json") {
2130
- const errorValue = JSON.parse(output.value);
2130
+ let errorValue = {};
2131
+ try {
2132
+ if (typeof output.value === "string") {
2133
+ errorValue = JSON.parse(output.value);
2134
+ } else if (typeof output.value === "object" && output.value !== null) {
2135
+ errorValue = output.value;
2136
+ }
2137
+ } catch (e) {
2138
+ const extractedErrorCode = (_p = output.value) == null ? void 0 : _p.errorCode;
2139
+ errorValue = {
2140
+ errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unknown"
2141
+ };
2142
+ }
2131
2143
  anthropicContent.push({
2132
2144
  type: "web_fetch_tool_result",
2133
2145
  tool_use_id: part.toolCallId,
2134
2146
  content: {
2135
2147
  type: "web_fetch_tool_result_error",
2136
- error_code: errorValue.errorCode
2148
+ error_code: (_q = errorValue.errorCode) != null ? _q : "unknown"
2137
2149
  },
2138
2150
  cache_control: cacheControl
2139
2151
  });