ai 6.0.213 → 6.0.215
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 +16 -0
- package/dist/index.js +26 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -11
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +46 -0
- package/docs/03-ai-sdk-core/35-image-generation.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +42 -0
- package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +1 -1
- package/package.json +3 -3
- package/src/generate-text/prune-messages.ts +45 -16
package/dist/internal/index.js
CHANGED
|
@@ -152,7 +152,7 @@ function detectMediaType({
|
|
|
152
152
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
153
153
|
|
|
154
154
|
// src/version.ts
|
|
155
|
-
var VERSION = true ? "6.0.
|
|
155
|
+
var VERSION = true ? "6.0.215" : "0.0.0-test";
|
|
156
156
|
|
|
157
157
|
// src/util/download/download.ts
|
|
158
158
|
var download = async ({
|
package/dist/internal/index.mjs
CHANGED
|
@@ -313,6 +313,52 @@ Resource templates are dynamic URI patterns that allow flexible queries. List al
|
|
|
313
313
|
const templates = await mcpClient.listResourceTemplates();
|
|
314
314
|
```
|
|
315
315
|
|
|
316
|
+
## Using MCP Completions
|
|
317
|
+
|
|
318
|
+
MCP servers can provide autocompletion suggestions for prompt arguments and
|
|
319
|
+
resource template variables when they advertise the `completions` capability.
|
|
320
|
+
Use `complete` to ask the server for suggestions based on the current partial
|
|
321
|
+
argument value:
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
const completion = await mcpClient.complete({
|
|
325
|
+
ref: {
|
|
326
|
+
type: 'ref/resource',
|
|
327
|
+
uri: 'file:///{path}',
|
|
328
|
+
},
|
|
329
|
+
argument: {
|
|
330
|
+
name: 'path',
|
|
331
|
+
value: 'doc',
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
console.log(completion.completion.values);
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
For resource templates or prompts with multiple arguments, pass already resolved
|
|
339
|
+
values through `context.arguments`:
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
const completion = await mcpClient.complete({
|
|
343
|
+
ref: {
|
|
344
|
+
type: 'ref/resource',
|
|
345
|
+
uri: 'kubernetes://namespaced/{plural}/{namespace}',
|
|
346
|
+
},
|
|
347
|
+
argument: {
|
|
348
|
+
name: 'namespace',
|
|
349
|
+
value: 'auth',
|
|
350
|
+
},
|
|
351
|
+
context: {
|
|
352
|
+
arguments: {
|
|
353
|
+
plural: 'deployments',
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
If the connected server does not advertise `capabilities.completions`, the
|
|
360
|
+
client throws an `MCPClientError`.
|
|
361
|
+
|
|
316
362
|
## Using MCP Prompts
|
|
317
363
|
|
|
318
364
|
<Note type="warning">
|
|
@@ -291,7 +291,7 @@ for (const file of result.files) {
|
|
|
291
291
|
| Provider | Model | Support sizes (`width x height`) or aspect ratios (`width : height`) |
|
|
292
292
|
| ------------------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
293
293
|
| [xAI Grok](/providers/ai-sdk-providers/xai#image-models) | `grok-imagine-image` | `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3`, `2:1`, `1:2`, `19.5:9`, `9:19.5`, `20:9`, `9:20`, `auto` |
|
|
294
|
-
| [OpenAI](/providers/ai-sdk-providers/openai#image-models) | `gpt-image-
|
|
294
|
+
| [OpenAI](/providers/ai-sdk-providers/openai#image-models) | `gpt-image-2` | 1024x1024, 1536x1024, 1024x1536 |
|
|
295
295
|
| [OpenAI](/providers/ai-sdk-providers/openai#image-models) | `dall-e-3` | 1024x1024, 1792x1024, 1024x1792 |
|
|
296
296
|
| [OpenAI](/providers/ai-sdk-providers/openai#image-models) | `dall-e-2` | 256x256, 512x512, 1024x1024 |
|
|
297
297
|
| [Amazon Bedrock](/providers/ai-sdk-providers/amazon-bedrock#image-models) | `amazon.nova-canvas-v1:0` | 320-4096 (multiples of 16), 1:4 to 4:1, max 4.2M pixels |
|
|
@@ -10,6 +10,7 @@ Creates a lightweight Model Context Protocol (MCP) client that connects to an MC
|
|
|
10
10
|
- **Tools**: Automatic conversion between MCP tools and AI SDK tools
|
|
11
11
|
- **Resources**: Methods to list, read, and discover resource templates from MCP servers
|
|
12
12
|
- **Prompts**: Methods to list available prompts and retrieve prompt messages
|
|
13
|
+
- **Completions**: Methods to request autocompletion suggestions for prompt arguments and resource template variables
|
|
13
14
|
- **Elicitation**: Support for handling server requests for additional input during tool execution
|
|
14
15
|
|
|
15
16
|
It currently does not support accepting notifications from an MCP server, and custom configuration of the client.
|
|
@@ -294,6 +295,47 @@ Returns a Promise that resolves to an `MCPClient` with the following properties
|
|
|
294
295
|
},
|
|
295
296
|
],
|
|
296
297
|
},
|
|
298
|
+
{
|
|
299
|
+
name: 'complete',
|
|
300
|
+
type: `async (args: CompleteRequestParams & {
|
|
301
|
+
options?: RequestOptions;
|
|
302
|
+
}) => Promise<CompleteResult>`,
|
|
303
|
+
description:
|
|
304
|
+
'Requests autocompletion suggestions for a prompt argument or resource template variable. The server must advertise the completions capability.',
|
|
305
|
+
properties: [
|
|
306
|
+
{
|
|
307
|
+
type: 'args',
|
|
308
|
+
parameters: [
|
|
309
|
+
{
|
|
310
|
+
name: 'ref',
|
|
311
|
+
type: "{ type: 'ref/prompt'; name: string } | { type: 'ref/resource'; uri: string }",
|
|
312
|
+
description:
|
|
313
|
+
'Reference to the prompt or resource template being completed.',
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
name: 'argument',
|
|
317
|
+
type: '{ name: string; value: string }',
|
|
318
|
+
description:
|
|
319
|
+
'Argument name and current partial value to complete.',
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: 'context',
|
|
323
|
+
type: '{ arguments: Record<string, string> }',
|
|
324
|
+
isOptional: true,
|
|
325
|
+
description:
|
|
326
|
+
'Previously resolved argument values used to provide context for multi-argument prompts or resource templates.',
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
name: 'options',
|
|
330
|
+
type: 'RequestOptions',
|
|
331
|
+
isOptional: true,
|
|
332
|
+
description:
|
|
333
|
+
'Optional request options including signal and timeout.',
|
|
334
|
+
},
|
|
335
|
+
],
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
},
|
|
297
339
|
{
|
|
298
340
|
name: 'experimental_listPrompts',
|
|
299
341
|
type: `async (options?: {
|
|
@@ -13,7 +13,7 @@ import { generateImage, wrapImageModel } from 'ai';
|
|
|
13
13
|
import { openai } from '@ai-sdk/openai';
|
|
14
14
|
|
|
15
15
|
const model = wrapImageModel({
|
|
16
|
-
model: openai.image('gpt-image-
|
|
16
|
+
model: openai.image('gpt-image-2'),
|
|
17
17
|
middleware: yourImageModelMiddleware,
|
|
18
18
|
});
|
|
19
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.215",
|
|
4
4
|
"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.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@opentelemetry/api": "^1.9.0",
|
|
48
|
-
"@ai-sdk/gateway": "3.0.
|
|
48
|
+
"@ai-sdk/gateway": "3.0.139",
|
|
49
49
|
"@ai-sdk/provider": "3.0.12",
|
|
50
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
50
|
+
"@ai-sdk/provider-utils": "4.0.33"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@edge-runtime/vm": "^5.0.0",
|
|
@@ -100,6 +100,44 @@ export function pruneMessages({
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
// Build global maps from tool call id and approval id to tool name.
|
|
104
|
+
// These must be global (not per-message) because a `tool-approval-response`
|
|
105
|
+
// lives in a separate `tool` message from its `tool-approval-request`
|
|
106
|
+
// (assistant message), so the tool name of a response can only be resolved
|
|
107
|
+
// by looking across messages. Resolving names per-message left responses
|
|
108
|
+
// unresolved, which caused them to be kept while their request was pruned,
|
|
109
|
+
// producing orphaned approval responses.
|
|
110
|
+
const toolCallIdToToolName = new Map<string, string>();
|
|
111
|
+
for (const message of messages) {
|
|
112
|
+
if (
|
|
113
|
+
(message.role === 'assistant' || message.role === 'tool') &&
|
|
114
|
+
typeof message.content !== 'string'
|
|
115
|
+
) {
|
|
116
|
+
for (const part of message.content) {
|
|
117
|
+
if (part.type === 'tool-call' || part.type === 'tool-result') {
|
|
118
|
+
toolCallIdToToolName.set(part.toolCallId, part.toolName);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const approvalIdToToolName = new Map<string, string>();
|
|
125
|
+
for (const message of messages) {
|
|
126
|
+
if (
|
|
127
|
+
(message.role === 'assistant' || message.role === 'tool') &&
|
|
128
|
+
typeof message.content !== 'string'
|
|
129
|
+
) {
|
|
130
|
+
for (const part of message.content) {
|
|
131
|
+
if (part.type === 'tool-approval-request') {
|
|
132
|
+
const toolName = toolCallIdToToolName.get(part.toolCallId);
|
|
133
|
+
if (toolName != null) {
|
|
134
|
+
approvalIdToToolName.set(part.approvalId, toolName);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
103
141
|
messages = messages.map((message, messageIndex) => {
|
|
104
142
|
if (
|
|
105
143
|
(message.role !== 'assistant' && message.role !== 'tool') ||
|
|
@@ -110,9 +148,6 @@ export function pruneMessages({
|
|
|
110
148
|
return message;
|
|
111
149
|
}
|
|
112
150
|
|
|
113
|
-
const toolCallIdToToolName: Record<string, string> = {};
|
|
114
|
-
const approvalIdToToolName: Record<string, string> = {};
|
|
115
|
-
|
|
116
151
|
return {
|
|
117
152
|
...message,
|
|
118
153
|
content: message.content.filter(part => {
|
|
@@ -126,14 +161,6 @@ export function pruneMessages({
|
|
|
126
161
|
return true;
|
|
127
162
|
}
|
|
128
163
|
|
|
129
|
-
// track tool calls and approvals:
|
|
130
|
-
if (part.type === 'tool-call') {
|
|
131
|
-
toolCallIdToToolName[part.toolCallId] = part.toolName;
|
|
132
|
-
} else if (part.type === 'tool-approval-request') {
|
|
133
|
-
approvalIdToToolName[part.approvalId] =
|
|
134
|
-
toolCallIdToToolName[part.toolCallId];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
164
|
// keep parts that are associated with a tool call or approval that needs to be kept:
|
|
138
165
|
if (
|
|
139
166
|
((part.type === 'tool-call' || part.type === 'tool-result') &&
|
|
@@ -146,13 +173,15 @@ export function pruneMessages({
|
|
|
146
173
|
}
|
|
147
174
|
|
|
148
175
|
// keep parts that are not associated with a tool that should be removed:
|
|
176
|
+
const partToolName =
|
|
177
|
+
part.type === 'tool-call' || part.type === 'tool-result'
|
|
178
|
+
? part.toolName
|
|
179
|
+
: approvalIdToToolName.get(part.approvalId);
|
|
180
|
+
|
|
149
181
|
return (
|
|
150
182
|
toolCall.tools != null &&
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
? part.toolName
|
|
154
|
-
: approvalIdToToolName[part.approvalId],
|
|
155
|
-
)
|
|
183
|
+
partToolName != null &&
|
|
184
|
+
!toolCall.tools.includes(partToolName)
|
|
156
185
|
);
|
|
157
186
|
}),
|
|
158
187
|
} as AssistantModelMessage | ToolModelMessage;
|