@celljs/ta 4.15.2 → 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 (669) hide show
  1. package/README.en.md +1 -0
  2. package/README.md +1 -0
  3. package/dist/cli.mjs +2227 -203
  4. package/dist/gateway.mjs +2391 -291
  5. package/dist/pi/CHANGELOG.md +19 -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 +286 -111
  12. package/dist/pi/packages/ta-agents/host/index.mjs +662 -0
  13. package/dist/pi/packages/ta-agents/lib/acp-protocol.d.ts +2 -0
  14. package/dist/pi/packages/ta-agents/lib/acp-protocol.js +5 -0
  15. package/dist/pi/packages/ta-agents/lib/agent-catalog.d.ts +36 -2
  16. package/dist/pi/packages/ta-agents/lib/agent-catalog.js +76 -6
  17. package/dist/pi/packages/ta-agents/lib/agent-installer.d.ts +55 -0
  18. package/dist/pi/packages/ta-agents/lib/agent-installer.js +140 -0
  19. package/dist/pi/packages/ta-agents/lib/agent-installs.d.ts +25 -0
  20. package/dist/pi/packages/ta-agents/lib/agent-installs.js +64 -0
  21. package/dist/pi/packages/ta-agents/lib/agent-prompt.d.ts +6 -0
  22. package/dist/pi/packages/ta-agents/lib/agent-prompt.js +9 -0
  23. package/dist/pi/packages/ta-agents/lib/agent-refresh.d.ts +11 -0
  24. package/dist/pi/packages/ta-agents/lib/agent-refresh.js +37 -0
  25. package/dist/pi/packages/ta-agents/lib/agent-session.d.ts +0 -2
  26. package/dist/pi/packages/ta-agents/lib/agent-session.js +3 -6
  27. package/dist/pi/packages/ta-agents/lib/agent-turn.d.ts +7 -2
  28. package/dist/pi/packages/ta-agents/lib/agent-turn.js +8 -4
  29. package/dist/pi/packages/ta-agents/lib/agents-protocol.d.ts +26 -0
  30. package/dist/pi/packages/ta-agents/lib/agents-protocol.js +11 -0
  31. package/dist/pi/packages/ta-agents/lib/agents-settings.d.ts +10 -0
  32. package/dist/pi/packages/ta-agents/lib/agents-settings.js +165 -0
  33. package/dist/pi/packages/ta-agents/lib/extension.d.ts +3 -1
  34. package/dist/pi/packages/ta-agents/lib/extension.js +17 -4
  35. package/dist/pi/packages/ta-agents/lib/host.d.ts +35 -0
  36. package/dist/pi/packages/ta-agents/lib/host.js +96 -0
  37. package/dist/pi/packages/ta-agents/lib/react.d.ts +8 -0
  38. package/dist/pi/packages/ta-agents/lib/react.js +8 -0
  39. package/dist/pi/packages/ta-agents/lib/style.d.ts +4 -0
  40. package/dist/pi/packages/ta-agents/lib/style.js +30 -0
  41. package/dist/pi/packages/ta-agents/lib/texts.d.ts +18 -0
  42. package/dist/pi/packages/ta-agents/lib/texts.js +18 -0
  43. package/dist/pi/packages/ta-agents/lib/web-words.d.ts +30 -0
  44. package/dist/pi/packages/ta-agents/lib/web-words.js +98 -0
  45. package/dist/pi/packages/ta-agents/lib/web.d.ts +4 -0
  46. package/dist/pi/packages/ta-agents/lib/web.js +14 -0
  47. package/dist/pi/packages/ta-agents/package.json +21 -5
  48. package/dist/pi/packages/ta-agents/web/index.js +385 -0
  49. package/dist/pi/packages/ta-app-use/README.en.md +28 -0
  50. package/dist/pi/packages/ta-app-use/README.md +28 -0
  51. package/dist/pi/packages/ta-app-use/extension/index.mjs +534 -0
  52. package/dist/pi/packages/ta-app-use/host/index.mjs +136 -0
  53. package/dist/pi/packages/ta-app-use/lib/app-host.d.ts +32 -0
  54. package/dist/pi/packages/ta-app-use/lib/app-host.js +79 -0
  55. package/dist/pi/packages/ta-app-use/lib/app-protocol.d.ts +23 -0
  56. package/dist/pi/packages/ta-app-use/lib/app-protocol.js +9 -0
  57. package/dist/pi/packages/ta-app-use/lib/app-util.d.ts +18 -0
  58. package/dist/pi/packages/ta-app-use/lib/app-util.js +71 -0
  59. package/dist/pi/packages/ta-app-use/lib/extension.d.ts +80 -0
  60. package/dist/pi/packages/ta-app-use/lib/extension.js +125 -0
  61. package/dist/pi/packages/ta-app-use/lib/host.d.ts +7 -0
  62. package/dist/pi/packages/ta-app-use/lib/host.js +16 -0
  63. package/dist/pi/packages/ta-app-use/lib/i18n.d.ts +38 -0
  64. package/dist/pi/packages/ta-app-use/lib/i18n.js +130 -0
  65. package/dist/pi/packages/ta-app-use/lib/index.d.ts +9 -0
  66. package/dist/pi/packages/ta-app-use/lib/index.js +93 -0
  67. package/dist/pi/packages/ta-app-use/lib/screen-cursor.d.ts +33 -0
  68. package/dist/pi/packages/ta-app-use/lib/screen-cursor.js +134 -0
  69. package/dist/pi/packages/ta-app-use/lib/screen-dom.d.ts +19 -0
  70. package/dist/pi/packages/ta-app-use/lib/screen-dom.js +184 -0
  71. package/dist/pi/packages/ta-app-use/lib/screen-driver.d.ts +46 -0
  72. package/dist/pi/packages/ta-app-use/lib/screen-driver.js +174 -0
  73. package/dist/pi/packages/ta-app-use/lib/screen-protocol.d.ts +67 -0
  74. package/dist/pi/packages/ta-app-use/lib/screen-protocol.js +8 -0
  75. package/dist/pi/packages/ta-app-use/lib/screen-text.d.ts +13 -0
  76. package/dist/pi/packages/ta-app-use/lib/screen-text.js +69 -0
  77. package/dist/pi/packages/ta-app-use/lib/screen-window.d.ts +68 -0
  78. package/dist/pi/packages/ta-app-use/lib/screen-window.js +376 -0
  79. package/dist/pi/packages/ta-app-use/lib/tool-line.d.ts +11 -0
  80. package/dist/pi/packages/ta-app-use/lib/tool-line.js +69 -0
  81. package/dist/pi/packages/ta-app-use/package.json +63 -0
  82. package/dist/pi/packages/ta-app-use/web/index.js +1520 -0
  83. package/dist/pi/packages/ta-bots/README.en.md +1 -0
  84. package/dist/pi/packages/ta-bots/README.md +1 -0
  85. package/dist/pi/packages/ta-bots/extension/index.mjs +25 -22
  86. package/dist/pi/packages/ta-bots/host/index.mjs +726 -151
  87. package/dist/pi/packages/ta-bots/lib/bot-service.d.ts +9 -1
  88. package/dist/pi/packages/ta-bots/lib/bot-service.js +49 -8
  89. package/dist/pi/packages/ta-bots/lib/channel-protocol.d.ts +2 -0
  90. package/dist/pi/packages/ta-bots/lib/extension.d.ts +2 -2
  91. package/dist/pi/packages/ta-bots/lib/extension.js +28 -24
  92. package/dist/pi/packages/ta-bots/lib/index.js +4 -0
  93. package/dist/pi/packages/ta-bots/lib/page.d.ts +7 -1
  94. package/dist/pi/packages/ta-bots/lib/page.js +17 -0
  95. package/dist/pi/packages/ta-bots/lib/style.d.ts +1 -1
  96. package/dist/pi/packages/ta-bots/lib/style.js +1 -1
  97. package/dist/pi/packages/ta-bots/lib/wecom-channel.js +1 -1
  98. package/dist/pi/packages/ta-bots/lib/weixin-api.d.ts +1 -0
  99. package/dist/pi/packages/ta-bots/lib/weixin-channel.js +2 -1
  100. package/dist/pi/packages/ta-bots/package.json +1 -1
  101. package/dist/pi/packages/ta-bots/web/index.js +13 -2
  102. package/dist/pi/packages/ta-call/README.en.md +9 -0
  103. package/dist/pi/packages/ta-call/README.md +9 -0
  104. package/dist/pi/packages/ta-call/extension/index.mjs +474 -0
  105. package/dist/pi/packages/ta-call/host/index.mjs +899 -0
  106. package/dist/pi/packages/ta-call/lib/call-host.d.ts +127 -0
  107. package/dist/pi/packages/ta-call/lib/call-host.js +377 -0
  108. package/dist/pi/packages/ta-call/lib/call-protocol.d.ts +33 -0
  109. package/dist/pi/packages/ta-call/lib/call-protocol.js +10 -0
  110. package/dist/pi/packages/ta-call/lib/call-util.d.ts +50 -0
  111. package/dist/pi/packages/ta-call/lib/call-util.js +250 -0
  112. package/dist/pi/packages/ta-call/lib/extension.d.ts +20 -0
  113. package/dist/pi/packages/ta-call/lib/extension.js +114 -0
  114. package/dist/pi/packages/ta-call/lib/host.d.ts +7 -0
  115. package/dist/pi/packages/ta-call/lib/host.js +20 -0
  116. package/dist/pi/packages/ta-call/lib/i18n.d.ts +16 -0
  117. package/dist/pi/packages/ta-call/lib/i18n.js +38 -0
  118. package/dist/pi/packages/ta-call/lib/index.d.ts +7 -0
  119. package/dist/pi/packages/ta-call/lib/index.js +60 -0
  120. package/dist/pi/packages/ta-call/lib/react.d.ts +8 -0
  121. package/dist/pi/packages/ta-call/lib/react.js +8 -0
  122. package/dist/pi/packages/ta-call/package.json +64 -0
  123. package/dist/pi/packages/ta-call/web/index.js +552 -0
  124. package/dist/pi/packages/ta-changes/extension/index.mjs +1 -0
  125. package/dist/pi/packages/ta-changes/lib/card.js +4 -1
  126. package/dist/pi/packages/ta-changes/package.json +1 -1
  127. package/dist/pi/packages/ta-changes/web/index.js +2 -0
  128. package/dist/pi/packages/ta-channels/extension/index.mjs +155 -194
  129. package/dist/pi/packages/ta-channels/host/index.mjs +2039 -1503
  130. package/dist/pi/packages/ta-channels/lib/agent-menu.js +2 -1
  131. package/dist/pi/packages/ta-channels/lib/channel-menu.d.ts +1 -1
  132. package/dist/pi/packages/ta-channels/lib/channel-menu.js +2 -2
  133. package/dist/pi/packages/ta-channels/lib/channels-text.d.ts +38 -0
  134. package/dist/pi/packages/ta-channels/lib/channels-text.js +173 -0
  135. package/dist/pi/packages/ta-channels/lib/channels-util.d.ts +0 -48
  136. package/dist/pi/packages/ta-channels/lib/channels-util.js +1 -223
  137. package/dist/pi/packages/ta-channels/lib/create.js +5 -1
  138. package/dist/pi/packages/ta-channels/lib/i18n-ja.d.ts +3 -0
  139. package/dist/pi/packages/ta-channels/lib/i18n-ja.js +182 -0
  140. package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.d.ts +3 -0
  141. package/dist/pi/packages/ta-channels/lib/i18n-zh-tw.js +182 -0
  142. package/dist/pi/packages/ta-channels/lib/i18n-zh.d.ts +3 -0
  143. package/dist/pi/packages/ta-channels/lib/i18n-zh.js +182 -0
  144. package/dist/pi/packages/ta-channels/lib/i18n.js +4 -535
  145. package/dist/pi/packages/ta-channels/lib/index.js +2 -1
  146. package/dist/pi/packages/ta-channels/lib/notice-util.d.ts +15 -0
  147. package/dist/pi/packages/ta-channels/lib/notice-util.js +61 -0
  148. package/dist/pi/packages/ta-channels/lib/notice.d.ts +1 -1
  149. package/dist/pi/packages/ta-channels/lib/notice.js +5 -4
  150. package/dist/pi/packages/ta-channels/lib/room.js +4 -3
  151. package/dist/pi/packages/ta-channels/lib/sidebar-head.d.ts +6 -0
  152. package/dist/pi/packages/ta-channels/lib/sidebar-head.js +67 -0
  153. package/dist/pi/packages/ta-channels/lib/sidebar-hooks.d.ts +51 -0
  154. package/dist/pi/packages/ta-channels/lib/sidebar-hooks.js +230 -0
  155. package/dist/pi/packages/ta-channels/lib/sidebar-rows.d.ts +71 -0
  156. package/dist/pi/packages/ta-channels/lib/sidebar-rows.js +105 -0
  157. package/dist/pi/packages/ta-channels/lib/sidebar.d.ts +0 -4
  158. package/dist/pi/packages/ta-channels/lib/sidebar.js +35 -396
  159. package/dist/pi/packages/ta-channels/lib/style.d.ts +1 -1
  160. package/dist/pi/packages/ta-channels/lib/style.js +0 -1
  161. package/dist/pi/packages/ta-channels/lib/tasks.js +2 -1
  162. package/dist/pi/packages/ta-channels/lib/team-store.d.ts +78 -0
  163. package/dist/pi/packages/ta-channels/lib/team-store.js +261 -0
  164. package/dist/pi/packages/ta-channels/lib/team-tools.js +3 -2
  165. package/dist/pi/packages/ta-channels/lib/team.d.ts +3 -76
  166. package/dist/pi/packages/ta-channels/lib/team.js +5 -254
  167. package/dist/pi/packages/ta-channels/package.json +1 -1
  168. package/dist/pi/packages/ta-channels/web/index.js +889 -809
  169. package/dist/pi/packages/ta-computer-use/package.json +1 -1
  170. package/dist/pi/packages/ta-cron/README.en.md +19 -3
  171. package/dist/pi/packages/ta-cron/README.md +19 -3
  172. package/dist/pi/packages/ta-cron/extension/index.mjs +396 -111
  173. package/dist/pi/packages/ta-cron/host/index.mjs +633 -49
  174. package/dist/pi/packages/ta-cron/lib/chat-task.d.ts +5 -3
  175. package/dist/pi/packages/ta-cron/lib/chat-task.js +15 -10
  176. package/dist/pi/packages/ta-cron/lib/commands.d.ts +7 -4
  177. package/dist/pi/packages/ta-cron/lib/commands.js +26 -47
  178. package/dist/pi/packages/ta-cron/lib/cron-expression.d.ts +8 -0
  179. package/dist/pi/packages/ta-cron/lib/cron-expression.js +43 -1
  180. package/dist/pi/packages/ta-cron/lib/cron-protocol.d.ts +54 -7
  181. package/dist/pi/packages/ta-cron/lib/cron-protocol.js +16 -2
  182. package/dist/pi/packages/ta-cron/lib/editor.d.ts +3 -0
  183. package/dist/pi/packages/ta-cron/lib/editor.js +106 -36
  184. package/dist/pi/packages/ta-cron/lib/extension.js +1 -1
  185. package/dist/pi/packages/ta-cron/lib/form-util.d.ts +16 -6
  186. package/dist/pi/packages/ta-cron/lib/form-util.js +40 -28
  187. package/dist/pi/packages/ta-cron/lib/host.js +17 -1
  188. package/dist/pi/packages/ta-cron/lib/i18n.d.ts +39 -5
  189. package/dist/pi/packages/ta-cron/lib/i18n.js +160 -24
  190. package/dist/pi/packages/ta-cron/lib/index.js +4 -0
  191. package/dist/pi/packages/ta-cron/lib/page.d.ts +3 -2
  192. package/dist/pi/packages/ta-cron/lib/page.js +13 -2
  193. package/dist/pi/packages/ta-cron/lib/schedule-util.d.ts +4 -0
  194. package/dist/pi/packages/ta-cron/lib/schedule-util.js +52 -4
  195. package/dist/pi/packages/ta-cron/lib/scheduler.d.ts +56 -6
  196. package/dist/pi/packages/ta-cron/lib/scheduler.js +209 -27
  197. package/dist/pi/packages/ta-cron/lib/style.d.ts +1 -1
  198. package/dist/pi/packages/ta-cron/lib/style.js +50 -21
  199. package/dist/pi/packages/ta-cron/lib/task-list.d.ts +23 -0
  200. package/dist/pi/packages/ta-cron/lib/task-list.js +70 -0
  201. package/dist/pi/packages/ta-cron/lib/task-row.d.ts +19 -0
  202. package/dist/pi/packages/ta-cron/lib/task-row.js +246 -0
  203. package/dist/pi/packages/ta-cron/lib/task-util.d.ts +10 -6
  204. package/dist/pi/packages/ta-cron/lib/task-util.js +53 -19
  205. package/dist/pi/packages/ta-cron/lib/task-watchers.d.ts +30 -0
  206. package/dist/pi/packages/ta-cron/lib/task-watchers.js +90 -0
  207. package/dist/pi/packages/ta-cron/lib/tasks-view.d.ts +3 -2
  208. package/dist/pi/packages/ta-cron/lib/tasks-view.js +48 -193
  209. package/dist/pi/packages/ta-cron/lib/tool-line.js +4 -0
  210. package/dist/pi/packages/ta-cron/lib/tool.d.ts +7 -0
  211. package/dist/pi/packages/ta-cron/lib/tool.js +18 -8
  212. package/dist/pi/packages/ta-cron/lib/when.d.ts +39 -0
  213. package/dist/pi/packages/ta-cron/lib/when.js +231 -0
  214. package/dist/pi/packages/ta-cron/package.json +2 -1
  215. package/dist/pi/packages/ta-cron/web/index.js +1091 -340
  216. package/dist/pi/packages/ta-extensions/lib/market-detail.js +9 -5
  217. package/dist/pi/packages/ta-extensions/lib/page.js +1 -1
  218. package/dist/pi/packages/ta-extensions/lib/style.d.ts +1 -1
  219. package/dist/pi/packages/ta-extensions/lib/style.js +1 -1
  220. package/dist/pi/packages/ta-extensions/package.json +1 -1
  221. package/dist/pi/packages/ta-extensions/skills/ta-package/SKILL.md +9 -7
  222. package/dist/pi/packages/ta-extensions/web/index.js +777 -237
  223. package/dist/pi/packages/ta-feedback/README.en.md +10 -0
  224. package/dist/pi/packages/ta-feedback/README.md +10 -0
  225. package/dist/pi/packages/ta-feedback/extension/index.mjs +451 -0
  226. package/dist/pi/packages/ta-feedback/host/index.mjs +1187 -0
  227. package/dist/pi/packages/ta-feedback/lib/extension.d.ts +31 -0
  228. package/dist/pi/packages/ta-feedback/lib/extension.js +160 -0
  229. package/dist/pi/packages/ta-feedback/lib/feedback-git.d.ts +25 -0
  230. package/dist/pi/packages/ta-feedback/lib/feedback-git.js +44 -0
  231. package/dist/pi/packages/ta-feedback/lib/feedback-host.d.ts +133 -0
  232. package/dist/pi/packages/ta-feedback/lib/feedback-host.js +668 -0
  233. package/dist/pi/packages/ta-feedback/lib/feedback-protocol.d.ts +127 -0
  234. package/dist/pi/packages/ta-feedback/lib/feedback-protocol.js +41 -0
  235. package/dist/pi/packages/ta-feedback/lib/feedback-util.d.ts +79 -0
  236. package/dist/pi/packages/ta-feedback/lib/feedback-util.js +252 -0
  237. package/dist/pi/packages/ta-feedback/lib/feedback-view.d.ts +11 -0
  238. package/dist/pi/packages/ta-feedback/lib/feedback-view.js +244 -0
  239. package/dist/pi/packages/ta-feedback/lib/host.d.ts +8 -0
  240. package/dist/pi/packages/ta-feedback/lib/host.js +19 -0
  241. package/dist/pi/packages/ta-feedback/lib/i18n.d.ts +69 -0
  242. package/dist/pi/packages/ta-feedback/lib/i18n.js +250 -0
  243. package/dist/pi/packages/ta-feedback/lib/index.d.ts +8 -0
  244. package/dist/pi/packages/ta-feedback/lib/index.js +88 -0
  245. package/dist/pi/packages/ta-feedback/lib/page.d.ts +35 -0
  246. package/dist/pi/packages/ta-feedback/lib/page.js +135 -0
  247. package/dist/pi/packages/ta-feedback/lib/react.d.ts +8 -0
  248. package/dist/pi/packages/ta-feedback/lib/react.js +8 -0
  249. package/dist/pi/packages/ta-feedback/lib/style.d.ts +4 -0
  250. package/dist/pi/packages/ta-feedback/lib/style.js +71 -0
  251. package/dist/pi/packages/ta-feedback/package.json +65 -0
  252. package/dist/pi/packages/ta-feedback/web/index.js +939 -0
  253. package/dist/pi/packages/ta-games/lib/style.d.ts +1 -1
  254. package/dist/pi/packages/ta-games/lib/style.js +1 -1
  255. package/dist/pi/packages/ta-games/package.json +1 -1
  256. package/dist/pi/packages/ta-games/web/index.js +1 -1
  257. package/dist/pi/packages/ta-glance/README.en.md +2 -0
  258. package/dist/pi/packages/ta-glance/README.md +2 -0
  259. package/dist/pi/packages/ta-glance/extension/index.mjs +135 -27
  260. package/dist/pi/packages/ta-glance/lib/card.js +155 -35
  261. package/dist/pi/packages/ta-glance/lib/glance-json.d.ts +1 -1
  262. package/dist/pi/packages/ta-glance/lib/glance-json.js +8 -1
  263. package/dist/pi/packages/ta-glance/lib/glance-prompt.d.ts +1 -1
  264. package/dist/pi/packages/ta-glance/lib/glance-prompt.js +9 -6
  265. package/dist/pi/packages/ta-glance/lib/glance-protocol.d.ts +43 -4
  266. package/dist/pi/packages/ta-glance/lib/glance-protocol.js +39 -1
  267. package/dist/pi/packages/ta-glance/lib/glance-spec.js +125 -23
  268. package/dist/pi/packages/ta-glance/lib/glance-speech.d.ts +13 -0
  269. package/dist/pi/packages/ta-glance/lib/glance-speech.js +45 -0
  270. package/dist/pi/packages/ta-glance/lib/glance-util.d.ts +13 -0
  271. package/dist/pi/packages/ta-glance/lib/glance-util.js +28 -0
  272. package/dist/pi/packages/ta-glance/lib/i18n.d.ts +5 -0
  273. package/dist/pi/packages/ta-glance/lib/i18n.js +20 -0
  274. package/dist/pi/packages/ta-glance/lib/index.js +11 -1
  275. package/dist/pi/packages/ta-glance/lib/style.d.ts +1 -1
  276. package/dist/pi/packages/ta-glance/lib/style.js +82 -5
  277. package/dist/pi/packages/ta-glance/package.json +2 -1
  278. package/dist/pi/packages/ta-glance/web/index.js +508 -62
  279. package/dist/pi/packages/ta-initiative/extension/index.mjs +3 -2
  280. package/dist/pi/packages/ta-initiative/host/index.mjs +1 -1
  281. package/dist/pi/packages/ta-initiative/lib/chat-proposals.js +1 -1
  282. package/dist/pi/packages/ta-initiative/lib/index.js +1 -0
  283. package/dist/pi/packages/ta-initiative/lib/material-util.js +1 -1
  284. package/dist/pi/packages/ta-initiative/lib/settings.js +2 -1
  285. package/dist/pi/packages/ta-initiative/lib/style.d.ts +1 -1
  286. package/dist/pi/packages/ta-initiative/lib/style.js +1 -1
  287. package/dist/pi/packages/ta-initiative/package.json +1 -1
  288. package/dist/pi/packages/ta-initiative/web/index.js +5 -3
  289. package/dist/pi/packages/ta-launcher/package.json +1 -1
  290. package/dist/pi/packages/ta-manual/lib/manual-util.d.ts +1 -1
  291. package/dist/pi/packages/ta-manual/lib/pictures-c.js +15 -0
  292. package/dist/pi/packages/ta-manual/lib/style.d.ts +1 -1
  293. package/dist/pi/packages/ta-manual/lib/style.js +1 -1
  294. package/dist/pi/packages/ta-manual/lib/topics-a.d.ts +3 -0
  295. package/dist/pi/packages/ta-manual/lib/topics-a.js +295 -0
  296. package/dist/pi/packages/ta-manual/lib/topics-model.d.ts +46 -0
  297. package/dist/pi/packages/ta-manual/lib/topics-model.js +21 -0
  298. package/dist/pi/packages/ta-manual/lib/topics.d.ts +1 -44
  299. package/dist/pi/packages/ta-manual/lib/topics.js +28 -318
  300. package/dist/pi/packages/ta-manual/package.json +1 -1
  301. package/dist/pi/packages/ta-manual/skills/ta-manual/SKILL.md +12 -10
  302. package/dist/pi/packages/ta-manual/web/index.js +97 -24
  303. package/dist/pi/packages/ta-moments/extension/index.mjs +740 -194
  304. package/dist/pi/packages/ta-moments/host/index.mjs +1393 -834
  305. package/dist/pi/packages/ta-moments/lib/index.js +3 -1
  306. package/dist/pi/packages/ta-moments/lib/moments-host-base.d.ts +96 -0
  307. package/dist/pi/packages/ta-moments/lib/moments-host-base.js +276 -0
  308. package/dist/pi/packages/ta-moments/lib/moments-host-pictures.d.ts +22 -0
  309. package/dist/pi/packages/ta-moments/lib/moments-host-pictures.js +167 -0
  310. package/dist/pi/packages/ta-moments/lib/moments-host.d.ts +4 -84
  311. package/dist/pi/packages/ta-moments/lib/moments-host.js +13 -426
  312. package/dist/pi/packages/ta-moments/lib/page.js +3 -3
  313. package/dist/pi/packages/ta-moments/lib/style.d.ts +1 -1
  314. package/dist/pi/packages/ta-moments/lib/style.js +1 -1
  315. package/dist/pi/packages/ta-moments/lib/talk-host-base.d.ts +71 -0
  316. package/dist/pi/packages/ta-moments/lib/talk-host-base.js +171 -0
  317. package/dist/pi/packages/ta-moments/lib/talk-host.d.ts +3 -62
  318. package/dist/pi/packages/ta-moments/lib/talk-host.js +14 -169
  319. package/dist/pi/packages/ta-moments/package.json +1 -1
  320. package/dist/pi/packages/ta-moments/web/index.js +686 -147
  321. package/dist/pi/packages/ta-nearby/extension/index.mjs +9 -0
  322. package/dist/pi/packages/ta-nearby/host/index.mjs +1073 -1018
  323. package/dist/pi/packages/ta-nearby/lib/index.js +8 -5
  324. package/dist/pi/packages/ta-nearby/lib/nearby-home.d.ts +13 -0
  325. package/dist/pi/packages/ta-nearby/lib/nearby-home.js +91 -0
  326. package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.d.ts +12 -0
  327. package/dist/pi/packages/ta-nearby/lib/nearby-meet-view.js +113 -0
  328. package/dist/pi/packages/ta-nearby/lib/nearby-page.d.ts +6 -0
  329. package/dist/pi/packages/ta-nearby/lib/nearby-page.js +157 -0
  330. package/dist/pi/packages/ta-nearby/lib/nearby-service-base.d.ts +161 -0
  331. package/dist/pi/packages/ta-nearby/lib/nearby-service-base.js +343 -0
  332. package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.d.ts +41 -0
  333. package/dist/pi/packages/ta-nearby/lib/nearby-service-meet.js +297 -0
  334. package/dist/pi/packages/ta-nearby/lib/nearby-service.d.ts +6 -167
  335. package/dist/pi/packages/ta-nearby/lib/nearby-service.js +38 -638
  336. package/dist/pi/packages/ta-nearby/lib/nearby-show-view.d.ts +6 -0
  337. package/dist/pi/packages/ta-nearby/lib/nearby-show-view.js +88 -0
  338. package/dist/pi/packages/ta-nearby/lib/nearby-spot.d.ts +6 -0
  339. package/dist/pi/packages/ta-nearby/lib/nearby-spot.js +25 -3
  340. package/dist/pi/packages/ta-nearby/lib/page.d.ts +27 -20
  341. package/dist/pi/packages/ta-nearby/lib/page.js +15 -417
  342. package/dist/pi/packages/ta-nearby/lib/server-texts.d.ts +1 -1
  343. package/dist/pi/packages/ta-nearby/lib/server-texts.js +9 -1
  344. package/dist/pi/packages/ta-nearby/lib/style.d.ts +1 -1
  345. package/dist/pi/packages/ta-nearby/lib/style.js +1 -1
  346. package/dist/pi/packages/ta-nearby/package.json +1 -1
  347. package/dist/pi/packages/ta-nearby/web/index.js +370 -362
  348. package/dist/pi/packages/ta-notify/extension/index.mjs +1 -0
  349. package/dist/pi/packages/ta-notify/lib/settings.js +1 -0
  350. package/dist/pi/packages/ta-notify/package.json +1 -1
  351. package/dist/pi/packages/ta-notify/web/index.js +1 -0
  352. package/dist/pi/packages/ta-plot/extension/index.mjs +1 -0
  353. package/dist/pi/packages/ta-plot/package.json +2 -1
  354. package/dist/pi/packages/ta-recall/extension/index.mjs +1 -0
  355. package/dist/pi/packages/ta-recall/host/index.mjs +1 -0
  356. package/dist/pi/packages/ta-recall/lib/settings.js +1 -0
  357. package/dist/pi/packages/ta-recall/package.json +1 -1
  358. package/dist/pi/packages/ta-recall/web/index.js +2 -0
  359. package/dist/pi/packages/ta-rooms/extension/index.mjs +1 -0
  360. package/dist/pi/packages/ta-rooms/host/index.mjs +497 -492
  361. package/dist/pi/packages/ta-rooms/lib/double-agents.js +6 -6
  362. package/dist/pi/packages/ta-rooms/lib/double-grants.js +10 -10
  363. package/dist/pi/packages/ta-rooms/lib/double-host.js +6 -5
  364. package/dist/pi/packages/ta-rooms/lib/double-tasks-base.d.ts +55 -0
  365. package/dist/pi/packages/ta-rooms/lib/double-tasks-base.js +279 -0
  366. package/dist/pi/packages/ta-rooms/lib/double-tasks.d.ts +3 -45
  367. package/dist/pi/packages/ta-rooms/lib/double-tasks.js +14 -282
  368. package/dist/pi/packages/ta-rooms/lib/double-user.js +2 -2
  369. package/dist/pi/packages/ta-rooms/lib/friend-notices.js +2 -2
  370. package/dist/pi/packages/ta-rooms/lib/i18n.d.ts +1 -0
  371. package/dist/pi/packages/ta-rooms/lib/i18n.js +8 -4
  372. package/dist/pi/packages/ta-rooms/lib/index.js +18 -2
  373. package/dist/pi/packages/ta-rooms/lib/members-view.js +37 -3
  374. package/dist/pi/packages/ta-rooms/lib/page.d.ts +36 -1
  375. package/dist/pi/packages/ta-rooms/lib/page.js +76 -1
  376. package/dist/pi/packages/ta-rooms/lib/room-view.js +22 -17
  377. package/dist/pi/packages/ta-rooms/lib/rooms-home.js +1 -0
  378. package/dist/pi/packages/ta-rooms/lib/style.d.ts +1 -1
  379. package/dist/pi/packages/ta-rooms/lib/style.js +32 -6
  380. package/dist/pi/packages/ta-rooms/package.json +1 -1
  381. package/dist/pi/packages/ta-rooms/web/index.js +223 -38
  382. package/dist/pi/packages/ta-secrets/README.en.md +22 -0
  383. package/dist/pi/packages/ta-secrets/README.md +22 -0
  384. package/dist/pi/packages/ta-secrets/extension/index.mjs +462 -0
  385. package/dist/pi/packages/ta-secrets/host/index.mjs +1341 -0
  386. package/dist/pi/packages/ta-secrets/lib/command-prelude.d.ts +36 -0
  387. package/dist/pi/packages/ta-secrets/lib/command-prelude.js +66 -0
  388. package/dist/pi/packages/ta-secrets/lib/extension.d.ts +28 -0
  389. package/dist/pi/packages/ta-secrets/lib/extension.js +156 -0
  390. package/dist/pi/packages/ta-secrets/lib/host.d.ts +4 -0
  391. package/dist/pi/packages/ta-secrets/lib/host.js +15 -0
  392. package/dist/pi/packages/ta-secrets/lib/i18n.d.ts +47 -0
  393. package/dist/pi/packages/ta-secrets/lib/i18n.js +166 -0
  394. package/dist/pi/packages/ta-secrets/lib/index.d.ts +8 -0
  395. package/dist/pi/packages/ta-secrets/lib/index.js +28 -0
  396. package/dist/pi/packages/ta-secrets/lib/personal-info.d.ts +26 -0
  397. package/dist/pi/packages/ta-secrets/lib/personal-info.js +108 -0
  398. package/dist/pi/packages/ta-secrets/lib/proxy-certs.d.ts +40 -0
  399. package/dist/pi/packages/ta-secrets/lib/proxy-certs.js +200 -0
  400. package/dist/pi/packages/ta-secrets/lib/proxy-scenario.d.ts +6 -0
  401. package/dist/pi/packages/ta-secrets/lib/proxy-scenario.js +91 -0
  402. package/dist/pi/packages/ta-secrets/lib/react.d.ts +8 -0
  403. package/dist/pi/packages/ta-secrets/lib/react.js +8 -0
  404. package/dist/pi/packages/ta-secrets/lib/scrubber.d.ts +20 -0
  405. package/dist/pi/packages/ta-secrets/lib/scrubber.js +70 -0
  406. package/dist/pi/packages/ta-secrets/lib/secrets-protocol.d.ts +106 -0
  407. package/dist/pi/packages/ta-secrets/lib/secrets-protocol.js +134 -0
  408. package/dist/pi/packages/ta-secrets/lib/server-texts.d.ts +14 -0
  409. package/dist/pi/packages/ta-secrets/lib/server-texts.js +62 -0
  410. package/dist/pi/packages/ta-secrets/lib/settings.d.ts +4 -0
  411. package/dist/pi/packages/ta-secrets/lib/settings.js +179 -0
  412. package/dist/pi/packages/ta-secrets/lib/style.d.ts +4 -0
  413. package/dist/pi/packages/ta-secrets/lib/style.js +32 -0
  414. package/dist/pi/packages/ta-secrets/lib/vault-fixture.d.ts +8 -0
  415. package/dist/pi/packages/ta-secrets/lib/vault-fixture.js +22 -0
  416. package/dist/pi/packages/ta-secrets/lib/vault-proxy.d.ts +94 -0
  417. package/dist/pi/packages/ta-secrets/lib/vault-proxy.js +357 -0
  418. package/dist/pi/packages/ta-secrets/lib/vault-service.d.ts +111 -0
  419. package/dist/pi/packages/ta-secrets/lib/vault-service.js +429 -0
  420. package/dist/pi/packages/ta-secrets/lib/vault-store.d.ts +48 -0
  421. package/dist/pi/packages/ta-secrets/lib/vault-store.js +107 -0
  422. package/dist/pi/packages/ta-secrets/package.json +67 -0
  423. package/dist/pi/packages/ta-secrets/web/index.js +579 -0
  424. package/dist/pi/packages/ta-share/extension/index.mjs +1 -0
  425. package/dist/pi/packages/ta-share/host/index.mjs +172 -21
  426. package/dist/pi/packages/ta-share/lib/i18n.d.ts +1 -0
  427. package/dist/pi/packages/ta-share/lib/i18n.js +4 -0
  428. package/dist/pi/packages/ta-share/lib/index.js +1 -1
  429. package/dist/pi/packages/ta-share/lib/share-dialog.js +1 -0
  430. package/dist/pi/packages/ta-share/lib/share-protocol.d.ts +2 -0
  431. package/dist/pi/packages/ta-share/lib/share-service.d.ts +11 -1
  432. package/dist/pi/packages/ta-share/lib/share-service.js +62 -4
  433. package/dist/pi/packages/ta-share/lib/snapshot.d.ts +8 -2
  434. package/dist/pi/packages/ta-share/lib/snapshot.js +93 -7
  435. package/dist/pi/packages/ta-share/lib/style.d.ts +1 -1
  436. package/dist/pi/packages/ta-share/lib/style.js +1 -1
  437. package/dist/pi/packages/ta-share/package.json +1 -1
  438. package/dist/pi/packages/ta-share/web/index.js +7 -2
  439. package/dist/pi/packages/ta-sync/host/index.mjs +1154 -755
  440. package/dist/pi/packages/ta-sync/lib/host.js +3 -0
  441. package/dist/pi/packages/ta-sync/lib/index.js +6 -2
  442. package/dist/pi/packages/ta-sync/lib/migrate-archive.d.ts +8 -6
  443. package/dist/pi/packages/ta-sync/lib/migrate-archive.js +24 -28
  444. package/dist/pi/packages/ta-sync/lib/migrate-i18n.d.ts +10 -0
  445. package/dist/pi/packages/ta-sync/lib/migrate-i18n.js +40 -0
  446. package/dist/pi/packages/ta-sync/lib/migrate-paths.d.ts +24 -0
  447. package/dist/pi/packages/ta-sync/lib/migrate-paths.js +230 -0
  448. package/dist/pi/packages/ta-sync/lib/migrate-protocol.d.ts +18 -0
  449. package/dist/pi/packages/ta-sync/lib/migrate-service.d.ts +11 -1
  450. package/dist/pi/packages/ta-sync/lib/migrate-service.js +28 -1
  451. package/dist/pi/packages/ta-sync/lib/move-panel.d.ts +9 -1
  452. package/dist/pi/packages/ta-sync/lib/move-panel.js +69 -5
  453. package/dist/pi/packages/ta-sync/lib/server-texts.d.ts +1 -0
  454. package/dist/pi/packages/ta-sync/lib/server-texts.js +9 -0
  455. package/dist/pi/packages/ta-sync/lib/style.d.ts +1 -1
  456. package/dist/pi/packages/ta-sync/lib/style.js +8 -1
  457. package/dist/pi/packages/ta-sync/lib/sync-service-base.d.ts +78 -0
  458. package/dist/pi/packages/ta-sync/lib/sync-service-base.js +224 -0
  459. package/dist/pi/packages/ta-sync/lib/sync-service-space.d.ts +36 -0
  460. package/dist/pi/packages/ta-sync/lib/sync-service-space.js +210 -0
  461. package/dist/pi/packages/ta-sync/lib/sync-service.d.ts +3 -99
  462. package/dist/pi/packages/ta-sync/lib/sync-service.js +2 -412
  463. package/dist/pi/packages/ta-sync/package.json +1 -1
  464. package/dist/pi/packages/ta-sync/web/index.js +138 -5
  465. package/dist/pi/packages/ta-sync-cloud/package.json +1 -1
  466. package/dist/pi/packages/ta-team/extension/index.mjs +1 -0
  467. package/dist/pi/packages/ta-team/host/index.mjs +1 -0
  468. package/dist/pi/packages/ta-team/lib/dialogs.d.ts +0 -2
  469. package/dist/pi/packages/ta-team/lib/dialogs.js +0 -227
  470. package/dist/pi/packages/ta-team/lib/i18n-ja.d.ts +3 -0
  471. package/dist/pi/packages/ta-team/lib/i18n-ja.js +211 -0
  472. package/dist/pi/packages/ta-team/lib/i18n-zh-tw.d.ts +3 -0
  473. package/dist/pi/packages/ta-team/lib/i18n-zh-tw.js +211 -0
  474. package/dist/pi/packages/ta-team/lib/i18n-zh.d.ts +3 -0
  475. package/dist/pi/packages/ta-team/lib/i18n-zh.js +211 -0
  476. package/dist/pi/packages/ta-team/lib/i18n.d.ts +1 -2
  477. package/dist/pi/packages/ta-team/lib/i18n.js +6 -624
  478. package/dist/pi/packages/ta-team/lib/index.js +3 -1
  479. package/dist/pi/packages/ta-team/lib/join-dialog.d.ts +3 -0
  480. package/dist/pi/packages/ta-team/lib/join-dialog.js +234 -0
  481. package/dist/pi/packages/ta-team/lib/members-tab.js +2 -1
  482. package/dist/pi/packages/ta-team/lib/style.d.ts +1 -1
  483. package/dist/pi/packages/ta-team/lib/style.js +1 -1
  484. package/dist/pi/packages/ta-team/package.json +1 -1
  485. package/dist/pi/packages/ta-team/web/index.js +2095 -2086
  486. package/dist/pi/packages/ta-usage/README.en.md +6 -0
  487. package/dist/pi/packages/ta-usage/README.md +6 -0
  488. package/dist/pi/packages/ta-usage/host/index.mjs +220 -0
  489. package/dist/pi/packages/ta-usage/lib/host.d.ts +4 -0
  490. package/dist/pi/packages/ta-usage/lib/host.js +9 -0
  491. package/dist/pi/packages/ta-usage/lib/i18n.d.ts +30 -0
  492. package/dist/pi/packages/ta-usage/lib/i18n.js +98 -0
  493. package/dist/pi/packages/ta-usage/lib/index.d.ts +4 -0
  494. package/dist/pi/packages/ta-usage/lib/index.js +20 -0
  495. package/dist/pi/packages/ta-usage/lib/react.d.ts +8 -0
  496. package/dist/pi/packages/ta-usage/lib/react.js +8 -0
  497. package/dist/pi/packages/ta-usage/lib/style.d.ts +4 -0
  498. package/dist/pi/packages/ta-usage/lib/style.js +53 -0
  499. package/dist/pi/packages/ta-usage/lib/usage-host.d.ts +25 -0
  500. package/dist/pi/packages/ta-usage/lib/usage-host.js +70 -0
  501. package/dist/pi/packages/ta-usage/lib/usage-protocol.d.ts +55 -0
  502. package/dist/pi/packages/ta-usage/lib/usage-protocol.js +7 -0
  503. package/dist/pi/packages/ta-usage/lib/usage-util.d.ts +18 -0
  504. package/dist/pi/packages/ta-usage/lib/usage-util.js +159 -0
  505. package/dist/pi/packages/ta-usage/lib/usage-view.d.ts +9 -0
  506. package/dist/pi/packages/ta-usage/lib/usage-view.js +91 -0
  507. package/dist/pi/packages/ta-usage/package.json +61 -0
  508. package/dist/pi/packages/ta-usage/web/index.js +471 -0
  509. package/dist/pi/packages/ta-voice/README.en.md +8 -0
  510. package/dist/pi/packages/ta-voice/README.md +8 -0
  511. package/dist/pi/packages/ta-voice/host/index.mjs +662 -0
  512. package/dist/pi/packages/ta-voice/lib/doubao-frames.d.ts +44 -0
  513. package/dist/pi/packages/ta-voice/lib/doubao-frames.js +116 -0
  514. package/dist/pi/packages/ta-voice/lib/doubao-realtime.d.ts +35 -0
  515. package/dist/pi/packages/ta-voice/lib/doubao-realtime.js +172 -0
  516. package/dist/pi/packages/ta-voice/lib/host.d.ts +20 -0
  517. package/dist/pi/packages/ta-voice/lib/host.js +120 -0
  518. package/dist/pi/packages/ta-voice/lib/openai-realtime.d.ts +73 -0
  519. package/dist/pi/packages/ta-voice/lib/openai-realtime.js +257 -0
  520. package/dist/pi/packages/ta-voice/lib/realtime-socket.d.ts +23 -0
  521. package/dist/pi/packages/ta-voice/lib/realtime-socket.js +80 -0
  522. package/dist/pi/packages/ta-voice/package.json +67 -0
  523. package/dist/pi/packages/ta-workspace/README.md +1 -1
  524. package/dist/pi/packages/ta-workspace/README.zh-cn.md +1 -1
  525. package/dist/pi/packages/ta-workspace/lib/browser-common.d.ts +4 -0
  526. package/dist/pi/packages/ta-workspace/lib/browser-common.js +1 -0
  527. package/dist/pi/packages/ta-workspace/lib/browser-pick.d.ts +49 -0
  528. package/dist/pi/packages/ta-workspace/lib/browser-pick.js +166 -0
  529. package/dist/pi/packages/ta-workspace/lib/browser-webview.js +16 -1
  530. package/dist/pi/packages/ta-workspace/lib/i18n-en.d.ts +3 -0
  531. package/dist/pi/packages/ta-workspace/lib/i18n-en.js +215 -0
  532. package/dist/pi/packages/ta-workspace/lib/i18n-ja.d.ts +3 -0
  533. package/dist/pi/packages/ta-workspace/lib/i18n-ja.js +215 -0
  534. package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.d.ts +3 -0
  535. package/dist/pi/packages/ta-workspace/lib/i18n-zh-tw.js +215 -0
  536. package/dist/pi/packages/ta-workspace/lib/i18n.d.ts +7 -3
  537. package/dist/pi/packages/ta-workspace/lib/i18n.js +11 -621
  538. package/dist/pi/packages/ta-workspace/package.json +1 -1
  539. package/dist/pi/packages/ta-workspace/web/index.js +1504 -770
  540. package/dist/public/assets/{abnfDiagram-S7VZAUFO-Dd51Bqbx.js → abnfDiagram-S7VZAUFO-w8qXXVn-.js} +1 -1
  541. package/dist/public/assets/{architecture-WOLXFQ4H-BbG3_x7_.js → architecture-WOLXFQ4H-B-FHaYwY.js} +1 -1
  542. package/dist/public/assets/{architectureDiagram-YGSQEFNW-DbJO4t8I.js → architectureDiagram-YGSQEFNW-DTnoGaaX.js} +1 -1
  543. package/dist/public/assets/{blockDiagram-APKKGZFW-BwtrHF1f.js → blockDiagram-APKKGZFW-CyeBzv-v.js} +1 -1
  544. package/dist/public/assets/{browser-D2BcOPKG.js → browser-Cb38iiEE.js} +1 -1
  545. package/dist/public/assets/{browser-CTbeNBsA.js → browser-DXexCqIh.js} +2 -2
  546. package/dist/public/assets/{c4Diagram-KJ2TOQU5-CfBe5A0H.js → c4Diagram-KJ2TOQU5-CJJqDqyQ.js} +1 -1
  547. package/dist/public/assets/{chunk-6MUBBAK2-C7R0mhrg.js → chunk-6MUBBAK2-DbvUMdNm.js} +1 -1
  548. package/dist/public/assets/{chunk-AXFCVDMN-VQgQruZT.js → chunk-AXFCVDMN-D4hlZGtj.js} +1 -1
  549. package/dist/public/assets/{chunk-BG4553SI-CkUi_vD5.js → chunk-BG4553SI-VNa9Q9On.js} +1 -1
  550. package/dist/public/assets/{chunk-DQASFODM-BAQq7ktk.js → chunk-DQASFODM-BtlEbc_V.js} +1 -1
  551. package/dist/public/assets/{chunk-HFQBQIA3-B1oF8lB7.js → chunk-HFQBQIA3-CAYSo4CJ.js} +1 -1
  552. package/dist/public/assets/{chunk-KQLB2F66-DE5amcgT.js → chunk-KQLB2F66-CyKdg6hW.js} +1 -1
  553. package/dist/public/assets/{chunk-KS47KZWR-ev9S_csp.js → chunk-KS47KZWR-BMogCB2r.js} +1 -1
  554. package/dist/public/assets/{chunk-LEVMRMFU-ziqnRvTG.js → chunk-LEVMRMFU-Y9wr-8qB.js} +1 -1
  555. package/dist/public/assets/{chunk-M57EVK23-DaqPdEKA.js → chunk-M57EVK23-DL3IAQKR.js} +1 -1
  556. package/dist/public/assets/{chunk-OY52VR5R-DFOG8j6z.js → chunk-OY52VR5R-CJBFHdg6.js} +1 -1
  557. package/dist/public/assets/{chunk-QB3YPZ4I-eg35JLLN.js → chunk-QB3YPZ4I-CyuWKZZv.js} +1 -1
  558. package/dist/public/assets/{chunk-R3KSYZAL-J73nie-R.js → chunk-R3KSYZAL-DxvGhfpm.js} +1 -1
  559. package/dist/public/assets/{chunk-STOXU5M4-B8EvDZvB.js → chunk-STOXU5M4-Cpdl6bfz.js} +1 -1
  560. package/dist/public/assets/{chunk-TU62E6Q5-DyCM007V.js → chunk-TU62E6Q5-CIxOg6QF.js} +1 -1
  561. package/dist/public/assets/{chunk-X4PVCEUW-BBGeCNmA.js → chunk-X4PVCEUW-DCFSCRBh.js} +1 -1
  562. package/dist/public/assets/{chunk-XXDRQBXY-CAtJ2Wph.js → chunk-XXDRQBXY-B2R8Cxf7.js} +1 -1
  563. package/dist/public/assets/{classDiagram-v2-L25IHNXF-DhQM6yHy.js → classDiagram-v2-L25IHNXF-B7W9HSbj.js} +1 -1
  564. package/dist/public/assets/{client-C8gi9Fk2.js → client-D75LfyFa.js} +1 -1
  565. package/dist/public/assets/{common-DrZR0tgm.js → common-CjqTomRQ.js} +1 -1
  566. package/dist/public/assets/{cose-bilkent-JH36ORCC-AqIcHabu.js → cose-bilkent-JH36ORCC-CXSLFyCH.js} +1 -1
  567. package/dist/public/assets/cynefin-EF2NZ3EQ-BIcbDns7.js +1 -0
  568. package/dist/public/assets/{cynefinDiagram-L36ESFBY-7SyXzhRd.js → cynefinDiagram-L36ESFBY-DTv0Kn1r.js} +1 -1
  569. package/dist/public/assets/{d3-selection-DsahLieG.js → d3-selection-g4Hl3_NH.js} +1 -1
  570. package/dist/public/assets/{dagre-SPEB5RXH-DalaGtMS.js → dagre-SPEB5RXH-BujVqk5R.js} +1 -1
  571. package/dist/public/assets/{diagram-3B7GL73J-BcY-qB9G.js → diagram-3B7GL73J-Ds-VnLzP.js} +1 -1
  572. package/dist/public/assets/{diagram-DNEMPZML-NV7fbe0h.js → diagram-DNEMPZML-BBoIIK-a.js} +1 -1
  573. package/dist/public/assets/{diagram-L3MUGCDN-BPx4GHoj.js → diagram-L3MUGCDN-Glgd5N_n.js} +1 -1
  574. package/dist/public/assets/{diagram-LA4NIPWU-BeUxqmw1.js → diagram-LA4NIPWU-B4EODdUU.js} +1 -1
  575. package/dist/public/assets/{diagram-MHCOC4E2-Dlg1S5na.js → diagram-MHCOC4E2-pzDDXO2J.js} +1 -1
  576. package/dist/public/assets/{diagram-XPFHEONP-DQhRoMkK.js → diagram-XPFHEONP-l--gwSuK.js} +1 -1
  577. package/dist/public/assets/{dist-CQU8zJh_.js → dist-C0u3lAFR.js} +1 -1
  578. package/dist/public/assets/{ebnfDiagram-UZSYDL2S-gVEs3Um2.js → ebnfDiagram-UZSYDL2S-BVfPeaVX.js} +1 -1
  579. package/dist/public/assets/{editor.api-SQ1snuat.js → editor.api-BMcewI3C.js} +1 -1
  580. package/dist/public/assets/{elk-XV6XMXQE-CHtlrPwu.js → elk-XV6XMXQE-BFJtUnG9.js} +1 -1
  581. package/dist/public/assets/{erDiagram-EYBAPDEH-B0xok726.js → erDiagram-EYBAPDEH-BWxMtfIc.js} +1 -1
  582. package/dist/public/assets/{eventmodeling-K75KTNOO-CFwphA0e.js → eventmodeling-K75KTNOO-YwYgBgCX.js} +1 -1
  583. package/dist/public/assets/flowDiagram-MALGAFMO-Dah4--NW.js +1 -0
  584. package/dist/public/assets/{freemarker2-DJKO-X2B.js → freemarker2-B8HquI7K.js} +1 -1
  585. package/dist/public/assets/{ganttDiagram-23REXITY-B5wVGN1A.js → ganttDiagram-23REXITY-CBqv7wbi.js} +1 -1
  586. package/dist/public/assets/gitGraph-VSP46ZUC-BwDfrSZS.js +1 -0
  587. package/dist/public/assets/{gitGraphDiagram-STJD7YCW-DEjNU1R_.js → gitGraphDiagram-STJD7YCW-BLSf23f_.js} +1 -1
  588. package/dist/public/assets/{handlebars-ChVN7JPd.js → handlebars-P1qmNq4N.js} +1 -1
  589. package/dist/public/assets/{html-CQ0znKSa.js → html-Ceswbytr.js} +1 -1
  590. package/dist/public/assets/{index-CLlacdXR.js → index-10isUUN4.js} +2 -2
  591. package/dist/public/assets/info-OHQRW6UA-Ch8aMV1p.js +1 -0
  592. package/dist/public/assets/{infoDiagram-KBXO4MBG-CJtrS72M.js → infoDiagram-KBXO4MBG-LvOtgUlm.js} +1 -1
  593. package/dist/public/assets/{ishikawaDiagram-M35NCXHK-qYI1QBsK.js → ishikawaDiagram-M35NCXHK-CwUZOvcm.js} +1 -1
  594. package/dist/public/assets/{javascript-B-DHbkyI.js → javascript-B3FXC8qR.js} +1 -1
  595. package/dist/public/assets/{journeyDiagram-OPLOXDXO-BOQ2y2ZZ.js → journeyDiagram-OPLOXDXO-5j1KtwTt.js} +1 -1
  596. package/dist/public/assets/{jsonMode-XuGC5N_z.js → jsonMode-CrCyxNQI.js} +1 -1
  597. package/dist/public/assets/{kanban-definition-BZKZHSQY-BJ64tKdP.js → kanban-definition-BZKZHSQY-BKAB5id1.js} +1 -1
  598. package/dist/public/assets/{liquid-B0Ujylzc.js → liquid-CXZRIgp2.js} +1 -1
  599. package/dist/public/assets/{mdx-B19-V510.js → mdx-Dm3uNczM.js} +1 -1
  600. package/dist/public/assets/{mermaid-parser.core-Scb01iBq.js → mermaid-parser.core-C755A-rX.js} +3 -3
  601. package/dist/public/assets/{mermaid.core-BMuvs7us.js → mermaid.core-CQrYmFAR.js} +4 -4
  602. package/dist/public/assets/{mindmap-definition-I2QAS2VK-BYfOS3XN.js → mindmap-definition-I2QAS2VK-DNJQKYbK.js} +1 -1
  603. package/dist/public/assets/module-9otB6_kX.js +1 -0
  604. package/dist/public/assets/{module-Cm_mLwAQ.js → module-C3jC5acf.js} +1 -1
  605. package/dist/public/assets/module-C_MyFORb.js +1 -0
  606. package/dist/public/assets/module-Cjpl4gva.js +1 -0
  607. package/dist/public/assets/{module-DUYj4E8T.js → module-D8yH9xCl.js} +1 -1
  608. package/dist/public/assets/module-DlHjBjOg.js +1 -0
  609. package/dist/public/assets/module-QsLiJaR6.js +1 -0
  610. package/dist/public/assets/module-aaW5Ri2L.js +2771 -0
  611. package/dist/public/assets/module-gSy9fKBo.js +1 -0
  612. package/dist/public/assets/{monaco-Bbe2os7m.js → monaco-BS7JBNW4.js} +3 -3
  613. package/dist/public/assets/packet-JDAUHWVQ-LqMrrc60.js +1 -0
  614. package/dist/public/assets/{pegDiagram-FD4XPPHP-D-Vlq9Gm.js → pegDiagram-FD4XPPHP-BzbBCWht.js} +1 -1
  615. package/dist/public/assets/pie-XZMESJXO-BWzABXQU.js +1 -0
  616. package/dist/public/assets/{pieDiagram-J4AKIIQI-_-94-aMD.js → pieDiagram-J4AKIIQI-Bf_LDukL.js} +1 -1
  617. package/dist/public/assets/{python-CWnMIOYq.js → python-jgOUhB-F.js} +1 -1
  618. package/dist/public/assets/{quadrantDiagram-XTYBLID2-BhFUbUYz.js → quadrantDiagram-XTYBLID2-CdMHWnKX.js} +1 -1
  619. package/dist/public/assets/radar-ABXABTNO-CR4kNiUj.js +1 -0
  620. package/dist/public/assets/railroad-I3PHUGI6-BAkWtkGC.js +1 -0
  621. package/dist/public/assets/{railroad-abnf-LNEFI6M7-yUa9GGCQ.js → railroad-abnf-LNEFI6M7-DQGYaRbc.js} +1 -1
  622. package/dist/public/assets/{railroad-ebnf-DWYD2UWJ-xY4YiL8M.js → railroad-ebnf-DWYD2UWJ-D6Ljza0U.js} +1 -1
  623. package/dist/public/assets/{railroad-peg-JR7BVNR7-BYFYCUAQ.js → railroad-peg-JR7BVNR7-Du9hL1Gf.js} +1 -1
  624. package/dist/public/assets/{railroadDiagram-MRQ6NCDL-C9FVhj0k.js → railroadDiagram-MRQ6NCDL-CS_JnlGN.js} +1 -1
  625. package/dist/public/assets/{razor-bDtpN6EJ.js → razor-BWj90God.js} +1 -1
  626. package/dist/public/assets/{requirementDiagram-Y7LWUY3S-DLmAg-6C.js → requirementDiagram-Y7LWUY3S-Cq8rRz2y.js} +1 -1
  627. package/dist/public/assets/{resolver-0zC31mg5.js → resolver-BPuspqws.js} +1 -1
  628. package/dist/public/assets/{sankeyDiagram-WGJFYUXA-Bl5IpDk4.js → sankeyDiagram-WGJFYUXA-aK7jRBVK.js} +1 -1
  629. package/dist/public/assets/{sequenceDiagram-5NDRBG5M-Z-N0OiT_.js → sequenceDiagram-5NDRBG5M-BxcIyc38.js} +1 -1
  630. package/dist/public/assets/{stateDiagram-v2-FJ4FJNEA-ctKQz8Mo.js → stateDiagram-v2-FJ4FJNEA-Ctletlj4.js} +1 -1
  631. package/dist/public/assets/{swimlanes-UMQ2AFYF-CWLKnALg.js → swimlanes-UMQ2AFYF-DaD55xd2.js} +1 -1
  632. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CytCT4x3.js +8 -0
  633. package/dist/public/assets/{timeline-definition-SEUHKTQE-DP8Ph_d6.js → timeline-definition-SEUHKTQE-Ce19CDiJ.js} +1 -1
  634. package/dist/public/assets/treeView-D4JQ5SDB-DvzNkX4G.js +1 -0
  635. package/dist/public/assets/treemap-SAJKECNS-BuUeBmMd.js +1 -0
  636. package/dist/public/assets/{typescript-CGpNlLbn.js → typescript-RgyfxmPQ.js} +1 -1
  637. package/dist/public/assets/{usecaseDiagram-AFA6YXN4-DvFjNj3J.js → usecaseDiagram-AFA6YXN4-CAVEBKQS.js} +1 -1
  638. package/dist/public/assets/{vennDiagram-NNMJR3RB-3m2F2H-I.js → vennDiagram-NNMJR3RB-DHyJxlHv.js} +1 -1
  639. package/dist/public/assets/wardley-7MLQ67FV-DSfdKACG.js +1 -0
  640. package/dist/public/assets/{wardleyDiagram-S7YFUSEH-CsMntu16.js → wardleyDiagram-S7YFUSEH-C-FCHxR7.js} +1 -1
  641. package/dist/public/assets/{xml-ByiLoakX.js → xml-DiA1T3iN.js} +1 -1
  642. package/dist/public/assets/{xychartDiagram-GGNKY7IX-C80rxvM0.js → xychartDiagram-GGNKY7IX-BlnHU6Gz.js} +1 -1
  643. package/dist/public/assets/{yaml-Cz2Af5Rj.js → yaml-dnCcfJBR.js} +1 -1
  644. package/dist/public/ext/index.json +1 -0
  645. package/dist/public/ext/ta-3d.js +660 -0
  646. package/dist/public/ext/ta-glance.js +1611 -0
  647. package/dist/public/ext/ta-plot.js +1320 -0
  648. package/dist/public/index.html +2 -2
  649. package/dist/serve/index.mjs +17829 -14233
  650. package/package.json +45 -39
  651. package/dist/public/assets/cynefin-EF2NZ3EQ-yFytgtiy.js +0 -1
  652. package/dist/public/assets/flowDiagram-MALGAFMO-Cwye_DsX.js +0 -1
  653. package/dist/public/assets/gitGraph-VSP46ZUC-BYzb--zb.js +0 -1
  654. package/dist/public/assets/info-OHQRW6UA-na0qX3JP.js +0 -1
  655. package/dist/public/assets/module-B3SKdB70.js +0 -1
  656. package/dist/public/assets/module-DDH-aU6z.js +0 -1
  657. package/dist/public/assets/module-DOrYVZ7B.js +0 -2615
  658. package/dist/public/assets/module-DRofmFJn.js +0 -1
  659. package/dist/public/assets/module-MaD4hvv4.js +0 -1
  660. package/dist/public/assets/module-ZDJutm0b.js +0 -1
  661. package/dist/public/assets/module-qoBVcE5h.js +0 -1
  662. package/dist/public/assets/packet-JDAUHWVQ-jhCd70vR.js +0 -1
  663. package/dist/public/assets/pie-XZMESJXO-DV0NJFsI.js +0 -1
  664. package/dist/public/assets/radar-ABXABTNO-Co-Hlf34.js +0 -1
  665. package/dist/public/assets/railroad-I3PHUGI6-DKMPEjDD.js +0 -1
  666. package/dist/public/assets/swimlanesDiagram-OMPLPG4O-CU76xJSu.js +0 -8
  667. package/dist/public/assets/treeView-D4JQ5SDB-JMMnu_MW.js +0 -1
  668. package/dist/public/assets/treemap-SAJKECNS-CPlAD3X1.js +0 -1
  669. package/dist/public/assets/wardley-7MLQ67FV-Dhc8wpLp.js +0 -1
