@agimon-ai/po 0.0.0-alpha.21 → 0.0.0-alpha.211
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/locales/vi.cjs +218 -0
- package/dist/locales/vi.cjs.map +1 -0
- package/dist/locales/vi.mjs +213 -0
- package/dist/locales/vi.mjs.map +1 -0
- package/dist/locales/zh-CN.cjs +218 -0
- package/dist/locales/zh-CN.cjs.map +1 -0
- package/dist/locales/zh-CN.mjs +213 -0
- package/dist/locales/zh-CN.mjs.map +1 -0
- 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 +58 -19
- package/dist/src/builders/server/index.cjs.map +1 -1
- package/dist/src/builders/server/index.mjs +57 -19
- 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 +2750 -486
- package/dist/src/builders/server/runtime.cjs.map +1 -1
- package/dist/src/builders/server/runtime.mjs +2760 -500
- 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 +92 -59
- package/dist/src/builders/web/index.cjs.map +1 -1
- package/dist/src/builders/web/index.d.mts +21 -14
- package/dist/src/builders/web/index.d.mts.map +1 -1
- package/dist/src/builders/web/index.mjs +91 -59
- 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 +30 -0
- package/dist/src/cli/locale.cjs.map +1 -0
- package/dist/src/cli/locale.mjs +27 -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 +2 -0
- package/dist/webBuilder.d.mts +3 -3
- package/dist/webBuilder.mjs +3 -3
- 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/locales/vi.json +208 -0
- package/locales/zh-CN.json +208 -0
- package/package.json +52 -69
- 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
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { containedAdoptSessionMethod, containedCloseSessionMethod, containedCreateInput, containedCreateSessionMethod } from "./containedSessions.mjs";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { MODEL_GATEWAY_FRAME_TYPE, runModelGateway } from "@agimon-ai/po-core/modelGateway";
|
|
4
|
+
import { definePoPluginMethod } from "@agimon-ai/po-core/pluginProtocol";
|
|
5
|
+
import WebSocket from "ws";
|
|
6
|
+
import { PoChannelsContract, PoHubBotSettingsContract, PoHubContract, PoSessionContract, SESSION_BOT_CHANGED_FRAME, SESSION_GROUPS_CHANGED_FRAME, createProtocolClient, createTextLink, transcriptPageQuery } from "@agimon-ai/po-core/sessionProtocol";
|
|
7
|
+
//#region src/builders/server/sandboxRouter.ts
|
|
8
|
+
/** Why a contained workspace cannot open, or reach, a session right now. */
|
|
9
|
+
const SANDBOX_UNREACHABLE = "This workspace's sandbox is not running, so its sessions are unavailable.";
|
|
10
|
+
const RECONNECT_MS = 2e3;
|
|
11
|
+
const CONNECT_TIMEOUT_MS = 15e3;
|
|
12
|
+
/** How long opening a session waits for a container that runs but does not listen yet. */
|
|
13
|
+
const START_WAIT_MS = 6e4;
|
|
14
|
+
const MIRROR_WAIT_MS = 6e4;
|
|
15
|
+
const TOKEN_HEADER = "x-po-token";
|
|
16
|
+
/** The largest protocol message the host accepts from a container, as a contained server accepts from its host. */
|
|
17
|
+
const MAX_PAYLOAD_BYTES = 8388608;
|
|
18
|
+
const Json = Type.Unsafe({});
|
|
19
|
+
/**
|
|
20
|
+
* Session plugin methods the host forwards to the container, and nothing else: never `mcp.apps`, `voice.control`,
|
|
21
|
+
* anything of the machine API or login, and never a global `/api/plugins/*` route.
|
|
22
|
+
*/
|
|
23
|
+
const FORWARDED_SESSION_METHODS = [
|
|
24
|
+
{
|
|
25
|
+
service: "browse",
|
|
26
|
+
method: "frame"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
service: "browse",
|
|
30
|
+
method: "snapshot"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
service: "browse",
|
|
34
|
+
method: "close"
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
function message(error) {
|
|
38
|
+
return error instanceof Error ? error.message : String(error);
|
|
39
|
+
}
|
|
40
|
+
/** A held reference's value, or `fallback` while it is still loading. */
|
|
41
|
+
function readyValue(readable, fallback) {
|
|
42
|
+
try {
|
|
43
|
+
return readable.value;
|
|
44
|
+
} catch {
|
|
45
|
+
return fallback;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** A text protocol link over a WebSocket to a container's loopback listener; the token travels as a header. */
|
|
49
|
+
async function openWebSocketLink(endpoint) {
|
|
50
|
+
const socket = new WebSocket(`${endpoint.origin.replace(/^http/u, "ws")}/api/ws`, {
|
|
51
|
+
headers: { [TOKEN_HEADER]: endpoint.token },
|
|
52
|
+
maxPayload: MAX_PAYLOAD_BYTES
|
|
53
|
+
});
|
|
54
|
+
const port = createTextLink({
|
|
55
|
+
send: (text) => {
|
|
56
|
+
if (socket.readyState === WebSocket.OPEN) socket.send(text);
|
|
57
|
+
},
|
|
58
|
+
close: () => socket.close()
|
|
59
|
+
});
|
|
60
|
+
socket.on("message", (data) => port.deliver((Array.isArray(data) ? Buffer.concat(data) : Buffer.from(data)).toString("utf8")));
|
|
61
|
+
socket.on("close", () => port.ended("socket closed"));
|
|
62
|
+
await new Promise((resolve, reject) => {
|
|
63
|
+
const timer = setTimeout(() => {
|
|
64
|
+
socket.terminate();
|
|
65
|
+
reject(/* @__PURE__ */ new Error("The sandbox did not answer in time."));
|
|
66
|
+
}, CONNECT_TIMEOUT_MS);
|
|
67
|
+
socket.once("open", () => {
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
socket.once("error", (error) => {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
reject(error);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
socket.on("error", () => port.ended("socket failed"));
|
|
77
|
+
return port.link;
|
|
78
|
+
}
|
|
79
|
+
function dormantRecord(view, workspaceId) {
|
|
80
|
+
return {
|
|
81
|
+
sessionId: view.id,
|
|
82
|
+
workspaceId,
|
|
83
|
+
cwd: view.cwd,
|
|
84
|
+
name: view.name,
|
|
85
|
+
createdAt: view.createdAt,
|
|
86
|
+
...view.parentSessionId === void 0 ? {} : { parentSessionId: view.parentSessionId },
|
|
87
|
+
...view.sessionProvenance === void 0 ? {} : { sessionProvenance: view.sessionProvenance },
|
|
88
|
+
...view.interaction === void 0 ? {} : { interaction: view.interaction },
|
|
89
|
+
...view.groups === void 0 ? {} : { groups: [...view.groups] },
|
|
90
|
+
...view.bot === void 0 ? {} : {
|
|
91
|
+
bot: { ...view.bot },
|
|
92
|
+
botRevision: view.botRevision ?? 0
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const sameList = (left, right) => JSON.stringify(left ?? []) === JSON.stringify(right ?? []);
|
|
97
|
+
/** The empty channel view a gateway watches until a container session gives it a real one. */
|
|
98
|
+
const NO_CHANNELS = { latest: {
|
|
99
|
+
value: {},
|
|
100
|
+
subscribe: () => () => void 0
|
|
101
|
+
} };
|
|
102
|
+
function createSandboxRouter(options) {
|
|
103
|
+
const { hub } = options;
|
|
104
|
+
const notice = (text) => options.onNotice(text);
|
|
105
|
+
const doFetch = options.fetch ?? fetch;
|
|
106
|
+
const reconnectMs = options.reconnectMs ?? RECONNECT_MS;
|
|
107
|
+
const startWaitMs = options.startWaitMs ?? START_WAIT_MS;
|
|
108
|
+
const openLink = (endpoint) => options.openLink === void 0 ? openWebSocketLink(endpoint) : options.openLink(endpoint);
|
|
109
|
+
const links = /* @__PURE__ */ new Map();
|
|
110
|
+
const mirrors = /* @__PURE__ */ new Map();
|
|
111
|
+
const mirrorWaiters = /* @__PURE__ */ new Set();
|
|
112
|
+
let disposed = false;
|
|
113
|
+
const record = (workspaceId) => workspaceId === void 0 ? void 0 : options.workspaces().find((entry) => entry.id === workspaceId);
|
|
114
|
+
const contains = (workspaceId) => record(workspaceId)?.sandbox !== void 0;
|
|
115
|
+
const linkOfSession = (sessionId) => mirrors.get(sessionId)?.link ?? [...links.values()].find((link) => link.dormant.some((entry) => entry.sessionId === sessionId));
|
|
116
|
+
/** Runs `fn` against the container's hub with the caller's signal, failing at once while the link is down. */
|
|
117
|
+
const remote = (link, fn, signal) => {
|
|
118
|
+
const hubRef = link.hub;
|
|
119
|
+
if (disposed || hubRef === void 0 || !link.client.connected || hubRef.status !== "live") return Promise.reject(/* @__PURE__ */ new Error(SANDBOX_UNREACHABLE));
|
|
120
|
+
return fn(hubRef, signal === void 0 ? {} : { signal });
|
|
121
|
+
};
|
|
122
|
+
/** A request to the container's own HTTP API, with its token. */
|
|
123
|
+
const containerFetch = async (link, pathname, init = {}) => {
|
|
124
|
+
const endpoint = link.endpoint;
|
|
125
|
+
if (endpoint === void 0 || !link.client.connected) throw new Error(SANDBOX_UNREACHABLE);
|
|
126
|
+
const headers = new Headers(init.headers);
|
|
127
|
+
headers.set(TOKEN_HEADER, endpoint.token);
|
|
128
|
+
return doFetch(new URL(pathname, endpoint.origin), {
|
|
129
|
+
...init,
|
|
130
|
+
headers
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const containerJson = async (link, pathname, init = {}) => {
|
|
134
|
+
const response = await containerFetch(link, pathname, {
|
|
135
|
+
...init,
|
|
136
|
+
...init.body === void 0 ? {} : { headers: { "content-type": "application/json" } }
|
|
137
|
+
});
|
|
138
|
+
const body = await response.json().catch(() => ({}));
|
|
139
|
+
if (!response.ok) throw new Error(typeof body.error === "string" ? body.error : `The sandbox answered ${String(response.status)}.`);
|
|
140
|
+
return body;
|
|
141
|
+
};
|
|
142
|
+
const sessionPath = (link, sessionId, suffix = "") => `/api/workspaces/${encodeURIComponent(link.workspaceId)}/sessions/${encodeURIComponent(sessionId)}${suffix}`;
|
|
143
|
+
/** Saves a container session's bot period through the container's own route. A stale revision answers `ok: false`. */
|
|
144
|
+
const putBot = async (link, sessionId, bot, expectedRevision) => {
|
|
145
|
+
const response = await containerFetch(link, sessionPath(link, sessionId, "/bot"), {
|
|
146
|
+
method: "PUT",
|
|
147
|
+
body: JSON.stringify({
|
|
148
|
+
wakePeriodMs: bot?.wakePeriodMs ?? null,
|
|
149
|
+
revision: expectedRevision
|
|
150
|
+
}),
|
|
151
|
+
headers: { "content-type": "application/json" }
|
|
152
|
+
});
|
|
153
|
+
const body = await response.json().catch(() => ({}));
|
|
154
|
+
if (response.status === 409 && typeof body.revision === "number") return {
|
|
155
|
+
ok: false,
|
|
156
|
+
revision: body.revision
|
|
157
|
+
};
|
|
158
|
+
if (!response.ok || typeof body.revision !== "number") throw new Error(typeof body.error === "string" ? body.error : `The sandbox answered ${String(response.status)}.`);
|
|
159
|
+
return {
|
|
160
|
+
ok: true,
|
|
161
|
+
revision: body.revision
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const waitForMirror = (sessionId, previous) => new Promise((resolve, reject) => {
|
|
165
|
+
const check = () => {
|
|
166
|
+
const current = mirrors.get(sessionId);
|
|
167
|
+
if (current === void 0 || current.host === previous || hub.session(sessionId)?.host !== current.host) return false;
|
|
168
|
+
clearTimeout(timer);
|
|
169
|
+
mirrorWaiters.delete(waiter);
|
|
170
|
+
resolve();
|
|
171
|
+
return true;
|
|
172
|
+
};
|
|
173
|
+
const waiter = () => {
|
|
174
|
+
check();
|
|
175
|
+
};
|
|
176
|
+
const timer = setTimeout(() => {
|
|
177
|
+
mirrorWaiters.delete(waiter);
|
|
178
|
+
reject(/* @__PURE__ */ new Error(`The sandbox session ${sessionId} did not appear on the host in time.`));
|
|
179
|
+
}, MIRROR_WAIT_MS);
|
|
180
|
+
if (!check()) mirrorWaiters.add(waiter);
|
|
181
|
+
});
|
|
182
|
+
const gatewayFollow = (link) => {
|
|
183
|
+
const gateway = link.gateway;
|
|
184
|
+
if (gateway === void 0) return;
|
|
185
|
+
if (gateway.channelsOf !== void 0 && mirrors.get(gateway.channelsOf)?.link === link) return;
|
|
186
|
+
const next = [...mirrors.values()].find((mirror) => mirror.link === link);
|
|
187
|
+
gateway.channelsOf = next?.sessionId;
|
|
188
|
+
gateway.runner.useChannels(next?.channels ?? NO_CHANNELS);
|
|
189
|
+
};
|
|
190
|
+
/** Merges the container session's channels into the host session, one session-mounted channel per frame type. */
|
|
191
|
+
const mergeChannels = (link, sessionId, channels) => {
|
|
192
|
+
const mounted = /* @__PURE__ */ new Map();
|
|
193
|
+
const publishers = /* @__PURE__ */ new Map();
|
|
194
|
+
/** The host connection that sent the last receive of a type: the next change of that type answers it only. */
|
|
195
|
+
const requesters = /* @__PURE__ */ new Map();
|
|
196
|
+
const last = /* @__PURE__ */ new Map();
|
|
197
|
+
const mount = (frameType) => {
|
|
198
|
+
if (frameType === MODEL_GATEWAY_FRAME_TYPE || mounted.has(frameType)) return;
|
|
199
|
+
const channel = {
|
|
200
|
+
frameType,
|
|
201
|
+
start(channelHost) {
|
|
202
|
+
publishers.set(frameType, channelHost);
|
|
203
|
+
return {
|
|
204
|
+
payloadFor: () => readyValue(channels.latest, {})[frameType],
|
|
205
|
+
close: () => publishers.delete(frameType)
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
receive(_scope, payload, connection) {
|
|
209
|
+
requesters.set(frameType, connection.connectionId);
|
|
210
|
+
remote(link, (_hubRef, ctx) => channels.receive({
|
|
211
|
+
type: frameType,
|
|
212
|
+
payload: { poProtocolForward: {
|
|
213
|
+
payload,
|
|
214
|
+
...connection.client === void 0 ? {} : { client: { ...connection.client } }
|
|
215
|
+
} }
|
|
216
|
+
}, ctx)).catch((error) => notice(`Sandbox channel ${frameType} for ${sessionId}: ${message(error)}`));
|
|
217
|
+
},
|
|
218
|
+
disconnected(connection) {
|
|
219
|
+
for (const [type, connectionId] of requesters) if (connectionId === connection.connectionId) requesters.delete(type);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
mounted.set(frameType, hub.registerChannel(channel, {
|
|
223
|
+
scope: "session",
|
|
224
|
+
sessionId
|
|
225
|
+
}));
|
|
226
|
+
};
|
|
227
|
+
const apply = (latest) => {
|
|
228
|
+
for (const [frameType, payload] of Object.entries(latest ?? {})) {
|
|
229
|
+
if (frameType === MODEL_GATEWAY_FRAME_TYPE) continue;
|
|
230
|
+
mount(frameType);
|
|
231
|
+
const text = JSON.stringify(payload);
|
|
232
|
+
if (last.get(frameType) === text) continue;
|
|
233
|
+
last.set(frameType, text);
|
|
234
|
+
const channelHost = publishers.get(frameType);
|
|
235
|
+
const requester = requesters.get(frameType);
|
|
236
|
+
requesters.delete(frameType);
|
|
237
|
+
if (requester !== void 0 && channelHost?.publishToConnection?.(requester, sessionId, payload) === true) continue;
|
|
238
|
+
channelHost?.publish(sessionId, payload);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
apply(readyValue(channels.latest, {}));
|
|
242
|
+
const stop = channels.latest.subscribe(apply);
|
|
243
|
+
return () => {
|
|
244
|
+
stop();
|
|
245
|
+
for (const unmount of mounted.values()) unmount();
|
|
246
|
+
mounted.clear();
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
/** Registers the allowlisted invoke forwards for one mirror session; the host's auth runs before each. */
|
|
250
|
+
const forwardMethods = (link, sessionId) => {
|
|
251
|
+
const unregister = FORWARDED_SESSION_METHODS.map(({ service, method }) => hub.pluginRegistry.register({
|
|
252
|
+
scope: "session",
|
|
253
|
+
sessionId
|
|
254
|
+
}, definePoPluginMethod({
|
|
255
|
+
service,
|
|
256
|
+
method,
|
|
257
|
+
scope: "session",
|
|
258
|
+
direction: "client-to-server",
|
|
259
|
+
input: Json,
|
|
260
|
+
output: Json
|
|
261
|
+
}), (input, caller) => remote(link, (hubRef, ctx) => hubRef.invoke({
|
|
262
|
+
mount: {
|
|
263
|
+
scope: "session",
|
|
264
|
+
sessionId
|
|
265
|
+
},
|
|
266
|
+
service: "po.protocol-forward",
|
|
267
|
+
method: "invoke",
|
|
268
|
+
input: {
|
|
269
|
+
service,
|
|
270
|
+
method,
|
|
271
|
+
input,
|
|
272
|
+
...caller.client === void 0 ? {} : { client: { ...caller.client } }
|
|
273
|
+
}
|
|
274
|
+
}, ctx), caller.signal)));
|
|
275
|
+
return () => {
|
|
276
|
+
for (const stop of unregister) stop();
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
const withBotSettings = (link, view) => {
|
|
280
|
+
const settings = link.botSettings && readyValue(link.botSettings.settings, void 0)?.[view.id];
|
|
281
|
+
return {
|
|
282
|
+
...view,
|
|
283
|
+
bot: settings?.bot,
|
|
284
|
+
botRevision: settings?.botRevision
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
const createMirror = async (link, row) => {
|
|
288
|
+
const sessionId = row.id;
|
|
289
|
+
link.creating.add(sessionId);
|
|
290
|
+
let session;
|
|
291
|
+
let channels;
|
|
292
|
+
try {
|
|
293
|
+
session = await link.client.get(PoSessionContract, { sessionId });
|
|
294
|
+
channels = await link.client.get(PoChannelsContract, { sessionId });
|
|
295
|
+
const view = withBotSettings(link, row);
|
|
296
|
+
if (disposed || link.disposed || hub.session(sessionId) !== void 0) {
|
|
297
|
+
session.release();
|
|
298
|
+
channels.release();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const heldSession = session;
|
|
302
|
+
const heldChannels = channels;
|
|
303
|
+
let resolveExit;
|
|
304
|
+
const exited = new Promise((resolve) => {
|
|
305
|
+
resolveExit = resolve;
|
|
306
|
+
});
|
|
307
|
+
const presentation = /* @__PURE__ */ new Set();
|
|
308
|
+
const call = (name, args) => remote(link, (_hubRef, ctx) => heldSession[name].call(heldSession, ...args, ctx));
|
|
309
|
+
const readState = async () => {
|
|
310
|
+
return {
|
|
311
|
+
...readyValue(heldSession.state, null)?.snapshot,
|
|
312
|
+
sessionId,
|
|
313
|
+
isStreaming: (mirror.view.phase ?? "idle") !== "idle"
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
const host = {
|
|
317
|
+
runtime: {
|
|
318
|
+
sessionId,
|
|
319
|
+
laneName: "main",
|
|
320
|
+
exited,
|
|
321
|
+
session: { snapshot: async () => ({}) },
|
|
322
|
+
readState,
|
|
323
|
+
readEntries: async () => ({
|
|
324
|
+
entries: [],
|
|
325
|
+
leafId: null
|
|
326
|
+
}),
|
|
327
|
+
submitPrompt: async (text) => ({ settled: call("prompt", [{
|
|
328
|
+
text,
|
|
329
|
+
waitFor: "settled"
|
|
330
|
+
}]).then(() => void 0) }),
|
|
331
|
+
abort: () => call("abort", []),
|
|
332
|
+
steer: (text) => call("steer", [text]),
|
|
333
|
+
setGroups: (groups) => call("setGroups", [[...groups]]),
|
|
334
|
+
setBot: (change) => putBot(link, sessionId, change.bot, change.expectedRevision)
|
|
335
|
+
},
|
|
336
|
+
agentSession: {
|
|
337
|
+
session: heldSession,
|
|
338
|
+
connected: () => link.client.connected && link.hub?.status === "live"
|
|
339
|
+
},
|
|
340
|
+
host: void 0,
|
|
341
|
+
toolSurface: {},
|
|
342
|
+
mcpSurface: {},
|
|
343
|
+
preparePackages: () => void 0,
|
|
344
|
+
activatePackages: async () => void 0,
|
|
345
|
+
canDispatch: () => false,
|
|
346
|
+
onPresentationFrame: (listener) => {
|
|
347
|
+
presentation.add(listener);
|
|
348
|
+
return () => presentation.delete(listener);
|
|
349
|
+
},
|
|
350
|
+
respondToExtensionUi: () => false,
|
|
351
|
+
dispose: async () => void 0
|
|
352
|
+
};
|
|
353
|
+
const stops = [];
|
|
354
|
+
const mirror = {
|
|
355
|
+
sessionId,
|
|
356
|
+
link,
|
|
357
|
+
host,
|
|
358
|
+
channels: heldChannels,
|
|
359
|
+
view,
|
|
360
|
+
ended: false,
|
|
361
|
+
end() {
|
|
362
|
+
if (mirror.ended) return;
|
|
363
|
+
mirror.ended = true;
|
|
364
|
+
resolveExit(0);
|
|
365
|
+
},
|
|
366
|
+
emit(frame) {
|
|
367
|
+
for (const listener of presentation) listener(frame);
|
|
368
|
+
},
|
|
369
|
+
dispose() {
|
|
370
|
+
for (const stop of stops.splice(0)) stop();
|
|
371
|
+
presentation.clear();
|
|
372
|
+
heldSession.release();
|
|
373
|
+
heldChannels.release();
|
|
374
|
+
resolveExit(0);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
stops.push(heldSession.alive.subscribe((alive) => {
|
|
378
|
+
if (!alive) mirror.end();
|
|
379
|
+
}));
|
|
380
|
+
mirrors.set(sessionId, mirror);
|
|
381
|
+
try {
|
|
382
|
+
hub.register({
|
|
383
|
+
id: sessionId,
|
|
384
|
+
workspaceId: link.workspaceId,
|
|
385
|
+
name: view.name,
|
|
386
|
+
cwd: view.cwd,
|
|
387
|
+
createdAt: view.createdAt,
|
|
388
|
+
...view.parentSessionId === void 0 ? {} : { parentSessionId: view.parentSessionId },
|
|
389
|
+
...view.sessionProvenance === void 0 ? {} : { sessionProvenance: view.sessionProvenance },
|
|
390
|
+
...view.interaction === void 0 ? {} : { interaction: view.interaction },
|
|
391
|
+
groups: [...view.groups ?? []],
|
|
392
|
+
...view.bot === void 0 ? {} : {
|
|
393
|
+
bot: { ...view.bot },
|
|
394
|
+
botRevision: view.botRevision ?? 0
|
|
395
|
+
},
|
|
396
|
+
everPrompted: view.everPrompted,
|
|
397
|
+
...view.lastSettledAt === void 0 ? {} : { lastSettledAt: view.lastSettledAt },
|
|
398
|
+
...view.phase === "idle" ? {} : { phase: view.phase },
|
|
399
|
+
awaitingInput: view.awaitingInput,
|
|
400
|
+
...options.sessionCompositions(sessionId),
|
|
401
|
+
host
|
|
402
|
+
}, () => options.sessionCompositions(sessionId));
|
|
403
|
+
} catch (error) {
|
|
404
|
+
mirrors.delete(sessionId);
|
|
405
|
+
mirror.dispose();
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
stops.push(forwardMethods(link, sessionId), mergeChannels(link, sessionId, heldChannels));
|
|
409
|
+
gatewayFollow(link);
|
|
410
|
+
replayNotices(link);
|
|
411
|
+
for (const waiter of mirrorWaiters) waiter();
|
|
412
|
+
} catch (error) {
|
|
413
|
+
session?.release();
|
|
414
|
+
channels?.release();
|
|
415
|
+
if (!disposed) notice(`Sandbox session ${sessionId} could not be mirrored: ${message(error)}`);
|
|
416
|
+
} finally {
|
|
417
|
+
link.creating.delete(sessionId);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
/** Replays the container's changes of a live session as the frames the host hub reads. */
|
|
421
|
+
const updateMirror = (mirror, row) => {
|
|
422
|
+
const view = withBotSettings(mirror.link, row);
|
|
423
|
+
const previous = mirror.view;
|
|
424
|
+
mirror.view = view;
|
|
425
|
+
const wasIdle = (previous.phase ?? "idle") === "idle";
|
|
426
|
+
const isIdle = (view.phase ?? "idle") === "idle";
|
|
427
|
+
if (wasIdle && !isIdle) mirror.emit({ type: "agent_start" });
|
|
428
|
+
if (previous.name !== view.name) mirror.emit({
|
|
429
|
+
type: "session_info_changed",
|
|
430
|
+
name: view.name
|
|
431
|
+
});
|
|
432
|
+
if (!sameList(previous.groups, view.groups)) mirror.emit({
|
|
433
|
+
type: SESSION_GROUPS_CHANGED_FRAME,
|
|
434
|
+
groups: [...view.groups ?? []]
|
|
435
|
+
});
|
|
436
|
+
if (previous.botRevision !== view.botRevision || JSON.stringify(previous.bot ?? null) !== JSON.stringify(view.bot ?? null)) mirror.emit({
|
|
437
|
+
type: SESSION_BOT_CHANGED_FRAME,
|
|
438
|
+
bot: view.bot ?? null,
|
|
439
|
+
revision: view.botRevision ?? 0
|
|
440
|
+
});
|
|
441
|
+
if (previous.awaitingInput && !view.awaitingInput) mirror.emit({ type: "extension_ui_answered" });
|
|
442
|
+
if (!wasIdle && isIdle) mirror.emit({ type: "agent_settled" });
|
|
443
|
+
};
|
|
444
|
+
/** Notification and dialog notices of mirrored sessions reach the host hub, then are acknowledged. */
|
|
445
|
+
const replayNotices = (link) => {
|
|
446
|
+
const hubRef = link.hub;
|
|
447
|
+
if (hubRef === void 0) return;
|
|
448
|
+
const pending = readyValue(hubRef.pending, []);
|
|
449
|
+
for (const entry of pending) {
|
|
450
|
+
const mirror = mirrors.get(entry.sessionId);
|
|
451
|
+
if (mirror === void 0 || mirror.link !== link || link.seenNotices.has(entry.id)) continue;
|
|
452
|
+
link.seenNotices.add(entry.id);
|
|
453
|
+
mirror.emit(entry.frame);
|
|
454
|
+
remote(link, (ref, ctx) => ref.ackNotice({ id: entry.id }, ctx)).catch((error) => notice(`Sandbox notice acknowledgement failed: ${message(error)}`));
|
|
455
|
+
}
|
|
456
|
+
const live = new Set(pending.map((entry) => entry.id));
|
|
457
|
+
for (const id of link.seenNotices) if (!live.has(id)) link.seenNotices.delete(id);
|
|
458
|
+
};
|
|
459
|
+
const syncSessions = (link) => {
|
|
460
|
+
const hubRef = link.hub;
|
|
461
|
+
if (hubRef === void 0 || link.disposed) return;
|
|
462
|
+
const views = readyValue(hubRef.sessions, void 0);
|
|
463
|
+
if (views === void 0) return;
|
|
464
|
+
const live = /* @__PURE__ */ new Map();
|
|
465
|
+
const dormant = [];
|
|
466
|
+
for (const view of Object.values(views)) {
|
|
467
|
+
if (view.workspaceId !== void 0 && view.workspaceId !== link.workspaceId) continue;
|
|
468
|
+
if (view.dormant === true) dormant.push(dormantRecord(withBotSettings(link, view), link.workspaceId));
|
|
469
|
+
else live.set(view.id, view);
|
|
470
|
+
}
|
|
471
|
+
for (const id of link.closing) if (!live.has(id)) link.closing.delete(id);
|
|
472
|
+
for (const [id, mirror] of mirrors) {
|
|
473
|
+
if (mirror.link !== link) continue;
|
|
474
|
+
const view = live.get(id);
|
|
475
|
+
if (view === void 0 || view.createdAt !== mirror.view.createdAt) mirror.end();
|
|
476
|
+
else updateMirror(mirror, view);
|
|
477
|
+
}
|
|
478
|
+
for (const [id, view] of live) if (!mirrors.has(id) && !link.creating.has(id) && !link.closing.has(id) && hub.session(id) === void 0) createMirror(link, view);
|
|
479
|
+
const before = new Map(link.dormant.map((entry) => [entry.sessionId, JSON.stringify(entry)]));
|
|
480
|
+
link.dormant = dormant;
|
|
481
|
+
link.synced = true;
|
|
482
|
+
for (const entry of dormant) if (before.get(entry.sessionId) !== JSON.stringify(entry)) hub.notifyDormantChanged(entry.sessionId);
|
|
483
|
+
for (const id of before.keys()) if (!dormant.some((entry) => entry.sessionId === id) && !live.has(id)) hub.notifySessionRemoved(id);
|
|
484
|
+
if (link.client.connected && link.botSettings && readyValue(link.botSettings.settings, void 0) !== void 0) options.onBotDirectoryReady?.(link.workspaceId);
|
|
485
|
+
};
|
|
486
|
+
const startGateway = async (link, hubRef) => {
|
|
487
|
+
const host = await options.modelGateway?.();
|
|
488
|
+
if (host === void 0 || link.disposed || link.gateway !== void 0) return;
|
|
489
|
+
const abort = new AbortController();
|
|
490
|
+
link.gateway = {
|
|
491
|
+
runner: runModelGateway({
|
|
492
|
+
hub: hubRef,
|
|
493
|
+
channels: NO_CHANNELS,
|
|
494
|
+
modelRuntime: host.modelRuntime,
|
|
495
|
+
defaultModel: () => host.defaultModel(),
|
|
496
|
+
signal: abort.signal,
|
|
497
|
+
onNotice: (text) => notice(`Workspace ${link.workspaceId} ${text}`)
|
|
498
|
+
}),
|
|
499
|
+
abort,
|
|
500
|
+
channelsOf: void 0
|
|
501
|
+
};
|
|
502
|
+
gatewayFollow(link);
|
|
503
|
+
};
|
|
504
|
+
const scheduleReconnect = (link) => {
|
|
505
|
+
if (disposed || link.disposed || link.reconnect !== void 0) return;
|
|
506
|
+
link.reconnect = setTimeout(() => {
|
|
507
|
+
link.reconnect = void 0;
|
|
508
|
+
connect(link);
|
|
509
|
+
}, reconnectMs);
|
|
510
|
+
link.reconnect.unref?.();
|
|
511
|
+
};
|
|
512
|
+
const connect = async (link) => {
|
|
513
|
+
try {
|
|
514
|
+
await link.client.connect();
|
|
515
|
+
if (link.hub === void 0) {
|
|
516
|
+
const hubRef = await link.client.get(PoHubContract, {});
|
|
517
|
+
if (link.disposed) {
|
|
518
|
+
hubRef.release();
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
link.hub = hubRef;
|
|
522
|
+
link.stops.push(hubRef.sessions.subscribe(() => syncSessions(link)), hubRef.pending.subscribe(() => replayNotices(link)));
|
|
523
|
+
const botSettings = link.client.hold(PoHubBotSettingsContract, {});
|
|
524
|
+
link.botSettings = botSettings;
|
|
525
|
+
const stopBotSettings = botSettings.settings.subscribe(() => syncSessions(link));
|
|
526
|
+
link.stops.push(() => {
|
|
527
|
+
stopBotSettings();
|
|
528
|
+
botSettings.release();
|
|
529
|
+
});
|
|
530
|
+
botSettings.ready.then(() => syncSessions(link), () => {
|
|
531
|
+
if (link.botSettings === botSettings) link.botSettings = void 0;
|
|
532
|
+
stopBotSettings();
|
|
533
|
+
botSettings.release();
|
|
534
|
+
});
|
|
535
|
+
startGateway(link, hubRef).catch((error) => notice(`Workspace ${link.workspaceId} model gateway did not start: ${message(error)}`));
|
|
536
|
+
}
|
|
537
|
+
link.lastError = void 0;
|
|
538
|
+
syncSessions(link);
|
|
539
|
+
options.onLinked?.(link.workspaceId);
|
|
540
|
+
return true;
|
|
541
|
+
} catch (error) {
|
|
542
|
+
if (!disposed && !link.disposed) {
|
|
543
|
+
if (link.lastError !== message(error)) notice(`Workspace ${link.workspaceId} sandbox link: ${message(error)}`);
|
|
544
|
+
link.lastError = message(error);
|
|
545
|
+
scheduleReconnect(link);
|
|
546
|
+
}
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
/** The workspace's link, made on first use. Settles false when the sandbox cannot be reached now. */
|
|
551
|
+
const ensureLink = (workspaceId) => {
|
|
552
|
+
if (disposed) return void 0;
|
|
553
|
+
const existing = links.get(workspaceId);
|
|
554
|
+
if (existing !== void 0) return existing;
|
|
555
|
+
const endpointOf = options.sandboxes.get(record(workspaceId)?.sandbox ?? "")?.endpoint;
|
|
556
|
+
if (endpointOf === void 0) return void 0;
|
|
557
|
+
const link = {
|
|
558
|
+
workspaceId,
|
|
559
|
+
client: createProtocolClient({
|
|
560
|
+
name: `po-host-${workspaceId}`,
|
|
561
|
+
openLink: async () => {
|
|
562
|
+
const endpoint = await endpointOf(workspaceId);
|
|
563
|
+
if (endpoint === void 0) throw new Error(SANDBOX_UNREACHABLE);
|
|
564
|
+
link.endpoint = endpoint;
|
|
565
|
+
return openLink(endpoint);
|
|
566
|
+
}
|
|
567
|
+
}),
|
|
568
|
+
endpoint: void 0,
|
|
569
|
+
hub: void 0,
|
|
570
|
+
ready: Promise.resolve(false),
|
|
571
|
+
dormant: [],
|
|
572
|
+
synced: false,
|
|
573
|
+
gateway: void 0,
|
|
574
|
+
creating: /* @__PURE__ */ new Set(),
|
|
575
|
+
closing: /* @__PURE__ */ new Set(),
|
|
576
|
+
seenNotices: /* @__PURE__ */ new Set(),
|
|
577
|
+
reconnect: void 0,
|
|
578
|
+
lastError: void 0,
|
|
579
|
+
disposed: false,
|
|
580
|
+
stops: []
|
|
581
|
+
};
|
|
582
|
+
link.stops.push(link.client.onConnectionStateChange(({ state }) => {
|
|
583
|
+
if (link.disposed) return;
|
|
584
|
+
options.announceWorkspace(workspaceId, state === "connected");
|
|
585
|
+
if (state !== "connected") link.synced = false;
|
|
586
|
+
if (state === "disconnected") scheduleReconnect(link);
|
|
587
|
+
}));
|
|
588
|
+
links.set(workspaceId, link);
|
|
589
|
+
link.ready = connect(link);
|
|
590
|
+
return link;
|
|
591
|
+
};
|
|
592
|
+
const liveLink = async (workspaceId) => {
|
|
593
|
+
const link = ensureLink(workspaceId);
|
|
594
|
+
if (link === void 0) throw new Error(SANDBOX_UNREACHABLE);
|
|
595
|
+
await link.ready;
|
|
596
|
+
const until = Date.now() + startWaitMs;
|
|
597
|
+
while (!link.client.connected || link.hub === void 0) {
|
|
598
|
+
if (await connect(link)) break;
|
|
599
|
+
if (link.endpoint === void 0 || Date.now() >= until || disposed) throw new Error(SANDBOX_UNREACHABLE);
|
|
600
|
+
await new Promise((resolve) => setTimeout(resolve, reconnectMs));
|
|
601
|
+
}
|
|
602
|
+
return link;
|
|
603
|
+
};
|
|
604
|
+
const disposeMirror = (mirror) => {
|
|
605
|
+
if (mirrors.get(mirror.sessionId) === mirror) mirrors.delete(mirror.sessionId);
|
|
606
|
+
mirror.dispose();
|
|
607
|
+
options.forgetCompositions(mirror.sessionId);
|
|
608
|
+
gatewayFollow(mirror.link);
|
|
609
|
+
setTimeout(() => syncSessions(mirror.link), 0);
|
|
610
|
+
};
|
|
611
|
+
const ownedLink = (sessionId) => {
|
|
612
|
+
const link = linkOfSession(sessionId);
|
|
613
|
+
if (link === void 0) throw new Error("Session not found.");
|
|
614
|
+
return link;
|
|
615
|
+
};
|
|
616
|
+
return {
|
|
617
|
+
start() {
|
|
618
|
+
for (const entry of options.workspaces()) if (entry.sandbox !== void 0) ensureLink(entry.id);
|
|
619
|
+
},
|
|
620
|
+
contains,
|
|
621
|
+
connected: (workspaceId) => {
|
|
622
|
+
const link = links.get(workspaceId);
|
|
623
|
+
return link !== void 0 && link.client.connected && link.hub !== void 0;
|
|
624
|
+
},
|
|
625
|
+
mirror: (sessionId) => mirrors.get(sessionId)?.host,
|
|
626
|
+
mirrors: () => [...mirrors.values()].map((mirror) => mirror.host),
|
|
627
|
+
owns: (sessionId) => linkOfSession(sessionId) !== void 0,
|
|
628
|
+
directoryReady: (workspaceId) => {
|
|
629
|
+
const link = links.get(workspaceId);
|
|
630
|
+
return link !== void 0 && link.client.connected && link.hub !== void 0 && link.synced;
|
|
631
|
+
},
|
|
632
|
+
dormant: () => [...links.values()].flatMap((link) => link.dormant.filter((entry) => hub.session(entry.sessionId) === void 0)),
|
|
633
|
+
async openSession(workspaceId, request, sessionId) {
|
|
634
|
+
request.signal?.throwIfAborted();
|
|
635
|
+
if ((request.parentSessionId === void 0 ? void 0 : hub.session(request.parentSessionId) ?? [...links.values()].flatMap((link) => link.dormant).find((record) => record.sessionId === request.parentSessionId))?.interaction === "unattended") request = {
|
|
636
|
+
...request,
|
|
637
|
+
interaction: "unattended"
|
|
638
|
+
};
|
|
639
|
+
if (request.workflowContext !== void 0 || request.reservationId !== void 0) throw new Error("Workflow steps and reserved sessions cannot run in a sandboxed workspace yet.");
|
|
640
|
+
const link = await liveLink(workspaceId);
|
|
641
|
+
const opened = await remote(link, (hubRef, ctx) => hubRef.invoke({
|
|
642
|
+
mount: { scope: "host" },
|
|
643
|
+
service: containedCreateSessionMethod.service,
|
|
644
|
+
method: containedCreateSessionMethod.method,
|
|
645
|
+
input: containedCreateInput(request, sessionId)
|
|
646
|
+
}, ctx), request.signal);
|
|
647
|
+
if (opened.workspaceId !== void 0 && opened.workspaceId !== workspaceId) notice(`The sandbox of ${workspaceId} opened session ${opened.sessionId} in workspace ${opened.workspaceId}.`);
|
|
648
|
+
await waitForMirror(opened.sessionId);
|
|
649
|
+
return {
|
|
650
|
+
sessionId: opened.sessionId,
|
|
651
|
+
cwd: opened.cwd,
|
|
652
|
+
workspaceId
|
|
653
|
+
};
|
|
654
|
+
},
|
|
655
|
+
async closeSession(sessionId, closeOptions = {}) {
|
|
656
|
+
const mirror = mirrors.get(sessionId);
|
|
657
|
+
if (mirror === void 0) return;
|
|
658
|
+
try {
|
|
659
|
+
if (!mirror.ended && closeOptions.disposeOnly !== true) {
|
|
660
|
+
mirror.link.closing.add(sessionId);
|
|
661
|
+
await remote(mirror.link, (hubRef, ctx) => hubRef.invoke({
|
|
662
|
+
mount: { scope: "host" },
|
|
663
|
+
service: containedCloseSessionMethod.service,
|
|
664
|
+
method: containedCloseSessionMethod.method,
|
|
665
|
+
input: {
|
|
666
|
+
sessionId,
|
|
667
|
+
...closeOptions.keepDormant === true ? { keepDormant: true } : {}
|
|
668
|
+
}
|
|
669
|
+
}, ctx)).catch((error) => {
|
|
670
|
+
mirror.link.closing.delete(sessionId);
|
|
671
|
+
throw error;
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
} finally {
|
|
675
|
+
disposeMirror(mirror);
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
async removeSession(sessionId, workspaceId) {
|
|
679
|
+
const link = linkOfSession(sessionId) ?? (workspaceId === void 0 ? void 0 : ensureLink(workspaceId)) ?? ownedLink(sessionId);
|
|
680
|
+
await containerJson(link, sessionPath(link, sessionId), { method: "DELETE" });
|
|
681
|
+
},
|
|
682
|
+
async adoptSession(workspaceId, record) {
|
|
683
|
+
const link = ensureLink(workspaceId);
|
|
684
|
+
if (link === void 0) throw new Error(SANDBOX_UNREACHABLE);
|
|
685
|
+
await remote(link, (hubRef, ctx) => hubRef.invoke({
|
|
686
|
+
mount: { scope: "host" },
|
|
687
|
+
service: containedAdoptSessionMethod.service,
|
|
688
|
+
method: containedAdoptSessionMethod.method,
|
|
689
|
+
input: {
|
|
690
|
+
sessionId: record.sessionId,
|
|
691
|
+
record
|
|
692
|
+
}
|
|
693
|
+
}, ctx));
|
|
694
|
+
},
|
|
695
|
+
async release(workspaceId) {
|
|
696
|
+
const link = links.get(workspaceId);
|
|
697
|
+
if (link === void 0) return;
|
|
698
|
+
links.delete(workspaceId);
|
|
699
|
+
link.disposed = true;
|
|
700
|
+
if (link.reconnect !== void 0) clearTimeout(link.reconnect);
|
|
701
|
+
link.gateway?.abort.abort(/* @__PURE__ */ new Error("The sandbox was switched off."));
|
|
702
|
+
for (const stop of link.stops.splice(0)) stop();
|
|
703
|
+
for (const mirror of mirrors.values()) if (mirror.link === link) mirror.end();
|
|
704
|
+
for (const entry of link.dormant) hub.notifySessionRemoved(entry.sessionId);
|
|
705
|
+
link.dormant = [];
|
|
706
|
+
link.hub?.release();
|
|
707
|
+
link.client.dispose();
|
|
708
|
+
},
|
|
709
|
+
async setDormantGroups(sessionId, groups) {
|
|
710
|
+
const link = ownedLink(sessionId);
|
|
711
|
+
await containerJson(link, sessionPath(link, sessionId, "/groups"), {
|
|
712
|
+
method: "PUT",
|
|
713
|
+
body: JSON.stringify({ groups })
|
|
714
|
+
});
|
|
715
|
+
},
|
|
716
|
+
async setDormantBot(sessionId, bot, revision) {
|
|
717
|
+
const link = ownedLink(sessionId);
|
|
718
|
+
if (!(await putBot(link, sessionId, bot, revision - 1)).ok) throw new Error("The bot settings changed. Reload and try again.");
|
|
719
|
+
},
|
|
720
|
+
async revive(sessionId, reviveOptions) {
|
|
721
|
+
if (mirrors.has(sessionId)) return;
|
|
722
|
+
const link = ownedLink(sessionId);
|
|
723
|
+
await containerJson(link, sessionPath(link, sessionId, "/revive"), {
|
|
724
|
+
method: "POST",
|
|
725
|
+
...reviveOptions?.automatic ? { body: JSON.stringify({ automatic: true }) } : {}
|
|
726
|
+
});
|
|
727
|
+
await waitForMirror(sessionId);
|
|
728
|
+
},
|
|
729
|
+
async restart(sessionId) {
|
|
730
|
+
const mirror = mirrors.get(sessionId);
|
|
731
|
+
if (mirror === void 0) throw new Error("Session not found.");
|
|
732
|
+
await containerJson(mirror.link, sessionPath(mirror.link, sessionId, "/restart"), { method: "POST" });
|
|
733
|
+
await waitForMirror(sessionId, mirror.host);
|
|
734
|
+
},
|
|
735
|
+
async resume(sessionId, targetSessionId) {
|
|
736
|
+
const mirror = mirrors.get(sessionId);
|
|
737
|
+
if (mirror === void 0) throw new Error("Session not found.");
|
|
738
|
+
const body = await containerJson(mirror.link, sessionPath(mirror.link, sessionId, "/resume"), {
|
|
739
|
+
method: "POST",
|
|
740
|
+
body: JSON.stringify({ targetSessionId })
|
|
741
|
+
});
|
|
742
|
+
await waitForMirror(body.sessionId);
|
|
743
|
+
return body.sessionId;
|
|
744
|
+
},
|
|
745
|
+
async resumeWorkspace(workspaceId, targetSessionId) {
|
|
746
|
+
const link = await liveLink(workspaceId);
|
|
747
|
+
const body = await containerJson(link, `/api/workspaces/${encodeURIComponent(workspaceId)}/resume`, {
|
|
748
|
+
method: "POST",
|
|
749
|
+
body: JSON.stringify({ targetSessionId })
|
|
750
|
+
});
|
|
751
|
+
await waitForMirror(body.sessionId);
|
|
752
|
+
return body.sessionId;
|
|
753
|
+
},
|
|
754
|
+
async history(workspaceId) {
|
|
755
|
+
const link = await liveLink(workspaceId);
|
|
756
|
+
return (await containerJson(link, `/api/workspaces/${encodeURIComponent(workspaceId)}/history`)).sessions ?? [];
|
|
757
|
+
},
|
|
758
|
+
async sessionHistory(sessionId) {
|
|
759
|
+
const link = ownedLink(sessionId);
|
|
760
|
+
return (await containerJson(link, sessionPath(link, sessionId, "/history"))).sessions ?? [];
|
|
761
|
+
},
|
|
762
|
+
async readTranscript(sessionId, request) {
|
|
763
|
+
const link = ownedLink(sessionId);
|
|
764
|
+
return await containerJson(link, sessionPath(link, sessionId, `/transcript${transcriptPageQuery(request)}`));
|
|
765
|
+
},
|
|
766
|
+
async requestSessionApi(scope, request) {
|
|
767
|
+
const mirror = mirrors.get(scope.sessionId);
|
|
768
|
+
if (mirror === void 0) return Response.json({ error: "Session not found." }, { status: 404 });
|
|
769
|
+
if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(request.basePath)) return Response.json({ error: "Invalid session API base path." }, { status: 400 });
|
|
770
|
+
if (!request.path.startsWith("/") || request.path.startsWith("//") || request.path.includes("#")) return Response.json({ error: "Invalid session API path." }, { status: 400 });
|
|
771
|
+
const headers = new Headers(request.headers);
|
|
772
|
+
for (const name of [
|
|
773
|
+
"host",
|
|
774
|
+
"authorization",
|
|
775
|
+
TOKEN_HEADER,
|
|
776
|
+
"content-length"
|
|
777
|
+
]) headers.delete(name);
|
|
778
|
+
try {
|
|
779
|
+
return await containerFetch(mirror.link, sessionPath(mirror.link, scope.sessionId, `/plugins/${request.basePath}${request.path}`), {
|
|
780
|
+
method: request.method,
|
|
781
|
+
headers,
|
|
782
|
+
...request.body === void 0 || request.body === null ? {} : { body: request.body },
|
|
783
|
+
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
784
|
+
});
|
|
785
|
+
} catch (error) {
|
|
786
|
+
return Response.json({ error: message(error) }, { status: 503 });
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
async dispose() {
|
|
790
|
+
disposed = true;
|
|
791
|
+
for (const mirror of mirrors.values()) {
|
|
792
|
+
mirrors.delete(mirror.sessionId);
|
|
793
|
+
mirror.dispose();
|
|
794
|
+
}
|
|
795
|
+
for (const link of links.values()) {
|
|
796
|
+
link.disposed = true;
|
|
797
|
+
if (link.reconnect !== void 0) clearTimeout(link.reconnect);
|
|
798
|
+
link.gateway?.abort.abort(/* @__PURE__ */ new Error("The host is shutting down."));
|
|
799
|
+
for (const stop of link.stops.splice(0)) stop();
|
|
800
|
+
link.hub?.release();
|
|
801
|
+
link.client.dispose();
|
|
802
|
+
}
|
|
803
|
+
links.clear();
|
|
804
|
+
mirrorWaiters.clear();
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
//#endregion
|
|
809
|
+
export { FORWARDED_SESSION_METHODS, SANDBOX_UNREACHABLE, createSandboxRouter };
|
|
810
|
+
|
|
811
|
+
//# sourceMappingURL=sandboxRouter.mjs.map
|