@celljs/ta-host 4.8.0 → 4.9.1

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 +213 -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 +124 -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 +216 -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 +127 -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,72 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { mkdtempSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { FileSessionStorage } from './file-session-storage';
6
- import { LeaseHeldError, StaleLeaseError } from './session-storage-protocol';
7
-
8
- const storage = () => new FileSessionStorage(mkdtempSync(join(tmpdir(), 'ta-sessions-')));
9
- const entry = (id: string) => ({ type: 'message', id });
10
-
11
- describe('FileSessionStorage', () => {
12
- it('keeps what the holder of the lease writes, in order', async () => {
13
- const store = storage();
14
- expect(await store.read('s1')).toBeUndefined();
15
- const lease = await store.acquire('s1', 'a', 1000);
16
- expect(lease.epoch).toBe(1);
17
- await store.write(lease, [{ type: 'session', id: 's1' }, entry('1')], { replace: true });
18
- await store.write(lease, [entry('2')]);
19
- expect((await store.read('s1'))?.map(e => e.id)).toEqual(['s1', '1', '2']);
20
- await store.write(lease, [entry('x')], { replace: true });
21
- expect((await store.read('s1'))?.map(e => e.id)).toEqual(['x']);
22
- });
23
-
24
- it('does not give a live lease to another holder, unless it takes the session over', async () => {
25
- const store = storage();
26
- const first = await store.acquire('s1', 'a', 60000);
27
- await expect(store.acquire('s1', 'b', 60000)).rejects.toBeInstanceOf(LeaseHeldError);
28
- const second = await store.acquire('s1', 'b', 60000, { takeOver: true });
29
- expect(second.epoch).toBe(first.epoch + 1);
30
- });
31
-
32
- it('lets another holder take an expired or released lease, with a higher epoch', async () => {
33
- const store = storage();
34
- const first = await store.acquire('s1', 'a', 1);
35
- await Bun.sleep(5);
36
- const second = await store.acquire('s1', 'b', 60000);
37
- await store.release(second);
38
- const third = await store.acquire('s1', 'c', 60000);
39
- expect([first.epoch, second.epoch, third.epoch]).toEqual([1, 2, 3]);
40
- });
41
-
42
- it('refuses the writes and renewals of a holder that lost the session, and writes nothing of them', async () => {
43
- const store = storage();
44
- const old = await store.acquire('s1', 'a', 60000);
45
- await store.write(old, [entry('1')]);
46
- const taken = await store.acquire('s1', 'b', 60000, { takeOver: true });
47
- await expect(store.write(old, [entry('late')])).rejects.toBeInstanceOf(StaleLeaseError);
48
- await expect(store.renew(old, 60000)).rejects.toBeInstanceOf(StaleLeaseError);
49
- await store.release(old);
50
- await store.write(taken, [entry('2')]);
51
- expect((await store.read('s1'))?.map(e => e.id)).toEqual(['1', '2']);
52
- });
53
-
54
- it('gives one lease of an epoch when holders race for it', async () => {
55
- const store = storage();
56
- const results = await Promise.allSettled(['a', 'b', 'c', 'd'].map(holder => store.acquire('s1', holder, 60000)));
57
- expect(results.filter(result => result.status === 'fulfilled')).toHaveLength(1);
58
- });
59
-
60
- it('skips a line cut off by a crash', async () => {
61
- const store = storage();
62
- const lease = await store.acquire('s1', 'a', 1000);
63
- await store.write(lease, [entry('1')]);
64
- const { appendFileSync } = await import('node:fs');
65
- appendFileSync(join((store as unknown as { dir: string }).dir, 's1.jsonl'), '{"type":"mess');
66
- expect((await store.read('s1'))?.map(e => e.id)).toEqual(['1']);
67
- });
68
-
69
- it('refuses ids that are not names of a file in its directory', async () => {
70
- await expect(storage().acquire('../x', 'a', 1000)).rejects.toThrow('Not a session id');
71
- });
72
- });
@@ -1,145 +0,0 @@
1
- import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { type SessionLease, SessionLeaseUtil, StaleLeaseError, type StoredEntry, type TaSessionStorage } from './session-storage-protocol';
4
-
5
- const LOCK_WAIT_MS = 5;
6
- const LOCK_TIMEOUT_MS = 5000;
7
- /** A lock older than this was left by a process that died holding it. */
8
- const STALE_LOCK_MS = 10000;
9
- const SESSION_ID = /^[A-Za-z0-9_-]{1,128}$/;
10
-
11
- /**
12
- * Sessions in a directory, which processes of this machine or of a shared file system can share:
13
- * `<id>.jsonl` (pi's format) and `<id>.lease.json`. A lock directory makes each operation atomic; a
14
- * cloud implementation does the same with conditional writes.
15
- */
16
- export class FileSessionStorage implements TaSessionStorage {
17
- constructor(protected readonly dir: string) {
18
- mkdirSync(dir, { recursive: true });
19
- }
20
-
21
- acquire(sessionId: string, holder: string, ttlMs: number, options: { takeOver?: boolean } = {}): Promise<SessionLease> {
22
- return this.locked(sessionId, () => {
23
- const lease = SessionLeaseUtil.next(this.lease(sessionId), sessionId, holder, ttlMs, options.takeOver);
24
- this.writeLease(lease);
25
- return lease;
26
- });
27
- }
28
-
29
- renew(lease: SessionLease, ttlMs: number): Promise<SessionLease> {
30
- return this.locked(lease.sessionId, () => {
31
- this.check(lease);
32
- const renewed = { ...lease, expiresAt: Date.now() + ttlMs };
33
- this.writeLease(renewed);
34
- return renewed;
35
- });
36
- }
37
-
38
- release(lease: SessionLease): Promise<void> {
39
- return this.locked(lease.sessionId, () => {
40
- if (SessionLeaseUtil.isCurrent(lease, this.lease(lease.sessionId))) {
41
- // The epoch stays, so that the next holder's is still higher.
42
- this.writeLease({ ...lease, expiresAt: 0 });
43
- }
44
- });
45
- }
46
-
47
- async read(sessionId: string): Promise<StoredEntry[] | undefined> {
48
- const file = this.file(sessionId, 'jsonl');
49
- if (!existsSync(file)) {
50
- return undefined;
51
- }
52
- // A line cut off by a crash in the middle of an append is left out, as pi does.
53
- return readFileSync(file, 'utf8')
54
- .split('\n')
55
- .filter(line => line.trim())
56
- .flatMap(line => {
57
- try {
58
- return [JSON.parse(line) as StoredEntry];
59
- } catch {
60
- return [];
61
- }
62
- });
63
- }
64
-
65
- write(lease: SessionLease, entries: StoredEntry[], options: { replace?: boolean } = {}): Promise<void> {
66
- return this.locked(lease.sessionId, () => {
67
- this.check(lease);
68
- const text = entries.map(entry => `${JSON.stringify(entry)}\n`).join('');
69
- const file = this.file(lease.sessionId, 'jsonl');
70
- if (options.replace) {
71
- this.replaceFile(file, text);
72
- } else {
73
- appendFileSync(file, text, { mode: 0o600 });
74
- }
75
- });
76
- }
77
-
78
- protected check(lease: SessionLease): void {
79
- if (!SessionLeaseUtil.isCurrent(lease, this.lease(lease.sessionId))) {
80
- throw new StaleLeaseError(lease);
81
- }
82
- }
83
-
84
- protected lease(sessionId: string): SessionLease | undefined {
85
- try {
86
- return JSON.parse(readFileSync(this.file(sessionId, 'lease.json'), 'utf8')) as SessionLease;
87
- } catch {
88
- return undefined;
89
- }
90
- }
91
-
92
- protected writeLease(lease: SessionLease): void {
93
- this.replaceFile(this.file(lease.sessionId, 'lease.json'), JSON.stringify(lease));
94
- }
95
-
96
- protected replaceFile(file: string, text: string): void {
97
- const temporary = `${file}.${process.pid}.tmp`;
98
- writeFileSync(temporary, text, { mode: 0o600 });
99
- renameSync(temporary, file);
100
- }
101
-
102
- protected file(sessionId: string, extension: string): string {
103
- if (!SESSION_ID.test(sessionId)) {
104
- throw new Error(`Not a session id: ${sessionId}`);
105
- }
106
- return join(this.dir, `${sessionId}.${extension}`);
107
- }
108
-
109
- /** Runs `action` holding `<id>.lock`, a directory: creating one is atomic on every file system. */
110
- protected async locked<T>(sessionId: string, action: () => T): Promise<T> {
111
- const lock = this.file(sessionId, 'lock');
112
- const deadline = Date.now() + LOCK_TIMEOUT_MS;
113
- for (;;) {
114
- try {
115
- mkdirSync(lock);
116
- break;
117
- } catch (error) {
118
- if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
119
- throw error;
120
- }
121
- if (this.isStale(lock)) {
122
- rmSync(lock, { recursive: true, force: true });
123
- continue;
124
- }
125
- if (Date.now() > deadline) {
126
- throw new Error(`The session ${sessionId} stayed locked for ${LOCK_TIMEOUT_MS} ms.`);
127
- }
128
- await new Promise(resolve => setTimeout(resolve, LOCK_WAIT_MS));
129
- }
130
- }
131
- try {
132
- return action();
133
- } finally {
134
- rmSync(lock, { recursive: true, force: true });
135
- }
136
- }
137
-
138
- protected isStale(lock: string): boolean {
139
- try {
140
- return Date.now() - statSync(lock).mtimeMs > STALE_LOCK_MS;
141
- } catch {
142
- return false;
143
- }
144
- }
145
- }
@@ -1,3 +0,0 @@
1
- export * from './file-session-storage';
2
- export * from './session-storage-protocol';
3
- export * from './stored-session';
@@ -1,81 +0,0 @@
1
- /** A line of a pi session file: its header, or an entry. The storage keeps them as they are. */
2
- export type StoredEntry = { type: string } & Record<string, unknown>;
3
-
4
- /**
5
- * The right of one holder (a ta serve) to write a session. The epoch grows by one each time a holder
6
- * takes the session, and every write names it: a holder that lost the session to another can no longer
7
- * write, even if it does not know yet (it was paused, or cut off). The expiry only says when another may
8
- * take the session without being asked to take it over.
9
- */
10
- export interface SessionLease {
11
- sessionId: string;
12
- holder: string;
13
- epoch: number;
14
- /** `Date.now()` time. */
15
- expiresAt: number;
16
- }
17
-
18
- export const TaSessionStorage = Symbol('TaSessionStorage');
19
-
20
- /**
21
- * Where sessions are kept when they are not pi's files on this machine, for example in the cloud, where
22
- * any of several ta serve may take a session over. Implementations make every write conditional on the
23
- * epoch of the lease (a conditional write in a database, a compare-and-swap in a key-value store).
24
- */
25
- export interface TaSessionStorage {
26
- /** A new lease, one epoch after the last. LeaseHeldError while another holder's lease is live, unless `takeOver`. */
27
- acquire(sessionId: string, holder: string, ttlMs: number, options?: { takeOver?: boolean }): Promise<SessionLease>;
28
- /** The same lease for longer. StaleLeaseError if another holder took the session since. */
29
- renew(lease: SessionLease, ttlMs: number): Promise<SessionLease>;
30
- /** Lets another take the session at once. Does nothing if the lease is no longer the current one. */
31
- release(lease: SessionLease): Promise<void>;
32
- /** The entries of the session, or nothing if it has none. */
33
- read(sessionId: string): Promise<StoredEntry[] | undefined>;
34
- /** Adds entries, or replaces them all; StaleLeaseError, and nothing written, if the lease is not the current one. */
35
- write(lease: SessionLease, entries: StoredEntry[], options?: { replace?: boolean }): Promise<void>;
36
- }
37
-
38
- /** Another holder has a live lease on the session. */
39
- export class LeaseHeldError extends Error {
40
- readonly code = 'LEASE_HELD';
41
-
42
- constructor(readonly current: SessionLease) {
43
- super(`The session ${current.sessionId} is held by ${current.holder} until ${new Date(current.expiresAt).toISOString()}.`);
44
- this.name = 'LeaseHeldError';
45
- }
46
- }
47
-
48
- /** The lease was not the current one: another holder took the session. */
49
- export class StaleLeaseError extends Error {
50
- readonly code = 'STALE_LEASE';
51
-
52
- constructor(readonly lease: SessionLease) {
53
- super(`The lease of epoch ${lease.epoch} on the session ${lease.sessionId} is no longer current: another holder took it.`);
54
- this.name = 'StaleLeaseError';
55
- }
56
- }
57
-
58
- export namespace SessionLeaseUtil {
59
- export function isLive(lease: SessionLease | undefined, now = Date.now()): lease is SessionLease {
60
- return lease !== undefined && lease.expiresAt > now;
61
- }
62
-
63
- /** What `acquire` gives after `current`, or why it cannot. */
64
- export function next(
65
- current: SessionLease | undefined,
66
- sessionId: string,
67
- holder: string,
68
- ttlMs: number,
69
- takeOver = false,
70
- now = Date.now(),
71
- ): SessionLease {
72
- if (!takeOver && isLive(current, now) && current.holder !== holder) {
73
- throw new LeaseHeldError(current);
74
- }
75
- return { sessionId, holder, epoch: (current?.epoch ?? 0) + 1, expiresAt: now + ttlMs };
76
- }
77
-
78
- export function isCurrent(lease: SessionLease, current: SessionLease | undefined): boolean {
79
- return current !== undefined && current.epoch === lease.epoch && current.holder === lease.holder;
80
- }
81
- }
@@ -1,80 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { mkdtempSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { PiSdkUtil } from '@celljs/ai-coding-agent/lib/node/pi/pi-sdk-util';
6
- import { FileSessionStorage } from './file-session-storage';
7
- import { LeaseHeldError, StaleLeaseError } from './session-storage-protocol';
8
- import { StoredSession } from './stored-session';
9
-
10
- const user = (text: string) => ({ role: 'user' as const, content: text, timestamp: Date.now() });
11
- /** The text of the messages among entries. */
12
- const texts = (entries: unknown[] | undefined) =>
13
- (entries ?? []).flatMap(entry => {
14
- const { type, message } = entry as { type: string; message?: { content: unknown } };
15
- return type === 'message' ? [message?.content] : [];
16
- });
17
-
18
- async function setup() {
19
- const { SessionManager } = await PiSdkUtil.load();
20
- const storage = new FileSessionStorage(mkdtempSync(join(tmpdir(), 'ta-stored-')));
21
- const open = (holder: string, takeOver = false) =>
22
- StoredSession.open(SessionManager, { storage, sessionId: 'session-1', cwd: '/w', holder, takeOver, leaseMs: 60000 });
23
- return { storage, open };
24
- }
25
-
26
- describe('StoredSession', () => {
27
- it('stores nothing before the first message, then what pi adds, and opens it again elsewhere', async () => {
28
- const { storage, open } = await setup();
29
- const first = await open('host-a');
30
- first.manager.appendModelChange('p', 'm');
31
- await first.flush();
32
- expect(await storage.read('session-1')).toBeUndefined();
33
- first.manager.appendMessage(user('hello'));
34
- first.manager.appendMessage(user('again'));
35
- await first.flush();
36
- const stored = await storage.read('session-1');
37
- expect(stored?.map(entry => entry.type)).toEqual(['session', 'model_change', 'message', 'message']);
38
- expect(first.manager.getSessionId()).toBe('session-1');
39
- await first.close();
40
-
41
- const second = await open('host-b');
42
- expect(second.epoch).toBe(2);
43
- expect(second.manager.getEntries()).toHaveLength(3);
44
- second.manager.appendMessage(user('from b'));
45
- await second.flush();
46
- expect(await storage.read('session-1')).toHaveLength(5);
47
- await second.close();
48
- });
49
-
50
- it('is not opened by another while it is held', async () => {
51
- const { open } = await setup();
52
- const first = await open('host-a');
53
- await expect(open('host-b')).rejects.toBeInstanceOf(LeaseHeldError);
54
- await first.close();
55
- });
56
-
57
- it('stops the holder that lost the session: its writes do not land, and pi gets an error', async () => {
58
- const { storage, open } = await setup();
59
- const old = await open('host-a');
60
- old.manager.appendMessage(user('one'));
61
- await old.flush();
62
- const lost: Error[] = [];
63
- old.onLost(error => lost.push(error));
64
-
65
- const taker = await open('host-b', true);
66
- old.manager.appendMessage(user('late'));
67
- await expect(old.flush()).rejects.toBeInstanceOf(StaleLeaseError);
68
- expect(lost).toHaveLength(1);
69
- expect(() => old.manager.appendMessage(user('later'))).toThrow(StaleLeaseError);
70
- // pi keeps its memory in line with what was written.
71
- expect(texts(old.manager.getEntries())).toEqual(['one', 'late']);
72
-
73
- taker.manager.appendMessage(user('two'));
74
- await taker.flush();
75
- const stored = await storage.read('session-1');
76
- expect(texts(stored)).toEqual(['one', 'two']);
77
- await old.close();
78
- await taker.close();
79
- });
80
- });
@@ -1,149 +0,0 @@
1
- import { type SessionLease, StaleLeaseError, type StoredEntry, type TaSessionStorage } from './session-storage-protocol';
2
-
3
- type SessionManager = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).SessionManager;
4
- type SessionManagerClass = typeof import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).SessionManager;
5
-
6
- /** What pi's SessionManager calls for each entry it adds; public in its build, though not in its documentation. */
7
- interface Persisting {
8
- _persist(entry: StoredEntry): void;
9
- }
10
-
11
- export interface StoredSessionOptions {
12
- storage: TaSessionStorage;
13
- sessionId: string;
14
- cwd: string;
15
- /** This ta serve, as the storage knows it. */
16
- holder: string;
17
- /** How long a lease lasts without being renewed; it is renewed at a third of that. Default 30000. */
18
- leaseMs?: number;
19
- /** Takes the session even while another holder's lease is live. */
20
- takeOver?: boolean;
21
- }
22
-
23
- const DEFAULT_LEASE_MS = 30000;
24
-
25
- /**
26
- * A pi session kept in a TaSessionStorage rather than in a file: pi's SessionManager in memory, with
27
- * what it would append to its file written to the storage under a lease. Writes go out in order, after
28
- * pi added the entry; once the lease is lost, the next entry pi adds fails, as a failed write to its
29
- * file does, and {@link onLost} tells the host to stop the session.
30
- */
31
- export class StoredSession {
32
- protected flushed: boolean;
33
- protected writing: Promise<void> = Promise.resolve();
34
- protected lost?: Error;
35
- protected closed = false;
36
- protected readonly renewTimer: ReturnType<typeof setInterval>;
37
- protected readonly lostListeners = new Set<(error: Error) => void>();
38
-
39
- protected constructor(
40
- readonly manager: SessionManager,
41
- protected lease: SessionLease,
42
- protected readonly options: StoredSessionOptions,
43
- stored: boolean,
44
- ) {
45
- // pi writes nothing until the session has a message of the user or the model; neither does this.
46
- this.flushed = stored;
47
- const leaseMs = options.leaseMs ?? DEFAULT_LEASE_MS;
48
- this.renewTimer = setInterval(() => void this.renew(leaseMs), leaseMs / 3);
49
- this.renewTimer.unref?.();
50
- (manager as unknown as Persisting)._persist = entry => this.persist(entry);
51
- }
52
-
53
- /** Takes the lease, and opens the session from what the storage has, or a new one with that id. */
54
- static async open(sessionManager: SessionManagerClass, options: StoredSessionOptions): Promise<StoredSession> {
55
- const { storage, sessionId, holder, takeOver } = options;
56
- const lease = await storage.acquire(sessionId, holder, options.leaseMs ?? DEFAULT_LEASE_MS, { takeOver });
57
- try {
58
- const entries = await storage.read(sessionId);
59
- const manager = sessionManager.inMemory(options.cwd, { id: sessionId }, entries as Parameters<SessionManagerClass['inMemory']>[2]);
60
- return new StoredSession(manager, lease, options, entries !== undefined && entries.length > 0);
61
- } catch (error) {
62
- await storage.release(lease);
63
- throw error;
64
- }
65
- }
66
-
67
- get epoch(): number {
68
- return this.lease.epoch;
69
- }
70
-
71
- /** Runs once, when another holder took the session. */
72
- onLost(listener: (error: Error) => void): () => void {
73
- this.lostListeners.add(listener);
74
- return () => this.lostListeners.delete(listener);
75
- }
76
-
77
- /** Resolves when what pi added so far is stored; rejects if it could not be. */
78
- async flush(): Promise<void> {
79
- await this.writing;
80
- if (this.lost) {
81
- throw this.lost;
82
- }
83
- }
84
-
85
- /** Stores what is left and lets another holder take the session at once. */
86
- async close(): Promise<void> {
87
- if (this.closed) {
88
- return;
89
- }
90
- this.closed = true;
91
- clearInterval(this.renewTimer);
92
- await this.writing.catch(() => undefined);
93
- if (!this.lost) {
94
- await this.options.storage.release(this.lease);
95
- }
96
- }
97
-
98
- protected persist(entry: StoredEntry): void {
99
- if (this.lost) {
100
- throw this.lost;
101
- }
102
- if (this.closed) {
103
- throw new Error(`The session ${this.options.sessionId} is closed.`);
104
- }
105
- if (!this.flushed) {
106
- const entries = this.manager.getEntries();
107
- if (!entries.some(candidate => candidate.type === 'message' && (candidate.message.role === 'user' || candidate.message.role === 'assistant'))) {
108
- return;
109
- }
110
- this.flushed = true;
111
- const header = this.manager.getHeader();
112
- this.enqueue([...(header ? [header] : []), ...entries] as unknown as StoredEntry[], true);
113
- return;
114
- }
115
- this.enqueue([entry], false);
116
- }
117
-
118
- protected enqueue(entries: StoredEntry[], replace: boolean): void {
119
- const lease = this.lease;
120
- this.writing = this.writing.then(() =>
121
- this.lost ? undefined : this.options.storage.write(lease, entries, { replace }).catch(error => this.fail(error)),
122
- );
123
- }
124
-
125
- protected async renew(leaseMs: number): Promise<void> {
126
- if (this.lost || this.closed) {
127
- return;
128
- }
129
- try {
130
- this.lease = await this.options.storage.renew(this.lease, leaseMs);
131
- } catch (error) {
132
- if (error instanceof StaleLeaseError) {
133
- this.fail(error);
134
- }
135
- // Other failures (the storage is unreachable) are tried again; the epoch guards the writes meanwhile.
136
- }
137
- }
138
-
139
- protected fail(error: unknown): void {
140
- if (this.lost) {
141
- return;
142
- }
143
- this.lost = error instanceof Error ? error : new Error(String(error));
144
- clearInterval(this.renewTimer);
145
- for (const listener of this.lostListeners) {
146
- listener(this.lost);
147
- }
148
- }
149
- }
@@ -1,42 +0,0 @@
1
- import { Autowired } from '@celljs/core';
2
- import { Rpc } from '@celljs/rpc';
3
- import { ExecEnvironmentFactory } from '@celljs/ta-exec';
4
- import { type TaSettingsScope, TaSettingsServer, type TaSettingsSnapshot } from '@celljs/ta-protocol';
5
- import { TaSettingsStore } from './settings-store';
6
- import { TaErrors } from './ta-errors';
7
-
8
- /** The settings of ta in pi's files; `cwd` defaults to the server's directory. */
9
- @Rpc(TaSettingsServer)
10
- export class TaSettingsServerImpl implements TaSettingsServer {
11
- @Autowired(ExecEnvironmentFactory)
12
- protected readonly environments: ExecEnvironmentFactory;
13
-
14
- @Autowired(TaSettingsStore)
15
- protected readonly settings: TaSettingsStore;
16
-
17
- getSettings(cwd?: string): Promise<TaSettingsSnapshot> {
18
- return TaErrors.guard(async () => this.settings.get(await this.cwd(cwd)));
19
- }
20
-
21
- updateSettings(scope: TaSettingsScope, changes: Record<string, unknown>, cwd?: string): Promise<TaSettingsSnapshot> {
22
- return TaErrors.guard(async () => {
23
- if (scope !== 'user' && scope !== 'project') {
24
- throw TaErrors.invalidArgument(`${String(scope)} is not where settings are kept.`, 'Pass user or project.');
25
- }
26
- return this.settings.update(scope, changes, await this.cwd(cwd));
27
- });
28
- }
29
-
30
- setLanguage(language: string): Promise<void> {
31
- return TaErrors.guard(async () => {
32
- if (typeof language !== 'string' || !/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(language)) {
33
- throw TaErrors.invalidArgument(`${String(language)} is not a language tag.`, 'Pass a tag such as zh-CN or en-US.');
34
- }
35
- process.env.TA_LANGUAGE = language;
36
- });
37
- }
38
-
39
- protected async cwd(cwd?: string): Promise<string> {
40
- return cwd || (await this.environments.defaultCwd());
41
- }
42
- }