@cotal-ai/workspace 0.133.12 → 0.134.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.
Files changed (49) hide show
  1. package/build/Release/darwin-arm64/build.json +1 -1
  2. package/build/Release/darwin-x64/build.json +1 -1
  3. package/build/Release/win32-arm64/build.json +1 -1
  4. package/build/Release/win32-x64/build.json +1 -1
  5. package/dist/control/actions.d.ts +141 -0
  6. package/dist/control/actions.d.ts.map +1 -0
  7. package/dist/control/actions.js +192 -0
  8. package/dist/control/actions.js.map +1 -0
  9. package/dist/control/dial-retry.d.ts +33 -0
  10. package/dist/control/dial-retry.d.ts.map +1 -0
  11. package/dist/control/dial-retry.js +70 -0
  12. package/dist/control/dial-retry.js.map +1 -0
  13. package/dist/control/index.d.ts +5 -0
  14. package/dist/control/index.d.ts.map +1 -0
  15. package/dist/control/index.js +5 -0
  16. package/dist/control/index.js.map +1 -0
  17. package/dist/control/manager.d.ts +291 -0
  18. package/dist/control/manager.d.ts.map +1 -0
  19. package/dist/control/manager.js +769 -0
  20. package/dist/control/manager.js.map +1 -0
  21. package/dist/control/seat.d.ts +168 -0
  22. package/dist/control/seat.d.ts.map +1 -0
  23. package/dist/control/seat.js +225 -0
  24. package/dist/control/seat.js.map +1 -0
  25. package/dist/launch.d.ts +94 -0
  26. package/dist/launch.d.ts.map +1 -0
  27. package/dist/launch.js +58 -0
  28. package/dist/launch.js.map +1 -0
  29. package/dist/maintenance.d.ts +7 -0
  30. package/dist/maintenance.d.ts.map +1 -1
  31. package/dist/maintenance.js +24 -0
  32. package/dist/maintenance.js.map +1 -1
  33. package/dist/output.d.ts +2 -0
  34. package/dist/output.d.ts.map +1 -1
  35. package/dist/output.js +5 -0
  36. package/dist/output.js.map +1 -1
  37. package/dist/view/index.d.ts +3 -0
  38. package/dist/view/index.d.ts.map +1 -0
  39. package/dist/view/index.js +3 -0
  40. package/dist/view/index.js.map +1 -0
  41. package/dist/view/mesh-view.d.ts +225 -0
  42. package/dist/view/mesh-view.d.ts.map +1 -0
  43. package/dist/view/mesh-view.js +550 -0
  44. package/dist/view/mesh-view.js.map +1 -0
  45. package/dist/view/observer.d.ts +26 -0
  46. package/dist/view/observer.d.ts.map +1 -0
  47. package/dist/view/observer.js +26 -0
  48. package/dist/view/observer.js.map +1 -0
  49. package/package.json +18 -4
@@ -3,7 +3,7 @@
3
3
  "platform": "darwin",
4
4
  "arch": "arm64",
5
5
  "nodeApi": 8,
6
- "source": "ecd34853a9a34e222011fa79722138de83200ab2",
6
+ "source": "22a7b35b019860833cafd6d1442c1a3f878fc414",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -3,7 +3,7 @@
3
3
  "platform": "darwin",
4
4
  "arch": "x64",
5
5
  "nodeApi": 8,
6
- "source": "ecd34853a9a34e222011fa79722138de83200ab2",
6
+ "source": "22a7b35b019860833cafd6d1442c1a3f878fc414",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -3,7 +3,7 @@
3
3
  "platform": "win32",
4
4
  "arch": "arm64",
5
5
  "nodeApi": 8,
6
- "source": "ecd34853a9a34e222011fa79722138de83200ab2",
6
+ "source": "22a7b35b019860833cafd6d1442c1a3f878fc414",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -3,7 +3,7 @@
3
3
  "platform": "win32",
4
4
  "arch": "x64",
5
5
  "nodeApi": 8,
