@agenticprimitives/edge-cloudflare 0.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/dist/dispatch.d.ts +16 -0
- package/dist/dispatch.d.ts.map +1 -0
- package/dist/dispatch.js +20 -0
- package/dist/dispatch.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/rate-limiter.d.ts +10 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +23 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/request.d.ts +13 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +36 -0
- package/dist/request.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -0
- package/spec.md +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agentic Trust Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @agenticprimitives/edge-cloudflare
|
|
2
|
+
|
|
3
|
+
The Cloudflare adapter for [`@agenticprimitives/edge-runtime`](../edge-runtime) (spec 288 §5). It maps the
|
|
4
|
+
platform runtime onto the vendor-neutral admission core — and owns no authority
|
|
5
|
+
([ADR-0043](../../docs/architecture/decisions/0043-edge-owns-admission-never-authority.md)).
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
- **`extractAdmissionRequest(request): Promise<ExtractedRequest>`** — `{ admission, rawBody }`. Reads the
|
|
10
|
+
body once; `admission` feeds `runAdmission`, `rawBody` is the exact ArrayBuffer to forward downstream
|
|
11
|
+
(byte-identical — the native pipeline re-hashes it for spec 287).
|
|
12
|
+
- **`createCloudflareRateLimiter(binding): SoftRateLimiter`** — wraps `env.<NAME>.limit({ key })` for
|
|
13
|
+
Stage-1 abuse limits (fail-soft, opaque buckets).
|
|
14
|
+
- **`dispatchToBinding(fetcher, init): Promise<Response>`** — forwards the admitted request to the bound
|
|
15
|
+
origin (`env.MCP` / `env.A2A`) over its Service Binding, setting the edge-minted `x-correlation-id`.
|
|
16
|
+
|
|
17
|
+
## Usage (in the Worker)
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { extractAdmissionRequest, createCloudflareRateLimiter, dispatchToBinding } from '@agenticprimitives/edge-cloudflare';
|
|
21
|
+
import { runAdmission } from '@agenticprimitives/edge-runtime';
|
|
22
|
+
|
|
23
|
+
const { admission, rawBody } = await extractAdmissionRequest(request);
|
|
24
|
+
const result = await runAdmission(admission, {
|
|
25
|
+
resolveRoute, // app catalog → SurfaceDescriptor
|
|
26
|
+
softLimiter: createCloudflareRateLimiter(env.EDGE_LIMITER),
|
|
27
|
+
});
|
|
28
|
+
if (!result.ok) return new Response('admission denied', { status: result.status });
|
|
29
|
+
return dispatchToBinding(env.MCP, {
|
|
30
|
+
url: request.url, method: admission.method, headers: result.headers,
|
|
31
|
+
correlationId: result.correlationId, rawBody,
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Concrete hostnames + Service-Binding names live in the deployed Worker (`apps/demo-edge`), never here
|
|
36
|
+
(ADR-0021). The downstream origin still runs the full Web3 authority pipeline — the edge only admits + shuttles.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FetcherLike } from './types.js';
|
|
2
|
+
export interface DispatchInit {
|
|
3
|
+
/** Downstream URL — the Service Binding ignores the host and routes to the bound Worker; the
|
|
4
|
+
* path + query select the origin route. */
|
|
5
|
+
url: string;
|
|
6
|
+
method: string;
|
|
7
|
+
/** Sanitized headers from the admission result (trusted internal headers already stripped). */
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
/** The edge-minted correlation id (set here — the edge is the trusted minter). */
|
|
10
|
+
correlationId: string;
|
|
11
|
+
/** Exact body bytes to forward (omit for GET/HEAD). */
|
|
12
|
+
rawBody?: ArrayBuffer;
|
|
13
|
+
}
|
|
14
|
+
/** Forward an admitted request to a bound origin over its Service Binding, byte-for-byte. */
|
|
15
|
+
export declare function dispatchToBinding(fetcher: FetcherLike, init: DispatchInit): Promise<Response>;
|
|
16
|
+
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B;gDAC4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,+FAA+F;IAC/F,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,kFAAkF;IAClF,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,6FAA6F;AAC7F,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAUnG"}
|
package/dist/dispatch.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Service-Binding dispatch: forward an ADMITTED request to the private origin (demo-a2a / demo-mcp).
|
|
2
|
+
//
|
|
3
|
+
// The edge owns no authority — it shuttles the exact admitted bytes to the bound Worker over a
|
|
4
|
+
// Service Binding (no public hop). The downstream still runs the full Web3 authority pipeline
|
|
5
|
+
// (delegation + signature + entitlement + policy); the edge only adds the correlation id it minted.
|
|
6
|
+
// Trusted internal headers were already stripped by `runAdmission` (sanitized `headers`); the edge,
|
|
7
|
+
// being the authenticated boundary, is the one party allowed to set `x-correlation-id`.
|
|
8
|
+
/** Forward an admitted request to a bound origin over its Service Binding, byte-for-byte. */
|
|
9
|
+
export async function dispatchToBinding(fetcher, init) {
|
|
10
|
+
const headers = new Headers(init.headers);
|
|
11
|
+
headers.set('x-correlation-id', init.correlationId);
|
|
12
|
+
const bodyless = init.method === 'GET' || init.method === 'HEAD';
|
|
13
|
+
const req = new Request(init.url, {
|
|
14
|
+
method: init.method,
|
|
15
|
+
headers,
|
|
16
|
+
body: bodyless ? undefined : init.rawBody,
|
|
17
|
+
});
|
|
18
|
+
return fetcher.fetch(req);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,EAAE;AACF,+FAA+F;AAC/F,8FAA8F;AAC9F,oGAAoG;AACpG,oGAAoG;AACpG,wFAAwF;AAiBxF,6FAA6F;AAC7F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAoB,EAAE,IAAkB;IAC9E,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC;IACjE,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,OAAO;QACP,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO;KAC1C,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PACKAGE_NAME, PACKAGE_STATUS, SPEC_REF } from './types.js';
|
|
2
|
+
export type { RateLimiterBinding, FetcherLike } from './types.js';
|
|
3
|
+
export { extractAdmissionRequest } from './request.js';
|
|
4
|
+
export type { ExtractedRequest } from './request.js';
|
|
5
|
+
export { createCloudflareRateLimiter } from './rate-limiter.js';
|
|
6
|
+
export { dispatchToBinding } from './dispatch.js';
|
|
7
|
+
export type { DispatchInit } from './dispatch.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACpE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @agenticprimitives/edge-cloudflare — public API.
|
|
2
|
+
// See ../../specs/288-agentic-edge-admission-and-surface-catalog.md (§5).
|
|
3
|
+
export { PACKAGE_NAME, PACKAGE_STATUS, SPEC_REF } from './types.js';
|
|
4
|
+
export { extractAdmissionRequest } from './request.js';
|
|
5
|
+
export { createCloudflareRateLimiter } from './rate-limiter.js';
|
|
6
|
+
export { dispatchToBinding } from './dispatch.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,0EAA0E;AAE1E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SoftRateLimiter } from '@agenticprimitives/rate-control';
|
|
2
|
+
import type { RateLimiterBinding } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wrap a Cloudflare Workers rate-limiter binding as a `SoftRateLimiter`. The binding's
|
|
5
|
+
* `limit({ key })` returns `{ success }`; we map it to `{ allowed }`. The binding key has limited
|
|
6
|
+
* length, so we namespace + truncate defensively (`profileId:key`). `cost` is advisory — the
|
|
7
|
+
* native binding counts one unit per call.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createCloudflareRateLimiter(binding: RateLimiterBinding): SoftRateLimiter;
|
|
10
|
+
//# sourceMappingURL=rate-limiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../src/rate-limiter.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAQxF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The Workers rate-limiter binding as an edge-runtime `SoftRateLimiter` (Stage-1 abuse only).
|
|
2
|
+
//
|
|
3
|
+
// This is the local, permissive, eventually-consistent abuse control (spec 288 §5 / spec 290 §4):
|
|
4
|
+
// it buckets by an OPAQUE key (IP+op / request-hash+op / token-hash+op — never a claimed SA) and is
|
|
5
|
+
// FAIL-SOFT — `runAdmission` treats a limiter error as allow, because admission must not become a
|
|
6
|
+
// hard dependency on the abuse layer. Hard, per-SA budgets are a different surface (a Durable
|
|
7
|
+
// Object HardBudgetStore, spec 290 §7-§8), enforced after authority — never here.
|
|
8
|
+
/**
|
|
9
|
+
* Wrap a Cloudflare Workers rate-limiter binding as a `SoftRateLimiter`. The binding's
|
|
10
|
+
* `limit({ key })` returns `{ success }`; we map it to `{ allowed }`. The binding key has limited
|
|
11
|
+
* length, so we namespace + truncate defensively (`profileId:key`). `cost` is advisory — the
|
|
12
|
+
* native binding counts one unit per call.
|
|
13
|
+
*/
|
|
14
|
+
export function createCloudflareRateLimiter(binding) {
|
|
15
|
+
return {
|
|
16
|
+
async check(input) {
|
|
17
|
+
const key = `${input.profileId}:${input.key}`.slice(0, 200);
|
|
18
|
+
const { success } = await binding.limit({ key });
|
|
19
|
+
return { allowed: success };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=rate-limiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../src/rate-limiter.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,EAAE;AACF,kGAAkG;AAClG,oGAAoG;AACpG,kGAAkG;AAClG,8FAA8F;AAC9F,kFAAkF;AAKlF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA2B;IACrE,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,KAAwD;YAClE,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAC5D,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YACjD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AdmissionRequest } from '@agenticprimitives/edge-runtime';
|
|
2
|
+
export interface ExtractedRequest {
|
|
3
|
+
admission: AdmissionRequest;
|
|
4
|
+
/** The exact body bytes for byte-identical downstream forwarding (undefined for bodyless requests). */
|
|
5
|
+
rawBody?: ArrayBuffer;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Extract an `AdmissionRequest` (+ the raw body for exact forwarding) from a Web `Request`.
|
|
9
|
+
* Reads the body once; safe for GET/HEAD (no body). The client IP is `cf-connecting-ip` — a
|
|
10
|
+
* pre-verification bucket key only, never trusted as authority.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractAdmissionRequest(request: Request): Promise<ExtractedRequest>;
|
|
13
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,uGAAuG;IACvG,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAWD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgBzF"}
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Map a Web `Request` to the runtime-neutral `AdmissionRequest`, preserving the EXACT body bytes.
|
|
2
|
+
//
|
|
3
|
+
// The body is read ONCE here as an ArrayBuffer: `bodyBytes` is its byteLength, `bodyText` is the
|
|
4
|
+
// UTF-8 decode (for the admission JSON depth/envelope checks), and the SAME ArrayBuffer is returned
|
|
5
|
+
// as `rawBody` so the dispatcher forwards byte-identical bytes downstream — the native pipeline
|
|
6
|
+
// re-hashes them (spec 287 / hashA2aMessage), so a re-serialize would break the proof.
|
|
7
|
+
/** Lowercased header map (the runtime contract: `AdmissionRequest.headers` keys are lowercased). */
|
|
8
|
+
function lowercaseHeaders(h) {
|
|
9
|
+
const out = {};
|
|
10
|
+
h.forEach((value, key) => {
|
|
11
|
+
out[key.toLowerCase()] = value;
|
|
12
|
+
});
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Extract an `AdmissionRequest` (+ the raw body for exact forwarding) from a Web `Request`.
|
|
17
|
+
* Reads the body once; safe for GET/HEAD (no body). The client IP is `cf-connecting-ip` — a
|
|
18
|
+
* pre-verification bucket key only, never trusted as authority.
|
|
19
|
+
*/
|
|
20
|
+
export async function extractAdmissionRequest(request) {
|
|
21
|
+
const url = new URL(request.url);
|
|
22
|
+
const headers = lowercaseHeaders(request.headers);
|
|
23
|
+
const hasBody = request.method !== 'GET' && request.method !== 'HEAD';
|
|
24
|
+
const rawBody = hasBody ? await request.arrayBuffer() : undefined;
|
|
25
|
+
const bodyText = rawBody && rawBody.byteLength > 0 ? new TextDecoder().decode(rawBody) : undefined;
|
|
26
|
+
const admission = {
|
|
27
|
+
method: request.method,
|
|
28
|
+
path: url.pathname,
|
|
29
|
+
headers,
|
|
30
|
+
ip: headers['cf-connecting-ip'],
|
|
31
|
+
bodyBytes: rawBody ? rawBody.byteLength : 0,
|
|
32
|
+
bodyText,
|
|
33
|
+
};
|
|
34
|
+
return { admission, rawBody };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,EAAE;AACF,iGAAiG;AACjG,oGAAoG;AACpG,gGAAgG;AAChG,uFAAuF;AAUvF,oGAAoG;AACpG,SAAS,gBAAgB,CAAC,CAAU;IAClC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACvB,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;IACjC,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAAgB;IAC5D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,KAAK,KAAK,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC;IACtE,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnG,MAAM,SAAS,GAAqB;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,IAAI,EAAE,GAAG,CAAC,QAAQ;QAClB,OAAO;QACP,EAAE,EAAE,OAAO,CAAC,kBAAkB,CAAC;QAC/B,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3C,QAAQ;KACT,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAChC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const PACKAGE_NAME: "@agenticprimitives/edge-cloudflare";
|
|
2
|
+
export declare const PACKAGE_STATUS: "w1-adapter";
|
|
3
|
+
export declare const SPEC_REF: "specs/288-agentic-edge-admission-and-surface-catalog.md";
|
|
4
|
+
/**
|
|
5
|
+
* The Cloudflare Workers rate-limiting binding (`env.<NAME>.limit`). Declared structurally so the
|
|
6
|
+
* package carries no platform type dependency — the deployed Worker supplies the real binding.
|
|
7
|
+
*/
|
|
8
|
+
export interface RateLimiterBinding {
|
|
9
|
+
limit(options: {
|
|
10
|
+
key: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
success: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A Service Binding / Fetcher (`env.<NAME>.fetch`) — the private origin (demo-a2a / demo-mcp) the
|
|
17
|
+
* edge dispatches to. Structural so no platform types are imported.
|
|
18
|
+
*/
|
|
19
|
+
export interface FetcherLike {
|
|
20
|
+
fetch(request: Request): Promise<Response>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,EAAG,oCAA6C,CAAC;AAC1E,eAAO,MAAM,cAAc,EAAG,YAAqB,CAAC;AACpD,eAAO,MAAM,QAAQ,EAAG,yDAAkE,CAAC;AAE3F;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAChE;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5C"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @agenticprimitives/edge-cloudflare — the Cloudflare adapter for edge-runtime (spec 288 §5).
|
|
2
|
+
//
|
|
3
|
+
// Implements the platform bits the vendor-neutral admission core can't: mapping a Web `Request`
|
|
4
|
+
// to the runtime's `AdmissionRequest` (preserving the exact body bytes the native pipeline
|
|
5
|
+
// re-hashes for spec 287 / hashA2aMessage), the Workers rate-limiter binding as a `SoftRateLimiter`
|
|
6
|
+
// (Stage-1 abuse only — local, permissive, eventually-consistent), and Service-Binding dispatch to
|
|
7
|
+
// the private A2A/MCP origins. It owns NO authority (ADR-0043) — it only shuttles bytes.
|
|
8
|
+
export const PACKAGE_NAME = '@agenticprimitives/edge-cloudflare';
|
|
9
|
+
export const PACKAGE_STATUS = 'w1-adapter';
|
|
10
|
+
export const SPEC_REF = 'specs/288-agentic-edge-admission-and-surface-catalog.md';
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,EAAE;AACF,gGAAgG;AAChG,2FAA2F;AAC3F,oGAAoG;AACpG,mGAAmG;AACnG,yFAAyF;AAEzF,MAAM,CAAC,MAAM,YAAY,GAAG,oCAA6C,CAAC;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG,YAAqB,CAAC;AACpD,MAAM,CAAC,MAAM,QAAQ,GAAG,yDAAkE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agenticprimitives/edge-cloudflare",
|
|
3
|
+
"version": "0.0.0-alpha.1",
|
|
4
|
+
"description": "Cloudflare adapter for @agenticprimitives/edge-runtime: Request→AdmissionRequest extraction (exact-byte preserving), the Workers rate-limiter binding as a SoftRateLimiter, and Service-Binding dispatch. Imports the platform runtime; the edge core never does.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
|
|
9
|
+
"directory": "packages/edge-cloudflare"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/agentictrustlabs/agenticprimitives/tree/master/packages/edge-cloudflare",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/agentictrustlabs/agenticprimitives/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"dist",
|
|
27
|
+
"spec.md",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@agenticprimitives/surface-catalog": "0.0.0-alpha.1",
|
|
35
|
+
"@agenticprimitives/rate-control": "0.0.0-alpha.1",
|
|
36
|
+
"@agenticprimitives/edge-runtime": "0.0.0-alpha.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"vitest": "^4.1.8",
|
|
40
|
+
"@agenticprimitives/surface-catalog": "0.0.0-alpha.1",
|
|
41
|
+
"@agenticprimitives/edge-runtime": "0.0.0-alpha.1",
|
|
42
|
+
"@agenticprimitives/rate-control": "0.0.0-alpha.1"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"agentic",
|
|
46
|
+
"primitives",
|
|
47
|
+
"edge",
|
|
48
|
+
"cloudflare",
|
|
49
|
+
"adapter"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc -p tsconfig.build.json",
|
|
53
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"test:unit": "vitest run test/unit --passWithNoTests",
|
|
56
|
+
"test:watch": "vitest",
|
|
57
|
+
"clean": "rm -rf dist"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/spec.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @agenticprimitives/edge-cloudflare — spec
|
|
2
|
+
|
|
3
|
+
The full design lives in
|
|
4
|
+
[`../../specs/288-agentic-edge-admission-and-surface-catalog.md`](../../specs/288-agentic-edge-admission-and-surface-catalog.md)
|
|
5
|
+
(§5), backed by
|
|
6
|
+
[ADR-0043](../../docs/architecture/decisions/0043-edge-owns-admission-never-authority.md).
|
|
7
|
+
|
|
8
|
+
This package is the **Cloudflare adapter** for [`edge-runtime`](../edge-runtime): the vendor-neutral
|
|
9
|
+
admission core (route resolution, header hygiene, size/depth/envelope checks, Stage-1 abuse limits,
|
|
10
|
+
correlation) stays platform-free, and this supplies the three platform bits it can't:
|
|
11
|
+
|
|
12
|
+
1. `extractAdmissionRequest` — map a Web `Request` to the runtime's `AdmissionRequest`, reading the body
|
|
13
|
+
once and returning the exact `rawBody` ArrayBuffer for **byte-identical** downstream forwarding (the
|
|
14
|
+
native pipeline re-hashes it for spec 287 / `hashA2aMessage`).
|
|
15
|
+
2. `createCloudflareRateLimiter` — the Workers rate-limiter binding (`env.<NAME>.limit`) as a fail-soft
|
|
16
|
+
`SoftRateLimiter` for Stage-1 abuse control (opaque buckets, never a claimed SA).
|
|
17
|
+
3. `dispatchToBinding` — Service-Binding dispatch of the admitted bytes to the private A2A/MCP origin,
|
|
18
|
+
setting the edge-minted `x-correlation-id`.
|
|
19
|
+
|
|
20
|
+
Platform binding types are structural (`RateLimiterBinding`, `FetcherLike`) so the package carries no
|
|
21
|
+
platform type dependency. It owns **no authority** (ADR-0043): `delegation`/`mcp-runtime`/`tool-policy`/
|
|
22
|
+
`entitlements`/`key-authorization`/`a2a` are forbidden imports — the downstream origin runs the full Web3
|
|
23
|
+
pipeline; the edge only admits + shuttles bytes.
|
|
24
|
+
|
|
25
|
+
Status: `w1-adapter` — request extraction + the rate-limiter binding + Service-Binding dispatch. Later:
|
|
26
|
+
the default Service-Binding-identity `GatewayAssertion` issuer (§4) and route lockdown (§6, an
|
|
27
|
+
`apps/demo-edge` concern, gated + sequenced last).
|