@kya-os/agentshield-nextjs 0.2.10 → 0.2.12

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.
package/dist/index.mjs CHANGED
@@ -2105,6 +2105,7 @@ var AgentShieldClient = class {
2105
2105
  confidence: input.detection.confidence,
2106
2106
  agentName: input.detection.agentName,
2107
2107
  agentType: input.detection.agentType,
2108
+ detectionClass: input.detection.detectionClass,
2108
2109
  verificationMethod: input.detection.verificationMethod,
2109
2110
  reasons: input.detection.reasons
2110
2111
  },
@@ -2174,16 +2175,21 @@ function shouldIncludePath(path, includePaths) {
2174
2175
  }
2175
2176
  function buildBlockedResponse(decision, config) {
2176
2177
  const status = config.blockedResponse?.status ?? 403;
2177
- const message = config.blockedResponse?.message ?? decision.message ?? "Access denied";
2178
- const response = NextResponse.json(
2179
- {
2180
- error: message,
2181
- code: "AGENT_BLOCKED",
2182
- reason: decision.reason,
2183
- agentType: decision.agentType
2184
- },
2185
- { status }
2186
- );
2178
+ const redirectUrl = config.redirectUrl || decision.redirectUrl;
2179
+ const baseMessage = config.blockedResponse?.message ?? decision.message ?? "Access denied";
2180
+ const errorMessage = redirectUrl ? `${baseMessage}. Please go to ${redirectUrl}` : baseMessage;
2181
+ const message = config.blockedResponse?.message ?? decision.message ?? (redirectUrl ? `AI agents are not permitted on this resource. Please go to ${redirectUrl} for more information.` : "AI agents are not permitted on this resource.");
2182
+ const responseBody = {
2183
+ error: errorMessage,
2184
+ code: "AGENT_BLOCKED",
2185
+ reason: decision.reason,
2186
+ agentType: decision.agentType,
2187
+ message
2188
+ };
2189
+ if (redirectUrl) {
2190
+ responseBody.redirectUrl = redirectUrl;
2191
+ }
2192
+ const response = NextResponse.json(responseBody, { status });
2187
2193
  if (config.blockedResponse?.headers) {
2188
2194
  for (const [key, value] of Object.entries(config.blockedResponse.headers)) {
2189
2195
  response.headers.set(key, value);
@@ -2191,6 +2197,9 @@ function buildBlockedResponse(decision, config) {
2191
2197
  }
2192
2198
  response.headers.set("X-AgentShield-Action", decision.action);
2193
2199
  response.headers.set("X-AgentShield-Reason", decision.reason);
2200
+ if (redirectUrl) {
2201
+ response.headers.set("X-AgentShield-Redirect", redirectUrl);
2202
+ }
2194
2203
  return response;
2195
2204
  }
2196
2205
  function buildRedirectResponse(request, decision, config) {