@celljs/ta-host 4.8.0 → 4.9.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 (435) hide show
  1. package/README.en.md +33 -5
  2. package/README.md +33 -5
  3. package/cell.schema.json +4 -0
  4. package/cell.yml +2 -0
  5. package/esm/node/client-tool-broker.d.ts +11 -3
  6. package/esm/node/client-tool-broker.js +23 -3
  7. package/esm/node/host-protocol.d.ts +22 -1
  8. package/esm/node/host-protocol.js +1 -0
  9. package/esm/node/index.d.ts +4 -0
  10. package/esm/node/index.js +4 -0
  11. package/esm/node/live-run.d.ts +22 -0
  12. package/esm/node/live-run.js +58 -0
  13. package/esm/node/message-page.d.ts +17 -0
  14. package/esm/node/message-page.js +71 -0
  15. package/esm/node/package-server-impl.d.ts +9 -1
  16. package/esm/node/package-server-impl.js +16 -1
  17. package/esm/node/relay-bridge.d.ts +9 -1
  18. package/esm/node/relay-bridge.js +44 -4
  19. package/esm/node/session-catalog.d.ts +69 -0
  20. package/esm/node/session-catalog.js +211 -0
  21. package/esm/node/session-info-util.d.ts +4 -1
  22. package/esm/node/session-info-util.js +8 -3
  23. package/esm/node/settings-store.d.ts +1 -4
  24. package/esm/node/settings-store.js +11 -3
  25. package/esm/node/sign-in/access-server-impl.d.ts +19 -0
  26. package/esm/node/sign-in/access-server-impl.js +82 -0
  27. package/esm/node/sign-in/access-store.d.ts +65 -0
  28. package/esm/node/sign-in/access-store.js +175 -0
  29. package/esm/node/sign-in/index.d.ts +7 -0
  30. package/esm/node/sign-in/index.js +8 -0
  31. package/esm/node/sign-in/sign-in-flow.d.ts +58 -0
  32. package/esm/node/sign-in/sign-in-flow.js +104 -0
  33. package/esm/node/sign-in/sign-in-middleware.d.ts +10 -0
  34. package/esm/node/sign-in/sign-in-middleware.js +48 -0
  35. package/esm/node/sign-in/sign-in-pages.d.ts +31 -0
  36. package/esm/node/sign-in/sign-in-pages.js +118 -0
  37. package/esm/node/sign-in/sign-in-provider.d.ts +135 -0
  38. package/esm/node/sign-in/sign-in-provider.js +225 -0
  39. package/esm/node/sign-in/ta-sign-in.d.ts +10 -0
  40. package/esm/node/sign-in/ta-sign-in.js +32 -0
  41. package/esm/node/ta-access.d.ts +7 -0
  42. package/esm/node/ta-access.js +30 -1
  43. package/esm/node/ta-server-impl.d.ts +8 -3
  44. package/esm/node/ta-server-impl.js +25 -6
  45. package/esm/node/ta-session-factory.d.ts +1 -1
  46. package/esm/node/ta-session-factory.js +14 -4
  47. package/esm/node/ta-session-registry.d.ts +2 -0
  48. package/esm/node/ta-session-registry.js +23 -3
  49. package/esm/node/ta-session.d.ts +24 -2
  50. package/esm/node/ta-session.js +83 -6
  51. package/esm/node/temporary-packages.d.ts +46 -0
  52. package/esm/node/temporary-packages.js +114 -0
  53. package/esm/node/temporary-purge.d.ts +13 -0
  54. package/esm/node/temporary-purge.js +51 -0
  55. package/esm/node/web-extension-catalog.d.ts +28 -1
  56. package/esm/node/web-extension-catalog.js +173 -5
  57. package/esm/node/web-extension-util.d.ts +5 -1
  58. package/esm/node/web-extension-util.js +36 -5
  59. package/esm/node/workspace-service.js +1 -1
  60. package/lib/node/client-tool-broker.d.ts +11 -3
  61. package/lib/node/client-tool-broker.js +23 -3
  62. package/lib/node/host-protocol.d.ts +22 -1
  63. package/lib/node/host-protocol.js +2 -1
  64. package/lib/node/index.d.ts +4 -0
  65. package/lib/node/index.js +4 -0
  66. package/lib/node/live-run.d.ts +23 -0
  67. package/lib/node/live-run.js +62 -0
  68. package/lib/node/message-page.d.ts +18 -0
  69. package/lib/node/message-page.js +74 -0
  70. package/lib/node/package-server-impl.d.ts +9 -1
  71. package/lib/node/package-server-impl.js +15 -0
  72. package/lib/node/relay-bridge.d.ts +9 -1
  73. package/lib/node/relay-bridge.js +43 -3
  74. package/lib/node/session-catalog.d.ts +70 -0
  75. package/lib/node/session-catalog.js +214 -0
  76. package/lib/node/session-info-util.d.ts +4 -1
  77. package/lib/node/session-info-util.js +7 -2
  78. package/lib/node/settings-store.d.ts +1 -4
  79. package/lib/node/settings-store.js +11 -3
  80. package/lib/node/sign-in/access-server-impl.d.ts +20 -0
  81. package/lib/node/sign-in/access-server-impl.js +85 -0
  82. package/lib/node/sign-in/access-store.d.ts +66 -0
  83. package/lib/node/sign-in/access-store.js +179 -0
  84. package/lib/node/sign-in/index.d.ts +8 -0
  85. package/lib/node/sign-in/index.js +24 -0
  86. package/lib/node/sign-in/sign-in-flow.d.ts +59 -0
  87. package/lib/node/sign-in/sign-in-flow.js +108 -0
  88. package/lib/node/sign-in/sign-in-middleware.d.ts +11 -0
  89. package/lib/node/sign-in/sign-in-middleware.js +51 -0
  90. package/lib/node/sign-in/sign-in-pages.d.ts +32 -0
  91. package/lib/node/sign-in/sign-in-pages.js +121 -0
  92. package/lib/node/sign-in/sign-in-provider.d.ts +136 -0
  93. package/lib/node/sign-in/sign-in-provider.js +232 -0
  94. package/lib/node/sign-in/ta-sign-in.d.ts +11 -0
  95. package/lib/node/sign-in/ta-sign-in.js +35 -0
  96. package/lib/node/ta-access.d.ts +7 -0
  97. package/lib/node/ta-access.js +30 -1
  98. package/lib/node/ta-server-impl.d.ts +8 -3
  99. package/lib/node/ta-server-impl.js +24 -5
  100. package/lib/node/ta-session-factory.d.ts +1 -1
  101. package/lib/node/ta-session-factory.js +14 -4
  102. package/lib/node/ta-session-registry.d.ts +2 -0
  103. package/lib/node/ta-session-registry.js +23 -3
  104. package/lib/node/ta-session.d.ts +24 -2
  105. package/lib/node/ta-session.js +83 -6
  106. package/lib/node/temporary-packages.d.ts +47 -0
  107. package/lib/node/temporary-packages.js +118 -0
  108. package/lib/node/temporary-purge.d.ts +14 -0
  109. package/lib/node/temporary-purge.js +54 -0
  110. package/lib/node/web-extension-catalog.d.ts +28 -1
  111. package/lib/node/web-extension-catalog.js +172 -4
  112. package/lib/node/web-extension-util.d.ts +5 -1
  113. package/lib/node/web-extension-util.js +36 -5
  114. package/lib/node/workspace-service.js +1 -1
  115. package/package.json +17 -12
  116. package/esm/node/auth-server-impl.js.map +0 -1
  117. package/esm/node/client-channel.js.map +0 -1
  118. package/esm/node/client-tool-broker.js.map +0 -1
  119. package/esm/node/event-log.js.map +0 -1
  120. package/esm/node/exec-environment-factory.js.map +0 -1
  121. package/esm/node/extension-data-notifier.js.map +0 -1
  122. package/esm/node/extension-data.js.map +0 -1
  123. package/esm/node/extension-providers.js.map +0 -1
  124. package/esm/node/host-protocol.js.map +0 -1
  125. package/esm/node/index.js.map +0 -1
  126. package/esm/node/module.js.map +0 -1
  127. package/esm/node/package-host-extension.js.map +0 -1
  128. package/esm/node/package-hosts.js.map +0 -1
  129. package/esm/node/package-server-impl.js.map +0 -1
  130. package/esm/node/package-switch.js.map +0 -1
  131. package/esm/node/receipt-book.js.map +0 -1
  132. package/esm/node/relay-bridge.js.map +0 -1
  133. package/esm/node/remote/index.js.map +0 -1
  134. package/esm/node/remote/pi-directories.js.map +0 -1
  135. package/esm/node/remote/port-forwards.js.map +0 -1
  136. package/esm/node/remote/remote-hosts.js.map +0 -1
  137. package/esm/node/remote/remote-protocol.js.map +0 -1
  138. package/esm/node/remote/remote-server-impl.js.map +0 -1
  139. package/esm/node/remote-ui-context.js.map +0 -1
  140. package/esm/node/session-files.js.map +0 -1
  141. package/esm/node/session-info-util.js.map +0 -1
  142. package/esm/node/session-storage/file-session-storage.js.map +0 -1
  143. package/esm/node/session-storage/index.js.map +0 -1
  144. package/esm/node/session-storage/session-storage-protocol.js.map +0 -1
  145. package/esm/node/session-storage/stored-session.js.map +0 -1
  146. package/esm/node/settings-server-impl.js.map +0 -1
  147. package/esm/node/settings-store.js.map +0 -1
  148. package/esm/node/ta-access.js.map +0 -1
  149. package/esm/node/ta-errors.js.map +0 -1
  150. package/esm/node/ta-event-util.js.map +0 -1
  151. package/esm/node/ta-server-impl.js.map +0 -1
  152. package/esm/node/ta-session-factory.js.map +0 -1
  153. package/esm/node/ta-session-registry.js.map +0 -1
  154. package/esm/node/ta-session.js.map +0 -1
  155. package/esm/node/terminal-protocol.js.map +0 -1
  156. package/esm/node/terminal-service.js.map +0 -1
  157. package/esm/node/terminal-util.js.map +0 -1
  158. package/esm/node/web-extension-catalog.js.map +0 -1
  159. package/esm/node/web-extension-util.js.map +0 -1
  160. package/esm/node/working-directory.js.map +0 -1
  161. package/esm/node/workspace-files.js.map +0 -1
  162. package/esm/node/workspace-protocol.js.map +0 -1
  163. package/esm/node/workspace-server-impl.js.map +0 -1
  164. package/esm/node/workspace-service.js.map +0 -1
  165. package/esm/node/workspace-util.js.map +0 -1
  166. package/lib/node/auth-server-impl.d.ts.map +0 -1
  167. package/lib/node/auth-server-impl.js.map +0 -1
  168. package/lib/node/auth-server-impl.spec.d.ts +0 -2
  169. package/lib/node/auth-server-impl.spec.d.ts.map +0 -1
  170. package/lib/node/auth-server-impl.spec.js +0 -47
  171. package/lib/node/auth-server-impl.spec.js.map +0 -1
  172. package/lib/node/client-channel.d.ts.map +0 -1
  173. package/lib/node/client-channel.js.map +0 -1
  174. package/lib/node/client-channel.spec.d.ts +0 -2
  175. package/lib/node/client-channel.spec.d.ts.map +0 -1
  176. package/lib/node/client-channel.spec.js +0 -106
  177. package/lib/node/client-channel.spec.js.map +0 -1
  178. package/lib/node/client-tool-broker.d.ts.map +0 -1
  179. package/lib/node/client-tool-broker.js.map +0 -1
  180. package/lib/node/client-tool-broker.spec.d.ts +0 -2
  181. package/lib/node/client-tool-broker.spec.d.ts.map +0 -1
  182. package/lib/node/client-tool-broker.spec.js +0 -49
  183. package/lib/node/client-tool-broker.spec.js.map +0 -1
  184. package/lib/node/event-log.d.ts.map +0 -1
  185. package/lib/node/event-log.js.map +0 -1
  186. package/lib/node/event-log.spec.d.ts +0 -2
  187. package/lib/node/event-log.spec.d.ts.map +0 -1
  188. package/lib/node/event-log.spec.js +0 -48
  189. package/lib/node/event-log.spec.js.map +0 -1
  190. package/lib/node/exec-environment-factory.d.ts.map +0 -1
  191. package/lib/node/exec-environment-factory.js.map +0 -1
  192. package/lib/node/extension-data-notifier.d.ts.map +0 -1
  193. package/lib/node/extension-data-notifier.js.map +0 -1
  194. package/lib/node/extension-data-notifier.spec.d.ts +0 -2
  195. package/lib/node/extension-data-notifier.spec.d.ts.map +0 -1
  196. package/lib/node/extension-data-notifier.spec.js +0 -35
  197. package/lib/node/extension-data-notifier.spec.js.map +0 -1
  198. package/lib/node/extension-data.d.ts.map +0 -1
  199. package/lib/node/extension-data.js.map +0 -1
  200. package/lib/node/extension-data.spec.d.ts +0 -2
  201. package/lib/node/extension-data.spec.d.ts.map +0 -1
  202. package/lib/node/extension-data.spec.js +0 -99
  203. package/lib/node/extension-data.spec.js.map +0 -1
  204. package/lib/node/extension-providers.d.ts.map +0 -1
  205. package/lib/node/extension-providers.js.map +0 -1
  206. package/lib/node/host-protocol.d.ts.map +0 -1
  207. package/lib/node/host-protocol.js.map +0 -1
  208. package/lib/node/index.d.ts.map +0 -1
  209. package/lib/node/index.js.map +0 -1
  210. package/lib/node/module.d.ts.map +0 -1
  211. package/lib/node/module.js.map +0 -1
  212. package/lib/node/package-host-extension.d.ts.map +0 -1
  213. package/lib/node/package-host-extension.js.map +0 -1
  214. package/lib/node/package-hosts.d.ts.map +0 -1
  215. package/lib/node/package-hosts.js.map +0 -1
  216. package/lib/node/package-hosts.spec.d.ts +0 -2
  217. package/lib/node/package-hosts.spec.d.ts.map +0 -1
  218. package/lib/node/package-hosts.spec.js +0 -53
  219. package/lib/node/package-hosts.spec.js.map +0 -1
  220. package/lib/node/package-server-impl.d.ts.map +0 -1
  221. package/lib/node/package-server-impl.js.map +0 -1
  222. package/lib/node/package-switch.d.ts.map +0 -1
  223. package/lib/node/package-switch.js.map +0 -1
  224. package/lib/node/receipt-book.d.ts.map +0 -1
  225. package/lib/node/receipt-book.js.map +0 -1
  226. package/lib/node/receipt-book.spec.d.ts +0 -2
  227. package/lib/node/receipt-book.spec.d.ts.map +0 -1
  228. package/lib/node/receipt-book.spec.js +0 -39
  229. package/lib/node/receipt-book.spec.js.map +0 -1
  230. package/lib/node/relay-bridge.d.ts.map +0 -1
  231. package/lib/node/relay-bridge.js.map +0 -1
  232. package/lib/node/remote/index.d.ts.map +0 -1
  233. package/lib/node/remote/index.js.map +0 -1
  234. package/lib/node/remote/pi-directories.d.ts.map +0 -1
  235. package/lib/node/remote/pi-directories.js.map +0 -1
  236. package/lib/node/remote/port-forwards.d.ts.map +0 -1
  237. package/lib/node/remote/port-forwards.js.map +0 -1
  238. package/lib/node/remote/remote-hosts.d.ts.map +0 -1
  239. package/lib/node/remote/remote-hosts.js.map +0 -1
  240. package/lib/node/remote/remote-protocol.d.ts.map +0 -1
  241. package/lib/node/remote/remote-protocol.js.map +0 -1
  242. package/lib/node/remote/remote-server-impl.d.ts.map +0 -1
  243. package/lib/node/remote/remote-server-impl.js.map +0 -1
  244. package/lib/node/remote/remote.spec.d.ts +0 -2
  245. package/lib/node/remote/remote.spec.d.ts.map +0 -1
  246. package/lib/node/remote/remote.spec.js +0 -130
  247. package/lib/node/remote/remote.spec.js.map +0 -1
  248. package/lib/node/remote-ui-context.d.ts.map +0 -1
  249. package/lib/node/remote-ui-context.js.map +0 -1
  250. package/lib/node/remote-ui-context.spec.d.ts +0 -2
  251. package/lib/node/remote-ui-context.spec.d.ts.map +0 -1
  252. package/lib/node/remote-ui-context.spec.js +0 -85
  253. package/lib/node/remote-ui-context.spec.js.map +0 -1
  254. package/lib/node/session-files.d.ts.map +0 -1
  255. package/lib/node/session-files.js.map +0 -1
  256. package/lib/node/session-files.spec.d.ts +0 -2
  257. package/lib/node/session-files.spec.d.ts.map +0 -1
  258. package/lib/node/session-files.spec.js +0 -51
  259. package/lib/node/session-files.spec.js.map +0 -1
  260. package/lib/node/session-info-util.d.ts.map +0 -1
  261. package/lib/node/session-info-util.js.map +0 -1
  262. package/lib/node/session-info-util.spec.d.ts +0 -2
  263. package/lib/node/session-info-util.spec.d.ts.map +0 -1
  264. package/lib/node/session-info-util.spec.js +0 -22
  265. package/lib/node/session-info-util.spec.js.map +0 -1
  266. package/lib/node/session-storage/file-session-storage.d.ts.map +0 -1
  267. package/lib/node/session-storage/file-session-storage.js.map +0 -1
  268. package/lib/node/session-storage/file-session-storage.spec.d.ts +0 -2
  269. package/lib/node/session-storage/file-session-storage.spec.d.ts.map +0 -1
  270. package/lib/node/session-storage/file-session-storage.spec.js +0 -70
  271. package/lib/node/session-storage/file-session-storage.spec.js.map +0 -1
  272. package/lib/node/session-storage/index.d.ts.map +0 -1
  273. package/lib/node/session-storage/index.js.map +0 -1
  274. package/lib/node/session-storage/session-storage-protocol.d.ts.map +0 -1
  275. package/lib/node/session-storage/session-storage-protocol.js.map +0 -1
  276. package/lib/node/session-storage/stored-session.d.ts.map +0 -1
  277. package/lib/node/session-storage/stored-session.js.map +0 -1
  278. package/lib/node/session-storage/stored-session.spec.d.ts +0 -2
  279. package/lib/node/session-storage/stored-session.spec.d.ts.map +0 -1
  280. package/lib/node/session-storage/stored-session.spec.js +0 -73
  281. package/lib/node/session-storage/stored-session.spec.js.map +0 -1
  282. package/lib/node/settings-server-impl.d.ts.map +0 -1
  283. package/lib/node/settings-server-impl.js.map +0 -1
  284. package/lib/node/settings-store.d.ts.map +0 -1
  285. package/lib/node/settings-store.js.map +0 -1
  286. package/lib/node/settings-store.spec.d.ts +0 -2
  287. package/lib/node/settings-store.spec.d.ts.map +0 -1
  288. package/lib/node/settings-store.spec.js +0 -148
  289. package/lib/node/settings-store.spec.js.map +0 -1
  290. package/lib/node/ta-access.d.ts.map +0 -1
  291. package/lib/node/ta-access.js.map +0 -1
  292. package/lib/node/ta-access.spec.d.ts +0 -2
  293. package/lib/node/ta-access.spec.d.ts.map +0 -1
  294. package/lib/node/ta-access.spec.js +0 -33
  295. package/lib/node/ta-access.spec.js.map +0 -1
  296. package/lib/node/ta-errors.d.ts.map +0 -1
  297. package/lib/node/ta-errors.js.map +0 -1
  298. package/lib/node/ta-errors.spec.d.ts +0 -2
  299. package/lib/node/ta-errors.spec.d.ts.map +0 -1
  300. package/lib/node/ta-errors.spec.js +0 -25
  301. package/lib/node/ta-errors.spec.js.map +0 -1
  302. package/lib/node/ta-event-util.d.ts.map +0 -1
  303. package/lib/node/ta-event-util.js.map +0 -1
  304. package/lib/node/ta-event-util.spec.d.ts +0 -2
  305. package/lib/node/ta-event-util.spec.d.ts.map +0 -1
  306. package/lib/node/ta-event-util.spec.js +0 -28
  307. package/lib/node/ta-event-util.spec.js.map +0 -1
  308. package/lib/node/ta-server-impl.d.ts.map +0 -1
  309. package/lib/node/ta-server-impl.js.map +0 -1
  310. package/lib/node/ta-session-factory.d.ts.map +0 -1
  311. package/lib/node/ta-session-factory.js.map +0 -1
  312. package/lib/node/ta-session-registry.d.ts.map +0 -1
  313. package/lib/node/ta-session-registry.js.map +0 -1
  314. package/lib/node/ta-session.d.ts.map +0 -1
  315. package/lib/node/ta-session.js.map +0 -1
  316. package/lib/node/terminal-protocol.d.ts.map +0 -1
  317. package/lib/node/terminal-protocol.js.map +0 -1
  318. package/lib/node/terminal-service.d.ts.map +0 -1
  319. package/lib/node/terminal-service.js.map +0 -1
  320. package/lib/node/terminal-service.spec.d.ts +0 -2
  321. package/lib/node/terminal-service.spec.d.ts.map +0 -1
  322. package/lib/node/terminal-service.spec.js +0 -110
  323. package/lib/node/terminal-service.spec.js.map +0 -1
  324. package/lib/node/terminal-util.d.ts.map +0 -1
  325. package/lib/node/terminal-util.js.map +0 -1
  326. package/lib/node/terminal-util.spec.d.ts +0 -2
  327. package/lib/node/terminal-util.spec.d.ts.map +0 -1
  328. package/lib/node/terminal-util.spec.js +0 -95
  329. package/lib/node/terminal-util.spec.js.map +0 -1
  330. package/lib/node/web-extension-catalog.d.ts.map +0 -1
  331. package/lib/node/web-extension-catalog.js.map +0 -1
  332. package/lib/node/web-extension-catalog.spec.d.ts +0 -2
  333. package/lib/node/web-extension-catalog.spec.d.ts.map +0 -1
  334. package/lib/node/web-extension-catalog.spec.js +0 -157
  335. package/lib/node/web-extension-catalog.spec.js.map +0 -1
  336. package/lib/node/web-extension-util.d.ts.map +0 -1
  337. package/lib/node/web-extension-util.js.map +0 -1
  338. package/lib/node/working-directory.d.ts.map +0 -1
  339. package/lib/node/working-directory.js.map +0 -1
  340. package/lib/node/workspace-files.d.ts.map +0 -1
  341. package/lib/node/workspace-files.js.map +0 -1
  342. package/lib/node/workspace-files.spec.d.ts +0 -2
  343. package/lib/node/workspace-files.spec.d.ts.map +0 -1
  344. package/lib/node/workspace-files.spec.js +0 -133
  345. package/lib/node/workspace-files.spec.js.map +0 -1
  346. package/lib/node/workspace-protocol.d.ts.map +0 -1
  347. package/lib/node/workspace-protocol.js.map +0 -1
  348. package/lib/node/workspace-server-impl.d.ts.map +0 -1
  349. package/lib/node/workspace-server-impl.js.map +0 -1
  350. package/lib/node/workspace-service.d.ts.map +0 -1
  351. package/lib/node/workspace-service.js.map +0 -1
  352. package/lib/node/workspace-service.spec.d.ts +0 -2
  353. package/lib/node/workspace-service.spec.d.ts.map +0 -1
  354. package/lib/node/workspace-service.spec.js +0 -113
  355. package/lib/node/workspace-service.spec.js.map +0 -1
  356. package/lib/node/workspace-util.d.ts.map +0 -1
  357. package/lib/node/workspace-util.js.map +0 -1
  358. package/lib/node/workspace-util.spec.d.ts +0 -2
  359. package/lib/node/workspace-util.spec.d.ts.map +0 -1
  360. package/lib/node/workspace-util.spec.js +0 -44
  361. package/lib/node/workspace-util.spec.js.map +0 -1
  362. package/src/node/auth-server-impl.spec.ts +0 -49
  363. package/src/node/auth-server-impl.ts +0 -258
  364. package/src/node/client-channel.spec.ts +0 -117
  365. package/src/node/client-channel.ts +0 -94
  366. package/src/node/client-tool-broker.spec.ts +0 -53
  367. package/src/node/client-tool-broker.ts +0 -106
  368. package/src/node/event-log.spec.ts +0 -52
  369. package/src/node/event-log.ts +0 -59
  370. package/src/node/exec-environment-factory.ts +0 -66
  371. package/src/node/extension-data-notifier.spec.ts +0 -34
  372. package/src/node/extension-data-notifier.ts +0 -124
  373. package/src/node/extension-data.spec.ts +0 -105
  374. package/src/node/extension-data.ts +0 -180
  375. package/src/node/extension-providers.ts +0 -49
  376. package/src/node/host-protocol.ts +0 -62
  377. package/src/node/index.ts +0 -39
  378. package/src/node/module.ts +0 -4
  379. package/src/node/package-host-extension.ts +0 -23
  380. package/src/node/package-hosts.spec.ts +0 -54
  381. package/src/node/package-hosts.ts +0 -204
  382. package/src/node/package-server-impl.ts +0 -87
  383. package/src/node/package-switch.ts +0 -80
  384. package/src/node/receipt-book.spec.ts +0 -41
  385. package/src/node/receipt-book.ts +0 -40
  386. package/src/node/relay-bridge.ts +0 -94
  387. package/src/node/remote/index.ts +0 -5
  388. package/src/node/remote/pi-directories.ts +0 -49
  389. package/src/node/remote/port-forwards.ts +0 -148
  390. package/src/node/remote/remote-hosts.ts +0 -170
  391. package/src/node/remote/remote-protocol.ts +0 -57
  392. package/src/node/remote/remote-server-impl.ts +0 -60
  393. package/src/node/remote/remote.spec.ts +0 -142
  394. package/src/node/remote-ui-context.spec.ts +0 -93
  395. package/src/node/remote-ui-context.ts +0 -197
  396. package/src/node/session-files.spec.ts +0 -52
  397. package/src/node/session-files.ts +0 -41
  398. package/src/node/session-info-util.spec.ts +0 -23
  399. package/src/node/session-info-util.ts +0 -55
  400. package/src/node/session-storage/file-session-storage.spec.ts +0 -72
  401. package/src/node/session-storage/file-session-storage.ts +0 -145
  402. package/src/node/session-storage/index.ts +0 -3
  403. package/src/node/session-storage/session-storage-protocol.ts +0 -81
  404. package/src/node/session-storage/stored-session.spec.ts +0 -80
  405. package/src/node/session-storage/stored-session.ts +0 -149
  406. package/src/node/settings-server-impl.ts +0 -42
  407. package/src/node/settings-store.spec.ts +0 -158
  408. package/src/node/settings-store.ts +0 -327
  409. package/src/node/ta-access.spec.ts +0 -36
  410. package/src/node/ta-access.ts +0 -156
  411. package/src/node/ta-errors.spec.ts +0 -25
  412. package/src/node/ta-errors.ts +0 -75
  413. package/src/node/ta-event-util.spec.ts +0 -29
  414. package/src/node/ta-event-util.ts +0 -23
  415. package/src/node/ta-server-impl.ts +0 -341
  416. package/src/node/ta-session-factory.ts +0 -216
  417. package/src/node/ta-session-registry.ts +0 -75
  418. package/src/node/ta-session.ts +0 -241
  419. package/src/node/terminal-protocol.ts +0 -18
  420. package/src/node/terminal-service.spec.ts +0 -119
  421. package/src/node/terminal-service.ts +0 -291
  422. package/src/node/terminal-util.spec.ts +0 -109
  423. package/src/node/terminal-util.ts +0 -197
  424. package/src/node/web-extension-catalog.spec.ts +0 -172
  425. package/src/node/web-extension-catalog.ts +0 -177
  426. package/src/node/web-extension-util.ts +0 -144
  427. package/src/node/working-directory.ts +0 -71
  428. package/src/node/workspace-files.spec.ts +0 -145
  429. package/src/node/workspace-files.ts +0 -256
  430. package/src/node/workspace-protocol.ts +0 -24
  431. package/src/node/workspace-server-impl.ts +0 -108
  432. package/src/node/workspace-service.spec.ts +0 -123
  433. package/src/node/workspace-service.ts +0 -235
  434. package/src/node/workspace-util.spec.ts +0 -47
  435. package/src/node/workspace-util.ts +0 -103
