best-email-builder 0.15.0 → 0.17.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 (110) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/README.md +16 -7
  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 +91 -99
  7. package/dist/ai.js.map +1 -1
  8. package/dist/builder.js +8 -8
  9. package/dist/{chunk-XALUYZYQ.js → chunk-2F7P4FXX.js} +2 -2
  10. package/dist/{chunk-RG2DTGST.js → chunk-4AUHYQPE.js} +7 -5
  11. package/dist/chunk-4AUHYQPE.js.map +1 -0
  12. package/dist/{chunk-6ZX3VYE4.js → chunk-5OUMNUJS.js} +143 -19
  13. package/dist/chunk-5OUMNUJS.js.map +1 -0
  14. package/dist/{chunk-ND3B5TL7.js → chunk-DOK6E6GK.js} +38 -13
  15. package/dist/chunk-DOK6E6GK.js.map +1 -0
  16. package/dist/{chunk-RZ3O4MH5.js → chunk-FPJF77MO.js} +329 -18
  17. package/dist/chunk-FPJF77MO.js.map +1 -0
  18. package/dist/{chunk-6LTSEPQX.js → chunk-PCLRIXAQ.js} +2 -2
  19. package/dist/{chunk-GHFNJY4O.js → chunk-QDAVDMA4.js} +2 -2
  20. package/dist/{chunk-AT4EB2NS.js → chunk-U3BA4NK3.js} +311 -3
  21. package/dist/chunk-U3BA4NK3.js.map +1 -0
  22. package/dist/{chunk-QXE6LJG5.js → chunk-V2PO42EN.js} +4 -4
  23. package/dist/{chunk-QXE6LJG5.js.map → chunk-V2PO42EN.js.map} +1 -1
  24. package/dist/{chunk-OK3EIEUA.js → chunk-X4WTY6LC.js} +2449 -1006
  25. package/dist/chunk-X4WTY6LC.js.map +1 -0
  26. package/dist/{chunk-I6FP6BBI.js → chunk-ZRER4JD4.js} +268 -55
  27. package/dist/chunk-ZRER4JD4.js.map +1 -0
  28. package/dist/de-BNFO6VLR.js +1875 -0
  29. package/dist/de-BNFO6VLR.js.map +1 -0
  30. package/dist/en-PBUZLCBA.js +1875 -0
  31. package/dist/en-PBUZLCBA.js.map +1 -0
  32. package/dist/es-M7A73ED7.js +1875 -0
  33. package/dist/es-M7A73ED7.js.map +1 -0
  34. package/dist/fr-SUFB35ZZ.js +1875 -0
  35. package/dist/fr-SUFB35ZZ.js.map +1 -0
  36. package/dist/index.js +10 -10
  37. package/dist/library.js +5 -5
  38. package/dist/pt-OEAULFDA.js +1875 -0
  39. package/dist/pt-OEAULFDA.js.map +1 -0
  40. package/dist/ru-ZCORYHGA.js +1875 -0
  41. package/dist/ru-ZCORYHGA.js.map +1 -0
  42. package/dist/server.js +63 -16
  43. package/dist/server.js.map +1 -1
  44. package/dist/styles.css +1 -1
  45. package/dist/types/ai/errors.d.ts +19 -7
  46. package/dist/types/ai/index.d.ts +1 -0
  47. package/dist/types/ai/languagetool.d.ts +46 -0
  48. package/dist/types/ai/rewrite.d.ts +9 -7
  49. package/dist/types/ai/server.d.ts +1 -0
  50. package/dist/types/ai/subjects.d.ts +1 -0
  51. package/dist/types/blocks/navbar/index.d.ts +1 -1
  52. package/dist/types/blocks/shared.d.ts +12 -9
  53. package/dist/types/blocks/social/index.d.ts +7 -3
  54. package/dist/types/core/EmailEditor.d.ts +154 -12
  55. package/dist/types/core/blockBox.d.ts +12 -0
  56. package/dist/types/core/constants.d.ts +1 -1
  57. package/dist/types/core/mjmlAttributes.d.ts +37 -0
  58. package/dist/types/core/textFormat.d.ts +4 -0
  59. package/dist/types/defaultEditor.d.ts +3 -1
  60. package/dist/types/engine/NativeAdapter.d.ts +5 -2
  61. package/dist/types/engine/canvas/CanvasView.d.ts +39 -1
  62. package/dist/types/engine/canvas/canvasStyles.d.ts +1 -1
  63. package/dist/types/engine/canvas/icons.d.ts +1 -8
  64. package/dist/types/engine/canvasMjml.d.ts +4 -2
  65. package/dist/types/engine/mjml.d.ts +7 -0
  66. package/dist/types/features/emoji/EmojiPanel.d.ts +3 -0
  67. package/dist/types/features/emoji/data/de.d.ts +2 -0
  68. package/dist/types/features/emoji/data/en.d.ts +2 -0
  69. package/dist/types/features/emoji/data/es.d.ts +2 -0
  70. package/dist/types/features/emoji/data/fr.d.ts +2 -0
  71. package/dist/types/features/emoji/data/pt.d.ts +2 -0
  72. package/dist/types/features/emoji/data/ru.d.ts +2 -0
  73. package/dist/types/features/emoji/data/zh.d.ts +2 -0
  74. package/dist/types/features/emoji/emojis.d.ts +33 -0
  75. package/dist/types/features/emoji/index.d.ts +2 -0
  76. package/dist/types/features/variables/VariableDialog.d.ts +9 -1
  77. package/dist/types/features/variables/VariablesPanel.d.ts +28 -0
  78. package/dist/types/features/variables/catalog.d.ts +12 -4
  79. package/dist/types/renderer/columnAlignment.d.ts +10 -0
  80. package/dist/types/renderer/compileEditorMjml.d.ts +2 -0
  81. package/dist/types/server/compileMjml.d.ts +5 -0
  82. package/dist/types/server/handler.d.ts +1 -1
  83. package/dist/types/server/render.d.ts +15 -4
  84. package/dist/types/server/sendTest.d.ts +2 -2
  85. package/dist/types/server/variables.d.ts +5 -0
  86. package/dist/types/storage/client.d.ts +6 -0
  87. package/dist/types/ui/BlockSidebar.d.ts +34 -0
  88. package/dist/types/ui/BoxModel.d.ts +39 -0
  89. package/dist/types/ui/CanvasAddMenu.d.ts +14 -0
  90. package/dist/types/ui/CanvasPanel.d.ts +19 -0
  91. package/dist/types/ui/TextRibbon.d.ts +25 -0
  92. package/dist/types/ui/fields.d.ts +16 -1
  93. package/dist/types/ui/primitives/color-picker.d.ts +18 -4
  94. package/dist/types/ui/primitives/misc.d.ts +3 -1
  95. package/dist/types/ui/primitives/overlays.d.ts +1 -0
  96. package/dist/types/ui/useEmailEditorState.d.ts +1 -0
  97. package/dist/zh-KPGU7EQG.js +1875 -0
  98. package/dist/zh-KPGU7EQG.js.map +1 -0
  99. package/package.json +2 -1
  100. package/dist/chunk-6ZX3VYE4.js.map +0 -1
  101. package/dist/chunk-AT4EB2NS.js.map +0 -1
  102. package/dist/chunk-I6FP6BBI.js.map +0 -1
  103. package/dist/chunk-ND3B5TL7.js.map +0 -1
  104. package/dist/chunk-OK3EIEUA.js.map +0 -1
  105. package/dist/chunk-RG2DTGST.js.map +0 -1
  106. package/dist/chunk-RZ3O4MH5.js.map +0 -1
  107. package/dist/types/features/variables/VariablesBar.d.ts +0 -23
  108. /package/dist/{chunk-XALUYZYQ.js.map → chunk-2F7P4FXX.js.map} +0 -0
  109. /package/dist/{chunk-6LTSEPQX.js.map → chunk-PCLRIXAQ.js.map} +0 -0
  110. /package/dist/{chunk-GHFNJY4O.js.map → chunk-QDAVDMA4.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,167 @@ All notable changes are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.17.0] — 2026-10-26
