@nac3/runtime 2.8.0 → 2.9.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.
@@ -0,0 +1,561 @@
1
+ // Generated by build.mjs -- do not edit. Source: yujin.app/nac-spec/js/nac-mcp-interop.js
2
+ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : {});
3
+ /**
4
+ * NAC MCP Interop -- host-side runtime for cross-app navigation.
5
+ *
6
+ * Adds FOUR public functions to window.NAC:
7
+ *
8
+ * NAC.export_tree(opts?) -> NACExportV1
9
+ * NAC.import_remote_tree(payload, conn) -> RemoteHandle
10
+ * NAC.list_remote_apps() -> RemoteHandle[]
11
+ * NAC.disconnect_remote(namespace) -> void
12
+ *
13
+ * And patches NAC.click / fill / tab / tab_by_label / etc to
14
+ * detect 'remote:<namespace>:<peer_id>' prefixes and proxy the
15
+ * call via the registered transport (http or stdio).
16
+ *
17
+ * Spec: docs/NAC_INTEROP_MCP.md.
18
+ *
19
+ * STATUS: published since 2.9.0 as the fourth entry of the package
20
+ * (owner decision D-31 of 2026-11-27, closing PND-137). Until that day
21
+ * this header said "v2.3 PREVIEW, lives in branch feat/nac-interop-mcp"
22
+ * while the file sat in main and reached no adopter: the build emitted
23
+ * three bundles and npm install brought none of this.
24
+ *
25
+ * import '@nac3/runtime'; // first: the runtime
26
+ * import '@nac3/runtime/mcp-interop'; // then: this
27
+ *
28
+ * Load order is the same contract js/nac-v2-extensions.js has: with no
29
+ * window.NAC this file warns and installs nothing.
30
+ *
31
+ * WHAT IT IS NOT. Cross-app navigation is OPTIONAL and no conformance
32
+ * level mentions it. An agent reaches a NAC3 application by calling
33
+ * NAC.click / NAC.call on the document, or through the intermediary of
34
+ * SPEC 11.1; what this file adds is a different capability -- driving a
35
+ * SECOND application by name from inside the first.
36
+ *
37
+ * IT NEEDS A DOCUMENT. The proxy reports through DOM events, so three
38
+ * of the four functions refuse by name under the headless profile
39
+ * (SPEC 19) instead of throwing ReferenceError at a property of
40
+ * undefined -- the same rule D-26 wrote for the primitives of the core
41
+ * runtime. list_remote_apps() reads state only and works anywhere.
42
+ */
43
+
44
+ (function (global) {
45
+ 'use strict';
46
+
47
+ if (!global.NAC) {
48
+ console.warn('[nac-interop] NAC runtime not loaded yet; skipping interop install');
49
+ return;
50
+ }
51
+ if (global.NAC.__interop_installed) return;
52
+ global.NAC.__interop_installed = true;
53
+
54
+ var REMOTE_PREFIX = 'remote:';
55
+ var _remotes = Object.create(null); /* namespace -> RemoteHandle */
56
+ var _origClick, _origFill, _origSelect, _origTab, _origTabByLabel,
57
+ _origGoToSection, _origDragDrop, _origEditField,
58
+ _origDtAddRow, _origDtRemoveRow, _origDtEditCell, _origDtCommit,
59
+ _origDtDiscard, _origDtReadAggregate;
60
+
61
+ /* ---------- Helpers ---------- */
62
+
63
+ function _now() { return new Date().toISOString(); }
64
+
65
+ function _err(code, message) {
66
+ var e = new Error(message);
67
+ e.code = code;
68
+ return e;
69
+ }
70
+
71
+ /* D-26 made this the rule for the core runtime: a primitive that
72
+ needs a document NAMES that it has none instead of dying on a
73
+ property of undefined. This module became publishable the day it
74
+ entered the package (D-31), and a published entry that throws
75
+ ReferenceError on a server is the same defect wearing a new file
76
+ name. Three of the four public functions report through DOM
77
+ events; list_remote_apps does not, and is not guarded. */
78
+ function _requireDocument(fnName) {
79
+ if (typeof document === 'undefined') {
80
+ throw _err('no_document',
81
+ fnName + ': cross-app navigation reports through DOM events and there is no '
82
+ + 'document in this process (SPEC 19 headless profile). list_remote_apps() is '
83
+ + 'the only function here that works without one.');
84
+ }
85
+ }
86
+
87
+ function _parseRemote(nac_id) {
88
+ if (typeof nac_id !== 'string') return null;
89
+ if (nac_id.indexOf(REMOTE_PREFIX) !== 0) return null;
90
+ var rest = nac_id.slice(REMOTE_PREFIX.length);
91
+ var colon = rest.indexOf(':');
92
+ if (colon < 0) return null;
93
+ return {
94
+ namespace: rest.slice(0, colon),
95
+ peer_id: rest.slice(colon + 1)
96
+ };
97
+ }
98
+
99
+ function _emitLocalAck(plugin, action_id, ok, detail) {
100
+ var name = ok ? 'nac:action:succeeded' : 'nac:action:failed';
101
+ document.dispatchEvent(new CustomEvent(name, {
102
+ detail: Object.assign({
103
+ plugin: plugin,
104
+ action_id: action_id,
105
+ is_trusted: false, /* remote actions are NEVER user-trusted */
106
+ via_interop: true
107
+ }, detail || {})
108
+ }));
109
+ }
110
+
111
+ /* ---------- export_tree ---------- */
112
+
113
+ function export_tree(opts) {
114
+ _requireDocument('export_tree');
115
+ opts = opts || {};
116
+ var scope = opts.scope || 'full';
117
+ var includeDom = !!opts.include_dom_state;
118
+ var includeLocales = opts.include_locales || null;
119
+
120
+ /* Collect manifests. We prefer NAC.list_registered_plugins
121
+ (v2.3 introspection helper) because it returns EVERY
122
+ registered manifest regardless of DOM mount state -- which
123
+ is the correct behavior for export (a peer can want to
124
+ export a manifest even if the plugin's DOM is currently
125
+ hidden). Fall back to NAC.describe()'s plugin list if the
126
+ helper isn't there (older runtimes). */
127
+ var manifests = {};
128
+ var snap = (typeof global.NAC.describe === 'function') ? global.NAC.describe() : { plugins: [], active: null };
129
+ var pluginSlugs;
130
+ if (typeof global.NAC.list_registered_plugins === 'function') {
131
+ pluginSlugs = global.NAC.list_registered_plugins();
132
+ } else {
133
+ pluginSlugs = (snap.plugins || []).map(function (p) { return p && p.plugin; }).filter(Boolean);
134
+ }
135
+ pluginSlugs.forEach(function (slug) {
136
+ var m = (typeof global.NAC.manifest === 'function') ? global.NAC.manifest(slug) : null;
137
+ if (!m) return;
138
+ if (includeLocales && Array.isArray(includeLocales)) {
139
+ m = _filterLocales(m, includeLocales);
140
+ }
141
+ if (scope === 'active_plugin' && snap.active !== slug) return;
142
+ if (scope.indexOf('plugin_slug:') === 0 && scope.slice(12) !== slug) return;
143
+ manifests[slug] = m;
144
+ });
145
+
146
+ /* Collect v2.0 scope tree if available. */
147
+ var scopeTree = [];
148
+ var dataTables = [];
149
+ if (typeof global.NAC.describe_v2 === 'function') {
150
+ try {
151
+ var v2 = global.NAC.describe_v2();
152
+ scopeTree = v2.v2_scope_entries || [];
153
+ dataTables = v2.data_tables || [];
154
+ } catch (e) { /* tolerated */ }
155
+ }
156
+
157
+ /* State block. */
158
+ var state = {
159
+ user_lang: (global.NacChat && global.NacChat._lang) || document.documentElement.lang || 'en'
160
+ };
161
+ if (includeDom) {
162
+ state.url = location.href;
163
+ state.title = document.title;
164
+ }
165
+
166
+ return {
167
+ app_id: global.__YUJIN_APP_ID__ || 'nac-app-' + Math.random().toString(36).slice(2, 10),
168
+ app_version: global.__YUJIN_APP_VERSION__ || '1.0.0',
169
+ nac_version: '2.3',
170
+ exported_at: _now(),
171
+ active_plugin: snap.active || null,
172
+ manifests: manifests,
173
+ scope_tree: scopeTree,
174
+ data_tables: dataTables,
175
+ state: state,
176
+ ack_endpoint: global.__YUJIN_ACK_ENDPOINT__ || null /* host-configurable */
177
+ };
178
+ }
179
+
180
+ function _filterLocales(manifest, locales) {
181
+ /* Deep-clone the manifest with label_i18n restricted to the
182
+ requested locales. Idempotent + side-effect-free. */
183
+ function reduce(obj) {
184
+ if (obj == null || typeof obj !== 'object') return obj;
185
+ if (Array.isArray(obj)) return obj.map(reduce);
186
+ var out = {};
187
+ for (var k in obj) {
188
+ if (!Object.prototype.hasOwnProperty.call(obj, k)) continue;
189
+ if (k === 'label_i18n' && obj[k] && typeof obj[k] === 'object') {
190
+ var filtered = {};
191
+ locales.forEach(function (loc) {
192
+ if (obj[k][loc]) filtered[loc] = obj[k][loc];
193
+ });
194
+ out[k] = filtered;
195
+ } else {
196
+ out[k] = reduce(obj[k]);
197
+ }
198
+ }
199
+ return out;
200
+ }
201
+ return reduce(manifest);
202
+ }
203
+
204
+ /* ---------- import_remote_tree ---------- */
205
+
206
+ function import_remote_tree(payload, conn) {
207
+ _requireDocument('import_remote_tree');
208
+ if (!payload || typeof payload !== 'object') {
209
+ throw _err('invalid', 'import_remote_tree: payload required');
210
+ }
211
+ if (!conn || !conn.endpoint || !conn.bearer) {
212
+ throw _err('invalid', 'import_remote_tree: conn.endpoint + conn.bearer required');
213
+ }
214
+ var transport = conn.transport || 'http';
215
+ var namespace = conn.namespace || payload.app_id;
216
+ if (!namespace) throw _err('invalid', 'import_remote_tree: namespace required (no app_id in payload)');
217
+ if (_remotes[namespace]) {
218
+ throw _err('conflict', 'import_remote_tree: namespace "' + namespace + '" already imported; disconnect first');
219
+ }
220
+
221
+ /* Register each remote plugin under namespaced slug. */
222
+ var importedPlugins = [];
223
+ for (var slug in payload.manifests) {
224
+ if (!Object.prototype.hasOwnProperty.call(payload.manifests, slug)) continue;
225
+ var m = payload.manifests[slug];
226
+ var nsSlug = REMOTE_PREFIX + namespace + ':' + slug;
227
+ /* Build a namespaced copy of the manifest. */
228
+ var nsManifest = JSON.parse(JSON.stringify(m));
229
+ nsManifest.plugin_slug = nsSlug;
230
+ nsManifest.__interop_origin = { namespace: namespace, peer_plugin: slug };
231
+ /* Prefix every id in elements / tabs / fields / actions. */
232
+ ['elements', 'tabs', 'fields', 'actions'].forEach(function (key) {
233
+ if (Array.isArray(nsManifest[key])) {
234
+ nsManifest[key].forEach(function (el) {
235
+ if (el && el.id) el.__peer_id = el.id;
236
+ if (el && el.id) el.id = REMOTE_PREFIX + namespace + ':' + el.id;
237
+ if (el && el.nac_id) el.__peer_nac_id = el.nac_id;
238
+ if (el && el.nac_id) el.nac_id = REMOTE_PREFIX + namespace + ':' + el.nac_id;
239
+ });
240
+ }
241
+ });
242
+ try {
243
+ global.NAC.register(nsManifest);
244
+ importedPlugins.push(nsSlug);
245
+ } catch (e) {
246
+ console.error('[nac-interop] failed to register namespaced plugin', nsSlug, e);
247
+ }
248
+ }
249
+
250
+ /* Build the handle. */
251
+ var handle = {
252
+ namespace: namespace,
253
+ app_id: payload.app_id,
254
+ app_version: payload.app_version,
255
+ nac_version: payload.nac_version,
256
+ imported_at: _now(),
257
+ transport: transport,
258
+ endpoint: conn.endpoint,
259
+ bearer: conn.bearer,
260
+ hmac_secret: conn.hmac_secret || null,
261
+ imported_plugins: importedPlugins,
262
+ sse: null,
263
+ _stats: { invocations: 0, successes: 0, failures: 0 }
264
+ };
265
+ _remotes[namespace] = handle;
266
+
267
+ /* Auto-subscribe to ack events. */
268
+ if (conn.auto_subscribe !== false && payload.ack_endpoint && transport === 'http') {
269
+ _subscribeRemote(handle, payload.ack_endpoint);
270
+ }
271
+
272
+ document.dispatchEvent(new CustomEvent('nac:interop:imported', {
273
+ detail: { namespace: namespace, app_id: payload.app_id, plugins: importedPlugins }
274
+ }));
275
+
276
+ return handle;
277
+ }
278
+
279
+ function _subscribeRemote(handle, ackEndpoint) {
280
+ if (typeof EventSource === 'undefined') {
281
+ console.warn('[nac-interop] EventSource not available; ack subscription skipped');
282
+ return;
283
+ }
284
+ /* Bearer can't go in headers for EventSource; use ?bearer query
285
+ string per the spec. */
286
+ var url = ackEndpoint
287
+ + (ackEndpoint.indexOf('?') < 0 ? '?' : '&')
288
+ + 'bearer=' + encodeURIComponent(handle.bearer);
289
+ var es = new EventSource(url);
290
+ es.addEventListener('nac:action:succeeded', function (ev) {
291
+ _relayPeerEvent(handle, 'nac:action:succeeded', ev.data);
292
+ });
293
+ es.addEventListener('nac:action:failed', function (ev) {
294
+ _relayPeerEvent(handle, 'nac:action:failed', ev.data);
295
+ });
296
+ es.addEventListener('nac:tab:activated', function (ev) {
297
+ _relayPeerEvent(handle, 'nac:tab:activated', ev.data);
298
+ });
299
+ es.addEventListener('nac:field:changed', function (ev) {
300
+ _relayPeerEvent(handle, 'nac:field:changed', ev.data);
301
+ });
302
+ es.onerror = function (e) {
303
+ console.warn('[nac-interop] SSE error on', handle.namespace, e);
304
+ };
305
+ handle.sse = es;
306
+ }
307
+
308
+ function _relayPeerEvent(handle, eventName, dataStr) {
309
+ var detail;
310
+ try { detail = JSON.parse(dataStr); } catch (_) { detail = { raw: dataStr }; }
311
+ /* Namespace the action_id / field_id / tab_id so local
312
+ listeners see the remote: prefix. */
313
+ ['action_id', 'field_id', 'tab_id', 'option_id', 'plugin'].forEach(function (k) {
314
+ if (detail[k] && typeof detail[k] === 'string'
315
+ && detail[k].indexOf(REMOTE_PREFIX) !== 0) {
316
+ detail[k] = REMOTE_PREFIX + handle.namespace + ':' + detail[k];
317
+ }
318
+ });
319
+ detail.via_interop = true;
320
+ detail.is_trusted = false;
321
+ document.dispatchEvent(new CustomEvent(eventName, { detail: detail }));
322
+ }
323
+
324
+ function list_remote_apps() {
325
+ return Object.keys(_remotes).map(function (ns) {
326
+ var h = _remotes[ns];
327
+ return {
328
+ namespace: h.namespace,
329
+ app_id: h.app_id,
330
+ nac_version: h.nac_version,
331
+ imported_at: h.imported_at,
332
+ imported_plugins: h.imported_plugins.slice(),
333
+ stats: Object.assign({}, h._stats)
334
+ };
335
+ });
336
+ }
337
+
338
+ function disconnect_remote(namespace) {
339
+ _requireDocument('disconnect_remote');
340
+ var handle = _remotes[namespace];
341
+ if (!handle) return;
342
+ /* Unregister each namespaced plugin. */
343
+ handle.imported_plugins.forEach(function (slug) {
344
+ if (typeof global.NAC.unregister === 'function') {
345
+ try { global.NAC.unregister(slug); } catch (_) {}
346
+ }
347
+ });
348
+ /* Close SSE. */
349
+ if (handle.sse) { try { handle.sse.close(); } catch (_) {} }
350
+ delete _remotes[namespace];
351
+ document.dispatchEvent(new CustomEvent('nac:interop:disconnected', {
352
+ detail: { namespace: namespace, app_id: handle.app_id }
353
+ }));
354
+ }
355
+
356
+ /* ---------- HMAC helpers (SubtleCrypto-based) ---------- */
357
+
358
+ async function _hmacSign(secret, body) {
359
+ if (!secret || typeof secret !== 'string') return null;
360
+ if (!global.crypto || !global.crypto.subtle) return null;
361
+ var enc = new TextEncoder();
362
+ var key = await global.crypto.subtle.importKey(
363
+ 'raw',
364
+ enc.encode(secret),
365
+ { name: 'HMAC', hash: 'SHA-256' },
366
+ false,
367
+ ['sign']
368
+ );
369
+ var sig = await global.crypto.subtle.sign('HMAC', key, enc.encode(body));
370
+ var arr = new Uint8Array(sig);
371
+ var hex = '';
372
+ for (var i = 0; i < arr.length; i++) {
373
+ hex += arr[i].toString(16).padStart(2, '0');
374
+ }
375
+ return hex;
376
+ }
377
+
378
+ /* ---------- Proxy invoke ---------- */
379
+
380
+ async function _proxyInvoke(handle, peer_id, action_kind, args) {
381
+ handle._stats.invocations++;
382
+ var body = {
383
+ bearer: handle.bearer,
384
+ nac_id: peer_id,
385
+ action: { kind: action_kind, args: args || {} }
386
+ };
387
+ /* Optional HMAC on sensitive actions; the host can mark verbs
388
+ sensitive via window.__NAC_INTEROP_SENSITIVE_VERBS__. */
389
+ if (handle.hmac_secret) {
390
+ var canonical = JSON.stringify({
391
+ nac_id: body.nac_id, kind: body.action.kind, args: body.action.args
392
+ });
393
+ try { body.hmac = await _hmacSign(handle.hmac_secret, canonical); } catch (_) {}
394
+ }
395
+ var resp;
396
+ try {
397
+ resp = await fetch(handle.endpoint + '/nac.invoke', {
398
+ method: 'POST',
399
+ headers: { 'Content-Type': 'application/json' },
400
+ body: JSON.stringify(body)
401
+ });
402
+ } catch (e) {
403
+ handle._stats.failures++;
404
+ throw _err('network', 'nac.invoke network error: ' + e.message);
405
+ }
406
+ if (!resp.ok) {
407
+ handle._stats.failures++;
408
+ throw _err('http_' + resp.status, 'nac.invoke HTTP ' + resp.status);
409
+ }
410
+ var json;
411
+ try { json = await resp.json(); }
412
+ catch (e) {
413
+ handle._stats.failures++;
414
+ throw _err('parse', 'nac.invoke returned non-JSON');
415
+ }
416
+ if (json.ok === false) {
417
+ handle._stats.failures++;
418
+ throw _err((json.error && json.error.code) || 'peer_error',
419
+ (json.error && json.error.message) || 'peer rejected the invocation');
420
+ }
421
+ handle._stats.successes++;
422
+ return json.result || { ok: true };
423
+ }
424
+
425
+ /* ---------- Patch NAC public API to route remote: prefix ---------- */
426
+
427
+ function _wrap(fnName, kindForProxy, argMapper) {
428
+ var orig = global.NAC[fnName];
429
+ if (typeof orig !== 'function') return;
430
+ global.NAC[fnName] = async function () {
431
+ var args = Array.prototype.slice.call(arguments);
432
+ var firstArg = args[0];
433
+ var parsed = _parseRemote(firstArg);
434
+ if (!parsed) return orig.apply(global.NAC, args);
435
+ var handle = _remotes[parsed.namespace];
436
+ if (!handle) {
437
+ throw _err('not_found',
438
+ fnName + ': namespace "' + parsed.namespace + '" not imported (call NAC.import_remote_tree first)');
439
+ }
440
+ var peerArgs = (typeof argMapper === 'function') ? argMapper(args, parsed) : {};
441
+ try {
442
+ var result = await _proxyInvoke(handle, parsed.peer_id, kindForProxy, peerArgs);
443
+ _emitLocalAck(REMOTE_PREFIX + parsed.namespace + ':' + (peerArgs.plugin || parsed.peer_id.split('.')[0]),
444
+ firstArg, true, { result: result });
445
+ return result;
446
+ } catch (e) {
447
+ _emitLocalAck(REMOTE_PREFIX + parsed.namespace,
448
+ firstArg, false, { error: { code: e.code, message: e.message } });
449
+ throw e;
450
+ }
451
+ };
452
+ return orig;
453
+ }
454
+
455
+ _origClick = _wrap('click', 'click', function (args) { return { opts: args[1] || {} }; });
456
+ _origFill = _wrap('fill', 'fill', function (args) { return { value: args[1] }; });
457
+ _origSelect = _wrap('select', 'select', function (args) { return { value: args[1] }; });
458
+ _origGoToSection = _wrap('go_to_section', 'go_to_section', function () { return {}; });
459
+ _origEditField = _wrap('edit_field', 'edit_field', function () { return {}; });
460
+
461
+ /* tab(plugin, tab_key): if plugin starts with remote: prefix, parse and proxy. */
462
+ _origTab = global.NAC.tab;
463
+ if (typeof _origTab === 'function') {
464
+ global.NAC.tab = async function (plugin, tab_key) {
465
+ var parsedPlugin = _parseRemote(plugin);
466
+ if (!parsedPlugin) return _origTab.call(global.NAC, plugin, tab_key);
467
+ var handle = _remotes[parsedPlugin.namespace];
468
+ if (!handle) throw _err('not_found', 'tab: namespace "' + parsedPlugin.namespace + '" not imported');
469
+ /* tab_key may also have the prefix; strip it if so. */
470
+ var peerTabKey = tab_key;
471
+ var parsedTab = _parseRemote(tab_key);
472
+ if (parsedTab && parsedTab.namespace === parsedPlugin.namespace) {
473
+ peerTabKey = parsedTab.peer_id;
474
+ }
475
+ var result = await _proxyInvoke(handle, parsedPlugin.peer_id,
476
+ 'tab', { tab_key: peerTabKey });
477
+ _emitLocalAck(plugin, REMOTE_PREFIX + parsedPlugin.namespace + ':' + peerTabKey,
478
+ true, { result: result });
479
+ return result;
480
+ };
481
+ }
482
+
483
+ /* tab_by_label and click_by_verb also accept a plugin arg. */
484
+ _origTabByLabel = global.NAC.tab_by_label;
485
+ if (typeof _origTabByLabel === 'function') {
486
+ global.NAC.tab_by_label = async function (plugin, label, opts) {
487
+ var parsedPlugin = _parseRemote(plugin);
488
+ if (!parsedPlugin) return _origTabByLabel.call(global.NAC, plugin, label, opts);
489
+ var handle = _remotes[parsedPlugin.namespace];
490
+ if (!handle) throw _err('not_found', 'tab_by_label: namespace not imported');
491
+ return _proxyInvoke(handle, parsedPlugin.peer_id, 'tab_by_label', { label: label });
492
+ };
493
+ }
494
+
495
+ var _origClickByVerb = global.NAC.click_by_verb;
496
+ if (typeof _origClickByVerb === 'function') {
497
+ global.NAC.click_by_verb = async function (plugin, verb, opts) {
498
+ var parsedPlugin = _parseRemote(plugin);
499
+ if (!parsedPlugin) return _origClickByVerb.call(global.NAC, plugin, verb, opts);
500
+ var handle = _remotes[parsedPlugin.namespace];
501
+ if (!handle) throw _err('not_found', 'click_by_verb: namespace not imported');
502
+ return _proxyInvoke(handle, parsedPlugin.peer_id, 'click_by_verb', { verb: verb });
503
+ };
504
+ }
505
+
506
+ /* dt_* family: each takes table_id as first arg. */
507
+ ['dt_add_row', 'dt_remove_row', 'dt_edit_cell',
508
+ 'dt_commit', 'dt_discard', 'dt_read_aggregate'].forEach(function (fnName) {
509
+ var orig = global.NAC[fnName];
510
+ if (typeof orig !== 'function') return;
511
+ global.NAC[fnName] = function () {
512
+ var args = Array.prototype.slice.call(arguments);
513
+ var tableId = args[0];
514
+ var parsed = _parseRemote(tableId);
515
+ if (!parsed) return orig.apply(global.NAC, args);
516
+ var handle = _remotes[parsed.namespace];
517
+ if (!handle) throw _err('not_found', fnName + ': namespace not imported');
518
+ var argsPayload = {};
519
+ switch (fnName) {
520
+ case 'dt_add_row': argsPayload = { values: args[1] || {} }; break;
521
+ case 'dt_remove_row': argsPayload = { row_id: args[1] }; break;
522
+ case 'dt_edit_cell': argsPayload = { row_id: args[1], column: args[2], value: args[3] }; break;
523
+ case 'dt_commit': argsPayload = {}; break;
524
+ case 'dt_discard': argsPayload = {}; break;
525
+ case 'dt_read_aggregate':argsPayload = { agg_key: args[1], column: args[2] }; break;
526
+ }
527
+ return _proxyInvoke(handle, parsed.peer_id, fnName, argsPayload);
528
+ };
529
+ });
530
+
531
+ /* ---------- Expose on NAC ---------- */
532
+
533
+ global.NAC.export_tree = export_tree;
534
+ global.NAC.import_remote_tree = import_remote_tree;
535
+ global.NAC.list_remote_apps = list_remote_apps;
536
+ global.NAC.disconnect_remote = disconnect_remote;
537
+
538
+ /* Behind a switch since 2026-11-24. This was the only
539
+ unconditional console.log left in published code: an install
540
+ banner every page that loads this file printed, whether or not
541
+ anyone was debugging. It prints no user content -- unlike the
542
+ three in nac-chat-client.js -- so the cost was noise rather than
543
+ disclosure, but a library that writes to the host console
544
+ uninvited is still the host's decision to make, not ours.
545
+ window.NAC_INTEROP_DEBUG = true brings it back. The warn and
546
+ error calls in this file are untouched. */
547
+ if (global.NAC_INTEROP_DEBUG === true && global.console
548
+ && typeof global.console.log === 'function') {
549
+ global.console.log('[nac-interop] installed (v2.3 preview) on top of NAC ' + global.NAC.version);
550
+ }
551
+
552
+ /* The same guard its three siblings carry. Until 2.9.0 this file ended
553
+ with (window), so the ESM and CJS bundles of the package could not
554
+ even be LOADED outside a browser -- which is one reason it was never
555
+ published. */
556
+ })(typeof window !== 'undefined' ? window : globalThis);
557
+
558
+ export default _g.NAC || _g.NACv2 || _g.NacChat || _g[Object.keys(_g).find(k => /^NA[Cc]/.test(k))];
559
+ export const NAC = _g.NAC;
560
+ export const NACv2 = _g.NACv2;
561
+ export const NacChat = _g.NacChat;
@@ -1,5 +1,5 @@
1
1
  // Generated by build.mjs -- do not edit. Source: js/nac-v2-extensions.js
