@cotal-ai/core 0.169.0 → 0.170.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-file.d.ts +9 -5
- package/dist/agent-file.d.ts.map +1 -1
- package/dist/agent-file.js +18 -8
- package/dist/agent-file.js.map +1 -1
- package/dist/anycast-requests.d.ts +8 -1
- package/dist/anycast-requests.d.ts.map +1 -1
- package/dist/anycast-requests.js +47 -0
- package/dist/anycast-requests.js.map +1 -1
- package/dist/backup-config.d.ts +5 -2
- package/dist/backup-config.d.ts.map +1 -1
- package/dist/backup-config.js +7 -2
- package/dist/backup-config.js.map +1 -1
- package/dist/backup.d.ts +6 -0
- package/dist/backup.d.ts.map +1 -1
- package/dist/backup.js +11 -4
- package/dist/backup.js.map +1 -1
- package/dist/endpoint-binding.d.ts.map +1 -1
- package/dist/endpoint-binding.js +2 -0
- package/dist/endpoint-binding.js.map +1 -1
- package/dist/endpoint-channel-discovery.d.ts +102 -0
- package/dist/endpoint-channel-discovery.d.ts.map +1 -0
- package/dist/endpoint-channel-discovery.js +170 -0
- package/dist/endpoint-channel-discovery.js.map +1 -0
- package/dist/endpoint-control-plane.d.ts +204 -0
- package/dist/endpoint-control-plane.d.ts.map +1 -0
- package/dist/endpoint-control-plane.js +627 -0
- package/dist/endpoint-control-plane.js.map +1 -0
- package/dist/endpoint-durable-backstop.d.ts +249 -0
- package/dist/endpoint-durable-backstop.d.ts.map +1 -0
- package/dist/endpoint-durable-backstop.js +485 -0
- package/dist/endpoint-durable-backstop.js.map +1 -0
- package/dist/endpoint-liveness.d.ts +105 -0
- package/dist/endpoint-liveness.d.ts.map +1 -0
- package/dist/endpoint-liveness.js +223 -0
- package/dist/endpoint-liveness.js.map +1 -0
- package/dist/endpoint-messaging.d.ts +229 -0
- package/dist/endpoint-messaging.d.ts.map +1 -0
- package/dist/endpoint-messaging.js +420 -0
- package/dist/endpoint-messaging.js.map +1 -0
- package/dist/endpoint-presence.d.ts +15 -0
- package/dist/endpoint-presence.d.ts.map +1 -1
- package/dist/endpoint-presence.js +35 -0
- package/dist/endpoint-presence.js.map +1 -1
- package/dist/endpoint-subscriptions.d.ts +199 -0
- package/dist/endpoint-subscriptions.d.ts.map +1 -0
- package/dist/endpoint-subscriptions.js +543 -0
- package/dist/endpoint-subscriptions.js.map +1 -0
- package/dist/endpoint.d.ts +32 -91
- package/dist/endpoint.d.ts.map +1 -1
- package/dist/endpoint.js +246 -1744
- package/dist/endpoint.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/provision-jwt.d.ts.map +1 -1
- package/dist/provision-jwt.js +1 -0
- package/dist/provision-jwt.js.map +1 -1
- package/dist/provision-permissions.d.ts +1 -1
- package/dist/provision-permissions.d.ts.map +1 -1
- package/dist/provision-permissions.js +3 -0
- package/dist/provision-permissions.js.map +1 -1
- package/dist/run-host.d.ts +4 -1
- package/dist/run-host.d.ts.map +1 -1
- package/dist/run-record.d.ts +4 -0
- package/dist/run-record.d.ts.map +1 -1
- package/dist/run-record.js +36 -0
- package/dist/run-record.js.map +1 -1
- package/dist/space-quiescence-resources.d.ts +30 -0
- package/dist/space-quiescence-resources.d.ts.map +1 -0
- package/dist/space-quiescence-resources.js +45 -0
- package/dist/space-quiescence-resources.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
// The messaging region of CotalEndpoint, as an internal component. Moved verbatim from endpoint.ts;
|
|
2
|
+
// the endpoint keeps the public methods and forwards to them. Not re-exported by the index.
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { headers, PermissionViolationError, TimeoutError } from "@nats-io/transport-node";
|
|
5
|
+
import { JetStreamApiCodes } from "@nats-io/jetstream";
|
|
6
|
+
import { eventPayloadSubject, eventPayloadStream } from "./event-payloads.js";
|
|
7
|
+
import { assertIdToken } from "./endpoint-subjects.js";
|
|
8
|
+
import { isCasLoss } from "./endpoint-records.js";
|
|
9
|
+
import { isJetStreamMissing } from "./jetstream-missing.js";
|
|
10
|
+
import { anycastSubject, assertValidOwnerToken, assertValidRole, chatStream, chatSubject, isConcreteChannel, normalizeMentions, parsePrincipalKey, unicastSubject, } from "./subjects.js";
|
|
11
|
+
/** The messaging verbs of one endpoint: multicast (plain and serialized), unicast, anycast, and the
|
|
12
|
+
* event-payload channel. Internal: `CotalEndpoint` keeps the public methods and forwards to it. */
|
|
13
|
+
export class EndpointMessaging {
|
|
14
|
+
deps;
|
|
15
|
+
constructor(deps) {
|
|
16
|
+
this.deps = deps;
|
|
17
|
+
}
|
|
18
|
+
get nc() { return this.deps.nc(); }
|
|
19
|
+
get js() { return this.deps.js(); }
|
|
20
|
+
get jsm() { return this.deps.jsm(); }
|
|
21
|
+
get space() { return this.deps.space(); }
|
|
22
|
+
get owner() { return this.deps.owner(); }
|
|
23
|
+
get actor() { return this.deps.actor(); }
|
|
24
|
+
get channels() { return this.deps.channels(); }
|
|
25
|
+
notLiveMsg() { return this.deps.notLiveMsg(); }
|
|
26
|
+
ref() { return this.deps.ref(); }
|
|
27
|
+
publishMsg(subject, msg) { return this.deps.publishMsg(subject, msg); }
|
|
28
|
+
streamHistory(stream, subjects, limit, before, signal) { return this.deps.streamHistory(stream, subjects, limit, before, signal); }
|
|
29
|
+
emitRecoverable(err) { this.deps.emitRecoverable(err); }
|
|
30
|
+
/** Multicast: broadcast to everyone on a channel. */
|
|
31
|
+
async multicast(text, opts) {
|
|
32
|
+
// Publish must target a concrete sub-channel — you can't broadcast to a
|
|
33
|
+
// wildcard. Default to the first concrete channel we're on (channels[0] may
|
|
34
|
+
// itself be a wildcard subscription like `team.>`). On no channels there is NO default: refuse
|
|
35
|
+
// rather than pick `general`, which is a destination the caller never chose and, for an agent
|
|
36
|
+
// whose cred carries no channel row, one the broker would deny anyway.
|
|
37
|
+
const channel = opts?.channel ?? this.channels.find(isConcreteChannel);
|
|
38
|
+
if (channel === undefined)
|
|
39
|
+
throw new Error("no default channel: this endpoint is not on any concrete channel, so there is nothing to broadcast to - name a channel explicitly, or join one first");
|
|
40
|
+
if (!isConcreteChannel(channel))
|
|
41
|
+
throw new Error(`cannot publish to wildcard channel "${channel}" - pick a concrete sub-channel`);
|
|
42
|
+
const msg = {
|
|
43
|
+
id: randomUUID(),
|
|
44
|
+
ts: Date.now(),
|
|
45
|
+
space: this.space,
|
|
46
|
+
from: this.ref(),
|
|
47
|
+
channel,
|
|
48
|
+
// Priority/wake hint, not routing — validation (against the roster) is the connector's
|
|
49
|
+
// job; core just canonicalizes and omits the field when empty.
|
|
50
|
+
mentions: normalizeMentions(opts?.mentions),
|
|
51
|
+
parts: opts?.parts ?? [{ kind: "text", text }],
|
|
52
|
+
replyTo: opts?.replyTo,
|
|
53
|
+
contextId: opts?.contextId,
|
|
54
|
+
};
|
|
55
|
+
await this.publishMsg(chatSubject(this.space, this.owner, this.actor, channel), msg);
|
|
56
|
+
return msg;
|
|
57
|
+
}
|
|
58
|
+
/** The broker's live `max_payload` — the CEILING a frame is measured against, not a budget for a
|
|
59
|
+
* caller's own payload.
|
|
60
|
+
*
|
|
61
|
+
* Exposed because the connection is private and callers outside core (a connector assembling a
|
|
62
|
+
* batched payload) otherwise have no way to learn the ceiling except by failing a publish.
|
|
63
|
+
* Throws rather than guessing a default: a wrong ceiling is worse than none, because it splits
|
|
64
|
+
* either too eagerly or too late and both look like working code.
|
|
65
|
+
*
|
|
66
|
+
* THIS ALONE CANNOT SIZE A MESSAGE. The envelope this endpoint adds after the publish call, and
|
|
67
|
+
* the client's own headers, are charged against the same ceiling and the caller never sees them.
|
|
68
|
+
* Use {@link encodedSize}, which measures what will actually be sent. */
|
|
69
|
+
get maxPayload() {
|
|
70
|
+
const max = this.nc?.info?.max_payload;
|
|
71
|
+
if (typeof max !== "number" || !Number.isFinite(max) || max <= 0)
|
|
72
|
+
throw new Error(`${this.notLiveMsg()} - max_payload is only known while connected`);
|
|
73
|
+
return max;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Verify the PRECONDITION {@link multicastExpecting} depends on: that the chat stream evaluates
|
|
77
|
+
* the subject expectation BEFORE the `Nats-Msg-Id` dedup cache. **Throws if it cannot be
|
|
78
|
+
* guaranteed.** Call before the first serialized append on a given endpoint.
|
|
79
|
+
*
|
|
80
|
+
* **The ordering follows the stream's REPLICATION FACTOR, not the deployment.** A standalone R1
|
|
81
|
+
* stream and an R1 stream inside a real 3-node cluster both refuse a stale expectation with a CAS
|
|
82
|
+
* error; only an R3 stream evaluates dedup first and answers a retry with `duplicate: true`. A
|
|
83
|
+
* check written against cluster size would pass on exactly the deployment that breaks.
|
|
84
|
+
*
|
|
85
|
+
* Every stream Cotal creates is `num_replicas: 1`, from the same canonical config the restore path
|
|
86
|
+
* uses, so the property holds by construction today. This exists because "by construction" is an
|
|
87
|
+
* observation until something checks it: nothing in the wire contract reserves the replica factor.
|
|
88
|
+
* A caller appending under a stale assumption does not fail loudly; it accepts a retry as success
|
|
89
|
+
* and drops a message.
|
|
90
|
+
*
|
|
91
|
+
* Evidence is `smoke:cas-preflight-cluster`, which records the server version it measured against
|
|
92
|
+
* rather than naming one here — the suites resolve `nats-server` from `PATH`, so a hardcoded
|
|
93
|
+
* provenance ages into a claim about a machine that no longer exists.
|
|
94
|
+
*
|
|
95
|
+
* @throws if the stream is unreadable (no `STREAM.INFO` grant, or absent) or reports more than
|
|
96
|
+
* one replica. Never degrades to a warning: the failure it prevents is silent.
|
|
97
|
+
*/
|
|
98
|
+
async assertExpectationSemantics() {
|
|
99
|
+
if (!this.jsm)
|
|
100
|
+
throw new Error(this.notLiveMsg());
|
|
101
|
+
const stream = chatStream(this.space);
|
|
102
|
+
let replicas;
|
|
103
|
+
try {
|
|
104
|
+
replicas = (await this.jsm.streams.info(stream)).config.num_replicas;
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
throw new Error(`cannot verify expectation semantics: stream "${stream}" info unavailable (${e.message}). ` +
|
|
108
|
+
`Serialized appends are refused rather than run on an unverified stream.`);
|
|
109
|
+
}
|
|
110
|
+
// `undefined` is NOT treated as 1. A server that does not report the field is a server whose
|
|
111
|
+
// ordering we have not established, which is the case this check exists for.
|
|
112
|
+
if (replicas !== 1)
|
|
113
|
+
throw new Error(`stream "${stream}" reports num_replicas=${String(replicas)}; serialized appends on THIS ` +
|
|
114
|
+
`stream require 1 — a property of this one stream, not of the broker, so a clustered ` +
|
|
115
|
+
`deployment is fine so long as this stream is R1, which a cluster can host. ` +
|
|
116
|
+
`On a replicated stream the dedup cache is consulted before the subject expectation, so a ` +
|
|
117
|
+
`retry returns a duplicate ack instead of a conflict and a lost message reads as success.`);
|
|
118
|
+
}
|
|
119
|
+
/** The envelope {@link multicastExpecting} publishes, built in ONE place so that a frame and any
|
|
120
|
+
* measurement of that frame cannot describe different messages. The fields this adds — `ts`,
|
|
121
|
+
* `space`, `from`, `channel` and the normalized `mentions` — are exactly the ones a caller
|
|
122
|
+
* holding only its parts cannot account for. */
|
|
123
|
+
casEnvelope(opts) {
|
|
124
|
+
return {
|
|
125
|
+
id: opts.id,
|
|
126
|
+
ts: Date.now(),
|
|
127
|
+
space: this.space,
|
|
128
|
+
from: this.ref(),
|
|
129
|
+
channel: opts.channel,
|
|
130
|
+
mentions: normalizeMentions(opts.mentions),
|
|
131
|
+
parts: opts.parts,
|
|
132
|
+
replyTo: opts.replyTo,
|
|
133
|
+
contextId: opts.contextId,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The bytes this frame will ACTUALLY put on the wire, to compare against {@link maxPayload}.
|
|
138
|
+
*
|
|
139
|
+
* Caller-side arithmetic is wrong in the dangerous direction: a split sized against the caller's
|
|
140
|
+
* own payload produces a frame the broker REJECTS, and a rejected truncation makes the loss silent
|
|
141
|
+
* again — the failure splitting exists to prevent.
|
|
142
|
+
*
|
|
143
|
+
* It lives on the surface that BUILDS the envelope so measurement and construction cannot drift
|
|
144
|
+
* apart unnoticed: it shares {@link casEnvelope} with the publish path, sets the same two headers,
|
|
145
|
+
* and lets the client's own encoder encode them rather than re-implementing the wire format.
|
|
146
|
+
* `frame-size.smoke.ts` binary-searches a real broker's ceiling and requires this number to land
|
|
147
|
+
* on it exactly.
|
|
148
|
+
*
|
|
149
|
+
* `expectedLastSubjectSeq` is a parameter because it is a header VALUE: sizing at 0 and publishing
|
|
150
|
+
* at 123456 differ by five bytes.
|
|
151
|
+
* `expectedLastMsgId` is measured when given, so a caller that may send it can size for it.
|
|
152
|
+
*
|
|
153
|
+
* Residual: `ts` is re-stamped at publish, so the two differ in value — not in length until
|
|
154
|
+
* epoch-millis needs a 14th digit.
|
|
155
|
+
*/
|
|
156
|
+
encodedSize(opts) {
|
|
157
|
+
// The same argument validation the publish path applies, so a caller cannot size a frame that
|
|
158
|
+
// would have been refused before it ever reached the wire.
|
|
159
|
+
if (!isConcreteChannel(opts.channel))
|
|
160
|
+
throw new Error(`cannot publish to wildcard channel "${opts.channel}" - pick a concrete sub-channel`);
|
|
161
|
+
assertIdToken(opts.id, "publish id");
|
|
162
|
+
if (!Number.isSafeInteger(opts.expectedLastSubjectSeq) || opts.expectedLastSubjectSeq < 0)
|
|
163
|
+
throw new Error(`expectedLastSubjectSeq must be a non-negative safe integer, got ${JSON.stringify(opts.expectedLastSubjectSeq)}`);
|
|
164
|
+
if (!Array.isArray(opts.parts) || opts.parts.length === 0)
|
|
165
|
+
throw new Error("encodedSize requires at least one part");
|
|
166
|
+
const mh = headers();
|
|
167
|
+
mh.set("Nats-Msg-Id", opts.id);
|
|
168
|
+
mh.set("Nats-Expected-Last-Subject-Sequence", `${opts.expectedLastSubjectSeq}`);
|
|
169
|
+
if (opts.expectedLastMsgId !== undefined) {
|
|
170
|
+
assertIdToken(opts.expectedLastMsgId, "expected last msg id");
|
|
171
|
+
mh.set("Nats-Expected-Last-Msg-Id", opts.expectedLastMsgId);
|
|
172
|
+
}
|
|
173
|
+
// `encode()` is on the client's header implementation but not on the published `MsgHdrs` type,
|
|
174
|
+
// so it is reached through a cast rather than copied. If a client version drops it, this throws
|
|
175
|
+
// immediately and loudly — the calibration cell would also fail — instead of returning a number
|
|
176
|
+
// that is quietly wrong near the ceiling.
|
|
177
|
+
const headerBytes = mh.encode().length;
|
|
178
|
+
return headerBytes + Buffer.byteLength(JSON.stringify(this.casEnvelope(opts)), "utf8");
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Multicast with an OPTIMISTIC-CONCURRENCY expectation and a caller-chosen dedup id, returning
|
|
182
|
+
* the `PubAck` fields instead of discarding them. The serialized-append primitive: two writers
|
|
183
|
+
* racing one subject cannot interleave, because the loser's expectation no longer holds.
|
|
184
|
+
*
|
|
185
|
+
* **Why a separate method rather than options on {@link multicast}.** `multicast` mints a fresh
|
|
186
|
+
* `id` per call and drops the ack; both are right for ordinary chat and both are fatal to a
|
|
187
|
+
* caller that must retry an append idempotently. Keeping them apart means no existing caller
|
|
188
|
+
* changes behaviour, and the stricter validation below applies only where a caller opted in.
|
|
189
|
+
*
|
|
190
|
+
* - `id` becomes the JetStream `Nats-Msg-Id`, so the SAME id may be republished on retry and the
|
|
191
|
+
* server dedups it within the stream's duplicate window. It is validated rather than trusted:
|
|
192
|
+
* it lands in a wire header, and the dedup cache is **stream-wide**, so a caller-supplied id is
|
|
193
|
+
* both an injection surface and a way to suppress another publisher's message.
|
|
194
|
+
* - `expectedLastSubjectSeq` is the sequence this publisher believes is the subject's tip; `0`
|
|
195
|
+
* means "the subject must be empty". A mismatch throws, and the throw stays classifiable by the
|
|
196
|
+
* already-public {@link isCasLoss} — the error is deliberately **not wrapped**, since wrapping
|
|
197
|
+
* would hide the `err_code` that classification reads.
|
|
198
|
+
* - `expectedLastMsgId`, when given, becomes `Nats-Expected-Last-Msg-Id`. The broker checks it after
|
|
199
|
+
* its dedup cache, so a fresh value nobody has published turns a publish into a probe: an id the
|
|
200
|
+
* cache holds answers `duplicate: true` with the stored sequence, and any other id is refused
|
|
201
|
+
* with error 10070 before anything is stored.
|
|
202
|
+
*
|
|
203
|
+
* @throws if the endpoint is not live, the channel is not concrete, `id` is malformed, `parts` is
|
|
204
|
+
* empty, or `expectedLastSubjectSeq` is not a non-negative safe integer.
|
|
205
|
+
*/
|
|
206
|
+
async multicastExpecting(opts) {
|
|
207
|
+
if (!this.js)
|
|
208
|
+
throw new Error(this.notLiveMsg());
|
|
209
|
+
if (!isConcreteChannel(opts.channel))
|
|
210
|
+
throw new Error(`cannot publish to wildcard channel "${opts.channel}" - pick a concrete sub-channel`);
|
|
211
|
+
// Reuse the existing id grammar rather than mint a second one: [A-Za-z0-9_-]{1,64} admits a
|
|
212
|
+
// UUID and rejects every character that could break a wire header (CR, LF, space, colon).
|
|
213
|
+
assertIdToken(opts.id, "publish id");
|
|
214
|
+
const expected = opts.expectedLastSubjectSeq;
|
|
215
|
+
if (!Number.isSafeInteger(expected) || expected < 0)
|
|
216
|
+
throw new Error(`expectedLastSubjectSeq must be a non-negative safe integer, got ${JSON.stringify(expected)}`);
|
|
217
|
+
if (!Array.isArray(opts.parts) || opts.parts.length === 0)
|
|
218
|
+
throw new Error("multicastExpecting requires at least one part");
|
|
219
|
+
if (opts.expectedLastMsgId !== undefined)
|
|
220
|
+
assertIdToken(opts.expectedLastMsgId, "expected last msg id");
|
|
221
|
+
const message = this.casEnvelope(opts);
|
|
222
|
+
assertPartsSerializable(message.parts);
|
|
223
|
+
// Publish DIRECTLY rather than through publishMsg: this path must set the expectation and read
|
|
224
|
+
// the ack, and publishMsg deliberately does neither.
|
|
225
|
+
const ack = await this.js.publish(chatSubject(this.space, this.owner, this.actor, opts.channel), JSON.stringify(message), { msgID: opts.id, expect: { lastSubjectSequence: expected, ...(opts.expectedLastMsgId !== undefined ? { lastMsgID: opts.expectedLastMsgId } : {}) } });
|
|
226
|
+
return { message, ack: { seq: ack.seq, duplicate: ack.duplicate === true } };
|
|
227
|
+
}
|
|
228
|
+
/** Publish a payload frame on this principal's forge-locked sibling event rail. */
|
|
229
|
+
async publishEventPayload(opts) {
|
|
230
|
+
if (!this.js)
|
|
231
|
+
throw new Error(this.notLiveMsg());
|
|
232
|
+
assertIdToken(opts.id, "publish id");
|
|
233
|
+
if (!Number.isSafeInteger(opts.expectedLastSubjectSeq) || opts.expectedLastSubjectSeq < 0)
|
|
234
|
+
throw new Error("payload expectation must be a non-negative safe integer");
|
|
235
|
+
if (!opts.parts.length)
|
|
236
|
+
throw new Error("payload frame requires parts");
|
|
237
|
+
const message = this.casEnvelope({ ...opts, channel: `events.${this.owner}.${this.actor}` });
|
|
238
|
+
assertPartsSerializable(message.parts);
|
|
239
|
+
const ack = await this.js.publish(eventPayloadSubject(this.space, this.owner, this.actor), JSON.stringify(message), { msgID: opts.id, expect: { lastSubjectSequence: opts.expectedLastSubjectSeq } });
|
|
240
|
+
return { ack: { seq: ack.seq, duplicate: ack.duplicate === true } };
|
|
241
|
+
}
|
|
242
|
+
/** Read payload history through a single native-filtered consumer, never through CHAT. */
|
|
243
|
+
async eventPayloadHistory(owner, actor, opts) {
|
|
244
|
+
return (await this.streamHistory(eventPayloadStream(this.space), [eventPayloadSubject(this.space, assertValidOwnerToken(owner), assertValidOwnerToken(actor))], opts?.limit ?? 100, undefined, opts?.signal))
|
|
245
|
+
.map(row => row.msg);
|
|
246
|
+
}
|
|
247
|
+
/** Verify the sibling stream and learn its actual message ceiling. A pre-upgrade space without
|
|
248
|
+
* the stream or its info-read permission returns null and emits a warning. Other authorization,
|
|
249
|
+
* transport and config errors throw. */
|
|
250
|
+
async eventPayloadLimit() {
|
|
251
|
+
if (!this.jsm)
|
|
252
|
+
throw new Error(this.notLiveMsg());
|
|
253
|
+
const stream = eventPayloadStream(this.space);
|
|
254
|
+
const info = await this.jsm.streams.info(stream).catch((err) => {
|
|
255
|
+
const denial = err instanceof PermissionViolationError ? err
|
|
256
|
+
: err?.cause;
|
|
257
|
+
const infoDenied = denial instanceof PermissionViolationError && denial.operation === "publish"
|
|
258
|
+
&& denial.subject === `$JS.API.STREAM.INFO.${stream}`;
|
|
259
|
+
if (!infoDenied && !isJetStreamMissing(err, JetStreamApiCodes.StreamNotFound))
|
|
260
|
+
throw err;
|
|
261
|
+
const reason = infoDenied ? `missing publish permission on $JS.API.STREAM.INFO.${stream}` : `stream ${stream} is absent`;
|
|
262
|
+
this.emitRecoverable(new Error(`event payloads unavailable: ${reason}; publishing tool names and times only. Upgrade the space's broker setup and credentials to enable payloads`));
|
|
263
|
+
return null;
|
|
264
|
+
});
|
|
265
|
+
if (info === null)
|
|
266
|
+
return null;
|
|
267
|
+
const { config } = info;
|
|
268
|
+
if (config.num_replicas !== 1)
|
|
269
|
+
throw new Error("event payload stream requires one replica for serialized appends");
|
|
270
|
+
const limits = [this.maxPayload, config.max_msg_size, config.max_bytes].filter((n) => typeof n === "number" && n > 0);
|
|
271
|
+
return Math.min(...limits);
|
|
272
|
+
}
|
|
273
|
+
/** Unicast: direct message to one specific instance. */
|
|
274
|
+
async unicast(instanceId, text, opts) {
|
|
275
|
+
const { msg } = await this.unicastAttributed(instanceId, text, opts);
|
|
276
|
+
return msg;
|
|
277
|
+
}
|
|
278
|
+
/** Unicast, returning the JetStream publish ack alongside the message: the only truthful proof
|
|
279
|
+
* a sender has is that the broker stored the message at a sequence, never that anyone read it. */
|
|
280
|
+
async unicastAttributed(instanceId, text, opts) {
|
|
281
|
+
if (!this.js)
|
|
282
|
+
throw new Error(this.notLiveMsg());
|
|
283
|
+
const msg = {
|
|
284
|
+
id: randomUUID(),
|
|
285
|
+
ts: Date.now(),
|
|
286
|
+
space: this.space,
|
|
287
|
+
from: this.ref(),
|
|
288
|
+
to: instanceId,
|
|
289
|
+
parts: opts?.parts ?? [{ kind: "text", text }],
|
|
290
|
+
replyTo: opts?.replyTo,
|
|
291
|
+
contextId: opts?.contextId,
|
|
292
|
+
};
|
|
293
|
+
// The recipient id is a principal dot-form `<owner>.<actor>` (owner+actor grammar); the 4-token DM
|
|
294
|
+
// subject forge-locks recipient AND sender, so both are split into their tokens here.
|
|
295
|
+
const recip = parsePrincipalKey(instanceId);
|
|
296
|
+
if (!recip)
|
|
297
|
+
throw new Error(`unicast: "${instanceId}" is not a valid recipient principal <owner>.<actor>`);
|
|
298
|
+
assertPartsSerializable(msg.parts);
|
|
299
|
+
// Publish DIRECTLY rather than through publishMsg, the way multicastExpecting does: this path
|
|
300
|
+
// must read the ack, and publishMsg deliberately discards it.
|
|
301
|
+
const subject = unicastSubject(this.space, recip.owner, recip.actor, this.owner, this.actor);
|
|
302
|
+
try {
|
|
303
|
+
const ack = await this.js.publish(subject, JSON.stringify(msg), { msgID: msg.id });
|
|
304
|
+
return { msg, ack: { seq: ack.seq, duplicate: ack.duplicate === true } };
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
if (error instanceof TimeoutError)
|
|
308
|
+
throw new Error(`${error.message} publishing to ${JSON.stringify(subject)}. The send outcome is unknown: the broker may have stored the message. Check before resending.`, { cause: error });
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/** Anycast: deliver to ANY one instance of a service (role) — queue-group load balancing. */
|
|
313
|
+
async anycast(service, text, opts) {
|
|
314
|
+
const { msg } = await this.anycastAttributed(service, text, opts);
|
|
315
|
+
return msg;
|
|
316
|
+
}
|
|
317
|
+
/** Anycast, returning the JetStream publish ack alongside the message: the broker stored the
|
|
318
|
+
* request on the role's work queue at a sequence, which proves neither a holder nor a read. */
|
|
319
|
+
async anycastAttributed(service, text, opts) {
|
|
320
|
+
if (!this.js)
|
|
321
|
+
throw new Error(this.notLiveMsg());
|
|
322
|
+
// The subject builder admits `*` for allow rules; a publish needs one concrete role.
|
|
323
|
+
assertValidRole(service);
|
|
324
|
+
const msg = {
|
|
325
|
+
id: randomUUID(),
|
|
326
|
+
ts: Date.now(),
|
|
327
|
+
space: this.space,
|
|
328
|
+
from: this.ref(),
|
|
329
|
+
toService: service,
|
|
330
|
+
parts: opts?.parts ?? [{ kind: "text", text }],
|
|
331
|
+
replyTo: opts?.replyTo,
|
|
332
|
+
contextId: opts?.contextId,
|
|
333
|
+
};
|
|
334
|
+
assertPartsSerializable(msg.parts);
|
|
335
|
+
// Publish DIRECTLY rather than through publishMsg, the way unicastAttributed does: this path
|
|
336
|
+
// must read the ack, and publishMsg deliberately discards it.
|
|
337
|
+
const ack = await this.js.publish(anycastSubject(this.space, service, this.owner, this.actor), JSON.stringify(msg), { msgID: msg.id });
|
|
338
|
+
return { msg, ack: { seq: ack.seq, duplicate: ack.duplicate === true } };
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/** A `data` part value the wire can carry faithfully: a JSON value at EVERY depth (SPEC §5's
|
|
342
|
+
* `<any JSON value>`). `JSON.stringify` does not reject what it cannot represent — it silently
|
|
343
|
+
* rewrites: `undefined` (and a function-valued member) drops the key, `NaN`/`Infinity` store as
|
|
344
|
+
* `null`, a `Date` stores as a string, a sparse array's holes store as `null`, a `Map` stores as
|
|
345
|
+
* `{}`, a `Buffer` stores as `{"type":"Buffer",...}`. A reader then cannot tell a stored `null`
|
|
346
|
+
* from a real one (#1404 fix round). So the producer checks structurally, matching the exported
|
|
347
|
+
* `JsonValue`: null, boolean, finite number, string, an array whose every slot (holes included)
|
|
348
|
+
* passes, or a plain object (prototype `null` or `Object.prototype`) whose every defined member
|
|
349
|
+
* passes. A cycle is refused here too, never left for stringify's TypeError.
|
|
350
|
+
*
|
|
351
|
+
* THE OBJECT/ARRAY ASYMMETRY ON `undefined`: an `undefined`-valued MEMBER of a plain object is
|
|
352
|
+
* allowed — stringify drops just that key, which is faithful (and the exported type says so) —
|
|
353
|
+
* while `undefined` at the top level or in an ARRAY SLOT is refused, because there stringify
|
|
354
|
+
* cannot drop a position: it stores `null`, which is a rewrite a reader cannot distinguish from
|
|
355
|
+
* a real `null`.
|
|
356
|
+
*
|
|
357
|
+
* `seen` is the set of ANCESTORS on the current path, not every object visited: it is deleted
|
|
358
|
+
* from on the way out, so a SHARED subtree (`{a: x, b: x}`) passes — stringify carries it twice,
|
|
359
|
+
* which is faithful — while an object that contains itself at any depth still reports its path. */
|
|
360
|
+
function jsonPathProblem(path, value, seen) {
|
|
361
|
+
if (value === null)
|
|
362
|
+
return undefined;
|
|
363
|
+
const t = typeof value;
|
|
364
|
+
if (t === "boolean" || t === "string")
|
|
365
|
+
return undefined;
|
|
366
|
+
if (t === "number")
|
|
367
|
+
return Number.isFinite(value) ? undefined : `${path} is not a finite number`;
|
|
368
|
+
if (t === "undefined" || t === "function" || t === "symbol" || t === "bigint")
|
|
369
|
+
return `${path} is not a JSON value`;
|
|
370
|
+
if (typeof value === "object") {
|
|
371
|
+
if (seen.has(value))
|
|
372
|
+
return `${path} is cyclic`;
|
|
373
|
+
seen.add(value);
|
|
374
|
+
let problem;
|
|
375
|
+
if (Array.isArray(value)) {
|
|
376
|
+
for (let i = 0; i < value.length; i++) {
|
|
377
|
+
problem = jsonPathProblem(`${path}[${i}]`, value[i], seen);
|
|
378
|
+
if (problem)
|
|
379
|
+
return problem;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
const proto = Object.getPrototypeOf(value);
|
|
384
|
+
if (proto !== null && proto !== Object.prototype) {
|
|
385
|
+
seen.delete(value);
|
|
386
|
+
return `${path} is not a plain object`;
|
|
387
|
+
}
|
|
388
|
+
for (const key of Object.keys(value)) {
|
|
389
|
+
// A member whose value is undefined is the allowed key-drop, not a defect: stringify omits
|
|
390
|
+
// the key, the object stays a JSON object, so skip it rather than walk it.
|
|
391
|
+
if (value[key] === undefined)
|
|
392
|
+
continue;
|
|
393
|
+
problem = jsonPathProblem(`${path}.${key}`, value[key], seen);
|
|
394
|
+
if (problem)
|
|
395
|
+
return problem;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
seen.delete(value);
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
return `${path} is not a JSON value`;
|
|
402
|
+
}
|
|
403
|
+
/** Refuse, at publish, a `data` part `JSON.stringify` would silently rewrite. The guard is the
|
|
404
|
+
* runtime half of `Part`'s `data: JsonValue` arm: with it, a non-JSON value at any depth never
|
|
405
|
+
* reaches the wire, so every reader (live core-sub, Plane-3 durable, history) gives one answer —
|
|
406
|
+
* the message was never sent — instead of the old split where history returned a rewritten row
|
|
407
|
+
* while Plane-3 terminated a keyless one as malformed. The error names the path to the offending
|
|
408
|
+
* value (e.g. `data[2].at`), so a caller learns which member to fix rather than that stringify
|
|
409
|
+
* would have mangled something. Throws rather than coercing: no fallback. */
|
|
410
|
+
export function assertPartsSerializable(parts) {
|
|
411
|
+
for (const p of parts) {
|
|
412
|
+
if (p.kind !== "data")
|
|
413
|
+
continue;
|
|
414
|
+
const problem = jsonPathProblem("data", p.data, new Set());
|
|
415
|
+
if (problem !== undefined) {
|
|
416
|
+
throw new Error(`cannot publish a data part carrying a non-JSON value (SPEC §5) - ${problem}`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=endpoint-messaging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-messaging.js","sourceRoot":"","sources":["../src/endpoint-messaging.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,4FAA4F;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAuB,MAAM,yBAAyB,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAA+C,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,qBAAqB,EACr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,IAAI,KAAK,CAAC,GAAyB,CAAC,KAAK,SAAS;oBAAE,SAAS;gBAC7D,OAAO,GAAG,eAAe,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,EAAE,KAAK,CAAC,GAAyB,CAAC,EAAE,IAAI,CAAC,CAAC;gBACpF,IAAI,OAAO;oBAAE,OAAO,OAAO,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,IAAI,sBAAsB,CAAC;AACvC,CAAC;AAED;;;;;;8EAM8E;AAC9E,MAAM,UAAU,uBAAuB,CAAC,KAAsB;IAC5D,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;YAAE,SAAS;QAChC,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,EAAG,CAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACnF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,oEAAoE,OAAO,EAAE,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -194,6 +194,21 @@ export declare class EndpointPresence {
|
|
|
194
194
|
/** Publish the agent's per-channel attention overrides into presence (advisory). An empty map drops
|
|
195
195
|
* the field. Mirror only - never read back into delivery. */
|
|
196
196
|
setChannelModes(modes: Record<string, ChannelMode>): Promise<void>;
|
|
197
|
+
/** Overlay the host's live model and optional variant onto the card's display-only metadata, then
|
|
198
|
+
* republish presence. For connectors that learn their actual selection only after launch (e.g.
|
|
199
|
+
* Claude Code's `SessionStart` hook). The mutated card is read live by every later publish, so even
|
|
200
|
+
* a pre-connect call surfaces on the first presence write. `provider` is the effective provider
|
|
201
|
+
* the connector reported serving the model; when omitted an existing `meta.provider` is left
|
|
202
|
+
* untouched (unlike `variant`, it is never deleted, since a caller that does not know the
|
|
203
|
+
* provider says nothing about whether one still applies). */
|
|
204
|
+
setCardModel(model: string, variant?: string, provider?: string): Promise<void>;
|
|
205
|
+
/** Overlay the session's working directory onto the card's display-only `meta.cwd`, then
|
|
206
|
+
* republish presence. For connectors that learn the directory from the harness after launch (e.g.
|
|
207
|
+
* Claude Code's `SessionStart` hook) rather than from their own process. Advisory display data,
|
|
208
|
+
* never a routing or access input. The pathname is kept byte for byte: a directory name may hold
|
|
209
|
+
* or end in whitespace, so it is never trimmed or normalized. An empty string names no directory
|
|
210
|
+
* and leaves the card unchanged. */
|
|
211
|
+
setCardCwd(cwd: string): Promise<void>;
|
|
197
212
|
publishPresence(): Promise<void>;
|
|
198
213
|
/** #1356: drop the presence-refusal record when the connection that OBSERVED those refusals goes
|
|
199
214
|
* away. "This bucket is refusing writes" is a claim about a specific broker connection; once that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-presence.d.ts","sourceRoot":"","sources":["../src/endpoint-presence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,EAAE,EAAW,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAOtI,KAAK,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtD,oFAAoF;AACpF,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,SAAS,CAAC;IACtB,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAA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C,WAAW;IASnB,OAAO,CAAC,yBAAyB;IAOjC,KAAK,IAAI,IAAI;CAuCd"}
|
|
@@ -295,6 +295,41 @@ export class EndpointPresence {
|
|
|
295
295
|
this.channelModes = Object.keys(modes).length ? modes : undefined;
|
|
296
296
|
await this.publishPresence();
|
|
297
297
|
}
|
|
298
|
+
/** Overlay the host's live model and optional variant onto the card's display-only metadata, then
|
|
299
|
+
* republish presence. For connectors that learn their actual selection only after launch (e.g.
|
|
300
|
+
* Claude Code's `SessionStart` hook). The mutated card is read live by every later publish, so even
|
|
301
|
+
* a pre-connect call surfaces on the first presence write. `provider` is the effective provider
|
|
302
|
+
* the connector reported serving the model; when omitted an existing `meta.provider` is left
|
|
303
|
+
* untouched (unlike `variant`, it is never deleted, since a caller that does not know the
|
|
304
|
+
* provider says nothing about whether one still applies). */
|
|
305
|
+
async setCardModel(model, variant, provider) {
|
|
306
|
+
const m = model.trim();
|
|
307
|
+
const v = variant?.trim();
|
|
308
|
+
const p = provider?.trim();
|
|
309
|
+
if (!m || (this.card.meta?.model === m && this.card.meta.variant === v && (p === undefined || this.card.meta?.provider === p)))
|
|
310
|
+
return;
|
|
311
|
+
const meta = { ...(this.card.meta ?? {}), model: m };
|
|
312
|
+
if (v)
|
|
313
|
+
meta.variant = v;
|
|
314
|
+
else
|
|
315
|
+
delete meta.variant;
|
|
316
|
+
if (p)
|
|
317
|
+
meta.provider = p;
|
|
318
|
+
this.card.meta = meta;
|
|
319
|
+
await this.publishPresence();
|
|
320
|
+
}
|
|
321
|
+
/** Overlay the session's working directory onto the card's display-only `meta.cwd`, then
|
|
322
|
+
* republish presence. For connectors that learn the directory from the harness after launch (e.g.
|
|
323
|
+
* Claude Code's `SessionStart` hook) rather than from their own process. Advisory display data,
|
|
324
|
+
* never a routing or access input. The pathname is kept byte for byte: a directory name may hold
|
|
325
|
+
* or end in whitespace, so it is never trimmed or normalized. An empty string names no directory
|
|
326
|
+
* and leaves the card unchanged. */
|
|
327
|
+
async setCardCwd(cwd) {
|
|
328
|
+
if (!cwd || this.card.meta?.cwd === cwd)
|
|
329
|
+
return;
|
|
330
|
+
this.card.meta = { ...(this.card.meta ?? {}), cwd };
|
|
331
|
+
await this.publishPresence();
|
|
332
|
+
}
|
|
298
333
|
async publishPresence() {
|
|
299
334
|
if (!this.doRegister || !this.kv)
|
|
300
335
|
return; // observers watch but never publish their own record
|