@nac3/runtime 2.2.0 → 2.3.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 +120 -0
- package/SPEC.md +147 -2
- package/dist/cli.js +3 -3
- package/dist/nac-chat-client.browser.js +17 -13
- package/dist/nac-chat-client.cjs +17 -13
- package/dist/nac-chat-client.mjs +17 -13
- package/dist/nac-v2-extensions.browser.js +15 -7
- package/dist/nac-v2-extensions.cjs +15 -7
- package/dist/nac-v2-extensions.mjs +15 -7
- package/dist/nac.browser.js +174 -10
- package/dist/nac.cjs +174 -10
- package/dist/nac.mjs +174 -10
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,125 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.3.0-alpha.1 -- 2026-05-12
|
|
4
|
+
|
|
5
|
+
### New: payload-bearing actions via `NAC.invoke` + `NAC.utter`
|
|
6
|
+
|
|
7
|
+
The NAC v2.2 contract was click-and-go: an agent triggers
|
|
8
|
+
`NAC.click(id)` or `NAC.click_by_verb(plugin, verb)` and the host
|
|
9
|
+
does whatever it does. That works for verb-and-state actions
|
|
10
|
+
(`save`, `cancel`, `submit`, `delete`) but breaks down when the
|
|
11
|
+
action needs **data** from the agent: `utter(text)`,
|
|
12
|
+
`search(query)`, `send_message(body)`, `upload(file)`,
|
|
13
|
+
`schedule(date)`. Hosts had no way to receive an agent's payload
|
|
14
|
+
via a synthetic click.
|
|
15
|
+
|
|
16
|
+
v2.3 adds the missing primitive:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
NAC.invoke(action_id, payload, opts?): Promise<{ok, request_id, ack}>
|
|
20
|
+
NAC.utter(action_id, {text, lang?, voice?}): Promise<...>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`NAC.invoke` dispatches a `nac:action:requested` CustomEvent on
|
|
24
|
+
the host element (bubbles) with the agent's `payload` + a
|
|
25
|
+
runtime-issued `request_id`. The host listens, processes, emits
|
|
26
|
+
`nac:action:succeeded` (or `:failed`) echoing the same
|
|
27
|
+
`request_id`. The runtime correlates and resolves the Promise.
|
|
28
|
+
|
|
29
|
+
Default timeout 30 s (vs 5 s for click). On timeout the Promise
|
|
30
|
+
rejects with `code='timeout'`.
|
|
31
|
+
|
|
32
|
+
`NAC.utter(id, opts)` is the ergonomic shortcut for `verb='utter'`
|
|
33
|
+
-- equivalent to `NAC.invoke(id, {verb:'utter', text, lang, voice})`.
|
|
34
|
+
|
|
35
|
+
Manifest entries for payload-bearing actions can declare an
|
|
36
|
+
informational `payload_schema`:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
{ id: 'atlas_pro_ad.mic', role: 'action',
|
|
40
|
+
actions: [
|
|
41
|
+
{ verb: 'listen' },
|
|
42
|
+
{ verb: 'utter',
|
|
43
|
+
payload_schema: {
|
|
44
|
+
text: { type: 'string', required: true, max: 4000 },
|
|
45
|
+
lang: { type: 'string', enum: ['en','es','pt','fr','it','de','ja','zh','hi','ar'] }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Click-style verbs (`NAC.click`, `NAC.click_by_verb`) continue to
|
|
53
|
+
work unchanged. The new contract is purely additive; no demo
|
|
54
|
+
behaviour regresses.
|
|
55
|
+
|
|
56
|
+
#### First adopter
|
|
57
|
+
|
|
58
|
+
Atlas Pro (`https://yujin.app/nac-spec/ads-demo/atlas-pro/`)
|
|
59
|
+
declares both `listen` (click-only, existing) and `utter`
|
|
60
|
+
(payload-bearing) on its `atlas_pro_ad.mic` action. The same
|
|
61
|
+
`/ad-orchestrator/parse` + `/ad-orchestrator/tts` loop drives
|
|
62
|
+
either path -- agents with their own STT call `listen`, agents
|
|
63
|
+
with their own LM call `utter` with the recognised text.
|
|
64
|
+
|
|
65
|
+
#### Test coverage
|
|
66
|
+
|
|
67
|
+
- `test/v23-invoke.mjs` (new) -- 22 assertions covering happy
|
|
68
|
+
path, ack echo, host-failed path, invalid args, not-found,
|
|
69
|
+
custom timeout. PASS.
|
|
70
|
+
- `test/v22.mjs` -- amended to accept v2.3.x in addition to
|
|
71
|
+
v2.2.x. PASS.
|
|
72
|
+
- `test/smoke.mjs` -- updated version assertions. PASS.
|
|
73
|
+
|
|
74
|
+
#### Files touched
|
|
75
|
+
|
|
76
|
+
- `yujin.app/nac-spec/js/nac.js` -- `invoke()` + `utter()` (~150
|
|
77
|
+
LOC additive). Public API surface +2 functions. NAC.version
|
|
78
|
+
bumped to '2.3.0-alpha.1', spec_version to '2.3'.
|
|
79
|
+
- `yujin.app/nac-spec/SPEC.md` -- new section 5.1.4 + header
|
|
80
|
+
version line.
|
|
81
|
+
- `yujin.app/nac-spec/ads-demo/atlas-pro/index.html` -- manifest
|
|
82
|
+
declares the `utter` verb + DOM listener routes into the demo's
|
|
83
|
+
existing `handleUtterance(text)`.
|
|
84
|
+
- `packages/nac/package.json`, `build.mjs`, `test/smoke.mjs` --
|
|
85
|
+
version bumps + new test in `npm test`.
|
|
86
|
+
|
|
87
|
+
#### Not yet wired
|
|
88
|
+
|
|
89
|
+
- `STRICT_VALIDATION` enforcement of `payload_schema` (alpha:
|
|
90
|
+
schema is informational).
|
|
91
|
+
- A `NAC.search` / `NAC.upload` / `NAC.send_message` ergonomic
|
|
92
|
+
shortcut sibling to `NAC.utter`. The generic `NAC.invoke` works
|
|
93
|
+
today; concrete shortcuts can be added without re-spec.
|
|
94
|
+
|
|
95
|
+
## 2.2.1 -- 2026-05-12
|
|
96
|
+
|
|
97
|
+
### Bug fix: importable in Node / SSR / test contexts
|
|
98
|
+
|
|
99
|
+
Pre-launch smoke test caught that `import '@nac3/runtime'` and
|
|
100
|
+
`import '@nac3/runtime/chat-client'` crashed in Node.js with
|
|
101
|
+
`ReferenceError: document is not defined`. The bundles had
|
|
102
|
+
top-level `document.dispatchEvent` and `document.addEventListener`
|
|
103
|
+
calls firing at module-evaluation time.
|
|
104
|
+
|
|
105
|
+
Fix: wrap browser-only init in `typeof document !== 'undefined'`
|
|
106
|
+
guards. In the browser the behaviour is unchanged (the events
|
|
107
|
+
still fire on install + the confirm listener still attaches). In
|
|
108
|
+
Node / SSR / Vitest / Jest the bundles now import as no-ops
|
|
109
|
+
instead of crashing.
|
|
110
|
+
|
|
111
|
+
Files patched (no API change):
|
|
112
|
+
- `dist/nac.{mjs,cjs,browser.js}` -- guarded `nac:installed`
|
|
113
|
+
dispatch + `_installA11yHintBridge()` call.
|
|
114
|
+
- `dist/nac-chat-client.{mjs,cjs,browser.js}` -- guarded
|
|
115
|
+
`nac:confirm:requested` listener attach.
|
|
116
|
+
- `dist/nac-v2-extensions.*` -- unchanged (it already early-bails
|
|
117
|
+
when the main runtime is not present).
|
|
118
|
+
|
|
119
|
+
Verified: all three entry points (`@nac3/runtime`,
|
|
120
|
+
`@nac3/runtime/extensions`, `@nac3/runtime/chat-client`) now
|
|
121
|
+
import cleanly under Node 22 ESM + CommonJS `require`.
|
|
122
|
+
|
|
3
123
|
## 2.2.0 -- 2026-05-10
|
|
4
124
|
|
|
5
125
|
Same-day v2.2 ships the constructor-strict validator + action-ack
|
package/SPEC.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# NAC3 -- Native Agent Contract
|
|
2
2
|
|
|
3
|
-
**Version:** 2.
|
|
4
|
-
**Status:**
|
|
3
|
+
**Version:** 2.3.0-alpha.1 (preview; payload-bearing actions land here)
|
|
4
|
+
**Status:** v2.2.x stable + v2.3 preview
|
|
5
5
|
**License:** Apache-2.0
|
|
6
6
|
**Editor:** Yujin (rpaforce.com)
|
|
7
7
|
|
|
@@ -232,6 +232,151 @@ NAC.edit_field('invoice.client_name');
|
|
|
232
232
|
NAC.click_by_verb('myplugin', 'edit_field', { nac_id: 'invoice.client_name' });
|
|
233
233
|
```
|
|
234
234
|
|
|
235
|
+
### 5.1.4 Action payload + invoke (v2.3 preview)
|
|
236
|
+
|
|
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-alpha. 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.
|
|
323
|
+
|
|
324
|
+
#### Conformance: hosts that support invoke MUST
|
|
325
|
+
|
|
326
|
+
1. Declare `actions[].payload_schema` in the manifest entry.
|
|
327
|
+
2. Listen for `nac:action:requested` (or use a generic listener
|
|
328
|
+
that filters by `detail.action_id` + `detail.verb`).
|
|
329
|
+
3. Emit `nac:action:succeeded` -- with `detail.request_id`
|
|
330
|
+
echoed back -- after processing, or `nac:action:failed`
|
|
331
|
+
(with `detail.error` code) on failure.
|
|
332
|
+
4. NEVER emit a `:succeeded` event with a `request_id` they did
|
|
333
|
+
not receive (prevents cross-talk between concurrent invocations).
|
|
334
|
+
|
|
335
|
+
Hosts that do NOT support invoke continue to operate normally
|
|
336
|
+
under `NAC.click()` and `NAC.click_by_verb()`. Agents that call
|
|
337
|
+
`NAC.invoke()` against a host without an `actions[].payload_schema`
|
|
338
|
+
entry will still receive a `request_id` but the runtime cannot
|
|
339
|
+
guarantee delivery; the timeout fires after 30 s.
|
|
340
|
+
|
|
341
|
+
#### Why this matters
|
|
342
|
+
|
|
343
|
+
The full agentic surface stops being "list of buttons" and
|
|
344
|
+
becomes "list of buttons + structured inputs". A voice ad becomes
|
|
345
|
+
NAC.invoke-able. A search bar becomes NAC.invoke-able. A
|
|
346
|
+
file upload becomes NAC.invoke-able. Same protocol, same
|
|
347
|
+
provenance, same ack semantics.
|
|
348
|
+
|
|
349
|
+
The first reference adopter is **Atlas Pro** -- its
|
|
350
|
+
`atlas_pro_ad.mic` element declares both `listen` (click-only,
|
|
351
|
+
existing) and `utter` (payload-bearing) verbs. The same
|
|
352
|
+
`/parse` + `/tts` conversational loop drives in either case;
|
|
353
|
+
agents that have STT call `listen`, agents that have their own
|
|
354
|
+
language model call `utter`.
|
|
355
|
+
|
|
356
|
+
#### Forward modalities (anticipated, no spec change required)
|
|
357
|
+
|
|
358
|
+
`invoke` is intentionally modality-agnostic so future input
|
|
359
|
+
families plug in without breaking the contract:
|
|
360
|
+
|
|
361
|
+
| Modality | Verb (sketch) | Payload (sketch) |
|
|
362
|
+
|----------|-----------------------|--------------------------------------------------|
|
|
363
|
+
| Text | `utter` | `{text, lang?}` |
|
|
364
|
+
| Search | `search` | `{query, scope?, limit?}` |
|
|
365
|
+
| File | `upload` | `{filename, mime, data_url \| stream_id}` |
|
|
366
|
+
| Image | `analyze_image` | `{image_url \| data_url, prompt?}` |
|
|
367
|
+
| Video | `analyze_stream` | `{stream_url, frame_window_ms?, return?}` |
|
|
368
|
+
| Schedule | `schedule` | `{datetime, duration_min, attendees?}` |
|
|
369
|
+
| Code | `apply_diff` | `{file_path, unified_diff}` |
|
|
370
|
+
| Voice | `transcribe` | `{audio_url \| data_url, lang?}` |
|
|
371
|
+
|
|
372
|
+
Each modality follows the same `nac:action:requested` ->
|
|
373
|
+
`nac:action:succeeded` / `:failed` event protocol, the same
|
|
374
|
+
`request_id` correlation, the same timeout semantics. The
|
|
375
|
+
runtime stays small; the verb vocabulary grows by convention
|
|
376
|
+
between hosts and agents. Ergonomic shortcuts (`NAC.utter`,
|
|
377
|
+
`NAC.search`, `NAC.watch`, etc.) can be added later without
|
|
378
|
+
re-spec because each is a thin wrapper over `invoke`.
|
|
379
|
+
|
|
235
380
|
### 5.1.2 Strict validation flag (v2.2)
|
|
236
381
|
|
|
237
382
|
`NAC.STRICT_VALIDATION` (boolean, default `false` in v2.2). When
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// NAC CLI v2.
|
|
2
|
+
// NAC CLI v2.3.0-alpha.1
|
|
3
3
|
// Usage:
|
|
4
4
|
// nac validate <url-or-dir> [--severity=error|warn|info]
|
|
5
5
|
// nac --version
|
|
@@ -18,7 +18,7 @@ const args = process.argv.slice(2);
|
|
|
18
18
|
const cmd = args[0];
|
|
19
19
|
|
|
20
20
|
function showHelp() {
|
|
21
|
-
console.log('NAC CLI v2.
|
|
21
|
+
console.log('NAC CLI v2.3.0-alpha.1');
|
|
22
22
|
console.log('');
|
|
23
23
|
console.log('Usage:');
|
|
24
24
|
console.log(' nac validate <url-or-dir> [--severity=error|warn|info]');
|
|
@@ -27,7 +27,7 @@ function showHelp() {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function showVersion() {
|
|
30
|
-
console.log('@nac3/runtime CLI 2.
|
|
30
|
+
console.log('@nac3/runtime CLI 2.3.0-alpha.1 (Native Agent Contract v2.3)');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
if (!cmd || cmd === '--help' || cmd === '-h') { showHelp(); process.exit(0); }
|
|
@@ -213,19 +213,23 @@
|
|
|
213
213
|
botSpeak(isYes ? 'Confirmado.' : 'Cancelado.', { skipBubble: true });
|
|
214
214
|
return true;
|
|
215
215
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
216
|
+
/* v2.2.1: guard browser-only listener so this bundle is importable in
|
|
217
|
+
Node / SSR / test contexts without crashing. */
|
|
218
|
+
if (typeof document !== 'undefined') {
|
|
219
|
+
document.addEventListener('nac:confirm:requested', function (e) {
|
|
220
|
+
try {
|
|
221
|
+
var prompt = (e && e.detail && e.detail.prompt) || '';
|
|
222
|
+
if (!prompt) return;
|
|
223
|
+
var hints = {
|
|
224
|
+
es: 'Decime si o no.', en: 'Say yes or no.', pt: 'Diga sim ou nao.',
|
|
225
|
+
fr: 'Dites oui ou non.', it: 'Dimmi si o no.', de: 'Sag ja oder nein.',
|
|
226
|
+
ja: 'はい か いいえ で答えて。', zh: '请说 是 或 否。',
|
|
227
|
+
hi: 'haan ya nahin.', ar: 'قل نعم او لا.'
|
|
228
|
+
};
|
|
229
|
+
botSpeak(prompt + ' ' + (hints[NacChat._lang] || hints.es), { skipBubble: true });
|
|
230
|
+
} catch (_) {}
|
|
231
|
+
}, true);
|
|
232
|
+
}
|
|
229
233
|
|
|
230
234
|
/* ---------- Locale switch (fix C7-bis) ---------- */
|
|
231
235
|
function _maybeChangeLocaleLocally(text) {
|
package/dist/nac-chat-client.cjs
CHANGED
|
@@ -214,19 +214,23 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
214
214
|
botSpeak(isYes ? 'Confirmado.' : 'Cancelado.', { skipBubble: true });
|
|
215
215
|
return true;
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
217
|
+
/* v2.2.1: guard browser-only listener so this bundle is importable in
|
|
218
|
+
Node / SSR / test contexts without crashing. */
|
|
219
|
+
if (typeof document !== 'undefined') {
|
|
220
|
+
document.addEventListener('nac:confirm:requested', function (e) {
|
|
221
|
+
try {
|
|
222
|
+
var prompt = (e && e.detail && e.detail.prompt) || '';
|
|
223
|
+
if (!prompt) return;
|
|
224
|
+
var hints = {
|
|
225
|
+
es: 'Decime si o no.', en: 'Say yes or no.', pt: 'Diga sim ou nao.',
|
|
226
|
+
fr: 'Dites oui ou non.', it: 'Dimmi si o no.', de: 'Sag ja oder nein.',
|
|
227
|
+
ja: 'はい か いいえ で答えて。', zh: '请说 是 或 否。',
|
|
228
|
+
hi: 'haan ya nahin.', ar: 'قل نعم او لا.'
|
|
229
|
+
};
|
|
230
|
+
botSpeak(prompt + ' ' + (hints[NacChat._lang] || hints.es), { skipBubble: true });
|
|
231
|
+
} catch (_) {}
|
|
232
|
+
}, true);
|
|
233
|
+
}
|
|
230
234
|
|
|
231
235
|
/* ---------- Locale switch (fix C7-bis) ---------- */
|
|
232
236
|
function _maybeChangeLocaleLocally(text) {
|
package/dist/nac-chat-client.mjs
CHANGED
|
@@ -214,19 +214,23 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
214
214
|
botSpeak(isYes ? 'Confirmado.' : 'Cancelado.', { skipBubble: true });
|
|
215
215
|
return true;
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
217
|
+
/* v2.2.1: guard browser-only listener so this bundle is importable in
|
|
218
|
+
Node / SSR / test contexts without crashing. */
|
|
219
|
+
if (typeof document !== 'undefined') {
|
|
220
|
+
document.addEventListener('nac:confirm:requested', function (e) {
|
|
221
|
+
try {
|
|
222
|
+
var prompt = (e && e.detail && e.detail.prompt) || '';
|
|
223
|
+
if (!prompt) return;
|
|
224
|
+
var hints = {
|
|
225
|
+
es: 'Decime si o no.', en: 'Say yes or no.', pt: 'Diga sim ou nao.',
|
|
226
|
+
fr: 'Dites oui ou non.', it: 'Dimmi si o no.', de: 'Sag ja oder nein.',
|
|
227
|
+
ja: 'はい か いいえ で答えて。', zh: '请说 是 或 否。',
|
|
228
|
+
hi: 'haan ya nahin.', ar: 'قل نعم او لا.'
|
|
229
|
+
};
|
|
230
|
+
botSpeak(prompt + ' ' + (hints[NacChat._lang] || hints.es), { skipBubble: true });
|
|
231
|
+
} catch (_) {}
|
|
232
|
+
}, true);
|
|
233
|
+
}
|
|
230
234
|
|
|
231
235
|
/* ---------- Locale switch (fix C7-bis) ---------- */
|
|
232
236
|
function _maybeChangeLocaleLocally(text) {
|
|
@@ -222,10 +222,14 @@
|
|
|
222
222
|
document.addEventListener(n, handler, { capture: true, passive: true });
|
|
223
223
|
});
|
|
224
224
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
/* v2.2.1: guard browser-only DOM hookup so this bundle is
|
|
226
|
+
importable in Node / SSR / test contexts. */
|
|
227
|
+
if (typeof document !== 'undefined') {
|
|
228
|
+
if (document.readyState === 'loading') {
|
|
229
|
+
document.addEventListener('DOMContentLoaded', _captureGestureFromDom);
|
|
230
|
+
} else {
|
|
231
|
+
_captureGestureFromDom();
|
|
232
|
+
}
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
/* v2.0-rc3: _readGestureAttested now requires the element being
|
|
@@ -2089,8 +2093,12 @@
|
|
|
2089
2093
|
NAC.version_v2 = '2.1.0-rc1';
|
|
2090
2094
|
NAC.spec_version_v2 = '2.1';
|
|
2091
2095
|
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2096
|
+
/* v2.2.1: guard browser-only dispatch so this bundle is importable
|
|
2097
|
+
in Node / SSR / test contexts. */
|
|
2098
|
+
if (typeof document !== 'undefined') {
|
|
2099
|
+
document.dispatchEvent(new CustomEvent('nac:v2_installed', {
|
|
2100
|
+
detail: { version: '2.0.0' }, bubbles: true
|
|
2101
|
+
}));
|
|
2102
|
+
}
|
|
2095
2103
|
})(typeof window !== 'undefined' ? window : globalThis);
|
|
2096
2104
|
|
|
@@ -223,10 +223,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
223
223
|
document.addEventListener(n, handler, { capture: true, passive: true });
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
/* v2.2.1: guard browser-only DOM hookup so this bundle is
|
|
227
|
+
importable in Node / SSR / test contexts. */
|
|
228
|
+
if (typeof document !== 'undefined') {
|
|
229
|
+
if (document.readyState === 'loading') {
|
|
230
|
+
document.addEventListener('DOMContentLoaded', _captureGestureFromDom);
|
|
231
|
+
} else {
|
|
232
|
+
_captureGestureFromDom();
|
|
233
|
+
}
|
|
230
234
|
}
|
|
231
235
|
|
|
232
236
|
/* v2.0-rc3: _readGestureAttested now requires the element being
|
|
@@ -2090,9 +2094,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2090
2094
|
NAC.version_v2 = '2.1.0-rc1';
|
|
2091
2095
|
NAC.spec_version_v2 = '2.1';
|
|
2092
2096
|
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2097
|
+
/* v2.2.1: guard browser-only dispatch so this bundle is importable
|
|
2098
|
+
in Node / SSR / test contexts. */
|
|
2099
|
+
if (typeof document !== 'undefined') {
|
|
2100
|
+
document.dispatchEvent(new CustomEvent('nac:v2_installed', {
|
|
2101
|
+
detail: { version: '2.0.0' }, bubbles: true
|
|
2102
|
+
}));
|
|
2103
|
+
}
|
|
2096
2104
|
})(typeof window !== 'undefined' ? window : globalThis);
|
|
2097
2105
|
|
|
2098
2106
|
module.exports = _g.NAC || _g.NACv2 || _g.NacChat;
|
|
@@ -223,10 +223,14 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
223
223
|
document.addEventListener(n, handler, { capture: true, passive: true });
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
/* v2.2.1: guard browser-only DOM hookup so this bundle is
|
|
227
|
+
importable in Node / SSR / test contexts. */
|
|
228
|
+
if (typeof document !== 'undefined') {
|
|
229
|
+
if (document.readyState === 'loading') {
|
|
230
|
+
document.addEventListener('DOMContentLoaded', _captureGestureFromDom);
|
|
231
|
+
} else {
|
|
232
|
+
_captureGestureFromDom();
|
|
233
|
+
}
|
|
230
234
|
}
|
|
231
235
|
|
|
232
236
|
/* v2.0-rc3: _readGestureAttested now requires the element being
|
|
@@ -2090,9 +2094,13 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2090
2094
|
NAC.version_v2 = '2.1.0-rc1';
|
|
2091
2095
|
NAC.spec_version_v2 = '2.1';
|
|
2092
2096
|
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2097
|
+
/* v2.2.1: guard browser-only dispatch so this bundle is importable
|
|
2098
|
+
in Node / SSR / test contexts. */
|
|
2099
|
+
if (typeof document !== 'undefined') {
|
|
2100
|
+
document.dispatchEvent(new CustomEvent('nac:v2_installed', {
|
|
2101
|
+
detail: { version: '2.0.0' }, bubbles: true
|
|
2102
|
+
}));
|
|
2103
|
+
}
|
|
2096
2104
|
})(typeof window !== 'undefined' ? window : globalThis);
|
|
2097
2105
|
|
|
2098
2106
|
export default _g.NAC || _g.NACv2 || _g.NacChat || _g[Object.keys(_g).find(k => /^NA[Cc]/.test(k))];
|
package/dist/nac.browser.js
CHANGED
|
@@ -2208,6 +2208,157 @@
|
|
|
2208
2208
|
targetPlugin ? { plugin: targetPlugin } : {}));
|
|
2209
2209
|
}
|
|
2210
2210
|
|
|
2211
|
+
/* ============================================================
|
|
2212
|
+
v2.3.0 -- NAC.invoke / NAC.utter (action payload contract)
|
|
2213
|
+
============================================================
|
|
2214
|
+
NAC v2.2 actions are click-and-go: NAC.click(id) /
|
|
2215
|
+
NAC.click_by_verb(plugin, verb) trigger a click; the host
|
|
2216
|
+
handles it; the runtime polls for nac:action:succeeded.
|
|
2217
|
+
|
|
2218
|
+
This works for verb-and-state actions (save, cancel, delete)
|
|
2219
|
+
but collapses when the action needs DATA from the agent:
|
|
2220
|
+
utter(text), search(query), send_message(body), upload(file),
|
|
2221
|
+
schedule(date), translate(text, target_lang). The host has
|
|
2222
|
+
no way to receive the agent's payload via a synthetic click.
|
|
2223
|
+
|
|
2224
|
+
v2.3 closes this gap. NAC.invoke(action_id, payload) dispatches
|
|
2225
|
+
a 'nac:action:requested' CustomEvent on the host element with
|
|
2226
|
+
the payload + a correlation request_id. The host listens,
|
|
2227
|
+
processes, and emits 'nac:action:succeeded' (or :failed) with
|
|
2228
|
+
the matching request_id. The runtime resolves the Promise.
|
|
2229
|
+
|
|
2230
|
+
Click-style verbs continue to work unchanged via click() /
|
|
2231
|
+
click_by_verb(). invoke is purely additive.
|
|
2232
|
+
|
|
2233
|
+
Atlas Pro is the reference adopter: its 'utter' verb on
|
|
2234
|
+
'atlas_pro_ad.mic' accepts {text, lang} and routes into the
|
|
2235
|
+
existing /parse + /tts conversational loop. */
|
|
2236
|
+
|
|
2237
|
+
async function invoke(action_id, payload, opts) {
|
|
2238
|
+
if (!action_id || typeof action_id !== 'string') {
|
|
2239
|
+
throw NacError('invalid', 'invoke requires an action_id');
|
|
2240
|
+
}
|
|
2241
|
+
if (payload == null || typeof payload !== 'object') {
|
|
2242
|
+
throw NacError('invalid', 'invoke requires a payload object');
|
|
2243
|
+
}
|
|
2244
|
+
const el = _findElement(action_id, opts);
|
|
2245
|
+
if (!el) {
|
|
2246
|
+
_emitCommandRejected({
|
|
2247
|
+
command_method: 'invoke',
|
|
2248
|
+
command_target: action_id,
|
|
2249
|
+
reason: 'not_found',
|
|
2250
|
+
message: 'No element with nac_id=' + action_id,
|
|
2251
|
+
source: (opts && opts.source) || undefined,
|
|
2252
|
+
});
|
|
2253
|
+
throw NacError('not_found', 'No element with nac_id=' + action_id);
|
|
2254
|
+
}
|
|
2255
|
+
/* invoke deliberately does NOT enforce visibility -- the
|
|
2256
|
+
canonical use case is a mic / search / upload widget that
|
|
2257
|
+
may live outside the visible viewport but is still a valid
|
|
2258
|
+
NAC target (the agent never had to "see" it to use it).
|
|
2259
|
+
Disabled state is still respected. */
|
|
2260
|
+
if (el.disabled || el.getAttribute('aria-disabled') === 'true') {
|
|
2261
|
+
_emitCommandRejected({
|
|
2262
|
+
command_method: 'invoke',
|
|
2263
|
+
command_target: action_id,
|
|
2264
|
+
reason: 'disabled',
|
|
2265
|
+
message: 'Element ' + action_id + ' is disabled',
|
|
2266
|
+
source: (opts && opts.source) || undefined,
|
|
2267
|
+
});
|
|
2268
|
+
throw NacError('disabled', 'Element ' + action_id + ' is disabled');
|
|
2269
|
+
}
|
|
2270
|
+
const verb = (payload && payload.verb)
|
|
2271
|
+
|| el.getAttribute('data-nac-action')
|
|
2272
|
+
|| '';
|
|
2273
|
+
const pluginRoot = el.closest('[data-nac-plugin]');
|
|
2274
|
+
const plugin = pluginRoot
|
|
2275
|
+
? pluginRoot.getAttribute('data-nac-plugin')
|
|
2276
|
+
: null;
|
|
2277
|
+
const request_id = 'nac_inv_'
|
|
2278
|
+
+ Math.random().toString(36).slice(2, 12)
|
|
2279
|
+
+ '_' + Date.now();
|
|
2280
|
+
const timeout_ms = (opts && opts.timeout) || 30000;
|
|
2281
|
+
|
|
2282
|
+
const result = new Promise(function (resolve, reject) {
|
|
2283
|
+
let settled = false;
|
|
2284
|
+
function matchesReq(e) {
|
|
2285
|
+
return e && e.detail && e.detail.request_id === request_id;
|
|
2286
|
+
}
|
|
2287
|
+
function onSucceeded(e) {
|
|
2288
|
+
if (settled) return;
|
|
2289
|
+
if (!matchesReq(e)) return;
|
|
2290
|
+
settled = true;
|
|
2291
|
+
cleanup();
|
|
2292
|
+
resolve({
|
|
2293
|
+
ok: true,
|
|
2294
|
+
request_id: request_id,
|
|
2295
|
+
ack: e.detail || null,
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
function onFailed(e) {
|
|
2299
|
+
if (settled) return;
|
|
2300
|
+
if (!matchesReq(e)) return;
|
|
2301
|
+
settled = true;
|
|
2302
|
+
cleanup();
|
|
2303
|
+
const code = (e.detail && e.detail.error) || 'failed';
|
|
2304
|
+
reject(NacError(code,
|
|
2305
|
+
'invoke failed for ' + action_id
|
|
2306
|
+
+ ((e.detail && e.detail.message) ? ': ' + e.detail.message : '')));
|
|
2307
|
+
}
|
|
2308
|
+
const timer = setTimeout(function () {
|
|
2309
|
+
if (settled) return;
|
|
2310
|
+
settled = true;
|
|
2311
|
+
cleanup();
|
|
2312
|
+
reject(NacError('timeout',
|
|
2313
|
+
'invoke timeout after ' + timeout_ms + 'ms for ' + action_id));
|
|
2314
|
+
}, timeout_ms);
|
|
2315
|
+
function cleanup() {
|
|
2316
|
+
document.removeEventListener('nac:action:succeeded', onSucceeded);
|
|
2317
|
+
document.removeEventListener('nac:action:failed', onFailed);
|
|
2318
|
+
clearTimeout(timer);
|
|
2319
|
+
}
|
|
2320
|
+
document.addEventListener('nac:action:succeeded', onSucceeded);
|
|
2321
|
+
document.addEventListener('nac:action:failed', onFailed);
|
|
2322
|
+
});
|
|
2323
|
+
|
|
2324
|
+
/* Dispatch the request event. Bubbles so the host can listen
|
|
2325
|
+
on document if it prefers a single handler for all actions
|
|
2326
|
+
(matches how the existing :succeeded / :failed contracts
|
|
2327
|
+
work today). detail.payload is opaque to the runtime; only
|
|
2328
|
+
the host knows what shape to expect for its own verb. */
|
|
2329
|
+
el.dispatchEvent(new CustomEvent('nac:action:requested', {
|
|
2330
|
+
bubbles: true,
|
|
2331
|
+
detail: {
|
|
2332
|
+
action_id: action_id,
|
|
2333
|
+
verb: verb,
|
|
2334
|
+
payload: payload,
|
|
2335
|
+
plugin: plugin,
|
|
2336
|
+
request_id: request_id,
|
|
2337
|
+
ts: Date.now(),
|
|
2338
|
+
},
|
|
2339
|
+
}));
|
|
2340
|
+
|
|
2341
|
+
return result;
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
/* Ergonomic shortcut for the most common payload-bearing verb.
|
|
2345
|
+
Equivalent to invoke(id, {verb:'utter', text, lang, voice}). */
|
|
2346
|
+
async function utter(action_id, opts) {
|
|
2347
|
+
if (!opts || typeof opts !== 'object') {
|
|
2348
|
+
throw NacError('invalid', 'utter requires an opts object with at least "text"');
|
|
2349
|
+
}
|
|
2350
|
+
if (!opts.text || typeof opts.text !== 'string') {
|
|
2351
|
+
throw NacError('invalid', 'utter requires opts.text (string)');
|
|
2352
|
+
}
|
|
2353
|
+
return await invoke(action_id, {
|
|
2354
|
+
verb: 'utter',
|
|
2355
|
+
text: opts.text,
|
|
2356
|
+
lang: opts.lang || null,
|
|
2357
|
+
voice: opts.voice || null,
|
|
2358
|
+
metadata: opts.metadata || null,
|
|
2359
|
+
}, opts);
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2211
2362
|
async function tab_by_label(plugin, label, opts) {
|
|
2212
2363
|
if (!label) throw NacError('invalid', 'tab_by_label requires a label');
|
|
2213
2364
|
const targetPlugin = plugin || _activePlugin();
|
|
@@ -5007,8 +5158,8 @@
|
|
|
5007
5158
|
|
|
5008
5159
|
global.NAC = {
|
|
5009
5160
|
__nac_v1_installed: true,
|
|
5010
|
-
version: '2.
|
|
5011
|
-
spec_version: '2.
|
|
5161
|
+
version: '2.3.0-alpha.1',
|
|
5162
|
+
spec_version: '2.3',
|
|
5012
5163
|
/* v2.2.0 (V22-01) -- strict validation toggle. When true,
|
|
5013
5164
|
NAC.register throws on findings (manifest_role_unknown,
|
|
5014
5165
|
tab_id_manifest_role_drift, manifest_dom_role_mismatch).
|
|
@@ -5055,6 +5206,15 @@
|
|
|
5055
5206
|
/* v1.4.1 -- voice/agent ergonomic helpers */
|
|
5056
5207
|
click_by_verb: click_by_verb,
|
|
5057
5208
|
tab_by_label: tab_by_label,
|
|
5209
|
+
/* v2.3.0 -- payload-bearing actions. invoke() is the generic
|
|
5210
|
+
primitive: dispatches nac:action:requested with the agent's
|
|
5211
|
+
payload and resolves on nac:action:succeeded/:failed matching
|
|
5212
|
+
the request_id. utter() is the ergonomic shortcut for the
|
|
5213
|
+
conversational verb pattern (the first concrete adopter is
|
|
5214
|
+
Atlas Pro's mic). Both are additive on top of click()/click_by_verb()
|
|
5215
|
+
and do not change existing demo behaviour. */
|
|
5216
|
+
invoke: invoke,
|
|
5217
|
+
utter: utter,
|
|
5058
5218
|
/* utility */
|
|
5059
5219
|
wait_for: wait_for,
|
|
5060
5220
|
screenshot: screenshot,
|
|
@@ -5193,15 +5353,19 @@
|
|
|
5193
5353
|
NacError: NacError,
|
|
5194
5354
|
};
|
|
5195
5355
|
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5356
|
+
/* v2.2.1: guard browser-only init so this module is importable in
|
|
5357
|
+
Node / SSR / test contexts without crashing. */
|
|
5358
|
+
if (typeof document !== 'undefined') {
|
|
5359
|
+
document.dispatchEvent(new CustomEvent('nac:installed', {
|
|
5360
|
+
detail: { version: global.NAC.version, spec: global.NAC.spec_version },
|
|
5361
|
+
}));
|
|
5199
5362
|
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5363
|
+
/* v1.9.0: install the ARIA bridge for data-nac-a11y-hint so
|
|
5364
|
+
screen readers actually consume the hints today (sec 3.1).
|
|
5365
|
+
Runs after install so existing host-level aria-describedby
|
|
5366
|
+
values are preserved (we append, not overwrite). */
|
|
5367
|
+
_installA11yHintBridge();
|
|
5368
|
+
}
|
|
5205
5369
|
|
|
5206
5370
|
/* v1.9.0: auto-replay any window.__NAC_PENDING__ buffer the
|
|
5207
5371
|
host staged before the runtime loaded (sec 13.11). The host
|
package/dist/nac.cjs
CHANGED
|
@@ -2209,6 +2209,157 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2209
2209
|
targetPlugin ? { plugin: targetPlugin } : {}));
|
|
2210
2210
|
}
|
|
2211
2211
|
|
|
2212
|
+
/* ============================================================
|
|
2213
|
+
v2.3.0 -- NAC.invoke / NAC.utter (action payload contract)
|
|
2214
|
+
============================================================
|
|
2215
|
+
NAC v2.2 actions are click-and-go: NAC.click(id) /
|
|
2216
|
+
NAC.click_by_verb(plugin, verb) trigger a click; the host
|
|
2217
|
+
handles it; the runtime polls for nac:action:succeeded.
|
|
2218
|
+
|
|
2219
|
+
This works for verb-and-state actions (save, cancel, delete)
|
|
2220
|
+
but collapses when the action needs DATA from the agent:
|
|
2221
|
+
utter(text), search(query), send_message(body), upload(file),
|
|
2222
|
+
schedule(date), translate(text, target_lang). The host has
|
|
2223
|
+
no way to receive the agent's payload via a synthetic click.
|
|
2224
|
+
|
|
2225
|
+
v2.3 closes this gap. NAC.invoke(action_id, payload) dispatches
|
|
2226
|
+
a 'nac:action:requested' CustomEvent on the host element with
|
|
2227
|
+
the payload + a correlation request_id. The host listens,
|
|
2228
|
+
processes, and emits 'nac:action:succeeded' (or :failed) with
|
|
2229
|
+
the matching request_id. The runtime resolves the Promise.
|
|
2230
|
+
|
|
2231
|
+
Click-style verbs continue to work unchanged via click() /
|
|
2232
|
+
click_by_verb(). invoke is purely additive.
|
|
2233
|
+
|
|
2234
|
+
Atlas Pro is the reference adopter: its 'utter' verb on
|
|
2235
|
+
'atlas_pro_ad.mic' accepts {text, lang} and routes into the
|
|
2236
|
+
existing /parse + /tts conversational loop. */
|
|
2237
|
+
|
|
2238
|
+
async function invoke(action_id, payload, opts) {
|
|
2239
|
+
if (!action_id || typeof action_id !== 'string') {
|
|
2240
|
+
throw NacError('invalid', 'invoke requires an action_id');
|
|
2241
|
+
}
|
|
2242
|
+
if (payload == null || typeof payload !== 'object') {
|
|
2243
|
+
throw NacError('invalid', 'invoke requires a payload object');
|
|
2244
|
+
}
|
|
2245
|
+
const el = _findElement(action_id, opts);
|
|
2246
|
+
if (!el) {
|
|
2247
|
+
_emitCommandRejected({
|
|
2248
|
+
command_method: 'invoke',
|
|
2249
|
+
command_target: action_id,
|
|
2250
|
+
reason: 'not_found',
|
|
2251
|
+
message: 'No element with nac_id=' + action_id,
|
|
2252
|
+
source: (opts && opts.source) || undefined,
|
|
2253
|
+
});
|
|
2254
|
+
throw NacError('not_found', 'No element with nac_id=' + action_id);
|
|
2255
|
+
}
|
|
2256
|
+
/* invoke deliberately does NOT enforce visibility -- the
|
|
2257
|
+
canonical use case is a mic / search / upload widget that
|
|
2258
|
+
may live outside the visible viewport but is still a valid
|
|
2259
|
+
NAC target (the agent never had to "see" it to use it).
|
|
2260
|
+
Disabled state is still respected. */
|
|
2261
|
+
if (el.disabled || el.getAttribute('aria-disabled') === 'true') {
|
|
2262
|
+
_emitCommandRejected({
|
|
2263
|
+
command_method: 'invoke',
|
|
2264
|
+
command_target: action_id,
|
|
2265
|
+
reason: 'disabled',
|
|
2266
|
+
message: 'Element ' + action_id + ' is disabled',
|
|
2267
|
+
source: (opts && opts.source) || undefined,
|
|
2268
|
+
});
|
|
2269
|
+
throw NacError('disabled', 'Element ' + action_id + ' is disabled');
|
|
2270
|
+
}
|
|
2271
|
+
const verb = (payload && payload.verb)
|
|
2272
|
+
|| el.getAttribute('data-nac-action')
|
|
2273
|
+
|| '';
|
|
2274
|
+
const pluginRoot = el.closest('[data-nac-plugin]');
|
|
2275
|
+
const plugin = pluginRoot
|
|
2276
|
+
? pluginRoot.getAttribute('data-nac-plugin')
|
|
2277
|
+
: null;
|
|
2278
|
+
const request_id = 'nac_inv_'
|
|
2279
|
+
+ Math.random().toString(36).slice(2, 12)
|
|
2280
|
+
+ '_' + Date.now();
|
|
2281
|
+
const timeout_ms = (opts && opts.timeout) || 30000;
|
|
2282
|
+
|
|
2283
|
+
const result = new Promise(function (resolve, reject) {
|
|
2284
|
+
let settled = false;
|
|
2285
|
+
function matchesReq(e) {
|
|
2286
|
+
return e && e.detail && e.detail.request_id === request_id;
|
|
2287
|
+
}
|
|
2288
|
+
function onSucceeded(e) {
|
|
2289
|
+
if (settled) return;
|
|
2290
|
+
if (!matchesReq(e)) return;
|
|
2291
|
+
settled = true;
|
|
2292
|
+
cleanup();
|
|
2293
|
+
resolve({
|
|
2294
|
+
ok: true,
|
|
2295
|
+
request_id: request_id,
|
|
2296
|
+
ack: e.detail || null,
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
function onFailed(e) {
|
|
2300
|
+
if (settled) return;
|
|
2301
|
+
if (!matchesReq(e)) return;
|
|
2302
|
+
settled = true;
|
|
2303
|
+
cleanup();
|
|
2304
|
+
const code = (e.detail && e.detail.error) || 'failed';
|
|
2305
|
+
reject(NacError(code,
|
|
2306
|
+
'invoke failed for ' + action_id
|
|
2307
|
+
+ ((e.detail && e.detail.message) ? ': ' + e.detail.message : '')));
|
|
2308
|
+
}
|
|
2309
|
+
const timer = setTimeout(function () {
|
|
2310
|
+
if (settled) return;
|
|
2311
|
+
settled = true;
|
|
2312
|
+
cleanup();
|
|
2313
|
+
reject(NacError('timeout',
|
|
2314
|
+
'invoke timeout after ' + timeout_ms + 'ms for ' + action_id));
|
|
2315
|
+
}, timeout_ms);
|
|
2316
|
+
function cleanup() {
|
|
2317
|
+
document.removeEventListener('nac:action:succeeded', onSucceeded);
|
|
2318
|
+
document.removeEventListener('nac:action:failed', onFailed);
|
|
2319
|
+
clearTimeout(timer);
|
|
2320
|
+
}
|
|
2321
|
+
document.addEventListener('nac:action:succeeded', onSucceeded);
|
|
2322
|
+
document.addEventListener('nac:action:failed', onFailed);
|
|
2323
|
+
});
|
|
2324
|
+
|
|
2325
|
+
/* Dispatch the request event. Bubbles so the host can listen
|
|
2326
|
+
on document if it prefers a single handler for all actions
|
|
2327
|
+
(matches how the existing :succeeded / :failed contracts
|
|
2328
|
+
work today). detail.payload is opaque to the runtime; only
|
|
2329
|
+
the host knows what shape to expect for its own verb. */
|
|
2330
|
+
el.dispatchEvent(new CustomEvent('nac:action:requested', {
|
|
2331
|
+
bubbles: true,
|
|
2332
|
+
detail: {
|
|
2333
|
+
action_id: action_id,
|
|
2334
|
+
verb: verb,
|
|
2335
|
+
payload: payload,
|
|
2336
|
+
plugin: plugin,
|
|
2337
|
+
request_id: request_id,
|
|
2338
|
+
ts: Date.now(),
|
|
2339
|
+
},
|
|
2340
|
+
}));
|
|
2341
|
+
|
|
2342
|
+
return result;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
/* Ergonomic shortcut for the most common payload-bearing verb.
|
|
2346
|
+
Equivalent to invoke(id, {verb:'utter', text, lang, voice}). */
|
|
2347
|
+
async function utter(action_id, opts) {
|
|
2348
|
+
if (!opts || typeof opts !== 'object') {
|
|
2349
|
+
throw NacError('invalid', 'utter requires an opts object with at least "text"');
|
|
2350
|
+
}
|
|
2351
|
+
if (!opts.text || typeof opts.text !== 'string') {
|
|
2352
|
+
throw NacError('invalid', 'utter requires opts.text (string)');
|
|
2353
|
+
}
|
|
2354
|
+
return await invoke(action_id, {
|
|
2355
|
+
verb: 'utter',
|
|
2356
|
+
text: opts.text,
|
|
2357
|
+
lang: opts.lang || null,
|
|
2358
|
+
voice: opts.voice || null,
|
|
2359
|
+
metadata: opts.metadata || null,
|
|
2360
|
+
}, opts);
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2212
2363
|
async function tab_by_label(plugin, label, opts) {
|
|
2213
2364
|
if (!label) throw NacError('invalid', 'tab_by_label requires a label');
|
|
2214
2365
|
const targetPlugin = plugin || _activePlugin();
|
|
@@ -5008,8 +5159,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
5008
5159
|
|
|
5009
5160
|
global.NAC = {
|
|
5010
5161
|
__nac_v1_installed: true,
|
|
5011
|
-
version: '2.
|
|
5012
|
-
spec_version: '2.
|
|
5162
|
+
version: '2.3.0-alpha.1',
|
|
5163
|
+
spec_version: '2.3',
|
|
5013
5164
|
/* v2.2.0 (V22-01) -- strict validation toggle. When true,
|
|
5014
5165
|
NAC.register throws on findings (manifest_role_unknown,
|
|
5015
5166
|
tab_id_manifest_role_drift, manifest_dom_role_mismatch).
|
|
@@ -5056,6 +5207,15 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
5056
5207
|
/* v1.4.1 -- voice/agent ergonomic helpers */
|
|
5057
5208
|
click_by_verb: click_by_verb,
|
|
5058
5209
|
tab_by_label: tab_by_label,
|
|
5210
|
+
/* v2.3.0 -- payload-bearing actions. invoke() is the generic
|
|
5211
|
+
primitive: dispatches nac:action:requested with the agent's
|
|
5212
|
+
payload and resolves on nac:action:succeeded/:failed matching
|
|
5213
|
+
the request_id. utter() is the ergonomic shortcut for the
|
|
5214
|
+
conversational verb pattern (the first concrete adopter is
|
|
5215
|
+
Atlas Pro's mic). Both are additive on top of click()/click_by_verb()
|
|
5216
|
+
and do not change existing demo behaviour. */
|
|
5217
|
+
invoke: invoke,
|
|
5218
|
+
utter: utter,
|
|
5059
5219
|
/* utility */
|
|
5060
5220
|
wait_for: wait_for,
|
|
5061
5221
|
screenshot: screenshot,
|
|
@@ -5194,15 +5354,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
5194
5354
|
NacError: NacError,
|
|
5195
5355
|
};
|
|
5196
5356
|
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5357
|
+
/* v2.2.1: guard browser-only init so this module is importable in
|
|
5358
|
+
Node / SSR / test contexts without crashing. */
|
|
5359
|
+
if (typeof document !== 'undefined') {
|
|
5360
|
+
document.dispatchEvent(new CustomEvent('nac:installed', {
|
|
5361
|
+
detail: { version: global.NAC.version, spec: global.NAC.spec_version },
|
|
5362
|
+
}));
|
|
5200
5363
|
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5364
|
+
/* v1.9.0: install the ARIA bridge for data-nac-a11y-hint so
|
|
5365
|
+
screen readers actually consume the hints today (sec 3.1).
|
|
5366
|
+
Runs after install so existing host-level aria-describedby
|
|
5367
|
+
values are preserved (we append, not overwrite). */
|
|
5368
|
+
_installA11yHintBridge();
|
|
5369
|
+
}
|
|
5206
5370
|
|
|
5207
5371
|
/* v1.9.0: auto-replay any window.__NAC_PENDING__ buffer the
|
|
5208
5372
|
host staged before the runtime loaded (sec 13.11). The host
|
package/dist/nac.mjs
CHANGED
|
@@ -2209,6 +2209,157 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
2209
2209
|
targetPlugin ? { plugin: targetPlugin } : {}));
|
|
2210
2210
|
}
|
|
2211
2211
|
|
|
2212
|
+
/* ============================================================
|
|
2213
|
+
v2.3.0 -- NAC.invoke / NAC.utter (action payload contract)
|
|
2214
|
+
============================================================
|
|
2215
|
+
NAC v2.2 actions are click-and-go: NAC.click(id) /
|
|
2216
|
+
NAC.click_by_verb(plugin, verb) trigger a click; the host
|
|
2217
|
+
handles it; the runtime polls for nac:action:succeeded.
|
|
2218
|
+
|
|
2219
|
+
This works for verb-and-state actions (save, cancel, delete)
|
|
2220
|
+
but collapses when the action needs DATA from the agent:
|
|
2221
|
+
utter(text), search(query), send_message(body), upload(file),
|
|
2222
|
+
schedule(date), translate(text, target_lang). The host has
|
|
2223
|
+
no way to receive the agent's payload via a synthetic click.
|
|
2224
|
+
|
|
2225
|
+
v2.3 closes this gap. NAC.invoke(action_id, payload) dispatches
|
|
2226
|
+
a 'nac:action:requested' CustomEvent on the host element with
|
|
2227
|
+
the payload + a correlation request_id. The host listens,
|
|
2228
|
+
processes, and emits 'nac:action:succeeded' (or :failed) with
|
|
2229
|
+
the matching request_id. The runtime resolves the Promise.
|
|
2230
|
+
|
|
2231
|
+
Click-style verbs continue to work unchanged via click() /
|
|
2232
|
+
click_by_verb(). invoke is purely additive.
|
|
2233
|
+
|
|
2234
|
+
Atlas Pro is the reference adopter: its 'utter' verb on
|
|
2235
|
+
'atlas_pro_ad.mic' accepts {text, lang} and routes into the
|
|
2236
|
+
existing /parse + /tts conversational loop. */
|
|
2237
|
+
|
|
2238
|
+
async function invoke(action_id, payload, opts) {
|
|
2239
|
+
if (!action_id || typeof action_id !== 'string') {
|
|
2240
|
+
throw NacError('invalid', 'invoke requires an action_id');
|
|
2241
|
+
}
|
|
2242
|
+
if (payload == null || typeof payload !== 'object') {
|
|
2243
|
+
throw NacError('invalid', 'invoke requires a payload object');
|
|
2244
|
+
}
|
|
2245
|
+
const el = _findElement(action_id, opts);
|
|
2246
|
+
if (!el) {
|
|
2247
|
+
_emitCommandRejected({
|
|
2248
|
+
command_method: 'invoke',
|
|
2249
|
+
command_target: action_id,
|
|
2250
|
+
reason: 'not_found',
|
|
2251
|
+
message: 'No element with nac_id=' + action_id,
|
|
2252
|
+
source: (opts && opts.source) || undefined,
|
|
2253
|
+
});
|
|
2254
|
+
throw NacError('not_found', 'No element with nac_id=' + action_id);
|
|
2255
|
+
}
|
|
2256
|
+
/* invoke deliberately does NOT enforce visibility -- the
|
|
2257
|
+
canonical use case is a mic / search / upload widget that
|
|
2258
|
+
may live outside the visible viewport but is still a valid
|
|
2259
|
+
NAC target (the agent never had to "see" it to use it).
|
|
2260
|
+
Disabled state is still respected. */
|
|
2261
|
+
if (el.disabled || el.getAttribute('aria-disabled') === 'true') {
|
|
2262
|
+
_emitCommandRejected({
|
|
2263
|
+
command_method: 'invoke',
|
|
2264
|
+
command_target: action_id,
|
|
2265
|
+
reason: 'disabled',
|
|
2266
|
+
message: 'Element ' + action_id + ' is disabled',
|
|
2267
|
+
source: (opts && opts.source) || undefined,
|
|
2268
|
+
});
|
|
2269
|
+
throw NacError('disabled', 'Element ' + action_id + ' is disabled');
|
|
2270
|
+
}
|
|
2271
|
+
const verb = (payload && payload.verb)
|
|
2272
|
+
|| el.getAttribute('data-nac-action')
|
|
2273
|
+
|| '';
|
|
2274
|
+
const pluginRoot = el.closest('[data-nac-plugin]');
|
|
2275
|
+
const plugin = pluginRoot
|
|
2276
|
+
? pluginRoot.getAttribute('data-nac-plugin')
|
|
2277
|
+
: null;
|
|
2278
|
+
const request_id = 'nac_inv_'
|
|
2279
|
+
+ Math.random().toString(36).slice(2, 12)
|
|
2280
|
+
+ '_' + Date.now();
|
|
2281
|
+
const timeout_ms = (opts && opts.timeout) || 30000;
|
|
2282
|
+
|
|
2283
|
+
const result = new Promise(function (resolve, reject) {
|
|
2284
|
+
let settled = false;
|
|
2285
|
+
function matchesReq(e) {
|
|
2286
|
+
return e && e.detail && e.detail.request_id === request_id;
|
|
2287
|
+
}
|
|
2288
|
+
function onSucceeded(e) {
|
|
2289
|
+
if (settled) return;
|
|
2290
|
+
if (!matchesReq(e)) return;
|
|
2291
|
+
settled = true;
|
|
2292
|
+
cleanup();
|
|
2293
|
+
resolve({
|
|
2294
|
+
ok: true,
|
|
2295
|
+
request_id: request_id,
|
|
2296
|
+
ack: e.detail || null,
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
function onFailed(e) {
|
|
2300
|
+
if (settled) return;
|
|
2301
|
+
if (!matchesReq(e)) return;
|
|
2302
|
+
settled = true;
|
|
2303
|
+
cleanup();
|
|
2304
|
+
const code = (e.detail && e.detail.error) || 'failed';
|
|
2305
|
+
reject(NacError(code,
|
|
2306
|
+
'invoke failed for ' + action_id
|
|
2307
|
+
+ ((e.detail && e.detail.message) ? ': ' + e.detail.message : '')));
|
|
2308
|
+
}
|
|
2309
|
+
const timer = setTimeout(function () {
|
|
2310
|
+
if (settled) return;
|
|
2311
|
+
settled = true;
|
|
2312
|
+
cleanup();
|
|
2313
|
+
reject(NacError('timeout',
|
|
2314
|
+
'invoke timeout after ' + timeout_ms + 'ms for ' + action_id));
|
|
2315
|
+
}, timeout_ms);
|
|
2316
|
+
function cleanup() {
|
|
2317
|
+
document.removeEventListener('nac:action:succeeded', onSucceeded);
|
|
2318
|
+
document.removeEventListener('nac:action:failed', onFailed);
|
|
2319
|
+
clearTimeout(timer);
|
|
2320
|
+
}
|
|
2321
|
+
document.addEventListener('nac:action:succeeded', onSucceeded);
|
|
2322
|
+
document.addEventListener('nac:action:failed', onFailed);
|
|
2323
|
+
});
|
|
2324
|
+
|
|
2325
|
+
/* Dispatch the request event. Bubbles so the host can listen
|
|
2326
|
+
on document if it prefers a single handler for all actions
|
|
2327
|
+
(matches how the existing :succeeded / :failed contracts
|
|
2328
|
+
work today). detail.payload is opaque to the runtime; only
|
|
2329
|
+
the host knows what shape to expect for its own verb. */
|
|
2330
|
+
el.dispatchEvent(new CustomEvent('nac:action:requested', {
|
|
2331
|
+
bubbles: true,
|
|
2332
|
+
detail: {
|
|
2333
|
+
action_id: action_id,
|
|
2334
|
+
verb: verb,
|
|
2335
|
+
payload: payload,
|
|
2336
|
+
plugin: plugin,
|
|
2337
|
+
request_id: request_id,
|
|
2338
|
+
ts: Date.now(),
|
|
2339
|
+
},
|
|
2340
|
+
}));
|
|
2341
|
+
|
|
2342
|
+
return result;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
/* Ergonomic shortcut for the most common payload-bearing verb.
|
|
2346
|
+
Equivalent to invoke(id, {verb:'utter', text, lang, voice}). */
|
|
2347
|
+
async function utter(action_id, opts) {
|
|
2348
|
+
if (!opts || typeof opts !== 'object') {
|
|
2349
|
+
throw NacError('invalid', 'utter requires an opts object with at least "text"');
|
|
2350
|
+
}
|
|
2351
|
+
if (!opts.text || typeof opts.text !== 'string') {
|
|
2352
|
+
throw NacError('invalid', 'utter requires opts.text (string)');
|
|
2353
|
+
}
|
|
2354
|
+
return await invoke(action_id, {
|
|
2355
|
+
verb: 'utter',
|
|
2356
|
+
text: opts.text,
|
|
2357
|
+
lang: opts.lang || null,
|
|
2358
|
+
voice: opts.voice || null,
|
|
2359
|
+
metadata: opts.metadata || null,
|
|
2360
|
+
}, opts);
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2212
2363
|
async function tab_by_label(plugin, label, opts) {
|
|
2213
2364
|
if (!label) throw NacError('invalid', 'tab_by_label requires a label');
|
|
2214
2365
|
const targetPlugin = plugin || _activePlugin();
|
|
@@ -5008,8 +5159,8 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
5008
5159
|
|
|
5009
5160
|
global.NAC = {
|
|
5010
5161
|
__nac_v1_installed: true,
|
|
5011
|
-
version: '2.
|
|
5012
|
-
spec_version: '2.
|
|
5162
|
+
version: '2.3.0-alpha.1',
|
|
5163
|
+
spec_version: '2.3',
|
|
5013
5164
|
/* v2.2.0 (V22-01) -- strict validation toggle. When true,
|
|
5014
5165
|
NAC.register throws on findings (manifest_role_unknown,
|
|
5015
5166
|
tab_id_manifest_role_drift, manifest_dom_role_mismatch).
|
|
@@ -5056,6 +5207,15 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
5056
5207
|
/* v1.4.1 -- voice/agent ergonomic helpers */
|
|
5057
5208
|
click_by_verb: click_by_verb,
|
|
5058
5209
|
tab_by_label: tab_by_label,
|
|
5210
|
+
/* v2.3.0 -- payload-bearing actions. invoke() is the generic
|
|
5211
|
+
primitive: dispatches nac:action:requested with the agent's
|
|
5212
|
+
payload and resolves on nac:action:succeeded/:failed matching
|
|
5213
|
+
the request_id. utter() is the ergonomic shortcut for the
|
|
5214
|
+
conversational verb pattern (the first concrete adopter is
|
|
5215
|
+
Atlas Pro's mic). Both are additive on top of click()/click_by_verb()
|
|
5216
|
+
and do not change existing demo behaviour. */
|
|
5217
|
+
invoke: invoke,
|
|
5218
|
+
utter: utter,
|
|
5059
5219
|
/* utility */
|
|
5060
5220
|
wait_for: wait_for,
|
|
5061
5221
|
screenshot: screenshot,
|
|
@@ -5194,15 +5354,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
5194
5354
|
NacError: NacError,
|
|
5195
5355
|
};
|
|
5196
5356
|
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5357
|
+
/* v2.2.1: guard browser-only init so this module is importable in
|
|
5358
|
+
Node / SSR / test contexts without crashing. */
|
|
5359
|
+
if (typeof document !== 'undefined') {
|
|
5360
|
+
document.dispatchEvent(new CustomEvent('nac:installed', {
|
|
5361
|
+
detail: { version: global.NAC.version, spec: global.NAC.spec_version },
|
|
5362
|
+
}));
|
|
5200
5363
|
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5364
|
+
/* v1.9.0: install the ARIA bridge for data-nac-a11y-hint so
|
|
5365
|
+
screen readers actually consume the hints today (sec 3.1).
|
|
5366
|
+
Runs after install so existing host-level aria-describedby
|
|
5367
|
+
values are preserved (we append, not overwrite). */
|
|
5368
|
+
_installA11yHintBridge();
|
|
5369
|
+
}
|
|
5206
5370
|
|
|
5207
5371
|
/* v1.9.0: auto-replay any window.__NAC_PENDING__ buffer the
|
|
5208
5372
|
host staged before the runtime loaded (sec 13.11). The host
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nac3/runtime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-alpha.1",
|
|
4
4
|
"description": "Native Agent Contract -- spec + reference runtime that lets web UIs be driven by AI agents, voice runners, and accessibility tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nac",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"homepage": "https://yujin.app/nac-spec/",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/
|
|
21
|
-
"directory": "
|
|
20
|
+
"url": "https://github.com/yujinapp/nac-spec.git",
|
|
21
|
+
"directory": "runtime"
|
|
22
22
|
},
|
|
23
|
-
"bugs": "https://github.com/
|
|
24
|
-
"author": "Yujin (https://
|
|
23
|
+
"bugs": "https://github.com/yujinapp/nac-spec/issues",
|
|
24
|
+
"author": "Yujin (https://yujin.app)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"type": "module",
|
|
27
27
|
"main": "./dist/nac.cjs",
|
|
@@ -66,9 +66,10 @@
|
|
|
66
66
|
],
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "node ./build.mjs",
|
|
69
|
-
"test": "node ./test/smoke.mjs && node ./test/v22.mjs",
|
|
70
|
-
"test:smoke":
|
|
71
|
-
"test:v22":
|
|
69
|
+
"test": "node ./test/smoke.mjs && node ./test/v22.mjs && node ./test/v23-invoke.mjs",
|
|
70
|
+
"test:smoke": "node ./test/smoke.mjs",
|
|
71
|
+
"test:v22": "node ./test/v22.mjs",
|
|
72
|
+
"test:v23": "node ./test/v23-invoke.mjs",
|
|
72
73
|
"prepublishOnly": "npm run build && npm test"
|
|
73
74
|
},
|
|
74
75
|
"engines": {
|