@celljs/ta 4.13.1 → 4.15.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 (394) hide show
  1. package/dist/cli.mjs +1025 -814
  2. package/dist/gateway.mjs +471 -196
  3. package/dist/pi/CHANGELOG.md +13 -0
  4. package/dist/pi/package.json +1 -1
  5. package/dist/pi/packages/ta-agents/extension/index.mjs +50 -21
  6. package/dist/pi/packages/ta-agents/lib/texts.d.ts +43 -22
  7. package/dist/pi/packages/ta-agents/lib/texts.js +54 -21
  8. package/dist/pi/packages/ta-agents/package.json +9 -5
  9. package/dist/pi/packages/ta-bots/extension/index.mjs +81 -10
  10. package/dist/pi/packages/ta-bots/host/index.mjs +303 -184
  11. package/dist/pi/packages/ta-bots/lib/i18n.d.ts +3 -0
  12. package/dist/pi/packages/ta-bots/lib/i18n.js +167 -2
  13. package/dist/pi/packages/ta-bots/lib/server-texts.d.ts +0 -1
  14. package/dist/pi/packages/ta-bots/lib/server-texts.js +45 -12
  15. package/dist/pi/packages/ta-bots/package.json +9 -5
  16. package/dist/pi/packages/ta-bots/web/index.js +203 -1
  17. package/dist/pi/packages/ta-changes/lib/i18n.d.ts +3 -0
  18. package/dist/pi/packages/ta-changes/lib/i18n.js +51 -2
  19. package/dist/pi/packages/ta-changes/package.json +9 -5
  20. package/dist/pi/packages/ta-changes/web/index.js +87 -1
  21. package/dist/pi/packages/ta-channels/extension/index.mjs +78 -13
  22. package/dist/pi/packages/ta-channels/host/index.mjs +291 -190
  23. package/dist/pi/packages/ta-channels/lib/agent-cards.d.ts +2 -1
  24. package/dist/pi/packages/ta-channels/lib/agent-cards.js +4 -3
  25. package/dist/pi/packages/ta-channels/lib/handoff.d.ts +5 -4
  26. package/dist/pi/packages/ta-channels/lib/handoff.js +22 -6
  27. package/dist/pi/packages/ta-channels/lib/i18n.d.ts +3 -0
  28. package/dist/pi/packages/ta-channels/lib/i18n.js +361 -2
  29. package/dist/pi/packages/ta-channels/lib/room.js +3 -3
  30. package/dist/pi/packages/ta-channels/lib/team-ask.d.ts +2 -1
  31. package/dist/pi/packages/ta-channels/lib/team-ask.js +19 -7
  32. package/dist/pi/packages/ta-channels/lib/team.d.ts +2 -2
  33. package/dist/pi/packages/ta-channels/lib/team.js +1 -1
  34. package/dist/pi/packages/ta-channels/package.json +9 -5
  35. package/dist/pi/packages/ta-channels/web/index.js +483 -47
  36. package/dist/pi/packages/ta-computer-use/extension/index.mjs +11 -1
  37. package/dist/pi/packages/ta-computer-use/lib/cua-driver-access.js +20 -2
  38. package/dist/pi/packages/ta-computer-use/package.json +9 -5
  39. package/dist/pi/packages/ta-cron/README.en.md +1 -1
  40. package/dist/pi/packages/ta-cron/README.md +1 -1
  41. package/dist/pi/packages/ta-cron/extension/index.mjs +82 -8
  42. package/dist/pi/packages/ta-cron/host/index.mjs +67 -3
  43. package/dist/pi/packages/ta-cron/lib/editor.js +1 -1
  44. package/dist/pi/packages/ta-cron/lib/i18n.d.ts +3 -0
  45. package/dist/pi/packages/ta-cron/lib/i18n.js +217 -2
  46. package/dist/pi/packages/ta-cron/lib/page.d.ts +2 -0
  47. package/dist/pi/packages/ta-cron/lib/page.js +22 -8
  48. package/dist/pi/packages/ta-cron/lib/schedule-util.js +29 -3
  49. package/dist/pi/packages/ta-cron/lib/server-texts.d.ts +2 -1
  50. package/dist/pi/packages/ta-cron/lib/server-texts.js +16 -9
  51. package/dist/pi/packages/ta-cron/package.json +9 -5
  52. package/dist/pi/packages/ta-cron/web/index.js +303 -14
  53. package/dist/pi/packages/ta-extensions/lib/i18n.d.ts +3 -0
  54. package/dist/pi/packages/ta-extensions/lib/i18n.js +240 -2
  55. package/dist/pi/packages/ta-extensions/package.json +9 -5
  56. package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +2 -1
  57. package/dist/pi/packages/ta-extensions/web/index.js +499 -176
  58. package/dist/pi/packages/ta-games/README.en.md +1 -1
  59. package/dist/pi/packages/ta-games/README.md +1 -1
  60. package/dist/pi/packages/ta-games/lib/i18n.d.ts +3 -0
  61. package/dist/pi/packages/ta-games/lib/i18n.js +61 -2
  62. package/dist/pi/packages/ta-games/package.json +9 -5
  63. package/dist/pi/packages/ta-games/skills/ta-game/SKILL.md +41 -3
  64. package/dist/pi/packages/ta-games/web/index.js +97 -1
  65. package/dist/pi/packages/ta-glance/extension/index.mjs +31 -13
  66. package/dist/pi/packages/ta-glance/lib/glance-json.d.ts +2 -0
  67. package/dist/pi/packages/ta-glance/lib/glance-json.js +38 -16
  68. package/dist/pi/packages/ta-glance/lib/i18n.d.ts +3 -0
  69. package/dist/pi/packages/ta-glance/lib/i18n.js +31 -2
  70. package/dist/pi/packages/ta-glance/package.json +9 -5
  71. package/dist/pi/packages/ta-glance/web/index.js +98 -14
  72. package/dist/pi/packages/ta-initiative/README.en.md +1 -0
  73. package/dist/pi/packages/ta-initiative/README.md +1 -0
  74. package/dist/pi/packages/ta-initiative/extension/index.mjs +89 -9
  75. package/dist/pi/packages/ta-initiative/host/index.mjs +123 -19
  76. package/dist/pi/packages/ta-initiative/lib/chat-kinds.js +15 -3
  77. package/dist/pi/packages/ta-initiative/lib/cron-proposals.js +20 -3
  78. package/dist/pi/packages/ta-initiative/lib/event-proposals.d.ts +2 -1
  79. package/dist/pi/packages/ta-initiative/lib/event-proposals.js +20 -6
  80. package/dist/pi/packages/ta-initiative/lib/i18n.d.ts +4 -0
  81. package/dist/pi/packages/ta-initiative/lib/i18n.js +155 -4
  82. package/dist/pi/packages/ta-initiative/lib/inbox.js +3 -2
  83. package/dist/pi/packages/ta-initiative/lib/initiative-protocol.d.ts +15 -4
  84. package/dist/pi/packages/ta-initiative/lib/initiative-protocol.js +11 -1
  85. package/dist/pi/packages/ta-initiative/lib/initiative-service.d.ts +1 -0
  86. package/dist/pi/packages/ta-initiative/lib/initiative-service.js +4 -1
  87. package/dist/pi/packages/ta-initiative/lib/initiative-store.js +5 -1
  88. package/dist/pi/packages/ta-initiative/lib/material-util.d.ts +2 -1
  89. package/dist/pi/packages/ta-initiative/lib/material-util.js +9 -3
  90. package/dist/pi/packages/ta-initiative/lib/review-service.js +1 -1
  91. package/dist/pi/packages/ta-initiative/lib/server-texts.d.ts +2 -1
  92. package/dist/pi/packages/ta-initiative/lib/server-texts.js +11 -4
  93. package/dist/pi/packages/ta-initiative/lib/settings.js +2 -3
  94. package/dist/pi/packages/ta-initiative/lib/style.d.ts +1 -1
  95. package/dist/pi/packages/ta-initiative/lib/style.js +1 -1
  96. package/dist/pi/packages/ta-initiative/package.json +9 -5
  97. package/dist/pi/packages/ta-initiative/web/index.js +207 -12
  98. package/dist/pi/packages/ta-launcher/lib/i18n.d.ts +3 -0
  99. package/dist/pi/packages/ta-launcher/lib/i18n.js +71 -2
  100. package/dist/pi/packages/ta-launcher/package.json +9 -5
  101. package/dist/pi/packages/ta-launcher/web/index.js +107 -1
  102. package/dist/pi/packages/ta-manual/README.en.md +1 -1
  103. package/dist/pi/packages/ta-manual/README.md +1 -1
  104. package/dist/pi/packages/ta-manual/lib/i18n.d.ts +3 -0
  105. package/dist/pi/packages/ta-manual/lib/i18n.js +21 -2
  106. package/dist/pi/packages/ta-manual/lib/manual-util.js +2 -1
  107. package/dist/pi/packages/ta-manual/lib/pictures-c.js +30 -0
  108. package/dist/pi/packages/ta-manual/lib/topics.d.ts +4 -0
  109. package/dist/pi/packages/ta-manual/lib/topics.js +188 -71
  110. package/dist/pi/packages/ta-manual/package.json +9 -5
  111. package/dist/pi/packages/ta-manual/skills/ta-manual/SKILL.md +9 -0
  112. package/dist/pi/packages/ta-manual/web/index.js +405 -119
  113. package/dist/pi/packages/ta-moments/extension/index.mjs +323 -147
  114. package/dist/pi/packages/ta-moments/host/index.mjs +350 -161
  115. package/dist/pi/packages/ta-moments/lib/editor.js +1 -1
  116. package/dist/pi/packages/ta-moments/lib/friends.d.ts +4 -1
  117. package/dist/pi/packages/ta-moments/lib/friends.js +3 -2
  118. package/dist/pi/packages/ta-moments/lib/i18n.d.ts +3 -0
  119. package/dist/pi/packages/ta-moments/lib/i18n.js +170 -3
  120. package/dist/pi/packages/ta-moments/lib/moments-host.js +25 -12
  121. package/dist/pi/packages/ta-moments/lib/moments-protocol.d.ts +2 -0
  122. package/dist/pi/packages/ta-moments/lib/page.js +8 -7
  123. package/dist/pi/packages/ta-moments/lib/post-util.js +2 -2
  124. package/dist/pi/packages/ta-moments/lib/server-texts.d.ts +10 -12
  125. package/dist/pi/packages/ta-moments/lib/server-texts.js +128 -62
  126. package/dist/pi/packages/ta-moments/lib/store.js +6 -0
  127. package/dist/pi/packages/ta-moments/lib/style.d.ts +1 -1
  128. package/dist/pi/packages/ta-moments/lib/style.js +4 -5
  129. package/dist/pi/packages/ta-moments/lib/talk-host.js +29 -8
  130. package/dist/pi/packages/ta-moments/package.json +9 -5
  131. package/dist/pi/packages/ta-moments/web/index.js +453 -192
  132. package/dist/pi/packages/ta-nearby/extension/index.mjs +229 -32
  133. package/dist/pi/packages/ta-nearby/host/index.mjs +437 -39
  134. package/dist/pi/packages/ta-nearby/lib/i18n.d.ts +3 -0
  135. package/dist/pi/packages/ta-nearby/lib/i18n.js +173 -2
  136. package/dist/pi/packages/ta-nearby/lib/nearby-net.js +2 -0
  137. package/dist/pi/packages/ta-nearby/lib/nearby-protocol.d.ts +11 -0
  138. package/dist/pi/packages/ta-nearby/lib/nearby-service.d.ts +5 -4
  139. package/dist/pi/packages/ta-nearby/lib/nearby-service.js +53 -10
  140. package/dist/pi/packages/ta-nearby/lib/page.js +15 -13
  141. package/dist/pi/packages/ta-nearby/lib/server-texts.d.ts +5 -13
  142. package/dist/pi/packages/ta-nearby/lib/server-texts.js +194 -42
  143. package/dist/pi/packages/ta-nearby/lib/style.d.ts +1 -1
  144. package/dist/pi/packages/ta-nearby/lib/style.js +1 -1
  145. package/dist/pi/packages/ta-nearby/package.json +9 -5
  146. package/dist/pi/packages/ta-nearby/web/index.js +223 -7
  147. package/dist/pi/packages/ta-notify/README.en.md +1 -0
  148. package/dist/pi/packages/ta-notify/README.md +1 -0
  149. package/dist/pi/packages/ta-notify/extension/index.mjs +54 -5
  150. package/dist/pi/packages/ta-notify/host/index.mjs +3 -0
  151. package/dist/pi/packages/ta-notify/lib/i18n.d.ts +3 -0
  152. package/dist/pi/packages/ta-notify/lib/i18n.js +53 -2
  153. package/dist/pi/packages/ta-notify/lib/notify-protocol.d.ts +2 -0
  154. package/dist/pi/packages/ta-notify/lib/notify-service.d.ts +1 -0
  155. package/dist/pi/packages/ta-notify/lib/notify-service.js +3 -0
  156. package/dist/pi/packages/ta-notify/lib/server-texts.d.ts +2 -1
  157. package/dist/pi/packages/ta-notify/lib/server-texts.js +16 -5
  158. package/dist/pi/packages/ta-notify/package.json +9 -5
  159. package/dist/pi/packages/ta-notify/web/index.js +89 -1
  160. package/dist/pi/packages/ta-recall/README.en.md +1 -1
  161. package/dist/pi/packages/ta-recall/README.md +1 -1
  162. package/dist/pi/packages/ta-recall/extension/index.mjs +52 -2
  163. package/dist/pi/packages/ta-recall/host/index.mjs +145 -67
  164. package/dist/pi/packages/ta-recall/lib/brief-util.d.ts +9 -6
  165. package/dist/pi/packages/ta-recall/lib/brief-util.js +26 -5
  166. package/dist/pi/packages/ta-recall/lib/extension-util.d.ts +2 -1
  167. package/dist/pi/packages/ta-recall/lib/extension-util.js +7 -1
  168. package/dist/pi/packages/ta-recall/lib/i18n.d.ts +3 -0
  169. package/dist/pi/packages/ta-recall/lib/i18n.js +89 -2
  170. package/dist/pi/packages/ta-recall/lib/keep-util.d.ts +2 -1
  171. package/dist/pi/packages/ta-recall/lib/keep-util.js +8 -1
  172. package/dist/pi/packages/ta-recall/lib/recall-service.d.ts +5 -3
  173. package/dist/pi/packages/ta-recall/lib/recall-service.js +16 -10
  174. package/dist/pi/packages/ta-recall/lib/server-texts.d.ts +2 -3
  175. package/dist/pi/packages/ta-recall/lib/server-texts.js +15 -8
  176. package/dist/pi/packages/ta-recall/package.json +9 -5
  177. package/dist/pi/packages/ta-recall/web/index.js +164 -9
  178. package/dist/pi/packages/ta-rooms/extension/index.mjs +60 -3
  179. package/dist/pi/packages/ta-rooms/host/index.mjs +284 -37
  180. package/dist/pi/packages/ta-rooms/lib/dialogs.js +2 -1
  181. package/dist/pi/packages/ta-rooms/lib/double-agents.js +31 -7
  182. package/dist/pi/packages/ta-rooms/lib/double-grants.js +57 -13
  183. package/dist/pi/packages/ta-rooms/lib/double-host.js +31 -5
  184. package/dist/pi/packages/ta-rooms/lib/double-i18n.d.ts +3 -0
  185. package/dist/pi/packages/ta-rooms/lib/double-i18n.js +201 -2
  186. package/dist/pi/packages/ta-rooms/lib/double-tasks.d.ts +2 -1
  187. package/dist/pi/packages/ta-rooms/lib/double-tasks.js +93 -21
  188. package/dist/pi/packages/ta-rooms/lib/double-user.js +1 -1
  189. package/dist/pi/packages/ta-rooms/lib/double-util.d.ts +1 -1
  190. package/dist/pi/packages/ta-rooms/lib/double-util.js +22 -3
  191. package/dist/pi/packages/ta-rooms/lib/doubles-store.js +2 -1
  192. package/dist/pi/packages/ta-rooms/lib/friend-notices.js +27 -8
  193. package/dist/pi/packages/ta-rooms/lib/friends-view.js +7 -8
  194. package/dist/pi/packages/ta-rooms/lib/i18n.d.ts +3 -0
  195. package/dist/pi/packages/ta-rooms/lib/i18n.js +243 -2
  196. package/dist/pi/packages/ta-rooms/lib/page.d.ts +12 -0
  197. package/dist/pi/packages/ta-rooms/lib/page.js +38 -3
  198. package/dist/pi/packages/ta-rooms/lib/style.d.ts +1 -1
  199. package/dist/pi/packages/ta-rooms/lib/style.js +1 -2
  200. package/dist/pi/packages/ta-rooms/package.json +9 -5
  201. package/dist/pi/packages/ta-rooms/web/index.js +537 -21
  202. package/dist/pi/packages/ta-share/extension/index.mjs +98 -23
  203. package/dist/pi/packages/ta-share/lib/i18n.d.ts +3 -0
  204. package/dist/pi/packages/ta-share/lib/i18n.js +203 -2
  205. package/dist/pi/packages/ta-share/lib/page.js +1 -1
  206. package/dist/pi/packages/ta-share/lib/server-texts.d.ts +2 -1
  207. package/dist/pi/packages/ta-share/lib/server-texts.js +60 -29
  208. package/dist/pi/packages/ta-share/package.json +9 -5
  209. package/dist/pi/packages/ta-share/web/index.js +240 -2
  210. package/dist/pi/packages/ta-sync/host/index.mjs +170 -25
  211. package/dist/pi/packages/ta-sync/lib/i18n.d.ts +3 -0
  212. package/dist/pi/packages/ta-sync/lib/i18n.js +175 -4
  213. package/dist/pi/packages/ta-sync/lib/migrate-i18n.d.ts +3 -0
  214. package/dist/pi/packages/ta-sync/lib/migrate-i18n.js +185 -4
  215. package/dist/pi/packages/ta-sync/lib/server-texts.d.ts +0 -1
  216. package/dist/pi/packages/ta-sync/lib/server-texts.js +132 -35
  217. package/dist/pi/packages/ta-sync/lib/style.d.ts +1 -1
  218. package/dist/pi/packages/ta-sync/lib/style.js +1 -1
  219. package/dist/pi/packages/ta-sync/package.json +9 -5
  220. package/dist/pi/packages/ta-sync/web/index.js +394 -7
  221. package/dist/pi/packages/ta-sync-cloud/host/index.mjs +52 -23
  222. package/dist/pi/packages/ta-sync-cloud/lib/host.js +49 -20
  223. package/dist/pi/packages/ta-sync-cloud/package.json +9 -5
  224. package/dist/pi/packages/ta-team/README.en.md +3 -1
  225. package/dist/pi/packages/ta-team/README.md +3 -1
  226. package/dist/pi/packages/ta-team/extension/index.mjs +86 -37
  227. package/dist/pi/packages/ta-team/host/index.mjs +694 -85
  228. package/dist/pi/packages/ta-team/lib/dialogs.js +140 -17
  229. package/dist/pi/packages/ta-team/lib/host.js +4 -0
  230. package/dist/pi/packages/ta-team/lib/i18n.d.ts +18 -1
  231. package/dist/pi/packages/ta-team/lib/i18n.js +455 -10
  232. package/dist/pi/packages/ta-team/lib/member-dialog.js +30 -25
  233. package/dist/pi/packages/ta-team/lib/members-tab.js +55 -8
  234. package/dist/pi/packages/ta-team/lib/page.d.ts +5 -0
  235. package/dist/pi/packages/ta-team/lib/page.js +19 -0
  236. package/dist/pi/packages/ta-team/lib/parts.d.ts +3 -1
  237. package/dist/pi/packages/ta-team/lib/parts.js +4 -3
  238. package/dist/pi/packages/ta-team/lib/policy.d.ts +24 -0
  239. package/dist/pi/packages/ta-team/lib/policy.js +32 -0
  240. package/dist/pi/packages/ta-team/lib/protocol.d.ts +22 -15
  241. package/dist/pi/packages/ta-team/lib/protocol.js +1 -3
  242. package/dist/pi/packages/ta-team/lib/shared-home.js +2 -2
  243. package/dist/pi/packages/ta-team/lib/style.d.ts +1 -1
  244. package/dist/pi/packages/ta-team/lib/style.js +19 -8
  245. package/dist/pi/packages/ta-team/lib/team-admin.js +1 -0
  246. package/dist/pi/packages/ta-team/lib/team-core.js +1 -0
  247. package/dist/pi/packages/ta-team/lib/team-invites.d.ts +80 -6
  248. package/dist/pi/packages/ta-team/lib/team-invites.js +239 -10
  249. package/dist/pi/packages/ta-team/lib/team-people.js +2 -0
  250. package/dist/pi/packages/ta-team/package.json +13 -5
  251. package/dist/pi/packages/ta-team/web/index.js +1028 -224
  252. package/dist/pi/packages/ta-workspace/lib/i18n.d.ts +3 -0
  253. package/dist/pi/packages/ta-workspace/lib/i18n.js +417 -1
  254. package/dist/pi/packages/ta-workspace/lib/style.d.ts +1 -1
  255. package/dist/pi/packages/ta-workspace/lib/style.js +2 -2
  256. package/dist/pi/packages/ta-workspace/package.json +10 -6
  257. package/dist/pi/packages/ta-workspace/web/index.js +714 -200
  258. package/dist/public/assets/GLTFLoader-C8PT6dAj.js +1 -0
  259. package/dist/public/assets/SkeletonUtils-BBAzQdty.js +1 -0
  260. package/dist/public/assets/{abnfDiagram-S7VZAUFO-C30pzFN3.js → abnfDiagram-S7VZAUFO-sclOP11q.js} +1 -1
  261. package/dist/public/assets/{architecture-WOLXFQ4H-wfYFQl2u.js → architecture-WOLXFQ4H-Bitg4Dpy.js} +1 -1
  262. package/dist/public/assets/{architectureDiagram-YGSQEFNW-B05zgxyT.js → architectureDiagram-YGSQEFNW-Hc0W5khF.js} +1 -1
  263. package/dist/public/assets/{blockDiagram-APKKGZFW-BhN8Bsu0.js → blockDiagram-APKKGZFW-D2ZWatLV.js} +1 -1
  264. package/dist/public/assets/{browser-DteLjv_-.js → browser-D-etIMuL.js} +1 -1
  265. package/dist/public/assets/{browser-D2CY3Lfb.js → browser-D2BcOPKG.js} +1 -1
  266. package/dist/public/assets/{c4Diagram-KJ2TOQU5-DvdF3qCV.js → c4Diagram-KJ2TOQU5-CWEcyfwV.js} +1 -1
  267. package/dist/public/assets/{chunk-6MUBBAK2-DNavkrnr.js → chunk-6MUBBAK2-CWbrJHxK.js} +1 -1
  268. package/dist/public/assets/{chunk-AXFCVDMN-DplVEqp_.js → chunk-AXFCVDMN-DJQdD4iX.js} +1 -1
  269. package/dist/public/assets/{chunk-BG4553SI-BazOaHvw.js → chunk-BG4553SI-CYiiJcBj.js} +1 -1
  270. package/dist/public/assets/{chunk-DQASFODM-DmoQWa8b.js → chunk-DQASFODM-NrNC1UeX.js} +1 -1
  271. package/dist/public/assets/{chunk-HFQBQIA3-Cj1m9ccz.js → chunk-HFQBQIA3-BIHXOwS2.js} +1 -1
  272. package/dist/public/assets/{chunk-KQLB2F66-_jbilrLX.js → chunk-KQLB2F66-CcU_AFwQ.js} +1 -1
  273. package/dist/public/assets/{chunk-KS47KZWR-CWU16Lut.js → chunk-KS47KZWR-DGfNbbcL.js} +1 -1
  274. package/dist/public/assets/{chunk-LEVMRMFU-wsbxWEZE.js → chunk-LEVMRMFU-B4PSS_Pp.js} +1 -1
  275. package/dist/public/assets/{chunk-M57EVK23-BGvmwwTv.js → chunk-M57EVK23-1555_mm4.js} +1 -1
  276. package/dist/public/assets/{chunk-OY52VR5R-Bp3hJ4kT.js → chunk-OY52VR5R-zbNEbYJ8.js} +1 -1
  277. package/dist/public/assets/{chunk-QB3YPZ4I-C1rQVxsJ.js → chunk-QB3YPZ4I-C-nNDGuN.js} +1 -1
  278. package/dist/public/assets/{chunk-R3KSYZAL-CEy0dKWn.js → chunk-R3KSYZAL-DcXXuhbl.js} +1 -1
  279. package/dist/public/assets/{chunk-STOXU5M4-akqvafwH.js → chunk-STOXU5M4-Bb77QkUj.js} +1 -1
  280. package/dist/public/assets/{chunk-TU62E6Q5-CVXAS4DS.js → chunk-TU62E6Q5-D8IJkNq5.js} +1 -1
  281. package/dist/public/assets/{chunk-X4PVCEUW-DT_bEMvQ.js → chunk-X4PVCEUW-BzejexgB.js} +1 -1
  282. package/dist/public/assets/{chunk-XXDRQBXY-Bgv_n5Qh.js → chunk-XXDRQBXY-D2GPHyll.js} +1 -1
  283. package/dist/public/assets/{classDiagram-v2-L25IHNXF-BtjQChpS.js → classDiagram-v2-L25IHNXF-CUEzxxI8.js} +1 -1
  284. package/dist/public/assets/{client-sUFoEC5s.js → client-C8gi9Fk2.js} +1 -1
  285. package/dist/public/assets/{common-CGQN5htF.js → common-DrZR0tgm.js} +2 -2
  286. package/dist/public/assets/{cose-bilkent-JH36ORCC-DSrOY8Uk.js → cose-bilkent-JH36ORCC-CJdgJyUw.js} +1 -1
  287. package/dist/public/assets/cynefin-EF2NZ3EQ-DBnkPRHn.js +1 -0
  288. package/dist/public/assets/{cynefinDiagram-L36ESFBY-DTy7FNFS.js → cynefinDiagram-L36ESFBY-D0F_9jN8.js} +1 -1
  289. package/dist/public/assets/{d3-selection-ip6rDUzY.js → d3-selection-BoARy1rP.js} +1 -1
  290. package/dist/public/assets/{dagre-SPEB5RXH-CHrks7Jb.js → dagre-SPEB5RXH-CzI5gZOv.js} +1 -1
  291. package/dist/public/assets/{diagram-3B7GL73J-eUJ7STAr.js → diagram-3B7GL73J-BCtNcE7M.js} +1 -1
  292. package/dist/public/assets/{diagram-DNEMPZML-B_fptNkg.js → diagram-DNEMPZML-DV9U4KeH.js} +1 -1
  293. package/dist/public/assets/{diagram-L3MUGCDN-C15owCSG.js → diagram-L3MUGCDN-DHU45Sd4.js} +1 -1
  294. package/dist/public/assets/{diagram-LA4NIPWU-Bfa1qEgY.js → diagram-LA4NIPWU-Ba5oVP56.js} +1 -1
  295. package/dist/public/assets/{diagram-MHCOC4E2-Bwxsih_Q.js → diagram-MHCOC4E2-B1Nk6qet.js} +1 -1
  296. package/dist/public/assets/{diagram-XPFHEONP-DKZ_lwah.js → diagram-XPFHEONP-DFwA3q09.js} +1 -1
  297. package/dist/public/assets/{dist-VHGBaby6.js → dist-Col1xVDT.js} +1 -1
  298. package/dist/public/assets/{ebnfDiagram-UZSYDL2S-CCkttvYi.js → ebnfDiagram-UZSYDL2S-BuBgxBJ2.js} +1 -1
  299. package/dist/public/assets/{editor.api-a2gC0dVD.js → editor.api-BLlyFz5x.js} +1 -1
  300. package/dist/public/assets/{elk-XV6XMXQE-DcikW39e.js → elk-XV6XMXQE-BPEI--zX.js} +1 -1
  301. package/dist/public/assets/{erDiagram-EYBAPDEH-BE3TV5lU.js → erDiagram-EYBAPDEH-Cci0kYUw.js} +1 -1
  302. package/dist/public/assets/{eventmodeling-K75KTNOO-C2s1kutf.js → eventmodeling-K75KTNOO-B0eT5X1_.js} +1 -1
  303. package/dist/public/assets/flowDiagram-MALGAFMO-CmMdmAxj.js +1 -0
  304. package/dist/public/assets/{freemarker2-2e8pZojb.js → freemarker2-CAZGFA3W.js} +1 -1
  305. package/dist/public/assets/{ganttDiagram-23REXITY-rGnJptii.js → ganttDiagram-23REXITY-DEm85e1I.js} +1 -1
  306. package/dist/public/assets/gitGraph-VSP46ZUC-DKo3OVhR.js +1 -0
  307. package/dist/public/assets/{gitGraphDiagram-STJD7YCW-CNnsDjQA.js → gitGraphDiagram-STJD7YCW-DJAZD2LR.js} +1 -1
  308. package/dist/public/assets/{handlebars-CMKN6E37.js → handlebars-Agkl4nGr.js} +1 -1
  309. package/dist/public/assets/{html-0AjXQhkQ.js → html-Cu-CsqZI.js} +1 -1
  310. package/dist/public/assets/{index-TUtoc8CW.js → index-TeLHaE4u.js} +2 -2
  311. package/dist/public/assets/info-OHQRW6UA-tKl26QqM.js +1 -0
  312. package/dist/public/assets/{infoDiagram-KBXO4MBG-DMKs8cuE.js → infoDiagram-KBXO4MBG-4zHsBnIy.js} +1 -1
  313. package/dist/public/assets/{ishikawaDiagram-M35NCXHK-Dg_IbA0G.js → ishikawaDiagram-M35NCXHK-Bg8OYLGr.js} +1 -1
  314. package/dist/public/assets/ja-BHBiml1x.js +12 -0
  315. package/dist/public/assets/{javascript-CqYOqPjw.js → javascript-BdMDRX8l.js} +1 -1
  316. package/dist/public/assets/{journeyDiagram-OPLOXDXO-ohAOfoEY.js → journeyDiagram-OPLOXDXO-B2xtzmpE.js} +1 -1
  317. package/dist/public/assets/{jsonMode-D-gI-S5H.js → jsonMode-Dg92qQvX.js} +1 -1
  318. package/dist/public/assets/{kanban-definition-BZKZHSQY-w-aKZS_U.js → kanban-definition-BZKZHSQY-DQ4N7t_w.js} +1 -1
  319. package/dist/public/assets/{liquid-oBN7c8NZ.js → liquid-BydEnYkh.js} +1 -1
  320. package/dist/public/assets/{mdx-CnwhgGjX.js → mdx-XZXeM7ll.js} +1 -1
  321. package/dist/public/assets/{mermaid-parser.core-CfFkSR0t.js → mermaid-parser.core-H24--uw9.js} +3 -3
  322. package/dist/public/assets/{mermaid.core-apiVCSBY.js → mermaid.core-BmCrSjUU.js} +4 -4
  323. package/dist/public/assets/meshopt_decoder.module-DXTYc6wn.js +1 -0
  324. package/dist/public/assets/{mindmap-definition-I2QAS2VK-E7vqVWB0.js → mindmap-definition-I2QAS2VK-CGQXKItp.js} +1 -1
  325. package/dist/public/assets/module-1mERtQ0Z.js +1 -0
  326. package/dist/public/assets/module-BxIQdJqY.js +2449 -0
  327. package/dist/public/assets/{module-B8jze-Tx.js → module-Cm_mLwAQ.js} +1 -1
  328. package/dist/public/assets/module-DDH-aU6z.js +1 -0
  329. package/dist/public/assets/module-DRofmFJn.js +1 -0
  330. package/dist/public/assets/{module-ZhkaqrNe.js → module-DUYj4E8T.js} +1 -1
  331. package/dist/public/assets/module-MaD4hvv4.js +1 -0
  332. package/dist/public/assets/module-ZDJutm0b.js +1 -0
  333. package/dist/public/assets/module-qoBVcE5h.js +1 -0
  334. package/dist/public/assets/{monaco-C0ByxW3l.js → monaco-DP8M_Ttp.js} +3 -3
  335. package/dist/public/assets/packet-JDAUHWVQ-CnBx3hR7.js +1 -0
  336. package/dist/public/assets/{pegDiagram-FD4XPPHP--RpwCE7x.js → pegDiagram-FD4XPPHP-CXKRGFUs.js} +1 -1
  337. package/dist/public/assets/pie-XZMESJXO-hogxgeR2.js +1 -0
  338. package/dist/public/assets/{pieDiagram-J4AKIIQI-DxSbPaRZ.js → pieDiagram-J4AKIIQI-9XEDP1wR.js} +1 -1
  339. package/dist/public/assets/{python-vNPe_Fao.js → python-C-0PA82u.js} +1 -1
  340. package/dist/public/assets/{quadrantDiagram-XTYBLID2-CR_eeYXi.js → quadrantDiagram-XTYBLID2-C-uxTp-5.js} +1 -1
  341. package/dist/public/assets/radar-ABXABTNO-CdWiN8Cw.js +1 -0
  342. package/dist/public/assets/railroad-I3PHUGI6-DnYOBI5V.js +1 -0
  343. package/dist/public/assets/{railroad-abnf-LNEFI6M7-D6I2HxIC.js → railroad-abnf-LNEFI6M7-CTft_ST0.js} +1 -1
  344. package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-BuhDRGo3.js → railroad-ebnf-DWYD2UWJ-DfRJhL7G.js} +1 -1
  345. package/dist/public/assets/{railroad-peg-JR7BVNR7-n15PB7Sb.js → railroad-peg-JR7BVNR7-DFePx4YD.js} +1 -1
  346. package/dist/public/assets/{railroadDiagram-MRQ6NCDL-Bbe5bNap.js → railroadDiagram-MRQ6NCDL-BmK1KUsT.js} +1 -1
  347. package/dist/public/assets/{razor-CnKbF0Yz.js → razor-DEKNSiT7.js} +1 -1
  348. package/dist/public/assets/{requirementDiagram-Y7LWUY3S-Beuygh9j.js → requirementDiagram-Y7LWUY3S-Ds27pS9Y.js} +1 -1
  349. package/dist/public/assets/{resolver-B7c_-amj.js → resolver-0zC31mg5.js} +1 -1
  350. package/dist/public/assets/{sankeyDiagram-WGJFYUXA-jwWPgnrS.js → sankeyDiagram-WGJFYUXA-e2OTzBma.js} +1 -1
  351. package/dist/public/assets/{sequenceDiagram-5NDRBG5M-CmU-HYQI.js → sequenceDiagram-5NDRBG5M-BcoIpxF6.js} +1 -1
  352. package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-Bo7BEi-m.js → stateDiagram-v2-FJ4FJNEA-CNr67mC9.js} +1 -1
  353. package/dist/public/assets/{swimlanes-UMQ2AFYF-PSKyZN_b.js → swimlanes-UMQ2AFYF-DKPgHCev.js} +1 -1
  354. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-U0uzjboz.js +8 -0
  355. package/dist/public/assets/{timeline-definition-SEUHKTQE-BuRxLScZ.js → timeline-definition-SEUHKTQE-BcCmuE6C.js} +1 -1
  356. package/dist/public/assets/treeView-D4JQ5SDB-4ppY0Rs5.js +1 -0
  357. package/dist/public/assets/treemap-SAJKECNS-CAvLAs7q.js +1 -0
  358. package/dist/public/assets/{typescript-C00ztMLg.js → typescript-B1Uk3m6A.js} +1 -1
  359. package/dist/public/assets/{usecaseDiagram-AFA6YXN4-Dlvyos8r.js → usecaseDiagram-AFA6YXN4-BpCD8dP7.js} +1 -1
  360. package/dist/public/assets/{vennDiagram-NNMJR3RB-CuLZubJH.js → vennDiagram-NNMJR3RB-CQjX5_-8.js} +1 -1
  361. package/dist/public/assets/wardley-7MLQ67FV-D_F3qmRJ.js +1 -0
  362. package/dist/public/assets/{wardleyDiagram-S7YFUSEH-WOGGTs4y.js → wardleyDiagram-S7YFUSEH-D7gYo9fV.js} +1 -1
  363. package/dist/public/assets/{xml-CHBFuf5n.js → xml-DBh_LekU.js} +1 -1
  364. package/dist/public/assets/{xychartDiagram-GGNKY7IX-DwW9eifP.js → xychartDiagram-GGNKY7IX-B_1aOZKU.js} +1 -1
  365. package/dist/public/assets/{yaml-C4qkqzcL.js → yaml-BE55tHva.js} +1 -1
  366. package/dist/public/assets/zh-tw-7q-tizR0.js +12 -0
  367. package/dist/public/index.html +2 -2
  368. package/dist/serve/index.mjs +3115 -1400
  369. package/package.json +39 -39
  370. package/dist/pi/packages/ta-team/lib/join.d.ts +0 -28
  371. package/dist/pi/packages/ta-team/lib/join.js +0 -48
  372. package/dist/pi/packages/ta-team/lib/remote.d.ts +0 -31
  373. package/dist/pi/packages/ta-team/lib/remote.js +0 -128
  374. package/dist/pi/packages/ta-team/lib/seal.d.ts +0 -28
  375. package/dist/pi/packages/ta-team/lib/seal.js +0 -75
  376. package/dist/public/assets/cynefin-EF2NZ3EQ-DYlwwGUb.js +0 -1
  377. package/dist/public/assets/flowDiagram-MALGAFMO-Bufgn1OL.js +0 -1
  378. package/dist/public/assets/gitGraph-VSP46ZUC-D_tzR9z9.js +0 -1
  379. package/dist/public/assets/info-OHQRW6UA-C5Pwv-6e.js +0 -1
  380. package/dist/public/assets/module-Blc8dqbf.js +0 -1
  381. package/dist/public/assets/module-C2jtFD0v.js +0 -2365
  382. package/dist/public/assets/module-C9WFrzAc.js +0 -1
  383. package/dist/public/assets/module-CouMtASh.js +0 -1
  384. package/dist/public/assets/module-EGdAhoOx.js +0 -1
  385. package/dist/public/assets/module-EeaigZHL.js +0 -1
  386. package/dist/public/assets/module-xT4L5yYw.js +0 -1
  387. package/dist/public/assets/packet-JDAUHWVQ-xozI7a9T.js +0 -1
  388. package/dist/public/assets/pie-XZMESJXO-BkHXIzDi.js +0 -1
  389. package/dist/public/assets/radar-ABXABTNO-CaUh9zV3.js +0 -1
  390. package/dist/public/assets/railroad-I3PHUGI6-DckPvlDe.js +0 -1
  391. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-z_0ABNQq.js +0 -8
  392. package/dist/public/assets/treeView-D4JQ5SDB-BN38Jg9j.js +0 -1
  393. package/dist/public/assets/treemap-SAJKECNS-CKdz7u7W.js +0 -1
  394. 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,1093 @@ 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();
