@kya-os/checkpoint-nextjs 1.1.1 → 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 +143 -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 +17 -28
- package/dist/edge-runtime-loader.d.ts +17 -28
- package/dist/edge-runtime-loader.js +43 -14
- package/dist/edge-runtime-loader.mjs +44 -15
- 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,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;
|
|
@@ -1,83 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
// src/nodejs-wasm-loader.ts
|
|
2
|
+
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.";
|
|
3
|
+
var _nodejsWasmWarned = false;
|
|
4
|
+
function warnNodejsWasmDeprecated() {
|
|
5
|
+
if (_nodejsWasmWarned) return;
|
|
6
|
+
_nodejsWasmWarned = true;
|
|
7
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
|
|
8
|
+
console.warn(`[Checkpoint] ${MIGRATION_ERROR}`);
|
|
9
|
+
}
|
|
10
|
+
function __resetNodejsWasmWarningForTests() {
|
|
11
|
+
_nodejsWasmWarned = false;
|
|
12
|
+
}
|
|
13
13
|
async function loadWasmNodejs() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const possiblePaths = [
|
|
19
|
-
// In node_modules (most likely)
|
|
20
|
-
path.join(
|
|
21
|
-
process.cwd(),
|
|
22
|
-
"node_modules",
|
|
23
|
-
"@kya-os",
|
|
24
|
-
"agentshield",
|
|
25
|
-
"dist",
|
|
26
|
-
"wasm",
|
|
27
|
-
"agentshield_wasm_bg.wasm"
|
|
28
|
-
),
|
|
29
|
-
// In project root (if user copied it)
|
|
30
|
-
path.join(process.cwd(), "agentshield_wasm_bg.wasm"),
|
|
31
|
-
// Relative to current file
|
|
32
|
-
path.join(
|
|
33
|
-
__dirname,
|
|
34
|
-
"..",
|
|
35
|
-
"..",
|
|
36
|
-
"..",
|
|
37
|
-
"agentshield",
|
|
38
|
-
"dist",
|
|
39
|
-
"wasm",
|
|
40
|
-
"agentshield_wasm_bg.wasm"
|
|
41
|
-
)
|
|
42
|
-
];
|
|
43
|
-
let wasmBuffer = null;
|
|
44
|
-
let loadedPath = null;
|
|
45
|
-
for (const wasmPath of possiblePaths) {
|
|
46
|
-
try {
|
|
47
|
-
if (fs.existsSync(wasmPath)) {
|
|
48
|
-
wasmBuffer = fs.readFileSync(wasmPath);
|
|
49
|
-
loadedPath = wasmPath;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
} catch (e) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (!wasmBuffer) {
|
|
57
|
-
console.warn("AgentShield: WASM file not found in any expected location");
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
const bytes = new Uint8Array(wasmBuffer);
|
|
61
|
-
wasmModule = await WebAssembly.compile(bytes);
|
|
62
|
-
setWasmModule(wasmModule);
|
|
63
|
-
wasmInitialized = true;
|
|
64
|
-
console.log(`\u2705 AgentShield: WASM loaded successfully from ${loadedPath} (Node.js runtime)`);
|
|
65
|
-
console.log("\u{1F510} Cryptographic verification enabled (95-100% confidence)");
|
|
66
|
-
return true;
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.warn("\u26A0\uFE0F AgentShield: Failed to load WASM in Node.js runtime:", error);
|
|
69
|
-
console.log("\u{1F4CA} Falling back to pattern detection (85% confidence)");
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
14
|
+
warnNodejsWasmDeprecated();
|
|
15
|
+
throw new Error(MIGRATION_ERROR);
|
|
72
16
|
}
|
|
73
17
|
function isNodejsRuntime() {
|
|
74
|
-
|
|
18
|
+
warnNodejsWasmDeprecated();
|
|
19
|
+
throw new Error(MIGRATION_ERROR);
|
|
75
20
|
}
|
|
76
21
|
function getWasmModule() {
|
|
77
|
-
|
|
22
|
+
warnNodejsWasmDeprecated();
|
|
23
|
+
throw new Error(MIGRATION_ERROR);
|
|
78
24
|
}
|
|
79
25
|
function isWasmInitialized() {
|
|
80
|
-
|
|
26
|
+
warnNodejsWasmDeprecated();
|
|
27
|
+
throw new Error(MIGRATION_ERROR);
|
|
81
28
|
}
|
|
82
29
|
|
|
83
|
-
export { getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
30
|
+
export { __resetNodejsWasmWarningForTests, getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { DetectionDetail } from '@kya-os/checkpoint-shared';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Edge-compatible session tracking for AI agents
|
|
@@ -25,7 +25,7 @@ declare class EdgeSessionTracker {
|
|
|
25
25
|
/**
|
|
26
26
|
* Track a new AI agent session
|
|
27
27
|
*/
|
|
28
|
-
track(_request: NextRequest, response: NextResponse, result:
|
|
28
|
+
track(_request: NextRequest, response: NextResponse, result: DetectionDetail): Promise<NextResponse>;
|
|
29
29
|
/**
|
|
30
30
|
* Check for existing AI agent session
|
|
31
31
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { DetectionDetail } from '@kya-os/checkpoint-shared';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Edge-compatible session tracking for AI agents
|
|
@@ -25,7 +25,7 @@ declare class EdgeSessionTracker {
|
|
|
25
25
|
/**
|
|
26
26
|
* Track a new AI agent session
|
|
27
27
|
*/
|
|
28
|
-
track(_request: NextRequest, response: NextResponse, result:
|
|
28
|
+
track(_request: NextRequest, response: NextResponse, result: DetectionDetail): Promise<NextResponse>;
|
|
29
29
|
/**
|
|
30
30
|
* Check for existing AI agent session
|
|
31
31
|
*/
|
package/dist/session-tracker.js
CHANGED
|
@@ -19,7 +19,9 @@ var EdgeSessionTracker = class {
|
|
|
19
19
|
*/
|
|
20
20
|
async track(_request, response, result) {
|
|
21
21
|
try {
|
|
22
|
-
|
|
22
|
+
const detectedName = result.detectedAgent?.name;
|
|
23
|
+
const isEnforceable = result.isAgent || result.isAiCrawler || checkpointShared.isKnownAiCrawler(detectedName);
|
|
24
|
+
if (!this.config.enabled || !isEnforceable) {
|
|
23
25
|
return response;
|
|
24
26
|
}
|
|
25
27
|
const sessionData = {
|
package/dist/session-tracker.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isKnownAiCrawler } from '@kya-os/checkpoint-shared';
|
|
2
2
|
|
|
3
3
|
// src/session-tracker.ts
|
|
4
4
|
var EdgeSessionTracker = class {
|
|
@@ -17,7 +17,9 @@ var EdgeSessionTracker = class {
|
|
|
17
17
|
*/
|
|
18
18
|
async track(_request, response, result) {
|
|
19
19
|
try {
|
|
20
|
-
|
|
20
|
+
const detectedName = result.detectedAgent?.name;
|
|
21
|
+
const isEnforceable = result.isAgent || result.isAiCrawler || isKnownAiCrawler(detectedName);
|
|
22
|
+
if (!this.config.enabled || !isEnforceable) {
|
|
21
23
|
return response;
|
|
22
24
|
}
|
|
23
25
|
const sessionData = {
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* WASM-enabled middleware for Next.js with
|
|
5
|
-
*
|
|
4
|
+
* WASM-enabled middleware for Next.js with Checkpoint.
|
|
5
|
+
*
|
|
6
|
+
* **Deprecation notice (AgentDetector-Deletion-1):**
|
|
7
|
+
* `createWasmAgentShieldMiddleware` is deprecated as of this patch and
|
|
8
|
+
* slated for removal in the next minor. It internally constructs a
|
|
9
|
+
* legacy `AgentDetector` and never actually uses the WASM instance for
|
|
10
|
+
* detection (the `wasmInstance` arg only bumps confidence by 15%).
|
|
11
|
+
* Stage 1 detection now lives in the Rust `kya-os-engine` (PDM-1
|
|
12
|
+
* #2560). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs`
|
|
13
|
+
* — engine-backed, runs the orchestrator including envelope
|
|
14
|
+
* verification.
|
|
6
15
|
*/
|
|
7
16
|
|
|
17
|
+
/** @internal — test-only reset for the one-shot warn latch. */
|
|
18
|
+
declare function __resetCreateWasmAgentShieldWarningForTests(): void;
|
|
8
19
|
interface WasmDetectionResult {
|
|
9
20
|
isAgent: boolean;
|
|
10
21
|
isAiCrawler?: boolean;
|
|
@@ -26,6 +37,11 @@ interface AgentShieldConfig {
|
|
|
26
37
|
};
|
|
27
38
|
}
|
|
28
39
|
/**
|
|
40
|
+
* @deprecated Wraps the legacy `AgentDetector` class. Will be removed
|
|
41
|
+
* in the next minor (AgentDetector-Deletion-2). Migrate to
|
|
42
|
+
* `withCheckpoint` from `@kya-os/checkpoint-nextjs` — engine-backed,
|
|
43
|
+
* runs the orchestrator including envelope verification.
|
|
44
|
+
*
|
|
29
45
|
* Create a WASM-enabled Checkpoint middleware (**pattern-detection only**).
|
|
30
46
|
*
|
|
31
47
|
* **This factory runs UA/header pattern matching only.** It does NOT
|
|
@@ -79,4 +95,4 @@ declare function createWasmAgentShieldMiddleware(config: AgentShieldConfig & {
|
|
|
79
95
|
*/
|
|
80
96
|
declare function instantiateWasm(wasmModule: WebAssembly.Module): Promise<WebAssembly.Instance>;
|
|
81
97
|
|
|
82
|
-
export { type AgentShieldConfig, type WasmDetectionResult, createWasmAgentShieldMiddleware, instantiateWasm };
|
|
98
|
+
export { type AgentShieldConfig, type WasmDetectionResult, __resetCreateWasmAgentShieldWarningForTests, createWasmAgentShieldMiddleware, instantiateWasm };
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* WASM-enabled middleware for Next.js with
|
|
5
|
-
*
|
|
4
|
+
* WASM-enabled middleware for Next.js with Checkpoint.
|
|
5
|
+
*
|
|
6
|
+
* **Deprecation notice (AgentDetector-Deletion-1):**
|
|
7
|
+
* `createWasmAgentShieldMiddleware` is deprecated as of this patch and
|
|
8
|
+
* slated for removal in the next minor. It internally constructs a
|
|
9
|
+
* legacy `AgentDetector` and never actually uses the WASM instance for
|
|
10
|
+
* detection (the `wasmInstance` arg only bumps confidence by 15%).
|
|
11
|
+
* Stage 1 detection now lives in the Rust `kya-os-engine` (PDM-1
|
|
12
|
+
* #2560). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs`
|
|
13
|
+
* — engine-backed, runs the orchestrator including envelope
|
|
14
|
+
* verification.
|
|
6
15
|
*/
|
|
7
16
|
|
|
17
|
+
/** @internal — test-only reset for the one-shot warn latch. */
|
|
18
|
+
declare function __resetCreateWasmAgentShieldWarningForTests(): void;
|
|
8
19
|
interface WasmDetectionResult {
|
|
9
20
|
isAgent: boolean;
|
|
10
21
|
isAiCrawler?: boolean;
|
|
@@ -26,6 +37,11 @@ interface AgentShieldConfig {
|
|
|
26
37
|
};
|
|
27
38
|
}
|
|
28
39
|
/**
|
|
40
|
+
* @deprecated Wraps the legacy `AgentDetector` class. Will be removed
|
|
41
|
+
* in the next minor (AgentDetector-Deletion-2). Migrate to
|
|
42
|
+
* `withCheckpoint` from `@kya-os/checkpoint-nextjs` — engine-backed,
|
|
43
|
+
* runs the orchestrator including envelope verification.
|
|
44
|
+
*
|
|
29
45
|
* Create a WASM-enabled Checkpoint middleware (**pattern-detection only**).
|
|
30
46
|
*
|
|
31
47
|
* **This factory runs UA/header pattern matching only.** It does NOT
|
|
@@ -79,4 +95,4 @@ declare function createWasmAgentShieldMiddleware(config: AgentShieldConfig & {
|
|
|
79
95
|
*/
|
|
80
96
|
declare function instantiateWasm(wasmModule: WebAssembly.Module): Promise<WebAssembly.Instance>;
|
|
81
97
|
|
|
82
|
-
export { type AgentShieldConfig, type WasmDetectionResult, createWasmAgentShieldMiddleware, instantiateWasm };
|
|
98
|
+
export { type AgentShieldConfig, type WasmDetectionResult, __resetCreateWasmAgentShieldWarningForTests, createWasmAgentShieldMiddleware, instantiateWasm };
|
package/dist/wasm-middleware.js
CHANGED
|
@@ -2,10 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
var server = require('next/server');
|
|
4
4
|
var checkpoint = require('@kya-os/checkpoint');
|
|
5
|
-
var checkpointShared = require('@kya-os/checkpoint-shared');
|
|
6
5
|
|
|
7
6
|
// src/wasm-middleware.ts
|
|
7
|
+
|
|
8
|
+
// src/local-detection-gate.ts
|
|
9
|
+
function isDetectedAgentForLocalGate(result) {
|
|
10
|
+
return result.isAgent === true;
|
|
11
|
+
}
|
|
12
|
+
function evaluateLocalDetectionGate(result, config) {
|
|
13
|
+
if (!isDetectedAgentForLocalGate(result)) {
|
|
14
|
+
return { action: "allow", shouldNotify: false };
|
|
15
|
+
}
|
|
16
|
+
if ((result.confidence ?? 0) >= config.confidenceThreshold) {
|
|
17
|
+
return { action: config.defaultAction, shouldNotify: true };
|
|
18
|
+
}
|
|
19
|
+
return { action: "allow", shouldNotify: false };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/wasm-middleware.ts
|
|
23
|
+
var _createWasmAgentShieldWarned = false;
|
|
24
|
+
function warnCreateWasmAgentShieldDeprecated() {
|
|
25
|
+
if (_createWasmAgentShieldWarned) return;
|
|
26
|
+
_createWasmAgentShieldWarned = true;
|
|
27
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
|
|
28
|
+
console.warn(
|
|
29
|
+
"[Checkpoint] createWasmAgentShieldMiddleware is deprecated and will be removed in the next minor. It wraps the legacy AgentDetector class; Stage 1 detection now lives in the Rust kya-os-engine (PDM-1). Migrate to `withCheckpoint` from @kya-os/checkpoint-nextjs \u2014 engine-backed and runs envelope verification. See packages/checkpoint-nextjs/CHANGELOG.md for the recipe."
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function __resetCreateWasmAgentShieldWarningForTests() {
|
|
33
|
+
_createWasmAgentShieldWarned = false;
|
|
34
|
+
}
|
|
8
35
|
function createWasmAgentShieldMiddleware(config) {
|
|
36
|
+
warnCreateWasmAgentShieldDeprecated();
|
|
9
37
|
const {
|
|
10
38
|
onAgentDetected,
|
|
11
39
|
blockOnHighConfidence = false,
|
|
@@ -45,11 +73,11 @@ function createWasmAgentShieldMiddleware(config) {
|
|
|
45
73
|
// Updated to 0-100 scale (was 0.7)
|
|
46
74
|
timestamp: result.timestamp instanceof Date ? result.timestamp.toISOString() : new Date(result.timestamp).toISOString()
|
|
47
75
|
};
|
|
48
|
-
const decision =
|
|
76
|
+
const decision = evaluateLocalDetectionGate(enhancedResult, {
|
|
49
77
|
confidenceThreshold,
|
|
50
78
|
defaultAction: blockOnHighConfidence ? "block" : "allow"
|
|
51
79
|
});
|
|
52
|
-
if (onAgentDetected &&
|
|
80
|
+
if (onAgentDetected && isDetectedAgentForLocalGate(enhancedResult)) {
|
|
53
81
|
await onAgentDetected(enhancedResult);
|
|
54
82
|
}
|
|
55
83
|
if (decision.action === "block") {
|
|
@@ -92,5 +120,6 @@ async function instantiateWasm(wasmModule) {
|
|
|
92
120
|
}
|
|
93
121
|
}
|
|
94
122
|
|
|
123
|
+
exports.__resetCreateWasmAgentShieldWarningForTests = __resetCreateWasmAgentShieldWarningForTests;
|
|
95
124
|
exports.createWasmAgentShieldMiddleware = createWasmAgentShieldMiddleware;
|
|
96
125
|
exports.instantiateWasm = instantiateWasm;
|
package/dist/wasm-middleware.mjs
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
2
|
import { AgentDetector } from '@kya-os/checkpoint';
|
|
3
|
-
import { evaluateEnforcement, shouldEnforce } from '@kya-os/checkpoint-shared';
|
|
4
3
|
|
|
5
4
|
// src/wasm-middleware.ts
|
|
5
|
+
|
|
6
|
+
// src/local-detection-gate.ts
|
|
7
|
+
function isDetectedAgentForLocalGate(result) {
|
|
8
|
+
return result.isAgent === true;
|
|
9
|
+
}
|
|
10
|
+
function evaluateLocalDetectionGate(result, config) {
|
|
11
|
+
if (!isDetectedAgentForLocalGate(result)) {
|
|
12
|
+
return { action: "allow", shouldNotify: false };
|
|
13
|
+
}
|
|
14
|
+
if ((result.confidence ?? 0) >= config.confidenceThreshold) {
|
|
15
|
+
return { action: config.defaultAction, shouldNotify: true };
|
|
16
|
+
}
|
|
17
|
+
return { action: "allow", shouldNotify: false };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/wasm-middleware.ts
|
|
21
|
+
var _createWasmAgentShieldWarned = false;
|
|
22
|
+
function warnCreateWasmAgentShieldDeprecated() {
|
|
23
|
+
if (_createWasmAgentShieldWarned) return;
|
|
24
|
+
_createWasmAgentShieldWarned = true;
|
|
25
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
|
|
26
|
+
console.warn(
|
|
27
|
+
"[Checkpoint] createWasmAgentShieldMiddleware is deprecated and will be removed in the next minor. It wraps the legacy AgentDetector class; Stage 1 detection now lives in the Rust kya-os-engine (PDM-1). Migrate to `withCheckpoint` from @kya-os/checkpoint-nextjs \u2014 engine-backed and runs envelope verification. See packages/checkpoint-nextjs/CHANGELOG.md for the recipe."
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function __resetCreateWasmAgentShieldWarningForTests() {
|
|
31
|
+
_createWasmAgentShieldWarned = false;
|
|
32
|
+
}
|
|
6
33
|
function createWasmAgentShieldMiddleware(config) {
|
|
34
|
+
warnCreateWasmAgentShieldDeprecated();
|
|
7
35
|
const {
|
|
8
36
|
onAgentDetected,
|
|
9
37
|
blockOnHighConfidence = false,
|
|
@@ -43,11 +71,11 @@ function createWasmAgentShieldMiddleware(config) {
|
|
|
43
71
|
// Updated to 0-100 scale (was 0.7)
|
|
44
72
|
timestamp: result.timestamp instanceof Date ? result.timestamp.toISOString() : new Date(result.timestamp).toISOString()
|
|
45
73
|
};
|
|
46
|
-
const decision =
|
|
74
|
+
const decision = evaluateLocalDetectionGate(enhancedResult, {
|
|
47
75
|
confidenceThreshold,
|
|
48
76
|
defaultAction: blockOnHighConfidence ? "block" : "allow"
|
|
49
77
|
});
|
|
50
|
-
if (onAgentDetected &&
|
|
78
|
+
if (onAgentDetected && isDetectedAgentForLocalGate(enhancedResult)) {
|
|
51
79
|
await onAgentDetected(enhancedResult);
|
|
52
80
|
}
|
|
53
81
|
if (decision.action === "block") {
|
|
@@ -90,4 +118,4 @@ async function instantiateWasm(wasmModule) {
|
|
|
90
118
|
}
|
|
91
119
|
}
|
|
92
120
|
|
|
93
|
-
export { createWasmAgentShieldMiddleware, instantiateWasm };
|
|
121
|
+
export { __resetCreateWasmAgentShieldWarningForTests, createWasmAgentShieldMiddleware, instantiateWasm };
|