@cotal-ai/core 0.78.1 → 0.79.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 (69) hide show
  1. package/dist/agent-file.d.ts +3 -0
  2. package/dist/agent-file.d.ts.map +1 -1
  3. package/dist/agent-file.js +7 -2
  4. package/dist/agent-file.js.map +1 -1
  5. package/dist/endpoint-binding.d.ts +6 -6
  6. package/dist/endpoint-binding.js +7 -7
  7. package/dist/endpoint-binding.js.map +1 -1
  8. package/dist/endpoint-envelope.d.ts +5 -1
  9. package/dist/endpoint-envelope.d.ts.map +1 -1
  10. package/dist/endpoint-envelope.js +11 -0
  11. package/dist/endpoint-envelope.js.map +1 -1
  12. package/dist/endpoint-error.d.ts +1 -1
  13. package/dist/endpoint-error.js +1 -1
  14. package/dist/endpoint-grants.d.ts +3 -3
  15. package/dist/endpoint-grants.js +4 -4
  16. package/dist/endpoint-grants.js.map +1 -1
  17. package/dist/endpoint-invoke.d.ts +1 -1
  18. package/dist/endpoint-invoke.js +3 -3
  19. package/dist/endpoint-invoke.js.map +1 -1
  20. package/dist/endpoint-reconcile.d.ts.map +1 -1
  21. package/dist/endpoint-reconcile.js +13 -20
  22. package/dist/endpoint-reconcile.js.map +1 -1
  23. package/dist/endpoint-serve-kv.d.ts +4 -5
  24. package/dist/endpoint-serve-kv.d.ts.map +1 -1
  25. package/dist/endpoint-serve-kv.js +3 -3
  26. package/dist/endpoint-serve-kv.js.map +1 -1
  27. package/dist/endpoint-service.d.ts +4 -1
  28. package/dist/endpoint-service.d.ts.map +1 -1
  29. package/dist/endpoint-service.js +12 -6
  30. package/dist/endpoint-service.js.map +1 -1
  31. package/dist/endpoint-session-rail.d.ts +1 -1
  32. package/dist/endpoint.d.ts +8 -17
  33. package/dist/endpoint.d.ts.map +1 -1
  34. package/dist/endpoint.js +11 -25
  35. package/dist/endpoint.js.map +1 -1
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/issued-authority.d.ts.map +1 -1
  41. package/dist/issued-authority.js +9 -4
  42. package/dist/issued-authority.js.map +1 -1
  43. package/dist/jetstream-missing.d.ts +8 -0
  44. package/dist/jetstream-missing.d.ts.map +1 -0
  45. package/dist/jetstream-missing.js +13 -0
  46. package/dist/jetstream-missing.js.map +1 -0
  47. package/dist/kv-scan.d.ts.map +1 -1
  48. package/dist/kv-scan.js +3 -2
  49. package/dist/kv-scan.js.map +1 -1
  50. package/dist/lease.d.ts +3 -3
  51. package/dist/lease.d.ts.map +1 -1
  52. package/dist/lifecycle-state.d.ts +4 -4
  53. package/dist/lifecycle-state.d.ts.map +1 -1
  54. package/dist/lifecycle-state.js +1 -1
  55. package/dist/lifecycle-state.js.map +1 -1
  56. package/dist/run-journal.d.ts +0 -6
  57. package/dist/run-journal.d.ts.map +1 -1
  58. package/dist/run-journal.js +1 -9
  59. package/dist/run-journal.js.map +1 -1
  60. package/dist/session-browser.d.ts +3 -3
  61. package/dist/session-browser.js +3 -3
  62. package/dist/streams.d.ts.map +1 -1
  63. package/dist/streams.js +3 -2
  64. package/dist/streams.js.map +1 -1
  65. package/dist/subjects.d.ts +6 -7
  66. package/dist/subjects.d.ts.map +1 -1
  67. package/dist/subjects.js +6 -7
  68. package/dist/subjects.js.map +1 -1
  69. package/package.json +1 -1
package/dist/endpoint.js CHANGED
@@ -15,11 +15,12 @@ import { isRepeatSafeCommand } from "./endpoint-grants.js";
15
15
  import { assertIdToken, assertGeneration } from "./endpoint-subjects.js";
16
16
  import { readAcceptedRow } from "./issued-authority.js";