1850
- }
1851
- get empty() {
1852
- return this.values.size === 0;
1861
+ this.cipher.seal(text).then((frame) => this.socket.readyState === OPEN && this.socket.send(frame));
1853
1862
  }
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 });
1868
- 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);
1875
- }
1876
- for (const id of FileRelayStorage.ids(join7(options.data, "hubs"))) {
1877
- this.hubOf(id);
1878
- }
1863
+ close(code = 1000, reason = "") {
1864
+ if (this.state === CLOSED) {
1865
+ return;
1879
1866
  }
1867
+ this.state = CLOSING;
1868
+ this.socket.close(code, reason);
1880
1869
  }
1881
- listen() {
1882
- const server = createServer2((request, response) => {
1883
- 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));
1889
- return;
1890
- }
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
- });
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));
1898
1875
  return;
1899
1876
  }
1900
- if (path === RELAY_ROOM_PATH) {
1901
- response.writeHead(200, { ...RELAY_VIEWER_HEADERS, "x-frame-options": "DENY" });
1902
- response.end(RelayViewer.room());
1903
- return;
1877
+ try {
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.");
1904
1882
  }
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());
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.");
1912
1889
  return;
1913
1890
  }
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.");
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.");
1935
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.");
1936
1904
  }
1937
- for (const { storage } of this.hubs.values()) {
1938
- (_b = (_a = storage).close) === null || _b === undefined || _b.call(_a);
1939
- }
1940
- for (const { storage } of this.blobs.values()) {
1941
- (_d = (_c = storage).close) === null || _d === undefined || _d.call(_c);
1905
+ }
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";
1942
1912
  }
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
- }
1913
+ }
1914
+ ping() {
1915
+ if (this.awaitingPong && this.ponged) {
1916
+ this.drop(RelayCloseCode.TIMEOUT, "The relay did not answer.");
1917
+ return;
1948
1918
  }
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
- }
1919
+ this.awaitingPong = true;
1920
+ if (this.socket.readyState === OPEN) {
1921
+ this.socket.send(RELAY_PING);
1955
1922
  }
