@kya-os/checkpoint-nextjs 1.1.1 → 1.2.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 +174 -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 +5 -2
- package/dist/index.mjs +6 -3
- package/dist/middleware-edge.js +2 -1
- package/dist/middleware-edge.mjs +2 -1
- package/dist/middleware-node.d.mts +16 -1
- package/dist/middleware-node.d.ts +16 -1
- package/dist/middleware-node.js +2 -1
- package/dist/middleware-node.mjs +2 -1
- 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 +8 -6
- package/templates/middleware-wasm-100.ts +11 -3
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
|
|
@@ -118,7 +118,8 @@ function buildVerifyOpts(config) {
|
|
|
118
118
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
119
119
|
reputationBaseline: config.reputationBaseline,
|
|
120
120
|
argusUrl: config.argusUrl,
|
|
121
|
-
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
|
|
121
|
+
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false,
|
|
122
|
+
engineConfig: config.engineConfig
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
125
|
async function dispatchOnResult(config, result, req) {
|
|
@@ -697,7 +698,9 @@ var EdgeSessionTracker = class {
|
|
|
697
698
|
*/
|
|
698
699
|
async track(_request, response, result) {
|
|
699
700
|
try {
|
|
700
|
-
|
|
701
|
+
const detectedName = result.detectedAgent?.name;
|
|
702
|
+
const isEnforceable = result.isAgent || result.isAiCrawler || isKnownAiCrawler(detectedName);
|
|
703
|
+
if (!this.config.enabled || !isEnforceable) {
|
|
701
704
|
return response;
|
|
702
705
|
}
|
|
703
706
|
const sessionData = {
|
package/dist/middleware-edge.js
CHANGED
|
@@ -109,7 +109,8 @@ function buildVerifyOpts(config) {
|
|
|
109
109
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
110
110
|
reputationBaseline: config.reputationBaseline,
|
|
111
111
|
argusUrl: config.argusUrl,
|
|
112
|
-
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
|
|
112
|
+
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false,
|
|
113
|
+
engineConfig: config.engineConfig
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
116
|
|
package/dist/middleware-edge.mjs
CHANGED
|
@@ -108,7 +108,8 @@ function buildVerifyOpts(config) {
|
|
|
108
108
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
109
109
|
reputationBaseline: config.reputationBaseline,
|
|
110
110
|
argusUrl: config.argusUrl,
|
|
111
|
-
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
|
|
111
|
+
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false,
|
|
112
|
+
engineConfig: config.engineConfig
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _kya_os_checkpoint_wasm_runtime_adapters from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
2
2
|
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
3
3
|
import { NextRequest, NextResponse } from 'next/server';
|
|
4
|
-
import { EnforcementMode, VerifyResult } from '@kya-os/checkpoint-wasm-runtime/engine';
|
|
4
|
+
import { EnforcementMode, VerifyResult, EngineConfig } from '@kya-os/checkpoint-wasm-runtime/engine';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for `withCheckpoint`.
|
|
@@ -93,6 +93,20 @@ interface CheckpointConfig {
|
|
|
93
93
|
* SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
|
|
94
94
|
*/
|
|
95
95
|
drainJsonBody?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Engine-default behaviour knobs forwarded to every composed
|
|
98
|
+
* `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
|
|
99
|
+
* customer-onboarding-safe (tenant policy decides; engine doesn't
|
|
100
|
+
* short-circuit known-agent UAs with an engine-default Block).
|
|
101
|
+
*
|
|
102
|
+
* Opt into `{ tier3Action: 'block' }` when the host wants the
|
|
103
|
+
* calibrated engine-default block for KnownAiAgent / AiCrawler /
|
|
104
|
+
* HeadlessBrowser classifications BEFORE the tenant policy seam.
|
|
105
|
+
*
|
|
106
|
+
* Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
|
|
107
|
+
* Default, #2653 + this PR's plumbing follow-up).
|
|
108
|
+
*/
|
|
109
|
+
engineConfig?: EngineConfig;
|
|
96
110
|
}
|
|
97
111
|
/**
|
|
98
112
|
* Build the Checkpoint middleware. Returns a function `(req) => NextResponse`
|
|
@@ -120,6 +134,7 @@ declare function buildVerifyOpts(config: CheckpointConfig): {
|
|
|
120
134
|
reputationBaseline: number | undefined;
|
|
121
135
|
argusUrl: string | undefined;
|
|
122
136
|
legacyEnvelopeFallback: boolean;
|
|
137
|
+
engineConfig: EngineConfig | undefined;
|
|
123
138
|
};
|
|
124
139
|
|
|
125
140
|
export { type CheckpointConfig, buildVerifyOpts as _buildVerifyOpts, withCheckpoint };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _kya_os_checkpoint_wasm_runtime_adapters from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
2
2
|
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
3
3
|
import { NextRequest, NextResponse } from 'next/server';
|
|
4
|
-
import { EnforcementMode, VerifyResult } from '@kya-os/checkpoint-wasm-runtime/engine';
|
|
4
|
+
import { EnforcementMode, VerifyResult, EngineConfig } from '@kya-os/checkpoint-wasm-runtime/engine';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for `withCheckpoint`.
|
|
@@ -93,6 +93,20 @@ interface CheckpointConfig {
|
|
|
93
93
|
* SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
|
|
94
94
|
*/
|
|
95
95
|
drainJsonBody?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Engine-default behaviour knobs forwarded to every composed
|
|
98
|
+
* `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` —
|
|
99
|
+
* customer-onboarding-safe (tenant policy decides; engine doesn't
|
|
100
|
+
* short-circuit known-agent UAs with an engine-default Block).
|
|
101
|
+
*
|
|
102
|
+
* Opt into `{ tier3Action: 'block' }` when the host wants the
|
|
103
|
+
* calibrated engine-default block for KnownAiAgent / AiCrawler /
|
|
104
|
+
* HeadlessBrowser classifications BEFORE the tenant policy seam.
|
|
105
|
+
*
|
|
106
|
+
* Added in `@kya-os/checkpoint-nextjs@1.2.0` (Engine-Tier3-Monitor-
|
|
107
|
+
* Default, #2653 + this PR's plumbing follow-up).
|
|
108
|
+
*/
|
|
109
|
+
engineConfig?: EngineConfig;
|
|
96
110
|
}
|
|
97
111
|
/**
|
|
98
112
|
* Build the Checkpoint middleware. Returns a function `(req) => NextResponse`
|
|
@@ -120,6 +134,7 @@ declare function buildVerifyOpts(config: CheckpointConfig): {
|
|
|
120
134
|
reputationBaseline: number | undefined;
|
|
121
135
|
argusUrl: string | undefined;
|
|
122
136
|
legacyEnvelopeFallback: boolean;
|
|
137
|
+
engineConfig: EngineConfig | undefined;
|
|
123
138
|
};
|
|
124
139
|
|
|
125
140
|
export { type CheckpointConfig, buildVerifyOpts as _buildVerifyOpts, withCheckpoint };
|
package/dist/middleware-node.js
CHANGED
|
@@ -119,7 +119,8 @@ function buildVerifyOpts(config) {
|
|
|
119
119
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
120
120
|
reputationBaseline: config.reputationBaseline,
|
|
121
121
|
argusUrl: config.argusUrl,
|
|
122
|
-
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
|
|
122
|
+
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false,
|
|
123
|
+
engineConfig: config.engineConfig
|
|
123
124
|
};
|
|
124
125
|
}
|
|
125
126
|
async function dispatchOnResult(config, result, req) {
|
package/dist/middleware-node.mjs
CHANGED
|
@@ -117,7 +117,8 @@ function buildVerifyOpts(config) {
|
|
|
117
117
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
118
118
|
reputationBaseline: config.reputationBaseline,
|
|
119
119
|
argusUrl: config.argusUrl,
|
|
120
|
-
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
|
|
120
|
+
legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false,
|
|
121
|
+
engineConfig: config.engineConfig
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
async function dispatchOnResult(config, result, req) {
|
|
@@ -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 };
|