imio.omnia.tinymce 1.0__py3-none-any.whl

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.
Files changed (90) hide show
  1. imio/omnia/tinymce/__init__.py +6 -0
  2. imio/omnia/tinymce/browser/__init__.py +0 -0
  3. imio/omnia/tinymce/browser/action.py +6 -0
  4. imio/omnia/tinymce/browser/configure.zcml +40 -0
  5. imio/omnia/tinymce/browser/controlpanel.py +93 -0
  6. imio/omnia/tinymce/browser/npm/package-lock.json +125 -0
  7. imio/omnia/tinymce/browser/npm/package.json +8 -0
  8. imio/omnia/tinymce/browser/overrides/.gitkeep +0 -0
  9. imio/omnia/tinymce/browser/resources/.env.example +13 -0
  10. imio/omnia/tinymce/browser/resources/.git +1 -0
  11. imio/omnia/tinymce/browser/resources/.gitignore +26 -0
  12. imio/omnia/tinymce/browser/resources/.gitlab-ci.yml +77 -0
  13. imio/omnia/tinymce/browser/resources/.storybook/main.js +124 -0
  14. imio/omnia/tinymce/browser/resources/.storybook/preview.js +8 -0
  15. imio/omnia/tinymce/browser/resources/CHANGELOG.md +19 -0
  16. imio/omnia/tinymce/browser/resources/CLAUDE.md +62 -0
  17. imio/omnia/tinymce/browser/resources/Makefile +28 -0
  18. imio/omnia/tinymce/browser/resources/README.md +327 -0
  19. imio/omnia/tinymce/browser/resources/dev/index.html +41 -0
  20. imio/omnia/tinymce/browser/resources/dev/vite.config.js +78 -0
  21. imio/omnia/tinymce/browser/resources/docs/images/example1.png +0 -0
  22. imio/omnia/tinymce/browser/resources/eslint.config.js +36 -0
  23. imio/omnia/tinymce/browser/resources/package-lock.json +4913 -0
  24. imio/omnia/tinymce/browser/resources/package.json +61 -0
  25. imio/omnia/tinymce/browser/resources/src/assets/ia-icon.svg +5 -0
  26. imio/omnia/tinymce/browser/resources/src/assets/omnia-icon.svg +10 -0
  27. imio/omnia/tinymce/browser/resources/src/client.js +239 -0
  28. imio/omnia/tinymce/browser/resources/src/config.js +220 -0
  29. imio/omnia/tinymce/browser/resources/src/plugin.js +158 -0
  30. imio/omnia/tinymce/browser/resources/src/shortcuts.js +92 -0
  31. imio/omnia/tinymce/browser/resources/src/ui/App.jsx +75 -0
  32. imio/omnia/tinymce/browser/resources/src/ui/FloatingPanel.jsx +375 -0
  33. imio/omnia/tinymce/browser/resources/src/ui/PanelHeader.jsx +15 -0
  34. imio/omnia/tinymce/browser/resources/src/ui/SidePanel.jsx +284 -0
  35. imio/omnia/tinymce/browser/resources/src/ui/StreamingText.jsx +143 -0
  36. imio/omnia/tinymce/browser/resources/src/ui/components.jsx +70 -0
  37. imio/omnia/tinymce/browser/resources/src/ui/mount.jsx +35 -0
  38. imio/omnia/tinymce/browser/resources/src/ui/omnia.css +35 -0
  39. imio/omnia/tinymce/browser/resources/src/utils.js +56 -0
  40. imio/omnia/tinymce/browser/resources/stories/FloatingPanel.stories.jsx +66 -0
  41. imio/omnia/tinymce/browser/resources/stories/SidePanel.stories.jsx +31 -0
  42. imio/omnia/tinymce/browser/resources/stories/StreamingText.stories.jsx +85 -0
  43. imio/omnia/tinymce/browser/resources/stories/TinyMCEEditor.stories.js +228 -0
  44. imio/omnia/tinymce/browser/resources/stories/TypingDots.stories.jsx +31 -0
  45. imio/omnia/tinymce/browser/resources/stories/mocks/editor.js +66 -0
  46. imio/omnia/tinymce/browser/resources/stories/mocks/omnia-client.js +99 -0
  47. imio/omnia/tinymce/browser/resources/stories/presets/accessibilite-reglement.html +49 -0
  48. imio/omnia/tinymce/browser/resources/stories/presets/ameliorer-communication.html +36 -0
  49. imio/omnia/tinymce/browser/resources/stories/presets/corriger-bulletin.html +186 -0
  50. imio/omnia/tinymce/browser/resources/stories/presets/long-cdld.html +12389 -0
  51. imio/omnia/tinymce/browser/resources/stories/presets/reduire-deliberation.html +87 -0
  52. imio/omnia/tinymce/browser/resources/stories/presets/traduire-guide.html +234 -0
  53. imio/omnia/tinymce/browser/resources/vite.config.js +27 -0
  54. imio/omnia/tinymce/browser/static/omnia-tinymce.css +1 -0
  55. imio/omnia/tinymce/browser/static/omnia-tinymce.js +22 -0
  56. imio/omnia/tinymce/browser/templates/omnia_config.pt +10 -0
  57. imio/omnia/tinymce/browser/viewlets.py +57 -0
  58. imio/omnia/tinymce/configure.zcml +42 -0
  59. imio/omnia/tinymce/interfaces.py +7 -0
  60. imio/omnia/tinymce/locales/README.rst +37 -0
  61. imio/omnia/tinymce/locales/__init__.py +0 -0
  62. imio/omnia/tinymce/locales/en/LC_MESSAGES/imio.omnia.tinymce.po +83 -0
  63. imio/omnia/tinymce/locales/fr/LC_MESSAGES/imio.omnia.tinymce.po +83 -0
  64. imio/omnia/tinymce/locales/imio.omnia.tinymce.pot +86 -0
  65. imio/omnia/tinymce/locales/update.py +74 -0
  66. imio/omnia/tinymce/locales/update.sh +12 -0
  67. imio/omnia/tinymce/permissions.zcml +10 -0
  68. imio/omnia/tinymce/profiles/default/actions.xml +13 -0
  69. imio/omnia/tinymce/profiles/default/browserlayer.xml +7 -0
  70. imio/omnia/tinymce/profiles/default/catalog.xml +4 -0
  71. imio/omnia/tinymce/profiles/default/metadata.xml +7 -0
  72. imio/omnia/tinymce/profiles/default/registry/main.xml +35 -0
  73. imio/omnia/tinymce/profiles/default/rolemap.xml +7 -0
  74. imio/omnia/tinymce/profiles/uninstall/browserlayer.xml +7 -0
  75. imio/omnia/tinymce/setuphandlers.py +45 -0
  76. imio/omnia/tinymce/testing.py +48 -0
  77. imio/omnia/tinymce/tests/__init__.py +0 -0
  78. imio/omnia/tinymce/tests/robot/test_example.robot +66 -0
  79. imio/omnia/tinymce/tests/test_robot.py +28 -0
  80. imio/omnia/tinymce/tests/test_setup.py +68 -0
  81. imio/omnia/tinymce/tests/test_viewlet.py +99 -0
  82. imio.omnia.tinymce-1.0-py3.12-nspkg.pth +2 -0
  83. imio_omnia_tinymce-1.0.dist-info/METADATA +294 -0
  84. imio_omnia_tinymce-1.0.dist-info/RECORD +90 -0
  85. imio_omnia_tinymce-1.0.dist-info/WHEEL +5 -0
  86. imio_omnia_tinymce-1.0.dist-info/entry_points.txt +5 -0
  87. imio_omnia_tinymce-1.0.dist-info/licenses/LICENSE.GPL +339 -0
  88. imio_omnia_tinymce-1.0.dist-info/licenses/LICENSE.rst +15 -0
  89. imio_omnia_tinymce-1.0.dist-info/namespace_packages.txt +2 -0
  90. imio_omnia_tinymce-1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@imiobe/omnia-tinymce",
