ai 7.0.92 → 7.0.94
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 +33 -0
- package/dist/index.d.ts +239 -214
- package/dist/index.js +391 -138
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +3 -2
- package/dist/internal/index.js +8 -5
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -1
- package/docs/03-agents/04-loop-control.mdx +5 -3
- package/docs/03-agents/07-workflow-agent.mdx +27 -6
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +15 -3
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +64 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +9 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +36 -35
- package/docs/03-ai-sdk-core/37-speech.mdx +0 -17
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +36 -0
- package/docs/04-ai-sdk-ui/20-streaming-data.mdx +11 -6
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +14 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +15 -1
- package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +2 -1
- package/docs/07-reference/01-ai-sdk-core/28-output.mdx +27 -1
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +4 -0
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +6 -1
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +42 -28
- package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +7 -0
- package/package.json +12 -12
- package/src/agent/tool-loop-agent-settings.ts +15 -0
- package/src/batch/batch-types.ts +76 -68
- package/src/batch/batch.ts +169 -101
- package/src/batch/index.ts +9 -7
- package/src/embed/embed-many.ts +27 -2
- package/src/error/no-image-generated-error.ts +9 -0
- package/src/generate-image/generate-image.ts +51 -10
- package/src/generate-text/output.ts +111 -1
- package/src/generate-text/stream-language-model-call.ts +82 -0
- package/src/generate-text/stream-text.ts +5 -1
- package/src/ui/chat.ts +1 -1
- package/src/ui/convert-to-model-messages.ts +8 -2
- package/src/ui/validate-ui-messages.ts +14 -0
- package/src/util/data-url.ts +1 -1
- package/src/util/merge-abort-signals.ts +1 -1
- package/src/util/prepare-retries.ts +7 -1
- package/src/util/retry-with-exponential-backoff.ts +9 -4
|
@@ -20,6 +20,9 @@ const existingMessages: UIMessage[] = [
|
|
|
20
20
|
|
|
21
21
|
const stream = createUIMessageStream({
|
|
22
22
|
async execute({ writer }) {
|
|
23
|
+
// The outer stream owns the assistant message lifecycle.
|
|
24
|
+
writer.write({ type: 'start' });
|
|
25
|
+
|
|
23
26
|
// Start a text message
|
|
24
27
|
// Note: The id must be consistent across text-start, text-delta, and text-end steps
|
|
25
28
|
// This allows the system to correctly identify they belong to the same text block
|
|
@@ -50,6 +53,7 @@ const stream = createUIMessageStream({
|
|
|
50
53
|
writer.merge(
|
|
51
54
|
toUIMessageStream({
|
|
52
55
|
stream: result.stream,
|
|
56
|
+
sendStart: false,
|
|
53
57
|
onEnd: ({ outcome }) => {
|
|
54
58
|
// The composer decides that the model stream outcome is also the
|
|
55
59
|
// aggregate stream outcome.
|
|
@@ -33,6 +33,9 @@ const response = createUIMessageStreamResponse({
|
|
|
33
33
|
},
|
|
34
34
|
stream: createUIMessageStream({
|
|
35
35
|
execute({ writer }) {
|
|
36
|
+
// The outer stream owns the assistant message lifecycle.
|
|
37
|
+
writer.write({ type: 'start' });
|
|
38
|
+
|
|
36
39
|
// Write custom data (type must be 'data-<name>')
|
|
37
40
|
writer.write({
|
|
38
41
|
type: 'data-message',
|
|
@@ -68,7 +71,9 @@ const response = createUIMessageStreamResponse({
|
|
|
68
71
|
prompt: 'Say hello',
|
|
69
72
|
});
|
|
70
73
|
|
|
71
|
-
writer.merge(
|
|
74
|
+
writer.merge(
|
|
75
|
+
toUIMessageStream({ stream: result.stream, sendStart: false }),
|
|
76
|
+
);
|
|
72
77
|
},
|
|
73
78
|
}),
|
|
74
79
|
});
|
|
@@ -99,7 +99,7 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
99
99
|
type: 'StopCondition | StopCondition[]',
|
|
100
100
|
isOptional: true,
|
|
101
101
|
description:
|
|
102
|
-
'Default stop condition for the agent loop.
|
|
102
|
+
'Default stop condition for the agent loop. When omitted, WorkflowAgent has no maximum step count and continues until natural completion. Use `isStepCount()` to bound execution. Per-stream values override this default.',
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
name: 'activeTools',
|
|
@@ -268,24 +268,24 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
268
268
|
},
|
|
269
269
|
{
|
|
270
270
|
name: 'onToolExecutionStart',
|
|
271
|
-
type: '
|
|
271
|
+
type: 'WorkflowAgentOnToolExecutionStartCallback',
|
|
272
272
|
isOptional: true,
|
|
273
273
|
description:
|
|
274
274
|
"Callback called right before a tool's execute function runs. If also specified in `stream()`, both callbacks fire (constructor first). Experimental (can break in patch releases).",
|
|
275
275
|
properties: [
|
|
276
276
|
{
|
|
277
|
-
type: '
|
|
277
|
+
type: 'WorkflowAgentToolExecutionStartEvent',
|
|
278
278
|
parameters: [
|
|
279
279
|
{
|
|
280
|
-
name: '
|
|
281
|
-
type: 'string',
|
|
280
|
+
name: 'toolCall',
|
|
281
|
+
type: '{ type: "tool-call"; toolCallId: string; toolName: string; input: unknown }',
|
|
282
282
|
description:
|
|
283
|
-
'
|
|
283
|
+
'The tool call being executed. For concrete tool sets, the tool name and input are correlated.',
|
|
284
284
|
},
|
|
285
285
|
{
|
|
286
|
-
name: '
|
|
287
|
-
type: '
|
|
288
|
-
description: 'The
|
|
286
|
+
name: 'stepNumber',
|
|
287
|
+
type: 'number',
|
|
288
|
+
description: 'The current step number, starting at zero.',
|
|
289
289
|
},
|
|
290
290
|
{
|
|
291
291
|
name: 'messages',
|
|
@@ -295,9 +295,9 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
295
295
|
},
|
|
296
296
|
{
|
|
297
297
|
name: 'toolContext',
|
|
298
|
-
type: 'InferToolContext<TOOLS[
|
|
298
|
+
type: 'InferToolContext<TOOLS[NAME]> | undefined',
|
|
299
299
|
description:
|
|
300
|
-
'
|
|
300
|
+
'The validated context for the tool call. For concrete tool sets, each event union member pairs it with the corresponding tool name.',
|
|
301
301
|
},
|
|
302
302
|
],
|
|
303
303
|
},
|
|
@@ -305,24 +305,24 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
305
305
|
},
|
|
306
306
|
{
|
|
307
307
|
name: 'onToolExecutionEnd',
|
|
308
|
-
type: '
|
|
308
|
+
type: 'WorkflowAgentOnToolExecutionEndCallback',
|
|
309
309
|
isOptional: true,
|
|
310
310
|
description:
|
|
311
|
-
"Callback called right after a tool's execute function completes or errors.
|
|
311
|
+
"Callback called right after a tool's execute function completes or errors. Check `success` to determine whether `output` or `error` is available. If also specified in `stream()`, both callbacks fire (constructor first). Experimental (can break in patch releases).",
|
|
312
312
|
properties: [
|
|
313
313
|
{
|
|
314
|
-
type: '
|
|
314
|
+
type: 'WorkflowAgentToolExecutionEndEvent',
|
|
315
315
|
parameters: [
|
|
316
316
|
{
|
|
317
|
-
name: '
|
|
318
|
-
type: 'string',
|
|
317
|
+
name: 'toolCall',
|
|
318
|
+
type: '{ type: "tool-call"; toolCallId: string; toolName: string; input: unknown }',
|
|
319
319
|
description:
|
|
320
|
-
'
|
|
320
|
+
'The tool call that was executed. For concrete tool sets, the tool name and input are correlated.',
|
|
321
321
|
},
|
|
322
322
|
{
|
|
323
|
-
name: '
|
|
324
|
-
type: '
|
|
325
|
-
description: 'The
|
|
323
|
+
name: 'stepNumber',
|
|
324
|
+
type: 'number',
|
|
325
|
+
description: 'The current step number, starting at zero.',
|
|
326
326
|
},
|
|
327
327
|
{
|
|
328
328
|
name: 'durationMs',
|
|
@@ -338,15 +338,29 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
|
|
|
338
338
|
},
|
|
339
339
|
{
|
|
340
340
|
name: 'toolContext',
|
|
341
|
-
type: 'InferToolContext<TOOLS[
|
|
341
|
+
type: 'InferToolContext<TOOLS[NAME]> | undefined',
|
|
342
|
+
description:
|
|
343
|
+
'The validated context for the tool call. For concrete tool sets, each event union member pairs it with the corresponding tool name.',
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
name: 'success',
|
|
347
|
+
type: 'boolean',
|
|
348
|
+
description:
|
|
349
|
+
'Whether the tool execution succeeded. Discriminates between the output and error event variants.',
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
name: 'output',
|
|
353
|
+
type: 'InferToolOutput<TOOLS[NAME]>',
|
|
354
|
+
isOptional: true,
|
|
342
355
|
description:
|
|
343
|
-
'
|
|
356
|
+
'The tool output. Available when `success` is `true` and correlated with the configured tool.',
|
|
344
357
|
},
|
|
345
358
|
{
|
|
346
|
-
name: '
|
|
347
|
-
type: '
|
|
359
|
+
name: 'error',
|
|
360
|
+
type: 'unknown',
|
|
361
|
+
isOptional: true,
|
|
348
362
|
description:
|
|
349
|
-
|
|
363
|
+
'The tool execution error. Available when `success` is `false`.',
|
|
350
364
|
},
|
|
351
365
|
],
|
|
352
366
|
},
|
|
@@ -509,7 +523,7 @@ const result = await agent.stream({
|
|
|
509
523
|
name: 'stopWhen',
|
|
510
524
|
type: 'StopCondition | StopCondition[]',
|
|
511
525
|
isOptional: true,
|
|
512
|
-
description: 'Condition(s) for ending the agent loop.
|
|
526
|
+
description: 'Condition(s) for ending the agent loop. When omitted and no constructor-level condition is configured, WorkflowAgent has no maximum step count and continues until natural completion. Use `isStepCount()` to bound execution.',
|
|
513
527
|
},
|
|
514
528
|
|
|
515
529
|
{
|
|
@@ -644,14 +658,14 @@ const result = await agent.stream({
|
|
|
644
658
|
},
|
|
645
659
|
{
|
|
646
660
|
name: 'onToolExecutionStart',
|
|
647
|
-
type: '
|
|
661
|
+
type: 'WorkflowAgentOnToolExecutionStartCallback',
|
|
648
662
|
isOptional: true,
|
|
649
663
|
description:
|
|
650
664
|
'Per-call onToolExecutionStart callback. If also specified in the constructor, both fire (constructor first).',
|
|
651
665
|
},
|
|
652
666
|
{
|
|
653
667
|
name: 'onToolExecutionEnd',
|
|
654
|
-
type: '
|
|
668
|
+
type: 'WorkflowAgentOnToolExecutionEndCallback',
|
|
655
669
|
isOptional: true,
|
|
656
670
|
description:
|
|
657
671
|
'Per-call onToolExecutionEnd callback. If also specified in the constructor, both fire (constructor first).',
|
|
@@ -14,6 +14,7 @@ It can arise due to the following reasons:
|
|
|
14
14
|
## Properties
|
|
15
15
|
|
|
16
16
|
- `message`: The error message (optional, defaults to `'No image generated.'`).
|
|
17
|
+
- `calls`: Results from the underlying image model calls, including generated images, provider metadata, response metadata, warnings, and usage (optional).
|
|
17
18
|
- `responses`: Metadata about the image model responses, including timestamp, model, and headers (optional).
|
|
18
19
|
- `cause`: The cause of the error. You can use this for more detailed error handling (optional).
|
|
19
20
|
|
|
@@ -31,6 +32,12 @@ try {
|
|
|
31
32
|
console.log('NoImageGeneratedError');
|
|
32
33
|
console.log('Cause:', error.cause);
|
|
33
34
|
console.log('Responses:', error.responses);
|
|
35
|
+
|
|
36
|
+
for (const call of error.calls ?? []) {
|
|
37
|
+
console.log('Provider metadata:', call.providerMetadata);
|
|
38
|
+
console.log('Warnings:', call.warnings);
|
|
39
|
+
console.log('Usage:', call.usage);
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
43
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.94",
|
|
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.
|
|
46
|
-
"@ai-sdk/provider": "4.0.
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
45
|
+
"@ai-sdk/gateway": "4.0.76",
|
|
46
|
+
"@ai-sdk/provider": "4.0.11",
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.37"
|
|
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.
|
|
50
|
+
"@ai-sdk/amazon-bedrock": "5.0.77",
|
|
51
|
+
"@ai-sdk/deepseek": "3.0.40",
|
|
52
|
+
"@ai-sdk/google": "4.0.65",
|
|
53
|
+
"@ai-sdk/groq": "4.0.38",
|
|
54
|
+
"@ai-sdk/huggingface": "2.0.45",
|
|
55
|
+
"@ai-sdk/moonshotai": "3.0.46",
|
|
56
|
+
"@ai-sdk/openai": "4.0.61",
|
|
57
57
|
"@ai-sdk/test-server": "2.0.1",
|
|
58
|
-
"@ai-sdk/xai": "4.0.
|
|
58
|
+
"@ai-sdk/xai": "4.0.55",
|
|
59
59
|
"@edge-runtime/vm": "^5.0.0",
|
|
60
60
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
61
61
|
"@smithy/util-utf8": "^4.3.3",
|
|
@@ -17,6 +17,10 @@ import type {
|
|
|
17
17
|
GenerateTextOnStepStartCallback,
|
|
18
18
|
} from '../generate-text/generate-text-events';
|
|
19
19
|
import type { GenerateTextInclude } from '../generate-text/generate-text';
|
|
20
|
+
import type {
|
|
21
|
+
OnLanguageModelCallEndCallback,
|
|
22
|
+
OnLanguageModelCallStartCallback,
|
|
23
|
+
} from '../generate-text/language-model-events';
|
|
20
24
|
import type { Output } from '../generate-text/output';
|
|
21
25
|
import type { PrepareStepFunction } from '../generate-text/prepare-step';
|
|
22
26
|
import type { StopCondition } from '../generate-text/stop-condition';
|
|
@@ -212,6 +216,17 @@ export type ToolLoopAgentSettings<
|
|
|
212
216
|
NoInfer<OUTPUT>
|
|
213
217
|
>;
|
|
214
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Callback that is called immediately before the provider model call begins.
|
|
221
|
+
*/
|
|
222
|
+
onLanguageModelCallStart?: OnLanguageModelCallStartCallback;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Callback that is called after the model response has been normalized and parsed,
|
|
226
|
+
* but before any client-side tool execution begins.
|
|
227
|
+
*/
|
|
228
|
+
onLanguageModelCallEnd?: OnLanguageModelCallEndCallback<NoInfer<TOOLS>>;
|
|
229
|
+
|
|
215
230
|
/**
|
|
216
231
|
* Callback that is called before each tool execution begins.
|
|
217
232
|
*/
|
package/src/batch/batch-types.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
Experimental_BatchV4 as BatchV4,
|
|
2
3
|
Experimental_BatchV4Error as BatchV4Error,
|
|
4
|
+
Experimental_BatchV4ModelIds as BatchV4ModelIds,
|
|
3
5
|
Experimental_BatchV4StartResult as BatchV4StartResult,
|
|
4
6
|
Experimental_BatchV4Status as BatchV4Status,
|
|
5
|
-
|
|
7
|
+
ProviderV4,
|
|
6
8
|
} from '@ai-sdk/provider';
|
|
7
9
|
import type {
|
|
8
10
|
InferToolSetContext,
|
|
@@ -13,40 +15,31 @@ import type { ContentPart } from '../generate-text/content-part';
|
|
|
13
15
|
import type { ToolOrder } from '../generate-text/tool-order';
|
|
14
16
|
import type { LanguageModelCallOptions } from '../prompt/language-model-call-options';
|
|
15
17
|
import type { Prompt } from '../prompt/prompt';
|
|
16
|
-
import type {
|
|
17
|
-
FinishReason,
|
|
18
|
-
GlobalProviderModelId,
|
|
19
|
-
ToolChoice,
|
|
20
|
-
} from '../types/language-model';
|
|
18
|
+
import type { FinishReason, ToolChoice } from '../types/language-model';
|
|
21
19
|
import type { ProviderMetadata } from '../types/provider-metadata';
|
|
22
20
|
import type { LanguageModelUsage } from '../types/usage';
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* String model IDs are resolved through the global provider and checked for
|
|
28
|
-
* batch support at runtime.
|
|
23
|
+
* Provider or lower-level batch interface used for batch processing.
|
|
29
24
|
*/
|
|
30
|
-
export type
|
|
25
|
+
export type BatchProvider = ProviderV4 | BatchV4;
|
|
26
|
+
|
|
27
|
+
type InferBatchModelIds<PROVIDER extends BatchProvider> =
|
|
28
|
+
PROVIDER extends BatchV4<infer MODEL_IDS>
|
|
29
|
+
? MODEL_IDS
|
|
30
|
+
: PROVIDER extends { experimental_batch(): BatchV4<infer MODEL_IDS> }
|
|
31
|
+
? MODEL_IDS
|
|
32
|
+
: BatchV4ModelIds;
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
|
-
* The persisted reference for a
|
|
35
|
+
* The persisted reference for a batch.
|
|
34
36
|
*/
|
|
35
|
-
export type
|
|
36
|
-
readonly version:
|
|
37
|
-
readonly type: 'text';
|
|
37
|
+
export type BatchReference = {
|
|
38
|
+
readonly version: 2;
|
|
38
39
|
readonly id: string;
|
|
39
40
|
readonly provider: string;
|
|
40
|
-
readonly modelId: string;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
/**
|
|
44
|
-
* Persisted reference for any supported batch type.
|
|
45
|
-
*
|
|
46
|
-
* Additional modality-specific references can be added to this union.
|
|
47
|
-
*/
|
|
48
|
-
export type BatchReference = TextBatchReference;
|
|
49
|
-
|
|
50
43
|
/**
|
|
51
44
|
* Serializable error information for a batch or batch item.
|
|
52
45
|
*/
|
|
@@ -58,55 +51,55 @@ export type BatchError = BatchV4Error;
|
|
|
58
51
|
export type BatchStatus = BatchV4Status;
|
|
59
52
|
|
|
60
53
|
/**
|
|
61
|
-
* A
|
|
54
|
+
* A batch and its latest normalized lifecycle status.
|
|
62
55
|
*/
|
|
63
|
-
export type
|
|
56
|
+
export type Batch = BatchReference & BatchStatus;
|
|
64
57
|
|
|
65
58
|
/**
|
|
66
59
|
* One text generation request within a batch.
|
|
67
60
|
*/
|
|
68
|
-
export type TextBatchRequest
|
|
61
|
+
export type TextBatchRequest<
|
|
62
|
+
ModelId extends string = string,
|
|
63
|
+
TOOLS extends ToolSet = ToolSet,
|
|
64
|
+
> = Prompt &
|
|
69
65
|
LanguageModelCallOptions & {
|
|
70
66
|
id: string;
|
|
67
|
+
type: 'text';
|
|
68
|
+
model: ModelId;
|
|
69
|
+
tools?: TOOLS;
|
|
70
|
+
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
71
|
+
toolOrder?: ToolOrder<TOOLS>;
|
|
72
|
+
toolsContext?: InferToolSetContext<TOOLS>;
|
|
71
73
|
providerOptions?: ProviderOptions;
|
|
72
74
|
};
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
/**
|
|
77
|
+
* One request within a batch, discriminated by modality.
|
|
78
|
+
*/
|
|
79
|
+
export type BatchRequest<
|
|
80
|
+
ModelIds extends BatchV4ModelIds = BatchV4ModelIds,
|
|
81
|
+
TOOLS extends ToolSet = ToolSet,
|
|
82
|
+
> = TextBatchRequest<ModelIds['text'], TOOLS>;
|
|
83
|
+
|
|
84
|
+
type BatchCallOptions = {
|
|
75
85
|
abortSignal?: AbortSignal;
|
|
76
86
|
headers?: Record<string, string | undefined>;
|
|
77
87
|
timeout?: number | { totalMs?: number };
|
|
78
88
|
};
|
|
79
89
|
|
|
80
90
|
/**
|
|
81
|
-
* Options for starting a
|
|
91
|
+
* Options for starting a batch.
|
|
82
92
|
*/
|
|
83
|
-
export type
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Tools that the model can call for every request in the batch.
|
|
89
|
-
*
|
|
90
|
-
* Tool definitions are sent to the provider, but their `execute` functions
|
|
91
|
-
* are never invoked by batch processing.
|
|
92
|
-
*/
|
|
93
|
-
tools?: TOOLS;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The tool choice strategy. Default: 'auto'.
|
|
97
|
-
*/
|
|
98
|
-
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
99
|
-
|
|
93
|
+
export type StartBatchOptions<
|
|
94
|
+
TOOLS extends ToolSet = ToolSet,
|
|
95
|
+
PROVIDER extends BatchProvider = BatchProvider,
|
|
96
|
+
> = {
|
|
100
97
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
98
|
+
* Provider used to process the batch. Defaults to the global provider, or
|
|
99
|
+
* the Vercel AI Gateway when no global provider is configured.
|
|
103
100
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Context used when resolving dynamic tool descriptions.
|
|
108
|
-
*/
|
|
109
|
-
toolsContext?: InferToolSetContext<TOOLS>;
|
|
101
|
+
provider?: PROVIDER;
|
|
102
|
+
requests: ReadonlyArray<BatchRequest<InferBatchModelIds<PROVIDER>, TOOLS>>;
|
|
110
103
|
|
|
111
104
|
providerOptions?: ProviderOptions;
|
|
112
105
|
|
|
@@ -116,33 +109,42 @@ export type StartTextBatchOptions<TOOLS extends ToolSet = ToolSet> = {
|
|
|
116
109
|
* unsupported warning.
|
|
117
110
|
*/
|
|
118
111
|
webhookUrl?: string;
|
|
119
|
-
} &
|
|
112
|
+
} & BatchCallOptions;
|
|
120
113
|
|
|
121
114
|
/**
|
|
122
|
-
* The acknowledged
|
|
115
|
+
* The acknowledged batch and warnings produced while starting it.
|
|
123
116
|
*/
|
|
124
|
-
export type
|
|
117
|
+
export type StartBatchResult = Batch & {
|
|
125
118
|
readonly warnings: BatchV4StartResult['warnings'];
|
|
126
119
|
};
|
|
127
120
|
|
|
128
121
|
/**
|
|
129
|
-
* Options
|
|
122
|
+
* Options for retrieving batch status.
|
|
130
123
|
*/
|
|
131
|
-
export type
|
|
132
|
-
model: BatchLanguageModel;
|
|
133
|
-
batch: BatchReference;
|
|
134
|
-
|
|
124
|
+
export type GetBatchStatusOptions = {
|
|
135
125
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* The definitions are used only to validate and normalize returned tool
|
|
139
|
-
* calls. Their `execute` functions are never invoked.
|
|
126
|
+
* Provider used to access the batch. Defaults to the global provider, or
|
|
127
|
+
* the Vercel AI Gateway when no global provider is configured.
|
|
140
128
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
129
|
+
provider?: BatchProvider;
|
|
130
|
+
batch: BatchReference;
|
|
143
131
|
providerOptions?: ProviderOptions;
|
|
144
132
|
maxRetries?: number;
|
|
145
|
-
} &
|
|
133
|
+
} & BatchCallOptions;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Options for retrieving batch results.
|
|
137
|
+
*/
|
|
138
|
+
export type GetBatchResultsOptions<TOOLS extends ToolSet = ToolSet> =
|
|
139
|
+
GetBatchStatusOptions & {
|
|
140
|
+
/**
|
|
141
|
+
* Definitions for client tools that were provided to `startBatch` requests.
|
|
142
|
+
*
|
|
143
|
+
* The definitions are used only to validate and normalize returned tool
|
|
144
|
+
* calls. Their `execute` functions are never invoked.
|
|
145
|
+
*/
|
|
146
|
+
tools?: TOOLS;
|
|
147
|
+
};
|
|
146
148
|
|
|
147
149
|
/**
|
|
148
150
|
* A normalized result for a successful text batch item.
|
|
@@ -182,3 +184,9 @@ export type TextBatchItemResult<TOOLS extends ToolSet = ToolSet> =
|
|
|
182
184
|
readonly error?: BatchError;
|
|
183
185
|
readonly providerMetadata?: ProviderMetadata;
|
|
184
186
|
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A complete terminal result for one request in a batch.
|
|
190
|
+
*/
|
|
191
|
+
export type BatchItemResult<TOOLS extends ToolSet = ToolSet> =
|
|
192
|
+
TextBatchItemResult<TOOLS>;
|