@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.
Files changed (39) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/EDGE_RUNTIME_WASM_SETUP.md +4 -10
  3. package/README.md +13 -0
  4. package/bin/setup-edge-wasm.js +40 -32
  5. package/dist/api-client.d.mts +10 -10
  6. package/dist/api-client.d.ts +10 -10
  7. package/dist/create-middleware.d.mts +7 -2
  8. package/dist/create-middleware.d.ts +7 -2
  9. package/dist/edge/index.d.mts +3 -3
  10. package/dist/edge/index.d.ts +3 -3
  11. package/dist/edge/index.js +16 -3
  12. package/dist/edge/index.mjs +16 -3
  13. package/dist/edge-runtime-loader.d.mts +17 -28
  14. package/dist/edge-runtime-loader.d.ts +17 -28
  15. package/dist/edge-runtime-loader.js +43 -14
  16. package/dist/edge-runtime-loader.mjs +44 -15
  17. package/dist/edge-wasm-middleware.d.mts +28 -34
  18. package/dist/edge-wasm-middleware.d.ts +28 -34
  19. package/dist/edge-wasm-middleware.js +16 -306
  20. package/dist/edge-wasm-middleware.mjs +16 -307
  21. package/dist/index.js +3 -1
  22. package/dist/index.mjs +4 -2
  23. package/dist/nodejs-wasm-loader.d.mts +26 -9
  24. package/dist/nodejs-wasm-loader.d.ts +26 -9
  25. package/dist/nodejs-wasm-loader.js +21 -78
  26. package/dist/nodejs-wasm-loader.mjs +21 -74
  27. package/dist/session-tracker.d.mts +2 -2
  28. package/dist/session-tracker.d.ts +2 -2
  29. package/dist/session-tracker.js +3 -1
  30. package/dist/session-tracker.mjs +4 -2
  31. package/dist/wasm-middleware.d.mts +19 -3
  32. package/dist/wasm-middleware.d.ts +19 -3
  33. package/dist/wasm-middleware.js +32 -3
  34. package/dist/wasm-middleware.mjs +32 -4
  35. package/dist/wasm-setup.js +29 -81
  36. package/dist/wasm-setup.mjs +29 -76
  37. package/package.json +4 -4
  38. package/templates/middleware-wasm-100.ts +11 -3
  39. package/dist/.tsbuildinfo +0 -1
@@ -1,3 +1,4 @@
1
+ import { DetectionDetail } from '@kya-os/checkpoint-shared';
1
2
  import { NextRequest } from 'next/server';
2
3
 
