ai 7.0.116 → 7.0.117

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.117
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [b67b1b7]
8
+ - @ai-sdk/gateway@4.0.95
9
+
3
10
  ## 7.0.116
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1328,7 +1328,7 @@ import {
1328
1328
  } from "@ai-sdk/provider-utils";
1329
1329
 
1330
1330
  // src/version.ts
1331
- var VERSION = true ? "7.0.116" : "0.0.0-test";
1331
+ var VERSION = true ? "7.0.117" : "0.0.0-test";
1332
1332
 
1333
1333
  // src/util/download/download.ts
1334
1334
  var download = async ({
@@ -90,7 +90,7 @@ import {
90
90
  } from "@ai-sdk/provider-utils";
91
91
 
92
92
  // src/version.ts
93
- var VERSION = true ? "7.0.116" : "0.0.0-test";
93
+ var VERSION = true ? "7.0.117" : "0.0.0-test";
94
94
 
95
95
  // src/util/download/download.ts
96
96
  var download = async ({
@@ -140,8 +140,8 @@ Context](/docs/ai-sdk-core/runtime-and-tool-context).
140
140
  ### Tools That Use Experimental Sandboxes
141
141
 
142
142
  Pass `experimental_sandbox` when an agent tool needs a command or code execution
143
- environment. The experimental sandbox is a per-call value, so provide it to `generate()`,
144
- `stream()`, or the agent UI stream helper that invokes the agent.
143
+ environment. The experimental sandbox is a per-call value, so provide it to
144
+ `generate()`, `stream()`, or the agent UI stream helper that invokes the agent.
145
145
 
146
146
  ```ts highlight="13,19-23,31"
147
147
  const agent = new ToolLoopAgent({
@@ -242,7 +242,7 @@ export default function Chat() {
242
242
  }
243
243
  ```
244
244
 
245
- `experimental_MCPAppRenderer` renders nothing for ordinary tools. For app-backed tools, it loads the resource, creates the sandbox bridge, sends tool input and result notifications to the iframe, and forwards supported app requests through your handlers.
245
+ For ordinary tools, `experimental_MCPAppRenderer` renders the provided `fallback` (or nothing when no fallback is provided). For app-backed tools, it loads the resource, creates the sandbox bridge, sends tool input and result notifications to the iframe, and forwards supported app requests through your handlers.
246
246
 
247
247
  ## Best Practices
248
248
 
@@ -77,9 +77,9 @@ This design lets you use the portable `reasoning` parameter by default and fall
77
77
 
78
78
  ## Provider Support
79
79
 
80
- The `reasoning` parameter is supported by the following providers: OpenAI, Anthropic, Google, xAI, Groq, DeepSeek, Fireworks, and Amazon Bedrock. Each provider translates the value to its native reasoning API. Some providers support all six levels natively, while others coerce to fewer levels (a warning is emitted when coercion occurs). Some providers use a numeric token budget instead of an enum for reasoning control; in those cases the top-level `reasoning` value is mapped to a budget calculated as a percentage of the model's maximum output tokens.
80
+ The `reasoning` parameter is supported by the following providers: OpenAI, Anthropic, Google, xAI, Groq, DeepSeek, Fireworks, Amazon Bedrock, and Perplexity. Each provider translates the value to its native reasoning API. Some providers support all six levels natively, while others coerce to fewer levels (a warning is emitted when coercion occurs). Some providers use a numeric token budget instead of an enum for reasoning control; in those cases the top-level `reasoning` value is mapped to a budget calculated as a percentage of the model's maximum output tokens.
81
81
 
82
- Providers that do not support reasoning (e.g. Mistral, Perplexity, Cohere) emit an `unsupported` warning and ignore the parameter.
82
+ Providers that do not support reasoning (e.g. Mistral and Cohere) emit an `unsupported` warning and ignore the parameter.
83
83
 
84
84
  ## Migrating from `providerOptions`
85
85
 
@@ -132,7 +132,7 @@ with `AI_GATEWAY_API_KEY` or Vercel OIDC, then pass a Gateway model ID:
132
132
  import { experimental_evaluate } from 'ai';
133
133
 
134
134
  const result = await experimental_evaluate({
135
- model: 'typesafe-ai/jev-latest',
135
+ model: 'typesafe-ai/jev',
136
136
  state: 'I was charged twice. Please refund the extra charge.',
137
137
  questions: {
138
138
  refund: {
@@ -246,8 +246,8 @@ if (result.answers.requestsRefund.probability >= 0.8) {
246
246
  The model's `supportedQuestionTypes` are checked before calling the provider.
247
247
  Any unsupported question fails the entire call with
248
248
  `Experimental_EvaluationUnsupportedQuestionTypeError`. Successful calls return
249
- an answer for every question; there is no partial success or automatic model
250
- substitution.
249
+ an answer for every question; there is no partial success, and Core does not
250
+ substitute models automatically.
251
251
 
252
252
  Invalid inputs throw `InvalidArgumentError`. Missing answers, mismatched answer
253
253
  types, invalid options, scores, or probabilities throw `InvalidResponseDataError`.
@@ -266,7 +266,10 @@ For tests, use `Experimental_EvaluationMockModelV4` from `ai/test`.
266
266
  Evaluation currently returns one complete result for one shared state. It does
267
267
  not stream answers, perform multilabel classification, or batch unrelated
268
268
  states. Run separate calls for separate states. Provider support and judgment
269
- quality depend on the chosen model; the SDK does not choose a model automatically.
269
+ quality depend on the chosen model. Core does not choose another model, but a
270
+ provider can implement routing through its provider options. For example, AI
271
+ Gateway supports conditional evaluation fallbacks under
272
+ `providerOptions.gateway.models`.
270
273
 
271
274
  Runnable examples are in
272
275
  [`examples/ai-functions/src/evaluate`](https://github.com/vercel/ai/tree/main/examples/ai-functions/src/evaluate),
@@ -301,8 +301,10 @@ This distinction matters when the step includes local tool execution: the step d
301
301
 
302
302
  ## Runtime and Tool Context
303
303
 
304
- Lifecycle callbacks receive the full `runtimeContext` and `toolsContext` values that flow through the call.
305
- This makes callbacks useful for attaching application context without changing prompts or tool inputs.
304
+ Generation and step lifecycle callbacks receive the full `runtimeContext` and
305
+ `toolsContext` values that flow through the call. Tool-execution callbacks receive
306
+ the scoped `toolContext` for the tool being executed. This makes callbacks useful
307
+ for attaching application context without changing prompts or tool inputs.
306
308
 
307
309
  ```tsx highlight="8-24,26-39"
308
310
  import { generateText, tool } from 'ai';
@@ -349,8 +351,9 @@ const result = await generateText({
349
351
 
350
352
  <Note>
351
353
  Telemetry integrations can filter `runtimeContext` and `toolsContext` before
352
- exporting them. Lifecycle callbacks receive the full context objects. Be
353
- careful not to log secrets or sensitive user data from callbacks.
354
+ exporting them. Generation and step callbacks receive the full context
355
+ objects; tool-execution callbacks receive scoped tool context. Be careful not
356
+ to log secrets or sensitive user data from callbacks.
354
357
  </Note>
355
358
 
356
359
  ## Available Callbacks
@@ -9,8 +9,9 @@ The AI SDK harness abstraction lets you run established agent harnesses through
9
9
  single AI SDK surface. A harness is a complete agent runtime, such as Claude
10
10
  Code, Codex, or Pi. It owns capabilities that are larger than a model call:
11
11
  workspace access, built-in coding tools, native session state, compaction,
12
- permission flows, and runtime-specific configuration. Additionally, all AI SDK
13
- agent harnesses operate in a sandbox, keeping the host environment safe.
12
+ permission flows, and runtime-specific configuration. Harness adapters can run
13
+ the runtime in a sandbox, but their execution environments differ by adapter;
14
+ review the adapter's runtime location and security guidance before use.
14
15
 
15
16
  The AI SDK harness abstraction is separate from the provider/model abstraction.
16
17
  Providers expose models to AI SDK Core functions such as `generateText` and
@@ -38,10 +38,10 @@ The AI SDK includes the following harness adapters:
38
38
  | [Claude Code](/providers/ai-sdk-harnesses/claude-code) | Sandbox bridge | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
39
39
  | [Cline](/providers/ai-sdk-harnesses/cline) | Host process | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
40
40
  | [Codex](/providers/ai-sdk-harnesses/codex) | Sandbox bridge | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> |
41
- | [Cursor](/providers/ai-sdk-harnesses/cursor) | Sandbox via ACP | <Check /> | <Check /> | <Cross /> | <Check /> | <Cross /> |
41
+ | [Cursor](/providers/ai-sdk-harnesses/cursor) | Sandbox via ACP | <Check /> | <Check /> | <Cross /> | <Cross /> | <Cross /> |
42
42
  | [Deep Agents](/providers/ai-sdk-harnesses/deepagents) | Sandbox bridge | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> via auto-rejection |
43
43
  | [fx](/providers/ai-sdk-harnesses/fx) | Sandbox via ACP | <Check /> | <Check /> | <Cross /> | <Check /> | <Cross /> |
44
- | [GitHub Copilot](/providers/ai-sdk-harnesses/github-copilot) | Sandbox via ACP | <Check /> | <Check /> | <Cross /> | <Check /> | <Cross /> |
45
- | [Grok Build](/providers/ai-sdk-harnesses/grok-build) | Sandbox via ACP | <Check /> | <Check /> | <Check /> | <Check /> | <Cross /> |
44
+ | [GitHub Copilot](/providers/ai-sdk-harnesses/github-copilot) | Sandbox via ACP | <Check /> | <Check /> | <Cross /> | <Cross /> | <Cross /> |
45
+ | [Grok Build](/providers/ai-sdk-harnesses/grok-build) | Sandbox via ACP | <Check /> | <Check /> | <Check /> | <Cross /> | <Cross /> |
46
46
  | [OpenCode](/providers/ai-sdk-harnesses/opencode) | Sandbox bridge | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> via auto-rejection |
47
47
  | [Pi](/providers/ai-sdk-harnesses/pi) | Host process | <Check /> | <Check /> | <Cross /> | <Check /> | <Check /> |
@@ -9,7 +9,7 @@ AI SDK UI is designed to help you build interactive chat, completion, and assist
9
9
 
10
10
  AI SDK UI provides robust abstractions that simplify the complex tasks of managing chat streams and UI updates on the frontend, enabling you to develop dynamic AI-driven interfaces more efficiently. With three main hooks — **`useChat`**, **`useCompletion`**, and **`useObject`** — you can incorporate real-time chat capabilities, text completions, streamed JSON, and interactive assistant features into your app.
11
11
 
12
- - **[`useChat`](/docs/ai-sdk-ui/chatbot)** offers real-time streaming of chat messages, abstracting state management for inputs, messages, loading, and errors, allowing for seamless integration into any UI design.
12
+ - **[`useChat`](/docs/ai-sdk-ui/chatbot)** offers real-time streaming of chat messages and manages message, loading, and error state. Manage input state in your component for seamless integration into any UI design.
13
13
  - **[`useCompletion`](/docs/ai-sdk-ui/completion)** enables you to handle text completions in your applications, managing the prompt input and automatically updating the UI as new completions are streamed.
14
14
  - **[`useObject`](/docs/ai-sdk-ui/object-generation)** is a hook that allows you to consume streamed JSON objects, providing a simple way to handle and display structured data in your application.
15
15
 
@@ -1009,10 +1009,12 @@ These are available as `reasoning-file` parts (`ReasoningFileUIPart`) with
1009
1009
  Some providers such as [Perplexity](/providers/ai-sdk-providers/perplexity#sources) and
1010
1010
  [Google](/providers/ai-sdk-providers/google#sources) include sources in the response.
1011
1011
 
1012
- Currently sources are limited to web pages that ground the response.
1013
- You can forward them to the client with the `sendSources` option:
1012
+ You can forward sources to the client with the `sendSources` option. This example uses the Perplexity Agent API's `fast` preset to search the web. Install `@ai-sdk/perplexity` and set `PERPLEXITY_API_KEY` in your environment:
1014
1013
 
1015
- ```ts filename="app/api/chat/route.ts" highlight="20"
1014
+ <InstallPackages packages="@ai-sdk/perplexity" />
1015
+
1016
+ ```ts filename="app/api/chat/route.ts" highlight="21"
1017
+ import { perplexity } from '@ai-sdk/perplexity';
1016
1018
  import {
1017
1019
  convertToModelMessages,
1018
1020
  createUIMessageStreamResponse,
@@ -1025,7 +1027,7 @@ export async function POST(req: Request) {
1025
1027
  const { messages }: { messages: UIMessage[] } = await req.json();
1026
1028
 
1027
1029
  const result = streamText({
1028
- model: 'perplexity/sonar-pro',
1030
+ model: perplexity('fast'),
1029
1031
  messages: await convertToModelMessages(messages),
1030
1032
  });
1031
1033
 
@@ -1051,7 +1053,7 @@ messages.map(message => (
1051
1053
  {message.parts
1052
1054
  .filter(part => part.type === 'source-url')
1053
1055
  .map(part => (
1054
- <span key={`source-${part.id}`}>
1056
+ <span key={`source-${part.sourceId}`}>
1055
1057
  [
1056
1058
  <a href={part.url} target="_blank">
1057
1059
  {part.title ?? new URL(part.url).hostname}
@@ -1064,8 +1066,8 @@ messages.map(message => (
1064
1066
  {message.parts
1065
1067
  .filter(part => part.type === 'source-document')
1066
1068
  .map(part => (
1067
- <span key={`source-${part.id}`}>
1068
- [<span>{part.title ?? `Document ${part.id}`}</span>]
1069
+ <span key={`source-${part.sourceId}`}>
1070
+ [<span>{part.title ?? `Document ${part.sourceId}`}</span>]
1069
1071
  </span>
1070
1072
  ))}
1071
1073
  </div>
@@ -5,7 +5,10 @@ description: Learn how to use the useObject hook.
5
5
 
6
6
  # Object Generation
7
7
 
8
- <Note>`useObject` is only available in React, Svelte, and Vue.</Note>
8
+ <Note>
9
+ `useObject` is available in React, Svelte, Vue, and the SolidJS community
10
+ integration. Angular provides the equivalent `StructuredObject` service.
11
+ </Note>
9
12
 
10
13
  The [`useObject`](/docs/reference/ai-sdk-ui/use-object) hook allows you to create interfaces that represent a structured JSON object that is being streamed.
11
14
 
@@ -30,6 +30,7 @@ const redis = new Redis({
30
30
  });
31
31
 
32
32
  export const cacheMiddleware: LanguageModelV4Middleware = {
33
+ specificationVersion: 'v4',
33
34
  wrapGenerate: async ({ doGenerate, params }) => {
34
35
  const cacheKey = JSON.stringify(params);
35
36
 
@@ -117,7 +118,7 @@ export const cacheMiddleware: LanguageModelV4Middleware = {
117
118
  replayed from the cache on later requests.
118
119
  </Note>
119
120
 
120
- `LanguageModelV4Middleware` has two methods: `wrapGenerate` and `wrapStream`. `wrapGenerate` is called when using [`generateText`](/docs/reference/ai-sdk-core/generate-text), while `wrapStream` is called when using [`streamText`](/docs/reference/ai-sdk-core/stream-text).
121
+ `LanguageModelV4Middleware` has the `wrapGenerate` and `wrapStream` wrapping methods, plus the optional `transformParams` method. `wrapGenerate` is called when using [`generateText`](/docs/reference/ai-sdk-core/generate-text), while `wrapStream` is called when using [`streamText`](/docs/reference/ai-sdk-core/stream-text).
121
122
 
122
123
  For `wrapGenerate`, you can cache the response directly. Instead, for `wrapStream`, you cache an array of the stream parts, which can then be used with [`simulateReadableStream`](/docs/ai-sdk-core/testing#simulate-ui-message-stream-responses) function to create a simulated `ReadableStream` that returns the cached response. In this way, the cached response is returned chunk-by-chunk as if it were being generated by the model. You can control the initial delay and delay between chunks by adjusting the `initialDelayInMs` and `chunkDelayInMs` parameters of `simulateReadableStream`.
123
124
 
@@ -1071,7 +1071,7 @@ To see `generateText` in action, check out [these examples](#examples).
1071
1071
  name: 'Output.json()',
1072
1072
  type: 'Output',
1073
1073
  description:
1074
- 'Output specification for unstructured JSON generation. When the model generates a text response, it will return a JSON object.',
1074
+ 'Output specification for unstructured JSON generation. When the model generates a text response, it will return any valid JSON value.',
1075
1075
  properties: [
1076
1076
  {
1077
1077
  type: 'Options',
@@ -5,7 +5,10 @@ description: API reference for the useObject hook.
5
5
 
6
6
  # `useObject()`
7
7
 
8
- <Note>`useObject` is only available in React, Svelte, and Vue.</Note>
8
+ <Note>
9
+ `useObject` is available in React, Svelte, Vue, and the SolidJS community
10
+ integration. Angular provides the equivalent `StructuredObject` service.
11
+ </Note>
9
12
 
10
13
  Allows you to consume text streams that represent a JSON object and parse them into a complete object based on a schema.
11
14
  You can use it together with [`streamText`](/docs/reference/ai-sdk-core/stream-text) and [`Output.object()`](/docs/reference/ai-sdk-core/output#output-object) in the backend.
@@ -36,6 +36,7 @@ To see `streamUI` in action, check out [these examples](#examples).
36
36
  },
37
37
  {
38
38
  name: 'instructions',
39
+ isOptional: true,
39
40
  type: 'Instructions',
40
41
  description:
41
42
  'Instructions to use that specify the behavior of the model.'
@@ -40,7 +40,7 @@ Creates a client-server context provider that can be used to wrap parts of your
40
40
  },
41
41
  {
42
42
  name: 'onGetUIState',
43
- type: '() => UIState',
43
+ type: '() => Promise<UIState | undefined>',
44
44
  description: 'is called during SSR to compare and update UI state.',
45
45
  },
46
46
  {
@@ -72,7 +72,7 @@ Create a stream that sends UI from the server to the client. On the client side,
72
72
  },
73
73
  {
74
74
  name: 'error',
75
- type: '(Error) => void',
75
+ type: '(any) => StreamableUIWrapper',
76
76
  description:
77
77
  'Signals that there is an error in the UI stream. It will be thrown on the client side and caught by the nearest error boundary component.',
78
78
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.116",
3
+ "version": "7.0.117",
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,18 +42,18 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@ai-sdk/gateway": "4.0.94",
45
+ "@ai-sdk/gateway": "4.0.95",
46
46
  "@ai-sdk/provider": "4.0.18",
47
47
  "@ai-sdk/provider-utils": "5.0.49"
48
48
  },
49
49
  "devDependencies": {
50
- "@ai-sdk/amazon-bedrock": "5.0.96",
50
+ "@ai-sdk/amazon-bedrock": "5.0.97",
51
51
  "@ai-sdk/deepseek": "3.0.54",
52
52
  "@ai-sdk/google": "4.0.82",
53
53
  "@ai-sdk/groq": "4.0.50",
54
54
  "@ai-sdk/huggingface": "2.0.57",
55
55
  "@ai-sdk/moonshotai": "3.0.58",
56
- "@ai-sdk/openai": "4.0.77",
56
+ "@ai-sdk/openai": "4.0.78",
57
57
  "@ai-sdk/test-server": "2.0.2",
58
58
  "@ai-sdk/xai": "5.0.10",
59
59
  "@edge-runtime/vm": "^5.0.0",