@elytracms/studio 0.0.91 → 0.0.93
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/asset-alt-migration.test.ts +127 -0
- package/convex/asset-replace.test.ts +168 -0
- package/convex/asset-revalidate.test.ts +6 -6
- package/convex/assets.ts +41 -5
- package/convex/cms.ts +537 -177
- package/convex/contract-parity.test.ts +173 -19
- package/convex/delivery.ts +26 -13
- package/convex/document-revalidate.test.ts +17 -16
- package/convex/orphan-hydration.test.ts +116 -0
- package/convex/presence-cost.test.ts +89 -0
- package/convex/rail-write-parity.test.ts +17 -14
- package/convex/referenceMaintenance.ts +15 -15
- package/convex/schema.ts +70 -5
- package/convex/triggers.ts +21 -8
- package/convex/write-limits.ts +1 -1
- package/dist/components/ai/ai-chat-panel.js +33 -22
- package/dist/components/ai/ai-chat-panel.js.map +1 -1
- package/dist/components/ai/proposal-card.js +2 -1
- package/dist/components/ai/proposal-card.js.map +1 -1
- package/dist/components/ai/translate-document-action.d.ts +8 -2
- package/dist/components/ai/translate-document-action.js.map +1 -1
- package/dist/components/ai/translate-document-dialog.d.ts +1 -1
- package/dist/components/ai/translate-document-dialog.js +14 -8
- package/dist/components/ai/translate-document-dialog.js.map +1 -1
- package/dist/components/ai/translate-skipped.d.ts +19 -0
- package/dist/components/ai/translate-skipped.js +46 -0
- package/dist/components/ai/translate-skipped.js.map +1 -0
- package/dist/components/app-views/default-modules.d.ts +23 -6
- package/dist/components/app-views/default-modules.js +33 -14
- package/dist/components/app-views/default-modules.js.map +1 -1
- package/dist/components/assets/asset-detail.js +18 -8
- package/dist/components/assets/asset-detail.js.map +1 -1
- package/dist/components/assets/asset-metadata.d.ts +15 -4
- package/dist/components/assets/asset-metadata.js +15 -2
- package/dist/components/assets/asset-metadata.js.map +1 -1
- package/dist/components/assets/asset-search.js +4 -1
- package/dist/components/assets/asset-search.js.map +1 -1
- package/dist/components/assets/asset-selection.d.ts +0 -8
- package/dist/components/assets/asset-selection.js +4 -23
- package/dist/components/assets/asset-selection.js.map +1 -1
- package/dist/components/assets/asset-thumb.js +3 -2
- package/dist/components/assets/asset-thumb.js.map +1 -1
- package/dist/components/assets/assets-collection-view-source.d.ts +3 -3
- package/dist/components/assets/assets-collection-view-source.js +9 -5
- package/dist/components/assets/assets-collection-view-source.js.map +1 -1
- package/dist/components/assets/assets-store.d.ts +14 -0
- package/dist/components/assets/assets-store.js +23 -1
- package/dist/components/assets/assets-store.js.map +1 -1
- package/dist/components/assets/replace-file.d.ts +22 -0
- package/dist/components/assets/replace-file.js +59 -0
- package/dist/components/assets/replace-file.js.map +1 -0
- package/dist/components/builder/blocks-model.d.ts +14 -26
- package/dist/components/builder/blocks-model.js +35 -41
- package/dist/components/builder/blocks-model.js.map +1 -1
- package/dist/components/builder/blocks-panel.d.ts +7 -3
- package/dist/components/builder/blocks-panel.js +6 -5
- package/dist/components/builder/blocks-panel.js.map +1 -1
- package/dist/components/builder/builder-store.d.ts +126 -30
- package/dist/components/builder/builder-store.js +169 -67
- package/dist/components/builder/builder-store.js.map +1 -1
- package/dist/components/builder/canvas-body.d.ts +30 -0
- package/dist/components/builder/canvas-body.js +38 -0
- package/dist/components/builder/canvas-body.js.map +1 -0
- package/dist/components/builder/canvas-chrome-css.js +7 -0
- package/dist/components/builder/canvas-chrome-css.js.map +1 -1
- package/dist/components/builder/canvas-dnd.d.ts +7 -7
- package/dist/components/builder/canvas-dnd.js +5 -5
- package/dist/components/builder/canvas-dnd.js.map +1 -1
- package/dist/components/builder/canvas-render-context.d.ts +30 -22
- package/dist/components/builder/canvas-render-context.js +44 -44
- package/dist/components/builder/canvas-render-context.js.map +1 -1
- package/dist/components/builder/canvas-runs.d.ts +45 -0
- package/dist/components/builder/canvas-runs.js +51 -0
- package/dist/components/builder/canvas-runs.js.map +1 -0
- package/dist/components/builder/canvas.d.ts +5 -4
- package/dist/components/builder/canvas.js +34 -6
- package/dist/components/builder/canvas.js.map +1 -1
- package/dist/components/builder/clipboard-actions.d.ts +15 -0
- package/dist/components/builder/clipboard-actions.js +50 -13
- package/dist/components/builder/clipboard-actions.js.map +1 -1
- package/dist/components/builder/composition-field-editor.d.ts +10 -16
- package/dist/components/builder/composition-field-editor.js +30 -40
- package/dist/components/builder/composition-field-editor.js.map +1 -1
- package/dist/components/builder/composition-patches.d.ts +7 -0
- package/dist/components/builder/composition-patches.js +256 -0
- package/dist/components/builder/composition-patches.js.map +1 -0
- package/dist/components/builder/delete-key.d.ts +5 -0
- package/dist/components/builder/delete-key.js +4 -0
- package/dist/components/builder/delete-key.js.map +1 -1
- package/dist/components/builder/insert-context.d.ts +17 -25
- package/dist/components/builder/insert-context.js +45 -92
- package/dist/components/builder/insert-context.js.map +1 -1
- package/dist/components/builder/page-tree.d.ts +3 -3
- package/dist/components/builder/page-tree.js +3 -3
- package/dist/components/builder/page-tree.js.map +1 -1
- package/dist/components/builder/placement-refusal.d.ts +18 -0
- package/dist/components/builder/placement-refusal.js +46 -0
- package/dist/components/builder/placement-refusal.js.map +1 -0
- package/dist/components/builder/property-inspector.js +4 -0
- package/dist/components/builder/property-inspector.js.map +1 -1
- package/dist/components/builder/reuse-context.js +65 -26
- package/dist/components/builder/reuse-context.js.map +1 -1
- package/dist/components/builder/reuse.d.ts +79 -8
- package/dist/components/builder/reuse.js +71 -23
- package/dist/components/builder/reuse.js.map +1 -1
- package/dist/components/builder/run-inspector.d.ts +11 -0
- package/dist/components/builder/run-inspector.js +33 -0
- package/dist/components/builder/run-inspector.js.map +1 -0
- package/dist/components/cms/asset-field.d.ts +38 -1
- package/dist/components/cms/asset-field.js +182 -58
- package/dist/components/cms/asset-field.js.map +1 -1
- package/dist/components/cms/asset-picker-core.d.ts +16 -0
- package/dist/components/cms/asset-picker-core.js +20 -0
- package/dist/components/cms/asset-picker-core.js.map +1 -1
- package/dist/components/cms/asset-picker.js +12 -18
- package/dist/components/cms/asset-picker.js.map +1 -1
- package/dist/components/cms/bulk-actions.d.ts +4 -20
- package/dist/components/cms/bulk-actions.js +3 -24
- package/dist/components/cms/bulk-actions.js.map +1 -1
- package/dist/components/cms/cell-edit.d.ts +5 -5
- package/dist/components/cms/cell-edit.js.map +1 -1
- package/dist/components/cms/cell.js.map +1 -1
- package/dist/components/cms/cms-store.d.ts +87 -45
- package/dist/components/cms/cms-store.js +347 -203
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/collection-table.js +7 -2
- package/dist/components/cms/collection-table.js.map +1 -1
- package/dist/components/cms/commit-policy.d.ts +24 -0
- package/dist/components/cms/commit-policy.js +37 -0
- package/dist/components/cms/commit-policy.js.map +1 -0
- package/dist/components/cms/detail-editor.js +83 -137
- package/dist/components/cms/detail-editor.js.map +1 -1
- package/dist/components/cms/document-diff-view.d.ts +3 -1
- package/dist/components/cms/document-diff-view.js +12 -7
- package/dist/components/cms/document-diff-view.js.map +1 -1
- package/dist/components/cms/draft-commit.d.ts +70 -0
- package/dist/components/cms/draft-commit.js +82 -0
- package/dist/components/cms/draft-commit.js.map +1 -0
- package/dist/components/cms/duplicate-document.d.ts +11 -13
- package/dist/components/cms/duplicate-document.js +26 -34
- package/dist/components/cms/duplicate-document.js.map +1 -1
- package/dist/components/cms/field-anchors.d.ts +7 -4
- package/dist/components/cms/field-anchors.js +9 -7
- package/dist/components/cms/field-anchors.js.map +1 -1
- package/dist/components/cms/field-collaboration.d.ts +47 -0
- package/dist/components/cms/field-collaboration.js +87 -0
- package/dist/components/cms/field-collaboration.js.map +1 -0
- package/dist/components/cms/field-control-lib.d.ts +22 -1
- package/dist/components/cms/field-control-lib.js +33 -4
- package/dist/components/cms/field-control-lib.js.map +1 -1
- package/dist/components/cms/field-control.js +17 -14
- package/dist/components/cms/field-control.js.map +1 -1
- package/dist/components/cms/gate-validation.d.ts +21 -30
- package/dist/components/cms/gate-validation.js +11 -22
- package/dist/components/cms/gate-validation.js.map +1 -1
- package/dist/components/cms/object-array-field.js +4 -4
- package/dist/components/cms/object-array-field.js.map +1 -1
- package/dist/components/cms/prop-fields.d.ts +7 -2
- package/dist/components/cms/prop-fields.js +13 -6
- package/dist/components/cms/prop-fields.js.map +1 -1
- package/dist/components/cms/reference-confirm.js +10 -4
- package/dist/components/cms/reference-confirm.js.map +1 -1
- package/dist/components/cms/rich-text/embed-picker.d.ts +1 -1
- package/dist/components/cms/rich-text/embed-picker.js.map +1 -1
- package/dist/components/cms/rich-text/insert.d.ts +20 -9
- package/dist/components/cms/rich-text/insert.js +25 -17
- package/dist/components/cms/rich-text/insert.js.map +1 -1
- package/dist/components/cms/use-document-draft.d.ts +96 -0
- package/dist/components/cms/use-document-draft.js +283 -0
- package/dist/components/cms/use-document-draft.js.map +1 -0
- package/dist/components/cms/use-document-versions.js +2 -2
- package/dist/components/cms/use-document-versions.js.map +1 -1
- package/dist/components/cms/use-live-url.d.ts +6 -12
- package/dist/components/cms/use-live-url.js +16 -15
- package/dist/components/cms/use-live-url.js.map +1 -1
- package/dist/components/cms/use-publish-controller.d.ts +13 -18
- package/dist/components/cms/use-publish-controller.js +24 -41
- package/dist/components/cms/use-publish-controller.js.map +1 -1
- package/dist/components/cms/use-published-perspective.d.ts +2 -3
- package/dist/components/cms/use-published-perspective.js +4 -3
- package/dist/components/cms/use-published-perspective.js.map +1 -1
- package/dist/components/cms/versions-pane.js +8 -1
- package/dist/components/cms/versions-pane.js.map +1 -1
- package/dist/components/collection-view/cms-collection-view-source.js +24 -7
- package/dist/components/collection-view/cms-collection-view-source.js.map +1 -1
- package/dist/components/components/transfer-dialog.js +28 -23
- package/dist/components/components/transfer-dialog.js.map +1 -1
- package/dist/components/components/transfer.d.ts +31 -21
- package/dist/components/components/transfer.js +49 -35
- package/dist/components/components/transfer.js.map +1 -1
- package/dist/components/project-list.js.map +1 -1
- package/dist/components/project-session.d.ts +6 -3
- package/dist/components/project-session.js +14 -8
- package/dist/components/project-session.js.map +1 -1
- package/dist/components/project-switcher.js.map +1 -1
- package/dist/components/rail-view-source.js +2 -1
- package/dist/components/rail-view-source.js.map +1 -1
- package/dist/components/section-nav.js +1 -1
- package/dist/components/section-nav.js.map +1 -1
- package/dist/lib/ai/apply-content.js +56 -116
- package/dist/lib/ai/apply-content.js.map +1 -1
- package/dist/lib/ai/chat-context.d.ts +8 -0
- package/dist/lib/ai/chat-context.js +37 -6
- package/dist/lib/ai/chat-context.js.map +1 -1
- package/dist/lib/ai/chat-state.d.ts +14 -1
- package/dist/lib/ai/chat-state.js.map +1 -1
- package/dist/lib/ai/constraints.d.ts +20 -5
- package/dist/lib/ai/constraints.js +125 -33
- package/dist/lib/ai/constraints.js.map +1 -1
- package/dist/lib/ai/fake-provider.d.ts +16 -3
- package/dist/lib/ai/fake-provider.js +22 -6
- package/dist/lib/ai/fake-provider.js.map +1 -1
- package/dist/lib/ai/index.d.ts +2 -0
- package/dist/lib/ai/index.js +2 -0
- package/dist/lib/ai/index.js.map +1 -1
- package/dist/lib/ai/leash.d.ts +34 -0
- package/dist/lib/ai/leash.js +28 -0
- package/dist/lib/ai/leash.js.map +1 -0
- package/dist/lib/ai/provenance.d.ts +1 -1
- package/dist/lib/ai/provenance.js.map +1 -1
- package/dist/lib/ai/rich-text-input.d.ts +8 -8
- package/dist/lib/ai/rich-text-input.js +2 -1
- package/dist/lib/ai/rich-text-input.js.map +1 -1
- package/dist/lib/ai/rich-text-translate.d.ts +27 -4
- package/dist/lib/ai/rich-text-translate.js +28 -10
- package/dist/lib/ai/rich-text-translate.js.map +1 -1
- package/dist/lib/ai/shape.d.ts +13 -13
- package/dist/lib/ai/shape.js +69 -93
- package/dist/lib/ai/shape.js.map +1 -1
- package/dist/lib/ai/tools.d.ts +36 -41
- package/dist/lib/ai/tools.js +85 -87
- package/dist/lib/ai/tools.js.map +1 -1
- package/dist/lib/ai/translate-document.d.ts +39 -5
- package/dist/lib/ai/translate-document.js +160 -51
- package/dist/lib/ai/translate-document.js.map +1 -1
- package/dist/lib/ai/types.d.ts +34 -23
- package/dist/lib/ai/types.js.map +1 -1
- package/dist/lib/ai/update-fields.d.ts +21 -12
- package/dist/lib/ai/update-fields.js +118 -177
- package/dist/lib/ai/update-fields.js.map +1 -1
- package/dist/lib/ai/writer-form.d.ts +116 -0
- package/dist/lib/ai/writer-form.js +429 -0
- package/dist/lib/ai/writer-form.js.map +1 -0
- package/dist/lib/ai-current-document.d.ts +11 -11
- package/dist/lib/ai-current-document.js +4 -4
- package/dist/lib/ai-current-document.js.map +1 -1
- package/dist/lib/assets/upload.d.ts +31 -2
- package/dist/lib/assets/upload.js +61 -6
- package/dist/lib/assets/upload.js.map +1 -1
- package/dist/lib/clipboard/os-clipboard.d.ts +10 -2
- package/dist/lib/clipboard/os-clipboard.js +8 -4
- package/dist/lib/clipboard/os-clipboard.js.map +1 -1
- package/dist/lib/clipboard/paste-target.d.ts +18 -9
- package/dist/lib/clipboard/paste-target.js +8 -7
- package/dist/lib/clipboard/paste-target.js.map +1 -1
- package/dist/lib/cms/field-patch.d.ts +15 -0
- package/dist/lib/cms/field-patch.js +25 -0
- package/dist/lib/cms/field-patch.js.map +1 -0
- package/dist/lib/cms/published-documents.d.ts +1 -1
- package/dist/lib/cms/published-documents.js +1 -1
- package/dist/lib/cms/published-documents.js.map +1 -1
- package/dist/lib/cms-views/view-model.d.ts +3 -3
- package/dist/lib/collection-view/__fixtures__/document-writes.d.ts +6 -0
- package/dist/lib/collection-view/__fixtures__/document-writes.js +23 -0
- package/dist/lib/collection-view/__fixtures__/document-writes.js.map +1 -0
- package/dist/lib/collection-view/collection-view-source.d.ts +69 -6
- package/dist/lib/collection-view/collection-view-source.js.map +1 -1
- package/dist/lib/data/collection-content.d.ts +4 -13
- package/dist/lib/data/collection-content.js +11 -5
- package/dist/lib/data/collection-content.js.map +1 -1
- package/dist/lib/dnd/drop-rules.d.ts +25 -31
- package/dist/lib/dnd/drop-rules.js +53 -59
- package/dist/lib/dnd/drop-rules.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 +72 -15
- package/dist/lib/i18n/messages.de.js.map +1 -1
- package/dist/lib/i18n/messages.en.d.ts +61 -12
- package/dist/lib/i18n/messages.en.js +76 -16
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/operations/__fixtures__/write-document.d.ts +30 -0
- package/dist/lib/operations/__fixtures__/write-document.js +16 -0
- package/dist/lib/operations/__fixtures__/write-document.js.map +1 -0
- package/dist/lib/operations/cms-persistence.d.ts +124 -31
- package/dist/lib/operations/cms-persistence.js +447 -68
- package/dist/lib/operations/cms-persistence.js.map +1 -1
- package/dist/lib/operations/config-manifest-lookup.d.ts +35 -0
- package/dist/lib/operations/config-manifest-lookup.js +56 -0
- package/dist/lib/operations/config-manifest-lookup.js.map +1 -0
- package/dist/lib/operations/project-runtime-config.d.ts +39 -0
- package/dist/lib/operations/project-runtime-config.js +54 -0
- package/dist/lib/operations/project-runtime-config.js.map +1 -0
- package/dist/lib/operations/publish-with-revision.d.ts +64 -0
- package/dist/lib/operations/publish-with-revision.js +66 -0
- package/dist/lib/operations/publish-with-revision.js.map +1 -0
- package/dist/lib/operations/runtime-validator.d.ts +32 -0
- package/dist/lib/operations/runtime-validator.js +18 -0
- package/dist/lib/operations/runtime-validator.js.map +1 -0
- package/dist/lib/operations/session-hydration.d.ts +31 -14
- package/dist/lib/operations/session-hydration.js +12 -16
- package/dist/lib/operations/session-hydration.js.map +1 -1
- package/dist/lib/operations/studio-operations.d.ts +59 -2
- package/dist/lib/operations/studio-operations.js +76 -14
- package/dist/lib/operations/studio-operations.js.map +1 -1
- package/dist/lib/persistence/convex-adapter.d.ts +13 -5
- package/dist/lib/persistence/convex-adapter.js +189 -74
- package/dist/lib/persistence/convex-adapter.js.map +1 -1
- package/dist/lib/persistence/convex-client.d.ts +65 -5
- package/dist/lib/persistence/convex-client.js +106 -3
- package/dist/lib/persistence/convex-client.js.map +1 -1
- package/dist/lib/persistence/index.js +17 -18
- package/dist/lib/persistence/index.js.map +1 -1
- package/dist/lib/persona/labels.js +4 -1
- package/dist/lib/persona/labels.js.map +1 -1
- package/dist/lib/query/operations-query.d.ts +1 -1
- package/dist/lib/query/operations-query.js +1 -1
- package/dist/lib/query/operations-query.js.map +1 -1
- package/dist/lib/references/impact.d.ts +21 -15
- package/dist/lib/references/impact.js +13 -26
- package/dist/lib/references/impact.js.map +1 -1
- package/dist/lib/references/references-store.d.ts +9 -0
- package/dist/lib/references/references-store.js +24 -4
- package/dist/lib/references/references-store.js.map +1 -1
- package/dist/lib/routes/route-issues.d.ts +6 -6
- package/dist/lib/routes/route-issues.js +26 -80
- package/dist/lib/routes/route-issues.js.map +1 -1
- package/dist/lib/workspace/config-issues.js +2 -1
- package/dist/lib/workspace/config-issues.js.map +1 -1
- package/dist/lib/workspace/index.d.ts +31 -1
- package/dist/lib/workspace/index.js +64 -17
- package/dist/lib/workspace/index.js.map +1 -1
- package/dist/lib/workspace/switcher-source.d.ts +3 -3
- package/dist/lib/workspace/switcher-source.js.map +1 -1
- package/dist/lib/workspace/workspace-source.d.ts +2 -2
- package/dist/lib/workspace/workspace-source.js +2 -1
- package/dist/lib/workspace/workspace-source.js.map +1 -1
- package/package.json +3 -3
- package/dist/components/cms/cms-composition-validators.d.ts +0 -16
- package/dist/components/cms/cms-composition-validators.js +0 -133
- package/dist/components/cms/cms-composition-validators.js.map +0 -1
- package/dist/components/cms/publish-clean.d.ts +0 -28
- package/dist/components/cms/publish-clean.js +0 -38
- package/dist/components/cms/publish-clean.js.map +0 -1
- package/dist/components/cms/use-save-mode.d.ts +0 -35
- package/dist/components/cms/use-save-mode.js +0 -54
- package/dist/components/cms/use-save-mode.js.map +0 -1
- package/dist/lib/assets/asset-placements.d.ts +0 -28
- package/dist/lib/assets/asset-placements.js +0 -83
- package/dist/lib/assets/asset-placements.js.map +0 -1
- package/dist/lib/cms/document-gate.d.ts +0 -47
- package/dist/lib/cms/document-gate.js +0 -61
- package/dist/lib/cms/document-gate.js.map +0 -1
package/dist/lib/ai/tools.js
CHANGED
|
@@ -32,11 +32,13 @@
|
|
|
32
32
|
* with the hand-rolled orchestrator (EC-334 slice 2).
|
|
33
33
|
*/
|
|
34
34
|
import { z } from 'zod';
|
|
35
|
-
import {
|
|
36
|
-
import { parseRichTextValue, richTextValueToMarkdownProse } from '@elytracms/core/rich-text';
|
|
35
|
+
import { resolveDocumentTitle } from '@elytracms/core/cms-core';
|
|
37
36
|
import { applyContentWithShape } from './apply-content.js';
|
|
37
|
+
import { describeComponentProps } from './chat-context.js';
|
|
38
|
+
import { assetCandidatesOf, relationCandidatesOf } from './leash.js';
|
|
38
39
|
import { translateDocument } from './translate-document.js';
|
|
39
40
|
import { buildUpdateProposal } from './update-fields.js';
|
|
41
|
+
import { componentIdsOf, toWriterDocument } from './writer-form.js';
|
|
40
42
|
import { aiProvenance } from './provenance.js';
|
|
41
43
|
/** Per-search result cap (protects the wire — results become model context). */
|
|
42
44
|
export const DEFAULT_SEARCH_LIMIT = 20;
|
|
@@ -76,9 +78,11 @@ export const chatToolDefinitions = {
|
|
|
76
78
|
}),
|
|
77
79
|
},
|
|
78
80
|
getDocument: {
|
|
79
|
-
description: 'Fetch one full document (values + localized values +
|
|
80
|
-
'id. Omit both to read the document currently open in the editor. Rich-text
|
|
81
|
-
'
|
|
81
|
+
description: 'Fetch one full document (values + localized values + component ids) by collection and ' +
|
|
82
|
+
'id. Omit both to read the document currently open in the editor. Rich-text values — ' +
|
|
83
|
+
'at any depth — are returned as markdown strings where faithfully expressible. ' +
|
|
84
|
+
'`components` lists, for every component on the document, the props you may change ' +
|
|
85
|
+
'with updateFields and the rules each value must satisfy.',
|
|
82
86
|
inputSchema: z.object({
|
|
83
87
|
collection: z
|
|
84
88
|
.string()
|
|
@@ -103,11 +107,13 @@ export const chatToolDefinitions = {
|
|
|
103
107
|
description: 'Change specific fields of an EXISTING document as a reviewable proposal — THE ' +
|
|
104
108
|
'tool for every edit request (change / fix / remove / replace / rewrite wording, ' +
|
|
105
109
|
'values, or a page-builder element). Call getDocument first to see the current ' +
|
|
106
|
-
'values (and
|
|
107
|
-
'(e.g. a Hero headline)
|
|
108
|
-
'
|
|
109
|
-
'
|
|
110
|
-
'
|
|
110
|
+
'values (and component ids), then pass ONLY the fields that change. A component ' +
|
|
111
|
+
'prop (e.g. a Hero headline) — at any depth: a top-level block, a child inside a ' +
|
|
112
|
+
'section, a component embedded in rich text — is addressed as field + blockId + ' +
|
|
113
|
+
'prop. Components are never added, moved or removed by the assistant (that is done ' +
|
|
114
|
+
'on the canvas). Omit collection and id to target the document currently open in ' +
|
|
115
|
+
'the editor. A rich-text value takes the FULL new value as a MARKDOWN string ' +
|
|
116
|
+
'(headings, lists, links, bold/italic, blockquotes — no images, code, tables, or HTML).',
|
|
111
117
|
inputSchema: z.object({
|
|
112
118
|
collection: z
|
|
113
119
|
.string()
|
|
@@ -130,11 +136,11 @@ export const chatToolDefinitions = {
|
|
|
130
136
|
blockId: z
|
|
131
137
|
.string()
|
|
132
138
|
.optional()
|
|
133
|
-
.describe('
|
|
139
|
+
.describe('To change a component prop: the component id (from getDocument) — any depth.'),
|
|
134
140
|
prop: z
|
|
135
141
|
.string()
|
|
136
142
|
.optional()
|
|
137
|
-
.describe('With blockId: the component prop to change.'),
|
|
143
|
+
.describe('With blockId: the component prop to change (from getDocument `components`).'),
|
|
138
144
|
value: z
|
|
139
145
|
.unknown()
|
|
140
146
|
.optional()
|
|
@@ -204,39 +210,29 @@ export function createChatCandidateStore() {
|
|
|
204
210
|
for (const result of results)
|
|
205
211
|
searchedAssets.set(result.id, result);
|
|
206
212
|
},
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
for (const field of collection.fields) {
|
|
210
|
-
if (field.type !== 'relation')
|
|
211
|
-
continue;
|
|
212
|
-
const found = searched.get(field.target);
|
|
213
|
-
if (!found || found.size === 0)
|
|
214
|
-
continue;
|
|
215
|
-
candidates[field.name] = [...found.values()].map((r) => ({ id: r.id, ...(r.title ? { label: r.title } : {}) }));
|
|
216
|
-
}
|
|
217
|
-
return candidates;
|
|
213
|
+
relationCandidates(target) {
|
|
214
|
+
return relationCandidatesOf(searched.get(target)?.values() ?? []);
|
|
218
215
|
},
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (field.type !== 'asset')
|
|
226
|
-
continue;
|
|
227
|
-
// EC-588 (A4): the field's enum is the pool filtered by ITS `accept` — an image
|
|
228
|
-
// field is never offered a PDF. The validator re-run at apply is the guarantee
|
|
229
|
-
// (`findAsset` checks the record); this keeps the model from spending its
|
|
230
|
-
// repair budget on a mismatch the leash can rule out up front.
|
|
231
|
-
const fitting = pool.filter((asset) => assetMatchesAccept(asset, field.accept));
|
|
232
|
-
if (fitting.length === 0)
|
|
233
|
-
continue;
|
|
234
|
-
candidates[field.name] = fitting.map((a) => ({ id: a.id, ...(a.title ? { label: a.title } : {}) }));
|
|
235
|
-
}
|
|
236
|
-
return candidates;
|
|
216
|
+
// EC-588 (A4): a position's enum is the pool filtered by ITS `accept` — an image
|
|
217
|
+
// field is never offered a PDF. The validator re-run at apply is the guarantee
|
|
218
|
+
// (`findAsset` checks the record); this keeps the model from spending its repair
|
|
219
|
+
// budget on a mismatch the leash can rule out up front.
|
|
220
|
+
assetCandidates(field) {
|
|
221
|
+
return assetCandidatesOf(field, searchedAssets.values());
|
|
237
222
|
},
|
|
238
223
|
};
|
|
239
224
|
}
|
|
225
|
+
/** A translate skip as one model-facing phrase: `menu[1].label (de): the provider returned no text`. */
|
|
226
|
+
export function describeTranslateSkip(skip) {
|
|
227
|
+
const where = skip.at.reduce((out, key) => (typeof key === 'number' ? `${out}[${key}]` : `${out}.${key}`), skip.field);
|
|
228
|
+
const component = skip.component ? ` in ${skip.component.componentId} "${skip.component.nodeId}"` : '';
|
|
229
|
+
const why = skip.reason === 'unreadable'
|
|
230
|
+
? 'the stored value is not readable as its type'
|
|
231
|
+
: skip.reason === 'not-returned'
|
|
232
|
+
? 'the provider returned no text'
|
|
233
|
+
: 'the translation did not keep its formatting, links or embeds, so the original was kept';
|
|
234
|
+
return `${where}${component} (${skip.locale}): ${why}`;
|
|
235
|
+
}
|
|
240
236
|
function issueSummary(issues) {
|
|
241
237
|
return issues
|
|
242
238
|
.slice(0, 5)
|
|
@@ -244,43 +240,32 @@ function issueSummary(issues) {
|
|
|
244
240
|
.join('; ');
|
|
245
241
|
}
|
|
246
242
|
/**
|
|
247
|
-
* The
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* its `{ version,
|
|
252
|
-
*
|
|
253
|
-
*
|
|
243
|
+
* The `getDocument` output (EC-379 → EC-593): the document in the form the model reads
|
|
244
|
+
* — the ONE converter's read side (`toWriterDocument`), so rich text is a markdown
|
|
245
|
+
* string at EVERY depth where the engine's loss-guarded inverse can express it
|
|
246
|
+
* faithfully (a top-level field, an object sub-field, a repeater item, a component's
|
|
247
|
+
* rich-text prop), and keeps its stored `{ version: 2, content }` value otherwise (embeds,
|
|
248
|
+
* internal `ref` links, out-of-subset marks), so nothing the model later echoes back can
|
|
249
|
+
* silently lose structure. It used to project TOP-LEVEL rich text only (SHAPES #29: a
|
|
250
|
+
* nested value read as v2 while every writer was told markdown).
|
|
251
|
+
*
|
|
252
|
+
* `components` is the catalog's prop half (RULES F3d): for every component on the
|
|
253
|
+
* document, the props `updateFields` may change and the rules each value must satisfy,
|
|
254
|
+
* read off the same declarations the validator judges (`lookupManifest`). Applies to
|
|
255
|
+
* the TOOL OUTPUT only; the proposal/apply paths always read the raw stored document.
|
|
254
256
|
*/
|
|
255
|
-
export function
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
continue;
|
|
267
|
-
const parsed = parseRichTextValue(value);
|
|
268
|
-
if (!parsed.ok)
|
|
269
|
-
continue;
|
|
270
|
-
const markdown = richTextValueToMarkdownProse(parsed.value);
|
|
271
|
-
if (markdown === undefined)
|
|
272
|
-
continue; // not faithfully expressible → keep the envelope
|
|
273
|
-
if (next === bucket)
|
|
274
|
-
next = { ...bucket };
|
|
275
|
-
next[name] = markdown;
|
|
276
|
-
}
|
|
277
|
-
return next;
|
|
257
|
+
export function modelFacingDocument(document, collection, validateOptions = {}) {
|
|
258
|
+
const lookupManifest = validateOptions.lookupManifest;
|
|
259
|
+
const read = toWriterDocument(collection, document, lookupManifest ? { lookupManifest } : {});
|
|
260
|
+
if (!lookupManifest)
|
|
261
|
+
return read;
|
|
262
|
+
const ids = componentIdsOf(collection, document, lookupManifest);
|
|
263
|
+
if (ids.length === 0)
|
|
264
|
+
return read;
|
|
265
|
+
return {
|
|
266
|
+
...read,
|
|
267
|
+
components: Object.fromEntries(ids.map((id) => [id, describeComponentProps(lookupManifest(id) ?? {})])),
|
|
278
268
|
};
|
|
279
|
-
const values = mapBucket(document.values);
|
|
280
|
-
const localized = document.localized
|
|
281
|
-
? Object.fromEntries(Object.entries(document.localized).map(([locale, bucket]) => [locale, mapBucket(bucket)]))
|
|
282
|
-
: undefined;
|
|
283
|
-
return { ...document, values, ...(localized ? { localized } : {}) };
|
|
284
269
|
}
|
|
285
270
|
/**
|
|
286
271
|
* Build the client executor map. Every entry validates its input against
|
|
@@ -345,9 +330,9 @@ export function createChatToolExecutor(options) {
|
|
|
345
330
|
errorText: `Document "${target.ref.collection}/${target.ref.id}" was not found.`,
|
|
346
331
|
};
|
|
347
332
|
}
|
|
348
|
-
// EC-379: the model reads (and re-authors)
|
|
333
|
+
// EC-379/EC-593: the model reads (and re-authors) every value in its writer form.
|
|
349
334
|
const collection = collectionById(target.ref.collection);
|
|
350
|
-
return { ok: true, output: collection ?
|
|
335
|
+
return { ok: true, output: collection ? modelFacingDocument(document, collection, validateOptions) : document };
|
|
351
336
|
}
|
|
352
337
|
/** EC-378 — the edit-flow terminal tool: current doc + model-authored changes → validated proposal. */
|
|
353
338
|
async function updateFields(toolCallId, input) {
|
|
@@ -376,8 +361,8 @@ export function createChatToolExecutor(options) {
|
|
|
376
361
|
collection,
|
|
377
362
|
document,
|
|
378
363
|
changes: input.changes,
|
|
379
|
-
|
|
380
|
-
|
|
364
|
+
// EC-381 → EC-593: the store IS the leash, asked per position.
|
|
365
|
+
leash: options.candidates,
|
|
381
366
|
...(options.locale ? { locale: options.locale } : {}),
|
|
382
367
|
validateOptions,
|
|
383
368
|
});
|
|
@@ -401,6 +386,7 @@ export function createChatToolExecutor(options) {
|
|
|
401
386
|
collection: collection.id,
|
|
402
387
|
documentId: document.id,
|
|
403
388
|
patch: result.patch,
|
|
389
|
+
patches: result.patches,
|
|
404
390
|
provenance: aiProvenance(options.provider),
|
|
405
391
|
attempts: 1,
|
|
406
392
|
issues: result.issues,
|
|
@@ -437,10 +423,9 @@ export function createChatToolExecutor(options) {
|
|
|
437
423
|
documentId,
|
|
438
424
|
instruction: input.instruction,
|
|
439
425
|
...(knowledge ? { knowledge } : {}),
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
assetCandidates: options.candidates.assetCandidatesFor(collection),
|
|
426
|
+
// EC-381 → EC-593: relation and asset positions — at every depth — are leashed
|
|
427
|
+
// to what was searched (the store IS the leash).
|
|
428
|
+
leash: options.candidates,
|
|
444
429
|
...(options.locale ? { locale: options.locale } : {}),
|
|
445
430
|
validateOptions,
|
|
446
431
|
...(options.maxRepairAttempts !== undefined
|
|
@@ -502,7 +487,10 @@ export function createChatToolExecutor(options) {
|
|
|
502
487
|
registry: options.registry,
|
|
503
488
|
validateOptions,
|
|
504
489
|
});
|
|
505
|
-
|
|
490
|
+
// EC-593 (ratified 4e): what could not be translated is REPORTED — to the model
|
|
491
|
+
// (it tells the user) and on the proposal the editor reviews — never skipped silently.
|
|
492
|
+
const skipped = result.skipped.map(describeTranslateSkip);
|
|
493
|
+
if (result.total === 0 && skipped.length === 0) {
|
|
506
494
|
return {
|
|
507
495
|
ok: true,
|
|
508
496
|
output: {
|
|
@@ -512,7 +500,12 @@ export function createChatToolExecutor(options) {
|
|
|
512
500
|
};
|
|
513
501
|
}
|
|
514
502
|
if (result.translated === 0) {
|
|
515
|
-
return {
|
|
503
|
+
return {
|
|
504
|
+
ok: false,
|
|
505
|
+
errorText: skipped.length > 0
|
|
506
|
+
? `The translation did not produce any content. Not translated: ${skipped.slice(0, 5).join('; ')}`
|
|
507
|
+
: 'The translation did not produce any content.',
|
|
508
|
+
};
|
|
516
509
|
}
|
|
517
510
|
// EC-473 established that a translated draft is validated before it is proposed
|
|
518
511
|
// (this path once proposed unvalidated content). EC-497 moved the gate INTO the
|
|
@@ -536,10 +529,12 @@ export function createChatToolExecutor(options) {
|
|
|
536
529
|
values: result.document.values,
|
|
537
530
|
...(result.document.localized ? { localized: result.document.localized } : {}),
|
|
538
531
|
},
|
|
532
|
+
patches: result.patches,
|
|
539
533
|
provenance: result.provenance,
|
|
540
534
|
attempts: 1,
|
|
541
535
|
// Warnings ride onto the proposal like every other path's (EC-496 renders them).
|
|
542
536
|
issues: [...result.issues],
|
|
537
|
+
...(result.skipped.length > 0 ? { skipped: [...result.skipped] } : {}),
|
|
543
538
|
before: {
|
|
544
539
|
values: document.values,
|
|
545
540
|
...(document.localized ? { localized: document.localized } : {}),
|
|
@@ -552,7 +547,10 @@ export function createChatToolExecutor(options) {
|
|
|
552
547
|
collection: collection.id,
|
|
553
548
|
documentId: document.id,
|
|
554
549
|
translatedUnits: result.translated,
|
|
555
|
-
|
|
550
|
+
...(skipped.length > 0 ? { notTranslated: skipped } : {}),
|
|
551
|
+
note: skipped.length > 0
|
|
552
|
+
? 'Translation proposal created; the editor reviews and applies it in the studio. Tell the user which positions were NOT translated (notTranslated).'
|
|
553
|
+
: 'Translation proposal created; the editor reviews and applies it in the studio.',
|
|
556
554
|
},
|
|
557
555
|
};
|
|
558
556
|
}
|
package/dist/lib/ai/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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M,CAAC,IAA4C,CAAC,CAAA;oBAC/E,KAAK,gBAAgB;wBACnB,OAAO,MAAM,cAAc,CACzB,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,IAAmD,CAC3D,CAAA;oBACH,KAAK,cAAc;wBACjB,OAAO,MAAM,YAAY,CACvB,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,IAA0E,CAClF,CAAA;oBACH,KAAK,mBAAmB;wBACtB,OAAO,MAAM,SAAS,CACpB,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,IAA2D,CACnE,CAAA;oBACH;wBACE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAA;gBACvE,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,EAAE,EAAE,KAAK;oBACT,SAAS,EAAE,OAAO,IAAI,CAAC,QAAQ,iBAAiB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE;iBAC3G,CAAA;YACH,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["/**\n * The narrow tool set the assistant works against (EC-199, reshaped by EC-334).\n *\n * Per the ratified AD, tools execute CLIENT-side against the operations layer with\n * the user's own session. This module carries the three pieces of that contract:\n *\n * 1. {@link chatToolDefinitions} — the SDK-native tool DEFINITIONS the route's\n * chat branch declares in `streamText`, deliberately WITHOUT `execute`, so the\n * SDK forwards every call to the client (the route stays a zero-data-access\n * proxy). Plain `{ description, inputSchema }` objects with zod schemas —\n * structurally the SDK's `FunctionTool`, with no SDK import (bundle discipline).\n * 2. {@link ChatToolReaders} — the operations-backed read interface the studio\n * binds client-side (search / list / get). Reads only — the engine never gains\n * a write path; apply is a separate, human-gated draft write.\n * 3. {@link createChatToolExecutor} — the client executor map `useChat`'s\n * `onToolCall` dispatches into. Readers pass through; the terminal tools run\n * the deterministic engines (`applyContentWithShape` / `translateDocument` /\n * `buildUpdateProposal`) and return a COMPACT proposal summary as the tool\n * output — the full proposal goes to the review UI via\n * `onProposal(toolCallId, …)`, never to the model.\n *\n * EC-378: `updateFields` is the edit-flow terminal tool — the model authors\n * per-field changes directly (it has `getDocument` output + the conversation as\n * context); the executor reads the CURRENT document, builds a validated update\n * proposal (`buildUpdateProposal`), and hands it to the review sink. Its target\n * (and `getDocument`'s) may be omitted to mean the document currently open in\n * the editor — resolved via the {@link ChatToolExecutorOptions.currentDocument}\n * seam ({@link resolveDocumentTarget}); the context block the panel injects is\n * ADVISORY, the resolution here is what makes \"this document\" deterministic.\n *\n * The EC-199 planner enum/schema (`plannerSchema` / `parsePlannerAction`) retired\n * with the hand-rolled orchestrator (EC-334 slice 2).\n */\nimport { z } from 'zod'\nimport { assetMatchesAccept, resolveDocumentTitle } from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n CollectionRegistry,\n CmsValidationIssue,\n FieldValues,\n LocaleConfig,\n ValidateDocumentOptions,\n} from '@elytracms/core/cms-core'\nimport { parseRichTextValue, richTextValueToMarkdownProse } from '@elytracms/core/rich-text'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport { applyContentWithShape } from './apply-content'\nimport { translateDocument } from './translate-document'\nimport { buildUpdateProposal } from './update-fields'\nimport type { UpdateFieldChange } from './update-fields'\nimport { aiProvenance } from './provenance'\nimport type { ChatProposal } from './chat-state'\nimport type {\n AiProvider,\n AssetCandidate,\n AssetCandidates,\n RelationCandidate,\n RelationCandidates,\n ResolvedKnowledge,\n} from './types'\n\n/** A document the model may reference as a relation target (from a `searchDocuments` read). */\nexport interface DocumentSearchResult {\n id: string\n title?: string\n}\n\n/**\n * An asset the model may reference (from a `listAssets` read). EC-588: it carries the\n * two facts a field's `accept` is judged on, so each asset field's candidates can be\n * filtered to what that field takes — and the model can see what each asset is.\n */\nexport interface AssetSearchResult {\n id: string\n title?: string\n contentType: string\n filename: string\n}\n\n/**\n * The client-side, operations-backed readers the executor calls. The studio binds\n * these to the user's authenticated operations client; tests bind an in-memory fake.\n * Reads only — there is no write tool (apply is a separate, human-gated draft write).\n */\nexport interface ChatToolReaders {\n searchDocuments(input: {\n collection: string\n query?: string\n limit?: number\n }): Promise<DocumentSearchResult[]>\n listAssets(input: { query?: string; limit?: number }): Promise<AssetSearchResult[]>\n /**\n * Fetch a full document (values + localized) — the translate flow and the model's\n * `getDocument` tool. Optional: a studio that only wires create can omit it.\n */\n getDocument?(input: { collection: string; id: string }): Promise<CmsDocument | null>\n}\n\n/** Per-search result cap (protects the wire — results become model context). */\nexport const DEFAULT_SEARCH_LIMIT = 20\n\n// --- SDK-native chat tool definitions (EC-334) --------------------------------------\n\n/**\n * One model-facing tool definition for the route's `streamText` call. Structurally\n * the SDK's `FunctionTool` WITHOUT `execute` (execution is client-side, always) —\n * typed locally so this module needs no SDK import.\n */\nexport interface ChatToolDefinition {\n description: string\n /** Zod input schema (the AI SDK accepts zod schemas as `inputSchema` directly). */\n inputSchema: z.ZodType\n}\n\n/**\n * The tool set the native chat branch declares (EC-334). No `execute` on any entry:\n * the SDK forwards each call to the client, which executes reads against the\n * operations layer with the user's session and posts the result back; the terminal\n * tools (`createDocument` / `translateDocument`) run the deterministic engines\n * client-side and return a compact proposal summary as the tool output. The route\n * itself never executes anything.\n *\n * Collections are NOT enum-leashed here — the route has zero data access, so it has\n * no catalog; the catalog reaches the model through the request `context` (system\n * prompt), and every id a proposal references must come from a tool RESULT\n * (client-validated; `applyContentWithShape` still enum-leashes relation ids).\n */\nexport const chatToolDefinitions = {\n searchDocuments: {\n description:\n 'Search documents in a collection. Use it to find the REAL ids a relation may ' +\n 'reference, or to locate an existing document — never invent an id. Returns ' +\n '{ id, title } summaries.',\n inputSchema: z.object({\n collection: z\n .string()\n .describe('Target collection id (from the catalog in the system context).'),\n query: z.string().optional().describe('Optional search text (title match).'),\n limit: z.number().int().positive().optional().describe('Max results.'),\n }),\n },\n listAssets: {\n description:\n 'List or search assets (images, files). Use it to find REAL asset ids — never ' +\n 'invent one. Returns { id, title, contentType, filename } summaries; an asset ' +\n 'field only takes the kinds it accepts.',\n inputSchema: z.object({\n query: z.string().optional().describe('Optional search text.'),\n limit: z.number().int().positive().optional().describe('Max results.'),\n }),\n },\n getDocument: {\n description:\n 'Fetch one full document (values + localized values + block ids) by collection and ' +\n 'id. Omit both to read the document currently open in the editor. Rich-text field ' +\n 'values are returned as markdown strings where faithfully expressible.',\n inputSchema: z.object({\n collection: z\n .string()\n .optional()\n .describe('Collection id. Omit to target the currently open document.'),\n id: z\n .string()\n .optional()\n .describe(\n 'Document id (from a searchDocuments result). Omit to target the currently open document.',\n ),\n }),\n },\n createDocument: {\n description:\n 'Author a NEW document in a collection as a reviewable draft proposal. Terminal ' +\n 'step of a creation request — call it once you have gathered the real ids you ' +\n 'need. Returns a compact proposal summary.',\n inputSchema: z.object({\n collection: z.string().describe('Target collection id.'),\n instruction: z.string().describe('What to write, refining the user request.'),\n }),\n },\n updateFields: {\n description:\n 'Change specific fields of an EXISTING document as a reviewable proposal — THE ' +\n 'tool for every edit request (change / fix / remove / replace / rewrite wording, ' +\n 'values, or a page-builder element). Call getDocument first to see the current ' +\n 'values (and block ids), then pass ONLY the fields that change. A block prop ' +\n '(e.g. a Hero headline) is addressed as field + blockId + prop. Omit collection ' +\n 'and id to target the document currently open in the editor. A rich-text field ' +\n 'takes the FULL new value as a MARKDOWN string (headings, lists, links, bold/italic, ' +\n 'blockquotes — no images, code, tables, or HTML).',\n inputSchema: z.object({\n collection: z\n .string()\n .optional()\n .describe('Collection id. Omit to target the currently open document.'),\n id: z\n .string()\n .optional()\n .describe('Document id. Omit to target the currently open document.'),\n changes: z\n .array(\n z.object({\n field: z\n .string()\n .describe(\n 'Field name from the collection schema. The catalog in the system context ' +\n 'lists every field with its type and the rules its value must satisfy.',\n ),\n locale: z\n .string()\n .optional()\n .describe(\n \"Locale of a LOCALIZED field (defaults to the editor's working locale).\",\n ),\n blockId: z\n .string()\n .optional()\n .describe('For a blocks field: the id of the block to change (from getDocument).'),\n prop: z\n .string()\n .optional()\n .describe('With blockId: the component prop to change.'),\n value: z\n .unknown()\n .optional()\n .describe(\n 'The new value (a rich-text field takes a markdown string). null clears the ' +\n \"field/prop. It MUST satisfy that field's rules as listed in the catalog \" +\n '(length bounds, format, allowed values, date range…); the studio validates ' +\n 'the merged document and rejects the proposal with the failing rules if it ' +\n 'does not. Where the catalog says further rules apply, keep the value ' +\n 'conventional and plausible.',\n ),\n }),\n )\n .min(1)\n .describe('The field changes — only what changes, never the whole document.'),\n }),\n },\n translateDocument: {\n description:\n 'Fill the EMPTY locale values of an existing document (search for it first to ' +\n 'get its id). Only for translation requests — never for edits (use updateFields ' +\n 'to change existing content). Returns a compact proposal summary.',\n inputSchema: z.object({\n collection: z.string().describe('Collection id.'),\n id: z.string().describe('Document id (from a searchDocuments result).'),\n locale: z.string().optional().describe('Target locale (defaults to the active one).'),\n }),\n },\n} satisfies Record<string, ChatToolDefinition>\n\n// --- Client executor map (EC-334) ----------------------------------------------------\n\n/** One forwarded tool call, as `useChat`'s `onToolCall` receives it. */\nexport interface ChatToolCall {\n toolCallId: string\n toolName: string\n input: unknown\n}\n\n/** The coordinates of the document currently open in the editor (EC-378 seam). */\nexport interface CurrentDocumentRef {\n collection: string\n id: string\n}\n\n/**\n * Resolve a tool call's target document from its (optional) input coordinates\n * and the current-document seam (EC-378). Deterministic:\n *\n * - both given → use them verbatim;\n * - both omitted → the currently open document (error when none is open);\n * - `collection` given with `id` omitted → the open document ONLY when the\n * collections match — a named collection must never silently cross onto a\n * different open document.\n *\n * Pure — tested directly; `getDocument` and `updateFields` share it.\n */\nexport function resolveDocumentTarget(\n input: { collection?: string; id?: string },\n current: CurrentDocumentRef | null | undefined,\n): { ok: true; ref: CurrentDocumentRef } | { ok: false; errorText: string } {\n if (input.collection !== undefined && input.id !== undefined) {\n return { ok: true, ref: { collection: input.collection, id: input.id } }\n }\n if (!current) {\n return {\n ok: false,\n errorText:\n 'No target document — pass collection and id, or ask the user to open the document in the editor.',\n }\n }\n if (input.collection !== undefined && input.collection !== current.collection) {\n return {\n ok: false,\n errorText: `The open document is in collection \"${current.collection}\", not \"${input.collection}\" — pass the document id explicitly.`,\n }\n }\n return { ok: true, ref: { collection: current.collection, id: input.id ?? current.id } }\n}\n\n/**\n * A tool execution outcome: an `output` posted back as the tool result, or an\n * `errorText` posted as an `output-error` part (the model sees the failure and\n * can react — never a thrown exception into the stream).\n */\nexport type ChatToolOutcome = { ok: true; output: unknown } | { ok: false; errorText: string }\n\n/**\n * The per-conversation candidate store: every `searchDocuments` result is recorded\n * per relation target collection, every `listAssets` result into one flat library\n * pool (EC-381), and the terminal tools may only reference the ids gathered here\n * (the `applyContentWithShape` / `buildUpdateProposal` enum + drop/loud leash makes\n * a hallucinated relation OR asset id structurally unrepresentable / fail loud).\n * Held by the panel per conversation — a new conversation (EC-380 clear) starts an\n * empty store.\n */\nexport interface ChatCandidateStore {\n record(collection: string, results: readonly DocumentSearchResult[]): void\n /** Record every `listAssets` result into the flat library pool (EC-381). */\n recordAssets(results: readonly AssetSearchResult[]): void\n /** Candidates for a target collection's relation fields, keyed by field name. */\n candidatesFor(collection: CollectionDef): RelationCandidates\n /**\n * Candidates for a target collection's asset/image fields (EC-381), keyed by\n * field name — the one flat searched-asset pool (`listAssets` has no field\n * dimension), filtered per field by that field's `accept` (EC-588). A field with no\n * fitting candidate is absent, so it is omitted from the shape (empty beats wrong).\n */\n assetCandidatesFor(collection: CollectionDef): AssetCandidates\n}\n\nexport function createChatCandidateStore(): ChatCandidateStore {\n const searched = new Map<string, Map<string, DocumentSearchResult>>()\n const searchedAssets = new Map<string, AssetSearchResult>()\n return {\n record(collection, results) {\n const byId = searched.get(collection) ?? new Map<string, DocumentSearchResult>()\n for (const result of results) byId.set(result.id, result)\n searched.set(collection, byId)\n },\n recordAssets(results) {\n for (const result of results) searchedAssets.set(result.id, result)\n },\n candidatesFor(collection) {\n const candidates: RelationCandidates = {}\n for (const field of collection.fields) {\n if (field.type !== 'relation') continue\n const found = searched.get(field.target)\n if (!found || found.size === 0) continue\n candidates[field.name] = [...found.values()].map(\n (r): RelationCandidate => ({ id: r.id, ...(r.title ? { label: r.title } : {}) }),\n )\n }\n return candidates\n },\n assetCandidatesFor(collection) {\n const candidates: AssetCandidates = {}\n if (searchedAssets.size === 0) return candidates\n const pool = [...searchedAssets.values()]\n for (const field of collection.fields) {\n if (field.type !== 'asset') continue\n // EC-588 (A4): the field's enum is the pool filtered by ITS `accept` — an image\n // field is never offered a PDF. The validator re-run at apply is the guarantee\n // (`findAsset` checks the record); this keeps the model from spending its\n // repair budget on a mismatch the leash can rule out up front.\n const fitting = pool.filter((asset) => assetMatchesAccept(asset, field.accept))\n if (fitting.length === 0) continue\n candidates[field.name] = fitting.map(\n (a): AssetCandidate => ({ id: a.id, ...(a.title ? { label: a.title } : {}) }),\n )\n }\n return candidates\n },\n }\n}\n\nexport interface ChatToolExecutorOptions {\n /** The (route) provider the terminal engines proxy their model calls through. */\n provider: AiProvider\n registry: CollectionRegistry\n /** The collections the assistant may target (unknown ids fail loud). */\n collections: readonly CollectionDef[]\n /** Operations-backed readers (client-side, user's session). */\n readers: ChatToolReaders\n /** Mint a fresh document id for a new draft (studio: the CMS store's minter). */\n mintDocumentId: (collectionId: string) => string\n /** Per-conversation relation-candidate store (see {@link createChatCandidateStore}). */\n candidates: ChatCandidateStore\n /**\n * Full proposal sink, keyed by `toolCallId` — the review UI's entry point.\n * The tool OUTPUT stays a compact summary; the patch never reaches the model.\n */\n onProposal: (toolCallId: string, proposal: ChatProposal) => void\n /**\n * The document currently open in the editor (EC-378 seam) — a thunk read at\n * EXECUTION time, so \"this document\" resolves against what is open NOW.\n * `getDocument` / `updateFields` fall back to it when the model omits the\n * target (see {@link resolveDocumentTarget}).\n */\n currentDocument?: () => CurrentDocumentRef | null | undefined\n /** Current knowledge snapshot (thunk — the body thunk refreshes it per request). */\n knowledge?: () => ResolvedKnowledge | undefined\n /** Component manifests — context for `allow`-leashed richText/blocks fields. */\n components?: readonly ComponentManifest[]\n /** Target locale for localized fields. */\n locale?: string\n /** Locale config — required for `translateDocument`. */\n localeConfig?: LocaleConfig\n /**\n * THE validation option bag (EC-497) — the CMS session's\n * `gateValidateOptions(...)`, forwarded whole to every engine below. EC-473\n * made the assistant's gate the editor's gate; passing one bag instead of five\n * keys makes it stay that way, because a key can no longer be dropped by being\n * forgotten at one of the three call sites this replaced.\n */\n validateOptions?: ValidateDocumentOptions\n /** Max repair attempts inside `applyContentWithShape`. */\n maxRepairAttempts?: number\n /** Per-search result cap (default {@link DEFAULT_SEARCH_LIMIT}). */\n searchLimit?: number\n}\n\n/** The executor `useChat`'s `onToolCall` dispatches into. */\nexport interface ChatToolExecutor {\n execute(call: ChatToolCall): Promise<ChatToolOutcome>\n}\n\nfunction issueSummary(issues: readonly CmsValidationIssue[]): string {\n return issues\n .slice(0, 5)\n .map((issue) => issue.message)\n .join('; ')\n}\n\n/**\n * The MODEL-facing view of a document (EC-379): rich-text field values are\n * projected to markdown strings — but ONLY when the engine's loss-guarded\n * inverse can express them faithfully (subset-only content, round-trip proven).\n * A document carrying embeds, internal `ref` links, or out-of-subset marks keeps\n * its `{ version, doc }` envelope, so nothing the model later echoes back can\n * silently lose structure. Applies to the `getDocument` TOOL OUTPUT only; the\n * proposal/apply paths always read the raw stored document.\n */\nexport function projectRichTextAsMarkdown(\n document: CmsDocument,\n collection: CollectionDef,\n): CmsDocument {\n const richTextFields = collection.fields\n .filter((field) => field.type === 'richText')\n .map((field) => field.name)\n if (richTextFields.length === 0) return document\n const mapBucket = (bucket: FieldValues): FieldValues => {\n let next = bucket\n for (const name of richTextFields) {\n const value = next[name]\n if (value === undefined || value === null) continue\n const parsed = parseRichTextValue(value)\n if (!parsed.ok) continue\n const markdown = richTextValueToMarkdownProse(parsed.value)\n if (markdown === undefined) continue // not faithfully expressible → keep the envelope\n if (next === bucket) next = { ...bucket }\n next[name] = markdown\n }\n return next\n }\n const values = mapBucket(document.values)\n const localized = document.localized\n ? Object.fromEntries(\n Object.entries(document.localized).map(([locale, bucket]) => [locale, mapBucket(bucket)]),\n )\n : undefined\n return { ...document, values, ...(localized ? { localized } : {}) }\n}\n\n/**\n * Build the client executor map. Every entry validates its input against\n * {@link chatToolDefinitions}' zod schema (the route validates UIMessages only\n * structurally — deep input validation is the client's), executes with the\n * user's session, and returns a JSON-safe outcome. EC-378's `updateFields`\n * lands as one more case in this dispatch.\n */\nexport function createChatToolExecutor(options: ChatToolExecutorOptions): ChatToolExecutor {\n const searchLimit = options.searchLimit ?? DEFAULT_SEARCH_LIMIT\n\n /**\n * EC-497 — the ONE bag every engine below is handed, assembled in exactly one\n * place instead of at each of the three former call sites.\n *\n * The executor's own `localeConfig` is a FLOOR, never an override: the session's\n * bag wins wherever it speaks, but a bag that omits the project's locales must\n * not be able to make the gate locale-blind — a localized bound would then go\n * unchecked, which is precisely the class of hole this task closed.\n */\n const validateOptions: ValidateDocumentOptions = {\n ...(options.localeConfig ? { localeConfig: options.localeConfig } : {}),\n ...(options.validateOptions ?? {}),\n }\n\n function collectionById(id: string): CollectionDef | undefined {\n return options.collections.find((c) => c.id === id)\n }\n\n async function searchDocuments(input: {\n collection: string\n query?: string\n limit?: number\n }): Promise<ChatToolOutcome> {\n if (!collectionById(input.collection)) {\n return { ok: false, errorText: `Unknown collection \"${input.collection}\" — use a collection id from the catalog.` }\n }\n const limit = Math.min(input.limit ?? searchLimit, searchLimit)\n const results = (\n await options.readers.searchDocuments({\n collection: input.collection,\n ...(input.query ? { query: input.query } : {}),\n limit,\n })\n ).slice(0, limit)\n options.candidates.record(input.collection, results)\n return { ok: true, output: results }\n }\n\n async function listAssets(input: { query?: string; limit?: number }): Promise<ChatToolOutcome> {\n const limit = Math.min(input.limit ?? searchLimit, searchLimit)\n const results = (\n await options.readers.listAssets({\n ...(input.query ? { query: input.query } : {}),\n limit,\n })\n ).slice(0, limit)\n // EC-381 — leash asset fields to what the model actually searched, exactly as\n // searchDocuments feeds the relation store.\n options.candidates.recordAssets(results)\n return { ok: true, output: results }\n }\n\n async function getDocument(input: {\n collection?: string\n id?: string\n }): Promise<ChatToolOutcome> {\n if (!options.readers.getDocument) {\n return { ok: false, errorText: 'Reading documents is not available here.' }\n }\n const target = resolveDocumentTarget(input, options.currentDocument?.())\n if (!target.ok) return { ok: false, errorText: target.errorText }\n const document = await options.readers.getDocument(target.ref)\n if (!document) {\n return {\n ok: false,\n errorText: `Document \"${target.ref.collection}/${target.ref.id}\" was not found.`,\n }\n }\n // EC-379: the model reads (and re-authors) rich text as markdown.\n const collection = collectionById(target.ref.collection)\n return { ok: true, output: collection ? projectRichTextAsMarkdown(document, collection) : document }\n }\n\n /** EC-378 — the edit-flow terminal tool: current doc + model-authored changes → validated proposal. */\n async function updateFields(\n toolCallId: string,\n input: { collection?: string; id?: string; changes: UpdateFieldChange[] },\n ): Promise<ChatToolOutcome> {\n if (!options.readers.getDocument) {\n return { ok: false, errorText: 'Reading documents is not available here.' }\n }\n const target = resolveDocumentTarget(input, options.currentDocument?.())\n if (!target.ok) return { ok: false, errorText: target.errorText }\n const collection = collectionById(target.ref.collection)\n if (!collection) {\n return {\n ok: false,\n errorText: `Unknown collection \"${target.ref.collection}\" — use a collection id from the catalog.`,\n }\n }\n const document = await options.readers.getDocument(target.ref)\n if (!document) {\n return {\n ok: false,\n errorText: `Document \"${target.ref.collection}/${target.ref.id}\" was not found.`,\n }\n }\n const result = buildUpdateProposal({\n registry: options.registry,\n collection,\n document,\n changes: input.changes,\n candidates: options.candidates.candidatesFor(collection),\n assetCandidates: options.candidates.assetCandidatesFor(collection),\n ...(options.locale ? { locale: options.locale } : {}),\n validateOptions,\n })\n if (!result.ok) {\n return {\n ok: false,\n errorText: `The proposed changes did not pass validation: ${issueSummary(result.issues)}`,\n }\n }\n if (result.kind === 'no-change') {\n return {\n ok: true,\n output: {\n status: 'no-change',\n note: 'The requested change matches the current values — there is nothing to update.',\n },\n }\n }\n options.onProposal(toolCallId, {\n origin: 'update',\n collection: collection.id,\n documentId: document.id,\n patch: result.patch,\n provenance: aiProvenance(options.provider),\n attempts: 1,\n issues: result.issues,\n before: result.before,\n })\n // Compact summary only — the full patch goes to the review UI, not the model.\n const titleValues = {\n ...result.patch.values,\n ...(options.locale ? result.patch.localized?.[options.locale] : {}),\n }\n return {\n ok: true,\n output: {\n status: 'proposed',\n collection: collection.id,\n documentId: document.id,\n title: resolveDocumentTitle(collection, titleValues, document.id),\n changedFields: result.changedFields,\n note: 'Update proposal created; the editor reviews and applies it in the studio. Summarize the change briefly — do not repeat the content.',\n },\n }\n }\n\n async function createDocument(\n toolCallId: string,\n input: { collection: string; instruction: string },\n ): Promise<ChatToolOutcome> {\n const collection = collectionById(input.collection)\n if (!collection) {\n return { ok: false, errorText: `Unknown collection \"${input.collection}\" — use a collection id from the catalog.` }\n }\n const documentId = options.mintDocumentId(collection.id)\n const knowledge = options.knowledge?.()\n const result = await applyContentWithShape({\n provider: options.provider,\n registry: options.registry,\n collection,\n documentId,\n instruction: input.instruction,\n ...(knowledge ? { knowledge } : {}),\n ...(options.components ? { components: options.components } : {}),\n candidates: options.candidates.candidatesFor(collection),\n // EC-381 — asset/image fields are leashed to searched library assets.\n assetCandidates: options.candidates.assetCandidatesFor(collection),\n ...(options.locale ? { locale: options.locale } : {}),\n validateOptions,\n ...(options.maxRepairAttempts !== undefined\n ? { maxRepairAttempts: options.maxRepairAttempts }\n : {}),\n })\n if (!result.ok) {\n return {\n ok: false,\n errorText: `The drafted ${collection.id} did not pass validation: ${issueSummary(result.issues)}`,\n }\n }\n options.onProposal(toolCallId, {\n origin: 'create',\n collection: collection.id,\n documentId,\n patch: result.patch,\n provenance: result.provenance,\n attempts: result.attempts,\n issues: result.issues,\n })\n // Compact summary only — the full patch goes to the review UI, not the model.\n return {\n ok: true,\n output: {\n status: 'proposed',\n collection: collection.id,\n documentId,\n title: resolveDocumentTitle(collection, result.patch.values, documentId),\n note: 'Draft proposal created; the editor reviews and applies it in the studio. Summarize briefly — do not repeat the content.',\n },\n }\n }\n\n async function translate(\n toolCallId: string,\n input: { collection: string; id: string; locale?: string },\n ): Promise<ChatToolOutcome> {\n const collection = collectionById(input.collection)\n if (!collection) {\n return { ok: false, errorText: `Unknown collection \"${input.collection}\" — use a collection id from the catalog.` }\n }\n if (!options.readers.getDocument || !options.localeConfig) {\n return { ok: false, errorText: 'Translation is not available here.' }\n }\n const document = await options.readers.getDocument({\n collection: input.collection,\n id: input.id,\n })\n if (!document) {\n return { ok: false, errorText: `Document \"${input.collection}/${input.id}\" was not found.` }\n }\n const knowledge = options.knowledge?.()\n const result = await translateDocument({\n provider: options.provider,\n collection,\n document,\n localeConfig: options.localeConfig,\n ...(input.locale ? { targetLocales: [input.locale] } : {}),\n ...(knowledge ? { knowledge } : {}),\n // EC-497: the engine gates its own output; both callers hand it the session\n // registry + THE bag so its verdict is the editor's verdict.\n registry: options.registry,\n validateOptions,\n })\n if (result.total === 0) {\n return {\n ok: true,\n output: {\n status: 'nothing-to-translate',\n note: 'Every locale value is already filled — there is nothing to translate.',\n },\n }\n }\n if (result.translated === 0) {\n return { ok: false, errorText: 'The translation did not produce any content.' }\n }\n // EC-473 established that a translated draft is validated before it is proposed\n // (this path once proposed unvalidated content). EC-497 moved the gate INTO the\n // engine so the detail-editor's header action — the other caller — inherits it\n // instead of writing model output straight to the document. Only errors the\n // translation INTRODUCED block it; pre-existing brokenness is not the\n // assistant's doing.\n if (result.introducedErrors.length > 0) {\n return {\n ok: false,\n errorText: `The translation did not pass validation: ${issueSummary(result.introducedErrors)}`,\n }\n }\n options.onProposal(toolCallId, {\n origin: 'translate',\n collection: collection.id,\n documentId: document.id,\n patch: {\n collection: collection.id,\n id: document.id,\n values: result.document.values,\n ...(result.document.localized ? { localized: result.document.localized } : {}),\n },\n provenance: result.provenance,\n attempts: 1,\n // Warnings ride onto the proposal like every other path's (EC-496 renders them).\n issues: [...result.issues],\n before: {\n values: document.values,\n ...(document.localized ? { localized: document.localized } : {}),\n },\n })\n return {\n ok: true,\n output: {\n status: 'proposed',\n collection: collection.id,\n documentId: document.id,\n translatedUnits: result.translated,\n note: 'Translation proposal created; the editor reviews and applies it in the studio.',\n },\n }\n }\n\n return {\n async execute(call: ChatToolCall): Promise<ChatToolOutcome> {\n const definition = (chatToolDefinitions as Record<string, ChatToolDefinition>)[call.toolName]\n if (!definition) {\n return { ok: false, errorText: `Unknown tool \"${call.toolName}\".` }\n }\n const parsed = definition.inputSchema.safeParse(call.input)\n if (!parsed.success) {\n return { ok: false, errorText: `Invalid ${call.toolName} input: ${parsed.error.message}` }\n }\n try {\n switch (call.toolName) {\n case 'searchDocuments':\n return await searchDocuments(parsed.data as { collection: string; query?: string; limit?: number })\n case 'listAssets':\n return await listAssets(parsed.data as { query?: string; limit?: number })\n case 'getDocument':\n return await getDocument(parsed.data as { collection?: string; id?: string })\n case 'createDocument':\n return await createDocument(\n call.toolCallId,\n parsed.data as { collection: string; instruction: string },\n )\n case 'updateFields':\n return await updateFields(\n call.toolCallId,\n parsed.data as { collection?: string; id?: string; changes: UpdateFieldChange[] },\n )\n case 'translateDocument':\n return await translate(\n call.toolCallId,\n parsed.data as { collection: string; id: string; locale?: string },\n )\n default:\n return { ok: false, errorText: `Unknown tool \"${call.toolName}\".` }\n }\n } catch (error) {\n return {\n ok: false,\n errorText: `The ${call.toolName} step failed: ${error instanceof Error ? error.message : 'unknown error'}`,\n }\n }\n },\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/lib/ai/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAS/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,MA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,OAAO,MAAM,eAAe,CAAC,MAAM,CAAC,IAA8D,CAAC,CAAA;oBACrG,KAAK,YAAY;wBACf,OAAO,MAAM,UAAU,CAAC,MAAM,CAAC,IAA0C,CAAC,CAAA;oBAC5E,KAAK,aAAa;wBAChB,OAAO,MAAM,WAAW,CAAC,MAAM,CAAC,IAA4C,CAAC,CAAA;oBAC/E,KAAK,gBAAgB;wBACnB,OAAO,MAAM,cAAc,CACzB,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,IAAmD,CAC3D,CAAA;oBACH,KAAK,cAAc;wBACjB,OAAO,MAAM,YAAY,CACvB,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,IAA0E,CAClF,CAAA;oBACH,KAAK,mBAAmB;wBACtB,OAAO,MAAM,SAAS,CACpB,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,IAA2D,CACnE,CAAA;oBACH;wBACE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAA;gBACvE,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,EAAE,EAAE,KAAK;oBACT,SAAS,EAAE,OAAO,IAAI,CAAC,QAAQ,iBAAiB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE;iBAC3G,CAAA;YACH,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["/**\n * The narrow tool set the assistant works against (EC-199, reshaped by EC-334).\n *\n * Per the ratified AD, tools execute CLIENT-side against the operations layer with\n * the user's own session. This module carries the three pieces of that contract:\n *\n * 1. {@link chatToolDefinitions} — the SDK-native tool DEFINITIONS the route's\n * chat branch declares in `streamText`, deliberately WITHOUT `execute`, so the\n * SDK forwards every call to the client (the route stays a zero-data-access\n * proxy). Plain `{ description, inputSchema }` objects with zod schemas —\n * structurally the SDK's `FunctionTool`, with no SDK import (bundle discipline).\n * 2. {@link ChatToolReaders} — the operations-backed read interface the studio\n * binds client-side (search / list / get). Reads only — the engine never gains\n * a write path; apply is a separate, human-gated draft write.\n * 3. {@link createChatToolExecutor} — the client executor map `useChat`'s\n * `onToolCall` dispatches into. Readers pass through; the terminal tools run\n * the deterministic engines (`applyContentWithShape` / `translateDocument` /\n * `buildUpdateProposal`) and return a COMPACT proposal summary as the tool\n * output — the full proposal goes to the review UI via\n * `onProposal(toolCallId, …)`, never to the model.\n *\n * EC-378: `updateFields` is the edit-flow terminal tool — the model authors\n * per-field changes directly (it has `getDocument` output + the conversation as\n * context); the executor reads the CURRENT document, builds a validated update\n * proposal (`buildUpdateProposal`), and hands it to the review sink. Its target\n * (and `getDocument`'s) may be omitted to mean the document currently open in\n * the editor — resolved via the {@link ChatToolExecutorOptions.currentDocument}\n * seam ({@link resolveDocumentTarget}); the context block the panel injects is\n * ADVISORY, the resolution here is what makes \"this document\" deterministic.\n *\n * The EC-199 planner enum/schema (`plannerSchema` / `parsePlannerAction`) retired\n * with the hand-rolled orchestrator (EC-334 slice 2).\n */\nimport { z } from 'zod'\nimport { resolveDocumentTitle } from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n CollectionRegistry,\n CmsValidationIssue,\n LocaleConfig,\n ValidateDocumentOptions,\n} from '@elytracms/core/cms-core'\nimport { applyContentWithShape } from './apply-content'\nimport { describeComponentProps } from './chat-context'\nimport { assetCandidatesOf, relationCandidatesOf } from './leash'\nimport type { SearchedAsset, SearchedDocument } from './leash'\nimport { translateDocument } from './translate-document'\nimport type { TranslateSkip } from './translate-document'\nimport { buildUpdateProposal } from './update-fields'\nimport type { UpdateFieldChange } from './update-fields'\nimport { componentIdsOf, toWriterDocument } from './writer-form'\nimport { aiProvenance } from './provenance'\nimport type { ChatProposal } from './chat-state'\nimport type { AiProvider, ResolvedKnowledge, WriterLeash } from './types'\n\n/** A document the model may reference as a relation target (from a `searchDocuments` read). */\nexport type DocumentSearchResult = SearchedDocument\n\n/**\n * An asset the model may reference (from a `listAssets` read). EC-588: it carries the\n * two facts a field's `accept` is judged on, so each asset position's candidates can be\n * filtered to what that position takes — and the model can see what each asset is.\n */\nexport type AssetSearchResult = SearchedAsset\n\n/**\n * The client-side, operations-backed readers the executor calls. The studio binds\n * these to the user's authenticated operations client; tests bind an in-memory fake.\n * Reads only — there is no write tool (apply is a separate, human-gated draft write).\n */\nexport interface ChatToolReaders {\n searchDocuments(input: {\n collection: string\n query?: string\n limit?: number\n }): Promise<DocumentSearchResult[]>\n listAssets(input: { query?: string; limit?: number }): Promise<AssetSearchResult[]>\n /**\n * Fetch a full document (values + localized) — the translate flow and the model's\n * `getDocument` tool. Optional: a studio that only wires create can omit it.\n */\n getDocument?(input: { collection: string; id: string }): Promise<CmsDocument | null>\n}\n\n/** Per-search result cap (protects the wire — results become model context). */\nexport const DEFAULT_SEARCH_LIMIT = 20\n\n// --- SDK-native chat tool definitions (EC-334) --------------------------------------\n\n/**\n * One model-facing tool definition for the route's `streamText` call. Structurally\n * the SDK's `FunctionTool` WITHOUT `execute` (execution is client-side, always) —\n * typed locally so this module needs no SDK import.\n */\nexport interface ChatToolDefinition {\n description: string\n /** Zod input schema (the AI SDK accepts zod schemas as `inputSchema` directly). */\n inputSchema: z.ZodType\n}\n\n/**\n * The tool set the native chat branch declares (EC-334). No `execute` on any entry:\n * the SDK forwards each call to the client, which executes reads against the\n * operations layer with the user's session and posts the result back; the terminal\n * tools (`createDocument` / `translateDocument`) run the deterministic engines\n * client-side and return a compact proposal summary as the tool output. The route\n * itself never executes anything.\n *\n * Collections are NOT enum-leashed here — the route has zero data access, so it has\n * no catalog; the catalog reaches the model through the request `context` (system\n * prompt), and every id a proposal references must come from a tool RESULT\n * (client-validated; `applyContentWithShape` still enum-leashes relation ids).\n */\nexport const chatToolDefinitions = {\n searchDocuments: {\n description:\n 'Search documents in a collection. Use it to find the REAL ids a relation may ' +\n 'reference, or to locate an existing document — never invent an id. Returns ' +\n '{ id, title } summaries.',\n inputSchema: z.object({\n collection: z\n .string()\n .describe('Target collection id (from the catalog in the system context).'),\n query: z.string().optional().describe('Optional search text (title match).'),\n limit: z.number().int().positive().optional().describe('Max results.'),\n }),\n },\n listAssets: {\n description:\n 'List or search assets (images, files). Use it to find REAL asset ids — never ' +\n 'invent one. Returns { id, title, contentType, filename } summaries; an asset ' +\n 'field only takes the kinds it accepts.',\n inputSchema: z.object({\n query: z.string().optional().describe('Optional search text.'),\n limit: z.number().int().positive().optional().describe('Max results.'),\n }),\n },\n getDocument: {\n description:\n 'Fetch one full document (values + localized values + component ids) by collection and ' +\n 'id. Omit both to read the document currently open in the editor. Rich-text values — ' +\n 'at any depth — are returned as markdown strings where faithfully expressible. ' +\n '`components` lists, for every component on the document, the props you may change ' +\n 'with updateFields and the rules each value must satisfy.',\n inputSchema: z.object({\n collection: z\n .string()\n .optional()\n .describe('Collection id. Omit to target the currently open document.'),\n id: z\n .string()\n .optional()\n .describe(\n 'Document id (from a searchDocuments result). Omit to target the currently open document.',\n ),\n }),\n },\n createDocument: {\n description:\n 'Author a NEW document in a collection as a reviewable draft proposal. Terminal ' +\n 'step of a creation request — call it once you have gathered the real ids you ' +\n 'need. Returns a compact proposal summary.',\n inputSchema: z.object({\n collection: z.string().describe('Target collection id.'),\n instruction: z.string().describe('What to write, refining the user request.'),\n }),\n },\n updateFields: {\n description:\n 'Change specific fields of an EXISTING document as a reviewable proposal — THE ' +\n 'tool for every edit request (change / fix / remove / replace / rewrite wording, ' +\n 'values, or a page-builder element). Call getDocument first to see the current ' +\n 'values (and component ids), then pass ONLY the fields that change. A component ' +\n 'prop (e.g. a Hero headline) — at any depth: a top-level block, a child inside a ' +\n 'section, a component embedded in rich text — is addressed as field + blockId + ' +\n 'prop. Components are never added, moved or removed by the assistant (that is done ' +\n 'on the canvas). Omit collection and id to target the document currently open in ' +\n 'the editor. A rich-text value takes the FULL new value as a MARKDOWN string ' +\n '(headings, lists, links, bold/italic, blockquotes — no images, code, tables, or HTML).',\n inputSchema: z.object({\n collection: z\n .string()\n .optional()\n .describe('Collection id. Omit to target the currently open document.'),\n id: z\n .string()\n .optional()\n .describe('Document id. Omit to target the currently open document.'),\n changes: z\n .array(\n z.object({\n field: z\n .string()\n .describe(\n 'Field name from the collection schema. The catalog in the system context ' +\n 'lists every field with its type and the rules its value must satisfy.',\n ),\n locale: z\n .string()\n .optional()\n .describe(\n \"Locale of a LOCALIZED field (defaults to the editor's working locale).\",\n ),\n blockId: z\n .string()\n .optional()\n .describe(\n 'To change a component prop: the component id (from getDocument) — any depth.',\n ),\n prop: z\n .string()\n .optional()\n .describe('With blockId: the component prop to change (from getDocument `components`).'),\n value: z\n .unknown()\n .optional()\n .describe(\n 'The new value (a rich-text field takes a markdown string). null clears the ' +\n \"field/prop. It MUST satisfy that field's rules as listed in the catalog \" +\n '(length bounds, format, allowed values, date range…); the studio validates ' +\n 'the merged document and rejects the proposal with the failing rules if it ' +\n 'does not. Where the catalog says further rules apply, keep the value ' +\n 'conventional and plausible.',\n ),\n }),\n )\n .min(1)\n .describe('The field changes — only what changes, never the whole document.'),\n }),\n },\n translateDocument: {\n description:\n 'Fill the EMPTY locale values of an existing document (search for it first to ' +\n 'get its id). Only for translation requests — never for edits (use updateFields ' +\n 'to change existing content). Returns a compact proposal summary.',\n inputSchema: z.object({\n collection: z.string().describe('Collection id.'),\n id: z.string().describe('Document id (from a searchDocuments result).'),\n locale: z.string().optional().describe('Target locale (defaults to the active one).'),\n }),\n },\n} satisfies Record<string, ChatToolDefinition>\n\n// --- Client executor map (EC-334) ----------------------------------------------------\n\n/** One forwarded tool call, as `useChat`'s `onToolCall` receives it. */\nexport interface ChatToolCall {\n toolCallId: string\n toolName: string\n input: unknown\n}\n\n/** The coordinates of the document currently open in the editor (EC-378 seam). */\nexport interface CurrentDocumentRef {\n collection: string\n id: string\n}\n\n/**\n * Resolve a tool call's target document from its (optional) input coordinates\n * and the current-document seam (EC-378). Deterministic:\n *\n * - both given → use them verbatim;\n * - both omitted → the currently open document (error when none is open);\n * - `collection` given with `id` omitted → the open document ONLY when the\n * collections match — a named collection must never silently cross onto a\n * different open document.\n *\n * Pure — tested directly; `getDocument` and `updateFields` share it.\n */\nexport function resolveDocumentTarget(\n input: { collection?: string; id?: string },\n current: CurrentDocumentRef | null | undefined,\n): { ok: true; ref: CurrentDocumentRef } | { ok: false; errorText: string } {\n if (input.collection !== undefined && input.id !== undefined) {\n return { ok: true, ref: { collection: input.collection, id: input.id } }\n }\n if (!current) {\n return {\n ok: false,\n errorText:\n 'No target document — pass collection and id, or ask the user to open the document in the editor.',\n }\n }\n if (input.collection !== undefined && input.collection !== current.collection) {\n return {\n ok: false,\n errorText: `The open document is in collection \"${current.collection}\", not \"${input.collection}\" — pass the document id explicitly.`,\n }\n }\n return { ok: true, ref: { collection: current.collection, id: input.id ?? current.id } }\n}\n\n/**\n * A tool execution outcome: an `output` posted back as the tool result, or an\n * `errorText` posted as an `output-error` part (the model sees the failure and\n * can react — never a thrown exception into the stream).\n */\nexport type ChatToolOutcome = { ok: true; output: unknown } | { ok: false; errorText: string }\n\n/**\n * The per-conversation candidate store: every `searchDocuments` result is recorded\n * per collection, every `listAssets` result into one flat library pool (EC-381), and\n * the terminal tools may only reference the ids gathered here. The store IS the\n * {@link WriterLeash} the engines ask per position (EC-593): a relation by its target\n * collection, an asset by its declaration's `accept` (EC-588) — so a nested relation, a\n * component's asset prop and a top-level field are leashed by the same two questions\n * (the create enum + drop, the update loud refusal). Held by the panel per\n * conversation — a new conversation (EC-380 clear) starts an empty store.\n */\nexport interface ChatCandidateStore extends WriterLeash {\n record(collection: string, results: readonly DocumentSearchResult[]): void\n /** Record every `listAssets` result into the flat library pool (EC-381). */\n recordAssets(results: readonly AssetSearchResult[]): void\n}\n\nexport function createChatCandidateStore(): ChatCandidateStore {\n const searched = new Map<string, Map<string, DocumentSearchResult>>()\n const searchedAssets = new Map<string, AssetSearchResult>()\n return {\n record(collection, results) {\n const byId = searched.get(collection) ?? new Map<string, DocumentSearchResult>()\n for (const result of results) byId.set(result.id, result)\n searched.set(collection, byId)\n },\n recordAssets(results) {\n for (const result of results) searchedAssets.set(result.id, result)\n },\n relationCandidates(target) {\n return relationCandidatesOf(searched.get(target)?.values() ?? [])\n },\n // EC-588 (A4): a position's enum is the pool filtered by ITS `accept` — an image\n // field is never offered a PDF. The validator re-run at apply is the guarantee\n // (`findAsset` checks the record); this keeps the model from spending its repair\n // budget on a mismatch the leash can rule out up front.\n assetCandidates(field) {\n return assetCandidatesOf(field, searchedAssets.values())\n },\n }\n}\n\nexport interface ChatToolExecutorOptions {\n /** The (route) provider the terminal engines proxy their model calls through. */\n provider: AiProvider\n registry: CollectionRegistry\n /** The collections the assistant may target (unknown ids fail loud). */\n collections: readonly CollectionDef[]\n /** Operations-backed readers (client-side, user's session). */\n readers: ChatToolReaders\n /** Mint a fresh document id for a new draft (studio: the CMS store's minter). */\n mintDocumentId: (collectionId: string) => string\n /** Per-conversation relation-candidate store (see {@link createChatCandidateStore}). */\n candidates: ChatCandidateStore\n /**\n * Full proposal sink, keyed by `toolCallId` — the review UI's entry point.\n * The tool OUTPUT stays a compact summary; the patch never reaches the model.\n */\n onProposal: (toolCallId: string, proposal: ChatProposal) => void\n /**\n * The document currently open in the editor (EC-378 seam) — a thunk read at\n * EXECUTION time, so \"this document\" resolves against what is open NOW.\n * `getDocument` / `updateFields` fall back to it when the model omits the\n * target (see {@link resolveDocumentTarget}).\n */\n currentDocument?: () => CurrentDocumentRef | null | undefined\n /** Current knowledge snapshot (thunk — the body thunk refreshes it per request). */\n knowledge?: () => ResolvedKnowledge | undefined\n /** Target locale for localized fields. */\n locale?: string\n /** Locale config — required for `translateDocument`. */\n localeConfig?: LocaleConfig\n /**\n * THE validation option bag (EC-497) — the CMS session's\n * `gateValidateOptions(...)`, forwarded whole to every engine below. EC-473\n * made the assistant's gate the editor's gate; passing one bag instead of five\n * keys makes it stay that way, because a key can no longer be dropped by being\n * forgotten at one of the three call sites this replaced. Its `lookupManifest` is\n * also how the writer-form converter and the read form reach component props\n * (EC-593) — the props the validator judges, no second component source.\n */\n validateOptions?: ValidateDocumentOptions\n /** Max repair attempts inside `applyContentWithShape`. */\n maxRepairAttempts?: number\n /** Per-search result cap (default {@link DEFAULT_SEARCH_LIMIT}). */\n searchLimit?: number\n}\n\n/** The executor `useChat`'s `onToolCall` dispatches into. */\nexport interface ChatToolExecutor {\n execute(call: ChatToolCall): Promise<ChatToolOutcome>\n}\n\n/** A translate skip as one model-facing phrase: `menu[1].label (de): the provider returned no text`. */\nexport function describeTranslateSkip(skip: TranslateSkip): string {\n const where = skip.at.reduce<string>(\n (out, key) => (typeof key === 'number' ? `${out}[${key}]` : `${out}.${key}`),\n skip.field,\n )\n const component = skip.component ? ` in ${skip.component.componentId} \"${skip.component.nodeId}\"` : ''\n const why =\n skip.reason === 'unreadable'\n ? 'the stored value is not readable as its type'\n : skip.reason === 'not-returned'\n ? 'the provider returned no text'\n : 'the translation did not keep its formatting, links or embeds, so the original was kept'\n return `${where}${component} (${skip.locale}): ${why}`\n}\n\nfunction issueSummary(issues: readonly CmsValidationIssue[]): string {\n return issues\n .slice(0, 5)\n .map((issue) => issue.message)\n .join('; ')\n}\n\n/**\n * The `getDocument` output (EC-379 → EC-593): the document in the form the model reads\n * — the ONE converter's read side (`toWriterDocument`), so rich text is a markdown\n * string at EVERY depth where the engine's loss-guarded inverse can express it\n * faithfully (a top-level field, an object sub-field, a repeater item, a component's\n * rich-text prop), and keeps its stored `{ version: 2, content }` value otherwise (embeds,\n * internal `ref` links, out-of-subset marks), so nothing the model later echoes back can\n * silently lose structure. It used to project TOP-LEVEL rich text only (SHAPES #29: a\n * nested value read as v2 while every writer was told markdown).\n *\n * `components` is the catalog's prop half (RULES F3d): for every component on the\n * document, the props `updateFields` may change and the rules each value must satisfy,\n * read off the same declarations the validator judges (`lookupManifest`). Applies to\n * the TOOL OUTPUT only; the proposal/apply paths always read the raw stored document.\n */\nexport function modelFacingDocument(\n document: CmsDocument,\n collection: CollectionDef,\n validateOptions: ValidateDocumentOptions = {},\n): CmsDocument & { components?: Record<string, string[]> } {\n const lookupManifest = validateOptions.lookupManifest\n const read = toWriterDocument(collection, document, lookupManifest ? { lookupManifest } : {})\n if (!lookupManifest) return read\n const ids = componentIdsOf(collection, document, lookupManifest)\n if (ids.length === 0) return read\n return {\n ...read,\n components: Object.fromEntries(ids.map((id) => [id, describeComponentProps(lookupManifest(id) ?? {})])),\n }\n}\n\n/**\n * Build the client executor map. Every entry validates its input against\n * {@link chatToolDefinitions}' zod schema (the route validates UIMessages only\n * structurally — deep input validation is the client's), executes with the\n * user's session, and returns a JSON-safe outcome. EC-378's `updateFields`\n * lands as one more case in this dispatch.\n */\nexport function createChatToolExecutor(options: ChatToolExecutorOptions): ChatToolExecutor {\n const searchLimit = options.searchLimit ?? DEFAULT_SEARCH_LIMIT\n\n /**\n * EC-497 — the ONE bag every engine below is handed, assembled in exactly one\n * place instead of at each of the three former call sites.\n *\n * The executor's own `localeConfig` is a FLOOR, never an override: the session's\n * bag wins wherever it speaks, but a bag that omits the project's locales must\n * not be able to make the gate locale-blind — a localized bound would then go\n * unchecked, which is precisely the class of hole this task closed.\n */\n const validateOptions: ValidateDocumentOptions = {\n ...(options.localeConfig ? { localeConfig: options.localeConfig } : {}),\n ...(options.validateOptions ?? {}),\n }\n\n function collectionById(id: string): CollectionDef | undefined {\n return options.collections.find((c) => c.id === id)\n }\n\n async function searchDocuments(input: {\n collection: string\n query?: string\n limit?: number\n }): Promise<ChatToolOutcome> {\n if (!collectionById(input.collection)) {\n return { ok: false, errorText: `Unknown collection \"${input.collection}\" — use a collection id from the catalog.` }\n }\n const limit = Math.min(input.limit ?? searchLimit, searchLimit)\n const results = (\n await options.readers.searchDocuments({\n collection: input.collection,\n ...(input.query ? { query: input.query } : {}),\n limit,\n })\n ).slice(0, limit)\n options.candidates.record(input.collection, results)\n return { ok: true, output: results }\n }\n\n async function listAssets(input: { query?: string; limit?: number }): Promise<ChatToolOutcome> {\n const limit = Math.min(input.limit ?? searchLimit, searchLimit)\n const results = (\n await options.readers.listAssets({\n ...(input.query ? { query: input.query } : {}),\n limit,\n })\n ).slice(0, limit)\n // EC-381 — leash asset fields to what the model actually searched, exactly as\n // searchDocuments feeds the relation store.\n options.candidates.recordAssets(results)\n return { ok: true, output: results }\n }\n\n async function getDocument(input: {\n collection?: string\n id?: string\n }): Promise<ChatToolOutcome> {\n if (!options.readers.getDocument) {\n return { ok: false, errorText: 'Reading documents is not available here.' }\n }\n const target = resolveDocumentTarget(input, options.currentDocument?.())\n if (!target.ok) return { ok: false, errorText: target.errorText }\n const document = await options.readers.getDocument(target.ref)\n if (!document) {\n return {\n ok: false,\n errorText: `Document \"${target.ref.collection}/${target.ref.id}\" was not found.`,\n }\n }\n // EC-379/EC-593: the model reads (and re-authors) every value in its writer form.\n const collection = collectionById(target.ref.collection)\n return { ok: true, output: collection ? modelFacingDocument(document, collection, validateOptions) : document }\n }\n\n /** EC-378 — the edit-flow terminal tool: current doc + model-authored changes → validated proposal. */\n async function updateFields(\n toolCallId: string,\n input: { collection?: string; id?: string; changes: UpdateFieldChange[] },\n ): Promise<ChatToolOutcome> {\n if (!options.readers.getDocument) {\n return { ok: false, errorText: 'Reading documents is not available here.' }\n }\n const target = resolveDocumentTarget(input, options.currentDocument?.())\n if (!target.ok) return { ok: false, errorText: target.errorText }\n const collection = collectionById(target.ref.collection)\n if (!collection) {\n return {\n ok: false,\n errorText: `Unknown collection \"${target.ref.collection}\" — use a collection id from the catalog.`,\n }\n }\n const document = await options.readers.getDocument(target.ref)\n if (!document) {\n return {\n ok: false,\n errorText: `Document \"${target.ref.collection}/${target.ref.id}\" was not found.`,\n }\n }\n const result = buildUpdateProposal({\n registry: options.registry,\n collection,\n document,\n changes: input.changes,\n // EC-381 → EC-593: the store IS the leash, asked per position.\n leash: options.candidates,\n ...(options.locale ? { locale: options.locale } : {}),\n validateOptions,\n })\n if (!result.ok) {\n return {\n ok: false,\n errorText: `The proposed changes did not pass validation: ${issueSummary(result.issues)}`,\n }\n }\n if (result.kind === 'no-change') {\n return {\n ok: true,\n output: {\n status: 'no-change',\n note: 'The requested change matches the current values — there is nothing to update.',\n },\n }\n }\n options.onProposal(toolCallId, {\n origin: 'update',\n collection: collection.id,\n documentId: document.id,\n patch: result.patch,\n patches: result.patches,\n provenance: aiProvenance(options.provider),\n attempts: 1,\n issues: result.issues,\n before: result.before,\n })\n // Compact summary only — the full patch goes to the review UI, not the model.\n const titleValues = {\n ...result.patch.values,\n ...(options.locale ? result.patch.localized?.[options.locale] : {}),\n }\n return {\n ok: true,\n output: {\n status: 'proposed',\n collection: collection.id,\n documentId: document.id,\n title: resolveDocumentTitle(collection, titleValues, document.id),\n changedFields: result.changedFields,\n note: 'Update proposal created; the editor reviews and applies it in the studio. Summarize the change briefly — do not repeat the content.',\n },\n }\n }\n\n async function createDocument(\n toolCallId: string,\n input: { collection: string; instruction: string },\n ): Promise<ChatToolOutcome> {\n const collection = collectionById(input.collection)\n if (!collection) {\n return { ok: false, errorText: `Unknown collection \"${input.collection}\" — use a collection id from the catalog.` }\n }\n const documentId = options.mintDocumentId(collection.id)\n const knowledge = options.knowledge?.()\n const result = await applyContentWithShape({\n provider: options.provider,\n registry: options.registry,\n collection,\n documentId,\n instruction: input.instruction,\n ...(knowledge ? { knowledge } : {}),\n // EC-381 → EC-593: relation and asset positions — at every depth — are leashed\n // to what was searched (the store IS the leash).\n leash: options.candidates,\n ...(options.locale ? { locale: options.locale } : {}),\n validateOptions,\n ...(options.maxRepairAttempts !== undefined\n ? { maxRepairAttempts: options.maxRepairAttempts }\n : {}),\n })\n if (!result.ok) {\n return {\n ok: false,\n errorText: `The drafted ${collection.id} did not pass validation: ${issueSummary(result.issues)}`,\n }\n }\n options.onProposal(toolCallId, {\n origin: 'create',\n collection: collection.id,\n documentId,\n patch: result.patch,\n provenance: result.provenance,\n attempts: result.attempts,\n issues: result.issues,\n })\n // Compact summary only — the full patch goes to the review UI, not the model.\n return {\n ok: true,\n output: {\n status: 'proposed',\n collection: collection.id,\n documentId,\n title: resolveDocumentTitle(collection, result.patch.values, documentId),\n note: 'Draft proposal created; the editor reviews and applies it in the studio. Summarize briefly — do not repeat the content.',\n },\n }\n }\n\n async function translate(\n toolCallId: string,\n input: { collection: string; id: string; locale?: string },\n ): Promise<ChatToolOutcome> {\n const collection = collectionById(input.collection)\n if (!collection) {\n return { ok: false, errorText: `Unknown collection \"${input.collection}\" — use a collection id from the catalog.` }\n }\n if (!options.readers.getDocument || !options.localeConfig) {\n return { ok: false, errorText: 'Translation is not available here.' }\n }\n const document = await options.readers.getDocument({\n collection: input.collection,\n id: input.id,\n })\n if (!document) {\n return { ok: false, errorText: `Document \"${input.collection}/${input.id}\" was not found.` }\n }\n const knowledge = options.knowledge?.()\n const result = await translateDocument({\n provider: options.provider,\n collection,\n document,\n localeConfig: options.localeConfig,\n ...(input.locale ? { targetLocales: [input.locale] } : {}),\n ...(knowledge ? { knowledge } : {}),\n // EC-497: the engine gates its own output; both callers hand it the session\n // registry + THE bag so its verdict is the editor's verdict.\n registry: options.registry,\n validateOptions,\n })\n // EC-593 (ratified 4e): what could not be translated is REPORTED — to the model\n // (it tells the user) and on the proposal the editor reviews — never skipped silently.\n const skipped = result.skipped.map(describeTranslateSkip)\n if (result.total === 0 && skipped.length === 0) {\n return {\n ok: true,\n output: {\n status: 'nothing-to-translate',\n note: 'Every locale value is already filled — there is nothing to translate.',\n },\n }\n }\n if (result.translated === 0) {\n return {\n ok: false,\n errorText:\n skipped.length > 0\n ? `The translation did not produce any content. Not translated: ${skipped.slice(0, 5).join('; ')}`\n : 'The translation did not produce any content.',\n }\n }\n // EC-473 established that a translated draft is validated before it is proposed\n // (this path once proposed unvalidated content). EC-497 moved the gate INTO the\n // engine so the detail-editor's header action — the other caller — inherits it\n // instead of writing model output straight to the document. Only errors the\n // translation INTRODUCED block it; pre-existing brokenness is not the\n // assistant's doing.\n if (result.introducedErrors.length > 0) {\n return {\n ok: false,\n errorText: `The translation did not pass validation: ${issueSummary(result.introducedErrors)}`,\n }\n }\n options.onProposal(toolCallId, {\n origin: 'translate',\n collection: collection.id,\n documentId: document.id,\n patch: {\n collection: collection.id,\n id: document.id,\n values: result.document.values,\n ...(result.document.localized ? { localized: result.document.localized } : {}),\n },\n patches: result.patches,\n provenance: result.provenance,\n attempts: 1,\n // Warnings ride onto the proposal like every other path's (EC-496 renders them).\n issues: [...result.issues],\n ...(result.skipped.length > 0 ? { skipped: [...result.skipped] } : {}),\n before: {\n values: document.values,\n ...(document.localized ? { localized: document.localized } : {}),\n },\n })\n return {\n ok: true,\n output: {\n status: 'proposed',\n collection: collection.id,\n documentId: document.id,\n translatedUnits: result.translated,\n ...(skipped.length > 0 ? { notTranslated: skipped } : {}),\n note:\n skipped.length > 0\n ? 'Translation proposal created; the editor reviews and applies it in the studio. Tell the user which positions were NOT translated (notTranslated).'\n : 'Translation proposal created; the editor reviews and applies it in the studio.',\n },\n }\n }\n\n return {\n async execute(call: ChatToolCall): Promise<ChatToolOutcome> {\n const definition = (chatToolDefinitions as Record<string, ChatToolDefinition>)[call.toolName]\n if (!definition) {\n return { ok: false, errorText: `Unknown tool \"${call.toolName}\".` }\n }\n const parsed = definition.inputSchema.safeParse(call.input)\n if (!parsed.success) {\n return { ok: false, errorText: `Invalid ${call.toolName} input: ${parsed.error.message}` }\n }\n try {\n switch (call.toolName) {\n case 'searchDocuments':\n return await searchDocuments(parsed.data as { collection: string; query?: string; limit?: number })\n case 'listAssets':\n return await listAssets(parsed.data as { query?: string; limit?: number })\n case 'getDocument':\n return await getDocument(parsed.data as { collection?: string; id?: string })\n case 'createDocument':\n return await createDocument(\n call.toolCallId,\n parsed.data as { collection: string; instruction: string },\n )\n case 'updateFields':\n return await updateFields(\n call.toolCallId,\n parsed.data as { collection?: string; id?: string; changes: UpdateFieldChange[] },\n )\n case 'translateDocument':\n return await translate(\n call.toolCallId,\n parsed.data as { collection: string; id: string; locale?: string },\n )\n default:\n return { ok: false, errorText: `Unknown tool \"${call.toolName}\".` }\n }\n } catch (error) {\n return {\n ok: false,\n errorText: `The ${call.toolName} step failed: ${error instanceof Error ? error.message : 'unknown error'}`,\n }\n }\n },\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CmsDocument, CmsValidationIssue, CollectionDef, CollectionRegistry, Locale, LocaleConfig, ValidateDocumentOptions } from '@elytracms/core/cms-core';
|
|
1
|
+
import type { CmsDocument, CmsValidationIssue, CollectionDef, CollectionRegistry, DocumentPatch, Locale, LocaleConfig, ValidateDocumentOptions } from '@elytracms/core/cms-core';
|
|
2
2
|
import type { AiProvenance, AiProvider, ResolvedKnowledge } from './types.js';
|
|
3
3
|
/** Default translatable units per `generate` call. */
|
|
4
4
|
export declare const DEFAULT_TRANSLATE_BATCH_SIZE = 12;
|
|
@@ -34,14 +34,15 @@ export interface TranslateDocumentInput {
|
|
|
34
34
|
* used. That is sound rather than a shortcut, because the verdict this engine
|
|
35
35
|
* publishes is a DELTA (`introducedErrors`, before vs after) and cross-collection
|
|
36
36
|
* findings appear identically on both sides — and a translation only ever writes
|
|
37
|
-
* localized
|
|
38
|
-
* callers pass the session registry anyway.
|
|
37
|
+
* localized values carried from the base with their text translated, plus derived
|
|
38
|
+
* slugs. Both real callers pass the session registry anyway.
|
|
39
39
|
*/
|
|
40
40
|
registry?: CollectionRegistry;
|
|
41
41
|
/**
|
|
42
42
|
* THE validation option bag (EC-497) — the studio session's
|
|
43
43
|
* `gateValidateOptions(...)`. Absent ⇒ store-dependent rules simply do not fire,
|
|
44
|
-
* the documented conditionality; everything else still runs.
|
|
44
|
+
* the documented conditionality; everything else still runs. Its `lookupManifest` is
|
|
45
|
+
* how the walk reaches component props (EC-593) — the props the validator judges.
|
|
45
46
|
*/
|
|
46
47
|
validateOptions?: ValidateDocumentOptions;
|
|
47
48
|
}
|
|
@@ -49,12 +50,43 @@ export interface TranslateProgress {
|
|
|
49
50
|
completed: number;
|
|
50
51
|
total: number;
|
|
51
52
|
}
|
|
53
|
+
/** Why a text position was not translated. */
|
|
54
|
+
export type TranslateSkipReason =
|
|
55
|
+
/** The stored value at the position is not readable as its type (e.g. a pre-convergence rich text). */
|
|
56
|
+
'unreadable'
|
|
57
|
+
/** The provider returned no (or empty) text for the unit. */
|
|
58
|
+
| 'not-returned'
|
|
59
|
+
/** The translation did not keep the formatting / link / embed tokens; the original was kept. */
|
|
60
|
+
| 'structure-changed';
|
|
61
|
+
/**
|
|
62
|
+
* One text position the run could NOT translate (EC-593, ratified 4e): reported in the
|
|
63
|
+
* result and shown in the dialog — never a silent skip.
|
|
64
|
+
*/
|
|
65
|
+
export interface TranslateSkip {
|
|
66
|
+
/** The top-level field. */
|
|
67
|
+
field: string;
|
|
68
|
+
locale: Locale;
|
|
69
|
+
/** Where below the field value (index-bearing; `[]` — the field itself). */
|
|
70
|
+
at: readonly (string | number)[];
|
|
71
|
+
/** For a position inside a component: the component (and its node id). */
|
|
72
|
+
component?: {
|
|
73
|
+
componentId: string;
|
|
74
|
+
nodeId: string;
|
|
75
|
+
};
|
|
76
|
+
reason: TranslateSkipReason;
|
|
77
|
+
}
|
|
52
78
|
export interface TranslateDocumentResult {
|
|
53
79
|
/** The new draft with the translations filled in (base + connected locale values). */
|
|
54
80
|
document: CmsDocument;
|
|
81
|
+
/**
|
|
82
|
+
* EC-595 A2 — the positions this run wrote, as patches (one per `(field, locale)`
|
|
83
|
+
* bucket it filled — "localized fields patch per bucket"): what the caller persists,
|
|
84
|
+
* so a colleague's concurrent edit of any other position is never overwritten.
|
|
85
|
+
*/
|
|
86
|
+
patches: DocumentPatch[];
|
|
55
87
|
/** Total translatable units the walk found. */
|
|
56
88
|
total: number;
|
|
57
|
-
/** Units actually translated (< total when aborted or
|
|
89
|
+
/** Units actually translated (< total when aborted, or when some are {@link skipped}). */
|
|
58
90
|
translated: number;
|
|
59
91
|
/** True when the run was aborted before every batch completed. */
|
|
60
92
|
cancelled: boolean;
|
|
@@ -64,6 +96,8 @@ export interface TranslateDocumentResult {
|
|
|
64
96
|
perLocale: Record<Locale, number>;
|
|
65
97
|
/** Slug fields derived per target locale (not model-translated). */
|
|
66
98
|
slugsDerived: number;
|
|
99
|
+
/** Every text position the run could not translate (EC-593) — empty when all landed. */
|
|
100
|
+
skipped: readonly TranslateSkip[];
|
|
67
101
|
provenance: AiProvenance;
|
|
68
102
|
/**
|
|
69
103
|
* EC-497 — errors this translation INTRODUCED, i.e. present on the produced
|