@averyyy/pi-coding-agent 0.87.1-piclient.2 → 1.0.0-piclient.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 (765) hide show
  1. package/CHANGELOG.md +183 -0
  2. package/dist/bun/cli.d.ts.map +1 -1
  3. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  4. package/dist/bun/restore-sandbox-env.js.map +1 -1
  5. package/dist/bun/runtime-setup.d.ts.map +1 -1
  6. package/dist/bun/runtime-setup.js +4 -1
  7. package/dist/bun/runtime-setup.js.map +1 -1
  8. package/dist/bun/sandbox-env-setup.d.ts.map +1 -1
  9. package/dist/bundle/chunks/anthropic-messages-UID2PALB.js +6 -0
  10. package/dist/bundle/chunks/anthropic.js +2 -2
  11. package/dist/bundle/chunks/azure-openai-responses-WK37QQ3X.js +2 -0
  12. package/dist/bundle/chunks/bedrock-converse-stream.js +3 -3
  13. package/dist/bundle/chunks/chunk-2LGHNI5Y.js +1553 -0
  14. package/dist/bundle/chunks/chunk-6D7LHLKG.js +2 -0
  15. package/dist/bundle/chunks/chunk-7JGR3GZN.js +11 -0
  16. package/dist/bundle/chunks/{chunk-FUXEF6JQ.js → chunk-CWVWZD3J.js} +2 -2
  17. package/dist/bundle/chunks/chunk-GIUN2MS4.js +16 -0
  18. package/dist/bundle/chunks/chunk-H3QXYIF7.js +31 -0
  19. package/dist/bundle/chunks/chunk-KYK7L7MP.js +127 -0
  20. package/dist/bundle/chunks/chunk-LD2P6SFZ.js +2 -0
  21. package/dist/bundle/chunks/chunk-LDPPAHPJ.js +4 -0
  22. package/dist/bundle/chunks/chunk-NEUJZQL3.js +19 -0
  23. package/dist/bundle/chunks/chunk-OI6YFHHK.js +82 -0
  24. package/dist/bundle/chunks/chunk-OSKPX3Z5.js +2 -0
  25. package/dist/bundle/chunks/{chunk-XDUWOHPL.js → chunk-S3GGRYIO.js} +2 -2
  26. package/dist/bundle/chunks/chunk-SQXKOUF6.js +2 -0
  27. package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
  28. package/dist/bundle/chunks/chunk-VIV3CWXG.js +2 -0
  29. package/dist/bundle/chunks/chunk-Y5O5BZGX.js +136 -0
  30. package/dist/bundle/chunks/{chunk-UZNGGY6N.js → chunk-Z772OFUN.js} +3 -3
  31. package/dist/bundle/chunks/cli-JE36AHMI.js +51 -0
  32. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NPQN263E.js +2 -0
  33. package/dist/bundle/chunks/codemode-worker.js +354 -0
  34. package/dist/bundle/chunks/execute-UX73LR4F.js +367 -0
  35. package/dist/bundle/chunks/github-copilot.js +1 -1
  36. package/dist/bundle/chunks/google-generative-ai-OHRSHIE7.js +2 -0
  37. package/dist/bundle/chunks/google-vertex-KXEB3MVO.js +2 -0
  38. package/dist/bundle/chunks/{https-proxy-agent-2VXB7436.js → https-proxy-agent-UDEHOBGS.js} +1 -1
  39. package/dist/bundle/chunks/{lib-HGQMNYVT.js → lib-TEDK3E5I.js} +2 -2
  40. package/dist/bundle/chunks/llama-cpp-classify-XT44PI3C.js +22 -0
  41. package/dist/bundle/chunks/mistral-conversations-DKVFNQL6.js +5 -0
  42. package/dist/bundle/chunks/openai-chatgpt.js +75 -0
  43. package/dist/bundle/chunks/{openai-codex-responses-SG7PGUUZ.js → openai-codex-responses-WVERB76N.js} +2 -2
  44. package/dist/bundle/chunks/openai-codex.js +2 -2
  45. package/dist/bundle/chunks/{openai-completions-OBX42CLD.js → openai-completions-JXDDPZ23.js} +2 -2
  46. package/dist/bundle/chunks/openai-responses-WDT74L23.js +3 -0
  47. package/dist/bundle/chunks/{openrouter-images-N4XVVFSD.js → openrouter-images-ZVXWCSIM.js} +1 -1
  48. package/dist/bundle/chunks/openrouter.js +2 -2
  49. package/dist/bundle/chunks/pi-logo-animation-APS4JS6B.js +2 -0
  50. package/dist/bundle/chunks/{pi-messages-GFKBWJHZ.js → pi-messages-TM5SOOIW.js} +2 -2
  51. package/dist/bundle/chunks/radius.js +2 -2
  52. package/dist/bundle/chunks/runtime-MPXPM7VL.js +2 -0
  53. package/dist/bundle/chunks/typesafe-system-one-A4CZTQWZ.js +2 -0
  54. package/dist/bundle/chunks/virtual-modules-XLXFDFIX.js +2 -0
  55. package/dist/bundle/cli-runtime.js +1 -1
  56. package/dist/bundle/index.js +1 -1
  57. package/dist/bundle/rpc-entry.js +1 -1
  58. package/dist/cli/args.d.ts.map +1 -1
  59. package/dist/cli/args.js +6 -5
  60. package/dist/cli/args.js.map +1 -1
  61. package/dist/cli/auth-check.d.ts.map +1 -1
  62. package/dist/cli/auth-check.js.map +1 -1
  63. package/dist/cli/auth-command.d.ts.map +1 -1
  64. package/dist/cli/auth-command.js.map +1 -1
  65. package/dist/cli/config-selector.d.ts.map +1 -1
  66. package/dist/cli/config-selector.js.map +1 -1
  67. package/dist/cli/credential-print.d.ts.map +1 -1
  68. package/dist/cli/credential-print.js.map +1 -1
  69. package/dist/cli/file-processor.d.ts.map +1 -1
  70. package/dist/cli/file-processor.js.map +1 -1
  71. package/dist/cli/initial-message.d.ts +1 -1
  72. package/dist/cli/initial-message.d.ts.map +1 -1
  73. package/dist/cli/initial-message.js.map +1 -1
  74. package/dist/cli/list-models.d.ts.map +1 -1
  75. package/dist/cli/list-models.js.map +1 -1
  76. package/dist/cli/project-trust.d.ts.map +1 -1
  77. package/dist/cli/project-trust.js.map +1 -1
  78. package/dist/cli/session-picker.d.ts.map +1 -1
  79. package/dist/cli/session-picker.js.map +1 -1
  80. package/dist/cli/setup.d.ts.map +1 -1
  81. package/dist/cli/setup.js.map +1 -1
  82. package/dist/cli/startup-ui.d.ts.map +1 -1
  83. package/dist/cli/startup-ui.js +38 -30
  84. package/dist/cli/startup-ui.js.map +1 -1
  85. package/dist/cli.d.ts.map +1 -1
  86. package/dist/config.d.ts +15 -4
  87. package/dist/config.d.ts.map +1 -1
  88. package/dist/config.js +33 -4
  89. package/dist/config.js.map +1 -1
  90. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  91. package/dist/core/agent-session-runtime.js +1 -1
  92. package/dist/core/agent-session-runtime.js.map +1 -1
  93. package/dist/core/agent-session-services.d.ts.map +1 -1
  94. package/dist/core/agent-session-services.js +13 -0
  95. package/dist/core/agent-session-services.js.map +1 -1
  96. package/dist/core/agent-session.d.ts +133 -12
  97. package/dist/core/agent-session.d.ts.map +1 -1
  98. package/dist/core/agent-session.js +598 -297
  99. package/dist/core/agent-session.js.map +1 -1
  100. package/dist/core/auth-guidance.d.ts.map +1 -1
  101. package/dist/core/auth-guidance.js.map +1 -1
  102. package/dist/core/auth-storage.d.ts.map +1 -1
  103. package/dist/core/auth-storage.js.map +1 -1
  104. package/dist/core/bash-executor.d.ts.map +1 -1
  105. package/dist/core/bash-executor.js.map +1 -1
  106. package/dist/core/bug-report-upload.d.ts.map +1 -1
  107. package/dist/core/bug-report-upload.js.map +1 -1
  108. package/dist/core/bug-report.d.ts +1 -1
  109. package/dist/core/bug-report.d.ts.map +1 -1
  110. package/dist/core/bug-report.js +1 -1
  111. package/dist/core/bug-report.js.map +1 -1
  112. package/dist/core/cache-stats.d.ts.map +1 -1
  113. package/dist/core/cache-stats.js.map +1 -1
  114. package/dist/core/cache-warmer.d.ts.map +1 -1
  115. package/dist/core/cache-warmer.js.map +1 -1
  116. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  117. package/dist/core/compaction/branch-summarization.js.map +1 -1
  118. package/dist/core/compaction/compaction.d.ts.map +1 -1
  119. package/dist/core/compaction/compaction.js +1 -22
  120. package/dist/core/compaction/compaction.js.map +1 -1
  121. package/dist/core/compaction/index.d.ts.map +1 -1
  122. package/dist/core/compaction/utils.d.ts +2 -1
  123. package/dist/core/compaction/utils.d.ts.map +1 -1
  124. package/dist/core/compaction/utils.js +25 -18
  125. package/dist/core/compaction/utils.js.map +1 -1
  126. package/dist/core/crash-log.d.ts.map +1 -1
  127. package/dist/core/crash-log.js +2 -1
  128. package/dist/core/crash-log.js.map +1 -1
  129. package/dist/core/defaults.d.ts.map +1 -1
  130. package/dist/core/diagnostics.d.ts.map +1 -1
  131. package/dist/core/event-bus.d.ts.map +1 -1
  132. package/dist/core/event-bus.js.map +1 -1
  133. package/dist/core/exec.d.ts.map +1 -1
  134. package/dist/core/exec.js.map +1 -1
  135. package/dist/core/experimental.d.ts.map +1 -1
  136. package/dist/core/experimental.js.map +1 -1
  137. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  138. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  139. package/dist/core/export-html/index.d.ts.map +1 -1
  140. package/dist/core/export-html/index.js.map +1 -1
  141. package/dist/core/export-html/template.css +10 -0
  142. package/dist/core/export-html/template.js +66 -17
  143. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  144. package/dist/core/export-html/tool-renderer.js.map +1 -1
  145. package/dist/core/extensions/index.d.ts +1 -1
  146. package/dist/core/extensions/index.d.ts.map +1 -1
  147. package/dist/core/extensions/index.js.map +1 -1
  148. package/dist/core/extensions/jiti-loader.d.ts.map +1 -1
  149. package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -1
  150. package/dist/core/extensions/loader.d.ts.map +1 -1
  151. package/dist/core/extensions/loader.js +67 -5
  152. package/dist/core/extensions/loader.js.map +1 -1
  153. package/dist/core/extensions/runner.d.ts +18 -1
  154. package/dist/core/extensions/runner.d.ts.map +1 -1
  155. package/dist/core/extensions/runner.js +99 -0
  156. package/dist/core/extensions/runner.js.map +1 -1
  157. package/dist/core/extensions/types.d.ts +301 -22
  158. package/dist/core/extensions/types.d.ts.map +1 -1
  159. package/dist/core/extensions/types.js.map +1 -1
  160. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  161. package/dist/core/extensions/wrapper.d.ts +2 -2
  162. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  163. package/dist/core/extensions/wrapper.js +3 -3
  164. package/dist/core/extensions/wrapper.js.map +1 -1
  165. package/dist/core/footer-data-provider.d.ts.map +1 -1
  166. package/dist/core/footer-data-provider.js.map +1 -1
  167. package/dist/core/http-dispatcher.d.ts.map +1 -1
  168. package/dist/core/http-dispatcher.js.map +1 -1
  169. package/dist/core/index.d.ts.map +1 -1
  170. package/dist/core/keybindings.d.ts +1 -1
  171. package/dist/core/keybindings.d.ts.map +1 -1
  172. package/dist/core/keybindings.js +1 -1
  173. package/dist/core/keybindings.js.map +1 -1
  174. package/dist/core/mcp-servers.d.ts +125 -0
  175. package/dist/core/mcp-servers.d.ts.map +1 -0
  176. package/dist/core/mcp-servers.js +198 -0
  177. package/dist/core/mcp-servers.js.map +1 -0
  178. package/dist/core/messages.d.ts.map +1 -1
  179. package/dist/core/messages.js.map +1 -1
  180. package/dist/core/model-config.d.ts.map +1 -1
  181. package/dist/core/model-config.js.map +1 -1
  182. package/dist/core/model-registry.d.ts +15 -1
  183. package/dist/core/model-registry.d.ts.map +1 -1
  184. package/dist/core/model-registry.js +29 -0
  185. package/dist/core/model-registry.js.map +1 -1
  186. package/dist/core/model-resolver.d.ts +2 -2
  187. package/dist/core/model-resolver.d.ts.map +1 -1
  188. package/dist/core/model-resolver.js +5 -5
  189. package/dist/core/model-resolver.js.map +1 -1
  190. package/dist/core/model-runtime.d.ts +47 -3
  191. package/dist/core/model-runtime.d.ts.map +1 -1
  192. package/dist/core/model-runtime.js +189 -35
  193. package/dist/core/model-runtime.js.map +1 -1
  194. package/dist/core/models-store.d.ts.map +1 -1
  195. package/dist/core/models-store.js.map +1 -1
  196. package/dist/core/nested-tool-calls.d.ts +102 -0
  197. package/dist/core/nested-tool-calls.d.ts.map +1 -0
  198. package/dist/core/nested-tool-calls.js +178 -0
  199. package/dist/core/nested-tool-calls.js.map +1 -0
  200. package/dist/core/output-guard.d.ts.map +1 -1
  201. package/dist/core/output-guard.js.map +1 -1
  202. package/dist/core/package-manager.d.ts +4 -0
  203. package/dist/core/package-manager.d.ts.map +1 -1
  204. package/dist/core/package-manager.js +59 -12
  205. package/dist/core/package-manager.js.map +1 -1
  206. package/dist/core/pi-client-cli-adapter.d.ts.map +1 -1
  207. package/dist/core/pi-client-cli-adapter.js.map +1 -1
  208. package/dist/core/pi-client-runtime-update.d.ts.map +1 -1
  209. package/dist/core/pi-client-runtime-update.js.map +1 -1
  210. package/dist/core/pi-manifest.d.ts.map +1 -1
  211. package/dist/core/pi-manifest.js.map +1 -1
  212. package/dist/core/pi-server-client.d.ts.map +1 -1
  213. package/dist/core/pi-server-client.js.map +1 -1
  214. package/dist/core/pi-server-protocol.d.ts.map +1 -1
  215. package/dist/core/pi-server-protocol.js.map +1 -1
  216. package/dist/core/pi-server-request.d.ts.map +1 -1
  217. package/dist/core/pi-server-request.js.map +1 -1
  218. package/dist/core/project-trust.d.ts.map +1 -1
  219. package/dist/core/project-trust.js.map +1 -1
  220. package/dist/core/prompt-templates.d.ts.map +1 -1
  221. package/dist/core/prompt-templates.js.map +1 -1
  222. package/dist/core/provider-attribution.d.ts.map +1 -1
  223. package/dist/core/provider-attribution.js.map +1 -1
  224. package/dist/core/provider-composer.d.ts +40 -21
  225. package/dist/core/provider-composer.d.ts.map +1 -1
  226. package/dist/core/provider-composer.js +92 -40
  227. package/dist/core/provider-composer.js.map +1 -1
  228. package/dist/core/radius.d.ts +2 -0
  229. package/dist/core/radius.d.ts.map +1 -1
  230. package/dist/core/radius.js +2 -0
  231. package/dist/core/radius.js.map +1 -1
  232. package/dist/core/remote-catalog-provider.d.ts +8 -1
  233. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  234. package/dist/core/remote-catalog-provider.js +21 -11
  235. package/dist/core/remote-catalog-provider.js.map +1 -1
  236. package/dist/core/resolve-config-value.d.ts.map +1 -1
  237. package/dist/core/resolve-config-value.js.map +1 -1
  238. package/dist/core/resource-loader.d.ts +7 -1
  239. package/dist/core/resource-loader.d.ts.map +1 -1
  240. package/dist/core/resource-loader.js +161 -35
  241. package/dist/core/resource-loader.js.map +1 -1
  242. package/dist/core/runtime-credentials.d.ts.map +1 -1
  243. package/dist/core/runtime-credentials.js.map +1 -1
  244. package/dist/core/sdk.d.ts +1 -1
  245. package/dist/core/sdk.d.ts.map +1 -1
  246. package/dist/core/sdk.js +25 -6
  247. package/dist/core/sdk.js.map +1 -1
  248. package/dist/core/session-cwd.d.ts.map +1 -1
  249. package/dist/core/session-cwd.js.map +1 -1
  250. package/dist/core/session-export.d.ts.map +1 -1
  251. package/dist/core/session-export.js.map +1 -1
  252. package/dist/core/session-manager.d.ts +9 -0
  253. package/dist/core/session-manager.d.ts.map +1 -1
  254. package/dist/core/session-manager.js +22 -22
  255. package/dist/core/session-manager.js.map +1 -1
  256. package/dist/core/settings-diagnostics.d.ts.map +1 -1
  257. package/dist/core/settings-diagnostics.js.map +1 -1
  258. package/dist/core/settings-manager.d.ts +36 -4
  259. package/dist/core/settings-manager.d.ts.map +1 -1
  260. package/dist/core/settings-manager.js +75 -4
  261. package/dist/core/settings-manager.js.map +1 -1
  262. package/dist/core/skills.d.ts.map +1 -1
  263. package/dist/core/skills.js.map +1 -1
  264. package/dist/core/slash-commands.d.ts.map +1 -1
  265. package/dist/core/source-info.d.ts +8 -0
  266. package/dist/core/source-info.d.ts.map +1 -1
  267. package/dist/core/source-info.js +16 -0
  268. package/dist/core/source-info.js.map +1 -1
  269. package/dist/core/system-prompt.d.ts.map +1 -1
  270. package/dist/core/system-prompt.js +1 -1
  271. package/dist/core/system-prompt.js.map +1 -1
  272. package/dist/core/telemetry.d.ts.map +1 -1
  273. package/dist/core/telemetry.js.map +1 -1
  274. package/dist/core/timings.d.ts.map +1 -1
  275. package/dist/core/timings.js.map +1 -1
  276. package/dist/core/tools/bash.d.ts +12 -0
  277. package/dist/core/tools/bash.d.ts.map +1 -1
  278. package/dist/core/tools/bash.js +33 -2
  279. package/dist/core/tools/bash.js.map +1 -1
  280. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  281. package/dist/core/tools/edit-diff.js.map +1 -1
  282. package/dist/core/tools/edit.d.ts.map +1 -1
  283. package/dist/core/tools/edit.js.map +1 -1
  284. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  285. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  286. package/dist/core/tools/find.d.ts.map +1 -1
  287. package/dist/core/tools/find.js.map +1 -1
  288. package/dist/core/tools/grep.d.ts.map +1 -1
  289. package/dist/core/tools/grep.js.map +1 -1
  290. package/dist/core/tools/index.d.ts.map +1 -1
  291. package/dist/core/tools/index.js.map +1 -1
  292. package/dist/core/tools/ls.d.ts.map +1 -1
  293. package/dist/core/tools/ls.js.map +1 -1
  294. package/dist/core/tools/output-accumulator.d.ts +11 -0
  295. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  296. package/dist/core/tools/output-accumulator.js +36 -0
  297. package/dist/core/tools/output-accumulator.js.map +1 -1
  298. package/dist/core/tools/path-utils.d.ts.map +1 -1
  299. package/dist/core/tools/path-utils.js.map +1 -1
  300. package/dist/core/tools/powershell.d.ts.map +1 -1
  301. package/dist/core/tools/powershell.js.map +1 -1
  302. package/dist/core/tools/read.d.ts.map +1 -1
  303. package/dist/core/tools/read.js.map +1 -1
  304. package/dist/core/tools/render-utils.d.ts +6 -0
  305. package/dist/core/tools/render-utils.d.ts.map +1 -1
  306. package/dist/core/tools/render-utils.js +26 -0
  307. package/dist/core/tools/render-utils.js.map +1 -1
  308. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  309. package/dist/core/tools/renderers/bash.js +11 -32
  310. package/dist/core/tools/renderers/bash.js.map +1 -1
  311. package/dist/core/tools/renderers/edit.d.ts.map +1 -1
  312. package/dist/core/tools/renderers/edit.js.map +1 -1
  313. package/dist/core/tools/renderers/find.d.ts.map +1 -1
  314. package/dist/core/tools/renderers/find.js.map +1 -1
  315. package/dist/core/tools/renderers/grep.d.ts.map +1 -1
  316. package/dist/core/tools/renderers/grep.js.map +1 -1
  317. package/dist/core/tools/renderers/index.d.ts.map +1 -1
  318. package/dist/core/tools/renderers/index.js.map +1 -1
  319. package/dist/core/tools/renderers/ls.d.ts.map +1 -1
  320. package/dist/core/tools/renderers/ls.js.map +1 -1
  321. package/dist/core/tools/renderers/read.d.ts.map +1 -1
  322. package/dist/core/tools/renderers/read.js +3 -2
  323. package/dist/core/tools/renderers/read.js.map +1 -1
  324. package/dist/core/tools/renderers/write.d.ts.map +1 -1
  325. package/dist/core/tools/renderers/write.js.map +1 -1
  326. package/dist/core/tools/tool-definition-wrapper.d.ts +5 -3
  327. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  328. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  329. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  330. package/dist/core/tools/truncate.d.ts +14 -0
  331. package/dist/core/tools/truncate.d.ts.map +1 -1
  332. package/dist/core/tools/truncate.js +29 -0
  333. package/dist/core/tools/truncate.js.map +1 -1
  334. package/dist/core/tools/write.d.ts.map +1 -1
  335. package/dist/core/tools/write.js.map +1 -1
  336. package/dist/core/trust-manager.d.ts.map +1 -1
  337. package/dist/core/trust-manager.js +1 -0
  338. package/dist/core/trust-manager.js.map +1 -1
  339. package/dist/core/usage-totals.d.ts +2 -0
  340. package/dist/core/usage-totals.d.ts.map +1 -1
  341. package/dist/core/usage-totals.js +23 -0
  342. package/dist/core/usage-totals.js.map +1 -1
  343. package/dist/core/virtual-models.d.ts +117 -0
  344. package/dist/core/virtual-models.d.ts.map +1 -0
  345. package/dist/core/virtual-models.js +124 -0
  346. package/dist/core/virtual-models.js.map +1 -0
  347. package/dist/extensions/codemode/execute.d.ts +16 -0
  348. package/dist/extensions/codemode/execute.d.ts.map +1 -0
  349. package/dist/extensions/codemode/execute.js +536 -0
  350. package/dist/extensions/codemode/execute.js.map +1 -0
  351. package/dist/extensions/codemode/execute.lazy.d.ts +3 -0
  352. package/dist/extensions/codemode/execute.lazy.d.ts.map +1 -0
  353. package/dist/extensions/codemode/execute.lazy.js +3 -0
  354. package/dist/extensions/codemode/execute.lazy.js.map +1 -0
  355. package/dist/extensions/codemode/index.d.ts +21 -0
  356. package/dist/extensions/codemode/index.d.ts.map +1 -0
  357. package/dist/extensions/codemode/index.js +31 -0
  358. package/dist/extensions/codemode/index.js.map +1 -0
  359. package/dist/extensions/codemode/renderer.d.ts +12 -0
  360. package/dist/extensions/codemode/renderer.d.ts.map +1 -0
  361. package/dist/extensions/codemode/renderer.js +137 -0
  362. package/dist/extensions/codemode/renderer.js.map +1 -0
  363. package/dist/extensions/codemode/tool.d.ts +123 -0
  364. package/dist/extensions/codemode/tool.d.ts.map +1 -0
  365. package/dist/extensions/codemode/tool.js +268 -0
  366. package/dist/extensions/codemode/tool.js.map +1 -0
  367. package/dist/extensions/codemode/worker.d.ts +7 -0
  368. package/dist/extensions/codemode/worker.d.ts.map +1 -0
  369. package/dist/extensions/codemode/worker.js +7 -0
  370. package/dist/extensions/codemode/worker.js.map +1 -0
  371. package/dist/extensions/index.d.ts.map +1 -1
  372. package/dist/extensions/index.js +11 -1
  373. package/dist/extensions/index.js.map +1 -1
  374. package/dist/extensions/llama/client.d.ts.map +1 -1
  375. package/dist/extensions/llama/client.js.map +1 -1
  376. package/dist/extensions/llama/huggingface.d.ts.map +1 -1
  377. package/dist/extensions/llama/huggingface.js.map +1 -1
  378. package/dist/extensions/llama/index.d.ts.map +1 -1
  379. package/dist/extensions/llama/index.js.map +1 -1
  380. package/dist/extensions/llama/provider.d.ts +1 -1
  381. package/dist/extensions/llama/provider.d.ts.map +1 -1
  382. package/dist/extensions/llama/provider.js +65 -13
  383. package/dist/extensions/llama/provider.js.map +1 -1
  384. package/dist/extensions/llama/ui.d.ts.map +1 -1
  385. package/dist/extensions/llama/ui.js.map +1 -1
  386. package/dist/extensions/mcp/cli.d.ts +21 -0
  387. package/dist/extensions/mcp/cli.d.ts.map +1 -0
  388. package/dist/extensions/mcp/cli.js +500 -0
  389. package/dist/extensions/mcp/cli.js.map +1 -0
  390. package/dist/extensions/mcp/cli.lazy.d.ts +3 -0
  391. package/dist/extensions/mcp/cli.lazy.d.ts.map +1 -0
  392. package/dist/extensions/mcp/cli.lazy.js +3 -0
  393. package/dist/extensions/mcp/cli.lazy.js.map +1 -0
  394. package/dist/extensions/mcp/config.d.ts +72 -0
  395. package/dist/extensions/mcp/config.d.ts.map +1 -0
  396. package/dist/extensions/mcp/config.js +158 -0
  397. package/dist/extensions/mcp/config.js.map +1 -0
  398. package/dist/extensions/mcp/index.d.ts +76 -0
  399. package/dist/extensions/mcp/index.d.ts.map +1 -0
  400. package/dist/extensions/mcp/index.js +1066 -0
  401. package/dist/extensions/mcp/index.js.map +1 -0
  402. package/dist/extensions/mcp/log.d.ts +16 -0
  403. package/dist/extensions/mcp/log.d.ts.map +1 -0
  404. package/dist/extensions/mcp/log.js +66 -0
  405. package/dist/extensions/mcp/log.js.map +1 -0
  406. package/dist/extensions/mcp/oauth.d.ts +97 -0
  407. package/dist/extensions/mcp/oauth.d.ts.map +1 -0
  408. package/dist/extensions/mcp/oauth.js +358 -0
  409. package/dist/extensions/mcp/oauth.js.map +1 -0
  410. package/dist/extensions/mcp/resources.d.ts +43 -0
  411. package/dist/extensions/mcp/resources.d.ts.map +1 -0
  412. package/dist/extensions/mcp/resources.js +262 -0
  413. package/dist/extensions/mcp/resources.js.map +1 -0
  414. package/dist/extensions/mcp/runtime.d.ts +98 -0
  415. package/dist/extensions/mcp/runtime.d.ts.map +1 -0
  416. package/dist/extensions/mcp/runtime.js +395 -0
  417. package/dist/extensions/mcp/runtime.js.map +1 -0
  418. package/dist/extensions/mcp/runtime.lazy.d.ts +3 -0
  419. package/dist/extensions/mcp/runtime.lazy.d.ts.map +1 -0
  420. package/dist/extensions/mcp/runtime.lazy.js +3 -0
  421. package/dist/extensions/mcp/runtime.lazy.js.map +1 -0
  422. package/dist/extensions/mcp/tools.d.ts +84 -0
  423. package/dist/extensions/mcp/tools.d.ts.map +1 -0
  424. package/dist/extensions/mcp/tools.js +251 -0
  425. package/dist/extensions/mcp/tools.js.map +1 -0
  426. package/dist/extensions/mcp/ui.d.ts +60 -0
  427. package/dist/extensions/mcp/ui.d.ts.map +1 -0
  428. package/dist/extensions/mcp/ui.js +174 -0
  429. package/dist/extensions/mcp/ui.js.map +1 -0
  430. package/dist/extensions/tool-search/index.d.ts +12 -0
  431. package/dist/extensions/tool-search/index.d.ts.map +1 -0
  432. package/dist/extensions/tool-search/index.js +15 -0
  433. package/dist/extensions/tool-search/index.js.map +1 -0
  434. package/dist/extensions/tool-search/tool.d.ts +73 -0
  435. package/dist/extensions/tool-search/tool.d.ts.map +1 -0
  436. package/dist/extensions/tool-search/tool.js +189 -0
  437. package/dist/extensions/tool-search/tool.js.map +1 -0
  438. package/dist/index.d.ts +10 -3
  439. package/dist/index.d.ts.map +1 -1
  440. package/dist/index.js +5 -0
  441. package/dist/index.js.map +1 -1
  442. package/dist/main.d.ts.map +1 -1
  443. package/dist/main.js +16 -0
  444. package/dist/main.js.map +1 -1
  445. package/dist/migrations.d.ts.map +1 -1
  446. package/dist/migrations.js.map +1 -1
  447. package/dist/modes/index.d.ts.map +1 -1
  448. package/dist/modes/interactive/bug-report.d.ts.map +1 -1
  449. package/dist/modes/interactive/bug-report.js.map +1 -1
  450. package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
  451. package/dist/modes/interactive/chat-viewport.js.map +1 -1
  452. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  453. package/dist/modes/interactive/components/armin.js.map +1 -1
  454. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  455. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  456. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  457. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  458. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  459. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  460. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  461. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  462. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  463. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  464. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  465. package/dist/modes/interactive/components/config-selector.js +13 -3
  466. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  467. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  468. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  469. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  470. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  471. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  472. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  473. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  474. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  475. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  476. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  477. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  478. package/dist/modes/interactive/components/diff.js.map +1 -1
  479. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  480. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  481. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  482. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  483. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  484. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  485. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  486. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  487. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  488. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  489. package/dist/modes/interactive/components/first-time-setup.d.ts +4 -4
  490. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  491. package/dist/modes/interactive/components/first-time-setup.js +8 -2
  492. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  493. package/dist/modes/interactive/components/footer.d.ts +7 -0
  494. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  495. package/dist/modes/interactive/components/footer.js +43 -3
  496. package/dist/modes/interactive/components/footer.js.map +1 -1
  497. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  498. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  499. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  500. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  501. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  502. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
  503. package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
  504. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  505. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  506. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  507. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  508. package/dist/modes/interactive/components/oauth-selector.d.ts +8 -2
  509. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  510. package/dist/modes/interactive/components/oauth-selector.js +24 -21
  511. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  512. package/dist/modes/interactive/components/pi-logo-animation.d.ts +68 -0
  513. package/dist/modes/interactive/components/pi-logo-animation.d.ts.map +1 -0
  514. package/dist/modes/interactive/components/pi-logo-animation.js +1086 -0
  515. package/dist/modes/interactive/components/pi-logo-animation.js.map +1 -0
  516. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts +7 -0
  517. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts.map +1 -0
  518. package/dist/modes/interactive/components/pi-logo-animation.lazy.js +12 -0
  519. package/dist/modes/interactive/components/pi-logo-animation.lazy.js.map +1 -0
  520. package/dist/modes/interactive/components/pi-logo.d.ts +19 -0
  521. package/dist/modes/interactive/components/pi-logo.d.ts.map +1 -0
  522. package/dist/modes/interactive/components/pi-logo.js +37 -0
  523. package/dist/modes/interactive/components/pi-logo.js.map +1 -0
  524. package/dist/modes/interactive/components/radius-login-selector.d.ts +15 -0
  525. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -0
  526. package/dist/modes/interactive/components/radius-login-selector.js +85 -0
  527. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -0
  528. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  529. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  530. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  531. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  532. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  533. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  534. package/dist/modes/interactive/components/settings-selector.d.ts +6 -4
  535. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  536. package/dist/modes/interactive/components/settings-selector.js +33 -11
  537. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  538. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  539. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  540. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  541. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  542. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  543. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  544. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  545. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  546. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  547. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  548. package/dist/modes/interactive/components/themed-text.d.ts +17 -0
  549. package/dist/modes/interactive/components/themed-text.d.ts.map +1 -0
  550. package/dist/modes/interactive/components/themed-text.js +29 -0
  551. package/dist/modes/interactive/components/themed-text.js.map +1 -0
  552. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  553. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  554. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  555. package/dist/modes/interactive/components/tool-execution.js +2 -2
  556. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  557. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  558. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  559. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  560. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  561. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  562. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  563. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  564. package/dist/modes/interactive/components/user-message.js +5 -4
  565. package/dist/modes/interactive/components/user-message.js.map +1 -1
  566. package/dist/modes/interactive/components/visual-truncate.d.ts +27 -3
  567. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  568. package/dist/modes/interactive/components/visual-truncate.js +39 -6
  569. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  570. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  571. package/dist/modes/interactive/external-editor.js.map +1 -1
  572. package/dist/modes/interactive/interactive-mode.d.ts +21 -0
  573. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  574. package/dist/modes/interactive/interactive-mode.js +348 -197
  575. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  576. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -1
  577. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -1
  578. package/dist/modes/interactive/model-search.d.ts.map +1 -1
  579. package/dist/modes/interactive/model-search.js.map +1 -1
  580. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  581. package/dist/modes/interactive/session-share.js.map +1 -1
  582. package/dist/modes/interactive/theme/dark.json +59 -72
  583. package/dist/modes/interactive/theme/light.json +57 -69
  584. package/dist/modes/interactive/theme/system-theme.d.ts +55 -0
  585. package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
  586. package/dist/modes/interactive/theme/system-theme.js +546 -0
  587. package/dist/modes/interactive/theme/system-theme.js.map +1 -0
  588. package/dist/modes/interactive/theme/theme-controller.d.ts +46 -6
  589. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  590. package/dist/modes/interactive/theme/theme-controller.js +127 -47
  591. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  592. package/dist/modes/interactive/theme/theme-json.d.ts +1 -0
  593. package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -1
  594. package/dist/modes/interactive/theme/theme-json.js +3 -1
  595. package/dist/modes/interactive/theme/theme-json.js.map +1 -1
  596. package/dist/modes/interactive/theme/theme-schema.json +7 -2
  597. package/dist/modes/interactive/theme/theme.d.ts +66 -39
  598. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  599. package/dist/modes/interactive/theme/theme.js +238 -317
  600. package/dist/modes/interactive/theme/theme.js.map +1 -1
  601. package/dist/modes/interactive/tui-renderer.d.ts +2 -1
  602. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
  603. package/dist/modes/interactive/tui-renderer.js +1 -0
  604. package/dist/modes/interactive/tui-renderer.js.map +1 -1
  605. package/dist/modes/json-event.d.ts.map +1 -1
  606. package/dist/modes/json-event.js.map +1 -1
  607. package/dist/modes/print-mode.d.ts.map +1 -1
  608. package/dist/modes/print-mode.js.map +1 -1
  609. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  610. package/dist/modes/rpc/jsonl.js.map +1 -1
  611. package/dist/modes/rpc/rpc-client.d.ts +6 -6
  612. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  613. package/dist/modes/rpc/rpc-client.js +12 -8
  614. package/dist/modes/rpc/rpc-client.js.map +1 -1
  615. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  616. package/dist/modes/rpc/rpc-mode.js +7 -9
  617. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  618. package/dist/modes/rpc/rpc-types.d.ts +10 -1
  619. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  620. package/dist/modes/rpc/rpc-types.js.map +1 -1
  621. package/dist/package-manager-cli.d.ts.map +1 -1
  622. package/dist/package-manager-cli.js +6 -2
  623. package/dist/package-manager-cli.js.map +1 -1
  624. package/dist/pi-client-cli.d.ts.map +1 -1
  625. package/dist/pi-client-cli.js.map +1 -1
  626. package/dist/rpc-entry.d.ts.map +1 -1
  627. package/dist/rpc-entry.js.map +1 -1
  628. package/dist/utils/abort.d.ts.map +1 -1
  629. package/dist/utils/abort.js.map +1 -1
  630. package/dist/utils/ansi.d.ts.map +1 -1
  631. package/dist/utils/ansi.js.map +1 -1
  632. package/dist/utils/changelog.d.ts.map +1 -1
  633. package/dist/utils/changelog.js.map +1 -1
  634. package/dist/utils/child-process.d.ts.map +1 -1
  635. package/dist/utils/child-process.js.map +1 -1
  636. package/dist/utils/clipboard-command.d.ts.map +1 -1
  637. package/dist/utils/clipboard-command.js.map +1 -1
  638. package/dist/utils/clipboard-image.d.ts.map +1 -1
  639. package/dist/utils/clipboard-image.js +14 -17
  640. package/dist/utils/clipboard-image.js.map +1 -1
  641. package/dist/utils/clipboard.d.ts +2 -0
  642. package/dist/utils/clipboard.d.ts.map +1 -1
  643. package/dist/utils/clipboard.js +5 -0
  644. package/dist/utils/clipboard.js.map +1 -1
  645. package/dist/utils/deprecation.d.ts.map +1 -1
  646. package/dist/utils/deprecation.js.map +1 -1
  647. package/dist/utils/exif-orientation.d.ts.map +1 -1
  648. package/dist/utils/exif-orientation.js.map +1 -1
  649. package/dist/utils/frontmatter.d.ts.map +1 -1
  650. package/dist/utils/frontmatter.js.map +1 -1
  651. package/dist/utils/fs-watch.d.ts.map +1 -1
  652. package/dist/utils/fs-watch.js.map +1 -1
  653. package/dist/utils/git.d.ts.map +1 -1
  654. package/dist/utils/git.js.map +1 -1
  655. package/dist/utils/html.d.ts.map +1 -1
  656. package/dist/utils/html.js.map +1 -1
  657. package/dist/utils/image-convert.d.ts.map +1 -1
  658. package/dist/utils/image-convert.js.map +1 -1
  659. package/dist/utils/image-process.d.ts.map +1 -1
  660. package/dist/utils/image-process.js.map +1 -1
  661. package/dist/utils/image-resize-core.d.ts.map +1 -1
  662. package/dist/utils/image-resize-core.js.map +1 -1
  663. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  664. package/dist/utils/image-resize-worker.js.map +1 -1
  665. package/dist/utils/image-resize.d.ts.map +1 -1
  666. package/dist/utils/image-resize.js.map +1 -1
  667. package/dist/utils/json.d.ts.map +1 -1
  668. package/dist/utils/json.js.map +1 -1
  669. package/dist/utils/management-http.d.ts.map +1 -1
  670. package/dist/utils/management-http.js.map +1 -1
  671. package/dist/utils/mime.d.ts.map +1 -1
  672. package/dist/utils/mime.js.map +1 -1
  673. package/dist/utils/open-browser.d.ts.map +1 -1
  674. package/dist/utils/open-browser.js.map +1 -1
  675. package/dist/utils/paths.d.ts +3 -3
  676. package/dist/utils/paths.d.ts.map +1 -1
  677. package/dist/utils/paths.js +5 -4
  678. package/dist/utils/paths.js.map +1 -1
  679. package/dist/utils/photon.d.ts.map +1 -1
  680. package/dist/utils/photon.js.map +1 -1
  681. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  682. package/dist/utils/pi-user-agent.js.map +1 -1
  683. package/dist/utils/shell.d.ts +1 -3
  684. package/dist/utils/shell.d.ts.map +1 -1
  685. package/dist/utils/shell.js +3 -30
  686. package/dist/utils/shell.js.map +1 -1
  687. package/dist/utils/sleep.d.ts.map +1 -1
  688. package/dist/utils/sleep.js.map +1 -1
  689. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  690. package/dist/utils/syntax-highlight.js +2 -0
  691. package/dist/utils/syntax-highlight.js.map +1 -1
  692. package/dist/utils/text.d.ts.map +1 -1
  693. package/dist/utils/text.js.map +1 -1
  694. package/dist/utils/tool-result-images.d.ts.map +1 -1
  695. package/dist/utils/tool-result-images.js.map +1 -1
  696. package/dist/utils/tools-manager.d.ts.map +1 -1
  697. package/dist/utils/tools-manager.js.map +1 -1
  698. package/dist/utils/version-check.d.ts.map +1 -1
  699. package/dist/utils/version-check.js.map +1 -1
  700. package/dist/utils/windows-self-update.d.ts.map +1 -1
  701. package/dist/utils/windows-self-update.js.map +1 -1
  702. package/dist/utils/wsl.d.ts.map +1 -1
  703. package/dist/utils/wsl.js.map +1 -1
  704. package/dist/utils/zip.d.ts.map +1 -1
  705. package/dist/utils/zip.js.map +1 -1
  706. package/docs/cli.md +58 -7
  707. package/docs/codemode.md +207 -0
  708. package/docs/configuration.md +2 -0
  709. package/docs/custom-provider.md +43 -4
  710. package/docs/docs.json +13 -1
  711. package/docs/environment-variables.md +2 -2
  712. package/docs/extensions.md +55 -0
  713. package/docs/index.md +1 -1
  714. package/docs/keybindings.md +1 -1
  715. package/docs/llama-cpp.md +13 -0
  716. package/docs/mcp.md +248 -0
  717. package/docs/models.md +57 -1
  718. package/docs/packages.md +4 -2
  719. package/docs/providers.md +19 -6
  720. package/docs/rpc-commands.md +9 -3
  721. package/docs/rpc.md +3 -1
  722. package/docs/sdk.md +8 -3
  723. package/docs/security.md +2 -0
  724. package/docs/session-format.md +5 -1
  725. package/docs/settings.md +24 -5
  726. package/docs/themes.md +33 -7
  727. package/docs/tui.md +18 -0
  728. package/docs/usage.md +1 -1
  729. package/docs/virtual-models.md +114 -0
  730. package/docs/windows.md +2 -0
  731. package/examples/README.md +1 -1
  732. package/examples/extensions/README.md +2 -0
  733. package/examples/extensions/built-in-tool-renderer.ts +16 -40
  734. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  735. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  736. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  737. package/examples/extensions/custom-provider-gitlab-duo/test.ts +5 -5
  738. package/examples/extensions/debug-provider.ts +90 -0
  739. package/examples/extensions/gondolin/package-lock.json +2 -2
  740. package/examples/extensions/gondolin/package.json +1 -1
  741. package/examples/extensions/jev-router.ts +113 -0
  742. package/examples/extensions/minimal-mode.ts +24 -96
  743. package/examples/extensions/sandbox/package-lock.json +2 -2
  744. package/examples/extensions/sandbox/package.json +1 -1
  745. package/examples/extensions/with-deps/package-lock.json +2 -2
  746. package/examples/extensions/with-deps/package.json +1 -1
  747. package/examples/rpc-client.ts +1 -1
  748. package/examples/rpc-extension-ui.ts +1 -1
  749. package/examples/sdk/14-codemode-mcp.ts +61 -0
  750. package/examples/sdk/README.md +2 -1
  751. package/package.json +14 -12
  752. package/dist/bundle/chunks/anthropic-messages-J5WXPPPC.js +0 -6
  753. package/dist/bundle/chunks/azure-openai-responses-QJ7SPP5M.js +0 -2
  754. package/dist/bundle/chunks/chunk-6R7UI4IY.js +0 -2
  755. package/dist/bundle/chunks/chunk-BZKWNWMI.js +0 -2
  756. package/dist/bundle/chunks/chunk-NUHFSC37.js +0 -25
  757. package/dist/bundle/chunks/chunk-RCZIEVGO.js +0 -11
  758. package/dist/bundle/chunks/chunk-S7SZN6Z3.js +0 -2
  759. package/dist/bundle/chunks/chunk-X2F52Z34.js +0 -1685
  760. package/dist/bundle/chunks/chunk-XNGRGP62.js +0 -2
  761. package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +0 -2
  762. package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +0 -2
  763. package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +0 -5
  764. package/dist/bundle/chunks/openai-responses-AH7QTG23.js +0 -2
  765. package/dist/bundle/chunks/virtual-modules-WWGGM27U.js +0 -2
