@ai-sdk/anthropic 4.0.93 → 4.0.94
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 +8 -0
- package/dist/index.js +231 -20
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +230 -19
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +12 -1
- package/package.json +1 -1
- package/src/anthropic-language-model.ts +121 -20
- package/src/has-circular-schema-reference.ts +115 -0
- package/src/sanitize-json-schema.ts +27 -24
- package/src/supports-native-structured-output-schema.ts +138 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__anthropic_api0.AnthropicToolChoice","_$__anthropic_api0.AnthropicTextContent","_$__anthropic_api0.AnthropicMessage","SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member"],"sources":["../../src/anthropic-files.ts","../../src/anthropic-api.ts","../../src/anthropic-language-model-options.ts","../../src/get-cache-control.ts","../../src/convert-to-anthropic-prompt.ts","../../src/anthropic-model-catalog.ts","../../src/anthropic-language-model.ts","../../src/tool/computer-toolset_20260801.ts","../../src/tool/bash_20241022.ts","../../src/tool/bash_20250124.ts","../../src/anthropic-tools.ts","../../src/anthropic-prepare-tools.ts","../../src/sanitize-json-schema.ts","../../src/skills/anthropic-skills.ts"],"mappings":";;;;UAiCU;EACR;EACA;EACA,SAAS,WAAW;EACpB,QAAQ;;qBAGG,0BAA0B;mBAOR;WANpB;MAEL;EAIyB,YAAA,QAAQ;EAE/B,aACJ,MACA,WACA,UACA,aACA,WACC,+BAA+B,QAAQ;;;;KC1ChC,mBACR,uBACA,4BACA;KAEQ;EACV;EACA;;UAGe;EACf;EACA,SAAS,MAAM,uBAAuB;EACtC;EACA;IACE;;;;;;;;;;UAWa;EACf;EACA;IAAQ;IAAwB;;EAChC;;UAGe;EACf;EACA,SAAS,MACL,uBACA,wBACA,wBACA,2BACA,kCACA;;UAIW;EACf;EACA,SAAS,MACL,uBACA,2BACA,mCACA,2BACA,2BACA,gCACA,0CACA,qCACA,sCACA,uCACA,8CACA,oDACA,oCACA,6BACA,gCACA;;cAIO,sCAA8B,EAAA;;;;;;;;GAKvC,EAAA,KAAA;KAKQ,2BAA2B,YACrC,kBAAkB;EAElB;;UAGe;EACf;EACA;EACA;EACA,gBAAgB;;UAGD;EACf;EACA;EACA,YAAY;EACZ,eAAe;;UAGA;EACf;EACA;EACA;EAGA;;UAGe;EACf;EACA;EAGA;;KAGG;EAEC;EACA;EACA;;EAGA;EACA;;EAGA;EACA;EACA;;EAGA;EACA;;UAGW;EACf;EACA,QAAQ;EACR,eAAe;;;UAIA;EACf;EACA,QAAQ;EACR,eAAe;;UAGA;EACf;EACA,QAAQ;EACR;EACA;EACA;IAAc;;EACd,eAAe;;UAGA;EACf;EACA;EACA;;;;;;KAOU;EAEN;EACA;;EAGA;EACA;;EAGA;;UAGW;EACf;EACA;EACA;EACA;;;;;EAKA,SAAS;;;;;EAKT;EACA,eAAe;;UAGA;EACf;EACA;EACA;EAaA;EACA,SAAS;EACT,eAAe;;KAKZ,6BAA6B,KAChC;EAGA;;KAGG,8BAA8B,KACjC;EAGA;;KAGG,iCAAiC,KACpC;EAGA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;;;EAIA;EACA,kBAEI,MACI,6BACA,8BACA,iCACA;EAER;EACA,eAAe;;UAGA;EACf;EACA;EACA,SACI;IACE;IACA;IACA;IACA;IACA;;IAGA;IACA;;EAEN,SAAS;EACT,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA,iBAAiB;MACf;MACA;;;IAIF;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;;IAGA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA;MACE;MACA;;;IAIF;IACA;;EAEN,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA;IACA;;IAGA;IACA;IACA;;IAGA;;;;;;IAMA;;EAEN,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;MACE;MACA;MACA;QAAc;;MACd;QACM;QAAgB;QAA+B;;QAC/C;QAAc;QAA0B;;;;IAIhD;IACA;;EAEN,SAAS;EACT,eAAe;;UAEA;EACf;EACA;EACA;EACA;EACA;EACA,eAAe;;UAGA;EACf;EACA;EACA;EACA,kBAEI;IACE;IACA;IACA,YAAY;;EAElB,eAAe;;KAGL;EAEN;EACA;EACA,cAAc;EACd,eAAe;EACf;EACA;;;;;EAKA;;;;;;;;EAQA,kBAAkB;;EAKlB;EACA;EACA,eAAe;;EAGf;EACA;;EAGA;EACA;;EAGA;EACA;EACA;EACA;EACA;EACA,eAAe;;EAGf;EACA;EACA;EACA;EACA;EACA;EACA,eAAe;;;;;;EAOf;EACA,UAAU;IAAiB;IAAmB;;EAC9C,eAAe;;EAGf;EACA;EAIA,eAAe;;EAGf;EACA;EACA;EACA,eAAe;;EAGf;EACA;EACA,eAAe;;EAGf;EACA;;EAGA;EACA;EACA;EACA;EACA;EACA;IAAc;;EACd;EACA;EACA;EACA,eAAe;;EAGf;EAIA;EACA;EACA;EACA;EACA;IACE;IACA;IACA;IACA;IACA;;EAEF;EACA,eAAe;;EAGf;EACA;;EAGA;EACA;;EAGA;EACA;EACA;EACA;EACA;EACA;IACE;IACA;;;KAMI;EACN;EAAsB;;EACtB;;EACA;EAAc;EAAc;;cAgNrB,0DAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgwBxB,WAAW,aACpB,mBAAmB;EAClB;;;;KC3iDQ;;;cCuBC;mBAIkB;UAHrB;UACA;EAEqB,YAAA;EAE7B,gBACE,kBAAkB,sCAClB;IAAW;IAAc;MACxB;EAkCH,eAAe;;;;;KCSL,+BACV,MAAM,4BACH,YACD,KAAK,wBAAwB;;;;iBC2SjB,8BAA8B;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__anthropic_api0.AnthropicToolChoice","_$__anthropic_api0.AnthropicTextContent","_$__anthropic_api0.AnthropicMessage","SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member"],"sources":["../../src/anthropic-files.ts","../../src/anthropic-api.ts","../../src/anthropic-language-model-options.ts","../../src/get-cache-control.ts","../../src/convert-to-anthropic-prompt.ts","../../src/anthropic-model-catalog.ts","../../src/anthropic-language-model.ts","../../src/tool/computer-toolset_20260801.ts","../../src/tool/bash_20241022.ts","../../src/tool/bash_20250124.ts","../../src/anthropic-tools.ts","../../src/anthropic-prepare-tools.ts","../../src/sanitize-json-schema.ts","../../src/skills/anthropic-skills.ts"],"mappings":";;;;UAiCU;EACR;EACA;EACA,SAAS,WAAW;EACpB,QAAQ;;qBAGG,0BAA0B;mBAOR;WANpB;MAEL;EAIyB,YAAA,QAAQ;EAE/B,aACJ,MACA,WACA,UACA,aACA,WACC,+BAA+B,QAAQ;;;;KC1ChC,mBACR,uBACA,4BACA;KAEQ;EACV;EACA;;UAGe;EACf;EACA,SAAS,MAAM,uBAAuB;EACtC;EACA;IACE;;;;;;;;;;UAWa;EACf;EACA;IAAQ;IAAwB;;EAChC;;UAGe;EACf;EACA,SAAS,MACL,uBACA,wBACA,wBACA,2BACA,kCACA;;UAIW;EACf;EACA,SAAS,MACL,uBACA,2BACA,mCACA,2BACA,2BACA,gCACA,0CACA,qCACA,sCACA,uCACA,8CACA,oDACA,oCACA,6BACA,gCACA;;cAIO,sCAA8B,EAAA;;;;;;;;GAKvC,EAAA,KAAA;KAKQ,2BAA2B,YACrC,kBAAkB;EAElB;;UAGe;EACf;EACA;EACA;EACA,gBAAgB;;UAGD;EACf;EACA;EACA,YAAY;EACZ,eAAe;;UAGA;EACf;EACA;EACA;EAGA;;UAGe;EACf;EACA;EAGA;;KAGG;EAEC;EACA;EACA;;EAGA;EACA;;EAGA;EACA;EACA;;EAGA;EACA;;UAGW;EACf;EACA,QAAQ;EACR,eAAe;;;UAIA;EACf;EACA,QAAQ;EACR,eAAe;;UAGA;EACf;EACA,QAAQ;EACR;EACA;EACA;IAAc;;EACd,eAAe;;UAGA;EACf;EACA;EACA;;;;;;KAOU;EAEN;EACA;;EAGA;EACA;;EAGA;;UAGW;EACf;EACA;EACA;EACA;;;;;EAKA,SAAS;;;;;EAKT;EACA,eAAe;;UAGA;EACf;EACA;EACA;EAaA;EACA,SAAS;EACT,eAAe;;KAKZ,6BAA6B,KAChC;EAGA;;KAGG,8BAA8B,KACjC;EAGA;;KAGG,iCAAiC,KACpC;EAGA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;;;EAIA;EACA,kBAEI,MACI,6BACA,8BACA,iCACA;EAER;EACA,eAAe;;UAGA;EACf;EACA;EACA,SACI;IACE;IACA;IACA;IACA;IACA;;IAGA;IACA;;EAEN,SAAS;EACT,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA,iBAAiB;MACf;MACA;;;IAIF;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;IACA;IACA;IACA,SAAS;MAAQ;MAA+B;;;IAGhD;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;;IAGA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;IAGA;IACA;IACA;IACA;IACA;IACA;;EAEN,eAAe;;UAIA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;IACA;MACE;MACA;;;IAIF;IACA;;EAEN,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA;IACA;;IAGA;IACA;IACA;;IAGA;;;;;;IAMA;;EAEN,eAAe;;UAGA;EACf;EACA;EACA;IAEM;IACA;IACA;IACA;MACE;MACA;MACA;QAAc;;MACd;QACM;QAAgB;QAA+B;;QAC/C;QAAc;QAA0B;;;;IAIhD;IACA;;EAEN,SAAS;EACT,eAAe;;UAEA;EACf;EACA;EACA;EACA;EACA;EACA,eAAe;;UAGA;EACf;EACA;EACA;EACA,kBAEI;IACE;IACA;IACA,YAAY;;EAElB,eAAe;;KAGL;EAEN;EACA;EACA,cAAc;EACd,eAAe;EACf;EACA;;;;;EAKA;;;;;;;;EAQA,kBAAkB;;EAKlB;EACA;EACA,eAAe;;EAGf;EACA;;EAGA;EACA;;EAGA;EACA;EACA;EACA;EACA;EACA,eAAe;;EAGf;EACA;EACA;EACA;EACA;EACA;EACA,eAAe;;;;;;EAOf;EACA,UAAU;IAAiB;IAAmB;;EAC9C,eAAe;;EAGf;EACA;EAIA,eAAe;;EAGf;EACA;EACA;EACA,eAAe;;EAGf;EACA;EACA,eAAe;;EAGf;EACA;;EAGA;EACA;EACA;EACA;EACA;EACA;IAAc;;EACd;EACA;EACA;EACA,eAAe;;EAGf;EAIA;EACA;EACA;EACA;EACA;IACE;IACA;IACA;IACA;IACA;;EAEF;EACA,eAAe;;EAGf;EACA;;EAGA;EACA;;EAGA;EACA;EACA;EACA;EACA;EACA;IACE;IACA;;;KAMI;EACN;EAAsB;;EACtB;;E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;;;;;;;;;;;;;;;;MAHxB;MACA;MAEa;MACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCnBC,eACpB,OACA,YACA,wBACA,uBACA,0BACA,qBACA,4BACA;EAEA,OAAO;EACP,YAAY;EACZ;EACA,wBAAwB;;;;EAKxB;;;;EAKA;;;;;EAMA;;;;;;EAOA;IACE;EACF,OAAO,MAAM;EACb,YAAY;EACZ,cAAc;EACd,OAAO;;;;;;;;;;;wBC3BO,mBAAmB,QAAQ,cAAc;;;UCtB/C;EACR;EACA;EACA,SAAS,WAAW;EACpB,QAAQ;;qBAGG,2BAA2B;mBAOT;WANpB;MAEL;EAIyB,YAAA,QAAQ;UAEvB;UAMA;EA0BR,YACJ,QAAQ,WAAW,8BAClB,QAAQ,QAAQ,WAAW"}
|
package/dist/internal/index.js
CHANGED
|
@@ -3699,8 +3699,10 @@ function sanitizeDefinition(definition) {
|
|
|
3699
3699
|
}
|
|
3700
3700
|
function sanitizeSchema(schema) {
|
|
3701
3701
|
const result = {};
|
|
3702
|
-
|
|
3703
|
-
|
|
3702
|
+
if (schema.$ref != null) return {
|
|
3703
|
+
$ref: schema.$ref,
|
|
3704
|
+
...sanitizeSchemaDefinitions(schema)
|
|
3705
|
+
};
|
|
3704
3706
|
if (schema.$schema != null) result.$schema = schema.$schema;
|
|
3705
3707
|
if (schema.$id != null) result.$id = schema.$id;
|
|
3706
3708
|
if (schema.title != null) result.title = schema.title;
|
|
@@ -3712,11 +3714,7 @@ function sanitizeSchema(schema) {
|
|
|
3712
3714
|
if (schema.anyOf != null) result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
3713
3715
|
else if (schema.oneOf != null) result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
3714
3716
|
if (schema.allOf != null) result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
3715
|
-
|
|
3716
|
-
if (schemaWithDefs.$defs != null) {
|
|
3717
|
-
const resultWithDefs = result;
|
|
3718
|
-
resultWithDefs.$defs = Object.fromEntries(Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [name, sanitizeDefinition(definition)]));
|
|
3719
|
-
}
|
|
3717
|
+
Object.assign(result, sanitizeSchemaDefinitions(schema));
|
|
3720
3718
|
if (schema.type === "object" || schema.properties != null) {
|
|
3721
3719
|
if (schema.properties != null) result.properties = Object.fromEntries(Object.entries(schema.properties).map(([name, definition]) => [name, sanitizeDefinition(definition)]));
|
|
3722
3720
|
result.additionalProperties = false;
|
|
@@ -3728,6 +3726,14 @@ function sanitizeSchema(schema) {
|
|
|
3728
3726
|
if (constraintDescription != null) result.description = result.description == null ? constraintDescription : `${result.description}\n${constraintDescription}`;
|
|
3729
3727
|
return result;
|
|
3730
3728
|
}
|
|
3729
|
+
function sanitizeSchemaDefinitions(schema) {
|
|
3730
|
+
const { $defs } = schema;
|
|
3731
|
+
const sanitizeAll = (definitions) => Object.fromEntries(Object.entries(definitions).map(([name, definition]) => [name, sanitizeDefinition(definition)]));
|
|
3732
|
+
return {
|
|
3733
|
+
...schema.definitions != null && { definitions: sanitizeAll(schema.definitions) },
|
|
3734
|
+
...$defs != null && { $defs: sanitizeAll($defs) }
|
|
3735
|
+
};
|
|
3736
|
+
}
|
|
3731
3737
|
function getConstraintDescription(schema) {
|
|
3732
3738
|
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
3733
3739
|
const value = schema[key];
|
|
@@ -3745,6 +3751,155 @@ function formatConstraintValue(value) {
|
|
|
3745
3751
|
return JSON.stringify(value);
|
|
3746
3752
|
}
|
|
3747
3753
|
//#endregion
|
|
3754
|
+
//#region src/has-circular-schema-reference.ts
|
|
3755
|
+
const SCHEMA_MAP_KEYWORDS = /* @__PURE__ */ new Set([
|
|
3756
|
+
"dependentSchemas",
|
|
3757
|
+
"patternProperties",
|
|
3758
|
+
"properties"
|
|
3759
|
+
]);
|
|
3760
|
+
const DATA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
3761
|
+
"const",
|
|
3762
|
+
"default",
|
|
3763
|
+
"enum",
|
|
3764
|
+
"examples"
|
|
3765
|
+
]);
|
|
3766
|
+
/**
|
|
3767
|
+
* Whether a JSON schema contains a cycle of local `$ref`s, e.g. a tree node
|
|
3768
|
+
* whose children reference the node itself.
|
|
3769
|
+
*
|
|
3770
|
+
* Anthropic's native structured outputs reject such schemas, while the JSON
|
|
3771
|
+
* response tool accepts them.
|
|
3772
|
+
*/
|
|
3773
|
+
function hasCircularSchemaReference(schema) {
|
|
3774
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
3775
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3776
|
+
const visit = (pointer) => {
|
|
3777
|
+
if (visiting.has(pointer)) return true;
|
|
3778
|
+
if (visited.has(pointer)) return false;
|
|
3779
|
+
const target = resolveSchemaPointer(schema, pointer);
|
|
3780
|
+
if (target === void 0) return false;
|
|
3781
|
+
visiting.add(pointer);
|
|
3782
|
+
const isCircular = collectLocalRefs(target).some(visit);
|
|
3783
|
+
visiting.delete(pointer);
|
|
3784
|
+
visited.add(pointer);
|
|
3785
|
+
return isCircular;
|
|
3786
|
+
};
|
|
3787
|
+
return visit("#");
|
|
3788
|
+
}
|
|
3789
|
+
function collectLocalRefs(node, refs = []) {
|
|
3790
|
+
if (Array.isArray(node)) {
|
|
3791
|
+
for (const item of node) collectLocalRefs(item, refs);
|
|
3792
|
+
return refs;
|
|
3793
|
+
}
|
|
3794
|
+
if (!isRecord(node)) return refs;
|
|
3795
|
+
for (const [key, value] of Object.entries(node)) if (key === "$ref") {
|
|
3796
|
+
if (typeof value === "string" && value.startsWith("#")) refs.push(value);
|
|
3797
|
+
} else if (SCHEMA_MAP_KEYWORDS.has(key) && isRecord(value)) for (const subschema of Object.values(value)) collectLocalRefs(subschema, refs);
|
|
3798
|
+
else if (key !== "$defs" && key !== "definitions" && !DATA_KEYWORDS.has(key)) collectLocalRefs(value, refs);
|
|
3799
|
+
return refs;
|
|
3800
|
+
}
|
|
3801
|
+
function resolveSchemaPointer(schema, pointer) {
|
|
3802
|
+
if (pointer === "#") return schema;
|
|
3803
|
+
if (!pointer.startsWith("#/")) return;
|
|
3804
|
+
let decodedPointer;
|
|
3805
|
+
try {
|
|
3806
|
+
decodedPointer = decodeURIComponent(pointer.slice(2));
|
|
3807
|
+
} catch {
|
|
3808
|
+
return;
|
|
3809
|
+
}
|
|
3810
|
+
let current = schema;
|
|
3811
|
+
for (const rawSegment of decodedPointer.split("/")) {
|
|
3812
|
+
const segment = rawSegment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
3813
|
+
if (Array.isArray(current)) current = current[Number(segment)];
|
|
3814
|
+
else if (isRecord(current)) current = current[segment];
|
|
3815
|
+
else return;
|
|
3816
|
+
}
|
|
3817
|
+
return current;
|
|
3818
|
+
}
|
|
3819
|
+
//#endregion
|
|
3820
|
+
//#region src/supports-native-structured-output-schema.ts
|
|
3821
|
+
const MAX_OPTIONAL_PROPERTIES = 10;
|
|
3822
|
+
const SUBSCHEMA_KEYWORDS = [
|
|
3823
|
+
"additionalProperties",
|
|
3824
|
+
"contains",
|
|
3825
|
+
"else",
|
|
3826
|
+
"if",
|
|
3827
|
+
"items",
|
|
3828
|
+
"not",
|
|
3829
|
+
"then"
|
|
3830
|
+
];
|
|
3831
|
+
const SUBSCHEMA_LIST_KEYWORDS = [
|
|
3832
|
+
"allOf",
|
|
3833
|
+
"anyOf",
|
|
3834
|
+
"oneOf",
|
|
3835
|
+
"prefixItems"
|
|
3836
|
+
];
|
|
3837
|
+
const SUBSCHEMA_MAP_KEYWORDS = [
|
|
3838
|
+
"dependentSchemas",
|
|
3839
|
+
"patternProperties",
|
|
3840
|
+
"properties"
|
|
3841
|
+
];
|
|
3842
|
+
/**
|
|
3843
|
+
* Whether Anthropic's native structured outputs (`output_config.format`) can
|
|
3844
|
+
* represent a schema without rejecting it or losing data.
|
|
3845
|
+
*
|
|
3846
|
+
* Rejected: self-referencing schemas, and schemas with too many optional
|
|
3847
|
+
* properties. Lossy: open objects (maps, free-form objects), which native
|
|
3848
|
+
* structured outputs close with `additionalProperties: false`, so the model
|
|
3849
|
+
* can only return `{}` for them.
|
|
3850
|
+
*/
|
|
3851
|
+
function supportsNativeStructuredOutputSchema(schema) {
|
|
3852
|
+
if (hasCircularSchemaReference(schema)) return false;
|
|
3853
|
+
const { optionalProperties, hasOpenObject } = getSchemaStats(schema, schema, /* @__PURE__ */ new Map());
|
|
3854
|
+
return !hasOpenObject && optionalProperties <= MAX_OPTIONAL_PROPERTIES;
|
|
3855
|
+
}
|
|
3856
|
+
function getSchemaStats(node, root, refStats) {
|
|
3857
|
+
const stats = {
|
|
3858
|
+
optionalProperties: 0,
|
|
3859
|
+
hasOpenObject: false
|
|
3860
|
+
};
|
|
3861
|
+
if (!isRecord(node)) return stats;
|
|
3862
|
+
const add = (child) => {
|
|
3863
|
+
const childStats = getSchemaStats(child, root, refStats);
|
|
3864
|
+
stats.optionalProperties += childStats.optionalProperties;
|
|
3865
|
+
stats.hasOpenObject ||= childStats.hasOpenObject;
|
|
3866
|
+
};
|
|
3867
|
+
if (typeof node.$ref === "string" && node.$ref.startsWith("#")) {
|
|
3868
|
+
let resolved = refStats.get(node.$ref);
|
|
3869
|
+
if (resolved == null) {
|
|
3870
|
+
resolved = getSchemaStats(resolveSchemaPointer(root, node.$ref), root, refStats);
|
|
3871
|
+
refStats.set(node.$ref, resolved);
|
|
3872
|
+
}
|
|
3873
|
+
stats.optionalProperties += resolved.optionalProperties;
|
|
3874
|
+
stats.hasOpenObject ||= resolved.hasOpenObject;
|
|
3875
|
+
}
|
|
3876
|
+
if (isOpenObject(node)) stats.hasOpenObject = true;
|
|
3877
|
+
if (isRecord(node.properties)) {
|
|
3878
|
+
const required = new Set(Array.isArray(node.required) ? node.required : []);
|
|
3879
|
+
stats.optionalProperties += Object.keys(node.properties).filter((name) => !required.has(name)).length;
|
|
3880
|
+
}
|
|
3881
|
+
for (const keyword of SUBSCHEMA_KEYWORDS) {
|
|
3882
|
+
const value = node[keyword];
|
|
3883
|
+
if (Array.isArray(value)) value.forEach(add);
|
|
3884
|
+
else add(value);
|
|
3885
|
+
}
|
|
3886
|
+
for (const keyword of SUBSCHEMA_LIST_KEYWORDS) {
|
|
3887
|
+
const value = node[keyword];
|
|
3888
|
+
if (Array.isArray(value)) value.forEach(add);
|
|
3889
|
+
}
|
|
3890
|
+
for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
|
|
3891
|
+
const value = node[keyword];
|
|
3892
|
+
if (isRecord(value)) Object.values(value).forEach(add);
|
|
3893
|
+
}
|
|
3894
|
+
return stats;
|
|
3895
|
+
}
|
|
3896
|
+
function isOpenObject(node) {
|
|
3897
|
+
const { additionalProperties, patternProperties, properties, type } = node;
|
|
3898
|
+
if (additionalProperties === true || isRecord(additionalProperties)) return true;
|
|
3899
|
+
if (isRecord(patternProperties) && Object.keys(patternProperties).length > 0) return true;
|
|
3900
|
+
return (type === "object" || Array.isArray(type) && type.includes("object")) && properties == null && additionalProperties !== false;
|
|
3901
|
+
}
|
|
3902
|
+
//#endregion
|
|
3748
3903
|
//#region src/anthropic-language-model.ts
|
|
3749
3904
|
function createAnthropicStreamError(error) {
|
|
3750
3905
|
const inferredMetadata = getAnthropicStreamErrorMetadata(error.type);
|
|
@@ -3863,6 +4018,28 @@ function getProviderOptionsName(provider) {
|
|
|
3863
4018
|
const dotIndex = provider.indexOf(".");
|
|
3864
4019
|
return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
|
|
3865
4020
|
}
|
|
4021
|
+
const TEXT_OR_THINKING_BLOCK_TYPES = /* @__PURE__ */ new Set([
|
|
4022
|
+
"redacted_thinking",
|
|
4023
|
+
"text",
|
|
4024
|
+
"thinking"
|
|
4025
|
+
]);
|
|
4026
|
+
function isContinuationStopReason(stopReason) {
|
|
4027
|
+
return stopReason === "pause_turn" || stopReason === "tool_use";
|
|
4028
|
+
}
|
|
4029
|
+
/**
|
|
4030
|
+
* Text parts to return when the JSON response tool is in use: the text after
|
|
4031
|
+
* the last tool call or result, and only if the tool was never called.
|
|
4032
|
+
*/
|
|
4033
|
+
function getJsonResponseToolFallbackText(content, stopReason) {
|
|
4034
|
+
const text = /* @__PURE__ */ new Set();
|
|
4035
|
+
if (isContinuationStopReason(stopReason)) return text;
|
|
4036
|
+
for (const part of content) {
|
|
4037
|
+
if (part.type === "tool_use" && part.name === "json") return /* @__PURE__ */ new Set();
|
|
4038
|
+
if (part.type === "text") text.add(part);
|
|
4039
|
+
else if (!TEXT_OR_THINKING_BLOCK_TYPES.has(part.type)) text.clear();
|
|
4040
|
+
}
|
|
4041
|
+
return text;
|
|
4042
|
+
}
|
|
3866
4043
|
var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
3867
4044
|
static [WORKFLOW_SERIALIZE](model) {
|
|
3868
4045
|
return serializeModelOptions({
|
|
@@ -3976,7 +4153,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
3976
4153
|
const supportsStrictTools = (config.supportsStrictTools ?? true) && modelSupportsStructuredOutput;
|
|
3977
4154
|
const structureOutputMode = anthropicOptions?.structuredOutputMode ?? "auto";
|
|
3978
4155
|
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
3979
|
-
if (!useStructuredOutput && rejectsForcedToolUse &&
|
|
4156
|
+
if (!useStructuredOutput && rejectsForcedToolUse && modelSupportsStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null && supportsNativeStructuredOutputSchema(responseFormat.schema)) {
|
|
3980
4157
|
warnings.push({
|
|
3981
4158
|
type: "unsupported",
|
|
3982
4159
|
feature: "providerOptions.anthropic.structuredOutputMode",
|
|
@@ -4383,9 +4560,10 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4383
4560
|
const serverToolCalls = {};
|
|
4384
4561
|
let isJsonResponseFromTool = false;
|
|
4385
4562
|
const hasWebSearchResults = response.content.some((part) => part.type === "web_search_tool_result" && Array.isArray(part.content) && part.content.length > 0);
|
|
4563
|
+
const jsonResponseToolFallbackText = usesJsonResponseTool ? getJsonResponseToolFallbackText(response.content, response.stop_reason) : void 0;
|
|
4386
4564
|
for (const part of response.content) switch (part.type) {
|
|
4387
4565
|
case "text":
|
|
4388
|
-
if (
|
|
4566
|
+
if (jsonResponseToolFallbackText == null || jsonResponseToolFallbackText.has(part)) {
|
|
4389
4567
|
const citations = part.citations ?? [];
|
|
4390
4568
|
content.push({
|
|
4391
4569
|
type: "text",
|
|
@@ -4823,6 +5001,16 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4823
5001
|
let safeguardResults;
|
|
4824
5002
|
let container = null;
|
|
4825
5003
|
let isJsonResponseFromTool = false;
|
|
5004
|
+
const heldBackText = [];
|
|
5005
|
+
const heldBackTextByIndex = /* @__PURE__ */ new Map();
|
|
5006
|
+
const createTextEnd = (id, citations) => ({
|
|
5007
|
+
type: "text-end",
|
|
5008
|
+
id,
|
|
5009
|
+
...citations.length > 0 && {
|
|
5010
|
+
citations: citations.map((citation) => mapAnthropicCitation(citation, citationDocuments)),
|
|
5011
|
+
providerMetadata: { anthropic: { citations } }
|
|
5012
|
+
}
|
|
5013
|
+
});
|
|
4826
5014
|
let hasWebSearchResults = false;
|
|
4827
5015
|
const fallbackWebCitations = [];
|
|
4828
5016
|
let isMessageOpen = false;
|
|
@@ -4869,9 +5057,19 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4869
5057
|
return;
|
|
4870
5058
|
}
|
|
4871
5059
|
blockType = contentBlockType;
|
|
5060
|
+
if (!TEXT_OR_THINKING_BLOCK_TYPES.has(contentBlockType)) heldBackText.length = 0;
|
|
4872
5061
|
switch (contentBlockType) {
|
|
4873
5062
|
case "text":
|
|
4874
|
-
if (usesJsonResponseTool)
|
|
5063
|
+
if (usesJsonResponseTool) {
|
|
5064
|
+
const entry = {
|
|
5065
|
+
id: String(value.index),
|
|
5066
|
+
text: "",
|
|
5067
|
+
citations: []
|
|
5068
|
+
};
|
|
5069
|
+
heldBackText.push(entry);
|
|
5070
|
+
heldBackTextByIndex.set(value.index, entry);
|
|
5071
|
+
return;
|
|
5072
|
+
}
|
|
4875
5073
|
contentBlocks[value.index] = {
|
|
4876
5074
|
type: "text",
|
|
4877
5075
|
citations: []
|
|
@@ -5257,14 +5455,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5257
5455
|
const contentBlock = contentBlocks[value.index];
|
|
5258
5456
|
switch (contentBlock.type) {
|
|
5259
5457
|
case "text":
|
|
5260
|
-
controller.enqueue(
|
|
5261
|
-
type: "text-end",
|
|
5262
|
-
id: String(value.index),
|
|
5263
|
-
...contentBlock.citations.length > 0 && {
|
|
5264
|
-
citations: contentBlock.citations.map((citation) => mapAnthropicCitation(citation, citationDocuments)),
|
|
5265
|
-
providerMetadata: { anthropic: { citations: contentBlock.citations } }
|
|
5266
|
-
}
|
|
5267
|
-
});
|
|
5458
|
+
controller.enqueue(createTextEnd(String(value.index), contentBlock.citations));
|
|
5268
5459
|
break;
|
|
5269
5460
|
case "reasoning":
|
|
5270
5461
|
controller.enqueue({
|
|
@@ -5324,7 +5515,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5324
5515
|
const deltaType = value.delta.type;
|
|
5325
5516
|
switch (deltaType) {
|
|
5326
5517
|
case "text_delta":
|
|
5327
|
-
if (usesJsonResponseTool)
|
|
5518
|
+
if (usesJsonResponseTool) {
|
|
5519
|
+
const entry = heldBackTextByIndex.get(value.index);
|
|
5520
|
+
if (entry != null) entry.text += value.delta.text;
|
|
5521
|
+
return;
|
|
5522
|
+
}
|
|
5328
5523
|
controller.enqueue({
|
|
5329
5524
|
type: "text-delta",
|
|
5330
5525
|
id: String(value.index),
|
|
@@ -5385,6 +5580,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5385
5580
|
const citation = value.delta.citation;
|
|
5386
5581
|
const contentBlock = contentBlocks[value.index];
|
|
5387
5582
|
if (contentBlock?.type === "text") contentBlock.citations.push(citation);
|
|
5583
|
+
heldBackTextByIndex.get(value.index)?.citations.push(citation);
|
|
5388
5584
|
if (citation.type === "web_search_result_location") fallbackWebCitations.push(citation);
|
|
5389
5585
|
else {
|
|
5390
5586
|
const source = createCitationSource(citation, citationDocuments, generateId);
|
|
@@ -5410,6 +5606,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5410
5606
|
}
|
|
5411
5607
|
isMessageOpen = true;
|
|
5412
5608
|
activeMessageId = value.message.id;
|
|
5609
|
+
heldBackTextByIndex.clear();
|
|
5413
5610
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
5414
5611
|
usage.cache_read_input_tokens = value.message.usage.cache_read_input_tokens ?? 0;
|
|
5415
5612
|
usage.cache_creation_input_tokens = value.message.usage.cache_creation_input_tokens ?? 0;
|
|
@@ -5530,6 +5727,20 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5530
5727
|
if (source) controller.enqueue(source);
|
|
5531
5728
|
}
|
|
5532
5729
|
fallbackWebCitations.length = 0;
|
|
5730
|
+
if (!isJsonResponseFromTool && !isContinuationStopReason(finishReason.raw)) for (const { id, text, citations } of heldBackText) {
|
|
5731
|
+
if (text.length === 0) continue;
|
|
5732
|
+
controller.enqueue({
|
|
5733
|
+
type: "text-start",
|
|
5734
|
+
id
|
|
5735
|
+
});
|
|
5736
|
+
controller.enqueue({
|
|
5737
|
+
type: "text-delta",
|
|
5738
|
+
id,
|
|
5739
|
+
delta: text
|
|
5740
|
+
});
|
|
5741
|
+
controller.enqueue(createTextEnd(id, citations));
|
|
5742
|
+
}
|
|
5743
|
+
heldBackText.length = 0;
|
|
5533
5744
|
controller.enqueue({
|
|
5534
5745
|
type: "finish",
|
|
5535
5746
|
finishReason,
|