1956
- this.rooms.clear();
1957
- return new Promise((resolve2) => this.server ? this.server.close(() => resolve2()) : resolve2());
1958
1923
  }
1959
- async blob(id, request, response) {
1924
+ drop(code, reason) {
1925
+ this.close(code, reason);
1926
+ this.finish(code, reason);
1927
+ }
1928
+ finish(code, reason) {
1960
1929
  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
- `);
1930
+ if (this.state === CLOSED) {
1969
1931
  return;
1970
1932
  }
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;
1982
- 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
- }
1989
- }
1990
- response.writeHead(answer.status, Object.fromEntries(answer.headers));
1991
- response.end(Buffer.from(await answer.arrayBuffer()));
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 });
1992
1938
  }
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;
2008
- }
2009
- claimsFile() {
2010
- return join7(this.options.data, "hosts.json");
2011
- }
2012
- saveClaims() {
2013
- if (!this.options.data) {
2014
- return;
2015
- }
2016
- const file = this.claimsFile();
2017
- writeFileSync5(`${file}.tmp`, JSON.stringify(Object.fromEntries(this.claims)), { mode: 384 });
2018
- renameSync3(`${file}.tmp`, file);
2019
- }
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);
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
+ if (link.language) {
1995
+ fragment.set("l", link.language);
1996
+ }
1997
+ return `${link.relay.replace(/\/+$/, "")}${RELAY_JOIN_PATH}#${fragment}`;
1998
+ }
1999
+ RelayTeamLinkUtil2.format = format;
2000
+ function parse(text) {
2001
+ var _a;
2002
+ var _b, _c, _d;
2003
+ let url;
2004
+ try {
2005
+ url = new URL(text.trim());
2006
+ } catch (_e) {
2007
+ return;
2008
+ }
2009
+ const fragment = new URLSearchParams(url.hash.slice(1));
2010
+ const [host, device, key] = ["h", "d", "k"].map((name) => {
2011
+ var _a2;
2012
+ return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
2036
2013
  });
2037
- request.on("end", () => size >= 0 && resolve2(Buffer.concat(chunks)));
2038
- request.on("error", reject);
2039
- });
2040
- }
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);
2047
- return;
2014
+ 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)) {
2015
+ return;
2016
+ }
2017
+ const what = (_a = fragment.get("w")) === null || _a === undefined ? undefined : _a.slice(0, 80);
2018
+ const language = (_b = fragment.get("l")) !== null && _b !== undefined ? _b : "";
2019
+ return {
2020
+ relay: url.origin,
2021
+ host,
2022
+ device,
2023
+ key,
2024
+ owner: (_c = fragment.get("o")) !== null && _c !== undefined ? _c : "",
2025
+ role: (_d = fragment.get("r")) !== null && _d !== undefined ? _d : "",
2026
+ ...what ? { what } : {},
2027
+ .../^[a-z]{2}(-[A-Za-z]{2,4})?$/.test(language) ? { language } : {}
2028
+ };
2048
2029
  }
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.");
2030
+ RelayTeamLinkUtil2.parse = parse;
2031
+ function signInFor(link, provider, handoff) {
2032
+ return `${format(link)}&${new URLSearchParams({ p: provider, x: handoff })}`;
2033
+ }
2034
+ RelayTeamLinkUtil2.signInFor = signInFor;
2035
+ function handoffOf(text) {
2036
+ var _a, _b;
2037
+ let url;
2038
+ try {
2039
+ url = new URL(text.trim());
2040
+ } catch (_c) {
2053
2041
  return;
2054
2042
  }
2055
- this.openHub(id2, WebSocketConnection.open(socket, checked.key, head, WEBSOCKET));
2056
- return;
2043
+ const fragment = new URLSearchParams(url.hash.slice(1));
2044
+ const provider = (_a = fragment.get("p")) !== null && _a !== undefined ? _a : "";
2045
+ const handoff = (_b = fragment.get("x")) !== null && _b !== undefined ? _b : "";
2046
+ return /^[a-z0-9_-]{1,32}$/.test(provider) && /^[A-Za-z0-9_-]{16,64}$/.test(handoff) ? { provider, handoff } : undefined;
2057
2047
  }
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.");
2048
+ RelayTeamLinkUtil2.handoffOf = handoffOf;
2049
+ function web(relay, pairing) {
2050
+ return `${relay.replace(/\/+$/, "")}${RELAY_WEB_PATH}#${new URLSearchParams({ pair: pairing })}`;
2051
+ }
2052
+ RelayTeamLinkUtil2.web = web;
2053
+ })(RelayTeamLinkUtil || (RelayTeamLinkUtil = {}));
2054
+ });
2055
+
2056
+ // ../../ta-packages/ta-relay/esm/common/relay-web.js
2057
+ var TYPES, RelayWebUtil;
2058
+ var init_relay_web = __esm(() => {
2059
+ init_relay_team();
2060
+ TYPES = {
2061
+ html: "text/html; charset=utf-8",
2062
+ js: "text/javascript; charset=utf-8",
2063
+ mjs: "text/javascript; charset=utf-8",
2064
+ css: "text/css; charset=utf-8",
2065
+ json: "application/json",
2066
+ webmanifest: "application/manifest+json",
2067
+ svg: "image/svg+xml",
2068
+ png: "image/png",
2069
+ jpg: "image/jpeg",
2070
+ webp: "image/webp",
2071
+ ico: "image/x-icon",
2072
+ woff2: "font/woff2",
2073
+ woff: "font/woff",
2074
+ ttf: "font/ttf",
2075
+ wasm: "application/wasm",
2076
+ txt: "text/plain; charset=utf-8"
2077
+ };
2078
+ (function(RelayWebUtil2) {
2079
+ function index(html) {
2080
+ return html.replace(/<base href="\/">/, `<base href="${RELAY_WEB_PATH}">`);
2081
+ }
2082
+ RelayWebUtil2.index = index;
2083
+ function file(path) {
2084
+ if (!path.startsWith(RELAY_WEB_PATH)) {
2062
2085
  return;
2063
2086
  }
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.");
2087
+ const rest = path.slice(RELAY_WEB_PATH.length) || "index.html";
2088
+ const parts = rest.split("/");
2089
+ if (parts.some((part) => !part || part === "." || part === ".." || !/^[\w.@-]+$/.test(part))) {
2069
2090
  return;
2070
2091
  }
2071
- this.openSpot(id2, connection2, address);
2072
- return;
2092
+ return rest;
2073
2093
  }
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;
2094
+ RelayWebUtil2.file = file;
2095
+ function headers(file2) {
2096
+ var _a;
2097
+ const type = (_a = TYPES[file2.slice(file2.lastIndexOf(".") + 1).toLowerCase()]) !== null && _a !== undefined ? _a : "application/octet-stream";
2098
+ const page = file2 === "index.html";
2099
+ return {
2100
+ "content-type": type,
2101
+ "cache-control": file2.startsWith("assets/") ? "public, max-age=31536000, immutable, no-transform" : "no-cache, no-transform",
2102
+ "x-content-type-options": "nosniff",
2103
+ "referrer-policy": "no-referrer",
2104
+ ...page ? { "x-frame-options": "DENY" } : {}
2105
+ };
2078
2106
  }
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);
2107
+ RelayWebUtil2.headers = headers;
2108
+ })(RelayWebUtil || (RelayWebUtil = {}));
2109
+ });
2110
+
2111
+ // ../../ta-packages/ta-relay/esm/node/relay-file-storage.js
2112
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync5, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
2113
+ import { join as join5 } from "node:path";
2114
+
2115
+ class FileRelayStorage {
2116
+ constructor(dir, onAlarm) {
2117
+ this.dir = dir;
2118
+ this.onAlarm = onAlarm;
2119
+ this.file = join5(dir, "values.json");
2120
+ this.values = FileRelayStorage.load(this.file);
2121
+ const alarm = this.values.get(ALARM);
2122
+ if (typeof alarm === "number") {
2123
+ this.schedule(alarm);
2084
2124
  }
2085
2125
  }
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();
2092
- }
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;
2097
- }
2098
- if (room.host) {
2099
- room.host.close(RelayCloseCode.REPLACED, "The host connected again.");
2100
- room.relay.hostClosed();
2126
+ static ids(root) {
2127
+ try {
2128
+ return readdirSync2(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
2129
+ } catch (_a) {
2130
+ return [];
2101
2131
  }
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();
2132
+ }
2133
+ get empty() {
2134
+ return [...this.values.keys()].every((key) => key === ALARM);
2135
+ }
2136
+ async get(key) {
2137
+ const value = this.values.get(key);
2138
+ return value === undefined ? undefined : structuredClone(value);
2139
+ }
2140
+ async put(key, value) {
2141
+ this.values.set(key, structuredClone(value));
2142
+ this.save();
2143
+ }
2144
+ async delete(key) {
2145
+ const had = this.values.delete(key);
2146
+ this.save();
2147
+ return had;
2148
+ }
2149
+ async list(options) {
2150
+ const found = new Map;
2151
+ for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
2152
+ if (key !== ALARM && key.startsWith(options.prefix)) {
2153
+ found.set(key, structuredClone(value));
2108
2154
  }
2109
- });
2155
+ }
2156
+ return found;
2110
2157
  }
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.");
2158
+ async deleteAll() {
2159
+ this.values.clear();
2160
+ clearTimeout(this.timer);
2161
+ rmSync2(this.dir, { recursive: true, force: true });
2162
+ }
2163
+ async setAlarm(at) {
2164
+ this.values.set(ALARM, at);
2165
+ this.save();
2166
+ this.schedule(at);
2167
+ }
2168
+ close() {
2169
+ clearTimeout(this.timer);
2170
+ }
2171
+ schedule(at) {
2172
+ var _a, _b;
2173
+ clearTimeout(this.timer);
2174
+ const wait = Math.max(at - Date.now(), 0);
2175
+ this.timer = setTimeout(() => {
2176
+ var _a2;
2177
+ return wait > 2 ** 31 - 1 ? this.schedule(at) : (_a2 = this.onAlarm) === null || _a2 === undefined ? undefined : _a2.call(this);
2178
+ }, Math.min(wait, 2 ** 31 - 1));
2179
+ (_b = (_a = this.timer).unref) === null || _b === undefined || _b.call(_a);
2180
+ }
2181
+ save() {
2182
+ if (this.empty) {
2183
+ rmSync2(this.dir, { recursive: true, force: true });
2119
2184
  return;
2120
2185
  }
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
- });
2186
+ mkdirSync4(this.dir, { recursive: true, mode: 448 });
2187
+ const temporary = `${this.file}.${process.pid}.tmp`;
2188
+ writeFileSync4(temporary, JSON.stringify(Object.fromEntries([...this.values].map(([key, value]) => [key, encode(value)]))), { mode: 384 });
2189
+ renameSync2(temporary, this.file);
2127
2190
  }
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);
2191
+ static load(file) {
2192
+ try {
2193
+ const data = JSON.parse(readFileSync5(file, "utf8"));
2194
+ return new Map(Object.entries(data).map(([key, stored]) => [key, decode(stored)]));
2195
+ } catch (_a) {
2196
+ return new Map;
2160
2197
  }
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);
2198
+ }
2199
+ }
2200
+ 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";
2201
+ var init_relay_file_storage = __esm(() => {
2202
+ init_relay_bytes();
2203
+ });
2204
+
2205
+ // ../../ta-packages/ta-relay/esm/node/relay-viewer.js
2206
+ import { fileURLToPath as __cellFileURLToPath3 } from "node:url";
2207
+ import { dirname as __cellDirname3 } from "node:path";
2208
+ import { readFileSync as readFileSync6 } from "node:fs";
2209
+ import { join as joinPath } from "node:path";
2210
+ var __filename4, __dirname4, RelayViewer;
2211
+ var init_relay_viewer = __esm(() => {
2212
+ __filename4 = __cellFileURLToPath3(import.meta.url);
2213
+ __dirname4 = __cellDirname3(__filename4);
2214
+ (function(RelayViewer2) {
2215
+ let pages;
2216
+ function read() {
2217
+ if (!pages) {
2218
+ const dir = joinPath(__dirname4, "../../viewer");
2219
+ const file = (name) => readFileSync6(joinPath(dir, name), "utf8");
2220
+ pages = { page: file("page.html"), frame: file("frame.html"), room: file("room.html"), join: file("join.html") };
2173
2221
  }
2174
- });
2222
+ return pages;
2223
+ }
2224
+ function room() {
2225
+ return read().room;
2226
+ }
2227
+ RelayViewer2.room = room;
2228
+ function join6() {
2229
+ return read().join;
2230
+ }
2231
+ RelayViewer2.join = join6;
2232
+ function page() {
2233
+ return read().page;
2234
+ }
2235
+ RelayViewer2.page = page;
2236
+ function frame() {
2237
+ return read().frame;
2238
+ }
2239
+ RelayViewer2.frame = frame;
2240
+ })(RelayViewer || (RelayViewer = {}));
2241
+ });
2242
+
2243
+ // ../../ta-packages/ta-relay/esm/node/relay-server.js
2244
+ var exports_relay_server = {};
2245
+ __export(exports_relay_server, {
2246
+ RelayServer: () => RelayServer
2247
+ });
2248
+ import { createHash as createHash2, randomBytes, timingSafeEqual } from "node:crypto";
2249
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, renameSync as renameSync3, statSync, writeFileSync as writeFileSync5 } from "node:fs";
2250
+ import { createServer as createServer2 } from "node:http";
2251
+ import { join as join6 } from "node:path";
2252
+
2253
+ class MemoryBlobStorage {
2254
+ constructor() {
2255
+ this.values = new Map;
2175
2256
  }
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
- });
2257
+ async get(key) {
2258
+ return this.values.get(key);
2210
2259
  }
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;
2260
+ async put(key, value) {
2261
+ this.values.set(key, value);
2241
2262
  }
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
- }
2263
+ async deleteAll() {
2264
+ this.values.clear();
2265
+ clearTimeout(this.timer);
2246
2266
  }
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;
2267
+ get empty() {
2268
+ return this.values.size === 0;
2262
2269
  }