@@ -1,9 +1,3 @@
1
- // ../ta-protocol/esm/common/access-protocol.js
2
- var TaAccessServer = Symbol("TaAccessServer");
3
- // ../ta-protocol/esm/common/auth-protocol.js
4
- var TaAuthServer = Symbol("TaAuthServer");
5
- // ../ta-protocol/esm/common/gateway-protocol.js
6
- var TaGatewayServer = Symbol("TaGatewayServer");
7
1
  // ../ta-protocol/esm/common/language.js
8
2
  var TaLanguageUtil;
9
3
  (function(TaLanguageUtil2) {
@@ -42,468 +36,954 @@ var TaLanguageUtil;
42
36
  }
43
37
  TaLanguageUtil2.list = list;
44
38
  })(TaLanguageUtil || (TaLanguageUtil = {}));
45
- // ../ta-protocol/esm/common/location.js
46
- var TaLocation;
47
- (function(TaLocation2) {
48
- TaLocation2.SSH = "ssh://";
49
- const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
50
- function isRemote(location) {
51
- return location.startsWith(TaLocation2.SSH);
39
+
40
+ // ../ta-protocol/esm/common/team-protocol.js
41
+ var TA_OWNER = "owner";
42
+ var TA_UNDECLARED = "extensions.install";
43
+ var TaPermissionUtil;
44
+ (function(TaPermissionUtil2) {
45
+ function read(pi) {
46
+ const given = pi === null || pi === undefined ? undefined : pi.permissions;
47
+ const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
48
+ const host2 = map(given === null || given === undefined ? undefined : given.host);
49
+ const tools = map(given === null || given === undefined ? undefined : given.tools);
50
+ return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
52
51
  }
53
- TaLocation2.isRemote = isRemote;
54
- function parse(location) {
55
- if (!isRemote(location)) {
56
- return;
57
- }
58
- const rest = location.slice(TaLocation2.SSH.length);
59
- const slash = rest.indexOf("/");
60
- const host2 = slash < 0 ? rest : rest.slice(0, slash);
61
- const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
62
- if (!isHost(host2)) {
63
- throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
52
+ TaPermissionUtil2.read = read;
53
+ function host(manifest, method, kind) {
54
+ var _a, _b, _c, _d;
55
+ const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
56
+ const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
57
+ return (_d = (_c = (_b = kind ? own(`${method}:${kind}`) : undefined) !== null && _b !== undefined ? _b : own(method)) !== null && _c !== undefined ? _c : own("*")) !== null && _d !== undefined ? _d : TA_UNDECLARED;
58
+ }
59
+ TaPermissionUtil2.host = host;
60
+ })(TaPermissionUtil || (TaPermissionUtil = {}));
61
+ var action = (id, en, zh, tw, ja, more = {}) => ({
62
+ id,
63
+ area: id.split(".")[0],
64
+ title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
65
+ ...more
66
+ });
67
+ var TA_ACTIONS = [
68
+ action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
69
+ action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
70
+ action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
71
+ action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
72
+ action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
73
+ action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
74
+ action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
75
+ action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
76
+ action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
77
+ action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
78
+ action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
79
+ action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
80
+ action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
81
+ action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
82
+ action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
83
+ action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
84
+ action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
85
+ action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
86
+ action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
87
+ action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
88
+ action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
89
+ action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更"),
90
+ action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
91
+ action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
92
+ action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
93
+ action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
94
+ action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
95
+ action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
96
+ action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
97
+ action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
98
+ action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
99
+ action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
100
+ action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
101
+ ];
102
+ var TaActionUtil;
103
+ (function(TaActionUtil2) {
104
+ const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
105
+ function info(id) {
106
+ return byId.get(id);
107
+ }
108
+ TaActionUtil2.info = info;
109
+ function title(id, language) {
110
+ var _a;
111
+ var _b, _c;
112
+ const title2 = (_a = byId.get(id)) === null || _a === undefined ? undefined : _a.title;
113
+ if (!title2) {
114
+ return id;
64
115
  }
65
- return { host: host2, path: path2 };
116
+ return TaLanguageUtil.pick(language, {
117
+ "zh-CN": title2["zh-CN"],
118
+ "zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
119
+ "en-US": title2.en,
120
+ "ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
121
+ });
66
122
  }
67
- TaLocation2.parse = parse;
68
- function isHost(host2) {
69
- return HOST.test(host2);
123
+ TaActionUtil2.title = title;
124
+ function inside(dir, path) {
125
+ const base = dir.replace(/\/+$/, "");
126
+ return path === base || path.startsWith(`${base}/`) || base === "";
70
127
  }
71
- TaLocation2.isHost = isHost;
72
- const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
73
- function readHost(input) {
74
- const words = input.trim().split(/\s+/).filter(Boolean);
75
- if (words[0] === "ssh") {
76
- words.shift();
128
+ TaActionUtil2.inside = inside;
129
+ })(TaActionUtil || (TaActionUtil = {}));
130
+
131
+ // ../ta-protocol/esm/common/redactor.js
132
+ var REDACTED = "[redacted]";
133
+ var WHOLE = [
134
+ ["PRIVATE_KEY", /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g],
135
+ ["API_KEY", /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g],
136
+ ["GITHUB_TOKEN", /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g],
137
+ ["GITHUB_TOKEN", /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g],
138
+ ["GITLAB_TOKEN", /\bglpat-[A-Za-z0-9_-]{20,}\b/g],
139
+ ["SLACK_TOKEN", /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g],
140
+ ["AWS_ACCESS_KEY_ID", /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g],
141
+ ["GOOGLE_API_KEY", /\bAIza[0-9A-Za-z_-]{35}\b/g],
142
+ ["JWT", /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g]
143
+ ];
144
+ var NAMED = [
145
+ /(\bBearer\s+)[A-Za-z0-9._~+/-]{16,}=*/gi,
146
+ /(\b[A-Za-z0-9_.-]*(?:password|passwd|pwd|secret|token|api[_-]?key|access[_-]?key|private[_-]?key)[A-Za-z0-9_.-]*["']?\s*[:=]\s*["']?)([^\s"'`,;]{6,})/gi,
147
+ /(:\/\/[^\s:/@]+:)([^\s@/]{3,})(@)/g
148
+ ];
149
+
150
+ class Redactor {
151
+ constructor() {
152
+ this.count = 0;
153
+ }
154
+ text(text) {
155
+ let out = text;
156
+ for (const [, pattern] of WHOLE) {
157
+ out = out.replace(pattern, () => this.hide());
77
158
  }
78
- let destination;
79
- let port;
80
- let user;
81
- const options = [];
82
- for (let i = 0;i < words.length; i++) {
83
- const word = words[i];
84
- const glued = /^-([pl])(.+)$/.exec(word);
85
- if (word === "-p" || word === "-l" || glued) {
86
- const value = glued ? glued[2] : words[++i];
87
- if (value === undefined) {
88
- return { error: "invalid" };
89
- }
90
- if ((glued ? glued[1] : word[1]) === "p") {
91
- port = value;
92
- } else {
93
- user = value;
94
- }
95
- } else if (word === "-o" || word.startsWith("-o")) {
96
- const value = word === "-o" ? words[++i] : word.slice(2);
97
- const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
98
- if (!option) {
99
- options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
100
- } else if (option[1].toLowerCase() === "port") {
101
- port = option[2];
102
- } else {
103
- user = option[2];
104
- }
105
- } else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
106
- options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
107
- } else if (destination === undefined) {
108
- destination = word;
109
- } else {
110
- return { error: "invalid" };
159
+ out = out.replace(NAMED[0], (_match, before) => before + this.hide());
160
+ out = out.replace(NAMED[1], (match, before, value) => Redactor.placeholder(value) ? match : before + this.hide());
161
+ out = out.replace(NAMED[2], (_match, before, _value, after) => before + this.hide() + after);
162
+ return out;
163
+ }
164
+ value(value, max) {
165
+ if (typeof value === "string") {
166
+ return Redactor.cut(this.text(value), max);
167
+ }
168
+ if (Array.isArray(value)) {
169
+ return value.map((item) => this.value(item, max));
170
+ }
171
+ if (value && typeof value === "object") {
172
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, this.value(item, max)]));
173
+ }
174
+ return value;
175
+ }
176
+ static spans(text) {
177
+ var _a;
178
+ var _b;
179
+ const found = [];
180
+ for (const [kind, pattern] of WHOLE) {
181
+ for (const match of text.matchAll(pattern)) {
182
+ found.push({ start: match.index, end: match.index + match[0].length, kind });
111
183
  }
112
184
  }
113
- if (options.length > 0) {
114
- return { error: "options", options };
185
+ for (const match of text.matchAll(NAMED[0])) {
186
+ found.push({ start: match.index + match[1].length, end: match.index + match[0].length, kind: "BEARER_TOKEN" });
115
187
  }
116
- if (!destination) {
117
- return { error: "empty" };
188
+ for (const match of text.matchAll(NAMED[1])) {
189
+ if (!Redactor.placeholder(match[2])) {
190
+ const start = match.index + match[1].length;
191
+ const name = (_b = (_a = /[A-Za-z0-9_.-]+/.exec(match[1])) === null || _a === undefined ? undefined : _a[0]) !== null && _b !== undefined ? _b : "SECRET";
192
+ found.push({ start, end: start + match[2].length, kind: name.replace(/[^A-Za-z0-9]+/g, "_").toUpperCase() });
193
+ }
118
194
  }
119
- let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
120
- if (user && !host2.includes("@")) {
121
- host2 = `${user}@${host2}`;
195
+ for (const match of text.matchAll(NAMED[2])) {
196
+ const start = match.index + match[1].length;
197
+ found.push({ start, end: start + match[2].length, kind: "URL_PASSWORD" });
122
198
  }
123
- if (port) {
124
- if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
125
- return { error: "invalid" };
199
+ found.sort((a, b) => a.start - b.start || b.end - a.end);
200
+ const spans = [];
201
+ for (const span of found) {
202
+ const last = spans.at(-1);
203
+ if (!last || span.start >= last.end) {
204
+ spans.push(span);
126
205
  }
127
- host2 = port === "22" ? host2 : `${host2}:${port}`;
128
206
  }
129
- return isHost(host2) ? { host: host2 } : { error: "invalid" };
130
- }
131
- TaLocation2.readHost = readHost;
132
- function ssh(host2, path2 = "") {
133
- return `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
207
+ return spans;
134
208
  }
135
- TaLocation2.ssh = ssh;
136
- function hostLabel(host2) {
137
- const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
138
- return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
209
+ static cut(text, max) {
210
+ return text.length > max ? `${text.slice(0, max)}…` : text;
139
211
  }
140
- TaLocation2.hostLabel = hostLabel;
141
- function host(location) {
142
- var _a;
143
- return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
212
+ hide() {
213
+ this.count++;
214
+ return REDACTED;
144
215
  }
145
- TaLocation2.host = host;
146
- function path(location) {
147
- var _a;
148
- var _b;
149
- return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
216
+ static placeholder(value) {
217
+ return /^(?:\$|<|\{|\[redacted|process\.env|os\.environ|xxx|\*{3})/i.test(value) || /^(?:true|false|null|undefined|none|string|number)$/i.test(value);
150
218
  }
151
- TaLocation2.path = path;
152
- function parent(location) {
153
- const remote = parse(location);
154
- if (remote) {
155
- const above = remote.path ? parentPath(remote.path) : undefined;
156
- return above === undefined ? undefined : ssh(remote.host, above);
219
+ }
220
+
221
+ // ../ta-relay/esm/common/relay-card.js
222
+ var RELAY_AGENT_KIND = "ta-agent";
223
+ var RelayAgentCards;
224
+ (function(RelayAgentCards2) {
225
+ const MAX_ROLE = 8000;
226
+ function parse(data) {
227
+ try {
228
+ const card = JSON.parse(typeof data === "string" ? data : new TextDecoder().decode(data));
229
+ if ((card === null || card === undefined ? undefined : card.v) !== 1 || typeof card.name !== "string" || !card.name.trim() || typeof card.role !== "string" || !card.role.trim()) {
230
+ return;
231
+ }
232
+ const color = typeof card.color === "string" && /^#[0-9a-fA-F]{6}$/.test(card.color) ? card.color : undefined;
233
+ return {
234
+ v: 1,
235
+ name: card.name.trim().slice(0, 32),
236
+ role: card.role.trim().slice(0, MAX_ROLE),
237
+ mark: typeof card.mark === "string" && card.mark.trim() ? card.mark.trim().slice(0, 2) : card.name.trim().slice(0, 1).toUpperCase(),
238
+ ...Number.isInteger(card.face) ? { face: card.face } : {},
239
+ ...color ? { color } : {},
240
+ ...typeof card.redacted === "number" && card.redacted > 0 ? { redacted: card.redacted } : {}
241
+ };
242
+ } catch (_a) {
243
+ return;
157
244
  }
158
- return parentPath(location);
159
245
  }
160
- TaLocation2.parent = parent;
161
- function child(location, name) {
162
- const remote = parse(location);
163
- if (remote) {
164
- return ssh(remote.host, childPath(remote.path || "/", name));
165
- }
166
- return childPath(location, name);
246
+ RelayAgentCards2.parse = parse;
247
+ })(RelayAgentCards || (RelayAgentCards = {}));
248
+
249
+ // web-src/channels-model.ts
250
+ var NAME = "@celljs/ta-channels";
251
+ var AGENT_MARK = "one of the agents of Ta";
252
+ var MEMBER_CHANGES = ["lead", "remove", "mute", "unmute"];
253
+ var Keys;
254
+ ((Keys) => {
255
+ Keys.TEAM = "team";
256
+ Keys.QUEUE = "queue";
257
+ Keys.WORKING = "working";
258
+ Keys.FOCUS = "focus";
259
+ Keys.ANSWERED = "answered";
260
+ Keys.CARDS = "cards";
261
+ Keys.MESSAGES = "messages/";
262
+ Keys.messages = (channelId) => `${Keys.MESSAGES}${channelId}`;
263
+ })(Keys ||= {});
264
+ var USER = "user";
265
+ var TA = "ta";
266
+ var SYSTEM = "system";
267
+ var MAX_HOPS = 3;
268
+ var MAX_REPLIES = 8;
269
+ var MAX_AGENT_REPLIES = 2;
270
+ var STOP_NOTE = "The agents stopped handing on here, at the limit of a round; it is your turn.";
271
+ var MAX_MESSAGES = 200;
272
+ var FACES = 16;
273
+ var MAX_MEMBERS = 12;
274
+ var CONTEXT_MESSAGES = 12;
275
+ var MAX_NAME = 32;
276
+ var MAX_NOTICE = 2000;
277
+ var NOTICE_HEADINGS = { zh: ["决定", "约定", "待办"], en: ["Decisions", "Conventions", "To do"] };
278
+ var CARD_DAYS = 30;
279
+
280
+ // web-src/channels-util.ts
281
+ var ChannelsUtil;
282
+ ((ChannelsUtil) => {
283
+ function newRound() {
284
+ return { total: 0, byAgent: {}, stopped: false };
167
285
  }
168
- TaLocation2.child = child;
169
- function basename(location) {
170
- const remote = parse(location);
171
- const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
172
- const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
173
- return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
286
+ ChannelsUtil.newRound = newRound;
287
+ function limit(round, targets, hops) {
288
+ const allowed = [];
289
+ const byAgent = { ...round.byAgent };
290
+ let total = round.total;
291
+ for (const id of targets) {
292
+ if (hops < MAX_HOPS && total < MAX_REPLIES && (byAgent[id] ?? 0) < MAX_AGENT_REPLIES) {
293
+ allowed.push(id);
294
+ byAgent[id] = (byAgent[id] ?? 0) + 1;
295
+ total++;
296
+ }
297
+ }
298
+ const cut = allowed.length < targets.length;
299
+ const note = cut && !round.stopped;
300
+ return { allowed, round: { total, byAgent, stopped: round.stopped || cut }, cut, note };
174
301
  }
175
- TaLocation2.basename = basename;
176
- function homeRelative(location) {
177
- var _a;
178
- const remote = parse(location);
179
- const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
180
- const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
181
- return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
302
+ ChannelsUtil.limit = limit;
303
+ function emptyTeam() {
304
+ return { agents: [], channels: [] };
182
305
  }
183
- TaLocation2.homeRelative = homeRelative;
184
- function isAbsolute(location) {
185
- if (homeRelative(location) !== undefined) {
186
- return false;
306
+ ChannelsUtil.emptyTeam = emptyTeam;
307
+ function newId(prefix) {
308
+ return `${prefix}-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
309
+ }
310
+ ChannelsUtil.newId = newId;
311
+ function checkName(value, what) {
312
+ const name = typeof value === "string" ? value.trim().replace(/^[@#]+/, "").replace(/\s+/g, "-") : "";
313
+ if (!name || name.length > MAX_NAME || /[@#,]/.test(name)) {
314
+ throw new Error(`The name of the ${what} must be 1 to ${MAX_NAME} characters, without @, # or commas.`);
315
+ }
316
+ return name;
317
+ }
318
+ ChannelsUtil.checkName = checkName;
319
+ function mark(name) {
320
+ const first = Array.from(name)[0] ?? "?";
321
+ if (!/[A-Za-z0-9]/.test(first)) {
322
+ return first;
323
+ }
324
+ const words = name.split(/[-_.\s]+|(?<=[a-z])(?=[A-Z])/).filter(Boolean);
325
+ return words.length > 1 ? (words[0][0] + words[1][0]).toUpperCase() : first.toUpperCase();
326
+ }
327
+ ChannelsUtil.mark = mark;
328
+ function faces(agents) {
329
+ const result = new Map;
330
+ const taken = new Set;
331
+ for (const agent of agents) {
332
+ if (isFace(agent.face)) {
333
+ result.set(agent.id, agent.face);
334
+ taken.add(agent.face);
335
+ }
336
+ }
337
+ for (const agent of agents) {
338
+ if (!result.has(agent.id)) {
339
+ const face = freeFace(hash(agent.id), taken);
340
+ result.set(agent.id, face);
341
+ taken.add(face);
342
+ }
343
+ }
344
+ return result;
345
+ }
346
+ ChannelsUtil.faces = faces;
347
+ function isFace(face) {
348
+ return typeof face === "number" && Number.isInteger(face) && face >= 0 && face < FACES;
349
+ }
350
+ ChannelsUtil.isFace = isFace;
351
+ function freeFaceFor(agents, seed) {
352
+ return freeFace(hash(seed), new Set(faces(agents).values()));
353
+ }
354
+ ChannelsUtil.freeFaceFor = freeFaceFor;
355
+ function freeName(team, base) {
356
+ let name = base;
357
+ for (let count = 2;findAgent(team, name); count++) {
358
+ name = `${base}-${count}`;
359
+ }
360
+ return name;
361
+ }
362
+ ChannelsUtil.freeName = freeName;
363
+ function freeFace(start, taken) {
364
+ for (let step = 0;step < FACES; step++) {
365
+ const face = (start + step) % FACES;
366
+ if (!taken.has(face)) {
367
+ return face;
368
+ }
369
+ }
370
+ return start % FACES;
371
+ }
372
+ function hash(text) {
373
+ let value = 2166136261;
374
+ for (let index = 0;index < text.length; index++) {
375
+ value = Math.imul(value ^ text.charCodeAt(index), 16777619);
376
+ }
377
+ return value >>> 0;
378
+ }
379
+ ChannelsUtil.hash = hash;
380
+ function findAgent(team, ref) {
381
+ const key = ref.trim().replace(/^@/, "").toLowerCase();
382
+ return team.agents.find((agent) => agent.id === ref) ?? team.agents.find((agent) => agent.name.toLowerCase() === key);
383
+ }
384
+ ChannelsUtil.findAgent = findAgent;
385
+ function findChannel(team, ref) {
386
+ const key = ref.trim().replace(/^#/, "").toLowerCase();
387
+ return team.channels.find((channel) => channel.id === ref) ?? team.channels.find((channel) => channel.name.toLowerCase() === key);
388
+ }
389
+ ChannelsUtil.findChannel = findChannel;
390
+ function directory(value) {
391
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
392
+ }
393
+ ChannelsUtil.directory = directory;
394
+ function addAgent(team, input) {
395
+ const name = checkName(input.name, "agent");
396
+ if (findAgent(team, name)) {
397
+ throw new Error(`There is an agent named ${name} already.`);
398
+ }
399
+ const role = typeof input.role === "string" ? input.role.trim() : "";
400
+ if (!role) {
401
+ throw new Error(`Say what ${name} does: its role.`);
402
+ }
403
+ const cwd = directory(input.cwd);
404
+ const id = newId("agent");
405
+ const face = isFace(input.face) ? input.face : freeFace(hash(id), new Set(faces(team.agents).values()));
406
+ const agent = { id, name, role, mark: mark(name), face, cwd, ...input.temporary ? { temporary: true } : {}, createdAt: Date.now() };
407
+ return { team: { ...team, agents: [...team.agents, agent] }, agent };
408
+ }
409
+ ChannelsUtil.addAgent = addAgent;
410
+ function addChannel(team, input) {
411
+ const name = checkName(input.name, "channel");
412
+ if (findChannel(team, name)) {
413
+ throw new Error(`There is a channel named ${name} already.`);
414
+ }
415
+ const members = agentIds(team, input.members);
416
+ if (members.length === 0) {
417
+ throw new Error("A channel needs at least one agent.");
418
+ }
419
+ if (members.length > MAX_MEMBERS) {
420
+ throw new Error(`A channel holds at most ${MAX_MEMBERS} agents.`);
421
+ }
422
+ const topic = typeof input.topic === "string" && input.topic.trim() ? input.topic.trim() : undefined;
423
+ const channel = {
424
+ id: newId("channel"),
425
+ name,
426
+ topic,
427
+ members,
428
+ ...input.by ? { by: input.by } : {},
429
+ ...input.origin ? { origin: input.origin } : {},
430
+ createdAt: Date.now()
431
+ };
432
+ return { team: { ...team, channels: [...team.channels, channel] }, channel };
433
+ }
434
+ ChannelsUtil.addChannel = addChannel;
435
+ function addMembers(team, input) {
436
+ const found = channelOf(team, input.channel);
437
+ const ids = agentIds(team, input.members);
438
+ if (ids.length === 0) {
439
+ throw new Error("Name at least one agent to add.");
440
+ }
441
+ const added = ids.filter((id) => !found.members.includes(id)).map((id) => team.agents.find((agent) => agent.id === id));
442
+ if (found.members.length + added.length > MAX_MEMBERS) {
443
+ throw new Error(`A channel holds at most ${MAX_MEMBERS} agents; #${found.name} has ${found.members.length}.`);
444
+ }
445
+ const channel = { ...found, members: [...found.members, ...added.map((agent) => agent.id)] };
446
+ return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, added };
447
+ }
448
+ ChannelsUtil.addMembers = addMembers;
449
+ function channelOf(team, ref) {
450
+ const key = typeof ref === "string" ? ref : "";
451
+ const found = findChannel(team, key);
452
+ if (!found) {
453
+ const known = team.channels.map((other) => `#${other.name}`).join(", ") || "none yet";
454
+ throw new Error(`No channel is named ${key}. The channels: ${known}.`);
455
+ }
456
+ return found;
457
+ }
458
+ ChannelsUtil.channelOf = channelOf;
459
+ function changeMember(team, input) {
460
+ const found = channelOf(team, input.channel);
461
+ const agent = findAgent(team, typeof input.agent === "string" ? input.agent : "");
462
+ if (!agent || !found.members.includes(agent.id)) {
463
+ throw new Error(`${agent?.name ?? String(input.agent)} is not a member of #${found.name}.`);
464
+ }
465
+ if (typeof input.change !== "string" || !MEMBER_CHANGES.includes(input.change)) {
466
+ throw new Error(`A member is changed with one of ${MEMBER_CHANGES.join(", ")}.`);
467
+ }
468
+ const others = found.members.filter((id) => id !== agent.id);
469
+ const muted = (found.muted ?? []).filter((id) => id !== agent.id);
470
+ let channel;
471
+ switch (input.change) {
472
+ case "lead":
473
+ channel = { ...found, members: [agent.id, ...others] };
474
+ break;
475
+ case "remove":
476
+ if (others.length === 0) {
477
+ throw new Error(`${agent.name} is the only member of #${found.name}: delete the channel instead.`);
478
+ }
479
+ channel = { ...found, members: others, muted };
480
+ break;
481
+ case "mute":
482
+ channel = { ...found, muted: [...muted, agent.id] };
483
+ break;
484
+ default:
485
+ channel = { ...found, muted };
486
+ }
487
+ if (channel.muted?.length === 0) {
488
+ delete channel.muted;
489
+ }
490
+ return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel };
491
+ }
492
+ ChannelsUtil.changeMember = changeMember;
493
+ function updateChannel(team, input) {
494
+ const before = channelOf(team, input.channel);
495
+ const channel = { ...before };
496
+ if (input.name !== undefined) {
497
+ const name = checkName(input.name, "channel");
498
+ const other = findChannel(team, name);
499
+ if (other && other.id !== channel.id) {
500
+ throw new Error(`There is a channel named ${name} already.`);
501
+ }
502
+ channel.name = name;
503
+ }
504
+ if (input.topic !== undefined) {
505
+ const topic = typeof input.topic === "string" ? input.topic.trim() : "";
506
+ if (topic) {
507
+ channel.topic = topic;
508
+ } else {
509
+ delete channel.topic;
510
+ }
511
+ }
512
+ if (input.pinned !== undefined) {
513
+ if (input.pinned === true) {
514
+ channel.pinned = true;
515
+ } else {
516
+ delete channel.pinned;
517
+ }
518
+ }
519
+ return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before };
520
+ }
521
+ ChannelsUtil.updateChannel = updateChannel;
522
+ function standing(team) {
523
+ const inChannel = new Set(team.channels.flatMap((channel) => channel.members));
524
+ return team.agents.filter((agent) => !agent.temporary || !inChannel.has(agent.id));
525
+ }
526
+ ChannelsUtil.standing = standing;
527
+ function taskChannels(team) {
528
+ return team.channels.filter((channel) => channel.by === "ta");
529
+ }
530
+ ChannelsUtil.taskChannels = taskChannels;
531
+ function ownChannels(team) {
532
+ return team.channels.filter((channel) => channel.by !== "ta");
533
+ }
534
+ ChannelsUtil.ownChannels = ownChannels;
535
+ function pinnedFirst(items) {
536
+ return [...items.filter((item) => item.pinned), ...items.filter((item) => !item.pinned)];
537
+ }
538
+ ChannelsUtil.pinnedFirst = pinnedFirst;
539
+ function removeChannel(team, ref) {
540
+ const channel = channelOf(team, ref);
541
+ return { team: { ...team, channels: team.channels.filter((other) => other.id !== channel.id) }, channel };
542
+ }
543
+ ChannelsUtil.removeChannel = removeChannel;
544
+ function resetAgent(team, ref) {
545
+ const found = findAgent(team, typeof ref === "string" ? ref : "");
546
+ if (!found) {
547
+ throw new Error(`No agent is ${String(ref)}.`);
548
+ }
549
+ const { sessionFile: _gone, ...agent } = found;
550
+ return { team: { ...team, agents: team.agents.map((other) => other.id === agent.id ? agent : other) }, agent };
551
+ }
552
+ ChannelsUtil.resetAgent = resetAgent;
553
+ function updateAgent(team, input) {
554
+ const before = findAgent(team, typeof input.agent === "string" ? input.agent : "");
555
+ if (!before) {
556
+ throw new Error(`No agent is ${String(input.agent)}.`);
557
+ }
558
+ const agent = { ...before };
559
+ if (input.name !== undefined) {
560
+ const name = checkName(input.name, "agent");
561
+ const other = findAgent(team, name);
562
+ if (other && other.id !== agent.id) {
563
+ throw new Error(`There is an agent named ${name} already.`);
564
+ }
565
+ agent.name = name;
566
+ agent.mark = mark(name);
567
+ }
568
+ if (input.role !== undefined) {
569
+ const role = typeof input.role === "string" ? input.role.trim() : "";
570
+ if (!role) {
571
+ throw new Error(`Say what ${agent.name} does: its role.`);
572
+ }
573
+ agent.role = role;
574
+ }
575
+ if (input.face !== undefined) {
576
+ if (!isFace(input.face)) {
577
+ throw new Error(`A face is a number from 0 to ${FACES - 1}.`);
578
+ }
579
+ agent.face = input.face;
580
+ }
581
+ if (input.keep === true) {
582
+ delete agent.temporary;
583
+ }
584
+ if (input.pinned === true) {
585
+ agent.pinned = true;
586
+ } else if (input.pinned !== undefined) {
587
+ delete agent.pinned;
588
+ }
589
+ if (input.cwd !== undefined) {
590
+ const cwd = typeof input.cwd === "string" && input.cwd.trim() ? input.cwd.trim() : undefined;
591
+ if (cwd !== before.cwd) {
592
+ agent.cwd = cwd;
593
+ delete agent.sessionFile;
594
+ }
595
+ if (!cwd) {
596
+ delete agent.cwd;
597
+ }
598
+ }
599
+ return { team: { ...team, agents: team.agents.map((other) => other.id === agent.id ? agent : other) }, agent, before };
600
+ }
601
+ ChannelsUtil.updateAgent = updateAgent;
602
+ function removeAgent(team, ref) {
603
+ const agent = findAgent(team, typeof ref === "string" ? ref : "");
604
+ if (!agent) {
605
+ throw new Error(`No agent is ${String(ref)}.`);
606
+ }
607
+ const gone = [];
608
+ const channels = [];
609
+ for (const channel of team.channels) {
610
+ if (!channel.members.includes(agent.id)) {
611
+ channels.push(channel);
612
+ continue;
613
+ }
614
+ const members = channel.members.filter((id) => id !== agent.id);
615
+ if (members.length === 0) {
616
+ gone.push(channel);
617
+ continue;
618
+ }
619
+ const muted = channel.muted?.filter((id) => id !== agent.id);
620
+ const next = { ...channel, members, muted };
621
+ if (!muted?.length) {
622
+ delete next.muted;
623
+ }
624
+ channels.push(next);
625
+ }
626
+ return { team: { agents: team.agents.filter((other) => other.id !== agent.id), channels }, agent, channels: gone };
627
+ }
628
+ ChannelsUtil.removeAgent = removeAgent;
629
+ function agentIds(team, refs) {
630
+ const ids = [];
631
+ for (const ref of Array.isArray(refs) ? refs.filter((item) => typeof item === "string") : []) {
632
+ const agent = findAgent(team, ref);
633
+ if (!agent) {
634
+ const known = team.agents.map((other) => other.name).join(", ") || "none yet";
635
+ throw new Error(`No agent is named ${ref}. The agents: ${known}.`);
636
+ }
637
+ if (!ids.includes(agent.id)) {
638
+ ids.push(agent.id);
639
+ }
187
640
  }
188
- return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
641
+ return ids;
189
642
  }
190
- TaLocation2.isAbsolute = isAbsolute;
191
- function parentPath(path2) {
192
- const trimmed = path2.replace(/[\\/]+$/, "");
193
- const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
194
- if (at < 0) {
195
- return;
643
+ function setNotice(team, input) {
644
+ const before = channelOf(team, input.channel);
645
+ const text = typeof input.text === "string" ? input.text.replace(/\r\n/g, `
646
+ `).trim() : "";
647
+ if (text.length > MAX_NOTICE) {
648
+ throw new Error(`The notice is too long (${text.length} characters, ${MAX_NOTICE} at most): keep it short, and drop to-dos done long ago.`);
196
649
  }
197
- const head = trimmed.slice(0, at);
198
- return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
199
- }
200
- function childPath(path2, name) {
201
- const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
202
- return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
650
+ if (text === (before.notice?.text ?? "")) {
651
+ return { team, channel: before, before, changed: false };
652
+ }
653
+ const channel = { ...before };
654
+ if (text) {
655
+ channel.notice = { text, at: input.at ?? Date.now(), by: input.by };
656
+ } else {
657
+ delete channel.notice;
658
+ }
659
+ return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before, changed: true };
203
660
  }
204
- function normalize(path2) {
205
- const squeezed = `/${path2}`.replace(/\/+/g, "/");
206
- return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
661
+ ChannelsUtil.setNotice = setNotice;
662
+ function append(messages, message) {
663
+ const next = [...messages, message];
664
+ return next.length > MAX_MESSAGES ? next.slice(next.length - MAX_MESSAGES) : next;
207
665
  }
208
- })(TaLocation || (TaLocation = {}));
209
- // ../ta-protocol/esm/common/package-protocol.js
210
- var TaPackageServer = Symbol("TaPackageServer");
211
- var TaPackageTextUtil;
212
- (function(TaPackageTextUtil2) {
213
- function pick(text, language) {
214
- var _a, _b, _c, _d, _e;
215
- if (text === undefined || typeof text === "string") {
216
- return text;
217
- }
218
- const base = language.split("-")[0];
219
- const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
220
- return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[base]) !== null && _b !== undefined ? _b : kin === undefined ? undefined : text[kin]) !== null && _c !== undefined ? _c : text.en) !== null && _d !== undefined ? _d : text["en-US"]) !== null && _e !== undefined ? _e : Object.values(text)[0];
666
+ ChannelsUtil.append = append;
667
+ })(ChannelsUtil ||= {});
668
+
669
+ // web-src/agent-cards.ts
670
+ var AgentCards;
671
+ ((AgentCards) => {
672
+ AgentCards.KIND = RELAY_AGENT_KIND;
673
+ AgentCards.MARK = "[ta-channels:card]";
674
+ function card(agent, color) {
675
+ const redactor = new Redactor;
676
+ const role = redactor.text(agent.role);
677
+ return {
678
+ v: 1,
679
+ name: agent.name,
680
+ role,
681
+ mark: agent.mark,
682
+ ...agent.face !== undefined ? { face: agent.face } : {},
683
+ ...color && /^#[0-9a-fA-F]{6}$/.test(color) ? { color } : {},
684
+ ...redactor.count ? { redacted: redactor.count } : {}
685
+ };
221
686
  }
222
- TaPackageTextUtil2.pick = pick;
223
- })(TaPackageTextUtil || (TaPackageTextUtil = {}));
224
- // ../ta-protocol/esm/common/ta-protocol.js
225
- var TaServer = Symbol("TaServer");
226
- var TaClient = Symbol("TaClient");
227
- var TaErrorCode = {
228
- SESSION_NOT_FOUND: "CELL_TA_SESSION_NOT_FOUND",
229
- SESSION_LOCKED: "CELL_TA_SESSION_LOCKED",
230
- TOO_MANY_SESSIONS: "CELL_TA_TOO_MANY_SESSIONS",
231
- MESSAGE_CONFLICT: "CELL_TA_MESSAGE_CONFLICT",
232
- MODEL_NOT_FOUND: "CELL_TA_MODEL_NOT_FOUND",
233
- INVALID_ARGUMENT: "CELL_TA_INVALID_ARGUMENT",
234
- COMMAND_FAILED: "CELL_TA_COMMAND_FAILED",
235
- NOTHING_TO_COMPACT: "CELL_TA_NOTHING_TO_COMPACT",
236
- ALREADY_COMPACTED: "CELL_TA_ALREADY_COMPACTED",
237
- SESSION_BUSY: "CELL_TA_SESSION_BUSY",
238
- CANCELLED: "CELL_TA_CANCELLED",
239
- NOT_SIGNED_IN: "CELL_TA_NOT_SIGNED_IN",
240
- ENVIRONMENT_FAILED: "CELL_TA_ENVIRONMENT_FAILED",
241
- RATE_LIMITED: "CELL_TA_RATE_LIMITED",
242
- FORBIDDEN: "CELL_TA_FORBIDDEN",
243
- LIMIT: "CELL_TA_LIMIT",
244
- CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
245
- };
246
- var TaErrorUtil;
247
- (function(TaErrorUtil2) {
248
- function code(error) {
249
- var _a;
250
- var _b;
251
- const failure = error;
252
- const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
253
- return typeof code2 === "string" ? code2 : undefined;
687
+ AgentCards.card = card;
688
+ function parse(data) {
689
+ return RelayAgentCards.parse(data);
254
690
  }
255
- TaErrorUtil2.code = code;
256
- })(TaErrorUtil || (TaErrorUtil = {}));
257
- var TaSlashCommandUtil;
258
- (function(TaSlashCommandUtil2) {
259
- function description(command, language) {
260
- var _a, _b;
261
- const { descriptions } = command;
262
- return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
691
+ AgentCards.parse = parse;
692
+ function freeName(team, name) {
693
+ const base = (name.trim().replace(/\s+/g, "-") || "agent").slice(0, MAX_NAME - 3);
694
+ if (!ChannelsUtil.findAgent(team, base)) {
695
+ return base;
696
+ }
697
+ for (let n = 2;; n++) {
698
+ if (!ChannelsUtil.findAgent(team, `${base}-${n}`)) {
699
+ return `${base}-${n}`;
700
+ }
701
+ }
263
702
  }
264
- TaSlashCommandUtil2.description = description;
265
- })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
266
- var TaMessageContext;
267
- (function(TaMessageContext2) {
268
- const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
269
- function wrap(context, message) {
703
+ AgentCards.freeName = freeName;
704
+ function adapt(cwd, language) {
705
+ const context = [
706
+ AgentCards.MARK,
707
+ `You were just added to this Ta from a card someone shared: the role in your instructions is theirs, written for their own work. Fit it to the project of your directory (${cwd}): look at it first (its README, manifests such as package.json, its layout, how it builds and tests), then rewrite your role for it, keeping what you are for, and save it with update_my_role. Then tell the user in a few sentences, in ${TaLanguageUtil.pick(language, { "zh-CN": "Chinese", "zh-TW": "Traditional Chinese", "en-US": "English", "ja-JP": "Japanese" })}, what you changed and what you can do here. Change no files.`
708
+ ].join(`
709
+ `);
270
710
  return `<context>
271
711
  ${context}
272
712
  </context>
273
- ${message}`;
274
- }
275
- TaMessageContext2.wrap = wrap;
276
- function strip(message) {
277
- return message.replace(BLOCK, "");
278
- }
279
- TaMessageContext2.strip = strip;
280
- function read(message) {
281
- var _a;
282
- const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
283
- return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
284
- }
285
- TaMessageContext2.read = read;
286
- })(TaMessageContext || (TaMessageContext = {}));
287
- var TaMessageSource;
288
- (function(TaMessageSource2) {
289
- TaMessageSource2.DOUBLE = "ta:double";
290
- const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
291
- function mark(message, from, detail) {
292
- if (/^[/!]/.test(message) || of(message)) {
293
- return message;
294
- }
295
- const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
296
- const context = TaMessageContext.read(message);
297
- return TaMessageContext.wrap(context === undefined ? line : `${context}
298
- ${line}`, TaMessageContext.strip(message));
299
- }
300
- TaMessageSource2.mark = mark;
301
- function of(message) {
302
- const context = TaMessageContext.read(message);
303
- const match = context === undefined ? null : LINE.exec(context);
304
- return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
713
+ ${TaLanguageUtil.pick(language, { "zh-CN": "看看这个项目,把你的职责调整得贴合这里", "zh-TW": "看看這個專案,把你的職責調整得貼合這裡", "en-US": "Look at this project and fit your role to it", "ja-JP": "このプロジェクトを見て、ロールをそれに適応させてください" })}`;
305
714
  }
306
- TaMessageSource2.of = of;
307
- })(TaMessageSource || (TaMessageSource = {}));
308
- var TaImageNote;
309
- (function(TaImageNote2) {
310
- const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
311
- function strip(text) {
312
- const lines = text.split(`
313
- `);
314
- const kept = lines.filter((line) => !NOTE.test(line.trim()));
315
- if (kept.length === lines.length) {
715
+ AgentCards.adapt = adapt;
716
+ })(AgentCards ||= {});
717
+
718
+ // web-src/channels-text.ts
719
+ var ChannelsText;
720
+ ((ChannelsText) => {
721
+ function markMentions(text, agents) {
722
+ if (agents.length === 0) {
316
723
  return text;
317
724
  }
318
- return kept.join(`
319
- `).replace(/\n+$/, "").replace(/^\n+/, "");
725
+ const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
726
+ const pattern = new RegExp(`(?<![*A-Za-z0-9_])@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
727
+ return text.split(/(```[\s\S]*?(?:```|$)|`[^`\n]*`)/).map((part, index) => index % 2 === 1 ? part : part.replace(pattern, "**$&**")).join("");
320
728
  }
321
- TaImageNote2.strip = strip;
322
- })(TaImageNote || (TaImageNote = {}));
323
- var TaImageSize;
324
- (function(TaImageSize2) {
325
- const JPEG_BYTES = 256 * 1024;
326
- function of(base64) {
327
- var _a, _b, _c;
328
- let bytes;
329
- try {
330
- const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
331
- bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
332
- } catch (_d) {
333
- return;
729
+ ChannelsText.markMentions = markMentions;
730
+ function mentions(text, agents) {
731
+ if (agents.length === 0) {
732
+ return [];
334
733
  }
335
- const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
336
- return size && size.width > 0 && size.height > 0 ? size : undefined;
337
- }
338
- TaImageSize2.of = of;
339
- function u16be(bytes, at) {
340
- return bytes[at] << 8 | bytes[at + 1];
341
- }
342
- function u16le(bytes, at) {
343
- return bytes[at] | bytes[at + 1] << 8;
344
- }
345
- function u24le(bytes, at) {
346
- return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
347
- }
348
- function u32be(bytes, at) {
349
- return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
734
+ const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
735
+ const pattern = new RegExp(`@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
736
+ const found = [];
737
+ for (const match of text.matchAll(pattern)) {
738
+ const agent = agents.find((candidate) => candidate.name.toLowerCase() === match[1].toLowerCase());
739
+ if (agent && !found.includes(agent.id)) {
740
+ found.push(agent.id);
741
+ }
742
+ }
743
+ return found;
350
744
  }
351
- function text(bytes, at, length) {
352
- return String.fromCharCode(...bytes.subarray(at, at + length));
745
+ ChannelsText.mentions = mentions;
746
+ function targets(team, channel, message) {
747
+ const muted = channel.muted ?? [];
748
+ const members = channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
749
+ const named = mentions(message.text, members).filter((id) => id !== message.author);
750
+ if (message.author === SYSTEM) {
751
+ return [];
752
+ }
753
+ if (named.length > 0 || message.author !== USER && message.author !== TA) {
754
+ return named;
755
+ }
756
+ return members.length > 0 ? [members[0].id] : [];
353
757
  }
354
- function png(bytes) {
355
- return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
758
+ ChannelsText.targets = targets;
759
+ function authorName(team, author, labels) {
760
+ if (author === SYSTEM) {
761
+ return "channel";
762
+ }
763
+ if (author === USER) {
764
+ return labels.user;
765
+ }
766
+ if (author === TA) {
767
+ return labels.ta;
768
+ }
769
+ return team.agents.find((agent) => agent.id === author)?.name ?? author;
356
770
  }
357
- function gif(bytes) {
358
- return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
771
+ ChannelsText.authorName = authorName;
772
+ function systemPrompt(agent) {
773
+ return [
774
+ `You are ${agent.name}, ${AGENT_MARK}. Your role: ${agent.role}`,
775
+ "You work with the user, Ta and other agents in channels. A message for you starts with a <context> block: the channel, its members, the recent messages and who speaks to you; answer what follows the block.",
776
+ "Do the part of the work your role covers with your tools, then answer in a few sentences: your answer is posted to the channel as it is.",
777
+ "To hand work to another member, write @ and their name in your answer; name nobody when the work is done or you need the user.",
778
+ NOTICE_RULE
779
+ ].join(`
780
+ `);
359
781
  }
360
- function webp(bytes) {
361
- if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
362
- return;
782
+ ChannelsText.systemPrompt = systemPrompt;
783
+ function prompt(team, channel, history, message, agent) {
784
+ const labels = { user: "user", ta: "Ta" };
785
+ const members = channel.members.map((id) => team.agents.find((other) => other.id === id)).filter((other) => !!other).map((other) => `@${other.name}${other.id === agent.id ? " (you)" : ""}: ${firstLine(other.role)}`);
786
+ const before = history.filter((item) => item.id !== message.id && !item.failed && !item.notice).slice(-CONTEXT_MESSAGES);
787
+ const lines = [`[#${channel.name}]${channel.topic ? ` ${channel.topic}` : ""}`, "Members:", ...members.map((line) => `- ${line}`)];
788
+ if (channel.notice) {
789
+ lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
363
790
  }
364
- switch (text(bytes, 12, 4)) {
365
- case "VP8 ":
366
- return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
367
- case "VP8L": {
368
- const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
369
- return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
370
- }
371
- case "VP8X":
372
- return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
373
- default:
374
- return;
791
+ if (before.length > 0) {
792
+ lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
375
793
  }
794
+ lines.push("", `${authorName(team, message.author, labels)} to you:`);
795
+ const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels).replace(/[\]\n]/g, " ")}`;
796
+ lines.push(`[ta:from ${NAME} #${channel.name}${speaker}]`);
797
+ return `<context>
798
+ ${lines.join(`
799
+ `)}
800
+ </context>
801
+ ${message.text}`;
376
802
  }
377
- function jpeg(bytes) {
378
- if (bytes[0] !== 255 || bytes[1] !== 216) {
379
- return;
803
+ ChannelsText.prompt = prompt;
804
+ function summary(team) {
805
+ if (team.agents.length === 0) {
806
+ return "No agents and no channels yet.";
380
807
  }
381
- let at = 2;
382
- while (at + 9 < bytes.length) {
383
- if (bytes[at] !== 255) {
384
- return;
808
+ const name = (id) => team.agents.find((agent) => agent.id === id)?.name ?? id;
809
+ const agents = team.agents.map((agent) => `- @${agent.name}: ${firstLine(agent.role)}`);
810
+ const channels = team.channels.map((channel) => `- #${channel.name}${channel.topic ? ` (${channel.topic})` : ""}: ${channel.members.map((id) => `@${name(id)}`).join(", ")}${channel.muted?.length ? `; muted by the user, answering nothing: ${channel.muted.map((id) => `@${name(id)}`).join(", ")}` : ""}${channel.notice ? `
811
+ notice: ${channel.notice.text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`);
812
+ return ["Agents:", ...agents, "", "Channels:", ...channels.length > 0 ? channels : ["none yet"]].join(`
813
+ `);
814
+ }
815
+ ChannelsText.summary = summary;
816
+ function transcript(team, messages) {
817
+ const labels = { user: "user", ta: "Ta" };
818
+ return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${item.text}`).join(`
819
+
820
+ `);
821
+ }
822
+ ChannelsText.transcript = transcript;
823
+ function markdown(agent, messages, labels) {
824
+ const parts = [`# ${agent.name}`, "", `> ${firstLine(agent.role)}`];
825
+ for (const message of messages) {
826
+ const { role, content } = message ?? {};
827
+ if (role !== "user" && role !== "assistant") {
828
+ continue;
385
829
  }
386
- const marker = bytes[at + 1];
387
- if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
388
- return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
830
+ const text = (typeof content === "string" ? content : Array.isArray(content) ? content.map((block) => block?.type === "text" ? String(block.text ?? "") : "").join("") : "").replace(/^<context>\n?[\s\S]*?\n?<\/context>\n?/, "").trim();
831
+ if (text) {
832
+ parts.push("", `## ${role === "user" ? labels.user : agent.name}`, "", text);
389
833
  }
390
- at += 2 + u16be(bytes, at + 2);
391
834
  }
392
- return;
835
+ return `${parts.join(`
836
+ `)}
837
+ `;
393
838
  }
394
- })(TaImageSize || (TaImageSize = {}));
395
- var TaAgentSummary;
396
- (function(TaAgentSummary2) {
397
- const START = /^\s*<conversation_history_summary>/;
398
- const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
399
- function read(text) {
400
- if (!START.test(text)) {
401
- return;
839
+ ChannelsText.markdown = markdown;
840
+ function channelMarkdown(team, channel, messages, labels) {
841
+ const parts = [`# #${channel.name}`];
842
+ if (channel.topic) {
843
+ parts.push("", `> ${firstLine(channel.topic)}`);
402
844
  }
403
- return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
404
- }
405
- TaAgentSummary2.read = read;
406
- function strip(text) {
407
- return text.replace(BLOCK, "");
408
- }
409
- TaAgentSummary2.strip = strip;
410
- })(TaAgentSummary || (TaAgentSummary = {}));
411
- var TaSkillUse;
412
- (function(TaSkillUse2) {
413
- const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
414
- function parse(message) {
415
- var _a;
416
- const match = BLOCK.exec(message);
417
- if (!match) {
418
- return;
845
+ for (const message of messages) {
846
+ const text = message.text.trim();
847
+ if (text && message.author !== SYSTEM) {
848
+ parts.push("", `## ${authorName(team, message.author, labels)}${message.failed ? " (failed)" : ""}`, "", text);
849
+ }
419
850
  }
420
- return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
851
+ return `${parts.join(`
852
+ `)}
853
+ `;
421
854
  }
422
- TaSkillUse2.parse = parse;
423
- function command(use) {
424
- return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
855
+ ChannelsText.channelMarkdown = channelMarkdown;
856
+ function firstLine(text) {
857
+ return text.split(`
858
+ `)[0];
425
859
  }
426
- TaSkillUse2.command = command;
427
- })(TaSkillUse || (TaSkillUse = {}));
860
+ })(ChannelsText ||= {});
861
+ var NOTICE_RULE = [
862
+ "A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
863
+ `When the talk settles a decision or a convention, or adds, assigns or finishes a to-do, update it with update_channel_notice: the whole notice, short, under the headings ### ${NOTICE_HEADINGS.zh.join(" / ")} (### ${NOTICE_HEADINGS.en.join(" / ")} in English), in the language of the channel, to-dos as - [ ] or - [x] with who does them. The lead keeps it most; leave it for small talk.`
864
+ ].join(`
865
+ `);
428
866
 
429
- // ../ta-protocol/esm/common/presence-protocol.js
430
- var TaPresenceServer = Symbol("TaPresenceServer");
431
- var TaMessageAuthor;
432
- (function(TaMessageAuthor2) {
433
- const LINE = /^\[ta:by ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
434
- const LINES = /^\[ta:by [^\]\n]*\]$\n?/gm;
435
- function strip(message) {
436
- const context = TaMessageContext.read(message);
437
- if (context === undefined || !LINE.test(context)) {
438
- return message;
867
+ // web-src/handoff.ts
868
+ var HandOff;
869
+ ((HandOff) => {
870
+ HandOff.TOOL = "hand_off";
871
+ HandOff.CARD = "ta-channels-handoff";
872
+ HandOff.BLOCK = "ta-handoff";
873
+ const MARK = /\[ta-handoff:([^\]\s]+)\]/;
874
+ HandOff.DEFINITION = {
875
+ name: HandOff.TOOL,
876
+ label: "Hand off",
877
+ description: "Hands the work of this conversation over to one of the user's agents (@name) or channels (#name), when the user says so (hand it to, give it to, 交给, 转给). The other side does not see this conversation: write the brief it needs to go on, in the user's language: the goal, what is done and decided, what is left or blocks, the files, branches, commands and links that matter. It works on it in its own conversation, which the user follows; you stop working on it here. list_channels lists the team. After the call, say in one line to whom it went.",
878
+ promptSnippet: "Hand the work over to one of the user's agents or channels",
879
+ parameters: {
880
+ type: "object",
881
+ properties: {
882
+ to: { type: "string", description: "@name of an agent or #name of a channel." },
883
+ brief: { type: "string", description: "Complete in itself: the receiver sees only this." }
884
+ },
885
+ required: ["to", "brief"]
439
886
  }
440
- const kept = context.replace(LINES, "").replace(/\n+$/, "");
441
- const body = TaMessageContext.strip(message);
442
- return kept.trim() ? TaMessageContext.wrap(kept, body) : body;
887
+ };
888
+ function ref(target) {
889
+ return `${target.kind === "agent" ? "@" : "#"}${target.name}`;
443
890
  }
444
- TaMessageAuthor2.strip = strip;
445
- function mark(message, id, name) {
446
- const plain = strip(message);
447
- if (/^[/!]/.test(plain)) {
448
- return plain;
449
- }
450
- const line = `[ta:by ${id.replace(/[\s\]]/g, "")} ${name.replace(/[\]\n]/g, " ").trim() || id}]`;
451
- const context = TaMessageContext.read(plain);
452
- return TaMessageContext.wrap(context === undefined ? line : `${context}
453
- ${line}`, TaMessageContext.strip(plain));
891
+ HandOff.ref = ref;
892
+ function ask(language, to) {
893
+ const fence = "```";
894
+ const context = [
895
+ `[ta-handoff:${to}]`,
896
+ `The user hands the work of this conversation over to ${to}, which does not see this conversation.`,
897
+ `- Write the brief it needs to go on: the goal, what is done and decided, what is left or blocks, the files, branches, commands and links that matter, in the user's language. Leave out what was only tried and dropped.`,
898
+ `- With the tool ${HandOff.TOOL}, call it with to "${to}" and the brief, then say in one line that it went.`,
899
+ `- Without it, say in one line what you hand over, then end your answer with the brief in a fenced block of the language ${HandOff.BLOCK}, which Ta reads to hand it over (a longer fence when the brief has one of its own):`,
900
+ `${fence}${HandOff.BLOCK}`,
901
+ "<the brief>",
902
+ fence,
903
+ `- When the conversation holds nothing to hand over yet, say so and ask what ${to} should do.`
904
+ ].join(`
905
+ `);
906
+ const line = TaLanguageUtil.pick(language, {
907
+ "zh-CN": `把这件事交给 ${to}`,
908
+ "zh-TW": `把這件事交給 ${to}`,
909
+ "en-US": `Hand this over to ${to}`,
910
+ "ja-JP": `これを ${to} に引き継ぐ`
911
+ });
912
+ return `<context>
913
+ ${context}
914
+ </context>
915
+ ${line}`;
454
916
  }
455
- TaMessageAuthor2.mark = mark;
456
- function of(message) {
457
- var _a;
458
- const context = TaMessageContext.read(message);
459
- const match = context === undefined ? null : LINE.exec(context);
460
- return match ? { id: match[1], name: ((_a = match[2]) !== null && _a !== undefined ? _a : match[1]).trim() } : undefined;
917
+ HandOff.ask = ask;
918
+ function asked(text) {
919
+ return MARK.exec(text)?.[1];
461
920
  }
462
- TaMessageAuthor2.of = of;
463
- })(TaMessageAuthor || (TaMessageAuthor = {}));
464
- // ../ta-protocol/esm/common/relay-protocol.js
465
- var TaRelayServer = Symbol("TaRelayServer");
466
- // ../ta-protocol/esm/common/remote-protocol.js
467
- var TaRemoteServer = Symbol("TaRemoteServer");
468
- // ../ta-protocol/esm/common/room-protocol.js
469
- var TaRoomServer = Symbol("TaRoomServer");
470
- var TaRoomWatchUtil;
471
- (function(TaRoomWatchUtil2) {
472
- function of(messages, state) {
473
- const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
474
- return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
921
+ HandOff.asked = asked;
922
+ function find(text) {
923
+ const lines = text.split(/\r?\n/);
924
+ let found;
925
+ for (let index = 0;index < lines.length; index++) {
926
+ const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
927
+ if (open?.[2] !== HandOff.BLOCK) {
928
+ continue;
929
+ }
930
+ const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
931
+ const end = lines.findIndex((line, at) => at > index && close.test(line));
932
+ found = lines.slice(index + 1, end < 0 ? lines.length : end);
933
+ index = end < 0 ? lines.length : end;
934
+ }
935
+ const brief = found?.join(`
936
+ `).trim();
937
+ return brief || undefined;
938
+ }
939
+ HandOff.find = find;
940
+ function message(origin, brief, language) {
941
+ const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
942
+ const head = TaLanguageUtil.pick(language, {
943
+ "zh-CN": `(交接自“${title}”)`,
944
+ "zh-TW": `(交接自「${title}」)`,
945
+ "en-US": `(Handed over from “${title}”)`,
946
+ "ja-JP": `(“${title}” から引き継ぎました)`
947
+ });
948
+ const context = [
949
+ "The user handed you this work from another conversation of theirs, which you do not see; the brief below is all it says. Go on from there in this conversation, which the user follows; ask them when the brief leaves out something you need.",
950
+ origin.sessionFile ? `That conversation is pi's session file ${origin.sessionFile}${origin.cwd ? `, working in ${origin.cwd}` : ""}: read it only when the brief is not enough.` : ""
951
+ ].filter(Boolean).join(`
952
+ `);
953
+ return `<context>
954
+ ${context}
955
+ </context>
956
+ ${head}
957
+
958
+ ${brief.trim()}`;
475
959
  }
476
- TaRoomWatchUtil2.of = of;
477
- function union(watches) {
478
- let messages = false;
479
- const state = [];
480
- for (const watch of watches) {
481
- messages || (messages = watch.messages);
482
- state.push(...watch.state);
483
- }
484
- return of(messages, messages ? [] : state);
960
+ HandOff.message = message;
961
+ function channelText(origin, brief, language) {
962
+ const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
963
+ return `${TaLanguageUtil.pick(language, {
964
+ "zh-CN": `(交接自“${title}”)`,
965
+ "zh-TW": `(交接自「${title}」)`,
966
+ "en-US": `(Handed over from “${title}”)`,
967
+ "ja-JP": `(“${title}” から引き継ぎました)`
968
+ })}
969
+
970
+ ${brief.trim()}`;
485
971
  }
486
- TaRoomWatchUtil2.union = union;
487
- function same(a, b) {
488
- return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
489
- `) === b.state.join(`
490
- `);
972
+ HandOff.channelText = channelText;
973
+ function serverLanguage(env = typeof process === "undefined" ? {} : process.env) {
974
+ return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
491
975
  }
492
- TaRoomWatchUtil2.same = same;
493
- function hears(watch, event) {
494
- if (event.type === "message") {
495
- return watch.messages;
496
- }
497
- if (event.type === "state") {
498
- return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
499
- }
500
- return true;
976
+ HandOff.serverLanguage = serverLanguage;
977
+ function result(target) {
978
+ return `Handed over to ${ref(target)}; it works on it in its own conversation, which the user follows. Do not go on with it here.`;
501
979
  }
502
- TaRoomWatchUtil2.hears = hears;
503
- })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
504
- // ../ta-protocol/esm/common/settings-protocol.js
505
- var TaSettingsServer = Symbol("TaSettingsServer");
980
+ HandOff.result = result;
981
+ })(HandOff ||= {});
982
+
983
+ // ../ta-protocol/esm/common/access-protocol.js
984
+ var TaAccessServer = Symbol("TaAccessServer");
506
985
  // ../ta-protocol/esm/common/ta-extension-host.js
986
+ var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
507
987
  var TA_HOST_EVENT = "ta:host";
508
988
  var TaHostUtil;
509
989
  (function(TaHostUtil2) {
@@ -595,1032 +1075,1284 @@ var TaAskUtil;
595
1075
  return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
596
1076
  }
597
1077
  })(TaAskUtil || (TaAskUtil = {}));
598
- // ../ta-protocol/esm/common/team-protocol.js
599
- var TA_OWNER = "owner";
600
- var TA_UNDECLARED = "extensions.install";
601
- var TaPermissionUtil;
602
- (function(TaPermissionUtil2) {
603
- function read(pi) {
604
- const given = pi === null || pi === undefined ? undefined : pi.permissions;
605
- const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
606
- const host2 = map(given === null || given === undefined ? undefined : given.host);
607
- const tools = map(given === null || given === undefined ? undefined : given.tools);
608
- return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
1078
+
1079
+ // ../ta-protocol/esm/common/delegate-protocol.js
1080
+ var TaDelegateUtil;
1081
+ (function(TaDelegateUtil2) {
1082
+ TaDelegateUtil2.LEVELS = ["less", "balanced", "more"];
1083
+ TaDelegateUtil2.DEFAULT = "balanced";
1084
+ TaDelegateUtil2.WORK_TOOLS = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
1085
+ TaDelegateUtil2.CHANGE_TOOLS = ["edit", "write"];
1086
+ const LIMITS = {
1087
+ less: { noChanges: false },
1088
+ balanced: { noChanges: true, steps: 6 },
1089
+ more: { noChanges: true, steps: 2 }
1090
+ };
1091
+ function parse(value) {
1092
+ return TaDelegateUtil2.LEVELS.includes(value) ? value : TaDelegateUtil2.DEFAULT;
609
1093
  }
610
- TaPermissionUtil2.read = read;
611
- function host(manifest, method, kind) {
612
- var _a, _b, _c, _d;
613
- const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
614
- const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
615
- return (_d = (_c = (_b = kind ? own(`${method}:${kind}`) : undefined) !== null && _b !== undefined ? _b : own(method)) !== null && _c !== undefined ? _c : own("*")) !== null && _d !== undefined ? _d : TA_UNDECLARED;
1094
+ TaDelegateUtil2.parse = parse;
1095
+ function mark(level) {
1096
+ return `(delegate=${level})`;
1097
+ }
1098
+ TaDelegateUtil2.mark = mark;
1099
+ function levelOf(systemPrompt) {
1100
+ const role = TaHostUtil.role(systemPrompt);
1101
+ return TaDelegateUtil2.LEVELS.find((level) => role.includes(mark(level)));
1102
+ }
1103
+ TaDelegateUtil2.levelOf = levelOf;
1104
+ function limits(level) {
1105
+ return LIMITS[level];
1106
+ }
1107
+ TaDelegateUtil2.limits = limits;
1108
+ function refusal(level, tool, steps) {
1109
+ if (!TaDelegateUtil2.WORK_TOOLS.includes(tool)) {
1110
+ return;
1111
+ }
1112
+ const limit = LIMITS[level];
1113
+ if (limit.noChanges && TaDelegateUtil2.CHANGE_TOOLS.includes(tool)) {
1114
+ return "You do not change files yourself: hand this to a task with start_task, with instructions complete enough to do it. The user set how much you hand out in the settings of the double.";
1115
+ }
1116
+ if (limit.steps !== undefined && steps >= limit.steps) {
1117
+ return "You have looked enough for this: hand the work to a task with start_task now, with what you found in its instructions, and tell the user what you started.";
1118
+ }
1119
+ return;
1120
+ }
1121
+ TaDelegateUtil2.refusal = refusal;
1122
+ })(TaDelegateUtil || (TaDelegateUtil = {}));
1123
+
1124
+ // ../ta-protocol/esm/common/app-protocol.js
1125
+ var FONT_SIZES = ["small", "standard", "large", "xlarge"];
1126
+ var words = (en, zh, tw, ja) => ({ "en-US": en, "zh-CN": zh, "zh-TW": tw, "ja-JP": ja });
1127
+ var SYSTEM2 = words("as the system", "跟随系统", "跟隨系統", "システムに合わせる");
1128
+ var FONT_SHOWN = {
1129
+ small: words("small", "小", "小", "小"),
1130
+ standard: words("standard", "标准", "標準", "標準"),
1131
+ large: words("large", "大", "大", "大"),
1132
+ xlarge: words("extra large", "特大", "特大", "特大")
1133
+ };
1134
+ var TA_WEB_SETTINGS = [
1135
+ {
1136
+ key: "theme",
1137
+ type: "enum",
1138
+ values: ["system", "light", "dark"],
1139
+ default: "system",
1140
+ what: "Light or dark look; system follows the device.",
1141
+ title: words("Theme", "外观", "外觀", "外観"),
1142
+ shown: { system: SYSTEM2, light: words("light", "浅色", "淺色", "ライト"), dark: words("dark", "深色", "深色", "ダーク") }
1143
+ },
1144
+ {
1145
+ key: "language",
1146
+ type: "enum",
1147
+ values: ["system", ...TaLanguageUtil.ALL],
1148
+ default: "system",
1149
+ what: "The language of Ta's pages and of what Ta says; system follows the device.",
1150
+ title: words("Language", "语言", "語言", "言語"),
1151
+ shown: {
1152
+ system: SYSTEM2,
1153
+ ...Object.fromEntries(TaLanguageUtil.ALL.map((language) => [
1154
+ language,
1155
+ words(TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language])
1156
+ ]))
1157
+ }
1158
+ },
1159
+ {
1160
+ key: "fontSize",
1161
+ type: "enum",
1162
+ values: FONT_SIZES,
1163
+ default: "standard",
1164
+ what: "The size of the text of the whole page.",
1165
+ title: words("Text size", "字体大小", "字型大小", "文字サイズ"),
1166
+ shown: FONT_SHOWN
1167
+ },
1168
+ {
1169
+ key: "chatFontSize",
1170
+ type: "enum",
1171
+ values: FONT_SIZES,
1172
+ default: "standard",
1173
+ what: "The size of the text of conversations, on top of fontSize.",
1174
+ title: words("Text size of conversations", "对话字体大小", "對話字型大小", "会話の文字サイズ"),
1175
+ shown: FONT_SHOWN
1176
+ },
1177
+ {
1178
+ key: "speak",
1179
+ type: "boolean",
1180
+ default: false,
1181
+ what: "Read every reply aloud.",
1182
+ title: words("Read replies aloud", "朗读回复", "朗讀回覆", "返信を読み上げ")
1183
+ },
1184
+ {
1185
+ key: "speakTalk",
1186
+ type: "boolean",
1187
+ default: false,
1188
+ what: "Read the reply aloud when the user spoke to the double by voice.",
1189
+ title: words("Read aloud what was asked by voice", "语音提问时朗读回复", "語音提問時朗讀回覆", "音声で聞いたら読み上げ")
1190
+ },
1191
+ {
1192
+ key: "callCaptions",
1193
+ type: "boolean",
1194
+ default: false,
1195
+ what: "Show captions in a call: what the user says and what Ta reads.",
1196
+ title: words("Call captions", "通话字幕", "通話字幕", "通話の字幕")
1197
+ },
1198
+ {
1199
+ key: "voice",
1200
+ type: "string",
1201
+ default: "",
1202
+ what: "The voice replies are read with (a voiceURI of the device's voices); empty for the most natural one.",
1203
+ title: words("Voice", "朗读声音", "朗讀聲音", "読み上げの声")
1204
+ },
1205
+ {
1206
+ key: "confirmTasks",
1207
+ type: "boolean",
1208
+ default: false,
1209
+ what: "The double asks before it hands out work.",
1210
+ title: words("Ask before handing out work", "派任务前先问我", "派任務前先問我", "作業を割り当てる前に確認")
1211
+ },
1212
+ {
1213
+ key: "maxTasks",
1214
+ type: "number",
1215
+ values: [0, 2, 4, 8],
1216
+ default: 0,
1217
+ what: "How many of the double's tasks run at once; 0 for as many as it starts.",
1218
+ title: words("Tasks at once", "同时运行的任务", "同時執行的任務", "同時に実行するタスク")
1219
+ },
1220
+ {
1221
+ key: "delegate",
1222
+ type: "enum",
1223
+ values: TaDelegateUtil.LEVELS,
1224
+ default: TaDelegateUtil.DEFAULT,
1225
+ what: "How much of the work the double hands out to tasks rather than doing it itself.",
1226
+ title: words("Hand out work", "派活多少", "派活多少", "作業の割り当て"),
1227
+ shown: { less: words("less", "少", "少", "少なめ"), balanced: words("balanced", "适中", "適中", "ふつう"), more: words("more", "多", "多", "多め") }
1228
+ },
1229
+ {
1230
+ key: "assistantModel",
1231
+ type: "model",
1232
+ default: "",
1233
+ what: "The model of the double, <provider>/<model id>; empty for the default model.",
1234
+ title: words("Model of the double", "分身的模型", "分身的模型", "分身のモデル")
1235
+ },
1236
+ {
1237
+ key: "taskModel",
1238
+ type: "model",
1239
+ default: "",
1240
+ what: "The model of the tasks the double starts; empty for the default model.",
1241
+ title: words("Model of tasks", "任务的模型", "任務的模型", "タスクのモデル")
1242
+ },
1243
+ { key: "reduceMotion", type: "boolean", default: false, what: "Fewer animations.", title: words("Reduce motion", "减少动画", "減少動畫", "動きを減らす") },
1244
+ {
1245
+ key: "keepAliveMinutes",
1246
+ type: "number",
1247
+ values: [1, 5, 15, 30],
1248
+ default: 5,
1249
+ what: "How long an extension started on open keeps running once left, in minutes.",
1250
+ title: words("Keep extensions running", "扩展离开后保留", "擴充功能離開後保留", "拡張機能を保持")
1251
+ },
1252
+ {
1253
+ key: "chatFoldDays",
1254
+ type: "number",
1255
+ values: [3, 7, 30, 0],
1256
+ default: 7,
1257
+ what: "Conversations not updated for these days fold at the end of the list; 0 for none.",
1258
+ title: words("Fold old conversations", "折叠旧对话", "摺疊舊對話", "古い会話を折りたたむ")
1259
+ },
1260
+ {
1261
+ key: "chatArchiveDays",
1262
+ type: "number",
1263
+ values: [30, 90, 365, 0],
1264
+ default: 30,
1265
+ what: "Conversations not updated for these days are archived (out of the list, found by search); 0 for none.",
1266
+ title: words("Archive old conversations", "归档旧对话", "歸檔舊對話", "古い会話をアーカイブ")
1267
+ },
1268
+ {
1269
+ key: "recentShots",
1270
+ type: "boolean",
1271
+ default: true,
1272
+ what: "The screenshot just taken is offered above the message box, once.",
1273
+ title: words("Offer recent screenshots", "提示刚截的图", "提示剛截的圖", "撮ったばかりのスクリーンショットを提案")
616
1274
  }
617
- TaPermissionUtil2.host = host;
618
- })(TaPermissionUtil || (TaPermissionUtil = {}));
619
- var action = (id, en, zh, tw, ja, more = {}) => ({
620
- id,
621
- area: id.split(".")[0],
622
- title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
623
- ...more
624
- });
625
- var TA_ACTIONS = [
626
- action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
627
- action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
628
- action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
629
- action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
630
- action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
631
- action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
632
- action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
633
- action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
634
- action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
635
- action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
636
- action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
637
- action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
638
- action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
639
- action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
640
- action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
641
- action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
642
- action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
643
- action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
644
- action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
645
- action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
646
- action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
647
- action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更"),
648
- action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
649
- action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
650
- action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
651
- action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
652
- action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
653
- action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
654
- action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
655
- action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
656
- action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
657
- action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
658
- action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
659
1275
  ];
660
- var TaActionUtil;
661
- (function(TaActionUtil2) {
662
- const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
663
- function info(id) {
664
- return byId.get(id);
1276
+ var TaAppUtil;
1277
+ (function(TaAppUtil2) {
1278
+ function check(spec, value) {
1279
+ var _a, _b;
1280
+ switch (spec.type) {
1281
+ case "boolean":
1282
+ return typeof value === "boolean" ? undefined : "true or false";
1283
+ case "string":
1284
+ return typeof value === "string" ? undefined : "a string";
1285
+ case "model":
1286
+ return value === "" || typeof value === "string" && /^[^/\s]+\/\S+$/.test(value) ? undefined : "<provider>/<model id>, or empty";
1287
+ default:
1288
+ return ((_a = spec.values) === null || _a === undefined ? undefined : _a.includes(value)) ? undefined : `one of ${(_b = spec.values) === null || _b === undefined ? undefined : _b.map((one) => JSON.stringify(one)).join(", ")}`;
1289
+ }
665
1290
  }
666
- TaActionUtil2.info = info;
667
- function title(id, language) {
1291
+ TaAppUtil2.check = check;
1292
+ function shown(value, language, spec) {
668
1293
  var _a;
669
- var _b, _c;
670
- const title2 = (_a = byId.get(id)) === null || _a === undefined ? undefined : _a.title;
671
- if (!title2) {
672
- return id;
1294
+ const named = (_a = spec === null || spec === undefined ? undefined : spec.shown) === null || _a === undefined ? undefined : _a[String(value)];
1295
+ if (named) {
1296
+ return TaLanguageUtil.pick(language, named);
673
1297
  }
674
- return TaLanguageUtil.pick(language, {
675
- "zh-CN": title2["zh-CN"],
676
- "zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
677
- "en-US": title2.en,
678
- "ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
679
- });
1298
+ if (typeof value === "boolean") {
1299
+ return TaLanguageUtil.pick(language, value ? words("on", "开", "開", "オン") : words("off", "关", "關", "オフ"));
1300
+ }
1301
+ if (value === "" || value === undefined || value === null) {
1302
+ return TaLanguageUtil.pick(language, words("default", "默认", "預設", "デフォルト"));
1303
+ }
1304
+ return String(value);
680
1305
  }
681
- TaActionUtil2.title = title;
682
- function inside(dir, path) {
683
- const base = dir.replace(/\/+$/, "");
684
- return path === base || path.startsWith(`${base}/`) || base === "";
1306
+ TaAppUtil2.shown = shown;
1307
+ })(TaAppUtil || (TaAppUtil = {}));
1308
+ // ../ta-protocol/esm/common/auth-protocol.js
1309
+ var TaAuthServer = Symbol("TaAuthServer");
1310
+ // ../ta-protocol/esm/common/deployment-protocol.js
1311
+ var TA_WELL_KNOWN_PATH = "/.well-known/ta";
1312
+
1313
+ class TaDeploymentError extends Error {
1314
+ }
1315
+ var TaDeploymentUtil;
1316
+ (function(TaDeploymentUtil2) {
1317
+ TaDeploymentUtil2.DISTRIBUTION_FILE = "distribution.json";
1318
+ function url(value) {
1319
+ if (typeof value !== "string" || !value.trim()) {
1320
+ return;
1321
+ }
1322
+ try {
1323
+ const parsed = new URL(value.trim());
1324
+ if (!/^https?:$/.test(parsed.protocol) || parsed.search || parsed.hash || parsed.username || parsed.password) {
1325
+ return;
1326
+ }
1327
+ return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, "");
1328
+ } catch (_a) {
1329
+ return;
1330
+ }
685
1331
  }
686
- TaActionUtil2.inside = inside;
687
- })(TaActionUtil || (TaActionUtil = {}));
688
- // ../ta-protocol/esm/common/usage-protocol.js
689
- var TaUsageServer = Symbol("TaUsageServer");
690
- // ../ta-protocol/esm/common/workspace-protocol.js
691
- var TaWorkspaceServer = Symbol("TaWorkspaceServer");
692
- var TaTerminalServer = Symbol("TaTerminalServer");
693
- var TaExcludedFiles;
694
- (function(TaExcludedFiles2) {
695
- TaExcludedFiles2.NAMES = [".git", ".svn", ".hg", ".DS_Store", "Thumbs.db"];
696
- function has(name) {
697
- return TaExcludedFiles2.NAMES.includes(name);
1332
+ TaDeploymentUtil2.url = url;
1333
+ function name(value) {
1334
+ return typeof value === "string" && value.trim() ? value.trim().slice(0, 80) : undefined;
698
1335
  }
699
- TaExcludedFiles2.has = has;
700
- function filter(entries) {
701
- return entries.filter((entry) => !has(entry.name));
1336
+ function describe(env, own, version) {
1337
+ var _a, _b;
1338
+ const gateway = (_a = url(own.gateway)) !== null && _a !== undefined ? _a : url(env.TA_GATEWAY_URL);
1339
+ const relay = (_b = url(own.relay)) !== null && _b !== undefined ? _b : url(env.TA_RELAY_URL);
1340
+ const called = name(env.TA_DEPLOYMENT_NAME);
1341
+ return { v: 1, ...called ? { name: called } : {}, ...gateway ? { gateway } : {}, ...relay ? { relay } : {}, ...version ? { version } : {} };
1342
+ }
1343
+ TaDeploymentUtil2.describe = describe;
1344
+ TaDeploymentUtil2.HEADERS = {
1345
+ "content-type": "application/json",
1346
+ "access-control-allow-origin": "*",
1347
+ "cache-control": "no-store"
1348
+ };
1349
+ function parse(value) {
1350
+ const given = value;
1351
+ if (!given || typeof given !== "object" || given.v !== 1) {
1352
+ return;
1353
+ }
1354
+ const deployment = describe({ TA_DEPLOYMENT_NAME: given.name, TA_GATEWAY_URL: given.gateway, TA_RELAY_URL: given.relay }, {});
1355
+ const version = name(given.version);
1356
+ return version ? { ...deployment, version } : deployment;
702
1357
  }
703
- TaExcludedFiles2.filter = filter;
704
- })(TaExcludedFiles || (TaExcludedFiles = {}));
705
- var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
706
- // ../ta-protocol/esm/common/redactor.js
707
- var REDACTED = "[redacted]";
708
- var WHOLE = [
709
- /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
710
- /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/g,
711
- /\bgh[pousr]_[A-Za-z0-9]{30,}\b/g,
712
- /\bgithub_pat_[A-Za-z0-9_]{40,}\b/g,
713
- /\bglpat-[A-Za-z0-9_-]{20,}\b/g,
714
- /\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
715
- /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
716
- /\bAIza[0-9A-Za-z_-]{35}\b/g,
717
- /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g
718
- ];
719
- var NAMED = [
720
- /(\bBearer\s+)[A-Za-z0-9._~+/-]{16,}=*/gi,
721
- /(\b[A-Za-z0-9_.-]*(?:password|passwd|pwd|secret|token|api[_-]?key|access[_-]?key|private[_-]?key)[A-Za-z0-9_.-]*["']?\s*[:=]\s*["']?)([^\s"'`,;]{6,})/gi,
722
- /(:\/\/[^\s:/@]+:)([^\s@/]{3,})(@)/g
723
- ];
724
-
725
- class Redactor {
726
- constructor() {
727
- this.count = 0;
1358
+ TaDeploymentUtil2.parse = parse;
1359
+ async function discover(address, timeoutMs = 6000) {
1360
+ const base = url(address);
1361
+ if (!base) {
1362
+ throw new TaDeploymentError(`${address} is not an address of http or https.`);
1363
+ }
1364
+ const controller = new AbortController;
1365
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
1366
+ try {
1367
+ const response = await fetch(`${base}${TA_WELL_KNOWN_PATH}`, { signal: controller.signal, redirect: "follow" });
1368
+ if (!response.ok) {
1369
+ throw new TaDeploymentError(`${base} is not a deployment of Ta (${response.status}).`);
1370
+ }
1371
+ const deployment = parse(await response.json().catch(() => {
1372
+ return;
1373
+ }));
1374
+ if (!deployment || !deployment.gateway && !deployment.relay) {
1375
+ throw new TaDeploymentError(`${base} is not a deployment of Ta.`);
1376
+ }
1377
+ return deployment;
1378
+ } catch (error) {
1379
+ if ((error === null || error === undefined ? undefined : error.name) === "AbortError") {
1380
+ throw new TaDeploymentError(`${base} did not answer in time.`);
1381
+ }
1382
+ throw error;
1383
+ } finally {
1384
+ clearTimeout(timer);
1385
+ }
1386
+ }
1387
+ TaDeploymentUtil2.discover = discover;
1388
+ function distribution(value) {
1389
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1390
+ throw new TaDeploymentError(`${TaDeploymentUtil2.DISTRIBUTION_FILE} holds a JSON object.`);
1391
+ }
1392
+ const given = value;
1393
+ const result = {};
1394
+ if (given.name !== undefined) {
1395
+ result.name = name(given.name);
1396
+ }
1397
+ for (const key of ["relay", "gateway"]) {
1398
+ if (given[key] !== undefined) {
1399
+ const address = url(given[key]);
1400
+ if (!address) {
1401
+ throw new TaDeploymentError(`"${key}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
1402
+ }
1403
+ result[key] = address;
1404
+ }
1405
+ }
1406
+ if (given.updates !== undefined) {
1407
+ const updates = given.updates;
1408
+ const base = url(updates === null || updates === undefined ? undefined : updates.base);
1409
+ if (!base && (updates === null || updates === undefined ? undefined : updates.base) !== undefined) {
1410
+ throw new TaDeploymentError(`"updates.base" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
1411
+ }
1412
+ const key = typeof (updates === null || updates === undefined ? undefined : updates.key) === "string" && updates.key.includes("PUBLIC KEY") ? updates.key : undefined;
1413
+ if ((updates === null || updates === undefined ? undefined : updates.key) !== undefined && !key) {
1414
+ throw new TaDeploymentError(`"updates.key" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a public key in PEM.`);
1415
+ }
1416
+ result.updates = { ...base ? { base } : {}, ...key ? { key } : {} };
1417
+ }
1418
+ return result;
1419
+ }
1420
+ TaDeploymentUtil2.distribution = distribution;
1421
+ function apply(distribution2, env) {
1422
+ const defaults = { TA_DEPLOYMENT_NAME: distribution2.name, TA_RELAY_URL: distribution2.relay, TA_GATEWAY_URL: distribution2.gateway };
1423
+ for (const [key, value] of Object.entries(defaults)) {
1424
+ if (value && !env[key]) {
1425
+ env[key] = value;
1426
+ }
1427
+ }
1428
+ }
1429
+ TaDeploymentUtil2.apply = apply;
1430
+ })(TaDeploymentUtil || (TaDeploymentUtil = {}));
1431
+ // ../ta-protocol/esm/common/error-protocol.js
1432
+ var TaErrorCode = {
1433
+ SESSION_NOT_FOUND: "CELL_TA_SESSION_NOT_FOUND",
1434
+ SESSION_LOCKED: "CELL_TA_SESSION_LOCKED",
1435
+ TOO_MANY_SESSIONS: "CELL_TA_TOO_MANY_SESSIONS",
1436
+ MESSAGE_CONFLICT: "CELL_TA_MESSAGE_CONFLICT",
1437
+ MODEL_NOT_FOUND: "CELL_TA_MODEL_NOT_FOUND",
1438
+ INVALID_ARGUMENT: "CELL_TA_INVALID_ARGUMENT",
1439
+ COMMAND_FAILED: "CELL_TA_COMMAND_FAILED",
1440
+ NOTHING_TO_COMPACT: "CELL_TA_NOTHING_TO_COMPACT",
1441
+ ALREADY_COMPACTED: "CELL_TA_ALREADY_COMPACTED",
1442
+ SESSION_BUSY: "CELL_TA_SESSION_BUSY",
1443
+ CANCELLED: "CELL_TA_CANCELLED",
1444
+ NOT_SIGNED_IN: "CELL_TA_NOT_SIGNED_IN",
1445
+ ENVIRONMENT_FAILED: "CELL_TA_ENVIRONMENT_FAILED",
1446
+ RATE_LIMITED: "CELL_TA_RATE_LIMITED",
1447
+ FORBIDDEN: "CELL_TA_FORBIDDEN",
1448
+ LIMIT: "CELL_TA_LIMIT",
1449
+ CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
1450
+ };
1451
+ var TaErrorUtil;
1452
+ (function(TaErrorUtil2) {
1453
+ function code(error) {
1454
+ var _a;
1455
+ var _b;
1456
+ const failure = error;
1457
+ const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
1458
+ return typeof code2 === "string" ? code2 : undefined;
1459
+ }
1460
+ TaErrorUtil2.code = code;
1461
+ })(TaErrorUtil || (TaErrorUtil = {}));
1462
+ // ../ta-protocol/esm/common/gateway-protocol.js
1463
+ var TaGatewayServer = Symbol("TaGatewayServer");
1464
+ // ../ta-protocol/esm/common/location.js
1465
+ var TaLocation;
1466
+ (function(TaLocation2) {
1467
+ TaLocation2.SSH = "ssh://";
1468
+ TaLocation2.CLOUD = "ta://";
1469
+ const CLOUD_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
1470
+ const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
1471
+ function isRemote(location) {
1472
+ return location.startsWith(TaLocation2.SSH) || location.startsWith(TaLocation2.CLOUD);
1473
+ }
1474
+ TaLocation2.isRemote = isRemote;
1475
+ function isCloud(host2) {
1476
+ return !!host2 && host2.startsWith(TaLocation2.CLOUD);
728
1477
  }
729
- text(text) {
730
- let out = text;
731
- for (const pattern of WHOLE) {
732
- out = out.replace(pattern, () => this.hide());
1478
+ TaLocation2.isCloud = isCloud;
1479
+ function isCloudName(name) {
1480
+ return CLOUD_NAME.test(name);
1481
+ }
1482
+ TaLocation2.isCloudName = isCloudName;
1483
+ function cloud(name, path2 = "") {
1484
+ return `${TaLocation2.CLOUD}${name}${path2 ? normalize(path2) : ""}`;
1485
+ }
1486
+ TaLocation2.cloud = cloud;
1487
+ function cloudName(hostOrLocation) {
1488
+ if (!hostOrLocation.startsWith(TaLocation2.CLOUD)) {
1489
+ return;
733
1490
  }
734
- out = out.replace(NAMED[0], (_match, before) => before + this.hide());
735
- out = out.replace(NAMED[1], (match, before, value) => Redactor.placeholder(value) ? match : before + this.hide());
736
- out = out.replace(NAMED[2], (_match, before, _value, after) => before + this.hide() + after);
737
- return out;
1491
+ const rest = hostOrLocation.slice(TaLocation2.CLOUD.length);
1492
+ const slash = rest.indexOf("/");
1493
+ return slash < 0 ? rest : rest.slice(0, slash);
738
1494
  }
739
- value(value, max) {
740
- if (typeof value === "string") {
741
- return Redactor.cut(this.text(value), max);
1495
+ TaLocation2.cloudName = cloudName;
1496
+ function parse(location) {
1497
+ var _a;
1498
+ if (!isRemote(location)) {
1499
+ return;
742
1500
  }
743
- if (Array.isArray(value)) {
744
- return value.map((item) => this.value(item, max));
1501
+ if (location.startsWith(TaLocation2.CLOUD)) {
1502
+ const name = (_a = cloudName(location)) !== null && _a !== undefined ? _a : "";
1503
+ if (!isCloudName(name)) {
1504
+ throw new Error(`${JSON.stringify(location)} names no cloud workspace: write ta://<name>/<path>.`);
1505
+ }
1506
+ const path3 = location.slice(TaLocation2.CLOUD.length + name.length);
1507
+ return { host: `${TaLocation2.CLOUD}${name}`, path: path3 ? normalize(path3) : "" };
745
1508
  }
746
- if (value && typeof value === "object") {
747
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, this.value(item, max)]));
1509
+ const rest = location.slice(TaLocation2.SSH.length);
1510
+ const slash = rest.indexOf("/");
1511
+ const host2 = slash < 0 ? rest : rest.slice(0, slash);
1512
+ const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
1513
+ if (!isHost(host2)) {
1514
+ throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
748
1515
  }
749
- return value;
750
- }
751
- static cut(text, max) {
752
- return text.length > max ? `${text.slice(0, max)}…` : text;
753
- }
754
- hide() {
755
- this.count++;
756
- return REDACTED;
1516
+ return { host: host2, path: path2 };
757
1517
  }
758
- static placeholder(value) {
759
- return /^(?:\$|<|\{|\[redacted|process\.env|os\.environ|xxx|\*{3})/i.test(value) || /^(?:true|false|null|undefined|none|string|number)$/i.test(value);
1518
+ TaLocation2.parse = parse;
1519
+ function isHost(host2) {
1520
+ return isCloud(host2) ? isCloudName(host2.slice(TaLocation2.CLOUD.length)) : HOST.test(host2);
760
1521
  }
761
- }
762
-
763
- // ../ta-relay/esm/common/relay-card.js
764
- var RELAY_AGENT_KIND = "ta-agent";
765
- var RelayAgentCards;
766
- (function(RelayAgentCards2) {
767
- const MAX_ROLE = 8000;
768
- function parse(data) {
769
- try {
770
- const card = JSON.parse(typeof data === "string" ? data : new TextDecoder().decode(data));
771
- if ((card === null || card === undefined ? undefined : card.v) !== 1 || typeof card.name !== "string" || !card.name.trim() || typeof card.role !== "string" || !card.role.trim()) {
772
- return;
1522
+ TaLocation2.isHost = isHost;
1523
+ const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
1524
+ function readHost(input) {
1525
+ const words2 = input.trim().split(/\s+/).filter(Boolean);
1526
+ if (words2[0] === "ssh") {
1527
+ words2.shift();
1528
+ }
1529
+ let destination;
1530
+ let port;
1531
+ let user;
1532
+ const options = [];
1533
+ for (let i = 0;i < words2.length; i++) {
1534
+ const word = words2[i];
1535
+ const glued = /^-([pl])(.+)$/.exec(word);
1536
+ if (word === "-p" || word === "-l" || glued) {
1537
+ const value = glued ? glued[2] : words2[++i];
1538
+ if (value === undefined) {
1539
+ return { error: "invalid" };
1540
+ }
1541
+ if ((glued ? glued[1] : word[1]) === "p") {
1542
+ port = value;
1543
+ } else {
1544
+ user = value;
1545
+ }
1546
+ } else if (word === "-o" || word.startsWith("-o")) {
1547
+ const value = word === "-o" ? words2[++i] : word.slice(2);
1548
+ const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
1549
+ if (!option) {
1550
+ options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
1551
+ } else if (option[1].toLowerCase() === "port") {
1552
+ port = option[2];
1553
+ } else {
1554
+ user = option[2];
1555
+ }
1556
+ } else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
1557
+ options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words2[i + 1] !== undefined ? `${word} ${words2[++i]}` : word);
1558
+ } else if (destination === undefined) {
1559
+ destination = word;
1560
+ } else {
1561
+ return { error: "invalid" };
773
1562
  }
774
- const color = typeof card.color === "string" && /^#[0-9a-fA-F]{6}$/.test(card.color) ? card.color : undefined;
775
- return {
776
- v: 1,
777
- name: card.name.trim().slice(0, 32),
778
- role: card.role.trim().slice(0, MAX_ROLE),
779
- mark: typeof card.mark === "string" && card.mark.trim() ? card.mark.trim().slice(0, 2) : card.name.trim().slice(0, 1).toUpperCase(),
780
- ...Number.isInteger(card.face) ? { face: card.face } : {},
781
- ...color ? { color } : {},
782
- ...typeof card.redacted === "number" && card.redacted > 0 ? { redacted: card.redacted } : {}
783
- };
784
- } catch (_a) {
785
- return;
786
1563
  }
1564
+ if (options.length > 0) {
1565
+ return { error: "options", options };
1566
+ }
1567
+ if (!destination) {
1568
+ return { error: "empty" };
1569
+ }
1570
+ let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
1571
+ if (user && !host2.includes("@")) {
1572
+ host2 = `${user}@${host2}`;
1573
+ }
1574
+ if (port) {
1575
+ if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
1576
+ return { error: "invalid" };
1577
+ }
1578
+ host2 = port === "22" ? host2 : `${host2}:${port}`;
1579
+ }
1580
+ return isHost(host2) ? { host: host2 } : { error: "invalid" };
787
1581
  }
788
- RelayAgentCards2.parse = parse;
789
- })(RelayAgentCards || (RelayAgentCards = {}));
790
-
791
- // web-src/channels-model.ts
792
- var NAME = "@celljs/ta-channels";
793
- var AGENT_MARK = "one of the agents of Ta";
794
- var MEMBER_CHANGES = ["lead", "remove", "mute", "unmute"];
795
- var Keys;
796
- ((Keys) => {
797
- Keys.TEAM = "team";
798
- Keys.QUEUE = "queue";
799
- Keys.WORKING = "working";
800
- Keys.FOCUS = "focus";
801
- Keys.ANSWERED = "answered";
802
- Keys.CARDS = "cards";
803
- Keys.MESSAGES = "messages/";
804
- Keys.messages = (channelId) => `${Keys.MESSAGES}${channelId}`;
805
- })(Keys ||= {});
806
- var USER = "user";
807
- var TA = "ta";
808
- var SYSTEM = "system";
809
- var MAX_HOPS = 3;
810
- var MAX_REPLIES = 8;
811
- var MAX_AGENT_REPLIES = 2;
812
- var STOP_NOTE = "The agents stopped handing on here, at the limit of a round; it is your turn.";
813
- var MAX_MESSAGES = 200;
814
- var FACES = 16;
815
- var MAX_MEMBERS = 12;
816
- var CONTEXT_MESSAGES = 12;
817
- var MAX_NAME = 32;
818
- var MAX_NOTICE = 2000;
819
- var NOTICE_HEADINGS = { zh: ["决定", "约定", "待办"], en: ["Decisions", "Conventions", "To do"] };
820
- var CARD_DAYS = 30;
821
-
822
- // web-src/channels-util.ts
823
- var ChannelsUtil;
824
- ((ChannelsUtil) => {
825
- function newRound() {
826
- return { total: 0, byAgent: {}, stopped: false };
1582
+ TaLocation2.readHost = readHost;
1583
+ function ssh(host2, path2 = "") {
1584
+ return isCloud(host2) ? `${host2}${path2 ? normalize(path2) : ""}` : `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
827
1585
  }
828
- ChannelsUtil.newRound = newRound;
829
- function limit(round, targets2, hops) {
830
- const allowed = [];
831
- const byAgent = { ...round.byAgent };
832
- let total = round.total;
833
- for (const id of targets2) {
834
- if (hops < MAX_HOPS && total < MAX_REPLIES && (byAgent[id] ?? 0) < MAX_AGENT_REPLIES) {
835
- allowed.push(id);
836
- byAgent[id] = (byAgent[id] ?? 0) + 1;
837
- total++;
838
- }
1586
+ TaLocation2.ssh = ssh;
1587
+ function hostLabel(host2) {
1588
+ if (isCloud(host2)) {
1589
+ return host2.slice(TaLocation2.CLOUD.length);
839
1590
  }
840
- const cut = allowed.length < targets2.length;
841
- const note = cut && !round.stopped;
842
- return { allowed, round: { total, byAgent, stopped: round.stopped || cut }, cut, note };
1591
+ const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
1592
+ return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
843
1593
  }
844
- ChannelsUtil.limit = limit;
845
- function emptyTeam() {
846
- return { agents: [], channels: [] };
1594
+ TaLocation2.hostLabel = hostLabel;
1595
+ function host(location) {
1596
+ var _a;
1597
+ return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
847
1598
  }
848
- ChannelsUtil.emptyTeam = emptyTeam;
849
- function newId(prefix) {
850
- return `${prefix}-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
1599
+ TaLocation2.host = host;
1600
+ function path(location) {
1601
+ var _a;
1602
+ var _b;
1603
+ return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
851
1604
  }
852
- ChannelsUtil.newId = newId;
853
- function checkName(value, what) {
854
- const name = typeof value === "string" ? value.trim().replace(/^[@#]+/, "").replace(/\s+/g, "-") : "";
855
- if (!name || name.length > MAX_NAME || /[@#,]/.test(name)) {
856
- throw new Error(`The name of the ${what} must be 1 to ${MAX_NAME} characters, without @, # or commas.`);
1605
+ TaLocation2.path = path;
1606
+ function parent(location) {
1607
+ const remote = parse(location);
1608
+ if (remote) {
1609
+ const above = remote.path ? parentPath(remote.path) : undefined;
1610
+ return above === undefined ? undefined : ssh(remote.host, above);
857
1611
  }
858
- return name;
1612
+ return parentPath(location);
859
1613
  }
860
- ChannelsUtil.checkName = checkName;
861
- function mark(name) {
862
- const first = Array.from(name)[0] ?? "?";
863
- if (!/[A-Za-z0-9]/.test(first)) {
864
- return first;
1614
+ TaLocation2.parent = parent;
1615
+ function child(location, name) {
1616
+ const remote = parse(location);
1617
+ if (remote) {
1618
+ return ssh(remote.host, childPath(remote.path || "/", name));
865
1619
  }
866
- const words = name.split(/[-_.\s]+|(?<=[a-z])(?=[A-Z])/).filter(Boolean);
867
- return words.length > 1 ? (words[0][0] + words[1][0]).toUpperCase() : first.toUpperCase();
1620
+ return childPath(location, name);
868
1621
  }
869
- ChannelsUtil.mark = mark;
870
- function faces(agents) {
871
- const result = new Map;
872
- const taken = new Set;
873
- for (const agent of agents) {
874
- if (isFace(agent.face)) {
875
- result.set(agent.id, agent.face);
876
- taken.add(agent.face);
877
- }
1622
+ TaLocation2.child = child;
1623
+ function basename(location) {
1624
+ const remote = parse(location);
1625
+ const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
1626
+ const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
1627
+ return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
1628
+ }
1629
+ TaLocation2.basename = basename;
1630
+ function homeRelative(location) {
1631
+ var _a;
1632
+ const remote = parse(location);
1633
+ const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
1634
+ const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
1635
+ return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
1636
+ }
1637
+ TaLocation2.homeRelative = homeRelative;
1638
+ function isAbsolute(location) {
1639
+ if (homeRelative(location) !== undefined) {
1640
+ return false;
878
1641
  }
879
- for (const agent of agents) {
880
- if (!result.has(agent.id)) {
881
- const face = freeFace(hash(agent.id), taken);
882
- result.set(agent.id, face);
883
- taken.add(face);
884
- }
1642
+ return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
1643
+ }
1644
+ TaLocation2.isAbsolute = isAbsolute;
1645
+ function parentPath(path2) {
1646
+ const trimmed = path2.replace(/[\\/]+$/, "");
1647
+ const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
1648
+ if (at < 0) {
1649
+ return;
885
1650
  }
886
- return result;
1651
+ const head = trimmed.slice(0, at);
1652
+ return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
887
1653
  }
888
- ChannelsUtil.faces = faces;
889
- function isFace(face) {
890
- return typeof face === "number" && Number.isInteger(face) && face >= 0 && face < FACES;
1654
+ function childPath(path2, name) {
1655
+ const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
1656
+ return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
891
1657
  }
892
- ChannelsUtil.isFace = isFace;
893
- function freeFaceFor(agents, seed) {
894
- return freeFace(hash(seed), new Set(faces(agents).values()));
1658
+ function normalize(path2) {
1659
+ const squeezed = `/${path2}`.replace(/\/+/g, "/");
1660
+ return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
895
1661
  }
896
- ChannelsUtil.freeFaceFor = freeFaceFor;
897
- function freeName(team, base) {
898
- let name = base;
899
- for (let count = 2;findAgent(team, name); count++) {
900
- name = `${base}-${count}`;
1662
+ })(TaLocation || (TaLocation = {}));
1663
+ // ../ta-protocol/esm/common/message-protocol.js
1664
+ var TaMessageContext;
1665
+ (function(TaMessageContext2) {
1666
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
1667
+ function wrap(context, message) {
1668
+ return `<context>
1669
+ ${context}
1670
+ </context>
1671
+ ${message}`;
1672
+ }
1673
+ TaMessageContext2.wrap = wrap;
1674
+ function strip(message) {
1675
+ return message.replace(BLOCK, "");
1676
+ }
1677
+ TaMessageContext2.strip = strip;
1678
+ function read(message) {
1679
+ var _a;
1680
+ const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
1681
+ return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
1682
+ }
1683
+ TaMessageContext2.read = read;
1684
+ })(TaMessageContext || (TaMessageContext = {}));
1685
+ var TaMessageSource;
1686
+ (function(TaMessageSource2) {
1687
+ TaMessageSource2.DOUBLE = "ta:double";
1688
+ const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
1689
+ function mark(message, from, detail) {
1690
+ if (/^[/!]/.test(message) || of(message)) {
1691
+ return message;
901
1692
  }
902
- return name;
1693
+ const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
1694
+ const context = TaMessageContext.read(message);
1695
+ return TaMessageContext.wrap(context === undefined ? line : `${context}
1696
+ ${line}`, TaMessageContext.strip(message));
903
1697
  }
904
- ChannelsUtil.freeName = freeName;
905
- function freeFace(start, taken) {
906
- for (let step = 0;step < FACES; step++) {
907
- const face = (start + step) % FACES;
908
- if (!taken.has(face)) {
909
- return face;
910
- }
1698
+ TaMessageSource2.mark = mark;
1699
+ function of(message) {
1700
+ const context = TaMessageContext.read(message);
1701
+ const match = context === undefined ? null : LINE.exec(context);
1702
+ return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
1703
+ }
1704
+ TaMessageSource2.of = of;
1705
+ })(TaMessageSource || (TaMessageSource = {}));
1706
+ var TaImageNote;
1707
+ (function(TaImageNote2) {
1708
+ const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
1709
+ function strip(text) {
1710
+ const lines = text.split(`
1711
+ `);
1712
+ const kept = lines.filter((line) => !NOTE.test(line.trim()));
1713
+ if (kept.length === lines.length) {
1714
+ return text;
911
1715
  }
912
- return start % FACES;
1716
+ return kept.join(`
1717
+ `).replace(/\n+$/, "").replace(/^\n+/, "");
913
1718
  }
914
- function hash(text) {
915
- let value = 2166136261;
916
- for (let index = 0;index < text.length; index++) {
917
- value = Math.imul(value ^ text.charCodeAt(index), 16777619);
1719
+ TaImageNote2.strip = strip;
1720
+ })(TaImageNote || (TaImageNote = {}));
1721
+ var TaImageSize;
1722
+ (function(TaImageSize2) {
1723
+ const JPEG_BYTES = 256 * 1024;
1724
+ function of(base64) {
1725
+ var _a, _b, _c;
1726
+ let bytes;
1727
+ try {
1728
+ const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
1729
+ bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
1730
+ } catch (_d) {
1731
+ return;
918
1732
  }
919
- return value >>> 0;
1733
+ const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
1734
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
920
1735
  }
921
- ChannelsUtil.hash = hash;
922
- function findAgent(team, ref) {
923
- const key = ref.trim().replace(/^@/, "").toLowerCase();
924
- return team.agents.find((agent) => agent.id === ref) ?? team.agents.find((agent) => agent.name.toLowerCase() === key);
1736
+ TaImageSize2.of = of;
1737
+ function u16be(bytes, at) {
1738
+ return bytes[at] << 8 | bytes[at + 1];
925
1739
  }
926
- ChannelsUtil.findAgent = findAgent;
927
- function findChannel(team, ref) {
928
- const key = ref.trim().replace(/^#/, "").toLowerCase();
929
- return team.channels.find((channel) => channel.id === ref) ?? team.channels.find((channel) => channel.name.toLowerCase() === key);
1740
+ function u16le(bytes, at) {
1741
+ return bytes[at] | bytes[at + 1] << 8;
930
1742
  }
931
- ChannelsUtil.findChannel = findChannel;
932
- function directory(value) {
933
- return typeof value === "string" && value.trim() ? value.trim() : undefined;
1743
+ function u24le(bytes, at) {
1744
+ return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
934
1745
  }
935
- ChannelsUtil.directory = directory;
936
- function addAgent(team, input) {
937
- const name = checkName(input.name, "agent");
938
- if (findAgent(team, name)) {
939
- throw new Error(`There is an agent named ${name} already.`);
940
- }
941
- const role = typeof input.role === "string" ? input.role.trim() : "";
942
- if (!role) {
943
- throw new Error(`Say what ${name} does: its role.`);
944
- }
945
- const cwd = directory(input.cwd);
946
- const id = newId("agent");
947
- const face = isFace(input.face) ? input.face : freeFace(hash(id), new Set(faces(team.agents).values()));
948
- const agent = { id, name, role, mark: mark(name), face, cwd, ...input.temporary ? { temporary: true } : {}, createdAt: Date.now() };
949
- return { team: { ...team, agents: [...team.agents, agent] }, agent };
1746
+ function u32be(bytes, at) {
1747
+ return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
950
1748
  }
951
- ChannelsUtil.addAgent = addAgent;
952
- function addChannel(team, input) {
953
- const name = checkName(input.name, "channel");
954
- if (findChannel(team, name)) {
955
- throw new Error(`There is a channel named ${name} already.`);
956
- }
957
- const members = agentIds(team, input.members);
958
- if (members.length === 0) {
959
- throw new Error("A channel needs at least one agent.");
960
- }
961
- if (members.length > MAX_MEMBERS) {
962
- throw new Error(`A channel holds at most ${MAX_MEMBERS} agents.`);
963
- }
964
- const topic = typeof input.topic === "string" && input.topic.trim() ? input.topic.trim() : undefined;
965
- const channel = {
966
- id: newId("channel"),
967
- name,
968
- topic,
969
- members,
970
- ...input.by ? { by: input.by } : {},
971
- ...input.origin ? { origin: input.origin } : {},
972
- createdAt: Date.now()
973
- };
974
- return { team: { ...team, channels: [...team.channels, channel] }, channel };
1749
+ function text(bytes, at, length) {
1750
+ return String.fromCharCode(...bytes.subarray(at, at + length));
975
1751
  }
976
- ChannelsUtil.addChannel = addChannel;
977
- function addMembers(team, input) {
978
- const found = channelOf(team, input.channel);
979
- const ids = agentIds(team, input.members);
980
- if (ids.length === 0) {
981
- throw new Error("Name at least one agent to add.");
982
- }
983
- const added = ids.filter((id) => !found.members.includes(id)).map((id) => team.agents.find((agent) => agent.id === id));
984
- if (found.members.length + added.length > MAX_MEMBERS) {
985
- throw new Error(`A channel holds at most ${MAX_MEMBERS} agents; #${found.name} has ${found.members.length}.`);
986
- }
987
- const channel = { ...found, members: [...found.members, ...added.map((agent) => agent.id)] };
988
- return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, added };
1752
+ function png(bytes) {
1753
+ return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
989
1754
  }
990
- ChannelsUtil.addMembers = addMembers;
991
- function channelOf(team, ref) {
992
- const key = typeof ref === "string" ? ref : "";
993
- const found = findChannel(team, key);
994
- if (!found) {
995
- const known = team.channels.map((other) => `#${other.name}`).join(", ") || "none yet";
996
- throw new Error(`No channel is named ${key}. The channels: ${known}.`);
997
- }
998
- return found;
1755
+ function gif(bytes) {
1756
+ return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
999
1757
  }
1000
- ChannelsUtil.channelOf = channelOf;
1001
- function changeMember(team, input) {
1002
- const found = channelOf(team, input.channel);
1003
- const agent = findAgent(team, typeof input.agent === "string" ? input.agent : "");
1004
- if (!agent || !found.members.includes(agent.id)) {
1005
- throw new Error(`${agent?.name ?? String(input.agent)} is not a member of #${found.name}.`);
1006
- }
1007
- if (typeof input.change !== "string" || !MEMBER_CHANGES.includes(input.change)) {
1008
- throw new Error(`A member is changed with one of ${MEMBER_CHANGES.join(", ")}.`);
1758
+ function webp(bytes) {
1759
+ if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
1760
+ return;
1009
1761
  }
1010
- const others = found.members.filter((id) => id !== agent.id);
1011
- const muted = (found.muted ?? []).filter((id) => id !== agent.id);
1012
- let channel;
1013
- switch (input.change) {
1014
- case "lead":
1015
- channel = { ...found, members: [agent.id, ...others] };
1016
- break;
1017
- case "remove":
1018
- if (others.length === 0) {
1019
- throw new Error(`${agent.name} is the only member of #${found.name}: delete the channel instead.`);
1020
- }
1021
- channel = { ...found, members: others, muted };
1022
- break;
1023
- case "mute":
1024
- channel = { ...found, muted: [...muted, agent.id] };
1025
- break;
1762
+ switch (text(bytes, 12, 4)) {
1763
+ case "VP8 ":
1764
+ return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
1765
+ case "VP8L": {
1766
+ const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
1767
+ return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
1768
+ }
1769
+ case "VP8X":
1770
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
1026
1771
  default:
1027
- channel = { ...found, muted };
1028
- }
1029
- if (channel.muted?.length === 0) {
1030
- delete channel.muted;
1772
+ return;
1031
1773
  }
1032
- return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel };
1033
1774
  }
1034
- ChannelsUtil.changeMember = changeMember;
1035
- function updateChannel(team, input) {
1036
- const before = channelOf(team, input.channel);
1037
- const channel = { ...before };
1038
- if (input.name !== undefined) {
1039
- const name = checkName(input.name, "channel");
1040
- const other = findChannel(team, name);
1041
- if (other && other.id !== channel.id) {
1042
- throw new Error(`There is a channel named ${name} already.`);
1043
- }
1044
- channel.name = name;
1775
+ function jpeg(bytes) {
1776
+ if (bytes[0] !== 255 || bytes[1] !== 216) {
1777
+ return;
1045
1778
  }
1046
- if (input.topic !== undefined) {
1047
- const topic = typeof input.topic === "string" ? input.topic.trim() : "";
1048
- if (topic) {
1049
- channel.topic = topic;
1050
- } else {
1051
- delete channel.topic;
1779
+ let at = 2;
1780
+ while (at + 9 < bytes.length) {
1781
+ if (bytes[at] !== 255) {
1782
+ return;
1783
+ }
1784
+ const marker = bytes[at + 1];
1785
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
1786
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
1052
1787
  }
1788
+ at += 2 + u16be(bytes, at + 2);
1053
1789
  }
1054
- if (input.pinned !== undefined) {
1055
- if (input.pinned === true) {
1056
- channel.pinned = true;
1057
- } else {
1058
- delete channel.pinned;
1059
- }
1790
+ return;
1791
+ }
1792
+ })(TaImageSize || (TaImageSize = {}));
1793
+ var TaAgentSummary;
1794
+ (function(TaAgentSummary2) {
1795
+ const START = /^\s*<conversation_history_summary>/;
1796
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
1797
+ function read(text) {
1798
+ if (!START.test(text)) {
1799
+ return;
1060
1800
  }
1061
- return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before };
1801
+ return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
1062
1802
  }
1063
- ChannelsUtil.updateChannel = updateChannel;
1064
- function standing(team) {
1065
- const inChannel = new Set(team.channels.flatMap((channel) => channel.members));
1066
- return team.agents.filter((agent) => !agent.temporary || !inChannel.has(agent.id));
1803
+ TaAgentSummary2.read = read;
1804
+ function strip(text) {
1805
+ return text.replace(BLOCK, "");
1067
1806
  }
1068
- ChannelsUtil.standing = standing;
1069
- function taskChannels(team) {
1070
- return team.channels.filter((channel) => channel.by === "ta");
1807
+ TaAgentSummary2.strip = strip;
1808
+ })(TaAgentSummary || (TaAgentSummary = {}));
1809
+ var TaSkillUse;
1810
+ (function(TaSkillUse2) {
1811
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
1812
+ function parse(message) {
1813
+ var _a;
1814
+ const match = BLOCK.exec(message);
1815
+ if (!match) {
1816
+ return;
1817
+ }
1818
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
1071
1819
  }
1072
- ChannelsUtil.taskChannels = taskChannels;
1073
- function ownChannels(team) {
1074
- return team.channels.filter((channel) => channel.by !== "ta");
1820
+ TaSkillUse2.parse = parse;
1821
+ function command(use) {
1822
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
1075
1823
  }
1076
- ChannelsUtil.ownChannels = ownChannels;
1077
- function pinnedFirst(items) {
1078
- return [...items.filter((item) => item.pinned), ...items.filter((item) => !item.pinned)];
1824
+ TaSkillUse2.command = command;
1825
+ })(TaSkillUse || (TaSkillUse = {}));
1826
+ var TaTaskNote;
1827
+ (function(TaTaskNote2) {
1828
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
1829
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
1830
+ function write(note) {
1831
+ const attributes = [`id="${quote(note.id)}"`];
1832
+ if (note.was !== undefined) {
1833
+ attributes.push(`was="${quote(note.was)}"`);
1834
+ }
1835
+ attributes.push(`title="${quote(note.title)}"`);
1836
+ if (note.status !== undefined) {
1837
+ attributes.push(`status="${quote(note.status)}"`);
1838
+ }
1839
+ return `<task_${note.kind} ${attributes.join(" ")}>
1840
+ ${note.body}
1841
+ </task_${note.kind}>`;
1842
+ }
1843
+ TaTaskNote2.write = write;
1844
+ function parse(text) {
1845
+ const match = NOTE.exec(text.trim());
1846
+ if (!match) {
1847
+ return;
1848
+ }
1849
+ const attributes = {};
1850
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
1851
+ attributes[name] = unquote(value);
1852
+ }
1853
+ if (!attributes.id || attributes.title === undefined) {
1854
+ return;
1855
+ }
1856
+ const { id, title, status, was } = attributes;
1857
+ return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
1079
1858
  }
1080
- ChannelsUtil.pinnedFirst = pinnedFirst;
1081
- function removeChannel(team, ref) {
1082
- const channel = channelOf(team, ref);
1083
- return { team: { ...team, channels: team.channels.filter((other) => other.id !== channel.id) }, channel };
1859
+ TaTaskNote2.parse = parse;
1860
+ function quote(text) {
1861
+ return text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/\n/g, " ");
1084
1862
  }
1085
- ChannelsUtil.removeChannel = removeChannel;
1086
- function resetAgent(team, ref) {
1087
- const found = findAgent(team, typeof ref === "string" ? ref : "");
1088
- if (!found) {
1089
- throw new Error(`No agent is ${String(ref)}.`);
1863
+ function unquote(text) {
1864
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
1865
+ }
1866
+ })(TaTaskNote || (TaTaskNote = {}));
1867
+ // ../ta-protocol/esm/common/package-protocol.js
1868
+ var TaPackageServer = Symbol("TaPackageServer");
1869
+ var TaPackageTextUtil;
1870
+ (function(TaPackageTextUtil2) {
1871
+ function pick(text, language) {
1872
+ var _a, _b, _c, _d, _e;
1873
+ if (text === undefined || typeof text === "string") {
1874
+ return text;
1090
1875
  }
1091
- const { sessionFile: _gone, ...agent } = found;
1092
- return { team: { ...team, agents: team.agents.map((other) => other.id === agent.id ? agent : other) }, agent };
1876
+ const base = language.split("-")[0];
1877
+ const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
1878
+ return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[base]) !== null && _b !== undefined ? _b : kin === undefined ? undefined : text[kin]) !== null && _c !== undefined ? _c : text.en) !== null && _d !== undefined ? _d : text["en-US"]) !== null && _e !== undefined ? _e : Object.values(text)[0];
1093
1879
  }
1094
- ChannelsUtil.resetAgent = resetAgent;
1095
- function updateAgent(team, input) {
1096
- const before = findAgent(team, typeof input.agent === "string" ? input.agent : "");
1097
- if (!before) {
1098
- throw new Error(`No agent is ${String(input.agent)}.`);
1880
+ TaPackageTextUtil2.pick = pick;
1881
+ })(TaPackageTextUtil || (TaPackageTextUtil = {}));
1882
+ // ../ta-protocol/esm/common/page-protocol.js
1883
+ var TaPageServer = Symbol("TaPageServer");
1884
+ // ../ta-protocol/esm/common/path-map.js
1885
+ var TaPathMap;
1886
+ (function(TaPathMap2) {
1887
+ function isWindows(path2) {
1888
+ return /^[a-zA-Z]:([\\/]|$)/.test(path2) || /^\\\\[^\\]/.test(path2);
1889
+ }
1890
+ TaPathMap2.isWindows = isWindows;
1891
+ function rest(path2, base) {
1892
+ const windows = isWindows(base);
1893
+ if (windows ? !isWindows(path2) : !base.startsWith("/") || !path2.startsWith("/")) {
1894
+ return;
1099
1895
  }
1100
- const agent = { ...before };
1101
- if (input.name !== undefined) {
1102
- const name = checkName(input.name, "agent");
1103
- const other = findAgent(team, name);
1104
- if (other && other.id !== agent.id) {
1105
- throw new Error(`There is an agent named ${name} already.`);
1106
- }
1107
- agent.name = name;
1108
- agent.mark = mark(name);
1896
+ const within = parts(base, windows);
1897
+ const all = parts(path2, windows);
1898
+ if (!within.length || all.length < within.length) {
1899
+ return;
1109
1900
  }
1110
- if (input.role !== undefined) {
1111
- const role = typeof input.role === "string" ? input.role.trim() : "";
1112
- if (!role) {
1113
- throw new Error(`Say what ${agent.name} does: its role.`);
1114
- }
1115
- agent.role = role;
1901
+ const same = (a, b) => windows ? a.toLowerCase() === b.toLowerCase() : a === b;
1902
+ return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
1903
+ }
1904
+ TaPathMap2.rest = rest;
1905
+ function under(path2, base) {
1906
+ return rest(path2, base) !== undefined;
1907
+ }
1908
+ TaPathMap2.under = under;
1909
+ function join(base, parts2) {
1910
+ if (!parts2.length) {
1911
+ return base;
1116
1912
  }
1117
- if (input.face !== undefined) {
1118
- if (!isFace(input.face)) {
1119
- throw new Error(`A face is a number from 0 to ${FACES - 1}.`);
1913
+ const sep = isWindows(base) ? "\\" : "/";
1914
+ return `${base.replace(/[\\/]+$/, "")}${sep}${parts2.join(sep)}`;
1915
+ }
1916
+ TaPathMap2.join = join;
1917
+ function basename(path2) {
1918
+ var _a;
1919
+ return (_a = path2.split(/[\\/]+/).filter(Boolean).pop()) !== null && _a !== undefined ? _a : "";
1920
+ }
1921
+ TaPathMap2.basename = basename;
1922
+ function path(value, pairs) {
1923
+ for (const [from, to] of deepest(pairs)) {
1924
+ const found = rest(value, from);
1925
+ if (found) {
1926
+ return join(to, found);
1120
1927
  }
1121
- agent.face = input.face;
1122
1928
  }
1123
- if (input.keep === true) {
1124
- delete agent.temporary;
1929
+ return value;
1930
+ }
1931
+ TaPathMap2.path = path;
1932
+ function text(value, pairs) {
1933
+ const order = deepest(pairs);
1934
+ if (!order.length) {
1935
+ return value;
1125
1936
  }
1126
- if (input.pinned === true) {
1127
- agent.pinned = true;
1128
- } else if (input.pinned !== undefined) {
1129
- delete agent.pinned;
1937
+ const end = String.raw`\s"'<>|*?:;,`;
1938
+ const pattern = new RegExp(String.raw`(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join("|")})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, "g");
1939
+ return value.replace(pattern, (...match) => {
1940
+ var _a;
1941
+ const before = match[1];
1942
+ const found = order.findIndex((_, i) => match[i + 2] !== undefined);
1943
+ const tail = (_a = match[order.length + 2]) !== null && _a !== undefined ? _a : "";
1944
+ return `${before}${join(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
1945
+ });
1946
+ }
1947
+ TaPathMap2.text = text;
1948
+ function json(value, pairs) {
1949
+ const order = deepest(pairs);
1950
+ if (!order.length) {
1951
+ return value;
1130
1952
  }
1131
- if (input.cwd !== undefined) {
1132
- const cwd = typeof input.cwd === "string" && input.cwd.trim() ? input.cwd.trim() : undefined;
1133
- if (cwd !== before.cwd) {
1134
- agent.cwd = cwd;
1135
- delete agent.sessionFile;
1953
+ const one = (each) => {
1954
+ const whole = path(each, order);
1955
+ return whole !== each ? whole : text(each, order);
1956
+ };
1957
+ const walk = (each) => {
1958
+ if (typeof each === "string") {
1959
+ return one(each);
1136
1960
  }
1137
- if (!cwd) {
1138
- delete agent.cwd;
1961
+ if (Array.isArray(each)) {
1962
+ return each.map(walk);
1139
1963
  }
1964
+ if (each && typeof each === "object") {
1965
+ return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
1966
+ }
1967
+ return each;
1968
+ };
1969
+ return walk(value);
1970
+ }
1971
+ TaPathMap2.json = json;
1972
+ function parts(path2, windows) {
1973
+ return path2.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
1974
+ }
1975
+ function deepest(pairs) {
1976
+ return pairs.filter(([from, to]) => from && to && from !== to && parts(from, isWindows(from)).length > 0).sort(([a], [b]) => parts(b, isWindows(b)).length - parts(a, isWindows(a)).length);
1977
+ }
1978
+ function source(base) {
1979
+ const windows = isWindows(base);
1980
+ const quote = (part) => [...part].map((char) => windows && char.toLowerCase() !== char.toUpperCase() ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
1981
+ const each = parts(base, windows).map(quote);
1982
+ if (!windows) {
1983
+ return `/${each.join("/+")}`;
1140
1984
  }
1141
- return { team: { ...team, agents: team.agents.map((other) => other.id === agent.id ? agent : other) }, agent, before };
1985
+ return `${base.startsWith("\\\\") ? String.raw`\\\\` : ""}${each.join(String.raw`[\\/]+`)}`;
1142
1986
  }
1143
- ChannelsUtil.updateAgent = updateAgent;
1144
- function removeAgent(team, ref) {
1145
- const agent = findAgent(team, typeof ref === "string" ? ref : "");
1146
- if (!agent) {
1147
- throw new Error(`No agent is ${String(ref)}.`);
1987
+ })(TaPathMap || (TaPathMap = {}));
1988
+ // ../ta-protocol/esm/common/presence-protocol.js
1989
+ var TaPresenceServer = Symbol("TaPresenceServer");
1990
+ var TaMessageAuthor;
1991
+ (function(TaMessageAuthor2) {
1992
+ const LINE = /^\[ta:by ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
1993
+ const LINES = /^\[ta:by [^\]\n]*\]$\n?/gm;
1994
+ function strip(message) {
1995
+ const context = TaMessageContext.read(message);
1996
+ if (context === undefined || !LINE.test(context)) {
1997
+ return message;
1148
1998
  }
1149
- const gone = [];
1150
- const channels = [];
1151
- for (const channel of team.channels) {
1152
- if (!channel.members.includes(agent.id)) {
1153
- channels.push(channel);
1154
- continue;
1155
- }
1156
- const members = channel.members.filter((id) => id !== agent.id);
1157
- if (members.length === 0) {
1158
- gone.push(channel);
1159
- continue;
1160
- }
1161
- const muted = channel.muted?.filter((id) => id !== agent.id);
1162
- const next = { ...channel, members, muted };
1163
- if (!muted?.length) {
1164
- delete next.muted;
1165
- }
1166
- channels.push(next);
1999
+ const kept = context.replace(LINES, "").replace(/\n+$/, "");
2000
+ const body = TaMessageContext.strip(message);
2001
+ return kept.trim() ? TaMessageContext.wrap(kept, body) : body;
2002
+ }
2003
+ TaMessageAuthor2.strip = strip;
2004
+ function mark(message, id, name) {
2005
+ const plain = strip(message);
2006
+ if (/^[/!]/.test(plain)) {
2007
+ return plain;
1167
2008
  }
1168
- return { team: { agents: team.agents.filter((other) => other.id !== agent.id), channels }, agent, channels: gone };
2009
+ const line = `[ta:by ${id.replace(/[\s\]]/g, "")} ${name.replace(/[\]\n]/g, " ").trim() || id}]`;
2010
+ const context = TaMessageContext.read(plain);
2011
+ return TaMessageContext.wrap(context === undefined ? line : `${context}
2012
+ ${line}`, TaMessageContext.strip(plain));
1169
2013
  }
1170
- ChannelsUtil.removeAgent = removeAgent;
1171
- function agentIds(team, refs) {
1172
- const ids = [];
1173
- for (const ref of Array.isArray(refs) ? refs.filter((item) => typeof item === "string") : []) {
1174
- const agent = findAgent(team, ref);
1175
- if (!agent) {
1176
- const known = team.agents.map((other) => other.name).join(", ") || "none yet";
1177
- throw new Error(`No agent is named ${ref}. The agents: ${known}.`);
1178
- }
1179
- if (!ids.includes(agent.id)) {
1180
- ids.push(agent.id);
1181
- }
2014
+ TaMessageAuthor2.mark = mark;
2015
+ function of(message) {
2016
+ var _a;
2017
+ const context = TaMessageContext.read(message);
2018
+ const match = context === undefined ? null : LINE.exec(context);
2019
+ return match ? { id: match[1], name: ((_a = match[2]) !== null && _a !== undefined ? _a : match[1]).trim() } : undefined;
2020
+ }
2021
+ TaMessageAuthor2.of = of;
2022
+ })(TaMessageAuthor || (TaMessageAuthor = {}));
2023
+ // ../ta-protocol/esm/common/relay-protocol.js
2024
+ var TaRelayServer = Symbol("TaRelayServer");
2025
+ // ../ta-protocol/esm/common/remote-protocol.js
2026
+ var TaRemoteServer = Symbol("TaRemoteServer");
2027
+ // ../ta-protocol/esm/common/room-protocol.js
2028
+ var TaRoomServer = Symbol("TaRoomServer");
2029
+ var TaRoomWatchUtil;
2030
+ (function(TaRoomWatchUtil2) {
2031
+ function of(messages, state) {
2032
+ const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
2033
+ return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
2034
+ }
2035
+ TaRoomWatchUtil2.of = of;
2036
+ function union(watches) {
2037
+ let messages = false;
2038
+ const state = [];
2039
+ for (const watch of watches) {
2040
+ messages || (messages = watch.messages);
2041
+ state.push(...watch.state);
1182
2042
  }
1183
- return ids;
2043
+ return of(messages, messages ? [] : state);
2044
+ }
2045
+ TaRoomWatchUtil2.union = union;
2046
+ function same(a, b) {
2047
+ return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
2048
+ `) === b.state.join(`
2049
+ `);
2050
+ }
2051
+ TaRoomWatchUtil2.same = same;
2052
+ function hears(watch, event) {
2053
+ if (event.type === "message") {
2054
+ return watch.messages;
2055
+ }
2056
+ if (event.type === "state") {
2057
+ return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
2058
+ }
2059
+ return true;
2060
+ }
2061
+ TaRoomWatchUtil2.hears = hears;
2062
+ })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
2063
+ // ../ta-protocol/esm/common/settings-protocol.js
2064
+ var TaSettingsServer = Symbol("TaSettingsServer");
2065
+ // ../ta-protocol/esm/common/ta-protocol.js
2066
+ var TaServer = Symbol("TaServer");
2067
+ var TaClient = Symbol("TaClient");
2068
+ var TaSlashCommandUtil;
2069
+ (function(TaSlashCommandUtil2) {
2070
+ function description(command, language) {
2071
+ var _a, _b;
2072
+ const { descriptions } = command;
2073
+ return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
1184
2074
  }
1185
- function markMentions(text, agents) {
1186
- if (agents.length === 0) {
1187
- return text;
1188
- }
1189
- const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
1190
- const pattern = new RegExp(`(?<![*A-Za-z0-9_])@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
1191
- return text.split(/(```[\s\S]*?(?:```|$)|`[^`\n]*`)/).map((part, index) => index % 2 === 1 ? part : part.replace(pattern, "**$&**")).join("");
2075
+ TaSlashCommandUtil2.description = description;
2076
+ })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
2077
+ // ../ta-protocol/esm/common/usage-protocol.js
2078
+ var TaUsageServer = Symbol("TaUsageServer");
2079
+ // ../ta-protocol/esm/common/voice-protocol.js
2080
+ var TaVoiceServer = Symbol("TaVoiceServer");
2081
+ // ../ta-protocol/esm/common/workspace-protocol.js
2082
+ var TaWorkspaceServer = Symbol("TaWorkspaceServer");
2083
+ var TaTerminalServer = Symbol("TaTerminalServer");
2084
+ var TaExcludedFiles;
2085
+ (function(TaExcludedFiles2) {
2086
+ TaExcludedFiles2.NAMES = [".git", ".svn", ".hg", ".DS_Store", "Thumbs.db"];
2087
+ function has(name) {
2088
+ return TaExcludedFiles2.NAMES.includes(name);
1192
2089
  }
1193
- ChannelsUtil.markMentions = markMentions;
1194
- function mentions(text, agents) {
1195
- if (agents.length === 0) {
1196
- return [];
1197
- }
1198
- const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
1199
- const pattern = new RegExp(`@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
1200
- const found = [];
1201
- for (const match of text.matchAll(pattern)) {
1202
- const agent = agents.find((candidate) => candidate.name.toLowerCase() === match[1].toLowerCase());
1203
- if (agent && !found.includes(agent.id)) {
1204
- found.push(agent.id);
2090
+ TaExcludedFiles2.has = has;
2091
+ function filter(entries) {
2092
+ return entries.filter((entry) => !has(entry.name));
2093
+ }
2094
+ TaExcludedFiles2.filter = filter;
2095
+ })(TaExcludedFiles || (TaExcludedFiles = {}));
2096
+ var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
2097
+ // web-src/team-view.ts
2098
+ var TeamViewUtil;
2099
+ ((TeamViewUtil) => {
2100
+ function visible(team2, can) {
2101
+ const channels = new Set(team2.channels.filter((channel) => can("channel", channel.id)).map((channel) => channel.id));
2102
+ const agents = new Set(team2.agents.filter((agent) => can("agent", agent.id)).map((agent) => agent.id));
2103
+ for (const channel of team2.channels) {
2104
+ if (channels.has(channel.id)) {
2105
+ for (const member of channel.members) {
2106
+ agents.add(member);
2107
+ }
1205
2108
  }
1206
2109
  }
1207
- return found;
2110
+ return { agents, channels };
1208
2111
  }
1209
- ChannelsUtil.mentions = mentions;
1210
- function targets(team, channel, message) {
1211
- const muted = channel.muted ?? [];
1212
- const members = channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
1213
- const named = mentions(message.text, members).filter((id) => id !== message.author);
1214
- if (message.author === SYSTEM) {
1215
- return [];
1216
- }
1217
- if (named.length > 0 || message.author !== USER && message.author !== TA) {
1218
- return named;
2112
+ TeamViewUtil.visible = visible;
2113
+ function team(value, visible2) {
2114
+ if (!value) {
2115
+ return value;
1219
2116
  }
1220
- return members.length > 0 ? [members[0].id] : [];
2117
+ return {
2118
+ ...value,
2119
+ agents: value.agents.filter((agent) => visible2.agents.has(agent.id)),
2120
+ channels: value.channels.filter((channel) => visible2.channels.has(channel.id))
2121
+ };
1221
2122
  }
1222
- ChannelsUtil.targets = targets;
1223
- function authorName(team, author, labels) {
1224
- if (author === SYSTEM) {
1225
- return "channel";
1226
- }
1227
- if (author === USER) {
1228
- return labels.user;
1229
- }
1230
- if (author === TA) {
1231
- return labels.ta;
2123
+ TeamViewUtil.team = team;
2124
+ function byId(value, seen) {
2125
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
2126
+ return value;
1232
2127
  }
1233
- return team.agents.find((agent) => agent.id === author)?.name ?? author;
2128
+ return Object.fromEntries(Object.entries(value).filter(([id]) => seen.has(id)));
1234
2129
  }
1235
- ChannelsUtil.authorName = authorName;
1236
- function systemPrompt(agent) {
1237
- return [
1238
- `You are ${agent.name}, ${AGENT_MARK}. Your role: ${agent.role}`,
1239
- "You work with the user, Ta and other agents in channels. A message for you starts with a <context> block: the channel, its members, the recent messages and who speaks to you; answer what follows the block.",
1240
- "Do the part of the work your role covers with your tools, then answer in a few sentences: your answer is posted to the channel as it is.",
1241
- "To hand work to another member, write @ and their name in your answer; name nobody when the work is done or you need the user.",
1242
- NOTICE_RULE
1243
- ].join(`
1244
- `);
2130
+ TeamViewUtil.byId = byId;
2131
+ })(TeamViewUtil ||= {});
2132
+
2133
+ // web-src/team-store.ts
2134
+ class TeamStore {
2135
+ host;
2136
+ team = ChannelsUtil.emptyTeam();
2137
+ queue = { jobs: [], rounds: {} };
2138
+ working = {};
2139
+ answered;
2140
+ messages = new Map;
2141
+ reading = new Map;
2142
+ agents = new Map;
2143
+ started = new Set;
2144
+ waiting = new Map;
2145
+ opening = new Map;
2146
+ settling = new Set;
2147
+ options;
2148
+ disposed = false;
2149
+ constructor(host, options = {}) {
2150
+ this.host = host;
2151
+ this.options = { pollMs: 300, timeoutMs: 15 * 60 * 1000, ...options };
1245
2152
  }
1246
- ChannelsUtil.systemPrompt = systemPrompt;
1247
- function setNotice(team, input) {
1248
- const before = channelOf(team, input.channel);
1249
- const text = typeof input.text === "string" ? input.text.replace(/\r\n/g, `
1250
- `).trim() : "";
1251
- if (text.length > MAX_NOTICE) {
1252
- throw new Error(`The notice is too long (${text.length} characters, ${MAX_NOTICE} at most): keep it short, and drop to-dos done long ago.`);
2153
+ get state() {
2154
+ return this.team;
2155
+ }
2156
+ async shareAgent(ref, color) {
2157
+ const agent = ChannelsUtil.findAgent(this.team, String(ref ?? ""));
2158
+ if (!agent) {
2159
+ throw new Error(`No agent is ${String(ref)}.`);
1253
2160
  }
1254
- if (text === (before.notice?.text ?? "")) {
1255
- return { team, channel: before, before, changed: false };
2161
+ const card = JSON.stringify(AgentCards.card(agent, typeof color === "string" ? color : undefined));
2162
+ const cards = await this.get(Keys.CARDS) ?? {};
2163
+ const kept = cards[agent.id];
2164
+ const live = kept ? (await this.host.shares.list()).find((share2) => share2.id === kept.share) : undefined;
2165
+ if (live && kept?.card === card) {
2166
+ return live;
1256
2167
  }
1257
- const channel = { ...before };
1258
- if (text) {
1259
- channel.notice = { text, at: input.at ?? Date.now(), by: input.by };
1260
- } else {
1261
- delete channel.notice;
2168
+ if (live) {
2169
+ await this.host.shares.remove(live.id);
1262
2170
  }
1263
- return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before, changed: true };
2171
+ const share = await this.host.shares.create({
2172
+ kind: AgentCards.KIND,
2173
+ title: `@${agent.name}`,
2174
+ type: "application/json",
2175
+ data: new TextEncoder().encode(card),
2176
+ access: "link",
2177
+ days: CARD_DAYS,
2178
+ offline: true
2179
+ });
2180
+ await this.set(Keys.CARDS, { ...this.liveCards(cards), [agent.id]: { share: share.id, card } });
2181
+ return share;
1264
2182
  }
1265
- ChannelsUtil.setNotice = setNotice;
1266
- function prompt(team, channel, history, message, agent) {
1267
- const labels = { user: "user", ta: "Ta" };
1268
- const members = channel.members.map((id) => team.agents.find((other) => other.id === id)).filter((other) => !!other).map((other) => `@${other.name}${other.id === agent.id ? " (you)" : ""}: ${firstLine(other.role)}`);
1269
- const before = history.filter((item) => item.id !== message.id && !item.failed && !item.notice).slice(-CONTEXT_MESSAGES);
1270
- const lines = [`[#${channel.name}]${channel.topic ? ` ${channel.topic}` : ""}`, "Members:", ...members.map((line) => `- ${line}`)];
1271
- if (channel.notice) {
1272
- lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
1273
- }
1274
- if (before.length > 0) {
1275
- lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
2183
+ async stopCard(ref) {
2184
+ const agent = ChannelsUtil.findAgent(this.team, String(ref ?? ""));
2185
+ const cards = await this.get(Keys.CARDS) ?? {};
2186
+ const kept = agent && cards[agent.id];
2187
+ if (!agent || !kept) {
2188
+ return false;
1276
2189
  }
1277
- lines.push("", `${authorName(team, message.author, labels)} to you:`);
1278
- const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels).replace(/[\]\n]/g, " ")}`;
1279
- lines.push(`[ta:from ${NAME} #${channel.name}${speaker}]`);
1280
- return `<context>
1281
- ${lines.join(`
1282
- `)}
1283
- </context>
1284
- ${message.text}`;
2190
+ const { [agent.id]: _gone, ...rest } = cards;
2191
+ await this.set(Keys.CARDS, this.liveCards(rest));
2192
+ return this.host.shares.remove(kept.share);
1285
2193
  }
1286
- ChannelsUtil.prompt = prompt;
1287
- function append(messages, message) {
1288
- const next = [...messages, message];
1289
- return next.length > MAX_MESSAGES ? next.slice(next.length - MAX_MESSAGES) : next;
2194
+ liveCards(cards) {
2195
+ return Object.fromEntries(Object.entries(cards).filter(([id]) => this.team.agents.some((agent) => agent.id === id)));
1290
2196
  }
1291
- ChannelsUtil.append = append;
1292
- function summary(team) {
1293
- if (team.agents.length === 0) {
1294
- return "No agents and no channels yet.";
2197
+ async openCard(link, password) {
2198
+ const content = await this.host.shares.open(String(link ?? ""), typeof password === "string" && password ? password : undefined);
2199
+ const card = content.kind === AgentCards.KIND ? AgentCards.parse(content.data) : undefined;
2200
+ if (!card) {
2201
+ throw new Error("This link shares no card of an agent.");
1295
2202
  }
1296
- const name = (id) => team.agents.find((agent) => agent.id === id)?.name ?? id;
1297
- const agents = team.agents.map((agent) => `- @${agent.name}: ${firstLine(agent.role)}`);
1298
- const channels = team.channels.map((channel) => `- #${channel.name}${channel.topic ? ` (${channel.topic})` : ""}: ${channel.members.map((id) => `@${name(id)}`).join(", ")}${channel.muted?.length ? `; muted by the user, answering nothing: ${channel.muted.map((id) => `@${name(id)}`).join(", ")}` : ""}${channel.notice ? `
1299
- notice: ${channel.notice.text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`);
1300
- return ["Agents:", ...agents, "", "Channels:", ...channels.length > 0 ? channels : ["none yet"]].join(`
1301
- `);
1302
- }
1303
- ChannelsUtil.summary = summary;
1304
- function transcript(team, messages) {
1305
- const labels = { user: "user", ta: "Ta" };
1306
- return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${item.text}`).join(`
1307
-
1308
- `);
2203
+ return card;
1309
2204
  }
1310
- ChannelsUtil.transcript = transcript;
1311
- function markdown(agent, messages, labels) {
1312
- const parts = [`# ${agent.name}`, "", `> ${firstLine(agent.role)}`];
1313
- for (const message of messages) {
1314
- const { role, content } = message ?? {};
1315
- if (role !== "user" && role !== "assistant") {
1316
- continue;
1317
- }
1318
- const text = (typeof content === "string" ? content : Array.isArray(content) ? content.map((block) => block?.type === "text" ? String(block.text ?? "") : "").join("") : "").replace(/^<context>\n?[\s\S]*?\n?<\/context>\n?/, "").trim();
1319
- if (text) {
1320
- parts.push("", `## ${role === "user" ? labels.user : agent.name}`, "", text);
1321
- }
2205
+ waitingFor(round) {
2206
+ let waiting = this.waiting.get(round);
2207
+ if (!waiting) {
2208
+ waiting = { replies: [], waiters: [] };
2209
+ this.waiting.set(round, waiting);
1322
2210
  }
1323
- return `${parts.join(`
1324
- `)}
1325
- `;
2211
+ return waiting;
1326
2212
  }
1327
- ChannelsUtil.markdown = markdown;
1328
- function channelMarkdown(team, channel, messages, labels) {
1329
- const parts = [`# #${channel.name}`];
1330
- if (channel.topic) {
1331
- parts.push("", `> ${firstLine(channel.topic)}`);
2213
+ async setAnswered(agentId, at) {
2214
+ this.answered ??= await this.get(Keys.ANSWERED) ?? {};
2215
+ const known = new Set(this.team.agents.map((agent) => agent.id));
2216
+ const kept = Object.fromEntries(Object.entries(this.answered).filter(([id]) => known.has(id)));
2217
+ this.answered = { ...kept, [agentId]: at };
2218
+ await this.set(Keys.ANSWERED, this.answered);
2219
+ }
2220
+ async pinDirectories() {
2221
+ const loose = this.team.agents.filter((agent) => !agent.cwd);
2222
+ if (loose.length === 0) {
2223
+ return;
1332
2224
  }
1333
- for (const message of messages) {
1334
- const text = message.text.trim();
1335
- if (text && message.author !== SYSTEM) {
1336
- parts.push("", `## ${authorName(team, message.author, labels)}${message.failed ? " (failed)" : ""}`, "", text);
1337
- }
2225
+ const serverCwd = (await this.host.getServerInfo()).cwd;
2226
+ const pinned = new Map;
2227
+ for (const agent of loose) {
2228
+ pinned.set(agent.id, agent.sessionFile && await this.host.sessionCwd(agent.sessionFile) || serverCwd);
1338
2229
  }
1339
- return `${parts.join(`
1340
- `)}
1341
- `;
2230
+ await this.saveTeam({ ...this.team, agents: this.team.agents.map((agent) => pinned.has(agent.id) ? { ...agent, cwd: pinned.get(agent.id) } : agent) });
1342
2231
  }
1343
- ChannelsUtil.channelMarkdown = channelMarkdown;
1344
- function firstLine(text) {
1345
- return text.split(`
1346
- `)[0];
2232
+ session(agent) {
2233
+ let opening = this.opening.get(agent.id);
2234
+ if (!opening) {
2235
+ opening = this.openSession(agent).finally(() => this.opening.delete(agent.id));
2236
+ this.opening.set(agent.id, opening);
2237
+ }
2238
+ return opening;
1347
2239
  }
1348
- })(ChannelsUtil ||= {});
1349
- var NOTICE_RULE = [
1350
- "A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
1351
- `When the talk settles a decision or a convention, or adds, assigns or finishes a to-do, update it with update_channel_notice: the whole notice, short, under the headings ### ${NOTICE_HEADINGS.zh.join(" / ")} (### ${NOTICE_HEADINGS.en.join(" / ")} in English), in the language of the channel, to-dos as - [ ] or - [x] with who does them. The lead keeps it most; leave it for small talk.`
1352
- ].join(`
1353
- `);
1354
- var NoticeUtil;
1355
- ((NoticeUtil) => {
1356
- const PARTS = {
1357
- 决定: "decisions",
1358
- decisions: "decisions",
1359
- 约定: "conventions",
1360
- conventions: "conventions",
1361
- 待办: "todo",
1362
- "to do": "todo",
1363
- todo: "todo",
1364
- "to-do": "todo"
1365
- };
1366
- function counts(text) {
1367
- const counts2 = { decisions: 0, conventions: 0, todo: 0, done: 0 };
1368
- let part;
1369
- for (const line of text.split(/\r?\n/)) {
1370
- const heading = /^\s*#{1,6}\s+(.+?)\s*#*\s*$/.exec(line) ?? /^\s*\*\*(.+?)\*\*\s*[::]?\s*$/.exec(line);
1371
- if (heading) {
1372
- part = PARTS[heading[1].replace(/[::]$/, "").trim().toLowerCase()];
1373
- continue;
1374
- }
1375
- const item = /^\s*(?:[-*+]|\d+[.)])\s+(\[( |x|X)\]\s+)?\S/.exec(line);
1376
- if (!part || !item) {
1377
- continue;
2240
+ async openSession(agent) {
2241
+ if (agent.sessionFile) {
2242
+ const open = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
2243
+ if (open) {
2244
+ return open.sessionId;
1378
2245
  }
1379
- if (part === "todo" && item[2] && item[2] !== " ") {
1380
- counts2.done++;
1381
- } else {
1382
- counts2[part]++;
2246
+ }
2247
+ const cwd = agent.cwd ?? (await this.host.getServerInfo()).cwd;
2248
+ const options = { cwd, appendSystemPrompt: ChannelsText.systemPrompt(agent), group: NAME };
2249
+ if (agent.sessionFile) {
2250
+ try {
2251
+ return (await this.host.openSession({ ...options, sessionFile: agent.sessionFile })).sessionId;
2252
+ } catch (error) {
2253
+ if (TaErrorUtil.code(error) !== TaErrorCode.INVALID_ARGUMENT) {
2254
+ throw error;
2255
+ }
1383
2256
  }
1384
2257
  }
1385
- return counts2;
2258
+ const { sessionId } = await this.host.openSession(options);
2259
+ await this.host.setSessionName(sessionId, agent.name);
2260
+ const { sessionFile } = await this.host.getState(sessionId);
2261
+ if (sessionFile) {
2262
+ await this.saveTeam({ ...this.team, agents: this.team.agents.map((other) => other.id === agent.id ? { ...other, sessionFile } : other) });
2263
+ }
2264
+ return sessionId;
1386
2265
  }
1387
- NoticeUtil.counts = counts;
1388
- function firstLine(text) {
1389
- for (const line of text.split(/\r?\n/)) {
1390
- const item = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+)$/.exec(line);
1391
- if (item) {
1392
- return item[1].replace(/[*_`~]+/g, "").trim();
2266
+ async settled(sessionId, before) {
2267
+ const start = Date.now();
2268
+ for (;; ) {
2269
+ const state = await this.host.getState(sessionId);
2270
+ if (!state.isStreaming && state.pendingMessageCount === 0 && state.messageCount > before) {
2271
+ return;
2272
+ }
2273
+ if (Date.now() - start > this.options.timeoutMs) {
2274
+ throw new Error("No answer in time; the agent may still be working in its session.");
1393
2275
  }
2276
+ await new Promise((resolve) => setTimeout(resolve, this.options.pollMs));
1394
2277
  }
1395
- return text.split(/\r?\n/).find((line) => line.trim() && !/^\s*#/.test(line))?.trim() ?? "";
1396
- }
1397
- NoticeUtil.firstLine = firstLine;
1398
- })(NoticeUtil ||= {});
1399
-
1400
- // web-src/agent-cards.ts
1401
- var AgentCards;
1402
- ((AgentCards) => {
1403
- AgentCards.KIND = RELAY_AGENT_KIND;
1404
- AgentCards.MARK = "[ta-channels:card]";
1405
- function card(agent, color) {
1406
- const redactor = new Redactor;
1407
- const role = redactor.text(agent.role);
1408
- return {
1409
- v: 1,
1410
- name: agent.name,
1411
- role,
1412
- mark: agent.mark,
1413
- ...agent.face !== undefined ? { face: agent.face } : {},
1414
- ...color && /^#[0-9a-fA-F]{6}$/.test(color) ? { color } : {},
1415
- ...redactor.count ? { redacted: redactor.count } : {}
1416
- };
1417
- }
1418
- AgentCards.card = card;
1419
- function parse(data) {
1420
- return RelayAgentCards.parse(data);
1421
2278
  }
1422
- AgentCards.parse = parse;
1423
- function freeName(team, name) {
1424
- const base = (name.trim().replace(/\s+/g, "-") || "agent").slice(0, MAX_NAME - 3);
1425
- if (!ChannelsUtil.findAgent(team, base)) {
1426
- return base;
2279
+ messagesOf(channelId) {
2280
+ const known = this.messages.get(channelId);
2281
+ if (known) {
2282
+ return Promise.resolve(known);
1427
2283
  }
1428
- for (let n = 2;; n++) {
1429
- if (!ChannelsUtil.findAgent(team, `${base}-${n}`)) {
1430
- return `${base}-${n}`;
1431
- }
2284
+ let reading = this.reading.get(channelId);
2285
+ if (!reading) {
2286
+ reading = this.get(Keys.messages(channelId)).then((stored) => {
2287
+ const messages = this.messages.get(channelId) ?? stored ?? [];
2288
+ this.messages.set(channelId, messages);
2289
+ return messages;
2290
+ });
2291
+ this.reading.set(channelId, reading);
1432
2292
  }
2293
+ return reading;
1433
2294
  }
1434
- AgentCards.freeName = freeName;
1435
- function adapt(cwd, language2) {
1436
- const context = [
1437
- AgentCards.MARK,
1438
- `You were just added to this Ta from a card someone shared: the role in your instructions is theirs, written for their own work. Fit it to the project of your directory (${cwd}): look at it first (its README, manifests such as package.json, its layout, how it builds and tests), then rewrite your role for it, keeping what you are for, and save it with update_my_role. Then tell the user in a few sentences, in ${TaLanguageUtil.pick(language2, { "zh-CN": "Chinese", "zh-TW": "Traditional Chinese", "en-US": "English", "ja-JP": "Japanese" })}, what you changed and what you can do here. Change no files.`
1439
- ].join(`
1440
- `);
1441
- return `<context>
1442
- ${context}
1443
- </context>
1444
- ${TaLanguageUtil.pick(language2, { "zh-CN": "看看这个项目,把你的职责调整得贴合这里", "zh-TW": "看看這個專案,把你的職責調整得貼合這裡", "en-US": "Look at this project and fit your role to it", "ja-JP": "このプロジェクトを見て、ロールをそれに適応させてください" })}`;
1445
- }
1446
- AgentCards.adapt = adapt;
1447
- })(AgentCards ||= {});
1448
-
1449
- // web-src/handoff.ts
1450
- var HandOff;
1451
- ((HandOff) => {
1452
- HandOff.TOOL = "hand_off";
1453
- HandOff.CARD = "ta-channels-handoff";
1454
- HandOff.BLOCK = "ta-handoff";
1455
- const MARK = /\[ta-handoff:([^\]\s]+)\]/;
1456
- HandOff.DEFINITION = {
1457
- name: HandOff.TOOL,
1458
- label: "Hand off",
1459
- description: "Hands the work of this conversation over to one of the user's agents (@name) or channels (#name), when the user says so (hand it to, give it to, 交给, 转给). The other side does not see this conversation: write the brief it needs to go on, in the user's language: the goal, what is done and decided, what is left or blocks, the files, branches, commands and links that matter. It works on it in its own conversation, which the user follows; you stop working on it here. list_channels lists the team. After the call, say in one line to whom it went.",
1460
- promptSnippet: "Hand the work over to one of the user's agents or channels",
1461
- parameters: {
1462
- type: "object",
1463
- properties: {
1464
- to: { type: "string", description: "@name of an agent or #name of a channel." },
1465
- brief: { type: "string", description: "Complete in itself: the receiver sees only this." }
1466
- },
1467
- required: ["to", "brief"]
2295
+ async append(channelId, message) {
2296
+ if (!this.team.channels.some((channel) => channel.id === channelId)) {
2297
+ return message;
1468
2298
  }
1469
- };
1470
- function ref(target) {
1471
- return `${target.kind === "agent" ? "@" : "#"}${target.name}`;
1472
- }
1473
- HandOff.ref = ref;
1474
- function ask(language2, to) {
1475
- const fence = "```";
1476
- const context = [
1477
- `[ta-handoff:${to}]`,
1478
- `The user hands the work of this conversation over to ${to}, which does not see this conversation.`,
1479
- `- Write the brief it needs to go on: the goal, what is done and decided, what is left or blocks, the files, branches, commands and links that matter, in the user's language. Leave out what was only tried and dropped.`,
1480
- `- With the tool ${HandOff.TOOL}, call it with to "${to}" and the brief, then say in one line that it went.`,
1481
- `- Without it, say in one line what you hand over, then end your answer with the brief in a fenced block of the language ${HandOff.BLOCK}, which Ta reads to hand it over (a longer fence when the brief has one of its own):`,
1482
- `${fence}${HandOff.BLOCK}`,
1483
- "<the brief>",
1484
- fence,
1485
- `- When the conversation holds nothing to hand over yet, say so and ask what ${to} should do.`
1486
- ].join(`
1487
- `);
1488
- const line = TaLanguageUtil.pick(language2, {
1489
- "zh-CN": `把这件事交给 ${to}`,
1490
- "zh-TW": `把這件事交給 ${to}`,
1491
- "en-US": `Hand this over to ${to}`,
1492
- "ja-JP": `これを ${to} に引き継ぐ`
1493
- });
1494
- return `<context>
1495
- ${context}
1496
- </context>
1497
- ${line}`;
2299
+ await this.messagesOf(channelId);
2300
+ const messages = ChannelsUtil.append(this.messages.get(channelId) ?? [], message);
2301
+ this.messages.set(channelId, messages);
2302
+ await this.set(Keys.messages(channelId), messages);
2303
+ return message;
1498
2304
  }
1499
- HandOff.ask = ask;
1500
- function asked(text) {
1501
- return MARK.exec(text)?.[1];
2305
+ async saveTeam(team) {
2306
+ this.team = team;
2307
+ this.linkSessions();
2308
+ await this.set(Keys.TEAM, team);
1502
2309
  }
1503
- HandOff.asked = asked;
1504
- function find(text) {
1505
- const lines = text.split(/\r?\n/);
1506
- let found;
1507
- for (let index = 0;index < lines.length; index++) {
1508
- const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
1509
- if (open?.[2] !== HandOff.BLOCK) {
1510
- continue;
1511
- }
1512
- const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
1513
- const end = lines.findIndex((line, at) => at > index && close.test(line));
1514
- found = lines.slice(index + 1, end < 0 ? lines.length : end);
1515
- index = end < 0 ? lines.length : end;
2310
+ shareWithMembers() {
2311
+ const team = this.host.team;
2312
+ if (!team) {
2313
+ return;
1516
2314
  }
1517
- const brief = found?.join(`
1518
- `).trim();
1519
- return brief || undefined;
1520
- }
1521
- HandOff.find = find;
1522
- function message(origin, brief, language2) {
1523
- const title = origin.title?.trim() || TaLanguageUtil.pick(language2, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
1524
- const head = TaLanguageUtil.pick(language2, {
1525
- "zh-CN": `(交接自“${title}”)`,
1526
- "zh-TW": `(交接自「${title}」)`,
1527
- "en-US": `(Handed over from “${title}”)`,
1528
- "ja-JP": `(“${title}” から引き継ぎました)`
1529
- });
1530
- const context = [
1531
- "The user handed you this work from another conversation of theirs, which you do not see; the brief below is all it says. Go on from there in this conversation, which the user follows; ask them when the brief leaves out something you need.",
1532
- origin.sessionFile ? `That conversation is pi's session file ${origin.sessionFile}${origin.cwd ? `, working in ${origin.cwd}` : ""}: read it only when the brief is not enough.` : ""
1533
- ].filter(Boolean).join(`
1534
- `);
1535
- return `<context>
1536
- ${context}
1537
- </context>
1538
- ${head}
1539
-
1540
- ${brief.trim()}`;
1541
- }
1542
- HandOff.message = message;
1543
- function channelText(origin, brief, language2) {
1544
- const title = origin.title?.trim() || TaLanguageUtil.pick(language2, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
1545
- return `${TaLanguageUtil.pick(language2, {
1546
- "zh-CN": `(交接自“${title}”)`,
1547
- "zh-TW": `(交接自「${title}」)`,
1548
- "en-US": `(Handed over from “${title}”)`,
1549
- "ja-JP": `(“${title}” から引き継ぎました)`
1550
- })}
1551
-
1552
- ${brief.trim()}`;
1553
- }
1554
- HandOff.channelText = channelText;
1555
- function serverLanguage(env = typeof process === "undefined" ? {} : process.env) {
1556
- return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
1557
- }
1558
- HandOff.serverLanguage = serverLanguage;
1559
- function result(target) {
1560
- return `Handed over to ${ref(target)}; it works on it in its own conversation, which the user follows. Do not go on with it here.`;
1561
- }
1562
- HandOff.result = result;
1563
- })(HandOff ||= {});
1564
-
1565
- // web-src/team-view.ts
1566
- var TeamViewUtil;
1567
- ((TeamViewUtil) => {
1568
- function visible(team2, can) {
1569
- const channels = new Set(team2.channels.filter((channel) => can("channel", channel.id)).map((channel) => channel.id));
1570
- const agents = new Set(team2.agents.filter((agent) => can("agent", agent.id)).map((agent) => agent.id));
1571
- for (const channel of team2.channels) {
1572
- if (channels.has(channel.id)) {
1573
- for (const member of channel.members) {
1574
- agents.add(member);
2315
+ const can = (principal, kind, id) => team.can(principal, kind === "agent" ? "agent.view" : "channel.view", { kind, id });
2316
+ team.shareData(NAME, {
2317
+ keys: [Keys.TEAM, Keys.WORKING, Keys.ANSWERED, Keys.FOCUS, Keys.MESSAGES],
2318
+ view: (principal, key, value) => {
2319
+ const visible = TeamViewUtil.visible(this.team, (kind, id) => can(principal, kind, id));
2320
+ if (key === Keys.TEAM) {
2321
+ return TeamViewUtil.team(value, visible);
2322
+ }
2323
+ if (key.startsWith(Keys.MESSAGES)) {
2324
+ return visible.channels.has(key.slice(Keys.MESSAGES.length)) ? value : undefined;
2325
+ }
2326
+ if (key === Keys.FOCUS) {
2327
+ return visible.channels.has(value?.channelId ?? "") ? value : undefined;
1575
2328
  }
2329
+ return TeamViewUtil.byId(value, key === Keys.WORKING ? visible.channels : visible.agents);
1576
2330
  }
1577
- }
1578
- return { agents, channels };
2331
+ });
2332
+ this.linkSessions();
1579
2333
  }
1580
- TeamViewUtil.visible = visible;
1581
- function team(value, visible2) {
1582
- if (!value) {
1583
- return value;
2334
+ linkSessions() {
2335
+ for (const agent of this.team.agents) {
2336
+ if (agent.sessionFile) {
2337
+ this.host.team?.link(agent.sessionFile, { kind: "agent", id: agent.id });
2338
+ }
1584
2339
  }
1585
- return {
1586
- ...value,
1587
- agents: value.agents.filter((agent) => visible2.agents.has(agent.id)),
1588
- channels: value.channels.filter((channel) => visible2.channels.has(channel.id))
1589
- };
1590
2340
  }
1591
- TeamViewUtil.team = team;
1592
- function byId(value, seen) {
1593
- if (!value || typeof value !== "object" || Array.isArray(value)) {
1594
- return value;
1595
- }
1596
- return Object.fromEntries(Object.entries(value).filter(([id]) => seen.has(id)));
2341
+ async setWorking(channelId, agentId, on) {
2342
+ const others = (this.working[channelId] ?? []).filter((id) => id !== agentId);
2343
+ this.working = { ...this.working, [channelId]: on ? [...others, agentId] : others };
2344
+ await this.set(Keys.WORKING, this.working);
1597
2345
  }
1598
- TeamViewUtil.byId = byId;
1599
- })(TeamViewUtil ||= {});
1600
-
1601
- // web-src/team.ts
1602
- class TeamService {
1603
- host;
1604
- team = ChannelsUtil.emptyTeam();
1605
- queue = { jobs: [], rounds: {} };
1606
- working = {};
1607
- answered;
1608
- messages = new Map;
1609
- reading = new Map;
1610
- agents = new Map;
1611
- started = new Set;
1612
- waiting = new Map;
1613
- opening = new Map;
1614
- settling = new Set;
1615
- options;
1616
- disposed = false;
1617
- constructor(host, options = {}) {
1618
- this.host = host;
1619
- this.options = { pollMs: 300, timeoutMs: 15 * 60 * 1000, ...options };
2346
+ async get(key) {
2347
+ return await this.host.getExtensionData(NAME, key) ?? undefined;
1620
2348
  }
1621
- get state() {
1622
- return this.team;
2349
+ set(key, value) {
2350
+ return this.host.setExtensionData(NAME, key, value);
1623
2351
  }
2352
+ }
2353
+
2354
+ // web-src/team.ts
2355
+ class TeamService extends TeamStore {
1624
2356
  async start() {
1625
2357
  this.team = await this.get(Keys.TEAM) ?? ChannelsUtil.emptyTeam();
1626
2358
  this.shareWithMembers();
@@ -1705,55 +2437,6 @@ class TeamService {
1705
2437
  agentOf(sessionFile) {
1706
2438
  return sessionFile ? this.team.agents.find((agent) => agent.sessionFile === sessionFile) : undefined;
1707
2439
  }
1708
- async shareAgent(ref, color) {
1709
- const agent = ChannelsUtil.findAgent(this.team, String(ref ?? ""));
1710
- if (!agent) {
1711
- throw new Error(`No agent is ${String(ref)}.`);
1712
- }
1713
- const card = JSON.stringify(AgentCards.card(agent, typeof color === "string" ? color : undefined));
1714
- const cards = await this.get(Keys.CARDS) ?? {};
1715
- const kept = cards[agent.id];
1716
- const live = kept ? (await this.host.shares.list()).find((share2) => share2.id === kept.share) : undefined;
1717
- if (live && kept?.card === card) {
1718
- return live;
1719
- }
1720
- if (live) {
1721
- await this.host.shares.remove(live.id);
1722
- }
1723
- const share = await this.host.shares.create({
1724
- kind: AgentCards.KIND,
1725
- title: `@${agent.name}`,
1726
- type: "application/json",
1727
- data: new TextEncoder().encode(card),
1728
- access: "link",
1729
- days: CARD_DAYS,
1730
- offline: true
1731
- });
1732
- await this.set(Keys.CARDS, { ...this.liveCards(cards), [agent.id]: { share: share.id, card } });
1733
- return share;
1734
- }
1735
- async stopCard(ref) {
1736
- const agent = ChannelsUtil.findAgent(this.team, String(ref ?? ""));
1737
- const cards = await this.get(Keys.CARDS) ?? {};
1738
- const kept = agent && cards[agent.id];
1739
- if (!agent || !kept) {
1740
- return false;
1741
- }
1742
- const { [agent.id]: _gone, ...rest } = cards;
1743
- await this.set(Keys.CARDS, this.liveCards(rest));
1744
- return this.host.shares.remove(kept.share);
1745
- }
1746
- liveCards(cards) {
1747
- return Object.fromEntries(Object.entries(cards).filter(([id]) => this.team.agents.some((agent) => agent.id === id)));
1748
- }
1749
- async openCard(link, password) {
1750
- const content = await this.host.shares.open(String(link ?? ""), typeof password === "string" && password ? password : undefined);
1751
- const card = content.kind === AgentCards.KIND ? AgentCards.parse(content.data) : undefined;
1752
- if (!card) {
1753
- throw new Error("This link shares no card of an agent.");
1754
- }
1755
- return card;
1756
- }
1757
2440
  async addFromCard(input, language2 = HandOff.serverLanguage()) {
1758
2441
  const card = await this.openCard(input.link, input.password);
1759
2442
  const agent = await this.createAgent({ name: AgentCards.freeName(this.team, card.name), role: card.role, cwd: input.cwd, face: card.face });
@@ -1909,7 +2592,7 @@ class TeamService {
1909
2592
  async handOn(channel, message, hops, round) {
1910
2593
  const current = this.queue.rounds[round]?.round ?? ChannelsUtil.newRound();
1911
2594
  const messages = await this.messagesOf(channel.id);
1912
- const targets = ChannelsUtil.targets(this.team, channel, message).filter((agentId) => !this.queue.jobs.some((job) => job.messageId === message.id && job.agentId === agentId) && !messages.some((item) => item.replyTo === message.id && item.author === agentId));
2595
+ const targets = ChannelsText.targets(this.team, channel, message).filter((agentId) => !this.queue.jobs.some((job) => job.messageId === message.id && job.agentId === agentId) && !messages.some((item) => item.replyTo === message.id && item.author === agentId));
1913
2596
  const limited = ChannelsUtil.limit(current, targets, hops);
1914
2597
  const jobs = limited.allowed.map((agentId) => ({
1915
2598
  id: ChannelsUtil.newId("job"),
@@ -1995,14 +2678,6 @@ class TeamService {
1995
2678
  resolve(waiting.replies);
1996
2679
  }
1997
2680
  }
1998
- waitingFor(round) {
1999
- let waiting = this.waiting.get(round);
2000
- if (!waiting) {
2001
- waiting = { replies: [], waiters: [] };
2002
- this.waiting.set(round, waiting);
2003
- }
2004
- return waiting;
2005
- }
2006
2681
  async answer(channel, message, agentId, by) {
2007
2682
  await this.setWorking(channel.id, agentId, true);
2008
2683
  let text;
@@ -2019,13 +2694,6 @@ class TeamService {
2019
2694
  }
2020
2695
  return this.append(channel.id, { id: ChannelsUtil.newId("message"), author: agentId, text, at: Date.now(), replyTo: message.id, failed });
2021
2696
  }
2022
- async setAnswered(agentId, at) {
2023
- this.answered ??= await this.get(Keys.ANSWERED) ?? {};
2024
- const known = new Set(this.team.agents.map((agent) => agent.id));
2025
- const kept = Object.fromEntries(Object.entries(this.answered).filter(([id]) => known.has(id)));
2026
- this.answered = { ...kept, [agentId]: at };
2027
- await this.set(Keys.ANSWERED, this.answered);
2028
- }
2029
2697
  async ask(channel, message, agentId) {
2030
2698
  const agent = this.team.agents.find((candidate) => candidate.id === agentId);
2031
2699
  if (!agent) {
@@ -2034,7 +2702,7 @@ class TeamService {
2034
2702
  const sessionId = await this.session(agent);
2035
2703
  const before = await this.host.getState(sessionId);
2036
2704
  const history = await this.messagesOf(channel.id);
2037
- const input = { clientMessageId: `${message.id}:${agent.id}`, message: ChannelsUtil.prompt(this.team, channel, history, message, agent) };
2705
+ const input = { clientMessageId: `${message.id}:${agent.id}`, message: ChannelsText.prompt(this.team, channel, history, message, agent) };
2038
2706
  await this.host.prompt(sessionId, input);
2039
2707
  await this.settled(sessionId, before.messageCount);
2040
2708
  const { text } = await this.host.getLastAssistantText(sessionId);
@@ -2043,127 +2711,6 @@ class TeamService {
2043
2711
  }
2044
2712
  return text.trim();
2045
2713
  }
2046
- async pinDirectories() {
2047
- const loose = this.team.agents.filter((agent) => !agent.cwd);
2048
- if (loose.length === 0) {
2049
- return;
2050
- }
2051
- const serverCwd = (await this.host.getServerInfo()).cwd;
2052
- const pinned = new Map;
2053
- for (const agent of loose) {
2054
- pinned.set(agent.id, agent.sessionFile && await this.host.sessionCwd(agent.sessionFile) || serverCwd);
2055
- }
2056
- await this.saveTeam({ ...this.team, agents: this.team.agents.map((agent) => pinned.has(agent.id) ? { ...agent, cwd: pinned.get(agent.id) } : agent) });
2057
- }
2058
- session(agent) {
2059
- let opening = this.opening.get(agent.id);
2060
- if (!opening) {
2061
- opening = this.openSession(agent).finally(() => this.opening.delete(agent.id));
2062
- this.opening.set(agent.id, opening);
2063
- }
2064
- return opening;
2065
- }
2066
- async openSession(agent) {
2067
- if (agent.sessionFile) {
2068
- const open = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
2069
- if (open) {
2070
- return open.sessionId;
2071
- }
2072
- }
2073
- const cwd = agent.cwd ?? (await this.host.getServerInfo()).cwd;
2074
- const options = { cwd, appendSystemPrompt: ChannelsUtil.systemPrompt(agent), group: NAME };
2075
- if (agent.sessionFile) {
2076
- try {
2077
- return (await this.host.openSession({ ...options, sessionFile: agent.sessionFile })).sessionId;
2078
- } catch (error) {
2079
- if (TaErrorUtil.code(error) !== TaErrorCode.INVALID_ARGUMENT) {
2080
- throw error;
2081
- }
2082
- }
2083
- }
2084
- const { sessionId } = await this.host.openSession(options);
2085
- await this.host.setSessionName(sessionId, agent.name);
2086
- const { sessionFile } = await this.host.getState(sessionId);
2087
- if (sessionFile) {
2088
- await this.saveTeam({ ...this.team, agents: this.team.agents.map((other) => other.id === agent.id ? { ...other, sessionFile } : other) });
2089
- }
2090
- return sessionId;
2091
- }
2092
- async settled(sessionId, before) {
2093
- const start = Date.now();
2094
- for (;; ) {
2095
- const state = await this.host.getState(sessionId);
2096
- if (!state.isStreaming && state.pendingMessageCount === 0 && state.messageCount > before) {
2097
- return;
2098
- }
2099
- if (Date.now() - start > this.options.timeoutMs) {
2100
- throw new Error("No answer in time; the agent may still be working in its session.");
2101
- }
2102
- await new Promise((resolve) => setTimeout(resolve, this.options.pollMs));
2103
- }
2104
- }
2105
- messagesOf(channelId) {
2106
- const known = this.messages.get(channelId);
2107
- if (known) {
2108
- return Promise.resolve(known);
2109
- }
2110
- let reading = this.reading.get(channelId);
2111
- if (!reading) {
2112
- reading = this.get(Keys.messages(channelId)).then((stored) => {
2113
- const messages = this.messages.get(channelId) ?? stored ?? [];
2114
- this.messages.set(channelId, messages);
2115
- return messages;
2116
- });
2117
- this.reading.set(channelId, reading);
2118
- }
2119
- return reading;
2120
- }
2121
- async append(channelId, message) {
2122
- if (!this.team.channels.some((channel) => channel.id === channelId)) {
2123
- return message;
2124
- }
2125
- await this.messagesOf(channelId);
2126
- const messages = ChannelsUtil.append(this.messages.get(channelId) ?? [], message);
2127
- this.messages.set(channelId, messages);
2128
- await this.set(Keys.messages(channelId), messages);
2129
- return message;
2130
- }
2131
- async saveTeam(team) {
2132
- this.team = team;
2133
- this.linkSessions();
2134
- await this.set(Keys.TEAM, team);
2135
- }
2136
- shareWithMembers() {
2137
- const team = this.host.team;
2138
- if (!team) {
2139
- return;
2140
- }
2141
- const can = (principal, kind, id) => team.can(principal, kind === "agent" ? "agent.view" : "channel.view", { kind, id });
2142
- team.shareData(NAME, {
2143
- keys: [Keys.TEAM, Keys.WORKING, Keys.ANSWERED, Keys.FOCUS, Keys.MESSAGES],
2144
- view: (principal, key, value) => {
2145
- const visible = TeamViewUtil.visible(this.team, (kind, id) => can(principal, kind, id));
2146
- if (key === Keys.TEAM) {
2147
- return TeamViewUtil.team(value, visible);
2148
- }
2149
- if (key.startsWith(Keys.MESSAGES)) {
2150
- return visible.channels.has(key.slice(Keys.MESSAGES.length)) ? value : undefined;
2151
- }
2152
- if (key === Keys.FOCUS) {
2153
- return visible.channels.has(value?.channelId ?? "") ? value : undefined;
2154
- }
2155
- return TeamViewUtil.byId(value, key === Keys.WORKING ? visible.channels : visible.agents);
2156
- }
2157
- });
2158
- this.linkSessions();
2159
- }
2160
- linkSessions() {
2161
- for (const agent of this.team.agents) {
2162
- if (agent.sessionFile) {
2163
- this.host.team?.link(agent.sessionFile, { kind: "agent", id: agent.id });
2164
- }
2165
- }
2166
- }
2167
2714
  listChannels() {
2168
2715
  return this.team.channels.map((channel) => ({
2169
2716
  id: channel.id,
@@ -2172,17 +2719,6 @@ class TeamService {
2172
2719
  members: channel.members
2173
2720
  }));
2174
2721
  }
2175
- async setWorking(channelId, agentId, on) {
2176
- const others = (this.working[channelId] ?? []).filter((id) => id !== agentId);
2177
- this.working = { ...this.working, [channelId]: on ? [...others, agentId] : others };
2178
- await this.set(Keys.WORKING, this.working);
2179
- }
2180
- async get(key) {
2181
- return await this.host.getExtensionData(NAME, key) ?? undefined;
2182
- }
2183
- set(key, value) {
2184
- return this.host.setExtensionData(NAME, key, value);
2185
- }
2186
2722
  }
2187
2723
 
2188
2724
  // web-src/host.ts