17
17
  import { liveKvEntries } from "./kv-scan.js";
18
+ import { isJetStreamMissing } from "./jetstream-missing.js";
18
19
  import { ARTIFACT_PART_KIND, isArtifactPart } from "./artifact.js";
19
20
  import { assertValidName } from "./resolve.js";
20
21
  import { EVICT_PRINCIPALS_MAX } from "./evict.js";
21
22
  import { createSpaceStreams, dmDurableConfig, dlvDurableConfig, taskDurableConfig, fanoutDurableConfig, inboxReaderConfig, MAX_MSGS_PER_SUBJECT, MANAGER_LEASE_TTL_MS, MANAGER_LEASE_ATTEMPT_MS, TTL_RECONCILE_CANARY_KEY, PRESENCE_STORAGE } from "./streams.js";
22
- import { jetstream, jetstreamManager, AckPolicy, DeliverPolicy, JetStreamApiCodes, JetStreamApiError, } from "@nats-io/jetstream";
23
+ import { jetstream, jetstreamManager, AckPolicy, DeliverPolicy, JetStreamApiCodes, } from "@nats-io/jetstream";
23
24
  import {} from "@nats-io/jetstream";
24
25
  import { Kvm } from "@nats-io/kv";
25
26
  import { Bucket, KvWatchInclude } from "@nats-io/kv/internal";
