agentrail-edge 0.3.1 → 0.4.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.
- package/README.md +6 -0
- package/dist/edge.js +38 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,6 +17,12 @@ wrote, lower-cased, without those your platform or a proxy added on the way
|
|
|
17
17
|
(`cf-*`, `x-vercel-*`, `x-forwarded-*` and the like), at most 40 in 512
|
|
18
18
|
characters.
|
|
19
19
|
|
|
20
|
+
A request from a CLI that uses
|
|
21
|
+
[`agentrail-cli-sdk`](https://www.npmjs.com/package/agentrail-cli-sdk) says
|
|
22
|
+
which command an agent ran, in which run and session. The edge records it
|
|
23
|
+
on the request's step, with the session as a keyed hash in place of the
|
|
24
|
+
visit cookie a CLI never sends back, and passes the header on to your origin.
|
|
25
|
+
|
|
20
26
|
## Install
|
|
21
27
|
|
|
22
28
|
```sh
|
package/dist/edge.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCollector, TRACE_HANDOFF_HEADER, signTraceHandoff, traceHandoffTarget, createSignatureVerifier, formatTraceparent, hashKeyIdOf, keyedHash, newSessionId, newSpanId, newTraceId, parseMarker, parseTraceparent, sessionCookie, VERSION, } from 'agentrail-core';
|
|
1
|
+
import { CLI_HEADER, createCollector, readCliHeader, TRACE_HANDOFF_HEADER, signTraceHandoff, traceHandoffTarget, createSignatureVerifier, formatTraceparent, hashKeyIdOf, keyedHash, newSessionId, newSpanId, newTraceId, parseMarker, parseTraceparent, sessionCookie, VERSION, } from 'agentrail-core';
|
|
2
2
|
import { MARKER_PARAMETER, markLinks } from './links.js';
|
|
3
3
|
/**
|
|
4
4
|
* The edge adapter: in front of a customer's site, on the Fetch API, it
|
|
@@ -37,6 +37,8 @@ const MARKABLE_BYTES = 2 * 1024 * 1024;
|
|
|
37
37
|
* `identify`.
|
|
38
38
|
*/
|
|
39
39
|
const SEND_WITHIN_MS = 25_000;
|
|
40
|
+
/** A CLI's session ends with its UTC day, as the collector keys an MCP session's. */
|
|
41
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
40
42
|
/** The longest `Accept` the collector takes; a longer one is cut. */
|
|
41
43
|
const ACCEPT_LENGTH = 256;
|
|
42
44
|
/** The longest `Accept-Encoding` the collector takes; a longer one is cut. */
|
|
@@ -283,6 +285,35 @@ export function createEdge(options) {
|
|
|
283
285
|
headers,
|
|
284
286
|
});
|
|
285
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* What a customer's CLI said of itself (`x-agentrail-cli`, written by
|
|
290
|
+
* agentrail-cli-sdk), and the session it named: the keyed hash of its
|
|
291
|
+
* session and the UTC day the request started, in place of the visit
|
|
292
|
+
* cookie a CLI never sends back. Null for a request with no header that
|
|
293
|
+
* reads.
|
|
294
|
+
*/
|
|
295
|
+
async function cliOf(request, start) {
|
|
296
|
+
const header = readCliHeader(request.headers.get(CLI_HEADER));
|
|
297
|
+
if (header === null)
|
|
298
|
+
return null;
|
|
299
|
+
const hash = await keyedHash(hashKey, header.session);
|
|
300
|
+
return {
|
|
301
|
+
facts: {
|
|
302
|
+
name: header.cli,
|
|
303
|
+
version: header.cliVersion ?? null,
|
|
304
|
+
command: header.command ?? null,
|
|
305
|
+
run: header.run,
|
|
306
|
+
sequence: header.sequence,
|
|
307
|
+
mode: header.mode,
|
|
308
|
+
sessionFrom: header.sessionFrom,
|
|
309
|
+
agent: header.agent ?? null,
|
|
310
|
+
agentVersion: header.agentVersion ?? null,
|
|
311
|
+
evidence: header.evidence ?? [],
|
|
312
|
+
sdkVersion: header.sdkVersion,
|
|
313
|
+
},
|
|
314
|
+
session: `cli:${hash}:${String(Math.floor(start / DAY_MS))}`,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
286
317
|
async function eventOf(input) {
|
|
287
318
|
const { request, url, observed } = input;
|
|
288
319
|
// With its port, as a link to it is recorded.
|
|
@@ -292,6 +323,7 @@ export function createEdge(options) {
|
|
|
292
323
|
const principal = await principalOf(request);
|
|
293
324
|
const actingUserId = principal?.actingUserId ?? null;
|
|
294
325
|
const signature = await verify(request);
|
|
326
|
+
const cli = await cliOf(request, input.start);
|
|
295
327
|
const { signals } = input;
|
|
296
328
|
return {
|
|
297
329
|
schemaVersion: 1,
|
|
@@ -315,7 +347,7 @@ export function createEdge(options) {
|
|
|
315
347
|
subtreeSpanIds: [],
|
|
316
348
|
links: input.caller === null ? [] : [input.caller],
|
|
317
349
|
},
|
|
318
|
-
session: { id: input.session, previousId: null },
|
|
350
|
+
session: { id: cli?.session ?? input.session, previousId: null },
|
|
319
351
|
http: {
|
|
320
352
|
method: request.method,
|
|
321
353
|
host,
|
|
@@ -371,6 +403,7 @@ export function createEdge(options) {
|
|
|
371
403
|
: await keyedHash(hashKey, actingUserId),
|
|
372
404
|
},
|
|
373
405
|
registration: null,
|
|
406
|
+
...(cli === null ? {} : { cli: cli.facts }),
|
|
374
407
|
markers: {
|
|
375
408
|
served: observed.served === null
|
|
376
409
|
? []
|
|
@@ -384,6 +417,9 @@ export function createEdge(options) {
|
|
|
384
417
|
...(principal === null
|
|
385
418
|
? []
|
|
386
419
|
: [{ field: 'principal.id', reason: 'keyed_hash' }]),
|
|
420
|
+
...(cli === null
|
|
421
|
+
? []
|
|
422
|
+
: [{ field: 'session.id', reason: 'keyed_hash' }]),
|
|
387
423
|
...(dropped
|
|
388
424
|
? [{ field: 'http.path', reason: 'query_outside_allowlist' }]
|
|
389
425
|
: []),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentrail-edge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The Agentrail edge: in front of a site on Cloudflare Workers, Vercel or any Fetch API runtime, it records each request and marks the links agents follow.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"node": ">=22"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"agentrail-core": "0.
|
|
28
|
+
"agentrail-core": "0.4.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "24.13.3",
|