ai 5.0.2 → 5.0.4

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,23 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [444df49]
8
+ - @ai-sdk/gateway@1.0.2
9
+
10
+ ## 5.0.3
11
+
12
+ ### Patch Changes
13
+
14
+ - 90d212f: feat (ai): add experimental tool call context
15
+ - Updated dependencies [028fb9c]
16
+ - Updated dependencies [90d212f]
17
+ - Updated dependencies [6331826]
18
+ - @ai-sdk/gateway@1.0.1
19
+ - @ai-sdk/provider-utils@3.0.1
20
+
3
21
  ## 5.0.2
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -952,7 +952,7 @@ If set and supported by the model, calls will generate deterministic results.
952
952
  @returns
953
953
  A result object that contains the generated text, the results of the tool calls, and additional information.
954
954
  */
955
- declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
955
+ declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, experimental_context, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
956
956
  /**
957
957
  The language model to use.
958
958
  */
@@ -1011,6 +1011,14 @@ A function that attempts to repair a tool call that failed to parse.
1011
1011
  Callback that is called when each step (LLM call) is finished, including intermediate steps.
1012
1012
  */
1013
1013
  onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
1014
+ /**
1015
+ * Context that is passed into tool execution.
1016
+ *
1017
+ * Experimental (can break in patch releases).
1018
+ *
1019
+ * @default undefined
1020
+ */
1021
+ experimental_context?: unknown;
1014
1022
  /**
1015
1023
  * Internal. For test use only. May change without notice.
1016
1024
  */
@@ -1157,7 +1165,7 @@ If set and supported by the model, calls will generate deterministic results.
1157
1165
  @return
1158
1166
  A result object for accessing different stream types and additional information.
1159
1167
  */
1160
- declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1168
+ declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1161
1169
  /**
1162
1170
  The language model to use.
1163
1171
  */
@@ -1253,6 +1261,14 @@ Callback that is called when each step (LLM call) is finished, including interme
1253
1261
  */
1254
1262
  onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
1255
1263
  /**
1264
+ * Context that is passed into tool execution.
1265
+ *
1266
+ * Experimental (can break in patch releases).
1267
+ *
1268
+ * @default undefined
1269
+ */
1270
+ experimental_context?: unknown;
1271
+ /**
1256
1272
  Internal. For test use only. May change without notice.
1257
1273
  */
