@celljs/ta 0.0.0-stage → 4.5.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 (325) hide show
  1. package/README.md +94 -2
  2. package/bin/ta.mjs +10 -0
  3. package/dist/cli.mjs +517 -0
  4. package/dist/pi/CHANGELOG.md +32 -0
  5. package/dist/pi/dist/bundle/chunks/anthropic-messages-BWGCKOF4.js +6 -0
  6. package/dist/pi/dist/bundle/chunks/anthropic.js +75 -0
  7. package/dist/pi/dist/bundle/chunks/azure-openai-responses-FSC6BAW3.js +2 -0
  8. package/dist/pi/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
  9. package/dist/pi/dist/bundle/chunks/chunk-36QC74V4.js +2 -0
  10. package/dist/pi/dist/bundle/chunks/chunk-3TGLJEWK.js +2 -0
  11. package/dist/pi/dist/bundle/chunks/chunk-44DLKSKE.js +1232 -0
  12. package/dist/pi/dist/bundle/chunks/chunk-4EYXVSA5.js +129 -0
  13. package/dist/pi/dist/bundle/chunks/chunk-5AGIVGSV.js +6 -0
  14. package/dist/pi/dist/bundle/chunks/chunk-62VOPMLK.js +65 -0
  15. package/dist/pi/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
  16. package/dist/pi/dist/bundle/chunks/chunk-7CBJINYJ.js +20 -0
  17. package/dist/pi/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
  18. package/dist/pi/dist/bundle/chunks/chunk-7O7QKK6A.js +2 -0
  19. package/dist/pi/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
  20. package/dist/pi/dist/bundle/chunks/chunk-B46VJEHW.js +44 -0
  21. package/dist/pi/dist/bundle/chunks/chunk-C2WU32PX.js +2 -0
  22. package/dist/pi/dist/bundle/chunks/chunk-CF5GWZHW.js +31 -0
  23. package/dist/pi/dist/bundle/chunks/chunk-CHWNPHIS.js +82 -0
  24. package/dist/pi/dist/bundle/chunks/chunk-EBFHJFEE.js +2 -0
  25. package/dist/pi/dist/bundle/chunks/chunk-EOO47QGR.js +2 -0
  26. package/dist/pi/dist/bundle/chunks/chunk-FFMDRXC4.js +10 -0
  27. package/dist/pi/dist/bundle/chunks/chunk-GN3QYODH.js +16 -0
  28. package/dist/pi/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
  29. package/dist/pi/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
  30. package/dist/pi/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
  31. package/dist/pi/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
  32. package/dist/pi/dist/bundle/chunks/chunk-NL4X6LBY.js +4 -0
  33. package/dist/pi/dist/bundle/chunks/chunk-NZY7EIPA.js +4 -0
  34. package/dist/pi/dist/bundle/chunks/chunk-P7FPUEYA.js +2 -0
  35. package/dist/pi/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
  36. package/dist/pi/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
  37. package/dist/pi/dist/bundle/chunks/chunk-PMRZO46Y.js +2 -0
  38. package/dist/pi/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
  39. package/dist/pi/dist/bundle/chunks/chunk-R2EGYMOO.js +7 -0
  40. package/dist/pi/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
  41. package/dist/pi/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
  42. package/dist/pi/dist/bundle/chunks/chunk-UKVNB6C4.js +2 -0
  43. package/dist/pi/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
  44. package/dist/pi/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
  45. package/dist/pi/dist/bundle/chunks/chunk-V6KH5QG4.js +9 -0
  46. package/dist/pi/dist/bundle/chunks/chunk-VOLAXWGI.js +2 -0
  47. package/dist/pi/dist/bundle/chunks/chunk-YZKQS34S.js +9 -0
  48. package/dist/pi/dist/bundle/chunks/cli-MCOUW5WS.js +53 -0
  49. package/dist/pi/dist/bundle/chunks/cloudflare-workers-ai-system-one-WLAFJSP6.js +2 -0
  50. package/dist/pi/dist/bundle/chunks/codemode-worker.js +478 -0
  51. package/dist/pi/dist/bundle/chunks/easter-egg-3d-WMBNSJ4M.js +2 -0
  52. package/dist/pi/dist/bundle/chunks/execute-4CEBORGZ.js +505 -0
  53. package/dist/pi/dist/bundle/chunks/github-copilot.js +2 -0
  54. package/dist/pi/dist/bundle/chunks/google-generative-ai-INGKNW72.js +2 -0
  55. package/dist/pi/dist/bundle/chunks/google-vertex-IBTX6MBF.js +2 -0
  56. package/dist/pi/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
  57. package/dist/pi/dist/bundle/chunks/image-resize-worker.js +2 -0
  58. package/dist/pi/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +21 -0
  59. package/dist/pi/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +2 -0
  60. package/dist/pi/dist/bundle/chunks/kimi-coding.js +2 -0
  61. package/dist/pi/dist/bundle/chunks/lib-4AVRLBHM.js +9 -0
  62. package/dist/pi/dist/bundle/chunks/llama-cpp-classify-V5U3QKXI.js +22 -0
  63. package/dist/pi/dist/bundle/chunks/meta.js +2 -0
  64. package/dist/pi/dist/bundle/chunks/mistral-conversations-S4OWXIXQ.js +5 -0
  65. package/dist/pi/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
  66. package/dist/pi/dist/bundle/chunks/node-AUOGOBCN.js +2 -0
  67. package/dist/pi/dist/bundle/chunks/node-KCMANYC2.js +16 -0
  68. package/dist/pi/dist/bundle/chunks/openai-chatgpt.js +75 -0
  69. package/dist/pi/dist/bundle/chunks/openai-codex-responses-QAWLOQSN.js +10 -0
  70. package/dist/pi/dist/bundle/chunks/openai-codex.js +75 -0
  71. package/dist/pi/dist/bundle/chunks/openai-completions-EJNYB6IX.js +7 -0
  72. package/dist/pi/dist/bundle/chunks/openai-decisions-IXI34BYG.js +5 -0
  73. package/dist/pi/dist/bundle/chunks/openai-responses-MD3562FB.js +4 -0
  74. package/dist/pi/dist/bundle/chunks/openrouter-images-PISKSFMS.js +2 -0
  75. package/dist/pi/dist/bundle/chunks/openrouter.js +75 -0
  76. package/dist/pi/dist/bundle/chunks/pi-messages-NORUKF4E.js +8 -0
  77. package/dist/pi/dist/bundle/chunks/radius.js +75 -0
  78. package/dist/pi/dist/bundle/chunks/runtime-FQB7RU7U.js +2 -0
  79. package/dist/pi/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
  80. package/dist/pi/dist/bundle/chunks/typesafe-system-one-CHVC2UUI.js +2 -0
  81. package/dist/pi/dist/bundle/chunks/virtual-modules-O76XM3OB.js +2 -0
  82. package/dist/pi/dist/bundle/chunks/xai.js +2 -0
  83. package/dist/pi/dist/bundle/cli-runtime.js +3 -0
  84. package/dist/pi/dist/bundle/cli.js +5 -0
  85. package/dist/pi/dist/bundle/index.js +2 -0
  86. package/dist/pi/dist/bundle/rpc-entry.js +3 -0
  87. package/dist/pi/dist/core/export-html/ansi-to-html.js +249 -0
  88. package/dist/pi/dist/core/export-html/index.js +228 -0
  89. package/dist/pi/dist/core/export-html/template.css +1085 -0
  90. package/dist/pi/dist/core/export-html/template.html +56 -0
  91. package/dist/pi/dist/core/export-html/template.js +2044 -0
  92. package/dist/pi/dist/core/export-html/tool-renderer.js +113 -0
  93. package/dist/pi/dist/core/export-html/vendor/highlight.min.js +1213 -0
  94. package/dist/pi/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
  95. package/dist/pi/dist/core/export-html/vendor/marked.min.js +79 -0
  96. package/dist/pi/dist/modes/interactive/assets/clankolas.png +0 -0
  97. package/dist/pi/dist/modes/interactive/theme/dark.json +78 -0
  98. package/dist/pi/dist/modes/interactive/theme/light.json +78 -0
  99. package/dist/pi/docs/cli-integration.md +106 -0
  100. package/dist/pi/docs/cli.md +343 -0
  101. package/dist/pi/docs/codemode.md +230 -0
  102. package/dist/pi/docs/compaction.md +463 -0
  103. package/dist/pi/docs/configuration.md +47 -0
  104. package/dist/pi/docs/containerization.md +183 -0
  105. package/dist/pi/docs/custom-provider.md +227 -0
  106. package/dist/pi/docs/docs.json +220 -0
  107. package/dist/pi/docs/environment-variables.md +103 -0
  108. package/dist/pi/docs/extensions.md +3347 -0
  109. package/dist/pi/docs/how-pi-works.md +49 -0
  110. package/dist/pi/docs/images/doom-extension.png +0 -0
  111. package/dist/pi/docs/images/exy.png +0 -0
  112. package/dist/pi/docs/images/interactive-mode.png +0 -0
  113. package/dist/pi/docs/images/tree-view.png +0 -0
  114. package/dist/pi/docs/index.md +39 -0
  115. package/dist/pi/docs/json.md +226 -0
  116. package/dist/pi/docs/keybindings.md +195 -0
  117. package/dist/pi/docs/llama-cpp.md +132 -0
  118. package/dist/pi/docs/mcp.md +274 -0
  119. package/dist/pi/docs/message-types.md +279 -0
  120. package/dist/pi/docs/models-configuration.md +196 -0
  121. package/dist/pi/docs/models.md +225 -0
  122. package/dist/pi/docs/nvidia-rtx-llama-cpp.md +96 -0
  123. package/dist/pi/docs/packages.md +153 -0
  124. package/dist/pi/docs/prompt-templates.md +59 -0
  125. package/dist/pi/docs/providers.md +247 -0
  126. package/dist/pi/docs/quickstart.md +140 -0
  127. package/dist/pi/docs/rpc-commands.md +860 -0
  128. package/dist/pi/docs/rpc-extension-ui.md +200 -0
  129. package/dist/pi/docs/rpc.md +193 -0
  130. package/dist/pi/docs/sdk.md +147 -0
  131. package/dist/pi/docs/security.md +99 -0
  132. package/dist/pi/docs/session-format.md +293 -0
  133. package/dist/pi/docs/sessions.md +74 -0
  134. package/dist/pi/docs/settings.md +173 -0
  135. package/dist/pi/docs/shell-aliases.md +93 -0
  136. package/dist/pi/docs/skills.md +93 -0
  137. package/dist/pi/docs/slash-commands.md +61 -0
  138. package/dist/pi/docs/terminal-setup.md +235 -0
  139. package/dist/pi/docs/termux.md +117 -0
  140. package/dist/pi/docs/themes.md +138 -0
  141. package/dist/pi/docs/tmux.md +61 -0
  142. package/dist/pi/docs/tui.md +197 -0
  143. package/dist/pi/docs/usage.md +94 -0
  144. package/dist/pi/docs/virtual-models.md +114 -0
  145. package/dist/pi/docs/windows.md +108 -0
  146. package/dist/pi/examples/README.md +36 -0
  147. package/dist/pi/examples/extensions/README.md +215 -0
  148. package/dist/pi/examples/extensions/auto-commit-on-exit.ts +49 -0
  149. package/dist/pi/examples/extensions/bash-spawn-hook.ts +30 -0
  150. package/dist/pi/examples/extensions/bookmark.ts +50 -0
  151. package/dist/pi/examples/extensions/border-status-editor.ts +150 -0
  152. package/dist/pi/examples/extensions/built-in-tool-renderer.ts +225 -0
  153. package/dist/pi/examples/extensions/claude-rules.ts +86 -0
  154. package/dist/pi/examples/extensions/commands.ts +72 -0
  155. package/dist/pi/examples/extensions/confirm-destructive.ts +59 -0
  156. package/dist/pi/examples/extensions/custom-compaction.ts +117 -0
  157. package/dist/pi/examples/extensions/custom-footer.ts +64 -0
  158. package/dist/pi/examples/extensions/custom-header.ts +73 -0
  159. package/dist/pi/examples/extensions/custom-provider-anthropic/index.ts +613 -0
  160. package/dist/pi/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  161. package/dist/pi/examples/extensions/custom-provider-anthropic/package.json +19 -0
  162. package/dist/pi/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
  163. package/dist/pi/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  164. package/dist/pi/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  165. package/dist/pi/examples/extensions/debug-provider.ts +90 -0
  166. package/dist/pi/examples/extensions/dirty-repo-guard.ts +56 -0
  167. package/dist/pi/examples/extensions/doom-overlay/README.md +46 -0
  168. package/dist/pi/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  169. package/dist/pi/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  170. package/dist/pi/examples/extensions/doom-overlay/doom/build.sh +152 -0
  171. package/dist/pi/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  172. package/dist/pi/examples/extensions/doom-overlay/doom-component.ts +132 -0
  173. package/dist/pi/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  174. package/dist/pi/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  175. package/dist/pi/examples/extensions/doom-overlay/index.ts +74 -0
  176. package/dist/pi/examples/extensions/doom-overlay/wad-finder.ts +55 -0
  177. package/dist/pi/examples/extensions/dynamic-resources/SKILL.md +8 -0
  178. package/dist/pi/examples/extensions/dynamic-resources/dynamic.json +81 -0
  179. package/dist/pi/examples/extensions/dynamic-resources/dynamic.md +5 -0
  180. package/dist/pi/examples/extensions/dynamic-resources/index.ts +15 -0
  181. package/dist/pi/examples/extensions/dynamic-tools.ts +74 -0
  182. package/dist/pi/examples/extensions/entry-renderer.ts +41 -0
  183. package/dist/pi/examples/extensions/event-bus.ts +43 -0
  184. package/dist/pi/examples/extensions/file-trigger.ts +41 -0
  185. package/dist/pi/examples/extensions/git-checkpoint.ts +53 -0
  186. package/dist/pi/examples/extensions/git-merge-and-resolve.ts +115 -0
  187. package/dist/pi/examples/extensions/github-issue-autocomplete.ts +185 -0
  188. package/dist/pi/examples/extensions/gondolin/index.ts +531 -0
  189. package/dist/pi/examples/extensions/gondolin/package-lock.json +175 -0
  190. package/dist/pi/examples/extensions/gondolin/package.json +19 -0
  191. package/dist/pi/examples/extensions/handoff.ts +190 -0
  192. package/dist/pi/examples/extensions/hello.ts +26 -0
  193. package/dist/pi/examples/extensions/hidden-thinking-label.ts +53 -0
  194. package/dist/pi/examples/extensions/inline-bash.ts +94 -0
  195. package/dist/pi/examples/extensions/input-transform-streaming.ts +39 -0
  196. package/dist/pi/examples/extensions/input-transform.ts +43 -0
  197. package/dist/pi/examples/extensions/interactive-shell.ts +196 -0
  198. package/dist/pi/examples/extensions/jev-router.ts +113 -0
  199. package/dist/pi/examples/extensions/mac-system-theme.ts +47 -0
  200. package/dist/pi/examples/extensions/message-renderer.ts +59 -0
  201. package/dist/pi/examples/extensions/minimal-mode.ts +353 -0
  202. package/dist/pi/examples/extensions/modal-editor.ts +85 -0
  203. package/dist/pi/examples/extensions/model-status.ts +31 -0
  204. package/dist/pi/examples/extensions/notify.ts +57 -0
  205. package/dist/pi/examples/extensions/overlay-qa-tests.ts +1450 -0
  206. package/dist/pi/examples/extensions/overlay-test.ts +153 -0
  207. package/dist/pi/examples/extensions/permission-gate.ts +34 -0
  208. package/dist/pi/examples/extensions/pirate.ts +47 -0
  209. package/dist/pi/examples/extensions/plan-mode/README.md +66 -0
  210. package/dist/pi/examples/extensions/plan-mode/index.ts +394 -0
  211. package/dist/pi/examples/extensions/plan-mode/utils.ts +168 -0
  212. package/dist/pi/examples/extensions/preset.ts +438 -0
  213. package/dist/pi/examples/extensions/project-trust.ts +64 -0
  214. package/dist/pi/examples/extensions/prompt-customizer.ts +49 -0
  215. package/dist/pi/examples/extensions/protected-paths.ts +30 -0
  216. package/dist/pi/examples/extensions/provider-payload.ts +18 -0
  217. package/dist/pi/examples/extensions/qna.ts +118 -0
  218. package/dist/pi/examples/extensions/question.ts +286 -0
  219. package/dist/pi/examples/extensions/questionnaire.ts +448 -0
  220. package/dist/pi/examples/extensions/rainbow-editor.ts +88 -0
  221. package/dist/pi/examples/extensions/reload-runtime.ts +49 -0
  222. package/dist/pi/examples/extensions/rpc-demo.ts +118 -0
  223. package/dist/pi/examples/extensions/send-user-message.ts +97 -0
  224. package/dist/pi/examples/extensions/session-name.ts +27 -0
  225. package/dist/pi/examples/extensions/shutdown-command.ts +63 -0
  226. package/dist/pi/examples/extensions/snake.ts +343 -0
  227. package/dist/pi/examples/extensions/space-invaders.ts +560 -0
  228. package/dist/pi/examples/extensions/ssh.ts +220 -0
  229. package/dist/pi/examples/extensions/status-line.ts +32 -0
  230. package/dist/pi/examples/extensions/structured-output.ts +65 -0
  231. package/dist/pi/examples/extensions/subagent/README.md +177 -0
  232. package/dist/pi/examples/extensions/subagent/agents/planner.md +37 -0
  233. package/dist/pi/examples/extensions/subagent/agents/reviewer.md +35 -0
  234. package/dist/pi/examples/extensions/subagent/agents/scout.md +50 -0
  235. package/dist/pi/examples/extensions/subagent/agents/worker.md +24 -0
  236. package/dist/pi/examples/extensions/subagent/agents.ts +157 -0
  237. package/dist/pi/examples/extensions/subagent/index.ts +1036 -0
  238. package/dist/pi/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  239. package/dist/pi/examples/extensions/subagent/prompts/implement.md +10 -0
  240. package/dist/pi/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  241. package/dist/pi/examples/extensions/summarize.ts +199 -0
  242. package/dist/pi/examples/extensions/system-prompt-header.ts +17 -0
  243. package/dist/pi/examples/extensions/tic-tac-toe.ts +1008 -0
  244. package/dist/pi/examples/extensions/timed-confirm.ts +70 -0
  245. package/dist/pi/examples/extensions/titlebar-spinner.ts +58 -0
  246. package/dist/pi/examples/extensions/todo.ts +304 -0
  247. package/dist/pi/examples/extensions/tool-override.ts +144 -0
  248. package/dist/pi/examples/extensions/tools.ts +148 -0
  249. package/dist/pi/examples/extensions/trigger-compact.ts +50 -0
  250. package/dist/pi/examples/extensions/truncated-tool.ts +195 -0
  251. package/dist/pi/examples/extensions/widget-placement.ts +9 -0
  252. package/dist/pi/examples/extensions/with-deps/index.ts +32 -0
  253. package/dist/pi/examples/extensions/with-deps/package-lock.json +31 -0
  254. package/dist/pi/examples/extensions/with-deps/package.json +22 -0
  255. package/dist/pi/examples/extensions/working-indicator.ts +123 -0
  256. package/dist/pi/examples/extensions/working-message-test.ts +25 -0
  257. package/dist/pi/examples/rpc-client.ts +35 -0
  258. package/dist/pi/examples/rpc-extension-ui.ts +661 -0
  259. package/dist/pi/examples/sdk/01-minimal.ts +26 -0
  260. package/dist/pi/examples/sdk/02-custom-model.ts +49 -0
  261. package/dist/pi/examples/sdk/03-custom-prompt.ts +75 -0
  262. package/dist/pi/examples/sdk/04-skills.ts +55 -0
  263. package/dist/pi/examples/sdk/05-tools.ts +48 -0
  264. package/dist/pi/examples/sdk/06-extensions.ts +99 -0
  265. package/dist/pi/examples/sdk/07-context-files.ts +47 -0
  266. package/dist/pi/examples/sdk/08-prompt-templates.ts +51 -0
  267. package/dist/pi/examples/sdk/09-api-keys-and-oauth.ts +34 -0
  268. package/dist/pi/examples/sdk/10-settings.ts +53 -0
  269. package/dist/pi/examples/sdk/11-sessions.ts +52 -0
  270. package/dist/pi/examples/sdk/12-full-control.ts +74 -0
  271. package/dist/pi/examples/sdk/13-session-runtime.ts +67 -0
  272. package/dist/pi/examples/sdk/14-codemode-mcp.ts +61 -0
  273. package/dist/pi/examples/sdk/README.md +141 -0
  274. package/dist/pi/examples/tsconfig.json +180 -0
  275. package/dist/pi/node_modules/@silvia-odwyer/photon-node/LICENSE.md +201 -0
  276. package/dist/pi/node_modules/@silvia-odwyer/photon-node/README.md +158 -0
  277. package/dist/pi/node_modules/@silvia-odwyer/photon-node/package.json +23 -0
  278. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs.d.ts +3226 -0
  279. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs.js +4521 -0
  280. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs_bg.js +4270 -0
  281. package/dist/pi/node_modules/@silvia-odwyer/photon-node/photon_rs_bg.wasm +0 -0
  282. package/dist/pi/node_modules/jiti/LICENSE +21 -0
  283. package/dist/pi/node_modules/jiti/README.md +258 -0
  284. package/dist/pi/node_modules/jiti/dist/babel.cjs +257 -0
  285. package/dist/pi/node_modules/jiti/dist/jiti.cjs +1 -0
  286. package/dist/pi/node_modules/jiti/lib/jiti-cli.mjs +34 -0
  287. package/dist/pi/node_modules/jiti/lib/jiti-hooks.mjs +124 -0
  288. package/dist/pi/node_modules/jiti/lib/jiti-native.mjs +121 -0
  289. package/dist/pi/node_modules/jiti/lib/jiti-register.d.mts +1 -0
  290. package/dist/pi/node_modules/jiti/lib/jiti-register.mjs +4 -0
  291. package/dist/pi/node_modules/jiti/lib/jiti-static.mjs +23 -0
  292. package/dist/pi/node_modules/jiti/lib/jiti.cjs +30 -0
  293. package/dist/pi/node_modules/jiti/lib/jiti.d.cts +8 -0
  294. package/dist/pi/node_modules/jiti/lib/jiti.d.mts +8 -0
  295. package/dist/pi/node_modules/jiti/lib/jiti.mjs +29 -0
  296. package/dist/pi/node_modules/jiti/lib/types.d.ts +420 -0
  297. package/dist/pi/node_modules/jiti/package.json +146 -0
  298. package/dist/pi/node_modules/quickjs-wasi/LICENSE +21 -0
  299. package/dist/pi/node_modules/quickjs-wasi/README.md +852 -0
  300. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.d.ts +110 -0
  301. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.d.ts.map +1 -0
  302. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.js +372 -0
  303. package/dist/pi/node_modules/quickjs-wasi/dist/extensions.js.map +1 -0
  304. package/dist/pi/node_modules/quickjs-wasi/dist/index.d.ts +1263 -0
  305. package/dist/pi/node_modules/quickjs-wasi/dist/index.d.ts.map +1 -0
  306. package/dist/pi/node_modules/quickjs-wasi/dist/index.js +2787 -0
  307. package/dist/pi/node_modules/quickjs-wasi/dist/index.js.map +1 -0
  308. package/dist/pi/node_modules/quickjs-wasi/dist/version.d.ts +2 -0
  309. package/dist/pi/node_modules/quickjs-wasi/dist/version.d.ts.map +1 -0
  310. package/dist/pi/node_modules/quickjs-wasi/dist/version.js +3 -0
  311. package/dist/pi/node_modules/quickjs-wasi/dist/version.js.map +1 -0
  312. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.d.ts +61 -0
  313. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.d.ts.map +1 -0
  314. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.js +103 -0
  315. package/dist/pi/node_modules/quickjs-wasi/dist/wasi-shim.js.map +1 -0
  316. package/dist/pi/node_modules/quickjs-wasi/extensions/crypto/crypto.so +0 -0
  317. package/dist/pi/node_modules/quickjs-wasi/extensions/encoding/encoding.so +0 -0
  318. package/dist/pi/node_modules/quickjs-wasi/extensions/headers/headers.so +0 -0
  319. package/dist/pi/node_modules/quickjs-wasi/extensions/structured-clone/structured-clone.so +0 -0
  320. package/dist/pi/node_modules/quickjs-wasi/extensions/url/url.so +0 -0
  321. package/dist/pi/node_modules/quickjs-wasi/package.json +69 -0
  322. package/dist/pi/node_modules/quickjs-wasi/quickjs.wasm +0 -0
  323. package/dist/pi/package.json +9 -0
  324. package/dist/serve/index.mjs +16495 -0
  325. package/package.json +52 -4
