@kya-os/checkpoint-nextjs 1.10.0 → 1.12.0
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/CHANGELOG.md +261 -0
- package/README.md +217 -35
- package/dist/{adapt.mjs → adapt-BvqYgrAk.mjs} +15 -4
- package/dist/adapt-BvqYgrAk.mjs.map +1 -0
- package/dist/{adapt.js → adapt-DUEIfZnx.js} +34 -13
- package/dist/api-client-JHOrRUA_.d.mts +222 -0
- package/dist/api-client-JHOrRUA_.d.mts.map +1 -0
- package/dist/api-client-JHOrRUA_.d.ts +222 -0
- package/dist/api-client-JHOrRUA_.d.ts.map +1 -0
- package/dist/api-client.d.mts +2 -204
- package/dist/api-client.d.ts +2 -204
- package/dist/api-client.js +19 -18
- package/dist/api-client.mjs +20 -16
- package/dist/api-client.mjs.map +1 -1
- package/dist/api-middleware-BtsYJU5u.d.mts +131 -0
- package/dist/api-middleware-BtsYJU5u.d.mts.map +1 -0
- package/dist/{api-middleware-CMDRoQik.mjs → api-middleware-DvmkJ_Li.mjs} +68 -38
- package/dist/api-middleware-DvmkJ_Li.mjs.map +1 -0
- package/dist/api-middleware-DyLDqOYF.d.ts +131 -0
- package/dist/api-middleware-DyLDqOYF.d.ts.map +1 -0
- package/dist/{api-middleware-CDSh3TSE.js → api-middleware-beNlXd5P.js} +75 -63
- package/dist/api-middleware.d.mts +2 -152
- package/dist/api-middleware.d.ts +2 -152
- package/dist/api-middleware.js +1 -5
- package/dist/api-middleware.mjs +2 -3
- package/dist/cedar-wasm.d.mts +20 -0
- package/dist/cedar-wasm.d.mts.map +1 -0
- package/dist/cedar-wasm.d.ts +19 -0
- package/dist/cedar-wasm.d.ts.map +1 -0
- package/dist/cedar-wasm.js +24 -0
- package/dist/cedar-wasm.mjs +23 -0
- package/dist/cedar-wasm.mjs.map +1 -0
- package/dist/config-D7h2w_it.d.mts +89 -0
- package/dist/config-D7h2w_it.d.mts.map +1 -0
- package/dist/config-DkXvl4nH.d.ts +89 -0
- package/dist/config-DkXvl4nH.d.ts.map +1 -0
- package/dist/engine-wasm.d.mts +20 -0
- package/dist/engine-wasm.d.mts.map +1 -0
- package/dist/engine-wasm.d.ts +19 -0
- package/dist/engine-wasm.d.ts.map +1 -0
- package/dist/engine-wasm.js +24 -0
- package/dist/engine-wasm.mjs +23 -0
- package/dist/engine-wasm.mjs.map +1 -0
- package/dist/index-edge.d.mts +8 -0
- package/dist/index-edge.d.ts +8 -0
- package/dist/index-edge.js +14 -0
- package/dist/index-edge.mjs +7 -0
- package/dist/index.d.mts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +20 -49
- package/dist/index.mjs +21 -8
- package/dist/index.mjs.map +1 -1
- package/dist/middleware-bundler.d.mts +1 -1
- package/dist/middleware-bundler.d.mts.map +1 -1
- package/dist/middleware-bundler.d.ts +1 -1
- package/dist/middleware-bundler.d.ts.map +1 -1
- package/dist/middleware-bundler.js +5 -5
- package/dist/middleware-bundler.mjs +5 -5
- package/dist/middleware-bundler.mjs.map +1 -1
- package/dist/middleware-core-B1GuspOY.js +169 -0
- package/dist/middleware-core-BmW2kH8J.d.ts +14 -0
- package/dist/middleware-core-BmW2kH8J.d.ts.map +1 -0
- package/dist/middleware-core-CnPUoD2v.d.mts +14 -0
- package/dist/middleware-core-CnPUoD2v.d.mts.map +1 -0
- package/dist/middleware-core-WZeMSRqx.mjs +159 -0
- package/dist/middleware-core-WZeMSRqx.mjs.map +1 -0
- package/dist/middleware-edge.d.mts +11 -3
- package/dist/middleware-edge.d.mts.map +1 -1
- package/dist/middleware-edge.d.ts +11 -3
- package/dist/middleware-edge.d.ts.map +1 -1
- package/dist/middleware-edge.js +68 -29
- package/dist/middleware-edge.mjs +68 -31
- package/dist/middleware-edge.mjs.map +1 -1
- package/dist/middleware-node-context-BvqrL2Ra.mjs +16 -0
- package/dist/middleware-node-context-BvqrL2Ra.mjs.map +1 -0
- package/dist/middleware-node-context-TRMTgp3y.js +20 -0
- package/dist/middleware-node.d.mts +12 -3
- package/dist/middleware-node.d.mts.map +1 -0
- package/dist/middleware-node.d.ts +12 -3
- package/dist/middleware-node.d.ts.map +1 -0
- package/dist/middleware-node.js +14 -6
- package/dist/middleware-node.mjs +14 -6
- package/dist/middleware-node.mjs.map +1 -1
- package/dist/posture-outcome-Ccujx_9V.d.mts +14 -0
- package/dist/posture-outcome-Ccujx_9V.d.mts.map +1 -0
- package/dist/posture-outcome-Ccujx_9V.d.ts +14 -0
- package/dist/posture-outcome-Ccujx_9V.d.ts.map +1 -0
- package/dist/posture-outcome-DQ4fdMfq.mjs +21 -0
- package/dist/posture-outcome-DQ4fdMfq.mjs.map +1 -0
- package/dist/posture-outcome-DddsJtL8.js +25 -0
- package/dist/public-api-Cw7Zj290.d.ts +5 -0
- package/dist/public-api-DgCw1uo6.d.mts +5 -0
- package/dist/rolldown-runtime-C24Yb2bl.js +33 -0
- package/dist/utils-Cnwg0VrY.mjs +88 -0
- package/dist/utils-Cnwg0VrY.mjs.map +1 -0
- package/dist/utils-dyFxqlFI.js +104 -0
- package/package.json +27 -62
- package/EDGE_RUNTIME_WASM_SETUP.md +0 -342
- package/bin/setup-edge-wasm.js +0 -513
- package/dist/adapt.d.mts +0 -11
- package/dist/adapt.d.mts.map +0 -1
- package/dist/adapt.d.ts +0 -11
- package/dist/adapt.d.ts.map +0 -1
- package/dist/adapt.mjs.map +0 -1
- package/dist/api-client.d.mts.map +0 -1
- package/dist/api-client.d.ts.map +0 -1
- package/dist/api-middleware-CMDRoQik.mjs.map +0 -1
- package/dist/api-middleware.d.mts.map +0 -1
- package/dist/api-middleware.d.ts.map +0 -1
- package/dist/composed-policy-BCaNiVHv.d.mts +0 -98
- package/dist/composed-policy-BCaNiVHv.d.mts.map +0 -1
- package/dist/composed-policy-zzJYNFTb.d.ts +0 -98
- package/dist/composed-policy-zzJYNFTb.d.ts.map +0 -1
- package/dist/composed-policy.d.mts +0 -2
- package/dist/composed-policy.d.ts +0 -2
- package/dist/composed-policy.js +0 -136
- package/dist/composed-policy.mjs +0 -132
- package/dist/composed-policy.mjs.map +0 -1
- package/dist/config-CbAg2mze.d.ts +0 -255
- package/dist/config-CbAg2mze.d.ts.map +0 -1
- package/dist/config-Doe0Tn53.d.mts +0 -255
- package/dist/config-Doe0Tn53.d.mts.map +0 -1
- package/dist/create-middleware.d.mts +0 -11
- package/dist/create-middleware.d.mts.map +0 -1
- package/dist/create-middleware.d.ts +0 -11
- package/dist/create-middleware.d.ts.map +0 -1
- package/dist/create-middleware.js +0 -39
- package/dist/create-middleware.mjs +0 -38
- package/dist/create-middleware.mjs.map +0 -1
- package/dist/edge/index.d.mts +0 -88
- package/dist/edge/index.d.mts.map +0 -1
- package/dist/edge/index.d.ts +0 -88
- package/dist/edge/index.d.ts.map +0 -1
- package/dist/edge/index.js +0 -362
- package/dist/edge/index.mjs +0 -362
- package/dist/edge/index.mjs.map +0 -1
- package/dist/edge-runtime-loader.d.mts +0 -49
- package/dist/edge-runtime-loader.d.mts.map +0 -1
- package/dist/edge-runtime-loader.d.ts +0 -49
- package/dist/edge-runtime-loader.d.ts.map +0 -1
- package/dist/edge-runtime-loader.js +0 -297
- package/dist/edge-runtime-loader.mjs +0 -292
- package/dist/edge-runtime-loader.mjs.map +0 -1
- package/dist/edge-wasm-middleware.d.mts +0 -43
- package/dist/edge-wasm-middleware.d.mts.map +0 -1
- package/dist/edge-wasm-middleware.d.ts +0 -43
- package/dist/edge-wasm-middleware.d.ts.map +0 -1
- package/dist/edge-wasm-middleware.js +0 -37
- package/dist/edge-wasm-middleware.mjs +0 -35
- package/dist/edge-wasm-middleware.mjs.map +0 -1
- package/dist/middleware-core-BYQP9FND.mjs +0 -165
- package/dist/middleware-core-BYQP9FND.mjs.map +0 -1
- package/dist/middleware-core-D6TijE6P.js +0 -175
- package/dist/middleware-node-CE4GevYs.d.ts +0 -20
- package/dist/middleware-node-CE4GevYs.d.ts.map +0 -1
- package/dist/middleware-node-DtyOuPta.d.mts +0 -20
- package/dist/middleware-node-DtyOuPta.d.mts.map +0 -1
- package/dist/middleware-node-context-BqPbf-fI.mjs +0 -34
- package/dist/middleware-node-context-BqPbf-fI.mjs.map +0 -1
- package/dist/middleware-node-context-rgnc7UNR.js +0 -38
- package/dist/middleware.d.mts +0 -25
- package/dist/middleware.d.mts.map +0 -1
- package/dist/middleware.d.ts +0 -25
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js +0 -53
- package/dist/middleware.mjs +0 -51
- package/dist/middleware.mjs.map +0 -1
- package/dist/nodejs-wasm-loader.d.mts +0 -42
- package/dist/nodejs-wasm-loader.d.mts.map +0 -1
- package/dist/nodejs-wasm-loader.d.ts +0 -42
- package/dist/nodejs-wasm-loader.d.ts.map +0 -1
- package/dist/nodejs-wasm-loader.js +0 -70
- package/dist/nodejs-wasm-loader.mjs +0 -66
- package/dist/nodejs-wasm-loader.mjs.map +0 -1
- package/dist/policy.d.mts +0 -138
- package/dist/policy.d.mts.map +0 -1
- package/dist/policy.d.ts +0 -138
- package/dist/policy.d.ts.map +0 -1
- package/dist/policy.js +0 -236
- package/dist/policy.mjs +0 -205
- package/dist/policy.mjs.map +0 -1
- package/dist/session-tracker.d.mts +0 -50
- package/dist/session-tracker.d.mts.map +0 -1
- package/dist/session-tracker.d.ts +0 -50
- package/dist/session-tracker.d.ts.map +0 -1
- package/dist/session-tracker.js +0 -148
- package/dist/session-tracker.mjs +0 -147
- package/dist/session-tracker.mjs.map +0 -1
- package/dist/translate.d.mts +0 -48
- package/dist/translate.d.mts.map +0 -1
- package/dist/translate.d.ts +0 -48
- package/dist/translate.d.ts.map +0 -1
- package/dist/translate.js +0 -79
- package/dist/translate.mjs +0 -79
- package/dist/translate.mjs.map +0 -1
- package/dist/types-C0SkqLMM.d.mts +0 -102
- package/dist/types-C0SkqLMM.d.mts.map +0 -1
- package/dist/types-C7DNSCTO.d.ts +0 -102
- package/dist/types-C7DNSCTO.d.ts.map +0 -1
- package/dist/utils-Cj4XNhIY.mjs +0 -35
- package/dist/utils-Cj4XNhIY.mjs.map +0 -1
- package/dist/utils-DAisnYnI.js +0 -45
- package/dist/wasm-setup.d.mts +0 -47
- package/dist/wasm-setup.d.mts.map +0 -1
- package/dist/wasm-setup.d.ts +0 -47
- package/dist/wasm-setup.d.ts.map +0 -1
- package/dist/wasm-setup.js +0 -91
- package/dist/wasm-setup.mjs +0 -95
- package/dist/wasm-setup.mjs.map +0 -1
- package/wasm/agentshield_wasm.d.ts +0 -479
- package/wasm/agentshield_wasm.js +0 -1536
- package/wasm/agentshield_wasm_bg.wasm +0 -0
- package/wasm/package.json +0 -30
- package/wasm.d.ts +0 -21
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_utils = require('./utils-DAisnYnI.js');
|
|
3
|
-
let _kya_os_checkpoint_shared = require("@kya-os/checkpoint-shared");
|
|
4
|
-
|
|
5
|
-
//#region src/edge-runtime-loader.ts
|
|
6
|
-
/**
|
|
7
|
-
* Edge Runtime Compatible WASM Loader for Checkpoint
|
|
8
|
-
*
|
|
9
|
-
* This module provides a pre-built solution for loading WASM in Edge Runtime.
|
|
10
|
-
* It requires the WASM file to be manually placed in the project.
|
|
11
|
-
*
|
|
12
|
-
* ## SSOT for pattern detection
|
|
13
|
-
*
|
|
14
|
-
* The fallback `patternDetection` path imports the single canonical
|
|
15
|
-
* pattern table `KNOWN_AGENT_PATTERNS` from
|
|
16
|
-
* `@kya-os/checkpoint-shared/constants/agents`. PDM-2 (#2573) folded
|
|
17
|
-
* what was previously a sibling supplement export
|
|
18
|
-
* (`INTERACTIVE_AGENT_PATTERNS`) into per-agent SSOT rows alongside
|
|
19
|
-
* the existing entries — interactive-session tokens, generic vendor
|
|
20
|
-
* fallbacks, and the GPT-Crawler bot are now first-class SSOT rows
|
|
21
|
-
* with `category`/`isLegitimate` fields. The drift-prevention test
|
|
22
|
-
* in `checkpoint-shared/__tests__/constants/agents.test.ts` enforces
|
|
23
|
-
* that no future PR re-introduces a sibling pool.
|
|
24
|
-
*
|
|
25
|
-
* ## Naming
|
|
26
|
-
*
|
|
27
|
-
* Old `AgentShield`-prefixed exports are kept as `@deprecated` aliases
|
|
28
|
-
* for one release (`createEdgeAgentShield`, `EdgeRuntimeAgentShield`,
|
|
29
|
-
* `AgentShieldConfig`, `getDefaultAgentShield`). New code should import
|
|
30
|
-
* the `Checkpoint`-prefixed names directly.
|
|
31
|
-
*/
|
|
32
|
-
const SUSPICIOUS_HEADER_PREFIXES = [
|
|
33
|
-
"x-openai-",
|
|
34
|
-
"x-anthropic-",
|
|
35
|
-
"x-ai-",
|
|
36
|
-
"x-llm-",
|
|
37
|
-
"x-gpt-"
|
|
38
|
-
];
|
|
39
|
-
/**
|
|
40
|
-
* Escape a string for use as a regex pattern. SSOT tokens contain
|
|
41
|
-
* regex meta-characters (`.`, `+`, etc.) that need escaping before
|
|
42
|
-
* we wrap them in delimiter guards. Standard MDN escape regex.
|
|
43
|
-
*/
|
|
44
|
-
function escapeRegex(s) {
|
|
45
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46
|
-
}
|
|
47
|
-
const REGEX_SYNTAX_PATTERN = /(?:\\.|[()[\]{}|^$]|\.\*|\.\+|\.\?)/;
|
|
48
|
-
/**
|
|
49
|
-
* Build a delimiter-guarded regex for an SSOT token.
|
|
50
|
-
*
|
|
51
|
-
* Pre-fix (cursor #2599): the matcher used bare `lowercasedUa.includes(pattern)`,
|
|
52
|
-
* which produced false positives whenever an SSOT token was a common
|
|
53
|
-
* English substring — `'command'` (Cohere) matched `TotalCommander/10.52`;
|
|
54
|
-
* `'palm'` (Google-Bard) matched `PalmOS-Browser/1.0`. With `blockAgents`
|
|
55
|
-
* enabled these mis-classified legitimate browser traffic as bot.
|
|
56
|
-
*
|
|
57
|
-
* Literal SSOT tokens are escaped before being wrapped in
|
|
58
|
-
* `(^|[^a-z0-9])…($|[^a-z0-9])`. Delimiter guards preserve the
|
|
59
|
-
* substring false-positive fix while still handling tokens that end in
|
|
60
|
-
* punctuation, such as `KYA-Agent/`.
|
|
61
|
-
*
|
|
62
|
-
* - `command` no longer matches `TotalCommander` (`l` is alphanumeric);
|
|
63
|
-
* still matches `cohere-command-r/1.0` and `command-r-plus`.
|
|
64
|
-
* - `palm` no longer matches `PalmOS` (`o` is alphanumeric);
|
|
65
|
-
* still matches `palm-2`.
|
|
66
|
-
*
|
|
67
|
-
* Regex-shaped SSOT entries (for example `BingPreview/.*ChatGPT`) are
|
|
68
|
-
* compiled as regex source to mirror kya-os-engine, where TS patterns
|
|
69
|
-
* are emitted into Rust `Regex::new("(?i)<pattern>")`.
|
|
70
|
-
*
|
|
71
|
-
* Cached so we don't rebuild the same RegExp for every UA.
|
|
72
|
-
*/
|
|
73
|
-
const TOKEN_REGEX_CACHE = /* @__PURE__ */ new Map();
|
|
74
|
-
function tokenRegex(token) {
|
|
75
|
-
const cached = TOKEN_REGEX_CACHE.get(token);
|
|
76
|
-
if (cached) return cached;
|
|
77
|
-
const source = REGEX_SYNTAX_PATTERN.test(token) ? token : escapeRegex(token);
|
|
78
|
-
const regex = new RegExp(`(^|[^a-z0-9])${source}($|[^a-z0-9])`, "i");
|
|
79
|
-
TOKEN_REGEX_CACHE.set(token, regex);
|
|
80
|
-
return regex;
|
|
81
|
-
}
|
|
82
|
-
function readStringField(value) {
|
|
83
|
-
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
84
|
-
}
|
|
85
|
-
function readNumberField(value) {
|
|
86
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
87
|
-
}
|
|
88
|
-
function readBooleanField(value) {
|
|
89
|
-
return typeof value === "boolean" ? value : void 0;
|
|
90
|
-
}
|
|
91
|
-
function readStringArrayField(value) {
|
|
92
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
93
|
-
}
|
|
94
|
-
function normalizeEngineConfidence(value) {
|
|
95
|
-
if (value === void 0) return 0;
|
|
96
|
-
return Math.round(Math.max(0, Math.min(100, value)));
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Match a UA string against `KNOWN_AGENT_PATTERNS` (the canonical SSOT).
|
|
100
|
-
* Returns the highest-confidence matching entry, or `null` if no entry
|
|
101
|
-
* matches.
|
|
102
|
-
*
|
|
103
|
-
* Delimiter anchoring prevents common-English substrings in the SSOT
|
|
104
|
-
* (`command`, `palm`, `Anthropic`) from false-positiving on legitimate
|
|
105
|
-
* UAs (`TotalCommander`, `PalmOS-Browser`, `AnthropicAssistant` —
|
|
106
|
-
* though the last is now stricter post-PDM-2; `Anthropic` must appear
|
|
107
|
-
* as a standalone token).
|
|
108
|
-
*/
|
|
109
|
-
function matchKnownAgent(lowercasedUa) {
|
|
110
|
-
let best = null;
|
|
111
|
-
for (const entry of _kya_os_checkpoint_shared.KNOWN_AGENT_PATTERNS) for (const pattern of entry.patterns) if (tokenRegex(pattern).test(lowercasedUa)) {
|
|
112
|
-
if (!best || entry.confidence > best.confidence) best = {
|
|
113
|
-
name: entry.name,
|
|
114
|
-
confidence: entry.confidence
|
|
115
|
-
};
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
return best;
|
|
119
|
-
}
|
|
120
|
-
var EdgeRuntimeCheckpoint = class {
|
|
121
|
-
wasmInstance = null;
|
|
122
|
-
wasmMemory = null;
|
|
123
|
-
config;
|
|
124
|
-
initialized = false;
|
|
125
|
-
constructor(config = {}) {
|
|
126
|
-
this.config = config;
|
|
127
|
-
}
|
|
128
|
-
async init(wasmModule) {
|
|
129
|
-
if (this.initialized) return;
|
|
130
|
-
const module = wasmModule || this.config.wasmModule;
|
|
131
|
-
if (module && this.config.enableWasm !== false) try {
|
|
132
|
-
this.wasmMemory = new WebAssembly.Memory({
|
|
133
|
-
initial: 17,
|
|
134
|
-
maximum: 256
|
|
135
|
-
});
|
|
136
|
-
const imports = {
|
|
137
|
-
wbg: {
|
|
138
|
-
__wbindgen_throw: (ptr, len) => {
|
|
139
|
-
throw new Error(this.readString(ptr, len));
|
|
140
|
-
},
|
|
141
|
-
__wbg_log_: (ptr, len) => {
|
|
142
|
-
if (this.config.debug) console.log(this.readString(ptr, len));
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
env: { memory: this.wasmMemory }
|
|
146
|
-
};
|
|
147
|
-
this.wasmInstance = await WebAssembly.instantiate(module, imports);
|
|
148
|
-
this.initialized = true;
|
|
149
|
-
if (this.config.debug) console.log("✅ Checkpoint WASM initialized in Edge Runtime");
|
|
150
|
-
} catch (error) {
|
|
151
|
-
console.warn("⚠️ WASM initialization failed, using pattern detection:", error);
|
|
152
|
-
this.initialized = true;
|
|
153
|
-
}
|
|
154
|
-
else this.initialized = true;
|
|
155
|
-
}
|
|
156
|
-
readString(ptr, len) {
|
|
157
|
-
if (!this.wasmInstance || !this.wasmMemory) throw new Error("WASM not initialized");
|
|
158
|
-
const bytes = new Uint8Array(this.wasmMemory.buffer).slice(ptr, ptr + len);
|
|
159
|
-
return new TextDecoder().decode(bytes);
|
|
160
|
-
}
|
|
161
|
-
writeString(str) {
|
|
162
|
-
if (!this.wasmInstance) throw new Error("WASM not initialized");
|
|
163
|
-
const exports = this.wasmInstance.exports;
|
|
164
|
-
const encoded = new TextEncoder().encode(str);
|
|
165
|
-
const ptr = exports.__wbindgen_malloc(encoded.length);
|
|
166
|
-
new Uint8Array(exports.memory.buffer).set(encoded, ptr);
|
|
167
|
-
return [ptr, encoded.length];
|
|
168
|
-
}
|
|
169
|
-
async detect(request) {
|
|
170
|
-
if (!this.initialized) await this.init();
|
|
171
|
-
const metadata = {
|
|
172
|
-
userAgent: request.headers.get("user-agent") || "",
|
|
173
|
-
ipAddress: require_utils.getClientIp(request, this.config.clientIpPolicy) || "",
|
|
174
|
-
headers: Object.fromEntries(request.headers.entries())
|
|
175
|
-
};
|
|
176
|
-
if (this.wasmInstance && this.config.enableWasm !== false) try {
|
|
177
|
-
const exports = this.wasmInstance.exports;
|
|
178
|
-
const [ptr, len] = this.writeString(JSON.stringify(metadata));
|
|
179
|
-
const resultPtr = exports.detect_agent(ptr, len);
|
|
180
|
-
let resultStr = "";
|
|
181
|
-
let offset = 0;
|
|
182
|
-
const memory = new Uint8Array(exports.memory.buffer);
|
|
183
|
-
while (offset < 4096) {
|
|
184
|
-
const byte = memory[resultPtr + offset];
|
|
185
|
-
if (byte === 0 || byte === void 0) break;
|
|
186
|
-
offset++;
|
|
187
|
-
}
|
|
188
|
-
if (offset > 0) resultStr = this.readString(resultPtr, offset);
|
|
189
|
-
exports.__wbindgen_free(ptr, len);
|
|
190
|
-
if (offset > 0) exports.__wbindgen_free(resultPtr, offset);
|
|
191
|
-
const result = JSON.parse(resultStr);
|
|
192
|
-
const agent = readStringField(result.agent) ?? readStringField(result.agentName);
|
|
193
|
-
const confidence = normalizeEngineConfidence(readNumberField(result.confidence));
|
|
194
|
-
const detection = {
|
|
195
|
-
isAgent: readBooleanField(result.isAgent) ?? readBooleanField(result.is_agent) ?? false,
|
|
196
|
-
isAiCrawler: readBooleanField(result.isAiCrawler) ?? readBooleanField(result.is_ai_crawler),
|
|
197
|
-
confidence,
|
|
198
|
-
detectionClass: agent ? {
|
|
199
|
-
type: "AiAgent",
|
|
200
|
-
agentType: agent
|
|
201
|
-
} : { type: confidence > 0 ? "IncompleteData" : "Human" },
|
|
202
|
-
detectedAgent: agent ? {
|
|
203
|
-
type: "ai_agent",
|
|
204
|
-
name: agent
|
|
205
|
-
} : void 0,
|
|
206
|
-
agent,
|
|
207
|
-
agentType: agent,
|
|
208
|
-
reasons: readStringArrayField(result.reasons),
|
|
209
|
-
signals: [],
|
|
210
|
-
verificationMethod: "signature",
|
|
211
|
-
riskLevel: readStringField(result.riskLevel) ?? readStringField(result.risk_level),
|
|
212
|
-
timestamp: Date.now()
|
|
213
|
-
};
|
|
214
|
-
if (this.config.onAgentDetected && detection.isAgent) this.config.onAgentDetected(detection);
|
|
215
|
-
return detection;
|
|
216
|
-
} catch (error) {
|
|
217
|
-
if (this.config.debug) console.error("WASM detection failed:", error);
|
|
218
|
-
}
|
|
219
|
-
return this.patternDetection(metadata);
|
|
220
|
-
}
|
|
221
|
-
patternDetection(metadata) {
|
|
222
|
-
const lowercasedUa = metadata.userAgent.toLowerCase();
|
|
223
|
-
let headerBoost = 0;
|
|
224
|
-
for (const key of Object.keys(metadata.headers)) if (SUSPICIOUS_HEADER_PREFIXES.some((prefix) => key.toLowerCase().startsWith(prefix))) {
|
|
225
|
-
headerBoost = .1;
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
const match = matchKnownAgent(lowercasedUa);
|
|
229
|
-
if (match) {
|
|
230
|
-
const finalConfidence = Math.min(match.confidence + headerBoost, 1);
|
|
231
|
-
const result = {
|
|
232
|
-
isAgent: true,
|
|
233
|
-
confidence: Math.round(finalConfidence * 100),
|
|
234
|
-
detectionClass: {
|
|
235
|
-
type: "AiAgent",
|
|
236
|
-
agentType: match.name
|
|
237
|
-
},
|
|
238
|
-
detectedAgent: {
|
|
239
|
-
type: "ai_agent",
|
|
240
|
-
name: match.name
|
|
241
|
-
},
|
|
242
|
-
agent: match.name,
|
|
243
|
-
agentType: match.name,
|
|
244
|
-
reasons: [`known_pattern:${match.name.toLowerCase()}`],
|
|
245
|
-
signals: [],
|
|
246
|
-
verificationMethod: "pattern",
|
|
247
|
-
riskLevel: finalConfidence > .9 ? "high" : "medium",
|
|
248
|
-
timestamp: Date.now()
|
|
249
|
-
};
|
|
250
|
-
if (this.config.onAgentDetected) this.config.onAgentDetected(result);
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
isAgent: false,
|
|
255
|
-
confidence: 0,
|
|
256
|
-
detectionClass: { type: "Human" },
|
|
257
|
-
reasons: ["No known agent indicators matched"],
|
|
258
|
-
signals: [],
|
|
259
|
-
verificationMethod: "pattern",
|
|
260
|
-
timestamp: Date.now()
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
isInitialized() {
|
|
264
|
-
return this.initialized;
|
|
265
|
-
}
|
|
266
|
-
getVerificationMethod() {
|
|
267
|
-
return this.wasmInstance ? "cryptographic" : "pattern";
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* Factory function to create a Checkpoint instance for Edge Runtime.
|
|
272
|
-
*/
|
|
273
|
-
function createEdgeCheckpoint(config) {
|
|
274
|
-
return new EdgeRuntimeCheckpoint(config);
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Singleton instance for simple usage.
|
|
278
|
-
*/
|
|
279
|
-
let defaultInstance = null;
|
|
280
|
-
function getDefaultEdgeCheckpoint(config) {
|
|
281
|
-
if (!defaultInstance) defaultInstance = new EdgeRuntimeCheckpoint(config);
|
|
282
|
-
return defaultInstance;
|
|
283
|
-
}
|
|
284
|
-
/** @deprecated Renamed to {@link EdgeRuntimeCheckpoint}. */
|
|
285
|
-
const EdgeRuntimeAgentShield = EdgeRuntimeCheckpoint;
|
|
286
|
-
/** @deprecated Renamed to {@link createEdgeCheckpoint}. */
|
|
287
|
-
const createEdgeAgentShield = createEdgeCheckpoint;
|
|
288
|
-
/** @deprecated Renamed to {@link getDefaultEdgeCheckpoint}. */
|
|
289
|
-
const getDefaultAgentShield = getDefaultEdgeCheckpoint;
|
|
290
|
-
|
|
291
|
-
//#endregion
|
|
292
|
-
exports.EdgeRuntimeAgentShield = EdgeRuntimeAgentShield;
|
|
293
|
-
exports.EdgeRuntimeCheckpoint = EdgeRuntimeCheckpoint;
|
|
294
|
-
exports.createEdgeAgentShield = createEdgeAgentShield;
|
|
295
|
-
exports.createEdgeCheckpoint = createEdgeCheckpoint;
|
|
296
|
-
exports.getDefaultAgentShield = getDefaultAgentShield;
|
|
297
|
-
exports.getDefaultEdgeCheckpoint = getDefaultEdgeCheckpoint;
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { t as getClientIp } from "./utils-Cj4XNhIY.mjs";
|
|
2
|
-
import { KNOWN_AGENT_PATTERNS } from "@kya-os/checkpoint-shared";
|
|
3
|
-
|
|
4
|
-
//#region src/edge-runtime-loader.ts
|
|
5
|
-
/**
|
|
6
|
-
* Edge Runtime Compatible WASM Loader for Checkpoint
|
|
7
|
-
*
|
|
8
|
-
* This module provides a pre-built solution for loading WASM in Edge Runtime.
|
|
9
|
-
* It requires the WASM file to be manually placed in the project.
|
|
10
|
-
*
|
|
11
|
-
* ## SSOT for pattern detection
|
|
12
|
-
*
|
|
13
|
-
* The fallback `patternDetection` path imports the single canonical
|
|
14
|
-
* pattern table `KNOWN_AGENT_PATTERNS` from
|
|
15
|
-
* `@kya-os/checkpoint-shared/constants/agents`. PDM-2 (#2573) folded
|
|
16
|
-
* what was previously a sibling supplement export
|
|
17
|
-
* (`INTERACTIVE_AGENT_PATTERNS`) into per-agent SSOT rows alongside
|
|
18
|
-
* the existing entries — interactive-session tokens, generic vendor
|
|
19
|
-
* fallbacks, and the GPT-Crawler bot are now first-class SSOT rows
|
|
20
|
-
* with `category`/`isLegitimate` fields. The drift-prevention test
|
|
21
|
-
* in `checkpoint-shared/__tests__/constants/agents.test.ts` enforces
|
|
22
|
-
* that no future PR re-introduces a sibling pool.
|
|
23
|
-
*
|
|
24
|
-
* ## Naming
|
|
25
|
-
*
|
|
26
|
-
* Old `AgentShield`-prefixed exports are kept as `@deprecated` aliases
|
|
27
|
-
* for one release (`createEdgeAgentShield`, `EdgeRuntimeAgentShield`,
|
|
28
|
-
* `AgentShieldConfig`, `getDefaultAgentShield`). New code should import
|
|
29
|
-
* the `Checkpoint`-prefixed names directly.
|
|
30
|
-
*/
|
|
31
|
-
const SUSPICIOUS_HEADER_PREFIXES = [
|
|
32
|
-
"x-openai-",
|
|
33
|
-
"x-anthropic-",
|
|
34
|
-
"x-ai-",
|
|
35
|
-
"x-llm-",
|
|
36
|
-
"x-gpt-"
|
|
37
|
-
];
|
|
38
|
-
/**
|
|
39
|
-
* Escape a string for use as a regex pattern. SSOT tokens contain
|
|
40
|
-
* regex meta-characters (`.`, `+`, etc.) that need escaping before
|
|
41
|
-
* we wrap them in delimiter guards. Standard MDN escape regex.
|
|
42
|
-
*/
|
|
43
|
-
function escapeRegex(s) {
|
|
44
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
45
|
-
}
|
|
46
|
-
const REGEX_SYNTAX_PATTERN = /(?:\\.|[()[\]{}|^$]|\.\*|\.\+|\.\?)/;
|
|
47
|
-
/**
|
|
48
|
-
* Build a delimiter-guarded regex for an SSOT token.
|
|
49
|
-
*
|
|
50
|
-
* Pre-fix (cursor #2599): the matcher used bare `lowercasedUa.includes(pattern)`,
|
|
51
|
-
* which produced false positives whenever an SSOT token was a common
|
|
52
|
-
* English substring — `'command'` (Cohere) matched `TotalCommander/10.52`;
|
|
53
|
-
* `'palm'` (Google-Bard) matched `PalmOS-Browser/1.0`. With `blockAgents`
|
|
54
|
-
* enabled these mis-classified legitimate browser traffic as bot.
|
|
55
|
-
*
|
|
56
|
-
* Literal SSOT tokens are escaped before being wrapped in
|
|
57
|
-
* `(^|[^a-z0-9])…($|[^a-z0-9])`. Delimiter guards preserve the
|
|
58
|
-
* substring false-positive fix while still handling tokens that end in
|
|
59
|
-
* punctuation, such as `KYA-Agent/`.
|
|
60
|
-
*
|
|
61
|
-
* - `command` no longer matches `TotalCommander` (`l` is alphanumeric);
|
|
62
|
-
* still matches `cohere-command-r/1.0` and `command-r-plus`.
|
|
63
|
-
* - `palm` no longer matches `PalmOS` (`o` is alphanumeric);
|
|
64
|
-
* still matches `palm-2`.
|
|
65
|
-
*
|
|
66
|
-
* Regex-shaped SSOT entries (for example `BingPreview/.*ChatGPT`) are
|
|
67
|
-
* compiled as regex source to mirror kya-os-engine, where TS patterns
|
|
68
|
-
* are emitted into Rust `Regex::new("(?i)<pattern>")`.
|
|
69
|
-
*
|
|
70
|
-
* Cached so we don't rebuild the same RegExp for every UA.
|
|
71
|
-
*/
|
|
72
|
-
const TOKEN_REGEX_CACHE = /* @__PURE__ */ new Map();
|
|
73
|
-
function tokenRegex(token) {
|
|
74
|
-
const cached = TOKEN_REGEX_CACHE.get(token);
|
|
75
|
-
if (cached) return cached;
|
|
76
|
-
const source = REGEX_SYNTAX_PATTERN.test(token) ? token : escapeRegex(token);
|
|
77
|
-
const regex = new RegExp(`(^|[^a-z0-9])${source}($|[^a-z0-9])`, "i");
|
|
78
|
-
TOKEN_REGEX_CACHE.set(token, regex);
|
|
79
|
-
return regex;
|
|
80
|
-
}
|
|
81
|
-
function readStringField(value) {
|
|
82
|
-
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
83
|
-
}
|
|
84
|
-
function readNumberField(value) {
|
|
85
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
86
|
-
}
|
|
87
|
-
function readBooleanField(value) {
|
|
88
|
-
return typeof value === "boolean" ? value : void 0;
|
|
89
|
-
}
|
|
90
|
-
function readStringArrayField(value) {
|
|
91
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
92
|
-
}
|
|
93
|
-
function normalizeEngineConfidence(value) {
|
|
94
|
-
if (value === void 0) return 0;
|
|
95
|
-
return Math.round(Math.max(0, Math.min(100, value)));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Match a UA string against `KNOWN_AGENT_PATTERNS` (the canonical SSOT).
|
|
99
|
-
* Returns the highest-confidence matching entry, or `null` if no entry
|
|
100
|
-
* matches.
|
|
101
|
-
*
|
|
102
|
-
* Delimiter anchoring prevents common-English substrings in the SSOT
|
|
103
|
-
* (`command`, `palm`, `Anthropic`) from false-positiving on legitimate
|
|
104
|
-
* UAs (`TotalCommander`, `PalmOS-Browser`, `AnthropicAssistant` —
|
|
105
|
-
* though the last is now stricter post-PDM-2; `Anthropic` must appear
|
|
106
|
-
* as a standalone token).
|
|
107
|
-
*/
|
|
108
|
-
function matchKnownAgent(lowercasedUa) {
|
|
109
|
-
let best = null;
|
|
110
|
-
for (const entry of KNOWN_AGENT_PATTERNS) for (const pattern of entry.patterns) if (tokenRegex(pattern).test(lowercasedUa)) {
|
|
111
|
-
if (!best || entry.confidence > best.confidence) best = {
|
|
112
|
-
name: entry.name,
|
|
113
|
-
confidence: entry.confidence
|
|
114
|
-
};
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
return best;
|
|
118
|
-
}
|
|
119
|
-
var EdgeRuntimeCheckpoint = class {
|
|
120
|
-
wasmInstance = null;
|
|
121
|
-
wasmMemory = null;
|
|
122
|
-
config;
|
|
123
|
-
initialized = false;
|
|
124
|
-
constructor(config = {}) {
|
|
125
|
-
this.config = config;
|
|
126
|
-
}
|
|
127
|
-
async init(wasmModule) {
|
|
128
|
-
if (this.initialized) return;
|
|
129
|
-
const module = wasmModule || this.config.wasmModule;
|
|
130
|
-
if (module && this.config.enableWasm !== false) try {
|
|
131
|
-
this.wasmMemory = new WebAssembly.Memory({
|
|
132
|
-
initial: 17,
|
|
133
|
-
maximum: 256
|
|
134
|
-
});
|
|
135
|
-
const imports = {
|
|
136
|
-
wbg: {
|
|
137
|
-
__wbindgen_throw: (ptr, len) => {
|
|
138
|
-
throw new Error(this.readString(ptr, len));
|
|
139
|
-
},
|
|
140
|
-
__wbg_log_: (ptr, len) => {
|
|
141
|
-
if (this.config.debug) console.log(this.readString(ptr, len));
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
env: { memory: this.wasmMemory }
|
|
145
|
-
};
|
|
146
|
-
this.wasmInstance = await WebAssembly.instantiate(module, imports);
|
|
147
|
-
this.initialized = true;
|
|
148
|
-
if (this.config.debug) console.log("✅ Checkpoint WASM initialized in Edge Runtime");
|
|
149
|
-
} catch (error) {
|
|
150
|
-
console.warn("⚠️ WASM initialization failed, using pattern detection:", error);
|
|
151
|
-
this.initialized = true;
|
|
152
|
-
}
|
|
153
|
-
else this.initialized = true;
|
|
154
|
-
}
|
|
155
|
-
readString(ptr, len) {
|
|
156
|
-
if (!this.wasmInstance || !this.wasmMemory) throw new Error("WASM not initialized");
|
|
157
|
-
const bytes = new Uint8Array(this.wasmMemory.buffer).slice(ptr, ptr + len);
|
|
158
|
-
return new TextDecoder().decode(bytes);
|
|
159
|
-
}
|
|
160
|
-
writeString(str) {
|
|
161
|
-
if (!this.wasmInstance) throw new Error("WASM not initialized");
|
|
162
|
-
const exports = this.wasmInstance.exports;
|
|
163
|
-
const encoded = new TextEncoder().encode(str);
|
|
164
|
-
const ptr = exports.__wbindgen_malloc(encoded.length);
|
|
165
|
-
new Uint8Array(exports.memory.buffer).set(encoded, ptr);
|
|
166
|
-
return [ptr, encoded.length];
|
|
167
|
-
}
|
|
168
|
-
async detect(request) {
|
|
169
|
-
if (!this.initialized) await this.init();
|
|
170
|
-
const metadata = {
|
|
171
|
-
userAgent: request.headers.get("user-agent") || "",
|
|
172
|
-
ipAddress: getClientIp(request, this.config.clientIpPolicy) || "",
|
|
173
|
-
headers: Object.fromEntries(request.headers.entries())
|
|
174
|
-
};
|
|
175
|
-
if (this.wasmInstance && this.config.enableWasm !== false) try {
|
|
176
|
-
const exports = this.wasmInstance.exports;
|
|
177
|
-
const [ptr, len] = this.writeString(JSON.stringify(metadata));
|
|
178
|
-
const resultPtr = exports.detect_agent(ptr, len);
|
|
179
|
-
let resultStr = "";
|
|
180
|
-
let offset = 0;
|
|
181
|
-
const memory = new Uint8Array(exports.memory.buffer);
|
|
182
|
-
while (offset < 4096) {
|
|
183
|
-
const byte = memory[resultPtr + offset];
|
|
184
|
-
if (byte === 0 || byte === void 0) break;
|
|
185
|
-
offset++;
|
|
186
|
-
}
|
|
187
|
-
if (offset > 0) resultStr = this.readString(resultPtr, offset);
|
|
188
|
-
exports.__wbindgen_free(ptr, len);
|
|
189
|
-
if (offset > 0) exports.__wbindgen_free(resultPtr, offset);
|
|
190
|
-
const result = JSON.parse(resultStr);
|
|
191
|
-
const agent = readStringField(result.agent) ?? readStringField(result.agentName);
|
|
192
|
-
const confidence = normalizeEngineConfidence(readNumberField(result.confidence));
|
|
193
|
-
const detection = {
|
|
194
|
-
isAgent: readBooleanField(result.isAgent) ?? readBooleanField(result.is_agent) ?? false,
|
|
195
|
-
isAiCrawler: readBooleanField(result.isAiCrawler) ?? readBooleanField(result.is_ai_crawler),
|
|
196
|
-
confidence,
|
|
197
|
-
detectionClass: agent ? {
|
|
198
|
-
type: "AiAgent",
|
|
199
|
-
agentType: agent
|
|
200
|
-
} : { type: confidence > 0 ? "IncompleteData" : "Human" },
|
|
201
|
-
detectedAgent: agent ? {
|
|
202
|
-
type: "ai_agent",
|
|
203
|
-
name: agent
|
|
204
|
-
} : void 0,
|
|
205
|
-
agent,
|
|
206
|
-
agentType: agent,
|
|
207
|
-
reasons: readStringArrayField(result.reasons),
|
|
208
|
-
signals: [],
|
|
209
|
-
verificationMethod: "signature",
|
|
210
|
-
riskLevel: readStringField(result.riskLevel) ?? readStringField(result.risk_level),
|
|
211
|
-
timestamp: Date.now()
|
|
212
|
-
};
|
|
213
|
-
if (this.config.onAgentDetected && detection.isAgent) this.config.onAgentDetected(detection);
|
|
214
|
-
return detection;
|
|
215
|
-
} catch (error) {
|
|
216
|
-
if (this.config.debug) console.error("WASM detection failed:", error);
|
|
217
|
-
}
|
|
218
|
-
return this.patternDetection(metadata);
|
|
219
|
-
}
|
|
220
|
-
patternDetection(metadata) {
|
|
221
|
-
const lowercasedUa = metadata.userAgent.toLowerCase();
|
|
222
|
-
let headerBoost = 0;
|
|
223
|
-
for (const key of Object.keys(metadata.headers)) if (SUSPICIOUS_HEADER_PREFIXES.some((prefix) => key.toLowerCase().startsWith(prefix))) {
|
|
224
|
-
headerBoost = .1;
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
const match = matchKnownAgent(lowercasedUa);
|
|
228
|
-
if (match) {
|
|
229
|
-
const finalConfidence = Math.min(match.confidence + headerBoost, 1);
|
|
230
|
-
const result = {
|
|
231
|
-
isAgent: true,
|
|
232
|
-
confidence: Math.round(finalConfidence * 100),
|
|
233
|
-
detectionClass: {
|
|
234
|
-
type: "AiAgent",
|
|
235
|
-
agentType: match.name
|
|
236
|
-
},
|
|
237
|
-
detectedAgent: {
|
|
238
|
-
type: "ai_agent",
|
|
239
|
-
name: match.name
|
|
240
|
-
},
|
|
241
|
-
agent: match.name,
|
|
242
|
-
agentType: match.name,
|
|
243
|
-
reasons: [`known_pattern:${match.name.toLowerCase()}`],
|
|
244
|
-
signals: [],
|
|
245
|
-
verificationMethod: "pattern",
|
|
246
|
-
riskLevel: finalConfidence > .9 ? "high" : "medium",
|
|
247
|
-
timestamp: Date.now()
|
|
248
|
-
};
|
|
249
|
-
if (this.config.onAgentDetected) this.config.onAgentDetected(result);
|
|
250
|
-
return result;
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
isAgent: false,
|
|
254
|
-
confidence: 0,
|
|
255
|
-
detectionClass: { type: "Human" },
|
|
256
|
-
reasons: ["No known agent indicators matched"],
|
|
257
|
-
signals: [],
|
|
258
|
-
verificationMethod: "pattern",
|
|
259
|
-
timestamp: Date.now()
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
isInitialized() {
|
|
263
|
-
return this.initialized;
|
|
264
|
-
}
|
|
265
|
-
getVerificationMethod() {
|
|
266
|
-
return this.wasmInstance ? "cryptographic" : "pattern";
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
/**
|
|
270
|
-
* Factory function to create a Checkpoint instance for Edge Runtime.
|
|
271
|
-
*/
|
|
272
|
-
function createEdgeCheckpoint(config) {
|
|
273
|
-
return new EdgeRuntimeCheckpoint(config);
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Singleton instance for simple usage.
|
|
277
|
-
*/
|
|
278
|
-
let defaultInstance = null;
|
|
279
|
-
function getDefaultEdgeCheckpoint(config) {
|
|
280
|
-
if (!defaultInstance) defaultInstance = new EdgeRuntimeCheckpoint(config);
|
|
281
|
-
return defaultInstance;
|
|
282
|
-
}
|
|
283
|
-
/** @deprecated Renamed to {@link EdgeRuntimeCheckpoint}. */
|
|
284
|
-
const EdgeRuntimeAgentShield = EdgeRuntimeCheckpoint;
|
|
285
|
-
/** @deprecated Renamed to {@link createEdgeCheckpoint}. */
|
|
286
|
-
const createEdgeAgentShield = createEdgeCheckpoint;
|
|
287
|
-
/** @deprecated Renamed to {@link getDefaultEdgeCheckpoint}. */
|
|
288
|
-
const getDefaultAgentShield = getDefaultEdgeCheckpoint;
|
|
289
|
-
|
|
290
|
-
//#endregion
|
|
291
|
-
export { EdgeRuntimeAgentShield, EdgeRuntimeCheckpoint, createEdgeAgentShield, createEdgeCheckpoint, getDefaultAgentShield, getDefaultEdgeCheckpoint };
|
|
292
|
-
//# sourceMappingURL=edge-runtime-loader.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edge-runtime-loader.mjs","names":[],"sources":["../src/edge-runtime-loader.ts"],"sourcesContent":["/**\n * Edge Runtime Compatible WASM Loader for Checkpoint\n *\n * This module provides a pre-built solution for loading WASM in Edge Runtime.\n * It requires the WASM file to be manually placed in the project.\n *\n * ## SSOT for pattern detection\n *\n * The fallback `patternDetection` path imports the single canonical\n * pattern table `KNOWN_AGENT_PATTERNS` from\n * `@kya-os/checkpoint-shared/constants/agents`. PDM-2 (#2573) folded\n * what was previously a sibling supplement export\n * (`INTERACTIVE_AGENT_PATTERNS`) into per-agent SSOT rows alongside\n * the existing entries — interactive-session tokens, generic vendor\n * fallbacks, and the GPT-Crawler bot are now first-class SSOT rows\n * with `category`/`isLegitimate` fields. The drift-prevention test\n * in `checkpoint-shared/__tests__/constants/agents.test.ts` enforces\n * that no future PR re-introduces a sibling pool.\n *\n * ## Naming\n *\n * Old `AgentShield`-prefixed exports are kept as `@deprecated` aliases\n * for one release (`createEdgeAgentShield`, `EdgeRuntimeAgentShield`,\n * `AgentShieldConfig`, `getDefaultAgentShield`). New code should import\n * the `Checkpoint`-prefixed names directly.\n */\n\nimport {\n KNOWN_AGENT_PATTERNS,\n type ClientIpTrustPolicy,\n type DetectionDetail,\n} from '@kya-os/checkpoint-shared';\nimport type { NextRequest } from 'next/server';\n\nimport { getClientIp } from './utils';\n\n// User must provide the WASM module via import\n// This is intentionally not imported here to allow user control\nexport interface WasmModule {\n default: WebAssembly.Module;\n}\n\nexport type EdgeRuntimeDetectionDetail = DetectionDetail & { agent?: string };\n\n/**\n * @deprecated Use EdgeRuntimeDetectionDetail.\n */\nexport type { EdgeRuntimeDetectionDetail as DetectionResult };\n\nexport interface EdgeCheckpointConfig {\n wasmModule?: WebAssembly.Module;\n enableWasm?: boolean;\n /** Explicit deployment/proxy trust profile for client-IP resolution. */\n clientIpPolicy?: ClientIpTrustPolicy;\n onAgentDetected?: (result: EdgeRuntimeDetectionDetail) => void;\n blockAgents?: boolean;\n allowedAgents?: string[];\n debug?: boolean;\n}\n\ninterface WasmExports {\n detect_agent(metadataPtr: number, metadataLen: number): number;\n get_version(): number;\n __wbindgen_malloc(size: number): number;\n __wbindgen_free(ptr: number, size: number): void;\n __wbindgen_realloc(ptr: number, oldSize: number, newSize: number): number;\n memory: WebAssembly.Memory;\n}\n\n// ---------------------------------------------------------------------------\n// Suspicious-header signal — orthogonal to the SSOT pattern table.\n// Used to BOOST detection confidence when a known AI-side header\n// accompanies the UA match. Kept here (not in shared) because it's\n// edge-runtime-specific signal-fusion logic, not an agent-identity\n// fact.\n// ---------------------------------------------------------------------------\nconst SUSPICIOUS_HEADER_PREFIXES = ['x-openai-', 'x-anthropic-', 'x-ai-', 'x-llm-', 'x-gpt-'];\n\n/**\n * Escape a string for use as a regex pattern. SSOT tokens contain\n * regex meta-characters (`.`, `+`, etc.) that need escaping before\n * we wrap them in delimiter guards. Standard MDN escape regex.\n */\nfunction escapeRegex(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nconst REGEX_SYNTAX_PATTERN = /(?:\\\\.|[()[\\]{}|^$]|\\.\\*|\\.\\+|\\.\\?)/;\n\n/**\n * Build a delimiter-guarded regex for an SSOT token.\n *\n * Pre-fix (cursor #2599): the matcher used bare `lowercasedUa.includes(pattern)`,\n * which produced false positives whenever an SSOT token was a common\n * English substring — `'command'` (Cohere) matched `TotalCommander/10.52`;\n * `'palm'` (Google-Bard) matched `PalmOS-Browser/1.0`. With `blockAgents`\n * enabled these mis-classified legitimate browser traffic as bot.\n *\n * Literal SSOT tokens are escaped before being wrapped in\n * `(^|[^a-z0-9])…($|[^a-z0-9])`. Delimiter guards preserve the\n * substring false-positive fix while still handling tokens that end in\n * punctuation, such as `KYA-Agent/`.\n *\n * - `command` no longer matches `TotalCommander` (`l` is alphanumeric);\n * still matches `cohere-command-r/1.0` and `command-r-plus`.\n * - `palm` no longer matches `PalmOS` (`o` is alphanumeric);\n * still matches `palm-2`.\n *\n * Regex-shaped SSOT entries (for example `BingPreview/.*ChatGPT`) are\n * compiled as regex source to mirror kya-os-engine, where TS patterns\n * are emitted into Rust `Regex::new(\"(?i)<pattern>\")`.\n *\n * Cached so we don't rebuild the same RegExp for every UA.\n */\nconst TOKEN_REGEX_CACHE = new Map<string, RegExp>();\nfunction tokenRegex(token: string): RegExp {\n const cached = TOKEN_REGEX_CACHE.get(token);\n if (cached) return cached;\n const source = REGEX_SYNTAX_PATTERN.test(token) ? token : escapeRegex(token);\n const regex = new RegExp(`(^|[^a-z0-9])${source}($|[^a-z0-9])`, 'i');\n TOKEN_REGEX_CACHE.set(token, regex);\n return regex;\n}\n\nfunction readStringField(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction readNumberField(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\nfunction readBooleanField(value: unknown): boolean | undefined {\n return typeof value === 'boolean' ? value : undefined;\n}\n\nfunction readStringArrayField(value: unknown): string[] {\n return Array.isArray(value)\n ? value.filter((item): item is string => typeof item === 'string')\n : [];\n}\n\nfunction normalizeEngineConfidence(value: number | undefined): number {\n if (value === undefined) return 0;\n return Math.round(Math.max(0, Math.min(100, value)));\n}\n\n/**\n * Match a UA string against `KNOWN_AGENT_PATTERNS` (the canonical SSOT).\n * Returns the highest-confidence matching entry, or `null` if no entry\n * matches.\n *\n * Delimiter anchoring prevents common-English substrings in the SSOT\n * (`command`, `palm`, `Anthropic`) from false-positiving on legitimate\n * UAs (`TotalCommander`, `PalmOS-Browser`, `AnthropicAssistant` —\n * though the last is now stricter post-PDM-2; `Anthropic` must appear\n * as a standalone token).\n */\nfunction matchKnownAgent(lowercasedUa: string): { name: string; confidence: number } | null {\n let best: { name: string; confidence: number } | null = null;\n\n for (const entry of KNOWN_AGENT_PATTERNS) {\n for (const pattern of entry.patterns) {\n if (tokenRegex(pattern).test(lowercasedUa)) {\n if (!best || entry.confidence > best.confidence) {\n best = { name: entry.name, confidence: entry.confidence };\n }\n break; // one match per entry is enough\n }\n }\n }\n\n return best;\n}\n\nclass EdgeRuntimeCheckpoint {\n private wasmInstance: WebAssembly.Instance | null = null;\n private wasmMemory: WebAssembly.Memory | null = null;\n private config: EdgeCheckpointConfig;\n private initialized = false;\n\n constructor(config: EdgeCheckpointConfig = {}) {\n this.config = config;\n }\n\n async init(wasmModule?: WebAssembly.Module): Promise<void> {\n if (this.initialized) return;\n\n const module = wasmModule || this.config.wasmModule;\n\n if (module && this.config.enableWasm !== false) {\n try {\n this.wasmMemory = new WebAssembly.Memory({ initial: 17, maximum: 256 });\n\n const imports = {\n wbg: {\n __wbindgen_throw: (ptr: number, len: number) => {\n throw new Error(this.readString(ptr, len));\n },\n __wbg_log_: (ptr: number, len: number) => {\n if (this.config.debug) {\n console.log(this.readString(ptr, len));\n }\n },\n },\n env: {\n memory: this.wasmMemory,\n },\n };\n\n this.wasmInstance = await WebAssembly.instantiate(module, imports);\n this.initialized = true;\n\n if (this.config.debug) {\n console.log('✅ Checkpoint WASM initialized in Edge Runtime');\n }\n } catch (error) {\n console.warn('⚠️ WASM initialization failed, using pattern detection:', error);\n this.initialized = true;\n }\n } else {\n this.initialized = true;\n }\n }\n\n private readString(ptr: number, len: number): string {\n if (!this.wasmInstance || !this.wasmMemory) {\n throw new Error('WASM not initialized');\n }\n const memory = new Uint8Array(this.wasmMemory.buffer);\n const bytes = memory.slice(ptr, ptr + len);\n return new TextDecoder().decode(bytes);\n }\n\n private writeString(str: string): [number, number] {\n if (!this.wasmInstance) {\n throw new Error('WASM not initialized');\n }\n const exports = this.wasmInstance.exports as unknown as WasmExports;\n\n const encoded = new TextEncoder().encode(str);\n const ptr = exports.__wbindgen_malloc(encoded.length);\n\n const memory = new Uint8Array(exports.memory.buffer);\n memory.set(encoded, ptr);\n\n return [ptr, encoded.length];\n }\n\n async detect(request: NextRequest): Promise<EdgeRuntimeDetectionDetail> {\n if (!this.initialized) {\n await this.init();\n }\n\n const metadata = {\n userAgent: request.headers.get('user-agent') || '',\n ipAddress: getClientIp(request, this.config.clientIpPolicy) || '',\n headers: Object.fromEntries(request.headers.entries()),\n };\n\n // Try WASM detection first\n if (this.wasmInstance && this.config.enableWasm !== false) {\n try {\n const exports = this.wasmInstance.exports as unknown as WasmExports;\n const [ptr, len] = this.writeString(JSON.stringify(metadata));\n\n const resultPtr = exports.detect_agent(ptr, len);\n // Read result with dynamic size\n let resultStr = '';\n let offset = 0;\n const memory = new Uint8Array((exports.memory as WebAssembly.Memory).buffer);\n\n // Read until we find the end of the JSON string\n while (offset < 4096) {\n // Max 4KB result\n const byte = memory[resultPtr + offset];\n if (byte === 0 || byte === undefined) break;\n offset++;\n }\n\n if (offset > 0) {\n resultStr = this.readString(resultPtr, offset);\n }\n\n exports.__wbindgen_free(ptr, len);\n if (offset > 0) {\n exports.__wbindgen_free(resultPtr, offset);\n }\n\n const result = JSON.parse(resultStr) as Record<string, unknown>;\n const agent = readStringField(result.agent) ?? readStringField(result.agentName);\n const confidence = normalizeEngineConfidence(readNumberField(result.confidence));\n\n const detection: EdgeRuntimeDetectionDetail = {\n isAgent: readBooleanField(result.isAgent) ?? readBooleanField(result.is_agent) ?? false,\n isAiCrawler:\n readBooleanField(result.isAiCrawler) ?? readBooleanField(result.is_ai_crawler),\n confidence,\n detectionClass: agent\n ? { type: 'AiAgent', agentType: agent }\n : { type: confidence > 0 ? 'IncompleteData' : 'Human' },\n detectedAgent: agent ? { type: 'ai_agent', name: agent } : undefined,\n agent,\n agentType: agent,\n reasons: readStringArrayField(result.reasons),\n signals: [],\n verificationMethod: 'signature',\n riskLevel: readStringField(result.riskLevel) ?? readStringField(result.risk_level),\n timestamp: Date.now(),\n };\n\n if (this.config.onAgentDetected && detection.isAgent) {\n this.config.onAgentDetected(detection);\n }\n\n return detection;\n } catch (error) {\n if (this.config.debug) {\n console.error('WASM detection failed:', error);\n }\n // Fall through to pattern detection\n }\n }\n\n // Fallback: SSOT pattern detection\n return this.patternDetection(metadata);\n }\n\n private patternDetection(metadata: {\n userAgent: string;\n ipAddress: string;\n headers: Record<string, string>;\n }): EdgeRuntimeDetectionDetail {\n const lowercasedUa = metadata.userAgent.toLowerCase();\n\n // Suspicious-header signal — orthogonal to the pattern match.\n // Boosts the confidence of an SSOT match when a known AI-side\n // request header accompanies the UA. Doesn't classify on its own.\n let headerBoost = 0;\n for (const key of Object.keys(metadata.headers)) {\n if (SUSPICIOUS_HEADER_PREFIXES.some((prefix) => key.toLowerCase().startsWith(prefix))) {\n headerBoost = 0.1;\n break;\n }\n }\n\n const match = matchKnownAgent(lowercasedUa);\n if (match) {\n const finalConfidence = Math.min(match.confidence + headerBoost, 1.0);\n const confidence = Math.round(finalConfidence * 100);\n const result: EdgeRuntimeDetectionDetail = {\n isAgent: true,\n confidence,\n detectionClass: { type: 'AiAgent', agentType: match.name },\n detectedAgent: { type: 'ai_agent', name: match.name },\n agent: match.name,\n agentType: match.name,\n reasons: [`known_pattern:${match.name.toLowerCase()}`],\n signals: [],\n verificationMethod: 'pattern',\n riskLevel: finalConfidence > 0.9 ? 'high' : 'medium',\n timestamp: Date.now(),\n };\n\n if (this.config.onAgentDetected) {\n this.config.onAgentDetected(result);\n }\n\n return result;\n }\n\n // Not detected — neutral verdict with low (default) confidence.\n return {\n isAgent: false,\n confidence: 0,\n detectionClass: { type: 'Human' },\n reasons: ['No known agent indicators matched'],\n signals: [],\n verificationMethod: 'pattern',\n timestamp: Date.now(),\n };\n }\n\n isInitialized(): boolean {\n return this.initialized;\n }\n\n getVerificationMethod(): 'cryptographic' | 'pattern' {\n return this.wasmInstance ? 'cryptographic' : 'pattern';\n }\n}\n\n/**\n * Factory function to create a Checkpoint instance for Edge Runtime.\n */\nexport function createEdgeCheckpoint(config?: EdgeCheckpointConfig) {\n return new EdgeRuntimeCheckpoint(config);\n}\n\n/**\n * Singleton instance for simple usage.\n */\nlet defaultInstance: EdgeRuntimeCheckpoint | null = null;\n\nexport function getDefaultEdgeCheckpoint(config?: EdgeCheckpointConfig): EdgeRuntimeCheckpoint {\n if (!defaultInstance) {\n defaultInstance = new EdgeRuntimeCheckpoint(config);\n }\n return defaultInstance;\n}\n\n// Export the canonical class for advanced consumers.\nexport { EdgeRuntimeCheckpoint };\n\n// ---------------------------------------------------------------------------\n// Back-compat aliases (SSOT-Fallback-Drift-1 rename — `AgentShield` → `Checkpoint`).\n//\n// The runtime is identical; the type and class symbols are re-exported\n// under their pre-rename names with `@deprecated` JSDoc tags. One\n// release of overlap; new code should import the `Checkpoint`-prefixed\n// names directly.\n// ---------------------------------------------------------------------------\n\n/** @deprecated Renamed to {@link EdgeCheckpointConfig}. */\nexport type AgentShieldConfig = EdgeCheckpointConfig;\n\n/** @deprecated Renamed to {@link EdgeRuntimeCheckpoint}. */\nexport const EdgeRuntimeAgentShield = EdgeRuntimeCheckpoint;\n\n/** @deprecated Renamed to {@link createEdgeCheckpoint}. */\nexport const createEdgeAgentShield = createEdgeCheckpoint;\n\n/** @deprecated Renamed to {@link getDefaultEdgeCheckpoint}. */\nexport const getDefaultAgentShield = getDefaultEdgeCheckpoint;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAM,6BAA6B;CAAC;CAAa;CAAgB;CAAS;CAAU;AAAQ;;;;;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kBAAkB,KAAM,SAAS;IAC5C,WAAW,KAAK,IAAI;GACtB;GAEA,IAAI,KAAK,OAAO,iBACd,KAAK,OAAO,gBAAgB,MAAM;GAGpC,OAAO;EACT;EAGA,OAAO;GACL,SAAS;GACT,YAAY;GACZ,gBAAgB,EAAE,MAAM,QAAQ;GAChC,SAAS,CAAC,mCAAmC;GAC7C,SAAS,CAAC;GACV,oBAAoB;GACpB,WAAW,KAAK,IAAI;EACtB;CACF;CAEA,gBAAyB;EACvB,OAAO,KAAK;CACd;CAEA,wBAAqD;EACnD,OAAO,KAAK,eAAe,kBAAkB;CAC/C;AACF;;;;AAKA,SAAgB,qBAAqB,QAA+B;CAClE,OAAO,IAAI,sBAAsB,MAAM;AACzC;;;;AAKA,IAAI,kBAAgD;AAEpD,SAAgB,yBAAyB,QAAsD;CAC7F,IAAI,CAAC,iBACH,kBAAkB,IAAI,sBAAsB,MAAM;CAEpD,OAAO;AACT;;AAkBA,MAAa,yBAAyB;;AAGtC,MAAa,wBAAwB;;AAGrC,MAAa,wBAAwB"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
-
//#region src/edge-wasm-middleware.d.ts
|
|
3
|
-
/** @deprecated See file header. Type-only surface preservation. */
|
|
4
|
-
export interface EdgeWasmDetectionResult {
|
|
5
|
-
isAgent: boolean;
|
|
6
|
-
isAiCrawler?: boolean;
|
|
7
|
-
confidence: number;
|
|
8
|
-
agent?: string;
|
|
9
|
-
verificationMethod: 'signature' | 'pattern' | 'wasm';
|
|
10
|
-
riskLevel: 'low' | 'medium' | 'high';
|
|
11
|
-
timestamp: string;
|
|
12
|
-
reasons?: string[];
|
|
13
|
-
}
|
|
14
|
-
/** @deprecated See file header. Type-only surface preservation. */
|
|
15
|
-
export interface EdgeAgentShieldConfig {
|
|
16
|
-
onAgentDetected?: (result: EdgeWasmDetectionResult) => void | Promise<void>;
|
|
17
|
-
blockOnHighConfidence?: boolean;
|
|
18
|
-
confidenceThreshold?: number;
|
|
19
|
-
skipPaths?: string[];
|
|
20
|
-
blockedResponse?: {
|
|
21
|
-
status?: number;
|
|
22
|
-
message?: string;
|
|
23
|
-
headers?: Record<string, string>;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/** @internal — test-only reset for the one-shot warn latch. */
|
|
27
|
-
export declare function __resetEdgeWasmWarningForTests(): void;
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
|
|
30
|
-
* `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
|
|
31
|
-
* surface exists only so static analysis sees the historical export.
|
|
32
|
-
*/
|
|
33
|
-
export declare function initializeEdgeWasm(_wasmModule: WebAssembly.Module): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
|
|
36
|
-
* `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
|
|
37
|
-
* surface exists only so static analysis sees the historical export.
|
|
38
|
-
*/
|
|
39
|
-
export declare function createEdgeWasmMiddleware(_config: EdgeAgentShieldConfig & {
|
|
40
|
-
wasmModule: WebAssembly.Module;
|
|
41
|
-
}): (request: NextRequest) => Promise<NextResponse>;
|
|
42
|
-
//#endregion
|
|
43
|
-
//# sourceMappingURL=edge-wasm-middleware.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edge-wasm-middleware.d.mts","names":[],"sources":["../src/edge-wasm-middleware.ts"],"mappings":";;;iBAuBiB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;iBAIe;EACf,mBAAmB,QAAQ,mCAAmC;EAC9D;EACA;EACA;EACA;IACE;IACA;IACA,UAAU;;;;wBAuBE;;;;;;wBASM,mBAAmB,aAAa,YAAY,SAAS;;;;;;wBAU3D,yBACd,SAAS;EACP,YAAY,YAAY;KAExB,SAAS,gBAAgB,QAAQ"}
|