@nac3/runtime 2.5.2 → 2.6.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/nac.cjs CHANGED
@@ -7,7 +7,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7
7
  =====================================================================
8
8
 
9
9
  AUTHORITATIVE VERSION CONSTANT: see the global.NAC export at the
10
- bottom of this file. `version: '2.5.2', spec_version: '2.5'`
10
+ bottom of this file. `version: '2.6.0', spec_version: '2.6'`
11
11
  is the normative declaration. The dated changelog sections below are
12
12
  historical notes; if they ever drift from the export, the export
13
13
  wins.
@@ -6931,8 +6931,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6931
6931
 
6932
6932
  const _v25_plugins = Object.create(null);
6933
6933
 
6934
- /* The 8 backend names from SPEC.md sec 15.4. Any other name in a
6935
- manifest is a hard reject at register time. */
6934
+ /* The 9 backend names from SPEC.md sec 15.4. Any other name in a
6935
+ manifest is a hard reject at register time. `emitter-listen` is
6936
+ the v2.6 addition (RFC V26-01 hook E-3): the only real event
6937
+ source before it was postMessage, so a plugin wrapping a library
6938
+ that emits its own events (map.on('moveend'),
6939
+ video.addEventListener('timeupdate'), pdf.js 'pagechanging')
6940
+ had to fall back to polling or to a hand-written mirror node. */
6936
6941
  const _V25_VALID_BACKENDS = {
6937
6942
  'postmessage': true,
6938
6943
  'postmessage-listen': true,
@@ -6942,8 +6947,96 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
6942
6947
  'same-origin-window': true,
6943
6948
  'synthetic-mutation': true,
6944
6949
  'synthetic-poll': true,
6950
+ 'emitter-listen': true,
6945
6951
  };
6946
6952
 
6953
+ /* The closed list of NacError codes the plugin contract raises
6954
+ (SPEC.md sec 15.9), plus the namespace a plugin uses for a code
6955
+ of its own (v2.6, RFC V26-01 hook E-6). Before this, `call` lifted
6956
+ ANY string a backend put on err._code, so a plugin-specific code
6957
+ worked by accident of implementation rather than by contract --
6958
+ and a future runtime honouring the closed list could have killed
6959
+ it without breaking anything written down. */
6960
+ const _V25_ERROR_CODES = {
6961
+ 'plugin_not_registered': true,
6962
+ 'verb_not_declared': true,
6963
+ 'state_not_declared': true,
6964
+ 'event_not_declared': true,
6965
+ 'backend_unknown': true,
6966
+ 'backend_target_missing': true,
6967
+ 'cross_origin_blocked': true,
6968
+ 'state_unreadable': true,
6969
+ 'timeout': true,
6970
+ 'invalid': true,
6971
+ };
6972
+ const _V25_PLUGIN_CODE_PREFIX = 'plugin.';
6973
+
6974
+ /* Is `code` a code this contract lets a backend raise? Either one of
6975
+ the ten above, or a plugin-owned code under the reserved prefix.
6976
+ Anything else is `invalid` -- fail closed, and name what was
6977
+ refused on err.offending_code so the author can see it. */
6978
+ function _v25_isDeclaredCode(code) {
6979
+ if (typeof code !== 'string' || !code) return false;
6980
+ if (_V25_ERROR_CODES[code]) return true;
6981
+ return code.indexOf(_V25_PLUGIN_CODE_PREFIX) === 0 &&
6982
+ code.length > _V25_PLUGIN_CODE_PREFIX.length;
6983
+ }
6984
+
6985
+ /* ---------- 15.10 API handle registry (v2.6, hook E-4) ----------
6986
+
6987
+ sdk-call used to resolve its `path` against the global object and
6988
+ nothing else, so an API object that never lands on `window` -- a
6989
+ React ref, a viewer handle held in a closure, a Leaflet map
6990
+ instance -- was unreachable. SPEC 15.1 names exactly that case
6991
+ ("invoke excalidrawAPI.setElements(...) on a React ref") as a
6992
+ motivation, and the backend could not do it.
6993
+
6994
+ The host registers the object once under a name; manifests stay
6995
+ pure JSON and reference it by `handle`. */
6996
+
6997
+ const _v25_api_handles = Object.create(null);
6998
+
6999
+ function registerApiHandle(name, obj) {
7000
+ if (typeof name !== 'string' || !name) {
7001
+ const e = new Error('registerApiHandle: name must be a non-empty string');
7002
+ e.code = 'invalid'; throw e;
7003
+ }
7004
+ if (obj == null) {
7005
+ const e = new Error('registerApiHandle: handle "' + name + '" cannot be null or undefined');
7006
+ e.code = 'invalid'; throw e;
7007
+ }
7008
+ _v25_api_handles[name] = obj;
7009
+ }
7010
+
7011
+ function unregisterApiHandle(name) {
7012
+ if (typeof name !== 'string' || !name) return false;
7013
+ if (!Object.prototype.hasOwnProperty.call(_v25_api_handles, name)) return false;
7014
+ delete _v25_api_handles[name];
7015
+ return true;
7016
+ }
7017
+
7018
+ function apiHandles() {
7019
+ return Object.keys(_v25_api_handles).sort();
7020
+ }
7021
+
7022
+ /* Resolve the root a binding's `path` is walked against: a registered
7023
+ handle when the binding declares one, the global object otherwise.
7024
+ An undeclared handle is backend_target_missing, not a silent fall
7025
+ back to `window` -- the whole point is that the two are different
7026
+ places and a manifest naming the wrong one must say so. */
7027
+ function _v25_bindingRoot(binding) {
7028
+ if (binding.handle == null) return { root: global, label: 'window' };
7029
+ if (typeof binding.handle !== 'string' || !binding.handle) {
7030
+ const e = new Error('`handle` must be a non-empty string');
7031
+ e._code = 'invalid'; throw e;
7032
+ }
7033
+ if (!Object.prototype.hasOwnProperty.call(_v25_api_handles, binding.handle)) {
7034
+ const e = new Error('API handle "' + binding.handle + '" is not registered (NAC.registerApiHandle)');
7035
+ e._code = 'backend_target_missing'; throw e;
7036
+ }
7037
+ return { root: _v25_api_handles[binding.handle], label: 'handle:' + binding.handle };
7038
+ }
7039
+
6947
7040
  /* Counter for the request_id baked into every provenance event. */
