@kya-os/checkpoint-nextjs 1.0.0 → 1.1.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 (91) hide show
  1. package/CHANGELOG.md +165 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/adapt.js +0 -2
  4. package/dist/adapt.mjs +0 -2
  5. package/dist/api-client.js +38 -24
  6. package/dist/api-client.mjs +38 -24
  7. package/dist/api-middleware.js +48 -28
  8. package/dist/api-middleware.mjs +48 -28
  9. package/dist/create-middleware.d.mts +1 -1
  10. package/dist/create-middleware.d.ts +1 -1
  11. package/dist/create-middleware.js +0 -2
  12. package/dist/create-middleware.mjs +0 -2
  13. package/dist/edge/index.d.mts +1 -1
  14. package/dist/edge/index.d.ts +1 -1
  15. package/dist/edge/index.js +4 -6
  16. package/dist/edge/index.mjs +4 -6
  17. package/dist/edge-runtime-loader.js +7 -2
  18. package/dist/edge-runtime-loader.mjs +7 -2
  19. package/dist/edge-wasm-middleware.js +0 -2
  20. package/dist/edge-wasm-middleware.mjs +0 -2
  21. package/dist/index.d.mts +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +77 -42
  24. package/dist/index.mjs +77 -42
  25. package/dist/middleware-edge.js +17 -10
  26. package/dist/middleware-edge.mjs +17 -10
  27. package/dist/middleware-node.d.mts +36 -0
  28. package/dist/middleware-node.d.ts +36 -0
  29. package/dist/middleware-node.js +17 -10
  30. package/dist/middleware-node.mjs +17 -10
  31. package/dist/middleware.d.mts +1 -1
  32. package/dist/middleware.d.ts +1 -1
  33. package/dist/middleware.js +0 -2
  34. package/dist/middleware.mjs +0 -2
  35. package/dist/nodejs-wasm-loader.js +0 -2
  36. package/dist/nodejs-wasm-loader.mjs +0 -2
  37. package/dist/policy.js +10 -6
  38. package/dist/policy.mjs +10 -6
  39. package/dist/session-tracker.js +1 -3
  40. package/dist/session-tracker.mjs +1 -3
  41. package/dist/signature-verifier.js +0 -2
  42. package/dist/signature-verifier.mjs +0 -2
  43. package/dist/translate.d.mts +36 -9
  44. package/dist/translate.d.ts +36 -9
  45. package/dist/translate.js +13 -8
  46. package/dist/translate.mjs +13 -8
  47. package/dist/{types-C-xCUNTr.d.mts → types-D9RQvPNy.d.mts} +1 -1
  48. package/dist/{types-C-xCUNTr.d.ts → types-D9RQvPNy.d.ts} +1 -1
  49. package/dist/wasm-middleware.d.mts +29 -10
  50. package/dist/wasm-middleware.d.ts +29 -10
  51. package/dist/wasm-middleware.js +0 -2
  52. package/dist/wasm-middleware.mjs +0 -2
  53. package/dist/wasm-setup.js +0 -2
  54. package/dist/wasm-setup.mjs +0 -2
  55. package/package.json +3 -3
  56. package/dist/adapt.js.map +0 -1
  57. package/dist/adapt.mjs.map +0 -1
  58. package/dist/api-client.js.map +0 -1
  59. package/dist/api-client.mjs.map +0 -1
  60. package/dist/api-middleware.js.map +0 -1
  61. package/dist/api-middleware.mjs.map +0 -1
  62. package/dist/create-middleware.js.map +0 -1
  63. package/dist/create-middleware.mjs.map +0 -1
  64. package/dist/edge/index.js.map +0 -1
  65. package/dist/edge/index.mjs.map +0 -1
  66. package/dist/edge-runtime-loader.js.map +0 -1
  67. package/dist/edge-runtime-loader.mjs.map +0 -1
  68. package/dist/edge-wasm-middleware.js.map +0 -1
  69. package/dist/edge-wasm-middleware.mjs.map +0 -1
  70. package/dist/index.js.map +0 -1
  71. package/dist/index.mjs.map +0 -1
  72. package/dist/middleware-edge.js.map +0 -1
  73. package/dist/middleware-edge.mjs.map +0 -1
  74. package/dist/middleware-node.js.map +0 -1
  75. package/dist/middleware-node.mjs.map +0 -1
  76. package/dist/middleware.js.map +0 -1
  77. package/dist/middleware.mjs.map +0 -1
  78. package/dist/nodejs-wasm-loader.js.map +0 -1
  79. package/dist/nodejs-wasm-loader.mjs.map +0 -1
  80. package/dist/policy.js.map +0 -1
  81. package/dist/policy.mjs.map +0 -1
  82. package/dist/session-tracker.js.map +0 -1
  83. package/dist/session-tracker.mjs.map +0 -1
  84. package/dist/signature-verifier.js.map +0 -1
  85. package/dist/signature-verifier.mjs.map +0 -1
  86. package/dist/translate.js.map +0 -1
  87. package/dist/translate.mjs.map +0 -1
  88. package/dist/wasm-middleware.js.map +0 -1
  89. package/dist/wasm-middleware.mjs.map +0 -1
  90. package/dist/wasm-setup.js.map +0 -1
  91. package/dist/wasm-setup.mjs.map +0 -1
