@ai-sdk/anthropic 2.0.111 → 2.0.113
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 +24 -0
- package/dist/index.js +348 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +352 -42
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +12 -1
- package/dist/internal/index.d.ts +12 -1
- package/dist/internal/index.js +351 -42
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +353 -42
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "2.0.
|
|
14
|
+
var VERSION = true ? "2.0.113" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
generateId,
|
|
26
26
|
parseProviderOptions as parseProviderOptions2,
|
|
27
27
|
postJsonToApi,
|
|
28
|
-
resolve
|
|
28
|
+
resolve,
|
|
29
|
+
secureJsonParse as secureJsonParse2
|
|
29
30
|
} from "@ai-sdk/provider-utils";
|
|
30
31
|
|
|
31
32
|
// src/anthropic-error.ts
|
|
@@ -1042,10 +1043,17 @@ var computerToolset_20260801Members = [
|
|
|
1042
1043
|
"hold_key",
|
|
1043
1044
|
"wait"
|
|
1044
1045
|
];
|
|
1045
|
-
var computerToolset_20260801InputSchema = lazySchema4(
|
|
1046
|
+
var computerToolset_20260801InputSchema = (configs) => lazySchema4(
|
|
1046
1047
|
() => zodSchema4(
|
|
1047
1048
|
z4.object({
|
|
1048
|
-
action: z4.enum(
|
|
1049
|
+
action: z4.enum(
|
|
1050
|
+
computerToolset_20260801Members.filter(
|
|
1051
|
+
(member) => {
|
|
1052
|
+
var _a;
|
|
1053
|
+
return ((_a = configs == null ? void 0 : configs[member]) == null ? void 0 : _a.enabled) !== false;
|
|
1054
|
+
}
|
|
1055
|
+
)
|
|
1056
|
+
),
|
|
1049
1057
|
coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
|
|
1050
1058
|
duration: z4.number().optional(),
|
|
1051
1059
|
region: z4.tuple([
|
|
@@ -1075,10 +1083,14 @@ var computerToolset_20260801ArgsSchema = lazySchema4(
|
|
|
1075
1083
|
})
|
|
1076
1084
|
)
|
|
1077
1085
|
);
|
|
1078
|
-
var
|
|
1086
|
+
var factory = createProviderDefinedToolFactory({
|
|
1079
1087
|
id: "anthropic.computer_toolset_20260801",
|
|
1080
1088
|
name: "computer",
|
|
1081
|
-
inputSchema: computerToolset_20260801InputSchema
|
|
1089
|
+
inputSchema: computerToolset_20260801InputSchema()
|
|
1090
|
+
});
|
|
1091
|
+
var computerToolset_20260801 = (args) => ({
|
|
1092
|
+
...factory(args),
|
|
1093
|
+
inputSchema: computerToolset_20260801InputSchema(args.configs)
|
|
1082
1094
|
});
|
|
1083
1095
|
|
|
1084
1096
|
// src/tool/text-editor_20250728.ts
|
|
@@ -1108,13 +1120,13 @@ var textEditor_20250728InputSchema = lazySchema5(
|
|
|
1108
1120
|
})
|
|
1109
1121
|
)
|
|
1110
1122
|
);
|
|
1111
|
-
var
|
|
1123
|
+
var factory2 = createProviderDefinedToolFactory2({
|
|
1112
1124
|
id: "anthropic.text_editor_20250728",
|
|
1113
1125
|
name: "str_replace_based_edit_tool",
|
|
1114
1126
|
inputSchema: textEditor_20250728InputSchema
|
|
1115
1127
|
});
|
|
1116
1128
|
var textEditor_20250728 = (args = {}) => {
|
|
1117
|
-
return
|
|
1129
|
+
return factory2(args);
|
|
1118
1130
|
};
|
|
1119
1131
|
|
|
1120
1132
|
// src/tool/web-search_20250305.ts
|
|
@@ -1160,14 +1172,14 @@ var webSearch_20250305InputSchema = lazySchema6(
|
|
|
1160
1172
|
})
|
|
1161
1173
|
)
|
|
1162
1174
|
);
|
|
1163
|
-
var
|
|
1175
|
+
var factory3 = createProviderDefinedToolFactoryWithOutputSchema({
|
|
1164
1176
|
id: "anthropic.web_search_20250305",
|
|
1165
1177
|
name: "web_search",
|
|
1166
1178
|
inputSchema: webSearch_20250305InputSchema,
|
|
1167
1179
|
outputSchema: webSearch_20250305OutputSchema
|
|
1168
1180
|
});
|
|
1169
1181
|
var webSearch_20250305 = (args = {}) => {
|
|
1170
|
-
return
|
|
1182
|
+
return factory3(args);
|
|
1171
1183
|
};
|
|
1172
1184
|
|
|
1173
1185
|
// src/tool/web-fetch-20250910.ts
|
|
@@ -1221,14 +1233,14 @@ var webFetch_20250910InputSchema = lazySchema7(
|
|
|
1221
1233
|
})
|
|
1222
1234
|
)
|
|
1223
1235
|
);
|
|
1224
|
-
var
|
|
1236
|
+
var factory4 = createProviderDefinedToolFactoryWithOutputSchema2({
|
|
1225
1237
|
id: "anthropic.web_fetch_20250910",
|
|
1226
1238
|
name: "web_fetch",
|
|
1227
1239
|
inputSchema: webFetch_20250910InputSchema,
|
|
1228
1240
|
outputSchema: webFetch_20250910OutputSchema
|
|
1229
1241
|
});
|
|
1230
1242
|
var webFetch_20250910 = (args = {}) => {
|
|
1231
|
-
return
|
|
1243
|
+
return factory4(args);
|
|
1232
1244
|
};
|
|
1233
1245
|
|
|
1234
1246
|
// src/anthropic-prepare-tools.ts
|
|
@@ -1546,6 +1558,8 @@ import {
|
|
|
1546
1558
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
1547
1559
|
} from "@ai-sdk/provider";
|
|
1548
1560
|
import {
|
|
1561
|
+
stringifyWithBigIntAndCycles,
|
|
1562
|
+
secureJsonParse,
|
|
1549
1563
|
convertToBase64,
|
|
1550
1564
|
parseProviderOptions,
|
|
1551
1565
|
validateTypes as validateTypes2
|
|
@@ -1575,14 +1589,14 @@ var codeExecution_20250522InputSchema = lazySchema8(
|
|
|
1575
1589
|
})
|
|
1576
1590
|
)
|
|
1577
1591
|
);
|
|
1578
|
-
var
|
|
1592
|
+
var factory5 = createProviderDefinedToolFactoryWithOutputSchema3({
|
|
1579
1593
|
id: "anthropic.code_execution_20250522",
|
|
1580
1594
|
name: "code_execution",
|
|
1581
1595
|
inputSchema: codeExecution_20250522InputSchema,
|
|
1582
1596
|
outputSchema: codeExecution_20250522OutputSchema
|
|
1583
1597
|
});
|
|
1584
1598
|
var codeExecution_20250522 = (args = {}) => {
|
|
1585
|
-
return
|
|
1599
|
+
return factory5(args);
|
|
1586
1600
|
};
|
|
1587
1601
|
|
|
1588
1602
|
// src/tool/code-execution_20250825.ts
|
|
@@ -1668,14 +1682,14 @@ var codeExecution_20250825InputSchema = lazySchema9(
|
|
|
1668
1682
|
])
|
|
1669
1683
|
)
|
|
1670
1684
|
);
|
|
1671
|
-
var
|
|
1685
|
+
var factory6 = createProviderDefinedToolFactoryWithOutputSchema4({
|
|
1672
1686
|
id: "anthropic.code_execution_20250825",
|
|
1673
1687
|
name: "code_execution",
|
|
1674
1688
|
inputSchema: codeExecution_20250825InputSchema,
|
|
1675
1689
|
outputSchema: codeExecution_20250825OutputSchema
|
|
1676
1690
|
});
|
|
1677
1691
|
var codeExecution_20250825 = (args = {}) => {
|
|
1678
|
-
return
|
|
1692
|
+
return factory6(args);
|
|
1679
1693
|
};
|
|
1680
1694
|
|
|
1681
1695
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
@@ -1970,7 +1984,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1970
1984
|
case "json":
|
|
1971
1985
|
case "error-json":
|
|
1972
1986
|
default:
|
|
1973
|
-
contentValue =
|
|
1987
|
+
contentValue = stringifyWithBigIntAndCycles(output.value);
|
|
1974
1988
|
break;
|
|
1975
1989
|
}
|
|
1976
1990
|
const toolsetName = getAnthropicToolsetName({
|
|
@@ -2144,7 +2158,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2144
2158
|
type: "tool_use",
|
|
2145
2159
|
id: part.toolCallId,
|
|
2146
2160
|
name: part.toolName,
|
|
2147
|
-
input: part.input,
|
|
2161
|
+
input: parseToolCallInput(part.input),
|
|
2148
2162
|
cache_control: cacheControl
|
|
2149
2163
|
});
|
|
2150
2164
|
break;
|
|
@@ -2379,6 +2393,18 @@ function getAnthropicToolsetName({
|
|
|
2379
2393
|
const fromMetadata = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.toolsetName;
|
|
2380
2394
|
return typeof fromMetadata === "string" ? fromMetadata : void 0;
|
|
2381
2395
|
}
|
|
2396
|
+
function parseToolCallInput(input) {
|
|
2397
|
+
if (typeof input === "string") {
|
|
2398
|
+
try {
|
|
2399
|
+
const parsed = secureJsonParse(input);
|
|
2400
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
2401
|
+
return parsed;
|
|
2402
|
+
}
|
|
2403
|
+
} catch (e) {
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
return input;
|
|
2407
|
+
}
|
|
2382
2408
|
|
|
2383
2409
|
// src/map-anthropic-stop-reason.ts
|
|
2384
2410
|
function mapAnthropicStopReason({
|
|
@@ -2549,7 +2575,204 @@ function isPlainObject(value) {
|
|
|
2549
2575
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2550
2576
|
}
|
|
2551
2577
|
|
|
2578
|
+
// src/has-circular-schema-reference.ts
|
|
2579
|
+
var SCHEMA_MAP_KEYWORDS = /* @__PURE__ */ new Set([
|
|
2580
|
+
"dependentSchemas",
|
|
2581
|
+
"patternProperties",
|
|
2582
|
+
"properties"
|
|
2583
|
+
]);
|
|
2584
|
+
var DATA_KEYWORDS = /* @__PURE__ */ new Set(["const", "default", "enum", "examples"]);
|
|
2585
|
+
function hasCircularSchemaReference(schema) {
|
|
2586
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
2587
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2588
|
+
const visit = (pointer) => {
|
|
2589
|
+
if (visiting.has(pointer)) {
|
|
2590
|
+
return true;
|
|
2591
|
+
}
|
|
2592
|
+
if (visited.has(pointer)) {
|
|
2593
|
+
return false;
|
|
2594
|
+
}
|
|
2595
|
+
const target = resolveSchemaPointer(schema, pointer);
|
|
2596
|
+
if (target === void 0) {
|
|
2597
|
+
return false;
|
|
2598
|
+
}
|
|
2599
|
+
visiting.add(pointer);
|
|
2600
|
+
const isCircular = collectLocalRefs(target).some(visit);
|
|
2601
|
+
visiting.delete(pointer);
|
|
2602
|
+
visited.add(pointer);
|
|
2603
|
+
return isCircular;
|
|
2604
|
+
};
|
|
2605
|
+
return visit("#");
|
|
2606
|
+
}
|
|
2607
|
+
function collectLocalRefs(node, refs = []) {
|
|
2608
|
+
if (Array.isArray(node)) {
|
|
2609
|
+
for (const item of node) {
|
|
2610
|
+
collectLocalRefs(item, refs);
|
|
2611
|
+
}
|
|
2612
|
+
return refs;
|
|
2613
|
+
}
|
|
2614
|
+
if (!isRecord(node)) {
|
|
2615
|
+
return refs;
|
|
2616
|
+
}
|
|
2617
|
+
for (const [key, value] of Object.entries(node)) {
|
|
2618
|
+
if (key === "$ref") {
|
|
2619
|
+
if (typeof value === "string" && value.startsWith("#")) {
|
|
2620
|
+
refs.push(value);
|
|
2621
|
+
}
|
|
2622
|
+
} else if (SCHEMA_MAP_KEYWORDS.has(key) && isRecord(value)) {
|
|
2623
|
+
for (const subschema of Object.values(value)) {
|
|
2624
|
+
collectLocalRefs(subschema, refs);
|
|
2625
|
+
}
|
|
2626
|
+
} else if (
|
|
2627
|
+
// definitions are only reached through a `$ref`:
|
|
2628
|
+
key !== "$defs" && key !== "definitions" && !DATA_KEYWORDS.has(key)
|
|
2629
|
+
) {
|
|
2630
|
+
collectLocalRefs(value, refs);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
return refs;
|
|
2634
|
+
}
|
|
2635
|
+
function resolveSchemaPointer(schema, pointer) {
|
|
2636
|
+
if (pointer === "#") {
|
|
2637
|
+
return schema;
|
|
2638
|
+
}
|
|
2639
|
+
if (!pointer.startsWith("#/")) {
|
|
2640
|
+
return void 0;
|
|
2641
|
+
}
|
|
2642
|
+
let decodedPointer;
|
|
2643
|
+
try {
|
|
2644
|
+
decodedPointer = decodeURIComponent(pointer.slice(2));
|
|
2645
|
+
} catch (e) {
|
|
2646
|
+
return void 0;
|
|
2647
|
+
}
|
|
2648
|
+
let current = schema;
|
|
2649
|
+
for (const rawSegment of decodedPointer.split("/")) {
|
|
2650
|
+
const segment = rawSegment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
2651
|
+
if (Array.isArray(current)) {
|
|
2652
|
+
current = current[Number(segment)];
|
|
2653
|
+
} else if (isRecord(current)) {
|
|
2654
|
+
current = current[segment];
|
|
2655
|
+
} else {
|
|
2656
|
+
return void 0;
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
return current;
|
|
2660
|
+
}
|
|
2661
|
+
function isRecord(value) {
|
|
2662
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
// src/supports-native-structured-output-schema.ts
|
|
2666
|
+
var MAX_OPTIONAL_PROPERTIES = 10;
|
|
2667
|
+
var SUBSCHEMA_KEYWORDS = [
|
|
2668
|
+
"additionalProperties",
|
|
2669
|
+
"contains",
|
|
2670
|
+
"else",
|
|
2671
|
+
"if",
|
|
2672
|
+
"items",
|
|
2673
|
+
"not",
|
|
2674
|
+
"then"
|
|
2675
|
+
];
|
|
2676
|
+
var SUBSCHEMA_LIST_KEYWORDS = ["allOf", "anyOf", "oneOf", "prefixItems"];
|
|
2677
|
+
var SUBSCHEMA_MAP_KEYWORDS = [
|
|
2678
|
+
"dependentSchemas",
|
|
2679
|
+
"patternProperties",
|
|
2680
|
+
"properties"
|
|
2681
|
+
];
|
|
2682
|
+
function supportsNativeStructuredOutputSchema(schema) {
|
|
2683
|
+
if (schema.$ref != null || hasCircularSchemaReference(schema)) {
|
|
2684
|
+
return false;
|
|
2685
|
+
}
|
|
2686
|
+
const { optionalProperties, hasOpenObject } = getSchemaStats(
|
|
2687
|
+
schema,
|
|
2688
|
+
schema,
|
|
2689
|
+
/* @__PURE__ */ new Map()
|
|
2690
|
+
);
|
|
2691
|
+
return !hasOpenObject && optionalProperties <= MAX_OPTIONAL_PROPERTIES;
|
|
2692
|
+
}
|
|
2693
|
+
function getSchemaStats(node, root, refStats) {
|
|
2694
|
+
const stats = { optionalProperties: 0, hasOpenObject: false };
|
|
2695
|
+
if (!isRecord(node)) {
|
|
2696
|
+
return stats;
|
|
2697
|
+
}
|
|
2698
|
+
const add = (child) => {
|
|
2699
|
+
const childStats = getSchemaStats(child, root, refStats);
|
|
2700
|
+
stats.optionalProperties += childStats.optionalProperties;
|
|
2701
|
+
stats.hasOpenObject || (stats.hasOpenObject = childStats.hasOpenObject);
|
|
2702
|
+
};
|
|
2703
|
+
if (typeof node.$ref === "string" && node.$ref.startsWith("#")) {
|
|
2704
|
+
let resolved = refStats.get(node.$ref);
|
|
2705
|
+
if (resolved == null) {
|
|
2706
|
+
resolved = getSchemaStats(
|
|
2707
|
+
resolveSchemaPointer(root, node.$ref),
|
|
2708
|
+
root,
|
|
2709
|
+
refStats
|
|
2710
|
+
);
|
|
2711
|
+
refStats.set(node.$ref, resolved);
|
|
2712
|
+
}
|
|
2713
|
+
stats.optionalProperties += resolved.optionalProperties;
|
|
2714
|
+
stats.hasOpenObject || (stats.hasOpenObject = resolved.hasOpenObject);
|
|
2715
|
+
}
|
|
2716
|
+
if (isOpenObject(node)) {
|
|
2717
|
+
stats.hasOpenObject = true;
|
|
2718
|
+
}
|
|
2719
|
+
if (isRecord(node.properties)) {
|
|
2720
|
+
const required = new Set(Array.isArray(node.required) ? node.required : []);
|
|
2721
|
+
stats.optionalProperties += Object.keys(node.properties).filter(
|
|
2722
|
+
(name) => !required.has(name)
|
|
2723
|
+
).length;
|
|
2724
|
+
}
|
|
2725
|
+
for (const keyword of SUBSCHEMA_KEYWORDS) {
|
|
2726
|
+
const value = node[keyword];
|
|
2727
|
+
if (Array.isArray(value)) {
|
|
2728
|
+
value.forEach(add);
|
|
2729
|
+
} else {
|
|
2730
|
+
add(value);
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
for (const keyword of SUBSCHEMA_LIST_KEYWORDS) {
|
|
2734
|
+
const value = node[keyword];
|
|
2735
|
+
if (Array.isArray(value)) {
|
|
2736
|
+
value.forEach(add);
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
|
|
2740
|
+
const value = node[keyword];
|
|
2741
|
+
if (isRecord(value)) {
|
|
2742
|
+
Object.values(value).forEach(add);
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
return stats;
|
|
2746
|
+
}
|
|
2747
|
+
function isOpenObject(node) {
|
|
2748
|
+
const { additionalProperties, patternProperties, properties, type } = node;
|
|
2749
|
+
if (additionalProperties === true || isRecord(additionalProperties)) {
|
|
2750
|
+
return true;
|
|
2751
|
+
}
|
|
2752
|
+
if (isRecord(patternProperties) && Object.keys(patternProperties).length > 0) {
|
|
2753
|
+
return true;
|
|
2754
|
+
}
|
|
2755
|
+
const isObjectType = type === "object" || Array.isArray(type) && type.includes("object");
|
|
2756
|
+
return isObjectType && properties == null && additionalProperties !== false;
|
|
2757
|
+
}
|
|
2758
|
+
|
|
2552
2759
|
// src/anthropic-messages-language-model.ts
|
|
2760
|
+
function validateToolsetMember({
|
|
2761
|
+
toolsetName,
|
|
2762
|
+
memberName,
|
|
2763
|
+
tools
|
|
2764
|
+
}) {
|
|
2765
|
+
var _a, _b;
|
|
2766
|
+
const toolset = tools == null ? void 0 : tools.find(
|
|
2767
|
+
(tool) => "type" in tool && tool.type === "computer_toolset_20260801"
|
|
2768
|
+
);
|
|
2769
|
+
if (toolsetName !== "computer" || toolset == null || !computerToolset_20260801Members.some((member) => member === memberName) || ((_b = (_a = toolset.configs) == null ? void 0 : _a[memberName]) == null ? void 0 : _b.enabled) === false) {
|
|
2770
|
+
throw new InvalidResponseDataError({
|
|
2771
|
+
data: { toolsetName, memberName },
|
|
2772
|
+
message: `Received an unavailable toolset member: ${toolsetName}.${memberName}.`
|
|
2773
|
+
});
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2553
2776
|
function getAnthropicToolsetNames(tools) {
|
|
2554
2777
|
const toolsetNames = {};
|
|
2555
2778
|
for (const tool of tools != null ? tools : []) {
|
|
@@ -2564,8 +2787,8 @@ function toToolsetMemberInput({
|
|
|
2564
2787
|
input
|
|
2565
2788
|
}) {
|
|
2566
2789
|
return {
|
|
2567
|
-
|
|
2568
|
-
|
|
2790
|
+
...typeof input === "object" && input !== null && !Array.isArray(input) ? input : {},
|
|
2791
|
+
action: memberName
|
|
2569
2792
|
};
|
|
2570
2793
|
}
|
|
2571
2794
|
function getJsonResponseToolName(tools) {
|
|
@@ -2606,6 +2829,31 @@ function createCitationSource(citation, citationDocuments, generateId3) {
|
|
|
2606
2829
|
}
|
|
2607
2830
|
};
|
|
2608
2831
|
}
|
|
2832
|
+
var TEXT_OR_THINKING_BLOCK_TYPES = /* @__PURE__ */ new Set([
|
|
2833
|
+
"redacted_thinking",
|
|
2834
|
+
"text",
|
|
2835
|
+
"thinking"
|
|
2836
|
+
]);
|
|
2837
|
+
function isContinuationStopReason(stopReason) {
|
|
2838
|
+
return stopReason === "pause_turn" || stopReason === "tool_use";
|
|
2839
|
+
}
|
|
2840
|
+
function getJsonResponseToolFallbackText(content, stopReason, jsonResponseToolName) {
|
|
2841
|
+
const text = /* @__PURE__ */ new Set();
|
|
2842
|
+
if (isContinuationStopReason(stopReason)) {
|
|
2843
|
+
return text;
|
|
2844
|
+
}
|
|
2845
|
+
for (const part of content) {
|
|
2846
|
+
if (part.type === "tool_use" && part.name === jsonResponseToolName) {
|
|
2847
|
+
return /* @__PURE__ */ new Set();
|
|
2848
|
+
}
|
|
2849
|
+
if (part.type === "text") {
|
|
2850
|
+
text.add(part);
|
|
2851
|
+
} else if (!TEXT_OR_THINKING_BLOCK_TYPES.has(part.type)) {
|
|
2852
|
+
text.clear();
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
return text;
|
|
2856
|
+
}
|
|
2609
2857
|
var AnthropicMessagesLanguageModel = class {
|
|
2610
2858
|
constructor(modelId, config) {
|
|
2611
2859
|
this.specificationVersion = "v2";
|
|
@@ -2733,9 +2981,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2733
2981
|
}
|
|
2734
2982
|
}
|
|
2735
2983
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
2984
|
+
const supportsResponseSchema = (responseFormat == null ? void 0 : responseFormat.type) !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
|
|
2736
2985
|
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") || this.modelId.includes("claude-opus-5-5") || this.modelId.includes("claude-sonnet-5-5") ? "auto" : "jsonTool";
|
|
2737
|
-
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
2738
|
-
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
2986
|
+
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
|
|
2987
|
+
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && supportsResponseSchema) {
|
|
2739
2988
|
warnings.push({
|
|
2740
2989
|
type: "unsupported-setting",
|
|
2741
2990
|
setting: "providerOptions.anthropic.structuredOutputMode",
|
|
@@ -3044,8 +3293,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3044
3293
|
betas: toolsBetas
|
|
3045
3294
|
} = await prepareTools(
|
|
3046
3295
|
jsonResponseTool != null ? {
|
|
3047
|
-
tools: [
|
|
3048
|
-
|
|
3296
|
+
tools: [
|
|
3297
|
+
...(tools != null ? tools : []).filter(
|
|
3298
|
+
(tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
|
|
3299
|
+
),
|
|
3300
|
+
jsonResponseTool
|
|
3301
|
+
],
|
|
3302
|
+
toolChoice: rejectsForcedToolUse ? { type: "auto" } : tools != null && tools.length > 0 ? { type: "required" } : { type: "tool", toolName: jsonResponseTool.name },
|
|
3049
3303
|
disableParallelToolUse: true,
|
|
3050
3304
|
cacheControlValidator,
|
|
3051
3305
|
rejectsForcedToolUse
|
|
@@ -3151,10 +3405,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3151
3405
|
});
|
|
3152
3406
|
const content = [];
|
|
3153
3407
|
let isJsonResponseFromTool = false;
|
|
3408
|
+
const jsonResponseToolFallbackText = jsonResponseToolName != null ? getJsonResponseToolFallbackText(
|
|
3409
|
+
response.content,
|
|
3410
|
+
response.stop_reason,
|
|
3411
|
+
jsonResponseToolName
|
|
3412
|
+
) : void 0;
|
|
3154
3413
|
for (const part of response.content) {
|
|
3155
3414
|
switch (part.type) {
|
|
3156
3415
|
case "text": {
|
|
3157
|
-
if (
|
|
3416
|
+
if (jsonResponseToolFallbackText == null || jsonResponseToolFallbackText.has(part)) {
|
|
3158
3417
|
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
3159
3418
|
(citation) => citation.type === "web_search_result_location"
|
|
3160
3419
|
);
|
|
@@ -3229,6 +3488,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3229
3488
|
text: JSON.stringify(part.input)
|
|
3230
3489
|
});
|
|
3231
3490
|
} else if (part.toolset_name != null) {
|
|
3491
|
+
validateToolsetMember({
|
|
3492
|
+
toolsetName: part.toolset_name,
|
|
3493
|
+
memberName: part.name,
|
|
3494
|
+
tools: args.tools
|
|
3495
|
+
});
|
|
3232
3496
|
content.push({
|
|
3233
3497
|
type: "tool-call",
|
|
3234
3498
|
toolCallId: part.id,
|
|
@@ -3533,6 +3797,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3533
3797
|
let iterations = null;
|
|
3534
3798
|
let contextManagement = null;
|
|
3535
3799
|
let isJsonResponseFromTool = false;
|
|
3800
|
+
let rawStopReason;
|
|
3801
|
+
const heldBackText = [];
|
|
3802
|
+
const heldBackTextByIndex = /* @__PURE__ */ new Map();
|
|
3803
|
+
const createTextEnd = (id, citations) => ({
|
|
3804
|
+
type: "text-end",
|
|
3805
|
+
id,
|
|
3806
|
+
...citations.length > 0 && {
|
|
3807
|
+
providerMetadata: { anthropic: { citations } }
|
|
3808
|
+
}
|
|
3809
|
+
});
|
|
3536
3810
|
let isMessageOpen = false;
|
|
3537
3811
|
let activeMessageId;
|
|
3538
3812
|
let hasInvalidMessageSequence = false;
|
|
@@ -3544,7 +3818,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3544
3818
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3545
3819
|
},
|
|
3546
3820
|
transform(chunk, controller) {
|
|
3547
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3821
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3548
3822
|
if (hasInvalidMessageSequence) {
|
|
3549
3823
|
return;
|
|
3550
3824
|
}
|
|
@@ -3566,8 +3840,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3566
3840
|
return;
|
|
3567
3841
|
}
|
|
3568
3842
|
blockType = contentBlockType;
|
|
3843
|
+
if (!TEXT_OR_THINKING_BLOCK_TYPES.has(contentBlockType)) {
|
|
3844
|
+
heldBackText.length = 0;
|
|
3845
|
+
}
|
|
3569
3846
|
switch (contentBlockType) {
|
|
3570
3847
|
case "text": {
|
|
3848
|
+
if (jsonResponseToolName != null) {
|
|
3849
|
+
const entry = {
|
|
3850
|
+
id: String(value.index),
|
|
3851
|
+
text: "",
|
|
3852
|
+
citations: []
|
|
3853
|
+
};
|
|
3854
|
+
heldBackText.push(entry);
|
|
3855
|
+
heldBackTextByIndex.set(value.index, entry);
|
|
3856
|
+
return;
|
|
3857
|
+
}
|
|
3571
3858
|
contentBlocks[value.index] = {
|
|
3572
3859
|
type: "text",
|
|
3573
3860
|
citations: []
|
|
@@ -3628,6 +3915,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3628
3915
|
id: String(value.index)
|
|
3629
3916
|
});
|
|
3630
3917
|
} else if (value.content_block.toolset_name != null) {
|
|
3918
|
+
validateToolsetMember({
|
|
3919
|
+
toolsetName: value.content_block.toolset_name,
|
|
3920
|
+
memberName: value.content_block.name,
|
|
3921
|
+
tools: args.tools
|
|
3922
|
+
});
|
|
3631
3923
|
contentBlocks[value.index] = {
|
|
3632
3924
|
type: "tool-call",
|
|
3633
3925
|
toolCallId: value.content_block.id,
|
|
@@ -3857,11 +4149,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3857
4149
|
if (contentBlock.toolset != null) {
|
|
3858
4150
|
let memberInput = {};
|
|
3859
4151
|
try {
|
|
3860
|
-
memberInput = contentBlock.input === "" ? {} :
|
|
4152
|
+
memberInput = contentBlock.input === "" ? {} : secureJsonParse2(contentBlock.input);
|
|
3861
4153
|
} catch (e) {
|
|
3862
|
-
|
|
4154
|
+
throw new InvalidResponseDataError({
|
|
4155
|
+
data: contentBlock.input,
|
|
4156
|
+
message: "Invalid toolset member input JSON."
|
|
4157
|
+
});
|
|
3863
4158
|
}
|
|
3864
|
-
contentBlock.input =
|
|
4159
|
+
contentBlock.input = JSON.stringify(
|
|
3865
4160
|
toToolsetMemberInput({
|
|
3866
4161
|
memberName: contentBlock.toolset.memberName,
|
|
3867
4162
|
input: memberInput
|
|
@@ -3903,6 +4198,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3903
4198
|
switch (deltaType) {
|
|
3904
4199
|
case "text_delta": {
|
|
3905
4200
|
if (jsonResponseToolName != null) {
|
|
4201
|
+
const entry = heldBackTextByIndex.get(value.index);
|
|
4202
|
+
if (entry != null) entry.text += value.delta.text;
|
|
3906
4203
|
return;
|
|
3907
4204
|
}
|
|
3908
4205
|
controller.enqueue({
|
|
@@ -3981,8 +4278,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3981
4278
|
case "citations_delta": {
|
|
3982
4279
|
const citation = value.delta.citation;
|
|
3983
4280
|
const contentBlock = contentBlocks[value.index];
|
|
3984
|
-
if (
|
|
3985
|
-
contentBlock.
|
|
4281
|
+
if (citation.type === "web_search_result_location") {
|
|
4282
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text")
|
|
4283
|
+
contentBlock.citations.push(citation);
|
|
4284
|
+
(_b2 = heldBackTextByIndex.get(value.index)) == null ? void 0 : _b2.citations.push(citation);
|
|
3986
4285
|
}
|
|
3987
4286
|
const source = createCitationSource(
|
|
3988
4287
|
citation,
|
|
@@ -4019,16 +4318,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4019
4318
|
}
|
|
4020
4319
|
isMessageOpen = true;
|
|
4021
4320
|
activeMessageId = value.message.id;
|
|
4321
|
+
heldBackTextByIndex.clear();
|
|
4022
4322
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
4023
|
-
usage.cachedInputTokens = (
|
|
4323
|
+
usage.cachedInputTokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : void 0;
|
|
4024
4324
|
rawUsage = {
|
|
4025
4325
|
...value.message.usage
|
|
4026
4326
|
};
|
|
4027
|
-
cacheCreationInputTokens = (
|
|
4327
|
+
cacheCreationInputTokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
|
|
4028
4328
|
controller.enqueue({
|
|
4029
4329
|
type: "response-metadata",
|
|
4030
|
-
id: (
|
|
4031
|
-
modelId: (
|
|
4330
|
+
id: (_e = value.message.id) != null ? _e : void 0,
|
|
4331
|
+
modelId: (_f = value.message.model) != null ? _f : void 0
|
|
4032
4332
|
});
|
|
4033
4333
|
return;
|
|
4034
4334
|
}
|
|
@@ -4042,7 +4342,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4042
4342
|
if (value.usage.iterations != null) {
|
|
4043
4343
|
iterations = value.usage.iterations;
|
|
4044
4344
|
}
|
|
4045
|
-
const servedByFallback = (
|
|
4345
|
+
const servedByFallback = (_g = value.usage.iterations) == null ? void 0 : _g.some(
|
|
4046
4346
|
(iter) => iter.type === "fallback_message"
|
|
4047
4347
|
);
|
|
4048
4348
|
if (value.usage.iterations && value.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -4061,21 +4361,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4061
4361
|
}
|
|
4062
4362
|
usage.outputTokens = value.usage.output_tokens;
|
|
4063
4363
|
}
|
|
4064
|
-
usage.totalTokens = ((
|
|
4364
|
+
usage.totalTokens = ((_h = usage.inputTokens) != null ? _h : 0) + ((_i = usage.outputTokens) != null ? _i : 0);
|
|
4365
|
+
rawStopReason = value.delta.stop_reason;
|
|
4065
4366
|
finishReason = mapAnthropicStopReason({
|
|
4066
4367
|
finishReason: value.delta.stop_reason,
|
|
4067
4368
|
isJsonResponseFromTool
|
|
4068
4369
|
});
|
|
4069
4370
|
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
4070
|
-
stopSequence = (
|
|
4371
|
+
stopSequence = (_j = value.delta.stop_sequence) != null ? _j : null;
|
|
4071
4372
|
container = value.delta.container != null ? {
|
|
4072
4373
|
expiresAt: value.delta.container.expires_at,
|
|
4073
4374
|
id: value.delta.container.id,
|
|
4074
|
-
skills: (
|
|
4375
|
+
skills: (_l = (_k = value.delta.container.skills) == null ? void 0 : _k.map((skill) => ({
|
|
4075
4376
|
type: skill.type,
|
|
4076
4377
|
skillId: skill.skill_id,
|
|
4077
4378
|
version: skill.version
|
|
4078
|
-
}))) != null ?
|
|
4379
|
+
}))) != null ? _l : null
|
|
4079
4380
|
} : null;
|
|
4080
4381
|
if (value.context_management != null) {
|
|
4081
4382
|
contextManagement = {
|
|
@@ -4113,6 +4414,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4113
4414
|
case "message_stop": {
|
|
4114
4415
|
isMessageOpen = false;
|
|
4115
4416
|
activeMessageId = void 0;
|
|
4417
|
+
if (!isJsonResponseFromTool && !isContinuationStopReason(rawStopReason)) {
|
|
4418
|
+
for (const { id, text, citations } of heldBackText) {
|
|
4419
|
+
if (text.length === 0) continue;
|
|
4420
|
+
controller.enqueue({ type: "text-start", id });
|
|
4421
|
+
controller.enqueue({ type: "text-delta", id, delta: text });
|
|
4422
|
+
controller.enqueue(createTextEnd(id, citations));
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
heldBackText.length = 0;
|
|
4116
4426
|
controller.enqueue({
|
|
4117
4427
|
type: "finish",
|
|
4118
4428
|
finishReason,
|
|
@@ -4528,14 +4838,14 @@ var codeExecution_20260120InputSchema = lazySchema12(
|
|
|
4528
4838
|
])
|
|
4529
4839
|
)
|
|
4530
4840
|
);
|
|
4531
|
-
var
|
|
4841
|
+
var factory7 = createProviderDefinedToolFactoryWithOutputSchema5({
|
|
4532
4842
|
id: "anthropic.code_execution_20260120",
|
|
4533
4843
|
name: "code_execution",
|
|
4534
4844
|
inputSchema: codeExecution_20260120InputSchema,
|
|
4535
4845
|
outputSchema: codeExecution_20260120OutputSchema
|
|
4536
4846
|
});
|
|
4537
4847
|
var codeExecution_20260120 = (args = {}) => {
|
|
4538
|
-
return
|
|
4848
|
+
return factory7(args);
|
|
4539
4849
|
};
|
|
4540
4850
|
|
|
4541
4851
|
// src/tool/computer_20241022.ts
|