@elytracms/studio 0.0.102 → 0.0.103
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/convex/ingest.test.ts +54 -21
- package/convex/ingest.ts +52 -15
- package/dist/components/ai/translate-document-dialog.d.ts +43 -0
- package/dist/components/ai/translate-document-dialog.js +104 -36
- package/dist/components/ai/translate-document-dialog.js.map +1 -1
- package/dist/components/ai/translate-skipped.d.ts +19 -3
- package/dist/components/ai/translate-skipped.js +33 -7
- package/dist/components/ai/translate-skipped.js.map +1 -1
- package/dist/lib/ai/translate-apply.d.ts +69 -0
- package/dist/lib/ai/translate-apply.js +36 -0
- package/dist/lib/ai/translate-apply.js.map +1 -0
- package/dist/lib/ai/translate-document.d.ts +94 -7
- package/dist/lib/ai/translate-document.js +175 -55
- package/dist/lib/ai/translate-document.js.map +1 -1
- package/dist/lib/ai/writer-form.d.ts +33 -2
- package/dist/lib/ai/writer-form.js +188 -27
- package/dist/lib/ai/writer-form.js.map +1 -1
- package/dist/lib/engine-version.d.ts +1 -1
- package/dist/lib/engine-version.js +1 -1
- package/dist/lib/engine-version.js.map +1 -1
- package/dist/lib/i18n/messages.de.js +48 -6
- package/dist/lib/i18n/messages.de.js.map +1 -1
- package/dist/lib/i18n/messages.en.d.ts +37 -1
- package/dist/lib/i18n/messages.en.js +50 -6
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate-document-dialog.js","sourceRoot":"","sources":["../../../src/components/ai/translate-document-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,cA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CAAC,CACrB,8BACE,KAAC,MAAM,IAAC,OAAO,EAAC,OAAO,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,KAAK,YAC7C,SAAS,CAAC,eAAe,CAAC,GACpB,EACT,MAAC,MAAM,IAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,EAAE,iBAAc,mBAAmB,aAC1E,KAAC,SAAS,KAAG,OAAE,SAAS,CAAC,sBAAsB,CAAC,IACzC,IACR,CACJ,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CACxB,KAAC,MAAM,IAAC,OAAO,EAAC,SAAS,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAc,kBAAkB,YACzG,SAAS,CAAC,eAAe,CAAC,GACpB,CACV,CAAC,CAAC,CAAC,CACF,KAAC,MAAM,IAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,KAAK,iBAAc,iBAAiB,YAC5D,SAAS,CAAC,oBAAoB,CAAC,GACzB,CACV,GACY,IACD,GACT,CACV,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { createCollectionRegistry } from '@elytracms/core/cms-core'\nimport { Check, Languages, Loader2, X } from 'lucide-react'\nimport {\n Badge,\n Button,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Row,\n Stack,\n Text,\n} from '@elytracms/studio/ui'\nimport { translate } from '../../lib/i18n'\nimport { localeChipLabel } from '../../lib/locale'\nimport { getStudioOperations } from '../../lib/operations'\nimport { resolveDeploymentAi } from '../../lib/workspace'\nimport { resolveAiConfig, resolveKnowledge, translateDocument } from '../../lib/ai'\nimport type { TranslateProgress, TranslateSkip } from '../../lib/ai'\nimport { cmsValidationIssueMessage } from '../../lib/persona/labels'\nimport { useCms } from '../cms/cms-store'\nimport type { TranslateDocumentActionProps } from './translate-document-action'\nimport { TranslateSkipped } from './translate-skipped'\n\n/**\n * The \"Translate document\" confirm + progress dialog (EC-332), heavy side — loaded lazily\n * by the gate so the AI engine stays off the critical path (EC-331 bundle discipline). A\n * modal is allowed here (a picker/confirmation, per the house rule — property forms are\n * not). It resolves the EC-331 provider + knowledge, runs the ONE `translateDocument`\n * engine over the live draft (fill-empty-only on EC-318 connection state), streams\n * progress, then writes the result to the DRAFT via the operations layer with a\n * provenance-tagged snapshot (mirroring the EC-199 apply) and reflects it into the open\n * editor. Cancel aborts cleanly — any already-translated units stay on the draft, visible\n * in Compare (EC-317) and rejectable via Discard (EC-316).\n */\ntype Phase = 'confirm' | 'running' | 'done' | 'error'\n\ninterface RunSummary {\n translated: number\n slugs: number\n locales: number\n cancelled: boolean\n nothing: boolean\n /** EC-593: every text position the run could not translate — listed, never silent. */\n skipped: readonly TranslateSkip[]\n}\n\nexport function TranslateDocumentDialog({\n projectId,\n collection,\n docRef,\n document,\n revision,\n localeConfig,\n flushDraft,\n open,\n onOpenChange,\n}: TranslateDocumentActionProps & { open: boolean; onOpenChange: (open: boolean) => void }) {\n const [phase, setPhase] = useState<Phase>('confirm')\n const [progress, setProgress] = useState<TranslateProgress | null>(null)\n const [summary, setSummary] = useState<RunSummary | null>(null)\n /**\n * EC-497 — why the refusal was blocked, when the gate refused. Reuses the\n * EC-473 `ai.error.applyInvalid` copy (\"the proposal no longer fits the current\n * document: …\"), which is exactly this situation: no new catalog string, and the\n * editor is told WHICH rules the translation would have broken rather than a bare\n * \"failed\".\n */\n const [refusal, setRefusal] = useState<string | null>(null)\n const abortRef = useRef<AbortController | null>(null)\n const cms = useCms()\n // The session registry the produced draft is judged against. Built here rather\n // than added to the CMS store's public surface for one consumer; the memo means\n // once per open, not once per render.\n const registry = useMemo(() => createCollectionRegistry(cms.collections), [cms.collections])\n\n useEffect(() => () => abortRef.current?.abort(), [])\n\n const base = localeConfig.default\n const targets = localeConfig.locales.filter((l) => l !== base)\n\n const run = useCallback(async () => {\n if (projectId === undefined) {\n setPhase('error')\n return\n }\n const resolved = resolveAiConfig(resolveDeploymentAi())\n const provider = resolved.resolved?.provider\n if (!provider || !resolved.ok) {\n setPhase('error')\n return\n }\n const controller = new AbortController()\n abortRef.current = controller\n setRefusal(null)\n setPhase('running')\n await flushDraft()\n setProgress({ completed: 0, total: 0 })\n try {\n const knowledge = await resolveKnowledge(resolved.resolved?.knowledge ?? [])\n const result = await translateDocument({\n provider,\n collection,\n document,\n localeConfig,\n knowledge,\n signal: controller.signal,\n onProgress: setProgress,\n // EC-497 — this action used to hand `translateDocument`'s output STRAIGHT to\n // `documents.upsert` with nothing in between: no gate, no proposal card, no\n // re-validation, so model-generated content reached the document completely\n // unvalidated while the chat path validated twice. It now validates with the\n // session's canonical bag (`cms.validateOptions`) — the editor's own rules —\n // and refuses below on what the translation INTRODUCED.\n registry,\n validateOptions: cms.validateOptions,\n })\n if (result.introducedErrors.length > 0) {\n setRefusal(\n translate('ai.error.applyInvalid', {\n issues: result.introducedErrors\n .slice(0, 3)\n .map((issue) => cmsValidationIssueMessage(issue))\n .join('; '),\n }),\n )\n setPhase('error')\n return\n }\n if (result.translated > 0 || result.slugsDerived > 0) {\n // EC-595 A2: the translation persists as the patches of the buckets it filled\n // (never the whole document) — through the session's queue, at the revision\n // the draft it was authored on is at (EC-647); a bucket a colleague changed\n // meanwhile is refused on that field and shown there.\n const outcome = await cms.commitPatches(\n docRef,\n result.patches,\n result.patches.map(() => revision),\n )\n if (outcome?.status === 'failed') {\n setPhase('error')\n return\n }\n const { operations } = await getStudioOperations()\n // Provenance: an AI-tagged version snapshot (best-effort — the draft already landed).\n try {\n await operations.documents.snapshot({\n projectId,\n ref: docRef,\n label: translate('cms.version.aiAuthoredTitle'),\n origin: 'assistant',\n })\n } catch {\n // ignore — provenance is additive\n }\n }\n setSummary({\n translated: result.translated,\n slugs: result.slugsDerived,\n locales: Object.keys(result.perLocale).length,\n cancelled: result.cancelled,\n nothing: result.total === 0 && result.skipped.length === 0,\n skipped: result.skipped,\n })\n setPhase('done')\n } catch {\n setPhase('error')\n } finally {\n abortRef.current = null\n }\n }, [projectId, collection, document, revision, localeConfig, docRef, flushDraft, registry, cms])\n\n const close = () => {\n if (phase === 'running') return // never close mid-run — Cancel aborts instead\n onOpenChange(false)\n }\n\n const doneMessage = (s: RunSummary): string => {\n if (s.nothing) return translate('ai.translate.nothing')\n if (s.cancelled) return translate('ai.translate.cancelled')\n return translate('ai.translate.applied', { count: s.translated, locales: s.locales })\n }\n\n return (\n <Dialog open={open} onOpenChange={(next) => (!next ? close() : undefined)}>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>\n <Row gap=\"2\" align=\"center\">\n <Languages className=\"size-4\" /> {translate('ai.translate.dialogTitle')}\n </Row>\n </DialogTitle>\n <DialogDescription>\n {translate('ai.translate.dialogDescription', { base: localeChipLabel(base) })}\n </DialogDescription>\n </DialogHeader>\n\n {phase === 'confirm' ? (\n <Stack gap=\"4\" className=\"py-2\">\n <Stack gap=\"1\">\n <Text size=\"xs\" weight=\"medium\" tone=\"muted\">\n {translate('ai.translate.targetsLabel')}\n </Text>\n <Row gap=\"1\" wrap>\n {targets.map((l) => (\n <Badge key={l} variant=\"outline\">\n {localeChipLabel(l)}\n </Badge>\n ))}\n </Row>\n </Stack>\n <Stack gap=\"1\">\n <Text size=\"xs\" weight=\"medium\" tone=\"muted\">\n {translate('ai.translate.scopeLabel')}\n </Text>\n <Row gap=\"2\" align=\"center\">\n <Badge variant=\"default\">{translate('ai.translate.fillMissing')}</Badge>\n <Button size=\"sm\" variant=\"ghost\" disabled title={translate('ai.translate.retranslateSoon')}>\n {translate('ai.translate.retranslateAll')}\n </Button>\n <Text size=\"xs\" tone=\"muted\">\n {translate('ai.translate.retranslateSoon')}\n </Text>\n </Row>\n </Stack>\n </Stack>\n ) : null}\n\n {phase === 'running' ? (\n <Stack gap=\"3\" align=\"center\" className=\"py-6\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n <Text size=\"sm\" tone=\"muted\" data-testid=\"translate-progress\">\n {progress && progress.total > 0\n ? translate('ai.translate.progress', { completed: progress.completed, total: progress.total })\n : translate('ai.translate.preparing')}\n </Text>\n {progress && progress.total > 0 ? (\n <div className=\"h-1.5 w-56 overflow-hidden rounded-full bg-muted\">\n <div\n className=\"h-full rounded-full bg-primary transition-all\"\n style={{ width: `${Math.round((progress.completed / progress.total) * 100)}%` }}\n />\n </div>\n ) : null}\n </Stack>\n ) : null}\n\n {phase === 'done' && summary ? (\n <Stack gap=\"2\" align=\"center\" className=\"py-6\">\n <Check className=\"size-6 text-success\" />\n <Text size=\"sm\" tone=\"muted\" className=\"text-center\" data-testid=\"translate-summary\">\n {doneMessage(summary)}\n </Text>\n <TranslateSkipped skipped={summary.skipped} collection={collection} />\n </Stack>\n ) : null}\n\n {phase === 'error' ? (\n <Stack gap=\"2\" align=\"center\" className=\"py-6\">\n <X className=\"size-6 text-destructive\" />\n <Text size=\"sm\" tone=\"muted\" className=\"text-center\" data-testid=\"translate-error\">\n {refusal ?? translate('ai.translate.failed')}\n </Text>\n </Stack>\n ) : null}\n\n <DialogFooter className=\"mt-2\">\n {phase === 'confirm' ? (\n <>\n <Button variant=\"ghost\" size=\"sm\" onClick={close}>\n {translate('common.cancel')}\n </Button>\n <Button size=\"sm\" onClick={() => void run()} data-testid=\"translate-confirm\">\n <Languages /> {translate('ai.translate.confirm')}\n </Button>\n </>\n ) : phase === 'running' ? (\n <Button variant=\"outline\" size=\"sm\" onClick={() => abortRef.current?.abort()} data-testid=\"translate-cancel\">\n {translate('common.cancel')}\n </Button>\n ) : (\n <Button size=\"sm\" onClick={close} data-testid=\"translate-close\">\n {translate('ai.translate.close')}\n </Button>\n )}\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"translate-document-dialog.js","sourceRoot":"","sources":["../../../src/components/ai/translate-document-dialog.tsx"],"names":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AAmB,IAClB,KAAK,EAAE,SAAS,CAAC,2BAA2B,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAChF,OAAO,EAAE,OAAO,CAAC,OAAO,EACxB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAC,mBAAmB,GAC1B,EACF,KAAC,mBAAmB,IAClB,KAAK,EAAE,SAAS,CAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,EAClE,OAAO,EAAE,IAAI,EACb,UAAU,EAAE,UAAU,EACtB,MAAM,EAAC,gBAAgB,GACvB,EACD,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,CACpC,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,iBAAa,yBAAyB,YAC/D,SAAS,CAAC,2BAA2B,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,GACrE,CACR,CAAC,CAAC,CAAC,IAAI,EACR,KAAC,gBAAgB,IAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,GAAI,IACpF,CACT,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { createCollectionRegistry } from '@elytracms/core/cms-core'\nimport type { CollectionDef, Locale } from '@elytracms/core/cms-core'\nimport { Check, Languages, Loader2, X } from 'lucide-react'\nimport {\n Badge,\n Button,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Row,\n SegmentedControl,\n Stack,\n Text,\n} from '@elytracms/studio/ui'\nimport { translate } from '../../lib/i18n'\nimport { localeChipLabel } from '../../lib/locale'\nimport { getStudioOperations } from '../../lib/operations'\nimport { resolveDeploymentAi } from '../../lib/workspace'\nimport { planTranslation, resolveAiConfig, resolveKnowledge, translateDocument } from '../../lib/ai'\nimport type { TranslateMode, TranslatePlan, TranslateProgress, TranslateSkip, TranslateWrite } from '../../lib/ai'\nimport { applyTranslation } from '../../lib/ai/translate-apply'\nimport { cmsValidationIssueMessage } from '../../lib/persona/labels'\nimport { useCms } from '../cms/cms-store'\nimport type { TranslateDocumentActionProps } from './translate-document-action'\nimport { TranslateBucketList, TranslateSkipped } from './translate-skipped'\n\n/**\n * The \"Translate document\" confirm + progress dialog (EC-332), heavy side — loaded lazily\n * by the gate so the AI engine stays off the critical path (EC-331 bundle discipline). A\n * modal is allowed here (a picker/confirmation, per the house rule — property forms are\n * not). It resolves the EC-331 provider + knowledge, runs the ONE `translateDocument`\n * engine over the live draft, streams progress, then writes the result to the DRAFT via\n * the session (`applyTranslation`) and reflects it into the open editor.\n *\n * The scope is a choice (EC-752): **Fill missing** (the default — only values still\n * connected to the base, EC-318; nothing is overwritten) or **Re-translate everything**,\n * which also REPLACES values with their own translation. Choosing it shows the run's own\n * pre-provider plan (`planTranslation` — what it replaces, fills and leaves as it is), and\n * running it takes the deliberate \"Re-translate and replace\". It snapshots the draft as a\n * labelled version BEFORE writing, so Versions brings any replaced value back; it never\n * touches a slug the editor set and writes a value only whole. The done summary reports\n * what was actually written.\n *\n * Cancel aborts cleanly: fill-empty keeps the already-translated units on the draft;\n * re-translate keeps only values whose every unit landed. Either way the result is visible\n * in Compare (EC-317).\n */\ntype Phase = 'confirm' | 'running' | 'done' | 'error'\n\n/** What the done phase reports — what the run actually wrote, against what it planned. */\nexport interface TranslateRunSummary {\n mode: TranslateMode\n plan: TranslatePlan\n /** Units translated (the fill message's count). */\n translated: number\n locales: number\n cancelled: boolean\n /** EC-752: the writes that landed (a write refused at its revision is in {@link refused}). */\n writes: readonly TranslateWrite[]\n refused: readonly TranslateWrite[]\n /** EC-752: the version saved before a re-translation wrote. */\n restorePoint?: number\n /** EC-593: every text position the run could not translate — listed, never silent. */\n skipped: readonly TranslateSkip[]\n}\n\nexport function TranslateDocumentDialog({\n projectId,\n collection,\n docRef,\n document,\n revision,\n localeConfig,\n flushDraft,\n open,\n onOpenChange,\n}: TranslateDocumentActionProps & { open: boolean; onOpenChange: (open: boolean) => void }) {\n const [phase, setPhase] = useState<Phase>('confirm')\n const [mode, setMode] = useState<TranslateMode>('fill-empty')\n const [progress, setProgress] = useState<TranslateProgress | null>(null)\n const [summary, setSummary] = useState<TranslateRunSummary | null>(null)\n /**\n * EC-497 — why the refusal was blocked, when the gate refused. Reuses the\n * EC-473 `ai.error.applyInvalid` copy (\"the proposal no longer fits the current\n * document: …\"), which is exactly this situation: no new catalog string, and the\n * editor is told WHICH rules the translation would have broken rather than a bare\n * \"failed\". EC-752: also why a re-translation wrote nothing (no restore point).\n */\n const [refusal, setRefusal] = useState<string | null>(null)\n const abortRef = useRef<AbortController | null>(null)\n const cms = useCms()\n // The session registry the produced draft is judged against. Built here rather\n // than added to the CMS store's public surface for one consumer; the memo means\n // once per open, not once per render.\n const registry = useMemo(() => createCollectionRegistry(cms.collections), [cms.collections])\n\n useEffect(() => () => abortRef.current?.abort(), [])\n\n const base = localeConfig.default\n const targets = localeConfig.locales.filter((l) => l !== base)\n // EC-752 rule 4: the confirm lists the run's OWN plan — the same judge, on the same input.\n const plan = useMemo(\n () =>\n mode === 'retranslate-all'\n ? planTranslation({ collection, document, localeConfig, mode, validateOptions: cms.validateOptions })\n : null,\n [mode, collection, document, localeConfig, cms.validateOptions],\n )\n\n const run = useCallback(async () => {\n if (projectId === undefined) {\n setPhase('error')\n return\n }\n const resolved = resolveAiConfig(resolveDeploymentAi())\n const provider = resolved.resolved?.provider\n if (!provider || !resolved.ok) {\n setPhase('error')\n return\n }\n const controller = new AbortController()\n abortRef.current = controller\n setRefusal(null)\n setPhase('running')\n await flushDraft()\n setProgress({ completed: 0, total: 0 })\n try {\n const knowledge = await resolveKnowledge(resolved.resolved?.knowledge ?? [])\n const result = await translateDocument({\n provider,\n collection,\n document,\n localeConfig,\n mode,\n knowledge,\n signal: controller.signal,\n onProgress: setProgress,\n // EC-497 — this action used to hand `translateDocument`'s output STRAIGHT to\n // `documents.upsert` with nothing in between: no gate, no proposal card, no\n // re-validation, so model-generated content reached the document completely\n // unvalidated while the chat path validated twice. It now validates with the\n // session's canonical bag (`cms.validateOptions`) — the editor's own rules —\n // and refuses below on what the translation INTRODUCED.\n registry,\n validateOptions: cms.validateOptions,\n })\n if (result.introducedErrors.length > 0) {\n setRefusal(\n translate('ai.error.applyInvalid', {\n issues: result.introducedErrors\n .slice(0, 3)\n .map((issue) => cmsValidationIssueMessage(issue))\n .join('; '),\n }),\n )\n setPhase('error')\n return\n }\n const { operations } = await getStudioOperations()\n // EC-752 rule 3 (in `applyTranslation`): a re-translation records a labelled restore\n // point of the stored draft BEFORE it writes; then the patches go through the session's\n // queue at the revision the draft was authored on (EC-595 A2 / EC-647 — a bucket a\n // colleague changed meanwhile is refused on that field and shown there); then the\n // AI-provenance snapshot.\n const applied = await applyTranslation(\n result,\n {\n commit: (patches) => cms.commitPatches(docRef, patches, patches.map(() => revision)),\n snapshot: async ({ label, origin }) => {\n const recorded = await operations.documents.snapshot({\n projectId,\n ref: docRef,\n label,\n ...(origin ? { origin } : {}),\n })\n if (!recorded.ok) throw new Error(recorded.error.message)\n return recorded.value\n },\n },\n { restorePoint: translate('ai.translate.snapshotLabel'), provenance: translate('cms.version.aiAuthoredTitle') },\n )\n if (applied.status === 'snapshot-failed') {\n setRefusal(translate('ai.translate.snapshotFailed'))\n setPhase('error')\n return\n }\n if (applied.status === 'failed') {\n setPhase('error')\n return\n }\n setSummary({\n mode,\n plan: result.plan,\n translated: result.translated,\n locales: Object.keys(result.perLocale).length,\n cancelled: result.cancelled,\n writes: applied.writes,\n refused: applied.refused,\n ...(applied.restorePoint !== undefined ? { restorePoint: applied.restorePoint } : {}),\n skipped: result.skipped,\n })\n setPhase('done')\n } catch {\n setPhase('error')\n } finally {\n abortRef.current = null\n }\n }, [projectId, collection, document, revision, localeConfig, mode, docRef, flushDraft, registry, cms])\n\n const close = () => {\n if (phase === 'running') return // never close mid-run — Cancel aborts instead\n onOpenChange(false)\n }\n\n const replaces = (plan?.buckets ?? []).some((bucket) => bucket.kind === 'replace')\n\n return (\n <Dialog open={open} onOpenChange={(next) => (!next ? close() : undefined)}>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>\n <Row gap=\"2\" align=\"center\">\n <Languages className=\"size-4\" /> {translate('ai.translate.dialogTitle')}\n </Row>\n </DialogTitle>\n <DialogDescription>\n {translate('ai.translate.dialogDescription', { base: localeChipLabel(base) })}\n </DialogDescription>\n </DialogHeader>\n\n {phase === 'confirm' ? (\n <TranslateConfirm\n mode={mode}\n onModeChange={setMode}\n base={base}\n targets={targets}\n plan={plan}\n collection={collection}\n />\n ) : null}\n\n {phase === 'running' ? (\n <Stack gap=\"3\" align=\"center\" className=\"py-6\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n <Text size=\"sm\" tone=\"muted\" data-testid=\"translate-progress\">\n {progress && progress.total > 0\n ? translate('ai.translate.progress', { completed: progress.completed, total: progress.total })\n : translate('ai.translate.preparing')}\n </Text>\n {progress && progress.total > 0 ? (\n <div className=\"h-1.5 w-56 overflow-hidden rounded-full bg-muted\">\n <div\n className=\"h-full rounded-full bg-primary transition-all\"\n style={{ width: `${Math.round((progress.completed / progress.total) * 100)}%` }}\n />\n </div>\n ) : null}\n </Stack>\n ) : null}\n\n {phase === 'done' && summary ? (\n <Stack gap=\"2\" align=\"center\" className=\"py-6\">\n <Check className=\"size-6 text-success\" />\n <TranslateDoneSummary summary={summary} base={base} collection={collection} />\n </Stack>\n ) : null}\n\n {phase === 'error' ? (\n <Stack gap=\"2\" align=\"center\" className=\"py-6\">\n <X className=\"size-6 text-destructive\" />\n <Text size=\"sm\" tone=\"muted\" className=\"text-center\" data-testid=\"translate-error\">\n {refusal ?? translate('ai.translate.failed')}\n </Text>\n </Stack>\n ) : null}\n\n <DialogFooter className=\"mt-2\">\n {phase === 'confirm' ? (\n <>\n <Button variant=\"ghost\" size=\"sm\" onClick={close}>\n {translate('common.cancel')}\n </Button>\n {mode === 'retranslate-all' && replaces ? (\n // EC-752: the deliberate confirm — the button says what it does.\n <Button size=\"sm\" variant=\"destructive\" onClick={() => void run()} data-testid=\"translate-confirm\">\n <Languages /> {translate('ai.translate.confirmReplace')}\n </Button>\n ) : (\n <Button size=\"sm\" onClick={() => void run()} data-testid=\"translate-confirm\">\n <Languages /> {translate('ai.translate.confirm')}\n </Button>\n )}\n </>\n ) : phase === 'running' ? (\n <Button variant=\"outline\" size=\"sm\" onClick={() => abortRef.current?.abort()} data-testid=\"translate-cancel\">\n {translate('common.cancel')}\n </Button>\n ) : (\n <Button size=\"sm\" onClick={close} data-testid=\"translate-close\">\n {translate('ai.translate.close')}\n </Button>\n )}\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n\n/**\n * EC-752 — the confirm phase: the target languages, the scope choice and, for a\n * re-translation, its plan (what it replaces, fills and leaves as it is — \"up to\").\n */\nexport function TranslateConfirm({\n mode,\n onModeChange,\n base,\n targets,\n plan,\n collection,\n}: {\n mode: TranslateMode\n onModeChange: (mode: TranslateMode) => void\n base: Locale\n targets: readonly Locale[]\n /** The run's plan — present in `retranslate-all`. */\n plan: TranslatePlan | null\n collection: CollectionDef\n}) {\n const baseLabel = localeChipLabel(base)\n return (\n <Stack gap=\"4\" className=\"py-2\">\n <Stack gap=\"1\">\n <Text size=\"xs\" weight=\"medium\" tone=\"muted\">\n {translate('ai.translate.targetsLabel')}\n </Text>\n <Row gap=\"1\" wrap>\n {targets.map((l) => (\n <Badge key={l} variant=\"outline\">\n {localeChipLabel(l)}\n </Badge>\n ))}\n </Row>\n </Stack>\n <Stack gap=\"1\">\n <Text size=\"xs\" weight=\"medium\" tone=\"muted\">\n {translate('ai.translate.scopeLabel')}\n </Text>\n <SegmentedControl\n ariaLabel={translate('ai.translate.scopeLabel')}\n testId=\"translate-scope\"\n items={[\n {\n key: 'fill-empty',\n label: translate('ai.translate.fillMissing'),\n active: mode === 'fill-empty',\n onClick: () => onModeChange('fill-empty'),\n testId: 'translate-scope-fill',\n },\n {\n key: 'retranslate-all',\n label: translate('ai.translate.retranslateAll'),\n active: mode === 'retranslate-all',\n onClick: () => onModeChange('retranslate-all'),\n testId: 'translate-scope-retranslate',\n },\n ]}\n />\n <Text size=\"xs\" tone=\"muted\">\n {translate(mode === 'retranslate-all' ? 'ai.translate.retranslateHint' : 'ai.translate.fillMissingHint', {\n base: baseLabel,\n })}\n </Text>\n </Stack>\n {mode === 'retranslate-all' && plan ? <RetranslatePlan plan={plan} base={base} collection={collection} /> : null}\n </Stack>\n )\n}\n\n/** EC-752 rule 4 — what a re-translation will do, from its own pre-provider plan. */\nfunction RetranslatePlan({ plan, base, collection }: { plan: TranslatePlan; base: Locale; collection: CollectionDef }) {\n const baseLabel = localeChipLabel(base)\n const replace = plan.buckets.filter((bucket) => bucket.kind === 'replace')\n const fill = plan.buckets.filter((bucket) => bucket.kind === 'fill')\n return (\n <Stack gap=\"2\" data-testid=\"translate-plan\">\n {replace.length > 0 ? (\n <TranslateBucketList\n title={translate('ai.translate.planReplaceTitle', { base: baseLabel, count: replace.length })}\n buckets={replace}\n collection={collection}\n testId=\"translate-plan-replace\"\n />\n ) : (\n <Text size=\"xs\" tone=\"muted\">\n {translate('ai.translate.planReplaceNone')}\n </Text>\n )}\n <TranslateBucketList\n title={translate('ai.translate.planFillTitle', { base: baseLabel, count: fill.length })}\n buckets={fill}\n collection={collection}\n testId=\"translate-plan-fill\"\n />\n <TranslateSkipped\n skipped={plan.skipped}\n collection={collection}\n mode={plan.mode}\n title={translate('ai.translate.planKeptTitle', { count: plan.skipped.length })}\n />\n <Stack gap=\"px\">\n <Text size=\"xs\" tone=\"muted\">\n {translate('ai.translate.planWhole')}\n </Text>\n <Text size=\"xs\" tone=\"muted\">\n {translate('ai.translate.planSlugsKept')}\n </Text>\n {replace.length > 0 ? (\n <Text size=\"xs\" tone=\"muted\">\n {translate('ai.translate.planRestorePoint')}\n </Text>\n ) : null}\n </Stack>\n </Stack>\n )\n}\n\n/** The headline of the done phase (EC-752: mode-aware; slugs and replacements are listed below it). */\nexport function translateDoneMessage(summary: TranslateRunSummary, base: Locale): string {\n const retranslate = summary.mode === 'retranslate-all'\n const nothing =\n summary.plan.total === 0 && summary.skipped.length === 0 && summary.writes.length === 0 && summary.refused.length === 0\n if (nothing) {\n return retranslate\n ? translate('ai.translate.retranslateNothing', { base: localeChipLabel(base) })\n : translate('ai.translate.nothing')\n }\n if (summary.cancelled) return translate(retranslate ? 'ai.translate.retranslateCancelled' : 'ai.translate.cancelled')\n if (retranslate) return translate('ai.translate.retranslateDone')\n return translate('ai.translate.applied', { count: summary.translated, locales: summary.locales })\n}\n\n/**\n * EC-752 — the done phase: what was actually written (a re-translation lists what it\n * replaced and filled), the slugs it set, what was refused at its revision, what a\n * re-translation planned but left as it was, its restore point, and what was not translated.\n */\nexport function TranslateDoneSummary({\n summary,\n base,\n collection,\n}: {\n summary: TranslateRunSummary\n base: Locale\n collection: CollectionDef\n}) {\n const retranslate = summary.mode === 'retranslate-all'\n const of = (kind: TranslateWrite['kind']) => summary.writes.filter((write) => write.kind === kind)\n const done = (bucket: { field: string; locale: string }) =>\n [...summary.writes, ...summary.refused].some((write) => write.field === bucket.field && write.locale === bucket.locale)\n const kept = retranslate ? summary.plan.buckets.filter((bucket) => !done(bucket)) : []\n return (\n <Stack gap=\"2\" className=\"w-full\">\n <Text size=\"sm\" tone=\"muted\" className=\"text-center\" data-testid=\"translate-summary\">\n {translateDoneMessage(summary, base)}\n </Text>\n {retranslate ? (\n <>\n <TranslateBucketList\n title={translate('ai.translate.replacedTitle', { count: of('replace').length })}\n buckets={of('replace')}\n collection={collection}\n testId=\"translate-replaced\"\n />\n <TranslateBucketList\n title={translate('ai.translate.filledTitle', { count: of('fill').length })}\n buckets={of('fill')}\n collection={collection}\n testId=\"translate-filled\"\n />\n </>\n ) : null}\n <TranslateBucketList\n title={translate('ai.translate.slugsTitle', { count: of('slug').length })}\n buckets={of('slug')}\n collection={collection}\n testId=\"translate-slugs\"\n />\n <TranslateBucketList\n title={translate('ai.translate.refusedTitle', { count: summary.refused.length })}\n buckets={summary.refused}\n collection={collection}\n testId=\"translate-refused\"\n />\n <TranslateBucketList\n title={translate('ai.translate.keptTitle', { count: kept.length })}\n buckets={kept}\n collection={collection}\n testId=\"translate-kept\"\n />\n {summary.restorePoint !== undefined ? (\n <Text size=\"xs\" tone=\"muted\" data-testid=\"translate-restore-point\">\n {translate('ai.translate.restorePoint', { version: summary.restorePoint })}\n </Text>\n ) : null}\n <TranslateSkipped skipped={summary.skipped} collection={collection} mode={summary.mode} />\n </Stack>\n )\n}\n"]}
|
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
import type { CollectionDef } from '@elytracms/core/cms-core';
|
|
2
|
-
import type { TranslateSkip } from '../../lib/ai/index.js';
|
|
2
|
+
import type { TranslateBucket, TranslateMode, TranslateSkip } from '../../lib/ai/index.js';
|
|
3
3
|
/** One skip as the editor reads it: where (field label › component › position), which language, why. */
|
|
4
4
|
export interface TranslateSkipLine {
|
|
5
5
|
where: string;
|
|
6
6
|
locale: string;
|
|
7
7
|
reason: string;
|
|
8
8
|
}
|
|
9
|
+
/** EC-752 — a field × locale value as the editor reads it: `Title (DE)`. */
|
|
10
|
+
export declare function translateBucketLabel(bucket: TranslateBucket, collection: CollectionDef | undefined): string;
|
|
9
11
|
/**
|
|
10
12
|
* The where-label of a skipped position: the field's label, then — inside a component —
|
|
11
13
|
* the component and its prop path, else the position below the field (an item counted
|
|
12
14
|
* from 1). Index-bearing segments the editor does not see (`content`, `props`) are left out.
|
|
13
15
|
*/
|
|
14
|
-
export declare function translateSkipLines(skipped: readonly TranslateSkip[], collection: CollectionDef | undefined): TranslateSkipLine[];
|
|
16
|
+
export declare function translateSkipLines(skipped: readonly TranslateSkip[], collection: CollectionDef | undefined, mode?: TranslateMode): TranslateSkipLine[];
|
|
15
17
|
/** The list; renders nothing when everything was translated. */
|
|
16
|
-
export declare function TranslateSkipped({ skipped, collection, }: {
|
|
18
|
+
export declare function TranslateSkipped({ skipped, collection, mode, title, }: {
|
|
17
19
|
skipped: readonly TranslateSkip[];
|
|
18
20
|
collection: CollectionDef | undefined;
|
|
21
|
+
/** EC-752: the run's mode — a re-translation's reasons say the whole value was left as it was. */
|
|
22
|
+
mode?: TranslateMode;
|
|
23
|
+
/** EC-752: the heading (default "Not translated (n)"); the confirm names what it will leave as it is. */
|
|
24
|
+
title?: string;
|
|
25
|
+
}): import("react").JSX.Element | null;
|
|
26
|
+
/**
|
|
27
|
+
* EC-752 — a list of field × locale values under a heading (what a re-translation replaces,
|
|
28
|
+
* fills, set as slugs or left as it was); renders nothing for an empty list.
|
|
29
|
+
*/
|
|
30
|
+
export declare function TranslateBucketList({ title, buckets, collection, testId, }: {
|
|
31
|
+
title: string;
|
|
32
|
+
buckets: readonly TranslateBucket[];
|
|
33
|
+
collection: CollectionDef | undefined;
|
|
34
|
+
testId: string;
|
|
19
35
|
}): import("react").JSX.Element | null;
|
|
@@ -9,6 +9,9 @@ import { localeChipLabel } from '../../lib/locale/index.js';
|
|
|
9
9
|
* editor reads the outcome: the "Translate document" dialog and the chat's translation
|
|
10
10
|
* proposal card. Before, a localized object or composition was skipped with no word,
|
|
11
11
|
* and a garbled rich-text block silently kept its original.
|
|
12
|
+
*
|
|
13
|
+
* EC-752 — the reason is MODE-aware: a re-translation writes a value whole or not at all,
|
|
14
|
+
* so its reasons say the whole value was left as it was (fill-empty fills the rest).
|
|
12
15
|
*/
|
|
13
16
|
const REASON_KEY = {
|
|
14
17
|
unreadable: 'ai.translate.skipped.unreadable',
|
|
@@ -16,15 +19,29 @@ const REASON_KEY = {
|
|
|
16
19
|
'structure-changed': 'ai.translate.skipped.structureChanged',
|
|
17
20
|
locked: 'ai.translate.skipped.locked',
|
|
18
21
|
};
|
|
22
|
+
const RETRANSLATE_REASON_KEY = {
|
|
23
|
+
unreadable: 'ai.translate.skipped.retranslate.unreadable',
|
|
24
|
+
'not-returned': 'ai.translate.skipped.retranslate.notReturned',
|
|
25
|
+
'structure-changed': 'ai.translate.skipped.retranslate.structureChanged',
|
|
26
|
+
locked: 'ai.translate.skipped.locked',
|
|
27
|
+
};
|
|
28
|
+
/** A top-level field's label as the editor reads it (its form label, else its name). */
|
|
29
|
+
function fieldLabel(fieldName, collection) {
|
|
30
|
+
const field = collection?.fields.find((f) => f.name === fieldName);
|
|
31
|
+
return resolveLabel(field?.form?.label) ?? fieldName;
|
|
32
|
+
}
|
|
33
|
+
/** EC-752 — a field × locale value as the editor reads it: `Title (DE)`. */
|
|
34
|
+
export function translateBucketLabel(bucket, collection) {
|
|
35
|
+
return `${fieldLabel(bucket.field, collection)} (${localeChipLabel(bucket.locale)})`;
|
|
36
|
+
}
|
|
19
37
|
/**
|
|
20
38
|
* The where-label of a skipped position: the field's label, then — inside a component —
|
|
21
39
|
* the component and its prop path, else the position below the field (an item counted
|
|
22
40
|
* from 1). Index-bearing segments the editor does not see (`content`, `props`) are left out.
|
|
23
41
|
*/
|
|
24
|
-
export function translateSkipLines(skipped, collection) {
|
|
42
|
+
export function translateSkipLines(skipped, collection, mode = 'fill-empty') {
|
|
43
|
+
const reasons = mode === 'retranslate-all' ? RETRANSLATE_REASON_KEY : REASON_KEY;
|
|
25
44
|
return skipped.map((skip) => {
|
|
26
|
-
const field = collection?.fields.find((f) => f.name === skip.field);
|
|
27
|
-
const label = resolveLabel(field?.form?.label) ?? skip.field;
|
|
28
45
|
const below = skip.component
|
|
29
46
|
? [skip.component.componentId, ...skip.at.slice(skip.at.lastIndexOf('props') + 1)]
|
|
30
47
|
: skip.at;
|
|
@@ -32,16 +49,25 @@ export function translateSkipLines(skipped, collection) {
|
|
|
32
49
|
.filter((segment) => segment !== 'content' && segment !== 'props')
|
|
33
50
|
.map((segment) => (typeof segment === 'number' ? `#${segment + 1}` : segment));
|
|
34
51
|
return {
|
|
35
|
-
where: [
|
|
52
|
+
where: [fieldLabel(skip.field, collection), ...segments].join(' › '),
|
|
36
53
|
locale: localeChipLabel(skip.locale),
|
|
37
|
-
reason: translate(
|
|
54
|
+
reason: translate(reasons[skip.reason]),
|
|
38
55
|
};
|
|
39
56
|
});
|
|
40
57
|
}
|
|
41
58
|
/** The list; renders nothing when everything was translated. */
|
|
42
|
-
export function TranslateSkipped({ skipped, collection, }) {
|
|
59
|
+
export function TranslateSkipped({ skipped, collection, mode = 'fill-empty', title, }) {
|
|
43
60
|
if (skipped.length === 0)
|
|
44
61
|
return null;
|
|
45
|
-
return (_jsxs(Stack, { gap: "1", "data-testid": "translate-skipped", children: [_jsxs(Row, { gap: "1", align: "center", children: [_jsx(AlertTriangle, { className: "size-3.5 text-warning" }), _jsx(Text, { size: "xs", weight: "medium", children: translate('ai.translate.skippedTitle', { count: skipped.length }) })] }), translateSkipLines(skipped, collection).map((line, index) => (_jsxs(Text, { size: "xs", tone: "muted", "data-translate-skip": true, children: [line.where, " (", line.locale, ") \u2014 ", line.reason] }, index)))] }));
|
|
62
|
+
return (_jsxs(Stack, { gap: "1", "data-testid": "translate-skipped", children: [_jsxs(Row, { gap: "1", align: "center", children: [_jsx(AlertTriangle, { className: "size-3.5 text-warning" }), _jsx(Text, { size: "xs", weight: "medium", children: title ?? translate('ai.translate.skippedTitle', { count: skipped.length }) })] }), translateSkipLines(skipped, collection, mode).map((line, index) => (_jsxs(Text, { size: "xs", tone: "muted", "data-translate-skip": true, children: [line.where, " (", line.locale, ") \u2014 ", line.reason] }, index)))] }));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* EC-752 — a list of field × locale values under a heading (what a re-translation replaces,
|
|
66
|
+
* fills, set as slugs or left as it was); renders nothing for an empty list.
|
|
67
|
+
*/
|
|
68
|
+
export function TranslateBucketList({ title, buckets, collection, testId, }) {
|
|
69
|
+
if (buckets.length === 0)
|
|
70
|
+
return null;
|
|
71
|
+
return (_jsxs(Stack, { gap: "1", "data-testid": testId, children: [_jsx(Text, { size: "xs", weight: "medium", children: title }), _jsx(Text, { size: "xs", tone: "muted", "data-translate-buckets": true, children: buckets.map((bucket) => translateBucketLabel(bucket, collection)).join(', ') })] }));
|
|
46
72
|
}
|
|
47
73
|
//# sourceMappingURL=translate-skipped.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate-skipped.js","sourceRoot":"","sources":["../../../src/components/ai/translate-skipped.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAGlD
|
|
1
|
+
{"version":3,"file":"translate-skipped.js","sourceRoot":"","sources":["../../../src/components/ai/translate-skipped.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAGlD;;;;;;;;GAQG;AAEH,MAAM,UAAU,GAAwC;IACtD,UAAU,EAAE,iCAAiC;IAC7C,cAAc,EAAE,kCAAkC;IAClD,mBAAmB,EAAE,uCAAuC;IAC5D,MAAM,EAAE,6BAA6B;CACtC,CAAA;AAED,MAAM,sBAAsB,GAAwC;IAClE,UAAU,EAAE,6CAA6C;IACzD,cAAc,EAAE,8CAA8C;IAC9D,mBAAmB,EAAE,mDAAmD;IACxE,MAAM,EAAE,6BAA6B;CACtC,CAAA;AASD,w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,mBAAmB,CAAC,EAClC,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,GAMP;IACC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACrC,OAAO,CACL,MAAC,KAAK,IAAC,GAAG,EAAC,GAAG,iBAAc,MAAM,aAChC,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,QAAQ,YAC5B,KAAK,GACD,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,4CACzB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GACxE,IACD,CACT,CAAA;AACH,CAAC","sourcesContent":["import { resolveLabel } from '@elytracms/core/cms-core'\nimport type { CollectionDef } from '@elytracms/core/cms-core'\nimport { AlertTriangle } from 'lucide-react'\nimport { Row, Stack, Text } from '@elytracms/studio/ui'\nimport { translate } from '../../lib/i18n'\nimport { localeChipLabel } from '../../lib/locale'\nimport type { TranslateBucket, TranslateMode, TranslateSkip, TranslateSkipReason } from '../../lib/ai'\n\n/**\n * EC-593 (ratified 4e) — what a translation run could NOT translate, shown where the\n * editor reads the outcome: the \"Translate document\" dialog and the chat's translation\n * proposal card. Before, a localized object or composition was skipped with no word,\n * and a garbled rich-text block silently kept its original.\n *\n * EC-752 — the reason is MODE-aware: a re-translation writes a value whole or not at all,\n * so its reasons say the whole value was left as it was (fill-empty fills the rest).\n */\n\nconst REASON_KEY: Record<TranslateSkipReason, string> = {\n unreadable: 'ai.translate.skipped.unreadable',\n 'not-returned': 'ai.translate.skipped.notReturned',\n 'structure-changed': 'ai.translate.skipped.structureChanged',\n locked: 'ai.translate.skipped.locked',\n}\n\nconst RETRANSLATE_REASON_KEY: Record<TranslateSkipReason, string> = {\n unreadable: 'ai.translate.skipped.retranslate.unreadable',\n 'not-returned': 'ai.translate.skipped.retranslate.notReturned',\n 'structure-changed': 'ai.translate.skipped.retranslate.structureChanged',\n locked: 'ai.translate.skipped.locked',\n}\n\n/** One skip as the editor reads it: where (field label › component › position), which language, why. */\nexport interface TranslateSkipLine {\n where: string\n locale: string\n reason: string\n}\n\n/** A top-level field's label as the editor reads it (its form label, else its name). */\nfunction fieldLabel(fieldName: string, collection: CollectionDef | undefined): string {\n const field = collection?.fields.find((f) => f.name === fieldName)\n return resolveLabel(field?.form?.label) ?? fieldName\n}\n\n/** EC-752 — a field × locale value as the editor reads it: `Title (DE)`. */\nexport function translateBucketLabel(bucket: TranslateBucket, collection: CollectionDef | undefined): string {\n return `${fieldLabel(bucket.field, collection)} (${localeChipLabel(bucket.locale)})`\n}\n\n/**\n * The where-label of a skipped position: the field's label, then — inside a component —\n * the component and its prop path, else the position below the field (an item counted\n * from 1). Index-bearing segments the editor does not see (`content`, `props`) are left out.\n */\nexport function translateSkipLines(\n skipped: readonly TranslateSkip[],\n collection: CollectionDef | undefined,\n mode: TranslateMode = 'fill-empty',\n): TranslateSkipLine[] {\n const reasons = mode === 'retranslate-all' ? RETRANSLATE_REASON_KEY : REASON_KEY\n return skipped.map((skip) => {\n const below = skip.component\n ? [skip.component.componentId, ...skip.at.slice(skip.at.lastIndexOf('props') + 1)]\n : skip.at\n const segments = below\n .filter((segment) => segment !== 'content' && segment !== 'props')\n .map((segment) => (typeof segment === 'number' ? `#${segment + 1}` : segment))\n return {\n where: [fieldLabel(skip.field, collection), ...segments].join(' › '),\n locale: localeChipLabel(skip.locale),\n reason: translate(reasons[skip.reason]),\n }\n })\n}\n\n/** The list; renders nothing when everything was translated. */\nexport function TranslateSkipped({\n skipped,\n collection,\n mode = 'fill-empty',\n title,\n}: {\n skipped: readonly TranslateSkip[]\n collection: CollectionDef | undefined\n /** EC-752: the run's mode — a re-translation's reasons say the whole value was left as it was. */\n mode?: TranslateMode\n /** EC-752: the heading (default \"Not translated (n)\"); the confirm names what it will leave as it is. */\n title?: string\n}) {\n if (skipped.length === 0) return null\n return (\n <Stack gap=\"1\" data-testid=\"translate-skipped\">\n <Row gap=\"1\" align=\"center\">\n <AlertTriangle className=\"size-3.5 text-warning\" />\n <Text size=\"xs\" weight=\"medium\">\n {title ?? translate('ai.translate.skippedTitle', { count: skipped.length })}\n </Text>\n </Row>\n {translateSkipLines(skipped, collection, mode).map((line, index) => (\n <Text key={index} size=\"xs\" tone=\"muted\" data-translate-skip>\n {line.where} ({line.locale}) — {line.reason}\n </Text>\n ))}\n </Stack>\n )\n}\n\n/**\n * EC-752 — a list of field × locale values under a heading (what a re-translation replaces,\n * fills, set as slugs or left as it was); renders nothing for an empty list.\n */\nexport function TranslateBucketList({\n title,\n buckets,\n collection,\n testId,\n}: {\n title: string\n buckets: readonly TranslateBucket[]\n collection: CollectionDef | undefined\n testId: string\n}) {\n if (buckets.length === 0) return null\n return (\n <Stack gap=\"1\" data-testid={testId}>\n <Text size=\"xs\" weight=\"medium\">\n {title}\n </Text>\n <Text size=\"xs\" tone=\"muted\" data-translate-buckets>\n {buckets.map((bucket) => translateBucketLabel(bucket, collection)).join(', ')}\n </Text>\n </Stack>\n )\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { DocumentPatch, ValuePath } from '@elytracms/core/cms-core';
|
|
2
|
+
import type { TranslateDocumentResult, TranslateWrite } from './translate-document.js';
|
|
3
|
+
/**
|
|
4
|
+
* EC-752 — how a translation run's writes land, in order: the pure core of the "Translate
|
|
5
|
+
* document" dialog's apply (the dialog wires it to the session's commit queue and the
|
|
6
|
+
* `documents.snapshot` operation), so the order is pinned by a test, not by a component.
|
|
7
|
+
*
|
|
8
|
+
* Re-translate everything REPLACES values someone made, and the draft records no history of
|
|
9
|
+
* its own (versions are recorded on publish, snapshot and restore only), so an unpublished
|
|
10
|
+
* manual translation it replaced was unrecoverable — the dialog used to snapshot only AFTER
|
|
11
|
+
* its commit, a restore point holding the post-write state. Now:
|
|
12
|
+
*
|
|
13
|
+
* 1. `retranslate-all` with anything to write: a labelled snapshot of the stored draft
|
|
14
|
+
* FIRST — the restore point Versions / Compare's scoped restore brings a field back
|
|
15
|
+
* from. If it cannot be recorded, nothing is written (`snapshot-failed`): a
|
|
16
|
+
* re-translation never replaces what it could not save.
|
|
17
|
+
* 2. The patches, through the caller's commit (the session's queue, at the revision the
|
|
18
|
+
* draft was authored on — a position a colleague changed meanwhile is refused there).
|
|
19
|
+
* 3. The AI-provenance snapshot (best-effort, as before — the draft already landed).
|
|
20
|
+
*
|
|
21
|
+
* `fill-empty` is unchanged: it fills only values that followed the base, so it replaces
|
|
22
|
+
* nothing and takes no restore point.
|
|
23
|
+
*/
|
|
24
|
+
/** What the caller's commit reports — structurally the session's `CommitOutcome`. */
|
|
25
|
+
export type TranslateCommitOutcome = {
|
|
26
|
+
readonly status: 'applied';
|
|
27
|
+
} | {
|
|
28
|
+
readonly status: 'refused';
|
|
29
|
+
readonly conflicts: readonly {
|
|
30
|
+
readonly path: ValuePath;
|
|
31
|
+
}[];
|
|
32
|
+
} | {
|
|
33
|
+
readonly status: 'failed';
|
|
34
|
+
};
|
|
35
|
+
export interface TranslateApplyDeps {
|
|
36
|
+
/** Persist the run's patches; `undefined` when the session applied them locally (a fixture session). */
|
|
37
|
+
commit(patches: readonly DocumentPatch[]): Promise<TranslateCommitOutcome | undefined>;
|
|
38
|
+
/** Record the current stored draft as a version (`documents.snapshot`). */
|
|
39
|
+
snapshot(options: {
|
|
40
|
+
readonly label: string;
|
|
41
|
+
readonly origin?: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
readonly version: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export interface TranslateApplyLabels {
|
|
47
|
+
/** The restore point's label (taken before a re-translation writes). */
|
|
48
|
+
readonly restorePoint: string;
|
|
49
|
+
/** The provenance snapshot's label (taken after the write). */
|
|
50
|
+
readonly provenance: string;
|
|
51
|
+
}
|
|
52
|
+
export type TranslateApplyOutcome = {
|
|
53
|
+
readonly status: 'applied';
|
|
54
|
+
/** The writes that landed — the run's writes minus the ones refused at their revision. */
|
|
55
|
+
readonly writes: readonly TranslateWrite[];
|
|
56
|
+
/** Writes refused because a colleague changed the position meanwhile (shown as conflicts there). */
|
|
57
|
+
readonly refused: readonly TranslateWrite[];
|
|
58
|
+
/** The version recorded before a re-translation wrote — what Versions restores from. */
|
|
59
|
+
readonly restorePoint?: number;
|
|
60
|
+
}
|
|
61
|
+
/** `retranslate-all`: the restore point could not be recorded, so nothing was written. */
|
|
62
|
+
| {
|
|
63
|
+
readonly status: 'snapshot-failed';
|
|
64
|
+
}
|
|
65
|
+
/** The commit failed (transport, authorization): reported by the session too. */
|
|
66
|
+
| {
|
|
67
|
+
readonly status: 'failed';
|
|
68
|
+
};
|
|
69
|
+
export declare function applyTranslation(result: Pick<TranslateDocumentResult, 'plan' | 'writes' | 'patches'>, deps: TranslateApplyDeps, labels: TranslateApplyLabels): Promise<TranslateApplyOutcome>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const pathKey = (path) => JSON.stringify(path ?? null);
|
|
2
|
+
/** The position a field write's patch addresses (`set` / `unset` — the only kinds a translation emits). */
|
|
3
|
+
function patchPath(patch) {
|
|
4
|
+
return 'path' in patch ? patch.path : undefined;
|
|
5
|
+
}
|
|
6
|
+
export async function applyTranslation(result, deps, labels) {
|
|
7
|
+
if (result.writes.length === 0)
|
|
8
|
+
return { status: 'applied', writes: [], refused: [] };
|
|
9
|
+
let restorePoint;
|
|
10
|
+
if (result.plan.mode === 'retranslate-all') {
|
|
11
|
+
try {
|
|
12
|
+
restorePoint = (await deps.snapshot({ label: labels.restorePoint })).version;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return { status: 'snapshot-failed' };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const outcome = await deps.commit(result.patches);
|
|
19
|
+
if (outcome?.status === 'failed')
|
|
20
|
+
return { status: 'failed' };
|
|
21
|
+
const refusedAt = new Set(outcome?.status === 'refused' ? outcome.conflicts.map((conflict) => pathKey(conflict.path)) : []);
|
|
22
|
+
const refused = result.writes.filter((write) => refusedAt.has(pathKey(patchPath(write.patch))));
|
|
23
|
+
try {
|
|
24
|
+
await deps.snapshot({ label: labels.provenance, origin: 'assistant' });
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// ignore — provenance is additive
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
status: 'applied',
|
|
31
|
+
writes: result.writes.filter((write) => !refused.includes(write)),
|
|
32
|
+
refused,
|
|
33
|
+
...(restorePoint !== undefined ? { restorePoint } : {}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=translate-apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate-apply.js","sourceRoot":"","sources":["../../../src/lib/ai/translate-apply.ts"],"names":[],"mappings":"AA4DA,MAAM,OAAO,GAAG,CAAC,IAA2B,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,CAAC,CAAA;AAErF,2GAA2G;AAC3G,SAAS,SAAS,CAAC,KAAoB;IACrC,OAAO,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACjD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAoE,EACpE,IAAwB,EACxB,MAA4B;IAE5B,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;IACrF,IAAI,YAAgC,CAAA;IACpC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;QAC3C,IAAI,CAAC;YACH,YAAY,GAAG,CAAC,MAAM,IAAI,CAAC,QAA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CAAC,CAAC,EAAE,CAAC;KACxD,CAAA;AACH,CAAC","sourcesContent":["import type { DocumentPatch, ValuePath } from '@elytracms/core/cms-core'\nimport type { TranslateDocumentResult, TranslateWrite } from './translate-document'\n\n/**\n * EC-752 — how a translation run's writes land, in order: the pure core of the \"Translate\n * document\" dialog's apply (the dialog wires it to the session's commit queue and the\n * `documents.snapshot` operation), so the order is pinned by a test, not by a component.\n *\n * Re-translate everything REPLACES values someone made, and the draft records no history of\n * its own (versions are recorded on publish, snapshot and restore only), so an unpublished\n * manual translation it replaced was unrecoverable — the dialog used to snapshot only AFTER\n * its commit, a restore point holding the post-write state. Now:\n *\n * 1. `retranslate-all` with anything to write: a labelled snapshot of the stored draft\n * FIRST — the restore point Versions / Compare's scoped restore brings a field back\n * from. If it cannot be recorded, nothing is written (`snapshot-failed`): a\n * re-translation never replaces what it could not save.\n * 2. The patches, through the caller's commit (the session's queue, at the revision the\n * draft was authored on — a position a colleague changed meanwhile is refused there).\n * 3. The AI-provenance snapshot (best-effort, as before — the draft already landed).\n *\n * `fill-empty` is unchanged: it fills only values that followed the base, so it replaces\n * nothing and takes no restore point.\n */\n\n/** What the caller's commit reports — structurally the session's `CommitOutcome`. */\nexport type TranslateCommitOutcome =\n | { readonly status: 'applied' }\n | { readonly status: 'refused'; readonly conflicts: readonly { readonly path: ValuePath }[] }\n | { readonly status: 'failed' }\n\nexport interface TranslateApplyDeps {\n /** Persist the run's patches; `undefined` when the session applied them locally (a fixture session). */\n commit(patches: readonly DocumentPatch[]): Promise<TranslateCommitOutcome | undefined>\n /** Record the current stored draft as a version (`documents.snapshot`). */\n snapshot(options: { readonly label: string; readonly origin?: string }): Promise<{ readonly version: number }>\n}\n\nexport interface TranslateApplyLabels {\n /** The restore point's label (taken before a re-translation writes). */\n readonly restorePoint: string\n /** The provenance snapshot's label (taken after the write). */\n readonly provenance: string\n}\n\nexport type TranslateApplyOutcome =\n | {\n readonly status: 'applied'\n /** The writes that landed — the run's writes minus the ones refused at their revision. */\n readonly writes: readonly TranslateWrite[]\n /** Writes refused because a colleague changed the position meanwhile (shown as conflicts there). */\n readonly refused: readonly TranslateWrite[]\n /** The version recorded before a re-translation wrote — what Versions restores from. */\n readonly restorePoint?: number\n }\n /** `retranslate-all`: the restore point could not be recorded, so nothing was written. */\n | { readonly status: 'snapshot-failed' }\n /** The commit failed (transport, authorization): reported by the session too. */\n | { readonly status: 'failed' }\n\nconst pathKey = (path: ValuePath | undefined): string => JSON.stringify(path ?? null)\n\n/** The position a field write's patch addresses (`set` / `unset` — the only kinds a translation emits). */\nfunction patchPath(patch: DocumentPatch): ValuePath | undefined {\n return 'path' in patch ? patch.path : undefined\n}\n\nexport async function applyTranslation(\n result: Pick<TranslateDocumentResult, 'plan' | 'writes' | 'patches'>,\n deps: TranslateApplyDeps,\n labels: TranslateApplyLabels,\n): Promise<TranslateApplyOutcome> {\n if (result.writes.length === 0) return { status: 'applied', writes: [], refused: [] }\n let restorePoint: number | undefined\n if (result.plan.mode === 'retranslate-all') {\n try {\n restorePoint = (await deps.snapshot({ label: labels.restorePoint })).version\n } catch {\n return { status: 'snapshot-failed' }\n }\n }\n const outcome = await deps.commit(result.patches)\n if (outcome?.status === 'failed') return { status: 'failed' }\n const refusedAt = new Set(outcome?.status === 'refused' ? outcome.conflicts.map((conflict) => pathKey(conflict.path)) : [])\n const refused = result.writes.filter((write) => refusedAt.has(pathKey(patchPath(write.patch))))\n try {\n await deps.snapshot({ label: labels.provenance, origin: 'assistant' })\n } catch {\n // ignore — provenance is additive\n }\n return {\n status: 'applied',\n writes: result.writes.filter((write) => !refused.includes(write)),\n refused,\n ...(restorePoint !== undefined ? { restorePoint } : {}),\n }\n}\n"]}
|
|
@@ -6,7 +6,10 @@ export declare const DEFAULT_TRANSLATE_BATCH_SIZE = 12;
|
|
|
6
6
|
export declare const DEFAULT_TRANSLATE_CONCURRENCY = 6;
|
|
7
7
|
/** The schema name the batch call carries — how a FakeProvider recognises a translate call. */
|
|
8
8
|
export declare const TRANSLATE_SCHEMA_NAME = "translate_units";
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Fill only still-connected locale values (default), or re-translate every localized field
|
|
11
|
+
* — replacing a value with its own translation, rebuilt from the base (EC-752).
|
|
12
|
+
*/
|
|
10
13
|
export type TranslateMode = 'fill-empty' | 'retranslate-all';
|
|
11
14
|
export interface TranslateDocumentInput {
|
|
12
15
|
provider: AiProvider;
|
|
@@ -18,7 +21,12 @@ export interface TranslateDocumentInput {
|
|
|
18
21
|
targetLocales?: readonly Locale[];
|
|
19
22
|
/** Assembled project knowledge (glossary / voice) sent as context with every batch. */
|
|
20
23
|
knowledge?: ResolvedKnowledge;
|
|
21
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* `fill-empty` (default) or `retranslate-all` — which REPLACES a value with its own
|
|
26
|
+
* translation, whole or not at all, never a slug the editor set (EC-752). The studio runs
|
|
27
|
+
* it only behind a confirm listing {@link planTranslation}'s replacements, after a version
|
|
28
|
+
* snapshot of the draft.
|
|
29
|
+
*/
|
|
22
30
|
mode?: TranslateMode;
|
|
23
31
|
batchSize?: number;
|
|
24
32
|
concurrency?: number;
|
|
@@ -52,17 +60,26 @@ export interface TranslateProgress {
|
|
|
52
60
|
}
|
|
53
61
|
/** Why a text position was not translated. */
|
|
54
62
|
export type TranslateSkipReason =
|
|
55
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* The stored value at the position is not readable as its type (e.g. a pre-convergence rich
|
|
65
|
+
* text) — or (EC-752) it is a value the traversal cannot read at all (`OpaquePosition`: a
|
|
66
|
+
* holder stored in a shape its declaration no longer reads) that may hold text.
|
|
67
|
+
*/
|
|
56
68
|
'unreadable'
|
|
57
69
|
/** The provider returned no (or empty) text for the unit. */
|
|
58
70
|
| 'not-returned'
|
|
59
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* The translation did not keep the formatting / link / embed tokens: `fill-empty` keeps
|
|
73
|
+
* the source's block in the fill; `retranslate-all` leaves the whole target value as it was.
|
|
74
|
+
*/
|
|
60
75
|
| 'structure-changed'
|
|
61
76
|
/**
|
|
62
77
|
* EC-738: the bucket's locked content (`form.readOnly` / `ai.exclude`) differs in shape
|
|
63
78
|
* from the source's — writing the translation would lose a locked value the target holds or
|
|
64
79
|
* add one it does not (a repeater with more or fewer items, a composition with other
|
|
65
|
-
* nodes)
|
|
80
|
+
* nodes) — or (EC-748) either side stores it in a shape the declaration no longer reads.
|
|
81
|
+
* The whole bucket was left as it is: only code, a seed, an import or a save in the editor
|
|
82
|
+
* changes it.
|
|
66
83
|
*/
|
|
67
84
|
| 'locked';
|
|
68
85
|
/**
|
|
@@ -82,9 +99,71 @@ export interface TranslateSkip {
|
|
|
82
99
|
};
|
|
83
100
|
reason: TranslateSkipReason;
|
|
84
101
|
}
|
|
102
|
+
/** One `(field, locale)` value — the unit a translation writes, plans and reports (EC-752). */
|
|
103
|
+
export interface TranslateBucket {
|
|
104
|
+
readonly field: string;
|
|
105
|
+
readonly locale: Locale;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* What a planned bucket is (EC-752): `fill` — the target FOLLOWS the base (EC-318 connected)
|
|
109
|
+
* and gets its own translation; `replace` — the target holds its own value (an earlier
|
|
110
|
+
* translation, an editor's edit), which a re-translation rebuilds from the base — its text
|
|
111
|
+
* translated, every other value (a number, an image, a select) the base's, its locked
|
|
112
|
+
* positions kept (EC-738). `replace` exists only in `retranslate-all`.
|
|
113
|
+
*/
|
|
114
|
+
export type TranslateBucketKind = 'fill' | 'replace';
|
|
115
|
+
export interface TranslatePlanBucket extends TranslateBucket {
|
|
116
|
+
readonly kind: TranslateBucketKind;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* EC-752 — what a run will do, judged BEFORE any provider call: the eligibility, the locked
|
|
120
|
+
* judgement (EC-738), the units and the unreadable positions. ONE judge
|
|
121
|
+
* ({@link planTranslation}) gives both the studio's confirm and the run's input, so the list
|
|
122
|
+
* an editor confirms is the list the run works from.
|
|
123
|
+
*
|
|
124
|
+
* It is an UPPER bound ("up to"): what is known only after the provider answered — a unit
|
|
125
|
+
* not returned, a block whose tokens did not survive, a cancel, the introduced-errors gate
|
|
126
|
+
* refusing the run, a colleague's write refused at its revision — can only take a bucket
|
|
127
|
+
* away. {@link TranslateDocumentResult.writes} says what was written.
|
|
128
|
+
*/
|
|
129
|
+
export interface TranslatePlan {
|
|
130
|
+
readonly mode: TranslateMode;
|
|
131
|
+
readonly base: Locale;
|
|
132
|
+
/** Every configured locale but the base (or the caller's `targetLocales`). */
|
|
133
|
+
readonly targets: readonly Locale[];
|
|
134
|
+
/** The buckets the run writes when every unit lands — walk order (field, then locale). */
|
|
135
|
+
readonly buckets: readonly TranslatePlanBucket[];
|
|
136
|
+
/**
|
|
137
|
+
* What the run will NOT translate, known now: a bucket left as it is for its locked
|
|
138
|
+
* content (`locked`), an unreadable position (`unreadable` — in `retranslate-all` its whole
|
|
139
|
+
* bucket is left as it was, so it is not in {@link buckets}).
|
|
140
|
+
*/
|
|
141
|
+
readonly skipped: readonly TranslateSkip[];
|
|
142
|
+
/** Translatable units — the run's {@link TranslateDocumentResult.total}. */
|
|
143
|
+
readonly total: number;
|
|
144
|
+
}
|
|
145
|
+
/** What {@link planTranslation} reads — the run's own inputs, minus the provider. */
|
|
146
|
+
export type TranslatePlanInput = Pick<TranslateDocumentInput, 'collection' | 'document' | 'localeConfig' | 'targetLocales' | 'mode' | 'validateOptions'>;
|
|
147
|
+
/**
|
|
148
|
+
* One bucket this run WROTE (EC-752): a planned `fill` / `replace` whose every unit landed
|
|
149
|
+
* (`fill-empty`: at least one), or a `slug` derived from the translated source (only where
|
|
150
|
+
* the target's slug followed the base). `patch` is the one the caller persists
|
|
151
|
+
* ({@link TranslateDocumentResult.patches}, same order).
|
|
152
|
+
*/
|
|
153
|
+
export interface TranslateWrite extends TranslateBucket {
|
|
154
|
+
readonly kind: TranslateBucketKind | 'slug';
|
|
155
|
+
readonly patch: DocumentPatch;
|
|
156
|
+
}
|
|
85
157
|
export interface TranslateDocumentResult {
|
|
86
|
-
/** The new draft with the translations
|
|
158
|
+
/** The new draft with the translations in. */
|
|
87
159
|
document: CmsDocument;
|
|
160
|
+
/** EC-752 — the pre-provider plan this run executed ({@link planTranslation} on its input). */
|
|
161
|
+
plan: TranslatePlan;
|
|
162
|
+
/**
|
|
163
|
+
* EC-752 — what this run wrote, one entry per bucket, in {@link patches}' order: compare
|
|
164
|
+
* with {@link plan} for what was planned but not written.
|
|
165
|
+
*/
|
|
166
|
+
writes: readonly TranslateWrite[];
|
|
88
167
|
/**
|
|
89
168
|
* EC-595 A2 — the positions this run wrote, as patches (one per `(field, locale)`
|
|
90
169
|
* bucket it filled — "localized fields patch per bucket"): what the caller persists,
|
|
@@ -101,7 +180,7 @@ export interface TranslateDocumentResult {
|
|
|
101
180
|
changed: boolean;
|
|
102
181
|
/** Translatable units filled per target locale. */
|
|
103
182
|
perLocale: Record<Locale, number>;
|
|
104
|
-
/** Slug fields derived
|
|
183
|
+
/** Slug fields derived (not model-translated) — the `slug` entries of {@link writes}. */
|
|
105
184
|
slugsDerived: number;
|
|
106
185
|
/** Every text position the run could not translate (EC-593) — empty when all landed. */
|
|
107
186
|
skipped: readonly TranslateSkip[];
|
|
@@ -125,4 +204,12 @@ export interface TranslateDocumentResult {
|
|
|
125
204
|
/** Surviving non-error findings on the produced draft — carried onto a proposal. */
|
|
126
205
|
issues: readonly CmsValidationIssue[];
|
|
127
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* EC-752 — THE pre-provider judge: which field × locale values a translation of `input`
|
|
209
|
+
* writes when every unit lands (`fill` / `replace`), and what it already knows it will not
|
|
210
|
+
* translate (`locked`, `unreadable`). Pure: no provider, no store, no clock. The studio's
|
|
211
|
+
* confirm lists it; {@link translateDocument} runs exactly it — one judge, never a second
|
|
212
|
+
* count. See {@link TranslatePlan} for why it is an upper bound.
|
|
213
|
+
*/
|
|
214
|
+
export declare function planTranslation(input: TranslatePlanInput): TranslatePlan;
|
|
128
215
|
export declare function translateDocument(input: TranslateDocumentInput): Promise<TranslateDocumentResult>;
|