ai 7.0.27 → 7.0.29

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/index.js +26 -20
  3. package/dist/index.js.map +1 -1
  4. package/dist/internal/index.js +1 -1
  5. package/docs/02-foundations/02-providers-and-models.mdx +5 -2
  6. package/docs/02-foundations/04-tools.mdx +1 -1
  7. package/docs/02-getting-started/02-nextjs-app-router.mdx +1 -1
  8. package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
  9. package/docs/02-getting-started/06-nodejs.mdx +1 -1
  10. package/docs/03-agents/08-terminal-ui.mdx +28 -7
  11. package/docs/03-ai-sdk-core/01-overview.mdx +1 -1
  12. package/docs/03-ai-sdk-core/05-generating-text.mdx +5 -5
  13. package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +3 -3
  14. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +10 -10
  15. package/docs/03-ai-sdk-core/25-settings.mdx +1 -1
  16. package/docs/03-ai-sdk-core/30-embeddings.mdx +1 -1
  17. package/docs/03-ai-sdk-core/31-reranking.mdx +4 -4
  18. package/docs/03-ai-sdk-core/35-image-generation.mdx +1 -1
  19. package/docs/03-ai-sdk-core/36-transcription.mdx +9 -4
  20. package/docs/03-ai-sdk-core/37-speech.mdx +1 -0
  21. package/docs/03-ai-sdk-core/38-video-generation.mdx +5 -5
  22. package/docs/03-ai-sdk-core/50-error-handling.mdx +5 -5
  23. package/docs/03-ai-sdk-core/55-testing.mdx +1 -1
  24. package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +5 -5
  25. package/docs/04-ai-sdk-ui/02-chatbot.mdx +2 -2
  26. package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +3 -3
  27. package/docs/04-ai-sdk-ui/20-streaming-data.mdx +1 -1
  28. package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +1 -1
  29. package/docs/06-advanced/04-caching.mdx +1 -1
  30. package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +1 -1
  31. package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +1 -1
  32. package/docs/07-reference/01-ai-sdk-core/index.mdx +0 -5
  33. package/docs/07-reference/06-ai-sdk-tui/01-run-agent-tui.mdx +29 -8
  34. package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
  35. package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
  36. package/docs/08-migration-guides/37-migration-guide-3-3.mdx +1 -1
  37. package/docs/08-migration-guides/39-migration-guide-3-1.mdx +1 -1
  38. package/docs/09-troubleshooting/14-tool-calling-with-structured-outputs.mdx +1 -1
  39. package/docs/09-troubleshooting/15-stream-text-not-working.mdx +1 -1
  40. package/package.json +2 -2
  41. package/src/ui/chat.ts +24 -17
@@ -5,7 +5,7 @@ description: API Reference for safeValidateUIMessages
5
5
 
6
6
  # `safeValidateUIMessages`
7
7
 
8
- `safeValidateUIMessages` is an async function that validates UI messages like [`validateUIMessages`](https://ai-sdk.dev/docs/reference/ai-sdk-core/validate-ui-messages), but instead of throwing it returns an object with a `success` key and either `data` or `error`.
8
+ `safeValidateUIMessages` is an async function that validates UI messages like [`validateUIMessages`](/docs/reference/ai-sdk-core/validate-ui-messages), but instead of throwing it returns an object with a `success` key and either `data` or `error`.
9
9
 
10
10
  ## Basic Usage
11
11
 
@@ -111,11 +111,6 @@ It also contains the following helper functions:
111
111
  description: 'Creates a client for connecting to MCP servers.',
112
112
  href: '/docs/reference/ai-sdk-core/create-mcp-client',
113
113
  },
