ai 5.0.0-alpha.12 → 5.0.0-alpha.14
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/dist/index.d.mts +177 -175
- package/dist/index.d.ts +177 -175
- package/dist/index.js +354 -344
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +301 -290
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +33 -20
- package/dist/internal/index.d.ts +33 -20
- package/dist/internal/index.js +14 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +14 -7
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +3 -3
- package/dist/mcp-stdio/index.d.ts +3 -3
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +4 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ToolResultContent, Schema } from '@ai-sdk/provider-utils';
|
2
2
|
export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';
|
3
|
-
import { SharedV2ProviderOptions, LanguageModelV2Prompt, JSONValue, JSONObject, LanguageModelV2FunctionTool,
|
3
|
+
import { SharedV2ProviderOptions, LanguageModelV2Prompt, JSONValue, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedClientTool, LanguageModelV2ProviderDefinedServerTool, LanguageModelV2ToolChoice } from '@ai-sdk/provider';
|
4
4
|
import * as z3 from 'zod/v3';
|
5
5
|
import * as z4 from 'zod/v4/core';
|
6
6
|
|
@@ -126,7 +126,7 @@ interface ToolCallPart {
|
|
126
126
|
/**
|
127
127
|
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
128
128
|
*/
|
129
|
-
|
129
|
+
input: unknown;
|
130
130
|
/**
|
131
131
|
Additional provider-specific metadata. They are passed through
|
132
132
|
to the provider from the AI SDK and enable provider-specific
|
@@ -150,7 +150,7 @@ interface ToolResultPart {
|
|
150
150
|
/**
|
151
151
|
Result of the tool call. This is a JSON-serializable object.
|
152
152
|
*/
|
153
|
-
|
153
|
+
output: unknown;
|
154
154
|
/**
|
155
155
|
Multi-part content of the tool result. Only for tools that support multipart results.
|
156
156
|
*/
|
@@ -367,7 +367,7 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
|
|
367
367
|
toolName: Extract<keyof TOOLS, string>;
|
368
368
|
};
|
369
369
|
|
370
|
-
type
|
370
|
+
type ToolInputSchema<T = JSONObject> = z4.$ZodType<T> | z3.Schema<T> | Schema<T>;
|
371
371
|
interface ToolCallOptions {
|
372
372
|
/**
|
373
373
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
@@ -390,21 +390,21 @@ This enables the language model to generate the input.
|
|
390
390
|
|
391
391
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
392
392
|
*/
|
393
|
-
type Tool<
|
393
|
+
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT = any> = {
|
394
394
|
/**
|
395
395
|
An optional description of what the tool does.
|
396
396
|
Will be used by the language model to decide whether to use the tool.
|
397
|
-
Not used for provider-defined tools.
|
397
|
+
Not used for provider-defined-client tools.
|
398
398
|
*/
|
399
399
|
description?: string;
|
400
|
-
} & NeverOptional<
|
400
|
+
} & NeverOptional<INPUT, {
|
401
401
|
/**
|
402
402
|
The schema of the input that the tool expects. The language model will use this to generate the input.
|
403
403
|
It is also used to validate the output of the language model.
|
404
404
|
Use descriptions to make the input understandable for the language model.
|
405
405
|
*/
|
406
|
-
|
407
|
-
}> & NeverOptional<
|
406
|
+
inputSchema: ToolInputSchema<INPUT>;
|
407
|
+
}> & NeverOptional<OUTPUT, {
|
408
408
|
/**
|
409
409
|
An async function that is called with the arguments from the tool call and produces a result.
|
410
410
|
If not provided, the tool will not be executed automatically.
|
@@ -412,29 +412,29 @@ If not provided, the tool will not be executed automatically.
|
|
412
412
|
@args is the input of the tool call.
|
413
413
|
@options.abortSignal is a signal that can be used to abort the tool call.
|
414
414
|
*/
|
415
|
-
execute: (
|
415
|
+
execute: (input: [INPUT] extends [never] ? undefined : INPUT, options: ToolCallOptions) => PromiseLike<OUTPUT>;
|
416
416
|
/**
|
417
417
|
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
418
418
|
*/
|
419
|
-
experimental_toToolResultContent?: (
|
419
|
+
experimental_toToolResultContent?: (output: OUTPUT) => ToolResultContent;
|
420
420
|
/**
|
421
421
|
* Optional function that is called when the argument streaming starts.
|
422
422
|
* Only called when the tool is used in a streaming context.
|
423
423
|
*/
|
424
|
-
|
424
|
+
onInputStart?: (options: ToolCallOptions) => void | PromiseLike<void>;
|
425
425
|
/**
|
426
426
|
* Optional function that is called when an argument streaming delta is available.
|
427
427
|
* Only called when the tool is used in a streaming context.
|
428
428
|
*/
|
429
|
-
|
430
|
-
|
429
|
+
onInputDelta?: (options: {
|
430
|
+
inputTextDelta: string;
|
431
431
|
} & ToolCallOptions) => void | PromiseLike<void>;
|
432
432
|
/**
|
433
433
|
* Optional function that is called when a tool call can be started,
|
434
434
|
* even if the execute function is not provided.
|
435
435
|
*/
|
436
|
-
|
437
|
-
|
436
|
+
onInputAvailable?: (options: {
|
437
|
+
input: [INPUT] extends [never] ? undefined : INPUT;
|
438
438
|
} & ToolCallOptions) => void | PromiseLike<void>;
|
439
439
|
}> & ({
|
440
440
|
/**
|
@@ -443,9 +443,22 @@ Function tool.
|
|
443
443
|
type?: undefined | 'function';
|
444
444
|
} | {
|
445
445
|
/**
|
446
|
-
Provider-defined tool.
|
446
|
+
Provider-defined-client tool.
|
447
447
|
*/
|
448
|
-
type: 'provider-defined';
|
448
|
+
type: 'provider-defined-client';
|
449
|
+
/**
|
450
|
+
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
451
|
+
*/
|
452
|
+
id: `${string}.${string}`;
|
453
|
+
/**
|
454
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
455
|
+
*/
|
456
|
+
args: Record<string, unknown>;
|
457
|
+
} | {
|
458
|
+
/**
|
459
|
+
Provider-defined-server tool.
|
460
|
+
*/
|
461
|
+
type: 'provider-defined-server';
|
449
462
|
/**
|
450
463
|
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
451
464
|
*/
|
@@ -456,14 +469,14 @@ The arguments for configuring the tool. Must match the expected arguments define
|
|
456
469
|
args: Record<string, unknown>;
|
457
470
|
});
|
458
471
|
|
459
|
-
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | '
|
472
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta'>>;
|
460
473
|
|
461
474
|
declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolChoice, activeTools, }: {
|
462
475
|
tools: TOOLS | undefined;
|
463
476
|
toolChoice: ToolChoice<TOOLS> | undefined;
|
464
477
|
activeTools: Array<keyof TOOLS> | undefined;
|
465
478
|
}): {
|
466
|
-
tools: Array<LanguageModelV2FunctionTool |
|
479
|
+
tools: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedClientTool | LanguageModelV2ProviderDefinedServerTool> | undefined;
|
467
480
|
toolChoice: LanguageModelV2ToolChoice | undefined;
|
468
481
|
};
|
469
482
|
|
package/dist/internal/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ToolResultContent, Schema } from '@ai-sdk/provider-utils';
|
2
2
|
export { convertAsyncIteratorToReadableStream } from '@ai-sdk/provider-utils';
|
3
|
-
import { SharedV2ProviderOptions, LanguageModelV2Prompt, JSONValue, JSONObject, LanguageModelV2FunctionTool,
|
3
|
+
import { SharedV2ProviderOptions, LanguageModelV2Prompt, JSONValue, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedClientTool, LanguageModelV2ProviderDefinedServerTool, LanguageModelV2ToolChoice } from '@ai-sdk/provider';
|
4
4
|
import * as z3 from 'zod/v3';
|
5
5
|
import * as z4 from 'zod/v4/core';
|
6
6
|
|
@@ -126,7 +126,7 @@ interface ToolCallPart {
|
|
126
126
|
/**
|
127
127
|
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
128
128
|
*/
|
129
|
-
|
129
|
+
input: unknown;
|
130
130
|
/**
|
131
131
|
Additional provider-specific metadata. They are passed through
|
132
132
|
to the provider from the AI SDK and enable provider-specific
|
@@ -150,7 +150,7 @@ interface ToolResultPart {
|
|
150
150
|
/**
|
151
151
|
Result of the tool call. This is a JSON-serializable object.
|
152
152
|
*/
|
153
|
-
|
153
|
+
output: unknown;
|
154
154
|
/**
|
155
155
|
Multi-part content of the tool result. Only for tools that support multipart results.
|
156
156
|
*/
|
@@ -367,7 +367,7 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
|
|
367
367
|
toolName: Extract<keyof TOOLS, string>;
|
368
368
|
};
|
369
369
|
|
370
|
-
type
|
370
|
+
type ToolInputSchema<T = JSONObject> = z4.$ZodType<T> | z3.Schema<T> | Schema<T>;
|
371
371
|
interface ToolCallOptions {
|
372
372
|
/**
|
373
373
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
@@ -390,21 +390,21 @@ This enables the language model to generate the input.
|
|
390
390
|
|
391
391
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
392
392
|
*/
|
393
|
-
type Tool<
|
393
|
+
type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT = any> = {
|
394
394
|
/**
|
395
395
|
An optional description of what the tool does.
|
396
396
|
Will be used by the language model to decide whether to use the tool.
|
397
|
-
Not used for provider-defined tools.
|
397
|
+
Not used for provider-defined-client tools.
|
398
398
|
*/
|
399
399
|
description?: string;
|
400
|
-
} & NeverOptional<
|
400
|
+
} & NeverOptional<INPUT, {
|
401
401
|
/**
|
402
402
|
The schema of the input that the tool expects. The language model will use this to generate the input.
|
403
403
|
It is also used to validate the output of the language model.
|
404
404
|
Use descriptions to make the input understandable for the language model.
|
405
405
|
*/
|
406
|
-
|
407
|
-
}> & NeverOptional<
|
406
|
+
inputSchema: ToolInputSchema<INPUT>;
|
407
|
+
}> & NeverOptional<OUTPUT, {
|
408
408
|
/**
|
409
409
|
An async function that is called with the arguments from the tool call and produces a result.
|
410
410
|
If not provided, the tool will not be executed automatically.
|
@@ -412,29 +412,29 @@ If not provided, the tool will not be executed automatically.
|
|
412
412
|
@args is the input of the tool call.
|
413
413
|
@options.abortSignal is a signal that can be used to abort the tool call.
|
414
414
|
*/
|
415
|
-
execute: (
|
415
|
+
execute: (input: [INPUT] extends [never] ? undefined : INPUT, options: ToolCallOptions) => PromiseLike<OUTPUT>;
|
416
416
|
/**
|
417
417
|
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
418
418
|
*/
|
419
|
-
experimental_toToolResultContent?: (
|
419
|
+
experimental_toToolResultContent?: (output: OUTPUT) => ToolResultContent;
|
420
420
|
/**
|
421
421
|
* Optional function that is called when the argument streaming starts.
|
422
422
|
* Only called when the tool is used in a streaming context.
|
423
423
|
*/
|
424
|
-
|
424
|
+
onInputStart?: (options: ToolCallOptions) => void | PromiseLike<void>;
|
425
425
|
/**
|
426
426
|
* Optional function that is called when an argument streaming delta is available.
|
427
427
|
* Only called when the tool is used in a streaming context.
|
428
428
|
*/
|
429
|
-
|
430
|
-
|
429
|
+
onInputDelta?: (options: {
|
430
|
+
inputTextDelta: string;
|
431
431
|
} & ToolCallOptions) => void | PromiseLike<void>;
|
432
432
|
/**
|
433
433
|
* Optional function that is called when a tool call can be started,
|
434
434
|
* even if the execute function is not provided.
|
435
435
|
*/
|
436
|
-
|
437
|
-
|
436
|
+
onInputAvailable?: (options: {
|
437
|
+
input: [INPUT] extends [never] ? undefined : INPUT;
|
438
438
|
} & ToolCallOptions) => void | PromiseLike<void>;
|
439
439
|
}> & ({
|
440
440
|
/**
|
@@ -443,9 +443,22 @@ Function tool.
|
|
443
443
|
type?: undefined | 'function';
|
444
444
|
} | {
|
445
445
|
/**
|
446
|
-
Provider-defined tool.
|
446
|
+
Provider-defined-client tool.
|
447
447
|
*/
|
448
|
-
type: 'provider-defined';
|
448
|
+
type: 'provider-defined-client';
|
449
|
+
/**
|
450
|
+
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
451
|
+
*/
|
452
|
+
id: `${string}.${string}`;
|
453
|
+
/**
|
454
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
455
|
+
*/
|
456
|
+
args: Record<string, unknown>;
|
457
|
+
} | {
|
458
|
+
/**
|
459
|
+
Provider-defined-server tool.
|
460
|
+
*/
|
461
|
+
type: 'provider-defined-server';
|
449
462
|
/**
|
450
463
|
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
451
464
|
*/
|
@@ -456,14 +469,14 @@ The arguments for configuring the tool. Must match the expected arguments define
|
|
456
469
|
args: Record<string, unknown>;
|
457
470
|
});
|
458
471
|
|
459
|
-
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | '
|
472
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta'>>;
|
460
473
|
|
461
474
|
declare function prepareToolsAndToolChoice<TOOLS extends ToolSet>({ tools, toolChoice, activeTools, }: {
|
462
475
|
tools: TOOLS | undefined;
|
463
476
|
toolChoice: ToolChoice<TOOLS> | undefined;
|
464
477
|
activeTools: Array<keyof TOOLS> | undefined;
|
465
478
|
}): {
|
466
|
-
tools: Array<LanguageModelV2FunctionTool |
|
479
|
+
tools: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedClientTool | LanguageModelV2ProviderDefinedServerTool> | undefined;
|
467
480
|
toolChoice: LanguageModelV2ToolChoice | undefined;
|
468
481
|
};
|
469
482
|
|
package/dist/internal/index.js
CHANGED
@@ -358,7 +358,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
358
358
|
type: "tool-call",
|
359
359
|
toolCallId: part.toolCallId,
|
360
360
|
toolName: part.toolName,
|
361
|
-
|
361
|
+
input: part.input,
|
362
362
|
providerOptions
|
363
363
|
};
|
364
364
|
}
|
@@ -374,7 +374,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
374
374
|
type: "tool-result",
|
375
375
|
toolCallId: part.toolCallId,
|
376
376
|
toolName: part.toolName,
|
377
|
-
|
377
|
+
output: part.output,
|
378
378
|
content: part.experimental_content,
|
379
379
|
isError: part.isError,
|
380
380
|
providerOptions: part.providerOptions
|
@@ -514,11 +514,18 @@ function prepareToolsAndToolChoice({
|
|
514
514
|
type: "function",
|
515
515
|
name: name5,
|
516
516
|
description: tool.description,
|
517
|
-
|
517
|
+
inputSchema: (0, import_provider_utils4.asSchema)(tool.inputSchema).jsonSchema
|
518
518
|
};
|
519
|
-
case "provider-defined":
|
519
|
+
case "provider-defined-client":
|
520
520
|
return {
|
521
|
-
type: "provider-defined",
|
521
|
+
type: "provider-defined-client",
|
522
|
+
name: name5,
|
523
|
+
id: tool.id,
|
524
|
+
args: tool.args
|
525
|
+
};
|
526
|
+
case "provider-defined-server":
|
527
|
+
return {
|
528
|
+
type: "provider-defined-server",
|
522
529
|
name: name5,
|
523
530
|
id: tool.id,
|
524
531
|
args: tool.args
|
@@ -607,14 +614,14 @@ var toolCallPartSchema = import_zod5.z.object({
|
|
607
614
|
type: import_zod5.z.literal("tool-call"),
|
608
615
|
toolCallId: import_zod5.z.string(),
|
609
616
|
toolName: import_zod5.z.string(),
|
610
|
-
|
617
|
+
input: import_zod5.z.unknown(),
|
611
618
|
providerOptions: providerMetadataSchema.optional()
|
612
619
|
});
|
613
620
|
var toolResultPartSchema = import_zod5.z.object({
|
614
621
|
type: import_zod5.z.literal("tool-result"),
|
615
622
|
toolCallId: import_zod5.z.string(),
|
616
623
|
toolName: import_zod5.z.string(),
|
617
|
-
|
624
|
+
output: import_zod5.z.unknown(),
|
618
625
|
content: toolResultContentSchema.optional(),
|
619
626
|
isError: import_zod5.z.boolean().optional(),
|
620
627
|
providerOptions: providerMetadataSchema.optional()
|