@miaws/miaw 1.18.5 → 1.18.6

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 (751) hide show
  1. package/package.json +1 -154
  2. package/AGENTS.md +0 -131
  3. package/Dockerfile +0 -18
  4. package/README.md +0 -15
  5. package/bunfig.toml +0 -7
  6. package/git +0 -0
  7. package/migration/20260511173437_session-metadata/migration.sql +0 -1
  8. package/migration/20260511173437_session-metadata/snapshot.json +0 -1500
  9. package/parsers-config.ts +0 -1
  10. package/script/bench-search.ts +0 -94
  11. package/script/bench-test-suite.ts +0 -52
  12. package/script/build.ts +0 -243
  13. package/script/generate.ts +0 -14
  14. package/script/httpapi-exercise.ts +0 -1
  15. package/script/postinstall.mjs +0 -189
  16. package/script/profile-test-files.ts +0 -42
  17. package/script/publish.ts +0 -213
  18. package/script/run-workspace-server +0 -106
  19. package/script/schema.ts +0 -77
  20. package/script/time.ts +0 -6
  21. package/script/trace-imports.ts +0 -153
  22. package/specs/effect/error-boundaries-plan.md +0 -235
  23. package/specs/effect/errors.md +0 -207
  24. package/specs/effect/facades.md +0 -218
  25. package/specs/effect/guide.md +0 -247
  26. package/specs/effect/instance-context.md +0 -13
  27. package/specs/effect/loose-ends.md +0 -30
  28. package/specs/effect/migration.md +0 -62
  29. package/specs/effect/routes.md +0 -61
  30. package/specs/effect/schema.md +0 -88
  31. package/specs/effect/server-package.md +0 -58
  32. package/specs/effect/todo.md +0 -241
  33. package/specs/effect/tools.md +0 -88
  34. package/specs/openapi-translation-cleanup.md +0 -204
  35. package/specs/tui-plugins.md +0 -544
  36. package/specs/v2/api.ts +0 -67
  37. package/specs/v2/message-shape.md +0 -136
  38. package/specs/v2/notifications.md +0 -13
  39. package/specs/v2/tui-command-shim.md +0 -67
  40. package/src/account/account.ts +0 -463
  41. package/src/account/repo.ts +0 -173
  42. package/src/account/schema.ts +0 -99
  43. package/src/account/url.ts +0 -8
  44. package/src/acp/agent.ts +0 -95
  45. package/src/acp/config-option.ts +0 -203
  46. package/src/acp/content.ts +0 -250
  47. package/src/acp/directory.ts +0 -210
  48. package/src/acp/error.ts +0 -90
  49. package/src/acp/event.ts +0 -336
  50. package/src/acp/permission.ts +0 -124
  51. package/src/acp/profile.ts +0 -42
  52. package/src/acp/service.ts +0 -1048
  53. package/src/acp/session.ts +0 -231
  54. package/src/acp/tool.ts +0 -321
  55. package/src/acp/usage.ts +0 -232
  56. package/src/agent/agent.ts +0 -467
  57. package/src/agent/generate.txt +0 -75
  58. package/src/agent/prompt/compaction.txt +0 -9
  59. package/src/agent/prompt/explore.txt +0 -18
  60. package/src/agent/prompt/summary.txt +0 -11
  61. package/src/agent/prompt/title.txt +0 -44
  62. package/src/agent/subagent-permissions.ts +0 -27
  63. package/src/audio.d.ts +0 -14
  64. package/src/auth/index.ts +0 -99
  65. package/src/background/job.ts +0 -39
  66. package/src/bus/global.ts +0 -22
  67. package/src/cli/bootstrap.ts +0 -11
  68. package/src/cli/cmd/account.ts +0 -264
  69. package/src/cli/cmd/acp.ts +0 -73
  70. package/src/cli/cmd/agent.ts +0 -253
  71. package/src/cli/cmd/attach.ts +0 -97
  72. package/src/cli/cmd/cmd.ts +0 -7
  73. package/src/cli/cmd/db.ts +0 -62
  74. package/src/cli/cmd/debug/agent.handler.ts +0 -193
  75. package/src/cli/cmd/debug/agent.ts +0 -27
  76. package/src/cli/cmd/debug/config.ts +0 -14
  77. package/src/cli/cmd/debug/file.ts +0 -73
  78. package/src/cli/cmd/debug/index.ts +0 -87
  79. package/src/cli/cmd/debug/lsp.ts +0 -50
  80. package/src/cli/cmd/debug/ripgrep.ts +0 -79
  81. package/src/cli/cmd/debug/scrap.ts +0 -15
  82. package/src/cli/cmd/debug/skill.ts +0 -15
  83. package/src/cli/cmd/debug/snapshot.ts +0 -50
  84. package/src/cli/cmd/debug/startup.ts +0 -11
  85. package/src/cli/cmd/debug/v2.ts +0 -49
  86. package/src/cli/cmd/export.ts +0 -292
  87. package/src/cli/cmd/generate.ts +0 -54
  88. package/src/cli/cmd/github.handler.ts +0 -1593
  89. package/src/cli/cmd/github.shared.ts +0 -30
  90. package/src/cli/cmd/github.ts +0 -42
  91. package/src/cli/cmd/import.ts +0 -224
  92. package/src/cli/cmd/mcp.ts +0 -849
  93. package/src/cli/cmd/models.ts +0 -66
  94. package/src/cli/cmd/plug.ts +0 -230
  95. package/src/cli/cmd/pr.ts +0 -115
  96. package/src/cli/cmd/prompt-display.ts +0 -1
  97. package/src/cli/cmd/providers.ts +0 -534
  98. package/src/cli/cmd/run/demo.ts +0 -1274
  99. package/src/cli/cmd/run/entry.body.ts +0 -205
  100. package/src/cli/cmd/run/footer.command.tsx +0 -1064
  101. package/src/cli/cmd/run/footer.menu.tsx +0 -351
  102. package/src/cli/cmd/run/footer.permission.tsx +0 -472
  103. package/src/cli/cmd/run/footer.prompt.tsx +0 -1306
  104. package/src/cli/cmd/run/footer.question.tsx +0 -573
  105. package/src/cli/cmd/run/footer.subagent.tsx +0 -173
  106. package/src/cli/cmd/run/footer.ts +0 -1129
  107. package/src/cli/cmd/run/footer.view.tsx +0 -943
  108. package/src/cli/cmd/run/footer.width.ts +0 -27
  109. package/src/cli/cmd/run/permission.shared.ts +0 -256
  110. package/src/cli/cmd/run/prompt.editor.ts +0 -157
  111. package/src/cli/cmd/run/prompt.shared.ts +0 -153
  112. package/src/cli/cmd/run/question.shared.ts +0 -340
  113. package/src/cli/cmd/run/runtime.boot.ts +0 -202
  114. package/src/cli/cmd/run/runtime.lifecycle.ts +0 -406
  115. package/src/cli/cmd/run/runtime.queue.ts +0 -349
  116. package/src/cli/cmd/run/runtime.shared.ts +0 -17
  117. package/src/cli/cmd/run/runtime.stdin.ts +0 -37
  118. package/src/cli/cmd/run/runtime.ts +0 -814
  119. package/src/cli/cmd/run/scrollback.shared.ts +0 -92
  120. package/src/cli/cmd/run/scrollback.surface.ts +0 -431
  121. package/src/cli/cmd/run/scrollback.writer.tsx +0 -352
  122. package/src/cli/cmd/run/session-data.ts +0 -1113
  123. package/src/cli/cmd/run/session-replay.ts +0 -374
  124. package/src/cli/cmd/run/session.shared.ts +0 -196
  125. package/src/cli/cmd/run/splash.ts +0 -280
  126. package/src/cli/cmd/run/stream.transport.ts +0 -1462
  127. package/src/cli/cmd/run/stream.ts +0 -175
  128. package/src/cli/cmd/run/subagent-data.ts +0 -876
  129. package/src/cli/cmd/run/theme.ts +0 -690
  130. package/src/cli/cmd/run/tool.ts +0 -1489
  131. package/src/cli/cmd/run/trace.ts +0 -94
  132. package/src/cli/cmd/run/turn-summary.ts +0 -47
  133. package/src/cli/cmd/run/types.ts +0 -350
  134. package/src/cli/cmd/run/variant.shared.ts +0 -215
  135. package/src/cli/cmd/run.ts +0 -894
  136. package/src/cli/cmd/serve.ts +0 -24
  137. package/src/cli/cmd/session.ts +0 -147
  138. package/src/cli/cmd/stats.ts +0 -393
  139. package/src/cli/cmd/tui.ts +0 -224
  140. package/src/cli/cmd/uninstall.ts +0 -353
  141. package/src/cli/cmd/upgrade.ts +0 -74
  142. package/src/cli/cmd/web.ts +0 -84
  143. package/src/cli/effect/prompt.ts +0 -37
  144. package/src/cli/effect-cmd.ts +0 -96
  145. package/src/cli/error.ts +0 -130
  146. package/src/cli/heap.ts +0 -45
  147. package/src/cli/logo.ts +0 -1
  148. package/src/cli/network.ts +0 -64
  149. package/src/cli/tui/layer.ts +0 -7
  150. package/src/cli/tui/validate-session.ts +0 -29
  151. package/src/cli/tui/worker.ts +0 -71
  152. package/src/cli/ui.ts +0 -132
  153. package/src/cli/upgrade.ts +0 -53
  154. package/src/command/index.ts +0 -184
  155. package/src/command/template/initialize.txt +0 -66
  156. package/src/command/template/review.txt +0 -101
  157. package/src/config/agent-preset.ts +0 -175
  158. package/src/config/agent.ts +0 -59
  159. package/src/config/command.ts +0 -39
  160. package/src/config/config.ts +0 -703
  161. package/src/config/entry-name.ts +0 -19
  162. package/src/config/managed.ts +0 -69
  163. package/src/config/markdown.ts +0 -36
  164. package/src/config/parse.ts +0 -79
  165. package/src/config/paths.ts +0 -45
  166. package/src/config/plugin.ts +0 -79
  167. package/src/config/tui-cwd.ts +0 -5
  168. package/src/config/tui-host-attention.ts +0 -21
  169. package/src/config/tui-migrate.ts +0 -132
  170. package/src/config/tui.ts +0 -274
  171. package/src/config/variable.ts +0 -91
  172. package/src/control-plane/adapters/index.ts +0 -41
  173. package/src/control-plane/adapters/worktree.ts +0 -96
  174. package/src/control-plane/dev/README.md +0 -19
  175. package/src/control-plane/dev/debug-workspace-plugin.ts +0 -73
  176. package/src/control-plane/types.ts +0 -59
  177. package/src/control-plane/util.ts +0 -39
  178. package/src/control-plane/workspace-adapter-runtime.ts +0 -51
  179. package/src/control-plane/workspace-context.ts +0 -26
  180. package/src/control-plane/workspace.ts +0 -989
  181. package/src/effect/app-runtime.ts +0 -132
  182. package/src/effect/bootstrap-runtime.ts +0 -23
  183. package/src/effect/bridge.ts +0 -84
  184. package/src/effect/config-service.ts +0 -67
  185. package/src/effect/instance-ref.ts +0 -11
  186. package/src/effect/instance-registry.ts +0 -12
  187. package/src/effect/instance-state.ts +0 -69
  188. package/src/effect/promise.ts +0 -17
  189. package/src/effect/run-service.ts +0 -47
  190. package/src/effect/runner.ts +0 -217
  191. package/src/effect/runtime-flags.ts +0 -79
  192. package/src/env/index.ts +0 -43
  193. package/src/event-v2-bridge.ts +0 -79
  194. package/src/format/formatter.ts +0 -404
  195. package/src/format/index.ts +0 -205
  196. package/src/git/index.ts +0 -350
  197. package/src/id/id.ts +0 -80
  198. package/src/ide/index.ts +0 -61
  199. package/src/image/image.ts +0 -174
  200. package/src/index.ts +0 -142
  201. package/src/installation/index.ts +0 -350
  202. package/src/lsp/client.ts +0 -650
  203. package/src/lsp/diagnostic.ts +0 -29
  204. package/src/lsp/language.ts +0 -121
  205. package/src/lsp/launch.ts +0 -21
  206. package/src/lsp/lsp.ts +0 -511
  207. package/src/lsp/server.ts +0 -1983
  208. package/src/markdown.d.ts +0 -4
  209. package/src/mcp/auth.ts +0 -174
  210. package/src/mcp/catalog.ts +0 -144
  211. package/src/mcp/index.ts +0 -953
  212. package/src/mcp/oauth-callback.ts +0 -221
  213. package/src/mcp/oauth-provider.ts +0 -206
  214. package/src/node.ts +0 -4
  215. package/src/patch/index.ts +0 -686
  216. package/src/permission/arity.ts +0 -163
  217. package/src/permission/evaluate.ts +0 -1
  218. package/src/permission/index.ts +0 -230
  219. package/src/plugin/azure.ts +0 -26
  220. package/src/plugin/cloudflare.ts +0 -76
  221. package/src/plugin/digitalocean.ts +0 -383
  222. package/src/plugin/github-copilot/copilot.ts +0 -413
  223. package/src/plugin/github-copilot/models.ts +0 -246
  224. package/src/plugin/index.ts +0 -315
  225. package/src/plugin/install.ts +0 -439
  226. package/src/plugin/loader.ts +0 -237
  227. package/src/plugin/meta.ts +0 -188
  228. package/src/plugin/openai/README.md +0 -31
  229. package/src/plugin/openai/codex.ts +0 -640
  230. package/src/plugin/openai/ws-pool.ts +0 -270
  231. package/src/plugin/openai/ws.ts +0 -381
  232. package/src/plugin/pty-environment.ts +0 -24
  233. package/src/plugin/shared.ts +0 -323
  234. package/src/plugin/snowflake-cortex.ts +0 -529
  235. package/src/plugin/tui/internal.ts +0 -10
  236. package/src/plugin/tui/runtime.ts +0 -1130
  237. package/src/plugin/xai.ts +0 -734
  238. package/src/project/bootstrap-service.ts +0 -9
  239. package/src/project/bootstrap.ts +0 -76
  240. package/src/project/instance-context.ts +0 -24
  241. package/src/project/instance-layer.ts +0 -11
  242. package/src/project/instance-runtime.ts +0 -16
  243. package/src/project/instance-store.ts +0 -209
  244. package/src/project/project.ts +0 -519
  245. package/src/project/vcs.ts +0 -431
  246. package/src/provider/auth.ts +0 -233
  247. package/src/provider/error.ts +0 -188
  248. package/src/provider/model-status.ts +0 -8
  249. package/src/provider/provider.ts +0 -1975
  250. package/src/provider/transform.ts +0 -1426
  251. package/src/question/index.ts +0 -229
  252. package/src/question/schema.ts +0 -10
  253. package/src/server/auth.ts +0 -48
  254. package/src/server/event.ts +0 -13
  255. package/src/server/global-lifecycle.ts +0 -28
  256. package/src/server/init-projectors.ts +0 -3
  257. package/src/server/mdns.ts +0 -47
  258. package/src/server/projectors.ts +0 -1
  259. package/src/server/proxy-util.ts +0 -48
  260. package/src/server/routes/instance/httpapi/AGENTS.md +0 -39
  261. package/src/server/routes/instance/httpapi/api.ts +0 -78
  262. package/src/server/routes/instance/httpapi/errors.ts +0 -193
  263. package/src/server/routes/instance/httpapi/groups/config.ts +0 -65
  264. package/src/server/routes/instance/httpapi/groups/control-plane.ts +0 -35
  265. package/src/server/routes/instance/httpapi/groups/control.ts +0 -76
  266. package/src/server/routes/instance/httpapi/groups/event.ts +0 -29
  267. package/src/server/routes/instance/httpapi/groups/experimental.ts +0 -260
  268. package/src/server/routes/instance/httpapi/groups/file.ts +0 -185
  269. package/src/server/routes/instance/httpapi/groups/global.ts +0 -138
  270. package/src/server/routes/instance/httpapi/groups/instance.ts +0 -206
  271. package/src/server/routes/instance/httpapi/groups/mcp.ts +0 -156
  272. package/src/server/routes/instance/httpapi/groups/metadata.ts +0 -18
  273. package/src/server/routes/instance/httpapi/groups/permission.ts +0 -61
  274. package/src/server/routes/instance/httpapi/groups/project-copy.ts +0 -32
  275. package/src/server/routes/instance/httpapi/groups/project.ts +0 -93
  276. package/src/server/routes/instance/httpapi/groups/provider.ts +0 -101
  277. package/src/server/routes/instance/httpapi/groups/pty.ts +0 -172
  278. package/src/server/routes/instance/httpapi/groups/query.ts +0 -12
  279. package/src/server/routes/instance/httpapi/groups/question.ts +0 -74
  280. package/src/server/routes/instance/httpapi/groups/session.ts +0 -462
  281. package/src/server/routes/instance/httpapi/groups/sync.ts +0 -113
  282. package/src/server/routes/instance/httpapi/groups/tui.ts +0 -208
  283. package/src/server/routes/instance/httpapi/groups/workspace.ts +0 -141
  284. package/src/server/routes/instance/httpapi/handlers/config.ts +0 -34
  285. package/src/server/routes/instance/httpapi/handlers/control-plane.ts +0 -37
  286. package/src/server/routes/instance/httpapi/handlers/control.ts +0 -43
  287. package/src/server/routes/instance/httpapi/handlers/event.ts +0 -99
  288. package/src/server/routes/instance/httpapi/handlers/experimental.ts +0 -187
  289. package/src/server/routes/instance/httpapi/handlers/file.ts +0 -139
  290. package/src/server/routes/instance/httpapi/handlers/global.ts +0 -156
  291. package/src/server/routes/instance/httpapi/handlers/instance.ts +0 -110
  292. package/src/server/routes/instance/httpapi/handlers/mcp.ts +0 -111
  293. package/src/server/routes/instance/httpapi/handlers/permission.ts +0 -41
  294. package/src/server/routes/instance/httpapi/handlers/project-copy.ts +0 -83
  295. package/src/server/routes/instance/httpapi/handlers/project.ts +0 -63
  296. package/src/server/routes/instance/httpapi/handlers/provider.ts +0 -113
  297. package/src/server/routes/instance/httpapi/handlers/pty.ts +0 -273
  298. package/src/server/routes/instance/httpapi/handlers/question.ts +0 -54
  299. package/src/server/routes/instance/httpapi/handlers/session-errors.ts +0 -21
  300. package/src/server/routes/instance/httpapi/handlers/session.ts +0 -440
  301. package/src/server/routes/instance/httpapi/handlers/sync.ts +0 -89
  302. package/src/server/routes/instance/httpapi/handlers/tui.ts +0 -131
  303. package/src/server/routes/instance/httpapi/handlers/workspace.ts +0 -102
  304. package/src/server/routes/instance/httpapi/lifecycle.ts +0 -54
  305. package/src/server/routes/instance/httpapi/middleware/authorization.ts +0 -150
  306. package/src/server/routes/instance/httpapi/middleware/compression.ts +0 -64
  307. package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +0 -29
  308. package/src/server/routes/instance/httpapi/middleware/error.ts +0 -43
  309. package/src/server/routes/instance/httpapi/middleware/fence.ts +0 -25
  310. package/src/server/routes/instance/httpapi/middleware/instance-context.ts +0 -43
  311. package/src/server/routes/instance/httpapi/middleware/proxy.ts +0 -108
  312. package/src/server/routes/instance/httpapi/middleware/schema-error.ts +0 -41
  313. package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +0 -250
  314. package/src/server/routes/instance/httpapi/public.ts +0 -535
  315. package/src/server/routes/instance/httpapi/server.ts +0 -298
  316. package/src/server/routes/instance/httpapi/websocket-tracker.ts +0 -57
  317. package/src/server/server.ts +0 -217
  318. package/src/server/shared/fence.ts +0 -60
  319. package/src/server/shared/pty-ticket.ts +0 -15
  320. package/src/server/shared/public-ui.ts +0 -12
  321. package/src/server/shared/tui-control.ts +0 -28
  322. package/src/server/shared/ui.ts +0 -108
  323. package/src/server/shared/workspace-routing.ts +0 -38
  324. package/src/server/tui-event.ts +0 -53
  325. package/src/session/compaction.ts +0 -620
  326. package/src/session/instruction.ts +0 -250
  327. package/src/session/llm/AGENTS.md +0 -90
  328. package/src/session/llm/ai-sdk.ts +0 -288
  329. package/src/session/llm/native-request.ts +0 -196
  330. package/src/session/llm/native-runtime.ts +0 -195
  331. package/src/session/llm/request.ts +0 -216
  332. package/src/session/llm.ts +0 -415
  333. package/src/session/message-error.ts +0 -14
  334. package/src/session/message-v2.ts +0 -744
  335. package/src/session/message.ts +0 -148
  336. package/src/session/overflow.ts +0 -34
  337. package/src/session/processor.ts +0 -1084
  338. package/src/session/prompt/anthropic.txt +0 -105
  339. package/src/session/prompt/beast.txt +0 -147
  340. package/src/session/prompt/build-switch.txt +0 -5
  341. package/src/session/prompt/codex.txt +0 -79
  342. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  343. package/src/session/prompt/default.txt +0 -95
  344. package/src/session/prompt/gemini.txt +0 -155
  345. package/src/session/prompt/gpt.txt +0 -107
  346. package/src/session/prompt/kimi.txt +0 -95
  347. package/src/session/prompt/max-steps.txt +0 -16
  348. package/src/session/prompt/plan-mode.txt +0 -70
  349. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  350. package/src/session/prompt/plan.txt +0 -26
  351. package/src/session/prompt/trinity.txt +0 -97
  352. package/src/session/prompt/ultrawork.txt +0 -289
  353. package/src/session/prompt.ts +0 -1725
  354. package/src/session/reminders.ts +0 -92
  355. package/src/session/retry.ts +0 -201
  356. package/src/session/revert.ts +0 -160
  357. package/src/session/run-state.ts +0 -156
  358. package/src/session/schema.ts +0 -26
  359. package/src/session/session.ts +0 -1119
  360. package/src/session/status.ts +0 -97
  361. package/src/session/summary.ts +0 -165
  362. package/src/session/system.ts +0 -117
  363. package/src/session/todo.ts +0 -90
  364. package/src/session/tools.ts +0 -207
  365. package/src/session/ultrawork.ts +0 -26
  366. package/src/share/session.ts +0 -61
  367. package/src/share/share-next.ts +0 -385
  368. package/src/skill/discovery.ts +0 -109
  369. package/src/skill/index.ts +0 -366
  370. package/src/snapshot/index.ts +0 -808
  371. package/src/sql.d.ts +0 -4
  372. package/src/storage/schema.ts +0 -5
  373. package/src/storage/storage.ts +0 -329
  374. package/src/sync/README.md +0 -179
  375. package/src/sync/schema.ts +0 -11
  376. package/src/temporary.ts +0 -31
  377. package/src/tool/apply_patch.ts +0 -313
  378. package/src/tool/apply_patch.txt +0 -33
  379. package/src/tool/edit.ts +0 -737
  380. package/src/tool/edit.txt +0 -10
  381. package/src/tool/external-directory.ts +0 -49
  382. package/src/tool/glob.ts +0 -76
  383. package/src/tool/glob.txt +0 -6
  384. package/src/tool/grep.ts +0 -112
  385. package/src/tool/grep.txt +0 -8
  386. package/src/tool/invalid.ts +0 -21
  387. package/src/tool/json-schema.ts +0 -164
  388. package/src/tool/lsp.ts +0 -113
  389. package/src/tool/lsp.txt +0 -24
  390. package/src/tool/mcp-websearch.ts +0 -96
  391. package/src/tool/plan-enter.txt +0 -14
  392. package/src/tool/plan-exit.txt +0 -13
  393. package/src/tool/plan.ts +0 -79
  394. package/src/tool/question.ts +0 -44
  395. package/src/tool/question.txt +0 -10
  396. package/src/tool/read.ts +0 -386
  397. package/src/tool/read.txt +0 -14
  398. package/src/tool/registry.ts +0 -440
  399. package/src/tool/schema.ts +0 -14
  400. package/src/tool/shell/id.ts +0 -19
  401. package/src/tool/shell/prompt.ts +0 -307
  402. package/src/tool/shell/shell.txt +0 -21
  403. package/src/tool/shell.ts +0 -657
  404. package/src/tool/skill.ts +0 -71
  405. package/src/tool/skill.txt +0 -5
  406. package/src/tool/task.ts +0 -346
  407. package/src/tool/task.txt +0 -19
  408. package/src/tool/todo.ts +0 -57
  409. package/src/tool/todowrite.txt +0 -44
  410. package/src/tool/tool.ts +0 -183
  411. package/src/tool/truncate.ts +0 -158
  412. package/src/tool/truncation-dir.ts +0 -4
  413. package/src/tool/webfetch.ts +0 -192
  414. package/src/tool/webfetch.txt +0 -13
  415. package/src/tool/websearch.ts +0 -143
  416. package/src/tool/websearch.txt +0 -14
  417. package/src/tool/write.ts +0 -104
  418. package/src/tool/write.txt +0 -8
  419. package/src/util/archive.ts +0 -17
  420. package/src/util/bom.ts +0 -27
  421. package/src/util/data-url.ts +0 -9
  422. package/src/util/defer.ts +0 -10
  423. package/src/util/effect-http-client.ts +0 -11
  424. package/src/util/error.ts +0 -1
  425. package/src/util/filesystem.ts +0 -251
  426. package/src/util/iife.ts +0 -3
  427. package/src/util/lazy.ts +0 -20
  428. package/src/util/local-context.ts +0 -25
  429. package/src/util/locale.ts +0 -2
  430. package/src/util/media.ts +0 -26
  431. package/src/util/process.ts +0 -177
  432. package/src/util/proxy-env.ts +0 -72
  433. package/src/util/queue.ts +0 -32
  434. package/src/util/record.ts +0 -1
  435. package/src/util/repository.ts +0 -232
  436. package/src/util/rpc.ts +0 -66
  437. package/src/util/signal.ts +0 -12
  438. package/src/util/timeout.ts +0 -13
  439. package/src/util/token.ts +0 -1
  440. package/src/util/wildcard.ts +0 -59
  441. package/src/worktree/index.ts +0 -654
  442. package/sst-env.d.ts +0 -10
  443. package/test/AGENTS.md +0 -204
  444. package/test/EFFECT_TEST_MIGRATION.md +0 -169
  445. package/test/account/repo.test.ts +0 -353
  446. package/test/account/service.test.ts +0 -453
  447. package/test/acp/config-option.test.ts +0 -229
  448. package/test/acp/content.test.ts +0 -201
  449. package/test/acp/directory.test.ts +0 -186
  450. package/test/acp/error.test.ts +0 -67
  451. package/test/acp/event.test.ts +0 -743
  452. package/test/acp/permission.test.ts +0 -273
  453. package/test/acp/service-session.test.ts +0 -1174
  454. package/test/acp/session.test.ts +0 -200
  455. package/test/acp/tool.test.ts +0 -210
  456. package/test/acp/usage.test.ts +0 -315
  457. package/test/agent/agent.test.ts +0 -760
  458. package/test/agent/plan-mode-subagent-bypass.test.ts +0 -159
  459. package/test/agent/plugin-agent-regression.test.ts +0 -64
  460. package/test/auth/auth.test.ts +0 -77
  461. package/test/background/job.test.ts +0 -243
  462. package/test/cli/account.test.ts +0 -30
  463. package/test/cli/acp/acp-test-client.ts +0 -97
  464. package/test/cli/acp/config-options.test.ts +0 -103
  465. package/test/cli/acp/helpers.ts +0 -96
  466. package/test/cli/acp/initialize-auth.test.ts +0 -61
  467. package/test/cli/acp/lifecycle.test.ts +0 -118
  468. package/test/cli/acp/prompt-content.test.ts +0 -97
  469. package/test/cli/acp/skills.test.ts +0 -38
  470. package/test/cli/cmd/tui/attention.test.ts +0 -484
  471. package/test/cli/effect-cmd-instance-als.test.ts +0 -39
  472. package/test/cli/error.test.ts +0 -95
  473. package/test/cli/github-action.test.ts +0 -199
  474. package/test/cli/github-remote.test.ts +0 -90
  475. package/test/cli/help/__snapshots__/help-snapshots.test.ts.snap +0 -631
  476. package/test/cli/help/help-snapshots.test.ts +0 -137
  477. package/test/cli/import.test.ts +0 -54
  478. package/test/cli/mcp-add.test.ts +0 -74
  479. package/test/cli/plugin-auth-picker.test.ts +0 -120
  480. package/test/cli/run/entry.body.test.ts +0 -536
  481. package/test/cli/run/footer.menu.test.ts +0 -43
  482. package/test/cli/run/footer.view.test.tsx +0 -1375
  483. package/test/cli/run/footer.width.test.ts +0 -35
  484. package/test/cli/run/permission.shared.test.ts +0 -144
  485. package/test/cli/run/prompt.editor.test.ts +0 -101
  486. package/test/cli/run/prompt.shared.test.ts +0 -101
  487. package/test/cli/run/question.shared.test.ts +0 -115
  488. package/test/cli/run/run-process.test.ts +0 -84
  489. package/test/cli/run/runtime.boot.test.ts +0 -283
  490. package/test/cli/run/runtime.queue.test.ts +0 -481
  491. package/test/cli/run/runtime.stdin.test.ts +0 -71
  492. package/test/cli/run/runtime.test.ts +0 -238
  493. package/test/cli/run/scrollback.surface.test.ts +0 -1065
  494. package/test/cli/run/session-data.test.ts +0 -595
  495. package/test/cli/run/session-replay.test.ts +0 -692
  496. package/test/cli/run/session.shared.test.ts +0 -247
  497. package/test/cli/run/stream.test.ts +0 -56
  498. package/test/cli/run/stream.transport.test.ts +0 -2363
  499. package/test/cli/run/subagent-data.test.ts +0 -547
  500. package/test/cli/run/theme.test.ts +0 -177
  501. package/test/cli/run/variant.shared.test.ts +0 -217
  502. package/test/cli/serve/serve-process.test.ts +0 -61
  503. package/test/cli/smokes/read-only.test.ts +0 -115
  504. package/test/cli/tui/attach.test.ts +0 -11
  505. package/test/cli/tui/editor-context-zed.test.ts +0 -379
  506. package/test/cli/tui/editor-context.test.tsx +0 -297
  507. package/test/cli/tui/plugin-add.test.ts +0 -110
  508. package/test/cli/tui/plugin-install.test.ts +0 -87
  509. package/test/cli/tui/plugin-lifecycle.test.ts +0 -224
  510. package/test/cli/tui/plugin-loader-entrypoint.test.ts +0 -485
  511. package/test/cli/tui/plugin-loader-pure.test.ts +0 -72
  512. package/test/cli/tui/plugin-loader.test.ts +0 -1332
  513. package/test/cli/tui/plugin-toggle.test.ts +0 -264
  514. package/test/cli/tui/thread.test.ts +0 -36
  515. package/test/config/agent-color.test.ts +0 -47
  516. package/test/config/config.test.ts +0 -2041
  517. package/test/config/entry-name.test.ts +0 -57
  518. package/test/config/fixtures/empty-frontmatter.md +0 -4
  519. package/test/config/fixtures/frontmatter.md +0 -28
  520. package/test/config/fixtures/markdown-header.md +0 -11
  521. package/test/config/fixtures/no-frontmatter.md +0 -1
  522. package/test/config/fixtures/weird-model-id.md +0 -13
  523. package/test/config/lsp.test.ts +0 -69
  524. package/test/config/markdown.test.ts +0 -228
  525. package/test/config/plugin.test.ts +0 -0
  526. package/test/config/tui.test.ts +0 -886
  527. package/test/control-plane/adapters.test.ts +0 -71
  528. package/test/control-plane/workspace.test.ts +0 -1703
  529. package/test/effect/app-graph-types.test.ts +0 -108
  530. package/test/effect/app-graph.test.ts +0 -204
  531. package/test/effect/app-runtime-logger.test.ts +0 -99
  532. package/test/effect/config-service.test.ts +0 -65
  533. package/test/effect/instance-state.test.ts +0 -391
  534. package/test/effect/run-service.test.ts +0 -89
  535. package/test/effect/runner.test.ts +0 -514
  536. package/test/effect/runtime-flags.test.ts +0 -373
  537. package/test/fake/account.ts +0 -9
  538. package/test/fake/auth.ts +0 -8
  539. package/test/fake/npm.ts +0 -8
  540. package/test/fake/provider.ts +0 -82
  541. package/test/fake/skill.ts +0 -8
  542. package/test/filesystem/filesystem.test.ts +0 -319
  543. package/test/fixture/agent-plugin.constants.ts +0 -6
  544. package/test/fixture/agent-plugin.ts +0 -12
  545. package/test/fixture/config.ts +0 -23
  546. package/test/fixture/db.ts +0 -11
  547. package/test/fixture/fixture.test.ts +0 -26
  548. package/test/fixture/fixture.ts +0 -224
  549. package/test/fixture/flag.ts +0 -20
  550. package/test/fixture/flock-worker.ts +0 -72
  551. package/test/fixture/lsp/fake-lsp-server.js +0 -249
  552. package/test/fixture/mcp-session-recovery.ts +0 -50
  553. package/test/fixture/plug-worker.ts +0 -93
  554. package/test/fixture/plugin-meta-worker.ts +0 -19
  555. package/test/fixture/plugin.ts +0 -10
  556. package/test/fixture/skills/agents-sdk/SKILL.md +0 -152
  557. package/test/fixture/skills/agents-sdk/references/callable.md +0 -92
  558. package/test/fixture/skills/cloudflare/SKILL.md +0 -211
  559. package/test/fixture/skills/index.json +0 -6
  560. package/test/fixture/tui-environment.tsx +0 -32
  561. package/test/fixture/tui-plugin.ts +0 -355
  562. package/test/fixture/tui-runtime.ts +0 -56
  563. package/test/fixture/tui-sdk.ts +0 -82
  564. package/test/fixture/workspace.ts +0 -30
  565. package/test/fixtures/recordings/session/native-anthropic-tool-loop.json +0 -49
  566. package/test/fixtures/recordings/session/native-openai-oauth-tool-loop.json +0 -45
  567. package/test/fixtures/recordings/session/native-zen-tool-loop.json +0 -49
  568. package/test/format/format.test.ts +0 -228
  569. package/test/git/git.test.ts +0 -178
  570. package/test/ide/ide.test.ts +0 -82
  571. package/test/image/fixtures/picture-5mb-base64.png +0 -0
  572. package/test/image/image.test.ts +0 -123
  573. package/test/installation/installation.test.ts +0 -230
  574. package/test/lib/cli-process.ts +0 -459
  575. package/test/lib/effect.ts +0 -177
  576. package/test/lib/filesystem.ts +0 -10
  577. package/test/lib/llm-server.ts +0 -779
  578. package/test/lib/snapshot.ts +0 -73
  579. package/test/lib/test-provider.ts +0 -37
  580. package/test/lib/websocket.ts +0 -46
  581. package/test/lsp/client.test.ts +0 -488
  582. package/test/lsp/index.test.ts +0 -232
  583. package/test/lsp/jdtls-root.test.ts +0 -459
  584. package/test/lsp/launch.test.ts +0 -22
  585. package/test/lsp/lifecycle.test.ts +0 -160
  586. package/test/mcp/auth.test.ts +0 -78
  587. package/test/mcp/headers.test.ts +0 -126
  588. package/test/mcp/lifecycle.test.ts +0 -1213
  589. package/test/mcp/oauth-auto-connect.test.ts +0 -276
  590. package/test/mcp/oauth-browser.test.ts +0 -239
  591. package/test/mcp/oauth-callback.test.ts +0 -34
  592. package/test/mcp/oauth-provider.test.ts +0 -61
  593. package/test/mcp/session-recovery.test.ts +0 -27
  594. package/test/patch/patch.test.ts +0 -383
  595. package/test/permission/arity.test.ts +0 -33
  596. package/test/permission/next.test.ts +0 -1176
  597. package/test/permission-task.test.ts +0 -318
  598. package/test/plugin/auth-override.test.ts +0 -105
  599. package/test/plugin/cloudflare.test.ts +0 -68
  600. package/test/plugin/codex.test.ts +0 -247
  601. package/test/plugin/github-copilot-models.test.ts +0 -332
  602. package/test/plugin/install-concurrency.test.ts +0 -140
  603. package/test/plugin/install.test.ts +0 -570
  604. package/test/plugin/loader-shared.test.ts +0 -1303
  605. package/test/plugin/meta.test.ts +0 -137
  606. package/test/plugin/openai-rollout.test.ts +0 -17
  607. package/test/plugin/openai-ws.test.ts +0 -877
  608. package/test/plugin/shared.test.ts +0 -88
  609. package/test/plugin/snowflake-cortex.test.ts +0 -278
  610. package/test/plugin/trigger.test.ts +0 -120
  611. package/test/plugin/workspace-adapter.test.ts +0 -140
  612. package/test/plugin/xai.test.ts +0 -634
  613. package/test/preload.ts +0 -92
  614. package/test/project/instance-bootstrap.test.ts +0 -110
  615. package/test/project/instance.test.ts +0 -245
  616. package/test/project/migrate-global.test.ts +0 -167
  617. package/test/project/project-directory.test.ts +0 -201
  618. package/test/project/project.test.ts +0 -815
  619. package/test/project/vcs.test.ts +0 -336
  620. package/test/project/worktree-remove.test.ts +0 -126
  621. package/test/project/worktree.test.ts +0 -320
  622. package/test/provider/amazon-bedrock.test.ts +0 -360
  623. package/test/provider/cf-ai-gateway-e2e.test.ts +0 -132
  624. package/test/provider/digitalocean.test.ts +0 -123
  625. package/test/provider/gitlab-duo.test.ts +0 -412
  626. package/test/provider/header-timeout.test.ts +0 -233
  627. package/test/provider/model-status.test.ts +0 -61
  628. package/test/provider/provider.test.ts +0 -1793
  629. package/test/provider/transform.test.ts +0 -4207
  630. package/test/question/question.test.ts +0 -465
  631. package/test/server/AGENTS.md +0 -15
  632. package/test/server/auth.test.ts +0 -59
  633. package/test/server/global-bus.ts +0 -31
  634. package/test/server/global-session-list.test.ts +0 -104
  635. package/test/server/httpapi-authorization.test.ts +0 -174
  636. package/test/server/httpapi-compression.test.ts +0 -151
  637. package/test/server/httpapi-config.test.ts +0 -110
  638. package/test/server/httpapi-control-plane.test.ts +0 -63
  639. package/test/server/httpapi-cors-vary.test.ts +0 -63
  640. package/test/server/httpapi-cors.test.ts +0 -122
  641. package/test/server/httpapi-error-middleware.test.ts +0 -101
  642. package/test/server/httpapi-event.test.ts +0 -94
  643. package/test/server/httpapi-exercise/assertions.ts +0 -64
  644. package/test/server/httpapi-exercise/backend.ts +0 -144
  645. package/test/server/httpapi-exercise/dsl.ts +0 -210
  646. package/test/server/httpapi-exercise/environment.ts +0 -40
  647. package/test/server/httpapi-exercise/index.ts +0 -1685
  648. package/test/server/httpapi-exercise/report.ts +0 -66
  649. package/test/server/httpapi-exercise/routing.ts +0 -96
  650. package/test/server/httpapi-exercise/runner.ts +0 -267
  651. package/test/server/httpapi-exercise/runtime.ts +0 -52
  652. package/test/server/httpapi-exercise/types.ts +0 -123
  653. package/test/server/httpapi-experimental.test.ts +0 -297
  654. package/test/server/httpapi-file.test.ts +0 -73
  655. package/test/server/httpapi-global.test.ts +0 -66
  656. package/test/server/httpapi-instance-context.test.ts +0 -348
  657. package/test/server/httpapi-instance-route-auth.test.ts +0 -81
  658. package/test/server/httpapi-instance.test.ts +0 -265
  659. package/test/server/httpapi-layer.ts +0 -33
  660. package/test/server/httpapi-listen.test.ts +0 -412
  661. package/test/server/httpapi-mcp-oauth.test.ts +0 -73
  662. package/test/server/httpapi-mcp.test.ts +0 -223
  663. package/test/server/httpapi-mdns.test.ts +0 -79
  664. package/test/server/httpapi-promptasync-context.test.ts +0 -223
  665. package/test/server/httpapi-provider.test.ts +0 -400
  666. package/test/server/httpapi-pty.test.ts +0 -299
  667. package/test/server/httpapi-public-openapi.test.ts +0 -319
  668. package/test/server/httpapi-query-schema-drift.test.ts +0 -330
  669. package/test/server/httpapi-reference.test.ts +0 -62
  670. package/test/server/httpapi-schema-error-body.test.ts +0 -165
  671. package/test/server/httpapi-sdk.test.ts +0 -909
  672. package/test/server/httpapi-session.test.ts +0 -1011
  673. package/test/server/httpapi-sync.test.ts +0 -148
  674. package/test/server/httpapi-ui.test.ts +0 -453
  675. package/test/server/httpapi-v2-location.test.ts +0 -82
  676. package/test/server/httpapi-v2-pty.test.ts +0 -250
  677. package/test/server/httpapi-workspace-routing.test.ts +0 -555
  678. package/test/server/httpapi-workspace.test.ts +0 -513
  679. package/test/server/negative-tokens-regression.test.ts +0 -83
  680. package/test/server/project-copy.test.ts +0 -121
  681. package/test/server/project-init-git.test.ts +0 -114
  682. package/test/server/proxy-util.test.ts +0 -113
  683. package/test/server/sdk-error-shape.test.ts +0 -81
  684. package/test/server/sdk-v1-smoke.test.ts +0 -57
  685. package/test/server/session-actions.test.ts +0 -109
  686. package/test/server/session-diff-missing-patch.test.ts +0 -96
  687. package/test/server/session-list.test.ts +0 -312
  688. package/test/server/session-messages.test.ts +0 -179
  689. package/test/server/session-select.test.ts +0 -66
  690. package/test/server/workspace-proxy.test.ts +0 -181
  691. package/test/server/workspace-routing.test.ts +0 -94
  692. package/test/server/worktree-endpoint-repro.test.ts +0 -307
  693. package/test/session/compaction.test.ts +0 -1834
  694. package/test/session/instruction.test.ts +0 -256
  695. package/test/session/llm-native-recorded.test.ts +0 -433
  696. package/test/session/llm-native.test.ts +0 -760
  697. package/test/session/llm.test.ts +0 -1932
  698. package/test/session/message-v2.test.ts +0 -1661
  699. package/test/session/messages-pagination.test.ts +0 -1056
  700. package/test/session/processor-effect.test.ts +0 -1076
  701. package/test/session/prompt.test.ts +0 -2326
  702. package/test/session/retry.test.ts +0 -439
  703. package/test/session/revert-compact.test.ts +0 -639
  704. package/test/session/schema-decoding.test.ts +0 -313
  705. package/test/session/session-schema.test.ts +0 -78
  706. package/test/session/session.test.ts +0 -248
  707. package/test/session/snapshot-tool-race.test.ts +0 -190
  708. package/test/session/structured-output-integration.test.ts +0 -235
  709. package/test/session/structured-output.test.ts +0 -387
  710. package/test/session/system.test.ts +0 -86
  711. package/test/session/ultrawork.test.ts +0 -25
  712. package/test/share/share-next.test.ts +0 -326
  713. package/test/skill/discovery.test.ts +0 -139
  714. package/test/skill/skill.test.ts +0 -571
  715. package/test/snapshot/snapshot.test.ts +0 -1121
  716. package/test/storage/storage.test.ts +0 -296
  717. package/test/tool/__snapshots__/parameters.test.ts.snap +0 -484
  718. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  719. package/test/tool/apply_patch.test.ts +0 -533
  720. package/test/tool/edit.test.ts +0 -578
  721. package/test/tool/external-directory.test.ts +0 -155
  722. package/test/tool/fixtures/large-image.png +0 -0
  723. package/test/tool/fixtures/models-api.json +0 -117299
  724. package/test/tool/glob.test.ts +0 -136
  725. package/test/tool/grep.test.ts +0 -225
  726. package/test/tool/lsp.test.ts +0 -181
  727. package/test/tool/parameters.test.ts +0 -293
  728. package/test/tool/question.test.ts +0 -138
  729. package/test/tool/read.test.ts +0 -605
  730. package/test/tool/registry.test.ts +0 -497
  731. package/test/tool/shell.test.ts +0 -1238
  732. package/test/tool/skill.test.ts +0 -136
  733. package/test/tool/task.test.ts +0 -898
  734. package/test/tool/tool-define.test.ts +0 -153
  735. package/test/tool/truncation.test.ts +0 -266
  736. package/test/tool/webfetch.test.ts +0 -113
  737. package/test/tool/websearch.test.ts +0 -99
  738. package/test/tool/write.test.ts +0 -276
  739. package/test/util/data-url.test.ts +0 -14
  740. package/test/util/error.test.ts +0 -16
  741. package/test/util/filesystem.test.ts +0 -656
  742. package/test/util/glob.test.ts +0 -164
  743. package/test/util/iife.test.ts +0 -36
  744. package/test/util/lazy.test.ts +0 -50
  745. package/test/util/module.test.ts +0 -59
  746. package/test/util/process.test.ts +0 -128
  747. package/test/util/repository.test.ts +0 -93
  748. package/test/util/timeout.test.ts +0 -21
  749. package/test/util/wildcard.test.ts +0 -90
  750. package/test/v2/session-message-updater.test.ts +0 -269
  751. package/tsconfig.json +0 -16
