@agimon-ai/po 0.0.0-alpha.21 → 0.0.0-alpha.210

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (621) hide show
  1. package/LICENSE +97 -8
  2. package/README.md +37 -722
  3. package/dist/apiContracts.cjs.map +1 -1
  4. package/dist/apiContracts.d.mts +2 -2
  5. package/dist/bin/cli.cjs +12 -7
  6. package/dist/bin/cli.cjs.map +1 -1
  7. package/dist/bin/cli.mjs +12 -7
  8. package/dist/bin/cli.mjs.map +1 -1
  9. package/dist/bin/poRunner.cjs +24 -7
  10. package/dist/bin/poRunner.cjs.map +1 -1
  11. package/dist/bin/poRunner.d.mts +8 -0
  12. package/dist/bin/poRunner.d.mts.map +1 -1
  13. package/dist/bin/poRunner.mjs +24 -7
  14. package/dist/bin/poRunner.mjs.map +1 -1
  15. package/dist/bin/serve.cjs +28 -17
  16. package/dist/bin/serve.cjs.map +1 -1
  17. package/dist/bin/serve.mjs +28 -17
  18. package/dist/bin/serve.mjs.map +1 -1
  19. package/dist/builders/cli/extensionAssembler/index.cjs +53 -40
  20. package/dist/builders/cli/extensionAssembler/index.cjs.map +1 -1
  21. package/dist/builders/cli/extensionAssembler/index.d.mts +11 -6
  22. package/dist/builders/cli/extensionAssembler/index.d.mts.map +1 -1
  23. package/dist/builders/cli/extensionAssembler/index.mjs +53 -41
  24. package/dist/builders/cli/extensionAssembler/index.mjs.map +1 -1
  25. package/dist/catalog/index.json +662 -105
  26. package/dist/cli.cjs +9 -14
  27. package/dist/cli.d.mts +1 -3
  28. package/dist/cli.mjs +1 -3
  29. package/dist/commands.cjs +13 -15
  30. package/dist/commands.d.mts +1 -2
  31. package/dist/commands.mjs +1 -2
  32. package/dist/config.cjs +9 -14
  33. package/dist/config.d.mts +3 -2
  34. package/dist/config.mjs +3 -2
  35. package/dist/extensions/server.cjs +30 -23
  36. package/dist/extensions/server.cjs.map +1 -1
  37. package/dist/extensions/server.d.mts.map +1 -1
  38. package/dist/extensions/server.mjs +31 -24
  39. package/dist/extensions/server.mjs.map +1 -1
  40. package/dist/harnessContext.cjs +0 -1
  41. package/dist/harnessContext.d.mts +2 -2
  42. package/dist/harnessContext.mjs +1 -1
  43. package/dist/harnessState.cjs +2 -1
  44. package/dist/help.cjs +9 -11
  45. package/dist/help.d.mts +1 -2
  46. package/dist/help.mjs +1 -2
  47. package/dist/index.cjs +40 -67
  48. package/dist/index.d.mts +7 -16
  49. package/dist/index.mjs +7 -14
  50. package/dist/matrixOptions.cjs +10 -5
  51. package/dist/matrixOptions.d.mts +2 -2
  52. package/dist/matrixOptions.mjs +1 -1
  53. package/dist/package.cjs +11 -0
  54. package/dist/package.cjs.map +1 -0
  55. package/dist/package.mjs +6 -0
  56. package/dist/package.mjs.map +1 -0
  57. package/dist/projectTrust.cjs +3 -0
  58. package/dist/projectTrust.d.mts +2 -2
  59. package/dist/projectTrust.mjs +1 -1
  60. package/dist/repository.cjs +1 -0
  61. package/dist/repository.d.mts +2 -2
  62. package/dist/repository.mjs +1 -1
  63. package/dist/services.cjs +5 -20
  64. package/dist/services.d.mts +3 -8
  65. package/dist/services.mjs +3 -8
  66. package/dist/shared.cjs +4 -17
  67. package/dist/shared.d.mts +2 -2
  68. package/dist/shared.mjs +1 -1
  69. package/dist/src/bin/agentDirectory.cjs +19 -15
  70. package/dist/src/bin/agentDirectory.cjs.map +1 -1
  71. package/dist/src/bin/agentDirectory.mjs +16 -13
  72. package/dist/src/bin/agentDirectory.mjs.map +1 -1
  73. package/dist/src/builders/apiContractExport/index.cjs +23 -22
  74. package/dist/src/builders/apiContractExport/index.cjs.map +1 -1
  75. package/dist/src/builders/apiContractExport/index.mjs +22 -21
  76. package/dist/src/builders/apiContractExport/index.mjs.map +1 -1
  77. package/dist/src/builders/cli/entryResolution.cjs +2 -2
  78. package/dist/src/builders/cli/entryResolution.cjs.map +1 -1
  79. package/dist/src/builders/cli/entryResolution.mjs +1 -1
  80. package/dist/src/builders/cli/entryResolution.mjs.map +1 -1
  81. package/dist/src/builders/cli/harnessContext.cjs +38 -43
  82. package/dist/src/builders/cli/harnessContext.cjs.map +1 -1
  83. package/dist/src/builders/cli/harnessContext.d.mts +11 -10
  84. package/dist/src/builders/cli/harnessContext.d.mts.map +1 -1
  85. package/dist/src/builders/cli/harnessContext.mjs +37 -41
  86. package/dist/src/builders/cli/harnessContext.mjs.map +1 -1
  87. package/dist/src/builders/cli/sessionComposition.cjs +23 -12
  88. package/dist/src/builders/cli/sessionComposition.cjs.map +1 -1
  89. package/dist/src/builders/cli/sessionComposition.mjs +23 -12
  90. package/dist/src/builders/cli/sessionComposition.mjs.map +1 -1
  91. package/dist/src/builders/isolate/compile.cjs +226 -0
  92. package/dist/src/builders/isolate/compile.cjs.map +1 -0
  93. package/dist/src/builders/isolate/compile.mjs +222 -0
  94. package/dist/src/builders/isolate/compile.mjs.map +1 -0
  95. package/dist/src/builders/isolate/index.cjs +195 -0
  96. package/dist/src/builders/isolate/index.cjs.map +1 -0
  97. package/dist/src/builders/isolate/index.mjs +192 -0
  98. package/dist/src/builders/isolate/index.mjs.map +1 -0
  99. package/dist/src/builders/isolate/membrane.cjs +198 -0
  100. package/dist/src/builders/isolate/membrane.cjs.map +1 -0
  101. package/dist/src/builders/isolate/membrane.mjs +198 -0
  102. package/dist/src/builders/isolate/membrane.mjs.map +1 -0
  103. package/dist/src/builders/isolate/names.cjs +10 -0
  104. package/dist/src/builders/isolate/names.cjs.map +1 -0
  105. package/dist/src/builders/isolate/names.mjs +9 -0
  106. package/dist/src/builders/isolate/names.mjs.map +1 -0
  107. package/dist/src/builders/native/index.cjs +229 -67
  108. package/dist/src/builders/native/index.cjs.map +1 -1
  109. package/dist/src/builders/native/index.d.mts +4 -2
  110. package/dist/src/builders/native/index.d.mts.map +1 -1
  111. package/dist/src/builders/native/index.mjs +229 -68
  112. package/dist/src/builders/native/index.mjs.map +1 -1
  113. package/dist/src/builders/npm/index.cjs +76 -0
  114. package/dist/src/builders/npm/index.cjs.map +1 -0
  115. package/dist/src/builders/npm/index.mjs +73 -0
  116. package/dist/src/builders/npm/index.mjs.map +1 -0
  117. package/dist/src/builders/server/backgroundSync.cjs +62 -39
  118. package/dist/src/builders/server/backgroundSync.cjs.map +1 -1
  119. package/dist/src/builders/server/backgroundSync.mjs +62 -38
  120. package/dist/src/builders/server/backgroundSync.mjs.map +1 -1
  121. package/dist/src/builders/server/bundlerService.cjs +165 -35
  122. package/dist/src/builders/server/bundlerService.cjs.map +1 -1
  123. package/dist/src/builders/server/bundlerService.mjs +164 -36
  124. package/dist/src/builders/server/bundlerService.mjs.map +1 -1
  125. package/dist/src/builders/server/capabilities.cjs +103 -0
  126. package/dist/src/builders/server/capabilities.cjs.map +1 -0
  127. package/dist/src/builders/server/capabilities.mjs +101 -0
  128. package/dist/src/builders/server/capabilities.mjs.map +1 -0
  129. package/dist/src/builders/server/computerUseBinding.cjs +62 -10
  130. package/dist/src/builders/server/computerUseBinding.cjs.map +1 -1
  131. package/dist/src/builders/server/computerUseBinding.mjs +60 -8
  132. package/dist/src/builders/server/computerUseBinding.mjs.map +1 -1
  133. package/dist/src/builders/server/computerUseRecordings.cjs +152 -51
  134. package/dist/src/builders/server/computerUseRecordings.cjs.map +1 -1
  135. package/dist/src/builders/server/computerUseRecordings.mjs +158 -59
  136. package/dist/src/builders/server/computerUseRecordings.mjs.map +1 -1
  137. package/dist/src/builders/server/containedSessions.cjs +152 -0
  138. package/dist/src/builders/server/containedSessions.cjs.map +1 -0
  139. package/dist/src/builders/server/containedSessions.mjs +146 -0
  140. package/dist/src/builders/server/containedSessions.mjs.map +1 -0
  141. package/dist/src/builders/server/defaultWorkspace.cjs +46 -11
  142. package/dist/src/builders/server/defaultWorkspace.cjs.map +1 -1
  143. package/dist/src/builders/server/defaultWorkspace.mjs +42 -10
  144. package/dist/src/builders/server/defaultWorkspace.mjs.map +1 -1
  145. package/dist/src/builders/server/electronBinding.cjs +82 -0
  146. package/dist/src/builders/server/electronBinding.cjs.map +1 -0
  147. package/dist/src/builders/server/electronBinding.mjs +82 -0
  148. package/dist/src/builders/server/electronBinding.mjs.map +1 -0
  149. package/dist/src/builders/server/federation.cjs +364 -0
  150. package/dist/src/builders/server/federation.cjs.map +1 -0
  151. package/dist/src/builders/server/federation.mjs +363 -0
  152. package/dist/src/builders/server/federation.mjs.map +1 -0
  153. package/dist/src/builders/server/hostDisplayName.cjs +14 -0
  154. package/dist/src/builders/server/hostDisplayName.cjs.map +1 -0
  155. package/dist/src/builders/server/hostDisplayName.mjs +14 -0
  156. package/dist/src/builders/server/hostDisplayName.mjs.map +1 -0
  157. package/dist/src/builders/server/hostModelGateway.cjs +41 -0
  158. package/dist/src/builders/server/hostModelGateway.cjs.map +1 -0
  159. package/dist/src/builders/server/hostModelGateway.mjs +39 -0
  160. package/dist/src/builders/server/hostModelGateway.mjs.map +1 -0
  161. package/dist/src/builders/server/hostTeam.cjs +188 -0
  162. package/dist/src/builders/server/hostTeam.cjs.map +1 -0
  163. package/dist/src/builders/server/hostTeam.mjs +180 -0
  164. package/dist/src/builders/server/hostTeam.mjs.map +1 -0
  165. package/dist/src/builders/server/idleRestart.cjs +185 -40
  166. package/dist/src/builders/server/idleRestart.cjs.map +1 -1
  167. package/dist/src/builders/server/idleRestart.mjs +176 -39
  168. package/dist/src/builders/server/idleRestart.mjs.map +1 -1
  169. package/dist/src/builders/server/index.cjs +33 -19
  170. package/dist/src/builders/server/index.cjs.map +1 -1
  171. package/dist/src/builders/server/index.mjs +33 -18
  172. package/dist/src/builders/server/index.mjs.map +1 -1
  173. package/dist/src/builders/server/liveActivityPush.cjs +202 -0
  174. package/dist/src/builders/server/liveActivityPush.cjs.map +1 -0
  175. package/dist/src/builders/server/liveActivityPush.mjs +202 -0
  176. package/dist/src/builders/server/liveActivityPush.mjs.map +1 -0
  177. package/dist/src/builders/server/logSink.cjs +12 -10
  178. package/dist/src/builders/server/logSink.cjs.map +1 -1
  179. package/dist/src/builders/server/logSink.mjs +12 -10
  180. package/dist/src/builders/server/logSink.mjs.map +1 -1
  181. package/dist/src/builders/server/mcpApp.cjs +27 -20
  182. package/dist/src/builders/server/mcpApp.cjs.map +1 -1
  183. package/dist/src/builders/server/mcpApp.mjs +25 -18
  184. package/dist/src/builders/server/mcpApp.mjs.map +1 -1
  185. package/dist/src/builders/server/mcpAppBuild.cjs +61 -41
  186. package/dist/src/builders/server/mcpAppBuild.cjs.map +1 -1
  187. package/dist/src/builders/server/mcpAppBuild.d.mts +3 -6
  188. package/dist/src/builders/server/mcpAppBuild.d.mts.map +1 -1
  189. package/dist/src/builders/server/mcpAppBuild.mjs +61 -40
  190. package/dist/src/builders/server/mcpAppBuild.mjs.map +1 -1
  191. package/dist/src/builders/server/mcpBundle.cjs +20 -16
  192. package/dist/src/builders/server/mcpBundle.cjs.map +1 -1
  193. package/dist/src/builders/server/mcpBundle.d.mts +2 -1
  194. package/dist/src/builders/server/mcpBundle.d.mts.map +1 -1
  195. package/dist/src/builders/server/mcpBundle.mjs +20 -15
  196. package/dist/src/builders/server/mcpBundle.mjs.map +1 -1
  197. package/dist/src/builders/server/nativePush.cjs +229 -0
  198. package/dist/src/builders/server/nativePush.cjs.map +1 -0
  199. package/dist/src/builders/server/nativePush.mjs +228 -0
  200. package/dist/src/builders/server/nativePush.mjs.map +1 -0
  201. package/dist/src/builders/server/network.cjs +887 -0
  202. package/dist/src/builders/server/network.cjs.map +1 -0
  203. package/dist/src/builders/server/network.mjs +886 -0
  204. package/dist/src/builders/server/network.mjs.map +1 -0
  205. package/dist/src/builders/server/networkGateway.cjs +123 -0
  206. package/dist/src/builders/server/networkGateway.cjs.map +1 -0
  207. package/dist/src/builders/server/networkGateway.mjs +123 -0
  208. package/dist/src/builders/server/networkGateway.mjs.map +1 -0
  209. package/dist/src/builders/server/networkRelay.cjs +83 -0
  210. package/dist/src/builders/server/networkRelay.cjs.map +1 -0
  211. package/dist/src/builders/server/networkRelay.mjs +81 -0
  212. package/dist/src/builders/server/networkRelay.mjs.map +1 -0
  213. package/dist/src/builders/server/orgPluginLibraryBinding.cjs +72 -0
  214. package/dist/src/builders/server/orgPluginLibraryBinding.cjs.map +1 -0
  215. package/dist/src/builders/server/orgPluginLibraryBinding.mjs +72 -0
  216. package/dist/src/builders/server/orgPluginLibraryBinding.mjs.map +1 -0
  217. package/dist/src/builders/server/packageReloadCheck.cjs +46 -2
  218. package/dist/src/builders/server/packageReloadCheck.cjs.map +1 -1
  219. package/dist/src/builders/server/packageReloadCheck.mjs +46 -3
  220. package/dist/src/builders/server/packageReloadCheck.mjs.map +1 -1
  221. package/dist/src/builders/server/packageUrl.cjs +161 -58
  222. package/dist/src/builders/server/packageUrl.cjs.map +1 -1
  223. package/dist/src/builders/server/packageUrl.mjs +162 -58
  224. package/dist/src/builders/server/packageUrl.mjs.map +1 -1
  225. package/dist/src/builders/server/privateRelay.cjs +309 -0
  226. package/dist/src/builders/server/privateRelay.cjs.map +1 -0
  227. package/dist/src/builders/server/privateRelay.mjs +305 -0
  228. package/dist/src/builders/server/privateRelay.mjs.map +1 -0
  229. package/dist/src/builders/server/privateRelayCarrier.cjs +316 -0
  230. package/dist/src/builders/server/privateRelayCarrier.cjs.map +1 -0
  231. package/dist/src/builders/server/privateRelayCarrier.mjs +309 -0
  232. package/dist/src/builders/server/privateRelayCarrier.mjs.map +1 -0
  233. package/dist/src/builders/server/runtime.cjs +2731 -485
  234. package/dist/src/builders/server/runtime.cjs.map +1 -1
  235. package/dist/src/builders/server/runtime.mjs +2741 -499
  236. package/dist/src/builders/server/runtime.mjs.map +1 -1
  237. package/dist/src/builders/server/runtimeResources.cjs +37 -0
  238. package/dist/src/builders/server/runtimeResources.cjs.map +1 -1
  239. package/dist/src/builders/server/runtimeResources.mjs +38 -2
  240. package/dist/src/builders/server/runtimeResources.mjs.map +1 -1
  241. package/dist/src/builders/server/sandboxRouter.cjs +815 -0
  242. package/dist/src/builders/server/sandboxRouter.cjs.map +1 -0
  243. package/dist/src/builders/server/sandboxRouter.mjs +811 -0
  244. package/dist/src/builders/server/sandboxRouter.mjs.map +1 -0
  245. package/dist/src/builders/server/sandboxSessionHandoff.cjs +298 -0
  246. package/dist/src/builders/server/sandboxSessionHandoff.cjs.map +1 -0
  247. package/dist/src/builders/server/sandboxSessionHandoff.mjs +287 -0
  248. package/dist/src/builders/server/sandboxSessionHandoff.mjs.map +1 -0
  249. package/dist/src/builders/server/scopeReloadController.cjs +80 -0
  250. package/dist/src/builders/server/scopeReloadController.cjs.map +1 -0
  251. package/dist/src/builders/server/scopeReloadController.mjs +80 -0
  252. package/dist/src/builders/server/scopeReloadController.mjs.map +1 -0
  253. package/dist/src/builders/server/selectionStatus.cjs +2 -2
  254. package/dist/src/builders/server/selectionStatus.cjs.map +1 -1
  255. package/dist/src/builders/server/selectionStatus.mjs +2 -2
  256. package/dist/src/builders/server/selectionStatus.mjs.map +1 -1
  257. package/dist/src/builders/server/sessionArguments.cjs +65 -7
  258. package/dist/src/builders/server/sessionArguments.cjs.map +1 -1
  259. package/dist/src/builders/server/sessionArguments.mjs +64 -8
  260. package/dist/src/builders/server/sessionArguments.mjs.map +1 -1
  261. package/dist/src/builders/server/sessionRemoval.cjs +233 -0
  262. package/dist/src/builders/server/sessionRemoval.cjs.map +1 -0
  263. package/dist/src/builders/server/sessionRemoval.mjs +224 -0
  264. package/dist/src/builders/server/sessionRemoval.mjs.map +1 -0
  265. package/dist/src/builders/server/sessionSummaries.cjs +32 -0
  266. package/dist/src/builders/server/sessionSummaries.cjs.map +1 -0
  267. package/dist/src/builders/server/sessionSummaries.mjs +31 -0
  268. package/dist/src/builders/server/sessionSummaries.mjs.map +1 -0
  269. package/dist/src/builders/server/shutdown.cjs +23 -0
  270. package/dist/src/builders/server/shutdown.cjs.map +1 -1
  271. package/dist/src/builders/server/shutdown.mjs +21 -1
  272. package/dist/src/builders/server/shutdown.mjs.map +1 -1
  273. package/dist/src/builders/server/shutdownStack.cjs +44 -0
  274. package/dist/src/builders/server/shutdownStack.cjs.map +1 -0
  275. package/dist/src/builders/server/shutdownStack.mjs +43 -0
  276. package/dist/src/builders/server/shutdownStack.mjs.map +1 -0
  277. package/dist/src/builders/server/toolBoundaryHold.cjs +55 -0
  278. package/dist/src/builders/server/toolBoundaryHold.cjs.map +1 -0
  279. package/dist/src/builders/server/toolBoundaryHold.mjs +55 -0
  280. package/dist/src/builders/server/toolBoundaryHold.mjs.map +1 -0
  281. package/dist/src/builders/server/watcherService.cjs +55 -28
  282. package/dist/src/builders/server/watcherService.cjs.map +1 -1
  283. package/dist/src/builders/server/watcherService.mjs +55 -27
  284. package/dist/src/builders/server/watcherService.mjs.map +1 -1
  285. package/dist/src/builders/server/webTemplateDecision.cjs +7 -3
  286. package/dist/src/builders/server/webTemplateDecision.cjs.map +1 -1
  287. package/dist/src/builders/server/webTemplateDecision.mjs +7 -3
  288. package/dist/src/builders/server/webTemplateDecision.mjs.map +1 -1
  289. package/dist/src/builders/server/workspaceAdmission.cjs +96 -0
  290. package/dist/src/builders/server/workspaceAdmission.cjs.map +1 -0
  291. package/dist/src/builders/server/workspaceAdmission.mjs +90 -0
  292. package/dist/src/builders/server/workspaceAdmission.mjs.map +1 -0
  293. package/dist/src/builders/server/workspaceCheckout.cjs +16 -7
  294. package/dist/src/builders/server/workspaceCheckout.cjs.map +1 -1
  295. package/dist/src/builders/server/workspaceCheckout.mjs +16 -7
  296. package/dist/src/builders/server/workspaceCheckout.mjs.map +1 -1
  297. package/dist/src/builders/web/bundle.cjs +16 -14
  298. package/dist/src/builders/web/bundle.cjs.map +1 -1
  299. package/dist/src/builders/web/bundle.d.mts +3 -0
  300. package/dist/src/builders/web/bundle.d.mts.map +1 -1
  301. package/dist/src/builders/web/bundle.mjs +15 -13
  302. package/dist/src/builders/web/bundle.mjs.map +1 -1
  303. package/dist/src/builders/web/index.cjs +77 -59
  304. package/dist/src/builders/web/index.cjs.map +1 -1
  305. package/dist/src/builders/web/index.d.mts +19 -14
  306. package/dist/src/builders/web/index.d.mts.map +1 -1
  307. package/dist/src/builders/web/index.mjs +76 -58
  308. package/dist/src/builders/web/index.mjs.map +1 -1
  309. package/dist/src/builders/web/webPluginGenerate.cjs +84 -45
  310. package/dist/src/builders/web/webPluginGenerate.cjs.map +1 -1
  311. package/dist/src/builders/web/webPluginGenerate.d.mts +13 -4
  312. package/dist/src/builders/web/webPluginGenerate.d.mts.map +1 -1
  313. package/dist/src/builders/web/webPluginGenerate.mjs +82 -44
  314. package/dist/src/builders/web/webPluginGenerate.mjs.map +1 -1
  315. package/dist/src/builders/web/webPluginManifest.cjs +24 -17
  316. package/dist/src/builders/web/webPluginManifest.cjs.map +1 -1
  317. package/dist/src/builders/web/webPluginManifest.d.mts +11 -23
  318. package/dist/src/builders/web/webPluginManifest.d.mts.map +1 -1
  319. package/dist/src/builders/web/webPluginManifest.mjs +23 -16
  320. package/dist/src/builders/web/webPluginManifest.mjs.map +1 -1
  321. package/dist/src/builders/web/webPluginScan.cjs +11 -8
  322. package/dist/src/builders/web/webPluginScan.cjs.map +1 -1
  323. package/dist/src/builders/web/webPluginScan.d.mts +1 -1
  324. package/dist/src/builders/web/webPluginScan.d.mts.map +1 -1
  325. package/dist/src/builders/web/webPluginScan.mjs +10 -7
  326. package/dist/src/builders/web/webPluginScan.mjs.map +1 -1
  327. package/dist/src/builders/web/webPluginVite.cjs +5 -5
  328. package/dist/src/builders/web/webPluginVite.cjs.map +1 -1
  329. package/dist/src/builders/web/webPluginVite.d.mts +1 -1
  330. package/dist/src/builders/web/webPluginVite.d.mts.map +1 -1
  331. package/dist/src/builders/web/webPluginVite.mjs +3 -3
  332. package/dist/src/builders/web/webPluginVite.mjs.map +1 -1
  333. package/dist/src/cli/cliApp.cjs +18 -19
  334. package/dist/src/cli/cliApp.cjs.map +1 -1
  335. package/dist/src/cli/cliApp.d.mts +1 -1
  336. package/dist/src/cli/cliApp.d.mts.map +1 -1
  337. package/dist/src/cli/cliApp.mjs +18 -19
  338. package/dist/src/cli/cliApp.mjs.map +1 -1
  339. package/dist/src/cli/commands/api-export/index.cjs +14 -13
  340. package/dist/src/cli/commands/api-export/index.cjs.map +1 -1
  341. package/dist/src/cli/commands/api-export/index.mjs +13 -12
  342. package/dist/src/cli/commands/api-export/index.mjs.map +1 -1
  343. package/dist/src/cli/commands/doctor/help.cjs +4 -3
  344. package/dist/src/cli/commands/doctor/help.cjs.map +1 -1
  345. package/dist/src/cli/commands/doctor/help.d.mts.map +1 -1
  346. package/dist/src/cli/commands/doctor/help.mjs +4 -3
  347. package/dist/src/cli/commands/doctor/help.mjs.map +1 -1
  348. package/dist/src/cli/commands/doctor/index.cjs +30 -17
  349. package/dist/src/cli/commands/doctor/index.cjs.map +1 -1
  350. package/dist/src/cli/commands/doctor/index.d.mts +4 -4
  351. package/dist/src/cli/commands/doctor/index.d.mts.map +1 -1
  352. package/dist/src/cli/commands/doctor/index.mjs +28 -15
  353. package/dist/src/cli/commands/doctor/index.mjs.map +1 -1
  354. package/dist/src/cli/commands/emit-mcp/index.cjs +3 -2
  355. package/dist/src/cli/commands/emit-mcp/index.cjs.map +1 -1
  356. package/dist/src/cli/commands/emit-mcp/index.d.mts.map +1 -1
  357. package/dist/src/cli/commands/emit-mcp/index.mjs +3 -2
  358. package/dist/src/cli/commands/emit-mcp/index.mjs.map +1 -1
  359. package/dist/src/cli/commands/explain/index.cjs +53 -38
  360. package/dist/src/cli/commands/explain/index.cjs.map +1 -1
  361. package/dist/src/cli/commands/explain/index.d.mts +3 -4
  362. package/dist/src/cli/commands/explain/index.d.mts.map +1 -1
  363. package/dist/src/cli/commands/explain/index.mjs +52 -37
  364. package/dist/src/cli/commands/explain/index.mjs.map +1 -1
  365. package/dist/src/cli/commands/init/help.cjs +3 -2
  366. package/dist/src/cli/commands/init/help.cjs.map +1 -1
  367. package/dist/src/cli/commands/init/help.d.mts.map +1 -1
  368. package/dist/src/cli/commands/init/help.mjs +3 -2
  369. package/dist/src/cli/commands/init/help.mjs.map +1 -1
  370. package/dist/src/cli/commands/init/index.cjs +17 -12
  371. package/dist/src/cli/commands/init/index.cjs.map +1 -1
  372. package/dist/src/cli/commands/init/index.d.mts.map +1 -1
  373. package/dist/src/cli/commands/init/index.mjs +16 -11
  374. package/dist/src/cli/commands/init/index.mjs.map +1 -1
  375. package/dist/src/cli/commands/init/presenter.cjs +29 -21
  376. package/dist/src/cli/commands/init/presenter.cjs.map +1 -1
  377. package/dist/src/cli/commands/init/presenter.mjs +29 -21
  378. package/dist/src/cli/commands/init/presenter.mjs.map +1 -1
  379. package/dist/src/cli/commands/sync/help.cjs +7 -3
  380. package/dist/src/cli/commands/sync/help.cjs.map +1 -1
  381. package/dist/src/cli/commands/sync/help.d.mts.map +1 -1
  382. package/dist/src/cli/commands/sync/help.mjs +7 -3
  383. package/dist/src/cli/commands/sync/help.mjs.map +1 -1
  384. package/dist/src/cli/commands/sync/index.cjs +72 -40
  385. package/dist/src/cli/commands/sync/index.cjs.map +1 -1
  386. package/dist/src/cli/commands/sync/index.d.mts.map +1 -1
  387. package/dist/src/cli/commands/sync/index.mjs +69 -37
  388. package/dist/src/cli/commands/sync/index.mjs.map +1 -1
  389. package/dist/src/cli/commands/sync/presenter.cjs +10 -1
  390. package/dist/src/cli/commands/sync/presenter.cjs.map +1 -1
  391. package/dist/src/cli/commands/sync/presenter.d.mts +0 -9
  392. package/dist/src/cli/commands/sync/presenter.d.mts.map +1 -1
  393. package/dist/src/cli/commands/sync/presenter.mjs +10 -1
  394. package/dist/src/cli/commands/sync/presenter.mjs.map +1 -1
  395. package/dist/src/cli/commands/web/index.cjs +7 -6
  396. package/dist/src/cli/commands/web/index.cjs.map +1 -1
  397. package/dist/src/cli/commands/web/index.mjs +6 -5
  398. package/dist/src/cli/commands/web/index.mjs.map +1 -1
  399. package/dist/src/cli/harnessOptions.cjs +15 -24
  400. package/dist/src/cli/harnessOptions.cjs.map +1 -1
  401. package/dist/src/cli/harnessOptions.d.mts +2 -2
  402. package/dist/src/cli/harnessOptions.d.mts.map +1 -1
  403. package/dist/src/cli/harnessOptions.mjs +14 -22
  404. package/dist/src/cli/harnessOptions.mjs.map +1 -1
  405. package/dist/src/cli/help.cjs +20 -26
  406. package/dist/src/cli/help.cjs.map +1 -1
  407. package/dist/src/cli/help.d.mts +1 -2
  408. package/dist/src/cli/help.d.mts.map +1 -1
  409. package/dist/src/cli/help.mjs +15 -20
  410. package/dist/src/cli/help.mjs.map +1 -1
  411. package/dist/src/cli/locale.cjs +25 -0
  412. package/dist/src/cli/locale.cjs.map +1 -0
  413. package/dist/src/cli/locale.mjs +22 -0
  414. package/dist/src/cli/locale.mjs.map +1 -0
  415. package/dist/src/cli/matrixOptions.cjs +85 -37
  416. package/dist/src/cli/matrixOptions.cjs.map +1 -1
  417. package/dist/src/cli/matrixOptions.d.mts +22 -16
  418. package/dist/src/cli/matrixOptions.d.mts.map +1 -1
  419. package/dist/src/cli/matrixOptions.mjs +76 -33
  420. package/dist/src/cli/matrixOptions.mjs.map +1 -1
  421. package/dist/src/cli/options.cjs +51 -128
  422. package/dist/src/cli/options.cjs.map +1 -1
  423. package/dist/src/cli/options.d.mts +1 -1
  424. package/dist/src/cli/options.d.mts.map +1 -1
  425. package/dist/src/cli/options.mjs +53 -130
  426. package/dist/src/cli/options.mjs.map +1 -1
  427. package/dist/src/cli/router.cjs +0 -1
  428. package/dist/src/cli/router.cjs.map +1 -1
  429. package/dist/src/cli/router.d.mts +1 -1
  430. package/dist/src/cli/router.mjs +0 -1
  431. package/dist/src/cli/router.mjs.map +1 -1
  432. package/dist/src/cli/server/options.cjs +37 -7
  433. package/dist/src/cli/server/options.cjs.map +1 -1
  434. package/dist/src/cli/server/options.mjs +37 -7
  435. package/dist/src/cli/server/options.mjs.map +1 -1
  436. package/dist/src/cli/server/processGuards.cjs +22 -15
  437. package/dist/src/cli/server/processGuards.cjs.map +1 -1
  438. package/dist/src/cli/server/processGuards.mjs +21 -14
  439. package/dist/src/cli/server/processGuards.mjs.map +1 -1
  440. package/dist/src/cli/server/restartPolicy.cjs +38 -0
  441. package/dist/src/cli/server/restartPolicy.cjs.map +1 -0
  442. package/dist/src/cli/server/restartPolicy.d.mts +21 -0
  443. package/dist/src/cli/server/restartPolicy.d.mts.map +1 -0
  444. package/dist/src/cli/server/restartPolicy.mjs +36 -0
  445. package/dist/src/cli/server/restartPolicy.mjs.map +1 -0
  446. package/dist/src/cli/server/run.cjs +12 -11
  447. package/dist/src/cli/server/run.cjs.map +1 -1
  448. package/dist/src/cli/server/run.mjs +11 -10
  449. package/dist/src/cli/server/run.mjs.map +1 -1
  450. package/dist/src/cli/server/supervise.cjs +89 -0
  451. package/dist/src/cli/server/supervise.cjs.map +1 -0
  452. package/dist/src/cli/server/supervise.mjs +89 -0
  453. package/dist/src/cli/server/supervise.mjs.map +1 -0
  454. package/dist/src/composition/harnessState/index.cjs +2 -1
  455. package/dist/src/composition/harnessState/index.cjs.map +1 -1
  456. package/dist/src/composition/harnessState/index.d.mts +2 -1
  457. package/dist/src/composition/harnessState/index.d.mts.map +1 -1
  458. package/dist/src/composition/harnessState/index.mjs +2 -1
  459. package/dist/src/composition/harnessState/index.mjs.map +1 -1
  460. package/dist/src/composition/layerPackageInstaller/index.cjs +293 -86
  461. package/dist/src/composition/layerPackageInstaller/index.cjs.map +1 -1
  462. package/dist/src/composition/layerPackageInstaller/index.d.mts +25 -2
  463. package/dist/src/composition/layerPackageInstaller/index.d.mts.map +1 -1
  464. package/dist/src/composition/layerPackageInstaller/index.mjs +295 -94
  465. package/dist/src/composition/layerPackageInstaller/index.mjs.map +1 -1
  466. package/dist/src/composition/marketplaceCatalog/index.cjs +136 -0
  467. package/dist/src/composition/marketplaceCatalog/index.cjs.map +1 -0
  468. package/dist/src/composition/marketplaceCatalog/index.mjs +132 -0
  469. package/dist/src/composition/marketplaceCatalog/index.mjs.map +1 -0
  470. package/dist/src/composition/orgPluginActivation/index.cjs +179 -0
  471. package/dist/src/composition/orgPluginActivation/index.cjs.map +1 -0
  472. package/dist/src/composition/orgPluginActivation/index.mjs +177 -0
  473. package/dist/src/composition/orgPluginActivation/index.mjs.map +1 -0
  474. package/dist/src/composition/orgPluginLibrary/index.cjs +205 -0
  475. package/dist/src/composition/orgPluginLibrary/index.cjs.map +1 -0
  476. package/dist/src/composition/orgPluginLibrary/index.mjs +200 -0
  477. package/dist/src/composition/orgPluginLibrary/index.mjs.map +1 -0
  478. package/dist/src/composition/pluginMarketplace/index.cjs +304 -0
  479. package/dist/src/composition/pluginMarketplace/index.cjs.map +1 -0
  480. package/dist/src/composition/pluginMarketplace/index.mjs +302 -0
  481. package/dist/src/composition/pluginMarketplace/index.mjs.map +1 -0
  482. package/dist/src/composition/poHomeMigration/index.cjs +46 -26
  483. package/dist/src/composition/poHomeMigration/index.cjs.map +1 -1
  484. package/dist/src/composition/poHomeMigration/index.d.mts.map +1 -1
  485. package/dist/src/composition/poHomeMigration/index.mjs +45 -25
  486. package/dist/src/composition/poHomeMigration/index.mjs.map +1 -1
  487. package/dist/src/composition/projectTrust/index.cjs +40 -3
  488. package/dist/src/composition/projectTrust/index.cjs.map +1 -1
  489. package/dist/src/composition/projectTrust/index.d.mts +8 -0
  490. package/dist/src/composition/projectTrust/index.d.mts.map +1 -1
  491. package/dist/src/composition/projectTrust/index.mjs +33 -2
  492. package/dist/src/composition/projectTrust/index.mjs.map +1 -1
  493. package/dist/src/composition/repository/index.cjs +29 -12
  494. package/dist/src/composition/repository/index.cjs.map +1 -1
  495. package/dist/src/composition/repository/index.d.mts +10 -3
  496. package/dist/src/composition/repository/index.d.mts.map +1 -1
  497. package/dist/src/composition/repository/index.mjs +29 -13
  498. package/dist/src/composition/repository/index.mjs.map +1 -1
  499. package/dist/src/composition/syncPrune/index.cjs +23 -16
  500. package/dist/src/composition/syncPrune/index.cjs.map +1 -1
  501. package/dist/src/composition/syncPrune/index.d.mts.map +1 -1
  502. package/dist/src/composition/syncPrune/index.mjs +22 -15
  503. package/dist/src/composition/syncPrune/index.mjs.map +1 -1
  504. package/dist/src/composition/syncService/index.cjs +441 -194
  505. package/dist/src/composition/syncService/index.cjs.map +1 -1
  506. package/dist/src/composition/syncService/index.d.mts +4 -1
  507. package/dist/src/composition/syncService/index.d.mts.map +1 -1
  508. package/dist/src/composition/syncService/index.mjs +440 -196
  509. package/dist/src/composition/syncService/index.mjs.map +1 -1
  510. package/dist/src/composition/syncService/localBuilds.cjs +41 -37
  511. package/dist/src/composition/syncService/localBuilds.cjs.map +1 -1
  512. package/dist/src/composition/syncService/localBuilds.mjs +40 -37
  513. package/dist/src/composition/syncService/localBuilds.mjs.map +1 -1
  514. package/dist/src/composition/transitionLayers.cjs.map +1 -1
  515. package/dist/src/composition/transitionLayers.d.mts +3 -3
  516. package/dist/src/composition/transitionLayers.d.mts.map +1 -1
  517. package/dist/src/composition/transitionLayers.mjs.map +1 -1
  518. package/dist/src/composition/types/harness.d.mts +4 -9
  519. package/dist/src/composition/types/harness.d.mts.map +1 -1
  520. package/dist/src/extensions/setupDiagnostics.cjs +8 -8
  521. package/dist/src/extensions/setupDiagnostics.cjs.map +1 -1
  522. package/dist/src/extensions/setupDiagnostics.mjs +8 -8
  523. package/dist/src/extensions/setupDiagnostics.mjs.map +1 -1
  524. package/dist/webBuilder.cjs +1 -0
  525. package/dist/webBuilder.d.mts +2 -2
  526. package/dist/webBuilder.mjs +2 -2
  527. package/docs/server/api-export.md +9 -9
  528. package/docs/server/api.md +22 -125
  529. package/docs/server/getting-started.md +21 -85
  530. package/docs/server/index.md +13 -58
  531. package/docs/server/ipc.md +26 -72
  532. package/docs/server/lifecycle.md +18 -91
  533. package/docs/server/security.md +20 -80
  534. package/package.json +47 -67
  535. package/src/prompts/po-author-extension/SKILL.md +2 -2
  536. package/src/prompts/po-author-extension/references/extension-contract.md +4 -6
  537. package/dist/antigravity.cjs +0 -5
  538. package/dist/antigravity.d.mts +0 -2
  539. package/dist/antigravity.mjs +0 -1
  540. package/dist/codex.cjs +0 -8
  541. package/dist/codex.d.mts +0 -2
  542. package/dist/codex.mjs +0 -1
  543. package/dist/compatibility.cjs +0 -27
  544. package/dist/compatibility.d.mts +0 -6
  545. package/dist/compatibility.mjs +0 -6
  546. package/dist/compatibilityCommand.cjs +0 -4
  547. package/dist/compatibilityCommand.d.mts +0 -2
  548. package/dist/compatibilityCommand.mjs +0 -1
  549. package/dist/compatibilityContext.cjs +0 -3
  550. package/dist/compatibilityContext.d.mts +0 -2
  551. package/dist/compatibilityContext.mjs +0 -1
  552. package/dist/compatibilityOptions.cjs +0 -5
  553. package/dist/compatibilityOptions.d.mts +0 -2
  554. package/dist/compatibilityOptions.mjs +0 -1
  555. package/dist/process.cjs +0 -12
  556. package/dist/process.d.mts +0 -2
  557. package/dist/process.mjs +0 -1
  558. package/dist/src/builders/hooks/index.cjs +0 -238
  559. package/dist/src/builders/hooks/index.cjs.map +0 -1
  560. package/dist/src/builders/hooks/index.mjs +0 -231
  561. package/dist/src/builders/hooks/index.mjs.map +0 -1
  562. package/dist/src/cli/commands/compat/context.cjs +0 -115
  563. package/dist/src/cli/commands/compat/context.cjs.map +0 -1
  564. package/dist/src/cli/commands/compat/context.d.mts +0 -22
  565. package/dist/src/cli/commands/compat/context.d.mts.map +0 -1
  566. package/dist/src/cli/commands/compat/context.mjs +0 -110
  567. package/dist/src/cli/commands/compat/context.mjs.map +0 -1
  568. package/dist/src/cli/commands/compat/help.cjs +0 -26
  569. package/dist/src/cli/commands/compat/help.cjs.map +0 -1
  570. package/dist/src/cli/commands/compat/help.d.mts +0 -4
  571. package/dist/src/cli/commands/compat/help.d.mts.map +0 -1
  572. package/dist/src/cli/commands/compat/help.mjs +0 -25
  573. package/dist/src/cli/commands/compat/help.mjs.map +0 -1
  574. package/dist/src/cli/commands/compat/index.cjs +0 -73
  575. package/dist/src/cli/commands/compat/index.cjs.map +0 -1
  576. package/dist/src/cli/commands/compat/index.d.mts +0 -14
  577. package/dist/src/cli/commands/compat/index.d.mts.map +0 -1
  578. package/dist/src/cli/commands/compat/index.mjs +0 -70
  579. package/dist/src/cli/commands/compat/index.mjs.map +0 -1
  580. package/dist/src/cli/commands/compat/options.cjs +0 -88
  581. package/dist/src/cli/commands/compat/options.cjs.map +0 -1
  582. package/dist/src/cli/commands/compat/options.d.mts +0 -15
  583. package/dist/src/cli/commands/compat/options.d.mts.map +0 -1
  584. package/dist/src/cli/commands/compat/options.mjs +0 -86
  585. package/dist/src/cli/commands/compat/options.mjs.map +0 -1
  586. package/dist/src/cli/commands/compat/providers/antigravity.cjs +0 -294
  587. package/dist/src/cli/commands/compat/providers/antigravity.cjs.map +0 -1
  588. package/dist/src/cli/commands/compat/providers/antigravity.d.mts +0 -9
  589. package/dist/src/cli/commands/compat/providers/antigravity.d.mts.map +0 -1
  590. package/dist/src/cli/commands/compat/providers/antigravity.mjs +0 -289
  591. package/dist/src/cli/commands/compat/providers/antigravity.mjs.map +0 -1
  592. package/dist/src/cli/commands/compat/providers/codex.cjs +0 -178
  593. package/dist/src/cli/commands/compat/providers/codex.cjs.map +0 -1
  594. package/dist/src/cli/commands/compat/providers/codex.d.mts +0 -17
  595. package/dist/src/cli/commands/compat/providers/codex.d.mts.map +0 -1
  596. package/dist/src/cli/commands/compat/providers/codex.mjs +0 -170
  597. package/dist/src/cli/commands/compat/providers/codex.mjs.map +0 -1
  598. package/dist/src/cli/commands/compat/providers/index.cjs +0 -65
  599. package/dist/src/cli/commands/compat/providers/index.cjs.map +0 -1
  600. package/dist/src/cli/commands/compat/providers/index.d.mts +0 -15
  601. package/dist/src/cli/commands/compat/providers/index.d.mts.map +0 -1
  602. package/dist/src/cli/commands/compat/providers/index.mjs +0 -45
  603. package/dist/src/cli/commands/compat/providers/index.mjs.map +0 -1
  604. package/dist/src/cli/commands/compat/providers/process.cjs +0 -172
  605. package/dist/src/cli/commands/compat/providers/process.cjs.map +0 -1
  606. package/dist/src/cli/commands/compat/providers/process.d.mts +0 -33
  607. package/dist/src/cli/commands/compat/providers/process.d.mts.map +0 -1
  608. package/dist/src/cli/commands/compat/providers/process.mjs +0 -159
  609. package/dist/src/cli/commands/compat/providers/process.mjs.map +0 -1
  610. package/dist/src/cli/commands/compat/providers/shared.cjs +0 -76
  611. package/dist/src/cli/commands/compat/providers/shared.cjs.map +0 -1
  612. package/dist/src/cli/commands/compat/providers/shared.d.mts +0 -40
  613. package/dist/src/cli/commands/compat/providers/shared.d.mts.map +0 -1
  614. package/dist/src/cli/commands/compat/providers/shared.mjs +0 -61
  615. package/dist/src/cli/commands/compat/providers/shared.mjs.map +0 -1
  616. package/dist/src/cli/commands/compat/types.d.mts +0 -31
  617. package/dist/src/cli/commands/compat/types.d.mts.map +0 -1
  618. package/dist/src/cli/commands/init/constants.cjs +0 -11
  619. package/dist/src/cli/commands/init/constants.cjs.map +0 -1
  620. package/dist/src/cli/commands/init/constants.mjs +0 -11
  621. package/dist/src/cli/commands/init/constants.mjs.map +0 -1
