@astrasyncai/verification-gateway 2.1.0 → 2.2.3

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 (84) hide show
  1. package/README.md +64 -30
  2. package/dist/adapter-interface/interface.d.mts +2 -2
  3. package/dist/adapter-interface/interface.d.ts +2 -2
  4. package/dist/adapters/express.d.mts +2 -2
  5. package/dist/adapters/express.d.ts +2 -2
  6. package/dist/adapters/express.js +74 -95
  7. package/dist/adapters/express.js.map +1 -1
  8. package/dist/adapters/express.mjs +74 -95
  9. package/dist/adapters/express.mjs.map +1 -1
  10. package/dist/adapters/nextjs.d.mts +2 -2
  11. package/dist/adapters/nextjs.d.ts +2 -2
  12. package/dist/adapters/nextjs.js +74 -115
  13. package/dist/adapters/nextjs.js.map +1 -1
  14. package/dist/adapters/nextjs.mjs +74 -115
  15. package/dist/adapters/nextjs.mjs.map +1 -1
  16. package/dist/adapters/sdk.d.mts +2 -2
  17. package/dist/adapters/sdk.d.ts +2 -2
  18. package/dist/adapters/sdk.js +56 -55
  19. package/dist/adapters/sdk.js.map +1 -1
  20. package/dist/adapters/sdk.mjs +56 -55
  21. package/dist/adapters/sdk.mjs.map +1 -1
  22. package/dist/agent/index.d.mts +2 -2
  23. package/dist/agent/index.d.ts +2 -2
  24. package/dist/agent/index.js +68 -2
  25. package/dist/agent/index.js.map +1 -1
  26. package/dist/agent/index.mjs +66 -2
  27. package/dist/agent/index.mjs.map +1 -1
  28. package/dist/browser/background.js +56 -55
  29. package/dist/browser/background.js.map +1 -1
  30. package/dist/browser/background.mjs +56 -55
  31. package/dist/browser/background.mjs.map +1 -1
  32. package/dist/browser/browser-adapter.d.mts +2 -2
  33. package/dist/browser/browser-adapter.d.ts +2 -2
  34. package/dist/cli/index.d.mts +2 -2
  35. package/dist/cli/index.d.ts +2 -2
  36. package/dist/cursor/cursor-adapter.d.mts +2 -2
  37. package/dist/cursor/cursor-adapter.d.ts +2 -2
  38. package/dist/cursor/extension.d.mts +2 -2
  39. package/dist/cursor/extension.d.ts +2 -2
  40. package/dist/cursor/extension.js +56 -55
  41. package/dist/cursor/extension.js.map +1 -1
  42. package/dist/cursor/extension.mjs +56 -55
  43. package/dist/cursor/extension.mjs.map +1 -1
  44. package/dist/{express-Bcl-uBUE.d.ts → express-BtKlLI8U.d.ts} +2 -2
  45. package/dist/{express-CtwDIZyF.d.mts → express-DgwpS8Ha.d.mts} +2 -2
  46. package/dist/gateway/gateway.d.mts +2 -2
  47. package/dist/gateway/gateway.d.ts +2 -2
  48. package/dist/gateway/gateway.js +56 -55
  49. package/dist/gateway/gateway.js.map +1 -1
  50. package/dist/gateway/gateway.mjs +56 -55
  51. package/dist/gateway/gateway.mjs.map +1 -1
  52. package/dist/git-trigger/git-hooks.d.mts +2 -2
  53. package/dist/git-trigger/git-hooks.d.ts +2 -2
  54. package/dist/{index-BY8yQ8N8.d.mts → index-AzhK20t0.d.mts} +46 -3
  55. package/dist/{index-CME6r4uH.d.ts → index-Ba0Lvsjo.d.ts} +1 -1
  56. package/dist/{index-3NRaBNvp.d.mts → index-BaxpmTGA.d.mts} +1 -1
  57. package/dist/{index-CtYSYwn3.d.ts → index-DpJS1JEI.d.ts} +46 -3
  58. package/dist/index.d.mts +7 -7
  59. package/dist/index.d.ts +7 -7
  60. package/dist/index.js +158 -117
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +158 -117
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/local-evaluator/evaluator.d.mts +2 -2
  65. package/dist/local-evaluator/evaluator.d.ts +2 -2
  66. package/dist/{nextjs-CEldnIJ9.d.ts → nextjs-B2kg19c1.d.ts} +1 -1
  67. package/dist/{nextjs-BQyMCSx_.d.mts → nextjs-ZymQ8jDh.d.mts} +1 -1
  68. package/dist/{sdk-BhvuJSrH.d.mts → sdk-B7id0VFS.d.mts} +2 -2
  69. package/dist/{sdk-BlyVSC_S.d.ts → sdk-Bso0FSI0.d.ts} +2 -2
  70. package/dist/transport/index.d.mts +2 -2
  71. package/dist/transport/index.d.ts +2 -2
  72. package/dist/{types-79qS7aON.d.ts → types-BYKAY6Cc.d.ts} +1 -1
  73. package/dist/{types-jJnPXStc.d.mts → types-CgXPKUwi.d.mts} +1 -1
  74. package/dist/{types-CxQwJKbd.d.mts → types-DOrqNMgy.d.mts} +79 -13
  75. package/dist/{types-CxQwJKbd.d.ts → types-DOrqNMgy.d.ts} +79 -13
  76. package/dist/ui/index.d.mts +1 -1
  77. package/dist/ui/index.d.ts +1 -1
  78. package/dist/webhooks.d.mts +59 -0
  79. package/dist/webhooks.d.ts +59 -0
  80. package/dist/webhooks.js +81 -0
  81. package/dist/webhooks.js.map +1 -0
  82. package/dist/webhooks.mjs +55 -0
  83. package/dist/webhooks.mjs.map +1 -0
  84. package/package.json +8 -3
