@cotal-ai/core 0.79.0 → 0.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/channels.d.ts +9 -3
  2. package/dist/channels.d.ts.map +1 -1
  3. package/dist/channels.js +33 -15
  4. package/dist/channels.js.map +1 -1
  5. package/dist/connector.d.ts +7 -4
  6. package/dist/connector.d.ts.map +1 -1
  7. package/dist/connector.js.map +1 -1
  8. package/dist/delegated-recovery.d.ts +220 -0
  9. package/dist/delegated-recovery.d.ts.map +1 -0
  10. package/dist/delegated-recovery.js +277 -0
  11. package/dist/delegated-recovery.js.map +1 -0
  12. package/dist/endpoint-binding.d.ts +6 -0
  13. package/dist/endpoint-binding.d.ts.map +1 -1
  14. package/dist/endpoint-binding.js +14 -9
  15. package/dist/endpoint-binding.js.map +1 -1
  16. package/dist/endpoint-serve-kv.d.ts +2 -1
  17. package/dist/endpoint-serve-kv.d.ts.map +1 -1
  18. package/dist/endpoint-serve-kv.js +2 -1
  19. package/dist/endpoint-serve-kv.js.map +1 -1
  20. package/dist/endpoint-service.d.ts +2 -0
  21. package/dist/endpoint-service.d.ts.map +1 -1
  22. package/dist/endpoint-service.js.map +1 -1
  23. package/dist/endpoint.d.ts +4 -2
  24. package/dist/endpoint.d.ts.map +1 -1
  25. package/dist/endpoint.js +23 -8
  26. package/dist/endpoint.js.map +1 -1
  27. package/dist/environment-manager-grants.d.ts +19 -0
  28. package/dist/environment-manager-grants.d.ts.map +1 -0
  29. package/dist/environment-manager-grants.js +68 -0
  30. package/dist/environment-manager-grants.js.map +1 -0
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/issued-authority.d.ts +2 -0
  36. package/dist/issued-authority.d.ts.map +1 -1
  37. package/dist/issued-authority.js +1 -1
  38. package/dist/issued-authority.js.map +1 -1
  39. package/dist/lifecycle-state.d.ts +3 -0
  40. package/dist/lifecycle-state.d.ts.map +1 -1
  41. package/dist/lifecycle-state.js +3 -1
  42. package/dist/lifecycle-state.js.map +1 -1
  43. package/dist/provision.d.ts +5 -1
  44. package/dist/provision.d.ts.map +1 -1
  45. package/dist/provision.js +32 -3
  46. package/dist/provision.js.map +1 -1
  47. package/dist/run-admission.d.ts.map +1 -1
  48. package/dist/run-admission.js +2 -2
  49. package/dist/run-admission.js.map +1 -1
  50. package/dist/runtime.d.ts +22 -0
  51. package/dist/runtime.d.ts.map +1 -1
  52. package/dist/runtime.js.map +1 -1
  53. package/dist/schema-profile.d.ts.map +1 -1
  54. package/dist/schema-profile.js +2 -0
  55. package/dist/schema-profile.js.map +1 -1
  56. package/dist/startup-confirm.d.ts +25 -13
  57. package/dist/startup-confirm.d.ts.map +1 -1
  58. package/dist/startup-confirm.js +69 -17
  59. package/dist/startup-confirm.js.map +1 -1
  60. package/package.json +6 -3
package/dist/endpoint.js CHANGED
@@ -27,7 +27,7 @@ import { Bucket, KvWatchInclude } from "@nats-io/kv/internal";
27
27
  import { openMembersRegistry, commitMember, tombstoneMember, activateMember, readMember, listMembers, listLifecycleMemberChannels, durableEligible, StaleMembershipWrite, } from "./members.js";
28
28
  import { openAclRegistry, readAcl, readAclForAlias, aclRetired, AmbiguousAclAlias, commitAcl as writeAclRecord, reissueAcl as writeAclReissue } from "./acls.js";
29
29
  import { openDeliveryRegistry } from "./lease.js";