3
+ "version": "0.1.0",
4
+ "description": "TinyMCE plugin for iMio's Omnia AI API — content generation, improvement, correction, accessibility and translation",
5
+ "type": "module",
6
+ "main": "dist/omnia-tinymce.umd.cjs",
7
+ "module": "dist/omnia-tinymce.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/omnia-tinymce.js",
11
+ "require": "./dist/omnia-tinymce.umd.cjs"
12
+ },
13
+ "./dist/omnia-tinymce.css": "./dist/omnia-tinymce.css"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "docs/images",
18
+ "README.md"
19
+ ],
20
+ "keywords": [
21
+ "tinymce",
22
+ "tinymce-plugin",
23
+ "ai",
24
+ "omnia",
25
+ "imio"
26
+ ],
27
+ "license": "SEE LICENSE IN LICENSE",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://gitlab.imio.be/imio/omnia-tinymce"
31
+ },
32
+ "peerDependencies": {
33
+ "tinymce": ">=6.0.0"
34
+ },
35
+ "scripts": {
36
+ "dev": "storybook dev -p 6006",
37
+ "build": "vite build",
38
+ "build-storybook": "storybook build",
39
+ "dev:integration": "vite serve dev/",
40
+ "lint": "eslint .",
41
+ "lint:fix": "eslint . --fix"
42
+ },
43
+ "dependencies": {
44
+ "motion": "^12.36.0",
45
+ "preact": "^10.29.0"
46
+ },
47
+ "devDependencies": {
48
+ "@eslint/js": "^10.0.1",
49
+ "@preact/preset-vite": "^2.10.3",
50
+ "@storybook/html": "^10.2.19",
51
+ "@storybook/html-vite": "^10.2.19",
52
+ "@tailwindcss/vite": "^4.2.1",
53
+ "eslint": "^10.0.3",
54
+ "globals": "^17.4.0",
55
+ "storybook": "^10.2.19",
56
+ "tailwindcss": "^4.2.1",
57
+ "tinymce": "^8.3.2",
58
+ "vite": "^7.3.1",
59
+ "vite-plugin-svgr": "^5.0.0"
60
+ }
61
+ }
@@ -0,0 +1,5 @@
1
+ <svg width="24" height="24" viewBox="0 0 1080 1080" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M882.746 381.027C894.249 392.529 900 407.471 900 425.74V855.446C900 873.095 894.249 887.811 882.746 899.652C871.244 911.549 856.697 917.413 839.048 917.413C821.4 917.413 807.078 911.662 795.914 900.103C784.75 888.6 778.829 874.053 778.153 856.405C761.237 876.083 738.402 892.773 709.589 906.7C680.776 920.57 650.442 927.506 618.641 927.506C571.898 927.506 529.553 915.496 491.662 891.42C453.716 867.4 423.719 834.02 401.785 791.393C379.739 748.767 368.8 700.276 368.8 646.147C368.8 592.018 379.683 543.414 401.278 500.393C422.93 457.428 452.531 423.823 490.14 399.803C527.749 375.783 569.191 363.717 614.581 363.717C647.059 363.717 677.563 369.637 706.037 381.478C734.455 393.375 758.531 408.43 778.209 426.698V425.683C778.209 408.035 783.96 393.375 795.519 381.478C807.022 369.694 821.569 363.717 839.217 363.717C856.866 363.717 871.413 369.468 882.915 381.027H882.859H882.746ZM741.503 767.543C769.3 735.347 783.115 694.863 783.115 646.147C783.115 597.431 769.188 556.777 741.503 524.243C713.705 491.766 677.845 475.471 633.808 475.471C589.772 475.471 554.87 491.766 527.128 524.243C499.387 556.721 485.517 597.431 485.517 646.147C485.517 694.863 499.218 735.404 526.621 767.543C554.08 799.738 589.772 815.808 633.808 815.808C677.845 815.808 713.705 799.738 741.503 767.543Z" fill="#282828"/>
3
+ <path d="M357.237 153.175C361.466 152.217 363.158 155.374 365.413 158.137C376.634 200.144 389.997 245.928 423.151 275.981C449.257 299.719 485.738 312.123 519.287 321.765C525.094 323.457 541.277 324.528 536.766 334.677C534.623 339.47 524.7 340.203 520.245 341.443C487.655 350.972 452.302 362.757 426.478 384.69C394.226 412.037 378.889 455.622 367.894 495.317C367.161 498.192 366.823 502.647 365.751 505.071C365.526 505.522 362.538 509.187 362.199 509.413C358.196 512.063 353.911 509.413 352.275 505.409C351.43 503.267 350.358 499.489 349.682 497.121C334.458 442.71 318.163 396.362 266.063 367.436C241.029 353.566 214.923 348.04 187.858 339.413C182.558 337.722 177.37 333.606 181.486 328.08C184.813 323.513 194.004 323.175 198.966 321.709C236.969 310.263 275.874 297.125 303.39 266.79C326.62 241.248 338.8 205.5 348.272 172.854C349.682 167.892 351.373 154.416 357.35 153.119H357.237V153.175Z" fill="#E6007E"/>
4
+ <path d="M220.219 398.451C218.922 420.892 218.302 439.668 218.302 446.716V842.761C218.302 864.018 224.109 881.779 235.612 895.988C247.114 910.197 261.662 917.358 279.31 917.358C296.958 917.358 311.506 910.31 323.008 895.988C334.51 881.723 340.262 863.962 340.262 842.761V575.386C318.666 501.465 292.448 438.766 220.275 398.395L220.219 398.451Z" fill="#282828"/>
5
+ </svg>
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 1080 1080" fill="none">
2
+ <path d="M1030.21 421.12C993.932 410.666 954.461 397.259 926.194 371.571C890.38 339.085 875.895 289.536 863.754 244.112C861.316 241.111 859.441 237.689 854.894 238.721H854.988C848.565 240.08 846.69 254.659 845.19 260.05C834.924 295.395 821.752 334.069 796.625 361.68C766.858 394.494 724.716 408.697 683.651 421.12C678.307 422.714 668.369 423.089 664.76 428.011C660.307 433.964 665.932 438.464 671.651 440.293C700.949 449.574 729.216 455.575 756.264 470.575C812.657 501.889 830.283 552.048 846.737 610.879C847.44 613.41 848.612 617.535 849.55 619.832C851.284 624.192 855.972 627.051 860.285 624.192C860.66 623.958 863.894 619.926 864.129 619.504C865.301 616.879 865.629 612.051 866.472 608.957C878.379 566.064 894.974 518.906 929.85 489.279C957.742 465.513 996.041 452.809 1031.29 442.449C1036.07 441.09 1046.81 440.246 1049.15 435.089C1054.03 424.073 1036.54 422.948 1030.26 421.073L1030.21 421.12Z" fill="#E6007E"/>
3
+ <path d="M217.46 645.991C210.053 624.803 204.99 602.677 202.318 579.52C151.128 605.911 100.642 635.585 52.3582 668.867C56.7647 666.711 61.6868 665.352 66.8901 665.024C67.7808 664.977 126.518 660.945 217.507 645.991H217.46Z" fill="#7D1751"/>
4
+ <path d="M30.4221 706.503C29.9065 698.628 31.7816 691.221 35.3911 684.846C27.8439 697.503 27.9845 713.816 37.3131 726.566C39.1413 729.051 41.2039 731.207 43.454 733.129C36.0474 726.52 31.1253 717.144 30.469 706.503H30.4221Z" fill="#7D1751"/>
5
+ <path d="M744.783 574.872C737.986 622.874 716.985 665.204 681.124 701.3C636.638 746.067 583.713 769.084 521.132 769.084C458.551 769.084 405.627 746.114 361.14 701.3C360.25 700.362 359.406 699.378 358.515 698.44C321.342 706.644 286.606 713.394 255.01 718.925C266.261 735.098 279.105 750.614 293.825 765.381C356.359 827.071 430.941 858.526 518.788 858.526C606.636 858.526 681.218 828.29 743.752 765.381C776.754 732.192 800.942 695.581 816.552 655.501C806.427 620.014 795.317 587.904 774.832 561.465C764.847 566.059 754.862 570.512 744.877 574.872H744.783Z" fill="#282828"/>
6
+ <path d="M254.776 639.566C272.964 636.285 292.184 632.582 312.201 628.41C310.279 623.863 308.497 619.269 306.904 614.628C298.888 591.095 294.903 566.016 294.903 539.156C294.903 537.937 294.95 536.718 294.997 535.452C295.841 474.184 317.498 422.103 361.094 378.226C404.408 333.458 458.504 310.442 521.085 310.442C580.01 310.442 630.356 330.833 673.202 370.585C703.25 360.882 732.877 348.834 756.69 327.974C752.471 323.286 748.159 318.645 743.658 314.098C681.124 252.455 606.496 221 518.695 221C430.894 221 356.265 251.236 293.731 314.145C231.197 375.835 199.93 450.886 199.93 539.156C199.93 552.937 200.774 566.391 202.321 579.517C204.993 602.674 210.055 624.8 217.462 645.989C229.369 644.02 241.791 641.91 254.729 639.566H254.776Z" fill="#282828"/>
7
+ <path d="M46.2221 673.078C48.2378 671.672 50.3004 670.266 52.363 668.859C46.269 671.813 41.1125 676.266 37.3154 681.751C39.7062 678.469 42.7063 675.516 46.2221 673.031V673.078Z" fill="#E6007E"/>
8
+ <path d="M388.424 691.598C445.661 678.238 511.664 660.425 581.886 637.127C634.483 619.595 689.423 598.969 744.785 574.827C754.769 570.468 764.754 566.014 774.739 561.42C767.004 551.436 758.004 542.201 747.082 533.95C741.175 529.497 734.753 525.278 727.721 521.387C718.721 516.371 709.58 512.434 700.345 509.012C581.371 559.733 464.787 593.438 372.158 615.189C351.485 620.064 331.468 624.423 312.202 628.408C292.185 632.533 273.012 636.236 254.777 639.565C241.839 641.909 229.37 644.065 217.51 645.987C126.521 660.941 67.7841 664.972 66.8935 665.019C61.6901 665.347 56.8149 666.707 52.3615 668.863C50.3458 670.269 48.2832 671.629 46.2206 673.082C42.6579 675.566 39.7047 678.52 37.3139 681.801C36.5639 682.785 36.0014 683.864 35.392 684.895C31.7824 691.27 29.9074 698.724 30.423 706.552C31.1262 717.24 36.0014 726.616 43.408 733.178C43.783 733.507 44.2049 733.835 44.6268 734.163C45.0018 734.444 45.3299 734.772 45.705 735.054C52.9241 740.585 62.112 743.632 71.9093 743.023C75.8939 742.741 146.866 737.96 254.918 718.975C286.513 713.443 321.249 706.693 358.423 698.489C368.267 696.333 378.205 694.083 388.377 691.692L388.424 691.598Z" fill="#E6007E"/>
9
+ <path d="M35.3927 684.846C36.0021 683.815 36.5646 682.736 37.3147 681.752C36.6115 682.736 36.0021 683.768 35.3927 684.846Z" fill="#E6007E"/>
10
+ </svg>
@@ -0,0 +1,239 @@
1
+ import { parseSSE } from './utils.js';
2
+
3
+ /**
4
+ * HTTP client for the Omnia AI API.
5
+ * All public methods return async iterables of text chunks (SSE streaming).
6
+ */
7
+ export class OmniaClient {
8
+ #baseUrl;
9
+ #application;
10
+ #municipality;
11
+ #authToken;
12
+ #onError;
13
+ #endpoints;
14
+
15
+ /**
16
+ * @param {{ baseUrl: string, application?: string, municipality?: string, authToken?: string, onError?: (err: Error) => void, endpoints?: Record<string, string> }} config
17
+ */
18
+ constructor({ baseUrl, application, municipality, authToken, onError, endpoints }) {
19
+ this.#baseUrl = baseUrl.replace(/\/+$/, '');
20
+ this.#application = application || null;
21
+ this.#municipality = municipality || null;
22
+ this.#authToken = authToken || null;
23
+ this.#onError = onError || null;
24
+ this.#endpoints = endpoints || {};
25
+ }
26
+
27
+ /**
28
+ * Internal: make a non-streaming JSON request and return the parsed body.
29
+ *
30
+ * @param {string} endpoint - Path relative to baseUrl
31
+ * @param {object} body - JSON request body
32
+ * @param {AbortSignal} [signal] - Optional abort signal
33
+ * @returns {Promise<object>}
34
+ */
35
+ #resolveUrl(endpoint) {
36
+ let url;
37
+ if (/^https?:\/\//.test(endpoint)) {
38
+ url = endpoint;
39
+ } else if (endpoint.startsWith('/')) {
40
+ url = `${this.#baseUrl}${endpoint}`;
41
+ } else {
42
+ url = `${this.#baseUrl}/${endpoint}`;
43
+ }
44
+
45
+ if (this.#authToken) {
46
+ // This is for Plone, where we need to add the CSRF token to the URL
47
+ // It also allows to authenticate the user.
48
+ // TODO: We might want to make this configurable and less Plone related
49
+ const sep = url.includes('?') ? '&' : '?';
50
+ url += `${sep}_authenticator=${encodeURIComponent(this.#authToken)}`;
51
+ }
52
+
53
+ return url;
54
+ }
55
+
56
+ #getEndpoint(key, fallback) {
57
+ return this.#endpoints[key] || fallback;
58
+ }
59
+
60
+ #buildHeaders(extra = {}) {
61
+ const headers = { 'Content-Type': 'application/json', ...extra };
62
+ if (this.#application) headers['x-imio-application'] = this.#application;
63
+ if (this.#municipality) headers['x-imio-municipality'] = this.#municipality;
64
+ return headers;
65
+ }
66
+
67
+ async #requestJSON(endpoint, body, signal) {
68
+ const url = this.#resolveUrl(endpoint);
69
+ const headers = this.#buildHeaders();
70
+
71
+ let response;
72
+ try {
73
+ response = await fetch(url, {
74
+ method: 'POST',
75
+ headers,
76
+ body: JSON.stringify(body),
77
+ signal,
78
+ });
79
+ } catch (err) {
80
+ if (err.name !== 'AbortError') this.#onError?.(err);
81
+ throw err;
82
+ }
83
+
84
+ if (!response.ok) {
85
+ const err = new Error(`Omnia API error: ${response.status} ${response.statusText}`);
86
+ err.status = response.status;
87
+ this.#onError?.(err);
88
+ throw err;
89
+ }
90
+
91
+ return response.json();
92
+ }
93
+
94
+ /**
95
+ * Internal: make a streaming request and return an async iterable of chunks.
96
+ *
97
+ * @param {string} endpoint - Path relative to baseUrl (e.g. '/generate')
98
+ * @param {object} body - JSON request body
99
+ * @param {AbortSignal} [signal] - Optional abort signal
100
+ * @returns {AsyncGenerator<string>}
101
+ */
102
+ async *#request(endpoint, body, signal) {
103
+ const url = this.#resolveUrl(endpoint);
104
+ const headers = this.#buildHeaders({ Accept: 'text/event-stream' });
105
+
106
+ let response;
107
+ try {
108
+ response = await fetch(url, {
109
+ method: 'POST',
110
+ headers,
111
+ body: JSON.stringify(body),
112
+ signal,
113
+ });
114
+ } catch (err) {
115
+ if (err.name !== 'AbortError') this.#onError?.(err);
116
+ throw err;
117
+ }
118
+
119
+ if (!response.ok) {
120
+ const err = new Error(`Omnia API error: ${response.status} ${response.statusText}`);
121
+ err.status = response.status;
122
+ this.#onError?.(err);
123
+ throw err;
124
+ }
125
+
126
+ yield* parseSSE(response, signal);
127
+ }
128
+
129
+ /**
130
+ * Generate content from a prompt.
131
+ * @param {string} prompt
132
+ * @param {{ tone?: string, signal?: AbortSignal }} [options]
133
+ */
134
+ async *generate(prompt, options = {}) {
135
+ const { signal, ...rest } = options;
136
+ yield* this.#request(this.#getEndpoint('generate', '/generate'), { prompt, ...rest }, signal);
137
+ }
138
+
139
+ /**
140
+ * Expand text (make it longer).
141
+ * @param {string} text
142
+ * @param {{ expansionTarget?: number, signal?: AbortSignal }} [options]
143
+ * @returns {Promise<string>}
144
+ */
145
+ async expandText(text, options = {}) {
146
+ const { signal, expansionTarget, ...rest } = options;
147
+ const body = { input: text, ...rest };
148
+ if (expansionTarget !== undefined) body.expansion_target = expansionTarget;
149
+ const data = await this.#requestJSON(
150
+ this.#getEndpoint('expand-text', '/v1/agents/expand-text'),
151
+ body,
152
+ signal,
153
+ );
154
+ return data.result;
155
+ }
156
+
157
+ /**
158
+ * Improve text quality and style.
159
+ * @param {string} text
160
+ * @param {{ signal?: AbortSignal }} [options]
161
+ * @returns {Promise<string>}
162
+ */
163
+ async improveText(text, options = {}) {
164
+ const { signal } = options;
165
+ const data = await this.#requestJSON(
166
+ this.#getEndpoint('improve-text', '/v1/agents/improve-text'),
167
+ { input: text },
168
+ signal,
169
+ );
170
+ return data.result;
171
+ }
172
+
173
+ /**
174
+ * Reduce text length.
175
+ * @param {string} text
176
+ * @param {{ reductionTarget?: number, signal?: AbortSignal }} [options]
177
+ * @returns {Promise<string>}
178
+ */
179
+ async reduceText(text, options = {}) {
180
+ const { signal, reductionTarget } = options;
181
+ const body = { input: text };
182
+ if (reductionTarget !== undefined) body.reduction_target = reductionTarget;
183
+ const data = await this.#requestJSON(
184
+ this.#getEndpoint('reduce-text', '/v1/agents/reduce-text'),
185
+ body,
186
+ signal,
187
+ );
188
+ return data.result;
189
+ }
190
+
191
+ /**
192
+ * Correct spelling and grammar.
193
+ * @param {string} text
194
+ * @param {{ signal?: AbortSignal }} [options]
195
+ * @returns {Promise<string>}
196
+ */
197
+ async correctText(text, options = {}) {
198
+ const { signal } = options;
199
+ const data = await this.#requestJSON(
200
+ this.#getEndpoint('correct-text', '/v1/agents/correct-text'),
201
+ { input: text },
202
+ signal,
203
+ );
204
+ return data.result;
205
+ }
206
+
207
+ /**
208
+ * Rewrite text for WCAG accessibility.
209
+ * @param {string} text
210
+ * @param {{ signal?: AbortSignal }} [options]
211
+ * @returns {Promise<string>}
212
+ */
213
+ async makeAccessible(text, options = {}) {
214
+ const { signal } = options;
215
+ const data = await this.#requestJSON(
216
+ this.#getEndpoint('make-accessible', '/v1/agents/make-accessible'),
217
+ { input: text },
218
+ signal,
219
+ );
220
+ return data.result;
221
+ }
222
+
223
+ /**
224
+ * Translate text using the structured agents endpoint.
225
+ * @param {string} text
226
+ * @param {string} targetLang - fr | nl | de | en | es | it
227
+ * @param {{ signal?: AbortSignal }} [options]
228
+ * @returns {Promise<string>}
229
+ */
230
+ async translateText(text, targetLang, options = {}) {
231
+ const { signal } = options;
232
+ const data = await this.#requestJSON(
233
+ this.#getEndpoint('translate-text', '/v1/agents/translate-text'),
234
+ { input: text, target_language: targetLang },
235
+ signal,
236
+ );
237
+ return data.result;
238
+ }
239
+ }
@@ -0,0 +1,220 @@
1
+ export const FEATURE_DEFS = [
2
+ {
3
+ id: 'generate',
4
+ label: 'Générer du contenu',
5
+ menu: 'panel',
6
+ shortcut: 'g',
7
+ menuItem: { id: 'omnia-generate', text: 'Générer' },
8
+ },
9
+ {
10
+ id: 'expand-text',
11
+ label: 'Développer la sélection',
12
+ menu: 'floating',
13
+ shortcut: 'd',
14
+ menuItem: { id: 'omnia-expand-text', text: 'Développer' },
15
+ },
16
+ {
17
+ id: 'improve-text',
18
+ label: 'Améliorer',
19
+ menu: 'floating',
20
+ shortcut: 'a',
21
+ menuItem: { id: 'omnia-improve-text', text: 'Améliorer' },
22
+ },
23
+ {
24
+ id: 'reduce-text',
25
+ label: 'Réduire',
26
+ menu: 'floating',
27
+ shortcut: 'r',
28
+ menuItem: { id: 'omnia-reduce-text', text: 'Réduire' },
29
+ },
30
+ {
31
+ id: 'correct-text',
32
+ label: 'Corriger',
33
+ menu: 'floating',
34
+ shortcut: 'c',
35
+ menuItem: { id: 'omnia-correct-text', text: 'Corriger' },
36
+ },
37
+ {
38
+ id: 'make-accessible',
39
+ label: 'Rendre accessible',
40
+ menu: 'floating',
41
+ shortcut: 'x',
42
+ menuItem: { id: 'omnia-make-accessible', text: 'Rendre accessible' },
43
+ },
44
+ {
45
+ id: 'translate-text',
46
+ label: 'Traduire',
47
+ menu: 'floating',
48
+ shortcut: 't',
49
+ menuItem: { id: 'omnia-translate-text', text: 'Traduire' },
50
+ },
51
+ ];
52
+
53
+ export const FEATURE_IDS = FEATURE_DEFS.map((feature) => feature.id);
54
+
55
+ /** Features enabled by default (generate excluded — not yet implemented server-side). */
56
+ export const DEFAULT_ENABLED_FEATURES = FEATURE_IDS.filter((id) => id !== 'generate');
57
+
58
+ export const LANGUAGES = [
59
+ { code: 'fr', label: 'Français' },
60
+ { code: 'nl', label: 'Nederlands' },
61
+ { code: 'de', label: 'Deutsch' },
62
+ { code: 'en', label: 'English' },
63
+ { code: 'es', label: 'Español' },
64
+ { code: 'it', label: 'Italiano' },
65
+ ];
66
+
67
+ const DEFAULT_ENDPOINTS = {
68
+ generate: '/generate',
69
+ 'expand-text': '/v1/agents/expand-text',
70
+ 'improve-text': '/v1/agents/improve-text',
71
+ 'reduce-text': '/v1/agents/reduce-text',
72
+ 'correct-text': '/v1/agents/correct-text',
73
+ 'make-accessible': '/v1/agents/make-accessible',
74
+ 'translate-text': '/v1/agents/translate-text',
75
+ };
76
+
77
+ function stringArrayProcessor(value) {
78
+ if (Array.isArray(value) && value.every((item) => typeof item === 'string')) {
79
+ return { value, valid: true };
80
+ }
81
+
82
+ if (typeof value === 'string') {
83
+ return {
84
+ value: value
85
+ .split(',')
86
+ .map((item) => item.trim())
87
+ .filter(Boolean),
88
+ valid: true,
89
+ };
90
+ }
91
+
92
+ return { valid: false, message: 'Expected a string or an array of strings.' };
93
+ }
94
+
95
+ function objectProcessor(value) {
96
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
97
+ return { value, valid: true };
98
+ }
99
+
100
+ return { valid: false, message: 'Expected an object.' };
101
+ }
102
+
103
+ function shortcutsProcessor(value) {
104
+ if (typeof value === 'boolean') {
105
+ return { value, valid: true };
106
+ }
107
+
108
+ return objectProcessor(value);
109
+ }
110
+
111
+ export function registerOmniaOptions(editor) {
112
+ editor.options.register('omnia_base_url', { processor: 'string', default: '' });
113
+ editor.options.register('omnia_auth_token', { processor: 'string', default: '' });
114
+ editor.options.register('omnia_application', { processor: 'string', default: '' });
115
+ editor.options.register('omnia_municipality', { processor: 'string', default: '' });
116
+ editor.options.register('omnia_default_translate_language', { processor: 'string', default: 'fr' });
117
+ editor.options.register('omnia_enabled_features', {
118
+ processor: stringArrayProcessor,
119
+ default: DEFAULT_ENABLED_FEATURES,
120
+ });
121
+ editor.options.register('omnia_endpoints', { processor: objectProcessor, default: {} });
122
+ editor.options.register('omnia_shortcuts', { processor: shortcutsProcessor, default: true });
123
+ editor.options.register('omnia_toolbar', { processor: 'boolean', default: true });
124
+ editor.options.register('omnia_context_menu', { processor: 'boolean', default: true });
125
+ editor.options.register('omnia_translate_languages', {
126
+ processor: stringArrayProcessor,
127
+ default: LANGUAGES.map((language) => language.code),
128
+ });
129
+ editor.options.register('omnia_history_limit', { processor: 'number', default: 5 });
130
+ editor.options.register('omnia_floating_panel_mode', {
131
+ processor: (value) =>
132
+ value === 'inline' || value === 'blur'
133
+ ? { value, valid: true }
134
+ : { valid: false, message: 'Expected "inline" or "blur".' },
135
+ default: 'inline',
136
+ });
137
+ editor.options.register('omnia_floating_panel_width', {
138
+ processor: (value) => {
139
+ if (value === 'full') return { value, valid: true };
140
+ if (typeof value === 'number' && value > 0) return { value, valid: true };
141
+ return { valid: false, message: 'Expected a positive number or "full".' };
142
+ },
143
+ default: 500,
144
+ });
145
+ }
146
+
147
+ function normalizeFeatureIds(featureIds) {
148
+ const allowed = new Set(FEATURE_IDS);
149
+ return featureIds.filter((featureId) => allowed.has(featureId));
150
+ }
151
+
152
+ function normalizeLanguages(languageCodes, defaultLanguage) {
153
+ const available = new Map(LANGUAGES.map((language) => [language.code, language]));
154
+ const normalized = languageCodes
155
+ .filter((code) => available.has(code))
156
+ .map((code) => available.get(code));
157
+
158
+ const languages = normalized.length > 0 ? normalized : LANGUAGES;
159
+ const enabledCodes = new Set(languages.map((language) => language.code));
160
+
161
+ return {
162
+ languages,
163
+ defaultLanguage: enabledCodes.has(defaultLanguage) ? defaultLanguage : languages[0].code,
164
+ };
165
+ }
166
+
167
+ function normalizeShortcuts(shortcutsOption, enabledFeatureIds) {
168
+ if (shortcutsOption === false) {
169
+ return { enabled: false, prefix: 'o', timeoutMs: 1500, bindings: {} };
170
+ }
171
+
172
+ if (shortcutsOption === true) {
173
+ shortcutsOption = {};
174
+ }
175
+
176
+ const enabledSet = new Set(enabledFeatureIds);
177
+ const bindings = {};
178
+
179
+ for (const feature of FEATURE_DEFS) {
180
+ const configured = shortcutsOption.bindings?.[feature.id];
181
+ const binding = typeof configured === 'string' ? configured.toLowerCase() : feature.shortcut;
182
+ if (enabledSet.has(feature.id) && binding) {
183
+ bindings[feature.id] = binding;
184
+ }
185
+ }
186
+
187
+ return {
188
+ enabled: shortcutsOption.enabled !== false,
189
+ prefix:
190
+ typeof shortcutsOption.prefix === 'string' && shortcutsOption.prefix.length === 1
191
+ ? shortcutsOption.prefix.toLowerCase()
192
+ : 'o',
193
+ timeoutMs: Number.isFinite(shortcutsOption.timeoutMs) ? shortcutsOption.timeoutMs : 1500,
194
+ bindings,
195
+ };
196
+ }
197
+
198
+ export function resolveOmniaConfig(editor) {
199
+ const enabledFeatures = normalizeFeatureIds(editor.options.get('omnia_enabled_features'));
200
+ const { languages, defaultLanguage } = normalizeLanguages(
201
+ editor.options.get('omnia_translate_languages'),
202
+ editor.options.get('omnia_default_translate_language'),
203
+ );
204
+
205
+ return {
206
+ enabledFeatures,
207
+ endpoints: { ...DEFAULT_ENDPOINTS, ...editor.options.get('omnia_endpoints') },
208
+ shortcuts: normalizeShortcuts(editor.options.get('omnia_shortcuts'), enabledFeatures),
209
+ toolbar: editor.options.get('omnia_toolbar'),
210
+ contextMenu: editor.options.get('omnia_context_menu'),
211
+ defaultLanguage,
212
+ languages,
213
+ historyLimit: Math.max(1, editor.options.get('omnia_history_limit')),
214
+ floatingPanelMode: editor.options.get('omnia_floating_panel_mode'),
215
+ floatingPanelWidth: editor.options.get('omnia_floating_panel_width'),
216
+ authToken: editor.options.get('omnia_auth_token'),
217
+ application: editor.options.get('omnia_application'),
218
+ municipality: editor.options.get('omnia_municipality'),
219
+ };
220
+ }