@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,887 @@
|
|
|
1
|
+
const require_networkGateway = require("./networkGateway.cjs");
|
|
2
|
+
const require_networkRelay = require("./networkRelay.cjs");
|
|
3
|
+
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
4
|
+
let node_crypto = require("node:crypto");
|
|
5
|
+
let _agimon_ai_po_web_security = require("@agimon-ai/po-web-security");
|
|
6
|
+
let _agimon_ai_po_session = require("@agimon-ai/po-session");
|
|
7
|
+
let _agimon_ai_po_network = require("@agimon-ai/po-network");
|
|
8
|
+
let _agimon_ai_po_web_security_deviceProof = require("@agimon-ai/po-web-security/deviceProof");
|
|
9
|
+
//#region src/builders/server/network.ts
|
|
10
|
+
function object(value) {
|
|
11
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function proposal(value) {
|
|
14
|
+
return object(value) && ["network", "candidate"].every((key) => typeof value[key] === "string") && [
|
|
15
|
+
"epoch",
|
|
16
|
+
"term",
|
|
17
|
+
"priority",
|
|
18
|
+
"issuedAt",
|
|
19
|
+
"expiresAt"
|
|
20
|
+
].every((key) => Number.isSafeInteger(value[key]));
|
|
21
|
+
}
|
|
22
|
+
function lease(value) {
|
|
23
|
+
return proposal(value) && "votes" in value && Array.isArray(value.votes) && value.votes.every((vote) => proposal(vote) && "voter" in vote && typeof vote.voter === "string" && "signature" in vote && typeof vote.signature === "string");
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Reported once by polling when no C9 voter set is committed: the host keeps syncing the roster without a
|
|
27
|
+
* vote. Not a sync failure, so callers word it apart from one.
|
|
28
|
+
*/
|
|
29
|
+
var NonVotingNotice = class extends Error {
|
|
30
|
+
constructor() {
|
|
31
|
+
super("Trusted C9 genesis unavailable; remaining non-voting");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/** One instance per network. C6 publication and C9 fencing have separate durable boundaries. */
|
|
35
|
+
async function createNodeNetwork(ports) {
|
|
36
|
+
const database = await ports.sqlite.open(ports.databaseFile, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT);
|
|
37
|
+
await database.exec("CREATE TABLE IF NOT EXISTS po_network_roster (network TEXT PRIMARY KEY, state_json TEXT NOT NULL)");
|
|
38
|
+
await database.exec("CREATE TABLE IF NOT EXISTS po_network_lease (network TEXT PRIMARY KEY, lease_json TEXT NOT NULL)");
|
|
39
|
+
await database.exec("CREATE TABLE IF NOT EXISTS po_network_nonce (host TEXT NOT NULL, nonce TEXT NOT NULL, expires_at INTEGER NOT NULL, PRIMARY KEY(host, nonce))");
|
|
40
|
+
await database.exec("CREATE TABLE IF NOT EXISTS po_network_genesis (network TEXT PRIMARY KEY, envelope_json TEXT NOT NULL)");
|
|
41
|
+
const saved = await database.get("SELECT state_json FROM po_network_roster WHERE network = ?", ports.networkId);
|
|
42
|
+
let roster = saved ? JSON.parse(saved.state_json) : (0, _agimon_ai_po_network.initialRosterState)(ports.networkId);
|
|
43
|
+
let unlinked = false;
|
|
44
|
+
const fresh = () => !unlinked && (0, _agimon_ai_po_network.rosterAuthorityFresh)(roster.syncedAt, ports.now());
|
|
45
|
+
const authorityRoster = () => fresh() ? roster : {
|
|
46
|
+
...roster,
|
|
47
|
+
hosts: [],
|
|
48
|
+
members: []
|
|
49
|
+
};
|
|
50
|
+
const genesisRow = await database.get("SELECT envelope_json FROM po_network_genesis WHERE network = ?", ports.networkId);
|
|
51
|
+
let genesisEnvelope = genesisRow ? JSON.parse(genesisRow.envelope_json) : void 0;
|
|
52
|
+
const directory = await (0, _agimon_ai_po_network.createCapabilityDirectory)(database);
|
|
53
|
+
let ownManifest;
|
|
54
|
+
let composition = "";
|
|
55
|
+
let observedRevision;
|
|
56
|
+
let lastManifestCheck = -Infinity;
|
|
57
|
+
let publishedTo = "";
|
|
58
|
+
const manifests = /* @__PURE__ */ new Map();
|
|
59
|
+
const manifestKeys = /* @__PURE__ */ new Map();
|
|
60
|
+
const knownHosts = new Map(roster.hosts.map((host) => [host.hostId, host]));
|
|
61
|
+
async function remember(envelope) {
|
|
62
|
+
const payload = await (0, _agimon_ai_po_network.verifyCapabilityManifest)(envelope, roster, ports.now());
|
|
63
|
+
if (!fresh() || !payload) return false;
|
|
64
|
+
const previous = manifests.get(payload.hostId);
|
|
65
|
+
if (!previous || previous.issuedAt <= payload.issuedAt) {
|
|
66
|
+
manifests.set(payload.hostId, payload);
|
|
67
|
+
manifestKeys.set(payload.hostId, roster.hosts.find((host) => host.hostId === payload.hostId).publicKey);
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
async function remote(hostId, operation, input) {
|
|
72
|
+
if (!fresh()) return void 0;
|
|
73
|
+
const origin = roster.hosts.find((entry) => entry.hostId === hostId)?.endpoints.find((endpoint) => endpoint.startsWith("https:"));
|
|
74
|
+
if (!origin || !ports.fetch || !ports.signHost) return void 0;
|
|
75
|
+
const method = operation === "capabilities" ? "GET" : "POST";
|
|
76
|
+
const path = `/api/networks/${encodeURIComponent(ports.networkId)}/network/${operation}`;
|
|
77
|
+
const body = method === "GET" ? void 0 : JSON.stringify(input);
|
|
78
|
+
const issuedAt = ports.now();
|
|
79
|
+
const payload = {
|
|
80
|
+
networkId: ports.networkId,
|
|
81
|
+
hostId: ports.hostId,
|
|
82
|
+
destination: hostId,
|
|
83
|
+
method,
|
|
84
|
+
path,
|
|
85
|
+
bodyHash: (0, _agimon_ai_po_web_security_deviceProof.federationDigest)(body ?? ""),
|
|
86
|
+
nonce: crypto.randomUUID(),
|
|
87
|
+
issuedAt,
|
|
88
|
+
expiresAt: issuedAt + 6e4
|
|
89
|
+
};
|
|
90
|
+
const proof = {
|
|
91
|
+
tag: "po/host-request/v1",
|
|
92
|
+
payload,
|
|
93
|
+
signature: ports.signHost((0, _agimon_ai_po_web_security.federationEnvelopeFields)(payload))
|
|
94
|
+
};
|
|
95
|
+
try {
|
|
96
|
+
const response = await ports.fetch(new URL(path, origin), {
|
|
97
|
+
method,
|
|
98
|
+
body,
|
|
99
|
+
redirect: "manual",
|
|
100
|
+
signal: AbortSignal.timeout(5e3),
|
|
101
|
+
headers: { "x-po-host-proof": JSON.stringify(proof) }
|
|
102
|
+
});
|
|
103
|
+
return response.ok ? response.json() : void 0;
|
|
104
|
+
} catch {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
let refreshing;
|
|
109
|
+
function refreshCapabilities() {
|
|
110
|
+
return refreshing ??= refreshCapabilityState().finally(() => {
|
|
111
|
+
refreshing = void 0;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async function refreshCapabilityState() {
|
|
115
|
+
if (!ports.capabilities || !ports.signCapabilities) return;
|
|
116
|
+
if (!ownManifest || observedRevision !== ports.capabilityRevision?.() || ports.now() - lastManifestCheck >= 6e5) {
|
|
117
|
+
const loaded = await ports.capabilities();
|
|
118
|
+
const fingerprint = JSON.stringify(loaded);
|
|
119
|
+
if (!ownManifest || fingerprint !== composition || ownManifest.payload.expiresAt - ports.now() < 36e5) {
|
|
120
|
+
ownManifest = ports.signCapabilities((0, _agimon_ai_po_network.createCapabilityManifest)({
|
|
121
|
+
...loaded,
|
|
122
|
+
hostId: ports.hostId,
|
|
123
|
+
networkId: ports.networkId,
|
|
124
|
+
now: ports.now()
|
|
125
|
+
}));
|
|
126
|
+
composition = fingerprint;
|
|
127
|
+
publishedTo = "";
|
|
128
|
+
}
|
|
129
|
+
observedRevision = ports.capabilityRevision?.();
|
|
130
|
+
lastManifestCheck = ports.now();
|
|
131
|
+
}
|
|
132
|
+
if (!ownManifest) return;
|
|
133
|
+
await remember(ownManifest);
|
|
134
|
+
const elected = await coordinator();
|
|
135
|
+
if (!elected) return;
|
|
136
|
+
const destination = `${elected.candidate}:${elected.term}:${ownManifest.payload.issuedAt}`;
|
|
137
|
+
if (destination !== publishedTo) {
|
|
138
|
+
if (elected.candidate === ports.hostId ? await directory.publish(ownManifest, roster, ports.now()) : await remote(elected.candidate, "directory.publish", ownManifest)) publishedTo = destination;
|
|
139
|
+
}
|
|
140
|
+
const entries = elected.candidate === ports.hostId ? await directory.read(roster, ports.now()) : await remote(elected.candidate, "directory.read", { networkId: ports.networkId });
|
|
141
|
+
if (Array.isArray(entries)) for (const envelope of entries) await remember(envelope);
|
|
142
|
+
}
|
|
143
|
+
let queue = Promise.resolve();
|
|
144
|
+
function serial(work) {
|
|
145
|
+
const result = queue.then(work);
|
|
146
|
+
queue = result.catch(() => void 0);
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
let votingReady = !genesisRow;
|
|
150
|
+
const storage = await (0, _agimon_ai_po_network.createSqliteElectionStorage)(database, (network) => {
|
|
151
|
+
const seed = genesisEnvelope?.payload;
|
|
152
|
+
const committed = seed && (0, _agimon_ai_po_network.genesisVoters)(seed);
|
|
153
|
+
if (network !== ports.networkId || !seed || !committed) throw new Error("Trusted C9 genesis unavailable");
|
|
154
|
+
votingReady = committed.length === 1 && committed[0] === ports.hostId;
|
|
155
|
+
return (0, _agimon_ai_po_network.initialState)({
|
|
156
|
+
network,
|
|
157
|
+
epoch: seed.epoch,
|
|
158
|
+
owner: seed.members.find((member) => member.role === "owner")?.principal.subject ?? "",
|
|
159
|
+
voters: committed
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
const electionState = () => storage.transact(ports.networkId, (state) => ({
|
|
163
|
+
state,
|
|
164
|
+
result: structuredClone(state)
|
|
165
|
+
}));
|
|
166
|
+
const voters = async () => {
|
|
167
|
+
try {
|
|
168
|
+
const committed = (0, _agimon_ai_po_network.committedVoters)(await electionState());
|
|
169
|
+
if (committed.length === 1 && committed[0] === ports.hostId) votingReady = true;
|
|
170
|
+
return committed;
|
|
171
|
+
} catch {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const configuration = (0, _agimon_ai_po_network.createConfigurationService)({
|
|
176
|
+
network: ports.networkId,
|
|
177
|
+
hostId: ports.hostId,
|
|
178
|
+
storage,
|
|
179
|
+
timing: ports.timing,
|
|
180
|
+
now: () => ports.now(),
|
|
181
|
+
trustedKey: (hostId) => {
|
|
182
|
+
const key = fresh() ? roster.hosts.find((host) => host.hostId === hostId)?.publicKey : void 0;
|
|
183
|
+
try {
|
|
184
|
+
return key ? (0, node_crypto.createPublicKey)({
|
|
185
|
+
key: Buffer.from(key, "base64url"),
|
|
186
|
+
format: "der",
|
|
187
|
+
type: "spki"
|
|
188
|
+
}).export({ format: "jwk" }) : null;
|
|
189
|
+
} catch {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
sign: async (tag, fields) => {
|
|
194
|
+
if (!ports.signConfiguration || tag !== "po/roster-promise/v1" && tag !== "po/roster-vote/v1") throw new Error("Configuration signer unavailable");
|
|
195
|
+
return ports.signConfiguration(tag, fields);
|
|
196
|
+
},
|
|
197
|
+
verify: async (key, _tag, bytes, signature) => {
|
|
198
|
+
try {
|
|
199
|
+
return (0, node_crypto.verify)("sha256", bytes, {
|
|
200
|
+
key: (0, node_crypto.createPublicKey)({
|
|
201
|
+
key,
|
|
202
|
+
format: "jwk"
|
|
203
|
+
}),
|
|
204
|
+
dsaEncoding: "ieee-p1363"
|
|
205
|
+
}, Buffer.from(signature, "base64url"));
|
|
206
|
+
} catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
verifyOwner: (change, authorization) => ports.verifyOwner?.(change, authorization) ?? Promise.resolve(false),
|
|
211
|
+
send: (hostId, operation, input) => hostId === ports.hostId ? handlers(true)(operation, input) : remote(hostId, operation, input),
|
|
212
|
+
activated: async () => {
|
|
213
|
+
await database.run("DELETE FROM po_network_lease WHERE network = ?", ports.networkId);
|
|
214
|
+
relay?.close();
|
|
215
|
+
relay = void 0;
|
|
216
|
+
relayHost = void 0;
|
|
217
|
+
retryAt = 0;
|
|
218
|
+
await gateway.refresh();
|
|
219
|
+
publishedTo = "";
|
|
220
|
+
if (ports.campaign?.() !== false) await elect();
|
|
221
|
+
await maintainRelay();
|
|
222
|
+
await refreshCapabilities();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
const verifyVote = (vote) => {
|
|
226
|
+
const key = roster.hosts.find((host) => host.hostId === vote.voter)?.publicKey;
|
|
227
|
+
return !!key && (0, _agimon_ai_po_web_security_deviceProof.verifyDeviceSignature)(key, _agimon_ai_po_network.VOTE_TAG, (0, _agimon_ai_po_network.voteFields)(vote).map(String), vote.signature);
|
|
228
|
+
};
|
|
229
|
+
async function vote(input) {
|
|
230
|
+
if (!fresh() || !(await voters()).includes(ports.hostId) || !votingReady || !roster.hosts.some((host) => host.hostId === ports.hostId)) return null;
|
|
231
|
+
if (!roster.hosts.some((host) => host.hostId === input.candidate)) return null;
|
|
232
|
+
const granted = await storage.transact(ports.networkId, (state) => (0, _agimon_ai_po_network.grantVote)(state, ports.hostId, input, ports.now(), ports.timing));
|
|
233
|
+
return granted ? {
|
|
234
|
+
...granted,
|
|
235
|
+
signature: ports.signVote((0, _agimon_ai_po_network.voteFields)(granted))
|
|
236
|
+
} : null;
|
|
237
|
+
}
|
|
238
|
+
async function acceptLease(input) {
|
|
239
|
+
if (!fresh()) return false;
|
|
240
|
+
const admitted = await storage.mutate(ports.networkId, input, ports.now(), ports.timing, verifyVote, async (transaction) => {
|
|
241
|
+
await transaction.run("INSERT OR REPLACE INTO po_network_lease VALUES (?, ?)", ports.networkId, JSON.stringify(input));
|
|
242
|
+
});
|
|
243
|
+
if (admitted) {
|
|
244
|
+
await maintainRelay();
|
|
245
|
+
await gateway.refresh();
|
|
246
|
+
publishedTo = "";
|
|
247
|
+
await refreshCapabilities();
|
|
248
|
+
}
|
|
249
|
+
return admitted;
|
|
250
|
+
}
|
|
251
|
+
async function coordinator() {
|
|
252
|
+
if (!fresh()) return void 0;
|
|
253
|
+
const row = await database.get("SELECT lease_json FROM po_network_lease WHERE network = ?", ports.networkId);
|
|
254
|
+
if (!row || !(await voters()).length) return void 0;
|
|
255
|
+
const current = JSON.parse(row.lease_json);
|
|
256
|
+
return storage.transact(ports.networkId, (state) => ({
|
|
257
|
+
state,
|
|
258
|
+
result: (0, _agimon_ai_po_network.validLease)(state, current, ports.now(), ports.timing, verifyVote) ? current : void 0
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
async function elect() {
|
|
262
|
+
if (!fresh()) return void 0;
|
|
263
|
+
const committed = await voters();
|
|
264
|
+
if (!votingReady || !committed.includes(ports.hostId) || !roster.hosts.some((host) => host.hostId === ports.hostId)) return void 0;
|
|
265
|
+
const now = ports.now();
|
|
266
|
+
const current = await coordinator();
|
|
267
|
+
if (current) return current;
|
|
268
|
+
const input = await storage.transact(ports.networkId, (state) => ({
|
|
269
|
+
state,
|
|
270
|
+
result: {
|
|
271
|
+
network: ports.networkId,
|
|
272
|
+
epoch: (0, _agimon_ai_po_network.committedEpoch)(state),
|
|
273
|
+
term: state.term + 1,
|
|
274
|
+
candidate: ports.hostId,
|
|
275
|
+
priority: 0,
|
|
276
|
+
issuedAt: now,
|
|
277
|
+
expiresAt: now + ports.timing.maxLeaseMs
|
|
278
|
+
}
|
|
279
|
+
}));
|
|
280
|
+
const votes = [];
|
|
281
|
+
for (const host of roster.hosts.filter((entry) => committed.includes(entry.hostId))) try {
|
|
282
|
+
const answer = host.hostId === ports.hostId ? await vote(input) : await ports.requestVote?.(host.hostId, input);
|
|
283
|
+
if (answer) votes.push(answer);
|
|
284
|
+
} catch {}
|
|
285
|
+
const certificate = {
|
|
286
|
+
...input,
|
|
287
|
+
votes
|
|
288
|
+
};
|
|
289
|
+
return await acceptLease(certificate) ? certificate : void 0;
|
|
290
|
+
}
|
|
291
|
+
async function rememberGenesis(envelope) {
|
|
292
|
+
await database.run("INSERT OR IGNORE INTO po_network_genesis VALUES (?, ?)", ports.networkId, JSON.stringify(envelope));
|
|
293
|
+
genesisEnvelope = structuredClone(envelope);
|
|
294
|
+
votingReady = false;
|
|
295
|
+
}
|
|
296
|
+
async function discoverGenesis() {
|
|
297
|
+
if (genesisEnvelope || await database.get("SELECT network FROM po_network_voter WHERE network = ?", ports.networkId)) return;
|
|
298
|
+
for (const host of roster.hosts) {
|
|
299
|
+
if (host.hostId === ports.hostId) continue;
|
|
300
|
+
try {
|
|
301
|
+
const envelope = await remote(host.hostId, "configuration.genesis", { network: ports.networkId });
|
|
302
|
+
if (!object(envelope) || !object(envelope.payload) || envelope.payload.networkId !== ports.networkId || typeof envelope.payload.expiresAt !== "number") continue;
|
|
303
|
+
const signed = envelope;
|
|
304
|
+
if (!(0, _agimon_ai_po_web_security_deviceProof.verifyEnvelope)(ports.trust.issuerPublicKey, "po/roster/v1", signed, Math.min(ports.now(), signed.payload.expiresAt - 3e4))) continue;
|
|
305
|
+
if (!(0, _agimon_ai_po_network.genesisVoters)(signed.payload)) continue;
|
|
306
|
+
await rememberGenesis(signed);
|
|
307
|
+
return;
|
|
308
|
+
} catch {}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function catchUp() {
|
|
312
|
+
await discoverGenesis();
|
|
313
|
+
try {
|
|
314
|
+
const committed = await voters();
|
|
315
|
+
for (const id of committed) {
|
|
316
|
+
if (id === ports.hostId) continue;
|
|
317
|
+
try {
|
|
318
|
+
if (await configuration.catchUp(id)) {
|
|
319
|
+
votingReady = true;
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
} catch {}
|
|
323
|
+
}
|
|
324
|
+
} catch {}
|
|
325
|
+
}
|
|
326
|
+
async function apply(envelope) {
|
|
327
|
+
if (envelope?.payload?.deletedAt !== void 0 && envelope.payload.networkId === ports.networkId && envelope.payload.epoch > roster.epoch && Number.isSafeInteger(envelope.payload.deletedAt) && !envelope.payload.members.length && !envelope.payload.hosts.length && (0, _agimon_ai_po_web_security_deviceProof.verifyEnvelope)(ports.trust.issuerPublicKey, "po/roster/v1", envelope, ports.now())) {
|
|
328
|
+
await unlinkNetwork();
|
|
329
|
+
await ports.unlink?.("org-deleted");
|
|
330
|
+
return roster;
|
|
331
|
+
}
|
|
332
|
+
return serial(async () => {
|
|
333
|
+
if (unlinked) throw new Error("Network unlinked");
|
|
334
|
+
const applied = (0, _agimon_ai_po_network.applyRoster)(roster, envelope, ports.trust, ports.now());
|
|
335
|
+
const next = applied && {
|
|
336
|
+
...applied,
|
|
337
|
+
voterChange: roster.voterChange,
|
|
338
|
+
syncedAt: ports.now(),
|
|
339
|
+
snapshot: envelope.payload
|
|
340
|
+
};
|
|
341
|
+
if (!next) throw new Error("Roster refused");
|
|
342
|
+
if ((await voters()).some((id) => !next.hosts.some((host) => host.hostId === id))) next.voterChange = "pending-quorum";
|
|
343
|
+
await database.run("INSERT OR REPLACE INTO po_network_roster VALUES (?, ?)", ports.networkId, JSON.stringify(next));
|
|
344
|
+
roster = next;
|
|
345
|
+
for (const host of roster.hosts) knownHosts.set(host.hostId, host);
|
|
346
|
+
if (!genesisEnvelope && (0, _agimon_ai_po_network.genesisVoters)(envelope.payload)) {
|
|
347
|
+
if (!await database.get("SELECT network FROM po_network_voter WHERE network = ?", ports.networkId)) await rememberGenesis(envelope);
|
|
348
|
+
}
|
|
349
|
+
await gateway.refresh();
|
|
350
|
+
for (const hostId of channels.keys()) if (!roster.hosts.some((host) => host.hostId === hostId && !next.rekeyedHostIds.includes(hostId))) channels.delete(hostId);
|
|
351
|
+
await maintainRelay();
|
|
352
|
+
await catchUp();
|
|
353
|
+
if (ports.campaign?.() !== false && (await voters()).includes(ports.hostId)) await elect();
|
|
354
|
+
return roster;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
const channels = /* @__PURE__ */ new Map();
|
|
358
|
+
const peer = (0, _agimon_ai_po_session.createRosterPeerLink)({
|
|
359
|
+
...ports.peer,
|
|
360
|
+
hostId: ports.hostId,
|
|
361
|
+
now: () => ports.now(),
|
|
362
|
+
roster: () => ({
|
|
363
|
+
networkId: roster.networkId,
|
|
364
|
+
epoch: roster.epoch,
|
|
365
|
+
hosts: authorityRoster().hosts
|
|
366
|
+
})
|
|
367
|
+
});
|
|
368
|
+
const network = {
|
|
369
|
+
async connect(hostId, token, exchange) {
|
|
370
|
+
const channel = await peer.connect(hostId, token, exchange);
|
|
371
|
+
channels.set(hostId, channel);
|
|
372
|
+
return channel;
|
|
373
|
+
},
|
|
374
|
+
async accept(proof, token) {
|
|
375
|
+
const accepted = await peer.accept(proof, token);
|
|
376
|
+
channels.set(proof.payload.hostId, accepted.channel);
|
|
377
|
+
return accepted;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
let relay;
|
|
381
|
+
let relayHost;
|
|
382
|
+
let relayKey;
|
|
383
|
+
let attempts = 0;
|
|
384
|
+
let retryAt = 0;
|
|
385
|
+
let candidateIndex = 0;
|
|
386
|
+
async function maintainRelay() {
|
|
387
|
+
const elected = roster.epoch ? await coordinator() : void 0;
|
|
388
|
+
const self = authorityRoster().hosts.find((host) => host.hostId === ports.hostId);
|
|
389
|
+
const committed = roster.epoch ? await voters() : [];
|
|
390
|
+
const candidates = roster.hosts.filter((host) => committed.includes(host.hostId) && host.hostId !== ports.hostId && host.endpoints.some((endpoint) => endpoint.startsWith("https:")));
|
|
391
|
+
if (!ports.relay || !self || ports.relay.publicOrigin() || !candidates.length) {
|
|
392
|
+
relay?.close();
|
|
393
|
+
relay = void 0;
|
|
394
|
+
relayHost = void 0;
|
|
395
|
+
attempts = 0;
|
|
396
|
+
retryAt = 0;
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (relay?.alive() && candidates.some((host) => host.hostId === relayHost && host.publicKey === relayKey)) {
|
|
400
|
+
if (relay.admitted()) {
|
|
401
|
+
attempts = 0;
|
|
402
|
+
retryAt = 0;
|
|
403
|
+
}
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
relay?.close();
|
|
407
|
+
if (ports.now() < retryAt) return;
|
|
408
|
+
const candidate = (attempts === 0 ? candidates.find((host) => host.hostId === elected?.candidate) : void 0) ?? candidates[candidateIndex % candidates.length];
|
|
409
|
+
candidateIndex = (candidates.indexOf(candidate) + 1) % candidates.length;
|
|
410
|
+
relayHost = candidate.hostId;
|
|
411
|
+
relayKey = candidate.publicKey;
|
|
412
|
+
const backoff = 1e3 * 2 ** Math.min(attempts++, 9);
|
|
413
|
+
retryAt = ports.now() + Math.min(3e5, Math.max(1e3, Math.round(backoff * (.75 + Math.random() * .5))));
|
|
414
|
+
const origin = candidate.endpoints.find((endpoint) => endpoint.startsWith("https:"));
|
|
415
|
+
const url = new URL(`/api/networks/${encodeURIComponent(ports.networkId)}/relay`, origin);
|
|
416
|
+
url.protocol = "wss:";
|
|
417
|
+
const gatewayKey = candidate.publicKey;
|
|
418
|
+
relay = require_networkRelay.connectNetworkRelay({
|
|
419
|
+
...ports.relay,
|
|
420
|
+
url: url.toString(),
|
|
421
|
+
networkId: ports.networkId,
|
|
422
|
+
hostId: ports.hostId,
|
|
423
|
+
gatewayHostId: candidate.hostId,
|
|
424
|
+
now: () => ports.now(),
|
|
425
|
+
acceptLease: async (value) => lease(value) && acceptLease(value),
|
|
426
|
+
current: () => fresh() && roster.hosts.some((host) => host.hostId === ports.hostId) && committed.includes(candidate.hostId) && roster.hosts.some((host) => host.hostId === candidate.hostId && host.publicKey === gatewayKey),
|
|
427
|
+
channel: () => ({
|
|
428
|
+
seal: () => {
|
|
429
|
+
throw new Error("A destination channel is required");
|
|
430
|
+
},
|
|
431
|
+
async open(envelope) {
|
|
432
|
+
for (const channel of channels.values()) {
|
|
433
|
+
const plaintext = await channel.open(envelope);
|
|
434
|
+
if (plaintext) return plaintext;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
const gateway = require_networkGateway.createNetworkGateway({
|
|
441
|
+
networkId: ports.networkId,
|
|
442
|
+
hostId: ports.hostId,
|
|
443
|
+
now: () => ports.now(),
|
|
444
|
+
roster: authorityRoster,
|
|
445
|
+
coordinator
|
|
446
|
+
});
|
|
447
|
+
function handlers(authorized) {
|
|
448
|
+
const authorize = async () => authorized && fresh();
|
|
449
|
+
return (0, _agimon_ai_po_network.createNetworkRouter)({
|
|
450
|
+
"directory.publish": {
|
|
451
|
+
validate: (value) => object(value) && value.tag === "po/capabilities/v1",
|
|
452
|
+
authorize,
|
|
453
|
+
handle: (value) => directory.publish(value, roster, ports.now())
|
|
454
|
+
},
|
|
455
|
+
"directory.read": {
|
|
456
|
+
validate: (value) => object(value) && value.networkId === ports.networkId,
|
|
457
|
+
authorize,
|
|
458
|
+
handle: () => directory.read(roster, ports.now())
|
|
459
|
+
},
|
|
460
|
+
"roster.read": {
|
|
461
|
+
validate: (value) => object(value) && value.networkId === ports.networkId,
|
|
462
|
+
authorize,
|
|
463
|
+
handle: async () => roster
|
|
464
|
+
},
|
|
465
|
+
"roster.apply": {
|
|
466
|
+
validate: (value) => object(value) && value.tag === "po/roster/v1" && object(value.payload) && value.payload.networkId === ports.networkId,
|
|
467
|
+
authorize,
|
|
468
|
+
handle: apply
|
|
469
|
+
},
|
|
470
|
+
"configuration.genesis": {
|
|
471
|
+
validate: _agimon_ai_po_network.configurationValidators["configuration.genesis"],
|
|
472
|
+
authorize,
|
|
473
|
+
handle: async (input) => input.network === ports.networkId ? genesisEnvelope ?? null : null
|
|
474
|
+
},
|
|
475
|
+
"configuration.promise": {
|
|
476
|
+
validate: _agimon_ai_po_network.configurationValidators["configuration.promise"],
|
|
477
|
+
authorize,
|
|
478
|
+
handle: async (input) => (await voters()).includes(ports.hostId) && votingReady && roster.hosts.some((host) => host.hostId === ports.hostId) ? configuration.promise(input) : null
|
|
479
|
+
},
|
|
480
|
+
"configuration.accept": {
|
|
481
|
+
validate: _agimon_ai_po_network.configurationValidators["configuration.accept"],
|
|
482
|
+
authorize,
|
|
483
|
+
handle: async (input) => (await voters()).includes(ports.hostId) && votingReady && roster.hosts.some((host) => host.hostId === ports.hostId) ? configuration.accept(input) : null
|
|
484
|
+
},
|
|
485
|
+
"configuration.activate": {
|
|
486
|
+
validate: _agimon_ai_po_network.configurationValidators["configuration.activate"],
|
|
487
|
+
authorize,
|
|
488
|
+
handle: (input) => configuration.activate(input)
|
|
489
|
+
},
|
|
490
|
+
"configuration.history": {
|
|
491
|
+
validate: _agimon_ai_po_network.configurationValidators["configuration.history"],
|
|
492
|
+
authorize,
|
|
493
|
+
handle: (input) => configuration.history(input)
|
|
494
|
+
},
|
|
495
|
+
"coordinator.vote": {
|
|
496
|
+
validate: proposal,
|
|
497
|
+
authorize,
|
|
498
|
+
handle: vote
|
|
499
|
+
},
|
|
500
|
+
"coordinator.lease": {
|
|
501
|
+
validate: lease,
|
|
502
|
+
authorize,
|
|
503
|
+
handle: acceptLease
|
|
504
|
+
},
|
|
505
|
+
"coordinator.mutate": {
|
|
506
|
+
validate: (value) => object(value) && lease(value.lease) && typeof value.operation === "string" && ports.mutations.has(value.operation) && ports.mutations.get(value.operation).validate(value.input),
|
|
507
|
+
authorize,
|
|
508
|
+
handle: async (input) => storage.mutate(ports.networkId, input.lease, ports.now(), ports.timing, verifyVote, (transaction) => ports.mutations.get(input.operation).apply(transaction, input.input))
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
async function admitNonce(hostId, nonce, expiresAt) {
|
|
513
|
+
return database.transaction(async (transaction) => {
|
|
514
|
+
await transaction.run("DELETE FROM po_network_nonce WHERE expires_at < ?", ports.now());
|
|
515
|
+
return !!await transaction.get("INSERT INTO po_network_nonce VALUES (?, ?, ?) ON CONFLICT DO NOTHING RETURNING nonce", hostId, nonce, expiresAt);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
async function authorizeHostOperation(request, operation) {
|
|
519
|
+
if (!fresh()) return false;
|
|
520
|
+
if (![
|
|
521
|
+
"roster.read",
|
|
522
|
+
"configuration.genesis",
|
|
523
|
+
"configuration.promise",
|
|
524
|
+
"configuration.accept",
|
|
525
|
+
"configuration.activate",
|
|
526
|
+
"configuration.history",
|
|
527
|
+
"coordinator.vote",
|
|
528
|
+
"coordinator.lease",
|
|
529
|
+
"directory.publish",
|
|
530
|
+
"directory.read",
|
|
531
|
+
"capabilities"
|
|
532
|
+
].includes(operation)) return false;
|
|
533
|
+
try {
|
|
534
|
+
const envelope = JSON.parse(request.headers.get("x-po-host-proof") ?? "null");
|
|
535
|
+
const host = roster.hosts.find((entry) => entry.hostId === envelope?.payload?.hostId);
|
|
536
|
+
if (!host || [
|
|
537
|
+
"coordinator.vote",
|
|
538
|
+
"coordinator.lease",
|
|
539
|
+
"configuration.promise",
|
|
540
|
+
"configuration.accept",
|
|
541
|
+
"configuration.activate"
|
|
542
|
+
].includes(operation) && !(await voters()).includes(host.hostId)) return false;
|
|
543
|
+
if (!(0, _agimon_ai_po_network.verifyHostProof)(host.publicKey, envelope, {
|
|
544
|
+
networkId: ports.networkId,
|
|
545
|
+
hostId: host.hostId,
|
|
546
|
+
destination: ports.hostId,
|
|
547
|
+
method: request.method,
|
|
548
|
+
path: new URL(request.url).pathname,
|
|
549
|
+
bodyHash: (0, _agimon_ai_po_web_security_deviceProof.federationDigest)(await request.text())
|
|
550
|
+
}, ports.now())) return false;
|
|
551
|
+
return admitNonce(host.hostId, envelope.payload.nonce, envelope.payload.expiresAt);
|
|
552
|
+
} catch {
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const maxHostBodyBytes = 8388608;
|
|
557
|
+
function gatewayTarget(method, path) {
|
|
558
|
+
return method === "GET" && path === "/api/plugins/gateway/catalog" || method === "POST" && path === "/api/plugins/gateway/calls" || method === "POST" && path === "/api/plugins/session-peer/control";
|
|
559
|
+
}
|
|
560
|
+
function sameOwnerHost(hostId) {
|
|
561
|
+
if (!fresh()) return void 0;
|
|
562
|
+
const self = roster.hosts.find((host) => host.hostId === ports.hostId);
|
|
563
|
+
const host = roster.hosts.find((host) => host.hostId === hostId);
|
|
564
|
+
return self && host && self.owner.issuer === host.owner.issuer && self.owner.subject === host.owner.subject ? host : void 0;
|
|
565
|
+
}
|
|
566
|
+
async function boundedHostBody(request) {
|
|
567
|
+
const reader = request.clone().body?.getReader();
|
|
568
|
+
if (!reader) return "";
|
|
569
|
+
const chunks = [];
|
|
570
|
+
let size = 0;
|
|
571
|
+
try {
|
|
572
|
+
for (;;) {
|
|
573
|
+
const chunk = await reader.read();
|
|
574
|
+
if (chunk.done) break;
|
|
575
|
+
size += chunk.value.byteLength;
|
|
576
|
+
if (size > maxHostBodyBytes) {
|
|
577
|
+
reader.cancel();
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
chunks.push(chunk.value);
|
|
581
|
+
}
|
|
582
|
+
const bytes = new Uint8Array(size);
|
|
583
|
+
let offset = 0;
|
|
584
|
+
for (const chunk of chunks) {
|
|
585
|
+
bytes.set(chunk, offset);
|
|
586
|
+
offset += chunk.byteLength;
|
|
587
|
+
}
|
|
588
|
+
return new TextDecoder().decode(bytes);
|
|
589
|
+
} finally {
|
|
590
|
+
reader.releaseLock();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
const hostRequests = {
|
|
594
|
+
hosts: () => roster.hosts.filter((host) => sameOwnerHost(host.hostId) && host.hostId !== ports.hostId).map((host) => ({
|
|
595
|
+
hostId: host.hostId,
|
|
596
|
+
https: host.endpoints.some((endpoint) => endpoint.startsWith("https:"))
|
|
597
|
+
})),
|
|
598
|
+
async fetch(hostId, request) {
|
|
599
|
+
const origin = sameOwnerHost(hostId)?.endpoints.find((endpoint) => endpoint.startsWith("https:"));
|
|
600
|
+
if (!origin || !ports.fetch || !ports.signHost || !gatewayTarget(request.method, request.path) || request.method === "GET" && request.body !== void 0 || new TextEncoder().encode(request.body ?? "").byteLength > maxHostBodyBytes) return void 0;
|
|
601
|
+
const issuedAt = ports.now();
|
|
602
|
+
const payload = {
|
|
603
|
+
networkId: ports.networkId,
|
|
604
|
+
hostId: ports.hostId,
|
|
605
|
+
destination: hostId,
|
|
606
|
+
method: request.method,
|
|
607
|
+
path: request.path,
|
|
608
|
+
bodyHash: (0, _agimon_ai_po_web_security_deviceProof.federationDigest)(request.body ?? ""),
|
|
609
|
+
nonce: crypto.randomUUID(),
|
|
610
|
+
issuedAt,
|
|
611
|
+
expiresAt: issuedAt + 6e4
|
|
612
|
+
};
|
|
613
|
+
try {
|
|
614
|
+
return await ports.fetch(new URL(request.path, origin), {
|
|
615
|
+
method: request.method,
|
|
616
|
+
body: request.body,
|
|
617
|
+
signal: request.signal ?? AbortSignal.timeout(1e4),
|
|
618
|
+
redirect: "manual",
|
|
619
|
+
headers: {
|
|
620
|
+
"content-type": "application/json",
|
|
621
|
+
"x-po-host-proof": JSON.stringify({
|
|
622
|
+
tag: "po/host-request/v1",
|
|
623
|
+
payload,
|
|
624
|
+
signature: ports.signHost((0, _agimon_ai_po_web_security.federationEnvelopeFields)(payload))
|
|
625
|
+
})
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
} catch {
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
async verify(request, pathPrefix) {
|
|
633
|
+
const url = new URL(request.url);
|
|
634
|
+
if (url.pathname.slice(0, url.pathname.lastIndexOf("/")) !== pathPrefix.replace(/\/$/u, "") || url.search || !gatewayTarget(request.method, url.pathname)) return void 0;
|
|
635
|
+
try {
|
|
636
|
+
const envelope = JSON.parse(request.headers.get("x-po-host-proof") ?? "null");
|
|
637
|
+
const host = sameOwnerHost(envelope?.payload?.hostId);
|
|
638
|
+
const p = envelope?.payload;
|
|
639
|
+
if (!host || !p || !Number.isSafeInteger(p.issuedAt) || !Number.isSafeInteger(p.expiresAt) || p.expiresAt <= p.issuedAt || p.expiresAt - p.issuedAt > 6e4) return void 0;
|
|
640
|
+
const body = await boundedHostBody(request);
|
|
641
|
+
if (body === void 0 || sameOwnerHost(host.hostId)?.publicKey !== host.publicKey || !(0, _agimon_ai_po_network.verifyHostProof)(host.publicKey, envelope, {
|
|
642
|
+
networkId: ports.networkId,
|
|
643
|
+
hostId: host.hostId,
|
|
644
|
+
destination: ports.hostId,
|
|
645
|
+
method: request.method,
|
|
646
|
+
path: url.pathname,
|
|
647
|
+
bodyHash: (0, _agimon_ai_po_web_security_deviceProof.federationDigest)(body)
|
|
648
|
+
}, ports.now())) return void 0;
|
|
649
|
+
return await admitNonce(host.hostId, p.nonce, p.expiresAt) ? { hostId: host.hostId } : void 0;
|
|
650
|
+
} catch {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
let timer;
|
|
656
|
+
async function unlinkNetwork() {
|
|
657
|
+
unlinked = true;
|
|
658
|
+
if (timer) clearInterval(timer);
|
|
659
|
+
channels.clear();
|
|
660
|
+
relay?.close();
|
|
661
|
+
gateway.close();
|
|
662
|
+
await queue;
|
|
663
|
+
await database.exec("DELETE FROM po_network_roster; DELETE FROM po_network_lease; DELETE FROM po_network_genesis; DELETE FROM po_network_nonce; DELETE FROM po_network_voter; DELETE FROM po_network_capabilities;");
|
|
664
|
+
roster = (0, _agimon_ai_po_network.initialRosterState)(ports.networkId);
|
|
665
|
+
}
|
|
666
|
+
return {
|
|
667
|
+
network,
|
|
668
|
+
hostRequests,
|
|
669
|
+
async candidates(workspaceId, owner, consents) {
|
|
670
|
+
await refreshCapabilities();
|
|
671
|
+
return (0, _agimon_ai_po_network.consentCandidates)({
|
|
672
|
+
manifests,
|
|
673
|
+
roster: authorityRoster(),
|
|
674
|
+
consents,
|
|
675
|
+
workspaceId,
|
|
676
|
+
owner,
|
|
677
|
+
now: ports.now()
|
|
678
|
+
});
|
|
679
|
+
},
|
|
680
|
+
rosterHostIds: () => authorityRoster().hosts.map((host) => host.hostId),
|
|
681
|
+
roster: () => fresh() ? {
|
|
682
|
+
hosts: roster.hosts.map(({ hostId, owner, enrollmentGeneration }) => ({
|
|
683
|
+
hostId,
|
|
684
|
+
owner,
|
|
685
|
+
enrollmentGeneration
|
|
686
|
+
})),
|
|
687
|
+
expiresAt: roster.syncedAt + _agimon_ai_po_web_security.FEDERATION_FRESHNESS.roster
|
|
688
|
+
} : void 0,
|
|
689
|
+
async manifest(hostId) {
|
|
690
|
+
await refreshCapabilities();
|
|
691
|
+
const value = manifests.get(hostId);
|
|
692
|
+
return fresh() && value && roster.hosts.some((host) => host.hostId === hostId && host.publicKey === manifestKeys.get(hostId)) && ports.now() < value.expiresAt - 3e4 ? value : void 0;
|
|
693
|
+
},
|
|
694
|
+
async providers(workspaceId, owner, consents) {
|
|
695
|
+
await refreshCapabilities();
|
|
696
|
+
for (const host of roster.hosts) {
|
|
697
|
+
const value = manifests.get(host.hostId);
|
|
698
|
+
if (host.hostId !== ports.hostId && host.owner.issuer === owner.issuer && host.owner.subject === owner.subject && (!value || ports.now() > value.expiresAt - 3e4)) try {
|
|
699
|
+
await remember(await remote(host.hostId, "capabilities"));
|
|
700
|
+
} catch {}
|
|
701
|
+
}
|
|
702
|
+
return (0, _agimon_ai_po_network.effectiveProviders)({
|
|
703
|
+
workspaceId,
|
|
704
|
+
owner,
|
|
705
|
+
localHostId: ports.hostId,
|
|
706
|
+
local: manifests.get(ports.hostId),
|
|
707
|
+
roster: { hosts: [...knownHosts.values()] },
|
|
708
|
+
manifests,
|
|
709
|
+
consents,
|
|
710
|
+
now: ports.now()
|
|
711
|
+
}).map((provider) => {
|
|
712
|
+
if (provider.provenance === "local") return provider;
|
|
713
|
+
const host = roster.hosts.find((host) => host.hostId === provider.hostId);
|
|
714
|
+
if (!host || host.publicKey !== manifestKeys.get(provider.hostId)) return {
|
|
715
|
+
...provider,
|
|
716
|
+
status: "unavailable",
|
|
717
|
+
reason: "host-removed"
|
|
718
|
+
};
|
|
719
|
+
if (!fresh()) return {
|
|
720
|
+
...provider,
|
|
721
|
+
status: "unavailable",
|
|
722
|
+
reason: "roster-stale"
|
|
723
|
+
};
|
|
724
|
+
return provider;
|
|
725
|
+
});
|
|
726
|
+
},
|
|
727
|
+
relayRetryState: () => ({
|
|
728
|
+
attempts,
|
|
729
|
+
retryAt,
|
|
730
|
+
admitted: relay?.admitted() ?? false
|
|
731
|
+
}),
|
|
732
|
+
acceptRelay: (socket, url) => gateway.accept(socket, url),
|
|
733
|
+
snapshot: () => roster,
|
|
734
|
+
async recordPendingVoterChange() {
|
|
735
|
+
roster = {
|
|
736
|
+
...roster,
|
|
737
|
+
voterChange: "pending-quorum"
|
|
738
|
+
};
|
|
739
|
+
await database.run("INSERT OR REPLACE INTO po_network_roster VALUES (?, ?)", ports.networkId, JSON.stringify(roster));
|
|
740
|
+
},
|
|
741
|
+
sendRelay: (frame) => fresh() && (relay?.send(frame) ?? false),
|
|
742
|
+
apply,
|
|
743
|
+
configuration,
|
|
744
|
+
elect,
|
|
745
|
+
coordinator,
|
|
746
|
+
async authorizeHost(token, hostId, networkId) {
|
|
747
|
+
if (!fresh()) return false;
|
|
748
|
+
try {
|
|
749
|
+
const envelope = JSON.parse(token);
|
|
750
|
+
const payload = envelope.payload;
|
|
751
|
+
const host = roster.hosts.find((entry) => entry.hostId === hostId);
|
|
752
|
+
if (!host || networkId !== ports.networkId || payload.networkId !== networkId || payload.hostId !== hostId || payload.destination !== ports.hostId || payload.method !== "LINK" || payload.path !== "/api/network-link" || typeof payload.nonce !== "string" || !payload.nonce || !(0, _agimon_ai_po_web_security_deviceProof.verifyEnvelope)(host.publicKey, "po/host-request/v1", envelope, ports.now())) return false;
|
|
753
|
+
return admitNonce(hostId, payload.nonce, payload.expiresAt);
|
|
754
|
+
} catch {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
hostKey(hostId) {
|
|
759
|
+
return authorityRoster().hosts.find((host) => host.hostId === hostId)?.publicKey;
|
|
760
|
+
},
|
|
761
|
+
async request(request) {
|
|
762
|
+
const pathname = new URL(request.url).pathname;
|
|
763
|
+
const nested = /^\/api\/networks\/([^/]+)\/network\/([^/]+)$/.exec(pathname);
|
|
764
|
+
if (nested && decodeURIComponent(nested[1]) !== ports.networkId) return Response.json({ error: "Network not found" }, { status: 404 });
|
|
765
|
+
const match = nested ? [nested[0], nested[2]] : /^\/api\/network\/([^/]+)$/.exec(pathname);
|
|
766
|
+
if (!match) return void 0;
|
|
767
|
+
if (request.method !== (match[1] === "capabilities" ? "GET" : "POST")) return Response.json({ error: "Method refused" }, { status: 405 });
|
|
768
|
+
try {
|
|
769
|
+
if (!fresh()) return Response.json({ error: "Roster authority unavailable" }, { status: 401 });
|
|
770
|
+
if (match[1] === "voters") {
|
|
771
|
+
if (request.headers.has("x-po-host-proof") || !await ports.verifyOwnerRequest?.(request.clone())) return Response.json({ error: "Owner proof required" }, { status: 403 });
|
|
772
|
+
const body = await request.json();
|
|
773
|
+
if (!object(body) || !object(body.change) || typeof body.authorization !== "string") return Response.json({ error: "Invalid voter change" }, { status: 400 });
|
|
774
|
+
const change = {
|
|
775
|
+
...body.change,
|
|
776
|
+
signature: body.authorization
|
|
777
|
+
};
|
|
778
|
+
if (!(0, _agimon_ai_po_network.isVoterAuthorization)(change) || !await ports.verifyOwner?.(change, body.authorization)) return Response.json({ error: "Voter authorization refused" }, { status: 403 });
|
|
779
|
+
if (!votingReady || !(await voters()).includes(ports.hostId)) return Response.json({ error: "Voting configuration unavailable" }, { status: 409 });
|
|
780
|
+
return Response.json(await configuration.propose(change));
|
|
781
|
+
}
|
|
782
|
+
if ((match[1].startsWith("configuration.") || [
|
|
783
|
+
"directory.publish",
|
|
784
|
+
"directory.read",
|
|
785
|
+
"capabilities"
|
|
786
|
+
].includes(match[1])) && !request.headers.has("x-po-host-proof")) return Response.json({ error: "Host proof required" }, { status: 401 });
|
|
787
|
+
if (!(request.headers.has("x-po-host-proof") ? await authorizeHostOperation(request.clone(), match[1]) : !!await ports.verify(request.clone()))) return Response.json({ error: "Network proof refused" }, { status: 401 });
|
|
788
|
+
if ((match[1].startsWith("configuration.") && match[1] !== "configuration.genesis" || match[1].startsWith("coordinator.")) && !(await voters()).length) return Response.json({ error: "Trusted C9 genesis unavailable" }, { status: 409 });
|
|
789
|
+
if (match[1] === "capabilities") {
|
|
790
|
+
await refreshCapabilities();
|
|
791
|
+
return ownManifest ? Response.json(ownManifest) : Response.json({ error: "Manifest unavailable" }, { status: 503 });
|
|
792
|
+
}
|
|
793
|
+
if (match[1].startsWith("directory.")) {
|
|
794
|
+
if ((await coordinator())?.candidate !== ports.hostId) return Response.json({ error: "Not active gateway" }, { status: 409 });
|
|
795
|
+
if (!request.headers.has("x-po-host-proof")) return Response.json({ error: "Host proof required" }, { status: 401 });
|
|
796
|
+
if (match[1] === "directory.read") {
|
|
797
|
+
const input = await request.json();
|
|
798
|
+
if (!object(input) || input.networkId !== ports.networkId) return Response.json({ error: "Network not found" }, { status: 404 });
|
|
799
|
+
return Response.json(await directory.read(roster, ports.now()));
|
|
800
|
+
}
|
|
801
|
+
if (match[1] === "directory.publish") {
|
|
802
|
+
const envelope = await request.json();
|
|
803
|
+
const proof = JSON.parse(request.headers.get("x-po-host-proof"));
|
|
804
|
+
if (!object(envelope) || !object(envelope.payload) || proof.payload.hostId !== envelope.payload.hostId) return Response.json({ error: "Manifest host mismatch" }, { status: 403 });
|
|
805
|
+
const accepted = await directory.publish(envelope, roster, ports.now());
|
|
806
|
+
if (accepted) await remember(envelope);
|
|
807
|
+
return Response.json(accepted);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return Response.json(await handlers(true)(match[1], await request.json()));
|
|
811
|
+
} catch {
|
|
812
|
+
return Response.json({ error: "Network operation refused" }, { status: 403 });
|
|
813
|
+
}
|
|
814
|
+
},
|
|
815
|
+
async sync() {
|
|
816
|
+
if (!ports.fetchRoster) throw new Error("Roster credentials unavailable");
|
|
817
|
+
const envelope = await ports.fetchRoster();
|
|
818
|
+
if (unlinked) throw new Error("Network unlinked");
|
|
819
|
+
if (envelope?.payload?.epoch === roster.epoch) {
|
|
820
|
+
const legacy = !roster.snapshot && (0, _agimon_ai_po_network.applyRoster)({
|
|
821
|
+
...roster,
|
|
822
|
+
epoch: roster.epoch - 1,
|
|
823
|
+
term: -1
|
|
824
|
+
}, envelope, ports.trust, ports.now());
|
|
825
|
+
const sameLegacy = legacy && JSON.stringify(legacy.members) === JSON.stringify(roster.members) && JSON.stringify(legacy.hosts) === JSON.stringify(roster.hosts) && JSON.stringify(legacy.tombstones) === JSON.stringify(roster.tombstones);
|
|
826
|
+
if (!roster.snapshot && !sameLegacy || !(0, _agimon_ai_po_web_security_deviceProof.verifyEnvelope)(ports.trust.issuerPublicKey, "po/roster/v1", envelope, ports.now()) || roster.snapshot && JSON.stringify({
|
|
827
|
+
...roster.snapshot,
|
|
828
|
+
issuedAt: envelope.payload.issuedAt,
|
|
829
|
+
expiresAt: envelope.payload.expiresAt
|
|
830
|
+
}) !== JSON.stringify(envelope.payload)) throw new Error("Conflicting roster epoch");
|
|
831
|
+
roster = {
|
|
832
|
+
...roster,
|
|
833
|
+
syncedAt: ports.now(),
|
|
834
|
+
snapshot: envelope.payload
|
|
835
|
+
};
|
|
836
|
+
await database.run("INSERT OR REPLACE INTO po_network_roster VALUES (?, ?)", ports.networkId, JSON.stringify(roster));
|
|
837
|
+
await catchUp();
|
|
838
|
+
await maintainRelay();
|
|
839
|
+
await gateway.refresh();
|
|
840
|
+
if (ports.campaign?.() !== false && (await voters()).includes(ports.hostId)) await elect();
|
|
841
|
+
await refreshCapabilities();
|
|
842
|
+
return roster;
|
|
843
|
+
}
|
|
844
|
+
const applied = await apply(envelope);
|
|
845
|
+
await refreshCapabilities();
|
|
846
|
+
return applied;
|
|
847
|
+
},
|
|
848
|
+
startPolling(intervalMs = 3e4, onError) {
|
|
849
|
+
if (timer) return;
|
|
850
|
+
let unavailableReported = false;
|
|
851
|
+
timer = setInterval(() => {
|
|
852
|
+
catchUp().then(async () => {
|
|
853
|
+
if ((await voters()).length) await configuration.tick();
|
|
854
|
+
else if (!unavailableReported) {
|
|
855
|
+
unavailableReported = true;
|
|
856
|
+
onError(new NonVotingNotice());
|
|
857
|
+
}
|
|
858
|
+
}).then(() => this.sync()).catch(async (error) => {
|
|
859
|
+
if (!fresh()) {
|
|
860
|
+
channels.clear();
|
|
861
|
+
await maintainRelay();
|
|
862
|
+
await gateway.refresh();
|
|
863
|
+
}
|
|
864
|
+
onError(error);
|
|
865
|
+
}).then(() => refreshCapabilities()).catch(onError);
|
|
866
|
+
}, intervalMs);
|
|
867
|
+
timer.unref?.();
|
|
868
|
+
},
|
|
869
|
+
unlink: unlinkNetwork,
|
|
870
|
+
async close() {
|
|
871
|
+
if (timer) clearInterval(timer);
|
|
872
|
+
relay?.close();
|
|
873
|
+
gateway.close();
|
|
874
|
+
await queue;
|
|
875
|
+
try {
|
|
876
|
+
await refreshing;
|
|
877
|
+
} finally {
|
|
878
|
+
await database.close();
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
//#endregion
|
|
884
|
+
exports.NonVotingNotice = NonVotingNotice;
|
|
885
|
+
exports.createNodeNetwork = createNodeNetwork;
|
|
886
|
+
|
|
887
|
+
//# sourceMappingURL=network.cjs.map
|