@@ -57,21 +57,28 @@ function applyHeaders(res, headers) {
57
57
  }
58
58
 
59
59
  // src/translate.ts
60
- function nextRequestToHttpLike(req) {
60
+ async function nextRequestToHttpLike(req, opts = {}) {
61
61
  const url = new URL(req.url);
62
+ const body = await tryDrainJsonBody(req, opts);
62
63
  return {
63
64
  method: req.method,
64
65
  // Path + query only — orchestrator's URL parsing expects no scheme/host.
65
66
  url: url.pathname + url.search,
66
67
  headers: headersToRecord(req.headers),
67
- // NextRequest.body is a ReadableStream; we don't drain it here.
68
- // The orchestrator routes to PlainHttp when body is falsy, which
69
- // is the right call for streaming middlewares that don't want to
70
- // buffer the request body just to detect agents.
71
- body: null,
68
+ body,
72
69
  remoteAddress: extractRemoteAddress(req)
73
70
  };
74
71
  }
72
+ async function tryDrainJsonBody(req, opts) {
73
+ if (opts.drainJsonBody === false) return null;
74
+ const contentType = req.headers.get("content-type") ?? "";
75
+ if (!contentType.toLowerCase().includes("application/json")) return null;
76
+ try {
77
+ return await req.clone().text();
78
+ } catch {
79
+ return null;
80
+ }
81
+ }
75
82
  function headersToRecord(headers) {
76
83
  const out = {};
77
84
  headers.forEach((value, key) => {
@@ -101,7 +108,8 @@ function buildVerifyOpts(config) {
101
108
  tenantHost: config.tenantHost,
102
109
  enforcementMode: config.enforcementMode ?? "enforce",
103
110
  reputationBaseline: config.reputationBaseline,
104
- argusUrl: config.argusUrl
111
+ argusUrl: config.argusUrl,
112
+ legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
105
113
  };
106
114
  }
107
115
 
@@ -109,8 +117,9 @@ function buildVerifyOpts(config) {
109
117
  function withCheckpoint(config) {
110
118
  void edge.initEngineEdge();
111
119
  const opts = buildVerifyOpts(config);
120
+ const translateOpts = { drainJsonBody: config.drainJsonBody };
112
121
  return async function checkpointMiddlewareEdge(req) {
113
- const httpLike = nextRequestToHttpLike(req);
122
+ const httpLike = await nextRequestToHttpLike(req, translateOpts);
114
123
  const result = await edge.verifyRequestEdge(httpLike, opts);
115
124
  await dispatchOnResult(config, result, req);
116
125
  const rendered = edge.renderDecisionAsResponse(result);
@@ -130,5 +139,3 @@ Object.defineProperty(exports, "initEngineEdge", {
130
139
  get: function () { return edge.initEngineEdge; }
131
140
  });
132
141
  exports.withCheckpoint = withCheckpoint;
133
- //# sourceMappingURL=middleware-edge.js.map
134
- //# sourceMappingURL=middleware-edge.js.map
@@ -56,21 +56,28 @@ function applyHeaders(res, headers) {
56
56
  }
57
57
 
58
58
  // src/translate.ts
59
- function nextRequestToHttpLike(req) {
59
+ async function nextRequestToHttpLike(req, opts = {}) {
60
60
  const url = new URL(req.url);
61
+ const body = await tryDrainJsonBody(req, opts);
61
62
  return {
62
63
  method: req.method,
63
64
  // Path + query only — orchestrator's URL parsing expects no scheme/host.
64
65
  url: url.pathname + url.search,
65
66
  headers: headersToRecord(req.headers),
66
- // NextRequest.body is a ReadableStream; we don't drain it here.
67
- // The orchestrator routes to PlainHttp when body is falsy, which
68
- // is the right call for streaming middlewares that don't want to
69
- // buffer the request body just to detect agents.
70
- body: null,
67
+ body,
71
68
  remoteAddress: extractRemoteAddress(req)
72
69
  };
73
70
  }
71
+ async function tryDrainJsonBody(req, opts) {
72
+ if (opts.drainJsonBody === false) return null;
73
+ const contentType = req.headers.get("content-type") ?? "";
74
+ if (!contentType.toLowerCase().includes("application/json")) return null;
75
+ try {
76
+ return await req.clone().text();
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
74
81
  function headersToRecord(headers) {
75
82
  const out = {};
76
83
  headers.forEach((value, key) => {
@@ -100,7 +107,8 @@ function buildVerifyOpts(config) {
100
107
  tenantHost: config.tenantHost,
101
108
  enforcementMode: config.enforcementMode ?? "enforce",
102
109
  reputationBaseline: config.reputationBaseline,
103
- argusUrl: config.argusUrl
110
+ argusUrl: config.argusUrl,
111
+ legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
104
112
  };
105
113
  }
106
114
 
@@ -108,8 +116,9 @@ function buildVerifyOpts(config) {
108
116
  function withCheckpoint(config) {
109
117
  void initEngineEdge();
110
118
  const opts = buildVerifyOpts(config);
119
+ const translateOpts = { drainJsonBody: config.drainJsonBody };
111
120
  return async function checkpointMiddlewareEdge(req) {
112
- const httpLike = nextRequestToHttpLike(req);
121
+ const httpLike = await nextRequestToHttpLike(req, translateOpts);
113
122
  const result = await verifyRequestEdge(httpLike, opts);
114
123
  await dispatchOnResult(config, result, req);
115
124
  const rendered = renderDecisionAsResponse(result);
@@ -125,5 +134,3 @@ async function dispatchOnResult(config, result, req) {
125
134
  }
126
135
 
127
136
  export { withCheckpoint };
128
- //# sourceMappingURL=middleware-edge.mjs.map
129
- //# sourceMappingURL=middleware-edge.mjs.map
@@ -58,6 +58,41 @@ interface CheckpointConfig {
58
58
  * response.
59
59
  */
60
60
  onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
61
+ /**
62
+ * Accept legacy `KYA-Delegation`-header envelope form alongside the
63
+ * canonical `_meta.proof.jws` body form. Default `false`.
64
+ *
65
+ * **When to enable** — customers whose agents pre-date Envelope-1
66
+ * (#2537) and ship MCP-I proofs as `{protected,payload,signature}`
67
+ * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
68
+ * ship compact JWS in the request body's `_meta.proof.jws` field;
69
+ * those don't need this flag.
70
+ *
71
+ * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
72
+ * Both transports (header + body) are honored when this is `true`;
73
+ * the orchestrator's detection order is body first, then header
74
+ * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
75
+ *
76
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
77
+ */
78
+ legacyEnvelopeFallback?: boolean;
79
+ /**
80
+ * Read the request body when `content-type` is `application/json` so
81
+ * the orchestrator can extract an MCP-I envelope from
82
+ * `_meta.proof.jws`. Default `true`.
83
+ *
84
+ * **When to disable** — streaming middlewares that can't tolerate
85
+ * the `req.clone()` memory overhead (one full-body copy is buffered
86
+ * during the read). For those, set `false` and route MCP-I
87
+ * envelopes through the `KYA-Delegation` header transport instead
88
+ * (requires `legacyEnvelopeFallback: true`).
89
+ *
90
+ * The clone preserves `req.body` for downstream handlers — disabling
91
+ * is a performance optimization, not a correctness fix.
92
+ *
93
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
94
+ */
95
+ drainJsonBody?: boolean;
61
96
  }
62
97
  /**
63
98
  * Build the Checkpoint middleware. Returns a function `(req) => NextResponse`
@@ -84,6 +119,7 @@ declare function buildVerifyOpts(config: CheckpointConfig): {
84
119
  enforcementMode: EnforcementMode;
85
120
  reputationBaseline: number | undefined;
86
121
  argusUrl: string | undefined;
122
+ legacyEnvelopeFallback: boolean;
87
123
  };
88
124
 
89
125
  export { type CheckpointConfig, buildVerifyOpts as _buildVerifyOpts, withCheckpoint };
@@ -58,6 +58,41 @@ interface CheckpointConfig {
58
58
  * response.
59
59
  */
60
60
  onResult?: (result: VerifyResult, req: NextRequest) => void | Promise<void>;
61
+ /**
62
+ * Accept legacy `KYA-Delegation`-header envelope form alongside the
63
+ * canonical `_meta.proof.jws` body form. Default `false`.
64
+ *
65
+ * **When to enable** — customers whose agents pre-date Envelope-1
66
+ * (#2537) and ship MCP-I proofs as `{protected,payload,signature}`
67
+ * JSON in a `KYA-Delegation` HTTP header. Post-Envelope-1 agents
68
+ * ship compact JWS in the request body's `_meta.proof.jws` field;
69
+ * those don't need this flag.
70
+ *
71
+ * Forwarded to the orchestrator's `VerifyRequestOpts.legacyEnvelopeFallback`.
72
+ * Both transports (header + body) are honored when this is `true`;
73
+ * the orchestrator's detection order is body first, then header
74
+ * (`packages/checkpoint-wasm-runtime/src/engine/orchestrator/build-agent-request.ts`).
75
+ *
76
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
77
+ */
78
+ legacyEnvelopeFallback?: boolean;
79
+ /**
80
+ * Read the request body when `content-type` is `application/json` so
81
+ * the orchestrator can extract an MCP-I envelope from
82
+ * `_meta.proof.jws`. Default `true`.
83
+ *
84
+ * **When to disable** — streaming middlewares that can't tolerate
85
+ * the `req.clone()` memory overhead (one full-body copy is buffered
86
+ * during the read). For those, set `false` and route MCP-I
87
+ * envelopes through the `KYA-Delegation` header transport instead
88
+ * (requires `legacyEnvelopeFallback: true`).
89
+ *
90
+ * The clone preserves `req.body` for downstream handlers — disabling
91
+ * is a performance optimization, not a correctness fix.
92
+ *
93
+ * SDK-Envelope-Plumbing-1 (#2594). Added in `@kya-os/checkpoint-nextjs@1.1.0`.
94
+ */
95
+ drainJsonBody?: boolean;
61
96
  }
62
97
  /**
63
98
  * Build the Checkpoint middleware. Returns a function `(req) => NextResponse`
@@ -84,6 +119,7 @@ declare function buildVerifyOpts(config: CheckpointConfig): {
84
119
  enforcementMode: EnforcementMode;
85
120
  reputationBaseline: number | undefined;
86
121
  argusUrl: string | undefined;
122
+ legacyEnvelopeFallback: boolean;
87
123
  };
88
124
 
89
125
  export { type CheckpointConfig, buildVerifyOpts as _buildVerifyOpts, withCheckpoint };
@@ -56,21 +56,28 @@ function applyHeaders(res, headers) {
56
56
  }
57
57
 
58
58
  // src/translate.ts
59
- function nextRequestToHttpLike(req) {
59
+ async function nextRequestToHttpLike(req, opts = {}) {
60
60
  const url = new URL(req.url);
61
+ const body = await tryDrainJsonBody(req, opts);
61
62
  return {
62
63
  method: req.method,
63
64
  // Path + query only — orchestrator's URL parsing expects no scheme/host.
64
65
  url: url.pathname + url.search,
65
66
  headers: headersToRecord(req.headers),
66
- // NextRequest.body is a ReadableStream; we don't drain it here.
67
- // The orchestrator routes to PlainHttp when body is falsy, which
68
- // is the right call for streaming middlewares that don't want to
69
- // buffer the request body just to detect agents.
70
- body: null,
67
+ body,
71
68
  remoteAddress: extractRemoteAddress(req)
72
69
  };
73
70
  }
71
+ async function tryDrainJsonBody(req, opts) {
72
+ if (opts.drainJsonBody === false) return null;
73
+ const contentType = req.headers.get("content-type") ?? "";
74
+ if (!contentType.toLowerCase().includes("application/json")) return null;
75
+ try {
76
+ return await req.clone().text();
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
74
81
  function headersToRecord(headers) {
75
82
  const out = {};
76
83
  headers.forEach((value, key) => {
@@ -91,8 +98,9 @@ function extractRemoteAddress(req) {
91
98
  // src/middleware-node.ts
92
99
  function withCheckpoint(config) {
93
100
  const opts = buildVerifyOpts(config);
101
+ const translateOpts = { drainJsonBody: config.drainJsonBody };
94
102
  return async function checkpointMiddleware(req) {
95
- const httpLike = nextRequestToHttpLike(req);
103
+ const httpLike = await nextRequestToHttpLike(req, translateOpts);
96
104
  const result = await orchestrator.verifyRequest(httpLike, opts);
97
105
  await dispatchOnResult(config, result, req);
98
106
  const rendered = orchestrator.renderDecisionAsResponse(result);
@@ -110,7 +118,8 @@ function buildVerifyOpts(config) {
110
118
  tenantHost: config.tenantHost,
111
119
  enforcementMode: config.enforcementMode ?? "enforce",
112
120
  reputationBaseline: config.reputationBaseline,
113
- argusUrl: config.argusUrl
121
+ argusUrl: config.argusUrl,
122
+ legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
114
123
  };
115
124
  }
116
125
  async function dispatchOnResult(config, result, req) {
@@ -123,5 +132,3 @@ async function dispatchOnResult(config, result, req) {
123
132
 
124
133
  exports._buildVerifyOpts = buildVerifyOpts;
125
134
  exports.withCheckpoint = withCheckpoint;
126
- //# sourceMappingURL=middleware-node.js.map
127
- //# sourceMappingURL=middleware-node.js.map
@@ -54,21 +54,28 @@ function applyHeaders(res, headers) {
54
54
  }
55
55
 
56
56
  // src/translate.ts
57
- function nextRequestToHttpLike(req) {
57
+ async function nextRequestToHttpLike(req, opts = {}) {
58
58
  const url = new URL(req.url);
59
+ const body = await tryDrainJsonBody(req, opts);
59
60
  return {
60
61
  method: req.method,
61
62
  // Path + query only — orchestrator's URL parsing expects no scheme/host.
62
63
  url: url.pathname + url.search,
63
64
  headers: headersToRecord(req.headers),
64
- // NextRequest.body is a ReadableStream; we don't drain it here.
65
- // The orchestrator routes to PlainHttp when body is falsy, which
66
- // is the right call for streaming middlewares that don't want to
67
- // buffer the request body just to detect agents.
68
- body: null,
65
+ body,
69
66
  remoteAddress: extractRemoteAddress(req)
70
67
  };
71
68
  }
69
+ async function tryDrainJsonBody(req, opts) {
70
+ if (opts.drainJsonBody === false) return null;
71
+ const contentType = req.headers.get("content-type") ?? "";
72
+ if (!contentType.toLowerCase().includes("application/json")) return null;
73
+ try {
74
+ return await req.clone().text();
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
72
79
  function headersToRecord(headers) {
73
80
  const out = {};
74
81
  headers.forEach((value, key) => {
@@ -89,8 +96,9 @@ function extractRemoteAddress(req) {
89
96
  // src/middleware-node.ts
90
97
  function withCheckpoint(config) {
91
98
  const opts = buildVerifyOpts(config);
99
+ const translateOpts = { drainJsonBody: config.drainJsonBody };
92
100
  return async function checkpointMiddleware(req) {
93
- const httpLike = nextRequestToHttpLike(req);
101
+ const httpLike = await nextRequestToHttpLike(req, translateOpts);
94
102
  const result = await verifyRequest(httpLike, opts);
95
103
  await dispatchOnResult(config, result, req);
96
104
  const rendered = renderDecisionAsResponse(result);
@@ -108,7 +116,8 @@ function buildVerifyOpts(config) {
108
116
  tenantHost: config.tenantHost,
109
117
  enforcementMode: config.enforcementMode ?? "enforce",
110
118
  reputationBaseline: config.reputationBaseline,
111
- argusUrl: config.argusUrl
119
+ argusUrl: config.argusUrl,
120
+ legacyEnvelopeFallback: config.legacyEnvelopeFallback ?? false
112
121
  };
113
122
  }
114
123
  async function dispatchOnResult(config, result, req) {
@@ -120,5 +129,3 @@ async function dispatchOnResult(config, result, req) {
120
129
  }
121
130
 
122
131
  export { buildVerifyOpts as _buildVerifyOpts, withCheckpoint };
123
- //# sourceMappingURL=middleware-node.mjs.map
124
- //# sourceMappingURL=middleware-node.mjs.map
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { N as NextJSMiddlewareConfig } from './types-C-xCUNTr.mjs';
2
+ import { N as NextJSMiddlewareConfig } from './types-D9RQvPNy.mjs';
3
3
  import '@kya-os/checkpoint-shared';
4
4
  import '@kya-os/checkpoint';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { N as NextJSMiddlewareConfig } from './types-C-xCUNTr.js';
2
+ import { N as NextJSMiddlewareConfig } from './types-D9RQvPNy.js';
3
3
  import '@kya-os/checkpoint-shared';
4
4
  import '@kya-os/checkpoint';
5
5
 
@@ -11,5 +11,3 @@ function agentShield(config = {}) {
11
11
 
12
12
  exports.agentShield = agentShield;
13
13
  exports.createAgentShieldMiddleware = createAgentShieldMiddleware;
14
- //# sourceMappingURL=middleware.js.map
15
- //# sourceMappingURL=middleware.js.map
@@ -8,5 +8,3 @@ function agentShield(config = {}) {
8
8
  }
9
9
 
10
10
  export { agentShield, createAgentShieldMiddleware };
11
- //# sourceMappingURL=middleware.mjs.map
12
- //# sourceMappingURL=middleware.mjs.map
@@ -91,5 +91,3 @@ exports.getWasmModule = getWasmModule;
91
91
  exports.isNodejsRuntime = isNodejsRuntime;
92
92
  exports.isWasmInitialized = isWasmInitialized;
93
93
  exports.loadWasmNodejs = loadWasmNodejs;
94
- //# sourceMappingURL=nodejs-wasm-loader.js.map
95
- //# sourceMappingURL=nodejs-wasm-loader.js.map
@@ -81,5 +81,3 @@ function isWasmInitialized() {
81
81
  }
82
82
 
83
83
  export { getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
84
- //# sourceMappingURL=nodejs-wasm-loader.mjs.map
85
- //# sourceMappingURL=nodejs-wasm-loader.mjs.map
package/dist/policy.js CHANGED
@@ -74,7 +74,7 @@ async function handlePolicyDecision(request, decision, config, detection) {
74
74
  case checkpointShared.ENFORCEMENT_ACTIONS.CHALLENGE:
75
75
  return buildChallengeResponse(request, decision, config, detection);
76
76
  case checkpointShared.ENFORCEMENT_ACTIONS.LOG:
77
- console.log("[AgentShield] Policy decision (log):", {
77
+ console.log("[Checkpoint] Policy decision (log):", {
78
78
  path: request.nextUrl.pathname,
79
79
  action: decision.action,
80
80
  reason: decision.reason,
@@ -119,7 +119,7 @@ async function getPolicy(config) {
119
119
  return await fetcher.getPolicy(config.fetchPolicy.projectId);
120
120
  } catch (error) {
121
121
  if (config.debug) {
122
- console.warn("[AgentShield] Policy fetch failed, using fallback:", error);
122
+ console.warn("[Checkpoint] Policy fetch failed, using fallback:", error);
123
123
  }
124
124
  return checkpointShared.PolicyConfigSchema.parse({
125
125
  ...checkpointShared.DEFAULT_POLICY,
@@ -144,12 +144,18 @@ async function applyPolicy(request, detection, config) {
144
144
  const context = createContextFromDetection(detection, request);
145
145
  const decision = checkpointShared.evaluatePolicy(policy, context);
146
146
  if (config.onPolicyDecision) {
147
- await config.onPolicyDecision(request, decision, context);
147
+ try {
148
+ await config.onPolicyDecision(request, decision, context);
149
+ } catch (error) {
150
+ if (config.debug) {
151
+ console.error("[Checkpoint] onPolicyDecision callback failed:", error);
152
+ }
153
+ }
148
154
  }
149
155
  return await handlePolicyDecision(request, decision, config, detection);
150
156
  } catch (error) {
151
157
  if (config.debug) {
152
- console.error("[AgentShield] Policy evaluation error:", error);
158
+ console.error("[Checkpoint] Policy evaluation error:", error);
153
159
  }
154
160
  if (config.failOpen !== false) {
155
161
  return null;
@@ -185,5 +191,3 @@ exports.createContextFromDetection = createContextFromDetection;
185
191
  exports.evaluatePolicyForDetection = evaluatePolicyForDetection;
186
192
  exports.getPolicy = getPolicy;
187
193
  exports.handlePolicyDecision = handlePolicyDecision;
188
- //# sourceMappingURL=policy.js.map
189
- //# sourceMappingURL=policy.js.map
package/dist/policy.mjs CHANGED
@@ -73,7 +73,7 @@ async function handlePolicyDecision(request, decision, config, detection) {
73
73
  case ENFORCEMENT_ACTIONS.CHALLENGE:
74
74
  return buildChallengeResponse(request, decision, config, detection);
75
75
  case ENFORCEMENT_ACTIONS.LOG:
76
- console.log("[AgentShield] Policy decision (log):", {
76
+ console.log("[Checkpoint] Policy decision (log):", {
77
77
  path: request.nextUrl.pathname,
78
78
  action: decision.action,
79
79
  reason: decision.reason,
@@ -118,7 +118,7 @@ async function getPolicy(config) {
118
118
  return await fetcher.getPolicy(config.fetchPolicy.projectId);
119
119
  } catch (error) {
120
120
  if (config.debug) {
121
- console.warn("[AgentShield] Policy fetch failed, using fallback:", error);
121
+ console.warn("[Checkpoint] Policy fetch failed, using fallback:", error);
122
122
  }
123
123
  return PolicyConfigSchema.parse({
124
124
  ...DEFAULT_POLICY,
@@ -143,12 +143,18 @@ async function applyPolicy(request, detection, config) {
143
143
  const context = createContextFromDetection(detection, request);
144
144
  const decision = evaluatePolicy(policy, context);
145
145
  if (config.onPolicyDecision) {
146
- await config.onPolicyDecision(request, decision, context);
146
+ try {
147
+ await config.onPolicyDecision(request, decision, context);
148
+ } catch (error) {
149
+ if (config.debug) {
150
+ console.error("[Checkpoint] onPolicyDecision callback failed:", error);
151
+ }
152
+ }
147
153
  }
148
154
  return await handlePolicyDecision(request, decision, config, detection);
149
155
  } catch (error) {
150
156
  if (config.debug) {
151
- console.error("[AgentShield] Policy evaluation error:", error);
157
+ console.error("[Checkpoint] Policy evaluation error:", error);
152
158
  }
153
159
  if (config.failOpen !== false) {
154
160
  return null;
@@ -161,5 +167,3 @@ async function applyPolicy(request, detection, config) {
161
167
  }
162
168
 
163
169
  export { applyPolicy, buildBlockedResponse, buildChallengeResponse, buildRedirectResponse, createContextFromDetection, evaluatePolicyForDetection, getPolicy, handlePolicyDecision };
164
- //# sourceMappingURL=policy.mjs.map
165
- //# sourceMappingURL=policy.mjs.map
@@ -11,7 +11,7 @@ var EdgeSessionTracker = class {
11
11
  cookieName: config.cookieName || "__agentshield_session",
12
12
  cookieMaxAge: config.cookieMaxAge || 3600,
13
13
  // 1 hour default
14
- encryptionKey: config.encryptionKey || process.env.AGENTSHIELD_SECRET || "agentshield-default-key"
14
+ encryptionKey: config.encryptionKey || process.env.CHECKPOINT_SECRET || "agentshield-default-key"
15
15
  };
16
16
  }
17
17
  /**
@@ -166,5 +166,3 @@ var StatelessSessionChecker = class {
166
166
 
167
167
  exports.EdgeSessionTracker = EdgeSessionTracker;
168
168
  exports.StatelessSessionChecker = StatelessSessionChecker;
169
- //# sourceMappingURL=session-tracker.js.map
170
- //# sourceMappingURL=session-tracker.js.map
@@ -9,7 +9,7 @@ var EdgeSessionTracker = class {
9
9
  cookieName: config.cookieName || "__agentshield_session",
10
10
  cookieMaxAge: config.cookieMaxAge || 3600,
11
11
  // 1 hour default
12
- encryptionKey: config.encryptionKey || process.env.AGENTSHIELD_SECRET || "agentshield-default-key"
12
+ encryptionKey: config.encryptionKey || process.env.CHECKPOINT_SECRET || "agentshield-default-key"
13
13
  };
14
14
  }
15
15
  /**
@@ -163,5 +163,3 @@ var StatelessSessionChecker = class {
163
163
  };
164
164
 
165
165
  export { EdgeSessionTracker, StatelessSessionChecker };
166
- //# sourceMappingURL=session-tracker.mjs.map
167
- //# sourceMappingURL=session-tracker.mjs.map
@@ -382,5 +382,3 @@ function isChatGPTSignature(headers) {
382
382
  exports.hasSignatureHeaders = hasSignatureHeaders;
383
383
  exports.isChatGPTSignature = isChatGPTSignature;
384
384
  exports.verifyAgentSignature = verifyAgentSignature;
385
- //# sourceMappingURL=signature-verifier.js.map
386
- //# sourceMappingURL=signature-verifier.js.map
@@ -358,5 +358,3 @@ function isChatGPTSignature(headers) {
358
358
  }
359
359
 
360
360
  export { hasSignatureHeaders, isChatGPTSignature, verifyAgentSignature };
361
- //# sourceMappingURL=signature-verifier.mjs.map
362
- //# sourceMappingURL=signature-verifier.mjs.map
@@ -16,18 +16,45 @@ import { IncomingHttpLike } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
16
16
  * `x-forwarded-for` first IP).
17
17
  */
18
18
 
19
+ /**
20
+ * Options controlling translator side effects.
21
+ *
22
+ * `drainJsonBody` (default `true`) controls whether the translator
23
+ * reads the request body so the orchestrator can extract an MCP-I
24
+ * envelope from `_meta.proof.jws` (the canonical spec-form transport).
25
+ *
26
+ * Trade-off — body draining consumes the request stream. We use
27
+ * `req.clone().text()` so the original `req.body` stream is preserved
28
+ * for downstream Next.js handlers. Cloning has memory overhead
29
+ * proportional to the body size; for large request bodies (>1 MB) or
30
+ * streaming-sensitive routes, set `drainJsonBody: false` and verify
31
+ * envelopes via the `KYA-Delegation` header transport instead (the
32
+ * legacy form, requires `legacyEnvelopeFallback: true` on
33
+ * `withCheckpoint`).
34
+ */
35
+ interface NextRequestToHttpLikeOpts {
36
+ /**
37
+ * Read the request body when `content-type` is `application/json` so
38
+ * the orchestrator can extract an MCP-I envelope from
39
+ * `_meta.proof.jws`. Default `true`. Set `false` for streaming
40
+ * middlewares that can't tolerate the clone/read overhead.
41
+ */
42
+ drainJsonBody?: boolean;
43
+ }
19
44
  /**
20
45
  * Translate a Next.js `NextRequest` into the orchestrator's
21
46
  * `IncomingHttpLike` shape.
22
47
  *
23
- * The body is passed through as-is the orchestrator's
24
- * `buildAgentRequest` decides whether to parse JSON (looking for an
25
- * MCP-I `_meta.proof.jws` envelope) or treat the request as PlainHttp.
26
- * On Next.js middleware the body is typically not pre-parsed; consumers
27
- * who want to inspect the body for routing decisions should `await
28
- * req.json()` themselves and pass the parsed result via a second
29
- * `verifyRequest` call (not common).
48
+ * When `opts.drainJsonBody !== false` and the request is JSON, the
49
+ * translator clones the request and reads the body into a string so
50
+ * the orchestrator's `buildAgentRequest` can extract a
51
+ * `_meta.proof.jws` envelope. The original `req.body` stream is
52
+ * preserved for downstream handlers via `req.clone()`.
53
+ *
54
+ * When the body can't be read (drain disabled, non-JSON, or a stream
55
+ * error) we pass `body: null` and the orchestrator routes to
56
+ * PlainHttp — same behavior as the pre-1.1.0 default.
30
57
  */
31
- declare function nextRequestToHttpLike(req: NextRequest): IncomingHttpLike;
58
+ declare function nextRequestToHttpLike(req: NextRequest, opts?: NextRequestToHttpLikeOpts): Promise<IncomingHttpLike>;
32
59
 
33
- export { nextRequestToHttpLike };
60
+ export { type NextRequestToHttpLikeOpts, nextRequestToHttpLike };
@@ -16,18 +16,45 @@ import { IncomingHttpLike } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
16
16
  * `x-forwarded-for` first IP).
17
17
  */
18
18
 
19
+ /**
20
+ * Options controlling translator side effects.
21
+ *
22
+ * `drainJsonBody` (default `true`) controls whether the translator
23
+ * reads the request body so the orchestrator can extract an MCP-I
24
+ * envelope from `_meta.proof.jws` (the canonical spec-form transport).
25
+ *
26
+ * Trade-off — body draining consumes the request stream. We use
27
+ * `req.clone().text()` so the original `req.body` stream is preserved
28
+ * for downstream Next.js handlers. Cloning has memory overhead
29
+ * proportional to the body size; for large request bodies (>1 MB) or
30
+ * streaming-sensitive routes, set `drainJsonBody: false` and verify
31
+ * envelopes via the `KYA-Delegation` header transport instead (the
32
+ * legacy form, requires `legacyEnvelopeFallback: true` on
33
+ * `withCheckpoint`).
34
+ */
35
+ interface NextRequestToHttpLikeOpts {
36
+ /**
37
+ * Read the request body when `content-type` is `application/json` so
38
+ * the orchestrator can extract an MCP-I envelope from
39
+ * `_meta.proof.jws`. Default `true`. Set `false` for streaming
40
+ * middlewares that can't tolerate the clone/read overhead.
41
+ */
42
+ drainJsonBody?: boolean;
43
+ }
19
44
  /**
20
45
  * Translate a Next.js `NextRequest` into the orchestrator's
21
46
  * `IncomingHttpLike` shape.
22
47
  *
23
- * The body is passed through as-is the orchestrator's
24
- * `buildAgentRequest` decides whether to parse JSON (looking for an
25
- * MCP-I `_meta.proof.jws` envelope) or treat the request as PlainHttp.
26
- * On Next.js middleware the body is typically not pre-parsed; consumers
27
- * who want to inspect the body for routing decisions should `await
28
- * req.json()` themselves and pass the parsed result via a second
29
- * `verifyRequest` call (not common).
48
+ * When `opts.drainJsonBody !== false` and the request is JSON, the
49
+ * translator clones the request and reads the body into a string so
50
+ * the orchestrator's `buildAgentRequest` can extract a
51
+ * `_meta.proof.jws` envelope. The original `req.body` stream is
52
+ * preserved for downstream handlers via `req.clone()`.
53
+ *
54
+ * When the body can't be read (drain disabled, non-JSON, or a stream
55
+ * error) we pass `body: null` and the orchestrator routes to
56
+ * PlainHttp — same behavior as the pre-1.1.0 default.
30
57
  */
31
- declare function nextRequestToHttpLike(req: NextRequest): IncomingHttpLike;
58
+ declare function nextRequestToHttpLike(req: NextRequest, opts?: NextRequestToHttpLikeOpts): Promise<IncomingHttpLike>;
32
59
 
33
- export { nextRequestToHttpLike };
60
+ export { type NextRequestToHttpLikeOpts, nextRequestToHttpLike };