@ai-sdk/provider-utils
Advanced tools
+6
-0
| # @ai-sdk/provider-utils | ||
| ## 4.0.33 | ||
| ### Patch Changes | ||
| - b30e43a: Limit JSON response body reads in response handlers to prevent unbounded memory use. | ||
| ## 4.0.32 | ||
@@ -4,0 +10,0 @@ |
+1
-1
| { | ||
| "name": "@ai-sdk/provider-utils", | ||
| "version": "4.0.32", | ||
| "version": "4.0.33", | ||
| "license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -5,2 +5,3 @@ import { APICallError, EmptyResponseBodyError } from '@ai-sdk/provider'; | ||
| import { parseJsonEventStream } from './parse-json-event-stream'; | ||
| import { readResponseWithSizeLimit } from './read-response-with-size-limit'; | ||
| import type { FlexibleSchema } from './schema'; | ||
@@ -18,2 +19,19 @@ | ||
| const textDecoder = new TextDecoder(); | ||
| async function readResponseBodyAsText({ | ||
| response, | ||
| url, | ||
| }: { | ||
| response: Response; | ||
| url: string; | ||
| }) { | ||
| return textDecoder.decode( | ||
| await readResponseWithSizeLimit({ | ||
| response, | ||
| url, | ||
| }), | ||
| ); | ||
| } | ||
| export const createJsonErrorResponseHandler = | ||
@@ -30,3 +48,3 @@ <T>({ | ||
| async ({ response, url, requestBodyValues }) => { | ||
| const responseBody = await response.text(); | ||
| const responseBody = await readResponseBodyAsText({ response, url }); | ||
| const responseHeaders = extractResponseHeaders(response); | ||
@@ -109,3 +127,3 @@ | ||
| async ({ response, url, requestBodyValues }) => { | ||
| const responseBody = await response.text(); | ||
| const responseBody = await readResponseBodyAsText({ response, url }); | ||
@@ -177,3 +195,3 @@ const parsedResult = await safeParseJSON({ | ||
| const responseHeaders = extractResponseHeaders(response); | ||
| const responseBody = await response.text(); | ||
| const responseBody = await readResponseBodyAsText({ response, url }); | ||
@@ -180,0 +198,0 @@ return { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
927719
0.26%12629
0.32%