@egen-civitas/esm-embed-host 0.3.0 → 0.5.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,42 @@
1
1
  # @egen-civitas/esm-embed-host
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 721c7f8: Droits d'iframe négociés et voie unique SDK.
8
+
9
+ - **protocole** : bloc `iframe` (`sandbox[]`, `allow[]`) dans la déclaration `egen-config.json` (demande) et dans le plafond approuvé ; listes blanches strictes (`IFRAME_SANDBOX_TOKENS`, `IFRAME_ALLOW_TOKENS`, jamais de `allow-top-navigation*`) ; `validateIframeRights`, `effectiveIframe` (demande ∩ plafond), `sanitizeIframeRights` ; `config` publique validée (≤ 8 Ko) ; `ApprovedGrants` accepte `iframe`. **Breaking** : `SUPPORTED_PROTOCOLS` ne contient plus que `2` (le protocole 1 / pont 1.1 est retiré) ; `negotiateProtocol(1)` → `null`.
10
+ - **hôte** : option `iframe` (droits effectifs) qui étend le socle et pose les attributs `sandbox` et `allow`, avec revalidation par liste blanche. **Breaking** : l'option `sandbox` est remplacée par `iframe` ; l'option `legacy` et le pont 1.1 (`handleLegacy`, `legacySend`) sont retirés ; la poignée de main ne propose plus que le protocole 2.
11
+ - **testing** : `createTestHost` accepte `manifestIframe` et expose `iframe` (droits effectifs) ; `egen-embed-check` valide la forme `iframe`, rappelle l'approbation requise et signale les permissions sensibles ; le simulateur applique les droits d'iframe.
12
+ - **client** : documentation (les droits se demandent dans `egen-config.json`), le manifeste s'appelle désormais `egen-config.json`.
13
+
14
+ ### Patch Changes
15
+
16
+ - 721c7f8: Retrait du paquet `@egen-civitas/esm-nextjs-utils` (pont 1.1 et script `egen-bridge.js`) : le SDK `esm-embed-client` est l'unique voie d'intégration d'une app embarquée. Les versions déjà publiées de `esm-nextjs-utils` doivent être marquées dépréciées sur npm (`npm deprecate`).
17
+ - Updated dependencies [721c7f8]
18
+ - @egen-civitas/esm-embed-protocol@0.5.0
19
+
20
+ ## 0.4.0
21
+
22
+ ### Minor Changes
23
+
24
+ - 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.
25
+ - 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).
26
+
27
+ - **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.
28
+ - `esm-framework` : ne ré-exporte plus la façade de l'ancienne couche. **Rupture** pour tout consommateur qui l'importait via `esm-framework`.
29
+ - `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/*`.
30
+ - `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_*`.
31
+ - `rspack-config` : le préfixe de variable publique de l'ancienne couche est retiré de `PUBLIC_ENV_PREFIXES`.
32
+ - `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).
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [3300bac]
37
+ - Updated dependencies [b2d283e]
38
+ - @egen-civitas/esm-embed-protocol@0.4.0
39
+
3
40
  ## 0.3.0
4
41
 
5
42
  ### Minor Changes
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
1
  # @egen-civitas/esm-embed-host
2
2
 
3
3
  Hôte (côté Shell/Core) des applications **embarquées** : iframe sécurisée, poignée de main v2, application des grants,
4
- fournisseurs de capacités, navigation partagée Core ↔ app, et compatibilité du pont 1.1 (`esm-nextjs-utils`).
4
+ fournisseurs de capacités, navigation partagée Core ↔ app. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
5
5
  Spécification : `docs/integration-apps/17-sdk-embed-protocole-v2.md` du dépôt Core.
6
6
 
7
7
  ```ts
8
- import { effectiveGrants } from '@egen-civitas/esm-embed-protocol';
8
+ import { effectiveGrants, effectiveIframe } from '@egen-civitas/esm-embed-protocol';
9
9
  import { createEmbedHost } from '@egen-civitas/esm-embed-host';
10
10
 
11
- const grants = effectiveGrants(manifest.capabilities, { notifications: {}, events: { publish: ['app.studio.*'] } });
11
+ const approved = { notifications: {}, events: { publish: ['app.studio.*'] }, iframe: { sandbox: ['allow-downloads'], allow: ['clipboard-write'] } };
12
+ const grants = effectiveGrants(manifest.capabilities, approved);
13
+ const iframe = effectiveIframe(manifest.iframe, approved.iframe); // droits d'iframe effectifs (demande ∩ plafond)
12
14
 
13
15
  const host = createEmbedHost({
14
16
  moduleName: manifest.name,
15
17
  src: manifest.url,
16
18
  grants,
19
+ iframe,
17
20
  navigation: { route: manifest.route, mode: manifest.navigation.mode },
18
21
  providers: {
19
22
  locale: { get, subscribe }, // services dont le Core est la source
@@ -27,5 +30,6 @@ host.mount(container); // …; host.destroy() au démontage
27
30
 
28
31
  - **Moindre privilège** : la table d'appels de la connexion ne contient que les capacités accordées **et** servies. Une capacité accordée sans fournisseur est refusée (`UNAVAILABLE`).
29
32
  - **Règle d'or** : le Core ne relaie ni identité/session, ni droits, ni thème, ni appels API authentifiés (ils viennent de Keycloak, des backends, du service de thèmes). Aucun jeton ne transite.
30
- - **Pont 1.1** : une app qui ne parle pas le protocole 2 continue de fonctionner (`ready`, `location`, `navigate`, `resize`, `title`, langue) — sans session. Désactivable : `legacy: false`.
33
+ - **Droits d'iframe négociés** : le socle (`allow-scripts allow-same-origin allow-forms allow-popups`) s'applique à toute app ; `iframe` (droits effectifs) ne peut que l'étendre (`allow-downloads`, `allow-modals`, `clipboard-*`, `fullscreen`…). L'hôte revalide chaque jeton par liste blanche et pose `sandbox` et `allow`. `allow-same-origin` + `allow-scripts` sur la même origine que le Shell est signalé (bac à sable sans effet).
34
+ - **Voie unique** : le pont 1.1 (`{ egen: 1 }`) est retiré ; ses messages sont ignorés. Une app doit adopter `@egen-civitas/esm-embed-client`.
31
35
  - `HostConnection` est indépendante du DOM (testable avec le vrai client, voir `src/__tests__/harness.ts`).
@@ -23,7 +23,6 @@ export declare class HostConnection {
23
23
  state: ConnectionState;
24
24
  private nonce?;
25
25
  private rpc?;
26
- private cleanup?;
27
26
  constructor(o: ConnectionOptions);
28
27
  /** Nouvelle poignée de main (à chaque chargement de l'iframe) : ferme toute connexion précédente. */
29
28
  hello(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,MAAM,EACZ,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAgD,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE7F,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,YAAY,CAA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KAAK,IAAI,IAAI;IAOb,OAAO,IAAI,IAAI;CAIhB"}
@@ -196,7 +196,6 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
196
196
  _define_property(this, "state", void 0);
197
197
  _define_property(this, "nonce", void 0);
198
198
  _define_property(this, "rpc", void 0);
199
- _define_property(this, "cleanup", void 0);
200
199
  this.o = o;
201
200
  this.state = 'idle';
202
201
  }
@@ -211,8 +210,7 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
211
210
  kind: 'hello',
212
211
  nonce: this.nonce,
213
212
  protocols: [
214
- EGEN_EMBED_PROTOCOL,
215
- 1
213
+ EGEN_EMBED_PROTOCOL
216
214
  ],
217
215
  hostVersion: this.o.hostVersion
218
216
  }));
@@ -230,8 +228,7 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
230
228
  kind: 'hello',
231
229
  nonce: this.nonce,
232
230
  protocols: [
233
- EGEN_EMBED_PROTOCOL,
234
- 1
231
+ EGEN_EMBED_PROTOCOL
235
232
  ],
236
233
  hostVersion: this.o.hostVersion
237
234
  }));
