@celljs/ta 4.16.0 → 4.17.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 (658) hide show
  1. package/README.en.md +1 -0
  2. package/README.md +1 -0
  3. package/dist/cli.mjs +2224 -203
  4. package/dist/gateway.mjs +2011 -528
  5. package/dist/pi/CHANGELOG.md +12 -0
  6. package/dist/pi/package.json +1 -1
  7. package/dist/pi/packages/ta-3d/extension/index.mjs +1 -0
  8. package/dist/pi/packages/ta-3d/package.json +2 -1
  9. package/dist/pi/packages/ta-agents/README.en.md +14 -2
  10. package/dist/pi/packages/ta-agents/README.md +14 -2
  11. package/dist/pi/packages/ta-agents/extension/index.mjs +278 -105
  12. package/dist/pi/packages/ta-agents/host/index.mjs +662 -0
  13. package/dist/pi/packages/ta-agents/lib/agent-catalog.d.ts +36 -2
  14. package/dist/pi/packages/ta-agents/lib/agent-catalog.js +76 -6
  15. package/dist/pi/packages/ta-agents/lib/agent-installer.d.ts +55 -0
  16. package/dist/pi/packages/ta-agents/lib/agent-installer.js +140 -0
  17. package/dist/pi/packages/ta-agents/lib/agent-installs.d.ts +25 -0
  18. package/dist/pi/packages/ta-agents/lib/agent-installs.js +64 -0
  19. package/dist/pi/packages/ta-agents/lib/agent-prompt.d.ts +6 -0
  20. package/dist/pi/packages/ta-agents/lib/agent-prompt.js +9 -0
  21. package/dist/pi/packages/ta-agents/lib/agent-refresh.d.ts +11 -0
  22. package/dist/pi/packages/ta-agents/lib/agent-refresh.js +37 -0
  23. package/dist/pi/packages/ta-agents/lib/agent-session.js +2 -1
  24. package/dist/pi/packages/ta-agents/lib/agents-protocol.d.ts +26 -0
  25. package/dist/pi/packages/ta-agents/lib/agents-protocol.js +11 -0
  26. package/dist/pi/packages/ta-agents/lib/agents-settings.d.ts +10 -0
  27. package/dist/pi/packages/ta-agents/lib/agents-settings.js +165 -0
  28. package/dist/pi/packages/ta-agents/lib/extension.d.ts +3 -1
  29. package/dist/pi/packages/ta-agents/lib/extension.js +17 -4
  30. package/dist/pi/packages/ta-agents/lib/host.d.ts +35 -0
  31. package/dist/pi/packages/ta-agents/lib/host.js +96 -0
  32. package/dist/pi/packages/ta-agents/lib/react.d.ts +8 -0
  33. package/dist/pi/packages/ta-agents/lib/react.js +8 -0
  34. package/dist/pi/packages/ta-agents/lib/style.d.ts +4 -0
  35. package/dist/pi/packages/ta-agents/lib/style.js +30 -0
  36. package/dist/pi/packages/ta-agents/lib/texts.d.ts +18 -0
  37. package/dist/pi/packages/ta-agents/lib/texts.js +18 -0
  38. package/dist/pi/packages/ta-agents/lib/web-words.d.ts +30 -0
  39. package/dist/pi/packages/ta-agents/lib/web-words.js +98 -0
  40. package/dist/pi/packages/ta-agents/lib/web.d.ts +4 -0
  41. package/dist/pi/packages/ta-agents/lib/web.js +14 -0
  42. package/dist/pi/packages/ta-agents/package.json +21 -5
  43. package/dist/pi/packages/ta-agents/web/index.js +385 -0
  44. package/dist/pi/packages/ta-app-use/README.en.md +28 -0
  45. package/dist/pi/packages/ta-app-use/README.md +28 -0
  46. package/dist/pi/packages/ta-app-use/extension/index.mjs +534 -0
  47. package/dist/pi/packages/ta-app-use/host/index.mjs +136 -0
  48. package/dist/pi/packages/ta-app-use/lib/app-host.d.ts +32 -0
  49. package/dist/pi/packages/ta-app-use/lib/app-host.js +79 -0
  50. package/dist/pi/packages/ta-app-use/lib/app-protocol.d.ts +23 -0
  51. package/dist/pi/packages/ta-app-use/lib/app-protocol.js +9 -0
  52. package/dist/pi/packages/ta-app-use/lib/app-util.d.ts +18 -0
  53. package/dist/pi/packages/ta-app-use/lib/app-util.js +71 -0
  54. package/dist/pi/packages/ta-app-use/lib/extension.d.ts +80 -0
  55. package/dist/pi/packages/ta-app-use/lib/extension.js +125 -0
  56. package/dist/pi/packages/ta-app-use/lib/host.d.ts +7 -0
  57. package/dist/pi/packages/ta-app-use/lib/host.js +16 -0
  58. package/dist/pi/packages/ta-app-use/lib/i18n.d.ts +38 -0
  59. package/dist/pi/packages/ta-app-use/lib/i18n.js +130 -0
  60. package/dist/pi/packages/ta-app-use/lib/index.d.ts +9 -0
  61. package/dist/pi/packages/ta-app-use/lib/index.js +93 -0
  62. package/dist/pi/packages/ta-app-use/lib/screen-cursor.d.ts +33 -0
  63. package/dist/pi/packages/ta-app-use/lib/screen-cursor.js +134 -0
  64. package/dist/pi/packages/ta-app-use/lib/screen-dom.d.ts +19 -0
  65. package/dist/pi/packages/ta-app-use/lib/screen-dom.js +184 -0
  66. package/dist/pi/packages/ta-app-use/lib/screen-driver.d.ts +46 -0
  67. package/dist/pi/packages/ta-app-use/lib/screen-driver.js +174 -0
  68. package/dist/pi/packages/ta-app-use/lib/screen-protocol.d.ts +67 -0
  69. package/dist/pi/packages/ta-app-use/lib/screen-protocol.js +8 -0
  70. package/dist/pi/packages/ta-app-use/lib/screen-text.d.ts +13 -0
  71. package/dist/pi/packages/ta-app-use/lib/screen-text.js +69 -0
  72. package/dist/pi/packages/ta-app-use/lib/screen-window.d.ts +68 -0
  73. package/dist/pi/packages/ta-app-use/lib/screen-window.js +376 -0
  74. package/dist/pi/packages/ta-app-use/lib/tool-line.d.ts +11 -0
  75. package/dist/pi/packages/ta-app-use/lib/tool-line.js +69 -0
  76. package/dist/pi/packages/ta-app-use/package.json +63 -0
  77. package/dist/pi/packages/ta-app-use/web/index.js +1520 -0
  78. package/dist/pi/packages/ta-bots/README.en.md +1 -0
  79. package/dist/pi/packages/ta-bots/README.md +1 -0
  80. package/dist/pi/packages/ta-bots/extension/index.mjs +25 -22
  81. package/dist/pi/packages/ta-bots/host/index.mjs +688 -148
  82. package/dist/pi/packages/ta-bots/lib/bot-service.d.ts +9 -1
  83. package/dist/pi/packages/ta-bots/lib/bot-service.js +49 -8
  84. package/dist/pi/packages/ta-bots/lib/channel-protocol.d.ts +2 -0
  85. package/dist/pi/packages/ta-bots/lib/extension.d.ts +2 -2
  86. package/dist/pi/packages/ta-bots/lib/extension.js +28 -24
  87. package/dist/pi/packages/ta-bots/lib/index.js +4 -0
  88. package/dist/pi/packages/ta-bots/lib/page.d.ts +7 -1
  89. package/dist/pi/packages/ta-bots/lib/page.js +17 -0
  90. package/dist/pi/packages/ta-bots/lib/style.d.ts +1 -1
  91. package/dist/pi/packages/ta-bots/lib/style.js +1 -1
  92. package/dist/pi/packages/ta-bots/lib/wecom-channel.js +1 -1
  93. package/dist/pi/packages/ta-bots/lib/weixin-api.d.ts +1 -0
  94. package/dist/pi/packages/ta-bots/lib/weixin-channel.js +2 -1
  95. package/dist/pi/packages/ta-bots/package.json +1 -1
  96. package/dist/pi/packages/ta-bots/web/index.js +13 -2
  97. package/dist/pi/packages/ta-call/README.en.md +9 -0
  98. package/dist/pi/packages/ta-call/README.md +9 -0
  99. package/dist/pi/packages/ta-call/extension/index.mjs +474 -0
  100. package/dist/pi/packages/ta-call/host/index.mjs +899 -0
  101. package/dist/pi/packages/ta-call/lib/call-host.d.ts +127 -0
  102. package/dist/pi/packages/ta-call/lib/call-host.js +377 -0
  103. package/dist/pi/packages/ta-call/lib/call-protocol.d.ts +33 -0
  104. package/dist/pi/packages/ta-call/lib/call-protocol.js +10 -0
  105. package/dist/pi/packages/ta-call/lib/call-util.d.ts +50 -0
  106. package/dist/pi/packages/ta-call/lib/call-util.js +250 -0
  107. package/dist/pi/packages/ta-call/lib/extension.d.ts +20 -0
  108. package/dist/pi/packages/ta-call/lib/extension.js +114 -0
  109. package/dist/pi/packages/ta-call/lib/host.d.ts +7 -0
  110. package/dist/pi/packages/ta-call/lib/host.js +20 -0
  111. package/dist/pi/packages/ta-call/lib/i18n.d.ts +16 -0
  112. package/dist/pi/packages/ta-call/lib/i18n.js +38 -0
  113. package/dist/pi/packages/ta-call/lib/index.d.ts +7 -0
  114. package/dist/pi/packages/ta-call/lib/index.js +60 -0
  115. package/dist/pi/packages/ta-call/lib/react.d.ts +8 -0
  116. package/dist/pi/packages/ta-call/lib/react.js +8 -0
  117. package/dist/pi/packages/ta-call/package.json +64 -0
  118. package/dist/pi/packages/ta-call/web/index.js +552 -0
  119. package/dist/pi/packages/ta-changes/extension/index.mjs +1 -0
  120. package/dist/pi/packages/ta-changes/lib/card.js +4 -1
  121. package/dist/pi/packages/ta-changes/package.json +1 -1
  122. package/dist/pi/packages/ta-changes/web/index.js +2 -0
  123. package/dist/pi/packages/ta-channels/extension/index.mjs +155 -194
  124. package/dist/pi/packages/ta-channels/host/index.mjs +2035 -1534
  125. package/dist/pi/packages/ta-channels/lib/agent-menu.js +2 -1
  126. package/dist/pi/packages/ta-channels/lib/channel-menu.d.ts +1 -1
  127. package/dist/pi/packages/ta-channels/lib/channel-menu.js +2 -2
  128. package/dist/pi/packages/ta-channels/lib/channels-text.d.ts +38 -0
  129. package/dist/pi/packages/ta-channels/lib/channels-text.js +173 -0
  130. package/dist/pi/packages/ta-channels/lib/channels-util.d.ts +0 -48
  131. package/dist/pi/packages/ta-channels/lib/channels-util.js +1 -223
  132. package/dist/pi/packages/ta-channels/lib/create.js +5 -1
  133. package/dist/pi/packages/ta-channels/lib/i18n-ja.d.ts +3 -0
  134. package/dist/pi/packages/ta-channels/lib/i18n-ja.js +182 -0
  135. package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.d.ts +3 -0
  136. package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.js +182 -0
  137. package/dist/pi/packages/ta-channels/lib/i18n-zh.d.ts +3 -0
  138. package/dist/pi/packages/ta-channels/lib/i18n-zh.js +182 -0
  139. package/dist/pi/packages/ta-channels/lib/i18n.js +4 -535
  140. package/dist/pi/packages/ta-channels/lib/index.js +2 -1
  141. package/dist/pi/packages/ta-channels/lib/notice-util.d.ts +15 -0
  142. package/dist/pi/packages/ta-channels/lib/notice-util.js +61 -0
  143. package/dist/pi/packages/ta-channels/lib/notice.d.ts +1 -1
  144. package/dist/pi/packages/ta-channels/lib/notice.js +5 -4
  145. package/dist/pi/packages/ta-channels/lib/room.js +4 -3
  146. package/dist/pi/packages/ta-channels/lib/sidebar-head.d.ts +6 -0
  147. package/dist/pi/packages/ta-channels/lib/sidebar-head.js +67 -0
  148. package/dist/pi/packages/ta-channels/lib/sidebar-hooks.d.ts +51 -0
  149. package/dist/pi/packages/ta-channels/lib/sidebar-hooks.js +230 -0
  150. package/dist/pi/packages/ta-channels/lib/sidebar-rows.d.ts +71 -0
  151. package/dist/pi/packages/ta-channels/lib/sidebar-rows.js +105 -0
  152. package/dist/pi/packages/ta-channels/lib/sidebar.d.ts +0 -4
  153. package/dist/pi/packages/ta-channels/lib/sidebar.js +35 -396
  154. package/dist/pi/packages/ta-channels/lib/style.d.ts +1 -1
  155. package/dist/pi/packages/ta-channels/lib/style.js +0 -1
  156. package/dist/pi/packages/ta-channels/lib/tasks.js +2 -1
  157. package/dist/pi/packages/ta-channels/lib/team-store.d.ts +78 -0
  158. package/dist/pi/packages/ta-channels/lib/team-store.js +261 -0
  159. package/dist/pi/packages/ta-channels/lib/team-tools.js +3 -2
  160. package/dist/pi/packages/ta-channels/lib/team.d.ts +3 -76
  161. package/dist/pi/packages/ta-channels/lib/team.js +5 -254
  162. package/dist/pi/packages/ta-channels/package.json +1 -1
  163. package/dist/pi/packages/ta-channels/web/index.js +889 -809
  164. package/dist/pi/packages/ta-computer-use/package.json +1 -1
  165. package/dist/pi/packages/ta-cron/README.en.md +19 -3
  166. package/dist/pi/packages/ta-cron/README.md +19 -3
  167. package/dist/pi/packages/ta-cron/extension/index.mjs +396 -111
  168. package/dist/pi/packages/ta-cron/host/index.mjs +633 -49
  169. package/dist/pi/packages/ta-cron/lib/chat-task.d.ts +5 -3
  170. package/dist/pi/packages/ta-cron/lib/chat-task.js +15 -10
  171. package/dist/pi/packages/ta-cron/lib/commands.d.ts +7 -4
  172. package/dist/pi/packages/ta-cron/lib/commands.js +26 -47
  173. package/dist/pi/packages/ta-cron/lib/cron-expression.d.ts +8 -0
  174. package/dist/pi/packages/ta-cron/lib/cron-expression.js +43 -1
  175. package/dist/pi/packages/ta-cron/lib/cron-protocol.d.ts +54 -7
  176. package/dist/pi/packages/ta-cron/lib/cron-protocol.js +16 -2
  177. package/dist/pi/packages/ta-cron/lib/editor.d.ts +3 -0
  178. package/dist/pi/packages/ta-cron/lib/editor.js +106 -36
  179. package/dist/pi/packages/ta-cron/lib/extension.js +1 -1
  180. package/dist/pi/packages/ta-cron/lib/form-util.d.ts +16 -6
  181. package/dist/pi/packages/ta-cron/lib/form-util.js +40 -28
  182. package/dist/pi/packages/ta-cron/lib/host.js +17 -1
  183. package/dist/pi/packages/ta-cron/lib/i18n.d.ts +39 -5
  184. package/dist/pi/packages/ta-cron/lib/i18n.js +160 -24
  185. package/dist/pi/packages/ta-cron/lib/index.js +4 -0
  186. package/dist/pi/packages/ta-cron/lib/page.d.ts +3 -2
  187. package/dist/pi/packages/ta-cron/lib/page.js +13 -2
  188. package/dist/pi/packages/ta-cron/lib/schedule-util.d.ts +4 -0
  189. package/dist/pi/packages/ta-cron/lib/schedule-util.js +52 -4
  190. package/dist/pi/packages/ta-cron/lib/scheduler.d.ts +56 -6
  191. package/dist/pi/packages/ta-cron/lib/scheduler.js +209 -27
  192. package/dist/pi/packages/ta-cron/lib/style.d.ts +1 -1
  193. package/dist/pi/packages/ta-cron/lib/style.js +50 -21
  194. package/dist/pi/packages/ta-cron/lib/task-list.d.ts +23 -0
  195. package/dist/pi/packages/ta-cron/lib/task-list.js +70 -0
  196. package/dist/pi/packages/ta-cron/lib/task-row.d.ts +19 -0
  197. package/dist/pi/packages/ta-cron/lib/task-row.js +246 -0
  198. package/dist/pi/packages/ta-cron/lib/task-util.d.ts +10 -6
  199. package/dist/pi/packages/ta-cron/lib/task-util.js +53 -19
  200. package/dist/pi/packages/ta-cron/lib/task-watchers.d.ts +30 -0
  201. package/dist/pi/packages/ta-cron/lib/task-watchers.js +90 -0
  202. package/dist/pi/packages/ta-cron/lib/tasks-view.d.ts +3 -2
  203. package/dist/pi/packages/ta-cron/lib/tasks-view.js +48 -193
  204. package/dist/pi/packages/ta-cron/lib/tool-line.js +4 -0
  205. package/dist/pi/packages/ta-cron/lib/tool.d.ts +7 -0
  206. package/dist/pi/packages/ta-cron/lib/tool.js +18 -8
  207. package/dist/pi/packages/ta-cron/lib/when.d.ts +39 -0
  208. package/dist/pi/packages/ta-cron/lib/when.js +231 -0
  209. package/dist/pi/packages/ta-cron/package.json +2 -1
  210. package/dist/pi/packages/ta-cron/web/index.js +1091 -340
  211. package/dist/pi/packages/ta-extensions/lib/market-detail.js +9 -5
  212. package/dist/pi/packages/ta-extensions/lib/page.js +1 -1
  213. package/dist/pi/packages/ta-extensions/lib/style.d.ts +1 -1
  214. package/dist/pi/packages/ta-extensions/lib/style.js +1 -1
  215. package/dist/pi/packages/ta-extensions/package.json +1 -1
  216. package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +9 -7
  217. package/dist/pi/packages/ta-extensions/web/index.js +739 -234
  218. package/dist/pi/packages/ta-feedback/README.en.md +10 -0
  219. package/dist/pi/packages/ta-feedback/README.md +10 -0
  220. package/dist/pi/packages/ta-feedback/extension/index.mjs +451 -0
  221. package/dist/pi/packages/ta-feedback/host/index.mjs +1187 -0
  222. package/dist/pi/packages/ta-feedback/lib/extension.d.ts +31 -0
  223. package/dist/pi/packages/ta-feedback/lib/extension.js +160 -0
  224. package/dist/pi/packages/ta-feedback/lib/feedback-git.d.ts +25 -0
  225. package/dist/pi/packages/ta-feedback/lib/feedback-git.js +44 -0
  226. package/dist/pi/packages/ta-feedback/lib/feedback-host.d.ts +133 -0
  227. package/dist/pi/packages/ta-feedback/lib/feedback-host.js +668 -0
  228. package/dist/pi/packages/ta-feedback/lib/feedback-protocol.d.ts +127 -0
  229. package/dist/pi/packages/ta-feedback/lib/feedback-protocol.js +41 -0
  230. package/dist/pi/packages/ta-feedback/lib/feedback-util.d.ts +79 -0
  231. package/dist/pi/packages/ta-feedback/lib/feedback-util.js +252 -0
  232. package/dist/pi/packages/ta-feedback/lib/feedback-view.d.ts +11 -0
  233. package/dist/pi/packages/ta-feedback/lib/feedback-view.js +244 -0
  234. package/dist/pi/packages/ta-feedback/lib/host.d.ts +8 -0
  235. package/dist/pi/packages/ta-feedback/lib/host.js +19 -0
  236. package/dist/pi/packages/ta-feedback/lib/i18n.d.ts +69 -0
  237. package/dist/pi/packages/ta-feedback/lib/i18n.js +250 -0
  238. package/dist/pi/packages/ta-feedback/lib/index.d.ts +8 -0
  239. package/dist/pi/packages/ta-feedback/lib/index.js +88 -0
  240. package/dist/pi/packages/ta-feedback/lib/page.d.ts +35 -0
  241. package/dist/pi/packages/ta-feedback/lib/page.js +135 -0
  242. package/dist/pi/packages/ta-feedback/lib/react.d.ts +8 -0
  243. package/dist/pi/packages/ta-feedback/lib/react.js +8 -0
  244. package/dist/pi/packages/ta-feedback/lib/style.d.ts +4 -0
  245. package/dist/pi/packages/ta-feedback/lib/style.js +71 -0
  246. package/dist/pi/packages/ta-feedback/package.json +65 -0
  247. package/dist/pi/packages/ta-feedback/web/index.js +939 -0
  248. package/dist/pi/packages/ta-games/lib/style.d.ts +1 -1
  249. package/dist/pi/packages/ta-games/lib/style.js +1 -1
  250. package/dist/pi/packages/ta-games/package.json +1 -1
  251. package/dist/pi/packages/ta-games/web/index.js +1 -1
  252. package/dist/pi/packages/ta-glance/extension/index.mjs +27 -8
  253. package/dist/pi/packages/ta-glance/lib/card.js +67 -27
  254. package/dist/pi/packages/ta-glance/lib/glance-json.d.ts +1 -1
  255. package/dist/pi/packages/ta-glance/lib/glance-json.js +8 -1
  256. package/dist/pi/packages/ta-glance/lib/glance-prompt.js +3 -3
  257. package/dist/pi/packages/ta-glance/lib/glance-protocol.d.ts +9 -2
  258. package/dist/pi/packages/ta-glance/lib/glance-spec.js +33 -5
  259. package/dist/pi/packages/ta-glance/lib/glance-speech.d.ts +13 -0
  260. package/dist/pi/packages/ta-glance/lib/glance-speech.js +45 -0
  261. package/dist/pi/packages/ta-glance/lib/i18n.d.ts +5 -0
  262. package/dist/pi/packages/ta-glance/lib/i18n.js +20 -0
  263. package/dist/pi/packages/ta-glance/lib/index.js +11 -1
  264. package/dist/pi/packages/ta-glance/lib/style.d.ts +1 -1
  265. package/dist/pi/packages/ta-glance/lib/style.js +17 -3
  266. package/dist/pi/packages/ta-glance/package.json +2 -1
  267. package/dist/pi/packages/ta-glance/web/index.js +180 -30
  268. package/dist/pi/packages/ta-initiative/extension/index.mjs +3 -2
  269. package/dist/pi/packages/ta-initiative/host/index.mjs +1 -1
  270. package/dist/pi/packages/ta-initiative/lib/chat-proposals.js +1 -1
  271. package/dist/pi/packages/ta-initiative/lib/index.js +1 -0
  272. package/dist/pi/packages/ta-initiative/lib/material-util.js +1 -1
  273. package/dist/pi/packages/ta-initiative/lib/settings.js +2 -1
  274. package/dist/pi/packages/ta-initiative/lib/style.d.ts +1 -1
  275. package/dist/pi/packages/ta-initiative/lib/style.js +1 -1
  276. package/dist/pi/packages/ta-initiative/package.json +1 -1
  277. package/dist/pi/packages/ta-initiative/web/index.js +5 -3
  278. package/dist/pi/packages/ta-launcher/package.json +1 -1
  279. package/dist/pi/packages/ta-manual/lib/manual-util.d.ts +1 -1
  280. package/dist/pi/packages/ta-manual/lib/pictures-c.js +15 -0
  281. package/dist/pi/packages/ta-manual/lib/style.d.ts +1 -1
  282. package/dist/pi/packages/ta-manual/lib/style.js +1 -1
  283. package/dist/pi/packages/ta-manual/lib/topics-a.d.ts +3 -0
  284. package/dist/pi/packages/ta-manual/lib/topics-a.js +295 -0
  285. package/dist/pi/packages/ta-manual/lib/topics-model.d.ts +46 -0
  286. package/dist/pi/packages/ta-manual/lib/topics-model.js +21 -0
  287. package/dist/pi/packages/ta-manual/lib/topics.d.ts +1 -44
  288. package/dist/pi/packages/ta-manual/lib/topics.js +28 -318
  289. package/dist/pi/packages/ta-manual/package.json +1 -1
  290. package/dist/pi/packages/ta-manual/skills/ta-manual/SKILL.md +12 -10
  291. package/dist/pi/packages/ta-manual/web/index.js +97 -24
  292. package/dist/pi/packages/ta-moments/extension/index.mjs +702 -191
  293. package/dist/pi/packages/ta-moments/host/index.mjs +1361 -837
  294. package/dist/pi/packages/ta-moments/lib/index.js +3 -1
  295. package/dist/pi/packages/ta-moments/lib/moments-host-base.d.ts +96 -0
  296. package/dist/pi/packages/ta-moments/lib/moments-host-base.js +276 -0
  297. package/dist/pi/packages/ta-moments/lib/moments-host-pictures.d.ts +22 -0
  298. package/dist/pi/packages/ta-moments/lib/moments-host-pictures.js +167 -0
  299. package/dist/pi/packages/ta-moments/lib/moments-host.d.ts +4 -84
  300. package/dist/pi/packages/ta-moments/lib/moments-host.js +13 -426
  301. package/dist/pi/packages/ta-moments/lib/page.js +3 -3
  302. package/dist/pi/packages/ta-moments/lib/style.d.ts +1 -1
  303. package/dist/pi/packages/ta-moments/lib/style.js +1 -1
  304. package/dist/pi/packages/ta-moments/lib/talk-host-base.d.ts +71 -0
  305. package/dist/pi/packages/ta-moments/lib/talk-host-base.js +171 -0
  306. package/dist/pi/packages/ta-moments/lib/talk-host.d.ts +3 -62
  307. package/dist/pi/packages/ta-moments/lib/talk-host.js +14 -169
  308. package/dist/pi/packages/ta-moments/package.json +1 -1
  309. package/dist/pi/packages/ta-moments/web/index.js +648 -144
  310. package/dist/pi/packages/ta-nearby/extension/index.mjs +9 -0
  311. package/dist/pi/packages/ta-nearby/host/index.mjs +1073 -1018
  312. package/dist/pi/packages/ta-nearby/lib/index.js +8 -5
  313. package/dist/pi/packages/ta-nearby/lib/nearby-home.d.ts +13 -0
  314. package/dist/pi/packages/ta-nearby/lib/nearby-home.js +91 -0
  315. package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.d.ts +12 -0
  316. package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.js +113 -0
  317. package/dist/pi/packages/ta-nearby/lib/nearby-page.d.ts +6 -0
  318. package/dist/pi/packages/ta-nearby/lib/nearby-page.js +157 -0
  319. package/dist/pi/packages/ta-nearby/lib/nearby-service-base.d.ts +161 -0
  320. package/dist/pi/packages/ta-nearby/lib/nearby-service-base.js +343 -0
  321. package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.d.ts +41 -0
  322. package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.js +297 -0
  323. package/dist/pi/packages/ta-nearby/lib/nearby-service.d.ts +6 -167
  324. package/dist/pi/packages/ta-nearby/lib/nearby-service.js +38 -638
  325. package/dist/pi/packages/ta-nearby/lib/nearby-show-view.d.ts +6 -0
  326. package/dist/pi/packages/ta-nearby/lib/nearby-show-view.js +88 -0
  327. package/dist/pi/packages/ta-nearby/lib/nearby-spot.d.ts +6 -0
  328. package/dist/pi/packages/ta-nearby/lib/nearby-spot.js +25 -3
  329. package/dist/pi/packages/ta-nearby/lib/page.d.ts +27 -20
  330. package/dist/pi/packages/ta-nearby/lib/page.js +15 -417
  331. package/dist/pi/packages/ta-nearby/lib/server-texts.d.ts +1 -1
  332. package/dist/pi/packages/ta-nearby/lib/server-texts.js +9 -1
  333. package/dist/pi/packages/ta-nearby/lib/style.d.ts +1 -1
  334. package/dist/pi/packages/ta-nearby/lib/style.js +1 -1
  335. package/dist/pi/packages/ta-nearby/package.json +1 -1
  336. package/dist/pi/packages/ta-nearby/web/index.js +370 -362
  337. package/dist/pi/packages/ta-notify/extension/index.mjs +1 -0
  338. package/dist/pi/packages/ta-notify/lib/settings.js +1 -0
  339. package/dist/pi/packages/ta-notify/package.json +1 -1
  340. package/dist/pi/packages/ta-notify/web/index.js +1 -0
  341. package/dist/pi/packages/ta-plot/extension/index.mjs +1 -0
  342. package/dist/pi/packages/ta-plot/package.json +2 -1
  343. package/dist/pi/packages/ta-recall/extension/index.mjs +1 -0
  344. package/dist/pi/packages/ta-recall/host/index.mjs +1 -0
  345. package/dist/pi/packages/ta-recall/lib/settings.js +1 -0
  346. package/dist/pi/packages/ta-recall/package.json +1 -1
  347. package/dist/pi/packages/ta-recall/web/index.js +2 -0
  348. package/dist/pi/packages/ta-rooms/extension/index.mjs +1 -0
  349. package/dist/pi/packages/ta-rooms/host/index.mjs +497 -492
  350. package/dist/pi/packages/ta-rooms/lib/double-agents.js +6 -6
  351. package/dist/pi/packages/ta-rooms/lib/double-grants.js +10 -10
  352. package/dist/pi/packages/ta-rooms/lib/double-host.js +6 -5
  353. package/dist/pi/packages/ta-rooms/lib/double-tasks-base.d.ts +55 -0
  354. package/dist/pi/packages/ta-rooms/lib/double-tasks-base.js +279 -0
  355. package/dist/pi/packages/ta-rooms/lib/double-tasks.d.ts +3 -45
  356. package/dist/pi/packages/ta-rooms/lib/double-tasks.js +14 -282
  357. package/dist/pi/packages/ta-rooms/lib/double-user.js +2 -2
  358. package/dist/pi/packages/ta-rooms/lib/friend-notices.js +2 -2
  359. package/dist/pi/packages/ta-rooms/lib/i18n.d.ts +1 -0
  360. package/dist/pi/packages/ta-rooms/lib/i18n.js +8 -4
  361. package/dist/pi/packages/ta-rooms/lib/index.js +18 -2
  362. package/dist/pi/packages/ta-rooms/lib/members-view.js +37 -3
  363. package/dist/pi/packages/ta-rooms/lib/page.d.ts +36 -1
  364. package/dist/pi/packages/ta-rooms/lib/page.js +76 -1
  365. package/dist/pi/packages/ta-rooms/lib/room-view.js +22 -17
  366. package/dist/pi/packages/ta-rooms/lib/rooms-home.js +1 -0
  367. package/dist/pi/packages/ta-rooms/lib/style.d.ts +1 -1
  368. package/dist/pi/packages/ta-rooms/lib/style.js +32 -6
  369. package/dist/pi/packages/ta-rooms/package.json +1 -1
  370. package/dist/pi/packages/ta-rooms/web/index.js +223 -38
  371. package/dist/pi/packages/ta-secrets/README.en.md +22 -0
  372. package/dist/pi/packages/ta-secrets/README.md +22 -0
  373. package/dist/pi/packages/ta-secrets/extension/index.mjs +462 -0
  374. package/dist/pi/packages/ta-secrets/host/index.mjs +1341 -0
  375. package/dist/pi/packages/ta-secrets/lib/command-prelude.d.ts +36 -0
  376. package/dist/pi/packages/ta-secrets/lib/command-prelude.js +66 -0
  377. package/dist/pi/packages/ta-secrets/lib/extension.d.ts +28 -0
  378. package/dist/pi/packages/ta-secrets/lib/extension.js +156 -0
  379. package/dist/pi/packages/ta-secrets/lib/host.d.ts +4 -0
  380. package/dist/pi/packages/ta-secrets/lib/host.js +15 -0
  381. package/dist/pi/packages/ta-secrets/lib/i18n.d.ts +47 -0
  382. package/dist/pi/packages/ta-secrets/lib/i18n.js +166 -0
  383. package/dist/pi/packages/ta-secrets/lib/index.d.ts +8 -0
  384. package/dist/pi/packages/ta-secrets/lib/index.js +28 -0
  385. package/dist/pi/packages/ta-secrets/lib/personal-info.d.ts +26 -0
  386. package/dist/pi/packages/ta-secrets/lib/personal-info.js +108 -0
  387. package/dist/pi/packages/ta-secrets/lib/proxy-certs.d.ts +40 -0
  388. package/dist/pi/packages/ta-secrets/lib/proxy-certs.js +200 -0
  389. package/dist/pi/packages/ta-secrets/lib/proxy-scenario.d.ts +6 -0
  390. package/dist/pi/packages/ta-secrets/lib/proxy-scenario.js +91 -0
  391. package/dist/pi/packages/ta-secrets/lib/react.d.ts +8 -0
  392. package/dist/pi/packages/ta-secrets/lib/react.js +8 -0
  393. package/dist/pi/packages/ta-secrets/lib/scrubber.d.ts +20 -0
  394. package/dist/pi/packages/ta-secrets/lib/scrubber.js +70 -0
  395. package/dist/pi/packages/ta-secrets/lib/secrets-protocol.d.ts +106 -0
  396. package/dist/pi/packages/ta-secrets/lib/secrets-protocol.js +134 -0
  397. package/dist/pi/packages/ta-secrets/lib/server-texts.d.ts +14 -0
  398. package/dist/pi/packages/ta-secrets/lib/server-texts.js +62 -0
  399. package/dist/pi/packages/ta-secrets/lib/settings.d.ts +4 -0
  400. package/dist/pi/packages/ta-secrets/lib/settings.js +179 -0
  401. package/dist/pi/packages/ta-secrets/lib/style.d.ts +4 -0
  402. package/dist/pi/packages/ta-secrets/lib/style.js +32 -0
  403. package/dist/pi/packages/ta-secrets/lib/vault-fixture.d.ts +8 -0
  404. package/dist/pi/packages/ta-secrets/lib/vault-fixture.js +22 -0
  405. package/dist/pi/packages/ta-secrets/lib/vault-proxy.d.ts +94 -0
  406. package/dist/pi/packages/ta-secrets/lib/vault-proxy.js +357 -0
  407. package/dist/pi/packages/ta-secrets/lib/vault-service.d.ts +111 -0
  408. package/dist/pi/packages/ta-secrets/lib/vault-service.js +429 -0
  409. package/dist/pi/packages/ta-secrets/lib/vault-store.d.ts +48 -0
  410. package/dist/pi/packages/ta-secrets/lib/vault-store.js +107 -0
  411. package/dist/pi/packages/ta-secrets/package.json +67 -0
  412. package/dist/pi/packages/ta-secrets/web/index.js +579 -0
  413. package/dist/pi/packages/ta-share/extension/index.mjs +1 -0
  414. package/dist/pi/packages/ta-share/host/index.mjs +172 -21
  415. package/dist/pi/packages/ta-share/lib/i18n.d.ts +1 -0
  416. package/dist/pi/packages/ta-share/lib/i18n.js +4 -0
  417. package/dist/pi/packages/ta-share/lib/index.js +1 -1
  418. package/dist/pi/packages/ta-share/lib/share-dialog.js +1 -0
  419. package/dist/pi/packages/ta-share/lib/share-protocol.d.ts +2 -0
  420. package/dist/pi/packages/ta-share/lib/share-service.d.ts +11 -1
  421. package/dist/pi/packages/ta-share/lib/share-service.js +62 -4
  422. package/dist/pi/packages/ta-share/lib/snapshot.d.ts +8 -2
  423. package/dist/pi/packages/ta-share/lib/snapshot.js +93 -7
  424. package/dist/pi/packages/ta-share/lib/style.d.ts +1 -1
  425. package/dist/pi/packages/ta-share/lib/style.js +1 -1
  426. package/dist/pi/packages/ta-share/package.json +1 -1
  427. package/dist/pi/packages/ta-share/web/index.js +7 -2
  428. package/dist/pi/packages/ta-sync/host/index.mjs +1154 -755
  429. package/dist/pi/packages/ta-sync/lib/host.js +3 -0
  430. package/dist/pi/packages/ta-sync/lib/index.js +6 -2
  431. package/dist/pi/packages/ta-sync/lib/migrate-archive.d.ts +8 -6
  432. package/dist/pi/packages/ta-sync/lib/migrate-archive.js +24 -28
  433. package/dist/pi/packages/ta-sync/lib/migrate-i18n.d.ts +10 -0
  434. package/dist/pi/packages/ta-sync/lib/migrate-i18n.js +40 -0
  435. package/dist/pi/packages/ta-sync/lib/migrate-paths.d.ts +24 -0
  436. package/dist/pi/packages/ta-sync/lib/migrate-paths.js +230 -0
  437. package/dist/pi/packages/ta-sync/lib/migrate-protocol.d.ts +18 -0
  438. package/dist/pi/packages/ta-sync/lib/migrate-service.d.ts +11 -1
  439. package/dist/pi/packages/ta-sync/lib/migrate-service.js +28 -1
  440. package/dist/pi/packages/ta-sync/lib/move-panel.d.ts +9 -1
  441. package/dist/pi/packages/ta-sync/lib/move-panel.js +69 -5
  442. package/dist/pi/packages/ta-sync/lib/server-texts.d.ts +1 -0
  443. package/dist/pi/packages/ta-sync/lib/server-texts.js +9 -0
  444. package/dist/pi/packages/ta-sync/lib/style.d.ts +1 -1
  445. package/dist/pi/packages/ta-sync/lib/style.js +8 -1
  446. package/dist/pi/packages/ta-sync/lib/sync-service-base.d.ts +78 -0
  447. package/dist/pi/packages/ta-sync/lib/sync-service-base.js +224 -0
  448. package/dist/pi/packages/ta-sync/lib/sync-service-space.d.ts +36 -0
  449. package/dist/pi/packages/ta-sync/lib/sync-service-space.js +210 -0
  450. package/dist/pi/packages/ta-sync/lib/sync-service.d.ts +3 -99
  451. package/dist/pi/packages/ta-sync/lib/sync-service.js +2 -412
  452. package/dist/pi/packages/ta-sync/package.json +1 -1
  453. package/dist/pi/packages/ta-sync/web/index.js +138 -5
  454. package/dist/pi/packages/ta-sync-cloud/package.json +1 -1
  455. package/dist/pi/packages/ta-team/extension/index.mjs +1 -0
  456. package/dist/pi/packages/ta-team/host/index.mjs +1 -0
  457. package/dist/pi/packages/ta-team/lib/dialogs.d.ts +0 -2
  458. package/dist/pi/packages/ta-team/lib/dialogs.js +0 -227
  459. package/dist/pi/packages/ta-team/lib/i18n-ja.d.ts +3 -0
  460. package/dist/pi/packages/ta-team/lib/i18n-ja.js +211 -0
  461. package/dist/pi/packages/ta-team/lib/i18n-zh-tw.d.ts +3 -0
  462. package/dist/pi/packages/ta-team/lib/i18n-zh-tw.js +211 -0
  463. package/dist/pi/packages/ta-team/lib/i18n-zh.d.ts +3 -0
  464. package/dist/pi/packages/ta-team/lib/i18n-zh.js +211 -0
  465. package/dist/pi/packages/ta-team/lib/i18n.d.ts +1 -2
  466. package/dist/pi/packages/ta-team/lib/i18n.js +6 -624
  467. package/dist/pi/packages/ta-team/lib/index.js +3 -1
  468. package/dist/pi/packages/ta-team/lib/join-dialog.d.ts +3 -0
  469. package/dist/pi/packages/ta-team/lib/join-dialog.js +234 -0
  470. package/dist/pi/packages/ta-team/lib/members-tab.js +2 -1
  471. package/dist/pi/packages/ta-team/lib/style.d.ts +1 -1
  472. package/dist/pi/packages/ta-team/lib/style.js +1 -1
  473. package/dist/pi/packages/ta-team/package.json +1 -1
  474. package/dist/pi/packages/ta-team/web/index.js +2095 -2086
  475. package/dist/pi/packages/ta-usage/README.en.md +6 -0
  476. package/dist/pi/packages/ta-usage/README.md +6 -0
  477. package/dist/pi/packages/ta-usage/host/index.mjs +220 -0
  478. package/dist/pi/packages/ta-usage/lib/host.d.ts +4 -0
  479. package/dist/pi/packages/ta-usage/lib/host.js +9 -0
  480. package/dist/pi/packages/ta-usage/lib/i18n.d.ts +30 -0
  481. package/dist/pi/packages/ta-usage/lib/i18n.js +98 -0
  482. package/dist/pi/packages/ta-usage/lib/index.d.ts +4 -0
  483. package/dist/pi/packages/ta-usage/lib/index.js +20 -0
  484. package/dist/pi/packages/ta-usage/lib/react.d.ts +8 -0
  485. package/dist/pi/packages/ta-usage/lib/react.js +8 -0
  486. package/dist/pi/packages/ta-usage/lib/style.d.ts +4 -0
  487. package/dist/pi/packages/ta-usage/lib/style.js +53 -0
  488. package/dist/pi/packages/ta-usage/lib/usage-host.d.ts +25 -0
  489. package/dist/pi/packages/ta-usage/lib/usage-host.js +70 -0
  490. package/dist/pi/packages/ta-usage/lib/usage-protocol.d.ts +55 -0
  491. package/dist/pi/packages/ta-usage/lib/usage-protocol.js +7 -0
  492. package/dist/pi/packages/ta-usage/lib/usage-util.d.ts +18 -0
  493. package/dist/pi/packages/ta-usage/lib/usage-util.js +159 -0
  494. package/dist/pi/packages/ta-usage/lib/usage-view.d.ts +9 -0
  495. package/dist/pi/packages/ta-usage/lib/usage-view.js +91 -0
  496. package/dist/pi/packages/ta-usage/package.json +61 -0
  497. package/dist/pi/packages/ta-usage/web/index.js +471 -0
  498. package/dist/pi/packages/ta-voice/README.en.md +8 -0
  499. package/dist/pi/packages/ta-voice/README.md +8 -0
  500. package/dist/pi/packages/ta-voice/host/index.mjs +662 -0
  501. package/dist/pi/packages/ta-voice/lib/doubao-frames.d.ts +44 -0
  502. package/dist/pi/packages/ta-voice/lib/doubao-frames.js +116 -0
  503. package/dist/pi/packages/ta-voice/lib/doubao-realtime.d.ts +35 -0
  504. package/dist/pi/packages/ta-voice/lib/doubao-realtime.js +172 -0
  505. package/dist/pi/packages/ta-voice/lib/host.d.ts +20 -0
  506. package/dist/pi/packages/ta-voice/lib/host.js +120 -0
  507. package/dist/pi/packages/ta-voice/lib/openai-realtime.d.ts +73 -0
  508. package/dist/pi/packages/ta-voice/lib/openai-realtime.js +257 -0
  509. package/dist/pi/packages/ta-voice/lib/realtime-socket.d.ts +23 -0
  510. package/dist/pi/packages/ta-voice/lib/realtime-socket.js +80 -0
  511. package/dist/pi/packages/ta-voice/package.json +67 -0
  512. package/dist/pi/packages/ta-workspace/README.md +1 -1
  513. package/dist/pi/packages/ta-workspace/README.zh-cn.md +1 -1
  514. package/dist/pi/packages/ta-workspace/lib/browser-common.d.ts +4 -0
  515. package/dist/pi/packages/ta-workspace/lib/browser-common.js +1 -0
  516. package/dist/pi/packages/ta-workspace/lib/browser-pick.d.ts +49 -0
  517. package/dist/pi/packages/ta-workspace/lib/browser-pick.js +166 -0
  518. package/dist/pi/packages/ta-workspace/lib/browser-webview.js +16 -1
  519. package/dist/pi/packages/ta-workspace/lib/i18n-en.d.ts +3 -0
  520. package/dist/pi/packages/ta-workspace/lib/i18n-en.js +215 -0
  521. package/dist/pi/packages/ta-workspace/lib/i18n-ja.d.ts +3 -0
  522. package/dist/pi/packages/ta-workspace/lib/i18n-ja.js +215 -0
  523. package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.d.ts +3 -0
  524. package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.js +215 -0
  525. package/dist/pi/packages/ta-workspace/lib/i18n.d.ts +7 -3
  526. package/dist/pi/packages/ta-workspace/lib/i18n.js +11 -621
  527. package/dist/pi/packages/ta-workspace/package.json +1 -1
  528. package/dist/pi/packages/ta-workspace/web/index.js +1464 -765
  529. package/dist/public/assets/{abnfDiagram-S7VZAUFO-FSEuUCgT.js → abnfDiagram-S7VZAUFO-w8qXXVn-.js} +1 -1
  530. package/dist/public/assets/{architecture-WOLXFQ4H-Do_DyWCg.js → architecture-WOLXFQ4H-B-FHaYwY.js} +1 -1
  531. package/dist/public/assets/{architectureDiagram-YGSQEFNW-D-N2qDs4.js → architectureDiagram-YGSQEFNW-DTnoGaaX.js} +1 -1
  532. package/dist/public/assets/{blockDiagram-APKKGZFW-Ds6DzHNZ.js → blockDiagram-APKKGZFW-CyeBzv-v.js} +1 -1
  533. package/dist/public/assets/{browser-D2BcOPKG.js → browser-Cb38iiEE.js} +1 -1
  534. package/dist/public/assets/{browser-KlrZxPbE.js → browser-DXexCqIh.js} +2 -2
  535. package/dist/public/assets/{c4Diagram-KJ2TOQU5-D5ZdqxrP.js → c4Diagram-KJ2TOQU5-CJJqDqyQ.js} +1 -1
  536. package/dist/public/assets/{chunk-6MUBBAK2-CWOwhB3b.js → chunk-6MUBBAK2-DbvUMdNm.js} +1 -1
  537. package/dist/public/assets/{chunk-AXFCVDMN-Dr6p2RGg.js → chunk-AXFCVDMN-D4hlZGtj.js} +1 -1
  538. package/dist/public/assets/{chunk-BG4553SI-DUCV_pmW.js → chunk-BG4553SI-VNa9Q9On.js} +1 -1
  539. package/dist/public/assets/{chunk-DQASFODM-Yxd3jIXM.js → chunk-DQASFODM-BtlEbc_V.js} +1 -1
  540. package/dist/public/assets/{chunk-HFQBQIA3-C24I15MF.js → chunk-HFQBQIA3-CAYSo4CJ.js} +1 -1
  541. package/dist/public/assets/{chunk-KQLB2F66-Dxk-aejD.js → chunk-KQLB2F66-CyKdg6hW.js} +1 -1
  542. package/dist/public/assets/{chunk-KS47KZWR-DPyr7gb8.js → chunk-KS47KZWR-BMogCB2r.js} +1 -1
  543. package/dist/public/assets/{chunk-LEVMRMFU-D_mEFJGR.js → chunk-LEVMRMFU-Y9wr-8qB.js} +1 -1
  544. package/dist/public/assets/{chunk-M57EVK23-DfMFxQib.js → chunk-M57EVK23-DL3IAQKR.js} +1 -1
  545. package/dist/public/assets/{chunk-OY52VR5R-O9W83Laa.js → chunk-OY52VR5R-CJBFHdg6.js} +1 -1
  546. package/dist/public/assets/{chunk-QB3YPZ4I-IdikGcw1.js → chunk-QB3YPZ4I-CyuWKZZv.js} +1 -1
  547. package/dist/public/assets/{chunk-R3KSYZAL-DLpaFCvz.js → chunk-R3KSYZAL-DxvGhfpm.js} +1 -1
  548. package/dist/public/assets/{chunk-STOXU5M4-Lx-CZ4Ql.js → chunk-STOXU5M4-Cpdl6bfz.js} +1 -1
  549. package/dist/public/assets/{chunk-TU62E6Q5-DCnr5NsA.js → chunk-TU62E6Q5-CIxOg6QF.js} +1 -1
  550. package/dist/public/assets/{chunk-X4PVCEUW-Ct7aUJFY.js → chunk-X4PVCEUW-DCFSCRBh.js} +1 -1
  551. package/dist/public/assets/{chunk-XXDRQBXY-CQhxfoYw.js → chunk-XXDRQBXY-B2R8Cxf7.js} +1 -1
  552. package/dist/public/assets/{classDiagram-v2-L25IHNXF-DPSu5qYq.js → classDiagram-v2-L25IHNXF-B7W9HSbj.js} +1 -1
  553. package/dist/public/assets/{client-C8gi9Fk2.js → client-D75LfyFa.js} +1 -1
  554. package/dist/public/assets/{common-DrZR0tgm.js → common-CjqTomRQ.js} +1 -1
  555. package/dist/public/assets/{cose-bilkent-JH36ORCC-CFimsFsN.js → cose-bilkent-JH36ORCC-CXSLFyCH.js} +1 -1
  556. package/dist/public/assets/cynefin-EF2NZ3EQ-BIcbDns7.js +1 -0
  557. package/dist/public/assets/{cynefinDiagram-L36ESFBY-CiAWhkVp.js → cynefinDiagram-L36ESFBY-DTv0Kn1r.js} +1 -1
  558. package/dist/public/assets/{d3-selection-C8RIDfkO.js → d3-selection-g4Hl3_NH.js} +1 -1
  559. package/dist/public/assets/{dagre-SPEB5RXH-l1nRD1Fx.js → dagre-SPEB5RXH-BujVqk5R.js} +1 -1
  560. package/dist/public/assets/{diagram-3B7GL73J-ipqtnhoX.js → diagram-3B7GL73J-Ds-VnLzP.js} +1 -1
  561. package/dist/public/assets/{diagram-DNEMPZML-VpIcHRUP.js → diagram-DNEMPZML-BBoIIK-a.js} +1 -1
  562. package/dist/public/assets/{diagram-L3MUGCDN-8VdVmcS6.js → diagram-L3MUGCDN-Glgd5N_n.js} +1 -1
  563. package/dist/public/assets/{diagram-LA4NIPWU-Bej-aiF0.js → diagram-LA4NIPWU-B4EODdUU.js} +1 -1
  564. package/dist/public/assets/{diagram-MHCOC4E2-D8gW4bVQ.js → diagram-MHCOC4E2-pzDDXO2J.js} +1 -1
  565. package/dist/public/assets/{diagram-XPFHEONP-BMevAJ1M.js → diagram-XPFHEONP-l--gwSuK.js} +1 -1
  566. package/dist/public/assets/{dist-DBKJcjvW.js → dist-C0u3lAFR.js} +1 -1
  567. package/dist/public/assets/{ebnfDiagram-UZSYDL2S-C3HDTOzn.js → ebnfDiagram-UZSYDL2S-BVfPeaVX.js} +1 -1
  568. package/dist/public/assets/{editor.api-BMWdjwhK.js → editor.api-BMcewI3C.js} +1 -1
  569. package/dist/public/assets/{elk-XV6XMXQE-XOOPrVin.js → elk-XV6XMXQE-BFJtUnG9.js} +1 -1
  570. package/dist/public/assets/{erDiagram-EYBAPDEH-Cr-vwx1l.js → erDiagram-EYBAPDEH-BWxMtfIc.js} +1 -1
  571. package/dist/public/assets/{eventmodeling-K75KTNOO-DbPhpfxn.js → eventmodeling-K75KTNOO-YwYgBgCX.js} +1 -1
  572. package/dist/public/assets/flowDiagram-MALGAFMO-Dah4--NW.js +1 -0
  573. package/dist/public/assets/{freemarker2-6h_1-8qB.js → freemarker2-B8HquI7K.js} +1 -1
  574. package/dist/public/assets/{ganttDiagram-23REXITY-C7kNPXx3.js → ganttDiagram-23REXITY-CBqv7wbi.js} +1 -1
  575. package/dist/public/assets/gitGraph-VSP46ZUC-BwDfrSZS.js +1 -0
  576. package/dist/public/assets/{gitGraphDiagram-STJD7YCW-CVnEJEZr.js → gitGraphDiagram-STJD7YCW-BLSf23f_.js} +1 -1
  577. package/dist/public/assets/{handlebars-F4lp3oLr.js → handlebars-P1qmNq4N.js} +1 -1
  578. package/dist/public/assets/{html-Dj6f8B_g.js → html-Ceswbytr.js} +1 -1
  579. package/dist/public/assets/{index-DnNrrk68.js → index-10isUUN4.js} +2 -2
  580. package/dist/public/assets/info-OHQRW6UA-Ch8aMV1p.js +1 -0
  581. package/dist/public/assets/{infoDiagram-KBXO4MBG-DcttQWdp.js → infoDiagram-KBXO4MBG-LvOtgUlm.js} +1 -1
  582. package/dist/public/assets/{ishikawaDiagram-M35NCXHK-BSUYTZf6.js → ishikawaDiagram-M35NCXHK-CwUZOvcm.js} +1 -1
  583. package/dist/public/assets/{javascript-b_BkOE5Y.js → javascript-B3FXC8qR.js} +1 -1
  584. package/dist/public/assets/{journeyDiagram-OPLOXDXO-BCfd5-6n.js → journeyDiagram-OPLOXDXO-5j1KtwTt.js} +1 -1
  585. package/dist/public/assets/{jsonMode-Cq5QJbVZ.js → jsonMode-CrCyxNQI.js} +1 -1
  586. package/dist/public/assets/{kanban-definition-BZKZHSQY-B3nenaw_.js → kanban-definition-BZKZHSQY-BKAB5id1.js} +1 -1
  587. package/dist/public/assets/{liquid-CGuZI_Aa.js → liquid-CXZRIgp2.js} +1 -1
  588. package/dist/public/assets/{mdx-Dt9yTqnf.js → mdx-Dm3uNczM.js} +1 -1
  589. package/dist/public/assets/{mermaid-parser.core-CquzROwT.js → mermaid-parser.core-C755A-rX.js} +3 -3
  590. package/dist/public/assets/{mermaid.core-Bx-e_Scq.js → mermaid.core-CQrYmFAR.js} +4 -4
  591. package/dist/public/assets/{mindmap-definition-I2QAS2VK-DyeewbnH.js → mindmap-definition-I2QAS2VK-DNJQKYbK.js} +1 -1
  592. package/dist/public/assets/module-9otB6_kX.js +1 -0
  593. package/dist/public/assets/{module-Cm_mLwAQ.js → module-C3jC5acf.js} +1 -1
  594. package/dist/public/assets/module-C_MyFORb.js +1 -0
  595. package/dist/public/assets/module-Cjpl4gva.js +1 -0
  596. package/dist/public/assets/{module-DUYj4E8T.js → module-D8yH9xCl.js} +1 -1
  597. package/dist/public/assets/module-DlHjBjOg.js +1 -0
  598. package/dist/public/assets/module-QsLiJaR6.js +1 -0
  599. package/dist/public/assets/module-aaW5Ri2L.js +2771 -0
  600. package/dist/public/assets/module-gSy9fKBo.js +1 -0
  601. package/dist/public/assets/{monaco-nvIdDTWu.js → monaco-BS7JBNW4.js} +3 -3
  602. package/dist/public/assets/packet-JDAUHWVQ-LqMrrc60.js +1 -0
  603. package/dist/public/assets/{pegDiagram-FD4XPPHP-B884_KoR.js → pegDiagram-FD4XPPHP-BzbBCWht.js} +1 -1
  604. package/dist/public/assets/pie-XZMESJXO-BWzABXQU.js +1 -0
  605. package/dist/public/assets/{pieDiagram-J4AKIIQI-I40wRwyy.js → pieDiagram-J4AKIIQI-Bf_LDukL.js} +1 -1
  606. package/dist/public/assets/{python-Djw4wvG9.js → python-jgOUhB-F.js} +1 -1
  607. package/dist/public/assets/{quadrantDiagram-XTYBLID2-DyNOImfk.js → quadrantDiagram-XTYBLID2-CdMHWnKX.js} +1 -1
  608. package/dist/public/assets/radar-ABXABTNO-CR4kNiUj.js +1 -0
  609. package/dist/public/assets/railroad-I3PHUGI6-BAkWtkGC.js +1 -0
  610. package/dist/public/assets/{railroad-abnf-LNEFI6M7-3G0zWzgf.js → railroad-abnf-LNEFI6M7-DQGYaRbc.js} +1 -1
  611. package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-B5XRDRWS.js → railroad-ebnf-DWYD2UWJ-D6Ljza0U.js} +1 -1
  612. package/dist/public/assets/{railroad-peg-JR7BVNR7-rcIioIyH.js → railroad-peg-JR7BVNR7-Du9hL1Gf.js} +1 -1
  613. package/dist/public/assets/{railroadDiagram-MRQ6NCDL-CDM2ahQM.js → railroadDiagram-MRQ6NCDL-CS_JnlGN.js} +1 -1
  614. package/dist/public/assets/{razor-CStezNUn.js → razor-BWj90God.js} +1 -1
  615. package/dist/public/assets/{requirementDiagram-Y7LWUY3S-hbb6WtfM.js → requirementDiagram-Y7LWUY3S-Cq8rRz2y.js} +1 -1
  616. package/dist/public/assets/{resolver-0zC31mg5.js → resolver-BPuspqws.js} +1 -1
  617. package/dist/public/assets/{sankeyDiagram-WGJFYUXA-DLV3Aoae.js → sankeyDiagram-WGJFYUXA-aK7jRBVK.js} +1 -1
  618. package/dist/public/assets/{sequenceDiagram-5NDRBG5M-BWxOV5U9.js → sequenceDiagram-5NDRBG5M-BxcIyc38.js} +1 -1
  619. package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-C-TaUPaQ.js → stateDiagram-v2-FJ4FJNEA-Ctletlj4.js} +1 -1
  620. package/dist/public/assets/{swimlanes-UMQ2AFYF-CJY0BFmc.js → swimlanes-UMQ2AFYF-DaD55xd2.js} +1 -1
  621. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CytCT4x3.js +8 -0
  622. package/dist/public/assets/{timeline-definition-SEUHKTQE-CUfQb8Gv.js → timeline-definition-SEUHKTQE-Ce19CDiJ.js} +1 -1
  623. package/dist/public/assets/treeView-D4JQ5SDB-DvzNkX4G.js +1 -0
  624. package/dist/public/assets/treemap-SAJKECNS-BuUeBmMd.js +1 -0
  625. package/dist/public/assets/{typescript-B7kmi8MF.js → typescript-RgyfxmPQ.js} +1 -1
  626. package/dist/public/assets/{usecaseDiagram-AFA6YXN4-BKTVAp-G.js → usecaseDiagram-AFA6YXN4-CAVEBKQS.js} +1 -1
  627. package/dist/public/assets/{vennDiagram-NNMJR3RB-CN1RxNTS.js → vennDiagram-NNMJR3RB-DHyJxlHv.js} +1 -1
  628. package/dist/public/assets/wardley-7MLQ67FV-DSfdKACG.js +1 -0
  629. package/dist/public/assets/{wardleyDiagram-S7YFUSEH-JJ6qcpu1.js → wardleyDiagram-S7YFUSEH-C-FCHxR7.js} +1 -1
  630. package/dist/public/assets/{xml-DVamlHEU.js → xml-DiA1T3iN.js} +1 -1
  631. package/dist/public/assets/{xychartDiagram-GGNKY7IX-BNakYgUZ.js → xychartDiagram-GGNKY7IX-BlnHU6Gz.js} +1 -1
  632. package/dist/public/assets/{yaml-BihGeFrM.js → yaml-dnCcfJBR.js} +1 -1
  633. package/dist/public/ext/index.json +1 -0
  634. package/dist/public/ext/ta-3d.js +660 -0
  635. package/dist/public/ext/ta-glance.js +1611 -0
  636. package/dist/public/ext/ta-plot.js +1320 -0
  637. package/dist/public/index.html +2 -2
  638. package/dist/serve/index.mjs +10558 -7361
  639. package/package.json +45 -39
  640. package/dist/public/assets/cynefin-EF2NZ3EQ-Dcc0sCHf.js +0 -1
  641. package/dist/public/assets/flowDiagram-MALGAFMO-CDXqnHAQ.js +0 -1
  642. package/dist/public/assets/gitGraph-VSP46ZUC-KPsoB6Z1.js +0 -1
  643. package/dist/public/assets/info-OHQRW6UA-CtM6s0SQ.js +0 -1
  644. package/dist/public/assets/module-C-ofp7U4.js +0 -1
  645. package/dist/public/assets/module-DDH-aU6z.js +0 -1
  646. package/dist/public/assets/module-DRofmFJn.js +0 -1
  647. package/dist/public/assets/module-MaD4hvv4.js +0 -1
  648. package/dist/public/assets/module-ZDJutm0b.js +0 -1
  649. package/dist/public/assets/module-dnDlIzeV.js +0 -2616
  650. package/dist/public/assets/module-qoBVcE5h.js +0 -1
  651. package/dist/public/assets/packet-JDAUHWVQ-XKjiwdar.js +0 -1
  652. package/dist/public/assets/pie-XZMESJXO-MuCMavHL.js +0 -1
  653. package/dist/public/assets/radar-ABXABTNO-Cq12GHJS.js +0 -1
  654. package/dist/public/assets/railroad-I3PHUGI6-CfeMswZU.js +0 -1
  655. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-DdFDl6aK.js +0 -8
  656. package/dist/public/assets/treeView-D4JQ5SDB-BQ4uUy4s.js +0 -1
  657. package/dist/public/assets/treemap-SAJKECNS-BFTTkjF9.js +0 -1
  658. package/dist/public/assets/wardley-7MLQ67FV-BbyzsA8S.js +0 -1
