@celljs/ta 4.13.1 → 4.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/dist/cli.mjs +997 -811
  2. package/dist/gateway.mjs +315 -150
  3. package/dist/pi/CHANGELOG.md +7 -0
  4. package/dist/pi/package.json +1 -1
  5. package/dist/pi/packages/ta-agents/package.json +3 -3
  6. package/dist/pi/packages/ta-bots/host/index.mjs +171 -135
  7. package/dist/pi/packages/ta-bots/package.json +3 -3
  8. package/dist/pi/packages/ta-changes/package.json +3 -3
  9. package/dist/pi/packages/ta-channels/host/index.mjs +170 -134
  10. package/dist/pi/packages/ta-channels/lib/room.js +3 -3
  11. package/dist/pi/packages/ta-channels/package.json +3 -3
  12. package/dist/pi/packages/ta-channels/web/index.js +1 -0
  13. package/dist/pi/packages/ta-computer-use/package.json +3 -3
  14. package/dist/pi/packages/ta-cron/README.en.md +1 -1
  15. package/dist/pi/packages/ta-cron/README.md +1 -1
  16. package/dist/pi/packages/ta-cron/lib/page.d.ts +2 -0
  17. package/dist/pi/packages/ta-cron/lib/page.js +8 -4
  18. package/dist/pi/packages/ta-cron/package.json +3 -3
  19. package/dist/pi/packages/ta-cron/web/index.js +9 -4
  20. package/dist/pi/packages/ta-extensions/package.json +3 -3
  21. package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +1 -1
  22. package/dist/pi/packages/ta-extensions/web/index.js +170 -134
  23. package/dist/pi/packages/ta-games/package.json +3 -3
  24. package/dist/pi/packages/ta-glance/package.json +3 -3
  25. package/dist/pi/packages/ta-initiative/README.en.md +1 -0
  26. package/dist/pi/packages/ta-initiative/README.md +1 -0
  27. package/dist/pi/packages/ta-initiative/host/index.mjs +3 -0
  28. package/dist/pi/packages/ta-initiative/lib/i18n.d.ts +1 -0
  29. package/dist/pi/packages/ta-initiative/lib/i18n.js +4 -2
  30. package/dist/pi/packages/ta-initiative/lib/inbox.js +1 -1
  31. package/dist/pi/packages/ta-initiative/lib/initiative-protocol.d.ts +2 -0
  32. package/dist/pi/packages/ta-initiative/lib/initiative-service.d.ts +1 -0
  33. package/dist/pi/packages/ta-initiative/lib/initiative-service.js +3 -0
  34. package/dist/pi/packages/ta-initiative/lib/initiative-store.js +5 -1
  35. package/dist/pi/packages/ta-initiative/lib/style.d.ts +1 -1
  36. package/dist/pi/packages/ta-initiative/lib/style.js +1 -1
  37. package/dist/pi/packages/ta-initiative/package.json +3 -3
  38. package/dist/pi/packages/ta-initiative/web/index.js +10 -7
  39. package/dist/pi/packages/ta-launcher/package.json +3 -3
  40. package/dist/pi/packages/ta-manual/package.json +3 -3
  41. package/dist/pi/packages/ta-moments/extension/index.mjs +81 -45
  42. package/dist/pi/packages/ta-moments/host/index.mjs +82 -46
  43. package/dist/pi/packages/ta-moments/lib/editor.js +1 -1
  44. package/dist/pi/packages/ta-moments/lib/friends.d.ts +4 -1
  45. package/dist/pi/packages/ta-moments/lib/friends.js +3 -2
  46. package/dist/pi/packages/ta-moments/lib/moments-host.js +1 -1
  47. package/dist/pi/packages/ta-moments/lib/moments-protocol.d.ts +2 -0
  48. package/dist/pi/packages/ta-moments/lib/page.js +4 -5
  49. package/dist/pi/packages/ta-moments/lib/post-util.js +2 -2
  50. package/dist/pi/packages/ta-moments/lib/store.js +6 -0
  51. package/dist/pi/packages/ta-moments/lib/style.d.ts +1 -1
  52. package/dist/pi/packages/ta-moments/lib/style.js +4 -5
  53. package/dist/pi/packages/ta-moments/package.json +3 -3
  54. package/dist/pi/packages/ta-moments/web/index.js +193 -149
  55. package/dist/pi/packages/ta-nearby/host/index.mjs +189 -4
  56. package/dist/pi/packages/ta-nearby/lib/nearby-net.js +2 -0
  57. package/dist/pi/packages/ta-nearby/lib/nearby-protocol.d.ts +11 -0
  58. package/dist/pi/packages/ta-nearby/lib/nearby-service.d.ts +3 -0
  59. package/dist/pi/packages/ta-nearby/lib/nearby-service.js +32 -7
  60. package/dist/pi/packages/ta-nearby/lib/page.js +10 -9
  61. package/dist/pi/packages/ta-nearby/lib/style.d.ts +1 -1
  62. package/dist/pi/packages/ta-nearby/lib/style.js +1 -1
  63. package/dist/pi/packages/ta-nearby/package.json +3 -3
  64. package/dist/pi/packages/ta-nearby/web/index.js +10 -2
  65. package/dist/pi/packages/ta-notify/README.en.md +1 -0
  66. package/dist/pi/packages/ta-notify/README.md +1 -0
  67. package/dist/pi/packages/ta-notify/host/index.mjs +3 -0
  68. package/dist/pi/packages/ta-notify/lib/notify-protocol.d.ts +2 -0
  69. package/dist/pi/packages/ta-notify/lib/notify-service.d.ts +1 -0
  70. package/dist/pi/packages/ta-notify/lib/notify-service.js +3 -0
  71. package/dist/pi/packages/ta-notify/package.json +3 -3
  72. package/dist/pi/packages/ta-recall/README.en.md +1 -1
  73. package/dist/pi/packages/ta-recall/README.md +1 -1
  74. package/dist/pi/packages/ta-recall/host/index.mjs +9 -12
  75. package/dist/pi/packages/ta-recall/lib/brief-util.d.ts +3 -3
  76. package/dist/pi/packages/ta-recall/lib/recall-service.d.ts +5 -3
  77. package/dist/pi/packages/ta-recall/lib/recall-service.js +11 -7
  78. package/dist/pi/packages/ta-recall/package.json +3 -3
  79. package/dist/pi/packages/ta-rooms/lib/friends-view.js +7 -8
  80. package/dist/pi/packages/ta-rooms/lib/page.d.ts +12 -0
  81. package/dist/pi/packages/ta-rooms/lib/page.js +38 -3
  82. package/dist/pi/packages/ta-rooms/lib/style.d.ts +1 -1
  83. package/dist/pi/packages/ta-rooms/lib/style.js +1 -2
  84. package/dist/pi/packages/ta-rooms/package.json +3 -3
  85. package/dist/pi/packages/ta-rooms/web/index.js +58 -17
  86. package/dist/pi/packages/ta-share/package.json +3 -3
  87. package/dist/pi/packages/ta-sync/lib/i18n.js +2 -2
  88. package/dist/pi/packages/ta-sync/lib/migrate-i18n.js +2 -2
  89. package/dist/pi/packages/ta-sync/lib/style.d.ts +1 -1
  90. package/dist/pi/packages/ta-sync/lib/style.js +1 -1
  91. package/dist/pi/packages/ta-sync/package.json +3 -3
  92. package/dist/pi/packages/ta-sync/web/index.js +5 -5
  93. package/dist/pi/packages/ta-sync-cloud/package.json +3 -3
  94. package/dist/pi/packages/ta-team/README.en.md +3 -1
  95. package/dist/pi/packages/ta-team/README.md +3 -1
  96. package/dist/pi/packages/ta-team/host/index.mjs +569 -47
  97. package/dist/pi/packages/ta-team/lib/dialogs.js +83 -16
  98. package/dist/pi/packages/ta-team/lib/host.js +4 -0
  99. package/dist/pi/packages/ta-team/lib/i18n.d.ts +11 -0
  100. package/dist/pi/packages/ta-team/lib/i18n.js +24 -2
  101. package/dist/pi/packages/ta-team/lib/members-tab.js +55 -8
  102. package/dist/pi/packages/ta-team/lib/page.d.ts +5 -0
  103. package/dist/pi/packages/ta-team/lib/page.js +15 -0
  104. package/dist/pi/packages/ta-team/lib/parts.d.ts +3 -1
  105. package/dist/pi/packages/ta-team/lib/parts.js +4 -3
  106. package/dist/pi/packages/ta-team/lib/policy.d.ts +24 -0
  107. package/dist/pi/packages/ta-team/lib/policy.js +32 -0
  108. package/dist/pi/packages/ta-team/lib/protocol.d.ts +22 -15
  109. package/dist/pi/packages/ta-team/lib/protocol.js +1 -3
  110. package/dist/pi/packages/ta-team/lib/shared-home.js +2 -2
  111. package/dist/pi/packages/ta-team/lib/style.d.ts +1 -1
  112. package/dist/pi/packages/ta-team/lib/style.js +8 -4
  113. package/dist/pi/packages/ta-team/lib/team-admin.js +1 -0
  114. package/dist/pi/packages/ta-team/lib/team-core.js +1 -0
  115. package/dist/pi/packages/ta-team/lib/team-invites.d.ts +74 -6
  116. package/dist/pi/packages/ta-team/lib/team-invites.js +207 -10
  117. package/dist/pi/packages/ta-team/lib/team-people.js +2 -0
  118. package/dist/pi/packages/ta-team/package.json +7 -3
  119. package/dist/pi/packages/ta-team/web/index.js +362 -139
  120. package/dist/pi/packages/ta-workspace/lib/style.d.ts +1 -1
  121. package/dist/pi/packages/ta-workspace/lib/style.js +2 -2
  122. package/dist/pi/packages/ta-workspace/package.json +4 -4
  123. package/dist/pi/packages/ta-workspace/web/index.js +210 -160
  124. package/dist/public/assets/{abnfDiagram-S7VZAUFO-C30pzFN3.js → abnfDiagram-S7VZAUFO-DMceNIR5.js} +1 -1
  125. package/dist/public/assets/{architecture-WOLXFQ4H-wfYFQl2u.js → architecture-WOLXFQ4H-5AdYeEv8.js} +1 -1
  126. package/dist/public/assets/{architectureDiagram-YGSQEFNW-B05zgxyT.js → architectureDiagram-YGSQEFNW-CqkJHg0A.js} +1 -1
  127. package/dist/public/assets/{blockDiagram-APKKGZFW-BhN8Bsu0.js → blockDiagram-APKKGZFW-BtuHdIjQ.js} +1 -1
  128. package/dist/public/assets/{browser-D2CY3Lfb.js → browser-D2BcOPKG.js} +1 -1
  129. package/dist/public/assets/{browser-DteLjv_-.js → browser-Ds5TwWWr.js} +1 -1
  130. package/dist/public/assets/{c4Diagram-KJ2TOQU5-DvdF3qCV.js → c4Diagram-KJ2TOQU5-eebbjTgZ.js} +1 -1
  131. package/dist/public/assets/{chunk-6MUBBAK2-DNavkrnr.js → chunk-6MUBBAK2-BjMKSfTf.js} +1 -1
  132. package/dist/public/assets/{chunk-AXFCVDMN-DplVEqp_.js → chunk-AXFCVDMN-BElluw_7.js} +1 -1
  133. package/dist/public/assets/{chunk-BG4553SI-BazOaHvw.js → chunk-BG4553SI-CUDwpWNL.js} +1 -1
  134. package/dist/public/assets/{chunk-DQASFODM-DmoQWa8b.js → chunk-DQASFODM-B-92o8Uj.js} +1 -1
  135. package/dist/public/assets/{chunk-HFQBQIA3-Cj1m9ccz.js → chunk-HFQBQIA3-pveEMcXK.js} +1 -1
  136. package/dist/public/assets/{chunk-KQLB2F66-_jbilrLX.js → chunk-KQLB2F66-m7DKNjYW.js} +1 -1
  137. package/dist/public/assets/{chunk-KS47KZWR-CWU16Lut.js → chunk-KS47KZWR-CnSSETdj.js} +1 -1
  138. package/dist/public/assets/{chunk-LEVMRMFU-wsbxWEZE.js → chunk-LEVMRMFU-Ds7OnJrC.js} +1 -1
  139. package/dist/public/assets/{chunk-M57EVK23-BGvmwwTv.js → chunk-M57EVK23-PJSYCuUh.js} +1 -1
  140. package/dist/public/assets/{chunk-OY52VR5R-Bp3hJ4kT.js → chunk-OY52VR5R-C3ygRwSC.js} +1 -1
  141. package/dist/public/assets/{chunk-QB3YPZ4I-C1rQVxsJ.js → chunk-QB3YPZ4I-DcFtmZh7.js} +1 -1
  142. package/dist/public/assets/{chunk-R3KSYZAL-CEy0dKWn.js → chunk-R3KSYZAL-B4BOidE6.js} +1 -1
  143. package/dist/public/assets/{chunk-STOXU5M4-akqvafwH.js → chunk-STOXU5M4-DcXfwN7k.js} +1 -1
  144. package/dist/public/assets/{chunk-TU62E6Q5-CVXAS4DS.js → chunk-TU62E6Q5-B-rpQQxX.js} +1 -1
  145. package/dist/public/assets/{chunk-X4PVCEUW-DT_bEMvQ.js → chunk-X4PVCEUW-BBtlFSw1.js} +1 -1
  146. package/dist/public/assets/{chunk-XXDRQBXY-Bgv_n5Qh.js → chunk-XXDRQBXY-Do8BIocv.js} +1 -1
  147. package/dist/public/assets/{classDiagram-v2-L25IHNXF-BtjQChpS.js → classDiagram-v2-L25IHNXF-bhGAODMS.js} +1 -1
  148. package/dist/public/assets/{client-sUFoEC5s.js → client-C8gi9Fk2.js} +1 -1
  149. package/dist/public/assets/{common-CGQN5htF.js → common-DrZR0tgm.js} +2 -2
  150. package/dist/public/assets/{cose-bilkent-JH36ORCC-DSrOY8Uk.js → cose-bilkent-JH36ORCC-B7Qv6Hv_.js} +1 -1
  151. package/dist/public/assets/cynefin-EF2NZ3EQ-Dfu5k3iG.js +1 -0
  152. package/dist/public/assets/{cynefinDiagram-L36ESFBY-DTy7FNFS.js → cynefinDiagram-L36ESFBY-BX-R5Z6L.js} +1 -1
  153. package/dist/public/assets/{d3-selection-ip6rDUzY.js → d3-selection-D3xgEEla.js} +1 -1
  154. package/dist/public/assets/{dagre-SPEB5RXH-CHrks7Jb.js → dagre-SPEB5RXH-MfJ9yO0v.js} +1 -1
  155. package/dist/public/assets/{diagram-3B7GL73J-eUJ7STAr.js → diagram-3B7GL73J-DxFRc2vC.js} +1 -1
  156. package/dist/public/assets/{diagram-DNEMPZML-B_fptNkg.js → diagram-DNEMPZML-BcBwOLbM.js} +1 -1
  157. package/dist/public/assets/{diagram-L3MUGCDN-C15owCSG.js → diagram-L3MUGCDN--Rw-isPI.js} +1 -1
  158. package/dist/public/assets/{diagram-LA4NIPWU-Bfa1qEgY.js → diagram-LA4NIPWU-DXkY85UN.js} +1 -1
  159. package/dist/public/assets/{diagram-MHCOC4E2-Bwxsih_Q.js → diagram-MHCOC4E2-CbNmfAid.js} +1 -1
  160. package/dist/public/assets/{diagram-XPFHEONP-DKZ_lwah.js → diagram-XPFHEONP-D1nGQjzf.js} +1 -1
  161. package/dist/public/assets/{dist-VHGBaby6.js → dist-B1JMTrET.js} +1 -1
  162. package/dist/public/assets/{ebnfDiagram-UZSYDL2S-CCkttvYi.js → ebnfDiagram-UZSYDL2S-DGXbVfke.js} +1 -1
  163. package/dist/public/assets/{editor.api-a2gC0dVD.js → editor.api-e3yQoo1r.js} +1 -1
  164. package/dist/public/assets/{elk-XV6XMXQE-DcikW39e.js → elk-XV6XMXQE-pA-iT6fg.js} +1 -1
  165. package/dist/public/assets/{erDiagram-EYBAPDEH-BE3TV5lU.js → erDiagram-EYBAPDEH-BpgBun7y.js} +1 -1
  166. package/dist/public/assets/{eventmodeling-K75KTNOO-C2s1kutf.js → eventmodeling-K75KTNOO-CVfyCcul.js} +1 -1
  167. package/dist/public/assets/flowDiagram-MALGAFMO-BHlXeeVG.js +1 -0
  168. package/dist/public/assets/{freemarker2-2e8pZojb.js → freemarker2-dYGec-fT.js} +1 -1
  169. package/dist/public/assets/{ganttDiagram-23REXITY-rGnJptii.js → ganttDiagram-23REXITY-DjLTTWwA.js} +1 -1
  170. package/dist/public/assets/gitGraph-VSP46ZUC-CFVSDv3q.js +1 -0
  171. package/dist/public/assets/{gitGraphDiagram-STJD7YCW-CNnsDjQA.js → gitGraphDiagram-STJD7YCW-D9m7IVyJ.js} +1 -1
  172. package/dist/public/assets/{handlebars-CMKN6E37.js → handlebars-Bxerz7ci.js} +1 -1
  173. package/dist/public/assets/{html-0AjXQhkQ.js → html-DlVnGsdp.js} +1 -1
  174. package/dist/public/assets/{index-TUtoc8CW.js → index-CZmGe9gc.js} +2 -2
  175. package/dist/public/assets/info-OHQRW6UA-C_Db4yjo.js +1 -0
  176. package/dist/public/assets/{infoDiagram-KBXO4MBG-DMKs8cuE.js → infoDiagram-KBXO4MBG-DoYdhkAy.js} +1 -1
  177. package/dist/public/assets/{ishikawaDiagram-M35NCXHK-Dg_IbA0G.js → ishikawaDiagram-M35NCXHK-Bc0GAInW.js} +1 -1
  178. package/dist/public/assets/{javascript-CqYOqPjw.js → javascript-DZrowo_I.js} +1 -1
  179. package/dist/public/assets/{journeyDiagram-OPLOXDXO-ohAOfoEY.js → journeyDiagram-OPLOXDXO-BM7Dwstu.js} +1 -1
  180. package/dist/public/assets/{jsonMode-D-gI-S5H.js → jsonMode-Bs30wPr5.js} +1 -1
  181. package/dist/public/assets/{kanban-definition-BZKZHSQY-w-aKZS_U.js → kanban-definition-BZKZHSQY-CO-Crrdu.js} +1 -1
  182. package/dist/public/assets/{liquid-oBN7c8NZ.js → liquid-dLz9d3ax.js} +1 -1
  183. package/dist/public/assets/{mdx-CnwhgGjX.js → mdx-DO0x92Kn.js} +1 -1
  184. package/dist/public/assets/{mermaid-parser.core-CfFkSR0t.js → mermaid-parser.core-BXwArNvw.js} +3 -3
  185. package/dist/public/assets/{mermaid.core-apiVCSBY.js → mermaid.core-C6mppfDC.js} +4 -4
  186. package/dist/public/assets/{mindmap-definition-I2QAS2VK-E7vqVWB0.js → mindmap-definition-I2QAS2VK-vcQ2EU4T.js} +1 -1
  187. package/dist/public/assets/module-C0tELrcJ.js +1 -0
  188. package/dist/public/assets/{module-B8jze-Tx.js → module-Cm_mLwAQ.js} +1 -1
  189. package/dist/public/assets/module-CteT9pTP.js +2405 -0
  190. package/dist/public/assets/module-DDH-aU6z.js +1 -0
  191. package/dist/public/assets/module-DRofmFJn.js +1 -0
  192. package/dist/public/assets/{module-ZhkaqrNe.js → module-DUYj4E8T.js} +1 -1
  193. package/dist/public/assets/module-MaD4hvv4.js +1 -0
  194. package/dist/public/assets/module-ZDJutm0b.js +1 -0
  195. package/dist/public/assets/module-qoBVcE5h.js +1 -0
  196. package/dist/public/assets/{monaco-C0ByxW3l.js → monaco-J_Pr5zjk.js} +3 -3
  197. package/dist/public/assets/packet-JDAUHWVQ-Bw7hmDUU.js +1 -0
  198. package/dist/public/assets/{pegDiagram-FD4XPPHP--RpwCE7x.js → pegDiagram-FD4XPPHP-DPDrbtS2.js} +1 -1
  199. package/dist/public/assets/pie-XZMESJXO-cb_eq1B6.js +1 -0
  200. package/dist/public/assets/{pieDiagram-J4AKIIQI-DxSbPaRZ.js → pieDiagram-J4AKIIQI-DXuaepGJ.js} +1 -1
  201. package/dist/public/assets/{python-vNPe_Fao.js → python-nnmIOv4s.js} +1 -1
  202. package/dist/public/assets/{quadrantDiagram-XTYBLID2-CR_eeYXi.js → quadrantDiagram-XTYBLID2-BuD_-coZ.js} +1 -1
  203. package/dist/public/assets/radar-ABXABTNO-Dqy-xoY_.js +1 -0
  204. package/dist/public/assets/railroad-I3PHUGI6-CBPVCTd3.js +1 -0
  205. package/dist/public/assets/{railroad-abnf-LNEFI6M7-D6I2HxIC.js → railroad-abnf-LNEFI6M7-CkCl68xY.js} +1 -1
  206. package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-BuhDRGo3.js → railroad-ebnf-DWYD2UWJ-DO3GiRv6.js} +1 -1
  207. package/dist/public/assets/{railroad-peg-JR7BVNR7-n15PB7Sb.js → railroad-peg-JR7BVNR7-DZBsKy4P.js} +1 -1
  208. package/dist/public/assets/{railroadDiagram-MRQ6NCDL-Bbe5bNap.js → railroadDiagram-MRQ6NCDL-BeLq7Mqp.js} +1 -1
  209. package/dist/public/assets/{razor-CnKbF0Yz.js → razor-l2rRITgB.js} +1 -1
  210. package/dist/public/assets/{requirementDiagram-Y7LWUY3S-Beuygh9j.js → requirementDiagram-Y7LWUY3S-BBizkrON.js} +1 -1
  211. package/dist/public/assets/{resolver-B7c_-amj.js → resolver-0zC31mg5.js} +1 -1
  212. package/dist/public/assets/{sankeyDiagram-WGJFYUXA-jwWPgnrS.js → sankeyDiagram-WGJFYUXA-tyo-p7oc.js} +1 -1
  213. package/dist/public/assets/{sequenceDiagram-5NDRBG5M-CmU-HYQI.js → sequenceDiagram-5NDRBG5M-BSGPbeJX.js} +1 -1
  214. package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-Bo7BEi-m.js → stateDiagram-v2-FJ4FJNEA-Dcdy66MQ.js} +1 -1
  215. package/dist/public/assets/{swimlanes-UMQ2AFYF-PSKyZN_b.js → swimlanes-UMQ2AFYF-BJfgQyQo.js} +1 -1
  216. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-BWvcVkFg.js +8 -0
  217. package/dist/public/assets/{timeline-definition-SEUHKTQE-BuRxLScZ.js → timeline-definition-SEUHKTQE-Ch8aQwF6.js} +1 -1
  218. package/dist/public/assets/treeView-D4JQ5SDB--XUqgqA6.js +1 -0
  219. package/dist/public/assets/treemap-SAJKECNS-CfrNtG7H.js +1 -0
  220. package/dist/public/assets/{typescript-C00ztMLg.js → typescript-LasX-M7S.js} +1 -1
  221. package/dist/public/assets/{usecaseDiagram-AFA6YXN4-Dlvyos8r.js → usecaseDiagram-AFA6YXN4-BzlSB4R4.js} +1 -1
  222. package/dist/public/assets/{vennDiagram-NNMJR3RB-CuLZubJH.js → vennDiagram-NNMJR3RB-4xaWLrMk.js} +1 -1
  223. package/dist/public/assets/wardley-7MLQ67FV-BXBG-txR.js +1 -0
  224. package/dist/public/assets/{wardleyDiagram-S7YFUSEH-WOGGTs4y.js → wardleyDiagram-S7YFUSEH-C-iK1p-O.js} +1 -1
  225. package/dist/public/assets/{xml-CHBFuf5n.js → xml-CGhYQUqn.js} +1 -1
  226. package/dist/public/assets/{xychartDiagram-GGNKY7IX-DwW9eifP.js → xychartDiagram-GGNKY7IX-CFsnisdM.js} +1 -1
  227. package/dist/public/assets/{yaml-C4qkqzcL.js → yaml-BcOaPfuH.js} +1 -1
  228. package/dist/public/index.html +2 -2
  229. package/dist/serve/index.mjs +2318 -1257
  230. package/package.json +39 -39
  231. package/dist/pi/packages/ta-team/lib/join.d.ts +0 -28
  232. package/dist/pi/packages/ta-team/lib/join.js +0 -48
  233. package/dist/pi/packages/ta-team/lib/remote.d.ts +0 -31
  234. package/dist/pi/packages/ta-team/lib/remote.js +0 -128
  235. package/dist/pi/packages/ta-team/lib/seal.d.ts +0 -28
  236. package/dist/pi/packages/ta-team/lib/seal.js +0 -75
  237. package/dist/public/assets/cynefin-EF2NZ3EQ-DYlwwGUb.js +0 -1
  238. package/dist/public/assets/flowDiagram-MALGAFMO-Bufgn1OL.js +0 -1
  239. package/dist/public/assets/gitGraph-VSP46ZUC-D_tzR9z9.js +0 -1
  240. package/dist/public/assets/info-OHQRW6UA-C5Pwv-6e.js +0 -1
  241. package/dist/public/assets/module-Blc8dqbf.js +0 -1
  242. package/dist/public/assets/module-C2jtFD0v.js +0 -2365
  243. package/dist/public/assets/module-C9WFrzAc.js +0 -1
  244. package/dist/public/assets/module-CouMtASh.js +0 -1
  245. package/dist/public/assets/module-EGdAhoOx.js +0 -1
  246. package/dist/public/assets/module-EeaigZHL.js +0 -1
  247. package/dist/public/assets/module-xT4L5yYw.js +0 -1
  248. package/dist/public/assets/packet-JDAUHWVQ-xozI7a9T.js +0 -1
  249. package/dist/public/assets/pie-XZMESJXO-BkHXIzDi.js +0 -1
  250. package/dist/public/assets/radar-ABXABTNO-CaUh9zV3.js +0 -1
  251. package/dist/public/assets/railroad-I3PHUGI6-DckPvlDe.js +0 -1
  252. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-z_0ABNQq.js +0 -8
  253. package/dist/public/assets/treeView-D4JQ5SDB-BN38Jg9j.js +0 -1
  254. package/dist/public/assets/treemap-SAJKECNS-CKdz7u7W.js +0 -1
  255. package/dist/public/assets/wardley-7MLQ67FV-B0cvM1zV.js +0 -1
