@cotal-ai/core 0.171.3 → 0.171.5

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 (43) hide show
  1. package/dist/control-exchange.d.ts.map +1 -1
  2. package/dist/control-exchange.js +3 -4
  3. package/dist/control-exchange.js.map +1 -1
  4. package/dist/endpoint-anycast.d.ts +110 -0
  5. package/dist/endpoint-anycast.d.ts.map +1 -0
  6. package/dist/endpoint-anycast.js +316 -0
  7. package/dist/endpoint-anycast.js.map +1 -0
  8. package/dist/endpoint-connection.d.ts +363 -0
  9. package/dist/endpoint-connection.d.ts.map +1 -0
  10. package/dist/endpoint-connection.js +741 -0
  11. package/dist/endpoint-connection.js.map +1 -0
  12. package/dist/endpoint-consumers.d.ts +147 -0
  13. package/dist/endpoint-consumers.d.ts.map +1 -0
  14. package/dist/endpoint-consumers.js +459 -0
  15. package/dist/endpoint-consumers.js.map +1 -0
  16. package/dist/endpoint-dial.d.ts +3 -1
  17. package/dist/endpoint-dial.d.ts.map +1 -1
  18. package/dist/endpoint-dial.js +5 -2
  19. package/dist/endpoint-dial.js.map +1 -1
  20. package/dist/endpoint-durable.d.ts +82 -0
  21. package/dist/endpoint-durable.d.ts.map +1 -0
  22. package/dist/endpoint-durable.js +164 -0
  23. package/dist/endpoint-durable.js.map +1 -0
  24. package/dist/endpoint-principal-serve.d.ts +110 -0
  25. package/dist/endpoint-principal-serve.d.ts.map +1 -0
  26. package/dist/endpoint-principal-serve.js +233 -0
  27. package/dist/endpoint-principal-serve.js.map +1 -0
  28. package/dist/endpoint-reconnect.d.ts +129 -0
  29. package/dist/endpoint-reconnect.d.ts.map +1 -0
  30. package/dist/endpoint-reconnect.js +166 -0
  31. package/dist/endpoint-reconnect.js.map +1 -0
  32. package/dist/endpoint.d.ts +44 -241
  33. package/dist/endpoint.d.ts.map +1 -1
  34. package/dist/endpoint.js +403 -1740
  35. package/dist/endpoint.js.map +1 -1
  36. package/dist/launch-artifacts.d.ts.map +1 -1
  37. package/dist/launch-artifacts.js +17 -9
  38. package/dist/launch-artifacts.js.map +1 -1
  39. package/dist/websocket-dial.d.ts +9 -0
  40. package/dist/websocket-dial.d.ts.map +1 -0
  41. package/dist/websocket-dial.js +121 -0
  42. package/dist/websocket-dial.js.map +1 -0
  43. package/package.json +1 -1
