@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
@@ -3021,51 +3021,45 @@ var ACCESS_LEVEL_HIERARCHY = {
3021
3021
  full: 4,
3022
3022
  internal: 5
3023
3023
  };
3024
- var DEFAULT_TRUST_THRESHOLDS = {
3025
- none: 0,
3026
- guidance: 0,
3027
- "read-only": 20,
3028
- standard: 40,
3029
- full: 70,
3030
- internal: 0
3031
- // Internal is based on org membership, not score
3032
- };
3033
3024
  function getTrustLevel(score) {
3034
3025
  if (score >= 80) return "PLATINUM";
3035
3026
  if (score >= 60) return "GOLD";
3036
3027
  if (score >= 40) return "SILVER";
3037
3028
  return "BRONZE";
3038
3029
  }
3039
- function getAccessLevelForScore(trustScore, thresholds = DEFAULT_TRUST_THRESHOLDS) {
3040
- if (trustScore >= thresholds.full) return "full";
3041
- if (trustScore >= thresholds.standard) return "standard";
3042
- if (trustScore >= thresholds["read-only"]) return "read-only";
3043
- return "guidance";
3044
- }
3045
- function determineAccessLevel(verified, trustScore, isOrgMember, customThresholds) {
3046
- if (!verified) {
3047
- return "guidance";
3048
- }
3049
- if (isOrgMember) {
3050
- return "internal";
3051
- }
3052
- const thresholds = {
3053
- ...DEFAULT_TRUST_THRESHOLDS,
3054
- ...customThresholds
3055
- };
3056
- return getAccessLevelForScore(trustScore, thresholds);
3057
- }
3058
3030
 
3059
3031
  // src/verify.ts
3060
3032
  var DEFAULT_CONFIG = {
3061
- apiBaseUrl: "https://api.astrasync.ai",
3033
+ apiBaseUrl: "https://astrasync.ai/api",
3062
3034
  defaultAccessLevel: "guidance",
3063
- minTrustScore: 40,
3064
- minTrustScoreForFull: 70,
3035
+ // minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
3065
3036
  cacheTtl: 300,
3066
3037
  // 5 minutes
3067
3038
  debug: false
3068
3039
  };
3040
+ var initCheckPerformed = false;
3041
+ var deprecationWarningShown = false;
3042
+ async function performInitCheck(apiBaseUrl, debug) {
3043
+ initCheckPerformed = true;
3044
+ try {
3045
+ const probeUrl = `${apiBaseUrl}/agents/verify-access`;
3046
+ const response = await fetch(probeUrl, { method: "HEAD" });
3047
+ const contentType = response.headers.get("content-type") ?? "";
3048
+ if (contentType.startsWith("text/html")) {
3049
+ console.warn(
3050
+ `[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.`
3051
+ );
3052
+ } else if (debug) {
3053
+ console.log(
3054
+ `[VerificationGateway] init check passed for ${apiBaseUrl} (content-type: ${contentType})`
3055
+ );
3056
+ }
3057
+ } catch (err) {
3058
+ if (debug) {
3059
+ console.log(`[VerificationGateway] init check failed (non-blocking): ${String(err)}`);
3060
+ }
3061
+ }
3062
+ }
3069
3063
  var verificationCache = /* @__PURE__ */ new Map();
3070
3064
  function getCacheKey(credentials) {
3071
3065
  return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
@@ -3088,9 +3082,6 @@ function cacheResult(credentials, result, ttlSeconds) {
3088
3082
  expiresAt: Date.now() + ttlSeconds * 1e3
3089
3083
  });
3090
3084
  }