3
4
  /**
@@ -8,23 +9,16 @@ import { NextRequest } from 'next/server';
8
9
  *
9
10
  * ## SSOT for pattern detection
10
11
  *
11
- * The fallback `patternDetection` path imports BOTH pattern arrays
12
- * from `@kya-os/checkpoint-shared/constants/agents`:
13
- *
14
- * - `KNOWN_AGENT_PATTERNS` strict SSOT carved for the server-side
15
- * classifier (per-agent rows with category + isLegitimate fields).
16
- * - `INTERACTIVE_AGENT_PATTERNS` supplement holding interactive-
17
- * session tokens, generic vendor fallbacks, and the GPT-Crawler
18
- * entry that lives in seed-agent-types-data.ts (NOT in the strict
19
- * SSOT).
20
- *
21
- * Pre-#2599 this file had a 15-pattern inline subset that diverged
22
- * from the shared SSOT — the you.com regex was tightened in agents.ts
23
- * but reverted here. SSOT-Fallback-Drift-1 (this PR) collapsed the
24
- * inline duplication and moved the supplement into checkpoint-shared
25
- * so both layers reference the same source. EPIC #2573 (PDM-2) is the
26
- * future unified-SSOT consolidation that folds the two arrays into
27
- * one canonical table.
12
+ * The fallback `patternDetection` path imports the single canonical
13
+ * pattern table `KNOWN_AGENT_PATTERNS` from
14
+ * `@kya-os/checkpoint-shared/constants/agents`. PDM-2 (#2573) folded
15
+ * what was previously a sibling supplement export
16
+ * (`INTERACTIVE_AGENT_PATTERNS`) into per-agent SSOT rows alongside
17
+ * the existing entries interactive-session tokens, generic vendor
18
+ * fallbacks, and the GPT-Crawler bot are now first-class SSOT rows
19
+ * with `category`/`isLegitimate` fields. The drift-prevention test
20
+ * in `checkpoint-shared/__tests__/constants/agents.test.ts` enforces
21
+ * that no future PR re-introduces a sibling pool.
28
22
  *
29
23
  * ## Naming
30
24
  *
@@ -37,19 +31,14 @@ import { NextRequest } from 'next/server';
37
31
  interface WasmModule {
38
32
  default: WebAssembly.Module;
39
33
  }
40
- interface DetectionResult {
41
- isAgent: boolean;
42
- isAiCrawler?: boolean;
43
- confidence: number;
34
+ type EdgeRuntimeDetectionDetail = DetectionDetail & {
44
35
  agent?: string;
45
- verificationMethod: 'cryptographic' | 'pattern';
46
- riskLevel?: 'low' | 'medium' | 'high' | 'critical';
47
- timestamp: string;
48
- }
36
+ };
37
+
49
38
  interface EdgeCheckpointConfig {
50
39
  wasmModule?: WebAssembly.Module;
51
40
  enableWasm?: boolean;
52
- onAgentDetected?: (result: DetectionResult) => void;
41
+ onAgentDetected?: (result: EdgeRuntimeDetectionDetail) => void;
53
42
  blockAgents?: boolean;
54
43
  allowedAgents?: string[];
55
44
  debug?: boolean;
@@ -63,7 +52,7 @@ declare class EdgeRuntimeCheckpoint {
63
52
  init(wasmModule?: WebAssembly.Module): Promise<void>;
64
53
  private readString;
65
54
  private writeString;
66
- detect(request: NextRequest): Promise<DetectionResult>;
55
+ detect(request: NextRequest): Promise<EdgeRuntimeDetectionDetail>;
67
56
  private patternDetection;
68
57
  isInitialized(): boolean;
69
58
  getVerificationMethod(): 'cryptographic' | 'pattern';
@@ -83,4 +72,4 @@ declare const createEdgeAgentShield: typeof createEdgeCheckpoint;
83
72
  /** @deprecated Renamed to {@link getDefaultEdgeCheckpoint}. */
84
73
  declare const getDefaultAgentShield: typeof getDefaultEdgeCheckpoint;
85
74
 
86
- export { type AgentShieldConfig, type DetectionResult, type EdgeCheckpointConfig, EdgeRuntimeAgentShield, EdgeRuntimeCheckpoint, type WasmModule, createEdgeAgentShield, createEdgeCheckpoint, getDefaultAgentShield, getDefaultEdgeCheckpoint };
75
+ export { type AgentShieldConfig, type EdgeRuntimeDetectionDetail as DetectionResult, type EdgeCheckpointConfig, EdgeRuntimeAgentShield, EdgeRuntimeCheckpoint, type EdgeRuntimeDetectionDetail, type WasmModule, createEdgeAgentShield, createEdgeCheckpoint, getDefaultAgentShield, getDefaultEdgeCheckpoint };
@@ -1,3 +1,4 @@
1
+ import { DetectionDetail } from '@kya-os/checkpoint-shared';
1
2
  import { NextRequest } from 'next/server';
2
3
 