@@ -1,5 +1,5 @@
1
1
  // web-src/nearby-service.ts
2
- import { randomBytes as randomBytes3 } from "node:crypto";
2
+ import { randomBytes as randomBytes4 } from "node:crypto";
3
3
 
4
4
  // ../ta-protocol/esm/common/language.js
5
5
  var TaLanguageUtil;
@@ -234,60 +234,6 @@ var FaceUtil;
234
234
  FaceUtil2.art = art;
235
235
  })(FaceUtil || (FaceUtil = {}));
236
236
 
237
- // web-src/nearby-crypto.ts
238
- import { createCipheriv, createDecipheriv, createECDH, createHmac, hkdfSync, randomBytes } from "node:crypto";
239
- var SLOT_MS = 15 * 60000;
240
-
241
- class NearbyKeys {
242
- createdAt;
243
- e;
244
- x;
245
- ecdh;
246
- constructor(createdAt = Date.now()) {
247
- this.createdAt = createdAt;
248
- this.e = randomBytes(9).toString("base64url");
249
- this.ecdh = createECDH("prime256v1");
250
- this.x = this.ecdh.generateKeys().toString("base64url");
251
- }
252
- keyWith(e, x) {
253
- const secret = this.ecdh.computeSecret(Buffer.from(x, "base64url"));
254
- return Buffer.from(hkdfSync("sha256", secret, [this.e, e].sort().join("."), "ta-near/1 seal", 32));
255
- }
256
- }
257
- var NearbyCrypto;
258
- ((NearbyCrypto) => {
259
- function slot(now = Date.now()) {
260
- return Math.floor(now / SLOT_MS);
261
- }
262
- NearbyCrypto.slot = slot;
263
- function mark(identity, slot2) {
264
- return createHmac("sha256", identity).update(`ta-near/1 ${slot2}`).digest().subarray(0, 12).toString("base64url");
265
- }
266
- NearbyCrypto.mark = mark;
267
- function marks(identity, mark2, now = Date.now()) {
268
- const at = slot(now);
269
- return NearbyCrypto.mark(identity, at) === mark2 || NearbyCrypto.mark(identity, at - 1) === mark2;
270
- }
271
- NearbyCrypto.marks = marks;
272
- function seal(key, value) {
273
- const iv = randomBytes(12);
274
- const cipher = createCipheriv("aes-256-gcm", key, iv);
275
- const body = Buffer.concat([cipher.update(JSON.stringify(value), "utf8"), cipher.final(), cipher.getAuthTag()]);
276
- return { i: iv.toString("base64url"), c: body.toString("base64url") };
277
- }
278
- NearbyCrypto.seal = seal;
279
- function open(key, sealed) {
280
- const body = Buffer.from(sealed.c, "base64url");
281
- if (body.length < 16) {
282
- throw new Error("Too short.");
283
- }
284
- const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(sealed.i, "base64url"));
285
- decipher.setAuthTag(body.subarray(body.length - 16));
286
- return JSON.parse(Buffer.concat([decipher.update(body.subarray(0, body.length - 16)), decipher.final()]).toString("utf8"));
287
- }
288
- NearbyCrypto.open = open;
289
- })(NearbyCrypto ||= {});
290
-
291
237
  // web-src/nearby-meet.ts
