alchemylab-opencode 1.0.7 → 1.0.9

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 (391) hide show
  1. package/dist/{chunk-B3FN2B2N.js → chunk-3PZZ2D23.js} +7 -3
  2. package/dist/chunk-3PZZ2D23.js.map +7 -0
  3. package/dist/{chunk-LU5XVQUD.js → chunk-EGZMJTLE.js} +7 -7
  4. package/dist/{chunk-LU5XVQUD.js.map → chunk-EGZMJTLE.js.map} +2 -2
  5. package/dist/{chunk-23UYOGZG.js → chunk-ORHZOVWK.js} +6 -6
  6. package/dist/{chunk-TASPMBUL.js → chunk-SV5NEV33.js} +5 -5
  7. package/dist/{chunk-SM6WZDN6.js → chunk-UKQIL5XA.js} +18 -12
  8. package/dist/chunk-UKQIL5XA.js.map +7 -0
  9. package/dist/{chunk-GSE2T5UY.js → chunk-ZFHDPNFZ.js} +4 -4
  10. package/dist/{mcp-XFGN3FWW.js → mcp-66BBNSWA.js} +3 -3
  11. package/dist/{registry-W4MBVBYD.js → registry-YVL3V6Z6.js} +4 -4
  12. package/dist/{run-73HUV4H3.js → run-65PIGE2A.js} +7 -7
  13. package/dist/{run-service-LHEVFBIU.js → run-service-AYATGPA6.js} +2 -2
  14. package/dist/run.js +1 -1
  15. package/dist/serve.js +1 -1
  16. package/dist/{server-2CPOG3LS.js → server-KCG3B4WQ.js} +7 -7
  17. package/dist/{session-M6HOZ56B.js → session-BR5MTI3X.js} +4 -4
  18. package/dist/{share-next-QRBVSD37.js → share-next-EPYQDJ32.js} +5 -5
  19. package/dist/{worktree-3GUHT2P7.js → worktree-PIVTZBUE.js} +6 -6
  20. package/package.json +2 -15
  21. package/packages/opencode/migration/20260409000000_add_session_metadata/migration.sql +1 -0
  22. package/build.mjs +0 -192
  23. package/dist/chunk-B3FN2B2N.js.map +0 -7
  24. package/dist/chunk-SM6WZDN6.js.map +0 -7
  25. package/packages/opencode/package.json +0 -138
  26. package/packages/opencode/src/account/account.sql.ts +0 -39
  27. package/packages/opencode/src/account/index.ts +0 -463
  28. package/packages/opencode/src/account/repo.ts +0 -163
  29. package/packages/opencode/src/account/schema.ts +0 -91
  30. package/packages/opencode/src/acp/README.md +0 -174
  31. package/packages/opencode/src/acp/agent.ts +0 -1847
  32. package/packages/opencode/src/acp/session.ts +0 -116
  33. package/packages/opencode/src/acp/types.ts +0 -24
  34. package/packages/opencode/src/agent/agent.ts +0 -420
  35. package/packages/opencode/src/agent/generate.txt +0 -75
  36. package/packages/opencode/src/agent/prompt/compaction.txt +0 -15
  37. package/packages/opencode/src/agent/prompt/explore.txt +0 -18
  38. package/packages/opencode/src/agent/prompt/summary.txt +0 -11
  39. package/packages/opencode/src/agent/prompt/title.txt +0 -44
  40. package/packages/opencode/src/auth/index.ts +0 -110
  41. package/packages/opencode/src/bus/bus-event.ts +0 -40
  42. package/packages/opencode/src/bus/global.ts +0 -10
  43. package/packages/opencode/src/bus/index.ts +0 -185
  44. package/packages/opencode/src/cli/bootstrap.ts +0 -17
  45. package/packages/opencode/src/cli/cmd/cmd.ts +0 -7
  46. package/packages/opencode/src/cli/cmd/run.ts +0 -689
  47. package/packages/opencode/src/cli/cmd/serve.ts +0 -24
  48. package/packages/opencode/src/cli/cmd/tui/event.ts +0 -49
  49. package/packages/opencode/src/cli/effect/prompt.ts +0 -25
  50. package/packages/opencode/src/cli/error.ts +0 -46
  51. package/packages/opencode/src/cli/heap.ts +0 -59
  52. package/packages/opencode/src/cli/logo.ts +0 -6
  53. package/packages/opencode/src/cli/network.ts +0 -60
  54. package/packages/opencode/src/cli/ui.ts +0 -133
  55. package/packages/opencode/src/cli/upgrade.ts +0 -31
  56. package/packages/opencode/src/command/index.ts +0 -195
  57. package/packages/opencode/src/command/template/initialize.txt +0 -66
  58. package/packages/opencode/src/command/template/review.txt +0 -101
  59. package/packages/opencode/src/config/config.ts +0 -1599
  60. package/packages/opencode/src/config/console-state.ts +0 -15
  61. package/packages/opencode/src/config/markdown.ts +0 -99
  62. package/packages/opencode/src/config/paths.ts +0 -167
  63. package/packages/opencode/src/config/tui-migrate.ts +0 -155
  64. package/packages/opencode/src/config/tui-schema.ts +0 -37
  65. package/packages/opencode/src/config/tui.ts +0 -179
  66. package/packages/opencode/src/control-plane/adaptors/index.ts +0 -20
  67. package/packages/opencode/src/control-plane/adaptors/worktree.ts +0 -42
  68. package/packages/opencode/src/control-plane/schema.ts +0 -17
  69. package/packages/opencode/src/control-plane/sse.ts +0 -66
  70. package/packages/opencode/src/control-plane/types.ts +0 -32
  71. package/packages/opencode/src/control-plane/workspace.sql.ts +0 -17
  72. package/packages/opencode/src/control-plane/workspace.ts +0 -168
  73. package/packages/opencode/src/effect/cross-spawn-spawner.ts +0 -502
  74. package/packages/opencode/src/effect/instance-ref.ts +0 -6
  75. package/packages/opencode/src/effect/instance-registry.ts +0 -12
  76. package/packages/opencode/src/effect/instance-state.ts +0 -82
  77. package/packages/opencode/src/effect/run-service.ts +0 -33
  78. package/packages/opencode/src/effect/runner.ts +0 -216
  79. package/packages/opencode/src/env/index.ts +0 -28
  80. package/packages/opencode/src/file/ignore.ts +0 -82
  81. package/packages/opencode/src/file/index.ts +0 -686
  82. package/packages/opencode/src/file/protected.ts +0 -59
  83. package/packages/opencode/src/file/ripgrep.ts +0 -376
  84. package/packages/opencode/src/file/time.ts +0 -133
  85. package/packages/opencode/src/file/watcher.ts +0 -173
  86. package/packages/opencode/src/filesystem/index.ts +0 -236
  87. package/packages/opencode/src/flag/flag.ts +0 -156
  88. package/packages/opencode/src/format/formatter.ts +0 -413
  89. package/packages/opencode/src/format/index.ts +0 -203
  90. package/packages/opencode/src/git/index.ts +0 -303
  91. package/packages/opencode/src/global/index.ts +0 -56
  92. package/packages/opencode/src/id/id.ts +0 -85
  93. package/packages/opencode/src/ide/index.ts +0 -74
  94. package/packages/opencode/src/installation/index.ts +0 -355
  95. package/packages/opencode/src/installation/meta.ts +0 -7
  96. package/packages/opencode/src/lsp/client.ts +0 -252
  97. package/packages/opencode/src/lsp/index.ts +0 -558
  98. package/packages/opencode/src/lsp/language.ts +0 -120
  99. package/packages/opencode/src/lsp/launch.ts +0 -21
  100. package/packages/opencode/src/lsp/server.ts +0 -1968
  101. package/packages/opencode/src/mcp/auth.ts +0 -173
  102. package/packages/opencode/src/mcp/index.ts +0 -931
  103. package/packages/opencode/src/mcp/oauth-callback.ts +0 -216
  104. package/packages/opencode/src/mcp/oauth-provider.ts +0 -185
  105. package/packages/opencode/src/node-loader.mjs +0 -104
  106. package/packages/opencode/src/node-preload.mjs +0 -39
  107. package/packages/opencode/src/node.ts +0 -1
  108. package/packages/opencode/src/npm/index.ts +0 -188
  109. package/packages/opencode/src/patch/index.ts +0 -680
  110. package/packages/opencode/src/permission/arity.ts +0 -163
  111. package/packages/opencode/src/permission/evaluate.ts +0 -15
  112. package/packages/opencode/src/permission/index.ts +0 -325
  113. package/packages/opencode/src/permission/schema.ts +0 -17
  114. package/packages/opencode/src/plugin/cloudflare.ts +0 -67
  115. package/packages/opencode/src/plugin/codex.ts +0 -608
  116. package/packages/opencode/src/plugin/github-copilot/copilot.ts +0 -361
  117. package/packages/opencode/src/plugin/github-copilot/models.ts +0 -144
  118. package/packages/opencode/src/plugin/index.ts +0 -299
  119. package/packages/opencode/src/plugin/install.ts +0 -439
  120. package/packages/opencode/src/plugin/loader.ts +0 -174
  121. package/packages/opencode/src/plugin/meta.ts +0 -188
  122. package/packages/opencode/src/plugin/shared.ts +0 -323
  123. package/packages/opencode/src/project/bootstrap.ts +0 -31
  124. package/packages/opencode/src/project/instance.ts +0 -175
  125. package/packages/opencode/src/project/project.sql.ts +0 -16
  126. package/packages/opencode/src/project/project.ts +0 -519
  127. package/packages/opencode/src/project/schema.ts +0 -16
  128. package/packages/opencode/src/project/state.ts +0 -70
  129. package/packages/opencode/src/project/vcs.ts +0 -240
  130. package/packages/opencode/src/provider/auth.ts +0 -253
  131. package/packages/opencode/src/provider/error.ts +0 -197
  132. package/packages/opencode/src/provider/models.ts +0 -162
  133. package/packages/opencode/src/provider/provider.ts +0 -1709
  134. package/packages/opencode/src/provider/schema.ts +0 -38
  135. package/packages/opencode/src/provider/sdk/copilot/README.md +0 -5
  136. package/packages/opencode/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -170
  137. package/packages/opencode/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
  138. package/packages/opencode/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -19
  139. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
  140. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -815
  141. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
  142. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
  143. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -83
  144. package/packages/opencode/src/provider/sdk/copilot/copilot-provider.ts +0 -100
  145. package/packages/opencode/src/provider/sdk/copilot/index.ts +0 -2
  146. package/packages/opencode/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
  147. package/packages/opencode/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -335
  148. package/packages/opencode/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
  149. package/packages/opencode/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
  150. package/packages/opencode/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
  151. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -214
  152. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1769
  153. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -173
  154. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
  155. package/packages/opencode/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -87
  156. package/packages/opencode/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -127
  157. package/packages/opencode/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -114
  158. package/packages/opencode/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -64
  159. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -103
  160. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -102
  161. package/packages/opencode/src/provider/transform.ts +0 -1050
  162. package/packages/opencode/src/pty/index.ts +0 -397
  163. package/packages/opencode/src/pty/pty.node.ts +0 -27
  164. package/packages/opencode/src/pty/pty.ts +0 -25
  165. package/packages/opencode/src/pty/schema.ts +0 -17
  166. package/packages/opencode/src/question/index.ts +0 -224
  167. package/packages/opencode/src/question/schema.ts +0 -17
  168. package/packages/opencode/src/run.ts +0 -28
  169. package/packages/opencode/src/serve.ts +0 -45
  170. package/packages/opencode/src/server/error.ts +0 -36
  171. package/packages/opencode/src/server/event.ts +0 -7
  172. package/packages/opencode/src/server/instance.ts +0 -324
  173. package/packages/opencode/src/server/mdns.ts +0 -60
  174. package/packages/opencode/src/server/middleware.ts +0 -33
  175. package/packages/opencode/src/server/projectors.ts +0 -28
  176. package/packages/opencode/src/server/proxy.ts +0 -131
  177. package/packages/opencode/src/server/router.ts +0 -105
  178. package/packages/opencode/src/server/routes/config.ts +0 -92
  179. package/packages/opencode/src/server/routes/event.ts +0 -83
  180. package/packages/opencode/src/server/routes/experimental.ts +0 -374
  181. package/packages/opencode/src/server/routes/file.ts +0 -197
  182. package/packages/opencode/src/server/routes/global.ts +0 -312
  183. package/packages/opencode/src/server/routes/mcp.ts +0 -225
  184. package/packages/opencode/src/server/routes/permission.ts +0 -69
  185. package/packages/opencode/src/server/routes/project.ts +0 -118
  186. package/packages/opencode/src/server/routes/provider.ts +0 -171
  187. package/packages/opencode/src/server/routes/pty.ts +0 -210
  188. package/packages/opencode/src/server/routes/question.ts +0 -99
  189. package/packages/opencode/src/server/routes/session.ts +0 -1030
  190. package/packages/opencode/src/server/routes/tui.ts +0 -379
  191. package/packages/opencode/src/server/routes/workspace.ts +0 -94
  192. package/packages/opencode/src/server/server.ts +0 -353
  193. package/packages/opencode/src/session/compaction.ts +0 -428
  194. package/packages/opencode/src/session/index.ts +0 -887
  195. package/packages/opencode/src/session/instruction.ts +0 -258
  196. package/packages/opencode/src/session/llm.ts +0 -354
  197. package/packages/opencode/src/session/message-v2.ts +0 -1031
  198. package/packages/opencode/src/session/message.ts +0 -191
  199. package/packages/opencode/src/session/overflow.ts +0 -22
  200. package/packages/opencode/src/session/processor.ts +0 -523
  201. package/packages/opencode/src/session/projectors.ts +0 -135
  202. package/packages/opencode/src/session/prompt/anthropic.txt +0 -105
  203. package/packages/opencode/src/session/prompt/beast.txt +0 -147
  204. package/packages/opencode/src/session/prompt/build-switch.txt +0 -5
  205. package/packages/opencode/src/session/prompt/codex.txt +0 -79
  206. package/packages/opencode/src/session/prompt/copilot-gpt-5.txt +0 -143
  207. package/packages/opencode/src/session/prompt/default.txt +0 -105
  208. package/packages/opencode/src/session/prompt/gemini.txt +0 -155
  209. package/packages/opencode/src/session/prompt/gpt.txt +0 -107
  210. package/packages/opencode/src/session/prompt/kimi.txt +0 -95
  211. package/packages/opencode/src/session/prompt/max-steps.txt +0 -16
  212. package/packages/opencode/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  213. package/packages/opencode/src/session/prompt/plan.txt +0 -26
  214. package/packages/opencode/src/session/prompt/trinity.txt +0 -97
  215. package/packages/opencode/src/session/prompt.ts +0 -1911
  216. package/packages/opencode/src/session/retry.ts +0 -106
  217. package/packages/opencode/src/session/revert.ts +0 -176
  218. package/packages/opencode/src/session/schema.ts +0 -38
  219. package/packages/opencode/src/session/session.sql.ts +0 -103
  220. package/packages/opencode/src/session/status.ts +0 -102
  221. package/packages/opencode/src/session/summary.ts +0 -177
  222. package/packages/opencode/src/session/system.ts +0 -76
  223. package/packages/opencode/src/session/todo.ts +0 -95
  224. package/packages/opencode/src/share/share-next.ts +0 -369
  225. package/packages/opencode/src/share/share.sql.ts +0 -13
  226. package/packages/opencode/src/shell/shell.ts +0 -110
  227. package/packages/opencode/src/skill/discovery.ts +0 -116
  228. package/packages/opencode/src/skill/index.ts +0 -277
  229. package/packages/opencode/src/snapshot/index.ts +0 -726
  230. package/packages/opencode/src/sql.d.ts +0 -4
  231. package/packages/opencode/src/storage/db.node.ts +0 -8
  232. package/packages/opencode/src/storage/db.ts +0 -177
  233. package/packages/opencode/src/storage/json-migration.ts +0 -425
  234. package/packages/opencode/src/storage/schema.sql.ts +0 -10
  235. package/packages/opencode/src/storage/schema.ts +0 -5
  236. package/packages/opencode/src/storage/storage.ts +0 -353
  237. package/packages/opencode/src/sync/README.md +0 -179
  238. package/packages/opencode/src/sync/event.sql.ts +0 -16
  239. package/packages/opencode/src/sync/index.ts +0 -263
  240. package/packages/opencode/src/sync/schema.ts +0 -14
  241. package/packages/opencode/src/tool/apply_patch.ts +0 -281
  242. package/packages/opencode/src/tool/apply_patch.txt +0 -33
  243. package/packages/opencode/src/tool/bash.ts +0 -496
  244. package/packages/opencode/src/tool/bash.txt +0 -117
  245. package/packages/opencode/src/tool/batch.ts +0 -183
  246. package/packages/opencode/src/tool/batch.txt +0 -24
  247. package/packages/opencode/src/tool/codesearch.ts +0 -132
  248. package/packages/opencode/src/tool/codesearch.txt +0 -12
  249. package/packages/opencode/src/tool/edit.ts +0 -667
  250. package/packages/opencode/src/tool/edit.txt +0 -10
  251. package/packages/opencode/src/tool/external-directory.ts +0 -46
  252. package/packages/opencode/src/tool/glob.ts +0 -78
  253. package/packages/opencode/src/tool/glob.txt +0 -6
  254. package/packages/opencode/src/tool/grep.ts +0 -156
  255. package/packages/opencode/src/tool/grep.txt +0 -8
  256. package/packages/opencode/src/tool/invalid.ts +0 -17
  257. package/packages/opencode/src/tool/ls.ts +0 -121
  258. package/packages/opencode/src/tool/ls.txt +0 -1
  259. package/packages/opencode/src/tool/lsp.ts +0 -97
  260. package/packages/opencode/src/tool/lsp.txt +0 -19
  261. package/packages/opencode/src/tool/multiedit.ts +0 -46
  262. package/packages/opencode/src/tool/multiedit.txt +0 -41
  263. package/packages/opencode/src/tool/plan-enter.txt +0 -14
  264. package/packages/opencode/src/tool/plan-exit.txt +0 -13
  265. package/packages/opencode/src/tool/plan.ts +0 -131
  266. package/packages/opencode/src/tool/question.ts +0 -46
  267. package/packages/opencode/src/tool/question.txt +0 -10
  268. package/packages/opencode/src/tool/read.ts +0 -332
  269. package/packages/opencode/src/tool/read.txt +0 -14
  270. package/packages/opencode/src/tool/registry.ts +0 -265
  271. package/packages/opencode/src/tool/schema.ts +0 -17
  272. package/packages/opencode/src/tool/skill.ts +0 -105
  273. package/packages/opencode/src/tool/task.ts +0 -166
  274. package/packages/opencode/src/tool/task.txt +0 -60
  275. package/packages/opencode/src/tool/todo.ts +0 -48
  276. package/packages/opencode/src/tool/todowrite.txt +0 -167
  277. package/packages/opencode/src/tool/tool.ts +0 -112
  278. package/packages/opencode/src/tool/truncate.ts +0 -144
  279. package/packages/opencode/src/tool/truncation-dir.ts +0 -4
  280. package/packages/opencode/src/tool/webfetch.ts +0 -206
  281. package/packages/opencode/src/tool/webfetch.txt +0 -13
  282. package/packages/opencode/src/tool/websearch.ts +0 -150
  283. package/packages/opencode/src/tool/websearch.txt +0 -14
  284. package/packages/opencode/src/tool/write.ts +0 -84
  285. package/packages/opencode/src/tool/write.txt +0 -8
  286. package/packages/opencode/src/util/abort.ts +0 -35
  287. package/packages/opencode/src/util/archive.ts +0 -17
  288. package/packages/opencode/src/util/color.ts +0 -19
  289. package/packages/opencode/src/util/context.ts +0 -25
  290. package/packages/opencode/src/util/data-url.ts +0 -9
  291. package/packages/opencode/src/util/defer.ts +0 -12
  292. package/packages/opencode/src/util/effect-http-client.ts +0 -11
  293. package/packages/opencode/src/util/effect-zod.ts +0 -98
  294. package/packages/opencode/src/util/error.ts +0 -77
  295. package/packages/opencode/src/util/filesystem.ts +0 -245
  296. package/packages/opencode/src/util/flock.ts +0 -333
  297. package/packages/opencode/src/util/fn.ts +0 -21
  298. package/packages/opencode/src/util/format.ts +0 -20
  299. package/packages/opencode/src/util/glob.ts +0 -34
  300. package/packages/opencode/src/util/hash.ts +0 -7
  301. package/packages/opencode/src/util/iife.ts +0 -3
  302. package/packages/opencode/src/util/keybind.ts +0 -103
  303. package/packages/opencode/src/util/lazy.ts +0 -23
  304. package/packages/opencode/src/util/locale.ts +0 -81
  305. package/packages/opencode/src/util/lock.ts +0 -98
  306. package/packages/opencode/src/util/log.ts +0 -182
  307. package/packages/opencode/src/util/network.ts +0 -9
  308. package/packages/opencode/src/util/process.ts +0 -176
  309. package/packages/opencode/src/util/queue.ts +0 -32
  310. package/packages/opencode/src/util/record.ts +0 -3
  311. package/packages/opencode/src/util/rpc.ts +0 -66
  312. package/packages/opencode/src/util/schema.ts +0 -53
  313. package/packages/opencode/src/util/scrap.ts +0 -10
  314. package/packages/opencode/src/util/signal.ts +0 -12
  315. package/packages/opencode/src/util/timeout.ts +0 -14
  316. package/packages/opencode/src/util/token.ts +0 -7
  317. package/packages/opencode/src/util/update-schema.ts +0 -13
  318. package/packages/opencode/src/util/which.ts +0 -14
  319. package/packages/opencode/src/util/wildcard.ts +0 -59
  320. package/packages/opencode/src/worktree/index.ts +0 -612
  321. package/packages/plugin/package.json +0 -38
  322. package/packages/plugin/src/example.ts +0 -18
  323. package/packages/plugin/src/index.ts +0 -282
  324. package/packages/plugin/src/shell.ts +0 -136
  325. package/packages/plugin/src/tool.ts +0 -38
  326. package/packages/plugin/src/tui.ts +0 -508
  327. package/packages/script/package.json +0 -16
  328. package/packages/script/src/index.ts +0 -77
  329. package/packages/sdk/package.json +0 -33
  330. package/packages/sdk/src/client.ts +0 -55
  331. package/packages/sdk/src/gen/client/client.gen.ts +0 -212
  332. package/packages/sdk/src/gen/client/index.ts +0 -25
  333. package/packages/sdk/src/gen/client/types.gen.ts +0 -222
  334. package/packages/sdk/src/gen/client/utils.gen.ts +0 -287
  335. package/packages/sdk/src/gen/client.gen.ts +0 -22
  336. package/packages/sdk/src/gen/core/auth.gen.ts +0 -41
  337. package/packages/sdk/src/gen/core/bodySerializer.gen.ts +0 -74
  338. package/packages/sdk/src/gen/core/params.gen.ts +0 -144
  339. package/packages/sdk/src/gen/core/pathSerializer.gen.ts +0 -167
  340. package/packages/sdk/src/gen/core/queryKeySerializer.gen.ts +0 -111
  341. package/packages/sdk/src/gen/core/serverSentEvents.gen.ts +0 -210
  342. package/packages/sdk/src/gen/core/types.gen.ts +0 -91
  343. package/packages/sdk/src/gen/core/utils.gen.ts +0 -109
  344. package/packages/sdk/src/gen/sdk.gen.ts +0 -1197
  345. package/packages/sdk/src/gen/types.gen.ts +0 -3904
  346. package/packages/sdk/src/index.ts +0 -21
  347. package/packages/sdk/src/process.ts +0 -31
  348. package/packages/sdk/src/server.ts +0 -134
  349. package/packages/sdk/src/v2/client.ts +0 -81
  350. package/packages/sdk/src/v2/gen/client/client.gen.ts +0 -285
  351. package/packages/sdk/src/v2/gen/client/index.ts +0 -25
  352. package/packages/sdk/src/v2/gen/client/types.gen.ts +0 -202
  353. package/packages/sdk/src/v2/gen/client/utils.gen.ts +0 -289
  354. package/packages/sdk/src/v2/gen/client.gen.ts +0 -18
  355. package/packages/sdk/src/v2/gen/core/auth.gen.ts +0 -41
  356. package/packages/sdk/src/v2/gen/core/bodySerializer.gen.ts +0 -82
  357. package/packages/sdk/src/v2/gen/core/params.gen.ts +0 -169
  358. package/packages/sdk/src/v2/gen/core/pathSerializer.gen.ts +0 -167
  359. package/packages/sdk/src/v2/gen/core/queryKeySerializer.gen.ts +0 -111
  360. package/packages/sdk/src/v2/gen/core/serverSentEvents.gen.ts +0 -239
  361. package/packages/sdk/src/v2/gen/core/types.gen.ts +0 -86
  362. package/packages/sdk/src/v2/gen/core/utils.gen.ts +0 -137
  363. package/packages/sdk/src/v2/gen/sdk.gen.ts +0 -4223
  364. package/packages/sdk/src/v2/gen/types.gen.ts +0 -5265
  365. package/packages/sdk/src/v2/index.ts +0 -21
  366. package/packages/sdk/src/v2/server.ts +0 -134
  367. package/packages/util/package.json +0 -20
  368. package/packages/util/src/array.ts +0 -10
  369. package/packages/util/src/binary.ts +0 -41
  370. package/packages/util/src/encode.ts +0 -51
  371. package/packages/util/src/error.ts +0 -54
  372. package/packages/util/src/fn.ts +0 -11
  373. package/packages/util/src/identifier.ts +0 -48
  374. package/packages/util/src/iife.ts +0 -3
  375. package/packages/util/src/lazy.ts +0 -11
  376. package/packages/util/src/module.ts +0 -10
  377. package/packages/util/src/path.ts +0 -37
  378. package/packages/util/src/retry.ts +0 -41
  379. package/packages/util/src/slug.ts +0 -74
  380. package/postinstall.cjs +0 -55
  381. /package/dist/{chunk-23UYOGZG.js.map → chunk-ORHZOVWK.js.map} +0 -0
  382. /package/dist/{chunk-TASPMBUL.js.map → chunk-SV5NEV33.js.map} +0 -0
  383. /package/dist/{chunk-GSE2T5UY.js.map → chunk-ZFHDPNFZ.js.map} +0 -0
  384. /package/dist/{mcp-XFGN3FWW.js.map → mcp-66BBNSWA.js.map} +0 -0
  385. /package/dist/{registry-W4MBVBYD.js.map → registry-YVL3V6Z6.js.map} +0 -0
  386. /package/dist/{run-73HUV4H3.js.map → run-65PIGE2A.js.map} +0 -0
  387. /package/dist/{run-service-LHEVFBIU.js.map → run-service-AYATGPA6.js.map} +0 -0
  388. /package/dist/{server-2CPOG3LS.js.map → server-KCG3B4WQ.js.map} +0 -0
  389. /package/dist/{session-M6HOZ56B.js.map → session-BR5MTI3X.js.map} +0 -0
  390. /package/dist/{share-next-QRBVSD37.js.map → share-next-EPYQDJ32.js.map} +0 -0
  391. /package/dist/{worktree-3GUHT2P7.js.map → worktree-PIVTZBUE.js.map} +0 -0