@@ -1,1932 +0,0 @@
1
- import { PermissionV1 } from "@miaw/core/v1/permission"
2
- import { ConfigV1 } from "@miaw/core/v1/config/config"
3
- import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test"
4
- import { SessionV1 } from "@miaw/core/v1/session"
5
- import path from "path"
6
- import { tool, type ModelMessage } from "ai"
7
- import { Cause, Effect, Exit, Fiber, Layer, Stream } from "effect"
8
- import { InstanceRef } from "../../src/effect/instance-ref"
9
- import { HttpClientRequest, HttpClientResponse } from "effect/unstable/http"
10
- import z from "zod"
11
- import { LLM } from "../../src/session/llm"
12
- import { LLMClient, RequestExecutor, WebSocketExecutor } from "@miaw/llm/route"
13
- import { Auth } from "@/auth"
14
- import { Config } from "@/config/config"
15
- import { Provider } from "@/provider/provider"
16
- import { ProviderTransform } from "@/provider/transform"
17
- import { ModelsDev } from "@miaw/core/models-dev"
18
- import { Plugin } from "@/plugin"
19
-
20
- import { testEffect } from "../lib/effect"
21
- import type { Agent } from "../../src/agent/agent"
22
- import { MessageV2 } from "../../src/session/message-v2"
23
- import { SessionID, MessageID } from "../../src/session/schema"
24
- import { RuntimeFlags } from "@/effect/runtime-flags"
25
- import { Permission } from "@/permission"
26
- import { LLMAISDK } from "@/session/llm/ai-sdk"
27
- import { Session as SessionNs } from "@/session/session"
28
- import { ProviderV2 } from "@miaw/core/provider"
29
- import { ModelV2 } from "@miaw/core/model"
30
-
31
- type ConfigModel = NonNullable<NonNullable<ConfigV1.Info["provider"]>[string]["models"]>[string]
32
-
33
- const openAIConfig = (model: ModelsDev.Provider["models"][string], baseURL: string): Partial<ConfigV1.Info> => {
34
- const { experimental: _experimental, ...configModel } = model
35
- return {
36
- enabled_providers: ["openai"],
37
- provider: {
38
- openai: {
39
- name: "OpenAI",
40
- env: ["OPENAI_API_KEY"],
41
- npm: "@ai-sdk/openai",
42
- api: "https://api.openai.com/v1",
43
- models: {
44
- [model.id]: JSON.parse(JSON.stringify(configModel)) as ConfigModel,
45
- },
46
- options: {
47
- apiKey: "test-openai-key",
48
- baseURL,
49
- },
50
- },
51
- },
52
- }
53
- }
54
-
55
- const it = testEffect(Layer.mergeAll(LLM.defaultLayer, Provider.defaultLayer))
56
-
57
- // LLM.stream returns a Stream, not an Effect, so we can't use the serviceUse proxy.
58
- const drain = (input: LLM.StreamInput) => LLM.Service.use((svc) => svc.stream(input).pipe(Stream.runDrain))
59
-
60
- // drainWith builds an isolated runtime so the custom layer fully owns LLM and
61
- // its transitive deps — `Effect.provide(layer)` over an existing runtime layers
62
- // the new services on top, but transitive Service overrides (e.g. RequestExecutor)
63
- // resolved through the outer LLM.defaultLayer leak through.
64
- const drainWith = (layer: Layer.Layer<LLM.Service>, input: LLM.StreamInput) =>
65
- Effect.gen(function* () {
66
- const ctx = yield* InstanceRef
67
- if (!ctx) return yield* Effect.die("InstanceRef not provided")
68
- return yield* Effect.promise(() =>
69
- Effect.runPromise(
70
- LLM.Service.use((svc) => svc.stream(input).pipe(Stream.runDrain)).pipe(
71
- Effect.provide(layer),
72
- Effect.provideService(InstanceRef, ctx),
73
- ),
74
- ),
75
- )
76
- })
77
-
78
- function llmLayerWithExecutor(executor: Layer.Layer<RequestExecutor.Service>, flags: Partial<RuntimeFlags.Info> = {}) {
79
- return LLM.layer.pipe(
80
- Layer.provide(Auth.defaultLayer),
81
- Layer.provide(Config.defaultLayer),
82
- Layer.provide(Provider.defaultLayer),
83
- Layer.provide(Plugin.defaultLayer),
84
- Layer.provide(LLMClient.layer.pipe(Layer.provide(Layer.mergeAll(executor, WebSocketExecutor.layer)))),
85
- Layer.provide(RuntimeFlags.layer(flags)),
86
- )
87
- }
88
-
89
- describe("session.llm.hasToolCalls", () => {
90
- test("returns false for empty messages array", () => {
91
- expect(LLM.hasToolCalls([])).toBe(false)
92
- })
93
-
94
- test("returns false for messages with only text content", () => {
95
- const messages: ModelMessage[] = [
96
- {
97
- role: "user",
98
- content: [{ type: "text", text: "Hello" }],
99
- },
100
- {
101
- role: "assistant",
102
- content: [{ type: "text", text: "Hi there" }],
103
- },
104
- ]
105
- expect(LLM.hasToolCalls(messages)).toBe(false)
106
- })
107
-
108
- test("returns true when messages contain tool-call", () => {
109
- const messages = [
110
- {
111
- role: "user",
112
- content: [{ type: "text", text: "Run a command" }],
113
- },
114
- {
115
- role: "assistant",
116
- content: [
117
- {
118
- type: "tool-call",
119
- toolCallId: "call-123",
120
- toolName: "bash",
121
- },
122
- ],
123
- },
124
- ] as ModelMessage[]
125
- expect(LLM.hasToolCalls(messages)).toBe(true)
126
- })
127
-
128
- test("returns true when messages contain tool-result", () => {
129
- const messages = [
130
- {
131
- role: "tool",
132
- content: [
133
- {
134
- type: "tool-result",
135
- toolCallId: "call-123",
136
- toolName: "bash",
137
- },
138
- ],
139
- },
140
- ] as ModelMessage[]
141
- expect(LLM.hasToolCalls(messages)).toBe(true)
142
- })
143
-
144
- test("returns false for messages with string content", () => {
145
- const messages: ModelMessage[] = [
146
- {
147
- role: "user",
148
- content: "Hello world",
149
- },
150
- {
151
- role: "assistant",
152
- content: "Hi there",
153
- },
154
- ]
155
- expect(LLM.hasToolCalls(messages)).toBe(false)
156
- })
157
-
158
- test("returns true when tool-call is mixed with text content", () => {
159
- const messages = [
160
- {
161
- role: "assistant",
162
- content: [
163
- { type: "text", text: "Let me run that command" },
164
- {
165
- type: "tool-call",
166
- toolCallId: "call-456",
167
- toolName: "read",
168
- },
169
- ],
170
- },
171
- ] as ModelMessage[]
172
- expect(LLM.hasToolCalls(messages)).toBe(true)
173
- })
174
- })
175
-
176
- describe("session.llm.ai-sdk adapter", () => {
177
- type AISDKAdapterEvent = Parameters<typeof LLMAISDK.toLLMEvents>[1]
178
-
179
- const adapt = (events: ReadonlyArray<AISDKAdapterEvent>) => {
180
- const state = LLMAISDK.adapterState()
181
- return Effect.runPromise(
182
- Effect.forEach(events, (event) => LLMAISDK.toLLMEvents(state, event)).pipe(Effect.map((items) => items.flat())),
183
- )
184
- }
185
- // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- tests defensive adapter branches outside AI SDK's current typed surface
186
- const uncheckedAdapterEvent = (input: unknown) => input as AISDKAdapterEvent
187
-
188
- test("maps AI SDK stream chunks without losing session-visible fields", async () => {
189
- const metadata = { openai: { itemID: "item-1" } }
190
- const events = await adapt([
191
- { type: "start" },
192
- { type: "start-step", request: {}, warnings: [] },
193
- { type: "text-start", id: "text-1", providerMetadata: metadata },
194
- { type: "text-delta", id: "text-1", text: "Hel", providerMetadata: { openai: { delta: 1 } } },
195
- { type: "text-delta", id: "text-1", text: "lo", providerMetadata: { openai: { delta: 2 } } },
196
- { type: "text-end", id: "text-1", providerMetadata: { openai: { done: true } } },
197
- { type: "reasoning-start", id: "reasoning-1", providerMetadata: metadata },
198
- { type: "reasoning-delta", id: "reasoning-1", text: "Think", providerMetadata: { openai: { delta: 3 } } },
199
- { type: "reasoning-end", id: "reasoning-1", providerMetadata: { openai: { done: true } } },
200
- { type: "tool-input-start", id: "call-1", toolName: "lookup", providerMetadata: metadata },
201
- { type: "tool-input-delta", id: "call-1", delta: '{"query":' },
202
- { type: "tool-input-delta", id: "call-1", delta: '"weather"}' },
203
- { type: "tool-input-end", id: "call-1", providerMetadata: { openai: { inputDone: true } } },
204
- {
205
- type: "tool-call",
206
- toolCallId: "call-1",
207
- toolName: "lookup",
208
- input: { query: "weather" },
209
- providerExecuted: true,
210
- providerMetadata: { openai: { called: true } },
211
- },
212
- {
213
- type: "tool-result",
214
- toolCallId: "call-1",
215
- toolName: "lookup",
216
- input: { query: "weather" },
217
- output: { title: "Lookup", output: "sunny", metadata: { ok: true } },
218
- providerExecuted: true,
219
- providerMetadata: { openai: { result: true } },
220
- },
221
- {
222
- type: "finish-step",
223
- response: { id: "response-1", timestamp: new Date(0), modelId: "gpt-test" },
224
- finishReason: "other",
225
- rawFinishReason: "other",
226
- usage: {
227
- inputTokens: 10,
228
- outputTokens: 5,
229
- totalTokens: 15,
230
- inputTokenDetails: { noCacheTokens: 5, cacheReadTokens: 3, cacheWriteTokens: 2 },
231
- outputTokenDetails: { textTokens: 4, reasoningTokens: 1 },
232
- },
233
- providerMetadata: { openai: { step: true } },
234
- },
235
- {
236
- type: "finish",
237
- finishReason: "other",
238
- rawFinishReason: "other",
239
- totalUsage: {
240
- inputTokens: 11,
241
- outputTokens: 6,
242
- totalTokens: 17,
243
- cachedInputTokens: 4,
244
- reasoningTokens: 2,
245
- inputTokenDetails: { noCacheTokens: 7, cacheReadTokens: 4, cacheWriteTokens: undefined },
246
- outputTokenDetails: { textTokens: 4, reasoningTokens: 2 },
247
- },
248
- },
249
- ])
250
-
251
- expect(events).toMatchObject([
252
- { type: "step-start", index: 0 },
253
- { type: "text-start", id: "text-1", providerMetadata: metadata },
254
- { type: "text-delta", id: "text-1", text: "Hel", providerMetadata: { openai: { delta: 1 } } },
255
- { type: "text-delta", id: "text-1", text: "lo", providerMetadata: { openai: { delta: 2 } } },
256
- { type: "text-end", id: "text-1", providerMetadata: { openai: { done: true } } },
257
- { type: "reasoning-start", id: "reasoning-1", providerMetadata: metadata },
258
- { type: "reasoning-delta", id: "reasoning-1", text: "Think", providerMetadata: { openai: { delta: 3 } } },
259
- { type: "reasoning-end", id: "reasoning-1", providerMetadata: { openai: { done: true } } },
260
- { type: "tool-input-start", id: "call-1", name: "lookup", providerMetadata: metadata },
261
- { type: "tool-input-delta", id: "call-1", name: "lookup", text: '{"query":' },
262
- { type: "tool-input-delta", id: "call-1", name: "lookup", text: '"weather"}' },
263
- { type: "tool-input-end", id: "call-1", name: "lookup", providerMetadata: { openai: { inputDone: true } } },
264
- {
265
- type: "tool-call",
266
- id: "call-1",
267
- name: "lookup",
268
- input: { query: "weather" },
269
- providerExecuted: true,
270
- providerMetadata: { openai: { called: true } },
271
- },
272
- {
273
- type: "tool-result",
274
- id: "call-1",
275
- name: "lookup",
276
- result: { type: "json", value: { title: "Lookup", output: "sunny", metadata: { ok: true } } },
277
- providerExecuted: true,
278
- providerMetadata: { openai: { result: true } },
279
- },
280
- {
281
- type: "step-finish",
282
- index: 0,
283
- reason: "unknown",
284
- usage: {
285
- inputTokens: 10,
286
- outputTokens: 5,
287
- totalTokens: 15,
288
- reasoningTokens: 1,
289
- cacheReadInputTokens: 3,
290
- cacheWriteInputTokens: 2,
291
- },
292
- providerMetadata: { openai: { step: true } },
293
- },
294
- {
295
- type: "finish",
296
- reason: "unknown",
297
- usage: {
298
- inputTokens: 11,
299
- outputTokens: 6,
300
- totalTokens: 17,
301
- reasoningTokens: 2,
302
- cacheReadInputTokens: 4,
303
- },
304
- },
305
- ])
306
- })
307
-
308
- test("creates stable block ids when AI SDK omits them", async () => {
309
- const events = await adapt([
310
- uncheckedAdapterEvent({ type: "text-delta", text: "implicit text" }),
311
- uncheckedAdapterEvent({ type: "text-end" }),
312
- uncheckedAdapterEvent({ type: "reasoning-delta", text: "implicit reasoning" }),
313
- uncheckedAdapterEvent({ type: "reasoning-end" }),
314
- ])
315
-
316
- expect(events).toMatchObject([
317
- { type: "text-delta", id: "text-0", text: "implicit text" },
318
- { type: "text-end", id: "text-0" },
319
- { type: "reasoning-delta", id: "reasoning-0", text: "implicit reasoning" },
320
- { type: "reasoning-end", id: "reasoning-0" },
321
- ])
322
- })
323
-
324
- test("explicitly ignores non-session-visible AI SDK chunks", async () => {
325
- expect(
326
- await adapt([
327
- uncheckedAdapterEvent({ type: "abort" }),
328
- uncheckedAdapterEvent({ type: "source" }),
329
- uncheckedAdapterEvent({ type: "file" }),
330
- uncheckedAdapterEvent({ type: "raw" }),
331
- uncheckedAdapterEvent({ type: "tool-output-denied" }),
332
- uncheckedAdapterEvent({ type: "tool-approval-request" }),
333
- ]),
334
- ).toEqual([])
335
- })
336
-
337
- test("preserves tool-error cause", async () => {
338
- const error = new PermissionV1.RejectedError()
339
- const events = await Effect.runPromise(
340
- LLMAISDK.toLLMEvents(LLMAISDK.adapterState(), {
341
- type: "tool-error",
342
- toolCallId: "call_123",
343
- toolName: "bash",
344
- input: {},
345
- error,
346
- }),
347
- )
348
-
349
- expect(events).toHaveLength(1)
350
- expect(events[0]).toMatchObject({
351
- type: "tool-error",
352
- id: "call_123",
353
- name: "bash",
354
- message: error.message,
355
- error,
356
- })
357
- })
358
-
359
- test("emits undefined usage when every AI SDK usage field is missing", async () => {
360
- // If every numeric field is undefined the translator should signal "no usage info"
361
- // by emitting undefined, not by polluting the event with usage: {}. Downstream cost
362
- // telemetry distinguishes "missing" from "zero," so emitting an empty object causes
363
- // false positives ("usage was tracked, just empty") instead of correct nulls.
364
- const events = await adapt([
365
- {
366
- type: "finish-step",
367
- response: { id: "response-1", timestamp: new Date(0), modelId: "gpt-test" },
368
- finishReason: "stop",
369
- rawFinishReason: "stop",
370
- providerMetadata: undefined,
371
- usage: {
372
- inputTokens: undefined,
373
- outputTokens: undefined,
374
- totalTokens: undefined,
375
- reasoningTokens: undefined,
376
- cachedInputTokens: undefined,
377
- inputTokenDetails: { noCacheTokens: undefined, cacheReadTokens: undefined, cacheWriteTokens: undefined },
378
- outputTokenDetails: { textTokens: undefined, reasoningTokens: undefined },
379
- },
380
- },
381
- ])
382
-
383
- expect(events).toHaveLength(1)
384
- const stepFinish = events[0]
385
- if (stepFinish.type !== "step-finish") throw new Error("expected step-finish")
386
- expect(stepFinish.usage).toBeUndefined()
387
- })
388
-
389
- test("reuses adapter state cleanly across streams once finish has fired", async () => {
390
- // adapterState() is meant to be per-stream, but the only thing finish currently clears
391
- // is toolNames — step, text counters, and the current text/reasoning IDs all leak
392
- // forward. A caller that reuses a state across two streams sees text-1/reasoning-1/
393
- // step index 1 on the second stream's first events. The test pins the intended
394
- // contract: after finish, the same state can be reused and starts fresh.
395
- const state = LLMAISDK.adapterState()
396
- const run = (events: ReadonlyArray<AISDKAdapterEvent>) =>
397
- Effect.runPromise(
398
- Effect.forEach(events, (event) => LLMAISDK.toLLMEvents(state, event)).pipe(Effect.map((items) => items.flat())),
399
- )
400
-
401
- await run([
402
- { type: "start-step", request: {}, warnings: [] },
403
- uncheckedAdapterEvent({ type: "text-delta", text: "first" }),
404
- uncheckedAdapterEvent({ type: "text-end" }),
405
- uncheckedAdapterEvent({ type: "reasoning-delta", text: "first reasoning" }),
406
- uncheckedAdapterEvent({ type: "reasoning-end" }),
407
- {
408
- type: "finish-step",
409
- response: { id: "r1", timestamp: new Date(0), modelId: "gpt-test" },
410
- finishReason: "stop",
411
- rawFinishReason: "stop",
412
- providerMetadata: undefined,
413
- usage: {
414
- inputTokens: 1,
415
- outputTokens: 1,
416
- totalTokens: 2,
417
- inputTokenDetails: { noCacheTokens: undefined, cacheReadTokens: undefined, cacheWriteTokens: undefined },
418
- outputTokenDetails: { textTokens: undefined, reasoningTokens: undefined },
419
- },
420
- },
421
- {
422
- type: "finish",
423
- finishReason: "stop",
424
- rawFinishReason: "stop",
425
- totalUsage: {
426
- inputTokens: 1,
427
- outputTokens: 1,
428
- totalTokens: 2,
429
- inputTokenDetails: { noCacheTokens: undefined, cacheReadTokens: undefined, cacheWriteTokens: undefined },
430
- outputTokenDetails: { textTokens: undefined, reasoningTokens: undefined },
431
- },
432
- },
433
- ])
434
-
435
- const secondStream = await run([
436
- { type: "start-step", request: {}, warnings: [] },
437
- uncheckedAdapterEvent({ type: "text-delta", text: "second" }),
438
- uncheckedAdapterEvent({ type: "text-end" }),
439
- uncheckedAdapterEvent({ type: "reasoning-delta", text: "second reasoning" }),
440
- uncheckedAdapterEvent({ type: "reasoning-end" }),
441
- ])
442
-
443
- expect(secondStream).toMatchObject([
444
- { type: "step-start", index: 0 },
445
- { type: "text-delta", id: "text-0", text: "second" },
446
- { type: "text-end", id: "text-0" },
447
- { type: "reasoning-delta", id: "reasoning-0", text: "second reasoning" },
448
- { type: "reasoning-end", id: "reasoning-0" },
449
- ])
450
- })
451
-
452
- // Anthropic emits cache write counts in providerMetadata.anthropic.cacheCreationInputTokens
453
- // rather than usage.inputTokenDetails.cacheWriteTokens. Session.getUsage falls back to the
454
- // metadata path — but only if the adapter preserves providerMetadata on step-finish.
455
- test("preserves providerMetadata on step-finish so Anthropic cache writes survive getUsage", async () => {
456
- const events = await adapt([
457
- {
458
- type: "finish-step",
459
- response: { id: "msg_test", timestamp: new Date(0), modelId: "claude-3-5-sonnet" },
460
- finishReason: "stop",
461
- rawFinishReason: "stop",
462
- // Anthropic's AI SDK shape: cacheWriteTokens is NOT in usage, it arrives via providerMetadata.
463
- usage: {
464
- inputTokens: 1000,
465
- outputTokens: 500,
466
- totalTokens: 1500,
467
- inputTokenDetails: { noCacheTokens: 800, cacheReadTokens: 200, cacheWriteTokens: undefined },
468
- outputTokenDetails: { textTokens: 500, reasoningTokens: undefined },
469
- },
470
- providerMetadata: { anthropic: { cacheCreationInputTokens: 300 } },
471
- },
472
- ])
473
-
474
- expect(events).toHaveLength(1)
475
- const stepFinish = events[0]
476
- if (stepFinish.type !== "step-finish") throw new Error("expected step-finish")
477
- expect(stepFinish.providerMetadata).toEqual({ anthropic: { cacheCreationInputTokens: 300 } })
478
- expect(stepFinish.usage?.cacheWriteInputTokens).toBeUndefined()
479
- expect(stepFinish.usage?.cacheReadInputTokens).toBe(200)
480
-
481
- // End-to-end: with the metadata preserved, getUsage extracts cache.write from the fallback path.
482
- const result = SessionNs.getUsage({
483
- model: {
484
- id: "claude-3-5-sonnet",
485
- providerID: "anthropic",
486
- name: "Claude",
487
- limit: { context: 200_000, output: 8_000 },
488
- cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
489
- capabilities: {
490
- toolcall: true,
491
- attachment: false,
492
- reasoning: false,
493
- temperature: true,
494
- input: { text: true, image: false, audio: false, video: false },
495
- output: { text: true, image: false, audio: false, video: false },
496
- },
497
- api: { npm: "@ai-sdk/anthropic" },
498
- options: {},
499
- } as never,
500
- usage: stepFinish.usage!,
501
- metadata: stepFinish.providerMetadata,
502
- })
503
- expect(result.tokens.cache.write).toBe(300)
504
- expect(result.tokens.cache.read).toBe(200)
505
- })
506
-
507
- test("captures Copilot billed usage from raw Anthropic message deltas per step", async () => {
508
- const events = await adapt([
509
- uncheckedAdapterEvent({
510
- type: "raw",
511
- rawValue: {
512
- type: "message_delta",
513
- copilot_usage: { total_nano_aiu: 4_473_525_000 },
514
- },
515
- }),
516
- {
517
- type: "finish-step",
518
- response: { id: "msg_test", timestamp: new Date(0), modelId: "claude-sonnet-4.6" },
519
- finishReason: "stop",
520
- rawFinishReason: "end_turn",
521
- usage: {
522
- inputTokens: 11_774,
523
- outputTokens: 39,
524
- totalTokens: 11_813,
525
- inputTokenDetails: { noCacheTokens: 3, cacheReadTokens: 0, cacheWriteTokens: 11_771 },
526
- outputTokenDetails: { textTokens: 39, reasoningTokens: undefined },
527
- },
528
- providerMetadata: { anthropic: { cacheCreationInputTokens: 11_771 } },
529
- },
530
- {
531
- type: "finish-step",
532
- response: { id: "msg_follow_up", timestamp: new Date(0), modelId: "claude-sonnet-4.6" },
533
- finishReason: "stop",
534
- rawFinishReason: "end_turn",
535
- usage: {
536
- inputTokens: 1,
537
- outputTokens: 1,
538
- totalTokens: 2,
539
- inputTokenDetails: { noCacheTokens: 1, cacheReadTokens: 0, cacheWriteTokens: 0 },
540
- outputTokenDetails: { textTokens: 1, reasoningTokens: undefined },
541
- },
542
- providerMetadata: { anthropic: {} },
543
- },
544
- ])
545
-
546
- expect(events[0]).toMatchObject({
547
- type: "step-finish",
548
- providerMetadata: {
549
- anthropic: { cacheCreationInputTokens: 11_771 },
550
- copilot: { totalNanoAiu: 4_473_525_000 },
551
- },
552
- })
553
- expect(events[1]).toMatchObject({ type: "step-finish", providerMetadata: { anthropic: {} } })
554
- if (events[1].type !== "step-finish") throw new Error("expected step-finish")
555
- expect(events[1].providerMetadata?.copilot).toBeUndefined()
556
- })
557
- })
558
-
559
- type Capture = {
560
- url: URL
561
- headers: Headers
562
- body: Record<string, unknown>
563
- }
564
-
565
- const state = {
566
- server: null as ReturnType<typeof Bun.serve> | null,
567
- queue: [] as Array<{
568
- path: string
569
- response: Response | ((req: Request, capture: Capture) => Response)
570
- resolve: (value: Capture) => void
571
- }>,
572
- }
573
-
574
- function deferred<T>() {
575
- const result = {} as { promise: Promise<T>; resolve: (value: T) => void }
576
- result.promise = new Promise((resolve) => {
577
- result.resolve = resolve
578
- })
579
- return result
580
- }
581
-
582
- function waitRequest(pathname: string, response: Response) {
583
- const pending = deferred<Capture>()
584
- state.queue.push({ path: pathname, response, resolve: pending.resolve })
585
- return pending.promise
586
- }
587
-
588
- function timeout(ms: number) {
589
- return new Promise<never>((_, reject) => {
590
- setTimeout(() => reject(new Error(`timed out after ${ms}ms`)), ms)
591
- })
592
- }
593
-
594
- function waitStreamingRequest(pathname: string) {
595
- const request = deferred<Capture>()
596
- const requestAborted = deferred<void>()
597
- const responseCanceled = deferred<void>()
598
- const encoder = new TextEncoder()
599
-
600
- state.queue.push({
601
- path: pathname,
602
- resolve: request.resolve,
603
- response(req: Request) {
604
- req.signal.addEventListener("abort", () => requestAborted.resolve(), { once: true })
605
-
606
- return new Response(
607
- new ReadableStream<Uint8Array>({
608
- start(controller) {
609
- controller.enqueue(
610
- encoder.encode(
611
- [
612
- `data: ${JSON.stringify({
613
- id: "chatcmpl-abort",
614
- object: "chat.completion.chunk",
615
- choices: [{ delta: { role: "assistant" } }],
616
- })}`,
617
- ].join("\n\n") + "\n\n",
618
- ),
619
- )
620
- },
621
- cancel() {
622
- responseCanceled.resolve()
623
- },
624
- }),
625
- {
626
- status: 200,
627
- headers: { "Content-Type": "text/event-stream" },
628
- },
629
- )
630
- },
631
- })
632
-
633
- return {
634
- request: request.promise,
635
- requestAborted: requestAborted.promise,
636
- responseCanceled: responseCanceled.promise,
637
- }
638
- }
639
-
640
- beforeAll(() => {
641
- state.server = Bun.serve({
642
- port: 0,
643
- async fetch(req) {
644
- const next = state.queue.shift()
645
- if (!next) {
646
- return new Response("unexpected request", { status: 500 })
647
- }
648
-
649
- const url = new URL(req.url)
650
- const body = (await req.json()) as Record<string, unknown>
651
- next.resolve({ url, headers: req.headers, body })
652
-
653
- if (!url.pathname.endsWith(next.path)) {
654
- return new Response("not found", { status: 404 })
655
- }
656
-
657
- return typeof next.response === "function"
658
- ? next.response(req, { url, headers: req.headers, body })
659
- : next.response
660
- },
661
- })
662
- })
663
-
664
- beforeEach(() => {
665
- state.queue.length = 0
666
- })
667
-
668
- afterAll(() => {
669
- void state.server?.stop()
670
- })
671
-
672
- function createChatStream(text: string) {
673
- const payload =
674
- [
675
- `data: ${JSON.stringify({
676
- id: "chatcmpl-1",
677
- object: "chat.completion.chunk",
678
- choices: [{ delta: { role: "assistant" } }],
679
- })}`,
680
- `data: ${JSON.stringify({
681
- id: "chatcmpl-1",
682
- object: "chat.completion.chunk",
683
- choices: [{ delta: { content: text } }],
684
- })}`,
685
- `data: ${JSON.stringify({
686
- id: "chatcmpl-1",
687
- object: "chat.completion.chunk",
688
- choices: [{ delta: {}, finish_reason: "stop" }],
689
- })}`,
690
- "data: [DONE]",
691
- ].join("\n\n") + "\n\n"
692
-
693
- const encoder = new TextEncoder()
694
- return new ReadableStream<Uint8Array>({
695
- start(controller) {
696
- controller.enqueue(encoder.encode(payload))
697
- controller.close()
698
- },
699
- })
700
- }
701
-
702
- const MODELS_FIXTURE = JSON.parse(
703
- await Bun.file(path.join(import.meta.dir, "../tool/fixtures/models-api.json")).text(),
704
- ) as Record<string, ModelsDev.Provider>
705
-
706
- function loadFixture(providerID: string, modelID: string) {
707
- const provider = MODELS_FIXTURE[providerID]
708
- if (!provider) throw new Error(`Missing provider in fixture: ${providerID}`)
709
- const model = provider.models[modelID]
710
- if (!model) throw new Error(`Missing model in fixture: ${modelID}`)
711
- return { provider, model }
712
- }
713
-
714
- function configModel(model: ModelsDev.Model) {
715
- return {
716
- id: model.id,
717
- name: model.name,
718
- family: model.family,
719
- release_date: model.release_date,
720
- attachment: model.attachment,
721
- reasoning: model.reasoning,
722
- temperature: model.temperature,
723
- tool_call: model.tool_call,
724
- interleaved: model.interleaved,
725
- cost: model.cost ? { ...model.cost, tiers: undefined } : undefined,
726
- limit: model.limit,
727
- modalities: model.modalities,
728
- status: model.status,
729
- provider: model.provider,
730
- }
731
- }
732
-
733
- function createEventStream(chunks: unknown[], includeDone = false) {
734
- const lines = chunks.map((chunk) => `data: ${typeof chunk === "string" ? chunk : JSON.stringify(chunk)}`)
735
- if (includeDone) {
736
- lines.push("data: [DONE]")
737
- }
738
- const payload = lines.join("\n\n") + "\n\n"
739
- const encoder = new TextEncoder()
740
- return new ReadableStream<Uint8Array>({
741
- start(controller) {
742
- controller.enqueue(encoder.encode(payload))
743
- controller.close()
744
- },
745
- })
746
- }
747
-
748
- function createEventResponse(chunks: unknown[], includeDone = false) {
749
- return new Response(createEventStream(chunks, includeDone), {
750
- status: 200,
751
- headers: { "Content-Type": "text/event-stream" },
752
- })
753
- }
754
-
755
- describe("session.llm.stream", () => {
756
- const vivgridFixture = { providerID: "vivgrid", modelID: "gemini-3.1-pro-preview" }
757
- it.instance(
758
- "sends temperature, tokens, and reasoning options for openai-compatible models",
759
- () =>
760
- Effect.gen(function* () {
761
- const fixture = loadFixture(vivgridFixture.providerID, vivgridFixture.modelID)
762
- const request = waitRequest(
763
- "/chat/completions",
764
- new Response(createChatStream("Hello"), {
765
- status: 200,
766
- headers: { "Content-Type": "text/event-stream" },
767
- }),
768
- )
769
-
770
- const resolved = yield* Provider.use.getModel(
771
- ProviderV2.ID.make(vivgridFixture.providerID),
772
- ModelV2.ID.make(fixture.model.id),
773
- )
774
- const sessionID = SessionID.make("session-test-1")
775
- const agent = {
776
- name: "test",
777
- mode: "primary",
778
- options: {},
779
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
780
- temperature: 0.4,
781
- topP: 0.8,
782
- } satisfies Agent.Info
783
-
784
- const user = {
785
- id: MessageID.make("msg_user-1"),
786
- sessionID,
787
- role: "user",
788
- time: { created: Date.now() },
789
- agent: agent.name,
790
- model: { providerID: ProviderV2.ID.make(vivgridFixture.providerID), modelID: resolved.id, variant: "high" },
791
- } satisfies SessionV1.User
792
-
793
- yield* drain({
794
- user,
795
- sessionID,
796
- model: resolved,
797
- agent,
798
- system: ["You are a helpful assistant."],
799
- messages: [{ role: "user", content: "Hello" }],
800
- tools: {},
801
- })
802
-
803
- const capture = yield* Effect.promise(() => request)
804
- const body = capture.body
805
- const headers = capture.headers
806
- const url = capture.url
807
-
808
- expect(url.pathname.startsWith("/v1/")).toBe(true)
809
- expect(url.pathname.endsWith("/chat/completions")).toBe(true)
810
- expect(headers.get("Authorization")).toBe("Bearer test-key")
811
-
812
- expect(body.model).toBe(resolved.api.id)
813
- expect(body.temperature).toBe(0.4)
814
- expect(body.top_p).toBe(0.8)
815
- expect(body.stream).toBe(true)
816
-
817
- const maxTokens = (body.max_tokens as number | undefined) ?? (body.max_output_tokens as number | undefined)
818
- const expectedMaxTokens = ProviderTransform.maxOutputTokens(resolved)
819
- expect(maxTokens).toBe(expectedMaxTokens)
820
-
821
- const reasoning = (body.reasoningEffort as string | undefined) ?? (body.reasoning_effort as string | undefined)
822
- expect(reasoning).toBe("high")
823
- }),
824
- {
825
- config: () => ({
826
- enabled_providers: [vivgridFixture.providerID],
827
- provider: {
828
- [vivgridFixture.providerID]: {
829
- options: { apiKey: "test-key", baseURL: `${state.server!.url.origin}/v1` },
830
- },
831
- },
832
- }),
833
- },
834
- )
835
-
836
- const alibabaQwenFixture = { providerID: "alibaba", modelID: "qwen-plus" }
837
- it.instance(
838
- "service stream cancellation cancels provider response body promptly",
839
- () =>
840
- Effect.gen(function* () {
841
- const fixture = loadFixture(alibabaQwenFixture.providerID, alibabaQwenFixture.modelID)
842
- const pending = waitStreamingRequest("/chat/completions")
843
-
844
- const resolved = yield* Provider.use.getModel(
845
- ProviderV2.ID.make(alibabaQwenFixture.providerID),
846
- ModelV2.ID.make(fixture.model.id),
847
- )
848
- const sessionID = SessionID.make("session-test-service-abort")
849
- const agent = {
850
- name: "test",
851
- mode: "primary",
852
- options: {},
853
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
854
- } satisfies Agent.Info
855
- const user = {
856
- id: MessageID.make("msg_user-service-abort"),
857
- sessionID,
858
- role: "user",
859
- time: { created: Date.now() },
860
- agent: agent.name,
861
- model: { providerID: ProviderV2.ID.make(alibabaQwenFixture.providerID), modelID: resolved.id },
862
- } satisfies SessionV1.User
863
-
864
- const fiber = yield* drain({
865
- user,
866
- sessionID,
867
- model: resolved,
868
- agent,
869
- system: ["You are a helpful assistant."],
870
- messages: [{ role: "user", content: "Hello" }],
871
- tools: {},
872
- }).pipe(Effect.exit, Effect.forkScoped)
873
-
874
- yield* Effect.promise(() => pending.request)
875
- yield* Fiber.interrupt(fiber)
876
-
877
- yield* Effect.promise(() => Promise.race([pending.responseCanceled, timeout(500)]))
878
- const exit = yield* Fiber.await(fiber)
879
- // Fiber.await returns an Exit<Exit<...>>. Unwrap once.
880
- const inner = Exit.isSuccess(exit) ? exit.value : exit
881
- expect(Exit.isFailure(inner)).toBe(true)
882
- if (Exit.isFailure(inner)) {
883
- expect(Cause.hasInterrupts(inner.cause)).toBe(true)
884
- }
885
- yield* Effect.promise(() => Promise.race([pending.requestAborted, timeout(500)]).catch(() => undefined))
886
- }),
887
- {
888
- config: () => ({
889
- enabled_providers: [alibabaQwenFixture.providerID],
890
- provider: {
891
- [alibabaQwenFixture.providerID]: {
892
- options: { apiKey: "test-key", baseURL: `${state.server!.url.origin}/v1` },
893
- },
894
- },
895
- }),
896
- },
897
- )
898
-
899
- it.instance(
900
- "keeps tools enabled by prompt permissions",
901
- () =>
902
- Effect.gen(function* () {
903
- const fixture = loadFixture(alibabaQwenFixture.providerID, alibabaQwenFixture.modelID)
904
- const request = waitRequest(
905
- "/chat/completions",
906
- new Response(createChatStream("Hello"), {
907
- status: 200,
908
- headers: { "Content-Type": "text/event-stream" },
909
- }),
910
- )
911
-
912
- const resolved = yield* Provider.use.getModel(
913
- ProviderV2.ID.make(alibabaQwenFixture.providerID),
914
- ModelV2.ID.make(fixture.model.id),
915
- )
916
- const sessionID = SessionID.make("session-test-tools")
917
- const agent = {
918
- name: "test",
919
- mode: "primary",
920
- options: {},
921
- permission: [{ permission: "question", pattern: "*", action: "deny" }],
922
- } satisfies Agent.Info
923
-
924
- const user = {
925
- id: MessageID.make("msg_user-tools"),
926
- sessionID,
927
- role: "user",
928
- time: { created: Date.now() },
929
- agent: agent.name,
930
- model: { providerID: ProviderV2.ID.make(alibabaQwenFixture.providerID), modelID: resolved.id },
931
- tools: { question: true },
932
- } satisfies SessionV1.User
933
-
934
- yield* drain({
935
- user,
936
- sessionID,
937
- model: resolved,
938
- agent,
939
- permission: [{ permission: "question", pattern: "*", action: "allow" }],
940
- system: ["You are a helpful assistant."],
941
- messages: [{ role: "user", content: "Hello" }],
942
- tools: {
943
- question: tool({
944
- description: "Ask a question",
945
- inputSchema: z.object({}),
946
- execute: async () => ({ output: "" }),
947
- }),
948
- },
949
- })
950
-
951
- const capture = yield* Effect.promise(() => request)
952
- const tools = capture.body.tools as Array<{ function?: { name?: string } }> | undefined
953
- expect(tools?.some((item) => item.function?.name === "question")).toBe(true)
954
- }),
955
- {
956
- config: () => ({
957
- enabled_providers: [alibabaQwenFixture.providerID],
958
- provider: {
959
- [alibabaQwenFixture.providerID]: {
960
- options: { apiKey: "test-key", baseURL: `${state.server!.url.origin}/v1` },
961
- },
962
- },
963
- }),
964
- },
965
- )
966
-
967
- it.instance(
968
- "sends responses API payload for OpenAI models",
969
- () =>
970
- Effect.gen(function* () {
971
- const model = loadFixture("openai", "gpt-5.2").model
972
-
973
- const responseChunks = [
974
- {
975
- type: "response.created",
976
- response: {
977
- id: "resp-1",
978
- created_at: Math.floor(Date.now() / 1000),
979
- model: model.id,
980
- service_tier: null,
981
- },
982
- },
983
- {
984
- type: "response.output_item.added",
985
- output_index: 0,
986
- item: { type: "message", id: "item-1", status: "in_progress", role: "assistant", content: [] },
987
- },
988
- {
989
- type: "response.content_part.added",
990
- item_id: "item-1",
991
- output_index: 0,
992
- content_index: 0,
993
- part: { type: "output_text", text: "", annotations: [] },
994
- },
995
- {
996
- type: "response.output_text.delta",
997
- item_id: "item-1",
998
- delta: "Hello",
999
- logprobs: null,
1000
- },
1001
- {
1002
- type: "response.completed",
1003
- response: {
1004
- incomplete_details: null,
1005
- usage: {
1006
- input_tokens: 1,
1007
- input_tokens_details: null,
1008
- output_tokens: 1,
1009
- output_tokens_details: null,
1010
- },
1011
- service_tier: null,
1012
- },
1013
- },
1014
- ]
1015
- const request = waitRequest("/responses", createEventResponse(responseChunks, true))
1016
-
1017
- const resolved = yield* Provider.use.getModel(ProviderV2.ID.openai, ModelV2.ID.make(model.id))
1018
- const sessionID = SessionID.make("session-test-2")
1019
- const agent = {
1020
- name: "test",
1021
- mode: "primary",
1022
- options: {},
1023
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1024
- temperature: 0.2,
1025
- } satisfies Agent.Info
1026
-
1027
- const user = {
1028
- id: MessageID.make("msg_user-2"),
1029
- sessionID,
1030
- role: "user",
1031
- time: { created: Date.now() },
1032
- agent: agent.name,
1033
- model: { providerID: ProviderV2.ID.make("openai"), modelID: resolved.id, variant: "high" },
1034
- } satisfies SessionV1.User
1035
-
1036
- yield* drain({
1037
- user,
1038
- sessionID,
1039
- model: resolved,
1040
- agent,
1041
- system: ["You are a helpful assistant."],
1042
- messages: [{ role: "user", content: "Hello" }],
1043
- tools: {},
1044
- })
1045
-
1046
- const capture = yield* Effect.promise(() => request)
1047
- const body = capture.body
1048
-
1049
- expect(capture.url.pathname.endsWith("/responses")).toBe(true)
1050
- expect(body.model).toBe(resolved.api.id)
1051
- expect(body.stream).toBe(true)
1052
- expect((body.reasoning as { effort?: string } | undefined)?.effort).toBe("high")
1053
-
1054
- const maxTokens = body.max_output_tokens as number | undefined
1055
- expect(maxTokens).toBe(undefined) // match codex cli behavior
1056
- }),
1057
- { config: () => openAIConfig(loadFixture("openai", "gpt-5.2").model, `${state.server!.url.origin}/v1`) },
1058
- )
1059
-
1060
- it.instance(
1061
- "keeps supported OpenAI models on AI SDK path when native flag is off",
1062
- () =>
1063
- Effect.gen(function* () {
1064
- const model = loadFixture("openai", "gpt-5.2").model
1065
- const request = waitRequest(
1066
- "/responses",
1067
- createEventResponse(
1068
- [
1069
- {
1070
- type: "response.created",
1071
- response: {
1072
- id: "resp-flag-off",
1073
- created_at: Math.floor(Date.now() / 1000),
1074
- model: model.id,
1075
- service_tier: null,
1076
- },
1077
- },
1078
- {
1079
- type: "response.output_item.added",
1080
- output_index: 0,
1081
- item: { type: "message", id: "item-flag-off", status: "in_progress", role: "assistant", content: [] },
1082
- },
1083
- {
1084
- type: "response.content_part.added",
1085
- item_id: "item-flag-off",
1086
- output_index: 0,
1087
- content_index: 0,
1088
- part: { type: "output_text", text: "", annotations: [] },
1089
- },
1090
- {
1091
- type: "response.output_text.delta",
1092
- item_id: "item-flag-off",
1093
- delta: "Flag off",
1094
- logprobs: null,
1095
- },
1096
- {
1097
- type: "response.completed",
1098
- response: {
1099
- incomplete_details: null,
1100
- usage: {
1101
- input_tokens: 1,
1102
- input_tokens_details: null,
1103
- output_tokens: 1,
1104
- output_tokens_details: null,
1105
- },
1106
- service_tier: null,
1107
- },
1108
- },
1109
- ],
1110
- true,
1111
- ),
1112
- )
1113
- const failingNativeClient = Layer.succeed(
1114
- LLMClient.Service,
1115
- LLMClient.Service.of({
1116
- prepare: () => Effect.die(new Error("native LLM client should not be used when the flag is off")),
1117
- stream: () => Stream.die(new Error("native LLM client should not be used when the flag is off")),
1118
- generate: () => Effect.die(new Error("native LLM client should not be used when the flag is off")),
1119
- }),
1120
- )
1121
-
1122
- const resolved = yield* Provider.use.getModel(ProviderV2.ID.openai, ModelV2.ID.make(model.id))
1123
- const sessionID = SessionID.make("session-test-native-flag-off")
1124
- const agent = {
1125
- name: "test",
1126
- mode: "primary",
1127
- options: {},
1128
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1129
- } satisfies Agent.Info
1130
-
1131
- yield* drainWith(
1132
- LLM.layer.pipe(
1133
- Layer.provide(Auth.defaultLayer),
1134
- Layer.provide(Config.defaultLayer),
1135
- Layer.provide(Provider.defaultLayer),
1136
- Layer.provide(Plugin.defaultLayer),
1137
- Layer.provide(failingNativeClient),
1138
- Layer.provide(RuntimeFlags.layer({ experimentalNativeLlm: false })),
1139
- ),
1140
- {
1141
- user: {
1142
- id: MessageID.make("msg_user-native-flag-off"),
1143
- sessionID,
1144
- role: "user",
1145
- time: { created: Date.now() },
1146
- agent: agent.name,
1147
- model: { providerID: ProviderV2.ID.make("openai"), modelID: resolved.id, variant: "high" },
1148
- } satisfies SessionV1.User,
1149
- sessionID,
1150
- model: resolved,
1151
- agent,
1152
- system: ["You are a helpful assistant."],
1153
- messages: [{ role: "user", content: "Hello" }],
1154
- tools: {},
1155
- },
1156
- )
1157
-
1158
- const capture = yield* Effect.promise(() => request)
1159
- expect(capture.url.pathname.endsWith("/responses")).toBe(true)
1160
- expect(capture.body.model).toBe(resolved.api.id)
1161
- }),
1162
- { config: () => openAIConfig(loadFixture("openai", "gpt-5.2").model, `${state.server!.url.origin}/v1`) },
1163
- )
1164
-
1165
- it.instance(
1166
- "streams OpenAI through native runtime when opted in",
1167
- () =>
1168
- Effect.gen(function* () {
1169
- const model = loadFixture("openai", "gpt-5.2").model
1170
- const chunks = [
1171
- { type: "response.created", response: { id: "resp-native" } },
1172
- {
1173
- type: "response.output_item.added",
1174
- item: { type: "message", id: "item-native", status: "in_progress" },
1175
- },
1176
- { type: "response.output_text.delta", item_id: "item-native", delta: "Hello native" },
1177
- {
1178
- type: "response.completed",
1179
- response: {
1180
- incomplete_details: null,
1181
- usage: {
1182
- input_tokens: 1,
1183
- input_tokens_details: null,
1184
- output_tokens: 1,
1185
- output_tokens_details: null,
1186
- },
1187
- },
1188
- },
1189
- ]
1190
- const request = waitRequest("/responses", createEventResponse(chunks, true))
1191
-
1192
- const resolved = yield* Provider.use.getModel(ProviderV2.ID.openai, ModelV2.ID.make(model.id))
1193
- const sessionID = SessionID.make("session-test-native")
1194
- const agent = {
1195
- name: "test",
1196
- mode: "primary",
1197
- options: {},
1198
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1199
- temperature: 0.2,
1200
- } satisfies Agent.Info
1201
-
1202
- yield* drainWith(llmLayerWithExecutor(RequestExecutor.defaultLayer, { experimentalNativeLlm: true }), {
1203
- user: {
1204
- id: MessageID.make("msg_user-native"),
1205
- sessionID,
1206
- role: "user",
1207
- time: { created: Date.now() },
1208
- agent: agent.name,
1209
- model: { providerID: ProviderV2.ID.make("openai"), modelID: resolved.id, variant: "high" },
1210
- } satisfies SessionV1.User,
1211
- sessionID,
1212
- model: resolved,
1213
- agent,
1214
- system: ["You are a helpful assistant."],
1215
- messages: [{ role: "user", content: "Hello" }],
1216
- tools: {},
1217
- })
1218
-
1219
- const capture = yield* Effect.promise(() => request)
1220
- expect(capture.url.pathname.endsWith("/responses")).toBe(true)
1221
- expect(capture.headers.get("Authorization")).toBe("Bearer test-openai-key")
1222
- expect(capture.body.model).toBe(model.id)
1223
- expect(capture.body.stream).toBe(true)
1224
- expect((capture.body.reasoning as { effort?: string } | undefined)?.effort).toBe("high")
1225
- expect(capture.body.include).toEqual(["reasoning.encrypted_content"])
1226
- expect(JSON.stringify(capture.body.input)).toContain("You are a helpful assistant.")
1227
- expect(capture.body.input).toContainEqual({ role: "user", content: [{ type: "input_text", text: "Hello" }] })
1228
- }),
1229
- { config: () => openAIConfig(loadFixture("openai", "gpt-5.2").model, `${state.server!.url.origin}/v1`) },
1230
- )
1231
-
1232
- it.instance(
1233
- "uses injected native request executor for tool calls",
1234
- () =>
1235
- Effect.gen(function* () {
1236
- const model = loadFixture("openai", "gpt-5.2").model
1237
- const chunks = [
1238
- {
1239
- type: "response.output_item.added",
1240
- item: { type: "function_call", id: "item-injected-tool", call_id: "call-injected-tool", name: "lookup" },
1241
- },
1242
- {
1243
- type: "response.function_call_arguments.delta",
1244
- item_id: "item-injected-tool",
1245
- delta: '{"query":"weather"}',
1246
- },
1247
- {
1248
- type: "response.output_item.done",
1249
- item: {
1250
- type: "function_call",
1251
- id: "item-injected-tool",
1252
- call_id: "call-injected-tool",
1253
- name: "lookup",
1254
- arguments: '{"query":"weather"}',
1255
- },
1256
- },
1257
- {
1258
- type: "response.completed",
1259
- response: { incomplete_details: null, usage: { input_tokens: 1, output_tokens: 1 } },
1260
- },
1261
- ]
1262
- let captured: Record<string, unknown> | undefined
1263
- let executed: unknown
1264
- const executor = Layer.succeed(
1265
- RequestExecutor.Service,
1266
- RequestExecutor.Service.of({
1267
- execute: (request) =>
1268
- Effect.gen(function* () {
1269
- const web = yield* HttpClientRequest.toWeb(request).pipe(Effect.orDie)
1270
- captured = (yield* Effect.promise(() => web.json())) as Record<string, unknown>
1271
- return HttpClientResponse.fromWeb(request, createEventResponse(chunks, true))
1272
- }),
1273
- }),
1274
- )
1275
-
1276
- const resolved = yield* Provider.use.getModel(ProviderV2.ID.openai, ModelV2.ID.make(model.id))
1277
- const sessionID = SessionID.make("session-test-native-injected-tool")
1278
- const agent = {
1279
- name: "test",
1280
- mode: "primary",
1281
- options: {},
1282
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1283
- } satisfies Agent.Info
1284
-
1285
- yield* drainWith(llmLayerWithExecutor(executor, { experimentalNativeLlm: true }), {
1286
- user: {
1287
- id: MessageID.make("msg_user-native-injected-tool"),
1288
- sessionID,
1289
- role: "user",
1290
- time: { created: Date.now() },
1291
- agent: agent.name,
1292
- model: { providerID: ProviderV2.ID.make("openai"), modelID: resolved.id },
1293
- } satisfies SessionV1.User,
1294
- sessionID,
1295
- model: resolved,
1296
- agent,
1297
- system: [],
1298
- messages: [{ role: "user", content: "Use lookup" }],
1299
- tools: {
1300
- lookup: tool({
1301
- description: "Lookup data",
1302
- inputSchema: z.object({ query: z.string() }),
1303
- execute: async (args, options) => {
1304
- executed = { args, toolCallId: options.toolCallId }
1305
- return { output: "looked up" }
1306
- },
1307
- }),
1308
- },
1309
- })
1310
-
1311
- expect(captured?.model).toBe(model.id)
1312
- expect(captured?.tools).toEqual([
1313
- {
1314
- type: "function",
1315
- name: "lookup",
1316
- description: "Lookup data",
1317
- parameters: {
1318
- type: "object",
1319
- properties: { query: { type: "string" } },
1320
- required: ["query"],
1321
- additionalProperties: false,
1322
- $schema: "http://json-schema.org/draft-07/schema#",
1323
- },
1324
- },
1325
- ])
1326
- expect(executed).toEqual({ args: { query: "weather" }, toolCallId: "call-injected-tool" })
1327
- }),
1328
- { config: () => openAIConfig(loadFixture("openai", "gpt-5.2").model, "https://injected-openai.test/v1") },
1329
- )
1330
-
1331
- it.instance(
1332
- "executes OpenAI tool calls through native runtime",
1333
- () =>
1334
- Effect.gen(function* () {
1335
- const model = loadFixture("openai", "gpt-5.2").model
1336
- const chunks = [
1337
- {
1338
- type: "response.output_item.added",
1339
- item: { type: "function_call", id: "item-native-tool", call_id: "call-native-tool", name: "lookup" },
1340
- },
1341
- {
1342
- type: "response.function_call_arguments.delta",
1343
- item_id: "item-native-tool",
1344
- delta: '{"query":"weather"}',
1345
- },
1346
- {
1347
- type: "response.output_item.done",
1348
- item: {
1349
- type: "function_call",
1350
- id: "item-native-tool",
1351
- call_id: "call-native-tool",
1352
- name: "lookup",
1353
- arguments: '{"query":"weather"}',
1354
- },
1355
- },
1356
- {
1357
- type: "response.completed",
1358
- response: { incomplete_details: null, usage: { input_tokens: 1, output_tokens: 1 } },
1359
- },
1360
- ]
1361
- const request = waitRequest("/responses", createEventResponse(chunks, true))
1362
- let executed: unknown
1363
-
1364
- const resolved = yield* Provider.use.getModel(ProviderV2.ID.openai, ModelV2.ID.make(model.id))
1365
- const sessionID = SessionID.make("session-test-native-tool")
1366
- const agent = {
1367
- name: "test",
1368
- mode: "primary",
1369
- options: {},
1370
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1371
- } satisfies Agent.Info
1372
-
1373
- yield* drainWith(llmLayerWithExecutor(RequestExecutor.defaultLayer, { experimentalNativeLlm: true }), {
1374
- user: {
1375
- id: MessageID.make("msg_user-native-tool"),
1376
- sessionID,
1377
- role: "user",
1378
- time: { created: Date.now() },
1379
- agent: agent.name,
1380
- model: { providerID: ProviderV2.ID.make("openai"), modelID: resolved.id },
1381
- } satisfies SessionV1.User,
1382
- sessionID,
1383
- model: resolved,
1384
- agent,
1385
- system: [],
1386
- messages: [{ role: "user", content: "Use lookup" }],
1387
- tools: {
1388
- lookup: tool({
1389
- description: "Lookup data",
1390
- inputSchema: z.object({ query: z.string() }),
1391
- execute: async (args, options) => {
1392
- executed = { args, toolCallId: options.toolCallId }
1393
- return { output: "looked up" }
1394
- },
1395
- }),
1396
- },
1397
- })
1398
-
1399
- const capture = yield* Effect.promise(() => request)
1400
- expect(capture.body.tools).toEqual([
1401
- {
1402
- type: "function",
1403
- name: "lookup",
1404
- description: "Lookup data",
1405
- parameters: {
1406
- type: "object",
1407
- properties: { query: { type: "string" } },
1408
- required: ["query"],
1409
- additionalProperties: false,
1410
- $schema: "http://json-schema.org/draft-07/schema#",
1411
- },
1412
- },
1413
- ])
1414
- expect(executed).toEqual({ args: { query: "weather" }, toolCallId: "call-native-tool" })
1415
- }),
1416
- {
1417
- config: () => {
1418
- const model = loadFixture("openai", "gpt-5.2").model
1419
- return {
1420
- enabled_providers: ["openai"],
1421
- provider: {
1422
- openai: {
1423
- name: "OpenAI",
1424
- env: ["OPENAI_API_KEY"],
1425
- npm: "@ai-sdk/openai",
1426
- api: "https://api.openai.com/v1",
1427
- models: { [model.id]: JSON.parse(JSON.stringify(model)) as ConfigModel },
1428
- options: { apiKey: "test-openai-key", baseURL: `${state.server!.url.origin}/v1` },
1429
- },
1430
- },
1431
- }
1432
- },
1433
- },
1434
- )
1435
-
1436
- it.instance(
1437
- "accepts user image attachments as data URLs for OpenAI models",
1438
- () =>
1439
- Effect.gen(function* () {
1440
- const model = loadFixture("openai", "gpt-5.2").model
1441
- const chunks = [
1442
- {
1443
- type: "response.created",
1444
- response: {
1445
- id: "resp-data-url",
1446
- created_at: Math.floor(Date.now() / 1000),
1447
- model: model.id,
1448
- service_tier: null,
1449
- },
1450
- },
1451
- {
1452
- type: "response.output_item.added",
1453
- output_index: 0,
1454
- item: { type: "message", id: "item-data-url", status: "in_progress", role: "assistant", content: [] },
1455
- },
1456
- {
1457
- type: "response.content_part.added",
1458
- item_id: "item-data-url",
1459
- output_index: 0,
1460
- content_index: 0,
1461
- part: { type: "output_text", text: "", annotations: [] },
1462
- },
1463
- {
1464
- type: "response.output_text.delta",
1465
- item_id: "item-data-url",
1466
- delta: "Looks good",
1467
- logprobs: null,
1468
- },
1469
- {
1470
- type: "response.completed",
1471
- response: {
1472
- incomplete_details: null,
1473
- usage: {
1474
- input_tokens: 1,
1475
- input_tokens_details: null,
1476
- output_tokens: 1,
1477
- output_tokens_details: null,
1478
- },
1479
- service_tier: null,
1480
- },
1481
- },
1482
- ]
1483
- const request = waitRequest("/responses", createEventResponse(chunks, true))
1484
- const image = `data:image/png;base64,${Buffer.from(
1485
- yield* Effect.promise(() =>
1486
- Bun.file(path.join(import.meta.dir, "../tool/fixtures/large-image.png")).arrayBuffer(),
1487
- ),
1488
- ).toString("base64")}`
1489
-
1490
- const resolved = yield* Provider.use.getModel(ProviderV2.ID.openai, ModelV2.ID.make(model.id))
1491
- const sessionID = SessionID.make("session-test-data-url")
1492
- const agent = {
1493
- name: "test",
1494
- mode: "primary",
1495
- options: {},
1496
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1497
- } satisfies Agent.Info
1498
-
1499
- const user = {
1500
- id: MessageID.make("msg_user-data-url"),
1501
- sessionID,
1502
- role: "user",
1503
- time: { created: Date.now() },
1504
- agent: agent.name,
1505
- model: { providerID: ProviderV2.ID.make("openai"), modelID: resolved.id },
1506
- } satisfies SessionV1.User
1507
-
1508
- yield* drain({
1509
- user,
1510
- sessionID,
1511
- model: resolved,
1512
- agent,
1513
- system: ["You are a helpful assistant."],
1514
- messages: [
1515
- {
1516
- role: "user",
1517
- content: [
1518
- { type: "text", text: "Describe this image" },
1519
- { type: "file", mediaType: "image/png", filename: "large-image.png", data: image },
1520
- ],
1521
- },
1522
- ] as ModelMessage[],
1523
- tools: {},
1524
- })
1525
-
1526
- const capture = yield* Effect.promise(() => request)
1527
- expect(capture.url.pathname.endsWith("/responses")).toBe(true)
1528
- }),
1529
- { config: () => openAIConfig(loadFixture("openai", "gpt-5.2").model, `${state.server!.url.origin}/v1`) },
1530
- )
1531
-
1532
- const minimaxFixture = { providerID: "minimax", modelID: "MiniMax-M2.5" }
1533
- it.instance(
1534
- "sends messages API payload for Anthropic Compatible models",
1535
- () =>
1536
- Effect.gen(function* () {
1537
- const model = loadFixture(minimaxFixture.providerID, minimaxFixture.modelID).model
1538
-
1539
- const chunks = [
1540
- {
1541
- type: "message_start",
1542
- message: {
1543
- id: "msg-1",
1544
- model: model.id,
1545
- usage: {
1546
- input_tokens: 3,
1547
- cache_creation_input_tokens: null,
1548
- cache_read_input_tokens: null,
1549
- },
1550
- },
1551
- },
1552
- {
1553
- type: "content_block_start",
1554
- index: 0,
1555
- content_block: { type: "text", text: "" },
1556
- },
1557
- {
1558
- type: "content_block_delta",
1559
- index: 0,
1560
- delta: { type: "text_delta", text: "Hello" },
1561
- },
1562
- { type: "content_block_stop", index: 0 },
1563
- {
1564
- type: "message_delta",
1565
- delta: { stop_reason: "end_turn", stop_sequence: null, container: null },
1566
- usage: {
1567
- input_tokens: 3,
1568
- output_tokens: 2,
1569
- cache_creation_input_tokens: null,
1570
- cache_read_input_tokens: null,
1571
- },
1572
- },
1573
- { type: "message_stop" },
1574
- ]
1575
- const request = waitRequest("/messages", createEventResponse(chunks))
1576
-
1577
- const resolved = yield* Provider.use.getModel(
1578
- ProviderV2.ID.make(minimaxFixture.providerID),
1579
- ModelV2.ID.make(model.id),
1580
- )
1581
- const sessionID = SessionID.make("session-test-3")
1582
- const agent = {
1583
- name: "test",
1584
- mode: "primary",
1585
- options: {},
1586
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1587
- temperature: 0.4,
1588
- topP: 0.9,
1589
- } satisfies Agent.Info
1590
-
1591
- const user = {
1592
- id: MessageID.make("msg_user-3"),
1593
- sessionID,
1594
- role: "user",
1595
- time: { created: Date.now() },
1596
- agent: agent.name,
1597
- model: { providerID: ProviderV2.ID.make("minimax"), modelID: ModelV2.ID.make("MiniMax-M2.5") },
1598
- } satisfies SessionV1.User
1599
-
1600
- yield* drain({
1601
- user,
1602
- sessionID,
1603
- model: resolved,
1604
- agent,
1605
- system: ["You are a helpful assistant."],
1606
- messages: [{ role: "user", content: "Hello" }],
1607
- tools: {},
1608
- })
1609
-
1610
- const capture = yield* Effect.promise(() => request)
1611
- const body = capture.body
1612
-
1613
- expect(capture.url.pathname.endsWith("/messages")).toBe(true)
1614
- expect(body.model).toBe(resolved.api.id)
1615
- expect(body.max_tokens).toBe(ProviderTransform.maxOutputTokens(resolved))
1616
- expect(body.temperature).toBe(0.4)
1617
- expect(body.top_p).toBe(0.9)
1618
- }),
1619
- {
1620
- config: () => ({
1621
- enabled_providers: [minimaxFixture.providerID],
1622
- provider: {
1623
- [minimaxFixture.providerID]: {
1624
- options: { apiKey: "test-anthropic-key", baseURL: `${state.server!.url.origin}/v1` },
1625
- },
1626
- },
1627
- }),
1628
- },
1629
- )
1630
-
1631
- it.instance(
1632
- "sends anthropic tool_use blocks with tool_result immediately after them",
1633
- () =>
1634
- Effect.gen(function* () {
1635
- const model = loadFixture("anthropic", "claude-opus-4-6").model
1636
- const chunks = [
1637
- {
1638
- type: "message_start",
1639
- message: {
1640
- id: "msg-tool-order",
1641
- model: model.id,
1642
- usage: {
1643
- input_tokens: 3,
1644
- cache_creation_input_tokens: null,
1645
- cache_read_input_tokens: null,
1646
- },
1647
- },
1648
- },
1649
- {
1650
- type: "content_block_start",
1651
- index: 0,
1652
- content_block: { type: "text", text: "" },
1653
- },
1654
- {
1655
- type: "content_block_delta",
1656
- index: 0,
1657
- delta: { type: "text_delta", text: "ok" },
1658
- },
1659
- { type: "content_block_stop", index: 0 },
1660
- {
1661
- type: "message_delta",
1662
- delta: { stop_reason: "end_turn", stop_sequence: null, container: null },
1663
- usage: {
1664
- input_tokens: 3,
1665
- output_tokens: 2,
1666
- cache_creation_input_tokens: null,
1667
- cache_read_input_tokens: null,
1668
- },
1669
- },
1670
- { type: "message_stop" },
1671
- ]
1672
- const request = waitRequest("/messages", createEventResponse(chunks))
1673
-
1674
- const resolved = yield* Provider.use.getModel(ProviderV2.ID.make("anthropic"), ModelV2.ID.make(model.id))
1675
- const sessionID = SessionID.make("session-test-anthropic-tools")
1676
- const agent = {
1677
- name: "test",
1678
- mode: "primary",
1679
- options: {},
1680
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1681
- } satisfies Agent.Info
1682
- const user = {
1683
- id: MessageID.make("msg_user-anthropic-tools"),
1684
- sessionID,
1685
- role: "user",
1686
- time: { created: Date.now() },
1687
- agent: agent.name,
1688
- model: { providerID: ProviderV2.ID.make("anthropic"), modelID: resolved.id, variant: "max" },
1689
- } satisfies SessionV1.User
1690
-
1691
- const input = [
1692
- {
1693
- info: {
1694
- id: "msg_user",
1695
- sessionID,
1696
- role: "user",
1697
- time: { created: 1 },
1698
- agent: "gentleman",
1699
- model: { providerID: "anthropic", modelID: "claude-opus-4-6", variant: "max" },
1700
- },
1701
- parts: [
1702
- {
1703
- id: "p_user",
1704
- sessionID,
1705
- messageID: "msg_user",
1706
- type: "text",
1707
- text: "Can you check whether there are any PDF files in my home directory?",
1708
- },
1709
- ],
1710
- },
1711
- {
1712
- info: {
1713
- id: "msg_call",
1714
- sessionID,
1715
- parentID: "msg_user",
1716
- role: "assistant",
1717
- mode: "gentleman",
1718
- agent: "gentleman",
1719
- variant: "max",
1720
- path: { cwd: "/root", root: "/" },
1721
- cost: 0,
1722
- tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
1723
- modelID: "claude-opus-4-6",
1724
- providerID: "anthropic",
1725
- time: { created: 2, completed: 3 },
1726
- finish: "tool-calls",
1727
- },
1728
- parts: [
1729
- {
1730
- id: "p_step",
1731
- sessionID,
1732
- messageID: "msg_call",
1733
- type: "step-start",
1734
- },
1735
- {
1736
- id: "p_read",
1737
- sessionID,
1738
- messageID: "msg_call",
1739
- type: "tool",
1740
- tool: "read",
1741
- callID: "toolu_01N8mDEzG8DSTs7UPHFtmgCT",
1742
- state: {
1743
- status: "completed",
1744
- input: { filePath: "/root" },
1745
- output: "<path>/root</path>",
1746
- metadata: {},
1747
- title: "root",
1748
- time: { start: 10, end: 11 },
1749
- },
1750
- },
1751
- {
1752
- id: "p_glob",
1753
- sessionID,
1754
- messageID: "msg_call",
1755
- type: "tool",
1756
- tool: "glob",
1757
- callID: "toolu_01APxrADs7VozN8uWzw9WwHr",
1758
- state: {
1759
- status: "completed",
1760
- input: { pattern: "**/*.pdf", path: "/root" },
1761
- output: "No files found",
1762
- metadata: {},
1763
- title: "root",
1764
- time: { start: 12, end: 13 },
1765
- },
1766
- },
1767
- {
1768
- id: "p_text",
1769
- sessionID,
1770
- messageID: "msg_call",
1771
- type: "text",
1772
- text: "I checked your home directory and looked for PDF files.",
1773
- time: { start: 14, end: 15 },
1774
- },
1775
- ],
1776
- },
1777
- ] as any[]
1778
-
1779
- const modelMessages = yield* Effect.promise(() => MessageV2.toModelMessages(input as any, resolved))
1780
- yield* drain({
1781
- user,
1782
- sessionID,
1783
- model: resolved,
1784
- agent,
1785
- system: [],
1786
- messages: modelMessages,
1787
- tools: {
1788
- read: tool({
1789
- description: "Stub read tool",
1790
- inputSchema: z.object({ filePath: z.string() }),
1791
- execute: async () => ({ output: "stub" }),
1792
- }),
1793
- glob: tool({
1794
- description: "Stub glob tool",
1795
- inputSchema: z.object({ pattern: z.string(), path: z.string().optional() }),
1796
- execute: async () => ({ output: "stub" }),
1797
- }),
1798
- },
1799
- })
1800
-
1801
- const capture = yield* Effect.promise(() => request)
1802
- const body = capture.body
1803
-
1804
- expect(capture.url.pathname.endsWith("/messages")).toBe(true)
1805
- const messages = body.messages as Array<{ role: string; content: Array<Record<string, unknown>> }>
1806
- expect(messages[0]?.role).toBe("user")
1807
- expect(messages[0]?.content[0]).toMatchObject({
1808
- type: "text",
1809
- text: "Can you check whether there are any PDF files in my home directory?",
1810
- })
1811
- expect(messages.some((message) => message.content.some((part) => "cache_control" in part))).toBe(true)
1812
- const toolUseIndex = messages.findIndex((message) => message.content.some((part) => part.type === "tool_use"))
1813
- expect(toolUseIndex).toBeGreaterThan(0)
1814
- expect(messages[toolUseIndex].role).toBe("assistant")
1815
- expect(messages[toolUseIndex].content.filter((part) => part.type === "tool_use")).toMatchObject([
1816
- {
1817
- type: "tool_use",
1818
- id: "toolu_01N8mDEzG8DSTs7UPHFtmgCT",
1819
- name: "read",
1820
- input: { filePath: "/root" },
1821
- },
1822
- {
1823
- type: "tool_use",
1824
- id: "toolu_01APxrADs7VozN8uWzw9WwHr",
1825
- name: "glob",
1826
- input: { pattern: "**/*.pdf", path: "/root" },
1827
- },
1828
- ])
1829
- expect(messages[toolUseIndex + 1]).toMatchObject({
1830
- role: "user",
1831
- content: [
1832
- { type: "tool_result", tool_use_id: "toolu_01N8mDEzG8DSTs7UPHFtmgCT", content: "<path>/root</path>" },
1833
- { type: "tool_result", tool_use_id: "toolu_01APxrADs7VozN8uWzw9WwHr", content: "No files found" },
1834
- ],
1835
- })
1836
- }),
1837
- {
1838
- config: () => {
1839
- const model = loadFixture("anthropic", "claude-opus-4-6").model
1840
- return {
1841
- enabled_providers: ["anthropic"],
1842
- provider: {
1843
- anthropic: {
1844
- name: "Anthropic",
1845
- env: ["ANTHROPIC_API_KEY"],
1846
- npm: "@ai-sdk/anthropic",
1847
- api: "https://api.anthropic.com/v1",
1848
- models: { [model.id]: configModel(model) as ConfigModel },
1849
- options: { apiKey: "test-anthropic-key", baseURL: `${state.server!.url.origin}/v1` },
1850
- },
1851
- },
1852
- }
1853
- },
1854
- },
1855
- )
1856
-
1857
- const geminiFixture = { providerID: "google", modelID: "gemini-2.5-flash" }
1858
- it.instance(
1859
- "sends Google API payload for Gemini models",
1860
- () =>
1861
- Effect.gen(function* () {
1862
- const model = loadFixture(geminiFixture.providerID, geminiFixture.modelID).model
1863
- const pathSuffix = `/v1beta/models/${model.id}:streamGenerateContent`
1864
-
1865
- const chunks = [
1866
- {
1867
- candidates: [{ content: { parts: [{ text: "Hello" }] }, finishReason: "STOP" }],
1868
- usageMetadata: { promptTokenCount: 1, candidatesTokenCount: 1, totalTokenCount: 2 },
1869
- },
1870
- ]
1871
- const request = waitRequest(pathSuffix, createEventResponse(chunks))
1872
-
1873
- const resolved = yield* Provider.use.getModel(
1874
- ProviderV2.ID.make(geminiFixture.providerID),
1875
- ModelV2.ID.make(model.id),
1876
- )
1877
- const sessionID = SessionID.make("session-test-4")
1878
- const agent = {
1879
- name: "test",
1880
- mode: "primary",
1881
- options: {},
1882
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1883
- temperature: 0.3,
1884
- topP: 0.8,
1885
- } satisfies Agent.Info
1886
-
1887
- const user = {
1888
- id: MessageID.make("msg_user-4"),
1889
- sessionID,
1890
- role: "user",
1891
- time: { created: Date.now() },
1892
- agent: agent.name,
1893
- model: { providerID: ProviderV2.ID.make(geminiFixture.providerID), modelID: resolved.id },
1894
- } satisfies SessionV1.User
1895
-
1896
- yield* drain({
1897
- user,
1898
- sessionID,
1899
- model: resolved,
1900
- agent,
1901
- system: ["You are a helpful assistant."],
1902
- messages: [
1903
- { role: "user", content: "Hello" },
1904
- { role: "assistant", content: [{ type: "reasoning", text: "" }] },
1905
- ],
1906
- tools: {},
1907
- })
1908
-
1909
- const capture = yield* Effect.promise(() => request)
1910
- const body = capture.body
1911
- const config = body.generationConfig as
1912
- | { temperature?: number; topP?: number; maxOutputTokens?: number }
1913
- | undefined
1914
-
1915
- expect(capture.url.pathname).toBe(pathSuffix)
1916
- expect(body.contents).toEqual([{ role: "user", parts: [{ text: "Hello" }] }])
1917
- expect(config?.temperature).toBe(0.3)
1918
- expect(config?.topP).toBe(0.8)
1919
- expect(config?.maxOutputTokens).toBe(ProviderTransform.maxOutputTokens(resolved))
1920
- }),
1921
- {
1922
- config: () => ({
1923
- enabled_providers: [geminiFixture.providerID],
1924
- provider: {
1925
- [geminiFixture.providerID]: {
1926
- options: { apiKey: "test-google-key", baseURL: `${state.server!.url.origin}/v1beta` },
1927
- },
1928
- },
1929
- }),
1930
- },
1931
- )
1932
- })