@@ -0,0 +1,613 @@
1
+ /**
2
+ * Custom Provider Example
3
+ *
4
+ * Demonstrates registering a custom provider with:
5
+ * - Custom API identifier ("custom-anthropic-api")
6
+ * - Custom streamSimple implementation
7
+ * - OAuth support for /login
8
+ * - API key support via environment variable
9
+ * - Two model definitions
10
+ *
11
+ * Usage:
12
+ * # First install dependencies
13
+ * cd packages/coding-agent/examples/extensions/custom-provider && npm install
14
+ *
15
+ * # With OAuth (run /login custom-anthropic first)
16
+ * pi -e ./packages/coding-agent/examples/extensions/custom-provider
17
+ *
18
+ * # With API key
19
+ * CUSTOM_ANTHROPIC_API_KEY=sk-ant-... pi -e ./packages/coding-agent/examples/extensions/custom-provider
20
+ *
21
+ * Then use /model to select custom-anthropic/claude-sonnet-4-5
22
+ */
23
+
24
+ import Anthropic from "@anthropic-ai/sdk";
25
+ import type { ContentBlockParam, MessageCreateParamsStreaming } from "@anthropic-ai/sdk/resources/messages.js";
26
+ import {
27
+ type Api,
28
+ type AssistantMessage,
29
+ type AssistantMessageEventStream,
30
+ calculateCost,
31
+ collapseSystemMessages,
32
+ createAssistantMessageEventStream,
33
+ getCurrentSystemPrompt,
34
+ getCurrentTools,
35
+ type ImageContent,
36
+ type Message,
37
+ type Model,
38
+ type OAuthCredentials,
39
+ type OAuthLoginCallbacks,
40
+ type SimpleStreamOptions,
41
+ type StopReason,
42
+ type TextContent,
43
+ type ThinkingContent,
44
+ type Tool,
45
+ ToolCallArgumentsStream,
46
+ type ToolResultMessage,
47
+ type TranscriptContext,
48
+ } from "@earendil-works/pi-ai";
49
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
50
+
51
+ // =============================================================================
52
+ // OAuth implementation adapted for the legacy extension compatibility interface.
53
+ // =============================================================================
54
+
55
+ const decode = (s: string) => atob(s);
56
+ const CLIENT_ID = decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
57
+ const AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
58
+ const TOKEN_URL = "https://console.anthropic.com/v1/oauth/token";
59
+ const REDIRECT_URI = "https://console.anthropic.com/oauth/code/callback";
60
+ const SCOPES = "org:create_api_key user:profile user:inference";
61
+
62
+ async function generatePKCE(): Promise<{ verifier: string; challenge: string }> {
63
+ const array = new Uint8Array(32);
64
+ crypto.getRandomValues(array);
65
+ const verifier = btoa(String.fromCharCode(...array))
66
+ .replace(/\+/g, "-")
67
+ .replace(/\//g, "_")
68
+ .replace(/=+$/, "");
69
+
70
+ const encoder = new TextEncoder();
71
+ const data = encoder.encode(verifier);
72
+ const hash = await crypto.subtle.digest("SHA-256", data);
73
+ const challenge = btoa(String.fromCharCode(...new Uint8Array(hash)))
74
+ .replace(/\+/g, "-")
75
+ .replace(/\//g, "_")
76
+ .replace(/=+$/, "");
77
+
78
+ return { verifier, challenge };
79
+ }
80
+
81
+ async function loginAnthropic(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
82
+ const { verifier, challenge } = await generatePKCE();
83
+
84
+ const authParams = new URLSearchParams({
85
+ code: "true",
86
+ client_id: CLIENT_ID,
87
+ response_type: "code",
88
+ redirect_uri: REDIRECT_URI,
89
+ scope: SCOPES,
90
+ code_challenge: challenge,
91
+ code_challenge_method: "S256",
92
+ state: verifier,
93
+ });
94
+
95
+ callbacks.onAuth({ url: `${AUTHORIZE_URL}?${authParams.toString()}` });
96
+
97
+ const authCode = await callbacks.onPrompt({ message: "Paste the authorization code:" });
98
+ const [code, state] = authCode.split("#");
99
+
100
+ const tokenResponse = await fetch(TOKEN_URL, {
101
+ method: "POST",
102
+ headers: { "Content-Type": "application/json" },
103
+ body: JSON.stringify({
104
+ grant_type: "authorization_code",
105
+ client_id: CLIENT_ID,
106
+ code,
107
+ state,
108
+ redirect_uri: REDIRECT_URI,
109
+ code_verifier: verifier,
110
+ }),
111
+ });
112
+
113
+ if (!tokenResponse.ok) {
114
+ throw new Error(`Token exchange failed: ${await tokenResponse.text()}`);
115
+ }
116
+
117
+ const data = (await tokenResponse.json()) as {
118
+ access_token: string;
119
+ refresh_token: string;
120
+ expires_in: number;
121
+ };
122
+
123
+ return {
124
+ refresh: data.refresh_token,
125
+ access: data.access_token,
126
+ expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
127
+ };
128
+ }
129
+
130
+ async function refreshAnthropicToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials> {
131
+ const response = await fetch(TOKEN_URL, {
132
+ method: "POST",
133
+ headers: { "Content-Type": "application/json" },
134
+ body: JSON.stringify({
135
+ grant_type: "refresh_token",
136
+ client_id: CLIENT_ID,
137
+ refresh_token: credentials.refresh,
138
+ }),
139
+ signal,
140
+ });
141
+
142
+ if (!response.ok) {
143
+ throw new Error(`Token refresh failed: ${await response.text()}`);
144
+ }
145
+
146
+ const data = (await response.json()) as {
147
+ access_token: string;
148
+ refresh_token: string;
149
+ expires_in: number;
150
+ };
151
+
152
+ return {
153
+ refresh: data.refresh_token,
154
+ access: data.access_token,
155
+ expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
156
+ };
157
+ }
158
+
159
+ // =============================================================================
160
+ // Streaming Implementation (simplified from packages/ai/src/api/anthropic-messages.ts)
161
+ // =============================================================================
162
+
163
+ // Claude Code tool names for OAuth stealth mode
164
+ const claudeCodeTools = [
165
+ "Read",
166
+ "Write",
167
+ "Edit",
168
+ "Bash",
169
+ "Grep",
170
+ "Glob",
171
+ "AskUserQuestion",
172
+ "TodoWrite",
173
+ "WebFetch",
174
+ "WebSearch",
175
+ ];
176
+ const ccToolLookup = new Map(claudeCodeTools.map((t) => [t.toLowerCase(), t]));
177
+ const toClaudeCodeName = (name: string) => ccToolLookup.get(name.toLowerCase()) ?? name;
178
+ const fromClaudeCodeName = (name: string, tools?: Tool[]) => {
179
+ const lowerName = name.toLowerCase();
180
+ const matched = tools?.find((t) => t.name.toLowerCase() === lowerName);
181
+ return matched?.name ?? name;
182
+ };
183
+
184
+ function isOAuthToken(apiKey: string): boolean {
185
+ return apiKey.includes("sk-ant-oat");
186
+ }
187
+
188
+ function sanitizeSurrogates(text: string): string {
189
+ return text.replace(/[\uD800-\uDFFF]/g, "\uFFFD");
190
+ }
191
+
192
+ function convertContentBlocks(
193
+ content: (TextContent | ImageContent)[],
194
+ ): string | Array<{ type: "text"; text: string } | { type: "image"; source: any }> {
195
+ const hasImages = content.some((c) => c.type === "image");
196
+ if (!hasImages) {
197
+ return sanitizeSurrogates(content.map((c) => (c as TextContent).text).join("\n"));
198
+ }
199
+
200
+ const blocks = content.map((block) => {
201
+ if (block.type === "text") {
202
+ return { type: "text" as const, text: sanitizeSurrogates(block.text) };
203
+ }
204
+ return {
205
+ type: "image" as const,
206
+ source: {
207
+ type: "base64" as const,
208
+ media_type: block.mimeType,
209
+ data: block.data,
210
+ },
211
+ };
212
+ });
213
+
214
+ if (!blocks.some((b) => b.type === "text")) {
215
+ blocks.unshift({ type: "text" as const, text: "(see attached image)" });
216
+ }
217
+
218
+ return blocks;
219
+ }
220
+
221
+ function convertMessages(messages: Message[], isOAuth: boolean, _tools?: Tool[]): any[] {
222
+ const params: any[] = [];
223
+
224
+ for (let i = 0; i < messages.length; i++) {
225
+ const msg = messages[i];
226
+
227
+ if (msg.role === "user") {
228
+ if (typeof msg.content === "string") {
229
+ if (msg.content.trim()) {
230
+ params.push({ role: "user", content: sanitizeSurrogates(msg.content) });
231
+ }
232
+ } else {
233
+ const blocks: ContentBlockParam[] = msg.content.map((item) =>
234
+ item.type === "text"
235
+ ? { type: "text" as const, text: sanitizeSurrogates(item.text) }
236
+ : {
237
+ type: "image" as const,
238
+ source: { type: "base64" as const, media_type: item.mimeType as any, data: item.data },
239
+ },
240
+ );
241
+ if (blocks.length > 0) {
242
+ params.push({ role: "user", content: blocks });
243
+ }
244
+ }
245
+ } else if (msg.role === "assistant") {
246
+ const blocks: ContentBlockParam[] = [];
247
+ for (const block of msg.content) {
248
+ if (block.type === "text" && block.text.trim()) {
249
+ blocks.push({ type: "text", text: sanitizeSurrogates(block.text) });
250
+ } else if (block.type === "thinking" && block.thinking.trim()) {
251
+ if ((block as ThinkingContent).thinkingSignature) {
252
+ blocks.push({
253
+ type: "thinking" as any,
254
+ thinking: sanitizeSurrogates(block.thinking),
255
+ signature: (block as ThinkingContent).thinkingSignature!,
256
+ });
257
+ } else {
258
+ blocks.push({ type: "text", text: sanitizeSurrogates(block.thinking) });
259
+ }
260
+ } else if (block.type === "toolCall") {
261
+ blocks.push({
262
+ type: "tool_use",
263
+ id: block.id,
264
+ name: isOAuth ? toClaudeCodeName(block.name) : block.name,
265
+ input: block.arguments,
266
+ });
267
+ }
268
+ }
269
+ if (blocks.length > 0) {
270
+ params.push({ role: "assistant", content: blocks });
271
+ }
272
+ } else if (msg.role === "toolResult") {
273
+ const toolResults: any[] = [];
274
+ toolResults.push({
275
+ type: "tool_result",
276
+ tool_use_id: msg.toolCallId,
277
+ content: convertContentBlocks(msg.content),
278
+ is_error: msg.isError,
279
+ });
280
+
281
+ let j = i + 1;
282
+ while (j < messages.length && messages[j].role === "toolResult") {
283
+ const nextMsg = messages[j] as ToolResultMessage;
284
+ toolResults.push({
285
+ type: "tool_result",
286
+ tool_use_id: nextMsg.toolCallId,
287
+ content: convertContentBlocks(nextMsg.content),
288
+ is_error: nextMsg.isError,
289
+ });
290
+ j++;
291
+ }
292
+ i = j - 1;
293
+ params.push({ role: "user", content: toolResults });
294
+ }
295
+ }
296
+
297
+ // Add cache control to last user message
298
+ if (params.length > 0) {
299
+ const last = params[params.length - 1];
300
+ if (last.role === "user" && Array.isArray(last.content)) {
301
+ const lastBlock = last.content[last.content.length - 1];
302
+ if (lastBlock) {
303
+ lastBlock.cache_control = { type: "ephemeral" };
304
+ }
305
+ }
306
+ }
307
+
308
+ return params;
309
+ }
310
+
311
+ function convertTools(tools: Tool[], isOAuth: boolean): any[] {
312
+ return tools.map((tool) => ({
313
+ name: isOAuth ? toClaudeCodeName(tool.name) : tool.name,
314
+ description: tool.description,
315
+ input_schema: {
316
+ type: "object",
317
+ properties: (tool.parameters as any).properties || {},
318
+ required: (tool.parameters as any).required || [],
319
+ },
320
+ }));
321
+ }
322
+
323
+ function mapStopReason(reason: string): StopReason {
324
+ switch (reason) {
325
+ case "end_turn":
326
+ case "pause_turn":
327
+ case "stop_sequence":
328
+ return "stop";
329
+ case "max_tokens":
330
+ return "length";
331
+ case "tool_use":
332
+ return "toolUse";
333
+ default:
334
+ return "error";
335
+ }
336
+ }
337
+
338
+ function streamCustomAnthropic(
339
+ model: Model<Api>,
340
+ context: TranscriptContext,
341
+ options?: SimpleStreamOptions,
342
+ ): AssistantMessageEventStream {
343
+ const stream = createAssistantMessageEventStream();
344
+ // The transcript carries the prompt and tools in its system messages. This provider sends
345
+ // one top-level system prompt, so fold later system messages into the leading one first.
346
+ const transcript = collapseSystemMessages(context);
347
+ const systemPrompt = getCurrentSystemPrompt(transcript.messages);
348
+ const tools = getCurrentTools(transcript.messages);
349
+
350
+ (async () => {
351
+ const output: AssistantMessage = {
352
+ role: "assistant",
353
+ content: [],
354
+ api: model.api,
355
+ provider: model.provider,
356
+ model: model.id,
357
+ usage: {
358
+ input: 0,
359
+ output: 0,
360
+ cacheRead: 0,
361
+ cacheWrite: 0,
362
+ totalTokens: 0,
363
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
364
+ },
365
+ stopReason: "pending",
366
+ timestamp: Date.now(),
367
+ };
368
+
369
+ try {
370
+ const apiKey = options?.apiKey ?? "";
371
+ const isOAuth = isOAuthToken(apiKey);
372
+
373
+ // Configure client based on auth type
374
+ const betaFeatures = ["fine-grained-tool-streaming-2025-05-14", "interleaved-thinking-2025-05-14"];
375
+ const clientOptions: any = {
376
+ baseURL: model.baseUrl,
377
+ dangerouslyAllowBrowser: true,
378
+ };
379
+
380
+ if (isOAuth) {
381
+ clientOptions.apiKey = null;
382
+ clientOptions.authToken = apiKey;
383
+ clientOptions.defaultHeaders = {
384
+ accept: "application/json",
385
+ "anthropic-dangerous-direct-browser-access": "true",
386
+ "anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
387
+ "user-agent": "claude-cli/2.1.2 (external, cli)",
388
+ "x-app": "cli",
389
+ };
390
+ } else {
391
+ clientOptions.apiKey = apiKey;
392
+ clientOptions.defaultHeaders = {
393
+ accept: "application/json",
394
+ "anthropic-dangerous-direct-browser-access": "true",
395
+ "anthropic-beta": betaFeatures.join(","),
396
+ };
397
+ }
398
+
399
+ const client = new Anthropic(clientOptions);
400
+
401
+ // Build request params
402
+ const params: MessageCreateParamsStreaming = {
403
+ model: model.id,
404
+ messages: convertMessages(transcript.messages, isOAuth, tools),
405
+ max_tokens: options?.maxTokens || Math.floor(model.maxTokens / 3),
406
+ stream: true,
407
+ };
408
+
409
+ // System prompt with Claude Code identity for OAuth
410
+ if (isOAuth) {
411
+ params.system = [
412
+ {
413
+ type: "text",
414
+ text: "You are Claude Code, Anthropic's official CLI for Claude.",
415
+ cache_control: { type: "ephemeral" },
416
+ },
417
+ ];
418
+ if (systemPrompt) {
419
+ params.system.push({
420
+ type: "text",
421
+ text: sanitizeSurrogates(systemPrompt),
422
+ cache_control: { type: "ephemeral" },
423
+ });
424
+ }
425
+ } else if (systemPrompt) {
426
+ params.system = [
427
+ {
428
+ type: "text",
429
+ text: sanitizeSurrogates(systemPrompt),
430
+ cache_control: { type: "ephemeral" },
431
+ },
432
+ ];
433
+ }
434
+
435
+ if (tools.length > 0) {
436
+ params.tools = convertTools(tools, isOAuth);
437
+ }
438
+
439
+ // Handle thinking/reasoning
440
+ if (options?.reasoning && model.reasoning) {
441
+ const defaultBudgets: Record<string, number> = {
442
+ minimal: 1024,
443
+ low: 4096,
444
+ medium: 10240,
445
+ high: 20480,
446
+ };
447
+ const customBudget = options.thinkingBudgets?.[options.reasoning as keyof typeof options.thinkingBudgets];
448
+ params.thinking = {
449
+ type: "enabled",
450
+ budget_tokens: customBudget ?? defaultBudgets[options.reasoning] ?? 10240,
451
+ };
452
+ }
453
+
454
+ const anthropicStream = client.messages.stream({ ...params }, { signal: options?.signal });
455
+ stream.push({ type: "start", partial: output });
456
+
457
+ // Stream state per Anthropic block index, kept off the content blocks so it never reaches partial messages.
458
+ // ToolCallArgumentsStream reads each argument delta once and shows the arguments parsed so far.
459
+ const openBlocks = new Map<number, { contentIndex: number; arguments?: ToolCallArgumentsStream }>();
460
+
461
+ for await (const event of anthropicStream) {
462
+ if (event.type === "message_start") {
463
+ output.usage.input = event.message.usage.input_tokens || 0;
464
+ output.usage.output = event.message.usage.output_tokens || 0;
465
+ output.usage.cacheRead = (event.message.usage as any).cache_read_input_tokens || 0;
466
+ output.usage.cacheWrite = (event.message.usage as any).cache_creation_input_tokens || 0;
467
+ output.usage.totalTokens =
468
+ output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
469
+ calculateCost(model, output.usage);
470
+ } else if (event.type === "content_block_start") {
471
+ if (event.content_block.type === "text") {
472
+ output.content.push({ type: "text", text: "" });
473
+ openBlocks.set(event.index, { contentIndex: output.content.length - 1 });
474
+ stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
475
+ } else if (event.content_block.type === "thinking") {
476
+ output.content.push({ type: "thinking", thinking: "", thinkingSignature: "" });
477
+ openBlocks.set(event.index, { contentIndex: output.content.length - 1 });
478
+ stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
479
+ } else if (event.content_block.type === "tool_use") {
480
+ output.content.push({
481
+ type: "toolCall",
482
+ id: event.content_block.id,
483
+ name: isOAuth ? fromClaudeCodeName(event.content_block.name, tools) : event.content_block.name,
484
+ arguments: {},
485
+ });
486
+ openBlocks.set(event.index, {
487
+ contentIndex: output.content.length - 1,
488
+ arguments: new ToolCallArgumentsStream(),
489
+ });
490
+ stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
491
+ }
492
+ } else if (event.type === "content_block_delta") {
493
+ const open = openBlocks.get(event.index);
494
+ if (!open) continue;
495
+ const index = open.contentIndex;
496
+ const block = output.content[index]!;
497
+
498
+ if (event.delta.type === "text_delta" && block.type === "text") {
499
+ block.text += event.delta.text;
500
+ stream.push({ type: "text_delta", contentIndex: index, delta: event.delta.text, partial: output });
501
+ } else if (event.delta.type === "thinking_delta" && block.type === "thinking") {
502
+ block.thinking += event.delta.thinking;
503
+ stream.push({
504
+ type: "thinking_delta",
505
+ contentIndex: index,
506
+ delta: event.delta.thinking,
507
+ partial: output,
508
+ });
509
+ } else if (event.delta.type === "input_json_delta" && block.type === "toolCall" && open.arguments) {
510
+ block.arguments = open.arguments.append(event.delta.partial_json);
511
+ stream.push({
512
+ type: "toolcall_delta",
513
+ contentIndex: index,
514
+ delta: event.delta.partial_json,
515
+ partial: output,
516
+ });
517
+ } else if (event.delta.type === "signature_delta" && block.type === "thinking") {
518
+ block.thinkingSignature = (block.thinkingSignature || "") + (event.delta as any).signature;
519
+ }
520
+ } else if (event.type === "content_block_stop") {
521
+ const open = openBlocks.get(event.index);
522
+ if (!open) continue;
523
+ openBlocks.delete(event.index);
524
+ const index = open.contentIndex;
525
+ const block = output.content[index]!;
526
+
527
+ if (block.type === "text") {
528
+ stream.push({ type: "text_end", contentIndex: index, content: block.text, partial: output });
529
+ } else if (block.type === "thinking") {
530
+ stream.push({ type: "thinking_end", contentIndex: index, content: block.thinking, partial: output });
531
+ } else if (block.type === "toolCall" && open.arguments) {
532
+ // One full parse of the complete text; malformed arguments are reported in `argumentsError`.
533
+ Object.assign(block, open.arguments.finish());
534
+ stream.push({ type: "toolcall_end", contentIndex: index, toolCall: block, partial: output });
535
+ }
536
+ } else if (event.type === "message_delta") {
537
+ if ((event.delta as any).stop_reason) {
538
+ output.stopReason = mapStopReason((event.delta as any).stop_reason);
539
+ }
540
+ output.usage.input = (event.usage as any).input_tokens || 0;
541
+ output.usage.output = (event.usage as any).output_tokens || 0;
542
+ output.usage.cacheRead = (event.usage as any).cache_read_input_tokens || 0;
543
+ output.usage.cacheWrite = (event.usage as any).cache_creation_input_tokens || 0;
544
+ output.usage.totalTokens =
545
+ output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
546
+ calculateCost(model, output.usage);
547
+ }
548
+ }
549
+
550
+ if (options?.signal?.aborted) {
551
+ throw new Error("Request was aborted");
552
+ }
553
+ if (output.stopReason === "pending") {
554
+ throw new Error("Anthropic stream ended without a stop reason");
555
+ }
556
+ if (output.stopReason === "error" || output.stopReason === "aborted") {
557
+ throw new Error(output.errorMessage || "An unknown error occurred");
558
+ }
559
+
560
+ stream.push({ type: "done", reason: output.stopReason, message: output });
561
+ stream.end();
562
+ } catch (error) {
563
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
564
+ output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
565
+ stream.push({ type: "error", reason: output.stopReason, error: output });
566
+ stream.end();
567
+ }
568
+ })();
569
+
570
+ return stream;
571
+ }
572
+
573
+ // =============================================================================
574
+ // Extension Entry Point
575
+ // =============================================================================
576
+
577
+ export default function (pi: ExtensionAPI) {
578
+ pi.registerProvider("custom-anthropic", {
579
+ baseUrl: "https://api.anthropic.com",
580
+ apiKey: "$CUSTOM_ANTHROPIC_API_KEY",
581
+ api: "custom-anthropic-api",
582
+
583
+ models: [
584
+ {
585
+ id: "claude-opus-4-5",
586
+ name: "Claude Opus 4.5 (Custom)",
587
+ reasoning: true,
588
+ input: ["text", "image"],
589
+ cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
590
+ contextWindow: 200000,
591
+ maxTokens: 64000,
592
+ },
593
+ {
594
+ id: "claude-sonnet-4-5",
595
+ name: "Claude Sonnet 4.5 (Custom)",
596
+ reasoning: true,
597
+ input: ["text", "image"],
598
+ cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
599
+ contextWindow: 200000,
600
+ maxTokens: 64000,
601
+ },
602
+ ],
603
+
604
+ oauth: {
605
+ name: "Custom Anthropic (Claude Pro/Max)",
606
+ login: loginAnthropic,
607
+ refreshToken: refreshAnthropicToken,
608
+ getApiKey: (cred) => cred.access,
609
+ },
610
+
611
+ streamSimple: streamCustomAnthropic,
612
+ });
613
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "pi-extension-custom-provider",
3
+ "version": "1.5.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "pi-extension-custom-provider",
9
+ "version": "1.5.0",
10
+ "dependencies": {
11
+ "@anthropic-ai/sdk": "^0.52.0"
12
+ }
13
+ },
14
+ "node_modules/@anthropic-ai/sdk": {
15
+ "version": "0.52.0",
16
+ "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.52.0.tgz",
17
+ "integrity": "sha512-d4c+fg+xy9e46c8+YnrrgIQR45CZlAi7PwdzIfDXDM6ACxEZli1/fxhURsq30ZpMZy6LvSkr41jGq5aF5TD7rQ==",
18
+ "license": "MIT",
19
+ "bin": {
20
+ "anthropic-ai-sdk": "bin/cli"
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "pi-extension-custom-provider-anthropic",
3
+ "private": true,
4
+ "version": "1.5.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "clean": "echo 'nothing to clean'",
8
+ "build": "echo 'nothing to build'",
9
+ "check": "echo 'nothing to check'"
10
+ },
11
+ "pi": {
12
+ "extensions": [
13
+ "./index.ts"
14
+ ]
15
+ },
16
+ "dependencies": {
17
+ "@anthropic-ai/sdk": "0.52.0"
18
+ }
19
+ }