ai 7.0.113 → 7.0.116
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 +32 -0
- package/README.md +6 -6
- package/dist/index.js +1010 -1289
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +231 -257
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +3 -0
- package/docs/02-foundations/03-prompts.mdx +1 -1
- package/docs/02-foundations/04-tools.mdx +2 -2
- package/docs/02-foundations/06-provider-options.mdx +11 -11
- package/docs/02-getting-started/00-choosing-a-provider.mdx +4 -4
- package/docs/02-getting-started/02-nextjs-app-router.mdx +3 -3
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +3 -3
- package/docs/02-getting-started/04-svelte.mdx +7 -7
- package/docs/02-getting-started/05-nuxt.mdx +7 -7
- package/docs/02-getting-started/06-nodejs.mdx +3 -3
- package/docs/02-getting-started/07-expo.mdx +3 -3
- package/docs/02-getting-started/08-tanstack-start.mdx +3 -3
- package/docs/02-getting-started/09-coding-agents.mdx +1 -1
- package/docs/03-agents/03-workflows.mdx +2 -2
- package/docs/03-agents/04-loop-control.mdx +1 -1
- package/docs/03-agents/05-configuring-call-options.mdx +4 -2
- package/docs/03-agents/06-memory.mdx +2 -2
- package/docs/03-agents/06-policy-tool-approvals.mdx +2 -2
- package/docs/03-agents/07-workflow-agent.mdx +11 -11
- package/docs/03-agents/08-terminal-ui.mdx +14 -10
- package/docs/03-ai-sdk-core/05-generating-text.mdx +2 -2
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +6 -1
- package/docs/03-ai-sdk-core/17-mcp-apps.mdx +1 -1
- package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +1 -1
- package/docs/03-ai-sdk-core/26-reasoning.mdx +13 -12
- package/docs/03-ai-sdk-core/31-reranking.mdx +12 -10
- package/docs/03-ai-sdk-core/32-evaluation.mdx +1 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -2
- package/docs/03-ai-sdk-core/37-speech.mdx +6 -6
- package/docs/03-ai-sdk-core/39-file-uploads.mdx +1 -1
- package/docs/03-ai-sdk-core/41-skill-uploads.mdx +1 -1
- package/docs/03-ai-sdk-core/42-batch.mdx +1 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +21 -21
- package/docs/03-ai-sdk-core/60-telemetry.mdx +1 -1
- package/docs/03-ai-sdk-core/65-devtools.mdx +3 -3
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +1 -1
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +97 -107
- package/docs/03-ai-sdk-harnesses/03-tools.mdx +1 -22
- package/docs/03-ai-sdk-harnesses/04-skills.mdx +0 -4
- package/docs/03-ai-sdk-harnesses/06-workflow-utilities.mdx +43 -9
- package/docs/03-ai-sdk-harnesses/07-ui.mdx +33 -30
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +8 -6
- package/docs/04-ai-sdk-ui/02-chatbot.mdx +3 -3
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +3 -3
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +1 -1
- package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +5 -5
- package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +1 -1
- package/docs/05-ai-sdk-rsc/06-loading-state.mdx +1 -1
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +3 -3
- package/docs/06-advanced/11-secure-url-fetching.mdx +39 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +5 -3
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +5 -3
- package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +5 -5
- package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +4 -2
- package/docs/07-reference/01-ai-sdk-core/20-start-batch.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +4 -4
- package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +3 -3
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -1
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +8 -8
- package/docs/07-reference/06-ai-sdk-tui/01-run-agent-tui.mdx +13 -9
- package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +3 -3
- package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +2 -2
- package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +1 -1
- package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +2 -2
- package/package.json +12 -12
- package/src/evaluate/evaluate.ts +1 -10
- package/src/generate-text/restricted-telemetry-dispatcher.ts +6 -58
- package/src/prompt/file-part-data.ts +9 -3
- package/src/prompt/standardize-prompt.ts +2 -0
- package/src/telemetry/create-telemetry-dispatcher.ts +58 -6
- package/src/telemetry/filter-included-context.ts +57 -2
- package/src/util/download/download.ts +2 -2
|
@@ -17,7 +17,7 @@ import { tool } from 'ai';
|
|
|
17
17
|
import { z } from 'zod';
|
|
18
18
|
|
|
19
19
|
const agent = new WorkflowAgent({
|
|
20
|
-
model: 'anthropic/claude-sonnet-
|
|
20
|
+
model: 'anthropic/claude-sonnet-5',
|
|
21
21
|
instructions: 'You are a helpful assistant.',
|
|
22
22
|
tools: {
|
|
23
23
|
weather: tool({
|
|
@@ -71,7 +71,7 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
71
71
|
type: 'LanguageModel',
|
|
72
72
|
isRequired: true,
|
|
73
73
|
description:
|
|
74
|
-
"The language model to use. A string compatible with the Vercel AI Gateway (e.g., 'anthropic/claude-sonnet-
|
|
74
|
+
"The language model to use. A string compatible with the Vercel AI Gateway (e.g., 'anthropic/claude-sonnet-5') or a provider instance (e.g., `openai('gpt-6-astra')`).",
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
77
|
name: 'instructions',
|
|
@@ -808,7 +808,7 @@ Infers the UI message type for a `WorkflowAgent` instance. Optionally accepts a
|
|
|
808
808
|
import { WorkflowAgent, InferWorkflowAgentUIMessage } from '@ai-sdk/workflow';
|
|
809
809
|
|
|
810
810
|
const agent = new WorkflowAgent({
|
|
811
|
-
model: 'anthropic/claude-sonnet-
|
|
811
|
+
model: 'anthropic/claude-sonnet-5',
|
|
812
812
|
tools: { weather: weatherTool },
|
|
813
813
|
});
|
|
814
814
|
|
|
@@ -835,7 +835,7 @@ import { tool } from 'ai';
|
|
|
835
835
|
import { z } from 'zod';
|
|
836
836
|
|
|
837
837
|
const agent = new WorkflowAgent({
|
|
838
|
-
model: 'anthropic/claude-sonnet-
|
|
838
|
+
model: 'anthropic/claude-sonnet-5',
|
|
839
839
|
instructions: 'You are a helpful assistant.',
|
|
840
840
|
tools: {
|
|
841
841
|
weather: tool({
|
|
@@ -890,7 +890,7 @@ export async function chat(messages: UIMessage[]) {
|
|
|
890
890
|
const modelMessages = await convertToModelMessages(messages);
|
|
891
891
|
|
|
892
892
|
const agent = new WorkflowAgent({
|
|
893
|
-
model: 'anthropic/claude-sonnet-
|
|
893
|
+
model: 'anthropic/claude-sonnet-5',
|
|
894
894
|
instructions: 'You are a flight booking assistant.',
|
|
895
895
|
tools: {
|
|
896
896
|
searchFlights: tool({
|
|
@@ -937,7 +937,7 @@ import { WorkflowAgent, Output } from '@ai-sdk/workflow';
|
|
|
937
937
|
import { z } from 'zod';
|
|
938
938
|
|
|
939
939
|
const analysisAgent = new WorkflowAgent({
|
|
940
|
-
model: 'anthropic/claude-sonnet-
|
|
940
|
+
model: 'anthropic/claude-sonnet-5',
|
|
941
941
|
});
|
|
942
942
|
|
|
943
943
|
const result = await analysisAgent.stream({
|
|
@@ -977,7 +977,7 @@ import { tool } from 'ai';
|
|
|
977
977
|
import { z } from 'zod';
|
|
978
978
|
|
|
979
979
|
const agent = new WorkflowAgent({
|
|
980
|
-
model: 'anthropic/claude-sonnet-
|
|
980
|
+
model: 'anthropic/claude-sonnet-5',
|
|
981
981
|
experimental_toolApprovalSecret: {
|
|
982
982
|
environmentVariable: 'TOOL_APPROVAL_SECRET',
|
|
983
983
|
},
|
|
@@ -1009,7 +1009,7 @@ serialize it. A stream-level reference overrides the constructor value.
|
|
|
1009
1009
|
import { WorkflowAgent } from '@ai-sdk/workflow';
|
|
1010
1010
|
|
|
1011
1011
|
const agent = new WorkflowAgent({
|
|
1012
|
-
model: 'anthropic/claude-sonnet-
|
|
1012
|
+
model: 'anthropic/claude-sonnet-5',
|
|
1013
1013
|
tools: { weather: weatherTool },
|
|
1014
1014
|
|
|
1015
1015
|
// Agent-wide callbacks
|
|
@@ -17,7 +17,7 @@ import { runAgentTUI } from '@ai-sdk/tui';
|
|
|
17
17
|
import { ToolLoopAgent } from 'ai';
|
|
18
18
|
|
|
19
19
|
const agent = new ToolLoopAgent({
|
|
20
|
-
model: openai('gpt-
|
|
20
|
+
model: openai('gpt-6-astra'),
|
|
21
21
|
instructions: 'You are a helpful terminal assistant.',
|
|
22
22
|
});
|
|
23
23
|
|
|
@@ -191,17 +191,21 @@ await runAgentTUI({
|
|
|
191
191
|
## Example with Sandbox
|
|
192
192
|
|
|
193
193
|
```ts
|
|
194
|
-
import {
|
|
194
|
+
import { createJustBashNetworkSandboxSession } from '@ai-sdk/sandbox-just-bash';
|
|
195
195
|
|
|
196
|
-
const sandboxSession = await
|
|
196
|
+
const sandboxSession = await createJustBashNetworkSandboxSession({
|
|
197
197
|
cwd: '/home/user',
|
|
198
|
-
}).createSession();
|
|
199
|
-
|
|
200
|
-
await runAgentTUI({
|
|
201
|
-
title: 'Sandbox Assistant',
|
|
202
|
-
agent,
|
|
203
|
-
sandbox: sandboxSession.restricted(),
|
|
204
198
|
});
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
await runAgentTUI({
|
|
202
|
+
title: 'Sandbox Assistant',
|
|
203
|
+
agent,
|
|
204
|
+
sandbox: sandboxSession.restricted(),
|
|
205
|
+
});
|
|
206
|
+
} finally {
|
|
207
|
+
await sandboxSession.destroy();
|
|
208
|
+
}
|
|
205
209
|
```
|
|
206
210
|
|
|
207
211
|
The sandbox is forwarded to every `agent.stream()` call as
|
|
@@ -73,7 +73,7 @@ const { messages, sendMessage } = useChat({
|
|
|
73
73
|
'X-App-ID': 'my-app', // Static app identifier
|
|
74
74
|
},
|
|
75
75
|
body: {
|
|
76
|
-
model: 'gpt-
|
|
76
|
+
model: 'gpt-6-astra', // Default model
|
|
77
77
|
stream: true, // Static configuration
|
|
78
78
|
},
|
|
79
79
|
credentials: 'include', // Static credentials policy
|
|
@@ -125,7 +125,7 @@ const { messages, sendMessage } = useChat({
|
|
|
125
125
|
'X-API-Version': 'v1',
|
|
126
126
|
},
|
|
127
127
|
body: {
|
|
128
|
-
model: 'gpt-
|
|
128
|
+
model: 'gpt-6-astra',
|
|
129
129
|
},
|
|
130
130
|
}),
|
|
131
131
|
});
|
|
@@ -139,7 +139,7 @@ sendMessage(
|
|
|
139
139
|
'X-Request-ID': '123', // This is added
|
|
140
140
|
},
|
|
141
141
|
body: {
|
|
142
|
-
model: 'gpt-
|
|
142
|
+
model: 'gpt-4.1-mini', // Supports the temperature setting below
|
|
143
143
|
temperature: 0.5, // This is added
|
|
144
144
|
},
|
|
145
145
|
},
|
|
@@ -15,7 +15,7 @@ export async function POST(req: Request) {
|
|
|
15
15
|
const { messages } = await req.json();
|
|
16
16
|
|
|
17
17
|
const result = streamText({
|
|
18
|
-
model: 'openai/gpt-
|
|
18
|
+
model: 'openai/gpt-6-luna',
|
|
19
19
|
messages: await convertToModelMessages(messages),
|
|
20
20
|
tools: {
|
|
21
21
|
weather: {
|
|
@@ -49,7 +49,7 @@ export async function POST(req: Request) {
|
|
|
49
49
|
const { messages } = await req.json();
|
|
50
50
|
|
|
51
51
|
const result = streamText({
|
|
52
|
-
model: 'openai/gpt-
|
|
52
|
+
model: 'openai/gpt-6-luna',
|
|
53
53
|
messages: await convertToModelMessages(messages),
|
|
54
54
|
tools: {
|
|
55
55
|
weather: {
|
|
@@ -128,7 +128,7 @@ export async function POST(req: Request) {
|
|
|
128
128
|
const { messages, temperature, userId } = await req.json();
|
|
129
129
|
|
|
130
130
|
const result = streamText({
|
|
131
|
-
model: 'openai/gpt-
|
|
131
|
+
model: 'openai/gpt-4.1-mini', // Supports dynamic temperature settings
|
|
132
132
|
messages: await convertToModelMessages(messages),
|
|
133
133
|
temperature, // Use the dynamic temperature from the request
|
|
134
134
|
// ... other configuration
|
|
@@ -30,7 +30,7 @@ import { generateText } from 'ai';
|
|
|
30
30
|
import { openai } from '@ai-sdk/openai';
|
|
31
31
|
|
|
32
32
|
const result = await generateText({
|
|
33
|
-
model: openai('gpt-
|
|
33
|
+
model: openai('gpt-6-astra'),
|
|
34
34
|
messages: [
|
|
35
35
|
{
|
|
36
36
|
role: 'user',
|
|
@@ -85,7 +85,7 @@ const results = [];
|
|
|
85
85
|
|
|
86
86
|
for (const imageUrl of imageUrls) {
|
|
87
87
|
const result = await generateText({
|
|
88
|
-
model: openai('gpt-
|
|
88
|
+
model: openai('gpt-6-astra'),
|
|
89
89
|
messages: [
|
|
90
90
|
{
|
|
91
91
|
role: 'user',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.116",
|
|
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,20 +42,20 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ai-sdk/gateway": "4.0.
|
|
45
|
+
"@ai-sdk/gateway": "4.0.94",
|
|
46
46
|
"@ai-sdk/provider": "4.0.18",
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.49"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@ai-sdk/amazon-bedrock": "5.0.
|
|
51
|
-
"@ai-sdk/deepseek": "3.0.
|
|
52
|
-
"@ai-sdk/google": "4.0.
|
|
53
|
-
"@ai-sdk/groq": "4.0.
|
|
54
|
-
"@ai-sdk/huggingface": "2.0.
|
|
55
|
-
"@ai-sdk/moonshotai": "3.0.
|
|
56
|
-
"@ai-sdk/openai": "4.0.
|
|
57
|
-
"@ai-sdk/test-server": "2.0.
|
|
58
|
-
"@ai-sdk/xai": "5.0.
|
|
50
|
+
"@ai-sdk/amazon-bedrock": "5.0.96",
|
|
51
|
+
"@ai-sdk/deepseek": "3.0.54",
|
|
52
|
+
"@ai-sdk/google": "4.0.82",
|
|
53
|
+
"@ai-sdk/groq": "4.0.50",
|
|
54
|
+
"@ai-sdk/huggingface": "2.0.57",
|
|
55
|
+
"@ai-sdk/moonshotai": "3.0.58",
|
|
56
|
+
"@ai-sdk/openai": "4.0.77",
|
|
57
|
+
"@ai-sdk/test-server": "2.0.2",
|
|
58
|
+
"@ai-sdk/xai": "5.0.10",
|
|
59
59
|
"@edge-runtime/vm": "^5.0.0",
|
|
60
60
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
61
61
|
"@smithy/util-utf8": "^4.3.3",
|
package/src/evaluate/evaluate.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
} from '@ai-sdk/provider-utils';
|
|
11
11
|
import { resolveEvaluationModel } from '../model/resolve-model';
|
|
12
12
|
import { logWarnings } from '../logger/log-warnings';
|
|
13
|
-
import { filterIncludedContext } from '../telemetry/filter-included-context';
|
|
14
13
|
import type { TelemetryOptions } from '../telemetry/telemetry-options';
|
|
15
14
|
import type { Callback } from '../util/callback';
|
|
16
15
|
import { notify } from '../util/notify';
|
|
@@ -112,17 +111,9 @@ export async function evaluate<
|
|
|
112
111
|
headers,
|
|
113
112
|
providerOptions,
|
|
114
113
|
};
|
|
115
|
-
const tracingStartEvent = {
|
|
116
|
-
...startEvent,
|
|
117
|
-
runtimeContext: filterIncludedContext({
|
|
118
|
-
context: runtimeContext,
|
|
119
|
-
includeContext: telemetry?.includeRuntimeContext,
|
|
120
|
-
}),
|
|
121
|
-
};
|
|
122
|
-
|
|
123
114
|
return await runInTracingChannelSpan({
|
|
124
115
|
type: 'experimental_evaluate',
|
|
125
|
-
event:
|
|
116
|
+
event: startEvent,
|
|
126
117
|
execute: async () => {
|
|
127
118
|
await notify({
|
|
128
119
|
event: startEvent,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '
|
|
7
|
-
import { filterIncludedContext } from '../telemetry/filter-included-context';
|
|
1
|
+
import type { Context, ToolSet } from '@ai-sdk/provider-utils';
|
|
2
|
+
import {
|
|
3
|
+
filterIncludedContext,
|
|
4
|
+
filterToolContext,
|
|
5
|
+
filterToolsContext,
|
|
6
|
+
} from '../telemetry/filter-included-context';
|
|
8
7
|
import { createTelemetryDispatcher } from '../telemetry/create-telemetry-dispatcher';
|
|
9
8
|
import type { TelemetryDispatcher } from '../telemetry/telemetry';
|
|
10
9
|
import type {
|
|
@@ -98,57 +97,6 @@ function restrictStepResult<
|
|
|
98
97
|
});
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
/**
|
|
102
|
-
* Returns a shallow copy of the tools context with only top-level properties
|
|
103
|
-
* marked for telemetry inclusion for each tool.
|
|
104
|
-
*/
|
|
105
|
-
function filterToolsContext<TOOLS extends ToolSet>({
|
|
106
|
-
toolsContext,
|
|
107
|
-
includeToolsContext,
|
|
108
|
-
}: {
|
|
109
|
-
toolsContext: InferToolSetContext<TOOLS>;
|
|
110
|
-
includeToolsContext: IncludedToolsContext<TOOLS>;
|
|
111
|
-
}): InferToolSetContext<TOOLS> {
|
|
112
|
-
if (includeToolsContext == null) {
|
|
113
|
-
return {} as InferToolSetContext<TOOLS>;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return Object.fromEntries(
|
|
117
|
-
Object.entries(toolsContext).map(([toolName, toolContext]) => [
|
|
118
|
-
toolName,
|
|
119
|
-
filterToolContext({
|
|
120
|
-
toolName,
|
|
121
|
-
toolContext,
|
|
122
|
-
includeToolsContext,
|
|
123
|
-
}),
|
|
124
|
-
]),
|
|
125
|
-
) as InferToolSetContext<TOOLS>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function filterToolContext<TOOLS extends ToolSet>({
|
|
129
|
-
toolName,
|
|
130
|
-
toolContext,
|
|
131
|
-
includeToolsContext,
|
|
132
|
-
}: {
|
|
133
|
-
toolName: string;
|
|
134
|
-
toolContext: unknown;
|
|
135
|
-
includeToolsContext: IncludedToolsContext<TOOLS>;
|
|
136
|
-
}) {
|
|
137
|
-
const includeToolContext = (
|
|
138
|
-
includeToolsContext as
|
|
139
|
-
| Record<
|
|
140
|
-
string,
|
|
141
|
-
IncludedContext<InferToolContext<TOOLS[typeof toolName]>>
|
|
142
|
-
>
|
|
143
|
-
| undefined
|
|
144
|
-
)?.[toolName];
|
|
145
|
-
|
|
146
|
-
return filterIncludedContext({
|
|
147
|
-
context: toolContext as InferToolContext<TOOLS[typeof toolName]>,
|
|
148
|
-
includeContext: includeToolContext,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
100
|
/**
|
|
153
101
|
* Creates a telemetry dispatcher that only includes configured runtime context
|
|
154
102
|
* properties in text-generation lifecycle events before dispatching them.
|
|
@@ -24,7 +24,10 @@ type ConvertResult = {
|
|
|
24
24
|
mediaType: string | undefined;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
function convertUrlToFilePartData(
|
|
27
|
+
function convertUrlToFilePartData(
|
|
28
|
+
url: URL,
|
|
29
|
+
originalUrl?: string,
|
|
30
|
+
): ConvertResult {
|
|
28
31
|
if (url.protocol === 'data:') {
|
|
29
32
|
const { mediaType, base64Content } = splitDataUrl(url.toString());
|
|
30
33
|
|
|
@@ -38,7 +41,10 @@ function convertUrlToFilePartData(url: URL): ConvertResult {
|
|
|
38
41
|
return { data: { type: 'data', data: base64Content }, mediaType };
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
return {
|
|
44
|
+
return {
|
|
45
|
+
data: { type: 'url', url, ...(originalUrl != null ? { originalUrl } : {}) },
|
|
46
|
+
mediaType: undefined,
|
|
47
|
+
};
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
function convertUrlStringToFilePartData(content: string): ConvertResult {
|
|
@@ -98,7 +104,7 @@ export function convertToLanguageModelV4FilePart(
|
|
|
98
104
|
}
|
|
99
105
|
return convertInlineDataToFilePartData(content.data);
|
|
100
106
|
case 'url':
|
|
101
|
-
return convertUrlToFilePartData(content.url);
|
|
107
|
+
return convertUrlToFilePartData(content.url, content.originalUrl);
|
|
102
108
|
case 'reference':
|
|
103
109
|
return {
|
|
104
110
|
data: { type: 'reference', reference: content.reference },
|
|
@@ -82,6 +82,8 @@ export async function standardizePrompt({
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// Require explicit trust in supplied system messages to reduce prompt-injection
|
|
86
|
+
// risk. The opt-in permits all system messages, including instruction text.
|
|
85
87
|
if (
|
|
86
88
|
!allowSystemInMessages &&
|
|
87
89
|
messages.some(message => message.role === 'system')
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { asArray } from '@ai-sdk/provider-utils';
|
|
1
|
+
import { asArray, type Context } from '@ai-sdk/provider-utils';
|
|
2
2
|
import type { Callback } from '../util/callback';
|
|
3
|
+
import {
|
|
4
|
+
filterIncludedContext,
|
|
5
|
+
filterToolContext,
|
|
6
|
+
filterToolsContext,
|
|
7
|
+
} from './filter-included-context';
|
|
3
8
|
import { mergeCallbacks } from '../util/merge-callbacks';
|
|
4
9
|
import type {
|
|
5
10
|
InferTelemetryEvent,
|
|
@@ -41,14 +46,59 @@ function augmentEvent<EVENT>(
|
|
|
41
46
|
event: EVENT,
|
|
42
47
|
telemetry: Pick<
|
|
43
48
|
TelemetryOptions,
|
|
44
|
-
|
|
49
|
+
| 'recordInputs'
|
|
50
|
+
| 'recordOutputs'
|
|
51
|
+
| 'functionId'
|
|
52
|
+
| 'includeRuntimeContext'
|
|
53
|
+
| 'includeToolsContext'
|
|
45
54
|
>,
|
|
55
|
+
filterContext = false,
|
|
46
56
|
): InferTelemetryEvent<EVENT> {
|
|
47
|
-
|
|
57
|
+
const augmentedEvent = Object.assign(
|
|
48
58
|
Object.create(Object.getPrototypeOf(event)),
|
|
49
59
|
event,
|
|
50
|
-
|
|
60
|
+
{
|
|
61
|
+
recordInputs: telemetry.recordInputs,
|
|
62
|
+
recordOutputs: telemetry.recordOutputs,
|
|
63
|
+
functionId: telemetry.functionId,
|
|
64
|
+
},
|
|
51
65
|
);
|
|
66
|
+
|
|
67
|
+
if (
|
|
68
|
+
filterContext &&
|
|
69
|
+
event != null &&
|
|
70
|
+
typeof event === 'object' &&
|
|
71
|
+
'runtimeContext' in event
|
|
72
|
+
) {
|
|
73
|
+
augmentedEvent.runtimeContext = filterIncludedContext({
|
|
74
|
+
context: event.runtimeContext as Context,
|
|
75
|
+
includeContext: telemetry.includeRuntimeContext,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (filterContext && event != null && typeof event === 'object') {
|
|
80
|
+
if ('toolsContext' in event) {
|
|
81
|
+
augmentedEvent.toolsContext = filterToolsContext({
|
|
82
|
+
toolsContext: event.toolsContext as Record<string, Context>,
|
|
83
|
+
includeToolsContext: telemetry.includeToolsContext,
|
|
84
|
+
});
|
|
85
|
+
} else if (
|
|
86
|
+
'toolContext' in event &&
|
|
87
|
+
event.toolContext != null &&
|
|
88
|
+
'toolCall' in event &&
|
|
89
|
+
event.toolCall != null &&
|
|
90
|
+
typeof event.toolCall === 'object' &&
|
|
91
|
+
'toolName' in event.toolCall
|
|
92
|
+
) {
|
|
93
|
+
augmentedEvent.toolContext = filterToolContext({
|
|
94
|
+
toolName: event.toolCall.toolName as string,
|
|
95
|
+
toolContext: event.toolContext,
|
|
96
|
+
includeToolsContext: telemetry.includeToolsContext,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return augmentedEvent;
|
|
52
102
|
}
|
|
53
103
|
|
|
54
104
|
/**
|
|
@@ -86,6 +136,8 @@ export function createTelemetryDispatcher({
|
|
|
86
136
|
recordInputs: telemetry?.recordInputs,
|
|
87
137
|
recordOutputs: telemetry?.recordOutputs,
|
|
88
138
|
functionId: telemetry?.functionId,
|
|
139
|
+
includeRuntimeContext: telemetry?.includeRuntimeContext,
|
|
140
|
+
includeToolsContext: telemetry?.includeToolsContext,
|
|
89
141
|
};
|
|
90
142
|
|
|
91
143
|
const mergeTelemetryCallback = <KEY extends TelemetryCallbackKey>(
|
|
@@ -127,7 +179,7 @@ export function createTelemetryDispatcher({
|
|
|
127
179
|
await runWithTracingChannelSpan(
|
|
128
180
|
{
|
|
129
181
|
type,
|
|
130
|
-
event: augmentEvent(event, telemetryMetadata),
|
|
182
|
+
event: augmentEvent(event, telemetryMetadata, true),
|
|
131
183
|
},
|
|
132
184
|
execute,
|
|
133
185
|
),
|
|
@@ -136,7 +188,7 @@ export function createTelemetryDispatcher({
|
|
|
136
188
|
openTelemetryChannelSpanContext({
|
|
137
189
|
message: {
|
|
138
190
|
type,
|
|
139
|
-
event: augmentEvent(event, telemetryMetadata),
|
|
191
|
+
event: augmentEvent(event, telemetryMetadata, true),
|
|
140
192
|
},
|
|
141
193
|
completion,
|
|
142
194
|
}),
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Context,
|
|
3
|
+
InferToolContext,
|
|
4
|
+
InferToolSetContext,
|
|
5
|
+
ToolSet,
|
|
6
|
+
} from '@ai-sdk/provider-utils';
|
|
7
|
+
import type {
|
|
8
|
+
IncludedContext,
|
|
9
|
+
IncludedToolsContext,
|
|
10
|
+
} from './telemetry-options';
|
|
3
11
|
|
|
4
12
|
/**
|
|
5
13
|
* Returns a shallow copy of the runtime context with only top-level
|
|
@@ -22,3 +30,50 @@ export function filterIncludedContext<CONTEXT extends Context>({
|
|
|
22
30
|
),
|
|
23
31
|
);
|
|
24
32
|
}
|
|
33
|
+
|
|
34
|
+
export function filterToolsContext<TOOLS extends ToolSet>({
|
|
35
|
+
toolsContext,
|
|
36
|
+
includeToolsContext,
|
|
37
|
+
}: {
|
|
38
|
+
toolsContext: InferToolSetContext<TOOLS>;
|
|
39
|
+
includeToolsContext: IncludedToolsContext<TOOLS>;
|
|
40
|
+
}): InferToolSetContext<TOOLS> {
|
|
41
|
+
if (includeToolsContext == null) {
|
|
42
|
+
return {} as InferToolSetContext<TOOLS>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Object.fromEntries(
|
|
46
|
+
Object.entries(toolsContext).map(([toolName, toolContext]) => [
|
|
47
|
+
toolName,
|
|
48
|
+
filterToolContext({
|
|
49
|
+
toolName,
|
|
50
|
+
toolContext,
|
|
51
|
+
includeToolsContext,
|
|
52
|
+
}),
|
|
53
|
+
]),
|
|
54
|
+
) as InferToolSetContext<TOOLS>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function filterToolContext<TOOLS extends ToolSet>({
|
|
58
|
+
toolName,
|
|
59
|
+
toolContext,
|
|
60
|
+
includeToolsContext,
|
|
61
|
+
}: {
|
|
62
|
+
toolName: string;
|
|
63
|
+
toolContext: unknown;
|
|
64
|
+
includeToolsContext: IncludedToolsContext<TOOLS>;
|
|
65
|
+
}) {
|
|
66
|
+
const includeToolContext = (
|
|
67
|
+
includeToolsContext as
|
|
68
|
+
| Record<
|
|
69
|
+
string,
|
|
70
|
+
IncludedContext<InferToolContext<TOOLS[typeof toolName]>>
|
|
71
|
+
>
|
|
72
|
+
| undefined
|
|
73
|
+
)?.[toolName];
|
|
74
|
+
|
|
75
|
+
return filterIncludedContext({
|
|
76
|
+
context: toolContext as InferToolContext<TOOLS[typeof toolName]>,
|
|
77
|
+
includeContext: includeToolContext,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
DownloadError,
|
|
4
4
|
readResponseWithSizeLimit,
|
|
5
5
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
6
|
-
|
|
6
|
+
fetchUntrustedUrl,
|
|
7
7
|
withUserAgentSuffix,
|
|
8
8
|
getRuntimeEnvironmentUserAgent,
|
|
9
9
|
} from '@ai-sdk/provider-utils';
|
|
@@ -36,7 +36,7 @@ export const download = async ({
|
|
|
36
36
|
getRuntimeEnvironmentUserAgent(),
|
|
37
37
|
);
|
|
38
38
|
|
|
39
|
-
const response = await
|
|
39
|
+
const response = await fetchUntrustedUrl({
|
|
40
40
|
url: urlText,
|
|
41
41
|
headers,
|
|
42
42
|
abortSignal,
|