best-email-builder 0.15.0 → 0.16.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +13 -6
  3. package/THIRD-PARTY-NOTICES.md +34 -0
  4. package/dist/ai-server.js +7 -3
  5. package/dist/ai-server.js.map +1 -1
  6. package/dist/ai.js +77 -85
  7. package/dist/ai.js.map +1 -1
  8. package/dist/builder.js +8 -8
  9. package/dist/{chunk-I6FP6BBI.js → chunk-6OR6W4KJ.js} +268 -55
  10. package/dist/chunk-6OR6W4KJ.js.map +1 -0
  11. package/dist/{chunk-ND3B5TL7.js → chunk-7H7TLQBL.js} +32 -11
  12. package/dist/chunk-7H7TLQBL.js.map +1 -0
  13. package/dist/{chunk-XALUYZYQ.js → chunk-AGA3BLRI.js} +2 -2
  14. package/dist/{chunk-RZ3O4MH5.js → chunk-EFE245KW.js} +311 -18
  15. package/dist/chunk-EFE245KW.js.map +1 -0
  16. package/dist/{chunk-QXE6LJG5.js → chunk-F5H7ITED.js} +3 -3
  17. package/dist/{chunk-OK3EIEUA.js → chunk-HAHHRMQG.js} +2062 -837
  18. package/dist/chunk-HAHHRMQG.js.map +1 -0
  19. package/dist/{chunk-RG2DTGST.js → chunk-MC7JUFHI.js} +4 -4
  20. package/dist/{chunk-GHFNJY4O.js → chunk-MSHGCLCA.js} +2 -2
  21. package/dist/{chunk-AT4EB2NS.js → chunk-QLUCTFJ2.js} +311 -3
  22. package/dist/chunk-QLUCTFJ2.js.map +1 -0
  23. package/dist/{chunk-6LTSEPQX.js → chunk-RPDQABWZ.js} +2 -2
  24. package/dist/{chunk-6ZX3VYE4.js → chunk-W5AJWWHH.js} +143 -19
  25. package/dist/chunk-W5AJWWHH.js.map +1 -0
  26. package/dist/de-BNFO6VLR.js +1875 -0
  27. package/dist/de-BNFO6VLR.js.map +1 -0
  28. package/dist/en-PBUZLCBA.js +1875 -0
  29. package/dist/en-PBUZLCBA.js.map +1 -0
  30. package/dist/es-M7A73ED7.js +1875 -0
  31. package/dist/es-M7A73ED7.js.map +1 -0
  32. package/dist/fr-SUFB35ZZ.js +1875 -0
  33. package/dist/fr-SUFB35ZZ.js.map +1 -0
  34. package/dist/index.js +10 -10
  35. package/dist/library.js +5 -5
  36. package/dist/pt-OEAULFDA.js +1875 -0
  37. package/dist/pt-OEAULFDA.js.map +1 -0
  38. package/dist/ru-ZCORYHGA.js +1875 -0
  39. package/dist/ru-ZCORYHGA.js.map +1 -0
  40. package/dist/server.js +63 -16
  41. package/dist/server.js.map +1 -1
  42. package/dist/styles.css +1 -1
  43. package/dist/types/ai/errors.d.ts +19 -7
  44. package/dist/types/ai/index.d.ts +1 -0
  45. package/dist/types/ai/languagetool.d.ts +46 -0
  46. package/dist/types/ai/rewrite.d.ts +9 -7
  47. package/dist/types/ai/server.d.ts +1 -0
  48. package/dist/types/ai/subjects.d.ts +1 -0
  49. package/dist/types/blocks/shared.d.ts +12 -9
  50. package/dist/types/core/EmailEditor.d.ts +85 -12
  51. package/dist/types/core/blockBox.d.ts +12 -0
  52. package/dist/types/core/constants.d.ts +1 -1
  53. package/dist/types/core/mjmlAttributes.d.ts +37 -0
  54. package/dist/types/core/textFormat.d.ts +4 -0
  55. package/dist/types/defaultEditor.d.ts +3 -1
  56. package/dist/types/engine/NativeAdapter.d.ts +5 -2
  57. package/dist/types/engine/canvas/CanvasView.d.ts +21 -0
  58. package/dist/types/engine/canvas/canvasStyles.d.ts +1 -1
  59. package/dist/types/engine/canvasMjml.d.ts +4 -2
  60. package/dist/types/engine/mjml.d.ts +7 -0
  61. package/dist/types/features/emoji/EmojiPanel.d.ts +3 -0
  62. package/dist/types/features/emoji/data/de.d.ts +2 -0
  63. package/dist/types/features/emoji/data/en.d.ts +2 -0
  64. package/dist/types/features/emoji/data/es.d.ts +2 -0
  65. package/dist/types/features/emoji/data/fr.d.ts +2 -0
  66. package/dist/types/features/emoji/data/pt.d.ts +2 -0
  67. package/dist/types/features/emoji/data/ru.d.ts +2 -0
  68. package/dist/types/features/emoji/data/zh.d.ts +2 -0
  69. package/dist/types/features/emoji/emojis.d.ts +33 -0
  70. package/dist/types/features/emoji/index.d.ts +2 -0
  71. package/dist/types/features/variables/VariableDialog.d.ts +9 -1
  72. package/dist/types/features/variables/VariablesPanel.d.ts +23 -0
  73. package/dist/types/features/variables/catalog.d.ts +12 -4
  74. package/dist/types/renderer/columnAlignment.d.ts +10 -0
  75. package/dist/types/renderer/compileEditorMjml.d.ts +2 -0
  76. package/dist/types/server/compileMjml.d.ts +5 -0
  77. package/dist/types/server/handler.d.ts +1 -1
  78. package/dist/types/server/render.d.ts +15 -4
  79. package/dist/types/server/sendTest.d.ts +2 -2
  80. package/dist/types/server/variables.d.ts +5 -0
  81. package/dist/types/storage/client.d.ts +6 -0
  82. package/dist/types/ui/BoxModel.d.ts +39 -0
  83. package/dist/types/ui/CanvasPanel.d.ts +19 -0
  84. package/dist/types/ui/TextRibbon.d.ts +25 -0
  85. package/dist/types/ui/fields.d.ts +16 -1
  86. package/dist/types/ui/primitives/color-picker.d.ts +18 -4
  87. package/dist/types/ui/useEmailEditorState.d.ts +1 -0
  88. package/dist/zh-KPGU7EQG.js +1875 -0
  89. package/dist/zh-KPGU7EQG.js.map +1 -0
  90. package/package.json +2 -1
  91. package/dist/chunk-6ZX3VYE4.js.map +0 -1
  92. package/dist/chunk-AT4EB2NS.js.map +0 -1
  93. package/dist/chunk-I6FP6BBI.js.map +0 -1
  94. package/dist/chunk-ND3B5TL7.js.map +0 -1
  95. package/dist/chunk-OK3EIEUA.js.map +0 -1
  96. package/dist/chunk-RZ3O4MH5.js.map +0 -1
  97. package/dist/types/features/variables/VariablesBar.d.ts +0 -23
  98. /package/dist/{chunk-XALUYZYQ.js.map → chunk-AGA3BLRI.js.map} +0 -0
  99. /package/dist/{chunk-QXE6LJG5.js.map → chunk-F5H7ITED.js.map} +0 -0
  100. /package/dist/{chunk-RG2DTGST.js.map → chunk-MC7JUFHI.js.map} +0 -0
  101. /package/dist/{chunk-GHFNJY4O.js.map → chunk-MSHGCLCA.js.map} +0 -0
  102. /package/dist/{chunk-6LTSEPQX.js.map → chunk-RPDQABWZ.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,134 @@ All notable changes are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.16.0] — 2026-10-26