6948
7041
  let _v25_req_counter = 0;
6949
7042
  function _v25_nextRequestId(prefix) {
@@ -7028,29 +7121,52 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7028
7121
  if (!path || typeof path !== 'string') {
7029
7122
  return Promise.reject(new Error('sdk-call requires `path` string'));
7030
7123
  }
7031
- const resolved = _v25_resolvePath(global, path);
7124
+ let base;
7125
+ try { base = _v25_bindingRoot(binding); }
7126
+ catch (e) { return Promise.reject(e); }
7127
+ const resolved = _v25_resolvePath(base.root, path);
7032
7128
  if (mode === 'read') {
7033
7129
  if (resolved.parent == null) {
7034
- return Promise.reject(new Error('sdk-call read: path not resolvable: ' + path));
7130
+ return Promise.reject(new Error('sdk-call read: path not resolvable: ' + base.label + '.' + path));
7035
7131
  }
7036
7132
  if (resolved.value === undefined) {
7037
- return Promise.reject(new Error('sdk-call read: path resolves to undefined: ' + path));
7133
+ return Promise.reject(new Error('sdk-call read: path resolves to undefined: ' + base.label + '.' + path));
7038
7134
  }
7039
7135
  return Promise.resolve(resolved.value);
7040
7136
  }
7041
7137
  if (mode === 'assign') {
7042
7138
  if (resolved.parent == null) {
7043
- return Promise.reject(new Error('sdk-call assign: path parent not resolvable: ' + path));
7139
+ return Promise.reject(new Error('sdk-call assign: path parent not resolvable: ' + base.label + '.' + path));
7044
7140
  }
7045
7141
  resolved.parent[resolved.key] = args;
7046
7142
  return Promise.resolve({ ok: true });
7047
7143
  }
7048
7144
  if (mode === 'invoke') {
7049
7145
  if (resolved.parent == null || typeof resolved.value !== 'function') {
7050
- return Promise.reject(new Error('sdk-call invoke: path is not a function: ' + path));
7146
+ return Promise.reject(new Error('sdk-call invoke: path is not a function: ' + base.label + '.' + path));
7147
+ }
7148
+ /* v2.6 (hook E-4): `args_order` spells out the POSITIONAL
7149
+ argument list, so a library signature like
7150
+ map.setView(center, zoom) is expressible. Without it the
7151
+ backend passes the args object as a single argument, which is
7152
+ what every published manifest does and keeps doing. */
7153
+ let list = null;
7154
+ if (binding.args_order != null) {
7155
+ if (!Array.isArray(binding.args_order)) {
7156
+ const e = new Error('sdk-call: `args_order` must be an array of arg names');
7157
+ e._code = 'invalid'; return Promise.reject(e);
7158
+ }
7159
+ const bag = (args && typeof args === 'object') ? args : {};
7160
+ list = [];
7161
+ for (let i = 0; i < binding.args_order.length; i++) {
7162
+ const k = binding.args_order[i];
7163
+ list.push(Object.prototype.hasOwnProperty.call(bag, k) ? bag[k] : undefined);
7164
+ }
7051
7165
  }
7052
7166
  try {
7053
- const ret = resolved.value.call(resolved.parent, args);
7167
+ const ret = list
7168
+ ? resolved.value.apply(resolved.parent, list)
7169
+ : resolved.value.call(resolved.parent, args);
7054
7170
  return Promise.resolve(ret);
7055
7171
  } catch (e) {
7056
7172
  return Promise.reject(e);
@@ -7293,6 +7409,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7293
7409
  whole subscription if any observed path's primary binding is
7294
7410
  not dom-mirror -- spec contract, no silent degradation. */
7295
7411
  const elements = [];
7412
+ const unresolved = [];
7296
7413
  const manifest = _v25_plugins[plugin];
7297
7414
  for (let i = 0; i < paths.length; i++) {
7298
7415
  const stateChain = manifest.state[paths[i]];
@@ -7308,9 +7425,47 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7308
7425
  }
7309
7426
  const el = document.querySelector(first.selector);
7310
7427
  if (el) elements.push(el);
7428
+ else unresolved.push(paths[i] + ' (' + first.selector + ')');
7429
+ }
7430
+ /* v2.6 (hook E-5). Until 2.5.2 an unresolved selector was dropped
7431
+ here with `if (el) elements.push(el)`, so a subscription whose
7432
+ mirror nodes were all absent observed NOTHING: subscribe()
7433
+ returned a valid handle and the callback never fired. Success
7434
+ and silence -- the silent damage this protocol exists to remove,
7435
+ inside the protocol.
7436
+
7437
+ Two ways out, and the manifest chooses:
7438
+ - no `root`: fail closed. An absent mirror node is
7439
+ backend_target_missing at subscribe time, named selector by
7440
+ selector.
7441
+ - `root` declared: observe that container with subtree:true
7442
+ and re-read on every mutation. A node that comes and goes
7443
+ (the row of a virtualised grid) is then observed by the
7444
+ container that outlives it, so the subscription survives
7445
+ the remount. The root itself must resolve -- otherwise we
7446
+ would be back to observing nothing. */
7447
+ let rootEl = null;
7448
+ if (binding.root != null) {
7449
+ if (typeof binding.root !== 'string' || !binding.root) {
7450
+ const e = new Error('synthetic-mutation: `root` must be a non-empty CSS selector');
7451
+ e._code = 'invalid'; throw e;
7452
+ }
7453
+ rootEl = document.querySelector(binding.root);
7454
+ if (!rootEl) {
7455
+ const e = new Error('synthetic-mutation: `root` selector matched no element: ' + binding.root +
7456
+ ' -- an observer with no root would never fire');
7457
+ e._code = 'backend_target_missing'; throw e;
7458
+ }
7459
+ }
7460
+ if (!rootEl && unresolved.length) {
7461
+ const e = new Error('synthetic-mutation: no element for observed state ' + unresolved.join(', ') +
7462
+ ' -- a subscription with nothing to observe would never fire; declare `root` to observe a' +
7463
+ ' container that outlives the node and re-resolve on mutation');
7464
+ e._code = 'backend_target_missing'; throw e;
7311
7465
  }
7312
7466
  let cached = null;
7313
7467
  let pending = null;
7468
+ let primed = false; /* has this subscription ever held a readable snapshot? */
7314
7469
  function snapshot() {
7315
7470
  const out = {};
7316
7471
  let allOk = true;
@@ -7334,29 +7489,48 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7334
7489
  }
7335
7490
  return false;
7336
7491
  }
7492
+ function emit(snap) {
7493
+ try { cb(snap); }
7494
+ finally {
7495
+ _v25_emitProvenance('event', plugin, event_path, 'synthetic-mutation',
7496
+ _v25_nextRequestId('pe'), true, null, 0);
7497
+ }
7498
+ }
7337
7499
  function tick() {
7338
7500
  pending = null;
7339
7501
  snapshot().then(function (snap) {
7340
7502
  if (snap == null) return;
7341
- if (cached == null) { cached = snap; return; }
7503
+ if (cached == null) {
7504
+ cached = snap;
7505
+ /* v2.6 (hook E-5): the subscription started with NOTHING
7506
+ readable -- the observed node was not painted when
7507
+ subscribe() was called, which under `root` is a legal and
7508
+ expected state. The move from unreadable to readable IS
7509
+ the change the caller is waiting for; adopting it as a
7510
+ silent baseline is how a row that remounts goes unnoticed.
7511
+ When the first snapshot DID resolve, this branch never
7512
+ runs and the baseline behaviour of 2.5 is untouched. */
7513
+ if (!primed) { primed = true; emit(snap); }
7514
+ return;
7515
+ }
7342
7516
  if (diffsFromCached(snap)) {
7343
7517
  cached = snap;
7344
- try { cb(snap); }
7345
- finally {
7346
- _v25_emitProvenance('event', plugin, event_path, 'synthetic-mutation',
7347
- _v25_nextRequestId('pe'), true, null, 0);
7348
- }
7518
+ emit(snap);
7349
7519
  }
7350
7520
  });
7351
7521
  }
7352
- /* Prime cache from first snapshot. */
7353
- snapshot().then(function (first) { if (first != null) cached = first; });
7522
+ /* Prime cache from first snapshot. A tick that got there first
7523
+ keeps its snapshot: the fresher read wins. */
7524
+ snapshot().then(function (first) {
7525
+ if (first != null && cached == null) { cached = first; primed = true; }
7526
+ });
7354
7527
  const observer = new MutationObserver(function () {
7355
7528
  if (pending != null) return; /* already throttled */
7356
7529
  pending = setTimeout(tick, throttle);
7357
7530
  });
7358
- for (let i = 0; i < elements.length; i++) {
7359
- observer.observe(elements[i], {
7531
+ const watched = rootEl ? [rootEl] : elements;
7532
+ for (let i = 0; i < watched.length; i++) {
7533
+ observer.observe(watched[i], {
7360
7534
  attributes: true, childList: true, characterData: true, subtree: true,
7361
7535
  });
7362
7536
  }
@@ -7366,6 +7540,117 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7366
7540
  };
7367
7541
  }
7368
7542
 
7543
+ /* emitter-listen (event, v2.6 -- hook E-3): subscribe to a real
7544
+ event source that is NOT postMessage. The emitter is the global
7545
+ object, a dotted path into it, or a registered API handle; the
7546
+ subscribe / unsubscribe method pair is detected from the three
7547
+ shapes libraries actually ship (on/off, addEventListener/
7548
+ removeEventListener, addListener/removeListener) or declared
7549
+ outright.
7550
+
7551
+ Fail closed in both directions: no subscribe method is
7552
+ backend_target_missing, and NO REMOVAL METHOD is too -- a
7553
+ subscription that cannot be torn down is a leak dressed as a
7554
+ success, and unsubscribe() is part of the published contract.
7555
+
7556
+ Payload: `extract` plucks a field out of the event object the
7557
+ library hands us. `observe` instead re-reads declared state paths
7558
+ and fires the callback with that snapshot -- the useful shape for
7559
+ a continuous surface, where the event only says "it moved" and
7560
+ the state says where it moved to. */
7561
+ const _V25_LISTEN_PAIRS = {
7562
+ 'on': 'off',
7563
+ 'addEventListener': 'removeEventListener',
7564
+ 'addListener': 'removeListener',
7565
+ };
7566
+
7567
+ function _v25_subscribe_emitter_listen(plugin, event_path, binding, cb) {
7568
+ const eventName = binding.event;
7569
+ if (!eventName || typeof eventName !== 'string') {
7570
+ const e = new Error('emitter-listen requires `event` (the library event name)');
7571
+ e._code = 'invalid'; throw e;
7572
+ }
7573
+ const base = _v25_bindingRoot(binding); /* throws with _code */
7574
+ let target = base.root;
7575
+ if (binding.path != null) {
7576
+ if (typeof binding.path !== 'string' || !binding.path) {
7577
+ const e = new Error('emitter-listen: `path` must be a non-empty dotted path');
7578
+ e._code = 'invalid'; throw e;
7579
+ }
7580
+ target = _v25_resolvePath(base.root, binding.path).value;
7581
+ }
7582
+ if (target == null) {
7583
+ const e = new Error('emitter-listen: emitter not resolvable at ' + base.label +
7584
+ (binding.path ? '.' + binding.path : ''));
7585
+ e._code = 'backend_target_missing'; throw e;
7586
+ }
7587
+ let onName = binding.method;
7588
+ if (onName != null) {
7589
+ if (typeof onName !== 'string' || typeof target[onName] !== 'function') {
7590
+ const e = new Error('emitter-listen: declared `method` "' + onName + '" is not a function on the emitter');
7591
+ e._code = 'backend_target_missing'; throw e;
7592
+ }
7593
+ } else {
7594
+ onName = null;
7595
+ for (const cand in _V25_LISTEN_PAIRS) {
7596
+ if (typeof target[cand] === 'function') { onName = cand; break; }
7597
+ }
7598
+ if (!onName) {
7599
+ const e = new Error('emitter-listen: emitter exposes none of on / addEventListener / addListener');
7600
+ e._code = 'backend_target_missing'; throw e;
7601
+ }
7602
+ }
7603
+ const offName = binding.off_method || _V25_LISTEN_PAIRS[onName] || null;
7604
+ if (!offName || typeof target[offName] !== 'function') {
7605
+ const e = new Error('emitter-listen: emitter has no removal method (' +
7606
+ (offName || 'none derivable from "' + onName + '"') +
7607
+ ') -- a subscription that cannot be torn down is refused');
7608
+ e._code = 'backend_target_missing'; throw e;
7609
+ }
7610
+ const observed = Array.isArray(binding.observe) ? binding.observe.slice() : null;
7611
+ if (observed) {
7612
+ for (let i = 0; i < observed.length; i++) {
7613
+ if (!_v25_plugins[plugin].state[observed[i]]) {
7614
+ const e = new Error('emitter-listen: observed state "' + observed[i] + '" not declared');
7615
+ e._code = 'invalid'; throw e;
7616
+ }
7617
+ }
7618
+ }
7619
+ function fire(value, ok, errMsg) {
7620
+ try { if (ok) cb(value); }
7621
+ finally {
7622
+ _v25_emitProvenance('event', plugin, event_path, 'emitter-listen',
7623
+ _v25_nextRequestId('pe'), !!ok, errMsg || null, 0);
7624
+ }
7625
+ }
7626
+ function handler(payload) {
7627
+ if (observed) {
7628
+ const out = {};
7629
+ let allOk = true;
7630
+ Promise.all(observed.map(function (p) {
7631
+ return read(plugin, p).then(function (v) { out[p] = v; },
7632
+ function () { allOk = false; });
7633
+ })).then(function () {
7634
+ if (allOk) fire(out, true, null);
7635
+ else fire(null, false, 'observed state unreadable at event time');
7636
+ });
7637
+ return;
7638
+ }
7639
+ let value;
7640
+ try {
7641
+ value = binding.extract ? _v25_extract(payload, binding.extract, false) : payload;
7642
+ } catch (e) {
7643
+ fire(null, false, e.message);
7644
+ return;
7645
+ }
7646
+ fire(value, true, null);
7647
+ }
7648
+ target[onName](eventName, handler);
7649
+ return function teardown() {
7650
+ try { target[offName](eventName, handler); } catch (_) { /* idempotent */ }
7651
+ };
7652
+ }
7653
+
7369
7654
  /* postmessage-listen (event): subscribe to incoming `message` events
7370
7655
  on the host window, filter by source iframe + MessageId, run the
7371
7656
  extractor, fire the user callback. Returns a teardown closure. */
@@ -7417,10 +7702,90 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7417
7702
  'postmessage-listen': _v25_subscribe_postmessage_listen,
7418
7703
  'synthetic-poll': _v25_subscribe_synthetic_poll,
7419
7704
  'synthetic-mutation': _v25_subscribe_synthetic_mutation,
7705
+ 'emitter-listen': _v25_subscribe_emitter_listen,
7420
7706
  };
7421
7707
 
7422
7708
  /* ---------- 15.2 / 15.3 public surface ---------- */
7423
7709
 
7710
+ /* ---------- 15.11 self-description (v2.6, hook E-2) ----------
7711
+
7712
+ A manifest used to declare only WHERE a verb routes, never what it
7713
+ is called or what it takes. The DOM half of the protocol has had
7714
+ that since v1 (a label, a hint, `fields[]` with a type); the
7715
+ plugin half had nothing, so on a continuous surface -- where the
7716
+ actionable thing IS the argument: a coordinate and a zoom, an
7717
+ instant, a page, a pose -- nothing declared the shape, the unit or
7718
+ the range of what travels in `args`, and a voice runner could not
7719
+ even name the verb out loud.
7720
+
7721
+ All of it is OPTIONAL: every manifest published against 2.5 stays
7722
+ valid. What is NOT optional is being well-formed when declared --
7723
+ a label that is not a string, or a param of a type the vocabulary
7724
+ does not have, is `invalid` at register time rather than a
7725
+ surprise at the moment an agent reads it. */
7726
+
7727
+ const _V25_PARAM_TYPES = {
7728
+ 'string': true, 'number': true, 'boolean': true, 'object': true, 'array': true,
7729
+ };
7730
+
7731
+ function _v25_validateText(value, where, field) {
7732
+ if (value == null) return;
7733
+ if (typeof value !== 'string' || !value.trim()) {
7734
+ const e = new Error(where + ': `' + field + '` must be a non-empty string when declared');
7735
+ e.code = 'invalid'; throw e;
7736
+ }
7737
+ }
7738
+
7739
+ function _v25_validateParams(params, where) {
7740
+ if (params == null) return;
7741
+ if (!Array.isArray(params)) {
7742
+ const e = new Error(where + ': `params` must be an array of parameter declarations');
7743
+ e.code = 'invalid'; throw e;
7744
+ }
7745
+ const seen = Object.create(null);
7746
+ for (let i = 0; i < params.length; i++) {
7747
+ const p = params[i];
7748
+ const at = where + ' params[' + i + ']';
7749
+ if (!p || typeof p !== 'object' || Array.isArray(p)) {
7750
+ const e = new Error(at + ': must be an object');
7751
+ e.code = 'invalid'; throw e;
7752
+ }
7753
+ if (typeof p.name !== 'string' || !p.name.trim()) {
7754
+ const e = new Error(at + ': `name` is required and must be a non-empty string');
7755
+ e.code = 'invalid'; throw e;
7756
+ }
7757
+ if (seen[p.name]) {
7758
+ const e = new Error(at + ': duplicate parameter name "' + p.name + '"');
7759
+ e.code = 'invalid'; throw e;
7760
+ }
7761
+ seen[p.name] = true;
7762
+ if (typeof p.type !== 'string' || !_V25_PARAM_TYPES[p.type]) {
7763
+ const e = new Error(at + ': `type` must be one of string, number, boolean, object, array (got ' +
7764
+ JSON.stringify(p.type) + ')');
7765
+ e.code = 'invalid'; throw e;
7766
+ }
7767
+ if (p.required != null && typeof p.required !== 'boolean') {
7768
+ const e = new Error(at + ': `required` must be a boolean when declared');
7769
+ e.code = 'invalid'; throw e;
7770
+ }
7771
+ _v25_validateText(p.label, at, 'label');
7772
+ _v25_validateText(p.hint, at, 'hint');
7773
+ _v25_validateText(p.unit, at, 'unit');
7774
+ if (p.min != null && typeof p.min !== 'number') {
7775
+ const e = new Error(at + ': `min` must be a number when declared');
7776
+ e.code = 'invalid'; throw e;
7777
+ }
7778
+ if (p.max != null && typeof p.max !== 'number') {
7779
+ const e = new Error(at + ': `max` must be a number when declared');
7780
+ e.code = 'invalid'; throw e;
7781
+ }
7782
+ if (p.enum != null && (!Array.isArray(p.enum) || p.enum.length === 0)) {
7783
+ const e = new Error(at + ': `enum` must be a non-empty array when declared');
7784
+ e.code = 'invalid'; throw e;
7785
+ }
7786
+ }
7787
+ }
7788
+
7424
7789
  function _v25_validateManifest(slug, manifest) {
7425
7790
  if (typeof slug !== 'string' || !slug) {
7426
7791
  const e = new Error('registerPlugin: slug must be non-empty string');
@@ -7433,6 +7798,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7433
7798
  const verbs = manifest.verbs || {};
7434
7799
  const states = manifest.state || {};
7435
7800
  const events = manifest.events || {};
7801
+ _v25_validateText(manifest.label, 'manifest "' + slug + '"', 'label');
7802
+ _v25_validateText(manifest.hint, 'manifest "' + slug + '"', 'hint');
7436
7803
  /* Verbs: single binding each, backend in vocabulary. */
7437
7804
  for (const vp in verbs) {
7438
7805
  const b = verbs[vp];
@@ -7444,6 +7811,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7444
7811
  const e = new Error('verb "' + vp + '" declares unknown backend: ' + b.backend);
7445
7812
  e.code = 'backend_unknown'; throw e;
7446
7813
  }
7814
+ _v25_validateText(b.label, 'verb "' + vp + '"', 'label');
7815
+ _v25_validateText(b.hint, 'verb "' + vp + '"', 'hint');
7816
+ _v25_validateParams(b.params, 'verb "' + vp + '"');
7447
7817
  }
7448
7818
  /* State: array of bindings each. */
7449
7819
  for (const sp in states) {
@@ -7462,6 +7832,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7462
7832
  const e = new Error('state "' + sp + '" binding[' + i + '] unknown backend: ' + b.backend);
7463
7833
  e.code = 'backend_unknown'; throw e;
7464
7834
  }
7835
+ _v25_validateText(b.label, 'state "' + sp + '" binding[' + i + ']', 'label');
7836
+ _v25_validateText(b.hint, 'state "' + sp + '" binding[' + i + ']', 'hint');
7837
+ _v25_validateText(b.unit, 'state "' + sp + '" binding[' + i + ']', 'unit');
7465
7838
  }
7466
7839
  }