@@ -282,14 +279,9 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
282
279
  moduleName: this.o.moduleName,
283
280
  granted: granted,
284
281
  providers: this.o.providers,
285
- controls: this.o.controls,
286
- callApp: function callApp(cap, method, args) {
287
- if (!_this.rpc) return Promise.reject(new Error('non connecté'));
288
- return _this.rpc.call(cap, method, args);
289
- }
290
- }), table = _createCapabilityTable.table, subscribe = _createCapabilityTable.subscribe, cleanup = _createCapabilityTable.cleanup;
282
+ controls: this.o.controls
283
+ }), table = _createCapabilityTable.table, subscribe = _createCapabilityTable.subscribe;
291
284
  var _ref = new MessageChannel(), port1 = _ref.port1, port2 = _ref.port2;
292
- this.cleanup = cleanup;
293
285
  this.rpc = new RpcEndpoint({
294
286
  port: port1,
295
287
  handlers: table,
@@ -299,9 +291,7 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
299
291
  },
300
292
  limits: this.o.limits,
301
293
  onClose: function onClose(reason) {
302
- var _this_cleanup, _this1, _this_o_onClose, _this_o;
303
- (_this_cleanup = (_this1 = _this).cleanup) === null || _this_cleanup === void 0 ? void 0 : _this_cleanup.call(_this1);
304
- _this.cleanup = undefined;
294
+ var _this_o_onClose, _this_o;
305
295
  if (_this.state !== 'closed') _this.state = 'idle';
306
296
  (_this_o_onClose = (_this_o = _this.o).onClose) === null || _this_o_onClose === void 0 ? void 0 : _this_o_onClose.call(_this_o, reason);
307
297
  }
@@ -345,11 +335,9 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
345
335
  {
346
336
  /** Ferme la connexion courante (rechargement de l'iframe) sans détruire l'objet. */ key: "reset",
347
337
  value: function reset() {
348
- var _this_rpc, _this_cleanup, _this;
338
+ var _this_rpc;
349
339
  (_this_rpc = this.rpc) === null || _this_rpc === void 0 ? void 0 : _this_rpc.close();
350
340
  this.rpc = undefined;
351
- (_this_cleanup = (_this = this).cleanup) === null || _this_cleanup === void 0 ? void 0 : _this_cleanup.call(_this);
352
- this.cleanup = undefined;
353
341
  this.nonce = undefined;
354
342
  if (this.state !== 'closed') this.state = 'idle';
355
343
  }
package/dist/host.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type Limits } from '@egen-civitas/esm-embed-protocol';
1
+ import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits } from '@egen-civitas/esm-embed-protocol';
2
2
  import { HostConnection } from './connection.js';
3
3
  import { type NavigationOptions } from './navigation.js';
4
4
  import type { HostProviders } from './providers.js';
