@plitzi/sdk-server 0.32.25 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +326 -162
- package/dist/adapters/authAdapters.d.ts +21 -0
- package/dist/adapters/authAdapters.js +12 -0
- package/dist/adapters/jsonAdapters.d.ts +15 -0
- package/dist/adapters/jsonAdapters.js +9 -4
- package/dist/core/auth/api.d.ts +148 -0
- package/dist/core/auth/api.js +286 -0
- package/dist/core/auth/authorize.d.ts +96 -0
- package/dist/core/auth/authorize.js +92 -0
- package/dist/core/auth/createAuth.d.ts +165 -0
- package/dist/core/auth/createAuth.js +105 -0
- package/dist/core/auth/credentials.d.ts +29 -0
- package/dist/core/auth/credentials.js +48 -0
- package/dist/core/auth/domains.d.ts +41 -0
- package/dist/core/auth/domains.js +78 -0
- package/dist/core/auth/identity.d.ts +108 -0
- package/dist/core/auth/identity.js +164 -0
- package/dist/core/auth/oauth/client.d.ts +5 -0
- package/dist/core/auth/oauth/client.js +47 -0
- package/dist/core/auth/oauth/index.d.ts +78 -0
- package/dist/core/auth/oauth/index.js +113 -0
- package/dist/core/auth/oauth/providers/github.d.ts +2 -0
- package/dist/core/auth/oauth/providers/github.js +48 -0
- package/dist/core/auth/oauth/providers/google.d.ts +2 -0
- package/dist/core/auth/oauth/providers/google.js +30 -0
- package/dist/core/auth/oauth/state.d.ts +23 -0
- package/dist/core/auth/oauth/state.js +55 -0
- package/dist/core/auth/oauth/types.d.ts +51 -0
- package/dist/core/auth/oauth/types.js +13 -0
- package/dist/core/auth/routes.d.ts +50 -0
- package/dist/core/auth/routes.js +129 -0
- package/dist/core/auth/session.d.ts +128 -0
- package/dist/core/auth/session.js +165 -0
- package/dist/core/auth/spaceTokens.d.ts +137 -0
- package/dist/core/auth/spaceTokens.js +212 -0
- package/dist/core/auth/tokens.d.ts +151 -0
- package/dist/core/auth/tokens.js +221 -0
- package/dist/core/createServer.d.ts +29 -0
- package/dist/core/createServer.js +28 -14
- package/dist/core/handlers/authMiddleware.d.ts +27 -0
- package/dist/core/handlers/authMiddleware.js +38 -0
- package/dist/core/handlers/authRouteHandlers.d.ts +46 -0
- package/dist/core/handlers/authRouteHandlers.js +75 -0
- package/dist/core/handlers/types.d.ts +37 -0
- package/dist/{src/core → core}/http/dispatcher.d.ts +2 -2
- package/dist/core/http/dispatcher.js +8 -6
- package/dist/core/http/navigation.d.ts +11 -0
- package/dist/core/http/navigation.js +16 -0
- package/dist/core/http/securityHeaders.js +6 -4
- package/dist/core/http/stages/authApi.d.ts +17 -0
- package/dist/core/http/stages/authApi.js +66 -0
- package/dist/core/http/stages/authRoutes.js +40 -11
- package/dist/core/http/stages/exchangeRoute.d.ts +15 -0
- package/dist/core/http/stages/exchangeRoute.js +67 -0
- package/dist/core/http/stages/health.d.ts +11 -0
- package/dist/core/http/stages/health.js +25 -3
- package/dist/core/http/stages/middlewares.d.ts +2 -0
- package/dist/core/http/stages/static.d.ts +13 -0
- package/dist/core/http/stages/static.js +21 -6
- package/dist/core/http/types.d.ts +35 -0
- package/dist/{modules/mcp/constants.js → core/previewToken.js} +1 -1
- package/dist/core/sdkAssets.d.ts +16 -0
- package/dist/core/sdkAssets.js +46 -0
- package/dist/core/server/baseServer.js +40 -5
- package/dist/core/server/pageServer.d.ts +7 -0
- package/dist/core/server/pageServer.js +13 -17
- package/dist/core/services/action.d.ts +9 -0
- package/dist/core/services/action.js +21 -0
- package/dist/core/services/registry.d.ts +3 -0
- package/dist/core/services/registry.js +9 -19
- package/dist/{src/core → core}/services/resolve.d.ts +1 -0
- package/dist/core/services/resolve.js +6 -4
- package/dist/core/services/rsc.js +3 -2
- package/dist/core/staticFiles.js +1 -1
- package/dist/{src/core → core}/transports.d.ts +3 -0
- package/dist/core/transports.js +7 -6
- package/dist/handlers.d.ts +58 -0
- package/dist/handlers.js +3 -0
- package/dist/{src/helpers → helpers}/buildResponseHelpers.d.ts +2 -1
- package/dist/helpers/buildResponseHelpers.js +13 -4
- package/dist/helpers/buildServerInfo.d.ts +3 -0
- package/dist/helpers/buildServerInfo.js +25 -3
- package/dist/{src/helpers → helpers}/cache/keys.d.ts +5 -1
- package/dist/helpers/cache/keys.js +1 -1
- package/dist/helpers/compress.d.ts +18 -0
- package/dist/helpers/compress.js +47 -11
- package/dist/helpers/offlineDataLoader.d.ts +11 -0
- package/dist/helpers/offlineDataLoader.js +15 -0
- package/dist/helpers/resolveDebugMode.d.ts +10 -0
- package/dist/helpers/resolveDebugMode.js +13 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +9 -20
- package/dist/kernel.d.ts +41 -0
- package/dist/kernel.js +22 -0
- package/dist/middlewares/spaceDeployment.d.ts +2 -0
- package/dist/middlewares/spaceDeployment.js +2 -1
- package/dist/modules/actions/handler.d.ts +11 -0
- package/dist/modules/actions/handler.js +77 -0
- package/dist/modules/connectors/engine.d.ts +42 -0
- package/dist/modules/connectors/engine.js +221 -0
- package/dist/modules/connectors/getByPath.d.ts +8 -0
- package/dist/modules/connectors/getByPath.js +21 -0
- package/dist/modules/connectors/index.d.ts +7 -0
- package/dist/modules/connectors/projection.d.ts +18 -0
- package/dist/modules/connectors/projection.js +108 -0
- package/dist/modules/connectors/resolver.d.ts +18 -0
- package/dist/modules/connectors/resolver.js +68 -0
- package/dist/modules/connectors/types.d.ts +19 -0
- package/dist/{src/modules → modules}/rsc/handler.d.ts +2 -2
- package/dist/modules/rsc/handler.js +54 -2
- package/dist/modules/rsc/resolveRscData.d.ts +35 -0
- package/dist/modules/rsc/resolveRscData.js +74 -0
- package/dist/{src/modules → modules}/ssr/Component.d.ts +4 -1
- package/dist/modules/ssr/Component.js +10 -3
- package/dist/modules/ssr/buildBody.d.ts +9 -0
- package/dist/modules/ssr/handler.d.ts +4 -0
- package/dist/modules/ssr/handler.js +18 -1
- package/dist/{src/modules → modules}/ssr/loadPluginComponents.d.ts +5 -2
- package/dist/modules/ssr/loadPluginComponents.js +20 -2
- package/dist/{src/modules → modules}/ssr/prepareRender.d.ts +2 -2
- package/dist/modules/ssr/prepareRender.js +24 -7
- package/dist/modules/ssr/preview.d.ts +10 -0
- package/dist/modules/ssr/preview.js +5 -78
- package/dist/modules/ssr/registerExternalPlugins.js +1 -1
- package/dist/modules/ssr/streamBody.d.ts +5 -0
- package/dist/modules/ssr/streamBody.js +1 -1
- package/dist/modules/ssr/template.d.ts +2 -0
- package/dist/modules/ssr/template.js +1 -1
- package/dist/plugins/compile.js +1 -1
- package/dist/plugins/manager.js +12 -8
- package/dist/ssr.d.ts +15 -0
- package/dist/ssr.js +4 -0
- package/package.json +29 -25
- package/dist/.gitkeep +0 -0
- package/dist/core/server/mcpServer.js +0 -29
- package/dist/core/services/mcp.js +0 -27
- package/dist/core/services/oauth.js +0 -116
- package/dist/core/services/preview.js +0 -37
- package/dist/core/services/proxy.js +0 -12
- package/dist/mcp.d.ts +0 -2
- package/dist/mcp.js +0 -7
- package/dist/modules/ai/AIEngine.js +0 -120
- package/dist/modules/ai/toolkit.js +0 -59
- package/dist/modules/mcp/apps/example/view/index.tsx +0 -70
- package/dist/modules/mcp/apps/index.js +0 -16
- package/dist/modules/mcp/apps/render/index.js +0 -17
- package/dist/modules/mcp/apps/render/styles.js +0 -54
- package/dist/modules/mcp/apps/render/view/heldBatch.ts +0 -107
- package/dist/modules/mcp/apps/render/view/index.tsx +0 -314
- package/dist/modules/mcp/apps/render/view/streamProgress.ts +0 -137
- package/dist/modules/mcp/apps/shared/assets.js +0 -10
- package/dist/modules/mcp/apps/shared/bundle.js +0 -23
- package/dist/modules/mcp/apps/shared/page.js +0 -34
- package/dist/modules/mcp/apps/shared/registerApp.js +0 -43
- package/dist/modules/mcp/apps/shared/resolve.js +0 -5
- package/dist/modules/mcp/apps/shared/shell.ejs +0 -59
- package/dist/modules/mcp/apps/shared/zodEnglishOnly.js +0 -23
- package/dist/modules/mcp/catalogs/builtinCallbacks.js +0 -204
- package/dist/modules/mcp/catalogs/builtinComponents.js +0 -170
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +0 -50
- package/dist/modules/mcp/catalogs/builtinTransformers.js +0 -148
- package/dist/modules/mcp/catalogs/builtinUtilities.js +0 -90
- package/dist/modules/mcp/catalogs/cssCatalog/border.js +0 -30
- package/dist/modules/mcp/catalogs/cssCatalog/box.js +0 -31
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.js +0 -185
- package/dist/modules/mcp/catalogs/cssCatalog/index.js +0 -131
- package/dist/modules/mcp/catalogs/cssCatalog/layout.js +0 -98
- package/dist/modules/mcp/catalogs/cssCatalog/visual.js +0 -144
- package/dist/modules/mcp/catalogs/observed.js +0 -90
- package/dist/modules/mcp/catalogs/paramSpec.js +0 -69
- package/dist/modules/mcp/catalogs/registry.js +0 -89
- package/dist/modules/mcp/handler.js +0 -83
- package/dist/modules/mcp/helpers/agentPrompt.js +0 -104
- package/dist/modules/mcp/helpers/computeVersion.js +0 -16
- package/dist/modules/mcp/helpers/guide.js +0 -467
- package/dist/modules/mcp/helpers/interactions.js +0 -123
- package/dist/modules/mcp/helpers/log.js +0 -64
- package/dist/modules/mcp/helpers/opResult.js +0 -18
- package/dist/modules/mcp/helpers/space.js +0 -300
- package/dist/modules/mcp/helpers/uris.js +0 -44
- package/dist/modules/mcp/previewClient.js +0 -31
- package/dist/modules/mcp/proxy/config.js +0 -63
- package/dist/modules/mcp/proxy/fetch.js +0 -91
- package/dist/modules/mcp/proxy/grant.js +0 -67
- package/dist/modules/mcp/proxy/guard.js +0 -38
- package/dist/modules/mcp/proxy/handler.js +0 -99
- package/dist/modules/mcp/proxy/payload.js +0 -29
- package/dist/modules/mcp/proxy/rewrite.js +0 -138
- package/dist/modules/mcp/proxy/sign.js +0 -15
- package/dist/modules/mcp/proxy/types.js +0 -9
- package/dist/modules/mcp/resources/canonical.js +0 -30
- package/dist/modules/mcp/resources/core.js +0 -18
- package/dist/modules/mcp/resources/envelope.js +0 -14
- package/dist/modules/mcp/resources/primer.js +0 -31
- package/dist/modules/mcp/resources/register.js +0 -190
- package/dist/modules/mcp/resources/renderGuide.js +0 -451
- package/dist/modules/mcp/resources/router.js +0 -37
- package/dist/modules/mcp/resources/schema.js +0 -43
- package/dist/modules/mcp/resources/style.js +0 -34
- package/dist/modules/mcp/screenshotClient.js +0 -47
- package/dist/modules/mcp/server.js +0 -113
- package/dist/modules/mcp/tools/apply/dispatch.js +0 -105
- package/dist/modules/mcp/tools/apply/index.js +0 -150
- package/dist/modules/mcp/tools/apply/writeResult.js +0 -37
- package/dist/modules/mcp/tools/index.js +0 -24
- package/dist/modules/mcp/tools/operations/index.js +0 -45
- package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +0 -32
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +0 -36
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +0 -47
- package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +0 -29
- package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +0 -41
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +0 -58
- package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +0 -148
- package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +0 -65
- package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +0 -30
- package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +0 -49
- package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +0 -52
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +0 -47
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +0 -44
- package/dist/modules/mcp/tools/operations/schema/operations.js +0 -41
- package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +0 -25
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +0 -75
- package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +0 -45
- package/dist/modules/mcp/tools/operations/schema/shared.js +0 -122
- package/dist/modules/mcp/tools/operations/schema/translator.js +0 -215
- package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +0 -18
- package/dist/modules/mcp/tools/operations/schema/variables/upsertVariable.js +0 -42
- package/dist/modules/mcp/tools/operations/schema/write.js +0 -109
- package/dist/modules/mcp/tools/operations/schemaIds.js +0 -54
- package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +0 -21
- package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +0 -28
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinition.js +0 -24
- package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinitions.js +0 -40
- package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +0 -21
- package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +0 -28
- package/dist/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.js +0 -24
- package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +0 -21
- package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +0 -28
- package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +0 -24
- package/dist/modules/mcp/tools/operations/style/operations.js +0 -29
- package/dist/modules/mcp/tools/operations/style/shared.js +0 -59
- package/dist/modules/mcp/tools/operations/style/translator.js +0 -101
- package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +0 -21
- package/dist/modules/mcp/tools/operations/style/variables/upsertStyleVariable.js +0 -22
- package/dist/modules/mcp/tools/operations/style/write.js +0 -108
- package/dist/modules/mcp/tools/preview.js +0 -37
- package/dist/modules/mcp/tools/read.js +0 -51
- package/dist/modules/mcp/tools/render.js +0 -184
- package/dist/modules/mcp/tools/screenshot.js +0 -83
- package/dist/modules/mcp/tools/search.js +0 -115
- package/dist/modules/mcp/tools/shared/expandOperations.js +0 -44
- package/dist/modules/mcp/tools/shared/tool.js +0 -33
- package/dist/modules/mcp/tools/shared/validator/audit.js +0 -124
- package/dist/modules/mcp/tools/shared/validator/batch.js +0 -39
- package/dist/modules/mcp/tools/shared/validator/bindings.js +0 -70
- package/dist/modules/mcp/tools/shared/validator/context.js +0 -35
- package/dist/modules/mcp/tools/shared/validator/css.js +0 -39
- package/dist/modules/mcp/tools/shared/validator/elements.js +0 -68
- package/dist/modules/mcp/tools/shared/validator/index.js +0 -246
- package/dist/modules/mcp/tools/shared/validator/interactions.js +0 -103
- package/dist/modules/mcp/tools/shared/validator/refs.js +0 -28
- package/dist/modules/mcp/tools/validate.js +0 -47
- package/dist/modules/oauth/authorize.js +0 -177
- package/dist/modules/oauth/challenge.js +0 -33
- package/dist/modules/oauth/consentPage.js +0 -118
- package/dist/modules/oauth/metadata.js +0 -69
- package/dist/modules/oauth/params.js +0 -5
- package/dist/modules/oauth/pkce.js +0 -15
- package/dist/modules/oauth/records.js +0 -46
- package/dist/modules/oauth/register.js +0 -55
- package/dist/modules/oauth/respond.js +0 -44
- package/dist/modules/oauth/token.js +0 -100
- package/dist/public/.gitkeep +0 -0
- package/dist/src/adapters/jsonAdapters.d.ts +0 -7
- package/dist/src/core/createServer.d.ts +0 -14
- package/dist/src/core/http/stages/health.d.ts +0 -2
- package/dist/src/core/http/stages/middlewares.d.ts +0 -2
- package/dist/src/core/http/stages/static.d.ts +0 -5
- package/dist/src/core/http/types.d.ts +0 -22
- package/dist/src/core/server/mcpServer.d.ts +0 -2
- package/dist/src/core/server/pageServer.d.ts +0 -10
- package/dist/src/core/services/mcp.d.ts +0 -3
- package/dist/src/core/services/oauth.d.ts +0 -18
- package/dist/src/core/services/preview.d.ts +0 -2
- package/dist/src/core/services/proxy.d.ts +0 -2
- package/dist/src/core/services/registry.d.ts +0 -4
- package/dist/src/helpers/buildServerInfo.d.ts +0 -2
- package/dist/src/helpers/compress.d.ts +0 -3
- package/dist/src/index.d.ts +0 -15
- package/dist/src/mcp.d.ts +0 -14
- package/dist/src/middlewares/spaceDeployment.d.ts +0 -2
- package/dist/src/modules/ai/AIEngine.d.ts +0 -20
- package/dist/src/modules/ai/index.d.ts +0 -4
- package/dist/src/modules/ai/toolkit.d.ts +0 -17
- package/dist/src/modules/mcp/apps/example/index.d.ts +0 -8
- package/dist/src/modules/mcp/apps/index.d.ts +0 -11
- package/dist/src/modules/mcp/apps/render/index.d.ts +0 -4
- package/dist/src/modules/mcp/apps/render/styles.d.ts +0 -10
- package/dist/src/modules/mcp/apps/shared/assets.d.ts +0 -10
- package/dist/src/modules/mcp/apps/shared/bundle.d.ts +0 -4
- package/dist/src/modules/mcp/apps/shared/index.d.ts +0 -3
- package/dist/src/modules/mcp/apps/shared/page.d.ts +0 -2
- package/dist/src/modules/mcp/apps/shared/registerApp.d.ts +0 -5
- package/dist/src/modules/mcp/apps/shared/resolve.d.ts +0 -1
- package/dist/src/modules/mcp/apps/shared/zodEnglishOnly.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/builtinCallbacks.d.ts +0 -23
- package/dist/src/modules/mcp/catalogs/builtinComponents.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/builtinElementCallbacks.d.ts +0 -20
- package/dist/src/modules/mcp/catalogs/builtinTransformers.d.ts +0 -28
- package/dist/src/modules/mcp/catalogs/builtinUtilities.d.ts +0 -18
- package/dist/src/modules/mcp/catalogs/cssCatalog/border.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/cssCatalog/box.d.ts +0 -4
- package/dist/src/modules/mcp/catalogs/cssCatalog/helpers.d.ts +0 -34
- package/dist/src/modules/mcp/catalogs/cssCatalog/index.d.ts +0 -19
- package/dist/src/modules/mcp/catalogs/cssCatalog/layout.d.ts +0 -9
- package/dist/src/modules/mcp/catalogs/cssCatalog/visual.d.ts +0 -8
- package/dist/src/modules/mcp/catalogs/index.d.ts +0 -9
- package/dist/src/modules/mcp/catalogs/observed.d.ts +0 -48
- package/dist/src/modules/mcp/catalogs/paramSpec.d.ts +0 -42
- package/dist/src/modules/mcp/catalogs/registry.d.ts +0 -35
- package/dist/src/modules/mcp/e2e/index.d.ts +0 -6
- package/dist/src/modules/mcp/e2e/mcpEndpoint.d.ts +0 -27
- package/dist/src/modules/mcp/e2e/postMessageChannel.d.ts +0 -22
- package/dist/src/modules/mcp/e2e/renderingHost.d.ts +0 -34
- package/dist/src/modules/mcp/handler.d.ts +0 -22
- package/dist/src/modules/mcp/helpers/agentPrompt.d.ts +0 -4
- package/dist/src/modules/mcp/helpers/computeVersion.d.ts +0 -1
- package/dist/src/modules/mcp/helpers/guide.d.ts +0 -4
- package/dist/src/modules/mcp/helpers/index.d.ts +0 -8
- package/dist/src/modules/mcp/helpers/interactions.d.ts +0 -30
- package/dist/src/modules/mcp/helpers/log.d.ts +0 -8
- package/dist/src/modules/mcp/helpers/opResult.d.ts +0 -13
- package/dist/src/modules/mcp/helpers/space.d.ts +0 -115
- package/dist/src/modules/mcp/helpers/uris.d.ts +0 -28
- package/dist/src/modules/mcp/index.d.ts +0 -13
- package/dist/src/modules/mcp/previewClient.d.ts +0 -13
- package/dist/src/modules/mcp/proxy/config.d.ts +0 -19
- package/dist/src/modules/mcp/proxy/fetch.d.ts +0 -18
- package/dist/src/modules/mcp/proxy/grant.d.ts +0 -25
- package/dist/src/modules/mcp/proxy/guard.d.ts +0 -6
- package/dist/src/modules/mcp/proxy/handler.d.ts +0 -8
- package/dist/src/modules/mcp/proxy/index.d.ts +0 -8
- package/dist/src/modules/mcp/proxy/payload.d.ts +0 -8
- package/dist/src/modules/mcp/proxy/rewrite.d.ts +0 -18
- package/dist/src/modules/mcp/proxy/sign.d.ts +0 -6
- package/dist/src/modules/mcp/proxy/types.d.ts +0 -45
- package/dist/src/modules/mcp/resources/canonical.d.ts +0 -6
- package/dist/src/modules/mcp/resources/core.d.ts +0 -5
- package/dist/src/modules/mcp/resources/envelope.d.ts +0 -10
- package/dist/src/modules/mcp/resources/index.d.ts +0 -8
- package/dist/src/modules/mcp/resources/primer.d.ts +0 -7
- package/dist/src/modules/mcp/resources/register.d.ts +0 -10
- package/dist/src/modules/mcp/resources/renderGuide.d.ts +0 -10
- package/dist/src/modules/mcp/resources/router.d.ts +0 -10
- package/dist/src/modules/mcp/resources/schema.d.ts +0 -5
- package/dist/src/modules/mcp/resources/style.d.ts +0 -5
- package/dist/src/modules/mcp/screenshotClient.d.ts +0 -13
- package/dist/src/modules/mcp/server.d.ts +0 -31
- package/dist/src/modules/mcp/tests/helpers.d.ts +0 -13
- package/dist/src/modules/mcp/tools/apply/dispatch.d.ts +0 -6
- package/dist/src/modules/mcp/tools/apply/index.d.ts +0 -470
- package/dist/src/modules/mcp/tools/apply/writeResult.d.ts +0 -8
- package/dist/src/modules/mcp/tools/index.d.ts +0 -18
- package/dist/src/modules/mcp/tools/operations/index.d.ts +0 -928
- package/dist/src/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +0 -17
- package/dist/src/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +0 -25
- package/dist/src/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +0 -27
- package/dist/src/modules/mcp/tools/operations/schema/elements/deleteElement.d.ts +0 -10
- package/dist/src/modules/mcp/tools/operations/schema/elements/moveElement.d.ts +0 -16
- package/dist/src/modules/mcp/tools/operations/schema/elements/patchElement.d.ts +0 -22
- package/dist/src/modules/mcp/tools/operations/schema/elements/repeatElement.d.ts +0 -55
- package/dist/src/modules/mcp/tools/operations/schema/elements/upsertElement.d.ts +0 -16
- package/dist/src/modules/mcp/tools/operations/schema/folders/deleteFolder.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/schema/folders/upsertFolder.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/schema/index.d.ts +0 -21
- package/dist/src/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +0 -18
- package/dist/src/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +0 -27
- package/dist/src/modules/mcp/tools/operations/schema/operations.d.ts +0 -229
- package/dist/src/modules/mcp/tools/operations/schema/pages/deletePage.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +0 -14
- package/dist/src/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +0 -34
- package/dist/src/modules/mcp/tools/operations/schema/shared.d.ts +0 -92
- package/dist/src/modules/mcp/tools/operations/schema/translator.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/schema/variables/deleteVariable.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/schema/variables/upsertVariable.d.ts +0 -16
- package/dist/src/modules/mcp/tools/operations/schema/write.d.ts +0 -42
- package/dist/src/modules/mcp/tools/operations/schemaIds.d.ts +0 -6
- package/dist/src/modules/mcp/tools/operations/style/definitions/deleteDefinition.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/style/definitions/patchDefinition.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/definitions/upsertDefinition.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/definitions/upsertDefinitions.d.ts +0 -41
- package/dist/src/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +0 -9
- package/dist/src/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +0 -37
- package/dist/src/modules/mcp/tools/operations/style/index.d.ts +0 -15
- package/dist/src/modules/mcp/tools/operations/style/operations.d.ts +0 -264
- package/dist/src/modules/mcp/tools/operations/style/shared.d.ts +0 -116
- package/dist/src/modules/mcp/tools/operations/style/translator.d.ts +0 -12
- package/dist/src/modules/mcp/tools/operations/style/variables/deleteStyleVariable.d.ts +0 -15
- package/dist/src/modules/mcp/tools/operations/style/variables/upsertStyleVariable.d.ts +0 -20
- package/dist/src/modules/mcp/tools/operations/style/write.d.ts +0 -12
- package/dist/src/modules/mcp/tools/preview.d.ts +0 -465
- package/dist/src/modules/mcp/tools/read.d.ts +0 -9
- package/dist/src/modules/mcp/tools/render.d.ts +0 -499
- package/dist/src/modules/mcp/tools/render.test.d.ts +0 -1
- package/dist/src/modules/mcp/tools/screenshot.d.ts +0 -470
- package/dist/src/modules/mcp/tools/search.d.ts +0 -15
- package/dist/src/modules/mcp/tools/shared/expandOperations.d.ts +0 -13
- package/dist/src/modules/mcp/tools/shared/tool.d.ts +0 -72
- package/dist/src/modules/mcp/tools/shared/validator/audit.d.ts +0 -4
- package/dist/src/modules/mcp/tools/shared/validator/batch.d.ts +0 -5
- package/dist/src/modules/mcp/tools/shared/validator/bindings.d.ts +0 -6
- package/dist/src/modules/mcp/tools/shared/validator/context.d.ts +0 -38
- package/dist/src/modules/mcp/tools/shared/validator/css.d.ts +0 -4
- package/dist/src/modules/mcp/tools/shared/validator/elements.d.ts +0 -7
- package/dist/src/modules/mcp/tools/shared/validator/index.d.ts +0 -8
- package/dist/src/modules/mcp/tools/shared/validator/interactions.d.ts +0 -3
- package/dist/src/modules/mcp/tools/shared/validator/refs.d.ts +0 -4
- package/dist/src/modules/mcp/tools/validate.d.ts +0 -467
- package/dist/src/modules/mcp/types/aiSchema.d.ts +0 -218
- package/dist/src/modules/mcp/types/appTypes.d.ts +0 -26
- package/dist/src/modules/mcp/types/index.d.ts +0 -5
- package/dist/src/modules/mcp/types/previewTypes.d.ts +0 -25
- package/dist/src/modules/mcp/types/screenshotTypes.d.ts +0 -29
- package/dist/src/modules/mcp/types/toolTypes.d.ts +0 -138
- package/dist/src/modules/oauth/authorize.d.ts +0 -7
- package/dist/src/modules/oauth/challenge.d.ts +0 -11
- package/dist/src/modules/oauth/consentPage.d.ts +0 -7
- package/dist/src/modules/oauth/metadata.d.ts +0 -40
- package/dist/src/modules/oauth/params.d.ts +0 -5
- package/dist/src/modules/oauth/pkce.d.ts +0 -6
- package/dist/src/modules/oauth/records.d.ts +0 -71
- package/dist/src/modules/oauth/register.d.ts +0 -5
- package/dist/src/modules/oauth/respond.d.ts +0 -13
- package/dist/src/modules/oauth/token.d.ts +0 -5
- package/dist/src/modules/ssr/buildBody.d.ts +0 -9
- package/dist/src/modules/ssr/handler.d.ts +0 -4
- package/dist/src/modules/ssr/preview.d.ts +0 -16
- package/dist/src/modules/ssr/streamBody.d.ts +0 -5
- package/dist/src/modules/ssr/template.d.ts +0 -6
- package/dist/src/standalone/alias-loader.d.mts +0 -2
- package/dist/src/standalone/plugins/ClientInfo.d.ts +0 -2
- package/dist/src/standalone/plugins/ServerInfo.d.ts +0 -2
- package/dist/src/standalone/plugins/SharedInfo.d.ts +0 -2
- package/dist/src/standalone/plugins/styles.d.ts +0 -5
- package/dist/src/standalone/register-alias.d.mts +0 -1
- package/dist/src/standalone/server.d.ts +0 -1
- package/dist/src/standalone/stubs/react-syntax-highlighter.d.mts +0 -31
- package/skills/plitzi-render/SKILL.md +0 -174
- /package/dist/{src/core/http/dispatcher.test.d.ts → core/auth/api.test.d.ts} +0 -0
- /package/dist/{src/core/server/mcpServer.test.d.ts → core/auth/authorize.test.d.ts} +0 -0
- /package/dist/{src/modules/ai/toolkit.test.d.ts → core/auth/createAuth.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/apps/apps.test.d.ts → core/auth/domains.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/apps/render/styles.test.d.ts → core/auth/identity.test.d.ts} +0 -0
- /package/dist/{src/modules → core/auth}/oauth/oauth.test.d.ts +0 -0
- /package/dist/{src/modules/mcp/catalogs/builtinTransformers.test.d.ts → core/auth/routes.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/catalogs/cssCatalog/cssCatalog.test.d.ts → core/auth/session.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/e2e/connector.test.d.ts → core/auth/spaceTokens.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/e2e/host.test.d.ts → core/auth/tokens.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/e2e/oauthConnector.test.d.ts → core/createServer.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/helpers/log.test.d.ts → core/handlers/handlers.test.d.ts} +0 -0
- /package/dist/{src/core → core}/health.d.ts +0 -0
- /package/dist/{src/modules/mcp/mcp.bench.d.ts → core/http/dispatcher.test.d.ts} +0 -0
- /package/dist/{src/core → core}/http/securityHeaders.d.ts +0 -0
- /package/dist/{src/core → core}/http/stages/authRoutes.d.ts +0 -0
- /package/dist/{src/core → core}/http/stages/pluginAssets.d.ts +0 -0
- /package/dist/{src/core → core}/mimeTypes.d.ts +0 -0
- /package/dist/{src/modules/mcp/constants.d.ts → core/previewToken.d.ts} +0 -0
- /package/dist/{src/core → core}/requestParser.d.ts +0 -0
- /package/dist/{src/core → core}/server/baseServer.d.ts +0 -0
- /package/dist/{src/modules/mcp/proxy/endpoint.test.d.ts → core/server/baseServer.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/proxy/proxy.test.d.ts → core/services/resolve.test.d.ts} +0 -0
- /package/dist/{src/core → core}/services/rsc.d.ts +0 -0
- /package/dist/{src/core → core}/services/ssr.d.ts +0 -0
- /package/dist/{src/core → core}/staticFiles.d.ts +0 -0
- /package/dist/{src/modules/mcp/proxy/wiring.test.d.ts → helpers/buildResponseHelpers.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/cache/TtlCache.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/cache/cacheManager.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/cache/defaults.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/cache/index.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/apply.test.d.ts → helpers/cache/keys.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/cache/serverCaches.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/bindings.test.d.ts → helpers/compress.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/escapeJson.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/metrics.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/normalizePlugins.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/css.test.d.ts → helpers/offlineDataLoader.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/readCookie.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/interactions.test.d.ts → helpers/resolveDebugMode.test.d.ts} +0 -0
- /package/dist/{src/helpers → helpers}/runMiddlewares.d.ts +0 -0
- /package/dist/{src/helpers → helpers}/serverLog.d.ts +0 -0
- /package/dist/{src/middlewares → middlewares}/auth.d.ts +0 -0
- /package/dist/{src/middlewares → middlewares}/basicAuth.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/pages.test.d.ts → middlewares/spaceDeployment.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/reads.test.d.ts → modules/actions/handler.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/schemaIds.test.d.ts → modules/connectors/engine.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/search.test.d.ts → modules/connectors/projection.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/skill.test.d.ts → modules/connectors/resolver.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/styles.test.d.ts → modules/rsc/resolveRscData.test.d.ts} +0 -0
- /package/dist/{src/modules → modules}/ssr/applySSRResult.d.ts +0 -0
- /package/dist/{src/modules/mcp/tests/tools.test.d.ts → modules/ssr/loadPluginComponents.test.d.ts} +0 -0
- /package/dist/{src/modules/mcp/tests/validation.test.d.ts → modules/ssr/metering.test.d.ts} +0 -0
- /package/dist/{src/modules → modules}/ssr/registerExternalPlugins.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/compile.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/copy.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/detect.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/manager.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/validate.d.ts +0 -0
- /package/dist/{src/plugins → plugins}/validate.test.d.ts +0 -0
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { renderLogEvent } from "../../../helpers/serverLog.js";
|
|
2
|
-
//#region src/modules/mcp/helpers/log.ts
|
|
3
|
-
var MCP_DEBUG = process.env.MCP_DEBUG === "1";
|
|
4
|
-
var MCP_LOG_ARGS = process.env.MCP_LOG_ARGS === "1";
|
|
5
|
-
var shapeOf = (value, depth = 0) => {
|
|
6
|
-
if (value === null) return "null";
|
|
7
|
-
if (Array.isArray(value)) return `[${value.length}]`;
|
|
8
|
-
if (typeof value === "object") {
|
|
9
|
-
if (depth >= 2) return "{…}";
|
|
10
|
-
const entries = Object.entries(value);
|
|
11
|
-
const shown = entries.slice(0, 8).map(([key, item]) => `${key}:${shapeOf(item, depth + 1)}`);
|
|
12
|
-
return `{${[...shown, ...entries.length > shown.length ? ["…"] : []].join(",")}}`;
|
|
13
|
-
}
|
|
14
|
-
return typeof value;
|
|
15
|
-
};
|
|
16
|
-
var rawSummary = (value, max = 300) => {
|
|
17
|
-
let json;
|
|
18
|
-
try {
|
|
19
|
-
json = JSON.stringify(value);
|
|
20
|
-
} catch {
|
|
21
|
-
return "[unserializable]";
|
|
22
|
-
}
|
|
23
|
-
return json.length > max ? `${json.slice(0, max)}…` : json;
|
|
24
|
-
};
|
|
25
|
-
var summarize = (value) => {
|
|
26
|
-
if (value === void 0) return;
|
|
27
|
-
return MCP_LOG_ARGS ? rawSummary(value) : shapeOf(value);
|
|
28
|
-
};
|
|
29
|
-
var errorText = (error) => error instanceof Error ? error.message : String(error);
|
|
30
|
-
var noop = () => void 0;
|
|
31
|
-
var inertLog = {
|
|
32
|
-
toolCall: noop,
|
|
33
|
-
resourceRead: noop
|
|
34
|
-
};
|
|
35
|
-
/** Build the protocol-log sink for one MCP server. Dispatches structured events to the consumer's `logger` when
|
|
36
|
-
* provided; otherwise renders to the console when MCP_DEBUG=1; otherwise a no-op. */
|
|
37
|
-
var createMcpLog = (logger) => {
|
|
38
|
-
if (!logger && !MCP_DEBUG) return inertLog;
|
|
39
|
-
const emit = (event) => {
|
|
40
|
-
if (logger) logger(event);
|
|
41
|
-
else console.log(renderLogEvent(event));
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
toolCall: (name, args, ms, error) => emit({
|
|
45
|
-
kind: "tool",
|
|
46
|
-
name,
|
|
47
|
-
durationMs: ms,
|
|
48
|
-
ok: !error,
|
|
49
|
-
...error ? { error: errorText(error) } : {},
|
|
50
|
-
...summarize(args) !== void 0 ? { argsSummary: summarize(args) } : {},
|
|
51
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
52
|
-
}),
|
|
53
|
-
resourceRead: (uri, ms, error) => emit({
|
|
54
|
-
kind: "resource",
|
|
55
|
-
name: uri,
|
|
56
|
-
durationMs: ms,
|
|
57
|
-
ok: !error,
|
|
58
|
-
...error ? { error: errorText(error) } : {},
|
|
59
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
60
|
-
})
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
//#endregion
|
|
64
|
-
export { createMcpLog };
|
|
@@ -1,18 +0,0 @@
|
|
|
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 };
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
//#region src/modules/mcp/helpers/space.ts
|
|
2
|
-
var cloneSpace = (space) => ({
|
|
3
|
-
schema: structuredClone(space.schema),
|
|
4
|
-
style: structuredClone(space.style),
|
|
5
|
-
...space.catalog ? { catalog: space.catalog } : {}
|
|
6
|
-
});
|
|
7
|
-
var emptySpace = () => ({
|
|
8
|
-
schema: {
|
|
9
|
-
flat: {},
|
|
10
|
-
definition: {
|
|
11
|
-
name: "",
|
|
12
|
-
permanentUrl: ""
|
|
13
|
-
},
|
|
14
|
-
variables: [],
|
|
15
|
-
settings: { customCss: "" },
|
|
16
|
-
pages: [],
|
|
17
|
-
pageFolders: []
|
|
18
|
-
},
|
|
19
|
-
style: {
|
|
20
|
-
platform: {
|
|
21
|
-
desktop: {},
|
|
22
|
-
tablet: {},
|
|
23
|
-
mobile: {}
|
|
24
|
-
},
|
|
25
|
-
theme: {
|
|
26
|
-
default: "system",
|
|
27
|
-
schemes: ["light", "dark"]
|
|
28
|
-
},
|
|
29
|
-
variables: {},
|
|
30
|
-
cache: ""
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
var slugify = (value) => value.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "";
|
|
34
|
-
/** A value when it is a string, otherwise undefined — for the many attributes typed as `unknown` that are strings
|
|
35
|
-
* in practice (name, slug, subType, dom id…). */
|
|
36
|
-
var strOr = (value) => typeof value === "string" ? value : void 0;
|
|
37
|
-
/** Display name of a page or element: its `name` attribute when set, otherwise its definition label. */
|
|
38
|
-
var nameOf = (el) => strOr(el.attributes.name) ?? el.definition.label;
|
|
39
|
-
/** Stable, human-readable ref for a page: its idRef, then slug, then a slugified label. A page without an idRef is
|
|
40
|
-
* still addressable — unlike a data source, a page ref has meaningful fallbacks the agent can read off the tree. */
|
|
41
|
-
var pageRefOf = (el) => {
|
|
42
|
-
if (el.idRef) return el.idRef;
|
|
43
|
-
const slug = strOr(el.attributes.slug)?.trim();
|
|
44
|
-
if (slug) return slugify(slug);
|
|
45
|
-
if (el.attributes.default === true) return "home";
|
|
46
|
-
return slugify(nameOf(el)) || el.id;
|
|
47
|
-
};
|
|
48
|
-
/** Stable ref for ADDRESSING a non-page element in the tree: its idRef when present, otherwise the opaque id so an
|
|
49
|
-
* element without one is still reachable — the agent needs to name it to give it an idRef in the first place.
|
|
50
|
-
* This is not the wiring key: the runtime wires interactions and data sources by idRef only, so an element
|
|
51
|
-
* addressed here by its id alone publishes no source and takes no interactions (see `getSourceName`). */
|
|
52
|
-
var elementRefOf = (el) => el.idRef ?? el.id;
|
|
53
|
-
var buildIndex = (schema) => {
|
|
54
|
-
const flat = schema.flat;
|
|
55
|
-
const lookup = (id) => flat[id];
|
|
56
|
-
const pageIds = new Set(schema.pages);
|
|
57
|
-
for (const el of Object.values(flat)) if (el.definition.type === "page") pageIds.add(el.id);
|
|
58
|
-
const pageElements = [];
|
|
59
|
-
const pageByRef = /* @__PURE__ */ new Map();
|
|
60
|
-
const elementByRef = /* @__PURE__ */ new Map();
|
|
61
|
-
for (const el of Object.values(flat)) if (pageIds.has(el.id)) {
|
|
62
|
-
pageElements.push(el);
|
|
63
|
-
const ref = pageRefOf(el);
|
|
64
|
-
if (!pageByRef.has(ref)) pageByRef.set(ref, el);
|
|
65
|
-
if (!pageByRef.has(el.id)) pageByRef.set(el.id, el);
|
|
66
|
-
} else {
|
|
67
|
-
const ref = elementRefOf(el);
|
|
68
|
-
if (!elementByRef.has(ref)) elementByRef.set(ref, el);
|
|
69
|
-
if (!elementByRef.has(el.id)) elementByRef.set(el.id, el);
|
|
70
|
-
}
|
|
71
|
-
const pageOf = /* @__PURE__ */ new Map();
|
|
72
|
-
for (const page of pageElements) {
|
|
73
|
-
pageOf.set(page.id, page.id);
|
|
74
|
-
const stack = [...page.definition.items ?? []];
|
|
75
|
-
while (stack.length > 0) {
|
|
76
|
-
const id = stack.pop();
|
|
77
|
-
if (id === void 0 || pageOf.has(id)) continue;
|
|
78
|
-
const el = lookup(id);
|
|
79
|
-
if (!el) continue;
|
|
80
|
-
pageOf.set(id, page.id);
|
|
81
|
-
for (const childId of el.definition.items ?? []) stack.push(childId);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
pageIds,
|
|
86
|
-
pageElements,
|
|
87
|
-
pageByRef,
|
|
88
|
-
elementByRef,
|
|
89
|
-
pageOf,
|
|
90
|
-
detailCache: /* @__PURE__ */ new Map()
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
var indexCache = /* @__PURE__ */ new WeakMap();
|
|
94
|
-
/** The index for a schema, built once and memoized on the schema object. */
|
|
95
|
-
var spaceIndex = (schema) => {
|
|
96
|
-
let index = indexCache.get(schema);
|
|
97
|
-
if (!index) {
|
|
98
|
-
index = buildIndex(schema);
|
|
99
|
-
indexCache.set(schema, index);
|
|
100
|
-
}
|
|
101
|
-
return index;
|
|
102
|
-
};
|
|
103
|
-
var cachedIndex = (schema) => indexCache.get(schema);
|
|
104
|
-
/** A new non-page element was created under `pageId`. */
|
|
105
|
-
var indexAddElement = (schema, el, pageId) => {
|
|
106
|
-
const index = cachedIndex(schema);
|
|
107
|
-
if (!index) return;
|
|
108
|
-
index.elementByRef.set(el.id, el);
|
|
109
|
-
if (el.idRef) index.elementByRef.set(el.idRef, el);
|
|
110
|
-
index.pageOf.set(el.id, pageId);
|
|
111
|
-
index.detailCache.clear();
|
|
112
|
-
};
|
|
113
|
-
/** These non-page elements were deleted (an element and its descendants). */
|
|
114
|
-
var indexRemoveElements = (schema, els) => {
|
|
115
|
-
const index = cachedIndex(schema);
|
|
116
|
-
if (!index) return;
|
|
117
|
-
for (const el of els) {
|
|
118
|
-
index.elementByRef.delete(el.id);
|
|
119
|
-
if (el.idRef) index.elementByRef.delete(el.idRef);
|
|
120
|
-
index.pageOf.delete(el.id);
|
|
121
|
-
}
|
|
122
|
-
index.detailCache.clear();
|
|
123
|
-
};
|
|
124
|
-
/** An existing element was just given an idRef (it had none), so it becomes addressable by that ref. */
|
|
125
|
-
var indexReRefElement = (schema, el) => {
|
|
126
|
-
const index = cachedIndex(schema);
|
|
127
|
-
if (!index) return;
|
|
128
|
-
if (el.idRef) index.elementByRef.set(el.idRef, el);
|
|
129
|
-
index.detailCache.clear();
|
|
130
|
-
};
|
|
131
|
-
/** A new page element was created. */
|
|
132
|
-
var indexAddPage = (schema, page) => {
|
|
133
|
-
const index = cachedIndex(schema);
|
|
134
|
-
if (!index) return;
|
|
135
|
-
index.pageIds.add(page.id);
|
|
136
|
-
index.pageElements.push(page);
|
|
137
|
-
index.pageByRef.set(page.id, page);
|
|
138
|
-
index.pageByRef.set(pageRefOf(page), page);
|
|
139
|
-
index.pageOf.set(page.id, page.id);
|
|
140
|
-
index.detailCache.clear();
|
|
141
|
-
};
|
|
142
|
-
/** A page and its `descendants` (its non-page elements) were deleted. */
|
|
143
|
-
var indexRemovePage = (schema, page, descendants) => {
|
|
144
|
-
const index = cachedIndex(schema);
|
|
145
|
-
if (!index) return;
|
|
146
|
-
index.pageIds.delete(page.id);
|
|
147
|
-
const at = index.pageElements.findIndex((p) => p.id === page.id);
|
|
148
|
-
if (at >= 0) index.pageElements.splice(at, 1);
|
|
149
|
-
index.pageByRef.delete(page.id);
|
|
150
|
-
index.pageByRef.delete(pageRefOf(page));
|
|
151
|
-
index.pageOf.delete(page.id);
|
|
152
|
-
for (const el of descendants) {
|
|
153
|
-
index.elementByRef.delete(el.id);
|
|
154
|
-
if (el.idRef) index.elementByRef.delete(el.idRef);
|
|
155
|
-
index.pageOf.delete(el.id);
|
|
156
|
-
}
|
|
157
|
-
index.detailCache.clear();
|
|
158
|
-
};
|
|
159
|
-
/** A page's slug/name/default changed; re-key its pageByRef entry if that changed its ref. `oldRef` is the ref
|
|
160
|
-
* computed BEFORE the attribute change. */
|
|
161
|
-
var indexReRefPage = (schema, page, oldRef) => {
|
|
162
|
-
const index = cachedIndex(schema);
|
|
163
|
-
if (!index) return;
|
|
164
|
-
const newRef = pageRefOf(page);
|
|
165
|
-
if (newRef !== oldRef) {
|
|
166
|
-
index.pageByRef.delete(oldRef);
|
|
167
|
-
index.pageByRef.set(newRef, page);
|
|
168
|
-
index.detailCache.clear();
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
/** A move reparented an element within its page: the ref/page maps are unchanged, but the moved element's
|
|
172
|
-
* parentRef and both parents' childRefs did change, so their memoized detail must be dropped. */
|
|
173
|
-
var indexInvalidateDetails = (schema) => {
|
|
174
|
-
cachedIndex(schema)?.detailCache.clear();
|
|
175
|
-
};
|
|
176
|
-
var isPageElement = (schema, el) => spaceIndex(schema).pageIds.has(el.id) || el.definition.type === "page";
|
|
177
|
-
var getPageElements = (schema) => spaceIndex(schema).pageElements;
|
|
178
|
-
/** Finds a page by its semantic ref (idRef/slug/…) or its raw id, so legacy schemas without an idRef still resolve. */
|
|
179
|
-
var findPageByRef = (schema, pageRef) => spaceIndex(schema).pageByRef.get(pageRef);
|
|
180
|
-
/** Find any non-page element by its semantic ref (idRef) or raw id, across the whole space. */
|
|
181
|
-
var findElementByRef = (schema, ref) => spaceIndex(schema).elementByRef.get(ref);
|
|
182
|
-
var pageFoldersOf = (schema) => {
|
|
183
|
-
schema.pageFolders ??= [];
|
|
184
|
-
return schema.pageFolders;
|
|
185
|
-
};
|
|
186
|
-
/** Resolve a folder by its id, or (for agent convenience) by an exact name or slug when that is unambiguous. */
|
|
187
|
-
var findFolderByRef = (schema, ref) => {
|
|
188
|
-
const folders = pageFoldersOf(schema);
|
|
189
|
-
const byId = folders.find((f) => f.id === ref);
|
|
190
|
-
if (byId) return byId;
|
|
191
|
-
const byName = folders.filter((f) => f.name === ref);
|
|
192
|
-
if (byName.length === 1) return byName[0];
|
|
193
|
-
const bySlug = folders.filter((f) => f.slug === ref);
|
|
194
|
-
return bySlug.length === 1 ? bySlug[0] : void 0;
|
|
195
|
-
};
|
|
196
|
-
/** Order folders so every parent precedes its children — the invariant the schema validator enforces on
|
|
197
|
-
* pageFolders (a parentId must appear earlier in the array). Cycles (rejected upstream) are left in place. */
|
|
198
|
-
var sortFolders = (folders) => {
|
|
199
|
-
const byId = new Map(folders.map((f) => [f.id, f]));
|
|
200
|
-
const placed = /* @__PURE__ */ new Set();
|
|
201
|
-
const result = [];
|
|
202
|
-
const visit = (folder, ancestry) => {
|
|
203
|
-
if (placed.has(folder.id)) return;
|
|
204
|
-
const parent = folder.parentId ? byId.get(folder.parentId) : void 0;
|
|
205
|
-
if (parent && !ancestry.has(parent.id)) visit(parent, new Set(ancestry).add(folder.id));
|
|
206
|
-
if (!placed.has(folder.id)) {
|
|
207
|
-
placed.add(folder.id);
|
|
208
|
-
result.push(folder);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
for (const folder of folders) visit(folder, /* @__PURE__ */ new Set([folder.id]));
|
|
212
|
-
return result;
|
|
213
|
-
};
|
|
214
|
-
/** Ancestor ids of a folder (following parentId), stopping on a cycle. Used to reject a parent change that would
|
|
215
|
-
* make a folder its own ancestor. */
|
|
216
|
-
var folderAncestorIds = (folders, startParentId) => {
|
|
217
|
-
const byId = new Map(folders.map((f) => [f.id, f]));
|
|
218
|
-
const chain = [];
|
|
219
|
-
const seen = /* @__PURE__ */ new Set();
|
|
220
|
-
let current = startParentId ? byId.get(startParentId) : void 0;
|
|
221
|
-
while (current && !seen.has(current.id)) {
|
|
222
|
-
seen.add(current.id);
|
|
223
|
-
chain.push(current.id);
|
|
224
|
-
current = current.parentId ? byId.get(current.parentId) : void 0;
|
|
225
|
-
}
|
|
226
|
-
return chain;
|
|
227
|
-
};
|
|
228
|
-
/** Route params a page's slug binds (e.g. ":spaceId/update/*" → ["spaceId"]). These are valid {{name}}
|
|
229
|
-
* references on that page even though they are not space-level schema variables. */
|
|
230
|
-
var slugRouteParams = (slug) => {
|
|
231
|
-
const params = [];
|
|
232
|
-
for (const segment of slug.split("/")) if (segment.startsWith(":")) params.push(segment.slice(1).replace(/[*+?]+$/, ""));
|
|
233
|
-
return params;
|
|
234
|
-
};
|
|
235
|
-
/** Every route param bound by any page slug in the space (union), so {{name}} validation does not false-flag a
|
|
236
|
-
* page-scoped dynamic binding. */
|
|
237
|
-
var routeParamNames = (schema) => {
|
|
238
|
-
const params = /* @__PURE__ */ new Set();
|
|
239
|
-
for (const page of getPageElements(schema)) {
|
|
240
|
-
const slug = typeof page.attributes.slug === "string" ? page.attributes.slug : "";
|
|
241
|
-
for (const param of slugRouteParams(slug)) params.add(param);
|
|
242
|
-
}
|
|
243
|
-
return [...params];
|
|
244
|
-
};
|
|
245
|
-
/** Indexed lookup that reflects the runtime reality: a flat id may be dangling (rsc placeholders, stale items). */
|
|
246
|
-
var elementById = (schema, id) => schema.flat[id];
|
|
247
|
-
/** All element ids belonging to a page subtree (excluding the page root). */
|
|
248
|
-
var collectDescendants = (schema, rootId, acc) => {
|
|
249
|
-
const el = elementById(schema, rootId);
|
|
250
|
-
if (!el) return;
|
|
251
|
-
const childIds = el.definition.items ?? [];
|
|
252
|
-
for (const childId of childIds) if (elementById(schema, childId)) {
|
|
253
|
-
acc.push(childId);
|
|
254
|
-
collectDescendants(schema, childId, acc);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
var descendantIds = (schema, pageRootId) => {
|
|
258
|
-
const acc = [];
|
|
259
|
-
collectDescendants(schema, pageRootId, acc);
|
|
260
|
-
return acc;
|
|
261
|
-
};
|
|
262
|
-
/** Resolve a ref to a concrete element within a page subtree (or the page root itself). Accepts either the
|
|
263
|
-
* semantic ref (idRef) or the raw element id, so schemas predating idRef keep working through their ids. */
|
|
264
|
-
var resolveRef = (schema, page, ref) => {
|
|
265
|
-
if (elementRefOf(page) === ref || pageRefOf(page) === ref || page.id === ref) return page;
|
|
266
|
-
const index = spaceIndex(schema);
|
|
267
|
-
const el = index.elementByRef.get(ref);
|
|
268
|
-
return el && index.pageOf.get(el.id) === page.id ? el : void 0;
|
|
269
|
-
};
|
|
270
|
-
/** Ordered children of an element, honoring definition.items and skipping dangling ids. */
|
|
271
|
-
var orderedChildren = (schema, el) => {
|
|
272
|
-
return (el.definition.items ?? []).map((id) => schema.flat[id]).filter((child) => Boolean(child));
|
|
273
|
-
};
|
|
274
|
-
/** The page ref an element belongs to. 'unknown' when it has no page ancestor. */
|
|
275
|
-
var pageRefOfElement = (schema, el) => {
|
|
276
|
-
const pageId = spaceIndex(schema).pageOf.get(el.id);
|
|
277
|
-
const page = pageId ? schema.flat[pageId] : void 0;
|
|
278
|
-
return page ? pageRefOf(page) : "unknown";
|
|
279
|
-
};
|
|
280
|
-
/** Total number of descendant elements under a subtree (excluding the root). */
|
|
281
|
-
var descendantCount = (schema, rootId) => descendantIds(schema, rootId).length;
|
|
282
|
-
var emptySpaceMessage = "Space data not available";
|
|
283
|
-
/** The code a space-dependent answer carries when the connection reaches no space, so both the agent and a host UI
|
|
284
|
-
* can tell "this connection cannot do that" from "the call failed". */
|
|
285
|
-
var noSpaceError = "NO_SPACE_ATTACHED";
|
|
286
|
-
var unauthorizedSpaceMessage = "This connection has no space attached (a guest or widgets-only grant, or a token that carries no space), so NOTHING in a space can be read or edited — every other space tool will fail the same way, do not retry them. Use plitzi_render instead: it builds a self-contained widget offline, with no space, backend or account (read plitzi://render/guide). To edit a real space, the user must reconnect the integration and grant access to one.";
|
|
287
|
-
/** Raised when a space-dependent operation runs on a connection that resolves no spaceId. A type of its own so the
|
|
288
|
-
* host answers it as a STATE of the connection — a plain result the agent reads — instead of letting it surface as
|
|
289
|
-
* a failed call, which hosts render to the user as "cannot connect to this server". */
|
|
290
|
-
var NoSpaceError = class extends Error {
|
|
291
|
-
constructor() {
|
|
292
|
-
super(unauthorizedSpaceMessage);
|
|
293
|
-
this.name = "NoSpaceError";
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
var generateObjectId = () => {
|
|
297
|
-
return `${Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0")}${Array.from({ length: 16 }, () => Math.floor(Math.random() * 16).toString(16)).join("")}`;
|
|
298
|
-
};
|
|
299
|
-
//#endregion
|
|
300
|
-
export { NoSpaceError, cloneSpace, descendantCount, descendantIds, elementById, elementRefOf, emptySpace, emptySpaceMessage, findElementByRef, findFolderByRef, findPageByRef, folderAncestorIds, generateObjectId, getPageElements, indexAddElement, indexAddPage, indexInvalidateDetails, indexReRefElement, indexReRefPage, indexRemoveElements, indexRemovePage, isPageElement, nameOf, noSpaceError, orderedChildren, pageFoldersOf, pageRefOf, pageRefOfElement, resolveRef, routeParamNames, slugRouteParams, slugify, sortFolders, spaceIndex, strOr, unauthorizedSpaceMessage };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//#region src/modules/mcp/helpers/uris.ts
|
|
2
|
-
var guideUri = "plitzi://guide";
|
|
3
|
-
var typesUri = "plitzi://types";
|
|
4
|
-
var cssPropertiesUri = "plitzi://css-properties";
|
|
5
|
-
var primerUri = (env) => `plitzi://primer/${env}`;
|
|
6
|
-
var pagesUri = (env) => `plitzi://schema/${env}/pages`;
|
|
7
|
-
var pageUri = (env, ref) => `plitzi://schema/${env}/pages/${ref}`;
|
|
8
|
-
var elementUri = (env, ref) => `plitzi://schema/${env}/elements/${ref}`;
|
|
9
|
-
var schemaVarsUri = (env) => `plitzi://schema-variables/${env}`;
|
|
10
|
-
var settingsUri = (env) => `plitzi://settings/${env}`;
|
|
11
|
-
var interactionsUri = (env) => `plitzi://interactions/${env}`;
|
|
12
|
-
var dataSourcesUri = (env) => `plitzi://data-sources/${env}`;
|
|
13
|
-
var foldersUri = (env) => `plitzi://folders/${env}`;
|
|
14
|
-
var folderUri = (env, ref) => `plitzi://folders/${env}/${ref}`;
|
|
15
|
-
var defsUri = (env) => `plitzi://definitions/${env}`;
|
|
16
|
-
var defUri = (env, ref) => `plitzi://definitions/${env}/${ref}`;
|
|
17
|
-
var globalsUri = (env) => `plitzi://global-styles/${env}`;
|
|
18
|
-
var globalUri = (env, componentType) => `plitzi://global-styles/${env}/${componentType}`;
|
|
19
|
-
var idsUri = (env) => `plitzi://id-styles/${env}`;
|
|
20
|
-
var idUri = (env, targetId) => `plitzi://id-styles/${env}/${targetId}`;
|
|
21
|
-
var styleVarsUri = (env) => `plitzi://style-variables/${env}`;
|
|
22
|
-
var styleVarUri = (env, category) => `plitzi://style-variables/${env}/${category}`;
|
|
23
|
-
var aliasedRoots = [
|
|
24
|
-
"definitions",
|
|
25
|
-
"global-styles",
|
|
26
|
-
"id-styles",
|
|
27
|
-
"style-variables",
|
|
28
|
-
"schema-variables",
|
|
29
|
-
"folders"
|
|
30
|
-
];
|
|
31
|
-
var itemTemplates = (env) => [
|
|
32
|
-
pageUri(env, "{ref}"),
|
|
33
|
-
elementUri(env, "{ref}"),
|
|
34
|
-
defUri(env, "{ref}"),
|
|
35
|
-
globalUri(env, "{componentType}"),
|
|
36
|
-
idUri(env, "{targetId}"),
|
|
37
|
-
styleVarUri(env, "{category}"),
|
|
38
|
-
folderUri(env, "{ref}")
|
|
39
|
-
];
|
|
40
|
-
/** The remainder of `uri` after `prefix`, or undefined when it does not start with it — so a resolver matches a
|
|
41
|
-
* family and extracts its ref in one step, without repeating the prefix string for both the startsWith and slice. */
|
|
42
|
-
var afterPrefix = (uri, prefix) => uri.startsWith(prefix) ? uri.slice(prefix.length) : void 0;
|
|
43
|
-
//#endregion
|
|
44
|
-
export { afterPrefix, aliasedRoots, cssPropertiesUri, dataSourcesUri, defUri, defsUri, elementUri, folderUri, foldersUri, globalUri, globalsUri, guideUri, idUri, idsUri, interactionsUri, itemTemplates, pageUri, pagesUri, primerUri, schemaVarsUri, settingsUri, styleVarUri, styleVarsUri, typesUri };
|
|
@@ -1,31 +0,0 @@
|
|
|
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 };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { requestOrigin } from "../../../core/requestParser.js";
|
|
2
|
-
import { connectionId } from "./sign.js";
|
|
3
|
-
import { DEFAULT_PROXY_TOOLS } from "./types.js";
|
|
4
|
-
//#region src/modules/mcp/proxy/config.ts
|
|
5
|
-
var PROXY_PATH = "/__proxy";
|
|
6
|
-
var MAX_BYTES = 8388608;
|
|
7
|
-
var TTL_SECONDS = 604800;
|
|
8
|
-
/** What this deployment serves at its widget endpoint, or undefined when it serves none. A secret is what turns it
|
|
9
|
-
* on: without one the endpoint could not tell its own widgets' URLs from anyone else's, and an unsigned fetcher
|
|
10
|
-
* on a public origin is an open proxy. */
|
|
11
|
-
var proxySettings = (config) => {
|
|
12
|
-
const proxy = config.mcpAi?.proxy;
|
|
13
|
-
if (!proxy?.secret || proxy.enabled === false) return;
|
|
14
|
-
return {
|
|
15
|
-
path: proxy.path ?? "/__proxy",
|
|
16
|
-
secret: proxy.secret,
|
|
17
|
-
maxBytes: proxy.maxBytes ?? MAX_BYTES,
|
|
18
|
-
ttl: proxy.ttl ?? TTL_SECONDS,
|
|
19
|
-
tools: proxy.tools ?? DEFAULT_PROXY_TOOLS,
|
|
20
|
-
baseUrl: proxy.baseUrl
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
/** The endpoint as a widget must address it: absolute, because the page runs on the host's origin and a relative
|
|
24
|
-
* URL there points at the host. Falls back to the origin this request came in on, which is the right one whenever
|
|
25
|
-
* the MCP server owns its sub-domain; a deployment reached under a different public name sets `proxy.baseUrl`. */
|
|
26
|
-
var endpointOf = (settings, req) => {
|
|
27
|
-
const base = (settings.baseUrl ?? requestOrigin(req)).replace(/\/$/, "");
|
|
28
|
-
return base ? `${base}${settings.path}` : void 0;
|
|
29
|
-
};
|
|
30
|
-
/** The proxy a tool rewrites through. The grants it mints carry the fingerprint of THIS request's credential, so
|
|
31
|
-
* they belong to this connection. */
|
|
32
|
-
var requestProxy = (config, req) => {
|
|
33
|
-
const settings = proxySettings(config);
|
|
34
|
-
const endpoint = settings && endpointOf(settings, req);
|
|
35
|
-
if (!settings || !endpoint) return;
|
|
36
|
-
return {
|
|
37
|
-
endpoint,
|
|
38
|
-
secret: settings.secret,
|
|
39
|
-
identity: connectionId(req.headers.authorization, settings.secret),
|
|
40
|
-
ttl: settings.ttl,
|
|
41
|
-
tools: settings.tools
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
/** The proxy the ENDPOINT itself mints with, while serving an API answer that carries URLs of its own. The request
|
|
45
|
-
* it is serving comes from a sandboxed iframe and presents no credential, so the connection is the one signed into
|
|
46
|
-
* the grant being served — the widget's own — rather than one read off a header. */
|
|
47
|
-
var grantingProxy = (settings, req, identity) => {
|
|
48
|
-
const endpoint = endpointOf(settings, req);
|
|
49
|
-
return endpoint ? {
|
|
50
|
-
endpoint,
|
|
51
|
-
secret: settings.secret,
|
|
52
|
-
identity,
|
|
53
|
-
ttl: settings.ttl,
|
|
54
|
-
tools: settings.tools
|
|
55
|
-
} : void 0;
|
|
56
|
-
};
|
|
57
|
-
/** The proxy THIS tool may use, or undefined — the single place that decides it, so a tool cannot reach the
|
|
58
|
-
* endpoint by being wired to it later. A render authors a throwaway widget, so rewriting its URLs is invisible
|
|
59
|
-
* and lasts as long as the widget does; a tool that WRITES a space (plitzi_apply) would persist those URLs into
|
|
60
|
-
* content the user owns, which is why it is not on the list unless a deployment puts it there deliberately. */
|
|
61
|
-
var proxyForTool = (proxy, tool) => proxy?.tools.includes(tool) ? proxy : void 0;
|
|
62
|
-
//#endregion
|
|
63
|
-
export { PROXY_PATH, grantingProxy, proxyForTool, proxySettings, requestProxy };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { isPublicHost } from "./guard.js";
|
|
2
|
-
//#region src/modules/mcp/proxy/fetch.ts
|
|
3
|
-
var TIMEOUT_MS = 1e4;
|
|
4
|
-
var MAX_REDIRECTS = 4;
|
|
5
|
-
var ALLOWED_TYPES = {
|
|
6
|
-
asset: [
|
|
7
|
-
"image/",
|
|
8
|
-
"video/",
|
|
9
|
-
"audio/",
|
|
10
|
-
"font/",
|
|
11
|
-
"application/font",
|
|
12
|
-
"application/octet-stream"
|
|
13
|
-
],
|
|
14
|
-
data: [
|
|
15
|
-
"application/json",
|
|
16
|
-
"application/ld+json",
|
|
17
|
-
"application/xml",
|
|
18
|
-
"text/plain",
|
|
19
|
-
"text/csv",
|
|
20
|
-
"text/xml"
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
var REQUEST_HEADERS = {
|
|
24
|
-
asset: {
|
|
25
|
-
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0 Safari/537.36",
|
|
26
|
-
Accept: "image/avif,image/webp,image/apng,image/*,*/*;q=0.8",
|
|
27
|
-
"Accept-Language": "en-US,en;q=0.9"
|
|
28
|
-
},
|
|
29
|
-
data: {
|
|
30
|
-
"User-Agent": "PlitziWidget/1.0 (+https://plitzi.com)",
|
|
31
|
-
Accept: "application/json,text/plain;q=0.9,*/*;q=0.8"
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var failure = (status, reason) => ({
|
|
35
|
-
ok: false,
|
|
36
|
-
status,
|
|
37
|
-
reason
|
|
38
|
-
});
|
|
39
|
-
var parseTarget = (target) => {
|
|
40
|
-
try {
|
|
41
|
-
const url = new URL(target);
|
|
42
|
-
return url.protocol === "http:" || url.protocol === "https:" ? url : void 0;
|
|
43
|
-
} catch {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
/** Fetch a remote resource on the widget's behalf. Redirects are followed by hand rather than by fetch, because
|
|
48
|
-
* each hop is a new host that has to pass the same guard — an allowed URL that redirects into the private network
|
|
49
|
-
* would otherwise walk straight through it. (It is also what makes the redirect-based image services work at
|
|
50
|
-
* all: the sandbox loses the redirect, this does not.) */
|
|
51
|
-
var fetchResource = async (target, kind, maxBytes) => {
|
|
52
|
-
let url = parseTarget(target);
|
|
53
|
-
if (!url) return failure(400, "Only http(s) URLs can be fetched.");
|
|
54
|
-
const controller = new AbortController();
|
|
55
|
-
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
56
|
-
try {
|
|
57
|
-
for (let redirects = 0; redirects <= MAX_REDIRECTS; redirects += 1) {
|
|
58
|
-
if (!await isPublicHost(url.hostname)) return failure(403, "That host is not reachable from here.");
|
|
59
|
-
const response = await fetch(url, {
|
|
60
|
-
headers: REQUEST_HEADERS[kind],
|
|
61
|
-
redirect: "manual",
|
|
62
|
-
signal: controller.signal
|
|
63
|
-
});
|
|
64
|
-
const location = response.headers.get("location");
|
|
65
|
-
if (response.status >= 300 && response.status < 400 && location) {
|
|
66
|
-
const next = parseTarget(new URL(location, url).toString());
|
|
67
|
-
if (!next) return failure(502, "It redirected somewhere that is not an http(s) URL.");
|
|
68
|
-
url = next;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (!response.ok) return failure(502, `It could not be fetched (upstream ${response.status}).`);
|
|
72
|
-
const contentType = response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
73
|
-
if (!ALLOWED_TYPES[kind].some((allowed) => contentType.startsWith(allowed))) return failure(415, `That URL answered with ${contentType || "no content type"}, which is not ${kind === "asset" ? "an image or media file" : "data"}.`);
|
|
74
|
-
const declared = Number(response.headers.get("content-length"));
|
|
75
|
-
if (Number.isFinite(declared) && declared > maxBytes) return failure(413, "That response is too large to load in a widget.");
|
|
76
|
-
return {
|
|
77
|
-
ok: true,
|
|
78
|
-
contentType,
|
|
79
|
-
contentLength: Number.isFinite(declared) && declared > 0 ? declared : void 0,
|
|
80
|
-
body: response.body
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return failure(502, "It redirected too many times.");
|
|
84
|
-
} catch (error) {
|
|
85
|
-
return failure(504, error instanceof Error && error.name === "AbortError" ? "It timed out." : "unreachable");
|
|
86
|
-
} finally {
|
|
87
|
-
clearTimeout(timer);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
//#endregion
|
|
91
|
-
export { fetchResource };
|