@@ -1,353 +0,0 @@
1
- import { Log } from "../util/log"
2
- import path from "path"
3
- import { Global } from "../global"
4
- import { NamedError } from "@opencode-ai/util/error"
5
- import z from "zod"
6
- import { AppFileSystem } from "@/filesystem"
7
- import { makeRuntime } from "@/effect/run-service"
8
- import { Effect, Exit, Layer, Option, RcMap, Schema, ServiceMap, TxReentrantLock } from "effect"
9
- import { Git } from "@/git"
10
-
11
- export namespace Storage {
12
- const log = Log.create({ service: "storage" })
13
-
14
- type Migration = (dir: string, fs: AppFileSystem.Interface) => Effect.Effect<void, AppFileSystem.Error>
15
-
16
- export const NotFoundError = NamedError.create(
17
- "NotFoundError",
18
- z.object({
19
- message: z.string(),
20
- }),
21
- )
22
-
23
- export type Error = AppFileSystem.Error | InstanceType<typeof NotFoundError>
24
-
25
- const RootFile = Schema.Struct({
26
- path: Schema.optional(
27
- Schema.Struct({
28
- root: Schema.optional(Schema.String),
29
- }),
30
- ),
31
- })
32
-
33
- const SessionFile = Schema.Struct({
34
- id: Schema.String,
35
- })
36
-
37
- const MessageFile = Schema.Struct({
38
- id: Schema.String,
39
- })
40
-
41
- const DiffFile = Schema.Struct({
42
- additions: Schema.Number,
43
- deletions: Schema.Number,
44
- })
45
-
46
- const SummaryFile = Schema.Struct({
47
- id: Schema.String,
48
- projectID: Schema.String,
49
- summary: Schema.Struct({ diffs: Schema.Array(DiffFile) }),
50
- })
51
-
52
- const decodeRoot = Schema.decodeUnknownOption(RootFile)
53
- const decodeSession = Schema.decodeUnknownOption(SessionFile)
54
- const decodeMessage = Schema.decodeUnknownOption(MessageFile)
55
- const decodeSummary = Schema.decodeUnknownOption(SummaryFile)
56
-
57
- export interface Interface {
58
- readonly remove: (key: string[]) => Effect.Effect<void, AppFileSystem.Error>
59
- readonly read: <T>(key: string[]) => Effect.Effect<T, Error>
60
- readonly update: <T>(key: string[], fn: (draft: T) => void) => Effect.Effect<T, Error>
61
- readonly write: <T>(key: string[], content: T) => Effect.Effect<void, AppFileSystem.Error>
62
- readonly list: (prefix: string[]) => Effect.Effect<string[][], AppFileSystem.Error>
63
- }
64
-
65
- export class Service extends ServiceMap.Service<Service, Interface>()("@opencode/Storage") {}
66
-
67
- function file(dir: string, key: string[]) {
68
- return path.join(dir, ...key) + ".json"
69
- }
70
-
71
- function missing(err: unknown) {
72
- if (!err || typeof err !== "object") return false
73
- if ("code" in err && err.code === "ENOENT") return true
74
- if ("reason" in err && err.reason && typeof err.reason === "object" && "_tag" in err.reason) {
75
- return err.reason._tag === "NotFound"
76
- }
77
- return false
78
- }
79
-
80
- function parseMigration(text: string) {
81
- const value = Number.parseInt(text, 10)
82
- return Number.isNaN(value) ? 0 : value
83
- }
84
-
85
- const MIGRATIONS: Migration[] = [
86
- Effect.fn("Storage.migration.1")(function* (dir: string, fs: AppFileSystem.Interface) {
87
- const project = path.resolve(dir, "../project")
88
- if (!(yield* fs.isDir(project))) return
89
- const projectDirs = yield* fs.glob("*", {
90
- cwd: project,
91
- include: "all",
92
- })
93
- for (const projectDir of projectDirs) {
94
- const full = path.join(project, projectDir)
95
- if (!(yield* fs.isDir(full))) continue
96
- log.info(`migrating project ${projectDir}`)
97
- let projectID = projectDir
98
- let worktree = "/"
99
-
100
- if (projectID !== "global") {
101
- for (const msgFile of yield* fs.glob("storage/session/message/*/*.json", {
102
- cwd: full,
103
- absolute: true,
104
- })) {
105
- const json = decodeRoot(yield* fs.readJson(msgFile), { onExcessProperty: "preserve" })
106
- const root = Option.isSome(json) ? json.value.path?.root : undefined
107
- if (!root) continue
108
- worktree = root
109
- break
110
- }
111
- if (!worktree) continue
112
- if (!(yield* fs.isDir(worktree))) continue
113
- const result = yield* Effect.promise(() =>
114
- Git.run(["rev-list", "--max-parents=0", "--all"], {
115
- cwd: worktree,
116
- }),
117
- )
118
- const [id] = result
119
- .text()
120
- .split("\n")
121
- .filter(Boolean)
122
- .map((x) => x.trim())
123
- .toSorted()
124
- if (!id) continue
125
- projectID = id
126
-
127
- yield* fs.writeWithDirs(
128
- path.join(dir, "project", projectID + ".json"),
129
- JSON.stringify(
130
- {
131
- id,
132
- vcs: "git",
133
- worktree,
134
- time: {
135
- created: Date.now(),
136
- initialized: Date.now(),
137
- },
138
- },
139
- null,
140
- 2,
141
- ),
142
- )
143
-
144
- log.info(`migrating sessions for project ${projectID}`)
145
- for (const sessionFile of yield* fs.glob("storage/session/info/*.json", {
146
- cwd: full,
147
- absolute: true,
148
- })) {
149
- const dest = path.join(dir, "session", projectID, path.basename(sessionFile))
150
- log.info("copying", { sessionFile, dest })
151
- const session = yield* fs.readJson(sessionFile)
152
- const info = decodeSession(session, { onExcessProperty: "preserve" })
153
- yield* fs.writeWithDirs(dest, JSON.stringify(session, null, 2))
154
- if (Option.isNone(info)) continue
155
- log.info(`migrating messages for session ${info.value.id}`)
156
- for (const msgFile of yield* fs.glob(`storage/session/message/${info.value.id}/*.json`, {
157
- cwd: full,
158
- absolute: true,
159
- })) {
160
- const next = path.join(dir, "message", info.value.id, path.basename(msgFile))
161
- log.info("copying", {
162
- msgFile,
163
- dest: next,
164
- })
165
- const message = yield* fs.readJson(msgFile)
166
- const item = decodeMessage(message, { onExcessProperty: "preserve" })
167
- yield* fs.writeWithDirs(next, JSON.stringify(message, null, 2))
168
- if (Option.isNone(item)) continue
169
-
170
- log.info(`migrating parts for message ${item.value.id}`)
171
- for (const partFile of yield* fs.glob(`storage/session/part/${info.value.id}/${item.value.id}/*.json`, {
172
- cwd: full,
173
- absolute: true,
174
- })) {
175
- const out = path.join(dir, "part", item.value.id, path.basename(partFile))
176
- const part = yield* fs.readJson(partFile)
177
- log.info("copying", {
178
- partFile,
179
- dest: out,
180
- })
181
- yield* fs.writeWithDirs(out, JSON.stringify(part, null, 2))
182
- }
183
- }
184
- }
185
- }
186
- }
187
- }),
188
- Effect.fn("Storage.migration.2")(function* (dir: string, fs: AppFileSystem.Interface) {
189
- for (const item of yield* fs.glob("session/*/*.json", {
190
- cwd: dir,
191
- absolute: true,
192
- })) {
193
- const raw = yield* fs.readJson(item)
194
- const session = decodeSummary(raw, { onExcessProperty: "preserve" })
195
- if (Option.isNone(session)) continue
196
- const diffs = session.value.summary.diffs
197
- yield* fs.writeWithDirs(
198
- path.join(dir, "session_diff", session.value.id + ".json"),
199
- JSON.stringify(diffs, null, 2),
200
- )
201
- yield* fs.writeWithDirs(
202
- path.join(dir, "session", session.value.projectID, session.value.id + ".json"),
203
- JSON.stringify(
204
- {
205
- ...(raw as Record<string, unknown>),
206
- summary: {
207
- additions: diffs.reduce((sum, x) => sum + x.additions, 0),
208
- deletions: diffs.reduce((sum, x) => sum + x.deletions, 0),
209
- },
210
- },
211
- null,
212
- 2,
213
- ),
214
- )
215
- }
216
- }),
217
- ]
218
-
219
- export const layer = Layer.effect(
220
- Service,
221
- Effect.gen(function* () {
222
- const fs = yield* AppFileSystem.Service
223
- const locks = yield* RcMap.make({
224
- lookup: () => TxReentrantLock.make(),
225
- idleTimeToLive: 0,
226
- })
227
- const state = yield* Effect.cached(
228
- Effect.gen(function* () {
229
- const dir = path.join(Global.Path.data, "storage")
230
- const marker = path.join(dir, "migration")
231
- const migration = yield* fs.readFileString(marker).pipe(
232
- Effect.map(parseMigration),
233
- Effect.catchIf(missing, () => Effect.succeed(0)),
234
- Effect.orElseSucceed(() => 0),
235
- )
236
- for (let i = migration; i < MIGRATIONS.length; i++) {
237
- log.info("running migration", { index: i })
238
- const step = MIGRATIONS[i]!
239
- const exit = yield* Effect.exit(step(dir, fs))
240
- if (Exit.isFailure(exit)) {
241
- log.error("failed to run migration", { index: i, cause: exit.cause })
242
- break
243
- }
244
- yield* fs.writeWithDirs(marker, String(i + 1))
245
- }
246
- return { dir }
247
- }),
248
- )
249
-
250
- const fail = (target: string): Effect.Effect<never, InstanceType<typeof NotFoundError>> =>
251
- Effect.fail(new NotFoundError({ message: `Resource not found: ${target}` }))
252
-
253
- const wrap = <A>(target: string, body: Effect.Effect<A, AppFileSystem.Error>) =>
254
- body.pipe(Effect.catchIf(missing, () => fail(target)))
255
-
256
- const writeJson = Effect.fnUntraced(function* (target: string, content: unknown) {
257
- yield* fs.writeWithDirs(target, JSON.stringify(content, null, 2))
258
- })
259
-
260
- const withResolved = <A, E>(
261
- key: string[],
262
- fn: (target: string, rw: TxReentrantLock.TxReentrantLock) => Effect.Effect<A, E>,
263
- ): Effect.Effect<A, E | AppFileSystem.Error> =>
264
- Effect.scoped(
265
- Effect.gen(function* () {
266
- const target = file((yield* state).dir, key)
267
- return yield* fn(target, yield* RcMap.get(locks, target))
268
- }),
269
- )
270
-
271
- const remove: Interface["remove"] = Effect.fn("Storage.remove")(function* (key: string[]) {
272
- yield* withResolved(key, (target, rw) =>
273
- TxReentrantLock.withWriteLock(rw, fs.remove(target).pipe(Effect.catchIf(missing, () => Effect.void))),
274
- )
275
- })
276
-
277
- const read: Interface["read"] = <T>(key: string[]) =>
278
- Effect.gen(function* () {
279
- const value = yield* withResolved(key, (target, rw) =>
280
- TxReentrantLock.withReadLock(rw, wrap(target, fs.readJson(target))),
281
- )
282
- return value as T
283
- })
284
-
285
- const update: Interface["update"] = <T>(key: string[], fn: (draft: T) => void) =>
286
- Effect.gen(function* () {
287
- const value = yield* withResolved(key, (target, rw) =>
288
- TxReentrantLock.withWriteLock(
289
- rw,
290
- Effect.gen(function* () {
291
- const content = yield* wrap(target, fs.readJson(target))
292
- fn(content as T)
293
- yield* writeJson(target, content)
294
- return content
295
- }),
296
- ),
297
- )
298
- return value as T
299
- })
300
-
301
- const write: Interface["write"] = (key: string[], content: unknown) =>
302
- Effect.gen(function* () {
303
- yield* withResolved(key, (target, rw) => TxReentrantLock.withWriteLock(rw, writeJson(target, content)))
304
- })
305
-
306
- const list: Interface["list"] = Effect.fn("Storage.list")(function* (prefix: string[]) {
307
- const dir = (yield* state).dir
308
- const cwd = path.join(dir, ...prefix)
309
- const result = yield* fs
310
- .glob("**/*", {
311
- cwd,
312
- include: "file",
313
- })
314
- .pipe(Effect.catch(() => Effect.succeed<string[]>([])))
315
- return result
316
- .map((x) => [...prefix, ...x.slice(0, -5).split(path.sep)])
317
- .toSorted((a, b) => a.join("/").localeCompare(b.join("/")))
318
- })
319
-
320
- return Service.of({
321
- remove,
322
- read,
323
- update,
324
- write,
325
- list,
326
- })
327
- }),
328
- )
329
-
330
- export const defaultLayer = layer.pipe(Layer.provide(AppFileSystem.defaultLayer))
331
-
332
- const { runPromise } = makeRuntime(Service, defaultLayer)
333
-
334
- export async function remove(key: string[]) {
335
- return runPromise((svc) => svc.remove(key))
336
- }
337
-
338
- export async function read<T>(key: string[]) {
339
- return runPromise((svc) => svc.read<T>(key))
340
- }
341
-
342
- export async function update<T>(key: string[], fn: (draft: T) => void) {
343
- return runPromise((svc) => svc.update<T>(key, fn))
344
- }
345
-
346
- export async function write<T>(key: string[], content: T) {
347
- return runPromise((svc) => svc.write(key, content))
348
- }
349
-
350
- export async function list(prefix: string[]) {
351
- return runPromise((svc) => svc.list(prefix))
352
- }
353
- }
@@ -1,179 +0,0 @@
1
- tl;dr All of these APIs work, are properly type-checked, and are sync events are backwards compatible with `Bus`:
2
-
3
- ```ts
4
- // The schema from `Updated` typechecks the object correctly
5
- SyncEvent.run(Updated, { sessionID: id, info: { title: "foo" } })
6
-
7
- // `subscribeAll` passes a generic sync event
8
- SyncEvent.subscribeAll((event) => {
9
- // These will be type-checked correctly
10
- event.id
11
- event.seq
12
- // This will be unknown because we are listening for all events,
13
- // and this API is only used to record them
14
- event.data
15
- })
16
-
17
- // This works, but you shouldn't publish sync event like this (should fail in the future)
18
- Bus.publish(Updated, { sessionID: id, info: { title: "foo" } })
19
-
20
- // Update event is fully type-checked
21
- Bus.subscribe(Updated, (event) => event.properties.info.title)
22
-
23
- // Update event is fully type-checked
24
- client.subscribe("session.updated", (evt) => evt.properties.info.title)
25
- ```
26
-
27
- # Goal
28
-
29
- ## Syncing with only one writer
30
-
31
- This system defines a basic event sourcing system for session replayability. The goal is to allow for one device to control and modify the session, and allow multiple other devices to "sync" session data. The sync works by getting a log of events to replay and replaying them locally.
32
-
33
- Because only one device is allowed to write, we don't need any kind of sophisticated distributed system clocks or causal ordering. We implement total ordering with a simple sequence id (a number) and increment it by one every time we generate an event.
34
-
35
- ## Bus event integration and backwards compatibility
36
-
37
- This initial implementation aims to be fully backwards compatible. We should be able to land this without any visible changes to the user.
38
-
39
- An existing `Bus` abstraction to send events already exists. We already send events like `session.created` through the system. We should not duplicate this.
40
-
41
- The difference in event sourcing is events are sent _before_ the mutation happens, and "projectors" handle the effects and perform the mutations. This difference is subtle, and a necessary change for syncing to work.
42
-
43
- So the goal is:
44
-
45
- - Introduce a new syncing abstraction to handle event sourcing and projectors
46
- - Seamlessly integrate these new events into the same existing `Bus` abstraction
47
- - Maintain full backwards compatibility to reduce risk
48
-
49
- ## My approach
50
-
51
- This directory introduces a new abstraction: `SyncEvent`. This handles all of the event sourcing.
52
-
53
- There are now "sync events" which are different than "bus events". Bus events are defined like this:
54
-
55
- ```ts
56
- const Diff = BusEvent.define(
57
- "session.diff",
58
- z.object({
59
- sessionID: SessionID.zod,
60
- diff: Snapshot.FileDiff.array(),
61
- }),
62
- )
63
- ```
64
-
65
- You can do `Bus.publish(Diff, { ... })` to push these events, and `Bus.subscribe(Diff, handler)` to listen to them.
66
-
67
- Sync events are a lower-level abstraction which are similar, but also handle the requirements for recording and replaying. Defining them looks like this:
68
-
69
- ```ts
70
- const Created = SyncEvent.define({
71
- type: "session.created",
72
- version: 1,
73
- aggregate: "sessionID",
74
- schema: z.object({
75
- sessionID: SessionID.zod,
76
- info: Info,
77
- }),
78
- })
79
- ```
80
-
81
- Not too different, except they track a version and an "aggregate" field (will explain that later).
82
-
83
- You do this to run an event, which is kind of like `Bus.publish` except that it runs through the event sourcing system:
84
-
85
- ```
86
- SyncEvent.run(Created, { ... })
87
- ```
88
-
89
- The data passed as the second argument is properly type-checked based on the schema defined in `Created`.
90
-
91
- Importantly, **sync events automatically re-publish as bus events**. This makes them backwards compatible, and allows the `Bus` to still be the single abstraction that the system uses to listen for individual events.
92
-
93
- **We have upgraded many of the session events to be sync events** (all of the ones that mutate the db). Sync and bus events are largely compatible. Here are the differences:
94
-
95
- ### Event shape
96
-
97
- - The shape of the events are slightly different. A sync event has the `type`, `id`, `seq`, `aggregateID`, and `data` fields. A bus event has the `type` and `properties` fields. `data` and `properties` are largely the same thing. This conversion is automatically handled when the sync system re-published the event throught the bus.
98
-
99
- The reason for this is because sync events need to track more information. I chose not to copy the `properties` naming to more clearly disambiguate the event types.
100
-
101
- ### Event flow
102
-
103
- There is no way to subscribe to individual sync events in `SyncEvent`. You can use `subscribeAll` to receive _all_ of the events, which is needed for clients that want to record them.
104
-
105
- To listen for individual events, use `Bus.subscribe`. You can pass in a sync event definition to it: `Bus.subscribe(Created, handler)`. This is fully supported.
106
-
107
- You should never "publish" a sync event however: `Bus.publish(Created, ...)`. I would like to force this to be a type error in the future. You should never be touching the db directly, and should not be manually handling these events.
108
-
109
- ### Backwards compatibility
110
-
111
- The system install projectors in `server/projectors.js`. It calls `SyncEvent.init` to do this. It also installs a hook for dynamically converting an event at runtime (`convertEvent`).
112
-
113
- This allows you to "reshape" an event from the sync system before it's published to the bus. This should be avoided, but might be necessary for temporary backwards compat.
114
-
115
- The only time we use this is the `session.updated` event. Previously this event contained the entire session object. The sync even only contains the fields updated. We convert the event to contain to full object for backwards compatibility (but ideally we'd remove this).
116
-
117
- It's very important that types are correct when working with events. Event definitions have a `schema` which carries the defintiion of the event shape (provided by a zod schema, inferred into a TypeScript type). Examples:
118
-
119
- ```ts
120
- // The schema from `Updated` typechecks the object correctly
121
- SyncEvent.run(Updated, { sessionID: id, info: { title: "foo" } })
122
-
123
- // `subscribeAll` passes a generic sync event
124
- SyncEvent.subscribeAll((event) => {
125
- // These will be type-checked correctly
126
- event.id
127
- event.seq
128
- // This will be unknown because we are listening for all events,
129
- // and this API is only used to record them
130
- event.data
131
- })
132
-
133
- // This works, but you shouldn't publish sync event like this (should fail in the future)
134
- Bus.publish(Updated, { sessionID: id, info: { title: "foo" } })
135
-
136
- // Update event is fully type-checked
137
- Bus.subscribe(Updated, (event) => event.properties.info.title)
138
-
139
- // Update event is fully type-checked
140
- client.subscribe("session.updated", (evt) => evt.properties.info.title)
141
- ```
142
-
143
- The last two examples look similar to `SyncEvent.run`, but they were the cause of a lot of grief. Those are existing APIs that we can't break, but we are passing in the new sync event definitions to these APIs, which sometimes have a different event shape.
144
-
145
- I previously mentioned the runtime conversion of events, but we still need to the types to work! To do that, the `define` API supports an optional `busSchema` prop to give it the schema for backwards compatibility. For example this is the full definition of `Session.Update`:
146
-
147
- ```ts
148
- const Update = SyncEvent.define({
149
- type: "session.updated",
150
- version: 1,
151
- aggregate: "sessionID",
152
- schema: z.object({
153
- sessionID: SessionID.zod,
154
- info: partialSchema(Info),
155
- }),
156
- busSchema: z.object({
157
- sessionID: SessionID.zod,
158
- info: Info,
159
- }),
160
- })
161
- ```
162
-
163
- _Important_: the conversion done in `convertEvent` is not automatically type-checked with `busSchema`. It's very important they match, but because we need this at type-checking time this needs to live here.
164
-
165
- Internally, the way this works is `busSchema` is stored on a `properties` field which is what the bus system expects. Doing this made everything with `Bus` "just work". This is why you can pass a sync event to the bus APIs.
166
-
167
- _Alternatives_
168
-
169
- These are some other paths I explored:
170
-
171
- - Providing a way to subscribe to individual sync events, and change all the instances of `Bus.subscribe` in our code to it. Then you are directly only working with sync events always.
172
- - Two big problems. First, `Bus` is instance-scoped, and we'd need to make the sync event system instance-scoped too for backwards compat. If we didn't, those listeners would get calls for events they weren't expecting.
173
- - Second, we can't change consumers of our SDK. So they still have to use the old events, and we might as well stick with them for consistency
174
- - Directly add sync event support to bus system
175
- - I explored adding sync events to the bus, but due to backwards compat, it only made it more complicated (still need to support both shapes)
176
- - I explored a `convertSchema` function to convert the event schema at runtime so we didn't need `busSchema`
177
- - Fatal flaw: we need type-checking done earlier. We can't do this at run-time. This worked for consumers of our SDK (because it gets generated TS types from the converted schema) but breaks for our internal usage of `Bus.subscribe` calls
178
-
179
- I explored many other permutations of the above solutions. What we have today I think is the best balance of backwards compatibility while opening a path forward for the new events.
@@ -1,16 +0,0 @@
1
- import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"
2
-
3
- export const EventSequenceTable = sqliteTable("event_sequence", {
4
- aggregate_id: text().notNull().primaryKey(),
5
- seq: integer().notNull(),
6
- })
7
-
8
- export const EventTable = sqliteTable("event", {
9
- id: text().primaryKey(),
10
- aggregate_id: text()
11
- .notNull()
12
- .references(() => EventSequenceTable.aggregate_id, { onDelete: "cascade" }),
13
- seq: integer().notNull(),
14
- type: text().notNull(),
15
- data: text({ mode: "json" }).$type<Record<string, unknown>>().notNull(),
16
- })