2
- // Brownfield + data-table extensions for @nac3/runtime v2.8.0.
2
+ // Brownfield + data-table extensions for @nac3/runtime v2.9.0.
3
3
  // This module MUST load AFTER the core runtime; it attaches every
4
4
  // member below onto the same window.NAC object. Import as:
5
5
  // import '@nac3/runtime';
@@ -6,7 +6,7 @@
6
6
  =====================================================================
7
7
 
8
8
  AUTHORITATIVE VERSION CONSTANT: see the global.NAC export at the
9
- bottom of this file. `version: '2.8.0', spec_version: '2.8'`
9
+ bottom of this file. `version: '2.9.0', spec_version: '2.9'`
10
10
  is the normative declaration. The dated changelog sections below are
11
11
  historical notes; if they ever drift from the export, the export
12
12
  wins.
@@ -1790,7 +1790,33 @@
1790
1790
  /* Structure. Every one of these is consumed by something: three
1791
1791
  are queried by this runtime, `list` hosts reorder(), and
1792
1792
  `canvas` is the door section 15.12 assigned to that surface. */
1793
- 'list', 'row', 'menu', 'label', 'value', 'paragraph', 'canvas'
1793
+ 'list', 'row', 'menu', 'label', 'value', 'paragraph', 'canvas',
1794
+
1795
+ /* ---- v2.9.0: the document vocabulary (SPEC.md 1.2) ----------
1796
+ THE DEFECT THIS CLOSES, and it was this project's own site.
1797
+ Measured 2026-11-27 with the PUBLISHED validator over the
1798
+ whole tree: 45 677 elements across 526 pages carried a role
1799
+ the specification did not declare, and they were not written
1800
+ by hand -- a single producer emits them,
1801
+ scripts/build-spec-html.mjs, which renders the normative text
1802
+ itself as a NAC3 page. So the document that declares the
1803
+ vocabulary was being served marked up in words it did not
1804
+ declare, 354 times per page.
1805
+
1806
+ Why declaring them is the right half of the fix rather than
1807
+ un-painting them: these are document structure, and under
1808
+ section 19 reading a document is a capability, not a side
1809
+ effect of having a screen. An agent with no screen navigates
1810
+ prose by heading; code says the text inside must be read
1811
+ verbatim rather than paraphrased. list and paragraph were
1812
+ already declared, so list-item and heading missing was half a
1813
+ family, which is why the count was in the tens of thousands.
1814
+
1815
+ All five are read-only: they go in _CLICK_NO_EVENT_ROLES
1816
+ below, never in the click family map, because putting a
1817
+ read-only role in that map would make click() promise a
1818
+ completion nobody emits. */
1819
+ 'heading', 'list-item', 'code', 'code-inline', 'note'
1794
1820
  ]);
