@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +174 -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 +5 -2
  22. package/dist/index.mjs +6 -3
  23. package/dist/middleware-edge.js +2 -1
  24. package/dist/middleware-edge.mjs +2 -1
  25. package/dist/middleware-node.d.mts +16 -1
  26. package/dist/middleware-node.d.ts +16 -1
  27. package/dist/middleware-node.js +2 -1
  28. package/dist/middleware-node.mjs +2 -1
  29. package/dist/nodejs-wasm-loader.d.mts +26 -9
  30. package/dist/nodejs-wasm-loader.d.ts +26 -9
  31. package/dist/nodejs-wasm-loader.js +21 -78
  32. package/dist/nodejs-wasm-loader.mjs +21 -74
  33. package/dist/session-tracker.d.mts +2 -2
  34. package/dist/session-tracker.d.ts +2 -2
  35. package/dist/session-tracker.js +3 -1
  36. package/dist/session-tracker.mjs +4 -2
  37. package/dist/wasm-middleware.d.mts +19 -3
  38. package/dist/wasm-middleware.d.ts +19 -3
  39. package/dist/wasm-middleware.js +32 -3
  40. package/dist/wasm-middleware.mjs +32 -4
  41. package/dist/wasm-setup.js +29 -81
  42. package/dist/wasm-setup.mjs +29 -76
  43. package/package.json +8 -6
  44. package/templates/middleware-wasm-100.ts +11 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,179 @@
1
1
  # @kya-os/checkpoint-nextjs
2
2
 
