@agimon-ai/po 0.0.0-alpha.21 → 0.0.0-alpha.210
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/LICENSE +97 -8
- package/README.md +37 -722
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/bin/cli.cjs +12 -7
- package/dist/bin/cli.cjs.map +1 -1
- package/dist/bin/cli.mjs +12 -7
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/bin/poRunner.cjs +24 -7
- package/dist/bin/poRunner.cjs.map +1 -1
- package/dist/bin/poRunner.d.mts +8 -0
- package/dist/bin/poRunner.d.mts.map +1 -1
- package/dist/bin/poRunner.mjs +24 -7
- package/dist/bin/poRunner.mjs.map +1 -1
- package/dist/bin/serve.cjs +28 -17
- package/dist/bin/serve.cjs.map +1 -1
- package/dist/bin/serve.mjs +28 -17
- package/dist/bin/serve.mjs.map +1 -1
- package/dist/builders/cli/extensionAssembler/index.cjs +53 -40
- package/dist/builders/cli/extensionAssembler/index.cjs.map +1 -1
- package/dist/builders/cli/extensionAssembler/index.d.mts +11 -6
- package/dist/builders/cli/extensionAssembler/index.d.mts.map +1 -1
- package/dist/builders/cli/extensionAssembler/index.mjs +53 -41
- package/dist/builders/cli/extensionAssembler/index.mjs.map +1 -1
- package/dist/catalog/index.json +662 -105
- package/dist/cli.cjs +9 -14
- package/dist/cli.d.mts +1 -3
- package/dist/cli.mjs +1 -3
- package/dist/commands.cjs +13 -15
- package/dist/commands.d.mts +1 -2
- package/dist/commands.mjs +1 -2
- package/dist/config.cjs +9 -14
- package/dist/config.d.mts +3 -2
- package/dist/config.mjs +3 -2
- package/dist/extensions/server.cjs +30 -23
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +31 -24
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/harnessContext.cjs +0 -1
- package/dist/harnessContext.d.mts +2 -2
- package/dist/harnessContext.mjs +1 -1
- package/dist/harnessState.cjs +2 -1
- package/dist/help.cjs +9 -11
- package/dist/help.d.mts +1 -2
- package/dist/help.mjs +1 -2
- package/dist/index.cjs +40 -67
- package/dist/index.d.mts +7 -16
- package/dist/index.mjs +7 -14
- package/dist/matrixOptions.cjs +10 -5
- package/dist/matrixOptions.d.mts +2 -2
- package/dist/matrixOptions.mjs +1 -1
- package/dist/package.cjs +11 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/projectTrust.cjs +3 -0
- package/dist/projectTrust.d.mts +2 -2
- package/dist/projectTrust.mjs +1 -1
- package/dist/repository.cjs +1 -0
- package/dist/repository.d.mts +2 -2
- package/dist/repository.mjs +1 -1
- package/dist/services.cjs +5 -20
- package/dist/services.d.mts +3 -8
- package/dist/services.mjs +3 -8
- package/dist/shared.cjs +4 -17
- package/dist/shared.d.mts +2 -2
- package/dist/shared.mjs +1 -1
- package/dist/src/bin/agentDirectory.cjs +19 -15
- package/dist/src/bin/agentDirectory.cjs.map +1 -1
- package/dist/src/bin/agentDirectory.mjs +16 -13
- package/dist/src/bin/agentDirectory.mjs.map +1 -1
- package/dist/src/builders/apiContractExport/index.cjs +23 -22
- package/dist/src/builders/apiContractExport/index.cjs.map +1 -1
- package/dist/src/builders/apiContractExport/index.mjs +22 -21
- package/dist/src/builders/apiContractExport/index.mjs.map +1 -1
- package/dist/src/builders/cli/entryResolution.cjs +2 -2
- package/dist/src/builders/cli/entryResolution.cjs.map +1 -1
- package/dist/src/builders/cli/entryResolution.mjs +1 -1
- package/dist/src/builders/cli/entryResolution.mjs.map +1 -1
- package/dist/src/builders/cli/harnessContext.cjs +38 -43
- package/dist/src/builders/cli/harnessContext.cjs.map +1 -1
- package/dist/src/builders/cli/harnessContext.d.mts +11 -10
- package/dist/src/builders/cli/harnessContext.d.mts.map +1 -1
- package/dist/src/builders/cli/harnessContext.mjs +37 -41
- package/dist/src/builders/cli/harnessContext.mjs.map +1 -1
- package/dist/src/builders/cli/sessionComposition.cjs +23 -12
- package/dist/src/builders/cli/sessionComposition.cjs.map +1 -1
- package/dist/src/builders/cli/sessionComposition.mjs +23 -12
- package/dist/src/builders/cli/sessionComposition.mjs.map +1 -1
- package/dist/src/builders/isolate/compile.cjs +226 -0
- package/dist/src/builders/isolate/compile.cjs.map +1 -0
- package/dist/src/builders/isolate/compile.mjs +222 -0
- package/dist/src/builders/isolate/compile.mjs.map +1 -0
- package/dist/src/builders/isolate/index.cjs +195 -0
- package/dist/src/builders/isolate/index.cjs.map +1 -0
- package/dist/src/builders/isolate/index.mjs +192 -0
- package/dist/src/builders/isolate/index.mjs.map +1 -0
- package/dist/src/builders/isolate/membrane.cjs +198 -0
- package/dist/src/builders/isolate/membrane.cjs.map +1 -0
- package/dist/src/builders/isolate/membrane.mjs +198 -0
- package/dist/src/builders/isolate/membrane.mjs.map +1 -0
- package/dist/src/builders/isolate/names.cjs +10 -0
- package/dist/src/builders/isolate/names.cjs.map +1 -0
- package/dist/src/builders/isolate/names.mjs +9 -0
- package/dist/src/builders/isolate/names.mjs.map +1 -0
- package/dist/src/builders/native/index.cjs +229 -67
- package/dist/src/builders/native/index.cjs.map +1 -1
- package/dist/src/builders/native/index.d.mts +4 -2
- package/dist/src/builders/native/index.d.mts.map +1 -1
- package/dist/src/builders/native/index.mjs +229 -68
- package/dist/src/builders/native/index.mjs.map +1 -1
- package/dist/src/builders/npm/index.cjs +76 -0
- package/dist/src/builders/npm/index.cjs.map +1 -0
- package/dist/src/builders/npm/index.mjs +73 -0
- package/dist/src/builders/npm/index.mjs.map +1 -0
- package/dist/src/builders/server/backgroundSync.cjs +62 -39
- package/dist/src/builders/server/backgroundSync.cjs.map +1 -1
- package/dist/src/builders/server/backgroundSync.mjs +62 -38
- package/dist/src/builders/server/backgroundSync.mjs.map +1 -1
- package/dist/src/builders/server/bundlerService.cjs +165 -35
- package/dist/src/builders/server/bundlerService.cjs.map +1 -1
- package/dist/src/builders/server/bundlerService.mjs +164 -36
- package/dist/src/builders/server/bundlerService.mjs.map +1 -1
- package/dist/src/builders/server/capabilities.cjs +103 -0
- package/dist/src/builders/server/capabilities.cjs.map +1 -0
- package/dist/src/builders/server/capabilities.mjs +101 -0
- package/dist/src/builders/server/capabilities.mjs.map +1 -0
- package/dist/src/builders/server/computerUseBinding.cjs +62 -10
- package/dist/src/builders/server/computerUseBinding.cjs.map +1 -1
- package/dist/src/builders/server/computerUseBinding.mjs +60 -8
- package/dist/src/builders/server/computerUseBinding.mjs.map +1 -1
- package/dist/src/builders/server/computerUseRecordings.cjs +152 -51
- package/dist/src/builders/server/computerUseRecordings.cjs.map +1 -1
- package/dist/src/builders/server/computerUseRecordings.mjs +158 -59
- package/dist/src/builders/server/computerUseRecordings.mjs.map +1 -1
- package/dist/src/builders/server/containedSessions.cjs +152 -0
- package/dist/src/builders/server/containedSessions.cjs.map +1 -0
- package/dist/src/builders/server/containedSessions.mjs +146 -0
- package/dist/src/builders/server/containedSessions.mjs.map +1 -0
- package/dist/src/builders/server/defaultWorkspace.cjs +46 -11
- package/dist/src/builders/server/defaultWorkspace.cjs.map +1 -1
- package/dist/src/builders/server/defaultWorkspace.mjs +42 -10
- package/dist/src/builders/server/defaultWorkspace.mjs.map +1 -1
- package/dist/src/builders/server/electronBinding.cjs +82 -0
- package/dist/src/builders/server/electronBinding.cjs.map +1 -0
- package/dist/src/builders/server/electronBinding.mjs +82 -0
- package/dist/src/builders/server/electronBinding.mjs.map +1 -0
- package/dist/src/builders/server/federation.cjs +364 -0
- package/dist/src/builders/server/federation.cjs.map +1 -0
- package/dist/src/builders/server/federation.mjs +363 -0
- package/dist/src/builders/server/federation.mjs.map +1 -0
- package/dist/src/builders/server/hostDisplayName.cjs +14 -0
- package/dist/src/builders/server/hostDisplayName.cjs.map +1 -0
- package/dist/src/builders/server/hostDisplayName.mjs +14 -0
- package/dist/src/builders/server/hostDisplayName.mjs.map +1 -0
- package/dist/src/builders/server/hostModelGateway.cjs +41 -0
- package/dist/src/builders/server/hostModelGateway.cjs.map +1 -0
- package/dist/src/builders/server/hostModelGateway.mjs +39 -0
- package/dist/src/builders/server/hostModelGateway.mjs.map +1 -0
- package/dist/src/builders/server/hostTeam.cjs +188 -0
- package/dist/src/builders/server/hostTeam.cjs.map +1 -0
- package/dist/src/builders/server/hostTeam.mjs +180 -0
- package/dist/src/builders/server/hostTeam.mjs.map +1 -0
- package/dist/src/builders/server/idleRestart.cjs +185 -40
- package/dist/src/builders/server/idleRestart.cjs.map +1 -1
- package/dist/src/builders/server/idleRestart.mjs +176 -39
- package/dist/src/builders/server/idleRestart.mjs.map +1 -1
- package/dist/src/builders/server/index.cjs +33 -19
- package/dist/src/builders/server/index.cjs.map +1 -1
- package/dist/src/builders/server/index.mjs +33 -18
- package/dist/src/builders/server/index.mjs.map +1 -1
- package/dist/src/builders/server/liveActivityPush.cjs +202 -0
- package/dist/src/builders/server/liveActivityPush.cjs.map +1 -0
- package/dist/src/builders/server/liveActivityPush.mjs +202 -0
- package/dist/src/builders/server/liveActivityPush.mjs.map +1 -0
- package/dist/src/builders/server/logSink.cjs +12 -10
- package/dist/src/builders/server/logSink.cjs.map +1 -1
- package/dist/src/builders/server/logSink.mjs +12 -10
- package/dist/src/builders/server/logSink.mjs.map +1 -1
- package/dist/src/builders/server/mcpApp.cjs +27 -20
- package/dist/src/builders/server/mcpApp.cjs.map +1 -1
- package/dist/src/builders/server/mcpApp.mjs +25 -18
- package/dist/src/builders/server/mcpApp.mjs.map +1 -1
- package/dist/src/builders/server/mcpAppBuild.cjs +61 -41
- package/dist/src/builders/server/mcpAppBuild.cjs.map +1 -1
- package/dist/src/builders/server/mcpAppBuild.d.mts +3 -6
- package/dist/src/builders/server/mcpAppBuild.d.mts.map +1 -1
- package/dist/src/builders/server/mcpAppBuild.mjs +61 -40
- package/dist/src/builders/server/mcpAppBuild.mjs.map +1 -1
- package/dist/src/builders/server/mcpBundle.cjs +20 -16
- package/dist/src/builders/server/mcpBundle.cjs.map +1 -1
- package/dist/src/builders/server/mcpBundle.d.mts +2 -1
- package/dist/src/builders/server/mcpBundle.d.mts.map +1 -1
- package/dist/src/builders/server/mcpBundle.mjs +20 -15
- package/dist/src/builders/server/mcpBundle.mjs.map +1 -1
- package/dist/src/builders/server/nativePush.cjs +229 -0
- package/dist/src/builders/server/nativePush.cjs.map +1 -0
- package/dist/src/builders/server/nativePush.mjs +228 -0
- package/dist/src/builders/server/nativePush.mjs.map +1 -0
- package/dist/src/builders/server/network.cjs +887 -0
- package/dist/src/builders/server/network.cjs.map +1 -0
- package/dist/src/builders/server/network.mjs +886 -0
- package/dist/src/builders/server/network.mjs.map +1 -0
- package/dist/src/builders/server/networkGateway.cjs +123 -0
- package/dist/src/builders/server/networkGateway.cjs.map +1 -0
- package/dist/src/builders/server/networkGateway.mjs +123 -0
- package/dist/src/builders/server/networkGateway.mjs.map +1 -0
- package/dist/src/builders/server/networkRelay.cjs +83 -0
- package/dist/src/builders/server/networkRelay.cjs.map +1 -0
- package/dist/src/builders/server/networkRelay.mjs +81 -0
- package/dist/src/builders/server/networkRelay.mjs.map +1 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.cjs +72 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.cjs.map +1 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.mjs +72 -0
- package/dist/src/builders/server/orgPluginLibraryBinding.mjs.map +1 -0
- package/dist/src/builders/server/packageReloadCheck.cjs +46 -2
- package/dist/src/builders/server/packageReloadCheck.cjs.map +1 -1
- package/dist/src/builders/server/packageReloadCheck.mjs +46 -3
- package/dist/src/builders/server/packageReloadCheck.mjs.map +1 -1
- package/dist/src/builders/server/packageUrl.cjs +161 -58
- package/dist/src/builders/server/packageUrl.cjs.map +1 -1
- package/dist/src/builders/server/packageUrl.mjs +162 -58
- package/dist/src/builders/server/packageUrl.mjs.map +1 -1
- package/dist/src/builders/server/privateRelay.cjs +309 -0
- package/dist/src/builders/server/privateRelay.cjs.map +1 -0
- package/dist/src/builders/server/privateRelay.mjs +305 -0
- package/dist/src/builders/server/privateRelay.mjs.map +1 -0
- package/dist/src/builders/server/privateRelayCarrier.cjs +316 -0
- package/dist/src/builders/server/privateRelayCarrier.cjs.map +1 -0
- package/dist/src/builders/server/privateRelayCarrier.mjs +309 -0
- package/dist/src/builders/server/privateRelayCarrier.mjs.map +1 -0
- package/dist/src/builders/server/runtime.cjs +2731 -485
- package/dist/src/builders/server/runtime.cjs.map +1 -1
- package/dist/src/builders/server/runtime.mjs +2741 -499
- package/dist/src/builders/server/runtime.mjs.map +1 -1
- package/dist/src/builders/server/runtimeResources.cjs +37 -0
- package/dist/src/builders/server/runtimeResources.cjs.map +1 -1
- package/dist/src/builders/server/runtimeResources.mjs +38 -2
- package/dist/src/builders/server/runtimeResources.mjs.map +1 -1
- package/dist/src/builders/server/sandboxRouter.cjs +815 -0
- package/dist/src/builders/server/sandboxRouter.cjs.map +1 -0
- package/dist/src/builders/server/sandboxRouter.mjs +811 -0
- package/dist/src/builders/server/sandboxRouter.mjs.map +1 -0
- package/dist/src/builders/server/sandboxSessionHandoff.cjs +298 -0
- package/dist/src/builders/server/sandboxSessionHandoff.cjs.map +1 -0
- package/dist/src/builders/server/sandboxSessionHandoff.mjs +287 -0
- package/dist/src/builders/server/sandboxSessionHandoff.mjs.map +1 -0
- package/dist/src/builders/server/scopeReloadController.cjs +80 -0
- package/dist/src/builders/server/scopeReloadController.cjs.map +1 -0
- package/dist/src/builders/server/scopeReloadController.mjs +80 -0
- package/dist/src/builders/server/scopeReloadController.mjs.map +1 -0
- package/dist/src/builders/server/selectionStatus.cjs +2 -2
- package/dist/src/builders/server/selectionStatus.cjs.map +1 -1
- package/dist/src/builders/server/selectionStatus.mjs +2 -2
- package/dist/src/builders/server/selectionStatus.mjs.map +1 -1
- package/dist/src/builders/server/sessionArguments.cjs +65 -7
- package/dist/src/builders/server/sessionArguments.cjs.map +1 -1
- package/dist/src/builders/server/sessionArguments.mjs +64 -8
- package/dist/src/builders/server/sessionArguments.mjs.map +1 -1
- package/dist/src/builders/server/sessionRemoval.cjs +233 -0
- package/dist/src/builders/server/sessionRemoval.cjs.map +1 -0
- package/dist/src/builders/server/sessionRemoval.mjs +224 -0
- package/dist/src/builders/server/sessionRemoval.mjs.map +1 -0
- package/dist/src/builders/server/sessionSummaries.cjs +32 -0
- package/dist/src/builders/server/sessionSummaries.cjs.map +1 -0
- package/dist/src/builders/server/sessionSummaries.mjs +31 -0
- package/dist/src/builders/server/sessionSummaries.mjs.map +1 -0
- package/dist/src/builders/server/shutdown.cjs +23 -0
- package/dist/src/builders/server/shutdown.cjs.map +1 -1
- package/dist/src/builders/server/shutdown.mjs +21 -1
- package/dist/src/builders/server/shutdown.mjs.map +1 -1
- package/dist/src/builders/server/shutdownStack.cjs +44 -0
- package/dist/src/builders/server/shutdownStack.cjs.map +1 -0
- package/dist/src/builders/server/shutdownStack.mjs +43 -0
- package/dist/src/builders/server/shutdownStack.mjs.map +1 -0
- package/dist/src/builders/server/toolBoundaryHold.cjs +55 -0
- package/dist/src/builders/server/toolBoundaryHold.cjs.map +1 -0
- package/dist/src/builders/server/toolBoundaryHold.mjs +55 -0
- package/dist/src/builders/server/toolBoundaryHold.mjs.map +1 -0
- package/dist/src/builders/server/watcherService.cjs +55 -28
- package/dist/src/builders/server/watcherService.cjs.map +1 -1
- package/dist/src/builders/server/watcherService.mjs +55 -27
- package/dist/src/builders/server/watcherService.mjs.map +1 -1
- package/dist/src/builders/server/webTemplateDecision.cjs +7 -3
- package/dist/src/builders/server/webTemplateDecision.cjs.map +1 -1
- package/dist/src/builders/server/webTemplateDecision.mjs +7 -3
- package/dist/src/builders/server/webTemplateDecision.mjs.map +1 -1
- package/dist/src/builders/server/workspaceAdmission.cjs +96 -0
- package/dist/src/builders/server/workspaceAdmission.cjs.map +1 -0
- package/dist/src/builders/server/workspaceAdmission.mjs +90 -0
- package/dist/src/builders/server/workspaceAdmission.mjs.map +1 -0
- package/dist/src/builders/server/workspaceCheckout.cjs +16 -7
- package/dist/src/builders/server/workspaceCheckout.cjs.map +1 -1
- package/dist/src/builders/server/workspaceCheckout.mjs +16 -7
- package/dist/src/builders/server/workspaceCheckout.mjs.map +1 -1
- package/dist/src/builders/web/bundle.cjs +16 -14
- package/dist/src/builders/web/bundle.cjs.map +1 -1
- package/dist/src/builders/web/bundle.d.mts +3 -0
- package/dist/src/builders/web/bundle.d.mts.map +1 -1
- package/dist/src/builders/web/bundle.mjs +15 -13
- package/dist/src/builders/web/bundle.mjs.map +1 -1
- package/dist/src/builders/web/index.cjs +77 -59
- package/dist/src/builders/web/index.cjs.map +1 -1
- package/dist/src/builders/web/index.d.mts +19 -14
- package/dist/src/builders/web/index.d.mts.map +1 -1
- package/dist/src/builders/web/index.mjs +76 -58
- package/dist/src/builders/web/index.mjs.map +1 -1
- package/dist/src/builders/web/webPluginGenerate.cjs +84 -45
- package/dist/src/builders/web/webPluginGenerate.cjs.map +1 -1
- package/dist/src/builders/web/webPluginGenerate.d.mts +13 -4
- package/dist/src/builders/web/webPluginGenerate.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginGenerate.mjs +82 -44
- package/dist/src/builders/web/webPluginGenerate.mjs.map +1 -1
- package/dist/src/builders/web/webPluginManifest.cjs +24 -17
- package/dist/src/builders/web/webPluginManifest.cjs.map +1 -1
- package/dist/src/builders/web/webPluginManifest.d.mts +11 -23
- package/dist/src/builders/web/webPluginManifest.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginManifest.mjs +23 -16
- package/dist/src/builders/web/webPluginManifest.mjs.map +1 -1
- package/dist/src/builders/web/webPluginScan.cjs +11 -8
- package/dist/src/builders/web/webPluginScan.cjs.map +1 -1
- package/dist/src/builders/web/webPluginScan.d.mts +1 -1
- package/dist/src/builders/web/webPluginScan.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginScan.mjs +10 -7
- package/dist/src/builders/web/webPluginScan.mjs.map +1 -1
- package/dist/src/builders/web/webPluginVite.cjs +5 -5
- package/dist/src/builders/web/webPluginVite.cjs.map +1 -1
- package/dist/src/builders/web/webPluginVite.d.mts +1 -1
- package/dist/src/builders/web/webPluginVite.d.mts.map +1 -1
- package/dist/src/builders/web/webPluginVite.mjs +3 -3
- package/dist/src/builders/web/webPluginVite.mjs.map +1 -1
- package/dist/src/cli/cliApp.cjs +18 -19
- package/dist/src/cli/cliApp.cjs.map +1 -1
- package/dist/src/cli/cliApp.d.mts +1 -1
- package/dist/src/cli/cliApp.d.mts.map +1 -1
- package/dist/src/cli/cliApp.mjs +18 -19
- package/dist/src/cli/cliApp.mjs.map +1 -1
- package/dist/src/cli/commands/api-export/index.cjs +14 -13
- package/dist/src/cli/commands/api-export/index.cjs.map +1 -1
- package/dist/src/cli/commands/api-export/index.mjs +13 -12
- package/dist/src/cli/commands/api-export/index.mjs.map +1 -1
- package/dist/src/cli/commands/doctor/help.cjs +4 -3
- package/dist/src/cli/commands/doctor/help.cjs.map +1 -1
- package/dist/src/cli/commands/doctor/help.d.mts.map +1 -1
- package/dist/src/cli/commands/doctor/help.mjs +4 -3
- package/dist/src/cli/commands/doctor/help.mjs.map +1 -1
- package/dist/src/cli/commands/doctor/index.cjs +30 -17
- package/dist/src/cli/commands/doctor/index.cjs.map +1 -1
- package/dist/src/cli/commands/doctor/index.d.mts +4 -4
- package/dist/src/cli/commands/doctor/index.d.mts.map +1 -1
- package/dist/src/cli/commands/doctor/index.mjs +28 -15
- package/dist/src/cli/commands/doctor/index.mjs.map +1 -1
- package/dist/src/cli/commands/emit-mcp/index.cjs +3 -2
- package/dist/src/cli/commands/emit-mcp/index.cjs.map +1 -1
- package/dist/src/cli/commands/emit-mcp/index.d.mts.map +1 -1
- package/dist/src/cli/commands/emit-mcp/index.mjs +3 -2
- package/dist/src/cli/commands/emit-mcp/index.mjs.map +1 -1
- package/dist/src/cli/commands/explain/index.cjs +53 -38
- package/dist/src/cli/commands/explain/index.cjs.map +1 -1
- package/dist/src/cli/commands/explain/index.d.mts +3 -4
- package/dist/src/cli/commands/explain/index.d.mts.map +1 -1
- package/dist/src/cli/commands/explain/index.mjs +52 -37
- package/dist/src/cli/commands/explain/index.mjs.map +1 -1
- package/dist/src/cli/commands/init/help.cjs +3 -2
- package/dist/src/cli/commands/init/help.cjs.map +1 -1
- package/dist/src/cli/commands/init/help.d.mts.map +1 -1
- package/dist/src/cli/commands/init/help.mjs +3 -2
- package/dist/src/cli/commands/init/help.mjs.map +1 -1
- package/dist/src/cli/commands/init/index.cjs +17 -12
- package/dist/src/cli/commands/init/index.cjs.map +1 -1
- package/dist/src/cli/commands/init/index.d.mts.map +1 -1
- package/dist/src/cli/commands/init/index.mjs +16 -11
- package/dist/src/cli/commands/init/index.mjs.map +1 -1
- package/dist/src/cli/commands/init/presenter.cjs +29 -21
- package/dist/src/cli/commands/init/presenter.cjs.map +1 -1
- package/dist/src/cli/commands/init/presenter.mjs +29 -21
- package/dist/src/cli/commands/init/presenter.mjs.map +1 -1
- package/dist/src/cli/commands/sync/help.cjs +7 -3
- package/dist/src/cli/commands/sync/help.cjs.map +1 -1
- package/dist/src/cli/commands/sync/help.d.mts.map +1 -1
- package/dist/src/cli/commands/sync/help.mjs +7 -3
- package/dist/src/cli/commands/sync/help.mjs.map +1 -1
- package/dist/src/cli/commands/sync/index.cjs +72 -40
- package/dist/src/cli/commands/sync/index.cjs.map +1 -1
- package/dist/src/cli/commands/sync/index.d.mts.map +1 -1
- package/dist/src/cli/commands/sync/index.mjs +69 -37
- package/dist/src/cli/commands/sync/index.mjs.map +1 -1
- package/dist/src/cli/commands/sync/presenter.cjs +10 -1
- package/dist/src/cli/commands/sync/presenter.cjs.map +1 -1
- package/dist/src/cli/commands/sync/presenter.d.mts +0 -9
- package/dist/src/cli/commands/sync/presenter.d.mts.map +1 -1
- package/dist/src/cli/commands/sync/presenter.mjs +10 -1
- package/dist/src/cli/commands/sync/presenter.mjs.map +1 -1
- package/dist/src/cli/commands/web/index.cjs +7 -6
- package/dist/src/cli/commands/web/index.cjs.map +1 -1
- package/dist/src/cli/commands/web/index.mjs +6 -5
- package/dist/src/cli/commands/web/index.mjs.map +1 -1
- package/dist/src/cli/harnessOptions.cjs +15 -24
- package/dist/src/cli/harnessOptions.cjs.map +1 -1
- package/dist/src/cli/harnessOptions.d.mts +2 -2
- package/dist/src/cli/harnessOptions.d.mts.map +1 -1
- package/dist/src/cli/harnessOptions.mjs +14 -22
- package/dist/src/cli/harnessOptions.mjs.map +1 -1
- package/dist/src/cli/help.cjs +20 -26
- package/dist/src/cli/help.cjs.map +1 -1
- package/dist/src/cli/help.d.mts +1 -2
- package/dist/src/cli/help.d.mts.map +1 -1
- package/dist/src/cli/help.mjs +15 -20
- package/dist/src/cli/help.mjs.map +1 -1
- package/dist/src/cli/locale.cjs +25 -0
- package/dist/src/cli/locale.cjs.map +1 -0
- package/dist/src/cli/locale.mjs +22 -0
- package/dist/src/cli/locale.mjs.map +1 -0
- package/dist/src/cli/matrixOptions.cjs +85 -37
- package/dist/src/cli/matrixOptions.cjs.map +1 -1
- package/dist/src/cli/matrixOptions.d.mts +22 -16
- package/dist/src/cli/matrixOptions.d.mts.map +1 -1
- package/dist/src/cli/matrixOptions.mjs +76 -33
- package/dist/src/cli/matrixOptions.mjs.map +1 -1
- package/dist/src/cli/options.cjs +51 -128
- package/dist/src/cli/options.cjs.map +1 -1
- package/dist/src/cli/options.d.mts +1 -1
- package/dist/src/cli/options.d.mts.map +1 -1
- package/dist/src/cli/options.mjs +53 -130
- package/dist/src/cli/options.mjs.map +1 -1
- package/dist/src/cli/router.cjs +0 -1
- package/dist/src/cli/router.cjs.map +1 -1
- package/dist/src/cli/router.d.mts +1 -1
- package/dist/src/cli/router.mjs +0 -1
- package/dist/src/cli/router.mjs.map +1 -1
- package/dist/src/cli/server/options.cjs +37 -7
- package/dist/src/cli/server/options.cjs.map +1 -1
- package/dist/src/cli/server/options.mjs +37 -7
- package/dist/src/cli/server/options.mjs.map +1 -1
- package/dist/src/cli/server/processGuards.cjs +22 -15
- package/dist/src/cli/server/processGuards.cjs.map +1 -1
- package/dist/src/cli/server/processGuards.mjs +21 -14
- package/dist/src/cli/server/processGuards.mjs.map +1 -1
- package/dist/src/cli/server/restartPolicy.cjs +38 -0
- package/dist/src/cli/server/restartPolicy.cjs.map +1 -0
- package/dist/src/cli/server/restartPolicy.d.mts +21 -0
- package/dist/src/cli/server/restartPolicy.d.mts.map +1 -0
- package/dist/src/cli/server/restartPolicy.mjs +36 -0
- package/dist/src/cli/server/restartPolicy.mjs.map +1 -0
- package/dist/src/cli/server/run.cjs +12 -11
- package/dist/src/cli/server/run.cjs.map +1 -1
- package/dist/src/cli/server/run.mjs +11 -10
- package/dist/src/cli/server/run.mjs.map +1 -1
- package/dist/src/cli/server/supervise.cjs +89 -0
- package/dist/src/cli/server/supervise.cjs.map +1 -0
- package/dist/src/cli/server/supervise.mjs +89 -0
- package/dist/src/cli/server/supervise.mjs.map +1 -0
- package/dist/src/composition/harnessState/index.cjs +2 -1
- package/dist/src/composition/harnessState/index.cjs.map +1 -1
- package/dist/src/composition/harnessState/index.d.mts +2 -1
- package/dist/src/composition/harnessState/index.d.mts.map +1 -1
- package/dist/src/composition/harnessState/index.mjs +2 -1
- package/dist/src/composition/harnessState/index.mjs.map +1 -1
- package/dist/src/composition/layerPackageInstaller/index.cjs +293 -86
- package/dist/src/composition/layerPackageInstaller/index.cjs.map +1 -1
- package/dist/src/composition/layerPackageInstaller/index.d.mts +25 -2
- package/dist/src/composition/layerPackageInstaller/index.d.mts.map +1 -1
- package/dist/src/composition/layerPackageInstaller/index.mjs +295 -94
- package/dist/src/composition/layerPackageInstaller/index.mjs.map +1 -1
- package/dist/src/composition/marketplaceCatalog/index.cjs +136 -0
- package/dist/src/composition/marketplaceCatalog/index.cjs.map +1 -0
- package/dist/src/composition/marketplaceCatalog/index.mjs +132 -0
- package/dist/src/composition/marketplaceCatalog/index.mjs.map +1 -0
- package/dist/src/composition/orgPluginActivation/index.cjs +179 -0
- package/dist/src/composition/orgPluginActivation/index.cjs.map +1 -0
- package/dist/src/composition/orgPluginActivation/index.mjs +177 -0
- package/dist/src/composition/orgPluginActivation/index.mjs.map +1 -0
- package/dist/src/composition/orgPluginLibrary/index.cjs +205 -0
- package/dist/src/composition/orgPluginLibrary/index.cjs.map +1 -0
- package/dist/src/composition/orgPluginLibrary/index.mjs +200 -0
- package/dist/src/composition/orgPluginLibrary/index.mjs.map +1 -0
- package/dist/src/composition/pluginMarketplace/index.cjs +304 -0
- package/dist/src/composition/pluginMarketplace/index.cjs.map +1 -0
- package/dist/src/composition/pluginMarketplace/index.mjs +302 -0
- package/dist/src/composition/pluginMarketplace/index.mjs.map +1 -0
- package/dist/src/composition/poHomeMigration/index.cjs +46 -26
- package/dist/src/composition/poHomeMigration/index.cjs.map +1 -1
- package/dist/src/composition/poHomeMigration/index.d.mts.map +1 -1
- package/dist/src/composition/poHomeMigration/index.mjs +45 -25
- package/dist/src/composition/poHomeMigration/index.mjs.map +1 -1
- package/dist/src/composition/projectTrust/index.cjs +40 -3
- package/dist/src/composition/projectTrust/index.cjs.map +1 -1
- package/dist/src/composition/projectTrust/index.d.mts +8 -0
- package/dist/src/composition/projectTrust/index.d.mts.map +1 -1
- package/dist/src/composition/projectTrust/index.mjs +33 -2
- package/dist/src/composition/projectTrust/index.mjs.map +1 -1
- package/dist/src/composition/repository/index.cjs +29 -12
- package/dist/src/composition/repository/index.cjs.map +1 -1
- package/dist/src/composition/repository/index.d.mts +10 -3
- package/dist/src/composition/repository/index.d.mts.map +1 -1
- package/dist/src/composition/repository/index.mjs +29 -13
- package/dist/src/composition/repository/index.mjs.map +1 -1
- package/dist/src/composition/syncPrune/index.cjs +23 -16
- package/dist/src/composition/syncPrune/index.cjs.map +1 -1
- package/dist/src/composition/syncPrune/index.d.mts.map +1 -1
- package/dist/src/composition/syncPrune/index.mjs +22 -15
- package/dist/src/composition/syncPrune/index.mjs.map +1 -1
- package/dist/src/composition/syncService/index.cjs +441 -194
- package/dist/src/composition/syncService/index.cjs.map +1 -1
- package/dist/src/composition/syncService/index.d.mts +4 -1
- package/dist/src/composition/syncService/index.d.mts.map +1 -1
- package/dist/src/composition/syncService/index.mjs +440 -196
- package/dist/src/composition/syncService/index.mjs.map +1 -1
- package/dist/src/composition/syncService/localBuilds.cjs +41 -37
- package/dist/src/composition/syncService/localBuilds.cjs.map +1 -1
- package/dist/src/composition/syncService/localBuilds.mjs +40 -37
- package/dist/src/composition/syncService/localBuilds.mjs.map +1 -1
- package/dist/src/composition/transitionLayers.cjs.map +1 -1
- package/dist/src/composition/transitionLayers.d.mts +3 -3
- package/dist/src/composition/transitionLayers.d.mts.map +1 -1
- package/dist/src/composition/transitionLayers.mjs.map +1 -1
- package/dist/src/composition/types/harness.d.mts +4 -9
- package/dist/src/composition/types/harness.d.mts.map +1 -1
- package/dist/src/extensions/setupDiagnostics.cjs +8 -8
- package/dist/src/extensions/setupDiagnostics.cjs.map +1 -1
- package/dist/src/extensions/setupDiagnostics.mjs +8 -8
- package/dist/src/extensions/setupDiagnostics.mjs.map +1 -1
- package/dist/webBuilder.cjs +1 -0
- package/dist/webBuilder.d.mts +2 -2
- package/dist/webBuilder.mjs +2 -2
- package/docs/server/api-export.md +9 -9
- package/docs/server/api.md +22 -125
- package/docs/server/getting-started.md +21 -85
- package/docs/server/index.md +13 -58
- package/docs/server/ipc.md +26 -72
- package/docs/server/lifecycle.md +18 -91
- package/docs/server/security.md +20 -80
- package/package.json +47 -67
- package/src/prompts/po-author-extension/SKILL.md +2 -2
- package/src/prompts/po-author-extension/references/extension-contract.md +4 -6
- package/dist/antigravity.cjs +0 -5
- package/dist/antigravity.d.mts +0 -2
- package/dist/antigravity.mjs +0 -1
- package/dist/codex.cjs +0 -8
- package/dist/codex.d.mts +0 -2
- package/dist/codex.mjs +0 -1
- package/dist/compatibility.cjs +0 -27
- package/dist/compatibility.d.mts +0 -6
- package/dist/compatibility.mjs +0 -6
- package/dist/compatibilityCommand.cjs +0 -4
- package/dist/compatibilityCommand.d.mts +0 -2
- package/dist/compatibilityCommand.mjs +0 -1
- package/dist/compatibilityContext.cjs +0 -3
- package/dist/compatibilityContext.d.mts +0 -2
- package/dist/compatibilityContext.mjs +0 -1
- package/dist/compatibilityOptions.cjs +0 -5
- package/dist/compatibilityOptions.d.mts +0 -2
- package/dist/compatibilityOptions.mjs +0 -1
- package/dist/process.cjs +0 -12
- package/dist/process.d.mts +0 -2
- package/dist/process.mjs +0 -1
- package/dist/src/builders/hooks/index.cjs +0 -238
- package/dist/src/builders/hooks/index.cjs.map +0 -1
- package/dist/src/builders/hooks/index.mjs +0 -231
- package/dist/src/builders/hooks/index.mjs.map +0 -1
- package/dist/src/cli/commands/compat/context.cjs +0 -115
- package/dist/src/cli/commands/compat/context.cjs.map +0 -1
- package/dist/src/cli/commands/compat/context.d.mts +0 -22
- package/dist/src/cli/commands/compat/context.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/context.mjs +0 -110
- package/dist/src/cli/commands/compat/context.mjs.map +0 -1
- package/dist/src/cli/commands/compat/help.cjs +0 -26
- package/dist/src/cli/commands/compat/help.cjs.map +0 -1
- package/dist/src/cli/commands/compat/help.d.mts +0 -4
- package/dist/src/cli/commands/compat/help.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/help.mjs +0 -25
- package/dist/src/cli/commands/compat/help.mjs.map +0 -1
- package/dist/src/cli/commands/compat/index.cjs +0 -73
- package/dist/src/cli/commands/compat/index.cjs.map +0 -1
- package/dist/src/cli/commands/compat/index.d.mts +0 -14
- package/dist/src/cli/commands/compat/index.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/index.mjs +0 -70
- package/dist/src/cli/commands/compat/index.mjs.map +0 -1
- package/dist/src/cli/commands/compat/options.cjs +0 -88
- package/dist/src/cli/commands/compat/options.cjs.map +0 -1
- package/dist/src/cli/commands/compat/options.d.mts +0 -15
- package/dist/src/cli/commands/compat/options.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/options.mjs +0 -86
- package/dist/src/cli/commands/compat/options.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/antigravity.cjs +0 -294
- package/dist/src/cli/commands/compat/providers/antigravity.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/antigravity.d.mts +0 -9
- package/dist/src/cli/commands/compat/providers/antigravity.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/antigravity.mjs +0 -289
- package/dist/src/cli/commands/compat/providers/antigravity.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/codex.cjs +0 -178
- package/dist/src/cli/commands/compat/providers/codex.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/codex.d.mts +0 -17
- package/dist/src/cli/commands/compat/providers/codex.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/codex.mjs +0 -170
- package/dist/src/cli/commands/compat/providers/codex.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/index.cjs +0 -65
- package/dist/src/cli/commands/compat/providers/index.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/index.d.mts +0 -15
- package/dist/src/cli/commands/compat/providers/index.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/index.mjs +0 -45
- package/dist/src/cli/commands/compat/providers/index.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/process.cjs +0 -172
- package/dist/src/cli/commands/compat/providers/process.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/process.d.mts +0 -33
- package/dist/src/cli/commands/compat/providers/process.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/process.mjs +0 -159
- package/dist/src/cli/commands/compat/providers/process.mjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/shared.cjs +0 -76
- package/dist/src/cli/commands/compat/providers/shared.cjs.map +0 -1
- package/dist/src/cli/commands/compat/providers/shared.d.mts +0 -40
- package/dist/src/cli/commands/compat/providers/shared.d.mts.map +0 -1
- package/dist/src/cli/commands/compat/providers/shared.mjs +0 -61
- package/dist/src/cli/commands/compat/providers/shared.mjs.map +0 -1
- package/dist/src/cli/commands/compat/types.d.mts +0 -31
- package/dist/src/cli/commands/compat/types.d.mts.map +0 -1
- package/dist/src/cli/commands/init/constants.cjs +0 -11
- package/dist/src/cli/commands/init/constants.cjs.map +0 -1
- package/dist/src/cli/commands/init/constants.mjs +0 -11
- package/dist/src/cli/commands/init/constants.mjs.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let
|
|
3
|
-
node_fs = require_runtime.__toESM(node_fs, 1);
|
|
2
|
+
let node_module = require("node:module");
|
|
4
3
|
let node_path = require("node:path");
|
|
5
4
|
node_path = require_runtime.__toESM(node_path, 1);
|
|
6
|
-
let
|
|
5
|
+
let node_fs_promises = require("node:fs/promises");
|
|
6
|
+
node_fs_promises = require_runtime.__toESM(node_fs_promises, 1);
|
|
7
7
|
let node_crypto = require("node:crypto");
|
|
8
8
|
node_crypto = require_runtime.__toESM(node_crypto, 1);
|
|
9
9
|
//#region src/builders/server/mcpApp.ts
|
|
10
10
|
/** Resolve generator-owned inputs before looking up an immutable build. */
|
|
11
|
-
function mcpAppInputs(componentsRoot) {
|
|
11
|
+
async function mcpAppInputs(componentsRoot) {
|
|
12
12
|
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
13
13
|
const root = componentsRoot ?? node_path.default.dirname(require$1.resolve("@agimon-ai/po-web-components/package.json"));
|
|
14
14
|
const coreManifest = require$1.resolve("@agimon-ai/po-core/package.json");
|
|
@@ -19,14 +19,14 @@ function mcpAppInputs(componentsRoot) {
|
|
|
19
19
|
coreManifest,
|
|
20
20
|
...fonts
|
|
21
21
|
]);
|
|
22
|
-
for (const css of fonts) for (const match of
|
|
22
|
+
for (const css of fonts) for (const match of (await node_fs_promises.default.readFile(css, "utf8")).matchAll(/url\(['"]?([^)'" ]+\.woff2)['"]?\)/gu)) inputs.add(node_path.default.resolve(node_path.default.dirname(css), match[1]));
|
|
23
23
|
for (const directory of [
|
|
24
24
|
node_path.default.join(root, "dist"),
|
|
25
25
|
node_path.default.join(root, "styles"),
|
|
26
26
|
node_path.default.dirname(reactRequire.resolve("react/package.json")),
|
|
27
27
|
node_path.default.dirname(reactRequire.resolve("react-dom/package.json")),
|
|
28
28
|
node_path.default.dirname(require$1.resolve("tailwindcss/package.json"))
|
|
29
|
-
]) for (const file of
|
|
29
|
+
]) for (const file of await node_fs_promises.default.readdir(directory, { recursive: true })) if (typeof file === "string" && /\.(?:[cm]?js|css|json)$/u.test(file)) inputs.add(node_path.default.join(directory, file));
|
|
30
30
|
inputs.add(node_path.default.join(root, "package.json"));
|
|
31
31
|
return [...inputs].sort();
|
|
32
32
|
}
|
|
@@ -45,16 +45,16 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
45
45
|
const runtimeRequire = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
46
46
|
const coreRoot = node_path.default.dirname(runtimeRequire.resolve("@agimon-ai/po-core/package.json"));
|
|
47
47
|
const componentsRoot = node_path.default.dirname(runtimeRequire.resolve("@agimon-ai/po-web-components/package.json"));
|
|
48
|
-
const componentsManifest = JSON.parse(
|
|
48
|
+
const componentsManifest = JSON.parse(await node_fs_promises.default.readFile(node_path.default.join(componentsRoot, "package.json"), "utf8"));
|
|
49
49
|
const appEntry = node_path.default.resolve(componentsRoot, componentsManifest.exports["./mcpWidget"].import);
|
|
50
50
|
const reactRequire = (0, node_module.createRequire)(node_path.default.join(coreRoot, "package.json"));
|
|
51
51
|
const directory = node_path.default.join(outputDirectory, "ui");
|
|
52
|
-
|
|
53
|
-
const outputRoot =
|
|
52
|
+
await node_fs_promises.default.mkdir(directory, { recursive: true });
|
|
53
|
+
const outputRoot = await node_fs_promises.default.realpath(outputDirectory);
|
|
54
54
|
const entry = node_path.default.join(directory, "entry.js");
|
|
55
55
|
const css = node_path.default.join(directory, "app.css");
|
|
56
56
|
const relative = (file) => file.split(node_path.default.sep).join("/");
|
|
57
|
-
|
|
57
|
+
await node_fs_promises.default.writeFile(entry, [
|
|
58
58
|
`import { mountMcpApp } from ${JSON.stringify(relative(appEntry))};`,
|
|
59
59
|
...mcpAppFonts(componentsRoot).map((font) => `import ${JSON.stringify(relative(font))};`),
|
|
60
60
|
"import './app.css';",
|
|
@@ -64,7 +64,7 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
64
64
|
"void mountMcpApp(widgets);",
|
|
65
65
|
""
|
|
66
66
|
].join("\n"));
|
|
67
|
-
|
|
67
|
+
await node_fs_promises.default.writeFile(css, [
|
|
68
68
|
`@import ${JSON.stringify(relative(runtimeRequire.resolve("tailwindcss/index.css")))};`,
|
|
69
69
|
`@import ${JSON.stringify(relative(node_path.default.join(componentsRoot, "styles/mcp.css")))};`,
|
|
70
70
|
`@source ${JSON.stringify(relative(node_path.default.join(componentsRoot, "dist")))};`,
|
|
@@ -74,12 +74,12 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
74
74
|
""
|
|
75
75
|
].join("\n"));
|
|
76
76
|
const inputs = /* @__PURE__ */ new Set([
|
|
77
|
-
...mcpAppInputs(),
|
|
77
|
+
...await mcpAppInputs(),
|
|
78
78
|
appEntry,
|
|
79
79
|
node_path.default.join(coreRoot, "package.json"),
|
|
80
80
|
node_path.default.join(componentsRoot, "package.json")
|
|
81
81
|
]);
|
|
82
|
-
for (const root of [node_path.default.join(componentsRoot, "styles"), node_path.default.dirname(runtimeRequire.resolve("tailwindcss/package.json"))]) for (const file of
|
|
82
|
+
for (const root of [node_path.default.join(componentsRoot, "styles"), node_path.default.dirname(runtimeRequire.resolve("tailwindcss/package.json"))]) for (const file of await node_fs_promises.default.readdir(root, { recursive: true })) if (typeof file === "string" && file.endsWith(".css")) inputs.add(node_path.default.join(root, file));
|
|
83
83
|
const { build } = await import("vite");
|
|
84
84
|
const { default: tailwindcss } = await import("@tailwindcss/vite");
|
|
85
85
|
const built = await build({
|
|
@@ -90,11 +90,18 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
90
90
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
91
91
|
plugins: [tailwindcss(), {
|
|
92
92
|
name: "po-mcp-inputs",
|
|
93
|
-
generateBundle() {
|
|
93
|
+
async generateBundle() {
|
|
94
94
|
for (const id of this.getModuleIds()) {
|
|
95
95
|
const file = id.split("?")[0];
|
|
96
|
-
if (file.includes("\0") || !node_path.default.isAbsolute(file)
|
|
97
|
-
|
|
96
|
+
if (file.includes("\0") || !node_path.default.isAbsolute(file)) continue;
|
|
97
|
+
let resolved;
|
|
98
|
+
try {
|
|
99
|
+
if (!(await node_fs_promises.default.stat(file)).isFile()) continue;
|
|
100
|
+
resolved = await node_fs_promises.default.realpath(file);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (error.code === "ENOENT") continue;
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
98
105
|
const withinOutput = node_path.default.relative(outputRoot, resolved);
|
|
99
106
|
if (withinOutput !== "" && !withinOutput.startsWith("..") && !node_path.default.isAbsolute(withinOutput)) continue;
|
|
100
107
|
inputs.add(resolved);
|
|
@@ -135,14 +142,14 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
135
142
|
if (scripts.length !== 1 || scripts[0].imports.some((file) => file !== scripts[0].fileName) || scripts[0].dynamicImports.length || output.length !== scripts.length + styles.length) throw new Error(`The composed MCP app must contain one self-contained script and inline CSS only: ${output.map((item) => item.fileName).join(", ")}; imports: ${scripts.flatMap((item) => [...item.imports, ...item.dynamicImports]).join(", ")}`);
|
|
136
143
|
const script = scripts[0].code.replace(/<\/script/giu, "<\\/script");
|
|
137
144
|
const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Po tools</title><style>${styles.map((item) => typeof item.source === "string" ? item.source : Buffer.from(item.source).toString("utf8")).join("\n").replace(/<\/style/giu, "<\\/style")}</style></head><body><div id="root"></div><script>${script}<\/script></body></html>`;
|
|
138
|
-
|
|
145
|
+
await node_fs_promises.default.writeFile(node_path.default.join(directory, "index.html"), html);
|
|
139
146
|
return {
|
|
140
147
|
file: "./ui/index.html",
|
|
141
148
|
sha256: node_crypto.default.createHash("sha256").update(html).digest("hex"),
|
|
142
|
-
inputs: [...inputs].sort().map((file) => ({
|
|
149
|
+
inputs: await Promise.all([...inputs].sort().map(async (file) => ({
|
|
143
150
|
path: file,
|
|
144
|
-
sha256: node_crypto.default.createHash("sha256").update(
|
|
145
|
-
}))
|
|
151
|
+
sha256: node_crypto.default.createHash("sha256").update(await node_fs_promises.default.readFile(file)).digest("hex")
|
|
152
|
+
})))
|
|
146
153
|
};
|
|
147
154
|
}
|
|
148
155
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcpApp.cjs","names":["require","createRequire","path","fs","crypto"],"sources":["../../../../src/builders/server/mcpApp.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\n\n/** The built MCP App HTML, its digest, and the files it was built from. */\nexport interface McpAppBundle {\n readonly file: string;\n readonly sha256: string;\n readonly inputs: readonly { readonly path: string; readonly sha256: string }[];\n}\n\nexport interface McpAppSource {\n readonly file: string;\n readonly widgets: readonly string[];\n}\n\n/** Resolve generator-owned inputs before looking up an immutable build. */\nexport function mcpAppInputs(componentsRoot?: string): string[] {\n const require = createRequire(import.meta.url);\n const root = componentsRoot ?? path.dirname(require.resolve('@agimon-ai/po-web-components/package.json'));\n const coreManifest = require.resolve('@agimon-ai/po-core/package.json');\n const reactRequire = createRequire(coreManifest);\n const fonts = mcpAppFonts(root);\n const inputs = new Set<string>([import.meta.filename, coreManifest, ...fonts]);\n for (const css of fonts) {\n for (const match of fs.readFileSync(css, 'utf8').matchAll(/url\\(['\"]?([^)'\" ]+\\.woff2)['\"]?\\)/gu))\n inputs.add(path.resolve(path.dirname(css), match[1]!));\n }\n for (const directory of [\n path.join(root, 'dist'),\n path.join(root, 'styles'),\n path.dirname(reactRequire.resolve('react/package.json')),\n path.dirname(reactRequire.resolve('react-dom/package.json')),\n path.dirname(require.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of fs.readdirSync(directory, { recursive: true })) {\n if (typeof file === 'string' && /\\.(?:[cm]?js|css|json)$/u.test(file)) inputs.add(path.join(directory, file));\n }\n }\n inputs.add(path.join(root, 'package.json'));\n return [...inputs].sort();\n}\n\nfunction mcpAppFonts(componentsRoot: string): string[] {\n const require = createRequire(path.join(componentsRoot, 'package.json'));\n return ['@fontsource-variable/ibm-plex-sans/index.css', '@fontsource-variable/jetbrains-mono/index.css'].map((font) =>\n require.resolve(font),\n );\n}\n\n/** Composes the installed packages' browser registries. No tool names or presentation policies live here. */\nexport async function bundleMcpApp(\n sources: readonly McpAppSource[],\n outputDirectory: string,\n): Promise<McpAppBundle | undefined> {\n if (sources.length === 0) return undefined;\n const names = new Set<string>();\n for (const source of sources) {\n for (const name of source.widgets) {\n if (names.has(name)) throw new Error(`Duplicate MCP widget '${name}'`);\n names.add(name);\n }\n }\n const runtimeRequire = createRequire(import.meta.url);\n const coreRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-core/package.json'));\n const componentsRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-web-components/package.json'));\n const componentsManifest = JSON.parse(fs.readFileSync(path.join(componentsRoot, 'package.json'), 'utf8')) as {\n exports: Record<string, { import: string }>;\n };\n const appEntry = path.resolve(componentsRoot, componentsManifest.exports['./mcpWidget']!.import);\n const reactRequire = createRequire(path.join(coreRoot, 'package.json'));\n const directory = path.join(outputDirectory, 'ui');\n fs.mkdirSync(directory, { recursive: true });\n const outputRoot = fs.realpathSync(outputDirectory);\n const entry = path.join(directory, 'entry.js');\n const css = path.join(directory, 'app.css');\n const relative = (file: string): string => file.split(path.sep).join('/');\n fs.writeFileSync(\n entry,\n [\n `import { mountMcpApp } from ${JSON.stringify(relative(appEntry))};`,\n ...mcpAppFonts(componentsRoot).map((font) => `import ${JSON.stringify(relative(font))};`),\n \"import './app.css';\",\n ...sources.map(\n (source, index) => `import { widgets as widgets${index} } from ${JSON.stringify(relative(source.file))};`,\n ),\n 'const widgets = Object.create(null);',\n ...sources.flatMap((source, index) =>\n source.widgets.map((name) => `widgets[${JSON.stringify(name)}] = widgets${index}[${JSON.stringify(name)}];`),\n ),\n 'void mountMcpApp(widgets);',\n '',\n ].join('\\n'),\n );\n fs.writeFileSync(\n css,\n [\n `@import ${JSON.stringify(relative(runtimeRequire.resolve('tailwindcss/index.css')))};`,\n `@import ${JSON.stringify(relative(path.join(componentsRoot, 'styles/mcp.css')))};`,\n `@source ${JSON.stringify(relative(path.join(componentsRoot, 'dist')))};`,\n ...sources.map((source) => `@source ${JSON.stringify(relative(source.file))};`),\n 'body { font-family: var(--font-sans, \"IBM Plex Sans Variable\", system-ui, sans-serif); }',\n 'code, pre, kbd, samp { font-family: var(--font-mono, \"JetBrains Mono Variable\", monospace); }',\n '',\n ].join('\\n'),\n );\n const inputs = new Set<string>([\n ...mcpAppInputs(),\n appEntry,\n path.join(coreRoot, 'package.json'),\n path.join(componentsRoot, 'package.json'),\n ]);\n for (const root of [\n path.join(componentsRoot, 'styles'),\n path.dirname(runtimeRequire.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of fs.readdirSync(root, { recursive: true })) {\n if (typeof file === 'string' && file.endsWith('.css')) inputs.add(path.join(root, file));\n }\n }\n const { build } = await import('vite');\n const { default: tailwindcss } = await import('@tailwindcss/vite');\n const built = await build({\n configFile: false,\n envDir: false,\n root: directory,\n logLevel: 'warn',\n // Library builds leave this React branch intact unless it is replaced explicitly.\n define: { 'process.env.NODE_ENV': JSON.stringify('production') },\n plugins: [\n tailwindcss(),\n {\n name: 'po-mcp-inputs',\n generateBundle() {\n for (const id of this.getModuleIds()) {\n const file = id.split('?')[0]!;\n if (file.includes('\\0') || !path.isAbsolute(file) || !fs.existsSync(file) || !fs.statSync(file).isFile())\n continue;\n const resolved = fs.realpathSync(file);\n const withinOutput = path.relative(outputRoot, resolved);\n if (withinOutput !== '' && !withinOutput.startsWith('..') && !path.isAbsolute(withinOutput)) continue;\n inputs.add(resolved);\n }\n },\n },\n ],\n resolve: {\n alias: [\n { find: /^@agimon-ai\\/po-web-components$/u, replacement: appEntry },\n ...['react', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'react-dom', 'react-dom/client'].map(\n (specifier) => ({\n find: new RegExp(`^${specifier.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}$`, 'u'),\n replacement: reactRequire.resolve(specifier),\n }),\n ),\n ],\n },\n build: {\n write: false,\n emptyOutDir: false,\n sourcemap: false,\n cssCodeSplit: false,\n // Vite library mode always inlines assets, regardless of this limit.\n assetsInlineLimit: Infinity,\n lib: { entry, formats: ['iife'], name: 'PoMcpApp', fileName: 'app', cssFileName: 'app' },\n },\n });\n const bundles = Array.isArray(built) ? built : [built];\n const output = bundles.flatMap((bundle) => ('output' in bundle ? bundle.output : []));\n const scripts = output.filter((item) => item.type === 'chunk');\n const styles = output.filter((item) => item.type === 'asset').filter((item) => item.fileName.endsWith('.css'));\n if (\n scripts.length !== 1 ||\n scripts[0]!.imports.some((file) => file !== scripts[0]!.fileName) ||\n scripts[0]!.dynamicImports.length ||\n output.length !== scripts.length + styles.length\n )\n throw new Error(\n `The composed MCP app must contain one self-contained script and inline CSS only: ${output.map((item) => item.fileName).join(', ')}; imports: ${scripts.flatMap((item) => [...item.imports, ...item.dynamicImports]).join(', ')}`,\n );\n const script = scripts[0]!.code.replace(/<\\/script/giu, '<\\\\/script');\n const style = styles\n .map((item) => (typeof item.source === 'string' ? item.source : Buffer.from(item.source).toString('utf8')))\n .join('\\n')\n .replace(/<\\/style/giu, '<\\\\/style');\n const html = `<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Po tools</title><style>${style}</style></head><body><div id=\"root\"></div><script>${script}</script></body></html>`;\n fs.writeFileSync(path.join(directory, 'index.html'), html);\n // Only immutable HTML is served. The generated imports remain useful for diagnosing a sync build.\n return {\n file: './ui/index.html',\n sha256: crypto.createHash('sha256').update(html).digest('hex'),\n inputs: [...inputs]\n .sort()\n .map((file) => ({ path: file, sha256: crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex') })),\n };\n}\n"],"mappings":";;;;;;;;;;AAkBA,SAAgB,aAAa,gBAAmC;CAC9D,MAAMA,aAAAA,GAAUC,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;CAC7C,MAAM,OAAO,kBAAkBC,UAAAA,QAAK,QAAQF,UAAQ,QAAQ,2CAA2C,CAAC;CACxG,MAAM,eAAeA,UAAQ,QAAQ,iCAAiC;CACtE,MAAM,gBAAA,GAAeC,YAAAA,cAAAA,CAAc,YAAY;CAC/C,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,yBAAS,IAAI,IAAY;;EAAuB;EAAc,GAAG;CAAK,CAAC;CAC7E,KAAK,MAAM,OAAO,OAChB,KAAK,MAAM,SAASE,QAAAA,QAAG,aAAa,KAAK,MAAM,CAAC,CAAC,SAAS,sCAAsC,GAC9F,OAAO,IAAID,UAAAA,QAAK,QAAQA,UAAAA,QAAK,QAAQ,GAAG,GAAG,MAAM,EAAG,CAAC;CAEzD,KAAK,MAAM,aAAa;EACtBA,UAAAA,QAAK,KAAK,MAAM,MAAM;EACtBA,UAAAA,QAAK,KAAK,MAAM,QAAQ;EACxBA,UAAAA,QAAK,QAAQ,aAAa,QAAQ,oBAAoB,CAAC;EACvDA,UAAAA,QAAK,QAAQ,aAAa,QAAQ,wBAAwB,CAAC;EAC3DA,UAAAA,QAAK,QAAQF,UAAQ,QAAQ,0BAA0B,CAAC;CAC1D,GACE,KAAK,MAAM,QAAQG,QAAAA,QAAG,YAAY,WAAW,EAAE,WAAW,KAAK,CAAC,GAC9D,IAAI,OAAO,SAAS,YAAY,2BAA2B,KAAK,IAAI,GAAG,OAAO,IAAID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,WACuJ,EAAE,oDAAoD,OAAO;CAC9O,QAAA,QAAG,cAAcA,UAAAA,QAAK,KAAK,WAAW,YAAY,GAAG,IAAI;CAEzD,OAAO;EACL,MAAM;EACN,QAAQE,YAAAA,QAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK;EAC7D,QAAQ,CAAC,GAAG,MAAM,CAAC,CAChB,KAAK,CAAC,CACN,KAAK,UAAU;GAAE,MAAM;GAAM,QAAQA,YAAAA,QAAO,WAAW,QAAQ,CAAC,CAAC,OAAOD,QAAAA,QAAG,aAAa,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK;EAAE,EAAE;CACpH;AACF"}
|
|
1
|
+
{"version":3,"file":"mcpApp.cjs","names":["require","createRequire","path","fs","crypto"],"sources":["../../../../src/builders/server/mcpApp.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\n\n/** The built MCP App HTML, its digest, and the files it was built from. */\nexport interface McpAppBundle {\n readonly file: string;\n readonly sha256: string;\n readonly inputs: readonly { readonly path: string; readonly sha256: string }[];\n}\n\nexport interface McpAppSource {\n readonly file: string;\n readonly widgets: readonly string[];\n}\n\n/** Resolve generator-owned inputs before looking up an immutable build. */\nexport async function mcpAppInputs(componentsRoot?: string): Promise<string[]> {\n const require = createRequire(import.meta.url);\n const root = componentsRoot ?? path.dirname(require.resolve('@agimon-ai/po-web-components/package.json'));\n const coreManifest = require.resolve('@agimon-ai/po-core/package.json');\n const reactRequire = createRequire(coreManifest);\n const fonts = mcpAppFonts(root);\n const inputs = new Set<string>([import.meta.filename, coreManifest, ...fonts]);\n for (const css of fonts) {\n for (const match of (await fs.readFile(css, 'utf8')).matchAll(/url\\(['\"]?([^)'\" ]+\\.woff2)['\"]?\\)/gu))\n inputs.add(path.resolve(path.dirname(css), match[1]!));\n }\n for (const directory of [\n path.join(root, 'dist'),\n path.join(root, 'styles'),\n path.dirname(reactRequire.resolve('react/package.json')),\n path.dirname(reactRequire.resolve('react-dom/package.json')),\n path.dirname(require.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of await fs.readdir(directory, { recursive: true })) {\n if (typeof file === 'string' && /\\.(?:[cm]?js|css|json)$/u.test(file)) inputs.add(path.join(directory, file));\n }\n }\n inputs.add(path.join(root, 'package.json'));\n return [...inputs].sort();\n}\n\nfunction mcpAppFonts(componentsRoot: string): string[] {\n const require = createRequire(path.join(componentsRoot, 'package.json'));\n return ['@fontsource-variable/ibm-plex-sans/index.css', '@fontsource-variable/jetbrains-mono/index.css'].map((font) =>\n require.resolve(font),\n );\n}\n\n/** Composes the installed packages' browser registries. No tool names or presentation policies live here. */\nexport async function bundleMcpApp(\n sources: readonly McpAppSource[],\n outputDirectory: string,\n): Promise<McpAppBundle | undefined> {\n if (sources.length === 0) return undefined;\n const names = new Set<string>();\n for (const source of sources) {\n for (const name of source.widgets) {\n if (names.has(name)) throw new Error(`Duplicate MCP widget '${name}'`);\n names.add(name);\n }\n }\n const runtimeRequire = createRequire(import.meta.url);\n const coreRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-core/package.json'));\n const componentsRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-web-components/package.json'));\n const componentsManifest = JSON.parse(await fs.readFile(path.join(componentsRoot, 'package.json'), 'utf8')) as {\n exports: Record<string, { import: string }>;\n };\n const appEntry = path.resolve(componentsRoot, componentsManifest.exports['./mcpWidget']!.import);\n const reactRequire = createRequire(path.join(coreRoot, 'package.json'));\n const directory = path.join(outputDirectory, 'ui');\n await fs.mkdir(directory, { recursive: true });\n const outputRoot = await fs.realpath(outputDirectory);\n const entry = path.join(directory, 'entry.js');\n const css = path.join(directory, 'app.css');\n const relative = (file: string): string => file.split(path.sep).join('/');\n await fs.writeFile(\n entry,\n [\n `import { mountMcpApp } from ${JSON.stringify(relative(appEntry))};`,\n ...mcpAppFonts(componentsRoot).map((font) => `import ${JSON.stringify(relative(font))};`),\n \"import './app.css';\",\n ...sources.map(\n (source, index) => `import { widgets as widgets${index} } from ${JSON.stringify(relative(source.file))};`,\n ),\n 'const widgets = Object.create(null);',\n ...sources.flatMap((source, index) =>\n source.widgets.map((name) => `widgets[${JSON.stringify(name)}] = widgets${index}[${JSON.stringify(name)}];`),\n ),\n 'void mountMcpApp(widgets);',\n '',\n ].join('\\n'),\n );\n await fs.writeFile(\n css,\n [\n `@import ${JSON.stringify(relative(runtimeRequire.resolve('tailwindcss/index.css')))};`,\n `@import ${JSON.stringify(relative(path.join(componentsRoot, 'styles/mcp.css')))};`,\n `@source ${JSON.stringify(relative(path.join(componentsRoot, 'dist')))};`,\n ...sources.map((source) => `@source ${JSON.stringify(relative(source.file))};`),\n 'body { font-family: var(--font-sans, \"IBM Plex Sans Variable\", system-ui, sans-serif); }',\n 'code, pre, kbd, samp { font-family: var(--font-mono, \"JetBrains Mono Variable\", monospace); }',\n '',\n ].join('\\n'),\n );\n const inputs = new Set<string>([\n ...(await mcpAppInputs()),\n appEntry,\n path.join(coreRoot, 'package.json'),\n path.join(componentsRoot, 'package.json'),\n ]);\n for (const root of [\n path.join(componentsRoot, 'styles'),\n path.dirname(runtimeRequire.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of await fs.readdir(root, { recursive: true })) {\n if (typeof file === 'string' && file.endsWith('.css')) inputs.add(path.join(root, file));\n }\n }\n const { build } = await import('vite');\n const { default: tailwindcss } = await import('@tailwindcss/vite');\n const built = await build({\n configFile: false,\n envDir: false,\n root: directory,\n logLevel: 'warn',\n // Library builds leave this React branch intact unless it is replaced explicitly.\n define: { 'process.env.NODE_ENV': JSON.stringify('production') },\n plugins: [\n tailwindcss(),\n {\n name: 'po-mcp-inputs',\n async generateBundle() {\n for (const id of this.getModuleIds()) {\n const file = id.split('?')[0]!;\n if (file.includes('\\0') || !path.isAbsolute(file)) continue;\n let resolved: string;\n try {\n if (!(await fs.stat(file)).isFile()) continue;\n resolved = await fs.realpath(file);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') continue;\n throw error;\n }\n const withinOutput = path.relative(outputRoot, resolved);\n if (withinOutput !== '' && !withinOutput.startsWith('..') && !path.isAbsolute(withinOutput)) continue;\n inputs.add(resolved);\n }\n },\n },\n ],\n resolve: {\n alias: [\n { find: /^@agimon-ai\\/po-web-components$/u, replacement: appEntry },\n ...['react', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'react-dom', 'react-dom/client'].map(\n (specifier) => ({\n find: new RegExp(`^${specifier.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}$`, 'u'),\n replacement: reactRequire.resolve(specifier),\n }),\n ),\n ],\n },\n build: {\n write: false,\n emptyOutDir: false,\n sourcemap: false,\n cssCodeSplit: false,\n // Vite library mode always inlines assets, regardless of this limit.\n assetsInlineLimit: Infinity,\n lib: { entry, formats: ['iife'], name: 'PoMcpApp', fileName: 'app', cssFileName: 'app' },\n },\n });\n const bundles = Array.isArray(built) ? built : [built];\n const output = bundles.flatMap((bundle) => ('output' in bundle ? bundle.output : []));\n const scripts = output.filter((item) => item.type === 'chunk');\n const styles = output.filter((item) => item.type === 'asset').filter((item) => item.fileName.endsWith('.css'));\n if (\n scripts.length !== 1 ||\n scripts[0]!.imports.some((file) => file !== scripts[0]!.fileName) ||\n scripts[0]!.dynamicImports.length ||\n output.length !== scripts.length + styles.length\n )\n throw new Error(\n `The composed MCP app must contain one self-contained script and inline CSS only: ${output.map((item) => item.fileName).join(', ')}; imports: ${scripts.flatMap((item) => [...item.imports, ...item.dynamicImports]).join(', ')}`,\n );\n const script = scripts[0]!.code.replace(/<\\/script/giu, '<\\\\/script');\n const style = styles\n .map((item) => (typeof item.source === 'string' ? item.source : Buffer.from(item.source).toString('utf8')))\n .join('\\n')\n .replace(/<\\/style/giu, '<\\\\/style');\n const html = `<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Po tools</title><style>${style}</style></head><body><div id=\"root\"></div><script>${script}</script></body></html>`;\n await fs.writeFile(path.join(directory, 'index.html'), html);\n // Only immutable HTML is served. The generated imports remain useful for diagnosing a sync build.\n return {\n file: './ui/index.html',\n sha256: crypto.createHash('sha256').update(html).digest('hex'),\n inputs: await Promise.all(\n [...inputs].sort().map(async (file) => ({\n path: file,\n sha256: crypto\n .createHash('sha256')\n .update(await fs.readFile(file))\n .digest('hex'),\n })),\n ),\n };\n}\n"],"mappings":";;;;;;;;;;AAkBA,eAAsB,aAAa,gBAA4C;CAC7E,MAAMA,aAAAA,GAAUC,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;CAC7C,MAAM,OAAO,kBAAkBC,UAAAA,QAAK,QAAQF,UAAQ,QAAQ,2CAA2C,CAAC;CACxG,MAAM,eAAeA,UAAQ,QAAQ,iCAAiC;CACtE,MAAM,gBAAA,GAAeC,YAAAA,cAAAA,CAAc,YAAY;CAC/C,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,yBAAS,IAAI,IAAY;;EAAuB;EAAc,GAAG;CAAK,CAAC;CAC7E,KAAK,MAAM,OAAO,OAChB,KAAK,MAAM,UAAU,MAAME,iBAAAA,QAAG,SAAS,KAAK,MAAM,EAAA,CAAG,SAAS,sCAAsC,GAClG,OAAO,IAAID,UAAAA,QAAK,QAAQA,UAAAA,QAAK,QAAQ,GAAG,GAAG,MAAM,EAAG,CAAC;CAEzD,KAAK,MAAM,aAAa;EACtBA,UAAAA,QAAK,KAAK,MAAM,MAAM;EACtBA,UAAAA,QAAK,KAAK,MAAM,QAAQ;EACxBA,UAAAA,QAAK,QAAQ,aAAa,QAAQ,oBAAoB,CAAC;EACvDA,UAAAA,QAAK,QAAQ,aAAa,QAAQ,wBAAwB,CAAC;EAC3DA,UAAAA,QAAK,QAAQF,UAAQ,QAAQ,0BAA0B,CAAC;CAC1D,GACE,KAAK,MAAM,QAAQ,MAAMG,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IAAI,GAChO;CACF,MAAM,SAAS,QAAQ,EAAE,CAAE,KAAK,QAAQ,gBAAgB,YAAY;CAKpE,MAAM,OAAO,gKAJC,OACX,KAAK,SAAU,OAAO,KAAK,WAAW,WAAW,KAAK,SAAS,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,CAAE,CAAC,CAC1G,KAAK,IAAI,CAAC,CACV,QAAQ,eAAe,WACuJ,EAAE,oDAAoD,OAAO;CAC9O,MAAMC,iBAAAA,QAAG,UAAUD,UAAAA,QAAK,KAAK,WAAW,YAAY,GAAG,IAAI;CAE3D,OAAO;EACL,MAAM;EACN,QAAQE,YAAAA,QAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK;EAC7D,QAAQ,MAAM,QAAQ,IACpB,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,UAAU;GACtC,MAAM;GACN,QAAQA,YAAAA,QACL,WAAW,QAAQ,CAAC,CACpB,OAAO,MAAMD,iBAAAA,QAAG,SAAS,IAAI,CAAC,CAAC,CAC/B,OAAO,KAAK;EACjB,EAAE,CACJ;CACF;AACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
4
|
import crypto from "node:crypto";
|
|
5
5
|
//#region src/builders/server/mcpApp.ts
|
|
6
6
|
/** Resolve generator-owned inputs before looking up an immutable build. */
|
|
7
|
-
function mcpAppInputs(componentsRoot) {
|
|
7
|
+
async function mcpAppInputs(componentsRoot) {
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
9
|
const root = componentsRoot ?? path.dirname(require.resolve("@agimon-ai/po-web-components/package.json"));
|
|
10
10
|
const coreManifest = require.resolve("@agimon-ai/po-core/package.json");
|
|
@@ -15,14 +15,14 @@ function mcpAppInputs(componentsRoot) {
|
|
|
15
15
|
coreManifest,
|
|
16
16
|
...fonts
|
|
17
17
|
]);
|
|
18
|
-
for (const css of fonts) for (const match of fs.
|
|
18
|
+
for (const css of fonts) for (const match of (await fs.readFile(css, "utf8")).matchAll(/url\(['"]?([^)'" ]+\.woff2)['"]?\)/gu)) inputs.add(path.resolve(path.dirname(css), match[1]));
|
|
19
19
|
for (const directory of [
|
|
20
20
|
path.join(root, "dist"),
|
|
21
21
|
path.join(root, "styles"),
|
|
22
22
|
path.dirname(reactRequire.resolve("react/package.json")),
|
|
23
23
|
path.dirname(reactRequire.resolve("react-dom/package.json")),
|
|
24
24
|
path.dirname(require.resolve("tailwindcss/package.json"))
|
|
25
|
-
]) for (const file of fs.
|
|
25
|
+
]) for (const file of await fs.readdir(directory, { recursive: true })) if (typeof file === "string" && /\.(?:[cm]?js|css|json)$/u.test(file)) inputs.add(path.join(directory, file));
|
|
26
26
|
inputs.add(path.join(root, "package.json"));
|
|
27
27
|
return [...inputs].sort();
|
|
28
28
|
}
|
|
@@ -41,16 +41,16 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
41
41
|
const runtimeRequire = createRequire(import.meta.url);
|
|
42
42
|
const coreRoot = path.dirname(runtimeRequire.resolve("@agimon-ai/po-core/package.json"));
|
|
43
43
|
const componentsRoot = path.dirname(runtimeRequire.resolve("@agimon-ai/po-web-components/package.json"));
|
|
44
|
-
const componentsManifest = JSON.parse(fs.
|
|
44
|
+
const componentsManifest = JSON.parse(await fs.readFile(path.join(componentsRoot, "package.json"), "utf8"));
|
|
45
45
|
const appEntry = path.resolve(componentsRoot, componentsManifest.exports["./mcpWidget"].import);
|
|
46
46
|
const reactRequire = createRequire(path.join(coreRoot, "package.json"));
|
|
47
47
|
const directory = path.join(outputDirectory, "ui");
|
|
48
|
-
fs.
|
|
49
|
-
const outputRoot = fs.
|
|
48
|
+
await fs.mkdir(directory, { recursive: true });
|
|
49
|
+
const outputRoot = await fs.realpath(outputDirectory);
|
|
50
50
|
const entry = path.join(directory, "entry.js");
|
|
51
51
|
const css = path.join(directory, "app.css");
|
|
52
52
|
const relative = (file) => file.split(path.sep).join("/");
|
|
53
|
-
fs.
|
|
53
|
+
await fs.writeFile(entry, [
|
|
54
54
|
`import { mountMcpApp } from ${JSON.stringify(relative(appEntry))};`,
|
|
55
55
|
...mcpAppFonts(componentsRoot).map((font) => `import ${JSON.stringify(relative(font))};`),
|
|
56
56
|
"import './app.css';",
|
|
@@ -60,7 +60,7 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
60
60
|
"void mountMcpApp(widgets);",
|
|
61
61
|
""
|
|
62
62
|
].join("\n"));
|
|
63
|
-
fs.
|
|
63
|
+
await fs.writeFile(css, [
|
|
64
64
|
`@import ${JSON.stringify(relative(runtimeRequire.resolve("tailwindcss/index.css")))};`,
|
|
65
65
|
`@import ${JSON.stringify(relative(path.join(componentsRoot, "styles/mcp.css")))};`,
|
|
66
66
|
`@source ${JSON.stringify(relative(path.join(componentsRoot, "dist")))};`,
|
|
@@ -70,12 +70,12 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
70
70
|
""
|
|
71
71
|
].join("\n"));
|
|
72
72
|
const inputs = /* @__PURE__ */ new Set([
|
|
73
|
-
...mcpAppInputs(),
|
|
73
|
+
...await mcpAppInputs(),
|
|
74
74
|
appEntry,
|
|
75
75
|
path.join(coreRoot, "package.json"),
|
|
76
76
|
path.join(componentsRoot, "package.json")
|
|
77
77
|
]);
|
|
78
|
-
for (const root of [path.join(componentsRoot, "styles"), path.dirname(runtimeRequire.resolve("tailwindcss/package.json"))]) for (const file of fs.
|
|
78
|
+
for (const root of [path.join(componentsRoot, "styles"), path.dirname(runtimeRequire.resolve("tailwindcss/package.json"))]) for (const file of await fs.readdir(root, { recursive: true })) if (typeof file === "string" && file.endsWith(".css")) inputs.add(path.join(root, file));
|
|
79
79
|
const { build } = await import("vite");
|
|
80
80
|
const { default: tailwindcss } = await import("@tailwindcss/vite");
|
|
81
81
|
const built = await build({
|
|
@@ -86,11 +86,18 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
86
86
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
87
87
|
plugins: [tailwindcss(), {
|
|
88
88
|
name: "po-mcp-inputs",
|
|
89
|
-
generateBundle() {
|
|
89
|
+
async generateBundle() {
|
|
90
90
|
for (const id of this.getModuleIds()) {
|
|
91
91
|
const file = id.split("?")[0];
|
|
92
|
-
if (file.includes("\0") || !path.isAbsolute(file)
|
|
93
|
-
|
|
92
|
+
if (file.includes("\0") || !path.isAbsolute(file)) continue;
|
|
93
|
+
let resolved;
|
|
94
|
+
try {
|
|
95
|
+
if (!(await fs.stat(file)).isFile()) continue;
|
|
96
|
+
resolved = await fs.realpath(file);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error.code === "ENOENT") continue;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
94
101
|
const withinOutput = path.relative(outputRoot, resolved);
|
|
95
102
|
if (withinOutput !== "" && !withinOutput.startsWith("..") && !path.isAbsolute(withinOutput)) continue;
|
|
96
103
|
inputs.add(resolved);
|
|
@@ -131,14 +138,14 @@ async function bundleMcpApp(sources, outputDirectory) {
|
|
|
131
138
|
if (scripts.length !== 1 || scripts[0].imports.some((file) => file !== scripts[0].fileName) || scripts[0].dynamicImports.length || output.length !== scripts.length + styles.length) throw new Error(`The composed MCP app must contain one self-contained script and inline CSS only: ${output.map((item) => item.fileName).join(", ")}; imports: ${scripts.flatMap((item) => [...item.imports, ...item.dynamicImports]).join(", ")}`);
|
|
132
139
|
const script = scripts[0].code.replace(/<\/script/giu, "<\\/script");
|
|
133
140
|
const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Po tools</title><style>${styles.map((item) => typeof item.source === "string" ? item.source : Buffer.from(item.source).toString("utf8")).join("\n").replace(/<\/style/giu, "<\\/style")}</style></head><body><div id="root"></div><script>${script}<\/script></body></html>`;
|
|
134
|
-
fs.
|
|
141
|
+
await fs.writeFile(path.join(directory, "index.html"), html);
|
|
135
142
|
return {
|
|
136
143
|
file: "./ui/index.html",
|
|
137
144
|
sha256: crypto.createHash("sha256").update(html).digest("hex"),
|
|
138
|
-
inputs: [...inputs].sort().map((file) => ({
|
|
145
|
+
inputs: await Promise.all([...inputs].sort().map(async (file) => ({
|
|
139
146
|
path: file,
|
|
140
|
-
sha256: crypto.createHash("sha256").update(fs.
|
|
141
|
-
}))
|
|
147
|
+
sha256: crypto.createHash("sha256").update(await fs.readFile(file)).digest("hex")
|
|
148
|
+
})))
|
|
142
149
|
};
|
|
143
150
|
}
|
|
144
151
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcpApp.mjs","names":[],"sources":["../../../../src/builders/server/mcpApp.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\n\n/** The built MCP App HTML, its digest, and the files it was built from. */\nexport interface McpAppBundle {\n readonly file: string;\n readonly sha256: string;\n readonly inputs: readonly { readonly path: string; readonly sha256: string }[];\n}\n\nexport interface McpAppSource {\n readonly file: string;\n readonly widgets: readonly string[];\n}\n\n/** Resolve generator-owned inputs before looking up an immutable build. */\nexport function mcpAppInputs(componentsRoot?: string): string[] {\n const require = createRequire(import.meta.url);\n const root = componentsRoot ?? path.dirname(require.resolve('@agimon-ai/po-web-components/package.json'));\n const coreManifest = require.resolve('@agimon-ai/po-core/package.json');\n const reactRequire = createRequire(coreManifest);\n const fonts = mcpAppFonts(root);\n const inputs = new Set<string>([import.meta.filename, coreManifest, ...fonts]);\n for (const css of fonts) {\n for (const match of fs.readFileSync(css, 'utf8').matchAll(/url\\(['\"]?([^)'\" ]+\\.woff2)['\"]?\\)/gu))\n inputs.add(path.resolve(path.dirname(css), match[1]!));\n }\n for (const directory of [\n path.join(root, 'dist'),\n path.join(root, 'styles'),\n path.dirname(reactRequire.resolve('react/package.json')),\n path.dirname(reactRequire.resolve('react-dom/package.json')),\n path.dirname(require.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of fs.readdirSync(directory, { recursive: true })) {\n if (typeof file === 'string' && /\\.(?:[cm]?js|css|json)$/u.test(file)) inputs.add(path.join(directory, file));\n }\n }\n inputs.add(path.join(root, 'package.json'));\n return [...inputs].sort();\n}\n\nfunction mcpAppFonts(componentsRoot: string): string[] {\n const require = createRequire(path.join(componentsRoot, 'package.json'));\n return ['@fontsource-variable/ibm-plex-sans/index.css', '@fontsource-variable/jetbrains-mono/index.css'].map((font) =>\n require.resolve(font),\n );\n}\n\n/** Composes the installed packages' browser registries. No tool names or presentation policies live here. */\nexport async function bundleMcpApp(\n sources: readonly McpAppSource[],\n outputDirectory: string,\n): Promise<McpAppBundle | undefined> {\n if (sources.length === 0) return undefined;\n const names = new Set<string>();\n for (const source of sources) {\n for (const name of source.widgets) {\n if (names.has(name)) throw new Error(`Duplicate MCP widget '${name}'`);\n names.add(name);\n }\n }\n const runtimeRequire = createRequire(import.meta.url);\n const coreRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-core/package.json'));\n const componentsRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-web-components/package.json'));\n const componentsManifest = JSON.parse(fs.readFileSync(path.join(componentsRoot, 'package.json'), 'utf8')) as {\n exports: Record<string, { import: string }>;\n };\n const appEntry = path.resolve(componentsRoot, componentsManifest.exports['./mcpWidget']!.import);\n const reactRequire = createRequire(path.join(coreRoot, 'package.json'));\n const directory = path.join(outputDirectory, 'ui');\n fs.mkdirSync(directory, { recursive: true });\n const outputRoot = fs.realpathSync(outputDirectory);\n const entry = path.join(directory, 'entry.js');\n const css = path.join(directory, 'app.css');\n const relative = (file: string): string => file.split(path.sep).join('/');\n fs.writeFileSync(\n entry,\n [\n `import { mountMcpApp } from ${JSON.stringify(relative(appEntry))};`,\n ...mcpAppFonts(componentsRoot).map((font) => `import ${JSON.stringify(relative(font))};`),\n \"import './app.css';\",\n ...sources.map(\n (source, index) => `import { widgets as widgets${index} } from ${JSON.stringify(relative(source.file))};`,\n ),\n 'const widgets = Object.create(null);',\n ...sources.flatMap((source, index) =>\n source.widgets.map((name) => `widgets[${JSON.stringify(name)}] = widgets${index}[${JSON.stringify(name)}];`),\n ),\n 'void mountMcpApp(widgets);',\n '',\n ].join('\\n'),\n );\n fs.writeFileSync(\n css,\n [\n `@import ${JSON.stringify(relative(runtimeRequire.resolve('tailwindcss/index.css')))};`,\n `@import ${JSON.stringify(relative(path.join(componentsRoot, 'styles/mcp.css')))};`,\n `@source ${JSON.stringify(relative(path.join(componentsRoot, 'dist')))};`,\n ...sources.map((source) => `@source ${JSON.stringify(relative(source.file))};`),\n 'body { font-family: var(--font-sans, \"IBM Plex Sans Variable\", system-ui, sans-serif); }',\n 'code, pre, kbd, samp { font-family: var(--font-mono, \"JetBrains Mono Variable\", monospace); }',\n '',\n ].join('\\n'),\n );\n const inputs = new Set<string>([\n ...mcpAppInputs(),\n appEntry,\n path.join(coreRoot, 'package.json'),\n path.join(componentsRoot, 'package.json'),\n ]);\n for (const root of [\n path.join(componentsRoot, 'styles'),\n path.dirname(runtimeRequire.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of fs.readdirSync(root, { recursive: true })) {\n if (typeof file === 'string' && file.endsWith('.css')) inputs.add(path.join(root, file));\n }\n }\n const { build } = await import('vite');\n const { default: tailwindcss } = await import('@tailwindcss/vite');\n const built = await build({\n configFile: false,\n envDir: false,\n root: directory,\n logLevel: 'warn',\n // Library builds leave this React branch intact unless it is replaced explicitly.\n define: { 'process.env.NODE_ENV': JSON.stringify('production') },\n plugins: [\n tailwindcss(),\n {\n name: 'po-mcp-inputs',\n generateBundle() {\n for (const id of this.getModuleIds()) {\n const file = id.split('?')[0]!;\n if (file.includes('\\0') || !path.isAbsolute(file) || !fs.existsSync(file) || !fs.statSync(file).isFile())\n continue;\n const resolved = fs.realpathSync(file);\n const withinOutput = path.relative(outputRoot, resolved);\n if (withinOutput !== '' && !withinOutput.startsWith('..') && !path.isAbsolute(withinOutput)) continue;\n inputs.add(resolved);\n }\n },\n },\n ],\n resolve: {\n alias: [\n { find: /^@agimon-ai\\/po-web-components$/u, replacement: appEntry },\n ...['react', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'react-dom', 'react-dom/client'].map(\n (specifier) => ({\n find: new RegExp(`^${specifier.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}$`, 'u'),\n replacement: reactRequire.resolve(specifier),\n }),\n ),\n ],\n },\n build: {\n write: false,\n emptyOutDir: false,\n sourcemap: false,\n cssCodeSplit: false,\n // Vite library mode always inlines assets, regardless of this limit.\n assetsInlineLimit: Infinity,\n lib: { entry, formats: ['iife'], name: 'PoMcpApp', fileName: 'app', cssFileName: 'app' },\n },\n });\n const bundles = Array.isArray(built) ? built : [built];\n const output = bundles.flatMap((bundle) => ('output' in bundle ? bundle.output : []));\n const scripts = output.filter((item) => item.type === 'chunk');\n const styles = output.filter((item) => item.type === 'asset').filter((item) => item.fileName.endsWith('.css'));\n if (\n scripts.length !== 1 ||\n scripts[0]!.imports.some((file) => file !== scripts[0]!.fileName) ||\n scripts[0]!.dynamicImports.length ||\n output.length !== scripts.length + styles.length\n )\n throw new Error(\n `The composed MCP app must contain one self-contained script and inline CSS only: ${output.map((item) => item.fileName).join(', ')}; imports: ${scripts.flatMap((item) => [...item.imports, ...item.dynamicImports]).join(', ')}`,\n );\n const script = scripts[0]!.code.replace(/<\\/script/giu, '<\\\\/script');\n const style = styles\n .map((item) => (typeof item.source === 'string' ? item.source : Buffer.from(item.source).toString('utf8')))\n .join('\\n')\n .replace(/<\\/style/giu, '<\\\\/style');\n const html = `<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Po tools</title><style>${style}</style></head><body><div id=\"root\"></div><script>${script}</script></body></html>`;\n fs.writeFileSync(path.join(directory, 'index.html'), html);\n // Only immutable HTML is served. The generated imports remain useful for diagnosing a sync build.\n return {\n file: './ui/index.html',\n sha256: crypto.createHash('sha256').update(html).digest('hex'),\n inputs: [...inputs]\n .sort()\n .map((file) => ({ path: file, sha256: crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex') })),\n };\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,aAAa,gBAAmC;CAC9D,MAAM,UAAU,cAAc,YAAY,GAAG;CAC7C,MAAM,OAAO,kBAAkB,KAAK,QAAQ,QAAQ,QAAQ,2CAA2C,CAAC;CACxG,MAAM,eAAe,QAAQ,QAAQ,iCAAiC;CACtE,MAAM,eAAe,cAAc,YAAY;CAC/C,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,yBAAS,IAAI,IAAY;EAAC,YAAY;EAAU;EAAc,GAAG;CAAK,CAAC;CAC7E,KAAK,MAAM,OAAO,OAChB,KAAK,MAAM,SAAS,GAAG,aAAa,KAAK,MAAM,CAAC,CAAC,SAAS,sCAAsC,GAC9F,OAAO,IAAI,KAAK,QAAQ,KAAK,QAAQ,GAAG,GAAG,MAAM,EAAG,CAAC;CAEzD,KAAK,MAAM,aAAa;EACtB,KAAK,KAAK,MAAM,MAAM;EACtB,KAAK,KAAK,MAAM,QAAQ;EACxB,KAAK,QAAQ,aAAa,QAAQ,oBAAoB,CAAC;EACvD,KAAK,QAAQ,aAAa,QAAQ,wBAAwB,CAAC;EAC3D,KAAK,QAAQ,QAAQ,QAAQ,0BAA0B,CAAC;CAC1D,GACE,KAAK,MAAM,QAAQ,GAAG,YAAY,WAAW,EAAE,WAAW,KAAK,CAAC,GAC9D,IAAI,OAAO,SAAS,YAAY,2BAA2B,KAAK,IAAI,GAAG,OAAO,IAAI,KAAK,KAAK,WAAW,IAAI,CAAC;CAGhH,OAAO,IAAI,KAAK,KAAK,MAAM,cAAc,CAAC;CAC1C,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK;AAC1B;AAEA,SAAS,YAAY,gBAAkC;CACrD,MAAM,UAAU,cAAc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AS,OAAO,CAAC,CAAC,QAAQ,SAAS,KAAK,SAAS,SAAS,MAAM,CAAC;CAC7G,IACE,QAAQ,WAAW,KACnB,QAAQ,EAAE,CAAE,QAAQ,MAAM,SAAS,SAAS,QAAQ,EAAE,CAAE,QAAQ,KAChE,QAAQ,EAAE,CAAE,eAAe,UAC3B,OAAO,WAAW,QAAQ,SAAS,OAAO,QAE1C,MAAM,IAAI,MACR,oFAAoF,OAAO,KAAK,SAAS,KAAK,QAAQ,CAAC,CAAC,KAAK,IAAI,EAAE,aAAa,QAAQ,SAAS,SAAS,CAAC,GAAG,KAAK,SAAS,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,GAChO;CACF,MAAM,SAAS,QAAQ,EAAE,CAAE,KAAK,QAAQ,gBAAgB,YAAY;CAKpE,MAAM,OAAO,gKAJC,OACX,KAAK,SAAU,OAAO,KAAK,WAAW,WAAW,KAAK,SAAS,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,CAAE,CAAC,CAC1G,KAAK,IAAI,CAAC,CACV,QAAQ,eAAe,WACuJ,EAAE,oDAAoD,OAAO;CAC9O,GAAG,cAAc,KAAK,KAAK,WAAW,YAAY,GAAG,IAAI;CAEzD,OAAO;EACL,MAAM;EACN,QAAQ,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK;EAC7D,QAAQ,CAAC,GAAG,MAAM,CAAC,CAChB,KAAK,CAAC,CACN,KAAK,UAAU;GAAE,MAAM;GAAM,QAAQ,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,GAAG,aAAa,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK;EAAE,EAAE;CACpH;AACF"}
|
|
1
|
+
{"version":3,"file":"mcpApp.mjs","names":[],"sources":["../../../../src/builders/server/mcpApp.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport path from 'node:path';\n\n/** The built MCP App HTML, its digest, and the files it was built from. */\nexport interface McpAppBundle {\n readonly file: string;\n readonly sha256: string;\n readonly inputs: readonly { readonly path: string; readonly sha256: string }[];\n}\n\nexport interface McpAppSource {\n readonly file: string;\n readonly widgets: readonly string[];\n}\n\n/** Resolve generator-owned inputs before looking up an immutable build. */\nexport async function mcpAppInputs(componentsRoot?: string): Promise<string[]> {\n const require = createRequire(import.meta.url);\n const root = componentsRoot ?? path.dirname(require.resolve('@agimon-ai/po-web-components/package.json'));\n const coreManifest = require.resolve('@agimon-ai/po-core/package.json');\n const reactRequire = createRequire(coreManifest);\n const fonts = mcpAppFonts(root);\n const inputs = new Set<string>([import.meta.filename, coreManifest, ...fonts]);\n for (const css of fonts) {\n for (const match of (await fs.readFile(css, 'utf8')).matchAll(/url\\(['\"]?([^)'\" ]+\\.woff2)['\"]?\\)/gu))\n inputs.add(path.resolve(path.dirname(css), match[1]!));\n }\n for (const directory of [\n path.join(root, 'dist'),\n path.join(root, 'styles'),\n path.dirname(reactRequire.resolve('react/package.json')),\n path.dirname(reactRequire.resolve('react-dom/package.json')),\n path.dirname(require.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of await fs.readdir(directory, { recursive: true })) {\n if (typeof file === 'string' && /\\.(?:[cm]?js|css|json)$/u.test(file)) inputs.add(path.join(directory, file));\n }\n }\n inputs.add(path.join(root, 'package.json'));\n return [...inputs].sort();\n}\n\nfunction mcpAppFonts(componentsRoot: string): string[] {\n const require = createRequire(path.join(componentsRoot, 'package.json'));\n return ['@fontsource-variable/ibm-plex-sans/index.css', '@fontsource-variable/jetbrains-mono/index.css'].map((font) =>\n require.resolve(font),\n );\n}\n\n/** Composes the installed packages' browser registries. No tool names or presentation policies live here. */\nexport async function bundleMcpApp(\n sources: readonly McpAppSource[],\n outputDirectory: string,\n): Promise<McpAppBundle | undefined> {\n if (sources.length === 0) return undefined;\n const names = new Set<string>();\n for (const source of sources) {\n for (const name of source.widgets) {\n if (names.has(name)) throw new Error(`Duplicate MCP widget '${name}'`);\n names.add(name);\n }\n }\n const runtimeRequire = createRequire(import.meta.url);\n const coreRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-core/package.json'));\n const componentsRoot = path.dirname(runtimeRequire.resolve('@agimon-ai/po-web-components/package.json'));\n const componentsManifest = JSON.parse(await fs.readFile(path.join(componentsRoot, 'package.json'), 'utf8')) as {\n exports: Record<string, { import: string }>;\n };\n const appEntry = path.resolve(componentsRoot, componentsManifest.exports['./mcpWidget']!.import);\n const reactRequire = createRequire(path.join(coreRoot, 'package.json'));\n const directory = path.join(outputDirectory, 'ui');\n await fs.mkdir(directory, { recursive: true });\n const outputRoot = await fs.realpath(outputDirectory);\n const entry = path.join(directory, 'entry.js');\n const css = path.join(directory, 'app.css');\n const relative = (file: string): string => file.split(path.sep).join('/');\n await fs.writeFile(\n entry,\n [\n `import { mountMcpApp } from ${JSON.stringify(relative(appEntry))};`,\n ...mcpAppFonts(componentsRoot).map((font) => `import ${JSON.stringify(relative(font))};`),\n \"import './app.css';\",\n ...sources.map(\n (source, index) => `import { widgets as widgets${index} } from ${JSON.stringify(relative(source.file))};`,\n ),\n 'const widgets = Object.create(null);',\n ...sources.flatMap((source, index) =>\n source.widgets.map((name) => `widgets[${JSON.stringify(name)}] = widgets${index}[${JSON.stringify(name)}];`),\n ),\n 'void mountMcpApp(widgets);',\n '',\n ].join('\\n'),\n );\n await fs.writeFile(\n css,\n [\n `@import ${JSON.stringify(relative(runtimeRequire.resolve('tailwindcss/index.css')))};`,\n `@import ${JSON.stringify(relative(path.join(componentsRoot, 'styles/mcp.css')))};`,\n `@source ${JSON.stringify(relative(path.join(componentsRoot, 'dist')))};`,\n ...sources.map((source) => `@source ${JSON.stringify(relative(source.file))};`),\n 'body { font-family: var(--font-sans, \"IBM Plex Sans Variable\", system-ui, sans-serif); }',\n 'code, pre, kbd, samp { font-family: var(--font-mono, \"JetBrains Mono Variable\", monospace); }',\n '',\n ].join('\\n'),\n );\n const inputs = new Set<string>([\n ...(await mcpAppInputs()),\n appEntry,\n path.join(coreRoot, 'package.json'),\n path.join(componentsRoot, 'package.json'),\n ]);\n for (const root of [\n path.join(componentsRoot, 'styles'),\n path.dirname(runtimeRequire.resolve('tailwindcss/package.json')),\n ]) {\n for (const file of await fs.readdir(root, { recursive: true })) {\n if (typeof file === 'string' && file.endsWith('.css')) inputs.add(path.join(root, file));\n }\n }\n const { build } = await import('vite');\n const { default: tailwindcss } = await import('@tailwindcss/vite');\n const built = await build({\n configFile: false,\n envDir: false,\n root: directory,\n logLevel: 'warn',\n // Library builds leave this React branch intact unless it is replaced explicitly.\n define: { 'process.env.NODE_ENV': JSON.stringify('production') },\n plugins: [\n tailwindcss(),\n {\n name: 'po-mcp-inputs',\n async generateBundle() {\n for (const id of this.getModuleIds()) {\n const file = id.split('?')[0]!;\n if (file.includes('\\0') || !path.isAbsolute(file)) continue;\n let resolved: string;\n try {\n if (!(await fs.stat(file)).isFile()) continue;\n resolved = await fs.realpath(file);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') continue;\n throw error;\n }\n const withinOutput = path.relative(outputRoot, resolved);\n if (withinOutput !== '' && !withinOutput.startsWith('..') && !path.isAbsolute(withinOutput)) continue;\n inputs.add(resolved);\n }\n },\n },\n ],\n resolve: {\n alias: [\n { find: /^@agimon-ai\\/po-web-components$/u, replacement: appEntry },\n ...['react', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'react-dom', 'react-dom/client'].map(\n (specifier) => ({\n find: new RegExp(`^${specifier.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}$`, 'u'),\n replacement: reactRequire.resolve(specifier),\n }),\n ),\n ],\n },\n build: {\n write: false,\n emptyOutDir: false,\n sourcemap: false,\n cssCodeSplit: false,\n // Vite library mode always inlines assets, regardless of this limit.\n assetsInlineLimit: Infinity,\n lib: { entry, formats: ['iife'], name: 'PoMcpApp', fileName: 'app', cssFileName: 'app' },\n },\n });\n const bundles = Array.isArray(built) ? built : [built];\n const output = bundles.flatMap((bundle) => ('output' in bundle ? bundle.output : []));\n const scripts = output.filter((item) => item.type === 'chunk');\n const styles = output.filter((item) => item.type === 'asset').filter((item) => item.fileName.endsWith('.css'));\n if (\n scripts.length !== 1 ||\n scripts[0]!.imports.some((file) => file !== scripts[0]!.fileName) ||\n scripts[0]!.dynamicImports.length ||\n output.length !== scripts.length + styles.length\n )\n throw new Error(\n `The composed MCP app must contain one self-contained script and inline CSS only: ${output.map((item) => item.fileName).join(', ')}; imports: ${scripts.flatMap((item) => [...item.imports, ...item.dynamicImports]).join(', ')}`,\n );\n const script = scripts[0]!.code.replace(/<\\/script/giu, '<\\\\/script');\n const style = styles\n .map((item) => (typeof item.source === 'string' ? item.source : Buffer.from(item.source).toString('utf8')))\n .join('\\n')\n .replace(/<\\/style/giu, '<\\\\/style');\n const html = `<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Po tools</title><style>${style}</style></head><body><div id=\"root\"></div><script>${script}</script></body></html>`;\n await fs.writeFile(path.join(directory, 'index.html'), html);\n // Only immutable HTML is served. The generated imports remain useful for diagnosing a sync build.\n return {\n file: './ui/index.html',\n sha256: crypto.createHash('sha256').update(html).digest('hex'),\n inputs: await Promise.all(\n [...inputs].sort().map(async (file) => ({\n path: file,\n sha256: crypto\n .createHash('sha256')\n .update(await fs.readFile(file))\n .digest('hex'),\n })),\n ),\n };\n}\n"],"mappings":";;;;;;AAkBA,eAAsB,aAAa,gBAA4C;CAC7E,MAAM,UAAU,cAAc,YAAY,GAAG;CAC7C,MAAM,OAAO,kBAAkB,KAAK,QAAQ,QAAQ,QAAQ,2CAA2C,CAAC;CACxG,MAAM,eAAe,QAAQ,QAAQ,iCAAiC;CACtE,MAAM,eAAe,cAAc,YAAY;CAC/C,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,yBAAS,IAAI,IAAY;EAAC,YAAY;EAAU;EAAc,GAAG;CAAK,CA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CAAC,GAAG,KAAK,SAAS,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,GAChO;CACF,MAAM,SAAS,QAAQ,EAAE,CAAE,KAAK,QAAQ,gBAAgB,YAAY;CAKpE,MAAM,OAAO,gKAJC,OACX,KAAK,SAAU,OAAO,KAAK,WAAW,WAAW,KAAK,SAAS,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,CAAE,CAAC,CAC1G,KAAK,IAAI,CAAC,CACV,QAAQ,eAAe,WACuJ,EAAE,oDAAoD,OAAO;CAC9O,MAAM,GAAG,UAAU,KAAK,KAAK,WAAW,YAAY,GAAG,IAAI;CAE3D,OAAO;EACL,MAAM;EACN,QAAQ,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK;EAC7D,QAAQ,MAAM,QAAQ,IACpB,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,UAAU;GACtC,MAAM;GACN,QAAQ,OACL,WAAW,QAAQ,CAAC,CACpB,OAAO,MAAM,GAAG,SAAS,IAAI,CAAC,CAAC,CAC/B,OAAO,KAAK;EACjB,EAAE,CACJ;CACF;AACF"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_packageUrl = require("./packageUrl.cjs");
|
|
3
3
|
const require_mcpApp = require("./mcpApp.cjs");
|
|
4
|
-
let node_fs = require("node:fs");
|
|
5
|
-
node_fs = require_runtime.__toESM(node_fs, 1);
|
|
6
4
|
let node_path = require("node:path");
|
|
7
5
|
node_path = require_runtime.__toESM(node_path, 1);
|
|
6
|
+
let _agimon_ai_po_core_nodePlatform = require("@agimon-ai/po-core/nodePlatform");
|
|
7
|
+
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
8
8
|
let node_crypto = require("node:crypto");
|
|
9
9
|
node_crypto = require_runtime.__toESM(node_crypto, 1);
|
|
10
10
|
//#region src/builders/server/mcpAppBuild.ts
|
|
11
|
-
function widgetSources(candidates) {
|
|
11
|
+
async function widgetSources(candidates, files) {
|
|
12
12
|
const sources = [];
|
|
13
13
|
for (const { declaration } of candidates) {
|
|
14
14
|
if (!declaration.ui || declaration.ui.widgets.length === 0) continue;
|
|
15
|
-
const root =
|
|
16
|
-
const file =
|
|
15
|
+
const root = (0, _agimon_ai_po_core_platform.getOrThrow)(await files.canonicalPath(declaration.packageDir, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
16
|
+
const file = (0, _agimon_ai_po_core_platform.getOrThrow)(await files.canonicalPath(node_path.default.resolve(root, declaration.ui.dist), _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
17
17
|
const relative = node_path.default.relative(root, file);
|
|
18
18
|
if (relative === ".." || relative.startsWith(`..${node_path.default.sep}`) || node_path.default.isAbsolute(relative)) throw new Error(`MCP UI entry escapes package: ${declaration.packageName}`);
|
|
19
19
|
sources.push({
|
|
@@ -24,84 +24,104 @@ function widgetSources(candidates) {
|
|
|
24
24
|
return sources;
|
|
25
25
|
}
|
|
26
26
|
/** Content key over every widget package's files, so any source change moves it. */
|
|
27
|
-
function mcpAppKey(candidates, inputs) {
|
|
27
|
+
async function mcpAppKey(candidates, inputs, files = (0, _agimon_ai_po_core_nodePlatform.createNodePlatform)().env(process.cwd())) {
|
|
28
28
|
const hash = node_crypto.default.createHash("sha256");
|
|
29
29
|
let any = false;
|
|
30
30
|
for (const { declaration } of candidates) {
|
|
31
31
|
if (!declaration.ui || declaration.ui.widgets.length === 0) continue;
|
|
32
32
|
any = true;
|
|
33
|
-
const root =
|
|
33
|
+
const root = (0, _agimon_ai_po_core_platform.getOrThrow)(await files.canonicalPath(declaration.packageDir, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
34
34
|
const entry = node_path.default.resolve(root, declaration.ui.dist);
|
|
35
35
|
hash.update(`${declaration.packageName}\0${root}\0${declaration.ui.widgets.join(",")}\0`);
|
|
36
|
-
hash.update(require_packageUrl.statSignature(root, require_packageUrl.snapshotFiles(root, entry)));
|
|
36
|
+
hash.update(await require_packageUrl.statSignature(root, await require_packageUrl.snapshotFiles(root, entry, files), files));
|
|
37
37
|
hash.update("\n");
|
|
38
38
|
}
|
|
39
39
|
if (!any) return void 0;
|
|
40
|
-
for (const file of [...inputs ?? require_mcpApp.mcpAppInputs(), __filename].sort()) {
|
|
40
|
+
for (const file of [...inputs ?? await require_mcpApp.mcpAppInputs(), __filename].sort()) {
|
|
41
41
|
hash.update(`${file}\0`);
|
|
42
|
-
hash.update(node_crypto.default.createHash("sha256").update(
|
|
42
|
+
hash.update(node_crypto.default.createHash("sha256").update((0, _agimon_ai_po_core_platform.getOrThrow)(await files.readBinaryFile(file, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT))).digest());
|
|
43
43
|
}
|
|
44
44
|
return hash.digest("hex").slice(0, 32);
|
|
45
45
|
}
|
|
46
46
|
function mcpAppFile(poHome, key) {
|
|
47
47
|
return node_path.default.join(poHome, "build", "mcp-app", key, "index.html");
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const loadedBuilds = /* @__PURE__ */ new Map();
|
|
50
|
+
async function loadedBuild(key, file, files) {
|
|
51
|
+
const cached = loadedBuilds.get(file);
|
|
52
|
+
if (cached !== void 0) return cached;
|
|
53
|
+
const html = (0, _agimon_ai_po_core_platform.getOrThrow)(await files.readTextFile(file, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
54
|
+
const build = {
|
|
52
55
|
key,
|
|
53
56
|
file,
|
|
54
57
|
html,
|
|
55
58
|
sha256: node_crypto.default.createHash("sha256").update(html).digest("hex")
|
|
56
59
|
};
|
|
60
|
+
loadedBuilds.set(file, build);
|
|
61
|
+
const [oldest] = loadedBuilds.keys();
|
|
62
|
+
if (loadedBuilds.size > 4 && oldest !== void 0) loadedBuilds.delete(oldest);
|
|
63
|
+
return build;
|
|
57
64
|
}
|
|
58
65
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* Undefined when no candidate declares UI widgets. Otherwise the key, plus the build when its
|
|
62
|
-
* file exists; a missing build means sync has not prepared this widget set yet.
|
|
66
|
+
* Keys by candidate list. The bundler hands every session of a root the same list until a sync or watched change
|
|
67
|
+
* invalidates it, so sessions opening together hash the widget packages once instead of once each.
|
|
63
68
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
const keysByCandidates = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
function sharedMcpAppKey(candidates, files) {
|
|
71
|
+
let key = keysByCandidates.get(candidates);
|
|
72
|
+
if (key === void 0) {
|
|
73
|
+
key = mcpAppKey(candidates, void 0, files);
|
|
74
|
+
keysByCandidates.set(candidates, key);
|
|
75
|
+
key.catch(() => {
|
|
76
|
+
if (keysByCandidates.get(candidates) === key) keysByCandidates.delete(candidates);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return key;
|
|
80
|
+
}
|
|
81
|
+
/** Reads sync's build without building. A missing HTML file returns only its expected key. */
|
|
82
|
+
async function readMcpAppBuild(input) {
|
|
83
|
+
const files = input.files ?? (0, _agimon_ai_po_core_nodePlatform.createNodePlatform)().env(input.poHome);
|
|
84
|
+
const key = await sharedMcpAppKey(input.candidates, files);
|
|
66
85
|
if (key === void 0) return void 0;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
try {
|
|
87
|
+
return {
|
|
88
|
+
key,
|
|
89
|
+
build: await loadedBuild(key, mcpAppFile(input.poHome, key), files)
|
|
90
|
+
};
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error instanceof Error && "code" in error && error.code === "not_found") return { key };
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
72
95
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Builds the composed MCP App HTML for live MCP plugins at `<home>/build/mcp-app/<key>/index.html`.
|
|
75
|
-
*
|
|
76
|
-
* An existing key is reused without building. A new key builds into a temporary
|
|
77
|
-
* sibling directory and is renamed into place.
|
|
78
|
-
*/
|
|
96
|
+
/** Builds into a temporary sibling and atomically publishes the immutable HTML. */
|
|
79
97
|
async function ensureMcpAppBuild(input) {
|
|
80
|
-
const
|
|
98
|
+
const files = input.files ?? (0, _agimon_ai_po_core_nodePlatform.createNodePlatform)().env(input.poHome);
|
|
99
|
+
const key = await mcpAppKey(input.candidates, void 0, files);
|
|
81
100
|
if (key === void 0) return void 0;
|
|
82
101
|
const file = mcpAppFile(input.poHome, key);
|
|
83
102
|
const directory = node_path.default.dirname(file);
|
|
84
103
|
const parent = node_path.default.dirname(directory);
|
|
85
|
-
if (!
|
|
86
|
-
|
|
87
|
-
const temporary =
|
|
104
|
+
if (!await (0, _agimon_ai_po_core_platform.pathExists)(files, file, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT)) {
|
|
105
|
+
(0, _agimon_ai_po_core_platform.getOrThrow)(await files.createDir(parent, { recursive: true }, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
106
|
+
const temporary = node_path.default.join(parent, `.${key}-${node_crypto.default.randomUUID()}`);
|
|
107
|
+
(0, _agimon_ai_po_core_platform.getOrThrow)(await files.createDir(temporary, void 0, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
88
108
|
try {
|
|
89
|
-
const built = await (input.bundle ?? require_mcpApp.bundleMcpApp)(widgetSources(input.candidates), temporary);
|
|
109
|
+
const built = await (input.bundle ?? require_mcpApp.bundleMcpApp)(await widgetSources(input.candidates, files), temporary);
|
|
90
110
|
if (built === void 0) return void 0;
|
|
91
|
-
|
|
111
|
+
(0, _agimon_ai_po_core_platform.getOrThrow)(await files.writeFile(node_path.default.join(temporary, "index.html"), (0, _agimon_ai_po_core_platform.getOrThrow)(await files.readBinaryFile(node_path.default.join(temporary, built.file), _agimon_ai_po_core_platform.BACKGROUND_CONTEXT)), _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
92
112
|
try {
|
|
93
|
-
|
|
113
|
+
(0, _agimon_ai_po_core_platform.getOrThrow)(await files.renameFile(temporary, directory, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
94
114
|
} catch (error) {
|
|
95
|
-
if (!
|
|
115
|
+
if (!await (0, _agimon_ai_po_core_platform.pathExists)(files, file, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT)) throw error;
|
|
96
116
|
}
|
|
97
117
|
} finally {
|
|
98
|
-
|
|
118
|
+
(0, _agimon_ai_po_core_platform.getOrThrow)(await files.remove(temporary, {
|
|
99
119
|
recursive: true,
|
|
100
120
|
force: true
|
|
101
|
-
});
|
|
121
|
+
}, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT));
|
|
102
122
|
}
|
|
103
123
|
}
|
|
104
|
-
return loadedBuild(key, file);
|
|
124
|
+
return loadedBuild(key, file, files);
|
|
105
125
|
}
|
|
106
126
|
//#endregion
|
|
107
127
|
exports.ensureMcpAppBuild = ensureMcpAppBuild;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcpAppBuild.cjs","names":["fs","path","crypto","statSignature","snapshotFiles","mcpAppInputs","bundleMcpApp"],"sources":["../../../../src/builders/server/mcpAppBuild.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { bundleMcpApp, mcpAppInputs, type McpAppSource } from './mcpApp';\nimport type { McpPluginCandidate } from './mcpBundle';\nimport { snapshotFiles, statSignature } from './packageUrl';\n\nexport interface McpAppBuild {\n readonly key: string;\n readonly file: string;\n readonly html: string;\n readonly sha256: string;\n}\n\nexport interface McpAppBuildInput {\n readonly poHome: string;\n readonly candidates: readonly McpPluginCandidate[];\n /** Test seam; defaults to `bundleMcpApp`. */\n readonly bundle?: typeof bundleMcpApp;\n}\n\nfunction widgetSources(candidates: readonly McpPluginCandidate[]): McpAppSource[] {\n const sources: McpAppSource[] = [];\n for (const { declaration } of candidates) {\n if (!declaration.ui || declaration.ui.widgets.length === 0) continue;\n const root = fs.realpathSync(declaration.packageDir);\n const file = fs.realpathSync(path.resolve(root, declaration.ui.dist));\n const relative = path.relative(root, file);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error(`MCP UI entry escapes package: ${declaration.packageName}`);\n sources.push({ file, widgets: declaration.ui.widgets });\n }\n return sources;\n}\n\n/** Content key over every widget package's files, so any source change moves it. */\nexport function mcpAppKey(candidates: readonly McpPluginCandidate[], inputs?: readonly string[]): string | undefined {\n const hash = crypto.createHash('sha256');\n let any = false;\n for (const { declaration } of candidates) {\n if (!declaration.ui || declaration.ui.widgets.length === 0) continue;\n any = true;\n const root = fs.realpathSync(declaration.packageDir);\n const entry = path.resolve(root, declaration.ui.dist);\n hash.update(`${declaration.packageName}\\0${root}\\0${declaration.ui.widgets.join(',')}\\0`);\n hash.update(statSignature(root, snapshotFiles(root, entry)));\n hash.update('\\n');\n }\n if (!any) return undefined;\n for (const file of [...(inputs ?? mcpAppInputs()), import.meta.filename].sort()) {\n hash.update(`${file}\\0`);\n hash.update(crypto.createHash('sha256').update(fs.readFileSync(file)).digest());\n }\n return hash.digest('hex').slice(0, 32);\n}\n\nfunction mcpAppFile(poHome: string, key: string): string {\n return path.join(poHome, 'build', 'mcp-app', key, 'index.html');\n}\n\nfunction loadedBuild(key: string, file: string): McpAppBuild {\n const html = fs.readFileSync(file, 'utf8');\n return { key, file, html, sha256: crypto.createHash('sha256').update(html).digest('hex') };\n}\n\n/**\n * Reads the MCP app sync built for these candidates, without building anything.\n *\n * Undefined when no candidate declares UI widgets. Otherwise the key, plus the build when its\n * file exists; a missing build means sync has not prepared this widget set yet.\n */\nexport function readMcpAppBuild(\n input: Pick<McpAppBuildInput, 'poHome' | 'candidates'>,\n): { key: string; build?: McpAppBuild } | undefined {\n const key = mcpAppKey(input.candidates);\n if (key === undefined) return undefined;\n const file = mcpAppFile(input.poHome, key);\n return fs.existsSync(file) ? { key, build: loadedBuild(key, file) } : { key };\n}\n\n/**\n * Builds the composed MCP App HTML for live MCP plugins at `<home>/build/mcp-app/<key>/index.html`.\n *\n * An existing key is reused without building. A new key builds into a temporary\n * sibling directory and is renamed into place.\n */\nexport async function ensureMcpAppBuild(input: McpAppBuildInput): Promise<McpAppBuild | undefined> {\n const key = mcpAppKey(input.candidates);\n if (key === undefined) return undefined;\n const file = mcpAppFile(input.poHome, key);\n const directory = path.dirname(file);\n const parent = path.dirname(directory);\n if (!fs.existsSync(file)) {\n fs.mkdirSync(parent, { recursive: true });\n const temporary = fs.mkdtempSync(path.join(parent, `.${key}-`));\n try {\n const built = await (input.bundle ?? bundleMcpApp)(widgetSources(input.candidates), temporary);\n if (built === undefined) return undefined;\n fs.copyFileSync(path.join(temporary, built.file), path.join(temporary, 'index.html'));\n try {\n fs.renameSync(temporary, directory);\n } catch (error) {\n // A concurrent build of the same key already published it.\n if (!fs.existsSync(file)) throw error;\n }\n } finally {\n fs.rmSync(temporary, { recursive: true, force: true });\n }\n }\n return loadedBuild(key, file);\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAS,cAAc,YAA2D;CAChF,MAAM,UAA0B,CAAC;CACjC,KAAK,MAAM,EAAE,iBAAiB,YAAY;EACxC,IAAI,CAAC,YAAY,MAAM,YAAY,GAAG,QAAQ,WAAW,GAAG;EAC5D,MAAM,OAAOA,QAAAA,QAAG,aAAa,YAAY,UAAU;EACnD,MAAM,OAAOA,QAAAA,QAAG,aAAaC,UAAAA,QAAK,QAAQ,MAAM,YAAY,GAAG,IAAI,CAAC;EACpE,MAAM,WAAWA,UAAAA,QAAK,SAAS,MAAM,IAAI;EACzC,IAAI,aAAa,QAAQ,SAAS,WAAW,KAAKA,UAAAA,QAAK,KAAK,KAAKA,UAAAA,QAAK,WAAW,QAAQ,GACvF,MAAM,IAAI,MAAM,iCAAiC,YAAY,aAAa;EAC5E,QAAQ,KAAK;GAAE;GAAM,SAA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AC9B"}
|
|
1
|
+
{"version":3,"file":"mcpAppBuild.cjs","names":["getOrThrow","BACKGROUND_CONTEXT","path","createNodePlatform","crypto","statSignature","snapshotFiles","mcpAppInputs","pathExists","bundleMcpApp"],"sources":["../../../../src/builders/server/mcpAppBuild.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport path from 'node:path';\n\nimport { createNodePlatform } from '@agimon-ai/po-core/nodePlatform';\nimport { BACKGROUND_CONTEXT, type FileSystem, getOrThrow, pathExists } from '@agimon-ai/po-core/platform';\n\nimport { bundleMcpApp, mcpAppInputs, type McpAppSource } from './mcpApp';\nimport type { McpPluginCandidate } from './mcpBundle';\nimport { snapshotFiles, statSignature } from './packageUrl';\n\nexport interface McpAppBuild {\n readonly key: string;\n readonly file: string;\n readonly html: string;\n readonly sha256: string;\n}\n\nexport interface McpAppBuildInput {\n readonly files?: FileSystem;\n readonly poHome: string;\n readonly candidates: readonly McpPluginCandidate[];\n /** Test seam; defaults to `bundleMcpApp`. */\n readonly bundle?: typeof bundleMcpApp;\n}\n\nasync function widgetSources(candidates: readonly McpPluginCandidate[], files: FileSystem): Promise<McpAppSource[]> {\n const sources: McpAppSource[] = [];\n for (const { declaration } of candidates) {\n if (!declaration.ui || declaration.ui.widgets.length === 0) continue;\n const root = getOrThrow(await files.canonicalPath(declaration.packageDir, BACKGROUND_CONTEXT));\n const file = getOrThrow(await files.canonicalPath(path.resolve(root, declaration.ui.dist), BACKGROUND_CONTEXT));\n const relative = path.relative(root, file);\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))\n throw new Error(`MCP UI entry escapes package: ${declaration.packageName}`);\n sources.push({ file, widgets: declaration.ui.widgets });\n }\n return sources;\n}\n\n/** Content key over every widget package's files, so any source change moves it. */\nexport async function mcpAppKey(\n candidates: readonly McpPluginCandidate[],\n inputs?: readonly string[],\n files: FileSystem = createNodePlatform().env(process.cwd()),\n): Promise<string | undefined> {\n const hash = crypto.createHash('sha256');\n let any = false;\n for (const { declaration } of candidates) {\n if (!declaration.ui || declaration.ui.widgets.length === 0) continue;\n any = true;\n const root = getOrThrow(await files.canonicalPath(declaration.packageDir, BACKGROUND_CONTEXT));\n const entry = path.resolve(root, declaration.ui.dist);\n hash.update(`${declaration.packageName}\\0${root}\\0${declaration.ui.widgets.join(',')}\\0`);\n hash.update(await statSignature(root, await snapshotFiles(root, entry, files), files));\n hash.update('\\n');\n }\n if (!any) return undefined;\n for (const file of [...(inputs ?? (await mcpAppInputs())), import.meta.filename].sort()) {\n hash.update(`${file}\\0`);\n hash.update(\n crypto\n .createHash('sha256')\n .update(getOrThrow(await files.readBinaryFile(file, BACKGROUND_CONTEXT)))\n .digest(),\n );\n }\n return hash.digest('hex').slice(0, 32);\n}\n\nfunction mcpAppFile(poHome: string, key: string): string {\n return path.join(poHome, 'build', 'mcp-app', key, 'index.html');\n}\n\n// A published build never changes, so every session shares one copy of its HTML (about 1.7 MB).\n// Rebuilds publish new keys, so only the most recent few stay cached.\nconst loadedBuilds = new Map<string, McpAppBuild>();\n\nasync function loadedBuild(key: string, file: string, files: FileSystem): Promise<McpAppBuild> {\n const cached = loadedBuilds.get(file);\n if (cached !== undefined) return cached;\n const html = getOrThrow(await files.readTextFile(file, BACKGROUND_CONTEXT));\n const build = { key, file, html, sha256: crypto.createHash('sha256').update(html).digest('hex') };\n loadedBuilds.set(file, build);\n const [oldest] = loadedBuilds.keys();\n if (loadedBuilds.size > 4 && oldest !== undefined) loadedBuilds.delete(oldest);\n return build;\n}\n\n/**\n * Keys by candidate list. The bundler hands every session of a root the same list until a sync or watched change\n * invalidates it, so sessions opening together hash the widget packages once instead of once each.\n */\nconst keysByCandidates = new WeakMap<readonly McpPluginCandidate[], Promise<string | undefined>>();\n\nfunction sharedMcpAppKey(candidates: readonly McpPluginCandidate[], files: FileSystem): Promise<string | undefined> {\n let key = keysByCandidates.get(candidates);\n if (key === undefined) {\n key = mcpAppKey(candidates, undefined, files);\n keysByCandidates.set(candidates, key);\n // A failed read is retried by the next session rather than remembered.\n key.catch(() => {\n if (keysByCandidates.get(candidates) === key) keysByCandidates.delete(candidates);\n });\n }\n return key;\n}\n\n/** Reads sync's build without building. A missing HTML file returns only its expected key. */\nexport async function readMcpAppBuild(\n input: Pick<McpAppBuildInput, 'poHome' | 'candidates' | 'files'>,\n): Promise<{ key: string; build?: McpAppBuild } | undefined> {\n const files = input.files ?? createNodePlatform().env(input.poHome);\n const key = await sharedMcpAppKey(input.candidates, files);\n if (key === undefined) return undefined;\n try {\n return { key, build: await loadedBuild(key, mcpAppFile(input.poHome, key), files) };\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'not_found') return { key };\n throw error;\n }\n}\n\n/** Builds into a temporary sibling and atomically publishes the immutable HTML. */\nexport async function ensureMcpAppBuild(input: McpAppBuildInput): Promise<McpAppBuild | undefined> {\n const files = input.files ?? createNodePlatform().env(input.poHome);\n const key = await mcpAppKey(input.candidates, undefined, files);\n if (key === undefined) return undefined;\n const file = mcpAppFile(input.poHome, key);\n const directory = path.dirname(file);\n const parent = path.dirname(directory);\n if (!(await pathExists(files, file, BACKGROUND_CONTEXT))) {\n getOrThrow(await files.createDir(parent, { recursive: true }, BACKGROUND_CONTEXT));\n const temporary = path.join(parent, `.${key}-${crypto.randomUUID()}`);\n getOrThrow(await files.createDir(temporary, undefined, BACKGROUND_CONTEXT));\n try {\n const built = await (input.bundle ?? bundleMcpApp)(await widgetSources(input.candidates, files), temporary);\n if (built === undefined) return undefined;\n getOrThrow(\n await files.writeFile(\n path.join(temporary, 'index.html'),\n getOrThrow(await files.readBinaryFile(path.join(temporary, built.file), BACKGROUND_CONTEXT)),\n BACKGROUND_CONTEXT,\n ),\n );\n try {\n getOrThrow(await files.renameFile(temporary, directory, BACKGROUND_CONTEXT));\n } catch (error) {\n // A concurrent build of the same key already published it.\n if (!(await pathExists(files, file, BACKGROUND_CONTEXT))) throw error;\n }\n } finally {\n getOrThrow(await files.remove(temporary, { recursive: true, force: true }, BACKGROUND_CONT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