@ai-sdk/amazon-bedrock 4.0.98 → 4.0.100

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.98",
3
+ "version": "4.0.100",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -38,9 +38,9 @@
38
38
  "@smithy/eventstream-codec": "^4.0.1",
39
39
  "@smithy/util-utf8": "^4.0.0",
40
40
  "aws4fetch": "^1.0.20",
41
- "@ai-sdk/anthropic": "3.0.73",
41
+ "@ai-sdk/anthropic": "3.0.74",
42
42
  "@ai-sdk/provider": "3.0.10",
43
- "@ai-sdk/provider-utils": "4.0.25"
43
+ "@ai-sdk/provider-utils": "4.0.26"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "20.17.24",
@@ -24,12 +24,14 @@ export interface BedrockCredentials {
24
24
  */
25
25
  export function createSigV4FetchFunction(
26
26
  getCredentials: () => BedrockCredentials | PromiseLike<BedrockCredentials>,
27
- fetch: FetchFunction = globalThis.fetch,
27
+ fetch?: FetchFunction,
28
28
  ): FetchFunction {
29
29
  return async (
30
30
  input: RequestInfo | URL,
31
31
  init?: RequestInit,
32
32
  ): Promise<Response> => {
33
+ // avoid caching globalThis.fetch in case it is patched by other libraries
34
+ const effectiveFetch = fetch ?? globalThis.fetch;
33
35
  const request = input instanceof Request ? input : undefined;
34
36
  const originalHeaders = combineHeaders(
35
37
  normalizeHeaders(request?.headers),
@@ -51,7 +53,7 @@ export function createSigV4FetchFunction(
51
53
  const effectiveMethod = init?.method ?? request?.method;
52
54
 
53
55
  if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {
54
- return fetch(input, {
56
+ return effectiveFetch(input, {
55
57
  ...init,
56
58
  headers: headersWithUserAgent as HeadersInit,
57
59
  });
@@ -84,7 +86,7 @@ export function createSigV4FetchFunction(
84
86
  // Use the combined headers directly as HeadersInit
85
87
  const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);
86
88
 
87
- return fetch(input, {
89
+ return effectiveFetch(input, {
88
90
  ...init,
89
91
  body,
90
92
  headers: combinedHeaders as HeadersInit,
@@ -113,12 +115,14 @@ function prepareBodyString(body: BodyInit | undefined): string {
113
115
  */
114
116
  export function createApiKeyFetchFunction(
115
117
  apiKey: string,
116
- fetch: FetchFunction = globalThis.fetch,
118
+ fetch?: FetchFunction,
117
119
  ): FetchFunction {
118
120
  return async (
119
121
  input: RequestInfo | URL,
120
122
  init?: RequestInit,
121
123
  ): Promise<Response> => {
124
+ // avoid caching globalThis.fetch in case it is patched by other libraries
125
+ const effectiveFetch = fetch ?? globalThis.fetch;
122
126
  const originalHeaders = normalizeHeaders(init?.headers);
123
127
  const headersWithUserAgent = withUserAgentSuffix(
124
128
  originalHeaders,
@@ -130,7 +134,7 @@ export function createApiKeyFetchFunction(
130
134
  Authorization: `Bearer ${apiKey}`,
131
135
  });
132
136
 
133
- return fetch(input, {
137
+ return effectiveFetch(input, {
134
138
  ...init,
135
139
  headers: finalHeaders as HeadersInit,
136
140
  });
@@ -309,9 +309,20 @@ export async function convertToBedrockChatMessages(
309
309
  },
310
310
  },
311
311
  });
312
- } else {
313
- // trim the last text part if it's the last message in the block
314
- // because Bedrock does not allow trailing whitespace
312
+ } else if (
313
+ part.providerOptions == null ||
314
+ Object.keys(part.providerOptions).every(
315
+ k => k === 'bedrock' || k === 'amazonBedrock',
316
+ )
317
+ ) {
318
+ // No foreign-provider metadata — preserve text. This covers
319
+ // the prefill case where the caller hand-crafts a reasoning
320
+ // block without a signature. Forwarding reasoning that was
321
+ // signed by a different provider (e.g. anthropic) would
322
+ // cause Bedrock to reject with
323
+ // `thinking.signature: Field required`, so we drop those.
324
+ // trim the last text part if it's the last message in the
325
+ // block because Bedrock does not allow trailing whitespace
315
326
  // in pre-filled assistant responses
316
327
  bedrockContent.push({
317
328
  reasoningContent: {