3091
- function hasCredentials(credentials) {
3092
- return !!(credentials.astraId || credentials.apiKey || credentials.jwt);
3093
- }
3094
3085
  function createGuidanceResponse(config, reason) {
3095
3086
  const guidance = {
3096
3087
  message: "This service verifies AI agents before granting access. Please register your agent with AstraSync.",
@@ -3114,7 +3105,7 @@ function createGuidanceResponse(config, reason) {
3114
3105
  async function callVerifyAccessAPI(config, request) {
3115
3106
  const { credentials, ...requestData } = request;
3116
3107
  const body = {
3117
- agentId: credentials.astraId,
3108
+ ...credentials.astraId && { agentId: credentials.astraId },
3118
3109
  purpose: requestData.purpose || "general"
3119
3110
  };
3120
3111
  if (requestData.action) body.action = requestData.action;
@@ -3126,21 +3117,34 @@ async function callVerifyAccessAPI(config, request) {
3126
3117
  if (requestData.isSubAgentRequest) body.isSubAgentRequest = requestData.isSubAgentRequest;
3127
3118
  if (requestData.parentAgentId) body.parentAgentId = requestData.parentAgentId;
3128
3119
  if (requestData.subAgentDepth !== void 0) body.subAgentDepth = requestData.subAgentDepth;
3129
- if (requestData.enableRuntimeChallenge) body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
3120
+ if (requestData.enableRuntimeChallenge)
3121
+ body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
3130
3122
  if (requestData.createSession) body.createSession = requestData.createSession;
3131
3123
  if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
3132
3124
  if (requestData.counterpartyType) body.counterpartyType = requestData.counterpartyType;
3133
3125
  if (requestData.counterpartyUrl) body.counterpartyUrl = requestData.counterpartyUrl;
3134
- if (requestData.runtimeChallengeOptions) body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
3126
+ if (config.counterpartyId) body.counterpartyId = config.counterpartyId;
3127
+ if (requestData.runtimeChallengeOptions)
3128
+ body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
3129
+ if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
3130
+ const meta = {
3131
+ ...requestData.clientIp && { sourceIp: requestData.clientIp },
3132
+ ...requestData.userAgent && { userAgent: requestData.userAgent },
3133
+ ...requestData.callerMetadata
3134
+ };
3135
+ if (Object.keys(meta).length > 0) body.callerMetadata = meta;
3136
+ }
3135
3137
  const headers = {
3136
3138
  "Content-Type": "application/json",
3137
3139
  ...config.customHeaders
3138
3140
  };
3139
- if (config.apiKey) {
3140
- headers["X-API-Key"] = config.apiKey;
3141
- }
3142
3141
  if (credentials.authorizationHeader) {
3143
3142
  headers["Authorization"] = credentials.authorizationHeader;
3143
+ } else if (config.apiKey) {
3144
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
3145
+ }
3146
+ if (config.apiKey) {
3147
+ headers["X-API-Key"] = config.apiKey;
3144
3148
  }
3145
3149
  try {
3146
3150
  const response = await fetch(`${config.apiBaseUrl}/agents/verify-access`, {
@@ -3166,8 +3170,14 @@ async function callVerifyAccessAPI(config, request) {
3166
3170
  }
3167
3171
  async function verify(config, request) {
3168
3172
  const mergedConfig = { ...DEFAULT_CONFIG, ...config };
3169
- if (!hasCredentials(request.credentials)) {
3170
- return createGuidanceResponse(mergedConfig, "No agent credentials provided");
3173
+ if (!initCheckPerformed && !mergedConfig.disableInitChecks && mergedConfig.apiBaseUrl) {
3174
+ void performInitCheck(mergedConfig.apiBaseUrl, mergedConfig.debug);
3175
+ }
3176
+ if (!deprecationWarningShown && (config.minTrustScore !== void 0 || config.minTrustScoreForFull !== void 0)) {
3177
+ deprecationWarningShown = true;
3178
+ console.warn(
3179
+ "[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."
3180
+ );
3171
3181
  }
3172
3182
  if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
3173
3183
  const cached = getCachedResult(request.credentials);
@@ -3239,18 +3249,7 @@ async function verify(config, request) {
3239
3249
  selfInstantiationAllowed: apiResponse.access.pdlss.selfInstantiationAllowed,
3240
3250
  appliedPolicy: apiResponse.access.appliedPolicy
3241
3251
  } : void 0;
3242
- const trustScore = agent?.trustScore || 0;
3243
- const isOrgMember = false;
3244
- const accessLevel = determineAccessLevel(
3245
- true,
3246
- trustScore,
3247
- isOrgMember,
3248
- {
3249
- "read-only": 20,
3250
- standard: mergedConfig.minTrustScore || 40,
3251
- full: mergedConfig.minTrustScoreForFull || 70
3252
- }
3253
- );
3252
+ const accessLevel = apiResponse.access?.accessLevel ?? "standard";
3254
3253
  const result = {
3255
3254
  verified: true,
3256
3255
  accessLevel,
@@ -3272,7 +3271,9 @@ async function verify(config, request) {
3272
3271
  if (result.recommendation === "deny") {
3273
3272
  result.verified = false;
3274
3273
  result.accessLevel = "none";
3275
- result.denialReasons = result.recommendationReasons || ["Access denied by AstraSync recommendation"];
3274
+ result.denialReasons = result.recommendationReasons || [
3275
+ "Access denied by AstraSync recommendation"
3276
+ ];
3276
3277
  if (result.runtimeChallenge) {
3277
3278
  result.guidance = {
3278
3279
  message: `Verification failed: ${result.runtimeChallenge.reason || "runtime challenge failed"}`,