ai 3.1.14 → 3.1.16
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/dist/index.d.mts +82 -6
- package/dist/index.d.ts +82 -6
- package/dist/index.js +96 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/rsc/dist/index.d.ts +18 -1
- package/rsc/dist/rsc-server.d.mts +18 -1
- package/rsc/dist/rsc-server.mjs +29 -6
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "3.1.
|
3
|
+
"version": "3.1.16",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -57,8 +57,8 @@
|
|
57
57
|
}
|
58
58
|
},
|
59
59
|
"dependencies": {
|
60
|
-
"@ai-sdk/provider": "0.0.
|
61
|
-
"@ai-sdk/provider-utils": "0.0.
|
60
|
+
"@ai-sdk/provider": "0.0.8",
|
61
|
+
"@ai-sdk/provider-utils": "0.0.11",
|
62
62
|
"secure-json-parse": "2.7.0",
|
63
63
|
"eventsource-parser": "1.1.2",
|
64
64
|
"jsondiffpatch": "0.6.0",
|
@@ -101,7 +101,7 @@
|
|
101
101
|
"tsup": "^7.2.0",
|
102
102
|
"typescript": "5.1.3",
|
103
103
|
"vite-plugin-solid": "2.7.2",
|
104
|
-
"zod": "3.
|
104
|
+
"zod": "3.23.8",
|
105
105
|
"@vercel/ai-tsconfig": "0.0.0",
|
106
106
|
"eslint-config-vercel-ai": "0.0.0"
|
107
107
|
},
|
package/rsc/dist/index.d.ts
CHANGED
@@ -422,6 +422,19 @@ type Prompt = {
|
|
422
422
|
messages?: Array<CoreMessage>;
|
423
423
|
};
|
424
424
|
|
425
|
+
/**
|
426
|
+
Tool choice for the generation. It supports the following settings:
|
427
|
+
|
428
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
429
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
430
|
+
- `none`: the model must not call tools
|
431
|
+
- `{ type: 'tool', tooName: string (typed) }`: the model must call the specified tool
|
432
|
+
*/
|
433
|
+
type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
434
|
+
type: 'tool';
|
435
|
+
toolName: keyof TOOLS;
|
436
|
+
};
|
437
|
+
|
425
438
|
type Streamable = ReactNode | Promise<ReactNode>;
|
426
439
|
type Renderer<T extends Array<any>> = (...args: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
|
427
440
|
type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
|
@@ -460,7 +473,7 @@ type RenderResult = {
|
|
460
473
|
*/
|
461
474
|
declare function streamUI<TOOLS extends {
|
462
475
|
[name: string]: z.ZodTypeAny;
|
463
|
-
} = {}>({ model, tools, system, prompt, messages, maxRetries, abortSignal, initial, text, ...settings }: CallSettings & Prompt & {
|
476
|
+
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, initial, text, ...settings }: CallSettings & Prompt & {
|
464
477
|
/**
|
465
478
|
* The language model to use.
|
466
479
|
*/
|
@@ -471,6 +484,10 @@ declare function streamUI<TOOLS extends {
|
|
471
484
|
tools?: {
|
472
485
|
[name in keyof TOOLS]: RenderTool<TOOLS[name]>;
|
473
486
|
};
|
487
|
+
/**
|
488
|
+
The tool choice strategy. Default: 'auto'.
|
489
|
+
*/
|
490
|
+
toolChoice?: CoreToolChoice<TOOLS>;
|
474
491
|
text?: RenderText;
|
475
492
|
initial?: ReactNode;
|
476
493
|
}): Promise<RenderResult>;
|
@@ -420,6 +420,19 @@ type Prompt = {
|
|
420
420
|
messages?: Array<CoreMessage>;
|
421
421
|
};
|
422
422
|
|
423
|
+
/**
|
424
|
+
Tool choice for the generation. It supports the following settings:
|
425
|
+
|
426
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
427
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
428
|
+
- `none`: the model must not call tools
|
429
|
+
- `{ type: 'tool', tooName: string (typed) }`: the model must call the specified tool
|
430
|
+
*/
|
431
|
+
type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
432
|
+
type: 'tool';
|
433
|
+
toolName: keyof TOOLS;
|
434
|
+
};
|
435
|
+
|
423
436
|
type Streamable = ReactNode | Promise<ReactNode>;
|
424
437
|
type Renderer<T extends Array<any>> = (...args: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
|
425
438
|
type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {
|
@@ -458,7 +471,7 @@ type RenderResult = {
|
|
458
471
|
*/
|
459
472
|
declare function streamUI<TOOLS extends {
|
460
473
|
[name: string]: z.ZodTypeAny;
|
461
|
-
} = {}>({ model, tools, system, prompt, messages, maxRetries, abortSignal, initial, text, ...settings }: CallSettings & Prompt & {
|
474
|
+
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, initial, text, ...settings }: CallSettings & Prompt & {
|
462
475
|
/**
|
463
476
|
* The language model to use.
|
464
477
|
*/
|
@@ -469,6 +482,10 @@ declare function streamUI<TOOLS extends {
|
|
469
482
|
tools?: {
|
470
483
|
[name in keyof TOOLS]: RenderTool<TOOLS[name]>;
|
471
484
|
};
|
485
|
+
/**
|
486
|
+
The tool choice strategy. Default: 'auto'.
|
487
|
+
*/
|
488
|
+
toolChoice?: CoreToolChoice<TOOLS>;
|
472
489
|
text?: RenderText;
|
473
490
|
initial?: ReactNode;
|
474
491
|
}): Promise<RenderResult>;
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -500,6 +500,33 @@ function convertZodToJSONSchema(zodSchema) {
|
|
500
500
|
return zodToJsonSchema(zodSchema);
|
501
501
|
}
|
502
502
|
|
503
|
+
// core/util/is-non-empty-object.ts
|
504
|
+
function isNonEmptyObject(object) {
|
505
|
+
return object != null && Object.keys(object).length > 0;
|
506
|
+
}
|
507
|
+
|
508
|
+
// core/prompt/prepare-tools-and-tool-choice.ts
|
509
|
+
function prepareToolsAndToolChoice({
|
510
|
+
tools,
|
511
|
+
toolChoice
|
512
|
+
}) {
|
513
|
+
if (!isNonEmptyObject(tools)) {
|
514
|
+
return {
|
515
|
+
tools: void 0,
|
516
|
+
toolChoice: void 0
|
517
|
+
};
|
518
|
+
}
|
519
|
+
return {
|
520
|
+
tools: Object.entries(tools).map(([name, tool]) => ({
|
521
|
+
type: "function",
|
522
|
+
name,
|
523
|
+
description: tool.description,
|
524
|
+
parameters: convertZodToJSONSchema(tool.parameters)
|
525
|
+
})),
|
526
|
+
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
527
|
+
};
|
528
|
+
}
|
529
|
+
|
503
530
|
// shared/stream-parts.ts
|
504
531
|
var textStreamPart = {
|
505
532
|
code: "0",
|
@@ -1641,6 +1668,7 @@ var defaultTextRenderer = ({ content }) => content;
|
|
1641
1668
|
async function streamUI({
|
1642
1669
|
model,
|
1643
1670
|
tools,
|
1671
|
+
toolChoice,
|
1644
1672
|
system,
|
1645
1673
|
prompt,
|
1646
1674
|
messages,
|
@@ -1720,12 +1748,7 @@ async function streamUI({
|
|
1720
1748
|
() => model.doStream({
|
1721
1749
|
mode: {
|
1722
1750
|
type: "regular",
|
1723
|
-
|
1724
|
-
type: "function",
|
1725
|
-
name,
|
1726
|
-
description: tool.description,
|
1727
|
-
parameters: convertZodToJSONSchema(tool.parameters)
|
1728
|
-
}))
|
1751
|
+
...prepareToolsAndToolChoice({ tools, toolChoice })
|
1729
1752
|
},
|
1730
1753
|
...prepareCallSettings(settings),
|
1731
1754
|
inputFormat: validatedPrompt.type,
|