@egen-civitas/esm-embed-testing 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @egen-civitas/esm-embed-testing
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3300bac: Toasts partagés : le Core est l'afficheur, l'app notifie en temps réel sans doublon. Politique d'opérateur dans le grant `notifications` (`exclusive`, défaut vrai ; `rate`, défaut 10 par 10 s), `id` de dédoublonnage, réponse `{ displayed }`, anti-spam `RATE_LIMITED`. Client : `egen.notify(toast, local?)` (point d'entrée unique, repli local si le Core n'affiche pas), `egen.coreDisplaysNotifications`, hook `useEgenNotify`. Hôte : le fournisseur peut répondre `false` (doublon). Testing : hôte de test, conformité et vérificateur couvrent le modèle.
8
+ - b2d283e: Retrait radical de l'ancienne couche d'assistance par agent. Elle était trop rigide et sera reconstruite sur une base saine, selon la nouvelle architecture documentée dans le dépôt Core (dossier de documentation de l'intégration de l'agent).
9
+
10
+ - **Packages supprimés** : les sept packages de l'ancienne couche (configuration, canal, contexte, événements, extensions, outils, façade). Le tag `pre-retrait-assistance-2026-11-25` conserve l'état précédent.
11
+ - `esm-framework` : ne ré-exporte plus la façade de l'ancienne couche. **Rupture** pour tout consommateur qui l'importait via `esm-framework`.
12
+ - `esm-styleguide` : le dossier `assistant/` est supprimé (orbe, robot 3D, scène Spline, saisie de prompt, fond d'érosion, modale « verre d'eau », audio), ainsi que les jetons CSS `--ui-*` dédiés à cette couche et les dépendances `three`, `@react-three/fiber`, `@splinetool/*`.
13
+ - `esm-app-shell` : le pont des variables d'environnement de l'ancienne couche vers `window` est supprimé (configuration, gabarit `index.ejs`, bootstrap natif). Le garde-fou des ponts ne porte plus que sur `EGEN_TENANT_*`.
14
+ - `rspack-config` : le préfixe de variable publique de l'ancienne couche est retiré de `PUBLIC_ENV_PREFIXES`.
15
+ - `esm-embed-*` : la capacité d'outils pilotés par un agent est retirée du catalogue du SDK embed (protocole, hôte, client, simulateur et vérificateur de test).
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [3300bac]
20
+ - Updated dependencies [b2d283e]
21
+ - @egen-civitas/esm-embed-protocol@0.4.0
22
+ - @egen-civitas/esm-embed-client@0.3.0
23
+ - @egen-civitas/esm-embed-host@0.4.0
24
+
3
25
  ## 0.3.0
4
26
 
5
27
  ### Minor Changes
package/README.md CHANGED
@@ -21,7 +21,7 @@ expect(sim.notifications).toEqual([{ kind: 'success', title: 'OK' }]);
21
21
  sim.emit.locale('en'); // le Core pousse un changement