7467
7840
  /* Events: single binding each. */
@@ -7475,6 +7848,16 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7475
7848
  const e = new Error('event "' + ep + '" unknown backend: ' + b.backend);
7476
7849
  e.code = 'backend_unknown'; throw e;
7477
7850
  }
7851
+ _v25_validateText(b.label, 'event "' + ep + '"', 'label');
7852
+ _v25_validateText(b.hint, 'event "' + ep + '"', 'hint');
7853
+ /* emitter-listen carries the one field the runtime cannot guess
7854
+ (v2.6): which event of the library to listen for. Caught here
7855
+ instead of at subscribe time so a manifest that can never work
7856
+ is refused when it is registered. */
7857
+ if (b.backend === 'emitter-listen' && (typeof b.event !== 'string' || !b.event)) {
7858
+ const e = new Error('event "' + ep + '": emitter-listen requires `event` (the library event name)');
7859
+ e.code = 'invalid'; throw e;
7860
+ }
7478
7861
  }
7479
7862
  }
7480
7863
 
@@ -7483,12 +7866,121 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7483
7866
  /* Re-register replaces -- idempotent for live-reload scenarios. */
7484
7867
  _v25_plugins[slug] = {
7485
7868
  slug: slug,
7869
+ label: manifest.label != null ? manifest.label : null,
7870
+ hint: manifest.hint != null ? manifest.hint : null,
7486
7871
  verbs: manifest.verbs || {},
7487
7872
  state: manifest.state || {},
7488
7873
  events: manifest.events || {},
7489
7874
  };
