@ecsplico/editor 2.1.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -1
- package/README.md +39 -156
- package/dist/adapters/comments/drizzle.d.ts +1 -1
- package/dist/adapters/comments/record.d.ts +15 -0
- package/dist/adapters/comments/{client.js → rest-model.js} +3 -3
- package/dist/adapters/comments/rest-model.js.map +1 -0
- package/dist/adapters/comments/server.d.ts +2 -1
- package/dist/adapters/comments/server.js +2 -1
- package/dist/adapters/comments/server.js.map +1 -1
- package/dist/adapters/comments/types.d.ts +2 -2
- package/dist/adapters/document-state.d.ts +23 -0
- package/dist/adapters/document-state.js +66 -0
- package/dist/adapters/document-state.js.map +1 -0
- package/dist/adapters/documents.js +14 -11
- package/dist/adapters/documents.js.map +1 -1
- package/dist/adapters/drizzle.d.ts +2 -2
- package/dist/adapters/drizzle.js +97 -88
- package/dist/adapters/drizzle.js.map +1 -1
- package/dist/adapters/forge.d.ts +12 -7
- package/dist/adapters/forge.js +38 -45
- package/dist/adapters/forge.js.map +1 -1
- package/dist/adapters/http.d.ts +20 -0
- package/dist/adapters/http.js +68 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/index.d.ts +5 -5
- package/dist/adapters/json.d.ts +3 -3
- package/dist/adapters/json.js +58 -49
- package/dist/adapters/json.js.map +1 -1
- package/dist/adapters/memory.d.ts +21 -0
- package/dist/adapters/memory.js +53 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/adapters/nitro.d.ts +27 -20
- package/dist/adapters/nitro.js +59 -163
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/adapters/react.d.ts +55 -0
- package/dist/adapters/react.js +209 -0
- package/dist/adapters/react.js.map +1 -0
- package/dist/adapters/shared.d.ts +15 -21
- package/dist/adapters/shared.js +10 -8
- package/dist/adapters/shared.js.map +1 -1
- package/dist/adapters/vue.d.ts +15 -30
- package/dist/adapters/vue.js +36 -87
- package/dist/adapters/vue.js.map +1 -1
- package/dist/code/CodeSurface.vue.d.ts +2 -2
- package/dist/config/index.d.ts +105 -0
- package/dist/config/index.js +95 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/abilities.js +1 -0
- package/dist/core/abilities.js.map +1 -1
- package/dist/{adapters/routes.js → core/api-routes.js} +5 -3
- package/dist/core/api-routes.js.map +1 -0
- package/dist/core/backend-capability.d.ts +7 -0
- package/dist/core/backend-capability.js +17 -0
- package/dist/core/backend-capability.js.map +1 -0
- package/dist/core/backend-types.d.ts +245 -0
- package/dist/core/backend-types.js +17 -0
- package/dist/core/backend-types.js.map +1 -0
- package/dist/core/backend.d.ts +108 -0
- package/dist/core/backend.js +14 -0
- package/dist/core/backend.js.map +1 -0
- package/dist/core/block-convert.d.ts +7 -5
- package/dist/core/block-convert.js +28 -5
- package/dist/core/block-convert.js.map +1 -1
- package/dist/core/command-types.d.ts +96 -0
- package/dist/core/commands.d.ts +40 -0
- package/dist/core/commands.js +151 -0
- package/dist/core/commands.js.map +1 -0
- package/dist/core/context.d.ts +17 -20
- package/dist/core/context.js +24 -21
- package/dist/core/context.js.map +1 -1
- package/dist/core/core-feature.d.ts +22 -7
- package/dist/core/core-feature.js +51 -18
- package/dist/core/core-feature.js.map +1 -1
- package/dist/core/define-editor.d.ts +4 -3
- package/dist/core/define-editor.js +14 -7
- package/dist/core/define-editor.js.map +1 -1
- package/dist/core/document-markdown.js +12 -3
- package/dist/core/document-markdown.js.map +1 -1
- package/dist/core/editor-ui.d.ts +8 -1
- package/dist/core/editor-ui.js +9 -8
- package/dist/core/editor-ui.js.map +1 -1
- package/dist/core/extension-points.d.ts +3 -15
- package/dist/core/feature-context.d.ts +8 -7
- package/dist/core/feature-context.js +12 -11
- package/dist/core/feature-context.js.map +1 -1
- package/dist/core/feature.d.ts +41 -19
- package/dist/core/feature.js.map +1 -1
- package/dist/core/fences.d.ts +2 -1
- package/dist/core/fences.js +3 -2
- package/dist/core/fences.js.map +1 -1
- package/dist/core/fetch-error.d.ts +1 -1
- package/dist/core/fetch-error.js +3 -1
- package/dist/core/fetch-error.js.map +1 -1
- package/dist/core/hash.d.ts +5 -0
- package/dist/core/hash.js +11 -0
- package/dist/core/hash.js.map +1 -0
- package/dist/core/http-backend.d.ts +11 -0
- package/dist/core/http-backend.js +195 -0
- package/dist/core/http-backend.js.map +1 -0
- package/dist/core/index.d.ts +15 -9
- package/dist/core/index.js +13 -9
- package/dist/core/palette.d.ts +48 -0
- package/dist/core/palette.js +95 -0
- package/dist/core/palette.js.map +1 -0
- package/dist/core/schema/abilities.d.ts +2 -1
- package/dist/core/schema/abilities.js +5 -1
- package/dist/core/schema/abilities.js.map +1 -1
- package/dist/core/schema/index.d.ts +11 -5
- package/dist/core/schema/index.js +13 -8
- package/dist/core/schema/index.js.map +1 -1
- package/dist/core/schema/mark-flags.d.ts +8 -1
- package/dist/core/schema/of-features.d.ts +13 -0
- package/dist/core/schema/of-features.js +14 -0
- package/dist/core/schema/of-features.js.map +1 -0
- package/dist/core/slash.d.ts +8 -6
- package/dist/core/slash.js +24 -16
- package/dist/core/slash.js.map +1 -1
- package/dist/core/surface-session.js +15 -5
- package/dist/core/surface-session.js.map +1 -1
- package/dist/core/toolbar-items.d.ts +10 -4
- package/dist/core/toolbar-items.js +269 -195
- package/dist/core/toolbar-items.js.map +1 -1
- package/dist/core/transaction-guards.d.ts +21 -0
- package/dist/core/transaction-guards.js +49 -0
- package/dist/core/transaction-guards.js.map +1 -0
- package/dist/core/util.js +11 -0
- package/dist/core/util.js.map +1 -0
- package/dist/document/DocumentSurface.d.ts +1 -1
- package/dist/document/DocumentSurface.vue.d.ts +2 -2
- package/dist/features/ai/agent-op-review.d.ts +1 -1
- package/dist/features/ai/agent-op-review.js +1 -1
- package/dist/features/ai/agent-ops.js +1 -1
- package/dist/features/ai/ai-apply.d.ts +2 -2
- package/dist/features/ai/ai-apply.js +1 -1
- package/dist/features/ai/ai-review.js +1 -1
- package/dist/features/ai/ai-sse.d.ts +6 -6
- package/dist/features/ai/ai-sse.js +20 -63
- package/dist/features/ai/ai-sse.js.map +1 -1
- package/dist/features/ai/assistant.d.ts +8 -7
- package/dist/features/ai/assistant.js +3 -3
- package/dist/features/ai/assistant.js.map +1 -1
- package/dist/features/ai/block-actions.d.ts +3 -2
- package/dist/features/ai/block-actions.js +3 -2
- package/dist/features/ai/block-actions.js.map +1 -1
- package/dist/features/ai/components/AiSelectionMenu.js +1 -1
- package/dist/features/ai/components/DocumentChatAnswer.js +1 -1
- package/dist/features/ai/components/DocumentChatOps.vue.d.ts +1 -1
- package/dist/features/ai/components/SettingsModelProfiles.js +8 -8
- package/dist/features/ai/components/SettingsModelProfiles.js.map +1 -1
- package/dist/features/ai/document-chat-model.d.ts +8 -7
- package/dist/features/ai/document-chat-model.js +5 -5
- package/dist/features/ai/document-chat-model.js.map +1 -1
- package/dist/features/ai/document-chat.js +1 -1
- package/dist/features/ai/feature.js +27 -14
- package/dist/features/ai/feature.js.map +1 -1
- package/dist/features/ai/ghost-autocomplete.d.ts +7 -6
- package/dist/features/ai/ghost-autocomplete.js +6 -9
- package/dist/features/ai/ghost-autocomplete.js.map +1 -1
- package/dist/features/ai/index.d.ts +4 -3
- package/dist/features/ai/index.js +10 -10
- package/dist/features/ai/model-profiles.d.ts +5 -4
- package/dist/features/ai/model-profiles.js +2 -2
- package/dist/features/ai/model-profiles.js.map +1 -1
- package/dist/features/ai/protocol/block-lines.js +1 -1
- package/dist/features/ai/protocol/block-lines.js.map +1 -1
- package/dist/features/ai/protocol/chat.js +6 -2
- package/dist/features/ai/protocol/chat.js.map +1 -1
- package/dist/features/ai/protocol/index.d.ts +3 -2
- package/dist/features/ai/protocol/models.d.ts +2 -16
- package/dist/features/ai/protocol/models.js.map +1 -1
- package/dist/features/ai/rate-limit.d.ts +1 -1
- package/dist/features/ai/rate-limit.js +3 -1
- package/dist/features/ai/rate-limit.js.map +1 -1
- package/dist/features/ai/react/AiSelectionMenu.js +2 -2
- package/dist/features/ai/react/AiSidebar.js +4 -4
- package/dist/features/ai/react/DocumentChatAnswer.js +1 -1
- package/dist/features/ai/react/DocumentChatOps.d.ts +1 -1
- package/dist/features/ai/react/DocumentChatOps.js +1 -1
- package/dist/features/ai/react/SettingsModelProfiles.js +8 -10
- package/dist/features/ai/react/SettingsModelProfiles.js.map +1 -1
- package/dist/features/ai/react/use-ai-assistant.d.ts +1 -1
- package/dist/features/ai/react/use-ai-assistant.js +3 -3
- package/dist/features/ai/react/use-ai-assistant.js.map +1 -1
- package/dist/features/ai/react/use-document-chat.js +2 -2
- package/dist/features/ai/react/use-document-chat.js.map +1 -1
- package/dist/features/ai/react/use-model-profiles.d.ts +2 -1
- package/dist/features/ai/selection-flow.d.ts +1 -1
- package/dist/features/ai/selection-flow.js +1 -1
- package/dist/features/ai/sidebar-flow.d.ts +1 -1
- package/dist/features/ai/sidebar-flow.js +1 -1
- package/dist/features/ai/use-ai-assistant.d.ts +1 -1
- package/dist/features/ai/use-ai-assistant.js +3 -3
- package/dist/features/ai/use-ai-assistant.js.map +1 -1
- package/dist/features/ai/use-document-chat.js +2 -2
- package/dist/features/ai/use-document-chat.js.map +1 -1
- package/dist/features/ai/use-model-profiles.d.ts +2 -1
- package/dist/features/authors/attribution.d.ts +1 -1
- package/dist/features/authors/feature.js +12 -11
- package/dist/features/authors/feature.js.map +1 -1
- package/dist/features/block-ui/block-actions.d.ts +1 -1
- package/dist/features/block-ui/block-actions.js +1 -1
- package/dist/features/block-ui/block-actions.js.map +1 -1
- package/dist/features/block-ui/components/BlockUi.js +1 -1
- package/dist/features/block-ui/feature.js +1 -0
- package/dist/features/block-ui/feature.js.map +1 -1
- package/dist/features/block-ui/react/BlockUi.js +1 -1
- package/dist/features/collab/anchor-resolver.js +1 -1
- package/dist/features/collab/feature.js +2 -0
- package/dist/features/collab/feature.js.map +1 -1
- package/dist/features/comments/components/CommentThreadView.vue.d.ts +2 -1
- package/dist/features/comments/feature.js +12 -11
- package/dist/features/comments/feature.js.map +1 -1
- package/dist/features/comments/index.d.ts +3 -2
- package/dist/features/comments/index.js +1 -1
- package/dist/features/comments/margin-layout.d.ts +3 -2
- package/dist/features/comments/model.d.ts +3 -67
- package/dist/features/comments/model.js +2 -2
- package/dist/features/comments/model.js.map +1 -1
- package/dist/features/comments/react/CommentThreadView.d.ts +3 -2
- package/dist/features/comments/react/use-comments.d.ts +2 -1
- package/dist/features/comments/react.d.ts +1 -1
- package/dist/features/comments/schema.d.ts +2 -52
- package/dist/features/comments/schema.js.map +1 -1
- package/dist/features/comments/snapshot-equality.js.map +1 -1
- package/dist/features/comments/use-comments.d.ts +3 -2
- package/dist/features/comments/vue.d.ts +1 -1
- package/dist/features/composites/accepted-children.d.ts +1 -0
- package/dist/features/composites/accepted-children.js +16 -1
- package/dist/features/composites/accepted-children.js.map +1 -1
- package/dist/features/composites/ai-brief.js +39 -0
- package/dist/features/composites/ai-brief.js.map +1 -1
- package/dist/features/composites/bibliography-command.d.ts +11 -0
- package/dist/features/composites/bibliography-form.js +90 -0
- package/dist/features/composites/bibliography-form.js.map +1 -0
- package/dist/features/composites/bibliography.d.ts +33 -0
- package/dist/features/composites/bibliography.js +120 -0
- package/dist/features/composites/bibliography.js.map +1 -0
- package/dist/features/composites/components/BibliographyEditor.js +261 -0
- package/dist/features/composites/components/BibliographyEditor.js.map +1 -0
- package/dist/features/composites/components/CompositeChrome.js +78 -29
- package/dist/features/composites/components/CompositeChrome.js.map +1 -1
- package/dist/features/composites/components/CompositeChrome.vue.d.ts +1 -1
- package/dist/features/composites/components/CompositeDetails.js +46 -11
- package/dist/features/composites/components/CompositeDetails.js.map +1 -1
- package/dist/features/composites/components/CompositeDetails.vue.d.ts +2 -1
- package/dist/features/composites/components/CompositeFieldEditor.js +64 -5
- package/dist/features/composites/components/CompositeFieldEditor.js.map +1 -1
- package/dist/features/composites/components/CompositeInspector.js +20 -7
- package/dist/features/composites/components/CompositeInspector.js.map +1 -1
- package/dist/features/composites/components/CompositeTable.js +13 -4
- package/dist/features/composites/components/CompositeTable.js.map +1 -1
- package/dist/features/composites/components/CompositeTagsEditor.js +1 -1
- package/dist/features/composites/components/CompositeView.js +11 -1
- package/dist/features/composites/components/CompositeView.js.map +1 -1
- package/dist/features/composites/components/DerivationBadge.js +103 -0
- package/dist/features/composites/components/DerivationBadge.js.map +1 -0
- package/dist/features/composites/components/ReferenceFieldSelect.js +60 -0
- package/dist/features/composites/components/ReferenceFieldSelect.js.map +1 -0
- package/dist/features/composites/components/ReferenceView.js +122 -0
- package/dist/features/composites/components/ReferenceView.js.map +1 -0
- package/dist/features/composites/components/ReferenceView.vue.d.ts +96 -0
- package/dist/features/composites/components/SettingsEditingTab.js +1 -1
- package/dist/features/composites/convert.js +2 -2
- package/dist/features/composites/convert.js.map +1 -1
- package/dist/features/composites/derivation.d.ts +61 -0
- package/dist/features/composites/derivation.js +98 -0
- package/dist/features/composites/derivation.js.map +1 -0
- package/dist/features/composites/derived-chrome.js +69 -0
- package/dist/features/composites/derived-chrome.js.map +1 -0
- package/dist/features/composites/feature.js +159 -109
- package/dist/features/composites/feature.js.map +1 -1
- package/dist/features/composites/fences.d.ts +4 -3
- package/dist/features/composites/fences.js +51 -7
- package/dist/features/composites/fences.js.map +1 -1
- package/dist/features/composites/index.d.ts +12 -3
- package/dist/features/composites/index.js +15 -6
- package/dist/features/composites/inspector-model.d.ts +4 -1
- package/dist/features/composites/inspector-model.js +8 -4
- package/dist/features/composites/inspector-model.js.map +1 -1
- package/dist/features/composites/kinds.d.ts +16 -2
- package/dist/features/composites/kinds.js +145 -6
- package/dist/features/composites/kinds.js.map +1 -1
- package/dist/features/composites/legacy.d.ts +4 -1
- package/dist/features/composites/legacy.js +56 -1
- package/dist/features/composites/legacy.js.map +1 -1
- package/dist/features/composites/meta-display.js +45 -2
- package/dist/features/composites/meta-display.js.map +1 -1
- package/dist/features/composites/meta-keys.d.ts +7 -0
- package/dist/features/composites/meta-keys.js +21 -0
- package/dist/features/composites/meta-keys.js.map +1 -0
- package/dist/features/composites/node-views.d.ts +6 -3
- package/dist/features/composites/node-views.js +7 -3
- package/dist/features/composites/node-views.js.map +1 -1
- package/dist/features/composites/nodes.d.ts +6 -1
- package/dist/features/composites/nodes.js +33 -7
- package/dist/features/composites/nodes.js.map +1 -1
- package/dist/features/composites/react/BibliographyEditor.js +229 -0
- package/dist/features/composites/react/BibliographyEditor.js.map +1 -0
- package/dist/features/composites/react/CompositeChrome.js +67 -19
- package/dist/features/composites/react/CompositeChrome.js.map +1 -1
- package/dist/features/composites/react/CompositeDetails.d.ts +2 -1
- package/dist/features/composites/react/CompositeDetails.js +45 -6
- package/dist/features/composites/react/CompositeDetails.js.map +1 -1
- package/dist/features/composites/react/CompositeFieldEditor.d.ts +1 -1
- package/dist/features/composites/react/CompositeFieldEditor.js +43 -1
- package/dist/features/composites/react/CompositeFieldEditor.js.map +1 -1
- package/dist/features/composites/react/CompositeInspector.js +12 -6
- package/dist/features/composites/react/CompositeInspector.js.map +1 -1
- package/dist/features/composites/react/CompositeStatusMenu.js +1 -1
- package/dist/features/composites/react/CompositeSummaryEditor.js +1 -1
- package/dist/features/composites/react/CompositeTable.js +16 -2
- package/dist/features/composites/react/CompositeTable.js.map +1 -1
- package/dist/features/composites/react/CompositeTagsEditor.js +2 -2
- package/dist/features/composites/react/CompositeView.js +6 -1
- package/dist/features/composites/react/CompositeView.js.map +1 -1
- package/dist/features/composites/react/DerivationBadge.js +116 -0
- package/dist/features/composites/react/DerivationBadge.js.map +1 -0
- package/dist/features/composites/react/ReferenceFieldSelect.js +52 -0
- package/dist/features/composites/react/ReferenceFieldSelect.js.map +1 -0
- package/dist/features/composites/react/ReferenceView.d.ts +11 -0
- package/dist/features/composites/react/ReferenceView.js +115 -0
- package/dist/features/composites/react/ReferenceView.js.map +1 -0
- package/dist/features/composites/react/SettingsEditingTab.js +2 -2
- package/dist/features/composites/react.d.ts +2 -1
- package/dist/features/composites/react.js +7 -3
- package/dist/features/composites/react.js.map +1 -1
- package/dist/features/composites/reference-ai.js +16 -0
- package/dist/features/composites/reference-ai.js.map +1 -0
- package/dist/features/composites/reference-label.d.ts +19 -0
- package/dist/features/composites/reference-label.js +58 -0
- package/dist/features/composites/reference-label.js.map +1 -0
- package/dist/features/composites/reference-suggestion.d.ts +10 -0
- package/dist/features/composites/reference-suggestion.js +41 -0
- package/dist/features/composites/reference-suggestion.js.map +1 -0
- package/dist/features/composites/reference-text.d.ts +18 -0
- package/dist/features/composites/reference-text.js +89 -0
- package/dist/features/composites/reference-text.js.map +1 -0
- package/dist/features/composites/reference.d.ts +44 -0
- package/dist/features/composites/reference.js +148 -0
- package/dist/features/composites/reference.js.map +1 -0
- package/dist/features/composites/reveal-source.d.ts +32 -0
- package/dist/features/composites/reveal-source.js +89 -0
- package/dist/features/composites/reveal-source.js.map +1 -0
- package/dist/features/composites/rows.d.ts +25 -3
- package/dist/features/composites/rows.js +72 -10
- package/dist/features/composites/rows.js.map +1 -1
- package/dist/features/composites/schema.d.ts +9 -3
- package/dist/features/composites/schema.js +11 -4
- package/dist/features/composites/schema.js.map +1 -1
- package/dist/features/composites/table-model.js +12 -21
- package/dist/features/composites/table-model.js.map +1 -1
- package/dist/features/composites/vue.d.ts +3 -2
- package/dist/features/composites/vue.js +8 -4
- package/dist/features/composites/vue.js.map +1 -1
- package/dist/features/media/assets.d.ts +2 -0
- package/dist/features/media/assets.js +3 -2
- package/dist/features/media/assets.js.map +1 -1
- package/dist/features/media/components/FileView.js +13 -4
- package/dist/features/media/components/FileView.js.map +1 -1
- package/dist/features/media/feature.d.ts +3 -3
- package/dist/features/media/feature.js +21 -28
- package/dist/features/media/feature.js.map +1 -1
- package/dist/features/media/file-import.js +2 -2
- package/dist/features/media/file-import.js.map +1 -1
- package/dist/features/media/index.d.ts +2 -2
- package/dist/features/media/index.js +3 -3
- package/dist/features/media/react/AudioRecorderModal.js +1 -1
- package/dist/features/media/react/FileView.js +19 -2
- package/dist/features/media/react/FileView.js.map +1 -1
- package/dist/features/media/react.js +1 -1
- package/dist/features/media/schema.d.ts +8 -0
- package/dist/features/media/schema.js +126 -11
- package/dist/features/media/schema.js.map +1 -1
- package/dist/features/media/upload.d.ts +16 -14
- package/dist/features/media/upload.js +13 -19
- package/dist/features/media/upload.js.map +1 -1
- package/dist/features/mentions/index.d.ts +4 -3
- package/dist/features/mentions/index.js +4 -1
- package/dist/features/mentions/index.js.map +1 -1
- package/dist/features/mentions/mention-text.d.ts +1 -1
- package/dist/features/mentions/mention-text.js.map +1 -1
- package/dist/features/mentions/mention.d.ts +0 -6
- package/dist/features/mentions/mention.js.map +1 -1
- package/dist/features/mentions/metadata-defaults.d.ts +2 -2
- package/dist/features/mentions/metadata-defaults.js +3 -9
- package/dist/features/mentions/metadata-defaults.js.map +1 -1
- package/dist/features/mentions/schema.d.ts +2 -1
- package/dist/features/mentions/schema.js.map +1 -1
- package/dist/features/tables/feature.d.ts +2 -1
- package/dist/features/tables/feature.js +90 -70
- package/dist/features/tables/feature.js.map +1 -1
- package/dist/features/themes/components/SettingsAppearanceTab.js +6 -9
- package/dist/features/themes/components/SettingsAppearanceTab.js.map +1 -1
- package/dist/features/themes/feature.js +2 -0
- package/dist/features/themes/feature.js.map +1 -1
- package/dist/features/themes/index.d.ts +2 -1
- package/dist/features/themes/react/SettingsAppearanceTab.js +7 -10
- package/dist/features/themes/react/SettingsAppearanceTab.js.map +1 -1
- package/dist/features/themes/schema.d.ts +2 -6
- package/dist/features/themes/schema.js.map +1 -1
- package/dist/features/themes/theme-runtime.d.ts +1 -1
- package/dist/features/themes/theme-runtime.js +4 -2
- package/dist/features/themes/theme-runtime.js.map +1 -1
- package/dist/features/transcript/TranscriptSegmentView.js +48 -28
- package/dist/features/transcript/TranscriptSegmentView.js.map +1 -1
- package/dist/features/transcript/feature.js +21 -19
- package/dist/features/transcript/feature.js.map +1 -1
- package/dist/features/transcript/react/TranscriptSegmentView.js +55 -36
- package/dist/features/transcript/react/TranscriptSegmentView.js.map +1 -1
- package/dist/features/transcript/segment-node.d.ts +2 -0
- package/dist/features/transcript/segment-node.js +35 -7
- package/dist/features/transcript/segment-node.js.map +1 -1
- package/dist/i18n/de/composites.js +91 -1
- package/dist/i18n/de/composites.js.map +1 -1
- package/dist/i18n/de/integrations.js +49 -8
- package/dist/i18n/de/integrations.js.map +1 -1
- package/dist/i18n/de/media.js +0 -1
- package/dist/i18n/de/media.js.map +1 -1
- package/dist/i18n/de/palette.js +22 -0
- package/dist/i18n/de/palette.js.map +1 -0
- package/dist/i18n/de/tables.js +0 -1
- package/dist/i18n/de/tables.js.map +1 -1
- package/dist/i18n/de/transcript.js +2 -1
- package/dist/i18n/de/transcript.js.map +1 -1
- package/dist/i18n/de/tree.js +3 -0
- package/dist/i18n/de/tree.js.map +1 -1
- package/dist/i18n/de.d.ts +157 -11
- package/dist/i18n/de.js +3 -1
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en/composites.js +89 -1
- package/dist/i18n/en/composites.js.map +1 -1
- package/dist/i18n/en/integrations.js +49 -8
- package/dist/i18n/en/integrations.js.map +1 -1
- package/dist/i18n/en/media.js +0 -1
- package/dist/i18n/en/media.js.map +1 -1
- package/dist/i18n/en/palette.js +22 -0
- package/dist/i18n/en/palette.js.map +1 -0
- package/dist/i18n/en/tables.js +0 -1
- package/dist/i18n/en/tables.js.map +1 -1
- package/dist/i18n/en/transcript.js +2 -1
- package/dist/i18n/en/transcript.js.map +1 -1
- package/dist/i18n/en/tree.js +3 -0
- package/dist/i18n/en/tree.js.map +1 -1
- package/dist/i18n/en.js +3 -1
- package/dist/i18n/en.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/integrations/composite-ai/bibliography-fetch.d.ts +31 -0
- package/dist/integrations/composite-ai/bibliography-fetch.js +159 -0
- package/dist/integrations/composite-ai/bibliography-fetch.js.map +1 -0
- package/dist/integrations/composite-ai/composite-fill.d.ts +30 -8
- package/dist/integrations/composite-ai/composite-fill.js +97 -56
- package/dist/integrations/composite-ai/composite-fill.js.map +1 -1
- package/dist/integrations/composite-ai/composite-summary.d.ts +4 -12
- package/dist/integrations/composite-ai/composite-summary.js +7 -26
- package/dist/integrations/composite-ai/composite-summary.js.map +1 -1
- package/dist/integrations/composite-ai/derive.d.ts +29 -0
- package/dist/integrations/composite-ai/derive.js +173 -0
- package/dist/integrations/composite-ai/derive.js.map +1 -0
- package/dist/integrations/composite-ai/index.d.ts +11 -7
- package/dist/integrations/composite-ai/index.js +72 -14
- package/dist/integrations/composite-ai/index.js.map +1 -1
- package/dist/integrations/composite-ai/rendition.d.ts +45 -0
- package/dist/integrations/composite-ai/rendition.js +314 -0
- package/dist/integrations/composite-ai/rendition.js.map +1 -0
- package/dist/integrations/composite-media/index.d.ts +7 -5
- package/dist/integrations/composite-media/index.js +86 -13
- package/dist/integrations/composite-media/index.js.map +1 -1
- package/dist/integrations/transcript-ai/index.d.ts +1 -1
- package/dist/integrations/transcript-ai/index.js +5 -2
- package/dist/integrations/transcript-ai/index.js.map +1 -1
- package/dist/integrations/transcript-ai/protocol.d.ts +2 -12
- package/dist/integrations/transcript-ai/protocol.js +0 -2
- package/dist/integrations/transcript-ai/protocol.js.map +1 -1
- package/dist/integrations/transcript-ai/transcript-cleanup.d.ts +5 -5
- package/dist/integrations/transcript-ai/transcript-cleanup.js +7 -10
- package/dist/integrations/transcript-ai/transcript-cleanup.js.map +1 -1
- package/dist/markdown/MarkdownSurface.vue.d.ts +12 -11
- package/dist/markdown/MarkdownSurface2.js +3 -6
- package/dist/markdown/MarkdownSurface2.js.map +1 -1
- package/dist/markdown/document.js +1 -1
- package/dist/markdown/source-mode.d.ts +1 -1
- package/dist/nuxt/module.d.ts +1402 -54
- package/dist/nuxt/module.js +6 -49
- package/dist/nuxt/module.js.map +1 -1
- package/dist/nuxt/runtime/install-context.d.ts +7 -3
- package/dist/nuxt/runtime/install-context.js +14 -8
- package/dist/nuxt/runtime/install-context.js.map +1 -1
- package/dist/nuxt/runtime/plugins/editor-context-nuxt-ui.client.ts +2 -2
- package/dist/nuxt/runtime/server/plugins/editor-server.js +20 -12
- package/dist/nuxt/runtime/server/plugins/editor-server.js.map +1 -1
- package/dist/presets/compose.d.ts +94 -0
- package/dist/presets/compose.js +164 -0
- package/dist/presets/compose.js.map +1 -0
- package/dist/react/AdvancedEditor.d.ts +15 -15
- package/dist/react/AdvancedEditor.js +15 -13
- package/dist/react/AdvancedEditor.js.map +1 -1
- package/dist/react/EditorCommandPalette.d.ts +13 -0
- package/dist/react/EditorCommandPalette.js +118 -0
- package/dist/react/EditorCommandPalette.js.map +1 -0
- package/dist/react/EditorSettingsModal.d.ts +5 -5
- package/dist/react/EditorSettingsModal.js +7 -4
- package/dist/react/EditorSettingsModal.js.map +1 -1
- package/dist/react/EditorSettingsPanel.d.ts +7 -7
- package/dist/react/EditorSettingsPanel.js +8 -5
- package/dist/react/EditorSettingsPanel.js.map +1 -1
- package/dist/react/EditorSurface.d.ts +7 -7
- package/dist/react/EditorSurface.js +10 -6
- package/dist/react/EditorSurface.js.map +1 -1
- package/dist/react/EditorToolbar.d.ts +4 -6
- package/dist/react/EditorToolbar.js +29 -37
- package/dist/react/EditorToolbar.js.map +1 -1
- package/dist/react/SimpleEditor.d.ts +22 -23
- package/dist/react/SimpleEditor.js +21 -7
- package/dist/react/SimpleEditor.js.map +1 -1
- package/dist/react/advanced.d.ts +4 -3
- package/dist/react/advanced.js +2 -2
- package/dist/react/compose.d.ts +20 -0
- package/dist/react/compose.js +49 -0
- package/dist/react/compose.js.map +1 -0
- package/dist/react/composed-surface.d.ts +39 -0
- package/dist/react/composed-surface.js +71 -0
- package/dist/react/composed-surface.js.map +1 -0
- package/dist/react/context.js +6 -2
- package/dist/react/context.js.map +1 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/key-labels.js +15 -0
- package/dist/react/key-labels.js.map +1 -0
- package/dist/react/settings.d.ts +1 -1
- package/dist/react/simple.d.ts +2 -2
- package/dist/react/ui/command.js +36 -1
- package/dist/react/ui/command.js.map +1 -1
- package/dist/schema/advanced.d.ts +6 -6
- package/dist/schema/advanced.js +26 -29
- package/dist/schema/advanced.js.map +1 -1
- package/dist/server/ai.d.ts +5 -16
- package/dist/server/ai.js.map +1 -1
- package/dist/server/auth.d.ts +9 -0
- package/dist/server/collab-state.d.ts +1 -1
- package/dist/server/collab-state.js.map +1 -1
- package/dist/server/collab.d.ts +13 -13
- package/dist/server/collab.js +34 -18
- package/dist/server/collab.js.map +1 -1
- package/dist/server/crossref.js +78 -0
- package/dist/server/crossref.js.map +1 -0
- package/dist/server/errors.d.ts +1 -1
- package/dist/server/errors.js +1 -1
- package/dist/server/errors.js.map +1 -1
- package/dist/server/extract.js +308 -0
- package/dist/server/extract.js.map +1 -0
- package/dist/server/h3.d.ts +8 -0
- package/dist/{nuxt/runtime/server/utils/editor-route.js → server/h3.js} +8 -16
- package/dist/server/h3.js.map +1 -0
- package/dist/server/handlers/ai.d.ts +32 -10
- package/dist/server/handlers/ai.js +172 -37
- package/dist/server/handlers/ai.js.map +1 -1
- package/dist/server/handlers/context.d.ts +12 -5
- package/dist/server/handlers/context.js +10 -4
- package/dist/server/handlers/context.js.map +1 -1
- package/dist/server/handlers/editor.d.ts +19 -13
- package/dist/server/handlers/editor.js +49 -38
- package/dist/server/handlers/editor.js.map +1 -1
- package/dist/server/handlers/index.d.ts +4 -4
- package/dist/server/handlers/index.js +4 -4
- package/dist/server/host.d.ts +16 -25
- package/dist/server/host.js +58 -41
- package/dist/server/host.js.map +1 -1
- package/dist/server/index.d.ts +6 -4
- package/dist/server/index.js +3 -2
- package/dist/server/pdf.js +97 -0
- package/dist/server/pdf.js.map +1 -0
- package/dist/server/{adapter.d.ts → ports.d.ts} +81 -30
- package/dist/server/ports.js +29 -0
- package/dist/server/ports.js.map +1 -0
- package/dist/server/routes.d.ts +22 -0
- package/dist/server/routes.js +144 -0
- package/dist/server/routes.js.map +1 -0
- package/dist/settings/index.d.ts +1 -1
- package/dist/settings/index.js.map +1 -1
- package/dist/styles/composites.css +25 -0
- package/dist/tree/DocumentTree.js +56 -29
- package/dist/tree/DocumentTree.js.map +1 -1
- package/dist/tree/react/DocumentTree.js +23 -0
- package/dist/tree/react/DocumentTree.js.map +1 -1
- package/dist/tree/tree-host.js +2 -2
- package/dist/tree/tree-items.js +1 -1
- package/dist/vue/AdvancedEditor.js +30 -9
- package/dist/vue/AdvancedEditor.js.map +1 -1
- package/dist/vue/AdvancedEditor.vue.d.ts +32 -12
- package/dist/vue/SimpleEditor.js +62 -16
- package/dist/vue/SimpleEditor.js.map +1 -1
- package/dist/vue/SimpleEditor.vue.d.ts +39 -9
- package/dist/vue/advanced.d.ts +3 -2
- package/dist/vue/advanced.js +2 -2
- package/dist/vue/components/EditorCommandPalette.js +91 -0
- package/dist/vue/components/EditorCommandPalette.js.map +1 -0
- package/dist/vue/components/EditorCommandPalette.vue.d.ts +15 -0
- package/dist/vue/components/EditorSettingsModal.js +10 -6
- package/dist/vue/components/EditorSettingsModal.js.map +1 -1
- package/dist/vue/components/EditorSettingsModal.vue.d.ts +4 -4
- package/dist/vue/components/EditorSettingsPanel.js +10 -6
- package/dist/vue/components/EditorSettingsPanel.js.map +1 -1
- package/dist/vue/components/EditorSettingsPanel.vue.d.ts +6 -6
- package/dist/vue/components/EditorSurface.js +11 -6
- package/dist/vue/components/EditorSurface.js.map +1 -1
- package/dist/vue/components/EditorSurface.vue.d.ts +11 -11
- package/dist/vue/components/EditorToolbar.js +41 -49
- package/dist/vue/components/EditorToolbar.js.map +1 -1
- package/dist/vue/components/EditorToolbar.vue.d.ts +2 -4
- package/dist/vue/compose.d.ts +17 -0
- package/dist/vue/compose.js +51 -0
- package/dist/vue/compose.js.map +1 -0
- package/dist/vue/context-key.d.ts +6 -0
- package/dist/vue/context-key.js +6 -0
- package/dist/vue/context-key.js.map +1 -0
- package/dist/vue/context.d.ts +8 -6
- package/dist/vue/context.js +6 -5
- package/dist/vue/context.js.map +1 -1
- package/dist/vue/index.d.ts +10 -8
- package/dist/vue/index.js +10 -8
- package/dist/vue/kit/index.d.ts +2 -2
- package/dist/vue/kit/nuxt-ui.js +23 -0
- package/dist/vue/kit/nuxt-ui.js.map +1 -1
- package/dist/vue/kit/types.d.ts +40 -1
- package/package.json +30 -16
- package/dist/adapters/comments/client.d.ts +0 -64
- package/dist/adapters/comments/client.js.map +0 -1
- package/dist/adapters/routes.js.map +0 -1
- package/dist/core/toolbar.d.ts +0 -74
- package/dist/core/toolbar.js +0 -45
- package/dist/core/toolbar.js.map +0 -1
- package/dist/integrations/composite-ai/document-transcribe.d.ts +0 -14
- package/dist/integrations/composite-ai/document-transcribe.js +0 -89
- package/dist/integrations/composite-ai/document-transcribe.js.map +0 -1
- package/dist/nuxt/runtime/server/api/ai/chat.post.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/ai/chat.post.js +0 -8
- package/dist/nuxt/runtime/server/api/ai/chat.post.js.map +0 -1
- package/dist/nuxt/runtime/server/api/ai/complete.post.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/ai/complete.post.js +0 -8
- package/dist/nuxt/runtime/server/api/ai/complete.post.js.map +0 -1
- package/dist/nuxt/runtime/server/api/ai/generate.post.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/ai/generate.post.js +0 -8
- package/dist/nuxt/runtime/server/api/ai/generate.post.js.map +0 -1
- package/dist/nuxt/runtime/server/api/ai/models.get.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/ai/models.get.js +0 -8
- package/dist/nuxt/runtime/server/api/ai/models.get.js.map +0 -1
- package/dist/nuxt/runtime/server/api/ai/transcribe.post.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/ai/transcribe.post.js +0 -8
- package/dist/nuxt/runtime/server/api/ai/transcribe.post.js.map +0 -1
- package/dist/nuxt/runtime/server/api/ai/transcript-cleanup.post.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/ai/transcript-cleanup.post.js +0 -8
- package/dist/nuxt/runtime/server/api/ai/transcript-cleanup.post.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/assets/[id]/[name].get.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/assets/[id]/[name].get.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/assets/[id]/[name].get.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/assets/[id].post.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/assets/[id].post.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/assets/[id].post.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/settings.get.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/settings.get.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/settings.get.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/settings.put.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/settings.put.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/settings.put.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/tags.get.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/tags.get.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/tags.get.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/themes/[id].delete.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/themes/[id].delete.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/themes/[id].delete.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/themes/[id].get.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/themes/[id].get.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/themes/[id].get.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/themes/index.get.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/themes/index.get.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/themes/index.get.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/themes/index.post.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/themes/index.post.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/themes/index.post.js.map +0 -1
- package/dist/nuxt/runtime/server/api/editor/users.get.d.ts +0 -5
- package/dist/nuxt/runtime/server/api/editor/users.get.js +0 -8
- package/dist/nuxt/runtime/server/api/editor/users.get.js.map +0 -1
- package/dist/nuxt/runtime/server/plugins/collab.d.ts +0 -5
- package/dist/nuxt/runtime/server/plugins/collab.js +0 -10
- package/dist/nuxt/runtime/server/plugins/collab.js.map +0 -1
- package/dist/nuxt/runtime/server/routes/collab/[id].d.ts +0 -5
- package/dist/nuxt/runtime/server/routes/collab/[id].js +0 -35
- package/dist/nuxt/runtime/server/routes/collab/[id].js.map +0 -1
- package/dist/nuxt/runtime/server/utils/editor-route.d.ts +0 -11
- package/dist/nuxt/runtime/server/utils/editor-route.js.map +0 -1
- package/dist/presets/advanced.d.ts +0 -33
- package/dist/presets/advanced.js +0 -50
- package/dist/presets/advanced.js.map +0 -1
- package/dist/presets/simple.d.ts +0 -9
- package/dist/presets/simple.js +0 -12
- package/dist/presets/simple.js.map +0 -1
- package/dist/react/advanced-preset.d.ts +0 -11
- package/dist/react/advanced-preset.js +0 -31
- package/dist/react/advanced-preset.js.map +0 -1
- package/dist/vue/advanced-preset.d.ts +0 -13
- package/dist/vue/advanced-preset.js +0 -33
- package/dist/vue/advanced-preset.js.map +0 -1
- package/docs/extending.md +0 -538
- package/docs/integration.md +0 -632
- package/docs/llms.md +0 -383
- package/docs/usage.md +0 -1076
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive.js","names":[],"sources":["../../../src/integrations/composite-ai/derive.ts"],"sourcesContent":["import type { Editor, JSONContent } from '@tiptap/core'\nimport { Fragment, type Node as PMNode } from '@tiptap/pm/model'\nimport type { EditorBackend } from '../../core/backend'\nimport { guardsAccept, parseBlocks, sha256Hex } from '../../core'\nimport type { Notifier } from '../../core/notify'\nimport { blockIdOf, findBlockById, newBlockId } from '../../core/schema'\nimport type { Translate } from '../../i18n'\nimport { type ModelRef, notifyAiRateLimited } from '../../features/ai'\nimport { bodyMarkdown, COMPOSITE_CHROME_COUNT, compositeJSON, compositeKind, compositeKindsOf, DERIVATION_KEY, type Derivation, derivationOf } from '../../features/composites/schema'\nimport { generateCompositeBody } from './composite-fill'\n\n/** Kinds a Baustein can be derived into: the ones with an `ai` configuration (their brief drives the generation). */\nexport const derivableKindsOf = (editor: Editor) => compositeKindsOf(editor).filter(kind => kind.ai !== undefined)\n\n/** Whether the Baustein `node` can be the source of a derivation: a composite with a block id (the derivation points at it by id). */\nexport const isDerivableSource = (editor: Editor, node: PMNode) => node.type.name === 'composite' && blockIdOf(node) !== null && derivableKindsOf(editor).length > 0\n\n/** Whether a Baustein of `kindId` may be inserted right after the Baustein at `pos` (the same guards as creating it there). */\nexport function canDeriveAfter(editor: Editor, pos: number, kindId: string): boolean {\n const source = editor.state.doc.nodeAt(pos)\n if (!source) return false\n const $at = editor.state.doc.resolve(pos + source.nodeSize)\n return guardsAccept(editor, $at, { type: 'composite', attrs: { kind: kindId } })\n}\n\n/**\n * „Ableiten (KI) → <Art>“: inserts a sibling Baustein of kind `kindId` right after the Baustein at `pos`, titled\n * „<Art>: <Quelle>“, whose `meta.derivation` points back at the source block (`from.block`, method `ai:<kindId>`, the\n * Markdown hash of the source's body as `inputHash`), generates its body from the source (`generateCompositeBody`; the\n * `aiBlockData` of composites hands the model the source's Markdown) and writes the result directly into the new\n * Baustein — no review, the new Baustein is the proposal. The hash of the written body becomes `outputHash`, so a later\n * edit shows as „bearbeitet“ and a later edit of the source as „Quelle geändert“. The new Baustein is found again by its\n * block id after every await, so edits while the model runs do not misplace the result. When the run fails or yields\n * nothing the still-empty Baustein is removed again. Notices go through `notify`, in the language of `t`.\n */\nexport async function deriveComposite(editor: Editor, pos: number, kindId: string, ai: NonNullable<EditorBackend['ai']>, modelRef: (slot: 'generate') => ModelRef, notify: Notifier, t: Translate): Promise<void> {\n const source = editor.state.doc.nodeAt(pos)\n const sourceId = source && blockIdOf(source)\n const kind = compositeKindsOf(editor).find(candidate => candidate.id === kindId)\n if (source?.type.name !== 'composite' || !sourceId || !kind?.ai) return\n if (!canDeriveAfter(editor, pos, kindId)) {\n notify({ title: t('integrations.compositeDerive.notAccepted'), kind: 'error' })\n return\n }\n\n const sourceKind = compositeKind(compositeKindsOf(editor), String(source.attrs.kind))\n const derivation: Derivation = {\n from: { block: sourceId },\n method: `ai:${kindId}`,\n createdAt: new Date().toISOString(),\n inputHash: sha256Hex(bodyMarkdown(editor, source)),\n outputHash: '',\n }\n const id = newBlockId()\n const json = compositeJSON(kindId)\n const [title, ...rest] = json.content as JSONContent[]\n const text = `${kind.label}: ${source.child(0).textContent.trim() || sourceKind.label}`\n const created: JSONContent = {\n ...json,\n attrs: { ...json.attrs, id, meta: { [DERIVATION_KEY]: derivation } },\n content: [{ ...title!, content: [{ type: 'text', text }] }, ...rest],\n }\n editor.view.dispatch(editor.state.tr.insert(pos + source.nodeSize, editor.schema.nodeFromJSON(created)))\n\n const toastId = `derive-${id}`\n const controller = new AbortController()\n const abort = () => controller.abort()\n editor.on('destroy', abort)\n notify({ id: toastId, title: t('integrations.compositeDerive.running', { kind: kind.label }), kind: 'info', icon: 'i-lucide-loader-circle', duration: 0 })\n\n /** Drops the new Baustein again, unless its body got content meanwhile (the user may have started writing in it). */\n const discard = () => {\n const found = editor.isDestroyed ? null : findBlockById(editor.state.doc, id)\n if (!found) return\n const body = Array.from({ length: found.node.childCount - COMPOSITE_CHROME_COUNT }, (_, index) => found.node.child(COMPOSITE_CHROME_COUNT + index))\n if (body.some(child => child.textContent.trim() || child.type.name !== 'paragraph')) return\n editor.view.dispatch(editor.state.tr.delete(found.pos, found.pos + found.node.nodeSize))\n }\n\n try {\n const target = findBlockById(editor.state.doc, id)\n const result = target ? await generateCompositeBody(editor, target.pos, ai, modelRef, t, controller.signal) : null\n if (!result || result.status === 'aborted' || editor.isDestroyed) {\n if (!editor.isDestroyed) discard()\n return\n }\n if (result.status === 'rate-limited') {\n discard()\n notifyAiRateLimited(notify, t)\n return\n }\n if (result.status === 'data-error') {\n discard()\n notify({ title: t('integrations.compositeFill.dataMissing'), description: result.message, kind: 'error' })\n return\n }\n if (result.status === 'error') {\n discard()\n notify({ title: t('integrations.compositeDerive.failed'), description: result.message, kind: 'error' })\n return\n }\n\n const blocks = result.output.trim() ? parseBlocks(editor, result.output).blocks.map(block => editor.schema.nodeFromJSON(block)) : []\n if (!blocks.length) {\n discard()\n notify({ title: t('integrations.compositeDerive.empty.title'), description: t('integrations.compositeDerive.empty.description'), kind: 'error' })\n return\n }\n const found = findBlockById(editor.state.doc, id)\n if (!found || !found.node.canReplace(COMPOSITE_CHROME_COUNT, found.node.childCount, Fragment.from(blocks))) {\n notify({ title: t('integrations.compositeDerive.gone.title'), description: t('integrations.compositeDerive.gone.description'), kind: 'error' })\n return\n }\n\n // One transaction: body and the hash of exactly that body, so one undo step removes both.\n const chromeSize = Array.from({ length: COMPOSITE_CHROME_COUNT }, (_, index) => found.node.child(index).nodeSize).reduce((sum, size) => sum + size, 0)\n const tr = editor.state.tr.replaceWith(found.pos + 1 + chromeSize, found.pos + found.node.nodeSize - 1, blocks)\n const written = findBlockById(tr.doc, id)!\n const stored = derivationOf(written.node) ?? derivation\n tr.setNodeMarkup(written.pos, undefined, {\n ...written.node.attrs,\n meta: { ...written.node.attrs.meta, [DERIVATION_KEY]: { ...stored, outputHash: sha256Hex(bodyMarkdown(editor, written.node)) } },\n })\n editor.view.dispatch(tr)\n editor.commands.revealBlock(id)\n notify({ title: t('integrations.compositeDerive.done', { kind: kind.label }), kind: 'success', icon: 'i-lucide-git-branch' })\n }\n finally {\n notify.dismiss?.(toastId)\n editor.off('destroy', abort)\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,oBAAoB,WAAmB,iBAAiB,MAAM,CAAC,CAAC,QAAO,SAAQ,KAAK,OAAO,KAAA,CAAS;;AAGjH,MAAa,qBAAqB,QAAgB,SAAiB,KAAK,KAAK,SAAS,eAAe,UAAU,IAAI,MAAM,QAAQ,iBAAiB,MAAM,CAAC,CAAC,SAAS;;AAGnK,SAAgB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KAAK;GAChB,MAAM;IAAE,GAAG,QAAQ,KAAK,MAAM;KAAO,iBAAiB;KAAE,GAAG;KAAQ,YAAY,UAAU,aAAa,QAAQ,QAAQ,IAAI,CAAC;IAAE;GAAE;EACjI,CAAC;EACD,OAAO,KAAK,SAAS,EAAE;EACvB,OAAO,SAAS,YAAY,EAAE;EAC9B,OAAO;GAAE,OAAO,EAAE,qCAAqC,EAAE,MAAM,KAAK,MAAM,CAAC;GAAG,MAAM;GAAW,MAAM;EAAsB,CAAC;CAC9H,UACQ;EACN,OAAO,UAAU,OAAO;EACxB,OAAO,IAAI,WAAW,KAAK;CAC7B;AACF"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { EditorFeature } from "../../core/feature.js";
|
|
2
2
|
import "../../core/index.js";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import "../../features/composites/bibliography-command.js";
|
|
4
|
+
import { CompositeBodyResult, fillComposite, generateCompositeBody } from "./composite-fill.js";
|
|
5
|
+
import { COMPOSITE_BODY_START, compositeSourceText, summarizeComposite } from "./composite-summary.js";
|
|
6
|
+
import { RenditionOptions, canCreateRendition, canRegenerateRendition, createRendition, regenerateRendition } from "./rendition.js";
|
|
7
|
+
import { canDeriveAfter, derivableKindsOf, deriveComposite, isDerivableSource } from "./derive.js";
|
|
8
|
+
import { canFetchBibliography, doiOf, fetchBibliography } from "./bibliography-fetch.js";
|
|
6
9
|
//#region src/integrations/composite-ai/index.d.ts
|
|
7
10
|
/**
|
|
8
11
|
* AI on composites (requires `composites`, `ai`, `media`): the „Baustein füllen (KI)“ block action (on composites of
|
|
9
12
|
* kinds with an `ai` configuration: brief + document → task `fill-block`, the result opens the diff review over the
|
|
10
13
|
* body), the „Zusammenfassung erzeugen“ block action (streams a
|
|
11
|
-
* summary of a composite's body
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
+
* summary of a composite's body into its description), the „Lesefassung erzeugen“ / „Neu erzeugen (ersetzen)“
|
|
15
|
+
* actions of source-holding Bausteine (`ai.extract`: a rendition child with the transcript, full text or description of
|
|
16
|
+
* the source; a recording needs the app's public AI configuration to enable transcription),
|
|
17
|
+
* and the composite-structure form of AI results: with `composite` structure an AI result that
|
|
14
18
|
* has a heading is inserted as a `section` composite fence, otherwise (and in flat structure) the base AI heading
|
|
15
19
|
* is used. It is the preset's single `formatAiResult` contributor. The base AI feature and the composites feature do
|
|
16
20
|
* not know it. Framework-free: notices go through the surface's `ctx.notify`, the model through the app's
|
|
@@ -18,5 +22,5 @@ import { transcribeDocument } from "./document-transcribe.js";
|
|
|
18
22
|
*/
|
|
19
23
|
export declare function compositeAiFeature(): EditorFeature<never>;
|
|
20
24
|
//#endregion
|
|
21
|
-
export { COMPOSITE_BODY_START, compositeSourceText, fillComposite,
|
|
25
|
+
export { COMPOSITE_BODY_START, type CompositeBodyResult, type RenditionOptions, canCreateRendition, canDeriveAfter, canFetchBibliography, canRegenerateRendition, compositeSourceText, createRendition, derivableKindsOf, deriveComposite, doiOf, fetchBibliography, fillComposite, generateCompositeBody, isDerivableSource, regenerateRendition, summarizeComposite };
|
|
22
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -5,11 +5,28 @@ import { compositeKindsOf } from "../../features/composites/nodes.js";
|
|
|
5
5
|
import { withHeading } from "../../features/ai/protocol/tasks.js";
|
|
6
6
|
import { modelProfiles } from "../../features/ai/model-profiles.js";
|
|
7
7
|
import { structureOf } from "../../features/composites/structure.js";
|
|
8
|
-
import { fillComposite } from "./composite-fill.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { fillComposite, generateCompositeBody } from "./composite-fill.js";
|
|
9
|
+
import { canDeriveAfter, derivableKindsOf, deriveComposite, isDerivableSource } from "./derive.js";
|
|
10
|
+
import { canFetchBibliography, doiOf, fetchBibliography } from "./bibliography-fetch.js";
|
|
11
|
+
import { COMPOSITE_BODY_START, compositeSourceText, summarizeComposite } from "./composite-summary.js";
|
|
12
|
+
import { canCreateRendition, canRegenerateRendition, createRendition, regenerateRendition } from "./rendition.js";
|
|
13
|
+
import { Extension } from "@tiptap/core";
|
|
11
14
|
//#region src/integrations/composite-ai/index.ts
|
|
15
|
+
/** The editor command `fetchCompositeBibliography` (declared by composites) behind the bibliography editor's „DOI abrufen“ button; absent without the AI capability. */
|
|
16
|
+
function bibliographyFetchExtensions(ctx) {
|
|
17
|
+
const ai = ctx.backend.ai;
|
|
18
|
+
if (!ai) return [];
|
|
19
|
+
return [Extension.create({
|
|
20
|
+
name: "compositeBibliographyFetch",
|
|
21
|
+
addCommands: () => ({ fetchCompositeBibliography: (pos) => ({ editor }) => {
|
|
22
|
+
fetchBibliography(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t, ctx.documentId);
|
|
23
|
+
return true;
|
|
24
|
+
} })
|
|
25
|
+
})];
|
|
26
|
+
}
|
|
12
27
|
function compositeAiActions(ctx) {
|
|
28
|
+
const ai = ctx.backend.ai;
|
|
29
|
+
if (!ai) return [];
|
|
13
30
|
return [
|
|
14
31
|
{
|
|
15
32
|
id: "composite-fill",
|
|
@@ -19,7 +36,7 @@ function compositeAiActions(ctx) {
|
|
|
19
36
|
order: 25,
|
|
20
37
|
isVisible: ({ editor, node }) => node.type.name === "composite" && compositeKind(compositeKindsOf(editor), String(node.attrs.kind)).ai !== void 0,
|
|
21
38
|
run: ({ editor, pos }) => {
|
|
22
|
-
fillComposite(editor, pos,
|
|
39
|
+
fillComposite(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t);
|
|
23
40
|
}
|
|
24
41
|
},
|
|
25
42
|
{
|
|
@@ -30,18 +47,56 @@ function compositeAiActions(ctx) {
|
|
|
30
47
|
order: 30,
|
|
31
48
|
isVisible: ({ node }) => compositeSourceText(node).trim().length > 0,
|
|
32
49
|
run: ({ editor, pos }) => {
|
|
33
|
-
summarizeComposite(editor, pos,
|
|
50
|
+
summarizeComposite(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t);
|
|
34
51
|
}
|
|
35
52
|
},
|
|
36
53
|
{
|
|
37
|
-
id: "
|
|
38
|
-
label: ctx.t("integrations.
|
|
54
|
+
id: "composite-derive",
|
|
55
|
+
label: ctx.t("integrations.compositeDerive.action"),
|
|
56
|
+
icon: "i-lucide-git-branch",
|
|
57
|
+
ability: ABILITY.compositeDerive,
|
|
58
|
+
order: 452,
|
|
59
|
+
isVisible: ({ editor, node }) => isDerivableSource(editor, node),
|
|
60
|
+
menu: ({ editor, pos }) => derivableKindsOf(editor).map((kind) => ({
|
|
61
|
+
label: kind.label,
|
|
62
|
+
icon: kind.icon,
|
|
63
|
+
disabled: !canDeriveAfter(editor, pos, kind.id),
|
|
64
|
+
onSelect: () => {
|
|
65
|
+
deriveComposite(editor, pos, kind.id, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t);
|
|
66
|
+
}
|
|
67
|
+
}))
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "bibliography-fetch",
|
|
71
|
+
label: ctx.t("integrations.bibliographyFetch.action"),
|
|
72
|
+
icon: "i-lucide-book-marked",
|
|
73
|
+
ability: ABILITY.compositeDerive,
|
|
74
|
+
order: 453,
|
|
75
|
+
isVisible: ({ editor, node }) => canFetchBibliography(editor, node),
|
|
76
|
+
run: ({ editor, pos }) => {
|
|
77
|
+
fetchBibliography(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t, ctx.documentId);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "rendition-create",
|
|
82
|
+
label: ctx.t("integrations.rendition.action"),
|
|
39
83
|
icon: "i-lucide-captions",
|
|
40
|
-
ability: ABILITY.
|
|
84
|
+
ability: ABILITY.compositeDerive,
|
|
41
85
|
order: 450,
|
|
42
|
-
isVisible: ({ node }) => node
|
|
86
|
+
isVisible: ({ editor, node }) => canCreateRendition(editor, node, !!ctx.ai?.transcription),
|
|
87
|
+
run: ({ editor, pos }) => {
|
|
88
|
+
createRendition(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "rendition-regenerate",
|
|
93
|
+
label: ctx.t("integrations.rendition.regenerate"),
|
|
94
|
+
icon: "i-lucide-refresh-cw",
|
|
95
|
+
ability: ABILITY.compositeDerive,
|
|
96
|
+
order: 451,
|
|
97
|
+
isVisible: ({ editor, node, pos }) => canRegenerateRendition(editor, node, pos, !!ctx.ai?.transcription),
|
|
43
98
|
run: ({ editor, pos }) => {
|
|
44
|
-
|
|
99
|
+
regenerateRendition(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t);
|
|
45
100
|
}
|
|
46
101
|
}
|
|
47
102
|
];
|
|
@@ -50,9 +105,10 @@ function compositeAiActions(ctx) {
|
|
|
50
105
|
* AI on composites (requires `composites`, `ai`, `media`): the „Baustein füllen (KI)“ block action (on composites of
|
|
51
106
|
* kinds with an `ai` configuration: brief + document → task `fill-block`, the result opens the diff review over the
|
|
52
107
|
* body), the „Zusammenfassung erzeugen“ block action (streams a
|
|
53
|
-
* summary of a composite's body
|
|
54
|
-
*
|
|
55
|
-
*
|
|
108
|
+
* summary of a composite's body into its description), the „Lesefassung erzeugen“ / „Neu erzeugen (ersetzen)“
|
|
109
|
+
* actions of source-holding Bausteine (`ai.extract`: a rendition child with the transcript, full text or description of
|
|
110
|
+
* the source; a recording needs the app's public AI configuration to enable transcription),
|
|
111
|
+
* and the composite-structure form of AI results: with `composite` structure an AI result that
|
|
56
112
|
* has a heading is inserted as a `section` composite fence, otherwise (and in flat structure) the base AI heading
|
|
57
113
|
* is used. It is the preset's single `formatAiResult` contributor. The base AI feature and the composites feature do
|
|
58
114
|
* not know it. Framework-free: notices go through the surface's `ctx.notify`, the model through the app's
|
|
@@ -61,12 +117,14 @@ function compositeAiActions(ctx) {
|
|
|
61
117
|
function compositeAiFeature() {
|
|
62
118
|
return {
|
|
63
119
|
id: "composite-ai",
|
|
120
|
+
dimension: "ai",
|
|
64
121
|
requires: [
|
|
65
122
|
"composites",
|
|
66
123
|
"ai",
|
|
67
124
|
"media"
|
|
68
125
|
],
|
|
69
126
|
blockActions: compositeAiActions,
|
|
127
|
+
extensions: bibliographyFetchExtensions,
|
|
70
128
|
formatAiResult: (editor, markdown, heading) => {
|
|
71
129
|
if (!heading) return markdown;
|
|
72
130
|
const text = withHeading(heading, markdown);
|
|
@@ -75,6 +133,6 @@ function compositeAiFeature() {
|
|
|
75
133
|
};
|
|
76
134
|
}
|
|
77
135
|
//#endregion
|
|
78
|
-
export { COMPOSITE_BODY_START, compositeAiFeature, compositeSourceText, fillComposite,
|
|
136
|
+
export { COMPOSITE_BODY_START, canCreateRendition, canDeriveAfter, canFetchBibliography, canRegenerateRendition, compositeAiFeature, compositeSourceText, createRendition, derivableKindsOf, deriveComposite, doiOf, fetchBibliography, fillComposite, generateCompositeBody, isDerivableSource, regenerateRendition, summarizeComposite };
|
|
79
137
|
|
|
80
138
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/integrations/composite-ai/index.ts"],"sourcesContent":["import type { BlockAction, EditorFeature, FeatureContext } from '../../core'\nimport { ABILITY } from '../../core/schema'\nimport { modelProfiles, withHeading } from '../../features/ai'\nimport { structureOf } from '../../features/composites'\nimport { compositeFence, compositeKind, compositeKindsOf } from '../../features/composites/schema'\nimport { fillComposite } from './composite-fill'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/integrations/composite-ai/index.ts"],"sourcesContent":["import { type AnyExtension, Extension } from '@tiptap/core'\nimport type { BlockAction, EditorFeature, FeatureContext } from '../../core'\nimport { ABILITY } from '../../core/schema'\nimport { modelProfiles, withHeading } from '../../features/ai'\nimport { structureOf } from '../../features/composites'\nimport '../../features/composites/bibliography-command'\nimport { compositeFence, compositeKind, compositeKindsOf } from '../../features/composites/schema'\nimport { fillComposite } from './composite-fill'\nimport { canDeriveAfter, derivableKindsOf, deriveComposite, isDerivableSource } from './derive'\nimport { canFetchBibliography, fetchBibliography } from './bibliography-fetch'\nimport { compositeSourceText, summarizeComposite } from './composite-summary'\nimport { canCreateRendition, canRegenerateRendition, createRendition, regenerateRendition } from './rendition'\n\nexport { type CompositeBodyResult, fillComposite, generateCompositeBody } from './composite-fill'\nexport { COMPOSITE_BODY_START, compositeSourceText, summarizeComposite } from './composite-summary'\nexport { canCreateRendition, canRegenerateRendition, createRendition, regenerateRendition, type RenditionOptions } from './rendition'\nexport { canDeriveAfter, derivableKindsOf, deriveComposite, isDerivableSource } from './derive'\nexport { canFetchBibliography, doiOf, fetchBibliography } from './bibliography-fetch'\n\n/** The editor command `fetchCompositeBibliography` (declared by composites) behind the bibliography editor's „DOI abrufen“ button; absent without the AI capability. */\nfunction bibliographyFetchExtensions(ctx: FeatureContext): AnyExtension[] {\n const ai = ctx.backend.ai\n if (!ai) return []\n return [Extension.create({\n name: 'compositeBibliographyFetch',\n addCommands: () => ({\n fetchCompositeBibliography: (pos: number) => ({ editor }) => {\n void fetchBibliography(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t, ctx.documentId)\n return true\n },\n }),\n })]\n}\n\nfunction compositeAiActions(ctx: FeatureContext): BlockAction[] {\n const ai = ctx.backend.ai\n // Without the AI capability there is nothing to run (`composeEditor` omits the integration in that case).\n if (!ai) return []\n return [\n {\n id: 'composite-fill',\n label: ctx.t('integrations.compositeFill.action'),\n icon: 'i-lucide-wand-sparkles',\n ability: ABILITY.aiGenerate,\n order: 25,\n isVisible: ({ editor, node }) => node.type.name === 'composite' && compositeKind(compositeKindsOf(editor), String(node.attrs.kind)).ai !== undefined,\n run: ({ editor, pos }) => {\n void fillComposite(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t)\n },\n },\n {\n id: 'composite-summarize',\n label: ctx.t('integrations.compositeSummary.action'),\n icon: 'i-lucide-text-quote',\n ability: ABILITY.compositeSummarize,\n order: 30,\n isVisible: ({ node }) => compositeSourceText(node).trim().length > 0,\n run: ({ editor, pos }) => {\n void summarizeComposite(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t)\n },\n },\n {\n id: 'composite-derive',\n label: ctx.t('integrations.compositeDerive.action'),\n icon: 'i-lucide-git-branch',\n ability: ABILITY.compositeDerive,\n order: 452,\n isVisible: ({ editor, node }) => isDerivableSource(editor, node),\n menu: ({ editor, pos }) => derivableKindsOf(editor).map(kind => ({\n label: kind.label,\n icon: kind.icon,\n disabled: !canDeriveAfter(editor, pos, kind.id),\n onSelect: () => {\n void deriveComposite(editor, pos, kind.id, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t)\n },\n })),\n },\n {\n id: 'bibliography-fetch',\n label: ctx.t('integrations.bibliographyFetch.action'),\n icon: 'i-lucide-book-marked',\n ability: ABILITY.compositeDerive,\n order: 453,\n isVisible: ({ editor, node }) => canFetchBibliography(editor, node),\n run: ({ editor, pos }) => {\n void fetchBibliography(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t, ctx.documentId)\n },\n },\n {\n id: 'rendition-create',\n label: ctx.t('integrations.rendition.action'),\n icon: 'i-lucide-captions',\n ability: ABILITY.compositeDerive,\n order: 450,\n isVisible: ({ editor, node }) => canCreateRendition(editor, node, !!ctx.ai?.transcription),\n run: ({ editor, pos }) => {\n void createRendition(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t)\n },\n },\n {\n id: 'rendition-regenerate',\n label: ctx.t('integrations.rendition.regenerate'),\n icon: 'i-lucide-refresh-cw',\n ability: ABILITY.compositeDerive,\n order: 451,\n isVisible: ({ editor, node, pos }) => canRegenerateRendition(editor, node, pos, !!ctx.ai?.transcription),\n run: ({ editor, pos }) => {\n regenerateRendition(editor, pos, ai, modelProfiles(ctx.app).modelRef, ctx.notify, ctx.t)\n },\n },\n ]\n}\n\n/**\n * AI on composites (requires `composites`, `ai`, `media`): the „Baustein füllen (KI)“ block action (on composites of\n * kinds with an `ai` configuration: brief + document → task `fill-block`, the result opens the diff review over the\n * body), the „Zusammenfassung erzeugen“ block action (streams a\n * summary of a composite's body into its description), the „Lesefassung erzeugen“ / „Neu erzeugen (ersetzen)“\n * actions of source-holding Bausteine (`ai.extract`: a rendition child with the transcript, full text or description of\n * the source; a recording needs the app's public AI configuration to enable transcription),\n * and the composite-structure form of AI results: with `composite` structure an AI result that\n * has a heading is inserted as a `section` composite fence, otherwise (and in flat structure) the base AI heading\n * is used. It is the preset's single `formatAiResult` contributor. The base AI feature and the composites feature do\n * not know it. Framework-free: notices go through the surface's `ctx.notify`, the model through the app's\n * `modelProfiles(ctx.app)`.\n */\nexport function compositeAiFeature(): EditorFeature<never> {\n return {\n id: 'composite-ai',\n dimension: 'ai',\n requires: ['composites', 'ai', 'media'],\n blockActions: compositeAiActions,\n extensions: bibliographyFetchExtensions,\n formatAiResult: (editor, markdown, heading) => {\n if (!heading) return markdown\n const text = withHeading(heading, markdown)\n return structureOf(editor) === 'composite' ? compositeFence('section', {}, text) : text\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAS,4BAA4B,KAAqC;CACxE,MAAM,KAAK,IAAI,QAAQ;CACvB,IAAI,CAAC,IAAI,OAAO,CAAC;CACjB,OAAO,CAAC,UAAU,OAAO;EACvB,MAAM;EACN,oBAAoB,EAClB,6BAA6B,SAAiB,EAAE,aAAa;GAC3D,kBAAuB,QAAQ,KAAK,IAAI,cAAc,IAAI,GAAG,CAAC,CAAC,UAAU,IAAI,QAAQ,IAAI,GAAG,IAAI,UAAU;GAC1G,OAAO;EACT,EACF;CACF,CAAC,CAAC;AACJ;AAEA,SAAS,mBAAmB,KAAoC;CAC9D,MAAM,KAAK,IAAI,QAAQ;CAEvB,IAAI,CAAC,IAAI,OAAO,CAAC;CACjB,OAAO;EACL;GACE,IAAI;GACJ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from "../../core/notify.js";
|
|
4
|
+
import { ModelRef } from "../../core/backend-types.js";
|
|
5
|
+
import "../../features/ai/index.js";
|
|
6
|
+
import { Editor } from "@tiptap/core";
|
|
7
|
+
import { Node as Node$1 } from "@tiptap/pm/model";
|
|
8
|
+
//#region src/integrations/composite-ai/rendition.d.ts
|
|
9
|
+
export interface RenditionOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Replace the rendition at this position (a child of the source-holding Baustein) in place instead of adding a new one
|
|
12
|
+
* after the source: its chrome (title, description, tags) and block id stay, body and derivation are new.
|
|
13
|
+
*/
|
|
14
|
+
replace?: {
|
|
15
|
+
pos: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* „Lesefassung erzeugen“: extracts the readable content of the source of the Baustein at `pos` (`ai.extract`, method
|
|
20
|
+
* `auto`: transcript with timestamps for audio/video, full text or OCR for a PDF, a description for an image) and adds
|
|
21
|
+
* it as a `rendition` Baustein right after the source block, carrying `meta.derivation` (asset, method, model, hashes,
|
|
22
|
+
* the stored raw output). Bibliographic data the server found fills an empty `meta.bib` of the Baustein, and the work's
|
|
23
|
+
* title an empty Baustein title. With `options.replace` the existing rendition is replaced in place (same block id).
|
|
24
|
+
* The Baustein is anchored through its description when the request starts and found again after it ends, so edits
|
|
25
|
+
* while it runs do not misplace the result. Notices go through `notify`, in the language of `t`; the progress notice
|
|
26
|
+
* stays until the request ends.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createRendition(editor: Editor, pos: number, ai: NonNullable<EditorBackend['ai']>, modelRef: (slot: 'generate') => ModelRef, notify: Notifier, t: Translate, options?: RenditionOptions): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Whether „Lesefassung erzeugen“ applies to `node`: a Baustein of a source-holding kind whose source block was
|
|
31
|
+
* found. A recording needs speech-to-text (`transcription`: the app's public configuration enables it); everything else
|
|
32
|
+
* is extracted by the server.
|
|
33
|
+
*/
|
|
34
|
+
export declare function canCreateRendition(editor: Editor, node: Node$1, transcription: boolean): boolean;
|
|
35
|
+
/** Whether „Neu erzeugen (ersetzen)“ applies to the Baustein `node` at `pos`: an asset-derived rendition inside a Baustein that still has a source. */
|
|
36
|
+
export declare function canRegenerateRendition(editor: Editor, node: Node$1, pos: number, transcription: boolean): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* „Neu erzeugen (ersetzen)“: makes the rendition at `pos` again from the source of its Baustein and replaces it in place
|
|
39
|
+
* (`createRendition` with `replace`; the block id stays, so references keep resolving). A rendition whose body was
|
|
40
|
+
* edited since it was made is not replaced silently: a warning notice offers „Trotzdem ersetzen“, dismissing the notice
|
|
41
|
+
* cancels. The rendition is found again by its id when the button is pressed.
|
|
42
|
+
*/
|
|
43
|
+
export declare function regenerateRendition(editor: Editor, pos: number, ai: NonNullable<EditorBackend['ai']>, modelRef: (slot: 'generate') => ModelRef, notify: Notifier, t: Translate): void;
|
|
44
|
+
//#endregion
|
|
45
|
+
//# sourceMappingURL=rendition.d.ts.map
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { parseBlocks, structureBlocks } from "../../core/pipeline.js";
|
|
2
|
+
import { blockIdOf, findBlockById, newBlockId } from "../../core/schema/block-ids.js";
|
|
3
|
+
import { captureRange, releaseRanges, resolveRange } from "../../core/doc-anchors.js";
|
|
4
|
+
import { fetchErrorMessage } from "../../core/fetch-error.js";
|
|
5
|
+
import { sha256Hex } from "../../core/hash.js";
|
|
6
|
+
import { compositeKind, kindAccepts } from "../../features/composites/kinds.js";
|
|
7
|
+
import { DERIVATION_KEY } from "../../features/composites/meta-keys.js";
|
|
8
|
+
import { bodyMarkdown, derivationOf, derivationState, sourceOf } from "../../features/composites/derivation.js";
|
|
9
|
+
import { compositeJSON, compositeKindsOf } from "../../features/composites/nodes.js";
|
|
10
|
+
import { bibOf } from "../../features/composites/bibliography.js";
|
|
11
|
+
import { isRateLimited, notifyAiRateLimited } from "../../features/ai/rate-limit.js";
|
|
12
|
+
import { Fragment } from "@tiptap/pm/model";
|
|
13
|
+
//#region src/integrations/composite-ai/rendition.ts
|
|
14
|
+
/** Methods with their own title of a fresh rendition (`integrations.rendition.title.<method>`). */
|
|
15
|
+
const TITLED_METHODS = [
|
|
16
|
+
"transcription",
|
|
17
|
+
"pdf-text",
|
|
18
|
+
"ocr",
|
|
19
|
+
"description"
|
|
20
|
+
];
|
|
21
|
+
/** What the server's `warnings` codes say; an unknown code is shown as it is. */
|
|
22
|
+
const WARNING_KEYS = {
|
|
23
|
+
"ocr-unavailable": "integrations.rendition.warning.ocr-unavailable",
|
|
24
|
+
"crossref-unavailable": "integrations.rendition.warning.crossref-unavailable",
|
|
25
|
+
"pages-truncated": "integrations.rendition.warning.pages-truncated",
|
|
26
|
+
"ocr-truncated": "integrations.rendition.warning.ocr-truncated",
|
|
27
|
+
"bibliography-failed": "integrations.rendition.warning.bibliography-failed"
|
|
28
|
+
};
|
|
29
|
+
/** The `<!-- page N -->` line the server puts at the start of every PDF page after the first (`joinPages`). */
|
|
30
|
+
const PAGE_MARKER = /^<!-- page (\d+) -->[ \t]*$/gm;
|
|
31
|
+
/**
|
|
32
|
+
* `markdown` with every page marker line replaced by an emphasised page label paragraph (`*S. 2*`): parsed as it is, a
|
|
33
|
+
* marker is an HTML comment and would leave an empty paragraph without the page. The stored raw output keeps the markers.
|
|
34
|
+
*/
|
|
35
|
+
function withPageLabels(markdown, t) {
|
|
36
|
+
return markdown.replace(PAGE_MARKER, (_marker, page) => `*${t("integrations.rendition.page", { n: page })}*`);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The body blocks of a rendition: one `transcriptSegment` per timed segment (speaker empty, `start`/`end` in seconds)
|
|
40
|
+
* when the editor has the transcript feature, else the Markdown parsed and brought into the preferred structure
|
|
41
|
+
* (chapters become nested `section` Bausteine in composite structure; PDF page breaks become page label paragraphs).
|
|
42
|
+
*/
|
|
43
|
+
function renditionBody(editor, response, t) {
|
|
44
|
+
if (editor.schema.nodes.transcriptSegment && response.segments?.length) {
|
|
45
|
+
const segments = response.segments.filter((segment) => segment.text.trim()).map((segment) => ({
|
|
46
|
+
type: "transcriptSegment",
|
|
47
|
+
attrs: {
|
|
48
|
+
speaker: "",
|
|
49
|
+
start: segment.start,
|
|
50
|
+
end: segment.end
|
|
51
|
+
},
|
|
52
|
+
content: [{
|
|
53
|
+
type: "text",
|
|
54
|
+
text: segment.text.trim()
|
|
55
|
+
}]
|
|
56
|
+
}));
|
|
57
|
+
if (segments.length) return segments;
|
|
58
|
+
}
|
|
59
|
+
return response.markdown.trim() ? structureBlocks(editor, parseBlocks(editor, withPageLabels(response.markdown, t)).blocks) : [];
|
|
60
|
+
}
|
|
61
|
+
/** `node` with `derivation` in its meta, `outputHash` being the hash of the Markdown of its body (what `derivationState` compares later). */
|
|
62
|
+
function sealed(editor, node, derivation) {
|
|
63
|
+
const outputHash = sha256Hex(bodyMarkdown(editor, node));
|
|
64
|
+
return node.type.create({
|
|
65
|
+
...node.attrs,
|
|
66
|
+
meta: {
|
|
67
|
+
...node.attrs.meta,
|
|
68
|
+
[DERIVATION_KEY]: {
|
|
69
|
+
...derivation,
|
|
70
|
+
outputHash
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, node.content, node.marks);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* „Lesefassung erzeugen“: extracts the readable content of the source of the Baustein at `pos` (`ai.extract`, method
|
|
77
|
+
* `auto`: transcript with timestamps for audio/video, full text or OCR for a PDF, a description for an image) and adds
|
|
78
|
+
* it as a `rendition` Baustein right after the source block, carrying `meta.derivation` (asset, method, model, hashes,
|
|
79
|
+
* the stored raw output). Bibliographic data the server found fills an empty `meta.bib` of the Baustein, and the work's
|
|
80
|
+
* title an empty Baustein title. With `options.replace` the existing rendition is replaced in place (same block id).
|
|
81
|
+
* The Baustein is anchored through its description when the request starts and found again after it ends, so edits
|
|
82
|
+
* while it runs do not misplace the result. Notices go through `notify`, in the language of `t`; the progress notice
|
|
83
|
+
* stays until the request ends.
|
|
84
|
+
*/
|
|
85
|
+
async function createRendition(editor, pos, ai, modelRef, notify, t, options = {}) {
|
|
86
|
+
const kinds = compositeKindsOf(editor);
|
|
87
|
+
const composite = editor.state.doc.nodeAt(pos);
|
|
88
|
+
const source = composite && sourceOf(composite, kinds);
|
|
89
|
+
if (composite?.type.name !== "composite" || !source) return;
|
|
90
|
+
const asset = source.asset;
|
|
91
|
+
if (!asset) {
|
|
92
|
+
notify({
|
|
93
|
+
title: t("integrations.rendition.noSource"),
|
|
94
|
+
kind: "error"
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!kindAccepts(kinds, String(composite.attrs.kind), "rendition")) {
|
|
99
|
+
notify({
|
|
100
|
+
title: t("integrations.rendition.notAccepted"),
|
|
101
|
+
kind: "error"
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
let replaceId = null;
|
|
106
|
+
if (options.replace) {
|
|
107
|
+
const target = editor.state.doc.nodeAt(options.replace.pos);
|
|
108
|
+
replaceId = target && options.replace.pos > pos && options.replace.pos < pos + composite.nodeSize ? blockIdOf(target) : null;
|
|
109
|
+
if (target?.type.name !== "composite" || !replaceId) return;
|
|
110
|
+
}
|
|
111
|
+
const descriptionPos = pos + 1 + composite.child(0).nodeSize;
|
|
112
|
+
const anchor = captureRange(editor, {
|
|
113
|
+
from: descriptionPos + 1,
|
|
114
|
+
to: descriptionPos + 1 + composite.child(1).content.size
|
|
115
|
+
});
|
|
116
|
+
const toastId = `rendition-${blockIdOf(composite) ?? asset.name}`;
|
|
117
|
+
const wantsBibliography = compositeKind(kinds, String(composite.attrs.kind)).fields.some((field) => field.type === "bibliography");
|
|
118
|
+
const model = modelRef("generate");
|
|
119
|
+
const controller = new AbortController();
|
|
120
|
+
const abort = () => controller.abort();
|
|
121
|
+
editor.on("destroy", abort);
|
|
122
|
+
notify({
|
|
123
|
+
id: toastId,
|
|
124
|
+
title: t("integrations.rendition.running"),
|
|
125
|
+
kind: "info",
|
|
126
|
+
icon: "i-lucide-loader-circle",
|
|
127
|
+
duration: 0
|
|
128
|
+
});
|
|
129
|
+
try {
|
|
130
|
+
const response = await ai.extract({
|
|
131
|
+
documentId: asset.documentId,
|
|
132
|
+
name: asset.name,
|
|
133
|
+
method: "auto",
|
|
134
|
+
model,
|
|
135
|
+
bibliography: wantsBibliography
|
|
136
|
+
}, controller.signal);
|
|
137
|
+
if (editor.isDestroyed) return;
|
|
138
|
+
const body = renditionBody(editor, response, t);
|
|
139
|
+
if (!body.length) {
|
|
140
|
+
notify({
|
|
141
|
+
title: t("integrations.rendition.empty.title"),
|
|
142
|
+
description: t("integrations.rendition.empty.description"),
|
|
143
|
+
kind: "error"
|
|
144
|
+
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const range = resolveRange(editor.state, anchor);
|
|
148
|
+
const $from = range && editor.state.doc.resolve(range.from);
|
|
149
|
+
const parentPos = $from && $from.parent.type.name === "compositeDescription" ? $from.before($from.depth - 1) : null;
|
|
150
|
+
const parent = parentPos === null ? null : editor.state.doc.nodeAt(parentPos);
|
|
151
|
+
const currentSource = parent && sourceOf(parent, kinds);
|
|
152
|
+
const replaced = replaceId ? findBlockById(editor.state.doc, replaceId) : null;
|
|
153
|
+
if (parentPos === null || !parent || !currentSource || replaceId !== null && (!replaced || replaced.pos <= parentPos || replaced.pos >= parentPos + parent.nodeSize)) {
|
|
154
|
+
notify({
|
|
155
|
+
title: t("integrations.rendition.gone.title"),
|
|
156
|
+
description: t("integrations.rendition.gone.description"),
|
|
157
|
+
kind: "error"
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const usedModel = response.method === "transcription" ? response.model : response.method === "ocr" || response.method === "description" ? "preset" in model ? model.preset : model.model : void 0;
|
|
162
|
+
const derivation = {
|
|
163
|
+
from: { asset: asset.name },
|
|
164
|
+
method: response.method,
|
|
165
|
+
...usedModel ? { model: usedModel } : {},
|
|
166
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
167
|
+
inputHash: response.inputHash,
|
|
168
|
+
outputHash: "",
|
|
169
|
+
...response.output ? { output: response.output } : {}
|
|
170
|
+
};
|
|
171
|
+
const { schema } = editor;
|
|
172
|
+
const bodyNodes = body.map((block) => schema.nodeFromJSON(block));
|
|
173
|
+
const id = replaceId ?? newBlockId();
|
|
174
|
+
let node;
|
|
175
|
+
if (replaced) {
|
|
176
|
+
const chrome = Array.from({ length: 3 }, (_, index) => replaced.node.child(index));
|
|
177
|
+
node = sealed(editor, replaced.node.type.create(replaced.node.attrs, Fragment.from([...chrome, ...bodyNodes])), derivation);
|
|
178
|
+
} else {
|
|
179
|
+
const titleKey = TITLED_METHODS.includes(response.method) ? `integrations.rendition.title.${response.method}` : null;
|
|
180
|
+
const json = compositeJSON("rendition", body);
|
|
181
|
+
const [title, ...rest] = json.content;
|
|
182
|
+
const text = titleKey ? t(titleKey) : compositeKind(kinds, "rendition").label;
|
|
183
|
+
node = sealed(editor, schema.nodeFromJSON({
|
|
184
|
+
...json,
|
|
185
|
+
attrs: {
|
|
186
|
+
...json.attrs,
|
|
187
|
+
id
|
|
188
|
+
},
|
|
189
|
+
content: [{
|
|
190
|
+
...title,
|
|
191
|
+
content: [{
|
|
192
|
+
type: "text",
|
|
193
|
+
text
|
|
194
|
+
}]
|
|
195
|
+
}, ...rest]
|
|
196
|
+
}), derivation);
|
|
197
|
+
}
|
|
198
|
+
const tr = editor.state.tr;
|
|
199
|
+
if (replaced) tr.replaceWith(replaced.pos, replaced.pos + replaced.node.nodeSize, node);
|
|
200
|
+
else {
|
|
201
|
+
let insertPos = parentPos + 1;
|
|
202
|
+
for (let index = 0; index <= currentSource.index; index++) insertPos += parent.child(index).nodeSize;
|
|
203
|
+
if (!parent.canReplace(currentSource.index + 1, currentSource.index + 1, Fragment.from(node))) {
|
|
204
|
+
notify({
|
|
205
|
+
title: t("integrations.rendition.notAccepted"),
|
|
206
|
+
kind: "error"
|
|
207
|
+
});
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
tr.insert(insertPos, node);
|
|
211
|
+
}
|
|
212
|
+
const { bib } = response;
|
|
213
|
+
const workTitle = bib?.title?.trim();
|
|
214
|
+
if (workTitle && !parent.child(0).textContent.trim()) tr.insert(parentPos + 2, schema.text(workTitle));
|
|
215
|
+
if (bib && bibOf(parent) === null) {
|
|
216
|
+
const csl = { ...bib };
|
|
217
|
+
delete csl.title;
|
|
218
|
+
tr.setNodeMarkup(parentPos, void 0, {
|
|
219
|
+
...parent.attrs,
|
|
220
|
+
meta: {
|
|
221
|
+
...parent.attrs.meta,
|
|
222
|
+
bib: csl
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
editor.view.dispatch(tr);
|
|
227
|
+
editor.commands.revealBlock(id);
|
|
228
|
+
notify({
|
|
229
|
+
title: t("integrations.rendition.done"),
|
|
230
|
+
kind: "success",
|
|
231
|
+
icon: "i-lucide-captions"
|
|
232
|
+
});
|
|
233
|
+
if (response.warnings.length) notify({
|
|
234
|
+
title: t("integrations.rendition.warnings.title"),
|
|
235
|
+
description: response.warnings.map((code) => WARNING_KEYS[code] ? t(WARNING_KEYS[code]) : code).join(" "),
|
|
236
|
+
kind: "info"
|
|
237
|
+
});
|
|
238
|
+
} catch (err) {
|
|
239
|
+
if (controller.signal.aborted || editor.isDestroyed) return;
|
|
240
|
+
if (isRateLimited(err)) notifyAiRateLimited(notify, t);
|
|
241
|
+
else notify({
|
|
242
|
+
title: t("integrations.rendition.failed"),
|
|
243
|
+
description: fetchErrorMessage(err),
|
|
244
|
+
kind: "error"
|
|
245
|
+
});
|
|
246
|
+
} finally {
|
|
247
|
+
notify.dismiss?.(toastId);
|
|
248
|
+
editor.off("destroy", abort);
|
|
249
|
+
releaseRanges(editor, [anchor]);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Whether „Lesefassung erzeugen“ applies to `node`: a Baustein of a source-holding kind whose source block was
|
|
254
|
+
* found. A recording needs speech-to-text (`transcription`: the app's public configuration enables it); everything else
|
|
255
|
+
* is extracted by the server.
|
|
256
|
+
*/
|
|
257
|
+
function canCreateRendition(editor, node, transcription) {
|
|
258
|
+
const source = sourceOf(node, compositeKindsOf(editor));
|
|
259
|
+
if (!source) return false;
|
|
260
|
+
return transcription || source.node.type.name !== "audio" && source.node.type.name !== "video";
|
|
261
|
+
}
|
|
262
|
+
/** The source-holding Baustein around the asset-derived rendition at `pos`; null for anything else. */
|
|
263
|
+
function renditionParentOf(editor, pos) {
|
|
264
|
+
const node = editor.state.doc.nodeAt(pos);
|
|
265
|
+
const derivation = node && derivationOf(node);
|
|
266
|
+
if (!derivation || !("asset" in derivation.from)) return null;
|
|
267
|
+
const $pos = editor.state.doc.resolve(pos);
|
|
268
|
+
if ($pos.depth === 0 || $pos.parent.type.name !== "composite" || !sourceOf($pos.parent, compositeKindsOf(editor))) return null;
|
|
269
|
+
return {
|
|
270
|
+
node: $pos.parent,
|
|
271
|
+
pos: $pos.before()
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/** Whether „Neu erzeugen (ersetzen)“ applies to the Baustein `node` at `pos`: an asset-derived rendition inside a Baustein that still has a source. */
|
|
275
|
+
function canRegenerateRendition(editor, node, pos, transcription) {
|
|
276
|
+
const parent = node.type.name === "composite" ? renditionParentOf(editor, pos) : null;
|
|
277
|
+
return parent !== null && canCreateRendition(editor, parent.node, transcription);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* „Neu erzeugen (ersetzen)“: makes the rendition at `pos` again from the source of its Baustein and replaces it in place
|
|
281
|
+
* (`createRendition` with `replace`; the block id stays, so references keep resolving). A rendition whose body was
|
|
282
|
+
* edited since it was made is not replaced silently: a warning notice offers „Trotzdem ersetzen“, dismissing the notice
|
|
283
|
+
* cancels. The rendition is found again by its id when the button is pressed.
|
|
284
|
+
*/
|
|
285
|
+
function regenerateRendition(editor, pos, ai, modelRef, notify, t) {
|
|
286
|
+
const node = editor.state.doc.nodeAt(pos);
|
|
287
|
+
const id = node && blockIdOf(node);
|
|
288
|
+
const parent = renditionParentOf(editor, pos);
|
|
289
|
+
if (!node || !id || !parent) return;
|
|
290
|
+
const replace = () => {
|
|
291
|
+
const found = findBlockById(editor.state.doc, id);
|
|
292
|
+
const current = found && renditionParentOf(editor, found.pos);
|
|
293
|
+
if (found && current) createRendition(editor, current.pos, ai, modelRef, notify, t, { replace: { pos: found.pos } });
|
|
294
|
+
};
|
|
295
|
+
const kinds = compositeKindsOf(editor);
|
|
296
|
+
if (derivationState(parent.node, node, () => sha256Hex(bodyMarkdown(editor, node)), kinds).edited !== true) {
|
|
297
|
+
replace();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
notify({
|
|
301
|
+
id: `rendition-edited-${id}`,
|
|
302
|
+
title: t("integrations.rendition.editedWarning.title"),
|
|
303
|
+
description: t("integrations.rendition.editedWarning.description"),
|
|
304
|
+
kind: "warning",
|
|
305
|
+
action: {
|
|
306
|
+
label: t("integrations.rendition.editedWarning.confirm"),
|
|
307
|
+
onClick: replace
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
export { canCreateRendition, canRegenerateRendition, createRendition, regenerateRendition };
|
|
313
|
+
|
|
314
|
+
//# sourceMappingURL=rendition.js.map
|