@ai-sdk/anthropic 4.0.49 → 4.0.50
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 +8 -5
- package/dist/index.js +161 -146
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +8 -15
- package/dist/internal/index.js +44 -38
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +22 -9
- package/package.json +3 -3
- package/src/{anthropic-messages-batch.ts → anthropic-batch.ts} +64 -55
- package/src/anthropic-language-model.ts +58 -52
- package/src/anthropic-provider.ts +31 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.50
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a4ba394: feat: support per-request models in batch
|
|
8
|
+
- Updated dependencies [a4ba394]
|
|
9
|
+
- Updated dependencies [45099da]
|
|
10
|
+
- Updated dependencies [9e1d1b2]
|
|
11
|
+
- Updated dependencies [a495511]
|
|
12
|
+
- @ai-sdk/provider@4.0.11
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.37
|
|
14
|
+
|
|
3
15
|
## 4.0.49
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONObject, ProviderV4,
|
|
1
|
+
import { JSONObject, ProviderV4, LanguageModelV4, Experimental_BatchV4, FilesV4, SkillsV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { ToolExecuteFunction, Tool, Experimental_SandboxSession, ProviderDefinedTool, FetchFunction } from '@ai-sdk/provider-utils';
|
|
@@ -1244,13 +1244,16 @@ interface AnthropicProvider extends ProviderV4 {
|
|
|
1244
1244
|
/**
|
|
1245
1245
|
* Creates a model for text generation.
|
|
1246
1246
|
*/
|
|
1247
|
-
(modelId: AnthropicModelId):
|
|
1247
|
+
(modelId: AnthropicModelId): LanguageModelV4;
|
|
1248
1248
|
/**
|
|
1249
1249
|
* Creates a model for text generation.
|
|
1250
1250
|
*/
|
|
1251
|
-
languageModel(modelId: AnthropicModelId):
|
|
1252
|
-
chat(modelId: AnthropicModelId):
|
|
1253
|
-
messages(modelId: AnthropicModelId):
|
|
1251
|
+
languageModel(modelId: AnthropicModelId): LanguageModelV4;
|
|
1252
|
+
chat(modelId: AnthropicModelId): LanguageModelV4;
|
|
1253
|
+
messages(modelId: AnthropicModelId): LanguageModelV4;
|
|
1254
|
+
experimental_batch(): Experimental_BatchV4<{
|
|
1255
|
+
text: AnthropicModelId;
|
|
1256
|
+
}>;
|
|
1254
1257
|
/**
|
|
1255
1258
|
* @deprecated Use `embeddingModel` instead.
|
|
1256
1259
|
*/
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
NoSuchModelError
|
|
5
5
|
} from "@ai-sdk/provider";
|
|
6
6
|
import {
|
|
7
|
-
generateId as
|
|
7
|
+
generateId as generateId3,
|
|
8
8
|
loadApiKey,
|
|
9
9
|
loadOptionalSetting,
|
|
10
10
|
validateBaseURL,
|
|
@@ -117,31 +117,31 @@ var AnthropicFiles = class {
|
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
// src/anthropic-
|
|
120
|
+
// src/anthropic-language-model.ts
|
|
121
121
|
import {
|
|
122
|
-
|
|
123
|
-
InvalidResponseDataError
|
|
124
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
122
|
+
APICallError,
|
|
123
|
+
InvalidResponseDataError
|
|
125
124
|
} from "@ai-sdk/provider";
|
|
126
125
|
import {
|
|
127
|
-
combineHeaders as
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
126
|
+
combineHeaders as combineHeaders2,
|
|
127
|
+
createEventSourceResponseHandler,
|
|
128
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
129
|
+
createProviderStreamError,
|
|
130
|
+
createToolNameMapping,
|
|
131
|
+
generateId,
|
|
132
|
+
isCustomReasoning,
|
|
133
|
+
isProviderStreamError,
|
|
134
|
+
mapReasoningToProviderBudget,
|
|
135
|
+
mapReasoningToProviderEffort,
|
|
136
|
+
parseProviderOptions as parseProviderOptions2,
|
|
137
|
+
postJsonToApi,
|
|
138
|
+
resolve,
|
|
139
|
+
resolveProviderReference as resolveProviderReference2,
|
|
140
|
+
secureJsonParse as secureJsonParse2,
|
|
141
|
+
serializeModelOptions,
|
|
142
|
+
WORKFLOW_SERIALIZE,
|
|
143
|
+
WORKFLOW_DESERIALIZE
|
|
143
144
|
} from "@ai-sdk/provider-utils";
|
|
144
|
-
import { z as z15 } from "zod/v4";
|
|
145
145
|
|
|
146
146
|
// src/anthropic-api.ts
|
|
147
147
|
import {
|
|
@@ -941,32 +941,6 @@ var anthropicReasoningMetadataSchema = lazySchema3(
|
|
|
941
941
|
)
|
|
942
942
|
);
|
|
943
943
|
|
|
944
|
-
// src/anthropic-language-model.ts
|
|
945
|
-
import {
|
|
946
|
-
APICallError,
|
|
947
|
-
InvalidResponseDataError
|
|
948
|
-
} from "@ai-sdk/provider";
|
|
949
|
-
import {
|
|
950
|
-
combineHeaders as combineHeaders2,
|
|
951
|
-
createEventSourceResponseHandler,
|
|
952
|
-
createJsonResponseHandler as createJsonResponseHandler2,
|
|
953
|
-
createProviderStreamError,
|
|
954
|
-
createToolNameMapping,
|
|
955
|
-
generateId,
|
|
956
|
-
isCustomReasoning,
|
|
957
|
-
isProviderStreamError,
|
|
958
|
-
mapReasoningToProviderBudget,
|
|
959
|
-
mapReasoningToProviderEffort,
|
|
960
|
-
parseProviderOptions as parseProviderOptions2,
|
|
961
|
-
postJsonToApi,
|
|
962
|
-
resolve,
|
|
963
|
-
resolveProviderReference as resolveProviderReference2,
|
|
964
|
-
secureJsonParse as secureJsonParse2,
|
|
965
|
-
serializeModelOptions,
|
|
966
|
-
WORKFLOW_SERIALIZE,
|
|
967
|
-
WORKFLOW_DESERIALIZE
|
|
968
|
-
} from "@ai-sdk/provider-utils";
|
|
969
|
-
|
|
970
944
|
// src/anthropic-language-model-options.ts
|
|
971
945
|
import { z as z4 } from "zod/v4";
|
|
972
946
|
var anthropicFilePartProviderOptions = z4.object({
|
|
@@ -3732,13 +3706,13 @@ function getAnthropicStreamErrorMetadata(type) {
|
|
|
3732
3706
|
return {};
|
|
3733
3707
|
}
|
|
3734
3708
|
}
|
|
3735
|
-
function createCitationSource(citation, citationDocuments,
|
|
3709
|
+
function createCitationSource(citation, citationDocuments, generateId4) {
|
|
3736
3710
|
var _a, _b;
|
|
3737
3711
|
if (citation.type === "web_search_result_location") {
|
|
3738
3712
|
return {
|
|
3739
3713
|
type: "source",
|
|
3740
3714
|
sourceType: "url",
|
|
3741
|
-
id:
|
|
3715
|
+
id: generateId4(),
|
|
3742
3716
|
url: citation.url,
|
|
3743
3717
|
title: (_a = citation.title) != null ? _a : void 0,
|
|
3744
3718
|
providerMetadata: {
|
|
@@ -3759,7 +3733,7 @@ function createCitationSource(citation, citationDocuments, generateId3) {
|
|
|
3759
3733
|
return {
|
|
3760
3734
|
type: "source",
|
|
3761
3735
|
sourceType: "document",
|
|
3762
|
-
id:
|
|
3736
|
+
id: generateId4(),
|
|
3763
3737
|
mediaType: documentInfo.mediaType,
|
|
3764
3738
|
title: (_b = citation.document_title) != null ? _b : documentInfo.title,
|
|
3765
3739
|
filename: documentInfo.filename,
|
|
@@ -3786,6 +3760,10 @@ function getAnthropicCallerMetadata(caller) {
|
|
|
3786
3760
|
const callerInfo = getAnthropicCallerInfo(caller);
|
|
3787
3761
|
return callerInfo == null ? {} : { providerMetadata: { anthropic: { caller: callerInfo } } };
|
|
3788
3762
|
}
|
|
3763
|
+
function getProviderOptionsName(provider) {
|
|
3764
|
+
const dotIndex = provider.indexOf(".");
|
|
3765
|
+
return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
|
|
3766
|
+
}
|
|
3789
3767
|
var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
3790
3768
|
constructor(modelId, config) {
|
|
3791
3769
|
this.specificationVersion = "v4";
|
|
@@ -3809,36 +3787,31 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3809
3787
|
get provider() {
|
|
3810
3788
|
return this.config.provider;
|
|
3811
3789
|
}
|
|
3812
|
-
/**
|
|
3813
|
-
* Extracts the dynamic provider name from the config.provider string.
|
|
3814
|
-
* e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
|
|
3815
|
-
*/
|
|
3816
|
-
get providerOptionsName() {
|
|
3817
|
-
const provider = this.config.provider;
|
|
3818
|
-
const dotIndex = provider.indexOf(".");
|
|
3819
|
-
return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
|
|
3820
|
-
}
|
|
3821
3790
|
get supportedUrls() {
|
|
3822
3791
|
var _a, _b, _c;
|
|
3823
3792
|
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
3824
3793
|
}
|
|
3825
|
-
async
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3794
|
+
static async prepareRequest({
|
|
3795
|
+
modelId,
|
|
3796
|
+
config,
|
|
3797
|
+
options: {
|
|
3798
|
+
userSuppliedBetas,
|
|
3799
|
+
prompt,
|
|
3800
|
+
maxOutputTokens,
|
|
3801
|
+
temperature,
|
|
3802
|
+
topP,
|
|
3803
|
+
topK,
|
|
3804
|
+
frequencyPenalty,
|
|
3805
|
+
presencePenalty,
|
|
3806
|
+
stopSequences,
|
|
3807
|
+
responseFormat,
|
|
3808
|
+
seed,
|
|
3809
|
+
tools,
|
|
3810
|
+
toolChoice,
|
|
3811
|
+
reasoning,
|
|
3812
|
+
providerOptions,
|
|
3813
|
+
stream
|
|
3814
|
+
}
|
|
3842
3815
|
}) {
|
|
3843
3816
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3844
3817
|
const warnings = [];
|
|
@@ -3875,7 +3848,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3875
3848
|
});
|
|
3876
3849
|
}
|
|
3877
3850
|
}
|
|
3878
|
-
const providerOptionsName =
|
|
3851
|
+
const providerOptionsName = getProviderOptionsName(config.provider);
|
|
3879
3852
|
const canonicalOptions = await parseProviderOptions2({
|
|
3880
3853
|
provider: "anthropic",
|
|
3881
3854
|
providerOptions,
|
|
@@ -3900,12 +3873,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3900
3873
|
supportsXhighEffort,
|
|
3901
3874
|
rejectsThinkingDisabledAboveHighEffort,
|
|
3902
3875
|
isKnownModel
|
|
3903
|
-
} = getModelCapabilities(
|
|
3876
|
+
} = getModelCapabilities(modelId);
|
|
3904
3877
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
3905
3878
|
warnings.push({
|
|
3906
3879
|
type: "compatibility",
|
|
3907
3880
|
feature: "maxOutputTokens",
|
|
3908
|
-
details: `The model "${
|
|
3881
|
+
details: `The model "${modelId}" is unknown. The max output tokens have been limited to ${maxOutputTokensForModel}. Set maxOutputTokens explicitly to override this limit.`
|
|
3909
3882
|
});
|
|
3910
3883
|
}
|
|
3911
3884
|
if (rejectsSamplingParameters) {
|
|
@@ -3913,7 +3886,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3913
3886
|
warnings.push({
|
|
3914
3887
|
type: "unsupported",
|
|
3915
3888
|
feature: "temperature",
|
|
3916
|
-
details: `temperature is not supported by ${
|
|
3889
|
+
details: `temperature is not supported by ${modelId} and will be ignored`
|
|
3917
3890
|
});
|
|
3918
3891
|
temperature = void 0;
|
|
3919
3892
|
}
|
|
@@ -3921,7 +3894,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3921
3894
|
warnings.push({
|
|
3922
3895
|
type: "unsupported",
|
|
3923
3896
|
feature: "topK",
|
|
3924
|
-
details: `topK is not supported by ${
|
|
3897
|
+
details: `topK is not supported by ${modelId} and will be ignored`
|
|
3925
3898
|
});
|
|
3926
3899
|
topK = void 0;
|
|
3927
3900
|
}
|
|
@@ -3929,14 +3902,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3929
3902
|
warnings.push({
|
|
3930
3903
|
type: "unsupported",
|
|
3931
3904
|
feature: "topP",
|
|
3932
|
-
details: `topP is not supported by ${
|
|
3905
|
+
details: `topP is not supported by ${modelId} and will be ignored`
|
|
3933
3906
|
});
|
|
3934
3907
|
topP = void 0;
|
|
3935
3908
|
}
|
|
3936
3909
|
}
|
|
3937
|
-
const isAnthropicModel = isKnownModel ||
|
|
3938
|
-
const supportsStructuredOutput = ((_a =
|
|
3939
|
-
const supportsStrictTools = ((_b =
|
|
3910
|
+
const isAnthropicModel = isKnownModel || modelId.includes("claude-");
|
|
3911
|
+
const supportsStructuredOutput = ((_a = config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
|
|
3912
|
+
const supportsStrictTools = ((_b = config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
3940
3913
|
const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
|
|
3941
3914
|
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
3942
3915
|
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
@@ -4006,7 +3979,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4006
3979
|
warnings.push({
|
|
4007
3980
|
type: "unsupported",
|
|
4008
3981
|
feature: "providerOptions.anthropic.effort",
|
|
4009
|
-
details: `effort '${anthropicOptions.effort}' is not supported by ${
|
|
3982
|
+
details: `effort '${anthropicOptions.effort}' is not supported by ${modelId} when thinking is disabled. The effort has been lowered to 'high'.`
|
|
4010
3983
|
});
|
|
4011
3984
|
anthropicOptions.effort = "high";
|
|
4012
3985
|
}
|
|
@@ -4019,7 +3992,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4019
3992
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
4020
3993
|
const baseArgs = {
|
|
4021
3994
|
// model id:
|
|
4022
|
-
model:
|
|
3995
|
+
model: modelId,
|
|
4023
3996
|
// standardized settings:
|
|
4024
3997
|
max_tokens: maxTokens,
|
|
4025
3998
|
temperature,
|
|
@@ -4219,7 +4192,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4219
4192
|
warnings.push({
|
|
4220
4193
|
type: "unsupported",
|
|
4221
4194
|
feature: "maxOutputTokens",
|
|
4222
|
-
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${
|
|
4195
|
+
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
|
|
4223
4196
|
});
|
|
4224
4197
|
}
|
|
4225
4198
|
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
@@ -4310,6 +4283,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4310
4283
|
usedCustomProviderKey
|
|
4311
4284
|
};
|
|
4312
4285
|
}
|
|
4286
|
+
getArgs(options) {
|
|
4287
|
+
return _AnthropicLanguageModel.prepareRequest({
|
|
4288
|
+
modelId: this.modelId,
|
|
4289
|
+
config: this.config,
|
|
4290
|
+
options
|
|
4291
|
+
});
|
|
4292
|
+
}
|
|
4313
4293
|
async getHeaders({
|
|
4314
4294
|
betas,
|
|
4315
4295
|
headers
|
|
@@ -4935,7 +4915,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4935
4915
|
let activeMessageId;
|
|
4936
4916
|
let hasInvalidMessageSequence = false;
|
|
4937
4917
|
let blockType = void 0;
|
|
4938
|
-
const
|
|
4918
|
+
const generateId4 = this.generateId;
|
|
4939
4919
|
const transformedStream = response.pipeThrough(
|
|
4940
4920
|
new TransformStream({
|
|
4941
4921
|
start(controller) {
|
|
@@ -5198,7 +5178,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5198
5178
|
controller.enqueue({
|
|
5199
5179
|
type: "source",
|
|
5200
5180
|
sourceType: "url",
|
|
5201
|
-
id:
|
|
5181
|
+
id: generateId4(),
|
|
5202
5182
|
url: result.url,
|
|
5203
5183
|
...result.title != null ? { title: result.title } : {},
|
|
5204
5184
|
providerMetadata: {
|
|
@@ -5560,7 +5540,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5560
5540
|
const source = createCitationSource(
|
|
5561
5541
|
citation,
|
|
5562
5542
|
citationDocuments,
|
|
5563
|
-
|
|
5543
|
+
generateId4
|
|
5564
5544
|
);
|
|
5565
5545
|
if (source) {
|
|
5566
5546
|
controller.enqueue(source);
|
|
@@ -6000,7 +5980,30 @@ function mapAnthropicStopDetails(stopDetails) {
|
|
|
6000
5980
|
};
|
|
6001
5981
|
}
|
|
6002
5982
|
|
|
6003
|
-
// src/anthropic-
|
|
5983
|
+
// src/anthropic-batch.ts
|
|
5984
|
+
import {
|
|
5985
|
+
InvalidArgumentError,
|
|
5986
|
+
InvalidResponseDataError as InvalidResponseDataError2,
|
|
5987
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
5988
|
+
} from "@ai-sdk/provider";
|
|
5989
|
+
import {
|
|
5990
|
+
combineHeaders as combineHeaders3,
|
|
5991
|
+
convertAsyncIteratorToReadableStream,
|
|
5992
|
+
createJsonLinesResponseHandler,
|
|
5993
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
5994
|
+
generateId as generateId2,
|
|
5995
|
+
getFromApi,
|
|
5996
|
+
isRecord as isRecord2,
|
|
5997
|
+
lazySchema as lazySchema14,
|
|
5998
|
+
normalizeBatchRequestCounts,
|
|
5999
|
+
normalizeHeaders,
|
|
6000
|
+
parseProviderOptions as parseProviderOptions3,
|
|
6001
|
+
postJsonToApi as postJsonToApi2,
|
|
6002
|
+
resolve as resolve2,
|
|
6003
|
+
safeValidateTypes,
|
|
6004
|
+
zodSchema as zodSchema14
|
|
6005
|
+
} from "@ai-sdk/provider-utils";
|
|
6006
|
+
import { z as z15 } from "zod/v4";
|
|
6004
6007
|
var anthropicBatchRequestIdPattern = /^[A-Za-z0-9_-]{1,64}$/;
|
|
6005
6008
|
var anthropicBatchProviderOptionsSchema = anthropicLanguageModelOptions.pick({
|
|
6006
6009
|
anthropicBeta: true
|
|
@@ -6077,31 +6080,27 @@ var anthropicBatchResultLineSchema = lazySchema14(
|
|
|
6077
6080
|
})
|
|
6078
6081
|
)
|
|
6079
6082
|
);
|
|
6080
|
-
var
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
);
|
|
6089
|
-
}
|
|
6090
|
-
constructor(modelId, config) {
|
|
6091
|
-
super(modelId, config);
|
|
6083
|
+
var AnthropicBatch = class {
|
|
6084
|
+
constructor(options) {
|
|
6085
|
+
this.options = options;
|
|
6086
|
+
this.specificationVersion = "v4";
|
|
6087
|
+
var _a;
|
|
6088
|
+
this.provider = options.provider;
|
|
6089
|
+
this.supportedUrls = options.supportedUrls;
|
|
6090
|
+
this.generateId = (_a = options.config.generateId) != null ? _a : generateId2;
|
|
6092
6091
|
}
|
|
6093
|
-
async
|
|
6092
|
+
async doStartBatch({
|
|
6094
6093
|
requests,
|
|
6095
6094
|
providerOptions,
|
|
6096
6095
|
headers,
|
|
6097
6096
|
abortSignal,
|
|
6098
6097
|
webhookUrl
|
|
6099
6098
|
}) {
|
|
6100
|
-
var _a;
|
|
6099
|
+
var _a, _b, _c, _d;
|
|
6101
6100
|
validateRequestIds(requests);
|
|
6102
6101
|
const explicitBatchBetas = new Set(
|
|
6103
6102
|
await getAnthropicBatchProviderBetas({
|
|
6104
|
-
provider: this.config.provider,
|
|
6103
|
+
provider: this.options.config.provider,
|
|
6105
6104
|
providerOptions
|
|
6106
6105
|
})
|
|
6107
6106
|
);
|
|
@@ -6118,19 +6117,23 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6118
6117
|
];
|
|
6119
6118
|
for (const request of requests) {
|
|
6120
6119
|
const requestBetas = await getAnthropicBatchProviderBetas({
|
|
6121
|
-
provider: this.config.provider,
|
|
6120
|
+
provider: this.options.config.provider,
|
|
6122
6121
|
providerOptions: request.options.providerOptions
|
|
6123
6122
|
});
|
|
6124
6123
|
if (requestBetas.length > 0) {
|
|
6125
6124
|
throw new UnsupportedFunctionalityError3({
|
|
6126
6125
|
functionality: "per-request providerOptions.anthropic.anthropicBeta",
|
|
6127
|
-
message: `Anthropic Message Batches do not support per-request betas (request "${request.id}"). Set providerOptions.anthropic.anthropicBeta on
|
|
6126
|
+
message: `Anthropic Message Batches do not support per-request betas (request "${request.id}"). Set providerOptions.anthropic.anthropicBeta on startBatch instead.`
|
|
6128
6127
|
});
|
|
6129
6128
|
}
|
|
6130
|
-
const prepared = await
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6129
|
+
const prepared = await AnthropicLanguageModel.prepareRequest({
|
|
6130
|
+
modelId: request.modelId,
|
|
6131
|
+
config: this.options.config,
|
|
6132
|
+
options: {
|
|
6133
|
+
...request.options,
|
|
6134
|
+
stream: false,
|
|
6135
|
+
userSuppliedBetas: new Set(explicitBatchBetas)
|
|
6136
|
+
}
|
|
6134
6137
|
});
|
|
6135
6138
|
if (prepared.usesJsonResponseTool) {
|
|
6136
6139
|
throw new UnsupportedFunctionalityError3({
|
|
@@ -6147,7 +6150,11 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6147
6150
|
message: `Anthropic Message Batches cannot restore the custom provider-tool name "${aliasedProviderTool.name}" when results are retrieved independently of the start call (request "${request.id}"). Use the provider's canonical tool name.`
|
|
6148
6151
|
});
|
|
6149
6152
|
}
|
|
6150
|
-
const body = this.transformRequestBody
|
|
6153
|
+
const body = (_d = (_c = (_b = this.options.config).transformRequestBody) == null ? void 0 : _c.call(
|
|
6154
|
+
_b,
|
|
6155
|
+
prepared.args,
|
|
6156
|
+
prepared.betas
|
|
6157
|
+
)) != null ? _d : prepared.args;
|
|
6151
6158
|
validateAnthropicBatchBody({
|
|
6152
6159
|
body,
|
|
6153
6160
|
requestId: request.id
|
|
@@ -6169,7 +6176,7 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6169
6176
|
anthropicBatchResponseSchema
|
|
6170
6177
|
),
|
|
6171
6178
|
abortSignal,
|
|
6172
|
-
fetch: this.config.fetch
|
|
6179
|
+
fetch: this.options.config.fetch
|
|
6173
6180
|
});
|
|
6174
6181
|
return {
|
|
6175
6182
|
batchId: batch.id,
|
|
@@ -6177,10 +6184,10 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6177
6184
|
warnings: batchWarnings
|
|
6178
6185
|
};
|
|
6179
6186
|
}
|
|
6180
|
-
async
|
|
6187
|
+
async doGetBatchStatus(options) {
|
|
6181
6188
|
return convertAnthropicBatchStatus(await this.retrieveBatch(options));
|
|
6182
6189
|
}
|
|
6183
|
-
async
|
|
6190
|
+
async doGetBatchResults(options) {
|
|
6184
6191
|
const batch = await this.retrieveBatch(options);
|
|
6185
6192
|
if (convertAnthropicBatchStatus(batch).status === "pending") {
|
|
6186
6193
|
throw new InvalidArgumentError({
|
|
@@ -6203,15 +6210,15 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6203
6210
|
const { value: lines } = await getFromApi({
|
|
6204
6211
|
url: batch.results_url,
|
|
6205
6212
|
validateUrl: true,
|
|
6206
|
-
credentialedOrigin: this.config.baseURL,
|
|
6207
|
-
trustedOrigin: this.config.baseURL,
|
|
6213
|
+
credentialedOrigin: this.options.config.baseURL,
|
|
6214
|
+
trustedOrigin: this.options.config.baseURL,
|
|
6208
6215
|
headers: await this.getBatchHeaders(options.headers),
|
|
6209
6216
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
6210
6217
|
successfulResponseHandler: createJsonLinesResponseHandler(
|
|
6211
6218
|
anthropicBatchResultLineSchema
|
|
6212
6219
|
),
|
|
6213
6220
|
abortSignal: options.abortSignal,
|
|
6214
|
-
fetch: this.config.fetch
|
|
6221
|
+
fetch: this.options.config.fetch
|
|
6215
6222
|
});
|
|
6216
6223
|
return convertAsyncIteratorToReadableStream(
|
|
6217
6224
|
this.iterateBatchResults(lines)
|
|
@@ -6227,7 +6234,7 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6227
6234
|
anthropicBatchResponseSchema
|
|
6228
6235
|
),
|
|
6229
6236
|
abortSignal: options.abortSignal,
|
|
6230
|
-
fetch: this.config.fetch
|
|
6237
|
+
fetch: this.options.config.fetch
|
|
6231
6238
|
});
|
|
6232
6239
|
return batch;
|
|
6233
6240
|
}
|
|
@@ -6237,7 +6244,7 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6237
6244
|
}
|
|
6238
6245
|
}
|
|
6239
6246
|
getBatchUrl(path) {
|
|
6240
|
-
return `${this.config.baseURL}/messages/batches${path}`;
|
|
6247
|
+
return `${this.options.config.baseURL}/messages/batches${path}`;
|
|
6241
6248
|
}
|
|
6242
6249
|
async getStartBatchHeaders({
|
|
6243
6250
|
betas,
|
|
@@ -6252,7 +6259,7 @@ var AnthropicMessagesBatchLanguageModel = class _AnthropicMessagesBatchLanguageM
|
|
|
6252
6259
|
}
|
|
6253
6260
|
async getBatchHeaders(headers) {
|
|
6254
6261
|
return combineHeaders3(
|
|
6255
|
-
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
6262
|
+
this.options.config.headers ? await resolve2(this.options.config.headers) : void 0,
|
|
6256
6263
|
headers
|
|
6257
6264
|
);
|
|
6258
6265
|
}
|
|
@@ -6355,7 +6362,7 @@ function convertAnthropicRequestCounts(counts) {
|
|
|
6355
6362
|
failed: counts.errored + counts.canceled + counts.expired
|
|
6356
6363
|
});
|
|
6357
6364
|
}
|
|
6358
|
-
async function convertAnthropicBatchResult(line,
|
|
6365
|
+
async function convertAnthropicBatchResult(line, generateId4) {
|
|
6359
6366
|
const resultValidation = await safeValidateTypes({
|
|
6360
6367
|
value: line.result,
|
|
6361
6368
|
schema: anthropicBatchResultSchema
|
|
@@ -6366,12 +6373,13 @@ async function convertAnthropicBatchResult(line, generateId3) {
|
|
|
6366
6373
|
const result = resultValidation.value;
|
|
6367
6374
|
switch (result.type) {
|
|
6368
6375
|
case "canceled":
|
|
6369
|
-
return { id: line.custom_id, status: "cancelled" };
|
|
6376
|
+
return { type: "text", id: line.custom_id, status: "cancelled" };
|
|
6370
6377
|
case "expired":
|
|
6371
|
-
return { id: line.custom_id, status: "expired" };
|
|
6378
|
+
return { type: "text", id: line.custom_id, status: "expired" };
|
|
6372
6379
|
case "errored": {
|
|
6373
6380
|
const requestId = result.error.request_id;
|
|
6374
6381
|
return {
|
|
6382
|
+
type: "text",
|
|
6375
6383
|
id: line.custom_id,
|
|
6376
6384
|
status: "failed",
|
|
6377
6385
|
error: {
|
|
@@ -6391,15 +6399,17 @@ async function convertAnthropicBatchResult(line, generateId3) {
|
|
|
6391
6399
|
return invalidAnthropicBatchResult(line.custom_id);
|
|
6392
6400
|
}
|
|
6393
6401
|
return {
|
|
6402
|
+
type: "text",
|
|
6394
6403
|
id: line.custom_id,
|
|
6395
6404
|
status: "succeeded",
|
|
6396
|
-
result: convertAnthropicBatchResponse(response,
|
|
6405
|
+
result: convertAnthropicBatchResponse(response, generateId4)
|
|
6397
6406
|
};
|
|
6398
6407
|
}
|
|
6399
6408
|
}
|
|
6400
6409
|
}
|
|
6401
6410
|
function invalidAnthropicBatchResult(id) {
|
|
6402
6411
|
return {
|
|
6412
|
+
type: "text",
|
|
6403
6413
|
id,
|
|
6404
6414
|
status: "failed",
|
|
6405
6415
|
error: {
|
|
@@ -6440,7 +6450,7 @@ async function parseAnthropicBatchResponse(message) {
|
|
|
6440
6450
|
});
|
|
6441
6451
|
return recovered.success ? recovered.value : void 0;
|
|
6442
6452
|
}
|
|
6443
|
-
function convertAnthropicBatchResponse(response,
|
|
6453
|
+
function convertAnthropicBatchResponse(response, generateId4) {
|
|
6444
6454
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6445
6455
|
const content = [];
|
|
6446
6456
|
const mcpToolCalls = {};
|
|
@@ -6459,7 +6469,7 @@ function convertAnthropicBatchResponse(response, generateId3) {
|
|
|
6459
6469
|
}
|
|
6460
6470
|
});
|
|
6461
6471
|
for (const citation of (_a = part.citations) != null ? _a : []) {
|
|
6462
|
-
const source = createCitationSource(citation, [],
|
|
6472
|
+
const source = createCitationSource(citation, [], generateId4);
|
|
6463
6473
|
if (source != null) {
|
|
6464
6474
|
content.push(source);
|
|
6465
6475
|
}
|
|
@@ -6627,7 +6637,7 @@ function convertAnthropicBatchResponse(response, generateId3) {
|
|
|
6627
6637
|
content.push({
|
|
6628
6638
|
type: "source",
|
|
6629
6639
|
sourceType: "url",
|
|
6630
|
-
id:
|
|
6640
|
+
id: generateId4(),
|
|
6631
6641
|
url: result.url,
|
|
6632
6642
|
...result.title != null ? { title: result.title } : {},
|
|
6633
6643
|
providerMetadata: {
|
|
@@ -7563,7 +7573,7 @@ var AnthropicSkills = class {
|
|
|
7563
7573
|
};
|
|
7564
7574
|
|
|
7565
7575
|
// src/version.ts
|
|
7566
|
-
var VERSION = true ? "4.0.
|
|
7576
|
+
var VERSION = true ? "4.0.50" : "0.0.0-test";
|
|
7567
7577
|
|
|
7568
7578
|
// src/anthropic-provider.ts
|
|
7569
7579
|
var ANTHROPIC_API_URL = "https://api.anthropic.com";
|
|
@@ -7575,7 +7585,7 @@ function normalizeBaseURL(baseURL) {
|
|
|
7575
7585
|
return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL ? ANTHROPIC_API_VERSIONED_URL : baseURLWithoutTrailingSlash;
|
|
7576
7586
|
}
|
|
7577
7587
|
function createAnthropic(options = {}) {
|
|
7578
|
-
var _a, _b;
|
|
7588
|
+
var _a, _b, _c;
|
|
7579
7589
|
const baseURL = (_a = normalizeBaseURL(
|
|
7580
7590
|
loadOptionalSetting({
|
|
7581
7591
|
settingValue: options.baseURL,
|
|
@@ -7583,6 +7593,10 @@ function createAnthropic(options = {}) {
|
|
|
7583
7593
|
})
|
|
7584
7594
|
)) != null ? _a : ANTHROPIC_API_VERSIONED_URL;
|
|
7585
7595
|
const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
|
|
7596
|
+
const supportedUrls = {
|
|
7597
|
+
"image/*": [/^https?:\/\/.*$/],
|
|
7598
|
+
"application/pdf": [/^https?:\/\/.*$/]
|
|
7599
|
+
};
|
|
7586
7600
|
if (options.apiKey && options.authToken) {
|
|
7587
7601
|
throw new InvalidArgumentError2({
|
|
7588
7602
|
argument: "apiKey/authToken",
|
|
@@ -7606,20 +7620,20 @@ function createAnthropic(options = {}) {
|
|
|
7606
7620
|
`ai-sdk/anthropic/${VERSION}`
|
|
7607
7621
|
);
|
|
7608
7622
|
};
|
|
7609
|
-
const
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2,
|
|
7617
|
-
supportedUrls: () => ({
|
|
7618
|
-
"image/*": [/^https?:\/\/.*$/],
|
|
7619
|
-
"application/pdf": [/^https?:\/\/.*$/]
|
|
7620
|
-
})
|
|
7621
|
-
});
|
|
7623
|
+
const languageModelConfig = {
|
|
7624
|
+
provider: providerName,
|
|
7625
|
+
baseURL,
|
|
7626
|
+
headers: getHeaders,
|
|
7627
|
+
fetch: options.fetch,
|
|
7628
|
+
generateId: (_c = options.generateId) != null ? _c : generateId3,
|
|
7629
|
+
supportedUrls: () => supportedUrls
|
|
7622
7630
|
};
|
|
7631
|
+
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, languageModelConfig);
|
|
7632
|
+
const createBatch = () => new AnthropicBatch({
|
|
7633
|
+
provider: `${providerName.replace(/\.messages$/, "")}.batch`,
|
|
7634
|
+
config: languageModelConfig,
|
|
7635
|
+
supportedUrls
|
|
7636
|
+
});
|
|
7623
7637
|
const createSkills = () => new AnthropicSkills({
|
|
7624
7638
|
provider: `${providerName.replace(".messages", "")}.skills`,
|
|
7625
7639
|
baseURL,
|
|
@@ -7638,6 +7652,7 @@ function createAnthropic(options = {}) {
|
|
|
7638
7652
|
provider.languageModel = createChatModel;
|
|
7639
7653
|
provider.chat = createChatModel;
|
|
7640
7654
|
provider.messages = createChatModel;
|
|
7655
|
+
provider.experimental_batch = createBatch;
|
|
7641
7656
|
provider.embeddingModel = (modelId) => {
|
|
7642
7657
|
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
7643
7658
|
};
|