best-email-builder 0.16.0 → 0.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/README.md +3 -1
- package/dist/ai-server.js +3 -3
- package/dist/ai.js +20 -20
- package/dist/ai.js.map +1 -1
- package/dist/builder.js +8 -8
- package/dist/{chunk-AGA3BLRI.js → chunk-2F7P4FXX.js} +2 -2
- package/dist/{chunk-MC7JUFHI.js → chunk-37N22Z4Y.js} +7 -5
- package/dist/chunk-37N22Z4Y.js.map +1 -0
- package/dist/{chunk-HAHHRMQG.js → chunk-6CLBQRCI.js} +816 -595
- package/dist/chunk-6CLBQRCI.js.map +1 -0
- package/dist/{chunk-EFE245KW.js → chunk-FPJF77MO.js} +19 -1
- package/dist/chunk-FPJF77MO.js.map +1 -0
- package/dist/{chunk-RPDQABWZ.js → chunk-PCLRIXAQ.js} +2 -2
- package/dist/{chunk-MSHGCLCA.js → chunk-QDAVDMA4.js} +2 -2
- package/dist/{chunk-QLUCTFJ2.js → chunk-WFZO7GQ4.js} +2 -2
- package/dist/{chunk-F5H7ITED.js → chunk-XDE6SMXH.js} +4 -4
- package/dist/{chunk-F5H7ITED.js.map → chunk-XDE6SMXH.js.map} +1 -1
- package/dist/{chunk-7H7TLQBL.js → chunk-YPSSQZ4R.js} +20 -13
- package/dist/chunk-YPSSQZ4R.js.map +1 -0
- package/dist/{chunk-W5AJWWHH.js → chunk-Z5NGST5W.js} +3 -3
- package/dist/{chunk-W5AJWWHH.js.map → chunk-Z5NGST5W.js.map} +1 -1
- package/dist/{chunk-6OR6W4KJ.js → chunk-ZRER4JD4.js} +3 -3
- package/dist/index.js +10 -10
- package/dist/library.js +5 -5
- package/dist/server.js +5 -5
- package/dist/styles.css +1 -1
- package/dist/types/blocks/navbar/index.d.ts +1 -1
- package/dist/types/blocks/social/index.d.ts +7 -3
- package/dist/types/core/EmailEditor.d.ts +69 -0
- package/dist/types/core/constants.d.ts +1 -1
- package/dist/types/engine/NativeAdapter.d.ts +1 -1
- package/dist/types/engine/canvas/CanvasView.d.ts +20 -3
- package/dist/types/engine/canvas/canvasStyles.d.ts +1 -1
- package/dist/types/engine/canvas/icons.d.ts +1 -8
- package/dist/types/features/variables/VariablesPanel.d.ts +5 -0
- package/dist/types/ui/BlockSidebar.d.ts +34 -0
- package/dist/types/ui/CanvasAddMenu.d.ts +14 -0
- package/dist/types/ui/primitives/fields.d.ts +2 -0
- package/dist/types/ui/primitives/misc.d.ts +3 -1
- package/dist/types/ui/primitives/overlays.d.ts +1 -0
- package/package.json +1 -1
- package/dist/chunk-7H7TLQBL.js.map +0 -1
- package/dist/chunk-EFE245KW.js.map +0 -1
- package/dist/chunk-HAHHRMQG.js.map +0 -1
- package/dist/chunk-MC7JUFHI.js.map +0 -1
- /package/dist/{chunk-AGA3BLRI.js.map → chunk-2F7P4FXX.js.map} +0 -0
- /package/dist/{chunk-RPDQABWZ.js.map → chunk-PCLRIXAQ.js.map} +0 -0
- /package/dist/{chunk-MSHGCLCA.js.map → chunk-QDAVDMA4.js.map} +0 -0
- /package/dist/{chunk-QLUCTFJ2.js.map → chunk-WFZO7GQ4.js.map} +0 -0
- /package/dist/{chunk-6OR6W4KJ.js.map → chunk-ZRER4JD4.js.map} +0 -0
package/dist/ai.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ai/keys.js","../src/ai/ConnectAi.jsx","../src/ai/ModelPicker.jsx","../src/ai/ProofreadButton.jsx","../src/ai/RewriteText.jsx","../src/ai/chip.js","../src/ai/SubjectIdeas.jsx","../src/ai/createAi.js"],"sourcesContent":["// @ts-check\n/**\n * THE USER'S KEY — when the AI runs in the page with `askKey: true`, each\n * user connects their own provider key, once.\n *\n * The first AI action asks for it (the Connect dialog, `ConnectAi.jsx`); it is\n * kept in this browser (localStorage, one entry per provider) and sent only to\n * the provider. A key the provider refuses is forgotten, and asked again.\n * Given several providers, the user chooses one in the same dialog; the\n * choice is kept too, and so is the model chosen for each provider.\n *\n * ai.key.get(id?) the key in use, or the one kept for that provider ('' when none)\n * ai.key.set(key) connect a key without the dialog\n * ai.key.forget() disconnect: the next AI action asks again\n * ai.key.request() ask the user now → the key, or '' when they cancel\n * ai.key.choose(id) use another of the providers (its kept key, if any)\n * ai.key.model(id?) the model chosen for that provider (its own by default)\n * ai.key.chooseModel(model, id?) write with another of its models\n * ai.key.listModels(id?, { apiKey, address, signal }) the models it offers (providers.js)\n * ai.key.address(id?) where an OpenAI-compatible API of the user's own answers\n * ai.key.setAddress(url, id?) keep it (for a provider without an address of its own)\n * ai.key.ready() whether the provider in use can write: its key (unless it\n * needs none), its address, its model\n * ai.key.subscribe(fn) called on every change; returns the unsubscribe\n * ai.key.provider the provider in use: name, model, where to get a key, what is free\n * ai.key.providers all those the user can choose from\n */\n\nimport { listProviderModels } from './providers.js';\n\n/** @typedef {import('./providers.js').AiProvider} AiProvider */\n/** @typedef {import('./providers.js').ModelChoice} ModelChoice */\n\nconst STORAGE_PREFIX = 'best-email-builder:ai-key:';\nconst CHOICE_SLOT = 'best-email-builder:ai-provider';\nconst MODEL_PREFIX = 'best-email-builder:ai-model:';\nconst ADDRESS_PREFIX = 'best-email-builder:ai-address:';\n\n/** localStorage when there is one that works (not in private modes that throw, not on the server). */\nfunction browserStorage() {\n try {\n const storage = globalThis.localStorage;\n return storage && typeof storage.getItem === 'function' ? storage : null;\n } catch {\n return null;\n }\n}\n\n/**\n * @typedef {Readonly<{id: string, name: string, model: string|null, keyUrl: string|null, keyHint: string, free: string|null, publicModels: boolean, keyless: boolean, needsAddress: boolean}>} ProviderChoice\n * `keyless`: a key is optional (a server of the user's own may need none);\n * `needsAddress`: the user gives the address of the API (an\n * OpenAI-compatible one: LM Studio, vLLM, a proxy…).\n * @typedef {{\n * provider: ProviderChoice,\n * providers: ReadonlyArray<ProviderChoice>,\n * get: (id?: string) => string,\n * set: (key: string) => void,\n * forget: () => void,\n * request: () => Promise<string>,\n * choose: (id: string) => void,\n * model: (id?: string) => string,\n * chooseModel: (model: string, id?: string) => void,\n * listModels: (id?: string, options?: {apiKey?: string, address?: string, signal?: AbortSignal}) => Promise<ModelChoice[]>,\n * address: (id?: string) => string,\n * setAddress: (url: string, id?: string) => void,\n * ready: () => boolean,\n * subscribe: (listener: () => void) => () => void,\n * state: () => Readonly<{asking: boolean, refused: boolean, connected: boolean}>,\n * answer: (key: string|null) => void,\n * refuse: () => void,\n * }} AiKey\n * `state`, `answer` and `refuse` serve the Connect dialog and the module:\n * whether the user is being asked, whether the last key was refused;\n * `answer('')` connects without a key (a keyless provider), `answer(null)`\n * cancels. `listModels`: with the key and address given, else those kept\n * (no key is needed for a provider whose list is public, OpenRouter's).\n */\n\n/** @param {AiProvider} provider @returns {ProviderChoice} */\nconst choiceOf = (provider) =>\n Object.freeze({\n id: provider.id,\n name: provider.name,\n model: provider.model ?? null,\n keyUrl: provider.keyUrl,\n keyHint: provider.keyHint,\n free: provider.free,\n publicModels: Boolean(provider.publicModels),\n keyless: Boolean(provider.keyless),\n needsAddress: !provider.createModel && !provider.baseUrl,\n });\n\n/** An address of the user's own, as the API takes it: http(s), no trailing slash. @param {string} url */\nconst cleanAddress = (url) => String(url || '').trim().replace(/\\/+$/, '');\n\n/**\n * @param {AiProvider | AiProvider[]} providerOrList one provider, or those the user chooses from\n * @param {{fetch?: typeof fetch}} [options] the fetch that lists the models\n * @returns {AiKey}\n */\nexport function createKeyStore(providerOrList, { fetch: fetchImpl } = {}) {\n const originals = Array.isArray(providerOrList) ? providerOrList : [providerOrList];\n const providers = Object.freeze(originals.map(choiceOf));\n if (!providers.length) throw new TypeError('createKeyStore: at least one provider');\n const known = (/** @type {unknown} */ id) => providers.some((provider) => provider.id === id);\n /** Kept here too: a browser that does not store still works for the page's life. */\n const memory = new Map();\n let refused = false;\n /** @type {{promise: Promise<string>, resolve: (key: string) => void}|null} */\n let pending = null;\n /** @type {Set<() => void>} */\n const listeners = new Set();\n /** @type {ReturnType<AiKey['state']>} */\n let snapshot;\n\n /** @param {string} slot */\n const read = (slot) => {\n try {\n return browserStorage()?.getItem(slot) || '';\n } catch {\n return '';\n }\n };\n /** @param {string} slot @param {string} value */\n const write = (slot, value) => {\n try {\n const storage = browserStorage();\n if (value) storage?.setItem(slot, value);\n else storage?.removeItem(slot);\n } catch {\n // Full, or blocked: the key stays in memory.\n }\n };\n /** @param {string} id */\n const keyOf = (id) => (memory.has(id) ? memory.get(id) : read(STORAGE_PREFIX + id));\n /** @param {string} id @param {string} value */\n const keep = (id, value) => {\n memory.set(id, value);\n write(STORAGE_PREFIX + id, value);\n };\n // The provider chosen last time; else the first one with a key; else the first.\n const kept = read(CHOICE_SLOT);\n let current = known(kept) ? kept : (providers.find((provider) => keyOf(provider.id)) || providers[0]).id;\n /** @param {string} [id] */\n const get = (id) => keyOf(id === undefined ? current : String(id));\n /** @param {string} [id] */\n const providerId = (id) => {\n if (id === undefined) return current;\n if (!known(id)) throw new TypeError(`ai.key: no provider \"${id}\" — one of ${providers.map((provider) => provider.id).join(', ')}`);\n return id;\n };\n /** The models listed, by provider and key: a dialog opened again shows them at once. */\n const lists = new Map();\n /** @param {ProviderChoice} choice */\n const modelOf = (choice) => (memory.get(MODEL_PREFIX + choice.id) ?? read(MODEL_PREFIX + choice.id)) || choice.model || '';\n /** @param {ProviderChoice} choice */\n const addressOf = (choice) =>\n choice.needsAddress ? cleanAddress(memory.get(ADDRESS_PREFIX + choice.id) ?? read(ADDRESS_PREFIX + choice.id)) : '';\n /** The provider in use can write: its key (unless it needs none), its address, its model. */\n const ready = () => {\n const choice = /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === current));\n if (refused) return false;\n if (!choice.keyless && !get()) return false;\n if (choice.needsAddress && !addressOf(choice)) return false;\n return Boolean(modelOf(choice));\n };\n const changed = () => {\n snapshot = Object.freeze({ asking: Boolean(pending), refused, connected: ready() });\n for (const listener of [...listeners]) listener();\n };\n snapshot = Object.freeze({ asking: false, refused: false, connected: ready() });\n\n /** @param {string|null} key null: cancelled */\n const answer = (key) => {\n const value = String(key || '').trim();\n if (value) keep(current, value);\n // Connected, with a key or (keyless) without: the last refusal is over.\n if (key !== null && (value || get() || /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === current)).keyless)) refused = false;\n const waiting = pending;\n pending = null;\n changed();\n waiting?.resolve(value);\n };\n\n return Object.freeze({\n get provider() {\n return /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === current));\n },\n providers,\n get,\n set: (/** @type {string} */ key) => {\n if (typeof key !== 'string' || !key.trim()) throw new TypeError('ai.key.set: a non-empty key');\n answer(key);\n },\n forget: () => {\n keep(current, '');\n changed();\n },\n choose: (/** @type {string} */ id) => {\n if (!known(id)) throw new TypeError(`ai.key.choose: one of ${providers.map((provider) => provider.id).join(', ')}`);\n if (id === current) return;\n current = id;\n refused = false;\n write(CHOICE_SLOT, id);\n changed();\n },\n model: (/** @type {string|undefined} */ id) => modelOf(/** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)))),\n address: (/** @type {string|undefined} */ id) => addressOf(/** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)))),\n setAddress: (/** @type {string} */ url, /** @type {string|undefined} */ id) => {\n const choice = /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)));\n if (!choice.needsAddress) throw new TypeError(`ai.key.setAddress: ${choice.name} has an address of its own`);\n const value = cleanAddress(url);\n if (value && !/^https?:\\/\\/[^\\s/]+/i.test(value)) throw new TypeError('ai.key.setAddress: an http(s) address, e.g. http://localhost:1234/v1');\n memory.set(ADDRESS_PREFIX + choice.id, value);\n write(ADDRESS_PREFIX + choice.id, value);\n changed();\n },\n ready,\n chooseModel: (/** @type {string} */ model, /** @type {string|undefined} */ id) => {\n if (typeof model !== 'string' || !model.trim()) throw new TypeError('ai.key.chooseModel: a model id');\n const choice = /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)));\n // The provider's own model is kept as no choice: a new default reaches the user.\n const value = model.trim() === choice.model ? '' : model.trim();\n memory.set(MODEL_PREFIX + choice.id, value);\n write(MODEL_PREFIX + choice.id, value);\n changed();\n },\n listModels: async (/** @type {string|undefined} */ id, { apiKey, address, signal } = {}) => {\n const at = providers.findIndex((provider) => provider.id === providerId(id));\n const key = String(apiKey ?? keyOf(providers[at].id)).trim();\n const where = providers[at].needsAddress ? cleanAddress(address ?? addressOf(providers[at])) : '';\n if (providers[at].needsAddress && !where) return [];\n const slot = `${providers[at].id}\\n${key}\\n${where}`;\n const provider = where ? { ...originals[at], baseUrl: where } : originals[at];\n if (!lists.has(slot)) lists.set(slot, await listProviderModels({ provider, apiKey: key, fetch: fetchImpl, signal }));\n return lists.get(slot);\n },\n request: () => {\n if (!pending) {\n /** @type {(key: string) => void} */\n let resolve = () => {};\n const promise = new Promise((done) => (resolve = done));\n pending = { promise, resolve };\n changed();\n }\n return pending.promise;\n },\n subscribe: (/** @type {() => void} */ listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n state: () => snapshot,\n answer: (/** @type {string|null} */ key) => answer(key ?? null),\n refuse: () => {\n keep(current, '');\n refused = true;\n changed();\n },\n });\n}\n","import { useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';\nimport { ArrowUpRight, Eye, EyeOff, KeyRound, ShieldCheck, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { cn } from '../ui/primitives/cn.js';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { Input, Label } from '../ui/primitives/fields.jsx';\nimport { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '../ui/primitives/overlays.jsx';\nimport ModelPicker from './ModelPicker.jsx';\n\n/** A key this long is complete enough to ask the provider for its models. */\nconst LISTABLE_KEY = 20;\n/** An address the API can be asked at (keys.js keeps it without the trailing slash). */\nconst ADDRESS = /^https?:\\/\\/[^\\s/]+/i;\n\n/**\n * CONNECT — the dialog that asks the user for their provider key, when the AI\n * runs in the page with `createAi({ provider, askKey: true })`.\n *\n * It opens by itself when an AI action needs a key and there is none, or the\n * provider refused the last one; the action goes on once the key is given.\n * Cancel ends the action (\"Connect an AI provider first\"). The key is kept in\n * this browser and sent only to the provider (see keys.js).\n *\n * Given several providers (`createAi({ provider: [...] })`), the user chooses\n * one at the top; a provider whose key this browser already keeps needs no\n * new one. Under the key, the model: the provider's own, or another of its\n * list (ModelPicker.jsx). An OpenAI-compatible API of the user's own\n * ('openai-compatible': LM Studio, vLLM, a proxy…) takes its address first,\n * and a key only if it needs one.\n */\nexport default function ConnectAi({ aiKey }) {\n const { t } = useUi();\n const state = useSyncExternalStore(aiKey.subscribe, aiKey.state, aiKey.state);\n const [value, setValue] = useState('');\n const [address, setAddress] = useState('');\n const [shown, setShown] = useState(false);\n const [chosenId, setChosenId] = useState(aiKey.provider.id);\n /** The models chosen in the dialog, by provider, until Connect. */\n const [picks, setPicks] = useState(/** @type {Record<string, string>} */ ({}));\n const [modelsOpen, setModelsOpen] = useState(false);\n const inputRef = useRef(/** @type {HTMLInputElement|null} */ (null));\n const addressRef = useRef(/** @type {HTMLInputElement|null} */ (null));\n const choicesRef = useRef(/** @type {HTMLDivElement|null} */ (null));\n const inputId = useId();\n const hintId = useId();\n const addressId = useId();\n const addressHintId = useId();\n const choices = aiKey.providers;\n const chosen = choices.find((provider) => provider.id === chosenId) || aiKey.provider;\n const { name, keyUrl, keyHint, free, keyless, needsAddress } = chosen;\n\n // Each time it opens: the provider in use, an empty field, the key hidden.\n useEffect(() => {\n if (!state.asking) return;\n setChosenId(aiKey.provider.id);\n setAddress(aiKey.address());\n setValue('');\n setShown(false);\n setPicks({});\n setModelsOpen(false);\n }, [state.asking, aiKey]);\n\n const key = value.trim();\n // The key this browser keeps for the provider chosen (none for one refused).\n const saved = aiKey.get(chosen.id);\n // A key from elsewhere (another provider's) is the usual mistake: said, not blocked.\n const unusual = Boolean(key && keyHint && !key.startsWith(keyHint));\n const refused = state.refused && chosen.id === aiKey.provider.id;\n /** @param {string} id */\n const modelFor = (id) => picks[id] ?? aiKey.model(id);\n const where = address.trim().replace(/\\/+$/, '');\n const addressOk = !needsAddress || ADDRESS.test(where);\n // Connect: a key (unless it needs none), the address, a model to write with.\n const ready = Boolean((key || saved || keyless) && (!needsAddress || (where && addressOk)) && modelFor(chosen.id));\n\n const submit = (/** @type {React.FormEvent} */ event) => {\n event.preventDefault();\n if (!ready) return;\n if (needsAddress && where !== aiKey.address(chosen.id)) aiKey.setAddress(where, chosen.id);\n if (chosen.id !== aiKey.provider.id) aiKey.choose(chosen.id);\n if (picks[chosen.id] && picks[chosen.id] !== aiKey.model(chosen.id)) aiKey.chooseModel(picks[chosen.id], chosen.id);\n aiKey.answer(key || saved);\n };\n\n /** @param {string} id */\n const choose = (id) => {\n setChosenId(id);\n setAddress(aiKey.address(id));\n setValue('');\n setModelsOpen(false);\n };\n\n /** Arrows move through the providers and choose, as in any radio group. */\n const onChoicesKeyDown = (/** @type {React.KeyboardEvent} */ event) => {\n const at = choices.findIndex((provider) => provider.id === chosen.id);\n const step = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[event.key];\n const to = step ? (at + step + choices.length) % choices.length : event.key === 'Home' ? 0 : event.key === 'End' ? choices.length - 1 : -1;\n if (to === -1) return;\n event.preventDefault();\n choose(choices[to].id);\n /** @type {HTMLElement|undefined} */ (choicesRef.current?.querySelectorAll('[role=\"radio\"]')[to])?.focus();\n };\n\n return (\n <Dialog open={state.asking} onOpenChange={(open) => !open && aiKey.answer(null)}>\n <DialogContent\n className={cn('eb:max-h-[calc(100dvh-2rem)] eb:gap-0 eb:overflow-y-auto eb:p-0', choices.length > 1 ? 'eb:sm:max-w-xl' : 'eb:sm:max-w-md')}\n data-testid=\"eb-ai-connect\"\n onOpenAutoFocus={(event) => {\n event.preventDefault();\n (needsAddress && !where ? addressRef : inputRef).current?.focus();\n }}\n // Esc closes the list of models first, then the dialog. From inside\n // the list, the list closes itself (and gives the focus back to its field).\n onEscapeKeyDown={(event) => {\n if (!modelsOpen) return;\n event.preventDefault();\n if (!(event.target instanceof Element && event.target.closest('[data-eb-models]'))) setModelsOpen(false);\n }}\n >\n {/* min-w-0: the long names of the list of models do not widen the dialog. */}\n <form onSubmit={submit} className=\"eb:min-w-0\">\n <div className=\"eb:flex eb:flex-col eb:gap-5 eb:px-6 eb:pt-6 eb:pb-5\">\n <DialogHeader className=\"eb:flex-row eb:items-start eb:gap-3.5 eb:pr-6\">\n <span className=\"eb:flex eb:size-10 eb:shrink-0 eb:items-center eb:justify-center eb:rounded-full eb:bg-primary/10 eb:text-primary\">\n <KeyRound className=\"eb:size-5\" aria-hidden=\"true\" />\n </span>\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\">\n <DialogTitle>{t('Connect {provider}', { provider: name })}</DialogTitle>\n <DialogDescription className=\"eb:text-[13px] eb:leading-relaxed eb:text-foreground-lighter\">\n {needsAddress\n ? t('The AI writes with an OpenAI-compatible API of your choice. Give its address, and its key if it needs one: this browser remembers them.')\n : t('The AI writes with your own {provider} key. Connect it once: this browser remembers it.', { provider: name })}\n </DialogDescription>\n </div>\n </DialogHeader>\n\n {choices.length > 1 && (\n <div\n ref={choicesRef}\n role=\"radiogroup\"\n aria-label={t('AI provider')}\n className=\"eb:grid eb:grid-cols-2 eb:gap-1.5 eb:sm:grid-cols-3\"\n onKeyDown={onChoicesKeyDown}\n data-testid=\"eb-ai-connect-providers\"\n >\n {choices.map((provider) => {\n const checked = provider.id === chosen.id;\n return (\n <button\n key={provider.id}\n type=\"button\"\n role=\"radio\"\n aria-checked={checked}\n tabIndex={checked ? 0 : -1}\n onClick={() => choose(provider.id)}\n className={cn(\n 'eb:flex eb:min-w-0 eb:flex-col eb:gap-0.5 eb:rounded-md eb:border eb:px-2.5 eb:py-2 eb:text-left eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n checked ? 'eb:border-primary eb:bg-primary/10' : 'eb:border-border eb:hover:bg-muted'\n )}\n >\n <span className=\"eb:flex eb:items-center eb:gap-1.5 eb:text-[13px] eb:leading-tight eb:font-medium eb:text-foreground\">\n <span className=\"eb:truncate\">{provider.name}</span>\n {aiKey.get(provider.id) && (\n <span className=\"eb:ml-auto eb:size-1.5 eb:shrink-0 eb:rounded-full eb:bg-success\" title={t('Key saved')} aria-label={t('Key saved')} />\n )}\n </span>\n {modelFor(provider.id) && (\n <span className=\"eb:truncate eb:font-mono eb:text-[10.5px] eb:text-foreground-muted\" title={modelFor(provider.id)}>\n {modelFor(provider.id)}\n </span>\n )}\n </button>\n );\n })}\n </div>\n )}\n\n {refused && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-2 eb:rounded-md eb:border eb:border-destructive/30 eb:bg-destructive/10 eb:px-3 eb:py-2 eb:text-[12.5px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-px eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {t('{provider} refused the last key. Paste another one.', { provider: name })}\n </p>\n )}\n\n {(keyUrl || free) && (\n <div className=\"eb:flex eb:flex-wrap eb:items-center eb:gap-x-3 eb:gap-y-2\">\n {keyUrl && (\n <Button asChild variant=\"outline\" size=\"sm-compact\">\n <a\n href={keyUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n // A new tab, always — even where a link's target is ignored (webviews).\n onClick={(event) => {\n event.preventDefault();\n window.open(keyUrl, '_blank', 'noopener,noreferrer');\n }}\n data-testid=\"eb-ai-connect-get-key\"\n >\n {t('Get a key')}\n <ArrowUpRight aria-hidden=\"true\" />\n </a>\n </Button>\n )}\n {free && (\n <span className=\"eb:rounded-full eb:bg-success/10 eb:px-2.5 eb:py-1 eb:text-[11.5px] eb:font-medium eb:text-success\">\n {t(free)}\n </span>\n )}\n </div>\n )}\n\n {needsAddress && (\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\">\n <Label htmlFor={addressId}>{t('API address')}</Label>\n <Input\n ref={addressRef}\n id={addressId}\n type=\"url\"\n inputMode=\"url\"\n value={address}\n onChange={(event) => setAddress(event.target.value)}\n placeholder=\"http://localhost:1234/v1\"\n autoComplete=\"url\"\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n spellCheck={false}\n aria-invalid={where && !addressOk ? true : undefined}\n aria-describedby={addressHintId}\n className=\"eb:h-9 eb:font-mono eb:text-[12.5px]\"\n data-testid=\"eb-ai-connect-address\"\n />\n <p id={addressHintId} className=\"eb:text-[11.5px] eb:leading-relaxed eb:text-foreground-muted\">\n {where && !addressOk ? (\n <span className=\"eb:text-warning\">{t('An address starts with http:// or https://.')}</span>\n ) : (\n t('Any API that speaks OpenAI: LM Studio, vLLM, Ollama, a proxy of your own… It must accept requests from this page (CORS).')\n )}\n </p>\n </div>\n )}\n\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\">\n <Label htmlFor={inputId}>{keyless ? t('API key (optional)') : t('API key')}</Label>\n <div className=\"eb:relative\">\n <Input\n ref={inputRef}\n id={inputId}\n type={shown ? 'text' : 'password'}\n value={value}\n onChange={(event) => setValue(event.target.value)}\n placeholder={keyHint ? `${keyHint}…` : t('Paste the key')}\n autoComplete=\"off\"\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n spellCheck={false}\n aria-describedby={hintId}\n className=\"eb:h-9 eb:pr-10 eb:font-mono eb:text-[12.5px]\"\n data-testid=\"eb-ai-connect-key\"\n />\n <button\n type=\"button\"\n className=\"eb:absolute eb:top-1/2 eb:right-1 eb:flex eb:size-7 eb:-translate-y-1/2 eb:items-center eb:justify-center eb:rounded eb:text-foreground-muted eb:transition-colors eb:outline-none eb:hover:bg-muted eb:hover:text-foreground eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50\"\n onClick={() => setShown((current) => !current)}\n aria-label={shown ? t('Hide the key') : t('Show the key')}\n aria-pressed={shown}\n >\n {shown ? <EyeOff className=\"eb:size-4\" aria-hidden=\"true\" /> : <Eye className=\"eb:size-4\" aria-hidden=\"true\" />}\n </button>\n </div>\n <p id={hintId} className=\"eb:min-h-4 eb:text-[11.5px] eb:text-foreground-muted\">\n {unusual ? (\n <span className=\"eb:text-warning\">{t('{provider} keys usually start with {prefix}.', { provider: name, prefix: keyHint })}</span>\n ) : saved && !key ? (\n t('A key for {provider} is saved in this browser: Connect uses it, or paste another one.', { provider: name })\n ) : keyHint ? (\n t('{provider} keys start with {prefix}.', { provider: name, prefix: keyHint })\n ) : keyless ? (\n t('Leave it empty if the API needs no key.')\n ) : null}\n </p>\n </div>\n\n <ModelPicker\n aiKey={aiKey}\n provider={chosen}\n apiKey={key.length >= LISTABLE_KEY || (keyless && key) ? key : saved}\n address={addressOk ? where : ''}\n delay={key.length >= LISTABLE_KEY || (keyless && key) || where !== aiKey.address(chosen.id) ? 350 : 0}\n value={modelFor(chosen.id)}\n onChange={(model) => setPicks((current) => ({ ...current, [chosen.id]: model }))}\n open={modelsOpen}\n onOpenChange={setModelsOpen}\n />\n </div>\n\n <div className=\"eb:flex eb:items-start eb:gap-2 eb:border-t eb:border-border eb:bg-surface-75 eb:px-6 eb:py-3 eb:text-[11.5px] eb:leading-relaxed eb:text-foreground-lighter\">\n <ShieldCheck className=\"eb:mt-0.5 eb:size-3.5 eb:shrink-0 eb:text-foreground-muted\" aria-hidden=\"true\" />\n <span>\n {needsAddress\n ? t('The address and the key stay in this browser; the key is sent only to that address.')\n : t('The key stays in this browser and is sent only to {provider}.', { provider: name })}\n </span>\n </div>\n\n <DialogFooter className=\"eb:border-t eb:border-border eb:px-6 eb:py-4\">\n <Button type=\"button\" variant=\"ghost\" onClick={() => aiKey.answer(null)}>\n {t('Cancel')}\n </Button>\n <Button type=\"submit\" disabled={!ready} data-testid=\"eb-ai-connect-submit\">\n {t('Connect')}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n}\n","import { useEffect, useId, useMemo, useRef, useState } from 'react';\nimport { Check, ChevronDown, LoaderCircle, Search } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { cn } from '../ui/primitives/cn.js';\n\n/**\n * MODEL — the model of the provider chosen, in the Connect dialog: a field\n * that opens the provider's list of models in place (not over the dialog, so\n * the list scrolls like the rest of it).\n *\n * The list comes from the provider with the key (OpenRouter's needs none;\n * an OpenAI-compatible API of the user's own, from the address given):\n * the default model first, then the free ones, then the newest. Type to\n * filter, ↑/↓ to move, Enter to choose, Esc to close. An id the list does not\n * have can be used as it is (\"Use “…”\"); without the list, the default model\n * still works.\n *\n * @param {{\n * aiKey: import('./keys.js').AiKey,\n * provider: import('./keys.js').ProviderChoice,\n * apiKey: string,\n * address?: string,\n * delay?: number,\n * value: string,\n * onChange: (model: string) => void,\n * open: boolean,\n * onOpenChange: (open: boolean) => void,\n * }} props\n * `apiKey`: the key the list is asked with ('' when there is none yet);\n * `address`: where the API answers, for a provider that needs one;\n * `delay`: how long to wait after they change (a key being pasted).\n */\nexport default function ModelPicker({ aiKey, provider, apiKey, address = '', delay = 0, value, onChange, open, onOpenChange }) {\n const { t } = useUi();\n const [list, setList] = useState(/** @type {{status: 'loading'|'ready'|'needs-key'|'needs-address'|'refused'|'failed', models: import('./providers.js').ModelChoice[]}} */ ({ status: 'loading', models: [] }));\n const [query, setQuery] = useState('');\n const [freeOnly, setFreeOnly] = useState(false);\n const [active, setActive] = useState(0);\n const triggerRef = useRef(/** @type {HTMLButtonElement|null} */ (null));\n const listRef = useRef(/** @type {HTMLDivElement|null} */ (null));\n const labelId = useId();\n const valueId = useId();\n const listId = useId();\n const hintId = useId();\n\n // The list of the provider, asked again when the key (or the address) changes.\n useEffect(() => {\n if (provider.needsAddress && !address) {\n setList({ status: 'needs-address', models: [] });\n return undefined;\n }\n if (!apiKey && !provider.publicModels && !provider.keyless) {\n setList({ status: 'needs-key', models: [] });\n return undefined;\n }\n const controller = new AbortController();\n setList({ status: 'loading', models: [] });\n const timer = setTimeout(() => {\n aiKey.listModels(provider.id, { apiKey, address, signal: controller.signal }).then(\n (models) => !controller.signal.aborted && setList({ status: 'ready', models }),\n (error) => !controller.signal.aborted && setList({ status: error?.code === 'KEY_REFUSED' ? 'refused' : 'failed', models: [] })\n );\n }, delay);\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [aiKey, provider.id, provider.publicModels, provider.keyless, provider.needsAddress, apiKey, address, delay]);\n\n // Each time it opens: no search, the model in use under the keys.\n useEffect(() => {\n if (!open) return;\n setQuery('');\n setFreeOnly(false);\n }, [open]);\n\n // The default model first, then the one in use, then the list.\n const models = useMemo(() => {\n const listed = new Map(list.models.map((model) => [model.id, model]));\n const seen = new Set();\n /** @type {import('./providers.js').ModelChoice[]} */\n const all = [];\n const add = (/** @type {import('./providers.js').ModelChoice} */ model) => {\n if (model.id && !seen.has(model.id)) seen.add(model.id) && all.push(model);\n };\n for (const id of [provider.model, value]) if (id) add(listed.get(id) || { id, name: id, free: false });\n list.models.forEach(add);\n return all;\n }, [list.models, provider.model, value]);\n const hasFree = list.models.some((model) => model.free);\n const typed = query.trim();\n const matches = useMemo(() => {\n const words = typed.toLowerCase().split(/\\s+/).filter(Boolean);\n return models.filter((model) => (!freeOnly || model.free) && words.every((word) => `${model.id} ${model.name}`.toLowerCase().includes(word)));\n }, [models, typed, freeOnly]);\n // An id of one's own: a model the list does not have (or not yet).\n const custom = typed && !/\\s/.test(typed) && !models.some((model) => model.id === typed) ? typed : '';\n const count = matches.length + (custom ? 1 : 0);\n const current = models.find((model) => model.id === value);\n\n useEffect(() => setActive(Math.max(0, matches.findIndex((model) => model.id === value))), [matches, value]);\n useEffect(() => {\n if (open) listRef.current?.querySelector('[data-active=\"true\"]')?.scrollIntoView({ block: 'nearest' });\n }, [active, open]);\n\n const close = () => {\n triggerRef.current?.focus();\n onOpenChange(false);\n };\n /** @param {string} id */\n const pick = (id) => {\n onChange(id);\n close();\n };\n\n const onKeyDown = (/** @type {React.KeyboardEvent} */ event) => {\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault();\n setActive((at) => (count ? (at + (event.key === 'ArrowDown' ? 1 : -1) + count) % count : 0));\n } else if (event.key === 'Enter') {\n // The model, not the form: Connect is the button's.\n event.preventDefault();\n const id = active < matches.length ? matches[active]?.id : custom;\n if (id) pick(id);\n }\n };\n\n const optionId = (/** @type {number} */ at) => `${listId}-${at}`;\n const badges = (/** @type {import('./providers.js').ModelChoice} */ model) => (\n <>\n {model.free && (\n <span className=\"eb:shrink-0 eb:rounded-full eb:bg-success/10 eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-success\">\n {t('Free')}\n </span>\n )}\n {model.id === provider.model && (\n <span className=\"eb:shrink-0 eb:rounded-full eb:bg-muted eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-foreground-lighter\">{t('Default')}</span>\n )}\n </>\n );\n\n const status = {\n loading: (\n <>\n <LoaderCircle className=\"eb:size-3 eb:shrink-0 eb:animate-spin\" aria-hidden=\"true\" />\n {t('Loading the models of {provider}…', { provider: provider.name })}\n </>\n ),\n 'needs-key': t('Paste the key to see all the models of {provider}.', { provider: provider.name }),\n 'needs-address': t('Give the API address to see its models.'),\n refused: <span className=\"eb:text-warning\">{t('{provider} refused this key: its models could not be listed.', { provider: provider.name })}</span>,\n failed: provider.model\n ? t('The list of models could not be loaded. The default model works, or type the id of another.')\n : t('The list of models could not be loaded. Type the id of the model.'),\n ready: list.models.length\n ? hasFree\n ? t('{count} models, the free ones first.', { count: list.models.length })\n : t('{count} models.', { count: list.models.length })\n : t('{provider} lists no models here: type the id of the one you want.', { provider: provider.name }),\n }[list.status];\n\n return (\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\" data-testid=\"eb-ai-connect-model-field\">\n <span id={labelId} className=\"eb:text-[12.5px] eb:leading-none eb:font-medium eb:text-foreground\">\n {t('Model')}\n </span>\n <button\n ref={triggerRef}\n type=\"button\"\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-labelledby={`${labelId} ${valueId}`}\n aria-describedby={hintId}\n onClick={() => onOpenChange(!open)}\n className={cn(\n 'eb:flex eb:h-9 eb:w-full eb:min-w-0 eb:items-center eb:gap-2 eb:rounded-md eb:border eb:border-input eb:bg-transparent eb:px-3 eb:text-left eb:shadow-xs eb:transition-[color,box-shadow] eb:outline-none eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n open && 'eb:border-ring'\n )}\n data-testid=\"eb-ai-connect-model\"\n >\n <span id={valueId} className=\"eb:min-w-0 eb:truncate eb:font-mono eb:text-[12.5px] eb:text-foreground\">{value || t('Choose a model')}</span>\n {current && badges(current)}\n <ChevronDown className={cn('eb:ml-auto eb:size-4 eb:shrink-0 eb:text-foreground-muted eb:transition-transform', open && 'eb:rotate-180')} aria-hidden=\"true\" />\n </button>\n\n {open && (\n <div\n className=\"eb:flex eb:flex-col eb:overflow-hidden eb:rounded-md eb:border eb:border-border eb:bg-background\"\n onKeyDown={(event) => event.key === 'Escape' && close()}\n data-eb-models=\"\"\n data-testid=\"eb-ai-connect-models\"\n >\n <div className=\"eb:flex eb:items-center eb:gap-2 eb:border-b eb:border-border eb:p-2\">\n <div className=\"eb:relative eb:min-w-0 eb:flex-1\">\n <Search className=\"eb:pointer-events-none eb:absolute eb:top-1/2 eb:left-2 eb:size-3.5 eb:-translate-y-1/2 eb:text-foreground-muted\" aria-hidden=\"true\" />\n <input\n autoFocus\n role=\"combobox\"\n aria-expanded=\"true\"\n aria-controls={listId}\n aria-autocomplete=\"list\"\n aria-activedescendant={count ? optionId(active) : undefined}\n aria-label={t('Search the models')}\n value={query}\n onChange={(event) => setQuery(event.target.value)}\n onKeyDown={onKeyDown}\n placeholder={t('Search the models…')}\n autoComplete=\"off\"\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n spellCheck={false}\n className=\"eb:h-8 eb:w-full eb:rounded-md eb:bg-surface-75 eb:pr-2 eb:pl-7 eb:text-[13px] eb:text-foreground eb:outline-none eb:placeholder:text-foreground-muted eb:focus-visible:ring-2 eb:focus-visible:ring-ring/40\"\n data-testid=\"eb-ai-connect-model-search\"\n />\n </div>\n {hasFree && (\n <button\n type=\"button\"\n aria-pressed={freeOnly}\n onClick={() => setFreeOnly((on) => !on)}\n className={cn(\n 'eb:inline-flex eb:h-8 eb:shrink-0 eb:items-center eb:rounded-md eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n freeOnly ? 'eb:border-success/40 eb:bg-success/10 eb:text-success' : 'eb:border-border eb:text-foreground-lighter eb:hover:bg-muted'\n )}\n >\n {t('Free only')}\n </button>\n )}\n </div>\n <div ref={listRef} id={listId} role=\"listbox\" aria-labelledby={labelId} className=\"eb:max-h-56 eb:overflow-y-auto eb:p-1\">\n {matches.map((model, at) => (\n <button\n key={model.id}\n id={optionId(at)}\n type=\"button\"\n role=\"option\"\n tabIndex={-1}\n aria-selected={model.id === value}\n data-active={at === active}\n data-model={model.id}\n onClick={() => pick(model.id)}\n onMouseMove={() => at !== active && setActive(at)}\n className={cn(\n 'eb:flex eb:w-full eb:min-w-0 eb:items-start eb:gap-2 eb:rounded-md eb:px-2 eb:py-1.5 eb:text-left',\n at === active ? 'eb:bg-accent eb:text-accent-foreground' : ''\n )}\n >\n <Check className={cn('eb:mt-0.5 eb:size-3.5 eb:shrink-0 eb:text-primary', model.id !== value && 'eb:invisible')} aria-hidden=\"true\" />\n <span className=\"eb:flex eb:min-w-0 eb:flex-1 eb:flex-col eb:gap-0.5\">\n <span className=\"eb:flex eb:min-w-0 eb:items-center eb:gap-1.5\">\n <span className=\"eb:truncate eb:text-[13px] eb:text-foreground\">{model.name}</span>\n {badges(model)}\n </span>\n {model.name !== model.id && <span className=\"eb:truncate eb:font-mono eb:text-[10.5px] eb:text-foreground-muted\">{model.id}</span>}\n </span>\n </button>\n ))}\n {custom && (\n <button\n id={optionId(matches.length)}\n type=\"button\"\n role=\"option\"\n tabIndex={-1}\n aria-selected={false}\n data-active={active === matches.length}\n onClick={() => pick(custom)}\n onMouseMove={() => active !== matches.length && setActive(matches.length)}\n className={cn(\n 'eb:flex eb:w-full eb:min-w-0 eb:items-center eb:gap-2 eb:rounded-md eb:px-2 eb:py-1.5 eb:text-left eb:text-[13px] eb:text-primary',\n active === matches.length ? 'eb:bg-accent' : ''\n )}\n data-testid=\"eb-ai-connect-model-custom\"\n >\n <span className=\"eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n <span className=\"eb:min-w-0 eb:truncate\">{t('Use “{model}”', { model: custom })}</span>\n </button>\n )}\n {!count && <p className=\"eb:px-2 eb:py-3 eb:text-center eb:text-[12px] eb:text-foreground-muted\">{t('No model matches.')}</p>}\n </div>\n </div>\n )}\n\n <p id={hintId} role=\"status\" className=\"eb:flex eb:min-h-4 eb:items-center eb:gap-1.5 eb:text-[11.5px] eb:text-foreground-muted\" data-testid=\"eb-ai-connect-models-status\">\n {status}\n </p>\n </div>\n );\n}\n","import { useEffect, useRef, useState } from 'react';\nimport { Check, CircleCheck, Loader2, SpellCheck, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { cn } from '../ui/primitives/cn.js';\nimport { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '../ui/primitives/overlays.jsx';\nimport { cleanRichText } from '../engine/richText.js';\nimport { diffWords } from './diff.js';\nimport { visibleText } from './subjects.js';\n\n/**\n * PROOFREAD — toolbar button and dialog: the mistakes of the whole email.\n *\n * One click reads every text the reader sees — the subject, the preview\n * text, the text blocks, the buttons, the menu links — and lists the ones\n * with a mistake: the old words struck out, the new ones next to them. Each\n * correction is applied on its own or all at once; in the email, all of them\n * are one step of the history (Ctrl+Z brings the texts back). Nothing changes\n * before the user applies it.\n *\n * A text edited while the email is read, or before its correction is\n * applied, is left as it is: the correction was for the old one. Who reads it\n * — an AI, or LanguageTool (languagetool.js) — is the `proofread` function's.\n */\n\n/** Tags whose content is a label of plain words (EmailEditor `content`). */\nconst LABEL_TAGS = { 'mj-button': 'button', 'mj-navbar-link': 'link' };\n\n/** What each kind of text is called in the list. */\nconst KIND_LABELS = { subject: 'Subject', preheader: 'Preview text', text: 'Text', button: 'Button', link: 'Menu link' };\n\n/**\n * The texts of the email, in order: as they are stored, under the id the\n * correction comes back with.\n * @param {any} editor @param {{subject: string, preheader: string}} meta\n */\nfunction textsOf(editor, meta) {\n /** @type {{id: string, kind: keyof typeof KIND_LABELS, format: 'html'|'plain', text: string}[]} */\n const texts = [];\n if (meta.subject.trim()) texts.push({ id: 'subject', kind: 'subject', format: 'plain', text: meta.subject.trim() });\n if (meta.preheader.trim()) texts.push({ id: 'preheader', kind: 'preheader', format: 'plain', text: meta.preheader.trim() });\n const walk = (/** @type {any} */ node) => {\n if (!node || typeof node !== 'object') return;\n const element = node.tag === 'mj-text' || LABEL_TAGS[node.tag] ? editor.getElement(node.id) : null;\n if (node.tag === 'mj-text' && element?.html) texts.push({ id: node.id, kind: 'text', format: 'html', text: element.html });\n else if (LABEL_TAGS[node.tag] && element?.content) texts.push({ id: node.id, kind: LABEL_TAGS[node.tag], format: 'plain', text: element.content });\n for (const child of node.children || []) walk(child);\n };\n walk(editor.getDocument().project?.root);\n return texts;\n}\n\n/** The text of one entry as it is now. @param {any} editor @param {{subject: string, preheader: string}} meta @param {string} id */\nfunction currentText(editor, meta, id) {\n if (id === 'subject' || id === 'preheader') return meta[id].trim();\n const element = editor.getElement(id);\n return (element?.tagName === 'mj-text' ? element?.html : element?.content) ?? null;\n}\n\nexport default function ProofreadButton({ context, proofread }) {\n const { editor, ready, meta, setMeta } = context;\n const { t, locale, notify } = useUi();\n const [open, setOpen] = useState(false);\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState('');\n const [seconds, setSeconds] = useState(0);\n /** @type {[{id: string, kind: keyof typeof KIND_LABELS, format: 'html'|'plain', before: string, after: string, state: 'open'|'applied'|'stale'}[]|null, Function]} */\n const [fixes, setFixes] = useState(null);\n const abortRef = useRef(/** @type {AbortController|null} */ (null));\n const metaRef = useRef(meta);\n metaRef.current = meta;\n\n useEffect(() => () => abortRef.current?.abort(), []);\n useEffect(() => {\n if (!busy) return undefined;\n setSeconds(0);\n const timer = setInterval(() => setSeconds((s) => s + 1), 1000);\n return () => clearInterval(timer);\n }, [busy]);\n // Another email loaded: these corrections were for the previous one.\n useEffect(\n () =>\n editor.on('load', () => {\n abortRef.current?.abort();\n setOpen(false);\n }),\n [editor]\n );\n\n const run = async () => {\n if (busy) return;\n const texts = textsOf(editor, metaRef.current);\n setError('');\n setFixes(null);\n if (!texts.length) {\n setError(t('The email has no text to check yet.'));\n return;\n }\n setBusy(true);\n const controller = new AbortController();\n abortRef.current = controller;\n try {\n const result = await proofread(\n { texts: texts.map(({ id, kind, format, text }) => ({ id, kind, format, text })), language: String(locale || 'en').slice(0, 2) },\n { signal: controller.signal }\n );\n if (controller.signal.aborted) return;\n const sent = new Map(texts.map((text) => [text.id, text]));\n setFixes(\n result.fixes\n .filter((fix) => sent.has(fix.id))\n .map((fix) => {\n const text = /** @type {(typeof texts)[number]} */ (sent.get(fix.id));\n // Edited while it was read: the correction is for the old text.\n const stale = currentText(editor, metaRef.current, fix.id) !== text.text;\n return { id: fix.id, kind: text.kind, format: text.format, before: text.text, after: fix.text, state: stale ? 'stale' : 'open' };\n })\n );\n } catch (err) {\n if (!controller.signal.aborted) setError(err?.message ? t(err.message) : t('The email could not be checked.'));\n } finally {\n // A reading cancelled for a newer one leaves that one busy.\n if (abortRef.current === controller) {\n abortRef.current = null;\n setBusy(false);\n }\n }\n };\n\n // Read once the dialog is there. Without a key yet, the reading opens the\n // Connect dialog, which then comes above this one; opened in the same\n // render, it was hidden from screen readers and the keyboard.\n useEffect(() => {\n if (!open) return undefined;\n run();\n return () => abortRef.current?.abort();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n\n const openDialog = () => setOpen(true);\n\n const close = (next) => {\n if (next) return;\n abortRef.current?.abort();\n abortRef.current = null;\n setBusy(false);\n setOpen(false);\n };\n\n /**\n * Applies corrections still open, those whose text has not changed since;\n * the others are marked. The texts of the email change in one step.\n * @param {string[]} ids\n */\n const apply = (ids) => {\n if (!fixes) return;\n const wanted = new Set(ids);\n /** @type {{id: string, content: string}[]} */\n const contents = [];\n /** @type {Partial<{subject: string, preheader: string}>} */\n const metaChanges = {};\n const next = fixes.map((fix) => {\n if (!wanted.has(fix.id) || fix.state !== 'open') return fix;\n if (currentText(editor, metaRef.current, fix.id) !== fix.before) return { ...fix, state: /** @type {const} */ ('stale') };\n if (fix.id === 'subject' || fix.id === 'preheader') metaChanges[fix.id] = fix.after;\n else contents.push({ id: fix.id, content: fix.format === 'html' ? cleanRichText(fix.after, document) : fix.after });\n return { ...fix, state: /** @type {const} */ ('applied') };\n });\n if (contents.length) editor.setContents(contents);\n if (Object.keys(metaChanges).length) setMeta((current) => ({ ...current, ...metaChanges }));\n setFixes(next);\n const applied = next.filter((fix, index) => fix.state === 'applied' && fixes[index].state !== 'applied').length;\n if (applied && next.every((fix) => fix.state !== 'open')) {\n setOpen(false);\n notify('success', t('Corrections applied: {count}.', { count: next.filter((fix) => fix.state === 'applied').length }));\n }\n };\n\n const remaining = (fixes || []).filter((fix) => fix.state === 'open');\n\n return (\n <>\n <Button variant=\"outline\" size=\"sm-compact\" disabled={!ready} onClick={openDialog}>\n <SpellCheck />\n {t('Proofread')}\n </Button>\n <Dialog open={open} onOpenChange={close}>\n <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\">\n <DialogHeader className=\"eb:gap-1.5 eb:px-6 eb:pt-6 eb:pb-4\">\n <DialogTitle>{t('Proofread the email')}</DialogTitle>\n <DialogDescription>{t('Every text is checked for spelling, grammar and punctuation mistakes. Nothing changes until you apply it.')}</DialogDescription>\n </DialogHeader>\n\n <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\">\n {busy && (\n <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\">\n <Loader2 className=\"eb:size-4 eb:animate-spin\" aria-hidden=\"true\" />\n {t('Reading the email… {seconds} s', { seconds })}\n </p>\n )}\n {error && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-1.5 eb:py-2 eb:text-[13px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-0.5 eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {error}\n </p>\n )}\n {fixes && !fixes.length && (\n <p className=\"eb:flex eb:items-center eb:gap-2 eb:py-6 eb:text-[13px] eb:text-foreground\" role=\"status\">\n <CircleCheck className=\"eb:size-4 eb:text-success\" aria-hidden=\"true\" />\n {t('No mistake found.')}\n </p>\n )}\n {fixes && fixes.length > 0 && (\n <ul className=\"eb:flex eb:flex-col eb:gap-2.5\" aria-label={t('Corrections')}>\n {fixes.map((fix) => (\n <li\n key={fix.id}\n className={cn('eb:rounded-md eb:border eb:border-border eb:p-3', fix.state !== 'open' && 'eb:bg-muted/40')}\n data-testid=\"eb-proofread-fix\"\n data-state={fix.state}\n >\n <div className=\"eb:mb-1.5 eb:flex eb:items-center eb:gap-2\">\n <span className=\"eb:text-[11px] eb:font-medium eb:tracking-wide eb:text-foreground-muted eb:uppercase\">{t(KIND_LABELS[fix.kind])}</span>\n <span className=\"eb:ml-auto\">\n {fix.state === 'open' && (\n <Button variant=\"outline\" size=\"xs\" onClick={() => apply([fix.id])}>\n {t('Apply')}\n </Button>\n )}\n {fix.state === 'applied' && (\n <span className=\"eb:flex eb:items-center eb:gap-1 eb:text-[12px] eb:text-success\">\n <Check className=\"eb:size-3.5\" aria-hidden=\"true\" />\n {t('Applied')}\n </span>\n )}\n {fix.state === 'stale' && (\n <span className=\"eb:text-[12px] eb:text-foreground-muted\">{t('Text changed since — left as it is')}</span>\n )}\n </span>\n </div>\n <Changes before={fix.before} after={fix.after} html={fix.format === 'html'} />\n </li>\n ))}\n </ul>\n )}\n </div>\n\n <div className=\"eb:flex eb:items-center eb:justify-end eb:gap-2 eb:border-t eb:border-border eb:px-6 eb:py-4\">\n {busy ? (\n <Button variant=\"outline\" size=\"sm\" onClick={() => close(false)}>\n {t('Cancel')}\n </Button>\n ) : (\n <>\n <Button variant=\"ghost\" size=\"sm\" className=\"eb:mr-auto\" onClick={run}>\n {t('Check again')}\n </Button>\n {remaining.length > 0 ? (\n <Button size=\"sm\" onClick={() => apply(remaining.map((fix) => fix.id))} data-testid=\"eb-proofread-apply-all\">\n <Check />\n {t('Apply all ({count})', { count: remaining.length })}\n </Button>\n ) : (\n <Button variant=\"outline\" size=\"sm\" onClick={() => close(false)}>\n {t('Close')}\n </Button>\n )}\n </>\n )}\n </div>\n </DialogContent>\n </Dialog>\n </>\n );\n}\n\n/**\n * The words a correction changes: the old ones struck out, the new ones\n * marked, in the flow of the text.\n */\nfunction Changes({ before, after, html }) {\n const parts = diffWords(html ? visibleText(before) : before, html ? visibleText(after) : after);\n return (\n <p className=\"eb:text-[13px] eb:leading-relaxed eb:break-words eb:whitespace-pre-line eb:text-foreground\">\n {parts.map((part, index) =>\n part.type === 'same' ? (\n <span key={index}>{around(part.text, index === 0, index === parts.length - 1)}</span>\n ) : part.type === 'removed' ? (\n <del key={index} className=\"eb:rounded-sm eb:bg-destructive/10 eb:text-destructive eb:line-through\">\n {part.text}\n </del>\n ) : (\n <ins key={index} className=\"eb:rounded-sm eb:bg-success/15 eb:text-success eb:no-underline\">\n {part.text}\n </ins>\n )\n )}\n </p>\n );\n}\n\n/** Words kept on each side of a change; a longer stretch is cut short. */\nconst CONTEXT = 48;\n\n/**\n * Unchanged words between corrections, shortened around them: a long text\n * shows where its mistakes are, not the whole of it.\n * @param {string} text @param {boolean} first @param {boolean} last\n */\nfunction around(text, first, last) {\n if (text.length <= CONTEXT * 2 + 8) return text;\n const head = (/** @type {string} */ value) => value.slice(0, CONTEXT).replace(/\\s\\S*$/, '');\n const tail = (/** @type {string} */ value) => value.slice(-CONTEXT).replace(/^\\S*\\s/, '');\n if (first && last) return text;\n if (first) return `…${tail(text)}`;\n if (last) return `${head(text)}…`;\n return `${head(text)} … ${tail(text)}`;\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { ChevronDown, Languages, Loader2, Sparkles, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { Textarea } from '../ui/primitives/fields.jsx';\nimport { SectionLabel } from '../ui/primitives/misc.jsx';\nimport { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '../ui/primitives/overlays.jsx';\nimport { cleanRichText } from '../engine/richText.js';\nimport { chipClassName } from './chip.js';\nimport { MAX_REWRITE_INSTRUCTION, REWRITE_ACTIONS, REWRITE_LANGUAGES } from './rewrite.js';\nimport { emailWords, visibleText } from './subjects.js';\n\n/**\n * WRITE WITH AI — in the properties of a selected text or button.\n *\n * One field for the user's words: what to change in the text (\"say it in\n * two lines\"), or what to write instead (\"the sale ends Sunday\") — the AI\n * tells which, and writes to fit the rest of the email (its language, its\n * tone, nothing it already says); a block set as a title gets one line.\n * Under it, one click rewrites the text: shorter, longer, fixed, friendlier,\n * more formal, translated. While the AI works the text shimmers on the\n * canvas; its answer comes in word by word. It replaces the text in one step\n * of the history: Ctrl+Z brings the previous text back, so there is nothing\n * to accept or compare.\n *\n * Mounted per element (keyed by its id): selecting another element cancels a\n * rewrite in progress. If the text is edited while the AI works, the user's\n * words win and the answer is dropped.\n */\n\n/** A language under its own name: \"Deutsch\", \"Українська\". @param {string} code */\nfunction nativeName(code) {\n try {\n const name = new Intl.DisplayNames([code], { type: 'language' }).of(code) || code;\n return name.charAt(0).toLocaleUpperCase(code) + name.slice(1);\n } catch {\n return code;\n }\n}\n\nexport default function RewriteText({ editor, selection, rewrite }) {\n const { t, locale, notify } = useUi();\n const [running, setRunning] = useState(/** @type {string|null} */ (null));\n const [error, setError] = useState('');\n const [request, setRequest] = useState('');\n const abortRef = useRef(/** @type {AbortController|null} */ (null));\n const label = selection.tagName === 'mj-button';\n\n /** Stops the AI's work, and its shimmer on the canvas. */\n const stop = useCallback(() => {\n if (!abortRef.current) return;\n abortRef.current.abort();\n abortRef.current = null;\n editor.showWorking(null);\n }, [editor]);\n\n useEffect(() => stop, [stop]);\n\n /** The text as stored: a button's label, a text block's HTML. */\n const currentText = () => {\n const element = editor.getElement(selection.id);\n return (label ? element?.content : element?.html) ?? '';\n };\n\n const run = async (action, extra = {}) => {\n if (running) return;\n const text = currentText();\n // The user's own words: the AI writes; a click: it rewrites.\n const writing = action === 'custom';\n setError('');\n setRunning(action);\n const controller = new AbortController();\n abortRef.current = controller;\n editor.showWorking(selection.id);\n try {\n const result = await rewrite({ action, text, format: label ? 'plain' : 'html', ...extra }, { signal: controller.signal });\n if (controller.signal.aborted) return;\n if (currentText() !== text) {\n setError(t('The text changed in the meantime, so it was left as it is.'));\n return;\n }\n editor.setContent(label ? result.text : cleanRichText(result.text, document), selection.id, { reveal: true });\n if (action === 'custom') setRequest('');\n notify('success', writing ? t('Text written. Ctrl+Z brings back the previous one.') : t('Text rewritten. Ctrl+Z brings back the previous one.'));\n } catch (err) {\n if (!controller.signal.aborted) {\n setError(err?.message ? t(err.message) : writing ? t('The text could not be written.') : t('The text could not be rewritten.'));\n }\n } finally {\n if (abortRef.current === controller) {\n abortRef.current = null;\n editor.showWorking(null);\n }\n setRunning(null);\n }\n };\n\n const cancel = () => {\n stop();\n setRunning(null);\n };\n\n /** The user's words: a change, or what to write — fitting the rest of the email. */\n const ask = () => {\n const words = request.trim();\n if (!words) return;\n const size = Number.parseFloat(String(editor.getElement(selection.id)?.attributes?.['font-size'] || ''));\n // The email without this text: what the new one must fit, and not repeat.\n const own = visibleText(currentText());\n const email = emailWords(editor.exportMjml());\n run('custom', {\n instruction: words,\n context: own ? email.replace(own, '').trim() : email,\n role: size >= 20 ? 'heading' : 'text',\n language: String(locale || 'en').slice(0, 2),\n });\n };\n\n const busy = Boolean(running);\n const spinner = <Loader2 className=\"eb:size-3 eb:animate-spin\" aria-hidden=\"true\" />;\n\n return (\n <section className=\"eb:space-y-2.5\" aria-label={t('Write with AI')} data-testid=\"eb-rewrite\">\n <SectionLabel className=\"eb:flex eb:items-center eb:gap-1.5\">\n <Sparkles className=\"eb:size-3\" aria-hidden=\"true\" />\n {t('Write with AI')}\n </SectionLabel>\n <PromptForm\n value={request}\n onChange={setRequest}\n onSubmit={ask}\n placeholder={t('What should it say, or what should change? e.g. the sale ends Sunday')}\n label={t('Ask the AI')}\n busy={busy}\n submitLabel={t('Write')}\n >\n {running === 'custom' ? <Loader2 className=\"eb:animate-spin\" /> : <Sparkles />}\n </PromptForm>\n <div className=\"eb:flex eb:flex-wrap eb:gap-1.5\">\n {REWRITE_ACTIONS.map((action) => (\n <button key={action.id} type=\"button\" className={chipClassName()} disabled={busy} onClick={() => run(action.id)}>\n {running === action.id && spinner}\n {t(action.label)}\n </button>\n ))}\n <DropdownMenu>\n <DropdownMenuTrigger asChild disabled={busy}>\n <button type=\"button\" className={chipClassName()}>\n {running === 'translate' ? spinner : <Languages className=\"eb:size-3\" aria-hidden=\"true\" />}\n {t('Translate')}\n <ChevronDown className=\"eb:size-3\" aria-hidden=\"true\" />\n </button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"start\" aria-label={t('Translate into')}>\n {REWRITE_LANGUAGES.map((code) => (\n <DropdownMenuItem key={code} lang={code} onSelect={() => run('translate', { targetLanguage: code })}>\n {nativeName(code)}\n </DropdownMenuItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n {running && (\n <p className=\"eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted\" role=\"status\" aria-live=\"polite\">\n {running === 'custom' ? t('Writing…') : t('Rewriting…')}\n <Button type=\"button\" variant=\"link\" size=\"xs\" className=\"eb:h-auto eb:px-0\" onClick={cancel}>\n {t('Cancel')}\n </Button>\n </p>\n )}\n {error && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-px eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {error}\n </p>\n )}\n </section>\n );\n}\n\n/**\n * What the AI is asked, on a few lines so that the whole request stays in\n * view. Enter sends it, Shift+Enter starts a new line; an empty one is not\n * sent. `children`: the send button's icon.\n */\nfunction PromptForm({ value, onChange, onSubmit, placeholder, label, busy, submitLabel, children }) {\n const ready = !busy && Boolean(value.trim());\n return (\n <form\n className=\"eb:flex eb:items-end eb:gap-1.5\"\n onSubmit={(event) => {\n event.preventDefault();\n if (ready) onSubmit();\n }}\n >\n <Textarea\n dense\n rows={3}\n value={value}\n onChange={(event) => onChange(event.target.value)}\n onKeyDown={(event) => {\n if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing) return;\n event.preventDefault();\n if (ready) onSubmit();\n }}\n maxLength={MAX_REWRITE_INSTRUCTION}\n placeholder={placeholder}\n aria-label={label}\n disabled={busy}\n className=\"eb:min-h-16 eb:max-h-40 eb:resize-none\"\n />\n <Button type=\"submit\" variant=\"outline\" size=\"icon-dense\" aria-label={submitLabel} disabled={!ready}>\n {children}\n </Button>\n </form>\n );\n}\n","import { cn } from '../ui/primitives/cn.js';\n\n/**\n * A rounded badge button: the rewrite actions.\n * @param {boolean} [selected]\n */\nexport const chipClassName = (selected = false) =>\n cn(\n 'eb:inline-flex eb:h-[22px] eb:items-center eb:gap-1 eb:rounded-full eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:disabled:opacity-50',\n selected\n ? 'eb:border-primary eb:bg-primary eb:text-primary-foreground'\n : 'eb:border-border eb:bg-background eb:text-foreground eb:hover:border-primary/50 eb:hover:bg-primary/5'\n );\n","import { useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { Check, Loader2, Sparkles, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { cn } from '../ui/primitives/cn.js';\nimport { chipClassName } from './chip.js';\nimport { emailWords } from './subjects.js';\n\n/** Ideas already shown that \"More ideas\" asks the model not to repeat (the server keeps 12). */\nconst MAX_AVOID = 12;\n\n/**\n * SUGGEST SUBJECTS — under the subject of the email.\n *\n * One click: three other subject lines, drawn from the words of the email.\n * They are a list to pick from, the user's own subject first: a click puts\n * one in the field, another click another one, the first row brings the\n * user's subject back. \"More ideas\" asks for three new ones (none of those\n * already shown; the one in the field stays in the list); \"Done\" closes the\n * list and keeps the subject in the field.\n *\n * \"Yours\" is what the user wrote: typed in the field while the list is open\n * (or while ideas are on their way), it becomes the new \"yours\". When the\n * email itself is replaced (another template opened), the list closes.\n *\n * Keyboard: the list is a radio group — one Tab stop, the arrows move and\n * pick. Focus goes to the list when it opens, back to the button after Done or\n * Cancel.\n */\nexport default function SubjectIdeas({ editor, meta, onSubject, suggest, variables = null }) {\n const { t, locale } = useUi();\n const [running, setRunning] = useState(false);\n const [error, setError] = useState('');\n const [ideas, setIdeas] = useState(/** @type {string[]|null} */ (null));\n const [original, setOriginal] = useState('');\n const shownRef = useRef(/** @type {string[]} */ ([]));\n const abortRef = useRef(/** @type {AbortController|null} */ (null));\n const subjectRef = useRef(meta.subject);\n subjectRef.current = meta.subject;\n const rootRef = useRef(/** @type {HTMLDivElement|null} */ (null));\n /** Where focus goes after the next render: the list, or the button that opened it. */\n const focusRef = useRef(/** @type {'list'|'button'|null} */ (null));\n\n useEffect(() => () => abortRef.current?.abort(), []);\n\n // Another email loaded in the editor: these ideas were for the previous one.\n useEffect(\n () =>\n editor.on('load', () => {\n abortRef.current?.abort();\n abortRef.current = null;\n shownRef.current = [];\n setRunning(false);\n setIdeas(null);\n setError('');\n setOriginal('');\n }),\n [editor]\n );\n\n // Typed in the field while the list is open: that is the user's subject now.\n const typed = meta.subject.trim();\n useEffect(() => {\n if (ideas && typed && !ideas.includes(meta.subject) && typed !== original) setOriginal(typed);\n }, [ideas, meta.subject, typed, original]);\n\n useLayoutEffect(() => {\n const target = focusRef.current;\n if (!target || running) return;\n focusRef.current = null;\n const root = rootRef.current;\n const element =\n target === 'list'\n ? root?.querySelector('[role=\"radio\"][tabindex=\"0\"]')\n : root?.querySelector('[data-subject-ideas-button]');\n /** @type {HTMLElement|null|undefined} */ (element)?.focus();\n });\n\n const ready = editor.status === 'ready';\n\n const run = async () => {\n if (running || editor.status !== 'ready') return;\n const first = !ideas;\n // The user's subject: as it was before the first idea was picked, or typed since.\n const yours = first ? subjectRef.current.trim() : original;\n const controller = new AbortController();\n abortRef.current = controller;\n setError('');\n setRunning(true);\n try {\n const result = await suggest(\n {\n subject: yours,\n preheader: meta.preheader,\n text: emailWords(editor.exportMjml()),\n language: locale,\n variables: variables?.map(({ key, label, kind }) => ({ key, label, kind })),\n avoid: shownRef.current.slice(-MAX_AVOID),\n },\n { signal: controller.signal }\n );\n if (controller.signal.aborted) return;\n const current = subjectRef.current;\n // The idea in the field stays in the list; the others give way to the new ones.\n const kept = ideas?.includes(current) ? [current] : [];\n const next = [...kept, ...result.subjects.filter((subject) => subject !== current)];\n shownRef.current = [...shownRef.current, ...result.subjects];\n // Typed during the wait: that is \"yours\" now.\n setOriginal(current.trim() && !ideas?.includes(current) ? current.trim() : yours);\n setIdeas(next);\n if (first) focusRef.current = 'list';\n } catch (err) {\n if (!controller.signal.aborted) setError(err?.message ? t(err.message) : t('No subject could be suggested.'));\n } finally {\n // A request cancelled earlier must not end the one that replaced it.\n if (abortRef.current === controller) {\n abortRef.current = null;\n setRunning(false);\n }\n }\n };\n\n const cancel = () => {\n abortRef.current?.abort();\n abortRef.current = null;\n setRunning(false);\n focusRef.current = 'button';\n };\n\n const done = () => {\n setIdeas(null);\n setError('');\n shownRef.current = [];\n focusRef.current = 'button';\n };\n\n const options = ideas ? [...(original ? [{ text: original, yours: true }] : []), ...ideas.map((text) => ({ text, yours: false }))] : [];\n const checked = options.findIndex((option) => option.text === meta.subject);\n const tabStop = checked === -1 ? 0 : checked;\n\n /** Arrows move through the ideas and pick, as in any radio group. */\n const onKeyDown = (/** @type {React.KeyboardEvent} */ event) => {\n const step = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[event.key];\n const to = step ? (tabStop + step + options.length) % options.length : event.key === 'Home' ? 0 : event.key === 'End' ? options.length - 1 : -1;\n if (to === -1 || !options.length) return;\n event.preventDefault();\n onSubject(options[to].text);\n /** @type {HTMLElement|undefined} */ (rootRef.current?.querySelectorAll('[role=\"radio\"]')[to])?.focus();\n };\n\n const spinner = <Loader2 className=\"eb:size-3 eb:animate-spin\" aria-hidden=\"true\" />;\n\n return (\n <div className=\"eb:space-y-2\" data-testid=\"eb-subject-ideas\" ref={rootRef}>\n {!ideas && (\n <button type=\"button\" className={chipClassName()} disabled={running || !ready} onClick={run} data-subject-ideas-button>\n {running ? spinner : <Sparkles className=\"eb:size-3\" aria-hidden=\"true\" />}\n {t('Suggest subjects')}\n </button>\n )}\n {ideas && (\n <div className=\"eb:space-y-2 eb:rounded-md eb:border eb:border-border eb:p-1.5\">\n <div role=\"radiogroup\" aria-label={t('Subject ideas')} className=\"eb:space-y-0.5\" onKeyDown={onKeyDown}>\n {options.map((option, index) => {\n const chosen = index === checked;\n return (\n <button\n key={`${option.yours ? 'yours' : 'idea'}:${option.text}`}\n type=\"button\"\n role=\"radio\"\n aria-checked={chosen}\n tabIndex={index === tabStop ? 0 : -1}\n className={cn(\n 'eb:flex eb:w-full eb:items-start eb:gap-2 eb:rounded eb:px-2 eb:py-1.5 eb:text-left eb:text-[12.5px] eb:leading-snug eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n chosen ? 'eb:bg-primary/10 eb:text-foreground' : 'eb:text-foreground-lighter eb:hover:bg-muted'\n )}\n onClick={() => onSubject(option.text)}\n >\n <Check className={cn('eb:mt-0.5 eb:size-3.5 eb:shrink-0', chosen ? 'eb:text-primary' : 'eb:invisible')} aria-hidden=\"true\" />\n <span className=\"eb:min-w-0 eb:flex-1 eb:break-words\">{option.text}</span>\n {option.yours && <span className=\"eb:shrink-0 eb:text-[11px] eb:text-foreground-muted\">{t('yours')}</span>}\n </button>\n );\n })}\n </div>\n <div className=\"eb:flex eb:items-center eb:gap-1.5 eb:px-1 eb:pb-0.5\">\n <button type=\"button\" className={chipClassName()} disabled={running || !ready} onClick={run} data-subject-ideas-button>\n {running ? spinner : <Sparkles className=\"eb:size-3\" aria-hidden=\"true\" />}\n {t('More ideas')}\n </button>\n <Button type=\"button\" variant=\"ghost\" size=\"xs\" className=\"eb:ml-auto\" disabled={running} onClick={done}>\n {t('Done')}\n </Button>\n </div>\n </div>\n )}\n {running && (\n <p className=\"eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted\" role=\"status\" aria-live=\"polite\">\n {t('Reading the email…')}\n <Button type=\"button\" variant=\"link\" size=\"xs\" className=\"eb:h-auto eb:px-0\" onClick={cancel}>\n {t('Cancel')}\n </Button>\n </p>\n )}\n {error && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-px eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {error}\n </p>\n )}\n </div>\n );\n}\n","// @ts-check\n/**\n * THE AI MODULE — `createAi()`, given to the builder as `ai`.\n *\n * import { createAi } from 'best-email-builder/ai';\n * <EmailBuilder storage={storage} ai={createAi()} />\n *\n * Without it, the builder has no AI button, and none of the AI's code or\n * texts is in the application's bundle: the core never imports this folder.\n * With it, the builder gets what the module can do:\n *\n * proofread the Proofread button: the mistakes of every text, to apply\n * rewrite \"Write with AI\" and \"Rewrite with AI\" in the properties\n * of a text or a button\n * suggestSubjects \"Suggest subjects\" under the subject\n *\n * Where the model runs:\n *\n * createAi() the routes of createEmailBuilderHandler({ generator })\n * createAi({ baseUrl, headers }) the same routes elsewhere, or with the user's credentials\n * createAi({ provider, askKey: true }) the AI runs in the page with each user's own key\n * (OpenRouter, Gemini, Groq… — see providers.js);\n * the builder asks for it once (the Connect dialog)\n * createAi({ provider: [...], askKey: true })\n * the same, the user choosing the provider in that\n * dialog (Claude too: claudeProvider in claude.js),\n * and the model among those the provider lists\n * createAi({ provider, apiKey }) the same with one key for all (prototypes: the key\n * is then in the page)\n * createAi({ model }) the generator runs in the page with this model\n * createAi({ proofread, rewrite, … }) functions of your own: only those given are on —\n * createLanguageToolProofreader({ url }) proofreads\n * without AI (languagetool.js)\n *\n * Each of `proofread`, `rewrite` and `suggestSubjects` can also be `false`,\n * to leave that part out — its button with it.\n */\n\nimport { createHttpCaller } from '../storage/client.js';\nimport { EmailGenerationError } from './errors.js';\nimport { createEmailGenerator } from './generator.js';\nimport { AI_MESSAGES } from './i18n/index.js';\nimport { createKeyStore } from './keys.js';\nimport { providerEmailModel, resolveProvider } from './providers.js';\nimport ConnectAi from './ConnectAi.jsx';\nimport ProofreadButton from './ProofreadButton.jsx';\nimport RewriteText from './RewriteText.jsx';\nimport SubjectIdeas from './SubjectIdeas.jsx';\n\n/**\n * @typedef {import('./rewrite.js').RewriteInput} RewriteInput\n * @typedef {import('./subjects.js').SubjectsInput} SubjectsInput\n * @typedef {import('./proofread.js').ProofreadInput} ProofreadInput\n * @typedef {{signal?: AbortSignal}} CallOptions\n * @typedef {(input: ProofreadInput, options?: CallOptions) => Promise<{fixes: import('./proofread.js').ProofreadFix[]}>} ProofreadFn\n * @typedef {(input: RewriteInput, options?: CallOptions) => Promise<{text: string}>} RewriteFn\n * @typedef {(input: SubjectsInput, options?: CallOptions) => Promise<{subjects: string[]}>} SuggestSubjectsFn\n *\n * @typedef {{\n * baseUrl?: string,\n * headers?: Record<string, string> | (() => Record<string, string>),\n * fetch?: typeof fetch,\n * model?: import('./generator.js').EmailModel,\n * provider?: ProviderOption | ProviderOption[],\n * apiKey?: string,\n * askKey?: boolean,\n * maxAttempts?: number,\n * proofread?: ProofreadFn | boolean,\n * rewrite?: RewriteFn | boolean,\n * suggestSubjects?: SuggestSubjectsFn | boolean,\n * }} AiOptions\n * `provider`: an id of `AI_PROVIDERS` ('openrouter', 'gemini', 'groq'…), or\n * `{ id, model, baseUrl, headers }` for another model or an endpoint of your\n * own — or a list of them, with `askKey`: the user chooses (the first is\n * offered first). `apiKey`: one key for every user. `askKey`: each user\n * connects their own (off by default).\n *\n * @typedef {Readonly<{\n * proofread: ProofreadFn | null,\n * rewrite: RewriteFn | null,\n * suggestSubjects: SuggestSubjectsFn | null,\n * key: import('./keys.js').AiKey | null,\n * messages: Record<string, Record<string, string>>,\n * components: Readonly<{Proofread: typeof ProofreadButton, Rewrite: typeof RewriteText, Subjects: typeof SubjectIdeas, Connect: typeof ConnectAi | null}>,\n * }>} EmailBuilderAi\n * What the builder reads. `key`: the user's key, with `askKey` (keys.js).\n * `messages`: the module's own translations, by locale, merged under the\n * host's `messages`. `components.Connect`: the dialog that asks for the key.\n */\n\n/** @typedef {string | Partial<import('./providers.js').AiProvider>} ProviderOption */\n\nconst PARTS = /** @type {const} */ (['proofread', 'rewrite', 'suggestSubjects']);\nconst ROUTES = { proofread: '/proofread', rewrite: '/rewrite', suggestSubjects: '/subjects' };\n\n/**\n * @param {AiOptions} [options]\n * @returns {EmailBuilderAi}\n */\nexport function createAi(options = {}) {\n if (!options || typeof options !== 'object') throw new TypeError('createAi: options must be an object');\n const { model, maxAttempts, baseUrl, headers, fetch: fetchImpl, provider: providerOption, apiKey, askKey = false } = options;\n const usesProvider = providerOption !== undefined;\n const http = baseUrl !== undefined || headers !== undefined || (fetchImpl !== undefined && !usesProvider);\n if (model !== undefined && typeof model !== 'function') throw new TypeError('createAi: `model` must be a function');\n if (model && http) throw new TypeError('createAi: pass `model` (the AI runs in the page) or `baseUrl` (on the server), not both');\n if (usesProvider && (model || http)) {\n throw new TypeError('createAi: `provider` runs the AI in the page — not with `model`, `baseUrl` or `headers` (give the provider `{ id, model, baseUrl, headers }`)');\n }\n if (!usesProvider && (apiKey !== undefined || options.askKey !== undefined)) {\n throw new TypeError('createAi: `apiKey` and `askKey` go with a `provider` (e.g. provider: \"openrouter\")');\n }\n if (apiKey !== undefined && (typeof apiKey !== 'string' || !apiKey)) throw new TypeError('createAi: `apiKey` must be a non-empty string');\n // Gone in 0.10: no email is written from scratch any more. `false` (off) asks for nothing.\n const { generate } = /** @type {any} */ (options);\n if (generate !== undefined && generate !== false) {\n throw new TypeError('createAi: `generate` was removed in 0.10 — the AI checks and writes the texts of an email (`proofread`, `rewrite`), not whole emails');\n }\n if (typeof askKey !== 'boolean') throw new TypeError('createAi: `askKey` must be true or false');\n if (apiKey && askKey) throw new TypeError('createAi: `apiKey` (one key for all) or `askKey` (each user\\'s own), not both');\n const choice = Array.isArray(providerOption);\n if (choice && (!providerOption.length || !askKey)) {\n throw new TypeError('createAi: a list of providers is for `askKey: true` — each user chooses one and connects their own key');\n }\n /** @type {import('./providers.js').AiProvider[]} */\n const providers = usesProvider ? (choice ? providerOption : [providerOption]).map(providerOf) : [];\n if (new Set(providers.map((provider) => provider.id)).size !== providers.length) throw new TypeError('createAi: each provider once');\n const [provider = null] = providers;\n if (provider && !apiKey && !askKey && !provider.keyless) {\n throw new TypeError(`createAi: ${provider.name} needs a key — \\`apiKey\\`, or \\`askKey: true\\` to let each user connect their own`);\n }\n for (const part of PARTS) {\n const value = options[part];\n if (value !== undefined && typeof value !== 'boolean' && typeof value !== 'function') {\n throw new TypeError(`createAi: \\`${part}\\` must be a function, true or false`);\n }\n }\n\n // Functions of the host's own and nothing else: only those are on.\n const ownOnly = !model && !http && PARTS.some((part) => typeof options[part] === 'function');\n /** @type {Partial<Record<typeof PARTS[number], Function>>} */\n let transport = {};\n const key = provider && askKey ? createKeyStore(providers, { fetch: fetchImpl }) : null;\n if (provider) {\n /** @type {Map<string, import('./generator.js').EmailModel>} */\n const models = new Map();\n const keyFor = () => (key ? key.get() : apiKey || '');\n /** The model the user chose of the provider in use, made once. @param {string} id */\n const modelOf = (id) => {\n const chosen = /** @type {import('./providers.js').AiProvider} */ (providers.find((item) => item.id === id));\n const name = key ? key.model(id) : chosen.model;\n // An OpenAI-compatible API of the user's own: where it answers is theirs too.\n const address = key && key.providers.find((item) => item.id === id)?.needsAddress ? key.address(id) : '';\n const slot = `${id}\\n${name}\\n${address}`;\n if (!models.has(slot)) {\n models.set(\n slot,\n chosen.createModel\n ? chosen.createModel({ apiKey: keyFor, fetch: fetchImpl, ...(name ? { model: name } : {}) })\n : providerEmailModel({ provider: chosen, fetch: fetchImpl, apiKey: keyFor, ...(name ? { model: name } : {}), ...(address ? { baseUrl: address } : {}) })\n );\n }\n return /** @type {import('./generator.js').EmailModel} */ (models.get(slot));\n };\n /** @type {import('./generator.js').EmailModel} */\n const model = async (request) => {\n // The user's key (and the address, the model it needs), asked when\n // missing — they may choose another provider there. Cancelled: KEY_MISSING.\n if (key && !key.ready()) {\n await key.request();\n if (!key.ready()) throw new EmailGenerationError('KEY_MISSING', `${key.provider.name}: not connected`);\n }\n return modelOf(key ? key.provider.id : provider.id)(request);\n };\n const generator = createEmailGenerator({ model, maxAttempts });\n for (const part of PARTS) transport[part] = key ? askedAgain(generator[part], key) : generator[part];\n } else if (model) {\n transport = createEmailGenerator({ model, maxAttempts });\n } else if (!ownOnly) {\n const { call } = createHttpCaller({ baseUrl, headers, fetch: fetchImpl });\n for (const part of PARTS) {\n transport[part] = (/** @type {object} */ input, /** @type {CallOptions} */ { signal } = {}) =>\n call(ROUTES[part], { method: 'POST', body: JSON.stringify(input), signal });\n }\n }\n\n /** @param {typeof PARTS[number]} part */\n const resolve = (part) => {\n const value = options[part];\n if (typeof value === 'function') return value;\n if (value === false) return null;\n return transport[part] || null;\n };\n\n return Object.freeze({\n proofread: /** @type {ProofreadFn|null} */ (resolve('proofread')),\n rewrite: /** @type {RewriteFn|null} */ (resolve('rewrite')),\n suggestSubjects: /** @type {SuggestSubjectsFn|null} */ (resolve('suggestSubjects')),\n key,\n messages: AI_MESSAGES,\n components: Object.freeze({ Proofread: ProofreadButton, Rewrite: RewriteText, Subjects: SubjectIdeas, Connect: key ? ConnectAi : null }),\n });\n}\n\n/**\n * A provider of the list: an id, `{ id, model, … }`, or one with its own\n * `createModel` (claudeProvider) taken as it is.\n * @param {ProviderOption} option\n * @returns {import('./providers.js').AiProvider}\n */\nfunction providerOf(option) {\n if (option && typeof option === 'object' && typeof option.createModel === 'function') {\n if (!option.id || !option.name) throw new TypeError('createAi: a provider with `createModel` needs an `id` and a `name`');\n return /** @type {import('./providers.js').AiProvider} */ (option);\n }\n return resolveProvider(/** @type {any} */ (option));\n}\n\n/**\n * A key the provider refuses is forgotten and asked again, once, in the same\n * action: the user pastes a good one and the email still comes.\n * @param {Function} run\n * @param {import('./keys.js').AiKey} key\n */\nfunction askedAgain(run, key) {\n return async (/** @type {any} */ input, /** @type {any} */ options) => {\n try {\n return await run(input, options);\n } catch (error) {\n if (/** @type {any} */ (error)?.code !== 'KEY_REFUSED' || options?.signal?.aborted) throw error;\n key.refuse();\n try {\n return await run(input, options);\n } catch (again) {\n if (/** @type {any} */ (again)?.code === 'KEY_REFUSED') key.refuse();\n throw again;\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAM,iBAAiB;AACvB,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,iBAAiB;AAGvB,SAAS,iBAAiB;AACxB,MAAI;AACF,UAAM,UAAU,WAAW;AAC3B,WAAO,WAAW,OAAO,QAAQ,YAAY,aAAa,UAAU;AAAA,EACtE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAkCA,IAAM,WAAW,CAAC,aAChB,OAAO,OAAO;AAAA,EACZ,IAAI,SAAS;AAAA,EACb,MAAM,SAAS;AAAA,EACf,OAAO,SAAS,SAAS;AAAA,EACzB,QAAQ,SAAS;AAAA,EACjB,SAAS,S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AAO;AAC5B,WAAO,UAAU,IAAI,KAAK;AAAA,EAC5B;AAEA,SAAO,OAAO,OAAO;AAAA,IACnB;AAAA;AAAA,MAA4C,QAAQ,WAAW;AAAA;AAAA,IAC/D;AAAA;AAAA,MAAwC,QAAQ,SAAS;AAAA;AAAA,IACzD;AAAA;AAAA,MAAwD,QAAQ,iBAAiB;AAAA;AAAA,IACjF;AAAA,IACA,UAAU;AAAA,IACV,YAAY,OAAO,OAAO,EAAE,WAAW,iBAAiB,SAAS,aAAa,UAAU,cAAc,SAAS,MAAM,YAAY,KAAK,CAAC;AAAA,EACzI,CAAC;AACH;AAQA,SAAS,WAAW,QAAQ;AAC1B,MAAI,UAAU,OAAO,WAAW,YAAY,OAAO,OAAO,gBAAgB,YAAY;AACpF,QAAI,CAAC,OAAO,MAAM,CAAC,OAAO,KAAM,OAAM,IAAI,UAAU,oEAAoE;AACxH;AAAA;AAAA,MAA2D;AAAA;AAAA,EAC7D;AACA,SAAO;AAAA;AAAA,IAAoC;AAAA,EAAO;AACpD;AAQA,SAAS,WAAW,KAAK,KAAK;AAC5B,SAAO,OAA0B,OAA0B,YAAY;AACrE,QAAI;AACF,aAAO,MAAM,IAAI,OAAO,OAAO;AAAA,IACjC,SAAS,OAAO;AACd;AAAA;AAAA,QAAwB,OAAQ,SAAS,iBAAiB,SAAS,QAAQ;AAAA,OAAS,OAAM;AAC1F,UAAI,OAAO;AACX,UAAI;AACF,eAAO,MAAM,IAAI,OAAO,OAAO;AAAA,MACjC,SAAS,OAAO;AACd;AAAA;AAAA,UAAwB,OAAQ,SAAS;AAAA,SAAe,KAAI,OAAO;AACnE,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":["provider","useEffect","useId","useRef","useState","models","jsx","jsxs","useState","useRef","useId","useEffect","useEffect","useRef","useState","Check","TriangleAlert","Fragment","jsx","jsxs","useState","useRef","useEffect","TriangleAlert","Check","useEffect","useRef","useState","ChevronDown","Loader2","TriangleAlert","jsx","jsxs","useState","useRef","useEffect","currentText","Loader2","ChevronDown","TriangleAlert","useEffect","useRef","useState","Check","Loader2","Sparkles","TriangleAlert","jsx","jsxs","useState","useRef","useEffect","Loader2","Sparkles","Check","TriangleAlert","provider","model"]}
|
|
1
|
+
{"version":3,"sources":["../src/ai/keys.js","../src/ai/ConnectAi.jsx","../src/ai/ModelPicker.jsx","../src/ai/ProofreadButton.jsx","../src/ai/RewriteText.jsx","../src/ai/chip.js","../src/ai/SubjectIdeas.jsx","../src/ai/createAi.js"],"sourcesContent":["// @ts-check\n/**\n * THE USER'S KEY — when the AI runs in the page with `askKey: true`, each\n * user connects their own provider key, once.\n *\n * The first AI action asks for it (the Connect dialog, `ConnectAi.jsx`); it is\n * kept in this browser (localStorage, one entry per provider) and sent only to\n * the provider. A key the provider refuses is forgotten, and asked again.\n * Given several providers, the user chooses one in the same dialog; the\n * choice is kept too, and so is the model chosen for each provider.\n *\n * ai.key.get(id?) the key in use, or the one kept for that provider ('' when none)\n * ai.key.set(key) connect a key without the dialog\n * ai.key.forget() disconnect: the next AI action asks again\n * ai.key.request() ask the user now → the key, or '' when they cancel\n * ai.key.choose(id) use another of the providers (its kept key, if any)\n * ai.key.model(id?) the model chosen for that provider (its own by default)\n * ai.key.chooseModel(model, id?) write with another of its models\n * ai.key.listModels(id?, { apiKey, address, signal }) the models it offers (providers.js)\n * ai.key.address(id?) where an OpenAI-compatible API of the user's own answers\n * ai.key.setAddress(url, id?) keep it (for a provider without an address of its own)\n * ai.key.ready() whether the provider in use can write: its key (unless it\n * needs none), its address, its model\n * ai.key.subscribe(fn) called on every change; returns the unsubscribe\n * ai.key.provider the provider in use: name, model, where to get a key, what is free\n * ai.key.providers all those the user can choose from\n */\n\nimport { listProviderModels } from './providers.js';\n\n/** @typedef {import('./providers.js').AiProvider} AiProvider */\n/** @typedef {import('./providers.js').ModelChoice} ModelChoice */\n\nconst STORAGE_PREFIX = 'best-email-builder:ai-key:';\nconst CHOICE_SLOT = 'best-email-builder:ai-provider';\nconst MODEL_PREFIX = 'best-email-builder:ai-model:';\nconst ADDRESS_PREFIX = 'best-email-builder:ai-address:';\n\n/** localStorage when there is one that works (not in private modes that throw, not on the server). */\nfunction browserStorage() {\n try {\n const storage = globalThis.localStorage;\n return storage && typeof storage.getItem === 'function' ? storage : null;\n } catch {\n return null;\n }\n}\n\n/**\n * @typedef {Readonly<{id: string, name: string, model: string|null, keyUrl: string|null, keyHint: string, free: string|null, publicModels: boolean, keyless: boolean, needsAddress: boolean}>} ProviderChoice\n * `keyless`: a key is optional (a server of the user's own may need none);\n * `needsAddress`: the user gives the address of the API (an\n * OpenAI-compatible one: LM Studio, vLLM, a proxy…).\n * @typedef {{\n * provider: ProviderChoice,\n * providers: ReadonlyArray<ProviderChoice>,\n * get: (id?: string) => string,\n * set: (key: string) => void,\n * forget: () => void,\n * request: () => Promise<string>,\n * choose: (id: string) => void,\n * model: (id?: string) => string,\n * chooseModel: (model: string, id?: string) => void,\n * listModels: (id?: string, options?: {apiKey?: string, address?: string, signal?: AbortSignal}) => Promise<ModelChoice[]>,\n * address: (id?: string) => string,\n * setAddress: (url: string, id?: string) => void,\n * ready: () => boolean,\n * subscribe: (listener: () => void) => () => void,\n * state: () => Readonly<{asking: boolean, refused: boolean, connected: boolean}>,\n * answer: (key: string|null) => void,\n * refuse: () => void,\n * }} AiKey\n * `state`, `answer` and `refuse` serve the Connect dialog and the module:\n * whether the user is being asked, whether the last key was refused;\n * `answer('')` connects without a key (a keyless provider), `answer(null)`\n * cancels. `listModels`: with the key and address given, else those kept\n * (no key is needed for a provider whose list is public, OpenRouter's).\n */\n\n/** @param {AiProvider} provider @returns {ProviderChoice} */\nconst choiceOf = (provider) =>\n Object.freeze({\n id: provider.id,\n name: provider.name,\n model: provider.model ?? null,\n keyUrl: provider.keyUrl,\n keyHint: provider.keyHint,\n free: provider.free,\n publicModels: Boolean(provider.publicModels),\n keyless: Boolean(provider.keyless),\n needsAddress: !provider.createModel && !provider.baseUrl,\n });\n\n/** An address of the user's own, as the API takes it: http(s), no trailing slash. @param {string} url */\nconst cleanAddress = (url) => String(url || '').trim().replace(/\\/+$/, '');\n\n/**\n * @param {AiProvider | AiProvider[]} providerOrList one provider, or those the user chooses from\n * @param {{fetch?: typeof fetch}} [options] the fetch that lists the models\n * @returns {AiKey}\n */\nexport function createKeyStore(providerOrList, { fetch: fetchImpl } = {}) {\n const originals = Array.isArray(providerOrList) ? providerOrList : [providerOrList];\n const providers = Object.freeze(originals.map(choiceOf));\n if (!providers.length) throw new TypeError('createKeyStore: at least one provider');\n const known = (/** @type {unknown} */ id) => providers.some((provider) => provider.id === id);\n /** Kept here too: a browser that does not store still works for the page's life. */\n const memory = new Map();\n let refused = false;\n /** @type {{promise: Promise<string>, resolve: (key: string) => void}|null} */\n let pending = null;\n /** @type {Set<() => void>} */\n const listeners = new Set();\n /** @type {ReturnType<AiKey['state']>} */\n let snapshot;\n\n /** @param {string} slot */\n const read = (slot) => {\n try {\n return browserStorage()?.getItem(slot) || '';\n } catch {\n return '';\n }\n };\n /** @param {string} slot @param {string} value */\n const write = (slot, value) => {\n try {\n const storage = browserStorage();\n if (value) storage?.setItem(slot, value);\n else storage?.removeItem(slot);\n } catch {\n // Full, or blocked: the key stays in memory.\n }\n };\n /** @param {string} id */\n const keyOf = (id) => (memory.has(id) ? memory.get(id) : read(STORAGE_PREFIX + id));\n /** @param {string} id @param {string} value */\n const keep = (id, value) => {\n memory.set(id, value);\n write(STORAGE_PREFIX + id, value);\n };\n // The provider chosen last time; else the first one with a key; else the first.\n const kept = read(CHOICE_SLOT);\n let current = known(kept) ? kept : (providers.find((provider) => keyOf(provider.id)) || providers[0]).id;\n /** @param {string} [id] */\n const get = (id) => keyOf(id === undefined ? current : String(id));\n /** @param {string} [id] */\n const providerId = (id) => {\n if (id === undefined) return current;\n if (!known(id)) throw new TypeError(`ai.key: no provider \"${id}\" — one of ${providers.map((provider) => provider.id).join(', ')}`);\n return id;\n };\n /** The models listed, by provider and key: a dialog opened again shows them at once. */\n const lists = new Map();\n /** @param {ProviderChoice} choice */\n const modelOf = (choice) => (memory.get(MODEL_PREFIX + choice.id) ?? read(MODEL_PREFIX + choice.id)) || choice.model || '';\n /** @param {ProviderChoice} choice */\n const addressOf = (choice) =>\n choice.needsAddress ? cleanAddress(memory.get(ADDRESS_PREFIX + choice.id) ?? read(ADDRESS_PREFIX + choice.id)) : '';\n /** The provider in use can write: its key (unless it needs none), its address, its model. */\n const ready = () => {\n const choice = /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === current));\n if (refused) return false;\n if (!choice.keyless && !get()) return false;\n if (choice.needsAddress && !addressOf(choice)) return false;\n return Boolean(modelOf(choice));\n };\n const changed = () => {\n snapshot = Object.freeze({ asking: Boolean(pending), refused, connected: ready() });\n for (const listener of [...listeners]) listener();\n };\n snapshot = Object.freeze({ asking: false, refused: false, connected: ready() });\n\n /** @param {string|null} key null: cancelled */\n const answer = (key) => {\n const value = String(key || '').trim();\n if (value) keep(current, value);\n // Connected, with a key or (keyless) without: the last refusal is over.\n if (key !== null && (value || get() || /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === current)).keyless)) refused = false;\n const waiting = pending;\n pending = null;\n changed();\n waiting?.resolve(value);\n };\n\n return Object.freeze({\n get provider() {\n return /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === current));\n },\n providers,\n get,\n set: (/** @type {string} */ key) => {\n if (typeof key !== 'string' || !key.trim()) throw new TypeError('ai.key.set: a non-empty key');\n answer(key);\n },\n forget: () => {\n keep(current, '');\n changed();\n },\n choose: (/** @type {string} */ id) => {\n if (!known(id)) throw new TypeError(`ai.key.choose: one of ${providers.map((provider) => provider.id).join(', ')}`);\n if (id === current) return;\n current = id;\n refused = false;\n write(CHOICE_SLOT, id);\n changed();\n },\n model: (/** @type {string|undefined} */ id) => modelOf(/** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)))),\n address: (/** @type {string|undefined} */ id) => addressOf(/** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)))),\n setAddress: (/** @type {string} */ url, /** @type {string|undefined} */ id) => {\n const choice = /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)));\n if (!choice.needsAddress) throw new TypeError(`ai.key.setAddress: ${choice.name} has an address of its own`);\n const value = cleanAddress(url);\n if (value && !/^https?:\\/\\/[^\\s/]+/i.test(value)) throw new TypeError('ai.key.setAddress: an http(s) address, e.g. http://localhost:1234/v1');\n memory.set(ADDRESS_PREFIX + choice.id, value);\n write(ADDRESS_PREFIX + choice.id, value);\n changed();\n },\n ready,\n chooseModel: (/** @type {string} */ model, /** @type {string|undefined} */ id) => {\n if (typeof model !== 'string' || !model.trim()) throw new TypeError('ai.key.chooseModel: a model id');\n const choice = /** @type {ProviderChoice} */ (providers.find((provider) => provider.id === providerId(id)));\n // The provider's own model is kept as no choice: a new default reaches the user.\n const value = model.trim() === choice.model ? '' : model.trim();\n memory.set(MODEL_PREFIX + choice.id, value);\n write(MODEL_PREFIX + choice.id, value);\n changed();\n },\n listModels: async (/** @type {string|undefined} */ id, { apiKey, address, signal } = {}) => {\n const at = providers.findIndex((provider) => provider.id === providerId(id));\n const key = String(apiKey ?? keyOf(providers[at].id)).trim();\n const where = providers[at].needsAddress ? cleanAddress(address ?? addressOf(providers[at])) : '';\n if (providers[at].needsAddress && !where) return [];\n const slot = `${providers[at].id}\\n${key}\\n${where}`;\n const provider = where ? { ...originals[at], baseUrl: where } : originals[at];\n if (!lists.has(slot)) lists.set(slot, await listProviderModels({ provider, apiKey: key, fetch: fetchImpl, signal }));\n return lists.get(slot);\n },\n request: () => {\n if (!pending) {\n /** @type {(key: string) => void} */\n let resolve = () => {};\n const promise = new Promise((done) => (resolve = done));\n pending = { promise, resolve };\n changed();\n }\n return pending.promise;\n },\n subscribe: (/** @type {() => void} */ listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n state: () => snapshot,\n answer: (/** @type {string|null} */ key) => answer(key ?? null),\n refuse: () => {\n keep(current, '');\n refused = true;\n changed();\n },\n });\n}\n","import { useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';\nimport { ArrowUpRight, Eye, EyeOff, KeyRound, ShieldCheck, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { cn } from '../ui/primitives/cn.js';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { Input, Label } from '../ui/primitives/fields.jsx';\nimport { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '../ui/primitives/overlays.jsx';\nimport ModelPicker from './ModelPicker.jsx';\n\n/** A key this long is complete enough to ask the provider for its models. */\nconst LISTABLE_KEY = 20;\n/** An address the API can be asked at (keys.js keeps it without the trailing slash). */\nconst ADDRESS = /^https?:\\/\\/[^\\s/]+/i;\n\n/**\n * CONNECT — the dialog that asks the user for their provider key, when the AI\n * runs in the page with `createAi({ provider, askKey: true })`.\n *\n * It opens by itself when an AI action needs a key and there is none, or the\n * provider refused the last one; the action goes on once the key is given.\n * Cancel ends the action (\"Connect an AI provider first\"). The key is kept in\n * this browser and sent only to the provider (see keys.js).\n *\n * Given several providers (`createAi({ provider: [...] })`), the user chooses\n * one at the top; a provider whose key this browser already keeps needs no\n * new one. Under the key, the model: the provider's own, or another of its\n * list (ModelPicker.jsx). An OpenAI-compatible API of the user's own\n * ('openai-compatible': LM Studio, vLLM, a proxy…) takes its address first,\n * and a key only if it needs one.\n */\nexport default function ConnectAi({ aiKey }) {\n const { t } = useUi();\n const state = useSyncExternalStore(aiKey.subscribe, aiKey.state, aiKey.state);\n const [value, setValue] = useState('');\n const [address, setAddress] = useState('');\n const [shown, setShown] = useState(false);\n const [chosenId, setChosenId] = useState(aiKey.provider.id);\n /** The models chosen in the dialog, by provider, until Connect. */\n const [picks, setPicks] = useState(/** @type {Record<string, string>} */ ({}));\n const [modelsOpen, setModelsOpen] = useState(false);\n const inputRef = useRef(/** @type {HTMLInputElement|null} */ (null));\n const addressRef = useRef(/** @type {HTMLInputElement|null} */ (null));\n const choicesRef = useRef(/** @type {HTMLDivElement|null} */ (null));\n const inputId = useId();\n const hintId = useId();\n const addressId = useId();\n const addressHintId = useId();\n const choices = aiKey.providers;\n const chosen = choices.find((provider) => provider.id === chosenId) || aiKey.provider;\n const { name, keyUrl, keyHint, free, keyless, needsAddress } = chosen;\n\n // Each time it opens: the provider in use, an empty field, the key hidden.\n useEffect(() => {\n if (!state.asking) return;\n setChosenId(aiKey.provider.id);\n setAddress(aiKey.address());\n setValue('');\n setShown(false);\n setPicks({});\n setModelsOpen(false);\n }, [state.asking, aiKey]);\n\n const key = value.trim();\n // The key this browser keeps for the provider chosen (none for one refused).\n const saved = aiKey.get(chosen.id);\n // A key from elsewhere (another provider's) is the usual mistake: said, not blocked.\n const unusual = Boolean(key && keyHint && !key.startsWith(keyHint));\n const refused = state.refused && chosen.id === aiKey.provider.id;\n /** @param {string} id */\n const modelFor = (id) => picks[id] ?? aiKey.model(id);\n const where = address.trim().replace(/\\/+$/, '');\n const addressOk = !needsAddress || ADDRESS.test(where);\n // Connect: a key (unless it needs none), the address, a model to write with.\n const ready = Boolean((key || saved || keyless) && (!needsAddress || (where && addressOk)) && modelFor(chosen.id));\n\n const submit = (/** @type {React.FormEvent} */ event) => {\n event.preventDefault();\n if (!ready) return;\n if (needsAddress && where !== aiKey.address(chosen.id)) aiKey.setAddress(where, chosen.id);\n if (chosen.id !== aiKey.provider.id) aiKey.choose(chosen.id);\n if (picks[chosen.id] && picks[chosen.id] !== aiKey.model(chosen.id)) aiKey.chooseModel(picks[chosen.id], chosen.id);\n aiKey.answer(key || saved);\n };\n\n /** @param {string} id */\n const choose = (id) => {\n setChosenId(id);\n setAddress(aiKey.address(id));\n setValue('');\n setModelsOpen(false);\n };\n\n /** Arrows move through the providers and choose, as in any radio group. */\n const onChoicesKeyDown = (/** @type {React.KeyboardEvent} */ event) => {\n const at = choices.findIndex((provider) => provider.id === chosen.id);\n const step = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[event.key];\n const to = step ? (at + step + choices.length) % choices.length : event.key === 'Home' ? 0 : event.key === 'End' ? choices.length - 1 : -1;\n if (to === -1) return;\n event.preventDefault();\n choose(choices[to].id);\n /** @type {HTMLElement|undefined} */ (choicesRef.current?.querySelectorAll('[role=\"radio\"]')[to])?.focus();\n };\n\n return (\n <Dialog open={state.asking} onOpenChange={(open) => !open && aiKey.answer(null)}>\n <DialogContent\n className={cn('eb:max-h-[calc(100dvh-2rem)] eb:gap-0 eb:overflow-y-auto eb:p-0', choices.length > 1 ? 'eb:sm:max-w-xl' : 'eb:sm:max-w-md')}\n data-testid=\"eb-ai-connect\"\n onOpenAutoFocus={(event) => {\n event.preventDefault();\n (needsAddress && !where ? addressRef : inputRef).current?.focus();\n }}\n // Esc closes the list of models first, then the dialog. From inside\n // the list, the list closes itself (and gives the focus back to its field).\n onEscapeKeyDown={(event) => {\n if (!modelsOpen) return;\n event.preventDefault();\n if (!(event.target instanceof Element && event.target.closest('[data-eb-models]'))) setModelsOpen(false);\n }}\n >\n {/* min-w-0: the long names of the list of models do not widen the dialog. */}\n <form onSubmit={submit} className=\"eb:min-w-0\">\n <div className=\"eb:flex eb:flex-col eb:gap-5 eb:px-6 eb:pt-6 eb:pb-5\">\n <DialogHeader className=\"eb:flex-row eb:items-start eb:gap-3.5 eb:pr-6\">\n <span className=\"eb:flex eb:size-10 eb:shrink-0 eb:items-center eb:justify-center eb:rounded-full eb:bg-primary/10 eb:text-primary\">\n <KeyRound className=\"eb:size-5\" aria-hidden=\"true\" />\n </span>\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\">\n <DialogTitle>{t('Connect {provider}', { provider: name })}</DialogTitle>\n <DialogDescription className=\"eb:text-[13px] eb:leading-relaxed eb:text-foreground-lighter\">\n {needsAddress\n ? t('The AI writes with an OpenAI-compatible API of your choice. Give its address, and its key if it needs one: this browser remembers them.')\n : t('The AI writes with your own {provider} key. Connect it once: this browser remembers it.', { provider: name })}\n </DialogDescription>\n </div>\n </DialogHeader>\n\n {choices.length > 1 && (\n <div\n ref={choicesRef}\n role=\"radiogroup\"\n aria-label={t('AI provider')}\n className=\"eb:grid eb:grid-cols-2 eb:gap-1.5 eb:sm:grid-cols-3\"\n onKeyDown={onChoicesKeyDown}\n data-testid=\"eb-ai-connect-providers\"\n >\n {choices.map((provider) => {\n const checked = provider.id === chosen.id;\n return (\n <button\n key={provider.id}\n type=\"button\"\n role=\"radio\"\n aria-checked={checked}\n tabIndex={checked ? 0 : -1}\n onClick={() => choose(provider.id)}\n className={cn(\n 'eb:flex eb:min-w-0 eb:flex-col eb:gap-0.5 eb:rounded-lg2 eb:border eb:px-2.5 eb:py-2 eb:text-left eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n checked ? 'eb:border-primary eb:bg-primary/10' : 'eb:border-border eb:hover:bg-muted'\n )}\n >\n <span className=\"eb:flex eb:items-center eb:gap-1.5 eb:text-[13px] eb:leading-tight eb:font-medium eb:text-foreground\">\n <span className=\"eb:truncate\">{provider.name}</span>\n {aiKey.get(provider.id) && (\n <span className=\"eb:ml-auto eb:size-1.5 eb:shrink-0 eb:rounded-full eb:bg-success\" title={t('Key saved')} aria-label={t('Key saved')} />\n )}\n </span>\n {modelFor(provider.id) && (\n <span className=\"eb:truncate eb:font-mono eb:text-[10.5px] eb:text-foreground-muted\" title={modelFor(provider.id)}>\n {modelFor(provider.id)}\n </span>\n )}\n </button>\n );\n })}\n </div>\n )}\n\n {refused && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-2 eb:rounded-lg2 eb:border eb:border-destructive/30 eb:bg-destructive/10 eb:px-3 eb:py-2 eb:text-[12.5px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-px eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {t('{provider} refused the last key. Paste another one.', { provider: name })}\n </p>\n )}\n\n {(keyUrl || free) && (\n <div className=\"eb:flex eb:flex-wrap eb:items-center eb:gap-x-3 eb:gap-y-2\">\n {keyUrl && (\n <Button asChild variant=\"outline\" size=\"sm-compact\">\n <a\n href={keyUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n // A new tab, always — even where a link's target is ignored (webviews).\n onClick={(event) => {\n event.preventDefault();\n window.open(keyUrl, '_blank', 'noopener,noreferrer');\n }}\n data-testid=\"eb-ai-connect-get-key\"\n >\n {t('Get a key')}\n <ArrowUpRight aria-hidden=\"true\" />\n </a>\n </Button>\n )}\n {free && (\n <span className=\"eb:rounded-md eb:bg-success/10 eb:px-2.5 eb:py-1 eb:text-[11.5px] eb:font-medium eb:text-success\">\n {t(free)}\n </span>\n )}\n </div>\n )}\n\n {needsAddress && (\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\">\n <Label htmlFor={addressId}>{t('API address')}</Label>\n <Input\n ref={addressRef}\n id={addressId}\n type=\"url\"\n inputMode=\"url\"\n value={address}\n onChange={(event) => setAddress(event.target.value)}\n placeholder=\"http://localhost:1234/v1\"\n autoComplete=\"url\"\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n spellCheck={false}\n aria-invalid={where && !addressOk ? true : undefined}\n aria-describedby={addressHintId}\n className=\"eb:h-9 eb:font-mono eb:text-[12.5px]\"\n data-testid=\"eb-ai-connect-address\"\n />\n <p id={addressHintId} className=\"eb:text-[11.5px] eb:leading-relaxed eb:text-foreground-muted\">\n {where && !addressOk ? (\n <span className=\"eb:text-warning\">{t('An address starts with http:// or https://.')}</span>\n ) : (\n t('Any API that speaks OpenAI: LM Studio, vLLM, Ollama, a proxy of your own… It must accept requests from this page (CORS).')\n )}\n </p>\n </div>\n )}\n\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\">\n <Label htmlFor={inputId}>{keyless ? t('API key (optional)') : t('API key')}</Label>\n <div className=\"eb:relative\">\n <Input\n ref={inputRef}\n id={inputId}\n type={shown ? 'text' : 'password'}\n value={value}\n onChange={(event) => setValue(event.target.value)}\n placeholder={keyHint ? `${keyHint}…` : t('Paste the key')}\n autoComplete=\"off\"\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n spellCheck={false}\n aria-describedby={hintId}\n className=\"eb:h-9 eb:pr-10 eb:font-mono eb:text-[12.5px]\"\n data-testid=\"eb-ai-connect-key\"\n />\n <button\n type=\"button\"\n className=\"eb:absolute eb:top-1/2 eb:right-1 eb:flex eb:size-7 eb:-translate-y-1/2 eb:items-center eb:justify-center eb:rounded-md eb:text-foreground-muted eb:transition-colors eb:outline-none eb:hover:bg-muted eb:hover:text-foreground eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50\"\n onClick={() => setShown((current) => !current)}\n aria-label={shown ? t('Hide the key') : t('Show the key')}\n aria-pressed={shown}\n >\n {shown ? <EyeOff className=\"eb:size-4\" aria-hidden=\"true\" /> : <Eye className=\"eb:size-4\" aria-hidden=\"true\" />}\n </button>\n </div>\n <p id={hintId} className=\"eb:min-h-4 eb:text-[11.5px] eb:text-foreground-muted\">\n {unusual ? (\n <span className=\"eb:text-warning\">{t('{provider} keys usually start with {prefix}.', { provider: name, prefix: keyHint })}</span>\n ) : saved && !key ? (\n t('A key for {provider} is saved in this browser: Connect uses it, or paste another one.', { provider: name })\n ) : keyHint ? (\n t('{provider} keys start with {prefix}.', { provider: name, prefix: keyHint })\n ) : keyless ? (\n t('Leave it empty if the API needs no key.')\n ) : null}\n </p>\n </div>\n\n <ModelPicker\n aiKey={aiKey}\n provider={chosen}\n apiKey={key.length >= LISTABLE_KEY || (keyless && key) ? key : saved}\n address={addressOk ? where : ''}\n delay={key.length >= LISTABLE_KEY || (keyless && key) || where !== aiKey.address(chosen.id) ? 350 : 0}\n value={modelFor(chosen.id)}\n onChange={(model) => setPicks((current) => ({ ...current, [chosen.id]: model }))}\n open={modelsOpen}\n onOpenChange={setModelsOpen}\n />\n </div>\n\n <div className=\"eb:flex eb:items-start eb:gap-2 eb:border-t eb:border-border eb:bg-surface-75 eb:px-6 eb:py-3 eb:text-[11.5px] eb:leading-relaxed eb:text-foreground-lighter\">\n <ShieldCheck className=\"eb:mt-0.5 eb:size-3.5 eb:shrink-0 eb:text-foreground-muted\" aria-hidden=\"true\" />\n <span>\n {needsAddress\n ? t('The address and the key stay in this browser; the key is sent only to that address.')\n : t('The key stays in this browser and is sent only to {provider}.', { provider: name })}\n </span>\n </div>\n\n <DialogFooter className=\"eb:border-t eb:border-border eb:px-6 eb:py-4\">\n <Button type=\"button\" variant=\"ghost\" onClick={() => aiKey.answer(null)}>\n {t('Cancel')}\n </Button>\n <Button type=\"submit\" disabled={!ready} data-testid=\"eb-ai-connect-submit\">\n {t('Connect')}\n </Button>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n );\n}\n","import { useEffect, useId, useMemo, useRef, useState } from 'react';\nimport { Check, ChevronDown, LoaderCircle, Search } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { cn } from '../ui/primitives/cn.js';\n\n/**\n * MODEL — the model of the provider chosen, in the Connect dialog: a field\n * that opens the provider's list of models in place (not over the dialog, so\n * the list scrolls like the rest of it).\n *\n * The list comes from the provider with the key (OpenRouter's needs none;\n * an OpenAI-compatible API of the user's own, from the address given):\n * the default model first, then the free ones, then the newest. Type to\n * filter, ↑/↓ to move, Enter to choose, Esc to close. An id the list does not\n * have can be used as it is (\"Use “…”\"); without the list, the default model\n * still works.\n *\n * @param {{\n * aiKey: import('./keys.js').AiKey,\n * provider: import('./keys.js').ProviderChoice,\n * apiKey: string,\n * address?: string,\n * delay?: number,\n * value: string,\n * onChange: (model: string) => void,\n * open: boolean,\n * onOpenChange: (open: boolean) => void,\n * }} props\n * `apiKey`: the key the list is asked with ('' when there is none yet);\n * `address`: where the API answers, for a provider that needs one;\n * `delay`: how long to wait after they change (a key being pasted).\n */\nexport default function ModelPicker({ aiKey, provider, apiKey, address = '', delay = 0, value, onChange, open, onOpenChange }) {\n const { t } = useUi();\n const [list, setList] = useState(/** @type {{status: 'loading'|'ready'|'needs-key'|'needs-address'|'refused'|'failed', models: import('./providers.js').ModelChoice[]}} */ ({ status: 'loading', models: [] }));\n const [query, setQuery] = useState('');\n const [freeOnly, setFreeOnly] = useState(false);\n const [active, setActive] = useState(0);\n const triggerRef = useRef(/** @type {HTMLButtonElement|null} */ (null));\n const listRef = useRef(/** @type {HTMLDivElement|null} */ (null));\n const labelId = useId();\n const valueId = useId();\n const listId = useId();\n const hintId = useId();\n\n // The list of the provider, asked again when the key (or the address) changes.\n useEffect(() => {\n if (provider.needsAddress && !address) {\n setList({ status: 'needs-address', models: [] });\n return undefined;\n }\n if (!apiKey && !provider.publicModels && !provider.keyless) {\n setList({ status: 'needs-key', models: [] });\n return undefined;\n }\n const controller = new AbortController();\n setList({ status: 'loading', models: [] });\n const timer = setTimeout(() => {\n aiKey.listModels(provider.id, { apiKey, address, signal: controller.signal }).then(\n (models) => !controller.signal.aborted && setList({ status: 'ready', models }),\n (error) => !controller.signal.aborted && setList({ status: error?.code === 'KEY_REFUSED' ? 'refused' : 'failed', models: [] })\n );\n }, delay);\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [aiKey, provider.id, provider.publicModels, provider.keyless, provider.needsAddress, apiKey, address, delay]);\n\n // Each time it opens: no search, the model in use under the keys.\n useEffect(() => {\n if (!open) return;\n setQuery('');\n setFreeOnly(false);\n }, [open]);\n\n // The default model first, then the one in use, then the list.\n const models = useMemo(() => {\n const listed = new Map(list.models.map((model) => [model.id, model]));\n const seen = new Set();\n /** @type {import('./providers.js').ModelChoice[]} */\n const all = [];\n const add = (/** @type {import('./providers.js').ModelChoice} */ model) => {\n if (model.id && !seen.has(model.id)) seen.add(model.id) && all.push(model);\n };\n for (const id of [provider.model, value]) if (id) add(listed.get(id) || { id, name: id, free: false });\n list.models.forEach(add);\n return all;\n }, [list.models, provider.model, value]);\n const hasFree = list.models.some((model) => model.free);\n const typed = query.trim();\n const matches = useMemo(() => {\n const words = typed.toLowerCase().split(/\\s+/).filter(Boolean);\n return models.filter((model) => (!freeOnly || model.free) && words.every((word) => `${model.id} ${model.name}`.toLowerCase().includes(word)));\n }, [models, typed, freeOnly]);\n // An id of one's own: a model the list does not have (or not yet).\n const custom = typed && !/\\s/.test(typed) && !models.some((model) => model.id === typed) ? typed : '';\n const count = matches.length + (custom ? 1 : 0);\n const current = models.find((model) => model.id === value);\n\n useEffect(() => setActive(Math.max(0, matches.findIndex((model) => model.id === value))), [matches, value]);\n useEffect(() => {\n if (open) listRef.current?.querySelector('[data-active=\"true\"]')?.scrollIntoView({ block: 'nearest' });\n }, [active, open]);\n\n const close = () => {\n triggerRef.current?.focus();\n onOpenChange(false);\n };\n /** @param {string} id */\n const pick = (id) => {\n onChange(id);\n close();\n };\n\n const onKeyDown = (/** @type {React.KeyboardEvent} */ event) => {\n if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n event.preventDefault();\n setActive((at) => (count ? (at + (event.key === 'ArrowDown' ? 1 : -1) + count) % count : 0));\n } else if (event.key === 'Enter') {\n // The model, not the form: Connect is the button's.\n event.preventDefault();\n const id = active < matches.length ? matches[active]?.id : custom;\n if (id) pick(id);\n }\n };\n\n const optionId = (/** @type {number} */ at) => `${listId}-${at}`;\n const badges = (/** @type {import('./providers.js').ModelChoice} */ model) => (\n <>\n {model.free && (\n <span className=\"eb:shrink-0 eb:rounded-md eb:bg-success/10 eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-success\">\n {t('Free')}\n </span>\n )}\n {model.id === provider.model && (\n <span className=\"eb:shrink-0 eb:rounded-md eb:bg-muted eb:px-1.5 eb:py-px eb:text-[10.5px] eb:font-medium eb:text-foreground-lighter\">{t('Default')}</span>\n )}\n </>\n );\n\n const status = {\n loading: (\n <>\n <LoaderCircle className=\"eb:size-3 eb:shrink-0 eb:animate-spin\" aria-hidden=\"true\" />\n {t('Loading the models of {provider}…', { provider: provider.name })}\n </>\n ),\n 'needs-key': t('Paste the key to see all the models of {provider}.', { provider: provider.name }),\n 'needs-address': t('Give the API address to see its models.'),\n refused: <span className=\"eb:text-warning\">{t('{provider} refused this key: its models could not be listed.', { provider: provider.name })}</span>,\n failed: provider.model\n ? t('The list of models could not be loaded. The default model works, or type the id of another.')\n : t('The list of models could not be loaded. Type the id of the model.'),\n ready: list.models.length\n ? hasFree\n ? t('{count} models, the free ones first.', { count: list.models.length })\n : t('{count} models.', { count: list.models.length })\n : t('{provider} lists no models here: type the id of the one you want.', { provider: provider.name }),\n }[list.status];\n\n return (\n <div className=\"eb:flex eb:flex-col eb:gap-1.5\" data-testid=\"eb-ai-connect-model-field\">\n <span id={labelId} className=\"eb:text-[12.5px] eb:leading-none eb:font-medium eb:text-foreground\">\n {t('Model')}\n </span>\n <button\n ref={triggerRef}\n type=\"button\"\n aria-haspopup=\"listbox\"\n aria-expanded={open}\n aria-labelledby={`${labelId} ${valueId}`}\n aria-describedby={hintId}\n onClick={() => onOpenChange(!open)}\n className={cn(\n 'eb:flex eb:h-9 eb:w-full eb:min-w-0 eb:items-center eb:gap-2 eb:rounded-lg2 eb:border eb:border-input eb:bg-transparent eb:px-3 eb:text-left eb:shadow-xs eb:transition-[color,box-shadow] eb:outline-none eb:focus-visible:border-ring eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n open && 'eb:border-ring'\n )}\n data-testid=\"eb-ai-connect-model\"\n >\n <span id={valueId} className=\"eb:min-w-0 eb:truncate eb:font-mono eb:text-[12.5px] eb:text-foreground\">{value || t('Choose a model')}</span>\n {current && badges(current)}\n <ChevronDown className={cn('eb:ml-auto eb:size-4 eb:shrink-0 eb:text-foreground-muted eb:transition-transform', open && 'eb:rotate-180')} aria-hidden=\"true\" />\n </button>\n\n {open && (\n <div\n className=\"eb:flex eb:flex-col eb:overflow-hidden eb:rounded-lg2 eb:border eb:border-border eb:bg-background\"\n onKeyDown={(event) => event.key === 'Escape' && close()}\n data-eb-models=\"\"\n data-testid=\"eb-ai-connect-models\"\n >\n <div className=\"eb:flex eb:items-center eb:gap-2 eb:border-b eb:border-border eb:p-2\">\n <div className=\"eb:relative eb:min-w-0 eb:flex-1\">\n <Search className=\"eb:pointer-events-none eb:absolute eb:top-1/2 eb:left-2 eb:size-3.5 eb:-translate-y-1/2 eb:text-foreground-muted\" aria-hidden=\"true\" />\n <input\n autoFocus\n role=\"combobox\"\n aria-expanded=\"true\"\n aria-controls={listId}\n aria-autocomplete=\"list\"\n aria-activedescendant={count ? optionId(active) : undefined}\n aria-label={t('Search the models')}\n value={query}\n onChange={(event) => setQuery(event.target.value)}\n onKeyDown={onKeyDown}\n placeholder={t('Search the models…')}\n autoComplete=\"off\"\n autoCapitalize=\"off\"\n autoCorrect=\"off\"\n spellCheck={false}\n className=\"eb:h-8 eb:w-full eb:rounded-lg2 eb:bg-surface-75 eb:pr-2 eb:pl-7 eb:text-[13px] eb:text-foreground eb:outline-none eb:placeholder:text-foreground-muted eb:focus-visible:ring-2 eb:focus-visible:ring-ring/40\"\n data-testid=\"eb-ai-connect-model-search\"\n />\n </div>\n {hasFree && (\n <button\n type=\"button\"\n aria-pressed={freeOnly}\n onClick={() => setFreeOnly((on) => !on)}\n className={cn(\n 'eb:inline-flex eb:h-8 eb:shrink-0 eb:items-center eb:rounded-lg2 eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n freeOnly ? 'eb:border-success/40 eb:bg-success/10 eb:text-success' : 'eb:border-border eb:text-foreground-lighter eb:hover:bg-muted'\n )}\n >\n {t('Free only')}\n </button>\n )}\n </div>\n <div ref={listRef} id={listId} role=\"listbox\" aria-labelledby={labelId} className=\"eb:max-h-56 eb:overflow-y-auto eb:p-1\">\n {matches.map((model, at) => (\n <button\n key={model.id}\n id={optionId(at)}\n type=\"button\"\n role=\"option\"\n tabIndex={-1}\n aria-selected={model.id === value}\n data-active={at === active}\n data-model={model.id}\n onClick={() => pick(model.id)}\n onMouseMove={() => at !== active && setActive(at)}\n className={cn(\n 'eb:flex eb:w-full eb:min-w-0 eb:items-start eb:gap-2 eb:rounded-md eb:px-2 eb:py-1.5 eb:text-left',\n at === active ? 'eb:bg-accent eb:text-accent-foreground' : ''\n )}\n >\n <Check className={cn('eb:mt-0.5 eb:size-3.5 eb:shrink-0 eb:text-primary', model.id !== value && 'eb:invisible')} aria-hidden=\"true\" />\n <span className=\"eb:flex eb:min-w-0 eb:flex-1 eb:flex-col eb:gap-0.5\">\n <span className=\"eb:flex eb:min-w-0 eb:items-center eb:gap-1.5\">\n <span className=\"eb:truncate eb:text-[13px] eb:text-foreground\">{model.name}</span>\n {badges(model)}\n </span>\n {model.name !== model.id && <span className=\"eb:truncate eb:font-mono eb:text-[10.5px] eb:text-foreground-muted\">{model.id}</span>}\n </span>\n </button>\n ))}\n {custom && (\n <button\n id={optionId(matches.length)}\n type=\"button\"\n role=\"option\"\n tabIndex={-1}\n aria-selected={false}\n data-active={active === matches.length}\n onClick={() => pick(custom)}\n onMouseMove={() => active !== matches.length && setActive(matches.length)}\n className={cn(\n 'eb:flex eb:w-full eb:min-w-0 eb:items-center eb:gap-2 eb:rounded-md eb:px-2 eb:py-1.5 eb:text-left eb:text-[13px] eb:text-primary',\n active === matches.length ? 'eb:bg-accent' : ''\n )}\n data-testid=\"eb-ai-connect-model-custom\"\n >\n <span className=\"eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n <span className=\"eb:min-w-0 eb:truncate\">{t('Use “{model}”', { model: custom })}</span>\n </button>\n )}\n {!count && <p className=\"eb:px-2 eb:py-3 eb:text-center eb:text-[12px] eb:text-foreground-muted\">{t('No model matches.')}</p>}\n </div>\n </div>\n )}\n\n <p id={hintId} role=\"status\" className=\"eb:flex eb:min-h-4 eb:items-center eb:gap-1.5 eb:text-[11.5px] eb:text-foreground-muted\" data-testid=\"eb-ai-connect-models-status\">\n {status}\n </p>\n </div>\n );\n}\n","import { useEffect, useRef, useState } from 'react';\nimport { Check, CircleCheck, Loader2, SpellCheck, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { cn } from '../ui/primitives/cn.js';\nimport { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '../ui/primitives/overlays.jsx';\nimport { cleanRichText } from '../engine/richText.js';\nimport { diffWords } from './diff.js';\nimport { visibleText } from './subjects.js';\n\n/**\n * PROOFREAD — toolbar button and dialog: the mistakes of the whole email.\n *\n * One click reads every text the reader sees — the subject, the preview\n * text, the text blocks, the buttons, the menu links — and lists the ones\n * with a mistake: the old words struck out, the new ones next to them. Each\n * correction is applied on its own or all at once; in the email, all of them\n * are one step of the history (Ctrl+Z brings the texts back). Nothing changes\n * before the user applies it.\n *\n * A text edited while the email is read, or before its correction is\n * applied, is left as it is: the correction was for the old one. Who reads it\n * — an AI, or LanguageTool (languagetool.js) — is the `proofread` function's.\n */\n\n/** Tags whose content is a label of plain words (EmailEditor `content`). */\nconst LABEL_TAGS = { 'mj-button': 'button', 'mj-navbar-link': 'link' };\n\n/** What each kind of text is called in the list. */\nconst KIND_LABELS = { subject: 'Subject', preheader: 'Preview text', text: 'Text', button: 'Button', link: 'Menu link' };\n\n/**\n * The texts of the email, in order: as they are stored, under the id the\n * correction comes back with.\n * @param {any} editor @param {{subject: string, preheader: string}} meta\n */\nfunction textsOf(editor, meta) {\n /** @type {{id: string, kind: keyof typeof KIND_LABELS, format: 'html'|'plain', text: string}[]} */\n const texts = [];\n if (meta.subject.trim()) texts.push({ id: 'subject', kind: 'subject', format: 'plain', text: meta.subject.trim() });\n if (meta.preheader.trim()) texts.push({ id: 'preheader', kind: 'preheader', format: 'plain', text: meta.preheader.trim() });\n const walk = (/** @type {any} */ node) => {\n if (!node || typeof node !== 'object') return;\n const element = node.tag === 'mj-text' || LABEL_TAGS[node.tag] ? editor.getElement(node.id) : null;\n if (node.tag === 'mj-text' && element?.html) texts.push({ id: node.id, kind: 'text', format: 'html', text: element.html });\n else if (LABEL_TAGS[node.tag] && element?.content) texts.push({ id: node.id, kind: LABEL_TAGS[node.tag], format: 'plain', text: element.content });\n for (const child of node.children || []) walk(child);\n };\n walk(editor.getDocument().project?.root);\n return texts;\n}\n\n/** The text of one entry as it is now. @param {any} editor @param {{subject: string, preheader: string}} meta @param {string} id */\nfunction currentText(editor, meta, id) {\n if (id === 'subject' || id === 'preheader') return meta[id].trim();\n const element = editor.getElement(id);\n return (element?.tagName === 'mj-text' ? element?.html : element?.content) ?? null;\n}\n\nexport default function ProofreadButton({ context, proofread }) {\n const { editor, ready, meta, setMeta } = context;\n const { t, locale, notify } = useUi();\n const [open, setOpen] = useState(false);\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState('');\n const [seconds, setSeconds] = useState(0);\n /** @type {[{id: string, kind: keyof typeof KIND_LABELS, format: 'html'|'plain', before: string, after: string, state: 'open'|'applied'|'stale'}[]|null, Function]} */\n const [fixes, setFixes] = useState(null);\n const abortRef = useRef(/** @type {AbortController|null} */ (null));\n const metaRef = useRef(meta);\n metaRef.current = meta;\n\n useEffect(() => () => abortRef.current?.abort(), []);\n useEffect(() => {\n if (!busy) return undefined;\n setSeconds(0);\n const timer = setInterval(() => setSeconds((s) => s + 1), 1000);\n return () => clearInterval(timer);\n }, [busy]);\n // Another email loaded: these corrections were for the previous one.\n useEffect(\n () =>\n editor.on('load', () => {\n abortRef.current?.abort();\n setOpen(false);\n }),\n [editor]\n );\n\n const run = async () => {\n if (busy) return;\n const texts = textsOf(editor, metaRef.current);\n setError('');\n setFixes(null);\n if (!texts.length) {\n setError(t('The email has no text to check yet.'));\n return;\n }\n setBusy(true);\n const controller = new AbortController();\n abortRef.current = controller;\n try {\n const result = await proofread(\n { texts: texts.map(({ id, kind, format, text }) => ({ id, kind, format, text })), language: String(locale || 'en').slice(0, 2) },\n { signal: controller.signal }\n );\n if (controller.signal.aborted) return;\n const sent = new Map(texts.map((text) => [text.id, text]));\n setFixes(\n result.fixes\n .filter((fix) => sent.has(fix.id))\n .map((fix) => {\n const text = /** @type {(typeof texts)[number]} */ (sent.get(fix.id));\n // Edited while it was read: the correction is for the old text.\n const stale = currentText(editor, metaRef.current, fix.id) !== text.text;\n return { id: fix.id, kind: text.kind, format: text.format, before: text.text, after: fix.text, state: stale ? 'stale' : 'open' };\n })\n );\n } catch (err) {\n if (!controller.signal.aborted) setError(err?.message ? t(err.message) : t('The email could not be checked.'));\n } finally {\n // A reading cancelled for a newer one leaves that one busy.\n if (abortRef.current === controller) {\n abortRef.current = null;\n setBusy(false);\n }\n }\n };\n\n // Read once the dialog is there. Without a key yet, the reading opens the\n // Connect dialog, which then comes above this one; opened in the same\n // render, it was hidden from screen readers and the keyboard.\n useEffect(() => {\n if (!open) return undefined;\n run();\n return () => abortRef.current?.abort();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n\n const openDialog = () => setOpen(true);\n\n const close = (next) => {\n if (next) return;\n abortRef.current?.abort();\n abortRef.current = null;\n setBusy(false);\n setOpen(false);\n };\n\n /**\n * Applies corrections still open, those whose text has not changed since;\n * the others are marked. The texts of the email change in one step.\n * @param {string[]} ids\n */\n const apply = (ids) => {\n if (!fixes) return;\n const wanted = new Set(ids);\n /** @type {{id: string, content: string}[]} */\n const contents = [];\n /** @type {Partial<{subject: string, preheader: string}>} */\n const metaChanges = {};\n const next = fixes.map((fix) => {\n if (!wanted.has(fix.id) || fix.state !== 'open') return fix;\n if (currentText(editor, metaRef.current, fix.id) !== fix.before) return { ...fix, state: /** @type {const} */ ('stale') };\n if (fix.id === 'subject' || fix.id === 'preheader') metaChanges[fix.id] = fix.after;\n else contents.push({ id: fix.id, content: fix.format === 'html' ? cleanRichText(fix.after, document) : fix.after });\n return { ...fix, state: /** @type {const} */ ('applied') };\n });\n if (contents.length) editor.setContents(contents);\n if (Object.keys(metaChanges).length) setMeta((current) => ({ ...current, ...metaChanges }));\n setFixes(next);\n const applied = next.filter((fix, index) => fix.state === 'applied' && fixes[index].state !== 'applied').length;\n if (applied && next.every((fix) => fix.state !== 'open')) {\n setOpen(false);\n notify('success', t('Corrections applied: {count}.', { count: next.filter((fix) => fix.state === 'applied').length }));\n }\n };\n\n const remaining = (fixes || []).filter((fix) => fix.state === 'open');\n\n return (\n <>\n <Button variant=\"outline\" size=\"sm-compact\" disabled={!ready} onClick={openDialog}>\n <SpellCheck />\n {t('Proofread')}\n </Button>\n <Dialog open={open} onOpenChange={close}>\n <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\">\n <DialogHeader className=\"eb:gap-1.5 eb:px-6 eb:pt-6 eb:pb-4\">\n <DialogTitle>{t('Proofread the email')}</DialogTitle>\n <DialogDescription>{t('Every text is checked for spelling, grammar and punctuation mistakes. Nothing changes until you apply it.')}</DialogDescription>\n </DialogHeader>\n\n <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\">\n {busy && (\n <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\">\n <Loader2 className=\"eb:size-4 eb:animate-spin\" aria-hidden=\"true\" />\n {t('Reading the email… {seconds} s', { seconds })}\n </p>\n )}\n {error && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-1.5 eb:py-2 eb:text-[13px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-0.5 eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {error}\n </p>\n )}\n {fixes && !fixes.length && (\n <p className=\"eb:flex eb:items-center eb:gap-2 eb:py-6 eb:text-[13px] eb:text-foreground\" role=\"status\">\n <CircleCheck className=\"eb:size-4 eb:text-success\" aria-hidden=\"true\" />\n {t('No mistake found.')}\n </p>\n )}\n {fixes && fixes.length > 0 && (\n <ul className=\"eb:flex eb:flex-col eb:gap-2.5\" aria-label={t('Corrections')}>\n {fixes.map((fix) => (\n <li\n key={fix.id}\n className={cn('eb:rounded-lg2 eb:border eb:border-border eb:p-3', fix.state !== 'open' && 'eb:bg-muted/40')}\n data-testid=\"eb-proofread-fix\"\n data-state={fix.state}\n >\n <div className=\"eb:mb-1.5 eb:flex eb:items-center eb:gap-2\">\n <span className=\"eb:text-[11px] eb:font-medium eb:tracking-wide eb:text-foreground-muted eb:uppercase\">{t(KIND_LABELS[fix.kind])}</span>\n <span className=\"eb:ml-auto\">\n {fix.state === 'open' && (\n <Button variant=\"outline\" size=\"xs\" onClick={() => apply([fix.id])}>\n {t('Apply')}\n </Button>\n )}\n {fix.state === 'applied' && (\n <span className=\"eb:flex eb:items-center eb:gap-1 eb:text-[12px] eb:text-success\">\n <Check className=\"eb:size-3.5\" aria-hidden=\"true\" />\n {t('Applied')}\n </span>\n )}\n {fix.state === 'stale' && (\n <span className=\"eb:text-[12px] eb:text-foreground-muted\">{t('Text changed since — left as it is')}</span>\n )}\n </span>\n </div>\n <Changes before={fix.before} after={fix.after} html={fix.format === 'html'} />\n </li>\n ))}\n </ul>\n )}\n </div>\n\n <div className=\"eb:flex eb:items-center eb:justify-end eb:gap-2 eb:border-t eb:border-border eb:px-6 eb:py-4\">\n {busy ? (\n <Button variant=\"outline\" size=\"sm\" onClick={() => close(false)}>\n {t('Cancel')}\n </Button>\n ) : (\n <>\n <Button variant=\"ghost\" size=\"sm\" className=\"eb:mr-auto\" onClick={run}>\n {t('Check again')}\n </Button>\n {remaining.length > 0 ? (\n <Button size=\"sm\" onClick={() => apply(remaining.map((fix) => fix.id))} data-testid=\"eb-proofread-apply-all\">\n <Check />\n {t('Apply all ({count})', { count: remaining.length })}\n </Button>\n ) : (\n <Button variant=\"outline\" size=\"sm\" onClick={() => close(false)}>\n {t('Close')}\n </Button>\n )}\n </>\n )}\n </div>\n </DialogContent>\n </Dialog>\n </>\n );\n}\n\n/**\n * The words a correction changes: the old ones struck out, the new ones\n * marked, in the flow of the text.\n */\nfunction Changes({ before, after, html }) {\n const parts = diffWords(html ? visibleText(before) : before, html ? visibleText(after) : after);\n return (\n <p className=\"eb:text-[13px] eb:leading-relaxed eb:break-words eb:whitespace-pre-line eb:text-foreground\">\n {parts.map((part, index) =>\n part.type === 'same' ? (\n <span key={index}>{around(part.text, index === 0, index === parts.length - 1)}</span>\n ) : part.type === 'removed' ? (\n <del key={index} className=\"eb:rounded-sm eb:bg-destructive/10 eb:text-destructive eb:line-through\">\n {part.text}\n </del>\n ) : (\n <ins key={index} className=\"eb:rounded-sm eb:bg-success/15 eb:text-success eb:no-underline\">\n {part.text}\n </ins>\n )\n )}\n </p>\n );\n}\n\n/** Words kept on each side of a change; a longer stretch is cut short. */\nconst CONTEXT = 48;\n\n/**\n * Unchanged words between corrections, shortened around them: a long text\n * shows where its mistakes are, not the whole of it.\n * @param {string} text @param {boolean} first @param {boolean} last\n */\nfunction around(text, first, last) {\n if (text.length <= CONTEXT * 2 + 8) return text;\n const head = (/** @type {string} */ value) => value.slice(0, CONTEXT).replace(/\\s\\S*$/, '');\n const tail = (/** @type {string} */ value) => value.slice(-CONTEXT).replace(/^\\S*\\s/, '');\n if (first && last) return text;\n if (first) return `…${tail(text)}`;\n if (last) return `${head(text)}…`;\n return `${head(text)} … ${tail(text)}`;\n}\n","import { useCallback, useEffect, useRef, useState } from 'react';\nimport { ChevronDown, Languages, Loader2, Sparkles, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { Textarea } from '../ui/primitives/fields.jsx';\nimport { SectionLabel } from '../ui/primitives/misc.jsx';\nimport { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '../ui/primitives/overlays.jsx';\nimport { cleanRichText } from '../engine/richText.js';\nimport { chipClassName } from './chip.js';\nimport { MAX_REWRITE_INSTRUCTION, REWRITE_ACTIONS, REWRITE_LANGUAGES } from './rewrite.js';\nimport { emailWords, visibleText } from './subjects.js';\n\n/**\n * WRITE WITH AI — in the properties of a selected text or button.\n *\n * One field for the user's words: what to change in the text (\"say it in\n * two lines\"), or what to write instead (\"the sale ends Sunday\") — the AI\n * tells which, and writes to fit the rest of the email (its language, its\n * tone, nothing it already says); a block set as a title gets one line.\n * Under it, one click rewrites the text: shorter, longer, fixed, friendlier,\n * more formal, translated. While the AI works the text shimmers on the\n * canvas; its answer comes in word by word. It replaces the text in one step\n * of the history: Ctrl+Z brings the previous text back, so there is nothing\n * to accept or compare.\n *\n * Mounted per element (keyed by its id): selecting another element cancels a\n * rewrite in progress. If the text is edited while the AI works, the user's\n * words win and the answer is dropped.\n */\n\n/** A language under its own name: \"Deutsch\", \"Українська\". @param {string} code */\nfunction nativeName(code) {\n try {\n const name = new Intl.DisplayNames([code], { type: 'language' }).of(code) || code;\n return name.charAt(0).toLocaleUpperCase(code) + name.slice(1);\n } catch {\n return code;\n }\n}\n\nexport default function RewriteText({ editor, selection, rewrite }) {\n const { t, locale, notify } = useUi();\n const [running, setRunning] = useState(/** @type {string|null} */ (null));\n const [error, setError] = useState('');\n const [request, setRequest] = useState('');\n const abortRef = useRef(/** @type {AbortController|null} */ (null));\n const label = selection.tagName === 'mj-button';\n\n /** Stops the AI's work, and its shimmer on the canvas. */\n const stop = useCallback(() => {\n if (!abortRef.current) return;\n abortRef.current.abort();\n abortRef.current = null;\n editor.showWorking(null);\n }, [editor]);\n\n useEffect(() => stop, [stop]);\n\n /** The text as stored: a button's label, a text block's HTML. */\n const currentText = () => {\n const element = editor.getElement(selection.id);\n return (label ? element?.content : element?.html) ?? '';\n };\n\n const run = async (action, extra = {}) => {\n if (running) return;\n const text = currentText();\n // The user's own words: the AI writes; a click: it rewrites.\n const writing = action === 'custom';\n setError('');\n setRunning(action);\n const controller = new AbortController();\n abortRef.current = controller;\n editor.showWorking(selection.id);\n try {\n const result = await rewrite({ action, text, format: label ? 'plain' : 'html', ...extra }, { signal: controller.signal });\n if (controller.signal.aborted) return;\n if (currentText() !== text) {\n setError(t('The text changed in the meantime, so it was left as it is.'));\n return;\n }\n editor.setContent(label ? result.text : cleanRichText(result.text, document), selection.id, { reveal: true });\n if (action === 'custom') setRequest('');\n notify('success', writing ? t('Text written. Ctrl+Z brings back the previous one.') : t('Text rewritten. Ctrl+Z brings back the previous one.'));\n } catch (err) {\n if (!controller.signal.aborted) {\n setError(err?.message ? t(err.message) : writing ? t('The text could not be written.') : t('The text could not be rewritten.'));\n }\n } finally {\n if (abortRef.current === controller) {\n abortRef.current = null;\n editor.showWorking(null);\n }\n setRunning(null);\n }\n };\n\n const cancel = () => {\n stop();\n setRunning(null);\n };\n\n /** The user's words: a change, or what to write — fitting the rest of the email. */\n const ask = () => {\n const words = request.trim();\n if (!words) return;\n const size = Number.parseFloat(String(editor.getElement(selection.id)?.attributes?.['font-size'] || ''));\n // The email without this text: what the new one must fit, and not repeat.\n const own = visibleText(currentText());\n const email = emailWords(editor.exportMjml());\n run('custom', {\n instruction: words,\n context: own ? email.replace(own, '').trim() : email,\n role: size >= 20 ? 'heading' : 'text',\n language: String(locale || 'en').slice(0, 2),\n });\n };\n\n const busy = Boolean(running);\n const spinner = <Loader2 className=\"eb:size-3 eb:animate-spin\" aria-hidden=\"true\" />;\n\n return (\n <section className=\"eb:space-y-2.5\" aria-label={t('Write with AI')} data-testid=\"eb-rewrite\">\n <SectionLabel className=\"eb:flex eb:items-center eb:gap-1.5\">\n <Sparkles className=\"eb:size-3\" aria-hidden=\"true\" />\n {t('Write with AI')}\n </SectionLabel>\n <PromptForm\n value={request}\n onChange={setRequest}\n onSubmit={ask}\n placeholder={t('What should it say, or what should change? e.g. the sale ends Sunday')}\n label={t('Ask the AI')}\n busy={busy}\n submitLabel={t('Write')}\n >\n {running === 'custom' ? <Loader2 className=\"eb:animate-spin\" /> : <Sparkles />}\n </PromptForm>\n <div className=\"eb:flex eb:flex-wrap eb:gap-1.5\">\n {REWRITE_ACTIONS.map((action) => (\n <button key={action.id} type=\"button\" className={chipClassName()} disabled={busy} onClick={() => run(action.id)}>\n {running === action.id && spinner}\n {t(action.label)}\n </button>\n ))}\n <DropdownMenu>\n <DropdownMenuTrigger asChild disabled={busy}>\n <button type=\"button\" className={chipClassName()}>\n {running === 'translate' ? spinner : <Languages className=\"eb:size-3\" aria-hidden=\"true\" />}\n {t('Translate')}\n <ChevronDown className=\"eb:size-3\" aria-hidden=\"true\" />\n </button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"start\" aria-label={t('Translate into')}>\n {REWRITE_LANGUAGES.map((code) => (\n <DropdownMenuItem key={code} lang={code} onSelect={() => run('translate', { targetLanguage: code })}>\n {nativeName(code)}\n </DropdownMenuItem>\n ))}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n {running && (\n <p className=\"eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted\" role=\"status\" aria-live=\"polite\">\n {running === 'custom' ? t('Writing…') : t('Rewriting…')}\n <Button type=\"button\" variant=\"link\" size=\"xs\" className=\"eb:h-auto eb:px-0\" onClick={cancel}>\n {t('Cancel')}\n </Button>\n </p>\n )}\n {error && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-px eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {error}\n </p>\n )}\n </section>\n );\n}\n\n/**\n * What the AI is asked, on a few lines so that the whole request stays in\n * view. Enter sends it, Shift+Enter starts a new line; an empty one is not\n * sent. `children`: the send button's icon.\n */\nfunction PromptForm({ value, onChange, onSubmit, placeholder, label, busy, submitLabel, children }) {\n const ready = !busy && Boolean(value.trim());\n return (\n <form\n className=\"eb:flex eb:items-end eb:gap-1.5\"\n onSubmit={(event) => {\n event.preventDefault();\n if (ready) onSubmit();\n }}\n >\n <Textarea\n dense\n rows={3}\n value={value}\n onChange={(event) => onChange(event.target.value)}\n onKeyDown={(event) => {\n if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing) return;\n event.preventDefault();\n if (ready) onSubmit();\n }}\n maxLength={MAX_REWRITE_INSTRUCTION}\n placeholder={placeholder}\n aria-label={label}\n disabled={busy}\n className=\"eb:min-h-16 eb:max-h-40 eb:resize-none\"\n />\n <Button type=\"submit\" variant=\"outline\" size=\"icon-dense\" aria-label={submitLabel} disabled={!ready}>\n {children}\n </Button>\n </form>\n );\n}\n","import { cn } from '../ui/primitives/cn.js';\n\n/**\n * A rounded badge button: the rewrite actions.\n * @param {boolean} [selected]\n */\nexport const chipClassName = (selected = false) =>\n cn(\n 'eb:inline-flex eb:h-[22px] eb:items-center eb:gap-1 eb:rounded-md eb:border eb:px-2.5 eb:text-[12px] eb:font-medium eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50 eb:disabled:opacity-50',\n selected\n ? 'eb:border-primary eb:bg-primary eb:text-primary-foreground'\n : 'eb:border-border eb:bg-background eb:text-foreground eb:hover:border-primary/50 eb:hover:bg-primary/5'\n );\n","import { useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { Check, Loader2, Sparkles, TriangleAlert } from 'lucide-react';\nimport { useUi } from '../ui/context.jsx';\nimport { Button } from '../ui/primitives/button.jsx';\nimport { cn } from '../ui/primitives/cn.js';\nimport { chipClassName } from './chip.js';\nimport { emailWords } from './subjects.js';\n\n/** Ideas already shown that \"More ideas\" asks the model not to repeat (the server keeps 12). */\nconst MAX_AVOID = 12;\n\n/**\n * SUGGEST SUBJECTS — under the subject of the email.\n *\n * One click: three other subject lines, drawn from the words of the email.\n * They are a list to pick from, the user's own subject first: a click puts\n * one in the field, another click another one, the first row brings the\n * user's subject back. \"More ideas\" asks for three new ones (none of those\n * already shown; the one in the field stays in the list); \"Done\" closes the\n * list and keeps the subject in the field.\n *\n * \"Yours\" is what the user wrote: typed in the field while the list is open\n * (or while ideas are on their way), it becomes the new \"yours\". When the\n * email itself is replaced (another template opened), the list closes.\n *\n * Keyboard: the list is a radio group — one Tab stop, the arrows move and\n * pick. Focus goes to the list when it opens, back to the button after Done or\n * Cancel.\n */\nexport default function SubjectIdeas({ editor, meta, onSubject, suggest, variables = null }) {\n const { t, locale } = useUi();\n const [running, setRunning] = useState(false);\n const [error, setError] = useState('');\n const [ideas, setIdeas] = useState(/** @type {string[]|null} */ (null));\n const [original, setOriginal] = useState('');\n const shownRef = useRef(/** @type {string[]} */ ([]));\n const abortRef = useRef(/** @type {AbortController|null} */ (null));\n const subjectRef = useRef(meta.subject);\n subjectRef.current = meta.subject;\n const rootRef = useRef(/** @type {HTMLDivElement|null} */ (null));\n /** Where focus goes after the next render: the list, or the button that opened it. */\n const focusRef = useRef(/** @type {'list'|'button'|null} */ (null));\n\n useEffect(() => () => abortRef.current?.abort(), []);\n\n // Another email loaded in the editor: these ideas were for the previous one.\n useEffect(\n () =>\n editor.on('load', () => {\n abortRef.current?.abort();\n abortRef.current = null;\n shownRef.current = [];\n setRunning(false);\n setIdeas(null);\n setError('');\n setOriginal('');\n }),\n [editor]\n );\n\n // Typed in the field while the list is open: that is the user's subject now.\n const typed = meta.subject.trim();\n useEffect(() => {\n if (ideas && typed && !ideas.includes(meta.subject) && typed !== original) setOriginal(typed);\n }, [ideas, meta.subject, typed, original]);\n\n useLayoutEffect(() => {\n const target = focusRef.current;\n if (!target || running) return;\n focusRef.current = null;\n const root = rootRef.current;\n const element =\n target === 'list'\n ? root?.querySelector('[role=\"radio\"][tabindex=\"0\"]')\n : root?.querySelector('[data-subject-ideas-button]');\n /** @type {HTMLElement|null|undefined} */ (element)?.focus();\n });\n\n const ready = editor.status === 'ready';\n\n const run = async () => {\n if (running || editor.status !== 'ready') return;\n const first = !ideas;\n // The user's subject: as it was before the first idea was picked, or typed since.\n const yours = first ? subjectRef.current.trim() : original;\n const controller = new AbortController();\n abortRef.current = controller;\n setError('');\n setRunning(true);\n try {\n const result = await suggest(\n {\n subject: yours,\n preheader: meta.preheader,\n text: emailWords(editor.exportMjml()),\n language: locale,\n variables: variables?.map(({ key, label, kind }) => ({ key, label, kind })),\n avoid: shownRef.current.slice(-MAX_AVOID),\n },\n { signal: controller.signal }\n );\n if (controller.signal.aborted) return;\n const current = subjectRef.current;\n // The idea in the field stays in the list; the others give way to the new ones.\n const kept = ideas?.includes(current) ? [current] : [];\n const next = [...kept, ...result.subjects.filter((subject) => subject !== current)];\n shownRef.current = [...shownRef.current, ...result.subjects];\n // Typed during the wait: that is \"yours\" now.\n setOriginal(current.trim() && !ideas?.includes(current) ? current.trim() : yours);\n setIdeas(next);\n if (first) focusRef.current = 'list';\n } catch (err) {\n if (!controller.signal.aborted) setError(err?.message ? t(err.message) : t('No subject could be suggested.'));\n } finally {\n // A request cancelled earlier must not end the one that replaced it.\n if (abortRef.current === controller) {\n abortRef.current = null;\n setRunning(false);\n }\n }\n };\n\n const cancel = () => {\n abortRef.current?.abort();\n abortRef.current = null;\n setRunning(false);\n focusRef.current = 'button';\n };\n\n const done = () => {\n setIdeas(null);\n setError('');\n shownRef.current = [];\n focusRef.current = 'button';\n };\n\n const options = ideas ? [...(original ? [{ text: original, yours: true }] : []), ...ideas.map((text) => ({ text, yours: false }))] : [];\n const checked = options.findIndex((option) => option.text === meta.subject);\n const tabStop = checked === -1 ? 0 : checked;\n\n /** Arrows move through the ideas and pick, as in any radio group. */\n const onKeyDown = (/** @type {React.KeyboardEvent} */ event) => {\n const step = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[event.key];\n const to = step ? (tabStop + step + options.length) % options.length : event.key === 'Home' ? 0 : event.key === 'End' ? options.length - 1 : -1;\n if (to === -1 || !options.length) return;\n event.preventDefault();\n onSubject(options[to].text);\n /** @type {HTMLElement|undefined} */ (rootRef.current?.querySelectorAll('[role=\"radio\"]')[to])?.focus();\n };\n\n const spinner = <Loader2 className=\"eb:size-3 eb:animate-spin\" aria-hidden=\"true\" />;\n\n return (\n <div className=\"eb:space-y-2\" data-testid=\"eb-subject-ideas\" ref={rootRef}>\n {!ideas && (\n <button type=\"button\" className={chipClassName()} disabled={running || !ready} onClick={run} data-subject-ideas-button>\n {running ? spinner : <Sparkles className=\"eb:size-3\" aria-hidden=\"true\" />}\n {t('Suggest subjects')}\n </button>\n )}\n {ideas && (\n <div className=\"eb:space-y-2 eb:rounded-lg2 eb:border eb:border-border eb:p-1.5\">\n <div role=\"radiogroup\" aria-label={t('Subject ideas')} className=\"eb:space-y-0.5\" onKeyDown={onKeyDown}>\n {options.map((option, index) => {\n const chosen = index === checked;\n return (\n <button\n key={`${option.yours ? 'yours' : 'idea'}:${option.text}`}\n type=\"button\"\n role=\"radio\"\n aria-checked={chosen}\n tabIndex={index === tabStop ? 0 : -1}\n className={cn(\n 'eb:flex eb:w-full eb:items-start eb:gap-2 eb:rounded-md eb:px-2 eb:py-1.5 eb:text-left eb:text-[12.5px] eb:leading-snug eb:transition-colors eb:outline-none eb:focus-visible:ring-[3px] eb:focus-visible:ring-ring/50',\n chosen ? 'eb:bg-primary/10 eb:text-foreground' : 'eb:text-foreground-lighter eb:hover:bg-muted'\n )}\n onClick={() => onSubject(option.text)}\n >\n <Check className={cn('eb:mt-0.5 eb:size-3.5 eb:shrink-0', chosen ? 'eb:text-primary' : 'eb:invisible')} aria-hidden=\"true\" />\n <span className=\"eb:min-w-0 eb:flex-1 eb:break-words\">{option.text}</span>\n {option.yours && <span className=\"eb:shrink-0 eb:text-[11px] eb:text-foreground-muted\">{t('yours')}</span>}\n </button>\n );\n })}\n </div>\n <div className=\"eb:flex eb:items-center eb:gap-1.5 eb:px-1 eb:pb-0.5\">\n <button type=\"button\" className={chipClassName()} disabled={running || !ready} onClick={run} data-subject-ideas-button>\n {running ? spinner : <Sparkles className=\"eb:size-3\" aria-hidden=\"true\" />}\n {t('More ideas')}\n </button>\n <Button type=\"button\" variant=\"ghost\" size=\"xs\" className=\"eb:ml-auto\" disabled={running} onClick={done}>\n {t('Done')}\n </Button>\n </div>\n </div>\n )}\n {running && (\n <p className=\"eb:flex eb:items-center eb:gap-2 eb:text-[12px] eb:text-foreground-muted\" role=\"status\" aria-live=\"polite\">\n {t('Reading the email…')}\n <Button type=\"button\" variant=\"link\" size=\"xs\" className=\"eb:h-auto eb:px-0\" onClick={cancel}>\n {t('Cancel')}\n </Button>\n </p>\n )}\n {error && (\n <p role=\"alert\" className=\"eb:flex eb:items-start eb:gap-1.5 eb:text-[12px] eb:text-destructive\">\n <TriangleAlert className=\"eb:mt-px eb:size-3.5 eb:shrink-0\" aria-hidden=\"true\" />\n {error}\n </p>\n )}\n </div>\n );\n}\n","// @ts-check\n/**\n * THE AI MODULE — `createAi()`, given to the builder as `ai`.\n *\n * import { createAi } from 'best-email-builder/ai';\n * <EmailBuilder storage={storage} ai={createAi()} />\n *\n * Without it, the builder has no AI button, and none of the AI's code or\n * texts is in the application's bundle: the core never imports this folder.\n * With it, the builder gets what the module can do:\n *\n * proofread the Proofread button: the mistakes of every text, to apply\n * rewrite \"Write with AI\" and \"Rewrite with AI\" in the properties\n * of a text or a button\n * suggestSubjects \"Suggest subjects\" under the subject\n *\n * Where the model runs:\n *\n * createAi() the routes of createEmailBuilderHandler({ generator })\n * createAi({ baseUrl, headers }) the same routes elsewhere, or with the user's credentials\n * createAi({ provider, askKey: true }) the AI runs in the page with each user's own key\n * (OpenRouter, Gemini, Groq… — see providers.js);\n * the builder asks for it once (the Connect dialog)\n * createAi({ provider: [...], askKey: true })\n * the same, the user choosing the provider in that\n * dialog (Claude too: claudeProvider in claude.js),\n * and the model among those the provider lists\n * createAi({ provider, apiKey }) the same with one key for all (prototypes: the key\n * is then in the page)\n * createAi({ model }) the generator runs in the page with this model\n * createAi({ proofread, rewrite, … }) functions of your own: only those given are on —\n * createLanguageToolProofreader({ url }) proofreads\n * without AI (languagetool.js)\n *\n * Each of `proofread`, `rewrite` and `suggestSubjects` can also be `false`,\n * to leave that part out — its button with it.\n */\n\nimport { createHttpCaller } from '../storage/client.js';\nimport { EmailGenerationError } from './errors.js';\nimport { createEmailGenerator } from './generator.js';\nimport { AI_MESSAGES } from './i18n/index.js';\nimport { createKeyStore } from './keys.js';\nimport { providerEmailModel, resolveProvider } from './providers.js';\nimport ConnectAi from './ConnectAi.jsx';\nimport ProofreadButton from './ProofreadButton.jsx';\nimport RewriteText from './RewriteText.jsx';\nimport SubjectIdeas from './SubjectIdeas.jsx';\n\n/**\n * @typedef {import('./rewrite.js').RewriteInput} RewriteInput\n * @typedef {import('./subjects.js').SubjectsInput} SubjectsInput\n * @typedef {import('./proofread.js').ProofreadInput} ProofreadInput\n * @typedef {{signal?: AbortSignal}} CallOptions\n * @typedef {(input: ProofreadInput, options?: CallOptions) => Promise<{fixes: import('./proofread.js').ProofreadFix[]}>} ProofreadFn\n * @typedef {(input: RewriteInput, options?: CallOptions) => Promise<{text: string}>} RewriteFn\n * @typedef {(input: SubjectsInput, options?: CallOptions) => Promise<{subjects: string[]}>} SuggestSubjectsFn\n *\n * @typedef {{\n * baseUrl?: string,\n * headers?: Record<string, string> | (() => Record<string, string>),\n * fetch?: typeof fetch,\n * model?: import('./generator.js').EmailModel,\n * provider?: ProviderOption | ProviderOption[],\n * apiKey?: string,\n * askKey?: boolean,\n * maxAttempts?: number,\n * proofread?: ProofreadFn | boolean,\n * rewrite?: RewriteFn | boolean,\n * suggestSubjects?: SuggestSubjectsFn | boolean,\n * }} AiOptions\n * `provider`: an id of `AI_PROVIDERS` ('openrouter', 'gemini', 'groq'…), or\n * `{ id, model, baseUrl, headers }` for another model or an endpoint of your\n * own — or a list of them, with `askKey`: the user chooses (the first is\n * offered first). `apiKey`: one key for every user. `askKey`: each user\n * connects their own (off by default).\n *\n * @typedef {Readonly<{\n * proofread: ProofreadFn | null,\n * rewrite: RewriteFn | null,\n * suggestSubjects: SuggestSubjectsFn | null,\n * key: import('./keys.js').AiKey | null,\n * messages: Record<string, Record<string, string>>,\n * components: Readonly<{Proofread: typeof ProofreadButton, Rewrite: typeof RewriteText, Subjects: typeof SubjectIdeas, Connect: typeof ConnectAi | null}>,\n * }>} EmailBuilderAi\n * What the builder reads. `key`: the user's key, with `askKey` (keys.js).\n * `messages`: the module's own translations, by locale, merged under the\n * host's `messages`. `components.Connect`: the dialog that asks for the key.\n */\n\n/** @typedef {string | Partial<import('./providers.js').AiProvider>} ProviderOption */\n\nconst PARTS = /** @type {const} */ (['proofread', 'rewrite', 'suggestSubjects']);\nconst ROUTES = { proofread: '/proofread', rewrite: '/rewrite', suggestSubjects: '/subjects' };\n\n/**\n * @param {AiOptions} [options]\n * @returns {EmailBuilderAi}\n */\nexport function createAi(options = {}) {\n if (!options || typeof options !== 'object') throw new TypeError('createAi: options must be an object');\n const { model, maxAttempts, baseUrl, headers, fetch: fetchImpl, provider: providerOption, apiKey, askKey = false } = options;\n const usesProvider = providerOption !== undefined;\n const http = baseUrl !== undefined || headers !== undefined || (fetchImpl !== undefined && !usesProvider);\n if (model !== undefined && typeof model !== 'function') throw new TypeError('createAi: `model` must be a function');\n if (model && http) throw new TypeError('createAi: pass `model` (the AI runs in the page) or `baseUrl` (on the server), not both');\n if (usesProvider && (model || http)) {\n throw new TypeError('createAi: `provider` runs the AI in the page — not with `model`, `baseUrl` or `headers` (give the provider `{ id, model, baseUrl, headers }`)');\n }\n if (!usesProvider && (apiKey !== undefined || options.askKey !== undefined)) {\n throw new TypeError('createAi: `apiKey` and `askKey` go with a `provider` (e.g. provider: \"openrouter\")');\n }\n if (apiKey !== undefined && (typeof apiKey !== 'string' || !apiKey)) throw new TypeError('createAi: `apiKey` must be a non-empty string');\n // Gone in 0.10: no email is written from scratch any more. `false` (off) asks for nothing.\n const { generate } = /** @type {any} */ (options);\n if (generate !== undefined && generate !== false) {\n throw new TypeError('createAi: `generate` was removed in 0.10 — the AI checks and writes the texts of an email (`proofread`, `rewrite`), not whole emails');\n }\n if (typeof askKey !== 'boolean') throw new TypeError('createAi: `askKey` must be true or false');\n if (apiKey && askKey) throw new TypeError('createAi: `apiKey` (one key for all) or `askKey` (each user\\'s own), not both');\n const choice = Array.isArray(providerOption);\n if (choice && (!providerOption.length || !askKey)) {\n throw new TypeError('createAi: a list of providers is for `askKey: true` — each user chooses one and connects their own key');\n }\n /** @type {import('./providers.js').AiProvider[]} */\n const providers = usesProvider ? (choice ? providerOption : [providerOption]).map(providerOf) : [];\n if (new Set(providers.map((provider) => provider.id)).size !== providers.length) throw new TypeError('createAi: each provider once');\n const [provider = null] = providers;\n if (provider && !apiKey && !askKey && !provider.keyless) {\n throw new TypeError(`createAi: ${provider.name} needs a key — \\`apiKey\\`, or \\`askKey: true\\` to let each user connect their own`);\n }\n for (const part of PARTS) {\n const value = options[part];\n if (value !== undefined && typeof value !== 'boolean' && typeof value !== 'function') {\n throw new TypeError(`createAi: \\`${part}\\` must be a function, true or false`);\n }\n }\n\n // Functions of the host's own and nothing else: only those are on.\n const ownOnly = !model && !http && PARTS.some((part) => typeof options[part] === 'function');\n /** @type {Partial<Record<typeof PARTS[number], Function>>} */\n let transport = {};\n const key = provider && askKey ? createKeyStore(providers, { fetch: fetchImpl }) : null;\n if (provider) {\n /** @type {Map<string, import('./generator.js').EmailModel>} */\n const models = new Map();\n const keyFor = () => (key ? key.get() : apiKey || '');\n /** The model the user chose of the provider in use, made once. @param {string} id */\n const modelOf = (id) => {\n const chosen = /** @type {import('./providers.js').AiProvider} */ (providers.find((item) => item.id === id));\n const name = key ? key.model(id) : chosen.model;\n // An OpenAI-compatible API of the user's own: where it answers is theirs too.\n const address = key && key.providers.find((item) => item.id === id)?.needsAddress ? key.address(id) : '';\n const slot = `${id}\\n${name}\\n${address}`;\n if (!models.has(slot)) {\n models.set(\n slot,\n chosen.createModel\n ? chosen.createModel({ apiKey: keyFor, fetch: fetchImpl, ...(name ? { model: name } : {}) })\n : providerEmailModel({ provider: chosen, fetch: fetchImpl, apiKey: keyFor, ...(name ? { model: name } : {}), ...(address ? { baseUrl: address } : {}) })\n );\n }\n return /** @type {import('./generator.js').EmailModel} */ (models.get(slot));\n };\n /** @type {import('./generator.js').EmailModel} */\n const model = async (request) => {\n // The user's key (and the address, the model it needs), asked when\n // missing — they may choose another provider there. Cancelled: KEY_MISSING.\n if (key && !key.ready()) {\n await key.request();\n if (!key.ready()) throw new EmailGenerationError('KEY_MISSING', `${key.provider.name}: not connected`);\n }\n return modelOf(key ? key.provider.id : provider.id)(request);\n };\n const generator = createEmailGenerator({ model, maxAttempts });\n for (const part of PARTS) transport[part] = key ? askedAgain(generator[part], key) : generator[part];\n } else if (model) {\n transport = createEmailGenerator({ model, maxAttempts });\n } else if (!ownOnly) {\n const { call } = createHttpCaller({ baseUrl, headers, fetch: fetchImpl });\n for (const part of PARTS) {\n transport[part] = (/** @type {object} */ input, /** @type {CallOptions} */ { signal } = {}) =>\n call(ROUTES[part], { method: 'POST', body: JSON.stringify(input), signal });\n }\n }\n\n /** @param {typeof PARTS[number]} part */\n const resolve = (part) => {\n const value = options[part];\n if (typeof value === 'function') return value;\n if (value === false) return null;\n return transport[part] || null;\n };\n\n return Object.freeze({\n proofread: /** @type {ProofreadFn|null} */ (resolve('proofread')),\n rewrite: /** @type {RewriteFn|null} */ (resolve('rewrite')),\n suggestSubjects: /** @type {SuggestSubjectsFn|null} */ (resolve('suggestSubjects')),\n key,\n messages: AI_MESSAGES,\n components: Object.freeze({ Proofread: ProofreadButton, Rewrite: RewriteText, Subjects: SubjectIdeas, Connect: key ? ConnectAi : null }),\n });\n}\n\n/**\n * A provider of the list: an id, `{ id, model, … }`, or one with its own\n * `createModel` (claudeProvider) taken as it is.\n * @param {ProviderOption} option\n * @returns {import('./providers.js').AiProvider}\n */\nfunction providerOf(option) {\n if (option && typeof option === 'object' && typeof option.createModel === 'function') {\n if (!option.id || !option.name) throw new TypeError('createAi: a provider with `createModel` needs an `id` and a `name`');\n return /** @type {import('./providers.js').AiProvider} */ (option);\n }\n return resolveProvider(/** @type {any} */ (option));\n}\n\n/**\n * A key the provider refuses is forgotten and asked again, once, in the same\n * action: the user pastes a good one and the email still comes.\n * @param {Function} run\n * @param {import('./keys.js').AiKey} key\n */\nfunction askedAgain(run, key) {\n return async (/** @type {any} */ input, /** @type {any} */ options) => {\n try {\n return await run(input, options);\n } catch (error) {\n if (/** @type {any} */ (error)?.code !== 'KEY_REFUSED' || options?.signal?.aborted) throw error;\n key.refuse();\n try {\n return await run(input, options);\n } catch (again) {\n if (/** @type {any} */ (again)?.code === 'KEY_REFUSED') key.refuse();\n throw again;\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAM,iBAAiB;AACvB,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,iBAAiB;AAGvB,SAAS,iBAAiB;AACxB,MAAI;AACF,UAAM,UAAU,WAAW;AAC3B,WAAO,WAAW,OAAO,QAAQ,YAAY,aAAa,UAAU;AAAA,EACtE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAkCA,IAAM,WAAW,CAAC,aAChB,OAAO,OAAO;AAAA,EACZ,IAAI,SAAS;AAAA,EACb,MAAM,SAAS;AAAA,EACf,OAAO,SAAS,SAAS;AAAA,EACzB,QAAQ,SAAS;AAAA,EACjB,SAAS,SAAS;AAAA,EAClB,MAAM,SAAS;AAAA,EACf,cAAc,QAAQ,SAAS,YAAY;AAAA,EAC3C,SAAS,QAAQ,SAAS,OAAO;AAAA,EACjC,cAAc,CAAC,SAAS,eAAe,CAAC,SAAS;AACnD,CAAC;AAGH,IAAM,eAAe,CAAC,QAAQ,OAAO,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAOlE,SAAS,eAAe,gBAAgB,EAAE,OAAO,UAAU,IAAI,CAAC,GAAG;AACxE,QAAM,YAAY,MAAM,QAAQ,cAAc,IAAI,iBAAiB,CAAC,cAAc;AAClF,QAAM,YAAY,OAAO,OAAO,UAAU,IAAI,QAAQ,CAAC;AACvD,MAAI,CAAC,UAAU,OAAQ,OAAM,IAAI,UAAU,uCAAuC;AAClF,QAAM,QAAQ,CAAwB,OAAO,UAAU,KAAK,CAAC,aAAa,SAAS,OAAO,EAAE;AAE5F,QAAM,SAAS,oBAAI,IAAI;AACvB,MAAI,UAAU;AAEd,MAAI,UAAU;AAEd,QAAM,YAAY,oBAAI,IAAI;AA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K;AAC5B,SAAO,OAA0B,OAA0B,YAAY;AACrE,QAAI;AACF,aAAO,MAAM,IAAI,OAAO,OAAO;AAAA,IACjC,SAAS,OAAO;AACd;AAAA;AAAA,QAAwB,OAAQ,SAAS,iBAAiB,SAAS,QAAQ;AAAA,OAAS,OAAM;AAC1F,UAAI,OAAO;AACX,UAAI;AACF,eAAO,MAAM,IAAI,OAAO,OAAO;AAAA,MACjC,SAAS,OAAO;AACd;AAAA;AAAA,UAAwB,OAAQ,SAAS;AAAA,SAAe,KAAI,OAAO;AACnE,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":["provider","useEffect","useId","useRef","useState","models","jsx","jsxs","useState","useRef","useId","useEffect","useEffect","useRef","useState","Check","TriangleAlert","Fragment","jsx","jsxs","useState","useRef","useEffect","TriangleAlert","Check","useEffect","useRef","useState","ChevronDown","Loader2","TriangleAlert","jsx","jsxs","useState","useRef","useEffect","currentText","Loader2","ChevronDown","TriangleAlert","useEffect","useRef","useState","Check","Loader2","Sparkles","TriangleAlert","jsx","jsxs","useState","useRef","useEffect","Loader2","Sparkles","Check","TriangleAlert","provider","model"]}
|