@ai-sdk/amazon-bedrock 4.0.27 → 4.0.29

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/anthropic/index.js +1 -1
  3. package/dist/anthropic/index.mjs +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/index.mjs +1 -1
  6. package/package.json +9 -5
  7. package/src/__fixtures__/bedrock-json-only-text-first.1.chunks.txt +0 -7
  8. package/src/__fixtures__/bedrock-json-other-tool.1.chunks.txt +0 -6
  9. package/src/__fixtures__/bedrock-json-other-tool.1.json +0 -24
  10. package/src/__fixtures__/bedrock-json-tool-text-then-weather-then-json.1.chunks.txt +0 -12
  11. package/src/__fixtures__/bedrock-json-tool-with-answer.1.json +0 -29
  12. package/src/__fixtures__/bedrock-json-tool.1.chunks.txt +0 -4
  13. package/src/__fixtures__/bedrock-json-tool.1.json +0 -35
  14. package/src/__fixtures__/bedrock-json-tool.2.chunks.txt +0 -6
  15. package/src/__fixtures__/bedrock-json-tool.2.json +0 -28
  16. package/src/__fixtures__/bedrock-json-tool.3.chunks.txt +0 -7
  17. package/src/__fixtures__/bedrock-json-tool.3.json +0 -36
  18. package/src/__fixtures__/bedrock-json-with-tool.1.chunks.txt +0 -9
  19. package/src/__fixtures__/bedrock-json-with-tool.1.json +0 -41
  20. package/src/__fixtures__/bedrock-json-with-tools.1.chunks.txt +0 -12
  21. package/src/__fixtures__/bedrock-json-with-tools.1.json +0 -50
  22. package/src/__fixtures__/bedrock-tool-call.1.chunks.txt +0 -6
  23. package/src/__fixtures__/bedrock-tool-call.1.json +0 -24
  24. package/src/__fixtures__/bedrock-tool-no-args.chunks.txt +0 -8
  25. package/src/__fixtures__/bedrock-tool-no-args.json +0 -25
  26. package/src/anthropic/bedrock-anthropic-fetch.test.ts +0 -344
  27. package/src/anthropic/bedrock-anthropic-provider.test.ts +0 -456
  28. package/src/bedrock-chat-language-model.test.ts +0 -4569
  29. package/src/bedrock-embedding-model.test.ts +0 -148
  30. package/src/bedrock-event-stream-response-handler.test.ts +0 -233
  31. package/src/bedrock-image-model.test.ts +0 -866
  32. package/src/bedrock-provider.test.ts +0 -457
  33. package/src/bedrock-sigv4-fetch.test.ts +0 -675
  34. package/src/convert-bedrock-usage.test.ts +0 -207
  35. package/src/convert-to-bedrock-chat-messages.test.ts +0 -1175
  36. package/src/inject-fetch-headers.test.ts +0 -135
  37. package/src/normalize-tool-call-id.test.ts +0 -72
  38. package/src/reranking/__fixtures__/bedrock-reranking.1.json +0 -12
  39. package/src/reranking/bedrock-reranking-model.test.ts +0 -299