@@ -0,0 +1,268 @@
1
+ /**
2
+ * The `codemode` tool: the model writes JavaScript that calls other tools. Scripts use `tools`,
3
+ * `ALL_TOOLS`, `text()`, `image()`, `exit()`, `store()`/`load()`, `console.*`, and `return <value>`,
4
+ * may start with a `// @options:` line, and reach the model catalog, classifiers, and image models
5
+ * through `models.*`. Results start with a "Script completed" or "Script failed" header.
6
+ *
7
+ * Scripts can call the agent loop's nested tools: active `direct` tools and every `codemode` or
8
+ * `deferred` tool. Nested calls run through the agent loop's tool pipeline (`ctx.executeTool`), so
9
+ * validation, `tool_call`/`tool_result` hooks, and permission checks apply exactly as for direct
10
+ * calls. Only the script's output reaches the model; nested results do not.
11
+ *
12
+ * Nested results are handed to the script as follows:
13
+ * - A tool that declares `outputSchema` resolves to its `structuredContent`, also for error
14
+ * results that carry one (MCP tools resolve to their `CallToolResult`, including `isError`).
15
+ * - Any other tool resolves to its text content as one string.
16
+ * - A failed, blocked, or invalid call rejects with an Error carrying the tool's error text.
17
+ *
18
+ * A script that fails returns a normal error result that keeps its partial output, followed by
19
+ * "Script error:" and the error. `store(key, value)` and `load(key)` keep JSON values across
20
+ * calls; successful scripts append their writes to the session as `codemode-store` custom entries,
21
+ * so each branch sees the values written on its own path.
22
+ */
23
+ import { join } from "node:path";
24
+ import { MCP_TYPESCRIPT_PREAMBLE, mcpStructuredContentSchema, renderToolOutputType, renderToolSample, toCodemodeIdentifier, } from "@earendil-works/pi-codemode/declarations";
25
+ import { CODEMODE_SOURCE_GRAMMAR } from "@earendil-works/pi-codemode/source";
26
+ import { Type } from "typebox";
27
+ import { getDocsPath } from "../../config.js";
28
+ import { wrapToolDefinition } from "../../core/tools/tool-definition-wrapper.js";
29
+ import { loadCodemodeExecutor } from "./execute.lazy.js";
30
+ import { codemodeRenderers } from "./renderer.js";
31
+ export const CODEMODE_TOOL_NAME = "codemode";
32
+ /** Custom entry type holding one script's `store()` writes: {@link CodemodeStoreEntryData}. */
33
+ export const CODEMODE_STORE_ENTRY_TYPE = "codemode-store";
34
+ const TEXT_OUTPUT_SCHEMA = { type: "string" };
35
+ export const codemodeSchema = Type.Object({
36
+ code: Type.String({
37
+ description: "Raw JavaScript source.",
38
+ }),
39
+ });
40
+ /**
41
+ * Whether a registered tool is this package's `codemode` tool rather than another extension's tool
42
+ * with the same name. Compares the parameter schema, which the definition passes through by reference.
43
+ */
44
+ export function isCodemodeTool(tool) {
45
+ return tool.name === CODEMODE_TOOL_NAME && tool.parameters === codemodeSchema;
46
+ }
47
+ export const codemodeToolSystemPromptContribution = {
48
+ snippet: "Run JavaScript that calls other tools",
49
+ guidelines: [
50
+ "Use codemode to batch independent tool calls (Promise.allSettled), chain them, or filter large output, instead of many separate calls.",
51
+ ],
52
+ };
53
+ /** The reference for scripts: globals, tool results, `store()`, the `models` API, and limits. */
54
+ export const CODEMODE_DOCS_PATH = join(getDocsPath(), "codemode.md");
55
+ const DESCRIPTION_INTRO = `Run JavaScript that calls other tools. The input is raw JavaScript (not JSON, no code fence), run as an async function body in a QuickJS sandbox: top-level \`await\` and \`return\` work. No Node, file system, network, or timers.
56
+ - \`await tools.<name>({ ...args })\` resolves to a string, or an object if the tool's declaration says so, and rejects with an Error on failure. Calls still running when the script ends are cancelled.
57
+ - Optional first line: \`// @options: {"max_output_tokens": 10000, "timeout_ms": 60000}\``;
58
+ /** One line per global. The details live in {@link CODEMODE_DOCS_PATH}. */
59
+ function describeGlobals(models) {
60
+ const lines = [
61
+ "Globals:",
62
+ "- `text(value)`, `image(dataUrlOrImageBlock)`, `console.log(...)`, and top-level `return` add output; `exit()` ends the script.",
63
+ "- `store(key, value)` and `load(key)` keep JSON values across codemode calls.",
64
+ "- `ALL_TOOLS`, `searchTools(query, { limit?, namespace? })`, `describeTool(name)`, `describeNamespace(name)`: find unlisted tools, such as MCP tools.",
65
+ ];
66
+ if (models) {
67
+ lines.push(`- \`models\`: classifiers and image generation. Read ${CODEMODE_DOCS_PATH} first.`);
68
+ }
69
+ return lines.join("\n");
70
+ }
71
+ /** Default for {@link CodemodeDescriptionOptions.inlineBudget}, in estimated tokens. */
72
+ export const DEFAULT_CODEMODE_INLINE_BUDGET = 3000;
73
+ /** Characters per token when estimating the cost of a tool section. */
74
+ const CHARS_PER_TOKEN = 4;
75
+ /** What a script sees of a tool. Tools without an output schema resolve to their text output. */
76
+ export function toCodemodeDeclaration(tool) {
77
+ return {
78
+ name: tool.name,
79
+ description: tool.description,
80
+ inputSchema: tool.parameters,
81
+ outputSchema: tool.outputSchema ?? TEXT_OUTPUT_SCHEMA,
82
+ };
83
+ }
84
+ /** Tools a script may call: every given tool except the codemode tool itself. */
85
+ export function getCodemodeCallableTools(tools) {
86
+ return tools.filter((tool) => tool.name !== CODEMODE_TOOL_NAME);
87
+ }
88
+ /** `### \`id\` (\`raw name\`)` followed by the tool's description and declaration. */
89
+ function renderToolSection(declaration) {
90
+ const id = toCodemodeIdentifier(declaration.name);
91
+ const heading = id === declaration.name ? `### \`${id}\`` : `### \`${id}\` (\`${declaration.name}\`)`;
92
+ return `${heading}\n${renderToolSample(declaration).trim()}`;
93
+ }
94
+ /**
95
+ * Pick the tool sections that fit the budget, like OpenCode's catalog: in each round every group
96
+ * (tools without a namespace first, then namespaces by name) places its cheapest remaining tool; a
97
+ * group whose next tool does not fit drops out while the others continue. Every namespace is
98
+ * represented before any namespace is complete.
99
+ */
100
+ function selectCatalog(groups, budget) {
101
+ if (budget === undefined)
102
+ return new Set(groups.flatMap((group) => group.entries.map((entry) => entry.name)));
103
+ const queues = groups.map((group) => [...group.entries].sort((a, b) => a.cost - b.cost));
104
+ const shown = new Set();
105
+ let remaining = budget;
106
+ let active = queues.filter((queue) => queue.length > 0);
107
+ while (active.length > 0) {
108
+ active = active.filter((queue) => {
109
+ const next = queue[0];
110
+ if (next.cost > remaining)
111
+ return false;
112
+ remaining -= next.cost;
113
+ shown.add(next.name);
114
+ queue.shift();
115
+ return queue.length > 0;
116
+ });
117
+ }
118
+ return shown;
119
+ }
120
+ /**
121
+ * Model-facing description: the helper list, guidance for finding tools that are not listed, the
122
+ * shared MCP types when listed tools need them, the `models` API, and one section per listed tool,
123
+ * grouped by namespace. Deferred tools are never listed and do not affect the description at all, so
124
+ * it stays the same while MCP servers connect or change their tools. Tool sections are limited to
125
+ * `inlineBudget`.
126
+ */
127
+ export function createCodemodeDescription(tools, options = {}) {
128
+ const declarations = getCodemodeCallableTools(tools)
129
+ .filter((tool) => !options.deferred?.has(tool.name))
130
+ .map(toCodemodeDeclaration);
131
+ const groups = new Map([["", { namespace: undefined, entries: [] }]]);
132
+ for (const declaration of declarations) {
133
+ const namespace = options.namespaces?.get(declaration.name);
134
+ const key = namespace ? `ns:${namespace.name}` : "";
135
+ const group = groups.get(key) ?? { namespace, entries: [] };
136
+ groups.set(key, group);
137
+ const section = renderToolSection(declaration);
138
+ group.entries.push({ name: declaration.name, section, cost: Math.ceil(section.length / CHARS_PER_TOKEN) });
139
+ }
140
+ const ordered = [...groups.values()].sort((a, b) => a.namespace === undefined ? -1 : b.namespace === undefined ? 1 : a.namespace.name.localeCompare(b.namespace.name));
141
+ const shown = selectCatalog(ordered, options.inlineBudget);
142
+ const sections = [DESCRIPTION_INTRO, describeGlobals(options.models === true)];
143
+ if (declarations.some((declaration) => shown.has(declaration.name) && mcpStructuredContentSchema(declaration.outputSchema) !== undefined)) {
144
+ sections.push(`Shared MCP Types:\n\`\`\`ts\n${MCP_TYPESCRIPT_PREAMBLE}\n\`\`\``);
145
+ }
146
+ if (declarations.length === 0)
147
+ return sections.join("\n\n");
148
+ const toolSections = ["Nested tools:"];
149
+ for (const { namespace, entries } of ordered) {
150
+ const visible = entries.filter((entry) => shown.has(entry.name));
151
+ if (namespace) {
152
+ // Only tools that did not fit the budget are counted as not listed here.
153
+ const listing = visible.length === entries.length
154
+ ? ""
155
+ : visible.length === 0
156
+ ? " (tools not listed)"
157
+ : " (some tools not listed)";
158
+ const description = namespace.description?.trim();
159
+ toolSections.push(`## ${namespace.name}${listing}${description ? `\n${description}` : ""}`);
160
+ }
161
+ for (const entry of visible)
162
+ toolSections.push(entry.section);
163
+ }
164
+ sections.push(toolSections.join("\n\n"));
165
+ return sections.join("\n\n");
166
+ }
167
+ /**
168
+ * What a script call resolves to, in one line: `a string`, the field names of an object
169
+ * (`{ output, exit_code, full_output_path? }`), or the rendered type for anything else.
170
+ */
171
+ function describeOutput(schema) {
172
+ const type = renderToolOutputType(schema);
173
+ if (type === "string")
174
+ return "a string";
175
+ const object = typeof schema === "object" ? schema : undefined;
176
+ const properties = object?.properties;
177
+ if (object?.type === "object" &&
178
+ typeof properties === "object" &&
179
+ properties !== null &&
180
+ mcpStructuredContentSchema(schema) === undefined) {
181
+ const required = new Set(Array.isArray(object.required) ? object.required : []);
182
+ const fields = Object.keys(properties).map((name) => (required.has(name) ? name : `${name}?`));
183
+ return `\`{ ${fields.join(", ")} }\``;
184
+ }
185
+ return `\`${type.replace(/\s+/g, " ")}\``;
186
+ }
187
+ /**
188
+ * A declared tool's description followed by how scripts call it and what the call resolves to. The
189
+ * arguments are the tool's declared parameters, so they are not repeated.
190
+ */
191
+ function describeScriptCall(tool) {
192
+ return `${tool.description.trim()}\n\nCodemode: \`tools.${toCodemodeIdentifier(tool.name)}(args)\` resolves to ${describeOutput(toCodemodeDeclaration(tool).outputSchema)}.`;
193
+ }
194
+ /**
195
+ * How the codemode tool presents tools that are both declared and callable from scripts:
196
+ * - `on`: their descriptions say how scripts call them, and the codemode description
197
+ * lists only the callable tools without `direct` exposure.
198
+ * - `only`: the codemode description lists every callable tool, and requests leave out the
199
+ * declarations of active `direct` tools.
200
+ *
201
+ * Listing by exposure, not by the active set, keeps the codemode description unchanged when
202
+ * `tool_search` loads a tool, so loads do not redeclare codemode.
203
+ */
204
+ function prepareCodemodeLoadout(loadout, options) {
205
+ const mode = options.getMode?.() ?? "on";
206
+ const isDirect = (tool) => loadout.getExposure(tool.name) === "direct";
207
+ const callable = getCodemodeCallableTools(loadout.callable);
208
+ const callableNames = new Set(callable.map((tool) => tool.name));
209
+ const descriptions = {};
210
+ if (mode === "on") {
211
+ for (const tool of loadout.declared) {
212
+ if (callableNames.has(tool.name))
213
+ descriptions[tool.name] = describeScriptCall(tool);
214
+ }
215
+ }
216
+ const listed = mode === "only" ? callable : callable.filter((tool) => !isDirect(tool));
217
+ const namespaces = new Map(listed.flatMap((tool) => {
218
+ const namespace = loadout.getNamespace(tool.name);
219
+ return namespace ? [[tool.name, namespace]] : [];
220
+ }));
221
+ descriptions[CODEMODE_TOOL_NAME] = createCodemodeDescription(listed, {
222
+ models: options.models === true,
223
+ namespaces,
224
+ deferred: new Set(listed.filter((tool) => loadout.getExposure(tool.name) === "deferred").map((tool) => tool.name)),
225
+ inlineBudget: options.getInlineBudget?.() ?? DEFAULT_CODEMODE_INLINE_BUDGET,
226
+ });
227
+ const declaredNames = new Set(loadout.declared.map((tool) => tool.name));
228
+ return {
229
+ descriptions,
230
+ hiddenDeclarations: mode === "only"
231
+ ? callable.filter((tool) => isDirect(tool) && declaredNames.has(tool.name)).map((tool) => tool.name)
232
+ : [],
233
+ };
234
+ }
235
+ export function createCodemodeToolDefinition(options = {}) {
236
+ return {
237
+ name: CODEMODE_TOOL_NAME,
238
+ label: CODEMODE_TOOL_NAME,
239
+ // Replaced with the declarations of the callable tools when the tool is activated.
240
+ description: createCodemodeDescription([], { models: options.models === true }),
241
+ promptSnippet: codemodeToolSystemPromptContribution.snippet,
242
+ promptGuidelines: [...codemodeToolSystemPromptContribution.guidelines],
243
+ parameters: codemodeSchema,
244
+ // Scripts must not start other scripts.
245
+ exposure: "model-only",
246
+ prepareLoadout: (loadout) => prepareCodemodeLoadout(loadout, options),
247
+ // Capable models write the script as raw text instead of a JSON-escaped string.
248
+ constrainedSampling: { type: "grammar", variants: { openai_lark: CODEMODE_SOURCE_GRAMMAR } },
249
+ // The sandbox (worker, QuickJS wasm) loads on the first call, not at startup.
250
+ execute: async (toolCallId, params, signal, onUpdate, ctx) => (await loadCodemodeExecutor()).executeCodemode(toolCallId, params, signal, onUpdate, ctx, options),
251
+ ...codemodeRenderers,
252
+ };
253
+ }
254
+ /**
255
+ * Create the codemode tool as an AgentTool. The description lists the given tools; the script can
256
+ * call whatever tools the agent loop provides at execution time.
257
+ */
258
+ export function createCodemodeTool(tools = [], options = {}) {
259
+ const definition = createCodemodeToolDefinition(options);
260
+ const tool = wrapToolDefinition(definition);
261
+ Object.assign(tool, {
262
+ description: createCodemodeDescription(tools, { models: options.models === true }),
263
+ promptSnippet: definition.promptSnippet,
264
+ promptGuidelines: definition.promptGuidelines,
265
+ });
266
+ return tool;
267
+ }
268
+ //# sourceMappingURL=tool.js.map
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MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC;QACnG,GAAG,iBAAiB;KACpB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAK,GAA8B,EAAE,EACrC,OAAO,GAAwB,EAAE;IAEjC,MAAM,UAAU,GAAG,4BAA4B,CAAC,OAAO,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,WAAW,EAAE,yBAAyB,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAClF,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/**\n * The `codemode` tool: the model writes JavaScript that calls other tools. Scripts use `tools`,\n * `ALL_TOOLS`, `text()`, `image()`, `exit()`, `store()`/`load()`, `console.*`, and `return <value>`,\n * may start with a `// @options:` line, and reach the model catalog, classifiers, and image models\n * through `models.*`. Results start with a \"Script completed\" or \"Script failed\" header.\n *\n * Scripts can call the agent loop's nested tools: active `direct` tools and every `codemode` or\n * `deferred` tool. Nested calls run through the agent loop's tool pipeline (`ctx.executeTool`), so\n * validation, `tool_call`/`tool_result` hooks, and permission checks apply exactly as for direct\n * calls. Only the script's output reaches the model; nested results do not.\n *\n * Nested results are handed to the script as follows:\n * - A tool that declares `outputSchema` resolves to its `structuredContent`, also for error\n * results that carry one (MCP tools resolve to their `CallToolResult`, including `isError`).\n * - Any other tool resolves to its text content as one string.\n * - A failed, blocked, or invalid call rejects with an Error carrying the tool's error text.\n *\n * A script that fails returns a normal error result that keeps its partial output, followed by\n * \"Script error:\" and the error. `store(key, value)` and `load(key)` keep JSON values across\n * calls; successful scripts append their writes to the session as `codemode-store` custom entries,\n * so each branch sees the values written on its own path.\n */\n\nimport { join } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { CodemodeJsonSchema, CodemodeTool } from \"@earendil-works/pi-codemode\";\nimport {\n\tMCP_TYPESCRIPT_PREAMBLE,\n\tmcpStructuredContentSchema,\n\trenderToolOutputType,\n\trenderToolSample,\n\ttoCodemodeIdentifier,\n} from \"@earendil-works/pi-codemode/declarations\";\nimport { CODEMODE_SOURCE_GRAMMAR } from \"@earendil-works/pi-codemode/source\";\nimport { type Static, Type } from \"typebox\";\nimport { getDocsPath } from \"../../config.ts\";\nimport type {\n\tToolDefinition,\n\tToolInfo,\n\tToolLoadout,\n\tToolLoadoutChanges,\n\tToolNamespace,\n} from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport type { CodemodeMode } from \"../../core/settings-manager.ts\";\nimport { wrapToolDefinition } from \"../../core/tools/tool-definition-wrapper.ts\";\nimport { loadCodemodeExecutor } from \"./execute.lazy.ts\";\nimport { codemodeRenderers } from \"./renderer.ts\";\n\nexport const CODEMODE_TOOL_NAME = \"codemode\";\n\n/** Custom entry type holding one script's `store()` writes: {@link CodemodeStoreEntryData}. */\nexport const CODEMODE_STORE_ENTRY_TYPE = \"codemode-store\";\n\nexport interface CodemodeStoreEntryData {\n\tset: Record<string, unknown>;\n\tdelete: string[];\n}\n\n/** The part of the model registry that scripts reach through `models`. */\nexport type CodemodeModelRuntime = Pick<\n\tModelRegistry,\n\t\"getModelsOfType\" | \"getAvailableOfType\" | \"getModelOfType\" | \"classify\" | \"generateImages\"\n>;\n\nexport interface CodemodeToolOptions {\n\t/** Namespace of a tool, for `searchTools()` ranking and its `namespace` filter. */\n\tgetToolNamespace?: (toolName: string) => ToolNamespace | undefined;\n\t/**\n\t * Expose the `models` namespace to scripts, backed by the session's model registry\n\t * (`ctx.modelRegistry`). Without it, `models` is not declared.\n\t */\n\tmodels?: boolean;\n\t/**\n\t * Persists `store()` writes as a session custom entry. Without it, writes last only for the\n\t * current script; `load()` still reads entries already on the branch.\n\t */\n\tappendEntry?: (customType: string, data: CodemodeStoreEntryData) => void;\n\t/** How the tool presents the loadout while active (the `codemode.mode` setting). Default: `on`. */\n\tgetMode?: () => CodemodeMode;\n\t/** Token budget for tool declarations in the description. Default: {@link DEFAULT_CODEMODE_INLINE_BUDGET}. */\n\tgetInlineBudget?: () => number | undefined;\n}\n\nconst TEXT_OUTPUT_SCHEMA: CodemodeJsonSchema = { type: \"string\" };\n\nexport const codemodeSchema = Type.Object({\n\tcode: Type.String({\n\t\tdescription: \"Raw JavaScript source.\",\n\t}),\n});\n\nexport type CodemodeToolInput = Static<typeof codemodeSchema>;\n\n/**\n * Whether a registered tool is this package's `codemode` tool rather than another extension's tool\n * with the same name. Compares the parameter schema, which the definition passes through by reference.\n */\nexport function isCodemodeTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === CODEMODE_TOOL_NAME && tool.parameters === codemodeSchema;\n}\n\nexport type CodemodeNestedCallStatus = \"running\" | \"ok\" | \"error\" | \"cancelled\";\n\nexport interface CodemodeNestedCall {\n\t/** Tool call id of the nested call, `<codemode call id>/<n>`. */\n\tid: string;\n\tname: string;\n\t/** Compact JSON of the arguments, truncated for display. */\n\targs: string;\n\tstatus: CodemodeNestedCallStatus;\n\tdurationMs?: number;\n\t/** Error text, truncated for display. */\n\terror?: string;\n\t/** Cost in USD of a `models.*` call that reported usage. */\n\tcost?: number;\n}\n\nexport interface CodemodeToolDetails {\n\tcalls: CodemodeNestedCall[];\n\t/** Temp file with the full text output, when the output was truncated. */\n\tfullOutputPath?: string;\n}\n\nexport const codemodeToolSystemPromptContribution = {\n\tsnippet: \"Run JavaScript that calls other tools\",\n\tguidelines: [\n\t\t\"Use codemode to batch independent tool calls (Promise.allSettled), chain them, or filter large output, instead of many separate calls.\",\n\t],\n} as const;\n\n/** The reference for scripts: globals, tool results, `store()`, the `models` API, and limits. */\nexport const CODEMODE_DOCS_PATH = join(getDocsPath(), \"codemode.md\");\n\nconst DESCRIPTION_INTRO = `Run JavaScript that calls other tools. The input is raw JavaScript (not JSON, no code fence), run as an async function body in a QuickJS sandbox: top-level \\`await\\` and \\`return\\` work. No Node, file system, network, or timers.\n- \\`await tools.<name>({ ...args })\\` resolves to a string, or an object if the tool's declaration says so, and rejects with an Error on failure. Calls still running when the script ends are cancelled.\n- Optional first line: \\`// @options: {\"max_output_tokens\": 10000, \"timeout_ms\": 60000}\\``;\n\n/** One line per global. The details live in {@link CODEMODE_DOCS_PATH}. */\nfunction describeGlobals(models: boolean): string {\n\tconst lines = [\n\t\t\"Globals:\",\n\t\t\"- `text(value)`, `image(dataUrlOrImageBlock)`, `console.log(...)`, and top-level `return` add output; `exit()` ends the script.\",\n\t\t\"- `store(key, value)` and `load(key)` keep JSON values across codemode calls.\",\n\t\t\"- `ALL_TOOLS`, `searchTools(query, { limit?, namespace? })`, `describeTool(name)`, `describeNamespace(name)`: find unlisted tools, such as MCP tools.\",\n\t];\n\tif (models) {\n\t\tlines.push(`- \\`models\\`: classifiers and image generation. Read ${CODEMODE_DOCS_PATH} first.`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/** Default for {@link CodemodeDescriptionOptions.inlineBudget}, in estimated tokens. */\nexport const DEFAULT_CODEMODE_INLINE_BUDGET = 3000;\n/** Characters per token when estimating the cost of a tool section. */\nconst CHARS_PER_TOKEN = 4;\n\n/** What a script sees of a tool. Tools without an output schema resolve to their text output. */\nexport function toCodemodeDeclaration(tool: AgentTool<any>): Omit<CodemodeTool, \"execute\"> {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tinputSchema: tool.parameters as CodemodeJsonSchema,\n\t\toutputSchema: (tool.outputSchema as CodemodeJsonSchema | undefined) ?? TEXT_OUTPUT_SCHEMA,\n\t};\n}\n\n/** Tools a script may call: every given tool except the codemode tool itself. */\nexport function getCodemodeCallableTools(tools: readonly AgentTool<any>[]): AgentTool<any>[] {\n\treturn tools.filter((tool) => tool.name !== CODEMODE_TOOL_NAME);\n}\n\nexport interface CodemodeDescriptionOptions {\n\t/** Declare the `models` namespace; only for tools created with model access. */\n\tmodels?: boolean;\n\t/** Namespace of each tool, by tool name. Tools of one namespace are listed under one heading. */\n\tnamespaces?: ReadonlyMap<string, ToolNamespace>;\n\t/** Tools that are callable but never listed with their declaration (`deferred` exposure). */\n\tdeferred?: ReadonlySet<string>;\n\t/**\n\t * Estimated tokens (characters / 4) the tool sections may use. Tools that do not fit are left\n\t * out, like deferred tools. Unset lists every tool that is not deferred.\n\t */\n\tinlineBudget?: number;\n}\n\n/** `### \\`id\\` (\\`raw name\\`)` followed by the tool's description and declaration. */\nfunction renderToolSection(declaration: Omit<CodemodeTool, \"execute\">): string {\n\tconst id = toCodemodeIdentifier(declaration.name);\n\tconst heading = id === declaration.name ? `### \\`${id}\\`` : `### \\`${id}\\` (\\`${declaration.name}\\`)`;\n\treturn `${heading}\\n${renderToolSample(declaration).trim()}`;\n}\n\ninterface CatalogEntry {\n\tname: string;\n\tsection: string;\n\tcost: number;\n}\n\ninterface CatalogGroup {\n\tnamespace: ToolNamespace | undefined;\n\tentries: CatalogEntry[];\n}\n\n/**\n * Pick the tool sections that fit the budget, like OpenCode's catalog: in each round every group\n * (tools without a namespace first, then namespaces by name) places its cheapest remaining tool; a\n * group whose next tool does not fit drops out while the others continue. Every namespace is\n * represented before any namespace is complete.\n */\nfunction selectCatalog(groups: readonly CatalogGroup[], budget: number | undefined): Set<string> {\n\tif (budget === undefined) return new Set(groups.flatMap((group) => group.entries.map((entry) => entry.name)));\n\tconst queues = groups.map((group) => [...group.entries].sort((a, b) => a.cost - b.cost));\n\tconst shown = new Set<string>();\n\tlet remaining = budget;\n\tlet active = queues.filter((queue) => queue.length > 0);\n\twhile (active.length > 0) {\n\t\tactive = active.filter((queue) => {\n\t\t\tconst next = queue[0];\n\t\t\tif (next.cost > remaining) return false;\n\t\t\tremaining -= next.cost;\n\t\t\tshown.add(next.name);\n\t\t\tqueue.shift();\n\t\t\treturn queue.length > 0;\n\t\t});\n\t}\n\treturn shown;\n}\n\n/**\n * Model-facing description: the helper list, guidance for finding tools that are not listed, the\n * shared MCP types when listed tools need them, the `models` API, and one section per listed tool,\n * grouped by namespace. Deferred tools are never listed and do not affect the description at all, so\n * it stays the same while MCP servers connect or change their tools. Tool sections are limited to\n * `inlineBudget`.\n */\nexport function createCodemodeDescription(\n\ttools: readonly AgentTool<any>[],\n\toptions: CodemodeDescriptionOptions = {},\n): string {\n\tconst declarations = getCodemodeCallableTools(tools)\n\t\t.filter((tool) => !options.deferred?.has(tool.name))\n\t\t.map(toCodemodeDeclaration);\n\tconst groups = new Map<string, CatalogGroup>([[\"\", { namespace: undefined, entries: [] }]]);\n\tfor (const declaration of declarations) {\n\t\tconst namespace = options.namespaces?.get(declaration.name);\n\t\tconst key = namespace ? `ns:${namespace.name}` : \"\";\n\t\tconst group = groups.get(key) ?? { namespace, entries: [] };\n\t\tgroups.set(key, group);\n\t\tconst section = renderToolSection(declaration);\n\t\tgroup.entries.push({ name: declaration.name, section, cost: Math.ceil(section.length / CHARS_PER_TOKEN) });\n\t}\n\tconst ordered = [...groups.values()].sort((a, b) =>\n\t\ta.namespace === undefined ? -1 : b.namespace === undefined ? 1 : a.namespace.name.localeCompare(b.namespace.name),\n\t);\n\tconst shown = selectCatalog(ordered, options.inlineBudget);\n\n\tconst sections = [DESCRIPTION_INTRO, describeGlobals(options.models === true)];\n\tif (\n\t\tdeclarations.some(\n\t\t\t(declaration) =>\n\t\t\t\tshown.has(declaration.name) && mcpStructuredContentSchema(declaration.outputSchema) !== undefined,\n\t\t)\n\t) {\n\t\tsections.push(`Shared MCP Types:\\n\\`\\`\\`ts\\n${MCP_TYPESCRIPT_PREAMBLE}\\n\\`\\`\\``);\n\t}\n\tif (declarations.length === 0) return sections.join(\"\\n\\n\");\n\n\tconst toolSections = [\"Nested tools:\"];\n\tfor (const { namespace, entries } of ordered) {\n\t\tconst visible = entries.filter((entry) => shown.has(entry.name));\n\t\tif (namespace) {\n\t\t\t// Only tools that did not fit the budget are counted as not listed here.\n\t\t\tconst listing =\n\t\t\t\tvisible.length === entries.length\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: visible.length === 0\n\t\t\t\t\t\t? \" (tools not listed)\"\n\t\t\t\t\t\t: \" (some tools not listed)\";\n\t\t\tconst description = namespace.description?.trim();\n\t\t\ttoolSections.push(`## ${namespace.name}${listing}${description ? `\\n${description}` : \"\"}`);\n\t\t}\n\t\tfor (const entry of visible) toolSections.push(entry.section);\n\t}\n\tsections.push(toolSections.join(\"\\n\\n\"));\n\treturn sections.join(\"\\n\\n\");\n}\n\n/**\n * What a script call resolves to, in one line: `a string`, the field names of an object\n * (`{ output, exit_code, full_output_path? }`), or the rendered type for anything else.\n */\nfunction describeOutput(schema: CodemodeJsonSchema | undefined): string {\n\tconst type = renderToolOutputType(schema);\n\tif (type === \"string\") return \"a string\";\n\tconst object = typeof schema === \"object\" ? schema : undefined;\n\tconst properties = object?.properties;\n\tif (\n\t\tobject?.type === \"object\" &&\n\t\ttypeof properties === \"object\" &&\n\t\tproperties !== null &&\n\t\tmcpStructuredContentSchema(schema) === undefined\n\t) {\n\t\tconst required = new Set(Array.isArray(object.required) ? object.required : []);\n\t\tconst fields = Object.keys(properties).map((name) => (required.has(name) ? name : `${name}?`));\n\t\treturn `\\`{ ${fields.join(\", \")} }\\``;\n\t}\n\treturn `\\`${type.replace(/\\s+/g, \" \")}\\``;\n}\n\n/**\n * A declared tool's description followed by how scripts call it and what the call resolves to. The\n * arguments are the tool's declared parameters, so they are not repeated.\n */\nfunction describeScriptCall(tool: AgentTool<any>): string {\n\treturn `${tool.description.trim()}\\n\\nCodemode: \\`tools.${toCodemodeIdentifier(tool.name)}(args)\\` resolves to ${describeOutput(toCodemodeDeclaration(tool).outputSchema)}.`;\n}\n\n/**\n * How the codemode tool presents tools that are both declared and callable from scripts:\n * - `on`: their descriptions say how scripts call them, and the codemode description\n * lists only the callable tools without `direct` exposure.\n * - `only`: the codemode description lists every callable tool, and requests leave out the\n * declarations of active `direct` tools.\n *\n * Listing by exposure, not by the active set, keeps the codemode description unchanged when\n * `tool_search` loads a tool, so loads do not redeclare codemode.\n */\nfunction prepareCodemodeLoadout(loadout: ToolLoadout, options: CodemodeToolOptions): ToolLoadoutChanges {\n\tconst mode = options.getMode?.() ?? \"on\";\n\tconst isDirect = (tool: AgentTool) => loadout.getExposure(tool.name) === \"direct\";\n\tconst callable = getCodemodeCallableTools(loadout.callable);\n\tconst callableNames = new Set(callable.map((tool) => tool.name));\n\tconst descriptions: Record<string, string> = {};\n\tif (mode === \"on\") {\n\t\tfor (const tool of loadout.declared) {\n\t\t\tif (callableNames.has(tool.name)) descriptions[tool.name] = describeScriptCall(tool);\n\t\t}\n\t}\n\tconst listed = mode === \"only\" ? callable : callable.filter((tool) => !isDirect(tool));\n\tconst namespaces = new Map(\n\t\tlisted.flatMap((tool) => {\n\t\t\tconst namespace = loadout.getNamespace(tool.name);\n\t\t\treturn namespace ? [[tool.name, namespace] as const] : [];\n\t\t}),\n\t);\n\tdescriptions[CODEMODE_TOOL_NAME] = createCodemodeDescription(listed, {\n\t\tmodels: options.models === true,\n\t\tnamespaces,\n\t\tdeferred: new Set(\n\t\t\tlisted.filter((tool) => loadout.getExposure(tool.name) === \"deferred\").map((tool) => tool.name),\n\t\t),\n\t\tinlineBudget: options.getInlineBudget?.() ?? DEFAULT_CODEMODE_INLINE_BUDGET,\n\t});\n\tconst declaredNames = new Set(loadout.declared.map((tool) => tool.name));\n\treturn {\n\t\tdescriptions,\n\t\thiddenDeclarations:\n\t\t\tmode === \"only\"\n\t\t\t\t? callable.filter((tool) => isDirect(tool) && declaredNames.has(tool.name)).map((tool) => tool.name)\n\t\t\t\t: [],\n\t};\n}\n\nexport function createCodemodeToolDefinition(\n\toptions: CodemodeToolOptions = {},\n): ToolDefinition<typeof codemodeSchema, CodemodeToolDetails | undefined> {\n\treturn {\n\t\tname: CODEMODE_TOOL_NAME,\n\t\tlabel: CODEMODE_TOOL_NAME,\n\t\t// Replaced with the declarations of the callable tools when the tool is activated.\n\t\tdescription: createCodemodeDescription([], { models: options.models === true }),\n\t\tpromptSnippet: codemodeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...codemodeToolSystemPromptContribution.guidelines],\n\t\tparameters: codemodeSchema,\n\t\t// Scripts must not start other scripts.\n\t\texposure: \"model-only\",\n\t\tprepareLoadout: (loadout) => prepareCodemodeLoadout(loadout, options),\n\t\t// Capable models write the script as raw text instead of a JSON-escaped string.\n\t\tconstrainedSampling: { type: \"grammar\", variants: { openai_lark: CODEMODE_SOURCE_GRAMMAR } },\n\t\t// The sandbox (worker, QuickJS wasm) loads on the first call, not at startup.\n\t\texecute: async (toolCallId, params, signal, onUpdate, ctx) =>\n\t\t\t(await loadCodemodeExecutor()).executeCodemode(toolCallId, params, signal, onUpdate, ctx, options),\n\t\t...codemodeRenderers,\n\t};\n}\n\n/**\n * Create the codemode tool as an AgentTool. The description lists the given tools; the script can\n * call whatever tools the agent loop provides at execution time.\n */\nexport function createCodemodeTool(\n\ttools: readonly AgentTool<any>[] = [],\n\toptions: CodemodeToolOptions = {},\n): AgentTool<typeof codemodeSchema> {\n\tconst definition = createCodemodeToolDefinition(options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tdescription: createCodemodeDescription(tools, { models: options.models === true }),\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Worker entry for the codemode sandbox in bundled builds. The Node bundle and the Bun binary
3
+ * build this file as a separate entrypoint because pi-codemode's own worker file is not on disk
4
+ * there; `getCodemodeWorkerSpecifier()` in config.ts resolves it.
5
+ */
6
+ import "@earendil-works/pi-codemode/worker";
7
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/extensions/codemode/worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,oCAAoC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Worker entry for the codemode sandbox in bundled builds. The Node bundle and the Bun binary
3
+ * build this file as a separate entrypoint because pi-codemode's own worker file is not on disk
4
+ * there; `getCodemodeWorkerSpecifier()` in config.ts resolves it.
5
+ */
6
+ import "@earendil-works/pi-codemode/worker";
7
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/extensions/codemode/worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,oCAAoC,CAAC","sourcesContent":["/**\n * Worker entry for the codemode sandbox in bundled builds. The Node bundle and the Bun binary\n * build this file as a separate entrypoint because pi-codemode's own worker file is not on disk\n * there; `getCodemodeWorkerSpecifier()` in config.ts resolves it.\n */\nimport \"@earendil-works/pi-codemode/worker\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE,eAAO,MAAM,iBAAiB,EAAE,eAAe,EAAmE,CAAC","sourcesContent":["import type { InlineExtension } from \"../core/extensions/types.ts\";\nimport llamaExtension from \"./llama/index.ts\";\n\nexport const builtInExtensions: InlineExtension[] = [{ name: \"llama.cpp\", factory: llamaExtension, hidden: true }];\n"]}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAMnE,eAAO,MAAM,iBAAiB,EAAE,eAAe,EAO9C,CAAC"}
@@ -1,3 +1,13 @@
1
+ import codemodeExtension from "./codemode/index.js";
1
2
  import llamaExtension from "./llama/index.js";
