@korallis/k-pi 0.1.0

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 (348) hide show
  1. package/CHANGELOG.md +5619 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +66 -0
  4. package/README.md +723 -0
  5. package/dist/bundle/chunks/anthropic-messages-IBCPCIJO.js +45 -0
  6. package/dist/bundle/chunks/anthropic.js +75 -0
  7. package/dist/bundle/chunks/azure-openai-responses-GUUG57CZ.js +2 -0
  8. package/dist/bundle/chunks/bedrock-converse-stream.js +74 -0
  9. package/dist/bundle/chunks/chunk-4L3WN2XY.js +2 -0
  10. package/dist/bundle/chunks/chunk-6CYCI3EJ.js +12 -0
  11. package/dist/bundle/chunks/chunk-6R7UI4IY.js +2 -0
  12. package/dist/bundle/chunks/chunk-AXIIZGTV.js +2 -0
  13. package/dist/bundle/chunks/chunk-CO7LIZG5.js +2 -0
  14. package/dist/bundle/chunks/chunk-DRQDKNXA.js +2 -0
  15. package/dist/bundle/chunks/chunk-GMWCTUPB.js +2 -0
  16. package/dist/bundle/chunks/chunk-HOFU6X66.js +50 -0
  17. package/dist/bundle/chunks/chunk-JUUC5AZY.js +2 -0
  18. package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
  19. package/dist/bundle/chunks/chunk-MNAIPA3J.js +2 -0
  20. package/dist/bundle/chunks/chunk-NBBFIJUL.js +11 -0
  21. package/dist/bundle/chunks/chunk-NUHFSC37.js +25 -0
  22. package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
  23. package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
  24. package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
  25. package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
  26. package/dist/bundle/chunks/chunk-TRDNDS6A.js +4 -0
  27. package/dist/bundle/chunks/chunk-UAQELI3K.js +2 -0
  28. package/dist/bundle/chunks/chunk-X5QHCKY4.js +1653 -0
  29. package/dist/bundle/chunks/chunk-XDUWOHPL.js +6 -0
  30. package/dist/bundle/chunks/github-copilot.js +2 -0
  31. package/dist/bundle/chunks/google-generative-ai-YRXF7C4I.js +2 -0
  32. package/dist/bundle/chunks/google-vertex-BVZ6VBRQ.js +2 -0
  33. package/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +13 -0
  34. package/dist/bundle/chunks/image-resize-worker.js +2 -0
  35. package/dist/bundle/chunks/kimi-coding.js +2 -0
  36. package/dist/bundle/chunks/lib-HGQMNYVT.js +9 -0
  37. package/dist/bundle/chunks/mistral-conversations-Q3AWZJAZ.js +5 -0
  38. package/dist/bundle/chunks/multipart-parser-SQ6GDJL7.js +3 -0
  39. package/dist/bundle/chunks/openai-codex-responses-GJVBJXLB.js +8 -0
  40. package/dist/bundle/chunks/openai-codex.js +75 -0
  41. package/dist/bundle/chunks/openai-completions-OICQQ5JB.js +7 -0
  42. package/dist/bundle/chunks/openai-responses-P5LIZTXX.js +2 -0
  43. package/dist/bundle/chunks/openrouter-images-XTKS2AS3.js +2 -0
  44. package/dist/bundle/chunks/openrouter.js +75 -0
  45. package/dist/bundle/chunks/pi-messages-TPFH44NP.js +8 -0
  46. package/dist/bundle/chunks/radius.js +75 -0
  47. package/dist/bundle/chunks/src-UK77SYZE.js +4 -0
  48. package/dist/bundle/chunks/xai.js +2 -0
  49. package/dist/bundle/cli.js +3 -0
  50. package/dist/bundle/client.js +2 -0
  51. package/dist/bundle/index.js +2 -0
  52. package/dist/bundle/rpc-entry.js +3 -0
  53. package/dist/core/export-html/template.css +1066 -0
  54. package/dist/core/export-html/template.html +55 -0
  55. package/dist/core/export-html/template.js +1864 -0
  56. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  57. package/dist/core/export-html/vendor/marked.min.js +78 -0
  58. package/dist/kpi/graphs/coding-loop.auto.json +377 -0
  59. package/dist/kpi/graphs/coding-loop.gated.json +417 -0
  60. package/dist/kpi/graphs/spec-first.json +40 -0
  61. package/dist/kpi/kstack/NOTICE +5 -0
  62. package/dist/kpi/kstack/UPSTREAM.md +23 -0
  63. package/dist/kpi/kstack/generated/LICENSE +21 -0
  64. package/dist/kpi/kstack/generated/skills/architect/SKILL.md +83 -0
  65. package/dist/kpi/kstack/generated/skills/architect/references/design-red-flags.md +33 -0
  66. package/dist/kpi/kstack/generated/skills/architect/references/rationale-template.md +35 -0
  67. package/dist/kpi/kstack/generated/skills/architect/references/runner-prompt.md +20 -0
  68. package/dist/kpi/kstack/generated/skills/arena/SKILL.md +29 -0
  69. package/dist/kpi/kstack/generated/skills/blast-radius/SKILL.md +50 -0
  70. package/dist/kpi/kstack/generated/skills/bro/SKILL.md +7 -0
  71. package/dist/kpi/kstack/generated/skills/create-verification-skill/SKILL.md +44 -0
  72. package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
  73. package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
  74. package/dist/kpi/kstack/generated/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
  75. package/dist/kpi/kstack/generated/skills/figure-it-out/SKILL.md +55 -0
  76. package/dist/kpi/kstack/generated/skills/how/SKILL.md +135 -0
  77. package/dist/kpi/kstack/generated/skills/how/references/critic-prompt.md +59 -0
  78. package/dist/kpi/kstack/generated/skills/how/references/critique-rubric.md +58 -0
  79. package/dist/kpi/kstack/generated/skills/how/references/explainer-prompt.md +55 -0
  80. package/dist/kpi/kstack/generated/skills/how/references/explorer-prompt.md +52 -0
  81. package/dist/kpi/kstack/generated/skills/interrogate/SKILL.md +113 -0
  82. package/dist/kpi/kstack/generated/skills/interrogate/references/code-quality-review.md +47 -0
  83. package/dist/kpi/kstack/generated/skills/interrogate/references/lead-judgment.md +58 -0
  84. package/dist/kpi/kstack/generated/skills/interrogate/references/reviewer-prompt.md +72 -0
  85. package/dist/kpi/kstack/generated/skills/interrogate/references/rubric.md +77 -0
  86. package/dist/kpi/kstack/generated/skills/k-agent/SKILL.md +17 -0
  87. package/dist/kpi/kstack/generated/skills/k-mode/SKILL.md +64 -0
  88. package/dist/kpi/kstack/generated/skills/k-stack-principles/SKILL.md +24 -0
  89. package/dist/kpi/kstack/generated/skills/maintain-verification-skill/SKILL.md +39 -0
  90. package/dist/kpi/kstack/generated/skills/no-comments/SKILL.md +24 -0
  91. package/dist/kpi/kstack/generated/skills/playbook-arena/SKILL.md +20 -0
  92. package/dist/kpi/kstack/generated/skills/playbook-autonomous-run/SKILL.md +22 -0
  93. package/dist/kpi/kstack/generated/skills/playbook-autopilot-full/SKILL.md +20 -0
  94. package/dist/kpi/kstack/generated/skills/playbook-autopilot-stack/SKILL.md +20 -0
  95. package/dist/kpi/kstack/generated/skills/playbook-bug-fix/SKILL.md +21 -0
  96. package/dist/kpi/kstack/generated/skills/playbook-feature/SKILL.md +22 -0
  97. package/dist/kpi/kstack/generated/skills/playbook-investigation/SKILL.md +21 -0
  98. package/dist/kpi/kstack/generated/skills/playbook-shipping/SKILL.md +18 -0
  99. package/dist/kpi/kstack/generated/skills/playbook-swarm/SKILL.md +20 -0
  100. package/dist/kpi/kstack/generated/skills/principle-boundary-discipline/SKILL.md +34 -0
  101. package/dist/kpi/kstack/generated/skills/principle-build-the-lever/SKILL.md +23 -0
  102. package/dist/kpi/kstack/generated/skills/principle-encode-lessons-in-structure/SKILL.md +31 -0
  103. package/dist/kpi/kstack/generated/skills/principle-exhaust-the-design-space/SKILL.md +21 -0
  104. package/dist/kpi/kstack/generated/skills/principle-experience-first/SKILL.md +19 -0
  105. package/dist/kpi/kstack/generated/skills/principle-fix-root-causes/SKILL.md +23 -0
  106. package/dist/kpi/kstack/generated/skills/principle-foundational-thinking/SKILL.md +21 -0
  107. package/dist/kpi/kstack/generated/skills/principle-guard-the-context-window/SKILL.md +17 -0
  108. package/dist/kpi/kstack/generated/skills/principle-laziness-protocol/SKILL.md +18 -0
  109. package/dist/kpi/kstack/generated/skills/principle-make-operations-idempotent/SKILL.md +24 -0
  110. package/dist/kpi/kstack/generated/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +22 -0
  111. package/dist/kpi/kstack/generated/skills/principle-minimize-reader-load/SKILL.md +23 -0
  112. package/dist/kpi/kstack/generated/skills/principle-model-the-domain/SKILL.md +26 -0
  113. package/dist/kpi/kstack/generated/skills/principle-never-block-on-the-human/SKILL.md +23 -0
  114. package/dist/kpi/kstack/generated/skills/principle-outcome-oriented-execution/SKILL.md +22 -0
  115. package/dist/kpi/kstack/generated/skills/principle-prove-it-works/SKILL.md +33 -0
  116. package/dist/kpi/kstack/generated/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
  117. package/dist/kpi/kstack/generated/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
  118. package/dist/kpi/kstack/generated/skills/principle-sequence-verifiable-units/SKILL.md +22 -0
  119. package/dist/kpi/kstack/generated/skills/principle-subtract-before-you-add/SKILL.md +22 -0
  120. package/dist/kpi/kstack/generated/skills/principle-type-system-discipline/SKILL.md +31 -0
  121. package/dist/kpi/kstack/generated/skills/recall/SKILL.md +35 -0
  122. package/dist/kpi/kstack/generated/skills/reflect/SKILL.md +77 -0
  123. package/dist/kpi/kstack/generated/skills/reflect/references/divergent-reviewer.md +43 -0
  124. package/dist/kpi/kstack/generated/skills/reflect/references/judgment-reviewer.md +42 -0
  125. package/dist/kpi/kstack/generated/skills/reflect/references/synthesizer.md +56 -0
  126. package/dist/kpi/kstack/generated/skills/reflect/references/tooling-reviewer.md +57 -0
  127. package/dist/kpi/kstack/generated/skills/setup-kstack/SKILL.md +48 -0
  128. package/dist/kpi/kstack/generated/skills/show-me-your-work/SKILL.md +82 -0
  129. package/dist/kpi/kstack/generated/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
  130. package/dist/kpi/kstack/generated/skills/show-me-your-work/scripts/log.sh +40 -0
  131. package/dist/kpi/kstack/generated/skills/swarm/SKILL.md +27 -0
  132. package/dist/kpi/kstack/generated/skills/tdd/SKILL.md +44 -0
  133. package/dist/kpi/kstack/generated/skills/teach/SKILL.md +21 -0
  134. package/dist/kpi/kstack/generated/skills/technical-writing/SKILL.md +130 -0
  135. package/dist/kpi/kstack/generated/skills/typescript-best-practices/SKILL.md +30 -0
  136. package/dist/kpi/kstack/generated/skills/typescript-best-practices/references/patterns.md +313 -0
  137. package/dist/kpi/kstack/generated/skills/unslop/SKILL.md +81 -0
  138. package/dist/kpi/kstack/generated/skills/why/SKILL.md +230 -0
  139. package/dist/kpi/kstack/generated/skills/why/references/epistemics.md +144 -0
  140. package/dist/kpi/kstack/generated/skills/why/references/investigator-prompt.md +103 -0
  141. package/dist/kpi/kstack/generated/skills/why/references/source-playbook.md +17 -0
  142. package/dist/kpi/kstack/generated/skills/why/references/sources/code-archaeology.md +88 -0
  143. package/dist/kpi/kstack/generated/skills/why/references/sources/databricks.md +70 -0
  144. package/dist/kpi/kstack/generated/skills/why/references/sources/datadog.md +99 -0
  145. package/dist/kpi/kstack/generated/skills/why/references/sources/incident-postmortem.md +15 -0
  146. package/dist/kpi/kstack/generated/skills/why/references/sources/linear.md +48 -0
  147. package/dist/kpi/kstack/generated/skills/why/references/sources/notion.md +55 -0
  148. package/dist/kpi/kstack/generated/skills/why/references/sources/sentry.md +100 -0
  149. package/dist/kpi/kstack/generated/skills/why/references/sources/slack.md +54 -0
  150. package/dist/kpi/kstack/generated/skills/why/references/synthesizer-prompt.md +135 -0
  151. package/dist/kpi/kstack/model-ladder.md +50 -0
  152. package/dist/kpi/kstack/provenance.json +17 -0
  153. package/dist/kpi/prompts/implement.md +6 -0
  154. package/dist/kpi/prompts/plan.md +6 -0
  155. package/dist/kpi/prompts/review.md +6 -0
  156. package/dist/kpi/prompts/ship.md +6 -0
  157. package/dist/kpi/prompts/specify.md +6 -0
  158. package/dist/kpi/prompts/verify.md +6 -0
  159. package/dist/kpi/schemas/event.schema.json +1314 -0
  160. package/dist/kpi/schemas/evidence.schema.json +43 -0
  161. package/dist/kpi/schemas/stack.schema.json +102 -0
  162. package/dist/kpi/schemas/task.schema.json +165 -0
  163. package/dist/kpi/schemas/verdict.schema.json +44 -0
  164. package/dist/kpi/skills/concise-output/SKILL.md +10 -0
  165. package/dist/kpi/skills/context-pack/SKILL.md +10 -0
  166. package/dist/kpi/skills/conventional-commit/SKILL.md +12 -0
  167. package/dist/kpi/skills/isolated-review/SKILL.md +10 -0
  168. package/dist/kpi/skills/kg-claim/SKILL.md +26 -0
  169. package/dist/kpi/skills/minimalist/SKILL.md +24 -0
  170. package/dist/kpi/skills/quality-gates/SKILL.md +10 -0
  171. package/dist/kpi/skills/spec-first/SKILL.md +10 -0
  172. package/dist/kpi/skills/tdd-cycle/SKILL.md +10 -0
  173. package/dist/kpi/templates/AGENTS.md +31 -0
  174. package/dist/kpi/templates/APPEND_SYSTEM.md +13 -0
  175. package/dist/kpi/templates/context-pack/product.md +7 -0
  176. package/dist/kpi/templates/context-pack/structure.md +7 -0
  177. package/dist/kpi/templates/context-pack/tech.md +9 -0
  178. package/dist/kpi/templates/policy.json +17 -0
  179. package/dist/kpi/themes/loop-amber.json +82 -0
  180. package/dist/kpi/themes/protocol-blue.json +82 -0
  181. package/dist/modes/interactive/assets/clankolas.png +0 -0
  182. package/dist/modes/interactive/theme/dark.json +90 -0
  183. package/dist/modes/interactive/theme/light.json +89 -0
  184. package/dist/modes/interactive/theme/theme-schema.json +352 -0
  185. package/docs/compaction.md +418 -0
  186. package/docs/containerization.md +111 -0
  187. package/docs/custom-provider.md +777 -0
  188. package/docs/development.md +71 -0
  189. package/docs/docs.json +156 -0
  190. package/docs/environment-variables.md +97 -0
  191. package/docs/extensions.md +3020 -0
  192. package/docs/images/doom-extension.png +0 -0
  193. package/docs/images/exy.png +0 -0
  194. package/docs/images/interactive-mode.png +0 -0
  195. package/docs/images/tree-view.png +0 -0
  196. package/docs/index.md +84 -0
  197. package/docs/json.md +98 -0
  198. package/docs/keybindings.md +236 -0
  199. package/docs/llama-cpp.md +101 -0
  200. package/docs/models.md +571 -0
  201. package/docs/packages.md +228 -0
  202. package/docs/prompt-templates.md +96 -0
  203. package/docs/providers.md +317 -0
  204. package/docs/quickstart.md +167 -0
  205. package/docs/rpc.md +1618 -0
  206. package/docs/sdk.md +1219 -0
  207. package/docs/security.md +59 -0
  208. package/docs/session-format.md +438 -0
  209. package/docs/sessions.md +145 -0
  210. package/docs/settings.md +369 -0
  211. package/docs/shell-aliases.md +13 -0
  212. package/docs/skills.md +232 -0
  213. package/docs/terminal-setup.md +177 -0
  214. package/docs/termux.md +127 -0
  215. package/docs/themes.md +320 -0
  216. package/docs/tmux.md +63 -0
  217. package/docs/tui.md +942 -0
  218. package/docs/usage.md +311 -0
  219. package/docs/windows.md +39 -0
  220. package/examples/README.md +25 -0
  221. package/examples/extensions/README.md +213 -0
  222. package/examples/extensions/auto-commit-on-exit.ts +49 -0
  223. package/examples/extensions/bash-spawn-hook.ts +30 -0
  224. package/examples/extensions/bookmark.ts +50 -0
  225. package/examples/extensions/border-status-editor.ts +150 -0
  226. package/examples/extensions/built-in-tool-renderer.ts +249 -0
  227. package/examples/extensions/claude-rules.ts +86 -0
  228. package/examples/extensions/commands.ts +72 -0
  229. package/examples/extensions/confirm-destructive.ts +59 -0
  230. package/examples/extensions/custom-compaction.ts +117 -0
  231. package/examples/extensions/custom-footer.ts +64 -0
  232. package/examples/extensions/custom-header.ts +73 -0
  233. package/examples/extensions/custom-provider-anthropic/index.ts +611 -0
  234. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  235. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  236. package/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
  237. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  238. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  239. package/examples/extensions/dirty-repo-guard.ts +56 -0
  240. package/examples/extensions/doom-overlay/README.md +46 -0
  241. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  242. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  243. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  244. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  245. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  246. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  247. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  248. package/examples/extensions/doom-overlay/index.ts +74 -0
  249. package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
  250. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  251. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  252. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  253. package/examples/extensions/dynamic-resources/index.ts +15 -0
  254. package/examples/extensions/dynamic-tools.ts +74 -0
  255. package/examples/extensions/entry-renderer.ts +41 -0
  256. package/examples/extensions/event-bus.ts +43 -0
  257. package/examples/extensions/file-trigger.ts +41 -0
  258. package/examples/extensions/git-checkpoint.ts +53 -0
  259. package/examples/extensions/git-merge-and-resolve.ts +115 -0
  260. package/examples/extensions/github-issue-autocomplete.ts +185 -0
  261. package/examples/extensions/gondolin/index.ts +531 -0
  262. package/examples/extensions/gondolin/package-lock.json +185 -0
  263. package/examples/extensions/gondolin/package.json +19 -0
  264. package/examples/extensions/handoff.ts +190 -0
  265. package/examples/extensions/hello.ts +26 -0
  266. package/examples/extensions/hidden-thinking-label.ts +53 -0
  267. package/examples/extensions/inline-bash.ts +94 -0
  268. package/examples/extensions/input-transform-streaming.ts +39 -0
  269. package/examples/extensions/input-transform.ts +43 -0
  270. package/examples/extensions/interactive-shell.ts +196 -0
  271. package/examples/extensions/kimi-deferred-tools.ts +61 -0
  272. package/examples/extensions/mac-system-theme.ts +47 -0
  273. package/examples/extensions/message-renderer.ts +59 -0
  274. package/examples/extensions/minimal-mode.ts +426 -0
  275. package/examples/extensions/modal-editor.ts +85 -0
  276. package/examples/extensions/model-status.ts +31 -0
  277. package/examples/extensions/notify.ts +57 -0
  278. package/examples/extensions/overlay-qa-tests.ts +1450 -0
  279. package/examples/extensions/overlay-test.ts +153 -0
  280. package/examples/extensions/permission-gate.ts +34 -0
  281. package/examples/extensions/pirate.ts +47 -0
  282. package/examples/extensions/plan-mode/README.md +66 -0
  283. package/examples/extensions/plan-mode/index.ts +390 -0
  284. package/examples/extensions/plan-mode/utils.ts +168 -0
  285. package/examples/extensions/preset.ts +436 -0
  286. package/examples/extensions/project-trust.ts +64 -0
  287. package/examples/extensions/prompt-customizer.ts +97 -0
  288. package/examples/extensions/protected-paths.ts +30 -0
  289. package/examples/extensions/provider-payload.ts +18 -0
  290. package/examples/extensions/qna.ts +118 -0
  291. package/examples/extensions/question.ts +286 -0
  292. package/examples/extensions/questionnaire.ts +448 -0
  293. package/examples/extensions/rainbow-editor.ts +88 -0
  294. package/examples/extensions/reload-runtime.ts +37 -0
  295. package/examples/extensions/rpc-demo.ts +118 -0
  296. package/examples/extensions/sandbox/index.ts +321 -0
  297. package/examples/extensions/sandbox/package-lock.json +92 -0
  298. package/examples/extensions/sandbox/package.json +19 -0
  299. package/examples/extensions/send-user-message.ts +97 -0
  300. package/examples/extensions/session-name.ts +27 -0
  301. package/examples/extensions/shutdown-command.ts +63 -0
  302. package/examples/extensions/snake.ts +343 -0
  303. package/examples/extensions/space-invaders.ts +560 -0
  304. package/examples/extensions/ssh.ts +220 -0
  305. package/examples/extensions/status-line.ts +32 -0
  306. package/examples/extensions/structured-output.ts +65 -0
  307. package/examples/extensions/subagent/README.md +177 -0
  308. package/examples/extensions/subagent/agents/planner.md +37 -0
  309. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  310. package/examples/extensions/subagent/agents/scout.md +50 -0
  311. package/examples/extensions/subagent/agents/worker.md +24 -0
  312. package/examples/extensions/subagent/agents.ts +157 -0
  313. package/examples/extensions/subagent/index.ts +1038 -0
  314. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  315. package/examples/extensions/subagent/prompts/implement.md +10 -0
  316. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  317. package/examples/extensions/summarize.ts +199 -0
  318. package/examples/extensions/system-prompt-header.ts +17 -0
  319. package/examples/extensions/tic-tac-toe.ts +1008 -0
  320. package/examples/extensions/timed-confirm.ts +70 -0
  321. package/examples/extensions/titlebar-spinner.ts +58 -0
  322. package/examples/extensions/todo.ts +297 -0
  323. package/examples/extensions/tool-override.ts +144 -0
  324. package/examples/extensions/tools.ts +146 -0
  325. package/examples/extensions/trigger-compact.ts +50 -0
  326. package/examples/extensions/truncated-tool.ts +195 -0
  327. package/examples/extensions/widget-placement.ts +9 -0
  328. package/examples/extensions/with-deps/index.ts +32 -0
  329. package/examples/extensions/with-deps/package-lock.json +31 -0
  330. package/examples/extensions/with-deps/package.json +22 -0
  331. package/examples/extensions/working-indicator.ts +123 -0
  332. package/examples/extensions/working-message-test.ts +25 -0
  333. package/examples/rpc-extension-ui.ts +641 -0
  334. package/examples/sdk/01-minimal.ts +26 -0
  335. package/examples/sdk/02-custom-model.ts +49 -0
  336. package/examples/sdk/03-custom-prompt.ts +75 -0
  337. package/examples/sdk/04-skills.ts +55 -0
  338. package/examples/sdk/05-tools.ts +48 -0
  339. package/examples/sdk/06-extensions.ts +99 -0
  340. package/examples/sdk/07-context-files.ts +47 -0
  341. package/examples/sdk/08-prompt-templates.ts +51 -0
  342. package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
  343. package/examples/sdk/10-settings.ts +53 -0
  344. package/examples/sdk/11-sessions.ts +52 -0
  345. package/examples/sdk/12-full-control.ts +74 -0
  346. package/examples/sdk/13-session-runtime.ts +67 -0
  347. package/examples/sdk/README.md +140 -0
  348. package/package.json +55 -0
