ai 6.0.0-beta.141 → 6.0.0-beta.143
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.d.mts +67 -13
- package/dist/index.d.ts +67 -13
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.0-beta.143
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 81e29ab: feat(ai): allow modifying experimental context in prepareStep
|
|
8
|
+
- Updated dependencies [81e29ab]
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.0-beta.46
|
|
10
|
+
- @ai-sdk/gateway@2.0.0-beta.75
|
|
11
|
+
|
|
12
|
+
## 6.0.0-beta.142
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 7169511: feat(agent): support context in onFinish callback
|
|
17
|
+
- bbdcb81: Add experimental_context parameter to prepareStep callback
|
|
18
|
+
|
|
3
19
|
## 6.0.0-beta.141
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1051,28 +1051,74 @@ type DownloadFunction = (options: Array<{
|
|
|
1051
1051
|
} | null>>;
|
|
1052
1052
|
|
|
1053
1053
|
/**
|
|
1054
|
-
Function that you can use to provide different settings for a step.
|
|
1055
|
-
|
|
1056
|
-
@param options - The options for the step.
|
|
1057
|
-
@param options.steps - The steps that have been executed so far.
|
|
1058
|
-
@param options.stepNumber - The number of the step that is being executed.
|
|
1059
|
-
@param options.model - The model that is being used.
|
|
1060
|
-
|
|
1061
|
-
@
|
|
1062
|
-
|
|
1063
|
-
|
|
1054
|
+
* Function that you can use to provide different settings for a step.
|
|
1055
|
+
*
|
|
1056
|
+
* @param options - The options for the step.
|
|
1057
|
+
* @param options.steps - The steps that have been executed so far.
|
|
1058
|
+
* @param options.stepNumber - The number of the step that is being executed.
|
|
1059
|
+
* @param options.model - The model that is being used.
|
|
1060
|
+
* @param options.messages - The messages that will be sent to the model for the current step.
|
|
1061
|
+
* @param options.experimental_context - The context passed via the experimental_context setting (experimental).
|
|
1062
|
+
*
|
|
1063
|
+
* @returns An object that contains the settings for the step.
|
|
1064
|
+
* If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
1065
|
+
*/
|
|
1064
1066
|
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
1067
|
+
/**
|
|
1068
|
+
* The steps that have been executed so far.
|
|
1069
|
+
*/
|
|
1065
1070
|
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
|
1071
|
+
/**
|
|
1072
|
+
* The number of the step that is being executed.
|
|
1073
|
+
*/
|
|
1066
1074
|
stepNumber: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* The model instance that is being used for this step.
|
|
1077
|
+
*/
|
|
1067
1078
|
model: LanguageModel;
|
|
1079
|
+
/**
|
|
1080
|
+
* The messages that will be sent to the model for the current step.
|
|
1081
|
+
*/
|
|
1068
1082
|
messages: Array<ModelMessage>;
|
|
1083
|
+
/**
|
|
1084
|
+
* The context passed via the experimental_context setting (experimental).
|
|
1085
|
+
*/
|
|
1086
|
+
experimental_context: unknown;
|
|
1069
1087
|
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
|
1088
|
+
/**
|
|
1089
|
+
* The result type returned by a {@link PrepareStepFunction},
|
|
1090
|
+
* allowing per-step overrides of model, tools, or messages.
|
|
1091
|
+
*/
|
|
1070
1092
|
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
1093
|
+
/**
|
|
1094
|
+
* Optionally override which LanguageModel instance is used for this step.
|
|
1095
|
+
*/
|
|
1071
1096
|
model?: LanguageModel;
|
|
1097
|
+
/**
|
|
1098
|
+
* Optionally set which tool the model must call, or provide tool call configuration
|
|
1099
|
+
* for this step.
|
|
1100
|
+
*/
|
|
1072
1101
|
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
1102
|
+
/**
|
|
1103
|
+
* If provided, only these tools are enabled/available for this step.
|
|
1104
|
+
*/
|
|
1073
1105
|
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Optionally override the system message(s) sent to the model for this step.
|
|
1108
|
+
*/
|
|
1074
1109
|
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Optionally override the full set of messages sent to the model
|
|
1112
|
+
* for this step.
|
|
1113
|
+
*/
|
|
1075
1114
|
messages?: Array<ModelMessage>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Context that is passed into tool execution. Experimental.
|
|
1117
|
+
*
|
|
1118
|
+
* Changing the context will affect the context in this step
|
|
1119
|
+
* and all subsequent steps.
|
|
1120
|
+
*/
|
|
1121
|
+
experimental_context?: unknown;
|
|
1076
1122
|
} | undefined;
|
|
1077
1123
|
|
|
1078
1124
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
@@ -2682,13 +2728,21 @@ Callback that is set using the `onFinish` option.
|
|
|
2682
2728
|
*/
|
|
2683
2729
|
type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: StepResult<TOOLS> & {
|
|
2684
2730
|
/**
|
|
2685
|
-
Details for all steps.
|
|
2686
|
-
|
|
2731
|
+
* Details for all steps.
|
|
2732
|
+
*/
|
|
2687
2733
|
readonly steps: StepResult<TOOLS>[];
|
|
2688
2734
|
/**
|
|
2689
|
-
Total usage for all steps. This is the sum of the usage of all steps.
|
|
2735
|
+
* Total usage for all steps. This is the sum of the usage of all steps.
|
|
2690
2736
|
*/
|
|
2691
2737
|
readonly totalUsage: LanguageModelUsage;
|
|
2738
|
+
/**
|
|
2739
|
+
* Context that is passed into tool calls.
|
|
2740
|
+
*
|
|
2741
|
+
* Experimental (can break in patch releases).
|
|
2742
|
+
*
|
|
2743
|
+
* @default undefined
|
|
2744
|
+
*/
|
|
2745
|
+
experimental_context?: unknown;
|
|
2692
2746
|
}) => PromiseLike<void> | void;
|
|
2693
2747
|
|
|
2694
2748
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1051,28 +1051,74 @@ type DownloadFunction = (options: Array<{
|
|
|
1051
1051
|
} | null>>;
|
|
1052
1052
|
|
|
1053
1053
|
/**
|
|
1054
|
-
Function that you can use to provide different settings for a step.
|
|
1055
|
-
|
|
1056
|
-
@param options - The options for the step.
|
|
1057
|
-
@param options.steps - The steps that have been executed so far.
|
|
1058
|
-
@param options.stepNumber - The number of the step that is being executed.
|
|
1059
|
-
@param options.model - The model that is being used.
|
|
1060
|
-
|
|
1061
|
-
@
|
|
1062
|
-
|
|
1063
|
-
|
|
1054
|
+
* Function that you can use to provide different settings for a step.
|
|
1055
|
+
*
|
|
1056
|
+
* @param options - The options for the step.
|
|
1057
|
+
* @param options.steps - The steps that have been executed so far.
|
|
1058
|
+
* @param options.stepNumber - The number of the step that is being executed.
|
|
1059
|
+
* @param options.model - The model that is being used.
|
|
1060
|
+
* @param options.messages - The messages that will be sent to the model for the current step.
|
|
1061
|
+
* @param options.experimental_context - The context passed via the experimental_context setting (experimental).
|
|
1062
|
+
*
|
|
1063
|
+
* @returns An object that contains the settings for the step.
|
|
1064
|
+
* If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
|
1065
|
+
*/
|
|
1064
1066
|
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
1067
|
+
/**
|
|
1068
|
+
* The steps that have been executed so far.
|
|
1069
|
+
*/
|
|
1065
1070
|
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
|
1071
|
+
/**
|
|
1072
|
+
* The number of the step that is being executed.
|
|
1073
|
+
*/
|
|
1066
1074
|
stepNumber: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* The model instance that is being used for this step.
|
|
1077
|
+
*/
|
|
1067
1078
|
model: LanguageModel;
|
|
1079
|
+
/**
|
|
1080
|
+
* The messages that will be sent to the model for the current step.
|
|
1081
|
+
*/
|
|
1068
1082
|
messages: Array<ModelMessage>;
|
|
1083
|
+
/**
|
|
1084
|
+
* The context passed via the experimental_context setting (experimental).
|
|
1085
|
+
*/
|
|
1086
|
+
experimental_context: unknown;
|
|
1069
1087
|
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
|
1088
|
+
/**
|
|
1089
|
+
* The result type returned by a {@link PrepareStepFunction},
|
|
1090
|
+
* allowing per-step overrides of model, tools, or messages.
|
|
1091
|
+
*/
|
|
1070
1092
|
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
1093
|
+
/**
|
|
1094
|
+
* Optionally override which LanguageModel instance is used for this step.
|
|
1095
|
+
*/
|
|
1071
1096
|
model?: LanguageModel;
|
|
1097
|
+
/**
|
|
1098
|
+
* Optionally set which tool the model must call, or provide tool call configuration
|
|
1099
|
+
* for this step.
|
|
1100
|
+
*/
|
|
1072
1101
|
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
1102
|
+
/**
|
|
1103
|
+
* If provided, only these tools are enabled/available for this step.
|
|
1104
|
+
*/
|
|
1073
1105
|
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Optionally override the system message(s) sent to the model for this step.
|
|
1108
|
+
*/
|
|
1074
1109
|
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Optionally override the full set of messages sent to the model
|
|
1112
|
+
* for this step.
|
|
1113
|
+
*/
|
|
1075
1114
|
messages?: Array<ModelMessage>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Context that is passed into tool execution. Experimental.
|
|
1117
|
+
*
|
|
1118
|
+
* Changing the context will affect the context in this step
|
|
1119
|
+
* and all subsequent steps.
|
|
1120
|
+
*/
|
|
1121
|
+
experimental_context?: unknown;
|
|
1076
1122
|
} | undefined;
|
|
1077
1123
|
|
|
1078
1124
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
|
@@ -2682,13 +2728,21 @@ Callback that is set using the `onFinish` option.
|
|
|
2682
2728
|
*/
|
|
2683
2729
|
type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: StepResult<TOOLS> & {
|
|
2684
2730
|
/**
|
|
2685
|
-
Details for all steps.
|
|
2686
|
-
|
|
2731
|
+
* Details for all steps.
|
|
2732
|
+
*/
|
|
2687
2733
|
readonly steps: StepResult<TOOLS>[];
|
|
2688
2734
|
/**
|
|
2689
|
-
Total usage for all steps. This is the sum of the usage of all steps.
|
|
2735
|
+
* Total usage for all steps. This is the sum of the usage of all steps.
|
|
2690
2736
|
*/
|
|
2691
2737
|
readonly totalUsage: LanguageModelUsage;
|
|
2738
|
+
/**
|
|
2739
|
+
* Context that is passed into tool calls.
|
|
2740
|
+
*
|
|
2741
|
+
* Experimental (can break in patch releases).
|
|
2742
|
+
*
|
|
2743
|
+
* @default undefined
|
|
2744
|
+
*/
|
|
2745
|
+
experimental_context?: unknown;
|
|
2692
2746
|
}) => PromiseLike<void> | void;
|
|
2693
2747
|
|
|
2694
2748
|
/**
|
package/dist/index.js
CHANGED
|
@@ -962,7 +962,7 @@ function detectMediaType({
|
|
|
962
962
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
963
963
|
|
|
964
964
|
// src/version.ts
|
|
965
|
-
var VERSION = true ? "6.0.0-beta.
|
|
965
|
+
var VERSION = true ? "6.0.0-beta.143" : "0.0.0-test";
|
|
966
966
|
|
|
967
967
|
// src/util/download/download.ts
|
|
968
968
|
var download = async ({ url }) => {
|
|
@@ -3495,7 +3495,7 @@ async function generateText({
|
|
|
3495
3495
|
}),
|
|
3496
3496
|
tracer,
|
|
3497
3497
|
fn: async (span) => {
|
|
3498
|
-
var _a15, _b, _c, _d, _e, _f, _g;
|
|
3498
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h;
|
|
3499
3499
|
const initialMessages = initialPrompt.messages;
|
|
3500
3500
|
const responseMessages = [];
|
|
3501
3501
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
@@ -3549,7 +3549,8 @@ async function generateText({
|
|
|
3549
3549
|
model,
|
|
3550
3550
|
steps,
|
|
3551
3551
|
stepNumber: steps.length,
|
|
3552
|
-
messages: stepInputMessages
|
|
3552
|
+
messages: stepInputMessages,
|
|
3553
|
+
experimental_context
|
|
3553
3554
|
}));
|
|
3554
3555
|
const stepModel = resolveLanguageModel(
|
|
3555
3556
|
(_a15 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a15 : model
|
|
@@ -3562,10 +3563,11 @@ async function generateText({
|
|
|
3562
3563
|
supportedUrls: await stepModel.supportedUrls,
|
|
3563
3564
|
download: download2
|
|
3564
3565
|
});
|
|
3566
|
+
experimental_context = (_d = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _d : experimental_context;
|
|
3565
3567
|
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
3566
3568
|
tools,
|
|
3567
|
-
toolChoice: (
|
|
3568
|
-
activeTools: (
|
|
3569
|
+
toolChoice: (_e = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _e : toolChoice,
|
|
3570
|
+
activeTools: (_f = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _f : activeTools
|
|
3569
3571
|
});
|
|
3570
3572
|
currentModelResponse = await retry(
|
|
3571
3573
|
() => {
|
|
@@ -3608,7 +3610,7 @@ async function generateText({
|
|
|
3608
3610
|
}),
|
|
3609
3611
|
tracer,
|
|
3610
3612
|
fn: async (span2) => {
|
|
3611
|
-
var _a17, _b2, _c2, _d2, _e2, _f2, _g2,
|
|
3613
|
+
var _a17, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
3612
3614
|
const result = await stepModel.doGenerate({
|
|
3613
3615
|
...callSettings2,
|
|
3614
3616
|
tools: stepTools,
|
|
@@ -3624,7 +3626,7 @@ async function generateText({
|
|
|
3624
3626
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
|
3625
3627
|
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
3626
3628
|
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
3627
|
-
body: (
|
|
3629
|
+
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
3628
3630
|
};
|
|
3629
3631
|
span2.setAttributes(
|
|
3630
3632
|
await selectTelemetryAttributes({
|
|
@@ -3757,7 +3759,7 @@ async function generateText({
|
|
|
3757
3759
|
usage: asLanguageModelUsage(currentModelResponse.usage),
|
|
3758
3760
|
warnings: currentModelResponse.warnings,
|
|
3759
3761
|
providerMetadata: currentModelResponse.providerMetadata,
|
|
3760
|
-
request: (
|
|
3762
|
+
request: (_g = currentModelResponse.request) != null ? _g : {},
|
|
3761
3763
|
response: {
|
|
3762
3764
|
...currentModelResponse.response,
|
|
3763
3765
|
// deep clone msgs to avoid mutating past messages in multi-step:
|
|
@@ -3765,7 +3767,7 @@ async function generateText({
|
|
|
3765
3767
|
}
|
|
3766
3768
|
});
|
|
3767
3769
|
logWarnings({
|
|
3768
|
-
warnings: (
|
|
3770
|
+
warnings: (_h = currentModelResponse.warnings) != null ? _h : [],
|
|
3769
3771
|
provider: stepModel.provider,
|
|
3770
3772
|
model: stepModel.modelId
|
|
3771
3773
|
});
|
|
@@ -5935,7 +5937,7 @@ var DefaultStreamTextResult = class {
|
|
|
5935
5937
|
responseMessages,
|
|
5936
5938
|
usage
|
|
5937
5939
|
}) {
|
|
5938
|
-
var _a15, _b, _c, _d, _e;
|
|
5940
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
5939
5941
|
const includeRawChunks2 = self.includeRawChunks;
|
|
5940
5942
|
stepFinish = new import_provider_utils17.DelayedPromise();
|
|
5941
5943
|
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
@@ -5943,7 +5945,8 @@ var DefaultStreamTextResult = class {
|
|
|
5943
5945
|
model,
|
|
5944
5946
|
steps: recordedSteps,
|
|
5945
5947
|
stepNumber: recordedSteps.length,
|
|
5946
|
-
messages: stepInputMessages
|
|
5948
|
+
messages: stepInputMessages,
|
|
5949
|
+
experimental_context
|
|
5947
5950
|
}));
|
|
5948
5951
|
const stepModel = resolveLanguageModel(
|
|
5949
5952
|
(_a15 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a15 : model
|
|
@@ -5961,6 +5964,7 @@ var DefaultStreamTextResult = class {
|
|
|
5961
5964
|
toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
|
|
5962
5965
|
activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
|
|
5963
5966
|
});
|
|
5967
|
+
experimental_context = (_f = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _f : experimental_context;
|
|
5964
5968
|
const {
|
|
5965
5969
|
result: { stream: stream2, response, request },
|
|
5966
5970
|
doStreamSpan,
|