@@ -0,0 +1,886 @@
1
+ import { createNetworkGateway } from "./networkGateway.mjs";
2
+ import { connectNetworkRelay } from "./networkRelay.mjs";
3
+ import { BACKGROUND_CONTEXT } from "@agimon-ai/po-core/platform";
4
+ import { createPublicKey, verify } from "node:crypto";
5
+ import { FEDERATION_FRESHNESS, federationEnvelopeFields } from "@agimon-ai/po-web-security";
6
+ import { createRosterPeerLink } from "@agimon-ai/po-session";
7
+ import { VOTE_TAG, applyRoster, committedEpoch, committedVoters, configurationValidators, consentCandidates, createCapabilityDirectory, createCapabilityManifest, createConfigurationService, createNetworkRouter, createSqliteElectionStorage, effectiveProviders, genesisVoters, grantVote, initialRosterState, initialState, isVoterAuthorization, rosterAuthorityFresh, validLease, verifyCapabilityManifest, verifyHostProof, voteFields } from "@agimon-ai/po-network";
8
+ import { federationDigest, verifyDeviceSignature, verifyEnvelope } from "@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, 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) : initialRosterState(ports.networkId);
43
+ let unlinked = false;
44
+ const fresh = () => !unlinked && 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 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 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: 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(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(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 createSqliteElectionStorage(database, (network) => {
151
+ const seed = genesisEnvelope?.payload;
152
+ const committed = seed && 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 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 = 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 = 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 ? 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 verify("sha256", bytes, {
200
+ key: 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 && verifyDeviceSignature(key, VOTE_TAG, 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) => grantVote(state, ports.hostId, input, ports.now(), ports.timing));
233
+ return granted ? {
234
+ ...granted,
235
+ signature: ports.signVote(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: 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: 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 (!verifyEnvelope(ports.trust.issuerPublicKey, "po/roster/v1", signed, Math.min(ports.now(), signed.payload.expiresAt - 3e4))) continue;
305
+ if (!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 && 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 = 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 && 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 = 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 = 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 = 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 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: configurationValidators["configuration.genesis"],
472
+ authorize,
473
+ handle: async (input) => input.network === ports.networkId ? genesisEnvelope ?? null : null
474
+ },
475
+ "configuration.promise": {
476
+ validate: 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: 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: configurationValidators["configuration.activate"],
487
+ authorize,
488
+ handle: (input) => configuration.activate(input)
489
+ },
490
+ "configuration.history": {
491
+ validate: 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 (!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: 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: 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(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 || !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: 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 = initialRosterState(ports.networkId);
665
+ }
666
+ return {
667
+ network,
668
+ hostRequests,
669
+ async candidates(workspaceId, owner, consents) {
670
+ await refreshCapabilities();
671
+ return 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 + 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 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 || !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 (!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 && 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 || !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
+ export { NonVotingNotice, createNodeNetwork };
885
+
886
+ //# sourceMappingURL=network.mjs.map