@purposeinplay/payload-ai-translate 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +714 -0
- package/dist/alerts-collection.d.ts +21 -0
- package/dist/alerts-collection.js +159 -0
- package/dist/api.d.ts +4 -0
- package/dist/api.js +918 -0
- package/dist/bulk-translate-batches-collection.d.ts +29 -0
- package/dist/bulk-translate-batches-collection.js +404 -0
- package/dist/bulk-translate-units-collection.d.ts +35 -0
- package/dist/bulk-translate-units-collection.js +310 -0
- package/dist/client/estimated-cost-cell.d.ts +6 -0
- package/dist/client/estimated-cost-cell.js +12 -0
- package/dist/client/excluded-fields-field.d.ts +45 -0
- package/dist/client/excluded-fields-field.js +553 -0
- package/dist/client/field-translate-button.d.ts +6 -0
- package/dist/client/field-translate-button.js +199 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +6 -0
- package/dist/client/lib/use-global-kill-switches.d.ts +20 -0
- package/dist/client/lib/use-global-kill-switches.js +58 -0
- package/dist/client/translate-button.d.ts +2 -0
- package/dist/client/translate-button.js +228 -0
- package/dist/client/translate-modal.d.ts +16 -0
- package/dist/client/translate-modal.js +549 -0
- package/dist/client/translation-progress.d.ts +10 -0
- package/dist/client/translation-progress.js +297 -0
- package/dist/components/TranslationNavGroup.d.ts +45 -0
- package/dist/components/TranslationNavGroup.js +104 -0
- package/dist/defaults.d.ts +11 -0
- package/dist/defaults.js +16 -0
- package/dist/endpoints/client-config.d.ts +44 -0
- package/dist/endpoints/client-config.js +145 -0
- package/dist/endpoints/estimate.d.ts +5 -0
- package/dist/endpoints/estimate.js +237 -0
- package/dist/endpoints/progress.d.ts +2 -0
- package/dist/endpoints/progress.js +314 -0
- package/dist/endpoints/translate.d.ts +11 -0
- package/dist/endpoints/translate.js +376 -0
- package/dist/endpoints/translation-hub/_helpers.d.ts +140 -0
- package/dist/endpoints/translation-hub/_helpers.js +297 -0
- package/dist/endpoints/translation-hub/active.d.ts +21 -0
- package/dist/endpoints/translation-hub/active.js +220 -0
- package/dist/endpoints/translation-hub/cancel.d.ts +22 -0
- package/dist/endpoints/translation-hub/cancel.js +233 -0
- package/dist/endpoints/translation-hub/enqueue.d.ts +70 -0
- package/dist/endpoints/translation-hub/enqueue.js +529 -0
- package/dist/endpoints/translation-hub/failures.d.ts +12 -0
- package/dist/endpoints/translation-hub/failures.js +67 -0
- package/dist/endpoints/translation-hub/force-reset.d.ts +20 -0
- package/dist/endpoints/translation-hub/force-reset.js +144 -0
- package/dist/endpoints/translation-hub/index.d.ts +21 -0
- package/dist/endpoints/translation-hub/index.js +20 -0
- package/dist/endpoints/translation-hub/list.d.ts +40 -0
- package/dist/endpoints/translation-hub/list.js +182 -0
- package/dist/endpoints/translation-hub/preflight.d.ts +19 -0
- package/dist/endpoints/translation-hub/preflight.js +141 -0
- package/dist/endpoints/translation-hub/retry-failed.d.ts +38 -0
- package/dist/endpoints/translation-hub/retry-failed.js +235 -0
- package/dist/endpoints/translation-hub/revert.d.ts +88 -0
- package/dist/endpoints/translation-hub/revert.js +405 -0
- package/dist/endpoints/translation-hub/status.d.ts +45 -0
- package/dist/endpoints/translation-hub/status.js +391 -0
- package/dist/endpoints/translation-hub/usage-summary.d.ts +114 -0
- package/dist/endpoints/translation-hub/usage-summary.js +481 -0
- package/dist/exports/client.d.ts +6 -0
- package/dist/exports/client.js +6 -0
- package/dist/exports/components.d.ts +6 -0
- package/dist/exports/components.js +5 -0
- package/dist/exports/index.d.ts +8 -0
- package/dist/exports/index.js +7 -0
- package/dist/exports/providers.d.ts +9 -0
- package/dist/exports/providers.js +5 -0
- package/dist/exports/views-client.d.ts +23 -0
- package/dist/exports/views-client.js +22 -0
- package/dist/exports/views.d.ts +30 -0
- package/dist/exports/views.js +29 -0
- package/dist/hooks/after-change-global.d.ts +4 -0
- package/dist/hooks/after-change-global.js +109 -0
- package/dist/hooks/after-change.d.ts +16 -0
- package/dist/hooks/after-change.js +205 -0
- package/dist/hooks/after-delete.d.ts +30 -0
- package/dist/hooks/after-delete.js +95 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/jobs-collection.d.ts +17 -0
- package/dist/jobs-collection.js +139 -0
- package/dist/lexical/classifier.d.ts +3 -0
- package/dist/lexical/classifier.js +108 -0
- package/dist/lexical/deserializer.d.ts +4 -0
- package/dist/lexical/deserializer.js +263 -0
- package/dist/lexical/placeholder-integrity.d.ts +6 -0
- package/dist/lexical/placeholder-integrity.js +21 -0
- package/dist/lexical/placeholders.d.ts +21 -0
- package/dist/lexical/placeholders.js +117 -0
- package/dist/lexical/serializer.d.ts +21 -0
- package/dist/lexical/serializer.js +233 -0
- package/dist/lexical/types.d.ts +32 -0
- package/dist/lexical/types.js +1 -0
- package/dist/lib/auth-diagnostics.d.ts +14 -0
- package/dist/lib/auth-diagnostics.js +19 -0
- package/dist/lib/batch-counts.d.ts +58 -0
- package/dist/lib/batch-counts.js +105 -0
- package/dist/lib/bulk-translate-migrations.d.ts +92 -0
- package/dist/lib/bulk-translate-migrations.js +153 -0
- package/dist/lib/coalescing-queue.d.ts +38 -0
- package/dist/lib/coalescing-queue.js +69 -0
- package/dist/lib/content-extractor.d.ts +16 -0
- package/dist/lib/content-extractor.js +410 -0
- package/dist/lib/content-hash.d.ts +1 -0
- package/dist/lib/content-hash.js +19 -0
- package/dist/lib/content-patcher.d.ts +15 -0
- package/dist/lib/content-patcher.js +293 -0
- package/dist/lib/cost-guards.d.ts +2 -0
- package/dist/lib/cost-guards.js +18 -0
- package/dist/lib/daily-spend-cap.d.ts +58 -0
- package/dist/lib/daily-spend-cap.js +233 -0
- package/dist/lib/effective-locales.d.ts +181 -0
- package/dist/lib/effective-locales.js +302 -0
- package/dist/lib/error-messages.d.ts +245 -0
- package/dist/lib/error-messages.js +626 -0
- package/dist/lib/events.d.ts +39 -0
- package/dist/lib/events.js +146 -0
- package/dist/lib/exclude-fields.d.ts +3 -0
- package/dist/lib/exclude-fields.js +64 -0
- package/dist/lib/field-breadcrumb.d.ts +31 -0
- package/dist/lib/field-breadcrumb.js +227 -0
- package/dist/lib/field-diff.d.ts +1 -0
- package/dist/lib/field-diff.js +25 -0
- package/dist/lib/field-empty.d.ts +2 -0
- package/dist/lib/field-empty.js +68 -0
- package/dist/lib/field-resolver.d.ts +3 -0
- package/dist/lib/field-resolver.js +164 -0
- package/dist/lib/group-soft-skips.d.ts +39 -0
- package/dist/lib/group-soft-skips.js +45 -0
- package/dist/lib/locale-merge.d.ts +44 -0
- package/dist/lib/locale-merge.js +357 -0
- package/dist/lib/locale-row-check.d.ts +30 -0
- package/dist/lib/locale-row-check.js +64 -0
- package/dist/lib/logger.d.ts +74 -0
- package/dist/lib/logger.js +97 -0
- package/dist/lib/manual-edit-guard.d.ts +128 -0
- package/dist/lib/manual-edit-guard.js +393 -0
- package/dist/lib/output-validation.d.ts +48 -0
- package/dist/lib/output-validation.js +148 -0
- package/dist/lib/payload-read.d.ts +16 -0
- package/dist/lib/payload-read.js +51 -0
- package/dist/lib/per-doc-claim.d.ts +90 -0
- package/dist/lib/per-doc-claim.js +140 -0
- package/dist/lib/per-doc-lock.d.ts +94 -0
- package/dist/lib/per-doc-lock.js +119 -0
- package/dist/lib/persist-usage.d.ts +91 -0
- package/dist/lib/persist-usage.js +116 -0
- package/dist/lib/progress-store.d.ts +103 -0
- package/dist/lib/progress-store.js +314 -0
- package/dist/lib/rate-limiter.d.ts +3 -0
- package/dist/lib/rate-limiter.js +53 -0
- package/dist/lib/snapshot-select.d.ts +43 -0
- package/dist/lib/snapshot-select.js +108 -0
- package/dist/lib/translate-prompt.d.ts +31 -0
- package/dist/lib/translate-prompt.js +66 -0
- package/dist/lib/translation-token-bucket.d.ts +57 -0
- package/dist/lib/translation-token-bucket.js +365 -0
- package/dist/lib/truncate-source-value.d.ts +1 -0
- package/dist/lib/truncate-source-value.js +27 -0
- package/dist/manual-edit-collection.d.ts +22 -0
- package/dist/manual-edit-collection.js +124 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.js +934 -0
- package/dist/providers/ai-sdk-adapter.d.ts +35 -0
- package/dist/providers/ai-sdk-adapter.js +100 -0
- package/dist/providers/anthropic.d.ts +31 -0
- package/dist/providers/anthropic.js +66 -0
- package/dist/providers/custom.d.ts +36 -0
- package/dist/providers/custom.js +24 -0
- package/dist/providers/gemini.d.ts +20 -0
- package/dist/providers/gemini.js +48 -0
- package/dist/providers/mock.d.ts +2 -0
- package/dist/providers/mock.js +29 -0
- package/dist/providers/openai.d.ts +28 -0
- package/dist/providers/openai.js +69 -0
- package/dist/settings-global.d.ts +74 -0
- package/dist/settings-global.js +216 -0
- package/dist/tasks/bulk-translate-coordinator.d.ts +115 -0
- package/dist/tasks/bulk-translate-coordinator.js +708 -0
- package/dist/tasks/bulk-translate-doc-task.d.ts +142 -0
- package/dist/tasks/bulk-translate-doc-task.js +1000 -0
- package/dist/tasks/bulk-translate-janitor.d.ts +87 -0
- package/dist/tasks/bulk-translate-janitor.js +311 -0
- package/dist/tasks/translate-job-task.d.ts +51 -0
- package/dist/tasks/translate-job-task.js +154 -0
- package/dist/translate.d.ts +113 -0
- package/dist/translate.js +911 -0
- package/dist/translation-daily-spend-collection.d.ts +24 -0
- package/dist/translation-daily-spend-collection.js +133 -0
- package/dist/translation-rate-limits-collection.d.ts +30 -0
- package/dist/translation-rate-limits-collection.js +144 -0
- package/dist/types.d.ts +672 -0
- package/dist/types.js +1 -0
- package/dist/usage-collection.d.ts +14 -0
- package/dist/usage-collection.js +377 -0
- package/dist/views/BulkRunsHub/BatchRow.d.ts +32 -0
- package/dist/views/BulkRunsHub/BatchRow.js +1222 -0
- package/dist/views/BulkRunsHub/BucketRow.d.ts +62 -0
- package/dist/views/BulkRunsHub/BucketRow.js +982 -0
- package/dist/views/BulkRunsHub/BulkRunsHub.client.d.ts +18 -0
- package/dist/views/BulkRunsHub/BulkRunsHub.client.js +331 -0
- package/dist/views/BulkRunsHub/EmptyState.d.ts +6 -0
- package/dist/views/BulkRunsHub/EmptyState.js +64 -0
- package/dist/views/BulkRunsHub/FilterBar.d.ts +16 -0
- package/dist/views/BulkRunsHub/FilterBar.js +284 -0
- package/dist/views/BulkRunsHub/InFlightBanner.d.ts +14 -0
- package/dist/views/BulkRunsHub/InFlightBanner.js +59 -0
- package/dist/views/BulkRunsHub/StatusBadge.d.ts +64 -0
- package/dist/views/BulkRunsHub/StatusBadge.js +248 -0
- package/dist/views/BulkRunsHub/SummaryStrip.d.ts +22 -0
- package/dist/views/BulkRunsHub/SummaryStrip.js +249 -0
- package/dist/views/BulkRunsHub/bucket-grouping.d.ts +200 -0
- package/dist/views/BulkRunsHub/bucket-grouping.js +344 -0
- package/dist/views/BulkRunsHub/bucketFailureSummary.d.ts +9 -0
- package/dist/views/BulkRunsHub/bucketFailureSummary.js +36 -0
- package/dist/views/BulkRunsHub/dedupedStatusFetch.d.ts +5 -0
- package/dist/views/BulkRunsHub/dedupedStatusFetch.js +45 -0
- package/dist/views/BulkRunsHub/index.d.ts +17 -0
- package/dist/views/BulkRunsHub/index.js +80 -0
- package/dist/views/BulkRunsHub/urlFilters.d.ts +14 -0
- package/dist/views/BulkRunsHub/urlFilters.js +50 -0
- package/dist/views/BulkRunsHub/useBulkRunsList.d.ts +26 -0
- package/dist/views/BulkRunsHub/useBulkRunsList.js +204 -0
- package/dist/views/BulkRunsHub/useUrlFilters.d.ts +10 -0
- package/dist/views/BulkRunsHub/useUrlFilters.js +88 -0
- package/dist/views/TranslationHub/ActiveJobs.d.ts +6 -0
- package/dist/views/TranslationHub/ActiveJobs.js +320 -0
- package/dist/views/TranslationHub/AdvancedPanel.d.ts +17 -0
- package/dist/views/TranslationHub/AdvancedPanel.js +996 -0
- package/dist/views/TranslationHub/AlertBanner.d.ts +6 -0
- package/dist/views/TranslationHub/AlertBanner.js +568 -0
- package/dist/views/TranslationHub/AuditPanel.d.ts +6 -0
- package/dist/views/TranslationHub/AuditPanel.helpers.d.ts +44 -0
- package/dist/views/TranslationHub/AuditPanel.helpers.js +71 -0
- package/dist/views/TranslationHub/AuditPanel.js +1367 -0
- package/dist/views/TranslationHub/BulkTranslate.types.d.ts +242 -0
- package/dist/views/TranslationHub/BulkTranslate.types.js +36 -0
- package/dist/views/TranslationHub/BulkTranslateFailureDrawer.d.ts +19 -0
- package/dist/views/TranslationHub/BulkTranslateFailureDrawer.js +332 -0
- package/dist/views/TranslationHub/BulkTranslateMonitor.d.ts +28 -0
- package/dist/views/TranslationHub/BulkTranslateMonitor.js +305 -0
- package/dist/views/TranslationHub/BulkTranslateNarrowViewportBanner.d.ts +3 -0
- package/dist/views/TranslationHub/BulkTranslateNarrowViewportBanner.js +42 -0
- package/dist/views/TranslationHub/BulkTranslatePostEnqueueTransition.d.ts +26 -0
- package/dist/views/TranslationHub/BulkTranslatePostEnqueueTransition.js +95 -0
- package/dist/views/TranslationHub/BulkTranslatePreflightModal.d.ts +22 -0
- package/dist/views/TranslationHub/BulkTranslatePreflightModal.js +879 -0
- package/dist/views/TranslationHub/BulkTranslateTerminalCard.d.ts +29 -0
- package/dist/views/TranslationHub/BulkTranslateTerminalCard.js +445 -0
- package/dist/views/TranslationHub/BulkTranslateTrigger.d.ts +66 -0
- package/dist/views/TranslationHub/BulkTranslateTrigger.js +161 -0
- package/dist/views/TranslationHub/EditorRecentRunsPanel.d.ts +33 -0
- package/dist/views/TranslationHub/EditorRecentRunsPanel.js +290 -0
- package/dist/views/TranslationHub/Hub.client.d.ts +74 -0
- package/dist/views/TranslationHub/Hub.client.js +357 -0
- package/dist/views/TranslationHub/ModelCombobox.d.ts +14 -0
- package/dist/views/TranslationHub/ModelCombobox.js +415 -0
- package/dist/views/TranslationHub/PerCollectionConfig.d.ts +10 -0
- package/dist/views/TranslationHub/PerCollectionConfig.helpers.d.ts +16 -0
- package/dist/views/TranslationHub/PerCollectionConfig.helpers.js +19 -0
- package/dist/views/TranslationHub/PerCollectionConfig.js +759 -0
- package/dist/views/TranslationHub/SettingsRail.d.ts +11 -0
- package/dist/views/TranslationHub/SettingsRail.js +382 -0
- package/dist/views/TranslationHub/StatusStrip.d.ts +6 -0
- package/dist/views/TranslationHub/StatusStrip.js +451 -0
- package/dist/views/TranslationHub/UsageTable.d.ts +6 -0
- package/dist/views/TranslationHub/UsageTable.helpers.d.ts +69 -0
- package/dist/views/TranslationHub/UsageTable.helpers.js +49 -0
- package/dist/views/TranslationHub/UsageTable.js +1240 -0
- package/dist/views/TranslationHub/alertGrouping.d.ts +70 -0
- package/dist/views/TranslationHub/alertGrouping.js +99 -0
- package/dist/views/TranslationHub/index.d.ts +20 -0
- package/dist/views/TranslationHub/index.js +109 -0
- package/dist/views/TranslationHub/tabNavigation.d.ts +53 -0
- package/dist/views/TranslationHub/tabNavigation.js +74 -0
- package/dist/views/TranslationHub/terminalBannerVisibility.d.ts +33 -0
- package/dist/views/TranslationHub/terminalBannerVisibility.js +124 -0
- package/dist/views/TranslationHub/useBulkTranslateActive.d.ts +49 -0
- package/dist/views/TranslationHub/useBulkTranslateActive.js +251 -0
- package/dist/views/TranslationHub/useFocusTrap.d.ts +6 -0
- package/dist/views/TranslationHub/useFocusTrap.js +81 -0
- package/dist/views/TranslationHub/useTranslationHubUsageSummary.d.ts +77 -0
- package/dist/views/TranslationHub/useTranslationHubUsageSummary.js +267 -0
- package/dist/views/shared/EditorError.d.ts +97 -0
- package/dist/views/shared/EditorError.js +205 -0
- package/dist/views/shared/ModelCell.d.ts +18 -0
- package/dist/views/shared/ModelCell.js +31 -0
- package/dist/views/shared/docHref.d.ts +16 -0
- package/dist/views/shared/docHref.js +26 -0
- package/dist/views/shared/fetch-error-body.d.ts +25 -0
- package/dist/views/shared/fetch-error-body.js +42 -0
- package/dist/views/shared/filterPillStyle.d.ts +35 -0
- package/dist/views/shared/filterPillStyle.js +40 -0
- package/dist/views/shared/format.d.ts +75 -0
- package/dist/views/shared/format.js +131 -0
- package/package.json +141 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editor-facing error catalogue.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for every error / soft-skip / alert / endpoint
|
|
5
|
+
* failure that surfaces to a content editor in the admin UI. Plugin
|
|
6
|
+
* internals throw / log machine codes; this file maps each code to
|
|
7
|
+
* plain-English copy keyed by `{ title, body, action?, explanation? }`.
|
|
8
|
+
*
|
|
9
|
+
* Why this exists: editors hit the Translation Hub, AlertBanner, doc-view
|
|
10
|
+
* Translate modal, etc. and used to see raw `err.message` text like
|
|
11
|
+
* "NoObjectGeneratedError: Response was not valid JSON" or internal codes
|
|
12
|
+
* like "Code: permanent.config". Engineers can debug those; editors can't.
|
|
13
|
+
* Every render site now routes through `editorMessageFor(code, ctx)` and
|
|
14
|
+
* shows the raw text only behind a "Show technical details" disclosure.
|
|
15
|
+
*
|
|
16
|
+
* Adding a new code: add the literal to `EditorErrorCode`, register a
|
|
17
|
+
* formatter in `MESSAGES`, set `isPermanentFailure` if applicable. Tests
|
|
18
|
+
* in `error-messages.test.ts` enforce that every code has a formatter.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Every code an editor can encounter in the UI. Grouped by source:
|
|
22
|
+
*
|
|
23
|
+
* - `bulk.*` — `FailureCode` from `tasks/bulk-translate-doc-task.ts`
|
|
24
|
+
* classifyError(). Persisted on `bulk_translate_units.failureCode`.
|
|
25
|
+
* - `soft-skip.*` — Validation outcome from `lib/output-validation.ts`
|
|
26
|
+
* when an LLM response is rejected without erroring. Persisted on
|
|
27
|
+
* `translation-usage.targetLocales[].softSkippedFields[].reasonCode`.
|
|
28
|
+
* - `cost-guard.*` — Throws from `lib/cost-guards.ts`. Persisted on
|
|
29
|
+
* `translation-alerts.metadata.code` when alert is `cost-guard-abort`.
|
|
30
|
+
* - `alert.*` — `translation-alerts.alertType`. The collection itself
|
|
31
|
+
* already enums these.
|
|
32
|
+
* - `endpoint.*` — Response.error.code from `endpoints/translation-hub/*`.
|
|
33
|
+
* - `marker.*` — Special-case `failureMessage` values written by admin
|
|
34
|
+
* actions (cancel / force-reset) that aren't real failures.
|
|
35
|
+
*/
|
|
36
|
+
export type EditorErrorCode = 'bulk.transient.rate_limited' | 'bulk.transient.provider' | 'bulk.transient.crashed' | 'bulk.permanent.schema' | 'bulk.permanent.too_large' | 'bulk.permanent.config' | 'bulk.permanent.deleted' | 'bulk.unknown' | 'soft-skip.echoed' | 'soft-skip.too-short' | 'soft-skip.too-long' | 'soft-skip.placeholders' | 'soft-skip.refusal' | 'soft-skip.injection' | 'soft-skip.control-chars' | 'cost-guard.per-call' | 'cost-guard.per-doc' | 'cost-guard.daily-cap' | 'alert.persistent-failure' | 'alert.cost-guard-abort' | 'alert.provider-outage' | 'endpoint.invalid_state' | 'endpoint.not_found' | 'endpoint.totp_invalid' | 'endpoint.totp_missing' | 'endpoint.totp_plugin_unavailable' | 'endpoint.daily_cap_exceeded' | 'endpoint.concurrent_batch' | 'endpoint.not_configured' | 'endpoint.window_expired' | 'endpoint.cost_unavailable' | 'endpoint.invalid_batch_id' | 'endpoint.invalid_json' | 'endpoint.forbidden' | 'endpoint.unauthorized' | 'marker.cancelled-by-admin' | 'marker.force-reset-by-admin' | 'marker.cancelled-mid-flight';
|
|
37
|
+
/**
|
|
38
|
+
* One editor-facing message. UI components destructure this directly.
|
|
39
|
+
*
|
|
40
|
+
* - `title`: short — banner heading / status pill label / toast title
|
|
41
|
+
* (3–8 words).
|
|
42
|
+
* - `body`: 1–2 plain sentences. Names what happened and the impact
|
|
43
|
+
* the editor will feel.
|
|
44
|
+
* - `action`: optional 1-sentence CTA — what the editor can do next.
|
|
45
|
+
* Omitted when the action is implicit (e.g. close a modal).
|
|
46
|
+
* - `explanation`: only for permanent failures. Inline expandable
|
|
47
|
+
* "Why won't this work?" text shown when the editor clicks the
|
|
48
|
+
* disabled Retry button or a help affordance. Explains WHY this
|
|
49
|
+
* class of failure won't fix itself on retry.
|
|
50
|
+
*/
|
|
51
|
+
export type EditorMessage = {
|
|
52
|
+
title: string;
|
|
53
|
+
body: string;
|
|
54
|
+
action?: string;
|
|
55
|
+
explanation?: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Context used to template messages with concrete values. Every field
|
|
59
|
+
* optional — formatters that need a value handle missing gracefully
|
|
60
|
+
* (e.g. fall back to "this document" when collection slug is absent).
|
|
61
|
+
*
|
|
62
|
+
* Numeric fields are pre-formatted in `body`/`title` via `formatUsd`
|
|
63
|
+
* and `formatNumber` helpers so the catalogue itself stays free of
|
|
64
|
+
* locale-aware formatting concerns.
|
|
65
|
+
*/
|
|
66
|
+
export type EditorErrorContext = {
|
|
67
|
+
/** Locale code e.g. "fr". Mapped to a friendly label via `localeLabel`. */
|
|
68
|
+
locale?: string;
|
|
69
|
+
/** Count of items affected — fields failed, retries used, etc. */
|
|
70
|
+
count?: number;
|
|
71
|
+
/** Max attempts attempted (e.g. retry exhaustion). */
|
|
72
|
+
maxAttempts?: number;
|
|
73
|
+
/** Current batch status (e.g. "running", "failed"). */
|
|
74
|
+
status?: string;
|
|
75
|
+
/** Hours elapsed since a window opened. */
|
|
76
|
+
hoursElapsed?: number;
|
|
77
|
+
/** Hours allowed inside the window. */
|
|
78
|
+
hoursWindow?: number;
|
|
79
|
+
/** USD spent so far. */
|
|
80
|
+
spent?: number;
|
|
81
|
+
/** USD this request would add. */
|
|
82
|
+
delta?: number;
|
|
83
|
+
/** USD cap. */
|
|
84
|
+
cap?: number;
|
|
85
|
+
/** USD remaining inside the cap. */
|
|
86
|
+
remaining?: number;
|
|
87
|
+
/** Character count observed (cost-guard surfaces). */
|
|
88
|
+
chars?: number;
|
|
89
|
+
/** Character limit configured (cost-guard surfaces). */
|
|
90
|
+
limit?: number;
|
|
91
|
+
/** Length ratio observed (soft-skip too-short/too-long). */
|
|
92
|
+
ratio?: number;
|
|
93
|
+
/** Length ratio threshold (min for too-short, max for too-long). */
|
|
94
|
+
ratioThreshold?: number;
|
|
95
|
+
/** Placeholder ids missing from the translation (soft-skip placeholders). */
|
|
96
|
+
missingPlaceholders?: readonly string[];
|
|
97
|
+
/** Placeholder ids the translation added (soft-skip placeholders). */
|
|
98
|
+
extraPlaceholders?: readonly string[];
|
|
99
|
+
/** Collection slug — passed through for log context, not displayed. */
|
|
100
|
+
collection?: string;
|
|
101
|
+
/** Document id — passed through for log context, not displayed. */
|
|
102
|
+
documentId?: string | number;
|
|
103
|
+
/** Global slug, for global translation paths. */
|
|
104
|
+
globalSlug?: string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Returns the editor-facing message for a given code. When the code is
|
|
108
|
+
* unknown (e.g. legacy data with a code we no longer ship), returns a
|
|
109
|
+
* safe fallback rather than rendering `undefined` in the UI.
|
|
110
|
+
*/
|
|
111
|
+
export declare function editorMessageFor(code: EditorErrorCode | string | null | undefined, ctx?: EditorErrorContext): EditorMessage;
|
|
112
|
+
/**
|
|
113
|
+
* `true` when the code names a failure that won't fix itself on retry
|
|
114
|
+
* — used to disable the Retry button in the UI and show the inline
|
|
115
|
+
* "Why won't this work?" explanation. Conservative by design: when
|
|
116
|
+
* we're not sure, allow retry.
|
|
117
|
+
*/
|
|
118
|
+
export declare function isPermanentFailure(code: EditorErrorCode | string | null | undefined): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Adapter from the bulk worker's `FailureCode` (machine enum on the
|
|
121
|
+
* `bulk_translate_units.failureCode` column) to an `EditorErrorCode`.
|
|
122
|
+
* Keeps the persistence enum unchanged while letting the UI key off
|
|
123
|
+
* the catalogue.
|
|
124
|
+
*/
|
|
125
|
+
export declare function editorCodeFromFailureCode(failureCode: string | null | undefined): EditorErrorCode;
|
|
126
|
+
/**
|
|
127
|
+
* Adapter from the alerts collection's `alertType` enum to an
|
|
128
|
+
* `EditorErrorCode`. Used by AlertBanner to render the friendly
|
|
129
|
+
* message via the catalogue.
|
|
130
|
+
*/
|
|
131
|
+
export declare function editorCodeFromAlertType(alertType: string | null | undefined): EditorErrorCode;
|
|
132
|
+
/**
|
|
133
|
+
* Adapter from the cost-guard throw's `code` property to an
|
|
134
|
+
* `EditorErrorCode`. Used in API catch blocks that emitAlert.
|
|
135
|
+
*/
|
|
136
|
+
export declare function editorCodeFromCostGuardCode(costGuardCode: string | null | undefined): EditorErrorCode;
|
|
137
|
+
/**
|
|
138
|
+
* Adapter from a `failureMessage` enum marker (admin action) to an
|
|
139
|
+
* `EditorErrorCode`. Returns `null` when the message is a real error
|
|
140
|
+
* (not an admin marker) so callers can fall back to `failureCode`.
|
|
141
|
+
*/
|
|
142
|
+
export declare function editorCodeFromFailureMessageMarker(failureMessage: string | null | undefined): EditorErrorCode | null;
|
|
143
|
+
/**
|
|
144
|
+
* Coarse failure category used to drive UI tone + grouping. Five buckets:
|
|
145
|
+
*
|
|
146
|
+
* - `config-error` — legit configuration issue. Authentication missing
|
|
147
|
+
* or invalid, no model configured, no provider registered. WON'T fix
|
|
148
|
+
* itself on retry; editor needs to talk to engineering.
|
|
149
|
+
*
|
|
150
|
+
* - `transient-provider-error` — provider returned something invalid,
|
|
151
|
+
* timed out, hit a 5xx, was rate-limited, or returned a non-finite
|
|
152
|
+
* cost (broken instrumentation pattern observed in production where
|
|
153
|
+
* most units in the same batch succeeded). WILL fix itself on retry.
|
|
154
|
+
*
|
|
155
|
+
* - `cancelled-mid-flight` — the unit was in-flight when the admin
|
|
156
|
+
* clicked Cancel. The underlying error may look like anything; the
|
|
157
|
+
* relevant context is that the batch is `cancelled` / `cancelling`,
|
|
158
|
+
* so reporting it as a config / provider failure misdirects the
|
|
159
|
+
* editor.
|
|
160
|
+
*
|
|
161
|
+
* - `output-validation-error` — the model returned content that failed
|
|
162
|
+
* schema validation (Vercel AI SDK's `NoObjectGeneratedError`, JSON
|
|
163
|
+
* schema rejects). Retry MIGHT help with a different temperature /
|
|
164
|
+
* model; engineering may need to relax the schema.
|
|
165
|
+
*
|
|
166
|
+
* - `unknown-error` — fallback bucket. Raw error logged for diagnosis.
|
|
167
|
+
* NEVER use as a "we don't care" catch-all — every new error class
|
|
168
|
+
* should get its own bucket.
|
|
169
|
+
*/
|
|
170
|
+
export type FailureCategory = 'config-error' | 'transient-provider-error' | 'cancelled-mid-flight' | 'output-validation-error' | 'unknown-error';
|
|
171
|
+
/**
|
|
172
|
+
* Input to `categorizeFailure`. Caller passes whatever it has from the
|
|
173
|
+
* persisted unit row plus the parent batch's status (so we can detect
|
|
174
|
+
* `cancelled-mid-flight` without making the categorizer re-query the
|
|
175
|
+
* DB). Server-side callers also pass the raw `err` value before the
|
|
176
|
+
* row is persisted; client-side callers won't have it and pass only
|
|
177
|
+
* the persisted strings.
|
|
178
|
+
*/
|
|
179
|
+
export type CategorizeFailureInput = {
|
|
180
|
+
/** Persisted `failureCode` (e.g. `permanent.config`). */
|
|
181
|
+
failureCode?: string | null;
|
|
182
|
+
/** Persisted `failureMessage` (raw error text or admin marker). */
|
|
183
|
+
failureMessage?: string | null;
|
|
184
|
+
/** Parent batch status — `cancelled` / `cancelling` flips most errors to `cancelled-mid-flight`. */
|
|
185
|
+
batchStatus?: string | null;
|
|
186
|
+
/** Worker attempts so far — informational, used by callers that need to show context. */
|
|
187
|
+
attemptCount?: number;
|
|
188
|
+
/**
|
|
189
|
+
* Raw thrown error, when available. Server-side callers (worker
|
|
190
|
+
* `catch` block) have this; client-side callers don't.
|
|
191
|
+
*/
|
|
192
|
+
err?: unknown;
|
|
193
|
+
};
|
|
194
|
+
/** Result of `categorizeFailure`. */
|
|
195
|
+
export type CategorizedFailure = {
|
|
196
|
+
category: FailureCategory;
|
|
197
|
+
/**
|
|
198
|
+
* Chip label suitable for status badges (3-4 words, Sentence case).
|
|
199
|
+
* Derived from category, not from raw error text.
|
|
200
|
+
*/
|
|
201
|
+
label: string;
|
|
202
|
+
/**
|
|
203
|
+
* Editor-facing code keyed into the message catalogue. UI surfaces
|
|
204
|
+
* pass this to `<EditorError code={…}>` or `editorMessageFor` to
|
|
205
|
+
* render title + body + action.
|
|
206
|
+
*/
|
|
207
|
+
editorCode: EditorErrorCode;
|
|
208
|
+
/**
|
|
209
|
+
* One-line plain-English message (mirrors the catalogue's `title`).
|
|
210
|
+
* Pre-computed so callers that render in a constrained space (chip,
|
|
211
|
+
* table cell) don't need to call `editorMessageFor` themselves.
|
|
212
|
+
*/
|
|
213
|
+
userMessage: string;
|
|
214
|
+
/**
|
|
215
|
+
* Optional raw error text, suitable for an "engineering details"
|
|
216
|
+
* disclosure. Returned only when the category isn't a marker (admin
|
|
217
|
+
* cancel / cancel-mid-flight) — those don't have engineer-relevant
|
|
218
|
+
* detail beyond the marker itself.
|
|
219
|
+
*/
|
|
220
|
+
details?: string;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Coarse-grained failure categorizer used by `bulk_translate_units` UI
|
|
224
|
+
* surfaces (BatchRow expanded row, BucketRow locale detail, Failure
|
|
225
|
+
* drawer chip). Pure function over the persisted row + parent batch
|
|
226
|
+
* status. Server-side callers (worker) can also pass the raw thrown
|
|
227
|
+
* error before persistence.
|
|
228
|
+
*
|
|
229
|
+
* Decision order:
|
|
230
|
+
* 1. Admin markers (failureMessage = 'cancelled_by_admin' /
|
|
231
|
+
* 'force-reset by admin') short-circuit to the existing marker
|
|
232
|
+
* codes — those aren't real failures.
|
|
233
|
+
* 2. If the parent batch is `cancelled` or `cancelling` AND the unit
|
|
234
|
+
* has a real failure (failureCode present, not just the admin
|
|
235
|
+
* marker), classify as `cancelled-mid-flight`. The user's mental
|
|
236
|
+
* model is "I cancelled, so this stopped" — not "my config is
|
|
237
|
+
* broken."
|
|
238
|
+
* 3. Message-hint patterns override the persisted `failureCode` when
|
|
239
|
+
* they clearly point at a different bucket (defends against
|
|
240
|
+
* `classifyError` drift in legacy data — e.g. pre-v1.2.6 the
|
|
241
|
+
* COST_UNDEFINED case persisted as `permanent.config`).
|
|
242
|
+
* 4. Map `failureCode` to a category via the static tables.
|
|
243
|
+
* 5. Fallback: `unknown-error`.
|
|
244
|
+
*/
|
|
245
|
+
export declare function categorizeFailure(input: CategorizeFailureInput): CategorizedFailure;
|