7490
7875
  }
7491
7876
 
7877
+ /* ---------- 15.10 discovery (v2.6, hook E-1) ----------
7878
+
7879
+ Until 2.5.2 the registry was readable by exactly three functions
7880
+ -- call, read and subscribe -- and all three require the caller to
7881
+ already know the slug and the path. An agent that did not register
7882
+ the plugin itself had no way to learn it exists: it read the DOM
7883
+ manifest (section 5), found the chrome, and the canvas surface was
7884
+ INVISIBLE. For a plugin that declares no DOM at all there was
7885
+ nothing to find whatsoever.
7886
+
7887
+ plugins() and describePlugin() are the read-only answer. They are
7888
+ SYNCHRONOUS on purpose -- unlike call / read / subscribe, which
7889
+ reach a surface and therefore have to be async, these only read a
7890
+ local object. And they hand back a COPY: a caller cannot reach the
7891
+ live registry through the descriptor and rewrite another plugin's
7892
+ routing. */
7893
+
7894
+ function _v25_copy(value) {
7895
+ if (value == null || typeof value !== 'object') return value;
7896
+ try { return JSON.parse(JSON.stringify(value)); }
7897
+ catch (_) { return undefined; } /* not representable as data */
7898
+ }
7899
+
7900
+ function _v25_describeEntry(entry) {
7901
+ const out = {
7902
+ slug: entry.slug,
7903
+ label: entry.label != null ? entry.label : null,
7904
+ hint: entry.hint != null ? entry.hint : null,
7905
+ verbs: [],
7906
+ state: [],
7907
+ events: [],
7908
+ };
7909
+ const verbPaths = Object.keys(entry.verbs).sort();
7910
+ for (let i = 0; i < verbPaths.length; i++) {
7911
+ const vp = verbPaths[i];
7912
+ const b = entry.verbs[vp] || {};
7913
+ const row = {
7914
+ verb_path: vp,
7915
+ backend: b.backend || null,
7916
+ label: b.label != null ? b.label : null,
7917
+ hint: b.hint != null ? b.hint : null,
7918
+ params: Array.isArray(b.params) ? _v25_copy(b.params) : null,
7919
+ };
7920
+ if (b.handle != null) row.handle = b.handle;
7921
+ out.verbs.push(row);
7922
+ }
7923
+ const statePaths = Object.keys(entry.state).sort();
7924
+ for (let i = 0; i < statePaths.length; i++) {
7925
+ const sp = statePaths[i];
7926
+ const chain = entry.state[sp] || [];
7927
+ /* The label of a state PATH is the first one its chain declares:
7928
+ the chain is an ordered preference of sources for one value,
7929
+ so the value is named once, by whichever source names it. */
7930
+ let label = null; let hint = null; let unit = null;
7931
+ const backends = [];
7932
+ for (let j = 0; j < chain.length; j++) {
7933
+ const b = chain[j] || {};
7934
+ if (label == null && b.label != null) label = b.label;
7935
+ if (hint == null && b.hint != null) hint = b.hint;
7936
+ if (unit == null && b.unit != null) unit = b.unit;
7937
+ backends.push(b.backend || null);
7938
+ }
7939
+ out.state.push({
7940
+ state_path: sp,
7941
+ backends: backends,
7942
+ label: label,
7943
+ hint: hint,
7944
+ unit: unit,
7945
+ });
7946
+ }
7947
+ const eventPaths = Object.keys(entry.events).sort();
7948
+ for (let i = 0; i < eventPaths.length; i++) {
7949
+ const ep = eventPaths[i];
7950
+ const b = entry.events[ep] || {};
7951
+ const row = {
7952
+ event_path: ep,
7953
+ backend: b.backend || null,
7954
+ label: b.label != null ? b.label : null,
7955
+ hint: b.hint != null ? b.hint : null,
7956
+ observe: Array.isArray(b.observe) ? b.observe.slice() : null,
7957
+ };
7958
+ if (b.event != null) row.event = b.event;
7959
+ out.events.push(row);
7960
+ }
7961
+ return out;
7962
+ }
7963
+
7964
+ function plugins() {
7965
+ const slugs = Object.keys(_v25_plugins).sort();
7966
+ const out = [];
7967
+ for (let i = 0; i < slugs.length; i++) {
7968
+ out.push(_v25_describeEntry(_v25_plugins[slugs[i]]));
7969
+ }
7970
+ return out;
7971
+ }
7972
+
7973
+ function describePlugin(slug) {
7974
+ if (typeof slug !== 'string' || !slug) {
7975
+ throw _v25_buildNacError('invalid', 'NAC.describePlugin: slug must be a non-empty string');
7976
+ }
7977
+ if (!_v25_plugins[slug]) {
7978
+ throw _v25_buildNacError('plugin_not_registered',
7979
+ 'NAC.describePlugin: plugin "' + slug + '" not registered');
7980
+ }
7981
+ return _v25_describeEntry(_v25_plugins[slug]);
7982
+ }
7983
+
7492
7984
  /* Provenance emit helper -- the kind is one of 'invoked', 'read',
7493
7985
  'event'. Detail shape per SPEC.md sec 15.7. */