3
4
  /**
@@ -8,23 +9,16 @@ import { NextRequest } from 'next/server';
8
9
  *
9
10
  * ## SSOT for pattern detection
10
11
  *
11
- * The fallback `patternDetection` path imports BOTH pattern arrays
12
- * from `@kya-os/checkpoint-shared/constants/agents`:
13
- *
14
- * - `KNOWN_AGENT_PATTERNS` strict SSOT carved for the server-side
15
- * classifier (per-agent rows with category + isLegitimate fields).
16
- * - `INTERACTIVE_AGENT_PATTERNS` supplement holding interactive-
17
- * session tokens, generic vendor fallbacks, and the GPT-Crawler
18
- * entry that lives in seed-agent-types-data.ts (NOT in the strict
19
- * SSOT).
20
- *
21
- * Pre-#2599 this file had a 15-pattern inline subset that diverged
22
- * from the shared SSOT — the you.com regex was tightened in agents.ts
23
- * but reverted here. SSOT-Fallback-Drift-1 (this PR) collapsed the
24
- * inline duplication and moved the supplement into checkpoint-shared
25
- * so both layers reference the same source. EPIC #2573 (PDM-2) is the
26
- * future unified-SSOT consolidation that folds the two arrays into
27
- * one canonical table.
12
+ * The fallback `patternDetection` path imports the single canonical
13
+ * pattern table `KNOWN_AGENT_PATTERNS` from
14
+ * `@kya-os/checkpoint-shared/constants/agents`. PDM-2 (#2573) folded
15
+ * what was previously a sibling supplement export
16
+ * (`INTERACTIVE_AGENT_PATTERNS`) into per-agent SSOT rows alongside
17
+ * the existing entries interactive-session tokens, generic vendor
18
+ * fallbacks, and the GPT-Crawler bot are now first-class SSOT rows
19
+ * with `category`/`isLegitimate` fields. The drift-prevention test
20
+ * in `checkpoint-shared/__tests__/constants/agents.test.ts` enforces
21
+ * that no future PR re-introduces a sibling pool.
28
22
  *
29
23
  * ## Naming
30
24
  *
@@ -37,19 +31,14 @@ import { NextRequest } from 'next/server';
37
31
  interface WasmModule {
38
32
  default: WebAssembly.Module;
39
33
  }
40
- interface DetectionResult {
41
- isAgent: boolean;
42
- isAiCrawler?: boolean;
43
- confidence: number;
34
+ type EdgeRuntimeDetectionDetail = DetectionDetail & {
44
35
  agent?: string;
45
- verificationMethod: 'cryptographic' | 'pattern';
46
- riskLevel?: 'low' | 'medium' | 'high' | 'critical';
47
- timestamp: string;
48
- }
36
+ };
37
+
49
38
  interface EdgeCheckpointConfig {
50
39
  wasmModule?: WebAssembly.Module;
51
40
  enableWasm?: boolean;
52
- onAgentDetected?: (result: DetectionResult) => void;
41
+ onAgentDetected?: (result: EdgeRuntimeDetectionDetail) => void;
53
42
  blockAgents?: boolean;
54
43
  allowedAgents?: string[];
55
44
  debug?: boolean;
@@ -63,7 +52,7 @@ declare class EdgeRuntimeCheckpoint {
63
52
  init(wasmModule?: WebAssembly.Module): Promise<void>;
64
53
  private readString;
65
54
  private writeString;
66
- detect(request: NextRequest): Promise<DetectionResult>;
55
+ detect(request: NextRequest): Promise<EdgeRuntimeDetectionDetail>;
67
56
  private patternDetection;
68
57
  isInitialized(): boolean;
69
58
  getVerificationMethod(): 'cryptographic' | 'pattern';
@@ -83,4 +72,4 @@ declare const createEdgeAgentShield: typeof createEdgeCheckpoint;
83
72
  /** @deprecated Renamed to {@link getDefaultEdgeCheckpoint}. */
84
73
  declare const getDefaultAgentShield: typeof getDefaultEdgeCheckpoint;
85
74
 