@@ -0,0 +1,82 @@
1
+ import type { DeliveryClass, Plane3Entry, ControlReply } from "./types.js";
2
+ import { type JetStreamClient, type JetStreamManager } from "@nats-io/jetstream";
3
+ import type { KV } from "@nats-io/kv";
4
+ /** What the durable-membership component reads from its endpoint. State is read when it is used, never
5
+ * copied, and every method is looked up on the endpoint at call time, so a member a caller replaced on
6
+ * the endpoint is the one that runs. */
7
+ export interface EndpointDurableDeps {
8
+ js: () => JetStreamClient | undefined;
9
+ jsm: () => JetStreamManager | undefined;
10
+ space: () => string;
11
+ pendingDurableLeave: () => Map<string, number>;
12
+ stopped: () => boolean;
13
+ plane3Channels: () => Map<string, number>;
14
+ aclRegistry: () => Promise<KV>;
15
+ deliveryClassFresh: (channel: string) => Promise<DeliveryClass>;
16
+ deleteConsumerIfPresent: (stream: string, durable: string) => Promise<void>;
17
+ publishDinbox: (principal: string, lifecycleUid: string, entry: Plane3Entry) => Promise<void>;
18
+ requestDelivery: (op: string, args: Record<string, unknown>, timeoutMs?: number) => Promise<ControlReply>;
19
+ requireLifecycleUid: (what: string) => string;
20
+ emitRecoverable: (err: Error) => void;
21
+ membershipPause: (attempt: number) => Promise<void>;
22
+ }
23
+ /** One endpoint's durable membership. Internal: `CotalEndpoint` keeps the fields and forwards to it. */
24
+ export declare class EndpointDurable {
25
+ private readonly deps;
26
+ constructor(deps: EndpointDurableDeps);
27
+ private get js();
28
+ private get jsm();
29
+ private get space();
30
+ private get pendingDurableLeave();
31
+ private get stopped();
32
+ private get plane3Channels();
33
+ private aclRegistry;
34
+ private deliveryClassFresh;
35
+ private deleteConsumerIfPresent;
36
+ private publishDinbox;
37
+ private requestDelivery;
38
+ private requireLifecycleUid;
39
+ private emitRecoverable;
40
+ private membershipPause;
41
+ /** Whether one lifecycle's exact ACL row allows a membership on `channel` now (a family must lie
42
+ * inside one entry, {@link membershipInAllow}). A leader-served read: the handle is opened without
43
+ * direct reads, so a row narrowed before this read began is the row it returns. */
44
+ aclAllows(owner: string, lifecycleUid: string, channel: string): Promise<boolean>;
45
+ /** Idempotently copy the eligible chat messages in `(fromSeqExcl, toSeqIncl]` for `channel` into the
46
+ * owner inbox, via a DEDICATED per-(owner,join) ephemeral consumer (NOT the agent-scoped
47
+ * `chathist_<id>`/`histLock` — red-team HIGH-8). It copies what the stream still holds in that
48
+ * window; a post the history limit removed first is not copied and is not reported (SPEC §4).
49
+ *
50
+ * A FAMILY row (`review.>`, #5404) reads the window on every channel under it and copies a post only
51
+ * when that post's own channel is durable-class. Each copy names the post's own channel, never the
52
+ * family, and it skips nothing another row of the lifecycle covers: two joins can both be pending
53
+ * when a post lands, so neither proves the other copied it. The per-message, per-lifecycle dedupe id
54
+ * keeps one copy. */
55
+ catchupCopy(owner: string, lifecycleUid: string, channel: string, fromSeqExcl: number, toSeqIncl: number, generation: number): Promise<number>;
56
+ /** Agent-side: request a Plane-3 durable backstop for a channel via the server-side delivery daemon (ctl.delivery). Throws
57
+ * when no privileged writer is present (open / no delivery daemon). 30s timeout — activation catch-up may
58
+ * run before the reply (the window is small, but a busy channel can take more than the 5s default). */
59
+ durableJoinChannel(channel: string): Promise<{
60
+ durable: boolean;
61
+ reason?: string;
62
+ generation?: number;
63
+ }>;
64
+ /** Agent-side: release a Plane-3 durable backstop (tombstone membership at the leave cursor). Passes
65
+ * the join generation so a stale leave can't tombstone a newer rejoin (the delivery daemon validates
66
+ * it) AND this incarnation's lifecycleUid — membership rows are lifecycle-keyed (SPEC 13.1), and a
67
+ * leave must resolve the selected principal-owned row even after the ACL row was narrowed or purged. */
68
+ durableLeaveChannel(channel: string, generation?: number, lifecycleUid?: string): Promise<void>;
69
+ /** Fail-closed async cleanup for a channel forced out by a LATE sub.allow refusal (the broker revoked
70
+ * the live read). The sync sub callback can't await, so this RETRIES the Plane-3 tombstone with capped
71
+ * backoff UNTIL IT SUCCEEDS (or the endpoint stops) — the §7 boundary always closes once the manager
72
+ * is reachable, never a silent give-up. While pending, the channel is tracked in
73
+ * {@link pendingDurableLeave} and surfaced via {@link pendingDurableLeaves} (the connector shows it in
74
+ * `cotal_channels` as `durable-unclosed`, never ordinary absence). The generation is kept the whole
75
+ * time. Authoritative closure of a revoked membership is also handled by revocation (rotate creds + tear down). */
76
+ closeRefusedMembership(channel: string, generation: number): Promise<void>;
77
+ /** Channels with a Plane-3 durable membership whose §7 tombstone is still pending after a refused live
78
+ * sub (see {@link closeRefusedMembership}) — surfaced by the connector as a `durable-unclosed` state so
79
+ * it is never presented as ordinary "not subscribed". */
80
+ pendingDurableLeaves(): string[];
81
+ }
82
+ //# sourceMappingURL=endpoint-durable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-durable.d.ts","sourceRoot":"","sources":["../src/endpoint-durable.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAA4B,MAAM,oBAAoB,CAAC;AAC3G,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAGtC;;yCAEyC;AACzC,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,eAAe,GAAG,SAAS,CAAC;IACtC,GAAG,EAAE,MAAM,gBAAgB,GAAG,SAAS,CAAC;IACxC,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,OAAO,EAAE,MAAM,OAAO,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IA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Ae;IAEvB;;wFAEoF;IAC9E,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKvF;;;;;;;;;0BASsB;IAChB,WAAW,CACf,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAC/G,OAAO,CAAC,MAAM,CAAC;IAuDlB;;4GAEwG;IAClG,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAM9G;;;6GAGyG;IACnG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,YAAY,SAAwD,GAAG,OAAO,CAAC,IAAI,CAAC;IAKpJ;;;;;;wHAMoH;IAC9G,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBhF;;8DAE0D;IAC1D,oBAAoB,IAAI,MAAM,EAAE;CAGjC"}
@@ -0,0 +1,164 @@
1
+ // The agent-side durable membership of CotalEndpoint, as an internal component: ask the delivery daemon to
2
+ // join or leave a channel's Plane-3 backstop, retry the tombstone of a membership a refused live sub forced
3
+ // out, check a lifecycle's ACL row and copy the catch-up window for a privileged join. Moved verbatim from
4
+ // endpoint.ts; the endpoint keeps the fields and forwards to these. Not re-exported by the index.
5
+ import { readAcl } from "./acls.js";
6
+ import { isFromSubjectSender } from "./endpoint-messages.js";
7
+ import { membershipInAllow, chatSubject, isChannelFamily, parsePrincipalKey, lifecycleNameKey, token, chatStream, parseSubject } from "./subjects.js";
8
+ import { AckPolicy, DeliverPolicy } from "@nats-io/jetstream";
9
+ import { nanos } from "@nats-io/transport-node";
10
+ /** One endpoint's durable membership. Internal: `CotalEndpoint` keeps the fields and forwards to it. */
11
+ export class EndpointDurable {
12
+ deps;
13
+ constructor(deps) {
14
+ this.deps = deps;
15
+ }
16
+ get js() { return this.deps.js(); }
17
+ get jsm() { return this.deps.jsm(); }
18
+ get space() { return this.deps.space(); }
19
+ get pendingDurableLeave() { return this.deps.pendingDurableLeave(); }
20
+ get stopped() { return this.deps.stopped(); }
21
+ get plane3Channels() { return this.deps.plane3Channels(); }
22
+ aclRegistry() { return this.deps.aclRegistry(); }
23
+ deliveryClassFresh(channel) { return this.deps.deliveryClassFresh(channel); }
24
+ deleteConsumerIfPresent(stream, durable) { return this.deps.deleteConsumerIfPresent(stream, durable); }
25
+ publishDinbox(principal, lifecycleUid, entry) { return this.deps.publishDinbox(principal, lifecycleUid, entry); }
26
+ requestDelivery(op, args, timeoutMs) { return this.deps.requestDelivery(op, args, timeoutMs); }
27
+ requireLifecycleUid(what) { return this.deps.requireLifecycleUid(what); }
28
+ emitRecoverable(err) { return this.deps.emitRecoverable(err); }
29
+ membershipPause(attempt) { return this.deps.membershipPause(attempt); }
30
+ /** Whether one lifecycle's exact ACL row allows a membership on `channel` now (a family must lie
31
+ * inside one entry, {@link membershipInAllow}). A leader-served read: the handle is opened without
32
+ * direct reads, so a row narrowed before this read began is the row it returns. */
33
+ async aclAllows(owner, lifecycleUid, channel) {
34
+ const row = await readAcl(await this.aclRegistry(), owner, lifecycleUid);
35
+ return row !== undefined && membershipInAllow(row.record.allowSubscribe, channel);
36
+ }
37
+ /** Idempotently copy the eligible chat messages in `(fromSeqExcl, toSeqIncl]` for `channel` into the
38
+ * owner inbox, via a DEDICATED per-(owner,join) ephemeral consumer (NOT the agent-scoped
39
+ * `chathist_<id>`/`histLock` — red-team HIGH-8). It copies what the stream still holds in that
40
+ * window; a post the history limit removed first is not copied and is not reported (SPEC §4).
41
+ *
42
+ * A FAMILY row (`review.>`, #5404) reads the window on every channel under it and copies a post only
43
+ * when that post's own channel is durable-class. Each copy names the post's own channel, never the
44
+ * family, and it skips nothing another row of the lifecycle covers: two joins can both be pending
45
+ * when a post lands, so neither proves the other copied it. The per-message, per-lifecycle dedupe id
46
+ * keeps one copy. */
47
+ async catchupCopy(owner, lifecycleUid, channel, fromSeqExcl, toSeqIncl, generation) {
48
+ if (!this.js || !this.jsm || toSeqIncl <= fromSeqExcl)
49
+ return 0;
50
+ const subject = chatSubject(this.space, "*", "*", channel);
51
+ const family = isChannelFamily(channel);
52
+ const durableClass = new Map();
53
+ const stored = (ch) => {
54
+ if (!family)
55
+ return Promise.resolve(true);
56
+ let cls = durableClass.get(ch);
57
+ if (cls === undefined)
58
+ durableClass.set(ch, (cls = this.deliveryClassFresh(ch).then((c) => c === "durable")));
59
+ return cls;
60
+ };
61
+ // Consumer NAME must be JetStream-safe (no `.`) AND collision-free: use the principal DASH-form
62
+ // (`<owner>-<actor>`, `-` reserved as the sole separator), NOT `token(owner)` — `token()` maps the
63
+ // dot-form `.`→`_`, which is NOT collision-free (`_` is legal inside a token, so `a.b_c` and `a_b.c`
64
+ // would both underscore to `a_b_c`). LIFECYCLE-KEYED (SPEC 13.1): generations restart at 1 per
65
+ // lifecycle, so an alias-keyed `cu_<principal>_<gen>` would let a same-alias successor
66
+ // delete/recreate a predecessor's in-flight catch-up consumer — the uid disambiguates.
67
+ const cuP = parsePrincipalKey(owner);
68
+ const name = `cu_${cuP ? lifecycleNameKey(cuP.owner, cuP.actor, lifecycleUid) : `${token(owner)}-${lifecycleUid}`}_${generation}`;
69
+ // A failed read throws, leaving the pending row to retry over the same window.
70
+ await this.deleteConsumerIfPresent(chatStream(this.space), name);
71
+ await this.jsm.consumers.add(chatStream(this.space), {
72
+ name, filter_subject: subject, ack_policy: AckPolicy.None, mem_storage: true,
73
+ inactive_threshold: nanos(30_000), deliver_policy: DeliverPolicy.StartSequence, opt_start_seq: fromSeqExcl + 1,
74
+ });
75
+ let copied = 0;
76
+ try {
77
+ const consumer = await this.js.consumers.get(chatStream(this.space), name);
78
+ let pending = (await consumer.info()).num_pending;
79
+ while (pending > 0) {
80
+ const want = Math.min(pending, 256);
81
+ const iter = await consumer.fetch({ max_messages: want, expires: 5_000 });
82
+ let got = 0;
83
+ for await (const m of iter) {
84
+ got++;
85
+ if (m.seq > toSeqIncl)
86
+ return copied;
87
+ let msg;
88
+ try {
89
+ msg = m.json();
90
+ }
91
+ catch {
92
+ continue;
93
+ }
94
+ const parsed = parseSubject(m.subject);
95
+ if (!parsed || !isFromSubjectSender(msg, parsed) || msg.from.id === owner)
96
+ continue;
97
+ if (!(await stored(parsed.rest)))
98
+ continue;
99
+ await this.publishDinbox(owner, lifecycleUid, {
100
+ msg, channel: parsed.rest, seq: m.seq, reason: "durable-channel", generation, ...(family ? { row: channel } : {}),
101
+ });
102
+ copied++;
103
+ }
104
+ if (got < want)
105
+ break;
106
+ pending -= got;
107
+ }
108
+ }
109
+ finally {
110
+ await this.deleteConsumerIfPresent(chatStream(this.space), name);
111
+ }
112
+ return copied;
113
+ }
114
+ /** Agent-side: request a Plane-3 durable backstop for a channel via the server-side delivery daemon (ctl.delivery). Throws
115
+ * when no privileged writer is present (open / no delivery daemon). 30s timeout — activation catch-up may
116
+ * run before the reply (the window is small, but a busy channel can take more than the 5s default). */
117
+ async durableJoinChannel(channel) {
118
+ const reply = await this.requestDelivery("durableJoin", { channel }, 30_000);
119
+ if (!reply.ok)
120
+ throw new Error(reply.error ?? "durable join rejected");
121
+ return reply.data ?? { durable: false };
122
+ }
123
+ /** Agent-side: release a Plane-3 durable backstop (tombstone membership at the leave cursor). Passes
124
+ * the join generation so a stale leave can't tombstone a newer rejoin (the delivery daemon validates
125
+ * it) AND this incarnation's lifecycleUid — membership rows are lifecycle-keyed (SPEC 13.1), and a
126
+ * leave must resolve the selected principal-owned row even after the ACL row was narrowed or purged. */
127
+ async durableLeaveChannel(channel, generation, lifecycleUid = this.requireLifecycleUid("leaving a durable channel")) {
128
+ const reply = await this.requestDelivery("durableLeave", { channel, generation, lifecycleUid });
129
+ if (!reply.ok)
130
+ throw new Error(reply.error ?? "durable leave rejected");
131
+ }
132
+ /** Fail-closed async cleanup for a channel forced out by a LATE sub.allow refusal (the broker revoked
133
+ * the live read). The sync sub callback can't await, so this RETRIES the Plane-3 tombstone with capped
134
+ * backoff UNTIL IT SUCCEEDS (or the endpoint stops) — the §7 boundary always closes once the manager
135
+ * is reachable, never a silent give-up. While pending, the channel is tracked in
136
+ * {@link pendingDurableLeave} and surfaced via {@link pendingDurableLeaves} (the connector shows it in
137
+ * `cotal_channels` as `durable-unclosed`, never ordinary absence). The generation is kept the whole
138
+ * time. Authoritative closure of a revoked membership is also handled by revocation (rotate creds + tear down). */
139
+ async closeRefusedMembership(channel, generation) {
140
+ this.pendingDurableLeave.set(channel, generation);
141
+ for (let attempt = 0;; attempt++) {
142
+ if (this.stopped)
143
+ return;
144
+ try {
145
+ await this.durableLeaveChannel(channel, generation);
146
+ this.plane3Channels.delete(channel);
147
+ this.pendingDurableLeave.delete(channel);
148
+ return;
149
+ }
150
+ catch (e) {
151
+ if (attempt === 0)
152
+ this.emitRecoverable(new Error(`channel "${channel}": Plane-3 durable membership (generation ${generation}) not yet tombstoned after a refused live sub - retrying; §7 boundary may be open until it succeeds (${e.message})`));
153
+ await this.membershipPause(attempt);
154
+ }
155
+ }
156
+ }
157
+ /** Channels with a Plane-3 durable membership whose §7 tombstone is still pending after a refused live
158
+ * sub (see {@link closeRefusedMembership}) — surfaced by the connector as a `durable-unclosed` state so
159
+ * it is never presented as ordinary "not subscribed". */
160
+ pendingDurableLeaves() {
161
+ return [...this.pendingDurableLeave.keys()];
162
+ }
163
+ }
164
+ //# sourceMappingURL=endpoint-durable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-durable.js","sourceRoot":"","sources":["../src/endpoint-durable.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,4GAA4G;AAC5G,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type EndpointReply } from "./endpoint-envelope.js";
2
+ import type { PrincipalServeIntent } from "./endpoint-options.js";
3
+ import { type EpPrincipalServeHandle } from "./endpoint-serve.js";
4
+ import type { EpPrincipal, PrincipalAuthority } from "./endpoint-subjects.js";
5
+ import type { CompiledContract } from "./schema-profile.js";
6
+ import type { AgentCard, PresencePrompts } from "./types.js";
7
+ import type { NatsConnection, PermissionViolationError } from "@nats-io/transport-node";
8
+ /** What the principal-serve component reads from its endpoint. State is read when it is used, never
9
+ * copied, a field it reassigns is written back through its setter, and every method is looked up on the
10
+ * endpoint at call time, so a member a caller replaced on the endpoint is the one that runs. */
11
+ export interface EndpointPrincipalServeDeps {
12
+ space: () => string;
13
+ nc: () => NatsConnection | undefined;
14
+ owner: () => string;
15
+ actor: () => string;
16
+ card: () => AgentCard;
17
+ principalServes: () => Map<string, PrincipalServeIntent>;
18
+ principalServers: () => Map<string, PrincipalServeIntent>;
19
+ promptsPresence: () => PresencePrompts | undefined;
20
+ setPromptsPresence: (value: PresencePrompts | undefined) => void;
21
+ publishPresence: () => Promise<void>;
22
+ emitRecoverable: (err: Error) => void;
23
+ requireLifecycleUid: (what: string) => string;
24
+ notLiveMsg: () => string;
25
+ }
26
+ /** One endpoint's principal serve and prompts. Internal: `CotalEndpoint` keeps the fields and forwards to it. */
27
+ export declare class EndpointPrincipalServe {
28
+ private readonly deps;
29
+ constructor(deps: EndpointPrincipalServeDeps);
30
+ private get space();
31
+ private get nc();
32
+ private get owner();
33
+ private get actor();
34
+ private get card();
35
+ private get principalServes();
36
+ private get principalServers();
37
+ private get promptsPresence();
38
+ private set promptsPresence(value);
39
+ private publishPresence;
40
+ private emitRecoverable;
41
+ private requireLifecycleUid;
42
+ private notLiveMsg;
43
+ /** Subscribe `intent` on `nc`. */
44
+ bindPrincipalHandle(intent: PrincipalServeIntent, nc: NatsConnection): EpPrincipalServeHandle;
45
+ /** A principal-route refusal a call or a serve reports itself: a request publish, a serve
46
+ * subscription or a reply read. Only a reply publish is left, which no call or serve awaits. */
47
+ ownedPrincipalRouteRefusal(err: PermissionViolationError): boolean;
48
+ /** Track one binding: a refusal ends the serve, and an accepted subscription on the current
49
+ * connection shows the presence field. */
50
+ armPrincipalServe(intent: PrincipalServeIntent, nc: NatsConnection, handle: EpPrincipalServeHandle): Promise<void>;
51
+ /** The broker accepted `handle` on `nc`. When that is still the current binding, the serve is
52
+ * ready there. */
53
+ private principalServeConfirmed;
54
+ /** Re-bind every principal serve on a replaced connection (a rebuild), or re-run the check on the
55
+ * connection the library reconnected and re-subscribed itself. */
56
+ rebindPrincipalServes(reconnected: boolean): void;
57
+ /** End a serve the broker refused: no more serving, `failed` resolves, the presence field goes. */
58
+ private endPrincipalServe;
59
+ /** Mark `intent` ended and release what it holds in this endpoint and in this process. */
60
+ private forgetPrincipalServe;
61
+ /** Stop serving `intent` and wait for its handlers in flight, each until its request's deadline
62
+ * at most. The ending is synchronous, so a
63
+ * `ready` still waiting for the broker rejects before the caller's next step. `republish` writes
64
+ * presence without the `prompts` field; the endpoint's own stop writes it offline instead. */
65
+ stopPrincipalServe(intent: PrincipalServeIntent, republish?: boolean): Promise<void>;
66
+ /**
67
+ * Set this process's `prompts` presence field and write presence at once (SPEC §6): how many
68
+ * prompts it holds `open` or `sent`, and a counter that goes up by one each time a prompt opens or
69
+ * changes state. The field shows only while the `agent` endpoint is served and the broker accepted
70
+ * its subscription on the current connection. Until this is called it shows `open: 0` with the
71
+ * fresh `seq` the serve took from {@link nextPromptsSeq} when it started. Throws when the `agent`
72
+ * endpoint is not served, and a RangeError for a `seq` below one this runtime already used.
73
+ */
74
+ setPromptsPresence(prompts: PresencePrompts): Promise<void>;
75
+ /**
76
+ * Take the next `prompts` `seq` for this process's runtime (SPEC §6): 0 the first time, then one
77
+ * above every `seq` this process used under its runtime id, whichever endpoint object used it. A
78
+ * prompt desk takes every `seq` it shows from here. Throws without a lifecycle UID.
79
+ */
80
+ nextPromptsSeq(): number;
81
+ /** The `prompts` field this process's presence carries now, or none. */
82
+ servedPrompts(): PresencePrompts | undefined;
83
+ /**
84
+ * Call one command of a principal's own endpoint on the principal route (SPEC 13.21), as this
85
+ * endpoint's caller triple with the authority word its row covers. `principal` is the addressed
86
+ * process: owner, actor, lifecycle UID and the `runtime.id` its presence publishes. Presence is
87
+ * advisory, and a wrong value reaches a subject nobody serves or one this caller's row does not
88
+ * cover. It cannot widen authority.
89
+ *
90
+ * The `agent` endpoint's contracts and `describe`'s are built in; any other endpoint needs
91
+ * `contract`. Resolves the reply, whose `ok: false` is the agent's own refusal; throws
92
+ * `unavailable` (`not-executed`) when nothing serves that process, `permission-denied`
93
+ * (`not-executed`) when this credential holds no row for the request, and `deadline-exceeded`
94
+ * (`unknown`) when no reply came. See {@link epPrincipalCall}.
95
+ */
96
+ callPrincipal(call: {
97
+ endpoint: string;
98
+ principal: EpPrincipal;
99
+ command: string;
100
+ authority: PrincipalAuthority;
101
+ args?: Record<string, unknown>;
102
+ deadlineMs: number;
103
+ contract?: {
104
+ input: CompiledContract;
105
+ output: CompiledContract;
106
+ };
107
+ signal?: AbortSignal;
108
+ }): Promise<EndpointReply>;
109
+ }
110
+ //# sourceMappingURL=endpoint-principal-serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-principal-serve.d.ts","sourceRoot":"","sources":["../src/endpoint-principal-serve.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAA0C,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC1G,OAAO,KAAK,EAAY,WAAW,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAExF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,K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tB,GAAG,OAAO,CAAC,aAAa,CAAC;CAa3B"}
@@ -0,0 +1,233 @@
1
+ // The principal serve and prompts of CotalEndpoint, as an internal component: binding and arming each
2
+ // principal-route serve, confirming it, re-binding it on a new connection, ending and stopping it, the
3
+ // `prompts` presence field and its `seq`, and calling a principal. Moved verbatim from endpoint.ts; the
4
+ // endpoint keeps servePrincipal, which a smoke replaces, and the fields, and forwards to these. Not
5
+ // re-exported by the index.
6
+ import { AGENT_CONTRACTS, AGENT_ENDPOINT } from "./agent-endpoint.js";
7
+ import { epPrincipalCall } from "./endpoint-call.js";
8
+ import { EpEnvelopeError } from "./endpoint-envelope.js";
9
+ import { servePrincipalRoute, describeContracts } from "./endpoint-serve.js";
10
+ import { processRuntime } from "./process-runtime.js";
11
+ import { spacePrefix } from "./subjects.js";
12
+ /** The highest `prompts` presence `seq` this process used under each runtime id (SPEC §6). A reader
13
+ * orders lists by `seq` within one `runtime.id`, and a runtime id lives as long as the process, so
14
+ * this does too: across a stopped serve, a stopped endpoint and a new endpoint for the lifecycle. */
15
+ const promptsSeqs = new Map();
16
+ /** One endpoint's principal serve and prompts. Internal: `CotalEndpoint` keeps the fields and forwards to it. */
17
+ export class EndpointPrincipalServe {
18
+ deps;
19
+ constructor(deps) {
20
+ this.deps = deps;
21
+ }
22
+ get space() { return this.deps.space(); }
23
+ get nc() { return this.deps.nc(); }
24
+ get owner() { return this.deps.owner(); }
25
+ get actor() { return this.deps.actor(); }
26
+ get card() { return this.deps.card(); }
27
+ get principalServes() { return this.deps.principalServes(); }
28
+ get principalServers() { return this.deps.principalServers(); }
29
+ get promptsPresence() { return this.deps.promptsPresence(); }
30
+ set promptsPresence(value) { this.deps.setPromptsPresence(value); }
31
+ publishPresence() { return this.deps.publishPresence(); }
32
+ emitRecoverable(err) { return this.deps.emitRecoverable(err); }
33
+ requireLifecycleUid(what) { return this.deps.requireLifecycleUid(what); }
34
+ notLiveMsg() { return this.deps.notLiveMsg(); }
35
+ /** Subscribe `intent` on `nc`. */
36
+ bindPrincipalHandle(intent, nc) {
37
+ return servePrincipalRoute(nc, this.space, intent.self, intent.serve);
38
+ }
39
+ /** A principal-route refusal a call or a serve reports itself: a request publish, a serve
40
+ * subscription or a reply read. Only a reply publish is left, which no call or serve awaits. */
41
+ ownedPrincipalRouteRefusal(err) {
42
+ const p = `${spacePrefix(this.space)}.ep.`;
43
+ if (err.operation === "publish")
44
+ return err.subject.startsWith(`${p}prin.`);
45
+ return err.subject.startsWith(`${p}prin.`) || err.subject.startsWith(`${p}prin-reply.`);
46
+ }
47
+ /** Track one binding: a refusal ends the serve, and an accepted subscription on the current
48
+ * connection shows the presence field. */
49
+ async armPrincipalServe(intent, nc, handle) {
50
+ intent.binding = { nc, handle };
51
+ // Every earlier binding is on a replaced connection: retire it once its handlers finish.
52
+ for (const old of intent.handles)
53
+ void old.stop().finally(() => {
54
+ const i = intent.handles.indexOf(old);
55
+ if (i >= 0)
56
+ intent.handles.splice(i, 1);
57
+ });
58
+ intent.handles.push(handle);
59
+ intent.readyOn = undefined;
60
+ void handle.refused.then((err) => {
61
+ if (!intent.ended && intent.binding?.handle === handle)
62
+ this.endPrincipalServe(intent, err);
63
+ });
64
+ try {
65
+ await handle.ready;
66
+ }
67
+ catch {
68
+ // A refusal ends the serve through `refused`. A flush that failed because the connection
69
+ // went away is answered by the binding the next connection makes.
70
+ return;
71
+ }
72
+ this.principalServeConfirmed(intent, nc, handle);
73
+ }
74
+ /** The broker accepted `handle` on `nc`. When that is still the current binding, the serve is
75
+ * ready there. */
76
+ principalServeConfirmed(intent, nc, handle) {
77
+ if (intent.ended || intent.binding?.handle !== handle || this.nc !== nc)
78
+ return;
79
+ intent.readyOn = nc;
80
+ if (!intent.readySettled) {
81
+ intent.readySettled = true;
82
+ intent.resolveReady();
83
+ }
84
+ if (intent.serve.endpoint === AGENT_ENDPOINT)
85
+ this.publishPresence().catch((e) => this.emitRecoverable(e));
86
+ }
87
+ /** Re-bind every principal serve on a replaced connection (a rebuild), or re-run the check on the
88
+ * connection the library reconnected and re-subscribed itself. */
89
+ rebindPrincipalServes(reconnected) {
90
+ const nc = this.nc;
91
+ if (!nc)
92
+ return;
93
+ for (const intent of this.principalServes.values()) {
94
+ if (intent.ended)
95
+ continue;
96
+ const bound = intent.binding;
97
+ if (bound && bound.nc === nc) {
98
+ if (!reconnected)
99
+ continue;
100
+ intent.readyOn = undefined;
101
+ void bound.handle.check().then(() => this.principalServeConfirmed(intent, nc, bound.handle), () => { });
102
+ continue;
103
+ }
104
+ let handle;
105
+ try {
106
+ handle = this.bindPrincipalHandle(intent, nc);
107
+ }
108
+ catch (e) {
109
+ this.endPrincipalServe(intent, e);
110
+ continue;
111
+ }
112
+ void this.armPrincipalServe(intent, nc, handle);
113
+ }
114
+ }
115
+ /** End a serve the broker refused: no more serving, `failed` resolves, the presence field goes. */
116
+ endPrincipalServe(intent, err) {
117
+ if (intent.ended)
118
+ return;
119
+ this.forgetPrincipalServe(intent);
120
+ const wasReady = intent.readySettled;
121
+ if (!intent.readySettled) {
122
+ intent.readySettled = true;
123
+ intent.rejectReady(err);
124
+ }
125
+ intent.resolveFailed(err);
126
+ for (const handle of intent.handles)
127
+ void handle.stop();
128
+ if (intent.serve.endpoint === AGENT_ENDPOINT) {
129
+ this.promptsPresence = undefined;
130
+ this.publishPresence().catch((e) => this.emitRecoverable(e));
131
+ }
132
+ // `ready` already carried a refusal that came before it settled; a later one is reported here.
133
+ if (wasReady)
134
+ this.emitRecoverable(new Error(`stopped serving "${intent.serve.endpoint}" on the principal route: ${err.message}`, { cause: err }));
135
+ }
136
+ /** Mark `intent` ended and release what it holds in this endpoint and in this process. */
137
+ forgetPrincipalServe(intent) {
138
+ intent.ended = true;
139
+ intent.readyOn = undefined;
140
+ if (this.principalServes.get(intent.serve.endpoint) === intent)
141
+ this.principalServes.delete(intent.serve.endpoint);
142
+ if (this.principalServers.get(intent.serverKey) === intent)
143
+ this.principalServers.delete(intent.serverKey);
144
+ }
145
+ /** Stop serving `intent` and wait for its handlers in flight, each until its request's deadline
146
+ * at most. The ending is synchronous, so a
147
+ * `ready` still waiting for the broker rejects before the caller's next step. `republish` writes
148
+ * presence without the `prompts` field; the endpoint's own stop writes it offline instead. */
149
+ async stopPrincipalServe(intent, republish = true) {
150
+ if (!intent.ended) {
151
+ this.forgetPrincipalServe(intent);
152
+ if (!intent.readySettled) {
153
+ intent.readySettled = true;
154
+ intent.rejectReady(new Error(`stopped serving "${intent.serve.endpoint}" before the broker confirmed the subscription`));
155
+ }
156
+ if (intent.serve.endpoint === AGENT_ENDPOINT) {
157
+ this.promptsPresence = undefined;
158
+ if (republish)
159
+ this.publishPresence().catch((e) => this.emitRecoverable(e));
160
+ }
161
+ }
162
+ await Promise.all(intent.handles.map((handle) => handle.stop()));
163
+ }
164
+ /**
165
+ * Set this process's `prompts` presence field and write presence at once (SPEC §6): how many
166
+ * prompts it holds `open` or `sent`, and a counter that goes up by one each time a prompt opens or
167
+ * changes state. The field shows only while the `agent` endpoint is served and the broker accepted
168
+ * its subscription on the current connection. Until this is called it shows `open: 0` with the
169
+ * fresh `seq` the serve took from {@link nextPromptsSeq} when it started. Throws when the `agent`
170
+ * endpoint is not served, and a RangeError for a `seq` below one this runtime already used.
171
+ */
172
+ async setPromptsPresence(prompts) {
173
+ for (const k of ["open", "seq"])
174
+ if (!Number.isSafeInteger(prompts?.[k]) || prompts[k] < 0)
175
+ throw new TypeError(`prompts.${k} must be a non-negative safe integer`);
176
+ const intent = this.principalServes.get(AGENT_ENDPOINT);
177
+ if (!intent)
178
+ throw new Error(`the prompts presence field belongs to a served "${AGENT_ENDPOINT}" endpoint: call servePrincipal first (SPEC §6)`);
179
+ const used = promptsSeqs.get(intent.self.runtimeId) ?? 0;
180
+ if (prompts.seq < used)
181
+ throw new RangeError(`prompts.seq ${prompts.seq} is below ${used}, which this process already used under runtime ${intent.self.runtimeId}: seq never goes back under one runtime id (SPEC §6)`);
182
+ promptsSeqs.set(intent.self.runtimeId, prompts.seq);
183
+ this.promptsPresence = { open: prompts.open, seq: prompts.seq };
184
+ await this.publishPresence();
185
+ }
186
+ /**
187
+ * Take the next `prompts` `seq` for this process's runtime (SPEC §6): 0 the first time, then one
188
+ * above every `seq` this process used under its runtime id, whichever endpoint object used it. A
189
+ * prompt desk takes every `seq` it shows from here. Throws without a lifecycle UID.
190
+ */
191
+ nextPromptsSeq() {
192
+ const runtimeId = processRuntime(this.requireLifecycleUid("nextPromptsSeq")).id;
193
+ const used = promptsSeqs.get(runtimeId);
194
+ const next = used === undefined ? 0 : used + 1;
195
+ promptsSeqs.set(runtimeId, next);
196
+ return next;
197
+ }
198
+ /** The `prompts` field this process's presence carries now, or none. */
199
+ servedPrompts() {
200
+ const intent = this.principalServes.get(AGENT_ENDPOINT);
201
+ if (!intent || intent.ended || !this.nc || intent.readyOn !== this.nc)
202
+ return undefined;
203
+ return this.promptsPresence;
204
+ }
205
+ /**
206
+ * Call one command of a principal's own endpoint on the principal route (SPEC 13.21), as this
207
+ * endpoint's caller triple with the authority word its row covers. `principal` is the addressed
208
+ * process: owner, actor, lifecycle UID and the `runtime.id` its presence publishes. Presence is
209
+ * advisory, and a wrong value reaches a subject nobody serves or one this caller's row does not
210
+ * cover. It cannot widen authority.
211
+ *
212
+ * The `agent` endpoint's contracts and `describe`'s are built in; any other endpoint needs
213
+ * `contract`. Resolves the reply, whose `ok: false` is the agent's own refusal; throws
214
+ * `unavailable` (`not-executed`) when nothing serves that process, `permission-denied`
215
+ * (`not-executed`) when this credential holds no row for the request, and `deadline-exceeded`
216
+ * (`unknown`) when no reply came. See {@link epPrincipalCall}.
217
+ */
218
+ async callPrincipal(call) {
219
+ const nc = this.nc;
220
+ if (!nc)
221
+ throw new Error(this.notLiveMsg());
222
+ const contract = call.contract
223
+ ?? (call.command === "describe" ? describeContracts() : call.endpoint === AGENT_ENDPOINT ? AGENT_CONTRACTS[call.command] : undefined);
224
+ if (contract === undefined)
225
+ throw new EpEnvelopeError("bad-request", `no contract is built in for ${call.endpoint}.${call.command}; pass one`, undefined, "not-executed");
226
+ const caller = { owner: this.owner, actor: this.actor, uid: this.requireLifecycleUid("callPrincipal") };
227
+ return epPrincipalCall(nc, this.space, { principal: call.principal, authority: call.authority }, {
228
+ endpoint: call.endpoint, command: call.command, contract, caller, name: this.card.name,
229
+ ...(call.args !== undefined ? { args: call.args } : {}),
230
+ }, { deadlineMs: call.deadlineMs, ...(call.signal ? { signal: call.signal } : {}) });
231
+ }
232
+ }
233
+ //# sourceMappingURL=endpoint-principal-serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-principal-serve.js","sourceRoot":"","sources":["../src/endpoint-principal-serve.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,uGAAuG;AACvG,wGAAwG;AACxG,oGAAoG;AACpG,4BAA4B;AAC5B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAE7E,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAA+B,MAAM,qBAAqB,CAAC;AAE1G,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C;;sGAEsG;AACtG,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAqB9C,iHAAiH;AACjH,MAAM,OAAO,sBAAsB;IACJ;IAA7B,YAA6B,IAAgC;QAAhC,SAAI,GAAJ,IAAI,CAA4B;IAAG,CAAC;IAEjE,IAAY,KAAK,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjD,IAAY,EAAE,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3C,IAAY,KAAK,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC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