@bastani/atomic 0.10.14-alpha.1 → 0.10.15-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/_shared/dist-KOELCESV.js +2 -2
  3. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  4. package/dist/_shared/lib-4PES5P4V.js +2 -2
  5. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +3 -3
  6. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
  7. package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
  8. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  9. package/dist/_shared/runtime-O4KCSG4C.js +2 -2
  10. package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
  11. package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
  12. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  13. package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
  14. package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
  15. package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
  16. package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
  17. package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
  18. package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
  19. package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
  20. package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
  21. package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
  22. package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
  23. package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
  24. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  25. package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
  26. package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
  27. package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
  28. package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
  29. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  30. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  31. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  32. package/dist/builtin/intercom/package.json +1 -1
  33. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  34. package/dist/builtin/mcp/package.json +1 -1
  35. package/dist/builtin/subagents/package.json +1 -1
  36. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  37. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  38. package/dist/builtin/web-access/package.json +1 -1
  39. package/dist/cli/auth-cli.code.js +1 -1
  40. package/dist/cli/auth-cli.impl.js +3 -3
  41. package/dist/cli/auth-cli.js +3 -3
  42. package/dist/cli/blueprint-command.impl.js +3 -3
  43. package/dist/cli/blueprint-command.js +3 -3
  44. package/dist/cli/intercom-command.code.js +3 -3
  45. package/dist/cli/intercom-command.impl.js +3 -3
  46. package/dist/cli/intercom-command.js +3 -3
  47. package/dist/cli/list-models.impl.js +3 -3
  48. package/dist/cli/list-models.js +3 -3
  49. package/dist/cli/session-picker.code.js +1 -1
  50. package/dist/cli/session-picker.impl.js +3 -3
  51. package/dist/cli/session-picker.js +3 -3
  52. package/dist/cli/startup-ui.code.js +1 -1
  53. package/dist/cli/startup-ui.impl.js +3 -3
  54. package/dist/cli/startup-ui.js +3 -3
  55. package/dist/cli/storage-command.impl.js +3 -3
  56. package/dist/cli/storage-command.js +3 -3
  57. package/dist/cli/storage-search-session.code.js +1 -1
  58. package/dist/cli/storage-search-session.impl.js +3 -3
  59. package/dist/cli/storage-search-session.js +3 -3
  60. package/dist/cli/team-command.code.js +1 -1
  61. package/dist/cli/team-command.impl.js +3 -3
  62. package/dist/cli/team-command.js +3 -3
  63. package/dist/cli.js +2 -2
  64. package/dist/core/compaction/compactor.d.ts +0 -8
  65. package/dist/core/debug.impl.js +3 -3
  66. package/dist/core/debug.js +3 -3
  67. package/dist/core/export-html/card-projection.impl.js +3 -3
  68. package/dist/core/export-html/card-projection.js +3 -3
  69. package/dist/core/export-html/index.code.js +2 -2
  70. package/dist/core/export-html/index.impl.js +3 -3
  71. package/dist/core/export-html/index.js +3 -3
  72. package/dist/core/export-html/json-spans.impl.js +3 -3
  73. package/dist/core/export-html/json-spans.js +3 -3
  74. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  75. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  76. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  77. package/dist/core/export-html/tool-renderer.js +3 -3
  78. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  79. package/dist/core/extensions/jiti-loader.js +3 -3
  80. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  81. package/dist/core/extensions/jiti-static-loader.js +3 -3
  82. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  83. package/dist/core/extensions/loader-host-modules.js +3 -3
  84. package/dist/core/intercom-broker-control-host.code.js +1 -1
  85. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  86. package/dist/core/intercom-broker-control-host.js +3 -3
  87. package/dist/core/intercom-broker-control.code.js +2 -2
  88. package/dist/core/intercom-broker-control.impl.js +3 -3
  89. package/dist/core/intercom-broker-control.js +3 -3
  90. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  91. package/dist/core/package-manager-storage-adapters.js +3 -3
  92. package/dist/core/sdk.code.js +1 -1
  93. package/dist/core/sdk.impl.js +3 -3
  94. package/dist/core/sdk.js +3 -3
  95. package/dist/core/session-manager-core.js +3 -3
  96. package/dist/core/session-manager-list.impl.js +3 -3
  97. package/dist/core/session-manager-list.js +3 -3
  98. package/dist/core/session-manager.impl.js +3 -3
  99. package/dist/core/session-manager.js +3 -3
  100. package/dist/core/session-storage.impl.js +3 -3
  101. package/dist/core/session-storage.js +3 -3
  102. package/dist/core/storage/index.js +2 -2
  103. package/dist/core/storage/node-sqlite-thread.js +2 -2
  104. package/dist/core/storage/node-sqlite.js +2 -2
  105. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  106. package/dist/core/storage/offline-snapshot-file.js +3 -3
  107. package/dist/core/storage/provider.js +2 -2
  108. package/dist/core/storage/selection.js +2 -2
  109. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  110. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  111. package/dist/core/storage/session/branch-fork-source.js +3 -3
  112. package/dist/core/storage/session/card-view.impl.js +3 -3
  113. package/dist/core/storage/session/card-view.js +3 -3
  114. package/dist/core/storage/session/child-reader.code.js +2 -2
  115. package/dist/core/storage/session/child-reader.impl.js +3 -3
  116. package/dist/core/storage/session/child-reader.js +3 -3
  117. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  118. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  119. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  120. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  121. package/dist/core/storage/session/expanded-child-details.js +3 -3
  122. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  123. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  124. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  125. package/dist/core/storage/session/fork-row-index.js +3 -3
  126. package/dist/core/storage/session/fork-staging.code.js +1 -1
  127. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  128. package/dist/core/storage/session/fork-staging.js +3 -3
  129. package/dist/core/storage/session/fork-window.code.js +2 -2
  130. package/dist/core/storage/session/fork-window.impl.js +3 -3
  131. package/dist/core/storage/session/fork-window.js +3 -3
  132. package/dist/core/storage/session/history-pages.impl.js +3 -3
  133. package/dist/core/storage/session/history-pages.js +3 -3
  134. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  135. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  136. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  137. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  138. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  139. package/dist/core/storage/session/memory-session-store.js +3 -3
  140. package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
  141. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  142. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  143. package/dist/core/storage/session/released-history-files.code.js +1 -1
  144. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  145. package/dist/core/storage/session/released-history-files.js +3 -3
  146. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  147. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  148. package/dist/core/storage/session/session-resume.impl.js +3 -3
  149. package/dist/core/storage/session/session-resume.js +3 -3
  150. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  151. package/dist/core/storage/session/snapshot-cut.js +3 -3
  152. package/dist/core/storage/session/snapshot-history.code.js +2 -2
  153. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  154. package/dist/core/storage/session/snapshot-history.js +3 -3
  155. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  156. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  157. package/dist/core/storage/session/sql-session-store.js +3 -3
  158. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  159. package/dist/core/storage/session/tree-outline.js +3 -3
  160. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  161. package/dist/core/storage/session/tree-presentation.js +3 -3
  162. package/dist/core/storage/storage-status.impl.js +3 -3
  163. package/dist/core/storage/storage-status.js +3 -3
  164. package/dist/core/storage/team.impl.js +3 -3
  165. package/dist/core/storage/team.js +3 -3
  166. package/dist/core/structured-output/index.code.js +1 -1
  167. package/dist/core/structured-output/index.impl.js +3 -3
  168. package/dist/core/structured-output/index.js +3 -3
  169. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  170. package/dist/core/tasks/task-completion-entry.js +3 -3
  171. package/dist/core/tasks/task-file-history.code.js +2 -2
  172. package/dist/core/tasks/task-file-history.impl.js +3 -3
  173. package/dist/core/tasks/task-file-history.js +3 -3
  174. package/dist/core/tasks/task-reference-archive.code.js +2 -2
  175. package/dist/core/tasks/task-reference-archive.js +3 -3
  176. package/dist/core/tasks/task-reference-identity.js +3 -3
  177. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  178. package/dist/core/tasks/task-reference-stream.js +3 -3
  179. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  180. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  181. package/dist/core/tasks/task-view-source.impl.js +3 -3
  182. package/dist/core/tasks/task-view-source.js +3 -3
  183. package/dist/core/tools/read-url.impl.js +3 -3
  184. package/dist/core/tools/read-url.js +3 -3
  185. package/dist/core/worktree-snapshot/blob-store.js +2 -2
  186. package/dist/core/worktree-snapshot/errors.code.js +1 -1
  187. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  188. package/dist/core/worktree-snapshot/errors.js +3 -3
  189. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  190. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  191. package/dist/extensions/codemode/execute.impl.js +3 -3
  192. package/dist/extensions/codemode/execute.js +3 -3
  193. package/dist/extensions/codemode/renderer.impl.js +3 -3
  194. package/dist/extensions/codemode/renderer.js +3 -3
  195. package/dist/extensions/mcp/cli.code.js +1 -1
  196. package/dist/extensions/mcp/cli.impl.js +3 -3
  197. package/dist/extensions/mcp/cli.js +3 -3
  198. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  199. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  200. package/dist/extensions/mcp/cli.lazy.js +3 -3
  201. package/dist/extensions/mcp/runtime.code.js +1 -1
  202. package/dist/extensions/mcp/runtime.impl.js +3 -3
  203. package/dist/extensions/mcp/runtime.js +3 -3
  204. package/dist/index.d.ts +21 -1
  205. package/dist/index.js +2 -2
  206. package/dist/main-first-time-setup.code.js +1 -1
  207. package/dist/main-first-time-setup.impl.js +3 -3
  208. package/dist/main-first-time-setup.js +3 -3
  209. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  210. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  211. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  212. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  213. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  214. package/dist/modes/print-mode.js +1 -1
  215. package/dist/package-manager-cli.code.js +2 -2
  216. package/dist/package-manager-cli.impl.js +3 -3
  217. package/dist/package-manager-cli.js +3 -3
  218. package/dist/startup-files.json +1 -1
  219. package/dist/startup-stages/6.js +1 -1
  220. package/dist/utils/startup-database-spare.code.js +1 -1
  221. package/dist/utils/startup-database-spare.impl.js +3 -3
  222. package/dist/utils/startup-database-spare.js +3 -3
  223. package/dist/utils/tools-manager.impl.js +3 -3
  224. package/dist/utils/tools-manager.js +3 -3
  225. package/docs/background-tasks/reference.md +182 -0
  226. package/docs/background-tasks.md +98 -405
  227. package/docs/build.md +67 -27
  228. package/docs/changelog.mdx +9 -0
  229. package/docs/codemode.md +108 -39
  230. package/docs/compaction/branch-summaries.md +54 -0
  231. package/docs/compaction/custom-compactors.md +161 -0
  232. package/docs/compaction/memory-compaction.md +77 -0
  233. package/docs/compaction/reference.md +86 -38
  234. package/docs/compaction.md +51 -252
  235. package/docs/computer-use.md +169 -321
  236. package/docs/containerization.md +71 -57
  237. package/docs/custom-provider/api-reference.md +119 -25
  238. package/docs/custom-provider/oauth.md +114 -132
  239. package/docs/custom-provider/override.md +37 -27
  240. package/docs/custom-provider/registration.md +107 -83
  241. package/docs/custom-provider/streaming.md +85 -71
  242. package/docs/custom-provider.md +85 -52
  243. package/docs/development.md +39 -29
  244. package/docs/docs.json +76 -63
  245. package/docs/environment-variables.md +94 -44
  246. package/docs/extensions/api-reference.md +86 -43
  247. package/docs/extensions/authoring.md +162 -154
  248. package/docs/extensions/events.md +80 -25
  249. package/docs/extensions/examples.md +90 -85
  250. package/docs/extensions/ui.md +206 -82
  251. package/docs/extensions.md +79 -108
  252. package/docs/getting-started/authentication.md +67 -36
  253. package/docs/getting-started/first-session.md +53 -43
  254. package/docs/getting-started/installation.md +116 -89
  255. package/docs/getting-started/project-instructions.md +48 -34
  256. package/docs/guides/configuration.md +82 -20
  257. package/docs/guides/non-interactive.md +66 -24
  258. package/docs/guides/resume-on-any-machine.md +135 -82
  259. package/docs/guides/team-setup.md +114 -105
  260. package/docs/guides.md +76 -32
  261. package/docs/herdr.md +15 -16
  262. package/docs/how-atomic-works.md +140 -0
  263. package/docs/index.md +58 -44
  264. package/docs/intercom/operations.md +141 -151
  265. package/docs/intercom/reference.md +85 -108
  266. package/docs/intercom.md +84 -145
  267. package/docs/json.md +120 -67
  268. package/docs/keybindings.md +85 -49
  269. package/docs/libraries/agent-core.md +137 -275
  270. package/docs/libraries/ai.md +100 -84
  271. package/docs/libraries/codemode.md +210 -300
  272. package/docs/libraries/schema.md +59 -53
  273. package/docs/libraries/storage-postgres.md +49 -35
  274. package/docs/libraries/telemetry.md +153 -354
  275. package/docs/libraries/tui.md +265 -393
  276. package/docs/libraries.md +42 -26
  277. package/docs/llama-cpp.md +171 -161
  278. package/docs/mcp-servers.md +90 -51
  279. package/docs/models/choose-a-model.md +188 -0
  280. package/docs/models/reference.md +74 -30
  281. package/docs/models.md +153 -88
  282. package/docs/orchestration/migrating-workflows.md +23 -16
  283. package/docs/orchestration/patterns.md +39 -44
  284. package/docs/orchestration.md +65 -26
  285. package/docs/packages/authoring.md +51 -29
  286. package/docs/packages/reference.md +42 -21
  287. package/docs/packages.md +69 -58
  288. package/docs/programmatic.md +118 -24
  289. package/docs/prompt-templates.md +84 -83
  290. package/docs/providers/reference.md +43 -48
  291. package/docs/providers.md +219 -451
  292. package/docs/quickstart.md +140 -120
  293. package/docs/reference/cli.md +135 -97
  294. package/docs/reference.md +20 -18
  295. package/docs/rpc/examples.md +76 -20
  296. package/docs/rpc/extension-ui.md +64 -38
  297. package/docs/rpc/protocol.md +361 -110
  298. package/docs/rpc.md +57 -17
  299. package/docs/sdk/reference.md +409 -534
  300. package/docs/sdk/storage.md +53 -13
  301. package/docs/sdk/structured-decisions.md +82 -56
  302. package/docs/sdk/web-server.md +57 -43
  303. package/docs/sdk.md +106 -84
  304. package/docs/security.md +42 -64
  305. package/docs/session-format.md +62 -38
  306. package/docs/sessions.md +99 -214
  307. package/docs/settings.md +165 -195
  308. package/docs/shell-aliases.md +9 -6
  309. package/docs/skills/authoring.md +69 -48
  310. package/docs/skills/reference.md +51 -20
  311. package/docs/skills.md +99 -148
  312. package/docs/slash-commands.md +129 -0
  313. package/docs/storage/custom-adapters.md +160 -85
  314. package/docs/storage/jsonl.md +81 -66
  315. package/docs/storage/postgres/pgbouncer.md +120 -126
  316. package/docs/storage/postgres/tuning.md +120 -143
  317. package/docs/storage/postgres.md +314 -330
  318. package/docs/storage/sqlite.md +71 -42
  319. package/docs/storage.md +298 -302
  320. package/docs/subagents/authoring.md +55 -38
  321. package/docs/subagents/reference.md +73 -33
  322. package/docs/subagents.md +119 -187
  323. package/docs/terminal-setup.md +50 -38
  324. package/docs/termux.md +67 -41
  325. package/docs/themes/reference.md +23 -19
  326. package/docs/themes.md +142 -127
  327. package/docs/tmux.md +47 -55
  328. package/docs/tools.md +147 -109
  329. package/docs/tui/reference.md +166 -214
  330. package/docs/tui.md +196 -341
  331. package/docs/usage.md +118 -138
  332. package/docs/verification.md +79 -51
  333. package/docs/web-access.md +121 -101
  334. package/docs/windows.md +26 -27
  335. package/docs/worktree-snapshots/reference.md +245 -0
  336. package/docs/worktree-snapshots.md +71 -259
  337. package/package.json +8 -8
  338. package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
  339. package/docs/guides/intercom.md +0 -32
  340. package/docs/guides/orchestration.md +0 -28
  341. package/docs/guides/subagents.md +0 -37
