agentrail-edge 0.3.1 → 0.4.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/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.d.ts CHANGED
@@ -3,8 +3,12 @@ import { type MarkedHosts } from './links.js';
3
3
  /**
4
4
  * The header names no caller writes: what a proxy or the platform added on
5
5
  * the way (Cloudflare's `cf-*`, Vercel's `x-vercel-*`, and the `logs-url` and
6
- * `x-invocation-id` Vercel adds on the way to a function, `x-forwarded-*`),
7
- * and Agentrail's own first-party mark. The contract's
6
+ * `x-invocation-id` Vercel adds on the way to a function, `x-forwarded-*`;
7
+ * the `render-proxy-ttl`, `rndr-id` and `x-request-start` Render's proxy adds
8
+ * on the way to a service, which all 37 MCP steps recorded behind this edge
9
+ * on Render carried, 2026-11-19), the `x-agentrail-trace-handoff` an
10
+ * Agentrail edge adds to the request it forwards (`requestForOrigin`), and
11
+ * Agentrail's own first-party mark. The contract's
8
12
  * (`otlp.headerNames.addedOnTheWay`); the tests hold this copy to it.
9
13
  */
10
14
  export declare const ADDED_ON_THE_WAY: RegExp;
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. */
@@ -44,11 +46,15 @@ const ACCEPT_ENCODING_LENGTH = 128;
44
46
  /**
45
47
  * The header names no caller writes: what a proxy or the platform added on
46
48
  * the way (Cloudflare's `cf-*`, Vercel's `x-vercel-*`, and the `logs-url` and
47
- * `x-invocation-id` Vercel adds on the way to a function, `x-forwarded-*`),
48
- * and Agentrail's own first-party mark. The contract's
49
+ * `x-invocation-id` Vercel adds on the way to a function, `x-forwarded-*`;
50
+ * the `render-proxy-ttl`, `rndr-id` and `x-request-start` Render's proxy adds
51
+ * on the way to a service, which all 37 MCP steps recorded behind this edge
52
+ * on Render carried, 2026-11-19), the `x-agentrail-trace-handoff` an
53
+ * Agentrail edge adds to the request it forwards (`requestForOrigin`), and
54
+ * Agentrail's own first-party mark. The contract's
49
55
  * (`otlp.headerNames.addedOnTheWay`); the tests hold this copy to it.
50
56
  */
51
- export const ADDED_ON_THE_WAY = /^(?:x-forwarded-.*|x-amzn-.*|x-vercel-.*|cf-.*|forwarded|via|x-real-ip|cdn-loop|true-client-ip|logs-url|x-invocation-id|agentrail-first-party)$/iu;
57
+ export const ADDED_ON_THE_WAY = /^(?:x-forwarded-.*|x-amzn-.*|x-vercel-.*|cf-.*|forwarded|via|x-real-ip|cdn-loop|true-client-ip|logs-url|x-invocation-id|render-proxy-ttl|rndr-id|x-request-start|x-agentrail-trace-handoff|agentrail-first-party)$/iu;
52
58
  /** The most header names an event keeps, and the most characters they take joined (`otlp.headerNames`). */
53
59
  export const HEADER_NAMES_KEPT = { count: 40, characters: 512 };
54
60
  /** The longest `Sec-Fetch-*` value the collector takes; the browsers' are one word. */
@@ -283,6 +289,35 @@ export function createEdge(options) {
283
289
  headers,
284
290
  });
285
291
  }
292
+ /**
293
+ * What a customer's CLI said of itself (`x-agentrail-cli`, written by
294
+ * agentrail-cli-sdk), and the session it named: the keyed hash of its
295
+ * session and the UTC day the request started, in place of the visit
296
+ * cookie a CLI never sends back. Null for a request with no header that
297
+ * reads.
298
+ */
299
+ async function cliOf(request, start) {
300
+ const header = readCliHeader(request.headers.get(CLI_HEADER));
301
+ if (header === null)
302
+ return null;
303
+ const hash = await keyedHash(hashKey, header.session);
304
+ return {
305
+ facts: {
306
+ name: header.cli,
307
+ version: header.cliVersion ?? null,
308
+ command: header.command ?? null,
309
+ run: header.run,
310
+ sequence: header.sequence,
311
+ mode: header.mode,
312
+ sessionFrom: header.sessionFrom,
313
+ agent: header.agent ?? null,
314
+ agentVersion: header.agentVersion ?? null,
315
+ evidence: header.evidence ?? [],
316
+ sdkVersion: header.sdkVersion,
317
+ },
318
+ session: `cli:${hash}:${String(Math.floor(start / DAY_MS))}`,
319
+ };
320
+ }
286
321
  async function eventOf(input) {
287
322
  const { request, url, observed } = input;
288
323
  // With its port, as a link to it is recorded.
@@ -292,6 +327,7 @@ export function createEdge(options) {
292
327
  const principal = await principalOf(request);
293
328
  const actingUserId = principal?.actingUserId ?? null;
294
329
  const signature = await verify(request);
330
+ const cli = await cliOf(request, input.start);
295
331
  const { signals } = input;
296
332
  return {
297
333
  schemaVersion: 1,
@@ -315,7 +351,7 @@ export function createEdge(options) {
315
351
  subtreeSpanIds: [],
316
352
  links: input.caller === null ? [] : [input.caller],
317
353
  },
318
- session: { id: input.session, previousId: null },
354
+ session: { id: cli?.session ?? input.session, previousId: null },
319
355
  http: {
320
356
  method: request.method,
321
357
  host,
@@ -371,6 +407,7 @@ export function createEdge(options) {
371
407
  : await keyedHash(hashKey, actingUserId),
372
408
  },
373
409
  registration: null,
410
+ ...(cli === null ? {} : { cli: cli.facts }),
374
411
  markers: {
375
412
  served: observed.served === null
376
413
  ? []
@@ -384,6 +421,9 @@ export function createEdge(options) {
384
421
  ...(principal === null
385
422
  ? []
386
423
  : [{ field: 'principal.id', reason: 'keyed_hash' }]),
424
+ ...(cli === null
425
+ ? []
426
+ : [{ field: 'session.id', reason: 'keyed_hash' }]),
387
427
  ...(dropped
388
428
  ? [{ field: 'http.path', reason: 'query_outside_allowlist' }]
389
429
  : []),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentrail-edge",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
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.3.1"
28
+ "agentrail-core": "0.4.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "24.13.3",