ai 7.0.35 → 7.0.37

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.
@@ -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.35" : "0.0.0-test";
88
+ var VERSION = true ? "7.0.37" : "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