6
- "source": "ecd34853a9a34e222011fa79722138de83200ab2",
6
+ "source": "22a7b35b019860833cafd6d1442c1a3f878fc414",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -0,0 +1,141 @@
1
+ import { type ConnectFlags } from "../connect.js";
2
+ import { type ControlClient, type ManagerReply } from "./manager.js";
3
+ /** The console's control coordinates: the same `ConnectFlags` triple the CLI's control commands
4
+ * resolve from. `space` is the one the console is currently watching. */
5
+ export type ControlCtx = ConnectFlags;
6
+ /** The manager ops the console drives, each with the instrument profile the matching CLI command
7
+ * mints and whether the op names a seat (a targeted op resolves seat locality first, so it is
8
+ * served by the manager actually hosting the seat). */
9
+ declare const OPS: {
10
+ readonly status: {
11
+ readonly profile: "control-caller-privileged";
12
+ readonly targeted: true;
13
+ };
14
+ readonly start: {
15
+ readonly profile: "control-caller-privileged";
16
+ readonly targeted: false;
17
+ readonly timeoutMs: 40000;
18
+ };
19
+ readonly purge: {
20
+ readonly profile: "control-caller-admin";
21
+ readonly targeted: false;
22
+ };
23
+ readonly stop: {
24
+ readonly profile: "control-caller-admin";
25
+ readonly targeted: true;
26
+ };
27
+ };
28
+ export type ControlOp = keyof typeof OPS;
29
+ /** Delete one channel: its retained history (a filtered purge) and its registry entry, through
30
+ * core's `clearChannel`, the operation the web dashboard's delete button runs, with the same
31
+ * per-action authority: a static-auth mesh mints a one-shot `channel-purger` credential from the
32
+ * resolved mesh's seed, a user mesh asks for a `channel-purger` view (a fresh ledger check per
33
+ * click), an open mesh connects bare. No manager involved. The name must be the one the mesh
34
+ * uses, concrete and valid: a wildcard is refused (it would purge channels the operator did not
35
+ * name) and a name the wire would rewrite is refused rather than quietly rewritten. */
36
+ export declare function deleteChannel(ctx: ControlCtx, channel: string): Promise<{
37
+ ok: true;
38
+ purged: number;
39
+ } | {
40
+ ok: false;
41
+ error: string;
42
+ }>;
43
+ /** One managed-agent row as the manager's `ps` / `inspect` answer it (the fields the console reads). */
44
+ export interface ManagedRow {
45
+ name: string;
46
+ id: string;
47
+ role?: string;
48
+ agent: string;
49
+ mode: string;
50
+ status: string;
51
+ uptimeMs: number;
52
+ mesh: string;
53
+ model?: string;
54
+ }
55
+ /** One control call. A targeted op names its seat in `args.name`; the alias is resolved to the
56
+ * incarnation triple inside `askManager` (the manager's `inspect` read), so the wire never carries
57
+ * a name as a target. Reach is `owner` on a user mesh (the bearer's one path; the manager decides
58
+ * by ledger scope) and `any` on a static or open mesh (the admin instrument's cross-agent row). */
59
+ export declare function control(client: ControlClient, ctx: ControlCtx, op: ControlOp, args?: Record<string, unknown>): Promise<ManagerReply>;
60
+ /** The managed rows of every reachable manager in the space: the `cotal ps` read.
61
+ *
62
+ * `rows` is the merged list, `silent` the instances that did not answer, `failed` the reachable
63
+ * instances that answered with an error, and `answered` the rows attributed to the instance that
64
+ * served them. The attribution is what makes a partial answer
65
+ * usable: a caller holding state across polls can replace exactly the instances that spoke and
66
+ * keep only what a silent one last said, which neither a merged list nor a flat rebuild allows.
67
+ * `cotal ps` prints a silent instance rather than dropping it, and the console must not be the
68
+ * one surface that quietly answers a narrower question than the one asked. */
69
+ export type PsReply = {
70
+ ok: true;
71
+ rows: ManagedRow[];
72
+ silent: string[];
73
+ failed: {
74
+ instanceId: string;
75
+ error: string;
76
+ }[];
77
+ answered: {
78
+ instanceId: string;
79
+ rows: ManagedRow[];
80
+ }[];
81
+ } | {
82
+ ok: false;
83
+ error: string;
84
+ };
85
+ /** Fold one ps answer into the rows held per manager instance, which is the only shape that can
86
+ * both DROP a despawned seat and KEEP a quiet manager's seats.
87
+ *
88
+ * An instance that answered has its rows replaced wholesale, so a seat it no longer lists is gone
89
+ * on that tick. An instance that was asked and stayed silent keeps what it last said, because a
90
+ * seat is not gone just because nobody could be reached to ask about it. An instance that is
91
+ * neither has left the registry, and its rows leave with it.
92
+ *
93
+ * A flat merge across instances cannot express the first of those: it can add and overwrite but
94
+ * never delete, so one silent registration, which can persist indefinitely when a manager's host
95
+ * dies without deregistering, would freeze every other manager's seats in place forever. A flat
96
+ * rebuild is the opposite error, emptying a quiet manager's seats off the display. */
97
+ export declare function foldManagedRows(prev: Map<string, ManagedRow[]>, reply: {
98
+ answered: {
99
+ instanceId: string;
100
+ rows: ManagedRow[];
101
+ }[];
102
+ silent: string[];
103
+ }): Map<string, ManagedRow[]>;
104
+ /** The per-instance rows flattened to the id-keyed harness facts the roster and detail card read. */
105
+ export declare function managedById(byInstance: Map<string, ManagedRow[]>): Map<string, {
106
+ agent?: string;
107
+ mode?: string;
108
+ }>;
109
+ /** What one tick did, so a caller (and a test) can tell the three apart. */
110
+ export type PollOutcome = "applied" | "skipped" | "stopped";
111
+ /** The managed-row poll, SINGLE FLIGHT. One read may outlast the interval that scheduled it: the
112
+ * scatter alone budgets a service resolve, a gather and a reconcile, and the resolve and mint in
113
+ * front of it are additional. Left unguarded, two reads overlap and are applied in COMPLETION
114
+ * order rather than request order, so an older answer can land after a newer one and restore the
115
+ * very rows the newer one retired. That is the fold's own guarantee undone one layer up, and no
116
+ * test of the fold can see it.
117
+ *
118
+ * A tick while a read is in flight is therefore skipped outright rather than queued: the state is
119
+ * a snapshot of the whole space, so a skipped tick loses nothing that the next one will not carry,
120
+ * and skipping also bounds how much control traffic a slow mesh can accumulate. Being single
121
+ * flight is also what keeps a STALE FAILURE from stopping the poll after a newer success, since
122
+ * there can be no newer success in flight to race.
123
+ *
124
+ * Stopping on a failed read is deliberate and reported by the caller: an open mesh with no
125
+ * supervisor must not knock every tick. */
126
+ export declare function createManagedPoller(read: () => Promise<PsReply>, on: {
127
+ rows(flat: Map<string, {
128
+ agent?: string;
129
+ mode?: string;
130
+ }>): void;
131
+ partial(silent: string[], failed: {
132
+ instanceId: string;
133
+ error: string;
134
+ }[]): void;
135
+ stopped(error: string): void;
136
+ }): {
137
+ tick(): Promise<PollOutcome>;
138
+ };
139
+ export declare function controlPs(client: ControlClient, ctx: ControlCtx): Promise<PsReply>;
140
+ export {};
141
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/control/actions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAEhF,OAAO,EAAgD,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAGnH;0EAC0E;AAC1E,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC;AAEtC;;wDAEwD;AACxD,QAAA,MAAM,GAAG;;;;;;;;;;;;;;;;;;CAQC,CAAC;AACX,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,GAAG,CAAC;AAEzC;;;;;;wFAMwF;AACxF,wBAAsB,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAc1I;AAED,wGAAwG;AACxG,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;oGAGoG;AACpG,wBAAsB,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,M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OAAO,CAAC,EAC5B,EAAE,EAAE;IAAE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACvL;IAAE,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAAA;CAAE,CA+BlC;AACD,wBAAsB,SAAS,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBxF"}
@@ -0,0 +1,192 @@
1
+ // The console's control door: every operator action (kill / spawn / purge / status) is ONE call
2
+ // through the CLI's own per-action path (`ps` is the scatter below, one call per manager) — `resolveControlTarget` resolves
3
+ // the mesh and mints a one-shot instrument (or connects bare on an open mesh), `askManager` rides
4
+ // the ep rails, and nothing survives the call. The observer endpoint the console watches through
5
+ // never carries control, and the console never holds a seed or a standing instrument: the only
6
+ // thing it keeps is the `--space` / `--server` / `--creds` triple the CLI's control commands take.
7
+ //
8
+ // Every refusal comes back as a `{ok:false, error}` the status line can show. The THROWING resolve
9
+ // form is used throughout (`onRefusal: "throw"`): the CLI commands' default prints a sentence and
10
+ // exits the process, which inside a TUI would blank the screen mid-session.
11
+ import { assertValidChannel, clearChannel, isConcreteChannel } from "@cotal-ai/core";
12
+ import { connectOrThrow, userViewAuth } from "../connect.js";
13
+ import { resolveControlTarget } from "../control-target.js";
14
+ import { askManager, scatterManager, START_TIMEOUT_MS } from "./manager.js";
15
+ import { locateSeat, seatMissRefusal, seatNotFoundMessage } from "./seat.js";
16
+ /** The manager ops the console drives, each with the instrument profile the matching CLI command
17
+ * mints and whether the op names a seat (a targeted op resolves seat locality first, so it is
18
+ * served by the manager actually hosting the seat). */
19
+ const OPS = {
20
+ // `status` is `inspect` on the manager that HOSTS the seat: a multi-manager space answers a
21
+ // class-queue call from whichever manager is quickest, which may not be the host, and reports a
22
+ // false miss. Located and pinned like `stop`.
23
+ status: { profile: "control-caller-privileged", targeted: true },
24
+ start: { profile: "control-caller-privileged", targeted: false, timeoutMs: START_TIMEOUT_MS },
25
+ purge: { profile: "control-caller-admin", targeted: false },
26
+ stop: { profile: "control-caller-admin", targeted: true },
27
+ };
28
+ /** Delete one channel: its retained history (a filtered purge) and its registry entry, through
29
+ * core's `clearChannel`, the operation the web dashboard's delete button runs, with the same
30
+ * per-action authority: a static-auth mesh mints a one-shot `channel-purger` credential from the
31
+ * resolved mesh's seed, a user mesh asks for a `channel-purger` view (a fresh ledger check per
32
+ * click), an open mesh connects bare. No manager involved. The name must be the one the mesh
33
+ * uses, concrete and valid: a wildcard is refused (it would purge channels the operator did not
34
+ * name) and a name the wire would rewrite is refused rather than quietly rewritten. */
35
+ export async function deleteChannel(ctx, channel) {
36
+ try {
37
+ assertValidChannel(channel);
38
+ if (!isConcreteChannel(channel))
39
+ return { ok: false, error: `"${channel}" is a wildcard, not a deletable channel` };
40
+ const conn = await connectOrThrow(ctx, "channel-purger");
41
+ const r = conn.bearer
42
+ ? await userViewAuth(conn, "channel-purger").then((p) => clearChannel({ servers: conn.server, space: conn.space, channel, bearer: p.bearer, sentinelCreds: p.sentinelCreds }))
43
+ : await clearChannel({ servers: conn.server, space: conn.space, channel, creds: conn.creds });
44
+ return { ok: true, purged: r.purged };
45
+ }
46
+ catch (e) {
47
+ return { ok: false, error: e.message };
48
+ }
49
+ }
50
+ /** One control call. A targeted op names its seat in `args.name`; the alias is resolved to the
51
+ * incarnation triple inside `askManager` (the manager's `inspect` read), so the wire never carries
52
+ * a name as a target. Reach is `owner` on a user mesh (the bearer's one path; the manager decides
53
+ * by ledger scope) and `any` on a static or open mesh (the admin instrument's cross-agent row). */
54
+ export async function control(client, ctx, op, args) {
55
+ const spec = OPS[op];
56
+ try {
57
+ let on;
58
+ if (spec.targeted) {
59
+ const name = String(args?.name ?? "").trim();
60
+ if (!name)
61
+ return { ok: false, error: `${op} requires a name` };
62
+ const loc = await locateSeat(client, ctx, name, { onRefusal: "throw" });
63
+ if (loc.kind === "absent")
64
+ return { ok: false, error: seatNotFoundMessage(loc, name) };
65
+ if (loc.kind === "several")
66
+ return { ok: false, error: seatMissRefusal(name, `cotal ${op}`, loc) };
67
+ if (loc.kind === "pin")
68
+ on = loc.instanceId;
69
+ }
70
+ const t = await resolveControlTarget(ctx, spec.profile, on, { onRefusal: "throw" });
71
+ const reach = t.auth.bearer ? "owner" : "any";
72
+ const timeoutMs = "timeoutMs" in spec ? spec.timeoutMs : undefined;
73
+ // `args` goes through as given: a void-input command is refused by the manager's schema when it
74
+ // is handed `{}` instead of nothing, so no default is filled in here.
75
+ return await askManager(client, t.space, t.server, op, args, t.auth, reach, timeoutMs, spec.targeted ? { instanceId: on } : undefined);
76
+ }
77
+ catch (e) {
78
+ return { ok: false, error: e.message };
79
+ }
80
+ }
81
+ /** The single manager a user-mesh bearer reaches, which has no scatter and therefore no instance
82
+ * id of its own. A caller keeping rows per instance needs one key for it. */
83
+ const BEARER_INSTANCE = "owner";
84
+ /** Fold one ps answer into the rows held per manager instance, which is the only shape that can
85
+ * both DROP a despawned seat and KEEP a quiet manager's seats.
86
+ *
87
+ * An instance that answered has its rows replaced wholesale, so a seat it no longer lists is gone
88
+ * on that tick. An instance that was asked and stayed silent keeps what it last said, because a
89
+ * seat is not gone just because nobody could be reached to ask about it. An instance that is
90
+ * neither has left the registry, and its rows leave with it.
91
+ *
92
+ * A flat merge across instances cannot express the first of those: it can add and overwrite but
93
+ * never delete, so one silent registration, which can persist indefinitely when a manager's host
94
+ * dies without deregistering, would freeze every other manager's seats in place forever. A flat
95
+ * rebuild is the opposite error, emptying a quiet manager's seats off the display. */
96
+ export function foldManagedRows(prev, reply) {
97
+ const next = new Map(prev);
98
+ for (const id of [...next.keys()])
99
+ if (!reply.answered.some((a) => a.instanceId === id) && !reply.silent.includes(id))
100
+ next.delete(id);
101
+ for (const a of reply.answered)
102
+ next.set(a.instanceId, a.rows);
103
+ return next;
104
+ }
105
+ /** The per-instance rows flattened to the id-keyed harness facts the roster and detail card read. */
106
+ export function managedById(byInstance) {
107
+ const flat = new Map();
108
+ for (const rows of byInstance.values())
109
+ for (const a of rows)
110
+ flat.set(a.id, { agent: a.agent, mode: a.mode });
111
+ return flat;
112
+ }
113
+ /** The managed-row poll, SINGLE FLIGHT. One read may outlast the interval that scheduled it: the
114
+ * scatter alone budgets a service resolve, a gather and a reconcile, and the resolve and mint in
115
+ * front of it are additional. Left unguarded, two reads overlap and are applied in COMPLETION
116
+ * order rather than request order, so an older answer can land after a newer one and restore the
117
+ * very rows the newer one retired. That is the fold's own guarantee undone one layer up, and no
118
+ * test of the fold can see it.
119
+ *
120
+ * A tick while a read is in flight is therefore skipped outright rather than queued: the state is
121
+ * a snapshot of the whole space, so a skipped tick loses nothing that the next one will not carry,
122
+ * and skipping also bounds how much control traffic a slow mesh can accumulate. Being single
123
+ * flight is also what keeps a STALE FAILURE from stopping the poll after a newer success, since
124
+ * there can be no newer success in flight to race.
125
+ *
126
+ * Stopping on a failed read is deliberate and reported by the caller: an open mesh with no
127
+ * supervisor must not knock every tick. */
128
+ export function createManagedPoller(read, on) {
129
+ let byInstance = new Map();
130
+ let inFlight = false;
131
+ let stopped = false;
132
+ let announcedPartial = "";
133
+ return {
134
+ async tick() {
135
+ if (stopped)
136
+ return "stopped";
137
+ if (inFlight)
138
+ return "skipped";
139
+ inFlight = true;
140
+ try {
141
+ const r = await read();
142
+ if (!r.ok) {
143
+ stopped = true;
144
+ on.stopped(r.error);
145
+ return "stopped";
146
+ }
147
+ const partialKey = JSON.stringify({ silent: r.silent, failed: r.failed });
148
+ if ((r.silent.length || r.failed.length) && partialKey !== announcedPartial) {
149
+ announcedPartial = partialKey;
150
+ on.partial(r.silent, r.failed);
151
+ }
152
+ if (!r.silent.length && !r.failed.length)
153
+ announcedPartial = "";
154
+ byInstance = foldManagedRows(byInstance, r);
155
+ on.rows(managedById(byInstance));
156
+ return "applied";
157
+ }
158
+ finally {
159
+ inFlight = false;
160
+ }
161
+ },
162
+ };
163
+ }
164
+ export async function controlPs(client, ctx) {
165
+ try {
166
+ const t = await resolveControlTarget(ctx, "control-caller-privileged", undefined, { onRefusal: "throw" });
167
+ if (t.auth.bearer) {
168
+ const r = await askManager(client, t.space, t.server, "ps", undefined, t.auth, "owner", undefined, {});
169
+ if (!r.ok)
170
+ return { ok: false, error: r.error ?? "error" };
171
+ const rows = r.data ?? [];
172
+ return { ok: true, rows, silent: [], failed: [], answered: [{ instanceId: BEARER_INSTANCE, rows }] };
173
+ }
174
+ const s = await scatterManager(client, t.space, t.server, "ps", t.auth, t.spaceAuth);
175
+ if (!s.ok)
176
+ return s;
177
+ const answered = s.instances
178
+ .filter((i) => i.reachable && !i.error)
179
+ .map((i) => ({ instanceId: i.instanceId, rows: (i.data ?? []) }));
180
+ return {
181
+ ok: true,
182
+ rows: answered.flatMap((i) => i.rows),
183
+ silent: s.instances.filter((i) => !i.reachable).map((i) => i.instanceId),
184
+ failed: s.instances.filter((i) => i.reachable && i.error).map((i) => ({ instanceId: i.instanceId, error: i.error })),
185
+ answered,
186
+ };
187
+ }
188
+ catch (e) {
189
+ return { ok: false, error: e.message };
190
+ }
191
+ }
192
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/control/actions.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,4HAA4H;AAC5H,kGAAkG;AAClG,iGAAiG;AACjG,+FAA+F;AAC/F,mGAAmG;AACnG,EAAE;AACF,mGAAmG;AACnG,kGAAkG;AAClG,4EAA4E;AAC5E,OAAO,EAAE,kBAA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C,UAAU,EAAE,IAAI,EAAE,CAAE,CAAC,CAAC,IAAqB,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACtF,OAAO;YACL,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YACrC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;YACxE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,KAAM,EAAE,CAAC,CAAC;YACrH,QAAQ;SACT,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAG,CAAW,CAAC,OAAO,EAAE,CAAC;IACpD,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { ConnectRefusal } from "../connect.js";
2
+ /** Attempts a refused or timed-out connect gets, the first included. Nothing is published on a
3
+ * connection that never opened, so trying it again repeats nothing. */
4
+ export declare const DIAL_ATTEMPTS = 4;
5
+ /** The fixed wait between those attempts, in milliseconds. */
6
+ export declare const DIAL_RETRY_WAIT_MS = 1000;
7
+ /** How long one connect may take, in milliseconds. A connect that is admitted finishes well inside
8
+ * it; a broker waiting on an auth service that does not answer would otherwise hold it for the
9
+ * transport's 20 seconds. */
10
+ export declare const DIAL_TIMEOUT_MS = 5000;
11
+ /** How a connect that never opened ended: the broker refused the credential, or the connection did
12
+ * not open in time. */
13
+ export type DialStage = "refused" | "timeout";
14
+ /** The stage a failed connect ended at, or undefined for any other failure, which is not retried. */
15
+ export declare function dialStage(e: unknown): DialStage | undefined;
16
+ /** Every attempt at a connect ended at the same boundary, so nothing was sent on any of them. */
17
+ export declare class DialNotAdmitted extends Error {
18
+ readonly stage: DialStage;
19
+ readonly attempts: number;
20
+ readonly last: unknown;
21
+ constructor(stage: DialStage, attempts: number, last: unknown);
22
+ }
23
+ /** Run `dial` until it opens, trying again after a refused or timed-out attempt, up to
24
+ * {@link DIAL_ATTEMPTS}. Throws {@link DialNotAdmitted} when every attempt ended that way, and any
25
+ * other failure at once. `dial` builds its connection afresh each time. */
26
+ export declare function dialWithRetry<T>(dial: () => Promise<T>): Promise<T>;
27
+ /** A connection the broker did not admit on any attempt, as a refusal at the connect stage: `to` is
28
+ * what the command connects to and `unsent` what it therefore did not send. It says how the
29
+ * attempts ended in plain words; the broker's own words stay in the native detail. On a user-auth
30
+ * mesh the auth service decides admission at connect, as the view exchange decides it before; a
31
+ * refused view is transient there, so this refusal is transient too. */
32
+ export declare function notAdmittedRefusal(e: DialNotAdmitted, to: string, unsent: string, target: Record<string, unknown>, userAuth: boolean): ConnectRefusal;
33
+ //# sourceMappingURL=dial-retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dial-retry.d.ts","sourceRoot":"","sources":["../../src/control/dial-retry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;wEACwE;AACxE,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,8DAA8D;AAC9D,eAAO,MAAM,kBAAkB,OAAQ,CAAC;AACxC;;8BAE8B;AAC9B,eAAO,MAAM,eAAe,OAAQ,CAAC;AAErC;wBACwB;AACxB,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE9C,qGAAqG;AACrG,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAI3D;AAED,iGAAiG;AACjG,qBAAa,eAAgB,SAAQ,KAAK;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO;gBAAnE,KAAK,EAAE,SAAS,EAAW,QAAQ,EAAE,MAAM,EAAW,IAAI,EAAE,OAAO;CAIzF;AAED;;4EAE4E;AAC5E,wBAAsB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAWzE;AAED;;;;yEAIyE;AACzE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,cAAc,CAWrJ"}
@@ -0,0 +1,70 @@
1
+ import { setTimeout as delay } from "node:timers/promises";
2
+ import { TimeoutError } from "@nats-io/transport-node";
3
+ import { isAuthRejection } from "@cotal-ai/core";
4
+ import { ConnectRefusal } from "../connect.js";
5
+ /** Attempts a refused or timed-out connect gets, the first included. Nothing is published on a
6
+ * connection that never opened, so trying it again repeats nothing. */
7
+ export const DIAL_ATTEMPTS = 4;
8
+ /** The fixed wait between those attempts, in milliseconds. */
9
+ export const DIAL_RETRY_WAIT_MS = 1_000;
10
+ /** How long one connect may take, in milliseconds. A connect that is admitted finishes well inside
11
+ * it; a broker waiting on an auth service that does not answer would otherwise hold it for the
12
+ * transport's 20 seconds. */
13
+ export const DIAL_TIMEOUT_MS = 5_000;
14
+ /** The stage a failed connect ended at, or undefined for any other failure, which is not retried. */
15
+ export function dialStage(e) {
16
+ if (isAuthRejection(e))
17
+ return "refused";
18
+ if (e instanceof TimeoutError)
19
+ return "timeout";
20
+ return undefined;
21
+ }
22
+ /** Every attempt at a connect ended at the same boundary, so nothing was sent on any of them. */
23
+ export class DialNotAdmitted extends Error {
24
+ stage;
25
+ attempts;
26
+ last;
27
+ constructor(stage, attempts, last) {
28
+ super(last instanceof Error ? last.message : String(last), { cause: last });
29
+ this.stage = stage;
30
+ this.attempts = attempts;
31
+ this.last = last;
32
+ this.name = "DialNotAdmitted";
33
+ }
34
+ }
35
+ /** Run `dial` until it opens, trying again after a refused or timed-out attempt, up to
36
+ * {@link DIAL_ATTEMPTS}. Throws {@link DialNotAdmitted} when every attempt ended that way, and any
37
+ * other failure at once. `dial` builds its connection afresh each time. */
38
+ export async function dialWithRetry(dial) {
39
+ for (let attempt = 1;; attempt++) {
40
+ try {
41
+ return await dial();
42
+ }
43
+ catch (e) {
44
+ const stage = dialStage(e);
45
+ if (!stage)
46
+ throw e;
47
+ if (attempt >= DIAL_ATTEMPTS)
48
+ throw new DialNotAdmitted(stage, attempt, e);
49
+ await delay(DIAL_RETRY_WAIT_MS);
50
+ }
51
+ }
52
+ }
53
+ /** A connection the broker did not admit on any attempt, as a refusal at the connect stage: `to` is
54
+ * what the command connects to and `unsent` what it therefore did not send. It says how the
55
+ * attempts ended in plain words; the broker's own words stay in the native detail. On a user-auth
56
+ * mesh the auth service decides admission at connect, as the view exchange decides it before; a
57
+ * refused view is transient there, so this refusal is transient too. */
58
+ export function notAdmittedRefusal(e, to, unsent, target, userAuth) {
59
+ const how = e.stage === "refused" ? `the broker refused all ${e.attempts} attempts` : `none of ${e.attempts} attempts opened within ${DIAL_TIMEOUT_MS / 1000} seconds`;
60
+ const message = `could not connect to ${to}: ${how}, so ${unsent}`;
61
+ const remedy = e.stage === "refused"
62
+ ? userAuth ? "the space's auth service logs why it refused this connection" : undefined
63
+ : "nothing was sent, so the command can be run again once the broker admits connections";
64
+ return new ConnectRefusal(remedy ? `✗ ${message} - ${remedy}` : `✗ ${message}`, undefined, {
65
+ cause: e, kind: "transient", code: e.stage === "refused" ? "PERMISSION_DENIED" : "TARGET_UNAVAILABLE",
66
+ ...(remedy ? { parts: { message, remedy } } : {}), target,
67
+ native: { code: `connect-${e.stage}`, detail: { stage: "connect", attempts: e.attempts, reason: e.message } },
68
+ });
69
+ }
70
+ //# sourceMappingURL=dial-retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dial-retry.js","sourceRoot":"","sources":["../../src/control/dial-retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;wEACwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,8DAA8D;AAC9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACxC;;8BAE8B;AAC9B,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAMrC,qGAAqG;AACrG,MAAM,UAAU,SAAS,CAAC,CAAU;IAClC,IAAI,eAAe,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,CAAC,YAAY,YAAY;QAAE,OAAO,SAAS,CAAC;IAChD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iGAAiG;AACjG,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACnB;IAA2B;IAA2B;IAA3E,YAAqB,KAAgB,EAAW,QAAgB,EAAW,IAAa;QACtF,KAAK,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QADzD,UAAK,GAAL,KAAK,CAAW;QAAW,aAAQ,GAAR,QAAQ,CAAQ;QAAW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,CAAC,KAAK,OAAO,EAAE,EAAE,SAAS,EAAE;QACzF,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,oBAAoB;QACrG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM;QACzD,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;KAC9G,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./dial-retry.js";
2
+ export * from "./manager.js";
3
+ export * from "./seat.js";
4
+ export * from "./actions.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/control/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./dial-retry.js";
2
+ export * from "./manager.js";
3
+ export * from "./seat.js";
4
+ export * from "./actions.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/control/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}