@@ -1,12 +1,45 @@
1
1
  ---
2
2
  title: "Register a custom provider"
3
- sidebarTitle: "Register provider"
4
- description: "Add custom providers, choose a streaming API, set up multi-account aliases, and unregister providers."
3
+ sidebarTitle: "Register a Provider"
4
+ description: "Register custom providers with static or discovered models, pick a streaming API, create multi-account aliases, and unregister providers."
5
5
  ---
6
6
 
7
- ## Register a new provider {#register-new-provider}
7
+ Register a custom provider when you want to add models dynamically at startup, attach custom handlers or authentication, or expose multiple accounts for the same provider. All registrations should be awaited inside your `async` extension factory so Atomic discovers them before the session starts.
8
8
 
9
- Specify `models` alongside the provider endpoint and API to register a new provider. For remote model discovery, fetch and register inside an async extension factory so startup waits for the models to load:
9
+ ## Static and dynamic model registration {#register-new-provider}
10
+
11
+ Start with a static model definition alongside `baseUrl`, `apiKey`, and `api`:
12
+
13
+ ```typescript
14
+ import type { ExtensionAPI } from "@bastani/atomic";
15
+
16
+ export default async function (atomic: ExtensionAPI) {
17
+ await atomic.registerProvider("my-llm", {
18
+ name: "My LLM",
19
+ baseUrl: "https://api.my-llm.com/v1",
20
+ apiKey: "$MY_LLM_API_KEY", // supports $ENV_VAR, ${ENV_VAR}, !command, or literal values
21
+ api: "openai-completions", // built-in streaming API implementation
22
+ models: [
23
+ {
24
+ id: "my-llm-large",
25
+ name: "My LLM Large",
26
+ reasoning: true,
27
+ input: ["text", "image"],
28
+ cost: {
29
+ input: 3.0, // USD per million tokens
30
+ output: 15.0,
31
+ cacheRead: 0.3,
32
+ cacheWrite: 3.75,
33
+ },
34
+ contextWindow: 200000,
35
+ maxTokens: 16384,
36
+ },
37
+ ],
38
+ });
39
+ }
40
+ ```
41
+
42
+ For servers whose available models change at runtime, fetch the list inside the `async` extension factory so startup waits before building the model picker:
10
43
 