10
+
11
+ ### Added
12
+ - A ribbon above the canvas, always open, as in a word processor: bold,
13
+ italic, underline, strikethrough, link, remove the link, clear formatting,
14
+ font size (typed or picked), line height and alignment, each tool
15
+ named in a tooltip. The word tools act on the selection of the text being
16
+ edited, or on the whole of a selected text, and show what is pressed at the
17
+ caret. `editor.formatText(command, value)` drives them; the editor's
18
+ `format` event reports the format at the caret.
19
+ - An emoji panel, opened from the end of the ribbon: every emoji up to
20
+ Unicode 14 by group, searchable by name or keyword in the interface's
21
+ language (accents optional), the recently used first. Like a variable, an
22
+ emoji under the pointer shows in the text, a click inserts it. The names
23
+ are loaded on first use, one language at a time (emojibase-data, MIT — see
24
+ THIRD-PARTY-NOTICES.md), and only the rows near the scroll are drawn.
25
+ - A feature may declare `drawer: {icon, label, title, panel}`: its button at
26
+ the end of the ribbon opens its panel beside the canvas, one at a time.
27
+ - The Spacing section of the properties is a box diagram, as in a browser's
28
+ developer tools: the margin outside, the border, the padding inside, the
29
+ content in the middle, each zone with its four sides typed in place and a
30
+ line saying what it sets. Every built-in block has the three zones.
31
+ - Borders: a width per side, a style (solid, dashed, dotted, double, groove,
32
+ ridge) and a color. On sections, columns, images and buttons, equal widths
33
+ write one `border` attribute; different ones write `border-top`,
34
+ `border-right`… A double, groove or ridge line starts at 3 px, the least
35
+ that draws it. A block property may take `type: 'border'`, and `box:
36
+ 'margin' | 'border' | 'padding'` to place it in the diagram.
37
+ - Spacing MJML has no attribute for (a section's margin, a text's border or
38
+ margin…) is kept in valid MJML: a section's margin as an `mj-wrapper`
39
+ (`css-class="eb-section-margin"`) around it, the others in an encoded
40
+ `eb-box-…` CSS class. The package's compiler (`compileMjml`, the server
41
+ handler) turns them into email tables; another MJML compiler ignores them.
42
+ - Vertical alignment on every block: on a content block it aligns its
43
+ column, on a layout all its columns. Columns of one desktop row now have
44
+ equal heights in the compiled email, their content where it is aligned;
45
+ stacked on mobile, they keep their own height. Outlook keeps MJML's table.
46
+ - The corner radius takes pixels or percentages, with no upper limit (a size
47
+ property may give `units: ['px', '%']`).
48
+ - Variable groups: the *Variables* panel lists the variables under their
49
+ group; the **+** beside *Group* creates an empty group, a group's **+** a
50
+ variable in it. A storage may give `listVariableGroups()` and
51
+ `saveVariableGroup(name)` (HTTP: `GET` and `POST /variable-groups`); a
52
+ server repository `listGroups()` and `insertGroup(name)`. New error codes:
53
+ `INVALID_GROUP`, `DUPLICATE_GROUP`, `NO_GROUP_STORE`.
54
+ - `--eb-accent-color`, set on `:root`, gives the accent of every screen (the
55
+ primary color, the focus ring and the light accent come from it).
56
+ - The storage may give `imageUrl(path)`: where the canvas, and the *Brand*
57
+ dialog for a logo, show an uploaded image when the page cannot load its
58
+ path itself (images on another origin, no server). The template and the
59
+ brand keep the path.
60
+
61
+ - The unsubscribe link is edited like the other variables, since each email
62
+ provider has its own: its *value if empty* is used when the sending gives
63
+ no `unsubscribeUrl` (an address, or the provider's tag such as `*|UNSUB|*`),
64
+ its *sample value* in the preview and test sends (`#` otherwise). Both must
65
+ be an address or a tag, never `javascript:`.
66
+ - Colors keep their transparency: the picker's alpha slider is written
67
+ `rgba()` in the email (MJML refuses `#RRGGBBAA`) and shown as `#RRGGBBAA` in
68
+ the field. Classic Outlook, which reads no `rgba()`, gets in `bgcolor` the
69
+ opaque color it looks like over white.
70
+ - *Background under the content* (Email → Colors): a color painted under the
71
+ sections, at the email's width. The rounded corners of a section show it
72
+ instead of the page background. MJML has no such attribute: it is written
73
+ as an `mj-wrapper` (`css-class="eb-content-layer"`) around the sections and
74
+ read back as `content-background-color` on `mj-body`. A full-width band or
75
+ an `mj-wrapper` of your own interrupts it. Left empty, the MJML is exactly
76
+ as before.
77
+ - *Proofread* without AI: `createLanguageToolProofreader({ url })` (from
78
+ `best-email-builder/ai` and `/ai/server`) is a `proofread` function that
79
+ asks a LanguageTool server. Its corrections show in the same dialog, as the
80
+ smallest change of their words: markup, links and merge tags stay. Style
81
+ suggestions, brands and acronyms, and a capital asked of a subject or a
82
+ button are left out; `ignoreWords` adds your own. Alone, it is the only
83
+ check, with no key; beside a provider, LanguageTool proofreads and the AI
84
+ writes. `LANGUAGETOOL_PUBLIC_API` is LanguageTool's free API, to try it
85
+ out (limited, and the texts go to LanguageTool). New error codes:
86
+ `CHECKER_UNAVAILABLE`, `CHECKER_BUSY`.
87
+
88
+ ### Fixed
89
+ - A color dragged in the picker (the area, the hue or the transparency
90
+ slider) paints the block as it moves, rather than when the mouse is
91
+ released. The whole drag is one undo step.
92
+ - Bold, italic… on a text only selected (not being edited) formatted it but
93
+ left it open with everything selected: the next emoji or variable replaced
94
+ the whole text. The format is applied to the whole text and the text is
95
+ closed at once; the ribbon shows the format of its words.
96
+ - An emoji clicked in the panel showed twice for a moment, and the grid moved
97
+ under the pointer as *Recently used* appeared.
98
+ - The live demo showed no uploaded image: it had no server to serve
99
+ `/email-assets/`. It now keeps uploads in the browser (Cache Storage, so
100
+ they outlive a reload) and shows them in the canvas, the preview and the
101
+ exported HTML.
102
+ - Removing the last column of a section left an empty section behind, shown
103
+ as a phantom block: the section goes with it.
104
+ - Dialogs, menus and tooltips could open under the host page's layers or the
105
+ canvas: they stay above.
106
+
107
+ ### Changed
108
+ - The space around a button, an image, a divider or the social icons is
109
+ called its margin (MJML's `padding` of these blocks); the button's inner
110
+ padding is its padding.
111
+ - The *Email provider variables* bar above the canvas is now the *Variables*
112
+ panel beside it, opened by the *Variables* button at the end of the ribbon.
113
+ It stays open while you insert, rather than growing under the pointer.
114
+ - *Write with AI* and *Rewrite with AI* are one section with ONE field: say
115
+ what to change in the text, or give a topic to write about — the model
116
+ tells which (`action: 'custom'` now does both; on a text with no words, the
117
+ words are a topic). The one-click rewrites stay under it.
118
+ - While the AI works on a text, it shimmers on the canvas; the answer comes
119
+ in word by word (at once with reduced motion). `editor.setContent` takes
120
+ `{ reveal: true }` for that, and `editor.showWorking(id)` shows the shimmer.
121
+ - The **×** of a variable cut over two lines sits at the variable's end, top
122
+ right of its last line, rather than after its first piece.
123
+ - The *Variables* panel shows the unsubscribe link among the others, with
124
+ its pencil, without a line between them. The panels beside the canvas show
125
+ no heading (their button names them), only their **×**; no line before the
126
+ ribbon's *Emojis* and *Variables* buttons.
127
+ - The *Brand* dialog: its fields are as high as the properties panel's; the
128
+ logo's square, larger and square, opens the file explorer (the *Upload*
129
+ button is gone); the preview is as tall as the fields beside it; the color
130
+ pickers have no transparency slider (brand colors stay opaque).
131
+ - `unsubscribeUrl` is optional: without it, `personalize` and `renderEmail`
132
+ use the link's value if empty, `sendTestEmail` its sample; the handler's
133
+ `previewUnsubscribeUrl` defaults to `null` (the sample, otherwise `#`).
134
+ - The *Proofread* dialog no longer says the AI reads the email: "Every text
135
+ is checked for spelling, grammar and punctuation mistakes", whoever checks.
136
+
9
137
  ## [0.15.0] — 2026-10-22
10
138
 
11
139
  ### Added
package/README.md CHANGED
@@ -52,6 +52,10 @@ once and given away.
52
52
  - Columns from 1/4 to 3/4 of the row, background images on sections,
53
53
  full-width images on phones.
54
54
  - Drag with a drop line, type in place, a toolbar and shortcuts on every element.
55
+ - A ribbon above the canvas, as in a word processor: bold, italic, underline,
56
+ strikethrough, link, size, line height and alignment, each tool
57
+ named in a tooltip. At its end, panels beside the canvas for the emojis
58
+ (searchable, named in seven languages) and the variables.
55
59
  - Desktop and mobile canvas, showing the real compiled email.
56
60
  - Undo and redo, autosave, local drafts, versions, and conflict detection
57
61
  between two editors.
@@ -66,10 +70,12 @@ once and given away.
66
70
 
67
71
  **AI, optional**
68
72
  - *Proofread* the whole email: spelling, grammar and punctuation in every
69
- text, each correction shown word by word, applied in one step.
70
- - *Write* a text on a topic, to fit the rest of the email.
71
- - *Rewrite* any text: shorter, longer, fixed, friendlier, more formal, or
72
- translated into 13 languages.
73
+ text, each correction shown word by word, applied in one step. By the AI,
74
+ or without AI by LanguageTool, on your own server.
75
+ - *Write with AI*, in one field: a text on a topic, or a change in your own
76
+ words, to fit the rest of the email; or in one click: shorter, longer,
77
+ fixed, friendlier, more formal, translated into 13 languages. The answer
78
+ comes in word by word.
73
79
  - *Suggest* three subject lines drawn from the email.
74
80
  - OpenRouter, Gemini, Groq, Mistral, OpenAI, DeepSeek, Cerebras, Ollama, any
75
81
  OpenAI-compatible API, Claude or your own agent. The model runs on your
@@ -145,7 +151,7 @@ the layout, Next.js, Express and image hosting.
145
151
  | [Editor and library](docs/EDITOR.md) | The three ways to mount them, every prop, theming. |
146
152
  | [Server](docs/SERVER.md) | Routes, handler options, the storage contract, your database. |
147
153
  | [Variables and sending](docs/VARIABLES.md) | Merge tags, custom variables, personalizing at send time. |
148
- | [AI](docs/AI.md) | Proofread, Write, Rewrite, Subjects. Where the model runs, and the providers. |
154
+ | [AI](docs/AI.md) | Proofread, Write with AI, Subjects. Where the model runs, and the providers. |
149
155
  | [Your own AI agent](docs/AGENT.md) | The `agent@1` protocol. |
150
156
  | [Brand](docs/BRAND.md) | Logo, colors and font, read from a website. |
151
157
  | [Languages](docs/LANGUAGES.md) | Seven built in, your own strings, adding one. |
@@ -178,7 +184,8 @@ channel described in [SECURITY.md](SECURITY.md).
178
184
 
179
185
  ## License
180
186
 
181
- [MIT](LICENSE). MJML and mjml-browser are MIT too.
187
+ [MIT](LICENSE). MJML and mjml-browser are MIT too. The emoji names come from
188
+ emojibase-data (MIT), see [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md).
182
189
 
183
190
  ## Author
184
191
 
@@ -0,0 +1,34 @@
1
+ # Third-party notices
2
+
3
+ best-email-builder is MIT licensed (see [LICENSE](LICENSE)). It ships data
4
+ derived from the following project, under its own license.
5
+
6
+ ## emojibase-data
7
+
8
+ The names and keywords of the emoji panel (`src/features/emoji/data/`, built
9
+ by `scripts/build-emoji-data.mjs`) come from
10
+ [emojibase-data](https://github.com/milesj/emojibase) 18.0.0.
11
+
12
+ ```
13
+ MIT License
14
+
15
+ Copyright (c) 2017-2019 Miles Johnson
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to deal
19
+ in the Software without restriction, including without limitation the rights
20
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in all
25
+ copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
34
+ ```
package/dist/ai-server.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  DEFAULT_CLAUDE_MODEL,
7
7
  EmailGenerationError,
8
8
  GENERATION_ERRORS,
9
+ LANGUAGETOOL_PUBLIC_API,
9
10
  PROOFREAD_SYSTEM_PROMPT,
10
11
  REWRITE_ACTIONS,
11
12
  REWRITE_LANGUAGES,
@@ -14,6 +15,7 @@ import {
14
15
  agentEmailModel,
15
16
  claudeEmailModel,
16
17
  createEmailGenerator,
18
+ createLanguageToolProofreader,
17
19
  createProofreader,
18
20
  createRewriter,
19
21
  createSubjectSuggester,
@@ -26,9 +28,9 @@ import {
26
28
  reviewFix,
27
29
  reviewRewrite,
28
30
  reviewSubjects
29
- } from "./chunk-I6FP6BBI.js";
30
- import "./chunk-XALUYZYQ.js";
31
- import "./chunk-RZ3O4MH5.js";
31
+ } from "./chunk-6OR6W4KJ.js";
32
+ import "./chunk-AGA3BLRI.js";
33
+ import "./chunk-EFE245KW.js";
32
34
 
33
35
  // src/ai/agentEndpoint.js
34
36
  var TASKS = ["rewrite", "subjects"];
@@ -146,6 +148,7 @@ export {
146
148
  DEFAULT_CLAUDE_MODEL,
147
149
  EmailGenerationError,
148
150
  GENERATION_ERRORS,
151
+ LANGUAGETOOL_PUBLIC_API,
149
152
  PROOFREAD_SYSTEM_PROMPT,
150
153
  REWRITE_ACTIONS,
151
154
  REWRITE_LANGUAGES,
@@ -156,6 +159,7 @@ export {
156
159
  claudeEmailModel,
157
160
  createAgentEndpoint,
158
161
  createEmailGenerator,
162
+ createLanguageToolProofreader,
159
163
  createProofreader,
160
164
  createRewriter,
161
165
  createSubjectSuggester,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ai/agentEndpoint.js"],"sourcesContent":["// @ts-check\n/**\n * THE AGENT'S SIDE of `best-email-builder/agent@1` (see agent.js), for an\n * agent written in JavaScript — and `checkAgent`, to try any agent with the\n * builder's own checks before plugging it in.\n *\n * const endpoint = createAgentEndpoint({\n * complete: async ({ task, system, messages, schema, request }) => {\n * const who = await sessionOf(request); // your rights\n * return myAgent.answer({ system, messages, who }); // text, or the answer as an object\n * },\n * });\n * // Next.js: export const POST = endpoint; Express: app.post('/email-builder', toNodeListener(endpoint))\n *\n * const report = await checkAgent({ url: 'http://localhost:8800/email-builder', headers });\n * // { ok, results: [{ task: 'proofread', ok, ms, attempts, sample }, …] }\n */\n\nimport { AGENT_ERROR_CODES, AGENT_PROTOCOL, agentEmailModel } from './agent.js';\nimport { GENERATION_ERRORS } from './errors.js';\nimport { createEmailGenerator } from './generator.js';\n\nconst TASKS = ['rewrite', 'subjects'];\n/** A repair turn carries the last answer: the texts of an email at most. */\nconst MAX_BODY_BYTES = 2 * 1024 * 1024;\nconst MAX_MESSAGES = 20;\n\n/**\n * @typedef {{\n * task: 'rewrite'|'subjects',\n * system: string,\n * messages: {role: 'user'|'assistant', content: string}[],\n * schema: object,\n * request: Request,\n * signal: AbortSignal,\n * }} AgentTask\n */\n\n/** @param {unknown} body @param {number} status */\nconst json = (body, status = 200) =>\n new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' } });\n\n/** @param {string} error @param {string} code @param {number} status */\nconst refuse = (error, code, status) => json({ error, code }, status);\n\n/**\n * What the builder sent, checked; or why not.\n * @param {any} body\n * @returns {string|null} the problem\n */\nfunction problemOf(body) {\n if (!body || typeof body !== 'object') return 'The body is not a JSON object';\n if (body.protocol !== AGENT_PROTOCOL) return `Unsupported protocol ${JSON.stringify(body.protocol)} — this endpoint speaks ${AGENT_PROTOCOL}`;\n if (!TASKS.includes(body.task)) return `Unknown task ${JSON.stringify(body.task)}`;\n if (typeof body.system !== 'string') return '`system` must be a string';\n if (!body.schema || typeof body.schema !== 'object') return '`schema` must be an object';\n const { messages } = body;\n if (!Array.isArray(messages) || !messages.length || messages.length > MAX_MESSAGES) return `\\`messages\\` must hold 1 to ${MAX_MESSAGES} messages`;\n for (const message of messages) {\n if (!message || (message.role !== 'user' && message.role !== 'assistant') || typeof message.content !== 'string') {\n return 'Each message is { role: \"user\"|\"assistant\", content: string }';\n }\n }\n return null;\n}\n\n/**\n * @param {{\n * complete: (task: AgentTask) => Promise<string | object> | string | object,\n * onError?: (error: unknown, request: Request) => void,\n * }} options\n * `complete`: your agent. It answers with the text of its model, or with\n * the answer as an object. To fail with a reason the builder explains, throw\n * an error whose `code` is one of AGENT_ERROR_CODES ('REFUSED',\n * 'MODEL_BUSY'…); any other error is logged with `onError` and answered as\n * MODEL_ERROR, its message kept out of the response.\n * @returns {(request: Request) => Promise<Response>}\n */\nexport function createAgentEndpoint({ complete, onError = (error) => console.error('[agent]', error) } = /** @type {any} */ ({})) {\n if (typeof complete !== 'function') throw new TypeError('createAgentEndpoint: `complete` must be a function — your agent');\n\n return async function agentEndpoint(request) {\n if (request.method.toUpperCase() !== 'POST') return refuse('POST only', 'METHOD_NOT_ALLOWED', 405);\n const length = Number(request.headers.get('content-length') || 0);\n if (length > MAX_BODY_BYTES) return refuse('Request too large', 'TOO_LARGE', 413);\n const raw = await request.text();\n if (raw.length > MAX_BODY_BYTES) return refuse('Request too large', 'TOO_LARGE', 413);\n /** @type {any} */\n let body;\n try {\n body = JSON.parse(raw);\n } catch {\n return refuse('Invalid JSON', 'INVALID_JSON', 400);\n }\n const problem = problemOf(body);\n if (problem) return refuse(problem, 'INVALID_REQUEST', 400);\n\n try {\n const answer = await complete({\n task: body.task,\n system: body.system,\n messages: body.messages.map((/** @type {any} */ m) => ({ role: m.role, content: m.content })),\n schema: body.schema,\n request,\n signal: request.signal,\n });\n if (typeof answer === 'string') return json({ text: answer });\n if (answer && typeof answer === 'object') return json({ output: answer });\n return refuse('The agent gave no answer', 'MODEL_ERROR', 502);\n } catch (error) {\n const code = /** @type {any} */ (error)?.code;\n if (AGENT_ERROR_CODES.includes(code)) {\n const known = GENERATION_ERRORS[/** @type {keyof typeof GENERATION_ERRORS} */ (code)];\n return refuse(String(/** @type {any} */ (error)?.detail || /** @type {any} */ (error)?.message || known.message), code, known.status);\n }\n onError(error, request);\n return refuse('The agent could not answer', 'MODEL_ERROR', 502);\n }\n };\n}\n\nconst SAMPLE_TEXT =\n '<p>Our summer sale starts on Monday: 30% off everything in store, for three days only. ' +\n 'It ends on Wednesday at midnight. <a href=\"https://example.com/sale\">See the offers</a>.</p>';\n\n/** An email with three mistakes to find, and one text without. @type {import('./proofread.js').ProofreadText[]} */\nconst SAMPLE_EMAIL = [\n { id: 'subject', kind: 'subject', format: 'plain', text: 'Our sumer sale starts on Monday' },\n { id: 'text-1', kind: 'text', format: 'html', text: SAMPLE_TEXT },\n { id: 'text-2', kind: 'text', format: 'html', text: '<p>We hope to see you their. <b>Every</b> product are on sale.</p>' },\n { id: 'button-1', kind: 'button', format: 'plain', text: 'See the offers' },\n];\n\n/**\n * Tries an agent with the builder's own checks: an email proofread, one text\n * rewritten, subject ideas — in turn, each as the builder would ask it (with\n * its repair turn). Three to six calls to the agent.\n * @param {{\n * url: string,\n * headers?: import('./agent.js').AgentHeaders,\n * user?: any,\n * fetch?: typeof fetch,\n * timeout?: number,\n * language?: string,\n * }} options\n * `user`: what `headers` gets, as the handler's `authorize` would give it.\n * @returns {Promise<{ok: boolean, results: {task: string, ok: boolean, ms: number, attempts?: number, sample?: unknown, code?: string, error?: string}[]}>}\n */\nexport async function checkAgent({ url, headers, user, fetch: fetchImpl, timeout, language = 'en' }) {\n const model = agentEmailModel({ url, headers, fetch: fetchImpl, timeout });\n const generator = createEmailGenerator({ model });\n /** @type {[string, () => Promise<any>, (result: any) => unknown][]} */\n const steps = [\n ['proofread', () => generator.proofread({ texts: SAMPLE_EMAIL, language }, { user }), (r) => r.fixes],\n ['rewrite', () => generator.rewrite({ action: 'shorter', text: SAMPLE_TEXT, format: 'html' }, { user }), (r) => r.text],\n [\n 'subjects',\n () => generator.suggestSubjects({ subject: 'Summer sale: 30% off', text: 'Our summer sale starts on Monday: 30% off everything in store, for three days only.', language }, { user }),\n (r) => r.subjects,\n ],\n ];\n const results = [];\n for (const [task, run, sampleOf] of steps) {\n const started = Date.now();\n try {\n const result = await run();\n results.push({ task, ok: true, ms: Date.now() - started, attempts: result.attempts, sample: sampleOf(result) });\n } catch (error) {\n const failure = /** @type {any} */ (error);\n results.push({ task, ok: false, ms: Date.now() - started, code: failure?.code || 'ERROR', error: String(failure?.detail || failure?.message || error) });\n }\n }\n return { ok: results.every((result) => result.ok), results };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAM,QAAQ,CAAC,WAAW,UAAU;AAEpC,IAAM,iBAAiB,IAAI,OAA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ChH,SAAS,OAAO;AACd,YAAM;AAAA;AAAA,QAA8B;AAAA;AACpC,cAAQ,KAAK,EAAE,MAAM,IAAI,OAAO,IAAI,KAAK,IAAI,IAAI,SAAS,MAAM,SAAS,QAAQ,SAAS,OAAO,OAAO,SAAS,UAAU,SAAS,WAAW,KAAK,EAAE,CAAC;AAAA,IACzJ;AAAA,EACF;AACA,SAAO,EAAE,IAAI,QAAQ,MAAM,CAAC,WAAW,OAAO,EAAE,GAAG,QAAQ;AAC7D;","names":[]}
1
+ {"version":3,"sources":["../src/ai/agentEndpoint.js"],"sourcesContent":["// @ts-check\n/**\n * THE AGENT'S SIDE of `best-email-builder/agent@1` (see agent.js), for an\n * agent written in JavaScript — and `checkAgent`, to try any agent with the\n * builder's own checks before plugging it in.\n *\n * const endpoint = createAgentEndpoint({\n * complete: async ({ task, system, messages, schema, request }) => {\n * const who = await sessionOf(request); // your rights\n * return myAgent.answer({ system, messages, who }); // text, or the answer as an object\n * },\n * });\n * // Next.js: export const POST = endpoint; Express: app.post('/email-builder', toNodeListener(endpoint))\n *\n * const report = await checkAgent({ url: 'http://localhost:8800/email-builder', headers });\n * // { ok, results: [{ task: 'proofread', ok, ms, attempts, sample }, …] }\n */\n\nimport { AGENT_ERROR_CODES, AGENT_PROTOCOL, agentEmailModel } from './agent.js';\nimport { GENERATION_ERRORS } from './errors.js';\nimport { createEmailGenerator } from './generator.js';\n\nconst TASKS = ['rewrite', 'subjects'];\n/** A repair turn carries the last answer: the texts of an email at most. */\nconst MAX_BODY_BYTES = 2 * 1024 * 1024;\nconst MAX_MESSAGES = 20;\n\n/**\n * @typedef {{\n * task: 'rewrite'|'subjects',\n * system: string,\n * messages: {role: 'user'|'assistant', content: string}[],\n * schema: object,\n * request: Request,\n * signal: AbortSignal,\n * }} AgentTask\n */\n\n/** @param {unknown} body @param {number} status */\nconst json = (body, status = 200) =>\n new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' } });\n\n/** @param {string} error @param {string} code @param {number} status */\nconst refuse = (error, code, status) => json({ error, code }, status);\n\n/**\n * What the builder sent, checked; or why not.\n * @param {any} body\n * @returns {string|null} the problem\n */\nfunction problemOf(body) {\n if (!body || typeof body !== 'object') return 'The body is not a JSON object';\n if (body.protocol !== AGENT_PROTOCOL) return `Unsupported protocol ${JSON.stringify(body.protocol)} — this endpoint speaks ${AGENT_PROTOCOL}`;\n if (!TASKS.includes(body.task)) return `Unknown task ${JSON.stringify(body.task)}`;\n if (typeof body.system !== 'string') return '`system` must be a string';\n if (!body.schema || typeof body.schema !== 'object') return '`schema` must be an object';\n const { messages } = body;\n if (!Array.isArray(messages) || !messages.length || messages.length > MAX_MESSAGES) return `\\`messages\\` must hold 1 to ${MAX_MESSAGES} messages`;\n for (const message of messages) {\n if (!message || (message.role !== 'user' && message.role !== 'assistant') || typeof message.content !== 'string') {\n return 'Each message is { role: \"user\"|\"assistant\", content: string }';\n }\n }\n return null;\n}\n\n/**\n * @param {{\n * complete: (task: AgentTask) => Promise<string | object> | string | object,\n * onError?: (error: unknown, request: Request) => void,\n * }} options\n * `complete`: your agent. It answers with the text of its model, or with\n * the answer as an object. To fail with a reason the builder explains, throw\n * an error whose `code` is one of AGENT_ERROR_CODES ('REFUSED',\n * 'MODEL_BUSY'…); any other error is logged with `onError` and answered as\n * MODEL_ERROR, its message kept out of the response.\n * @returns {(request: Request) => Promise<Response>}\n */\nexport function createAgentEndpoint({ complete, onError = (error) => console.error('[agent]', error) } = /** @type {any} */ ({})) {\n if (typeof complete !== 'function') throw new TypeError('createAgentEndpoint: `complete` must be a function — your agent');\n\n return async function agentEndpoint(request) {\n if (request.method.toUpperCase() !== 'POST') return refuse('POST only', 'METHOD_NOT_ALLOWED', 405);\n const length = Number(request.headers.get('content-length') || 0);\n if (length > MAX_BODY_BYTES) return refuse('Request too large', 'TOO_LARGE', 413);\n const raw = await request.text();\n if (raw.length > MAX_BODY_BYTES) return refuse('Request too large', 'TOO_LARGE', 413);\n /** @type {any} */\n let body;\n try {\n body = JSON.parse(raw);\n } catch {\n return refuse('Invalid JSON', 'INVALID_JSON', 400);\n }\n const problem = problemOf(body);\n if (problem) return refuse(problem, 'INVALID_REQUEST', 400);\n\n try {\n const answer = await complete({\n task: body.task,\n system: body.system,\n messages: body.messages.map((/** @type {any} */ m) => ({ role: m.role, content: m.content })),\n schema: body.schema,\n request,\n signal: request.signal,\n });\n if (typeof answer === 'string') return json({ text: answer });\n if (answer && typeof answer === 'object') return json({ output: answer });\n return refuse('The agent gave no answer', 'MODEL_ERROR', 502);\n } catch (error) {\n const code = /** @type {any} */ (error)?.code;\n if (AGENT_ERROR_CODES.includes(code)) {\n const known = GENERATION_ERRORS[/** @type {keyof typeof GENERATION_ERRORS} */ (code)];\n return refuse(String(/** @type {any} */ (error)?.detail || /** @type {any} */ (error)?.message || known.message), code, known.status);\n }\n onError(error, request);\n return refuse('The agent could not answer', 'MODEL_ERROR', 502);\n }\n };\n}\n\nconst SAMPLE_TEXT =\n '<p>Our summer sale starts on Monday: 30% off everything in store, for three days only. ' +\n 'It ends on Wednesday at midnight. <a href=\"https://example.com/sale\">See the offers</a>.</p>';\n\n/** An email with three mistakes to find, and one text without. @type {import('./proofread.js').ProofreadText[]} */\nconst SAMPLE_EMAIL = [\n { id: 'subject', kind: 'subject', format: 'plain', text: 'Our sumer sale starts on Monday' },\n { id: 'text-1', kind: 'text', format: 'html', text: SAMPLE_TEXT },\n { id: 'text-2', kind: 'text', format: 'html', text: '<p>We hope to see you their. <b>Every</b> product are on sale.</p>' },\n { id: 'button-1', kind: 'button', format: 'plain', text: 'See the offers' },\n];\n\n/**\n * Tries an agent with the builder's own checks: an email proofread, one text\n * rewritten, subject ideas — in turn, each as the builder would ask it (with\n * its repair turn). Three to six calls to the agent.\n * @param {{\n * url: string,\n * headers?: import('./agent.js').AgentHeaders,\n * user?: any,\n * fetch?: typeof fetch,\n * timeout?: number,\n * language?: string,\n * }} options\n * `user`: what `headers` gets, as the handler's `authorize` would give it.\n * @returns {Promise<{ok: boolean, results: {task: string, ok: boolean, ms: number, attempts?: number, sample?: unknown, code?: string, error?: string}[]}>}\n */\nexport async function checkAgent({ url, headers, user, fetch: fetchImpl, timeout, language = 'en' }) {\n const model = agentEmailModel({ url, headers, fetch: fetchImpl, timeout });\n const generator = createEmailGenerator({ model });\n /** @type {[string, () => Promise<any>, (result: any) => unknown][]} */\n const steps = [\n ['proofread', () => generator.proofread({ texts: SAMPLE_EMAIL, language }, { user }), (r) => r.fixes],\n ['rewrite', () => generator.rewrite({ action: 'shorter', text: SAMPLE_TEXT, format: 'html' }, { user }), (r) => r.text],\n [\n 'subjects',\n () => generator.suggestSubjects({ subject: 'Summer sale: 30% off', text: 'Our summer sale starts on Monday: 30% off everything in store, for three days only.', language }, { user }),\n (r) => r.subjects,\n ],\n ];\n const results = [];\n for (const [task, run, sampleOf] of steps) {\n const started = Date.now();\n try {\n const result = await run();\n results.push({ task, ok: true, ms: Date.now() - started, attempts: result.attempts, sample: sampleOf(result) });\n } catch (error) {\n const failure = /** @type {any} */ (error);\n results.push({ task, ok: false, ms: Date.now() - started, code: failure?.code || 'ERROR', error: String(failure?.detail || failure?.message || error) });\n }\n }\n return { ok: results.every((result) => result.ok), results };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAM,QAAQ,CAAC,WAAW,UAAU;AAEpC,IAAM,iBAAiB,IAAI,OAAO;AAClC,IAAM,eAAe;AAcrB,IAAM,OAAO,CAAC,MAAM,SAAS,QAC3B,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG,EAAE,QAAQ,SAAS,EAAE,gBAAgB,mCAAmC,iBAAiB,WAAW,EAAE,CAAC;AAG5I,IAAM,SAAS,CAAC,OAAO,MAAM,WAAW,KAAK,EAAE,OAAO,KAAK,GAAG,MAAM;AAOpE,SAAS,UAAU,MAAM;AACvB,MAAI,CAAC,QAAQ,OAAO,SAAS,SAAU,QAAO;AAC9C,MA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ED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cleanRichText
3
- } from "./chunk-6LTSEPQX.js";
3
+ } from "./chunk-RPDQABWZ.js";
4
4
  import {
5
5
  Button,
6
6
  Dialog,
@@ -20,8 +20,8 @@ import {
20
20
  cn,
21
21
  createHttpCaller,
22
22
  useUi
23
- } from "./chunk-ND3B5TL7.js";
24
- import "./chunk-6ZX3VYE4.js";
23
+ } from "./chunk-7H7TLQBL.js";
24
+ import "./chunk-W5AJWWHH.js";
25
25
  import {
26
26
  AGENT_ERROR_CODES,
27
27
  AGENT_PROTOCOL,
@@ -30,6 +30,7 @@ import {
30
30
  DEFAULT_CLAUDE_MODEL,
31
31
  EmailGenerationError,
32
32
  GENERATION_ERRORS,
33
+ LANGUAGETOOL_PUBLIC_API,
33
34
  MAX_REWRITE_INSTRUCTION,
34
35
  REWRITE_ACTIONS,
35
36
  REWRITE_LANGUAGES,
@@ -37,6 +38,7 @@ import {
37
38
  claudeEmailModel,
38
39
  claudeProvider,
39
40
  createEmailGenerator,
41
+ createLanguageToolProofreader,
40
42
  diffWords,
41
43
  emailWords,
42
44
  failureCode,
@@ -44,9 +46,9 @@ import {
44
46
  providerEmailModel,
45
47
  resolveProvider,
46
48
  visibleText
47
- } from "./chunk-I6FP6BBI.js";
48
- import "./chunk-XALUYZYQ.js";
49
- import "./chunk-RZ3O4MH5.js";
49
+ } from "./chunk-6OR6W4KJ.js";
50
+ import "./chunk-AGA3BLRI.js";
51
+ import "./chunk-EFE245KW.js";
50
52
 
51
53
  // src/ai/keys.js
52
54
  var STORAGE_PREFIX = "best-email-builder:ai-key:";
@@ -864,7 +866,7 @@ function ProofreadButton({ context, proofread }) {
864
866
  /* @__PURE__ */ jsx3(Dialog, { open, onOpenChange: close, children: /* @__PURE__ */ jsxs3(DialogContent, { className: "eb:flex eb:max-h-[calc(100dvh-2rem)] eb:flex-col eb:gap-0 eb:p-0 eb:sm:max-w-xl", "data-testid": "eb-proofread", children: [
865
867
  /* @__PURE__ */ jsxs3(DialogHeader, { className: "eb:gap-1.5 eb:px-6 eb:pt-6 eb:pb-4", children: [
866
868
  /* @__PURE__ */ jsx3(DialogTitle, { children: t("Proofread the email") }),
867
- /* @__PURE__ */ jsx3(DialogDescription, { children: t("AI looks for spelling, grammar and punctuation mistakes in every text. Nothing changes until you apply it.") })
869
+ /* @__PURE__ */ jsx3(DialogDescription, { children: t("Every text is checked for spelling, grammar and punctuation mistakes. Nothing changes until you apply it.") })
868
870
  ] }),
869
871
  /* @__PURE__ */ jsxs3("div", { className: "eb:min-h-0 eb:flex-1 eb:overflow-y-auto eb:border-t eb:border-border eb:px-6 eb:py-4", children: [
870
872
  busy && /* @__PURE__ */ jsxs3("p", { className: "eb:flex eb:items-center eb:gap-2 eb:py-6 eb:text-[13px] eb:text-foreground-muted", role: "status", "aria-live": "polite", children: [
@@ -931,8 +933,8 @@ function around(text, first, last) {
931
933
  }
932
934
 
933
935
  // src/ai/RewriteText.jsx
934
- import { useEffect as useEffect4, useRef as useRef4, useState as useState4 } from "react";
935
- import { ChevronDown as ChevronDown2, Languages, Loader2 as Loader22, PenLine, Sparkles, TriangleAlert as TriangleAlert3 } from "lucide-react";
936
+ import { useCallback, useEffect as useEffect4, useRef as useRef4, useState as useState4 } from "react";
937
+ import { ChevronDown as ChevronDown2, Languages, Loader2 as Loader22, Sparkles, TriangleAlert as TriangleAlert3 } from "lucide-react";
936
938
 
937
939
  // src/ai/chip.js
938
940
  var chipClassName = (selected = false) => cn(
@@ -941,7 +943,7 @@ var chipClassName = (selected = false) => cn(
941
943
  );
942
944
 
943
945
  // src/ai/RewriteText.jsx
944
- import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
946
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
945
947
  function nativeName(code) {
946
948
  try {
947
949
  const name = new Intl.DisplayNames([code], { type: "language" }).of(code) || code;
@@ -957,14 +959,19 @@ function RewriteText({ editor, selection, rewrite }) {
957
959
  null
958
960
  );
959
961
  const [error, setError] = useState4("");
960
- const [instruction, setInstruction] = useState4("");
961
- const [topic, setTopic] = useState4("");
962
+ const [request, setRequest] = useState4("");
962
963
  const abortRef = useRef4(
963
964
  /** @type {AbortController|null} */
964
965
  null
965
966
  );
966
967
  const label = selection.tagName === "mj-button";
967
- useEffect4(() => () => abortRef.current?.abort(), []);
968
+ const stop = useCallback(() => {
969
+ if (!abortRef.current) return;
970
+ abortRef.current.abort();
971
+ abortRef.current = null;
972
+ editor.showWorking(null);
973
+ }, [editor]);
974
+ useEffect4(() => stop, [stop]);
968
975
  const currentText2 = () => {
969
976
  const element = editor.getElement(selection.id);
970
977
  return (label ? element?.content : element?.html) ?? "";
@@ -972,10 +979,12 @@ function RewriteText({ editor, selection, rewrite }) {
972
979
  const run = async (action, extra = {}) => {
973
980
  if (running) return;
974
981
  const text = currentText2();
982
+ const writing = action === "custom";
975
983
  setError("");
976
984
  setRunning(action);
977
985
  const controller = new AbortController();
978
986
  abortRef.current = controller;
987
+ editor.showWorking(selection.id);
979
988
  try {
980
989
  const result = await rewrite({ action, text, format: label ? "plain" : "html", ...extra }, { signal: controller.signal });
981
990
  if (controller.signal.aborted) return;
@@ -983,98 +992,79 @@ function RewriteText({ editor, selection, rewrite }) {
983
992
  setError(t("The text changed in the meantime, so it was left as it is."));
984
993
  return;
985
994
  }
986
- editor.setContent(label ? result.text : cleanRichText(result.text, document), selection.id);
987
- if (action === "custom") setInstruction("");
988
- if (action === "write") setTopic("");
989
- notify("success", action === "write" ? t("Text written. Ctrl+Z brings back the previous one.") : t("Text rewritten. Ctrl+Z brings back the previous one."));
995
+ editor.setContent(label ? result.text : cleanRichText(result.text, document), selection.id, { reveal: true });
996
+ if (action === "custom") setRequest("");
997
+ notify("success", writing ? t("Text written. Ctrl+Z brings back the previous one.") : t("Text rewritten. Ctrl+Z brings back the previous one."));
990
998
  } catch (err) {
991
999
  if (!controller.signal.aborted) {
992
- setError(err?.message ? t(err.message) : action === "write" ? t("The text could not be written.") : t("The text could not be rewritten."));
1000
+ setError(err?.message ? t(err.message) : writing ? t("The text could not be written.") : t("The text could not be rewritten."));
993
1001
  }
994
1002
  } finally {
995
- if (abortRef.current === controller) abortRef.current = null;
1003
+ if (abortRef.current === controller) {
1004
+ abortRef.current = null;
1005
+ editor.showWorking(null);
1006
+ }
996
1007
  setRunning(null);
997
1008
  }
998
1009
  };
999
1010
  const cancel = () => {
1000
- abortRef.current?.abort();
1011
+ stop();
1001
1012
  setRunning(null);
1002
1013
  };
1003
- const write = () => {
1004
- const subject = topic.trim();
1005
- if (!subject) return;
1014
+ const ask = () => {
1015
+ const words = request.trim();
1016
+ if (!words) return;
1006
1017
  const size = Number.parseFloat(String(editor.getElement(selection.id)?.attributes?.["font-size"] || ""));
1007
1018
  const own = visibleText(currentText2());
1008
- const words = emailWords(editor.exportMjml());
1009
- run("write", {
1010
- instruction: subject,
1011
- context: own ? words.replace(own, "").trim() : words,
1019
+ const email = emailWords(editor.exportMjml());
1020
+ run("custom", {
1021
+ instruction: words,
1022
+ context: own ? email.replace(own, "").trim() : email,
1012
1023
  role: size >= 20 ? "heading" : "text",
1013
1024
  language: String(locale || "en").slice(0, 2)
1014
1025
  });
1015
1026
  };
1016
1027
  const busy = Boolean(running);
1017
1028
  const spinner = /* @__PURE__ */ jsx4(Loader22, { className: "eb:size-3 eb:animate-spin", "aria-hidden": "true" });
1018
- return /* @__PURE__ */ jsxs4(Fragment3, { children: [
1019
- !label && /* @__PURE__ */ jsxs4("section", { className: "eb:space-y-2.5", "aria-label": t("Write with AI"), "data-testid": "eb-write", children: [
1020
- /* @__PURE__ */ jsxs4(SectionLabel, { className: "eb:flex eb:items-center eb:gap-1.5", children: [
1021
- /* @__PURE__ */ jsx4(PenLine, { className: "eb:size-3", "aria-hidden": "true" }),
1022
- t("Write with AI")
1023
- ] }),
1024
- /* @__PURE__ */ jsx4(
1025
- PromptForm,
1026
- {
1027
- value: topic,
1028
- onChange: setTopic,
1029
- onSubmit: write,
1030
- placeholder: t("What should it say? e.g. the sale ends Sunday"),
1031
- label: t("What the text is about"),
1032
- busy,
1033
- submitLabel: t("Write"),
1034
- children: running === "write" ? /* @__PURE__ */ jsx4(Loader22, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx4(PenLine, {})
1035
- }
1036
- )
1029
+ return /* @__PURE__ */ jsxs4("section", { className: "eb:space-y-2.5", "aria-label": t("Write with AI"), "data-testid": "eb-rewrite", children: [
1030
+ /* @__PURE__ */ jsxs4(SectionLabel, { className: "eb:flex eb:items-center eb:gap-1.5", children: [
1031
+ /* @__PURE__ */ jsx4(Sparkles, { className: "eb:size-3", "aria-hidden": "true" }),
1032
+ t("Write with AI")
1037
1033
  ] }),
1038
- /* @__PURE__ */ jsxs4("section", { className: "eb:space-y-2.5", "aria-label": t("Rewrite with AI"), "data-testid": "eb-rewrite", children: [
1039
- /* @__PURE__ */ jsxs4(SectionLabel, { className: "eb:flex eb:items-center eb:gap-1.5", children: [
1040
- /* @__PURE__ */ jsx4(Sparkles, { className: "eb:size-3", "aria-hidden": "true" }),
1041
- t("Rewrite with AI")
1042
- ] }),
1043
- /* @__PURE__ */ jsxs4("div", { className: "eb:flex eb:flex-wrap eb:gap-1.5", children: [
1044
- REWRITE_ACTIONS.map((action) => /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), disabled: busy, onClick: () => run(action.id), children: [
1045
- running === action.id && spinner,
1046
- t(action.label)
1047
- ] }, action.id)),
1048
- /* @__PURE__ */ jsxs4(DropdownMenu, { children: [
1049
- /* @__PURE__ */ jsx4(DropdownMenuTrigger, { asChild: true, disabled: busy, children: /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), children: [
1050
- running === "translate" ? spinner : /* @__PURE__ */ jsx4(Languages, { className: "eb:size-3", "aria-hidden": "true" }),
1051
- t("Translate"),
1052
- /* @__PURE__ */ jsx4(ChevronDown2, { className: "eb:size-3", "aria-hidden": "true" })
1053
- ] }) }),
1054
- /* @__PURE__ */ jsx4(DropdownMenuContent, { align: "start", "aria-label": t("Translate into"), children: REWRITE_LANGUAGES.map((code) => /* @__PURE__ */ jsx4(DropdownMenuItem, { lang: code, onSelect: () => run("translate", { targetLanguage: code }), children: nativeName(code) }, code)) })
1055
- ] })
1056
- ] }),
1057
- /* @__PURE__ */ jsx4(
1058
- PromptForm,
1059
- {
1060
- value: instruction,
1061
- onChange: setInstruction,
1062
- onSubmit: () => run("custom", { instruction: instruction.trim() }),
1063
- placeholder: t("Or say what to change\u2026"),
1064
- label: t("What to change"),
1065
- busy,
1066
- submitLabel: t("Rewrite"),
1067
- children: running === "custom" ? /* @__PURE__ */ jsx4(Loader22, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx4(Sparkles, {})
1068
- }
1069
- ),
1070
- running && /* @__PURE__ */ jsxs4("p", { className: "eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted", role: "status", "aria-live": "polite", children: [
1071
- running === "write" ? t("Writing\u2026") : t("Rewriting\u2026"),
1072
- /* @__PURE__ */ jsx4(Button, { type: "button", variant: "link", size: "xs", className: "eb:h-auto eb:px-0", onClick: cancel, children: t("Cancel") })
1073
- ] }),
1074
- error && /* @__PURE__ */ jsxs4("p", { role: "alert", className: "eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive", children: [
1075
- /* @__PURE__ */ jsx4(TriangleAlert3, { className: "eb:mt-px eb:size-3.5 eb:shrink-0", "aria-hidden": "true" }),
1076
- error
1034
+ /* @__PURE__ */ jsx4(
1035
+ PromptForm,
1036
+ {
1037
+ value: request,
1038
+ onChange: setRequest,
1039
+ onSubmit: ask,
1040
+ placeholder: t("What should it say, or what should change? e.g. the sale ends Sunday"),
1041
+ label: t("Ask the AI"),
1042
+ busy,
1043
+ submitLabel: t("Write"),
1044
+ children: running === "custom" ? /* @__PURE__ */ jsx4(Loader22, { className: "eb:animate-spin" }) : /* @__PURE__ */ jsx4(Sparkles, {})
1045
+ }
1046
+ ),
1047
+ /* @__PURE__ */ jsxs4("div", { className: "eb:flex eb:flex-wrap eb:gap-1.5", children: [
1048
+ REWRITE_ACTIONS.map((action) => /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), disabled: busy, onClick: () => run(action.id), children: [
1049
+ running === action.id && spinner,
1050
+ t(action.label)
1051
+ ] }, action.id)),
1052
+ /* @__PURE__ */ jsxs4(DropdownMenu, { children: [
1053
+ /* @__PURE__ */ jsx4(DropdownMenuTrigger, { asChild: true, disabled: busy, children: /* @__PURE__ */ jsxs4("button", { type: "button", className: chipClassName(), children: [
1054
+ running === "translate" ? spinner : /* @__PURE__ */ jsx4(Languages, { className: "eb:size-3", "aria-hidden": "true" }),
1055
+ t("Translate"),
1056
+ /* @__PURE__ */ jsx4(ChevronDown2, { className: "eb:size-3", "aria-hidden": "true" })
1057
+ ] }) }),
1058
+ /* @__PURE__ */ jsx4(DropdownMenuContent, { align: "start", "aria-label": t("Translate into"), children: REWRITE_LANGUAGES.map((code) => /* @__PURE__ */ jsx4(DropdownMenuItem, { lang: code, onSelect: () => run("translate", { targetLanguage: code }), children: nativeName(code) }, code)) })
1077
1059
  ] })
1060
+ ] }),
1061
+ running && /* @__PURE__ */ jsxs4("p", { className: "eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted", role: "status", "aria-live": "polite", children: [
1062
+ running === "custom" ? t("Writing\u2026") : t("Rewriting\u2026"),
1063
+ /* @__PURE__ */ jsx4(Button, { type: "button", variant: "link", size: "xs", className: "eb:h-auto eb:px-0", onClick: cancel, children: t("Cancel") })
1064
+ ] }),
1065
+ error && /* @__PURE__ */ jsxs4("p", { role: "alert", className: "eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive", children: [
1066
+ /* @__PURE__ */ jsx4(TriangleAlert3, { className: "eb:mt-px eb:size-3.5 eb:shrink-0", "aria-hidden": "true" }),
1067
+ error
1078
1068
  ] })
1079
1069
  ] });
1080
1070
  }
@@ -1437,6 +1427,7 @@ export {
1437
1427
  DEFAULT_CLAUDE_MODEL,
1438
1428
  EmailGenerationError,
1439
1429
  GENERATION_ERRORS,
1430
+ LANGUAGETOOL_PUBLIC_API,
1440
1431
  REWRITE_ACTIONS,
1441
1432
  REWRITE_LANGUAGES,
1442
1433
  agentEmailModel,
@@ -1444,6 +1435,7 @@ export {
1444
1435
  claudeProvider,
1445
1436
  createAi,
1446
1437
  createEmailGenerator,
1438
+ createLanguageToolProofreader,
1447
1439
  diffWords,
1448
1440
  emailWords,
1449
1441
  failureCode,