@@ -1,94 +0,0 @@
1
- import type { RpcConnection } from '@celljs/rpc/lib/node';
2
- import { TaClient, type TaEventEnvelope } from '@celljs/ta-protocol';
3
- import type { LoggedEvent } from './event-log';
4
-
5
- const FLUSH_INTERVAL_MS = 30;
6
-
7
- /** The events that come by the hundred while a model or a tool streams; the others leave at once. */
8
- const STREAMED_EVENTS = new Set(['message_update', 'tool_execution_update']);
9
-
10
- /**
11
- * Events on their way to one client, one message at a time: the next leaves when the client has
12
- * answered the last, so that a slow client costs a bounded queue and nothing while no events flow.
13
- * A model streams hundreds of deltas a second: streamed events leave at most once per interval, the
14
- * first of them at once. Other events (a message starts, a tool ends, a dialog opens) leave at once,
15
- * with what is queued, so that nothing a user waits for is delayed.
16
- */
17
- export class ClientChannel {
18
- protected queue: TaEventEnvelope[] = [];
19
- protected queuedBytes = 0;
20
- protected timer?: ReturnType<typeof setTimeout>;
21
- protected sending = false;
22
- protected lastFlushAt = Number.NEGATIVE_INFINITY;
23
- /** When the timer fires, on the clock of `performance.now()`. */
24
- protected dueAt = 0;
25
- /** The queue holds an event that should not wait. */
26
- protected urgent = false;
27
- /** The queue holds a streamed event. */
28
- protected streamed = false;
29
-
30
- constructor(
31
- readonly connection: RpcConnection,
32
- protected readonly maxBacklogBytes: number,
33
- ) {}
34
-
35
- send(logged: LoggedEvent): void {
36
- this.queue.push(logged.envelope);
37
- this.queuedBytes += logged.size;
38
- if (this.queuedBytes > this.maxBacklogBytes) {
39
- this.clear();
40
- this.connection.close(1013, 'The client is too far behind; attach again with the last seq it has.');
41
- return;
42
- }
43
- const streamed = STREAMED_EVENTS.has(logged.envelope.event.type);
44
- this.streamed ||= streamed;
45
- this.urgent ||= !streamed;
46
- this.schedule();
47
- }
48
-
49
- /** A timer, not a direct send: the events of the same turn of the event loop leave together. */
50
- protected schedule(): void {
51
- const due = this.urgent ? 0 : this.lastFlushAt + FLUSH_INTERVAL_MS;
52
- if (this.timer !== undefined && this.dueAt <= due) {
53
- return;
54
- }
55
- clearTimeout(this.timer);
56
- this.dueAt = due;
57
- this.timer = setTimeout(() => this.flush(), Math.max(0, due - performance.now()));
58
- }
59
-
60
- protected flush(): void {
61
- this.timer = undefined;
62
- if (this.sending || !this.queue.length || this.connection.closed) {
63
- return;
64
- }
65
- const batch = this.queue;
66
- this.queue = [];
67
- this.queuedBytes = 0;
68
- if (this.streamed) {
69
- this.lastFlushAt = performance.now();
70
- }
71
- this.urgent = false;
72
- this.streamed = false;
73
- this.sending = true;
74
- this.connection
75
- .client<TaClient>(TaClient)
76
- .onEvents(batch)
77
- .catch(() => undefined)
78
- .finally(() => {
79
- this.sending = false;
80
- if (this.queue.length) {
81
- this.schedule();
82
- }
83
- });
84
- }
85
-
86
- protected clear(): void {
87
- clearTimeout(this.timer);
88
- this.timer = undefined;
89
- this.queue = [];
90
- this.queuedBytes = 0;
91
- this.urgent = false;
92
- this.streamed = false;
93
- }
94
- }
@@ -1,53 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import type { TaEvent } from '@celljs/ta-protocol';
3
- import { ClientToolBroker } from './client-tool-broker';
4
-
5
- const PICK = { name: 'pick_color', description: 'Asks the user for a color.', parameters: { type: 'object', properties: {} } };
6
-
7
- function setup() {
8
- const events: TaEvent[] = [];
9
- const broker = new ClientToolBroker([PICK]);
10
- broker.connect(event => events.push(event));
11
- const [tool] = broker.tools() as unknown as { name: string; execute(id: string, input: unknown, signal?: AbortSignal): Promise<unknown> }[];
12
- return { broker, events, tool };
13
- }
14
-
15
- describe('ClientToolBroker', () => {
16
- it('is a tool of pi that waits for the first answer of a client', async () => {
17
- const { broker, events, tool } = setup();
18
- expect(tool.name).toBe('pick_color');
19
- const result = tool.execute('call-1', { hint: 'warm' });
20
- expect(events).toEqual([{ type: 'client_tool_request', id: 'call-1', toolName: 'pick_color', input: { hint: 'warm' } }]);
21
- expect(broker.pendingRequests).toHaveLength(1);
22
- expect(broker.respond({ id: 'call-1', output: 'red' })).toBe(true);
23
- expect(broker.respond({ id: 'call-1', output: 'blue' })).toBe(false);
24
- expect(await result).toEqual({ content: [{ type: 'text', text: 'red' }], details: undefined });
25
- expect(events.at(-1)).toEqual({ type: 'client_tool_resolved', id: 'call-1' });
26
- expect(broker.pendingRequests).toEqual([]);
27
- });
28
-
29
- it('fails the tool with the output of a failed answer', async () => {
30
- const { broker, tool } = setup();
31
- const result = tool.execute('call-2', {});
32
- broker.respond({ id: 'call-2', output: 'no color today', isError: true });
33
- await expect(result).rejects.toThrow('no color today');
34
- });
35
-
36
- it('ends a call without a result when the run is aborted or the session closes', async () => {
37
- const { broker, events, tool } = setup();
38
- const controller = new AbortController();
39
- const aborted = tool.execute('call-3', {}, controller.signal);
40
- controller.abort();
41
- await expect(aborted).rejects.toThrow('got no result');
42
- const closed = tool.execute('call-4', {});
43
- broker.cancelAll();
44
- await expect(closed).rejects.toThrow('got no result');
45
- expect(events.filter(event => event.type === 'client_tool_resolved')).toHaveLength(2);
46
- });
47
-
48
- it('refuses definitions pi could not take', () => {
49
- expect(() => new ClientToolBroker([{ ...PICK, name: 'has space' }])).toThrow('not valid or not unique');
50
- expect(() => new ClientToolBroker([PICK, PICK])).toThrow('not valid or not unique');
51
- expect(() => new ClientToolBroker([{ ...PICK, parameters: { type: 'string' } }])).toThrow('not an object schema');
52
- });
53
- });
@@ -1,106 +0,0 @@
1
- import type { TaClientToolDefinition, TaClientToolRequest, TaClientToolResult, TaEvent } from '@celljs/ta-protocol';
2
- import { TaErrors } from './ta-errors';
3
-
4
- type ToolDefinition = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).ToolDefinition;
5
-
6
- interface PendingCall {
7
- request: TaClientToolRequest;
8
- settle(result: TaClientToolResult | undefined): void;
9
- }
10
-
11
- const TOOL_NAME = /^[A-Za-z][\w-]*$/;
12
-
13
- /**
14
- * The tools a session's clients run. Each is a tool of pi whose `execute` publishes the call and waits
15
- * for a client's answer: the model, codemode and extensions see it like any other tool. As with
16
- * dialogs, the call goes to every attached client and the first answer counts. A call ends without a
17
- * result when the run is aborted or the session closes.
18
- */
19
- export class ClientToolBroker {
20
- protected readonly pending = new Map<string, PendingCall>();
21
- protected publish: (event: TaEvent) => void = () => undefined;
22
-
23
- /** Throws CELL_TA_INVALID_ARGUMENT for a definition pi could not take. */
24
- constructor(protected readonly definitions: TaClientToolDefinition[] = []) {
25
- const names = new Set<string>();
26
- for (const { name, parameters } of definitions) {
27
- if (!TOOL_NAME.test(name ?? '') || names.has(name)) {
28
- throw TaErrors.invalidArgument(
29
- `The client tool name ${JSON.stringify(name)} is not valid or not unique.`,
30
- 'Name each client tool with letters, digits, _ and -, starting with a letter.',
31
- );
32
- }
33
- if (parameters?.type !== 'object') {
34
- throw TaErrors.invalidArgument(
35
- `The parameters of the client tool ${name} are not an object schema.`,
36
- 'Pass a JSON schema with type: "object".',
37
- );
38
- }
39
- names.add(name);
40
- }
41
- }
42
-
43
- get pendingRequests(): TaClientToolRequest[] {
44
- return [...this.pending.values()].map(call => call.request);
45
- }
46
-
47
- /** Where the calls go: the session's event log. */
48
- connect(publish: (event: TaEvent) => void): void {
49
- this.publish = publish;
50
- }
51
-
52
- /** The tools for pi. */
53
- tools(): ToolDefinition[] {
54
- return this.definitions.map(definition => ({
55
- name: definition.name,
56
- label: definition.name,
57
- description: definition.description,
58
- parameters: definition.parameters,
59
- execute: (toolCallId: string, input: unknown, signal?: AbortSignal) => this.call(definition.name, toolCallId, input, signal),
60
- })) as unknown as ToolDefinition[];
61
- }
62
-
63
- /** False when nobody waits for this call. */
64
- respond(result: TaClientToolResult): boolean {
65
- const call = this.pending.get(result.id);
66
- call?.settle(result);
67
- return call !== undefined;
68
- }
69
-
70
- cancelAll(): void {
71
- for (const call of [...this.pending.values()]) {
72
- call.settle(undefined);
73
- }
74
- }
75
-
76
- protected call(
77
- toolName: string,
78
- id: string,
79
- input: unknown,
80
- signal?: AbortSignal,
81
- ): Promise<{ content: { type: 'text'; text: string }[]; details: undefined }> {
82
- if (signal?.aborted) {
83
- return Promise.reject(new Error('The run was aborted.'));
84
- }
85
- return new Promise((resolve, reject) => {
86
- const settle = (result: TaClientToolResult | undefined) => {
87
- signal?.removeEventListener('abort', onAbort);
88
- this.pending.delete(id);
89
- this.publish({ type: 'client_tool_resolved', id });
90
- if (!result) {
91
- reject(new Error(`The client tool ${toolName} got no result: the run was aborted or the session closed.`));
92
- } else if (result.isError) {
93
- // pi turns a failed tool into an error result for the model.
94
- reject(new Error(result.output));
95
- } else {
96
- resolve({ content: [{ type: 'text', text: result.output }], details: undefined });
97
- }
98
- };
99
- const onAbort = () => settle(undefined);
100
- signal?.addEventListener('abort', onAbort, { once: true });
101
- const request: TaClientToolRequest = { type: 'client_tool_request', id, toolName, input };
102
- this.pending.set(id, { request, settle });
103
- this.publish(request);
104
- });
105
- }
106
- }
@@ -1,52 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import type { TaEvent } from '@celljs/ta-protocol';
3
- import { EventLog } from './event-log';
4
-
5
- const event = (size = 1): TaEvent => ({ type: 'ui_request_resolved', id: 'x'.repeat(size) });
6
- const seqs = (log: EventLog, after: number) => log.since(after).events.map(envelope => envelope.seq);
7
-
8
- describe('EventLog', () => {
9
- it('numbers events from one and replays those after a seq', () => {
10
- const log = new EventLog('s', 10000);
11
- log.append(event());
12
- log.append(event());
13
- log.append(event());
14
- expect(log.lastSeq).toBe(3);
15
- expect(seqs(log, 1)).toEqual([2, 3]);
16
- expect(seqs(log, 3)).toEqual([]);
17
- expect(log.append(event()).envelope.sessionId).toBe('s');
18
- });
19
-
20
- it('drops the oldest events beyond its size and reports the gap', () => {
21
- const log = new EventLog('s', 200);
22
- for (let i = 0; i < 5; i++) {
23
- log.append(event(80));
24
- }
25
- expect(log.since(0).gap).toBe(true);
26
- expect(log.since(0).events).toEqual([]);
27
- expect(log.since(4)).toMatchObject({ gap: false });
28
- expect(seqs(log, 4)).toEqual([5]);
29
- });
30
-
31
- it('keeps the latest event even when it alone is too big', () => {
32
- const log = new EventLog('s', 10);
33
- log.append(event(100));
34
- expect(seqs(log, 0)).toEqual([1]);
35
- });
36
-
37
- it('reports a gap for a seq it never gave', () => {
38
- const log = new EventLog('s', 1000);
39
- log.append(event());
40
- expect(log.since(7).gap).toBe(true);
41
- });
42
-
43
- it('stays usable over many events without growing', () => {
44
- const log = new EventLog('s', 500);
45
- for (let i = 0; i < 20000; i++) {
46
- log.append(event(20));
47
- }
48
- expect(log.lastSeq).toBe(20000);
49
- expect(seqs(log, 19999)).toEqual([20000]);
50
- expect((log as unknown as { entries: unknown[] }).entries.length).toBeLessThan(2100);
51
- });
52
- });
@@ -1,59 +0,0 @@
1
- import type { TaEvent, TaEventEnvelope } from '@celljs/ta-protocol';
2
-
3
- export interface LoggedEvent {
4
- envelope: TaEventEnvelope;
5
- /** Approximate size in bytes. */
6
- size: number;
7
- }
8
-
9
- /**
10
- * The latest events of a session, by size, so that a client that reconnects can catch up. Only that:
11
- * what happened is in the session file, and a client that fell further behind reads it again.
12
- */
13
- export class EventLog {
14
- protected entries: LoggedEvent[] = [];
15
- protected head = 0;
16
- protected bytes = 0;
17
- protected seq = 0;
18
-
19
- constructor(
20
- protected readonly sessionId: string,
21
- protected readonly maxBytes: number,
22
- ) {}
23
-
24
- get lastSeq(): number {
25
- return this.seq;
26
- }
27
-
28
- append(event: TaEvent): LoggedEvent {
29
- const logged = { envelope: { sessionId: this.sessionId, seq: ++this.seq, event }, size: this.sizeOf(event) };
30
- this.entries.push(logged);
31
- this.bytes += logged.size;
32
- while (this.bytes > this.maxBytes && this.entries.length - this.head > 1) {
33
- this.bytes -= this.entries[this.head++].size;
34
- }
35
- if (this.head > 1024 && this.head * 2 > this.entries.length) {
36
- this.entries = this.entries.slice(this.head);
37
- this.head = 0;
38
- }
39
- return logged;
40
- }
41
-
42
- /** The events after `afterSeq`; `gap` when some of them are gone. */
43
- since(afterSeq: number): { events: TaEventEnvelope[]; gap: boolean } {
44
- const oldest = this.head < this.entries.length ? this.entries[this.head].envelope.seq : this.seq + 1;
45
- if (afterSeq + 1 < oldest || afterSeq > this.seq) {
46
- return { events: [], gap: true };
47
- }
48
- return { events: this.entries.slice(this.head + afterSeq + 1 - oldest).map(entry => entry.envelope), gap: false };
49
- }
50
-
51
- /** Deltas are most of the events and their size is known; the others are rare enough to measure. */
52
- protected sizeOf(event: TaEvent): number {
53
- if (event.type === 'message_update') {
54
- const delta = (event.assistantMessageEvent as { delta?: string }).delta;
55
- return 256 + (delta?.length ?? 0);
56
- }
57
- return JSON.stringify(event).length;
58
- }
59
- }
@@ -1,66 +0,0 @@
1
- import { Autowired, Component, Optional, Value } from '@celljs/core';
2
- import { ExecClient, type ExecEnvironment, ExecEnvironmentFactory, LocalExecEnvironment, RemoteExecEnvironment } from '@celljs/ta-exec';
3
- import { TaLocation } from '@celljs/ta-protocol';
4
- import { TA_EXEC_OPTIONS, type TaExecOptions } from './host-protocol';
5
- import { RemoteHosts } from './remote/remote-protocol';
6
- import { TaErrors } from './ta-errors';
7
- import { TaWorkingDirectory } from './working-directory';
8
-
9
- /**
10
- * Where a location runs. `ssh://<host>/<path>`: on that host, through ssh (RemoteHosts). A path: on this
11
- * machine, or with `ta.exec.url` on the machine of a `ta exec-server`, all sessions on one connection.
12
- * The agent loop stays here; commands and files are there. The default directory is the one the user
13
- * chose (TaWorkingDirectory), if any.
14
- */
15
- @Component(ExecEnvironmentFactory)
16
- export class DefaultExecEnvironmentFactory implements ExecEnvironmentFactory {
17
- @Value(TA_EXEC_OPTIONS)
18
- protected readonly options?: TaExecOptions;
19
-
20
- @Autowired(TaWorkingDirectory)
21
- @Optional()
22
- protected readonly workingDirectory?: TaWorkingDirectory;
23
-
24
- @Autowired(RemoteHosts)
25
- protected readonly remoteHosts: RemoteHosts;
26
-
27
- protected client?: ExecClient;
28
-
29
- /** Its `cwd` is the path there: the one to resolve paths against, not the location. */
30
- create(location: string): ExecEnvironment {
31
- let remote: TaLocation.Remote | undefined;
32
- try {
33
- remote = TaLocation.parse(location);
34
- } catch (error) {
35
- throw TaErrors.invalidArgument((error as Error).message, 'Write ssh://<host>/<absolute path>.');
36
- }
37
- if (remote) {
38
- if (!remote.path) {
39
- throw TaErrors.invalidArgument(`${location} names no directory.`, 'Resolve it first (TaRemoteServer.resolveLocation), or write its path.');
40
- }
41
- return new RemoteExecEnvironment(this.remoteHosts.client(remote.host), remote.path);
42
- }
43
- const client = this.remote();
44
- return client ? new RemoteExecEnvironment(client, location) : new LocalExecEnvironment(location);
45
- }
46
-
47
- /** The working directory the user chose, else that of this process, or of the exec server. */
48
- async defaultCwd(): Promise<string> {
49
- const chosen = this.workingDirectory?.get();
50
- if (chosen) {
51
- return chosen;
52
- }
53
- const client = this.remote();
54
- return client ? (await client.info()).cwd : process.cwd();
55
- }
56
-
57
- protected remote(): ExecClient | undefined {
58
- const { url, token = '', epoch } = this.options ?? {};
59
- if (!url) {
60
- return undefined;
61
- }
62
- // A host started later fences the ones before it.
63
- this.client ??= new ExecClient({ connect: ExecClient.webSocket(url, token), epoch: epoch || Date.now() });
64
- return this.client;
65
- }
66
- }
@@ -1,34 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { ExtensionDataBatch, ExtensionDataScope } from './extension-data-notifier';
3
-
4
- describe('ExtensionDataBatch', () => {
5
- it('gathers the keys that changed, by package, once each', () => {
6
- const batch = new ExtensionDataBatch();
7
- expect(batch.empty).toBe(true);
8
- batch.add('ta-channels', 'messages/b');
9
- batch.add('notes', 'list');
10
- batch.add('ta-channels', 'team');
11
- batch.add('ta-channels', 'messages/b');
12
- expect(batch.take()).toEqual([
13
- ['notes', ['list']],
14
- ['ta-channels', ['messages/b', 'team']],
15
- ]);
16
- expect(batch.empty).toBe(true);
17
- expect(batch.take()).toEqual([]);
18
- });
19
-
20
- it('keeps the keys of a directory apart from those of the package', () => {
21
- const batch = new ExtensionDataBatch();
22
- batch.add('notes', 'open', '/work');
23
- batch.add('notes', 'list');
24
- batch.add('notes', 'open', '/work');
25
- batch.add('notes', 'open', '/else');
26
- expect(batch.take()).toEqual([
27
- ['notes', ['list']],
28
- ['notes', ['open'], '/else'],
29
- ['notes', ['open'], '/work'],
30
- ]);
31
- expect(ExtensionDataScope.parse(ExtensionDataScope.of('notes', '/a\nb'))).toEqual(['notes', '/a\nb']);
32
- expect(ExtensionDataScope.parse(ExtensionDataScope.of('notes'))).toEqual(['notes']);
33
- });
34
- });
@@ -1,124 +0,0 @@
1
- import { Autowired, Component } from '@celljs/core';
2
- import type { RpcConnection } from '@celljs/rpc/lib/node';
3
- import { TaClient } from '@celljs/ta-protocol';
4
- import { ExtensionDataStore } from './extension-data';
5
-
6
- export const ExtensionDataNotifier = Symbol('ExtensionDataNotifier');
7
-
8
- /** At most one notice per connection in this time, with the keys that changed meanwhile. */
9
- const NOTICE_MS = 250;
10
-
11
- /** Tells the clients which keys of the data of packages changed (TaClient.onExtensionData). */
12
- export interface ExtensionDataNotifier {
13
- /** The connection reads the data of the package, of a directory with `cwd`: tell it when that changes. */
14
- watch(connection: RpcConnection, name: string, cwd?: string): void;
15
- }
16
-
17
- /** One package, or its data of one directory. */
18
- export namespace ExtensionDataScope {
19
- export function of(name: string, cwd?: string): string {
20
- return cwd === undefined ? name : `${name}\n${cwd}`;
21
- }
22
-
23
- export function parse(scope: string): [name: string, cwd?: string] {
24
- const at = scope.indexOf('\n');
25
- return at < 0 ? [scope] : [scope.slice(0, at), scope.slice(at + 1)];
26
- }
27
- }
28
-
29
- /**
30
- * The keys that changed for one connection, by package and directory, until they leave together: a
31
- * channel where agents talk writes many times a second, a page draws once.
32
- */
33
- export class ExtensionDataBatch {
34
- protected readonly pending = new Map<string, Set<string>>();
35
-
36
- add(name: string, key: string, cwd?: string): void {
37
- const scope = ExtensionDataScope.of(name, cwd);
38
- let keys = this.pending.get(scope);
39
- if (!keys) {
40
- keys = new Set();
41
- this.pending.set(scope, keys);
42
- }
43
- keys.add(key);
44
- }
45
-
46
- get empty(): boolean {
47
- return this.pending.size === 0;
48
- }
49
-
50
- /** What changed, by package then directory, sorted; empties the batch. */
51
- take(): [name: string, keys: string[], cwd?: string][] {
52
- const taken = [...this.pending].sort(([a], [b]) => a.localeCompare(b));
53
- this.pending.clear();
54
- return taken.map(([scope, keys]) => {
55
- const [name, cwd] = ExtensionDataScope.parse(scope);
56
- return cwd === undefined ? [name, [...keys].sort()] : [name, [...keys].sort(), cwd];
57
- });
58
- }
59
- }
60
-
61
- interface Watcher {
62
- /** By ExtensionDataScope. */
63
- scopes: Set<string>;
64
- batch: ExtensionDataBatch;
65
- timer?: ReturnType<typeof setTimeout>;
66
- lastAt: number;
67
- }
68
-
69
- @Component(ExtensionDataNotifier)
70
- export class ExtensionDataNotifierImpl implements ExtensionDataNotifier {
71
- @Autowired(ExtensionDataStore)
72
- protected readonly store: ExtensionDataStore;
73
-
74
- protected readonly watchers = new Map<RpcConnection, Watcher>();
75
- protected unsubscribe?: () => void;
76
-
77
- watch(connection: RpcConnection, name: string, cwd?: string): void {
78
- let watcher = this.watchers.get(connection);
79
- if (!watcher) {
80
- const created: Watcher = { scopes: new Set(), batch: new ExtensionDataBatch(), lastAt: Number.NEGATIVE_INFINITY };
81
- this.watchers.set(connection, created);
82
- connection.onClose(() => {
83
- clearTimeout(created.timer);
84
- this.watchers.delete(connection);
85
- if (this.watchers.size === 0) {
86
- this.unsubscribe?.();
87
- this.unsubscribe = undefined;
88
- }
89
- });
90
- watcher = created;
91
- }
92
- watcher.scopes.add(ExtensionDataScope.of(name, cwd));
93
- this.unsubscribe ??= this.store.onChange((changed, key, directory) => this.changed(changed, key, directory));
94
- }
95
-
96
- protected changed(name: string, key: string, cwd?: string): void {
97
- const scope = ExtensionDataScope.of(name, cwd);
98
- for (const [connection, watcher] of this.watchers) {
99
- if (watcher.scopes.has(scope)) {
100
- watcher.batch.add(name, key, cwd);
101
- this.schedule(connection, watcher);
102
- }
103
- }
104
- }
105
-
106
- /** The first change leaves at once; the next ones wait for the rest of the interval. */
107
- protected schedule(connection: RpcConnection, watcher: Watcher): void {
108
- if (watcher.timer !== undefined) {
109
- return;
110
- }
111
- const wait = Math.max(0, watcher.lastAt + NOTICE_MS - performance.now());
112
- watcher.timer = setTimeout(() => {
113
- watcher.timer = undefined;
114
- watcher.lastAt = performance.now();
115
- if (connection.closed) {
116
- return;
117
- }
118
- const client = connection.client<TaClient>(TaClient);
119
- for (const [name, keys, cwd] of watcher.batch.take()) {
120
- (cwd === undefined ? client.onExtensionData(name, keys) : client.onExtensionData(name, keys, cwd)).catch(() => undefined);
121
- }
122
- }, wait);
123
- }
124
- }