@openadapter/koda 1.0.0-beta.3

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 (357) hide show
  1. package/CHANGELOG.md +4448 -0
  2. package/README.md +665 -0
  3. package/dist/bun/cli.d.ts +2 -0
  4. package/dist/bun/cli.js +2 -0
  5. package/dist/bun/register-bedrock.d.ts +1 -0
  6. package/dist/bun/register-bedrock.js +1 -0
  7. package/dist/bun/restore-sandbox-env.d.ts +12 -0
  8. package/dist/bun/restore-sandbox-env.js +1 -0
  9. package/dist/cli/args.d.ts +55 -0
  10. package/dist/cli/args.js +167 -0
  11. package/dist/cli/config-selector.d.ts +13 -0
  12. package/dist/cli/config-selector.js +1 -0
  13. package/dist/cli/file-processor.d.ts +14 -0
  14. package/dist/cli/file-processor.js +7 -0
  15. package/dist/cli/import-sessions.d.ts +34 -0
  16. package/dist/cli/import-sessions.js +6 -0
  17. package/dist/cli/initial-message.d.ts +17 -0
  18. package/dist/cli/initial-message.js +1 -0
  19. package/dist/cli/list-models.d.ts +8 -0
  20. package/dist/cli/list-models.js +2 -0
  21. package/dist/cli/openadapter-setup.d.ts +29 -0
  22. package/dist/cli/openadapter-setup.js +3 -0
  23. package/dist/cli/session-picker.d.ts +8 -0
  24. package/dist/cli/session-picker.js +1 -0
  25. package/dist/cli.d.ts +2 -0
  26. package/dist/cli.js +2 -0
  27. package/dist/config.d.ts +92 -0
  28. package/dist/config.js +1 -0
  29. package/dist/core/agent-session-runtime.d.ts +116 -0
  30. package/dist/core/agent-session-runtime.js +1 -0
  31. package/dist/core/agent-session-services.d.ts +86 -0
  32. package/dist/core/agent-session-services.js +1 -0
  33. package/dist/core/agent-session.d.ts +747 -0
  34. package/dist/core/agent-session.js +32 -0
  35. package/dist/core/auth-guidance.d.ts +4 -0
  36. package/dist/core/auth-guidance.js +8 -0
  37. package/dist/core/auth-storage.d.ts +140 -0
  38. package/dist/core/auth-storage.js +1 -0
  39. package/dist/core/bash-executor.d.ts +31 -0
  40. package/dist/core/bash-executor.js +1 -0
  41. package/dist/core/compaction/branch-summarization.d.ts +89 -0
  42. package/dist/core/compaction/branch-summarization.js +38 -0
  43. package/dist/core/compaction/compaction.d.ts +120 -0
  44. package/dist/core/compaction/compaction.js +104 -0
  45. package/dist/core/compaction/index.d.ts +6 -0
  46. package/dist/core/compaction/index.js +1 -0
  47. package/dist/core/compaction/utils.d.ts +37 -0
  48. package/dist/core/compaction/utils.js +19 -0
  49. package/dist/core/defaults.d.ts +2 -0
  50. package/dist/core/defaults.js +1 -0
  51. package/dist/core/diagnostics.d.ts +14 -0
  52. package/dist/core/diagnostics.js +0 -0
  53. package/dist/core/event-bus.d.ts +8 -0
  54. package/dist/core/event-bus.js +1 -0
  55. package/dist/core/exec.d.ts +28 -0
  56. package/dist/core/exec.js +1 -0
  57. package/dist/core/export-html/ansi-to-html.d.ts +21 -0
  58. package/dist/core/export-html/ansi-to-html.js +1 -0
  59. package/dist/core/export-html/index.d.ts +36 -0
  60. package/dist/core/export-html/index.js +2 -0
  61. package/dist/core/export-html/template.css +1066 -0
  62. package/dist/core/export-html/template.html +55 -0
  63. package/dist/core/export-html/template.js +72 -0
  64. package/dist/core/export-html/tool-renderer.d.ts +33 -0
  65. package/dist/core/export-html/tool-renderer.js +1 -0
  66. package/dist/core/export-html/vendor/highlight.min.js +8 -0
  67. package/dist/core/export-html/vendor/marked.min.js +56 -0
  68. package/dist/core/extensions/index.d.ts +11 -0
  69. package/dist/core/extensions/index.js +1 -0
  70. package/dist/core/extensions/loader.d.ts +23 -0
  71. package/dist/core/extensions/loader.js +1 -0
  72. package/dist/core/extensions/runner.d.ts +160 -0
  73. package/dist/core/extensions/runner.js +1 -0
  74. package/dist/core/extensions/types.d.ts +1180 -0
  75. package/dist/core/extensions/types.js +1 -0
  76. package/dist/core/extensions/wrapper.d.ts +19 -0
  77. package/dist/core/extensions/wrapper.js +1 -0
  78. package/dist/core/footer-data-provider.d.ts +53 -0
  79. package/dist/core/footer-data-provider.js +1 -0
  80. package/dist/core/http-dispatcher.d.ts +20 -0
  81. package/dist/core/http-dispatcher.js +1 -0
  82. package/dist/core/index.d.ts +11 -0
  83. package/dist/core/index.js +1 -0
  84. package/dist/core/keybindings.d.ts +352 -0
  85. package/dist/core/keybindings.js +1 -0
  86. package/dist/core/messages.d.ts +76 -0
  87. package/dist/core/messages.js +17 -0
  88. package/dist/core/model-registry.d.ts +149 -0
  89. package/dist/core/model-registry.js +9 -0
  90. package/dist/core/model-resolver.d.ts +109 -0
  91. package/dist/core/model-resolver.js +1 -0
  92. package/dist/core/output-guard.d.ts +6 -0
  93. package/dist/core/output-guard.js +1 -0
  94. package/dist/core/package-manager.d.ts +203 -0
  95. package/dist/core/package-manager.js +3 -0
  96. package/dist/core/prompt-templates.d.ts +51 -0
  97. package/dist/core/prompt-templates.js +2 -0
  98. package/dist/core/provider-attribution.d.ts +3 -0
  99. package/dist/core/provider-attribution.js +1 -0
  100. package/dist/core/provider-display-names.d.ts +1 -0
  101. package/dist/core/provider-display-names.js +1 -0
  102. package/dist/core/resolve-config-value.d.ts +30 -0
  103. package/dist/core/resolve-config-value.js +1 -0
  104. package/dist/core/resource-loader.d.ts +193 -0
  105. package/dist/core/resource-loader.js +1 -0
  106. package/dist/core/sdk.d.ts +108 -0
  107. package/dist/core/sdk.js +1 -0
  108. package/dist/core/session-cwd.d.ts +18 -0
  109. package/dist/core/session-cwd.js +7 -0
  110. package/dist/core/session-manager.d.ts +331 -0
  111. package/dist/core/session-manager.js +11 -0
  112. package/dist/core/settings-manager.d.ts +265 -0
  113. package/dist/core/settings-manager.js +1 -0
  114. package/dist/core/skills.d.ts +59 -0
  115. package/dist/core/skills.js +4 -0
  116. package/dist/core/slash-commands.d.ts +13 -0
  117. package/dist/core/slash-commands.js +1 -0
  118. package/dist/core/source-info.d.ts +17 -0
  119. package/dist/core/source-info.js +1 -0
  120. package/dist/core/system-prompt.d.ts +27 -0
  121. package/dist/core/system-prompt.js +52 -0
  122. package/dist/core/telemetry.d.ts +2 -0
  123. package/dist/core/telemetry.js +1 -0
  124. package/dist/core/timings.d.ts +7 -0
  125. package/dist/core/timings.js +3 -0
  126. package/dist/core/tools/bash.d.ts +67 -0
  127. package/dist/core/tools/bash.js +18 -0
  128. package/dist/core/tools/edit-diff.d.ts +86 -0
  129. package/dist/core/tools/edit-diff.js +16 -0
  130. package/dist/core/tools/edit.d.ts +50 -0
  131. package/dist/core/tools/edit.js +2 -0
  132. package/dist/core/tools/file-mutation-queue.d.ts +5 -0
  133. package/dist/core/tools/file-mutation-queue.js +1 -0
  134. package/dist/core/tools/find.d.ts +34 -0
  135. package/dist/core/tools/find.js +13 -0
  136. package/dist/core/tools/grep.d.ts +36 -0
  137. package/dist/core/tools/grep.js +13 -0
  138. package/dist/core/tools/index.d.ts +39 -0
  139. package/dist/core/tools/index.js +1 -0
  140. package/dist/core/tools/ls.d.ts +36 -0
  141. package/dist/core/tools/ls.js +9 -0
  142. package/dist/core/tools/output-accumulator.d.ts +51 -0
  143. package/dist/core/tools/output-accumulator.js +4 -0
  144. package/dist/core/tools/path-utils.d.ts +9 -0
  145. package/dist/core/tools/path-utils.js +1 -0
  146. package/dist/core/tools/read.d.ts +34 -0
  147. package/dist/core/tools/read.js +22 -0
  148. package/dist/core/tools/render-utils.d.ts +23 -0
  149. package/dist/core/tools/render-utils.js +4 -0
  150. package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
  151. package/dist/core/tools/tool-definition-wrapper.js +1 -0
  152. package/dist/core/tools/truncate.d.ts +69 -0
  153. package/dist/core/tools/truncate.js +5 -0
  154. package/dist/core/tools/write.d.ts +25 -0
  155. package/dist/core/tools/write.js +13 -0
  156. package/dist/index.d.ts +30 -0
  157. package/dist/index.js +1 -0
  158. package/dist/main.d.ts +11 -0
  159. package/dist/main.js +1 -0
  160. package/dist/migrations.d.ts +32 -0
  161. package/dist/migrations.js +8 -0
  162. package/dist/modes/index.d.ts +8 -0
  163. package/dist/modes/index.js +1 -0
  164. package/dist/modes/interactive/assets/clankolas.png +0 -0
  165. package/dist/modes/interactive/components/armin.d.ts +33 -0
  166. package/dist/modes/interactive/components/armin.js +1 -0
  167. package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
  168. package/dist/modes/interactive/components/assistant-message.js +1 -0
  169. package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
  170. package/dist/modes/interactive/components/bash-execution.js +13 -0
  171. package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
  172. package/dist/modes/interactive/components/bordered-loader.js +1 -0
  173. package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
  174. package/dist/modes/interactive/components/branch-summary-message.js +3 -0
  175. package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
  176. package/dist/modes/interactive/components/compaction-summary-message.js +3 -0
  177. package/dist/modes/interactive/components/config-selector.d.ts +70 -0
  178. package/dist/modes/interactive/components/config-selector.js +1 -0
  179. package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
  180. package/dist/modes/interactive/components/countdown-timer.js +1 -0
  181. package/dist/modes/interactive/components/custom-editor.d.ts +20 -0
  182. package/dist/modes/interactive/components/custom-editor.js +1 -0
  183. package/dist/modes/interactive/components/custom-message.d.ts +19 -0
  184. package/dist/modes/interactive/components/custom-message.js +2 -0
  185. package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
  186. package/dist/modes/interactive/components/daxnuts.js +1 -0
  187. package/dist/modes/interactive/components/diff.d.ts +11 -0
  188. package/dist/modes/interactive/components/diff.js +3 -0
  189. package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
  190. package/dist/modes/interactive/components/dynamic-border.js +1 -0
  191. package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
  192. package/dist/modes/interactive/components/earendil-announcement.js +1 -0
  193. package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
  194. package/dist/modes/interactive/components/extension-editor.js +3 -0
  195. package/dist/modes/interactive/components/extension-input.d.ts +22 -0
  196. package/dist/modes/interactive/components/extension-input.js +2 -0
  197. package/dist/modes/interactive/components/extension-selector.d.ts +25 -0
  198. package/dist/modes/interactive/components/extension-selector.js +2 -0
  199. package/dist/modes/interactive/components/footer.d.ts +27 -0
  200. package/dist/modes/interactive/components/footer.js +1 -0
  201. package/dist/modes/interactive/components/index.d.ts +31 -0
  202. package/dist/modes/interactive/components/index.js +1 -0
  203. package/dist/modes/interactive/components/keybinding-hints.d.ts +12 -0
  204. package/dist/modes/interactive/components/keybinding-hints.js +1 -0
  205. package/dist/modes/interactive/components/login-dialog.d.ts +51 -0
  206. package/dist/modes/interactive/components/login-dialog.js +1 -0
  207. package/dist/modes/interactive/components/model-selector.d.ts +46 -0
  208. package/dist/modes/interactive/components/model-selector.js +2 -0
  209. package/dist/modes/interactive/components/oauth-selector.d.ts +30 -0
  210. package/dist/modes/interactive/components/oauth-selector.js +1 -0
  211. package/dist/modes/interactive/components/scoped-models-selector.d.ts +41 -0
  212. package/dist/modes/interactive/components/scoped-models-selector.js +1 -0
  213. package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
  214. package/dist/modes/interactive/components/session-selector-search.js +1 -0
  215. package/dist/modes/interactive/components/session-selector.d.ts +95 -0
  216. package/dist/modes/interactive/components/session-selector.js +2 -0
  217. package/dist/modes/interactive/components/settings-selector.d.ts +68 -0
  218. package/dist/modes/interactive/components/settings-selector.js +1 -0
  219. package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
  220. package/dist/modes/interactive/components/show-images-selector.js +1 -0
  221. package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
  222. package/dist/modes/interactive/components/skill-invocation-message.js +3 -0
  223. package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
  224. package/dist/modes/interactive/components/theme-selector.js +1 -0
  225. package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
  226. package/dist/modes/interactive/components/thinking-selector.js +1 -0
  227. package/dist/modes/interactive/components/tool-execution.d.ts +62 -0
  228. package/dist/modes/interactive/components/tool-execution.js +4 -0
  229. package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
  230. package/dist/modes/interactive/components/tree-selector.js +1 -0
  231. package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
  232. package/dist/modes/interactive/components/user-message-selector.js +1 -0
  233. package/dist/modes/interactive/components/user-message.d.ts +9 -0
  234. package/dist/modes/interactive/components/user-message.js +1 -0
  235. package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
  236. package/dist/modes/interactive/components/visual-truncate.js +1 -0
  237. package/dist/modes/interactive/interactive-mode.d.ts +417 -0
  238. package/dist/modes/interactive/interactive-mode.js +116 -0
  239. package/dist/modes/interactive/theme/dark.json +86 -0
  240. package/dist/modes/interactive/theme/light.json +85 -0
  241. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  242. package/dist/modes/interactive/theme/theme.d.ts +101 -0
  243. package/dist/modes/interactive/theme/theme.js +18 -0
  244. package/dist/modes/print-mode.d.ts +27 -0
  245. package/dist/modes/print-mode.js +4 -0
  246. package/dist/modes/rpc/jsonl.d.ts +16 -0
  247. package/dist/modes/rpc/jsonl.js +3 -0
  248. package/dist/modes/rpc/rpc-client.d.ts +226 -0
  249. package/dist/modes/rpc/rpc-client.js +1 -0
  250. package/dist/modes/rpc/rpc-mode.d.ts +19 -0
  251. package/dist/modes/rpc/rpc-mode.js +1 -0
  252. package/dist/modes/rpc/rpc-types.d.ts +419 -0
  253. package/dist/modes/rpc/rpc-types.js +0 -0
  254. package/dist/package-manager-cli.d.ts +3 -0
  255. package/dist/package-manager-cli.js +49 -0
  256. package/dist/utils/ansi.d.ts +1 -0
  257. package/dist/utils/ansi.js +1 -0
  258. package/dist/utils/auto-update.d.ts +13 -0
  259. package/dist/utils/auto-update.js +1 -0
  260. package/dist/utils/changelog.d.ts +20 -0
  261. package/dist/utils/changelog.js +4 -0
  262. package/dist/utils/child-process.d.ts +14 -0
  263. package/dist/utils/child-process.js +1 -0
  264. package/dist/utils/clipboard-image.d.ts +10 -0
  265. package/dist/utils/clipboard-image.js +1 -0
  266. package/dist/utils/clipboard-native.d.ts +9 -0
  267. package/dist/utils/clipboard-native.js +1 -0
  268. package/dist/utils/clipboard.d.ts +1 -0
  269. package/dist/utils/clipboard.js +1 -0
  270. package/dist/utils/deprecation.d.ts +3 -0
  271. package/dist/utils/deprecation.js +1 -0
  272. package/dist/utils/exif-orientation.d.ts +4 -0
  273. package/dist/utils/exif-orientation.js +1 -0
  274. package/dist/utils/frontmatter.d.ts +7 -0
  275. package/dist/utils/frontmatter.js +4 -0
  276. package/dist/utils/fs-watch.d.ts +4 -0
  277. package/dist/utils/fs-watch.js +1 -0
  278. package/dist/utils/git.d.ts +25 -0
  279. package/dist/utils/git.js +1 -0
  280. package/dist/utils/html.d.ts +6 -0
  281. package/dist/utils/html.js +1 -0
  282. package/dist/utils/image-convert.d.ts +8 -0
  283. package/dist/utils/image-convert.js +1 -0
  284. package/dist/utils/image-resize-core.d.ts +29 -0
  285. package/dist/utils/image-resize-core.js +1 -0
  286. package/dist/utils/image-resize-worker.d.ts +1 -0
  287. package/dist/utils/image-resize-worker.js +1 -0
  288. package/dist/utils/image-resize.d.ts +15 -0
  289. package/dist/utils/image-resize.js +1 -0
  290. package/dist/utils/json.d.ts +2 -0
  291. package/dist/utils/json.js +1 -0
  292. package/dist/utils/koda-user-agent.d.ts +1 -0
  293. package/dist/utils/koda-user-agent.js +1 -0
  294. package/dist/utils/mime.d.ts +2 -0
  295. package/dist/utils/mime.js +1 -0
  296. package/dist/utils/paths.d.ts +30 -0
  297. package/dist/utils/paths.js +1 -0
  298. package/dist/utils/photon.d.ts +20 -0
  299. package/dist/utils/photon.js +1 -0
  300. package/dist/utils/shell.d.ts +29 -0
  301. package/dist/utils/shell.js +8 -0
  302. package/dist/utils/sleep.d.ts +4 -0
  303. package/dist/utils/sleep.js +1 -0
  304. package/dist/utils/syntax-highlight.d.ts +11 -0
  305. package/dist/utils/syntax-highlight.js +2 -0
  306. package/dist/utils/tools-manager.d.ts +2 -0
  307. package/dist/utils/tools-manager.js +1 -0
  308. package/dist/utils/version-check.d.ts +14 -0
  309. package/dist/utils/version-check.js +1 -0
  310. package/dist/utils/windows-self-update.d.ts +2 -0
  311. package/dist/utils/windows-self-update.js +1 -0
  312. package/docs/compaction.md +394 -0
  313. package/docs/custom-provider.md +736 -0
  314. package/docs/development.md +71 -0
  315. package/docs/docs.json +148 -0
  316. package/docs/extensions.md +2626 -0
  317. package/docs/images/doom-extension.png +0 -0
  318. package/docs/images/exy.png +0 -0
  319. package/docs/images/interactive-mode.png +0 -0
  320. package/docs/images/tree-view.png +0 -0
  321. package/docs/index.md +80 -0
  322. package/docs/json.md +82 -0
  323. package/docs/keybindings.md +197 -0
  324. package/docs/models.md +493 -0
  325. package/docs/packages.md +226 -0
  326. package/docs/prompt-templates.md +88 -0
  327. package/docs/providers.md +253 -0
  328. package/docs/quickstart.md +165 -0
  329. package/docs/rpc.md +1408 -0
  330. package/docs/sdk.md +1137 -0
  331. package/docs/session-format.md +412 -0
  332. package/docs/sessions.md +145 -0
  333. package/docs/settings.md +281 -0
  334. package/docs/shell-aliases.md +13 -0
  335. package/docs/skills.md +231 -0
  336. package/docs/terminal-setup.md +114 -0
  337. package/docs/termux.md +127 -0
  338. package/docs/themes.md +295 -0
  339. package/docs/tmux.md +61 -0
  340. package/docs/tui.md +927 -0
  341. package/docs/usage.md +288 -0
  342. package/docs/windows.md +17 -0
  343. package/npm-shrinkwrap.json +1792 -0
  344. package/openadapter/extensions/koda-ask.js +12 -0
  345. package/openadapter/extensions/koda-bg.js +14 -0
  346. package/openadapter/extensions/koda-commands.mjs +15 -0
  347. package/openadapter/extensions/koda-help.js +8 -0
  348. package/openadapter/extensions/koda-memory.js +16 -0
  349. package/openadapter/extensions/koda-status.js +1 -0
  350. package/openadapter/extensions/koda-todo.js +4 -0
  351. package/openadapter/extensions/koda-vision.js +4 -0
  352. package/openadapter/extensions/koda-web.js +7 -0
  353. package/openadapter/setup.mjs +173 -0
  354. package/openadapter/skills/code-review/SKILL.md +22 -0
  355. package/openadapter/skills/debugging/SKILL.md +28 -0
  356. package/openadapter/skills/frontend/SKILL.md +38 -0
  357. package/package.json +108 -0
