@cotal-ai/connector-hermes 0.28.0 → 0.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13605,11 +13605,11 @@ var require_connect = __commonJS({
13605
13605
  "../../node_modules/.pnpm/@nats-io+transport-node@3.4.0/node_modules/@nats-io/transport-node/lib/connect.js"(exports2) {
13606
13606
  "use strict";
13607
13607
  Object.defineProperty(exports2, "__esModule", { value: true });
13608
- exports2.connect = connect8;
13608
+ exports2.connect = connect7;
13609
13609
  var node_transport_1 = require_node_transport();
13610
13610
  var nats_base_client_1 = require_nats_base_client();
13611
13611
  var nats_base_client_2 = require_nats_base_client();
13612
- function connect8(opts = {}) {
13612
+ function connect7(opts = {}) {
13613
13613
  if ((0, nats_base_client_2.hasWsProtocol)(opts)) {
13614
13614
  return Promise.reject(nats_base_client_2.errors.InvalidArgumentError.format(`servers`, `node client doesn't support websockets, use the 'wsconnect' function instead`));
13615
13615
  }
@@ -35848,49 +35848,33 @@ var SYS_LIMITS = { ...BASE_LIMITS, mem_storage: 0, disk_storage: 0 };
35848
35848
  var import_nkeys4 = __toESM(require_mod2(), 1);
35849
35849
 
35850
35850
  // ../../packages/core/dist/channels.js
35851
- var import_kv4 = __toESM(require_mod6(), 1);
35852
- var import_transport_node13 = __toESM(require_transport_node(), 1);
35853
- function parseDuration(s) {
35854
- const m = /^(\d+)(s|m|h|d)$/.exec(s.trim());
35855
- if (!m)
35856
- throw new Error(`invalid duration "${s}" - expected <number><s|m|h|d>, e.g. "24h"`);
35857
- const n = Number(m[1]);
35858
- const unit = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 }[m[2]];
35859
- return n * unit;
35860
- }
35861
- function effectiveReplay(cfg, defaults) {
35862
- return cfg?.replay ?? defaults?.replay ?? true;
35863
- }
35864
- function effectiveReplayWindowMs(cfg, defaults) {
35865
- const w = cfg?.replayWindow ?? defaults?.replayWindow;
35866
- return w === void 0 ? void 0 : parseDuration(w);
35867
- }
35868
- function effectiveDeliveryClass(cfg, defaults) {
35869
- return cfg?.deliveryClass ?? defaults?.deliveryClass ?? "durable";
35870
- }
35871
- async function openChannelRegistry(nc, space, opts = {}) {
35872
- const kvm = new import_kv4.Kvm(nc);
35873
- return opts.create ? kvm.create(channelBucket(space)) : kvm.open(channelBucket(space));
35874
- }
35875
- async function readChannelConfig(kv, channel) {
35876
- return decode2(kv, channel);
35877
- }
35878
- async function readChannelDefaults(kv) {
35879
- return decode2(kv, CHANNEL_DEFAULTS_KEY);
35880
- }
35881
- async function decode2(kv, key) {
35882
- const e = await kv.get(key);
35883
- if (!e || e.operation === "DEL" || e.operation === "PURGE")
35884
- return void 0;
35885
- try {
35886
- return e.json();
35887
- } catch {
35888
- return void 0;
35889
- }
35851
+ var import_kv7 = __toESM(require_mod6(), 1);
35852
+ var import_transport_node15 = __toESM(require_transport_node(), 1);
35853
+
35854
+ // ../../packages/core/dist/endpoint.js
35855
+ var import_node_events = require("node:events");
35856
+ var import_node_crypto7 = require("node:crypto");
35857
+ var import_node_net = require("node:net");
35858
+ var import_transport_node14 = __toESM(require_transport_node(), 1);
35859
+ var import_nats_core = __toESM(require_mod3(), 1);
35860
+
35861
+ // ../../packages/core/dist/artifact.js
35862
+ var ARTIFACT_PART_KIND = "artifact";
35863
+ function isArtifactPart(value) {
35864
+ if (!value || typeof value !== "object")
35865
+ return false;
35866
+ const p = value;
35867
+ return p.kind === ARTIFACT_PART_KIND && typeof p.name === "string" && p.name.length > 0 && typeof p.mediaType === "string" && p.mediaType.length > 0 && typeof p.digest === "string" && isContractDigest(p.digest) && typeof p.size === "number" && Number.isSafeInteger(p.size) && p.size >= 0;
35890
35868
  }
35891
35869
 
35870
+ // ../../packages/core/dist/endpoint.js
35871
+ var import_jetstream13 = __toESM(require_mod4(), 1);
35872
+ var import_jetstream14 = __toESM(require_mod4(), 1);
35873
+ var import_kv6 = __toESM(require_mod6(), 1);
35874
+ var import_internal2 = __toESM(require_internal_mod3(), 1);
35875
+
35892
35876
  // ../../packages/core/dist/members.js
35893
- var import_kv5 = __toESM(require_mod6(), 1);
35877
+ var import_kv4 = __toESM(require_mod6(), 1);
35894
35878
  var StaleMembershipWrite = class extends Error {
35895
35879
  constructor(channel, owner, attempted, current) {
35896
35880
  super(`stale membership write for ${channel}/${owner}: generation ${attempted} < current ${current}`);
@@ -35898,7 +35882,7 @@ var StaleMembershipWrite = class extends Error {
35898
35882
  }
35899
35883
  };
35900
35884
  async function openMembersRegistry(nc, space, opts = {}) {
35901
- const kvm = new import_kv5.Kvm(nc);
35885
+ const kvm = new import_kv4.Kvm(nc);
35902
35886
  return opts.create ? kvm.create(membersBucket(space)) : kvm.open(membersBucket(space));
35903
35887
  }
35904
35888
  async function readMember(kv, channel, owner, lifecycleUid) {
@@ -35998,221 +35982,14 @@ function durableEligible(rec, seq) {
35998
35982
  return true;
35999
35983
  }
36000
35984
 
36001
- // ../../packages/core/dist/membership-feed.js
36002
- var import_transport_node14 = __toESM(require_transport_node(), 1);
36003
- var import_kv6 = __toESM(require_mod6(), 1);
36004
-
36005
- // ../../packages/core/dist/evict.js
36006
- var import_transport_node15 = __toESM(require_transport_node(), 1);
36007
-
36008
35985
  // ../../packages/core/dist/lease.js
36009
- var import_kv7 = __toESM(require_mod6(), 1);
36010
- var import_transport_node16 = __toESM(require_transport_node(), 1);
35986
+ var import_kv5 = __toESM(require_mod6(), 1);
35987
+ var import_transport_node13 = __toESM(require_transport_node(), 1);
36011
35988
  async function openDeliveryRegistry(nc, space) {
36012
- return new import_kv7.Kvm(nc).open(deliveryBucket(space));
36013
- }
36014
-
36015
- // ../../packages/core/dist/agent-file.js
36016
- var import_node_fs = require("node:fs");
36017
- var import_yaml = __toESM(require_dist(), 1);
36018
- function parseFrontmatter(src, path) {
36019
- let doc;
36020
- try {
36021
- doc = (0, import_yaml.parse)(src);
36022
- } catch (e) {
36023
- throw new Error(`agent file ${path}: invalid YAML frontmatter; ${e.message}`);
36024
- }
36025
- if (doc === null || doc === void 0)
36026
- return {};
36027
- if (typeof doc !== "object" || Array.isArray(doc))
36028
- throw new Error(`agent file ${path}: frontmatter must be a YAML mapping (key: value pairs)`);
36029
- return doc;
36030
- }
36031
- function loadAgentFile(path) {
36032
- const src = (0, import_node_fs.readFileSync)(path, "utf8");
36033
- const m = /^---\n([\s\S]*?)\n---\n?([\s\S]*)$/.exec(src);
36034
- if (!m)
36035
- throw new Error(`agent file ${path}: missing "---" frontmatter block`);
36036
- const fm = parseFrontmatter(m[1], path);
36037
- const persona = m[2].trim();
36038
- const str2 = (k) => {
36039
- const v = fm[k];
36040
- if (v === void 0 || v === null)
36041
- return void 0;
36042
- if (typeof v === "object")
36043
- throw new Error(`agent file ${path}: "${k}" must be a scalar`);
36044
- return String(v);
36045
- };
36046
- const list = (k) => {
36047
- const v = fm[k];
36048
- if (v === void 0 || v === null)
36049
- return void 0;
36050
- return (Array.isArray(v) ? v : [v]).map((x) => {
36051
- if (x === null || typeof x === "object")
36052
- throw new Error(`agent file ${path}: "${k}" list items must be scalars`);
36053
- return String(x);
36054
- });
36055
- };
36056
- const name = str2("name");
36057
- if (!name)
36058
- throw new Error(`agent file ${path}: "name" is required`);
36059
- assertValidName(name);
36060
- const kind = str2("kind");
36061
- if (kind && kind !== "agent" && kind !== "endpoint")
36062
- throw new Error(`agent file ${path}: "kind" must be "agent" or "endpoint"`);
36063
- for (const old of ["channels", "publish"])
36064
- if (old in fm)
36065
- throw new Error(`agent file ${path}: "${old}" was renamed - use "subscribe"/"allowSubscribe" (read) and "allowPublish" (post)`);
36066
- const subscribe = list("subscribe");
36067
- const allowSubscribe = list("allowSubscribe");
36068
- const allowPublish = list("allowPublish");
36069
- const quiet = list("quiet");
36070
- const muted = list("muted");
36071
- for (const ch of [...subscribe ?? [], ...allowSubscribe ?? [], ...allowPublish ?? []])
36072
- try {
36073
- assertValidChannel(ch);
36074
- } catch (e) {
36075
- throw new Error(`agent file ${path}: ${e.message}`);
36076
- }
36077
- const effSubscribe = subscribe ?? [];
36078
- const effAllow = allowSubscribe?.length ? allowSubscribe : effSubscribe;
36079
- for (const ch of effSubscribe)
36080
- if (!channelInAllow(effAllow, ch))
36081
- throw new Error(`agent file ${path}: subscribe channel "${ch}" is not within allowSubscribe [${effAllow.join(", ")}]`);
36082
- const both = (quiet ?? []).filter((c) => (muted ?? []).includes(c));
36083
- if (both.length)
36084
- throw new Error(`agent file ${path}: channel(s) [${both.join(", ")}] are in both quiet and muted - pick one`);
36085
- for (const [field, chans] of [["quiet", quiet], ["muted", muted]])
36086
- for (const ch of chans ?? []) {
36087
- try {
36088
- assertValidChannel(ch);
36089
- } catch (e) {
36090
- throw new Error(`agent file ${path}: ${e.message}`);
36091
- }
36092
- if (!isConcreteChannel(ch))
36093
- throw new Error(`agent file ${path}: ${field} channel "${ch}" must be a concrete channel (no wildcard)`);
36094
- if (!channelInAllow(effAllow, ch))
36095
- throw new Error(`agent file ${path}: ${field} channel "${ch}" is not within your read ACL / allowSubscribe [${effAllow.join(", ")}]`);
36096
- }
36097
- const launchOptionsRaw = fm["launchOptions"];
36098
- let launchOptions;
36099
- if (launchOptionsRaw !== void 0 && launchOptionsRaw !== null) {
36100
- if (typeof launchOptionsRaw !== "object" || Array.isArray(launchOptionsRaw))
36101
- throw new Error(`agent file ${path}: "launchOptions" must be a mapping of key: value pairs`);
36102
- launchOptions = launchOptionsRaw;
36103
- }
36104
- const known = /* @__PURE__ */ new Set(["name", "role", "kind", "description", "tags", "subscribe", "allowSubscribe", "allowPublish", "quiet", "muted", "model", "variant", "launchOptions", "capabilities", "owner"]);
36105
- const meta3 = {};
36106
- for (const [k, v] of Object.entries(fm))
36107
- if (!known.has(k) && v !== null && typeof v !== "object")
36108
- meta3[k] = String(v);
36109
- return {
36110
- name,
36111
- role: str2("role"),
36112
- kind,
36113
- description: str2("description"),
36114
- tags: list("tags"),
36115
- subscribe,
36116
- allowSubscribe,
36117
- allowPublish,
36118
- quiet,
36119
- muted,
36120
- model: str2("model"),
36121
- variant: str2("variant"),
36122
- launchOptions,
36123
- capabilities: list("capabilities"),
36124
- owner: str2("owner"),
36125
- meta: Object.keys(meta3).length ? meta3 : void 0,
36126
- persona: persona || void 0
36127
- };
36128
- }
36129
-
36130
- // ../../packages/core/dist/secret-fs.js
36131
- var isWin = process.platform === "win32";
36132
-
36133
- // ../../packages/core/dist/launch-material.js
36134
- var import_node_fs2 = require("node:fs");
36135
- var LAUNCH_MATERIAL_ENV = "COTAL_LAUNCH_MATERIAL";
36136
- function readLaunchMaterial(path) {
36137
- let raw;
36138
- try {
36139
- if (process.platform !== "win32") {
36140
- const mode = (0, import_node_fs2.statSync)(path).mode & 511;
36141
- if (mode & 63)
36142
- throw new Error(`is readable beyond its owner (mode ${mode.toString(8)}) - refusing to read connection material out of a file other local users can open`);
36143
- }
36144
- raw = (0, import_node_fs2.readFileSync)(path, "utf8");
36145
- } catch (e) {
36146
- throw new Error(`launch material: cannot read ${path} (${e instanceof Error ? e.message : String(e)})`);
36147
- }
36148
- let parsed;
36149
- try {
36150
- parsed = JSON.parse(raw);
36151
- } catch {
36152
- throw new Error(`launch material: ${path} is not valid JSON`);
36153
- }
36154
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
36155
- throw new Error(`launch material: ${path} must contain a JSON object`);
36156
- return validate(parsed, path);
36157
- }
36158
- function validate(raw, path) {
36159
- const material = {};
36160
- const str2 = (key) => {
36161
- const v = raw[key];
36162
- if (v === void 0)
36163
- return;
36164
- if (typeof v !== "string" || !v.trim())
36165
- throw new Error(`launch material: ${path} has a ${key} that is not a non-empty string`);
36166
- material[key] = v;
36167
- };
36168
- str2("servers");
36169
- str2("creds");
36170
- str2("token");
36171
- str2("controlToken");
36172
- if (raw.userAuth !== void 0) {
36173
- const u = raw.userAuth;
36174
- if (typeof u !== "object" || u === null || Array.isArray(u))
36175
- throw new Error(`launch material: ${path} has a userAuth that is not an object`);
36176
- const { owner, actor, sentinelCredsPath, bearerCmd } = u;
36177
- const named = { owner, actor, sentinelCredsPath };
36178
- for (const [k, v] of Object.entries(named))
36179
- if (typeof v !== "string" || !v.trim())
36180
- throw new Error(`launch material: ${path} has a userAuth.${k} that is not a non-empty string`);
36181
- if (!Array.isArray(bearerCmd) || bearerCmd.length === 0 || !bearerCmd.every((a) => typeof a === "string" && a))
36182
- throw new Error(`launch material: ${path} has a userAuth.bearerCmd that is not a non-empty array of strings`);
36183
- material.userAuth = {
36184
- owner,
36185
- actor,
36186
- sentinelCredsPath,
36187
- bearerCmd
36188
- };
36189
- }
36190
- if (Object.keys(material).length === 0)
36191
- throw new Error(`launch material: ${path} carries nothing this reader recognises. A launch that references material and supplies none is a broken launcher, not an open-mode launch, so it is refused rather than defaulted.`);
36192
- return material;
36193
- }
36194
-
36195
- // ../../packages/core/dist/endpoint.js
36196
- var import_node_events = require("node:events");
36197
- var import_node_crypto7 = require("node:crypto");
36198
- var import_node_net = require("node:net");
36199
- var import_transport_node17 = __toESM(require_transport_node(), 1);
36200
- var import_nats_core = __toESM(require_mod3(), 1);
36201
-
36202
- // ../../packages/core/dist/artifact.js
36203
- var ARTIFACT_PART_KIND = "artifact";
36204
- function isArtifactPart(value) {
36205
- if (!value || typeof value !== "object")
36206
- return false;
36207
- const p = value;
36208
- return p.kind === ARTIFACT_PART_KIND && typeof p.name === "string" && p.name.length > 0 && typeof p.mediaType === "string" && p.mediaType.length > 0 && typeof p.digest === "string" && isContractDigest(p.digest) && typeof p.size === "number" && Number.isSafeInteger(p.size) && p.size >= 0;
35989
+ return new import_kv5.Kvm(nc).open(deliveryBucket(space));
36209
35990
  }
36210
35991
 
36211
35992
  // ../../packages/core/dist/endpoint.js
36212
- var import_jetstream13 = __toESM(require_mod4(), 1);
36213
- var import_jetstream14 = __toESM(require_mod4(), 1);
36214
- var import_kv8 = __toESM(require_mod6(), 1);
36215
- var import_internal2 = __toESM(require_internal_mod3(), 1);
36216
35993
  var DEFAULT_SERVER = "nats://127.0.0.1:4222";
36217
35994
  var PLANE3_FRAME_HEADER = "Cotal-Delivery-Frame";
36218
35995
  var READER_MAX_REDELIVERIES = 10;
@@ -36726,7 +36503,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
36726
36503
  this.watchStatus();
36727
36504
  this.js = (0, import_jetstream13.jetstream)(this.nc);
36728
36505
  if (this.doWatch || this.doRegister) {
36729
- const kvm = new import_kv8.Kvm(this.nc);
36506
+ const kvm = new import_kv6.Kvm(this.nc);
36730
36507
  this.kv = this.authed ? await kvm.open(presenceBucket(this.space)) : await kvm.create(presenceBucket(this.space), { ttl: this.ttlMs });
36731
36508
  }
36732
36509
  if (this.doWatch) {
@@ -37108,7 +36885,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
37108
36885
  throw new Error(`expectedLastSubjectSeq must be a non-negative safe integer, got ${JSON.stringify(opts.expectedLastSubjectSeq)}`);
37109
36886
  if (!Array.isArray(opts.parts) || opts.parts.length === 0)
37110
36887
  throw new Error("encodedSize requires at least one part");
37111
- const mh = (0, import_transport_node17.headers)();
36888
+ const mh = (0, import_transport_node14.headers)();
37112
36889
  mh.set("Nats-Msg-Id", opts.id);
37113
36890
  mh.set("Nats-Expected-Last-Subject-Sequence", `${opts.expectedLastSubjectSeq}`);
37114
36891
  const headerBytes = mh.encode().length;
@@ -37614,7 +37391,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
37614
37391
  async membershipFeedRegistry() {
37615
37392
  if (!this.nc)
37616
37393
  throw new Error("endpoint not started");
37617
- this.membershipFeedKv ??= await new import_kv8.Kvm(this.nc).open(membershipBucket(this.space));
37394
+ this.membershipFeedKv ??= await new import_kv6.Kvm(this.nc).open(membershipBucket(this.space));
37618
37395
  return this.membershipFeedKv;
37619
37396
  }
37620
37397
  /**
@@ -37980,7 +37757,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
37980
37757
  for await (const s of this.nc.status()) {
37981
37758
  if (s.type !== "error")
37982
37759
  continue;
37983
- if (s.error instanceof import_transport_node17.PermissionViolationError && this.confirmingChatSubs.has(s.error.subject))
37760
+ if (s.error instanceof import_transport_node14.PermissionViolationError && this.confirmingChatSubs.has(s.error.subject))
37984
37761
  continue;
37985
37762
  this.emit("error", describeStatusError(s.error));
37986
37763
  }
@@ -38203,7 +37980,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
38203
37980
  throw new Error("endpoint not started");
38204
37981
  if (this.managerLeaseKv)
38205
37982
  return this.managerLeaseKv;
38206
- const kvm = new import_kv8.Kvm((0, import_jetstream13.jetstream)(this.nc, { timeout: MANAGER_LEASE_ATTEMPT_MS }));
37983
+ const kvm = new import_kv6.Kvm((0, import_jetstream13.jetstream)(this.nc, { timeout: MANAGER_LEASE_ATTEMPT_MS }));
38207
37984
  if (this.authed) {
38208
37985
  this.managerLeaseKv = await kvm.open(managerBucket(this.space));
38209
37986
  } else {
@@ -38433,7 +38210,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
38433
38210
  filter_subject: subject,
38434
38211
  ack_policy: import_jetstream13.AckPolicy.None,
38435
38212
  mem_storage: true,
38436
- inactive_threshold: (0, import_transport_node17.nanos)(3e4),
38213
+ inactive_threshold: (0, import_transport_node14.nanos)(3e4),
38437
38214
  deliver_policy: import_jetstream13.DeliverPolicy.StartSequence,
38438
38215
  opt_start_seq: fromSeqExcl + 1
38439
38216
  });
@@ -38895,7 +38672,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
38895
38672
  channel: entry.channel,
38896
38673
  msg: authenticatedChannelMessage(entry.msg, entry.channel)
38897
38674
  };
38898
- const frameHeaders = (0, import_transport_node17.headers)();
38675
+ const frameHeaders = (0, import_transport_node14.headers)();
38899
38676
  frameHeaders.set(PLANE3_FRAME_HEADER, "1");
38900
38677
  await this.js.publish(dlvSubject(this.space, pr.owner, pr.actor, pr.lifecycleUid), JSON.stringify(frame), {
38901
38678
  msgID: `${entry.msg.id}:${owner}:${pr.lifecycleUid}:${entry.generation}`,
@@ -39025,7 +38802,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
39025
38802
  * distinct from a responder that errored. nats.js surfaces it as NoRespondersError, or a RequestError
39026
38803
  * whose `isNoResponders()` is true. */
39027
38804
  isNoResponders(e) {
39028
- return e instanceof import_transport_node17.NoRespondersError || e instanceof import_transport_node17.RequestError && e.isNoResponders();
38805
+ return e instanceof import_transport_node14.NoRespondersError || e instanceof import_transport_node14.RequestError && e.isNoResponders();
39029
38806
  }
39030
38807
  /** Agent-side: this session's CURRENT durable memberships (channel + join generation) from the
39031
38808
  * manager — the agent holds no read on the privileged members KV. `undefined` ⇒ NO control responder
@@ -39368,7 +39145,7 @@ var CotalEndpoint = class _CotalEndpoint extends import_node_events.EventEmitter
39368
39145
  filter_subject: subject,
39369
39146
  ack_policy: import_jetstream13.AckPolicy.None,
39370
39147
  mem_storage: true,
39371
- inactive_threshold: (0, import_transport_node17.nanos)(3e4),
39148
+ inactive_threshold: (0, import_transport_node14.nanos)(3e4),
39372
39149
  ..."time" in start ? { deliver_policy: import_jetstream13.DeliverPolicy.StartTime, opt_start_time: start.time.toISOString() } : { deliver_policy: import_jetstream13.DeliverPolicy.StartSequence, opt_start_seq: start.seq }
39373
39150
  });
39374
39151
  try {
@@ -39729,7 +39506,7 @@ function authOpts(a) {
39729
39506
  if (!a.sentinelCreds)
39730
39507
  throw new Error("user-mode bearer requires sentinelCreds");
39731
39508
  return {
39732
- authenticator: [(0, import_transport_node17.credsAuthenticator)(new TextEncoder().encode(a.sentinelCreds)), (0, import_transport_node17.tokenAuthenticator)(a.bearer)],
39509
+ authenticator: [(0, import_transport_node14.credsAuthenticator)(new TextEncoder().encode(a.sentinelCreds)), (0, import_transport_node14.tokenAuthenticator)(a.bearer)],
39733
39510
  tls
39734
39511
  };
39735
39512
  }
@@ -39737,7 +39514,7 @@ function authOpts(a) {
39737
39514
  if (a.token || a.user || a.pass)
39738
39515
  throw new Error("creds are mutually exclusive with token/user/pass auth");
39739
39516
  const creds = a.creds;
39740
- const authenticator = typeof creds === "function" ? (nonce3) => (0, import_transport_node17.credsAuthenticator)(new TextEncoder().encode(creds()))(nonce3) : (0, import_transport_node17.credsAuthenticator)(new TextEncoder().encode(creds));
39517
+ const authenticator = typeof creds === "function" ? (nonce3) => (0, import_transport_node14.credsAuthenticator)(new TextEncoder().encode(creds()))(nonce3) : (0, import_transport_node14.credsAuthenticator)(new TextEncoder().encode(creds));
39741
39518
  return { authenticator, tls };
39742
39519
  }
39743
39520
  return { token: a.token, user: a.user, pass: a.pass, tls };
@@ -39772,25 +39549,32 @@ function decodeBearerPrincipal(bearer) {
39772
39549
  return { owner, actor };
39773
39550
  }
39774
39551
  function describeStatusError(err2) {
39775
- if (err2 instanceof import_transport_node17.PermissionViolationError) {
39552
+ if (err2 instanceof import_transport_node14.PermissionViolationError) {
39776
39553
  return new Error(`NATS permission denied: cannot ${err2.operation} "${err2.subject}" - check this endpoint's ACLs (a denied peer looks "absent" rather than blocked)`, { cause: err2 });
39777
39554
  }
39778
39555
  return err2;
39779
39556
  }
39780
39557
  function isPermissionDenied(e) {
39781
- if (e instanceof import_transport_node17.PermissionViolationError)
39558
+ if (e instanceof import_transport_node14.PermissionViolationError)
39782
39559
  return true;
39783
- if (e?.cause instanceof import_transport_node17.PermissionViolationError)
39560
+ if (e?.cause instanceof import_transport_node14.PermissionViolationError)
39784
39561
  return true;
39785
39562
  return /permissions?\s+violation/i.test(String(e?.message ?? ""));
39786
39563
  }
39787
39564
  function isPublishPermissionDenied(e) {
39788
- const typed = e instanceof import_transport_node17.PermissionViolationError ? e : e?.cause instanceof import_transport_node17.PermissionViolationError ? e.cause : void 0;
39565
+ const typed = e instanceof import_transport_node14.PermissionViolationError ? e : e?.cause instanceof import_transport_node14.PermissionViolationError ? e.cause : void 0;
39789
39566
  return typed?.operation === "publish";
39790
39567
  }
39568
+ function wsServers(servers) {
39569
+ return /^wss?:\/\//i.test((servers.split(",")[0] ?? "").trim());
39570
+ }
39791
39571
  function dialerFor(servers) {
39792
- const first = (servers.split(",")[0] ?? "").trim();
39793
- return /^wss?:\/\//i.test(first) ? import_nats_core.wsconnect : import_transport_node17.connect;
39572
+ if (!wsServers(servers))
39573
+ return import_transport_node14.connect;
39574
+ return ((opts) => {
39575
+ const { tls: _tls, ...rest } = opts ?? {};
39576
+ return (0, import_nats_core.wsconnect)(rest);
39577
+ });
39794
39578
  }
39795
39579
  function hostPort(server) {
39796
39580
  const raw = (server.split(",")[0] ?? "").trim();
@@ -39855,13 +39639,240 @@ function classifyProbeFailure(e, opts) {
39855
39639
  } catch {
39856
39640
  }
39857
39641
  }
39858
- if (e instanceof import_transport_node17.UserAuthenticationExpiredError)
39642
+ if (e instanceof import_transport_node14.UserAuthenticationExpiredError)
39859
39643
  return { ok: false, reason: "stale-auth" };
39860
- if (e instanceof import_transport_node17.AuthorizationError)
39644
+ if (e instanceof import_transport_node14.AuthorizationError)
39861
39645
  return { ok: false, reason: "auth-required" };
39862
39646
  return { ok: false, reason: "unreachable" };
39863
39647
  }
39864
39648
 
39649
+ // ../../packages/core/dist/channels.js
39650
+ function parseDuration(s) {
39651
+ const m = /^(\d+)(s|m|h|d)$/.exec(s.trim());
39652
+ if (!m)
39653
+ throw new Error(`invalid duration "${s}" - expected <number><s|m|h|d>, e.g. "24h"`);
39654
+ const n = Number(m[1]);
39655
+ const unit = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 }[m[2]];
39656
+ return n * unit;
39657
+ }
39658
+ function effectiveReplay(cfg, defaults) {
39659
+ return cfg?.replay ?? defaults?.replay ?? true;
39660
+ }
39661
+ function effectiveReplayWindowMs(cfg, defaults) {
39662
+ const w = cfg?.replayWindow ?? defaults?.replayWindow;
39663
+ return w === void 0 ? void 0 : parseDuration(w);
39664
+ }
39665
+ function effectiveDeliveryClass(cfg, defaults) {
39666
+ return cfg?.deliveryClass ?? defaults?.deliveryClass ?? "durable";
39667
+ }
39668
+ async function openChannelRegistry(nc, space, opts = {}) {
39669
+ const kvm = new import_kv7.Kvm(nc);
39670
+ return opts.create ? kvm.create(channelBucket(space)) : kvm.open(channelBucket(space));
39671
+ }
39672
+ async function readChannelConfig(kv, channel) {
39673
+ return decode2(kv, channel);
39674
+ }
39675
+ async function readChannelDefaults(kv) {
39676
+ return decode2(kv, CHANNEL_DEFAULTS_KEY);
39677
+ }
39678
+ async function decode2(kv, key) {
39679
+ const e = await kv.get(key);
39680
+ if (!e || e.operation === "DEL" || e.operation === "PURGE")
39681
+ return void 0;
39682
+ try {
39683
+ return e.json();
39684
+ } catch {
39685
+ return void 0;
39686
+ }
39687
+ }
39688
+
39689
+ // ../../packages/core/dist/membership-feed.js
39690
+ var import_transport_node16 = __toESM(require_transport_node(), 1);
39691
+ var import_kv8 = __toESM(require_mod6(), 1);
39692
+
39693
+ // ../../packages/core/dist/evict.js
39694
+ var import_transport_node17 = __toESM(require_transport_node(), 1);
39695
+
39696
+ // ../../packages/core/dist/agent-file.js
39697
+ var import_node_fs = require("node:fs");
39698
+ var import_yaml = __toESM(require_dist(), 1);
39699
+ function parseFrontmatter(src, path) {
39700
+ let doc;
39701
+ try {
39702
+ doc = (0, import_yaml.parse)(src);
39703
+ } catch (e) {
39704
+ throw new Error(`agent file ${path}: invalid YAML frontmatter; ${e.message}`);
39705
+ }
39706
+ if (doc === null || doc === void 0)
39707
+ return {};
39708
+ if (typeof doc !== "object" || Array.isArray(doc))
39709
+ throw new Error(`agent file ${path}: frontmatter must be a YAML mapping (key: value pairs)`);
39710
+ return doc;
39711
+ }
39712
+ function loadAgentFile(path) {
39713
+ const src = (0, import_node_fs.readFileSync)(path, "utf8");
39714
+ const m = /^---\n([\s\S]*?)\n---\n?([\s\S]*)$/.exec(src);
39715
+ if (!m)
39716
+ throw new Error(`agent file ${path}: missing "---" frontmatter block`);
39717
+ const fm = parseFrontmatter(m[1], path);
39718
+ const persona = m[2].trim();
39719
+ const str2 = (k) => {
39720
+ const v = fm[k];
39721
+ if (v === void 0 || v === null)
39722
+ return void 0;
39723
+ if (typeof v === "object")
39724
+ throw new Error(`agent file ${path}: "${k}" must be a scalar`);
39725
+ return String(v);
39726
+ };
39727
+ const list = (k) => {
39728
+ const v = fm[k];
39729
+ if (v === void 0 || v === null)
39730
+ return void 0;
39731
+ return (Array.isArray(v) ? v : [v]).map((x) => {
39732
+ if (x === null || typeof x === "object")
39733
+ throw new Error(`agent file ${path}: "${k}" list items must be scalars`);
39734
+ return String(x);
39735
+ });
39736
+ };
39737
+ const name = str2("name");
39738
+ if (!name)
39739
+ throw new Error(`agent file ${path}: "name" is required`);
39740
+ assertValidName(name);
39741
+ const kind = str2("kind");
39742
+ if (kind && kind !== "agent" && kind !== "endpoint")
39743
+ throw new Error(`agent file ${path}: "kind" must be "agent" or "endpoint"`);
39744
+ for (const old of ["channels", "publish"])
39745
+ if (old in fm)
39746
+ throw new Error(`agent file ${path}: "${old}" was renamed - use "subscribe"/"allowSubscribe" (read) and "allowPublish" (post)`);
39747
+ const subscribe = list("subscribe");
39748
+ const allowSubscribe = list("allowSubscribe");
39749
+ const allowPublish = list("allowPublish");
39750
+ const quiet = list("quiet");
39751
+ const muted = list("muted");
39752
+ for (const ch of [...subscribe ?? [], ...allowSubscribe ?? [], ...allowPublish ?? []])
39753
+ try {
39754
+ assertValidChannel(ch);
39755
+ } catch (e) {
39756
+ throw new Error(`agent file ${path}: ${e.message}`);
39757
+ }
39758
+ const effSubscribe = subscribe ?? [];
39759
+ const effAllow = allowSubscribe?.length ? allowSubscribe : effSubscribe;
39760
+ for (const ch of effSubscribe)
39761
+ if (!channelInAllow(effAllow, ch))
39762
+ throw new Error(`agent file ${path}: subscribe channel "${ch}" is not within allowSubscribe [${effAllow.join(", ")}]`);
39763
+ const both = (quiet ?? []).filter((c) => (muted ?? []).includes(c));
39764
+ if (both.length)
39765
+ throw new Error(`agent file ${path}: channel(s) [${both.join(", ")}] are in both quiet and muted - pick one`);
39766
+ for (const [field, chans] of [["quiet", quiet], ["muted", muted]])
39767
+ for (const ch of chans ?? []) {
39768
+ try {
39769
+ assertValidChannel(ch);
39770
+ } catch (e) {
39771
+ throw new Error(`agent file ${path}: ${e.message}`);
39772
+ }
39773
+ if (!isConcreteChannel(ch))
39774
+ throw new Error(`agent file ${path}: ${field} channel "${ch}" must be a concrete channel (no wildcard)`);
39775
+ if (!channelInAllow(effAllow, ch))
39776
+ throw new Error(`agent file ${path}: ${field} channel "${ch}" is not within your read ACL / allowSubscribe [${effAllow.join(", ")}]`);
39777
+ }
39778
+ const launchOptionsRaw = fm["launchOptions"];
39779
+ let launchOptions;
39780
+ if (launchOptionsRaw !== void 0 && launchOptionsRaw !== null) {
39781
+ if (typeof launchOptionsRaw !== "object" || Array.isArray(launchOptionsRaw))
39782
+ throw new Error(`agent file ${path}: "launchOptions" must be a mapping of key: value pairs`);
39783
+ launchOptions = launchOptionsRaw;
39784
+ }
39785
+ const known = /* @__PURE__ */ new Set(["name", "role", "kind", "description", "tags", "subscribe", "allowSubscribe", "allowPublish", "quiet", "muted", "model", "variant", "launchOptions", "capabilities", "owner"]);
39786
+ const meta3 = {};
39787
+ for (const [k, v] of Object.entries(fm))
39788
+ if (!known.has(k) && v !== null && typeof v !== "object")
39789
+ meta3[k] = String(v);
39790
+ return {
39791
+ name,
39792
+ role: str2("role"),
39793
+ kind,
39794
+ description: str2("description"),
39795
+ tags: list("tags"),
39796
+ subscribe,
39797
+ allowSubscribe,
39798
+ allowPublish,
39799
+ quiet,
39800
+ muted,
39801
+ model: str2("model"),
39802
+ variant: str2("variant"),
39803
+ launchOptions,
39804
+ capabilities: list("capabilities"),
39805
+ owner: str2("owner"),
39806
+ meta: Object.keys(meta3).length ? meta3 : void 0,
39807
+ persona: persona || void 0
39808
+ };
39809
+ }
39810
+
39811
+ // ../../packages/core/dist/secret-fs.js
39812
+ var isWin = process.platform === "win32";
39813
+
39814
+ // ../../packages/core/dist/launch-material.js
39815
+ var import_node_fs2 = require("node:fs");
39816
+ var LAUNCH_MATERIAL_ENV = "COTAL_LAUNCH_MATERIAL";
39817
+ function readLaunchMaterial(path) {
39818
+ let raw;
39819
+ try {
39820
+ if (process.platform !== "win32") {
39821
+ const mode = (0, import_node_fs2.statSync)(path).mode & 511;
39822
+ if (mode & 63)
39823
+ throw new Error(`is readable beyond its owner (mode ${mode.toString(8)}) - refusing to read connection material out of a file other local users can open`);
39824
+ }
39825
+ raw = (0, import_node_fs2.readFileSync)(path, "utf8");
39826
+ } catch (e) {
39827
+ throw new Error(`launch material: cannot read ${path} (${e instanceof Error ? e.message : String(e)})`);
39828
+ }
39829
+ let parsed;
39830
+ try {
39831
+ parsed = JSON.parse(raw);
39832
+ } catch {
39833
+ throw new Error(`launch material: ${path} is not valid JSON`);
39834
+ }
39835
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
39836
+ throw new Error(`launch material: ${path} must contain a JSON object`);
39837
+ return validate(parsed, path);
39838
+ }
39839
+ function validate(raw, path) {
39840
+ const material = {};
39841
+ const str2 = (key) => {
39842
+ const v = raw[key];
39843
+ if (v === void 0)
39844
+ return;
39845
+ if (typeof v !== "string" || !v.trim())
39846
+ throw new Error(`launch material: ${path} has a ${key} that is not a non-empty string`);
39847
+ material[key] = v;
39848
+ };
39849
+ str2("servers");
39850
+ str2("creds");
39851
+ str2("token");
39852
+ str2("controlToken");
39853
+ if (raw.userAuth !== void 0) {
39854
+ const u = raw.userAuth;
39855
+ if (typeof u !== "object" || u === null || Array.isArray(u))
39856
+ throw new Error(`launch material: ${path} has a userAuth that is not an object`);
39857
+ const { owner, actor, sentinelCredsPath, bearerCmd } = u;
39858
+ const named = { owner, actor, sentinelCredsPath };
39859
+ for (const [k, v] of Object.entries(named))
39860
+ if (typeof v !== "string" || !v.trim())
39861
+ throw new Error(`launch material: ${path} has a userAuth.${k} that is not a non-empty string`);
39862
+ if (!Array.isArray(bearerCmd) || bearerCmd.length === 0 || !bearerCmd.every((a) => typeof a === "string" && a))
39863
+ throw new Error(`launch material: ${path} has a userAuth.bearerCmd that is not a non-empty array of strings`);
39864
+ material.userAuth = {
39865
+ owner,
39866
+ actor,
39867
+ sentinelCredsPath,
39868
+ bearerCmd
39869
+ };
39870
+ }
39871
+ if (Object.keys(material).length === 0)
39872
+ throw new Error(`launch material: ${path} carries nothing this reader recognises. A launch that references material and supplies none is a broken launcher, not an open-mode launch, so it is refused rather than defaulted.`);
39873
+ return material;
39874
+ }
39875
+
39865
39876
  // ../../packages/core/dist/spaces.js
39866
39877
  var import_transport_node18 = __toESM(require_transport_node(), 1);
39867
39878
  var import_jetstream15 = __toESM(require_mod4(), 1);
@@ -55757,7 +55768,7 @@ config(en_default());
55757
55768
 
55758
55769
  // ../connector-core/dist/docs-bundle.generated.js
55759
55770
  var DOCS_BUNDLE = {
55760
- "version": "0.28.0",
55771
+ "version": "0.28.2",
55761
55772
  "generatedFrom": "docs/*.md + SPEC.md + spec/cotal-lang.md + spec/cotal.schema.json",
55762
55773
  "pages": [
55763
55774
  {