@cotal-ai/web 0.171.0 → 0.171.2
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-post.d.ts +87 -0
- package/dist/web-post.d.ts.map +1 -0
- package/dist/web-post.js +171 -0
- package/dist/web-post.js.map +1 -0
- package/dist/web-read.d.ts +306 -0
- package/dist/web-read.d.ts.map +1 -0
- package/dist/web-read.js +471 -0
- package/dist/web-read.js.map +1 -0
- package/dist/web.d.ts +3 -374
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +8 -632
- package/dist/web.js.map +1 -1
- package/package.json +3 -3
package/dist/web-read.js
ADDED
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
// Read paths, moved verbatim from web.ts: client assets, activity aggregation, the session feed and its
|
|
2
|
+
// watchers, agent events and activity backfill. web.ts re-exports the public names.
|
|
3
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
4
|
+
import { extname, join } from "node:path";
|
|
5
|
+
import { eventChannel, isEventChannel, isPermissionDenied, } from "@cotal-ai/core";
|
|
6
|
+
import { BadRequest, classifyTap } from "./web-request.js";
|
|
7
|
+
/** The one condition name for "the membership read did not answer", shared by the HTTP body and the
|
|
8
|
+
* SSE event so a browser matches ONE token and a test asserts the same token the server emits.
|
|
9
|
+
* Exported so a test asserts the token the server emits rather than a restated copy. */
|
|
10
|
+
export const MEMBERSHIP_READ_FAILED = "membership-read-failed";
|
|
11
|
+
/** Content types for the files a client build contains. A file of any other type is not served,
|
|
12
|
+
* so a stray file dropped into the build directory never becomes a route. */
|
|
13
|
+
const CLIENT_TYPES = {
|
|
14
|
+
".js": "text/javascript; charset=utf-8",
|
|
15
|
+
".css": "text/css; charset=utf-8",
|
|
16
|
+
".woff2": "font/woff2",
|
|
17
|
+
".svg": "image/svg+xml",
|
|
18
|
+
".png": "image/png",
|
|
19
|
+
};
|
|
20
|
+
/** The answer when the client build is missing: the server keeps serving the API and says what to
|
|
21
|
+
* do instead of serving nothing. It speaks to both readers who can meet it: in a source checkout
|
|
22
|
+
* the page has not been built yet, while an installed package always ships its page, so there the
|
|
23
|
+
* install itself is broken. */
|
|
24
|
+
export const CLIENT_NOT_BUILT = "the dashboard client is not built. In a source checkout, run `pnpm --filter @cotal-ai/web build`. " +
|
|
25
|
+
"An installed @cotal-ai/web always ships its client, so this is a broken install: reinstall it with `cotal ext seed --force`.";
|
|
26
|
+
/** The classic script the page loads in its head, before the stylesheet, to put the saved theme on
|
|
27
|
+
* the root element before anything is drawn (`client/src/lib/themeBoot.ts`, written by the build). */
|
|
28
|
+
export const THEME_BOOT = "theme-boot.js";
|
|
29
|
+
/** The client build as an allow-list, read once at startup: the page at `/` (and `/graph`, so an
|
|
30
|
+
* old link opens the app), the theme boot script at `/theme-boot.js`, and the files directly inside
|
|
31
|
+
* `assets/`. Nothing else under `dir` is reachable, and no request path is ever joined onto the
|
|
32
|
+
* filesystem. The boot script's name carries no hash, so unlike the assets it is not cached for good. */
|
|
33
|
+
export function clientAssets(dir) {
|
|
34
|
+
const routes = new Map();
|
|
35
|
+
const index = join(dir, "index.html");
|
|
36
|
+
if (!existsSync(index))
|
|
37
|
+
return routes;
|
|
38
|
+
const page = { path: index, type: "text/html; charset=utf-8", immutable: false };
|
|
39
|
+
routes.set("/", page);
|
|
40
|
+
routes.set("/graph", page);
|
|
41
|
+
const boot = join(dir, THEME_BOOT);
|
|
42
|
+
if (existsSync(boot))
|
|
43
|
+
routes.set(`/${THEME_BOOT}`, { path: boot, type: CLIENT_TYPES[".js"], immutable: false });
|
|
44
|
+
const assets = join(dir, "assets");
|
|
45
|
+
if (!existsSync(assets))
|
|
46
|
+
return routes;
|
|
47
|
+
for (const entry of readdirSync(assets, { withFileTypes: true })) {
|
|
48
|
+
const type = entry.isFile() ? CLIENT_TYPES[extname(entry.name)] : undefined;
|
|
49
|
+
if (type)
|
|
50
|
+
routes.set(`/assets/${entry.name}`, { path: join(assets, entry.name), type, immutable: true });
|
|
51
|
+
}
|
|
52
|
+
return routes;
|
|
53
|
+
}
|
|
54
|
+
/** The answer to a static request: the file when the build has it, a 503 naming the build command
|
|
55
|
+
* when the build is missing and the page is asked for, otherwise a 404. A pure function of the
|
|
56
|
+
* route map and the path, so the 503 is testable without a server. */
|
|
57
|
+
export function clientResponse(routes, path) {
|
|
58
|
+
const file = routes.get(path);
|
|
59
|
+
if (file)
|
|
60
|
+
return { status: 200, file };
|
|
61
|
+
if (routes.size === 0 && (path === "/" || path === "/graph"))
|
|
62
|
+
return { status: 503, body: { error: CLIENT_NOT_BUILT } };
|
|
63
|
+
return { status: 404 };
|
|
64
|
+
}
|
|
65
|
+
/** The channels this dashboard LISTS and BACKFILLS: chat only.
|
|
66
|
+
*
|
|
67
|
+
* WHY AN AGENT'S EVENT CHANNEL IS NOT ONE OF THEM. `listChannels()` derives a row from every
|
|
68
|
+
* retained concrete subject and the chat stream caps per subject rather than by age, so the list
|
|
69
|
+
* grows by one row per agent that has ever run and those rows never age out. Unfiltered, the channel
|
|
70
|
+
* sidebar is buried under machine streams, the client's graph grows a hub node for each, and
|
|
71
|
+
* `/api/activity` merges every event channel into a global top-N that a human reading chat did not
|
|
72
|
+
* ask for, and pays to move those messages across the link first. That is a cost that scales with
|
|
73
|
+
* the number of agents ever run, which is the wrong axis entirely.
|
|
74
|
+
*
|
|
75
|
+
* FILTERED BEFORE THE FETCH, NOT AFTER, AND THE ORDER IS THE CLAIM. Filtering the merged output
|
|
76
|
+
* would still move every byte and then discard it. The activity backfill reads all of chat in
|
|
77
|
+
* ONE stream read, and this classifier decides that read's FILTER SET, so an event channel is
|
|
78
|
+
* dropped by the broker and never crosses the link at all. The console applies the identical rule at
|
|
79
|
+
* the identical point (`mesh-view.ts` filters `listChannels()` before `channelHistory`), and the two
|
|
80
|
+
* surfaces share this classifier rather than each spelling the convention, so they cannot disagree
|
|
81
|
+
* about what a channel is.
|
|
82
|
+
*
|
|
83
|
+
* WHAT IS NOT FILTERED, DELIBERATELY, IN TWO PLACES. The live SSE tap still receives frames, and
|
|
84
|
+
* sends each one as an `agent-frame` only to the feeds watching that agent (see {@link classifyTap}
|
|
85
|
+
* and {@link SessionWatchers}), never as a `message` to every browser and never dropped for a
|
|
86
|
+
* watcher. And `/api/channels/<name>/history` still serves an event channel
|
|
87
|
+
* when a caller names one, because that route answers a question about a channel the caller already
|
|
88
|
+
* identified; a filter there would mean the dashboard could render a frame it could never fetch. */
|
|
89
|
+
export function chatOnly(rows) {
|
|
90
|
+
return rows.filter((row) => !isEventChannel(row.channel));
|
|
91
|
+
}
|
|
92
|
+
/** How long one aggregating request may take before it answers with what it has.
|
|
93
|
+
*
|
|
94
|
+
* WHY A DEADLINE AT ALL, with the measurement that set it. The cost of a history read is the link,
|
|
95
|
+
* not the broker. Against a local broker behind a 160ms-RTT, 128 KiB/s link with 40 channels and
|
|
96
|
+
* 12000 messages, an unbounded aggregation reading one source per channel finished in 125ms for a
|
|
97
|
+
* reader ON the broker host and returned 500 `timeout` after 15.94s for the reader across the link;
|
|
98
|
+
* at a less constrained 256 KiB/s it SUCCEEDED after 34491ms, which is the same defect with a
|
|
99
|
+
* different ending. An unbounded aggregation has no answer for either case.
|
|
100
|
+
*
|
|
101
|
+
* WHY ONE READ FOR ALL OF CHAT STILL NEEDS IT. A bound is not a repair for a read that is too
|
|
102
|
+
* expensive; it is what makes the surface answer at all when a link cannot serve a request in a
|
|
103
|
+
* useful time. Any read across any link can still be too slow, and a page that says what it is
|
|
104
|
+
* missing beats one that never arrives.
|
|
105
|
+
*
|
|
106
|
+
* WHY THIS NUMBER. It is longer than a healthy remote read of this shape and far shorter than a
|
|
107
|
+
* reader will sit in front of a blank panel. It is not tuned to any one link: what makes the surface
|
|
108
|
+
* honest is that it always answers and always says what it left out, not that the bound is
|
|
109
|
+
* optimal. */
|
|
110
|
+
export const AGGREGATION_DEADLINE_MS = 8_000;
|
|
111
|
+
/** How many per-source reads are in flight at once.
|
|
112
|
+
*
|
|
113
|
+
* WHY NOT ALL OF THEM. Every source shares ONE connection to ONE broker, so past the point where
|
|
114
|
+
* the link is saturated extra concurrency buys no throughput: it spreads the same bytes over more
|
|
115
|
+
* unfinished reads, and a read that is 90% done when the deadline fires contributes nothing.
|
|
116
|
+
*
|
|
117
|
+
* THE NUMBER IS MEASURED, NOT PREFERRED, and the measurement includes what it costs. Corpus of 40
|
|
118
|
+
* channels, 12000 chat messages and 2000 DMs at 160ms RTT, sources answered inside the 8000ms
|
|
119
|
+
* deadline, three strategies, each arm on an idle link, one source per channel plus the DMs:
|
|
120
|
+
*
|
|
121
|
+
* link fan out all 41 pool of 8 pool of 1 widening on each completion
|
|
122
|
+
* 1024 KiB/s 1 16 3
|
|
123
|
+
* 512 KiB/s 1 8 3
|
|
124
|
+
* 256 KiB/s 1 0 3
|
|
125
|
+
* 128 KiB/s 1 0 1
|
|
126
|
+
*
|
|
127
|
+
* The fan-out is the worst column at every speed: reading the whole set at once leaves the panel
|
|
128
|
+
* empty rather than short. A pool that starts at one and widens on each completed read was built and
|
|
129
|
+
* measured too, on the reasoning that it would adapt to a link it cannot know; it does not pay,
|
|
130
|
+
* because at a healthy link a single source is round-trip bound rather than throughput bound, so the
|
|
131
|
+
* first completion arrives too late to be useful evidence and the ramp costs more than the
|
|
132
|
+
* adaptation returns.
|
|
133
|
+
*
|
|
134
|
+
* WITH TWO SOURCES IT DOES NOT BIND. The aggregation reads chat and DMs, so the pool never fills
|
|
135
|
+
* and this number chooses nothing for that source list. The bound is on the SHAPE (a cursor the
|
|
136
|
+
* workers pull from) rather than on a source count, so a third or a tenth source is pooled at this
|
|
137
|
+
* width instead of fanned out, the worst column above. */
|
|
138
|
+
export const AGGREGATION_CONCURRENCY = 8;
|
|
139
|
+
/** The sentinel a source resolves to when the deadline beat it. */
|
|
140
|
+
export const LATE = Symbol("late");
|
|
141
|
+
/** A promise that resolves at `ms`, plus the handle to cancel its timer. `unref` alone is not
|
|
142
|
+
* enough: an 8-second timer in a long-lived server would hold a poll's worth of state per request. */
|
|
143
|
+
export function deadline(ms) {
|
|
144
|
+
const controller = new AbortController();
|
|
145
|
+
let timer;
|
|
146
|
+
const until = new Promise((resolve) => {
|
|
147
|
+
timer = setTimeout(() => {
|
|
148
|
+
resolve(LATE);
|
|
149
|
+
controller.abort(new DOMException(`history read deadline exceeded after ${ms}ms`, "AbortError"));
|
|
150
|
+
}, ms);
|
|
151
|
+
timer.unref();
|
|
152
|
+
});
|
|
153
|
+
return { until, signal: controller.signal, done: () => clearTimeout(timer) };
|
|
154
|
+
}
|
|
155
|
+
/** Race one source against the request's deadline. History sources receive the deadline signal, so
|
|
156
|
+
* a late JetStream read stops its pull iterator and deletes its ephemeral consumer instead of keeping
|
|
157
|
+
* the shared link busy after this response has moved on. */
|
|
158
|
+
export async function within(p, until) {
|
|
159
|
+
return Promise.race([p, until]);
|
|
160
|
+
}
|
|
161
|
+
/** The most bytes a feed may have waiting to be sent before the server gives up on it. A browser on
|
|
162
|
+
* a slow link, watching a busy agent, cannot take frames as fast as the tap produces them, and
|
|
163
|
+
* every byte it has not taken waits in this process. Past this the feed is told why and ended, and
|
|
164
|
+
* the browser's own reconnect opens a fresh one, watches again and reads the gap from history. */
|
|
165
|
+
const MAX_FEED_BUFFER_BYTES = 1_048_576;
|
|
166
|
+
/** Each cold feed and the unsent bytes its opening snapshots left behind. A feed is cold from a
|
|
167
|
+
* snapshot write that leaves bytes unsent until its response emits `drain`, or a live write finds
|
|
168
|
+
* nothing unsent, and is warm after. A feed that has gone is dropped with its response. */
|
|
169
|
+
const coldFeeds = new WeakMap();
|
|
170
|
+
/** The feed's opening state has drained: from here on a live event is held to the ceiling alone. */
|
|
171
|
+
function warmFeed(res) {
|
|
172
|
+
coldFeeds.delete(res);
|
|
173
|
+
}
|
|
174
|
+
/** Writes one SSE event to a feed. A feed that has ended takes nothing more.
|
|
175
|
+
*
|
|
176
|
+
* A live event is checked against the backlog the feed already holds, measured BEFORE the write:
|
|
177
|
+
* when more than `ceiling` bytes are still unsent, the feed is told so with one `overflow` event
|
|
178
|
+
* `{ reason }` and ended, and the event is not written. Measuring after the write would end a feed
|
|
179
|
+
* for one event larger than the ceiling on its own, such as a single long chat message, which would
|
|
180
|
+
* disconnect every dashboard at once. So one large event over an empty backlog is written, and the
|
|
181
|
+
* feed ends only when it is in fact behind.
|
|
182
|
+
*
|
|
183
|
+
* A snapshot is never checked. Its unsent bytes are not live traffic the feed fell behind on, so
|
|
184
|
+
* while they drain (the feed is cold) a live event is allowed them on top of the ceiling: on a slow
|
|
185
|
+
* link a roster over the ceiling would otherwise end the feed at its first live event, and every
|
|
186
|
+
* reconnect would end the same way. The allowance goes when the opening state has drained, so a
|
|
187
|
+
* cold feed still has a bound, its opening bytes plus the ceiling plus one event. */
|
|
188
|
+
export function writeFeed(res, event, data, kind = "live", ceiling = MAX_FEED_BUFFER_BYTES) {
|
|
189
|
+
if (res.writableEnded)
|
|
190
|
+
return;
|
|
191
|
+
const frame = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
|
192
|
+
if (kind === "snapshot") {
|
|
193
|
+
res.write(frame);
|
|
194
|
+
if (res.writableLength > 0) {
|
|
195
|
+
if (!coldFeeds.has(res))
|
|
196
|
+
res.once?.("drain", () => warmFeed(res));
|
|
197
|
+
coldFeeds.set(res, res.writableLength);
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (res.writableLength === 0)
|
|
202
|
+
warmFeed(res);
|
|
203
|
+
const allowance = coldFeeds.get(res) ?? 0;
|
|
204
|
+
if (res.writableLength > ceiling + allowance) {
|
|
205
|
+
const reason = `this feed fell more than ${ceiling} bytes behind, so the server closed it; reconnect to resume`;
|
|
206
|
+
res.write(`event: overflow\ndata: ${JSON.stringify({ reason })}\n\n`);
|
|
207
|
+
res.end();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
res.write(frame);
|
|
211
|
+
}
|
|
212
|
+
/** Writes a new feed's opening state through `send`, every write a snapshot: `hello` first, so a
|
|
213
|
+
* browser can watch an agent before the roster arrives, then the roster and the presence view, then
|
|
214
|
+
* the membership seed once it is read, or its refusal when the read fails. Resolves when the seed
|
|
215
|
+
* is written. */
|
|
216
|
+
export function writeOpening(send, state) {
|
|
217
|
+
send("hello", { feed: state.feed }, "snapshot");
|
|
218
|
+
send("roster", state.roster, "snapshot");
|
|
219
|
+
send("presence-view", state.presenceView, "snapshot");
|
|
220
|
+
return state.membership()
|
|
221
|
+
.then((m) => send("membership", m, "snapshot"))
|
|
222
|
+
.catch((e) => send(MEMBERSHIP_READ_FAILED, { reason: e.message }, "snapshot"));
|
|
223
|
+
}
|
|
224
|
+
/** The most agents one feed may watch at once. A watch is a row in a map this process holds for as
|
|
225
|
+
* long as the feed is open, and the id is the caller's, so without a ceiling one browser could
|
|
226
|
+
* grow that map without bound by asking for ids nobody runs. The dashboard watches the agent whose
|
|
227
|
+
* session is open, in the panel and the centre, so it never comes near this. */
|
|
228
|
+
const MAX_WATCHES_PER_FEED = 64;
|
|
229
|
+
/** Which feeds watch which agent. A feed is counted once per agent however many times it asks.
|
|
230
|
+
*
|
|
231
|
+
* This is the refcount behind "subscribe on demand": the tap already receives every frame, so an
|
|
232
|
+
* agent with no watcher costs no browser anything, and an agent leaves the map with its last
|
|
233
|
+
* watcher. Both directions are kept so `drop` touches only the agents its feed held, and so the
|
|
234
|
+
* per-feed ceiling is a lookup rather than a scan. */
|
|
235
|
+
export class SessionWatchers {
|
|
236
|
+
perFeed;
|
|
237
|
+
byAgent = new Map();
|
|
238
|
+
byFeed = new Map();
|
|
239
|
+
constructor(perFeed = MAX_WATCHES_PER_FEED) {
|
|
240
|
+
this.perFeed = perFeed;
|
|
241
|
+
}
|
|
242
|
+
/** Throws a BadRequest when the feed already watches `perFeed` other agents. */
|
|
243
|
+
watch(agent, feed) {
|
|
244
|
+
const held = this.byFeed.get(feed) ?? new Set();
|
|
245
|
+
if (!held.has(agent) && held.size >= this.perFeed)
|
|
246
|
+
throw new BadRequest(`this feed already watches ${this.perFeed} agents, the most one feed may watch at once`);
|
|
247
|
+
const feeds = this.byAgent.get(agent) ?? [];
|
|
248
|
+
if (!feeds.includes(feed))
|
|
249
|
+
feeds.push(feed);
|
|
250
|
+
this.byAgent.set(agent, feeds);
|
|
251
|
+
held.add(agent);
|
|
252
|
+
this.byFeed.set(feed, held);
|
|
253
|
+
}
|
|
254
|
+
unwatch(agent, feed) {
|
|
255
|
+
const feeds = this.byAgent.get(agent);
|
|
256
|
+
if (feeds !== undefined) {
|
|
257
|
+
const rest = feeds.filter((f) => f !== feed);
|
|
258
|
+
if (rest.length === 0)
|
|
259
|
+
this.byAgent.delete(agent);
|
|
260
|
+
else
|
|
261
|
+
this.byAgent.set(agent, rest);
|
|
262
|
+
}
|
|
263
|
+
const held = this.byFeed.get(feed);
|
|
264
|
+
if (held !== undefined) {
|
|
265
|
+
held.delete(agent);
|
|
266
|
+
if (held.size === 0)
|
|
267
|
+
this.byFeed.delete(feed);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/** A feed closed: forget every watch it held. */
|
|
271
|
+
drop(feed) {
|
|
272
|
+
for (const agent of [...(this.byFeed.get(feed) ?? [])])
|
|
273
|
+
this.unwatch(agent, feed);
|
|
274
|
+
}
|
|
275
|
+
targets(agent) {
|
|
276
|
+
return [...(this.byAgent.get(agent) ?? [])];
|
|
277
|
+
}
|
|
278
|
+
/** Agents with at least one watcher. An agent with none is absent, not zero. */
|
|
279
|
+
agents() {
|
|
280
|
+
return [...this.byAgent.keys()];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/** The events read ran past its deadline. Its own type, so the route can tell it from a refusal
|
|
284
|
+
* (an answer) and from any other failure (a 503 with the reason). */
|
|
285
|
+
export class AgentEventsLate extends Error {
|
|
286
|
+
}
|
|
287
|
+
/** One agent's newest frames within the deadline. Reads `limit + 1` from `events.<owner>.<actor>`
|
|
288
|
+
* with `channelHistory` and answers the newest `limit`, oldest first, with `more` when one more
|
|
289
|
+
* existed. A permission denial (`isPermissionDenied` from core) is an answer, `{ refused }` with the
|
|
290
|
+
* broker's own text and the grant command for this mesh. The deadline throws `AgentEventsLate`; any
|
|
291
|
+
* other failure rethrows.
|
|
292
|
+
*
|
|
293
|
+
* SENDER-CHECKED LIKE THE LIVE FEED. The read names the agent as `publisher`, so it filters on the
|
|
294
|
+
* agent's own subject, `chat.<owner>.<actor>.events.<owner>.<actor>`, and a frame whose subject
|
|
295
|
+
* names another sender is never read. That is the check `classifyTap` makes on a live frame, so a
|
|
296
|
+
* session's history and its live frames hold the same frames. Like that check, it is as strong as
|
|
297
|
+
* the mesh's publish permissions: on an open mesh any raw NATS client can publish on this subject.
|
|
298
|
+
*
|
|
299
|
+
* BOUNDED TWICE. The caller's `limit` is already capped at {@link MAX_HISTORY_LIMIT}, so one read
|
|
300
|
+
* holds at most one more message than that, and the read races the same deadline its siblings do,
|
|
301
|
+
* with the signal handed down so a late read stops its pull and drops its consumer.
|
|
302
|
+
*
|
|
303
|
+
* `channelHistory`, not the mediated `readHistory`: the mediated read caps a page at 200 and has
|
|
304
|
+
* no cursor, and this is the same credential the channel history route already reads with. */
|
|
305
|
+
export async function agentEventsPage(source, agent, limit, grantFor, deadlineMs = AGGREGATION_DEADLINE_MS) {
|
|
306
|
+
const channel = eventChannel(agent);
|
|
307
|
+
const clock = deadline(deadlineMs);
|
|
308
|
+
try {
|
|
309
|
+
const publisher = { owner: agent.owner, actor: agent.actor };
|
|
310
|
+
const page = await within(source.channelHistory(channel, { limit: limit + 1, signal: clock.signal, publisher }), clock.until);
|
|
311
|
+
if (page === LATE)
|
|
312
|
+
throw new AgentEventsLate(`${channel}: the read did not finish within ${deadlineMs}ms`);
|
|
313
|
+
let payloads = [];
|
|
314
|
+
let payloadRead;
|
|
315
|
+
if (source.eventPayloadHistory) {
|
|
316
|
+
try {
|
|
317
|
+
const result = await within(source.eventPayloadHistory(agent.owner, agent.actor, { limit: limit + 1, signal: clock.signal }), clock.until);
|
|
318
|
+
if (result !== LATE)
|
|
319
|
+
payloads = result;
|
|
320
|
+
else
|
|
321
|
+
payloadRead = { status: "timeout", reason: "Tool payload read timed out. Try again." };
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
payloadRead = clock.signal.aborted
|
|
325
|
+
? { status: "timeout", reason: "Tool payload read timed out. Try again." }
|
|
326
|
+
: isPermissionDenied(e)
|
|
327
|
+
? { status: "refused", reason: "Tool payload read refused. Ask the mesh owner to check payload access." }
|
|
328
|
+
: { status: "failed", reason: "Tool payload read failed. Try again." };
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const seen = new Set();
|
|
332
|
+
const tail = (rows) => limit === 0 ? [] : rows.slice(-limit);
|
|
333
|
+
const merged = [...tail(page), ...tail(payloads)].filter(msg => {
|
|
334
|
+
if (seen.has(msg.id))
|
|
335
|
+
return false;
|
|
336
|
+
seen.add(msg.id);
|
|
337
|
+
return true;
|
|
338
|
+
}).sort((a, b) => a.ts - b.ts);
|
|
339
|
+
const more = page.length > limit || payloads.length > limit;
|
|
340
|
+
return { frames: merged, more, ...(payloadRead === undefined ? {} : { payloadRead }) };
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
if (e instanceof AgentEventsLate)
|
|
344
|
+
throw e;
|
|
345
|
+
if (isPermissionDenied(e)) {
|
|
346
|
+
const grant = grantFor(channel, agent.owner);
|
|
347
|
+
return { refused: e instanceof Error ? e.message : String(e), ...(grant === undefined ? {} : { grant }) };
|
|
348
|
+
}
|
|
349
|
+
throw e;
|
|
350
|
+
}
|
|
351
|
+
finally {
|
|
352
|
+
clock.done();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/** The command that lets a reader see one agent's event channel, as `docs/connect-claude.md` gives
|
|
356
|
+
* it for each kind of mesh, or nothing on an open mesh, where there is no grant to give. */
|
|
357
|
+
export function eventsGrantFor(mode) {
|
|
358
|
+
if (mode === "user")
|
|
359
|
+
return (channel, owner) => `cotal actor grant <reader> --owner ${owner} --scope '' --allow-subscribe '${channel}' --allow-publish ''`;
|
|
360
|
+
if (mode === "static")
|
|
361
|
+
return (channel) => `cotal auth mint watcher --profile agent --allow-subscribe '${channel}' --provision`;
|
|
362
|
+
return () => undefined;
|
|
363
|
+
}
|
|
364
|
+
/** The all-activity backfill: recent chat history merged with DM history, oldest-first by `ts`,
|
|
365
|
+
* capped, and BOUNDED.
|
|
366
|
+
*
|
|
367
|
+
* Both sources, all of chat in one stream read and the DM backlog, race one shared deadline, so the
|
|
368
|
+
* caller never waits on the slower read past it and one source's rejection never discards the
|
|
369
|
+
* other's rows. Sources that answered are merged; sources that refused or ran late are NAMED in the
|
|
370
|
+
* page. The page is never a 500 and never silently short.
|
|
371
|
+
*
|
|
372
|
+
* Separate from the route so the filter above is reachable by a test that can see WHICH channels
|
|
373
|
+
* were asked for, which is the only evidence that separates filtering before the fetch from
|
|
374
|
+
* filtering after it. The route is a thin caller. */
|
|
375
|
+
export async function activityBackfill(ep, limit, deadlineMs = AGGREGATION_DEADLINE_MS, concurrency = AGGREGATION_CONCURRENCY) {
|
|
376
|
+
const clock = deadline(deadlineMs);
|
|
377
|
+
try {
|
|
378
|
+
// The channel list is inside the deadline too: it is a broker read like any other, and a request
|
|
379
|
+
// that could hang here would be bounded everywhere except its first step. There is no partial
|
|
380
|
+
// page to serve without it, so this one is a refusal rather than a partial: `0 of 0` would claim
|
|
381
|
+
// the space has no channels, which is a different answer and the wrong one.
|
|
382
|
+
//
|
|
383
|
+
// BOTH ENDINGS ARE NAMED, and the second is why this is not just a `within` call. The registry
|
|
384
|
+
// read has its OWN timeout inside the client, shorter than this deadline: measured across a
|
|
385
|
+
// 128 KiB/s link it rejects with the broker's bare `timeout` after 5s, before the deadline can
|
|
386
|
+
// fire, and unwrapped that word reaches the browser through the generic 500 handler as
|
|
387
|
+
// `{"error":"timeout"}` - five characters of cause for a blank panel. A reader cannot act on a
|
|
388
|
+
// refusal that does not say what failed, so the reason is wrapped in the name of the read that
|
|
389
|
+
// produced it.
|
|
390
|
+
const listed = await within(ep.listChannels().catch((e) => {
|
|
391
|
+
throw new Error(`the channel list could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
392
|
+
}), clock.until);
|
|
393
|
+
if (listed === LATE)
|
|
394
|
+
throw new Error(`the channel list did not arrive within ${deadlineMs}ms`);
|
|
395
|
+
const chans = chatOnly(listed);
|
|
396
|
+
const sources = [
|
|
397
|
+
{
|
|
398
|
+
name: "chat",
|
|
399
|
+
read: async (signal) => (await ep.multiChannelHistory(chans.map((ch) => ch.channel), { limit, signal }))
|
|
400
|
+
.map(({ channel, msg }) => ({ mode: "chat", channel, msg })),
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
name: "direct messages",
|
|
404
|
+
read: async (signal) => (await ep.dmHistory({ limit, signal })).map((msg) => ({ mode: "unicast", msg })),
|
|
405
|
+
},
|
|
406
|
+
];
|
|
407
|
+
// A POOL, NOT A FAN-OUT. Workers pull from a shared cursor, so at most `concurrency` reads are
|
|
408
|
+
// in flight and the rest wait their turn. A worker that finds the deadline already past does not
|
|
409
|
+
// start another read: the page is closed, and issuing broker work for it would be waste with a
|
|
410
|
+
// guaranteed-discarded result.
|
|
411
|
+
const settled = new Array(sources.length).fill(LATE);
|
|
412
|
+
const failed = new Array(sources.length);
|
|
413
|
+
let next = 0;
|
|
414
|
+
let expired = false;
|
|
415
|
+
void clock.until.then(() => { expired = true; });
|
|
416
|
+
const worker = async () => {
|
|
417
|
+
for (;;) {
|
|
418
|
+
const i = next++;
|
|
419
|
+
if (i >= sources.length || expired)
|
|
420
|
+
return;
|
|
421
|
+
try {
|
|
422
|
+
const r = await within(sources[i].read(clock.signal), clock.until);
|
|
423
|
+
if (r !== LATE)
|
|
424
|
+
settled[i] = r;
|
|
425
|
+
}
|
|
426
|
+
catch (e) {
|
|
427
|
+
// A source that FAILED is missing for the same reason a late one is: it has nothing to
|
|
428
|
+
// contribute. It is named the same way, and the other source's rows still reach the page.
|
|
429
|
+
// Its reason is kept, because a refusal and a timeout ask different things of an operator.
|
|
430
|
+
failed[i] = e instanceof Error ? e.message : String(e);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, sources.length) }, worker));
|
|
435
|
+
const entries = [];
|
|
436
|
+
const missing = [];
|
|
437
|
+
const reasons = {};
|
|
438
|
+
for (let i = 0; i < settled.length; i++) {
|
|
439
|
+
const r = settled[i];
|
|
440
|
+
if (r === LATE) {
|
|
441
|
+
missing.push(sources[i].name);
|
|
442
|
+
reasons[sources[i].name] = failed[i] === undefined
|
|
443
|
+
? `the read did not finish within ${deadlineMs}ms`
|
|
444
|
+
: `the read failed: ${failed[i]}`;
|
|
445
|
+
}
|
|
446
|
+
else
|
|
447
|
+
entries.push(...r);
|
|
448
|
+
}
|
|
449
|
+
// THE PAGE IS ORDERED BY `ts`, AND THE CHAT HALF WAS CHOSEN BY ARRIVAL. The chat rows are the
|
|
450
|
+
// newest `limit` by CHAT stream sequence, the order the broker stored them in, and the DM rows
|
|
451
|
+
// are the newest `limit` of the DM stream. The two streams number their messages independently,
|
|
452
|
+
// so the sender's `ts` is the only key both halves carry: it orders the merged page and makes the
|
|
453
|
+
// final cut to `limit` across both. Where a sender's clock disagrees with arrival, two chat rows
|
|
454
|
+
// can show in an order their arrival did not imply. The sort is stable, so rows with equal `ts`
|
|
455
|
+
// keep the order the reads returned: chat in stream sequence, then DMs in stream sequence.
|
|
456
|
+
entries.sort((a, b) => a.msg.ts - b.msg.ts);
|
|
457
|
+
return {
|
|
458
|
+
entries: entries.slice(-limit),
|
|
459
|
+
partial: missing.length > 0,
|
|
460
|
+
read: sources.length - missing.length,
|
|
461
|
+
of: sources.length,
|
|
462
|
+
missing,
|
|
463
|
+
reasons,
|
|
464
|
+
deadlineMs,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
finally {
|
|
468
|
+
clock.done();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
//# sourceMappingURL=web-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