ai 6.0.0-beta.142 → 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 +9 -0
- package/dist/index.d.mts +56 -13
- package/dist/index.d.ts +56 -13
- package/dist/index.js +11 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
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
|
+
|
|
3
12
|
## 6.0.0-beta.142
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1051,31 +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
|
-
@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
|
-
|
|
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
|
+
*/
|
|
1066
1066
|
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
1067
|
+
/**
|
|
1068
|
+
* The steps that have been executed so far.
|
|
1069
|
+
*/
|
|
1067
1070
|
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
|
1071
|
+
/**
|
|
1072
|
+
* The number of the step that is being executed.
|
|
1073
|
+
*/
|
|
1068
1074
|
stepNumber: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* The model instance that is being used for this step.
|
|
1077
|
+
*/
|
|
1069
1078
|
model: LanguageModel;
|
|
1079
|
+
/**
|
|
1080
|
+
* The messages that will be sent to the model for the current step.
|
|
1081
|
+
*/
|
|
1070
1082
|
messages: Array<ModelMessage>;
|
|
1071
|
-
|
|
1083
|
+
/**
|
|
1084
|
+
* The context passed via the experimental_context setting (experimental).
|
|
1085
|
+
*/
|
|
1086
|
+
experimental_context: unknown;
|
|
1072
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
|
+
*/
|
|
1073
1092
|
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
1093
|
+
/**
|
|
1094
|
+
* Optionally override which LanguageModel instance is used for this step.
|
|
1095
|
+
*/
|
|
1074
1096
|
model?: LanguageModel;
|
|
1097
|
+
/**
|
|
1098
|
+
* Optionally set which tool the model must call, or provide tool call configuration
|
|
1099
|
+
* for this step.
|
|
1100
|
+
*/
|
|
1075
1101
|
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
1102
|
+
/**
|
|
1103
|
+
* If provided, only these tools are enabled/available for this step.
|
|
1104
|
+
*/
|
|
1076
1105
|
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Optionally override the system message(s) sent to the model for this step.
|
|
1108
|
+
*/
|
|
1077
1109
|
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Optionally override the full set of messages sent to the model
|
|
1112
|
+
* for this step.
|
|
1113
|
+
*/
|
|
1078
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;
|
|
1079
1122
|
} | undefined;
|
|
1080
1123
|
|
|
1081
1124
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1051,31 +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
|
-
@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
|
-
|
|
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
|
+
*/
|
|
1066
1066
|
type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
1067
|
+
/**
|
|
1068
|
+
* The steps that have been executed so far.
|
|
1069
|
+
*/
|
|
1067
1070
|
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
|
1071
|
+
/**
|
|
1072
|
+
* The number of the step that is being executed.
|
|
1073
|
+
*/
|
|
1068
1074
|
stepNumber: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* The model instance that is being used for this step.
|
|
1077
|
+
*/
|
|
1069
1078
|
model: LanguageModel;
|
|
1079
|
+
/**
|
|
1080
|
+
* The messages that will be sent to the model for the current step.
|
|
1081
|
+
*/
|
|
1070
1082
|
messages: Array<ModelMessage>;
|
|
1071
|
-
|
|
1083
|
+
/**
|
|
1084
|
+
* The context passed via the experimental_context setting (experimental).
|
|
1085
|
+
*/
|
|
1086
|
+
experimental_context: unknown;
|
|
1072
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
|
+
*/
|
|
1073
1092
|
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
1093
|
+
/**
|
|
1094
|
+
* Optionally override which LanguageModel instance is used for this step.
|
|
1095
|
+
*/
|
|
1074
1096
|
model?: LanguageModel;
|
|
1097
|
+
/**
|
|
1098
|
+
* Optionally set which tool the model must call, or provide tool call configuration
|
|
1099
|
+
* for this step.
|
|
1100
|
+
*/
|
|
1075
1101
|
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
|
1102
|
+
/**
|
|
1103
|
+
* If provided, only these tools are enabled/available for this step.
|
|
1104
|
+
*/
|
|
1076
1105
|
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Optionally override the system message(s) sent to the model for this step.
|
|
1108
|
+
*/
|
|
1077
1109
|
system?: string | SystemModelMessage | Array<SystemModelMessage>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Optionally override the full set of messages sent to the model
|
|
1112
|
+
* for this step.
|
|
1113
|
+
*/
|
|
1078
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;
|
|
1079
1122
|
} | undefined;
|
|
1080
1123
|
|
|
1081
1124
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
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 });
|
|
@@ -3563,10 +3563,11 @@ async function generateText({
|
|
|
3563
3563
|
supportedUrls: await stepModel.supportedUrls,
|
|
3564
3564
|
download: download2
|
|
3565
3565
|
});
|
|
3566
|
+
experimental_context = (_d = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _d : experimental_context;
|
|
3566
3567
|
const { toolChoice: stepToolChoice, tools: stepTools } = await prepareToolsAndToolChoice({
|
|
3567
3568
|
tools,
|
|
3568
|
-
toolChoice: (
|
|
3569
|
-
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
|
|
3570
3571
|
});
|
|
3571
3572
|
currentModelResponse = await retry(
|
|
3572
3573
|
() => {
|
|
@@ -3609,7 +3610,7 @@ async function generateText({
|
|
|
3609
3610
|
}),
|
|
3610
3611
|
tracer,
|
|
3611
3612
|
fn: async (span2) => {
|
|
3612
|
-
var _a17, _b2, _c2, _d2, _e2, _f2, _g2,
|
|
3613
|
+
var _a17, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
3613
3614
|
const result = await stepModel.doGenerate({
|
|
3614
3615
|
...callSettings2,
|
|
3615
3616
|
tools: stepTools,
|
|
@@ -3625,7 +3626,7 @@ async function generateText({
|
|
|
3625
3626
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
|
3626
3627
|
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
3627
3628
|
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
3628
|
-
body: (
|
|
3629
|
+
body: (_h2 = result.response) == null ? void 0 : _h2.body
|
|
3629
3630
|
};
|
|
3630
3631
|
span2.setAttributes(
|
|
3631
3632
|
await selectTelemetryAttributes({
|
|
@@ -3758,7 +3759,7 @@ async function generateText({
|
|
|
3758
3759
|
usage: asLanguageModelUsage(currentModelResponse.usage),
|
|
3759
3760
|
warnings: currentModelResponse.warnings,
|
|
3760
3761
|
providerMetadata: currentModelResponse.providerMetadata,
|
|
3761
|
-
request: (
|
|
3762
|
+
request: (_g = currentModelResponse.request) != null ? _g : {},
|
|
3762
3763
|
response: {
|
|
3763
3764
|
...currentModelResponse.response,
|
|
3764
3765
|
// deep clone msgs to avoid mutating past messages in multi-step:
|
|
@@ -3766,7 +3767,7 @@ async function generateText({
|
|
|
3766
3767
|
}
|
|
3767
3768
|
});
|
|
3768
3769
|
logWarnings({
|
|
3769
|
-
warnings: (
|
|
3770
|
+
warnings: (_h = currentModelResponse.warnings) != null ? _h : [],
|
|
3770
3771
|
provider: stepModel.provider,
|
|
3771
3772
|
model: stepModel.modelId
|
|
3772
3773
|
});
|
|
@@ -5936,7 +5937,7 @@ var DefaultStreamTextResult = class {
|
|
|
5936
5937
|
responseMessages,
|
|
5937
5938
|
usage
|
|
5938
5939
|
}) {
|
|
5939
|
-
var _a15, _b, _c, _d, _e;
|
|
5940
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
5940
5941
|
const includeRawChunks2 = self.includeRawChunks;
|
|
5941
5942
|
stepFinish = new import_provider_utils17.DelayedPromise();
|
|
5942
5943
|
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
@@ -5963,6 +5964,7 @@ var DefaultStreamTextResult = class {
|
|
|
5963
5964
|
toolChoice: (_d = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _d : toolChoice,
|
|
5964
5965
|
activeTools: (_e = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _e : activeTools
|
|
5965
5966
|
});
|
|
5967
|
+
experimental_context = (_f = prepareStepResult == null ? void 0 : prepareStepResult.experimental_context) != null ? _f : experimental_context;
|
|
5966
5968
|
const {
|
|
5967
5969
|
result: { stream: stream2, response, request },
|
|
5968
5970
|
doStreamSpan,
|