1258
1274
  _internal?: {
@@ -2013,6 +2029,14 @@ type AgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never
2013
2029
  Callback that is called when each step (LLM call) is finished, including intermediate steps.
2014
2030
  */
2015
2031
  onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
2032
+ /**
2033
+ * Context that is passed into tool calls.
2034
+ *
2035
+ * Experimental (can break in patch releases).
2036
+ *
2037
+ * @default undefined
2038
+ */
2039
+ experimental_context?: unknown;
2016
2040
  /**
2017
2041
  * Internal. For test use only. May change without notice.
2018
2042
  */
package/dist/index.d.ts CHANGED
@@ -952,7 +952,7 @@ If set and supported by the model, calls will generate deterministic results.
952
952
  @returns
953
953
  A result object that contains the generated text, the results of the tool calls, and additional information.
954
954
  */
955
- declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
955
+ declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, experimental_context, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
956
956
  /**
957
957
  The language model to use.
958
958
  */
@@ -1011,6 +1011,14 @@ A function that attempts to repair a tool call that failed to parse.
1011
1011
  Callback that is called when each step (LLM call) is finished, including intermediate steps.
1012
1012
  */
1013
1013
  onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
1014
+ /**
1015
+ * Context that is passed into tool execution.
1016
+ *
1017
+ * Experimental (can break in patch releases).
1018
+ *
1019
+ * @default undefined
1020
+ */
1021
+ experimental_context?: unknown;
1014
1022
  /**
1015
1023
  * Internal. For test use only. May change without notice.
1016
1024
  */
@@ -1157,7 +1165,7 @@ If set and supported by the model, calls will generate deterministic results.
1157
1165
  @return
1158
1166
  A result object for accessing different stream types and additional information.
1159
1167
  */
1160
- declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1168
+ declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, includeRawChunks, onChunk, onError, onFinish, onAbort, onStepFinish, experimental_context, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
1161
1169
  /**
1162
1170
  The language model to use.
1163
1171
  */
@@ -1253,6 +1261,14 @@ Callback that is called when each step (LLM call) is finished, including interme
1253
1261
  */
1254
1262
  onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
1255
1263
  /**
1264
+ * Context that is passed into tool execution.
1265
+ *
1266
+ * Experimental (can break in patch releases).
1267
+ *
1268
+ * @default undefined
1269
+ */
1270
+ experimental_context?: unknown;
1271
+ /**
1256
1272
  Internal. For test use only. May change without notice.
1257
1273
  */
1258
1274
  _internal?: {
@@ -2013,6 +2029,14 @@ type AgentSettings<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never
2013
2029
  Callback that is called when each step (LLM call) is finished, including intermediate steps.
2014
2030
  */
2015
2031
  onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
2032
+ /**
2033
+ * Context that is passed into tool calls.
2034
+ *
2035
+ * Experimental (can break in patch releases).
2036
+ *
2037
+ * @default undefined
2038
+ */
2039
+ experimental_context?: unknown;
2016
2040
  /**
2017
2041
  * Internal. For test use only. May change without notice.
2018
2042
  */
package/dist/index.js CHANGED
@@ -2038,6 +2038,7 @@ async function generateText({
2038
2038
  experimental_prepareStep,
2039
2039
  prepareStep = experimental_prepareStep,
2040
2040
  experimental_repairToolCall: repairToolCall,
2041
+ experimental_context,
2041
2042
  _internal: {
2042
2043
  generateId: generateId3 = originalGenerateId,
2043
2044
  currentDate = () => /* @__PURE__ */ new Date()
@@ -2235,7 +2236,8 @@ async function generateText({
2235
2236
  input: toolCall.input,
2236
2237
  toolCallId: toolCall.toolCallId,
2237
2238
  messages: stepInputMessages,
2238
- abortSignal
2239
+ abortSignal,
2240
+ experimental_context
2239
2241
  });
2240
2242
  }
2241
2243
  }
@@ -2248,7 +2250,8 @@ async function generateText({
2248
2250
  tracer,
2249
2251
  telemetry,
2250
2252
  messages: stepInputMessages,
2251
- abortSignal
2253
+ abortSignal,
2254
+ experimental_context
2252
2255
  });
2253
2256
  const stepContent = asContent({
2254
2257
  content: currentModelResponse.content,
@@ -2329,7 +2332,8 @@ async function executeTools({
2329
2332
  tracer,
2330
2333
  telemetry,
2331
2334
  messages,
2332
- abortSignal
2335
+ abortSignal,
2336
+ experimental_context
2333
2337
  }) {
2334
2338
  const toolOutputs = await Promise.all(
2335
2339
  toolCalls.map(async ({ toolCallId, toolName, input }) => {
@@ -2359,7 +2363,8 @@ async function executeTools({
2359
2363
  const output = await tool3.execute(input, {
2360
2364
  toolCallId,
2361
2365
  messages,
2362
- abortSignal
2366
+ abortSignal,
2367
+ experimental_context
2363
2368
  });
2364
2369
  try {
2365
2370
  span.setAttributes(
@@ -3923,7 +3928,8 @@ function runToolsTransformation({
3923
3928
  system,
3924
3929
  messages,
3925
3930
  abortSignal,
3926
- repairToolCall
3931
+ repairToolCall,
3932
+ experimental_context
3927
3933
  }) {
3928
3934
  let toolResultsStreamController = null;
3929
3935
  const toolResultsStream = new ReadableStream({
@@ -4000,7 +4006,8 @@ function runToolsTransformation({
4000
4006
  input: toolCall.input,
4001
4007
  toolCallId: toolCall.toolCallId,
4002
4008
  messages,
4003
- abortSignal
4009
+ abortSignal,
4010
+ experimental_context
4004
4011
  });
4005
4012
  }
4006
4013
  if (tool3.execute != null && toolCall.providerExecuted !== true) {
@@ -4029,7 +4036,8 @@ function runToolsTransformation({
4029
4036
  output = await tool3.execute(toolCall.input, {
4030
4037
  toolCallId: toolCall.toolCallId,
4031
4038
  messages,
4032
- abortSignal
4039
+ abortSignal,
4040
+ experimental_context
4033
4041
  });
4034
4042
  } catch (error) {
4035
4043
  recordErrorOnSpan(span, error);
@@ -4163,6 +4171,7 @@ function streamText({
4163
4171
  onFinish,
4164
4172
  onAbort,
4165
4173
  onStepFinish,
4174
+ experimental_context,
4166
4175
  _internal: {
4167
4176
  now: now2 = now,
4168
4177
  generateId: generateId3 = originalGenerateId2,
@@ -4197,7 +4206,8 @@ function streamText({
4197
4206
  onStepFinish,
4198
4207
  now: now2,
4199
4208
  currentDate,
4200
- generateId: generateId3
4209
+ generateId: generateId3,
4210
+ experimental_context
4201
4211
  });
4202
4212
  }
4203
4213
  function createOutputTransformStream(output) {
@@ -4293,7 +4303,8 @@ var DefaultStreamTextResult = class {
4293
4303
  onError,
4294
4304
  onFinish,
4295
4305
  onAbort,
4296
- onStepFinish
4306
+ onStepFinish,
4307
+ experimental_context
4297
4308
  }) {
4298
4309
  this._totalUsage = new DelayedPromise();
4299
4310
  this._finishReason = new DelayedPromise();
@@ -4672,7 +4683,8 @@ var DefaultStreamTextResult = class {
4672
4683
  system,
4673
4684
  messages: stepInputMessages,
4674
4685
  repairToolCall,
4675
- abortSignal
4686
+ abortSignal,
4687
+ experimental_context
4676
4688
  });
4677
4689
  const stepRequest = request != null ? request : {};
4678
4690
  const stepToolCalls = [];
@@ -4800,7 +4812,8 @@ var DefaultStreamTextResult = class {
4800
4812
  await tool3.onInputStart({
4801
4813
  toolCallId: chunk.id,
4802
4814
  messages: stepInputMessages,
4803
- abortSignal
4815
+ abortSignal,
4816
+ experimental_context
4804
4817
  });
4805
4818
  }
4806
4819
  controller.enqueue({
@@ -4822,7 +4835,8 @@ var DefaultStreamTextResult = class {
4822
4835
  inputTextDelta: chunk.delta,
4823
4836
  toolCallId: chunk.id,
4824
4837
  messages: stepInputMessages,
4825
- abortSignal
4838
+ abortSignal,
4839
+ experimental_context
4826
4840
  });
4827
4841
  }
4828
4842
  controller.enqueue(chunk);