3
+ ## 1.2.0 — 2026-05-18
4
+
5
+ **Minor release** — peer to `@kya-os/checkpoint-wasm-runtime@1.4.0`.
6
+ Bundler-port docs + E2E gate + Monitor-default visibility.
7
+
8
+ ### Changed
9
+
10
+ - QUICKSTART rewritten with **Bundler compatibility** + **Webpack
11
+ fallback** sections. The `--target bundler` artifact works under
12
+ Next.js 15+ Turbopack, Next.js 14 `next dev --turbo`, Vite, and
13
+ esbuild bundling mode out of the box. Webpack 5 + `asyncWebAssembly`
14
+ is documented as **incompatible** with `--target bundler`
15
+ (wasm-bindgen's sync `.wasm` import receives a Promise instead of
16
+ the resolved module — exports table breaks). Recommended Webpack
17
+ path is the `./engine/node` (or `./orchestrator/node`) safety net.
18
+
19
+ ### Added
20
+
21
+ - `tests-e2e/nextjs-consumer/` fixture + matching CI workflow
22
+ (`.github/workflows/e2e-nextjs-bundler.yml`) exercising the
23
+ `./engine/node` safety net under both Turbopack (`next dev --turbo`)
24
+ and Webpack (`next build` + `next start`).
25
+ - Tier-3 Monitor-default visibility: a default-config `withCheckpoint`
26
+ install no longer blocks ChatGPT-User et al. unless the consumer
27
+ writes a tenant-policy rule or opts into
28
+ `tier3_action: 'block'`. See
29
+ [wasm-runtime@1.4.0 CHANGELOG](../checkpoint-wasm-runtime/CHANGELOG.md)
30
+ for the migration story.
31
+
32
+ ---
33
+
34
+ ## 1.1.4 — 2026-05-18
35
+
36
+ Companion patch for `@kya-os/checkpoint-wasm-runtime@1.2.0`.
37
+
38
+ ### Changed
39
+
40
+ - Middleware enforcement now reads the canonical engine
41
+ `VerifyResult.decision`; descriptive/session metadata reads
42
+ `VerifyResult.detectionDetail`.
43
+ - Edge runtime detection types now reuse the shared `DetectionDetail`
44
+ surface instead of maintaining a parallel `DetectionResult` definition.
45
+ - Edge runtime fallback detection now emits canonical 0-100
46
+ `DetectionDetail.confidence` values. A no-match fallback emits
47
+ confidence `0` instead of the older legacy `0.85` placeholder.
48
+
49
+ ## 1.1.3 — 2026-05-18
50
+
51
+ Phase-D.9a (Phase 1 of 2) — convert legacy `agentshield-wasm`-bound
52
+ public APIs to throw-stubs. The underlying `agentshield-wasm` Rust
53
+ crate + its shipped artifacts stay live for one more cycle (Phase-D.9b
54
+ deletes them after migrating the production Cloudflare gateway worker).
55
+
56
+ ### Deprecations as throw-stubs (no engine work; runtime callers must migrate)
57
+
58
+ - **`edge-wasm-middleware.ts`** — `createEdgeWasmMiddleware`,
59
+ `initializeEdgeWasm` now `@deprecated` + throw with migration error
60
+ pointing at `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge`.
61
+ 470 LOC of hand-written wasm-bindgen heap manager removed (the
62
+ engine path has its own wasm-bindgen output centrally maintained in
63
+ `@kya-os/checkpoint-wasm-runtime`).
64
+
65
+ - **`nodejs-wasm-loader.ts`** — `loadWasmNodejs`, `isNodejsRuntime`,
66
+ `getWasmModule`, `isWasmInitialized` now `@deprecated` + throw with
67
+ the same migration error. 117 LOC of `fs.readFileSync`-based
68
+ multi-path WASM-locator logic removed (`@kya-os/checkpoint-wasm-runtime`'s
69
+ loaders auto-resolve via the `"node"` / `"edge-runtime"` export
70
+ conditions; no manual `fs` needed).
71
+
72
+ Net: **−415 LOC** of legacy wasm-bindgen glue / fs-locator code.
73
+
74
+ ### Throw-stub pattern (matches PR #2610's `createWasmAgentShieldMiddleware`)
75
+
76
+ - One-shot dev-only `console.warn` on first invocation; suppressed in
77
+ production and after the first emission.
78
+ - Test-only reset helpers exported (`__resetEdgeWasmWarningForTests`,
79
+ `__resetNodejsWasmWarningForTests`).
80
+ - Migration target named directly in the error message.
81
+
82
+ ### Why throw vs. deprecate-and-keep-working
83
+
84
+ Unlike PR #2610's `createWasmAgentShieldMiddleware` (which still does
85
+ useful work backed by the legacy `AgentDetector` class), these two
86
+ files depend on the `agentshield-wasm` Rust crate's shipped artifacts.
87
+ The artifacts will be deleted in Phase-D.9b. Keeping these functions
88
+ working until D.9b would mean they'd start silently failing the moment
89
+ the artifact deletion lands. Throwing immediately on call surfaces
90
+ the migration error today, before D.9b's deletion makes it worse.
91
+
92
+ ### Regression tests (20 new across 3 files)
93
+
94
+ - `edge-wasm-middleware.test.ts` (7 tests): throws with migration
95
+ error, one-shot warn, no-op in prod, latch shared across both exports
96
+ - `nodejs-wasm-loader.test.ts` (6 tests): same shape across the 4
97
+ throw-stub exports + shared-latch verification
98
+ - `d9-deletion-gate-scaffold.test.ts` (7 tests): pins what Phase-D.9a
99
+ achieved structurally — both files exist as compile-time surface;
100
+ both removed inline wasm-bindgen helpers; both reference
101
+ `withCheckpoint`; no live imports of `setWasmModule` from the legacy
102
+ `@kya-os/checkpoint` package
103
+
104
+ Revert-and-fail verified: removing the `warn*()` call from either
105
+ throw-stub function fails 2 of the warn assertions; restoring re-greens.
106
+
107
+ ### Out of scope for D.9a (deferred to Phase-D.9b)
108
+
109
+ - `rust/crates/agentshield-wasm/` Rust crate deletion (gateway worker
110
+ is the last consumer)
111
+ - All 7 shipped `agentshield_wasm_bg.wasm` artifact copies
112
+ - `apps/web/lib/wasm/agentshield-loader.ts` migration (audit found 6
113
+ production-route consumers using a multi-function WASM API that
114
+ doesn't map structurally to the engine's single `verify(input, ctx)`
115
+ entry — needs the same engine-API translation as the gateway worker)
116
+ - Cloudflare gateway worker migration (production-risk; needs Wrangler
117
+ preview deploy + cold-start measurement; compressed size verified at
118
+ 0.44 MB, well under Workers' 1 MB free-tier limit)
119
+ - `apps/web/public/sw.js` service-worker cache manifest cleanup
120
+ - Top-level ad-hoc `test-wasm.mjs`-style dev scripts at repo root
121
+ - Final deletion-gate test (lands with D.9b)
122
+
123
+ ### Bench safety
124
+
125
+ TS-only, zero `kya-os-engine` or `agentshield-wasm` Rust changes.
126
+ Ships in parallel with Engineer 1's Express bench pivot + bundler audit.
127
+
128
+ ### Version
129
+
130
+ `@kya-os/checkpoint-nextjs` 1.1.2 → **1.1.3** (patch — deprecation,
131
+ breaking only for callers that ignored the prior deprecation cycle).
132
+
133
+ ## 1.1.2 — 2026-05-17
134
+
135
+ AgentDetector-Deletion-1 (Phase 1 of 2) — deprecate the two README-
136
+ documented public APIs that wrap the legacy TS `AgentDetector` class.
137
+ The class itself stays live for one more minor release; this patch is
138
+ the deprecation signal.
139
+
140
+ ### Deprecations (no behavior change)
141
+
142
+ - **`useAgentDetection`** (`packages/checkpoint-nextjs/src/hooks.ts`)
143
+ - `@deprecated` JSDoc + one-shot dev-only `console.warn`
144
+ - Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` for
145
+ server-side detection, or consume `KNOWN_AGENT_PATTERNS` directly
146
+ from `@kya-os/checkpoint-shared` for client-side pattern matching.
147
+ - `useDetectionMonitor` is NOT deprecated — it doesn't depend on
148
+ `AgentDetector`.
149
+
150
+ - **`createWasmAgentShieldMiddleware`** (`packages/checkpoint-nextjs/src/wasm-middleware.ts`)
151
+ - `@deprecated` JSDoc + one-shot dev-only `console.warn`
152
+ - Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` —
153
+ engine-backed, runs envelope verification.
154
+
155
+ ### Why
156
+
157
+ Pattern-Detection-Migration-1 (#2560) moved Stage 1 detection into the
158
+ Rust `kya-os-engine` crate. The legacy TS `AgentDetector` class that
159
+ both APIs wrap duplicates that path. PDM-2 (#2608) consolidated the
160
+ shared pattern table; this patch begins phasing out the legacy class
161
+ itself.
162
+
163
+ ### Removal timeline
164
+
165
+ - **Now (1.1.2):** deprecation signals — APIs keep working, dev-only
166
+ `console.warn` fires once per process pointing at the migration
167
+ target. README banners added.
168
+ - **Next minor:** AgentDetector-Deletion-2 — delete the legacy class,
169
+ delete these two APIs, deletion-gate test pins absence. Will be a
170
+ breaking change for any caller that ignored the deprecation.
171
+
172
+ ### Bench safety
173
+
174
+ TS-only, zero `kya-os-engine` changes. Ships in parallel with
175
+ in-flight Rust bench captures without invalidating them.
176
+
3
177
  ## 1.1.1 — 2026-05-17
4
178
 
5
179
  Companion patch to `@kya-os/checkpoint-wasm-runtime@1.1.0`'s
@@ -113,6 +113,7 @@ Create `lib/agentshield-edge.ts`:
113
113
  ```typescript
114
114
  // lib/agentshield-edge.ts
115
115
  import type { NextRequest } from 'next/server';
116
+ import type { EdgeRuntimeDetectionDetail } from '@kya-os/checkpoint-nextjs/edge-runtime-loader';
116
117
  import wasmModule from '../wasm/agentshield_wasm_bg.wasm?module';
117
118
 
118
119
  let wasmInstance: WebAssembly.Instance | null = null;
@@ -167,16 +168,9 @@ function writeString(str: string): [number, number] {
167
168
  return [ptr, encoded.length];
168
169
  }
169
170
 
170
- export interface DetectionResult {
171
- isAgent: boolean;
172
- confidence: number;
173
- agent?: string;
174
- verificationMethod: 'cryptographic' | 'pattern';
175
- }
176
-
177
171
  export function createAgentShieldMiddleware(options: {
178
172
  enableWasm?: boolean;
179
- onAgentDetected?: (result: DetectionResult) => void;
173
+ onAgentDetected?: (result: EdgeRuntimeDetectionDetail) => void;
180
174
  }) {
181
175
  let initialized = false;
182
176
 
@@ -198,7 +192,7 @@ export function createAgentShieldMiddleware(options: {
198
192
  }
199
193
  },
200
194
 
201
- async detect(request: NextRequest): Promise<DetectionResult> {
195
+ async detect(request: NextRequest): Promise<DetectionDetail> {
202
196
  const metadata = {
203
197
  userAgent: request.headers.get('user-agent') || '',
204
198
  ipAddress: request.ip || request.headers.get('x-forwarded-for') || '',
@@ -248,7 +242,7 @@ export function createAgentShieldMiddleware(options: {
248
242
 
249
243
  for (const { pattern, name } of aiAgentPatterns) {
250
244
  if (pattern.test(userAgent)) {
251
- const result: DetectionResult = {
245
+ const result: DetectionDetail = {
252
246
  isAgent: true,
253
247
  confidence: 0.85,
254
248
  agent: name,
package/README.md CHANGED
@@ -76,6 +76,15 @@ export const config = {
76
76
 
77
77
  ### React Hooks
78
78
 
79
+ > ⚠️ **`useAgentDetection` is deprecated** as of AgentDetector-Deletion-1
80
+ > and slated for removal in the next minor. It wraps the legacy TS
81
+ > `AgentDetector` class; Stage 1 detection now lives in the Rust
82
+ > `kya-os-engine` (PDM-1 #2560). Migrate to server-side detection via
83
+ > `withCheckpoint` from `@kya-os/checkpoint-nextjs`, or consume
84
+ > `KNOWN_AGENT_PATTERNS` directly from `@kya-os/checkpoint-shared` if
85
+ > you genuinely need client-side pattern matching. `useDetectionMonitor`
86
+ > stays — it doesn't depend on `AgentDetector`.
87
+
79
88
  ```javascript
80
89
  'use client';
81
90
 
@@ -202,6 +211,10 @@ export default agentShield({
202
211
 
203
212
  ### useAgentDetection
204
213
 
214
+ > ⚠️ **Deprecated** — see banner above. Will be removed in the next
215
+ > minor. Migrate to `withCheckpoint` (server-side) or direct
216
+ > `KNOWN_AGENT_PATTERNS` consumption (client-side pattern matching).
217
+
205
218
  Client-side agent detection:
206
219
 
207
220
  ```javascript
@@ -116,14 +116,8 @@ export interface AgentShieldWasm {
116
116
  memory: WebAssembly.Memory;
117
117
  }
118
118
 
119
- export interface DetectionResult {
120
- isAgent: boolean;
121
- confidence: number;
122
- agent?: string;
123
- verificationMethod: 'cryptographic' | 'pattern';
124
- riskLevel?: 'low' | 'medium' | 'high' | 'critical';
125
- timestamp: string;
126
- }
119
+ export type EdgeWasmDetectionDetail =
120
+ import('@kya-os/checkpoint-nextjs/edge-runtime-loader').EdgeRuntimeDetectionDetail;
127
121
  `;
128
122
 
129
123
  const dtsPath = path.join(wasmDir, 'agentshield.d.ts');
@@ -144,8 +138,11 @@ export interface DetectionResult {
144
138
  */
145
139
 
146
140
  import type { NextRequest } from 'next/server';
141
+ import type { EdgeRuntimeDetectionDetail } from '@kya-os/checkpoint-nextjs/edge-runtime-loader';
147
142
  import wasmModule from '../wasm/agentshield_wasm_bg.wasm?module';
148
143
 
144
+ type EdgeWasmDetectionDetail = EdgeRuntimeDetectionDetail;
145
+
149
146
  let wasmInstance: WebAssembly.Instance | null = null;
150
147
  let wasmMemory: WebAssembly.Memory | null = null;
151
148
 
@@ -200,18 +197,9 @@ function writeString(str: string): [number, number] {
200
197
  return [ptr, encoded.length];
201
198
  }
202
199
 
203
- export interface DetectionResult {
204
- isAgent: boolean;
205
- confidence: number;
206
- agent?: string;
207
- verificationMethod: 'cryptographic' | 'pattern';
208
- riskLevel?: 'low' | 'medium' | 'high' | 'critical';
209
- timestamp?: string;
210
- }
211
-
212
200
  export interface AgentShieldOptions {
213
201
  enableWasm?: boolean;
214
- onAgentDetected?: (result: DetectionResult) => void;
202
+ onAgentDetected?: (result: EdgeWasmDetectionDetail) => void;
215
203
  blockAgents?: boolean;
216
204
  allowedAgents?: string[];
217
205
  }
@@ -240,7 +228,7 @@ export function createAgentShieldMiddleware(options: AgentShieldOptions = {}) {
240
228
  }
241
229
  },
242
230
 
243
- async detect(request: NextRequest): Promise<DetectionResult> {
231
+ async detect(request: NextRequest): Promise<EdgeWasmDetectionDetail> {
244
232
  const metadata = {
245
233
  userAgent: request.headers.get('user-agent') || '',
246
234
  ipAddress: request.ip || request.headers.get('x-forwarded-for')?.split(',')[0] || '',
@@ -261,11 +249,23 @@ export function createAgentShieldMiddleware(options: AgentShieldOptions = {}) {
261
249
  exports.__wbindgen_free(resultPtr, resultLen);
262
250
 
263
251
  const result = JSON.parse(resultStr);
264
-
265
- const detection: DetectionResult = {
252
+
253
+ // EdgeWasmDetectionDetail's contract is confidence on a 0-100
254
+ // scale. The canonical kya-os-engine emits 0-100 natively
255
+ // (see checkpoint-nextjs/src/edge-runtime-loader.ts's
256
+ // normalizeEngineConfidence). Clamp + round here as a defensive
257
+ // measure for malformed WASM output, but do NOT multiply —
258
+ // multiplying would produce 9500 instead of 95 for any user
259
+ // who's switched from the legacy agentshield_wasm binding to
260
+ // the current engine.
261
+ const detection: EdgeWasmDetectionDetail = {
266
262
  ...result,
267
- verificationMethod: 'cryptographic',
268
- timestamp: new Date().toISOString(),
263
+ confidence:
264
+ typeof result.confidence === 'number'
265
+ ? Math.round(Math.max(0, Math.min(100, result.confidence)))
266
+ : 0,
267
+ verificationMethod: 'signature',
268
+ timestamp: Date.now(),
269
269
  };
270
270
 
271
271
  if (options.onAgentDetected && detection.isAgent) {
@@ -299,7 +299,7 @@ export function createAgentShieldMiddleware(options: AgentShieldOptions = {}) {
299
299
  function patternDetection(
300
300
  metadata: { userAgent: string; ipAddress: string; headers: Record<string, string> },
301
301
  options: AgentShieldOptions
302
- ): DetectionResult {
302
+ ): EdgeWasmDetectionDetail {
303
303
  const userAgent = metadata.userAgent.toLowerCase();
304
304
 
305
305
  // Known AI agent patterns with confidence scores
@@ -336,13 +336,18 @@ function patternDetection(
336
336
  if (pattern.test(userAgent)) {
337
337
  const finalConfidence = Math.min(confidence + headerBoost, 1.0);
338
338
 
339
- const result: DetectionResult = {
339
+ const result: EdgeWasmDetectionDetail = {
340
340
  isAgent: true,
341
- confidence: finalConfidence,
341
+ confidence: Math.round(finalConfidence * 100),
342
342
  agent: name,
343
+ detectionClass: { type: 'AiAgent', agentType: name },
344
+ detectedAgent: { type: 'ai_agent', name },
345
+ agentType: name,
346
+ reasons: [\`known_pattern:\${name.toLowerCase()}\`],
347
+ signals: [],
343
348
  verificationMethod: 'pattern',
344
349
  riskLevel: finalConfidence > 0.9 ? 'high' : 'medium',
345
- timestamp: new Date().toISOString(),
350
+ timestamp: Date.now(),
346
351
  };
347
352
 
348
353
  if (options.onAgentDetected) {
@@ -356,9 +361,12 @@ function patternDetection(
356
361
  // Not detected as AI agent
357
362
  return {
358
363
  isAgent: false,
359
- confidence: 0.85,
364
+ confidence: 0,
365
+ detectionClass: { type: 'Human' },
366
+ reasons: ['No known agent indicators matched'],
367
+ signals: [],
360
368
  verificationMethod: 'pattern',
361
- timestamp: new Date().toISOString(),
369
+ timestamp: Date.now(),
362
370
  };
363
371
  }
364
372
 
@@ -380,7 +388,7 @@ import { createAgentShieldMiddleware } from './lib/agentshield-edge';
380
388
  const agentShield = createAgentShieldMiddleware({
381
389
  enableWasm: true,
382
390
  onAgentDetected: (result) => {
383
- console.log(\`🤖 AI Agent detected: \${result.agent} (confidence: \${(result.confidence * 100).toFixed(1)}%)\`);
391
+ console.log(\`🤖 AI Agent detected: \${result.agent} (confidence: \${result.confidence.toFixed(1)}%)\`);
384
392
  },
385
393
  });
386
394
 
@@ -401,8 +409,8 @@ export async function middleware(request: NextRequest) {
401
409
  response.headers.set('X-Agent-Confidence', detection.confidence.toString());
402
410
  return response;
403
411
 
404
- // Optional: Block AI agents
405
- // if (detection.confidence > 0.9) {
412
+ // Optional: Block AI agents (confidence is on 0-100 scale)
413
+ // if (detection.confidence > 90) {
406
414
  // return NextResponse.json(
407
415
  // { error: 'AI agent access denied' },
408
416
  // { status: 403 }
@@ -1,4 +1,4 @@
1
- import { EnforcementAction } from '@kya-os/checkpoint-shared';
1
+ import { EnforcementAction, DetectionDetail } from '@kya-os/checkpoint-shared';
2
2
  export { EnforcementAction } from '@kya-os/checkpoint-shared';
3
3
 
4
4
  /**
@@ -53,20 +53,20 @@ interface EnforcementDecision {
53
53
  };
54
54
  }
55
55
  /**
56
- * Detection result (optional in response)
56
+ * Detection detail (optional in response)
57
57
  */
58
- interface DetectionResult {
59
- isAgent: boolean;
60
- confidence: number;
58
+ type ApiDetectionDetail = Omit<DetectionDetail, 'detectionClass' | 'verificationMethod' | 'reasons' | 'signals' | 'timestamp'> & {
61
59
  agentName?: string;
62
- agentType?: string;
63
60
  /** Detection class: 'human', 'ai_agent', 'bot', 'incomplete_data' */
64
61
  detectionClass?: string;
65
62
  verificationMethod?: string;
66
63
  reasons?: string[];
64
+ signals?: DetectionDetail['signals'];
65
+ timestamp?: DetectionDetail['timestamp'];
67
66
  /** Detection engine used: 'wasm' or 'javascript-fallback' */
68
67
  detectionMethod?: string;
69
- }
68
+ };
69
+
70
70
  /**
71
71
  * Enforce API response
72
72
  */
@@ -76,7 +76,7 @@ interface EnforceResponse {
76
76
  decision: EnforcementDecision;
77
77
  processingTimeMs: number;
78
78
  requestId: string;
79
- detection?: DetectionResult;
79
+ detection?: ApiDetectionDetail;
80
80
  };
81
81
  error?: {
82
82
  code: string;
@@ -114,7 +114,7 @@ interface EnforceInput {
114
114
  */
115
115
  interface LogDetectionInput {
116
116
  /** Detection result from Gateway */
117
- detection: DetectionResult;
117
+ detection: ApiDetectionDetail;
118
118
  /** Request context */
119
119
  context: {
120
120
  userAgent?: string;
@@ -201,4 +201,4 @@ declare const getAgentShieldClient: typeof getCheckpointApiClient;
201
201
  /** @deprecated Renamed to {@link resetCheckpointApiClient}. */
202
202
  declare const resetAgentShieldClient: typeof resetCheckpointApiClient;
203
203
 
204
- export { AgentShieldClient, type AgentShieldClientConfig, CheckpointApiClient, type CheckpointApiClientConfig, type DetectionResult, type EnforceInput, type EnforceResponse, type EnforcementDecision, type LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient };
204
+ export { AgentShieldClient, type AgentShieldClientConfig, type ApiDetectionDetail, CheckpointApiClient, type CheckpointApiClientConfig, type ApiDetectionDetail as DetectionResult, type EnforceInput, type EnforceResponse, type EnforcementDecision, type LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient };
@@ -1,4 +1,4 @@
1
- import { EnforcementAction } from '@kya-os/checkpoint-shared';
1
+ import { EnforcementAction, DetectionDetail } from '@kya-os/checkpoint-shared';
2
2
  export { EnforcementAction } from '@kya-os/checkpoint-shared';
3
3
 
4
4
  /**
@@ -53,20 +53,20 @@ interface EnforcementDecision {
53
53
  };
54
54
  }
55
55
  /**
56
- * Detection result (optional in response)
56
+ * Detection detail (optional in response)
57
57
  */
58
- interface DetectionResult {
59
- isAgent: boolean;
60
- confidence: number;
58
+ type ApiDetectionDetail = Omit<DetectionDetail, 'detectionClass' | 'verificationMethod' | 'reasons' | 'signals' | 'timestamp'> & {
61
59
  agentName?: string;
62
- agentType?: string;
63
60
  /** Detection class: 'human', 'ai_agent', 'bot', 'incomplete_data' */
64
61
  detectionClass?: string;
65
62
  verificationMethod?: string;
66
63
  reasons?: string[];
64
+ signals?: DetectionDetail['signals'];
65
+ timestamp?: DetectionDetail['timestamp'];
67
66
  /** Detection engine used: 'wasm' or 'javascript-fallback' */
68
67
  detectionMethod?: string;
69
- }
68
+ };
69
+
70
70
  /**
71
71
  * Enforce API response
72
72
  */
@@ -76,7 +76,7 @@ interface EnforceResponse {
76
76
  decision: EnforcementDecision;
77
77
  processingTimeMs: number;
78
78
  requestId: string;
79
- detection?: DetectionResult;
79
+ detection?: ApiDetectionDetail;
80
80
  };
81
81
  error?: {
82
82
  code: string;
@@ -114,7 +114,7 @@ interface EnforceInput {
114
114
  */
115
115
  interface LogDetectionInput {
116
116
  /** Detection result from Gateway */
117
- detection: DetectionResult;
117
+ detection: ApiDetectionDetail;
118
118
  /** Request context */
119
119
  context: {
120
120
  userAgent?: string;
@@ -201,4 +201,4 @@ declare const getAgentShieldClient: typeof getCheckpointApiClient;
201
201
  /** @deprecated Renamed to {@link resetCheckpointApiClient}. */
202
202
  declare const resetAgentShieldClient: typeof resetCheckpointApiClient;
203
203
 
204
- export { AgentShieldClient, type AgentShieldClientConfig, CheckpointApiClient, type CheckpointApiClientConfig, type DetectionResult, type EnforceInput, type EnforceResponse, type EnforcementDecision, type LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient };
204
+ export { AgentShieldClient, type AgentShieldClientConfig, type ApiDetectionDetail, CheckpointApiClient, type CheckpointApiClientConfig, type ApiDetectionDetail as DetectionResult, type EnforceInput, type EnforceResponse, type EnforcementDecision, type LogDetectionInput, getAgentShieldClient, getCheckpointApiClient, resetAgentShieldClient, resetCheckpointApiClient };
@@ -4,8 +4,13 @@ import '@kya-os/checkpoint-shared';
4
4
  import '@kya-os/checkpoint';
5
5
 
6
6
  /**
7
- * Enhanced middleware creator for Edge Runtime
8
- * Uses EdgeAgentDetector which doesn't require WASM
7
+ * Enhanced middleware creator for Edge Runtime.
8
+ *
9
+ * NOTE (post-Phase D): this wrapper delegates to
10
+ * `createAgentShieldMiddleware` from `./middleware`, which is itself a
11
+ * throw-stub pointing at `withCheckpoint`. Effectively dead code; kept
12
+ * as a compile-time surface until next-minor cleanup. See `middleware.ts`
13
+ * for the migration error message + canonical replacement recipe.
9
14
  */
10
15
 
11
16
  /**
@@ -4,8 +4,13 @@ import '@kya-os/checkpoint-shared';
4
4
  import '@kya-os/checkpoint';
5
5
 
6
6
  /**
7
- * Enhanced middleware creator for Edge Runtime
8
- * Uses EdgeAgentDetector which doesn't require WASM
7
+ * Enhanced middleware creator for Edge Runtime.
8
+ *
9
+ * NOTE (post-Phase D): this wrapper delegates to
10
+ * `createAgentShieldMiddleware` from `./middleware`, which is itself a
11
+ * throw-stub pointing at `withCheckpoint`. Effectively dead code; kept
12
+ * as a compile-time surface until next-minor cleanup. See `middleware.ts`
13
+ * for the migration error message + canonical replacement recipe.
9
14
  */
10
15
 
11
16
  /**
@@ -1,6 +1,6 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { DetectionResult } from '@kya-os/checkpoint-shared';
3
- export { DetectionResult } from '@kya-os/checkpoint-shared';
2
+ import { DetectionDetail } from '@kya-os/checkpoint-shared';
3
+ export { DetectionDetail } from '@kya-os/checkpoint-shared';
4
4
 
5
5
  /**
6
6
  * Edge Runtime Middleware with WASM Support
@@ -54,7 +54,7 @@ interface EdgeMiddlewareConfig {
54
54
  * Custom handler called when an agent is detected
55
55
  * Return a NextResponse to override default behavior
56
56
  */
57
- onDetection?: (request: NextRequest, result: DetectionResult) => Promise<NextResponse | void> | NextResponse | void;
57
+ onDetection?: (request: NextRequest, result: DetectionDetail) => Promise<NextResponse | void> | NextResponse | void;
58
58
  /**
59
59
  * Paths to skip detection (can be string prefixes or RegExp)
60
60
  */
@@ -1,6 +1,6 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { DetectionResult } from '@kya-os/checkpoint-shared';
3
- export { DetectionResult } from '@kya-os/checkpoint-shared';
2
+ import { DetectionDetail } from '@kya-os/checkpoint-shared';
3
+ export { DetectionDetail } from '@kya-os/checkpoint-shared';
4
4
 
5
5
  /**
6
6
  * Edge Runtime Middleware with WASM Support
@@ -54,7 +54,7 @@ interface EdgeMiddlewareConfig {
54
54
  * Custom handler called when an agent is detected
55
55
  * Return a NextResponse to override default behavior
56
56
  */
57
- onDetection?: (request: NextRequest, result: DetectionResult) => Promise<NextResponse | void> | NextResponse | void;
57
+ onDetection?: (request: NextRequest, result: DetectionDetail) => Promise<NextResponse | void> | NextResponse | void;
58
58
  /**
59
59
  * Paths to skip detection (can be string prefixes or RegExp)
60
60
  */
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var server = require('next/server');
4
- var checkpointShared = require('@kya-os/checkpoint-shared');
5
4
 
6
5
  // src/edge/index.ts
7
6
 
@@ -21,6 +20,20 @@ function getClientIp(request) {
21
20
  return void 0;
22
21
  }
23
22
 
23
+ // src/local-detection-gate.ts
24
+ function isDetectedAgentForLocalGate(result) {
25
+ return result.isAgent === true;
26
+ }
27
+ function evaluateLocalDetectionGate(result, config) {
28
+ if (!isDetectedAgentForLocalGate(result)) {
29
+ return { action: "allow", shouldNotify: false };
30
+ }
31
+ if ((result.confidence ?? 0) >= config.confidenceThreshold) {
32
+ return { action: config.defaultAction, shouldNotify: true };
33
+ }
34
+ return { action: "allow", shouldNotify: false };
35
+ }
36
+
24
37
  // src/edge/index.ts
25
38
  async function patternDetect(input) {
26
39
  const userAgent = input.userAgent?.toLowerCase() || "";
@@ -111,7 +124,7 @@ async function createDetector(config) {
111
124
  reasons: result.reasons,
112
125
  timestamp: result.timestamp,
113
126
  signals: [],
114
- // Required by DetectionResult, empty for WASM results
127
+ // Required by DetectionDetail, empty for WASM results
115
128
  shouldBlock: result.shouldBlock,
116
129
  blockReason: result.blockReason
117
130
  };
@@ -209,7 +222,7 @@ function createEdgeMiddleware(config = {}) {
209
222
  );
210
223
  }
211
224
  if (result.shouldBlock !== false) {
212
- const decision = checkpointShared.evaluateEnforcement(result, {
225
+ const decision = evaluateLocalDetectionGate(result, {
213
226
  confidenceThreshold,
214
227
  defaultAction: onAgentDetected
215
228
  });
@@ -1,5 +1,4 @@
1
1
  import { NextResponse } from 'next/server';
2
- import { evaluateEnforcement } from '@kya-os/checkpoint-shared';
3
2
 
4
3
  // src/edge/index.ts
5
4
 
@@ -19,6 +18,20 @@ function getClientIp(request) {
19
18
  return void 0;
20
19
  }
21
20
 
21
+ // src/local-detection-gate.ts
22
+ function isDetectedAgentForLocalGate(result) {
23
+ return result.isAgent === true;
24
+ }
25
+ function evaluateLocalDetectionGate(result, config) {
26
+ if (!isDetectedAgentForLocalGate(result)) {
27
+ return { action: "allow", shouldNotify: false };
28
+ }
29
+ if ((result.confidence ?? 0) >= config.confidenceThreshold) {
30
+ return { action: config.defaultAction, shouldNotify: true };
31
+ }
32
+ return { action: "allow", shouldNotify: false };
33
+ }
34
+
22
35
  // src/edge/index.ts
23
36
  async function patternDetect(input) {
24
37
  const userAgent = input.userAgent?.toLowerCase() || "";
@@ -109,7 +122,7 @@ async function createDetector(config) {
109
122
  reasons: result.reasons,
110
123
  timestamp: result.timestamp,
111
124
  signals: [],
112
- // Required by DetectionResult, empty for WASM results
125
+ // Required by DetectionDetail, empty for WASM results
113
126
  shouldBlock: result.shouldBlock,
114
127
  blockReason: result.blockReason
115
128
  };
@@ -207,7 +220,7 @@ function createEdgeMiddleware(config = {}) {
207
220
  );
208
221
  }
209
222
  if (result.shouldBlock !== false) {
210
- const decision = evaluateEnforcement(result, {
223
+ const decision = evaluateLocalDetectionGate(result, {
211
224
  confidenceThreshold,
212
225
  defaultAction: onAgentDetected
213
226
  });