@@ -1901,14 +1902,11 @@ export class CotalEndpoint extends EventEmitter {
1901
1902
  /** Serve control requests for a service. Returns the subscription so a caller that re-registers on
1902
1903
  * reconnect (the delivery daemon) can drop the stale one. `boundReply` is REQUIRED for any service
1903
1904
  * whose responder holds a wildcard publish grant over the service subtree (the delivery daemon's
1904
- * `ctl.delivery.*.reply.>`): without it, an authenticated caller could set its reply target to a
1905
+ * `ctl.delivery.*.*.reply.>`): without it, an authenticated caller could set its reply target to a
1905
1906
  * PEER's reply lane (`ctl.delivery.<victim>.reply.<n>`) and turn the responder into a confused
1906
1907
  * deputy — the broker does NOT permission-check the requester's embedded reply subject. With it, a
1907
1908
  * reply is published only when `m.reply` is under the AUTHENTICATED request subject
1908
- * (`${m.subject}.reply.…`), binding the reply to the broker-policed sender token. The manager's three
1909
- * lifecycle tiers ALSO require it as of closure (i): they reply on bounded `ctl.<tier>.<caller>.reply.…`
1910
- * (the manager cred holds the wildcard `ctl.<tier>.*.reply.>` pub — exactly the confused-deputy
1911
- * condition above), so do NOT drop `boundReply` on them. */
1909
+ * (`${m.subject}.reply.…`), binding the reply to the broker-policed sender token. */
1912
1910
  serveControl(service, handler, opts = {}) {
1913
1911
  if (!this.nc)
1914
1912
  throw new Error("endpoint not started");
@@ -1967,16 +1965,10 @@ export class CotalEndpoint extends EventEmitter {
1967
1965
  }
1968
1966
  /** Send a control request to a service and await its reply (client side). Like {@link requestDelivery},
1969
1967
  * the reply rides a BOUNDED subject UNDER the request subject (`ctl.<service>.<id>.reply.<uuid>`), not
1970
- * the per-id `_INBOX` — closure (i): this frees the manager's permission set from needing a position-1
1971
- * inbox wildcard, so its publish surface can be an exact self-scoped allow-list (no message forging).
1968
+ * the per-id `_INBOX`.
1972
1969
  * `noMux` lets us name the reply subject while keeping NoResponders detection. The random suffix is
1973
1970
  * defense-in-depth (a predictable suffix would let a peer target an in-flight named reply sub). The
1974
- * reply sits under the sender's OWN request subject, so the responder's `boundReply` guard accepts it.
1975
- *
1976
- * CUTOVER (not backward-compatible): an agent cred minted BEFORE closure (i) lacks the
1977
- * `ctl.<tier>.<id>.reply.>` sub grant — it can still publish the request but cannot subscribe the
1978
- * reply, so its control calls (spawn/despawn/purge/definePersona, self-stop) hang. The per-user-auth
1979
- * atomic cutover re-mints every agent; if this change ships ahead of that, agents must be RESPAWNED. */
1971
+ * reply sits under the sender's OWN request subject, so the responder's `boundReply` guard accepts it. */
1980
1972
  async requestControl(service, req, timeoutMs = 5000) {
1981
1973
  if (!this.nc)
1982
1974
  throw new Error(this.notLiveMsg());
@@ -2064,7 +2056,7 @@ export class CotalEndpoint extends EventEmitter {
2064
2056
  this.resolvedServices.set(endpoint, svc);
2065
2057
  return svc;
2066
2058
  }
2067
- /** GENERIC v0.4 service invoke over this endpoint's own connection (P2 item 1, 1c.2b): resolve
2059
+ /** GENERIC v0.4 service invoke over this endpoint's own connection: resolve
2068
2060
  * the named endpoint's registered surface — describe, §13.7 store fetch, digest-verified
2069
2061
  * recompile ({@link resolveService}; cached per endpoint name) — and invoke one command. The
2070
2062
  * resolve is describe-bound currency, and a call that reaches the wrong incarnation is recovered
@@ -2245,7 +2237,7 @@ export class CotalEndpoint extends EventEmitter {
2245
2237
  throw e;
2246
2238
  }
2247
2239
  };
2248
- // P2 item 2 (2b): a goal-bearing command (spawn/launch) follows its acceptance to the terminal so
2240
+ // A goal-bearing command (spawn/launch) follows its acceptance to the terminal so
2249
2241
  // the caller still returns on the real outcome (UX unchanged); every other command replies directly.
2250
2242
  if (!opts.follow)
2251
2243
  return doInvoke(await resolveFirst());
@@ -2258,8 +2250,8 @@ export class CotalEndpoint extends EventEmitter {
2258
2250
  });
2259
2251
  }
2260
2252
  /** Send a durable-membership request to the SERVER-SIDE delivery daemon (`ctl.delivery`) and await its
2261
- * reply. Unlike {@link requestControl}, the reply rides a subject UNDER `ctl.delivery.<id>.>` (not the
2262
- * per-id `_INBOX`), so the scoped delivery cred can answer without broad inbox-publish — see
2253
+ * reply. The reply rides a subject UNDER `ctl.delivery.<id>.>` (not the per-id `_INBOX`), so the
2254
+ * scoped delivery cred can answer without broad inbox-publish — see
2263
2255
  * CONTROL_DELIVERY. `noMux` lets us name the reply subject while keeping NoResponders detection (so a
2264
2256
  * caller can fail-closed vs. degrade to live-only when no daemon is present). */
2265
2257
  async requestDelivery(op, args, timeoutMs = 5000) {
@@ -3872,7 +3864,7 @@ export class CotalEndpoint extends EventEmitter {
3872
3864
  * ({@link managerLeaseKey}). THROWS only if that SAME instance id already holds a live key (a same-root
3873
3865
  * concurrent double-start, or a restart racing the crashed predecessor's not-yet-expired key) — a loud
3874
3866
  * refusal, never a retry. A DIFFERENT instance (second workspace root ⇒ different id) creates its OWN
3875
- * key and coexists (P2 item 3 demotion). A crashed holder's key auto-expires (bucket TTL). Returns the
3867
+ * key and coexists. A crashed holder's key auto-expires (bucket TTL). Returns the
3876
3868
  * lease revision (for renew). */
3877
3869
  async acquireManagerLease(info) {
3878
3870
  return (await this.managerLeaseRegistry()).create(managerLeaseKey(info.instanceId), this.encodeManagerLease({ ...info, since: Date.now() }));
@@ -6843,12 +6835,6 @@ export function isPermissionDenied(e) {
6843
6835
  return true;
6844
6836
  return /permissions?\s+violation/i.test(String(e?.message ?? ""));
6845
6837
  }
6846
- /** True only for the structured JetStream API absence codes named by the caller. A status 404 or
6847
- * message regex is too broad here: the catch sites use absence to produce a successful empty/fresh
6848
- * result, so a permission denial, timeout, or protocol failure must never pass as "not found". */
6849
- function isJetStreamMissing(e, ...codes) {
6850
- return e instanceof JetStreamApiError && codes.includes(e.code);
6851
- }
6852
6838
  /** The ordered consumer behind a KV watch, which nats.js keeps on the iterator and the KV types hide. */
6853
6839
  function kvWatchConsumer(iter) {
6854
6840
  const consumer = iter._data;