22
22
  ```
23
23
 
24
- `sim.calls` (journal des services sollicités), `sim.published`, `sim.tools` + `sim.invokeTool()` (agent IA), `sim.emit.*`.
24
+ `sim.calls` (journal des services sollicités), `sim.published`, `sim.emit.*`.
25
25
 
26
26
  ## 2. Suite de conformité
27
27
 
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,2GAA2G;IAC3G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,+HAA+H;AAC/H,wBAAsB,aAAa,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAuD1E;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,EAAE,YAA4C,CAAC"}
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,2GAA2G;IAC3G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,+HAA+H;AAC/H,wBAAsB,aAAa,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAsD1E;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,EAAE,YAA4C,CAAC"}
package/dist/check.js CHANGED
@@ -154,7 +154,7 @@ function _ts_generator(thisArg, body) {
154
154
  import { CAPABILITIES, patternCovers, validateManifest } from '@egen-civitas/esm-embed-protocol';
155
155
  /** Vérificateur d'app embarquée (`egen-embed-check`) : manifeste, hygiène des capacités demandées, intégrabilité en iframe. */ export function checkEmbedApp(o) {
156
156
  return _async_to_generator(function() {
157
- var _m_extensions, _m_extensions1, _caps_events, _caps_aitools, _caps_extensions, issues, add, r, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _$e, m, caps, needApproval, pub, own, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, p, tools, slots, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _$e1, discover, _o_fetchImpl, f, _res_headers_get, _exec_, _exec, res, xfo, csp, fa, tokens, e;
157
+ var _m_extensions, _m_extensions1, _caps_events, _caps_extensions, issues, add, r, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _$e, m, caps, needApproval, pub, own, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, p, slots, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _$e1, discover, _o_fetchImpl, f, _res_headers_get, _exec_, _exec, res, xfo, csp, fa, tokens, e;
158
158
  return _ts_generator(this, function(_state) {
159
159
  switch(_state.label){
160
160
  case 0:
@@ -225,10 +225,7 @@ import { CAPABILITIES, patternCovers, validateManifest } from '@egen-civitas/esm
225
225
  }
226
226
  }
227
227
  }
228
- tools = (_caps_aitools = caps['ai-tools']) === null || _caps_aitools === void 0 ? void 0 : _caps_aitools.tools;
229
- if (Array.isArray(tools) && tools.some(function(t) {
230
- return !String(t).includes('.');
231
- })) add('warn', 'ai-tools.tools : préférer des noms d’outils préfixés (ex. studio.apply) pour éviter les collisions');
228
+ if (caps.notifications) add('info', "Notifications : le Core affiche les toasts (par défaut seul). N'affichez pas les vôtres : appelez egen.notify(toast, local) et ne rendez votre composant de toasts que si !egen.coreDisplaysNotifications");
232
229
  slots = _to_consumable_array(new Set(((_m_extensions = m.extensions) !== null && _m_extensions !== void 0 ? _m_extensions : []).map(function(e) {
233
230
  return e.slot;
234
231
  })));
@@ -1 +1 @@
1
- {"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../src/conformance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAGjF,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC7C,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IACvD,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,cAAc,GAAG,IAAI,CAwF7E"}
1
+ {"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../src/conformance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAGjF,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC7C,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IACvD,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,cAAc,GAAG,IAAI,CA4H7E"}
@@ -526,6 +526,175 @@ import { createTestHost } from './test-host.js';
526
526
  });
527
527
  })();
528
528
  });
529
+ it('toasts : le Core affiche seul, l’app n’affiche pas les siens (notify sans doublon)', function() {
530
+ return _async_to_generator(function() {
531
+ var sim, c, local;
532
+ return _ts_generator(this, function(_state) {
533
+ switch(_state.label){
534
+ case 0:
535
+ sim = createTestHost({
536
+ manifestCapabilities: {
537
+ notifications: {}
538
+ },
539
+ approved: {
540
+ notifications: {}
541
+ }
542
+ });
543
+ return [
544
+ 4,
545
+ connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
546
+ capabilities: [
547
+ 'notifications'
548
+ ]
549
+ }))
550
+ ];
551
+ case 1:
552
+ c = _state.sent();
553
+ local = [];
554
+ expect(c.coreDisplaysNotifications).toBe(true);
555
+ return [
556
+ 4,
557
+ c.notify({
558
+ kind: 'success',
559
+ title: 'Enregistré',
560
+ id: 't1'
561
+ }, function(t) {
562
+ return local.push(t);
563
+ })
564
+ ];
565
+ case 2:
566
+ _state.sent();
567
+ return [
568
+ 4,
569
+ c.notify({
570
+ kind: 'success',
571
+ title: 'Enregistré',
572
+ id: 't1'
573
+ }, function(t) {
574
+ return local.push(t);
575
+ })
576
+ ];
577
+ case 3:
578
+ _state.sent();
579
+ expect(local).toEqual([]);
580
+ expect(sim.notifications).toHaveLength(1); // le doublon (même id) n'est pas réaffiché par le Core
581
+ c.close();
582
+ sim.destroy();
583
+ return [
584
+ 2
585
+ ];
586
+ }
587
+ });
588
+ })();
589
+ });
590
+ it('toasts : sans approbation, l’app affiche elle-même (jamais de perte, jamais de doublon)', function() {
591
+ return _async_to_generator(function() {
592
+ var sim, c, local;
593
+ return _ts_generator(this, function(_state) {
594
+ switch(_state.label){
595
+ case 0:
596
+ sim = createTestHost();
597
+ return [
598
+ 4,
599
+ connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
600
+ capabilities: [
601
+ 'notifications'
602
+ ]
603
+ }))
604
+ ];
605
+ case 1:
606
+ c = _state.sent();
607
+ local = [];
608
+ expect(c.coreDisplaysNotifications).toBe(false);
609
+ return [
610
+ 4,
611
+ c.notify({
612
+ kind: 'info',
613
+ title: 'x'
614
+ }, function(t) {
615
+ return local.push(t);
616
+ })
617
+ ];
618
+ case 2:
619
+ _state.sent();
620
+ expect(local).toHaveLength(1);
621
+ expect(sim.notifications).toHaveLength(0);
622
+ c.close();
623
+ sim.destroy();
624
+ return [
625
+ 2
626
+ ];
627
+ }
628
+ });
629
+ })();
630
+ });
631
+ it('toasts : anti-spam (rate) — au-delà, abandonné, ni Core ni local', function() {
632
+ return _async_to_generator(function() {
633
+ var sim, c, local, i;
634
+ return _ts_generator(this, function(_state) {
635
+ switch(_state.label){
636
+ case 0:
637
+ sim = createTestHost({
638
+ manifestCapabilities: {
639
+ notifications: {}
640
+ },
641
+ approved: {
642
+ notifications: {
643
+ rate: {
644
+ max: 2,
645
+ perSeconds: 60
646
+ }
647
+ }
648
+ }
649
+ });
650
+ return [
651
+ 4,
652
+ connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
653
+ capabilities: [
654
+ 'notifications'
655
+ ]
656
+ }))
657
+ ];
658
+ case 1:
659
+ c = _state.sent();
660
+ local = [];
661
+ i = 0;
662
+ _state.label = 2;
663
+ case 2:
664
+ if (!(i < 5)) return [
665
+ 3,
666
+ 5
667
+ ];
668
+ return [
669
+ 4,
670
+ c.notify({
671
+ kind: 'info',
672
+ title: "t".concat(i)
673
+ }, function(t) {
674
+ return local.push(t);
675
+ })
676
+ ];
677
+ case 3:
678
+ _state.sent();
679
+ _state.label = 4;
680
+ case 4:
681
+ i++;
682
+ return [
683
+ 3,
684
+ 2
685
+ ];
686
+ case 5:
687
+ expect(sim.notifications).toHaveLength(2);
688
+ expect(local).toEqual([]);
689
+ c.close();
690
+ sim.destroy();
691
+ return [
692
+ 2
693
+ ];
694
+ }
695
+ });
696
+ })();
697
+ });
529
698
  it('fermeture : appels suivants rejetés', function() {
530
699
  return _async_to_generator(function() {
531
700
  var sim, c;
package/dist/server.js CHANGED
@@ -310,4 +310,4 @@ export function startSimulator(o) {
310
310
  });
311
311
  })();
312
312
  }
313
- var PAGE = "<!doctype html><html lang=\"fr\"><head><meta charset=\"utf-8\"><title>EGEN — simulateur de Shell</title>\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<script type=\"importmap\">{\"imports\":{\"@egen-civitas/esm-embed-protocol\":\"/vendor/protocol/index.js\"}}</script>\n<style>\n:root{color-scheme:light dark;--b:#d0d7de;font-family:system-ui,sans-serif}\nbody{margin:0;display:grid;grid-template-columns:1fr 360px;height:100vh}\n#stage{min-width:0;display:flex}#stage iframe{flex:1;border:0}\naside{border-left:1px solid var(--b);padding:12px;overflow:auto;font-size:13px}\nbutton{margin:2px 4px 2px 0;padding:4px 8px;cursor:pointer}\npre{white-space:pre-wrap;word-break:break-word;font-size:12px;max-height:50vh;overflow:auto;border:1px solid var(--b);padding:6px;border-radius:6px}\n.toast{border:1px solid var(--b);border-radius:6px;padding:6px;margin:4px 0}\nh1{font-size:14px;margin:0 0 8px}h2{font-size:12px;margin:12px 0 4px;text-transform:uppercase;opacity:.7}\n</style></head><body>\n<div id=\"stage\"></div>\n<aside><h1>Simulateur de Shell EGEN</h1>\n<div id=\"info\"></div>\n<h2>Pousser vers l'app</h2>\n<button id=\"locale\">Langue fr/en</button><button id=\"event\">\xc9v\xe9nement core.sim.ping</button><button id=\"ext\">Changer les extensions de topbar-nav-slot</button>\n<h2>Notifications</h2><div id=\"toasts\"></div>\n<h2>Journal des \xe9changes</h2><pre id=\"log\"></pre></aside>\n<script type=\"module\">\nimport { effectiveGrants } from '@egen-civitas/esm-embed-protocol';\nimport { createEmbedHost } from '/vendor/host/index.js';\nconst cfg = await (await fetch('/api/config')).json();\nconst $ = (id) => document.getElementById(id);\nconst log = (...a) => { $('log').textContent = new Date().toLocaleTimeString() + ' ' + a.map((x) => typeof x === 'string' ? x : JSON.stringify(x)).join(' ') + '\\n' + $('log').textContent; };\nconst watch = (v) => { const s = new Set(); return { get: () => v, subscribe: (cb) => (s.add(cb), () => s.delete(cb)), set: (n) => { v = n; s.forEach((f) => f(n)); } }; };\nconst locale = watch('fr'), tenant = watch({ id: 'sim-tenant' }), conf = watch({});\nconst topics = new Map();\nconst extState = new Map(Object.entries(cfg.extensions)), extSubs = new Map();\nconst wrap = (cap, p) => Object.fromEntries(Object.entries(p).map(([k, f]) => [k, typeof f === 'function' ? (...a) => { log('←', cap + '.' + k, a); return f(...a); } : f]));\nconst providers = {\n locale: wrap('locale', locale), tenant: wrap('tenant', tenant), config: wrap('config', conf),\n flags: wrap('flags', { isEnabled: () => true }),\n extensions: { list: (slot) => { log('← extensions.list', slot); return extState.get(slot) || []; }, subscribe: (slot, cb) => { const s = extSubs.get(slot) || new Set(); s.add(cb); extSubs.set(slot, s); return () => s.delete(cb); } },\n events: { publish: (t, p, c) => { log('← events.publish', t, p, 'de', c.moduleName); (topics.get(t) || []).forEach((f) => f(p)); }, subscribe: (t, cb) => { log('← events.subscribe', t); const l = topics.get(t) || []; l.push(cb); topics.set(t, l); return () => topics.set(t, (topics.get(t) || []).filter((f) => f !== cb)); } },\n notifications: { show: (n) => { log('← notifications.show', n); const d = document.createElement('div'); d.className = 'toast'; d.textContent = '[' + n.kind + '] ' + n.title + (n.subtitle ? ' — ' + n.subtitle : ''); $('toasts').prepend(d); } },\n dialogs: { confirm: (d) => { log('← dialogs.confirm', d); return confirm(d.title + '\\n\\n' + d.message); } },\n telemetry: { log: (...a) => log('← telemetry.log', a.slice(0, 3)), metric: (...a) => log('← telemetry.metric', a.slice(0, 3)) },\n aiTools: { register: (m, t) => log('← ai-tools.register', t.map((x) => x.name)), unregister: (m, n) => log('← ai-tools.unregister', n) },\n};\nconst grants = effectiveGrants(cfg.manifestCapabilities, cfg.approved);\n$('info').innerHTML = '<b>App</b> ' + cfg.app + '<br><b>Module</b> ' + cfg.moduleName + '<br><b>hostOrigins \xe0 d\xe9clarer dans l’app</b> <code>' + location.origin + '</code><br><b>Capacit\xe9s accord\xe9es</b> ' + Object.keys(grants).join(', ');\nconst host = createEmbedHost({ moduleName: cfg.moduleName, src: cfg.app, grants, providers, onConnect: (g, d) => log('✔ connect\xe9', { accord\xe9es: g.map((x) => x.id), refus\xe9es: d }), onClose: (r) => log('✖ ferm\xe9', r) });\nhost.mount($('stage'));\n$('locale').onclick = () => locale.set(locale.get() === 'fr' ? 'en' : 'fr');\n$('event').onclick = () => (topics.get('core.sim.ping') || []).forEach((f) => f({ at: Date.now() }));\n$('ext').onclick = () => { const n = [{ name: 'nav-' + Math.floor(Math.random() * 100), moduleName: '@egen/esm-demo-app', meta: { label: 'Nouvelle extension' } }]; extState.set('topbar-nav-slot', n); (extSubs.get('topbar-nav-slot') || []).forEach((f) => f(n)); };\n</script></body></html>";
313
+ var PAGE = "<!doctype html><html lang=\"fr\"><head><meta charset=\"utf-8\"><title>EGEN — simulateur de Shell</title>\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<script type=\"importmap\">{\"imports\":{\"@egen-civitas/esm-embed-protocol\":\"/vendor/protocol/index.js\"}}</script>\n<style>\n:root{color-scheme:light dark;--b:#d0d7de;font-family:system-ui,sans-serif}\nbody{margin:0;display:grid;grid-template-columns:1fr 360px;height:100vh}\n#stage{min-width:0;display:flex}#stage iframe{flex:1;border:0}\naside{border-left:1px solid var(--b);padding:12px;overflow:auto;font-size:13px}\nbutton{margin:2px 4px 2px 0;padding:4px 8px;cursor:pointer}\npre{white-space:pre-wrap;word-break:break-word;font-size:12px;max-height:50vh;overflow:auto;border:1px solid var(--b);padding:6px;border-radius:6px}\n.toast{border:1px solid var(--b);border-radius:6px;padding:6px;margin:4px 0}\nh1{font-size:14px;margin:0 0 8px}h2{font-size:12px;margin:12px 0 4px;text-transform:uppercase;opacity:.7}\n</style></head><body>\n<div id=\"stage\"></div>\n<aside><h1>Simulateur de Shell EGEN</h1>\n<div id=\"info\"></div>\n<h2>Pousser vers l'app</h2>\n<button id=\"locale\">Langue fr/en</button><button id=\"event\">\xc9v\xe9nement core.sim.ping</button><button id=\"ext\">Changer les extensions de topbar-nav-slot</button>\n<h2>Notifications</h2><div id=\"toasts\"></div>\n<h2>Journal des \xe9changes</h2><pre id=\"log\"></pre></aside>\n<script type=\"module\">\nimport { effectiveGrants } from '@egen-civitas/esm-embed-protocol';\nimport { createEmbedHost } from '/vendor/host/index.js';\nconst cfg = await (await fetch('/api/config')).json();\nconst $ = (id) => document.getElementById(id);\nconst log = (...a) => { $('log').textContent = new Date().toLocaleTimeString() + ' ' + a.map((x) => typeof x === 'string' ? x : JSON.stringify(x)).join(' ') + '\\n' + $('log').textContent; };\nconst watch = (v) => { const s = new Set(); return { get: () => v, subscribe: (cb) => (s.add(cb), () => s.delete(cb)), set: (n) => { v = n; s.forEach((f) => f(n)); } }; };\nconst locale = watch('fr'), tenant = watch({ id: 'sim-tenant' }), conf = watch({});\nconst topics = new Map(), seenToasts = new Set();\nconst extState = new Map(Object.entries(cfg.extensions)), extSubs = new Map();\nconst wrap = (cap, p) => Object.fromEntries(Object.entries(p).map(([k, f]) => [k, typeof f === 'function' ? (...a) => { log('←', cap + '.' + k, a); return f(...a); } : f]));\nconst providers = {\n locale: wrap('locale', locale), tenant: wrap('tenant', tenant), config: wrap('config', conf),\n flags: wrap('flags', { isEnabled: () => true }),\n extensions: { list: (slot) => { log('← extensions.list', slot); return extState.get(slot) || []; }, subscribe: (slot, cb) => { const s = extSubs.get(slot) || new Set(); s.add(cb); extSubs.set(slot, s); return () => s.delete(cb); } },\n events: { publish: (t, p, c) => { log('← events.publish', t, p, 'de', c.moduleName); (topics.get(t) || []).forEach((f) => f(p)); }, subscribe: (t, cb) => { log('← events.subscribe', t); const l = topics.get(t) || []; l.push(cb); topics.set(t, l); return () => topics.set(t, (topics.get(t) || []).filter((f) => f !== cb)); } },\n notifications: { show: (n, c) => { log('← notifications.show', n, 'de', c.moduleName); if (n.id && seenToasts.has(n.id)) return false; if (n.id) seenToasts.add(n.id); const d = document.createElement('div'); d.className = 'toast'; d.textContent = '[' + n.kind + '] ' + cfg.moduleName + ' \xb7 ' + n.title + (n.subtitle ? ' — ' + n.subtitle : ''); $('toasts').prepend(d); return true; } },\n dialogs: { confirm: (d) => { log('← dialogs.confirm', d); return confirm(d.title + '\\n\\n' + d.message); } },\n telemetry: { log: (...a) => log('← telemetry.log', a.slice(0, 3)), metric: (...a) => log('← telemetry.metric', a.slice(0, 3)) },\n};\nconst grants = effectiveGrants(cfg.manifestCapabilities, cfg.approved);\n$('info').innerHTML = '<b>App</b> ' + cfg.app + '<br><b>Module</b> ' + cfg.moduleName + '<br><b>hostOrigins \xe0 d\xe9clarer dans l’app</b> <code>' + location.origin + '</code><br><b>Capacit\xe9s accord\xe9es</b> ' + Object.keys(grants).join(', ');\nconst host = createEmbedHost({ moduleName: cfg.moduleName, src: cfg.app, grants, providers, onConnect: (g, d) => log('✔ connect\xe9', { accord\xe9es: g.map((x) => x.id), refus\xe9es: d }), onClose: (r) => log('✖ ferm\xe9', r) });\nhost.mount($('stage'));\n$('locale').onclick = () => locale.set(locale.get() === 'fr' ? 'en' : 'fr');\n$('event').onclick = () => (topics.get('core.sim.ping') || []).forEach((f) => f({ at: Date.now() }));\n$('ext').onclick = () => { const n = [{ name: 'nav-' + Math.floor(Math.random() * 100), moduleName: '@egen/esm-demo-app', meta: { label: 'Nouvelle extension' } }]; extState.set('topbar-nav-slot', n); (extSubs.get('topbar-nav-slot') || []).forEach((f) => f(n)); };\n</script></body></html>";
@@ -35,6 +35,7 @@ export interface TestHost {
35
35
  /** Journal des services du Core sollicités par l'app. */
36
36
  calls: CallRecord[];
37
37
  notifications: Array<{
38
+ id?: string;
38
39
  kind: string;
39
40
  title: string;
40
41
  subtitle?: string;
@@ -44,9 +45,6 @@ export interface TestHost {
44
45
  payload: unknown;
45
46
  from: string;
46
47
  }>;
47
- tools: Map<string, {
48
- description: string;
49
- }>;
50
48
  /** Pousse un changement vers l'app (comme le ferait le Core). */
51
49
  emit: {
52
50
  tenant(v: {
@@ -59,8 +57,6 @@ export interface TestHost {
59
57
  goto(path: string): void;
60
58
  visibility(visible: boolean): void;
61
59
  };
62
- /** L'agent IA appelle un outil déclaré par l'app. */
63
- invokeTool(name: string, args?: Record<string, unknown>): Promise<unknown>;
64
60
  destroy(): void;
65
61
  }
66
62
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../src/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC7H,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAa,cAAc,EAAE,KAAK,aAAa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info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _ts_generator(thisArg, body) {
31
- var f, y, t, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
40
- return d(g, "next", {
41
- value: verb(0)
42
- }), d(g, "throw", {
43
- value: verb(1)
44
- }), d(g, "return", {
45
- value: verb(2)
46
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
47
- value: function() {
48
- return this;
49
- }
50
- }), g;
51
- function verb(n) {
52
- return function(v) {
53
- return step([
54
- n,
55
- v
56
- ]);
57
- };
58
- }
59
- function step(op) {
60
- if (f) throw new TypeError("Generator is already executing.");
61
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
62
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
- if (y = 0, t) op = [
64
- op[0] & 2,
65
- t.value
66
- ];
67
- switch(op[0]){
68
- case 0:
69
- case 1:
70
- t = op;
71
- break;
72
- case 4:
73
- _.label++;
74
- return {
75
- value: op[1],
76
- done: false
77
- };
78
- case 5:
79
- _.label++;
80
- y = op[1];
81
- op = [
82
- 0
83
- ];
84
- continue;
85
- case 7:
86
- op = _.ops.pop();
87
- _.trys.pop();
88
- continue;
89
- default:
90
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
91
- _ = 0;
92
- continue;
93
- }
94
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
95
- _.label = op[1];
96
- break;
97
- }
98
- if (op[0] === 6 && _.label < t[1]) {
99
- _.label = t[1];
100
- t = op;
101
- break;
102
- }
103
- if (t && _.label < t[2]) {
104
- _.label = t[2];
105
- _.ops.push(op);
106
- break;
107
- }
108
- if (t[2]) _.ops.pop();
109
- _.trys.pop();
110
- continue;
111
- }
112
- op = body.call(thisArg, _);
113
- } catch (e) {
114
- op = [
115
- 6,
116
- e
117
- ];
118
- y = 0;
119
- } finally{
120
- f = t = 0;
121
- }
122
- if (op[0] & 5) throw op[1];
123
- return {
124
- value: op[0] ? op[1] : void 0,
125
- done: true
126
- };
127
- }
128
- }
129
1
  import { effectiveGrants } from '@egen-civitas/esm-embed-protocol';
130
2
  import { createBus, HostConnection } from '@egen-civitas/esm-embed-host';
131
3
  function watchable(initial) {
@@ -164,8 +36,6 @@ function watchable(initial) {
164
36
  var calls = [];
165
37
  var notifications = [];
166
38
  var published = [];
167
- var tools = new Map();
168
- var toolInvokers = new Map();
169
39
  var log = function log(cap, method) {
170
40
  for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
171
41
  args[_key - 2] = arguments[_key];
@@ -247,7 +117,12 @@ function watchable(initial) {
247
117
  notifications: {
248
118
  show: function show(n) {
249
119
  log('notifications', 'show', n);
120
+ // même dédoublonnage que le Core : un `id` déjà affiché n'est pas réaffiché
121
+ if (n.id && notifications.some(function(x) {
122
+ return x.id === n.id;
123
+ })) return false;
250
124
  notifications.push(n);
125
+ return true;
251
126
  }
252
127
  },
253
128
  dialogs: {
@@ -264,59 +139,6 @@ function watchable(initial) {
264
139
  metric: function metric(n, v, t) {
265
140
  return log('telemetry', 'metric', n, v, t);
266
141
  }
267
- },
268
- aiTools: {
269
- register: function register(_m, list, invoke) {
270
- log('ai-tools', 'register', list.map(function(t) {
271
- return t.name;
272
- }));
273
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
274
- try {
275
- for(var _iterator = list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
276
- var t = _step.value;
277
- tools.set(t.name, {
278
- description: t.description
279
- });
280
- toolInvokers.set(t.name, invoke);
281
- }
282
- } catch (err) {
283
- _didIteratorError = true;
284
- _iteratorError = err;
285
- } finally{
286
- try {
287
- if (!_iteratorNormalCompletion && _iterator.return != null) {
288
- _iterator.return();
289
- }
290
- } finally{
291
- if (_didIteratorError) {
292
- throw _iteratorError;
293
- }
294
- }
295
- }
296
- },
297
- unregister: function unregister(_m, names) {
298
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
299
- try {
300
- for(var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
301
- var n = _step.value;
302
- tools.delete(n);
303
- toolInvokers.delete(n);
304
- }
305
- } catch (err) {
306
- _didIteratorError = true;
307
- _iteratorError = err;
308
- } finally{
309
- try {
310
- if (!_iteratorNormalCompletion && _iterator.return != null) {
311
- _iterator.return();
312
- }
313
- } finally{
314
- if (_didIteratorError) {
315
- throw _iteratorError;
316
- }
317
- }
318
- }
319
- }
320
142
  }
321
143
  };
322
144
  var appWindow = new EventTarget();
@@ -377,7 +199,6 @@ function watchable(initial) {
377
199
  calls: calls,
378
200
  notifications: notifications,
379
201
  published: published,
380
- tools: tools,
381
202
  emit: {
382
203
  tenant: function tenant1(v) {
383
204
  return tenant.set(v);
@@ -411,20 +232,6 @@ function watchable(initial) {
411
232
  return channel.emit('visibility', v);
412
233
  }
413
234
  },
414
- invokeTool: function invokeTool(name) {
415
- var args = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
416
- return _async_to_generator(function() {
417
- var inv;
418
- return _ts_generator(this, function(_state) {
419
- inv = toolInvokers.get(name);
420
- if (!inv) throw new Error("Outil non enregistr\xe9 : ".concat(name));
421
- return [
422
- 2,
423
- inv(name, args)
424
- ];
425
- });
426
- })();
427
- },
428
235
  destroy: function destroy() {
429
236
  return connection.destroy();
430
237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-embed-testing",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Développer et tester une app embarquée sans le Core : hôte de test en mémoire, suite de conformité du protocole v2, simulateur de Shell (egen-embed-sim).",
6
6
  "type": "module",
@@ -76,9 +76,9 @@
76
76
  "vitest": "^4.1.2"
77
77
  },
78
78
  "dependencies": {
79
- "@egen-civitas/esm-embed-client": "^0.2.0",
80
- "@egen-civitas/esm-embed-host": "^0.3.0",
81
- "@egen-civitas/esm-embed-protocol": "^0.3.0"
79
+ "@egen-civitas/esm-embed-client": "^0.3.0",
80
+ "@egen-civitas/esm-embed-host": "^0.4.0",
81
+ "@egen-civitas/esm-embed-protocol": "^0.4.0"
82
82
  },
83
83
  "bin": {
84
84
  "egen-embed-check": "bin/egen-embed-check.mjs",
package/src/check.ts CHANGED
@@ -40,9 +40,8 @@ export async function checkEmbedApp(o: CheckOptions): Promise<CheckIssue[]> {
40
40
  else if (!patternCovers(own, String(p).replace(/\.\*$/, '.x'))) add('warn', `events.publish : « ${p} » sort de l'espace conseillé ${own}`);