10
+
11
+ ### Added
12
+ - A "+" on the canvas, as in Unlayer. Under the selected element, it opens
13
+ the blocks, and the one picked goes after the element (at the end of a
14
+ selected column). After the last icon of a social block, it opens the
15
+ networks with their icons; after a menu's last link, it adds a link at
16
+ once. The new icon or link copies the last one's look and is selected.
17
+ - `editor.addItem(choice, id)`: one more item in a row (a social block's
18
+ icons, a menu's links). A block declares its row's choices in `items`;
19
+ the canvas's "+" emits the editor's `add-menu` event with where it is on
20
+ screen.
21
+ - Variables move by drag and drop: a badge dragged onto another group of
22
+ the *Variables* panel moves there and is saved, as its dialog would save
23
+ it. The other groups are outlined, the one under the pointer lit; Esc
24
+ cancels, and a click still inserts.
25
+
26
+ ### Changed
27
+ - The template library, wide: the list takes a fifth of the width (never
28
+ under 260 px), and the template's details and its preview share the rest
29
+ equally.
30
+ - One corner for every control, the button's (10 px): fields, selects and
31
+ their lists, filter chips, the ribbon's buttons, cards. Badges under
32
+ 24 px tall (tags, variables, the AI's quick actions) take 6 px instead of
33
+ a pill, and items inside a list 6 px, following its corners. The rule is
34
+ written next to the radius tokens in `styles.css`.
35
+
36
+ ### Removed
37
+ - The formatting bar over a text being edited in the canvas: the ribbon
38
+ above the canvas has the same tools (bold, italic, underline, strike,
39
+ link, unlink, clear) and stays the one place for them. Its link field
40
+ now takes an address without `https://` too, as the bar did.
41
+
42
+ ## [0.16.0] — 2026-10-26
43
+
44
+ ### Added
45
+ - A ribbon above the canvas, always open, as in a word processor: bold,
46
+ italic, underline, strikethrough, link, remove the link, clear formatting,
47
+ font size (typed or picked), line height and alignment, each tool
48
+ named in a tooltip. The word tools act on the selection of the text being
49
+ edited, or on the whole of a selected text, and show what is pressed at the
50
+ caret. `editor.formatText(command, value)` drives them; the editor's
51
+ `format` event reports the format at the caret.
52
+ - An emoji panel, opened from the end of the ribbon: every emoji up to
53
+ Unicode 14 by group, searchable by name or keyword in the interface's
54
+ language (accents optional), the recently used first. Like a variable, an
55
+ emoji under the pointer shows in the text, a click inserts it. The names
56
+ are loaded on first use, one language at a time (emojibase-data, MIT — see
57
+ THIRD-PARTY-NOTICES.md), and only the rows near the scroll are drawn.
58
+ - A feature may declare `drawer: {icon, label, title, panel}`: its button at
59
+ the end of the ribbon opens its panel beside the canvas, one at a time.
60
+ - The Spacing section of the properties is a box diagram, as in a browser's
61
+ developer tools: the margin outside, the border, the padding inside, the
62
+ content in the middle, each zone with its four sides typed in place and a
63
+ line saying what it sets. Every built-in block has the three zones.
64
+ - Borders: a width per side, a style (solid, dashed, dotted, double, groove,
65
+ ridge) and a color. On sections, columns, images and buttons, equal widths
66
+ write one `border` attribute; different ones write `border-top`,
67
+ `border-right`… A double, groove or ridge line starts at 3 px, the least
68
+ that draws it. A block property may take `type: 'border'`, and `box:
69
+ 'margin' | 'border' | 'padding'` to place it in the diagram.
70
+ - Spacing MJML has no attribute for (a section's margin, a text's border or
71
+ margin…) is kept in valid MJML: a section's margin as an `mj-wrapper`
72
+ (`css-class="eb-section-margin"`) around it, the others in an encoded
73
+ `eb-box-…` CSS class. The package's compiler (`compileMjml`, the server
74
+ handler) turns them into email tables; another MJML compiler ignores them.
75
+ - Vertical alignment on every block: on a content block it aligns its
76
+ column, on a layout all its columns. Columns of one desktop row now have
77
+ equal heights in the compiled email, their content where it is aligned;
78
+ stacked on mobile, they keep their own height. Outlook keeps MJML's table.
79
+ - The corner radius takes pixels or percentages, with no upper limit (a size
80
+ property may give `units: ['px', '%']`).
81
+ - Variable groups: the *Variables* panel lists the variables under their
82
+ group; the **+** beside *Group* creates an empty group, a group's **+** a
83
+ variable in it. A storage may give `listVariableGroups()` and
84
+ `saveVariableGroup(name)` (HTTP: `GET` and `POST /variable-groups`); a
85
+ server repository `listGroups()` and `insertGroup(name)`. New error codes:
86
+ `INVALID_GROUP`, `DUPLICATE_GROUP`, `NO_GROUP_STORE`.
87
+ - `--eb-accent-color`, set on `:root`, gives the accent of every screen (the
88
+ primary color, the focus ring and the light accent come from it).
89
+ - The storage may give `imageUrl(path)`: where the canvas, and the *Brand*
90
+ dialog for a logo, show an uploaded image when the page cannot load its
91
+ path itself (images on another origin, no server). The template and the
92
+ brand keep the path.
93
+
94
+ - The unsubscribe link is edited like the other variables, since each email
95
+ provider has its own: its *value if empty* is used when the sending gives
96
+ no `unsubscribeUrl` (an address, or the provider's tag such as `*|UNSUB|*`),
97
+ its *sample value* in the preview and test sends (`#` otherwise). Both must
98
+ be an address or a tag, never `javascript:`.
99
+ - Colors keep their transparency: the picker's alpha slider is written
100
+ `rgba()` in the email (MJML refuses `#RRGGBBAA`) and shown as `#RRGGBBAA` in
101
+ the field. Classic Outlook, which reads no `rgba()`, gets in `bgcolor` the
102
+ opaque color it looks like over white.
103
+ - *Background under the content* (Email → Colors): a color painted under the
104
+ sections, at the email's width. The rounded corners of a section show it
105
+ instead of the page background. MJML has no such attribute: it is written
106
+ as an `mj-wrapper` (`css-class="eb-content-layer"`) around the sections and
107
+ read back as `content-background-color` on `mj-body`. A full-width band or
108
+ an `mj-wrapper` of your own interrupts it. Left empty, the MJML is exactly
109
+ as before.
110
+ - *Proofread* without AI: `createLanguageToolProofreader({ url })` (from
111
+ `best-email-builder/ai` and `/ai/server`) is a `proofread` function that
112
+ asks a LanguageTool server. Its corrections show in the same dialog, as the
113
+ smallest change of their words: markup, links and merge tags stay. Style
114
+ suggestions, brands and acronyms, and a capital asked of a subject or a
115
+ button are left out; `ignoreWords` adds your own. Alone, it is the only
116
+ check, with no key; beside a provider, LanguageTool proofreads and the AI
117
+ writes. `LANGUAGETOOL_PUBLIC_API` is LanguageTool's free API, to try it
118
+ out (limited, and the texts go to LanguageTool). New error codes:
119
+ `CHECKER_UNAVAILABLE`, `CHECKER_BUSY`.
120
+
121
+ ### Fixed
122
+ - A color dragged in the picker (the area, the hue or the transparency
123
+ slider) paints the block as it moves, rather than when the mouse is
124
+ released. The whole drag is one undo step.
125
+ - Bold, italic… on a text only selected (not being edited) formatted it but
126
+ left it open with everything selected: the next emoji or variable replaced
127
+ the whole text. The format is applied to the whole text and the text is
128
+ closed at once; the ribbon shows the format of its words.
129
+ - An emoji clicked in the panel showed twice for a moment, and the grid moved
130
+ under the pointer as *Recently used* appeared.
131
+ - The live demo showed no uploaded image: it had no server to serve
132
+ `/email-assets/`. It now keeps uploads in the browser (Cache Storage, so
133
+ they outlive a reload) and shows them in the canvas, the preview and the
134
+ exported HTML.
135
+ - Removing the last column of a section left an empty section behind, shown
136
+ as a phantom block: the section goes with it.
137
+ - Dialogs, menus and tooltips could open under the host page's layers or the
138
+ canvas: they stay above.
139
+
140
+ ### Changed
141
+ - The space around a button, an image, a divider or the social icons is
142
+ called its margin (MJML's `padding` of these blocks); the button's inner
143
+ padding is its padding.
144
+ - The *Email provider variables* bar above the canvas is now the *Variables*
145
+ panel beside it, opened by the *Variables* button at the end of the ribbon.
146
+ It stays open while you insert, rather than growing under the pointer.
147
+ - *Write with AI* and *Rewrite with AI* are one section with ONE field: say
148
+ what to change in the text, or give a topic to write about — the model
149
+ tells which (`action: 'custom'` now does both; on a text with no words, the
150
+ words are a topic). The one-click rewrites stay under it.
151
+ - While the AI works on a text, it shimmers on the canvas; the answer comes
152
+ in word by word (at once with reduced motion). `editor.setContent` takes
153
+ `{ reveal: true }` for that, and `editor.showWorking(id)` shows the shimmer.
154
+ - The **×** of a variable cut over two lines sits at the variable's end, top
155
+ right of its last line, rather than after its first piece.
156
+ - The *Variables* panel shows the unsubscribe link among the others, with
157
+ its pencil, without a line between them. The panels beside the canvas show
158
+ no heading (their button names them), only their **×**; no line before the
159
+ ribbon's *Emojis* and *Variables* buttons.
160
+ - The *Brand* dialog: its fields are as high as the properties panel's; the
161
+ logo's square, larger and square, opens the file explorer (the *Upload*
162
+ button is gone); the preview is as tall as the fields beside it; the color
163
+ pickers have no transparency slider (brand colors stay opaque).
164
+ - `unsubscribeUrl` is optional: without it, `personalize` and `renderEmail`
165
+ use the link's value if empty, `sendTestEmail` its sample; the handler's
166
+ `previewUnsubscribeUrl` defaults to `null` (the sample, otherwise `#`).
167
+ - The *Proofread* dialog no longer says the AI reads the email: "Every text
168
+ is checked for spelling, grammar and punctuation mistakes", whoever checks.
169
+
9
170
  ## [0.15.0] — 2026-10-22
10
171
 
11
172
  ### Added
package/README.md CHANGED
@@ -52,6 +52,12 @@ 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 "+" under the selected element adds a block after it; a "+" after the
56
+ last social icon or menu link adds one more.
57
+ - A ribbon above the canvas, as in a word processor: bold, italic, underline,
58
+ strikethrough, link, size, line height and alignment, each tool
59
+ named in a tooltip. At its end, panels beside the canvas for the emojis
60
+ (searchable, named in seven languages) and the variables.
55
61
  - Desktop and mobile canvas, showing the real compiled email.
56
62
  - Undo and redo, autosave, local drafts, versions, and conflict detection
57
63
  between two editors.
@@ -66,10 +72,12 @@ once and given away.
66
72
 
67
73
  **AI, optional**
68
74
  - *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.
75
+ text, each correction shown word by word, applied in one step. By the AI,
76
+ or without AI by LanguageTool, on your own server.
77
+ - *Write with AI*, in one field: a text on a topic, or a change in your own
78
+ words, to fit the rest of the email; or in one click: shorter, longer,
79
+ fixed, friendlier, more formal, translated into 13 languages. The answer
80
+ comes in word by word.
73
81
  - *Suggest* three subject lines drawn from the email.
74
82
  - OpenRouter, Gemini, Groq, Mistral, OpenAI, DeepSeek, Cerebras, Ollama, any
75
83
  OpenAI-compatible API, Claude or your own agent. The model runs on your
@@ -79,7 +87,7 @@ once and given away.
79
87
  - A template library: search, favorites, up to three colored tags per
80
88
  template that also filter the list, and *Edit*, *Duplicate*, *Copy HTML*,
81
89
  *Download*, *Delete*.
82
- - Merge-tag variables, including ones your users create.
90
+ - Merge-tag variables, including ones your users create, sorted into groups by drag and drop.
83
91
  - Your brand read from your website: logo, colors and font.
84
92
  - One Fetch-API handler for Next.js, Hono, Bun, Deno, Cloudflare Workers and Express.
85
93
  - Seven interface languages, and any other through a dictionary.
@@ -145,7 +153,7 @@ the layout, Next.js, Express and image hosting.
145
153
  | [Editor and library](docs/EDITOR.md) | The three ways to mount them, every prop, theming. |
146
154
  | [Server](docs/SERVER.md) | Routes, handler options, the storage contract, your database. |
147
155
  | [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. |
156
+ | [AI](docs/AI.md) | Proofread, Write with AI, Subjects. Where the model runs, and the providers. |
149
157
  | [Your own AI agent](docs/AGENT.md) | The `agent@1` protocol. |
150
158
  | [Brand](docs/BRAND.md) | Logo, colors and font, read from a website. |
151
159
  | [Languages](docs/LANGUAGES.md) | Seven built in, your own strings, adding one. |
@@ -178,7 +186,8 @@ channel described in [SECURITY.md](SECURITY.md).
178
186
 
179
187
  ## License
180
188
 
181
- [MIT](LICENSE). MJML and mjml-browser are MIT too.
189
+ [MIT](LICENSE). MJML and mjml-browser are MIT too. The emoji names come from
190
+ emojibase-data (MIT), see [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md).
182
191
 
183
192
  ## Author
184
193
 
@@ -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-ZRER4JD4.js";
32
+ import "./chunk-2F7P4FXX.js";
33
+ import "./chunk-FPJF77MO.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,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,MAAI,KAAK,aAAa,eAAgB,QAAO,wBAAwB,KAAK,UAAU,KAAK,QAAQ,CAAC,gCAA2B,cAAc;AAC3I,MAAI,CAAC,MAAM,SAAS,KAAK,IAAI,EAAG,QAAO,gBAAgB,KAAK,UAAU,KAAK,IAAI,CAAC;AAChF,MAAI,OAAO,KAAK,WAAW,SAAU,QAAO;AAC5C,MAAI,CAAC,KAAK,UAAU,OAAO,KAAK,WAAW,SAAU,QAAO;AAC5D,QAAM,EAAE,SAAS,IAAI;AACrB,MAAI,CAAC,MAAM,QAAQ,QAAQ,KAAK,CAAC,SAAS,UAAU,SAAS,SAAS,aAAc,QAAO,+BAA+B,YAAY;AACtI,aAAW,WAAW,UAAU;AAC9B,QAAI,CAAC,WAAY,QAAQ,SAAS,UAAU,QAAQ,SAAS,eAAgB,OAAO,QAAQ,YAAY,UAAU;AAChH,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAcO,SAAS,oBAAoB,EAAE,UAAU,UAAU,CAAC,UAAU,QAAQ,MAAM,WAAW,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;AACjB,aAAW,CAAC,MAAM,KAAK,QAAQ,KAAK,OAAO;AACzC,UAAM,UAAU,KAAK,IAAI;AACzB,QAAI;AACF,YAAM,SAAS,MAAM,IAAI;AACzB,cAAQ,KAAK,EAAE,MAAM,IAAI,MAAM,IAAI,KAAK,IAAI,IAAI,SAAS,UAAU,OAAO,UAAU,QAAQ,SAAS,MAAM,EAAE,CAAC;AAAA,IAChH,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,KAA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