ai 7.0.90 → 7.0.92
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 +21 -0
- package/dist/index.d.ts +45 -12
- package/dist/index.js +412 -90
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -2
- package/dist/internal/index.js +9 -7
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +5 -0
- package/docs/03-agents/06-policy-tool-approvals.mdx +2 -1
- package/docs/03-agents/06-tool-approvals.mdx +7 -4
- package/docs/03-ai-sdk-core/50-error-handling.mdx +83 -6
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +24 -4
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +1 -1
- package/package.json +6 -6
- package/src/generate-text/execute-tools-from-stream.ts +18 -4
- package/src/generate-text/generate-text-events.ts +1 -1
- package/src/generate-text/index.ts +2 -0
- package/src/generate-text/invoke-tool-callbacks-from-stream.ts +14 -2
- package/src/generate-text/smooth-stream.ts +19 -4
- package/src/generate-text/stream-retry-attempt-boundary.ts +29 -0
- package/src/generate-text/stream-text.ts +637 -162
- package/src/ui/call-completion-api.ts +1 -1
- package/src/ui/http-chat-transport.ts +2 -2
- package/src/util/async-iterable-stream.ts +1 -1
- package/src/util/prepare-retries.ts +9 -5
|
@@ -201,7 +201,7 @@ export abstract class HttpChatTransport<
|
|
|
201
201
|
|
|
202
202
|
if (!response.ok) {
|
|
203
203
|
throw new Error(
|
|
204
|
-
(await response.text())
|
|
204
|
+
(await response.text()) || 'Failed to fetch the chat response.',
|
|
205
205
|
);
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -257,7 +257,7 @@ export abstract class HttpChatTransport<
|
|
|
257
257
|
|
|
258
258
|
if (!response.ok) {
|
|
259
259
|
throw new Error(
|
|
260
|
-
(await response.text())
|
|
260
|
+
(await response.text()) || 'Failed to fetch the chat response.',
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
|
|
@@ -43,7 +43,7 @@ export function asAsyncIterableStream<T>(
|
|
|
43
43
|
* Implements the async iterator protocol for the stream.
|
|
44
44
|
* Ensures proper cleanup (cancelling and releasing the reader) on completion, early exit, or error.
|
|
45
45
|
*/
|
|
46
|
-
(stream as
|
|
46
|
+
(stream as unknown as AsyncIterable<T>)[Symbol.asyncIterator] = function (
|
|
47
47
|
this: ReadableStream<T>,
|
|
48
48
|
): AsyncIterator<T> {
|
|
49
49
|
const reader = this.getReader();
|
|
@@ -7,9 +7,13 @@ import { retryWithExponentialBackoffRespectingRetryHeaders } from '../util/retry
|
|
|
7
7
|
export function prepareRetries({
|
|
8
8
|
maxRetries,
|
|
9
9
|
abortSignal,
|
|
10
|
+
parameter = 'maxRetries',
|
|
11
|
+
defaultMaxRetries = 2,
|
|
10
12
|
}: {
|
|
11
13
|
maxRetries: number | undefined;
|
|
12
14
|
abortSignal: AbortSignal | undefined;
|
|
15
|
+
parameter?: string;
|
|
16
|
+
defaultMaxRetries?: number;
|
|
13
17
|
}): {
|
|
14
18
|
maxRetries: number;
|
|
15
19
|
retry: RetryFunction;
|
|
@@ -17,22 +21,22 @@ export function prepareRetries({
|
|
|
17
21
|
if (maxRetries != null) {
|
|
18
22
|
if (!Number.isInteger(maxRetries)) {
|
|
19
23
|
throw new InvalidArgumentError({
|
|
20
|
-
parameter
|
|
24
|
+
parameter,
|
|
21
25
|
value: maxRetries,
|
|
22
|
-
message:
|
|
26
|
+
message: `${parameter} must be an integer`,
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
if (maxRetries < 0) {
|
|
27
31
|
throw new InvalidArgumentError({
|
|
28
|
-
parameter
|
|
32
|
+
parameter,
|
|
29
33
|
value: maxRetries,
|
|
30
|
-
message:
|
|
34
|
+
message: `${parameter} must be >= 0`,
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
const maxRetriesResult = maxRetries ??
|
|
39
|
+
const maxRetriesResult = maxRetries ?? defaultMaxRetries;
|
|
36
40
|
|
|
37
41
|
return {
|
|
38
42
|
maxRetries: maxRetriesResult,
|