41
41
  }
42
42
  }
43
- const tools = caps['ai-tools']?.tools;
44
- if (Array.isArray(tools) && tools.some((t) => !String(t).includes('.'))) add('warn', 'ai-tools.tools : préférer des noms d’outils préfixés (ex. studio.apply) pour éviter les collisions');
45
43
 
44
+ if (caps.notifications) add('info', "Notifications : le Core affiche les toasts (par défaut seul). N'affichez pas les vôtres : appelez egen.notify(toast, local) et ne rendez votre composant de toasts que si !egen.coreDisplaysNotifications");
46
45
  const slots = [...new Set((m.extensions ?? []).map((e) => e.slot))];
47
46
  if (slots.length) add('info', `Contributions d'extension : l'opérateur doit approuver les slots (extensions.contribute) : ${slots.join(', ')}`);
48
47
  for (const e of m.extensions ?? []) if (e.view) add('info', `Extension « ${e.name} » : la vue ${e.view} sera affichée dans une iframe du Core (frame-ancestors à autoriser pour le Shell, hauteur via navigation.resize)`);
@@ -93,6 +93,42 @@ export function defineConformance(connect: ConnectFn, t: ConformanceApi): void {
93
93
  sim.destroy();
94
94
  });
95
95
 
96
+ it('toasts : le Core affiche seul, l’app n’affiche pas les siens (notify sans doublon)', async () => {
97
+ const sim = createTestHost({ manifestCapabilities: { notifications: {} }, approved: { notifications: {} } });
98
+ const c = await connect({ ...sim.connectOptions, capabilities: ['notifications'] });
99
+ const local: unknown[] = [];
100
+ expect(c.coreDisplaysNotifications).toBe(true);
101
+ await c.notify({ kind: 'success', title: 'Enregistré', id: 't1' }, (t) => local.push(t));
102
+ await c.notify({ kind: 'success', title: 'Enregistré', id: 't1' }, (t) => local.push(t));
103
+ expect(local).toEqual([]);
104
+ expect(sim.notifications).toHaveLength(1); // le doublon (même id) n'est pas réaffiché par le Core
105
+ c.close();
106
+ sim.destroy();
107
+ });
108
+
109
+ it('toasts : sans approbation, l’app affiche elle-même (jamais de perte, jamais de doublon)', async () => {
110
+ const sim = createTestHost();
111
+ const c = await connect({ ...sim.connectOptions, capabilities: ['notifications'] });
112
+ const local: unknown[] = [];
113
+ expect(c.coreDisplaysNotifications).toBe(false);
114
+ await c.notify({ kind: 'info', title: 'x' }, (t) => local.push(t));
115
+ expect(local).toHaveLength(1);
116
+ expect(sim.notifications).toHaveLength(0);
117
+ c.close();
118
+ sim.destroy();
119
+ });
120
+
121
+ it('toasts : anti-spam (rate) — au-delà, abandonné, ni Core ni local', async () => {
122
+ const sim = createTestHost({ manifestCapabilities: { notifications: {} }, approved: { notifications: { rate: { max: 2, perSeconds: 60 } } } });
123
+ const c = await connect({ ...sim.connectOptions, capabilities: ['notifications'] });
124
+ const local: unknown[] = [];
125
+ for (let i = 0; i < 5; i++) await c.notify({ kind: 'info', title: `t${i}` }, (t) => local.push(t));
126
+ expect(sim.notifications).toHaveLength(2);
127
+ expect(local).toEqual([]);
128
+ c.close();
129
+ sim.destroy();
130
+ });
131
+
96
132
  it('fermeture : appels suivants rejetés', async () => {
97
133
  const sim = createTestHost();
98
134
  const c = await connect({ ...sim.connectOptions, capabilities: ['tenant'] });
package/src/server.ts CHANGED
@@ -109,7 +109,7 @@ const $ = (id) => document.getElementById(id);
109
109
  const log = (...a) => { $('log').textContent = new Date().toLocaleTimeString() + ' ' + a.map((x) => typeof x === 'string' ? x : JSON.stringify(x)).join(' ') + '\\n' + $('log').textContent; };
110
110
  const watch = (v) => { const s = new Set(); return { get: () => v, subscribe: (cb) => (s.add(cb), () => s.delete(cb)), set: (n) => { v = n; s.forEach((f) => f(n)); } }; };
111
111
  const locale = watch('fr'), tenant = watch({ id: 'sim-tenant' }), conf = watch({});
112
- const topics = new Map();
112
+ const topics = new Map(), seenToasts = new Set();
113
113
  const extState = new Map(Object.entries(cfg.extensions)), extSubs = new Map();
114
114
  const wrap = (cap, p) => Object.fromEntries(Object.entries(p).map(([k, f]) => [k, typeof f === 'function' ? (...a) => { log('←', cap + '.' + k, a); return f(...a); } : f]));
115
115
  const providers = {
@@ -117,10 +117,9 @@ const providers = {
117
117
  flags: wrap('flags', { isEnabled: () => true }),
118
118
  extensions: { list: (slot) => { log('← extensions.list', slot); return extState.get(slot) || []; }, subscribe: (slot, cb) => { const s = extSubs.get(slot) || new Set(); s.add(cb); extSubs.set(slot, s); return () => s.delete(cb); } },
119
119
  events: { publish: (t, p, c) => { log('← events.publish', t, p, 'de', c.moduleName); (topics.get(t) || []).forEach((f) => f(p)); }, subscribe: (t, cb) => { log('← events.subscribe', t); const l = topics.get(t) || []; l.push(cb); topics.set(t, l); return () => topics.set(t, (topics.get(t) || []).filter((f) => f !== cb)); } },
120
- notifications: { show: (n) => { log('← notifications.show', n); const d = document.createElement('div'); d.className = 'toast'; d.textContent = '[' + n.kind + '] ' + n.title + (n.subtitle ? ' — ' + n.subtitle : ''); $('toasts').prepend(d); } },
120
+ notifications: { show: (n, c) => { log('← notifications.show', n, 'de', c.moduleName); if (n.id && seenToasts.has(n.id)) return false; if (n.id) seenToasts.add(n.id); const d = document.createElement('div'); d.className = 'toast'; d.textContent = '[' + n.kind + '] ' + cfg.moduleName + ' · ' + n.title + (n.subtitle ? ' — ' + n.subtitle : ''); $('toasts').prepend(d); return true; } },
121
121
  dialogs: { confirm: (d) => { log('← dialogs.confirm', d); return confirm(d.title + '\\n\\n' + d.message); } },
122
122
  telemetry: { log: (...a) => log('← telemetry.log', a.slice(0, 3)), metric: (...a) => log('← telemetry.metric', a.slice(0, 3)) },
123
- aiTools: { register: (m, t) => log('← ai-tools.register', t.map((x) => x.name)), unregister: (m, n) => log('← ai-tools.unregister', n) },
124
123
  };
125
124
  const grants = effectiveGrants(cfg.manifestCapabilities, cfg.approved);
126
125
  $('info').innerHTML = '<b>App</b> ' + cfg.app + '<br><b>Module</b> ' + cfg.moduleName + '<br><b>hostOrigins à déclarer dans l’app</b> <code>' + location.origin + '</code><br><b>Capacités accordées</b> ' + Object.keys(grants).join(', ');
package/src/test-host.ts CHANGED
@@ -31,9 +31,8 @@ export interface TestHost {
31
31
  connection: HostConnection;
32
32
  /** Journal des services du Core sollicités par l'app. */
33
33
  calls: CallRecord[];
34
- notifications: Array<{ kind: string; title: string; subtitle?: string }>;
34
+ notifications: Array<{ id?: string; kind: string; title: string; subtitle?: string }>;
35
35
  published: Array<{ topic: string; payload: unknown; from: string }>;
36
- tools: Map<string, { description: string }>;
37
36
  /** Pousse un changement vers l'app (comme le ferait le Core). */
38
37
  emit: {
39
38
  tenant(v: { id: string | null }): void;
@@ -44,8 +43,6 @@ export interface TestHost {
44
43
  goto(path: string): void;
45
44
  visibility(visible: boolean): void;
46
45
  };
47
- /** L'agent IA appelle un outil déclaré par l'app. */
48
- invokeTool(name: string, args?: Record<string, unknown>): Promise<unknown>;
49
46
  destroy(): void;
50
47
  }
51
48
 
@@ -77,8 +74,6 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
77
74
  const calls: CallRecord[] = [];
78
75
  const notifications: TestHost['notifications'] = [];
79
76
  const published: TestHost['published'] = [];
80
- const tools = new Map<string, { description: string }>();
81
- const toolInvokers = new Map<string, (name: string, args: Record<string, unknown>) => Promise<unknown>>();
82
77
  const log = (cap: string, method: string, ...args: unknown[]) => void calls.push({ cap, method, args });
83
78
 
84
79
  const tenant = watchable(o.tenant ?? { id: null });
@@ -136,7 +131,10 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
136
131
  notifications: {
137
132
  show: (n) => {
138
133
  log('notifications', 'show', n);
134
+ // même dédoublonnage que le Core : un `id` déjà affiché n'est pas réaffiché
135
+ if (n.id && notifications.some((x) => x.id === n.id)) return false;
139
136
  notifications.push(n);
137
+ return true;
140
138
  },
141
139
  },
142
140
  dialogs: {
@@ -146,21 +144,6 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
146
144
  },
147
145
  },
148
146
  telemetry: { log: (l, m, c) => log('telemetry', 'log', l, m, c), metric: (n, v, t) => log('telemetry', 'metric', n, v, t) },
149
- aiTools: {
150
- register: (_m, list, invoke) => {
151
- log('ai-tools', 'register', list.map((t) => t.name));
152
- for (const t of list) {
153
- tools.set(t.name, { description: t.description });
154
- toolInvokers.set(t.name, invoke);
155
- }
156
- },
157
- unregister: (_m, names) => {
158
- for (const n of names) {
159
- tools.delete(n);
160
- toolInvokers.delete(n);
161
- }
162
- },
163
- },
164
147
  };
165
148
 
166
149
  const appWindow = new EventTarget();
@@ -196,7 +179,6 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
196
179
  calls,
197
180
  notifications,
198
181
  published,
199
- tools,
200
182
  emit: {
201
183
  tenant: (v) => tenant.set(v),
202
184
  locale: (v) => locale.set(v),
@@ -209,11 +191,6 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
209
191
  goto: (path) => channel.emit('goto', { path, seq: Date.now() }),
210
192
  visibility: (v) => channel.emit('visibility', v),
211
193
  },
212
- invokeTool: async (name, args = {}) => {
213
- const inv = toolInvokers.get(name);
214
- if (!inv) throw new Error(`Outil non enregistré : ${name}`);
215
- return inv(name, args);
216
- },
217
194
  destroy: () => connection.destroy(),
218
195
  };
219
196
  }