86
- export { type AgentShieldConfig, type DetectionResult, type EdgeCheckpointConfig, EdgeRuntimeAgentShield, EdgeRuntimeCheckpoint, type WasmModule, createEdgeAgentShield, createEdgeCheckpoint, getDefaultAgentShield, getDefaultEdgeCheckpoint };
75
+ export { type AgentShieldConfig, type EdgeRuntimeDetectionDetail as DetectionResult, type EdgeCheckpointConfig, EdgeRuntimeAgentShield, EdgeRuntimeCheckpoint, type EdgeRuntimeDetectionDetail, type WasmModule, createEdgeAgentShield, createEdgeCheckpoint, getDefaultAgentShield, getDefaultEdgeCheckpoint };
@@ -33,6 +33,22 @@ function tokenRegex(token) {
33
33
  TOKEN_REGEX_CACHE.set(token, regex);
34
34
  return regex;
35
35
  }
36
+ function readStringField(value) {
37
+ return typeof value === "string" && value.length > 0 ? value : void 0;
38
+ }
39
+ function readNumberField(value) {
40
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
41
+ }
42
+ function readBooleanField(value) {
43
+ return typeof value === "boolean" ? value : void 0;
44
+ }
45
+ function readStringArrayField(value) {
46
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
47
+ }
48
+ function normalizeEngineConfidence(value) {
49
+ if (value === void 0) return 0;
50
+ return Math.round(Math.max(0, Math.min(100, value)));
51
+ }
36
52
  function matchKnownAgent(lowercasedUa) {
37
53
  let best = null;
38
54
  for (const entry of checkpointShared.KNOWN_AGENT_PATTERNS) {
@@ -45,13 +61,6 @@ function matchKnownAgent(lowercasedUa) {
45
61
  }
46
62
  }
47
63
  }
48
- for (const { pattern, name, confidence } of checkpointShared.INTERACTIVE_AGENT_PATTERNS) {
49
- if (pattern.test(lowercasedUa)) {
50
- if (!best || confidence > best.confidence) {
51
- best = { name, confidence };
52
- }
53
- }
54
- }
55
64
  return best;
56
65
  }