@@ -0,0 +1,736 @@
1
+ # Custom Providers
2
+
3
+ Extensions can register custom model providers via `pi.registerProvider()`. This enables:
4
+
5
+ - **Proxies** - Route requests through corporate proxies or API gateways
6
+ - **Custom endpoints** - Use self-hosted or private model deployments
7
+ - **OAuth/SSO** - Add authentication flows for enterprise providers
8
+ - **Custom APIs** - Implement streaming for non-standard LLM APIs
9
+
10
+ ## Example Extensions
11
+
12
+ See these complete provider examples:
13
+
14
+ - [`examples/extensions/custom-provider-anthropic/`](../examples/extensions/custom-provider-anthropic/)
15
+ - [`examples/extensions/custom-provider-gitlab-duo/`](../examples/extensions/custom-provider-gitlab-duo/)
16
+
17
+ ## Table of Contents
18
+
19
+ - [Example Extensions](#example-extensions)
20
+ - [Quick Reference](#quick-reference)
21
+ - [Override Existing Provider](#override-existing-provider)
22
+ - [Register New Provider](#register-new-provider)
23
+ - [Unregister Provider](#unregister-provider)
24
+ - [OAuth Support](#oauth-support)
25
+ - [Custom Streaming API](#custom-streaming-api)
26
+ - [Context Overflow Errors](#context-overflow-errors)
27
+ - [Testing Your Implementation](#testing-your-implementation)
28
+ - [Config Reference](#config-reference)
29
+ - [Model Definition Reference](#model-definition-reference)
30
+
31
+ ## Quick Reference
32
+
33
+ ```typescript
34
+ import type { ExtensionAPI } from "@openadapter/koda";
35
+
36
+ export default function (pi: ExtensionAPI) {
37
+ // Override baseUrl for existing provider
38
+ pi.registerProvider("anthropic", {
39
+ baseUrl: "https://proxy.example.com"
40
+ });
41
+
42
+ // Register new provider with models
43
+ pi.registerProvider("my-provider", {
44
+ name: "My Provider",
45
+ baseUrl: "https://api.example.com",
46
+ apiKey: "$MY_API_KEY",
47
+ api: "openai-completions",
48
+ models: [
49
+ {
50
+ id: "my-model",
51
+ name: "My Model",
52
+ reasoning: false,
53
+ input: ["text", "image"],
54
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
55
+ contextWindow: 128000,
56
+ maxTokens: 4096
57
+ }
58
+ ]
59
+ });
60
+ }
61
+ ```
62
+
63
+ The extension factory can also be `async`. For dynamic model discovery, fetch and register models in the factory instead of `session_start`. pi waits for the factory before startup continues, so the provider is available during interactive startup and to `pi --list-models`.
64
+
65
+ ## Override Existing Provider
66
+
67
+ The simplest use case: redirect an existing provider through a proxy.
68
+
69
+ ```typescript
70
+ // All Anthropic requests now go through your proxy
71
+ pi.registerProvider("anthropic", {
72
+ baseUrl: "https://proxy.example.com"
73
+ });
74
+
75
+ // Add custom headers to OpenAI requests
76
+ pi.registerProvider("openai", {
77
+ headers: {
78
+ "X-Custom-Header": "value"
79
+ }
80
+ });
81
+
82
+ // Both baseUrl and headers
83
+ pi.registerProvider("google", {
84
+ baseUrl: "https://ai-gateway.corp.com/google",
85
+ headers: {
86
+ "X-Corp-Auth": "$CORP_AUTH_TOKEN" // env var or literal
87
+ }
88
+ });
89
+ ```
90
+
91
+ When only `baseUrl` and/or `headers` are provided (no `models`), all existing models for that provider are preserved with the new endpoint.
92
+
93
+ ## Register New Provider
94
+
95
+ To add a completely new provider, specify `models` along with the required configuration.
96
+
97
+ If the model list comes from a remote endpoint, use an async extension factory:
98
+
99
+ ```typescript
100
+ import type { ExtensionAPI } from "@openadapter/koda";
101
+
102
+ export default async function (pi: ExtensionAPI) {
103
+ const response = await fetch("http://localhost:1234/v1/models");
104
+ const payload = (await response.json()) as {
105
+ data: Array<{
106
+ id: string;
107
+ name?: string;
108
+ context_window?: number;
109
+ max_tokens?: number;
110
+ }>;
111
+ };
112
+
113
+ pi.registerProvider("local-openai", {
114
+ baseUrl: "http://localhost:1234/v1",
115
+ apiKey: "$LOCAL_OPENAI_API_KEY",
116
+ api: "openai-completions",
117
+ models: payload.data.map((model) => ({
118
+ id: model.id,
119
+ name: model.name ?? model.id,
120
+ reasoning: false,
121
+ input: ["text"],
122
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
123
+ contextWindow: model.context_window ?? 128000,
124
+ maxTokens: model.max_tokens ?? 4096,
125
+ })),
126
+ });
127
+ }
128
+ ```
129
+
130
+ This registers the fetched models before startup finishes.
131
+
132
+ ```typescript
133
+ pi.registerProvider("my-llm", {
134
+ baseUrl: "https://api.my-llm.com/v1",
135
+ apiKey: "$MY_LLM_API_KEY", // env var reference
136
+ api: "openai-completions", // which streaming API to use
137
+ models: [
138
+ {
139
+ id: "my-llm-large",
140
+ name: "My LLM Large",
141
+ reasoning: true, // supports extended thinking
142
+ input: ["text", "image"],
143
+ cost: {
144
+ input: 3.0, // $/million tokens
145
+ output: 15.0,
146
+ cacheRead: 0.3,
147
+ cacheWrite: 3.75
148
+ },
149
+ contextWindow: 200000,
150
+ maxTokens: 16384
151
+ }
152
+ ]
153
+ });
154
+ ```
155
+
156
+ When `models` is provided, it **replaces** all existing models for that provider.
157
+
158
+ `apiKey` and custom header values use the same config value syntax as `models.json`: `!command` at the start executes a command for the whole value, `$ENV_VAR` and `${ENV_VAR}` interpolate environment variables, `$$` emits a literal `$`, and `$!` emits a literal `!`.
159
+
160
+ ## Unregister Provider
161
+
162
+ Use `pi.unregisterProvider(name)` to remove a provider that was previously registered via `pi.registerProvider(name, ...)`:
163
+
164
+ ```typescript
165
+ // Register
166
+ pi.registerProvider("my-llm", {
167
+ baseUrl: "https://api.my-llm.com/v1",
168
+ apiKey: "$MY_LLM_API_KEY",
169
+ api: "openai-completions",
170
+ models: [
171
+ {
172
+ id: "my-llm-large",
173
+ name: "My LLM Large",
174
+ reasoning: true,
175
+ input: ["text", "image"],
176
+ cost: { input: 3.0, output: 15.0, cacheRead: 0.3, cacheWrite: 3.75 },
177
+ contextWindow: 200000,
178
+ maxTokens: 16384
179
+ }
180
+ ]
181
+ });
182
+
183
+ // Later, remove it
184
+ pi.unregisterProvider("my-llm");
185
+ ```
186
+
187
+ Unregistering removes that provider's dynamic models, API key fallback, OAuth provider registration, and custom stream handler registrations. Any built-in models or provider behavior that were overridden are restored.
188
+
189
+ Calls made after the initial extension load phase are applied immediately, so no `/reload` is required.
190
+
191
+ ### API Types
192
+
193
+ The `api` field determines which streaming implementation is used:
194
+
195
+ | API | Use for |
196
+ |-----|---------|
197
+ | `anthropic-messages` | Anthropic Claude API and compatibles |
198
+ | `openai-completions` | OpenAI Chat Completions API and compatibles |
199
+ | `openai-responses` | OpenAI Responses API |
200
+ | `azure-openai-responses` | Azure OpenAI Responses API |
201
+ | `openai-codex-responses` | OpenAI Codex Responses API |
202
+ | `mistral-conversations` | Mistral SDK Conversations/Chat streaming |
203
+ | `google-generative-ai` | Google Generative AI API |
204
+ | `google-vertex` | Google Vertex AI API |
205
+ | `bedrock-converse-stream` | Amazon Bedrock Converse API |
206
+
207
+ Most OpenAI-compatible providers work with `openai-completions`. Use model-level `thinkingLevelMap` for model-specific thinking levels, and `compat` for provider quirks:
208
+
209
+ ```typescript
210
+ models: [{
211
+ id: "custom-model",
212
+ // ...
213
+ reasoning: true,
214
+ thinkingLevelMap: { // map pi levels to provider values; null hides unsupported levels
215
+ minimal: null,
216
+ low: null,
217
+ medium: null,
218
+ high: "default",
219
+ xhigh: "max"
220
+ },
221
+ compat: {
222
+ supportsDeveloperRole: false, // use "system" instead of "developer"
223
+ supportsReasoningEffort: true,
224
+ maxTokensField: "max_tokens", // instead of "max_completion_tokens"
225
+ requiresToolResultName: true, // tool results need name field
226
+ thinkingFormat: "qwen", // top-level enable_thinking: true
227
+ cacheControlFormat: "anthropic" // Anthropic-style cache_control markers
228
+ }
229
+ }]
230
+ ```
231
+
232
+ Use `openrouter` for OpenRouter-style `reasoning: { effort }` controls. Use `together` for Together-style `reasoning: { enabled }` controls; with `supportsReasoningEffort`, it also sends `reasoning_effort`. Use `qwen-chat-template` instead for local Qwen-compatible servers that read `chat_template_kwargs.enable_thinking`.
233
+ Use `cacheControlFormat: "anthropic"` for OpenAI-compatible providers that expose Anthropic-style prompt caching via `cache_control` on the system prompt, last tool definition, and last user/assistant text content.
234
+
235
+ For Anthropic-compatible providers using `api: "anthropic-messages"`, set `compat.forceAdaptiveThinking: true` on models or providers whose upstream model requires adaptive thinking (`thinking.type: "adaptive"` plus `output_config.effort`). Built-in adaptive Claude models set this automatically. Set `compat.allowEmptySignature: true` only for providers that emit empty thinking signatures and expect `signature: ""` on replay.
236
+
237
+ > Migration note: Mistral moved from `openai-completions` to `mistral-conversations`.
238
+ > Use `mistral-conversations` for native Mistral models.
239
+ > If you intentionally route Mistral-compatible/custom endpoints through `openai-completions`, set `compat` flags explicitly as needed.
240
+
241
+ ### Auth Header
242
+
243
+ If your provider expects `Authorization: Bearer <key>` but doesn't use a standard API, set `authHeader: true`:
244
+
245
+ ```typescript
246
+ pi.registerProvider("custom-api", {
247
+ baseUrl: "https://api.example.com",
248
+ apiKey: "$MY_API_KEY",
249
+ authHeader: true, // adds Authorization: Bearer header
250
+ api: "openai-completions",
251
+ models: [...]
252
+ });
253
+ ```
254
+
255
+ ## OAuth Support
256
+
257
+ Add OAuth/SSO authentication that integrates with `/login`:
258
+
259
+ ```typescript
260
+ import type { OAuthCredentials, OAuthLoginCallbacks } from "@openadapter/koda-ai";
261
+
262
+ pi.registerProvider("corporate-ai", {
263
+ baseUrl: "https://ai.corp.com/v1",
264
+ api: "openai-responses",
265
+ models: [...],
266
+ oauth: {
267
+ name: "Corporate AI (SSO)",
268
+
269
+ async login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
270
+ const method = await callbacks.onSelect({
271
+ message: "Select login method:",
272
+ options: [
273
+ { id: "browser", label: "Browser OAuth" },
274
+ { id: "device", label: "Device code" }
275
+ ]
276
+ });
277
+ if (!method) throw new Error("Login cancelled");
278
+
279
+ let code: string;
280
+ if (method === "device") {
281
+ callbacks.onDeviceCode({
282
+ userCode: "ABCD-1234",
283
+ verificationUri: "https://sso.corp.com/device",
284
+ intervalSeconds: 5,
285
+ expiresInSeconds: 900
286
+ });
287
+ code = await pollDeviceCodeUntilComplete();
288
+ } else {
289
+ callbacks.onAuth({ url: "https://sso.corp.com/authorize?..." });
290
+ code = await callbacks.onPrompt({ message: "Enter SSO code:" });
291
+ }
292
+
293
+ // Exchange for tokens (your implementation)
294
+ const tokens = await exchangeCodeForTokens(code);
295
+
296
+ return {
297
+ refresh: tokens.refreshToken,
298
+ access: tokens.accessToken,
299
+ expires: Date.now() + tokens.expiresIn * 1000
300
+ };
301
+ },
302
+
303
+ async refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials> {
304
+ const tokens = await refreshAccessToken(credentials.refresh);
305
+ return {
306
+ refresh: tokens.refreshToken ?? credentials.refresh,
307
+ access: tokens.accessToken,
308
+ expires: Date.now() + tokens.expiresIn * 1000
309
+ };
310
+ },
311
+
312
+ getApiKey(credentials: OAuthCredentials): string {
313
+ return credentials.access;
314
+ },
315
+
316
+ // Optional: modify models based on user's subscription
317
+ modifyModels(models, credentials) {
318
+ const region = decodeRegionFromToken(credentials.access);
319
+ return models.map(m => ({
320
+ ...m,
321
+ baseUrl: `https://${region}.ai.corp.com/v1`
322
+ }));
323
+ }
324
+ }
325
+ });
326
+ ```
327
+
328
+ After registration, users can authenticate via `/login corporate-ai`.
329
+
330
+ ### OAuthLoginCallbacks
331
+
332
+ The `callbacks` object provides three ways to authenticate:
333
+
334
+ ```typescript
335
+ interface OAuthLoginCallbacks {
336
+ // Open URL in browser (for OAuth redirects)
337
+ onAuth(params: { url: string }): void;
338
+
339
+ // Show device code (for device authorization flow)
340
+ onDeviceCode(params: {
341
+ userCode: string;
342
+ verificationUri: string;
343
+ intervalSeconds?: number;
344
+ expiresInSeconds?: number;
345
+ }): void;
346
+
347
+ // Prompt user for input (for manual token entry)
348
+ onPrompt(params: { message: string }): Promise<string>;
349
+
350
+ // Show an interactive selector, e.g. to choose browser OAuth vs device code
351
+ onSelect(params: {
352
+ message: string;
353
+ options: { id: string; label: string }[];
354
+ }): Promise<string | undefined>;
355
+ }
356
+ ```
357
+
358
+ ### OAuthCredentials
359
+
360
+ Credentials are persisted in `~/.pi/agent/auth.json`:
361
+
362
+ ```typescript
363
+ interface OAuthCredentials {
364
+ refresh: string; // Refresh token (for refreshToken())
365
+ access: string; // Access token (returned by getApiKey())
366
+ expires: number; // Expiration timestamp in milliseconds
367
+ }
368
+ ```
369
+
370
+ ## Custom Streaming API
371
+
372
+ For providers with non-standard APIs, implement `streamSimple`. Study the existing provider implementations before writing your own:
373
+
374
+ **Reference implementations:**
375
+ - [anthropic.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/providers/anthropic.ts) - Anthropic Messages API
376
+ - [mistral.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/providers/mistral.ts) - Mistral Conversations API
377
+ - [openai-completions.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/providers/openai-completions.ts) - OpenAI Chat Completions
378
+ - [openai-responses.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/providers/openai-responses.ts) - OpenAI Responses API
379
+ - [google.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/providers/google.ts) - Google Generative AI
380
+ - [amazon-bedrock.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/providers/amazon-bedrock.ts) - AWS Bedrock
381
+
382
+ ### Stream Pattern
383
+
384
+ All providers follow the same pattern:
385
+
386
+ ```typescript
387
+ import {
388
+ type AssistantMessage,
389
+ type AssistantMessageEventStream,
390
+ type Context,
391
+ type Model,
392
+ type SimpleStreamOptions,
393
+ calculateCost,
394
+ createAssistantMessageEventStream,
395
+ } from "@openadapter/koda-ai";
396
+
397
+ function streamMyProvider(
398
+ model: Model<any>,
399
+ context: Context,
400
+ options?: SimpleStreamOptions
401
+ ): AssistantMessageEventStream {
402
+ const stream = createAssistantMessageEventStream();
403
+
404
+ (async () => {
405
+ // Initialize output message
406
+ const output: AssistantMessage = {
407
+ role: "assistant",
408
+ content: [],
409
+ api: model.api,
410
+ provider: model.provider,
411
+ model: model.id,
412
+ usage: {
413
+ input: 0,
414
+ output: 0,
415
+ cacheRead: 0,
416
+ cacheWrite: 0,
417
+ totalTokens: 0,
418
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
419
+ },
420
+ stopReason: "stop",
421
+ timestamp: Date.now(),
422
+ };
423
+
424
+ try {
425
+ // Push start event
426
+ stream.push({ type: "start", partial: output });
427
+
428
+ // Make API request and process response...
429
+ // Push content events as they arrive...
430
+
431
+ // Push done event
432
+ stream.push({
433
+ type: "done",
434
+ reason: output.stopReason as "stop" | "length" | "toolUse",
435
+ message: output
436
+ });
437
+ stream.end();
438
+ } catch (error) {
439
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
440
+ output.errorMessage = error instanceof Error ? error.message : String(error);
441
+ stream.push({ type: "error", reason: output.stopReason, error: output });
442
+ stream.end();
443
+ }
444
+ })();
445
+
446
+ return stream;
447
+ }
448
+ ```
449
+
450
+ ### Event Types
451
+
452
+ Push events via `stream.push()` in this order:
453
+
454
+ 1. `{ type: "start", partial: output }` - Stream started
455
+
456
+ 2. Content events (repeatable, track `contentIndex` for each block):
457
+ - `{ type: "text_start", contentIndex, partial }` - Text block started
458
+ - `{ type: "text_delta", contentIndex, delta, partial }` - Text chunk
459
+ - `{ type: "text_end", contentIndex, content, partial }` - Text block ended
460
+ - `{ type: "thinking_start", contentIndex, partial }` - Thinking started
461
+ - `{ type: "thinking_delta", contentIndex, delta, partial }` - Thinking chunk
462
+ - `{ type: "thinking_end", contentIndex, content, partial }` - Thinking ended
463
+ - `{ type: "toolcall_start", contentIndex, partial }` - Tool call started
464
+ - `{ type: "toolcall_delta", contentIndex, delta, partial }` - Tool call JSON chunk
465
+ - `{ type: "toolcall_end", contentIndex, toolCall, partial }` - Tool call ended
466
+
467
+ 3. `{ type: "done", reason, message }` or `{ type: "error", reason, error }` - Stream ended
468
+
469
+ The `partial` field in each event contains the current `AssistantMessage` state. Update `output.content` as you receive data, then include `output` as the `partial`.
470
+
471
+ ### Content Blocks
472
+
473
+ Add content blocks to `output.content` as they arrive:
474
+
475
+ ```typescript
476
+ // Text block
477
+ output.content.push({ type: "text", text: "" });
478
+ stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
479
+
480
+ // As text arrives
481
+ const block = output.content[contentIndex];
482
+ if (block.type === "text") {
483
+ block.text += delta;
484
+ stream.push({ type: "text_delta", contentIndex, delta, partial: output });
485
+ }
486
+
487
+ // When block completes
488
+ stream.push({ type: "text_end", contentIndex, content: block.text, partial: output });
489
+ ```
490
+
491
+ ### Tool Calls
492
+
493
+ Tool calls require accumulating JSON and parsing:
494
+
495
+ ```typescript
496
+ // Start tool call
497
+ output.content.push({
498
+ type: "toolCall",
499
+ id: toolCallId,
500
+ name: toolName,
501
+ arguments: {}
502
+ });
503
+ stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
504
+
505
+ // Accumulate JSON
506
+ let partialJson = "";
507
+ partialJson += jsonDelta;
508
+ try {
509
+ block.arguments = JSON.parse(partialJson);
510
+ } catch {}
511
+ stream.push({ type: "toolcall_delta", contentIndex, delta: jsonDelta, partial: output });
512
+
513
+ // Complete
514
+ stream.push({
515
+ type: "toolcall_end",
516
+ contentIndex,
517
+ toolCall: { type: "toolCall", id, name, arguments: block.arguments },
518
+ partial: output
519
+ });
520
+ ```
521
+
522
+ ### Usage and Cost
523
+
524
+ Update usage from API response and calculate cost:
525
+
526
+ ```typescript
527
+ output.usage.input = response.usage.input_tokens;
528
+ output.usage.output = response.usage.output_tokens;
529
+ output.usage.cacheRead = response.usage.cache_read_tokens ?? 0;
530
+ output.usage.cacheWrite = response.usage.cache_write_tokens ?? 0;
531
+ output.usage.totalTokens = output.usage.input + output.usage.output +
532
+ output.usage.cacheRead + output.usage.cacheWrite;
533
+ calculateCost(model, output.usage);
534
+ ```
535
+
536
+ ### Context Overflow Errors
537
+
538
+ When a request exceeds the model's context window, pi can recover automatically by compacting the conversation and retrying. This recovery only kicks in if pi recognizes the failure as an overflow.
539
+
540
+ Detection runs on the finalized assistant message:
541
+
542
+ - `stopReason === "error"`
543
+ - `errorMessage` matches one of pi's known overflow patterns (see [`packages/ai/src/utils/overflow.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/utils/overflow.ts))
544
+
545
+ If your provider returns overflow errors with a message pi does not recognize, normalize the error from the same extension that registers the provider. Use a `message_end` handler to rewrite the assistant message so its `errorMessage` starts with a phrase pi recognizes. The generic fallback `context_length_exceeded` is the safest choice.
546
+
547
+ ```typescript
548
+ const MY_PROVIDER_OVERFLOW_PATTERN = /your provider's overflow phrase/i;
549
+
550
+ export default function (pi: ExtensionAPI) {
551
+ pi.registerProvider("my-provider", { /* ... */ });
552
+
553
+ pi.on("message_end", (event, ctx) => {
554
+ const message = event.message;
555
+ if (message.role !== "assistant") return;
556
+ if (message.stopReason !== "error") return;
557
+ if (
558
+ message.provider !== "my-provider" &&
559
+ ctx.model?.provider !== "my-provider"
560
+ )
561
+ return;
562
+
563
+ const errorMessage = message.errorMessage ?? "";
564
+ if (errorMessage.includes("context_length_exceeded")) return;
565
+ if (!MY_PROVIDER_OVERFLOW_PATTERN.test(errorMessage)) return;
566
+
567
+ return {
568
+ message: {
569
+ ...message,
570
+ errorMessage: `context_length_exceeded: ${errorMessage}`,
571
+ },
572
+ };
573
+ });
574
+ }
575
+ ```
576
+
577
+ `message_end` runs before pi tracks the assistant message for auto-compaction, so the rewritten `errorMessage` is what pi checks. With this in place, pi will:
578
+
579
+ 1. Detect the overflow from `errorMessage`.
580
+ 2. Drop the failed assistant message from live context.
581
+ 3. Run compaction.
582
+ 4. Retry the request once.
583
+
584
+ Guard the rewrite carefully:
585
+
586
+ - Scope it to your provider (`message.provider` and `ctx.model?.provider`) so unrelated errors from other providers are untouched.
587
+ - Match a provider-specific pattern, not pi's generic overflow patterns. Rewriting rate-limit or throttling errors (`rate limit`, `too many requests`) would falsely trigger compaction instead of pi's normal retry-with-backoff path.
588
+ - Skip when `errorMessage` already includes `context_length_exceeded` so the handler is idempotent.
589
+
590
+ ### Registration
591
+
592
+ Register your stream function:
593
+
594
+ ```typescript
595
+ pi.registerProvider("my-provider", {
596
+ baseUrl: "https://api.example.com",
597
+ apiKey: "$MY_API_KEY",
598
+ api: "my-custom-api",
599
+ models: [...],
600
+ streamSimple: streamMyProvider
601
+ });
602
+ ```
603
+
604
+ ## Testing Your Implementation
605
+
606
+ Test your provider against the same test suites used by built-in providers. Copy and adapt these test files from [packages/ai/test/](https://github.com/earendil-works/pi-mono/tree/main/packages/ai/test):
607
+
608
+ | Test | Purpose |
609
+ |------|---------|
610
+ | `stream.test.ts` | Basic streaming, text output |
611
+ | `tokens.test.ts` | Token counting and usage |
612
+ | `abort.test.ts` | AbortSignal handling |
613
+ | `empty.test.ts` | Empty/minimal responses |
614
+ | `context-overflow.test.ts` | Context window limits |
615
+ | `image-limits.test.ts` | Image input handling |
616
+ | `unicode-surrogate.test.ts` | Unicode edge cases |
617
+ | `tool-call-without-result.test.ts` | Tool call edge cases |
618
+ | `image-tool-result.test.ts` | Images in tool results |
619
+ | `total-tokens.test.ts` | Total token calculation |
620
+ | `cross-provider-handoff.test.ts` | Context handoff between providers |
621
+
622
+ Run tests with your provider/model pairs to verify compatibility.
623
+
624
+ ## Config Reference
625
+
626
+ ```typescript
627
+ interface ProviderConfig {
628
+ /** Display name for the provider in UI such as /login. */
629
+ name?: string;
630
+
631
+ /** API endpoint URL. Required when defining models. */
632
+ baseUrl?: string;
633
+
634
+ /** API key literal, env interpolation ($ENV_VAR or ${ENV_VAR}), or !command. Required when defining models (unless oauth). */
635
+ apiKey?: string;
636
+
637
+ /** API type for streaming. Required at provider or model level when defining models. */
638
+ api?: Api;
639
+
640
+ /** Custom streaming implementation for non-standard APIs. */
641
+ streamSimple?: (
642
+ model: Model<Api>,
643
+ context: Context,
644
+ options?: SimpleStreamOptions
645
+ ) => AssistantMessageEventStream;
646
+
647
+ /** Custom headers to include in requests. Values use the same resolution syntax as apiKey. */
648
+ headers?: Record<string, string>;
649
+
650
+ /** If true, adds Authorization: Bearer header with the resolved API key. */
651
+ authHeader?: boolean;
652
+
653
+ /** Models to register. If provided, replaces all existing models for this provider. */
654
+ models?: ProviderModelConfig[];
655
+
656
+ /** OAuth provider for /login support. */
657
+ oauth?: {
658
+ name: string;
659
+ login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
660
+ refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials>;
661
+ getApiKey(credentials: OAuthCredentials): string;
662
+ modifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];
663
+ };
664
+ }
665
+ ```
666
+
667
+ ## Model Definition Reference
668
+
669
+ ```typescript
670
+ interface ProviderModelConfig {
671
+ /** Model ID (e.g., "claude-sonnet-4-20250514"). */
672
+ id: string;
673
+
674
+ /** Display name (e.g., "Claude 4 Sonnet"). */
675
+ name: string;
676
+
677
+ /** API type override for this specific model. */
678
+ api?: Api;
679
+
680
+ /** API endpoint URL override for this specific model. */
681
+ baseUrl?: string;
682
+
683
+ /** Whether the model supports extended thinking. */
684
+ reasoning: boolean;
685
+
686
+ /** Maps pi thinking levels to provider/model-specific values; null marks a level unsupported. */
687
+ thinkingLevelMap?: Partial<Record<"off" | "minimal" | "low" | "medium" | "high" | "xhigh", string | null>>;
688
+
689
+ /** Supported input types. */
690
+ input: ("text" | "image")[];
691
+
692
+ /** Cost per million tokens (for usage tracking). */
693
+ cost: {
694
+ input: number;
695
+ output: number;
696
+ cacheRead: number;
697
+ cacheWrite: number;
698
+ };
699
+
700
+ /** Maximum context window size in tokens. */
701
+ contextWindow: number;
702
+
703
+ /** Maximum output tokens. */
704
+ maxTokens: number;
705
+
706
+ /** Custom headers for this specific model. */
707
+ headers?: Record<string, string>;
708
+
709
+ /** Compatibility settings for the selected API. */
710
+ compat?: {
711
+ // openai-completions
712
+ supportsStore?: boolean;
713
+ supportsDeveloperRole?: boolean;
714
+ supportsReasoningEffort?: boolean;
715
+ supportsUsageInStreaming?: boolean;
716
+ maxTokensField?: "max_completion_tokens" | "max_tokens";
717
+ requiresToolResultName?: boolean;
718
+ requiresAssistantAfterToolResult?: boolean;
719
+ requiresThinkingAsText?: boolean;
720
+ requiresReasoningContentOnAssistantMessages?: boolean;
721
+ thinkingFormat?: "openai" | "openrouter" | "deepseek" | "together" | "zai" | "qwen" | "qwen-chat-template";
722
+ cacheControlFormat?: "anthropic";
723
+
724
+ // anthropic-messages
725
+ supportsEagerToolInputStreaming?: boolean;
726
+ supportsLongCacheRetention?: boolean;
727
+ sendSessionAffinityHeaders?: boolean;
728
+ supportsCacheControlOnTools?: boolean;
729
+ forceAdaptiveThinking?: boolean;
730
+ allowEmptySignature?: boolean;
731
+ };
732
+ }
733
+ ```
734
+
735
+ `openrouter` sends `reasoning: { effort }`. `deepseek` sends `thinking: { type: "enabled" | "disabled" }` and `reasoning_effort` when enabled. `together` sends `reasoning: { enabled }` and also `reasoning_effort` when `supportsReasoningEffort` is enabled. `qwen` is for DashScope-style top-level `enable_thinking`. Use `qwen-chat-template` for local Qwen-compatible servers that read `chat_template_kwargs.enable_thinking`.
736
+ `cacheControlFormat: "anthropic"` applies Anthropic-style `cache_control` markers to the system prompt, last tool definition, and last user/assistant text content.