ai 7.0.171 → 7.0.173

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/index.d.ts +40 -30
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +54 -27
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +153 -55
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +53 -16
  9. package/dist/internal/index.js.map +1 -1
  10. package/docs/02-foundations/03-prompts.mdx +1 -1
  11. package/docs/03-agents/04-loop-control.mdx +1 -1
  12. package/docs/03-agents/06-tool-approvals.mdx +1 -1
  13. package/docs/03-agents/07-workflow-agent.mdx +187 -14
  14. package/docs/03-ai-sdk-core/05-generating-text.mdx +7 -2
  15. package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +4 -0
  16. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +3 -0
  17. package/docs/03-ai-sdk-core/26-reasoning.mdx +3 -3
  18. package/docs/03-ai-sdk-core/32-decisions.mdx +13 -2
  19. package/docs/03-ai-sdk-core/33-extractions.mdx +58 -0
  20. package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
  21. package/docs/03-ai-sdk-core/36-transcription.mdx +3 -0
  22. package/docs/03-ai-sdk-core/37-speech.mdx +3 -0
  23. package/docs/06-advanced/11-secure-url-fetching.mdx +10 -1
  24. package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +20 -15
  25. package/docs/07-reference/01-ai-sdk-core/14-extract.mdx +17 -12
  26. package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +6 -0
  27. package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +3 -0
  28. package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +115 -7
  29. package/package.json +11 -11
  30. package/src/agent/default-stop-condition.ts +28 -13
  31. package/src/decide/decide.ts +12 -1
  32. package/src/decide/decision-state.ts +29 -6
  33. package/src/extract/extract.ts +12 -1
  34. package/src/generate-text/validate-tool-approvals.ts +23 -19
package/dist/index.js CHANGED
@@ -1251,7 +1251,7 @@ function cloneValue(value, seen) {
1251
1251
  }
1252
1252
  //#endregion
1253
1253
  //#region src/version.ts
1254
- const VERSION = "7.0.171";
1254
+ const VERSION = "7.0.173";
1255
1255
  //#endregion
1256
1256
  //#region src/util/download/download.ts
1257
1257
  /**
@@ -5379,22 +5379,25 @@ async function validateApprovedToolApprovals({ approvedToolApprovals, tools, too
5379
5379
  });
5380
5380
  }
5381
5381
  if (isExecutableTool(tool) && tool.inputSchema != null) {
5382
- const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(approvalRequest, "inputSchemaInput");
5383
- const validation = await safeValidateTypes({
5384
- value: hasInputSchemaInput ? approvalRequest.inputSchemaInput : toolCall.input,
5385
- schema: asSchema$1(tool.inputSchema)
5386
- });
5387
5382
  let validationError;
5388
- if (!validation.success) validationError = validation.error;
5389
- else try {
5390
- const revalidatedToolCall = await refineParsedToolCallInput({
5391
- toolCall: {
5392
- ...toolCall,
5393
- input: validation.value
5394
- },
5395
- refineToolInput
5383
+ try {
5384
+ const approvedInput = structuredClone(toolCall.input);
5385
+ const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(approvalRequest, "inputSchemaInput");
5386
+ const validation = await safeValidateTypes({
5387
+ value: structuredClone(hasInputSchemaInput ? approvalRequest.inputSchemaInput : toolCall.input),
5388
+ schema: asSchema$1(tool.inputSchema)
5396
5389
  });
5397
- if (!isDeepEqualData(structuredClone(revalidatedToolCall.input), structuredClone(toolCall.input))) validationError = /* @__PURE__ */ new Error("Approved tool input does not match the validated schema output.");
5390
+ if (!validation.success) validationError = validation.error;
5391
+ else {
5392
+ const revalidatedToolCall = await refineParsedToolCallInput({
5393
+ toolCall: {
5394
+ ...toolCall,
5395
+ input: validation.value
5396
+ },
5397
+ refineToolInput
5398
+ });
5399
+ if (!isDeepEqualData(structuredClone(revalidatedToolCall.input), approvedInput)) validationError = /* @__PURE__ */ new Error("Approved tool input does not match the validated schema output.");
5400
+ }
5398
5401
  } catch (error) {
5399
5402
  validationError = error;
5400
5403
  }