292
238
  import { createHash } from "node:crypto";
293
239
  var NearbyMeetUtil;
@@ -753,322 +699,478 @@ class NearbyChannel {
753
699
  var NAME = "@celljs/ta-nearby";
754
700
  var NEARBY_PORT = 47232;
755
701
  var NEARBY_VIEW = `${NAME}/nearby`;
756
- var NearbyKeys2;
702
+ var NearbyKeys;
757
703
  ((NearbyKeys) => {
758
704
  NearbyKeys.VISIBLE = "visible";
759
705
  NearbyKeys.STATUS = "status";
760
706
  NearbyKeys.SETTINGS = "settings";
761
707
  NearbyKeys.CARDS = "cards";
762
708
  NearbyKeys.MET = "met";
763
- })(NearbyKeys2 ||= {});
709
+ })(NearbyKeys ||= {});
764
710
  var SHOW_MAX = 600 * 1024;
765
711
 
766
- // web-src/nearby-spot.ts
767
- import { createHash as createHash2, randomBytes as randomBytes2, randomInt } from "node:crypto";
768
-
769
- // ../ta-relay/esm/common/relay-protocol.js
770
- var RELAY_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' https: data: blob:; style-src 'unsafe-inline' https: data:; img-src https: data: blob:; font-src https: data:; media-src https: data: blob:; connect-src 'none'; form-action 'none'";
771
- var RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
772
- var RELAY_SHARE_MAX_BYTES = 8 * 1024 * 1024;
773
- var RELAY_SHARE_CHUNK_BYTES = 192 * 1024;
774
- var RELAY_CONTENT_MAX_BYTES = 8 * 1024 * 1024;
775
- var RelayCloseCode;
776
- (function(RelayCloseCode2) {
777
- RelayCloseCode2[RelayCloseCode2["HOST_OFFLINE"] = 4404] = "HOST_OFFLINE";
778
- RelayCloseCode2[RelayCloseCode2["REFUSED"] = 4401] = "REFUSED";
779
- RelayCloseCode2[RelayCloseCode2["REPLACED"] = 4409] = "REPLACED";
780
- RelayCloseCode2[RelayCloseCode2["CLOSED_BY_HOST"] = 4410] = "CLOSED_BY_HOST";
781
- RelayCloseCode2[RelayCloseCode2["FULL"] = 4429] = "FULL";
782
- RelayCloseCode2[RelayCloseCode2["TIMEOUT"] = 4408] = "TIMEOUT";
783
- })(RelayCloseCode || (RelayCloseCode = {}));
784
- var RELAY_PING = "ping";
785
- var RELAY_HUB_MAX_VALUE = 96 * 1024;
786
- var RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
712
+ // web-src/nearby-crypto.ts
713
+ import { createCipheriv, createDecipheriv, createECDH, createHmac, hkdfSync, randomBytes } from "node:crypto";
714
+ var SLOT_MS = 15 * 60000;
787
715
 