57
66
  var EdgeRuntimeCheckpoint = class {
@@ -145,10 +154,21 @@ var EdgeRuntimeCheckpoint = class {
145
154
  exports$1.__wbindgen_free(resultPtr, offset);
146
155
  }
147
156
  const result = JSON.parse(resultStr);
157
+ const agent = readStringField(result.agent) ?? readStringField(result.agentName);
158
+ const confidence = normalizeEngineConfidence(readNumberField(result.confidence));
148
159
  const detection = {
149
- ...result,
150
- verificationMethod: "cryptographic",
151
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
160
+ isAgent: readBooleanField(result.isAgent) ?? readBooleanField(result.is_agent) ?? false,
161
+ isAiCrawler: readBooleanField(result.isAiCrawler) ?? readBooleanField(result.is_ai_crawler),
162
+ confidence,
163
+ detectionClass: agent ? { type: "AiAgent", agentType: agent } : { type: confidence > 0 ? "IncompleteData" : "Human" },
164
+ detectedAgent: agent ? { type: "ai_agent", name: agent } : void 0,
165
+ agent,
166
+ agentType: agent,
167
+ reasons: readStringArrayField(result.reasons),
168
+ signals: [],
169
+ verificationMethod: "signature",
170
+ riskLevel: readStringField(result.riskLevel) ?? readStringField(result.risk_level),
171
+ timestamp: Date.now()
152
172
  };
153
173
  if (this.config.onAgentDetected && detection.isAgent) {
154
174
  this.config.onAgentDetected(detection);
@@ -174,13 +194,19 @@ var EdgeRuntimeCheckpoint = class {
174
194
  const match = matchKnownAgent(lowercasedUa);
175
195
  if (match) {
176
196
  const finalConfidence = Math.min(match.confidence + headerBoost, 1);
197
+ const confidence = Math.round(finalConfidence * 100);
177
198
  const result = {
178
199
  isAgent: true,
179
- confidence: finalConfidence,
200
+ confidence,
201
+ detectionClass: { type: "AiAgent", agentType: match.name },
202
+ detectedAgent: { type: "ai_agent", name: match.name },
180
203
  agent: match.name,
204
+ agentType: match.name,
205
+ reasons: [`known_pattern:${match.name.toLowerCase()}`],
206
+ signals: [],
181
207
  verificationMethod: "pattern",
182
208
  riskLevel: finalConfidence > 0.9 ? "high" : "medium",
183
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
209
+ timestamp: Date.now()
184
210
  };
185
211
  if (this.config.onAgentDetected) {
186
212
  this.config.onAgentDetected(result);
@@ -189,9 +215,12 @@ var EdgeRuntimeCheckpoint = class {
189
215
  }
190
216
  return {
191
217
  isAgent: false,
192
- confidence: 0.85,
218
+ confidence: 0,
219
+ detectionClass: { type: "Human" },
220
+ reasons: ["No known agent indicators matched"],
221
+ signals: [],
193
222
  verificationMethod: "pattern",
194
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
223
+ timestamp: Date.now()
195
224
  };
196
225
  }
197
226
  isInitialized() {
@@ -1,4 +1,4 @@
1
- import { KNOWN_AGENT_PATTERNS, INTERACTIVE_AGENT_PATTERNS } from '@kya-os/checkpoint-shared';
1
+ import { KNOWN_AGENT_PATTERNS } from '@kya-os/checkpoint-shared';
2
2
 
3
3
  // src/edge-runtime-loader.ts
4
4
 
@@ -31,6 +31,22 @@ function tokenRegex(token) {
31
31
  TOKEN_REGEX_CACHE.set(token, regex);
32
32
  return regex;
33
33
  }
34
+ function readStringField(value) {
35
+ return typeof value === "string" && value.length > 0 ? value : void 0;
36
+ }
37
+ function readNumberField(value) {
38
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
39
+ }
40
+ function readBooleanField(value) {
41
+ return typeof value === "boolean" ? value : void 0;
42
+ }
43
+ function readStringArrayField(value) {
44
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
45
+ }
46
+ function normalizeEngineConfidence(value) {
47
+ if (value === void 0) return 0;
48
+ return Math.round(Math.max(0, Math.min(100, value)));
49
+ }
34
50
  function matchKnownAgent(lowercasedUa) {
35
51
  let best = null;
36
52
  for (const entry of KNOWN_AGENT_PATTERNS) {
@@ -43,13 +59,6 @@ function matchKnownAgent(lowercasedUa) {
43
59
  }
44
60
  }
45
61
  }
46
- for (const { pattern, name, confidence } of INTERACTIVE_AGENT_PATTERNS) {
47
- if (pattern.test(lowercasedUa)) {
48
- if (!best || confidence > best.confidence) {
49
- best = { name, confidence };
50
- }
51
- }
52
- }
53
62
  return best;
54
63
  }
55
64
  var EdgeRuntimeCheckpoint = class {
@@ -143,10 +152,21 @@ var EdgeRuntimeCheckpoint = class {
143
152
  exports$1.__wbindgen_free(resultPtr, offset);
144
153
  }
145
154
  const result = JSON.parse(resultStr);
155
+ const agent = readStringField(result.agent) ?? readStringField(result.agentName);
156
+ const confidence = normalizeEngineConfidence(readNumberField(result.confidence));
146
157
  const detection = {
147
- ...result,
148
- verificationMethod: "cryptographic",
149
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
158
+ isAgent: readBooleanField(result.isAgent) ?? readBooleanField(result.is_agent) ?? false,
159
+ isAiCrawler: readBooleanField(result.isAiCrawler) ?? readBooleanField(result.is_ai_crawler),
160
+ confidence,
161
+ detectionClass: agent ? { type: "AiAgent", agentType: agent } : { type: confidence > 0 ? "IncompleteData" : "Human" },
162
+ detectedAgent: agent ? { type: "ai_agent", name: agent } : void 0,
163
+ agent,
164
+ agentType: agent,
165
+ reasons: readStringArrayField(result.reasons),
166
+ signals: [],
167
+ verificationMethod: "signature",
168
+ riskLevel: readStringField(result.riskLevel) ?? readStringField(result.risk_level),
169
+ timestamp: Date.now()
150
170
  };
151
171
  if (this.config.onAgentDetected && detection.isAgent) {
152
172
  this.config.onAgentDetected(detection);
@@ -172,13 +192,19 @@ var EdgeRuntimeCheckpoint = class {
172
192
  const match = matchKnownAgent(lowercasedUa);
173
193
  if (match) {
174
194
  const finalConfidence = Math.min(match.confidence + headerBoost, 1);
195
+ const confidence = Math.round(finalConfidence * 100);
175
196
  const result = {
176
197
  isAgent: true,
177
- confidence: finalConfidence,
198
+ confidence,
199
+ detectionClass: { type: "AiAgent", agentType: match.name },
200
+ detectedAgent: { type: "ai_agent", name: match.name },
178
201
  agent: match.name,
202
+ agentType: match.name,
203
+ reasons: [`known_pattern:${match.name.toLowerCase()}`],
204
+ signals: [],
179
205
  verificationMethod: "pattern",
180
206
  riskLevel: finalConfidence > 0.9 ? "high" : "medium",
181
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
207
+ timestamp: Date.now()
182
208
  };
183
209
  if (this.config.onAgentDetected) {
184
210
  this.config.onAgentDetected(result);
@@ -187,9 +213,12 @@ var EdgeRuntimeCheckpoint = class {
187
213
  }
188
214
  return {
189
215
  isAgent: false,
190
- confidence: 0.85,
216
+ confidence: 0,
217
+ detectionClass: { type: "Human" },
218
+ reasons: ["No known agent indicators matched"],
219
+ signals: [],
191
220
  verificationMethod: "pattern",
192
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
221
+ timestamp: Date.now()
193
222
  };
194
223
  }
195
224
  isInitialized() {
@@ -1,15 +1,25 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
 
3
3
  /**
4
- * Edge Runtime Compatible WASM Middleware for AgentShield
4
+ * @deprecated Phase-D.9a — legacy Edge Runtime WASM middleware wrapping
5
+ * the retired `agentshield-wasm` Rust crate. This file shipped hand-
6
+ * written wasm-bindgen glue code that loaded the legacy detector's
7
+ * WASM binary; PR #2599's SSOT consolidation + PDM-1 #2560's engine
8
+ * move + AgentDetector-Deletion-1 PR #2610's class-deprecation made
9
+ * it structural dead weight.
5
10
  *
6
- * This module provides WASM-based AI agent detection with 95-100% confidence
7
- * in Next.js Edge Runtime and Vercel Edge Functions.
11
+ * Phase-D.9a converts the exports to throw-stubs (same precedent as
12
+ * PR #2610's `createWasmAgentShieldMiddleware` deprecation). Phase-D.9b
13
+ * (follow-up) deletes the underlying `agentshield-wasm` Rust crate
14
+ * after migrating the production Cloudflare gateway worker.
8
15
  *
9
- * IMPORTANT: WebAssembly.instantiate(module) IS supported in Edge Runtime
10
- * when using a pre-compiled module imported with ?module suffix.
16
+ * Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge`
17
+ * engine-backed, runs the full kya-os-engine orchestrator including
18
+ * MCP-I envelope verification. See `packages/checkpoint-nextjs/README.md`
19
+ * for the canonical recipe.
11
20
  */
12
21
 
22
+ /** @deprecated See file header. Type-only surface preservation. */
13
23
  interface EdgeWasmDetectionResult {
14
24
  isAgent: boolean;
15
25
  isAiCrawler?: boolean;
@@ -20,17 +30,10 @@ interface EdgeWasmDetectionResult {
20
30
  timestamp: string;
21
31
  reasons?: string[];
22
32
  }
33
+ /** @deprecated See file header. Type-only surface preservation. */
23
34
  interface EdgeAgentShieldConfig {
24
35
  onAgentDetected?: (result: EdgeWasmDetectionResult) => void | Promise<void>;
25
36
  blockOnHighConfidence?: boolean;
26
- /**
27
- * Confidence threshold for blocking (0.0-1.0 scale).
28
- * Detection confidence above this threshold will be blocked if blockOnHighConfidence is true.
29
- * @default 0.9 (90% confidence)
30
- * @example
31
- * confidenceThreshold: 0.9 // Block if >= 90% confident
32
- * confidenceThreshold: 0.7 // Block if >= 70% confident
33
- */
34
37
  confidenceThreshold?: number;
35
38
  skipPaths?: string[];
36
39
  blockedResponse?: {
@@ -39,30 +42,21 @@ interface EdgeAgentShieldConfig {
39
42
  headers?: Record<string, string>;
40
43
  };
41
44
  }
45
+ /** @internal — test-only reset for the one-shot warn latch. */
46
+ declare function __resetEdgeWasmWarningForTests(): void;
42
47
  /**
43
- * Initialize WASM module with proper imports for Edge Runtime
48
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
49
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
50
+ * surface exists only so static analysis sees the historical export.
44
51
  */
45
- declare function initializeEdgeWasm(wasmModule: WebAssembly.Module): Promise<void>;
52
+ declare function initializeEdgeWasm(_wasmModule: WebAssembly.Module): Promise<void>;
46
53
  /**
47
- * Create Edge Runtime compatible WASM middleware
48
- *
49
- * @example
50
- * ```typescript
51
- * // middleware.ts
52
- * import wasmModule from '@kya-os/checkpoint/wasm?module';
53
- * import { createEdgeWasmMiddleware } from '@kya-os/checkpoint-nextjs/edge-wasm-middleware';
54
- *
55
- * export const middleware = createEdgeWasmMiddleware({
56
- * wasmModule,
57
- * onAgentDetected: (result) => {
58
- * // Note: result.confidence is 0.0-1.0 scale
59
- * console.log(`AI Agent: ${result.agent} (${Math.round(result.confidence * 100)}% confidence)`);
60
- * }
61
- * });
62
- * ```
54
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
55
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
56
+ * surface exists only so static analysis sees the historical export.
63
57
  */
64
- declare function createEdgeWasmMiddleware(config: EdgeAgentShieldConfig & {
58
+ declare function createEdgeWasmMiddleware(_config: EdgeAgentShieldConfig & {
65
59
  wasmModule: WebAssembly.Module;
66
- }): (request: NextRequest) => Promise<NextResponse<unknown>>;
60
+ }): (request: NextRequest) => Promise<NextResponse>;
67
61
 
68
- export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, createEdgeWasmMiddleware, initializeEdgeWasm };
62
+ export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, __resetEdgeWasmWarningForTests, createEdgeWasmMiddleware, initializeEdgeWasm };
@@ -1,15 +1,25 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
 
3
3
  /**
4
- * Edge Runtime Compatible WASM Middleware for AgentShield
4
+ * @deprecated Phase-D.9a — legacy Edge Runtime WASM middleware wrapping
5
+ * the retired `agentshield-wasm` Rust crate. This file shipped hand-
6
+ * written wasm-bindgen glue code that loaded the legacy detector's
7
+ * WASM binary; PR #2599's SSOT consolidation + PDM-1 #2560's engine
8
+ * move + AgentDetector-Deletion-1 PR #2610's class-deprecation made
9
+ * it structural dead weight.
5
10
  *
6
- * This module provides WASM-based AI agent detection with 95-100% confidence
7
- * in Next.js Edge Runtime and Vercel Edge Functions.
11
+ * Phase-D.9a converts the exports to throw-stubs (same precedent as
12
+ * PR #2610's `createWasmAgentShieldMiddleware` deprecation). Phase-D.9b
13
+ * (follow-up) deletes the underlying `agentshield-wasm` Rust crate
14
+ * after migrating the production Cloudflare gateway worker.
8
15
  *
9
- * IMPORTANT: WebAssembly.instantiate(module) IS supported in Edge Runtime
10
- * when using a pre-compiled module imported with ?module suffix.
16
+ * Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge`
17
+ * engine-backed, runs the full kya-os-engine orchestrator including
18
+ * MCP-I envelope verification. See `packages/checkpoint-nextjs/README.md`
19
+ * for the canonical recipe.
11
20
  */
12
21
 
22
+ /** @deprecated See file header. Type-only surface preservation. */
13
23
  interface EdgeWasmDetectionResult {
14
24
  isAgent: boolean;
15
25
  isAiCrawler?: boolean;
@@ -20,17 +30,10 @@ interface EdgeWasmDetectionResult {
20
30
  timestamp: string;
21
31
  reasons?: string[];
22
32
  }
33
+ /** @deprecated See file header. Type-only surface preservation. */
23
34
  interface EdgeAgentShieldConfig {
24
35
  onAgentDetected?: (result: EdgeWasmDetectionResult) => void | Promise<void>;
25
36
  blockOnHighConfidence?: boolean;
26
- /**
27
- * Confidence threshold for blocking (0.0-1.0 scale).
28
- * Detection confidence above this threshold will be blocked if blockOnHighConfidence is true.
29
- * @default 0.9 (90% confidence)
30
- * @example
31
- * confidenceThreshold: 0.9 // Block if >= 90% confident
32
- * confidenceThreshold: 0.7 // Block if >= 70% confident
33
- */
34
37
  confidenceThreshold?: number;
35
38
  skipPaths?: string[];
36
39
  blockedResponse?: {
@@ -39,30 +42,21 @@ interface EdgeAgentShieldConfig {
39
42
  headers?: Record<string, string>;
40
43
  };
41
44
  }
45
+ /** @internal — test-only reset for the one-shot warn latch. */
46
+ declare function __resetEdgeWasmWarningForTests(): void;
42
47
  /**
43
- * Initialize WASM module with proper imports for Edge Runtime
48
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
49
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
50
+ * surface exists only so static analysis sees the historical export.
44
51
  */
45
- declare function initializeEdgeWasm(wasmModule: WebAssembly.Module): Promise<void>;
52
+ declare function initializeEdgeWasm(_wasmModule: WebAssembly.Module): Promise<void>;
46
53
  /**
47
- * Create Edge Runtime compatible WASM middleware
48
- *
49
- * @example
50
- * ```typescript
51
- * // middleware.ts
52
- * import wasmModule from '@kya-os/checkpoint/wasm?module';
53
- * import { createEdgeWasmMiddleware } from '@kya-os/checkpoint-nextjs/edge-wasm-middleware';
54
- *
55
- * export const middleware = createEdgeWasmMiddleware({
56
- * wasmModule,
57
- * onAgentDetected: (result) => {
58
- * // Note: result.confidence is 0.0-1.0 scale
59
- * console.log(`AI Agent: ${result.agent} (${Math.round(result.confidence * 100)}% confidence)`);
60
- * }
61
- * });
62
- * ```
54
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
55
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
56
+ * surface exists only so static analysis sees the historical export.
63
57
  */
64
- declare function createEdgeWasmMiddleware(config: EdgeAgentShieldConfig & {
58
+ declare function createEdgeWasmMiddleware(_config: EdgeAgentShieldConfig & {
65
59
  wasmModule: WebAssembly.Module;
66
- }): (request: NextRequest) => Promise<NextResponse<unknown>>;
60
+ }): (request: NextRequest) => Promise<NextResponse>;
67
61
 
68
- export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, createEdgeWasmMiddleware, initializeEdgeWasm };
62
+ export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, __resetEdgeWasmWarningForTests, createEdgeWasmMiddleware, initializeEdgeWasm };