ruicode 0.98.12 → 0.98.14
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/binary.d.ts +0 -2
- package/dist/binary.js +0 -3
- package/dist/client.d.ts +0 -6
- package/dist/client.js +0 -36
- package/dist/feed.d.ts +0 -7
- package/dist/feed.js +0 -9
- package/dist/follow.d.ts +0 -29
- package/dist/follow.js +0 -29
- package/dist/line.d.ts +0 -11
- package/dist/line.js +0 -10
- package/dist/sessions.d.ts +0 -10
- package/dist/sessions.js +0 -10
- package/dist/settings.d.ts +0 -1
- package/package.json +4 -4
package/dist/binary.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/** The one table of platforms Rui builds for: Node's platform, then architecture, to the npm package holding rui. */
|
|
2
1
|
export declare const PLATFORM_PACKAGES: Record<string, Record<string, string>>;
|
|
3
2
|
export interface BinaryLookup {
|
|
4
3
|
platform?: string;
|
|
5
4
|
arch?: string;
|
|
6
5
|
from?: string;
|
|
7
6
|
}
|
|
8
|
-
/** The rui to start: `binary` when given, else the platform package's. Never a guess from PATH. */
|
|
9
7
|
export declare function resolveBinary(binary: string | undefined, lookup?: BinaryLookup): string;
|
package/dist/binary.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { RuiUnavailableError } from "./errors.js";
|
|
4
|
-
/** The one table of platforms Rui builds for: Node's platform, then architecture, to the npm package holding rui. */
|
|
5
4
|
export const PLATFORM_PACKAGES = {
|
|
6
5
|
linux: { x64: "ruicode-linux-x64", arm64: "ruicode-linux-arm64" },
|
|
7
6
|
darwin: { arm64: "ruicode-darwin-arm64" },
|
|
8
7
|
};
|
|
9
|
-
// pack.mjs PLATFORMS publishes these packages, with glibc required on Linux; TS-10 checks the two tables agree.
|
|
10
8
|
const SUPPORTED = `Rui runs on ${Object.entries(PLATFORM_PACKAGES)
|
|
11
9
|
.map(([platform, arches]) => `${platform === "linux" ? "glibc Linux" : platform} on ${Object.keys(arches).join(" or ")}`)
|
|
12
10
|
.join(", and ")}.`;
|
|
13
|
-
/** The rui to start: `binary` when given, else the platform package's. Never a guess from PATH. */
|
|
14
11
|
export function resolveBinary(binary, lookup = {}) {
|
|
15
12
|
if (binary !== undefined)
|
|
16
13
|
return binary;
|
package/dist/client.d.ts
CHANGED
|
@@ -34,7 +34,6 @@ export declare class Rui extends EventEmitter<{
|
|
|
34
34
|
exit: [ExitEvent];
|
|
35
35
|
}> {
|
|
36
36
|
#private;
|
|
37
|
-
/** The one line this client holds for every watcher, and the registry of the Sessions they follow. */
|
|
38
37
|
readonly follows: Follows;
|
|
39
38
|
/** Create and list Sessions. */
|
|
40
39
|
readonly sessions: Sessions;
|
|
@@ -63,11 +62,6 @@ export declare class Rui extends EventEmitter<{
|
|
|
63
62
|
get pid(): number | undefined;
|
|
64
63
|
get hostInfo(): HostInfo | undefined;
|
|
65
64
|
}
|
|
66
|
-
/**
|
|
67
|
-
* The application's environment a child Host inherits: process basics, and the proxy and trust variables its transport
|
|
68
|
-
* reads, so a Host behind a proxy or a private CA reaches its provider and models.dev. Secrets reach it only through
|
|
69
|
-
* `{ env }` sources in the settings.
|
|
70
|
-
*/
|
|
71
65
|
export declare const INHERITED_ENVIRONMENT: readonly ["PATH", "HOME", "TMPDIR", "https_proxy", "HTTPS_PROXY", "no_proxy", "NO_PROXY", "SSL_CERT_FILE", "SSL_CERT_DIR"];
|
|
72
66
|
export declare function launchFor(settings: HostSettings, runtimeDir: string, options?: ClientOptions): Launch;
|
|
73
67
|
export declare function encodeSettings(document: Schemas["HostSettings"]): Buffer;
|
package/dist/client.js
CHANGED
|
@@ -45,7 +45,6 @@ export class Rui extends EventEmitter {
|
|
|
45
45
|
#closing;
|
|
46
46
|
#dead;
|
|
47
47
|
#storeFailed;
|
|
48
|
-
/** The one line this client holds for every watcher, and the registry of the Sessions they follow. */
|
|
49
48
|
follows = new Follows((session, request) => readPage(this, session, request), { watch: (sessions) => this.#watchLine(sessions) });
|
|
50
49
|
#line;
|
|
51
50
|
#lineSessions = [];
|
|
@@ -162,13 +161,6 @@ export class Rui extends EventEmitter {
|
|
|
162
161
|
}
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
|
-
/**
|
|
166
|
-
* The one classification of a failed attempt against `host`, shared by `call` and the line. A canonical Store failure
|
|
167
|
-
* latches. A dispatch_fenced reply is classified only once the Host has exited, since stop and cleanup phases also send it.
|
|
168
|
-
* A lost connection or a host_stopping reply settles the Host, then allows one retry; only the line (GET /v1/line) receives a
|
|
169
|
-
* host_stopping reply. Returns when the attempt may be
|
|
170
|
-
* retried; otherwise throws the error the caller reports.
|
|
171
|
-
*/
|
|
172
164
|
async #retryAfter(host, error, retried) {
|
|
173
165
|
if (this.#storeFailed)
|
|
174
166
|
throw this.#storeFailed;
|
|
@@ -226,10 +218,6 @@ export class Rui extends EventEmitter {
|
|
|
226
218
|
this.#scheduleRestart();
|
|
227
219
|
});
|
|
228
220
|
}
|
|
229
|
-
/**
|
|
230
|
-
* The one owner of the Store-failed latch. Every fence signal reaches it: a canonical 500 reply (`isCanonicalFailure`), and the
|
|
231
|
-
* `store_fenced` line. The first latch wins, rejects the pending calls with the same error and stops restarts.
|
|
232
|
-
*/
|
|
233
221
|
#latchStoreFailed(cause) {
|
|
234
222
|
if (this.#storeFailed)
|
|
235
223
|
return this.#storeFailed;
|
|
@@ -243,7 +231,6 @@ export class Rui extends EventEmitter {
|
|
|
243
231
|
for (const waiter of this.#waiters.splice(0))
|
|
244
232
|
waiter.reject(error);
|
|
245
233
|
}
|
|
246
|
-
/** The line's watched set. Empty closes the line; otherwise an open line is sent the set, and a closed one reopens. */
|
|
247
234
|
#watchLine(sessions) {
|
|
248
235
|
this.#lineSessions = sessions;
|
|
249
236
|
if (sessions.length === 0) {
|
|
@@ -265,16 +252,10 @@ export class Rui extends EventEmitter {
|
|
|
265
252
|
.catch((error) => this.follows.fail(error instanceof Error ? error : new RuiUnavailableError(String(error))))
|
|
266
253
|
.finally(() => {
|
|
267
254
|
this.#opening = false;
|
|
268
|
-
// A watch that arrived while this attempt was ending saw it as running, so it is opened here.
|
|
269
255
|
if (this.#lineSessions.length > 0 && !this.#line && !this.#closing && !this.#storeFailed)
|
|
270
256
|
this.#openLine();
|
|
271
257
|
});
|
|
272
258
|
}
|
|
273
|
-
/**
|
|
274
|
-
* Opens the line on the current Host and sends it the watched set; the Host nudges each listed Session, so every watcher
|
|
275
|
-
* re-reads from its cursor. A refused or lost attempt follows the restart path, as `call` does: wait for the child to exit,
|
|
276
|
-
* then reconnect to the Host that replaces it, once.
|
|
277
|
-
*/
|
|
278
259
|
async #connectLine() {
|
|
279
260
|
for (let attempt = 1;; attempt++) {
|
|
280
261
|
const host = await this.#ready();
|
|
@@ -298,7 +279,6 @@ export class Rui extends EventEmitter {
|
|
|
298
279
|
}
|
|
299
280
|
}
|
|
300
281
|
#lineFrame(frame) {
|
|
301
|
-
// Only an answer to a watch set resets the count of closes: `hello` and `ping` arrive whether or not the Host read it.
|
|
302
282
|
if (frame.type === "changed" || frame.type === "resync" || frame.type === "failed")
|
|
303
283
|
this.#silentCloses = 0;
|
|
304
284
|
switch (frame.type) {
|
|
@@ -309,7 +289,6 @@ export class Rui extends EventEmitter {
|
|
|
309
289
|
this.follows.nudgeAll();
|
|
310
290
|
return;
|
|
311
291
|
case "failed":
|
|
312
|
-
// `host_stopping` needs no action: the Host closes the line, and the close reconnects once the child restarts.
|
|
313
292
|
if (frame.code === "store_failed")
|
|
314
293
|
this.#latchStoreFailed(new RuiUnavailableError("the Rui Host's line reported store_failed"));
|
|
315
294
|
return;
|
|
@@ -327,8 +306,6 @@ export class Rui extends EventEmitter {
|
|
|
327
306
|
this.follows.fail(new RuiUnavailableError("the Rui Host sent a malformed line frame", { cause: error }));
|
|
328
307
|
return;
|
|
329
308
|
}
|
|
330
|
-
// A Host restart closes a line once and then answers its successor. A line that closes twice without answering a watch
|
|
331
|
-
// set is not a restart: the Host refuses that set, so reconnecting would repeat it.
|
|
332
309
|
if (++this.#silentCloses > 1) {
|
|
333
310
|
this.follows.fail(new RuiUnavailableError("the Rui Host closed its line twice without a frame"));
|
|
334
311
|
return;
|
|
@@ -379,11 +356,6 @@ export class Rui extends EventEmitter {
|
|
|
379
356
|
}
|
|
380
357
|
}
|
|
381
358
|
}
|
|
382
|
-
/**
|
|
383
|
-
* The application's environment a child Host inherits: process basics, and the proxy and trust variables its transport
|
|
384
|
-
* reads, so a Host behind a proxy or a private CA reaches its provider and models.dev. Secrets reach it only through
|
|
385
|
-
* `{ env }` sources in the settings.
|
|
386
|
-
*/
|
|
387
359
|
export const INHERITED_ENVIRONMENT = ["PATH", "HOME", "TMPDIR", ...TRANSPORT_ENVIRONMENT];
|
|
388
360
|
export function launchFor(settings, runtimeDir, options = {}) {
|
|
389
361
|
const env = Object.create(null);
|
|
@@ -512,15 +484,12 @@ async function start(launch, spawned) {
|
|
|
512
484
|
stdout.length = 0;
|
|
513
485
|
}
|
|
514
486
|
}
|
|
515
|
-
/** The Host's 500 reply for a fenced Store, the stable signal the Store fence latches on. */
|
|
516
487
|
function isCanonicalFailure(error) {
|
|
517
488
|
return error.type === "invocation_error" && error.code === "canonical_store_failure";
|
|
518
489
|
}
|
|
519
|
-
/** The Host's 503 reply while it is not in its open phase: a stop, a cleanup fence or a Store fence. Not a signal alone. */
|
|
520
490
|
function isDispatchFenced(error) {
|
|
521
491
|
return error.type === "host_unavailable" && error.code === "dispatch_fenced";
|
|
522
492
|
}
|
|
523
|
-
/** Resolves with `done`, or with `fallback` once `ms` passes. The timer is cleared as soon as the wait settles. */
|
|
524
493
|
async function bounded(done, ms, fallback) {
|
|
525
494
|
const cancel = new AbortController();
|
|
526
495
|
try {
|
|
@@ -533,17 +502,12 @@ async function bounded(done, ms, fallback) {
|
|
|
533
502
|
cancel.abort();
|
|
534
503
|
}
|
|
535
504
|
}
|
|
536
|
-
/**
|
|
537
|
-
* Waits for a lost or fenced child to exit, bounded by the shutdown grace (D129), then for its stdout to drain so a final
|
|
538
|
-
* `store_fenced` line has been read. Resolves whether the child exited in time.
|
|
539
|
-
*/
|
|
540
505
|
async function settle(host) {
|
|
541
506
|
const gone = await bounded(host.exited.then(() => true), CLOSE_GRACE_MS, false);
|
|
542
507
|
if (gone)
|
|
543
508
|
await drained(host);
|
|
544
509
|
return gone;
|
|
545
510
|
}
|
|
546
|
-
/** Lets a stopped child's stdout deliver its final lines, bounded so a grandchild holding the pipe cannot stall us. */
|
|
547
511
|
async function drained(host) {
|
|
548
512
|
await bounded(host.output, OUTPUT_GRACE_MS, undefined);
|
|
549
513
|
}
|
package/dist/feed.d.ts
CHANGED
|
@@ -58,7 +58,6 @@ export declare function decodeCursor(cursor: string): {
|
|
|
58
58
|
export interface ContentOptions {
|
|
59
59
|
field?: number;
|
|
60
60
|
}
|
|
61
|
-
/** The Host owns the rule: its text route refuses a parts value as `ContentIsParts`. */
|
|
62
61
|
export declare function readContentBytes(link: Link, session: string, entry: {
|
|
63
62
|
position: string;
|
|
64
63
|
ordinal: string;
|
|
@@ -67,7 +66,6 @@ export declare function readContent(link: Link, session: string, entry: {
|
|
|
67
66
|
position: string;
|
|
68
67
|
ordinal: string;
|
|
69
68
|
}, options?: ContentOptions): Promise<string>;
|
|
70
|
-
/** A page request: the next row's cursor, the `since` token of the last full reply, and the kinds. `end` pins a bounded traversal. */
|
|
71
69
|
export interface PageRequest {
|
|
72
70
|
end: string | null;
|
|
73
71
|
position: string;
|
|
@@ -76,12 +74,7 @@ export interface PageRequest {
|
|
|
76
74
|
kinds: readonly FeedKind[];
|
|
77
75
|
}
|
|
78
76
|
export declare function readPage(link: Link, session: string, request: PageRequest): Promise<Schemas["ActivityPageReply"]>;
|
|
79
|
-
/**
|
|
80
|
-
* Follows a Session's feed on the client's one line: yields each new row once, in order. Each nudge for the Session reads
|
|
81
|
-
* from this iterator's cursor (`Follows`); an idle Session makes no reads until the Host nudges it.
|
|
82
|
-
*/
|
|
83
77
|
export declare function watchActivity(link: Link, session: string, options?: WatchOptions, observe?: (target: InterruptTarget | null) => void): AsyncGenerator<FeedEntry, void, undefined>;
|
|
84
|
-
/** The Session's feed from `after` to its current end, or with `follow`, `watchActivity`. */
|
|
85
78
|
export declare function listActivity(link: Link, session: string, options?: ListActivityOptions, observe?: (target: InterruptTarget | null) => void): AsyncGenerator<FeedEntry, void, undefined>;
|
|
86
79
|
export interface SearchActivityOptions {
|
|
87
80
|
/** Resume before this search entry's cursor. */
|
package/dist/feed.js
CHANGED
|
@@ -64,7 +64,6 @@ function contentOf(payload) {
|
|
|
64
64
|
function entryOf(row) {
|
|
65
65
|
const [kind, payload] = Object.entries(row.value)[0];
|
|
66
66
|
const reference = contentOf(payload);
|
|
67
|
-
// A failed Turn's report is the entry's text; a finished Turn's answer is its assistant entry and a stopped one has none.
|
|
68
67
|
const wanted = kind !== "turn_ended" || ENDING_SIGN[payload.ending] === "failed";
|
|
69
68
|
const entry = {
|
|
70
69
|
kind,
|
|
@@ -104,7 +103,6 @@ function contentBody(store, session, entry, options = {}) {
|
|
|
104
103
|
});
|
|
105
104
|
}
|
|
106
105
|
const MAX_CONTENT_BYTES = 1024 * 1024 * 1024;
|
|
107
|
-
/** The Host owns the rule: its text route refuses a parts value as `ContentIsParts`. */
|
|
108
106
|
export async function readContentBytes(link, session, entry, options = {}) {
|
|
109
107
|
try {
|
|
110
108
|
return await link.exchange("/v1/activity-content", (store) => contentBody(store, session, entry, options), undefined, { max: MAX_CONTENT_BYTES });
|
|
@@ -128,7 +126,6 @@ function kindsOf(kinds) {
|
|
|
128
126
|
function startOf(after) {
|
|
129
127
|
return after === undefined ? { position: "0", ordinal: null } : decodeCursor(after);
|
|
130
128
|
}
|
|
131
|
-
/** One page's rows as entries, with their inline content read in order. Stops at an abort. */
|
|
132
129
|
async function* entriesOf(link, session, items, signal) {
|
|
133
130
|
for (const row of items) {
|
|
134
131
|
if (signal?.aborted)
|
|
@@ -137,7 +134,6 @@ async function* entriesOf(link, session, items, signal) {
|
|
|
137
134
|
if (reference && "content" in entry) {
|
|
138
135
|
if (reference.type === "parts") {
|
|
139
136
|
entry.parts = await listParts(link, session, reference.owner);
|
|
140
|
-
// One entry inlines at most INLINE_TEXT_BYTES across its Text parts, as a text entry does.
|
|
141
137
|
let inline = INLINE_TEXT_BYTES;
|
|
142
138
|
for (const part of entry.parts) {
|
|
143
139
|
if (part.type !== "text")
|
|
@@ -166,10 +162,6 @@ async function* entriesOf(link, session, items, signal) {
|
|
|
166
162
|
yield entry;
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Follows a Session's feed on the client's one line: yields each new row once, in order. Each nudge for the Session reads
|
|
171
|
-
* from this iterator's cursor (`Follows`); an idle Session makes no reads until the Host nudges it.
|
|
172
|
-
*/
|
|
173
165
|
export async function* watchActivity(link, session, options = {}, observe) {
|
|
174
166
|
const follows = link.follows;
|
|
175
167
|
if (!follows)
|
|
@@ -188,7 +180,6 @@ export async function* watchActivity(link, session, options = {}, observe) {
|
|
|
188
180
|
follows.leave(watcher);
|
|
189
181
|
}
|
|
190
182
|
}
|
|
191
|
-
/** The Session's feed from `after` to its current end, or with `follow`, `watchActivity`. */
|
|
192
183
|
export async function* listActivity(link, session, options = {}, observe) {
|
|
193
184
|
if (options.follow) {
|
|
194
185
|
yield* watchActivity(link, session, options, observe);
|
package/dist/follow.d.ts
CHANGED
|
@@ -1,60 +1,39 @@
|
|
|
1
1
|
import type { FeedKind, PageRequest } from "./feed.ts";
|
|
2
2
|
import type { components } from "./wire.ts";
|
|
3
3
|
type Reply = components["schemas"]["ActivityPageReply"];
|
|
4
|
-
/** A page of rows; a `not_modified` reply carries none. */
|
|
5
4
|
export type Page = Extract<Reply, {
|
|
6
5
|
delta: "full";
|
|
7
6
|
}>;
|
|
8
|
-
/** The most Sessions one line may watch (docs/contracts/inspection.md#live-line). */
|
|
9
7
|
export declare const MAX_WATCHED_SESSIONS = 256;
|
|
10
|
-
/** Replaces the held line's watched set. An empty set closes the line. */
|
|
11
8
|
export interface LineControl {
|
|
12
9
|
watch(sessions: readonly string[]): void;
|
|
13
10
|
}
|
|
14
|
-
/** Reads one page of a Session's feed from a cursor. */
|
|
15
11
|
export type PageReader = (session: string, request: PageRequest) => Promise<Reply>;
|
|
16
12
|
export interface Cursor {
|
|
17
13
|
position: string;
|
|
18
14
|
ordinal: string | null;
|
|
19
15
|
since: string | null;
|
|
20
16
|
}
|
|
21
|
-
/**
|
|
22
|
-
* The one way this client follows a Session. Every watcher of the client shares one line. A nudge (`changed`, `resync`,
|
|
23
|
-
* a reconnect) makes each affected watcher read its own cursor once. The nudge carries no fact: rows come from feed reads.
|
|
24
|
-
*/
|
|
25
17
|
export declare class Follows {
|
|
26
18
|
#private;
|
|
27
19
|
constructor(read: PageReader, line: LineControl);
|
|
28
|
-
/**
|
|
29
|
-
* Registers a watcher at `cursor`. A Session's first watcher adds it to the line, and the Host answers a watch set with one
|
|
30
|
-
* nudge per listed Session, which reads it. A later watcher of a watched Session gets no frame, so it reads itself.
|
|
31
|
-
*/
|
|
32
20
|
join(session: string, cursor: Cursor, kinds: readonly FeedKind[]): Watcher;
|
|
33
|
-
/** Releases a watcher. The last watcher of a Session drops it from the line; the last one of the client closes the line. */
|
|
34
21
|
leave(watcher: Watcher): void;
|
|
35
|
-
/** A commit touched `session`, or the Host asked for a re-read: each of its watchers reads once. */
|
|
36
22
|
nudge(session: string): void;
|
|
37
|
-
/** The change ring no longer covers the line: every watched Session is re-read from its cursors. */
|
|
38
23
|
nudgeAll(): void;
|
|
39
|
-
/** A read of `follow` failed: its watchers end with `error`. A Session that is no longer registered only ends its own watchers. */
|
|
40
24
|
failFollow(follow: SessionFollow, error: Error): void;
|
|
41
|
-
/** The client can no longer follow: every watcher ends with `error`, and the line closes. */
|
|
42
25
|
fail(error: Error): void;
|
|
43
|
-
/** The client's page reader, for the read loop of each watched Session. */
|
|
44
26
|
get read(): PageReader;
|
|
45
27
|
}
|
|
46
|
-
/** The watchers of one Session. At most one feed read is in flight for it; watchers at the same cursor share that read. */
|
|
47
28
|
declare class SessionFollow {
|
|
48
29
|
#private;
|
|
49
30
|
readonly session: string;
|
|
50
31
|
readonly watchers: Set<Watcher>;
|
|
51
32
|
constructor(session: string, follows: Follows);
|
|
52
33
|
nudge(): void;
|
|
53
|
-
/** Starts the read loop unless one is running; a running loop re-checks for due watchers after each read. */
|
|
54
34
|
drive(): void;
|
|
55
35
|
failWatchers(error: Error): void;
|
|
56
36
|
}
|
|
57
|
-
/** One consumer's cursor and the pages it has not yet taken. The Session's read loop delivers pages; `take` waits for one. */
|
|
58
37
|
export declare class Watcher {
|
|
59
38
|
#private;
|
|
60
39
|
position: string;
|
|
@@ -62,23 +41,15 @@ export declare class Watcher {
|
|
|
62
41
|
since: string | null;
|
|
63
42
|
readonly kinds: readonly FeedKind[];
|
|
64
43
|
readonly follow: SessionFollow;
|
|
65
|
-
/** A read is owed from this cursor: set by a nudge, by a `more` page, and by joining. */
|
|
66
44
|
due: boolean;
|
|
67
45
|
constructor(cursor: Cursor, kinds: readonly FeedKind[], follow: SessionFollow);
|
|
68
46
|
get hasPages(): boolean;
|
|
69
47
|
get request(): PageRequest;
|
|
70
|
-
/** Watchers with equal keys read the same request. */
|
|
71
48
|
get key(): string;
|
|
72
49
|
isWaitingAt(key: string): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Applies a page read from this cursor. A `not_modified` reply moves only the token. `settled` is false when a nudge
|
|
75
|
-
* arrived after the read was issued: the rows are still this cursor's facts, but the watcher stays due for another read.
|
|
76
|
-
*/
|
|
77
50
|
deliver(page: Reply, settled: boolean): void;
|
|
78
51
|
fail(error: Error): void;
|
|
79
|
-
/** Waits for the next page, resolving `undefined` once `signal` aborts. Taking a page starts the next owed read. */
|
|
80
52
|
take(signal: AbortSignal | undefined): Promise<Page | undefined>;
|
|
81
|
-
/** A released watcher neither takes nor receives pages again. */
|
|
82
53
|
release(): void;
|
|
83
54
|
}
|
|
84
55
|
export {};
|
package/dist/follow.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
/** The most Sessions one line may watch (docs/contracts/inspection.md#live-line). */
|
|
2
1
|
export const MAX_WATCHED_SESSIONS = 256;
|
|
3
|
-
/** A Session id in the Host's grammar: six characters of its Crockford alphabet. The Host closes a line whose watch set breaks it. */
|
|
4
2
|
const SESSION_ID = /^[0-9a-hjkmnp-tv-z]{6}$/;
|
|
5
|
-
/**
|
|
6
|
-
* The one way this client follows a Session. Every watcher of the client shares one line. A nudge (`changed`, `resync`,
|
|
7
|
-
* a reconnect) makes each affected watcher read its own cursor once. The nudge carries no fact: rows come from feed reads.
|
|
8
|
-
*/
|
|
9
3
|
export class Follows {
|
|
10
4
|
#read;
|
|
11
5
|
#line;
|
|
@@ -14,10 +8,6 @@ export class Follows {
|
|
|
14
8
|
this.#read = read;
|
|
15
9
|
this.#line = line;
|
|
16
10
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Registers a watcher at `cursor`. A Session's first watcher adds it to the line, and the Host answers a watch set with one
|
|
19
|
-
* nudge per listed Session, which reads it. A later watcher of a watched Session gets no frame, so it reads itself.
|
|
20
|
-
*/
|
|
21
11
|
join(session, cursor, kinds) {
|
|
22
12
|
if (!SESSION_ID.test(session))
|
|
23
13
|
throw new RangeError(`not a Session id: ${JSON.stringify(session)}`);
|
|
@@ -37,7 +27,6 @@ export class Follows {
|
|
|
37
27
|
follow.drive();
|
|
38
28
|
return watcher;
|
|
39
29
|
}
|
|
40
|
-
/** Releases a watcher. The last watcher of a Session drops it from the line; the last one of the client closes the line. */
|
|
41
30
|
leave(watcher) {
|
|
42
31
|
const follow = watcher.follow;
|
|
43
32
|
if (!follow.watchers.delete(watcher))
|
|
@@ -48,16 +37,13 @@ export class Follows {
|
|
|
48
37
|
this.#line.watch([...this.#sessions.keys()]);
|
|
49
38
|
}
|
|
50
39
|
}
|
|
51
|
-
/** A commit touched `session`, or the Host asked for a re-read: each of its watchers reads once. */
|
|
52
40
|
nudge(session) {
|
|
53
41
|
this.#sessions.get(session)?.nudge();
|
|
54
42
|
}
|
|
55
|
-
/** The change ring no longer covers the line: every watched Session is re-read from its cursors. */
|
|
56
43
|
nudgeAll() {
|
|
57
44
|
for (const follow of this.#sessions.values())
|
|
58
45
|
follow.nudge();
|
|
59
46
|
}
|
|
60
|
-
/** A read of `follow` failed: its watchers end with `error`. A Session that is no longer registered only ends its own watchers. */
|
|
61
47
|
failFollow(follow, error) {
|
|
62
48
|
if (this.#sessions.get(follow.session) === follow) {
|
|
63
49
|
this.#sessions.delete(follow.session);
|
|
@@ -65,7 +51,6 @@ export class Follows {
|
|
|
65
51
|
}
|
|
66
52
|
follow.failWatchers(error);
|
|
67
53
|
}
|
|
68
|
-
/** The client can no longer follow: every watcher ends with `error`, and the line closes. */
|
|
69
54
|
fail(error) {
|
|
70
55
|
const all = [...this.#sessions.values()];
|
|
71
56
|
this.#sessions.clear();
|
|
@@ -73,18 +58,15 @@ export class Follows {
|
|
|
73
58
|
follow.failWatchers(error);
|
|
74
59
|
this.#line.watch([]);
|
|
75
60
|
}
|
|
76
|
-
/** The client's page reader, for the read loop of each watched Session. */
|
|
77
61
|
get read() {
|
|
78
62
|
return this.#read;
|
|
79
63
|
}
|
|
80
64
|
}
|
|
81
|
-
/** The watchers of one Session. At most one feed read is in flight for it; watchers at the same cursor share that read. */
|
|
82
65
|
class SessionFollow {
|
|
83
66
|
session;
|
|
84
67
|
watchers = new Set();
|
|
85
68
|
#follows;
|
|
86
69
|
#reading = false;
|
|
87
|
-
/** Counts nudges. A read issued before the latest nudge may miss its commit, so its reply leaves the watchers due. */
|
|
88
70
|
#nudges = 0;
|
|
89
71
|
constructor(session, follows) {
|
|
90
72
|
this.session = session;
|
|
@@ -96,7 +78,6 @@ class SessionFollow {
|
|
|
96
78
|
watcher.due = true;
|
|
97
79
|
this.drive();
|
|
98
80
|
}
|
|
99
|
-
/** Starts the read loop unless one is running; a running loop re-checks for due watchers after each read. */
|
|
100
81
|
drive() {
|
|
101
82
|
if (this.#reading)
|
|
102
83
|
return;
|
|
@@ -121,7 +102,6 @@ class SessionFollow {
|
|
|
121
102
|
this.#follows.failFollow(this, error instanceof Error ? error : new Error(String(error)));
|
|
122
103
|
return;
|
|
123
104
|
}
|
|
124
|
-
// No await since the last check: a nudge either marked a watcher due before that check, or finds the loop cleared.
|
|
125
105
|
this.#reading = false;
|
|
126
106
|
}
|
|
127
107
|
#nextDue() {
|
|
@@ -137,14 +117,12 @@ class SessionFollow {
|
|
|
137
117
|
watcher.fail(error);
|
|
138
118
|
}
|
|
139
119
|
}
|
|
140
|
-
/** One consumer's cursor and the pages it has not yet taken. The Session's read loop delivers pages; `take` waits for one. */
|
|
141
120
|
export class Watcher {
|
|
142
121
|
position;
|
|
143
122
|
ordinal;
|
|
144
123
|
since;
|
|
145
124
|
kinds;
|
|
146
125
|
follow;
|
|
147
|
-
/** A read is owed from this cursor: set by a nudge, by a `more` page, and by joining. */
|
|
148
126
|
due = true;
|
|
149
127
|
#pages = [];
|
|
150
128
|
#error;
|
|
@@ -162,17 +140,12 @@ export class Watcher {
|
|
|
162
140
|
get request() {
|
|
163
141
|
return { end: null, position: this.position, ordinal: this.ordinal, since: this.since, kinds: this.kinds };
|
|
164
142
|
}
|
|
165
|
-
/** Watchers with equal keys read the same request. */
|
|
166
143
|
get key() {
|
|
167
144
|
return JSON.stringify([this.position, this.ordinal, this.since, this.kinds]);
|
|
168
145
|
}
|
|
169
146
|
isWaitingAt(key) {
|
|
170
147
|
return this.key === key && !this.hasPages;
|
|
171
148
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Applies a page read from this cursor. A `not_modified` reply moves only the token. `settled` is false when a nudge
|
|
174
|
-
* arrived after the read was issued: the rows are still this cursor's facts, but the watcher stays due for another read.
|
|
175
|
-
*/
|
|
176
149
|
deliver(page, settled) {
|
|
177
150
|
if (page.delta === "not_modified") {
|
|
178
151
|
this.since = page.since;
|
|
@@ -199,7 +172,6 @@ export class Watcher {
|
|
|
199
172
|
this.#error = error;
|
|
200
173
|
this.#notify();
|
|
201
174
|
}
|
|
202
|
-
/** Waits for the next page, resolving `undefined` once `signal` aborts. Taking a page starts the next owed read. */
|
|
203
175
|
async take(signal) {
|
|
204
176
|
for (;;) {
|
|
205
177
|
if (this.#error)
|
|
@@ -223,7 +195,6 @@ export class Watcher {
|
|
|
223
195
|
});
|
|
224
196
|
}
|
|
225
197
|
}
|
|
226
|
-
/** A released watcher neither takes nor receives pages again. */
|
|
227
198
|
release() {
|
|
228
199
|
this.#pages.length = 0;
|
|
229
200
|
this.due = false;
|
package/dist/line.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** A frame the Host sends on the held line. A nudge names a Session and carries no saved fact. */
|
|
2
1
|
export type LineFrame = {
|
|
3
2
|
type: "hello";
|
|
4
3
|
line: number;
|
|
@@ -14,32 +13,22 @@ export type LineFrame = {
|
|
|
14
13
|
} | {
|
|
15
14
|
type: "ping";
|
|
16
15
|
};
|
|
17
|
-
/** The Host sent a frame outside the line's grammar: a length of 0 or above 16 KiB, or a payload that is no known frame. */
|
|
18
16
|
export declare class LineProtocolError extends Error {
|
|
19
17
|
readonly name = "LineProtocolError";
|
|
20
18
|
}
|
|
21
19
|
export interface LineHandler {
|
|
22
20
|
frame(frame: LineFrame): void;
|
|
23
|
-
/** Called once per line. `error` is set when the line ended by a socket error or a malformed frame. */
|
|
24
21
|
closed(line: Line, error: Error | undefined): void;
|
|
25
22
|
}
|
|
26
|
-
/**
|
|
27
|
-
* One held, notification-only connection to a Host (`GET /v1/line`, docs/contracts/inspection.md#live-line). The client
|
|
28
|
-
* sends `watch` frames and reads nudges. It holds no Session state; `Follows` decides what a nudge means.
|
|
29
|
-
*/
|
|
30
23
|
export declare class Line {
|
|
31
24
|
#private;
|
|
32
25
|
private constructor();
|
|
33
|
-
/** Upgrades to a line on the Host's socket. Resolves once the Host has switched protocols; a refusal rejects with its error. */
|
|
34
26
|
static open(options: {
|
|
35
27
|
socketPath: string;
|
|
36
28
|
instance: string;
|
|
37
29
|
handler: LineHandler;
|
|
38
30
|
}): Promise<Line>;
|
|
39
|
-
/** False once the line has ended, by either side. */
|
|
40
31
|
get isOpen(): boolean;
|
|
41
|
-
/** Replaces the watched set with `sessions`. The Host nudges each listed Session once. */
|
|
42
32
|
watch(sessions: readonly string[]): void;
|
|
43
|
-
/** Closes the socket. The handler's `closed` runs once, with no error. */
|
|
44
33
|
close(): void;
|
|
45
34
|
}
|
package/dist/line.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { request } from "node:http";
|
|
2
2
|
import { ConnectionError, refusal, WIRE_VERSION } from "./transport.js";
|
|
3
3
|
const MAX_FRAME_BYTES = 16 * 1024;
|
|
4
|
-
/** The Host sent a frame outside the line's grammar: a length of 0 or above 16 KiB, or a payload that is no known frame. */
|
|
5
4
|
export class LineProtocolError extends Error {
|
|
6
5
|
name = "LineProtocolError";
|
|
7
6
|
}
|
|
8
|
-
/**
|
|
9
|
-
* One held, notification-only connection to a Host (`GET /v1/line`, docs/contracts/inspection.md#live-line). The client
|
|
10
|
-
* sends `watch` frames and reads nudges. It holds no Session state; `Follows` decides what a nudge means.
|
|
11
|
-
*/
|
|
12
7
|
export class Line {
|
|
13
8
|
#socket;
|
|
14
9
|
#handler;
|
|
@@ -18,7 +13,6 @@ export class Line {
|
|
|
18
13
|
this.#socket = socket;
|
|
19
14
|
this.#handler = handler;
|
|
20
15
|
}
|
|
21
|
-
/** Upgrades to a line on the Host's socket. Resolves once the Host has switched protocols; a refusal rejects with its error. */
|
|
22
16
|
static open(options) {
|
|
23
17
|
return new Promise((resolve, reject) => {
|
|
24
18
|
const outgoing = request({
|
|
@@ -41,7 +35,6 @@ export class Line {
|
|
|
41
35
|
incoming.on("end", () => reject(refusal(incoming.statusCode, Buffer.concat(chunks))));
|
|
42
36
|
});
|
|
43
37
|
outgoing.on("upgrade", (_incoming, socket, head) => {
|
|
44
|
-
// Held while a watcher follows: a following script stays alive until its watch ends, and the line closes with the last one.
|
|
45
38
|
const line = new Line(socket, options.handler);
|
|
46
39
|
socket.on("data", (chunk) => line.#receive(chunk));
|
|
47
40
|
socket.on("error", (error) => line.#finish(new ConnectionError(error.message, { cause: error })));
|
|
@@ -53,15 +46,12 @@ export class Line {
|
|
|
53
46
|
outgoing.end();
|
|
54
47
|
});
|
|
55
48
|
}
|
|
56
|
-
/** False once the line has ended, by either side. */
|
|
57
49
|
get isOpen() {
|
|
58
50
|
return !this.#ended;
|
|
59
51
|
}
|
|
60
|
-
/** Replaces the watched set with `sessions`. The Host nudges each listed Session once. */
|
|
61
52
|
watch(sessions) {
|
|
62
53
|
this.#send({ type: "watch", sessions: [...sessions] });
|
|
63
54
|
}
|
|
64
|
-
/** Closes the socket. The handler's `closed` runs once, with no error. */
|
|
65
55
|
close() {
|
|
66
56
|
this.#finish(undefined);
|
|
67
57
|
}
|
package/dist/sessions.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { type ContentValue } from "./parts.ts";
|
|
|
4
4
|
import { type ReplyLimits } from "./transport.ts";
|
|
5
5
|
import type { components } from "./wire.ts";
|
|
6
6
|
export interface Link {
|
|
7
|
-
/** The client's one way to follow a Session. A link without it cannot `watch`. */
|
|
8
7
|
readonly follows?: Follows;
|
|
9
8
|
exchange(path: string, build: (store: string) => string, environment?: Buffer, limits?: ReplyLimits): Promise<Buffer>;
|
|
10
9
|
}
|
|
@@ -245,15 +244,6 @@ export interface ToolReloadOutcome {
|
|
|
245
244
|
/** Tools the server listed that the offered set left out (a clashing name, a name too long after prefixing, or the record limit). */
|
|
246
245
|
leftOut: number;
|
|
247
246
|
}
|
|
248
|
-
/**
|
|
249
|
-
* Asks the Host to list one MCP server, or every configured server, again, then polls `tools_status` until each asked
|
|
250
|
-
* generation has landed. An empty ask resolves at once with no poll. Rejects with RuiWaitTimeoutError after 60 s.
|
|
251
|
-
*
|
|
252
|
-
* Landing follows the CLI's owner (`toolsProgress` in client.zig): a server has landed in the Host that asked once
|
|
253
|
-
* its finished generation reaches the ask's; a Host with another instance has restarted its generations, so a
|
|
254
|
-
* server has landed there once any list has finished. A missing row, or `never` once landed, is an invalid reply.
|
|
255
|
-
*/
|
|
256
247
|
export declare function reloadTools(link: Link, server?: string): Promise<ToolReloadOutcome[]>;
|
|
257
|
-
/** Reads `tools_status`; undefined while the Host is busy. Exported for the tests that read each row. */
|
|
258
248
|
export declare function readToolsStatus(link: Link): Promise<Schemas["ToolsStatusReply"] | undefined>;
|
|
259
249
|
export {};
|
package/dist/sessions.js
CHANGED
|
@@ -289,7 +289,6 @@ export class Sessions {
|
|
|
289
289
|
for (;;) {
|
|
290
290
|
const wireAfter = after;
|
|
291
291
|
const wireCeiling = ceiling;
|
|
292
|
-
// The live roster: the Archived window reply (the one with `next.more_above`) is read by its own client.
|
|
293
292
|
const page = parse(await this.#link.exchange("/v1/list-sessions", (store) => JSON.stringify({
|
|
294
293
|
version: WIRE_VERSION,
|
|
295
294
|
kind: "list_sessions",
|
|
@@ -331,14 +330,6 @@ export async function setPaused(link, paused) {
|
|
|
331
330
|
}
|
|
332
331
|
const RELOAD_POLL_MS = 250;
|
|
333
332
|
const RELOAD_WAIT_MS = 60_000;
|
|
334
|
-
/**
|
|
335
|
-
* Asks the Host to list one MCP server, or every configured server, again, then polls `tools_status` until each asked
|
|
336
|
-
* generation has landed. An empty ask resolves at once with no poll. Rejects with RuiWaitTimeoutError after 60 s.
|
|
337
|
-
*
|
|
338
|
-
* Landing follows the CLI's owner (`toolsProgress` in client.zig): a server has landed in the Host that asked once
|
|
339
|
-
* its finished generation reaches the ask's; a Host with another instance has restarted its generations, so a
|
|
340
|
-
* server has landed there once any list has finished. A missing row, or `never` once landed, is an invalid reply.
|
|
341
|
-
*/
|
|
342
333
|
export async function reloadTools(link, server) {
|
|
343
334
|
const reply = parse(await link.exchange("/v1/control/tools-reload", (store) => JSON.stringify({
|
|
344
335
|
version: WIRE_VERSION,
|
|
@@ -366,7 +357,6 @@ export async function reloadTools(link, server) {
|
|
|
366
357
|
await new Promise((resolve) => setTimeout(resolve, Math.min(RELOAD_POLL_MS, remaining)));
|
|
367
358
|
}
|
|
368
359
|
}
|
|
369
|
-
/** Reads `tools_status`; undefined while the Host is busy. Exported for the tests that read each row. */
|
|
370
360
|
export async function readToolsStatus(link) {
|
|
371
361
|
try {
|
|
372
362
|
return parse(await link.exchange("/v1/tools-status", (store) => JSON.stringify({
|
package/dist/settings.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ type Input<T> = T extends {
|
|
|
9
9
|
} : T;
|
|
10
10
|
/** The generated Host document, with pipe-only secret strings and byte-array paths. */
|
|
11
11
|
export type HostSettings = Omit<Input<components["schemas"]["HostSettings"]>, "presets"> & {
|
|
12
|
-
/** Uses the same friendly Session spec and writer as sessions.create. */
|
|
13
12
|
/** Connect-time presets take every agent setting but `appTools`: a lane root declares app tools on create or configure. */
|
|
14
13
|
presets?: Record<string, Omit<AgentSpec, "appTools">>;
|
|
15
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruicode",
|
|
3
|
-
"version": "0.98.
|
|
3
|
+
"version": "0.98.14",
|
|
4
4
|
"description": "Start a Rui Host as a child process and talk to it over its local socket.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"mcp"
|
|
33
33
|
],
|
|
34
34
|
"optionalDependencies": {
|
|
35
|
-
"ruicode-linux-x64": "0.98.
|
|
36
|
-
"ruicode-linux-arm64": "0.98.
|
|
37
|
-
"ruicode-darwin-arm64": "0.98.
|
|
35
|
+
"ruicode-linux-x64": "0.98.14",
|
|
36
|
+
"ruicode-linux-arm64": "0.98.14",
|
|
37
|
+
"ruicode-darwin-arm64": "0.98.14"
|
|
38
38
|
}
|
|
39
39
|
}
|