@supernova-studio/client 1.96.5 → 1.96.7
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/dist/index.d.mts +101428 -143199
- package/dist/index.d.ts +101428 -143199
- package/dist/index.js +489 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5607 -5217
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -9
- package/src/api/client.ts +62 -0
- package/src/api/conversion/analytics/index.ts +3 -0
- package/src/api/conversion/analytics/page-visits-to-comparison-dto.ts +65 -0
- package/src/api/conversion/analytics/page-visits-to-dto.ts +68 -0
- package/src/api/conversion/analytics/page-visits-to-heatmap-dto.ts +49 -0
- package/src/api/conversion/documentation/documentation-group-v1-to-dto.ts +114 -0
- package/src/api/conversion/documentation/documentation-group-v2-to-dto.ts +91 -0
- package/src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts +52 -0
- package/src/api/conversion/documentation/documentation-item-configuration-v2-to-dto.ts +34 -0
- package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +134 -0
- package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +69 -0
- package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +84 -0
- package/src/api/conversion/documentation/documentation-settings-to-dto.ts +14 -0
- package/src/api/conversion/documentation/index.ts +8 -0
- package/src/api/conversion/export/index.ts +1 -0
- package/src/api/conversion/export/pipeline.ts +27 -0
- package/src/api/conversion/index.ts +4 -0
- package/src/api/conversion/integrations/git.ts +37 -0
- package/src/api/conversion/integrations/index.ts +2 -0
- package/src/api/conversion/integrations/integration.ts +37 -0
- package/src/api/dto/access-tokens/access-token.ts +45 -0
- package/src/api/dto/access-tokens/index.ts +1 -0
- package/src/api/dto/aux/color.ts +7 -0
- package/src/api/dto/aux/index.ts +4 -0
- package/src/api/dto/aux/meta.ts +8 -0
- package/src/api/dto/aux/object-metadata.ts +29 -0
- package/src/api/dto/aux/pagination.ts +8 -0
- package/src/api/dto/bff/app-bootstrap-data.ts +20 -0
- package/src/api/dto/bff/index.ts +1 -0
- package/src/api/dto/collections/index.ts +1 -0
- package/src/api/dto/collections/token-collection.ts +32 -0
- package/src/api/dto/design-systems/brand.ts +44 -0
- package/src/api/dto/design-systems/code-component-usage.ts +52 -0
- package/src/api/dto/design-systems/code-component.ts +101 -0
- package/src/api/dto/design-systems/code-history.ts +43 -0
- package/src/api/dto/design-systems/code-scan.ts +29 -0
- package/src/api/dto/design-systems/code-snapshots.ts +46 -0
- package/src/api/dto/design-systems/component.ts +40 -0
- package/src/api/dto/design-systems/contact.ts +11 -0
- package/src/api/dto/design-systems/data-source.ts +216 -0
- package/src/api/dto/design-systems/design-system.ts +75 -0
- package/src/api/dto/design-systems/documentation-search.ts +31 -0
- package/src/api/dto/design-systems/elements-diff.ts +14 -0
- package/src/api/dto/design-systems/figma-variables.ts +122 -0
- package/src/api/dto/design-systems/file.ts +71 -0
- package/src/api/dto/design-systems/import-job.ts +62 -0
- package/src/api/dto/design-systems/index.ts +24 -0
- package/src/api/dto/design-systems/members.ts +52 -0
- package/src/api/dto/design-systems/redirects.ts +33 -0
- package/src/api/dto/design-systems/role.ts +11 -0
- package/src/api/dto/design-systems/stats.ts +20 -0
- package/src/api/dto/design-systems/storybook.ts +45 -0
- package/src/api/dto/design-systems/user-design-systems.ts +10 -0
- package/src/api/dto/design-systems/version-room.ts +12 -0
- package/src/api/dto/design-systems/version.ts +56 -0
- package/src/api/dto/design-systems/view.ts +45 -0
- package/src/api/dto/design-tokens/design-token.ts +78 -0
- package/src/api/dto/design-tokens/index.ts +1 -0
- package/src/api/dto/documentation/analytics-v2.ts +80 -0
- package/src/api/dto/documentation/analytics.ts +32 -0
- package/src/api/dto/documentation/anchor.ts +15 -0
- package/src/api/dto/documentation/approvals.ts +21 -0
- package/src/api/dto/documentation/block-definition.ts +28 -0
- package/src/api/dto/documentation/block.ts +6 -0
- package/src/api/dto/documentation/documentation-page-snapshot.ts +18 -0
- package/src/api/dto/documentation/documentation.ts +34 -0
- package/src/api/dto/documentation/index.ts +11 -0
- package/src/api/dto/documentation/link-preview.ts +23 -0
- package/src/api/dto/documentation/publish.ts +23 -0
- package/src/api/dto/documentation/room.ts +12 -0
- package/src/api/dto/elements/components/figma-component-group.ts +19 -0
- package/src/api/dto/elements/components/figma-component.ts +56 -0
- package/src/api/dto/elements/components/index.ts +2 -0
- package/src/api/dto/elements/documentation/configuration.ts +20 -0
- package/src/api/dto/elements/documentation/draft-state.ts +37 -0
- package/src/api/dto/elements/documentation/group-action.ts +108 -0
- package/src/api/dto/elements/documentation/group-v1.ts +35 -0
- package/src/api/dto/elements/documentation/group-v2.ts +117 -0
- package/src/api/dto/elements/documentation/hierarchy.ts +25 -0
- package/src/api/dto/elements/documentation/index.ts +16 -0
- package/src/api/dto/elements/documentation/item-configuration-v1.ts +24 -0
- package/src/api/dto/elements/documentation/item-configuration-v2.ts +14 -0
- package/src/api/dto/elements/documentation/metadata.ts +8 -0
- package/src/api/dto/elements/documentation/page-actions-v2.ts +138 -0
- package/src/api/dto/elements/documentation/page-content.ts +15 -0
- package/src/api/dto/elements/documentation/page-dependencies.ts +30 -0
- package/src/api/dto/elements/documentation/page-v1.ts +21 -0
- package/src/api/dto/elements/documentation/page-v2.ts +132 -0
- package/src/api/dto/elements/documentation/settings.ts +9 -0
- package/src/api/dto/elements/documentation/structure.ts +37 -0
- package/src/api/dto/elements/elements-action-v2.ts +125 -0
- package/src/api/dto/elements/figma-nodes/figma-node-structure.ts +27 -0
- package/src/api/dto/elements/figma-nodes/figma-node-v1.ts +32 -0
- package/src/api/dto/elements/figma-nodes/figma-node-v2.ts +32 -0
- package/src/api/dto/elements/figma-nodes/figma-node.ts +103 -0
- package/src/api/dto/elements/figma-nodes/index.ts +5 -0
- package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +25 -0
- package/src/api/dto/elements/frame-node-structures/frame-node-structure.ts +17 -0
- package/src/api/dto/elements/frame-node-structures/index.ts +1 -0
- package/src/api/dto/elements/get-elements-v2.ts +27 -0
- package/src/api/dto/elements/index.ts +7 -0
- package/src/api/dto/elements/properties/index.ts +2 -0
- package/src/api/dto/elements/properties/property-definitions.ts +75 -0
- package/src/api/dto/elements/properties/property-values.ts +50 -0
- package/src/api/dto/events/forge-project.ts +51 -0
- package/src/api/dto/events/index.ts +2 -0
- package/src/api/dto/events/workspace.ts +81 -0
- package/src/api/dto/export/exporter-property.ts +114 -0
- package/src/api/dto/export/exporter.ts +115 -0
- package/src/api/dto/export/filter.ts +20 -0
- package/src/api/dto/export/index.ts +5 -0
- package/src/api/dto/export/job.ts +114 -0
- package/src/api/dto/export/pipeline.ts +60 -0
- package/src/api/dto/figma-components/assets/download.ts +30 -0
- package/src/api/dto/figma-components/assets/index.ts +1 -0
- package/src/api/dto/figma-components/index.ts +1 -0
- package/src/api/dto/figma-exporter/figma-node.ts +11 -0
- package/src/api/dto/figma-exporter/index.ts +1 -0
- package/src/api/dto/files/files.ts +94 -0
- package/src/api/dto/files/index.ts +1 -0
- package/src/api/dto/forge/agent.ts +38 -0
- package/src/api/dto/forge/artifact.ts +94 -0
- package/src/api/dto/forge/feature-messages.ts +551 -0
- package/src/api/dto/forge/feature-room.ts +12 -0
- package/src/api/dto/forge/figma-node.ts +117 -0
- package/src/api/dto/forge/index.ts +28 -0
- package/src/api/dto/forge/iteration-message-old.ts +43 -0
- package/src/api/dto/forge/knowledge-item.ts +67 -0
- package/src/api/dto/forge/memory.ts +67 -0
- package/src/api/dto/forge/participant.ts +44 -0
- package/src/api/dto/forge/project-action.ts +123 -0
- package/src/api/dto/forge/project-artifact-room.ts +12 -0
- package/src/api/dto/forge/project-artifact.ts +85 -0
- package/src/api/dto/forge/project-context-feedback.ts +141 -0
- package/src/api/dto/forge/project-context-override.ts +41 -0
- package/src/api/dto/forge/project-context-scope.ts +23 -0
- package/src/api/dto/forge/project-context-v2.ts +228 -0
- package/src/api/dto/forge/project-context.ts +72 -0
- package/src/api/dto/forge/project-feature.ts +86 -0
- package/src/api/dto/forge/project-figma-node.ts +9 -0
- package/src/api/dto/forge/project-file.ts +48 -0
- package/src/api/dto/forge/project-invitation.ts +46 -0
- package/src/api/dto/forge/project-iteration-old.ts +54 -0
- package/src/api/dto/forge/project-member.ts +67 -0
- package/src/api/dto/forge/project-room.ts +12 -0
- package/src/api/dto/forge/project-section.ts +37 -0
- package/src/api/dto/forge/project.ts +105 -0
- package/src/api/dto/forge/relation.ts +34 -0
- package/src/api/dto/forge/threads.ts +153 -0
- package/src/api/dto/index.ts +25 -0
- package/src/api/dto/liveblocks/auth-response.ts +7 -0
- package/src/api/dto/liveblocks/index.ts +1 -0
- package/src/api/dto/mcp/index.ts +1 -0
- package/src/api/dto/mcp/stream.ts +17 -0
- package/src/api/dto/notifications/index.ts +2 -0
- package/src/api/dto/notifications/notifications.ts +65 -0
- package/src/api/dto/notifications/settings.ts +10 -0
- package/src/api/dto/portal/index.ts +1 -0
- package/src/api/dto/portal/portal-settings.ts +45 -0
- package/src/api/dto/sandboxes/index.ts +1 -0
- package/src/api/dto/sandboxes/template.ts +143 -0
- package/src/api/dto/storybook-sites/index.ts +1 -0
- package/src/api/dto/storybook-sites/storybook-sites.ts +60 -0
- package/src/api/dto/themes/index.ts +2 -0
- package/src/api/dto/themes/override.ts +27 -0
- package/src/api/dto/themes/theme.ts +53 -0
- package/src/api/dto/threads/index.ts +1 -0
- package/src/api/dto/threads/threads.ts +280 -0
- package/src/api/dto/trail-events/index.ts +1 -0
- package/src/api/dto/trail-events/trail-events.ts +172 -0
- package/src/api/dto/users/authenticated-user.ts +92 -0
- package/src/api/dto/users/index.ts +2 -0
- package/src/api/dto/users/user.ts +27 -0
- package/src/api/dto/workspaces/billing.ts +156 -0
- package/src/api/dto/workspaces/enums.ts +13 -0
- package/src/api/dto/workspaces/git.ts +32 -0
- package/src/api/dto/workspaces/index.ts +15 -0
- package/src/api/dto/workspaces/integrations.ts +34 -0
- package/src/api/dto/workspaces/invitations.ts +47 -0
- package/src/api/dto/workspaces/ip-whitelist.ts +33 -0
- package/src/api/dto/workspaces/knowledge-items-search.ts +37 -0
- package/src/api/dto/workspaces/login-screen.ts +42 -0
- package/src/api/dto/workspaces/membership.ts +55 -0
- package/src/api/dto/workspaces/npm-registry.ts +62 -0
- package/src/api/dto/workspaces/products.ts +45 -0
- package/src/api/dto/workspaces/subscription.ts +170 -0
- package/src/api/dto/workspaces/transfer-ownership.ts +7 -0
- package/src/api/dto/workspaces/untyped-data.ts +35 -0
- package/src/api/dto/workspaces/workspace.ts +49 -0
- package/src/api/endpoints/auth-tokens.ts +28 -0
- package/src/api/endpoints/codegen/codegen.ts +16 -0
- package/src/api/endpoints/codegen/ds-pipelines.ts +37 -0
- package/src/api/endpoints/codegen/exporters.ts +54 -0
- package/src/api/endpoints/codegen/index.ts +5 -0
- package/src/api/endpoints/codegen/jobs.ts +15 -0
- package/src/api/endpoints/codegen/pipelines.ts +55 -0
- package/src/api/endpoints/design-system/analytics.ts +14 -0
- package/src/api/endpoints/design-system/bff.ts +13 -0
- package/src/api/endpoints/design-system/code-snapshots.ts +47 -0
- package/src/api/endpoints/design-system/contact.ts +12 -0
- package/src/api/endpoints/design-system/design-systems.ts +90 -0
- package/src/api/endpoints/design-system/figma-node-structures.ts +20 -0
- package/src/api/endpoints/design-system/index.ts +11 -0
- package/src/api/endpoints/design-system/members.ts +24 -0
- package/src/api/endpoints/design-system/redirects.ts +46 -0
- package/src/api/endpoints/design-system/sources.ts +80 -0
- package/src/api/endpoints/design-system/storybook.ts +28 -0
- package/src/api/endpoints/design-system/versions/brands.ts +45 -0
- package/src/api/endpoints/design-system/versions/documentation.ts +107 -0
- package/src/api/endpoints/design-system/versions/ds-components.ts +30 -0
- package/src/api/endpoints/design-system/versions/elements-action.ts +65 -0
- package/src/api/endpoints/design-system/versions/elements.ts +27 -0
- package/src/api/endpoints/design-system/versions/figma-component-groups.ts +13 -0
- package/src/api/endpoints/design-system/versions/figma-components.ts +15 -0
- package/src/api/endpoints/design-system/versions/figma-frame-structures.ts +13 -0
- package/src/api/endpoints/design-system/versions/files.ts +43 -0
- package/src/api/endpoints/design-system/versions/import-jobs.ts +13 -0
- package/src/api/endpoints/design-system/versions/index.ts +19 -0
- package/src/api/endpoints/design-system/versions/overrides.ts +17 -0
- package/src/api/endpoints/design-system/versions/property-definitions.ts +43 -0
- package/src/api/endpoints/design-system/versions/property-values.ts +25 -0
- package/src/api/endpoints/design-system/versions/stats.ts +12 -0
- package/src/api/endpoints/design-system/versions/themes.ts +35 -0
- package/src/api/endpoints/design-system/versions/token-collections.ts +13 -0
- package/src/api/endpoints/design-system/versions/token-groups.ts +30 -0
- package/src/api/endpoints/design-system/versions/tokens.ts +29 -0
- package/src/api/endpoints/design-system/versions/versions.ts +90 -0
- package/src/api/endpoints/feedback.ts +60 -0
- package/src/api/endpoints/files.ts +25 -0
- package/src/api/endpoints/forge/agents.ts +54 -0
- package/src/api/endpoints/forge/artifacts.ts +54 -0
- package/src/api/endpoints/forge/documents.ts +18 -0
- package/src/api/endpoints/forge/feature-artifacts.ts +39 -0
- package/src/api/endpoints/forge/feature-iterations.ts +49 -0
- package/src/api/endpoints/forge/feature-messages.ts +68 -0
- package/src/api/endpoints/forge/features.ts +63 -0
- package/src/api/endpoints/forge/forge.ts +38 -0
- package/src/api/endpoints/forge/index.ts +16 -0
- package/src/api/endpoints/forge/iteration-tags.ts +13 -0
- package/src/api/endpoints/forge/memory.ts +41 -0
- package/src/api/endpoints/forge/project-contexts.ts +49 -0
- package/src/api/endpoints/forge/project-files.ts +41 -0
- package/src/api/endpoints/forge/project-invitations.ts +39 -0
- package/src/api/endpoints/forge/project-iterations.ts +65 -0
- package/src/api/endpoints/forge/project-members.ts +55 -0
- package/src/api/endpoints/forge/projects.ts +56 -0
- package/src/api/endpoints/index.ts +13 -0
- package/src/api/endpoints/liveblocks.ts +14 -0
- package/src/api/endpoints/mcp/index.ts +1 -0
- package/src/api/endpoints/mcp/streams.ts +21 -0
- package/src/api/endpoints/sandboxes/builds.ts +30 -0
- package/src/api/endpoints/sandboxes/index.ts +3 -0
- package/src/api/endpoints/sandboxes/sandboxes.ts +13 -0
- package/src/api/endpoints/sandboxes/templates.ts +16 -0
- package/src/api/endpoints/storybook-sites.ts +42 -0
- package/src/api/endpoints/threads.ts +38 -0
- package/src/api/endpoints/users.ts +26 -0
- package/src/api/endpoints/workspaces/billing.ts +24 -0
- package/src/api/endpoints/workspaces/chat-threads.ts +95 -0
- package/src/api/endpoints/workspaces/index.ts +9 -0
- package/src/api/endpoints/workspaces/integrations.ts +15 -0
- package/src/api/endpoints/workspaces/invites.ts +34 -0
- package/src/api/endpoints/workspaces/knowledge-items.ts +59 -0
- package/src/api/endpoints/workspaces/members.ts +31 -0
- package/src/api/endpoints/workspaces/npm-register.ts +20 -0
- package/src/api/endpoints/workspaces/subscription.ts +31 -0
- package/src/api/endpoints/workspaces/workspaces.ts +84 -0
- package/src/api/index.ts +6 -0
- package/src/api/payloads/design-systems/code-snapshots.ts +27 -0
- package/src/api/payloads/design-systems/index.ts +3 -0
- package/src/api/payloads/design-systems/update-design-system.ts +42 -0
- package/src/api/payloads/design-systems/version.ts +29 -0
- package/src/api/payloads/documentation/analytics.ts +36 -0
- package/src/api/payloads/documentation/block-definitions.ts +18 -0
- package/src/api/payloads/documentation/design-data-doc-diff.ts +7 -0
- package/src/api/payloads/documentation/index.ts +3 -0
- package/src/api/payloads/export/index.ts +1 -0
- package/src/api/payloads/export/pipeline.ts +111 -0
- package/src/api/payloads/index.ts +6 -0
- package/src/api/payloads/liveblocks/auth.ts +7 -0
- package/src/api/payloads/liveblocks/index.ts +1 -0
- package/src/api/payloads/users/index.ts +1 -0
- package/src/api/payloads/users/notifications/index.ts +1 -0
- package/src/api/payloads/users/notifications/notification-settings.ts +17 -0
- package/src/api/payloads/workspaces/index.ts +2 -0
- package/src/api/payloads/workspaces/workspace-configuration.ts +62 -0
- package/src/api/payloads/workspaces/workspace-integrations.ts +35 -0
- package/src/api/transport/index.ts +2 -0
- package/src/api/transport/request-executor-error.ts +60 -0
- package/src/api/transport/request-executor.ts +94 -0
- package/src/events/design-system.ts +21 -0
- package/src/events/event.ts +6 -0
- package/src/events/index.ts +2 -0
- package/src/index.ts +5 -0
- package/src/sync/docs-local-action-executor.ts +412 -0
- package/src/sync/docs-structure-repo.ts +283 -0
- package/src/sync/index.ts +5 -0
- package/src/sync/project-content-repo.ts +215 -0
- package/src/sync/project-local-action-executor.ts +415 -0
- package/src/sync/types.ts +37 -0
- package/src/utils/figma.ts +72 -0
- package/src/utils/hash.ts +62 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/query.ts +41 -0
- package/src/utils/redirect-validation.ts +76 -0
- package/src/yjs/design-system-content/documentation-hierarchy.ts +35 -0
- package/src/yjs/design-system-content/index.ts +2 -0
- package/src/yjs/design-system-content/item-configuration.ts +62 -0
- package/src/yjs/docs-editor/blocks-to-prosemirror.ts +764 -0
- package/src/yjs/docs-editor/index.ts +7 -0
- package/src/yjs/docs-editor/list-tree-builder.ts +127 -0
- package/src/yjs/docs-editor/mock.ts +2271 -0
- package/src/yjs/docs-editor/model/block.ts +8 -0
- package/src/yjs/docs-editor/model/index.ts +2 -0
- package/src/yjs/docs-editor/model/page.ts +8 -0
- package/src/yjs/docs-editor/prosemirror/index.ts +3 -0
- package/src/yjs/docs-editor/prosemirror/inner-editor-schema.ts +145 -0
- package/src/yjs/docs-editor/prosemirror/main-editor-schema.ts +577 -0
- package/src/yjs/docs-editor/prosemirror/types.ts +19 -0
- package/src/yjs/docs-editor/prosemirror-to-blocks.ts +986 -0
- package/src/yjs/docs-editor/utils.ts +115 -0
- package/src/yjs/feature-room/backend.ts +36 -0
- package/src/yjs/feature-room/base.ts +109 -0
- package/src/yjs/feature-room/frontend.ts +53 -0
- package/src/yjs/feature-room/index.ts +3 -0
- package/src/yjs/forge-project-room/backend.ts +59 -0
- package/src/yjs/forge-project-room/base.ts +190 -0
- package/src/yjs/forge-project-room/index.ts +2 -0
- package/src/yjs/index.ts +7 -0
- package/src/yjs/thread-room/backend.ts +32 -0
- package/src/yjs/thread-room/base.ts +71 -0
- package/src/yjs/thread-room/frontend.ts +39 -0
- package/src/yjs/thread-room/index.ts +3 -0
- package/src/yjs/utils/index.ts +1 -0
- package/src/yjs/utils/key-value-storage.ts +57 -0
- package/src/yjs/version-room/backend.ts +101 -0
- package/src/yjs/version-room/base.ts +323 -0
- package/src/yjs/version-room/compute-dto.ts +387 -0
- package/src/yjs/version-room/frontend.ts +76 -0
- package/src/yjs/version-room/index.ts +6 -0
- package/src/yjs/version-room/types.ts +31 -0
- package/src/yjs/version-room/utils.ts +109 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { PageBlockEditorModel } from "./model/block";
|
|
2
|
+
import {
|
|
3
|
+
PageBlockDefinition,
|
|
4
|
+
PageBlockDefinitionPropertyType,
|
|
5
|
+
PageBlockItemEmbedValue,
|
|
6
|
+
PageBlockItemMultiRichTextValue,
|
|
7
|
+
PageBlockItemRichTextValue,
|
|
8
|
+
PageBlockItemTableValue,
|
|
9
|
+
PageBlockItemUntypedValue,
|
|
10
|
+
PageBlockItemV2,
|
|
11
|
+
PageBlockText,
|
|
12
|
+
} from "@supernova-studio/model";
|
|
13
|
+
|
|
14
|
+
export const BlockParsingUtils = {
|
|
15
|
+
singleBlockItem(block: PageBlockEditorModel) {
|
|
16
|
+
if (!block.data.items.length) throw new Error(`Block ${block.id} has no items`);
|
|
17
|
+
if (block.data.items.length > 1) throw new Error(`Block ${block.id} has more than 1 item`);
|
|
18
|
+
|
|
19
|
+
return block.data.items[0]!;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
richTextPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemRichTextValue {
|
|
23
|
+
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
24
|
+
const richText = PageBlockItemRichTextValue.parse(objectValue);
|
|
25
|
+
|
|
26
|
+
return richText;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
multiRichTextPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemMultiRichTextValue {
|
|
30
|
+
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
31
|
+
const richText = PageBlockItemMultiRichTextValue.parse(objectValue);
|
|
32
|
+
|
|
33
|
+
return richText;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
tablePropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemTableValue {
|
|
37
|
+
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
38
|
+
const table = PageBlockItemTableValue.parse(objectValue);
|
|
39
|
+
|
|
40
|
+
return table;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
embedPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemEmbedValue {
|
|
44
|
+
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
45
|
+
const embed = PageBlockItemEmbedValue.parse(objectValue);
|
|
46
|
+
|
|
47
|
+
return embed;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
objectPropertyValue(item: PageBlockItemV2, propertyKey: string) {
|
|
51
|
+
const value = this.propertyValueOrThrow(item, propertyKey);
|
|
52
|
+
|
|
53
|
+
if (typeof value !== "object") {
|
|
54
|
+
throw new Error(`Value for property ${propertyKey} is expected to be an object, but instead is ${typeof value}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return value;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
propertyValueOrThrow(item: PageBlockItemV2, propertyKey: string): PageBlockItemUntypedValue {
|
|
61
|
+
const value = item.props[propertyKey];
|
|
62
|
+
if (!value) throw new Error(`Property ${propertyKey} is not defined on block item`);
|
|
63
|
+
|
|
64
|
+
return value;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const BlockDefinitionUtils = {
|
|
69
|
+
firstRichTextProperty(definition: PageBlockDefinition) {
|
|
70
|
+
const property = definition.item.properties.find(p => p.type === "RichText");
|
|
71
|
+
if (property) return property;
|
|
72
|
+
return undefined;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
firstMultiRichTextProperty(definition: PageBlockDefinition) {
|
|
76
|
+
const property = definition.item.properties.find(p => p.type === "MultiRichText");
|
|
77
|
+
if (property) return property;
|
|
78
|
+
return undefined;
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
firstTableProperty(definition: PageBlockDefinition) {
|
|
82
|
+
const property = definition.item.properties.find(p => p.type === "Table");
|
|
83
|
+
if (property) return property;
|
|
84
|
+
return undefined;
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
firstEmbedProperty(definition: PageBlockDefinition) {
|
|
88
|
+
const property = definition.item.properties.find(p => p.type === "EmbedURL");
|
|
89
|
+
if (property) return property;
|
|
90
|
+
return undefined;
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
richTextProperty(definition: PageBlockDefinition, propertyKey: string) {
|
|
94
|
+
return this.property(definition, propertyKey, "RichText");
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
property(
|
|
98
|
+
definition: PageBlockDefinition,
|
|
99
|
+
propertyKey: string,
|
|
100
|
+
expectedPropertyType?: PageBlockDefinitionPropertyType
|
|
101
|
+
) {
|
|
102
|
+
const property = definition.item.properties.find(p => p.id === propertyKey);
|
|
103
|
+
if (!property) {
|
|
104
|
+
throw new Error(`Definition ${definition.id} doesn't contain property ${propertyKey}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (expectedPropertyType && property.type !== expectedPropertyType) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Property ${propertyKey} of definition ${definition.id} expected to be ${expectedPropertyType} but was ${property.type}`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return property;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { DTOFeatureAgentResponseTracker } from "../../api/dto/forge/feature-messages";
|
|
3
|
+
import { FeatureRoomBaseYDoc } from "./base";
|
|
4
|
+
|
|
5
|
+
type FeatureRoomTransaction = {
|
|
6
|
+
agentResponseTrackers?: DTOFeatureAgentResponseTracker[];
|
|
7
|
+
agentResponseTrackerIdsToDelete?: string[];
|
|
8
|
+
|
|
9
|
+
executedTransactionIds?: string[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export class BackendFeatureRoomYDoc {
|
|
13
|
+
private readonly yDoc: Y.Doc;
|
|
14
|
+
|
|
15
|
+
constructor(yDoc: Y.Doc) {
|
|
16
|
+
this.yDoc = yDoc;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
updateFeatureRoom(transaction: FeatureRoomTransaction) {
|
|
20
|
+
this.yDoc.transact(trx => {
|
|
21
|
+
const yDoc = new FeatureRoomBaseYDoc(trx.doc);
|
|
22
|
+
// Agent Response Trackers
|
|
23
|
+
transaction.agentResponseTrackerIdsToDelete &&
|
|
24
|
+
yDoc.deleteAgentResponseTrackers(transaction.agentResponseTrackerIdsToDelete);
|
|
25
|
+
transaction.agentResponseTrackers && yDoc.updateAgentResponseTrackers(transaction.agentResponseTrackers);
|
|
26
|
+
|
|
27
|
+
// Executed transaction ids
|
|
28
|
+
transaction.executedTransactionIds && yDoc.updateExecutedTransactionIds(transaction.executedTransactionIds);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getState() {
|
|
33
|
+
const featureRoomDoc = new FeatureRoomBaseYDoc(this.yDoc);
|
|
34
|
+
return featureRoomDoc.getState();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { ZodSchema, ZodTypeDef } from "zod";
|
|
3
|
+
import { DTOFeatureAgentResponseTracker } from "../../api/dto/forge/feature-messages";
|
|
4
|
+
|
|
5
|
+
type YJSSerializable = { id: string };
|
|
6
|
+
|
|
7
|
+
export interface FeatureRoomBaseYDocState {
|
|
8
|
+
isLoaded: boolean;
|
|
9
|
+
agentResponseTrackers: DTOFeatureAgentResponseTracker[];
|
|
10
|
+
executedTransactionIds: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface FeatureRoomUpdate {
|
|
14
|
+
agentResponseTrackers?: DTOFeatureAgentResponseTracker[];
|
|
15
|
+
agentResponseTrackerIdsToDelete?: string[];
|
|
16
|
+
|
|
17
|
+
executedTransactionIds?: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class FeatureRoomBaseYDoc {
|
|
21
|
+
private readonly yDoc: Y.Doc;
|
|
22
|
+
|
|
23
|
+
constructor(yDoc: Y.Doc) {
|
|
24
|
+
this.yDoc = yDoc;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getState(): FeatureRoomBaseYDocState {
|
|
28
|
+
const agentResponseTrackers = this.getAgentResponseTrackers();
|
|
29
|
+
const executedTransactionIds = this.getExecutedTransactionIds();
|
|
30
|
+
const isLoaded = true; // For now, consider it loaded if we can access the data
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
isLoaded,
|
|
34
|
+
agentResponseTrackers,
|
|
35
|
+
executedTransactionIds,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//
|
|
40
|
+
// Agent Response Trackers
|
|
41
|
+
//
|
|
42
|
+
|
|
43
|
+
getAgentResponseTrackers(): DTOFeatureAgentResponseTracker[] {
|
|
44
|
+
return this.getObjects(this.agentResponseTrackersYMap, DTOFeatureAgentResponseTracker);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
updateAgentResponseTrackers(trackers: DTOFeatureAgentResponseTracker[]) {
|
|
48
|
+
this.setObjects(this.agentResponseTrackersYMap, trackers);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
deleteAgentResponseTrackers(ids: string[]) {
|
|
52
|
+
this.deleteObjects(this.agentResponseTrackersYMap, ids);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private get agentResponseTrackersYMap() {
|
|
56
|
+
return this.yDoc.getMap<object>("forgeFeatureAgentResponseTrackers");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//
|
|
60
|
+
// Executed transactions
|
|
61
|
+
//
|
|
62
|
+
|
|
63
|
+
updateExecutedTransactionIds(transactionIds: string[]) {
|
|
64
|
+
transactionIds = Array.from(new Set(transactionIds));
|
|
65
|
+
if (!transactionIds.length) return;
|
|
66
|
+
|
|
67
|
+
const array = this.executedTransactionIdsArray;
|
|
68
|
+
|
|
69
|
+
// Append transactions at the end
|
|
70
|
+
array.push(transactionIds);
|
|
71
|
+
|
|
72
|
+
// Trim from the beginning in case it contains more than 100
|
|
73
|
+
if (array.length > 100) {
|
|
74
|
+
array.delete(0, array.length - 100);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getExecutedTransactionIds(): string[] {
|
|
79
|
+
const array = this.executedTransactionIdsArray;
|
|
80
|
+
|
|
81
|
+
// Y.Array doesn't support filtering
|
|
82
|
+
const transactionIds: string[] = [];
|
|
83
|
+
array.forEach(e => typeof e === "string" && transactionIds.push(e));
|
|
84
|
+
|
|
85
|
+
return transactionIds;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private get executedTransactionIdsArray() {
|
|
89
|
+
return this.yDoc.getArray<unknown>("executedTransactionIds");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//
|
|
93
|
+
// Utility methods
|
|
94
|
+
//
|
|
95
|
+
|
|
96
|
+
private getObjects<T extends YJSSerializable, I>(map: Y.Map<object>, schema: ZodSchema<T, ZodTypeDef, I>): T[] {
|
|
97
|
+
const objects: T[] = [];
|
|
98
|
+
map.forEach(value => objects.push(schema.parse(value)));
|
|
99
|
+
return objects;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private setObjects<T extends YJSSerializable>(map: Y.Map<object>, objects: T[]) {
|
|
103
|
+
objects.forEach(o => map.set(o.id, JSON.parse(JSON.stringify(o))));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private deleteObjects(map: Y.Map<object>, ids: string[]) {
|
|
107
|
+
ids.forEach(id => map.delete(id));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { DTOFeatureAgentResponseTracker } from "../../api/dto/forge/feature-messages";
|
|
3
|
+
import { FeatureRoomBaseYDoc, FeatureRoomBaseYDocState } from "./base";
|
|
4
|
+
|
|
5
|
+
export class FrontendFeatureRoomYDoc {
|
|
6
|
+
private readonly yDoc: Y.Doc;
|
|
7
|
+
|
|
8
|
+
constructor(yDoc: Y.Doc, private readonly debug = false) {
|
|
9
|
+
this.yDoc = yDoc;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//
|
|
13
|
+
// State Access
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
getState(): FeatureRoomBaseYDocState {
|
|
17
|
+
const doc = new FeatureRoomBaseYDoc(this.yDoc);
|
|
18
|
+
return doc.getState();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//
|
|
22
|
+
// Agent Response Trackers
|
|
23
|
+
//
|
|
24
|
+
|
|
25
|
+
getAgentResponseTrackers(): DTOFeatureAgentResponseTracker[] {
|
|
26
|
+
const doc = new FeatureRoomBaseYDoc(this.yDoc);
|
|
27
|
+
return doc.getAgentResponseTrackers();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
updateAgentResponseTracker(tracker: DTOFeatureAgentResponseTracker) {
|
|
31
|
+
const doc = new FeatureRoomBaseYDoc(this.yDoc);
|
|
32
|
+
return doc.updateAgentResponseTrackers([tracker]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
deleteAgentResponseTrackers(id: string) {
|
|
36
|
+
const doc = new FeatureRoomBaseYDoc(this.yDoc);
|
|
37
|
+
return doc.deleteAgentResponseTrackers([id]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//
|
|
41
|
+
// Utility Methods
|
|
42
|
+
//
|
|
43
|
+
|
|
44
|
+
isLoaded(): boolean {
|
|
45
|
+
const doc = new FeatureRoomBaseYDoc(this.yDoc);
|
|
46
|
+
return doc.getState().isLoaded;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getExecutedTransactionIds(): string[] {
|
|
50
|
+
const doc = new FeatureRoomBaseYDoc(this.yDoc);
|
|
51
|
+
return doc.getExecutedTransactionIds();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ForgeProjectArtifact, ForgeSection, ProjectFeature, ForgeRelation } from "@supernova-studio/model";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
import { ForgeProjectRoomBaseYDoc } from "./base";
|
|
4
|
+
|
|
5
|
+
type ForgeProjectRoomTransaction = {
|
|
6
|
+
artifacts?: ForgeProjectArtifact[];
|
|
7
|
+
artifactIdsToDelete?: string[];
|
|
8
|
+
features?: ProjectFeature[];
|
|
9
|
+
featureIdsToDelete?: string[];
|
|
10
|
+
artifactSections?: ForgeSection[];
|
|
11
|
+
artifactSectionIdsToDelete?: string[];
|
|
12
|
+
featureSections?: ForgeSection[];
|
|
13
|
+
featureSectionIdsToDelete?: string[];
|
|
14
|
+
relations?: ForgeRelation[];
|
|
15
|
+
executedTransactionIds?: string[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export class BackendForgeProjectRoomYDoc {
|
|
19
|
+
private readonly yDoc: Y.Doc;
|
|
20
|
+
|
|
21
|
+
constructor(yDoc: Y.Doc) {
|
|
22
|
+
this.yDoc = yDoc;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
updateWithLists(transaction: ForgeProjectRoomTransaction) {
|
|
26
|
+
this.yDoc.transact(trx => {
|
|
27
|
+
const yDoc = new ForgeProjectRoomBaseYDoc(trx.doc);
|
|
28
|
+
|
|
29
|
+
// Delete artifacts first
|
|
30
|
+
transaction.artifactIdsToDelete && yDoc.deleteArtifacts(transaction.artifactIdsToDelete);
|
|
31
|
+
|
|
32
|
+
// Then update/add artifacts
|
|
33
|
+
transaction.artifacts && yDoc.updateArtifacts(transaction.artifacts);
|
|
34
|
+
|
|
35
|
+
// Delete features
|
|
36
|
+
transaction.featureIdsToDelete && yDoc.deleteFeatures(transaction.featureIdsToDelete);
|
|
37
|
+
|
|
38
|
+
// Then update/add features
|
|
39
|
+
transaction.features && yDoc.updateFeatures(transaction.features);
|
|
40
|
+
|
|
41
|
+
// Delete artifact sections
|
|
42
|
+
transaction.artifactSectionIdsToDelete && yDoc.deleteArtifactSections(transaction.artifactSectionIdsToDelete);
|
|
43
|
+
|
|
44
|
+
// Then update/add artifact sections
|
|
45
|
+
transaction.artifactSections && yDoc.updateArtifactSections(transaction.artifactSections);
|
|
46
|
+
|
|
47
|
+
// Delete feature sections
|
|
48
|
+
transaction.featureSectionIdsToDelete && yDoc.deleteFeatureSections(transaction.featureSectionIdsToDelete);
|
|
49
|
+
|
|
50
|
+
// Then update/add feature sections
|
|
51
|
+
transaction.featureSections && yDoc.updateFeatureSections(transaction.featureSections);
|
|
52
|
+
|
|
53
|
+
// Then update/add relations
|
|
54
|
+
transaction.relations && yDoc.updateRelations(transaction.relations);
|
|
55
|
+
|
|
56
|
+
transaction.executedTransactionIds && yDoc.updateExecutedTransactionIds(transaction.executedTransactionIds);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { ForgeProjectArtifact, ForgeSection, ProjectFeature, ForgeRelation } from "@supernova-studio/model";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
import { ZodSchema, ZodTypeDef } from "zod";
|
|
4
|
+
|
|
5
|
+
type YJSSerializable = { id: string };
|
|
6
|
+
|
|
7
|
+
export interface ForgeProjectRoomBaseYDocState {
|
|
8
|
+
isLoaded: boolean;
|
|
9
|
+
artifacts: ForgeProjectArtifact[];
|
|
10
|
+
features: ProjectFeature[];
|
|
11
|
+
artifactSections: ForgeSection[];
|
|
12
|
+
featureSections: ForgeSection[];
|
|
13
|
+
relations: ForgeRelation[];
|
|
14
|
+
executedTransactionIds: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class ForgeProjectRoomBaseYDoc {
|
|
18
|
+
private readonly yDoc: Y.Doc;
|
|
19
|
+
|
|
20
|
+
constructor(yDoc: Y.Doc) {
|
|
21
|
+
this.yDoc = yDoc;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getState(): ForgeProjectRoomBaseYDocState {
|
|
25
|
+
const artifacts = this.getArtifacts();
|
|
26
|
+
const features = this.getFeatures();
|
|
27
|
+
const artifactSections = this.getArtifactSections();
|
|
28
|
+
const featureSections = this.getFeatureSections();
|
|
29
|
+
const relations = this.getRelations();
|
|
30
|
+
const executedTransactionIds = this.getExecutedTransactionIds();
|
|
31
|
+
const isLoaded = true; // For now, consider it loaded if we can access artifacts
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
isLoaded,
|
|
35
|
+
artifacts,
|
|
36
|
+
features,
|
|
37
|
+
artifactSections,
|
|
38
|
+
featureSections,
|
|
39
|
+
relations,
|
|
40
|
+
executedTransactionIds,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//
|
|
45
|
+
// Artifacts
|
|
46
|
+
//
|
|
47
|
+
|
|
48
|
+
getArtifacts(): ForgeProjectArtifact[] {
|
|
49
|
+
return this.getObjects(this.artifactsYMap, ForgeProjectArtifact);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
updateArtifacts(artifacts: ForgeProjectArtifact[]) {
|
|
53
|
+
this.setObjects(this.artifactsYMap, artifacts);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
deleteArtifacts(ids: string[]) {
|
|
57
|
+
this.deleteObjects(this.artifactsYMap, ids);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private get artifactsYMap() {
|
|
61
|
+
return this.yDoc.getMap<object>("forgeProjectArtifacts");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//
|
|
65
|
+
// Features
|
|
66
|
+
//
|
|
67
|
+
|
|
68
|
+
getFeatures(): ProjectFeature[] {
|
|
69
|
+
return this.getObjects(this.featuresYMap, ProjectFeature);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
updateFeatures(features: ProjectFeature[]) {
|
|
73
|
+
this.setObjects(this.featuresYMap, features);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
deleteFeatures(ids: string[]) {
|
|
77
|
+
this.deleteObjects(this.featuresYMap, ids);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private get featuresYMap() {
|
|
81
|
+
return this.yDoc.getMap<object>("forgeProjectFeatures");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//
|
|
85
|
+
// Sections
|
|
86
|
+
//
|
|
87
|
+
|
|
88
|
+
getArtifactSections(): ForgeSection[] {
|
|
89
|
+
return this.getObjects(this.artifactSectionsYMap, ForgeSection);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
updateArtifactSections(sections: ForgeSection[]) {
|
|
93
|
+
this.setObjects(this.artifactSectionsYMap, sections);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
deleteArtifactSections(ids: string[]) {
|
|
97
|
+
this.deleteObjects(this.artifactSectionsYMap, ids);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private get artifactSectionsYMap() {
|
|
101
|
+
return this.yDoc.getMap<object>("forgeProjectArtifactSections");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//
|
|
105
|
+
// Feature Sections
|
|
106
|
+
//
|
|
107
|
+
|
|
108
|
+
getFeatureSections(): ForgeSection[] {
|
|
109
|
+
return this.getObjects(this.featureSectionsYMap, ForgeSection);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
updateFeatureSections(sections: ForgeSection[]) {
|
|
113
|
+
this.setObjects(this.featureSectionsYMap, sections);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
deleteFeatureSections(ids: string[]) {
|
|
117
|
+
this.deleteObjects(this.featureSectionsYMap, ids);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private get featureSectionsYMap() {
|
|
121
|
+
return this.yDoc.getMap<object>("forgeProjectFeatureSections");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//
|
|
125
|
+
// Relations
|
|
126
|
+
//
|
|
127
|
+
|
|
128
|
+
getRelations(): ForgeRelation[] {
|
|
129
|
+
return this.getObjects(this.relationsYMap, ForgeRelation);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
updateRelations(relations: ForgeRelation[]) {
|
|
133
|
+
this.setObjects(this.relationsYMap, relations);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private get relationsYMap() {
|
|
137
|
+
return this.yDoc.getMap<object>("forgeRelations");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//
|
|
141
|
+
// Executed transactions
|
|
142
|
+
//
|
|
143
|
+
|
|
144
|
+
updateExecutedTransactionIds(transactionIds: string[]) {
|
|
145
|
+
transactionIds = Array.from(new Set(transactionIds));
|
|
146
|
+
if (!transactionIds.length) return;
|
|
147
|
+
|
|
148
|
+
const array = this.executedTransactionIdsArray;
|
|
149
|
+
|
|
150
|
+
// Append transactions at the end
|
|
151
|
+
array.push(transactionIds);
|
|
152
|
+
|
|
153
|
+
// Trim from the beginning in case it contains more than 100
|
|
154
|
+
if (array.length > 100) {
|
|
155
|
+
array.delete(0, array.length - 100);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
getExecutedTransactionIds(): string[] {
|
|
160
|
+
const array = this.executedTransactionIdsArray;
|
|
161
|
+
|
|
162
|
+
// Y.Array doesn't support filtering
|
|
163
|
+
const transactionIds: string[] = [];
|
|
164
|
+
array.forEach(e => typeof e === "string" && transactionIds.push(e));
|
|
165
|
+
|
|
166
|
+
return transactionIds;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private get executedTransactionIdsArray() {
|
|
170
|
+
return this.yDoc.getArray<unknown>("executedTransactionIds");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//
|
|
174
|
+
// Utility methods
|
|
175
|
+
//
|
|
176
|
+
|
|
177
|
+
private getObjects<T extends YJSSerializable, I>(map: Y.Map<object>, schema: ZodSchema<T, ZodTypeDef, I>): T[] {
|
|
178
|
+
const objects: T[] = [];
|
|
179
|
+
map.forEach(value => objects.push(schema.parse(value)));
|
|
180
|
+
return objects;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private setObjects<T extends YJSSerializable>(map: Y.Map<object>, objects: T[]) {
|
|
184
|
+
objects.forEach(o => map.set(o.id, JSON.parse(JSON.stringify(o))));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private deleteObjects(map: Y.Map<object>, ids: string[]) {
|
|
188
|
+
ids.forEach(id => map.delete(id));
|
|
189
|
+
}
|
|
190
|
+
}
|
package/src/yjs/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { DTOFeatureAgentResponseTracker } from "../../api/dto/forge/feature-messages";
|
|
3
|
+
import { ThreadRoomBaseYDoc } from "./base";
|
|
4
|
+
|
|
5
|
+
type ThreadRoomTransaction = {
|
|
6
|
+
agentResponseTrackers?: DTOFeatureAgentResponseTracker[];
|
|
7
|
+
agentResponseTrackerIdsToDelete?: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export class BackendThreadRoomYDoc {
|
|
11
|
+
private readonly yDoc: Y.Doc;
|
|
12
|
+
|
|
13
|
+
constructor(yDoc: Y.Doc) {
|
|
14
|
+
this.yDoc = yDoc;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
updateState(transaction: ThreadRoomTransaction) {
|
|
18
|
+
this.yDoc.transact(trx => {
|
|
19
|
+
const yDoc = new ThreadRoomBaseYDoc(trx.doc);
|
|
20
|
+
|
|
21
|
+
// Agent Response Trackers
|
|
22
|
+
transaction.agentResponseTrackerIdsToDelete &&
|
|
23
|
+
yDoc.deleteAgentResponseTrackers(transaction.agentResponseTrackerIdsToDelete);
|
|
24
|
+
transaction.agentResponseTrackers && yDoc.updateAgentResponseTrackers(transaction.agentResponseTrackers);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getState() {
|
|
29
|
+
const featureRoomDoc = new ThreadRoomBaseYDoc(this.yDoc);
|
|
30
|
+
return featureRoomDoc.getState();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { ZodSchema, ZodTypeDef } from "zod";
|
|
3
|
+
import { DTOFeatureAgentResponseTracker } from "../../api/dto/forge/feature-messages";
|
|
4
|
+
|
|
5
|
+
type YJSSerializable = { id: string };
|
|
6
|
+
|
|
7
|
+
export interface ThreadRoomBaseYDocState {
|
|
8
|
+
isLoaded: boolean;
|
|
9
|
+
agentResponseTrackers: DTOFeatureAgentResponseTracker[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ThreadRoomUpdate {
|
|
13
|
+
agentResponseTrackers?: DTOFeatureAgentResponseTracker[];
|
|
14
|
+
agentResponseTrackerIdsToDelete?: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class ThreadRoomBaseYDoc {
|
|
18
|
+
private readonly yDoc: Y.Doc;
|
|
19
|
+
|
|
20
|
+
constructor(yDoc: Y.Doc) {
|
|
21
|
+
this.yDoc = yDoc;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getState(): ThreadRoomBaseYDocState {
|
|
25
|
+
const agentResponseTrackers = this.getAgentResponseTrackers();
|
|
26
|
+
const isLoaded = true; // For now, consider it loaded if we can access the data
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
isLoaded,
|
|
30
|
+
agentResponseTrackers,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//
|
|
35
|
+
// Agent Response Trackers
|
|
36
|
+
//
|
|
37
|
+
|
|
38
|
+
getAgentResponseTrackers(): DTOFeatureAgentResponseTracker[] {
|
|
39
|
+
return this.getObjects(this.agentResponseTrackersYMap, DTOFeatureAgentResponseTracker);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
updateAgentResponseTrackers(trackers: DTOFeatureAgentResponseTracker[]) {
|
|
43
|
+
this.setObjects(this.agentResponseTrackersYMap, trackers);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
deleteAgentResponseTrackers(ids: string[]) {
|
|
47
|
+
this.deleteObjects(this.agentResponseTrackersYMap, ids);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private get agentResponseTrackersYMap() {
|
|
51
|
+
return this.yDoc.getMap<object>("forgeFeatureAgentResponseTrackers");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//
|
|
55
|
+
// Utility methods
|
|
56
|
+
//
|
|
57
|
+
|
|
58
|
+
private getObjects<T extends YJSSerializable, I>(map: Y.Map<object>, schema: ZodSchema<T, ZodTypeDef, I>): T[] {
|
|
59
|
+
const objects: T[] = [];
|
|
60
|
+
map.forEach(value => objects.push(schema.parse(value)));
|
|
61
|
+
return objects;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private setObjects<T extends YJSSerializable>(map: Y.Map<object>, objects: T[]) {
|
|
65
|
+
objects.forEach(o => map.set(o.id, JSON.parse(JSON.stringify(o))));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private deleteObjects(map: Y.Map<object>, ids: string[]) {
|
|
69
|
+
ids.forEach(id => map.delete(id));
|
|
70
|
+
}
|
|
71
|
+
}
|