ai 4.0.0 → 4.0.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # ai
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b117255: feat (ai/core): add messages to tool call options
8
+
3
9
  ## 4.0.0
4
10
 
5
11
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1203,6 +1203,14 @@ type CoreTool<PARAMETERS extends Parameters = any, RESULT = any> = {
1203
1203
  @options.abortSignal is a signal that can be used to abort the tool call.
1204
1204
  */
1205
1205
  execute?: (args: inferParameters<PARAMETERS>, options: {
1206
+ /**
1207
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
1208
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
1209
+ */
1210
+ messages: CoreMessage[];
1211
+ /**
1212
+ * An optional abort signal that indicates that the overall operation should be aborted.
1213
+ */
1206
1214
  abortSignal?: AbortSignal;
1207
1215
  }) => PromiseLike<RESULT>;
1208
1216
  } & ({
@@ -1233,10 +1241,12 @@ Helper function for inferring the execute args of a tool.
1233
1241
  */
1234
1242
  declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARAMETERS, RESULT> & {
1235
1243
  execute: (args: inferParameters<PARAMETERS>, options: {
1244
+ messages: CoreMessage[];
1236
1245
  abortSignal?: AbortSignal;
1237
1246
  }) => PromiseLike<RESULT>;
1238
1247
  }): CoreTool<PARAMETERS, RESULT> & {
1239
1248
  execute: (args: inferParameters<PARAMETERS>, options: {
1249
+ messages: CoreMessage[];
1240
1250
  abortSignal?: AbortSignal;
1241
1251
  }) => PromiseLike<RESULT>;
1242
1252
  };
package/dist/index.d.ts CHANGED
@@ -1203,6 +1203,14 @@ type CoreTool<PARAMETERS extends Parameters = any, RESULT = any> = {
1203
1203
  @options.abortSignal is a signal that can be used to abort the tool call.
1204
1204
  */
1205
1205
  execute?: (args: inferParameters<PARAMETERS>, options: {
1206
+ /**
1207
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
1208
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
1209
+ */
1210
+ messages: CoreMessage[];
1211
+ /**
1212
+ * An optional abort signal that indicates that the overall operation should be aborted.
1213
+ */
1206
1214
  abortSignal?: AbortSignal;
1207
1215
  }) => PromiseLike<RESULT>;
1208
1216
  } & ({
@@ -1233,10 +1241,12 @@ Helper function for inferring the execute args of a tool.
1233
1241
  */
1234
1242
  declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARAMETERS, RESULT> & {
1235
1243
  execute: (args: inferParameters<PARAMETERS>, options: {
1244
+ messages: CoreMessage[];
1236
1245
  abortSignal?: AbortSignal;
1237
1246
  }) => PromiseLike<RESULT>;
1238
1247
  }): CoreTool<PARAMETERS, RESULT> & {
1239
1248
  execute: (args: inferParameters<PARAMETERS>, options: {
1249
+ messages: CoreMessage[];
1240
1250
  abortSignal?: AbortSignal;
1241
1251
  }) => PromiseLike<RESULT>;
1242
1252
  };
package/dist/index.js CHANGED
@@ -3324,15 +3324,16 @@ async function generateText({
3324
3324
  };
3325
3325
  let stepType = "initial";
3326
3326
  do {
3327
- if (stepCount === 1) {
3328
- initialPrompt.type = "messages";
3329
- }
3330
3327
  const promptFormat = stepCount === 0 ? initialPrompt.type : "messages";
3328
+ const stepInputMessages = [
3329
+ ...initialPrompt.messages,
3330
+ ...responseMessages
3331
+ ];
3331
3332
  const promptMessages = await convertToLanguageModelPrompt({
3332
3333
  prompt: {
3333
3334
  type: promptFormat,
3334
3335
  system: initialPrompt.system,
3335
- messages: [...initialPrompt.messages, ...responseMessages]
3336
+ messages: stepInputMessages
3336
3337
  },
3337
3338
  modelSupportsImageUrls: model.supportsImageUrls,
3338
3339
  modelSupportsUrl: model.supportsUrl
@@ -3428,6 +3429,7 @@ async function generateText({
3428
3429
  tools,
3429
3430
  tracer,
3430
3431
  telemetry,
3432
+ messages: stepInputMessages,
3431
3433
  abortSignal
3432
3434
  });
3433
3435
  const currentUsage = calculateLanguageModelUsage(
@@ -3538,6 +3540,7 @@ async function executeTools({
3538
3540
  tools,
3539
3541
  tracer,
3540
3542
  telemetry,
3543
+ messages,
3541
3544
  abortSignal
3542
3545
  }) {
3543
3546
  const toolResults = await Promise.all(
@@ -3564,7 +3567,10 @@ async function executeTools({
3564
3567
  }),
3565
3568
  tracer,
3566
3569
  fn: async (span) => {
3567
- const result2 = await tool2.execute(toolCall.args, { abortSignal });
3570
+ const result2 = await tool2.execute(toolCall.args, {
3571
+ messages,
3572
+ abortSignal
3573
+ });
3568
3574
  try {
3569
3575
  span.setAttributes(
3570
3576
  selectTelemetryAttributes({
@@ -3709,6 +3715,7 @@ function runToolsTransformation({
3709
3715
  toolCallStreaming,
3710
3716
  tracer,
3711
3717
  telemetry,
3718
+ messages,
3712
3719
  abortSignal
3713
3720
  }) {
3714
3721
  let toolResultsStreamController = null;
@@ -3804,7 +3811,10 @@ function runToolsTransformation({
3804
3811
  }
3805
3812
  }),
3806
3813
  tracer,
3807
- fn: async (span) => tool2.execute(toolCall.args, { abortSignal }).then(
3814
+ fn: async (span) => tool2.execute(toolCall.args, {
3815
+ messages,
3816
+ abortSignal
3817
+ }).then(
3808
3818
  (result) => {
3809
3819
  toolResultsStreamController.enqueue({
3810
3820
  ...toolCall,
@@ -4030,11 +4040,15 @@ var DefaultStreamTextResult = class {
4030
4040
  hasLeadingWhitespace
4031
4041
  }) {
4032
4042
  const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
4043
+ const stepInputMessages = [
4044
+ ...initialPrompt.messages,
4045
+ ...responseMessages
4046
+ ];
4033
4047
  const promptMessages = await convertToLanguageModelPrompt({
4034
4048
  prompt: {
4035
4049
  type: promptFormat,
4036
4050
  system: initialPrompt.system,
4037
- messages: [...initialPrompt.messages, ...responseMessages]
4051
+ messages: stepInputMessages
4038
4052
  },
4039
4053
  modelSupportsImageUrls: model.supportsImageUrls,
4040
4054
  modelSupportsUrl: model.supportsUrl
@@ -4110,6 +4124,7 @@ var DefaultStreamTextResult = class {
4110
4124
  toolCallStreaming,
4111
4125
  tracer,
4112
4126
  telemetry,
4127
+ messages: stepInputMessages,
4113
4128
  abortSignal
4114
4129
  });
4115
4130
  const stepRequest = request != null ? request : {};