onlycode 1.18.0 → 1.20.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 (418) hide show
  1. package/bin/{opencode.cjs → onlycode.cjs} +8 -42
  2. package/package.json +12 -147
  3. package/src/account/account.ts +0 -463
  4. package/src/account/repo.ts +0 -173
  5. package/src/account/schema.ts +0 -99
  6. package/src/account/url.ts +0 -8
  7. package/src/acp/agent.ts +0 -95
  8. package/src/acp/config-option.ts +0 -203
  9. package/src/acp/content.ts +0 -250
  10. package/src/acp/directory.ts +0 -210
  11. package/src/acp/error.ts +0 -90
  12. package/src/acp/event.ts +0 -342
  13. package/src/acp/permission.ts +0 -124
  14. package/src/acp/profile.ts +0 -42
  15. package/src/acp/service.ts +0 -1048
  16. package/src/acp/session.ts +0 -231
  17. package/src/acp/tool.ts +0 -367
  18. package/src/acp/usage.ts +0 -232
  19. package/src/agent/agent.ts +0 -459
  20. package/src/agent/generate.txt +0 -75
  21. package/src/agent/prompt/compaction.txt +0 -9
  22. package/src/agent/prompt/explore.txt +0 -18
  23. package/src/agent/prompt/summary.txt +0 -11
  24. package/src/agent/prompt/title.txt +0 -44
  25. package/src/agent/subagent-permissions.ts +0 -27
  26. package/src/audio.d.ts +0 -14
  27. package/src/auth/index.ts +0 -99
  28. package/src/background/job.ts +0 -39
  29. package/src/bus/global.ts +0 -22
  30. package/src/cli/bootstrap.ts +0 -11
  31. package/src/cli/cmd/account.ts +0 -264
  32. package/src/cli/cmd/acp.ts +0 -73
  33. package/src/cli/cmd/agent.ts +0 -259
  34. package/src/cli/cmd/attach.ts +0 -97
  35. package/src/cli/cmd/cmd.ts +0 -7
  36. package/src/cli/cmd/db.ts +0 -62
  37. package/src/cli/cmd/debug/agent.handler.ts +0 -193
  38. package/src/cli/cmd/debug/agent.ts +0 -27
  39. package/src/cli/cmd/debug/config.ts +0 -14
  40. package/src/cli/cmd/debug/file.ts +0 -73
  41. package/src/cli/cmd/debug/index.ts +0 -87
  42. package/src/cli/cmd/debug/lsp.ts +0 -50
  43. package/src/cli/cmd/debug/ripgrep.ts +0 -79
  44. package/src/cli/cmd/debug/scrap.ts +0 -15
  45. package/src/cli/cmd/debug/skill.ts +0 -15
  46. package/src/cli/cmd/debug/snapshot.ts +0 -50
  47. package/src/cli/cmd/debug/startup.ts +0 -11
  48. package/src/cli/cmd/debug/v2.ts +0 -44
  49. package/src/cli/cmd/export.ts +0 -292
  50. package/src/cli/cmd/generate.ts +0 -54
  51. package/src/cli/cmd/github.handler.ts +0 -1593
  52. package/src/cli/cmd/github.shared.ts +0 -30
  53. package/src/cli/cmd/github.ts +0 -42
  54. package/src/cli/cmd/import.ts +0 -224
  55. package/src/cli/cmd/mcp.ts +0 -849
  56. package/src/cli/cmd/models.ts +0 -66
  57. package/src/cli/cmd/plug.ts +0 -230
  58. package/src/cli/cmd/pr.ts +0 -115
  59. package/src/cli/cmd/prompt-display.ts +0 -1
  60. package/src/cli/cmd/providers.ts +0 -534
  61. package/src/cli/cmd/run/demo.ts +0 -1274
  62. package/src/cli/cmd/run/entry.body.ts +0 -205
  63. package/src/cli/cmd/run/footer.command.tsx +0 -1064
  64. package/src/cli/cmd/run/footer.menu.tsx +0 -351
  65. package/src/cli/cmd/run/footer.permission.tsx +0 -472
  66. package/src/cli/cmd/run/footer.prompt.tsx +0 -1306
  67. package/src/cli/cmd/run/footer.question.tsx +0 -573
  68. package/src/cli/cmd/run/footer.subagent.tsx +0 -173
  69. package/src/cli/cmd/run/footer.ts +0 -1129
  70. package/src/cli/cmd/run/footer.view.tsx +0 -943
  71. package/src/cli/cmd/run/footer.width.ts +0 -27
  72. package/src/cli/cmd/run/permission.shared.ts +0 -256
  73. package/src/cli/cmd/run/prompt.editor.ts +0 -157
  74. package/src/cli/cmd/run/prompt.shared.ts +0 -153
  75. package/src/cli/cmd/run/question.shared.ts +0 -340
  76. package/src/cli/cmd/run/runtime.boot.ts +0 -202
  77. package/src/cli/cmd/run/runtime.lifecycle.ts +0 -406
  78. package/src/cli/cmd/run/runtime.queue.ts +0 -349
  79. package/src/cli/cmd/run/runtime.shared.ts +0 -17
  80. package/src/cli/cmd/run/runtime.stdin.ts +0 -37
  81. package/src/cli/cmd/run/runtime.ts +0 -814
  82. package/src/cli/cmd/run/scrollback.shared.ts +0 -92
  83. package/src/cli/cmd/run/scrollback.surface.ts +0 -431
  84. package/src/cli/cmd/run/scrollback.writer.tsx +0 -352
  85. package/src/cli/cmd/run/session-data.ts +0 -1113
  86. package/src/cli/cmd/run/session-replay.ts +0 -374
  87. package/src/cli/cmd/run/session.shared.ts +0 -196
  88. package/src/cli/cmd/run/splash.ts +0 -275
  89. package/src/cli/cmd/run/stream.transport.ts +0 -1462
  90. package/src/cli/cmd/run/stream.ts +0 -175
  91. package/src/cli/cmd/run/subagent-data.ts +0 -876
  92. package/src/cli/cmd/run/theme.ts +0 -690
  93. package/src/cli/cmd/run/tool.ts +0 -1489
  94. package/src/cli/cmd/run/trace.ts +0 -94
  95. package/src/cli/cmd/run/turn-summary.ts +0 -47
  96. package/src/cli/cmd/run/types.ts +0 -350
  97. package/src/cli/cmd/run/variant.shared.ts +0 -215
  98. package/src/cli/cmd/run.ts +0 -894
  99. package/src/cli/cmd/serve.ts +0 -24
  100. package/src/cli/cmd/session.ts +0 -147
  101. package/src/cli/cmd/stats.ts +0 -393
  102. package/src/cli/cmd/tui.ts +0 -224
  103. package/src/cli/cmd/uninstall.ts +0 -353
  104. package/src/cli/cmd/upgrade.ts +0 -74
  105. package/src/cli/cmd/web.ts +0 -84
  106. package/src/cli/effect/prompt.ts +0 -37
  107. package/src/cli/effect-cmd.ts +0 -96
  108. package/src/cli/error.ts +0 -130
  109. package/src/cli/heap.ts +0 -45
  110. package/src/cli/logo-pixel.ts +0 -35
  111. package/src/cli/logo.ts +0 -1
  112. package/src/cli/network.ts +0 -64
  113. package/src/cli/tui/layer.ts +0 -7
  114. package/src/cli/tui/validate-session.ts +0 -29
  115. package/src/cli/tui/worker.ts +0 -71
  116. package/src/cli/ui.ts +0 -148
  117. package/src/cli/upgrade.ts +0 -53
  118. package/src/command/index.ts +0 -184
  119. package/src/command/template/initialize.txt +0 -66
  120. package/src/command/template/review.txt +0 -101
  121. package/src/config/agent.ts +0 -59
  122. package/src/config/command.ts +0 -39
  123. package/src/config/config.ts +0 -686
  124. package/src/config/entry-name.ts +0 -19
  125. package/src/config/managed.ts +0 -69
  126. package/src/config/markdown.ts +0 -36
  127. package/src/config/parse.ts +0 -79
  128. package/src/config/paths.ts +0 -45
  129. package/src/config/plugin.ts +0 -79
  130. package/src/config/tui-cwd.ts +0 -5
  131. package/src/config/tui-host-attention.ts +0 -21
  132. package/src/config/tui-migrate.ts +0 -132
  133. package/src/config/tui.ts +0 -274
  134. package/src/config/variable.ts +0 -91
  135. package/src/control-plane/adapters/index.ts +0 -41
  136. package/src/control-plane/adapters/worktree.ts +0 -96
  137. package/src/control-plane/dev/README.md +0 -19
  138. package/src/control-plane/dev/debug-workspace-plugin.ts +0 -73
  139. package/src/control-plane/types.ts +0 -59
  140. package/src/control-plane/util.ts +0 -39
  141. package/src/control-plane/workspace-adapter-runtime.ts +0 -51
  142. package/src/control-plane/workspace-context.ts +0 -26
  143. package/src/control-plane/workspace.ts +0 -989
  144. package/src/effect/app-runtime.ts +0 -132
  145. package/src/effect/bootstrap-runtime.ts +0 -23
  146. package/src/effect/bridge.ts +0 -84
  147. package/src/effect/config-service.ts +0 -67
  148. package/src/effect/instance-ref.ts +0 -11
  149. package/src/effect/instance-registry.ts +0 -12
  150. package/src/effect/instance-state.ts +0 -69
  151. package/src/effect/promise.ts +0 -17
  152. package/src/effect/run-service.ts +0 -47
  153. package/src/effect/runner.ts +0 -217
  154. package/src/effect/runtime-flags.ts +0 -79
  155. package/src/env/index.ts +0 -43
  156. package/src/event-v2-bridge.ts +0 -79
  157. package/src/format/formatter.ts +0 -404
  158. package/src/format/index.ts +0 -205
  159. package/src/git/index.ts +0 -350
  160. package/src/id/id.ts +0 -80
  161. package/src/ide/index.ts +0 -61
  162. package/src/image/image.ts +0 -174
  163. package/src/index.ts +0 -142
  164. package/src/installation/index.ts +0 -350
  165. package/src/lsp/client.ts +0 -650
  166. package/src/lsp/diagnostic.ts +0 -29
  167. package/src/lsp/language.ts +0 -121
  168. package/src/lsp/launch.ts +0 -21
  169. package/src/lsp/lsp.ts +0 -511
  170. package/src/lsp/server.ts +0 -1983
  171. package/src/markdown.d.ts +0 -4
  172. package/src/mcp/auth.ts +0 -174
  173. package/src/mcp/catalog.ts +0 -153
  174. package/src/mcp/index.ts +0 -953
  175. package/src/mcp/oauth-callback.ts +0 -233
  176. package/src/mcp/oauth-provider.ts +0 -206
  177. package/src/node.ts +0 -4
  178. package/src/patch/index.ts +0 -686
  179. package/src/permission/arity.ts +0 -163
  180. package/src/permission/evaluate.ts +0 -1
  181. package/src/permission/index.ts +0 -230
  182. package/src/plugin/azure.ts +0 -26
  183. package/src/plugin/cloudflare.ts +0 -76
  184. package/src/plugin/digitalocean.ts +0 -383
  185. package/src/plugin/github-copilot/copilot.ts +0 -414
  186. package/src/plugin/github-copilot/models.ts +0 -246
  187. package/src/plugin/index.ts +0 -316
  188. package/src/plugin/install.ts +0 -439
  189. package/src/plugin/loader.ts +0 -237
  190. package/src/plugin/meta.ts +0 -188
  191. package/src/plugin/openai/README.md +0 -31
  192. package/src/plugin/openai/codex.ts +0 -641
  193. package/src/plugin/openai/ws-pool.ts +0 -270
  194. package/src/plugin/openai/ws.ts +0 -381
  195. package/src/plugin/pty-environment.ts +0 -24
  196. package/src/plugin/shared.ts +0 -323
  197. package/src/plugin/snowflake-cortex.ts +0 -529
  198. package/src/plugin/tui/internal.ts +0 -10
  199. package/src/plugin/tui/runtime.ts +0 -1130
  200. package/src/plugin/xai.ts +0 -716
  201. package/src/project/bootstrap-service.ts +0 -9
  202. package/src/project/bootstrap.ts +0 -76
  203. package/src/project/instance-context.ts +0 -24
  204. package/src/project/instance-layer.ts +0 -11
  205. package/src/project/instance-runtime.ts +0 -16
  206. package/src/project/instance-store.ts +0 -209
  207. package/src/project/project.ts +0 -519
  208. package/src/project/vcs.ts +0 -431
  209. package/src/provider/auth.ts +0 -233
  210. package/src/provider/error.ts +0 -188
  211. package/src/provider/model-status.ts +0 -8
  212. package/src/provider/provider.ts +0 -1975
  213. package/src/provider/transform.ts +0 -1543
  214. package/src/question/index.ts +0 -229
  215. package/src/question/schema.ts +0 -10
  216. package/src/server/auth.ts +0 -48
  217. package/src/server/event.ts +0 -13
  218. package/src/server/global-lifecycle.ts +0 -28
  219. package/src/server/init-projectors.ts +0 -3
  220. package/src/server/mdns.ts +0 -47
  221. package/src/server/projectors.ts +0 -1
  222. package/src/server/proxy-util.ts +0 -48
  223. package/src/server/routes/instance/httpapi/AGENTS.md +0 -39
  224. package/src/server/routes/instance/httpapi/api.ts +0 -78
  225. package/src/server/routes/instance/httpapi/errors.ts +0 -193
  226. package/src/server/routes/instance/httpapi/groups/config.ts +0 -65
  227. package/src/server/routes/instance/httpapi/groups/control-plane.ts +0 -35
  228. package/src/server/routes/instance/httpapi/groups/control.ts +0 -76
  229. package/src/server/routes/instance/httpapi/groups/event.ts +0 -29
  230. package/src/server/routes/instance/httpapi/groups/experimental.ts +0 -275
  231. package/src/server/routes/instance/httpapi/groups/file.ts +0 -185
  232. package/src/server/routes/instance/httpapi/groups/global.ts +0 -138
  233. package/src/server/routes/instance/httpapi/groups/instance.ts +0 -206
  234. package/src/server/routes/instance/httpapi/groups/mcp.ts +0 -156
  235. package/src/server/routes/instance/httpapi/groups/metadata.ts +0 -18
  236. package/src/server/routes/instance/httpapi/groups/permission.ts +0 -61
  237. package/src/server/routes/instance/httpapi/groups/project-copy.ts +0 -32
  238. package/src/server/routes/instance/httpapi/groups/project.ts +0 -93
  239. package/src/server/routes/instance/httpapi/groups/provider.ts +0 -101
  240. package/src/server/routes/instance/httpapi/groups/pty.ts +0 -172
  241. package/src/server/routes/instance/httpapi/groups/query.ts +0 -12
  242. package/src/server/routes/instance/httpapi/groups/question.ts +0 -74
  243. package/src/server/routes/instance/httpapi/groups/session.ts +0 -462
  244. package/src/server/routes/instance/httpapi/groups/sync.ts +0 -113
  245. package/src/server/routes/instance/httpapi/groups/tui.ts +0 -208
  246. package/src/server/routes/instance/httpapi/groups/workspace.ts +0 -141
  247. package/src/server/routes/instance/httpapi/handlers/config.ts +0 -34
  248. package/src/server/routes/instance/httpapi/handlers/control-plane.ts +0 -37
  249. package/src/server/routes/instance/httpapi/handlers/control.ts +0 -43
  250. package/src/server/routes/instance/httpapi/handlers/event.ts +0 -99
  251. package/src/server/routes/instance/httpapi/handlers/experimental.ts +0 -192
  252. package/src/server/routes/instance/httpapi/handlers/file.ts +0 -139
  253. package/src/server/routes/instance/httpapi/handlers/global.ts +0 -156
  254. package/src/server/routes/instance/httpapi/handlers/instance.ts +0 -110
  255. package/src/server/routes/instance/httpapi/handlers/mcp.ts +0 -111
  256. package/src/server/routes/instance/httpapi/handlers/permission.ts +0 -41
  257. package/src/server/routes/instance/httpapi/handlers/project-copy.ts +0 -83
  258. package/src/server/routes/instance/httpapi/handlers/project.ts +0 -63
  259. package/src/server/routes/instance/httpapi/handlers/provider.ts +0 -113
  260. package/src/server/routes/instance/httpapi/handlers/pty.ts +0 -273
  261. package/src/server/routes/instance/httpapi/handlers/question.ts +0 -54
  262. package/src/server/routes/instance/httpapi/handlers/session-errors.ts +0 -21
  263. package/src/server/routes/instance/httpapi/handlers/session.ts +0 -440
  264. package/src/server/routes/instance/httpapi/handlers/sync.ts +0 -89
  265. package/src/server/routes/instance/httpapi/handlers/tui.ts +0 -131
  266. package/src/server/routes/instance/httpapi/handlers/workspace.ts +0 -102
  267. package/src/server/routes/instance/httpapi/lifecycle.ts +0 -54
  268. package/src/server/routes/instance/httpapi/middleware/authorization.ts +0 -150
  269. package/src/server/routes/instance/httpapi/middleware/compression.ts +0 -64
  270. package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +0 -29
  271. package/src/server/routes/instance/httpapi/middleware/error.ts +0 -43
  272. package/src/server/routes/instance/httpapi/middleware/fence.ts +0 -25
  273. package/src/server/routes/instance/httpapi/middleware/instance-context.ts +0 -43
  274. package/src/server/routes/instance/httpapi/middleware/proxy.ts +0 -108
  275. package/src/server/routes/instance/httpapi/middleware/schema-error.ts +0 -41
  276. package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +0 -250
  277. package/src/server/routes/instance/httpapi/public.ts +0 -535
  278. package/src/server/routes/instance/httpapi/server.ts +0 -298
  279. package/src/server/routes/instance/httpapi/websocket-tracker.ts +0 -57
  280. package/src/server/server.ts +0 -225
  281. package/src/server/shared/fence.ts +0 -60
  282. package/src/server/shared/pty-ticket.ts +0 -15
  283. package/src/server/shared/public-ui.ts +0 -12
  284. package/src/server/shared/tui-control.ts +0 -28
  285. package/src/server/shared/ui.ts +0 -108
  286. package/src/server/shared/workspace-routing.ts +0 -38
  287. package/src/server/tui-event.ts +0 -53
  288. package/src/session/compaction.ts +0 -620
  289. package/src/session/instruction.ts +0 -241
  290. package/src/session/llm/AGENTS.md +0 -90
  291. package/src/session/llm/ai-sdk.ts +0 -288
  292. package/src/session/llm/native-request.ts +0 -196
  293. package/src/session/llm/native-runtime.ts +0 -195
  294. package/src/session/llm/request.ts +0 -216
  295. package/src/session/llm.ts +0 -415
  296. package/src/session/message-error.ts +0 -14
  297. package/src/session/message-v2.ts +0 -747
  298. package/src/session/message.ts +0 -148
  299. package/src/session/overflow.ts +0 -34
  300. package/src/session/processor.ts +0 -1084
  301. package/src/session/prompt/anthropic.txt +0 -109
  302. package/src/session/prompt/beast.txt +0 -151
  303. package/src/session/prompt/build-switch.txt +0 -9
  304. package/src/session/prompt/codex.txt +0 -83
  305. package/src/session/prompt/copilot-gpt-5.txt +0 -147
  306. package/src/session/prompt/default.txt +0 -99
  307. package/src/session/prompt/gemini.txt +0 -159
  308. package/src/session/prompt/gpt.txt +0 -111
  309. package/src/session/prompt/kimi.txt +0 -99
  310. package/src/session/prompt/plan-mode.txt +0 -74
  311. package/src/session/prompt/plan-reminder-anthropic.txt +0 -71
  312. package/src/session/prompt/plan.txt +0 -30
  313. package/src/session/prompt/trinity.txt +0 -101
  314. package/src/session/prompt.ts +0 -1707
  315. package/src/session/reminders.ts +0 -92
  316. package/src/session/retry.ts +0 -201
  317. package/src/session/revert.ts +0 -160
  318. package/src/session/run-state.ts +0 -156
  319. package/src/session/schema.ts +0 -26
  320. package/src/session/session.ts +0 -1119
  321. package/src/session/status.ts +0 -97
  322. package/src/session/summary.ts +0 -165
  323. package/src/session/system.ts +0 -117
  324. package/src/session/todo.ts +0 -90
  325. package/src/session/tools.ts +0 -207
  326. package/src/share/session.ts +0 -61
  327. package/src/share/share-next.ts +0 -385
  328. package/src/skill/discovery.ts +0 -109
  329. package/src/skill/index.ts +0 -366
  330. package/src/snapshot/index.ts +0 -808
  331. package/src/sql.d.ts +0 -4
  332. package/src/storage/schema.ts +0 -5
  333. package/src/storage/storage.ts +0 -329
  334. package/src/sync/README.md +0 -179
  335. package/src/sync/schema.ts +0 -11
  336. package/src/temporary.ts +0 -31
  337. package/src/tool/apply_patch.ts +0 -315
  338. package/src/tool/apply_patch.txt +0 -33
  339. package/src/tool/apply_patch.zh.txt +0 -33
  340. package/src/tool/description.ts +0 -100
  341. package/src/tool/edit.ts +0 -739
  342. package/src/tool/edit.txt +0 -10
  343. package/src/tool/edit.zh.txt +0 -10
  344. package/src/tool/external-directory.ts +0 -49
  345. package/src/tool/glob.ts +0 -78
  346. package/src/tool/glob.txt +0 -6
  347. package/src/tool/glob.zh.txt +0 -6
  348. package/src/tool/grep.ts +0 -114
  349. package/src/tool/grep.txt +0 -8
  350. package/src/tool/grep.zh.txt +0 -8
  351. package/src/tool/invalid.ts +0 -21
  352. package/src/tool/json-schema.ts +0 -164
  353. package/src/tool/lsp.ts +0 -115
  354. package/src/tool/lsp.txt +0 -24
  355. package/src/tool/lsp.zh.txt +0 -24
  356. package/src/tool/mcp-websearch.ts +0 -96
  357. package/src/tool/plan-enter.txt +0 -14
  358. package/src/tool/plan-enter.zh.txt +0 -14
  359. package/src/tool/plan-exit.txt +0 -13
  360. package/src/tool/plan-exit.zh.txt +0 -13
  361. package/src/tool/plan.ts +0 -81
  362. package/src/tool/question.ts +0 -46
  363. package/src/tool/question.txt +0 -10
  364. package/src/tool/question.zh.txt +0 -10
  365. package/src/tool/read.ts +0 -388
  366. package/src/tool/read.txt +0 -14
  367. package/src/tool/read.zh.txt +0 -14
  368. package/src/tool/registry.ts +0 -440
  369. package/src/tool/schema.ts +0 -14
  370. package/src/tool/shell/id.ts +0 -19
  371. package/src/tool/shell/prompt.ts +0 -307
  372. package/src/tool/shell/shell.txt +0 -21
  373. package/src/tool/shell.ts +0 -657
  374. package/src/tool/skill.ts +0 -73
  375. package/src/tool/skill.txt +0 -5
  376. package/src/tool/skill.zh.txt +0 -5
  377. package/src/tool/task.ts +0 -348
  378. package/src/tool/task.txt +0 -19
  379. package/src/tool/task.zh.txt +0 -19
  380. package/src/tool/todo.ts +0 -59
  381. package/src/tool/todowrite.txt +0 -44
  382. package/src/tool/todowrite.zh.txt +0 -44
  383. package/src/tool/tool.ts +0 -183
  384. package/src/tool/truncate.ts +0 -158
  385. package/src/tool/truncation-dir.ts +0 -4
  386. package/src/tool/webfetch.ts +0 -194
  387. package/src/tool/webfetch.txt +0 -13
  388. package/src/tool/webfetch.zh.txt +0 -13
  389. package/src/tool/websearch.ts +0 -145
  390. package/src/tool/websearch.txt +0 -14
  391. package/src/tool/websearch.zh.txt +0 -14
  392. package/src/tool/write.ts +0 -106
  393. package/src/tool/write.txt +0 -8
  394. package/src/tool/write.zh.txt +0 -8
  395. package/src/util/archive.ts +0 -17
  396. package/src/util/bom.ts +0 -27
  397. package/src/util/data-url.ts +0 -9
  398. package/src/util/defer.ts +0 -10
  399. package/src/util/effect-http-client.ts +0 -11
  400. package/src/util/error.ts +0 -1
  401. package/src/util/filesystem.ts +0 -251
  402. package/src/util/html.ts +0 -8
  403. package/src/util/iife.ts +0 -3
  404. package/src/util/lazy.ts +0 -20
  405. package/src/util/local-context.ts +0 -25
  406. package/src/util/locale.ts +0 -2
  407. package/src/util/media.ts +0 -26
  408. package/src/util/process.ts +0 -177
  409. package/src/util/proxy-env.ts +0 -72
  410. package/src/util/queue.ts +0 -32
  411. package/src/util/record.ts +0 -1
  412. package/src/util/repository.ts +0 -232
  413. package/src/util/rpc.ts +0 -66
  414. package/src/util/signal.ts +0 -12
  415. package/src/util/timeout.ts +0 -13
  416. package/src/util/token.ts +0 -1
  417. package/src/util/wildcard.ts +0 -59
  418. package/src/worktree/index.ts +0 -654