30
- import { openChannelRegistry, effectiveReplay, effectiveReplayWindowMs, effectiveDeliveryClass, readChannelConfig, readChannelDefaults, } from "./channels.js";
30
+ import { openChannelRegistry, effectiveReplay, effectiveReplayWindowMs, effectiveDeliveryClass, readChannelConfig, readChannelDefaults, decodeChannelEntry, } from "./channels.js";
31
31
  import { anycastSubject, assertValidRole, CHANNEL_DEFAULTS_KEY, chatStream, chatHistDurable, chatSubject, controlServiceSubject, livenessSubject, livenessServeFilter, CONTROL_DELIVERY, CONTROL_DELIVERY_ADMIN, dmStream, dmDurable, dlvStream, dlvDurable, dlvSubject, dinboxSubject, inboxStream, parseDinboxPrincipal, FANOUT_DURABLE, INBOX_READER_DURABLE, leaseKey, managerBucket, MANAGER_LEASE_KEY, MANAGER_RENEWAL_LEASE_KEY, managerLeaseKey, chatWildcard, assertValidChannel, channelInAllow, isConcreteChannel, normalizeMentions, parseSubject, isPrincipalOwnerToken, assertInboxConnId, presenceBucket, membershipBucket, MEMBERSHIP_FEED_KEY, principalKey, parsePrincipalKey, assertLifecycleToken, mintLifecycleUid, lifecycleNameKey, DEV_OWNER, spacePrefix, spaceWildcard, subjectMatches, taskStream, taskDurable, token, unicastSubject, unicastRecvFilter, } from "./subjects.js";
32
32
  export const DEFAULT_SERVER = "nats://127.0.0.1:4222";
33
33
  const PLANE3_FRAME_HEADER = "Cotal-Delivery-Frame";
@@ -512,7 +512,8 @@ export class CotalEndpoint extends EventEmitter {
512
512
  // principalKey validates both tokens.
513
513
  const principal = principalKey(this.owner, this.actor);
514
514
  this.card = { ...opts.card, id: principal.key, owner: this.owner, actor: this.actor };
515
- this.environment = process.env.COTAL_ENVIRONMENT?.trim() || undefined;
515
+ this.environment =
516
+ (opts.environment === undefined ? process.env.COTAL_ENVIRONMENT : opts.environment)?.trim() || undefined;
516
517
  this.servers = opts.servers ?? DEFAULT_SERVER;
517
518
  this.token = opts.token;
518
519
  this.user = opts.user;
@@ -561,7 +562,14 @@ export class CotalEndpoint extends EventEmitter {
561
562
  return flight;
562
563
  }
563
564
  async startOnce() {
564
- await this.connectAndBind();
565
+ // A stopped dial is not a teardown failure. The stopped fence still closes any late epoch.
566
+ try {
567
+ await this.connectAndBind();
568
+ }
569
+ catch (error) {
570
+ if (!this.stopped)
571
+ throw error;
572
+ }
565
573
  // stop() can finish while the INITIAL connectAndBind is still awaiting its broker work. The
566
574
  // rebuild path already closes that race; initial start needs the same fence or the late bind
567
575
  // leaves a fresh nc, heartbeat, consumers, and presence live on an endpoint already stopped.
@@ -1449,9 +1457,16 @@ export class CotalEndpoint extends EventEmitter {
1449
1457
  await this.closeWithoutLibraryReconnect(oldNc);
1450
1458
  // stop() can arrive while the old epoch closes. Do not start another authentication
1451
1459
  // handshake after it: a terminal credential may already have expired in that window.
1460
+ // Keep old-epoch and late-epoch close failures outside this dial-only catch.
1452
1461
  if (this.stopped)
1453
1462
  return;
1454
- await this.connectAndBind();
1463
+ try {
1464
+ await this.connectAndBind();
1465
+ }
1466
+ catch (error) {
1467
+ if (!this.stopped)
1468
+ throw error;
1469
+ }
1455
1470
  // stop() may have run during the await — don't leave a live connection + heartbeat +
1456
1471
  // supervisor on a stopped endpoint. (Reads this.nc in its own scope — a bare `this.nc`
1457
1472
  // here in doRebuild narrows to `never` via TS inlining connectAndBind's assignment.)
@@ -6191,8 +6206,8 @@ export class CotalEndpoint extends EventEmitter {
6191
6206
  })();
6192
6207
  }
6193
6208
  /** Watch the channel registry: replay existing keys, then stream updates, into the local
6194
- * cache. A failed bind throws out of connect; an entry that does not decode is reported as a
6195
- * `warning` and dropped, so its channel resolves to the default policy. */
6209
+ * cache. A failed bind throws out of connect; an entry that does not decode or validate is
6210
+ * reported as a `warning` and dropped, so its channel resolves to the default policy. */
6196
6211
  async startChannelWatch() {
6197
6212
  if (!this.channelKv)
6198
6213
  return;
@@ -6216,9 +6231,9 @@ export class CotalEndpoint extends EventEmitter {
6216
6231
  return;
6217
6232
  try {
6218
6233
  if (isDefaults)
6219
- this.channelDefaults = e.json();
6234
+ this.channelDefaults = decodeChannelEntry(e);
6220
6235
  else
6221
- this.channelConfigs.set(e.key, e.json());
6236
+ this.channelConfigs.set(e.key, decodeChannelEntry(e));
6222
6237
  }
6223
6238
  catch (err) {
6224
6239
  this.emitRecoverable(new Error(`dropped channel registry entry for key ${JSON.stringify(e.key)}: ${err.message}`));