2
- export const builtInExtensions = [{ name: "llama.cpp", factory: llamaExtension, hidden: true }];
3
+ import mcpExtension from "./mcp/index.js";
4
+ import toolSearchExtension from "./tool-search/index.js";
5
+ export const builtInExtensions = [
6
+ { name: "llama.cpp", factory: llamaExtension, builtin: true },
7
+ // Replaceable: an extension that registers `codemode`, `tool_search`, or `/mcp` (such as a third-party
8
+ // MCP extension) takes over instead of running alongside the built-in one.
9
+ { name: "codemode", factory: codemodeExtension, replaceable: true, builtin: true },
10
+ { name: "tool-search", factory: toolSearchExtension, replaceable: true, builtin: true },
11
+ { name: "mcp", factory: mcpExtension, replaceable: true, builtin: true },
12
+ ];
3
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,MAAM,iBAAiB,GAAsB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC","sourcesContent":["import type { InlineExtension } from \"../core/extensions/types.ts\";\nimport llamaExtension from \"./llama/index.ts\";\n\nexport const builtInExtensions: InlineExtension[] = [{ name: \"llama.cpp\", factory: llamaExtension, hidden: true }];\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,mBAAmB,MAAM,wBAAwB,CAAC;AAEzD,MAAM,CAAC,MAAM,iBAAiB,GAAsB;IACnD,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE;IAC7D,uGAAuG;IACvG,2EAA2E;IAC3E,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IAClF,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IACvF,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;CACxE,CAAC","sourcesContent":["import type { InlineExtension } from \"../core/extensions/types.ts\";\nimport codemodeExtension from \"./codemode/index.ts\";\nimport llamaExtension from \"./llama/index.ts\";\nimport mcpExtension from \"./mcp/index.ts\";\nimport toolSearchExtension from \"./tool-search/index.ts\";\n\nexport const builtInExtensions: InlineExtension[] = [\n\t{ name: \"llama.cpp\", factory: llamaExtension, builtin: true },\n\t// Replaceable: an extension that registers `codemode`, `tool_search`, or `/mcp` (such as a third-party\n\t// MCP extension) takes over instead of running alongside the built-in one.\n\t{ name: \"codemode\", factory: codemodeExtension, replaceable: true, builtin: true },\n\t{ name: \"tool-search\", factory: toolSearchExtension, replaceable: true, builtin: true },\n\t{ name: \"mcp\", factory: mcpExtension, replaceable: true, builtin: true },\n];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/client.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,UAAU,CAAC;AAE9F,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE;QACP,KAAK,EAAE,gBAAgB,CAAC;QACxB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,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,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,cAAc,EAAE,CAAC,CAuC3B;CACD","sourcesContent":["export type LlamaModelStatus = \"unloaded\" | \"loading\" | \"loaded\" | \"downloading\" | \"sleeping\";\n\nexport interface LlamaModelInfo {\n\tid: string;\n\taliases?: string[];\n\tstatus: {\n\t\tvalue: LlamaModelStatus;\n\t\targs?: string[];\n\t\tfailed?: boolean;\n\t\texit_code?: number;\n\t\tprogress?: Record<string, { done: number; total: number }>;\n\t};\n\tarchitecture?: {\n\t\tinput_modalities?: string[];\n\t\toutput_modalities?: string[];\n\t};\n\tsource?: string;\n\tmeta?: {\n\t\tn_ctx?: number;\n\t\tn_ctx_train?: number;\n\t\tsize?: number;\n\t\tftype?: string;\n\t};\n}\n\nexport interface LlamaModelsResponse {\n\tdata: LlamaModelInfo[];\n\tobject?: string;\n}\n\nexport interface LlamaServerProps {\n\tmodels_autoload?: boolean;\n\tchat_template?: string;\n}\n\nexport interface LlamaModelEvent {\n\tmodel: string;\n\tevent: string;\n\tdata?: unknown;\n}\n\nexport interface LlamaProgress {\n\tmessage: string;\n\tratio?: number;\n\tdetail?: string;\n}\n\nfunction errorMessage(payload: unknown, fallback: string): string {\n\tif (typeof payload !== \"object\" || payload === null) return fallback;\n\tconst error = (payload as { error?: unknown }).error;\n\tif (typeof error !== \"object\" || error === null) return fallback;\n\tconst message = (error as { message?: unknown }).message;\n\treturn typeof message === \"string\" && message ? message : fallback;\n}\n\nfunction isModelInfo(value: unknown): value is LlamaModelInfo {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst candidate = value as { id?: unknown; status?: { value?: unknown } };\n\treturn typeof candidate.id === \"string\" && typeof candidate.status?.value === \"string\";\n}\n\nfunction linkSignal(source: AbortSignal | undefined, target: AbortController): () => void {\n\tif (!source) return () => {};\n\tif (source.aborted) {\n\t\ttarget.abort(source.reason);\n\t\treturn () => {};\n\t}\n\tconst abort = () => target.abort(source.reason);\n\tsource.addEventListener(\"abort\", abort, { once: true });\n\treturn () => source.removeEventListener(\"abort\", abort);\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(signal.reason ?? new Error(\"Cancelled\"));\n\t\t\treturn;\n\t\t}\n\t\tconst abort = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(signal?.reason ?? new Error(\"Cancelled\"));\n\t\t};\n\t\tconst timeout = setTimeout(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t});\n}\n\nfunction parseLoadProgress(data: unknown): LlamaProgress | undefined {\n\tif (typeof data !== \"object\" || data === null) return undefined;\n\tconst progress = (data as { progress?: unknown }).progress;\n\tif (typeof progress !== \"object\" || progress === null) return undefined;\n\tconst value = progress as { stages?: unknown; current?: unknown; stage?: unknown; value?: unknown };\n\tconst stage =\n\t\ttypeof value.current === \"string\" ? value.current : typeof value.stage === \"string\" ? value.stage : undefined;\n\tconst stages = Array.isArray(value.stages)\n\t\t? value.stages.filter((entry): entry is string => typeof entry === \"string\")\n\t\t: [];\n\tconst stageRatio = typeof value.value === \"number\" ? Math.max(0, Math.min(1, value.value)) : undefined;\n\tlet ratio = stageRatio;\n\tif (stage && stages.length > 0) {\n\t\tconst index = stages.indexOf(stage);\n\t\tif (index >= 0) ratio = (index + (stageRatio ?? 0)) / stages.length;\n\t}\n\treturn {\n\t\tmessage: stage ? `Loading ${stage.replaceAll(\"_\", \" \")}` : \"Loading model\",\n\t\tratio,\n\t};\n}\n\nfunction parseDownloadProgress(data: unknown): LlamaProgress | undefined {\n\tif (typeof data !== \"object\" || data === null) return undefined;\n\tconst nested = (data as { progress?: unknown }).progress;\n\tconst files = typeof nested === \"object\" && nested !== null ? nested : data;\n\tlet done = 0;\n\tlet total = 0;\n\tfor (const value of Object.values(files as Record<string, unknown>)) {\n\t\tif (typeof value !== \"object\" || value === null) continue;\n\t\tconst entry = value as { done?: unknown; total?: unknown };\n\t\tif (typeof entry.done !== \"number\" || typeof entry.total !== \"number\") continue;\n\t\tdone += entry.done;\n\t\ttotal += entry.total;\n\t}\n\tif (total <= 0) return undefined;\n\treturn {\n\t\tmessage: \"Downloading model\",\n\t\tratio: done / total,\n\t\tdetail: `${formatBytes(done)} / ${formatBytes(total)}`,\n\t};\n}\n\nexport function formatBytes(bytes: number): string {\n\tif (bytes < 1024) return `${bytes} B`;\n\tconst units = [\"KiB\", \"MiB\", \"GiB\", \"TiB\"];\n\tlet value = bytes / 1024;\n\tlet unit = units[0]!;\n\tfor (let index = 1; index < units.length && value >= 1024; index++) {\n\t\tvalue /= 1024;\n\t\tunit = units[index]!;\n\t}\n\treturn `${value >= 10 ? value.toFixed(1) : value.toFixed(2)} ${unit}`;\n}\n\nexport function normalizeLlamaServerUrl(value: string): string {\n\tconst url = new URL(value.trim());\n\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n\t\tthrow new Error(\"Server URL must use http or https\");\n\t}\n\turl.hash = \"\";\n\turl.search = \"\";\n\turl.pathname = url.pathname.replace(/\\/+$/u, \"\").replace(/\\/v1$/u, \"\") || \"/\";\n\treturn url.toString().replace(/\\/$/u, \"\");\n}\n\nexport function llamaInferenceUrl(serverUrl: string): string {\n\treturn `${normalizeLlamaServerUrl(serverUrl)}/v1`;\n}\n\nexport class LlamaClient {\n\treadonly serverUrl: string;\n\tprivate readonly apiKey: string | undefined;\n\n\tconstructor(serverUrl: string, apiKey?: string) {\n\t\tthis.serverUrl = normalizeLlamaServerUrl(serverUrl);\n\t\tthis.apiKey = apiKey;\n\t}\n\n\tprivate async request(path: string, init: RequestInit = {}): Promise<unknown> {\n\t\tconst headers = new Headers(init.headers);\n\t\tif (init.body !== undefined) headers.set(\"Content-Type\", \"application/json\");\n\t\tif (this.apiKey) headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\t\tconst timeout = AbortSignal.timeout(15_000);\n\t\tconst signal = init.signal ? AbortSignal.any([init.signal, timeout]) : timeout;\n\t\tconst response = await fetch(`${this.serverUrl}${path}`, { ...init, headers, signal });\n\t\tlet payload: unknown;\n\t\ttry {\n\t\t\tpayload = await response.json();\n\t\t} catch {\n\t\t\tpayload = undefined;\n\t\t}\n\t\tif (!response.ok) throw new Error(errorMessage(payload, `llama.cpp returned HTTP ${response.status}`));\n\t\treturn payload;\n\t}\n\n\tasync list(options: { reload?: boolean; signal?: AbortSignal } = {}): Promise<LlamaModelInfo[]> {\n\t\tconst payload = await this.request(`/models${options.reload ? \"?reload=1\" : \"\"}`, { signal: options.signal });\n\t\tif (typeof payload !== \"object\" || payload === null || !Array.isArray((payload as { data?: unknown }).data)) {\n\t\t\tthrow new Error(\"llama.cpp returned an invalid model catalog\");\n\t\t}\n\t\tconst data = (payload as { data: unknown[] }).data;\n\t\tif (!data.every(isModelInfo)) throw new Error(\"Server is not running in llama.cpp router mode\");\n\t\treturn data;\n\t}\n\n\tasync props(options: { model?: string; signal?: AbortSignal } = {}): Promise<LlamaServerProps> {\n\t\tconst query = options.model ? `?${new URLSearchParams({ model: options.model, autoload: \"false\" })}` : \"\";\n\t\tconst payload = await this.request(`/props${query}`, { signal: options.signal });\n\t\tif (typeof payload !== \"object\" || payload === null) return {};\n\t\tconst { models_autoload: modelsAutoload, chat_template: chatTemplate } = payload as Record<string, unknown>;\n\t\treturn {\n\t\t\t...(typeof modelsAutoload === \"boolean\" ? { models_autoload: modelsAutoload } : {}),\n\t\t\t...(typeof chatTemplate === \"string\" ? { chat_template: chatTemplate } : {}),\n\t\t};\n\t}\n\n\tasync load(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models/load\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync unload(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models/unload\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync unloadAndWait(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.unload(model, signal);\n\t\twhile (true) {\n\t\t\tconst entry = (await this.list({ signal })).find((candidate) => candidate.id === model);\n\t\t\tif (!entry || entry.status.value === \"unloaded\") return;\n\t\t\tawait sleep(100, signal);\n\t\t}\n\t}\n\n\tasync download(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync watch(onEvent: (event: LlamaModelEvent) => void, signal?: AbortSignal): Promise<void> {\n\t\tconst headers = new Headers();\n\t\tif (this.apiKey) headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\t\tconst response = await fetch(`${this.serverUrl}/models/sse`, { headers, signal });\n\t\tif (!response.ok || !response.body) throw new Error(`llama.cpp SSE returned HTTP ${response.status}`);\n\t\tconst reader = response.body.getReader();\n\t\tconst decoder = new TextDecoder();\n\t\tlet buffer = \"\";\n\t\twhile (true) {\n\t\t\tconst chunk = await reader.read();\n\t\t\tif (chunk.done) break;\n\t\t\tbuffer += decoder.decode(chunk.value, { stream: true }).replaceAll(\"\\r\\n\", \"\\n\");\n\t\t\tlet boundary = buffer.indexOf(\"\\n\\n\");\n\t\t\twhile (boundary >= 0) {\n\t\t\t\tconst frame = buffer.slice(0, boundary);\n\t\t\t\tbuffer = buffer.slice(boundary + 2);\n\t\t\t\tconst data = frame\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.filter((line) => line.startsWith(\"data:\"))\n\t\t\t\t\t.map((line) => line.slice(5).trimStart())\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tif (data) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst event = JSON.parse(data) as LlamaModelEvent;\n\t\t\t\t\t\tif (event && typeof event.model === \"string\" && typeof event.event === \"string\") onEvent(event);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore malformed events; catalog polling remains authoritative.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tboundary = buffer.indexOf(\"\\n\\n\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync loadAndWait(\n\t\tmodel: string,\n\t\tonProgress: (progress: LlamaProgress) => void,\n\t\tsignal?: AbortSignal,\n\t): Promise<LlamaModelInfo> {\n\t\tconst watcher = new AbortController();\n\t\tconst unlink = linkSignal(signal, watcher);\n\t\tlet eventLoaded = false;\n\t\tlet eventError: string | undefined;\n\t\tvoid this.watch((event) => {\n\t\t\tif (event.model !== model) return;\n\t\t\tif (event.event !== \"model_status\" && event.event !== \"status_change\") return;\n\t\t\tconst data = event.data as { status?: unknown } | undefined;\n\t\t\tif (data?.status === \"loaded\") eventLoaded = true;\n\t\t\tif (data?.status === \"unloaded\") eventError = \"Model failed to load\";\n\t\t\tconst progress = parseLoadProgress(event.data);\n\t\t\tif (progress) onProgress(progress);\n\t\t}, watcher.signal).catch(() => {});\n\t\ttry {\n\t\t\tawait this.load(model, signal);\n\t\t\tonProgress({ message: \"Loading model\" });\n\t\t\twhile (true) {\n\t\t\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Cancelled\");\n\t\t\t\tconst entry = (await this.list({ signal })).find((candidate) => candidate.id === model);\n\t\t\t\tif (entry?.status.value === \"loaded\") return entry;\n\t\t\t\tif (eventLoaded && !entry) return { id: model, status: { value: \"loaded\" } };\n\t\t\t\tif (entry?.status.failed || eventError) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tentry?.status.exit_code === undefined\n\t\t\t\t\t\t\t? (eventError ?? \"Model failed to load\")\n\t\t\t\t\t\t\t: `Model exited with code ${entry.status.exit_code}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait sleep(250, signal);\n\t\t\t}\n\t\t} finally {\n\t\t\tunlink();\n\t\t\twatcher.abort();\n\t\t}\n\t}\n\n\tasync downloadAndWait(\n\t\tmodel: string,\n\t\tonProgress: (progress: LlamaProgress) => void,\n\t\tsignal?: AbortSignal,\n\t): Promise<LlamaModelInfo[]> {\n\t\tconst watcher = new AbortController();\n\t\tconst unlink = linkSignal(signal, watcher);\n\t\tlet finished = false;\n\t\tlet failure: string | undefined;\n\t\tlet sawDownloading = false;\n\t\tlet polls = 0;\n\t\tvoid this.watch((event) => {\n\t\t\tif (event.model !== model) return;\n\t\t\tif (event.event === \"download_finished\") finished = true;\n\t\t\tif (event.event === \"download_failed\") failure = errorMessage(event.data, \"Download failed\");\n\t\t\tif (event.event === \"download_progress\") {\n\t\t\t\tsawDownloading = true;\n\t\t\t\tconst progress = parseDownloadProgress(event.data);\n\t\t\t\tif (progress) onProgress(progress);\n\t\t\t}\n\t\t}, watcher.signal).catch(() => {});\n\t\ttry {\n\t\t\tawait this.download(model, signal);\n\t\t\tonProgress({ message: \"Downloading model\" });\n\t\t\twhile (true) {\n\t\t\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Cancelled\");\n\t\t\t\tif (failure) throw new Error(failure);\n\t\t\t\tconst models = await this.list({ signal });\n\t\t\t\tpolls++;\n\t\t\t\tconst entry = models.find((candidate) => candidate.id === model);\n\t\t\t\tif (entry?.status.value === \"downloading\") {\n\t\t\t\t\tsawDownloading = true;\n\t\t\t\t\tconst progress = parseDownloadProgress(entry.status.progress);\n\t\t\t\t\tif (progress) onProgress(progress);\n\t\t\t\t} else if (finished || (entry && (sawDownloading || polls >= 2))) {\n\t\t\t\t\treturn this.list({ reload: true, signal });\n\t\t\t\t}\n\t\t\t\tawait sleep(500, signal);\n\t\t\t}\n\t\t} finally {\n\t\t\tunlink();\n\t\t\twatcher.abort();\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/client.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,UAAU,CAAC;AAE9F,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,EAAE,CA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,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;oBAClE,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC5C,CAAC;gBACD,MAAM,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC1B,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,MAAM,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;IAAA,CACD;CACD","sourcesContent":["export type LlamaModelStatus = \"unloaded\" | \"loading\" | \"loaded\" | \"downloading\" | \"sleeping\";\n\nexport interface LlamaModelInfo {\n\tid: string;\n\taliases?: string[];\n\tstatus: {\n\t\tvalue: LlamaModelStatus;\n\t\targs?: string[];\n\t\tfailed?: boolean;\n\t\texit_code?: number;\n\t\tprogress?: Record<string, { done: number; total: number }>;\n\t};\n\tarchitecture?: {\n\t\tinput_modalities?: string[];\n\t\toutput_modalities?: string[];\n\t};\n\tsource?: string;\n\tmeta?: {\n\t\tn_ctx?: number;\n\t\tn_ctx_train?: number;\n\t\tsize?: number;\n\t\tftype?: string;\n\t};\n}\n\nexport interface LlamaModelsResponse {\n\tdata: LlamaModelInfo[];\n\tobject?: string;\n}\n\nexport interface LlamaServerProps {\n\tmodels_autoload?: boolean;\n\tchat_template?: string;\n}\n\nexport interface LlamaModelEvent {\n\tmodel: string;\n\tevent: string;\n\tdata?: unknown;\n}\n\nexport interface LlamaProgress {\n\tmessage: string;\n\tratio?: number;\n\tdetail?: string;\n}\n\nfunction errorMessage(payload: unknown, fallback: string): string {\n\tif (typeof payload !== \"object\" || payload === null) return fallback;\n\tconst error = (payload as { error?: unknown }).error;\n\tif (typeof error !== \"object\" || error === null) return fallback;\n\tconst message = (error as { message?: unknown }).message;\n\treturn typeof message === \"string\" && message ? message : fallback;\n}\n\nfunction isModelInfo(value: unknown): value is LlamaModelInfo {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst candidate = value as { id?: unknown; status?: { value?: unknown } };\n\treturn typeof candidate.id === \"string\" && typeof candidate.status?.value === \"string\";\n}\n\nfunction linkSignal(source: AbortSignal | undefined, target: AbortController): () => void {\n\tif (!source) return () => {};\n\tif (source.aborted) {\n\t\ttarget.abort(source.reason);\n\t\treturn () => {};\n\t}\n\tconst abort = () => target.abort(source.reason);\n\tsource.addEventListener(\"abort\", abort, { once: true });\n\treturn () => source.removeEventListener(\"abort\", abort);\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(signal.reason ?? new Error(\"Cancelled\"));\n\t\t\treturn;\n\t\t}\n\t\tconst abort = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(signal?.reason ?? new Error(\"Cancelled\"));\n\t\t};\n\t\tconst timeout = setTimeout(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t});\n}\n\nfunction parseLoadProgress(data: unknown): LlamaProgress | undefined {\n\tif (typeof data !== \"object\" || data === null) return undefined;\n\tconst progress = (data as { progress?: unknown }).progress;\n\tif (typeof progress !== \"object\" || progress === null) return undefined;\n\tconst value = progress as { stages?: unknown; current?: unknown; stage?: unknown; value?: unknown };\n\tconst stage =\n\t\ttypeof value.current === \"string\" ? value.current : typeof value.stage === \"string\" ? value.stage : undefined;\n\tconst stages = Array.isArray(value.stages)\n\t\t? value.stages.filter((entry): entry is string => typeof entry === \"string\")\n\t\t: [];\n\tconst stageRatio = typeof value.value === \"number\" ? Math.max(0, Math.min(1, value.value)) : undefined;\n\tlet ratio = stageRatio;\n\tif (stage && stages.length > 0) {\n\t\tconst index = stages.indexOf(stage);\n\t\tif (index >= 0) ratio = (index + (stageRatio ?? 0)) / stages.length;\n\t}\n\treturn {\n\t\tmessage: stage ? `Loading ${stage.replaceAll(\"_\", \" \")}` : \"Loading model\",\n\t\tratio,\n\t};\n}\n\nfunction parseDownloadProgress(data: unknown): LlamaProgress | undefined {\n\tif (typeof data !== \"object\" || data === null) return undefined;\n\tconst nested = (data as { progress?: unknown }).progress;\n\tconst files = typeof nested === \"object\" && nested !== null ? nested : data;\n\tlet done = 0;\n\tlet total = 0;\n\tfor (const value of Object.values(files as Record<string, unknown>)) {\n\t\tif (typeof value !== \"object\" || value === null) continue;\n\t\tconst entry = value as { done?: unknown; total?: unknown };\n\t\tif (typeof entry.done !== \"number\" || typeof entry.total !== \"number\") continue;\n\t\tdone += entry.done;\n\t\ttotal += entry.total;\n\t}\n\tif (total <= 0) return undefined;\n\treturn {\n\t\tmessage: \"Downloading model\",\n\t\tratio: done / total,\n\t\tdetail: `${formatBytes(done)} / ${formatBytes(total)}`,\n\t};\n}\n\nexport function formatBytes(bytes: number): string {\n\tif (bytes < 1024) return `${bytes} B`;\n\tconst units = [\"KiB\", \"MiB\", \"GiB\", \"TiB\"];\n\tlet value = bytes / 1024;\n\tlet unit = units[0]!;\n\tfor (let index = 1; index < units.length && value >= 1024; index++) {\n\t\tvalue /= 1024;\n\t\tunit = units[index]!;\n\t}\n\treturn `${value >= 10 ? value.toFixed(1) : value.toFixed(2)} ${unit}`;\n}\n\nexport function normalizeLlamaServerUrl(value: string): string {\n\tconst url = new URL(value.trim());\n\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n\t\tthrow new Error(\"Server URL must use http or https\");\n\t}\n\turl.hash = \"\";\n\turl.search = \"\";\n\turl.pathname = url.pathname.replace(/\\/+$/u, \"\").replace(/\\/v1$/u, \"\") || \"/\";\n\treturn url.toString().replace(/\\/$/u, \"\");\n}\n\nexport function llamaInferenceUrl(serverUrl: string): string {\n\treturn `${normalizeLlamaServerUrl(serverUrl)}/v1`;\n}\n\nexport class LlamaClient {\n\treadonly serverUrl: string;\n\tprivate readonly apiKey: string | undefined;\n\n\tconstructor(serverUrl: string, apiKey?: string) {\n\t\tthis.serverUrl = normalizeLlamaServerUrl(serverUrl);\n\t\tthis.apiKey = apiKey;\n\t}\n\n\tprivate async request(path: string, init: RequestInit = {}): Promise<unknown> {\n\t\tconst headers = new Headers(init.headers);\n\t\tif (init.body !== undefined) headers.set(\"Content-Type\", \"application/json\");\n\t\tif (this.apiKey) headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\t\tconst timeout = AbortSignal.timeout(15_000);\n\t\tconst signal = init.signal ? AbortSignal.any([init.signal, timeout]) : timeout;\n\t\tconst response = await fetch(`${this.serverUrl}${path}`, { ...init, headers, signal });\n\t\tlet payload: unknown;\n\t\ttry {\n\t\t\tpayload = await response.json();\n\t\t} catch {\n\t\t\tpayload = undefined;\n\t\t}\n\t\tif (!response.ok) throw new Error(errorMessage(payload, `llama.cpp returned HTTP ${response.status}`));\n\t\treturn payload;\n\t}\n\n\tasync list(options: { reload?: boolean; signal?: AbortSignal } = {}): Promise<LlamaModelInfo[]> {\n\t\tconst payload = await this.request(`/models${options.reload ? \"?reload=1\" : \"\"}`, { signal: options.signal });\n\t\tif (typeof payload !== \"object\" || payload === null || !Array.isArray((payload as { data?: unknown }).data)) {\n\t\t\tthrow new Error(\"llama.cpp returned an invalid model catalog\");\n\t\t}\n\t\tconst data = (payload as { data: unknown[] }).data;\n\t\tif (!data.every(isModelInfo)) throw new Error(\"Server is not running in llama.cpp router mode\");\n\t\treturn data;\n\t}\n\n\tasync props(options: { model?: string; signal?: AbortSignal } = {}): Promise<LlamaServerProps> {\n\t\tconst query = options.model ? `?${new URLSearchParams({ model: options.model, autoload: \"false\" })}` : \"\";\n\t\tconst payload = await this.request(`/props${query}`, { signal: options.signal });\n\t\tif (typeof payload !== \"object\" || payload === null) return {};\n\t\tconst { models_autoload: modelsAutoload, chat_template: chatTemplate } = payload as Record<string, unknown>;\n\t\treturn {\n\t\t\t...(typeof modelsAutoload === \"boolean\" ? { models_autoload: modelsAutoload } : {}),\n\t\t\t...(typeof chatTemplate === \"string\" ? { chat_template: chatTemplate } : {}),\n\t\t};\n\t}\n\n\tasync load(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models/load\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync unload(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models/unload\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync unloadAndWait(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.unload(model, signal);\n\t\twhile (true) {\n\t\t\tconst entry = (await this.list({ signal })).find((candidate) => candidate.id === model);\n\t\t\tif (!entry || entry.status.value === \"unloaded\") return;\n\t\t\tawait sleep(100, signal);\n\t\t}\n\t}\n\n\tasync download(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync watch(onEvent: (event: LlamaModelEvent) => void, signal?: AbortSignal): Promise<void> {\n\t\tconst headers = new Headers();\n\t\tif (this.apiKey) headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\t\tconst response = await fetch(`${this.serverUrl}/models/sse`, { headers, signal });\n\t\tif (!response.ok || !response.body) throw new Error(`llama.cpp SSE returned HTTP ${response.status}`);\n\t\tconst reader = response.body.getReader();\n\t\tconst decoder = new TextDecoder();\n\t\tlet buffer = \"\";\n\t\twhile (true) {\n\t\t\tconst chunk = await reader.read();\n\t\t\tif (chunk.done) break;\n\t\t\tbuffer += decoder.decode(chunk.value, { stream: true }).replaceAll(\"\\r\\n\", \"\\n\");\n\t\t\tlet boundary = buffer.indexOf(\"\\n\\n\");\n\t\t\twhile (boundary >= 0) {\n\t\t\t\tconst frame = buffer.slice(0, boundary);\n\t\t\t\tbuffer = buffer.slice(boundary + 2);\n\t\t\t\tconst data = frame\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.filter((line) => line.startsWith(\"data:\"))\n\t\t\t\t\t.map((line) => line.slice(5).trimStart())\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tif (data) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst event = JSON.parse(data) as LlamaModelEvent;\n\t\t\t\t\t\tif (event && typeof event.model === \"string\" && typeof event.event === \"string\") onEvent(event);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore malformed events; catalog polling remains authoritative.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tboundary = buffer.indexOf(\"\\n\\n\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync loadAndWait(\n\t\tmodel: string,\n\t\tonProgress: (progress: LlamaProgress) => void,\n\t\tsignal?: AbortSignal,\n\t): Promise<LlamaModelInfo> {\n\t\tconst watcher = new AbortController();\n\t\tconst unlink = linkSignal(signal, watcher);\n\t\tlet eventLoaded = false;\n\t\tlet eventError: string | undefined;\n\t\tvoid this.watch((event) => {\n\t\t\tif (event.model !== model) return;\n\t\t\tif (event.event !== \"model_status\" && event.event !== \"status_change\") return;\n\t\t\tconst data = event.data as { status?: unknown } | undefined;\n\t\t\tif (data?.status === \"loaded\") eventLoaded = true;\n\t\t\tif (data?.status === \"unloaded\") eventError = \"Model failed to load\";\n\t\t\tconst progress = parseLoadProgress(event.data);\n\t\t\tif (progress) onProgress(progress);\n\t\t}, watcher.signal).catch(() => {});\n\t\ttry {\n\t\t\tawait this.load(model, signal);\n\t\t\tonProgress({ message: \"Loading model\" });\n\t\t\twhile (true) {\n\t\t\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Cancelled\");\n\t\t\t\tconst entry = (await this.list({ signal })).find((candidate) => candidate.id === model);\n\t\t\t\tif (entry?.status.value === \"loaded\") return entry;\n\t\t\t\tif (eventLoaded && !entry) return { id: model, status: { value: \"loaded\" } };\n\t\t\t\tif (entry?.status.failed || eventError) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tentry?.status.exit_code === undefined\n\t\t\t\t\t\t\t? (eventError ?? \"Model failed to load\")\n\t\t\t\t\t\t\t: `Model exited with code ${entry.status.exit_code}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait sleep(250, signal);\n\t\t\t}\n\t\t} finally {\n\t\t\tunlink();\n\t\t\twatcher.abort();\n\t\t}\n\t}\n\n\tasync downloadAndWait(\n\t\tmodel: string,\n\t\tonProgress: (progress: LlamaProgress) => void,\n\t\tsignal?: AbortSignal,\n\t): Promise<LlamaModelInfo[]> {\n\t\tconst watcher = new AbortController();\n\t\tconst unlink = linkSignal(signal, watcher);\n\t\tlet finished = false;\n\t\tlet failure: string | undefined;\n\t\tlet sawDownloading = false;\n\t\tlet polls = 0;\n\t\tvoid this.watch((event) => {\n\t\t\tif (event.model !== model) return;\n\t\t\tif (event.event === \"download_finished\") finished = true;\n\t\t\tif (event.event === \"download_failed\") failure = errorMessage(event.data, \"Download failed\");\n\t\t\tif (event.event === \"download_progress\") {\n\t\t\t\tsawDownloading = true;\n\t\t\t\tconst progress = parseDownloadProgress(event.data);\n\t\t\t\tif (progress) onProgress(progress);\n\t\t\t}\n\t\t}, watcher.signal).catch(() => {});\n\t\ttry {\n\t\t\tawait this.download(model, signal);\n\t\t\tonProgress({ message: \"Downloading model\" });\n\t\t\twhile (true) {\n\t\t\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Cancelled\");\n\t\t\t\tif (failure) throw new Error(failure);\n\t\t\t\tconst models = await this.list({ signal });\n\t\t\t\tpolls++;\n\t\t\t\tconst entry = models.find((candidate) => candidate.id === model);\n\t\t\t\tif (entry?.status.value === \"downloading\") {\n\t\t\t\t\tsawDownloading = true;\n\t\t\t\t\tconst progress = parseDownloadProgress(entry.status.progress);\n\t\t\t\t\tif (progress) onProgress(progress);\n\t\t\t\t} else if (finished || (entry && (sawDownloading || polls >= 2))) {\n\t\t\t\t\treturn this.list({ reload: true, signal });\n\t\t\t\t}\n\t\t\t\tawait sleep(500, signal);\n\t\t\t}\n\t\t} finally {\n\t\t\tunlink();\n\t\t\twatcher.abort();\n\t\t}\n\t}\n}\n"]}
1
+ {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tid: string;\n\taliases?: string[];\n\tstatus: {\n\t\tvalue: LlamaModelStatus;\n\t\targs?: string[];\n\t\tfailed?: boolean;\n\t\texit_code?: number;\n\t\tprogress?: Record<string, { done: number; total: number }>;\n\t};\n\tarchitecture?: {\n\t\tinput_modalities?: string[];\n\t\toutput_modalities?: string[];\n\t};\n\tsource?: string;\n\tmeta?: {\n\t\tn_ctx?: number;\n\t\tn_ctx_train?: number;\n\t\tsize?: number;\n\t\tftype?: string;\n\t};\n}\n\nexport interface LlamaModelsResponse {\n\tdata: LlamaModelInfo[];\n\tobject?: string;\n}\n\nexport interface LlamaServerProps {\n\tmodels_autoload?: boolean;\n\tchat_template?: string;\n}\n\nexport interface LlamaModelEvent {\n\tmodel: string;\n\tevent: string;\n\tdata?: unknown;\n}\n\nexport interface LlamaProgress {\n\tmessage: string;\n\tratio?: number;\n\tdetail?: string;\n}\n\nfunction errorMessage(payload: unknown, fallback: string): string {\n\tif (typeof payload !== \"object\" || payload === null) return fallback;\n\tconst error = (payload as { error?: unknown }).error;\n\tif (typeof error !== \"object\" || error === null) return fallback;\n\tconst message = (error as { message?: unknown }).message;\n\treturn typeof message === \"string\" && message ? message : fallback;\n}\n\nfunction isModelInfo(value: unknown): value is LlamaModelInfo {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst candidate = value as { id?: unknown; status?: { value?: unknown } };\n\treturn typeof candidate.id === \"string\" && typeof candidate.status?.value === \"string\";\n}\n\nfunction linkSignal(source: AbortSignal | undefined, target: AbortController): () => void {\n\tif (!source) return () => {};\n\tif (source.aborted) {\n\t\ttarget.abort(source.reason);\n\t\treturn () => {};\n\t}\n\tconst abort = () => target.abort(source.reason);\n\tsource.addEventListener(\"abort\", abort, { once: true });\n\treturn () => source.removeEventListener(\"abort\", abort);\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(signal.reason ?? new Error(\"Cancelled\"));\n\t\t\treturn;\n\t\t}\n\t\tconst abort = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(signal?.reason ?? new Error(\"Cancelled\"));\n\t\t};\n\t\tconst timeout = setTimeout(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t});\n}\n\nfunction parseLoadProgress(data: unknown): LlamaProgress | undefined {\n\tif (typeof data !== \"object\" || data === null) return undefined;\n\tconst progress = (data as { progress?: unknown }).progress;\n\tif (typeof progress !== \"object\" || progress === null) return undefined;\n\tconst value = progress as { stages?: unknown; current?: unknown; stage?: unknown; value?: unknown };\n\tconst stage =\n\t\ttypeof value.current === \"string\" ? value.current : typeof value.stage === \"string\" ? value.stage : undefined;\n\tconst stages = Array.isArray(value.stages)\n\t\t? value.stages.filter((entry): entry is string => typeof entry === \"string\")\n\t\t: [];\n\tconst stageRatio = typeof value.value === \"number\" ? Math.max(0, Math.min(1, value.value)) : undefined;\n\tlet ratio = stageRatio;\n\tif (stage && stages.length > 0) {\n\t\tconst index = stages.indexOf(stage);\n\t\tif (index >= 0) ratio = (index + (stageRatio ?? 0)) / stages.length;\n\t}\n\treturn {\n\t\tmessage: stage ? `Loading ${stage.replaceAll(\"_\", \" \")}` : \"Loading model\",\n\t\tratio,\n\t};\n}\n\nfunction parseDownloadProgress(data: unknown): LlamaProgress | undefined {\n\tif (typeof data !== \"object\" || data === null) return undefined;\n\tconst nested = (data as { progress?: unknown }).progress;\n\tconst files = typeof nested === \"object\" && nested !== null ? nested : data;\n\tlet done = 0;\n\tlet total = 0;\n\tfor (const value of Object.values(files as Record<string, unknown>)) {\n\t\tif (typeof value !== \"object\" || value === null) continue;\n\t\tconst entry = value as { done?: unknown; total?: unknown };\n\t\tif (typeof entry.done !== \"number\" || typeof entry.total !== \"number\") continue;\n\t\tdone += entry.done;\n\t\ttotal += entry.total;\n\t}\n\tif (total <= 0) return undefined;\n\treturn {\n\t\tmessage: \"Downloading model\",\n\t\tratio: done / total,\n\t\tdetail: `${formatBytes(done)} / ${formatBytes(total)}`,\n\t};\n}\n\nexport function formatBytes(bytes: number): string {\n\tif (bytes < 1024) return `${bytes} B`;\n\tconst units = [\"KiB\", \"MiB\", \"GiB\", \"TiB\"];\n\tlet value = bytes / 1024;\n\tlet unit = units[0]!;\n\tfor (let index = 1; index < units.length && value >= 1024; index++) {\n\t\tvalue /= 1024;\n\t\tunit = units[index]!;\n\t}\n\treturn `${value >= 10 ? value.toFixed(1) : value.toFixed(2)} ${unit}`;\n}\n\nexport function normalizeLlamaServerUrl(value: string): string {\n\tconst url = new URL(value.trim());\n\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n\t\tthrow new Error(\"Server URL must use http or https\");\n\t}\n\turl.hash = \"\";\n\turl.search = \"\";\n\turl.pathname = url.pathname.replace(/\\/+$/u, \"\").replace(/\\/v1$/u, \"\") || \"/\";\n\treturn url.toString().replace(/\\/$/u, \"\");\n}\n\nexport function llamaInferenceUrl(serverUrl: string): string {\n\treturn `${normalizeLlamaServerUrl(serverUrl)}/v1`;\n}\n\nexport class LlamaClient {\n\treadonly serverUrl: string;\n\tprivate readonly apiKey: string | undefined;\n\n\tconstructor(serverUrl: string, apiKey?: string) {\n\t\tthis.serverUrl = normalizeLlamaServerUrl(serverUrl);\n\t\tthis.apiKey = apiKey;\n\t}\n\n\tprivate async request(path: string, init: RequestInit = {}): Promise<unknown> {\n\t\tconst headers = new Headers(init.headers);\n\t\tif (init.body !== undefined) headers.set(\"Content-Type\", \"application/json\");\n\t\tif (this.apiKey) headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\t\tconst timeout = AbortSignal.timeout(15_000);\n\t\tconst signal = init.signal ? AbortSignal.any([init.signal, timeout]) : timeout;\n\t\tconst response = await fetch(`${this.serverUrl}${path}`, { ...init, headers, signal });\n\t\tlet payload: unknown;\n\t\ttry {\n\t\t\tpayload = await response.json();\n\t\t} catch {\n\t\t\tpayload = undefined;\n\t\t}\n\t\tif (!response.ok) throw new Error(errorMessage(payload, `llama.cpp returned HTTP ${response.status}`));\n\t\treturn payload;\n\t}\n\n\tasync list(options: { reload?: boolean; signal?: AbortSignal } = {}): Promise<LlamaModelInfo[]> {\n\t\tconst payload = await this.request(`/models${options.reload ? \"?reload=1\" : \"\"}`, { signal: options.signal });\n\t\tif (typeof payload !== \"object\" || payload === null || !Array.isArray((payload as { data?: unknown }).data)) {\n\t\t\tthrow new Error(\"llama.cpp returned an invalid model catalog\");\n\t\t}\n\t\tconst data = (payload as { data: unknown[] }).data;\n\t\tif (!data.every(isModelInfo)) throw new Error(\"Server is not running in llama.cpp router mode\");\n\t\treturn data;\n\t}\n\n\tasync props(options: { model?: string; signal?: AbortSignal } = {}): Promise<LlamaServerProps> {\n\t\tconst query = options.model ? `?${new URLSearchParams({ model: options.model, autoload: \"false\" })}` : \"\";\n\t\tconst payload = await this.request(`/props${query}`, { signal: options.signal });\n\t\tif (typeof payload !== \"object\" || payload === null) return {};\n\t\tconst { models_autoload: modelsAutoload, chat_template: chatTemplate } = payload as Record<string, unknown>;\n\t\treturn {\n\t\t\t...(typeof modelsAutoload === \"boolean\" ? { models_autoload: modelsAutoload } : {}),\n\t\t\t...(typeof chatTemplate === \"string\" ? { chat_template: chatTemplate } : {}),\n\t\t};\n\t}\n\n\tasync load(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models/load\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync unload(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models/unload\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync unloadAndWait(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.unload(model, signal);\n\t\twhile (true) {\n\t\t\tconst entry = (await this.list({ signal })).find((candidate) => candidate.id === model);\n\t\t\tif (!entry || entry.status.value === \"unloaded\") return;\n\t\t\tawait sleep(100, signal);\n\t\t}\n\t}\n\n\tasync download(model: string, signal?: AbortSignal): Promise<void> {\n\t\tawait this.request(\"/models\", { method: \"POST\", body: JSON.stringify({ model }), signal });\n\t}\n\n\tasync watch(onEvent: (event: LlamaModelEvent) => void, signal?: AbortSignal): Promise<void> {\n\t\tconst headers = new Headers();\n\t\tif (this.apiKey) headers.set(\"Authorization\", `Bearer ${this.apiKey}`);\n\t\tconst response = await fetch(`${this.serverUrl}/models/sse`, { headers, signal });\n\t\tif (!response.ok || !response.body) throw new Error(`llama.cpp SSE returned HTTP ${response.status}`);\n\t\tconst reader = response.body.getReader();\n\t\tconst decoder = new TextDecoder();\n\t\tlet buffer = \"\";\n\t\twhile (true) {\n\t\t\tconst chunk = await reader.read();\n\t\t\tif (chunk.done) break;\n\t\t\tbuffer += decoder.decode(chunk.value, { stream: true }).replaceAll(\"\\r\\n\", \"\\n\");\n\t\t\tlet boundary = buffer.indexOf(\"\\n\\n\");\n\t\t\twhile (boundary >= 0) {\n\t\t\t\tconst frame = buffer.slice(0, boundary);\n\t\t\t\tbuffer = buffer.slice(boundary + 2);\n\t\t\t\tconst data = frame\n\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t.filter((line) => line.startsWith(\"data:\"))\n\t\t\t\t\t.map((line) => line.slice(5).trimStart())\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t\tif (data) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst event = JSON.parse(data) as LlamaModelEvent;\n\t\t\t\t\t\tif (event && typeof event.model === \"string\" && typeof event.event === \"string\") onEvent(event);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Ignore malformed events; catalog polling remains authoritative.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tboundary = buffer.indexOf(\"\\n\\n\");\n\t\t\t}\n\t\t}\n\t}\n\n\tasync loadAndWait(\n\t\tmodel: string,\n\t\tonProgress: (progress: LlamaProgress) => void,\n\t\tsignal?: AbortSignal,\n\t): Promise<LlamaModelInfo> {\n\t\tconst watcher = new AbortController();\n\t\tconst unlink = linkSignal(signal, watcher);\n\t\tlet eventLoaded = false;\n\t\tlet eventError: string | undefined;\n\t\tvoid this.watch((event) => {\n\t\t\tif (event.model !== model) return;\n\t\t\tif (event.event !== \"model_status\" && event.event !== \"status_change\") return;\n\t\t\tconst data = event.data as { status?: unknown } | undefined;\n\t\t\tif (data?.status === \"loaded\") eventLoaded = true;\n\t\t\tif (data?.status === \"unloaded\") eventError = \"Model failed to load\";\n\t\t\tconst progress = parseLoadProgress(event.data);\n\t\t\tif (progress) onProgress(progress);\n\t\t}, watcher.signal).catch(() => {});\n\t\ttry {\n\t\t\tawait this.load(model, signal);\n\t\t\tonProgress({ message: \"Loading model\" });\n\t\t\twhile (true) {\n\t\t\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Cancelled\");\n\t\t\t\tconst entry = (await this.list({ signal })).find((candidate) => candidate.id === model);\n\t\t\t\tif (entry?.status.value === \"loaded\") return entry;\n\t\t\t\tif (eventLoaded && !entry) return { id: model, status: { value: \"loaded\" } };\n\t\t\t\tif (entry?.status.failed || eventError) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tentry?.status.exit_code === undefined\n\t\t\t\t\t\t\t? (eventError ?? \"Model failed to load\")\n\t\t\t\t\t\t\t: `Model exited with code ${entry.status.exit_code}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tawait sleep(250, signal);\n\t\t\t}\n\t\t} finally {\n\t\t\tunlink();\n\t\t\twatcher.abort();\n\t\t}\n\t}\n\n\tasync downloadAndWait(\n\t\tmodel: string,\n\t\tonProgress: (progress: LlamaProgress) => void,\n\t\tsignal?: AbortSignal,\n\t): Promise<LlamaModelInfo[]> {\n\t\tconst watcher = new AbortController();\n\t\tconst unlink = linkSignal(signal, watcher);\n\t\tlet finished = false;\n\t\tlet failure: string | undefined;\n\t\tlet sawDownloading = false;\n\t\tlet polls = 0;\n\t\tvoid this.watch((event) => {\n\t\t\tif (event.model !== model) return;\n\t\t\tif (event.event === \"download_finished\") finished = true;\n\t\t\tif (event.event === \"download_failed\") failure = errorMessage(event.data, \"Download failed\");\n\t\t\tif (event.event === \"download_progress\") {\n\t\t\t\tsawDownloading = true;\n\t\t\t\tconst progress = parseDownloadProgress(event.data);\n\t\t\t\tif (progress) onProgress(progress);\n\t\t\t}\n\t\t}, watcher.signal).catch(() => {});\n\t\ttry {\n\t\t\tawait this.download(model, signal);\n\t\t\tonProgress({ message: \"Downloading model\" });\n\t\t\twhile (true) {\n\t\t\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Cancelled\");\n\t\t\t\tif (failure) throw new Error(failure);\n\t\t\t\tconst models = await this.list({ signal });\n\t\t\t\tpolls++;\n\t\t\t\tconst entry = models.find((candidate) => candidate.id === model);\n\t\t\t\tif (entry?.status.value === \"downloading\") {\n\t\t\t\t\tsawDownloading = true;\n\t\t\t\t\tconst progress = parseDownloadProgress(entry.status.progress);\n\t\t\t\t\tif (progress) onProgress(progress);\n\t\t\t\t} else if (finished || (entry && (sawDownloading || polls >= 2))) {\n\t\t\t\t\treturn this.list({ reload: true, signal });\n\t\t\t\t}\n\t\t\t\tawait sleep(500, signal);\n\t\t\t}\n\t\t} finally {\n\t\t\tunlink();\n\t\t\twatcher.abort();\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"huggingface.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/huggingface.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;IACjC,aAAa,EAAE,uBAAuB,EAAE,CAAC;CACzC;AAsBD,wBAAsB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAe5G;AAED,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,YAAY,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,SAA2B,EAG7D;YAEa,OAAO;IA4Bf,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAgB7E;IAEK,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAuChF;CACD","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nconst DEFAULT_HUGGING_FACE_URL = \"https://huggingface.co\";\nconst QUANTIZATION_PATTERN =\n\t/(?:^|[-_.])((?:UD-)?(?:IQ\\d(?:_[A-Z0-9]+)+|Q\\d(?:_[A-Z0-9]+)+|BF16|F16|F32|MXFP\\d(?:_[A-Z0-9]+)*))$/iu;\nconst SHARD_SUFFIX_PATTERN = /-\\d{5}-of-\\d{5}$/u;\n\nexport interface HuggingFaceModel {\n\tid: string;\n\tdownloads: number;\n}\n\nexport interface HuggingFaceQuantization {\n\tname: string;\n\tsize?: number;\n}\n\nexport interface HuggingFaceModelDetails {\n\tid: string;\n\tgated: false | \"auto\" | \"manual\";\n\tquantizations: HuggingFaceQuantization[];\n}\n\nfunction payloadError(payload: unknown, fallback: string): string {\n\tif (typeof payload !== \"object\" || payload === null) return fallback;\n\tconst error = (payload as { error?: unknown }).error;\n\treturn typeof error === \"string\" && error ? error : fallback;\n}\n\nfunction parseRateLimitDelay(value: string | null): number | undefined {\n\tconst match = value?.match(/(?:^|;)t=(\\d+)/u);\n\treturn match ? Number(match[1]) : undefined;\n}\n\nasync function readToken(path: string): Promise<string | undefined> {\n\ttry {\n\t\tconst token = (await readFile(path, \"utf8\")).trim();\n\t\treturn token || undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport async function findHuggingFaceToken(env: NodeJS.ProcessEnv = process.env): Promise<string | undefined> {\n\tconst fromEnvironment = env.HF_TOKEN?.trim();\n\tif (fromEnvironment) return fromEnvironment;\n\n\tconst paths = [\n\t\tenv.HF_TOKEN_PATH,\n\t\tenv.HF_HOME ? join(env.HF_HOME, \"token\") : undefined,\n\t\tenv.XDG_CACHE_HOME ? join(env.XDG_CACHE_HOME, \"huggingface\", \"token\") : undefined,\n\t\tjoin(homedir(), \".cache\", \"huggingface\", \"token\"),\n\t].filter((path): path is string => Boolean(path));\n\tfor (const path of new Set(paths)) {\n\t\tconst token = await readToken(path);\n\t\tif (token) return token;\n\t}\n\treturn undefined;\n}\n\nexport class HuggingFaceClient {\n\tprivate readonly token: string | undefined;\n\tprivate readonly baseUrl: string;\n\n\tconstructor(token?: string, baseUrl = DEFAULT_HUGGING_FACE_URL) {\n\t\tthis.token = token;\n\t\tthis.baseUrl = baseUrl.replace(/\\/+$/u, \"\");\n\t}\n\n\tprivate async request(path: string, signal?: AbortSignal): Promise<unknown> {\n\t\tconst headers = new Headers();\n\t\tif (this.token) headers.set(\"Authorization\", `Bearer ${this.token}`);\n\t\tconst timeout = AbortSignal.timeout(15_000);\n\t\tconst response = await fetch(`${this.baseUrl}${path}`, {\n\t\t\theaders,\n\t\t\tsignal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n\t\t});\n\t\tlet payload: unknown;\n\t\ttry {\n\t\t\tpayload = await response.json();\n\t\t} catch {\n\t\t\tpayload = undefined;\n\t\t}\n\t\tif (!response.ok) {\n\t\t\tconst fallback = `Hugging Face returned HTTP ${response.status}`;\n\t\t\tif (response.status === 429) {\n\t\t\t\tconst delay =\n\t\t\t\t\tNumber(response.headers.get(\"retry-after\")) || parseRateLimitDelay(response.headers.get(\"ratelimit\"));\n\t\t\t\tthrow new Error(\n\t\t\t\t\tdelay ? `Hugging Face rate limit reached; retry in ${delay}s` : \"Hugging Face rate limit reached\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new Error(payloadError(payload, fallback));\n\t\t}\n\t\treturn payload;\n\t}\n\n\tasync search(query: string, signal?: AbortSignal): Promise<HuggingFaceModel[]> {\n\t\tconst params = new URLSearchParams({\n\t\t\tsearch: query,\n\t\t\tfilter: \"gguf\",\n\t\t\tsort: \"downloads\",\n\t\t\tdirection: \"-1\",\n\t\t\tlimit: \"20\",\n\t\t});\n\t\tconst payload = await this.request(`/api/models?${params}`, signal);\n\t\tif (!Array.isArray(payload)) throw new Error(\"Hugging Face returned invalid search results\");\n\t\treturn payload.flatMap((value) => {\n\t\t\tif (typeof value !== \"object\" || value === null || typeof (value as { id?: unknown }).id !== \"string\")\n\t\t\t\treturn [];\n\t\t\tconst model = value as { id: string; downloads?: unknown };\n\t\t\treturn [{ id: model.id, downloads: typeof model.downloads === \"number\" ? model.downloads : 0 }];\n\t\t});\n\t}\n\n\tasync details(id: string, signal?: AbortSignal): Promise<HuggingFaceModelDetails> {\n\t\tconst encodedId = id.split(\"/\").map(encodeURIComponent).join(\"/\");\n\t\tconst payload = await this.request(`/api/models/${encodedId}?blobs=true`, signal);\n\t\tif (typeof payload !== \"object\" || payload === null) {\n\t\t\tthrow new Error(\"Hugging Face returned invalid model details\");\n\t\t}\n\t\tconst model = payload as { id?: unknown; gated?: unknown; siblings?: unknown };\n\t\tconst sizes = new Map<string, { total: number; complete: boolean }>();\n\t\tif (Array.isArray(model.siblings)) {\n\t\t\tfor (const value of model.siblings) {\n\t\t\t\tif (typeof value !== \"object\" || value === null) continue;\n\t\t\t\tconst file = value as { rfilename?: unknown; size?: unknown };\n\t\t\t\tif (typeof file.rfilename !== \"string\" || !file.rfilename.toLowerCase().endsWith(\".gguf\")) continue;\n\t\t\t\tconst filename = file.rfilename.split(\"/\").at(-1)!;\n\t\t\t\tif (filename.toLowerCase().startsWith(\"mmproj\")) continue;\n\t\t\t\tconst stem = filename.slice(0, -5).replace(SHARD_SUFFIX_PATTERN, \"\");\n\t\t\t\tconst quantization = stem.match(QUANTIZATION_PATTERN)?.[1]?.toUpperCase();\n\t\t\t\tif (!quantization) continue;\n\t\t\t\tconst current = sizes.get(quantization) ?? { total: 0, complete: true };\n\t\t\t\tif (typeof file.size === \"number\") current.total += file.size;\n\t\t\t\telse current.complete = false;\n\t\t\t\tsizes.set(quantization, current);\n\t\t\t}\n\t\t}\n\t\tconst quantizations = [...sizes]\n\t\t\t.map(([name, size]) => ({ name, size: size.complete ? size.total : undefined }))\n\t\t\t.sort((left, right) => {\n\t\t\t\tif (left.name === \"Q4_K_M\") return -1;\n\t\t\t\tif (right.name === \"Q4_K_M\") return 1;\n\t\t\t\treturn (\n\t\t\t\t\t(left.size ?? Number.MAX_SAFE_INTEGER) - (right.size ?? Number.MAX_SAFE_INTEGER) ||\n\t\t\t\t\tleft.name.localeCompare(right.name)\n\t\t\t\t);\n\t\t\t});\n\t\treturn {\n\t\t\tid: typeof model.id === \"string\" ? model.id : id,\n\t\t\tgated: model.gated === \"auto\" || model.gated === \"manual\" ? model.gated : false,\n\t\t\tquantizations,\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"huggingface.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/huggingface.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;IACjC,aAAa,EAAE,uBAAuB,EAAE,CAAC;CACzC;AAsBD,wBAAsB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAe5G;AAED,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,YAAY,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,SAA2B,EAG7D;YAEa,OAAO;IA4Bf,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAgB7E;IAEK,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAuChF;CACD"}