@ai-sdk/anthropic-aws 1.0.14 → 2.0.0
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 +117 -58
- package/README.md +2 -2
- package/dist/index.d.ts +11 -6
- package/dist/index.js +60 -61
- package/dist/index.js.map +1 -1
- package/docs/07-anthropic-aws.mdx +12 -12
- package/package.json +13 -12
- package/src/anthropic-aws-provider.ts +39 -12
- package/dist/index.d.mts +0 -94
- package/dist/index.mjs +0 -235
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,119 +1,178 @@
|
|
|
1
1
|
# @ai-sdk/anthropic-aws
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- a23b676: Release `@ai-sdk/anthropic-aws` as `2.0.0`. The provider was initially published as `1.0.0` because its `major` changeset was applied to the package's starting `0.0.1` version (`0.0.1` → `1.0.0`) rather than to the `1.0.0` intended for its first stable release. This major bump corrects the version to `2.0.0` to reflect the intended v2 line.
|
|
8
|
+
|
|
9
|
+
## 1.0.8
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
6
12
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
- @ai-sdk/
|
|
9
|
-
- @ai-sdk/anthropic@3.0.92
|
|
13
|
+
- Updated dependencies [0aa0ff3]
|
|
14
|
+
- @ai-sdk/anthropic@4.0.8
|
|
10
15
|
|
|
11
|
-
## 1.0.
|
|
16
|
+
## 1.0.7
|
|
12
17
|
|
|
13
18
|
### Patch Changes
|
|
14
19
|
|
|
15
|
-
-
|
|
16
|
-
- Updated dependencies [
|
|
17
|
-
- @ai-sdk/
|
|
18
|
-
- @ai-sdk/provider@
|
|
19
|
-
- @ai-sdk/
|
|
20
|
+
- 5c5c0f5: Add experimental streaming transcription support for transcription models, including OpenAI `gpt-realtime-whisper` and xAI WebSocket STT.
|
|
21
|
+
- Updated dependencies [5c5c0f5]
|
|
22
|
+
- @ai-sdk/provider@4.0.2
|
|
23
|
+
- @ai-sdk/provider-utils@5.0.5
|
|
24
|
+
- @ai-sdk/anthropic@4.0.7
|
|
20
25
|
|
|
21
|
-
## 1.0.
|
|
26
|
+
## 1.0.6
|
|
22
27
|
|
|
23
28
|
### Patch Changes
|
|
24
29
|
|
|
25
|
-
- Updated dependencies [
|
|
26
|
-
|
|
30
|
+
- Updated dependencies [c6f5e62]
|
|
31
|
+
- Updated dependencies [679c52a]
|
|
32
|
+
- @ai-sdk/anthropic@4.0.6
|
|
33
|
+
- @ai-sdk/provider-utils@5.0.4
|
|
27
34
|
|
|
28
|
-
## 1.0.
|
|
35
|
+
## 1.0.5
|
|
29
36
|
|
|
30
37
|
### Patch Changes
|
|
31
38
|
|
|
32
|
-
- Updated dependencies [
|
|
33
|
-
- @ai-sdk/provider-utils@
|
|
34
|
-
- @ai-sdk/anthropic@
|
|
39
|
+
- Updated dependencies [8c616f0]
|
|
40
|
+
- @ai-sdk/provider-utils@5.0.3
|
|
41
|
+
- @ai-sdk/anthropic@4.0.5
|
|
35
42
|
|
|
36
|
-
## 1.0.
|
|
43
|
+
## 1.0.4
|
|
37
44
|
|
|
38
45
|
### Patch Changes
|
|
39
46
|
|
|
40
|
-
- Updated dependencies [
|
|
41
|
-
- @ai-sdk/
|
|
42
|
-
- @ai-sdk/anthropic@3.0.88
|
|
43
|
-
- @ai-sdk/provider-utils@4.0.32
|
|
47
|
+
- Updated dependencies [c18018c]
|
|
48
|
+
- @ai-sdk/anthropic@4.0.4
|
|
44
49
|
|
|
45
|
-
## 1.0.
|
|
50
|
+
## 1.0.3
|
|
46
51
|
|
|
47
52
|
### Patch Changes
|
|
48
53
|
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
- @ai-sdk/anthropic@
|
|
52
|
-
- @ai-sdk/provider-utils@
|
|
53
|
-
- @ai-sdk/provider@3.0.11
|
|
54
|
+
- Updated dependencies [0274f34]
|
|
55
|
+
- @ai-sdk/provider@4.0.1
|
|
56
|
+
- @ai-sdk/anthropic@4.0.3
|
|
57
|
+
- @ai-sdk/provider-utils@5.0.2
|
|
54
58
|
|
|
55
|
-
## 1.0.
|
|
59
|
+
## 1.0.2
|
|
56
60
|
|
|
57
61
|
### Patch Changes
|
|
58
62
|
|
|
59
|
-
- Updated dependencies [
|
|
60
|
-
- @ai-sdk/anthropic@
|
|
63
|
+
- Updated dependencies [dfffb27]
|
|
64
|
+
- @ai-sdk/anthropic@4.0.2
|
|
61
65
|
|
|
62
|
-
## 1.0.
|
|
66
|
+
## 1.0.1
|
|
63
67
|
|
|
64
68
|
### Patch Changes
|
|
65
69
|
|
|
66
|
-
- Updated dependencies [
|
|
67
|
-
- @ai-sdk/provider-utils@
|
|
68
|
-
- @ai-sdk/anthropic@
|
|
70
|
+
- Updated dependencies [6a436e3]
|
|
71
|
+
- @ai-sdk/provider-utils@5.0.1
|
|
72
|
+
- @ai-sdk/anthropic@4.0.1
|
|
69
73
|
|
|
70
|
-
## 1.0.
|
|
74
|
+
## 1.0.0
|
|
75
|
+
|
|
76
|
+
### Major Changes
|
|
77
|
+
|
|
78
|
+
- e617cba: feat(anthropic-aws): add Claude Platform on AWS provider
|
|
71
79
|
|
|
72
80
|
### Patch Changes
|
|
73
81
|
|
|
74
|
-
-
|
|
75
|
-
- Updated dependencies [f42aa79]
|
|
76
|
-
- @ai-sdk/provider-utils@4.0.29
|
|
77
|
-
- @ai-sdk/anthropic@3.0.84
|
|
82
|
+
- b8396f0: trigger initial beta release
|
|
78
83
|
|
|
79
|
-
## 1.0.
|
|
84
|
+
## 1.0.0-beta.10
|
|
80
85
|
|
|
81
86
|
### Patch Changes
|
|
82
87
|
|
|
83
|
-
- Updated dependencies [
|
|
84
|
-
- @ai-sdk/
|
|
85
|
-
- @ai-sdk/anthropic@3.0.83
|
|
88
|
+
- Updated dependencies [19c5ee2]
|
|
89
|
+
- @ai-sdk/anthropic@4.0.0-beta.69
|
|
86
90
|
|
|
87
|
-
## 1.0.
|
|
91
|
+
## 1.0.0-beta.9
|
|
88
92
|
|
|
89
93
|
### Patch Changes
|
|
90
94
|
|
|
91
|
-
- Updated dependencies [
|
|
92
|
-
- @ai-sdk/
|
|
95
|
+
- Updated dependencies [0416e3e]
|
|
96
|
+
- @ai-sdk/provider@4.0.0-beta.20
|
|
97
|
+
- @ai-sdk/anthropic@4.0.0-beta.68
|
|
98
|
+
- @ai-sdk/provider-utils@5.0.0-beta.50
|
|
93
99
|
|
|
94
|
-
## 1.0.
|
|
100
|
+
## 1.0.0-beta.8
|
|
95
101
|
|
|
96
102
|
### Patch Changes
|
|
97
103
|
|
|
98
|
-
-
|
|
99
|
-
|
|
104
|
+
- b8396f0: trigger initial beta release
|
|
105
|
+
- Updated dependencies [b8396f0]
|
|
106
|
+
- @ai-sdk/anthropic@4.0.0-beta.67
|
|
107
|
+
- @ai-sdk/provider-utils@5.0.0-beta.49
|
|
108
|
+
- @ai-sdk/provider@4.0.0-beta.19
|
|
100
109
|
|
|
101
|
-
## 1.0.
|
|
110
|
+
## 1.0.0-canary.7
|
|
102
111
|
|
|
103
112
|
### Patch Changes
|
|
104
113
|
|
|
105
|
-
- Updated dependencies [
|
|
106
|
-
|
|
114
|
+
- Updated dependencies [aeda373]
|
|
115
|
+
- Updated dependencies [375fdd7]
|
|
116
|
+
- Updated dependencies [b4507d5]
|
|
117
|
+
- @ai-sdk/provider-utils@5.0.0-canary.48
|
|
118
|
+
- @ai-sdk/anthropic@4.0.0-canary.66
|
|
107
119
|
|
|
108
|
-
## 1.0.
|
|
120
|
+
## 1.0.0-canary.6
|
|
109
121
|
|
|
110
122
|
### Patch Changes
|
|
111
123
|
|
|
112
|
-
- Updated dependencies [
|
|
113
|
-
- @ai-sdk/
|
|
124
|
+
- Updated dependencies [bae5e2b]
|
|
125
|
+
- @ai-sdk/provider-utils@5.0.0-canary.47
|
|
126
|
+
- @ai-sdk/anthropic@4.0.0-canary.65
|
|
114
127
|
|
|
115
|
-
## 1.0.0
|
|
128
|
+
## 1.0.0-canary.5
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- Updated dependencies [6b4d325]
|
|
133
|
+
- @ai-sdk/anthropic@4.0.0-canary.64
|
|
134
|
+
|
|
135
|
+
## 1.0.0-canary.4
|
|
136
|
+
|
|
137
|
+
### Patch Changes
|
|
138
|
+
|
|
139
|
+
- Updated dependencies [ce769dd]
|
|
140
|
+
- @ai-sdk/provider@4.0.0-canary.18
|
|
141
|
+
- @ai-sdk/anthropic@4.0.0-canary.63
|
|
142
|
+
- @ai-sdk/provider-utils@5.0.0-canary.46
|
|
143
|
+
|
|
144
|
+
## 1.0.0-canary.3
|
|
145
|
+
|
|
146
|
+
### Patch Changes
|
|
147
|
+
|
|
148
|
+
- Updated dependencies [ee798eb]
|
|
149
|
+
- Updated dependencies [daf6637]
|
|
150
|
+
- @ai-sdk/provider-utils@5.0.0-canary.45
|
|
151
|
+
- @ai-sdk/anthropic@4.0.0-canary.62
|
|
152
|
+
|
|
153
|
+
## 1.0.0-canary.2
|
|
154
|
+
|
|
155
|
+
### Patch Changes
|
|
156
|
+
|
|
157
|
+
- Updated dependencies [e02f041]
|
|
158
|
+
- @ai-sdk/anthropic@4.0.0-canary.61
|
|
159
|
+
|
|
160
|
+
## 1.0.0-canary.1
|
|
161
|
+
|
|
162
|
+
### Patch Changes
|
|
163
|
+
|
|
164
|
+
- Updated dependencies [6c93e36]
|
|
165
|
+
- Updated dependencies [f617ac2]
|
|
166
|
+
- @ai-sdk/provider-utils@5.0.0-canary.44
|
|
167
|
+
- @ai-sdk/anthropic@4.0.0-canary.60
|
|
168
|
+
|
|
169
|
+
## 1.0.0-canary.0
|
|
116
170
|
|
|
117
171
|
### Major Changes
|
|
118
172
|
|
|
119
|
-
-
|
|
173
|
+
- e617cba: feat(anthropic-aws): add Claude Platform on AWS provider
|
|
174
|
+
|
|
175
|
+
### Patch Changes
|
|
176
|
+
|
|
177
|
+
- Updated dependencies [648705c]
|
|
178
|
+
- @ai-sdk/anthropic@4.0.0-canary.59
|
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@ gives you access to the Anthropic Messages API hosted in AWS at
|
|
|
6
6
|
AWS-provisioned API key.
|
|
7
7
|
|
|
8
8
|
Same wire format and feature set as `@ai-sdk/anthropic` — model IDs, streaming,
|
|
9
|
-
prompt caching, tool use, computer use, and `anthropic-beta`
|
|
10
|
-
the first-party Claude API.
|
|
9
|
+
prompt caching, tool use, computer use, Agent Skills, and `anthropic-beta`
|
|
10
|
+
headers all match the first-party Claude API.
|
|
11
11
|
|
|
12
12
|
## Setup
|
|
13
13
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderV4, LanguageModelV4, FilesV4, SkillsV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { AnthropicModelId, anthropicTools } from '@ai-sdk/anthropic/internal';
|
|
4
4
|
|
|
5
5
|
interface AnthropicAwsCredentials {
|
|
6
6
|
region: string;
|
|
@@ -9,25 +9,30 @@ interface AnthropicAwsCredentials {
|
|
|
9
9
|
sessionToken?: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface AnthropicAwsProvider extends
|
|
12
|
+
interface AnthropicAwsProvider extends ProviderV4 {
|
|
13
13
|
/**
|
|
14
14
|
* Creates a model for text generation.
|
|
15
15
|
*/
|
|
16
|
-
(modelId:
|
|
16
|
+
(modelId: AnthropicModelId): LanguageModelV4;
|
|
17
17
|
/**
|
|
18
18
|
* Creates a model for text generation.
|
|
19
19
|
*/
|
|
20
|
-
languageModel(modelId:
|
|
20
|
+
languageModel(modelId: AnthropicModelId): LanguageModelV4;
|
|
21
21
|
/**
|
|
22
22
|
* @deprecated Use `embeddingModel` instead.
|
|
23
23
|
*/
|
|
24
24
|
textEmbeddingModel(modelId: string): never;
|
|
25
|
+
files(): FilesV4;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a SkillsV4 interface for uploading skills to Anthropic.
|
|
28
|
+
*/
|
|
29
|
+
skills(): SkillsV4;
|
|
25
30
|
tools: typeof anthropicTools;
|
|
26
31
|
}
|
|
27
32
|
interface AnthropicAwsProviderSettings {
|
|
28
33
|
/**
|
|
29
34
|
* The AWS region to use for Claude Platform on AWS. Defaults to the value of the
|
|
30
|
-
* `AWS_REGION` environment variable. Required — no fallback default.
|
|
35
|
+
* `AWS_REGION` environment variable. Required — there is no fallback default.
|
|
31
36
|
*/
|
|
32
37
|
region?: string;
|
|
33
38
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
anthropicAws: () => anthropicAws,
|
|
25
|
-
createAnthropicAws: () => createAnthropicAws
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/anthropic-aws-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadOptionalSetting,
|
|
7
|
+
loadSetting,
|
|
8
|
+
withoutTrailingSlash
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
10
|
+
import {
|
|
11
|
+
AnthropicFiles,
|
|
12
|
+
AnthropicLanguageModel,
|
|
13
|
+
AnthropicSkills,
|
|
14
|
+
anthropicTools
|
|
15
|
+
} from "@ai-sdk/anthropic/internal";
|
|
33
16
|
|
|
34
17
|
// src/anthropic-aws-fetch.ts
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
import {
|
|
19
|
+
combineHeaders,
|
|
20
|
+
normalizeHeaders,
|
|
21
|
+
withUserAgentSuffix,
|
|
22
|
+
getRuntimeEnvironmentUserAgent
|
|
23
|
+
} from "@ai-sdk/provider-utils";
|
|
24
|
+
import { AwsV4Signer } from "aws4fetch";
|
|
37
25
|
|
|
38
26
|
// src/version.ts
|
|
39
|
-
var VERSION = true ? "
|
|
27
|
+
var VERSION = true ? "2.0.0" : "0.0.0-test";
|
|
40
28
|
|
|
41
29
|
// src/anthropic-aws-fetch.ts
|
|
42
30
|
function createSigV4FetchFunction(getCredentials, fetch) {
|
|
@@ -44,14 +32,14 @@ function createSigV4FetchFunction(getCredentials, fetch) {
|
|
|
44
32
|
var _a, _b;
|
|
45
33
|
const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
|
|
46
34
|
const request = input instanceof Request ? input : void 0;
|
|
47
|
-
const originalHeaders =
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
const originalHeaders = combineHeaders(
|
|
36
|
+
normalizeHeaders(request == null ? void 0 : request.headers),
|
|
37
|
+
normalizeHeaders(init == null ? void 0 : init.headers)
|
|
50
38
|
);
|
|
51
|
-
const headersWithUserAgent =
|
|
39
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
52
40
|
originalHeaders,
|
|
53
41
|
`ai-sdk/anthropic-aws/${VERSION}`,
|
|
54
|
-
|
|
42
|
+
getRuntimeEnvironmentUserAgent()
|
|
55
43
|
);
|
|
56
44
|
let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
|
|
57
45
|
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
@@ -70,7 +58,7 @@ function createSigV4FetchFunction(getCredentials, fetch) {
|
|
|
70
58
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
71
59
|
const body = prepareBodyString(effectiveBody);
|
|
72
60
|
const credentials = await getCredentials();
|
|
73
|
-
const signer = new
|
|
61
|
+
const signer = new AwsV4Signer({
|
|
74
62
|
url,
|
|
75
63
|
method: "POST",
|
|
76
64
|
headers: Object.entries(headersWithUserAgent),
|
|
@@ -82,8 +70,8 @@ function createSigV4FetchFunction(getCredentials, fetch) {
|
|
|
82
70
|
service: "aws-external-anthropic"
|
|
83
71
|
});
|
|
84
72
|
const signingResult = await signer.sign();
|
|
85
|
-
const signedHeaders =
|
|
86
|
-
const combinedHeaders =
|
|
73
|
+
const signedHeaders = normalizeHeaders(signingResult.headers);
|
|
74
|
+
const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);
|
|
87
75
|
return effectiveFetch(input, {
|
|
88
76
|
...init,
|
|
89
77
|
body,
|
|
@@ -105,13 +93,13 @@ function prepareBodyString(body) {
|
|
|
105
93
|
function createApiKeyFetchFunction(apiKey, fetch) {
|
|
106
94
|
return async (input, init) => {
|
|
107
95
|
const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
|
|
108
|
-
const originalHeaders =
|
|
109
|
-
const headersWithUserAgent =
|
|
96
|
+
const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
97
|
+
const headersWithUserAgent = withUserAgentSuffix(
|
|
110
98
|
originalHeaders,
|
|
111
99
|
`ai-sdk/anthropic-aws/${VERSION}`,
|
|
112
|
-
|
|
100
|
+
getRuntimeEnvironmentUserAgent()
|
|
113
101
|
);
|
|
114
|
-
const finalHeaders =
|
|
102
|
+
const finalHeaders = combineHeaders(headersWithUserAgent, {
|
|
115
103
|
"x-api-key": apiKey
|
|
116
104
|
});
|
|
117
105
|
return effectiveFetch(input, {
|
|
@@ -123,12 +111,12 @@ function createApiKeyFetchFunction(apiKey, fetch) {
|
|
|
123
111
|
|
|
124
112
|
// src/anthropic-aws-provider.ts
|
|
125
113
|
function createAnthropicAws(options = {}) {
|
|
126
|
-
const apiKey =
|
|
114
|
+
const apiKey = loadOptionalSetting({
|
|
127
115
|
settingValue: options.apiKey,
|
|
128
116
|
environmentVariableName: "ANTHROPIC_AWS_API_KEY"
|
|
129
117
|
});
|
|
130
118
|
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
131
|
-
const region =
|
|
119
|
+
const region = loadSetting({
|
|
132
120
|
settingValue: options.region,
|
|
133
121
|
settingName: "region",
|
|
134
122
|
environmentVariableName: "AWS_REGION",
|
|
@@ -150,19 +138,19 @@ function createAnthropicAws(options = {}) {
|
|
|
150
138
|
try {
|
|
151
139
|
return {
|
|
152
140
|
region,
|
|
153
|
-
accessKeyId:
|
|
141
|
+
accessKeyId: loadSetting({
|
|
154
142
|
settingValue: options.accessKeyId,
|
|
155
143
|
settingName: "accessKeyId",
|
|
156
144
|
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
157
145
|
description: "AWS access key ID"
|
|
158
146
|
}),
|
|
159
|
-
secretAccessKey:
|
|
147
|
+
secretAccessKey: loadSetting({
|
|
160
148
|
settingValue: options.secretAccessKey,
|
|
161
149
|
settingName: "secretAccessKey",
|
|
162
150
|
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
163
151
|
description: "AWS secret access key"
|
|
164
152
|
}),
|
|
165
|
-
sessionToken:
|
|
153
|
+
sessionToken: loadOptionalSetting({
|
|
166
154
|
settingValue: options.sessionToken,
|
|
167
155
|
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
168
156
|
})
|
|
@@ -190,7 +178,7 @@ Original error: ${errorMessage}`
|
|
|
190
178
|
}, options.fetch);
|
|
191
179
|
const getBaseURL = () => {
|
|
192
180
|
var _a;
|
|
193
|
-
return (_a =
|
|
181
|
+
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : `https://aws-external-anthropic.${loadSetting({
|
|
194
182
|
settingValue: options.region,
|
|
195
183
|
settingName: "region",
|
|
196
184
|
environmentVariableName: "AWS_REGION",
|
|
@@ -199,7 +187,7 @@ Original error: ${errorMessage}`
|
|
|
199
187
|
};
|
|
200
188
|
const getHeaders = () => ({
|
|
201
189
|
"anthropic-version": "2023-06-01",
|
|
202
|
-
"anthropic-workspace-id":
|
|
190
|
+
"anthropic-workspace-id": loadSetting({
|
|
203
191
|
settingValue: options.workspaceId,
|
|
204
192
|
settingName: "workspaceId",
|
|
205
193
|
environmentVariableName: "ANTHROPIC_AWS_WORKSPACE_ID",
|
|
@@ -207,7 +195,7 @@ Original error: ${errorMessage}`
|
|
|
207
195
|
}),
|
|
208
196
|
...options.headers
|
|
209
197
|
});
|
|
210
|
-
const createChatModel = (modelId) => new
|
|
198
|
+
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, {
|
|
211
199
|
provider: "anthropic-aws.messages",
|
|
212
200
|
baseURL: getBaseURL(),
|
|
213
201
|
headers: getHeaders,
|
|
@@ -226,25 +214,36 @@ Original error: ${errorMessage}`
|
|
|
226
214
|
}
|
|
227
215
|
return createChatModel(modelId);
|
|
228
216
|
};
|
|
229
|
-
provider.specificationVersion = "
|
|
217
|
+
provider.specificationVersion = "v4";
|
|
230
218
|
provider.languageModel = createChatModel;
|
|
231
219
|
provider.chat = createChatModel;
|
|
232
220
|
provider.messages = createChatModel;
|
|
233
221
|
provider.embeddingModel = (modelId) => {
|
|
234
|
-
throw new
|
|
222
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
235
223
|
};
|
|
236
224
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
237
225
|
provider.imageModel = (modelId) => {
|
|
238
|
-
throw new
|
|
226
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
239
227
|
};
|
|
240
|
-
provider.
|
|
228
|
+
provider.files = () => new AnthropicFiles({
|
|
229
|
+
provider: "anthropic-aws.messages",
|
|
230
|
+
baseURL: getBaseURL(),
|
|
231
|
+
headers: getHeaders,
|
|
232
|
+
fetch: fetchFunction
|
|
233
|
+
});
|
|
234
|
+
provider.skills = () => new AnthropicSkills({
|
|
235
|
+
provider: "anthropic-aws.skills",
|
|
236
|
+
baseURL: getBaseURL(),
|
|
237
|
+
headers: getHeaders,
|
|
238
|
+
fetch: fetchFunction
|
|
239
|
+
});
|
|
240
|
+
provider.tools = anthropicTools;
|
|
241
241
|
return provider;
|
|
242
242
|
}
|
|
243
243
|
var anthropicAws = createAnthropicAws();
|
|
244
|
-
|
|
245
|
-
0 && (module.exports = {
|
|
244
|
+
export {
|
|
246
245
|
VERSION,
|
|
247
246
|
anthropicAws,
|
|
248
247
|
createAnthropicAws
|
|
249
|
-
}
|
|
248
|
+
};
|
|
250
249
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/anthropic-aws-provider.ts","../src/anthropic-aws-fetch.ts","../src/version.ts"],"sourcesContent":["export { anthropicAws, createAnthropicAws } from './anthropic-aws-provider';\nexport type {\n AnthropicAwsProvider,\n AnthropicAwsProviderSettings,\n} from './anthropic-aws-provider';\nexport type { AnthropicAwsCredentials } from './anthropic-aws-fetch';\nexport { VERSION } from './version';\n","import {\n NoSuchModelError,\n type LanguageModelV3,\n type ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n AnthropicMessagesLanguageModel,\n anthropicTools,\n type AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AnthropicAwsCredentials,\n} from './anthropic-aws-fetch';\n\nexport interface AnthropicAwsProvider extends ProviderV3 {\n /**\n * Creates a model for text generation.\n */\n (modelId: AnthropicMessagesModelId): LanguageModelV3;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n\n tools: typeof anthropicTools;\n}\n\nexport interface AnthropicAwsProviderSettings {\n /**\n * The AWS region to use for Claude Platform on AWS. Defaults to the value of the\n * `AWS_REGION` environment variable. Required — no fallback default.\n */\n region?: string;\n\n /**\n * The Anthropic workspace ID for this AWS account. Sent on every request via the\n * `anthropic-workspace-id` header. Defaults to the value of the\n * `ANTHROPIC_AWS_WORKSPACE_ID` environment variable.\n */\n workspaceId?: string;\n\n /**\n * API key for authenticating requests via the `x-api-key` header.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `ANTHROPIC_AWS_API_KEY` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Claude Platform on AWS API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use to get dynamic credentials similar to the\n * AWS SDK. Setting a provider here will cause its credential values to be used\n * instead of the `accessKeyId`, `secretAccessKey`, and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AnthropicAwsCredentials, 'region'>\n >;\n\n generateId?: () => string;\n}\n\n/**\n * Create a Claude Platform on AWS provider instance.\n * This provider uses the Anthropic Messages API hosted in AWS, authenticated\n * with AWS SigV4 or an AWS-provisioned API key.\n */\nexport function createAnthropicAws(\n options: AnthropicAwsProviderSettings = {},\n): AnthropicAwsProvider {\n const apiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'ANTHROPIC_AWS_API_KEY',\n });\n\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with ANTHROPIC_AWS_API_KEY or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n }, options.fetch);\n\n const getBaseURL = (): string =>\n withoutTrailingSlash(options.baseURL) ??\n `https://aws-external-anthropic.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/v1`;\n\n const getHeaders = (): Record<string, string | undefined> => ({\n 'anthropic-version': '2023-06-01',\n 'anthropic-workspace-id': loadSetting({\n settingValue: options.workspaceId,\n settingName: 'workspaceId',\n environmentVariableName: 'ANTHROPIC_AWS_WORKSPACE_ID',\n description: 'Anthropic AWS workspace ID',\n }),\n ...options.headers,\n });\n\n const createChatModel = (modelId: AnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'anthropic-aws.messages',\n baseURL: getBaseURL(),\n headers: getHeaders,\n fetch: fetchFunction,\n generateId: options.generateId,\n supportedUrls: () => ({\n 'image/*': [/^https?:\\/\\/.*$/],\n 'application/pdf': [/^https?:\\/\\/.*$/],\n }),\n });\n\n const provider = function (modelId: AnthropicMessagesModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic AWS model function cannot be called with the new keyword.',\n );\n }\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n\n/**\n * Default Claude Platform on AWS provider instance.\n */\nexport const anthropicAws = createAnthropicAws();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AnthropicAwsCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing for\n * Claude Platform on AWS.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AnthropicAwsCredentials\n | PromiseLike<AnthropicAwsCredentials>,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service: 'aws-external-anthropic',\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies x-api-key header authentication.\n *\n * @param apiKey - The API key to use for x-api-key header authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds the x-api-key header to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n 'x-api-key': apiKey,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAIO;AACP,IAAAA,yBAKO;AACP,sBAIO;;;ACfP,4BAMO;AACP,uBAA4B;;;ACLrB,IAAM,UACX,OACI,WACA;;;ADoBC,SAAS,yBACd,gBAGA,OACe;AACf,SAAO,OACL,OACA,SACsB;AAlC1B;AAmCI,UAAM,iBAAiB,wBAAS,WAAW;AAC3C,UAAM,UAAU,iBAAiB,UAAU,QAAQ;AACnD,UAAM,sBAAkB;AAAA,UACtB,wCAAiB,mCAAS,OAAO;AAAA,UACjC,wCAAiB,6BAAM,OAAO;AAAA,IAChC;AACA,UAAM,2BAAuB;AAAA,MAC3B;AAAA,MACA,wBAAwB,OAAO;AAAA,UAC/B,sDAA+B;AAAA,IACjC;AAEA,QAAI,iBAAsC,kCAAM,SAAN,YAAc;AACxD,QAAI,kBAAkB,UAAa,WAAW,QAAQ,SAAS,MAAM;AACnE,UAAI;AACF,wBAAgB,MAAM,QAAQ,MAAM,EAAE,KAAK;AAAA,MAC7C,SAAQ;AAAA,MAAC;AAAA,IACX;AAEA,UAAM,mBAAkB,kCAAM,WAAN,YAAgB,mCAAS;AAEjD,SAAI,mDAAiB,mBAAkB,UAAU,CAAC,eAAe;AAC/D,aAAO,eAAe,OAAO;AAAA,QAC3B,GAAG;AAAA,QACH,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAEA,UAAM,MACJ,OAAO,UAAU,WACb,QACA,iBAAiB,MACf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Aa,CAAC,YAAoB;AACzC,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,WAAS,QAAQ;AAEjB,SAAO;AACT;AAKO,IAAM,eAAe,mBAAmB;","names":["import_provider_utils"]}
|
|
1
|
+
{"version":3,"sources":["../src/anthropic-aws-provider.ts","../src/anthropic-aws-fetch.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type FilesV4,\n type LanguageModelV4,\n type ProviderV4,\n type SkillsV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n AnthropicFiles,\n AnthropicLanguageModel,\n AnthropicSkills,\n anthropicTools,\n type AnthropicModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AnthropicAwsCredentials,\n} from './anthropic-aws-fetch';\n\nexport interface AnthropicAwsProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: AnthropicModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: AnthropicModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n\n files(): FilesV4;\n\n /**\n * Returns a SkillsV4 interface for uploading skills to Anthropic.\n */\n skills(): SkillsV4;\n\n tools: typeof anthropicTools;\n}\n\nexport interface AnthropicAwsProviderSettings {\n /**\n * The AWS region to use for Claude Platform on AWS. Defaults to the value of the\n * `AWS_REGION` environment variable. Required — there is no fallback default.\n */\n region?: string;\n\n /**\n * The Anthropic workspace ID for this AWS account. Sent on every request via the\n * `anthropic-workspace-id` header. Defaults to the value of the\n * `ANTHROPIC_AWS_WORKSPACE_ID` environment variable.\n */\n workspaceId?: string;\n\n /**\n * API key for authenticating requests via the `x-api-key` header.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `ANTHROPIC_AWS_API_KEY` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Claude Platform on AWS API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use to get dynamic credentials similar to the\n * AWS SDK. Setting a provider here will cause its credential values to be used\n * instead of the `accessKeyId`, `secretAccessKey`, and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AnthropicAwsCredentials, 'region'>\n >;\n\n generateId?: () => string;\n}\n\n/**\n * Create a Claude Platform on AWS provider instance.\n * This provider uses the Anthropic Messages API hosted in AWS, authenticated\n * with AWS SigV4 or an AWS-provisioned API key.\n */\nexport function createAnthropicAws(\n options: AnthropicAwsProviderSettings = {},\n): AnthropicAwsProvider {\n const apiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'ANTHROPIC_AWS_API_KEY',\n });\n\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with ANTHROPIC_AWS_API_KEY or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n }, options.fetch);\n\n const getBaseURL = (): string =>\n withoutTrailingSlash(options.baseURL) ??\n `https://aws-external-anthropic.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/v1`;\n\n const getHeaders = (): Record<string, string | undefined> => ({\n 'anthropic-version': '2023-06-01',\n 'anthropic-workspace-id': loadSetting({\n settingValue: options.workspaceId,\n settingName: 'workspaceId',\n environmentVariableName: 'ANTHROPIC_AWS_WORKSPACE_ID',\n description: 'Anthropic AWS workspace ID',\n }),\n ...options.headers,\n });\n\n const createChatModel = (modelId: AnthropicModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'anthropic-aws.messages',\n baseURL: getBaseURL(),\n headers: getHeaders,\n fetch: fetchFunction,\n generateId: options.generateId,\n supportedUrls: () => ({\n 'image/*': [/^https?:\\/\\/.*$/],\n 'application/pdf': [/^https?:\\/\\/.*$/],\n }),\n });\n\n const provider = function (modelId: AnthropicModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic AWS model function cannot be called with the new keyword.',\n );\n }\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.files = () =>\n new AnthropicFiles({\n provider: 'anthropic-aws.messages',\n baseURL: getBaseURL(),\n headers: getHeaders,\n fetch: fetchFunction,\n });\n\n provider.skills = () =>\n new AnthropicSkills({\n provider: 'anthropic-aws.skills',\n baseURL: getBaseURL(),\n headers: getHeaders,\n fetch: fetchFunction,\n });\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n\n/**\n * Default Claude Platform on AWS provider instance.\n */\nexport const anthropicAws = createAnthropicAws();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AnthropicAwsCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing for\n * Claude Platform on AWS.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AnthropicAwsCredentials\n | PromiseLike<AnthropicAwsCredentials>,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service: 'aws-external-anthropic',\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies x-api-key header authentication.\n *\n * @param apiKey - The API key to use for x-api-key header authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds the x-api-key header to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n 'x-api-key': apiKey,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACnBP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAAmB;;;ACLrB,IAAM,UACX,OACI,UACA;;;ADoBC,SAAS,yBACd,gBAGA,OACe;AACf,SAAO,OACL,OACA,SACsB;AAlC1B;AAmCI,UAAM,iBAAiB,wBAA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,QAAQ;AAAA,EACb;AAEA,QAAM,kBAAkB,CAAC,YACvB,IAAI,uBAAuB,SAAS;AAAA,IAClC,UAAU;AAAA,IACV,SAAS,WAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY,QAAQ;AAAA,IACpB,eAAe,OAAO;AAAA,MACpB,WAAW,CAAC,iBAAiB;AAAA,MAC7B,mBAAmB,CAAC,iBAAiB;AAAA,IACvC;AAAA,EACF,CAAC;AAEH,QAAM,WAAW,SAAU,SAA2B;AACpD,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO,gBAAgB,OAAO;AAAA,EAChC;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,WAAW;AAEpB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,WAAS,QAAQ,MACf,IAAI,eAAe;AAAA,IACjB,UAAU;AAAA,IACV,SAAS,WAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAEH,WAAS,SAAS,MAChB,IAAI,gBAAgB;AAAA,IAClB,UAAU;AAAA,IACV,SAAS,WAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO;AAAA,EACT,CAAC;AAEH,WAAS,QAAQ;AAEjB,SAAO;AACT;AAKO,IAAM,eAAe,mBAAmB;","names":[]}
|
|
@@ -105,18 +105,18 @@ const anthropicAws = createAnthropicAws({
|
|
|
105
105
|
|
|
106
106
|
### Provider Settings
|
|
107
107
|
|
|
108
|
-
| Setting
|
|
109
|
-
|
|
|
110
|
-
| `region`
|
|
111
|
-
| `workspaceId`
|
|
112
|
-
| `apiKey`
|
|
113
|
-
| `accessKeyId`
|
|
114
|
-
| `secretAccessKey`
|
|
115
|
-
| `sessionToken`
|
|
116
|
-
| `baseURL`
|
|
117
|
-
| `headers`
|
|
118
|
-
| `fetch`
|
|
119
|
-
| `credentialProvider` | Function returning dynamic AWS credentials. Overrides `accessKeyId`, `secretAccessKey`, and `sessionToken`.
|
|
108
|
+
| Setting | Description |
|
|
109
|
+
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
+
| `region` | AWS region for the Claude Platform on AWS endpoint. Reads from `AWS_REGION` if omitted. Required — no fallback default. |
|
|
111
|
+
| `workspaceId` | Anthropic workspace ID for this AWS account. Sent on every request via the `anthropic-workspace-id` header. Reads from `ANTHROPIC_AWS_WORKSPACE_ID` if omitted. |
|
|
112
|
+
| `apiKey` | API key for `x-api-key` authentication. When provided, used instead of SigV4. Reads from `ANTHROPIC_AWS_API_KEY` if omitted. |
|
|
113
|
+
| `accessKeyId` | AWS access key ID for SigV4. Reads from `AWS_ACCESS_KEY_ID`. |
|
|
114
|
+
| `secretAccessKey` | AWS secret access key for SigV4. Reads from `AWS_SECRET_ACCESS_KEY`. |
|
|
115
|
+
| `sessionToken` | AWS session token for SigV4 (temporary credentials only). Reads from `AWS_SESSION_TOKEN`. |
|
|
116
|
+
| `baseURL` | Base URL override. Defaults to `https://aws-external-anthropic.{region}.api.aws/v1`. |
|
|
117
|
+
| `headers` | Custom headers to include on every request. |
|
|
118
|
+
| `fetch` | Custom fetch implementation for testing or middleware. |
|
|
119
|
+
| `credentialProvider` | Function returning dynamic AWS credentials. Overrides `accessKeyId`, `secretAccessKey`, and `sessionToken`. |
|
|
120
120
|
|
|
121
121
|
## Language Models
|
|
122
122
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic-aws",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"license": "Apache-2.0",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
@@ -24,32 +24,33 @@
|
|
|
24
24
|
"./package.json": "./package.json",
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"import": "./dist/index.
|
|
28
|
-
"
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"aws4fetch": "^1.0.20",
|
|
33
|
-
"@ai-sdk/
|
|
34
|
-
"@ai-sdk/provider": "
|
|
35
|
-
"@ai-sdk/
|
|
33
|
+
"@ai-sdk/provider": "4.0.2",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.5",
|
|
35
|
+
"@ai-sdk/anthropic": "4.0.8"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "
|
|
39
|
-
"tsup": "^8",
|
|
38
|
+
"@types/node": "22.19.19",
|
|
39
|
+
"tsup": "^8.5.1",
|
|
40
40
|
"typescript": "5.8.3",
|
|
41
41
|
"zod": "3.25.76",
|
|
42
|
-
"@ai-sdk/test-server": "
|
|
42
|
+
"@ai-sdk/test-server": "2.0.0",
|
|
43
43
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"zod": "^3.25.76 || ^4.1.8"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
|
-
"node": ">=
|
|
49
|
+
"node": ">=22"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
|
-
"access": "public"
|
|
52
|
+
"access": "public",
|
|
53
|
+
"provenance": true
|
|
53
54
|
},
|
|
54
55
|
"homepage": "https://ai-sdk.dev/docs",
|
|
55
56
|
"repository": {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NoSuchModelError,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
type FilesV4,
|
|
4
|
+
type LanguageModelV4,
|
|
5
|
+
type ProviderV4,
|
|
6
|
+
type SkillsV4,
|
|
5
7
|
} from '@ai-sdk/provider';
|
|
6
8
|
import {
|
|
7
9
|
loadOptionalSetting,
|
|
@@ -10,9 +12,11 @@ import {
|
|
|
10
12
|
type FetchFunction,
|
|
11
13
|
} from '@ai-sdk/provider-utils';
|
|
12
14
|
import {
|
|
13
|
-
|
|
15
|
+
AnthropicFiles,
|
|
16
|
+
AnthropicLanguageModel,
|
|
17
|
+
AnthropicSkills,
|
|
14
18
|
anthropicTools,
|
|
15
|
-
type
|
|
19
|
+
type AnthropicModelId,
|
|
16
20
|
} from '@ai-sdk/anthropic/internal';
|
|
17
21
|
import {
|
|
18
22
|
createApiKeyFetchFunction,
|
|
@@ -20,29 +24,36 @@ import {
|
|
|
20
24
|
type AnthropicAwsCredentials,
|
|
21
25
|
} from './anthropic-aws-fetch';
|
|
22
26
|
|
|
23
|
-
export interface AnthropicAwsProvider extends
|
|
27
|
+
export interface AnthropicAwsProvider extends ProviderV4 {
|
|
24
28
|
/**
|
|
25
29
|
* Creates a model for text generation.
|
|
26
30
|
*/
|
|
27
|
-
(modelId:
|
|
31
|
+
(modelId: AnthropicModelId): LanguageModelV4;
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Creates a model for text generation.
|
|
31
35
|
*/
|
|
32
|
-
languageModel(modelId:
|
|
36
|
+
languageModel(modelId: AnthropicModelId): LanguageModelV4;
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* @deprecated Use `embeddingModel` instead.
|
|
36
40
|
*/
|
|
37
41
|
textEmbeddingModel(modelId: string): never;
|
|
38
42
|
|
|
43
|
+
files(): FilesV4;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns a SkillsV4 interface for uploading skills to Anthropic.
|
|
47
|
+
*/
|
|
48
|
+
skills(): SkillsV4;
|
|
49
|
+
|
|
39
50
|
tools: typeof anthropicTools;
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
export interface AnthropicAwsProviderSettings {
|
|
43
54
|
/**
|
|
44
55
|
* The AWS region to use for Claude Platform on AWS. Defaults to the value of the
|
|
45
|
-
* `AWS_REGION` environment variable. Required — no fallback default.
|
|
56
|
+
* `AWS_REGION` environment variable. Required — there is no fallback default.
|
|
46
57
|
*/
|
|
47
58
|
region?: string;
|
|
48
59
|
|
|
@@ -216,8 +227,8 @@ export function createAnthropicAws(
|
|
|
216
227
|
...options.headers,
|
|
217
228
|
});
|
|
218
229
|
|
|
219
|
-
const createChatModel = (modelId:
|
|
220
|
-
new
|
|
230
|
+
const createChatModel = (modelId: AnthropicModelId) =>
|
|
231
|
+
new AnthropicLanguageModel(modelId, {
|
|
221
232
|
provider: 'anthropic-aws.messages',
|
|
222
233
|
baseURL: getBaseURL(),
|
|
223
234
|
headers: getHeaders,
|
|
@@ -229,7 +240,7 @@ export function createAnthropicAws(
|
|
|
229
240
|
}),
|
|
230
241
|
});
|
|
231
242
|
|
|
232
|
-
const provider = function (modelId:
|
|
243
|
+
const provider = function (modelId: AnthropicModelId) {
|
|
233
244
|
if (new.target) {
|
|
234
245
|
throw new Error(
|
|
235
246
|
'The Anthropic AWS model function cannot be called with the new keyword.',
|
|
@@ -238,7 +249,7 @@ export function createAnthropicAws(
|
|
|
238
249
|
return createChatModel(modelId);
|
|
239
250
|
};
|
|
240
251
|
|
|
241
|
-
provider.specificationVersion = '
|
|
252
|
+
provider.specificationVersion = 'v4' as const;
|
|
242
253
|
provider.languageModel = createChatModel;
|
|
243
254
|
provider.chat = createChatModel;
|
|
244
255
|
provider.messages = createChatModel;
|
|
@@ -251,6 +262,22 @@ export function createAnthropicAws(
|
|
|
251
262
|
throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
|
|
252
263
|
};
|
|
253
264
|
|
|
265
|
+
provider.files = () =>
|
|
266
|
+
new AnthropicFiles({
|
|
267
|
+
provider: 'anthropic-aws.messages',
|
|
268
|
+
baseURL: getBaseURL(),
|
|
269
|
+
headers: getHeaders,
|
|
270
|
+
fetch: fetchFunction,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
provider.skills = () =>
|
|
274
|
+
new AnthropicSkills({
|
|
275
|
+
provider: 'anthropic-aws.skills',
|
|
276
|
+
baseURL: getBaseURL(),
|
|
277
|
+
headers: getHeaders,
|
|
278
|
+
fetch: fetchFunction,
|
|
279
|
+
});
|
|
280
|
+
|
|
254
281
|
provider.tools = anthropicTools;
|
|
255
282
|
|
|
256
283
|
return provider;
|
package/dist/index.d.mts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { AnthropicMessagesModelId, anthropicTools } from '@ai-sdk/anthropic/internal';
|
|
4
|
-
|
|
5
|
-
interface AnthropicAwsCredentials {
|
|
6
|
-
region: string;
|
|
7
|
-
accessKeyId: string;
|
|
8
|
-
secretAccessKey: string;
|
|
9
|
-
sessionToken?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface AnthropicAwsProvider extends ProviderV3 {
|
|
13
|
-
/**
|
|
14
|
-
* Creates a model for text generation.
|
|
15
|
-
*/
|
|
16
|
-
(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a model for text generation.
|
|
19
|
-
*/
|
|
20
|
-
languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use `embeddingModel` instead.
|
|
23
|
-
*/
|
|
24
|
-
textEmbeddingModel(modelId: string): never;
|
|
25
|
-
tools: typeof anthropicTools;
|
|
26
|
-
}
|
|
27
|
-
interface AnthropicAwsProviderSettings {
|
|
28
|
-
/**
|
|
29
|
-
* The AWS region to use for Claude Platform on AWS. Defaults to the value of the
|
|
30
|
-
* `AWS_REGION` environment variable. Required — no fallback default.
|
|
31
|
-
*/
|
|
32
|
-
region?: string;
|
|
33
|
-
/**
|
|
34
|
-
* The Anthropic workspace ID for this AWS account. Sent on every request via the
|
|
35
|
-
* `anthropic-workspace-id` header. Defaults to the value of the
|
|
36
|
-
* `ANTHROPIC_AWS_WORKSPACE_ID` environment variable.
|
|
37
|
-
*/
|
|
38
|
-
workspaceId?: string;
|
|
39
|
-
/**
|
|
40
|
-
* API key for authenticating requests via the `x-api-key` header.
|
|
41
|
-
* When provided, this will be used instead of AWS SigV4 authentication.
|
|
42
|
-
* Defaults to the value of the `ANTHROPIC_AWS_API_KEY` environment variable.
|
|
43
|
-
*/
|
|
44
|
-
apiKey?: string;
|
|
45
|
-
/**
|
|
46
|
-
* The AWS access key ID to use for SigV4 authentication. Defaults to the value of the
|
|
47
|
-
* `AWS_ACCESS_KEY_ID` environment variable.
|
|
48
|
-
*/
|
|
49
|
-
accessKeyId?: string;
|
|
50
|
-
/**
|
|
51
|
-
* The AWS secret access key to use for SigV4 authentication. Defaults to the value of the
|
|
52
|
-
* `AWS_SECRET_ACCESS_KEY` environment variable.
|
|
53
|
-
*/
|
|
54
|
-
secretAccessKey?: string;
|
|
55
|
-
/**
|
|
56
|
-
* The AWS session token to use for SigV4 authentication. Defaults to the value of the
|
|
57
|
-
* `AWS_SESSION_TOKEN` environment variable.
|
|
58
|
-
*/
|
|
59
|
-
sessionToken?: string;
|
|
60
|
-
/**
|
|
61
|
-
* Base URL for the Claude Platform on AWS API calls.
|
|
62
|
-
*/
|
|
63
|
-
baseURL?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Custom headers to include in the requests.
|
|
66
|
-
*/
|
|
67
|
-
headers?: Record<string, string | undefined>;
|
|
68
|
-
/**
|
|
69
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
70
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
71
|
-
*/
|
|
72
|
-
fetch?: FetchFunction;
|
|
73
|
-
/**
|
|
74
|
-
* The AWS credential provider to use to get dynamic credentials similar to the
|
|
75
|
-
* AWS SDK. Setting a provider here will cause its credential values to be used
|
|
76
|
-
* instead of the `accessKeyId`, `secretAccessKey`, and `sessionToken` settings.
|
|
77
|
-
*/
|
|
78
|
-
credentialProvider?: () => PromiseLike<Omit<AnthropicAwsCredentials, 'region'>>;
|
|
79
|
-
generateId?: () => string;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Create a Claude Platform on AWS provider instance.
|
|
83
|
-
* This provider uses the Anthropic Messages API hosted in AWS, authenticated
|
|
84
|
-
* with AWS SigV4 or an AWS-provisioned API key.
|
|
85
|
-
*/
|
|
86
|
-
declare function createAnthropicAws(options?: AnthropicAwsProviderSettings): AnthropicAwsProvider;
|
|
87
|
-
/**
|
|
88
|
-
* Default Claude Platform on AWS provider instance.
|
|
89
|
-
*/
|
|
90
|
-
declare const anthropicAws: AnthropicAwsProvider;
|
|
91
|
-
|
|
92
|
-
declare const VERSION: string;
|
|
93
|
-
|
|
94
|
-
export { type AnthropicAwsCredentials, type AnthropicAwsProvider, type AnthropicAwsProviderSettings, VERSION, anthropicAws, createAnthropicAws };
|
package/dist/index.mjs
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
// src/anthropic-aws-provider.ts
|
|
2
|
-
import {
|
|
3
|
-
NoSuchModelError
|
|
4
|
-
} from "@ai-sdk/provider";
|
|
5
|
-
import {
|
|
6
|
-
loadOptionalSetting,
|
|
7
|
-
loadSetting,
|
|
8
|
-
withoutTrailingSlash
|
|
9
|
-
} from "@ai-sdk/provider-utils";
|
|
10
|
-
import {
|
|
11
|
-
AnthropicMessagesLanguageModel,
|
|
12
|
-
anthropicTools
|
|
13
|
-
} from "@ai-sdk/anthropic/internal";
|
|
14
|
-
|
|
15
|
-
// src/anthropic-aws-fetch.ts
|
|
16
|
-
import {
|
|
17
|
-
combineHeaders,
|
|
18
|
-
normalizeHeaders,
|
|
19
|
-
withUserAgentSuffix,
|
|
20
|
-
getRuntimeEnvironmentUserAgent
|
|
21
|
-
} from "@ai-sdk/provider-utils";
|
|
22
|
-
import { AwsV4Signer } from "aws4fetch";
|
|
23
|
-
|
|
24
|
-
// src/version.ts
|
|
25
|
-
var VERSION = true ? "1.0.14" : "0.0.0-test";
|
|
26
|
-
|
|
27
|
-
// src/anthropic-aws-fetch.ts
|
|
28
|
-
function createSigV4FetchFunction(getCredentials, fetch) {
|
|
29
|
-
return async (input, init) => {
|
|
30
|
-
var _a, _b;
|
|
31
|
-
const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
|
|
32
|
-
const request = input instanceof Request ? input : void 0;
|
|
33
|
-
const originalHeaders = combineHeaders(
|
|
34
|
-
normalizeHeaders(request == null ? void 0 : request.headers),
|
|
35
|
-
normalizeHeaders(init == null ? void 0 : init.headers)
|
|
36
|
-
);
|
|
37
|
-
const headersWithUserAgent = withUserAgentSuffix(
|
|
38
|
-
originalHeaders,
|
|
39
|
-
`ai-sdk/anthropic-aws/${VERSION}`,
|
|
40
|
-
getRuntimeEnvironmentUserAgent()
|
|
41
|
-
);
|
|
42
|
-
let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
|
|
43
|
-
if (effectiveBody === void 0 && request && request.body !== null) {
|
|
44
|
-
try {
|
|
45
|
-
effectiveBody = await request.clone().text();
|
|
46
|
-
} catch (e) {
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const effectiveMethod = (_b = init == null ? void 0 : init.method) != null ? _b : request == null ? void 0 : request.method;
|
|
50
|
-
if ((effectiveMethod == null ? void 0 : effectiveMethod.toUpperCase()) !== "POST" || !effectiveBody) {
|
|
51
|
-
return effectiveFetch(input, {
|
|
52
|
-
...init,
|
|
53
|
-
headers: headersWithUserAgent
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
57
|
-
const body = prepareBodyString(effectiveBody);
|
|
58
|
-
const credentials = await getCredentials();
|
|
59
|
-
const signer = new AwsV4Signer({
|
|
60
|
-
url,
|
|
61
|
-
method: "POST",
|
|
62
|
-
headers: Object.entries(headersWithUserAgent),
|
|
63
|
-
body,
|
|
64
|
-
region: credentials.region,
|
|
65
|
-
accessKeyId: credentials.accessKeyId,
|
|
66
|
-
secretAccessKey: credentials.secretAccessKey,
|
|
67
|
-
sessionToken: credentials.sessionToken,
|
|
68
|
-
service: "aws-external-anthropic"
|
|
69
|
-
});
|
|
70
|
-
const signingResult = await signer.sign();
|
|
71
|
-
const signedHeaders = normalizeHeaders(signingResult.headers);
|
|
72
|
-
const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);
|
|
73
|
-
return effectiveFetch(input, {
|
|
74
|
-
...init,
|
|
75
|
-
body,
|
|
76
|
-
headers: combinedHeaders
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function prepareBodyString(body) {
|
|
81
|
-
if (typeof body === "string") {
|
|
82
|
-
return body;
|
|
83
|
-
} else if (body instanceof Uint8Array) {
|
|
84
|
-
return new TextDecoder().decode(body);
|
|
85
|
-
} else if (body instanceof ArrayBuffer) {
|
|
86
|
-
return new TextDecoder().decode(new Uint8Array(body));
|
|
87
|
-
} else {
|
|
88
|
-
return JSON.stringify(body);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function createApiKeyFetchFunction(apiKey, fetch) {
|
|
92
|
-
return async (input, init) => {
|
|
93
|
-
const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
|
|
94
|
-
const originalHeaders = normalizeHeaders(init == null ? void 0 : init.headers);
|
|
95
|
-
const headersWithUserAgent = withUserAgentSuffix(
|
|
96
|
-
originalHeaders,
|
|
97
|
-
`ai-sdk/anthropic-aws/${VERSION}`,
|
|
98
|
-
getRuntimeEnvironmentUserAgent()
|
|
99
|
-
);
|
|
100
|
-
const finalHeaders = combineHeaders(headersWithUserAgent, {
|
|
101
|
-
"x-api-key": apiKey
|
|
102
|
-
});
|
|
103
|
-
return effectiveFetch(input, {
|
|
104
|
-
...init,
|
|
105
|
-
headers: finalHeaders
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// src/anthropic-aws-provider.ts
|
|
111
|
-
function createAnthropicAws(options = {}) {
|
|
112
|
-
const apiKey = loadOptionalSetting({
|
|
113
|
-
settingValue: options.apiKey,
|
|
114
|
-
environmentVariableName: "ANTHROPIC_AWS_API_KEY"
|
|
115
|
-
});
|
|
116
|
-
const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
|
|
117
|
-
const region = loadSetting({
|
|
118
|
-
settingValue: options.region,
|
|
119
|
-
settingName: "region",
|
|
120
|
-
environmentVariableName: "AWS_REGION",
|
|
121
|
-
description: "AWS region"
|
|
122
|
-
});
|
|
123
|
-
if (options.credentialProvider) {
|
|
124
|
-
try {
|
|
125
|
-
return {
|
|
126
|
-
...await options.credentialProvider(),
|
|
127
|
-
region
|
|
128
|
-
};
|
|
129
|
-
} catch (error) {
|
|
130
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
131
|
-
throw new Error(
|
|
132
|
-
`AWS credential provider failed: ${errorMessage}. Please ensure your credential provider returns valid AWS credentials with accessKeyId and secretAccessKey properties.`
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
return {
|
|
138
|
-
region,
|
|
139
|
-
accessKeyId: loadSetting({
|
|
140
|
-
settingValue: options.accessKeyId,
|
|
141
|
-
settingName: "accessKeyId",
|
|
142
|
-
environmentVariableName: "AWS_ACCESS_KEY_ID",
|
|
143
|
-
description: "AWS access key ID"
|
|
144
|
-
}),
|
|
145
|
-
secretAccessKey: loadSetting({
|
|
146
|
-
settingValue: options.secretAccessKey,
|
|
147
|
-
settingName: "secretAccessKey",
|
|
148
|
-
environmentVariableName: "AWS_SECRET_ACCESS_KEY",
|
|
149
|
-
description: "AWS secret access key"
|
|
150
|
-
}),
|
|
151
|
-
sessionToken: loadOptionalSetting({
|
|
152
|
-
settingValue: options.sessionToken,
|
|
153
|
-
environmentVariableName: "AWS_SESSION_TOKEN"
|
|
154
|
-
})
|
|
155
|
-
};
|
|
156
|
-
} catch (error) {
|
|
157
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
158
|
-
if (errorMessage.includes("AWS_ACCESS_KEY_ID") || errorMessage.includes("accessKeyId")) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
`AWS SigV4 authentication requires AWS credentials. Please provide either:
|
|
161
|
-
1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
|
|
162
|
-
2. Provide accessKeyId and secretAccessKey in options
|
|
163
|
-
3. Use a credentialProvider function
|
|
164
|
-
4. Use API key authentication with ANTHROPIC_AWS_API_KEY or apiKey option
|
|
165
|
-
Original error: ${errorMessage}`
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
if (errorMessage.includes("AWS_SECRET_ACCESS_KEY") || errorMessage.includes("secretAccessKey")) {
|
|
169
|
-
throw new Error(
|
|
170
|
-
`AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Please ensure both credentials are provided.
|
|
171
|
-
Original error: ${errorMessage}`
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
throw error;
|
|
175
|
-
}
|
|
176
|
-
}, options.fetch);
|
|
177
|
-
const getBaseURL = () => {
|
|
178
|
-
var _a;
|
|
179
|
-
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : `https://aws-external-anthropic.${loadSetting({
|
|
180
|
-
settingValue: options.region,
|
|
181
|
-
settingName: "region",
|
|
182
|
-
environmentVariableName: "AWS_REGION",
|
|
183
|
-
description: "AWS region"
|
|
184
|
-
})}.api.aws/v1`;
|
|
185
|
-
};
|
|
186
|
-
const getHeaders = () => ({
|
|
187
|
-
"anthropic-version": "2023-06-01",
|
|
188
|
-
"anthropic-workspace-id": loadSetting({
|
|
189
|
-
settingValue: options.workspaceId,
|
|
190
|
-
settingName: "workspaceId",
|
|
191
|
-
environmentVariableName: "ANTHROPIC_AWS_WORKSPACE_ID",
|
|
192
|
-
description: "Anthropic AWS workspace ID"
|
|
193
|
-
}),
|
|
194
|
-
...options.headers
|
|
195
|
-
});
|
|
196
|
-
const createChatModel = (modelId) => new AnthropicMessagesLanguageModel(modelId, {
|
|
197
|
-
provider: "anthropic-aws.messages",
|
|
198
|
-
baseURL: getBaseURL(),
|
|
199
|
-
headers: getHeaders,
|
|
200
|
-
fetch: fetchFunction,
|
|
201
|
-
generateId: options.generateId,
|
|
202
|
-
supportedUrls: () => ({
|
|
203
|
-
"image/*": [/^https?:\/\/.*$/],
|
|
204
|
-
"application/pdf": [/^https?:\/\/.*$/]
|
|
205
|
-
})
|
|
206
|
-
});
|
|
207
|
-
const provider = function(modelId) {
|
|
208
|
-
if (new.target) {
|
|
209
|
-
throw new Error(
|
|
210
|
-
"The Anthropic AWS model function cannot be called with the new keyword."
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
return createChatModel(modelId);
|
|
214
|
-
};
|
|
215
|
-
provider.specificationVersion = "v3";
|
|
216
|
-
provider.languageModel = createChatModel;
|
|
217
|
-
provider.chat = createChatModel;
|
|
218
|
-
provider.messages = createChatModel;
|
|
219
|
-
provider.embeddingModel = (modelId) => {
|
|
220
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
221
|
-
};
|
|
222
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
223
|
-
provider.imageModel = (modelId) => {
|
|
224
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
225
|
-
};
|
|
226
|
-
provider.tools = anthropicTools;
|
|
227
|
-
return provider;
|
|
228
|
-
}
|
|
229
|
-
var anthropicAws = createAnthropicAws();
|
|
230
|
-
export {
|
|
231
|
-
VERSION,
|
|
232
|
-
anthropicAws,
|
|
233
|
-
createAnthropicAws
|
|
234
|
-
};
|
|
235
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/anthropic-aws-provider.ts","../src/anthropic-aws-fetch.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type LanguageModelV3,\n type ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport {\n AnthropicMessagesLanguageModel,\n anthropicTools,\n type AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n createApiKeyFetchFunction,\n createSigV4FetchFunction,\n type AnthropicAwsCredentials,\n} from './anthropic-aws-fetch';\n\nexport interface AnthropicAwsProvider extends ProviderV3 {\n /**\n * Creates a model for text generation.\n */\n (modelId: AnthropicMessagesModelId): LanguageModelV3;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n\n tools: typeof anthropicTools;\n}\n\nexport interface AnthropicAwsProviderSettings {\n /**\n * The AWS region to use for Claude Platform on AWS. Defaults to the value of the\n * `AWS_REGION` environment variable. Required — no fallback default.\n */\n region?: string;\n\n /**\n * The Anthropic workspace ID for this AWS account. Sent on every request via the\n * `anthropic-workspace-id` header. Defaults to the value of the\n * `ANTHROPIC_AWS_WORKSPACE_ID` environment variable.\n */\n workspaceId?: string;\n\n /**\n * API key for authenticating requests via the `x-api-key` header.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `ANTHROPIC_AWS_API_KEY` environment variable.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for SigV4 authentication. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for SigV4 authentication. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * Base URL for the Claude Platform on AWS API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string | undefined>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use to get dynamic credentials similar to the\n * AWS SDK. Setting a provider here will cause its credential values to be used\n * instead of the `accessKeyId`, `secretAccessKey`, and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<\n Omit<AnthropicAwsCredentials, 'region'>\n >;\n\n generateId?: () => string;\n}\n\n/**\n * Create a Claude Platform on AWS provider instance.\n * This provider uses the Anthropic Messages API hosted in AWS, authenticated\n * with AWS SigV4 or an AWS-provisioned API key.\n */\nexport function createAnthropicAws(\n options: AnthropicAwsProviderSettings = {},\n): AnthropicAwsProvider {\n const apiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'ANTHROPIC_AWS_API_KEY',\n });\n\n const fetchFunction = apiKey\n ? createApiKeyFetchFunction(apiKey, options.fetch)\n : createSigV4FetchFunction(async () => {\n const region = loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n });\n\n if (options.credentialProvider) {\n try {\n return {\n ...(await options.credentialProvider()),\n region,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n throw new Error(\n `AWS credential provider failed: ${errorMessage}. ` +\n 'Please ensure your credential provider returns valid AWS credentials ' +\n 'with accessKeyId and secretAccessKey properties.',\n );\n }\n }\n\n try {\n return {\n region,\n accessKeyId: loadSetting({\n settingValue: options.accessKeyId,\n settingName: 'accessKeyId',\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n description: 'AWS access key ID',\n }),\n secretAccessKey: loadSetting({\n settingValue: options.secretAccessKey,\n settingName: 'secretAccessKey',\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n description: 'AWS secret access key',\n }),\n sessionToken: loadOptionalSetting({\n settingValue: options.sessionToken,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n if (\n errorMessage.includes('AWS_ACCESS_KEY_ID') ||\n errorMessage.includes('accessKeyId')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires AWS credentials. Please provide either:\\n' +\n '1. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables\\n' +\n '2. Provide accessKeyId and secretAccessKey in options\\n' +\n '3. Use a credentialProvider function\\n' +\n '4. Use API key authentication with ANTHROPIC_AWS_API_KEY or apiKey option\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n if (\n errorMessage.includes('AWS_SECRET_ACCESS_KEY') ||\n errorMessage.includes('secretAccessKey')\n ) {\n throw new Error(\n 'AWS SigV4 authentication requires both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. ' +\n 'Please ensure both credentials are provided.\\n' +\n `Original error: ${errorMessage}`,\n );\n }\n throw error;\n }\n }, options.fetch);\n\n const getBaseURL = (): string =>\n withoutTrailingSlash(options.baseURL) ??\n `https://aws-external-anthropic.${loadSetting({\n settingValue: options.region,\n settingName: 'region',\n environmentVariableName: 'AWS_REGION',\n description: 'AWS region',\n })}.api.aws/v1`;\n\n const getHeaders = (): Record<string, string | undefined> => ({\n 'anthropic-version': '2023-06-01',\n 'anthropic-workspace-id': loadSetting({\n settingValue: options.workspaceId,\n settingName: 'workspaceId',\n environmentVariableName: 'ANTHROPIC_AWS_WORKSPACE_ID',\n description: 'Anthropic AWS workspace ID',\n }),\n ...options.headers,\n });\n\n const createChatModel = (modelId: AnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'anthropic-aws.messages',\n baseURL: getBaseURL(),\n headers: getHeaders,\n fetch: fetchFunction,\n generateId: options.generateId,\n supportedUrls: () => ({\n 'image/*': [/^https?:\\/\\/.*$/],\n 'application/pdf': [/^https?:\\/\\/.*$/],\n }),\n });\n\n const provider = function (modelId: AnthropicMessagesModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic AWS model function cannot be called with the new keyword.',\n );\n }\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n\n/**\n * Default Claude Platform on AWS provider instance.\n */\nexport const anthropicAws = createAnthropicAws();\n","import {\n combineHeaders,\n normalizeHeaders,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { VERSION } from './version';\n\nexport interface AnthropicAwsCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing for\n * Claude Platform on AWS.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nexport function createSigV4FetchFunction(\n getCredentials: () =>\n | AnthropicAwsCredentials\n | PromiseLike<AnthropicAwsCredentials>,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const request = input instanceof Request ? input : undefined;\n const originalHeaders = combineHeaders(\n normalizeHeaders(request?.headers),\n normalizeHeaders(init?.headers),\n );\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n let effectiveBody: BodyInit | undefined = init?.body ?? undefined;\n if (effectiveBody === undefined && request && request.body !== null) {\n try {\n effectiveBody = await request.clone().text();\n } catch {}\n }\n\n const effectiveMethod = init?.method ?? request?.method;\n\n if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {\n return effectiveFetch(input, {\n ...init,\n headers: headersWithUserAgent as HeadersInit,\n });\n }\n\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body = prepareBodyString(effectiveBody);\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: 'POST',\n headers: Object.entries(headersWithUserAgent),\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service: 'aws-external-anthropic',\n });\n\n const signingResult = await signer.sign();\n const signedHeaders = normalizeHeaders(signingResult.headers);\n const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);\n\n return effectiveFetch(input, {\n ...init,\n body,\n headers: combinedHeaders as HeadersInit,\n });\n };\n}\n\nfunction prepareBodyString(body: BodyInit | undefined): string {\n if (typeof body === 'string') {\n return body;\n } else if (body instanceof Uint8Array) {\n return new TextDecoder().decode(body);\n } else if (body instanceof ArrayBuffer) {\n return new TextDecoder().decode(new Uint8Array(body));\n } else {\n return JSON.stringify(body);\n }\n}\n\n/**\n * Creates a fetch function that applies x-api-key header authentication.\n *\n * @param apiKey - The API key to use for x-api-key header authentication.\n * @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that adds the x-api-key header to requests.\n */\nexport function createApiKeyFetchFunction(\n apiKey: string,\n fetch?: FetchFunction,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const effectiveFetch = fetch ?? globalThis.fetch;\n const originalHeaders = normalizeHeaders(init?.headers);\n const headersWithUserAgent = withUserAgentSuffix(\n originalHeaders,\n `ai-sdk/anthropic-aws/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n );\n\n const finalHeaders = combineHeaders(headersWithUserAgent, {\n 'x-api-key': apiKey,\n });\n\n return effectiveFetch(input, {\n ...init,\n headers: finalHeaders as HeadersInit,\n });\n };\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAEK;;;ACfP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAAmB;;;ACLrB,IAAM,UACX,OACI,WACA;;;ADoBC,SAAS,yBACd,gBAGA,OACe;AACf,SAAO,OACL,OACA,SACsB;AAlC1B;AAmCI,UAAM,iBAAiB,wBAAS,WAAW;AAC3C,UAAM,UAAU,iBAAiB,UAAU,QAAQ;AACnD,UAAM,kBAAkB;AAAA,MACtB,iBAAiB,mCAAS,OAAO;AAAA,MACjC,iBAAiB,6BAAM,OAAO;AAAA,IAChC;AACA,UAAM,uBAAuB;AAAA,MAC3B;AAAA,MACA,wBAAwB,OAAO;AAAA,MAC/B,+BAA+B;AA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