@nac3/runtime 2.3.1 → 2.5.0-alpha.1
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/CHANGELOG.md +452 -68
- package/LICENSE +201 -201
- package/README.md +9 -9
- package/SPEC.md +788 -83
- package/dist/cli.js +3 -3
- package/dist/nac-chat-client.browser.js +705 -705
- package/dist/nac-chat-client.cjs +705 -705
- package/dist/nac-chat-client.mjs +705 -705
- package/dist/nac-v2-extensions.browser.js +2102 -2291
- package/dist/nac-v2-extensions.cjs +2102 -2291
- package/dist/nac-v2-extensions.mjs +2102 -2291
- package/dist/nac.browser.js +7137 -6125
- package/dist/nac.cjs +7137 -6125
- package/dist/nac.mjs +7137 -6125
- package/package.json +92 -81
package/SPEC.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# NAC3 -- Native Agent Contract
|
|
2
2
|
|
|
3
|
-
**Version:** 2.
|
|
4
|
-
**Status:**
|
|
5
|
-
**Benchmark:** 600 runs across 5 models x 3 protocols -- [results](./benchmark/)
|
|
3
|
+
**Version:** 2.5.0-alpha.1 (consolidation alpha: Block A canvas+API + V24-01/02/05 RFCs alongside v2.4 strict resolution)
|
|
4
|
+
**Status:** v2.5.0-alpha.1 alpha -- consolidates parallel dev lines, V24-04 OCC still in implementation for alpha.2
|
|
6
5
|
**License:** Apache-2.0
|
|
7
6
|
**Editor:** Yujin (yujin.app)
|
|
8
|
-
**RFCs in flight:** see [/rfcs/](./rfcs/) for V24-04 (snapshot versioning, enforcement opt-in in 2.3.0) and V24-05 (authority, draft for 2.4).
|
|
9
7
|
|
|
10
8
|
---
|
|
11
9
|
|
|
@@ -71,10 +69,9 @@ Every agent-resolvable element carries `data-nac-id`. The id is:
|
|
|
71
69
|
- **A dotted path** (e.g. `deals.list.row.42.actions.delete`).
|
|
72
70
|
Dots separate semantic levels; the runtime does not interpret
|
|
73
71
|
them, but humans and LLMs do.
|
|
74
|
-
- **Globally unique within a `
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
See sec 7.4 for the plugin slug uniqueness contract.
|
|
72
|
+
- **Globally unique within a `data-nac-plugin` scope.** Two
|
|
73
|
+
different plugins MAY share an id; the runtime resolves by
|
|
74
|
+
`(plugin, id)` pair.
|
|
78
75
|
- **Stable across re-renders.** Frameworks that produce a new id
|
|
79
76
|
per render (random hashes, instance counters) break the contract.
|
|
80
77
|
- **Stable across UI redesigns.** A button moves from the toolbar
|
|
@@ -225,9 +222,8 @@ NAC-3 callable verbs:
|
|
|
225
222
|
Esc closes (cancel). Ctrl/Cmd+Enter saves. Click on overlay
|
|
226
223
|
backdrop cancels.
|
|
227
224
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
under the V23_EDITOR_fix_monitor task.
|
|
225
|
+
Spec sec 13 will formalise the contract in v2.3; the v2.2 runtime
|
|
226
|
+
ships a working reference impl so adopters can wire it today.
|
|
231
227
|
Available on any field via:
|
|
232
228
|
|
|
233
229
|
```js
|
|
@@ -236,11 +232,444 @@ NAC.edit_field('invoice.client_name');
|
|
|
236
232
|
NAC.click_by_verb('myplugin', 'edit_field', { nac_id: 'invoice.client_name' });
|
|
237
233
|
```
|
|
238
234
|
|
|
239
|
-
### 5.1.
|
|
235
|
+
### 5.1.4 Action payload + invoke (v2.3)
|
|
240
236
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
237
|
+
NAC v2.2 actions are click-and-go: an agent triggers `NAC.click(id)`
|
|
238
|
+
or `NAC.click_by_verb(plugin, verb)` and the host runs whatever it
|
|
239
|
+
does. This works for verb-and-state actions (`save`, `cancel`,
|
|
240
|
+
`submit`, `delete`) but collapses when an action needs **data**
|
|
241
|
+
from the agent -- `utter(text)`, `search(query)`,
|
|
242
|
+
`send_message(body)`, `upload(file)`, `schedule(date)`,
|
|
243
|
+
`translate(text, target_lang)`. The host has no way to receive
|
|
244
|
+
the agent's payload via a synthetic click.
|
|
245
|
+
|
|
246
|
+
v2.3 closes this gap. The contract is additive: click-style
|
|
247
|
+
verbs continue to work unchanged.
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
NAC.invoke(action_id: string, payload: object, opts?: { timeout?: number })
|
|
251
|
+
: Promise<{ok: true, request_id: string, ack: object|null}>
|
|
252
|
+
|
|
253
|
+
NAC.utter(action_id: string,
|
|
254
|
+
opts: { text: string, lang?: string, voice?: string, metadata?: object })
|
|
255
|
+
: Promise<{ok: true, request_id: string, ack: object|null}>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
`NAC.invoke` dispatches a `nac:action:requested` `CustomEvent`
|
|
259
|
+
on the host element (bubbles to document) with:
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
detail: {
|
|
263
|
+
action_id: string, // canonical nac_id of the host element
|
|
264
|
+
verb: string, // payload.verb || el's data-nac-action
|
|
265
|
+
payload: object, // arbitrary, action-specific
|
|
266
|
+
plugin: string|null,
|
|
267
|
+
request_id: string, // correlation token assigned by the runtime
|
|
268
|
+
ts: number, // Date.now()
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The host listens for `nac:action:requested`, processes the
|
|
273
|
+
payload, and emits `nac:action:succeeded` (or `nac:action:failed`)
|
|
274
|
+
with the same `request_id` in the detail. The runtime correlates
|
|
275
|
+
by `request_id` and resolves the agent's Promise.
|
|
276
|
+
|
|
277
|
+
Default timeout is **30 seconds** (vs 5 s for click). Override
|
|
278
|
+
with `opts.timeout`. On timeout, the Promise rejects with
|
|
279
|
+
`NacError('timeout', ...)`. As with click, a timeout means real
|
|
280
|
+
failure: callers MUST treat it as such unless they have side-
|
|
281
|
+
effect proof via another channel.
|
|
282
|
+
|
|
283
|
+
`NAC.utter(id, opts)` is the ergonomic shortcut for the most
|
|
284
|
+
common payload-bearing verb. It is equivalent to:
|
|
285
|
+
|
|
286
|
+
```js
|
|
287
|
+
NAC.invoke(id, { verb: 'utter', text: opts.text, lang: opts.lang });
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
#### Manifest declaration
|
|
291
|
+
|
|
292
|
+
A payload-bearing action declares its payload schema in the
|
|
293
|
+
manifest entry for traceability and tooling:
|
|
294
|
+
|
|
295
|
+
```js
|
|
296
|
+
NAC.register({
|
|
297
|
+
plugin_slug: 'atlas_pro_ad',
|
|
298
|
+
version: '2.1.0',
|
|
299
|
+
nac_version: '2.3',
|
|
300
|
+
elements: [
|
|
301
|
+
{ id: 'atlas_pro_ad.mic', role: 'action',
|
|
302
|
+
actions: [
|
|
303
|
+
{ verb: 'listen' },
|
|
304
|
+
{ verb: 'utter',
|
|
305
|
+
payload_schema: {
|
|
306
|
+
text: { type: 'string', required: true, max: 4000 },
|
|
307
|
+
lang: { type: 'string',
|
|
308
|
+
enum: ['en','es','pt','fr','it','de','ja','zh','hi','ar'] }
|
|
309
|
+
},
|
|
310
|
+
label_i18n: { es:'Decir', en:'Utter', /* ... 10 locales */ } }
|
|
311
|
+
],
|
|
312
|
+
label_i18n: { /* ... */ } }
|
|
313
|
+
]
|
|
314
|
+
});
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
`payload_schema` is informational in v2.3 stable. Agents MAY
|
|
318
|
+
validate before sending; runtimes MAY enforce it when
|
|
319
|
+
`STRICT_VALIDATION` is `true`. Schemas are intentionally simple
|
|
320
|
+
(JSON-Schema-shaped subset) so a runtime can validate without
|
|
321
|
+
shipping a full JSON-Schema validator. v2.4 will formalise the
|
|
322
|
+
schema grammar and turn enforcement into a default.
|
|
323
|
+
|
|
324
|
+
#### Disabled-state semantics (v2.3 hotfix from alpha.2)
|
|
325
|
+
|
|
326
|
+
`NAC.invoke` does NOT reject when the target element has
|
|
327
|
+
`disabled` or `aria-disabled='true'` set. The `disabled` HTML
|
|
328
|
+
attribute is a UX click guard; `invoke` is a logical
|
|
329
|
+
payload-bearing request, not a synthetic click. Hosts that need
|
|
330
|
+
to refuse an invoke based on UI state MUST do it in their
|
|
331
|
+
`nac:action:requested` listener and emit `nac:action:failed`
|
|
332
|
+
with a meaningful error code.
|
|
333
|
+
|
|
334
|
+
`NAC.click`, by contrast, STILL rejects on disabled elements
|
|
335
|
+
(click semantics preserved). Test coverage:
|
|
336
|
+
`packages/nac/test/v23-invoke.mjs` T7/T8/T9.
|
|
337
|
+
|
|
338
|
+
#### Conformance: hosts that support invoke MUST
|
|
339
|
+
|
|
340
|
+
1. Declare `actions[].payload_schema` in the manifest entry.
|
|
341
|
+
2. Listen for `nac:action:requested` (or use a generic listener
|
|
342
|
+
that filters by `detail.action_id` + `detail.verb`).
|
|
343
|
+
3. Emit `nac:action:succeeded` -- with `detail.request_id`
|
|
344
|
+
echoed back -- after processing, or `nac:action:failed`
|
|
345
|
+
(with `detail.error` code) on failure.
|
|
346
|
+
4. NEVER emit a `:succeeded` event with a `request_id` they did
|
|
347
|
+
not receive (prevents cross-talk between concurrent invocations).
|
|
348
|
+
|
|
349
|
+
Hosts that do NOT support invoke continue to operate normally
|
|
350
|
+
under `NAC.click()` and `NAC.click_by_verb()`. Agents that call
|
|
351
|
+
`NAC.invoke()` against a host without an `actions[].payload_schema`
|
|
352
|
+
entry will still receive a `request_id` but the runtime cannot
|
|
353
|
+
guarantee delivery; the timeout fires after 30 s.
|
|
354
|
+
|
|
355
|
+
#### Why this matters
|
|
356
|
+
|
|
357
|
+
The full agentic surface stops being "list of buttons" and
|
|
358
|
+
becomes "list of buttons + structured inputs". A voice ad becomes
|
|
359
|
+
NAC.invoke-able. A search bar becomes NAC.invoke-able. A
|
|
360
|
+
file upload becomes NAC.invoke-able. Same protocol, same
|
|
361
|
+
provenance, same ack semantics.
|
|
362
|
+
|
|
363
|
+
The first reference adopter is **Atlas Pro** -- its
|
|
364
|
+
`atlas_pro_ad.mic` element declares both `listen` (click-only,
|
|
365
|
+
existing) and `utter` (payload-bearing) verbs. The same
|
|
366
|
+
`/parse` + `/tts` conversational loop drives in either case;
|
|
367
|
+
agents that have STT call `listen`, agents that have their own
|
|
368
|
+
language model call `utter`.
|
|
369
|
+
|
|
370
|
+
#### Forward modalities (anticipated, no spec change required)
|
|
371
|
+
|
|
372
|
+
`invoke` is intentionally modality-agnostic so future input
|
|
373
|
+
families plug in without breaking the contract:
|
|
374
|
+
|
|
375
|
+
| Modality | Verb (sketch) | Payload (sketch) |
|
|
376
|
+
|----------|-----------------------|--------------------------------------------------|
|
|
377
|
+
| Text | `utter` | `{text, lang?}` |
|
|
378
|
+
| Search | `search` | `{query, scope?, limit?}` |
|
|
379
|
+
| File | `upload` | `{filename, mime, data_url \| stream_id}` |
|
|
380
|
+
| Image | `analyze_image` | `{image_url \| data_url, prompt?}` |
|
|
381
|
+
| Video | `analyze_stream` | `{stream_url, frame_window_ms?, return?}` |
|
|
382
|
+
| Schedule | `schedule` | `{datetime, duration_min, attendees?}` |
|
|
383
|
+
| Code | `apply_diff` | `{file_path, unified_diff}` |
|
|
384
|
+
| Voice | `transcribe` | `{audio_url \| data_url, lang?}` |
|
|
385
|
+
|
|
386
|
+
Each modality follows the same `nac:action:requested` ->
|
|
387
|
+
`nac:action:succeeded` / `:failed` event protocol, the same
|
|
388
|
+
`request_id` correlation, the same timeout semantics. The
|
|
389
|
+
runtime stays small; the verb vocabulary grows by convention
|
|
390
|
+
between hosts and agents. Ergonomic shortcuts (`NAC.utter`,
|
|
391
|
+
`NAC.search`, `NAC.watch`, etc.) can be added later without
|
|
392
|
+
re-spec because each is a thin wrapper over `invoke`.
|
|
393
|
+
|
|
394
|
+
### 5.1.5 Shadow DOM resolution -- open roots (v2.3)
|
|
395
|
+
|
|
396
|
+
The runtime resolves `data-nac-id` references through open
|
|
397
|
+
shadow roots recursively. A page can mount Web Components
|
|
398
|
+
using `attachShadow({mode:'open'})`, place
|
|
399
|
+
`data-nac-*` attributes on elements inside the shadow tree,
|
|
400
|
+
and any NAC3 caller (`NAC.click`, `NAC.fill`, `NAC.invoke`,
|
|
401
|
+
etc.) resolves the target transparently.
|
|
402
|
+
|
|
403
|
+
#### Resolution algorithm
|
|
404
|
+
|
|
405
|
+
For a selector `S` (typically `[data-nac-id="..."]`) against a
|
|
406
|
+
root `R` (typically `document`):
|
|
407
|
+
|
|
408
|
+
1. `R.querySelector(S)` -> if non-null, return immediately.
|
|
409
|
+
2. For every descendant `el` of `R`:
|
|
410
|
+
- If `el.shadowRoot` is non-null (i.e. open shadow root):
|
|
411
|
+
recurse with `R := el.shadowRoot`, depth +1.
|
|
412
|
+
- Else if `el.nac3` is an object exposing a `query` method,
|
|
413
|
+
delegate (see sec 5.1.6).
|
|
414
|
+
3. The recursion is **depth-capped at 10 levels**. Targets
|
|
415
|
+
deeper than 10 are unreachable; the caller receives
|
|
416
|
+
`code='not_found'`. The cap exists to prevent pathological
|
|
417
|
+
walks; in practice no production codebase nests more than
|
|
418
|
+
3-4 shadow levels.
|
|
419
|
+
4. The walk is breadth-of-DOM-order: siblings before nested
|
|
420
|
+
shadows. First match wins.
|
|
421
|
+
|
|
422
|
+
#### Event propagation
|
|
423
|
+
|
|
424
|
+
Events emitted by hosts inside shadow roots MUST set
|
|
425
|
+
`composed: true` for document-level listeners to receive them.
|
|
426
|
+
The NAC3 runtime emits all its own events with `composed:true`
|
|
427
|
+
already; host code that emits manual `nac:*` events is
|
|
428
|
+
responsible for the same. Without `composed:true` the event
|
|
429
|
+
stops at the shadow boundary and the runtime's correlation
|
|
430
|
+
machinery never sees it.
|
|
431
|
+
|
|
432
|
+
#### Author responsibility
|
|
433
|
+
|
|
434
|
+
The component author needs to:
|
|
435
|
+
|
|
436
|
+
1. Place `data-nac-id`, `data-nac-role`, `data-nac-action` on
|
|
437
|
+
operable elements inside the shadow root.
|
|
438
|
+
2. Set `composed:true` on any custom event the host emits to
|
|
439
|
+
signal a NAC3 contract (`nac:action:succeeded`,
|
|
440
|
+
`nac:field:changed`, etc.).
|
|
441
|
+
3. Avoid `<slot>` for elements that need to be
|
|
442
|
+
shadow-isolated -- slotted nodes live in light DOM and are
|
|
443
|
+
resolved there instead.
|
|
444
|
+
|
|
445
|
+
No manifest hint or runtime opt-in is required for open shadow
|
|
446
|
+
roots; the resolution is automatic.
|
|
447
|
+
|
|
448
|
+
#### Reference implementation
|
|
449
|
+
|
|
450
|
+
The reference runtime exposes two internal helpers,
|
|
451
|
+
`_deepQuery(selector, root)` and
|
|
452
|
+
`_deepQueryAll(selector, root)`, that perform the walk. Public
|
|
453
|
+
helpers `NAC.click`, `NAC.fill`, `NAC.invoke`,
|
|
454
|
+
`NAC.describe`, etc. all go through the deep variants.
|
|
455
|
+
|
|
456
|
+
#### Demos and tests
|
|
457
|
+
|
|
458
|
+
- `example-v23-shadow-open.php` -- 1-, 2-, and 3-level nested
|
|
459
|
+
open shadow demos.
|
|
460
|
+
- `packages/nac/test/v23-shadow.mjs` T1-T3, T10 -- unit
|
|
461
|
+
coverage including depth cap.
|
|
462
|
+
|
|
463
|
+
### 5.1.6 Shadow DOM resolution -- closed roots, voluntary exposure (v2.3)
|
|
464
|
+
|
|
465
|
+
Closed shadow roots (`attachShadow({mode:'closed'})`) are
|
|
466
|
+
opaque from outside the component author's code -- a browser
|
|
467
|
+
security boundary, not a NAC3 decision. NAC3 cannot reach
|
|
468
|
+
inside unless the component author voluntarily exposes a
|
|
469
|
+
queriable surface via the contract below.
|
|
470
|
+
|
|
471
|
+
#### The `el.nac3` interface contract
|
|
472
|
+
|
|
473
|
+
A custom element MAY expose an interface object on its host
|
|
474
|
+
via a getter named `nac3`:
|
|
475
|
+
|
|
476
|
+
```ts
|
|
477
|
+
interface NAC3HostInterface {
|
|
478
|
+
query(selector: string): Element | null; // MANDATORY
|
|
479
|
+
queryAll(selector: string): Element[]; // RECOMMENDED
|
|
480
|
+
describe?(): Array<{ // OPTIONAL
|
|
481
|
+
id: string;
|
|
482
|
+
role: string;
|
|
483
|
+
action?: string;
|
|
484
|
+
label?: string;
|
|
485
|
+
}>;
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Components opt in by implementing the getter. Components that
|
|
490
|
+
do NOT opt in remain inaccessible to NAC3 callers (their
|
|
491
|
+
internals stay private, as the browser intends).
|
|
492
|
+
|
|
493
|
+
#### Resolution semantics
|
|
494
|
+
|
|
495
|
+
During `_deepQuery(selector)`, for every visited element `el`
|
|
496
|
+
with `el.shadowRoot === null`:
|
|
497
|
+
|
|
498
|
+
1. If `typeof el.nac3 === 'object'` and `el.nac3.query` is a
|
|
499
|
+
function, the runtime calls `el.nac3.query(selector)`:
|
|
500
|
+
- Return value is an Element -> resolved.
|
|
501
|
+
- Return value is `null` -> not a match in this shadow.
|
|
502
|
+
- Return value is anything else -> emit
|
|
503
|
+
`nac:shadow_protocol_violation` (once per host) and skip.
|
|
504
|
+
- Throws -> emit `nac:shadow_blocked` (reason
|
|
505
|
+
`'exposure_threw'`, once per host) and skip.
|
|
506
|
+
2. Else if `el.hasAttribute('data-nac-shadow') === true` and
|
|
507
|
+
the attribute value is `'closed'` AND there is no `nac3`
|
|
508
|
+
interface present, the runtime emits `nac:shadow_blocked`
|
|
509
|
+
(reason `'not_exposed'`, once per host). Author opt-in to
|
|
510
|
+
the "I am a deliberately closed component" debug signal.
|
|
511
|
+
3. Else: the element is treated as a normal light-DOM
|
|
512
|
+
element with no shadow root.
|
|
513
|
+
|
|
514
|
+
#### Error event detail shapes
|
|
515
|
+
|
|
516
|
+
`nac:shadow_blocked` detail:
|
|
517
|
+
|
|
518
|
+
```ts
|
|
519
|
+
{
|
|
520
|
+
host: Element, // the closed-shadow host
|
|
521
|
+
reason: 'exposure_threw' | 'not_exposed',
|
|
522
|
+
ts: number // Date.now()
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
`nac:shadow_protocol_violation` detail:
|
|
527
|
+
|
|
528
|
+
```ts
|
|
529
|
+
{
|
|
530
|
+
host: Element,
|
|
531
|
+
message: string, // diagnostic message
|
|
532
|
+
value_snapshot: string, // truncated value preview
|
|
533
|
+
ts: number
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
Both events bubble (`bubbles: true`) and cross shadow
|
|
538
|
+
boundaries (`composed: true`). Dedup is per-host via a
|
|
539
|
+
WeakSet kept by the runtime; the same host emits each event
|
|
540
|
+
**at most once per page load**.
|
|
541
|
+
|
|
542
|
+
#### Why voluntary
|
|
543
|
+
|
|
544
|
+
The browser enforces closed-shadow opacity. Even if NAC3
|
|
545
|
+
defined a non-voluntary mechanism, the browser would prevent
|
|
546
|
+
it. Voluntary exposure puts the component author in full
|
|
547
|
+
control of what their public surface looks like for agents.
|
|
548
|
+
|
|
549
|
+
The cost is per-component opt-in; the benefit is that
|
|
550
|
+
NAC3-compliant agents work against design systems with closed
|
|
551
|
+
shadow components (Salesforce Lightning, some GitHub Primer
|
|
552
|
+
components, security-sensitive widgets) without per-component
|
|
553
|
+
adapter code.
|
|
554
|
+
|
|
555
|
+
#### Demos and tests
|
|
556
|
+
|
|
557
|
+
- `example-v23-shadow-closed.php` -- positive
|
|
558
|
+
(`<todo-card-closed-exposed>`) and negative
|
|
559
|
+
(`<todo-card-closed-blind>`) side-by-side with verdict
|
|
560
|
+
panels + live event log.
|
|
561
|
+
- `packages/nac/test/v23-shadow.mjs` T4-T9 -- unit coverage
|
|
562
|
+
for every error event family plus dedup semantics.
|
|
563
|
+
- `guides/SHADOW_DOM_CLOSED.md` -- authoring guide.
|
|
564
|
+
|
|
565
|
+
### 5.1.7 Auth-aware capabilities (v2.3)
|
|
566
|
+
|
|
567
|
+
NAC3 v2.3 lets the manifest declare per-action capability
|
|
568
|
+
requirements that gate `NAC.click` and `NAC.invoke` before
|
|
569
|
+
dispatch. The agent receives a fast rejection
|
|
570
|
+
(`code='capability_required'`) instead of a round-trip that
|
|
571
|
+
fails server-side.
|
|
572
|
+
|
|
573
|
+
#### Manifest declaration
|
|
574
|
+
|
|
575
|
+
A capability requirement attaches at the element level or at
|
|
576
|
+
the verb level. Verb-level wins if both are present.
|
|
577
|
+
|
|
578
|
+
```js
|
|
579
|
+
NAC.register({
|
|
580
|
+
plugin_slug: 'fin',
|
|
581
|
+
version: '1.0.0',
|
|
582
|
+
nac_version: '2.3',
|
|
583
|
+
elements: [
|
|
584
|
+
// Element-level (covers all verbs on this id).
|
|
585
|
+
{ id: 'fin.invoice.delete', role: 'action',
|
|
586
|
+
requires_capability: 'finance.delete_invoice',
|
|
587
|
+
actions: [{ verb: 'delete' }] },
|
|
588
|
+
|
|
589
|
+
// Verb-level (more granular).
|
|
590
|
+
{ id: 'fin.invoice.edit', role: 'action',
|
|
591
|
+
actions: [
|
|
592
|
+
{ verb: 'edit',
|
|
593
|
+
requires_capability: 'finance.edit_invoice' },
|
|
594
|
+
{ verb: 'view',
|
|
595
|
+
/* no capability -> always allowed */ }
|
|
596
|
+
] },
|
|
597
|
+
|
|
598
|
+
// Array value: OR semantics.
|
|
599
|
+
// ("at least one of these capabilities matches")
|
|
600
|
+
{ id: 'fin.invoice.approve', role: 'action',
|
|
601
|
+
requires_capability: ['finance.approve',
|
|
602
|
+
'finance.admin'],
|
|
603
|
+
actions: [{ verb: 'approve' }] }
|
|
604
|
+
]
|
|
605
|
+
});
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
For AND semantics ("user needs ALL of these caps"), declare
|
|
609
|
+
each via separate gated actions or compose at the host level
|
|
610
|
+
in the `nac:action:requested` listener.
|
|
611
|
+
|
|
612
|
+
#### Public API
|
|
613
|
+
|
|
614
|
+
```ts
|
|
615
|
+
NAC.setCapabilities(caps: string | string[] | null): void
|
|
616
|
+
NAC.grantCapability(cap: string): void
|
|
617
|
+
NAC.revokeCapability(cap: string): void
|
|
618
|
+
NAC.userCapabilities(): string[]
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
`setCapabilities` replaces the entire set (use for login /
|
|
622
|
+
session refresh). `grantCapability` / `revokeCapability` are
|
|
623
|
+
incremental. `userCapabilities` returns a snapshot array.
|
|
624
|
+
`setCapabilities(null)` clears the set.
|
|
625
|
+
|
|
626
|
+
Hosts call these whenever the user's role changes. The set
|
|
627
|
+
lives in the runtime; no manifest reload is required.
|
|
628
|
+
|
|
629
|
+
#### Gate semantics
|
|
630
|
+
|
|
631
|
+
Before dispatch, `NAC.click(id)` and `NAC.invoke(id, payload)`
|
|
632
|
+
look up the matching manifest entry (element + verb), read
|
|
633
|
+
`requires_capability`, and call `_hasCapability`:
|
|
634
|
+
|
|
635
|
+
- No requirement declared -> allow.
|
|
636
|
+
- Requirement declared, current set satisfies it -> allow.
|
|
637
|
+
- Requirement declared, current set does NOT satisfy -> reject
|
|
638
|
+
with `NacError('capability_required', ...)` AND emit
|
|
639
|
+
`nac:command:rejected` with `detail.reason='capability_required'`.
|
|
640
|
+
|
|
641
|
+
The gate runs AFTER `not_found` / `disabled` / `hidden` checks
|
|
642
|
+
on `click` so the most specific failure surfaces. On `invoke`,
|
|
643
|
+
the gate runs before the request event fires (the host never
|
|
644
|
+
sees an unauthorised attempt).
|
|
645
|
+
|
|
646
|
+
#### Why this matters
|
|
647
|
+
|
|
648
|
+
Without the gate, an agent calling `NAC.click('finance.delete')`
|
|
649
|
+
either succeeds (no auth gate at all -> security hole) or
|
|
650
|
+
fails server-side with a 403 several seconds later. With the
|
|
651
|
+
gate, the agent learns synchronously that it lacks the
|
|
652
|
+
capability and can react appropriately (request a different
|
|
653
|
+
flow, ask for elevation, surface the constraint to the user).
|
|
654
|
+
|
|
655
|
+
This complements -- it does not replace -- server-side
|
|
656
|
+
authorisation. Hosts MUST still enforce permissions on the
|
|
657
|
+
server. The client gate is a UX optimisation and an
|
|
658
|
+
intent-level signal, not a security boundary.
|
|
659
|
+
|
|
660
|
+
#### Demos and tests
|
|
661
|
+
|
|
662
|
+
- `packages/nac/test/v23-capabilities.mjs` -- 17 assertions
|
|
663
|
+
covering set/get, grant/revoke, click gate, invoke gate,
|
|
664
|
+
verb-level vs element-level resolution, OR semantics,
|
|
665
|
+
null-clear, invalid-input rejection, regression for
|
|
666
|
+
unguarded actions.
|
|
667
|
+
|
|
668
|
+
### 5.1.2 Strict validation flag (v2.2; default-flipped in v2.3)
|
|
669
|
+
|
|
670
|
+
`NAC.STRICT_VALIDATION` (boolean). When `true`, `NAC.register()`
|
|
671
|
+
throws an `Error` with `code='strict_validation'` and a
|
|
672
|
+
`findings` array on any of:
|
|
244
673
|
|
|
245
674
|
- `manifest_role_unknown` -- entry's role outside the canonical set.
|
|
246
675
|
- `tab_id_manifest_role_drift` -- id matches `^tab\.` but role
|
|
@@ -248,18 +677,38 @@ and a `findings` array on any of:
|
|
|
248
677
|
- `manifest_dom_role_mismatch` -- mounted DOM element's
|
|
249
678
|
`data-nac-role` differs from manifest entry's role.
|
|
250
679
|
|
|
251
|
-
|
|
252
|
-
|
|
680
|
+
**Default value:**
|
|
681
|
+
|
|
682
|
+
- **v2.2.x:** `false` (warning-only). Adopters needed a migration
|
|
683
|
+
window.
|
|
684
|
+
- **v2.3.x:** **`true`** (throwing). The migration window closed
|
|
685
|
+
with the v2.2 line. Adopters with drift-laden manifests opt
|
|
686
|
+
out by setting `NAC.STRICT_VALIDATION = false` BEFORE any
|
|
687
|
+
`register()` call.
|
|
688
|
+
- **v3.0:** flag removed (strict is the only mode).
|
|
689
|
+
|
|
690
|
+
See `guides/MIGRATION_v2.2_to_v2.3.md` for the playbook to clean
|
|
691
|
+
up drift findings.
|
|
253
692
|
|
|
254
693
|
All async methods reject with `NacError` whose `code` is one of:
|
|
255
694
|
|
|
256
695
|
- `not_found` -- the named element/role/verb is not in the DOM.
|
|
257
696
|
- `invalid` -- argument shape is wrong.
|
|
697
|
+
- `disabled` -- element has `disabled` or `aria-disabled='true'`
|
|
698
|
+
(`NAC.click` only; `NAC.invoke` no longer checks per v2.3
|
|
699
|
+
hotfix, see sec 5.1.4).
|
|
700
|
+
- `hidden` -- element is offscreen / `aria-hidden='true'` /
|
|
701
|
+
zero-dimension.
|
|
702
|
+
- `capability_required` -- manifest declared
|
|
703
|
+
`requires_capability` and the current
|
|
704
|
+
`NAC.userCapabilities()` set does not satisfy it (v2.3, see
|
|
705
|
+
sec 5.1.7).
|
|
258
706
|
- `timeout` -- side effect dispatched but the conformance ack
|
|
259
|
-
event did not arrive within 5 seconds
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
707
|
+
event did not arrive within 5 seconds (30 seconds for
|
|
708
|
+
`invoke`). **A timeout means real failure**: the handler may
|
|
709
|
+
have hung, the ack was never wired, a network race occurred.
|
|
710
|
+
Callers MUST treat timeout as failure unless they have proof
|
|
711
|
+
of side effect via another channel.
|
|
263
712
|
|
|
264
713
|
### 5.2 Introspection
|
|
265
714
|
|
|
@@ -413,66 +862,6 @@ See `SECURITY.md` for the full threat model. Short version:
|
|
|
413
862
|
- NAC3 does not protect against a malicious agent running with
|
|
414
863
|
user-level access. Such an agent can do anything the user can.
|
|
415
864
|
|
|
416
|
-
### 7.4 Plugin slug uniqueness (v2.4)
|
|
417
|
-
|
|
418
|
-
A `data-nac-plugin="<slug>"` attribute identifies a plugin
|
|
419
|
-
**instance** in the DOM. The runtime resolves
|
|
420
|
-
`(plugin, nac_id)` pairs against these scopes, so the host MUST
|
|
421
|
-
guarantee unambiguous resolution.
|
|
422
|
-
|
|
423
|
-
**Rules.**
|
|
424
|
-
|
|
425
|
-
1. A given plugin slug MAY appear on more than one DOM root
|
|
426
|
-
simultaneously (a "list view + side panel" combo for the same
|
|
427
|
-
plugin family, a topbar mirror of an action that also lives in
|
|
428
|
-
the body, etc).
|
|
429
|
-
2. **When the slug appears more than once, every root carrying it
|
|
430
|
-
MUST also carry a unique `data-nac-plugin-id` attribute.** The
|
|
431
|
-
pair `(data-nac-plugin, data-nac-plugin-id)` is the canonical
|
|
432
|
-
instance key.
|
|
433
|
-
3. A single-root slug MAY omit `data-nac-plugin-id`; in that case
|
|
434
|
-
`(slug, null)` is the instance key.
|
|
435
|
-
|
|
436
|
-
**Runtime enforcement (v2.4).**
|
|
437
|
-
|
|
438
|
-
- The constructor `NAC.register(manifest)` rejects the call
|
|
439
|
-
synchronously with `NacError('duplicate_plugin_no_instance_id',
|
|
440
|
-
...)` when the DOM already contains multiple roots with the
|
|
441
|
-
registered slug and any of them omits / duplicates
|
|
442
|
-
`data-nac-plugin-id`.
|
|
443
|
-
- A boot-time pass (`nac:dom-ready` listener installed by the
|
|
444
|
-
runtime) performs the same check across every `[data-nac-plugin]`
|
|
445
|
-
root in the document. On the first violation it dispatches
|
|
446
|
-
`nac:fatal` with `code='duplicate_plugin_no_instance_id'`,
|
|
447
|
-
inserts a visible red banner at the top of `<body>`, and
|
|
448
|
-
throws. The runtime then refuses every subsequent
|
|
449
|
-
`describe`/`click`/`click_by_verb`/`tab` call.
|
|
450
|
-
- `NAC.click_by_verb` resolves verbs against the manifest first.
|
|
451
|
-
When the manifest does not declare a top-level `actions[]` and
|
|
452
|
-
the runtime falls back to DOM scanning, the scan iterates
|
|
453
|
-
**every** `[data-nac-plugin="<slug>"]` root (not just the
|
|
454
|
-
first), matching the first descendant `[data-nac-action="<verb>"]`
|
|
455
|
-
it finds.
|
|
456
|
-
- `NAC.validate_global()` continues to emit
|
|
457
|
-
`duplicate_plugin_no_instance_id` as a structured finding for CI
|
|
458
|
-
pipelines that prefer non-fatal reporting.
|
|
459
|
-
|
|
460
|
-
**Migration from v2.3.**
|
|
461
|
-
|
|
462
|
-
The boot-time throw is enabled by default in v2.4. Authors who
|
|
463
|
-
need a one-release migration window can set
|
|
464
|
-
`NAC.HARD_DEDUP = false` before the runtime's
|
|
465
|
-
`DOMContentLoaded` listener fires. The flag is removed in v2.5.
|
|
466
|
-
|
|
467
|
-
**Why "throw" not "warn".**
|
|
468
|
-
|
|
469
|
-
Multiple roots sharing a slug without instance ids make every
|
|
470
|
-
`(plugin, nac_id)` lookup first-match-wins by document order.
|
|
471
|
-
That is non-deterministic across DOM rearrangements (drag-drop
|
|
472
|
-
sorts, conditional render order, framework re-mounts) and the
|
|
473
|
-
agent has no way to know which root won. v2.3 surfaced this only
|
|
474
|
-
through opt-in lint; v2.4 makes it a build-time gate.
|
|
475
|
-
|
|
476
865
|
---
|
|
477
866
|
|
|
478
867
|
## 8. Conformance levels
|
|
@@ -661,6 +1050,322 @@ code, is the authority.
|
|
|
661
1050
|
|
|
662
1051
|
---
|
|
663
1052
|
|
|
664
|
-
|
|
665
|
-
|
|
1053
|
+
## 15. Plugin extension contract -- canvas + API surfaces (v2.5)
|
|
1054
|
+
|
|
1055
|
+
Sections 1-14 assume the agent-relevant surface is **DOM**. Every
|
|
1056
|
+
addressable element has a `data-nac-id` attribute, every verb fires
|
|
1057
|
+
through `el.click()`, every state read comes from
|
|
1058
|
+
`el.getAttribute(...)`. This works for apps whose chrome AND
|
|
1059
|
+
content live in DOM nodes.
|
|
1060
|
+
|
|
1061
|
+
It does not work for apps where part of the surface is **canvas**
|
|
1062
|
+
(LibreOffice / Collabora Online, Figma, Excalidraw, Miro, every
|
|
1063
|
+
custom WebGL editor). The chrome may still be DOM (toolbars,
|
|
1064
|
+
dialogs), but commands often need to flow through the app's own
|
|
1065
|
+
public API (postMessage, plugin SDK, script bridge), and state may
|
|
1066
|
+
not be readable from the DOM at all.
|
|
1067
|
+
|
|
1068
|
+
v2.5 adds a small set of primitives that let a NAC3 plugin declare
|
|
1069
|
+
its own routing contract to such surfaces. The runtime stays
|
|
1070
|
+
agnostic of any specific app -- it learns how to talk to one only
|
|
1071
|
+
by reading the plugin's manifest.
|
|
1072
|
+
|
|
1073
|
+
### 15.1 Why a new primitive set
|
|
1074
|
+
|
|
1075
|
+
DOM-only `NAC.click(id)` cannot:
|
|
1076
|
+
|
|
1077
|
+
- Send a `Send_UNO_Command` postMessage to a sandboxed Collabora
|
|
1078
|
+
iframe.
|
|
1079
|
+
- Call `figma.currentPage.selection = [...]` inside the Figma
|
|
1080
|
+
plugin sandbox.
|
|
1081
|
+
- Invoke `excalidrawAPI.setElements(...)` on a React ref.
|
|
1082
|
+
- Read whether Bold is active on the current Collabora selection
|
|
1083
|
+
(the toolbar reflects it; the canvas hides it).
|
|
1084
|
+
|
|
1085
|
+
The fix is **not** to extend `NAC.click` with backend-detection
|
|
1086
|
+
heuristics. The fix is to add an explicit, agnostic verb that
|
|
1087
|
+
takes a plugin slug and a verb path, and lets the plugin's
|
|
1088
|
+
manifest declare how that verb is routed.
|
|
1089
|
+
|
|
1090
|
+
### 15.2 The three primitives
|
|
1091
|
+
|
|
1092
|
+
```ts
|
|
1093
|
+
NAC.registerPlugin(slug: string, manifest: PluginManifest): void
|
|
1094
|
+
NAC.call(plugin: string, verb_path: string, args?: object): Promise<any>
|
|
1095
|
+
NAC.read(plugin: string, state_path: string): Promise<any>
|
|
1096
|
+
NAC.subscribe(plugin: string, event_path: string,
|
|
1097
|
+
cb: (data: any) => void): SubscriptionHandle
|
|
1098
|
+
NAC.unsubscribe(handle: SubscriptionHandle): void
|
|
1099
|
+
```
|
|
1100
|
+
|
|
1101
|
+
- `registerPlugin(slug, manifest)` registers a v2.5 plugin. A given
|
|
1102
|
+
`slug` MAY appear in both the DOM manifest registry (section 5)
|
|
1103
|
+
and the v2.5 extension registry; the two coexist. v2.5 calls
|
|
1104
|
+
resolve only through the v2.5 registry.
|
|
1105
|
+
- `call` invokes a declared verb. Routing is chosen by the
|
|
1106
|
+
manifest, not by the agent. Resolves with whatever the backend
|
|
1107
|
+
returned (often `undefined` / `{ok: true}`); rejects with
|
|
1108
|
+
`NacError` if the verb is unknown, the backend fails, or the
|
|
1109
|
+
response shape is invalid.
|
|
1110
|
+
- `read` returns a declared state value. The runtime walks the
|
|
1111
|
+
state's fallback chain in declared order and returns the first
|
|
1112
|
+
source that resolves; rejects only when every source in the
|
|
1113
|
+
chain failed.
|
|
1114
|
+
- `subscribe` attaches a listener to a declared event. Returns a
|
|
1115
|
+
handle that the caller passes to `unsubscribe` to clean up.
|
|
1116
|
+
Events MAY be backed by a real upstream event source or
|
|
1117
|
+
synthesised via polling / MutationObserver -- the manifest
|
|
1118
|
+
declares which.
|
|
1119
|
+
|
|
1120
|
+
All four functions are async (Promise-returning) except
|
|
1121
|
+
`unsubscribe`, which is synchronous and idempotent.
|
|
1122
|
+
|
|
1123
|
+
### 15.3 Plugin manifest shape
|
|
1124
|
+
|
|
1125
|
+
```ts
|
|
1126
|
+
interface PluginManifest {
|
|
1127
|
+
slug: string;
|
|
1128
|
+
verbs: { [verb_path: string]: VerbBinding };
|
|
1129
|
+
state: { [state_path: string]: StateBinding[] };
|
|
1130
|
+
events: { [event_path: string]: EventBinding };
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
interface VerbBinding {
|
|
1134
|
+
backend: BackendKind;
|
|
1135
|
+
/* backend-specific fields (see 15.4) */
|
|
1136
|
+
[k: string]: any;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
interface StateBinding {
|
|
1140
|
+
backend: BackendKind;
|
|
1141
|
+
/* backend-specific fields (see 15.4) */
|
|
1142
|
+
extract?: string; /* extractor DSL string (see 15.5) */
|
|
1143
|
+
[k: string]: any;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
interface EventBinding {
|
|
1147
|
+
backend: BackendKind;
|
|
1148
|
+
/* backend-specific fields */
|
|
1149
|
+
[k: string]: any;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
type BackendKind =
|
|
1153
|
+
| 'postmessage'
|
|
1154
|
+
| 'postmessage-listen'
|
|
1155
|
+
| 'sdk-call'
|
|
1156
|
+
| 'script-bridge'
|
|
1157
|
+
| 'dom-mirror'
|
|
1158
|
+
| 'same-origin-window'
|
|
1159
|
+
| 'synthetic-mutation'
|
|
1160
|
+
| 'synthetic-poll';
|
|
1161
|
+
```
|
|
1162
|
+
|
|
1163
|
+
Manifests are pure JSON (no JS callbacks). Forge, Sumi, and any
|
|
1164
|
+
future tooling generates them as data; the runtime interprets the
|
|
1165
|
+
backend names from a fixed vocabulary.
|
|
1166
|
+
|
|
1167
|
+
Verbs and events have **exactly one** binding. State has an
|
|
1168
|
+
**ordered array** of bindings: the runtime walks the chain in
|
|
1169
|
+
order, returning the first source that successfully resolved.
|
|
1170
|
+
|
|
1171
|
+
### 15.4 Backend vocabulary
|
|
1172
|
+
|
|
1173
|
+
| Kind | Used for | Required fields |
|
|
1174
|
+
|------|----------|-----------------|
|
|
1175
|
+
| `postmessage` | Verb: post a message to an iframe via `postMessage`. | `target` (CSS selector of the iframe to send to), `message` (MessageId string), `values` (object literal interpolated with args), `values_from_args` (optional array of arg keys to forward verbatim) |
|
|
1176
|
+
| `postmessage-listen` | Event: listen for a specific incoming `MessageId` on `window.message`. | `source` (CSS selector of the iframe to filter origin by; if omitted, accept any source), `message` (MessageId to match), `extract` (extractor DSL into the message data) |
|
|
1177
|
+
| `sdk-call` | Verb: call a globally-exposed JS function (e.g. Figma plugin, Excalidraw API). | `path` (dotted path into `window`, e.g. `figma.currentPage.selection`), `mode` (`assign` to set the path to the args value, `invoke` to call it as a function with the args object) |
|
|
1178
|
+
| `script-bridge` | Verb or state: invoke an app's scripting bridge (Collabora's `CallPythonScript`, LibreOffice UNO bridge, Google Apps Script). | `bridge` (a backend-specific identifier like `collabora.python`), `script` (script identifier), `function` (function name to run), `args` (object literal interpolated with the call args), `response_match` (for state: the response MessageId to wait on), `timeout_ms` (optional, default 5000) |
|
|
1179
|
+
| `dom-mirror` | State: read from a DOM element whose attribute / class / text mirrors a canvas-internal state (e.g. a toolbar button highlighted when its formatting is active on the current selection). | `selector` (CSS selector to query), `extract` (extractor DSL, see 15.5) |
|
|
1180
|
+
| `same-origin-window` | State: read from `iframe.contentWindow.<path>` when the iframe is same-origin. The runtime detects cross-origin and falls through. | `target` (CSS selector of the iframe), `path` (dotted path into `contentWindow`) |
|
|
1181
|
+
| `synthetic-mutation` | Event: synthesise an event by observing DOM mutations on one or more state sources and re-emitting when the observed value changes. | `observe` (array of state paths to watch; the runtime calls `read` on each and diffs across mutations), `throttle_ms` (optional, default 100) |
|
|
1182
|
+
| `synthetic-poll` | Event: synthesise an event by polling state sources. | `observe` (array of state paths), `interval_ms` (default 250) |
|
|
1183
|
+
|
|
1184
|
+
Each backend MUST be implemented by the runtime as a self-contained
|
|
1185
|
+
dispatcher (`dispatch(binding, args, context) -> Promise<value>`).
|
|
1186
|
+
Adding a new backend type to the spec requires bumping the spec
|
|
1187
|
+
version; runtimes ignoring unknown backends MUST reject manifests
|
|
1188
|
+
that declare them (no silent skip).
|
|
1189
|
+
|
|
1190
|
+
### 15.5 Extractor mini-DSL
|
|
1191
|
+
|
|
1192
|
+
State backends and the `postmessage-listen` event backend often
|
|
1193
|
+
need to pluck a field out of a larger object. The runtime ships
|
|
1194
|
+
a tiny declarative DSL so manifests stay JSON-only:
|
|
1195
|
+
|
|
1196
|
+
| Syntax | Meaning | Example input -> output |
|
|
1197
|
+
|--------|---------|-------------------------|
|
|
1198
|
+
| `field.path.to.value` | Dotted path traversal. | `{a:{b:1}}` with `a.b` -> `1` |
|
|
1199
|
+
| `attribute:NAME` | DOM only: read `el.getAttribute(NAME)`. | `<i data-x="hi">` with `attribute:data-x` -> `'hi'` |
|
|
1200
|
+
| `text` | DOM only: read `el.textContent`. | `<span>hi</span>` with `text` -> `'hi'` |
|
|
1201
|
+
| `classList.contains:CLASS` | DOM only: `el.classList.contains(CLASS)` -> boolean. | `<button class="active">` with `classList.contains:active` -> `true` |
|
|
1202
|
+
| `value` | DOM only: read `el.value`. | `<input value="x">` with `value` -> `'x'` |
|
|
1203
|
+
| `present` | DOM only: returns `true` if the selector resolved an element, `false` otherwise. | selector matched -> `true` |
|
|
1204
|
+
|
|
1205
|
+
Composition is not supported in v2.5; an extractor is exactly one
|
|
1206
|
+
of the rows above. A manifest needing complex transformation
|
|
1207
|
+
declares a `script-bridge` instead.
|
|
1208
|
+
|
|
1209
|
+
### 15.6 Fallback chain semantics for `state`
|
|
1210
|
+
|
|
1211
|
+
`state[path]` is an array of bindings. `NAC.read(plugin, path)` walks
|
|
1212
|
+
the array in order. For each binding:
|
|
1213
|
+
|
|
1214
|
+
1. The runtime invokes the backend's dispatcher.
|
|
1215
|
+
2. If the dispatcher resolves with a value (including `false`, `0`,
|
|
1216
|
+
empty string, but NOT `undefined`), `read` returns that value.
|
|
1217
|
+
3. If the dispatcher rejects, or resolves with `undefined`, the
|
|
1218
|
+
runtime advances to the next binding in the array.
|
|
1219
|
+
4. If no binding produced a value, `read` rejects with
|
|
1220
|
+
`NacError('state_unreadable', ...)` whose `err.attempts: [...]`
|
|
1221
|
+
carries one entry per attempted backend with `{backend, reason}`.
|
|
1222
|
+
|
|
1223
|
+
Rationale: the chain encodes the manifest author's preference
|
|
1224
|
+
order. The fastest, cheapest, freshest source is declared first;
|
|
1225
|
+
fallbacks degrade gracefully. The runtime never silently picks an
|
|
1226
|
+
inferior source first.
|
|
1227
|
+
|
|
1228
|
+
### 15.7 Provenance for synthetic actions
|
|
1229
|
+
|
|
1230
|
+
Every `NAC.call` dispatch emits a `nac:plugin:invoked` event on
|
|
1231
|
+
`document` after the backend returns. The detail payload:
|
|
1232
|
+
|
|
1233
|
+
```js
|
|
1234
|
+
{
|
|
1235
|
+
plugin: 'collabora.writer',
|
|
1236
|
+
verb_path: 'uno.Bold',
|
|
1237
|
+
backend: 'postmessage',
|
|
1238
|
+
request_id: 'pi_<random hex>',
|
|
1239
|
+
source: 'agent', // see sec 7
|
|
1240
|
+
trusted: false,
|
|
1241
|
+
duration_ms: 12,
|
|
1242
|
+
ok: true,
|
|
1243
|
+
error: null,
|
|
1244
|
+
}
|
|
1245
|
+
```
|
|
1246
|
+
|
|
1247
|
+
Same shape for `nac:plugin:read` (after a `read`) and
|
|
1248
|
+
`nac:plugin:event` (synthesised event re-emit). `source` defaults
|
|
1249
|
+
to `'agent'`; hosts that wrap the runtime in a user-facing UI MAY
|
|
1250
|
+
override via the existing `NAC.set_source(...)` mechanism (sec 7).
|
|
1251
|
+
|
|
1252
|
+
### 15.8 Worked example -- Collabora Writer
|
|
1253
|
+
|
|
1254
|
+
```json
|
|
1255
|
+
{
|
|
1256
|
+
"slug": "collabora.writer",
|
|
1257
|
+
"verbs": {
|
|
1258
|
+
"uno.Bold": {
|
|
1259
|
+
"backend": "postmessage",
|
|
1260
|
+
"target": "iframe[data-collabora-frame]",
|
|
1261
|
+
"message": "Send_UNO_Command",
|
|
1262
|
+
"values": { "Command": ".uno:Bold" }
|
|
1263
|
+
},
|
|
1264
|
+
"doc.save": {
|
|
1265
|
+
"backend": "postmessage",
|
|
1266
|
+
"target": "iframe[data-collabora-frame]",
|
|
1267
|
+
"message": "Action_Save",
|
|
1268
|
+
"values_from_args": ["DontTerminateEdit", "Notify"]
|
|
1269
|
+
}
|
|
1270
|
+
},
|
|
1271
|
+
"state": {
|
|
1272
|
+
"selection.isBold": [
|
|
1273
|
+
{ "backend": "dom-mirror",
|
|
1274
|
+
"selector": "[data-nac-id='toolbar.bold']",
|
|
1275
|
+
"extract": "classList.contains:selected" },
|
|
1276
|
+
{ "backend": "script-bridge",
|
|
1277
|
+
"bridge": "collabora.python",
|
|
1278
|
+
"script": "yujin_state.py",
|
|
1279
|
+
"function": "GetSelectionState",
|
|
1280
|
+
"response_match": "CallPythonScript-Result",
|
|
1281
|
+
"extract": "Values.is_bold" }
|
|
1282
|
+
],
|
|
1283
|
+
"doc.modified": [
|
|
1284
|
+
{ "backend": "same-origin-window",
|
|
1285
|
+
"target": "iframe[data-collabora-frame]",
|
|
1286
|
+
"path": "app.file.modified" }
|
|
1287
|
+
]
|
|
1288
|
+
},
|
|
1289
|
+
"events": {
|
|
1290
|
+
"doc.modified": {
|
|
1291
|
+
"backend": "postmessage-listen",
|
|
1292
|
+
"source": "iframe[data-collabora-frame]",
|
|
1293
|
+
"message": "Doc_ModifiedStatus",
|
|
1294
|
+
"extract": "Values.Modified"
|
|
1295
|
+
},
|
|
1296
|
+
"selection.changed": {
|
|
1297
|
+
"backend": "synthetic-mutation",
|
|
1298
|
+
"observe": ["selection.isBold", "selection.isItalic"],
|
|
1299
|
+
"throttle_ms": 100
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
The agent calls `NAC.call('collabora.writer', 'uno.Bold')`; the
|
|
1306
|
+
runtime routes through the `postmessage` backend, posts
|
|
1307
|
+
`Send_UNO_Command` to the iframe. To confirm the effect occurred
|
|
1308
|
+
(see sec 17), the agent calls
|
|
1309
|
+
`await NAC.read('collabora.writer', 'selection.isBold')`; the
|
|
1310
|
+
runtime tries the toolbar mirror first (fast, free), falls back to
|
|
1311
|
+
the Python script bridge if the mirror is unavailable. The agent
|
|
1312
|
+
never knows or cares which source answered.
|
|
1313
|
+
|
|
1314
|
+
### 15.9 Errors
|
|
1315
|
+
|
|
1316
|
+
`NAC.call` / `read` / `subscribe` reject with `NacError` whose `code`
|
|
1317
|
+
is one of:
|
|
1318
|
+
|
|
1319
|
+
- `plugin_not_registered` -- the slug has no v2.5 manifest.
|
|
1320
|
+
- `verb_not_declared` -- the verb path is not in the manifest.
|
|
1321
|
+
- `state_not_declared` -- the state path is not in the manifest.
|
|
1322
|
+
- `event_not_declared` -- the event path is not in the manifest.
|
|
1323
|
+
- `backend_unknown` -- the manifest declares a backend the runtime
|
|
1324
|
+
does not implement. Manifest MUST be rejected at register time;
|
|
1325
|
+
this error only surfaces if a runtime accepts a future manifest
|
|
1326
|
+
format it then cannot dispatch.
|
|
1327
|
+
- `backend_target_missing` -- the backend's target (iframe, JS
|
|
1328
|
+
path, DOM selector) is not findable.
|
|
1329
|
+
- `cross_origin_blocked` -- `same-origin-window` was attempted
|
|
1330
|
+
against a cross-origin iframe.
|
|
1331
|
+
- `state_unreadable` -- every binding in a state chain failed; see
|
|
1332
|
+
15.6.
|
|
1333
|
+
- `timeout` -- a backend did not respond within its declared
|
|
1334
|
+
`timeout_ms` (default 5000 for verbs, 1000 for state reads).
|
|
1335
|
+
- `invalid` -- argument shape is wrong (bad slug, malformed
|
|
1336
|
+
manifest at register time, etc).
|
|
1337
|
+
|
|
1338
|
+
---
|
|
1339
|
+
|
|
1340
|
+
## 16. Tree navigation (v2.5 -- PLANNED, see sec 17 & 18 below)
|
|
1341
|
+
|
|
1342
|
+
*Drafting pending. Captures `NAC.context(plugin)` (current
|
|
1343
|
+
breadcrumb) + `NAC.tree(plugin, rootId?)` (enumerate hijos
|
|
1344
|
+
navegables) + the `data-nac-opens` / `data-nac-leaf` attributes
|
|
1345
|
+
that let the chrome declare hierarchical relationships explicitly.*
|
|
1346
|
+
|
|
1347
|
+
---
|
|
1348
|
+
|
|
1349
|
+
## 17. Asistive labels (v2.5 -- PLANNED)
|
|
1350
|
+
|
|
1351
|
+
*Drafting pending. Captures `NAC.narrate(plugin, nodeId)` (return
|
|
1352
|
+
the canonical human-readable label for screen reader / TTS),
|
|
1353
|
+
validation warnings for ordinal-shaped ids and for nodes that
|
|
1354
|
+
have no readable label.*
|
|
1355
|
+
|
|
1356
|
+
---
|
|
1357
|
+
|
|
1358
|
+
## 18. Effect detection (v2.5 -- PLANNED)
|
|
1359
|
+
|
|
1360
|
+
*Drafting pending. Captures `NAC.expect(plugin, statePath, value,
|
|
1361
|
+
opts?)` (Promise that resolves when a state matches an expected
|
|
1362
|
+
value within a timeout) and `NAC.diff(plugin, statePath, beforeFn,
|
|
1363
|
+
afterFn)` (snapshot a state pre- and post- an action).*
|
|
1364
|
+
|
|
1365
|
+
---
|
|
1366
|
+
|
|
1367
|
+
*This document is the canonical NAC3 v2.5-draft specification.
|
|
1368
|
+
Sections 0-14 are unchanged from v2.4 stable. Section 15 is GA
|
|
1369
|
+
in v2.5; sections 16-18 are in active drafting. Edits to this
|
|
1370
|
+
file constitute spec changes and require an RFC; see
|
|
666
1371
|
`CONTRIBUTING.md`.*
|