@ai-sdk/anthropic 2.0.110 → 2.0.112
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 +22 -0
- package/dist/index.js +287 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +289 -20
- 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 +290 -21
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +290 -20
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -813,4 +813,15 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
|
|
|
813
813
|
*/
|
|
814
814
|
declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
|
|
815
815
|
|
|
816
|
-
|
|
816
|
+
/**
|
|
817
|
+
* Whether Anthropic's native structured outputs (`output_config.format`) can
|
|
818
|
+
* represent a schema without rejecting it or losing data.
|
|
819
|
+
*
|
|
820
|
+
* Rejected: self-referencing schemas, and schemas with too many optional
|
|
821
|
+
* properties. Lossy: open objects (maps, free-form objects), which native
|
|
822
|
+
* structured outputs close with `additionalProperties: false`, so the model
|
|
823
|
+
* can only return `{}` for them.
|
|
824
|
+
*/
|
|
825
|
+
declare function supportsNativeStructuredOutputSchema(schema: JSONSchema7): boolean;
|
|
826
|
+
|
|
827
|
+
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -813,4 +813,15 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
|
|
|
813
813
|
*/
|
|
814
814
|
declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
|
|
815
815
|
|
|
816
|
-
|
|
816
|
+
/**
|
|
817
|
+
* Whether Anthropic's native structured outputs (`output_config.format`) can
|
|
818
|
+
* represent a schema without rejecting it or losing data.
|
|
819
|
+
*
|
|
820
|
+
* Rejected: self-referencing schemas, and schemas with too many optional
|
|
821
|
+
* properties. Lossy: open objects (maps, free-form objects), which native
|
|
822
|
+
* structured outputs close with `additionalProperties: false`, so the model
|
|
823
|
+
* can only return `{}` for them.
|
|
824
|
+
*/
|
|
825
|
+
declare function supportsNativeStructuredOutputSchema(schema: JSONSchema7): boolean;
|
|
826
|
+
|
|
827
|
+
export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
|
package/dist/internal/index.js
CHANGED
|
@@ -24,7 +24,8 @@ __export(index_exports, {
|
|
|
24
24
|
anthropicTools: () => anthropicTools,
|
|
25
25
|
getModelCapabilities: () => getModelCapabilities,
|
|
26
26
|
prepareTools: () => prepareTools,
|
|
27
|
-
sanitizeJsonSchema: () => sanitizeJsonSchema
|
|
27
|
+
sanitizeJsonSchema: () => sanitizeJsonSchema,
|
|
28
|
+
supportsNativeStructuredOutputSchema: () => supportsNativeStructuredOutputSchema
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(index_exports);
|
|
30
31
|
|
|
@@ -1932,7 +1933,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1932
1933
|
case "json":
|
|
1933
1934
|
case "error-json":
|
|
1934
1935
|
default:
|
|
1935
|
-
contentValue =
|
|
1936
|
+
contentValue = (0, import_provider_utils11.stringifyWithBigIntAndCycles)(output.value);
|
|
1936
1937
|
break;
|
|
1937
1938
|
}
|
|
1938
1939
|
const toolsetName = getAnthropicToolsetName({
|
|
@@ -2106,7 +2107,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2106
2107
|
type: "tool_use",
|
|
2107
2108
|
id: part.toolCallId,
|
|
2108
2109
|
name: part.toolName,
|
|
2109
|
-
input: part.input,
|
|
2110
|
+
input: parseToolCallInput(part.input),
|
|
2110
2111
|
cache_control: cacheControl
|
|
2111
2112
|
});
|
|
2112
2113
|
break;
|
|
@@ -2341,6 +2342,18 @@ function getAnthropicToolsetName({
|
|
|
2341
2342
|
const fromMetadata = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.toolsetName;
|
|
2342
2343
|
return typeof fromMetadata === "string" ? fromMetadata : void 0;
|
|
2343
2344
|
}
|
|
2345
|
+
function parseToolCallInput(input) {
|
|
2346
|
+
if (typeof input === "string") {
|
|
2347
|
+
try {
|
|
2348
|
+
const parsed = (0, import_provider_utils11.secureJsonParse)(input);
|
|
2349
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
2350
|
+
return parsed;
|
|
2351
|
+
}
|
|
2352
|
+
} catch (e) {
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
return input;
|
|
2356
|
+
}
|
|
2344
2357
|
|
|
2345
2358
|
// src/map-anthropic-stop-reason.ts
|
|
2346
2359
|
function mapAnthropicStopReason({
|
|
@@ -2511,6 +2524,187 @@ function isPlainObject(value) {
|
|
|
2511
2524
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2512
2525
|
}
|
|
2513
2526
|
|
|
2527
|
+
// src/has-circular-schema-reference.ts
|
|
2528
|
+
var SCHEMA_MAP_KEYWORDS = /* @__PURE__ */ new Set([
|
|
2529
|
+
"dependentSchemas",
|
|
2530
|
+
"patternProperties",
|
|
2531
|
+
"properties"
|
|
2532
|
+
]);
|
|
2533
|
+
var DATA_KEYWORDS = /* @__PURE__ */ new Set(["const", "default", "enum", "examples"]);
|
|
2534
|
+
function hasCircularSchemaReference(schema) {
|
|
2535
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
2536
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2537
|
+
const visit = (pointer) => {
|
|
2538
|
+
if (visiting.has(pointer)) {
|
|
2539
|
+
return true;
|
|
2540
|
+
}
|
|
2541
|
+
if (visited.has(pointer)) {
|
|
2542
|
+
return false;
|
|
2543
|
+
}
|
|
2544
|
+
const target = resolveSchemaPointer(schema, pointer);
|
|
2545
|
+
if (target === void 0) {
|
|
2546
|
+
return false;
|
|
2547
|
+
}
|
|
2548
|
+
visiting.add(pointer);
|
|
2549
|
+
const isCircular = collectLocalRefs(target).some(visit);
|
|
2550
|
+
visiting.delete(pointer);
|
|
2551
|
+
visited.add(pointer);
|
|
2552
|
+
return isCircular;
|
|
2553
|
+
};
|
|
2554
|
+
return visit("#");
|
|
2555
|
+
}
|
|
2556
|
+
function collectLocalRefs(node, refs = []) {
|
|
2557
|
+
if (Array.isArray(node)) {
|
|
2558
|
+
for (const item of node) {
|
|
2559
|
+
collectLocalRefs(item, refs);
|
|
2560
|
+
}
|
|
2561
|
+
return refs;
|
|
2562
|
+
}
|
|
2563
|
+
if (!isRecord(node)) {
|
|
2564
|
+
return refs;
|
|
2565
|
+
}
|
|
2566
|
+
for (const [key, value] of Object.entries(node)) {
|
|
2567
|
+
if (key === "$ref") {
|
|
2568
|
+
if (typeof value === "string" && value.startsWith("#")) {
|
|
2569
|
+
refs.push(value);
|
|
2570
|
+
}
|
|
2571
|
+
} else if (SCHEMA_MAP_KEYWORDS.has(key) && isRecord(value)) {
|
|
2572
|
+
for (const subschema of Object.values(value)) {
|
|
2573
|
+
collectLocalRefs(subschema, refs);
|
|
2574
|
+
}
|
|
2575
|
+
} else if (
|
|
2576
|
+
// definitions are only reached through a `$ref`:
|
|
2577
|
+
key !== "$defs" && key !== "definitions" && !DATA_KEYWORDS.has(key)
|
|
2578
|
+
) {
|
|
2579
|
+
collectLocalRefs(value, refs);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
return refs;
|
|
2583
|
+
}
|
|
2584
|
+
function resolveSchemaPointer(schema, pointer) {
|
|
2585
|
+
if (pointer === "#") {
|
|
2586
|
+
return schema;
|
|
2587
|
+
}
|
|
2588
|
+
if (!pointer.startsWith("#/")) {
|
|
2589
|
+
return void 0;
|
|
2590
|
+
}
|
|
2591
|
+
let decodedPointer;
|
|
2592
|
+
try {
|
|
2593
|
+
decodedPointer = decodeURIComponent(pointer.slice(2));
|
|
2594
|
+
} catch (e) {
|
|
2595
|
+
return void 0;
|
|
2596
|
+
}
|
|
2597
|
+
let current = schema;
|
|
2598
|
+
for (const rawSegment of decodedPointer.split("/")) {
|
|
2599
|
+
const segment = rawSegment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
2600
|
+
if (Array.isArray(current)) {
|
|
2601
|
+
current = current[Number(segment)];
|
|
2602
|
+
} else if (isRecord(current)) {
|
|
2603
|
+
current = current[segment];
|
|
2604
|
+
} else {
|
|
2605
|
+
return void 0;
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
return current;
|
|
2609
|
+
}
|
|
2610
|
+
function isRecord(value) {
|
|
2611
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
// src/supports-native-structured-output-schema.ts
|
|
2615
|
+
var MAX_OPTIONAL_PROPERTIES = 10;
|
|
2616
|
+
var SUBSCHEMA_KEYWORDS = [
|
|
2617
|
+
"additionalProperties",
|
|
2618
|
+
"contains",
|
|
2619
|
+
"else",
|
|
2620
|
+
"if",
|
|
2621
|
+
"items",
|
|
2622
|
+
"not",
|
|
2623
|
+
"then"
|
|
2624
|
+
];
|
|
2625
|
+
var SUBSCHEMA_LIST_KEYWORDS = ["allOf", "anyOf", "oneOf", "prefixItems"];
|
|
2626
|
+
var SUBSCHEMA_MAP_KEYWORDS = [
|
|
2627
|
+
"dependentSchemas",
|
|
2628
|
+
"patternProperties",
|
|
2629
|
+
"properties"
|
|
2630
|
+
];
|
|
2631
|
+
function supportsNativeStructuredOutputSchema(schema) {
|
|
2632
|
+
if (schema.$ref != null || hasCircularSchemaReference(schema)) {
|
|
2633
|
+
return false;
|
|
2634
|
+
}
|
|
2635
|
+
const { optionalProperties, hasOpenObject } = getSchemaStats(
|
|
2636
|
+
schema,
|
|
2637
|
+
schema,
|
|
2638
|
+
/* @__PURE__ */ new Map()
|
|
2639
|
+
);
|
|
2640
|
+
return !hasOpenObject && optionalProperties <= MAX_OPTIONAL_PROPERTIES;
|
|
2641
|
+
}
|
|
2642
|
+
function getSchemaStats(node, root, refStats) {
|
|
2643
|
+
const stats = { optionalProperties: 0, hasOpenObject: false };
|
|
2644
|
+
if (!isRecord(node)) {
|
|
2645
|
+
return stats;
|
|
2646
|
+
}
|
|
2647
|
+
const add = (child) => {
|
|
2648
|
+
const childStats = getSchemaStats(child, root, refStats);
|
|
2649
|
+
stats.optionalProperties += childStats.optionalProperties;
|
|
2650
|
+
stats.hasOpenObject || (stats.hasOpenObject = childStats.hasOpenObject);
|
|
2651
|
+
};
|
|
2652
|
+
if (typeof node.$ref === "string" && node.$ref.startsWith("#")) {
|
|
2653
|
+
let resolved = refStats.get(node.$ref);
|
|
2654
|
+
if (resolved == null) {
|
|
2655
|
+
resolved = getSchemaStats(
|
|
2656
|
+
resolveSchemaPointer(root, node.$ref),
|
|
2657
|
+
root,
|
|
2658
|
+
refStats
|
|
2659
|
+
);
|
|
2660
|
+
refStats.set(node.$ref, resolved);
|
|
2661
|
+
}
|
|
2662
|
+
stats.optionalProperties += resolved.optionalProperties;
|
|
2663
|
+
stats.hasOpenObject || (stats.hasOpenObject = resolved.hasOpenObject);
|
|
2664
|
+
}
|
|
2665
|
+
if (isOpenObject(node)) {
|
|
2666
|
+
stats.hasOpenObject = true;
|
|
2667
|
+
}
|
|
2668
|
+
if (isRecord(node.properties)) {
|
|
2669
|
+
const required = new Set(Array.isArray(node.required) ? node.required : []);
|
|
2670
|
+
stats.optionalProperties += Object.keys(node.properties).filter(
|
|
2671
|
+
(name) => !required.has(name)
|
|
2672
|
+
).length;
|
|
2673
|
+
}
|
|
2674
|
+
for (const keyword of SUBSCHEMA_KEYWORDS) {
|
|
2675
|
+
const value = node[keyword];
|
|
2676
|
+
if (Array.isArray(value)) {
|
|
2677
|
+
value.forEach(add);
|
|
2678
|
+
} else {
|
|
2679
|
+
add(value);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
for (const keyword of SUBSCHEMA_LIST_KEYWORDS) {
|
|
2683
|
+
const value = node[keyword];
|
|
2684
|
+
if (Array.isArray(value)) {
|
|
2685
|
+
value.forEach(add);
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
|
|
2689
|
+
const value = node[keyword];
|
|
2690
|
+
if (isRecord(value)) {
|
|
2691
|
+
Object.values(value).forEach(add);
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
return stats;
|
|
2695
|
+
}
|
|
2696
|
+
function isOpenObject(node) {
|
|
2697
|
+
const { additionalProperties, patternProperties, properties, type } = node;
|
|
2698
|
+
if (additionalProperties === true || isRecord(additionalProperties)) {
|
|
2699
|
+
return true;
|
|
2700
|
+
}
|
|
2701
|
+
if (isRecord(patternProperties) && Object.keys(patternProperties).length > 0) {
|
|
2702
|
+
return true;
|
|
2703
|
+
}
|
|
2704
|
+
const isObjectType = type === "object" || Array.isArray(type) && type.includes("object");
|
|
2705
|
+
return isObjectType && properties == null && additionalProperties !== false;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2514
2708
|
// src/anthropic-messages-language-model.ts
|
|
2515
2709
|
function getAnthropicToolsetNames(tools) {
|
|
2516
2710
|
const toolsetNames = {};
|
|
@@ -2568,6 +2762,31 @@ function createCitationSource(citation, citationDocuments, generateId2) {
|
|
|
2568
2762
|
}
|
|
2569
2763
|
};
|
|
2570
2764
|
}
|
|
2765
|
+
var TEXT_OR_THINKING_BLOCK_TYPES = /* @__PURE__ */ new Set([
|
|
2766
|
+
"redacted_thinking",
|
|
2767
|
+
"text",
|
|
2768
|
+
"thinking"
|
|
2769
|
+
]);
|
|
2770
|
+
function isContinuationStopReason(stopReason) {
|
|
2771
|
+
return stopReason === "pause_turn" || stopReason === "tool_use";
|
|
2772
|
+
}
|
|
2773
|
+
function getJsonResponseToolFallbackText(content, stopReason, jsonResponseToolName) {
|
|
2774
|
+
const text = /* @__PURE__ */ new Set();
|
|
2775
|
+
if (isContinuationStopReason(stopReason)) {
|
|
2776
|
+
return text;
|
|
2777
|
+
}
|
|
2778
|
+
for (const part of content) {
|
|
2779
|
+
if (part.type === "tool_use" && part.name === jsonResponseToolName) {
|
|
2780
|
+
return /* @__PURE__ */ new Set();
|
|
2781
|
+
}
|
|
2782
|
+
if (part.type === "text") {
|
|
2783
|
+
text.add(part);
|
|
2784
|
+
} else if (!TEXT_OR_THINKING_BLOCK_TYPES.has(part.type)) {
|
|
2785
|
+
text.clear();
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
return text;
|
|
2789
|
+
}
|
|
2571
2790
|
var AnthropicMessagesLanguageModel = class {
|
|
2572
2791
|
constructor(modelId, config) {
|
|
2573
2792
|
this.specificationVersion = "v2";
|
|
@@ -2695,9 +2914,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2695
2914
|
}
|
|
2696
2915
|
}
|
|
2697
2916
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
2917
|
+
const supportsResponseSchema = (responseFormat == null ? void 0 : responseFormat.type) !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
|
|
2698
2918
|
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";
|
|
2699
|
-
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
2700
|
-
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
2919
|
+
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
|
|
2920
|
+
if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && supportsResponseSchema) {
|
|
2701
2921
|
warnings.push({
|
|
2702
2922
|
type: "unsupported-setting",
|
|
2703
2923
|
setting: "providerOptions.anthropic.structuredOutputMode",
|
|
@@ -3006,8 +3226,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3006
3226
|
betas: toolsBetas
|
|
3007
3227
|
} = await prepareTools(
|
|
3008
3228
|
jsonResponseTool != null ? {
|
|
3009
|
-
tools: [
|
|
3010
|
-
|
|
3229
|
+
tools: [
|
|
3230
|
+
...(tools != null ? tools : []).filter(
|
|
3231
|
+
(tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
|
|
3232
|
+
),
|
|
3233
|
+
jsonResponseTool
|
|
3234
|
+
],
|
|
3235
|
+
toolChoice: rejectsForcedToolUse ? { type: "auto" } : tools != null && tools.length > 0 ? { type: "required" } : { type: "tool", toolName: jsonResponseTool.name },
|
|
3011
3236
|
disableParallelToolUse: true,
|
|
3012
3237
|
cacheControlValidator,
|
|
3013
3238
|
rejectsForcedToolUse
|
|
@@ -3113,10 +3338,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3113
3338
|
});
|
|
3114
3339
|
const content = [];
|
|
3115
3340
|
let isJsonResponseFromTool = false;
|
|
3341
|
+
const jsonResponseToolFallbackText = jsonResponseToolName != null ? getJsonResponseToolFallbackText(
|
|
3342
|
+
response.content,
|
|
3343
|
+
response.stop_reason,
|
|
3344
|
+
jsonResponseToolName
|
|
3345
|
+
) : void 0;
|
|
3116
3346
|
for (const part of response.content) {
|
|
3117
3347
|
switch (part.type) {
|
|
3118
3348
|
case "text": {
|
|
3119
|
-
if (
|
|
3349
|
+
if (jsonResponseToolFallbackText == null || jsonResponseToolFallbackText.has(part)) {
|
|
3120
3350
|
const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
|
|
3121
3351
|
(citation) => citation.type === "web_search_result_location"
|
|
3122
3352
|
);
|
|
@@ -3495,6 +3725,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3495
3725
|
let iterations = null;
|
|
3496
3726
|
let contextManagement = null;
|
|
3497
3727
|
let isJsonResponseFromTool = false;
|
|
3728
|
+
let rawStopReason;
|
|
3729
|
+
const heldBackText = [];
|
|
3730
|
+
const heldBackTextByIndex = /* @__PURE__ */ new Map();
|
|
3731
|
+
const createTextEnd = (id, citations) => ({
|
|
3732
|
+
type: "text-end",
|
|
3733
|
+
id,
|
|
3734
|
+
...citations.length > 0 && {
|
|
3735
|
+
providerMetadata: { anthropic: { citations } }
|
|
3736
|
+
}
|
|
3737
|
+
});
|
|
3498
3738
|
let isMessageOpen = false;
|
|
3499
3739
|
let activeMessageId;
|
|
3500
3740
|
let hasInvalidMessageSequence = false;
|
|
@@ -3506,7 +3746,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3506
3746
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3507
3747
|
},
|
|
3508
3748
|
transform(chunk, controller) {
|
|
3509
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3749
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3510
3750
|
if (hasInvalidMessageSequence) {
|
|
3511
3751
|
return;
|
|
3512
3752
|
}
|
|
@@ -3528,8 +3768,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3528
3768
|
return;
|
|
3529
3769
|
}
|
|
3530
3770
|
blockType = contentBlockType;
|
|
3771
|
+
if (!TEXT_OR_THINKING_BLOCK_TYPES.has(contentBlockType)) {
|
|
3772
|
+
heldBackText.length = 0;
|
|
3773
|
+
}
|
|
3531
3774
|
switch (contentBlockType) {
|
|
3532
3775
|
case "text": {
|
|
3776
|
+
if (jsonResponseToolName != null) {
|
|
3777
|
+
const entry = {
|
|
3778
|
+
id: String(value.index),
|
|
3779
|
+
text: "",
|
|
3780
|
+
citations: []
|
|
3781
|
+
};
|
|
3782
|
+
heldBackText.push(entry);
|
|
3783
|
+
heldBackTextByIndex.set(value.index, entry);
|
|
3784
|
+
return;
|
|
3785
|
+
}
|
|
3533
3786
|
contentBlocks[value.index] = {
|
|
3534
3787
|
type: "text",
|
|
3535
3788
|
citations: []
|
|
@@ -3865,6 +4118,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3865
4118
|
switch (deltaType) {
|
|
3866
4119
|
case "text_delta": {
|
|
3867
4120
|
if (jsonResponseToolName != null) {
|
|
4121
|
+
const entry = heldBackTextByIndex.get(value.index);
|
|
4122
|
+
if (entry != null) entry.text += value.delta.text;
|
|
3868
4123
|
return;
|
|
3869
4124
|
}
|
|
3870
4125
|
controller.enqueue({
|
|
@@ -3943,8 +4198,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3943
4198
|
case "citations_delta": {
|
|
3944
4199
|
const citation = value.delta.citation;
|
|
3945
4200
|
const contentBlock = contentBlocks[value.index];
|
|
3946
|
-
if (
|
|
3947
|
-
contentBlock.
|
|
4201
|
+
if (citation.type === "web_search_result_location") {
|
|
4202
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) === "text")
|
|
4203
|
+
contentBlock.citations.push(citation);
|
|
4204
|
+
(_b2 = heldBackTextByIndex.get(value.index)) == null ? void 0 : _b2.citations.push(citation);
|
|
3948
4205
|
}
|
|
3949
4206
|
const source = createCitationSource(
|
|
3950
4207
|
citation,
|
|
@@ -3981,16 +4238,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3981
4238
|
}
|
|
3982
4239
|
isMessageOpen = true;
|
|
3983
4240
|
activeMessageId = value.message.id;
|
|
4241
|
+
heldBackTextByIndex.clear();
|
|
3984
4242
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
3985
|
-
usage.cachedInputTokens = (
|
|
4243
|
+
usage.cachedInputTokens = (_c = value.message.usage.cache_read_input_tokens) != null ? _c : void 0;
|
|
3986
4244
|
rawUsage = {
|
|
3987
4245
|
...value.message.usage
|
|
3988
4246
|
};
|
|
3989
|
-
cacheCreationInputTokens = (
|
|
4247
|
+
cacheCreationInputTokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
|
|
3990
4248
|
controller.enqueue({
|
|
3991
4249
|
type: "response-metadata",
|
|
3992
|
-
id: (
|
|
3993
|
-
modelId: (
|
|
4250
|
+
id: (_e = value.message.id) != null ? _e : void 0,
|
|
4251
|
+
modelId: (_f = value.message.model) != null ? _f : void 0
|
|
3994
4252
|
});
|
|
3995
4253
|
return;
|
|
3996
4254
|
}
|
|
@@ -4004,7 +4262,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4004
4262
|
if (value.usage.iterations != null) {
|
|
4005
4263
|
iterations = value.usage.iterations;
|
|
4006
4264
|
}
|
|
4007
|
-
const servedByFallback = (
|
|
4265
|
+
const servedByFallback = (_g = value.usage.iterations) == null ? void 0 : _g.some(
|
|
4008
4266
|
(iter) => iter.type === "fallback_message"
|
|
4009
4267
|
);
|
|
4010
4268
|
if (value.usage.iterations && value.usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -4023,21 +4281,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4023
4281
|
}
|
|
4024
4282
|
usage.outputTokens = value.usage.output_tokens;
|
|
4025
4283
|
}
|
|
4026
|
-
usage.totalTokens = ((
|
|
4284
|
+
usage.totalTokens = ((_h = usage.inputTokens) != null ? _h : 0) + ((_i = usage.outputTokens) != null ? _i : 0);
|
|
4285
|
+
rawStopReason = value.delta.stop_reason;
|
|
4027
4286
|
finishReason = mapAnthropicStopReason({
|
|
4028
4287
|
finishReason: value.delta.stop_reason,
|
|
4029
4288
|
isJsonResponseFromTool
|
|
4030
4289
|
});
|
|
4031
4290
|
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
4032
|
-
stopSequence = (
|
|
4291
|
+
stopSequence = (_j = value.delta.stop_sequence) != null ? _j : null;
|
|
4033
4292
|
container = value.delta.container != null ? {
|
|
4034
4293
|
expiresAt: value.delta.container.expires_at,
|
|
4035
4294
|
id: value.delta.container.id,
|
|
4036
|
-
skills: (
|
|
4295
|
+
skills: (_l = (_k = value.delta.container.skills) == null ? void 0 : _k.map((skill) => ({
|
|
4037
4296
|
type: skill.type,
|
|
4038
4297
|
skillId: skill.skill_id,
|
|
4039
4298
|
version: skill.version
|
|
4040
|
-
}))) != null ?
|
|
4299
|
+
}))) != null ? _l : null
|
|
4041
4300
|
} : null;
|
|
4042
4301
|
if (value.context_management != null) {
|
|
4043
4302
|
contextManagement = {
|
|
@@ -4075,6 +4334,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4075
4334
|
case "message_stop": {
|
|
4076
4335
|
isMessageOpen = false;
|
|
4077
4336
|
activeMessageId = void 0;
|
|
4337
|
+
if (!isJsonResponseFromTool && !isContinuationStopReason(rawStopReason)) {
|
|
4338
|
+
for (const { id, text, citations } of heldBackText) {
|
|
4339
|
+
if (text.length === 0) continue;
|
|
4340
|
+
controller.enqueue({ type: "text-start", id });
|
|
4341
|
+
controller.enqueue({ type: "text-delta", id, delta: text });
|
|
4342
|
+
controller.enqueue(createTextEnd(id, citations));
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
heldBackText.length = 0;
|
|
4078
4346
|
controller.enqueue({
|
|
4079
4347
|
type: "finish",
|
|
4080
4348
|
finishReason,
|
|
@@ -4863,6 +5131,7 @@ var anthropicTools = {
|
|
|
4863
5131
|
anthropicTools,
|
|
4864
5132
|
getModelCapabilities,
|
|
4865
5133
|
prepareTools,
|
|
4866
|
-
sanitizeJsonSchema
|
|
5134
|
+
sanitizeJsonSchema,
|
|
5135
|
+
supportsNativeStructuredOutputSchema
|
|
4867
5136
|
});
|
|
4868
5137
|
//# sourceMappingURL=index.js.map
|