1795
1821
 
1796
1822
  /* ---- Declared aliases (SPEC.md 1.5) ---------------------------
@@ -3494,7 +3520,7 @@
3494
3520
  }
3495
3521
  }
3496
3522
  return {
3497
- spec_version: '2.8',
3523
+ spec_version: '2.9',
3498
3524
  canonical: Array.from(_KNOWN_ROLES_V22),
3499
3525
  aliases: Object.assign({}, _ROLE_ALIASES),
3500
3526
  registered: registered,
@@ -3794,6 +3820,8 @@
3794
3820
  'breadcrumb', 'pagination-control',
3795
3821
  'avatar', 'presence-indicator', 'skeleton', 'empty-state',
3796
3822
  'list', 'row', 'menu', 'label', 'value', 'paragraph', 'canvas',
3823
+ /* v2.9.0: the five document roles. Read-only, every one. */
3824
+ 'heading', 'list-item', 'code', 'code-inline', 'note',
3797
3825
  ]);
3798
3826
 
3799
3827
  /* v1.6.4: field types whose click() act on a value (toggle).
@@ -10214,8 +10242,8 @@
10214
10242
 
10215
10243
  global.NAC = {
10216
10244
  __nac_v1_installed: true,
10217
- version: '2.8.0',
10218
- spec_version: '2.8',
10245
+ version: '2.9.0',
10246
+ spec_version: '2.9',
10219
10247
  /* v2.2.0 (V22-01) -- strict validation toggle. When true,
10220
10248
  NAC.register throws on findings (manifest_role_unknown,
10221
10249
  tab_id_manifest_role_drift, manifest_dom_role_mismatch).