@kya-os/checkpoint-nextjs 1.1.0 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +178 -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 +43 -18
  14. package/dist/edge-runtime-loader.d.ts +43 -18
  15. package/dist/edge-runtime-loader.js +101 -58
  16. package/dist/edge-runtime-loader.mjs +98 -59
  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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,183 @@
1
1
  # @kya-os/checkpoint-nextjs
2
2
 
3
+ ## 1.1.4 — 2026-05-18
4
+
5
+ Companion patch for `@kya-os/checkpoint-wasm-runtime@1.2.0`.
6
+
7
+ ### Changed
8
+
9
+ - Middleware enforcement now reads the canonical engine
10
+ `VerifyResult.decision`; descriptive/session metadata reads
11
+ `VerifyResult.detectionDetail`.
12
+ - Edge runtime detection types now reuse the shared `DetectionDetail`
13
+ surface instead of maintaining a parallel `DetectionResult` definition.
14
+ - Edge runtime fallback detection now emits canonical 0-100
15
+ `DetectionDetail.confidence` values. A no-match fallback emits
16
+ confidence `0` instead of the older legacy `0.85` placeholder.
17
+
18
+ ## 1.1.3 — 2026-05-18
19
+
20
+ Phase-D.9a (Phase 1 of 2) — convert legacy `agentshield-wasm`-bound
21
+ public APIs to throw-stubs. The underlying `agentshield-wasm` Rust
22
+ crate + its shipped artifacts stay live for one more cycle (Phase-D.9b
23
+ deletes them after migrating the production Cloudflare gateway worker).
24
+
25
+ ### Deprecations as throw-stubs (no engine work; runtime callers must migrate)
26
+
27
+ - **`edge-wasm-middleware.ts`** — `createEdgeWasmMiddleware`,
28
+ `initializeEdgeWasm` now `@deprecated` + throw with migration error
29
+ pointing at `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge`.
30
+ 470 LOC of hand-written wasm-bindgen heap manager removed (the
31
+ engine path has its own wasm-bindgen output centrally maintained in
32
+ `@kya-os/checkpoint-wasm-runtime`).
33
+
34
+ - **`nodejs-wasm-loader.ts`** — `loadWasmNodejs`, `isNodejsRuntime`,
35
+ `getWasmModule`, `isWasmInitialized` now `@deprecated` + throw with
36
+ the same migration error. 117 LOC of `fs.readFileSync`-based
37
+ multi-path WASM-locator logic removed (`@kya-os/checkpoint-wasm-runtime`'s
38
+ loaders auto-resolve via the `"node"` / `"edge-runtime"` export
39
+ conditions; no manual `fs` needed).
40
+
41
+ Net: **−415 LOC** of legacy wasm-bindgen glue / fs-locator code.
42
+
43
+ ### Throw-stub pattern (matches PR #2610's `createWasmAgentShieldMiddleware`)
44
+
45
+ - One-shot dev-only `console.warn` on first invocation; suppressed in
46
+ production and after the first emission.
47
+ - Test-only reset helpers exported (`__resetEdgeWasmWarningForTests`,
48
+ `__resetNodejsWasmWarningForTests`).
49
+ - Migration target named directly in the error message.
50
+
51
+ ### Why throw vs. deprecate-and-keep-working
52
+
53
+ Unlike PR #2610's `createWasmAgentShieldMiddleware` (which still does
54
+ useful work backed by the legacy `AgentDetector` class), these two
55
+ files depend on the `agentshield-wasm` Rust crate's shipped artifacts.
56
+ The artifacts will be deleted in Phase-D.9b. Keeping these functions
57
+ working until D.9b would mean they'd start silently failing the moment
58
+ the artifact deletion lands. Throwing immediately on call surfaces
59
+ the migration error today, before D.9b's deletion makes it worse.
60
+
61
+ ### Regression tests (20 new across 3 files)
62
+
63
+ - `edge-wasm-middleware.test.ts` (7 tests): throws with migration
64
+ error, one-shot warn, no-op in prod, latch shared across both exports
65
+ - `nodejs-wasm-loader.test.ts` (6 tests): same shape across the 4
66
+ throw-stub exports + shared-latch verification
67
+ - `d9-deletion-gate-scaffold.test.ts` (7 tests): pins what Phase-D.9a
68
+ achieved structurally — both files exist as compile-time surface;
69
+ both removed inline wasm-bindgen helpers; both reference
70
+ `withCheckpoint`; no live imports of `setWasmModule` from the legacy
71
+ `@kya-os/checkpoint` package
72
+
73
+ Revert-and-fail verified: removing the `warn*()` call from either
74
+ throw-stub function fails 2 of the warn assertions; restoring re-greens.
75
+
76
+ ### Out of scope for D.9a (deferred to Phase-D.9b)
77
+
78
+ - `rust/crates/agentshield-wasm/` Rust crate deletion (gateway worker
79
+ is the last consumer)
80
+ - All 7 shipped `agentshield_wasm_bg.wasm` artifact copies
81
+ - `apps/web/lib/wasm/agentshield-loader.ts` migration (audit found 6
82
+ production-route consumers using a multi-function WASM API that
83
+ doesn't map structurally to the engine's single `verify(input, ctx)`
84
+ entry — needs the same engine-API translation as the gateway worker)
85
+ - Cloudflare gateway worker migration (production-risk; needs Wrangler
86
+ preview deploy + cold-start measurement; compressed size verified at
87
+ 0.44 MB, well under Workers' 1 MB free-tier limit)
88
+ - `apps/web/public/sw.js` service-worker cache manifest cleanup
89
+ - Top-level ad-hoc `test-wasm.mjs`-style dev scripts at repo root
90
+ - Final deletion-gate test (lands with D.9b)
91
+
92
+ ### Bench safety
93
+
94
+ TS-only, zero `kya-os-engine` or `agentshield-wasm` Rust changes.
95
+ Ships in parallel with Engineer 1's Express bench pivot + bundler audit.
96
+
97
+ ### Version
98
+
99
+ `@kya-os/checkpoint-nextjs` 1.1.2 → **1.1.3** (patch — deprecation,
100
+ breaking only for callers that ignored the prior deprecation cycle).
101
+
102
+ ## 1.1.2 — 2026-05-17
103
+
104
+ AgentDetector-Deletion-1 (Phase 1 of 2) — deprecate the two README-
105
+ documented public APIs that wrap the legacy TS `AgentDetector` class.
106
+ The class itself stays live for one more minor release; this patch is
107
+ the deprecation signal.
108
+
109
+ ### Deprecations (no behavior change)
110
+
111
+ - **`useAgentDetection`** (`packages/checkpoint-nextjs/src/hooks.ts`)
112
+ - `@deprecated` JSDoc + one-shot dev-only `console.warn`
113
+ - Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` for
114
+ server-side detection, or consume `KNOWN_AGENT_PATTERNS` directly
115
+ from `@kya-os/checkpoint-shared` for client-side pattern matching.
116
+ - `useDetectionMonitor` is NOT deprecated — it doesn't depend on
117
+ `AgentDetector`.
118
+
119
+ - **`createWasmAgentShieldMiddleware`** (`packages/checkpoint-nextjs/src/wasm-middleware.ts`)
120
+ - `@deprecated` JSDoc + one-shot dev-only `console.warn`
121
+ - Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` —
122
+ engine-backed, runs envelope verification.
123
+
124
+ ### Why
125
+
126
+ Pattern-Detection-Migration-1 (#2560) moved Stage 1 detection into the
127
+ Rust `kya-os-engine` crate. The legacy TS `AgentDetector` class that
128
+ both APIs wrap duplicates that path. PDM-2 (#2608) consolidated the
129
+ shared pattern table; this patch begins phasing out the legacy class
130
+ itself.
131
+
132
+ ### Removal timeline
133
+
134
+ - **Now (1.1.2):** deprecation signals — APIs keep working, dev-only
135
+ `console.warn` fires once per process pointing at the migration
136
+ target. README banners added.
137
+ - **Next minor:** AgentDetector-Deletion-2 — delete the legacy class,
138
+ delete these two APIs, deletion-gate test pins absence. Will be a
139
+ breaking change for any caller that ignored the deprecation.
140
+
141
+ ### Bench safety
142
+
143
+ TS-only, zero `kya-os-engine` changes. Ships in parallel with
144
+ in-flight Rust bench captures without invalidating them.
145
+
146
+ ## 1.1.1 — 2026-05-17
147
+
148
+ Companion patch to `@kya-os/checkpoint-wasm-runtime@1.1.0`'s
149
+ SDK-WASM-Bundler-Loader-1 fix. **All 1.1.0 users running under Next.js
150
+ Node runtime should upgrade** — `withCheckpoint` couldn't actually be
151
+ deployed under Next.js Node runtime in 1.1.0 due to a Turbopack-
152
+ incompatible URL trick in the wasm-runtime's orchestrator bundle.
153
+
154
+ ### Internal change
155
+
156
+ - `@kya-os/checkpoint-wasm-runtime` dep changed from exact `1.0.0`
157
+ pin (the `workspace:*` default) to `^1.1.0` range (via `workspace:^`).
158
+ Fresh installs now pull `wasm-runtime@1.1.0+`, which adds the
159
+ `"node"` export condition routing Next.js Node-runtime bundlers to
160
+ the bundler-clean `orchestrator-node.mjs` entry.
161
+
162
+ ### No code or config changes
163
+
164
+ Customer middleware.ts call site is unchanged. Verifying envelopes
165
+ under Next.js Node runtime now works end-to-end:
166
+
167
+ ```typescript
168
+ import { withCheckpoint } from '@kya-os/checkpoint-nextjs';
169
+
170
+ export default withCheckpoint({
171
+ tenantHost: 'acme.checkpoint.example',
172
+ legacyEnvelopeFallback: true,
173
+ });
174
+ ```
175
+
176
+ See `@kya-os/checkpoint-wasm-runtime@1.1.0` CHANGELOG for the
177
+ architectural detail.
178
+
179
+ ---
180
+
3
181
  ## 1.1.0 — 2026-05-17
4
182
 
5
183
  Closes [SDK-Envelope-Plumbing-1 (#2594)](https://github.com/Know-That-Ai/agent-shield/issues/2594).
@@ -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
  });