ai 7.0.120 → 7.0.122
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 +23 -0
- package/dist/index.d.ts +29 -3
- package/dist/index.js +106 -31
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/04-ai-sdk-ui/02-chatbot.mdx +9 -0
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +8 -0
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +10 -3
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +10 -1
- package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +5 -5
- package/docs/08-migration-guides/37-migration-guide-3-3.mdx +1 -1
- package/package.json +11 -11
- package/src/embed/embed-many.ts +5 -3
- package/src/generate-image/generate-image.ts +8 -3
- package/src/generate-text/smooth-stream.ts +24 -9
- package/src/generate-text/stream-text-result.ts +5 -0
- package/src/generate-video/generate-video.ts +6 -4
- package/src/registry/provider-registry.ts +1 -1
- package/src/ui/chat.ts +13 -4
- package/src/ui/http-chat-transport.ts +19 -3
- package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +15 -3
- package/src/ui/process-ui-message-stream.ts +51 -14
- package/src/ui/ui-messages.ts +14 -0
- package/src/ui/validate-ui-messages.ts +2 -0
- package/src/ui-message-stream/to-ui-message-chunk.ts +9 -1
- package/src/ui-message-stream/to-ui-message-stream.ts +1 -1
- package/src/util/set-own.ts +16 -0
|
@@ -18,6 +18,11 @@ export type ToUIMessageChunkOptions<
|
|
|
18
18
|
sendSources?: boolean;
|
|
19
19
|
sendStart?: boolean;
|
|
20
20
|
sendFinish?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Formats stream errors, invalid tool calls, and application-executed tool
|
|
23
|
+
* errors. Provider-executed tool execution errors bypass this callback so
|
|
24
|
+
* their original error data survives model-message round trips.
|
|
25
|
+
*/
|
|
21
26
|
onError?: (error: unknown) => string;
|
|
22
27
|
messageMetadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
|
23
28
|
responseMessageId?: string;
|
|
@@ -40,7 +45,7 @@ export function toUIMessageChunk<
|
|
|
40
45
|
sendSources = false,
|
|
41
46
|
sendStart = true,
|
|
42
47
|
sendFinish = true,
|
|
43
|
-
onError = () => 'An error occurred.', //
|
|
48
|
+
onError = () => 'An error occurred.', // masks errors except provider-executed tool execution errors
|
|
44
49
|
messageMetadata,
|
|
45
50
|
responseMessageId,
|
|
46
51
|
}: ToUIMessageChunkOptions<TOOLS, UI_MESSAGE> = {},
|
|
@@ -305,6 +310,9 @@ export function toUIMessageChunk<
|
|
|
305
310
|
case 'tool-error': {
|
|
306
311
|
const dynamic = isDynamic(part);
|
|
307
312
|
|
|
313
|
+
// Preserve provider error codes for model-message round trips and harness
|
|
314
|
+
// runtime error messages. These execution errors intentionally bypass
|
|
315
|
+
// onError; invalid tool calls and stream errors still go through it.
|
|
308
316
|
return {
|
|
309
317
|
type: 'tool-output-error',
|
|
310
318
|
toolCallId: part.toolCallId,
|
|
@@ -26,7 +26,7 @@ export function toUIMessageStream<
|
|
|
26
26
|
sendSources = false,
|
|
27
27
|
sendStart = true,
|
|
28
28
|
sendFinish = true,
|
|
29
|
-
onError = () => 'An error occurred.', //
|
|
29
|
+
onError = () => 'An error occurred.', // masks errors except provider-executed tool execution errors
|
|
30
30
|
messageMetadata,
|
|
31
31
|
originalMessages,
|
|
32
32
|
generateMessageId,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes an enumerable own property without invoking inherited setters such as
|
|
3
|
+
* `Object.prototype.__proto__`. Keeps the target object's prototype unchanged.
|
|
4
|
+
*/
|
|
5
|
+
export function setOwn<T>(
|
|
6
|
+
object: Record<string, T>,
|
|
7
|
+
key: string,
|
|
8
|
+
value: T,
|
|
9
|
+
): void {
|
|
10
|
+
Object.defineProperty(object, key, {
|
|
11
|
+
value,
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
});
|
|
16
|
+
}
|