ai 7.0.34 → 7.0.36

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 (31) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/index.d.ts +26 -10
  3. package/dist/index.js +144 -47
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +5 -2
  6. package/dist/internal/index.js +26 -3
  7. package/dist/internal/index.js.map +1 -1
  8. package/docs/03-ai-sdk-core/25-settings.mdx +15 -2
  9. package/docs/03-ai-sdk-core/65-devtools.mdx +6 -0
  10. package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +42 -0
  11. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +29 -0
  12. package/docs/04-ai-sdk-ui/21-error-handling.mdx +10 -4
  13. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +4 -4
  14. package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +10 -8
  15. package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +6 -1
  16. package/docs/08-migration-guides/24-migration-guide-6-0.mdx +28 -0
  17. package/package.json +2 -2
  18. package/src/agent/agent.ts +4 -1
  19. package/src/agent/pipe-agent-ui-stream-to-response.ts +1 -1
  20. package/src/generate-object/stream-object-result.ts +4 -1
  21. package/src/generate-object/stream-object.ts +1 -1
  22. package/src/generate-text/generate-text-events.ts +2 -1
  23. package/src/generate-text/stream-text-result.ts +5 -2
  24. package/src/generate-text/stream-text.ts +113 -33
  25. package/src/generate-text/tool-approval-signature.ts +54 -2
  26. package/src/prompt/index.ts +1 -0
  27. package/src/prompt/request-options.ts +20 -2
  28. package/src/text-stream/pipe-text-stream-to-response.ts +3 -2
  29. package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +3 -2
  30. package/src/util/create-stitchable-stream.ts +41 -15
  31. package/src/util/write-to-server-response.ts +2 -2
@@ -421,13 +421,15 @@ type LanguageModelCallOptions = {
421
421
  * - A number representing milliseconds
422
422
  * - An object with `totalMs` property for the total timeout in milliseconds
423
423
  * - An object with `stepMs` property for the timeout of each step in milliseconds
424
- * - An object with `chunkMs` property for the timeout between stream chunks (streaming only)
424
+ * - An object with `firstChunkMs` property for the timeout until the first content chunk of each step (streaming only)
425
+ * - An object with `chunkMs` property for the timeout between content chunks (streaming only)
425
426
  * - An object with `toolMs` property for the default timeout for all tool executions
426
427
  * - An object with `tools` property for per-tool timeout overrides using `{toolName}Ms` keys
427
428
  */
428
429
  type TimeoutConfiguration<TOOLS extends ToolSet> = number | {
429
430
  totalMs?: number;
430
431
  stepMs?: number;
432
+ firstChunkMs?: number;
431
433
  chunkMs?: number;
432
434
  toolMs?: number;
433
435
  tools?: Partial<Record<`${keyof TOOLS & string}Ms`, number>>;
@@ -1965,7 +1967,8 @@ type GenerateTextStartEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT ext
1965
1967
  readonly maxRetries: number;
1966
1968
  /**
1967
1969
  * Timeout configuration for the generation.
1968
- * Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs, toolMs, and per-tool overrides via tools.
1970
+ * Can be a number (milliseconds) or an object with totalMs, stepMs,
1971
+ * firstChunkMs (streaming only), chunkMs, toolMs, and per-tool overrides via tools.
1969
1972
  */
1970
1973
  readonly timeout: TimeoutConfiguration<TOOLS> | undefined;
1971
1974
  /** Additional HTTP headers sent with the request. */
@@ -85,7 +85,7 @@ import {
85
85
  } from "@ai-sdk/provider-utils";
86
86
 
87
87
  // src/version.ts
88
- var VERSION = true ? "7.0.34" : "0.0.0-test";
88
+ var VERSION = true ? "7.0.36" : "0.0.0-test";
89
89
 
90
90
  // src/util/download/download.ts
91
91
  var download = async ({
@@ -3281,6 +3281,17 @@ async function importKey(secret) {
3281
3281
  );
3282
3282
  }
3283
3283
  function buildPayload(approvalId, toolCallId, toolName, inputDigest) {
3284
+ return encoder2.encode(
3285
+ JSON.stringify([
3286
+ "ai-sdk-tool-approval-v1",
3287
+ approvalId,
3288
+ toolCallId,
3289
+ toolName,
3290
+ inputDigest
3291
+ ])
3292
+ );
3293
+ }
3294
+ function buildLegacyPayload(approvalId, toolCallId, toolName, inputDigest) {
3284
3295
  return encoder2.encode(
3285
3296
  `${approvalId}
3286
3297
  ${toolCallId}
@@ -3298,9 +3309,21 @@ async function verifyToolApprovalSignature({
3298
3309
  }) {
3299
3310
  const key = await importKey(secret);
3300
3311
  const inputDigest = await hashCanonical(input);
3301
- const payload = buildPayload(approvalId, toolCallId, toolName, inputDigest);
3302
3312
  const sigBytes = fromBase64url(signature);
3303
- return crypto.subtle.verify("HMAC", key, sigBytes, payload);
3313
+ const payload = buildPayload(approvalId, toolCallId, toolName, inputDigest);
3314
+ if (await crypto.subtle.verify("HMAC", key, sigBytes, payload)) {
3315
+ return true;
3316
+ }
3317
+ if (!approvalId.includes("\n") && !toolCallId.includes("\n") && !toolName.includes("\n")) {
3318
+ const legacyPayload = buildLegacyPayload(
3319
+ approvalId,
3320
+ toolCallId,
3321
+ toolName,
3322
+ inputDigest
3323
+ );
3324
+ return crypto.subtle.verify("HMAC", key, sigBytes, legacyPayload);
3325
+ }
3326
+ return false;
3304
3327
  }
3305
3328
 
3306
3329
  // src/generate-text/validate-tool-approvals.ts