11
44
  ```typescript
12
45
  import type { ExtensionAPI } from "@bastani/atomic";
@@ -39,102 +72,88 @@ export default async function (atomic: ExtensionAPI) {
39
72
  }
40
73
  ```
41
74
 
42
- Or register static models directly:
43
-
44
- ```typescript
45
- await atomic.registerProvider("my-llm", {
46
- baseUrl: "https://api.my-llm.com/v1",
47
- apiKey: "$MY_LLM_API_KEY", // supports $ENV_VAR, ${ENV_VAR}, !command, or literal values
48
- api: "openai-completions", // streaming API implementation
49
- models: [
50
- {
51
- id: "my-llm-large",
52
- name: "My LLM Large",
53
- reasoning: true,
54
- input: ["text", "image"],
55
- cost: {
56
- input: 3.0, // USD per million tokens
57
- output: 15.0,
58
- cacheRead: 0.3,
59
- cacheWrite: 3.75
60
- },
61
- contextWindow: 200000,
62
- maxTokens: 16384
63
- }
64
- ]
65
- });
66
- ```
67
-
68
- Providing `models` replaces all existing chat, image, classifier, and compactor models for that provider. Omitting `type` registers a chat model; image and classifier models require `type: "image"` or `type: "classifier"` plus handlers in `images` or `classifiers`; compactor models use `type: "compactor"` (`ProviderCompactorModelConfig`, see [Compactor request contract](/compaction/reference#compactor-request-contract)). See the [mixed-operation provider example](/custom-provider#mixed-operation-providers).
75
+ Providing `models` replaces all existing chat, image, classifier, and compactor models for that provider. Omitting `type` registers a chat model; image and classifier models require `type: "image"` or `type: "classifier"` plus matching handlers in `images` or `classifiers`; compactor models use `type: "compactor"` (`ProviderCompactorModelConfig`, see [Compactor request contract](/compaction/reference#compactor-request-contract)). See the [mixed-operation provider example](/custom-provider#mixed-operation-providers).
69
76
 
70
- Registered providers appear in `/login` like built-in providers: `/login my-llm` prompts for an API key and stores it in `auth.json`, and the selector shows configured status (such as `✓ env: MY_LLM_API_KEY`). See [Credential resolution order](/providers/reference#resolution-order) for how stored keys, extension `apiKey`, and environment variables interact. Once configured, `/model` lists its models; without credentials, selecting one reports `No API key found for my-llm` with the `/login` hint.
77
+ Registered providers appear in `/login` alongside built-in providers: `/login my-llm` prompts for an API key, saves it in `auth.json`, and displays configured status (such as `✓ env: MY_LLM_API_KEY`). Once credentials are configured, `/model` lists the provider's models; selecting a model without credentials reports `No API key found for my-llm` with a `/login` hint. See [Credential resolution order](/providers/reference#resolution-order).
71
78
 
72
79
  ### API types
73
80
 
74
- The `api` field selects the built-in chat streaming implementation:
81
+ The `api` field selects one of Atomic's built-in chat streaming protocols:
75
82
 
76
83
  | API | Use for |
77
84
  | --- | --- |
78
- | `anthropic-messages` | Anthropic Claude API and compatibles |
79
- | `openai-completions` | OpenAI Chat Completions API and compatibles |
85
+ | `openai-completions` | OpenAI Chat Completions API and most OpenAI-compatible servers |
80
86
  | `openai-responses` | OpenAI Responses API |
81
87
  | `azure-openai-responses` | Azure OpenAI Responses API |
82
88
  | `openai-codex-responses` | OpenAI Codex Responses API |
83
- | `mistral-conversations` | Native Mistral Chat Completions streaming |
84
- | `google-generative-ai` | Google Generative AI API |
89
+ | `anthropic-messages` | Anthropic Claude Messages API and compatibles |
90
+ | `mistral-conversations` | Native Mistral Conversations and Chat streaming |
91
+ | `google-generative-ai` | Google Generative AI (Gemini API) |
85
92
  | `google-vertex` | Google Vertex AI API |
86
93
  | `bedrock-converse-stream` | Amazon Bedrock Converse API |
87
- | `pi-messages` | Custom gateways speaking the `pi-messages` protocol |
94
+ | `pi-messages` | Custom gateways speaking Atomic's native `pi-messages` protocol |
88
95
 
89
- Image (`images`) and classifier (`classifiers`) handlers use their own operation-specific `api` keys independent of this chat streaming table. Compactor models (`type: "compactor"`) declare a compactor `api` string at model or provider level and follow the [Compactor request contract](/compaction/reference#compactor-request-contract).
96
+ Image (`images`) and classifier (`classifiers`) handlers use their own operation-specific `api` keys independent of this table. Compactor models (`type: "compactor"`) declare a compactor `api` string at model or provider level and follow the [Compactor request contract](/compaction/reference#compactor-request-contract).
90
97
 
91
- Most OpenAI-compatible servers use `openai-completions`. Configure model-specific thinking controls with `thinkingLevelMap` and endpoint quirks with `compat`:
98
+ Most OpenAI-compatible servers use `openai-completions`. Configure model-specific thinking controls with `thinkingLevelMap` and server quirks with `compat`:
92
99
 
93
100
  ```typescript
94
- models: [{
95
- id: "custom-model",
96
- name: "Custom Model",
97
- reasoning: true,
98
- input: ["text"],
99
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
100
- contextWindow: 128000,
101
- maxTokens: 16384,
102
- thinkingLevelMap: { // map Atomic thinking levels; null hides unsupported levels
103
- minimal: null,
104
- low: null,
105
- medium: null,
106
- high: "default",
107
- xhigh: null,
108
- max: "max"
101
+ models: [
102
+ {
103
+ id: "custom-model",
104
+ name: "Custom Model",
105
+ reasoning: true,
106
+ input: ["text"],
107
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
108
+ contextWindow: 128000,
109
+ maxTokens: 16384,
110
+ thinkingLevelMap: { // Map Atomic thinking levels; null hides unsupported levels
111
+ minimal: null,
112
+ low: null,
113
+ medium: null,
114
+ high: "default",
115
+ xhigh: null,
116
+ max: "max",
117
+ },
118
+ compat: {
119
+ supportsDeveloperRole: false,
120
+ supportsReasoningEffort: true,
121
+ maxTokensField: "max_tokens",
122
+ requiresToolResultName: true,
123
+ thinkingFormat: "qwen",
124
+ cacheControlFormat: "anthropic",
125
+ },
109
126
  },
110
- compat: {
111
- supportsDeveloperRole: false,
112
- supportsReasoningEffort: true,
113
- maxTokensField: "max_tokens",
114
- requiresToolResultName: true,
115
- thinkingFormat: "qwen",
116
- cacheControlFormat: "anthropic"
117
- }
118
- }]
127
+ ]
119
128
  ```
120
129
 
121
130
  See [Compatibility fields](/models-configuration#compatibility) for every `compat` option (`thinkingFormat`, `cacheControlFormat`, session affinity, and tool flags). Use `mistral-conversations` for native Mistral endpoints; if routing a Mistral-compatible endpoint through `openai-completions`, configure `compat` flags explicitly.
122
131
 
123
132
  ### Auth header
124
133
 
125
- Set `authHeader: true` when an endpoint expects `Authorization: Bearer <key>` using the resolved `apiKey`:
134
+ Set `authHeader: true` when an endpoint expects `Authorization: Bearer <key>` derived from the resolved `apiKey`:
126
135
 
127
136
  ```typescript
128
137
  await atomic.registerProvider("custom-api", {
129
- baseUrl: "https://api.example.com",
138
+ baseUrl: "https://api.example.com/v1",
130
139
  apiKey: "$MY_API_KEY",
131
140
  authHeader: true,
132
141
  api: "openai-completions",
133
- models: []
142
+ models: [
143
+ {
144
+ id: "custom-chat",
145
+ name: "Custom Chat",
146
+ reasoning: false,
147
+ input: ["text"],
148
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
149
+ contextWindow: 128000,
150
+ maxTokens: 4096,
151
+ },
152
+ ],
134
153
  });
135
154
  ```
136
155
 
137
- If `authHeader: true` is set and the provider resolves no API key (for example, `$MY_API_KEY` is unset and no key is saved in `auth.json`), requests fail with a missing API key error (`authHeader requires a resolved API key`).
156
+ If `authHeader: true` is set and no API key resolves (for example, `$MY_API_KEY` is unset and no key is saved in `auth.json`), requests fail with a missing API key error.
138
157
 
139
158
  ## Multiple accounts for one provider
140
159
 
@@ -144,7 +163,7 @@ Use `atomic.registerProviderAlias()` to reuse an existing provider's models, OAu
144
163
  import type { ExtensionAPI } from "@bastani/atomic";
145
164
 
146
165
  export default async function (atomic: ExtensionAPI) {
147
- for (let account = 1; account <= 7; account++) {
166
+ for (let account = 1; account <= 3; account++) {
148
167
  await atomic.registerProviderAlias({
149
168
  id: `openai-${account}`,
150
169
  name: `OpenAI account ${account}`,
@@ -154,25 +173,30 @@ export default async function (atomic: ExtensionAPI) {
154
173
  }
155
174
  ```
156
175
 
157
- Run `/login openai-1`, choose **Sign in with ChatGPT**, and select an `openai-1` model in `/model`. Repeat for each alias. The source `openai` uses OpenAI ChatGPT sign-in rather than `openai-codex`.
176
+ Run `/login openai-1`, choose **Use a subscription** (for ChatGPT sign-in on OpenAI's Responses API) or **Use an API key**, and select an `openai-1` model in `/model`. Repeat for each alias.
158
177
 
159
- Each alias stores and refreshes its own credentials without borrowing the source's stored login or ambient environment keys. Keeping the same alias ID preserves saved credentials. Confirm the intended account in your browser during login; an alias name does not select an account or increase quota.
178
+ <Note>
179
+ Confirm the intended account in your browser during login. An alias only isolates stored credentials in `auth.json` — it does not select an account automatically or increase provider quota.
180
+ </Note>
160
181
 
161
- Aliases work with OAuth logins and non-empty stored API keys. For ambient-only authentication (such as an AWS profile or environment-based service account), use the original provider or register a full custom provider instead.
182
+ How aliases behave:
162
183
 
163
- Aliases inherit the source's endpoint, shared headers, models, derived Fast variants, OAuth callbacks, and request handling. Do not hard-code account secrets in source headers; supply per-account credentials through `/login`. Saved messages and callbacks keep the alias ID. Source catalog updates are shared while availability filters run against each alias's credential; aliases do not run separate per-account catalog discovery, except `github-copilot` aliases, which refresh their own account's model list independently.
184
+ - **Isolated credentials.** Each alias stores and refreshes its own credentials without borrowing the source's stored login or ambient environment keys. Keeping the same alias ID preserves saved credentials.
185
+ - **Supported auth types.** Aliases work with OAuth logins and non-empty stored API keys. For ambient-only authentication (such as an AWS profile or environment-based service account), use the original provider or register a full custom provider instead.
186
+ - **Inherited configuration.** Aliases inherit the source's endpoint, shared headers, models, derived Fast variants, OAuth callbacks, and request handling. Do not hard-code account secrets in source headers; supply per-account credentials through `/login`. Saved messages and callbacks keep the alias ID.
187
+ - **Catalog updates.** Source catalog updates are shared across aliases while availability filters run per alias credential. Aliases do not run separate catalog discovery, except `github-copilot` aliases, which refresh their own account's model list independently.
164
188
 
165
189
  Validation rules for `registerProviderAlias()`:
166
190
 
167
191
  - `id` and `provider` must be distinct, non-empty strings.
168
- - `id` cannot match any built-in provider, `models.json` provider, or existing non-alias extension provider (throws `Provider alias <id> cannot replace an existing provider.`).
169
- - `provider` must already be registered and cannot itself be an alias (throws `Provider aliases must refer directly to a source provider, not another alias.`).
170
- - `registerProviderAlias({ id, name, provider })` is shorthand for `registerProvider(id, { aliasOf: provider, name })`. No other fields (such as `baseUrl` or `headers`) are allowed on an alias; configure endpoints, headers, and `models.json` overrides on the source provider instead.
171
- - Call `atomic.unregisterProvider("openai-1")` to remove an alias without deleting its saved credentials.
192
+ - `id` cannot match any built-in provider, `models.json` provider, or existing non-alias extension provider.
193
+ - `provider` must already be registered and must point directly to a source provider, never to another alias.
194
+ - `registerProviderAlias({ id, name, provider })` is shorthand for `registerProvider(id, { aliasOf: provider, name })`. Only `aliasOf` and optional `name` are allowed on an alias; configure endpoints, headers, and `models.json` overrides on the source provider instead.
195
+ - Calling `await atomic.unregisterProvider("openai-1")` removes the alias without deleting its saved credentials in `auth.json`.
172
196
 
173
197
  ## Unregister a provider {#unregister-provider}
174
198
 
175
- Call `atomic.unregisterProvider(name)` to remove a provider registered with `atomic.registerProvider()` or `atomic.registerProviderAlias()`:
199
+ Call `await atomic.unregisterProvider(name)` to remove a provider registered with `registerProvider()` or `registerProviderAlias()`:
176
200
 
177
201
  ```typescript
178
202
  await atomic.registerProvider("my-llm", {
@@ -187,13 +211,13 @@ await atomic.registerProvider("my-llm", {
187
211
  input: ["text", "image"],
188
212
  cost: { input: 3.0, output: 15.0, cacheRead: 0.3, cacheWrite: 3.75 },
189
213
  contextWindow: 200000,
190
- maxTokens: 16384
191
- }
192
- ]
214
+ maxTokens: 16384,
215
+ },
216
+ ],
193
217
  });
194
218
 
195
- // Remove later without needing /reload
219
+ // Remove later without running /reload
196
220
  await atomic.unregisterProvider("my-llm");
197
221
  ```
198
222
 
199
- Unregistering removes the provider's dynamic models, API key fallback, OAuth registration, and custom stream handlers, restoring any overridden built-in provider behavior. Calls made after initial extension loading take effect immediately without `/reload`. If the current session is using a model from the unregistered provider, Atomic refreshes the active model immediately. Calling `unregisterProvider()` for a provider that is not registered is a safe no-op.
223
+ Unregistering removes the provider's dynamic models, API key fallback, OAuth registration, and custom stream handlers, restoring any built-in provider it overrode. Calls made after startup take effect immediately without `/reload`, and if the active session is using a model from the removed provider, Atomic refreshes the active model immediately. Calling `unregisterProvider()` for an unknown provider is a safe no-op.
@@ -1,47 +1,56 @@
1
1
  ---
2
2
  title: "Implement provider streaming"
3
- sidebarTitle: "Streaming API"
3
+ sidebarTitle: "Implement Streaming"
4
4
  description: "Build a custom streamSimple handler with stream events, content blocks, tool calls, stop reasons, and cost calculation."
5
5
  ---
6
6
 
7
- ## Custom streaming API
7
+ When a provider uses a protocol that none of Atomic's built-in APIs speak, supply a `streamSimple` handler in `atomic.registerProvider()`. Your handler converts upstream chunks into normalized Atomic stream events so the UI, retries, compaction, and tool execution work identically to built-in providers.
8
8
 
9
- For providers with non-standard APIs, implement `streamSimple`. Study Atomic's built-in streaming implementations in the [`@bastani/atomic-ai` API source directory](https://github.com/bastani-inc/atomic/tree/main/packages/ai/src/api) before writing your own:
9
+ <Steps>
10
+ <Step title="Create the event stream and output message">
11
+ Construct an `AssistantMessageEventStream` via `createAssistantMessageEventStream()` and initialize an `AssistantMessage` with `stopReason: "pending"`, `timestamp: Date.now()`, and zeroed `usage`.
12
+ </Step>
13
+ <Step title="Emit start and send the request">
14
+ Push `{ type: "start", partial: output }`, read the system prompt and tools from `context.messages`, and open the upstream request while forwarding `options?.signal`.
15
+ </Step>
16
+ <Step title="Stream content blocks">
17
+ Append text, thinking, and tool-call blocks to `output.content` and push matching `*_start`, `*_delta`, and `*_end` events as chunks arrive.
18
+ </Step>
19
+ <Step title="Compute usage and map the stop reason">
20
+ Populate `output.usage`, call `calculateCost(model, output.usage)`, and map the provider's terminal finish reason onto Atomic's `StopReason` union (throwing on unrecognized values).
21
+ </Step>
22
+ <Step title="Emit done or error and end the stream">
23
+ Push `{ type: "done", reason, message: output }` on success — or `{ type: "error", reason, error: output }` in `catch` — then call `stream.end()`.
24
+ </Step>
25
+ </Steps>
10
26
 
11
- - `anthropic-messages.ts`: Anthropic Messages API
12
- - `mistral-conversations.ts`: Mistral Conversations and Chat streaming
13
- - `openai-completions.ts`: OpenAI Chat Completions
14
- - `openai-responses.ts`: OpenAI Responses API
15
- - `google-generative-ai.ts`: Google Generative AI
16
- - `bedrock-converse-stream.ts`: Amazon Bedrock Converse API
27
+ ## Stream pattern
17
28
 
18
- Built-in provider configurations (base URLs, auth, and model catalogs) live in [`packages/ai/src/providers`](https://github.com/bastani-inc/atomic/tree/main/packages/ai/src/providers). For general library usage, see the [AI library reference](/libraries/ai).
29
+ Return a stream created by `createAssistantMessageEventStream()` (or `new AssistantMessageEventStream()`). A plain `EventStream` subclass does not satisfy Atomic's response stream contract.
19
30
 
20
- ### Stream pattern
31
+ `AssistantMessageEventStream` automatically fills `output.durationMs` using a monotonic clock when you push `done` or `error`. Set `timestamp: Date.now()` when the request starts; existing durations are preserved, and messages whose timestamps predate the stream (such as fetched deferred results) remain untimed.
21
32
 
22
- Return a stream from `createAssistantMessageEventStream()` or construct `AssistantMessageEventStream` directly. A plain `EventStream` subclass does not satisfy the response stream type.
23
-
24
- `AssistantMessageEventStream` populates `output.durationMs` automatically using a monotonic clock when you push a `done` or `error` event. Set `timestamp` when the request starts. Existing durations stay intact, and messages whose timestamps predate the stream (such as fetched deferred results) remain untimed.
25
-
26
- Note on context types: `@bastani/atomic-ai` types the `context` argument as `TranscriptContext`, while `ProviderConfig.streamSimple` uses the compatible `Context` alias; both pass the normalized message transcript where `getCurrentSystemPrompt(context.messages)` and `getCurrentTools(context.messages)` read the active system prompt and tools.
33
+ <Note>
34
+ `ProviderConfig.streamSimple` types `context` as `Context`, and Atomic passes a normalized transcript where `getCurrentSystemPrompt(context.messages)` and `getCurrentTools(context.messages)` resolve the active system prompt and tool definitions.
35
+ </Note>
27
36
 
28
37
  ```typescript
29
38
  import {
39
+ type Api,
30
40
  type AssistantMessage,
31
41
  type AssistantMessageEventStream,
42
+ type Context,
32
43
  type Model,
33
44
  type SimpleStreamOptions,
34
- type TranscriptContext,
35
45
  calculateCost,
36
46
  createAssistantMessageEventStream,
37
47
  getCurrentSystemPrompt,
38
48
  getCurrentTools,
39
- ToolCallArgumentsStream,
40
49
  } from "@bastani/atomic-ai";
41
50
 
42
51
  function streamMyProvider(
43
- model: Model<any>,
44
- context: TranscriptContext,
52
+ model: Model<Api>,
53
+ context: Context,
45
54
  options?: SimpleStreamOptions
46
55
  ): AssistantMessageEventStream {
47
56
  const stream = createAssistantMessageEventStream();
@@ -49,7 +58,7 @@ function streamMyProvider(
49
58
  (async () => {
50
59
  const systemPrompt = getCurrentSystemPrompt(context.messages);
51
60
  const tools = getCurrentTools(context.messages);
52
- // Initialize output message
61
+
53
62
  const output: AssistantMessage = {
54
63
  role: "assistant",
55
64
  content: [],
@@ -69,12 +78,13 @@ function streamMyProvider(
69
78
  };
70
79
 
71
80
  try {
72
- // Push start event
73
81
  stream.push({ type: "start", partial: output });
74
82
 
75
- // Send API request, push content events, and set output.stopReason from
76
- // the terminal event. Throw on any unmapped stop reason instead of falling
77
- // back to "stop".
83
+ // Send your upstream request using systemPrompt, tools, context.messages, and options.
84
+ // Push content block events as chunks arrive, populate output.usage, call
85
+ // calculateCost(model, output.usage), and set output.stopReason from the terminal event.
86
+ // Throw on any unrecognized provider stop reason instead of defaulting to "stop".
87
+
78
88
  if (output.stopReason === "pending") {
79
89
  throw new Error("Provider stream ended without a stop reason");
80
90
  }
@@ -82,11 +92,10 @@ function streamMyProvider(
82
92
  throw new Error(output.errorMessage || "An unknown error occurred");
83
93
  }
84
94
 
85
- // Push done event
86
95
  stream.push({
87
96
  type: "done",
88
97
  reason: output.stopReason,
89
- message: output
98
+ message: output,
90
99
  });
91
100
  stream.end();
92
101
  } catch (error) {
@@ -101,7 +110,7 @@ function streamMyProvider(
101
110
  }
102
111
  ```
103
112
 
104
- Common fields on `options` (`SimpleStreamOptions`):
113
+ ### Common `SimpleStreamOptions` fields
105
114
 
106
115
  | Option | Purpose |
107
116
  | --- | --- |
@@ -113,50 +122,43 @@ Common fields on `options` (`SimpleStreamOptions`):
113
122
  | `temperature`, `maxTokens`, `samplingParams` | Generation parameters and custom request-body sampling overrides |
114
123
  | `sessionId`, `cacheRetention`, `transport` | Session affinity ID, prompt-cache retention tier, and transport preference |
115
124
  | `timeoutMs`, `websocketConnectTimeoutMs`, `streamDeadlineMs`, `retryDeadline` | Request, handshake, idle-stream, and retry timeout bounds |
116
- | `onPayload`, `onResponse`, `onProviderStreamEvent` | Lifecycle hooks to inspect/modify request payloads, inspect HTTP responses, and observe raw parsed stream events before normalization |
117
-
118
- ### Event types
125
+ | `onPayload`, `onResponse`, `onProviderStreamEvent` | Lifecycle hooks to inspect or modify payloads, inspect HTTP responses, and observe parsed raw stream chunks before normalization |
119
126
 
120
- Push events with `stream.push()` in this order:
127
+ ## Event types
121
128
 
122
- 1. `{ type: "start", partial: output }`: stream started.
123
- 2. Content events (repeatable; track `contentIndex` for each block):
124
- - `{ type: "text_start", contentIndex, partial }`: text block started.
125
- - `{ type: "text_delta", contentIndex, delta, partial }`: text chunk.
126
- - `{ type: "text_end", contentIndex, content, partial }`: text block ended.
127
- - `{ type: "thinking_start", contentIndex, partial }`: thinking block started.
128
- - `{ type: "thinking_delta", contentIndex, delta, partial }`: thinking chunk.
129
- - `{ type: "thinking_end", contentIndex, content, partial }`: thinking block ended.
130
- - `{ type: "toolcall_start", contentIndex, partial }`: tool call started.
131
- - `{ type: "toolcall_delta", contentIndex, delta, partial }`: tool call JSON chunk.
132
- - `{ type: "toolcall_end", contentIndex, toolCall, partial }`: tool call ended.
133
- 3. `{ type: "done", reason, message }` or `{ type: "error", reason, error }`: stream ended.
129
+ Push events through `stream.push()` in this order:
134
130
 
135
- `partial` holds the current `AssistantMessage` state. Update `output.content` as chunks arrive, then pass `output` as `partial`.
131
+ 1. `{ type: "start", partial: output }` — stream started.
132
+ 2. Content block events (repeatable; `contentIndex` is the block's index in `output.content`):
133
+ - Text: `text_start`, `text_delta` (`delta`), `text_end` (`content`)
134
+ - Thinking: `thinking_start`, `thinking_delta` (`delta`), `thinking_end` (`content`)
135
+ - Tool calls: `toolcall_start`, `toolcall_delta` (`delta`), `toolcall_end` (`toolCall`)
136
+ 3. Terminal event: `{ type: "done", reason, message }` or `{ type: "error", reason, error }`, followed by `stream.end()`.
136
137
 
137
- ### Stop reasons
138
+ `partial` always carries the current `AssistantMessage` state. Mutate `output.content` before pushing each event, then pass `output` as `partial`.
138
139
 
139
- `StopReason` is `"pending" | "stop" | "length" | "toolUse" | "error" | "aborted" | "deferred"` (`"deferred"` is for deferred batch APIs).
140
+ ## Stop reasons
140
141
 
141
- Initialize every in-flight message to `"pending"`. When the provider emits its terminal event, assign the mapped reason before pushing `done`.
142
+ `StopReason` is `"pending" | "stop" | "length" | "toolUse" | "error" | "aborted" | "deferred"` (`"deferred"` is for asynchronous batch APIs).
142
143
 
143
- Run two checks before `done`:
144
+ Initialize every in-flight message to `"pending"`. Assign the mapped reason when the provider emits its terminal event, and run two checks before pushing `done`:
144
145
 
145
- - If `output.stopReason` is still `"pending"`, throw an error so a stream without a terminal event does not appear complete.
146
+ - If `output.stopReason` is still `"pending"`, throw an error so a stream that drops before its terminal event does not appear complete.
146
147
  - If `output.stopReason` is `"error"` or `"aborted"`, throw `output.errorMessage` so the `catch` block emits an `error` event.
147
148
 
148
- `done` accepts only `"stop"`, `"length"`, and `"toolUse"`, which matches what remains after those two checks.
149
+ After those two checks, the remaining terminal reasons (`"stop"`, `"length"`, `"toolUse"`, and `"deferred"`) are all valid for `done`.
149
150
 
150
- Map every raw stop reason your provider sends onto one of the terminal values, and **throw on any unrecognized reason** instead of falling back to `"stop"`. Store the provider's original string in `rawStopReason` when needed.
151
+ Map every upstream finish reason explicitly and **throw on any unrecognized value** instead of falling back to `"stop"`. Store the provider's original string in `output.rawStopReason` when helpful for diagnostics.
151
152
 
152
- ### Content blocks
153
+ ## Content blocks
153
154
 
154
- Append content blocks to `output.content` as they arrive:
155
+ Append each new block to `output.content`, update it as deltas arrive, and emit its closing event:
155
156
 
156
157
  ```typescript
157
158
  // Start text block
158
159
  output.content.push({ type: "text", text: "" });
159
- stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
160
+ const contentIndex = output.content.length - 1;
161
+ stream.push({ type: "text_start", contentIndex, partial: output });
160
162
 
161
163
  // Append text delta
162
164
  const block = output.content[contentIndex];
@@ -166,22 +168,30 @@ if (block.type === "text") {
166
168
  }
167
169
 
168
170
  // Complete text block
169
- stream.push({ type: "text_end", contentIndex, content: block.text, partial: output });
171
+ if (block.type === "text") {
172
+ stream.push({ type: "text_end", contentIndex, content: block.text, partial: output });
173
+ }
170
174
  ```
171
175
 
172
- ### Tool calls
176
+ Thinking blocks follow the same lifecycle with `{ type: "thinking", thinking: "" }` and `thinking_start` / `thinking_delta` / `thinking_end`.
177
+
178
+ ## Tool calls
173
179
 
174
- Tool call arguments stream as JSON text. `ToolCallArgumentsStream` from `@bastani/atomic-ai` parses each delta incrementally instead of re-parsing the full text on every chunk:
180
+ Tool call arguments stream as JSON fragments. Use `ToolCallArgumentsStream` from `@bastani/atomic-ai` to parse deltas incrementally rather than re-parsing the entire buffer on every chunk:
175
181
 
176
182
  ```typescript
183
+ import { ToolCallArgumentsStream } from "@bastani/atomic-ai";
184
+
177
185
  // Start tool call
178
- output.content.push({
179
- type: "toolCall",
186
+ const block = {
187
+ type: "toolCall" as const,
180
188
  id: toolCallId,
181
189
  name: toolName,
182
- arguments: {}
183
- });
184
- stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
190
+ arguments: {},
191
+ };
192
+ output.content.push(block);
193
+ const contentIndex = output.content.length - 1;
194
+ stream.push({ type: "toolcall_start", contentIndex, partial: output });
185
195
 
186
196
  const args = new ToolCallArgumentsStream();
187
197
 
@@ -189,12 +199,12 @@ const args = new ToolCallArgumentsStream();
189
199
  block.arguments = args.append(jsonDelta);
190
200
  stream.push({ type: "toolcall_delta", contentIndex, delta: jsonDelta, partial: output });
191
201
 
192
- // Finalize: full parse; malformed arguments record `argumentsError`
202
+ // Finalize: full parse; malformed JSON records `argumentsError` on `block`
193
203
  Object.assign(block, args.finish());
194
204
  stream.push({ type: "toolcall_end", contentIndex, toolCall: block, partial: output });
195
205
  ```
196
206
 
197
- ### Usage and cost
207
+ ## Usage and cost
198
208
 
199
209
  Populate `output.usage` from the provider response and call `calculateCost()`:
200
210
 
@@ -211,11 +221,11 @@ output.usage.totalTokens =
211
221
  calculateCost(model, output.usage);
212
222
  ```
213
223
 
214
- `calculateCost(model, output.usage)` mutates `output.usage.cost` in place and returns it. It applies one rate set to the whole request. Aggregate input is `usage.input + usage.cacheRead + usage.cacheWrite`; a tier applies only when that total strictly exceeds `inputTokensAbove`, and the highest matching threshold wins. Every tier must define `input`, `output`, `cacheRead`, and `cacheWrite`. Extension-registered models keep these tiers, and `models.json` `modelOverrides` follow the rules in [Request-wide cost tiers](/models/reference#request-wide-cost-tiers).
224
+ `calculateCost(model, output.usage)` mutates `output.usage.cost` in place and returns it, applying any long-context `cost.tiers` configured on the model. See [Request-wide cost tiers](/models/reference#request-wide-cost-tiers) for threshold matching and `modelOverrides` rules.
215
225
 
216
- ### Registration
226
+ ## Registration
217
227
 
218
- Register your stream handler with `atomic.registerProvider()`. Providing `streamSimple` requires `api` at the provider level and suppresses derived `-fast` variants for that `api`:
228
+ Pass `streamSimple` alongside a provider-level `api` string in `atomic.registerProvider()`. Supplying `streamSimple` requires `api` at the provider level and suppresses derived `-fast` variants for that `api`:
219
229
 
220
230
  ```typescript
221
231
  await atomic.registerProvider("my-provider", {
@@ -230,9 +240,13 @@ await atomic.registerProvider("my-provider", {
230
240
  input: ["text"],
231
241
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
232
242
  contextWindow: 128000,
233
- maxTokens: 8192
234
- }
243
+ maxTokens: 8192,
244
+ },
235
245
  ],
236
- streamSimple: streamMyProvider
246
+ streamSimple: streamMyProvider,
237
247
  });
238
248
  ```
249
+
250
+ <Tip>
251
+ For general streaming utilities, transcript helpers, and standalone `@bastani/atomic-ai` usage outside extensions, see the [AI library reference](/libraries/ai).
252
+ </Tip>