@plitzi/sdk-server 0.32.3 → 0.32.5
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 +18 -0
- package/dist/adapters/jsonAdapters.js +6 -1
- package/dist/core/createServer.js +8 -44
- package/dist/core/health.js +15 -0
- package/dist/core/http/dispatcher.js +29 -0
- package/dist/core/http/securityHeaders.js +15 -0
- package/dist/core/http/stages/authRoutes.js +41 -0
- package/dist/core/http/stages/health.js +12 -0
- package/dist/core/http/stages/middlewares.js +16 -0
- package/dist/core/http/stages/pluginAssets.js +20 -0
- package/dist/core/http/stages/static.js +30 -0
- package/dist/core/server/baseServer.js +29 -0
- package/dist/core/server/mcpServer.js +29 -0
- package/dist/core/server/ssrServer.js +54 -0
- package/dist/core/services/mcp.js +22 -0
- package/dist/core/services/preview.js +37 -0
- package/dist/core/services/registry.js +30 -0
- package/dist/core/services/resolve.js +12 -0
- package/dist/core/services/rsc.js +11 -0
- package/dist/core/services/ssr.js +13 -0
- package/dist/core/transports.js +9 -9
- package/dist/helpers/buildServerInfo.js +11 -11
- package/dist/index.js +19 -6
- package/dist/modules/ai/AIEngine.js +4 -4
- package/dist/modules/ai/toolkit.js +58 -0
- package/dist/modules/mcp/constants.js +4 -0
- package/dist/modules/mcp/handler.js +15 -21
- package/dist/modules/mcp/helpers/computeVersion.js +16 -0
- package/dist/modules/mcp/helpers/guide.js +130 -0
- package/dist/modules/mcp/helpers/opResult.js +18 -0
- package/dist/modules/mcp/helpers/space.js +137 -0
- package/dist/modules/mcp/previewClient.js +31 -0
- package/dist/modules/mcp/resources/canonical.js +45 -0
- package/dist/modules/mcp/resources/core.js +14 -0
- package/dist/modules/mcp/resources/envelope.js +14 -0
- package/dist/modules/mcp/resources/primer.js +25 -0
- package/dist/modules/mcp/resources/register.js +142 -0
- package/dist/modules/mcp/resources/router.js +25 -0
- package/dist/modules/mcp/resources/schema.js +33 -0
- package/dist/modules/mcp/resources/style.js +27 -0
- package/dist/modules/mcp/screenshotClient.js +47 -0
- package/dist/modules/mcp/server.js +52 -20
- package/dist/modules/mcp/tools/apply/dispatch.js +83 -0
- package/dist/modules/mcp/tools/apply/index.js +121 -0
- package/dist/modules/mcp/tools/apply/writeResult.js +36 -0
- package/dist/modules/mcp/tools/index.js +20 -148
- package/dist/modules/mcp/tools/operations/index.js +30 -0
- package/dist/modules/mcp/tools/operations/schema/deleteElement.js +25 -0
- package/dist/modules/mcp/tools/operations/schema/deleteFolder.js +30 -0
- package/dist/modules/mcp/tools/operations/schema/deletePage.js +22 -0
- package/dist/modules/mcp/tools/operations/schema/deleteVariable.js +18 -0
- package/dist/modules/mcp/tools/operations/schema/moveElement.js +39 -0
- package/dist/modules/mcp/tools/operations/schema/operations.js +25 -0
- package/dist/modules/mcp/tools/operations/schema/patchElement.js +46 -0
- package/dist/modules/mcp/tools/operations/schema/registry.js +55 -0
- package/dist/modules/mcp/tools/operations/schema/shared.js +27 -0
- package/dist/modules/mcp/tools/operations/schema/translator.js +148 -0
- package/dist/modules/mcp/tools/operations/schema/upsertElement.js +59 -0
- package/dist/modules/mcp/tools/operations/schema/upsertFolder.js +49 -0
- package/dist/modules/mcp/tools/operations/schema/upsertPage.js +64 -0
- package/dist/modules/mcp/tools/operations/schema/upsertVariable.js +42 -0
- package/dist/modules/mcp/tools/operations/schema/write.js +44 -0
- package/dist/modules/mcp/tools/operations/style/cssCatalog.js +132 -0
- package/dist/modules/mcp/tools/operations/style/deleteDefinition.js +20 -0
- package/dist/modules/mcp/tools/operations/style/deleteGlobalStyle.js +20 -0
- package/dist/modules/mcp/tools/operations/style/deleteStyleVariable.js +21 -0
- package/dist/modules/mcp/tools/operations/style/operations.js +21 -0
- package/dist/modules/mcp/tools/operations/style/patchDefinition.js +27 -0
- package/dist/modules/mcp/tools/operations/style/patchGlobalStyle.js +27 -0
- package/dist/modules/mcp/tools/operations/style/shared.js +59 -0
- package/dist/modules/mcp/tools/operations/style/translator.js +77 -0
- package/dist/modules/mcp/tools/operations/style/upsertDefinition.js +23 -0
- package/dist/modules/mcp/tools/operations/style/upsertGlobalStyle.js +23 -0
- package/dist/modules/mcp/tools/operations/style/upsertStyleVariable.js +22 -0
- package/dist/modules/mcp/tools/operations/style/write.js +100 -0
- package/dist/modules/mcp/tools/preview.js +37 -0
- package/dist/modules/mcp/tools/read.js +33 -0
- package/dist/modules/mcp/tools/screenshot.js +83 -0
- package/dist/modules/mcp/tools/search.js +108 -0
- package/dist/modules/mcp/tools/shared/tool.js +26 -0
- package/dist/modules/mcp/tools/shared/validator.js +262 -0
- package/dist/modules/mcp/tools/validate.js +19 -0
- package/dist/modules/ssr/buildBody.js +2 -2
- package/dist/modules/ssr/handler.js +6 -4
- package/dist/modules/ssr/prepareRender.js +5 -5
- package/dist/modules/ssr/preview.js +106 -0
- package/dist/modules/ssr/registerExternalPlugins.js +1 -1
- package/dist/modules/ssr/streamBody.js +3 -3
- package/dist/modules/ssr/template.js +1 -1
- package/dist/plugins/compile.js +1 -1
- package/dist/plugins/copy.js +1 -1
- package/dist/plugins/manager.js +1 -1
- package/dist/server.js +34 -9
- package/dist/src/core/createServer.d.ts +5 -1
- package/dist/src/core/health.d.ts +10 -0
- package/dist/src/core/http/dispatcher.d.ts +7 -0
- package/dist/src/core/http/securityHeaders.d.ts +2 -0
- package/dist/src/core/http/stages/authRoutes.d.ts +4 -0
- package/dist/src/core/http/stages/health.d.ts +2 -0
- package/dist/src/core/http/stages/middlewares.d.ts +2 -0
- package/dist/src/core/http/stages/pluginAssets.d.ts +2 -0
- package/dist/src/core/http/stages/static.d.ts +5 -0
- package/dist/src/core/http/types.d.ts +19 -0
- package/dist/src/core/server/baseServer.d.ts +9 -0
- package/dist/src/core/server/mcpServer.d.ts +2 -0
- package/dist/src/core/server/ssrServer.d.ts +2 -0
- package/dist/src/core/services/mcp.d.ts +3 -0
- package/dist/src/core/services/preview.d.ts +2 -0
- package/dist/src/core/services/registry.d.ts +4 -0
- package/dist/src/core/services/resolve.d.ts +3 -0
- package/dist/src/core/services/rsc.d.ts +2 -0
- package/dist/src/core/services/ssr.d.ts +3 -0
- package/dist/src/core/transports.d.ts +2 -2
- package/dist/src/index.d.ts +12 -3
- package/dist/src/modules/ai/index.d.ts +1 -0
- package/dist/src/modules/ai/toolkit.d.ts +17 -0
- package/dist/src/modules/mcp/constants.d.ts +1 -0
- package/dist/src/modules/mcp/handler.d.ts +6 -3
- package/dist/src/modules/mcp/helpers/computeVersion.d.ts +1 -0
- package/dist/src/modules/mcp/helpers/guide.d.ts +2 -0
- package/dist/src/modules/mcp/helpers/index.d.ts +4 -0
- package/dist/src/modules/mcp/helpers/opResult.d.ts +13 -0
- package/dist/src/modules/mcp/helpers/space.d.ts +49 -0
- package/dist/src/modules/mcp/index.d.ts +12 -5
- package/dist/src/modules/mcp/previewClient.d.ts +13 -0
- package/dist/src/modules/mcp/resources/canonical.d.ts +7 -0
- package/dist/src/modules/mcp/resources/core.d.ts +5 -0
- package/dist/src/modules/mcp/resources/envelope.d.ts +10 -0
- package/dist/src/modules/mcp/resources/index.d.ts +8 -10
- package/dist/src/modules/mcp/resources/primer.d.ts +6 -0
- package/dist/src/modules/mcp/resources/register.d.ts +6 -0
- package/dist/src/modules/mcp/resources/router.d.ts +6 -0
- package/dist/src/modules/mcp/resources/schema.d.ts +5 -0
- package/dist/src/modules/mcp/resources/style.d.ts +5 -0
- package/dist/src/modules/mcp/screenshotClient.d.ts +13 -0
- package/dist/src/modules/mcp/server.d.ts +18 -3
- package/dist/src/modules/mcp/tools/apply/dispatch.d.ts +6 -0
- package/dist/src/modules/mcp/tools/apply/index.d.ts +231 -0
- package/dist/src/modules/mcp/tools/apply/writeResult.d.ts +8 -0
- package/dist/src/modules/mcp/tools/index.d.ts +17 -6
- package/dist/src/modules/mcp/tools/operations/index.d.ts +449 -0
- package/dist/src/modules/mcp/tools/operations/schema/deleteElement.d.ts +10 -0
- package/dist/src/modules/mcp/tools/operations/schema/deleteFolder.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/schema/deletePage.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/schema/deleteVariable.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/schema/index.d.ts +14 -0
- package/dist/src/modules/mcp/tools/operations/schema/moveElement.d.ts +16 -0
- package/dist/src/modules/mcp/tools/operations/schema/operations.d.ts +79 -0
- package/dist/src/modules/mcp/tools/operations/schema/patchElement.d.ts +17 -0
- package/dist/src/modules/mcp/tools/operations/schema/registry.d.ts +22 -0
- package/dist/src/modules/mcp/tools/operations/schema/shared.d.ts +24 -0
- package/dist/src/modules/mcp/tools/operations/schema/translator.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/schema/upsertElement.d.ts +16 -0
- package/dist/src/modules/mcp/tools/operations/schema/upsertFolder.d.ts +12 -0
- package/dist/src/modules/mcp/tools/operations/schema/upsertPage.d.ts +13 -0
- package/dist/src/modules/mcp/tools/operations/schema/upsertVariable.d.ts +16 -0
- package/dist/src/modules/mcp/tools/operations/schema/write.d.ts +12 -0
- package/dist/src/modules/mcp/tools/operations/style/cssCatalog.d.ts +10 -0
- package/dist/src/modules/mcp/tools/operations/style/deleteDefinition.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/style/deleteGlobalStyle.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/style/deleteStyleVariable.d.ts +15 -0
- package/dist/src/modules/mcp/tools/operations/style/index.d.ts +12 -0
- package/dist/src/modules/mcp/tools/operations/style/operations.d.ts +163 -0
- package/dist/src/modules/mcp/tools/operations/style/patchDefinition.d.ts +37 -0
- package/dist/src/modules/mcp/tools/operations/style/patchGlobalStyle.d.ts +37 -0
- package/dist/src/modules/mcp/tools/operations/style/shared.d.ts +115 -0
- package/dist/src/modules/mcp/tools/operations/style/translator.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/style/upsertDefinition.d.ts +37 -0
- package/dist/src/modules/mcp/tools/operations/style/upsertGlobalStyle.d.ts +37 -0
- package/dist/src/modules/mcp/tools/operations/style/upsertStyleVariable.d.ts +20 -0
- package/dist/src/modules/mcp/tools/operations/style/write.d.ts +17 -0
- package/dist/src/modules/mcp/tools/preview.d.ts +226 -0
- package/dist/src/modules/mcp/tools/read.d.ts +8 -0
- package/dist/src/modules/mcp/tools/screenshot.d.ts +231 -0
- package/dist/src/modules/mcp/tools/search.d.ts +15 -0
- package/dist/src/modules/mcp/tools/shared/tool.d.ts +50 -0
- package/dist/src/modules/mcp/tools/shared/validator.d.ts +4 -0
- package/dist/src/modules/mcp/tools/validate.d.ts +228 -0
- package/dist/src/modules/mcp/types/aiSchema.d.ts +126 -0
- package/dist/src/modules/mcp/types/index.d.ts +4 -0
- package/dist/src/modules/mcp/types/previewTypes.d.ts +25 -0
- package/dist/src/modules/mcp/types/screenshotTypes.d.ts +29 -0
- package/dist/src/modules/mcp/types/toolTypes.d.ts +138 -0
- package/dist/src/modules/ssr/buildBody.d.ts +2 -2
- package/dist/src/modules/ssr/prepareRender.d.ts +2 -2
- package/dist/src/modules/ssr/preview.d.ts +16 -0
- package/dist/src/modules/ssr/streamBody.d.ts +2 -2
- package/package.json +10 -10
- package/dist/_virtual/_rolldown/runtime.js +0 -13
- package/dist/core/requestHandler.js +0 -126
- package/dist/modules/mcp/helpers.js +0 -75
- package/dist/modules/mcp/resources/glossary/binding.js +0 -73
- package/dist/modules/mcp/resources/glossary/collection.js +0 -76
- package/dist/modules/mcp/resources/glossary/displayMode.js +0 -50
- package/dist/modules/mcp/resources/glossary/element.js +0 -68
- package/dist/modules/mcp/resources/glossary/environment.js +0 -48
- package/dist/modules/mcp/resources/glossary/interaction.js +0 -62
- package/dist/modules/mcp/resources/glossary/page.js +0 -70
- package/dist/modules/mcp/resources/glossary/plugin.js +0 -96
- package/dist/modules/mcp/resources/glossary/resource.js +0 -75
- package/dist/modules/mcp/resources/glossary/schema.js +0 -69
- package/dist/modules/mcp/resources/glossary/schemaVariable.js +0 -60
- package/dist/modules/mcp/resources/glossary/segment.js +0 -59
- package/dist/modules/mcp/resources/glossary/space.js +0 -73
- package/dist/modules/mcp/resources/glossary/style.js +0 -81
- package/dist/modules/mcp/resources/glossary/styleSelector.js +0 -77
- package/dist/modules/mcp/resources/glossary/styleVariable.js +0 -72
- package/dist/modules/mcp/resources/index.js +0 -71
- package/dist/modules/mcp/resources/workflows/data.js +0 -49
- package/dist/modules/mcp/resources/workflows/elements.js +0 -53
- package/dist/modules/mcp/resources/workflows/segments.js +0 -55
- package/dist/modules/mcp/resources/workflows/styles.js +0 -91
- package/dist/modules/mcp/tools/collections/createCollection.js +0 -25
- package/dist/modules/mcp/tools/collections/createCollectionRecord.js +0 -27
- package/dist/modules/mcp/tools/collections/deleteCollection.js +0 -16
- package/dist/modules/mcp/tools/collections/deleteCollectionRecord.js +0 -16
- package/dist/modules/mcp/tools/collections/getCollection.js +0 -21
- package/dist/modules/mcp/tools/collections/getCollectionRecord.js +0 -25
- package/dist/modules/mcp/tools/collections/getCollectionRecords.js +0 -29
- package/dist/modules/mcp/tools/collections/getCollections.js +0 -19
- package/dist/modules/mcp/tools/collections/updateCollection.js +0 -28
- package/dist/modules/mcp/tools/collections/updateCollectionRecord.js +0 -31
- package/dist/modules/mcp/tools/docs/listResources.js +0 -16
- package/dist/modules/mcp/tools/docs/readResource.js +0 -23
- package/dist/modules/mcp/tools/plugins/addPlugin.js +0 -24
- package/dist/modules/mcp/tools/plugins/listPlugins.js +0 -20
- package/dist/modules/mcp/tools/plugins/removePlugin.js +0 -16
- package/dist/modules/mcp/tools/plugins/updatePlugin.js +0 -23
- package/dist/modules/mcp/tools/resources/addResource.js +0 -33
- package/dist/modules/mcp/tools/resources/getResource.js +0 -29
- package/dist/modules/mcp/tools/resources/getResources.js +0 -27
- package/dist/modules/mcp/tools/resources/moveResource.js +0 -30
- package/dist/modules/mcp/tools/resources/removeResource.js +0 -19
- package/dist/modules/mcp/tools/segment/createSegment.js +0 -27
- package/dist/modules/mcp/tools/segment/deleteSegment.js +0 -16
- package/dist/modules/mcp/tools/segment/getSegment.js +0 -19
- package/dist/modules/mcp/tools/segment/getSegments.js +0 -27
- package/dist/modules/mcp/tools/segment/schema/elements/createSegmentElement.js +0 -24
- package/dist/modules/mcp/tools/segment/schema/elements/deleteSegmentElement.js +0 -19
- package/dist/modules/mcp/tools/segment/schema/elements/moveSegmentElement.js +0 -28
- package/dist/modules/mcp/tools/segment/schema/elements/updateSegmentElement.js +0 -23
- package/dist/modules/mcp/tools/segment/schema/variables/createSegmentVariable.js +0 -41
- package/dist/modules/mcp/tools/segment/schema/variables/deleteSegmentVariable.js +0 -19
- package/dist/modules/mcp/tools/segment/schema/variables/updateSegmentVariable.js +0 -41
- package/dist/modules/mcp/tools/segment/style/variables/createSegmentStyleVariable.js +0 -34
- package/dist/modules/mcp/tools/segment/style/variables/deleteSegmentStyleVariable.js +0 -21
- package/dist/modules/mcp/tools/segment/style/variables/updateSegmentStyleVariable.js +0 -34
- package/dist/modules/mcp/tools/segment/updateSegment.js +0 -30
- package/dist/modules/mcp/tools/space/schema/applyPreview.js +0 -33
- package/dist/modules/mcp/tools/space/schema/elements/cloneElement.js +0 -34
- package/dist/modules/mcp/tools/space/schema/elements/createElement.js +0 -50
- package/dist/modules/mcp/tools/space/schema/elements/deleteElement.js +0 -16
- package/dist/modules/mcp/tools/space/schema/elements/getElement.js +0 -17
- package/dist/modules/mcp/tools/space/schema/elements/getElements.js +0 -21
- package/dist/modules/mcp/tools/space/schema/elements/listElements.js +0 -28
- package/dist/modules/mcp/tools/space/schema/elements/moveElement.js +0 -27
- package/dist/modules/mcp/tools/space/schema/elements/updateElement.js +0 -49
- package/dist/modules/mcp/tools/space/schema/getSpaceSettings.js +0 -46
- package/dist/modules/mcp/tools/space/schema/pageFolders/createPageFolder.js +0 -24
- package/dist/modules/mcp/tools/space/schema/pageFolders/deletePageFolder.js +0 -16
- package/dist/modules/mcp/tools/space/schema/pageFolders/getPageFolder.js +0 -17
- package/dist/modules/mcp/tools/space/schema/pageFolders/getPageFolders.js +0 -17
- package/dist/modules/mcp/tools/space/schema/pageFolders/updatePageFolder.js +0 -28
- package/dist/modules/mcp/tools/space/schema/pages/createPage.js +0 -37
- package/dist/modules/mcp/tools/space/schema/pages/deletePage.js +0 -16
- package/dist/modules/mcp/tools/space/schema/pages/getPage.js +0 -28
- package/dist/modules/mcp/tools/space/schema/pages/getPageBySlug.js +0 -17
- package/dist/modules/mcp/tools/space/schema/pages/getPages.js +0 -17
- package/dist/modules/mcp/tools/space/schema/pages/updatePage.js +0 -25
- package/dist/modules/mcp/tools/space/schema/schemas.js +0 -53
- package/dist/modules/mcp/tools/space/schema/updateSpaceSettings.js +0 -23
- package/dist/modules/mcp/tools/space/schema/variables/createVariable.js +0 -38
- package/dist/modules/mcp/tools/space/schema/variables/deleteVariable.js +0 -16
- package/dist/modules/mcp/tools/space/schema/variables/getVariable.js +0 -17
- package/dist/modules/mcp/tools/space/schema/variables/getVariables.js +0 -17
- package/dist/modules/mcp/tools/space/schema/variables/updateVariable.js +0 -38
- package/dist/modules/mcp/tools/space/style/selectors/createStyleSelector.js +0 -37
- package/dist/modules/mcp/tools/space/style/selectors/deleteStyleSelector.js +0 -24
- package/dist/modules/mcp/tools/space/style/selectors/getStyleSelectors.js +0 -20
- package/dist/modules/mcp/tools/space/style/selectors/updateStyleSelector.js +0 -37
- package/dist/modules/mcp/tools/space/style/variables/createStyleVariable.js +0 -33
- package/dist/modules/mcp/tools/space/style/variables/deleteStyleVariable.js +0 -20
- package/dist/modules/mcp/tools/space/style/variables/getStyleVariable.js +0 -19
- package/dist/modules/mcp/tools/space/style/variables/getStyleVariables.js +0 -16
- package/dist/modules/mcp/tools/space/style/variables/updateStyleVariable.js +0 -33
- package/dist/package.js +0 -77
- package/dist/package.json.d.ts +0 -67
- package/dist/src/core/requestHandler.d.ts +0 -5
- package/dist/src/modules/mcp/helpers.d.ts +0 -9
- package/dist/src/modules/mcp/resources/glossary/binding.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/collection.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/displayMode.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/element.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/environment.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/interaction.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/page.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/plugin.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/resource.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/schema.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/schemaVariable.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/segment.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/space.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/style.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/styleSelector.d.ts +0 -7
- package/dist/src/modules/mcp/resources/glossary/styleVariable.d.ts +0 -7
- package/dist/src/modules/mcp/resources/workflows/data.d.ts +0 -7
- package/dist/src/modules/mcp/resources/workflows/elements.d.ts +0 -7
- package/dist/src/modules/mcp/resources/workflows/segments.d.ts +0 -7
- package/dist/src/modules/mcp/resources/workflows/styles.d.ts +0 -7
- package/dist/src/modules/mcp/tools/collections/createCollection.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/createCollectionRecord.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/deleteCollection.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/deleteCollectionRecord.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/getCollection.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/getCollectionRecord.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/getCollectionRecords.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/getCollections.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/index.d.ts +0 -10
- package/dist/src/modules/mcp/tools/collections/updateCollection.d.ts +0 -3
- package/dist/src/modules/mcp/tools/collections/updateCollectionRecord.d.ts +0 -3
- package/dist/src/modules/mcp/tools/docs/index.d.ts +0 -2
- package/dist/src/modules/mcp/tools/docs/listResources.d.ts +0 -3
- package/dist/src/modules/mcp/tools/docs/readResource.d.ts +0 -3
- package/dist/src/modules/mcp/tools/plugins/addPlugin.d.ts +0 -3
- package/dist/src/modules/mcp/tools/plugins/index.d.ts +0 -5
- package/dist/src/modules/mcp/tools/plugins/listPlugins.d.ts +0 -3
- package/dist/src/modules/mcp/tools/plugins/removePlugin.d.ts +0 -3
- package/dist/src/modules/mcp/tools/plugins/updatePlugin.d.ts +0 -3
- package/dist/src/modules/mcp/tools/resources/addResource.d.ts +0 -3
- package/dist/src/modules/mcp/tools/resources/getResource.d.ts +0 -3
- package/dist/src/modules/mcp/tools/resources/getResources.d.ts +0 -3
- package/dist/src/modules/mcp/tools/resources/index.d.ts +0 -6
- package/dist/src/modules/mcp/tools/resources/moveResource.d.ts +0 -3
- package/dist/src/modules/mcp/tools/resources/removeResource.d.ts +0 -3
- package/dist/src/modules/mcp/tools/resources/resources.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/segment/createSegment.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/deleteSegment.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/getSegment.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/getSegments.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/index.d.ts +0 -8
- package/dist/src/modules/mcp/tools/segment/schema/elements/createSegmentElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/schema/elements/deleteSegmentElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/schema/elements/index.d.ts +0 -5
- package/dist/src/modules/mcp/tools/segment/schema/elements/moveSegmentElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/schema/elements/segmentElements.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/segment/schema/elements/updateSegmentElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/schema/index.d.ts +0 -2
- package/dist/src/modules/mcp/tools/segment/schema/variables/createSegmentVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/schema/variables/deleteSegmentVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/schema/variables/index.d.ts +0 -4
- package/dist/src/modules/mcp/tools/segment/schema/variables/segmentVariables.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/segment/schema/variables/updateSegmentVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/segment.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/segment/style/index.d.ts +0 -1
- package/dist/src/modules/mcp/tools/segment/style/variables/createSegmentStyleVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/style/variables/deleteSegmentStyleVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/style/variables/index.d.ts +0 -4
- package/dist/src/modules/mcp/tools/segment/style/variables/segmentStyleVariables.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/segment/style/variables/updateSegmentStyleVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/segment/updateSegment.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/index.d.ts +0 -2
- package/dist/src/modules/mcp/tools/space/schema/applyPreview.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/cloneElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/createElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/deleteElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/elements.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/space/schema/elements/getElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/getElements.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/index.d.ts +0 -9
- package/dist/src/modules/mcp/tools/space/schema/elements/listElements.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/moveElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/elements/updateElement.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/getSpaceSettings.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/index.d.ts +0 -8
- package/dist/src/modules/mcp/tools/space/schema/pageFolders/createPageFolder.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pageFolders/deletePageFolder.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pageFolders/getPageFolder.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pageFolders/getPageFolders.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pageFolders/index.d.ts +0 -6
- package/dist/src/modules/mcp/tools/space/schema/pageFolders/pageFolders.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/space/schema/pageFolders/updatePageFolder.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pages/createPage.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pages/deletePage.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pages/getPage.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pages/getPageBySlug.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pages/getPages.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/pages/index.d.ts +0 -7
- package/dist/src/modules/mcp/tools/space/schema/pages/pages.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/space/schema/pages/updatePage.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/schemas.d.ts +0 -66
- package/dist/src/modules/mcp/tools/space/schema/updateSpaceSettings.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/variables/createVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/variables/deleteVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/variables/getVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/variables/getVariables.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/variables/index.d.ts +0 -6
- package/dist/src/modules/mcp/tools/space/schema/variables/updateVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/schema/variables/variables.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/space/space.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/space/style/index.d.ts +0 -2
- package/dist/src/modules/mcp/tools/space/style/selectors/createStyleSelector.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/selectors/deleteStyleSelector.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/selectors/getStyleSelectors.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/selectors/index.d.ts +0 -5
- package/dist/src/modules/mcp/tools/space/style/selectors/styleSelectors.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/space/style/selectors/updateStyleSelector.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/variables/createStyleVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/variables/deleteStyleVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/variables/getStyleVariable.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/variables/getStyleVariables.d.ts +0 -3
- package/dist/src/modules/mcp/tools/space/style/variables/index.d.ts +0 -6
- package/dist/src/modules/mcp/tools/space/style/variables/styleVariables.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/space/style/variables/updateStyleVariable.d.ts +0 -3
- /package/dist/src/{modules/mcp/helpers.test.d.ts → core/server/mcpServer.test.d.ts} +0 -0
- /package/dist/src/modules/{mcp/tools/collections/collections.test.d.ts → ai/toolkit.test.d.ts} +0 -0
- /package/dist/src/modules/mcp/{tools/plugins/plugins.test.d.ts → mcp.test.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { operation } from "./modules/mcp/tools/operations/index.js";
|
|
2
|
+
import { apply, applyShape } from "./modules/mcp/tools/apply/index.js";
|
|
3
|
+
import { read, readShape } from "./modules/mcp/tools/read.js";
|
|
4
|
+
import { search, searchShape } from "./modules/mcp/tools/search.js";
|
|
5
|
+
import { validate, validateShape } from "./modules/mcp/tools/validate.js";
|
|
6
|
+
import { tools } from "./modules/mcp/tools/index.js";
|
|
7
|
+
import { bindTools, getAllowedModes, isCallToolResult, isToolActive, resolveToolHandler, toolResponseErr, toolResponseFromResult, toolResponseOk, zodToJsonSchema } from "./modules/ai/toolkit.js";
|
|
3
8
|
import { createMcpServer } from "./modules/mcp/server.js";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
9
|
+
import { handleMcp, readMcpBody, serveMcp } from "./modules/mcp/handler.js";
|
|
10
|
+
import { createHttpPreviewClient } from "./modules/mcp/previewClient.js";
|
|
11
|
+
import { PREVIEW_TOKEN_PARAM } from "./modules/mcp/constants.js";
|
|
12
|
+
import { createHttpScreenshotClient } from "./modules/mcp/screenshotClient.js";
|
|
13
|
+
import { createMemoryDraftStore, createPreview } from "./modules/ssr/preview.js";
|
|
14
|
+
import { buildHealthPayload, registerHealthCheck } from "./core/health.js";
|
|
15
|
+
import { createMCPServer } from "./core/server/mcpServer.js";
|
|
16
|
+
import { resolveServices } from "./core/services/resolve.js";
|
|
17
|
+
import { createSSRServer } from "./core/server/ssrServer.js";
|
|
18
|
+
import { createServer } from "./core/createServer.js";
|
|
7
19
|
import { createJsonAdapters } from "./adapters/jsonAdapters.js";
|
|
8
|
-
|
|
20
|
+
import AIEngine from "./modules/ai/AIEngine.js";
|
|
21
|
+
export { AIEngine, PREVIEW_TOKEN_PARAM, apply, applyShape, bindTools, buildHealthPayload, createHttpPreviewClient, createHttpScreenshotClient, createJsonAdapters, createMCPServer, createMcpServer, createMemoryDraftStore, createPreview, createSSRServer, createServer, getAllowedModes, handleMcp, isCallToolResult, isToolActive, operation, read, readMcpBody, readShape, registerHealthCheck, resolveServices, resolveToolHandler, search, searchShape, serveMcp, toolResponseErr, toolResponseFromResult, toolResponseOk, tools, validate, validateShape, zodToJsonSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toolResponseErr } from "
|
|
1
|
+
import { firstText, toolResponseErr } from "./toolkit.js";
|
|
2
2
|
//#region src/modules/ai/AIEngine.ts
|
|
3
3
|
var AIEngine = class {
|
|
4
4
|
mode;
|
|
@@ -44,12 +44,12 @@ var AIEngine = class {
|
|
|
44
44
|
let resultParsed;
|
|
45
45
|
if (result.data !== void 0) resultParsed = result.data;
|
|
46
46
|
else try {
|
|
47
|
-
resultParsed = JSON.parse(result.content
|
|
47
|
+
resultParsed = JSON.parse(firstText(result.content) ?? "");
|
|
48
48
|
} catch {}
|
|
49
49
|
if (result.isError) this.callbacks.onToolError?.({
|
|
50
50
|
name,
|
|
51
51
|
args,
|
|
52
|
-
result: resultParsed ?? { error: result.content
|
|
52
|
+
result: resultParsed ?? { error: firstText(result.content) ?? "Tool failed" }
|
|
53
53
|
});
|
|
54
54
|
else this.callbacks.onToolSuccess?.({
|
|
55
55
|
name,
|
|
@@ -96,7 +96,7 @@ var AIEngine = class {
|
|
|
96
96
|
if (outputError) this.callbacks.onLog?.("info", `tool output schema drift: ${name} — ${outputError}`);
|
|
97
97
|
const tool = this.toolsAvailables.get(name);
|
|
98
98
|
if (!result.isError && tool?.mcpDefinition.outputSchema && result.data !== void 0 && result.data !== null) result.structuredContent = typeof result.data === "object" && !Array.isArray(result.data) ? result.data : { data: result.data };
|
|
99
|
-
if (result.isError) this.callbacks.onLog?.("error", `tool failed: ${name} error=${result.content
|
|
99
|
+
if (result.isError) this.callbacks.onLog?.("error", `tool failed: ${name} error=${firstText(result.content) ?? "unknown"}`);
|
|
100
100
|
await this.after(name, args, result);
|
|
101
101
|
return result;
|
|
102
102
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/modules/ai/toolkit.ts
|
|
3
|
+
/** Convert a Zod schema to the JSON Schema an AI provider (Anthropic / OpenAI) expects in a tool definition.
|
|
4
|
+
* Delegates to Zod v4's built-in converter — one implementation, so descriptions, literal discriminators,
|
|
5
|
+
* enums, nested objects and recursive (z.lazy) shapes all survive and the provider sees the same contract an
|
|
6
|
+
* MCP client does. `io: 'input'` describes what the agent must SEND; `unrepresentable: 'any'` degrades an
|
|
7
|
+
* exotic type to an empty schema instead of throwing, so one unusual tool never breaks the whole tool list. */
|
|
8
|
+
var zodToJsonSchema = (schema) => {
|
|
9
|
+
const json = z.toJSONSchema(schema, {
|
|
10
|
+
target: "draft-7",
|
|
11
|
+
io: "input",
|
|
12
|
+
unrepresentable: "any"
|
|
13
|
+
});
|
|
14
|
+
delete json.$schema;
|
|
15
|
+
return json;
|
|
16
|
+
};
|
|
17
|
+
var firstText = (content) => content.find((block) => block.type === "text")?.text;
|
|
18
|
+
var getAllowedModes = (operationType) => {
|
|
19
|
+
return operationType === "write" ? ["build"] : ["plan", "build"];
|
|
20
|
+
};
|
|
21
|
+
var toolResponseOk = (data, agentMessage) => {
|
|
22
|
+
return {
|
|
23
|
+
content: [{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: agentMessage ?? JSON.stringify(data ?? null, null, 2)
|
|
26
|
+
}],
|
|
27
|
+
data
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var toolResponseErr = (error) => ({
|
|
31
|
+
content: [{
|
|
32
|
+
type: "text",
|
|
33
|
+
text: error instanceof Error ? error.message : error
|
|
34
|
+
}],
|
|
35
|
+
isError: true
|
|
36
|
+
});
|
|
37
|
+
var isCallToolResult = (result) => typeof result === "object" && result !== null && Array.isArray(result.content);
|
|
38
|
+
var toolResponseFromResult = (result) => {
|
|
39
|
+
const content = [];
|
|
40
|
+
for (const block of result.content) if (block.type === "text") content.push({
|
|
41
|
+
type: "text",
|
|
42
|
+
text: block.text
|
|
43
|
+
});
|
|
44
|
+
else if (block.type === "image") content.push({
|
|
45
|
+
type: "image",
|
|
46
|
+
data: block.data,
|
|
47
|
+
mimeType: block.mimeType
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
content,
|
|
51
|
+
isError: result.isError ? true : void 0
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
var isToolActive = (tool) => Boolean(tool.handler);
|
|
55
|
+
var resolveToolHandler = (tool) => tool.handler;
|
|
56
|
+
var bindTools = (tools) => tools.filter(isToolActive);
|
|
57
|
+
//#endregion
|
|
58
|
+
export { bindTools, firstText, getAllowedModes, isCallToolResult, isToolActive, resolveToolHandler, toolResponseErr, toolResponseFromResult, toolResponseOk, zodToJsonSchema };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createMcpServer } from "./server.js";
|
|
2
|
-
import AIEngine from "../ai/AIEngine.js";
|
|
3
2
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp";
|
|
4
3
|
//#region src/modules/mcp/handler.ts
|
|
5
4
|
var readMcpBody = (req) => new Promise((resolve, reject) => {
|
|
@@ -16,38 +15,33 @@ var readMcpBody = (req) => new Promise((resolve, reject) => {
|
|
|
16
15
|
});
|
|
17
16
|
req.on("error", reject);
|
|
18
17
|
});
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
const ctx = context ?? {
|
|
22
|
-
userId: 0,
|
|
23
|
-
spaceId: 0,
|
|
24
|
-
environment: "main",
|
|
25
|
-
mode: "plan"
|
|
26
|
-
};
|
|
27
|
-
const engine = new AIEngine(ctx.mode, {}, ctx);
|
|
28
|
-
server = createMcpServer(config.adapters, engine, config.tools, config.prompts);
|
|
29
|
-
}
|
|
30
|
-
if (!transport) transport = new StreamableHTTPServerTransport({
|
|
18
|
+
var serveMcp = async (raw, res, server) => {
|
|
19
|
+
const transport = new StreamableHTTPServerTransport({
|
|
31
20
|
sessionIdGenerator: void 0,
|
|
32
21
|
enableJsonResponse: true
|
|
33
22
|
});
|
|
34
23
|
await server.connect(transport);
|
|
35
24
|
try {
|
|
36
|
-
if (
|
|
37
|
-
let body;
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
body = await readMcpBody(req);
|
|
25
|
+
if (raw.method === "POST") {
|
|
26
|
+
let body = raw.body;
|
|
27
|
+
if (body === void 0) try {
|
|
28
|
+
body = await readMcpBody(raw);
|
|
41
29
|
} catch {
|
|
42
30
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
43
31
|
res.end(JSON.stringify({ error: "Invalid JSON body" }));
|
|
44
32
|
return;
|
|
45
33
|
}
|
|
46
|
-
await transport.handleRequest(
|
|
47
|
-
} else await transport.handleRequest(
|
|
34
|
+
await transport.handleRequest(raw, res, body);
|
|
35
|
+
} else await transport.handleRequest(raw, res);
|
|
48
36
|
} finally {
|
|
49
37
|
await transport.close();
|
|
50
38
|
}
|
|
51
39
|
};
|
|
40
|
+
var handleMcp = (raw, res, req, adapters, preview, screenshot) => serveMcp(raw, res, createMcpServer({
|
|
41
|
+
adapters,
|
|
42
|
+
getSpaceId: () => adapters.getSpaceId?.(req) ?? Promise.resolve(void 0),
|
|
43
|
+
preview,
|
|
44
|
+
screenshot
|
|
45
|
+
}));
|
|
52
46
|
//#endregion
|
|
53
|
-
export { handleMcp, readMcpBody };
|
|
47
|
+
export { createMcpServer, handleMcp, readMcpBody, serveMcp };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
//#region src/modules/mcp/helpers/computeVersion.ts
|
|
3
|
+
var canonicalize = (data) => {
|
|
4
|
+
if (data === null || data === void 0) return "null";
|
|
5
|
+
if (typeof data === "string") return JSON.stringify(data);
|
|
6
|
+
if (typeof data === "number" || typeof data === "boolean") return String(data);
|
|
7
|
+
if (Array.isArray(data)) return `[${data.map(canonicalize).join(",")}]`;
|
|
8
|
+
if (typeof data === "bigint") return data.toString();
|
|
9
|
+
if (typeof data === "object") return `{${Object.keys(data).sort().map((k) => `${canonicalize(k)}:${canonicalize(data[k])}`).join(",")}}`;
|
|
10
|
+
return "null";
|
|
11
|
+
};
|
|
12
|
+
var computeVersion = (data) => {
|
|
13
|
+
return createHash("sha1").update(canonicalize(data)).digest("hex").slice(0, 12);
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { computeVersion };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/modules/mcp/helpers/guide.ts
|
|
2
|
+
var serverInstructions = "Plitzi AI server: read-then-write editing of a Plitzi space. Reads follow a filesystem model — list cheap, read one item in detail on demand; never fetch a whole tree you do not need. Workflow: (1) read plitzi://primer/{env} once — it bundles the guide, types, css-properties and page/definition/variable summaries in a single call; (2) plitzi_search with include:\"detail\" to jump to elements — each hit then carries its uri, stateVersion AND full style/resolvedStyle, so an edit needs no per-element read; open a page skeleton or element only when you need its tree/detail (the skeleton already lists the style classes of each node, and plitzi_read fetches many uris at once); (3) plitzi_apply with dryRun to preview a batch; (4) plitzi_apply to persist, passing expectedResourceVersions to guard against concurrent edits — apply and search both hand back the versions you need for the next edit. Use patchElement / patchDefinition to change only some props / CSS (the upsert variants replace them all). An element read (and search include:\"detail\") inlines the CSS of the definitions it attaches under resolvedStyle, so you rarely need a separate definition read. Refs accept a semantic aiRef or the raw id. CSS is kebab-case (shorthands like border/padding are accepted); style vars are var(--name), schema vars are {{name}}.";
|
|
3
|
+
var guideText = `# Plitzi AI MCP — usage guide
|
|
4
|
+
|
|
5
|
+
A Plitzi space is **two separate schemas** you edit together:
|
|
6
|
+
- **Element schema** — the tree of pages and elements (their type, label, props, and which style classes they use).
|
|
7
|
+
- **Style schema** — reusable **definitions** (CSS classes), design tokens (variables), theme.
|
|
8
|
+
|
|
9
|
+
They are stored and persisted independently, but a single \`plitzi_apply\` batch may touch **both atomically**.
|
|
10
|
+
To style a specific element you do two things in one batch: write a **definition** (style schema) and **attach**
|
|
11
|
+
it via the element's \`style.base\` (element schema). Example — "rename button X to PEPE and make it red":
|
|
12
|
+
\`\`\`json
|
|
13
|
+
{ "operations": [
|
|
14
|
+
{ "type": "upsertDefinition", "ref": "btn-x", "desktop": { "color": "red" } },
|
|
15
|
+
{ "type": "upsertElement", "pageRef": "home",
|
|
16
|
+
"element": { "ref": "X", "type": "button", "label": "PEPE", "style": { "base": ["btn-x"] } } }
|
|
17
|
+
] }
|
|
18
|
+
\`\`\`
|
|
19
|
+
|
|
20
|
+
Reads are cheap by design — treat them like a filesystem: **list** to navigate, **read one item** for detail.
|
|
21
|
+
Never download a whole tree you do not need.
|
|
22
|
+
|
|
23
|
+
## Resources (read)
|
|
24
|
+
- \`plitzi://primer/{env}\` — **cold-start bundle**: guide + types + css-properties + page/definition/variable
|
|
25
|
+
**summaries** in one read. Fetch this first instead of the individual resources below. Summaries only — open a
|
|
26
|
+
page skeleton or element for its tree/detail.
|
|
27
|
+
- \`plitzi://guide\` — this guide.
|
|
28
|
+
- \`plitzi://types\` — element types **observed in this space** (ground truth): props, slots, subTypes.
|
|
29
|
+
- \`plitzi://css-properties\` — valid kebab-case CSS property keys.
|
|
30
|
+
- \`plitzi://schema/{env}/pages\` — page **summaries** (ref, label, elementCount, folder). No element trees.
|
|
31
|
+
- \`plitzi://folders/{env}\` — page **folders** (the sidebar tree): ref, name, slug, parentId. \`/{ref}\` for one.
|
|
32
|
+
- \`plitzi://schema/{env}/pages/{ref}\` — one page as a **skeleton tree**: each node is \`ref/type/label\` **plus the
|
|
33
|
+
style classes it attaches** (\`base\`, and \`slots\` for non-base slots) — names only, no CSS. So you can map every
|
|
34
|
+
element to its class in a single page read, without opening each element just to learn which class it uses.
|
|
35
|
+
- \`plitzi://schema/{env}/pages/{ref}/styles\` — **every style the page uses in one read**: the class definitions its
|
|
36
|
+
elements attach (deduplicated, **with full CSS**) plus the global styles affecting any element type on the page.
|
|
37
|
+
Reach for this to recolor/restyle a whole page — it needs no shared class-name prefix and no per-element reads.
|
|
38
|
+
- \`plitzi://schema/{env}/elements/{ref}\` — one element in **full detail** (props, style, parentRef, childRefs).
|
|
39
|
+
Its \`resolvedStyle\` inlines the **CSS of every definition** the element attaches (keyed by class ref), so you
|
|
40
|
+
can see and edit its style without a separate definition read. Its \`globalStyles\` lists the **global element
|
|
41
|
+
selectors** that also affect it (the CSS equivalent of \`button { … }\`, keyed by the type they target) — every
|
|
42
|
+
element of that type inherits them. Edit a global only through the global-style tools (never per element).
|
|
43
|
+
- \`plitzi://definitions/{env}\` — the **names** of every style definition.
|
|
44
|
+
- \`plitzi://definitions/{env}/{ref}\` — one definition's CSS.
|
|
45
|
+
- \`plitzi://global-styles/{env}\` — element **types** that have a site-wide global style. \`/{componentType}\` for one.
|
|
46
|
+
- \`plitzi://style-variables/{env}\` — design tokens by category. \`/{category}\` for one.
|
|
47
|
+
- \`plitzi://schema-variables/{env}\` — space-level values referenced in props as \`{{name}}\`.
|
|
48
|
+
|
|
49
|
+
The style resources also answer under the \`plitzi://schema/{env}/…\` root as aliases — \`plitzi://schema/{env}/definitions/{ref}\`, \`plitzi://schema/{env}/style-variables/{category}\`, \`plitzi://schema/{env}/schema-variables\` — but prefer the ready-made \`uri\` from search / a write response over hand-building either form.
|
|
50
|
+
|
|
51
|
+
Data resources return \`{ stateVersion, data }\`. Keep \`stateVersion\` for optimistic concurrency.
|
|
52
|
+
|
|
53
|
+
## Navigating (files analogy)
|
|
54
|
+
Pages and containers are folders; elements are files. **Prefer \`plitzi_search\` (especially with \`include: "detail"\`)
|
|
55
|
+
over reading elements one by one** — it jumps straight to elements by label/type/attribute and each hit already
|
|
56
|
+
carries the element's \`uri\`, \`stateVersion\`, \`pageUri\`, \`parentRef\` and tree \`path\`, so you can edit it (with
|
|
57
|
+
optimistic concurrency) **without a follow-up read**. \`include: "detail"\` additionally inlines each hit's props/style
|
|
58
|
+
**and** its \`resolvedStyle\` (the CSS behind its classes) — so a search-then-edit is the efficient path and a manual
|
|
59
|
+
element read is the exception. Search also matches **pages** by name/slug (returned under \`pages\`, each with its uri +
|
|
60
|
+
stateVersion) and returns any **style definitions** whose name matches the query, with full CSS, under \`definitions\`.
|
|
61
|
+
When you do hold several refs to open (e.g. from a skeleton), read them together with \`plitzi_read\` rather than one at a time.
|
|
62
|
+
|
|
63
|
+
## Tools (write)
|
|
64
|
+
- \`plitzi_validate\` — check a batch, returns teachable errors/warnings. Writes nothing.
|
|
65
|
+
- \`plitzi_apply\` — validate → apply → persist atomically. Rejects the whole batch on any error or conflict. Pass
|
|
66
|
+
\`dryRun: true\` to apply in memory only and get the same result back (changed versions + full element detail)
|
|
67
|
+
without persisting — inspect it, then re-run without \`dryRun\` to commit.
|
|
68
|
+
- \`plitzi_search\` — find elements (and pages/definitions) across the space.
|
|
69
|
+
- \`plitzi_read\` — read many resource **uris in one batch** (pages, elements, definitions, variables). Pass the
|
|
70
|
+
ready-made uris from search / a write response; each result is \`{ uri, stateVersion, data }\` or a teachable error,
|
|
71
|
+
so one bad uri never fails the batch. Use it instead of N single reads whenever you already hold several refs.
|
|
72
|
+
|
|
73
|
+
Write tools return what **changed** (\`{ uri, stateVersion }\`) plus counts, and the **full detail of every element
|
|
74
|
+
they created or updated** — each with its own \`uri\` and \`stateVersion\` (\`elements: [...]\`) so a follow-up edit of
|
|
75
|
+
the same element needs **no intermediate read**. Other resources (pages, definitions, variables) still report only
|
|
76
|
+
uri+stateVersion — re-read them if you need their new content. The operation shapes are in each tool's input
|
|
77
|
+
schema (discriminated by \`type\`).
|
|
78
|
+
|
|
79
|
+
## Addressing
|
|
80
|
+
Refs are a semantic \`aiRef\` you choose (e.g. \`"hero.cta"\`) or the element's **raw id**. Both always resolve, so
|
|
81
|
+
schemas predating aiRef keep working through ids. Creating an element stores its \`ref\` as the aiRef.
|
|
82
|
+
|
|
83
|
+
## Styling (crosses both schemas)
|
|
84
|
+
- A definition lives in the **style schema**; an element's \`style.base\` (element schema) is the link that applies
|
|
85
|
+
it. Styling an element = upsertDefinition + upsertElement with that ref in \`style.base\`, in one batch.
|
|
86
|
+
- CSS keys are **kebab-case** (\`background-color\`). camelCase is rejected — read \`plitzi://css-properties\`.
|
|
87
|
+
- Common **shorthands are accepted** and expanded for you: \`border\`, \`border-{side}\`, \`border-radius\`,
|
|
88
|
+
\`padding\`, \`margin\`, \`inset\`, \`gap\` (they persist as their longhand keys).
|
|
89
|
+
- CSS is grouped by breakpoint: \`desktop\`, \`tablet\`, \`mobile\`.
|
|
90
|
+
- Reference a style variable in CSS as \`var(--name)\`; a schema variable in a prop as \`{{name}}\`.
|
|
91
|
+
- \`element.style.base\` is a list of definition refs; other slots go under \`element.style.slots\`.
|
|
92
|
+
- **Two kinds of style live in the style schema — do not confuse them:**
|
|
93
|
+
- **Definitions** = reusable CSS **classes** (\`upsertDefinition\`/\`patchDefinition\`/\`deleteDefinition\`, keyed by a
|
|
94
|
+
class \`ref\`). Attach one to an element via \`style.base\` to style **that** element (and anything else that opts in).
|
|
95
|
+
- **Global styles** = the CSS equivalent of a bare element selector like \`button { … }\`
|
|
96
|
+
(\`upsertGlobalStyle\`/\`patchGlobalStyle\`/\`deleteGlobalStyle\`, keyed by \`componentType\`). They style **every**
|
|
97
|
+
element of that type at once. Use these for site-wide intent — e.g. "all buttons rounded":
|
|
98
|
+
\`{ "type": "upsertGlobalStyle", "componentType": "button", "desktop": { "border-radius": "9999px" } }\`.
|
|
99
|
+
- The two share one name space, so a class op refuses a name held by a global and vice-versa (guards against a
|
|
100
|
+
typo silently rewriting every element of a type). If refused, you targeted the wrong kind — switch tools or
|
|
101
|
+
rename. To style one element only, never reach for a global.
|
|
102
|
+
|
|
103
|
+
## Pages & folders
|
|
104
|
+
Pages can be grouped into **folders** (the sidebar tree). A folder is \`{ ref, name, slug, parentId? }\`; its \`ref\`
|
|
105
|
+
**is its id** (there is no separate aiRef), and that id is what a page and a nested folder reference.
|
|
106
|
+
- Create/rename/move a folder with \`upsertFolder\` (the \`ref\` you pass on create becomes its id — pick a stable one
|
|
107
|
+
like \`"blog"\`). Nest it under another with \`parentId\` (a folder ref); \`parentId: null\` moves it back to the root.
|
|
108
|
+
- Put a page in a folder with \`upsertPage\`'s \`folder\` (a folder ref). A page's \`folder\` is always either **empty
|
|
109
|
+
(root)** or an **existing folder id**: \`folder: null\` or \`folder: ""\` moves it to the root, and any other value
|
|
110
|
+
must resolve to a folder that already exists or is created earlier in the same batch — an unknown folder is
|
|
111
|
+
rejected, never stored.
|
|
112
|
+
- \`deleteFolder\` removes a folder and **promotes its contents up one level** — its child folders and its pages move
|
|
113
|
+
to its parent (or the root). A folder cannot be nested under itself or one of its descendants.
|
|
114
|
+
|
|
115
|
+
## Semantics
|
|
116
|
+
- **props are fully replaced** on \`upsertElement\`: send every prop you want to keep. To change only some props,
|
|
117
|
+
use **\`patchElement\`** — it merges \`props\`/\`style\` onto the existing element (listed keys change, \`null\` unsets
|
|
118
|
+
a key, everything else is preserved) and never creates. Combined with \`plitzi_search\` (which returns the ref +
|
|
119
|
+
stateVersion), a targeted edit is two calls with no read.
|
|
120
|
+
- **definition CSS is fully replaced** on \`upsertDefinition\`: send every property you want to keep. To change only
|
|
121
|
+
some declarations, use **\`patchDefinition\`** — it merges CSS per breakpoint/state/variant/slot onto the existing
|
|
122
|
+
definition (listed keys change, \`null\` removes a property, everything else is preserved) and never creates.
|
|
123
|
+
Example — recolor one definition without resending it: \`{ "type": "patchDefinition", "ref": "btn-x",
|
|
124
|
+
"desktop": { "background-color": "#111" } }\`.
|
|
125
|
+
- **Atomic batches**: if any operation fails, \`plitzi_apply\` persists nothing.
|
|
126
|
+
- **Optimistic concurrency**: pass \`expectedResourceVersions\` (URI → the stateVersion you read). If the live data
|
|
127
|
+
drifted, apply is rejected with a conflict; re-read the reported resources and retry.
|
|
128
|
+
`;
|
|
129
|
+
//#endregion
|
|
130
|
+
export { guideText, serverInstructions };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/modules/mcp/helpers/opResult.ts
|
|
2
|
+
var empty = () => ({
|
|
3
|
+
created: 0,
|
|
4
|
+
updated: 0,
|
|
5
|
+
deleted: 0,
|
|
6
|
+
staleResources: []
|
|
7
|
+
});
|
|
8
|
+
var fail = (path, message, hint, validValues) => ({
|
|
9
|
+
...empty(),
|
|
10
|
+
errors: [{
|
|
11
|
+
path,
|
|
12
|
+
message,
|
|
13
|
+
hint,
|
|
14
|
+
validValues
|
|
15
|
+
}]
|
|
16
|
+
});
|
|
17
|
+
//#endregion
|
|
18
|
+
export { empty, fail };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
//#region src/modules/mcp/helpers/space.ts
|
|
2
|
+
var cloneSpace = (space) => structuredClone(space);
|
|
3
|
+
var slugify = (value) => value.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "";
|
|
4
|
+
var isPageElement = (schema, el) => schema.pages.includes(el.id) || el.definition.type === "page";
|
|
5
|
+
var getPageElements = (schema) => Object.values(schema.flat).filter((el) => isPageElement(schema, el));
|
|
6
|
+
/** Stable, human-readable ref for a page. Prefers an agent-chosen aiRef, then slug, then a slugified label. */
|
|
7
|
+
var pageRefOf = (el) => {
|
|
8
|
+
if (el.definition.aiRef) return el.definition.aiRef;
|
|
9
|
+
const slug = typeof el.attributes.slug === "string" ? el.attributes.slug.trim() : "";
|
|
10
|
+
if (slug) return slugify(slug);
|
|
11
|
+
if (el.attributes.default === true) return "home";
|
|
12
|
+
return slugify(typeof el.attributes.name === "string" ? el.attributes.name : el.definition.label) || el.id;
|
|
13
|
+
};
|
|
14
|
+
/** Stable ref for a non-page element. An agent-chosen aiRef when present, otherwise the opaque id. */
|
|
15
|
+
var elementRefOf = (el) => el.definition.aiRef ?? el.id;
|
|
16
|
+
/** Finds a page by its semantic ref (aiRef/slug/…) or its raw id, so legacy schemas without an aiRef still resolve. */
|
|
17
|
+
var findPageByRef = (schema, pageRef) => getPageElements(schema).find((el) => pageRefOf(el) === pageRef || el.id === pageRef);
|
|
18
|
+
var pageFoldersOf = (schema) => {
|
|
19
|
+
schema.pageFolders ??= [];
|
|
20
|
+
return schema.pageFolders;
|
|
21
|
+
};
|
|
22
|
+
/** Resolve a folder by its id, or (for agent convenience) by an exact name or slug when that is unambiguous. */
|
|
23
|
+
var findFolderByRef = (schema, ref) => {
|
|
24
|
+
const folders = pageFoldersOf(schema);
|
|
25
|
+
const byId = folders.find((f) => f.id === ref);
|
|
26
|
+
if (byId) return byId;
|
|
27
|
+
const byName = folders.filter((f) => f.name === ref);
|
|
28
|
+
if (byName.length === 1) return byName[0];
|
|
29
|
+
const bySlug = folders.filter((f) => f.slug === ref);
|
|
30
|
+
return bySlug.length === 1 ? bySlug[0] : void 0;
|
|
31
|
+
};
|
|
32
|
+
/** Order folders so every parent precedes its children — the invariant the schema validator enforces on
|
|
33
|
+
* pageFolders (a parentId must appear earlier in the array). Cycles (rejected upstream) are left in place. */
|
|
34
|
+
var sortFolders = (folders) => {
|
|
35
|
+
const byId = new Map(folders.map((f) => [f.id, f]));
|
|
36
|
+
const placed = /* @__PURE__ */ new Set();
|
|
37
|
+
const result = [];
|
|
38
|
+
const visit = (folder, ancestry) => {
|
|
39
|
+
if (placed.has(folder.id)) return;
|
|
40
|
+
const parent = folder.parentId ? byId.get(folder.parentId) : void 0;
|
|
41
|
+
if (parent && !ancestry.has(parent.id)) visit(parent, new Set(ancestry).add(folder.id));
|
|
42
|
+
if (!placed.has(folder.id)) {
|
|
43
|
+
placed.add(folder.id);
|
|
44
|
+
result.push(folder);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
for (const folder of folders) visit(folder, /* @__PURE__ */ new Set([folder.id]));
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
/** Ancestor ids of a folder (following parentId), stopping on a cycle. Used to reject a parent change that would
|
|
51
|
+
* make a folder its own ancestor. */
|
|
52
|
+
var folderAncestorIds = (folders, startParentId) => {
|
|
53
|
+
const byId = new Map(folders.map((f) => [f.id, f]));
|
|
54
|
+
const chain = [];
|
|
55
|
+
const seen = /* @__PURE__ */ new Set();
|
|
56
|
+
let current = startParentId ? byId.get(startParentId) : void 0;
|
|
57
|
+
while (current && !seen.has(current.id)) {
|
|
58
|
+
seen.add(current.id);
|
|
59
|
+
chain.push(current.id);
|
|
60
|
+
current = current.parentId ? byId.get(current.parentId) : void 0;
|
|
61
|
+
}
|
|
62
|
+
return chain;
|
|
63
|
+
};
|
|
64
|
+
/** Route params a page's slug binds (e.g. ":spaceId/update/*" → ["spaceId"]). These are valid {{name}}
|
|
65
|
+
* references on that page even though they are not space-level schema variables. */
|
|
66
|
+
var slugRouteParams = (slug) => {
|
|
67
|
+
const params = [];
|
|
68
|
+
for (const segment of slug.split("/")) if (segment.startsWith(":")) params.push(segment.slice(1).replace(/[*+?]+$/, ""));
|
|
69
|
+
return params;
|
|
70
|
+
};
|
|
71
|
+
/** Every route param bound by any page slug in the space (union), so {{name}} validation does not false-flag a
|
|
72
|
+
* page-scoped dynamic binding. */
|
|
73
|
+
var routeParamNames = (schema) => {
|
|
74
|
+
const params = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const page of getPageElements(schema)) {
|
|
76
|
+
const slug = typeof page.attributes.slug === "string" ? page.attributes.slug : "";
|
|
77
|
+
for (const param of slugRouteParams(slug)) params.add(param);
|
|
78
|
+
}
|
|
79
|
+
return [...params];
|
|
80
|
+
};
|
|
81
|
+
/** Indexed lookup that reflects the runtime reality: a flat id may be dangling (rsc placeholders, stale items). */
|
|
82
|
+
var elementById = (schema, id) => schema.flat[id];
|
|
83
|
+
/** All element ids belonging to a page subtree (excluding the page root). */
|
|
84
|
+
var collectDescendants = (schema, rootId, acc) => {
|
|
85
|
+
const el = elementById(schema, rootId);
|
|
86
|
+
if (!el) return;
|
|
87
|
+
const childIds = el.definition.items ?? [];
|
|
88
|
+
for (const childId of childIds) if (elementById(schema, childId)) {
|
|
89
|
+
acc.push(childId);
|
|
90
|
+
collectDescendants(schema, childId, acc);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var descendantIds = (schema, pageRootId) => {
|
|
94
|
+
const acc = [];
|
|
95
|
+
collectDescendants(schema, pageRootId, acc);
|
|
96
|
+
return acc;
|
|
97
|
+
};
|
|
98
|
+
/** Resolve a ref to a concrete element within a page subtree (or the page root itself). Accepts either the
|
|
99
|
+
* semantic ref (aiRef) or the raw element id, so schemas predating aiRef keep working through their ids. */
|
|
100
|
+
var resolveRef = (schema, page, ref) => {
|
|
101
|
+
if (elementRefOf(page) === ref || pageRefOf(page) === ref || page.id === ref) return page;
|
|
102
|
+
for (const id of descendantIds(schema, page.id)) {
|
|
103
|
+
const el = elementById(schema, id);
|
|
104
|
+
if (el && (elementRefOf(el) === ref || el.id === ref)) return el;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/** Ordered children of an element, honoring definition.items and skipping dangling ids. */
|
|
108
|
+
var orderedChildren = (schema, el) => {
|
|
109
|
+
return (el.definition.items ?? []).map((id) => schema.flat[id]).filter((child) => Boolean(child));
|
|
110
|
+
};
|
|
111
|
+
/** The page ref an element belongs to, walking up parents. 'unknown' when it has no page ancestor. */
|
|
112
|
+
var pageRefOfElement = (schema, el) => {
|
|
113
|
+
let current = el;
|
|
114
|
+
const guard = /* @__PURE__ */ new Set();
|
|
115
|
+
while (current && !guard.has(current.id)) {
|
|
116
|
+
guard.add(current.id);
|
|
117
|
+
if (isPageElement(schema, current)) return pageRefOf(current);
|
|
118
|
+
current = current.definition.parentId ? schema.flat[current.definition.parentId] : void 0;
|
|
119
|
+
}
|
|
120
|
+
return "unknown";
|
|
121
|
+
};
|
|
122
|
+
/** Find any non-page element by its semantic ref (aiRef) or raw id, across the whole space. */
|
|
123
|
+
var findElementByRef = (schema, ref) => {
|
|
124
|
+
for (const el of Object.values(schema.flat)) {
|
|
125
|
+
if (isPageElement(schema, el)) continue;
|
|
126
|
+
if (elementRefOf(el) === ref || el.id === ref) return el;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/** Total number of descendant elements under a subtree (excluding the root). */
|
|
130
|
+
var descendantCount = (schema, rootId) => descendantIds(schema, rootId).length;
|
|
131
|
+
var emptySpaceMessage = "Space data not available";
|
|
132
|
+
var unauthorizedSpaceMessage = "This tool/resource needs a space, but no spaceId could be resolved from the Authorization token";
|
|
133
|
+
var generateObjectId = () => {
|
|
134
|
+
return `${Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0")}${Array.from({ length: 16 }, () => Math.floor(Math.random() * 16).toString(16)).join("")}`;
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
export { cloneSpace, descendantCount, descendantIds, elementById, elementRefOf, emptySpaceMessage, findElementByRef, findFolderByRef, findPageByRef, folderAncestorIds, generateObjectId, getPageElements, isPageElement, orderedChildren, pageFoldersOf, pageRefOf, pageRefOfElement, resolveRef, routeParamNames, slugRouteParams, slugify, sortFolders, unauthorizedSpaceMessage };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/modules/mcp/previewClient.ts
|
|
2
|
+
/** Default `PreviewClient`: POSTs the preview request to the SSR `/preview` endpoint over HTTP. Used when the
|
|
3
|
+
* MCP server is a separate process from the SSR renderer (the common case). A network/HTTP failure surfaces as
|
|
4
|
+
* an `ok:false` result rather than throwing, so the calling tool can degrade gracefully. */
|
|
5
|
+
var createHttpPreviewClient = ({ url, secret, fetchImpl = fetch }) => ({ async render(body) {
|
|
6
|
+
let res;
|
|
7
|
+
try {
|
|
8
|
+
res = await fetchImpl(url, {
|
|
9
|
+
method: "POST",
|
|
10
|
+
headers: {
|
|
11
|
+
"content-type": "application/json",
|
|
12
|
+
...secret ? { "x-preview-secret": secret } : {}
|
|
13
|
+
},
|
|
14
|
+
body: JSON.stringify(body)
|
|
15
|
+
});
|
|
16
|
+
} catch (err) {
|
|
17
|
+
return {
|
|
18
|
+
ok: false,
|
|
19
|
+
error: "PREVIEW_UNREACHABLE",
|
|
20
|
+
message: `Preview endpoint unreachable: ${String(err)}`
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (!res.ok && res.status !== 422) return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: "PREVIEW_REQUEST_FAILED",
|
|
26
|
+
message: `Preview endpoint returned ${res.status}.`
|
|
27
|
+
};
|
|
28
|
+
return await res.json();
|
|
29
|
+
} });
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createHttpPreviewClient };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/modules/mcp/resources/canonical.ts
|
|
2
|
+
var ALIASED_ROOTS = [
|
|
3
|
+
"definitions",
|
|
4
|
+
"global-styles",
|
|
5
|
+
"style-variables",
|
|
6
|
+
"schema-variables",
|
|
7
|
+
"folders"
|
|
8
|
+
];
|
|
9
|
+
var canonicalUri = (env, uri) => {
|
|
10
|
+
const aliasPrefix = `plitzi://schema/${env}/`;
|
|
11
|
+
if (!uri.startsWith(aliasPrefix)) return uri;
|
|
12
|
+
const rest = uri.slice(aliasPrefix.length);
|
|
13
|
+
for (const root of ALIASED_ROOTS) {
|
|
14
|
+
if (rest === root) return `plitzi://${root}/${env}`;
|
|
15
|
+
if (rest.startsWith(`${root}/`)) return `plitzi://${root}/${env}/${rest.slice(root.length + 1)}`;
|
|
16
|
+
}
|
|
17
|
+
return uri;
|
|
18
|
+
};
|
|
19
|
+
var itemTemplates = (env) => [
|
|
20
|
+
`plitzi://schema/${env}/pages/{ref}`,
|
|
21
|
+
`plitzi://schema/${env}/elements/{ref}`,
|
|
22
|
+
`plitzi://definitions/${env}/{ref}`,
|
|
23
|
+
`plitzi://global-styles/${env}/{componentType}`,
|
|
24
|
+
`plitzi://style-variables/${env}/{category}`,
|
|
25
|
+
`plitzi://folders/${env}/{ref}`
|
|
26
|
+
];
|
|
27
|
+
/** Teachable message for a URI that read as null. Distinguishes a well-formed URI whose ref does not resolve (the
|
|
28
|
+
* resource may be stale/deleted) from a URI whose shape matches no template at all (malformed — echo the valid
|
|
29
|
+
* templates so the agent stops hand-building URIs). See RFC 0004 I2. */
|
|
30
|
+
var resourceErrorMessage = (env, uri) => {
|
|
31
|
+
const canonical = canonicalUri(env, uri);
|
|
32
|
+
if (itemTemplates(env).some((tpl) => canonical.startsWith(tpl.slice(0, tpl.lastIndexOf("/") + 1)))) return JSON.stringify({
|
|
33
|
+
error: "NOT_FOUND",
|
|
34
|
+
message: `No resource at '${uri}'. Its shape is valid but the ref does not resolve.`,
|
|
35
|
+
hint: "It may have been deleted or your URI is stale. Re-list the parent resource (pages/definitions) to refresh."
|
|
36
|
+
});
|
|
37
|
+
return JSON.stringify({
|
|
38
|
+
error: "MALFORMED_URI",
|
|
39
|
+
message: `'${uri}' matches no resource template.`,
|
|
40
|
+
hint: "Do not hand-build element URIs — take the ready-made uri from plitzi_search or a write response.",
|
|
41
|
+
validTemplates: [`plitzi://primer/${env}`, ...itemTemplates(env)]
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { canonicalUri, itemTemplates, resourceErrorMessage };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { guideText } from "../helpers/guide.js";
|
|
2
|
+
import { envelope } from "./envelope.js";
|
|
3
|
+
import { cssProperties } from "../tools/operations/style/cssCatalog.js";
|
|
4
|
+
import { buildTypeRegistry } from "../tools/operations/schema/registry.js";
|
|
5
|
+
//#region src/modules/mcp/resources/core.ts
|
|
6
|
+
/** Space-independent singletons: the usage guide, the observed type registry and the CSS property catalog.
|
|
7
|
+
* Returns undefined when the URI is not one of these, so the router falls through to the next resolver. */
|
|
8
|
+
var readCoreResource = (space, uri) => {
|
|
9
|
+
if (uri === "plitzi://guide") return envelope(guideText);
|
|
10
|
+
if (uri === "plitzi://types") return envelope(buildTypeRegistry(space.schema));
|
|
11
|
+
if (uri === "plitzi://css-properties") return envelope(cssProperties);
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { readCoreResource };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computeVersion } from "../helpers/computeVersion.js";
|
|
2
|
+
//#region src/modules/mcp/resources/envelope.ts
|
|
3
|
+
/** Wrap any read projection with the version its optimistic-concurrency checks key on. */
|
|
4
|
+
var envelope = (data) => ({
|
|
5
|
+
stateVersion: computeVersion(data),
|
|
6
|
+
data
|
|
7
|
+
});
|
|
8
|
+
var jsonContents = (uri, data) => ({ contents: [{
|
|
9
|
+
uri,
|
|
10
|
+
mimeType: "application/json",
|
|
11
|
+
text: JSON.stringify(data)
|
|
12
|
+
}] });
|
|
13
|
+
//#endregion
|
|
14
|
+
export { envelope, jsonContents };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { guideText } from "../helpers/guide.js";
|
|
2
|
+
import { envelope } from "./envelope.js";
|
|
3
|
+
import { cssProperties } from "../tools/operations/style/cssCatalog.js";
|
|
4
|
+
import { buildTypeRegistry } from "../tools/operations/schema/registry.js";
|
|
5
|
+
import { definitionRefs, styleVariablesToAI } from "../tools/operations/style/translator.js";
|
|
6
|
+
import { foldersToAI, pageSummariesToAI, schemaVariablesToAI } from "../tools/operations/schema/translator.js";
|
|
7
|
+
//#region src/modules/mcp/resources/primer.ts
|
|
8
|
+
/** The cold-start bundle: everything the guide says to read before the first write, in one round-trip.
|
|
9
|
+
* Summaries only — never full page/element trees (those are opened on demand), so it stays cheap even on a
|
|
10
|
+
* large space. Returns undefined when the URI is not the primer. */
|
|
11
|
+
var readPrimerResource = (space, env, uri) => {
|
|
12
|
+
if (uri !== `plitzi://primer/${env}`) return;
|
|
13
|
+
return envelope({
|
|
14
|
+
guide: guideText,
|
|
15
|
+
types: buildTypeRegistry(space.schema),
|
|
16
|
+
cssProperties,
|
|
17
|
+
pages: pageSummariesToAI(space.schema),
|
|
18
|
+
folders: foldersToAI(space.schema),
|
|
19
|
+
definitions: definitionRefs(space.style),
|
|
20
|
+
styleVariables: styleVariablesToAI(space.style),
|
|
21
|
+
schemaVariables: schemaVariablesToAI(space.schema, false)
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { readPrimerResource };
|