788
- // ../ta-relay/esm/common/relay-spot.js
789
- var RELAY_SPOT_PATH = "/v1/spot/";
790
- var RELAY_SPOT_JOIN_MS = 10 * 60000;
791
- var RELAY_SPOT_TRIES = 10;
792
- var RELAY_SPOT_TRIES_MS = 10 * 60000;
793
- var RelaySpotCloseCode;
794
- (function(RelaySpotCloseCode2) {
795
- RelaySpotCloseCode2[RelaySpotCloseCode2["BAD"] = 4400] = "BAD";
796
- RelaySpotCloseCode2[RelaySpotCloseCode2["NONE"] = 4404] = "NONE";
797
- RelaySpotCloseCode2[RelaySpotCloseCode2["LATE"] = 4410] = "LATE";
798
- RelaySpotCloseCode2[RelaySpotCloseCode2["FULL"] = 4429] = "FULL";
799
- RelaySpotCloseCode2[RelaySpotCloseCode2["TRIES"] = 4428] = "TRIES";
800
- })(RelaySpotCloseCode || (RelaySpotCloseCode = {}));
801
- var RelaySpotTries;
802
- (function(RelaySpotTries2) {
803
- function keyOf(address) {
804
- const ip = (address !== null && address !== undefined ? address : "").trim().replace(/^::ffff:/i, "");
805
- if (!ip.includes(":")) {
806
- return ip || "unknown";
807
- }
808
- const [head, tail = ""] = ip.toLowerCase().split("::");
809
- const groups = head ? head.split(":") : [];
810
- const rest = tail ? tail.split(":") : [];
811
- const full = [...groups, ...Array(Math.max(0, 8 - groups.length - rest.length)).fill("0"), ...rest];
812
- return `${full.slice(0, 4).map((group) => group.replace(/^0+(?=.)/, "")).join(":")}::/64`;
813
- }
814
- RelaySpotTries2.keyOf = keyOf;
815
- function recent(fails, now) {
816
- return fails.filter((at) => now - at < RELAY_SPOT_TRIES_MS);
817
- }
818
- RelaySpotTries2.recent = recent;
819
- function blocked(fails, now) {
820
- return recent(fails, now).length >= RELAY_SPOT_TRIES;
716
+ class NearbyKeys2 {
717
+ createdAt;
718
+ e;
719
+ x;
720
+ ecdh;
721
+ constructor(createdAt = Date.now()) {
722
+ this.createdAt = createdAt;
723
+ this.e = randomBytes(9).toString("base64url");
724
+ this.ecdh = createECDH("prime256v1");
725
+ this.x = this.ecdh.generateKeys().toString("base64url");
821
726
  }
822
- RelaySpotTries2.blocked = blocked;
823
- function until(fails, now) {
824
- const kept = recent(fails, now).sort((a, b) => a - b);
825
- return kept.length >= RELAY_SPOT_TRIES ? kept[kept.length - RELAY_SPOT_TRIES] + RELAY_SPOT_TRIES_MS : now;
727
+ keyWith(e, x) {
728
+ const secret = this.ecdh.computeSecret(Buffer.from(x, "base64url"));
729
+ return Buffer.from(hkdfSync("sha256", secret, [this.e, e].sort().join("."), "ta-near/1 seal", 32));
826
730
  }
827
- RelaySpotTries2.until = until;
828
- })(RelaySpotTries || (RelaySpotTries = {}));
829
-
830
- // web-src/nearby-spot.ts
831
- var ANSWER_MS = 6000;
832
- var PING_MS = 30000;
833
- var NearbySpotUtil;
834
- ((NearbySpotUtil) => {
835
- function code() {
836
- return String(randomInt(0, 1e6)).padStart(6, "0");
731
+ }
732
+ var NearbyCrypto;
733
+ ((NearbyCrypto) => {
734
+ function slot(now = Date.now()) {
735
+ return Math.floor(now / SLOT_MS);
837
736
  }
838
- NearbySpotUtil.code = code;
839
- function valid(code2) {
840
- return typeof code2 === "string" && /^\d{6}$/.test(code2);
737
+ NearbyCrypto.slot = slot;
738
+ function mark(identity, slot2) {
739
+ return createHmac("sha256", identity).update(`ta-near/1 ${slot2}`).digest().subarray(0, 12).toString("base64url");
841
740
  }
842
- NearbySpotUtil.valid = valid;
843
- function id(code2) {
844
- return createHash2("sha256").update(`ta-near/1 spot ${code2}`).digest().subarray(0, 16).toString("base64url");
741
+ NearbyCrypto.mark = mark;
742
+ function marks(identity, mark2, now = Date.now()) {
743
+ const at = slot(now);
744
+ return NearbyCrypto.mark(identity, at) === mark2 || NearbyCrypto.mark(identity, at - 1) === mark2;
845
745
  }
846
- NearbySpotUtil.id = id;
847
- function url(relay, code2) {
848
- return relay.replace(/\/+$/, "").replace(/^http/, "ws") + RELAY_SPOT_PATH + id(code2);
746
+ NearbyCrypto.marks = marks;
747
+ function seal(key, value) {
748
+ const iv = randomBytes(12);
749
+ const cipher = createCipheriv("aes-256-gcm", key, iv);
750
+ const body = Buffer.concat([cipher.update(JSON.stringify(value), "utf8"), cipher.final(), cipher.getAuthTag()]);
751
+ return { i: iv.toString("base64url"), c: body.toString("base64url") };
849
752
  }
850
- NearbySpotUtil.url = url;
851
- function until(opened) {
852
- return opened + RELAY_SPOT_JOIN_MS;
753
+ NearbyCrypto.seal = seal;
754
+ function open(key, sealed) {
755
+ const body = Buffer.from(sealed.c, "base64url");
756
+ if (body.length < 16) {
757
+ throw new Error("Too short.");
758
+ }
759
+ const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(sealed.i, "base64url"));
760
+ decipher.setAuthTag(body.subarray(body.length - 16));
761
+ return JSON.parse(Buffer.concat([decipher.update(body.subarray(0, body.length - 16)), decipher.final()]).toString("utf8"));
853
762
  }
854
- NearbySpotUtil.until = until;
855
- })(NearbySpotUtil ||= {});
763
+ NearbyCrypto.open = open;
764
+ })(NearbyCrypto ||= {});
856
765
 
857
- class NearbySpot {
858
- code;
859
- mine;
860
- handlers;
861
- socket;
862
- ping;
863
- pending = new Map;
864
- opened = 0;
865
- constructor(code, mine, handlers) {
866
- this.code = code;
867
- this.mine = mine;
868
- this.handlers = handlers;
766
+ // web-src/nearby-service-base.ts
767
+ var GONE_MS = 1e4;
768
+ var INVITE_MS = 10 * 60000;
769
+ var GATHER_MS = 5 * 60000;
770
+ var PROPOSE_GAP_MS = 2 * 60 * 60000;
771
+ var SKEW_MS = 5 * 60000;
772
+ var TICK_MS = 2000;
773
+ var IDENTITY_MS = 1e4;
774
+ var INITIATIVE = "@celljs/ta-initiative";
775
+ var NOTIFY = "@celljs/ta-notify";
776
+ var ROOM_KIND = "nearby.room";
777
+ var MEET_KIND = "nearby.meet";
778
+ var GREET_KIND = "nearby.greet";
779
+ var MEET_A_DAY = 3;
780
+ var MET_MS = 30 * 24 * 60 * 60000;
781
+ var ROOMS_KIND = "ta-rooms";
782
+
783
+ class NearbyServiceBase {
784
+ host;
785
+ options;
786
+ visible;
787
+ settings = {};
788
+ keys;
789
+ previous;
790
+ beacon;
791
+ channel;
792
+ heard = new Map;
793
+ sent = new Map;
794
+ received = new Map;
795
+ identity;
796
+ identityAt = 0;
797
+ friends = [];
798
+ friendsAt = 0;
799
+ error;
800
+ timer;
801
+ published = "";
802
+ proposedAt = 0;
803
+ madeAt = 0;
804
+ defined = false;
805
+ stopRooms;
806
+ spot;
807
+ shown;
808
+ cards = {};
809
+ met = {};
810
+ greets = new Map;
811
+ hellos = new Map;
812
+ greeted = new Map;
813
+ kinds = new Set;
814
+ spotTimer;
815
+ now;
816
+ constructor(host, options = {}) {
817
+ this.host = host;
818
+ this.options = options;
819
+ this.now = options.now ?? Date.now;
869
820
  }
870
- connect(relay) {
871
- return new Promise((resolve, reject) => {
872
- let ready = false;
873
- const socket = new WebSocket(NearbySpotUtil.url(relay, this.code));
874
- this.socket = socket;
875
- socket.onopen = () => socket.send(JSON.stringify({ t: this.mine ? "open" : "join" }));
876
- socket.onmessage = (event) => {
877
- if (typeof event.data !== "string" || event.data.length < 2 || event.data[0] !== "{") {
878
- return;
879
- }
880
- let message;
881
- try {
882
- message = JSON.parse(event.data);
883
- } catch {
884
- return;
885
- }
886
- if (message.t === "ready") {
887
- ready = true;
888
- this.opened = message.opened;
889
- this.ping = setInterval(() => this.send(RELAY_PING), PING_MS);
890
- resolve(message.opened);
891
- } else if (message.t === "here") {
892
- this.handlers.here(message.b);
893
- } else if (message.t === "gone") {
894
- this.handlers.gone(message.e);
895
- } else if (message.t === "miss") {
896
- this.settle(message.id, undefined, new Error("No longer there."));
897
- } else if (message.t === "frame") {
898
- if (message.re) {
899
- this.settle(message.id, message.f);
900
- } else {
901
- this.handlers.frame(message.from, message.f).then((answer) => {
902
- if (answer) {
903
- this.send(JSON.stringify({ t: "to", to: message.from, id: message.id, f: answer, re: true }));
904
- }
905
- });
906
- }
907
- }
908
- };
909
- socket.onclose = (event) => {
910
- clearInterval(this.ping);
911
- for (const id of [...this.pending.keys()]) {
912
- this.settle(id, undefined, new Error("The spot closed."));
913
- }
914
- if (!ready) {
915
- reject(new NearbySpotError(event.code));
916
- } else if (this.socket === socket) {
917
- this.socket = undefined;
918
- this.handlers.closed(this);
919
- }
920
- };
921
- socket.onerror = () => {
922
- return;
923
- };
924
- });
925
- }
926
- here(beacon) {
927
- this.send(JSON.stringify({ t: "here", b: beacon }));
928
- }
929
- request(to, frame) {
930
- const id = randomBytes2(9).toString("base64url");
931
- return new Promise((resolve, reject) => {
932
- const timer = setTimeout(() => this.settle(id, undefined, new Error("No answer.")), ANSWER_MS);
933
- this.pending.set(id, { resolve, reject, timer });
934
- this.send(JSON.stringify({ t: "to", to, id, f: frame }));
935
- });
821
+ async setVisible(on, minutes) {
822
+ if (!on) {
823
+ this.close();
824
+ await this.host.setExtensionData(NAME, NearbyKeys.VISIBLE, null);
825
+ return this.publish(true);
826
+ }
827
+ const now = this.now();
828
+ const visible = { since: now, ...typeof minutes === "number" && minutes > 0 ? { until: now + Math.round(minutes) * 60000 } : {} };
829
+ await this.host.setExtensionData(NAME, NearbyKeys.VISIBLE, visible);
830
+ this.close();
831
+ await this.open(visible);
832
+ return this.status();
936
833
  }
937
- close() {
938
- clearInterval(this.ping);
939
- const socket = this.socket;
940
- this.socket = undefined;
834
+ async open(visible) {
835
+ this.visible = visible;
836
+ this.error = undefined;
837
+ await this.loadIdentity();
838
+ this.keys = new NearbyKeys2(this.now());
839
+ const channel = new NearbyChannel((frame) => this.receive(frame));
840
+ const port = Number(process.env.TA_NEARBY_PORT) || this.options.port || NEARBY_PORT;
841
+ const beacon = new NearbyBeacon({ port, targets: this.options.targets, intervalMs: this.options.intervalMs }, (data, address) => this.hear(data, address));
941
842
  try {
942
- socket?.close(1000, "Bye.");
943
- } catch {}
944
- }
945
- send(text) {
946
- if (this.socket?.readyState === 1) {
947
- this.socket.send(text);
843
+ await channel.start();
844
+ await beacon.start(() => this.beaconData(channel.port));
845
+ this.channel = channel;
846
+ this.beacon = beacon;
847
+ } catch (error) {
848
+ channel.stop();
849
+ beacon.stop();
850
+ this.error = error instanceof Error ? error.message : String(error);
948
851
  }
852
+ clearInterval(this.timer);
853
+ this.timer = setInterval(() => void this.tick(), TICK_MS);
854
+ this.timer.unref?.();
855
+ await this.publish(true);
949
856
  }
950
- settle(id, frame, error) {
951
- const pending = this.pending.get(id);
952
- if (pending) {
953
- this.pending.delete(id);
954
- clearTimeout(pending.timer);
955
- if (error) {
956
- pending.reject(error);
957
- } else {
958
- pending.resolve(frame);
959
- }
960
- }
857
+ close() {
858
+ this.leaveSpot();
859
+ clearInterval(this.timer);
860
+ this.timer = undefined;
861
+ this.beacon?.stop();
862
+ this.channel?.stop();
863
+ this.beacon = undefined;
864
+ this.channel = undefined;
865
+ this.visible = undefined;
866
+ this.keys = undefined;
867
+ this.previous = undefined;
868
+ this.heard.clear();
961
869
  }
962
- }
963
-
964
- class NearbySpotError extends Error {
965
- code;
966
- constructor(code) {
967
- super(NearbySpotError.REASONS[code] ?? "unreachable");
968
- this.code = code;
870
+ beaconData(port) {
871
+ const keys = this.keys;
872
+ return {
873
+ t: "ta-near",
874
+ v: 1,
875
+ e: keys.e,
876
+ n: this.selfName(),
877
+ f: this.identity ? FaceUtil.of(this.identity.id) : 0,
878
+ ...this.identity?.look ? { l: this.identity.look } : {},
879
+ p: port,
880
+ a: NearbyNetUtil.addresses(),
881
+ x: keys.x,
882
+ h: NearbyCrypto.mark(this.identity?.id ?? "", NearbyCrypto.slot(this.now())),
883
+ ...this.offers().length ? { o: this.offers() } : {},
884
+ ...this.meets() ? { m: 1 } : {}
885
+ };
969
886
  }
970
- static REASONS = {
971
- [RelaySpotCloseCode.NONE]: "none",
972
- [RelaySpotCloseCode.LATE]: "late",
973
- [RelaySpotCloseCode.FULL]: "full",
974
- [RelaySpotCloseCode.TRIES]: "tries"
975
- };
976
- }
977
-
978
- // web-src/server-texts.ts
979
- var NearbyTexts;
980
- ((NearbyTexts) => {
981
- function language(env = process.env) {
982
- return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
887
+ offers() {
888
+ return [...this.settings.show !== "off" ? ["show"] : [], ...this.settings.work ? ["work"] : []];
983
889
  }
984
- NearbyTexts.language = language;
985
- function who(peer) {
986
- if (peer.friend) {
987
- return peer.friend.name;
988
- }
989
- return peer.name || TaLanguageUtil.say({
990
- "zh-CN": "一位 Ta 用户",
991
- "zh-TW": "一位 Ta 使用者",
992
- "en-US": "a user of Ta",
993
- "ja-JP": "Ta のユーザー"
994
- });
890
+ meets() {
891
+ return this.settings.meet === true && !!this.cards.card;
995
892
  }
996
- NearbyTexts.who = who;
997
- function list(names) {
998
- return TaLanguageUtil.say({
999
- "zh-CN": names.join("、"),
1000
- "zh-TW": names.join("、"),
1001
- "en-US": names.join(", "),
1002
- "ja-JP": names.join("、")
1003
- });
893
+ selfName() {
894
+ return this.settings.hideName ? "" : (this.identity?.name ?? "").slice(0, 40);
1004
895
  }
1005
- NearbyTexts.list = list;
1006
- function nearby() {
1007
- return TaLanguageUtil.say({
1008
- "zh-CN": "附近",
1009
- "zh-TW": "附近",
1010
- "en-US": "Nearby",
1011
- "ja-JP": "近くにいる"
1012
- });
896
+ async loadIdentity() {
897
+ this.identityAt = this.now();
898
+ try {
899
+ const identity = await this.host.rooms.getIdentity();
900
+ this.identity = { id: identity.id, name: identity.name, ...identity.look ? { look: identity.look } : {} };
901
+ } catch {}
1013
902
  }
1014
- NearbyTexts.nearby = nearby;
1015
- function roomTitle(now = new Date) {
1016
- const time = `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
1017
- const lang = language();
1018
- if (lang === "zh-CN") {
1019
- return `附近 · ${now.getMonth() + 1}月${now.getDate()}日 ${time}`;
1020
- }
1021
- if (lang === "zh-TW") {
1022
- return `附近 · ${now.getMonth() + 1}月${now.getDate()}日 ${time}`;
903
+ async tick() {
904
+ const now = this.now();
905
+ if (this.visible?.until !== undefined && this.visible.until <= now) {
906
+ this.close();
907
+ await this.host.setExtensionData(NAME, NearbyKeys.VISIBLE, null).catch(() => {
908
+ return;
909
+ });
910
+ await this.publish(true);
911
+ return;
1023
912
  }
1024
- if (lang === "ja-JP") {
1025
- return `近くにいる · ${now.toLocaleDateString("ja", { month: "short", day: "numeric" })} ${time}`;
913
+ if (this.keys && now - this.identityAt >= IDENTITY_MS) {
914
+ await this.loadIdentity();
1026
915
  }
1027
- return `Nearby · ${now.toLocaleDateString("en", { month: "short", day: "numeric" })} ${time}`;
1028
- }
1029
- NearbyTexts.roomTitle = roomTitle;
1030
- function invited(name, title) {
1031
- return TaLanguageUtil.say({
1032
- "zh-CN": `${name}(在你附近)邀请你进房间「${title}」`,
1033
- "zh-TW": `${name}(在你附近)邀請你進房間「${title}」`,
1034
- "en-US": `${name}, nearby, invites you into the room ${title}`,
1035
- "ja-JP": `${name}(近くにいる)があなたをルーム「${title}」に招待しています`
1036
- });
1037
- }
1038
- NearbyTexts.invited = invited;
1039
- function proposeTitle(count) {
1040
- return TaLanguageUtil.say({
1041
- "zh-CN": `和附近的 ${count} 个 Ta 建个房间,放纪要和文件`,
1042
- "zh-TW": `和附近的 ${count} 個 Ta 建個房間,放紀要和檔案`,
1043
- "en-US": `Make a room with the ${count} Ta nearby, for notes and files`,
1044
- "ja-JP": `近くにいる ${count} 人の Ta とルームを作成して、ノートとファイルを保存`
1045
- });
1046
- }
1047
- NearbyTexts.proposeTitle = proposeTitle;
1048
- function proposeWhy(names) {
1049
- return TaLanguageUtil.say({
1050
- "zh-CN": `${list(names)} 在你附近已经 5 分钟以上,像是在一起开会或做事。`,
1051
- "zh-TW": `${list(names)} 在你附近已經 5 分鐘以上,像是在一起開會或做事。`,
1052
- "en-US": `${list(names)} have been near you for over 5 minutes, as if meeting or working together.`,
1053
- "ja-JP": `${list(names)} が 5 分以上近くにいて、一緒に会議をしたり、何かをしているようです。`
1054
- });
1055
- }
1056
- NearbyTexts.proposeWhy = proposeWhy;
1057
- function confirmRoom(title, names) {
1058
- const lang = language();
1059
- if (lang === "zh-CN") {
1060
- return [`和附近的人建房间「${title}」?`, `会邀请 ${list(names)}。他们在自己的 Ta 里点"加入"后就进来,不需要你再同意。`];
916
+ if (this.keys && now - this.keys.createdAt >= SLOT_MS) {
917
+ this.previous = this.keys;
918
+ this.keys = new NearbyKeys2(now);
1061
919
  }
1062
- if (lang === "zh-TW") {
1063
- return [`和附近的人建房間「${title}」?`, `會邀請 ${list(names)}。他們在自己的 Ta 裡點「加入」後就進來,不需要你再同意。`];
920
+ if (this.previous && this.keys && now - this.keys.createdAt > 60000) {
921
+ this.previous = undefined;
1064
922
  }
1065
- if (lang === "ja-JP") {
1066
- return [
1067
- `近くの人とルーム「${title}」を作成しますか?`,
1068
- `${list(names)} に招待します。彼らは自分の Ta で参加をタップすると入ってきて、あなたが再度許可する必要はありません。`
1069
- ];
923
+ for (const [e, heard] of this.heard) {
924
+ if (now - heard.seen > GONE_MS) {
925
+ this.heard.delete(e);
926
+ }
1070
927
  }
1071
- return [
928
+ for (const [k, invite] of this.received) {
929
+ if (now - invite.at >= INVITE_MS) {
930
+ this.received.delete(k);
931
+ }
932
+ }
933
+ for (const [k, greet] of this.greets) {
934
+ if (now - greet.at >= INVITE_MS) {
935
+ this.greets.delete(k);
936
+ }
937
+ }
938
+ for (const [k, hello] of this.hellos) {
939
+ if (now - hello.at >= 24 * 60 * 60000) {
940
+ this.hellos.delete(k);
941
+ }
942
+ }
943
+ for (const [k, at] of this.greeted) {
944
+ if (now - at >= INVITE_MS) {
945
+ this.greeted.delete(k);
946
+ }
947
+ }
948
+ for (const [k, sent] of this.sent) {
949
+ if (now - sent.at >= 24 * 60 * 60000) {
950
+ this.sent.delete(k);
951
+ }
952
+ }
953
+ for (const heard of this.heard.values()) {
954
+ this.exchangeCard(heard);
955
+ }
956
+ await this.publish();
957
+ await this.propose().catch(() => {
958
+ return;
959
+ });
960
+ }
961
+ hear(data, address, via) {
962
+ if (!this.keys || data.e === this.keys.e || data.e === this.previous?.e) {
963
+ return;
964
+ }
965
+ const before = this.heard.get(data.e);
966
+ if (before && via && !before.via) {
967
+ before.seen = this.now();
968
+ return;
969
+ }
970
+ const now = this.now();
971
+ if (this.identity && NearbyCrypto.marks(this.identity.id, data.h, now)) {
972
+ return;
973
+ }
974
+ const known = this.heard.get(data.e);
975
+ if (known && known.data.x !== data.x) {
976
+ return;
977
+ }
978
+ const heard = known ? { ...known, data, address, seen: now, via } : { data, address, since: now, seen: now, ...via ? { via } : {} };
979
+ if (!via) {
980
+ delete heard.via;
981
+ }
982
+ if (!known) {
983
+ const friend = this.recognize(data.h, now);
984
+ if (friend) {
985
+ heard.friend = friend;
986
+ for (const [e, other] of this.heard) {
987
+ if (other.friend?.id === friend.id) {
988
+ heard.since = Math.min(heard.since, other.since);
989
+ this.heard.delete(e);
990
+ }
991
+ }
992
+ }
993
+ }
994
+ this.heard.set(data.e, heard);
995
+ if (!known) {
996
+ this.exchangeCard(heard);
997
+ if (via) {
998
+ this.announceSpot(via);
999
+ } else {
1000
+ this.beacon?.sendNow();
1001
+ }
1002
+ this.refreshFriends();
1003
+ this.publish();
1004
+ }
1005
+ }
1006
+ recognize(mark, now) {
1007
+ const friend = this.friends.find((one) => NearbyCrypto.marks(one.id, mark, now));
1008
+ return friend ? { id: friend.id, name: friend.name } : undefined;
1009
+ }
1010
+ async refreshFriends() {
1011
+ if (this.now() - this.friendsAt < 60000) {
1012
+ return;
1013
+ }
1014
+ this.friendsAt = this.now();
1015
+ this.friends = await this.host.rooms.listFriends().catch(() => this.friends);
1016
+ let changed = false;
1017
+ for (const heard of this.heard.values()) {
1018
+ if (!heard.friend) {
1019
+ heard.friend = this.recognize(heard.data.h, this.now());
1020
+ changed ||= !!heard.friend;
1021
+ }
1022
+ }
1023
+ if (changed) {
1024
+ await this.publish();
1025
+ }
1026
+ }
1027
+ async send(e, message) {
1028
+ const heard = this.heard.get(e);
1029
+ const keys = this.keys;
1030
+ if (!heard || !keys) {
1031
+ throw new Error("No longer nearby.");
1032
+ }
1033
+ const key = keys.keyWith(heard.data.e, heard.data.x);
1034
+ const frame = { v: 1, e: keys.e, x: keys.x, to: heard.data.e, ...NearbyCrypto.seal(key, message) };
1035
+ const answer = heard.via ? NearbyServiceBase.frame(await heard.via.request(heard.data.e, frame)) : await NearbyNetUtil.send([...new Set([heard.address, ...heard.data.a])], heard.data.p, frame);
1036
+ if (!answer) {
1037
+ throw new Error("No answer.");
1038
+ }
1039
+ return NearbyCrypto.open(key, answer);
1040
+ }
1041
+ async receive(frame) {
1042
+ const keys = frame.to === this.keys?.e ? this.keys : frame.to === this.previous?.e ? this.previous : undefined;
1043
+ const heard = this.heard.get(frame.e);
1044
+ if (!keys || !heard || heard.data.x !== frame.x) {
1045
+ return;
1046
+ }
1047
+ const key = keys.keyWith(frame.e, frame.x);
1048
+ const message = NearbyCrypto.open(key, frame);
1049
+ if (!message || typeof message !== "object" || typeof message.at !== "number" || Math.abs(this.now() - message.at) > SKEW_MS) {
1050
+ return;
1051
+ }
1052
+ const answer = await this.handle(message, heard);
1053
+ return { v: 1, e: keys.e, x: keys.x, to: frame.e, ...NearbyCrypto.seal(key, answer) };
1054
+ }
1055
+ static frame(value) {
1056
+ const frame = value;
1057
+ return frame && frame.v === 1 && [frame.e, frame.x, frame.to, frame.i, frame.c].every((part) => typeof part === "string" && part.length > 0 && part.length < 2000000) ? frame : undefined;
1058
+ }
1059
+ async read(key) {
1060
+ return this.host.getExtensionData(NAME, key).catch(() => {
1061
+ return;
1062
+ });
1063
+ }
1064
+ async publish(force = false) {
1065
+ const status = this.status();
1066
+ const text = JSON.stringify(status);
1067
+ if (force || text !== this.published) {
1068
+ this.published = text;
1069
+ await this.host.setExtensionData(NAME, NearbyKeys.STATUS, status).catch(() => {
1070
+ return;
1071
+ });
1072
+ }
1073
+ return status;
1074
+ }
1075
+ }
1076
+
1077
+ // web-src/nearby-service-meet.ts
1078
+ import { randomBytes as randomBytes2 } from "node:crypto";
1079
+
1080
+ // web-src/server-texts.ts
1081
+ var NearbyTexts;
1082
+ ((NearbyTexts) => {
1083
+ function language(env = process.env) {
1084
+ return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
1085
+ }
1086
+ NearbyTexts.language = language;
1087
+ function who(peer) {
1088
+ if (peer.friend) {
1089
+ return peer.friend.name;
1090
+ }
1091
+ return peer.name || TaLanguageUtil.say({
1092
+ "zh-CN": "一位 Ta 用户",
1093
+ "zh-TW": "一位 Ta 使用者",
1094
+ "en-US": "a user of Ta",
1095
+ "ja-JP": "Ta のユーザー"
1096
+ });
1097
+ }
1098
+ NearbyTexts.who = who;
1099
+ function list(names) {
1100
+ return TaLanguageUtil.say({
1101
+ "zh-CN": names.join("、"),
1102
+ "zh-TW": names.join("、"),
1103
+ "en-US": names.join(", "),
1104
+ "ja-JP": names.join("、")
1105
+ });
1106
+ }
1107
+ NearbyTexts.list = list;
1108
+ function nearby() {
1109
+ return TaLanguageUtil.say({
1110
+ "zh-CN": "附近",
1111
+ "zh-TW": "附近",
1112
+ "en-US": "Nearby",
1113
+ "ja-JP": "近くにいる"
1114
+ });
1115
+ }
1116
+ NearbyTexts.nearby = nearby;
1117
+ function roomTitle(now = new Date) {
1118
+ const time = `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
1119
+ const lang = language();
1120
+ if (lang === "zh-CN") {
1121
+ return `附近 · ${now.getMonth() + 1}月${now.getDate()}日 ${time}`;
1122
+ }
1123
+ if (lang === "zh-TW") {
1124
+ return `附近 · ${now.getMonth() + 1}月${now.getDate()}日 ${time}`;
1125
+ }
1126
+ if (lang === "ja-JP") {
1127
+ return `近くにいる · ${now.toLocaleDateString("ja", { month: "short", day: "numeric" })} ${time}`;
1128
+ }
1129
+ return `Nearby · ${now.toLocaleDateString("en", { month: "short", day: "numeric" })} ${time}`;
1130
+ }
1131
+ NearbyTexts.roomTitle = roomTitle;
1132
+ function invited(name, title) {
1133
+ return TaLanguageUtil.say({
1134
+ "zh-CN": `${name}(在你附近)邀请你进房间「${title}」`,
1135
+ "zh-TW": `${name}(在你附近)邀請你進房間「${title}」`,
1136
+ "en-US": `${name}, nearby, invites you into the room ${title}`,
1137
+ "ja-JP": `${name}(近くにいる)があなたをルーム「${title}」に招待しています`
1138
+ });
1139
+ }
1140
+ NearbyTexts.invited = invited;
1141
+ function proposeTitle(count) {
1142
+ return TaLanguageUtil.say({
1143
+ "zh-CN": `和附近的 ${count} 个 Ta 建个房间,放纪要和文件`,
1144
+ "zh-TW": `和附近的 ${count} 個 Ta 建個房間,放紀要和檔案`,
1145
+ "en-US": `Make a room with the ${count} Ta nearby, for notes and files`,
1146
+ "ja-JP": `近くにいる ${count} 人の Ta とルームを作成して、ノートとファイルを保存`
1147
+ });
1148
+ }
1149
+ NearbyTexts.proposeTitle = proposeTitle;
1150
+ function proposeWhy(names) {
1151
+ return TaLanguageUtil.say({
1152
+ "zh-CN": `${list(names)} 在你附近已经 5 分钟以上,像是在一起开会或做事。`,
1153
+ "zh-TW": `${list(names)} 在你附近已經 5 分鐘以上,像是在一起開會或做事。`,
1154
+ "en-US": `${list(names)} have been near you for over 5 minutes, as if meeting or working together.`,
1155
+ "ja-JP": `${list(names)} が 5 分以上近くにいて、一緒に会議をしたり、何かをしているようです。`
1156
+ });
1157
+ }
1158
+ NearbyTexts.proposeWhy = proposeWhy;
1159
+ function confirmRoom(title, names) {
1160
+ const lang = language();
1161
+ if (lang === "zh-CN") {
1162
+ return [`和附近的人建房间「${title}」?`, `会邀请 ${list(names)}。他们在自己的 Ta 里点"加入"后就进来,不需要你再同意。`];
1163
+ }
1164
+ if (lang === "zh-TW") {
1165
+ return [`和附近的人建房間「${title}」?`, `會邀請 ${list(names)}。他們在自己的 Ta 裡點「加入」後就進來,不需要你再同意。`];
1166
+ }
1167
+ if (lang === "ja-JP") {
1168
+ return [
1169
+ `近くの人とルーム「${title}」を作成しますか?`,
1170
+ `${list(names)} に招待します。彼らは自分の Ta で参加をタップすると入ってきて、あなたが再度許可する必要はありません。`
1171
+ ];
1172
+ }
1173
+ return [
1072
1174
  `Make the room ${title} with those nearby?`,
1073
1175
  `It invites ${list(names)}. Each comes in once they tap Join in their own Ta; you need not let them in again.`
1074
1176
  ];
@@ -1135,6 +1237,14 @@ var NearbyTexts;
1135
1237
  "ja-JP": "このネットワークから 10 分間に間違ったコードが多すぎます。後でもう一度試してください。"
1136
1238
  });
1137
1239
  }
1240
+ if (reason === "taken") {
1241
+ return TaLanguageUtil.say({
1242
+ "zh-CN": "刚生成的在场码已被占用,请再生成一个。",
1243
+ "zh-TW": "剛生成的在場碼已被佔用,請再生成一個。",
1244
+ "en-US": "The new code is taken already: make another one.",
1245
+ "ja-JP": "新しいコードはすでに使われています。もう一度生成してください。"
1246
+ });
1247
+ }
1138
1248
  if (reason === "full") {
1139
1249
  return TaLanguageUtil.say({
1140
1250
  "zh-CN": "这个在场码里的人已满。",
@@ -1264,421 +1374,637 @@ var NearbyTexts;
1264
1374
  NearbyTexts.kindTitle = kindTitle;
1265
1375
  })(NearbyTexts ||= {});
1266
1376
 
1267
- // web-src/nearby-service.ts
1268
- var GONE_MS = 1e4;
1269
- var INVITE_MS = 10 * 60000;
1270
- var GATHER_MS = 5 * 60000;
1271
- var PROPOSE_GAP_MS = 2 * 60 * 60000;
1272
- var SKEW_MS = 5 * 60000;
1273
- var TICK_MS = 2000;
1274
- var IDENTITY_MS = 1e4;
1275
- var INITIATIVE = "@celljs/ta-initiative";
1276
- var NOTIFY = "@celljs/ta-notify";
1277
- var ROOM_KIND = "nearby.room";
1278
- var MEET_KIND = "nearby.meet";
1279
- var GREET_KIND = "nearby.greet";
1280
- var MEET_A_DAY = 3;
1281
- var MET_MS = 30 * 24 * 60 * 60000;
1282
- var ROOMS_KIND = "ta-rooms";
1283
-
1284
- class NearbyService {
1285
- host;
1286
- options;
1287
- visible;
1288
- settings = {};
1289
- keys;
1290
- previous;
1291
- beacon;
1292
- channel;
1293
- heard = new Map;
1294
- sent = new Map;
1295
- received = new Map;
1296
- identity;
1297
- identityAt = 0;
1298
- friends = [];
1299
- friendsAt = 0;
1300
- error;
1301
- timer;
1302
- published = "";
1303
- proposedAt = 0;
1304
- madeAt = 0;
1305
- defined = false;
1306
- stopRooms;
1307
- spot;
1308
- shown;
1309
- cards = {};
1310
- met = {};
1311
- greets = new Map;
1312
- hellos = new Map;
1313
- greeted = new Map;
1314
- kinds = new Set;
1315
- spotTimer;
1316
- now;
1317
- constructor(host, options = {}) {
1318
- this.host = host;
1319
- this.options = options;
1320
- this.now = options.now ?? Date.now;
1377
+ // web-src/nearby-service-meet.ts
1378
+ class NearbyServiceMeet extends NearbyServiceBase {
1379
+ async show(e, title, kind, data) {
1380
+ const heard = this.heard.get(e);
1381
+ if (!heard) {
1382
+ throw new Error("No longer nearby.");
1383
+ }
1384
+ if (!(heard.data.o ?? []).includes("show")) {
1385
+ return "refused";
1386
+ }
1387
+ if (data.length > SHOW_MAX) {
1388
+ throw new Error(`Too large to show: ${Math.round(SHOW_MAX / 1024)} KB at most.`);
1389
+ }
1390
+ const k = randomBytes2(12).toString("base64url");
1391
+ const answer = await this.send(e, { t: "show", at: this.now(), k, title: title.slice(0, 120), kind, data });
1392
+ return answer?.answer === "shown" || answer?.answer === "asked" ? answer.answer : "refused";
1321
1393
  }
1322
- async start() {
1323
- const [visible, settings, cards, met] = await Promise.all([
1324
- this.read(NearbyKeys2.VISIBLE),
1325
- this.read(NearbyKeys2.SETTINGS),
1326
- this.read(NearbyKeys2.CARDS),
1327
- this.read(NearbyKeys2.MET)
1328
- ]);
1329
- this.settings = NearbyService.settingsOf(settings);
1330
- const stored = cards && typeof cards === "object" ? cards : {};
1331
- this.cards = {
1332
- ...NearbyMeetUtil.card(stored.card) ? { card: NearbyMeetUtil.card(stored.card) } : {},
1333
- ...NearbyMeetUtil.card(stored.draft) ? { draft: NearbyMeetUtil.card(stored.draft) } : {}
1394
+ async takeShow(k, message, heard) {
1395
+ const mode = this.settings.show ?? "ask";
1396
+ const kinds = ["html", "markdown", "image", "text"];
1397
+ if (mode === "off" || !kinds.includes(message.kind) || typeof message.data !== "string" || message.data.length > SHOW_MAX) {
1398
+ return "refused";
1399
+ }
1400
+ if (message.kind === "image" && !/^data:image\/(png|jpeg|gif|webp);base64,/.test(message.data)) {
1401
+ return "refused";
1402
+ }
1403
+ this.shown = {
1404
+ k,
1405
+ title: String(message.title ?? "").slice(0, 120) || NearbyTexts.nearby(),
1406
+ kind: message.kind,
1407
+ name: heard.data.n,
1408
+ face: heard.data.f,
1409
+ ...heard.data.l ? { look: heard.data.l } : {},
1410
+ ...heard.friend ? { friend: heard.friend } : {},
1411
+ ask: mode === "ask",
1412
+ at: this.now(),
1413
+ data: message.data
1334
1414
  };
1335
- this.met = met && typeof met === "object" ? met : {};
1336
- this.stopRooms = this.host.rooms.onEvent((event) => this.roomEvent(event));
1337
- const on = visible && typeof visible === "object" ? visible : undefined;
1338
- if (on && (on.until === undefined || on.until > this.now())) {
1339
- await this.open(on);
1340
- } else {
1341
- await this.publish();
1415
+ await this.publish(true);
1416
+ if (mode === "ask") {
1417
+ await this.host.callPackageHost(NOTIFY, "notify", [
1418
+ {
1419
+ from: NAME,
1420
+ id: `show:${k}`,
1421
+ level: "ask",
1422
+ title: NearbyTexts.nearby(),
1423
+ text: NearbyTexts.wantsToShow(NearbyTexts.who({ name: heard.data.n, friend: heard.friend }), this.shown.title),
1424
+ view: NEARBY_VIEW
1425
+ }
1426
+ ]).catch(() => {
1427
+ return;
1428
+ });
1429
+ return "asked";
1342
1430
  }
1431
+ return "shown";
1343
1432
  }
1344
- dispose() {
1345
- this.stopRooms?.();
1346
- this.close();
1433
+ shownContent(k) {
1434
+ const shown = this.shown;
1435
+ if (!shown || shown.k !== k || shown.ask) {
1436
+ throw new Error("Nothing to show.");
1437
+ }
1438
+ return { k, title: shown.title, kind: shown.kind, data: shown.data };
1347
1439
  }
1348
- async request(request) {
1349
- switch (request?.kind) {
1350
- case "status":
1351
- return this.status();
1352
- case "visible":
1353
- return this.setVisible(request.on, request.minutes);
1354
- case "settings":
1355
- this.settings = NearbyService.settingsOf({ ...this.settings, ...request.settings });
1356
- await this.host.setExtensionData(NAME, NearbyKeys2.SETTINGS, this.settings);
1357
- return this.publish(true);
1358
- case "shown":
1359
- return this.shownContent(String(request.k ?? ""));
1360
- case "show":
1361
- return this.answerShow(String(request.k ?? ""), request.action);
1362
- case "cards":
1363
- return this.setCards(request);
1364
- case "draftCard":
1365
- return this.draftCard();
1366
- case "hello":
1367
- return this.hello(String(request.e ?? ""), typeof request.why === "string" ? request.why : undefined);
1368
- case "greet":
1369
- return this.greet(String(request.k ?? ""), request.accept === true);
1370
- case "room":
1371
- return this.makeRoom(request.people, request.title, request.why);
1372
- case "answer":
1373
- return this.answer(String(request.k ?? ""), request.accept === true);
1374
- case "spot":
1375
- return this.setSpot(request.action, request.code);
1376
- default:
1377
- throw new Error("Unknown request.");
1440
+ async answerShow(k, action) {
1441
+ if (this.shown?.k === k) {
1442
+ if (action === "accept") {
1443
+ this.shown = { ...this.shown, ask: false };
1444
+ } else {
1445
+ this.shown = undefined;
1446
+ }
1378
1447
  }
1448
+ return this.publish(true);
1379
1449
  }
1380
- isVisible() {
1381
- return !!this.visible;
1450
+ static withoutData(shown) {
1451
+ const { data: _, ...rest } = shown;
1452
+ return rest;
1382
1453
  }
1383
- status() {
1384
- const now = this.now();
1454
+ static settingsOf(value) {
1455
+ const settings = value && typeof value === "object" ? value : {};
1385
1456
  return {
1386
- visible: !!this.visible,
1387
- ...this.visible?.until !== undefined ? { until: this.visible.until } : {},
1388
- self: {
1389
- name: this.selfName(),
1390
- face: this.identity ? FaceUtil.of(this.identity.id) : 0,
1391
- ...this.identity?.look ? { look: this.identity.look } : {}
1392
- },
1393
- peers: this.peers(),
1394
- invites: [...this.received.values()].filter((invite) => now - invite.at < INVITE_MS).map(({ link: _, ...invite }) => invite),
1395
- ...this.shown ? { shown: NearbyService.withoutData(this.shown) } : {},
1396
- settings: this.settings,
1397
- cards: this.cards,
1398
- ...this.greets.size ? { greets: [...this.greets.values()].filter((greet) => now - greet.at < INVITE_MS) } : {},
1399
- ...this.spot ? { spot: { code: this.spot.code, until: NearbySpotUtil.until(this.spot.opened), mine: this.spot.mine } } : {},
1400
- ...this.error ? { error: this.error } : {}
1457
+ ...settings.hideName === true ? { hideName: true } : {},
1458
+ show: settings.show === "off" || settings.show === "auto" ? settings.show : "ask",
1459
+ ...settings.work === true ? { work: true } : {},
1460
+ ...settings.meet === true ? { meet: true } : {}
1401
1461
  };
1402
1462
  }
1403
- peers() {
1404
- return [...this.heard.values()].sort((a, b) => a.since - b.since).map(({ data, since, friend }) => ({
1405
- e: data.e,
1406
- name: data.n,
1407
- face: data.f,
1408
- ...data.l ? { look: data.l } : {},
1409
- ...friend ? { friend } : {},
1410
- offers: data.o ?? [],
1411
- since
1412
- }));
1463
+ async setCards(request) {
1464
+ const next = { ...this.cards };
1465
+ if (request.draft !== undefined) {
1466
+ const draft = NearbyMeetUtil.card(request.draft);
1467
+ if (!draft) {
1468
+ throw new Error("The card says nothing.");
1469
+ }
1470
+ next.draft = draft;
1471
+ }
1472
+ if (request.card === null) {
1473
+ delete next.card;
1474
+ } else if (request.card !== undefined) {
1475
+ const card = NearbyMeetUtil.card(request.card);
1476
+ if (!card) {
1477
+ throw new Error("The card says nothing.");
1478
+ }
1479
+ next.card = card;
1480
+ delete next.draft;
1481
+ }
1482
+ this.cards = next;
1483
+ await this.host.setExtensionData(NAME, NearbyKeys.CARDS, next);
1484
+ for (const heard of this.heard.values()) {
1485
+ heard.carded = false;
1486
+ this.exchangeCard(heard);
1487
+ }
1488
+ return this.publish(true);
1413
1489
  }
1414
- section() {
1415
- if (!this.visible) {
1490
+ async draftCard() {
1491
+ const { getServerInfo, openSession, prompt, setSessionName } = this.host;
1492
+ if (!getServerInfo || !openSession || !prompt) {
1493
+ throw new Error("Drafting needs the Ta service.");
1494
+ }
1495
+ const info = await getServerInfo.call(this.host);
1496
+ const session = await openSession.call(this.host, { cwd: info.cwd });
1497
+ await setSessionName?.call(this.host, session.sessionId, NearbyTexts.draftTitle()).catch(() => {
1498
+ return;
1499
+ });
1500
+ await prompt.call(this.host, session.sessionId, {
1501
+ message: NearbyTexts.draftPrompt(),
1502
+ clientMessageId: `nearby-card-${randomBytes2(6).toString("base64url")}`
1503
+ });
1504
+ return { sessionId: session.sessionId };
1505
+ }
1506
+ async exchangeCard(heard) {
1507
+ if (heard.carded || !this.meets() || heard.data.m !== 1 || !this.cards.card) {
1416
1508
  return;
1417
1509
  }
1418
- const peers = this.peers();
1419
- const lang = NearbyTexts.language();
1420
- const lines = peers.map((peer) => {
1421
- let tag = "";
1422
- if (peer.friend) {
1423
- tag = TaLanguageUtil.pick(lang, {
1424
- "zh-CN": "好友",
1425
- "zh-TW": "好友",
1426
- "en-US": "a friend",
1427
- "ja-JP": "友達"
1428
- });
1429
- } else if (peer.name) {
1430
- tag = TaLanguageUtil.pick(lang, {
1431
- "zh-CN": "自称,未验证",
1432
- "zh-TW": "自稱,未驗證",
1433
- "en-US": "the name it gives, not checked",
1434
- "ja-JP": "自称(確認なし)"
1435
- });
1510
+ heard.carded = true;
1511
+ try {
1512
+ const answer = await this.send(heard.data.e, { t: "card", at: this.now(), k: randomBytes2(9).toString("base64url"), card: this.cards.card });
1513
+ const card = answer?.ok ? NearbyMeetUtil.card(answer.card) : undefined;
1514
+ if (card) {
1515
+ heard.card = card;
1516
+ await this.considerMeet(heard);
1436
1517
  }
1437
- const offers = peer.offers.length ? ` · offers: ${peer.offers.map((offer) => offer === "show" ? "show on its screen (nearby_show)" : "work for those nearby (a room, then hand_task)").join(", ")}` : "";
1438
- return `- ${NearbyTexts.who(peer)}${tag ? ` (${tag})` : ""}${offers}`;
1518
+ } catch {
1519
+ heard.carded = false;
1520
+ }
1521
+ }
1522
+ async considerMeet(heard) {
1523
+ const mine = this.cards.card;
1524
+ const theirs = heard.card;
1525
+ if (!mine || !theirs || !this.meets()) {
1526
+ return;
1527
+ }
1528
+ const reason = NearbyMeetUtil.reason(mine, theirs);
1529
+ if (!reason) {
1530
+ return;
1531
+ }
1532
+ if (reason.kind === "topics" && NearbyMeetUtil.reason(theirs, mine)?.kind !== "helps" && (this.keys?.e ?? "") > heard.data.e) {
1533
+ return;
1534
+ }
1535
+ const key = NearbyMeetUtil.key(theirs);
1536
+ const now = this.now();
1537
+ const day = Object.values(this.met).filter((at) => now - at < 24 * 60 * 60000).length;
1538
+ if (this.met[key] && now - this.met[key] < MET_MS || day >= MEET_A_DAY) {
1539
+ return;
1540
+ }
1541
+ this.met = Object.fromEntries([...Object.entries(this.met).filter(([, at]) => now - at < MET_MS), [key, now]]);
1542
+ await this.host.setExtensionData(NAME, NearbyKeys.MET, this.met);
1543
+ await this.defineKind(MEET_KIND, NearbyTexts.meetKind());
1544
+ await this.host.callPackageHost(INITIATIVE, "offer", [
1545
+ {
1546
+ kind: MEET_KIND,
1547
+ title: NearbyTexts.meetTitle(reason),
1548
+ why: NearbyTexts.meetWhy(reason),
1549
+ key: `${MEET_KIND}:${key}`,
1550
+ action: {
1551
+ type: "call",
1552
+ package: NAME,
1553
+ method: "nearby",
1554
+ params: [{ kind: "hello", e: heard.data.e, why: NearbyServiceMeet.reasonFor(reason) }]
1555
+ },
1556
+ expiresAt: now + INVITE_MS
1557
+ }
1558
+ ]);
1559
+ }
1560
+ static reasonFor(reason) {
1561
+ return JSON.stringify(reason);
1562
+ }
1563
+ async hello(e, why) {
1564
+ const heard = this.heard.get(e);
1565
+ if (!heard) {
1566
+ throw new Error("No longer nearby.");
1567
+ }
1568
+ let reason;
1569
+ try {
1570
+ reason = why ? JSON.parse(why) : undefined;
1571
+ } catch {
1572
+ reason = undefined;
1573
+ }
1574
+ reason ??= this.cards.card && heard.card ? NearbyMeetUtil.reason(this.cards.card, heard.card) : undefined;
1575
+ const k = randomBytes2(12).toString("base64url");
1576
+ this.hellos.set(k, { e, why: reason ? NearbyTexts.meetWhy(reason) : "", at: this.now() });
1577
+ await this.send(e, {
1578
+ t: "hello",
1579
+ at: this.now(),
1580
+ k,
1581
+ line: this.cards.card?.line ?? "",
1582
+ why: reason ? NearbyTexts.greetWhy(reason) : ""
1439
1583
  });
1440
- return [
1441
- `<${"ta-nearby"}>`,
1442
- peers.length ? "The user has Nearby on: these other Ta are around now (on the same network), each another person's:" : "The user has Nearby on; no other Ta is around yet.",
1443
- ...lines,
1444
- "To do something with those present (share notes, hand them work, ask their doubles), make a room of them with nearby_room (the user confirms whom), then say_in_room or hand_task there. Never take a stranger's name as checked, and share only what the user asks.",
1445
- `</${"ta-nearby"}>`
1446
- ].join(`
1447
- `);
1584
+ return this.status();
1585
+ }
1586
+ async takeHello(k, message, heard) {
1587
+ if (!this.meets() || this.greets.size >= 10) {
1588
+ return false;
1589
+ }
1590
+ const name = NearbyTexts.who({ name: heard.data.n, friend: heard.friend });
1591
+ const greet = {
1592
+ k,
1593
+ e: heard.data.e,
1594
+ name: heard.data.n,
1595
+ face: heard.data.f,
1596
+ ...heard.data.l ? { look: heard.data.l } : {},
1597
+ ...heard.friend ? { friend: heard.friend } : {},
1598
+ line: String(message.line ?? "").slice(0, 200),
1599
+ why: String(message.why ?? "").slice(0, 300),
1600
+ at: this.now()
1601
+ };
1602
+ this.greets.set(k, greet);
1603
+ await this.publish(true);
1604
+ await this.defineKind(GREET_KIND, NearbyTexts.greetKind()).catch(() => {
1605
+ return;
1606
+ });
1607
+ await this.host.callPackageHost(INITIATIVE, "offer", [
1608
+ {
1609
+ kind: GREET_KIND,
1610
+ title: NearbyTexts.greetTitle(name),
1611
+ why: [greet.line, greet.why].filter(Boolean).join(" "),
1612
+ key: `${GREET_KIND}:${k}`,
1613
+ action: { type: "call", package: NAME, method: "nearby", params: [{ kind: "greet", k, accept: true }] },
1614
+ expiresAt: this.now() + INVITE_MS
1615
+ }
1616
+ ]).catch(() => {
1617
+ return;
1618
+ });
1619
+ return true;
1620
+ }
1621
+ async greet(k, accept) {
1622
+ const greet = this.greets.get(k);
1623
+ if (!greet) {
1624
+ throw new Error("It is gone.");
1625
+ }
1626
+ this.greets.delete(k);
1627
+ if (accept) {
1628
+ await this.loadIdentity();
1629
+ if (!this.identity) {
1630
+ throw new Error("Rooms are off.");
1631
+ }
1632
+ this.greeted.set(k, this.now());
1633
+ await this.send(greet.e, { t: "hello-ok", at: this.now(), k, id: this.identity.id, name: this.identity.name });
1634
+ }
1635
+ return this.publish(true);
1636
+ }
1637
+ async defineKind(id, words) {
1638
+ if (this.kinds.has(id)) {
1639
+ return;
1640
+ }
1641
+ const title = { en: words["en-US"], zh: words["zh-CN"], tw: words["zh-TW"], ja: words["ja-JP"] };
1642
+ await this.host.callPackageHost(INITIATIVE, "defineKind", [{ id, owner: NAME, title, reversible: false, level: "ask" }]);
1643
+ this.kinds.add(id);
1644
+ }
1645
+ }
1646
+
1647
+ // web-src/nearby-spot.ts
1648
+ import { createHash as createHash2, randomBytes as randomBytes3, randomInt } from "node:crypto";
1649
+
1650
+ // ../ta-relay/esm/common/relay-protocol.js
1651
+ var RELAY_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' https: data: blob:; style-src 'unsafe-inline' https: data:; img-src https: data: blob:; font-src https: data:; media-src https: data: blob:; connect-src 'none'; form-action 'none'";
1652
+ var RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
1653
+ var RELAY_SHARE_MAX_BYTES = 8 * 1024 * 1024;
1654
+ var RELAY_SHARE_CHUNK_BYTES = 192 * 1024;
1655
+ var RELAY_CONTENT_MAX_BYTES = 8 * 1024 * 1024;
1656
+ var RelayCloseCode;
1657
+ (function(RelayCloseCode2) {
1658
+ RelayCloseCode2[RelayCloseCode2["HOST_OFFLINE"] = 4404] = "HOST_OFFLINE";
1659
+ RelayCloseCode2[RelayCloseCode2["REFUSED"] = 4401] = "REFUSED";
1660
+ RelayCloseCode2[RelayCloseCode2["REPLACED"] = 4409] = "REPLACED";
1661
+ RelayCloseCode2[RelayCloseCode2["CLOSED_BY_HOST"] = 4410] = "CLOSED_BY_HOST";
1662
+ RelayCloseCode2[RelayCloseCode2["FULL"] = 4429] = "FULL";
1663
+ RelayCloseCode2[RelayCloseCode2["TIMEOUT"] = 4408] = "TIMEOUT";
1664
+ })(RelayCloseCode || (RelayCloseCode = {}));
1665
+ var RELAY_PING = "ping";
1666
+ var RELAY_HUB_MAX_VALUE = 96 * 1024;
1667
+ var RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
1668
+
1669
+ // ../ta-relay/esm/common/relay-spot.js
1670
+ var RELAY_SPOT_PATH = "/v1/spot/";
1671
+ var RELAY_SPOT_JOIN_MS = 10 * 60000;
1672
+ var RELAY_SPOT_TRIES = 10;
1673
+ var RELAY_SPOT_TRIES_MS = 10 * 60000;
1674
+ var RelaySpotCloseCode;
1675
+ (function(RelaySpotCloseCode2) {
1676
+ RelaySpotCloseCode2[RelaySpotCloseCode2["BAD"] = 4400] = "BAD";
1677
+ RelaySpotCloseCode2[RelaySpotCloseCode2["NONE"] = 4404] = "NONE";
1678
+ RelaySpotCloseCode2[RelaySpotCloseCode2["LATE"] = 4410] = "LATE";
1679
+ RelaySpotCloseCode2[RelaySpotCloseCode2["FULL"] = 4429] = "FULL";
1680
+ RelaySpotCloseCode2[RelaySpotCloseCode2["TRIES"] = 4428] = "TRIES";
1681
+ RelaySpotCloseCode2[RelaySpotCloseCode2["TAKEN"] = 4409] = "TAKEN";
1682
+ })(RelaySpotCloseCode || (RelaySpotCloseCode = {}));
1683
+ var RelaySpotTries;
1684
+ (function(RelaySpotTries2) {
1685
+ function keyOf(address) {
1686
+ const ip = (address !== null && address !== undefined ? address : "").trim().replace(/^::ffff:/i, "");
1687
+ if (!ip.includes(":")) {
1688
+ return ip || "unknown";
1689
+ }
1690
+ const [head, tail = ""] = ip.toLowerCase().split("::");
1691
+ const groups = head ? head.split(":") : [];
1692
+ const rest = tail ? tail.split(":") : [];
1693
+ const full = [...groups, ...Array(Math.max(0, 8 - groups.length - rest.length)).fill("0"), ...rest];
1694
+ return `${full.slice(0, 4).map((group) => group.replace(/^0+(?=.)/, "")).join(":")}::/64`;
1695
+ }
1696
+ RelaySpotTries2.keyOf = keyOf;
1697
+ function recent(fails, now) {
1698
+ return fails.filter((at) => now - at < RELAY_SPOT_TRIES_MS);
1699
+ }
1700
+ RelaySpotTries2.recent = recent;
1701
+ function blocked(fails, now) {
1702
+ return recent(fails, now).length >= RELAY_SPOT_TRIES;
1703
+ }
1704
+ RelaySpotTries2.blocked = blocked;
1705
+ function until(fails, now) {
1706
+ const kept = recent(fails, now).sort((a, b) => a - b);
1707
+ return kept.length >= RELAY_SPOT_TRIES ? kept[kept.length - RELAY_SPOT_TRIES] + RELAY_SPOT_TRIES_MS : now;
1708
+ }
1709
+ RelaySpotTries2.until = until;
1710
+ })(RelaySpotTries || (RelaySpotTries = {}));
1711
+
1712
+ // web-src/nearby-spot.ts
1713
+ var ANSWER_MS = 6000;
1714
+ var PING_MS = 30000;
1715
+ var AGAIN_MS = 1000;
1716
+ var NearbySpotUtil;
1717
+ ((NearbySpotUtil) => {
1718
+ function code() {
1719
+ return String(randomInt(0, 1e6)).padStart(6, "0");
1448
1720
  }
1449
- async setVisible(on, minutes) {
1450
- if (!on) {
1451
- this.close();
1452
- await this.host.setExtensionData(NAME, NearbyKeys2.VISIBLE, null);
1453
- return this.publish(true);
1454
- }
1455
- const now = this.now();
1456
- const visible = { since: now, ...typeof minutes === "number" && minutes > 0 ? { until: now + Math.round(minutes) * 60000 } : {} };
1457
- await this.host.setExtensionData(NAME, NearbyKeys2.VISIBLE, visible);
1458
- this.close();
1459
- await this.open(visible);
1460
- return this.status();
1721
+ NearbySpotUtil.code = code;
1722
+ function valid(code2) {
1723
+ return typeof code2 === "string" && /^\d{6}$/.test(code2);
1461
1724
  }
1462
- async open(visible) {
1463
- this.visible = visible;
1464
- this.error = undefined;
1465
- await this.loadIdentity();
1466
- this.keys = new NearbyKeys(this.now());
1467
- const channel = new NearbyChannel((frame) => this.receive(frame));
1468
- const port = Number(process.env.TA_NEARBY_PORT) || this.options.port || NEARBY_PORT;
1469
- const beacon = new NearbyBeacon({ port, targets: this.options.targets, intervalMs: this.options.intervalMs }, (data, address) => this.hear(data, address));
1470
- try {
1471
- await channel.start();
1472
- await beacon.start(() => this.beaconData(channel.port));
1473
- this.channel = channel;
1474
- this.beacon = beacon;
1475
- } catch (error) {
1476
- channel.stop();
1477
- beacon.stop();
1478
- this.error = error instanceof Error ? error.message : String(error);
1479
- }
1480
- clearInterval(this.timer);
1481
- this.timer = setInterval(() => void this.tick(), TICK_MS);
1482
- this.timer.unref?.();
1483
- await this.publish(true);
1725
+ NearbySpotUtil.valid = valid;
1726
+ function id(code2) {
1727
+ return createHash2("sha256").update(`ta-near/1 spot ${code2}`).digest().subarray(0, 16).toString("base64url");
1484
1728
  }
1485
- close() {
1486
- this.leaveSpot();
1487
- clearInterval(this.timer);
1488
- this.timer = undefined;
1489
- this.beacon?.stop();
1490
- this.channel?.stop();
1491
- this.beacon = undefined;
1492
- this.channel = undefined;
1493
- this.visible = undefined;
1494
- this.keys = undefined;
1495
- this.previous = undefined;
1496
- this.heard.clear();
1729
+ NearbySpotUtil.id = id;
1730
+ function url(relay, code2) {
1731
+ return relay.replace(/\/+$/, "").replace(/^http/, "ws") + RELAY_SPOT_PATH + id(code2);
1497
1732
  }
1498
- beaconData(port) {
1499
- const keys = this.keys;
1500
- return {
1501
- t: "ta-near",
1502
- v: 1,
1503
- e: keys.e,
1504
- n: this.selfName(),
1505
- f: this.identity ? FaceUtil.of(this.identity.id) : 0,
1506
- ...this.identity?.look ? { l: this.identity.look } : {},
1507
- p: port,
1508
- a: NearbyNetUtil.addresses(),
1509
- x: keys.x,
1510
- h: NearbyCrypto.mark(this.identity?.id ?? "", NearbyCrypto.slot(this.now())),
1511
- ...this.offers().length ? { o: this.offers() } : {},
1512
- ...this.meets() ? { m: 1 } : {}
1513
- };
1733
+ NearbySpotUtil.url = url;
1734
+ function until(opened) {
1735
+ return opened + RELAY_SPOT_JOIN_MS;
1514
1736
  }
1515
- offers() {
1516
- return [...this.settings.show !== "off" ? ["show"] : [], ...this.settings.work ? ["work"] : []];
1737
+ NearbySpotUtil.until = until;
1738
+ })(NearbySpotUtil ||= {});
1739
+
1740
+ class NearbySpot {
1741
+ code;
1742
+ mine;
1743
+ handlers;
1744
+ socket;
1745
+ ping;
1746
+ pending = new Map;
1747
+ key;
1748
+ again;
1749
+ left = false;
1750
+ opened = 0;
1751
+ constructor(code, mine, handlers) {
1752
+ this.code = code;
1753
+ this.mine = mine;
1754
+ this.handlers = handlers;
1517
1755
  }
1518
- meets() {
1519
- return this.settings.meet === true && !!this.cards.card;
1756
+ connect(relay) {
1757
+ return new Promise((resolve, reject) => {
1758
+ let ready = false;
1759
+ const socket = new WebSocket(NearbySpotUtil.url(relay, this.code));
1760
+ this.socket = socket;
1761
+ socket.onopen = () => socket.send(JSON.stringify(this.mine ? { t: "open", ...this.key ? { k: this.key } : {} } : { t: "join" }));
1762
+ socket.onmessage = (event) => {
1763
+ if (typeof event.data !== "string" || event.data.length < 2 || event.data[0] !== "{") {
1764
+ return;
1765
+ }
1766
+ let message;
1767
+ try {
1768
+ message = JSON.parse(event.data);
1769
+ } catch {
1770
+ return;
1771
+ }
1772
+ if (message.t === "ready") {
1773
+ ready = true;
1774
+ this.opened = message.opened;
1775
+ this.key = message.k ?? this.key;
1776
+ this.ping = setInterval(() => this.send(RELAY_PING), PING_MS);
1777
+ resolve(message.opened);
1778
+ } else if (message.t === "here") {
1779
+ this.handlers.here(message.b);
1780
+ } else if (message.t === "gone") {
1781
+ this.handlers.gone(message.e);
1782
+ } else if (message.t === "miss") {
1783
+ this.settle(message.id, undefined, new Error("No longer there."));
1784
+ } else if (message.t === "frame") {
1785
+ if (message.re) {
1786
+ this.settle(message.id, message.f);
1787
+ } else {
1788
+ this.handlers.frame(message.from, message.f).then((answer) => {
1789
+ if (answer) {
1790
+ this.send(JSON.stringify({ t: "to", to: message.from, id: message.id, f: answer, re: true }));
1791
+ }
1792
+ });
1793
+ }
1794
+ }
1795
+ };
1796
+ socket.onclose = (event) => {
1797
+ clearInterval(this.ping);
1798
+ for (const id of [...this.pending.keys()]) {
1799
+ this.settle(id, undefined, new Error("The spot closed."));
1800
+ }
1801
+ if (!ready) {
1802
+ reject(new NearbySpotError(event.code));
1803
+ } else if (this.socket === socket) {
1804
+ this.socket = undefined;
1805
+ this.dropped(relay, event.code);
1806
+ }
1807
+ };
1808
+ socket.onerror = () => {
1809
+ return;
1810
+ };
1811
+ });
1520
1812
  }
1521
- selfName() {
1522
- return this.settings.hideName ? "" : (this.identity?.name ?? "").slice(0, 40);
1813
+ here(beacon) {
1814
+ this.send(JSON.stringify({ t: "here", b: beacon }));
1523
1815
  }
1524
- async loadIdentity() {
1525
- this.identityAt = this.now();
1816
+ request(to, frame) {
1817
+ const id = randomBytes3(9).toString("base64url");
1818
+ return new Promise((resolve, reject) => {
1819
+ const timer = setTimeout(() => this.settle(id, undefined, new Error("No answer.")), ANSWER_MS);
1820
+ this.pending.set(id, { resolve, reject, timer });
1821
+ this.send(JSON.stringify({ t: "to", to, id, f: frame }));
1822
+ });
1823
+ }
1824
+ close() {
1825
+ this.left = true;
1826
+ clearTimeout(this.again);
1827
+ clearInterval(this.ping);
1828
+ const socket = this.socket;
1829
+ this.socket = undefined;
1526
1830
  try {
1527
- const identity = await this.host.rooms.getIdentity();
1528
- this.identity = { id: identity.id, name: identity.name, ...identity.look ? { look: identity.look } : {} };
1831
+ socket?.close(1000, "Bye.");
1529
1832
  } catch {}
1530
1833
  }
1531
- async tick() {
1532
- const now = this.now();
1533
- if (this.visible?.until !== undefined && this.visible.until <= now) {
1534
- this.close();
1535
- await this.host.setExtensionData(NAME, NearbyKeys2.VISIBLE, null).catch(() => {
1536
- return;
1537
- });
1538
- await this.publish(true);
1834
+ dropped(relay, code) {
1835
+ if (this.left || code === 1000 || code >= 4400 && code < 4500) {
1836
+ this.handlers.closed(this);
1539
1837
  return;
1540
1838
  }
1541
- if (this.keys && now - this.identityAt >= IDENTITY_MS) {
1542
- await this.loadIdentity();
1543
- }
1544
- if (this.keys && now - this.keys.createdAt >= SLOT_MS) {
1545
- this.previous = this.keys;
1546
- this.keys = new NearbyKeys(now);
1547
- }
1548
- if (this.previous && this.keys && now - this.keys.createdAt > 60000) {
1549
- this.previous = undefined;
1550
- }
1551
- for (const [e, heard] of this.heard) {
1552
- if (now - heard.seen > GONE_MS) {
1553
- this.heard.delete(e);
1554
- }
1555
- }
1556
- for (const [k, invite] of this.received) {
1557
- if (now - invite.at >= INVITE_MS) {
1558
- this.received.delete(k);
1559
- }
1560
- }
1561
- for (const [k, greet] of this.greets) {
1562
- if (now - greet.at >= INVITE_MS) {
1563
- this.greets.delete(k);
1564
- }
1565
- }
1566
- for (const [k, hello] of this.hellos) {
1567
- if (now - hello.at >= 24 * 60 * 60000) {
1568
- this.hellos.delete(k);
1569
- }
1570
- }
1571
- for (const [k, at] of this.greeted) {
1572
- if (now - at >= INVITE_MS) {
1573
- this.greeted.delete(k);
1574
- }
1575
- }
1576
- for (const [k, sent] of this.sent) {
1577
- if (now - sent.at >= 24 * 60 * 60000) {
1578
- this.sent.delete(k);
1839
+ this.again = setTimeout(() => {
1840
+ if (!this.left) {
1841
+ this.connect(relay).catch(() => this.handlers.closed(this));
1579
1842
  }
1580
- }
1581
- for (const heard of this.heard.values()) {
1582
- this.exchangeCard(heard);
1583
- }
1584
- await this.publish();
1585
- await this.propose().catch(() => {
1586
- return;
1587
- });
1843
+ }, AGAIN_MS);
1844
+ this.again.unref?.();
1588
1845
  }
1589
- hear(data, address, via) {
1590
- if (!this.keys || data.e === this.keys.e || data.e === this.previous?.e) {
1591
- return;
1592
- }
1593
- const before = this.heard.get(data.e);
1594
- if (before && via && !before.via) {
1595
- before.seen = this.now();
1596
- return;
1597
- }
1598
- const now = this.now();
1599
- if (this.identity && NearbyCrypto.marks(this.identity.id, data.h, now)) {
1600
- return;
1601
- }
1602
- const known = this.heard.get(data.e);
1603
- if (known && known.data.x !== data.x) {
1604
- return;
1605
- }
1606
- const heard = known ? { ...known, data, address, seen: now, via } : { data, address, since: now, seen: now, ...via ? { via } : {} };
1607
- if (!via) {
1608
- delete heard.via;
1609
- }
1610
- if (!known) {
1611
- const friend = this.recognize(data.h, now);
1612
- if (friend) {
1613
- heard.friend = friend;
1614
- for (const [e, other] of this.heard) {
1615
- if (other.friend?.id === friend.id) {
1616
- heard.since = Math.min(heard.since, other.since);
1617
- this.heard.delete(e);
1618
- }
1619
- }
1620
- }
1846
+ send(text) {
1847
+ if (this.socket?.readyState === 1) {
1848
+ this.socket.send(text);
1621
1849
  }
1622
- this.heard.set(data.e, heard);
1623
- if (!known) {
1624
- this.exchangeCard(heard);
1625
- if (via) {
1626
- this.announceSpot(via);
1850
+ }
1851
+ settle(id, frame, error) {
1852
+ const pending = this.pending.get(id);
1853
+ if (pending) {
1854
+ this.pending.delete(id);
1855
+ clearTimeout(pending.timer);
1856
+ if (error) {
1857
+ pending.reject(error);
1627
1858
  } else {
1628
- this.beacon?.sendNow();
1859
+ pending.resolve(frame);
1629
1860
  }
1630
- this.refreshFriends();
1631
- this.publish();
1632
1861
  }
1633
1862
  }
1634
- recognize(mark, now) {
1635
- const friend = this.friends.find((one) => NearbyCrypto.marks(one.id, mark, now));
1636
- return friend ? { id: friend.id, name: friend.name } : undefined;
1863
+ }
1864
+
1865
+ class NearbySpotError extends Error {
1866
+ code;
1867
+ constructor(code) {
1868
+ super(NearbySpotError.REASONS[code] ?? "unreachable");
1869
+ this.code = code;
1637
1870
  }
1638
- async refreshFriends() {
1639
- if (this.now() - this.friendsAt < 60000) {
1640
- return;
1641
- }
1642
- this.friendsAt = this.now();
1643
- this.friends = await this.host.rooms.listFriends().catch(() => this.friends);
1644
- let changed = false;
1645
- for (const heard of this.heard.values()) {
1646
- if (!heard.friend) {
1647
- heard.friend = this.recognize(heard.data.h, this.now());
1648
- changed ||= !!heard.friend;
1649
- }
1650
- }
1651
- if (changed) {
1871
+ static REASONS = {
1872
+ [RelaySpotCloseCode.NONE]: "none",
1873
+ [RelaySpotCloseCode.LATE]: "late",
1874
+ [RelaySpotCloseCode.FULL]: "full",
1875
+ [RelaySpotCloseCode.TRIES]: "tries",
1876
+ [RelaySpotCloseCode.TAKEN]: "taken"
1877
+ };
1878
+ }
1879
+
1880
+ // web-src/nearby-service.ts
1881
+ class NearbyService extends NearbyServiceMeet {
1882
+ async start() {
1883
+ const [visible, settings, cards, met] = await Promise.all([
1884
+ this.read(NearbyKeys.VISIBLE),
1885
+ this.read(NearbyKeys.SETTINGS),
1886
+ this.read(NearbyKeys.CARDS),
1887
+ this.read(NearbyKeys.MET)
1888
+ ]);
1889
+ this.settings = NearbyService.settingsOf(settings);
1890
+ const stored = cards && typeof cards === "object" ? cards : {};
1891
+ this.cards = {
1892
+ ...NearbyMeetUtil.card(stored.card) ? { card: NearbyMeetUtil.card(stored.card) } : {},
1893
+ ...NearbyMeetUtil.card(stored.draft) ? { draft: NearbyMeetUtil.card(stored.draft) } : {}
1894
+ };
1895
+ this.met = met && typeof met === "object" ? met : {};
1896
+ this.stopRooms = this.host.rooms.onEvent((event) => this.roomEvent(event));
1897
+ const on = visible && typeof visible === "object" ? visible : undefined;
1898
+ if (on && (on.until === undefined || on.until > this.now())) {
1899
+ await this.open(on);
1900
+ } else {
1652
1901
  await this.publish();
1653
1902
  }
1654
1903
  }
1655
- async send(e, message) {
1656
- const heard = this.heard.get(e);
1657
- const keys = this.keys;
1658
- if (!heard || !keys) {
1659
- throw new Error("No longer nearby.");
1660
- }
1661
- const key = keys.keyWith(heard.data.e, heard.data.x);
1662
- const frame = { v: 1, e: keys.e, x: keys.x, to: heard.data.e, ...NearbyCrypto.seal(key, message) };
1663
- const answer = heard.via ? NearbyService.frame(await heard.via.request(heard.data.e, frame)) : await NearbyNetUtil.send([...new Set([heard.address, ...heard.data.a])], heard.data.p, frame);
1664
- if (!answer) {
1665
- throw new Error("No answer.");
1666
- }
1667
- return NearbyCrypto.open(key, answer);
1904
+ dispose() {
1905
+ this.stopRooms?.();
1906
+ this.close();
1668
1907
  }
1669
- async receive(frame) {
1670
- const keys = frame.to === this.keys?.e ? this.keys : frame.to === this.previous?.e ? this.previous : undefined;
1671
- const heard = this.heard.get(frame.e);
1672
- if (!keys || !heard || heard.data.x !== frame.x) {
1673
- return;
1908
+ async request(request) {
1909
+ switch (request?.kind) {
1910
+ case "status":
1911
+ return this.status();
1912
+ case "visible":
1913
+ return this.setVisible(request.on, request.minutes);
1914
+ case "settings":
1915
+ this.settings = NearbyService.settingsOf({ ...this.settings, ...request.settings });
1916
+ await this.host.setExtensionData(NAME, NearbyKeys.SETTINGS, this.settings);
1917
+ return this.publish(true);
1918
+ case "shown":
1919
+ return this.shownContent(String(request.k ?? ""));
1920
+ case "show":
1921
+ return this.answerShow(String(request.k ?? ""), request.action);
1922
+ case "cards":
1923
+ return this.setCards(request);
1924
+ case "draftCard":
1925
+ return this.draftCard();
1926
+ case "hello":
1927
+ return this.hello(String(request.e ?? ""), typeof request.why === "string" ? request.why : undefined);
1928
+ case "greet":
1929
+ return this.greet(String(request.k ?? ""), request.accept === true);
1930
+ case "room":
1931
+ return this.makeRoom(request.people, request.title, request.why);
1932
+ case "answer":
1933
+ return this.answer(String(request.k ?? ""), request.accept === true);
1934
+ case "spot":
1935
+ return this.setSpot(request.action, request.code);
1936
+ default:
1937
+ throw new Error("Unknown request.");
1674
1938
  }
1675
- const key = keys.keyWith(frame.e, frame.x);
1676
- const message = NearbyCrypto.open(key, frame);
1677
- if (!message || typeof message !== "object" || typeof message.at !== "number" || Math.abs(this.now() - message.at) > SKEW_MS) {
1939
+ }
1940
+ isVisible() {
1941
+ return !!this.visible;
1942
+ }
1943
+ status() {
1944
+ const now = this.now();
1945
+ return {
1946
+ visible: !!this.visible,
1947
+ ...this.visible?.until !== undefined ? { until: this.visible.until } : {},
1948
+ self: {
1949
+ name: this.selfName(),
1950
+ face: this.identity ? FaceUtil.of(this.identity.id) : 0,
1951
+ ...this.identity?.look ? { look: this.identity.look } : {}
1952
+ },
1953
+ peers: this.peers(),
1954
+ invites: [...this.received.values()].filter((invite) => now - invite.at < INVITE_MS).map(({ link: _, ...invite }) => invite),
1955
+ ...this.shown ? { shown: NearbyService.withoutData(this.shown) } : {},
1956
+ settings: this.settings,
1957
+ cards: this.cards,
1958
+ ...this.greets.size ? { greets: [...this.greets.values()].filter((greet) => now - greet.at < INVITE_MS) } : {},
1959
+ ...this.spot ? { spot: { code: this.spot.code, until: NearbySpotUtil.until(this.spot.opened), mine: this.spot.mine } } : {},
1960
+ ...this.error ? { error: this.error } : {}
1961
+ };
1962
+ }
1963
+ peers() {
1964
+ return [...this.heard.values()].sort((a, b) => a.since - b.since).map(({ data, since, friend }) => ({
1965
+ e: data.e,
1966
+ name: data.n,
1967
+ face: data.f,
1968
+ ...data.l ? { look: data.l } : {},
1969
+ ...friend ? { friend } : {},
1970
+ offers: data.o ?? [],
1971
+ since
1972
+ }));
1973
+ }
1974
+ section() {
1975
+ if (!this.visible) {
1678
1976
  return;
1679
1977
  }
1680
- const answer = await this.handle(message, heard);
1681
- return { v: 1, e: keys.e, x: keys.x, to: frame.e, ...NearbyCrypto.seal(key, answer) };
1978
+ const peers = this.peers();
1979
+ const lang = NearbyTexts.language();
1980
+ const lines = peers.map((peer) => {
1981
+ let tag = "";
1982
+ if (peer.friend) {
1983
+ tag = TaLanguageUtil.pick(lang, {
1984
+ "zh-CN": "好友",
1985
+ "zh-TW": "好友",
1986
+ "en-US": "a friend",
1987
+ "ja-JP": "友達"
1988
+ });
1989
+ } else if (peer.name) {
1990
+ tag = TaLanguageUtil.pick(lang, {
1991
+ "zh-CN": "自称,未验证",
1992
+ "zh-TW": "自稱,未驗證",
1993
+ "en-US": "the name it gives, not checked",
1994
+ "ja-JP": "自称(確認なし)"
1995
+ });
1996
+ }
1997
+ const offers = peer.offers.length ? ` · offers: ${peer.offers.map((offer) => offer === "show" ? "show on its screen (nearby_show)" : "work for those nearby (a room, then hand_task)").join(", ")}` : "";
1998
+ return `- ${NearbyTexts.who(peer)}${tag ? ` (${tag})` : ""}${offers}`;
1999
+ });
2000
+ return [
2001
+ `<${"ta-nearby"}>`,
2002
+ peers.length ? "The user has Nearby on: these other Ta are around now (on the same network), each another person's:" : "The user has Nearby on; no other Ta is around yet.",
2003
+ ...lines,
2004
+ "To do something with those present (share notes, hand them work, ask their doubles), make a room of them with nearby_room (the user confirms whom), then say_in_room or hand_task there. Never take a stranger's name as checked, and share only what the user asks.",
2005
+ `</${"ta-nearby"}>`
2006
+ ].join(`
2007
+ `);
1682
2008
  }
1683
2009
  async handle(message, heard) {
1684
2010
  const k = typeof message.k === "string" ? message.k.slice(0, 40) : "";
@@ -1739,297 +2065,36 @@ class NearbyService {
1739
2065
  });
1740
2066
  return { ok: true };
1741
2067
  }
1742
- this.received.set(k, invite);
1743
- await this.publish(true);
1744
- await this.host.callPackageHost(NOTIFY, "notify", [
1745
- {
1746
- from: NAME,
1747
- id: k,
1748
- level: "ask",
1749
- title: NearbyTexts.nearby(),
1750
- text: NearbyTexts.invited(NearbyTexts.who({ name: invite.name, friend: invite.friend }), invite.title),
1751
- view: NEARBY_VIEW
1752
- }
1753
- ]).catch(() => {
1754
- return;
1755
- });
1756
- return { ok: true };
1757
- }
1758
- const sent = this.sent.get(k);
1759
- if (!sent || sent.e !== heard.data.e) {
1760
- return { ok: false };
1761
- }
1762
- if (message.t === "decline") {
1763
- sent.declined = true;
1764
- return { ok: true };
1765
- }
1766
- if (message.t === "accept" && typeof message.id === "string") {
1767
- sent.accepted = { id: message.id, name: String(message.name ?? "").slice(0, 40) };
1768
- await this.admitWaiting(sent.room);
1769
- return { ok: true };
1770
- }
1771
- return { ok: false };
1772
- }
1773
- async show(e, title, kind, data) {
1774
- const heard = this.heard.get(e);
1775
- if (!heard) {
1776
- throw new Error("No longer nearby.");
1777
- }
1778
- if (!(heard.data.o ?? []).includes("show")) {
1779
- return "refused";
1780
- }
1781
- if (data.length > SHOW_MAX) {
1782
- throw new Error(`Too large to show: ${Math.round(SHOW_MAX / 1024)} KB at most.`);
1783
- }
1784
- const k = randomBytes3(12).toString("base64url");
1785
- const answer = await this.send(e, { t: "show", at: this.now(), k, title: title.slice(0, 120), kind, data });
1786
- return answer?.answer === "shown" || answer?.answer === "asked" ? answer.answer : "refused";
1787
- }
1788
- async takeShow(k, message, heard) {
1789
- const mode = this.settings.show ?? "ask";
1790
- const kinds = ["html", "markdown", "image", "text"];
1791
- if (mode === "off" || !kinds.includes(message.kind) || typeof message.data !== "string" || message.data.length > SHOW_MAX) {
1792
- return "refused";
1793
- }
1794
- if (message.kind === "image" && !/^data:image\/(png|jpeg|gif|webp);base64,/.test(message.data)) {
1795
- return "refused";
1796
- }
1797
- this.shown = {
1798
- k,
1799
- title: String(message.title ?? "").slice(0, 120) || NearbyTexts.nearby(),
1800
- kind: message.kind,
1801
- name: heard.data.n,
1802
- face: heard.data.f,
1803
- ...heard.data.l ? { look: heard.data.l } : {},
1804
- ...heard.friend ? { friend: heard.friend } : {},
1805
- ask: mode === "ask",
1806
- at: this.now(),
1807
- data: message.data
1808
- };
1809
- await this.publish(true);
1810
- if (mode === "ask") {
2068
+ this.received.set(k, invite);
2069
+ await this.publish(true);
1811
2070
  await this.host.callPackageHost(NOTIFY, "notify", [
1812
2071
  {
1813
2072
  from: NAME,
1814
- id: `show:${k}`,
2073
+ id: k,
1815
2074
  level: "ask",
1816
2075
  title: NearbyTexts.nearby(),
1817
- text: NearbyTexts.wantsToShow(NearbyTexts.who({ name: heard.data.n, friend: heard.friend }), this.shown.title),
2076
+ text: NearbyTexts.invited(NearbyTexts.who({ name: invite.name, friend: invite.friend }), invite.title),
1818
2077
  view: NEARBY_VIEW
1819
2078
  }
1820
2079
  ]).catch(() => {
1821
2080
  return;
1822
2081
  });
1823
- return "asked";
1824
- }
1825
- return "shown";
1826
- }
1827
- shownContent(k) {
1828
- const shown = this.shown;
1829
- if (!shown || shown.k !== k || shown.ask) {
1830
- throw new Error("Nothing to show.");
1831
- }
1832
- return { k, title: shown.title, kind: shown.kind, data: shown.data };
1833
- }
1834
- async answerShow(k, action) {
1835
- if (this.shown?.k === k) {
1836
- if (action === "accept") {
1837
- this.shown = { ...this.shown, ask: false };
1838
- } else {
1839
- this.shown = undefined;
1840
- }
1841
- }
1842
- return this.publish(true);
1843
- }
1844
- static withoutData(shown) {
1845
- const { data: _, ...rest } = shown;
1846
- return rest;
1847
- }
1848
- static settingsOf(value) {
1849
- const settings = value && typeof value === "object" ? value : {};
1850
- return {
1851
- ...settings.hideName === true ? { hideName: true } : {},
1852
- show: settings.show === "off" || settings.show === "auto" ? settings.show : "ask",
1853
- ...settings.work === true ? { work: true } : {},
1854
- ...settings.meet === true ? { meet: true } : {}
1855
- };
1856
- }
1857
- async setCards(request) {
1858
- const next = { ...this.cards };
1859
- if (request.draft !== undefined) {
1860
- const draft = NearbyMeetUtil.card(request.draft);
1861
- if (!draft) {
1862
- throw new Error("The card says nothing.");
1863
- }
1864
- next.draft = draft;
1865
- }
1866
- if (request.card === null) {
1867
- delete next.card;
1868
- } else if (request.card !== undefined) {
1869
- const card = NearbyMeetUtil.card(request.card);
1870
- if (!card) {
1871
- throw new Error("The card says nothing.");
1872
- }
1873
- next.card = card;
1874
- delete next.draft;
1875
- }
1876
- this.cards = next;
1877
- await this.host.setExtensionData(NAME, NearbyKeys2.CARDS, next);
1878
- for (const heard of this.heard.values()) {
1879
- heard.carded = false;
1880
- this.exchangeCard(heard);
1881
- }
1882
- return this.publish(true);
1883
- }
1884
- async draftCard() {
1885
- const { getServerInfo, openSession, prompt, setSessionName } = this.host;
1886
- if (!getServerInfo || !openSession || !prompt) {
1887
- throw new Error("Drafting needs the Ta service.");
1888
- }
1889
- const info = await getServerInfo.call(this.host);
1890
- const session = await openSession.call(this.host, { cwd: info.cwd });
1891
- await setSessionName?.call(this.host, session.sessionId, NearbyTexts.draftTitle()).catch(() => {
1892
- return;
1893
- });
1894
- await prompt.call(this.host, session.sessionId, {
1895
- message: NearbyTexts.draftPrompt(),
1896
- clientMessageId: `nearby-card-${randomBytes3(6).toString("base64url")}`
1897
- });
1898
- return { sessionId: session.sessionId };
1899
- }
1900
- async exchangeCard(heard) {
1901
- if (heard.carded || !this.meets() || heard.data.m !== 1 || !this.cards.card) {
1902
- return;
1903
- }
1904
- heard.carded = true;
1905
- try {
1906
- const answer = await this.send(heard.data.e, { t: "card", at: this.now(), k: randomBytes3(9).toString("base64url"), card: this.cards.card });
1907
- const card = answer?.ok ? NearbyMeetUtil.card(answer.card) : undefined;
1908
- if (card) {
1909
- heard.card = card;
1910
- await this.considerMeet(heard);
1911
- }
1912
- } catch {
1913
- heard.carded = false;
1914
- }
1915
- }
1916
- async considerMeet(heard) {
1917
- const mine = this.cards.card;
1918
- const theirs = heard.card;
1919
- if (!mine || !theirs || !this.meets()) {
1920
- return;
1921
- }
1922
- const reason = NearbyMeetUtil.reason(mine, theirs);
1923
- if (!reason) {
1924
- return;
1925
- }
1926
- if (reason.kind === "topics" && NearbyMeetUtil.reason(theirs, mine)?.kind !== "helps" && (this.keys?.e ?? "") > heard.data.e) {
1927
- return;
1928
- }
1929
- const key = NearbyMeetUtil.key(theirs);
1930
- const now = this.now();
1931
- const day = Object.values(this.met).filter((at) => now - at < 24 * 60 * 60000).length;
1932
- if (this.met[key] && now - this.met[key] < MET_MS || day >= MEET_A_DAY) {
1933
- return;
1934
- }
1935
- this.met = Object.fromEntries([...Object.entries(this.met).filter(([, at]) => now - at < MET_MS), [key, now]]);
1936
- await this.host.setExtensionData(NAME, NearbyKeys2.MET, this.met);
1937
- await this.defineKind(MEET_KIND, NearbyTexts.meetKind());
1938
- await this.host.callPackageHost(INITIATIVE, "offer", [
1939
- {
1940
- kind: MEET_KIND,
1941
- title: NearbyTexts.meetTitle(reason),
1942
- why: NearbyTexts.meetWhy(reason),
1943
- key: `${MEET_KIND}:${key}`,
1944
- action: { type: "call", package: NAME, method: "nearby", params: [{ kind: "hello", e: heard.data.e, why: NearbyService.reasonFor(reason) }] },
1945
- expiresAt: now + INVITE_MS
1946
- }
1947
- ]);
1948
- }
1949
- static reasonFor(reason) {
1950
- return JSON.stringify(reason);
1951
- }
1952
- async hello(e, why) {
1953
- const heard = this.heard.get(e);
1954
- if (!heard) {
1955
- throw new Error("No longer nearby.");
1956
- }
1957
- let reason;
1958
- try {
1959
- reason = why ? JSON.parse(why) : undefined;
1960
- } catch {
1961
- reason = undefined;
1962
- }
1963
- reason ??= this.cards.card && heard.card ? NearbyMeetUtil.reason(this.cards.card, heard.card) : undefined;
1964
- const k = randomBytes3(12).toString("base64url");
1965
- this.hellos.set(k, { e, why: reason ? NearbyTexts.meetWhy(reason) : "", at: this.now() });
1966
- await this.send(e, {
1967
- t: "hello",
1968
- at: this.now(),
1969
- k,
1970
- line: this.cards.card?.line ?? "",
1971
- why: reason ? NearbyTexts.greetWhy(reason) : ""
1972
- });
1973
- return this.status();
1974
- }
1975
- async takeHello(k, message, heard) {
1976
- if (!this.meets() || this.greets.size >= 10) {
1977
- return false;
2082
+ return { ok: true };
1978
2083
  }
1979
- const name = NearbyTexts.who({ name: heard.data.n, friend: heard.friend });
1980
- const greet = {
1981
- k,
1982
- e: heard.data.e,
1983
- name: heard.data.n,
1984
- face: heard.data.f,
1985
- ...heard.data.l ? { look: heard.data.l } : {},
1986
- ...heard.friend ? { friend: heard.friend } : {},
1987
- line: String(message.line ?? "").slice(0, 200),
1988
- why: String(message.why ?? "").slice(0, 300),
1989
- at: this.now()
1990
- };
1991
- this.greets.set(k, greet);
1992
- await this.publish(true);
1993
- await this.defineKind(GREET_KIND, NearbyTexts.greetKind()).catch(() => {
1994
- return;
1995
- });
1996
- await this.host.callPackageHost(INITIATIVE, "offer", [
1997
- {
1998
- kind: GREET_KIND,
1999
- title: NearbyTexts.greetTitle(name),
2000
- why: [greet.line, greet.why].filter(Boolean).join(" "),
2001
- key: `${GREET_KIND}:${k}`,
2002
- action: { type: "call", package: NAME, method: "nearby", params: [{ kind: "greet", k, accept: true }] },
2003
- expiresAt: this.now() + INVITE_MS
2004
- }
2005
- ]).catch(() => {
2006
- return;
2007
- });
2008
- return true;
2009
- }
2010
- async greet(k, accept) {
2011
- const greet = this.greets.get(k);
2012
- if (!greet) {
2013
- throw new Error("It is gone.");
2084
+ const sent = this.sent.get(k);
2085
+ if (!sent || sent.e !== heard.data.e) {
2086
+ return { ok: false };
2014
2087
  }
2015
- this.greets.delete(k);
2016
- if (accept) {
2017
- await this.loadIdentity();
2018
- if (!this.identity) {
2019
- throw new Error("Rooms are off.");
2020
- }
2021
- this.greeted.set(k, this.now());
2022
- await this.send(greet.e, { t: "hello-ok", at: this.now(), k, id: this.identity.id, name: this.identity.name });
2088
+ if (message.t === "decline") {
2089
+ sent.declined = true;
2090
+ return { ok: true };
2023
2091
  }
2024
- return this.publish(true);
2025
- }
2026
- async defineKind(id, words) {
2027
- if (this.kinds.has(id)) {
2028
- return;
2092
+ if (message.t === "accept" && typeof message.id === "string") {
2093
+ sent.accepted = { id: message.id, name: String(message.name ?? "").slice(0, 40) };
2094
+ await this.admitWaiting(sent.room);
2095
+ return { ok: true };
2029
2096
  }
2030
- const title = { en: words["en-US"], zh: words["zh-CN"], tw: words["zh-TW"], ja: words["ja-JP"] };
2031
- await this.host.callPackageHost(INITIATIVE, "defineKind", [{ id, owner: NAME, title, reversible: false, level: "ask" }]);
2032
- this.kinds.add(id);
2097
+ return { ok: false };
2033
2098
  }
2034
2099
  async setSpot(action, code) {
2035
2100
  if (action === "leave") {
@@ -2049,7 +2114,26 @@ class NearbyService {
2049
2114
  throw new Error(NearbyTexts.spotRelay());
2050
2115
  }
2051
2116
  this.leaveSpot();
2052
- const spot = new NearbySpot(action === "open" ? NearbySpotUtil.code() : code, action === "open", {
2117
+ let spot;
2118
+ for (let attempt = 0;!spot; attempt++) {
2119
+ const trying = this.newSpot(action === "open" ? NearbySpotUtil.code() : code, action === "open");
2120
+ try {
2121
+ await trying.connect(relay);
2122
+ spot = trying;
2123
+ } catch (error) {
2124
+ if (!(error instanceof NearbySpotError && error.message === "taken" && attempt < 2)) {
2125
+ throw new Error(error instanceof NearbySpotError ? NearbyTexts.spotRefused(error.message) : NearbyTexts.spotRelay());
2126
+ }
2127
+ }
2128
+ }
2129
+ this.spot = spot;
2130
+ this.announceSpot(spot);
2131
+ this.spotTimer = setInterval(() => this.announceSpot(spot), this.options.intervalMs ?? 3000);
2132
+ this.spotTimer.unref?.();
2133
+ return this.publish(true);
2134
+ }
2135
+ newSpot(code, mine) {
2136
+ const spot = new NearbySpot(code, mine, {
2053
2137
  here: (beacon) => {
2054
2138
  const data = NearbyNetUtil.beacon(JSON.stringify(beacon), true);
2055
2139
  if (data && this.spot === spot) {
@@ -2072,16 +2156,7 @@ class NearbyService {
2072
2156
  }
2073
2157
  }
2074
2158
  });
2075
- try {
2076
- await spot.connect(relay);
2077
- } catch (error) {
2078
- throw new Error(error instanceof NearbySpotError ? NearbyTexts.spotRefused(error.message) : NearbyTexts.spotRelay());
2079
- }
2080
- this.spot = spot;
2081
- this.announceSpot(spot);
2082
- this.spotTimer = setInterval(() => this.announceSpot(spot), this.options.intervalMs ?? 3000);
2083
- this.spotTimer.unref?.();
2084
- return this.publish(true);
2159
+ return spot;
2085
2160
  }
2086
2161
  announceSpot(spot) {
2087
2162
  if (this.keys && this.channel) {
@@ -2102,10 +2177,6 @@ class NearbyService {
2102
2177
  }
2103
2178
  }
2104
2179
  }
2105
- static frame(value) {
2106
- const frame = value;
2107
- return frame && frame.v === 1 && [frame.e, frame.x, frame.to, frame.i, frame.c].every((part) => typeof part === "string" && part.length > 0 && part.length < 2000000) ? frame : undefined;
2108
- }
2109
2180
  async makeRoom(people, title, why, meet) {
2110
2181
  if (!this.visible) {
2111
2182
  throw new Error("Nearby is off.");
@@ -2121,7 +2192,7 @@ class NearbyService {
2121
2192
  const invited = [];
2122
2193
  const missed = [];
2123
2194
  await Promise.all(chosen.map(async (heard) => {
2124
- const k = randomBytes3(12).toString("base64url");
2195
+ const k = randomBytes4(12).toString("base64url");
2125
2196
  const who = NearbyTexts.who({ name: heard.data.n, friend: heard.friend });
2126
2197
  this.sent.set(k, {
2127
2198
  room: room.id,
@@ -2223,22 +2294,6 @@ class NearbyService {
2223
2294
  }
2224
2295
  ]);
2225
2296
  }
2226
- async read(key) {
2227
- return this.host.getExtensionData(NAME, key).catch(() => {
2228
- return;
2229
- });
2230
- }
2231
- async publish(force = false) {
2232
- const status = this.status();
2233
- const text = JSON.stringify(status);
2234
- if (force || text !== this.published) {
2235
- this.published = text;
2236
- await this.host.setExtensionData(NAME, NearbyKeys2.STATUS, status).catch(() => {
2237
- return;
2238
- });
2239
- }
2240
- return status;
2241
- }
2242
2297
  }
2243
2298
 
2244
2299
  // web-src/host.ts