@@ -0,0 +1,611 @@
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
+ type Context,
31
+ calculateCost,
32
+ createAssistantMessageEventStream,
33
+ type ImageContent,
34
+ type Message,
35
+ type Model,
36
+ type OAuthCredentials,
37
+ type OAuthLoginCallbacks,
38
+ type SimpleStreamOptions,
39
+ type StopReason,
40
+ type TextContent,
41
+ type ThinkingContent,
42
+ type Tool,
43
+ type ToolCall,
44
+ type ToolResultMessage,
45
+ } from "@earendil-works/pi-ai";
46
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
47
+
48
+ // =============================================================================
49
+ // OAuth implementation adapted for the legacy extension compatibility interface.
50
+ // =============================================================================
51
+
52
+ const decode = (s: string) => atob(s);
53
+ const CLIENT_ID = decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
54
+ const AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
55
+ const TOKEN_URL = "https://console.anthropic.com/v1/oauth/token";
56
+ const REDIRECT_URI = "https://console.anthropic.com/oauth/code/callback";
57
+ const SCOPES = "org:create_api_key user:profile user:inference";
58
+
59
+ async function generatePKCE(): Promise<{ verifier: string; challenge: string }> {
60
+ const array = new Uint8Array(32);
61
+ crypto.getRandomValues(array);
62
+ const verifier = btoa(String.fromCharCode(...array))
63
+ .replace(/\+/g, "-")
64
+ .replace(/\//g, "_")
65
+ .replace(/=+$/, "");
66
+
67
+ const encoder = new TextEncoder();
68
+ const data = encoder.encode(verifier);
69
+ const hash = await crypto.subtle.digest("SHA-256", data);
70
+ const challenge = btoa(String.fromCharCode(...new Uint8Array(hash)))
71
+ .replace(/\+/g, "-")
72
+ .replace(/\//g, "_")
73
+ .replace(/=+$/, "");
74
+
75
+ return { verifier, challenge };
76
+ }
77
+
78
+ async function loginAnthropic(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
79
+ const { verifier, challenge } = await generatePKCE();
80
+
81
+ const authParams = new URLSearchParams({
82
+ code: "true",
83
+ client_id: CLIENT_ID,
84
+ response_type: "code",
85
+ redirect_uri: REDIRECT_URI,
86
+ scope: SCOPES,
87
+ code_challenge: challenge,
88
+ code_challenge_method: "S256",
89
+ state: verifier,
90
+ });
91
+
92
+ callbacks.onAuth({ url: `${AUTHORIZE_URL}?${authParams.toString()}` });
93
+
94
+ const authCode = await callbacks.onPrompt({ message: "Paste the authorization code:" });
95
+ const [code, state] = authCode.split("#");
96
+
97
+ const tokenResponse = await fetch(TOKEN_URL, {
98
+ method: "POST",
99
+ headers: { "Content-Type": "application/json" },
100
+ body: JSON.stringify({
101
+ grant_type: "authorization_code",
102
+ client_id: CLIENT_ID,
103
+ code,
104
+ state,
105
+ redirect_uri: REDIRECT_URI,
106
+ code_verifier: verifier,
107
+ }),
108
+ });
109
+
110
+ if (!tokenResponse.ok) {
111
+ throw new Error(`Token exchange failed: ${await tokenResponse.text()}`);
112
+ }
113
+
114
+ const data = (await tokenResponse.json()) as {
115
+ access_token: string;
116
+ refresh_token: string;
117
+ expires_in: number;
118
+ };
119
+
120
+ return {
121
+ refresh: data.refresh_token,
122
+ access: data.access_token,
123
+ expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
124
+ };
125
+ }
126
+
127
+ async function refreshAnthropicToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials> {
128
+ const response = await fetch(TOKEN_URL, {
129
+ method: "POST",
130
+ headers: { "Content-Type": "application/json" },
131
+ body: JSON.stringify({
132
+ grant_type: "refresh_token",
133
+ client_id: CLIENT_ID,
134
+ refresh_token: credentials.refresh,
135
+ }),
136
+ signal,
137
+ });
138
+
139
+ if (!response.ok) {
140
+ throw new Error(`Token refresh failed: ${await response.text()}`);
141
+ }
142
+
143
+ const data = (await response.json()) as {
144
+ access_token: string;
145
+ refresh_token: string;
146
+ expires_in: number;
147
+ };
148
+
149
+ return {
150
+ refresh: data.refresh_token,
151
+ access: data.access_token,
152
+ expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
153
+ };
154
+ }
155
+
156
+ // =============================================================================
157
+ // Streaming Implementation (simplified from packages/ai/src/api/anthropic-messages.ts)
158
+ // =============================================================================
159
+
160
+ // Claude Code tool names for OAuth stealth mode
161
+ const claudeCodeTools = [
162
+ "Read",
163
+ "Write",
164
+ "Edit",
165
+ "Bash",
166
+ "Grep",
167
+ "Glob",
168
+ "AskUserQuestion",
169
+ "TodoWrite",
170
+ "WebFetch",
171
+ "WebSearch",
172
+ ];
173
+ const ccToolLookup = new Map(claudeCodeTools.map((t) => [t.toLowerCase(), t]));
174
+ const toClaudeCodeName = (name: string) => ccToolLookup.get(name.toLowerCase()) ?? name;
175
+ const fromClaudeCodeName = (name: string, tools?: Tool[]) => {
176
+ const lowerName = name.toLowerCase();
177
+ const matched = tools?.find((t) => t.name.toLowerCase() === lowerName);
178
+ return matched?.name ?? name;
179
+ };
180
+
181
+ function isOAuthToken(apiKey: string): boolean {
182
+ return apiKey.includes("sk-ant-oat");
183
+ }
184
+
185
+ function sanitizeSurrogates(text: string): string {
186
+ return text.replace(/[\uD800-\uDFFF]/g, "\uFFFD");
187
+ }
188
+
189
+ function convertContentBlocks(
190
+ content: (TextContent | ImageContent)[],
191
+ ): string | Array<{ type: "text"; text: string } | { type: "image"; source: any }> {
192
+ const hasImages = content.some((c) => c.type === "image");
193
+ if (!hasImages) {
194
+ return sanitizeSurrogates(content.map((c) => (c as TextContent).text).join("\n"));
195
+ }
196
+
197
+ const blocks = content.map((block) => {
198
+ if (block.type === "text") {
199
+ return { type: "text" as const, text: sanitizeSurrogates(block.text) };
200
+ }
201
+ return {
202
+ type: "image" as const,
203
+ source: {
204
+ type: "base64" as const,
205
+ media_type: block.mimeType,
206
+ data: block.data,
207
+ },
208
+ };
209
+ });
210
+
211
+ if (!blocks.some((b) => b.type === "text")) {
212
+ blocks.unshift({ type: "text" as const, text: "(see attached image)" });
213
+ }
214
+
215
+ return blocks;
216
+ }
217
+
218
+ function convertMessages(messages: Message[], isOAuth: boolean, _tools?: Tool[]): any[] {
219
+ const params: any[] = [];
220
+
221
+ for (let i = 0; i < messages.length; i++) {
222
+ const msg = messages[i];
223
+
224
+ if (msg.role === "user") {
225
+ if (typeof msg.content === "string") {
226
+ if (msg.content.trim()) {
227
+ params.push({ role: "user", content: sanitizeSurrogates(msg.content) });
228
+ }
229
+ } else {
230
+ const blocks: ContentBlockParam[] = msg.content.map((item) =>
231
+ item.type === "text"
232
+ ? { type: "text" as const, text: sanitizeSurrogates(item.text) }
233
+ : {
234
+ type: "image" as const,
235
+ source: { type: "base64" as const, media_type: item.mimeType as any, data: item.data },
236
+ },
237
+ );
238
+ if (blocks.length > 0) {
239
+ params.push({ role: "user", content: blocks });
240
+ }
241
+ }
242
+ } else if (msg.role === "assistant") {
243
+ const blocks: ContentBlockParam[] = [];
244
+ for (const block of msg.content) {
245
+ if (block.type === "text" && block.text.trim()) {
246
+ blocks.push({ type: "text", text: sanitizeSurrogates(block.text) });
247
+ } else if (block.type === "thinking" && block.thinking.trim()) {
248
+ if ((block as ThinkingContent).thinkingSignature) {
249
+ blocks.push({
250
+ type: "thinking" as any,
251
+ thinking: sanitizeSurrogates(block.thinking),
252
+ signature: (block as ThinkingContent).thinkingSignature!,
253
+ });
254
+ } else {
255
+ blocks.push({ type: "text", text: sanitizeSurrogates(block.thinking) });
256
+ }
257
+ } else if (block.type === "toolCall") {
258
+ blocks.push({
259
+ type: "tool_use",
260
+ id: block.id,
261
+ name: isOAuth ? toClaudeCodeName(block.name) : block.name,
262
+ input: block.arguments,
263
+ });
264
+ }
265
+ }
266
+ if (blocks.length > 0) {
267
+ params.push({ role: "assistant", content: blocks });
268
+ }
269
+ } else if (msg.role === "toolResult") {
270
+ const toolResults: any[] = [];
271
+ toolResults.push({
272
+ type: "tool_result",
273
+ tool_use_id: msg.toolCallId,
274
+ content: convertContentBlocks(msg.content),
275
+ is_error: msg.isError,
276
+ });
277
+
278
+ let j = i + 1;
279
+ while (j < messages.length && messages[j].role === "toolResult") {
280
+ const nextMsg = messages[j] as ToolResultMessage;
281
+ toolResults.push({
282
+ type: "tool_result",
283
+ tool_use_id: nextMsg.toolCallId,
284
+ content: convertContentBlocks(nextMsg.content),
285
+ is_error: nextMsg.isError,
286
+ });
287
+ j++;
288
+ }
289
+ i = j - 1;
290
+ params.push({ role: "user", content: toolResults });
291
+ }
292
+ }
293
+
294
+ // Add cache control to last user message
295
+ if (params.length > 0) {
296
+ const last = params[params.length - 1];
297
+ if (last.role === "user" && Array.isArray(last.content)) {
298
+ const lastBlock = last.content[last.content.length - 1];
299
+ if (lastBlock) {
300
+ lastBlock.cache_control = { type: "ephemeral" };
301
+ }
302
+ }
303
+ }
304
+
305
+ return params;
306
+ }
307
+
308
+ function convertTools(tools: Tool[], isOAuth: boolean): any[] {
309
+ return tools.map((tool) => ({
310
+ name: isOAuth ? toClaudeCodeName(tool.name) : tool.name,
311
+ description: tool.description,
312
+ input_schema: {
313
+ type: "object",
314
+ properties: (tool.parameters as any).properties || {},
315
+ required: (tool.parameters as any).required || [],
316
+ },
317
+ }));
318
+ }
319
+
320
+ function mapStopReason(reason: string): StopReason {
321
+ switch (reason) {
322
+ case "end_turn":
323
+ case "pause_turn":
324
+ case "stop_sequence":
325
+ return "stop";
326
+ case "max_tokens":
327
+ return "length";
328
+ case "tool_use":
329
+ return "toolUse";
330
+ default:
331
+ return "error";
332
+ }
333
+ }
334
+
335
+ function streamCustomAnthropic(
336
+ model: Model<Api>,
337
+ context: Context,
338
+ options?: SimpleStreamOptions,
339
+ ): AssistantMessageEventStream {
340
+ const stream = createAssistantMessageEventStream();
341
+
342
+ (async () => {
343
+ const output: AssistantMessage = {
344
+ role: "assistant",
345
+ content: [],
346
+ api: model.api,
347
+ provider: model.provider,
348
+ model: model.id,
349
+ usage: {
350
+ input: 0,
351
+ output: 0,
352
+ cacheRead: 0,
353
+ cacheWrite: 0,
354
+ totalTokens: 0,
355
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
356
+ },
357
+ stopReason: "pending",
358
+ timestamp: Date.now(),
359
+ };
360
+
361
+ try {
362
+ const apiKey = options?.apiKey ?? "";
363
+ const isOAuth = isOAuthToken(apiKey);
364
+
365
+ // Configure client based on auth type
366
+ const betaFeatures = ["fine-grained-tool-streaming-2025-05-14", "interleaved-thinking-2025-05-14"];
367
+ const clientOptions: any = {
368
+ baseURL: model.baseUrl,
369
+ dangerouslyAllowBrowser: true,
370
+ };
371
+
372
+ if (isOAuth) {
373
+ clientOptions.apiKey = null;
374
+ clientOptions.authToken = apiKey;
375
+ clientOptions.defaultHeaders = {
376
+ accept: "application/json",
377
+ "anthropic-dangerous-direct-browser-access": "true",
378
+ "anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
379
+ "user-agent": "claude-cli/2.1.2 (external, cli)",
380
+ "x-app": "cli",
381
+ };
382
+ } else {
383
+ clientOptions.apiKey = apiKey;
384
+ clientOptions.defaultHeaders = {
385
+ accept: "application/json",
386
+ "anthropic-dangerous-direct-browser-access": "true",
387
+ "anthropic-beta": betaFeatures.join(","),
388
+ };
389
+ }
390
+
391
+ const client = new Anthropic(clientOptions);
392
+
393
+ // Build request params
394
+ const params: MessageCreateParamsStreaming = {
395
+ model: model.id,
396
+ messages: convertMessages(context.messages, isOAuth, context.tools),
397
+ max_tokens: options?.maxTokens || Math.floor(model.maxTokens / 3),
398
+ stream: true,
399
+ };
400
+
401
+ // System prompt with Claude Code identity for OAuth
402
+ if (isOAuth) {
403
+ params.system = [
404
+ {
405
+ type: "text",
406
+ text: "You are Claude Code, Anthropic's official CLI for Claude.",
407
+ cache_control: { type: "ephemeral" },
408
+ },
409
+ ];
410
+ if (context.systemPrompt) {
411
+ params.system.push({
412
+ type: "text",
413
+ text: sanitizeSurrogates(context.systemPrompt),
414
+ cache_control: { type: "ephemeral" },
415
+ });
416
+ }
417
+ } else if (context.systemPrompt) {
418
+ params.system = [
419
+ {
420
+ type: "text",
421
+ text: sanitizeSurrogates(context.systemPrompt),
422
+ cache_control: { type: "ephemeral" },
423
+ },
424
+ ];
425
+ }
426
+
427
+ if (context.tools) {
428
+ params.tools = convertTools(context.tools, isOAuth);
429
+ }
430
+
431
+ // Handle thinking/reasoning
432
+ if (options?.reasoning && model.reasoning) {
433
+ const defaultBudgets: Record<string, number> = {
434
+ minimal: 1024,
435
+ low: 4096,
436
+ medium: 10240,
437
+ high: 20480,
438
+ };
439
+ const customBudget = options.thinkingBudgets?.[options.reasoning as keyof typeof options.thinkingBudgets];
440
+ params.thinking = {
441
+ type: "enabled",
442
+ budget_tokens: customBudget ?? defaultBudgets[options.reasoning] ?? 10240,
443
+ };
444
+ }
445
+
446
+ const anthropicStream = client.messages.stream({ ...params }, { signal: options?.signal });
447
+ stream.push({ type: "start", partial: output });
448
+
449
+ type Block = (ThinkingContent | TextContent | (ToolCall & { partialJson: string })) & { index: number };
450
+ const blocks = output.content as Block[];
451
+
452
+ for await (const event of anthropicStream) {
453
+ if (event.type === "message_start") {
454
+ output.usage.input = event.message.usage.input_tokens || 0;
455
+ output.usage.output = event.message.usage.output_tokens || 0;
456
+ output.usage.cacheRead = (event.message.usage as any).cache_read_input_tokens || 0;
457
+ output.usage.cacheWrite = (event.message.usage as any).cache_creation_input_tokens || 0;
458
+ output.usage.totalTokens =
459
+ output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
460
+ calculateCost(model, output.usage);
461
+ } else if (event.type === "content_block_start") {
462
+ if (event.content_block.type === "text") {
463
+ output.content.push({ type: "text", text: "", index: event.index } as any);
464
+ stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
465
+ } else if (event.content_block.type === "thinking") {
466
+ output.content.push({
467
+ type: "thinking",
468
+ thinking: "",
469
+ thinkingSignature: "",
470
+ index: event.index,
471
+ } as any);
472
+ stream.push({ type: "thinking_start", contentIndex: output.content.length - 1, partial: output });
473
+ } else if (event.content_block.type === "tool_use") {
474
+ output.content.push({
475
+ type: "toolCall",
476
+ id: event.content_block.id,
477
+ name: isOAuth
478
+ ? fromClaudeCodeName(event.content_block.name, context.tools)
479
+ : event.content_block.name,
480
+ arguments: {},
481
+ partialJson: "",
482
+ index: event.index,
483
+ } as any);
484
+ stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
485
+ }
486
+ } else if (event.type === "content_block_delta") {
487
+ const index = blocks.findIndex((b) => b.index === event.index);
488
+ const block = blocks[index];
489
+ if (!block) continue;
490
+
491
+ if (event.delta.type === "text_delta" && block.type === "text") {
492
+ block.text += event.delta.text;
493
+ stream.push({ type: "text_delta", contentIndex: index, delta: event.delta.text, partial: output });
494
+ } else if (event.delta.type === "thinking_delta" && block.type === "thinking") {
495
+ block.thinking += event.delta.thinking;
496
+ stream.push({
497
+ type: "thinking_delta",
498
+ contentIndex: index,
499
+ delta: event.delta.thinking,
500
+ partial: output,
501
+ });
502
+ } else if (event.delta.type === "input_json_delta" && block.type === "toolCall") {
503
+ (block as any).partialJson += event.delta.partial_json;
504
+ try {
505
+ block.arguments = JSON.parse((block as any).partialJson);
506
+ } catch {}
507
+ stream.push({
508
+ type: "toolcall_delta",
509
+ contentIndex: index,
510
+ delta: event.delta.partial_json,
511
+ partial: output,
512
+ });
513
+ } else if (event.delta.type === "signature_delta" && block.type === "thinking") {
514
+ block.thinkingSignature = (block.thinkingSignature || "") + (event.delta as any).signature;
515
+ }
516
+ } else if (event.type === "content_block_stop") {
517
+ const index = blocks.findIndex((b) => b.index === event.index);
518
+ const block = blocks[index];
519
+ if (!block) continue;
520
+
521
+ delete (block as any).index;
522
+ if (block.type === "text") {
523
+ stream.push({ type: "text_end", contentIndex: index, content: block.text, partial: output });
524
+ } else if (block.type === "thinking") {
525
+ stream.push({ type: "thinking_end", contentIndex: index, content: block.thinking, partial: output });
526
+ } else if (block.type === "toolCall") {
527
+ try {
528
+ block.arguments = JSON.parse((block as any).partialJson);
529
+ } catch {}
530
+ delete (block as any).partialJson;
531
+ stream.push({ type: "toolcall_end", contentIndex: index, toolCall: block, partial: output });
532
+ }
533
+ } else if (event.type === "message_delta") {
534
+ if ((event.delta as any).stop_reason) {
535
+ output.stopReason = mapStopReason((event.delta as any).stop_reason);
536
+ }
537
+ output.usage.input = (event.usage as any).input_tokens || 0;
538
+ output.usage.output = (event.usage as any).output_tokens || 0;
539
+ output.usage.cacheRead = (event.usage as any).cache_read_input_tokens || 0;
540
+ output.usage.cacheWrite = (event.usage as any).cache_creation_input_tokens || 0;
541
+ output.usage.totalTokens =
542
+ output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
543
+ calculateCost(model, output.usage);
544
+ }
545
+ }
546
+
547
+ if (options?.signal?.aborted) {
548
+ throw new Error("Request was aborted");
549
+ }
550
+ if (output.stopReason === "pending") {
551
+ throw new Error("Anthropic stream ended without a stop reason");
552
+ }
553
+ if (output.stopReason === "error" || output.stopReason === "aborted") {
554
+ throw new Error(output.errorMessage || "An unknown error occurred");
555
+ }
556
+
557
+ stream.push({ type: "done", reason: output.stopReason, message: output });
558
+ stream.end();
559
+ } catch (error) {
560
+ for (const block of output.content) delete (block as any).index;
561
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
562
+ output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
563
+ stream.push({ type: "error", reason: output.stopReason, error: output });
564
+ stream.end();
565
+ }
566
+ })();
567
+
568
+ return stream;
569
+ }
570
+
571
+ // =============================================================================
572
+ // Extension Entry Point
573
+ // =============================================================================
574
+
575
+ export default function (pi: ExtensionAPI) {
576
+ pi.registerProvider("custom-anthropic", {
577
+ baseUrl: "https://api.anthropic.com",
578
+ apiKey: "$CUSTOM_ANTHROPIC_API_KEY",
579
+ api: "custom-anthropic-api",
580
+
581
+ models: [
582
+ {
583
+ id: "claude-opus-4-5",
584
+ name: "Claude Opus 4.5 (Custom)",
585
+ reasoning: true,
586
+ input: ["text", "image"],
587
+ cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
588
+ contextWindow: 200000,
589
+ maxTokens: 64000,
590
+ },
591
+ {
592
+ id: "claude-sonnet-4-5",
593
+ name: "Claude Sonnet 4.5 (Custom)",
594
+ reasoning: true,
595
+ input: ["text", "image"],
596
+ cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
597
+ contextWindow: 200000,
598
+ maxTokens: 64000,
599
+ },
600
+ ],
601
+
602
+ oauth: {
603
+ name: "Custom Anthropic (Claude Pro/Max)",
604
+ login: loginAnthropic,
605
+ refreshToken: refreshAnthropicToken,
606
+ getApiKey: (cred) => cred.access,
607
+ },
608
+
609
+ streamSimple: streamCustomAnthropic,
610
+ });
611
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "pi-extension-custom-provider",
3
+ "version": "0.84.4",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "pi-extension-custom-provider",
9
+ "version": "0.84.4",
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": "0.84.4",
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
+ }