@ai-sdk/amazon-bedrock 5.0.0-beta.46 → 5.0.0-beta.47

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": "5.0.0-beta.46",
3
+ "version": "5.0.0-beta.47",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -26,12 +26,14 @@ export function createSigV4FetchFunction(
26
26
  getCredentials: () =>
27
27
  | AmazonBedrockCredentials
28
28
  | PromiseLike<AmazonBedrockCredentials>,
29
- fetch: FetchFunction = globalThis.fetch,
29
+ fetch?: FetchFunction,
30
30
  ): FetchFunction {
31
31
  return async (
32
32
  input: RequestInfo | URL,
33
33
  init?: RequestInit,
34
34
  ): Promise<Response> => {
35
+ // avoid caching globalThis.fetch in case it is patched by other libraries
36
+ const effectiveFetch = fetch ?? globalThis.fetch;
35
37
  const request = input instanceof Request ? input : undefined;
36
38
  const originalHeaders = combineHeaders(
37
39
  normalizeHeaders(request?.headers),
@@ -53,7 +55,7 @@ export function createSigV4FetchFunction(
53
55
  const effectiveMethod = init?.method ?? request?.method;
54
56
 
55
57
  if (effectiveMethod?.toUpperCase() !== 'POST' || !effectiveBody) {
56
- return fetch(input, {
58
+ return effectiveFetch(input, {
57
59
  ...init,
58
60
  headers: headersWithUserAgent as HeadersInit,
59
61
  });
@@ -86,7 +88,7 @@ export function createSigV4FetchFunction(
86
88
  // Use the combined headers directly as HeadersInit
87
89
  const combinedHeaders = combineHeaders(headersWithUserAgent, signedHeaders);
88
90
 
89
- return fetch(input, {
91
+ return effectiveFetch(input, {
90
92
  ...init,
91
93
  body,
92
94
  headers: combinedHeaders as HeadersInit,
@@ -115,12 +117,14 @@ function prepareBodyString(body: BodyInit | undefined): string {
115
117
  */
116
118
  export function createApiKeyFetchFunction(
117
119
  apiKey: string,
118
- fetch: FetchFunction = globalThis.fetch,
120
+ fetch?: FetchFunction,
119
121
  ): FetchFunction {
120
122
  return async (
121
123
  input: RequestInfo | URL,
122
124
  init?: RequestInit,
123
125
  ): Promise<Response> => {
126
+ // avoid caching globalThis.fetch in case it is patched by other libraries
127
+ const effectiveFetch = fetch ?? globalThis.fetch;
124
128
  const originalHeaders = normalizeHeaders(init?.headers);
125
129
  const headersWithUserAgent = withUserAgentSuffix(
126
130
  originalHeaders,
@@ -132,7 +136,7 @@ export function createApiKeyFetchFunction(
132
136
  Authorization: `Bearer ${apiKey}`,
133
137
  });
134
138
 
135
- return fetch(input, {
139
+ return effectiveFetch(input, {
136
140
  ...init,
137
141
  headers: finalHeaders as HeadersInit,
138
142
  });
@@ -361,9 +361,20 @@ export async function convertToAmazonBedrockChatMessages(
361
361
  },
362
362
  },
363
363
  });
364
- } else {
365
- // trim the last text part if it's the last message in the block
366
- // because Bedrock does not allow trailing whitespace
364
+ } else if (
365
+ part.providerOptions == null ||
366
+ Object.keys(part.providerOptions).every(
367
+ k => k === 'bedrock' || k === 'amazonBedrock',
368
+ )
369
+ ) {
370
+ // No foreign-provider metadata — preserve text. This covers
371
+ // the prefill case where the caller hand-crafts a reasoning
372
+ // block without a signature. Forwarding reasoning that was
373
+ // signed by a different provider (e.g. anthropic) would
374
+ // cause Bedrock to reject with
375
+ // `thinking.signature: Field required`, so we drop those.
376
+ // trim the last text part if it's the last message in the
377
+ // block because Bedrock does not allow trailing whitespace
367
378
  // in pre-filled assistant responses
368
379
  amazonBedrockContent.push({
369
380
  reasoningContent: {