@@ -3285,51 +3285,45 @@ var ACCESS_LEVEL_HIERARCHY = {
3285
3285
  full: 4,
3286
3286
  internal: 5
3287
3287
  };
3288
- var DEFAULT_TRUST_THRESHOLDS = {
3289
- none: 0,
3290
- guidance: 0,
3291
- "read-only": 20,
3292
- standard: 40,
3293
- full: 70,
3294
- internal: 0
3295
- // Internal is based on org membership, not score
3296
- };
3297
3288
  function getTrustLevel(score) {
3298
3289
  if (score >= 80) return "PLATINUM";
3299
3290
  if (score >= 60) return "GOLD";
3300
3291
  if (score >= 40) return "SILVER";
3301
3292
  return "BRONZE";
3302
3293
  }
3303
- function getAccessLevelForScore(trustScore, thresholds = DEFAULT_TRUST_THRESHOLDS) {
3304
- if (trustScore >= thresholds.full) return "full";
3305
- if (trustScore >= thresholds.standard) return "standard";
3306
- if (trustScore >= thresholds["read-only"]) return "read-only";
3307
- return "guidance";
3308
- }
3309
- function determineAccessLevel(verified, trustScore, isOrgMember, customThresholds) {
3310
- if (!verified) {
3311
- return "guidance";
3312
- }
3313
- if (isOrgMember) {
3314
- return "internal";
3315
- }
3316
- const thresholds = {
3317
- ...DEFAULT_TRUST_THRESHOLDS,
3318
- ...customThresholds
3319
- };
3320
- return getAccessLevelForScore(trustScore, thresholds);
3321
- }
3322
3294
 
3323
3295
  // src/verify.ts
3324
3296
  var DEFAULT_CONFIG = {
3325
- apiBaseUrl: "https://api.astrasync.ai",
3297
+ apiBaseUrl: "https://astrasync.ai/api",
3326
3298
  defaultAccessLevel: "guidance",
3327
- minTrustScore: 40,
3328
- minTrustScoreForFull: 70,
3299
+ // minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
3329
3300
  cacheTtl: 300,
3330
3301
  // 5 minutes
3331
3302
  debug: false
3332
3303
  };
