@kya-os/checkpoint-nextjs 1.1.0 → 1.1.4
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 +178 -0
- package/EDGE_RUNTIME_WASM_SETUP.md +4 -10
- package/README.md +13 -0
- package/bin/setup-edge-wasm.js +40 -32
- package/dist/api-client.d.mts +10 -10
- package/dist/api-client.d.ts +10 -10
- package/dist/create-middleware.d.mts +7 -2
- package/dist/create-middleware.d.ts +7 -2
- package/dist/edge/index.d.mts +3 -3
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +16 -3
- package/dist/edge/index.mjs +16 -3
- package/dist/edge-runtime-loader.d.mts +43 -18
- package/dist/edge-runtime-loader.d.ts +43 -18
- package/dist/edge-runtime-loader.js +101 -58
- package/dist/edge-runtime-loader.mjs +98 -59
- package/dist/edge-wasm-middleware.d.mts +28 -34
- package/dist/edge-wasm-middleware.d.ts +28 -34
- package/dist/edge-wasm-middleware.js +16 -306
- package/dist/edge-wasm-middleware.mjs +16 -307
- package/dist/index.js +3 -1
- package/dist/index.mjs +4 -2
- package/dist/nodejs-wasm-loader.d.mts +26 -9
- package/dist/nodejs-wasm-loader.d.ts +26 -9
- package/dist/nodejs-wasm-loader.js +21 -78
- package/dist/nodejs-wasm-loader.mjs +21 -74
- package/dist/session-tracker.d.mts +2 -2
- package/dist/session-tracker.d.ts +2 -2
- package/dist/session-tracker.js +3 -1
- package/dist/session-tracker.mjs +4 -2
- package/dist/wasm-middleware.d.mts +19 -3
- package/dist/wasm-middleware.d.ts +19 -3
- package/dist/wasm-middleware.js +32 -3
- package/dist/wasm-middleware.mjs +32 -4
- package/dist/wasm-setup.js +29 -81
- package/dist/wasm-setup.mjs +29 -76
- package/package.json +4 -4
- package/templates/middleware-wasm-100.ts +11 -3
- package/dist/.tsbuildinfo +0 -1
|
@@ -1,313 +1,22 @@
|
|
|
1
|
-
import { NextResponse } from 'next/server';
|
|
2
|
-
import { normalizeConfidence, evaluateEnforcement, shouldEnforce, toPercent } from '@kya-os/checkpoint-shared';
|
|
3
|
-
|
|
4
1
|
// src/edge-wasm-middleware.ts
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const idx = heap_next;
|
|
13
|
-
heap_next = heap[idx];
|
|
14
|
-
heap[idx] = obj;
|
|
15
|
-
return idx;
|
|
16
|
-
}
|
|
17
|
-
function getObject(idx) {
|
|
18
|
-
return heap[idx];
|
|
19
|
-
}
|
|
20
|
-
function dropObject(idx) {
|
|
21
|
-
if (idx < 132) return;
|
|
22
|
-
heap[idx] = heap_next;
|
|
23
|
-
heap_next = idx;
|
|
24
|
-
}
|
|
25
|
-
function takeObject(idx) {
|
|
26
|
-
const ret = getObject(idx);
|
|
27
|
-
dropObject(idx);
|
|
28
|
-
return ret;
|
|
29
|
-
}
|
|
30
|
-
var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
|
|
31
|
-
var cachedTextEncoder = new TextEncoder();
|
|
32
|
-
var cachedUint8ArrayMemory0 = null;
|
|
33
|
-
function getUint8ArrayMemory0() {
|
|
34
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
35
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasmExports.memory.buffer);
|
|
36
|
-
}
|
|
37
|
-
return cachedUint8ArrayMemory0;
|
|
38
|
-
}
|
|
39
|
-
function getStringFromWasm0(ptr, len) {
|
|
40
|
-
ptr = ptr >>> 0;
|
|
41
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
42
|
-
}
|
|
43
|
-
var WASM_VECTOR_LEN = 0;
|
|
44
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
45
|
-
if (realloc === void 0) {
|
|
46
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
47
|
-
const ptr2 = malloc(buf.length, 1) >>> 0;
|
|
48
|
-
getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
|
|
49
|
-
WASM_VECTOR_LEN = buf.length;
|
|
50
|
-
return ptr2;
|
|
51
|
-
}
|
|
52
|
-
let len = arg.length;
|
|
53
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
54
|
-
const mem = getUint8ArrayMemory0();
|
|
55
|
-
let offset = 0;
|
|
56
|
-
for (; offset < len; offset++) {
|
|
57
|
-
const code = arg.charCodeAt(offset);
|
|
58
|
-
if (code > 127) break;
|
|
59
|
-
mem[ptr + offset] = code;
|
|
60
|
-
}
|
|
61
|
-
if (offset !== len) {
|
|
62
|
-
if (offset !== 0) {
|
|
63
|
-
arg = arg.slice(offset);
|
|
64
|
-
}
|
|
65
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
66
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
67
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
68
|
-
offset += ret.written;
|
|
69
|
-
}
|
|
70
|
-
WASM_VECTOR_LEN = offset;
|
|
71
|
-
return ptr;
|
|
72
|
-
}
|
|
73
|
-
var cachedDataViewMemory0 = null;
|
|
74
|
-
function getDataViewMemory0() {
|
|
75
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer !== wasmExports.memory.buffer) {
|
|
76
|
-
cachedDataViewMemory0 = new DataView(wasmExports.memory.buffer);
|
|
77
|
-
}
|
|
78
|
-
return cachedDataViewMemory0;
|
|
2
|
+
var MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs/edge-wasm-middleware` was deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` \u2014 engine-backed via the Rust `kya-os-engine` crate (PDM-1 #2560), runs the full orchestrator including MCP-I envelope verification. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
|
|
3
|
+
var _edgeWasmWarned = false;
|
|
4
|
+
function warnEdgeWasmDeprecated() {
|
|
5
|
+
if (_edgeWasmWarned) return;
|
|
6
|
+
_edgeWasmWarned = true;
|
|
7
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
|
|
8
|
+
console.warn(`[Checkpoint] ${MIGRATION_ERROR}`);
|
|
79
9
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return wasmInitPromise;
|
|
83
|
-
}
|
|
84
|
-
wasmInitPromise = (async () => {
|
|
85
|
-
try {
|
|
86
|
-
const imports = {
|
|
87
|
-
"./agentshield_wasm_bg.js": {
|
|
88
|
-
__wbindgen_object_drop_ref: function(arg0) {
|
|
89
|
-
dropObject(arg0);
|
|
90
|
-
},
|
|
91
|
-
__wbindgen_string_new: function(arg0, arg1) {
|
|
92
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
93
|
-
return addHeapObject(ret);
|
|
94
|
-
},
|
|
95
|
-
__wbindgen_string_get: function(arg0, arg1) {
|
|
96
|
-
const obj = getObject(arg1);
|
|
97
|
-
const ret = typeof obj === "string" ? obj : void 0;
|
|
98
|
-
const ptr1 = ret ? passStringToWasm0(
|
|
99
|
-
ret,
|
|
100
|
-
wasmExports.__wbindgen_malloc,
|
|
101
|
-
wasmExports.__wbindgen_realloc
|
|
102
|
-
) : 0;
|
|
103
|
-
const len1 = WASM_VECTOR_LEN;
|
|
104
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
105
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
106
|
-
},
|
|
107
|
-
__wbindgen_throw: function(arg0, arg1) {
|
|
108
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
wbg: {
|
|
112
|
-
__wbindgen_object_drop_ref: function(arg0) {
|
|
113
|
-
dropObject(arg0);
|
|
114
|
-
},
|
|
115
|
-
__wbindgen_string_new: function(arg0, arg1) {
|
|
116
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
117
|
-
return addHeapObject(ret);
|
|
118
|
-
},
|
|
119
|
-
__wbindgen_string_get: function(arg0, arg1) {
|
|
120
|
-
const obj = getObject(arg1);
|
|
121
|
-
const ret = typeof obj === "string" ? obj : void 0;
|
|
122
|
-
const ptr1 = ret ? passStringToWasm0(
|
|
123
|
-
ret,
|
|
124
|
-
wasmExports.__wbindgen_malloc,
|
|
125
|
-
wasmExports.__wbindgen_realloc
|
|
126
|
-
) : 0;
|
|
127
|
-
const len1 = WASM_VECTOR_LEN;
|
|
128
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
129
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
130
|
-
},
|
|
131
|
-
__wbindgen_throw: function(arg0, arg1) {
|
|
132
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
const instance = await WebAssembly.instantiate(wasmModule, imports);
|
|
137
|
-
wasmExports = instance.exports;
|
|
138
|
-
if (wasmExports.__wbindgen_start) {
|
|
139
|
-
wasmExports.__wbindgen_start();
|
|
140
|
-
}
|
|
141
|
-
console.log(
|
|
142
|
-
"\u2705 AgentShield: WASM module loaded successfully in Edge Runtime (95-100% confidence enabled)"
|
|
143
|
-
);
|
|
144
|
-
} catch (error) {
|
|
145
|
-
console.error("\u274C AgentShield: Failed to initialize WASM in Edge Runtime:", error);
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
})();
|
|
149
|
-
return wasmInitPromise;
|
|
10
|
+
function __resetEdgeWasmWarningForTests() {
|
|
11
|
+
_edgeWasmWarned = false;
|
|
150
12
|
}
|
|
151
|
-
async function
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
const userAgent = metadata.userAgent || "";
|
|
157
|
-
const ipAddress = metadata.ipAddress || "";
|
|
158
|
-
const headers = JSON.stringify(metadata.headers);
|
|
159
|
-
const timestamp = metadata.timestamp;
|
|
160
|
-
const url = metadata.url || "";
|
|
161
|
-
const method = metadata.method || "";
|
|
162
|
-
const clientFingerprint = metadata.clientFingerprint || "";
|
|
163
|
-
const ptr0 = passStringToWasm0(
|
|
164
|
-
userAgent,
|
|
165
|
-
wasmExports.__wbindgen_malloc,
|
|
166
|
-
wasmExports.__wbindgen_realloc
|
|
167
|
-
);
|
|
168
|
-
const len0 = WASM_VECTOR_LEN;
|
|
169
|
-
const ptr1 = passStringToWasm0(
|
|
170
|
-
ipAddress,
|
|
171
|
-
wasmExports.__wbindgen_malloc,
|
|
172
|
-
wasmExports.__wbindgen_realloc
|
|
173
|
-
);
|
|
174
|
-
const len1 = WASM_VECTOR_LEN;
|
|
175
|
-
const ptr2 = passStringToWasm0(
|
|
176
|
-
headers,
|
|
177
|
-
wasmExports.__wbindgen_malloc,
|
|
178
|
-
wasmExports.__wbindgen_realloc
|
|
179
|
-
);
|
|
180
|
-
const len2 = WASM_VECTOR_LEN;
|
|
181
|
-
const ptr3 = passStringToWasm0(
|
|
182
|
-
timestamp,
|
|
183
|
-
wasmExports.__wbindgen_malloc,
|
|
184
|
-
wasmExports.__wbindgen_realloc
|
|
185
|
-
);
|
|
186
|
-
const len3 = WASM_VECTOR_LEN;
|
|
187
|
-
const ptr4 = passStringToWasm0(
|
|
188
|
-
url,
|
|
189
|
-
wasmExports.__wbindgen_malloc,
|
|
190
|
-
wasmExports.__wbindgen_realloc
|
|
191
|
-
);
|
|
192
|
-
const len4 = WASM_VECTOR_LEN;
|
|
193
|
-
const ptr5 = passStringToWasm0(
|
|
194
|
-
method,
|
|
195
|
-
wasmExports.__wbindgen_malloc,
|
|
196
|
-
wasmExports.__wbindgen_realloc
|
|
197
|
-
);
|
|
198
|
-
const len5 = WASM_VECTOR_LEN;
|
|
199
|
-
const ptr6 = passStringToWasm0(
|
|
200
|
-
clientFingerprint,
|
|
201
|
-
wasmExports.__wbindgen_malloc,
|
|
202
|
-
wasmExports.__wbindgen_realloc
|
|
203
|
-
);
|
|
204
|
-
const len6 = WASM_VECTOR_LEN;
|
|
205
|
-
const metadataPtr = wasmExports.jsrequestmetadata_new(
|
|
206
|
-
ptr0,
|
|
207
|
-
len0,
|
|
208
|
-
ptr1,
|
|
209
|
-
len1,
|
|
210
|
-
ptr2,
|
|
211
|
-
len2,
|
|
212
|
-
ptr3,
|
|
213
|
-
len3,
|
|
214
|
-
ptr4,
|
|
215
|
-
len4,
|
|
216
|
-
ptr5,
|
|
217
|
-
len5,
|
|
218
|
-
ptr6,
|
|
219
|
-
len6
|
|
220
|
-
);
|
|
221
|
-
const resultPtr = wasmExports.detect_agent(metadataPtr);
|
|
222
|
-
const result = takeObject(resultPtr);
|
|
223
|
-
wasmExports.__wbg_jsrequestmetadata_free(metadataPtr, 0);
|
|
224
|
-
const parsedResult = typeof result === "string" ? JSON.parse(result) : result;
|
|
225
|
-
return {
|
|
226
|
-
isAgent: parsedResult.is_agent || false,
|
|
227
|
-
isAiCrawler: parsedResult.is_ai_crawler || false,
|
|
228
|
-
confidence: parsedResult.confidence || 0,
|
|
229
|
-
agent: parsedResult.agent,
|
|
230
|
-
verificationMethod: parsedResult.verification_method || "wasm",
|
|
231
|
-
riskLevel: parsedResult.risk_level || "low",
|
|
232
|
-
timestamp: parsedResult.timestamp || metadata.timestamp,
|
|
233
|
-
reasons: parsedResult.reasons || []
|
|
234
|
-
};
|
|
235
|
-
} catch (error) {
|
|
236
|
-
console.error("WASM detection failed:", error);
|
|
237
|
-
return {
|
|
238
|
-
isAgent: false,
|
|
239
|
-
confidence: 0,
|
|
240
|
-
verificationMethod: "pattern",
|
|
241
|
-
riskLevel: "low",
|
|
242
|
-
timestamp: metadata.timestamp
|
|
243
|
-
};
|
|
244
|
-
}
|
|
13
|
+
async function initializeEdgeWasm(_wasmModule) {
|
|
14
|
+
warnEdgeWasmDeprecated();
|
|
15
|
+
throw new Error(MIGRATION_ERROR);
|
|
245
16
|
}
|
|
246
|
-
function createEdgeWasmMiddleware(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
onAgentDetected,
|
|
250
|
-
blockOnHighConfidence = false,
|
|
251
|
-
confidenceThreshold: configThreshold = 0.9,
|
|
252
|
-
skipPaths = [],
|
|
253
|
-
blockedResponse = {
|
|
254
|
-
status: 403,
|
|
255
|
-
message: "AI agent access restricted",
|
|
256
|
-
headers: { "Content-Type": "application/json" }
|
|
257
|
-
}
|
|
258
|
-
} = config;
|
|
259
|
-
const confidenceThreshold = normalizeConfidence(configThreshold, "confidenceThreshold");
|
|
260
|
-
const initPromise = initializeEdgeWasm(wasmModule);
|
|
261
|
-
return async function middleware(request) {
|
|
262
|
-
const path = request.nextUrl.pathname;
|
|
263
|
-
if (skipPaths.some((skip) => path.startsWith(skip))) {
|
|
264
|
-
return NextResponse.next();
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
await initPromise;
|
|
268
|
-
const metadata = {
|
|
269
|
-
userAgent: request.headers.get("user-agent") || void 0,
|
|
270
|
-
ipAddress: request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || void 0,
|
|
271
|
-
headers: Object.fromEntries(request.headers.entries()),
|
|
272
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
273
|
-
};
|
|
274
|
-
const result = await detectWithWasm(metadata);
|
|
275
|
-
const decision = evaluateEnforcement(
|
|
276
|
-
{ ...result, confidence: result.confidence * 100 },
|
|
277
|
-
{
|
|
278
|
-
confidenceThreshold: confidenceThreshold * 100,
|
|
279
|
-
defaultAction: blockOnHighConfidence ? "block" : "allow"
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
if (onAgentDetected && shouldEnforce(result)) {
|
|
283
|
-
await onAgentDetected(result);
|
|
284
|
-
}
|
|
285
|
-
if (decision.action === "block") {
|
|
286
|
-
return NextResponse.json(
|
|
287
|
-
{
|
|
288
|
-
error: blockedResponse.message,
|
|
289
|
-
agent: result.agent,
|
|
290
|
-
confidence: toPercent(result.confidence)
|
|
291
|
-
// Convert to 0-100 for display
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
status: blockedResponse.status || 403,
|
|
295
|
-
headers: blockedResponse.headers || {}
|
|
296
|
-
}
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
const response = NextResponse.next();
|
|
300
|
-
if (result.isAgent) {
|
|
301
|
-
response.headers.set("X-Agent-Detected", result.agent || "unknown");
|
|
302
|
-
response.headers.set("X-Agent-Confidence", String(toPercent(result.confidence)));
|
|
303
|
-
response.headers.set("X-Agent-Verification", result.verificationMethod);
|
|
304
|
-
}
|
|
305
|
-
return response;
|
|
306
|
-
} catch (error) {
|
|
307
|
-
console.error("Edge WASM middleware error:", error);
|
|
308
|
-
return NextResponse.next();
|
|
309
|
-
}
|
|
310
|
-
};
|
|
17
|
+
function createEdgeWasmMiddleware(_config) {
|
|
18
|
+
warnEdgeWasmDeprecated();
|
|
19
|
+
throw new Error(MIGRATION_ERROR);
|
|
311
20
|
}
|
|
312
21
|
|
|
313
|
-
export { createEdgeWasmMiddleware, initializeEdgeWasm };
|
|
22
|
+
export { __resetEdgeWasmWarningForTests, createEdgeWasmMiddleware, initializeEdgeWasm };
|
package/dist/index.js
CHANGED
|
@@ -698,7 +698,9 @@ var EdgeSessionTracker = class {
|
|
|
698
698
|
*/
|
|
699
699
|
async track(_request, response, result) {
|
|
700
700
|
try {
|
|
701
|
-
|
|
701
|
+
const detectedName = result.detectedAgent?.name;
|
|
702
|
+
const isEnforceable = result.isAgent || result.isAiCrawler || checkpointShared.isKnownAiCrawler(detectedName);
|
|
703
|
+
if (!this.config.enabled || !isEnforceable) {
|
|
702
704
|
return response;
|
|
703
705
|
}
|
|
704
706
|
const sessionData = {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { verifyRequest, renderDecisionAsResponse } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
2
2
|
import { makeSystemClock, makePolicyEvaluator, makeReputationOracle, makeStatusListCache, makeDidResolver } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
|
-
import {
|
|
4
|
+
import { isKnownAiCrawler, createEvaluationContext, evaluatePolicy, ENFORCEMENT_ACTIONS, PolicyConfigSchema, DEFAULT_POLICY, matchPath, acceptsHtml, encodeVerdictCookie, classifyResponseShape, BLOCKED_PATH, createPolicyFetcher, VERDICT_COOKIE_NAME } from '@kya-os/checkpoint-shared';
|
|
5
5
|
export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
|
|
6
6
|
|
|
7
7
|
// src/middleware-node.ts
|
|
@@ -697,7 +697,9 @@ var EdgeSessionTracker = class {
|
|
|
697
697
|
*/
|
|
698
698
|
async track(_request, response, result) {
|
|
699
699
|
try {
|
|
700
|
-
|
|
700
|
+
const detectedName = result.detectedAgent?.name;
|
|
701
|
+
const isEnforceable = result.isAgent || result.isAiCrawler || isKnownAiCrawler(detectedName);
|
|
702
|
+
if (!this.config.enabled || !isEnforceable) {
|
|
701
703
|
return response;
|
|
702
704
|
}
|
|
703
705
|
const sessionData = {
|
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Node.js
|
|
2
|
+
* @deprecated Phase-D.9a — legacy Node.js WASM loader for the retired
|
|
3
|
+
* `agentshield-wasm` Rust crate. This file used `fs.readFileSync` to
|
|
4
|
+
* locate + load the legacy detector's WASM binary into the
|
|
5
|
+
* `@kya-os/checkpoint` `AgentDetector` class via `setWasmModule`. Both
|
|
6
|
+
* the WASM crate (Phase-D.9a/D.9b) and the AgentDetector class
|
|
7
|
+
* (AgentDetector-Deletion-2, next minor) are slated for deletion.
|
|
3
8
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
9
|
+
* Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` — it
|
|
10
|
+
* loads the canonical `kya-os-engine` WASM automatically via
|
|
11
|
+
* `@kya-os/checkpoint-wasm-runtime`'s loaders. No manual `fs.readFileSync`
|
|
12
|
+
* needed; the runtime handles bundler resolution across Next.js Node +
|
|
13
|
+
* Edge runtimes.
|
|
6
14
|
*/
|
|
15
|
+
/** @internal — test-only reset for the one-shot warn latch. */
|
|
16
|
+
declare function __resetNodejsWasmWarningForTests(): void;
|
|
7
17
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
18
|
+
* @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
|
|
19
|
+
* `@kya-os/checkpoint-nextjs` — it auto-loads `kya-os-engine` WASM
|
|
20
|
+
* via `@kya-os/checkpoint-wasm-runtime`. Throws on invocation; surface
|
|
21
|
+
* exists only so static analysis sees the historical export.
|
|
10
22
|
*/
|
|
11
23
|
declare function loadWasmNodejs(): Promise<boolean>;
|
|
12
24
|
/**
|
|
13
|
-
*
|
|
25
|
+
* @deprecated Removed in Phase-D.9a. The runtime guard is no longer
|
|
26
|
+
* needed; `@kya-os/checkpoint-wasm-runtime`'s loaders auto-detect
|
|
27
|
+
* runtime via the `"node"` / `"edge-runtime"` export conditions.
|
|
28
|
+
* Throws on invocation; surface exists only for export-compatibility.
|
|
14
29
|
*/
|
|
15
30
|
declare function isNodejsRuntime(): boolean;
|
|
16
31
|
/**
|
|
17
|
-
*
|
|
32
|
+
* @deprecated Removed in Phase-D.9a. Migrate to `withCheckpoint`.
|
|
33
|
+
* Throws on invocation; surface exists only for export-compatibility.
|
|
18
34
|
*/
|
|
19
35
|
declare function getWasmModule(): WebAssembly.Module | null;
|
|
20
36
|
/**
|
|
21
|
-
*
|
|
37
|
+
* @deprecated Removed in Phase-D.9a. Migrate to `withCheckpoint`.
|
|
38
|
+
* Throws on invocation; surface exists only for export-compatibility.
|
|
22
39
|
*/
|
|
23
40
|
declare function isWasmInitialized(): boolean;
|
|
24
41
|
|
|
25
|
-
export { getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
42
|
+
export { __resetNodejsWasmWarningForTests, getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Node.js
|
|
2
|
+
* @deprecated Phase-D.9a — legacy Node.js WASM loader for the retired
|
|
3
|
+
* `agentshield-wasm` Rust crate. This file used `fs.readFileSync` to
|
|
4
|
+
* locate + load the legacy detector's WASM binary into the
|
|
5
|
+
* `@kya-os/checkpoint` `AgentDetector` class via `setWasmModule`. Both
|
|
6
|
+
* the WASM crate (Phase-D.9a/D.9b) and the AgentDetector class
|
|
7
|
+
* (AgentDetector-Deletion-2, next minor) are slated for deletion.
|
|
3
8
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
9
|
+
* Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` — it
|
|
10
|
+
* loads the canonical `kya-os-engine` WASM automatically via
|
|
11
|
+
* `@kya-os/checkpoint-wasm-runtime`'s loaders. No manual `fs.readFileSync`
|
|
12
|
+
* needed; the runtime handles bundler resolution across Next.js Node +
|
|
13
|
+
* Edge runtimes.
|
|
6
14
|
*/
|
|
15
|
+
/** @internal — test-only reset for the one-shot warn latch. */
|
|
16
|
+
declare function __resetNodejsWasmWarningForTests(): void;
|
|
7
17
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
18
|
+
* @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
|
|
19
|
+
* `@kya-os/checkpoint-nextjs` — it auto-loads `kya-os-engine` WASM
|
|
20
|
+
* via `@kya-os/checkpoint-wasm-runtime`. Throws on invocation; surface
|
|
21
|
+
* exists only so static analysis sees the historical export.
|
|
10
22
|
*/
|
|
11
23
|
declare function loadWasmNodejs(): Promise<boolean>;
|
|
12
24
|
/**
|
|
13
|
-
*
|
|
25
|
+
* @deprecated Removed in Phase-D.9a. The runtime guard is no longer
|
|
26
|
+
* needed; `@kya-os/checkpoint-wasm-runtime`'s loaders auto-detect
|
|
27
|
+
* runtime via the `"node"` / `"edge-runtime"` export conditions.
|
|
28
|
+
* Throws on invocation; surface exists only for export-compatibility.
|
|
14
29
|
*/
|
|
15
30
|
declare function isNodejsRuntime(): boolean;
|
|
16
31
|
/**
|
|
17
|
-
*
|
|
32
|
+
* @deprecated Removed in Phase-D.9a. Migrate to `withCheckpoint`.
|
|
33
|
+
* Throws on invocation; surface exists only for export-compatibility.
|
|
18
34
|
*/
|
|
19
35
|
declare function getWasmModule(): WebAssembly.Module | null;
|
|
20
36
|
/**
|
|
21
|
-
*
|
|
37
|
+
* @deprecated Removed in Phase-D.9a. Migrate to `withCheckpoint`.
|
|
38
|
+
* Throws on invocation; surface exists only for export-compatibility.
|
|
22
39
|
*/
|
|
23
40
|
declare function isWasmInitialized(): boolean;
|
|
24
41
|
|
|
25
|
-
export { getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
42
|
+
export { __resetNodejsWasmWarningForTests, getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
@@ -1,92 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
16
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
|
-
});
|
|
18
|
-
var wasmInitialized = false;
|
|
19
|
-
var wasmModule = null;
|
|
3
|
+
// src/nodejs-wasm-loader.ts
|
|
4
|
+
var MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs`'s `loadWasmNodejs` / `isNodejsRuntime` / `getWasmModule` / `isWasmInitialized` were deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). The legacy `AgentDetector` class they fed is slated for deletion in AgentDetector-Deletion-2 (next minor). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` \u2014 engine-backed via the Rust `kya-os-engine` crate, with automatic WASM loading via `@kya-os/checkpoint-wasm-runtime`. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
|
|
5
|
+
var _nodejsWasmWarned = false;
|
|
6
|
+
function warnNodejsWasmDeprecated() {
|
|
7
|
+
if (_nodejsWasmWarned) return;
|
|
8
|
+
_nodejsWasmWarned = true;
|
|
9
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
|
|
10
|
+
console.warn(`[Checkpoint] ${MIGRATION_ERROR}`);
|
|
11
|
+
}
|
|
12
|
+
function __resetNodejsWasmWarningForTests() {
|
|
13
|
+
_nodejsWasmWarned = false;
|
|
14
|
+
}
|
|
20
15
|
async function loadWasmNodejs() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
const possiblePaths = [
|
|
26
|
-
// In node_modules (most likely)
|
|
27
|
-
path__default.default.join(
|
|
28
|
-
process.cwd(),
|
|
29
|
-
"node_modules",
|
|
30
|
-
"@kya-os",
|
|
31
|
-
"agentshield",
|
|
32
|
-
"dist",
|
|
33
|
-
"wasm",
|
|
34
|
-
"agentshield_wasm_bg.wasm"
|
|
35
|
-
),
|
|
36
|
-
// In project root (if user copied it)
|
|
37
|
-
path__default.default.join(process.cwd(), "agentshield_wasm_bg.wasm"),
|
|
38
|
-
// Relative to current file
|
|
39
|
-
path__default.default.join(
|
|
40
|
-
__dirname,
|
|
41
|
-
"..",
|
|
42
|
-
"..",
|
|
43
|
-
"..",
|
|
44
|
-
"agentshield",
|
|
45
|
-
"dist",
|
|
46
|
-
"wasm",
|
|
47
|
-
"agentshield_wasm_bg.wasm"
|
|
48
|
-
)
|
|
49
|
-
];
|
|
50
|
-
let wasmBuffer = null;
|
|
51
|
-
let loadedPath = null;
|
|
52
|
-
for (const wasmPath of possiblePaths) {
|
|
53
|
-
try {
|
|
54
|
-
if (fs__default.default.existsSync(wasmPath)) {
|
|
55
|
-
wasmBuffer = fs__default.default.readFileSync(wasmPath);
|
|
56
|
-
loadedPath = wasmPath;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
} catch (e) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (!wasmBuffer) {
|
|
64
|
-
console.warn("AgentShield: WASM file not found in any expected location");
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
const bytes = new Uint8Array(wasmBuffer);
|
|
68
|
-
wasmModule = await WebAssembly.compile(bytes);
|
|
69
|
-
checkpoint.setWasmModule(wasmModule);
|
|
70
|
-
wasmInitialized = true;
|
|
71
|
-
console.log(`\u2705 AgentShield: WASM loaded successfully from ${loadedPath} (Node.js runtime)`);
|
|
72
|
-
console.log("\u{1F510} Cryptographic verification enabled (95-100% confidence)");
|
|
73
|
-
return true;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.warn("\u26A0\uFE0F AgentShield: Failed to load WASM in Node.js runtime:", error);
|
|
76
|
-
console.log("\u{1F4CA} Falling back to pattern detection (85% confidence)");
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
16
|
+
warnNodejsWasmDeprecated();
|
|
17
|
+
throw new Error(MIGRATION_ERROR);
|
|
79
18
|
}
|
|
80
19
|
function isNodejsRuntime() {
|
|
81
|
-
|
|
20
|
+
warnNodejsWasmDeprecated();
|
|
21
|
+
throw new Error(MIGRATION_ERROR);
|
|
82
22
|
}
|
|
83
23
|
function getWasmModule() {
|
|
84
|
-
|
|
24
|
+
warnNodejsWasmDeprecated();
|
|
25
|
+
throw new Error(MIGRATION_ERROR);
|
|
85
26
|
}
|
|
86
27
|
function isWasmInitialized() {
|
|
87
|
-
|
|
28
|
+
warnNodejsWasmDeprecated();
|
|
29
|
+
throw new Error(MIGRATION_ERROR);
|
|
88
30
|
}
|
|
89
31
|
|
|
32
|
+
exports.__resetNodejsWasmWarningForTests = __resetNodejsWasmWarningForTests;
|
|
90
33
|
exports.getWasmModule = getWasmModule;
|
|
91
34
|
exports.isNodejsRuntime = isNodejsRuntime;
|
|
92
35
|
exports.isWasmInitialized = isWasmInitialized;
|