@agentvisa/widget 0.2.0 → 0.2.1
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/core.d.ts +43 -10
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +84 -5
- package/dist/core.js.map +1 -1
- package/dist/express/index.d.ts.map +1 -1
- package/dist/express/index.js +60 -6
- package/dist/express/index.js.map +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +56 -10
- package/dist/next/index.js.map +1 -1
- package/dist/widget.esm.js +12 -3
- package/dist/widget.js +12 -3
- package/package.json +3 -3
package/dist/core.d.ts
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
* Used by Express and Next.js middleware — no framework deps here.
|
|
4
4
|
*/
|
|
5
5
|
export declare const DEFAULT_API_BASE = "https://api.agentvisa.ai";
|
|
6
|
+
export declare const DEFAULT_REDIRECT_URL = "https://agentvisa.ai/for-agents";
|
|
7
|
+
/**
|
|
8
|
+
* Detect whether an incoming request looks like an AI agent.
|
|
9
|
+
*
|
|
10
|
+
* Used to guard the viral redirect loop — we only send requests to
|
|
11
|
+
* agentvisa.ai/for-agents when there is evidence the requester is an
|
|
12
|
+
* AI agent that can act on the instructions there. Bot scrapers and
|
|
13
|
+
* human browsers get a plain 401 instead.
|
|
14
|
+
*
|
|
15
|
+
* Detection hierarchy:
|
|
16
|
+
* Strong (any one → true): RFC 9421 Signature-Input, Agent-Authorization header
|
|
17
|
+
* Medium (any one → true): known AI User-Agent pattern
|
|
18
|
+
* Weak combo (both needed): no browser fingerprint headers + no text/html in Accept
|
|
19
|
+
*/
|
|
20
|
+
export declare function isLikelyAiAgent(headers: Record<string, string | string[] | undefined>): boolean;
|
|
6
21
|
export interface AgentVisaConfig {
|
|
7
22
|
/** Your widget ID from the AgentVisa dashboard */
|
|
8
23
|
widgetId: string;
|
|
@@ -12,30 +27,48 @@ export interface AgentVisaConfig {
|
|
|
12
27
|
apiBaseUrl?: string;
|
|
13
28
|
/**
|
|
14
29
|
* What to do when verification fails or token is missing.
|
|
15
|
-
* "
|
|
30
|
+
* "redirect" (default) — redirect the agent to redirectUrl (agentvisa.ai/for-agents).
|
|
31
|
+
* "block" — return 401 and stop the request. The redirect_url is still included
|
|
32
|
+
* in the JSON body so the agent knows where to go.
|
|
16
33
|
* "passthrough" — attach result to request and continue; let your
|
|
17
34
|
* handler decide. Useful for soft-gating or analytics.
|
|
18
35
|
*/
|
|
19
|
-
onUnverified?: "block" | "passthrough";
|
|
36
|
+
onUnverified?: "redirect" | "block" | "passthrough";
|
|
37
|
+
/**
|
|
38
|
+
* Where to send unverified agents.
|
|
39
|
+
* Defaults to "https://agentvisa.ai/for-agents".
|
|
40
|
+
* Only used when onUnverified is "redirect".
|
|
41
|
+
*/
|
|
42
|
+
redirectUrl?: string;
|
|
20
43
|
}
|
|
21
44
|
export interface VerifyResult {
|
|
22
45
|
valid: boolean;
|
|
23
46
|
reason: string;
|
|
24
47
|
plan?: string;
|
|
25
48
|
widget_id?: string;
|
|
26
|
-
human_name?: string | null;
|
|
27
49
|
verified_at?: string | null;
|
|
28
50
|
expires_at?: string | null;
|
|
29
|
-
|
|
30
|
-
age_over_18?:
|
|
31
|
-
age_over_21?:
|
|
32
|
-
|
|
33
|
-
|
|
51
|
+
domain_verified?: boolean;
|
|
52
|
+
age_over_18?: "y" | "n" | "null";
|
|
53
|
+
age_over_21?: "y" | "n" | "null";
|
|
54
|
+
gov_id_pic_validation?: "y" | "n" | "null";
|
|
55
|
+
multiple_agents_authorized?: "y" | "n" | "null";
|
|
56
|
+
member_since?: string;
|
|
57
|
+
email_confirmed?: boolean;
|
|
58
|
+
phone_last4_confirmed?: boolean;
|
|
59
|
+
web_bot_auth_bound?: boolean;
|
|
34
60
|
}
|
|
35
61
|
/**
|
|
36
62
|
* Call /v1/verify with a TemporaryToken.
|
|
37
|
-
*
|
|
63
|
+
*
|
|
64
|
+
* @param temporaryToken The tmp_xxx token from the agent's request header
|
|
65
|
+
* @param config Resolved widget config (widgetId, apiKey, apiBaseUrl)
|
|
66
|
+
* @param forwardHeaders Optional headers from the original agent request.
|
|
67
|
+
* Pass these so the backend can detect Web Bot Auth binding
|
|
68
|
+
* (Signature-Input header) and populate web_bot_auth_bound.
|
|
69
|
+
*
|
|
70
|
+
* Returns the full VerifyResult or a synthetic error result on network failure.
|
|
38
71
|
*/
|
|
39
|
-
export declare function callVerify(temporaryToken: string, config: Required<AgentVisaConfig>): Promise<VerifyResult>;
|
|
72
|
+
export declare function callVerify(temporaryToken: string, config: Required<AgentVisaConfig>, forwardHeaders?: Record<string, string | string[] | undefined>): Promise<VerifyResult>;
|
|
40
73
|
export declare function resolveConfig(config: AgentVisaConfig): Required<AgentVisaConfig>;
|
|
41
74
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,gBAAgB,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,gBAAgB,6BAA6B,CAAC;AAC3D,eAAO,MAAM,oBAAoB,oCAAoC,CAAC;AA0BtE;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GACrD,OAAO,CAyBT;AAED,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE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ULT_API_BASE = "https://api.agentvisa.ai";
|
|
6
|
+
export const DEFAULT_REDIRECT_URL = "https://agentvisa.ai/for-agents";
|
|
7
|
+
// ── Agent signal detection ────────────────────────────────────────────────────
|
|
8
|
+
/**
|
|
9
|
+
* Known AI agent / LLM user-agent substrings (case-insensitive).
|
|
10
|
+
* Not exhaustive — the UA check is a medium-confidence signal only.
|
|
11
|
+
* The strongest signals are RFC 9421 headers (Signature-Input, Agent-Authorization).
|
|
12
|
+
*/
|
|
13
|
+
const AI_UA_PATTERNS = [
|
|
14
|
+
/claude/i,
|
|
15
|
+
/anthropic/i,
|
|
16
|
+
/openai/i,
|
|
17
|
+
/chatgpt/i,
|
|
18
|
+
/gpt-[0-9]/i,
|
|
19
|
+
/gemini/i,
|
|
20
|
+
/cursor\//i,
|
|
21
|
+
/windsurf/i,
|
|
22
|
+
/codeium/i,
|
|
23
|
+
/perplexity/i,
|
|
24
|
+
/copilot/i,
|
|
25
|
+
/agentvisa/i,
|
|
26
|
+
/python-httpx/i,
|
|
27
|
+
/python-requests/i,
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Detect whether an incoming request looks like an AI agent.
|
|
31
|
+
*
|
|
32
|
+
* Used to guard the viral redirect loop — we only send requests to
|
|
33
|
+
* agentvisa.ai/for-agents when there is evidence the requester is an
|
|
34
|
+
* AI agent that can act on the instructions there. Bot scrapers and
|
|
35
|
+
* human browsers get a plain 401 instead.
|
|
36
|
+
*
|
|
37
|
+
* Detection hierarchy:
|
|
38
|
+
* Strong (any one → true): RFC 9421 Signature-Input, Agent-Authorization header
|
|
39
|
+
* Medium (any one → true): known AI User-Agent pattern
|
|
40
|
+
* Weak combo (both needed): no browser fingerprint headers + no text/html in Accept
|
|
41
|
+
*/
|
|
42
|
+
export function isLikelyAiAgent(headers) {
|
|
43
|
+
const h = (name) => {
|
|
44
|
+
const v = headers[name.toLowerCase()];
|
|
45
|
+
return Array.isArray(v) ? v[0] : (v ?? "");
|
|
46
|
+
};
|
|
47
|
+
// Strong: RFC 9421 Web Bot Auth — signed request almost certainly from AI operator
|
|
48
|
+
if (h("signature-input") || h("agent-authorization"))
|
|
49
|
+
return true;
|
|
50
|
+
// Medium: known AI User-Agent
|
|
51
|
+
const ua = h("user-agent");
|
|
52
|
+
if (ua && AI_UA_PATTERNS.some((p) => p.test(ua)))
|
|
53
|
+
return true;
|
|
54
|
+
// Weak combo: no browser fingerprint + no HTML in Accept
|
|
55
|
+
// Real browsers always send sec-fetch-* and always include text/html in Accept.
|
|
56
|
+
const hasBrowserFingerprint = !!h("sec-fetch-mode") || !!h("sec-fetch-site") || !!h("sec-ch-ua");
|
|
57
|
+
const accept = h("accept");
|
|
58
|
+
const acceptsHtml = accept.includes("text/html");
|
|
59
|
+
const looksLikeApiClient = accept.includes("application/json") || accept === "*/*" || accept === "";
|
|
60
|
+
if (!hasBrowserFingerprint && !acceptsHtml && looksLikeApiClient)
|
|
61
|
+
return true;
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
6
64
|
/**
|
|
7
65
|
* Call /v1/verify with a TemporaryToken.
|
|
8
|
-
*
|
|
66
|
+
*
|
|
67
|
+
* @param temporaryToken The tmp_xxx token from the agent's request header
|
|
68
|
+
* @param config Resolved widget config (widgetId, apiKey, apiBaseUrl)
|
|
69
|
+
* @param forwardHeaders Optional headers from the original agent request.
|
|
70
|
+
* Pass these so the backend can detect Web Bot Auth binding
|
|
71
|
+
* (Signature-Input header) and populate web_bot_auth_bound.
|
|
72
|
+
*
|
|
73
|
+
* Returns the full VerifyResult or a synthetic error result on network failure.
|
|
9
74
|
*/
|
|
10
|
-
export async function callVerify(temporaryToken, config) {
|
|
75
|
+
export async function callVerify(temporaryToken, config, forwardHeaders) {
|
|
11
76
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
77
|
+
// Forward Signature-Input from the original agent request so the backend
|
|
78
|
+
// can detect Web Bot Auth binding and set web_bot_auth_bound in Pro responses.
|
|
79
|
+
const extraHeaders = {};
|
|
80
|
+
if (forwardHeaders) {
|
|
81
|
+
const sigInput = forwardHeaders["signature-input"];
|
|
82
|
+
if (sigInput) {
|
|
83
|
+
extraHeaders["signature-input"] = Array.isArray(sigInput) ? sigInput[0] : sigInput;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const response = await fetch(`${config.apiBaseUrl}/v1/verify`, {
|
|
14
87
|
method: "POST",
|
|
15
88
|
headers: {
|
|
16
89
|
"Content-Type": "application/json",
|
|
17
90
|
"X-Widget-Api-Key": config.apiKey,
|
|
91
|
+
...extraHeaders,
|
|
18
92
|
},
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
token: temporaryToken,
|
|
95
|
+
widget_id: config.widgetId,
|
|
96
|
+
}),
|
|
19
97
|
});
|
|
20
98
|
return await response.json();
|
|
21
99
|
}
|
|
@@ -26,7 +104,8 @@ export async function callVerify(temporaryToken, config) {
|
|
|
26
104
|
export function resolveConfig(config) {
|
|
27
105
|
return {
|
|
28
106
|
apiBaseUrl: DEFAULT_API_BASE,
|
|
29
|
-
onUnverified: "
|
|
107
|
+
onUnverified: "redirect",
|
|
108
|
+
redirectUrl: DEFAULT_REDIRECT_URL,
|
|
30
109
|
...config,
|
|
31
110
|
};
|
|
32
111
|
}
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAC3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,iCAAiC,CAAC;AAEtE,iFAAiF;AAEjF;;;;GAIG;AACH,MAAM,cAAc,GAAa;IAC/B,SAAS;IACT,YAAY;IACZ,SAAS;IACT,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,EAAE,oBAAoB;QACjC,GAAG,MAAM;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,eAAe,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,eAAe,EAAE,YAAY,EAA8C,MAAM,YAAY,CAAC;AAEvG,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AAI9C,UAAU,GAAG;IACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,SAAS,CAAC,EAAE;QACV,QAAQ,EAAE,OAAO,CAAC;QAClB,MAAM,CAAC,EAAE,YAAY,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,UAAU,GAAG;IACX,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC;IAC1B,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9C;AAED,KAAK,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;AAEtC,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,IAI7C,KAAK,GAAG,EACR,KAAK,GAAG,EACR,MAAM,MAAM,KACX,OAAO,CAAC,IAAI,CAAC,CAkGjB"}
|
package/dist/express/index.js
CHANGED
|
@@ -17,11 +17,15 @@
|
|
|
17
17
|
* req.agentVisa.result — full VerifyResult (if verified)
|
|
18
18
|
* req.agentVisa.reason — failure reason (if not verified + passthrough mode)
|
|
19
19
|
*/
|
|
20
|
-
import { callVerify, resolveConfig } from "../core.js";
|
|
20
|
+
import { callVerify, resolveConfig, isLikelyAiAgent } from "../core.js";
|
|
21
21
|
export function agentVisa(config) {
|
|
22
22
|
const resolved = resolveConfig(config);
|
|
23
23
|
return async function agentVisaMiddleware(req, res, next) {
|
|
24
|
-
|
|
24
|
+
// Accept both header modes:
|
|
25
|
+
// Standard: X-AgentVisa-Token: tmp_xxx
|
|
26
|
+
// Web Bot Auth: AgentVisa-Assertion: tmp_xxx (covered by RFC 9421 Signature-Input)
|
|
27
|
+
const rawAssertion = req.headers["agentvisa-assertion"];
|
|
28
|
+
const rawToken = rawAssertion ?? req.headers["x-agentvisa-token"];
|
|
25
29
|
const token = Array.isArray(rawToken) ? rawToken[0] : rawToken;
|
|
26
30
|
// ── No token present ────────────────────────────────────────────────────
|
|
27
31
|
if (!token) {
|
|
@@ -29,28 +33,78 @@ export function agentVisa(config) {
|
|
|
29
33
|
req.agentVisa = { verified: false, reason: "no_token" };
|
|
30
34
|
return next();
|
|
31
35
|
}
|
|
36
|
+
if (resolved.onUnverified === "redirect") {
|
|
37
|
+
// Only redirect if this actually looks like an AI agent.
|
|
38
|
+
// Bot scrapers and human browsers get a plain 401 — we don't want
|
|
39
|
+
// them flooding agentvisa.ai/for-agents or triggering the growth loop
|
|
40
|
+
// for non-agent traffic.
|
|
41
|
+
if (!isLikelyAiAgent(req.headers)) {
|
|
42
|
+
res.setHeader("X-AgentVisa-Required", resolved.widgetId);
|
|
43
|
+
res.status(401).json({
|
|
44
|
+
error: "agentvisa_required",
|
|
45
|
+
reason: "no_token",
|
|
46
|
+
widget_id: resolved.widgetId,
|
|
47
|
+
info_url: resolved.redirectUrl,
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
res.setHeader("X-AgentVisa-Required", resolved.widgetId);
|
|
52
|
+
res.setHeader("Location", resolved.redirectUrl);
|
|
53
|
+
res.status(302).json({
|
|
54
|
+
error: "agentvisa_required",
|
|
55
|
+
reason: "no_token",
|
|
56
|
+
widget_id: resolved.widgetId,
|
|
57
|
+
signup_url: "https://agentvisa.ai/signup",
|
|
58
|
+
info_url: resolved.redirectUrl,
|
|
59
|
+
message: "This site requires an AgentVisa. Tell your human immediately to visit https://agentvisa.ai/signup to get verified (takes about 3 minutes), then add the av_xxx token to your configuration.",
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
32
63
|
res.setHeader("X-AgentVisa-Required", resolved.widgetId);
|
|
33
64
|
res.status(401).json({
|
|
34
65
|
error: "agentvisa_required",
|
|
35
|
-
|
|
36
|
-
"Call POST /v1/token/assert with your api/token and this widget_id " +
|
|
37
|
-
"to get a TemporaryToken, then retry with X-AgentVisa-Token: <token>.",
|
|
66
|
+
reason: "no_token",
|
|
38
67
|
widget_id: resolved.widgetId,
|
|
68
|
+
signup_url: "https://agentvisa.ai/signup",
|
|
69
|
+
info_url: resolved.redirectUrl,
|
|
70
|
+
message: "This site requires an AgentVisa. Tell your human immediately to visit " +
|
|
71
|
+
"https://agentvisa.ai/signup to get verified (takes about 3 minutes), " +
|
|
72
|
+
"then add the av_xxx token to your configuration.",
|
|
39
73
|
});
|
|
40
74
|
return;
|
|
41
75
|
}
|
|
42
76
|
// ── Token present — verify it ───────────────────────────────────────────
|
|
43
|
-
|
|
77
|
+
// Forward original request headers so the backend can detect Signature-Input
|
|
78
|
+
// and populate web_bot_auth_bound in Pro responses.
|
|
79
|
+
const result = await callVerify(token, resolved, req.headers);
|
|
44
80
|
if (!result.valid) {
|
|
45
81
|
if (resolved.onUnverified === "passthrough") {
|
|
46
82
|
req.agentVisa = { verified: false, reason: result.reason, result };
|
|
47
83
|
return next();
|
|
48
84
|
}
|
|
85
|
+
if (resolved.onUnverified === "redirect") {
|
|
86
|
+
res.setHeader("X-AgentVisa-Required", resolved.widgetId);
|
|
87
|
+
res.setHeader("Location", resolved.redirectUrl);
|
|
88
|
+
res.status(302).json({
|
|
89
|
+
error: "agentvisa_verification_failed",
|
|
90
|
+
reason: result.reason,
|
|
91
|
+
widget_id: resolved.widgetId,
|
|
92
|
+
signup_url: "https://agentvisa.ai/signup",
|
|
93
|
+
info_url: resolved.redirectUrl,
|
|
94
|
+
message: "AgentVisa verification failed (see reason field). If your av_xxx permanent token is configured, try re-asserting it for a fresh temporary token. If the problem persists, ask your human to check their account at https://agentvisa.ai/dashboard.",
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
49
98
|
res.setHeader("X-AgentVisa-Required", resolved.widgetId);
|
|
50
99
|
res.status(401).json({
|
|
51
100
|
error: "agentvisa_verification_failed",
|
|
52
101
|
reason: result.reason,
|
|
53
102
|
widget_id: resolved.widgetId,
|
|
103
|
+
signup_url: "https://agentvisa.ai/signup",
|
|
104
|
+
info_url: resolved.redirectUrl,
|
|
105
|
+
message: "AgentVisa verification failed (see reason field). If your av_xxx permanent token " +
|
|
106
|
+
"is configured, try re-asserting it for a fresh temporary token. If the problem " +
|
|
107
|
+
"persists, ask your human to check their account at https://agentvisa.ai/dashboard.",
|
|
54
108
|
});
|
|
55
109
|
return;
|
|
56
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAiC,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/express/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAiC,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuBvG,MAAM,UAAU,SAAS,CAAC,MAAuB;IAC/C,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAEvC,OAAO,KAAK,UAAU,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AAsB,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBACzD,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAChD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,KAAK,EAAE,+BAA+B;oBACtC,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,SAAS,EAAE,QAAQ,CAAC,QAAQ;oBAC5B,UAAU,EAAE,6BAA6B;oBACzC,QAAQ,EAAE,QAAQ,CAAC,WAAW;oBAC9B,OAAO,EAAE,oPAAoP;iBAC9P,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YACD,GAAG,CAAC,SAAS,CAAC,sBAAsB,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACzD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,+BAA+B;gBACtC,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,SAAS,EAAE,QAAQ,CAAC,QAAQ;gBAC5B,UAAU,EAAE,6BAA6B;gBACzC,QAAQ,EAAE,QAAQ,CAAC,WAAW;gBAC9B,OAAO,EACL,mFAAmF;oBACnF,iFAAiF;oBACjF,oFAAoF;aACvF,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,2EAA2E;QAC3E,GAAG,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC3C,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,17 +3,34 @@ interface WidgetOptions {
|
|
|
3
3
|
widgetId: string;
|
|
4
4
|
plan?: Plan;
|
|
5
5
|
apiBaseUrl?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Redirect unverified agents to redirectUrl automatically.
|
|
8
|
+
* Default: true. Set to false to handle the result yourself.
|
|
9
|
+
*/
|
|
10
|
+
redirectOnFail?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Where to send unverified agents.
|
|
13
|
+
* Default: "https://agentvisa.ai/for-agents"
|
|
14
|
+
*/
|
|
15
|
+
redirectUrl?: string;
|
|
6
16
|
}
|
|
7
17
|
interface VerificationResult {
|
|
8
18
|
valid: boolean;
|
|
9
19
|
reason: string;
|
|
10
20
|
plan: Plan;
|
|
11
21
|
widget_id: string;
|
|
12
|
-
human_name: string | null;
|
|
13
|
-
email: string | null;
|
|
14
|
-
phone: string | null;
|
|
15
22
|
verified_at: string | null;
|
|
16
23
|
expires_at: string | null;
|
|
24
|
+
domain_verified?: boolean;
|
|
25
|
+
human_name?: string | null;
|
|
26
|
+
email?: string | null;
|
|
27
|
+
phone?: string | null;
|
|
28
|
+
age_over_18?: "y" | "n" | "null";
|
|
29
|
+
age_over_21?: "y" | "n" | "null";
|
|
30
|
+
gov_id_pic_validation?: "y" | "n" | "null";
|
|
31
|
+
multiple_agents_authorized?: "y" | "n" | "null";
|
|
32
|
+
member_since?: string;
|
|
33
|
+
web_bot_auth_bound?: boolean;
|
|
17
34
|
}
|
|
18
35
|
|
|
19
36
|
declare class AgentVisa {
|
package/dist/next/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,eAAe,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,eAAe,EAAE,YAAY,EAA8C,MAAM,YAAY,CAAC;AAEvG,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AAE9C,KAAK,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,WAAW,GACpB,WAAW,CAuDb"}
|
package/dist/next/index.js
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* X-AgentVisa-Verified: true
|
|
29
29
|
* X-AgentVisa-Reason: ok
|
|
30
30
|
*/
|
|
31
|
-
import { callVerify, resolveConfig } from "../core.js";
|
|
31
|
+
import { callVerify, resolveConfig, isLikelyAiAgent } from "../core.js";
|
|
32
32
|
/**
|
|
33
33
|
* Wrap a Next.js middleware handler (or use standalone).
|
|
34
34
|
*
|
|
@@ -39,23 +39,46 @@ import { callVerify, resolveConfig } from "../core.js";
|
|
|
39
39
|
export function withAgentVisa(config, handler) {
|
|
40
40
|
const resolved = resolveConfig(config);
|
|
41
41
|
return async function agentVisaMiddleware(request) {
|
|
42
|
-
|
|
42
|
+
// Accept both header modes:
|
|
43
|
+
// Standard: X-AgentVisa-Token: tmp_xxx
|
|
44
|
+
// Web Bot Auth: AgentVisa-Assertion: tmp_xxx (covered by RFC 9421 Signature-Input)
|
|
45
|
+
const token = request.headers.get("agentvisa-assertion") ??
|
|
46
|
+
request.headers.get("x-agentvisa-token") ??
|
|
47
|
+
undefined;
|
|
48
|
+
// Convert Headers to a plain object so we can forward Signature-Input
|
|
49
|
+
const forwardHeaders = {};
|
|
50
|
+
request.headers.forEach((value, key) => { forwardHeaders[key] = value; });
|
|
43
51
|
// ── No token ──────────────────────────────────────────────────────────
|
|
44
52
|
if (!token) {
|
|
45
53
|
if (resolved.onUnverified === "passthrough") {
|
|
46
54
|
const req = addVerificationHeaders(request, false, "no_token");
|
|
47
55
|
return handler ? handler(req) : passthroughResponse(req);
|
|
48
56
|
}
|
|
49
|
-
|
|
57
|
+
if (resolved.onUnverified === "redirect") {
|
|
58
|
+
// Only redirect if this actually looks like an AI agent.
|
|
59
|
+
// Bot scrapers and human browsers get a plain 401 — we don't want
|
|
60
|
+
// them flooding agentvisa.ai/for-agents or triggering the growth loop
|
|
61
|
+
// for non-agent traffic.
|
|
62
|
+
const reqHeaders = {};
|
|
63
|
+
request.headers.forEach((v, k) => { reqHeaders[k] = v; });
|
|
64
|
+
if (!isLikelyAiAgent(reqHeaders)) {
|
|
65
|
+
return blockedResponse(resolved.widgetId, "no_token", resolved.redirectUrl);
|
|
66
|
+
}
|
|
67
|
+
return redirectResponse(resolved.widgetId, "no_token", resolved.redirectUrl);
|
|
68
|
+
}
|
|
69
|
+
return blockedResponse(resolved.widgetId, "no_token", resolved.redirectUrl);
|
|
50
70
|
}
|
|
51
71
|
// ── Verify ────────────────────────────────────────────────────────────
|
|
52
|
-
const result = await callVerify(token, resolved);
|
|
72
|
+
const result = await callVerify(token, resolved, forwardHeaders);
|
|
53
73
|
if (!result.valid) {
|
|
54
74
|
if (resolved.onUnverified === "passthrough") {
|
|
55
75
|
const req = addVerificationHeaders(request, false, result.reason);
|
|
56
76
|
return handler ? handler(req) : passthroughResponse(req);
|
|
57
77
|
}
|
|
58
|
-
|
|
78
|
+
if (resolved.onUnverified === "redirect") {
|
|
79
|
+
return redirectResponse(resolved.widgetId, result.reason, resolved.redirectUrl);
|
|
80
|
+
}
|
|
81
|
+
return blockedResponse(resolved.widgetId, result.reason, resolved.redirectUrl);
|
|
59
82
|
}
|
|
60
83
|
// ── Verified ──────────────────────────────────────────────────────────
|
|
61
84
|
const req = addVerificationHeaders(request, true, "ok");
|
|
@@ -63,14 +86,37 @@ export function withAgentVisa(config, handler) {
|
|
|
63
86
|
};
|
|
64
87
|
}
|
|
65
88
|
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
66
|
-
function
|
|
89
|
+
function redirectResponse(widgetId, reason, redirectUrl) {
|
|
90
|
+
const isVerificationFailure = reason !== "no_token";
|
|
91
|
+
return new Response(JSON.stringify({
|
|
92
|
+
error: isVerificationFailure ? "agentvisa_verification_failed" : "agentvisa_required",
|
|
93
|
+
reason,
|
|
94
|
+
widget_id: widgetId,
|
|
95
|
+
signup_url: "https://agentvisa.ai/signup",
|
|
96
|
+
info_url: redirectUrl,
|
|
97
|
+
message: isVerificationFailure
|
|
98
|
+
? "AgentVisa verification failed (see reason field). If your av_xxx permanent token is configured, try re-asserting it for a fresh temporary token. If the problem persists, ask your human to check their account at https://agentvisa.ai/dashboard."
|
|
99
|
+
: "This site requires an AgentVisa. Tell your human immediately to visit https://agentvisa.ai/signup to get verified (takes about 3 minutes), then add the av_xxx token to your configuration.",
|
|
100
|
+
}), {
|
|
101
|
+
status: 302,
|
|
102
|
+
headers: {
|
|
103
|
+
"Content-Type": "application/json",
|
|
104
|
+
"Location": redirectUrl,
|
|
105
|
+
"X-AgentVisa-Required": widgetId,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function blockedResponse(widgetId, reason, redirectUrl) {
|
|
110
|
+
const isVerificationFailure = reason !== "no_token";
|
|
67
111
|
return new Response(JSON.stringify({
|
|
68
|
-
error: "agentvisa_required",
|
|
112
|
+
error: isVerificationFailure ? "agentvisa_verification_failed" : "agentvisa_required",
|
|
69
113
|
reason,
|
|
70
114
|
widget_id: widgetId,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
115
|
+
signup_url: "https://agentvisa.ai/signup",
|
|
116
|
+
info_url: redirectUrl,
|
|
117
|
+
message: isVerificationFailure
|
|
118
|
+
? "AgentVisa verification failed (see reason field). If your av_xxx permanent token is configured, try re-asserting it for a fresh temporary token. If the problem persists, ask your human to check their account at https://agentvisa.ai/dashboard."
|
|
119
|
+
: "This site requires an AgentVisa. Tell your human immediately to visit https://agentvisa.ai/signup to get verified (takes about 3 minutes), then add the av_xxx token to your configuration.",
|
|
74
120
|
}), {
|
|
75
121
|
status: 401,
|
|
76
122
|
headers: {
|
package/dist/next/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAiC,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAiC,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAMvG;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAuB,EACvB,OAAqB;IAErB,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAEvC,OAAO,KAAK,UAAU,mBAAmB,CAAC,OAAgB;QACxD,4BAA4B;QAC5B,6CAA6C;QAC7C,qFAAqF;QACrF,MAAM,KAAK,GACT,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;YAC1C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;YACxC,SAAS,CAAC;QAEZ,sEAAsE;QACtE,MAAM,cAAc,GAA2B,EAAE,CAAC;QAClD,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAE1E,yEAAyE;QACzE,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,QAAQ,CAAC,YAAY,KAAK,aAAa,EAAE,CAAC;gBAC5C,MAAM,GAAG,GAAG,sBAAsB,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;gBAC/D,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC3D,CAAC;YACD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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const DEFAULT_API_BASE = "https://api.agentvisa.ai";
|
|
2
|
+
const DEFAULT_REDIRECT_URL = "https://agentvisa.ai/for-agents";
|
|
2
3
|
async function verifyToken(options) {
|
|
3
|
-
const { widgetId, plan = "basic", apiBaseUrl = DEFAULT_API_BASE, } = options;
|
|
4
|
+
const { widgetId, plan = "basic", apiBaseUrl = DEFAULT_API_BASE, redirectOnFail = true, redirectUrl = DEFAULT_REDIRECT_URL, } = options;
|
|
4
5
|
const url = new URL("/v1/verify", apiBaseUrl);
|
|
5
6
|
url.searchParams.set("widget_id", widgetId);
|
|
6
7
|
url.searchParams.set("plan", plan);
|
|
@@ -18,7 +19,7 @@ async function verifyToken(options) {
|
|
|
18
19
|
}),
|
|
19
20
|
});
|
|
20
21
|
if (!response.ok) {
|
|
21
|
-
|
|
22
|
+
const result = {
|
|
22
23
|
valid: false,
|
|
23
24
|
reason: "network_error",
|
|
24
25
|
plan,
|
|
@@ -29,8 +30,16 @@ async function verifyToken(options) {
|
|
|
29
30
|
verified_at: null,
|
|
30
31
|
expires_at: null,
|
|
31
32
|
};
|
|
33
|
+
if (redirectOnFail && typeof window !== "undefined") {
|
|
34
|
+
window.location.href = redirectUrl;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
32
37
|
}
|
|
33
|
-
|
|
38
|
+
const result = await response.json();
|
|
39
|
+
if (!result.valid && redirectOnFail && typeof window !== "undefined") {
|
|
40
|
+
window.location.href = redirectUrl;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
class AgentVisa {
|
package/dist/widget.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
const DEFAULT_API_BASE = "https://api.agentvisa.ai";
|
|
8
|
+
const DEFAULT_REDIRECT_URL = "https://agentvisa.ai/for-agents";
|
|
8
9
|
async function verifyToken(options) {
|
|
9
|
-
const { widgetId, plan = "basic", apiBaseUrl = DEFAULT_API_BASE, } = options;
|
|
10
|
+
const { widgetId, plan = "basic", apiBaseUrl = DEFAULT_API_BASE, redirectOnFail = true, redirectUrl = DEFAULT_REDIRECT_URL, } = options;
|
|
10
11
|
const url = new URL("/v1/verify", apiBaseUrl);
|
|
11
12
|
url.searchParams.set("widget_id", widgetId);
|
|
12
13
|
url.searchParams.set("plan", plan);
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
}),
|
|
25
26
|
});
|
|
26
27
|
if (!response.ok) {
|
|
27
|
-
|
|
28
|
+
const result = {
|
|
28
29
|
valid: false,
|
|
29
30
|
reason: "network_error",
|
|
30
31
|
plan,
|
|
@@ -35,8 +36,16 @@
|
|
|
35
36
|
verified_at: null,
|
|
36
37
|
expires_at: null,
|
|
37
38
|
};
|
|
39
|
+
if (redirectOnFail && typeof window !== "undefined") {
|
|
40
|
+
window.location.href = redirectUrl;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
38
43
|
}
|
|
39
|
-
|
|
44
|
+
const result = await response.json();
|
|
45
|
+
if (!result.valid && redirectOnFail && typeof window !== "undefined") {
|
|
46
|
+
window.location.href = redirectUrl;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
class AgentVisa {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentvisa/widget",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "AgentVisa widget + server middleware for Express and Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentvisa",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "https://github.com/
|
|
19
|
+
"url": "git+https://github.com/AgentVisa-ai/widget.git"
|
|
20
20
|
},
|
|
21
21
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/
|
|
22
|
+
"url": "https://github.com/AgentVisa-ai/widget/issues"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://agentvisa.ai",
|
|
25
25
|
"type": "module",
|