2263
- static same(a, b) {
2264
- const [left, right] = [Buffer.from(a), Buffer.from(b)];
2265
- return left.length === right.length && timingSafeEqual(left, right);
2270
+ async setAlarm(at) {
2271
+ var _a, _b;
2272
+ clearTimeout(this.timer);
2273
+ this.timer = setTimeout(() => this.values.clear(), Math.min(Math.max(at - Date.now(), 0), 2 ** 31 - 1));
2274
+ (_b = (_a = this.timer).unref) === null || _b === undefined || _b.call(_a);
2266
2275
  }
2267
2276
  }
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
2277
 
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();
2278
+ class MemoryHubStorage {
2279
+ constructor() {
2280
+ this.values = new Map;
2292
2281
  }
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);
2282
+ async get(key) {
2283
+ const value = this.values.get(key);
2284
+ return value === undefined ? undefined : structuredClone(value);
2300
2285
  }
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;
2286
+ async put(key, value) {
2287
+ this.values.set(key, structuredClone(value));
2311
2288
  }
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));
2289
+ async delete(key) {
2290
+ return this.values.delete(key);
2291
+ }
2292
+ async list(options) {
2293
+ const found = new Map;
2294
+ for (const [key, value] of [...this.values].sort(([a], [b]) => a.localeCompare(b))) {
2295
+ if (key.startsWith(options.prefix)) {
2296
+ found.set(key, structuredClone(value));
2297
+ }
2298
+ }
2299
+ return found;
2300
+ }
2301
+ async deleteAll() {
2302
+ this.values.clear();
2303
+ }
2304
+ get empty() {
2305
+ return this.values.size === 0;
2306
+ }
2307
+ }
2308
+
2309
+ class RelayServer {
2310
+ constructor(options = {}) {
2311
+ this.options = options;
2312
+ this.rooms = new Map;
2313
+ this.blobs = new Map;
2314
+ this.claims = new Map;
2315
+ this.hubs = new Map;
2316
+ this.spots = new Map;
2317
+ this.spotTries = new Map;
2318
+ this.spotAddresses = new WeakMap;
2319
+ if (options.data) {
2320
+ mkdirSync5(options.data, { recursive: true, mode: 448 });
2321
+ try {
2322
+ for (const [id, hash] of Object.entries(JSON.parse(readFileSync7(this.claimsFile(), "utf8")))) {
2323
+ this.claims.set(id, hash);
2324
+ }
2325
+ } catch (_a) {}
2326
+ for (const id of FileRelayStorage.ids(join6(options.data, "blobs"))) {
2327
+ this.blobCopy(id);
2328
+ }
2329
+ for (const id of FileRelayStorage.ids(join6(options.data, "hubs"))) {
2330
+ this.hubOf(id);
2331
+ }
2332
+ }
2333
+ }
2334
+ listen() {
2335
+ const server = createServer2((request, response) => {
2336
+ var _a;
2337
+ const path = ((_a = request.url) !== null && _a !== undefined ? _a : "/").split(/[?#]/)[0];
2338
+ if (path === RELAY_INFO_PATH) {
2339
+ const info = RelayInfoUtil.of(!!this.options.data);
2340
+ response.writeHead(200, { "content-type": "application/json", "access-control-allow-origin": "*", "cache-control": "no-store" });
2341
+ response.end(JSON.stringify(info));
2342
+ return;
2343
+ }
2344
+ if (path.startsWith(RELAY_BLOB_PATH)) {
2345
+ this.blob(path.slice(RELAY_BLOB_PATH.length), request, response).catch(() => {
2346
+ if (!response.headersSent) {
2347
+ response.writeHead(400);
2348
+ }
2349
+ response.end();
2350
+ });
2351
+ return;
2352
+ }
2353
+ if (path === RELAY_ROOM_PATH || path === RELAY_JOIN_PATH) {
2354
+ response.writeHead(200, { ...RELAY_VIEWER_HEADERS, "x-frame-options": "DENY" });
2355
+ response.end(path === RELAY_ROOM_PATH ? RelayViewer.room() : RelayViewer.join());
2356
+ return;
2357
+ }
2358
+ if (path.startsWith(RELAY_WEB_PATH) || path === RELAY_WEB_PATH.slice(0, -1)) {
2359
+ this.web(path, response);
2360
+ return;
2361
+ }
2362
+ if (path === RELAY_CONTENT_PATH || path === RELAY_FRAME_PATH) {
2363
+ const frame = path === RELAY_FRAME_PATH;
2364
+ response.writeHead(200, {
2365
+ ...RELAY_VIEWER_HEADERS,
2366
+ ...frame ? { "content-security-policy": RELAY_FRAME_HEADER_CSP } : { "x-frame-options": "DENY" }
2367
+ });
2368
+ response.end(frame ? RelayViewer.frame() : RelayViewer.page());
2369
+ return;
2370
+ }
2371
+ const page = path === RELAY_PAIR_PATH ? RELAY_PAIR_PAGE : path === RELAY_SHARE_PATH ? RELAY_SHARE_PAGE : undefined;
2372
+ response.writeHead(200, { "content-type": page ? "text/html; charset=utf-8" : "text/plain" });
2373
+ response.end(page !== null && page !== undefined ? page : `Ta relay
2374
+ `);
2317
2375
  });
2318
- this.opening = opened.catch(() => {
2319
- return;
2376
+ server.on("upgrade", (request, socket, head) => this.upgrade(request, socket, head));
2377
+ this.server = server;
2378
+ return new Promise((resolve2, reject) => {
2379
+ var _a, _b;
2380
+ server.once("error", reject);
2381
+ server.listen((_a = this.options.port) !== null && _a !== undefined ? _a : 0, (_b = this.options.host) !== null && _b !== undefined ? _b : "127.0.0.1", () => {
2382
+ const { address, port } = server.address();
2383
+ resolve2(`http://${address.includes(":") ? `[${address}]` : address}:${port}`);
2384
+ });
2320
2385
  });
2321
- return opened;
2322
2386
  }
2323
- async pack(text) {
2324
- const bytes = encoder2.encode(text);
2325
- if (!this.compress) {
2326
- return bytes;
2387
+ web(path, response) {
2388
+ var _a;
2389
+ if (path === RELAY_WEB_PATH.slice(0, -1)) {
2390
+ response.writeHead(308, { location: RELAY_WEB_PATH });
2391
+ response.end();
2392
+ return;
2327
2393
  }
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);
2330
- }
2331
- async unpack(bytes) {
2332
- if (!this.compress) {
2333
- return decoder2.decode(bytes);
2394
+ const file = RelayWebUtil.file(path);
2395
+ const full = file && this.options.web ? join6(this.options.web, file) : undefined;
2396
+ if (!file || !full || !((_a = statSync(full, { throwIfNoEntry: false })) === null || _a === undefined ? undefined : _a.isFile())) {
2397
+ response.writeHead(404, { "content-type": "text/plain" });
2398
+ response.end(`Not found.
2399
+ `);
2400
+ return;
2334
2401
  }
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;
2402
+ const body = readFileSync7(full);
2403
+ response.writeHead(200, RelayWebUtil.headers(file));
2404
+ response.end(file === "index.html" ? RelayWebUtil.index(body.toString("utf8")) : body);
2343
2405
  }
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
- }
2406
+ close() {
2407
+ var _a, _b, _c, _d, _e;
2408
+ for (const { sockets } of this.hubs.values()) {
2409
+ for (const connection of sockets.keys()) {
2410
+ connection.close(1001, "The relay is stopping.");
2361
2411
  }
2362
- return support;
2363
- }
2364
- RelayDeflate2.supported = supported;
2365
- function compress(bytes) {
2366
- return through(bytes, new CompressionStream("deflate-raw"));
2367
2412
  }
2368
- RelayDeflate2.compress = compress;
2369
- function decompress(bytes) {
2370
- return through(bytes, new DecompressionStream("deflate-raw"));
2413
+ for (const { storage } of this.hubs.values()) {
2414
+ (_b = (_a = storage).close) === null || _b === undefined || _b.call(_a);
2371
2415
  }
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());
2416
+ for (const { storage } of this.blobs.values()) {
2417
+ (_d = (_c = storage).close) === null || _d === undefined || _d.call(_c);
2376
2418
  }
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);
2419
+ this.hubs.clear();
2420
+ for (const { sockets } of this.spots.values()) {
2421
+ for (const connection of sockets.keys()) {
2422
+ connection.close(1001, "The relay is stopping.");
2393
2423
  }
2394
- return `${pairing.relay}${RELAY_PAIR_PATH}#${fragment}`;
2395
2424
  }
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.");
2425
+ this.spots.clear();
2426
+ for (const room of this.rooms.values()) {
2427
+ (_e = room.host) === null || _e === undefined || _e.close(1001, "The relay is stopping.");
2428
+ for (const client of room.clients.values()) {
2429
+ client.close(1001, "The relay is stopping.");
2407
2430
  }
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
2431
  }
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 = {}) {
2432
+ this.rooms.clear();
2433
+ return new Promise((resolve2) => this.server ? this.server.close(() => resolve2()) : resolve2());
2434
+ }
2435
+ async blob(id, request, response) {
2421
2436
  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;
2437
+ if (!RELAY_ID.test(id)) {
2438
+ response.writeHead(404).end();
2439
+ return;
2440
+ }
2441
+ const read = await RelayServer.body(request, RelayBlobs.MAX_BYTES);
2442
+ if (!read) {
2443
+ response.writeHead(413, { connection: "close" }).end(`Too large.
2444
+ `);
2445
+ return;
2446
+ }
2447
+ const copy = this.blobCopy(id);
2448
+ const headers = new Headers;
2449
+ for (const [name, value] of Object.entries(request.headers)) {
2450
+ if (typeof value === "string") {
2451
+ headers.set(name, value);
2453
2452
  }
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));
2453
+ }
2454
+ const method = (_a = request.method) !== null && _a !== undefined ? _a : "GET";
2455
+ const body = read.length && method !== "GET" && method !== "HEAD" ? read : undefined;
2456
+ copy.pending++;
2457
+ let answer;
2458
+ try {
2459
+ answer = await copy.blobs.handle(new Request(`http://relay${request.url}`, { method, headers, body }));
2460
+ } finally {
2461
+ copy.pending--;
2462
+ if (copy.pending === 0 && copy.storage.empty && this.blobs.get(id) === copy) {
2463
+ this.blobs.delete(id);
2464
+ }
2465
+ }
2466
+ response.writeHead(answer.status, Object.fromEntries(answer.headers));
2467
+ response.end(Buffer.from(await answer.arrayBuffer()));
2461
2468
  }
2462
- get readyState() {
2463
- return this.state;
2469
+ blobCopy(id) {
2470
+ let copy = this.blobs.get(id);
2471
+ if (!copy) {
2472
+ const data = this.options.data;
2473
+ const made = { pending: 0 };
2474
+ const storage = data ? new FileRelayStorage(join6(data, "blobs", id), () => {
2475
+ var _a;
2476
+ (_a = made.storage) === null || _a === undefined || _a.deleteAll().then(() => this.blobs.get(id) === copy && this.blobs.delete(id));
2477
+ }) : new MemoryBlobStorage;
2478
+ made.storage = storage;
2479
+ made.blobs = new RelayBlobs(storage);
2480
+ copy = made;
2481
+ this.blobs.set(id, copy);
2482
+ }
2483
+ return copy;
2464
2484
  }
2465
- get closeCode() {
2466
- return this.code;
2485
+ claimsFile() {
2486
+ return join6(this.options.data, "hosts.json");
2467
2487
  }
2468
- send(text) {
2469
- if (this.state !== OPEN || !this.cipher) {
2470
- throw new Error("The connection is not open.");
2488
+ saveClaims() {
2489
+ if (!this.options.data) {
2490
+ return;
2471
2491
  }
2472
- this.cipher.seal(text).then((frame) => this.socket.readyState === OPEN && this.socket.send(frame));
2492
+ const file = this.claimsFile();
2493
+ writeFileSync5(`${file}.tmp`, JSON.stringify(Object.fromEntries(this.claims)), { mode: 384 });
2494
+ renameSync3(`${file}.tmp`, file);
2473
2495
  }
2474
- close(code = 1000, reason = "") {
2475
- if (this.state === CLOSED) {
2496
+ static body(request, max) {
2497
+ return new Promise((resolve2, reject) => {
2498
+ const chunks = [];
2499
+ let size = 0;
2500
+ request.on("data", (chunk) => {
2501
+ if (size < 0) {
2502
+ return;
2503
+ }
2504
+ size += chunk.length;
2505
+ if (size > max) {
2506
+ size = -1;
2507
+ chunks.length = 0;
2508
+ resolve2(undefined);
2509
+ return;
2510
+ }
2511
+ chunks.push(chunk);
2512
+ });
2513
+ request.on("end", () => size >= 0 && resolve2(Buffer.concat(chunks)));
2514
+ request.on("error", reject);
2515
+ });
2516
+ }
2517
+ upgrade(request, socket, head) {
2518
+ var _a, _b, _c;
2519
+ const url = new URL((_a = request.url) !== null && _a !== undefined ? _a : "/", "http://relay");
2520
+ const checked = WebSocketConnection.check(request);
2521
+ if ("status" in checked) {
2522
+ WebSocketConnection.refuse(socket, checked.status, checked.message);
2523
+ return;
2524
+ }
2525
+ if (url.pathname.startsWith(RELAY_HUB_PATH)) {
2526
+ const id2 = url.pathname.slice(RELAY_HUB_PATH.length);
2527
+ if (!RELAY_ID.test(id2)) {
2528
+ WebSocketConnection.refuse(socket, 404, "Not found.");
2529
+ return;
2530
+ }
2531
+ this.openHub(id2, WebSocketConnection.open(socket, checked.key, head, WEBSOCKET));
2532
+ return;
2533
+ }
2534
+ if (url.pathname.startsWith(RELAY_SPOT_PATH)) {
2535
+ const id2 = url.pathname.slice(RELAY_SPOT_PATH.length);
2536
+ if (!RELAY_ID.test(id2)) {
2537
+ WebSocketConnection.refuse(socket, 404, "Not found.");
2538
+ return;
2539
+ }
2540
+ const address = RelaySpotTries.keyOf(request.socket.remoteAddress);
2541
+ const connection2 = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
2542
+ const fails = RelaySpotTries.recent((_b = this.spotTries.get(address)) !== null && _b !== undefined ? _b : [], Date.now());
2543
+ if (RelaySpotTries.blocked(fails, Date.now())) {
2544
+ connection2.close(RelaySpotCloseCode.TRIES, "Too many codes tried.");
2545
+ return;
2546
+ }
2547
+ this.openSpot(id2, connection2, address);
2548
+ return;
2549
+ }
2550
+ 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)];
2551
+ if (!url.pathname.startsWith(path) || !RELAY_ID.test(id)) {
2552
+ WebSocketConnection.refuse(socket, 404, "Not found.");
2476
2553
  return;
2477
2554
  }
2478
- this.state = CLOSING;
2479
- this.socket.close(code, reason);
2555
+ const connection = WebSocketConnection.open(socket, checked.key, head, WEBSOCKET);
2556
+ if (path === RELAY_HOST_PATH) {
2557
+ this.openHost(id, (_c = url.searchParams.get("secret")) !== null && _c !== undefined ? _c : "", connection);
2558
+ } else {
2559
+ this.openClient(id, connection);
2560
+ }
2480
2561
  }
2481
- async receive(text) {
2562
+ openHost(id, secret, connection) {
2482
2563
  var _a, _b;
2483
- if (this.cipher) {
2484
- if (this.options.proveFirst && text.startsWith("{")) {
2485
- this.drop(RelaySocket.REFUSED, RelaySocket.refusal(text));
2486
- return;
2487
- }
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
- }
2564
+ const hash = createHash2("sha256").update(secret).digest("base64url");
2565
+ if (secret.length >= 32 && !this.claims.has(id) && this.options.data) {
2566
+ this.claims.set(id, hash);
2567
+ this.saveClaims();
2568
+ }
2569
+ const room = (_a = this.rooms.get(id)) !== null && _a !== undefined ? _a : this.createRoom(id, (_b = this.claims.get(id)) !== null && _b !== undefined ? _b : hash);
2570
+ if (secret.length < 32 || !RelayServer.same(room.secretHash, hash)) {
2571
+ connection.close(RelayCloseCode.REFUSED, "Refused.");
2494
2572
  return;
2495
2573
  }
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.");
2500
- return;
2501
- }
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.");
2574
+ if (room.host) {
2575
+ room.host.close(RelayCloseCode.REPLACED, "The host connected again.");
2576
+ room.relay.hostClosed();
2577
+ }
2578
+ room.host = connection;
2579
+ connection.onMessage((text) => room.relay.fromHost(text));
2580
+ connection.onClose(() => {
2581
+ if (room.host === connection) {
2582
+ room.host = undefined;
2583
+ room.relay.hostClosed();
2507
2584
  }
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.");
2585
+ });
2586
+ }
2587
+ openClient(id, connection) {
2588
+ const room = this.rooms.get(id);
2589
+ const channel = randomBytes(9).toString("base64url");
2590
+ room === null || room === undefined || room.clients.set(channel, connection);
2591
+ const refused = room ? room.relay.clientOpened(channel) : RelayCloseCode.HOST_OFFLINE;
2592
+ if (!room || refused !== undefined) {
2593
+ room === null || room === undefined || room.clients.delete(channel);
2594
+ connection.close(refused !== null && refused !== undefined ? refused : RelayCloseCode.HOST_OFFLINE, "The host is not available.");
2595
+ return;
2515
2596
  }
2597
+ connection.onMessage((text) => room.relay.fromClient(channel, text));
2598
+ connection.onClose(() => {
2599
+ if (room.clients.delete(channel)) {
2600
+ room.relay.clientClosed(channel);
2601
+ }
2602
+ });
2516
2603
  }
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";
2604
+ openSpot(id, connection, address) {
2605
+ let current = this.spots.get(id);
2606
+ if (!current) {
2607
+ const sockets2 = new Map;
2608
+ const socketOf = (other) => ({
2609
+ key: other,
2610
+ get who() {
2611
+ var _a;
2612
+ return (_a = sockets2.get(other)) === null || _a === undefined ? undefined : _a.who;
2613
+ },
2614
+ set who(who) {
2615
+ const state = sockets2.get(other);
2616
+ if (state) {
2617
+ state.who = who;
2618
+ }
2619
+ },
2620
+ send: (text) => other.send(text),
2621
+ close: (code, reason) => other.close(code, reason)
2622
+ });
2623
+ const missed = (socket2) => {
2624
+ var _a, _b;
2625
+ const key = (_a = this.spotAddresses.get(socket2.key)) !== null && _a !== undefined ? _a : "unknown";
2626
+ const now = Date.now();
2627
+ this.spotTries.set(key, [...RelaySpotTries.recent((_b = this.spotTries.get(key)) !== null && _b !== undefined ? _b : [], now), now]);
2628
+ for (const [other, fails] of this.spotTries) {
2629
+ if (!RelaySpotTries.recent(fails, now).length) {
2630
+ this.spotTries.delete(other);
2631
+ }
2632
+ }
2633
+ };
2634
+ current = { sockets: sockets2, socketOf, spot: new RelaySpot(() => [...sockets2.keys()].map(socketOf), Date.now, missed) };
2635
+ this.spots.set(id, current);
2523
2636
  }
2637
+ const { sockets, spot } = current;
2638
+ sockets.set(connection, {});
2639
+ this.spotAddresses.set(connection, address);
2640
+ const socket = current.socketOf(connection);
2641
+ connection.onMessage((text) => spot.receive(socket, text));
2642
+ connection.onClose(() => {
2643
+ if (sockets.has(connection)) {
2644
+ spot.closed(socket);
2645
+ sockets.delete(connection);
2646
+ }
2647
+ if (sockets.size === 0 && this.spots.get(id) === current) {
2648
+ this.spots.delete(id);
2649
+ }
2650
+ });
2524
2651
  }
2525
- ping() {
2526
- if (this.awaitingPong && this.ponged) {
2527
- this.drop(RelayCloseCode.TIMEOUT, "The relay did not answer.");
2528
- return;
2652
+ openHub(id, connection) {
2653
+ const current = this.hubOf(id);
2654
+ const { sockets, hub: relay } = current;
2655
+ sockets.set(connection, {});
2656
+ let chain = Promise.resolve();
2657
+ const socket = {
2658
+ key: connection,
2659
+ get who() {
2660
+ var _a;
2661
+ return (_a = sockets.get(connection)) === null || _a === undefined ? undefined : _a.who;
2662
+ },
2663
+ set who(who) {
2664
+ const state = sockets.get(connection);
2665
+ if (state) {
2666
+ state.who = who;
2667
+ }
2668
+ },
2669
+ send: (text) => connection.send(text),
2670
+ close: (code, reason) => connection.close(code, reason)
2671
+ };
2672
+ connection.onMessage((text) => {
2673
+ chain = chain.then(() => relay.receive(socket, text)).catch(() => {
2674
+ return;
2675
+ });
2676
+ });
2677
+ connection.onClose(() => {
2678
+ chain.then(() => {
2679
+ if (sockets.has(connection)) {
2680
+ relay.closed(socket);
2681
+ sockets.delete(connection);
2682
+ }
2683
+ this.dropHub(id, current);
2684
+ });
2685
+ });
2686
+ }
2687
+ hubOf(id) {
2688
+ let hub = this.hubs.get(id);
2689
+ if (!hub) {
2690
+ const sockets = new Map;
2691
+ const socketOf = (other) => {
2692
+ var _a;
2693
+ const state = (_a = sockets.get(other)) !== null && _a !== undefined ? _a : {};
2694
+ return {
2695
+ key: other,
2696
+ get who() {
2697
+ return state.who;
2698
+ },
2699
+ set who(who) {
2700
+ state.who = who;
2701
+ },
2702
+ send: (text) => other.send(text),
2703
+ close: (code, reason) => other.close(code, reason)
2704
+ };
2705
+ };
2706
+ const made = { sockets };
2707
+ const storage = this.options.data ? new FileRelayStorage(join6(this.options.data, "hubs", id), () => {
2708
+ var _a;
2709
+ return void ((_a = made.hub) === null || _a === undefined ? undefined : _a.alarm().then(() => this.dropHub(id, made)));
2710
+ }) : new MemoryHubStorage;
2711
+ made.storage = storage;
2712
+ made.hub = new RelayHub(storage, () => [...sockets.keys()].map(socketOf));
2713
+ hub = made;
2714
+ this.hubs.set(id, hub);
2529
2715
  }
2530
- this.awaitingPong = true;
2531
- if (this.socket.readyState === OPEN) {
2532
- this.socket.send(RELAY_PING);
2716
+ return hub;
2717
+ }
2718
+ dropHub(id, hub) {
2719
+ if (hub && hub.sockets.size === 0 && hub.storage.empty && this.hubs.get(id) === hub) {
2720
+ this.hubs.delete(id);
2533
2721
  }
2534
2722
  }
2535
- drop(code, reason) {
2536
- this.close(code, reason);
2537
- this.finish(code, reason);
2723
+ createRoom(id, secretHash) {
2724
+ const room = {
2725
+ secretHash,
2726
+ clients: new Map,
2727
+ relay: new RelayRoom({
2728
+ host: () => room.host ? peer(room.host) : undefined,
2729
+ client: (channel) => {
2730
+ const client = room.clients.get(channel);
2731
+ return client ? peer(client) : undefined;
2732
+ },
2733
+ clients: () => [...room.clients.values()].map(peer)
2734
+ })
2735
+ };
2736
+ this.rooms.set(id, room);
2737
+ return room;
2538
2738
  }
2539
- finish(code, reason) {
2540
- var _a;
2541
- if (this.state === CLOSED) {
2542
- return;
2543
- }
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 });
2739
+ static same(a, b) {
2740
+ const [left, right] = [Buffer.from(a), Buffer.from(b)];
2741
+ return left.length === right.length && timingSafeEqual(left, right);
2549
2742
  }
2550
2743
  }
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();
2744
+ var WEBSOCKET, peer = (connection) => ({ send: (text) => connection.send(text), close: (code, reason) => connection.close(code, reason) });
2745
+ var init_relay_server = __esm(() => {
2746
+ init_websocket_connection();
2747
+ init_relay_blobs();
2748
+ init_relay_hub();
2749
+ init_relay_info();
2556
2750
  init_relay_protocol();
2557
- RelaySocket.CONNECTING = CONNECTING;
2558
- RelaySocket.OPEN = OPEN;
2559
- RelaySocket.CLOSING = CLOSING;
2560
- RelaySocket.CLOSED = CLOSED;
2561
- RelaySocket.REFUSED = 4403;
2751
+ init_relay_room();
2752
+ init_relay_spot();
2753
+ init_relay_team();
2754
+ init_relay_web();
2755
+ init_relay_file_storage();
2756
+ init_relay_viewer();
2757
+ WEBSOCKET = { maxPayload: 32 * 1024 * 1024, heartbeat: 30000 };
2562
2758
  });
2563
2759
 
2564
2760
  // ../../ta-packages/ta-relay/esm/common/relay-content.js
@@ -2841,14 +3037,14 @@ __export(exports_relay_store, {
2841
3037
  import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
2842
3038
  import { chmodSync as chmodSync2, mkdirSync as mkdirSync6, readFileSync as readFileSync8, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
2843
3039
  import { hostname as hostname2 } from "node:os";
2844
- import { dirname as dirname4, join as join8 } from "node:path";
3040
+ import { dirname as dirname4, join as join7 } from "node:path";
2845
3041
 
2846
3042
  class RelayStore {
2847
3043
  constructor(agentDir) {
2848
3044
  this.agentDir = agentDir;
2849
3045
  }
2850
3046
  get file() {
2851
- return join8(this.agentDir, RelayStore.FILE);
3047
+ return join7(this.agentDir, RelayStore.FILE);
2852
3048
  }
2853
3049
  read() {
2854
3050
  try {
@@ -2971,7 +3167,7 @@ class RelayStore {
2971
3167
  }));
2972
3168
  }
2973
3169
  contentFile(contentId) {
2974
- return join8(this.agentDir, "shares", contentId);
3170
+ return join7(this.agentDir, "shares", contentId);
2975
3171
  }
2976
3172
  static live(content, now) {
2977
3173
  return content.expiresAt === undefined || content.expiresAt > now;
@@ -3085,16 +3281,16 @@ __export(exports_relays_file, {
3085
3281
  RELAY_FEATURES: () => RELAY_FEATURES,
3086
3282
  OFFICIAL_RELAY: () => OFFICIAL_RELAY
3087
3283
  });
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";
3284
+ 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
3285
  import { homedir as homedir2 } from "node:os";
3090
- import { dirname as dirname5, isAbsolute, join as join9, resolve as resolve2 } from "node:path";
3286
+ import { dirname as dirname5, isAbsolute, join as join8, resolve as resolve2 } from "node:path";
3091
3287
 
3092
3288
  class RelaysFile {
3093
3289
  constructor(agentDir) {
3094
3290
  this.agentDir = agentDir;
3095
3291
  }
3096
3292
  get file() {
3097
- return join9(this.agentDir, RelaysFile.FILE);
3293
+ return join8(this.agentDir, RelaysFile.FILE);
3098
3294
  }
3099
3295
  read() {
3100
3296
  let text;
@@ -3326,7 +3522,7 @@ var init_relays_file = __esm(() => {
3326
3522
  function expand(path) {
3327
3523
  const text = String(path !== null && path !== undefined ? path : "").trim();
3328
3524
  if (text === "~" || text.startsWith("~/")) {
3329
- return join9(homedir2(), text.slice(1));
3525
+ return join8(homedir2(), text.slice(1));
3330
3526
  }
3331
3527
  return isAbsolute(text) ? resolve2(text) : resolve2(homedir2(), text);
3332
3528
  }
@@ -3363,19 +3559,19 @@ var init_relays_file = __esm(() => {
3363
3559
  const found = [];
3364
3560
  const add = (name, dir) => {
3365
3561
  try {
3366
- if (statSync(dir).isDirectory()) {
3367
- found.push({ name, path: portable(join9(dir, "Ta")) });
3562
+ if (statSync2(dir).isDirectory()) {
3563
+ found.push({ name, path: portable(join8(dir, "Ta")) });
3368
3564
  }
3369
3565
  } catch (_a) {}
3370
3566
  };
3371
- add("iCloud Drive", join9(home, "Library", "Mobile Documents", "com~apple~CloudDocs"));
3567
+ add("iCloud Drive", join8(home, "Library", "Mobile Documents", "com~apple~CloudDocs"));
3372
3568
  try {
3373
- for (const entry of readdirSync3(join9(home, "Library", "CloudStorage"))) {
3374
- add(entry.replace(/-.*$/, ""), join9(home, "Library", "CloudStorage", entry));
3569
+ for (const entry of readdirSync3(join8(home, "Library", "CloudStorage"))) {
3570
+ add(entry.replace(/-.*$/, ""), join8(home, "Library", "CloudStorage", entry));
3375
3571
  }
3376
3572
  } catch (_a) {}
3377
3573
  for (const name of ["Dropbox", "OneDrive", "Nutstore Files", "坚果云"]) {
3378
- add(name, join9(home, name));
3574
+ add(name, join8(home, name));
3379
3575
  }
3380
3576
  return found.filter((drive, index) => found.findIndex((other) => other.path === drive.path) === index);
3381
3577
  }
@@ -3383,7 +3579,7 @@ var init_relays_file = __esm(() => {
3383
3579
  function checkFolder(path) {
3384
3580
  const dir = expand(path);
3385
3581
  try {
3386
- if (!statSync(dir).isDirectory()) {
3582
+ if (!statSync2(dir).isDirectory()) {
3387
3583
  return `${dir} is not a folder.`;
3388
3584
  }
3389
3585
  accessSync(dir, constants2.W_OK);
@@ -4248,7 +4444,7 @@ var init_exec_server = __esm(() => {
4248
4444
 
4249
4445
  // ../../ta-packages/ta-harness/esm/node/ta-cli.js
4250
4446
  import { randomBytes as randomBytes3 } from "node:crypto";
4251
- import { dirname as dirname6, join as join10 } from "node:path";
4447
+ import { dirname as dirname6, join as join9 } from "node:path";
4252
4448
  import { parseArgs } from "node:util";
4253
4449
 
4254
4450
  // ../../ai-packages/ai-coding-agent/esm/node/pi/pi-bundle-util.js
@@ -4286,14 +4482,23 @@ var PiBundleUtil;
4286
4482
 
4287
4483
  // ../../ta-packages/ta-harness/esm/node/bug-report.js
4288
4484
  import { spawn } from "node:child_process";
4485
+ function ofLanguage(tag) {
4486
+ if (/^zh/i.test(tag)) {
4487
+ return /(?:tw|hk|mo|hant)/i.test(tag) ? "zh-TW" : "zh-CN";
4488
+ }
4489
+ if (/^ja/i.test(tag)) {
4490
+ return "ja-JP";
4491
+ }
4492
+ return "en-US";
4493
+ }
4289
4494
  var BugReport;
4290
4495
  (function(BugReport2) {
4291
- BugReport2.ISSUES_URL = "https://github.com/cellbang/cell/issues/new";
4496
+ BugReport2.ISSUES_URL = "https://github.com/cellbang/ta/issues/new";
4292
4497
  function issueUrl(description, environment) {
4293
4498
  var _a;
4294
4499
  const url = new URL(BugReport2.ISSUES_URL);
4295
- url.searchParams.set("title", `[Ta] ${description.trim() || "Describe the bug"}`);
4296
- url.searchParams.set("labels", "ta");
4500
+ url.searchParams.set("title", description.trim() || "Describe the bug");
4501
+ url.searchParams.set("labels", "bug");
4297
4502
  url.searchParams.set("body", [
4298
4503
  "## What happened",
4299
4504
  "",
@@ -4323,7 +4528,10 @@ var BugReport;
4323
4528
  }
4324
4529
  BugReport2.open = open;
4325
4530
  function notice(url, env = process.env) {
4326
- return /^zh/i.test(env.TA_LANGUAGE || env.LC_ALL || env.LANG || "") ? `一个新的 Ta 问题(只带版本、模型和平台信息)会在浏览器里打开。如果没有打开:
4531
+ const language = ofLanguage(env.TA_LANGUAGE || env.LC_ALL || env.LANG || "");
4532
+ return language === "zh-CN" ? `一个新的 Ta 问题(只带版本、模型和平台信息)会在浏览器里打开。如果没有打开:
4533
+ ${url}` : language === "zh-TW" ? `一個新的 Ta 問題(只帶版本、模型和平台資訊)會在瀏覽器裡開啟。如果沒有開啟:
4534
+ ${url}` : language === "ja-JP" ? `Ta の新しい問題(バージョン、モデル、プラットフォーム情報のみ)がブラウザで開きます。開かない場合:
4327
4535
  ${url}` : `A new issue for Ta, with its version, the model and the platform and nothing else, opens in the browser. If it did not:
4328
4536
  ${url}`;
4329
4537
  }
@@ -5025,7 +5233,8 @@ var TaPackages;
5025
5233
  // ../../ta-packages/ta-harness/esm/node/ta-cli.js
5026
5234
  var SERVE_HELP = `Usage: ta serve [--host <host>] [--port <port>] [--web] [--exec <url>]
5027
5235
 
5028
- Serves the sessions of Ta over WebSocket to any number of clients, and its web client. Stops on SIGINT or SIGTERM.
5236
+ Serves the sessions of Ta over WebSocket to any number of clients, and its web client. Stops on SIGINT
5237
+ or SIGTERM.
5029
5238
 
5030
5239
  --host Address to listen on. Default: 127.0.0.1
5031
5240
  --port Port to listen on. Default: the port of the last start if it is free, so that a web app
@@ -5056,7 +5265,8 @@ Set TA_EXEC_TOKEN to choose the token hosts must present; otherwise a random one
5056
5265
  var RELAY_HELP = `Usage: ta relay [--host <host>] [--port <port>] [--data <dir>]
5057
5266
 
5058
5267
  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.
5268
+ what goes through is encrypted end to end. It also serves the page of Ta under /w/, for those let into a
5269
+ Ta from a browser by a link that invites. Put it behind HTTPS. Stops on SIGINT or SIGTERM.
5060
5270
 
5061
5271
  --host Address to listen on. Default: 127.0.0.1
5062
5272
  --port Port to listen on. Default: 8080
@@ -5082,7 +5292,7 @@ var TaCli;
5082
5292
  return;
5083
5293
  }
5084
5294
  if (argv[0] === "relay") {
5085
- await relay(argv.slice(1));
5295
+ await relay(argv.slice(1), join9(dirname6(options.serveEntry), "..", "public"));
5086
5296
  return;
5087
5297
  }
5088
5298
  if (argv[0] === "pair") {
@@ -5092,7 +5302,7 @@ var TaCli;
5092
5302
  if (argv[0] === "gateway" && options.gatewayEntry) {
5093
5303
  const { GatewayCli } = await import(options.gatewayEntry);
5094
5304
  await GatewayCli.run(argv.slice(1), {
5095
- publicDir: join10(dirname6(options.serveEntry), "..", "public"),
5305
+ publicDir: join9(dirname6(options.serveEntry), "..", "public"),
5096
5306
  taCommand: [process.execPath, process.argv[1]]
5097
5307
  });
5098
5308
  return;
@@ -5156,7 +5366,7 @@ var TaCli;
5156
5366
  }
5157
5367
  await import(entry);
5158
5368
  }
5159
- async function relay(argv) {
5369
+ async function relay(argv, web) {
5160
5370
  const { values } = parseArgs({
5161
5371
  args: argv,
5162
5372
  options: { host: { type: "string" }, port: { type: "string" }, data: { type: "string" }, help: { type: "boolean", short: "h" } }
@@ -5170,7 +5380,8 @@ var TaCli;
5170
5380
  const server = new RelayServer2({
5171
5381
  host: values.host,
5172
5382
  port: values.port ? Number(values.port) : 8080,
5173
- data: values.data ? resolve4(values.data) : undefined
5383
+ data: values.data ? resolve4(values.data) : undefined,
5384
+ web
5174
5385
  });
5175
5386
  console.log(`ta relay: ${await server.listen()}`);
5176
5387
  const stop = () => void server.close().then(() => process.exit(0));