package/dist/cli.mjs CHANGED
@@ -670,7 +670,7 @@ var init_relay_protocol = __esm(() => {
670
670
  RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
671
671
  RELAY_VIEWER_HEADERS = {
672
672
  "content-type": "text/html; charset=utf-8",
673
- "cache-control": "no-cache",
673
+ "cache-control": "no-cache, no-transform",
674
674
  "referrer-policy": "no-referrer",
675
675
  "x-content-type-options": "nosniff"
676
676
  };
@@ -915,9 +915,18 @@ var init_relay_identity = __esm(() => {
915
915
  }
916
916
  RelayIdentityUtil2.check = check;
917
917
  function publicOf(identity) {
918
- return { id: identity.id, name: identity.name, sign: identity.sign, box: identity.box };
918
+ return withLook({ id: identity.id, name: identity.name, sign: identity.sign, box: identity.box }, identity.look);
919
919
  }
920
920
  RelayIdentityUtil2.publicOf = publicOf;
921
+ function isLook(look) {
922
+ return typeof look === "string" && /^[a-z][a-z0-9-]{0,31}$/.test(look);
923
+ }
924
+ RelayIdentityUtil2.isLook = isLook;
925
+ function withLook(value, look) {
926
+ const { look: _, ...rest } = value;
927
+ return isLook(look) ? { ...rest, look } : rest;
928
+ }
929
+ RelayIdentityUtil2.withLook = withLook;
921
930
  async function sign(identity, text) {
922
931
  const key = await subtle().importKey("jwk", identity.signKey, SIGN, false, ["sign"]);
923
932
  return RelayBytes.toBase64(new Uint8Array(await subtle().sign(SIGNATURE, key, encoder.encode(text))));
@@ -1659,906 +1668,1080 @@ var init_relay_spot = __esm(() => {
1659
1668
  })(RelaySpotTries || (RelaySpotTries = {}));
1660
1669
  });
1661
1670
 
1662
- // ../../ta-packages/ta-relay/esm/node/relay-file-storage.js
1663
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync5, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
1664
- import { join as join5 } from "node:path";
1665
-
1666
- class FileRelayStorage {
1667
- constructor(dir, onAlarm) {
1668
- this.dir = dir;
1669
- this.onAlarm = onAlarm;
1670
- this.file = join5(dir, "values.json");
1671
- this.values = FileRelayStorage.load(this.file);
1672
- const alarm = this.values.get(ALARM);
1673
- if (typeof alarm === "number") {
1674
- this.schedule(alarm);
1675
- }
1676
- }
1677
- static ids(root) {
1678
- try {
1679
- return readdirSync2(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
1680
- } catch (_a) {
1681
- return [];
1671
+ // ../../ta-packages/ta-relay/esm/common/relay-pairing.js
1672
+ var exports_relay_pairing = {};
1673
+ __export(exports_relay_pairing, {
1674
+ RelayPairingUtil: () => RelayPairingUtil
1675
+ });
1676
+ var RelayPairingUtil;
1677
+ var init_relay_pairing = __esm(() => {
1678
+ init_relay_protocol();
1679
+ (function(RelayPairingUtil2) {
1680
+ function link(pairing) {
1681
+ const fragment = new URLSearchParams({ v: "1", h: pairing.host, d: pairing.device, k: pairing.key });
1682
+ if (pairing.name) {
1683
+ fragment.set("n", pairing.name);
1684
+ }
1685
+ return `${pairing.relay}${RELAY_PAIR_PATH}#${fragment}`;
1682
1686
  }
1683
- }
1684
- get empty() {
1685
- return [...this.values.keys()].every((key) => key === ALARM);
1686
- }
1687
- async get(key) {
1688
- const value = this.values.get(key);
1689
- return value === undefined ? undefined : structuredClone(value);
1690
- }
1691
- async put(key, value) {
1692
- this.values.set(key, structuredClone(value));
1693
- this.save();
1694
- }
1695
- async delete(key) {
1696
- const had = this.values.delete(key);
1697
- this.save();
1698
- return had;
1699
- }
1700
- async list(options) {
1701
- const found = new Map;
1702
- for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
1703
- if (key !== ALARM && key.startsWith(options.prefix)) {
1704
- found.set(key, structuredClone(value));
1687
+ RelayPairingUtil2.link = link;
1688
+ function parse(link2) {
1689
+ var _a;
1690
+ const url = new URL(link2.trim());
1691
+ const fragment = new URLSearchParams(url.hash.slice(1));
1692
+ const [host, device, key] = ["h", "d", "k"].map((name) => {
1693
+ var _a2;
1694
+ return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
1695
+ });
1696
+ if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_PAIR_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(host) || !RELAY_ID.test(device) || !/^[A-Za-z0-9_-]{43}$/.test(key)) {
1697
+ throw new Error("Not a pairing link of Ta.");
1705
1698
  }
1699
+ return { relay: url.origin, host, device, key, name: (_a = fragment.get("n")) !== null && _a !== undefined ? _a : undefined };
1706
1700
  }
1707
- return found;
1708
- }
1709
- async deleteAll() {
1710
- this.values.clear();
1711
- clearTimeout(this.timer);
1712
- rmSync2(this.dir, { recursive: true, force: true });
1713
- }
1714
- async setAlarm(at) {
1715
- this.values.set(ALARM, at);
1716
- this.save();
1717
- this.schedule(at);
1701
+ RelayPairingUtil2.parse = parse;
1702
+ function websocketUrl(relay, path) {
1703
+ return relay.replace(/^http/, "ws") + path;
1704
+ }
1705
+ RelayPairingUtil2.websocketUrl = websocketUrl;
1706
+ })(RelayPairingUtil || (RelayPairingUtil = {}));
1707
+ });
1708
+
1709
+ // ../../ta-packages/ta-relay/esm/common/relay-cipher.js
1710
+ class RelayCipher {
1711
+ constructor(sendKey, receiveKey) {
1712
+ this.sendKey = sendKey;
1713
+ this.receiveKey = receiveKey;
1714
+ this.compress = false;
1715
+ this.sent = 0;
1716
+ this.received = 0;
1717
+ this.sealing = Promise.resolve();
1718
+ this.opening = Promise.resolve();
1718
1719
  }
1719
- close() {
1720
- clearTimeout(this.timer);
1720
+ static async derive(deviceKey, clientNonce, hostNonce, side) {
1721
+ const subtle2 = globalThis.crypto.subtle;
1722
+ const secret = await subtle2.importKey("raw", deviceKey, "HKDF", false, ["deriveKey"]);
1723
+ const salt = RelayBytes.concat(clientNonce, hostNonce);
1724
+ const key = (direction) => subtle2.deriveKey({ name: "HKDF", hash: "SHA-256", salt, info: encoder2.encode(`ta-relay/1 ${direction}`) }, secret, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
1725
+ const [toHost, toClient] = await Promise.all([key("client-to-host"), key("host-to-client")]);
1726
+ return side === "client" ? new RelayCipher(toHost, toClient) : new RelayCipher(toClient, toHost);
1721
1727
  }
1722
- schedule(at) {
1723
- var _a, _b;
1724
- clearTimeout(this.timer);
1725
- const wait = Math.max(at - Date.now(), 0);
1726
- this.timer = setTimeout(() => {
1727
- var _a2;
1728
- return wait > 2 ** 31 - 1 ? this.schedule(at) : (_a2 = this.onAlarm) === null || _a2 === undefined ? undefined : _a2.call(this);
1729
- }, Math.min(wait, 2 ** 31 - 1));
1730
- (_b = (_a = this.timer).unref) === null || _b === undefined || _b.call(_a);
1728
+ seal(text) {
1729
+ const iv = RelayCipher.iv(this.sent++);
1730
+ const sealed = this.sealing.then(async () => {
1731
+ const data = await globalThis.crypto.subtle.encrypt({ name: "AES-GCM", iv }, this.sendKey, await this.pack(text));
1732
+ return RelayBytes.toBase64(new Uint8Array(data));
1733
+ });
1734
+ this.sealing = sealed.catch(() => {
1735
+ return;
1736
+ });
1737
+ return sealed;
1731
1738
  }
1732
- save() {
1733
- if (this.empty) {
1734
- rmSync2(this.dir, { recursive: true, force: true });
1739
+ open(frame) {
1740
+ const iv = RelayCipher.iv(this.received++);
1741
+ const opened = this.opening.then(async () => {
1742
+ const data = await globalThis.crypto.subtle.decrypt({ name: "AES-GCM", iv }, this.receiveKey, RelayBytes.fromBase64(frame));
1743
+ return this.unpack(new Uint8Array(data));
1744
+ });
1745
+ this.opening = opened.catch(() => {
1735
1746
  return;
1747
+ });
1748
+ return opened;
1749
+ }
1750
+ async pack(text) {
1751
+ const bytes = encoder2.encode(text);
1752
+ if (!this.compress) {
1753
+ return bytes;
1736
1754
  }
1737
- mkdirSync4(this.dir, { recursive: true, mode: 448 });
1738
- const temporary = `${this.file}.${process.pid}.tmp`;
1739
- writeFileSync4(temporary, JSON.stringify(Object.fromEntries([...this.values].map(([key, value]) => [key, encode(value)]))), { mode: 384 });
1740
- renameSync2(temporary, this.file);
1755
+ const deflated = bytes.length >= DEFLATE_MIN_BYTES ? await RelayDeflate.compress(bytes) : undefined;
1756
+ return deflated && deflated.length < bytes.length ? RelayBytes.concat(Uint8Array.of(DEFLATED), deflated) : RelayBytes.concat(Uint8Array.of(PLAIN), bytes);
1741
1757
  }
1742
- static load(file) {
1743
- try {
1744
- const data = JSON.parse(readFileSync5(file, "utf8"));
1745
- return new Map(Object.entries(data).map(([key, stored]) => [key, decode(stored)]));
1746
- } catch (_a) {
1747
- return new Map;
1758
+ async unpack(bytes) {
1759
+ if (!this.compress) {
1760
+ return decoder2.decode(bytes);
1748
1761
  }
1762
+ const body = bytes.subarray(1);
1763
+ return decoder2.decode(bytes[0] === DEFLATED ? await RelayDeflate.decompress(body) : body);
1764
+ }
1765
+ static iv(counter) {
1766
+ const iv = new Uint8Array(IV_LENGTH);
1767
+ new DataView(iv.buffer).setUint32(IV_LENGTH - 8, Math.floor(counter / 2 ** 32));
1768
+ new DataView(iv.buffer).setUint32(IV_LENGTH - 4, counter >>> 0);
1769
+ return iv;
1749
1770
  }
1750
1771
  }
1751
- var encode = (value) => value instanceof Uint8Array ? { b: RelayBytes.toBase64(value) } : { j: value }, decode = (stored) => ("b" in stored) ? RelayBytes.fromBase64(stored.b) : stored.j, ALARM = "\x00alarm";
1752
- var init_relay_file_storage = __esm(() => {
1772
+ var encoder2, decoder2, IV_LENGTH = 12, PLAIN = 0, DEFLATED = 1, DEFLATE_MIN_BYTES = 1024, RelayDeflate;
1773
+ var init_relay_cipher = __esm(() => {
1753
1774
  init_relay_bytes();
1754
- });
1755
-
1756
- // ../../ta-packages/ta-relay/esm/node/relay-viewer.js
1757
- import { fileURLToPath as __cellFileURLToPath3 } from "node:url";
1758
- import { dirname as __cellDirname3 } from "node:path";
1759
- import { readFileSync as readFileSync6 } from "node:fs";
1760
- import { join as join6 } from "node:path";
1761
- var __filename4, __dirname4, RelayViewer;
1762
- var init_relay_viewer = __esm(() => {
1763
- __filename4 = __cellFileURLToPath3(import.meta.url);
1764
- __dirname4 = __cellDirname3(__filename4);
1765
- (function(RelayViewer2) {
1766
- let pages;
1767
- function read() {
1768
- if (!pages) {
1769
- const dir = join6(__dirname4, "../../viewer");
1770
- const file = (name) => readFileSync6(join6(dir, name), "utf8");
1771
- pages = { page: file("page.html"), frame: file("frame.html"), room: file("room.html") };
1775
+ encoder2 = new TextEncoder;
1776
+ decoder2 = new TextDecoder;
1777
+ (function(RelayDeflate2) {
1778
+ let support;
1779
+ function supported() {
1780
+ if (support === undefined) {
1781
+ try {
1782
+ new CompressionStream("deflate-raw");
1783
+ new DecompressionStream("deflate-raw");
1784
+ support = true;
1785
+ } catch (_a) {
1786
+ support = false;
1787
+ }
1772
1788
  }
1773
- return pages;
1789
+ return support;
1774
1790
  }
1775
- function room() {
1776
- return read().room;
1791
+ RelayDeflate2.supported = supported;
1792
+ function compress(bytes) {
1793
+ return through(bytes, new CompressionStream("deflate-raw"));
1777
1794
  }
1778
- RelayViewer2.room = room;
1779
- function page() {
1780
- return read().page;
1795
+ RelayDeflate2.compress = compress;
1796
+ function decompress(bytes) {
1797
+ return through(bytes, new DecompressionStream("deflate-raw"));
1781
1798
  }
1782
- RelayViewer2.page = page;
1783
- function frame() {
1784
- return read().frame;
1799
+ RelayDeflate2.decompress = decompress;
1800
+ async function through(bytes, stream) {
1801
+ const piped = new Blob([bytes]).stream().pipeThrough(stream);
1802
+ return new Uint8Array(await new Response(piped).arrayBuffer());
1785
1803
  }
1786
- RelayViewer2.frame = frame;
1787
- })(RelayViewer || (RelayViewer = {}));
1788
- });
1789
-
1790
- // ../../ta-packages/ta-relay/esm/node/relay-server.js
1791
- var exports_relay_server = {};
1792
- __export(exports_relay_server, {
1793
- RelayServer: () => RelayServer
1804
+ })(RelayDeflate || (RelayDeflate = {}));
1794
1805
  });
1795
- import { createHash as createHash2, randomBytes, timingSafeEqual } from "node:crypto";
1796
- import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, renameSync as renameSync3, writeFileSync as writeFileSync5 } from "node:fs";
1797
- import { createServer as createServer2 } from "node:http";
1798
- import { join as join7 } from "node:path";
1799
-
1800
- class MemoryBlobStorage {
1801
- constructor() {
1802
- this.values = new Map;
1803
- }
1804
- async get(key) {
1805
- return this.values.get(key);
1806
- }
1807
- async put(key, value) {
1808
- this.values.set(key, value);
1809
- }
1810
- async deleteAll() {
1811
- this.values.clear();
1812
- clearTimeout(this.timer);
1813
- }
1814
- get empty() {
1815
- return this.values.size === 0;
1816
- }
1817
- async setAlarm(at) {
1818
- var _a, _b;
1819
- clearTimeout(this.timer);
1820
- this.timer = setTimeout(() => this.values.clear(), Math.min(Math.max(at - Date.now(), 0), 2 ** 31 - 1));
1821
- (_b = (_a = this.timer).unref) === null || _b === undefined || _b.call(_a);
1822
- }
1823
- }
1824
1806
 
1825
- class MemoryHubStorage {
1826
- constructor() {
1827
- this.values = new Map;
1828
- }
1829
- async get(key) {
1830
- const value = this.values.get(key);
1831
- return value === undefined ? undefined : structuredClone(value);
1807
+ // ../../ta-packages/ta-relay/esm/common/relay-socket.js
1808
+ class RelaySocket {
1809
+ constructor(pairing, options = {}) {
1810
+ var _a;
1811
+ this.pairing = pairing;
1812
+ this.options = options;
1813
+ this.onopen = null;
1814
+ this.onmessage = null;
1815
+ this.onclose = null;
1816
+ this.onerror = null;
1817
+ this.state = CONNECTING;
1818
+ this.nonce = RelayBytes.random(16);
1819
+ this.ponged = false;
1820
+ this.awaitingPong = false;
1821
+ this.receiving = Promise.resolve();
1822
+ this.socket = new WebSocket(RelayPairingUtil.websocketUrl(pairing.relay, RELAY_CONNECT_PATH + pairing.host));
1823
+ this.helloTimer = setTimeout(() => this.drop(RelayCloseCode.TIMEOUT, "The host did not answer."), (_a = options.helloMs) !== null && _a !== undefined ? _a : HELLO_MS);
1824
+ this.socket.onopen = () => {
1825
+ var _a2;
1826
+ const hello = {
1827
+ t: "hello",
1828
+ v: 1,
1829
+ device: pairing.device,
1830
+ nonce: RelayBytes.toBase64(this.nonce),
1831
+ ...RelayDeflate.supported() ? { z: 1 } : {}
1832
+ };
1833
+ this.socket.send(JSON.stringify(hello));
1834
+ this.pingTimer = setInterval(() => this.ping(), (_a2 = options.pingMs) !== null && _a2 !== undefined ? _a2 : RELAY_PING_MS);
1835
+ };
1836
+ this.socket.onmessage = (message) => {
1837
+ const text = String(message.data);
1838
+ if (text === RELAY_PONG) {
1839
+ this.ponged = true;
1840
+ this.awaitingPong = false;
1841
+ return;
1842
+ }
1843
+ this.receiving = this.receiving.then(() => this.receive(text));
1844
+ };
1845
+ this.socket.onerror = (event) => {
1846
+ var _a2;
1847
+ return (_a2 = this.onerror) === null || _a2 === undefined ? undefined : _a2.call(this, event);
1848
+ };
1849
+ this.socket.onclose = (event) => void this.receiving.then(() => this.finish(event.code, event.reason));
1832
1850
  }
1833
- async put(key, value) {
1834
- this.values.set(key, structuredClone(value));
1851
+ get readyState() {
1852
+ return this.state;
1835
1853
  }
1836
- async delete(key) {
1837
- return this.values.delete(key);
1854
+ get closeCode() {
1855
+ return this.code;
1838
1856
  }
1839
- async list(options) {
1840
- const found = new Map;
1841
- for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
1842
- if (key.startsWith(options.prefix)) {
1843
- found.set(key, structuredClone(value));
1844
- }
1857
+ send(text) {
1858
+ if (this.state !== OPEN || !this.cipher) {
1859
+ throw new Error("The connection is not open.");
1845
1860
  }
1846
- return found;
1847
- }
1848
- async deleteAll() {
1849
- this.values.clear();
1861
+ this.cipher.seal(text).then((frame) => this.socket.readyState === OPEN && this.socket.send(frame));
1850
1862
  }
1851
- get empty() {
1852
- return this.values.size === 0;
1863
+ close(code = 1000, reason = "") {
1864
+ if (this.state === CLOSED) {
1865
+ return;
1866
+ }
1867
+ this.state = CLOSING;
1868
+ this.socket.close(code, reason);
1853
1869
  }
1854
- }
1855
-
1856
- class RelayServer {
1857
- constructor(options = {}) {
1858
- this.options = options;
1859
- this.rooms = new Map;
1860
- this.blobs = new Map;
1861
- this.claims = new Map;
1862
- this.hubs = new Map;
1863
- this.spots = new Map;
1864
- this.spotTries = new Map;
1865
- this.spotAddresses = new WeakMap;
1866
- if (options.data) {
1867
- mkdirSync5(options.data, { recursive: true, mode: 448 });
1870
+ async receive(text) {
1871
+ var _a, _b;
1872
+ if (this.cipher) {
1873
+ if (this.options.proveFirst && text.startsWith("{")) {
1874
+ this.drop(RelaySocket.REFUSED, RelaySocket.refusal(text));
1875
+ return;
1876
+ }
1868
1877
  try {
1869
- for (const [id, hash] of Object.entries(JSON.parse(readFileSync7(this.claimsFile(), "utf8")))) {
1870
- this.claims.set(id, hash);
1871
- }
1872
- } catch (_a) {}
1873
- for (const id of FileRelayStorage.ids(join7(options.data, "blobs"))) {
1874
- this.blobCopy(id);
1878
+ const data = await this.cipher.open(text);
1879
+ (_a = this.onmessage) === null || _a === undefined || _a.call(this, { data });
1880
+ } catch (_c) {
1881
+ this.close(4400, "A message did not open.");
1875
1882
  }
1876
- for (const id of FileRelayStorage.ids(join7(options.data, "hubs"))) {
1877
- this.hubOf(id);
1883
+ return;
1884
+ }
1885
+ try {
1886
+ const welcome = JSON.parse(text);
1887
+ if (welcome.t !== "ready") {
1888
+ this.drop(RelaySocket.REFUSED, this.options.proveFirst ? RelaySocket.refusal(text) : "The host refused this device.");
1889
+ return;
1890
+ }
1891
+ const cipher = await RelayCipher.derive(RelayBytes.fromBase64(this.pairing.key), this.nonce, RelayBytes.fromBase64(welcome.nonce), "client");
1892
+ if (welcome.proof === undefined && this.options.proveFirst) {
1893
+ this.socket.send(await cipher.seal(RELAY_PROOF));
1894
+ } else if (welcome.proof === undefined || await cipher.open(welcome.proof) !== RELAY_PROOF) {
1895
+ throw new Error("The host did not show the key.");
1878
1896
  }
1897
+ cipher.compress = welcome.z === 1 && RelayDeflate.supported();
1898
+ this.cipher = cipher;
1899
+ clearTimeout(this.helloTimer);
1900
+ this.state = OPEN;
1901
+ (_b = this.onopen) === null || _b === undefined || _b.call(this);
1902
+ } catch (_d) {
1903
+ this.drop(RelaySocket.REFUSED, "The host refused this device.");
1879
1904
  }
1880
1905
  }
1881
- listen() {
1882
- const server = createServer2((request, response) => {
1906
+ static refusal(text) {
1907
+ try {
1908
+ const reason = JSON.parse(text).reason;
1909
+ return reason === "key" || reason === "busy" ? reason : "gone";
1910
+ } catch (_a) {
1911
+ return "gone";
1912
+ }
1913
+ }
1914
+ ping() {
1915
+ if (this.awaitingPong && this.ponged) {
1916
+ this.drop(RelayCloseCode.TIMEOUT, "The relay did not answer.");
1917
+ return;
1918
+ }
1919
+ this.awaitingPong = true;
1920
+ if (this.socket.readyState === OPEN) {
1921
+ this.socket.send(RELAY_PING);
1922
+ }
1923
+ }
1924
+ drop(code, reason) {
1925
+ this.close(code, reason);
1926
+ this.finish(code, reason);
1927
+ }
1928
+ finish(code, reason) {
1929
+ var _a;
1930
+ if (this.state === CLOSED) {
1931
+ return;
1932
+ }
1933
+ clearTimeout(this.helloTimer);
1934
+ clearInterval(this.pingTimer);
1935
+ this.state = CLOSED;
1936
+ this.code = code;
1937
+ (_a = this.onclose) === null || _a === undefined || _a.call(this, { code, reason });
1938
+ }
1939
+ }
1940
+ var CONNECTING = 0, OPEN = 1, CLOSING = 2, CLOSED = 3, HELLO_MS = 15000;
1941
+ var init_relay_socket = __esm(() => {
1942
+ init_relay_bytes();
1943
+ init_relay_cipher();
1944
+ init_relay_pairing();
1945
+ init_relay_protocol();
1946
+ RelaySocket.CONNECTING = CONNECTING;
1947
+ RelaySocket.OPEN = OPEN;
1948
+ RelaySocket.CLOSING = CLOSING;
1949
+ RelaySocket.CLOSED = CLOSED;
1950
+ RelaySocket.REFUSED = 4403;
1951
+ });
1952
+
1953
+ // ../../ta-packages/ta-relay/esm/common/relay-host-calls.js
1954
+ var init_relay_host_calls = __esm(() => {
1955
+ init_relay_pairing();
1956
+ init_relay_socket();
1957
+ });
1958
+
1959
+ // ../../ta-packages/ta-relay/esm/common/relay-team.js
1960
+ var RELAY_JOIN_PATH = "/j", RELAY_WEB_PATH = "/w/", SEAL_INFO = "ta-team/1 device", RelayTeamSeal, RelayTeamLinkUtil;
1961
+ var init_relay_team = __esm(() => {
1962
+ init_relay_bytes();
1963
+ init_relay_host_calls();
1964
+ init_relay_identity();
1965
+ init_relay_pairing();
1966
+ (function(RelayTeamSeal2) {
1967
+ function keys(name) {
1968
+ return RelayIdentityUtil.create(name);
1969
+ }
1970
+ RelayTeamSeal2.keys = keys;
1971
+ async function seal(box, salt, text) {
1972
+ const own = await RelayIdentityUtil.create("ta");
1973
+ const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(own, box, salt, SEAL_INFO));
1974
+ return { box: own.box, sealed: await RelayKeys.seal(key, text) };
1975
+ }
1976
+ RelayTeamSeal2.seal = seal;
1977
+ async function open(keys2, answer, salt) {
1978
+ const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(keys2, answer.box, salt, SEAL_INFO));
1979
+ return RelayKeys.open(key, answer.sealed);
1980
+ }
1981
+ RelayTeamSeal2.open = open;
1982
+ function isKey(box) {
1983
+ return typeof box === "string" && /^[A-Za-z0-9_-]{80,100}$/.test(box) && RelayBytes.fromBase64(box).length === 65;
1984
+ }
1985
+ RelayTeamSeal2.isKey = isKey;
1986
+ })(RelayTeamSeal || (RelayTeamSeal = {}));
1987
+ (function(RelayTeamLinkUtil2) {
1988
+ const ID = /^[A-Za-z0-9_-]{16,64}$/;
1989
+ function format(link) {
1990
+ const fragment = new URLSearchParams({ v: "1", h: link.host, d: link.device, k: link.key, o: link.owner, r: link.role });
1991
+ if (link.what) {
1992
+ fragment.set("w", link.what);
1993
+ }
1994
+ return `${link.relay.replace(/\/+$/, "")}${RELAY_JOIN_PATH}#${fragment}`;
1995
+ }
1996
+ RelayTeamLinkUtil2.format = format;
1997
+ function parse(text) {
1883
1998
  var _a;
1884
- const path = ((_a = request.url) !== null && _a !== undefined ? _a : "/").split(/[?#]/)[0];
1885
- if (path === RELAY_INFO_PATH) {
1886
- const info = RelayInfoUtil.of(!!this.options.data);
1887
- response.writeHead(200, { "content-type": "application/json", "access-control-allow-origin": "*", "cache-control": "no-store" });
1888
- response.end(JSON.stringify(info));
1999
+ var _b, _c;
2000
+ let url;
2001
+ try {
2002
+ url = new URL(text.trim());
2003
+ } catch (_d) {
1889
2004
  return;
1890
2005
  }
1891
- if (path.startsWith(RELAY_BLOB_PATH)) {
1892
- this.blob(path.slice(RELAY_BLOB_PATH.length), request, response).catch(() => {
1893
- if (!response.headersSent) {
1894
- response.writeHead(400);
1895
- }
1896
- response.end();
1897
- });
2006
+ const fragment = new URLSearchParams(url.hash.slice(1));
2007
+ const [host, device, key] = ["h", "d", "k"].map((name) => {
2008
+ var _a2;
2009
+ return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
2010
+ });
2011
+ if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_JOIN_PATH || fragment.get("v") !== "1" || !ID.test(host) || !ID.test(device) || !/^[A-Za-z0-9_-]{43}$/.test(key)) {
1898
2012
  return;
1899
2013
  }
1900
- if (path === RELAY_ROOM_PATH) {
1901
- response.writeHead(200, { ...RELAY_VIEWER_HEADERS, "x-frame-options": "DENY" });
1902
- response.end(RelayViewer.room());
2014
+ const what = (_a = fragment.get("w")) === null || _a === undefined ? undefined : _a.slice(0, 80);
2015
+ return { relay: url.origin, host, device, key, owner: (_b = fragment.get("o")) !== null && _b !== undefined ? _b : "", role: (_c = fragment.get("r")) !== null && _c !== undefined ? _c : "", ...what ? { what } : {} };
2016
+ }
2017
+ RelayTeamLinkUtil2.parse = parse;
2018
+ function signInFor(link, provider, handoff) {
2019
+ return `${format(link)}&${new URLSearchParams({ p: provider, x: handoff })}`;
2020
+ }
2021
+ RelayTeamLinkUtil2.signInFor = signInFor;
2022
+ function handoffOf(text) {
2023
+ var _a, _b;
2024
+ let url;
2025
+ try {
2026
+ url = new URL(text.trim());
2027
+ } catch (_c) {
1903
2028
  return;
1904
2029
  }
1905
- if (path === RELAY_CONTENT_PATH || path === RELAY_FRAME_PATH) {
1906
- const frame = path === RELAY_FRAME_PATH;
1907
- response.writeHead(200, {
1908
- ...RELAY_VIEWER_HEADERS,
1909
- ...frame ? { "content-security-policy": RELAY_FRAME_HEADER_CSP } : { "x-frame-options": "DENY" }
1910
- });
1911
- response.end(frame ? RelayViewer.frame() : RelayViewer.page());
2030
+ const fragment = new URLSearchParams(url.hash.slice(1));
2031
+ const provider = (_a = fragment.get("p")) !== null && _a !== undefined ? _a : "";
2032
+ const handoff = (_b = fragment.get("x")) !== null && _b !== undefined ? _b : "";
2033
+ return /^[a-z0-9_-]{1,32}$/.test(provider) && /^[A-Za-z0-9_-]{16,64}$/.test(handoff) ? { provider, handoff } : undefined;
2034
+ }
2035
+ RelayTeamLinkUtil2.handoffOf = handoffOf;
2036
+ function web(relay, pairing) {
2037
+ return `${relay.replace(/\/+$/, "")}${RELAY_WEB_PATH}#${new URLSearchParams({ pair: pairing })}`;
2038
+ }
2039
+ RelayTeamLinkUtil2.web = web;
2040
+ })(RelayTeamLinkUtil || (RelayTeamLinkUtil = {}));
2041
+ });
2042
+
2043
+ // ../../ta-packages/ta-relay/esm/common/relay-web.js
2044
+ var TYPES, RelayWebUtil;
2045
+ var init_relay_web = __esm(() => {
2046
+ init_relay_team();
2047
+ TYPES = {
2048
+ html: "text/html; charset=utf-8",
2049
+ js: "text/javascript; charset=utf-8",
2050
+ mjs: "text/javascript; charset=utf-8",
2051
+ css: "text/css; charset=utf-8",
2052
+ json: "application/json",
2053
+ webmanifest: "application/manifest+json",
2054
+ svg: "image/svg+xml",
2055
+ png: "image/png",
2056
+ jpg: "image/jpeg",
2057
+ webp: "image/webp",
2058
+ ico: "image/x-icon",
2059
+ woff2: "font/woff2",
2060
+ woff: "font/woff",
2061
+ ttf: "font/ttf",
2062
+ wasm: "application/wasm",
2063
+ txt: "text/plain; charset=utf-8"
2064
+ };
2065
+ (function(RelayWebUtil2) {
2066
+ function index(html) {
2067
+ return html.replace(/<base href="\/">/, `<base href="${RELAY_WEB_PATH}">`);
2068
+ }
2069
+ RelayWebUtil2.index = index;
2070
+ function file(path) {
2071
+ if (!path.startsWith(RELAY_WEB_PATH)) {
1912
2072
  return;
1913
2073
  }
1914
- const page = path === RELAY_PAIR_PATH ? RELAY_PAIR_PAGE : path === RELAY_SHARE_PATH ? RELAY_SHARE_PAGE : undefined;
1915
- response.writeHead(200, { "content-type": page ? "text/html; charset=utf-8" : "text/plain" });
1916
- response.end(page !== null && page !== undefined ? page : `Ta relay
1917
- `);
1918
- });
1919
- server.on("upgrade", (request, socket, head) => this.upgrade(request, socket, head));
1920
- this.server = server;
1921
- return new Promise((resolve2, reject) => {
1922
- var _a, _b;
1923
- server.once("error", reject);
1924
- server.listen((_a = this.options.port) !== null && _a !== undefined ? _a : 0, (_b = this.options.host) !== null && _b !== undefined ? _b : "127.0.0.1", () => {
1925
- const { address, port } = server.address();
1926
- resolve2(`http://${address.includes(":") ? `[${address}]` : address}:${port}`);
1927
- });
1928
- });
1929
- }
1930
- close() {
1931
- var _a, _b, _c, _d, _e;
1932
- for (const { sockets } of this.hubs.values()) {
1933
- for (const connection of sockets.keys()) {
1934
- connection.close(1001, "The relay is stopping.");
2074
+ const rest = path.slice(RELAY_WEB_PATH.length) || "index.html";
2075
+ const parts = rest.split("/");
2076
+ if (parts.some((part) => !part || part === "." || part === ".." || !/^[\w.@-]+$/.test(part))) {
2077
+ return;
1935
2078
  }
2079
+ return rest;
1936
2080
  }
1937
- for (const { storage } of this.hubs.values()) {
1938
- (_b = (_a = storage).close) === null || _b === undefined || _b.call(_a);
2081
+ RelayWebUtil2.file = file;
2082
+ function headers(file2) {
2083
+ var _a;
2084
+ const type = (_a = TYPES[file2.slice(file2.lastIndexOf(".") + 1).toLowerCase()]) !== null && _a !== undefined ? _a : "application/octet-stream";
2085
+ const page = file2 === "index.html";
2086
+ return {
2087
+ "content-type": type,
2088
+ "cache-control": file2.startsWith("assets/") ? "public, max-age=31536000, immutable, no-transform" : "no-cache, no-transform",
2089
+ "x-content-type-options": "nosniff",
2090
+ "referrer-policy": "no-referrer",
2091
+ ...page ? { "x-frame-options": "DENY" } : {}
2092
+ };
1939
2093
  }
1940
- for (const { storage } of this.blobs.values()) {
1941
- (_d = (_c = storage).close) === null || _d === undefined || _d.call(_c);
1942
- }
1943
- this.hubs.clear();
1944
- for (const { sockets } of this.spots.values()) {
1945
- for (const connection of sockets.keys()) {
1946
- connection.close(1001, "The relay is stopping.");
1947
- }
1948
- }
1949
- this.spots.clear();
1950
- for (const room of this.rooms.values()) {
1951
- (_e = room.host) === null || _e === undefined || _e.close(1001, "The relay is stopping.");
1952
- for (const client of room.clients.values()) {
1953
- client.close(1001, "The relay is stopping.");
1954
- }
2094
+ RelayWebUtil2.headers = headers;
2095
+ })(RelayWebUtil || (RelayWebUtil = {}));
2096
+ });
2097
+
2098
+ // ../../ta-packages/ta-relay/esm/node/relay-file-storage.js
2099
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync5, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
2100
+ import { join as join5 } from "node:path";
2101
+
2102
+ class FileRelayStorage {
2103
+ constructor(dir, onAlarm) {
2104
+ this.dir = dir;
2105
+ this.onAlarm = onAlarm;
2106
+ this.file = join5(dir, "values.json");
2107
+ this.values = FileRelayStorage.load(this.file);
2108
+ const alarm = this.values.get(ALARM);
2109
+ if (typeof alarm === "number") {
2110
+ this.schedule(alarm);
1955
2111
  }
1956
- this.rooms.clear();
1957
- return new Promise((resolve2) => this.server ? this.server.close(() => resolve2()) : resolve2());
1958
2112
  }
1959
- async blob(id, request, response) {
1960
- var _a;
1961
- if (!RELAY_ID.test(id)) {
1962
- response.writeHead(404).end();
1963
- return;
1964
- }
1965
- const read = await RelayServer.body(request, RelayBlobs.MAX_BYTES);
1966
- if (!read) {
1967
- response.writeHead(413, { connection: "close" }).end(`Too large.
1968
- `);
1969
- return;
1970
- }
1971
- const copy = this.blobCopy(id);
1972
- const headers = new Headers;
1973
- for (const [name, value] of Object.entries(request.headers)) {
1974
- if (typeof value === "string") {
1975
- headers.set(name, value);
1976
- }
1977
- }
1978
- const method = (_a = request.method) !== null && _a !== undefined ? _a : "GET";
1979
- const body = read.length && method !== "GET" && method !== "HEAD" ? read : undefined;
1980
- copy.pending++;
1981
- let answer;
2113
+ static ids(root) {
1982
2114
  try {
1983
- answer = await copy.blobs.handle(new Request(`http://relay${request.url}`, { method, headers, body }));
1984
- } finally {
1985
- copy.pending--;
1986
- if (copy.pending === 0 && copy.storage.empty && this.blobs.get(id) === copy) {
1987
- this.blobs.delete(id);
1988
- }
2115
+ return readdirSync2(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
2116
+ } catch (_a) {
2117
+ return [];
1989
2118
  }
1990
- response.writeHead(answer.status, Object.fromEntries(answer.headers));
1991
- response.end(Buffer.from(await answer.arrayBuffer()));
1992
2119
  }
1993
- blobCopy(id) {
1994
- let copy = this.blobs.get(id);
1995
- if (!copy) {
1996
- const data = this.options.data;
1997
- const made = { pending: 0 };
1998
- const storage = data ? new FileRelayStorage(join7(data, "blobs", id), () => {
1999
- var _a;
2000
- (_a = made.storage) === null || _a === undefined || _a.deleteAll().then(() => this.blobs.get(id) === copy && this.blobs.delete(id));
2001
- }) : new MemoryBlobStorage;
2002
- made.storage = storage;
2003
- made.blobs = new RelayBlobs(storage);
2004
- copy = made;
2005
- this.blobs.set(id, copy);
2006
- }
2007
- return copy;
2120
+ get empty() {
2121
+ return [...this.values.keys()].every((key) => key === ALARM);
2008
2122
  }
2009
- claimsFile() {
2010
- return join7(this.options.data, "hosts.json");
2123
+ async get(key) {
2124
+ const value = this.values.get(key);
2125
+ return value === undefined ? undefined : structuredClone(value);
2011
2126
  }
2012
- saveClaims() {
2013
- if (!this.options.data) {
2014
- return;
2127
+ async put(key, value) {
2128
+ this.values.set(key, structuredClone(value));
2129
+ this.save();
2130
+ }
2131
+ async delete(key) {
2132
+ const had = this.values.delete(key);
2133
+ this.save();
2134
+ return had;
2135
+ }
2136
+ async list(options) {
2137
+ const found = new Map;
2138
+ for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
2139
+ if (key !== ALARM && key.startsWith(options.prefix)) {
2140
+ found.set(key, structuredClone(value));
2141
+ }
2015
2142
  }
2016
- const file = this.claimsFile();
2017
- writeFileSync5(`${file}.tmp`, JSON.stringify(Object.fromEntries(this.claims)), { mode: 384 });
2018
- renameSync3(`${file}.tmp`, file);
2143
+ return found;
2019
2144
  }
2020
- static body(request, max) {
2021
- return new Promise((resolve2, reject) => {
2022
- const chunks = [];
2023
- let size = 0;
2024
- request.on("data", (chunk) => {
2025
- if (size < 0) {
2026
- return;
2027
- }
2028
- size += chunk.length;
2029
- if (size > max) {
2030
- size = -1;
2031
- chunks.length = 0;
2032
- resolve2(undefined);
2033
- return;
2034
- }
2035
- chunks.push(chunk);
2036
- });
2037
- request.on("end", () => size >= 0 && resolve2(Buffer.concat(chunks)));
2038
- request.on("error", reject);
2039
- });
2145
+ async deleteAll() {
2146
+ this.values.clear();
2147
+ clearTimeout(this.timer);
2148
+ rmSync2(this.dir, { recursive: true, force: true });
2040
2149
  }
2041
- upgrade(request, socket, head) {
2042
- var _a, _b, _c;
2043
- const url = new URL((_a = request.url) !== null && _a !== undefined ? _a : "/", "http://relay");
2044
- const checked = WebSocketConnection.check(request);
2045
- if ("status" in checked) {
2046
- WebSocketConnection.refuse(socket, checked.status, checked.message);
2150
+ async setAlarm(at) {
2151
+ this.values.set(ALARM, at);
2152
+ this.save();
2153
+ this.schedule(at);
2154
+ }
2155
+ close() {
2156
+ clearTimeout(this.timer);
2157
+ }
2158
+ schedule(at) {
2159
+ var _a, _b;
2160
+ clearTimeout(this.timer);
2161
+ const wait = Math.max(at - Date.now(), 0);
2162
+ this.timer = setTimeout(() => {
2163
+ var _a2;
2164
+ return wait > 2 ** 31 - 1 ? this.schedule(at) : (_a2 = this.onAlarm) === null || _a2 === undefined ? undefined : _a2.call(this);
2165
+ }, Math.min(wait, 2 ** 31 - 1));
2166
+ (_b = (_a = this.timer).unref) === null || _b === undefined || _b.call(_a);
2167
+ }
2168
+ save() {
2169
+ if (this.empty) {
2170
+ rmSync2(this.dir, { recursive: true, force: true });
2047
2171
  return;
2048
2172
  }
2049
- if (url.pathname.startsWith(RELAY_HUB_PATH)) {
2050
- const id2 = url.pathname.slice(RELAY_HUB_PATH.length);
2051
- if (!RELAY_ID.test(id2)) {
2052
- WebSocketConnection.refuse(socket, 404, "Not found.");
2053
- return;
2054
- }
2055
- this.openHub(id2, WebSocketConnection.open(socket, checked.key, head, WEBSOCKET));
2056
- return;
2173
+ mkdirSync4(this.dir, { recursive: true, mode: 448 });
2174
+ const temporary = `${this.file}.${process.pid}.tmp`;
2175
+ writeFileSync4(temporary, JSON.stringify(Object.fromEntries([...this.values].map(([key, value]) => [key, encode(value)]))), { mode: 384 });
2176
+ renameSync2(temporary, this.file);
2177
+ }
2178
+ static load(file) {
2179
+ try {
2180
+ const data = JSON.parse(readFileSync5(file, "utf8"));
2181
+ return new Map(Object.entries(data).map(([key, stored]) => [key, decode(stored)]));
2182
+ } catch (_a) {
2183
+ return new Map;
2057
2184
  }
2058
- if (url.pathname.startsWith(RELAY_SPOT_PATH)) {
2059
- const id2 = url.pathname.slice(RELAY_SPOT_PATH.length);
2060
- if (!RELAY_ID.test(id2)) {
2061
- WebSocketConnection.refuse(socket, 404, "Not found.");
2062
- return;
2063
- }
2064
- const address = RelaySpotTries.keyOf(request.socket.remoteAddress);
2065
- const connection2 = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
2066
- const fails = RelaySpotTries.recent((_b = this.spotTries.get(address)) !== null && _b !== undefined ? _b : [], Date.now());
2067
- if (RelaySpotTries.blocked(fails, Date.now())) {
2068
- connection2.close(RelaySpotCloseCode.TRIES, "Too many codes tried.");
2069
- return;
2185
+ }
2186
+ }
2187
+ var encode = (value) => value instanceof Uint8Array ? { b: RelayBytes.toBase64(value) } : { j: value }, decode = (stored) => ("b" in stored) ? RelayBytes.fromBase64(stored.b) : stored.j, ALARM = "\x00alarm";
2188
+ var init_relay_file_storage = __esm(() => {
2189
+ init_relay_bytes();
2190
+ });
2191
+
2192
+ // ../../ta-packages/ta-relay/esm/node/relay-viewer.js
2193
+ import { fileURLToPath as __cellFileURLToPath3 } from "node:url";
2194
+ import { dirname as __cellDirname3 } from "node:path";
2195
+ import { readFileSync as readFileSync6 } from "node:fs";
2196
+ import { join as joinPath } from "node:path";
2197
+ var __filename4, __dirname4, RelayViewer;
2198
+ var init_relay_viewer = __esm(() => {
2199
+ __filename4 = __cellFileURLToPath3(import.meta.url);
2200
+ __dirname4 = __cellDirname3(__filename4);
2201
+ (function(RelayViewer2) {
2202
+ let pages;
2203
+ function read() {
2204
+ if (!pages) {
2205
+ const dir = joinPath(__dirname4, "../../viewer");
2206
+ const file = (name) => readFileSync6(joinPath(dir, name), "utf8");
2207
+ pages = { page: file("page.html"), frame: file("frame.html"), room: file("room.html"), join: file("join.html") };
2070
2208
  }
2071
- this.openSpot(id2, connection2, address);
2072
- return;
2073
- }
2074
- const [path, id] = url.pathname.startsWith(RELAY_HOST_PATH) ? [RELAY_HOST_PATH, url.pathname.slice(RELAY_HOST_PATH.length)] : [RELAY_CONNECT_PATH, url.pathname.slice(RELAY_CONNECT_PATH.length)];
2075
- if (!url.pathname.startsWith(path) || !RELAY_ID.test(id)) {
2076
- WebSocketConnection.refuse(socket, 404, "Not found.");
2077
- return;
2209
+ return pages;
2078
2210
  }
2079
- const connection = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
2080
- if (path === RELAY_HOST_PATH) {
2081
- this.openHost(id, (_c = url.searchParams.get("secret")) !== null && _c !== undefined ? _c : "", connection);
2082
- } else {
2083
- this.openClient(id, connection);
2211
+ function room() {
2212
+ return read().room;
2084
2213
  }
2085
- }
2086
- openHost(id, secret, connection) {
2087
- var _a, _b;
2088
- const hash = createHash2("sha256").update(secret).digest("base64url");
2089
- if (secret.length >= 32 && !this.claims.has(id) && this.options.data) {
2090
- this.claims.set(id, hash);
2091
- this.saveClaims();
2214
+ RelayViewer2.room = room;
2215
+ function join6() {
2216
+ return read().join;
2092
2217
  }
2093
- const room = (_a = this.rooms.get(id)) !== null && _a !== undefined ? _a : this.createRoom(id, (_b = this.claims.get(id)) !== null && _b !== undefined ? _b : hash);
2094
- if (secret.length < 32 || !RelayServer.same(room.secretHash, hash)) {
2095
- connection.close(RelayCloseCode.REFUSED, "Refused.");
2096
- return;
2218
+ RelayViewer2.join = join6;
2219
+ function page() {
2220
+ return read().page;
2097
2221
  }
2098
- if (room.host) {
2099
- room.host.close(RelayCloseCode.REPLACED, "The host connected again.");
2100
- room.relay.hostClosed();
2222
+ RelayViewer2.page = page;
2223
+ function frame() {
2224
+ return read().frame;
2101
2225
  }
2102
- room.host = connection;
2103
- connection.onMessage((text) => room.relay.fromHost(text));
2104
- connection.onClose(() => {
2105
- if (room.host === connection) {
2106
- room.host = undefined;
2107
- room.relay.hostClosed();
2108
- }
2109
- });
2110
- }
2111
- openClient(id, connection) {
2112
- const room = this.rooms.get(id);
2113
- const channel = randomBytes(9).toString("base64url");
2114
- room === null || room === undefined || room.clients.set(channel, connection);
2115
- const refused = room ? room.relay.clientOpened(channel) : RelayCloseCode.HOST_OFFLINE;
2116
- if (!room || refused !== undefined) {
2117
- room === null || room === undefined || room.clients.delete(channel);
2118
- connection.close(refused !== null && refused !== undefined ? refused : RelayCloseCode.HOST_OFFLINE, "The host is not available.");
2119
- return;
2120
- }
2121
- connection.onMessage((text) => room.relay.fromClient(channel, text));
2122
- connection.onClose(() => {
2123
- if (room.clients.delete(channel)) {
2124
- room.relay.clientClosed(channel);
2125
- }
2126
- });
2127
- }
2128
- openSpot(id, connection, address) {
2129
- let current = this.spots.get(id);
2130
- if (!current) {
2131
- const sockets2 = new Map;
2132
- const socketOf = (other) => ({
2133
- key: other,
2134
- get who() {
2135
- var _a;
2136
- return (_a = sockets2.get(other)) === null || _a === undefined ? undefined : _a.who;
2137
- },
2138
- set who(who) {
2139
- const state = sockets2.get(other);
2140
- if (state) {
2141
- state.who = who;
2142
- }
2143
- },
2144
- send: (text) => other.send(text),
2145
- close: (code, reason) => other.close(code, reason)
2146
- });
2147
- const missed = (socket2) => {
2148
- var _a, _b;
2149
- const key = (_a = this.spotAddresses.get(socket2.key)) !== null && _a !== undefined ? _a : "unknown";
2150
- const now = Date.now();
2151
- this.spotTries.set(key, [...RelaySpotTries.recent((_b = this.spotTries.get(key)) !== null && _b !== undefined ? _b : [], now), now]);
2152
- for (const [other, fails] of this.spotTries) {
2153
- if (!RelaySpotTries.recent(fails, now).length) {
2154
- this.spotTries.delete(other);
2155
- }
2156
- }
2157
- };
2158
- current = { sockets: sockets2, socketOf, spot: new RelaySpot(() => [...sockets2.keys()].map(socketOf), Date.now, missed) };
2159
- this.spots.set(id, current);
2160
- }
2161
- const { sockets, spot } = current;
2162
- sockets.set(connection, {});
2163
- this.spotAddresses.set(connection, address);
2164
- const socket = current.socketOf(connection);
2165
- connection.onMessage((text) => spot.receive(socket, text));
2166
- connection.onClose(() => {
2167
- if (sockets.has(connection)) {
2168
- spot.closed(socket);
2169
- sockets.delete(connection);
2170
- }
2171
- if (sockets.size === 0 && this.spots.get(id) === current) {
2172
- this.spots.delete(id);
2173
- }
2174
- });
2226
+ RelayViewer2.frame = frame;
2227
+ })(RelayViewer || (RelayViewer = {}));
2228
+ });
2229
+
2230
+ // ../../ta-packages/ta-relay/esm/node/relay-server.js
2231
+ var exports_relay_server = {};
2232
+ __export(exports_relay_server, {
2233
+ RelayServer: () => RelayServer
2234
+ });
2235
+ import { createHash as createHash2, randomBytes, timingSafeEqual } from "node:crypto";
2236
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, renameSync as renameSync3, statSync, writeFileSync as writeFileSync5 } from "node:fs";
2237
+ import { createServer as createServer2 } from "node:http";
2238
+ import { join as join6 } from "node:path";
2239
+
2240
+ class MemoryBlobStorage {
2241
+ constructor() {
2242
+ this.values = new Map;
2175
2243
  }
2176
- openHub(id, connection) {
2177
- const current = this.hubOf(id);
2178
- const { sockets, hub: relay } = current;
2179
- sockets.set(connection, {});
2180
- let chain = Promise.resolve();
2181
- const socket = {
2182
- key: connection,
2183
- get who() {
2184
- var _a;
2185
- return (_a = sockets.get(connection)) === null || _a === undefined ? undefined : _a.who;
2186
- },
2187
- set who(who) {
2188
- const state = sockets.get(connection);
2189
- if (state) {
2190
- state.who = who;
2191
- }
2192
- },
2193
- send: (text) => connection.send(text),
2194
- close: (code, reason) => connection.close(code, reason)
2195
- };
2196
- connection.onMessage((text) => {
2197
- chain = chain.then(() => relay.receive(socket, text)).catch(() => {
2198
- return;
2199
- });
2200
- });
2201
- connection.onClose(() => {
2202
- chain.then(() => {
2203
- if (sockets.has(connection)) {
2204
- relay.closed(socket);
2205
- sockets.delete(connection);
2206
- }
2207
- this.dropHub(id, current);
2208
- });
2209
- });
2244
+ async get(key) {
2245
+ return this.values.get(key);
2210
2246
  }
2211
- hubOf(id) {
2212
- let hub = this.hubs.get(id);
2213
- if (!hub) {
2214
- const sockets = new Map;
2215
- const socketOf = (other) => {
2216
- var _a;
2217
- const state = (_a = sockets.get(other)) !== null && _a !== undefined ? _a : {};
2218
- return {
2219
- key: other,
2220
- get who() {
2221
- return state.who;
2222
- },
2223
- set who(who) {
2224
- state.who = who;
2225
- },
2226
- send: (text) => other.send(text),
2227
- close: (code, reason) => other.close(code, reason)
2228
- };
2229
- };
2230
- const made = { sockets };
2231
- const storage = this.options.data ? new FileRelayStorage(join7(this.options.data, "hubs", id), () => {
2232
- var _a;
2233
- return void ((_a = made.hub) === null || _a === undefined ? undefined : _a.alarm().then(() => this.dropHub(id, made)));
2234
- }) : new MemoryHubStorage;
2235
- made.storage = storage;
2236
- made.hub = new RelayHub(storage, () => [...sockets.keys()].map(socketOf));
2237
- hub = made;
2238
- this.hubs.set(id, hub);
2239
- }
2240
- return hub;
2247
+ async put(key, value) {
2248
+ this.values.set(key, value);
2241
2249
  }
2242
- dropHub(id, hub) {
2243
- if (hub && hub.sockets.size === 0 && hub.storage.empty && this.hubs.get(id) === hub) {
2244
- this.hubs.delete(id);
2245
- }
2250
+ async deleteAll() {
2251
+ this.values.clear();
2252
+ clearTimeout(this.timer);
2246
2253
  }
2247
- createRoom(id, secretHash) {
2248
- const room = {
2249
- secretHash,
2250
- clients: new Map,
2251
- relay: new RelayRoom({
2252
- host: () => room.host ? peer(room.host) : undefined,
2253
- client: (channel) => {
2254
- const client = room.clients.get(channel);
2255
- return client ? peer(client) : undefined;
2256
- },
2257
- clients: () => [...room.clients.values()].map(peer)
2258
- })
2259
- };
2260
- this.rooms.set(id, room);
2261
- return room;
2254
+ get empty() {
2255
+ return this.values.size === 0;
2262
2256
  }
2263
- static same(a, b) {
2264
- const [left, right] = [Buffer.from(a), Buffer.from(b)];
2265
- return left.length === right.length && timingSafeEqual(left, right);
2257
+ async setAlarm(at) {
2258
+ var _a, _b;
2259
+ clearTimeout(this.timer);
2260
+ this.timer = setTimeout(() => this.values.clear(), Math.min(Math.max(at - Date.now(), 0), 2 ** 31 - 1));
2261
+ (_b = (_a = this.timer).unref) === null || _b === undefined || _b.call(_a);
2266
2262
  }
2267
2263
  }
2268
- var WEBSOCKET, peer = (connection) => ({ send: (text) => connection.send(text), close: (code, reason) => connection.close(code, reason) });
2269
- var init_relay_server = __esm(() => {
2270
- init_websocket_connection();
2271
- init_relay_blobs();
2272
- init_relay_hub();
2273
- init_relay_info();
2274
- init_relay_protocol();
2275
- init_relay_room();
2276
- init_relay_spot();
2277
- init_relay_file_storage();
2278
- init_relay_viewer();
2279
- WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
2280
- });
2281
2264
 
2282
- // ../../ta-packages/ta-relay/esm/common/relay-cipher.js
2283
- class RelayCipher {
2284
- constructor(sendKey, receiveKey) {
2285
- this.sendKey = sendKey;
2286
- this.receiveKey = receiveKey;
2287
- this.compress = false;
2288
- this.sent = 0;
2289
- this.received = 0;
2290
- this.sealing = Promise.resolve();
2291
- this.opening = Promise.resolve();
2265
+ class MemoryHubStorage {
2266
+ constructor() {
2267
+ this.values = new Map;
2292
2268
  }
2293
- static async derive(deviceKey, clientNonce, hostNonce, side) {
2294
- const subtle2 = globalThis.crypto.subtle;
2295
- const secret = await subtle2.importKey("raw", deviceKey, "HKDF", false, ["deriveKey"]);
2296
- const salt = RelayBytes.concat(clientNonce, hostNonce);
2297
- const key = (direction) => subtle2.deriveKey({ name: "HKDF", hash: "SHA-256", salt, info: encoder2.encode(`ta-relay/1 ${direction}`) }, secret, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
2298
- const [toHost, toClient] = await Promise.all([key("client-to-host"), key("host-to-client")]);
2299
- return side === "client" ? new RelayCipher(toHost, toClient) : new RelayCipher(toClient, toHost);
2269
+ async get(key) {
2270
+ const value = this.values.get(key);
2271
+ return value === undefined ? undefined : structuredClone(value);
2300
2272
  }
2301
- seal(text) {
2302
- const iv = RelayCipher.iv(this.sent++);
2303
- const sealed = this.sealing.then(async () => {
2304
- const data = await globalThis.crypto.subtle.encrypt({ name: "AES-GCM", iv }, this.sendKey, await this.pack(text));
2305
- return RelayBytes.toBase64(new Uint8Array(data));
2306
- });
2307
- this.sealing = sealed.catch(() => {
2308
- return;
2309
- });
2310
- return sealed;
2273
+ async put(key, value) {
2274
+ this.values.set(key, structuredClone(value));
2311
2275
  }
2312
- open(frame) {
2313
- const iv = RelayCipher.iv(this.received++);
2314
- const opened = this.opening.then(async () => {
2315
- const data = await globalThis.crypto.subtle.decrypt({ name: "AES-GCM", iv }, this.receiveKey, RelayBytes.fromBase64(frame));
2316
- return this.unpack(new Uint8Array(data));
2317
- });
2318
- this.opening = opened.catch(() => {
2319
- return;
2320
- });
2321
- return opened;
2276
+ async delete(key) {
2277
+ return this.values.delete(key);
2322
2278
  }
2323
- async pack(text) {
2324
- const bytes = encoder2.encode(text);
2325
- if (!this.compress) {
2326
- return bytes;
2279
+ async list(options) {
2280
+ const found = new Map;
2281
+ for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
2282
+ if (key.startsWith(options.prefix)) {
2283
+ found.set(key, structuredClone(value));
2284
+ }
2327
2285
  }
2328
- const deflated = bytes.length >= DEFLATE_MIN_BYTES ? await RelayDeflate.compress(bytes) : undefined;
2329
- return deflated && deflated.length < bytes.length ? RelayBytes.concat(Uint8Array.of(DEFLATED), deflated) : RelayBytes.concat(Uint8Array.of(PLAIN), bytes);
2286
+ return found;
2287
+ }
2288
+ async deleteAll() {
2289
+ this.values.clear();
2290
+ }
2291
+ get empty() {
2292
+ return this.values.size === 0;
2293
+ }
2294
+ }
2295
+
2296
+ class RelayServer {
2297
+ constructor(options = {}) {
2298
+ this.options = options;
2299
+ this.rooms = new Map;
2300
+ this.blobs = new Map;
2301
+ this.claims = new Map;
2302
+ this.hubs = new Map;
2303
+ this.spots = new Map;
2304
+ this.spotTries = new Map;
2305
+ this.spotAddresses = new WeakMap;
2306
+ if (options.data) {
2307
+ mkdirSync5(options.data, { recursive: true, mode: 448 });
2308
+ try {
2309
+ for (const [id, hash] of Object.entries(JSON.parse(readFileSync7(this.claimsFile(), "utf8")))) {
2310
+ this.claims.set(id, hash);
2311
+ }
2312
+ } catch (_a) {}
2313
+ for (const id of FileRelayStorage.ids(join6(options.data, "blobs"))) {
2314
+ this.blobCopy(id);
2315
+ }
2316
+ for (const id of FileRelayStorage.ids(join6(options.data, "hubs"))) {
2317
+ this.hubOf(id);
2318
+ }
2319
+ }
2320
+ }
2321
+ listen() {
2322
+ const server = createServer2((request, response) => {
2323
+ var _a;
2324
+ const path = ((_a = request.url) !== null && _a !== undefined ? _a : "/").split(/[?#]/)[0];
2325
+ if (path === RELAY_INFO_PATH) {
2326
+ const info = RelayInfoUtil.of(!!this.options.data);
2327
+ response.writeHead(200, { "content-type": "application/json", "access-control-allow-origin": "*", "cache-control": "no-store" });
2328
+ response.end(JSON.stringify(info));
2329
+ return;
2330
+ }
2331
+ if (path.startsWith(RELAY_BLOB_PATH)) {
2332
+ this.blob(path.slice(RELAY_BLOB_PATH.length), request, response).catch(() => {
2333
+ if (!response.headersSent) {
2334
+ response.writeHead(400);
2335
+ }
2336
+ response.end();
2337
+ });
2338
+ return;
2339
+ }
2340
+ if (path === RELAY_ROOM_PATH || path === RELAY_JOIN_PATH) {
2341
+ response.writeHead(200, { ...RELAY_VIEWER_HEADERS, "x-frame-options": "DENY" });
2342
+ response.end(path === RELAY_ROOM_PATH ? RelayViewer.room() : RelayViewer.join());
2343
+ return;
2344
+ }
2345
+ if (path.startsWith(RELAY_WEB_PATH) || path === RELAY_WEB_PATH.slice(0, -1)) {
2346
+ this.web(path, response);
2347
+ return;
2348
+ }
2349
+ if (path === RELAY_CONTENT_PATH || path === RELAY_FRAME_PATH) {
2350
+ const frame = path === RELAY_FRAME_PATH;
2351
+ response.writeHead(200, {
2352
+ ...RELAY_VIEWER_HEADERS,
2353
+ ...frame ? { "content-security-policy": RELAY_FRAME_HEADER_CSP } : { "x-frame-options": "DENY" }
2354
+ });
2355
+ response.end(frame ? RelayViewer.frame() : RelayViewer.page());
2356
+ return;
2357
+ }
2358
+ const page = path === RELAY_PAIR_PATH ? RELAY_PAIR_PAGE : path === RELAY_SHARE_PATH ? RELAY_SHARE_PAGE : undefined;
2359
+ response.writeHead(200, { "content-type": page ? "text/html; charset=utf-8" : "text/plain" });
2360
+ response.end(page !== null && page !== undefined ? page : `Ta relay
2361
+ `);
2362
+ });
2363
+ server.on("upgrade", (request, socket, head) => this.upgrade(request, socket, head));
2364
+ this.server = server;
2365
+ return new Promise((resolve2, reject) => {
2366
+ var _a, _b;
2367
+ server.once("error", reject);
2368
+ server.listen((_a = this.options.port) !== null && _a !== undefined ? _a : 0, (_b = this.options.host) !== null && _b !== undefined ? _b : "127.0.0.1", () => {
2369
+ const { address, port } = server.address();
2370
+ resolve2(`http://${address.includes(":") ? `[${address}]` : address}:${port}`);
2371
+ });
2372
+ });
2330
2373
  }
2331
- async unpack(bytes) {
2332
- if (!this.compress) {
2333
- return decoder2.decode(bytes);
2374
+ web(path, response) {
2375
+ var _a;
2376
+ if (path === RELAY_WEB_PATH.slice(0, -1)) {
2377
+ response.writeHead(308, { location: RELAY_WEB_PATH });
2378
+ response.end();
2379
+ return;
2334
2380
  }
2335
- const body = bytes.subarray(1);
2336
- return decoder2.decode(bytes[0] === DEFLATED ? await RelayDeflate.decompress(body) : body);
2337
- }
2338
- static iv(counter) {
2339
- const iv = new Uint8Array(IV_LENGTH);
2340
- new DataView(iv.buffer).setUint32(IV_LENGTH - 8, Math.floor(counter / 2 ** 32));
2341
- new DataView(iv.buffer).setUint32(IV_LENGTH - 4, counter >>> 0);
2342
- return iv;
2381
+ const file = RelayWebUtil.file(path);
2382
+ const full = file && this.options.web ? join6(this.options.web, file) : undefined;
2383
+ if (!file || !full || !((_a = statSync(full, { throwIfNoEntry: false })) === null || _a === undefined ? undefined : _a.isFile())) {
2384
+ response.writeHead(404, { "content-type": "text/plain" });
2385
+ response.end(`Not found.
2386
+ `);
2387
+ return;
2388
+ }
2389
+ const body = readFileSync7(full);
2390
+ response.writeHead(200, RelayWebUtil.headers(file));
2391
+ response.end(file === "index.html" ? RelayWebUtil.index(body.toString("utf8")) : body);
2343
2392
  }
2344
- }
2345
- var encoder2, decoder2, IV_LENGTH = 12, PLAIN = 0, DEFLATED = 1, DEFLATE_MIN_BYTES = 1024, RelayDeflate;
2346
- var init_relay_cipher = __esm(() => {
2347
- init_relay_bytes();
2348
- encoder2 = new TextEncoder;
2349
- decoder2 = new TextDecoder;
2350
- (function(RelayDeflate2) {
2351
- let support;
2352
- function supported() {
2353
- if (support === undefined) {
2354
- try {
2355
- new CompressionStream("deflate-raw");
2356
- new DecompressionStream("deflate-raw");
2357
- support = true;
2358
- } catch (_a) {
2359
- support = false;
2360
- }
2393
+ close() {
2394
+ var _a, _b, _c, _d, _e;
2395
+ for (const { sockets } of this.hubs.values()) {
2396
+ for (const connection of sockets.keys()) {
2397
+ connection.close(1001, "The relay is stopping.");
2361
2398
  }
2362
- return support;
2363
- }
2364
- RelayDeflate2.supported = supported;
2365
- function compress(bytes) {
2366
- return through(bytes, new CompressionStream("deflate-raw"));
2367
2399
  }
2368
- RelayDeflate2.compress = compress;
2369
- function decompress(bytes) {
2370
- return through(bytes, new DecompressionStream("deflate-raw"));
2400
+ for (const { storage } of this.hubs.values()) {
2401
+ (_b = (_a = storage).close) === null || _b === undefined || _b.call(_a);
2371
2402
  }
2372
- RelayDeflate2.decompress = decompress;
2373
- async function through(bytes, stream) {
2374
- const piped = new Blob([bytes]).stream().pipeThrough(stream);
2375
- return new Uint8Array(await new Response(piped).arrayBuffer());
2403
+ for (const { storage } of this.blobs.values()) {
2404
+ (_d = (_c = storage).close) === null || _d === undefined || _d.call(_c);
2376
2405
  }
2377
- })(RelayDeflate || (RelayDeflate = {}));
2378
- });
2379
-
2380
- // ../../ta-packages/ta-relay/esm/common/relay-pairing.js
2381
- var exports_relay_pairing = {};
2382
- __export(exports_relay_pairing, {
2383
- RelayPairingUtil: () => RelayPairingUtil
2384
- });
2385
- var RelayPairingUtil;
2386
- var init_relay_pairing = __esm(() => {
2387
- init_relay_protocol();
2388
- (function(RelayPairingUtil2) {
2389
- function link(pairing) {
2390
- const fragment = new URLSearchParams({ v: "1", h: pairing.host, d: pairing.device, k: pairing.key });
2391
- if (pairing.name) {
2392
- fragment.set("n", pairing.name);
2406
+ this.hubs.clear();
2407
+ for (const { sockets } of this.spots.values()) {
2408
+ for (const connection of sockets.keys()) {
2409
+ connection.close(1001, "The relay is stopping.");
2393
2410
  }
2394
- return `${pairing.relay}${RELAY_PAIR_PATH}#${fragment}`;
2395
2411
  }
2396
- RelayPairingUtil2.link = link;
2397
- function parse(link2) {
2398
- var _a;
2399
- const url = new URL(link2.trim());
2400
- const fragment = new URLSearchParams(url.hash.slice(1));
2401
- const [host, device, key] = ["h", "d", "k"].map((name) => {
2402
- var _a2;
2403
- return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
2404
- });
2405
- if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_PAIR_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(host) || !RELAY_ID.test(device) || !/^[A-Za-z0-9_-]{43}$/.test(key)) {
2406
- throw new Error("Not a pairing link of Ta.");
2412
+ this.spots.clear();
2413
+ for (const room of this.rooms.values()) {
2414
+ (_e = room.host) === null || _e === undefined || _e.close(1001, "The relay is stopping.");
2415
+ for (const client of room.clients.values()) {
2416
+ client.close(1001, "The relay is stopping.");
2407
2417
  }
2408
- return { relay: url.origin, host, device, key, name: (_a = fragment.get("n")) !== null && _a !== undefined ? _a : undefined };
2409
- }
2410
- RelayPairingUtil2.parse = parse;
2411
- function websocketUrl(relay, path) {
2412
- return relay.replace(/^http/, "ws") + path;
2413
2418
  }
2414
- RelayPairingUtil2.websocketUrl = websocketUrl;
2415
- })(RelayPairingUtil || (RelayPairingUtil = {}));
2416
- });
2417
-
2418
- // ../../ta-packages/ta-relay/esm/common/relay-socket.js
2419
- class RelaySocket {
2420
- constructor(pairing, options = {}) {
2419
+ this.rooms.clear();
2420
+ return new Promise((resolve2) => this.server ? this.server.close(() => resolve2()) : resolve2());
2421
+ }
2422
+ async blob(id, request, response) {
2421
2423
  var _a;
2422
- this.pairing = pairing;
2423
- this.options = options;
2424
- this.onopen = null;
2425
- this.onmessage = null;
2426
- this.onclose = null;
2427
- this.onerror = null;
2428
- this.state = CONNECTING;
2429
- this.nonce = RelayBytes.random(16);
2430
- this.ponged = false;
2431
- this.awaitingPong = false;
2432
- this.receiving = Promise.resolve();
2433
- this.socket = new WebSocket(RelayPairingUtil.websocketUrl(pairing.relay, RELAY_CONNECT_PATH + pairing.host));
2434
- this.helloTimer = setTimeout(() => this.drop(RelayCloseCode.TIMEOUT, "The host did not answer."), (_a = options.helloMs) !== null && _a !== undefined ? _a : HELLO_MS);
2435
- this.socket.onopen = () => {
2436
- var _a2;
2437
- const hello = {
2438
- t: "hello",
2439
- v: 1,
2440
- device: pairing.device,
2441
- nonce: RelayBytes.toBase64(this.nonce),
2442
- ...RelayDeflate.supported() ? { z: 1 } : {}
2443
- };
2444
- this.socket.send(JSON.stringify(hello));
2445
- this.pingTimer = setInterval(() => this.ping(), (_a2 = options.pingMs) !== null && _a2 !== undefined ? _a2 : RELAY_PING_MS);
2446
- };
2447
- this.socket.onmessage = (message) => {
2448
- const text = String(message.data);
2449
- if (text === RELAY_PONG) {
2450
- this.ponged = true;
2451
- this.awaitingPong = false;
2452
- return;
2424
+ if (!RELAY_ID.test(id)) {
2425
+ response.writeHead(404).end();
2426
+ return;
2427
+ }
2428
+ const read = await RelayServer.body(request, RelayBlobs.MAX_BYTES);
2429
+ if (!read) {
2430
+ response.writeHead(413, { connection: "close" }).end(`Too large.
2431
+ `);
2432
+ return;
2433
+ }
2434
+ const copy = this.blobCopy(id);
2435
+ const headers = new Headers;
2436
+ for (const [name, value] of Object.entries(request.headers)) {
2437
+ if (typeof value === "string") {
2438
+ headers.set(name, value);
2453
2439
  }
2454
- this.receiving = this.receiving.then(() => this.receive(text));
2455
- };
2456
- this.socket.onerror = (event) => {
2457
- var _a2;
2458
- return (_a2 = this.onerror) === null || _a2 === undefined ? undefined : _a2.call(this, event);
2459
- };
2460
- this.socket.onclose = (event) => void this.receiving.then(() => this.finish(event.code, event.reason));
2440
+ }
2441
+ const method = (_a = request.method) !== null && _a !== undefined ? _a : "GET";
2442
+ const body = read.length && method !== "GET" && method !== "HEAD" ? read : undefined;
2443
+ copy.pending++;
2444
+ let answer;
2445
+ try {
2446
+ answer = await copy.blobs.handle(new Request(`http://relay${request.url}`, { method, headers, body }));
2447
+ } finally {
2448
+ copy.pending--;
2449
+ if (copy.pending === 0 && copy.storage.empty && this.blobs.get(id) === copy) {
2450
+ this.blobs.delete(id);
2451
+ }
2452
+ }
2453
+ response.writeHead(answer.status, Object.fromEntries(answer.headers));
2454
+ response.end(Buffer.from(await answer.arrayBuffer()));
2461
2455
  }
2462
- get readyState() {
2463
- return this.state;
2456
+ blobCopy(id) {
2457
+ let copy = this.blobs.get(id);
2458
+ if (!copy) {
2459
+ const data = this.options.data;
2460
+ const made = { pending: 0 };
2461
+ const storage = data ? new FileRelayStorage(join6(data, "blobs", id), () => {
2462
+ var _a;
2463
+ (_a = made.storage) === null || _a === undefined || _a.deleteAll().then(() => this.blobs.get(id) === copy && this.blobs.delete(id));
2464
+ }) : new MemoryBlobStorage;
2465
+ made.storage = storage;
2466
+ made.blobs = new RelayBlobs(storage);
2467
+ copy = made;
2468
+ this.blobs.set(id, copy);
2469
+ }
2470
+ return copy;
2464
2471
  }
2465
- get closeCode() {
2466
- return this.code;
2472
+ claimsFile() {
2473
+ return join6(this.options.data, "hosts.json");
2467
2474
  }
2468
- send(text) {
2469
- if (this.state !== OPEN || !this.cipher) {
2470
- throw new Error("The connection is not open.");
2475
+ saveClaims() {
2476
+ if (!this.options.data) {
2477
+ return;
2471
2478
  }
2472
- this.cipher.seal(text).then((frame) => this.socket.readyState === OPEN && this.socket.send(frame));
2479
+ const file = this.claimsFile();
2480
+ writeFileSync5(`${file}.tmp`, JSON.stringify(Object.fromEntries(this.claims)), { mode: 384 });
2481
+ renameSync3(`${file}.tmp`, file);
2473
2482
  }
2474
- close(code = 1000, reason = "") {
2475
- if (this.state === CLOSED) {
2483
+ static body(request, max) {
2484
+ return new Promise((resolve2, reject) => {
2485
+ const chunks = [];
2486
+ let size = 0;
2487
+ request.on("data", (chunk) => {
2488
+ if (size < 0) {
2489
+ return;
2490
+ }
2491
+ size += chunk.length;
2492
+ if (size > max) {
2493
+ size = -1;
2494
+ chunks.length = 0;
2495
+ resolve2(undefined);
2496
+ return;
2497
+ }
2498
+ chunks.push(chunk);
2499
+ });
2500
+ request.on("end", () => size >= 0 && resolve2(Buffer.concat(chunks)));
2501
+ request.on("error", reject);
2502
+ });
2503
+ }
2504
+ upgrade(request, socket, head) {
2505
+ var _a, _b, _c;
2506
+ const url = new URL((_a = request.url) !== null && _a !== undefined ? _a : "/", "http://relay");
2507
+ const checked = WebSocketConnection.check(request);
2508
+ if ("status" in checked) {
2509
+ WebSocketConnection.refuse(socket, checked.status, checked.message);
2476
2510
  return;
2477
2511
  }
2478
- this.state = CLOSING;
2479
- this.socket.close(code, reason);
2480
- }
2481
- async receive(text) {
2482
- var _a, _b;
2483
- if (this.cipher) {
2484
- if (this.options.proveFirst && text.startsWith("{")) {
2485
- this.drop(RelaySocket.REFUSED, RelaySocket.refusal(text));
2512
+ if (url.pathname.startsWith(RELAY_HUB_PATH)) {
2513
+ const id2 = url.pathname.slice(RELAY_HUB_PATH.length);
2514
+ if (!RELAY_ID.test(id2)) {
2515
+ WebSocketConnection.refuse(socket, 404, "Not found.");
2486
2516
  return;
2487
2517
  }
2488
- try {
2489
- const data = await this.cipher.open(text);
2490
- (_a = this.onmessage) === null || _a === undefined || _a.call(this, { data });
2491
- } catch (_c) {
2492
- this.close(4400, "A message did not open.");
2493
- }
2518
+ this.openHub(id2, WebSocketConnection.open(socket, checked.key, head, WEBSOCKET));
2494
2519
  return;
2495
2520
  }
2496
- try {
2497
- const welcome = JSON.parse(text);
2498
- if (welcome.t !== "ready") {
2499
- this.drop(RelaySocket.REFUSED, this.options.proveFirst ? RelaySocket.refusal(text) : "The host refused this device.");
2521
+ if (url.pathname.startsWith(RELAY_SPOT_PATH)) {
2522
+ const id2 = url.pathname.slice(RELAY_SPOT_PATH.length);
2523
+ if (!RELAY_ID.test(id2)) {
2524
+ WebSocketConnection.refuse(socket, 404, "Not found.");
2500
2525
  return;
2501
2526
  }
2502
- const cipher = await RelayCipher.derive(RelayBytes.fromBase64(this.pairing.key), this.nonce, RelayBytes.fromBase64(welcome.nonce), "client");
2503
- if (welcome.proof === undefined && this.options.proveFirst) {
2504
- this.socket.send(await cipher.seal(RELAY_PROOF));
2505
- } else if (welcome.proof === undefined || await cipher.open(welcome.proof) !== RELAY_PROOF) {
2506
- throw new Error("The host did not show the key.");
2527
+ const address = RelaySpotTries.keyOf(request.socket.remoteAddress);
2528
+ const connection2 = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
2529
+ const fails = RelaySpotTries.recent((_b = this.spotTries.get(address)) !== null && _b !== undefined ? _b : [], Date.now());
2530
+ if (RelaySpotTries.blocked(fails, Date.now())) {
2531
+ connection2.close(RelaySpotCloseCode.TRIES, "Too many codes tried.");
2532
+ return;
2507
2533
  }
2508
- cipher.compress = welcome.z === 1 && RelayDeflate.supported();
2509
- this.cipher = cipher;
2510
- clearTimeout(this.helloTimer);
2511
- this.state = OPEN;
2512
- (_b = this.onopen) === null || _b === undefined || _b.call(this);
2513
- } catch (_d) {
2514
- this.drop(RelaySocket.REFUSED, "The host refused this device.");
2534
+ this.openSpot(id2, connection2, address);
2535
+ return;
2536
+ }
2537
+ const [path, id] = url.pathname.startsWith(RELAY_HOST_PATH) ? [RELAY_HOST_PATH, url.pathname.slice(RELAY_HOST_PATH.length)] : [RELAY_CONNECT_PATH, url.pathname.slice(RELAY_CONNECT_PATH.length)];
2538
+ if (!url.pathname.startsWith(path) || !RELAY_ID.test(id)) {
2539
+ WebSocketConnection.refuse(socket, 404, "Not found.");
2540
+ return;
2541
+ }
2542
+ const connection = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
2543
+ if (path === RELAY_HOST_PATH) {
2544
+ this.openHost(id, (_c = url.searchParams.get("secret")) !== null && _c !== undefined ? _c : "", connection);
2545
+ } else {
2546
+ this.openClient(id, connection);
2515
2547
  }
2516
2548
  }
2517
- static refusal(text) {
2518
- try {
2519
- const reason = JSON.parse(text).reason;
2520
- return reason === "key" || reason === "busy" ? reason : "gone";
2521
- } catch (_a) {
2522
- return "gone";
2549
+ openHost(id, secret, connection) {
2550
+ var _a, _b;
2551
+ const hash = createHash2("sha256").update(secret).digest("base64url");
2552
+ if (secret.length >= 32 && !this.claims.has(id) && this.options.data) {
2553
+ this.claims.set(id, hash);
2554
+ this.saveClaims();
2555
+ }
2556
+ const room = (_a = this.rooms.get(id)) !== null && _a !== undefined ? _a : this.createRoom(id, (_b = this.claims.get(id)) !== null && _b !== undefined ? _b : hash);
2557
+ if (secret.length < 32 || !RelayServer.same(room.secretHash, hash)) {
2558
+ connection.close(RelayCloseCode.REFUSED, "Refused.");
2559
+ return;
2560
+ }
2561
+ if (room.host) {
2562
+ room.host.close(RelayCloseCode.REPLACED, "The host connected again.");
2563
+ room.relay.hostClosed();
2523
2564
  }
2565
+ room.host = connection;
2566
+ connection.onMessage((text) => room.relay.fromHost(text));
2567
+ connection.onClose(() => {
2568
+ if (room.host === connection) {
2569
+ room.host = undefined;
2570
+ room.relay.hostClosed();
2571
+ }
2572
+ });
2524
2573
  }
2525
- ping() {
2526
- if (this.awaitingPong && this.ponged) {
2527
- this.drop(RelayCloseCode.TIMEOUT, "The relay did not answer.");
2574
+ openClient(id, connection) {
2575
+ const room = this.rooms.get(id);
2576
+ const channel = randomBytes(9).toString("base64url");
2577
+ room === null || room === undefined || room.clients.set(channel, connection);
2578
+ const refused = room ? room.relay.clientOpened(channel) : RelayCloseCode.HOST_OFFLINE;
2579
+ if (!room || refused !== undefined) {
2580
+ room === null || room === undefined || room.clients.delete(channel);
2581
+ connection.close(refused !== null && refused !== undefined ? refused : RelayCloseCode.HOST_OFFLINE, "The host is not available.");
2528
2582
  return;
2529
2583
  }
2530
- this.awaitingPong = true;
2531
- if (this.socket.readyState === OPEN) {
2532
- this.socket.send(RELAY_PING);
2584
+ connection.onMessage((text) => room.relay.fromClient(channel, text));
2585
+ connection.onClose(() => {
2586
+ if (room.clients.delete(channel)) {
2587
+ room.relay.clientClosed(channel);
2588
+ }
2589
+ });
2590
+ }
2591
+ openSpot(id, connection, address) {
2592
+ let current = this.spots.get(id);
2593
+ if (!current) {
2594
+ const sockets2 = new Map;
2595
+ const socketOf = (other) => ({
2596
+ key: other,
2597
+ get who() {
2598
+ var _a;
2599
+ return (_a = sockets2.get(other)) === null || _a === undefined ? undefined : _a.who;
2600
+ },
2601
+ set who(who) {
2602
+ const state = sockets2.get(other);
2603
+ if (state) {
2604
+ state.who = who;
2605
+ }
2606
+ },
2607
+ send: (text) => other.send(text),
2608
+ close: (code, reason) => other.close(code, reason)
2609
+ });
2610
+ const missed = (socket2) => {
2611
+ var _a, _b;
2612
+ const key = (_a = this.spotAddresses.get(socket2.key)) !== null && _a !== undefined ? _a : "unknown";
2613
+ const now = Date.now();
2614
+ this.spotTries.set(key, [...RelaySpotTries.recent((_b = this.spotTries.get(key)) !== null && _b !== undefined ? _b : [], now), now]);
2615
+ for (const [other, fails] of this.spotTries) {
2616
+ if (!RelaySpotTries.recent(fails, now).length) {
2617
+ this.spotTries.delete(other);
2618
+ }
2619
+ }
2620
+ };
2621
+ current = { sockets: sockets2, socketOf, spot: new RelaySpot(() => [...sockets2.keys()].map(socketOf), Date.now, missed) };
2622
+ this.spots.set(id, current);
2533
2623
  }
2624
+ const { sockets, spot } = current;
2625
+ sockets.set(connection, {});
2626
+ this.spotAddresses.set(connection, address);
2627
+ const socket = current.socketOf(connection);
2628
+ connection.onMessage((text) => spot.receive(socket, text));
2629
+ connection.onClose(() => {
2630
+ if (sockets.has(connection)) {
2631
+ spot.closed(socket);
2632
+ sockets.delete(connection);
2633
+ }
2634
+ if (sockets.size === 0 && this.spots.get(id) === current) {
2635
+ this.spots.delete(id);
2636
+ }
2637
+ });
2534
2638
  }
2535
- drop(code, reason) {
2536
- this.close(code, reason);
2537
- this.finish(code, reason);
2639
+ openHub(id, connection) {
2640
+ const current = this.hubOf(id);
2641
+ const { sockets, hub: relay } = current;
2642
+ sockets.set(connection, {});
2643
+ let chain = Promise.resolve();
2644
+ const socket = {
2645
+ key: connection,
2646
+ get who() {
2647
+ var _a;
2648
+ return (_a = sockets.get(connection)) === null || _a === undefined ? undefined : _a.who;
2649
+ },
2650
+ set who(who) {
2651
+ const state = sockets.get(connection);
2652
+ if (state) {
2653
+ state.who = who;
2654
+ }
2655
+ },
2656
+ send: (text) => connection.send(text),
2657
+ close: (code, reason) => connection.close(code, reason)
2658
+ };
2659
+ connection.onMessage((text) => {
2660
+ chain = chain.then(() => relay.receive(socket, text)).catch(() => {
2661
+ return;
2662
+ });
2663
+ });
2664
+ connection.onClose(() => {
2665
+ chain.then(() => {
2666
+ if (sockets.has(connection)) {
2667
+ relay.closed(socket);
2668
+ sockets.delete(connection);
2669
+ }
2670
+ this.dropHub(id, current);
2671
+ });
2672
+ });
2538
2673
  }
2539
- finish(code, reason) {
2540
- var _a;
2541
- if (this.state === CLOSED) {
2542
- return;
2674
+ hubOf(id) {
2675
+ let hub = this.hubs.get(id);
2676
+ if (!hub) {
2677
+ const sockets = new Map;
2678
+ const socketOf = (other) => {
2679
+ var _a;
2680
+ const state = (_a = sockets.get(other)) !== null && _a !== undefined ? _a : {};
2681
+ return {
2682
+ key: other,
2683
+ get who() {
2684
+ return state.who;
2685
+ },
2686
+ set who(who) {
2687
+ state.who = who;
2688
+ },
2689
+ send: (text) => other.send(text),
2690
+ close: (code, reason) => other.close(code, reason)
2691
+ };
2692
+ };
2693
+ const made = { sockets };
2694
+ const storage = this.options.data ? new FileRelayStorage(join6(this.options.data, "hubs", id), () => {
2695
+ var _a;
2696
+ return void ((_a = made.hub) === null || _a === undefined ? undefined : _a.alarm().then(() => this.dropHub(id, made)));
2697
+ }) : new MemoryHubStorage;
2698
+ made.storage = storage;
2699
+ made.hub = new RelayHub(storage, () => [...sockets.keys()].map(socketOf));
2700
+ hub = made;
2701
+ this.hubs.set(id, hub);
2543
2702
  }
2544
- clearTimeout(this.helloTimer);
2545
- clearInterval(this.pingTimer);
2546
- this.state = CLOSED;
2547
- this.code = code;
2548
- (_a = this.onclose) === null || _a === undefined || _a.call(this, { code, reason });
2703
+ return hub;
2704
+ }
2705
+ dropHub(id, hub) {
2706
+ if (hub && hub.sockets.size === 0 && hub.storage.empty && this.hubs.get(id) === hub) {
2707
+ this.hubs.delete(id);
2708
+ }
2709
+ }
2710
+ createRoom(id, secretHash) {
2711
+ const room = {
2712
+ secretHash,
2713
+ clients: new Map,
2714
+ relay: new RelayRoom({
2715
+ host: () => room.host ? peer(room.host) : undefined,
2716
+ client: (channel) => {
2717
+ const client = room.clients.get(channel);
2718
+ return client ? peer(client) : undefined;
2719
+ },
2720
+ clients: () => [...room.clients.values()].map(peer)
2721
+ })
2722
+ };
2723
+ this.rooms.set(id, room);
2724
+ return room;
2725
+ }
2726
+ static same(a, b) {
2727
+ const [left, right] = [Buffer.from(a), Buffer.from(b)];
2728
+ return left.length === right.length && timingSafeEqual(left, right);
2549
2729
  }
2550
2730
  }
2551
- var CONNECTING = 0, OPEN = 1, CLOSING = 2, CLOSED = 3, HELLO_MS = 15000;
2552
- var init_relay_socket = __esm(() => {
2553
- init_relay_bytes();
2554
- init_relay_cipher();
2555
- init_relay_pairing();
2731
+ var WEBSOCKET, peer = (connection) => ({ send: (text) => connection.send(text), close: (code, reason) => connection.close(code, reason) });
2732
+ var init_relay_server = __esm(() => {
2733
+ init_websocket_connection();
2734
+ init_relay_blobs();
2735
+ init_relay_hub();
2736
+ init_relay_info();
2556
2737
  init_relay_protocol();
2557
- RelaySocket.CONNECTING = CONNECTING;
2558
- RelaySocket.OPEN = OPEN;
2559
- RelaySocket.CLOSING = CLOSING;
2560
- RelaySocket.CLOSED = CLOSED;
2561
- RelaySocket.REFUSED = 4403;
2738
+ init_relay_room();
2739
+ init_relay_spot();
2740
+ init_relay_team();
2741
+ init_relay_web();
2742
+ init_relay_file_storage();
2743
+ init_relay_viewer();
2744
+ WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
2562
2745
  });
2563
2746
 
2564
2747
  // ../../ta-packages/ta-relay/esm/common/relay-content.js
@@ -2841,14 +3024,14 @@ __export(exports_relay_store, {
2841
3024
  import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
2842
3025
  import { chmodSync as chmodSync2, mkdirSync as mkdirSync6, readFileSync as readFileSync8, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
2843
3026
  import { hostname as hostname2 } from "node:os";
2844
- import { dirname as dirname4, join as join8 } from "node:path";
3027
+ import { dirname as dirname4, join as join7 } from "node:path";
2845
3028
 
2846
3029
  class RelayStore {
2847
3030
  constructor(agentDir) {
2848
3031
  this.agentDir = agentDir;
2849
3032
  }
2850
3033
  get file() {
2851
- return join8(this.agentDir, RelayStore.FILE);
3034
+ return join7(this.agentDir, RelayStore.FILE);
2852
3035
  }
2853
3036
  read() {
2854
3037
  try {
@@ -2971,7 +3154,7 @@ class RelayStore {
2971
3154
  }));
2972
3155
  }
2973
3156
  contentFile(contentId) {
2974
- return join8(this.agentDir, "shares", contentId);
3157
+ return join7(this.agentDir, "shares", contentId);
2975
3158
  }
2976
3159
  static live(content, now) {
2977
3160
  return content.expiresAt === undefined || content.expiresAt > now;
@@ -3085,16 +3268,16 @@ __export(exports_relays_file, {
3085
3268
  RELAY_FEATURES: () => RELAY_FEATURES,
3086
3269
  OFFICIAL_RELAY: () => OFFICIAL_RELAY
3087
3270
  });
3088
- import { accessSync, chmodSync as chmodSync3, constants as constants2, mkdirSync as mkdirSync7, readdirSync as readdirSync3, readFileSync as readFileSync9, renameSync as renameSync5, statSync, writeFileSync as writeFileSync7 } from "node:fs";
3271
+ import { accessSync, chmodSync as chmodSync3, constants as constants2, mkdirSync as mkdirSync7, readdirSync as readdirSync3, readFileSync as readFileSync9, renameSync as renameSync5, statSync as statSync2, writeFileSync as writeFileSync7 } from "node:fs";
3089
3272
  import { homedir as homedir2 } from "node:os";
3090
- import { dirname as dirname5, isAbsolute, join as join9, resolve as resolve2 } from "node:path";
3273
+ import { dirname as dirname5, isAbsolute, join as join8, resolve as resolve2 } from "node:path";
3091
3274
 
3092
3275
  class RelaysFile {
3093
3276
  constructor(agentDir) {
3094
3277
  this.agentDir = agentDir;
3095
3278
  }
3096
3279
  get file() {
3097
- return join9(this.agentDir, RelaysFile.FILE);
3280
+ return join8(this.agentDir, RelaysFile.FILE);
3098
3281
  }
3099
3282
  read() {
3100
3283
  let text;
@@ -3326,7 +3509,7 @@ var init_relays_file = __esm(() => {
3326
3509
  function expand(path) {
3327
3510
  const text = String(path !== null && path !== undefined ? path : "").trim();
3328
3511
  if (text === "~" || text.startsWith("~/")) {
3329
- return join9(homedir2(), text.slice(1));
3512
+ return join8(homedir2(), text.slice(1));
3330
3513
  }
3331
3514
  return isAbsolute(text) ? resolve2(text) : resolve2(homedir2(), text);
3332
3515
  }
@@ -3363,19 +3546,19 @@ var init_relays_file = __esm(() => {
3363
3546
  const found = [];
3364
3547
  const add = (name, dir) => {
3365
3548
  try {
3366
- if (statSync(dir).isDirectory()) {
3367
- found.push({ name, path: portable(join9(dir, "Ta")) });
3549
+ if (statSync2(dir).isDirectory()) {
3550
+ found.push({ name, path: portable(join8(dir, "Ta")) });
3368
3551
  }
3369
3552
  } catch (_a) {}
3370
3553
  };
3371
- add("iCloud Drive", join9(home, "Library", "Mobile Documents", "com~apple~CloudDocs"));
3554
+ add("iCloud Drive", join8(home, "Library", "Mobile Documents", "com~apple~CloudDocs"));
3372
3555
  try {
3373
- for (const entry of readdirSync3(join9(home, "Library", "CloudStorage"))) {
3374
- add(entry.replace(/-.*$/, ""), join9(home, "Library", "CloudStorage", entry));
3556
+ for (const entry of readdirSync3(join8(home, "Library", "CloudStorage"))) {
3557
+ add(entry.replace(/-.*$/, ""), join8(home, "Library", "CloudStorage", entry));
3375
3558
  }
3376
3559
  } catch (_a) {}
3377
3560
  for (const name of ["Dropbox", "OneDrive", "Nutstore Files", "坚果云"]) {
3378
- add(name, join9(home, name));
3561
+ add(name, join8(home, name));
3379
3562
  }
3380
3563
  return found.filter((drive, index) => found.findIndex((other) => other.path === drive.path) === index);
3381
3564
  }
@@ -3383,7 +3566,7 @@ var init_relays_file = __esm(() => {
3383
3566
  function checkFolder(path) {
3384
3567
  const dir = expand(path);
3385
3568
  try {
3386
- if (!statSync(dir).isDirectory()) {
3569
+ if (!statSync2(dir).isDirectory()) {
3387
3570
  return `${dir} is not a folder.`;
3388
3571
  }
3389
3572
  accessSync(dir, constants2.W_OK);
@@ -4248,7 +4431,7 @@ var init_exec_server = __esm(() => {
4248
4431
 
4249
4432
  // ../../ta-packages/ta-harness/esm/node/ta-cli.js
4250
4433
  import { randomBytes as randomBytes3 } from "node:crypto";
4251
- import { dirname as dirname6, join as join10 } from "node:path";
4434
+ import { dirname as dirname6, join as join9 } from "node:path";
4252
4435
  import { parseArgs } from "node:util";
4253
4436
 
4254
4437
  // ../../ai-packages/ai-coding-agent/esm/node/pi/pi-bundle-util.js
@@ -4288,12 +4471,12 @@ var PiBundleUtil;
4288
4471
  import { spawn } from "node:child_process";
4289
4472
  var BugReport;
4290
4473
  (function(BugReport2) {
4291
- BugReport2.ISSUES_URL = "https://github.com/cellbang/cell/issues/new";
4474
+ BugReport2.ISSUES_URL = "https://github.com/cellbang/ta/issues/new";
4292
4475
  function issueUrl(description, environment) {
4293
4476
  var _a;
4294
4477
  const url = new URL(BugReport2.ISSUES_URL);
4295
- url.searchParams.set("title", `[Ta] ${description.trim() || "Describe the bug"}`);
4296
- url.searchParams.set("labels", "ta");
4478
+ url.searchParams.set("title", description.trim() || "Describe the bug");
4479
+ url.searchParams.set("labels", "bug");
4297
4480
  url.searchParams.set("body", [
4298
4481
  "## What happened",
4299
4482
  "",
@@ -5025,7 +5208,8 @@ var TaPackages;
5025
5208
  // ../../ta-packages/ta-harness/esm/node/ta-cli.js
5026
5209
  var SERVE_HELP = `Usage: ta serve [--host <host>] [--port <port>] [--web] [--exec <url>]
5027
5210
 
5028
- Serves the sessions of Ta over WebSocket to any number of clients, and its web client. Stops on SIGINT or SIGTERM.
5211
+ Serves the sessions of Ta over WebSocket to any number of clients, and its web client. Stops on SIGINT
5212
+ or SIGTERM.
5029
5213
 
5030
5214
  --host Address to listen on. Default: 127.0.0.1
5031
5215
  --port Port to listen on. Default: the port of the last start if it is free, so that a web app
@@ -5056,7 +5240,8 @@ Set TA_EXEC_TOKEN to choose the token hosts must present; otherwise a random one
5056
5240
  var RELAY_HELP = `Usage: ta relay [--host <host>] [--port <port>] [--data <dir>]
5057
5241
 
5058
5242
  Runs a relay, through which paired devices reach a ta serve from anywhere (ta pair). It only forwards:
5059
- what goes through is encrypted end to end. Put it behind HTTPS. Stops on SIGINT or SIGTERM.
5243
+ what goes through is encrypted end to end. It also serves the page of Ta under /w/, for those let into a
5244
+ Ta from a browser by a link that invites. Put it behind HTTPS. Stops on SIGINT or SIGTERM.
5060
5245
 
5061
5246
  --host Address to listen on. Default: 127.0.0.1
5062
5247
  --port Port to listen on. Default: 8080
@@ -5082,7 +5267,7 @@ var TaCli;
5082
5267
  return;
5083
5268
  }
5084
5269
  if (argv[0] === "relay") {
5085
- await relay(argv.slice(1));
5270
+ await relay(argv.slice(1), join9(dirname6(options.serveEntry), "..", "public"));
5086
5271
  return;
5087
5272
  }
5088
5273
  if (argv[0] === "pair") {
@@ -5092,7 +5277,7 @@ var TaCli;
5092
5277
  if (argv[0] === "gateway" && options.gatewayEntry) {
5093
5278
  const { GatewayCli } = await import(options.gatewayEntry);
5094
5279
  await GatewayCli.run(argv.slice(1), {
5095
- publicDir: join10(dirname6(options.serveEntry), "..", "public"),
5280
+ publicDir: join9(dirname6(options.serveEntry), "..", "public"),
5096
5281
  taCommand: [process.execPath, process.argv[1]]
5097
5282
  });
5098
5283
  return;
@@ -5156,7 +5341,7 @@ var TaCli;
5156
5341
  }
5157
5342
  await import(entry);
5158
5343
  }
5159
- async function relay(argv) {
5344
+ async function relay(argv, web) {
5160
5345
  const { values } = parseArgs({
5161
5346
  args: argv,
5162
5347
  options: { host: { type: "string" }, port: { type: "string" }, data: { type: "string" }, help: { type: "boolean", short: "h" } }
@@ -5170,7 +5355,8 @@ var TaCli;
5170
5355
  const server = new RelayServer2({
5171
5356
  host: values.host,
5172
5357
  port: values.port ? Number(values.port) : 8080,
5173
- data: values.data ? resolve4(values.data) : undefined
5358
+ data: values.data ? resolve4(values.data) : undefined,
5359
+ web
5174
5360
  });
5175
5361
  console.log(`ta relay: ${await server.listen()}`);
5176
5362
  const stop = () => void server.close().then(() => process.exit(0));