114
- {
115
- title: 'validateJSONRPCMessage()',
116
- description: 'Validates unknown values as MCP JSON-RPC messages.',
117
- href: '/docs/reference/ai-sdk-core/validate-json-rpc-message',
118
- },
119
114
  {
120
115
  title: 'MCP Apps',
121
116
  description:
@@ -5,9 +5,9 @@ description: API Reference for the runAgentTUI function.
5
5
 
6
6
  # `runAgentTUI()`
7
7
 
8
- Runs a `ToolLoopAgent` in an interactive terminal UI. The terminal UI reads user
9
- prompts, streams assistant responses, renders markdown, displays tool and
10
- reasoning sections, and handles manual tool approvals.
8
+ Runs a local agent or chat transport in an interactive terminal UI. The
9
+ terminal UI reads user prompts, streams assistant responses, renders markdown,
10
+ displays tool and reasoning sections, and handles manual tool approvals.
11
11
 
12
12
  `runAgentTUI` runs until the user exits with `Esc` or `Ctrl+C`.
13
13
 
@@ -49,9 +49,16 @@ await runAgentTUI({
49
49
  {
50
50
  name: 'agent',
51
51
  type: 'AgentTUIAgent',
52
- isRequired: true,
52
+ isOptional: true,
53
+ description:
54
+ 'The agent to run. Provide exactly one of `agent` or `transport`. The agent must not require per-call options and must not use structured output.',
55
+ },
56
+ {
57
+ name: 'transport',
58
+ type: 'ChatTransport<UIMessage>',
59
+ isOptional: true,
53
60
  description:
54
- 'The agent to run. The agent must not require per-call options and must not use structured output.',
61
+ 'The transport used to communicate with a remote agent. Provide exactly one of `agent` or `transport`.',
55
62
  },
56
63
  {
57
64
  name: 'title',
@@ -168,6 +175,19 @@ await runAgentTUI({
168
175
  });
169
176
  ```
170
177
 
178
+ ## Example with a Chat Transport
179
+
180
+ ```ts
181
+ import { DefaultChatTransport } from 'ai';
182
+
183
+ await runAgentTUI({
184
+ title: 'Remote Assistant',
185
+ transport: new DefaultChatTransport({
186
+ api: 'https://example.com/api/chat',
187
+ }),
188
+ });
189
+ ```
190
+
171
191
  ## Example with Sandbox
172
192
 
173
193
  ```ts
@@ -192,8 +212,9 @@ working directory or exposed ports.
192
212
 
193
213
  ## Compatibility
194
214
 
195
- Use `runAgentTUI` for agents that can run directly from free-form user input.
196
- Use `agent.generate()` or `agent.stream()` directly when you need fixed prompts,
215
+ Use the `agent` option for agents that can run directly from free-form user
216
+ input. Use the `transport` option to communicate with a remote agent. Use
217
+ `agent.generate()` or `agent.stream()` directly when you need fixed prompts,
197
218
  per-call options, structured output, custom result inspection, or custom stream
198
219
  processing.
199
220
 
@@ -201,4 +222,4 @@ processing.
201
222
 
202
223
  - [Terminal UI guide](/docs/agents/terminal-ui)
203
224
  - [Building Agents](/docs/agents/building-agents)
204
- - [ToolLoopAgent guide](/docs/agents/overview#tooloopagent-class)
225
+ - [ToolLoopAgent guide](/docs/agents/overview#toolloopagent-class)
@@ -1902,7 +1902,7 @@ const model = xai('grok-4.3');
1902
1902
  const chatModel = xai.chat('grok-4.3');
1903
1903
  ```
1904
1904
 
1905
- # Migration Skill
1905
+ ## Migration Skill
1906
1906
 
1907
1907
  Use the command below to add the migration skill and guide your agent
1908
1908
 
@@ -817,7 +817,7 @@ The following options have been removed from the `useChat` hook:
817
817
  - `maxAutomaticRoundtrips`
818
818
  - `maxToolRoundtrips`
819
819
 
820
- Please use the [`maxSteps`](/docs/ai-sdk-core/tools-and-tool-calling#multi-step-calls) option instead.
820
+ Please use the [`maxSteps`](/docs/ai-sdk-core/tools-and-tool-calling#multi-step-calls-using-stopwhen) option instead.
821
821
  The value of `maxSteps` is equal to roundtrips + 1.
822
822
 
823
823
  ```ts filename="AI SDK 3.4"
@@ -20,7 +20,7 @@ introducing significant improvements and new features across the AI SDK and its
20
20
 
21
21
  ### Open Telemetry Support
22
22
 
23
- - Added experimental [OpenTelemetry support](/docs/ai-sdk-core/telemetry#telemetry) for all [AI SDK Core functions](/docs/ai-sdk-core/overview#ai-sdk-core-functions), enabling better observability and tracing capabilities.
23
+ - Added experimental [OpenTelemetry support](/docs/ai-sdk-core/telemetry) for all [AI SDK Core functions](/docs/ai-sdk-core/overview#ai-sdk-core-functions), enabling better observability and tracing capabilities.
24
24
 
25
25
  ### AI SDK UI Improvements
26
26
 
@@ -129,7 +129,7 @@ async function submitMessage(userInput = 'What is the weather in SF?') {
129
129
  }
130
130
  ```
131
131
 
132
- With the new [`streamUI`](/docs/reference/ai-sdk-rsc/stream-ui) function, you can now use any compatible AI SDK provider. In this example, you import the AI SDK OpenAI provider. Then, you pass it to the [`model`](/docs/reference/ai-sdk-rsc/stream-ui#model) key of the new [`streamUI`](/docs/reference/ai-sdk-rsc/stream-ui) function. Finally, you declare a tool and return a React Server Component, defined in the [`generate`](/docs/reference/ai-sdk-rsc/stream-ui#tools-generate) key of the tool.
132
+ With the new [`streamUI`](/docs/reference/ai-sdk-rsc/stream-ui) function, you can now use any compatible AI SDK provider. In this example, you import the AI SDK OpenAI provider. Then, you pass it to the [`model`](/docs/reference/ai-sdk-rsc/stream-ui#model) key of the new [`streamUI`](/docs/reference/ai-sdk-rsc/stream-ui) function. Finally, you declare a tool and return a React Server Component, defined in the [`generate`](/docs/reference/ai-sdk-rsc/stream-ui#tools.tool.generate) key of the tool.
133
133
 
134
134
  ```tsx
135
135
  import { streamUI } from '@ai-sdk/rsc';
@@ -45,4 +45,4 @@ const result = await generateText({
45
45
  });
46
46
  ```
47
47
 
48
- For more information about using structured outputs with `generateText` and `streamText` see [Generating Structured Data](/docs/ai-sdk-core/generating-structured-data#structured-outputs-with-generatetext-and-streamtext).
48
+ For more information about using structured outputs with `generateText` and `streamText` see [Generating Structured Data](/docs/ai-sdk-core/generating-structured-data#generating-structured-outputs).
@@ -19,7 +19,7 @@ Errors become part of the stream and are not thrown to prevent e.g. servers from
19
19
 
20
20
  To log errors, you can provide an `onError` callback that is triggered when an error occurs.
21
21
 
22
- ```tsx highlight="6-8"
22
+ ```tsx highlight="7-9"
23
23
  import { streamText } from 'ai';
24
24
  __PROVIDER_IMPORT__;
25
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.27",
3
+ "version": "7.0.29",
4
4
  "type": "module",
5
5
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
6
6
  "license": "Apache-2.0",
@@ -42,7 +42,7 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@ai-sdk/gateway": "4.0.20",
45
+ "@ai-sdk/gateway": "4.0.21",
46
46
  "@ai-sdk/provider": "4.0.3",
47
47
  "@ai-sdk/provider-utils": "5.0.10"
48
48
  },
package/src/ui/chat.ts CHANGED
@@ -650,9 +650,10 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
650
650
  let isAbort = false;
651
651
  let isDisconnect = false;
652
652
  let isError = false;
653
+ let activeResponse: ActiveResponse<UI_MESSAGE> | undefined;
653
654
 
654
655
  try {
655
- const activeResponse = {
656
+ const response = {
656
657
  state: createStreamingUIMessageState({
657
658
  lastMessage: this.state.snapshot(lastMessage),
658
659
  messageId: this.generateId(),
@@ -660,11 +661,13 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
660
661
  abortController: new AbortController(),
661
662
  } as ActiveResponse<UI_MESSAGE>;
662
663
 
663
- activeResponse.abortController.signal.addEventListener('abort', () => {
664
+ activeResponse = response;
665
+
666
+ response.abortController.signal.addEventListener('abort', () => {
664
667
  isAbort = true;
665
668
  });
666
669
 
667
- this.activeResponse = activeResponse;
670
+ this.activeResponse = response;
668
671
 
669
672
  let stream: ReadableStream<UIMessageChunk>;
670
673
 
@@ -674,7 +677,7 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
674
677
  stream = await this.transport.sendMessages({
675
678
  chatId: this.id,
676
679
  messages: this.state.messages,
677
- abortSignal: activeResponse.abortController.signal,
680
+ abortSignal: response.abortController.signal,
678
681
  metadata,
679
682
  headers,
680
683
  body,
@@ -692,21 +695,21 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
692
695
  // serialize the job execution to avoid race conditions:
693
696
  this.jobExecutor.run(() =>
694
697
  job({
695
- state: activeResponse.state,
698
+ state: response.state,
696
699
  write: () => {
697
700
  // streaming is set on first write (before it should be "submitted")
698
701
  this.setStatus({ status: 'streaming' });
699
702
 
700
703
  const replaceLastMessage =
701
- activeResponse.state.message.id === this.lastMessage?.id;
704
+ response.state.message.id === this.lastMessage?.id;
702
705
 
703
706
  if (replaceLastMessage) {
704
707
  this.state.replaceMessage(
705
708
  this.state.messages.length - 1,
706
- activeResponse.state.message,
709
+ response.state.message,
707
710
  );
708
711
  } else {
709
- this.state.pushMessage(activeResponse.state.message);
712
+ this.state.pushMessage(response.state.message);
710
713
  }
711
714
  },
712
715
  }),
@@ -756,19 +759,23 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
756
759
  this.setStatus({ status: 'error', error: err as Error });
757
760
  } finally {
758
761
  try {
759
- this.onFinish?.({
760
- message: this.activeResponse!.state.message,
761
- messages: this.state.messages,
762
- isAbort,
763
- isDisconnect,
764
- isError,
765
- finishReason: this.activeResponse?.state.finishReason,
766
- });
762
+ if (activeResponse) {
763
+ this.onFinish?.({
764
+ message: activeResponse.state.message,
765
+ messages: this.state.messages,
766
+ isAbort,
767
+ isDisconnect,
768
+ isError,
769
+ finishReason: activeResponse.state.finishReason,
770
+ });
771
+ }
767
772
  } catch (err) {
768
773
  console.error(err);
769
774
  }
770
775
 
771
- this.activeResponse = undefined;
776
+ if (this.activeResponse === activeResponse) {
777
+ this.activeResponse = undefined;
778
+ }
772
779
  }
773
780
 
774
781
  // automatically send the message if the sendAutomaticallyWhen function returns true