5
5
  export interface EmbedHostOptions {
6
- /** Nom du module (= `name` du manifeste). */
6
+ /** Nom du module (= `name` de `egen-config.json`). */
7
7
  moduleName: string;
8
8
  /** URL de base de l'application embarquée. */
9
9
  src: string;
@@ -12,8 +12,11 @@ export interface EmbedHostOptions {
12
12
  /** Grants effectifs (`effectiveGrants(manifeste.capabilities, approuvés)`). */
13
13
  grants: EffectiveGrants;
14
14
  providers: HostProviders;
15
- /** Attribut `sandbox` (défaut : scripts, même origine, formulaires, popups). */
16
- sandbox?: string;
15
+ /**
16
+ * Droits d'iframe EFFECTIFS (`effectiveIframe(manifeste.iframe, approuvés.iframe)`) : ils étendent le socle
17
+ * (`allow-scripts allow-same-origin allow-forms allow-popups`). Les jetons hors liste blanche sont écartés.
18
+ */
19
+ iframe?: IframeRights;
17
20
  title?: string;
18
21
  minHeight?: number;
19
22
  /** Navigation partagée Core ↔ app (URL du Core = source de vérité). Absent ou `none` : opaque. */
@@ -22,8 +25,6 @@ export interface EmbedHostOptions {
22
25
  onNavigate?: (to: string) => void;
23
26
  limits?: Partial<Limits>;
24
27
  hostVersion?: string;
25
- /** Accepter aussi les apps qui parlent encore le pont 1.1 (défaut : oui). */
26
- legacy?: boolean;
27
28
  window?: Window;
28
29
  onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
29
30
  onClose?(reason: string): void;
@@ -38,7 +39,7 @@ export interface EmbedHost {
38
39
  }
39
40
  /**
40
41
  * Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
41
- * événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
42
+ * événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
42
43
  * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
43
44
  */
44
45
  export declare function createEmbedHost(opts: EmbedHostOptions): EmbedHost;
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAEpI,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAwH,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAA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M,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,KAAK,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,2IAA2I;IAC3I,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,IAAI,IAAI,CAAC;CACjB;AAKD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,CA0IjE"}
package/dist/host.js CHANGED
@@ -1,3 +1,11 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
1
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
10
  try {
3
11
  var info = gen[key](arg);
@@ -40,6 +48,12 @@ function _define_property(obj, key, value) {
40
48
  }
41
49
  return obj;
42
50
  }
51
+ function _iterable_to_array(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _non_iterable_spread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
43
57
  function _object_spread(target) {
44
58
  for(var i = 1; i < arguments.length; i++){
45
59
  var source = arguments[i] != null ? arguments[i] : {};
@@ -79,6 +93,17 @@ function _object_spread_props(target, source) {
79
93
  }
80
94
  return target;
81
95
  }
96
+ function _to_consumable_array(arr) {
97
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
98
+ }
99
+ function _unsupported_iterable_to_array(o, minLen) {
100
+ if (!o) return;
101
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
102
+ var n = Object.prototype.toString.call(o).slice(8, -1);
103
+ if (n === "Object" && o.constructor) n = o.constructor.name;
104
+ if (n === "Map" || n === "Set") return Array.from(n);
105
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
106
+ }
82
107
  function _ts_generator(thisArg, body) {
83
108
  var f, y, t, _ = {
84
109
  label: 0,
@@ -178,16 +203,22 @@ function _ts_generator(thisArg, body) {
178
203
  };
179
204
  }
180
205
  }
206
+ import { sanitizeIframeRights } from '@egen-civitas/esm-embed-protocol';
181
207
  import { createBus } from './bus.js';
182
208
  import { HostConnection } from './connection.js';
183
209
  import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath } from './navigation.js';
184
- var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups';
210
+ /** Socle d'isolation appliqué à toute app embarquée ; les droits négociés (`iframe`) ne peuvent que l'étendre. */ var BASE_SANDBOX = [
211
+ 'allow-scripts',
212
+ 'allow-same-origin',
213
+ 'allow-forms',
214
+ 'allow-popups'
215
+ ];
185
216
  /**
186
217
  * Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
187
- * événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
218
+ * événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
188
219
  * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
189
220
  */ export function createEmbedHost(opts) {
190
- var _opts_window, _opts_navigation_mode, _opts_navigation_mode1, _currentCorePath, _toAppPath, _opts_allowedOrigin, _opts_sandbox, _opts_title, _opts_minHeight;
221
+ var _opts_window, _opts_navigation_mode, _opts_navigation_mode1, _currentCorePath, _toAppPath, _opts_allowedOrigin, _opts_title, _opts_minHeight;
191
222
  var win = (_opts_window = opts.window) !== null && _opts_window !== void 0 ? _opts_window : window;
192
223
  var doc = win.document;
193
224
  var nav = opts.navigation && ((_opts_navigation_mode = opts.navigation.mode) !== null && _opts_navigation_mode !== void 0 ? _opts_navigation_mode : 'history') !== 'none' ? _object_spread_props(_object_spread({}, opts.navigation), {
@@ -208,7 +239,8 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
208
239
  var src = nav ? buildEmbedSrc(opts.src, initialAppPath, nav.mode) : opts.src;
209
240
  var origin = (_opts_allowedOrigin = opts.allowedOrigin) !== null && _opts_allowedOrigin !== void 0 ? _opts_allowedOrigin : new URL(src, win.location.href).origin;
210
241
  if (origin === '*' || origin === 'null') throw new Error('allowedOrigin invalide : une origine explicite est requise.');
211
- var sandbox = (_opts_sandbox = opts.sandbox) !== null && _opts_sandbox !== void 0 ? _opts_sandbox : DEFAULT_SANDBOX;
242
+ var rights = sanitizeIframeRights(opts.iframe);
243
+ var sandbox = _to_consumable_array(new Set(_to_consumable_array(BASE_SANDBOX).concat(_to_consumable_array(rights.sandbox)))).join(' ');
212
244
  if (origin === win.location.origin && /allow-scripts/.test(sandbox) && /allow-same-origin/.test(sandbox)) {
213
245
  console.warn("[egen] ".concat(opts.moduleName, " : application embarqu\xe9e de m\xeame origine que le Shell avec \xab allow-scripts allow-same-origin \xbb : le bac \xe0 sable est sans effet. H\xe9berger l'application sur une autre origine (sous-domaine)."));
214
246
  }
@@ -216,6 +248,7 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
216
248
  iframe.src = src;
217
249
  iframe.title = (_opts_title = opts.title) !== null && _opts_title !== void 0 ? _opts_title : opts.moduleName;
218
250
  iframe.setAttribute('sandbox', sandbox);
251
+ if (rights.allow.length) iframe.setAttribute('allow', rights.allow.join('; '));
219
252
  iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
220
253
  iframe.setAttribute('data-egen-fill', '');
221
254
  iframe.style.cssText = "width:100%;border:0;display:block;min-height:".concat((_opts_minHeight = opts.minHeight) !== null && _opts_minHeight !== void 0 ? _opts_minHeight : 400, "px");
@@ -223,20 +256,11 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
223
256
  var allowLocation = createRateLimiter();
224
257
  var stop = [];
225
258
  var seq = 0;
226
- var legacySeen = false;
227
- var legacyReady = false;
228
259
  var postRaw = function postRaw(message, transfer) {
229
260
  var _iframe_contentWindow;
230
261
  return (_iframe_contentWindow = iframe.contentWindow) === null || _iframe_contentWindow === void 0 ? void 0 : _iframe_contentWindow.postMessage(message, origin, transfer);
231
262
  };
232
- var legacySend = function legacySend(message) {
233
- return postRaw({
234
- egen: 1,
235
- moduleName: opts.moduleName,
236
- message: message
237
- });
238
- };
239
- /** Page courante annoncée par l'app → URL du Core (partagé entre le protocole 2 et le pont 1.1). */ var reportLocation = function reportLocation(path, o) {
263
+ /** Page courante annoncée par l'app → URL du Core. */ var reportLocation = function reportLocation(path, o) {
240
264
  if (!nav || !allowLocation()) return;
241
265
  if (typeof (o === null || o === void 0 ? void 0 : o.title) === 'string') {
242
266
  var _nav_onTitle;
@@ -279,137 +303,14 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
279
303
  onConnect: opts.onConnect,
280
304
  onClose: opts.onClose
281
305
  });
282
- /**
283
- * Pont 1.1 : compatibilité des apps qui ne parlent pas encore le protocole 2. La session n'est PLUS transmise (règle d'or,
284
- * doc 17 §2) : une app obtient son identité auprès de Keycloak. Seuls restent la langue, la navigation, le titre et la hauteur.
285
- */ var handleLegacy = function handleLegacy(data) {
286
- return _async_to_generator(function() {
287
- var msg, _, _win_i18next, locale, _tmp, _controls_navigate, _controls_resize;
288
- return _ts_generator(this, function(_state) {
289
- switch(_state.label){
290
- case 0:
291
- if (opts.legacy === false || connection.connected) return [
292
- 2
293
- ];
294
- if (!data || data.egen !== 1 || data.moduleName !== opts.moduleName || !data.message || typeof data.message.kind !== 'string') return [
295
- 2
296
- ];
297
- msg = data.message;
298
- _ = msg.kind;
299
- switch(_){
300
- case 'ready':
301
- return [
302
- 3,
303
- 1
304
- ];
305
- case 'navigate':
306
- return [
307
- 3,
308
- 5
309
- ];
310
- case 'resize':
311
- return [
312
- 3,
313
- 6
314
- ];
315
- case 'title':
316
- return [
317
- 3,
318
- 7
319
- ];
320
- case 'location':
321
- return [
322
- 3,
323
- 8
324
- ];
325
- }
326
- return [
327
- 3,
328
- 9
329
- ];
330
- case 1:
331
- legacySeen = true;
332
- legacyReady = true;
333
- if (!opts.providers.locale) return [
334
- 3,
335
- 3
336
- ];
337
- return [
338
- 4,
339
- opts.providers.locale.get()
340
- ];
341
- case 2:
342
- _tmp = _state.sent();
343
- return [
344
- 3,
345
- 4
346
- ];
347
- case 3:
348
- _tmp = (_win_i18next = win.i18next) === null || _win_i18next === void 0 ? void 0 : _win_i18next.language;
349
- _state.label = 4;
350
- case 4:
351
- locale = _tmp;
352
- legacySend({
353
- kind: 'init',
354
- payload: {
355
- moduleName: opts.moduleName,
356
- locale: locale,
357
- spaBase: spaBase(),
358
- navigation: nav ? {
359
- mode: nav.mode,
360
- route: nav.route
361
- } : undefined
362
- }
363
- });
364
- return [
365
- 3,
366
- 9
367
- ];
368
- case 5:
369
- (_controls_navigate = controls.navigate) === null || _controls_navigate === void 0 ? void 0 : _controls_navigate.call(controls, msg.to);
370
- return [
371
- 3,
372
- 9
373
- ];
374
- case 6:
375
- (_controls_resize = controls.resize) === null || _controls_resize === void 0 ? void 0 : _controls_resize.call(controls, msg.height);
376
- return [
377
- 3,
378
- 9
379
- ];
380
- case 7:
381
- if (typeof msg.title === 'string') iframe.title = msg.title.slice(0, 200);
382
- return [
383
- 3,
384
- 9
385
- ];
386
- case 8:
387
- legacySeen = true;
388
- reportLocation(msg.path, {
389
- replace: !!msg.replace,
390
- title: msg.title
391
- });
392
- return [
393
- 3,
394
- 9
395
- ];
396
- case 9:
397
- return [
398
- 2
399
- ];
400
- }
401
- });
402
- })();
403
- };
404
306
  var onMessage = function onMessage(event) {
405
307
  if (event.source !== iframe.contentWindow || event.origin !== origin) return;
406
- if (!connection.handle(event.data)) void handleLegacy(event.data);
308
+ connection.handle(event.data);
407
309
  };
408
310
  return {
409
311
  iframe: iframe,
410
312
  connection: connection,
411
313
  mount: function mount(container) {
412
- var _p_locale;
413
314
  win.addEventListener('message', onMessage);
414
315
  stop.push(function() {
415
316
  return win.removeEventListener('message', onMessage);
@@ -432,11 +333,6 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
432
333
  path: appPath,
433
334
  seq: ++seq
434
335
  });
435
- else if (legacySeen) legacySend({
436
- kind: 'goto',
437
- path: appPath,
438
- seq: ++seq
439
- });
440
336
  else iframe.src = buildEmbedSrc(opts.src, appPath, nav.mode);
441
337
  };
442
338
  win.addEventListener('single-spa:routing-event', onCoreLocation);
@@ -463,14 +359,6 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
463
359
  win.removeEventListener('focus', onFocus);
464
360
  win.removeEventListener('blur', onBlur);
465
361
  });
466
- // Pont 1.1 : la langue est poussée après `ready`.
467
- var p = opts.providers;
468
- if ((_p_locale = p.locale) === null || _p_locale === void 0 ? void 0 : _p_locale.subscribe) stop.push(p.locale.subscribe(function(l) {
469
- return legacyReady && !connection.connected && l && legacySend({
470
- kind: 'locale',
471
- locale: l
472
- });
473
- }));
474
362
  container.appendChild(iframe);
475
363
  },
476
364
  canLeave: function canLeave() {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
2
+ * Navigation partagée Shell ↔ application embarquée (capacité `navigation` du protocole 2).
3
3
  *
4
4
  * L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
5
5
  * Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
2
+ * Navigation partagée Shell ↔ application embarquée (capacité `navigation` du protocole 2).
3
3
  *
4
4
  * L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
5
5
  * Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
@@ -9,6 +9,8 @@ export interface CallerContext {
9
9
  moduleName: string;
10
10
  }
11
11
  export interface NotificationInput {
12
+ /** Clé de dédoublonnage facultative : un même `id` ne produit pas deux toasts rapprochés. */
13
+ id?: string;
12
14
  kind: 'info' | 'success' | 'warning' | 'error';
13
15
  title: string;
14
16
  subtitle?: string;
@@ -20,11 +22,6 @@ export interface ExtensionInfo {
20
22
  order?: number;
21
23
  meta: Record<string, unknown>;
22
24
  }
23
- export interface AiToolDescriptor {
24
- name: string;
25
- description: string;
26
- inputSchema?: Record<string, unknown>;
27
- }
28
25
  /**
29
26
  * Services du Core mis à disposition des apps embarquées. Toute capacité sans fournisseur est
30
27
  * automatiquement refusée à la négociation (`UNAVAILABLE`) : on ne promet que ce qu'on sait servir.
@@ -46,8 +43,9 @@ export interface HostProviders {
46
43
  publish(topic: string, payload: unknown, ctx: CallerContext): void;
47
44
  subscribe(topic: string, cb: (payload: unknown) => void): Unsub;
48
45
  };
46
+ /** Affiche le toast dans l'interface du Core ; retourne `false` si non affiché (doublon, etc.). Le Core attribue le toast à son app d'origine. */
49
47
  notifications?: {
50
- show(n: NotificationInput, ctx: CallerContext): void | Promise<void>;
48
+ show(n: NotificationInput, ctx: CallerContext): void | boolean | Promise<void | boolean>;
51
49
  };
52
50
  dialogs?: {
53
51
  confirm(d: {
@@ -65,9 +63,5 @@ export interface HostProviders {
65
63
  log(level: 'debug' | 'info' | 'warn' | 'error', message: string, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
66
64
  metric(name: string, value: number, tags: Record<string, unknown> | undefined, from: CallerContext): void;
67
65
  };
68
- aiTools?: {
69
- register(moduleName: string, tools: AiToolDescriptor[], invoke: (name: string, args: Record<string, unknown>) => Promise<unknown>): void;
70
- unregister(moduleName: string, names: string[]): void;
71
- };
72
66
  }
73
67
  //# sourceMappingURL=providers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC;AAE/B,wDAAwD;AACxD,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC;CAC3C;AAED,MAAM,WAAW,aAAa;IAC5B,uGAAuG;IACvG,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,SAAS,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA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AC,IAAI,GAAG,OAAO,CAAC,CAAA;KAAE,CAAC;IAC7G,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,OAAO,CAAA;SAAE,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IAC/H,+HAA+H;IAC/H,UAAU,CAAC,EAAE;QAAE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;QAAC,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,IAAI,GAAG,KAAK,CAAA;KAAE,CAAC;IACtJ,SAAS,CAAC,EAAE;QACV,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;QACtI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;KAC3G,CAAC;CACH"}
package/dist/table.d.ts CHANGED
@@ -21,16 +21,13 @@ export interface TableOptions {
21
21
  granted: CapabilityGranted[];
22
22
  providers: HostProviders;
23
23
  controls: HostControls;
24
- /** Appel hôte → app (`ai-tools.invoke`). */
25
- callApp: (cap: string, method: string, args: unknown[]) => Promise<unknown>;
26
24
  }
27
25
  /**
28
26
  * Construit la table de dispatch FERMÉE d'une connexion : seules les capacités accordées (et servies) y figurent,
29
- * chaque méthode applique son grant (sujets d'événements, slots découvrables, drapeaux, outils IA).
27
+ * chaque méthode applique son grant (sujets d'événements, slots découvrables, drapeaux).
30
28
  */
31
29
  export declare function createCapabilityTable(o: TableOptions): {
32
30
  table: HandlerTable;
33
31
  subscribe: SubscribeHandler;
34
- cleanup: () => void;
35
32
  };
36
33
  //# sourceMappingURL=table.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAEjB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEnE,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1E,QAAQ,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,6DAA6D;IAC7D,OAAO,EAAE,GAAG,CAAC;CACd;AAED,8HAA8H;AAC9H,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,CAezE;AAID,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,SAAS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,CAAC,YAAY,CAAC,CAczE;AAID,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAA;CAAE,CA+F3G"}
package/dist/table.js CHANGED
@@ -6,9 +6,6 @@ function _array_like_to_array(arr, len) {
6
6
  function _array_with_holes(arr) {
7
7
  if (Array.isArray(arr)) return arr;
8
8
  }
9
- function _array_without_holes(arr) {
10
- if (Array.isArray(arr)) return _array_like_to_array(arr);
11
- }
12
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
10
  try {
14
11
  var info = gen[key](arg);
@@ -38,9 +35,6 @@ function _async_to_generator(fn) {
38
35
  });
39
36
  };
40
37
  }
41
- function _iterable_to_array(iter) {
42
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
- }
44
38
  function _iterable_to_array_limit(arr, i) {
45
39
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
46
40
  if (_i == null) return;
@@ -68,15 +62,9 @@ function _iterable_to_array_limit(arr, i) {
68
62
  function _non_iterable_rest() {
69
63
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
70
64
  }
71
- function _non_iterable_spread() {
72
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73
- }
74
65
  function _sliced_to_array(arr, i) {
75
66
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
76
67
  }
77
- function _to_consumable_array(arr) {
78
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
79
- }
80
68
  function _unsupported_iterable_to_array(o, minLen) {
81
69
  if (!o) return;
82
70
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -184,7 +172,7 @@ function _ts_generator(thisArg, body) {
184
172
  };
185
173
  }
186
174
  }
187
- import { CAPABILITIES, EmbedError, slotAllowed, topicAllowed } from '@egen-civitas/esm-embed-protocol';
175
+ import { CAPABILITIES, createSlidingLimiter, notificationPolicy, EmbedError, slotAllowed, topicAllowed } from '@egen-civitas/esm-embed-protocol';
188
176
  /** Capacités que l'hôte sait servir avec ces fournisseurs. `navigation`, `lifecycle` et `telemetry` sont toujours servies. */ export function availableCapabilities(p) {
189
177
  var s = new Set([
190
178
  'navigation',
@@ -223,10 +211,6 @@ import { CAPABILITIES, EmbedError, slotAllowed, topicAllowed } from '@egen-civit
223
211
  [
224
212
  'extensions',
225
213
  p.extensions
226
- ],
227
- [
228
- 'ai-tools',
229
- p.aiTools
230
214
  ]
231
215
  ];
232
216
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -256,7 +240,7 @@ var list = function list(cfg, key) {
256
240
  };
257
241
  /**
258
242
  * Construit la table de dispatch FERMÉE d'une connexion : seules les capacités accordées (et servies) y figurent,
259
- * chaque méthode applique son grant (sujets d'événements, slots découvrables, drapeaux, outils IA).
243
+ * chaque méthode applique son grant (sujets d'événements, slots découvrables, drapeaux).
260
244
  */ export function createCapabilityTable(o) {
261
245
  var p = o.providers, c = o.controls;
262
246
  var ctx = {
@@ -269,7 +253,6 @@ var list = function list(cfg, key) {
269
253
  ];
270
254
  }));
271
255
  var table = {};
272
- var registeredTools = new Set();
273
256
  var denied = function denied(msg) {
274
257
  return new EmbedError('DENIED', msg);
275
258
  };
@@ -342,26 +325,34 @@ var list = function list(cfg, key) {
342
325
  }
343
326
  };
344
327
  }
345
- if (cfgOf.has('notifications') && p.notifications) table.notifications = {
346
- show: function show(n) {
347
- return _async_to_generator(function() {
348
- return _ts_generator(this, function(_state) {
349
- switch(_state.label){
350
- case 0:
351
- return [
352
- 4,
353
- p.notifications.show(n, ctx)
354
- ];
355
- case 1:
356
- return [
357
- 2,
358
- void _state.sent()
359
- ];
360
- }
361
- });
362
- })();
363
- }
364
- };
328
+ if (cfgOf.has('notifications') && p.notifications) {
329
+ // Anti-spam : une iframe ne doit pas pouvoir inonder l'interface du Core (ni imiter des messages système en rafale).
330
+ var policy = notificationPolicy(cfgOf.get('notifications'));
331
+ var allow = createSlidingLimiter(policy.rate.max, policy.rate.perSeconds);
332
+ table.notifications = {
333
+ show: function show(n) {
334
+ return _async_to_generator(function() {
335
+ var _tmp;
336
+ return _ts_generator(this, function(_state) {
337
+ switch(_state.label){
338
+ case 0:
339
+ if (!allow()) throw new EmbedError('RATE_LIMITED', 'Trop de notifications');
340
+ _tmp = {};
341
+ return [
342
+ 4,
343
+ p.notifications.show(n, ctx)
344
+ ];
345
+ case 1:
346
+ return [
347
+ 2,
348
+ (_tmp.displayed = _state.sent() !== false, _tmp)
349
+ ];
350
+ }
351
+ });
352
+ })();
353
+ }
354
+ };
355
+ }
365
356
  if (cfgOf.has('dialogs') && p.dialogs) table.dialogs = {
366
357
  confirm: function confirm(d) {
367
358
  return _async_to_generator(function() {
@@ -398,82 +389,6 @@ var list = function list(cfg, key) {
398
389
  }
399
390
  };
400
391
  }
401
- if (cfgOf.has('ai-tools') && p.aiTools) {
402
- var allowed = list(cfgOf.get('ai-tools'), 'tools');
403
- table['ai-tools'] = {
404
- register: function register(tools) {
405
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
406
- try {
407
- for(var _iterator = tools[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
408
- var t = _step.value;
409
- if (!topicAllowed(allowed, t.name)) throw denied("Outil non autoris\xe9 : ".concat(t.name));
410
- }
411
- } catch (err) {
412
- _didIteratorError = true;
413
- _iteratorError = err;
414
- } finally{
415
- try {
416
- if (!_iteratorNormalCompletion && _iterator.return != null) {
417
- _iterator.return();
418
- }
419
- } finally{
420
- if (_didIteratorError) {
421
- throw _iteratorError;
422
- }
423
- }
424
- }
425
- p.aiTools.register(o.moduleName, tools, function(name, args) {
426
- return o.callApp('ai-tools', 'invoke', [
427
- name,
428
- args
429
- ]);
430
- });
431
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
432
- try {
433
- for(var _iterator1 = tools[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
434
- var t1 = _step1.value;
435
- registeredTools.add(t1.name);
436
- }
437
- } catch (err) {
438
- _didIteratorError1 = true;
439
- _iteratorError1 = err;
440
- } finally{
441
- try {
442
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
443
- _iterator1.return();
444
- }
445
- } finally{
446
- if (_didIteratorError1) {
447
- throw _iteratorError1;
448
- }
449
- }
450
- }
451
- },
452
- unregister: function unregister(names) {
453
- p.aiTools.unregister(o.moduleName, names);
454
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
455
- try {
456
- for(var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
457
- var n = _step.value;
458
- registeredTools.delete(n);
459
- }
460
- } catch (err) {
461
- _didIteratorError = true;
462
- _iteratorError = err;
463
- } finally{
464
- try {
465
- if (!_iteratorNormalCompletion && _iterator.return != null) {
466
- _iterator.return();
467
- }
468
- } finally{
469
- if (_didIteratorError) {
470
- throw _iteratorError;
471
- }
472
- }
473
- }
474
- }
475
- };
476
- }
477
392
  if (cfgOf.has('telemetry')) {
478
393
  table.telemetry = {
479
394
  log: function log(level, message, extra) {
@@ -543,10 +458,6 @@ var list = function list(cfg, key) {
543
458
  };
544
459
  return {
545
460
  table: table,
546
- subscribe: subscribe,
547
- cleanup: function cleanup() {
548
- if (registeredTools.size && p.aiTools) p.aiTools.unregister(o.moduleName, _to_consumable_array(registeredTools));
549
- registeredTools.clear();
550
- }
461
+ subscribe: subscribe
551
462
  };
552
463
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-embed-host",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Hôte (côté Shell/Core) des applications embarquées : iframe sécurisée, poignée de main v2, grants, fournisseurs de capacités, navigation partagée, compatibilité du pont 1.1.",
6
6
  "type": "module",
@@ -57,7 +57,7 @@
57
57
  "access": "public"
58
58
  },
59
59
  "devDependencies": {
60
- "@egen-civitas/esm-embed-client": "^0.2.0",
60
+ "@egen-civitas/esm-embed-client": "^0.3.1",
61
61
  "@swc/cli": "0.8.1",
62
62
  "@swc/core": "1.15.21",
63
63
  "@types/node": "^20",
@@ -69,6 +69,6 @@
69
69
  "vitest": "^4.1.2"
70
70
  },
71
71
  "dependencies": {
72
- "@egen-civitas/esm-embed-protocol": "^0.3.0"
72
+ "@egen-civitas/esm-embed-protocol": "^0.5.0"
73
73
  }
74
74
  }
package/src/connection.ts CHANGED
@@ -39,7 +39,6 @@ export class HostConnection {
39
39
  state: ConnectionState = 'idle';
40
40
  private nonce?: string;
41
41
  private rpc?: RpcEndpoint;
42
- private cleanup?: () => void;
43
42
 
44
43
  constructor(private readonly o: ConnectionOptions) {}
45
44
 
@@ -48,7 +47,7 @@ export class HostConnection {
48
47
  this.reset();
49
48
  this.nonce = createNonce();
50
49
  this.state = 'hello';
51
- this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL, 1], hostVersion: this.o.hostVersion }));
50
+ this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL], hostVersion: this.o.hostVersion }));
52
51
  }
53
52
 
54
53
  /** Traite un message de poignée de main v2 ; `true` si le message est de la famille v2 (consommé). */
@@ -58,7 +57,7 @@ export class HostConnection {
58
57
  const m = env.message;
59
58
  if (m.kind === 'probe') {
60
59
  if (this.state === 'idle') this.hello();
61
- else if (this.state === 'hello' && this.nonce) this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL, 1], hostVersion: this.o.hostVersion }));
60
+ else if (this.state === 'hello' && this.nonce) this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL], hostVersion: this.o.hostVersion }));
62
61
  } else if (m.kind === 'connect' && this.state === 'hello') {
63
62
  const c = parseConnect(m);
64
63
  if (!c || c.nonce !== this.nonce || negotiateProtocol(c.protocol, [EGEN_EMBED_PROTOCOL]) === null) return true;
@@ -76,18 +75,13 @@ export class HostConnection {
76
75
  if (avail.has(g.id)) granted.push(g);
77
76
  else denied.push({ id: g.id, reason: 'UNAVAILABLE' });
78
77
  }
79
- const { table, subscribe, cleanup } = createCapabilityTable({
78
+ const { table, subscribe } = createCapabilityTable({
80
79
  moduleName: this.o.moduleName,
81
80
  granted,
82
81
  providers: this.o.providers,
83
82
  controls: this.o.controls,
84
- callApp: (cap, method, args) => {
85
- if (!this.rpc) return Promise.reject(new Error('non connecté'));
86
- return this.rpc.call(cap, method, args);
87
- },
88
83
  });
89
84
  const { port1, port2 } = new MessageChannel();
90
- this.cleanup = cleanup;
91
85
  this.rpc = new RpcEndpoint({
92
86
  port: port1,
93
87
  handlers: table,
@@ -95,8 +89,6 @@ export class HostConnection {
95
89
  validate: (cap, method, args) => validateCall(cap, method, args, 'app-to-host'),
96
90
  limits: this.o.limits,
97
91
  onClose: (reason) => {
98
- this.cleanup?.();
99
- this.cleanup = undefined;
100
92
  if (this.state !== 'closed') this.state = 'idle';
101
93
  this.o.onClose?.(reason);
102
94
  },
@@ -119,8 +111,6 @@ export class HostConnection {
119
111
  reset(): void {
120
112
  this.rpc?.close();
121
113
  this.rpc = undefined;
122
- this.cleanup?.();
123
- this.cleanup = undefined;
124
114
  this.nonce = undefined;
125
115
  if (this.state !== 'closed') this.state = 'idle';
126
116
  }
package/src/host.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type Limits } from '@egen-civitas/esm-embed-protocol';
1
+ import { sanitizeIframeRights, type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits } from '@egen-civitas/esm-embed-protocol';
2
2
  import { createBus } from './bus.js';
3
3
  import { HostConnection } from './connection.js';
4
4
  import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath, type NavigationOptions } from './navigation.js';
@@ -6,7 +6,7 @@ import type { HostProviders, Unsub } from './providers.js';
6
6
  import type { HostControls } from './table.js';
7
7
 
8
8
  export interface EmbedHostOptions {
9
- /** Nom du module (= `name` du manifeste). */
9
+ /** Nom du module (= `name` de `egen-config.json`). */
10
10
  moduleName: string;
11
11
  /** URL de base de l'application embarquée. */
12
12
  src: string;
@@ -15,8 +15,11 @@ export interface EmbedHostOptions {
15
15
  /** Grants effectifs (`effectiveGrants(manifeste.capabilities, approuvés)`). */
16
16
  grants: EffectiveGrants;
17
17
  providers: HostProviders;
18
- /** Attribut `sandbox` (défaut : scripts, même origine, formulaires, popups). */
19
- sandbox?: string;
18
+ /**
19
+ * Droits d'iframe EFFECTIFS (`effectiveIframe(manifeste.iframe, approuvés.iframe)`) : ils étendent le socle
20
+ * (`allow-scripts allow-same-origin allow-forms allow-popups`). Les jetons hors liste blanche sont écartés.
21
+ */
22
+ iframe?: IframeRights;
20
23
  title?: string;
21
24
  minHeight?: number;
22
25
  /** Navigation partagée Core ↔ app (URL du Core = source de vérité). Absent ou `none` : opaque. */
@@ -25,8 +28,6 @@ export interface EmbedHostOptions {
25
28
  onNavigate?: (to: string) => void;
26
29
  limits?: Partial<Limits>;
27
30
  hostVersion?: string;
28
- /** Accepter aussi les apps qui parlent encore le pont 1.1 (défaut : oui). */
29
- legacy?: boolean;
30
31
  window?: Window;
31
32
  onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
32
33
  onClose?(reason: string): void;
@@ -41,11 +42,12 @@ export interface EmbedHost {
41
42
  destroy(): void;
42
43
  }
43
44
 
44
- const DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups';
45
+ /** Socle d'isolation appliqué à toute app embarquée ; les droits négociés (`iframe`) ne peuvent que l'étendre. */
46
+ const BASE_SANDBOX = ['allow-scripts', 'allow-same-origin', 'allow-forms', 'allow-popups'];
45
47
 
46
48
  /**
47
49
  * Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
48
- * événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
50
+ * événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
49
51
  * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
50
52
  */
51
53
  export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
@@ -63,7 +65,8 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
63
65
  const src = nav ? buildEmbedSrc(opts.src, initialAppPath, nav.mode) : opts.src;
64
66
  const origin = opts.allowedOrigin ?? new URL(src, win.location.href).origin;
65
67
  if (origin === '*' || origin === 'null') throw new Error('allowedOrigin invalide : une origine explicite est requise.');
66
- const sandbox = opts.sandbox ?? DEFAULT_SANDBOX;
68
+ const rights = sanitizeIframeRights(opts.iframe);
69
+ const sandbox = [...new Set([...BASE_SANDBOX, ...rights.sandbox])].join(' ');
67
70
  if (origin === win.location.origin && /allow-scripts/.test(sandbox) && /allow-same-origin/.test(sandbox)) {
68
71
  console.warn(`[egen] ${opts.moduleName} : application embarquée de même origine que le Shell avec « allow-scripts allow-same-origin » : le bac à sable est sans effet. Héberger l'application sur une autre origine (sous-domaine).`);
69
72
  }
@@ -72,6 +75,7 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
72
75
  iframe.src = src;
73
76
  iframe.title = opts.title ?? opts.moduleName;
74
77
  iframe.setAttribute('sandbox', sandbox);
78
+ if (rights.allow.length) iframe.setAttribute('allow', rights.allow.join('; '));
75
79
  iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
76
80
  iframe.setAttribute('data-egen-fill', '');
77
81
  iframe.style.cssText = `width:100%;border:0;display:block;min-height:${opts.minHeight ?? 400}px`;
@@ -80,13 +84,10 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
80
84
  const allowLocation = createRateLimiter();
81
85
  const stop: Unsub[] = [];
82
86
  let seq = 0;
83
- let legacySeen = false;
84
- let legacyReady = false;
85
87
 
86
88
  const postRaw = (message: unknown, transfer?: Transferable[]) => iframe.contentWindow?.postMessage(message, origin, transfer);
87
- const legacySend = (message: unknown) => postRaw({ egen: 1, moduleName: opts.moduleName, message });
88
89
 
89
- /** Page courante annoncée par l'app → URL du Core (partagé entre le protocole 2 et le pont 1.1). */
90
+ /** Page courante annoncée par l'app → URL du Core. */
90
91
  const reportLocation = (path: unknown, o?: { replace?: boolean; title?: string }) => {
91
92
  if (!nav || !allowLocation()) return;
92
93
  if (typeof o?.title === 'string') {
@@ -124,41 +125,9 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
124
125
  onClose: opts.onClose,
125
126
  });
126
127
 
127
- /**
128
- * Pont 1.1 : compatibilité des apps qui ne parlent pas encore le protocole 2. La session n'est PLUS transmise (règle d'or,
129
- * doc 17 §2) : une app obtient son identité auprès de Keycloak. Seuls restent la langue, la navigation, le titre et la hauteur.
130
- */
131
- const handleLegacy = async (data: any) => {
132
- if (opts.legacy === false || connection.connected) return;
133
- if (!data || data.egen !== 1 || data.moduleName !== opts.moduleName || !data.message || typeof data.message.kind !== 'string') return;
134
- const msg = data.message;
135
- switch (msg.kind) {
136
- case 'ready': {
137
- legacySeen = true;
138
- legacyReady = true;
139
- const locale = opts.providers.locale ? await opts.providers.locale.get() : (win as any).i18next?.language;
140
- legacySend({ kind: 'init', payload: { moduleName: opts.moduleName, locale, spaBase: spaBase(), navigation: nav ? { mode: nav.mode, route: nav.route } : undefined } });
141
- break;
142
- }
143
- case 'navigate':
144
- controls.navigate?.(msg.to);
145
- break;
146
- case 'resize':
147
- controls.resize?.(msg.height);
148
- break;
149
- case 'title':
150
- if (typeof msg.title === 'string') iframe.title = msg.title.slice(0, 200);
151
- break;
152
- case 'location':
153
- legacySeen = true;
154
- reportLocation(msg.path, { replace: !!msg.replace, title: msg.title });
155
- break;
156
- }
157
- };
158
-
159
128
  const onMessage = (event: MessageEvent) => {
160
129
  if (event.source !== iframe.contentWindow || event.origin !== origin) return;
161
- if (!connection.handle(event.data)) void handleLegacy(event.data);
130
+ connection.handle(event.data);
162
131
  };
163
132
 
164
133
  return {
@@ -180,7 +149,6 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
180
149
  const appPath = toAppPath(cur, nav);
181
150
  if (!appPath) return;
182
151
  if (connection.connected) channel.emit('goto', { path: appPath, seq: ++seq });
183
- else if (legacySeen) legacySend({ kind: 'goto', path: appPath, seq: ++seq });
184
152
  else iframe.src = buildEmbedSrc(opts.src, appPath, nav.mode);
185
153
  };
186
154
  win.addEventListener('single-spa:routing-event', onCoreLocation);
@@ -203,10 +171,6 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
203
171
  win.removeEventListener('blur', onBlur);
204
172
  });
205
173
 
206
- // Pont 1.1 : la langue est poussée après `ready`.
207
- const p = opts.providers;
208
- if (p.locale?.subscribe) stop.push(p.locale.subscribe((l) => legacyReady && !connection.connected && l && legacySend({ kind: 'locale', locale: l })));
209
-
210
174
  container.appendChild(iframe);
211
175
  },
212
176
  async canLeave(timeoutMs = 1500) {
package/src/navigation.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
2
+ * Navigation partagée Shell ↔ application embarquée (capacité `navigation` du protocole 2).
3
3
  *
4
4
  * L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
5
5
  * Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
package/src/providers.ts CHANGED
@@ -12,6 +12,8 @@ export interface CallerContext {
12
12
  }
13
13
 
14
14
  export interface NotificationInput {
15
+ /** Clé de dédoublonnage facultative : un même `id` ne produit pas deux toasts rapprochés. */
16
+ id?: string;
15
17
  kind: 'info' | 'success' | 'warning' | 'error';
16
18
  title: string;
17
19
  subtitle?: string;
@@ -25,12 +27,6 @@ export interface ExtensionInfo {
25
27
  meta: Record<string, unknown>;
26
28
  }
27
29
 
28
- export interface AiToolDescriptor {
29
- name: string;
30
- description: string;
31
- inputSchema?: Record<string, unknown>;
32
- }
33
-
34
30
  /**
35
31
  * Services du Core mis à disposition des apps embarquées. Toute capacité sans fournisseur est
36
32
  * automatiquement refusée à la négociation (`UNAVAILABLE`) : on ne promet que ce qu'on sait servir.
@@ -44,7 +40,8 @@ export interface HostProviders {
44
40
  config?: Watchable<Record<string, unknown>>;
45
41
  flags?: { isEnabled(name: string): boolean | Promise<boolean>; subscribe?(cb: () => void): Unsub };
46
42
  events?: { publish(topic: string, payload: unknown, ctx: CallerContext): void; subscribe(topic: string, cb: (payload: unknown) => void): Unsub };
47
- notifications?: { show(n: NotificationInput, ctx: CallerContext): void | Promise<void> };
43
+ /** Affiche le toast dans l'interface du Core ; retourne `false` si non affiché (doublon, etc.). Le Core attribue le toast à son app d'origine. */
44
+ notifications?: { show(n: NotificationInput, ctx: CallerContext): void | boolean | Promise<void | boolean> };
48
45
  dialogs?: { confirm(d: { title: string; message: string; danger?: boolean }, ctx: CallerContext): boolean | Promise<boolean> };
49
46
  /** Extensions attachées à un slot du Core (apps internes, framework, autres apps) : métadonnées seulement, jamais le rendu. */
50
47
  extensions?: { list(slot: string): ExtensionInfo[] | Promise<ExtensionInfo[]>; subscribe?(slot: string, cb: (list: ExtensionInfo[]) => void): Unsub };
@@ -52,8 +49,4 @@ export interface HostProviders {
52
49
  log(level: 'debug' | 'info' | 'warn' | 'error', message: string, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
53
50
  metric(name: string, value: number, tags: Record<string, unknown> | undefined, from: CallerContext): void;
54
51
  };
55
- aiTools?: {
56
- register(moduleName: string, tools: AiToolDescriptor[], invoke: (name: string, args: Record<string, unknown>) => Promise<unknown>): void;
57
- unregister(moduleName: string, names: string[]): void;
58
- };
59
52
  }
package/src/table.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  CAPABILITIES,
3
+ createSlidingLimiter,
4
+ notificationPolicy,
3
5
  EmbedError,
4
6
  slotAllowed,
5
7
  topicAllowed,
@@ -35,7 +37,6 @@ export function availableCapabilities(p: HostProviders): Set<CapabilityId> {
35
37
  ['notifications', p.notifications],
36
38
  ['dialogs', p.dialogs],
37
39
  ['extensions', p.extensions],
38
- ['ai-tools', p.aiTools],
39
40
  ];
40
41
  for (const [id, prov] of map) if (prov) s.add(id);
41
42
  return s;
@@ -48,20 +49,17 @@ export interface TableOptions {
48
49
  granted: CapabilityGranted[];
49
50
  providers: HostProviders;
50
51
  controls: HostControls;
51
- /** Appel hôte → app (`ai-tools.invoke`). */
52
- callApp: (cap: string, method: string, args: unknown[]) => Promise<unknown>;
53
52
  }
54
53
 
55
54
  /**
56
55
  * Construit la table de dispatch FERMÉE d'une connexion : seules les capacités accordées (et servies) y figurent,
57
- * chaque méthode applique son grant (sujets d'événements, slots découvrables, drapeaux, outils IA).
56
+ * chaque méthode applique son grant (sujets d'événements, slots découvrables, drapeaux).
58
57
  */
59
- export function createCapabilityTable(o: TableOptions): { table: HandlerTable; subscribe: SubscribeHandler; cleanup: () => void } {
58
+ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; subscribe: SubscribeHandler } {
60
59
  const { providers: p, controls: c } = o;
61
60
  const ctx: CallerContext = { moduleName: o.moduleName };
62
61
  const cfgOf = new Map(o.granted.map((g) => [g.id, g.config]));
63
62
  const table: HandlerTable = {};
64
- const registeredTools = new Set<string>();
65
63
 
66
64
  const denied = (msg: string) => new EmbedError('DENIED', msg);
67
65
 
@@ -87,7 +85,17 @@ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; s
87
85
  },
88
86
  };
89
87
  }
90
- if (cfgOf.has('notifications') && p.notifications) table.notifications = { show: async (n: any) => void (await p.notifications!.show(n, ctx)) };
88
+ if (cfgOf.has('notifications') && p.notifications) {
89
+ // Anti-spam : une iframe ne doit pas pouvoir inonder l'interface du Core (ni imiter des messages système en rafale).
90
+ const policy = notificationPolicy(cfgOf.get('notifications'));
91
+ const allow = createSlidingLimiter(policy.rate.max, policy.rate.perSeconds);
92
+ table.notifications = {
93
+ show: async (n: any) => {
94
+ if (!allow()) throw new EmbedError('RATE_LIMITED', 'Trop de notifications');
95
+ return { displayed: (await p.notifications!.show(n, ctx)) !== false };
96
+ },
97
+ };
98
+ }
91
99
  if (cfgOf.has('dialogs') && p.dialogs) table.dialogs = { confirm: async (d: any) => !!(await p.dialogs!.confirm(d, ctx)) };
92
100
  if (cfgOf.has('extensions') && p.extensions) {
93
101
  const discover = list(cfgOf.get('extensions'), 'discover');
@@ -98,20 +106,6 @@ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; s
98
106
  },
99
107
  };
100
108
  }
101
- if (cfgOf.has('ai-tools') && p.aiTools) {
102
- const allowed = list(cfgOf.get('ai-tools'), 'tools');
103
- table['ai-tools'] = {
104
- register: (tools: Array<{ name: string; description: string; inputSchema?: Record<string, unknown> }>) => {
105
- for (const t of tools) if (!topicAllowed(allowed, t.name)) throw denied(`Outil non autorisé : ${t.name}`);
106
- p.aiTools!.register(o.moduleName, tools, (name, args) => o.callApp('ai-tools', 'invoke', [name, args]));
107
- for (const t of tools) registeredTools.add(t.name);
108
- },
109
- unregister: (names: string[]) => {
110
- p.aiTools!.unregister(o.moduleName, names);
111
- for (const n of names) registeredTools.delete(n);
112
- },
113
- };
114
- }
115
109
  if (cfgOf.has('telemetry')) {
116
110
  table.telemetry = {
117
111
  log: (level: any, message: string, extra?: Record<string, unknown>) => void p.telemetry?.log(level, message, extra, ctx),
@@ -155,9 +149,5 @@ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; s
155
149
  return {
156
150
  table,
157
151
  subscribe,
158
- cleanup: () => {
159
- if (registeredTools.size && p.aiTools) p.aiTools.unregister(o.moduleName, [...registeredTools]);
160
- registeredTools.clear();
161
- },
162
152
  };
163
153
  }