@@ -1,54 +0,0 @@
1
- import { Question } from "@/question"
2
- import { QuestionID } from "@/question/schema"
3
- import { Effect } from "effect"
4
- import { HttpApiBuilder } from "effect/unstable/httpapi"
5
- import { InstanceHttpApi } from "../api"
6
- import { QuestionNotFoundError } from "../errors"
7
-
8
- export const questionHandlers = HttpApiBuilder.group(InstanceHttpApi, "question", (handlers) =>
9
- Effect.gen(function* () {
10
- const svc = yield* Question.Service
11
-
12
- const list = Effect.fn("QuestionHttpApi.list")(function* () {
13
- return yield* svc.list()
14
- })
15
-
16
- const reply = Effect.fn("QuestionHttpApi.reply")(function* (ctx: {
17
- params: { requestID: QuestionID }
18
- payload: Question.Reply
19
- }) {
20
- yield* svc
21
- .reply({
22
- requestID: ctx.params.requestID,
23
- answers: ctx.payload.answers,
24
- })
25
- .pipe(
26
- Effect.catchTag("Question.NotFoundError", (error) =>
27
- Effect.fail(
28
- new QuestionNotFoundError({
29
- requestID: String(error.requestID),
30
- message: `Question request not found: ${error.requestID}`,
31
- }),
32
- ),
33
- ),
34
- )
35
- return true
36
- })
37
-
38
- const reject = Effect.fn("QuestionHttpApi.reject")(function* (ctx: { params: { requestID: QuestionID } }) {
39
- yield* svc.reject(ctx.params.requestID).pipe(
40
- Effect.catchTag("Question.NotFoundError", (error) =>
41
- Effect.fail(
42
- new QuestionNotFoundError({
43
- requestID: String(error.requestID),
44
- message: `Question request not found: ${error.requestID}`,
45
- }),
46
- ),
47
- ),
48
- )
49
- return true
50
- })
51
-
52
- return handlers.handle("list", list).handle("reply", reply).handle("reject", reject)
53
- }),
54
- )
@@ -1,21 +0,0 @@
1
- import type { NotFoundError as StorageNotFoundError } from "@/storage/storage"
2
- import type { Session } from "@/session/session"
3
- import { Effect } from "effect"
4
- import * as ApiError from "../errors"
5
-
6
- export function mapStorageNotFound<A, R>(self: Effect.Effect<A, StorageNotFoundError, R>) {
7
- return self.pipe(Effect.mapError((error) => ApiError.notFound(error.message)))
8
- }
9
-
10
- export function mapBusy<A, R>(self: Effect.Effect<A, Session.BusyError, R>) {
11
- return self.pipe(
12
- Effect.catchTag("SessionBusyError", (error) =>
13
- Effect.fail(
14
- new ApiError.SessionBusyError({
15
- sessionID: error.sessionID,
16
- message: `Session is busy: ${error.sessionID}`,
17
- }),
18
- ),
19
- ),
20
- )
21
- }
@@ -1,440 +0,0 @@
1
- import { PermissionV1 } from "@opencode-ai/core/v1/permission"
2
- import { Agent } from "@/agent/agent"
3
- import { SessionV1 } from "@opencode-ai/core/v1/session"
4
- import { EventV2Bridge } from "@/event-v2-bridge"
5
- import { Command } from "@/command"
6
- import { Permission } from "@/permission"
7
- import { SessionShare } from "@/share/session"
8
- import { Session } from "@/session/session"
9
- import { SessionCompaction } from "@/session/compaction"
10
- import { MessageV2 } from "@/session/message-v2"
11
- import { SessionPrompt } from "@/session/prompt"
12
- import { SessionRevert } from "@/session/revert"
13
- import { SessionRunState } from "@/session/run-state"
14
- import { SessionStatus } from "@/session/status"
15
- import { SessionSummary } from "@/session/summary"
16
- import { Todo } from "@/session/todo"
17
- import { MessageID, PartID, SessionID } from "@/session/schema"
18
- import { NamedError } from "@opencode-ai/core/util/error"
19
- import { Cause, Effect, Option, Schema, Scope } from "effect"
20
- import * as Stream from "effect/Stream"
21
- import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http"
22
- import { HttpApiBuilder, HttpApiError, HttpApiSchema } from "effect/unstable/httpapi"
23
- import { InstanceHttpApi } from "../api"
24
- import {
25
- CommandPayload,
26
- DiffQuery,
27
- ForkPayload,
28
- InitPayload,
29
- ListQuery,
30
- MessagesQuery,
31
- PermissionResponsePayload,
32
- PromptPayload,
33
- RevertPayload,
34
- ShellPayload,
35
- SummarizePayload,
36
- UpdatePayload,
37
- } from "../groups/session"
38
- import { PermissionNotFoundError } from "../errors"
39
- import * as SessionError from "./session-errors"
40
-
41
- const tryParseJson = (text: string) =>
42
- Effect.try({
43
- try: () => JSON.parse(text) as unknown,
44
- catch: () => new HttpApiError.BadRequest({}),
45
- })
46
-
47
- export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session", (handlers) =>
48
- Effect.gen(function* () {
49
- const session = yield* Session.Service
50
- const shareSvc = yield* SessionShare.Service
51
- const promptSvc = yield* SessionPrompt.Service
52
- const revertSvc = yield* SessionRevert.Service
53
- const compactSvc = yield* SessionCompaction.Service
54
- const runState = yield* SessionRunState.Service
55
- const agentSvc = yield* Agent.Service
56
- const permissionSvc = yield* Permission.Service
57
- const statusSvc = yield* SessionStatus.Service
58
- const todoSvc = yield* Todo.Service
59
- const summary = yield* SessionSummary.Service
60
- const events = yield* EventV2Bridge.Service
61
- const scope = yield* Scope.Scope
62
-
63
- const list = Effect.fn("SessionHttpApi.list")(function* (ctx: { query: typeof ListQuery.Type }) {
64
- return yield* session.list({
65
- directory: ctx.query.scope === "project" ? undefined : ctx.query.directory,
66
- scope: ctx.query.scope,
67
- path: ctx.query.path,
68
- roots: ctx.query.roots,
69
- start: ctx.query.start,
70
- search: ctx.query.search,
71
- limit: ctx.query.limit,
72
- })
73
- })
74
-
75
- const status = Effect.fn("SessionHttpApi.status")(function* () {
76
- return Object.fromEntries(yield* statusSvc.list())
77
- })
78
-
79
- const requireSession = Effect.fn("SessionHttpApi.requireSession")(function* (sessionID: SessionID) {
80
- return yield* SessionError.mapStorageNotFound(session.get(sessionID))
81
- })
82
-
83
- const get = Effect.fn("SessionHttpApi.get")(function* (ctx: { params: { sessionID: SessionID } }) {
84
- return yield* requireSession(ctx.params.sessionID)
85
- })
86
-
87
- const children = Effect.fn("SessionHttpApi.children")(function* (ctx: { params: { sessionID: SessionID } }) {
88
- yield* requireSession(ctx.params.sessionID)
89
- return yield* session.children(ctx.params.sessionID)
90
- })
91
-
92
- const todo = Effect.fn("SessionHttpApi.todo")(function* (ctx: { params: { sessionID: SessionID } }) {
93
- yield* requireSession(ctx.params.sessionID)
94
- return yield* todoSvc.get(ctx.params.sessionID)
95
- })
96
-
97
- const diff = Effect.fn("SessionHttpApi.diff")(function* (ctx: {
98
- params: { sessionID: SessionID }
99
- query: typeof DiffQuery.Type
100
- }) {
101
- return yield* summary.diff({ sessionID: ctx.params.sessionID, messageID: ctx.query.messageID })
102
- })
103
-
104
- const messages = Effect.fn("SessionHttpApi.messages")(function* (ctx: {
105
- params: { sessionID: SessionID }
106
- query: typeof MessagesQuery.Type
107
- }) {
108
- if (ctx.query.before && ctx.query.limit === undefined) return yield* new HttpApiError.BadRequest({})
109
- if (ctx.query.before) {
110
- const before = ctx.query.before
111
- yield* Effect.try({
112
- try: () => MessageV2.cursor.decode(before),
113
- catch: () => new HttpApiError.BadRequest({}),
114
- })
115
- }
116
- yield* requireSession(ctx.params.sessionID)
117
- if (ctx.query.limit === undefined || ctx.query.limit === 0) {
118
- return yield* SessionError.mapStorageNotFound(session.messages({ sessionID: ctx.params.sessionID }))
119
- }
120
-
121
- const page = yield* SessionError.mapStorageNotFound(
122
- MessageV2.page({
123
- sessionID: ctx.params.sessionID,
124
- limit: ctx.query.limit,
125
- before: ctx.query.before,
126
- }),
127
- )
128
- if (!page.cursor) return page.items
129
-
130
- const request = yield* HttpServerRequest.HttpServerRequest
131
- // toURL() honors the Host + x-forwarded-proto headers, so the Link
132
- // header echoes the real origin instead of a hard-coded localhost.
133
- const url = Option.getOrElse(HttpServerRequest.toURL(request), () => new URL(request.url, "http://localhost"))
134
- url.searchParams.set("limit", ctx.query.limit.toString())
135
- url.searchParams.set("before", page.cursor)
136
- return HttpServerResponse.jsonUnsafe(page.items, {
137
- headers: {
138
- "Access-Control-Expose-Headers": "Link, X-Next-Cursor",
139
- Link: `<${url.toString()}>; rel="next"`,
140
- "X-Next-Cursor": page.cursor,
141
- },
142
- })
143
- })
144
-
145
- const message = Effect.fn("SessionHttpApi.message")(function* (ctx: {
146
- params: { sessionID: SessionID; messageID: MessageID }
147
- }) {
148
- return yield* SessionError.mapStorageNotFound(
149
- MessageV2.get({ sessionID: ctx.params.sessionID, messageID: ctx.params.messageID }),
150
- )
151
- })
152
-
153
- const create = Effect.fn("SessionHttpApi.create")(function* (ctx: { payload?: Session.CreateInput }) {
154
- return yield* shareSvc.create(ctx.payload)
155
- })
156
-
157
- const createRaw = Effect.fn("SessionHttpApi.createRaw")(function* (ctx: {
158
- request: HttpServerRequest.HttpServerRequest
159
- }) {
160
- const body = yield* Effect.orDie(ctx.request.text)
161
- if (body.trim().length === 0) return yield* create({})
162
-
163
- const json = yield* tryParseJson(body)
164
- const decoded = yield* Schema.decodeUnknownEffect(Session.CreateInput)(json).pipe(
165
- Effect.mapError(() => new HttpApiError.BadRequest({})),
166
- )
167
- const payload = decoded
168
- ? {
169
- ...decoded,
170
- permission: decoded.permission ? [...decoded.permission] : undefined,
171
- }
172
- : decoded
173
- return yield* create({ payload })
174
- })
175
-
176
- const remove = Effect.fn("SessionHttpApi.remove")(function* (ctx: { params: { sessionID: SessionID } }) {
177
- yield* SessionError.mapStorageNotFound(session.remove(ctx.params.sessionID))
178
- return true
179
- })
180
-
181
- const update = Effect.fn("SessionHttpApi.update")(function* (ctx: {
182
- params: { sessionID: SessionID }
183
- payload: typeof UpdatePayload.Type
184
- }) {
185
- const current = yield* requireSession(ctx.params.sessionID)
186
- if (ctx.payload.title !== undefined) {
187
- yield* session.setTitle({ sessionID: ctx.params.sessionID, title: ctx.payload.title })
188
- }
189
- if (ctx.payload.metadata !== undefined) {
190
- yield* session.setMetadata({ sessionID: ctx.params.sessionID, metadata: ctx.payload.metadata })
191
- }
192
- if (ctx.payload.permission !== undefined) {
193
- yield* session.setPermission({
194
- sessionID: ctx.params.sessionID,
195
- permission: Permission.merge(current.permission ?? [], ctx.payload.permission),
196
- })
197
- }
198
- if (ctx.payload.time?.archived !== undefined) {
199
- yield* session.setArchived({ sessionID: ctx.params.sessionID, time: ctx.payload.time.archived })
200
- }
201
- return yield* requireSession(ctx.params.sessionID)
202
- })
203
-
204
- const fork = Effect.fn("SessionHttpApi.fork")(function* (ctx: {
205
- params: { sessionID: SessionID }
206
- payload?: typeof ForkPayload.Type
207
- }) {
208
- return yield* SessionError.mapStorageNotFound(
209
- session.fork({
210
- sessionID: ctx.params.sessionID,
211
- messageID: ctx.payload?.messageID,
212
- }),
213
- )
214
- })
215
-
216
- const forkRaw = Effect.fn("SessionHttpApi.forkRaw")(function* (ctx: {
217
- params: { sessionID: SessionID }
218
- request: HttpServerRequest.HttpServerRequest
219
- }) {
220
- const body = yield* Effect.orDie(ctx.request.text)
221
- if (body.trim().length === 0) return yield* fork({ params: ctx.params })
222
-
223
- const json = yield* tryParseJson(body)
224
- const payload = yield* Schema.decodeUnknownEffect(ForkPayload)(json).pipe(
225
- Effect.mapError(() => new HttpApiError.BadRequest({})),
226
- )
227
- return yield* fork({ params: ctx.params, payload })
228
- })
229
-
230
- const abort = Effect.fn("SessionHttpApi.abort")(function* (ctx: { params: { sessionID: SessionID } }) {
231
- yield* promptSvc.cancel(ctx.params.sessionID)
232
- return true
233
- })
234
-
235
- const init = Effect.fn("SessionHttpApi.init")(function* (ctx: {
236
- params: { sessionID: SessionID }
237
- payload: typeof InitPayload.Type
238
- }) {
239
- yield* requireSession(ctx.params.sessionID)
240
- yield* promptSvc
241
- .command({
242
- sessionID: ctx.params.sessionID,
243
- messageID: ctx.payload.messageID,
244
- model: `${ctx.payload.providerID}/${ctx.payload.modelID}`,
245
- command: Command.Default.INIT,
246
- arguments: "",
247
- })
248
- .pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
249
- return true
250
- })
251
-
252
- // share/unshare errors aren't all client-induced — storage and network
253
- // failures from SessionShare are real possibilities. Map to a typed 500
254
- // (matches the legacy route behavior which routed any failure through
255
- // ErrorMiddleware → NamedError.Unknown 500) instead of blanket-mapping
256
- // every failure to a 400 BadRequest.
257
- const share = Effect.fn("SessionHttpApi.share")(function* (ctx: { params: { sessionID: SessionID } }) {
258
- yield* requireSession(ctx.params.sessionID)
259
- yield* shareSvc.share(ctx.params.sessionID).pipe(Effect.mapError(() => new HttpApiError.InternalServerError({})))
260
- return yield* requireSession(ctx.params.sessionID)
261
- })
262
-
263
- const unshare = Effect.fn("SessionHttpApi.unshare")(function* (ctx: { params: { sessionID: SessionID } }) {
264
- yield* requireSession(ctx.params.sessionID)
265
- yield* shareSvc
266
- .unshare(ctx.params.sessionID)
267
- .pipe(Effect.mapError(() => new HttpApiError.InternalServerError({})))
268
- return yield* requireSession(ctx.params.sessionID)
269
- })
270
-
271
- const summarize = Effect.fn("SessionHttpApi.summarize")(function* (ctx: {
272
- params: { sessionID: SessionID }
273
- payload: typeof SummarizePayload.Type
274
- }) {
275
- yield* revertSvc.cleanup(yield* requireSession(ctx.params.sessionID))
276
- const messages = yield* SessionError.mapStorageNotFound(session.messages({ sessionID: ctx.params.sessionID }))
277
- const defaultAgent = yield* agentSvc.defaultAgent()
278
- const currentAgent = messages.findLast((message) => message.info.role === "user")?.info.agent ?? defaultAgent
279
-
280
- yield* compactSvc.create({
281
- sessionID: ctx.params.sessionID,
282
- agent: currentAgent,
283
- model: {
284
- providerID: ctx.payload.providerID,
285
- modelID: ctx.payload.modelID,
286
- },
287
- auto: ctx.payload.auto ?? false,
288
- })
289
- yield* promptSvc.loop({ sessionID: ctx.params.sessionID })
290
- return true
291
- })
292
-
293
- const prompt = Effect.fn("SessionHttpApi.prompt")(function* (ctx: {
294
- params: { sessionID: SessionID }
295
- payload: typeof PromptPayload.Type
296
- }) {
297
- yield* requireSession(ctx.params.sessionID)
298
- const message = yield* promptSvc
299
- .prompt({
300
- ...ctx.payload,
301
- sessionID: ctx.params.sessionID,
302
- })
303
- .pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
304
- return HttpServerResponse.stream(Stream.make(JSON.stringify(message)).pipe(Stream.encodeText), {
305
- contentType: "application/json",
306
- })
307
- })
308
-
309
- const promptAsync = Effect.fn("SessionHttpApi.promptAsync")(function* (ctx: {
310
- params: { sessionID: SessionID }
311
- payload: typeof PromptPayload.Type
312
- }) {
313
- yield* requireSession(ctx.params.sessionID)
314
- yield* promptSvc.prompt({ ...ctx.payload, sessionID: ctx.params.sessionID }).pipe(
315
- Effect.catchCause((cause) =>
316
- Effect.gen(function* () {
317
- yield* Effect.logError("prompt_async failed", { sessionID: ctx.params.sessionID, cause })
318
- yield* events.publish(Session.Event.Error, {
319
- sessionID: ctx.params.sessionID,
320
- error: new NamedError.Unknown({ message: Cause.pretty(cause) }).toObject(),
321
- })
322
- }),
323
- ),
324
- Effect.forkIn(scope, { startImmediately: true }),
325
- )
326
- return HttpApiSchema.NoContent.make()
327
- })
328
-
329
- const command = Effect.fn("SessionHttpApi.command")(function* (ctx: {
330
- params: { sessionID: SessionID }
331
- payload: typeof CommandPayload.Type
332
- }) {
333
- yield* requireSession(ctx.params.sessionID)
334
- return yield* promptSvc
335
- .command({ ...ctx.payload, sessionID: ctx.params.sessionID })
336
- .pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
337
- })
338
-
339
- const shell = Effect.fn("SessionHttpApi.shell")(function* (ctx: {
340
- params: { sessionID: SessionID }
341
- payload: typeof ShellPayload.Type
342
- }) {
343
- yield* requireSession(ctx.params.sessionID)
344
- return yield* SessionError.mapBusy(promptSvc.shell({ ...ctx.payload, sessionID: ctx.params.sessionID }))
345
- })
346
-
347
- const revert = Effect.fn("SessionHttpApi.revert")(function* (ctx: {
348
- params: { sessionID: SessionID }
349
- payload: typeof RevertPayload.Type
350
- }) {
351
- yield* requireSession(ctx.params.sessionID)
352
- return yield* SessionError.mapBusy(revertSvc.revert({ sessionID: ctx.params.sessionID, ...ctx.payload }))
353
- })
354
-
355
- const unrevert = Effect.fn("SessionHttpApi.unrevert")(function* (ctx: { params: { sessionID: SessionID } }) {
356
- yield* requireSession(ctx.params.sessionID)
357
- return yield* SessionError.mapBusy(revertSvc.unrevert({ sessionID: ctx.params.sessionID }))
358
- })
359
-
360
- const permissionRespond = Effect.fn("SessionHttpApi.permissionRespond")(function* (ctx: {
361
- params: { sessionID: SessionID; permissionID: PermissionV1.ID }
362
- payload: typeof PermissionResponsePayload.Type
363
- }) {
364
- yield* requireSession(ctx.params.sessionID)
365
- yield* permissionSvc.reply({ requestID: ctx.params.permissionID, reply: ctx.payload.response }).pipe(
366
- Effect.catchTag("Permission.NotFoundError", (error) =>
367
- Effect.fail(
368
- new PermissionNotFoundError({
369
- requestID: String(error.requestID),
370
- message: `Permission request not found: ${error.requestID}`,
371
- }),
372
- ),
373
- ),
374
- )
375
- return true
376
- })
377
-
378
- const deleteMessage = Effect.fn("SessionHttpApi.deleteMessage")(function* (ctx: {
379
- params: { sessionID: SessionID; messageID: MessageID }
380
- }) {
381
- yield* requireSession(ctx.params.sessionID)
382
- yield* SessionError.mapBusy(runState.assertNotBusy(ctx.params.sessionID))
383
- yield* session.removeMessage(ctx.params)
384
- return true
385
- })
386
-
387
- const deletePart = Effect.fn("SessionHttpApi.deletePart")(function* (ctx: {
388
- params: { sessionID: SessionID; messageID: MessageID; partID: PartID }
389
- }) {
390
- yield* requireSession(ctx.params.sessionID)
391
- yield* session.removePart(ctx.params)
392
- return true
393
- })
394
-
395
- const updatePart = Effect.fn("SessionHttpApi.updatePart")(function* (ctx: {
396
- params: { sessionID: SessionID; messageID: MessageID; partID: PartID }
397
- payload: typeof SessionV1.Part.Type
398
- }) {
399
- yield* requireSession(ctx.params.sessionID)
400
- const payload = ctx.payload as SessionV1.Part
401
- if (
402
- payload.id !== ctx.params.partID ||
403
- payload.messageID !== ctx.params.messageID ||
404
- payload.sessionID !== ctx.params.sessionID
405
- ) {
406
- return yield* new HttpApiError.BadRequest({})
407
- }
408
- return yield* session.updatePart(payload)
409
- })
410
-
411
- return handlers
412
- .handle("list", list)
413
- .handle("status", status)
414
- .handle("get", get)
415
- .handle("children", children)
416
- .handle("todo", todo)
417
- .handle("diff", diff)
418
- .handle("messages", messages)
419
- .handle("message", message)
420
- .handleRaw("create", createRaw)
421
- .handle("remove", remove)
422
- .handle("update", update)
423
- .handleRaw("fork", forkRaw)
424
- .handle("abort", abort)
425
- .handle("init", init)
426
- .handle("share", share)
427
- .handle("unshare", unshare)
428
- .handle("summarize", summarize)
429
- .handle("prompt", prompt)
430
- .handle("promptAsync", promptAsync)
431
- .handle("command", command)
432
- .handle("shell", shell)
433
- .handle("revert", revert)
434
- .handle("unrevert", unrevert)
435
- .handle("permissionRespond", permissionRespond)
436
- .handle("deleteMessage", deleteMessage)
437
- .handle("deletePart", deletePart)
438
- .handle("updatePart", updatePart)
439
- }),
440
- )
@@ -1,89 +0,0 @@
1
- import { Workspace } from "@/control-plane/workspace"
2
- import * as InstanceState from "@/effect/instance-state"
3
- import { Session } from "@/session/session"
4
- import { Database } from "@opencode-ai/core/database/database"
5
- import { EventV2 } from "@opencode-ai/core/event"
6
- import { EventV2Bridge } from "@/event-v2-bridge"
7
- import { EventTable } from "@opencode-ai/core/event/sql"
8
- import { asc } from "drizzle-orm"
9
- import { and } from "drizzle-orm"
10
- import { eq } from "drizzle-orm"
11
- import { lte } from "drizzle-orm"
12
- import { not } from "drizzle-orm"
13
- import { or } from "drizzle-orm"
14
- import { Effect, Scope } from "effect"
15
- import { HttpApiBuilder, HttpApiError } from "effect/unstable/httpapi"
16
- import { InstanceHttpApi } from "../api"
17
- import { HistoryPayload, ReplayPayload, SessionPayload } from "../groups/sync"
18
-
19
- export const syncHandlers = HttpApiBuilder.group(InstanceHttpApi, "sync", (handlers) =>
20
- Effect.gen(function* () {
21
- const workspace = yield* Workspace.Service
22
- const session = yield* Session.Service
23
- const scope = yield* Scope.Scope
24
- const events = yield* EventV2Bridge.Service
25
- const { db } = yield* Database.Service
26
-
27
- const start = Effect.fn("SyncHttpApi.start")(function* () {
28
- yield* workspace
29
- .startWorkspaceSyncing((yield* InstanceState.context).project.id)
30
- .pipe(Effect.ignore, Effect.forkIn(scope))
31
- return true
32
- })
33
-
34
- const replay = Effect.fn("SyncHttpApi.replay")(function* (ctx: { payload: typeof ReplayPayload.Type }) {
35
- const payload: EventV2.SerializedEvent[] = ctx.payload.events.map((event) => ({
36
- id: event.id,
37
- aggregateID: event.aggregateID,
38
- seq: event.seq,
39
- type: event.type,
40
- data: { ...event.data },
41
- }))
42
- const source = payload[0].aggregateID
43
- yield* Effect.logInfo("sync replay requested", {
44
- sessionID: source,
45
- events: payload.length,
46
- first: payload[0]?.seq,
47
- last: payload.at(-1)?.seq,
48
- directory: ctx.payload.directory,
49
- })
50
- const ownerID = yield* InstanceState.workspaceID
51
- yield* events.replayAll(payload, { ownerID, strictOwner: true })
52
- yield* Effect.logInfo("sync replay complete", {
53
- sessionID: source,
54
- events: payload.length,
55
- first: payload[0]?.seq,
56
- last: payload.at(-1)?.seq,
57
- })
58
- return { sessionID: source }
59
- })
60
-
61
- const steal = Effect.fn("SyncHttpApi.steal")(function* (ctx: { payload: typeof SessionPayload.Type }) {
62
- const workspaceID = yield* InstanceState.workspaceID
63
- if (!workspaceID) return yield* new HttpApiError.BadRequest({})
64
-
65
- yield* session.setWorkspace({ sessionID: ctx.payload.sessionID, workspaceID })
66
-
67
- yield* Effect.logInfo("sync session stolen", { sessionID: ctx.payload.sessionID, workspaceID })
68
-
69
- return { sessionID: ctx.payload.sessionID }
70
- })
71
-
72
- const history = Effect.fn("SyncHttpApi.history")(function* (ctx: { payload: typeof HistoryPayload.Type }) {
73
- const exclude = Object.entries(ctx.payload)
74
- return yield* db
75
- .select()
76
- .from(EventTable)
77
- .where(
78
- exclude.length > 0
79
- ? not(or(...exclude.map(([id, seq]) => and(eq(EventTable.aggregate_id, id), lte(EventTable.seq, seq))))!)
80
- : undefined,
81
- )
82
- .orderBy(asc(EventTable.seq))
83
- .all()
84
- .pipe(Effect.orDie)
85
- })
86
-
87
- return handlers.handle("start", start).handle("replay", replay).handle("steal", steal).handle("history", history)
88
- }),
89
- )