@cotal-ai/web 0.170.0 → 0.171.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/dist/web-request.d.ts +166 -0
- package/dist/web-request.d.ts.map +1 -0
- package/dist/web-request.js +276 -0
- package/dist/web-request.js.map +1 -0
- package/dist/web.d.ts +2 -130
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +3 -273
- package/dist/web.js.map +1 -1
- package/package.json +3 -3
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAgB,KAAK,eAAe,EAAuB,MAAM,WAAW,CAAC;AAKpF,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAgB,KAAK,eAAe,EAAuB,MAAM,WAAW,CAAC;AAKpF,OAAO,EACL,aAAa,EAeb,KAAK,YAAY,EAGjB,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAoBL,KAAK,UAAU,EACf,KAAK,YAAY,EAGjB,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAiB7B,OAAO,EACL,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAI1B;;;+DAG+D;AAC/D,eAAO,MAAM,QAAQ,OAAO,CAAC;AAC7B,eAAO,MAAM,QAAQ,cAAc,CAAC;AACpC,eAAO,MAAM,OAAO,iCAAwC,CAAC;AAG7D;;wCAEwC;AACxC,eAAO,MAAM,eAAe,o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AAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC5F,OAAO,CAAC,UAAU,CAAC,CAkDrB;AAED,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAY9F;AAWD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAYpE;AAID;wGACwG;AACxG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAsBlE;AAaD,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGzD;AA+ED;sGACsG;AACtG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAa7C"}
|
package/dist/web.js
CHANGED
|
@@ -4,8 +4,10 @@ import { createServer } from "node:http";
|
|
|
4
4
|
import { closeSync, existsSync, fstatSync, openSync, readdirSync, readFileSync, readSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { basename, dirname, extname, join } from "node:path";
|
|
7
|
-
import { CotalEndpoint,
|
|
7
|
+
import { CotalEndpoint, eventChannel, isEventChannel, isPermissionDenied, spacePrefix, credsClaims, mintCreds, mintLifecycleUid, newIdentity, clearChannel, hardenPrivate, mentionsIn, openPrivateAppend, writePrivateRecord, } from "@cotal-ai/core";
|
|
8
8
|
import { c, connectOrExit, inputDisabledByFlag, localProcessPath, parsePid, probeLiveness, probeWebReadiness, webBoundUrl as boundUrl, readPidfile, readWebSession, removePidPair, userViewAuth, userViewAuthOrExit, WEB_PIDFILE, WEB_READINESS_HEADER, WEB_READINESS_PATH, WEB_SESSION_FILE, writeIdentityPin, } from "@cotal-ai/workspace";
|
|
9
|
+
import { BadRequest, PayloadTooLarge, BodyDeadlineExceeded, BrokerRefused, MAX_BODY_BYTES, DELETE_BODY_DEADLINE_MS, BODY_ROUTES, quoteForOperator, escapeForOperator, channelNameFromPath, canonicalChannel, historyLimit, agentIdFromPath, classifyTap, } from "./web-request.js";
|
|
10
|
+
export { BadRequest, BrokerRefused, quoteForOperator, MAX_HISTORY_LIMIT, agentIdFromPath, classifyTap, } from "./web-request.js";
|
|
9
11
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
10
12
|
/** The dashboard's default port and its branded address. The server binds loopback
|
|
11
13
|
* (127.0.0.1) but serves any Host, so `cotal.localhost` — which Chrome/Firefox/Edge
|
|
@@ -397,278 +399,6 @@ function deadline(ms) {
|
|
|
397
399
|
async function within(p, until) {
|
|
398
400
|
return Promise.race([p, until]);
|
|
399
401
|
}
|
|
400
|
-
/** A request the CALLER got wrong, so the frame answers 400 rather than the 500 it gives a server
|
|
401
|
-
* fault. Without this every malformed query reads, in the log and in the body, exactly like the
|
|
402
|
-
* dashboard breaking. */
|
|
403
|
-
export class BadRequest extends Error {
|
|
404
|
-
}
|
|
405
|
-
/** A body the caller sent that this server declines to READ, which is a different fact from a body
|
|
406
|
-
* it read and disliked, and carries its own status. Deliberately NOT a `BadRequest`: 400 says
|
|
407
|
-
* "what you sent is wrong", 413 says "I stopped before finding out", and a caller that retries on
|
|
408
|
-
* 400 by fixing its payload would loop forever on a size it never learns is the problem. */
|
|
409
|
-
export class PayloadTooLarge extends Error {
|
|
410
|
-
}
|
|
411
|
-
/** A delete upload that did not finish within its total body deadline. */
|
|
412
|
-
class BodyDeadlineExceeded extends Error {
|
|
413
|
-
}
|
|
414
|
-
/** A post the broker, or the operator's connection to it, refused. Neither the caller's fault nor
|
|
415
|
-
* this server's, so the frame answers 502 with the broker's own message, escaped by
|
|
416
|
-
* {@link escapeForOperator}. */
|
|
417
|
-
export class BrokerRefused extends Error {
|
|
418
|
-
}
|
|
419
|
-
/** The most a request body may weigh before a body route refuses to keep reading it.
|
|
420
|
-
*
|
|
421
|
-
* The delete route's body has one field, a channel name, and `assertValidChannel` bounds a usable
|
|
422
|
-
* name to dotted `[A-Za-z0-9_-]` segments that the wire will carry as a subject. The dashboard's
|
|
423
|
-
* own delete sends about sixty bytes. 8 KiB is therefore not a guess at a working size, it is two
|
|
424
|
-
* orders of magnitude ABOVE any name the broker would accept, chosen so that no legitimate
|
|
425
|
-
* caller can meet it and an abusive one meets it immediately. The send route shares the cap, so a
|
|
426
|
-
* post's text is bounded by it too.
|
|
427
|
-
*
|
|
428
|
-
* MEASURED, before this existed, against the shipped route over a local broker with a raw socket
|
|
429
|
-
* rather than `fetch`, because `fetch` hides how much of the body actually left the client:
|
|
430
|
-
* 30,000,000 bytes posted -> ALL 30,000,000 sent, 70,000,144 bytes of refusal returned,
|
|
431
|
-
* peak RSS +1.39 GB, 1022 ms. The read was unbounded and ran to completion before the route
|
|
432
|
-
* formed an opinion, so the refusal was the expensive part rather than the cheap one. */
|
|
433
|
-
const MAX_BODY_BYTES = 8 * 1024;
|
|
434
|
-
const DELETE_BODY_DEADLINE_MS = 10_000;
|
|
435
|
-
/** The only routes that read a request body. Every other route refuses an announced body. */
|
|
436
|
-
const BODY_ROUTES = new Set(["/api/channel/delete", "/api/send"]);
|
|
437
|
-
/** Codepoints `JSON.stringify` leaves RAW that PRODUCE NO GLYPH OF THEIR OWN, or that reorder the
|
|
438
|
-
* text around them, stated as Unicode PROPERTIES rather than as a hand list. That wording is
|
|
439
|
-
* narrower than "change what a reader sees" on purpose, and the narrowing is a review finding:
|
|
440
|
-
* the looser phrase admits every combining mark, and the paragraph at the end of this comment is
|
|
441
|
-
* why escaping those would be this issue pointed the other way. The first version of this WAS a hand list, and review
|
|
442
|
-
* found it missing U+061C, U+2060, the variation selectors and the tag characters, every one of
|
|
443
|
-
* which is exactly the thing the list said it closed. A list is a claim about a set nobody
|
|
444
|
-
* maintains; the property IS the set, and it moves with the Unicode version the runtime carries.
|
|
445
|
-
*
|
|
446
|
-
* Two properties, because neither contains the other and both name the same harm from a different
|
|
447
|
-
* side. `Default_Ignorable_Code_Point` is the renders-as-nothing family: the soft hyphen, the
|
|
448
|
-
* zero-width characters, the word joiner, the variation selectors, the tag characters and the BOM.
|
|
449
|
-
* `Cf` is the format family: characters with no glyph of their own that change how the text around
|
|
450
|
-
* them is read, which is where the interlinear annotation controls U+FFF9 to U+FFFB live. Review
|
|
451
|
-
* found those three arriving raw against a class that had only the first property, and they are the
|
|
452
|
-
* clearest case of the harm: they mark a span as base text plus its gloss, so a reader whose
|
|
453
|
-
* terminal does not implement them sees the two runs concatenated into a sentence nobody wrote.
|
|
454
|
-
* Measured, the second property adds 32 codepoints and not one of them is a letter or a digit.
|
|
455
|
-
*
|
|
456
|
-
* `Bidi_Control` is deliberately absent: measured on this runtime, all twelve of its codepoints,
|
|
457
|
-
* U+061C and the isolates included, are already default-ignorable, so naming it would be a second
|
|
458
|
-
* name for one set. The suite pins those twelve by hand, so a Unicode version that separated them
|
|
459
|
-
* goes red rather than quietly leaving a reordering character raw.
|
|
460
|
-
*
|
|
461
|
-
* What no property covers is DEL and the C1 controls, which are `Cc`, and U+2028/U+2029, which are
|
|
462
|
-
* line and paragraph separators, so those are named. C0 is absent because `JSON.stringify` already
|
|
463
|
-
* escapes all of it.
|
|
464
|
-
*
|
|
465
|
-
* NOT IN THIS CLASS, and deliberately: a VISIBLE character that merely resembles another. A Cyrillic
|
|
466
|
-
* small a is a letter, it renders as itself, and escaping it would make a refusal about a name a
|
|
467
|
-
* human typed unreadable, which is this issue pointed the other way. Confusables are a different
|
|
468
|
-
* problem with a different answer, and quoting for a human to read is not it.
|
|
469
|
-
*
|
|
470
|
-
* NOT IN THIS CLASS EITHER, and this one review reached by finding U+0338 COMBINING LONG SOLIDUS
|
|
471
|
-
* OVERLAY arriving raw and asking whether it belonged: a COMBINING MARK. It produces a visible
|
|
472
|
-
* mark on a visible base, and the property that carries it, `gc=Mn`, is the same one carrying the
|
|
473
|
-
* acute accent in a name written in NFD, the Devanagari vowel signs, the Arabic and Hebrew points
|
|
474
|
-
* and the Vietnamese tones. Measured on this runtime, marks are 2543 codepoints and only 263 of
|
|
475
|
-
* them are already in the class, so escaping them would take about 2280 codepoints of ordinary
|
|
476
|
-
* written language and render an accented name as its escapes. A mark CAN build a confusable
|
|
477
|
-
* (U+0338 over `=` renders as a not-equals sign, so a quoted `a=b` can display as `a` not-equals
|
|
478
|
-
* `b`), which is a real harm and the same one the paragraph above declines: it is unbounded, it
|
|
479
|
-
* needs no combining mark to exist, and its answer is normalization or confusable detection
|
|
480
|
-
* rather than making every script that writes with marks unreadable. The suite asserts both
|
|
481
|
-
* exclusions rather than only describing them. */
|
|
482
|
-
const INVISIBLE_AFTER_JSON = /[\p{Default_Ignorable_Code_Point}\p{gc=Cf}\u007f-\u009f\u2028\u2029]/gu;
|
|
483
|
-
/** QUOTE A CALLER'S OWN VALUE SO AN OPERATOR CAN READ IT.
|
|
484
|
-
*
|
|
485
|
-
* `JSON.stringify` was doing two jobs at every site below and only claims one of them. It builds
|
|
486
|
-
* valid JSON, and on the way it escapes every C0 control, so `ESC` arrives as the six characters
|
|
487
|
-
* `\u001b` and a newline as `\n`. It is not a renderer for humans and never said it was: DEL, the
|
|
488
|
-
* C1 range, `U+2028`/`U+2029`, the bidi controls and the zero-width characters are all valid JSON
|
|
489
|
-
* string content and pass through untouched.
|
|
490
|
-
*
|
|
491
|
-
* MEASURED against the shipped `web()` entry before this existed, driving `/api/activity?limit=`
|
|
492
|
-
* with each codepoint percent-encoded and reading the answer as BYTES rather than through a JSON
|
|
493
|
-
* parse (a parse decodes the very thing under test and hands the input back whatever the server
|
|
494
|
-
* wrote). Six of eight arrived raw in BOTH the 400 body and the operator's stderr line: DEL,
|
|
495
|
-
* `U+0085`, `U+009B`, `U+202E`, `U+2028`, `U+2029`. `ESC` and `LF` came back escaped, which is
|
|
496
|
-
* what makes the other six a finding rather than a property of the harness.
|
|
497
|
-
*
|
|
498
|
-
* The escape is emitted as `\uXXXX`, so the message stays valid JSON on the body path and reads as
|
|
499
|
-
* the codepoint it is on the terminal path. Applied where the value is QUOTED rather than where it
|
|
500
|
-
* is written out, because the untrusted thing is the value and the message is derived from it: a
|
|
501
|
-
* guard at the two exits fences those two exits, while a guard here travels with the sentence.
|
|
502
|
-
*
|
|
503
|
-
* The loop below is per UTF-16 UNIT, not per codepoint: `u` hands the callback a whole codepoint,
|
|
504
|
-
* so an astral one (a tag character, a musical control) arrives as its surrogate pair and has to
|
|
505
|
-
* leave as two escapes. `\u1d173` is not a JSON escape, and a body carrying it would stop parsing
|
|
506
|
-
* for the caller who asked what was wrong with their request. */
|
|
507
|
-
export function quoteForOperator(value) {
|
|
508
|
-
return JSON.stringify(value).replace(INVISIBLE_AFTER_JSON, (ch) => {
|
|
509
|
-
let out = "";
|
|
510
|
-
for (let i = 0; i < ch.length; i++)
|
|
511
|
-
out += "\\u" + ch.charCodeAt(i).toString(16).padStart(4, "0");
|
|
512
|
-
return out;
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
/** Every codepoint {@link quoteForOperator} escapes, the C0 controls included, without its quotes. */
|
|
516
|
-
const UNREADABLE = new RegExp(`[\\u0000-\\u001f]|${INVISIBLE_AFTER_JSON.source}`, "gu");
|
|
517
|
-
/** Escapes a message someone else wrote, keeping its wording. A broker refusal names the subject it
|
|
518
|
-
* refused, and a DM subject carries a recipient id taken from another agent's presence card, so the
|
|
519
|
-
* message reaches the 502 body and the operator's line as untrusted text. Each codepoint the quoter
|
|
520
|
-
* escapes leaves as its escape; the rest, quotes included, stays as the broker wrote it. */
|
|
521
|
-
export function escapeForOperator(text) {
|
|
522
|
-
return text.replace(UNREADABLE, (ch) => quoteForOperator(ch).slice(1, -1));
|
|
523
|
-
}
|
|
524
|
-
/** The channel name out of the path. A percent escape the decoder cannot read is the caller having
|
|
525
|
-
* typed a bad one, so it is refused as a bad request like any other malformed input. Left as a
|
|
526
|
-
* bare `URIError` it reached the request frame unrecognised and was reported as a server fault,
|
|
527
|
-
* which is the one thing the 400/500 split exists to prevent. */
|
|
528
|
-
export function channelNameFromPath(raw) {
|
|
529
|
-
let name;
|
|
530
|
-
try {
|
|
531
|
-
name = decodeURIComponent(raw);
|
|
532
|
-
}
|
|
533
|
-
catch {
|
|
534
|
-
throw new BadRequest(`channel name ${quoteForOperator(raw)} is not valid percent-encoded text`);
|
|
535
|
-
}
|
|
536
|
-
return canonicalChannel(name);
|
|
537
|
-
}
|
|
538
|
-
/** A caller's channel name, refused unless it is ALREADY the name the wire uses.
|
|
539
|
-
*
|
|
540
|
-
* The wire builds a channel's subject through `token()`, which rewrites anything outside
|
|
541
|
-
* `[A-Za-z0-9_-]` to `_` rather than refusing it, so a name a caller invented and a real channel
|
|
542
|
-
* collide: `abc` + U+202E and `abc_` are one channel on the wire while the dashboard answers with
|
|
543
|
-
* whichever the caller typed. Measured against the shipped routes on a local broker before this
|
|
544
|
-
* existed, with one message seeded on `abc_`: the history read under the first name returned the
|
|
545
|
-
* second's message, and the delete route purged the second while answering
|
|
546
|
-
* `{"ok":true,"channel":"abc<U+202E>","purged":1}`. Rendering that answer readably would have made
|
|
547
|
-
* the lie legible without removing it, which is why this refuses the name instead.
|
|
548
|
-
*
|
|
549
|
-
* Core already owns the rule, written for the same aliasing gap on the ACL side; the dashboard
|
|
550
|
-
* simply never asked it. Its message is rebuilt here rather than passed through, because core
|
|
551
|
-
* quotes the raw name with `JSON.stringify` and this route is the one place that must not. */
|
|
552
|
-
function canonicalChannel(name) {
|
|
553
|
-
try {
|
|
554
|
-
return assertValidChannel(name);
|
|
555
|
-
}
|
|
556
|
-
catch {
|
|
557
|
-
throw new BadRequest(`channel name ${quoteForOperator(name)} is not a channel: dotted segments of [A-Za-z0-9_-], ` +
|
|
558
|
-
`and a name the wire would rewrite would address a different channel than it names`);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
/** The most messages one read may ask for. A route reads up to `limit` messages and holds them all
|
|
562
|
-
* before it answers, so a limit with no ceiling lets one request make the server read a stream's
|
|
563
|
-
* whole retained history. The dashboard asks for at most 500. */
|
|
564
|
-
export const MAX_HISTORY_LIMIT = 2000;
|
|
565
|
-
/** The `limit` out of the query. The ceiling refusal is reachable only through the digits-only test
|
|
566
|
-
* above it, so its value cannot carry anything the quoter would escape today. It quotes anyway:
|
|
567
|
-
* the guarantee that a refusal renders its input unambiguously should hold because the quoting site
|
|
568
|
-
* holds it, not because a regex two lines up stays exactly as narrow as it is this morning.
|
|
569
|
-
*
|
|
570
|
-
* THE LIMIT, PARSED ONCE, because three routes each re-deriving
|
|
571
|
-
* `query.get("limit") ? Number(...) : N` is how they came to disagree about the same parameter.
|
|
572
|
-
*
|
|
573
|
-
* MEASURED ON THE SHIPPED ROUTES, against a real broker, before this existed:
|
|
574
|
-
* ?limit=abc `Number("abc")` is NaN and every comparison against NaN is false, so core's
|
|
575
|
-
* `limit <= 0` guard does not fire and the widening search's two exits can
|
|
576
|
-
* never be true. No answer after 30s, and the ABANDONED request kept consuming
|
|
577
|
-
* half a core with its caller long gone, invisible because the process keeps
|
|
578
|
-
* serving everything else.
|
|
579
|
-
* ?limit=Infinity passes the same guard, and `slice(-Infinity)` is the whole array: a channel's
|
|
580
|
-
* entire retained history from a one word request. `1e999` is the same value.
|
|
581
|
-
* ?limit=2.5 silently truncated to 2.
|
|
582
|
-
* ?limit=" 5" accepted as 5, because `Number()` trims whitespace.
|
|
583
|
-
*
|
|
584
|
-
* So the accepted form is the narrow one: a plain run of digits no larger than
|
|
585
|
-
* {@link MAX_HISTORY_LIMIT}. `0` keeps
|
|
586
|
-
* meaning zero, which is what it already did and what a caller expects; an absent or empty
|
|
587
|
-
* parameter keeps meaning the route's own default, the one shape the old parse got right.
|
|
588
|
-
*
|
|
589
|
-
* Everything else is REFUSED rather than clamped. A clamp would answer a request nobody made, and
|
|
590
|
-
* the caller who wrote `limit=2.5` would never learn that the page they read was not the page they
|
|
591
|
-
* asked for. */
|
|
592
|
-
export function historyLimit(query, fallback) {
|
|
593
|
-
const raw = query.get("limit");
|
|
594
|
-
if (raw === null || raw === "")
|
|
595
|
-
return fallback;
|
|
596
|
-
if (!/^[0-9]+$/.test(raw))
|
|
597
|
-
throw new BadRequest(`limit must be a whole number of messages, received ${quoteForOperator(raw)}`);
|
|
598
|
-
// The ceiling also covers a run of digits too long for a double to count exactly: every such
|
|
599
|
-
// number is far above it.
|
|
600
|
-
const n = Number(raw);
|
|
601
|
-
if (n > MAX_HISTORY_LIMIT)
|
|
602
|
-
throw new BadRequest(`limit ${quoteForOperator(raw)} is above the most this server reads at once, ${MAX_HISTORY_LIMIT} messages`);
|
|
603
|
-
return n;
|
|
604
|
-
}
|
|
605
|
-
/** An agent id out of a path segment: decoded, and a principal key, or a BadRequest naming it.
|
|
606
|
-
*
|
|
607
|
-
* The id is the roster's `card.id`, which is `principalKey(owner, actor).key` by construction, so
|
|
608
|
-
* the agent is named by its principal and never by a display name: two live agents with one name
|
|
609
|
-
* never share a session. The answer's `id` is rebuilt from the parsed tokens rather than passed
|
|
610
|
-
* through, so the id a route acts on is the one the event channel is formed from. */
|
|
611
|
-
export function agentIdFromPath(raw) {
|
|
612
|
-
let decoded;
|
|
613
|
-
try {
|
|
614
|
-
decoded = decodeURIComponent(raw);
|
|
615
|
-
}
|
|
616
|
-
catch {
|
|
617
|
-
throw new BadRequest(`agent id ${quoteForOperator(raw)} is not valid percent-encoded text`);
|
|
618
|
-
}
|
|
619
|
-
const principal = parsePrincipalKey(decoded);
|
|
620
|
-
if (principal === null)
|
|
621
|
-
throw new BadRequest(`agent id ${quoteForOperator(decoded)} is not an agent id: <owner>.<actor>, each of [A-Za-z0-9_]`);
|
|
622
|
-
return { id: principalKey(principal.owner, principal.actor).key, ...principal };
|
|
623
|
-
}
|
|
624
|
-
/** What the live tap does with one message. A chat message on a principal-shaped event channel is an
|
|
625
|
-
* agent frame for `principalKey(owner, actor).key`; everything else goes out as today's `message`.
|
|
626
|
-
*
|
|
627
|
-
* WHY FRAMES LEAVE THE BROADCAST. The observer taps `chat.>`, and an agent's event channel is a
|
|
628
|
-
* chat channel, so this one subscription receives every agent's frames. A NATS wildcard cannot
|
|
629
|
-
* exclude a sub-tree, so the observer still receives them; what changes is who it forwards them to.
|
|
630
|
-
* Sent as `message` to every browser, each frame cost every open dashboard a write whether or not
|
|
631
|
-
* anyone was reading that agent. As `agent-frame` it reaches only the feeds watching that agent.
|
|
632
|
-
*
|
|
633
|
-
* The agent is the event channel's principal, the same derivation the chat-only filter reads, so a
|
|
634
|
-
* near-miss name such as `events.standup` stays an ordinary `message`. The channel is the one the
|
|
635
|
-
* broker policed, taken from the subject, never the payload's own claim.
|
|
636
|
-
*
|
|
637
|
-
* A FRAME FROM ANYONE BUT THE AGENT IS DROPPED, and dropped rather than sent on as a `message`. The
|
|
638
|
-
* subject's sender is the verified publisher, and a frame is that agent's only when the agent
|
|
639
|
-
* published it. On a mesh where another principal may write the channel (an open mesh, or a grant
|
|
640
|
-
* wider than the agent's own), a forged frame would otherwise read as the agent's session, and
|
|
641
|
-
* falling through to `message` would hand it to every browser instead. */
|
|
642
|
-
export function classifyTap(subject, msg) {
|
|
643
|
-
const parsed = parseSubject(subject);
|
|
644
|
-
if (parsed?.kind === "evp") {
|
|
645
|
-
if (!msg || parsed.sender !== msg.from?.id)
|
|
646
|
-
return null;
|
|
647
|
-
return { event: "agent-frame", agent: parsed.sender, data: { id: parsed.sender, msg } };
|
|
648
|
-
}
|
|
649
|
-
const mode = deliveryOf(subject);
|
|
650
|
-
if (!mode || !msg)
|
|
651
|
-
return null;
|
|
652
|
-
// senderId is the subject's sender token, the *verified* publisher (the server policed who could
|
|
653
|
-
// publish it), vs the advisory `from` in the payload.
|
|
654
|
-
const senderId = parsed?.sender;
|
|
655
|
-
// The channel the broker actually POLICED, taken from the subject rather than the payload: a
|
|
656
|
-
// publish grant is per-channel (`chat.<owner>.<actor>.<ch>`), so this token is covered by the
|
|
657
|
-
// minted grant, while `msg.channel` is publisher-supplied and backed by nothing.
|
|
658
|
-
//
|
|
659
|
-
// Gated on kind, and the gate is load-bearing rather than defensive: `rest` is the channel only
|
|
660
|
-
// on the chat plane. On `inst` it is the RECIPIENT (`subjects.ts:599`) and on `svc` the route
|
|
661
|
-
// (`:603`), so forwarding it ungated would label a DM's recipient as a channel.
|
|
662
|
-
const channel = parsed?.kind === "chat" ? parsed.rest : undefined;
|
|
663
|
-
const agent = channel === undefined ? null : eventChannelPrincipal(channel);
|
|
664
|
-
if (agent !== null) {
|
|
665
|
-
const id = principalKey(agent.owner, agent.actor).key;
|
|
666
|
-
if (senderId !== id)
|
|
667
|
-
return null;
|
|
668
|
-
return { event: "agent-frame", agent: id, data: { id, msg } };
|
|
669
|
-
}
|
|
670
|
-
return { event: "message", data: { mode, senderId, channel, msg } };
|
|
671
|
-
}
|
|
672
402
|
/** The most bytes a feed may have waiting to be sent before the server gives up on it. A browser on
|
|
673
403
|
* a slow link, watching a busy agent, cannot take frames as fast as the tap produces them, and
|
|
674
404
|
* every byte it has not taken waits in this process. Past this the feed is told why and ended, and
|