@@ -11171,6 +11174,19 @@ function isCausedByAbort(error) {
11171
11174
  //#endregion
11172
11175
  //#region src/agent/default-stop-condition.ts
11173
11176
  /**
11177
+ * Logs the warning for the default stopWhen condition.
11178
+ */
11179
+ function logDefaultStopConditionWarning({ stepCount, provider, modelId }) {
11180
+ logWarnings({
11181
+ provider,
11182
+ model: modelId,
11183
+ warnings: [{
11184
+ type: "other",
11185
+ message: `The tool loop stopped because it reached the default stopWhen condition, isStepCount(${stepCount}). To allow more steps, set stopWhen to isStepCount(...) with a higher limit or provide a custom stop condition. Learn more: https://ai-sdk.dev/docs/agents/loop-control`
11186
+ }]
11187
+ });
11188
+ }
11189
+ /**
11174
11190
  * Stop conditions are only evaluated when the tool loop can otherwise continue,
11175
11191
  * so logging here avoids warning when a call finishes naturally at the limit.
11176
11192
  */
@@ -11178,13 +11194,10 @@ function createDefaultStopCondition(stepCount) {
11178
11194
  return ({ steps }) => {
11179
11195
  if (steps.length !== stepCount) return false;
11180
11196
  const { provider, modelId } = steps[steps.length - 1].model;
11181
- logWarnings({
11197
+ logDefaultStopConditionWarning({
11198
+ stepCount,
11182
11199
  provider,
11183
- model: modelId,
11184
- warnings: [{
11185
- type: "other",
11186
- message: `The tool loop stopped because it reached the default stopWhen condition, isStepCount(${stepCount}). To allow more steps, set stopWhen to isStepCount(...) with a higher limit or provide a custom stop condition. Learn more: https://ai-sdk.dev/docs/agents/loop-control`
11187
- }]
11200
+ modelId
11188
11201
  });
11189
11202
  return true;
11190
11203
  };
@@ -13692,7 +13705,7 @@ var DefaultEmbedManyResult = class {
13692
13705
  function isDecisionStateParts(state) {
13693
13706
  return Array.isArray(state);
13694
13707
  }
13695
- async function prepareDecisionState(state, abortSignal) {
13708
+ async function prepareDecisionState({ state, abortSignal, download }) {
13696
13709
  if (typeof state === "string") return [{
13697
13710
  type: "text",
13698
13711
  text: state
@@ -13711,7 +13724,13 @@ async function prepareDecisionState(state, abortSignal) {
13711
13724
  }]
13712
13725
  },
13713
13726
  supportedUrls: {},
13714
- download: void 0,
13727
+ download: download ?? (async (requests) => {
13728
+ if (requests.length > 0) throw new DownloadError$1({
13729
+ url: requests[0].url.toString(),
13730
+ message: "URL file state requires experimental_download. For untrusted URLs, use createDownload({ fetch }) with a transport that validates DNS at connection time."
13731
+ });
13732
+ return [];
13733
+ }),
13715
13734
  abortSignal
13716
13735
  }))[0];
13717
13736
  if (message.role !== "user") throw new Error("Expected user message.");
@@ -13865,7 +13884,7 @@ const originalGenerateCallId$4 = createIdGenerator$1({
13865
13884
  size: 24
13866
13885
  });
13867
13886
  /** Decide answers to typed questions against one shared state. Experimental. */
13868
- async function decide({ model: modelArg, state, questions, maxOutputTokens, reasoning, maxRetries, abortSignal, headers, providerOptions = {}, telemetry, runtimeContext = {}, onStart, onEnd, _internal: { generateCallId = originalGenerateCallId$4 } = {} }) {
13887
+ async function decide({ model: modelArg, state, questions, maxOutputTokens, reasoning, maxRetries, abortSignal, experimental_download: download, headers, providerOptions = {}, telemetry, runtimeContext = {}, onStart, onEnd, _internal: { generateCallId = originalGenerateCallId$4 } = {} }) {
13869
13888
  const model = resolveDecisionModel(modelArg);
13870
13889
  prepareLanguageModelCallOptions({ maxOutputTokens });
13871
13890
  validateDecisionInput({
@@ -13908,7 +13927,11 @@ async function decide({ model: modelArg, state, questions, maxOutputTokens, reas
13908
13927
  callbacks: [onStart, telemetryDispatcher.onStart]
13909
13928
  });
13910
13929
  try {
13911
- const preparedState = await prepareDecisionState(state, abortSignal);
13930
+ const preparedState = await prepareDecisionState({
13931
+ state,
13932
+ abortSignal,
13933
+ download
13934
+ });
13912
13935
  const modelCallEvent = {
13913
13936
  callId,
13914
13937
  operationId: "ai.decide.doDecide",
@@ -14092,7 +14115,7 @@ function validateExtractionAnswers({ fields, state, answers }) {
14092
14115
  //#endregion
14093
14116
  //#region src/extract/extract.ts
14094
14117
  /** Extract typed field values from one shared state. Experimental. */
14095
- async function extract({ model: modelArg, state, fields, referenceDate, maxOutputTokens, reasoning, maxRetries, abortSignal, headers, providerOptions = {} }) {
14118
+ async function extract({ model: modelArg, state, fields, referenceDate, maxOutputTokens, reasoning, maxRetries, abortSignal, experimental_download: download, headers, providerOptions = {} }) {
14096
14119
  const model = resolveExtractionModel(modelArg);
14097
14120
  prepareLanguageModelCallOptions({ maxOutputTokens });
14098
14121
  validateExtractionInput({
@@ -14110,7 +14133,11 @@ async function extract({ model: modelArg, state, fields, referenceDate, maxOutpu
14110
14133
  maxRetries,
14111
14134
  abortSignal
14112
14135
  });
14113
- const preparedState = await prepareDecisionState(state, abortSignal);
14136
+ const preparedState = await prepareDecisionState({
14137
+ state,
14138
+ abortSignal,
14139
+ download
14140
+ });
14114
14141
  const result = await retry(async () => {
14115
14142
  abortSignal?.throwIfAborted();
14116
14143
  return await model.doExtract({