3304
+ var initCheckPerformed = false;
3305
+ var deprecationWarningShown = false;
3306
+ async function performInitCheck(apiBaseUrl, debug) {
3307
+ initCheckPerformed = true;
3308
+ try {
3309
+ const probeUrl = `${apiBaseUrl}/agents/verify-access`;
3310
+ const response = await fetch(probeUrl, { method: "HEAD" });
3311
+ const contentType = response.headers.get("content-type") ?? "";
3312
+ if (contentType.startsWith("text/html")) {
3313
+ console.warn(
3314
+ `[VerificationGateway] apiBaseUrl '${apiBaseUrl}' returned HTML (content-type: ${contentType}). This usually means apiBaseUrl is pointing at a marketing site instead of the API. Expected: 'https://astrasync.ai/api' (prod) or 'https://staging.astrasync.ai/api' (staging). Set disableInitChecks: true on GatewayConfig to silence this warning.`
3315
+ );
3316
+ } else if (debug) {
3317
+ console.log(
3318
+ `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
3319
+ );
3320
+ }
3321
+ } catch (err) {
3322
+ if (debug) {
3323
+ console.log(`[VerificationGateway] init check failed (non-blocking): ${String(err)}`);
3324
+ }
3325
+ }
3326
+ }
3333
3327
  var verificationCache = /* @__PURE__ */ new Map();
3334
3328
  function getCacheKey(credentials) {
3335
3329
  return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
@@ -3352,9 +3346,6 @@ function cacheResult(credentials, result, ttlSeconds) {
3352
3346
  expiresAt: Date.now() + ttlSeconds * 1e3
3353
3347
  });
3354
3348
  }
3355
- function hasCredentials(credentials) {
3356
- return !!(credentials.astraId || credentials.apiKey || credentials.jwt);
3357
- }
3358
3349
  function createGuidanceResponse(config, reason) {
3359
3350
  const guidance = {
3360
3351
  message: "This service verifies AI agents before granting access. Please register your agent with AstraSync.",
@@ -3378,7 +3369,7 @@ function createGuidanceResponse(config, reason) {
3378
3369
  async function callVerifyAccessAPI(config, request) {
3379
3370
  const { credentials, ...requestData } = request;
3380
3371
  const body = {
3381
- agentId: credentials.astraId,
3372
+ ...credentials.astraId && { agentId: credentials.astraId },
3382
3373
  purpose: requestData.purpose || "general"
3383
3374
  };
3384
3375
  if (requestData.action) body.action = requestData.action;
@@ -3390,21 +3381,34 @@ async function callVerifyAccessAPI(config, request) {
3390
3381
  if (requestData.isSubAgentRequest) body.isSubAgentRequest = requestData.isSubAgentRequest;
3391
3382
  if (requestData.parentAgentId) body.parentAgentId = requestData.parentAgentId;
3392
3383
  if (requestData.subAgentDepth !== void 0) body.subAgentDepth = requestData.subAgentDepth;
3393
- if (requestData.enableRuntimeChallenge) body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
3384
+ if (requestData.enableRuntimeChallenge)
3385
+ body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
3394
3386
  if (requestData.createSession) body.createSession = requestData.createSession;
3395
3387
  if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
3396
3388
  if (requestData.counterpartyType) body.counterpartyType = requestData.counterpartyType;
3397
3389
  if (requestData.counterpartyUrl) body.counterpartyUrl = requestData.counterpartyUrl;
3398
- if (requestData.runtimeChallengeOptions) body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
3390
+ if (config.counterpartyId) body.counterpartyId = config.counterpartyId;
3391
+ if (requestData.runtimeChallengeOptions)
3392
+ body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
3393
+ if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
3394
+ const meta = {
3395
+ ...requestData.clientIp && { sourceIp: requestData.clientIp },
3396
+ ...requestData.userAgent && { userAgent: requestData.userAgent },
3397
+ ...requestData.callerMetadata
3398
+ };
3399
+ if (Object.keys(meta).length > 0) body.callerMetadata = meta;
3400
+ }
3399
3401
  const headers = {
3400
3402
  "Content-Type": "application/json",
3401
3403
  ...config.customHeaders
3402
3404
  };
3403
- if (config.apiKey) {
3404
- headers["X-API-Key"] = config.apiKey;
3405
- }
3406
3405
  if (credentials.authorizationHeader) {
3407
3406
  headers["Authorization"] = credentials.authorizationHeader;
3407
+ } else if (config.apiKey) {
3408
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
3409
+ }
3410
+ if (config.apiKey) {
3411
+ headers["X-API-Key"] = config.apiKey;
3408
3412
  }
3409
3413
  try {
3410
3414
  const response = await fetch(`${config.apiBaseUrl}/agents/verify-access`, {
@@ -3430,8 +3434,14 @@ async function callVerifyAccessAPI(config, request) {
3430
3434
  }
3431
3435
  async function verify(config, request) {
3432
3436
  const mergedConfig = { ...DEFAULT_CONFIG, ...config };
3433
- if (!hasCredentials(request.credentials)) {
3434
- return createGuidanceResponse(mergedConfig, "No agent credentials provided");
3437
+ if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
3438
+ void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug);
3439
+ }
3440
+ if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
3441
+ deprecationWarningShown = true;
3442
+ console.warn(
3443
+ "[VerificationGateway] minTrustScore / minTrustScoreForFull are deprecated in v2.3.0 and have no effect. Server is now the single source of truth for access-level decisions (the SDK reads access.accessLevel from the verify-access response). To gate access to an endpoint, configure the endpoint's trust_score_requirement server-side."
3444
+ );
3435
3445
  }
3436
3446
  if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
3437
3447
  const cached = getCachedResult(request.credentials);
@@ -3503,18 +3513,7 @@ async function verify(config, request) {
3503
3513
  selfInstantiationAllowed: apiResponse.access.pdlss.selfInstantiationAllowed,
3504
3514
  appliedPolicy: apiResponse.access.appliedPolicy
3505
3515
  } : void 0;
3506
- const trustScore = agent?.trustScore || 0;
3507
- const isOrgMember = false;
3508
- const accessLevel = determineAccessLevel(
3509
- true,
3510
- trustScore,
3511
- isOrgMember,
3512
- {
3513
- "read-only": 20,
3514
- standard: mergedConfig.minTrustScore || 40,
3515
- full: mergedConfig.minTrustScoreForFull || 70
3516
- }
3517
- );
3516
+ const accessLevel = apiResponse.access?.accessLevel ?? "standard";
3518
3517
  const result = {
3519
3518
  verified: true,
3520
3519
  accessLevel,
@@ -3536,7 +3535,9 @@ async function verify(config, request) {
3536
3535
  if (result.recommendation === "deny") {
3537
3536
  result.verified = false;
3538
3537
  result.accessLevel = "none";
3539
- result.denialReasons = result.recommendationReasons || ["Access denied by AstraSync recommendation"];
3538
+ result.denialReasons = result.recommendationReasons || [
3539
+ "Access denied by AstraSync recommendation"
3540
+ ];
3540
3541
  if (result.runtimeChallenge) {
3541
3542
  result.guidance = {
3542
3543
  message: `Verification failed: ${result.runtimeChallenge.reason || "runtime challenge failed"}`,