@@ -1,207 +0,0 @@
1
- import { convertBedrockUsage } from './convert-bedrock-usage';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('convertBedrockUsage', () => {
5
- it('should convert basic usage without cache tokens', () => {
6
- const result = convertBedrockUsage({
7
- inputTokens: 100,
8
- outputTokens: 50,
9
- });
10
-
11
- expect(result).toEqual({
12
- inputTokens: {
13
- total: 100,
14
- noCache: 100,
15
- cacheRead: 0,
16
- cacheWrite: 0,
17
- },
18
- outputTokens: {
19
- total: 50,
20
- text: 50,
21
- reasoning: undefined,
22
- },
23
- raw: {
24
- inputTokens: 100,
25
- outputTokens: 50,
26
- },
27
- });
28
- });
29
-
30
- it('should convert usage with cache read tokens', () => {
31
- const result = convertBedrockUsage({
32
- inputTokens: 100,
33
- outputTokens: 50,
34
- cacheReadInputTokens: 80,
35
- });
36
-
37
- expect(result).toEqual({
38
- inputTokens: {
39
- total: 180, // 100 + 80 + 0
40
- noCache: 100,
41
- cacheRead: 80,
42
- cacheWrite: 0,
43
- },
44
- outputTokens: {
45
- total: 50,
46
- text: 50,
47
- reasoning: undefined,
48
- },
49
- raw: {
50
- inputTokens: 100,
51
- outputTokens: 50,
52
- cacheReadInputTokens: 80,
53
- },
54
- });
55
- });
56
-
57
- it('should convert usage with cache write tokens', () => {
58
- const result = convertBedrockUsage({
59
- inputTokens: 100,
60
- outputTokens: 50,
61
- cacheWriteInputTokens: 60,
62
- });
63
-
64
- expect(result).toEqual({
65
- inputTokens: {
66
- total: 160, // 100 + 0 + 60
67
- noCache: 100,
68
- cacheRead: 0,
69
- cacheWrite: 60,
70
- },
71
- outputTokens: {
72
- total: 50,
73
- text: 50,
74
- reasoning: undefined,
75
- },
76
- raw: {
77
- inputTokens: 100,
78
- outputTokens: 50,
79
- cacheWriteInputTokens: 60,
80
- },
81
- });
82
- });
83
-
84
- it('should convert usage with both cache read and write tokens', () => {
85
- const result = convertBedrockUsage({
86
- inputTokens: 100,
87
- outputTokens: 50,
88
- cacheReadInputTokens: 80,
89
- cacheWriteInputTokens: 60,
90
- });
91
-
92
- expect(result).toEqual({
93
- inputTokens: {
94
- total: 240, // 100 + 80 + 60
95
- noCache: 100,
96
- cacheRead: 80,
97
- cacheWrite: 60,
98
- },
99
- outputTokens: {
100
- total: 50,
101
- text: 50,
102
- reasoning: undefined,
103
- },
104
- raw: {
105
- inputTokens: 100,
106
- outputTokens: 50,
107
- cacheReadInputTokens: 80,
108
- cacheWriteInputTokens: 60,
109
- },
110
- });
111
- });
112
-
113
- it('should handle null cache tokens', () => {
114
- const result = convertBedrockUsage({
115
- inputTokens: 100,
116
- outputTokens: 50,
117
- cacheReadInputTokens: null,
118
- cacheWriteInputTokens: null,
119
- });
120
-
121
- expect(result).toEqual({
122
- inputTokens: {
123
- total: 100,
124
- noCache: 100,
125
- cacheRead: 0,
126
- cacheWrite: 0,
127
- },
128
- outputTokens: {
129
- total: 50,
130
- text: 50,
131
- reasoning: undefined,
132
- },
133
- raw: {
134
- inputTokens: 100,
135
- outputTokens: 50,
136
- cacheReadInputTokens: null,
137
- cacheWriteInputTokens: null,
138
- },
139
- });
140
- });
141
-
142
- it('should handle null usage', () => {
143
- const result = convertBedrockUsage(null);
144
-
145
- expect(result).toEqual({
146
- inputTokens: {
147
- total: undefined,
148
- noCache: undefined,
149
- cacheRead: undefined,
150
- cacheWrite: undefined,
151
- },
152
- outputTokens: {
153
- total: undefined,
154
- text: undefined,
155
- reasoning: undefined,
156
- },
157
- raw: undefined,
158
- });
159
- });
160
-
161
- it('should handle undefined usage', () => {
162
- const result = convertBedrockUsage(undefined);
163
-
164
- expect(result).toEqual({
165
- inputTokens: {
166
- total: undefined,
167
- noCache: undefined,
168
- cacheRead: undefined,
169
- cacheWrite: undefined,
170
- },
171
- outputTokens: {
172
- total: undefined,
173
- text: undefined,
174
- reasoning: undefined,
175
- },
176
- raw: undefined,
177
- });
178
- });
179
-
180
- it('should include totalTokens in raw when provided', () => {
181
- const result = convertBedrockUsage({
182
- inputTokens: 100,
183
- outputTokens: 50,
184
- totalTokens: 150,
185
- });
186
-
187
- expect(result.raw).toEqual({
188
- inputTokens: 100,
189
- outputTokens: 50,
190
- totalTokens: 150,
191
- });
192
- });
193
-
194
- it('should preserve raw usage data', () => {
195
- const rawUsage = {
196
- inputTokens: 100,
197
- outputTokens: 50,
198
- totalTokens: 150,
199
- cacheReadInputTokens: 80,
200
- cacheWriteInputTokens: 60,
201
- };
202
-
203
- const result = convertBedrockUsage(rawUsage);
204
-
205
- expect(result.raw).toEqual(rawUsage);
206
- });
207
- });