@ai-sdk/anthropic 4.0.0-beta.40 → 4.0.0-beta.41
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +10 -10
- package/dist/index.js +156 -128
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +10 -10
- package/dist/internal/index.js +149 -121
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +1 -1
- package/package.json +4 -4
- package/src/anthropic-api.ts +6 -2
- package/src/anthropic-error.ts +1 -1
- package/src/anthropic-files.ts +4 -5
- package/src/anthropic-language-model.ts +27 -27
- package/src/anthropic-message-metadata.ts +1 -1
- package/src/anthropic-prepare-tools.ts +3 -3
- package/src/anthropic-provider.ts +6 -6
- package/src/convert-anthropic-usage.ts +1 -1
- package/src/convert-to-anthropic-prompt.ts +156 -138
- package/src/forward-anthropic-container-id-from-last-step.ts +2 -2
- package/src/get-cache-control.ts +5 -2
- package/src/map-anthropic-stop-reason.ts +1 -1
- package/src/skills/anthropic-skills.ts +5 -9
- package/src/tool/text-editor_20250728.ts +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
|
|
8
|
+
- 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
|
|
9
|
+
- Updated dependencies [9bd6512]
|
|
10
|
+
- Updated dependencies [258c093]
|
|
11
|
+
- Updated dependencies [b6783da]
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.0-beta.29
|
|
13
|
+
- @ai-sdk/provider@4.0.0-beta.14
|
|
14
|
+
|
|
3
15
|
## 4.0.0-beta.40
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -284,7 +284,7 @@ declare const anthropicTools: {
|
|
|
284
284
|
type: "code_execution_output";
|
|
285
285
|
file_id: string;
|
|
286
286
|
}>;
|
|
287
|
-
}, {}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
287
|
+
}, {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
288
288
|
code: string;
|
|
289
289
|
}, {
|
|
290
290
|
type: "code_execution_result";
|
|
@@ -368,7 +368,7 @@ declare const anthropicTools: {
|
|
|
368
368
|
new_start: number | null;
|
|
369
369
|
old_lines: number | null;
|
|
370
370
|
old_start: number | null;
|
|
371
|
-
}, {}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
371
|
+
}, {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
372
372
|
type: "programmatic-tool-call";
|
|
373
373
|
code: string;
|
|
374
374
|
} | {
|
|
@@ -514,7 +514,7 @@ declare const anthropicTools: {
|
|
|
514
514
|
new_start: number | null;
|
|
515
515
|
old_lines: number | null;
|
|
516
516
|
old_start: number | null;
|
|
517
|
-
}, {}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
517
|
+
}, {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
518
518
|
type: "programmatic-tool-call";
|
|
519
519
|
code: string;
|
|
520
520
|
} | {
|
|
@@ -767,7 +767,7 @@ declare const anthropicTools: {
|
|
|
767
767
|
view_range?: number[];
|
|
768
768
|
}, {
|
|
769
769
|
maxCharacters?: number;
|
|
770
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
770
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderDefinedTool<{
|
|
771
771
|
command: "view" | "create" | "str_replace" | "insert";
|
|
772
772
|
path: string;
|
|
773
773
|
file_text?: string;
|
|
@@ -816,7 +816,7 @@ declare const anthropicTools: {
|
|
|
816
816
|
enabled: boolean;
|
|
817
817
|
};
|
|
818
818
|
maxContentTokens?: number;
|
|
819
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
819
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
820
820
|
url: string;
|
|
821
821
|
}, {
|
|
822
822
|
type: "web_fetch_result";
|
|
@@ -878,7 +878,7 @@ declare const anthropicTools: {
|
|
|
878
878
|
enabled: boolean;
|
|
879
879
|
};
|
|
880
880
|
maxContentTokens?: number;
|
|
881
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
881
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
882
882
|
url: string;
|
|
883
883
|
}, {
|
|
884
884
|
type: "web_fetch_result";
|
|
@@ -928,7 +928,7 @@ declare const anthropicTools: {
|
|
|
928
928
|
country?: string;
|
|
929
929
|
timezone?: string;
|
|
930
930
|
};
|
|
931
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
931
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
932
932
|
query: string;
|
|
933
933
|
}, {
|
|
934
934
|
type: "web_search_result";
|
|
@@ -964,7 +964,7 @@ declare const anthropicTools: {
|
|
|
964
964
|
country?: string;
|
|
965
965
|
timezone?: string;
|
|
966
966
|
};
|
|
967
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
967
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
968
968
|
query: string;
|
|
969
969
|
}, {
|
|
970
970
|
type: "web_search_result";
|
|
@@ -992,7 +992,7 @@ declare const anthropicTools: {
|
|
|
992
992
|
}, {
|
|
993
993
|
type: "tool_reference";
|
|
994
994
|
toolName: string;
|
|
995
|
-
}[], {}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
995
|
+
}[], {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
996
996
|
pattern: string;
|
|
997
997
|
limit?: number;
|
|
998
998
|
}, {
|
|
@@ -1018,7 +1018,7 @@ declare const anthropicTools: {
|
|
|
1018
1018
|
}, {
|
|
1019
1019
|
type: "tool_reference";
|
|
1020
1020
|
toolName: string;
|
|
1021
|
-
}[], {}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
1021
|
+
}[], {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
1022
1022
|
query: string;
|
|
1023
1023
|
limit?: number;
|
|
1024
1024
|
}, {
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
// src/anthropic-files.ts
|
|
15
15
|
import {
|
|
16
16
|
combineHeaders,
|
|
17
|
-
|
|
17
|
+
convertInlineFileDataToUint8Array,
|
|
18
18
|
createJsonResponseHandler,
|
|
19
19
|
lazySchema as lazySchema2,
|
|
20
20
|
postFormDataToApi,
|
|
@@ -73,7 +73,7 @@ var AnthropicFiles = class {
|
|
|
73
73
|
filename
|
|
74
74
|
}) {
|
|
75
75
|
var _a, _b;
|
|
76
|
-
const fileBytes =
|
|
76
|
+
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
77
77
|
const blob = new Blob([fileBytes], { type: mediaType });
|
|
78
78
|
const formData = new FormData();
|
|
79
79
|
if (filename != null) {
|
|
@@ -134,7 +134,10 @@ import {
|
|
|
134
134
|
} from "@ai-sdk/provider-utils";
|
|
135
135
|
|
|
136
136
|
// src/anthropic-api.ts
|
|
137
|
-
import {
|
|
137
|
+
import {
|
|
138
|
+
lazySchema as lazySchema3,
|
|
139
|
+
zodSchema as zodSchema3
|
|
140
|
+
} from "@ai-sdk/provider-utils";
|
|
138
141
|
import { z as z3 } from "zod/v4";
|
|
139
142
|
var anthropicResponseSchema = lazySchema3(
|
|
140
143
|
() => zodSchema3(
|
|
@@ -1145,9 +1148,12 @@ var CacheControlValidator = class {
|
|
|
1145
1148
|
};
|
|
1146
1149
|
|
|
1147
1150
|
// src/tool/text-editor_20250728.ts
|
|
1148
|
-
import {
|
|
1151
|
+
import {
|
|
1152
|
+
createProviderDefinedToolFactory,
|
|
1153
|
+
lazySchema as lazySchema4,
|
|
1154
|
+
zodSchema as zodSchema4
|
|
1155
|
+
} from "@ai-sdk/provider-utils";
|
|
1149
1156
|
import { z as z5 } from "zod/v4";
|
|
1150
|
-
import { lazySchema as lazySchema4, zodSchema as zodSchema4 } from "@ai-sdk/provider-utils";
|
|
1151
1157
|
var textEditor_20250728ArgsSchema = lazySchema4(
|
|
1152
1158
|
() => zodSchema4(
|
|
1153
1159
|
z5.object({
|
|
@@ -1794,10 +1800,11 @@ import {
|
|
|
1794
1800
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
1795
1801
|
} from "@ai-sdk/provider";
|
|
1796
1802
|
import {
|
|
1797
|
-
convertBase64ToUint8Array
|
|
1803
|
+
convertBase64ToUint8Array,
|
|
1798
1804
|
convertToBase64,
|
|
1799
|
-
|
|
1805
|
+
getTopLevelMediaType,
|
|
1800
1806
|
parseProviderOptions,
|
|
1807
|
+
resolveFullMediaType,
|
|
1801
1808
|
resolveProviderReference,
|
|
1802
1809
|
validateTypes as validateTypes2,
|
|
1803
1810
|
isNonNullable
|
|
@@ -2125,30 +2132,11 @@ var toolSearchRegex_20251119 = (args = {}) => {
|
|
|
2125
2132
|
};
|
|
2126
2133
|
|
|
2127
2134
|
// src/convert-to-anthropic-prompt.ts
|
|
2128
|
-
function
|
|
2135
|
+
function convertBytesDataToString(data) {
|
|
2129
2136
|
if (typeof data === "string") {
|
|
2130
|
-
return new TextDecoder().decode(
|
|
2131
|
-
}
|
|
2132
|
-
if (data instanceof Uint8Array) {
|
|
2133
|
-
return new TextDecoder().decode(data);
|
|
2137
|
+
return new TextDecoder().decode(convertBase64ToUint8Array(data));
|
|
2134
2138
|
}
|
|
2135
|
-
|
|
2136
|
-
throw new UnsupportedFunctionalityError2({
|
|
2137
|
-
functionality: "URL-based text documents are not supported for citations"
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
throw new UnsupportedFunctionalityError2({
|
|
2141
|
-
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
2142
|
-
});
|
|
2143
|
-
}
|
|
2144
|
-
function isUrlData(data) {
|
|
2145
|
-
return data instanceof URL || isUrlString(data);
|
|
2146
|
-
}
|
|
2147
|
-
function isUrlString(data) {
|
|
2148
|
-
return typeof data === "string" && /^https?:\/\//i.test(data);
|
|
2149
|
-
}
|
|
2150
|
-
function getUrlString(data) {
|
|
2151
|
-
return data instanceof URL ? data.toString() : data;
|
|
2139
|
+
return new TextDecoder().decode(data);
|
|
2152
2140
|
}
|
|
2153
2141
|
async function convertToAnthropicPrompt({
|
|
2154
2142
|
prompt,
|
|
@@ -2157,7 +2145,7 @@ async function convertToAnthropicPrompt({
|
|
|
2157
2145
|
cacheControlValidator,
|
|
2158
2146
|
toolNameMapping
|
|
2159
2147
|
}) {
|
|
2160
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
2148
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
2161
2149
|
const betas = /* @__PURE__ */ new Set();
|
|
2162
2150
|
const blocks = groupIntoBlocks(prompt);
|
|
2163
2151
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2230,91 +2218,131 @@ async function convertToAnthropicPrompt({
|
|
|
2230
2218
|
break;
|
|
2231
2219
|
}
|
|
2232
2220
|
case "file": {
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
betas.add("files-api-2025-04-14");
|
|
2239
|
-
if (part.mediaType.startsWith("image/")) {
|
|
2240
|
-
anthropicContent.push({
|
|
2241
|
-
type: "image",
|
|
2242
|
-
source: { type: "file", file_id: fileId },
|
|
2243
|
-
cache_control: cacheControl
|
|
2221
|
+
switch (part.data.type) {
|
|
2222
|
+
case "reference": {
|
|
2223
|
+
const fileId = resolveProviderReference({
|
|
2224
|
+
reference: part.data.reference,
|
|
2225
|
+
provider: "anthropic"
|
|
2244
2226
|
});
|
|
2245
|
-
|
|
2227
|
+
betas.add("files-api-2025-04-14");
|
|
2228
|
+
if (getTopLevelMediaType(part.mediaType) === "image") {
|
|
2229
|
+
anthropicContent.push({
|
|
2230
|
+
type: "image",
|
|
2231
|
+
source: { type: "file", file_id: fileId },
|
|
2232
|
+
cache_control: cacheControl
|
|
2233
|
+
});
|
|
2234
|
+
} else {
|
|
2235
|
+
anthropicContent.push({
|
|
2236
|
+
type: "document",
|
|
2237
|
+
source: { type: "file", file_id: fileId },
|
|
2238
|
+
cache_control: cacheControl
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
break;
|
|
2242
|
+
}
|
|
2243
|
+
case "text": {
|
|
2244
|
+
const enableCitations = await shouldEnableCitations(
|
|
2245
|
+
part.providerOptions
|
|
2246
|
+
);
|
|
2247
|
+
const metadata = await getDocumentMetadata(
|
|
2248
|
+
part.providerOptions
|
|
2249
|
+
);
|
|
2246
2250
|
anthropicContent.push({
|
|
2247
2251
|
type: "document",
|
|
2248
|
-
source: {
|
|
2252
|
+
source: {
|
|
2253
|
+
type: "text",
|
|
2254
|
+
media_type: "text/plain",
|
|
2255
|
+
data: part.data.text
|
|
2256
|
+
},
|
|
2257
|
+
title: (_b = metadata.title) != null ? _b : part.filename,
|
|
2258
|
+
...metadata.context && {
|
|
2259
|
+
context: metadata.context
|
|
2260
|
+
},
|
|
2261
|
+
...enableCitations && {
|
|
2262
|
+
citations: { enabled: true }
|
|
2263
|
+
},
|
|
2249
2264
|
cache_control: cacheControl
|
|
2250
2265
|
});
|
|
2266
|
+
break;
|
|
2267
|
+
}
|
|
2268
|
+
case "url":
|
|
2269
|
+
case "data": {
|
|
2270
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
2271
|
+
if (topLevel === "image") {
|
|
2272
|
+
anthropicContent.push({
|
|
2273
|
+
type: "image",
|
|
2274
|
+
source: part.data.type === "url" ? {
|
|
2275
|
+
type: "url",
|
|
2276
|
+
url: part.data.url.toString()
|
|
2277
|
+
} : {
|
|
2278
|
+
type: "base64",
|
|
2279
|
+
media_type: resolveFullMediaType({ part }),
|
|
2280
|
+
data: convertToBase64(part.data.data)
|
|
2281
|
+
},
|
|
2282
|
+
cache_control: cacheControl
|
|
2283
|
+
});
|
|
2284
|
+
} else if (topLevel === "application" && (part.data.type === "url" ? part.mediaType === "application/pdf" : resolveFullMediaType({ part }) === "application/pdf")) {
|
|
2285
|
+
betas.add("pdfs-2024-09-25");
|
|
2286
|
+
const enableCitations = await shouldEnableCitations(
|
|
2287
|
+
part.providerOptions
|
|
2288
|
+
);
|
|
2289
|
+
const metadata = await getDocumentMetadata(
|
|
2290
|
+
part.providerOptions
|
|
2291
|
+
);
|
|
2292
|
+
anthropicContent.push({
|
|
2293
|
+
type: "document",
|
|
2294
|
+
source: part.data.type === "url" ? {
|
|
2295
|
+
type: "url",
|
|
2296
|
+
url: part.data.url.toString()
|
|
2297
|
+
} : {
|
|
2298
|
+
type: "base64",
|
|
2299
|
+
media_type: "application/pdf",
|
|
2300
|
+
data: convertToBase64(part.data.data)
|
|
2301
|
+
},
|
|
2302
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
2303
|
+
...metadata.context && {
|
|
2304
|
+
context: metadata.context
|
|
2305
|
+
},
|
|
2306
|
+
...enableCitations && {
|
|
2307
|
+
citations: { enabled: true }
|
|
2308
|
+
},
|
|
2309
|
+
cache_control: cacheControl
|
|
2310
|
+
});
|
|
2311
|
+
} else if (part.mediaType === "text/plain") {
|
|
2312
|
+
const enableCitations = await shouldEnableCitations(
|
|
2313
|
+
part.providerOptions
|
|
2314
|
+
);
|
|
2315
|
+
const metadata = await getDocumentMetadata(
|
|
2316
|
+
part.providerOptions
|
|
2317
|
+
);
|
|
2318
|
+
anthropicContent.push({
|
|
2319
|
+
type: "document",
|
|
2320
|
+
source: part.data.type === "url" ? {
|
|
2321
|
+
type: "url",
|
|
2322
|
+
url: part.data.url.toString()
|
|
2323
|
+
} : {
|
|
2324
|
+
type: "text",
|
|
2325
|
+
media_type: "text/plain",
|
|
2326
|
+
data: convertBytesDataToString(
|
|
2327
|
+
part.data.data
|
|
2328
|
+
)
|
|
2329
|
+
},
|
|
2330
|
+
title: (_d = metadata.title) != null ? _d : part.filename,
|
|
2331
|
+
...metadata.context && {
|
|
2332
|
+
context: metadata.context
|
|
2333
|
+
},
|
|
2334
|
+
...enableCitations && {
|
|
2335
|
+
citations: { enabled: true }
|
|
2336
|
+
},
|
|
2337
|
+
cache_control: cacheControl
|
|
2338
|
+
});
|
|
2339
|
+
} else {
|
|
2340
|
+
throw new UnsupportedFunctionalityError2({
|
|
2341
|
+
functionality: `media type: ${part.mediaType}`
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
break;
|
|
2251
2345
|
}
|
|
2252
|
-
} else if (part.mediaType.startsWith("image/")) {
|
|
2253
|
-
anthropicContent.push({
|
|
2254
|
-
type: "image",
|
|
2255
|
-
source: isUrlData(part.data) ? {
|
|
2256
|
-
type: "url",
|
|
2257
|
-
url: getUrlString(part.data)
|
|
2258
|
-
} : {
|
|
2259
|
-
type: "base64",
|
|
2260
|
-
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
2261
|
-
data: convertToBase64(part.data)
|
|
2262
|
-
},
|
|
2263
|
-
cache_control: cacheControl
|
|
2264
|
-
});
|
|
2265
|
-
} else if (part.mediaType === "application/pdf") {
|
|
2266
|
-
betas.add("pdfs-2024-09-25");
|
|
2267
|
-
const enableCitations = await shouldEnableCitations(
|
|
2268
|
-
part.providerOptions
|
|
2269
|
-
);
|
|
2270
|
-
const metadata = await getDocumentMetadata(
|
|
2271
|
-
part.providerOptions
|
|
2272
|
-
);
|
|
2273
|
-
anthropicContent.push({
|
|
2274
|
-
type: "document",
|
|
2275
|
-
source: isUrlData(part.data) ? {
|
|
2276
|
-
type: "url",
|
|
2277
|
-
url: getUrlString(part.data)
|
|
2278
|
-
} : {
|
|
2279
|
-
type: "base64",
|
|
2280
|
-
media_type: "application/pdf",
|
|
2281
|
-
data: convertToBase64(part.data)
|
|
2282
|
-
},
|
|
2283
|
-
title: (_b = metadata.title) != null ? _b : part.filename,
|
|
2284
|
-
...metadata.context && { context: metadata.context },
|
|
2285
|
-
...enableCitations && {
|
|
2286
|
-
citations: { enabled: true }
|
|
2287
|
-
},
|
|
2288
|
-
cache_control: cacheControl
|
|
2289
|
-
});
|
|
2290
|
-
} else if (part.mediaType === "text/plain") {
|
|
2291
|
-
const enableCitations = await shouldEnableCitations(
|
|
2292
|
-
part.providerOptions
|
|
2293
|
-
);
|
|
2294
|
-
const metadata = await getDocumentMetadata(
|
|
2295
|
-
part.providerOptions
|
|
2296
|
-
);
|
|
2297
|
-
anthropicContent.push({
|
|
2298
|
-
type: "document",
|
|
2299
|
-
source: isUrlData(part.data) ? {
|
|
2300
|
-
type: "url",
|
|
2301
|
-
url: getUrlString(part.data)
|
|
2302
|
-
} : {
|
|
2303
|
-
type: "text",
|
|
2304
|
-
media_type: "text/plain",
|
|
2305
|
-
data: convertToString(part.data)
|
|
2306
|
-
},
|
|
2307
|
-
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
2308
|
-
...metadata.context && { context: metadata.context },
|
|
2309
|
-
...enableCitations && {
|
|
2310
|
-
citations: { enabled: true }
|
|
2311
|
-
},
|
|
2312
|
-
cache_control: cacheControl
|
|
2313
|
-
});
|
|
2314
|
-
} else {
|
|
2315
|
-
throw new UnsupportedFunctionalityError2({
|
|
2316
|
-
functionality: `media type: ${part.mediaType}`
|
|
2317
|
-
});
|
|
2318
2346
|
}
|
|
2319
2347
|
break;
|
|
2320
2348
|
}
|
|
@@ -2329,10 +2357,10 @@ async function convertToAnthropicPrompt({
|
|
|
2329
2357
|
continue;
|
|
2330
2358
|
}
|
|
2331
2359
|
const isLastPart = i2 === content.length - 1;
|
|
2332
|
-
const cacheControl = (
|
|
2360
|
+
const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
|
|
2333
2361
|
type: "tool result part",
|
|
2334
2362
|
canCache: true
|
|
2335
|
-
})) != null ?
|
|
2363
|
+
})) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2336
2364
|
type: "tool result message",
|
|
2337
2365
|
canCache: true
|
|
2338
2366
|
}) : void 0;
|
|
@@ -2423,7 +2451,7 @@ async function convertToAnthropicPrompt({
|
|
|
2423
2451
|
contentValue = output.value;
|
|
2424
2452
|
break;
|
|
2425
2453
|
case "execution-denied":
|
|
2426
|
-
contentValue = (
|
|
2454
|
+
contentValue = (_f = output.reason) != null ? _f : "Tool call execution denied.";
|
|
2427
2455
|
break;
|
|
2428
2456
|
case "json":
|
|
2429
2457
|
case "error-json":
|
|
@@ -2460,16 +2488,16 @@ async function convertToAnthropicPrompt({
|
|
|
2460
2488
|
for (let k = 0; k < content.length; k++) {
|
|
2461
2489
|
const part = content[k];
|
|
2462
2490
|
const isLastContentPart = k === content.length - 1;
|
|
2463
|
-
const cacheControl = (
|
|
2491
|
+
const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
|
|
2464
2492
|
type: "assistant message part",
|
|
2465
2493
|
canCache: true
|
|
2466
|
-
})) != null ?
|
|
2494
|
+
})) != null ? _g : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2467
2495
|
type: "assistant message",
|
|
2468
2496
|
canCache: true
|
|
2469
2497
|
}) : void 0;
|
|
2470
2498
|
switch (part.type) {
|
|
2471
2499
|
case "text": {
|
|
2472
|
-
const textMetadata = (
|
|
2500
|
+
const textMetadata = (_h = part.providerOptions) == null ? void 0 : _h.anthropic;
|
|
2473
2501
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2474
2502
|
anthropicContent.push({
|
|
2475
2503
|
type: "compaction",
|
|
@@ -2542,10 +2570,10 @@ async function convertToAnthropicPrompt({
|
|
|
2542
2570
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2543
2571
|
part.toolName
|
|
2544
2572
|
);
|
|
2545
|
-
const isMcpToolUse = ((
|
|
2573
|
+
const isMcpToolUse = ((_j = (_i = part.providerOptions) == null ? void 0 : _i.anthropic) == null ? void 0 : _j.type) === "mcp-tool-use";
|
|
2546
2574
|
if (isMcpToolUse) {
|
|
2547
2575
|
mcpToolUseIds.add(part.toolCallId);
|
|
2548
|
-
const serverName = (
|
|
2576
|
+
const serverName = (_l = (_k = part.providerOptions) == null ? void 0 : _k.anthropic) == null ? void 0 : _l.serverName;
|
|
2549
2577
|
if (serverName == null || typeof serverName !== "string") {
|
|
2550
2578
|
warnings.push({
|
|
2551
2579
|
type: "other",
|
|
@@ -2613,7 +2641,7 @@ async function convertToAnthropicPrompt({
|
|
|
2613
2641
|
}
|
|
2614
2642
|
break;
|
|
2615
2643
|
}
|
|
2616
|
-
const callerOptions = (
|
|
2644
|
+
const callerOptions = (_m = part.providerOptions) == null ? void 0 : _m.anthropic;
|
|
2617
2645
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2618
2646
|
type: callerOptions.caller.type,
|
|
2619
2647
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2666,7 +2694,7 @@ async function convertToAnthropicPrompt({
|
|
|
2666
2694
|
tool_use_id: part.toolCallId,
|
|
2667
2695
|
content: {
|
|
2668
2696
|
type: "code_execution_tool_result_error",
|
|
2669
|
-
error_code: (
|
|
2697
|
+
error_code: (_n = errorInfo.errorCode) != null ? _n : "unknown"
|
|
2670
2698
|
},
|
|
2671
2699
|
cache_control: cacheControl
|
|
2672
2700
|
});
|
|
@@ -2677,7 +2705,7 @@ async function convertToAnthropicPrompt({
|
|
|
2677
2705
|
cache_control: cacheControl,
|
|
2678
2706
|
content: {
|
|
2679
2707
|
type: "bash_code_execution_tool_result_error",
|
|
2680
|
-
error_code: (
|
|
2708
|
+
error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
|
|
2681
2709
|
}
|
|
2682
2710
|
});
|
|
2683
2711
|
}
|
|
@@ -2710,7 +2738,7 @@ async function convertToAnthropicPrompt({
|
|
|
2710
2738
|
stdout: codeExecutionOutput.stdout,
|
|
2711
2739
|
stderr: codeExecutionOutput.stderr,
|
|
2712
2740
|
return_code: codeExecutionOutput.return_code,
|
|
2713
|
-
content: (
|
|
2741
|
+
content: (_p = codeExecutionOutput.content) != null ? _p : []
|
|
2714
2742
|
},
|
|
2715
2743
|
cache_control: cacheControl
|
|
2716
2744
|
});
|
|
@@ -2728,7 +2756,7 @@ async function convertToAnthropicPrompt({
|
|
|
2728
2756
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2729
2757
|
stderr: codeExecutionOutput.stderr,
|
|
2730
2758
|
return_code: codeExecutionOutput.return_code,
|
|
2731
|
-
content: (
|
|
2759
|
+
content: (_q = codeExecutionOutput.content) != null ? _q : []
|
|
2732
2760
|
},
|
|
2733
2761
|
cache_control: cacheControl
|
|
2734
2762
|
});
|
|
@@ -2747,7 +2775,7 @@ async function convertToAnthropicPrompt({
|
|
|
2747
2775
|
stdout: codeExecutionOutput.stdout,
|
|
2748
2776
|
stderr: codeExecutionOutput.stderr,
|
|
2749
2777
|
return_code: codeExecutionOutput.return_code,
|
|
2750
|
-
content: (
|
|
2778
|
+
content: (_r = codeExecutionOutput.content) != null ? _r : []
|
|
2751
2779
|
},
|
|
2752
2780
|
cache_control: cacheControl
|
|
2753
2781
|
});
|
|
@@ -2780,7 +2808,7 @@ async function convertToAnthropicPrompt({
|
|
|
2780
2808
|
errorValue = output.value;
|
|
2781
2809
|
}
|
|
2782
2810
|
} catch (e) {
|
|
2783
|
-
const extractedErrorCode = (
|
|
2811
|
+
const extractedErrorCode = (_s = output.value) == null ? void 0 : _s.errorCode;
|
|
2784
2812
|
errorValue = {
|
|
2785
2813
|
errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
|
|
2786
2814
|
};
|
|
@@ -2790,7 +2818,7 @@ async function convertToAnthropicPrompt({
|
|
|
2790
2818
|
tool_use_id: part.toolCallId,
|
|
2791
2819
|
content: {
|
|
2792
2820
|
type: "web_fetch_tool_result_error",
|
|
2793
|
-
error_code: (
|
|
2821
|
+
error_code: (_t = errorValue.errorCode) != null ? _t : "unavailable"
|
|
2794
2822
|
},
|
|
2795
2823
|
cache_control: cacheControl
|
|
2796
2824
|
});
|
|
@@ -5586,7 +5614,7 @@ var anthropicTools = {
|
|
|
5586
5614
|
// src/skills/anthropic-skills.ts
|
|
5587
5615
|
import {
|
|
5588
5616
|
combineHeaders as combineHeaders3,
|
|
5589
|
-
|
|
5617
|
+
convertInlineFileDataToUint8Array as convertInlineFileDataToUint8Array2,
|
|
5590
5618
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
5591
5619
|
getFromApi,
|
|
5592
5620
|
postFormDataToApi as postFormDataToApi2,
|
|
@@ -5673,7 +5701,7 @@ var AnthropicSkills = class {
|
|
|
5673
5701
|
formData.append("display_title", params.displayTitle);
|
|
5674
5702
|
}
|
|
5675
5703
|
for (const file of params.files) {
|
|
5676
|
-
const content =
|
|
5704
|
+
const content = convertInlineFileDataToUint8Array2(file.data);
|
|
5677
5705
|
formData.append("files[]", new Blob([content]), file.path);
|
|
5678
5706
|
}
|
|
5679
5707
|
const headers = await this.getHeaders();
|
|
@@ -5713,7 +5741,7 @@ var AnthropicSkills = class {
|
|
|
5713
5741
|
};
|
|
5714
5742
|
|
|
5715
5743
|
// src/version.ts
|
|
5716
|
-
var VERSION = true ? "4.0.0-beta.
|
|
5744
|
+
var VERSION = true ? "4.0.0-beta.41" : "0.0.0-test";
|
|
5717
5745
|
|
|
5718
5746
|
// src/anthropic-provider.ts
|
|
5719
5747
|
function createAnthropic(options = {}) {
|