7494
7986
  function _v25_emitProvenance(kind, plugin, path, backend, request_id, ok, error, duration_ms, extra) {
@@ -7557,7 +8049,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7557
8049
  const msg = (err && err.message) || String(err);
7558
8050
  _v25_emitProvenance('invoked', plugin, verb_path, binding.backend, request_id, false, msg, Date.now() - t0);
7559
8051
  if (err && err._code) {
7560
- throw _v25_buildNacError(err._code, msg);
8052
+ /* v2.6 (hook E-6): the code has to be one the contract
8053
+ declares -- one of the ten of 15.9, or a plugin-owned code
8054
+ under the `plugin.` prefix. Anything else is `invalid` and
8055
+ names what it refused, instead of inventing a code the
8056
+ published list does not have. */
8057
+ if (_v25_isDeclaredCode(err._code)) {
8058
+ throw _v25_buildNacError(err._code, msg);
8059
+ }
8060
+ throw _v25_buildNacError('invalid',
8061
+ 'NAC.call: backend raised the undeclared error code "' + err._code +
8062
+ '" (SPEC 15.9: one of the ten contract codes, or a plugin code under the "' +
8063
+ _V25_PLUGIN_CODE_PREFIX + '" prefix): ' + msg,
8064
+ { offending_code: err._code });
7561
8065
  }
7562
8066
  throw err;
7563
8067
  });
@@ -7654,7 +8158,12 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7654
8158
  let teardown;
7655
8159
  try { teardown = subscriber(plugin, event_path, binding, cb); }
7656
8160
  catch (e) {
7657
- if (e && e._code) throw _v25_buildNacError(e._code, e.message);
8161
+ if (e && e._code) {
8162
+ if (_v25_isDeclaredCode(e._code)) throw _v25_buildNacError(e._code, e.message);
8163
+ throw _v25_buildNacError('invalid',
8164
+ 'NAC.subscribe: backend raised the undeclared error code "' + e._code +
8165
+ '" (SPEC 15.9): ' + e.message, { offending_code: e._code });
8166
+ }
7658
8167
  throw e;
7659
8168
  }
7660
8169
  _v25_sub_counter += 1;
@@ -7922,8 +8431,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
7922
8431
 
7923
8432
  global.NAC = {
7924
8433
  __nac_v1_installed: true,
7925
- version: '2.5.2',
7926
- spec_version: '2.5',
8434
+ version: '2.6.0',
8435
+ spec_version: '2.6',
7927
8436
  /* v2.2.0 (V22-01) -- strict validation toggle. When true,
7928
8437
  NAC.register throws on findings (manifest_role_unknown,
7929
8438
  tab_id_manifest_role_drift, manifest_dom_role_mismatch).
@@ -8173,6 +8682,17 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
8173
8682
  read: read,
8174
8683
  subscribe: subscribe,
8175
8684
  unsubscribe: unsubscribe,
8685
+ /* v2.6 -- the six hooks of RFC V26-01 (SPEC.md sec 15.10 / 15.11).
8686
+ plugins() + describePlugin() make the registry discoverable, so
8687
+ a plugin living in another repository under another licence can
8688
+ be FOUND by an agent that did not register it; registerApiHandle
8689
+ lets a manifest route to an API object that never lands on
8690
+ window (a React ref, a library instance held in a closure). */
8691
+ plugins: plugins,
8692
+ describePlugin: describePlugin,
8693
+ registerApiHandle: registerApiHandle,
8694
+ unregisterApiHandle: unregisterApiHandle,
8695
+ apiHandles: apiHandles,
8176
8696
  /* v2.5 Block C -- assistive labels (SPEC.md sec 17 / RFC V25-03).
8177
8697
  Canonical human-readable label resolution for screen readers,
8178
8698
  TTS, voice flows, audit logs. Priority order: aria-label >