@humain/terminal 0.0.2 → 0.0.3-beta.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 (688) hide show
  1. package/CHANGELOG.md +251 -24
  2. package/README.md +143 -119
  3. package/dist/cli/args.d.ts +4 -2
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +37 -39
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/auth-check.d.ts +19 -0
  8. package/dist/cli/auth-check.d.ts.map +1 -0
  9. package/dist/cli/auth-check.js +50 -0
  10. package/dist/cli/auth-check.js.map +1 -0
  11. package/dist/cli/auth-command.d.ts +24 -0
  12. package/dist/cli/auth-command.d.ts.map +1 -0
  13. package/dist/cli/auth-command.js +103 -0
  14. package/dist/cli/auth-command.js.map +1 -0
  15. package/dist/cli/config-selector.d.ts.map +1 -1
  16. package/dist/cli/config-selector.js +2 -2
  17. package/dist/cli/config-selector.js.map +1 -1
  18. package/dist/cli/credential-print.d.ts +5 -15
  19. package/dist/cli/credential-print.d.ts.map +1 -1
  20. package/dist/cli/credential-print.js +42 -83
  21. package/dist/cli/credential-print.js.map +1 -1
  22. package/dist/cli/experimental/auth.d.ts +16 -0
  23. package/dist/cli/experimental/auth.d.ts.map +1 -0
  24. package/dist/cli/experimental/auth.js +13 -0
  25. package/dist/cli/experimental/auth.js.map +1 -0
  26. package/dist/cli/experimental/cli.d.ts +6 -0
  27. package/dist/cli/experimental/cli.d.ts.map +1 -0
  28. package/dist/cli/experimental/cli.js +5 -0
  29. package/dist/cli/experimental/cli.js.map +1 -0
  30. package/dist/cli/experimental/command-options.d.ts +17 -0
  31. package/dist/cli/experimental/command-options.d.ts.map +1 -0
  32. package/dist/cli/experimental/command-options.js +35 -0
  33. package/dist/cli/experimental/command-options.js.map +1 -0
  34. package/dist/cli/experimental/command.d.ts +63 -0
  35. package/dist/cli/experimental/command.d.ts.map +1 -0
  36. package/dist/cli/experimental/command.js +130 -0
  37. package/dist/cli/experimental/command.js.map +1 -0
  38. package/dist/cli/experimental/commands/client.d.ts +13 -0
  39. package/dist/cli/experimental/commands/client.d.ts.map +1 -0
  40. package/dist/cli/experimental/commands/client.js +25 -0
  41. package/dist/cli/experimental/commands/client.js.map +1 -0
  42. package/dist/cli/experimental/commands/pi.d.ts +15 -0
  43. package/dist/cli/experimental/commands/pi.d.ts.map +1 -0
  44. package/dist/cli/experimental/commands/pi.js +28 -0
  45. package/dist/cli/experimental/commands/pi.js.map +1 -0
  46. package/dist/cli/experimental/commands/server.d.ts +13 -0
  47. package/dist/cli/experimental/commands/server.d.ts.map +1 -0
  48. package/dist/cli/experimental/commands/server.js +25 -0
  49. package/dist/cli/experimental/commands/server.js.map +1 -0
  50. package/dist/cli/experimental/transport-address.d.ts +10 -0
  51. package/dist/cli/experimental/transport-address.d.ts.map +1 -0
  52. package/dist/cli/experimental/transport-address.js +38 -0
  53. package/dist/cli/experimental/transport-address.js.map +1 -0
  54. package/dist/cli/list-models.d.ts +1 -1
  55. package/dist/cli/list-models.d.ts.map +1 -1
  56. package/dist/cli/list-models.js +2 -2
  57. package/dist/cli/list-models.js.map +1 -1
  58. package/dist/cli/startup-ui.d.ts +1 -1
  59. package/dist/cli/startup-ui.d.ts.map +1 -1
  60. package/dist/cli/startup-ui.js +2 -2
  61. package/dist/cli/startup-ui.js.map +1 -1
  62. package/dist/client/index.d.ts +3 -0
  63. package/dist/client/index.d.ts.map +1 -0
  64. package/dist/client/index.js +3 -0
  65. package/dist/client/index.js.map +1 -0
  66. package/dist/client/remote-session.d.ts +53 -0
  67. package/dist/client/remote-session.d.ts.map +1 -0
  68. package/dist/client/remote-session.js +340 -0
  69. package/dist/client/remote-session.js.map +1 -0
  70. package/dist/client/transcript.d.ts +12 -0
  71. package/dist/client/transcript.d.ts.map +1 -0
  72. package/dist/client/transcript.js +98 -0
  73. package/dist/client/transcript.js.map +1 -0
  74. package/dist/config.d.ts.map +1 -1
  75. package/dist/config.js +4 -3
  76. package/dist/config.js.map +1 -1
  77. package/dist/core/agent-session-services.d.ts +1 -0
  78. package/dist/core/agent-session-services.d.ts.map +1 -1
  79. package/dist/core/agent-session-services.js +1 -0
  80. package/dist/core/agent-session-services.js.map +1 -1
  81. package/dist/core/agent-session.d.ts +1 -10
  82. package/dist/core/agent-session.d.ts.map +1 -1
  83. package/dist/core/agent-session.js +72 -70
  84. package/dist/core/agent-session.js.map +1 -1
  85. package/dist/core/auth-storage.d.ts +25 -9
  86. package/dist/core/auth-storage.d.ts.map +1 -1
  87. package/dist/core/auth-storage.js +237 -39
  88. package/dist/core/auth-storage.js.map +1 -1
  89. package/dist/core/extensions/index.d.ts +1 -1
  90. package/dist/core/extensions/index.d.ts.map +1 -1
  91. package/dist/core/extensions/index.js.map +1 -1
  92. package/dist/core/extensions/loader.d.ts.map +1 -1
  93. package/dist/core/extensions/loader.js +60 -41
  94. package/dist/core/extensions/loader.js.map +1 -1
  95. package/dist/core/extensions/runner.d.ts +2 -1
  96. package/dist/core/extensions/runner.d.ts.map +1 -1
  97. package/dist/core/extensions/runner.js +3 -0
  98. package/dist/core/extensions/runner.js.map +1 -1
  99. package/dist/core/extensions/types.d.ts +27 -4
  100. package/dist/core/extensions/types.d.ts.map +1 -1
  101. package/dist/core/extensions/types.js.map +1 -1
  102. package/dist/core/http-dispatcher.d.ts.map +1 -1
  103. package/dist/core/http-dispatcher.js +5 -0
  104. package/dist/core/http-dispatcher.js.map +1 -1
  105. package/dist/core/keybindings.d.ts +45 -5
  106. package/dist/core/keybindings.d.ts.map +1 -1
  107. package/dist/core/keybindings.js.map +1 -1
  108. package/dist/core/model-config.d.ts +29 -5
  109. package/dist/core/model-config.d.ts.map +1 -1
  110. package/dist/core/model-config.js +4 -0
  111. package/dist/core/model-config.js.map +1 -1
  112. package/dist/core/model-registry.d.ts +5 -3
  113. package/dist/core/model-registry.d.ts.map +1 -1
  114. package/dist/core/model-registry.js +13 -10
  115. package/dist/core/model-registry.js.map +1 -1
  116. package/dist/core/model-resolver.d.ts +4 -3
  117. package/dist/core/model-resolver.d.ts.map +1 -1
  118. package/dist/core/model-resolver.js +42 -10
  119. package/dist/core/model-resolver.js.map +1 -1
  120. package/dist/core/model-runtime.d.ts +30 -13
  121. package/dist/core/model-runtime.d.ts.map +1 -1
  122. package/dist/core/model-runtime.js +233 -73
  123. package/dist/core/model-runtime.js.map +1 -1
  124. package/dist/core/models-store.d.ts +12 -7
  125. package/dist/core/models-store.d.ts.map +1 -1
  126. package/dist/core/models-store.js +83 -14
  127. package/dist/core/models-store.js.map +1 -1
  128. package/dist/core/package-manager.d.ts +6 -3
  129. package/dist/core/package-manager.d.ts.map +1 -1
  130. package/dist/core/package-manager.js +80 -61
  131. package/dist/core/package-manager.js.map +1 -1
  132. package/dist/core/pi-manifest.d.ts +8 -0
  133. package/dist/core/pi-manifest.d.ts.map +1 -0
  134. package/dist/core/pi-manifest.js +28 -0
  135. package/dist/core/pi-manifest.js.map +1 -0
  136. package/dist/core/provider-composer.d.ts +4 -1
  137. package/dist/core/provider-composer.d.ts.map +1 -1
  138. package/dist/core/provider-composer.js +36 -15
  139. package/dist/core/provider-composer.js.map +1 -1
  140. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  141. package/dist/core/remote-catalog-provider.js +73 -67
  142. package/dist/core/remote-catalog-provider.js.map +1 -1
  143. package/dist/core/resource-loader.d.ts.map +1 -1
  144. package/dist/core/resource-loader.js +2 -2
  145. package/dist/core/resource-loader.js.map +1 -1
  146. package/dist/core/runtime-credentials.d.ts +5 -5
  147. package/dist/core/runtime-credentials.d.ts.map +1 -1
  148. package/dist/core/runtime-credentials.js +11 -8
  149. package/dist/core/runtime-credentials.js.map +1 -1
  150. package/dist/core/sdk.d.ts +1 -1
  151. package/dist/core/sdk.d.ts.map +1 -1
  152. package/dist/core/sdk.js +2 -2
  153. package/dist/core/sdk.js.map +1 -1
  154. package/dist/core/session-manager.d.ts.map +1 -1
  155. package/dist/core/session-manager.js +3 -1
  156. package/dist/core/session-manager.js.map +1 -1
  157. package/dist/core/settings-manager.d.ts +12 -0
  158. package/dist/core/settings-manager.d.ts.map +1 -1
  159. package/dist/core/settings-manager.js +40 -16
  160. package/dist/core/settings-manager.js.map +1 -1
  161. package/dist/core/system-prompt.d.ts.map +1 -1
  162. package/dist/core/system-prompt.js +8 -0
  163. package/dist/core/system-prompt.js.map +1 -1
  164. package/dist/core/tools/bash.d.ts +5 -1
  165. package/dist/core/tools/bash.d.ts.map +1 -1
  166. package/dist/core/tools/bash.js +16 -15
  167. package/dist/core/tools/bash.js.map +1 -1
  168. package/dist/core/tools/edit.d.ts +4 -0
  169. package/dist/core/tools/edit.d.ts.map +1 -1
  170. package/dist/core/tools/edit.js +11 -7
  171. package/dist/core/tools/edit.js.map +1 -1
  172. package/dist/core/tools/find.d.ts +7 -0
  173. package/dist/core/tools/find.d.ts.map +1 -1
  174. package/dist/core/tools/find.js +16 -19
  175. package/dist/core/tools/find.js.map +1 -1
  176. package/dist/core/tools/grep.d.ts +4 -0
  177. package/dist/core/tools/grep.d.ts.map +1 -1
  178. package/dist/core/tools/grep.js +5 -1
  179. package/dist/core/tools/grep.js.map +1 -1
  180. package/dist/core/tools/ls.d.ts +4 -0
  181. package/dist/core/tools/ls.d.ts.map +1 -1
  182. package/dist/core/tools/ls.js +5 -1
  183. package/dist/core/tools/ls.js.map +1 -1
  184. package/dist/core/tools/read.d.ts +4 -0
  185. package/dist/core/tools/read.d.ts.map +1 -1
  186. package/dist/core/tools/read.js +7 -3
  187. package/dist/core/tools/read.js.map +1 -1
  188. package/dist/core/tools/write.d.ts +4 -0
  189. package/dist/core/tools/write.d.ts.map +1 -1
  190. package/dist/core/tools/write.js +6 -2
  191. package/dist/core/tools/write.js.map +1 -1
  192. package/dist/extensions/llama/index.d.ts.map +1 -1
  193. package/dist/extensions/llama/index.js +11 -2
  194. package/dist/extensions/llama/index.js.map +1 -1
  195. package/dist/extensions/llama/provider.d.ts.map +1 -1
  196. package/dist/extensions/llama/provider.js +21 -7
  197. package/dist/extensions/llama/provider.js.map +1 -1
  198. package/dist/humain/agent-execution-protocol.d.ts +218 -0
  199. package/dist/humain/agent-execution-protocol.d.ts.map +1 -0
  200. package/dist/humain/agent-execution-protocol.js +204 -0
  201. package/dist/humain/agent-execution-protocol.js.map +1 -0
  202. package/dist/humain/agent-execution-runtime.d.ts +35 -0
  203. package/dist/humain/agent-execution-runtime.d.ts.map +1 -0
  204. package/dist/humain/agent-execution-runtime.js +170 -0
  205. package/dist/humain/agent-execution-runtime.js.map +1 -0
  206. package/dist/humain/index.d.ts.map +1 -1
  207. package/dist/humain/index.js +8 -7
  208. package/dist/humain/index.js.map +1 -1
  209. package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
  210. package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
  211. package/dist/humain/mcp-adapter/vendor/README.md +736 -0
  212. package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
  213. package/dist/humain/mcp-adapter/vendor/agent-dir.ts +68 -0
  214. package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +377 -0
  215. package/dist/humain/mcp-adapter/vendor/app-bridge.bundle.js +67 -0
  216. package/dist/humain/mcp-adapter/vendor/banner.png +0 -0
  217. package/dist/humain/mcp-adapter/vendor/cli.js +230 -0
  218. package/dist/humain/mcp-adapter/vendor/commands.ts +627 -0
  219. package/dist/humain/mcp-adapter/vendor/config.ts +1226 -0
  220. package/dist/humain/mcp-adapter/vendor/consent-manager.ts +64 -0
  221. package/dist/humain/mcp-adapter/vendor/direct-tools.ts +607 -0
  222. package/dist/humain/mcp-adapter/vendor/elicitation-handler.ts +348 -0
  223. package/dist/humain/mcp-adapter/vendor/error-signal.ts +21 -0
  224. package/dist/humain/mcp-adapter/vendor/errors.ts +223 -0
  225. package/dist/humain/mcp-adapter/vendor/glimpse-ui.ts +80 -0
  226. package/dist/humain/mcp-adapter/vendor/host-html-template.ts +461 -0
  227. package/dist/humain/mcp-adapter/vendor/index.bundle.d.mts +4 -0
  228. package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +16279 -0
  229. package/dist/humain/mcp-adapter/vendor/index.ts +898 -0
  230. package/dist/humain/mcp-adapter/vendor/init.ts +649 -0
  231. package/dist/humain/mcp-adapter/vendor/json-schema-validator.ts +69 -0
  232. package/dist/humain/mcp-adapter/vendor/lifecycle.ts +147 -0
  233. package/dist/humain/mcp-adapter/vendor/logger.ts +169 -0
  234. package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +993 -0
  235. package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +1000 -0
  236. package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +510 -0
  237. package/dist/humain/mcp-adapter/vendor/mcp-code.ts +354 -0
  238. package/dist/humain/mcp-adapter/vendor/mcp-keyring-helper.cjs +89 -0
  239. package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +616 -0
  240. package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +408 -0
  241. package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +1015 -0
  242. package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +187 -0
  243. package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +130 -0
  244. package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +667 -0
  245. package/dist/humain/mcp-adapter/vendor/mcp-status.ts +109 -0
  246. package/dist/humain/mcp-adapter/vendor/mcp-trace.ts +306 -0
  247. package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +363 -0
  248. package/dist/humain/mcp-adapter/vendor/npx-resolver.ts +543 -0
  249. package/dist/humain/mcp-adapter/vendor/oauth-handler.ts +30 -0
  250. package/dist/humain/mcp-adapter/vendor/oauth.ts +48 -0
  251. package/dist/humain/mcp-adapter/vendor/onboarding-state.ts +76 -0
  252. package/dist/humain/mcp-adapter/vendor/package.json +179 -0
  253. package/dist/humain/mcp-adapter/vendor/panel-keys.ts +53 -0
  254. package/dist/humain/mcp-adapter/vendor/prompts.ts +353 -0
  255. package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +1331 -0
  256. package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +336 -0
  257. package/dist/humain/mcp-adapter/vendor/resource-tools.ts +17 -0
  258. package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +91 -0
  259. package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +284 -0
  260. package/dist/humain/mcp-adapter/vendor/search-ranking.ts +206 -0
  261. package/dist/humain/mcp-adapter/vendor/server-manager.ts +1129 -0
  262. package/dist/humain/mcp-adapter/vendor/session-recovery.ts +151 -0
  263. package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +38 -0
  264. package/dist/humain/mcp-adapter/vendor/state.ts +62 -0
  265. package/dist/humain/mcp-adapter/vendor/tool-approval.ts +182 -0
  266. package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +296 -0
  267. package/dist/humain/mcp-adapter/vendor/tool-registrar.ts +253 -0
  268. package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +423 -0
  269. package/dist/humain/mcp-adapter/vendor/ts-shape.ts +149 -0
  270. package/dist/humain/mcp-adapter/vendor/types.ts +942 -0
  271. package/dist/humain/mcp-adapter/vendor/ui-app-bridge-helpers.ts +40 -0
  272. package/dist/humain/mcp-adapter/vendor/ui-resource-handler.ts +250 -0
  273. package/dist/humain/mcp-adapter/vendor/ui-server.ts +866 -0
  274. package/dist/humain/mcp-adapter/vendor/ui-session.ts +570 -0
  275. package/dist/humain/mcp-adapter/vendor/ui-stream-types.ts +89 -0
  276. package/dist/humain/mcp-adapter/vendor/ui-tool-visibility.ts +25 -0
  277. package/dist/humain/mcp-adapter/vendor/unix-socket-transport.ts +85 -0
  278. package/dist/humain/mcp-adapter/vendor/utils.ts +310 -0
  279. package/dist/humain/mcp-adapter.d.ts +3 -0
  280. package/dist/humain/mcp-adapter.d.ts.map +1 -0
  281. package/dist/humain/mcp-adapter.js +5 -0
  282. package/dist/humain/mcp-adapter.js.map +1 -0
  283. package/dist/humain/pi-agent-execution-host.d.ts +34 -0
  284. package/dist/humain/pi-agent-execution-host.d.ts.map +1 -0
  285. package/dist/humain/pi-agent-execution-host.js +77 -0
  286. package/dist/humain/pi-agent-execution-host.js.map +1 -0
  287. package/dist/humain/web-access/host.d.ts +4 -0
  288. package/dist/humain/web-access/host.d.ts.map +1 -0
  289. package/dist/humain/web-access/host.js +3 -0
  290. package/dist/humain/web-access/host.js.map +1 -0
  291. package/dist/humain/web-access/index.d.ts +3 -0
  292. package/dist/humain/web-access/index.d.ts.map +1 -0
  293. package/dist/humain/web-access/index.js +5 -0
  294. package/dist/humain/web-access/index.js.map +1 -0
  295. package/dist/humain/web-access/vendor/activity.d.ts +34 -0
  296. package/dist/humain/web-access/vendor/activity.d.ts.map +1 -0
  297. package/dist/humain/web-access/vendor/activity.js +68 -0
  298. package/dist/humain/web-access/vendor/activity.js.map +1 -0
  299. package/dist/humain/web-access/vendor/anysearch.d.ts +8 -0
  300. package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -0
  301. package/dist/humain/web-access/vendor/anysearch.js +167 -0
  302. package/dist/humain/web-access/vendor/anysearch.js.map +1 -0
  303. package/dist/humain/web-access/vendor/auth-fetch.d.ts +13 -0
  304. package/dist/humain/web-access/vendor/auth-fetch.d.ts.map +1 -0
  305. package/dist/humain/web-access/vendor/auth-fetch.js +134 -0
  306. package/dist/humain/web-access/vendor/auth-fetch.js.map +1 -0
  307. package/dist/humain/web-access/vendor/bocha.d.ts +4 -0
  308. package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -0
  309. package/dist/humain/web-access/vendor/bocha.js +219 -0
  310. package/dist/humain/web-access/vendor/bocha.js.map +1 -0
  311. package/dist/humain/web-access/vendor/brave.d.ts +4 -0
  312. package/dist/humain/web-access/vendor/brave.d.ts.map +1 -0
  313. package/dist/humain/web-access/vendor/brave.js +194 -0
  314. package/dist/humain/web-access/vendor/brave.js.map +1 -0
  315. package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts +12 -0
  316. package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -0
  317. package/dist/humain/web-access/vendor/brightdata-unlocker.js +230 -0
  318. package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -0
  319. package/dist/humain/web-access/vendor/brightdata.d.ts +8 -0
  320. package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -0
  321. package/dist/humain/web-access/vendor/brightdata.js +519 -0
  322. package/dist/humain/web-access/vendor/brightdata.js.map +1 -0
  323. package/dist/humain/web-access/vendor/chrome-cookies.d.ts +23 -0
  324. package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
  325. package/dist/humain/web-access/vendor/chrome-cookies.js +522 -0
  326. package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -0
  327. package/dist/humain/web-access/vendor/content-find.d.ts +11 -0
  328. package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -0
  329. package/dist/humain/web-access/vendor/content-find.js +117 -0
  330. package/dist/humain/web-access/vendor/content-find.js.map +1 -0
  331. package/dist/humain/web-access/vendor/credential-source.d.ts +28 -0
  332. package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -0
  333. package/dist/humain/web-access/vendor/credential-source.js +151 -0
  334. package/dist/humain/web-access/vendor/credential-source.js.map +1 -0
  335. package/dist/humain/web-access/vendor/curator-page.d.ts +30 -0
  336. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
  337. package/dist/humain/web-access/vendor/curator-page.js +3556 -0
  338. package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
  339. package/dist/humain/web-access/vendor/curator-server.d.ts +94 -0
  340. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
  341. package/dist/humain/web-access/vendor/curator-server.js +690 -0
  342. package/dist/humain/web-access/vendor/curator-server.js.map +1 -0
  343. package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts +60 -0
  344. package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts.map +1 -0
  345. package/dist/humain/web-access/vendor/datalab-pdf-extract.js +416 -0
  346. package/dist/humain/web-access/vendor/datalab-pdf-extract.js.map +1 -0
  347. package/dist/humain/web-access/vendor/declared-web-links.d.ts +16 -0
  348. package/dist/humain/web-access/vendor/declared-web-links.d.ts.map +1 -0
  349. package/dist/humain/web-access/vendor/declared-web-links.js +168 -0
  350. package/dist/humain/web-access/vendor/declared-web-links.js.map +1 -0
  351. package/dist/humain/web-access/vendor/duckduckgo.d.ts +4 -0
  352. package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -0
  353. package/dist/humain/web-access/vendor/duckduckgo.js +123 -0
  354. package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -0
  355. package/dist/humain/web-access/vendor/exa.d.ts +10 -0
  356. package/dist/humain/web-access/vendor/exa.d.ts.map +1 -0
  357. package/dist/humain/web-access/vendor/exa.js +426 -0
  358. package/dist/humain/web-access/vendor/exa.js.map +1 -0
  359. package/dist/humain/web-access/vendor/extract.d.ts +48 -0
  360. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
  361. package/dist/humain/web-access/vendor/extract.js +1126 -0
  362. package/dist/humain/web-access/vendor/extract.js.map +1 -0
  363. package/dist/humain/web-access/vendor/feature-config.d.ts +3 -0
  364. package/dist/humain/web-access/vendor/feature-config.d.ts.map +1 -0
  365. package/dist/humain/web-access/vendor/feature-config.js +27 -0
  366. package/dist/humain/web-access/vendor/feature-config.js.map +1 -0
  367. package/dist/humain/web-access/vendor/fetch-params.d.ts +27 -0
  368. package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
  369. package/dist/humain/web-access/vendor/fetch-params.js +71 -0
  370. package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
  371. package/dist/humain/web-access/vendor/firecrawl.d.ts +19 -0
  372. package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
  373. package/dist/humain/web-access/vendor/firecrawl.js +370 -0
  374. package/dist/humain/web-access/vendor/firecrawl.js.map +1 -0
  375. package/dist/humain/web-access/vendor/gemini-api.d.ts +27 -0
  376. package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -0
  377. package/dist/humain/web-access/vendor/gemini-api.js +230 -0
  378. package/dist/humain/web-access/vendor/gemini-api.js.map +1 -0
  379. package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts +9 -0
  380. package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts.map +1 -0
  381. package/dist/humain/web-access/vendor/gemini-pdf-extract.js +85 -0
  382. package/dist/humain/web-access/vendor/gemini-pdf-extract.js.map +1 -0
  383. package/dist/humain/web-access/vendor/gemini-search.d.ts +40 -0
  384. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -0
  385. package/dist/humain/web-access/vendor/gemini-search.js +832 -0
  386. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -0
  387. package/dist/humain/web-access/vendor/gemini-url-context.d.ts +4 -0
  388. package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -0
  389. package/dist/humain/web-access/vendor/gemini-url-context.js +101 -0
  390. package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -0
  391. package/dist/humain/web-access/vendor/gemini-web-config.d.ts +4 -0
  392. package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -0
  393. package/dist/humain/web-access/vendor/gemini-web-config.js +42 -0
  394. package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -0
  395. package/dist/humain/web-access/vendor/gemini-web.d.ts +18 -0
  396. package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -0
  397. package/dist/humain/web-access/vendor/gemini-web.js +385 -0
  398. package/dist/humain/web-access/vendor/gemini-web.js.map +1 -0
  399. package/dist/humain/web-access/vendor/github-api.d.ts +7 -0
  400. package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -0
  401. package/dist/humain/web-access/vendor/github-api.js +160 -0
  402. package/dist/humain/web-access/vendor/github-api.js.map +1 -0
  403. package/dist/humain/web-access/vendor/github-extract.d.ts +13 -0
  404. package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -0
  405. package/dist/humain/web-access/vendor/github-extract.js +635 -0
  406. package/dist/humain/web-access/vendor/github-extract.js.map +1 -0
  407. package/dist/humain/web-access/vendor/index.d.ts +4 -0
  408. package/dist/humain/web-access/vendor/index.d.ts.map +1 -0
  409. package/dist/humain/web-access/vendor/index.js +3076 -0
  410. package/dist/humain/web-access/vendor/index.js.map +1 -0
  411. package/dist/humain/web-access/vendor/jina-search.d.ts +8 -0
  412. package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -0
  413. package/dist/humain/web-access/vendor/jina-search.js +255 -0
  414. package/dist/humain/web-access/vendor/jina-search.js.map +1 -0
  415. package/dist/humain/web-access/vendor/kagi.d.ts +15 -0
  416. package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -0
  417. package/dist/humain/web-access/vendor/kagi.js +262 -0
  418. package/dist/humain/web-access/vendor/kagi.js.map +1 -0
  419. package/dist/humain/web-access/vendor/ollama.d.ts +15 -0
  420. package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -0
  421. package/dist/humain/web-access/vendor/ollama.js +216 -0
  422. package/dist/humain/web-access/vendor/ollama.js.map +1 -0
  423. package/dist/humain/web-access/vendor/openai-search.d.ts +15 -0
  424. package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -0
  425. package/dist/humain/web-access/vendor/openai-search.js +459 -0
  426. package/dist/humain/web-access/vendor/openai-search.js.map +1 -0
  427. package/dist/humain/web-access/vendor/page-query.d.ts +16 -0
  428. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -0
  429. package/dist/humain/web-access/vendor/page-query.js +79 -0
  430. package/dist/humain/web-access/vendor/page-query.js.map +1 -0
  431. package/dist/humain/web-access/vendor/parallel.d.ts +12 -0
  432. package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -0
  433. package/dist/humain/web-access/vendor/parallel.js +343 -0
  434. package/dist/humain/web-access/vendor/parallel.js.map +1 -0
  435. package/dist/humain/web-access/vendor/pdf-extract.d.ts +44 -0
  436. package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -0
  437. package/dist/humain/web-access/vendor/pdf-extract.js +298 -0
  438. package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -0
  439. package/dist/humain/web-access/vendor/perplexity.d.ts +20 -0
  440. package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -0
  441. package/dist/humain/web-access/vendor/perplexity.js +159 -0
  442. package/dist/humain/web-access/vendor/perplexity.js.map +1 -0
  443. package/dist/humain/web-access/vendor/querit.d.ts +10 -0
  444. package/dist/humain/web-access/vendor/querit.d.ts.map +1 -0
  445. package/dist/humain/web-access/vendor/querit.js +335 -0
  446. package/dist/humain/web-access/vendor/querit.js.map +1 -0
  447. package/dist/humain/web-access/vendor/render-search-error.d.ts +57 -0
  448. package/dist/humain/web-access/vendor/render-search-error.d.ts.map +1 -0
  449. package/dist/humain/web-access/vendor/render-search-error.js +130 -0
  450. package/dist/humain/web-access/vendor/render-search-error.js.map +1 -0
  451. package/dist/humain/web-access/vendor/rsc-extract.d.ts +12 -0
  452. package/dist/humain/web-access/vendor/rsc-extract.d.ts.map +1 -0
  453. package/dist/humain/web-access/vendor/rsc-extract.js +329 -0
  454. package/dist/humain/web-access/vendor/rsc-extract.js.map +1 -0
  455. package/dist/humain/web-access/vendor/search1api.d.ts +10 -0
  456. package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -0
  457. package/dist/humain/web-access/vendor/search1api.js +251 -0
  458. package/dist/humain/web-access/vendor/search1api.js.map +1 -0
  459. package/dist/humain/web-access/vendor/searchinfinity.d.ts +8 -0
  460. package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -0
  461. package/dist/humain/web-access/vendor/searchinfinity.js +229 -0
  462. package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -0
  463. package/dist/humain/web-access/vendor/searxng.d.ts +4 -0
  464. package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -0
  465. package/dist/humain/web-access/vendor/searxng.js +238 -0
  466. package/dist/humain/web-access/vendor/searxng.js.map +1 -0
  467. package/dist/humain/web-access/vendor/serpbase.d.ts +4 -0
  468. package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -0
  469. package/dist/humain/web-access/vendor/serpbase.js +211 -0
  470. package/dist/humain/web-access/vendor/serpbase.js.map +1 -0
  471. package/dist/humain/web-access/vendor/serpdive.d.ts +8 -0
  472. package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -0
  473. package/dist/humain/web-access/vendor/serpdive.js +267 -0
  474. package/dist/humain/web-access/vendor/serpdive.js.map +1 -0
  475. package/dist/humain/web-access/vendor/source-check.d.ts +99 -0
  476. package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -0
  477. package/dist/humain/web-access/vendor/source-check.js +205 -0
  478. package/dist/humain/web-access/vendor/source-check.js.map +1 -0
  479. package/dist/humain/web-access/vendor/ssrf-protection.d.ts +50 -0
  480. package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -0
  481. package/dist/humain/web-access/vendor/ssrf-protection.js +466 -0
  482. package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -0
  483. package/dist/humain/web-access/vendor/storage.d.ts +55 -0
  484. package/dist/humain/web-access/vendor/storage.d.ts.map +1 -0
  485. package/dist/humain/web-access/vendor/storage.js +485 -0
  486. package/dist/humain/web-access/vendor/storage.js.map +1 -0
  487. package/dist/humain/web-access/vendor/summary-model-scope.d.ts +25 -0
  488. package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -0
  489. package/dist/humain/web-access/vendor/summary-model-scope.js +98 -0
  490. package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -0
  491. package/dist/humain/web-access/vendor/summary-review.d.ts +26 -0
  492. package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
  493. package/dist/humain/web-access/vendor/summary-review.js +344 -0
  494. package/dist/humain/web-access/vendor/summary-review.js.map +1 -0
  495. package/dist/humain/web-access/vendor/tavily.d.ts +8 -0
  496. package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -0
  497. package/dist/humain/web-access/vendor/tavily.js +194 -0
  498. package/dist/humain/web-access/vendor/tavily.js.map +1 -0
  499. package/dist/humain/web-access/vendor/tinyfish.d.ts +11 -0
  500. package/dist/humain/web-access/vendor/tinyfish.d.ts.map +1 -0
  501. package/dist/humain/web-access/vendor/tinyfish.js +331 -0
  502. package/dist/humain/web-access/vendor/tinyfish.js.map +1 -0
  503. package/dist/humain/web-access/vendor/utils.d.ts +20 -0
  504. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -0
  505. package/dist/humain/web-access/vendor/utils.js +91 -0
  506. package/dist/humain/web-access/vendor/utils.js.map +1 -0
  507. package/dist/humain/web-access/vendor/video-extract.d.ts +16 -0
  508. package/dist/humain/web-access/vendor/video-extract.d.ts.map +1 -0
  509. package/dist/humain/web-access/vendor/video-extract.js +335 -0
  510. package/dist/humain/web-access/vendor/video-extract.js.map +1 -0
  511. package/dist/humain/web-access/vendor/xai-search.d.ts +13 -0
  512. package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -0
  513. package/dist/humain/web-access/vendor/xai-search.js +331 -0
  514. package/dist/humain/web-access/vendor/xai-search.js.map +1 -0
  515. package/dist/humain/web-access/vendor/youtube-extract.d.ts +27 -0
  516. package/dist/humain/web-access/vendor/youtube-extract.d.ts.map +1 -0
  517. package/dist/humain/web-access/vendor/youtube-extract.js +282 -0
  518. package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -0
  519. package/dist/index.d.ts +7 -4
  520. package/dist/index.d.ts.map +1 -1
  521. package/dist/index.js +5 -2
  522. package/dist/index.js.map +1 -1
  523. package/dist/main.d.ts +2 -2
  524. package/dist/main.d.ts.map +1 -1
  525. package/dist/main.js +169 -102
  526. package/dist/main.js.map +1 -1
  527. package/dist/modes/agent-exec-mode.d.ts +14 -0
  528. package/dist/modes/agent-exec-mode.d.ts.map +1 -0
  529. package/dist/modes/agent-exec-mode.js +92 -0
  530. package/dist/modes/agent-exec-mode.js.map +1 -0
  531. package/dist/modes/index.d.ts +4 -2
  532. package/dist/modes/index.d.ts.map +1 -1
  533. package/dist/modes/index.js +2 -1
  534. package/dist/modes/index.js.map +1 -1
  535. package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
  536. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  537. package/dist/modes/interactive/components/assistant-message.js +13 -4
  538. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  539. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  540. package/dist/modes/interactive/components/custom-editor.js +7 -0
  541. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  542. package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
  543. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
  544. package/dist/modes/interactive/components/earendil-announcement.js +40 -0
  545. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
  546. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  547. package/dist/modes/interactive/components/footer.js +1 -1
  548. package/dist/modes/interactive/components/footer.js.map +1 -1
  549. package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
  550. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
  551. package/dist/modes/interactive/components/markdown-transform.js +19 -0
  552. package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
  553. package/dist/modes/interactive/components/mermaid.d.ts +11 -0
  554. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
  555. package/dist/modes/interactive/components/mermaid.js +75 -0
  556. package/dist/modes/interactive/components/mermaid.js.map +1 -0
  557. package/dist/modes/interactive/components/model-selector.d.ts +1 -1
  558. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  559. package/dist/modes/interactive/components/model-selector.js +16 -4
  560. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  561. package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
  562. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  563. package/dist/modes/interactive/components/scoped-models-selector.js +26 -0
  564. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  565. package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
  566. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  567. package/dist/modes/interactive/components/settings-selector.js +30 -0
  568. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  569. package/dist/modes/interactive/components/user-message.d.ts +3 -1
  570. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  571. package/dist/modes/interactive/components/user-message.js +9 -2
  572. package/dist/modes/interactive/components/user-message.js.map +1 -1
  573. package/dist/modes/interactive/interactive-mode.d.ts +45 -9
  574. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  575. package/dist/modes/interactive/interactive-mode.js +581 -211
  576. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  577. package/dist/modes/interactive/theme/dark.json +1 -0
  578. package/dist/modes/interactive/theme/light.json +1 -0
  579. package/dist/modes/interactive/theme/theme-controller.d.ts +3 -0
  580. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  581. package/dist/modes/interactive/theme/theme-controller.js +10 -1
  582. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  583. package/dist/modes/interactive/theme/theme-schema.json +5 -1
  584. package/dist/modes/interactive/theme/theme.d.ts +2 -2
  585. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  586. package/dist/modes/interactive/theme/theme.js +24 -6
  587. package/dist/modes/interactive/theme/theme.js.map +1 -1
  588. package/dist/modes/json-event.d.ts +28 -0
  589. package/dist/modes/json-event.d.ts.map +1 -0
  590. package/dist/modes/json-event.js +12 -0
  591. package/dist/modes/json-event.js.map +1 -0
  592. package/dist/modes/print-mode.d.ts.map +1 -1
  593. package/dist/modes/print-mode.js +12 -2
  594. package/dist/modes/print-mode.js.map +1 -1
  595. package/dist/modes/rpc/rpc-client.d.ts +12 -5
  596. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  597. package/dist/modes/rpc/rpc-client.js +55 -1
  598. package/dist/modes/rpc/rpc-client.js.map +1 -1
  599. package/dist/modes/rpc/rpc-mode.d.ts +1 -1
  600. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  601. package/dist/modes/rpc/rpc-mode.js +13 -3
  602. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  603. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  604. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  605. package/dist/modes/rpc/rpc-types.js.map +1 -1
  606. package/dist/package-manager-cli.d.ts.map +1 -1
  607. package/dist/package-manager-cli.js +11 -9
  608. package/dist/package-manager-cli.js.map +1 -1
  609. package/dist/rpc-entry.d.ts.map +1 -1
  610. package/dist/rpc-entry.js +3 -2
  611. package/dist/rpc-entry.js.map +1 -1
  612. package/dist/server/create-harness.d.ts +26 -0
  613. package/dist/server/create-harness.d.ts.map +1 -0
  614. package/dist/server/create-harness.js +104 -0
  615. package/dist/server/create-harness.js.map +1 -0
  616. package/dist/utils/abort.d.ts +5 -0
  617. package/dist/utils/abort.d.ts.map +1 -0
  618. package/dist/utils/abort.js +48 -0
  619. package/dist/utils/abort.js.map +1 -0
  620. package/dist/utils/clipboard.d.ts +1 -1
  621. package/dist/utils/clipboard.d.ts.map +1 -1
  622. package/dist/utils/clipboard.js +22 -2
  623. package/dist/utils/clipboard.js.map +1 -1
  624. package/dist/utils/management-http.d.ts +23 -0
  625. package/dist/utils/management-http.d.ts.map +1 -0
  626. package/dist/utils/management-http.js +50 -0
  627. package/dist/utils/management-http.js.map +1 -0
  628. package/dist/utils/paths.d.ts +3 -0
  629. package/dist/utils/paths.d.ts.map +1 -1
  630. package/dist/utils/paths.js +23 -1
  631. package/dist/utils/paths.js.map +1 -1
  632. package/dist/utils/tool-result-images.d.ts +19 -0
  633. package/dist/utils/tool-result-images.d.ts.map +1 -0
  634. package/dist/utils/tool-result-images.js +45 -0
  635. package/dist/utils/tool-result-images.js.map +1 -0
  636. package/dist/utils/tools-manager.d.ts.map +1 -1
  637. package/dist/utils/tools-manager.js +13 -25
  638. package/dist/utils/tools-manager.js.map +1 -1
  639. package/dist/utils/version-check.d.ts +4 -0
  640. package/dist/utils/version-check.d.ts.map +1 -1
  641. package/dist/utils/version-check.js +23 -5
  642. package/dist/utils/version-check.js.map +1 -1
  643. package/docs/compaction.md +2 -2
  644. package/docs/custom-provider.md +7 -5
  645. package/docs/extensions.md +30 -5
  646. package/docs/humain-terminal.md +21 -1
  647. package/docs/json.md +24 -19
  648. package/docs/keybindings.md +46 -14
  649. package/docs/models.md +32 -11
  650. package/docs/providers.md +9 -1
  651. package/docs/quickstart.md +39 -37
  652. package/docs/rpc.md +31 -11
  653. package/docs/sdk.md +21 -2
  654. package/docs/security.md +21 -21
  655. package/docs/session-format.md +14 -14
  656. package/docs/settings.md +4 -1
  657. package/docs/themes.md +5 -3
  658. package/docs/usage.md +7 -0
  659. package/examples/extensions/custom-compaction.ts +3 -18
  660. package/examples/extensions/custom-provider-anthropic/index.ts +5 -1
  661. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  662. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  663. package/examples/extensions/custom-provider-gitlab-duo/index.ts +5 -1
  664. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  665. package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
  666. package/examples/extensions/gondolin/package-lock.json +2 -2
  667. package/examples/extensions/gondolin/package.json +1 -1
  668. package/examples/extensions/handoff.ts +4 -13
  669. package/examples/extensions/qna.ts +5 -9
  670. package/examples/extensions/sandbox/package-lock.json +2 -2
  671. package/examples/extensions/sandbox/package.json +1 -1
  672. package/examples/extensions/summarize.ts +9 -20
  673. package/examples/extensions/with-deps/package-lock.json +2 -2
  674. package/examples/extensions/with-deps/package.json +1 -1
  675. package/examples/rpc-extension-ui.ts +11 -2
  676. package/examples/sdk/02-custom-model.ts +2 -3
  677. package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
  678. package/examples/sdk/12-full-control.ts +1 -1
  679. package/examples/sdk/README.md +1 -1
  680. package/npm-shrinkwrap.json +2771 -535
  681. package/package.json +40 -11
  682. package/src/humain/mcp-adapter/UPSTREAM.md +15 -0
  683. package/src/humain/mcp-adapter/upstream.json +7 -0
  684. package/src/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
  685. package/src/humain/mcp-adapter/vendor/LICENSE +21 -0
  686. package/src/humain/web-access/UPSTREAM.md +17 -0
  687. package/src/humain/web-access/upstream.json +23 -0
  688. package/src/humain/web-access/vendor/LICENSE +21 -0
@@ -0,0 +1,103 @@
1
+ import { APP_NAME } from "../config.js";
2
+ export class AuthCommandError extends Error {
3
+ }
4
+ const AUTH_COMMAND_USAGE = {
5
+ check: `${APP_NAME} auth check --provider <provider> [--json] [--credentials] [--no-refresh]`,
6
+ api_key: `${APP_NAME} auth print-api-key --provider <provider> [--model <model>]`,
7
+ bearer_token: `${APP_NAME} auth print-bearer-token --provider <provider> [--model <model>] [--min-expiry <duration>]`,
8
+ };
9
+ export function getAuthCommandName(kind) {
10
+ return kind === "check" ? "auth check" : kind === "api_key" ? "auth print-api-key" : "auth print-bearer-token";
11
+ }
12
+ export function getAuthCommandUsage(kind) {
13
+ return AUTH_COMMAND_USAGE[kind];
14
+ }
15
+ export function isAuthCommandHelp(args) {
16
+ return (args[0] === "auth" &&
17
+ (args[1] === undefined || args[1] === "help" || args.includes("--help") || args.includes("-h")));
18
+ }
19
+ export function printAuthCommandHelp() {
20
+ console.log(`Usage:
21
+ ${APP_NAME} auth print-api-key [--provider <provider>] [--model <model>]
22
+ ${APP_NAME} auth print-bearer-token [--provider <provider>] [--model <model>] [--min-expiry <duration>]
23
+ ${APP_NAME} auth check [--provider <provider>] [--model <model>] [--json] [--credentials] [--no-refresh]
24
+
25
+ Auth commands require at least one of --provider or --model. Checks refresh expired OAuth credentials by default; --no-refresh prevents this. --credentials emits the credential, or includes it in JSON output.`);
26
+ }
27
+ export function parseAuthCommand(args) {
28
+ if (args[0] !== "auth")
29
+ return undefined;
30
+ const kind = args[1] === "check"
31
+ ? "check"
32
+ : args[1] === "print-api-key"
33
+ ? "api_key"
34
+ : args[1] === "print-bearer-token"
35
+ ? "bearer_token"
36
+ : undefined;
37
+ if (!kind) {
38
+ throw new AuthCommandError(`Unknown auth command "${args[1] ?? ""}". Use "${APP_NAME} auth print-api-key", "${APP_NAME} auth print-bearer-token", or "${APP_NAME} auth check".`);
39
+ }
40
+ const commandArgs = [];
41
+ let json = false;
42
+ let credentials = false;
43
+ let noRefresh = false;
44
+ let minExpiryMs;
45
+ for (let index = 2; index < args.length; index++) {
46
+ const arg = args[index];
47
+ if (arg === "--min-expiry") {
48
+ if (kind !== "bearer_token")
49
+ throw new AuthCommandError("--min-expiry is only supported by print-bearer-token");
50
+ const value = args[++index];
51
+ const match = value ? /^(\d+)(ms|s|m|h)$/iu.exec(value) : undefined;
52
+ if (!match)
53
+ throw new AuthCommandError("--min-expiry must use a duration such as 30m or 1h");
54
+ const amount = Number(match[1]);
55
+ const unit = match[2];
56
+ minExpiryMs = amount * (unit === "ms" ? 1 : unit === "s" ? 1_000 : unit === "m" ? 60_000 : 3_600_000);
57
+ continue;
58
+ }
59
+ if (arg === "--json" || arg === "--credentials" || arg === "--no-refresh") {
60
+ if (kind !== "check")
61
+ throw new AuthCommandError(`${arg} is only supported by auth check`);
62
+ if (arg === "--json")
63
+ json = true;
64
+ else if (arg === "--credentials")
65
+ credentials = true;
66
+ else
67
+ noRefresh = true;
68
+ continue;
69
+ }
70
+ commandArgs.push(arg);
71
+ }
72
+ return minExpiryMs === undefined
73
+ ? { kind, args: commandArgs, json, credentials, noRefresh }
74
+ : { kind, args: commandArgs, json, credentials, noRefresh, minExpiryMs };
75
+ }
76
+ export function validateAuthCommandArgs(args, kind) {
77
+ const provider = args.provider?.trim() || undefined;
78
+ const model = args.model?.trim() || undefined;
79
+ if (args.unknownFlags.size > 0) {
80
+ const option = args.unknownFlags.keys().next().value;
81
+ throw new AuthCommandError(`Unknown option --${option} for "${getAuthCommandName(kind)}".`);
82
+ }
83
+ if (args.apiKey !== undefined || args.messages.length > 0 || args.fileArgs.length > 0) {
84
+ throw new AuthCommandError("Auth commands only accept --provider and --model");
85
+ }
86
+ if (kind === "check") {
87
+ if (!provider && !model) {
88
+ throw new AuthCommandError("Auth checks require --provider <provider> or --model <model>");
89
+ }
90
+ return { provider, model };
91
+ }
92
+ if (!provider && !model) {
93
+ throw new AuthCommandError("Credential printing requires --provider <provider> or --model <model>");
94
+ }
95
+ return { provider, model };
96
+ }
97
+ export function getAuthCredential(auth) {
98
+ if (auth?.auth.apiKey)
99
+ return auth.auth.apiKey;
100
+ const authorization = Object.entries(auth?.auth.headers ?? {}).find(([name]) => name.toLowerCase() === "authorization")?.[1];
101
+ return typeof authorization === "string" ? /^Bearer\s+(.+)$/iu.exec(authorization)?.[1] : undefined;
102
+ }
103
+ //# sourceMappingURL=auth-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-command.js","sourceRoot":"","sources":["../../src/cli/auth-command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAcxC,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,MAAM,kBAAkB,GAAoC;IAC3D,KAAK,EAAE,GAAG,QAAQ,2EAA2E;IAC7F,OAAO,EAAE,GAAG,QAAQ,6DAA6D;IACjF,YAAY,EAAE,GAAG,QAAQ,4FAA4F;CACrH,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAAC,IAAqB,EAAU;IACjE,OAAO,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,yBAAyB,CAAC;AAAA,CAC/G;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAqB,EAAU;IAClE,OAAO,kBAA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F,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IACD,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,gBAAgB,CAAC,uEAAuE,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAAA,CAC3B;AAED,MAAM,UAAU,iBAAiB,CAAC,IAA4B,EAAsB;IACnF,IAAI,IAAI,EAAE,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/C,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAClE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,eAAe,CAClD,EAAE,CAAC,CAAC,CAAC,CAAC;IACP,OAAO,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CACpG","sourcesContent":["import type { AuthResult } from \"@earendil-works/pi-ai\";\nimport { APP_NAME } from \"../config.ts\";\nimport type { Args } from \"./args.ts\";\n\nexport type AuthCommandKind = \"check\" | \"api_key\" | \"bearer_token\";\n\nexport interface AuthCommand {\n\tkind: AuthCommandKind;\n\targs: string[];\n\tjson: boolean;\n\tcredentials: boolean;\n\tnoRefresh: boolean;\n\tminExpiryMs?: number;\n}\n\nexport class AuthCommandError extends Error {}\n\nconst AUTH_COMMAND_USAGE: Record<AuthCommandKind, string> = {\n\tcheck: `${APP_NAME} auth check --provider <provider> [--json] [--credentials] [--no-refresh]`,\n\tapi_key: `${APP_NAME} auth print-api-key --provider <provider> [--model <model>]`,\n\tbearer_token: `${APP_NAME} auth print-bearer-token --provider <provider> [--model <model>] [--min-expiry <duration>]`,\n};\n\nexport function getAuthCommandName(kind: AuthCommandKind): string {\n\treturn kind === \"check\" ? \"auth check\" : kind === \"api_key\" ? \"auth print-api-key\" : \"auth print-bearer-token\";\n}\n\nexport function getAuthCommandUsage(kind: AuthCommandKind): string {\n\treturn AUTH_COMMAND_USAGE[kind];\n}\n\nexport function isAuthCommandHelp(args: string[]): boolean {\n\treturn (\n\t\targs[0] === \"auth\" &&\n\t\t(args[1] === undefined || args[1] === \"help\" || args.includes(\"--help\") || args.includes(\"-h\"))\n\t);\n}\n\nexport function printAuthCommandHelp(): void {\n\tconsole.log(`Usage:\n ${APP_NAME} auth print-api-key [--provider <provider>] [--model <model>]\n ${APP_NAME} auth print-bearer-token [--provider <provider>] [--model <model>] [--min-expiry <duration>]\n ${APP_NAME} auth check [--provider <provider>] [--model <model>] [--json] [--credentials] [--no-refresh]\n\nAuth commands require at least one of --provider or --model. Checks refresh expired OAuth credentials by default; --no-refresh prevents this. --credentials emits the credential, or includes it in JSON output.`);\n}\n\nexport function parseAuthCommand(args: string[]): AuthCommand | undefined {\n\tif (args[0] !== \"auth\") return undefined;\n\n\tconst kind =\n\t\targs[1] === \"check\"\n\t\t\t? \"check\"\n\t\t\t: args[1] === \"print-api-key\"\n\t\t\t\t? \"api_key\"\n\t\t\t\t: args[1] === \"print-bearer-token\"\n\t\t\t\t\t? \"bearer_token\"\n\t\t\t\t\t: undefined;\n\tif (!kind) {\n\t\tthrow new AuthCommandError(\n\t\t\t`Unknown auth command \"${args[1] ?? \"\"}\". Use \"${APP_NAME} auth print-api-key\", \"${APP_NAME} auth print-bearer-token\", or \"${APP_NAME} auth check\".`,\n\t\t);\n\t}\n\n\tconst commandArgs: string[] = [];\n\tlet json = false;\n\tlet credentials = false;\n\tlet noRefresh = false;\n\tlet minExpiryMs: number | undefined;\n\tfor (let index = 2; index < args.length; index++) {\n\t\tconst arg = args[index];\n\t\tif (arg === \"--min-expiry\") {\n\t\t\tif (kind !== \"bearer_token\")\n\t\t\t\tthrow new AuthCommandError(\"--min-expiry is only supported by print-bearer-token\");\n\t\t\tconst value = args[++index];\n\t\t\tconst match = value ? /^(\\d+)(ms|s|m|h)$/iu.exec(value) : undefined;\n\t\t\tif (!match) throw new AuthCommandError(\"--min-expiry must use a duration such as 30m or 1h\");\n\t\t\tconst amount = Number(match[1]);\n\t\t\tconst unit = match[2];\n\t\t\tminExpiryMs = amount * (unit === \"ms\" ? 1 : unit === \"s\" ? 1_000 : unit === \"m\" ? 60_000 : 3_600_000);\n\t\t\tcontinue;\n\t\t}\n\t\tif (arg === \"--json\" || arg === \"--credentials\" || arg === \"--no-refresh\") {\n\t\t\tif (kind !== \"check\") throw new AuthCommandError(`${arg} is only supported by auth check`);\n\t\t\tif (arg === \"--json\") json = true;\n\t\t\telse if (arg === \"--credentials\") credentials = true;\n\t\t\telse noRefresh = true;\n\t\t\tcontinue;\n\t\t}\n\t\tcommandArgs.push(arg);\n\t}\n\n\treturn minExpiryMs === undefined\n\t\t? { kind, args: commandArgs, json, credentials, noRefresh }\n\t\t: { kind, args: commandArgs, json, credentials, noRefresh, minExpiryMs };\n}\n\nexport function validateAuthCommandArgs(args: Args, kind: AuthCommandKind): { provider?: string; model?: string } {\n\tconst provider = args.provider?.trim() || undefined;\n\tconst model = args.model?.trim() || undefined;\n\tif (args.unknownFlags.size > 0) {\n\t\tconst option = args.unknownFlags.keys().next().value;\n\t\tthrow new AuthCommandError(`Unknown option --${option} for \"${getAuthCommandName(kind)}\".`);\n\t}\n\tif (args.apiKey !== undefined || args.messages.length > 0 || args.fileArgs.length > 0) {\n\t\tthrow new AuthCommandError(\"Auth commands only accept --provider and --model\");\n\t}\n\tif (kind === \"check\") {\n\t\tif (!provider && !model) {\n\t\t\tthrow new AuthCommandError(\"Auth checks require --provider <provider> or --model <model>\");\n\t\t}\n\t\treturn { provider, model };\n\t}\n\tif (!provider && !model) {\n\t\tthrow new AuthCommandError(\"Credential printing requires --provider <provider> or --model <model>\");\n\t}\n\treturn { provider, model };\n}\n\nexport function getAuthCredential(auth: AuthResult | undefined): string | undefined {\n\tif (auth?.auth.apiKey) return auth.auth.apiKey;\n\tconst authorization = Object.entries(auth?.auth.headers ?? {}).find(\n\t\t([name]) => name.toLowerCase() === \"authorization\",\n\t)?.[1];\n\treturn typeof authorization === \"string\" ? /^Bearer\\s+(.+)$/iu.exec(authorization)?.[1] : undefined;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"config-selector.d.ts","sourceRoot":"","sources":["../../src/cli/config-selector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAGvH,MAAM,WAAW,qBAAqB;IACrC,aAAa,EAAE,mBAAmB,CAAC;IACnC,eAAe,EAAE,eAAe,CAAC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjC,oBAAoB,EAAE,OAAO,CAAC;CAC9B;AAED,sDAAsD;AACtD,wBAAsB,YAAY,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoChF","sourcesContent":["/**\n * TUI config selector for `pi config` command\n */\n\nimport { ProcessTerminal, TUI } from \"@earendil-works/pi-tui\";\nimport type { SettingsManager } from \"../core/settings-manager.ts\";\nimport { ConfigSelectorComponent, type ScopedResolvedPaths } from \"../modes/interactive/components/config-selector.ts\";\nimport { initTheme, stopThemeWatcher } from \"../modes/interactive/theme/theme.ts\";\n\nexport interface ConfigSelectorOptions {\n\tresolvedPaths: ScopedResolvedPaths;\n\tsettingsManager: SettingsManager;\n\tcwd: string;\n\tagentDir: string;\n\twriteScope: \"global\" | \"project\";\n\tprojectModeAvailable: boolean;\n}\n\n/** Show TUI config selector and return when closed */\nexport async function selectConfig(options: ConfigSelectorOptions): Promise<void> {\n\t// Initialize theme before showing TUI\n\tinitTheme(options.settingsManager.getTheme(), true);\n\n\treturn new Promise((resolve) => {\n\t\tconst ui = new TUI(new ProcessTerminal(), undefined, options.agentDir);\n\t\tlet resolved = false;\n\n\t\tconst selector = new ConfigSelectorComponent(\n\t\t\toptions.resolvedPaths,\n\t\t\toptions.settingsManager,\n\t\t\toptions.cwd,\n\t\t\toptions.agentDir,\n\t\t\t() => {\n\t\t\t\tif (!resolved) {\n\t\t\t\t\tresolved = true;\n\t\t\t\t\tui.stop();\n\t\t\t\t\tstopThemeWatcher();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tui.stop();\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t},\n\t\t\t() => ui.requestRender(),\n\t\t\tui.terminal.rows,\n\t\t\toptions.writeScope,\n\t\t\toptions.projectModeAvailable,\n\t\t);\n\n\t\tui.addChild(selector);\n\t\tui.setFocus(selector.getResourceList());\n\t\tui.start();\n\t});\n}\n"]}
1
+ {"version":3,"file":"config-selector.d.ts","sourceRoot":"","sources":["../../src/cli/config-selector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAA2B,KAAK,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAGvH,MAAM,WAAW,qBAAqB;IACrC,aAAa,EAAE,mBAAmB,CAAC;IACnC,eAAe,EAAE,eAAe,CAAC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjC,oBAAoB,EAAE,OAAO,CAAC;CAC9B;AAED,sDAAsD;AACtD,wBAAsB,YAAY,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoChF","sourcesContent":["/**\n * TUI config selector for `pi config` command\n */\n\nimport { ProcessTerminal, type TUI, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport type { SettingsManager } from \"../core/settings-manager.ts\";\nimport { ConfigSelectorComponent, type ScopedResolvedPaths } from \"../modes/interactive/components/config-selector.ts\";\nimport { initTheme, stopThemeWatcher } from \"../modes/interactive/theme/theme.ts\";\n\nexport interface ConfigSelectorOptions {\n\tresolvedPaths: ScopedResolvedPaths;\n\tsettingsManager: SettingsManager;\n\tcwd: string;\n\tagentDir: string;\n\twriteScope: \"global\" | \"project\";\n\tprojectModeAvailable: boolean;\n}\n\n/** Show TUI config selector and return when closed */\nexport async function selectConfig(options: ConfigSelectorOptions): Promise<void> {\n\t// Initialize theme before showing TUI\n\tinitTheme(options.settingsManager.getTheme(), true);\n\n\treturn new Promise((resolve) => {\n\t\tconst ui: TUI = new TuiMainScreen(new ProcessTerminal(), undefined, options.agentDir);\n\t\tlet resolved = false;\n\n\t\tconst selector = new ConfigSelectorComponent(\n\t\t\toptions.resolvedPaths,\n\t\t\toptions.settingsManager,\n\t\t\toptions.cwd,\n\t\t\toptions.agentDir,\n\t\t\t() => {\n\t\t\t\tif (!resolved) {\n\t\t\t\t\tresolved = true;\n\t\t\t\t\tui.stop();\n\t\t\t\t\tstopThemeWatcher();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tui.stop();\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t},\n\t\t\t() => ui.requestRender(),\n\t\t\tui.terminal.rows,\n\t\t\toptions.writeScope,\n\t\t\toptions.projectModeAvailable,\n\t\t);\n\n\t\tui.addChild(selector);\n\t\tui.setFocus(selector.getResourceList());\n\t\tui.start();\n\t});\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * TUI config selector for `pi config` command
3
3
  */
4
- import { ProcessTerminal, TUI } from "@earendil-works/pi-tui";
4
+ import { ProcessTerminal, TuiMainScreen } from "@earendil-works/pi-tui";
5
5
  import { ConfigSelectorComponent } from "../modes/interactive/components/config-selector.js";
6
6
  import { initTheme, stopThemeWatcher } from "../modes/interactive/theme/theme.js";
7
7
  /** Show TUI config selector and return when closed */
@@ -9,7 +9,7 @@ export async function selectConfig(options) {
9
9
  // Initialize theme before showing TUI
10
10
  initTheme(options.settingsManager.getTheme(), true);
11
11
  return new Promise((resolve) => {
12
- const ui = new TUI(new ProcessTerminal(), undefined, options.agentDir);
12
+ const ui = new TuiMainScreen(new ProcessTerminal(), undefined, options.agentDir);
13
13
  let resolved = false;
14
14
  const selector = new ConfigSelectorComponent(options.resolvedPaths, options.settingsManager, options.cwd, options.agentDir, () => {
15
15
  if (!resolved) {
@@ -1 +1 @@
1
- {"version":3,"file":"config-selector.js","sourceRoot":"","sources":["../../src/cli/config-selector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,uBAAuB,EAA4B,MAAM,oDAAoD,CAAC;AACvH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAWlF,sDAAsD;AACtD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAA8B,EAAiB;IACjF,sCAAsC;IACtC,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC;IAEpD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/B,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,IAAI,eAAe,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvE,IAAI,QAAQ,GAAG,KAAK,CAAC;QAErB,MAAM,QAAQ,GAAG,IAAI,uBAAuB,CAC3C,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,GAAG,EACX,OAAO,CAAC,QAAQ,EAChB,GAAG,EAAE,CAAC;YACL,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACf,QAAQ,GAAG,IAAI,CAAC;gBAChB,EAAE,CAAC,IAAI,EAAE,CAAC;gBACV,gBAAgB,EAAE,CAAC;gBACnB,OAAO,EAAE,CAAC;YACX,CAAC;QAAA,CACD,EACD,GAAG,EAAE,CAAC;YACL,EAAE,CAAC,IAAI,EAAE,CAAC;YACV,gBAAgB,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAAA,CAChB,EACD,GAAG,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,EACxB,EAAE,CAAC,QAAQ,CAAC,IAAI,EAChB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,oBAAoB,CAC5B,CAAC;QAEF,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC;QACxC,EAAE,CAAC,KAAK,EAAE,CAAC;IAAA,CACX,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * TUI config selector for `pi config` command\n */\n\nimport { ProcessTerminal, TUI } from \"@earendil-works/pi-tui\";\nimport type { SettingsManager } from \"../core/settings-manager.ts\";\nimport { ConfigSelectorComponent, type ScopedResolvedPaths } from \"../modes/interactive/components/config-selector.ts\";\nimport { initTheme, stopThemeWatcher } from \"../modes/interactive/theme/theme.ts\";\n\nexport interface ConfigSelectorOptions {\n\tresolvedPaths: ScopedResolvedPaths;\n\tsettingsManager: SettingsManager;\n\tcwd: string;\n\tagentDir: string;\n\twriteScope: \"global\" | \"project\";\n\tprojectModeAvailable: boolean;\n}\n\n/** Show TUI config selector and return when closed */\nexport async function selectConfig(options: ConfigSelectorOptions): Promise<void> {\n\t// Initialize theme before showing TUI\n\tinitTheme(options.settingsManager.getTheme(), true);\n\n\treturn new Promise((resolve) => {\n\t\tconst ui = new TUI(new ProcessTerminal(), undefined, options.agentDir);\n\t\tlet resolved = false;\n\n\t\tconst selector = new ConfigSelectorComponent(\n\t\t\toptions.resolvedPaths,\n\t\t\toptions.settingsManager,\n\t\t\toptions.cwd,\n\t\t\toptions.agentDir,\n\t\t\t() => {\n\t\t\t\tif (!resolved) {\n\t\t\t\t\tresolved = true;\n\t\t\t\t\tui.stop();\n\t\t\t\t\tstopThemeWatcher();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tui.stop();\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t},\n\t\t\t() => ui.requestRender(),\n\t\t\tui.terminal.rows,\n\t\t\toptions.writeScope,\n\t\t\toptions.projectModeAvailable,\n\t\t);\n\n\t\tui.addChild(selector);\n\t\tui.setFocus(selector.getResourceList());\n\t\tui.start();\n\t});\n}\n"]}
1
+ {"version":3,"file":"config-selector.js","sourceRoot":"","sources":["../../src/cli/config-selector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAY,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAElF,OAAO,EAAE,uBAAuB,EAA4B,MAAM,oDAAoD,CAAC;AACvH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAWlF,sDAAsD;AACtD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAA8B,EAAiB;IACjF,sCAAsC;IACtC,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC;IAEpD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/B,MAAM,EAAE,GAAQ,IAAI,aAAa,CAAC,IAAI,eAAe,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtF,IAAI,QAAQ,GAAG,KAAK,CAAC;QAErB,MAAM,QAAQ,GAAG,IAAI,uBAAuB,CAC3C,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,GAAG,EACX,OAAO,CAAC,QAAQ,EAChB,GAAG,EAAE,CAAC;YACL,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACf,QAAQ,GAAG,IAAI,CAAC;gBAChB,EAAE,CAAC,IAAI,EAAE,CAAC;gBACV,gBAAgB,EAAE,CAAC;gBACnB,OAAO,EAAE,CAAC;YACX,CAAC;QAAA,CACD,EACD,GAAG,EAAE,CAAC;YACL,EAAE,CAAC,IAAI,EAAE,CAAC;YACV,gBAAgB,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAAA,CAChB,EACD,GAAG,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,EACxB,EAAE,CAAC,QAAQ,CAAC,IAAI,EAChB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,oBAAoB,CAC5B,CAAC;QAEF,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC;QACxC,EAAE,CAAC,KAAK,EAAE,CAAC;IAAA,CACX,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * TUI config selector for `pi config` command\n */\n\nimport { ProcessTerminal, type TUI, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport type { SettingsManager } from \"../core/settings-manager.ts\";\nimport { ConfigSelectorComponent, type ScopedResolvedPaths } from \"../modes/interactive/components/config-selector.ts\";\nimport { initTheme, stopThemeWatcher } from \"../modes/interactive/theme/theme.ts\";\n\nexport interface ConfigSelectorOptions {\n\tresolvedPaths: ScopedResolvedPaths;\n\tsettingsManager: SettingsManager;\n\tcwd: string;\n\tagentDir: string;\n\twriteScope: \"global\" | \"project\";\n\tprojectModeAvailable: boolean;\n}\n\n/** Show TUI config selector and return when closed */\nexport async function selectConfig(options: ConfigSelectorOptions): Promise<void> {\n\t// Initialize theme before showing TUI\n\tinitTheme(options.settingsManager.getTheme(), true);\n\n\treturn new Promise((resolve) => {\n\t\tconst ui: TUI = new TuiMainScreen(new ProcessTerminal(), undefined, options.agentDir);\n\t\tlet resolved = false;\n\n\t\tconst selector = new ConfigSelectorComponent(\n\t\t\toptions.resolvedPaths,\n\t\t\toptions.settingsManager,\n\t\t\toptions.cwd,\n\t\t\toptions.agentDir,\n\t\t\t() => {\n\t\t\t\tif (!resolved) {\n\t\t\t\t\tresolved = true;\n\t\t\t\t\tui.stop();\n\t\t\t\t\tstopThemeWatcher();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tui.stop();\n\t\t\t\tstopThemeWatcher();\n\t\t\t\tprocess.exit(0);\n\t\t\t},\n\t\t\t() => ui.requestRender(),\n\t\t\tui.terminal.rows,\n\t\t\toptions.writeScope,\n\t\t\toptions.projectModeAvailable,\n\t\t);\n\n\t\tui.addChild(selector);\n\t\tui.setFocus(selector.getResourceList());\n\t\tui.start();\n\t});\n}\n"]}
@@ -1,23 +1,13 @@
1
1
  import type { ModelRuntime } from "../core/model-runtime.ts";
2
2
  import type { Args } from "./args.ts";
3
- export type CredentialPrintKind = "api_key" | "bearer_token";
4
- export interface CredentialPrintCommand {
5
- kind: CredentialPrintKind;
6
- args: string[];
7
- minExpiryMs?: number;
8
- }
9
- export declare class CredentialPrintError extends Error {
10
- }
11
- export declare function isCredentialPrintHelp(args: string[]): boolean;
12
- export declare function printCredentialPrintHelp(): void;
13
- /** Parse the small, extensible `pi auth` command surface before normal startup. */
14
- export declare function parseCredentialPrintCommand(args: string[]): CredentialPrintCommand | undefined;
15
- export declare function validateCredentialPrintArgs(args: Args): void;
3
+ import { type AuthCommandKind } from "./auth-command.ts";
4
+ type CredentialPrintKind = Exclude<AuthCommandKind, "check">;
16
5
  /**
17
- * Resolve one request credential for a specific provider/model pair.
6
+ * Resolve one configured provider credential.
18
7
  *
19
8
  * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists
20
9
  * OAuth credentials with less than five minutes remaining through the normal request-auth path.
21
10
  */
22
- export declare function resolveCredentialForPrint(args: Args, modelRuntime: ModelRuntime, kind: CredentialPrintKind, minExpiryMs?: number): Promise<string>;
11
+ export declare function resolveCredentialForPrint(args: Args, modelRuntime: ModelRuntime, kind: CredentialPrintKind, minExpiryMs?: number, signal?: AbortSignal): Promise<string>;
12
+ export {};
23
13
  //# sourceMappingURL=credential-print.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"credential-print.d.ts","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,cAAc,CAAC;AAI7D,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,oBAAqB,SAAQ,KAAK;CAAG;AAElD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAI7D;AAED,wBAAgB,wBAAwB,IAAI,IAAI,CAM/C;AAED,mFAAmF;AACnF,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,sBAAsB,GAAG,SAAS,CA+B9F;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAU5D;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC9C,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,mBAAmB,EACzB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CA+DjB","sourcesContent":["import type { Api, CredentialInfo, Model } from \"@earendil-works/pi-ai\";\nimport { APP_NAME } from \"../config.ts\";\nimport { resolveCliModel } from \"../core/model-resolver.ts\";\nimport type { ModelRuntime } from \"../core/model-runtime.ts\";\nimport type { Args } from \"./args.ts\";\n\nexport type CredentialPrintKind = \"api_key\" | \"bearer_token\";\n\nconst DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;\n\nexport interface CredentialPrintCommand {\n\tkind: CredentialPrintKind;\n\targs: string[];\n\tminExpiryMs?: number;\n}\n\nexport class CredentialPrintError extends Error {}\n\nexport function isCredentialPrintHelp(args: string[]): boolean {\n\treturn (\n\t\targs[0] === \"auth\" && (args[1] === undefined || args[1] === \"help\" || args[1] === \"--help\" || args[1] === \"-h\")\n\t);\n}\n\nexport function printCredentialPrintHelp(): void {\n\tconsole.log(`Usage:\n ${APP_NAME} auth print-api-key --model <model> [--provider <provider>]\n ${APP_NAME} auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]\n\nPrints the configured credential alone on stdout. Provider inference uses configured credentials; specify --provider to select explicitly. Bearer tokens have a 30-minute minimum expiry by default. --min-expiry accepts ms, s, m, or h (for example, 30m).`);\n}\n\n/** Parse the small, extensible `pi auth` command surface before normal startup. */\nexport function parseCredentialPrintCommand(args: string[]): CredentialPrintCommand | undefined {\n\tif (args[0] !== \"auth\") return undefined;\n\n\tconst kind = args[1] === \"print-api-key\" ? \"api_key\" : args[1] === \"print-bearer-token\" ? \"bearer_token\" : undefined;\n\tif (!kind) {\n\t\tthrow new CredentialPrintError(\n\t\t\t`Unknown auth command \"${args[1] ?? \"\"}\". Use \"${APP_NAME} auth print-api-key\" or \"${APP_NAME} auth print-bearer-token\".`,\n\t\t);\n\t}\n\n\tconst commandArgs: string[] = [];\n\tlet minExpiryMs: number | undefined;\n\tfor (let index = 2; index < args.length; index++) {\n\t\tif (args[index] !== \"--min-expiry\") {\n\t\t\tcommandArgs.push(args[index]);\n\t\t\tcontinue;\n\t\t}\n\t\tif (kind !== \"bearer_token\") {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry is only supported by print-bearer-token\");\n\t\t}\n\t\tconst value = args[++index];\n\t\tconst match = value ? /^(\\d+)(ms|s|m|h)$/iu.exec(value) : undefined;\n\t\tif (!match) {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry must use a duration such as 30m or 1h\");\n\t\t}\n\t\tconst amount = Number(match[1]);\n\t\tconst unit = match[2];\n\t\tminExpiryMs = amount * (unit === \"ms\" ? 1 : unit === \"s\" ? 1_000 : unit === \"m\" ? 60_000 : 3_600_000);\n\t}\n\n\treturn minExpiryMs === undefined ? { kind, args: commandArgs } : { kind, args: commandArgs, minExpiryMs };\n}\n\nexport function validateCredentialPrintArgs(args: Args): void {\n\tif (!args.model?.trim()) {\n\t\tthrow new CredentialPrintError(\"Credential printing requires --model <model>\");\n\t}\n\tif (args.apiKey !== undefined) {\n\t\tthrow new CredentialPrintError(\"Credential printing reads configured credentials; --api-key is not supported\");\n\t}\n\tif (args.messages.length > 0 || args.fileArgs.length > 0 || args.unknownFlags.size > 0) {\n\t\tthrow new CredentialPrintError(\"Credential printing only accepts --provider and --model\");\n\t}\n}\n\n/**\n * Resolve one request credential for a specific provider/model pair.\n *\n * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists\n * OAuth credentials with less than five minutes remaining through the normal request-auth path.\n */\nexport async function resolveCredentialForPrint(\n\targs: Args,\n\tmodelRuntime: ModelRuntime,\n\tkind: CredentialPrintKind,\n\tminExpiryMs?: number,\n): Promise<string> {\n\tvalidateCredentialPrintArgs(args);\n\n\tconst credentialTypes = new Map<string, CredentialInfo[\"type\"]>(\n\t\t(await modelRuntime.listCredentials()).map((credential) => [credential.providerId, credential.type]),\n\t);\n\tconst models: Model<Api>[] = [];\n\tif (args.provider) {\n\t\tconst resolved = resolveCliModel({ cliProvider: args.provider, cliModel: args.model, modelRuntime });\n\t\tif (resolved.error || !resolved.model) {\n\t\t\tthrow new CredentialPrintError(resolved.error ?? \"Unable to resolve the requested provider/model\");\n\t\t}\n\t\tmodels.push(resolved.model);\n\t} else {\n\t\tfor (const provider of modelRuntime.getProviders()) {\n\t\t\tif (!credentialTypes.has(provider.id)) continue;\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel: args.model, modelRuntime });\n\t\t\tif (resolved.model && !resolved.error && !resolved.warning?.includes(\"Using custom model id\")) {\n\t\t\t\tmodels.push(resolved.model);\n\t\t\t}\n\t\t}\n\t\tif (models.length === 0) {\n\t\t\tthrow new CredentialPrintError(`Model \"${args.model}\" not found. Use --list-models to see available models.`);\n\t\t}\n\t}\n\n\tconst credentials: Array<{ providerId: string; value: string }> = [];\n\tfor (const model of models) {\n\t\tconst type = credentialTypes.get(model.provider);\n\t\tif (kind === \"api_key\" && type === \"oauth\") continue;\n\t\tif (kind === \"bearer_token\" && type !== \"oauth\") continue;\n\n\t\tconst auth = await modelRuntime.getAuth(\n\t\t\tmodel,\n\t\t\tkind === \"bearer_token\"\n\t\t\t\t? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS }\n\t\t\t\t: undefined,\n\t\t);\n\t\tconst authorization = Object.entries(auth?.auth.headers ?? {}).find(\n\t\t\t([name]) => name.toLowerCase() === \"authorization\",\n\t\t)?.[1];\n\t\tconst bearerToken = typeof authorization === \"string\" ? /^Bearer\\s+(.+)$/iu.exec(authorization)?.[1] : undefined;\n\t\tconst value = kind === \"bearer_token\" ? (auth?.auth.apiKey ?? bearerToken) : auth?.auth.apiKey;\n\t\tif (value) credentials.push({ providerId: model.provider, value });\n\t}\n\n\tif (credentials.length === 1) return credentials[0].value;\n\tif (credentials.length === 0) {\n\t\tconst providerId = models[0]?.provider;\n\t\tconst type = providerId ? credentialTypes.get(providerId) : undefined;\n\t\tif (args.provider && kind === \"api_key\" && type === \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is configured with OAuth, not an API key`);\n\t\t}\n\t\tif (args.provider && kind === \"bearer_token\" && type !== \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is not configured with an OAuth bearer token`);\n\t\t}\n\t\tthrow new CredentialPrintError(\n\t\t\t`No usable ${kind === \"api_key\" ? \"API key\" : \"OAuth bearer token\"} is configured`,\n\t\t);\n\t}\n\tthrow new CredentialPrintError(\n\t\t`Model \"${args.model}\" has multiple configured providers (${credentials.map(({ providerId }) => providerId).join(\", \")}). Specify --provider.`,\n\t);\n}\n"]}
1
+ {"version":3,"file":"credential-print.d.ts","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAoB,KAAK,eAAe,EAA8C,MAAM,mBAAmB,CAAC;AAIvH,KAAK,mBAAmB,GAAG,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAE7D;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC9C,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,mBAAmB,EACzB,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CAgEjB","sourcesContent":["import type { Api, CredentialInfo, Model } from \"@earendil-works/pi-ai\";\nimport { resolveCliModel } from \"../core/model-resolver.ts\";\nimport type { ModelRuntime } from \"../core/model-runtime.ts\";\nimport type { Args } from \"./args.ts\";\nimport { AuthCommandError, type AuthCommandKind, getAuthCredential, validateAuthCommandArgs } from \"./auth-command.ts\";\n\nconst DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;\n\ntype CredentialPrintKind = Exclude<AuthCommandKind, \"check\">;\n\n/**\n * Resolve one configured provider credential.\n *\n * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists\n * OAuth credentials with less than five minutes remaining through the normal request-auth path.\n */\nexport async function resolveCredentialForPrint(\n\targs: Args,\n\tmodelRuntime: ModelRuntime,\n\tkind: CredentialPrintKind,\n\tminExpiryMs?: number,\n\tsignal?: AbortSignal,\n): Promise<string> {\n\tconst { provider: cliProvider, model: cliModel } = validateAuthCommandArgs(args, kind);\n\tconst credentialTypes = new Map<string, CredentialInfo[\"type\"]>(\n\t\t(await modelRuntime.listCredentials({ signal })).map((credential) => [credential.providerId, credential.type]),\n\t);\n\tconst providers: Array<{ id: string; model?: Model<Api> }> = [];\n\tif (cliProvider) {\n\t\tconst provider = modelRuntime.getProvider(cliProvider);\n\t\tif (!provider) {\n\t\t\tthrow new AuthCommandError(`Unknown provider \"${cliProvider}\". Use --list-models to see available providers.`);\n\t\t}\n\t\tif (cliModel) {\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel, modelRuntime });\n\t\t\tif (resolved.error || !resolved.model) {\n\t\t\t\tthrow new AuthCommandError(resolved.error ?? \"Unable to resolve the requested provider/model\");\n\t\t\t}\n\t\t\tproviders.push({ id: provider.id, model: resolved.model });\n\t\t} else {\n\t\t\tproviders.push({ id: provider.id });\n\t\t}\n\t} else {\n\t\tfor (const provider of modelRuntime.getProviders()) {\n\t\t\tif (!credentialTypes.has(provider.id)) continue;\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel: cliModel!, modelRuntime });\n\t\t\tif (resolved.model && !resolved.error && !resolved.warning?.includes(\"Using custom model id\")) {\n\t\t\t\tproviders.push({ id: provider.id, model: resolved.model });\n\t\t\t}\n\t\t}\n\t\tif (providers.length === 0) {\n\t\t\tthrow new AuthCommandError(`Model \"${cliModel}\" not found. Use --list-models to see available models.`);\n\t\t}\n\t}\n\n\tconst credentials: Array<{ providerId: string; value: string }> = [];\n\tfor (const provider of providers) {\n\t\tconst type = credentialTypes.get(provider.id);\n\t\tif (kind === \"api_key\" && type === \"oauth\") continue;\n\t\tif (kind === \"bearer_token\" && type !== \"oauth\") continue;\n\t\tconst authOptions = {\n\t\t\t...(kind === \"bearer_token\" ? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS } : {}),\n\t\t\tsignal,\n\t\t};\n\t\tconst auth = provider.model\n\t\t\t? await modelRuntime.getAuth(provider.model, authOptions)\n\t\t\t: await modelRuntime.getAuth(provider.id, authOptions);\n\t\tconst value = getAuthCredential(auth);\n\t\tif (value) credentials.push({ providerId: provider.id, value });\n\t}\n\n\tif (credentials.length === 1) return credentials[0].value;\n\tif (credentials.length === 0) {\n\t\tconst providerId = providers[0]?.id;\n\t\tconst type = providerId ? credentialTypes.get(providerId) : undefined;\n\t\tif (cliProvider && kind === \"api_key\" && type === \"oauth\") {\n\t\t\tthrow new AuthCommandError(`Provider \"${providerId}\" is configured with OAuth, not an API key`);\n\t\t}\n\t\tif (cliProvider && kind === \"bearer_token\" && type !== \"oauth\") {\n\t\t\tthrow new AuthCommandError(`Provider \"${providerId}\" is not configured with an OAuth bearer token`);\n\t\t}\n\t\tthrow new AuthCommandError(`No usable ${kind === \"api_key\" ? \"API key\" : \"OAuth bearer token\"} is configured`);\n\t}\n\tthrow new AuthCommandError(\n\t\t`Multiple configured providers matched (${credentials.map(({ providerId }) => providerId).join(\", \")}). Specify --provider.`,\n\t);\n}\n"]}
@@ -1,117 +1,76 @@
1
- import { APP_NAME } from "../config.js";
2
1
  import { resolveCliModel } from "../core/model-resolver.js";
2
+ import { AuthCommandError, getAuthCredential, validateAuthCommandArgs } from "./auth-command.js";
3
3
  const DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;
4
- export class CredentialPrintError extends Error {
5
- }
6
- export function isCredentialPrintHelp(args) {
7
- return (args[0] === "auth" && (args[1] === undefined || args[1] === "help" || args[1] === "--help" || args[1] === "-h"));
8
- }
9
- export function printCredentialPrintHelp() {
10
- console.log(`Usage:
11
- ${APP_NAME} auth print-api-key --model <model> [--provider <provider>]
12
- ${APP_NAME} auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]
13
-
14
- Prints the configured credential alone on stdout. Provider inference uses configured credentials; specify --provider to select explicitly. Bearer tokens have a 30-minute minimum expiry by default. --min-expiry accepts ms, s, m, or h (for example, 30m).`);
15
- }
16
- /** Parse the small, extensible `pi auth` command surface before normal startup. */
17
- export function parseCredentialPrintCommand(args) {
18
- if (args[0] !== "auth")
19
- return undefined;
20
- const kind = args[1] === "print-api-key" ? "api_key" : args[1] === "print-bearer-token" ? "bearer_token" : undefined;
21
- if (!kind) {
22
- throw new CredentialPrintError(`Unknown auth command "${args[1] ?? ""}". Use "${APP_NAME} auth print-api-key" or "${APP_NAME} auth print-bearer-token".`);
23
- }
24
- const commandArgs = [];
25
- let minExpiryMs;
26
- for (let index = 2; index < args.length; index++) {
27
- if (args[index] !== "--min-expiry") {
28
- commandArgs.push(args[index]);
29
- continue;
30
- }
31
- if (kind !== "bearer_token") {
32
- throw new CredentialPrintError("--min-expiry is only supported by print-bearer-token");
33
- }
34
- const value = args[++index];
35
- const match = value ? /^(\d+)(ms|s|m|h)$/iu.exec(value) : undefined;
36
- if (!match) {
37
- throw new CredentialPrintError("--min-expiry must use a duration such as 30m or 1h");
38
- }
39
- const amount = Number(match[1]);
40
- const unit = match[2];
41
- minExpiryMs = amount * (unit === "ms" ? 1 : unit === "s" ? 1_000 : unit === "m" ? 60_000 : 3_600_000);
42
- }
43
- return minExpiryMs === undefined ? { kind, args: commandArgs } : { kind, args: commandArgs, minExpiryMs };
44
- }
45
- export function validateCredentialPrintArgs(args) {
46
- if (!args.model?.trim()) {
47
- throw new CredentialPrintError("Credential printing requires --model <model>");
48
- }
49
- if (args.apiKey !== undefined) {
50
- throw new CredentialPrintError("Credential printing reads configured credentials; --api-key is not supported");
51
- }
52
- if (args.messages.length > 0 || args.fileArgs.length > 0 || args.unknownFlags.size > 0) {
53
- throw new CredentialPrintError("Credential printing only accepts --provider and --model");
54
- }
55
- }
56
4
  /**
57
- * Resolve one request credential for a specific provider/model pair.
5
+ * Resolve one configured provider credential.
58
6
  *
59
7
  * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists
60
8
  * OAuth credentials with less than five minutes remaining through the normal request-auth path.
61
9
  */
62
- export async function resolveCredentialForPrint(args, modelRuntime, kind, minExpiryMs) {
63
- validateCredentialPrintArgs(args);
64
- const credentialTypes = new Map((await modelRuntime.listCredentials()).map((credential) => [credential.providerId, credential.type]));
65
- const models = [];
66
- if (args.provider) {
67
- const resolved = resolveCliModel({ cliProvider: args.provider, cliModel: args.model, modelRuntime });
68
- if (resolved.error || !resolved.model) {
69
- throw new CredentialPrintError(resolved.error ?? "Unable to resolve the requested provider/model");
10
+ export async function resolveCredentialForPrint(args, modelRuntime, kind, minExpiryMs, signal) {
11
+ const { provider: cliProvider, model: cliModel } = validateAuthCommandArgs(args, kind);
12
+ const credentialTypes = new Map((await modelRuntime.listCredentials({ signal })).map((credential) => [credential.providerId, credential.type]));
13
+ const providers = [];
14
+ if (cliProvider) {
15
+ const provider = modelRuntime.getProvider(cliProvider);
16
+ if (!provider) {
17
+ throw new AuthCommandError(`Unknown provider "${cliProvider}". Use --list-models to see available providers.`);
18
+ }
19
+ if (cliModel) {
20
+ const resolved = resolveCliModel({ cliProvider: provider.id, cliModel, modelRuntime });
21
+ if (resolved.error || !resolved.model) {
22
+ throw new AuthCommandError(resolved.error ?? "Unable to resolve the requested provider/model");
23
+ }
24
+ providers.push({ id: provider.id, model: resolved.model });
25
+ }
26
+ else {
27
+ providers.push({ id: provider.id });
70
28
  }
71
- models.push(resolved.model);
72
29
  }
73
30
  else {
74
31
  for (const provider of modelRuntime.getProviders()) {
75
32
  if (!credentialTypes.has(provider.id))
76
33
  continue;
77
- const resolved = resolveCliModel({ cliProvider: provider.id, cliModel: args.model, modelRuntime });
34
+ const resolved = resolveCliModel({ cliProvider: provider.id, cliModel: cliModel, modelRuntime });
78
35
  if (resolved.model && !resolved.error && !resolved.warning?.includes("Using custom model id")) {
79
- models.push(resolved.model);
36
+ providers.push({ id: provider.id, model: resolved.model });
80
37
  }
81
38
  }
82
- if (models.length === 0) {
83
- throw new CredentialPrintError(`Model "${args.model}" not found. Use --list-models to see available models.`);
39
+ if (providers.length === 0) {
40
+ throw new AuthCommandError(`Model "${cliModel}" not found. Use --list-models to see available models.`);
84
41
  }
85
42
  }
86
43
  const credentials = [];
87
- for (const model of models) {
88
- const type = credentialTypes.get(model.provider);
44
+ for (const provider of providers) {
45
+ const type = credentialTypes.get(provider.id);
89
46
  if (kind === "api_key" && type === "oauth")
90
47
  continue;
91
48
  if (kind === "bearer_token" && type !== "oauth")
92
49
  continue;
93
- const auth = await modelRuntime.getAuth(model, kind === "bearer_token"
94
- ? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS }
95
- : undefined);
96
- const authorization = Object.entries(auth?.auth.headers ?? {}).find(([name]) => name.toLowerCase() === "authorization")?.[1];
97
- const bearerToken = typeof authorization === "string" ? /^Bearer\s+(.+)$/iu.exec(authorization)?.[1] : undefined;
98
- const value = kind === "bearer_token" ? (auth?.auth.apiKey ?? bearerToken) : auth?.auth.apiKey;
50
+ const authOptions = {
51
+ ...(kind === "bearer_token" ? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS } : {}),
52
+ signal,
53
+ };
54
+ const auth = provider.model
55
+ ? await modelRuntime.getAuth(provider.model, authOptions)
56
+ : await modelRuntime.getAuth(provider.id, authOptions);
57
+ const value = getAuthCredential(auth);
99
58
  if (value)
100
- credentials.push({ providerId: model.provider, value });
59
+ credentials.push({ providerId: provider.id, value });
101
60
  }
102
61
  if (credentials.length === 1)
103
62
  return credentials[0].value;
104
63
  if (credentials.length === 0) {
105
- const providerId = models[0]?.provider;
64
+ const providerId = providers[0]?.id;
106
65
  const type = providerId ? credentialTypes.get(providerId) : undefined;
107
- if (args.provider && kind === "api_key" && type === "oauth") {
108
- throw new CredentialPrintError(`Provider "${providerId}" is configured with OAuth, not an API key`);
66
+ if (cliProvider && kind === "api_key" && type === "oauth") {
67
+ throw new AuthCommandError(`Provider "${providerId}" is configured with OAuth, not an API key`);
109
68
  }
110
- if (args.provider && kind === "bearer_token" && type !== "oauth") {
111
- throw new CredentialPrintError(`Provider "${providerId}" is not configured with an OAuth bearer token`);
69
+ if (cliProvider && kind === "bearer_token" && type !== "oauth") {
70
+ throw new AuthCommandError(`Provider "${providerId}" is not configured with an OAuth bearer token`);
112
71
  }
113
- throw new CredentialPrintError(`No usable ${kind === "api_key" ? "API key" : "OAuth bearer token"} is configured`);
72
+ throw new AuthCommandError(`No usable ${kind === "api_key" ? "API key" : "OAuth bearer token"} is configured`);
114
73
  }
115
- throw new CredentialPrintError(`Model "${args.model}" has multiple configured providers (${credentials.map(({ providerId }) => providerId).join(", ")}). Specify --provider.`);
74
+ throw new AuthCommandError(`Multiple configured providers matched (${credentials.map(({ providerId }) => providerId).join(", ")}). Specify --provider.`);
116
75
  }
117
76
  //# sourceMappingURL=credential-print.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"credential-print.js","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D,MAAM,kCAAkC,GAAG,EAAE,GAAG,MAAM,CAAC;AAQvD,MAAM,OAAO,oBAAqB,SAAQ,KAAK;CAAG;AAElD,MAAM,UAAU,qBAAqB,CAAC,IAAc,EAAW;IAC9D,OAAO,CACN,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAC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import { APP_NAME } from \"../config.ts\";\nimport { resolveCliModel } from \"../core/model-resolver.ts\";\nimport type { ModelRuntime } from \"../core/model-runtime.ts\";\nimport type { Args } from \"./args.ts\";\n\nexport type CredentialPrintKind = \"api_key\" | \"bearer_token\";\n\nconst DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;\n\nexport interface CredentialPrintCommand {\n\tkind: CredentialPrintKind;\n\targs: string[];\n\tminExpiryMs?: number;\n}\n\nexport class CredentialPrintError extends Error {}\n\nexport function isCredentialPrintHelp(args: string[]): boolean {\n\treturn (\n\t\targs[0] === \"auth\" && (args[1] === undefined || args[1] === \"help\" || args[1] === \"--help\" || args[1] === \"-h\")\n\t);\n}\n\nexport function printCredentialPrintHelp(): void {\n\tconsole.log(`Usage:\n ${APP_NAME} auth print-api-key --model <model> [--provider <provider>]\n ${APP_NAME} auth print-bearer-token --model <model> [--provider <provider>] [--min-expiry <duration>]\n\nPrints the configured credential alone on stdout. Provider inference uses configured credentials; specify --provider to select explicitly. Bearer tokens have a 30-minute minimum expiry by default. --min-expiry accepts ms, s, m, or h (for example, 30m).`);\n}\n\n/** Parse the small, extensible `pi auth` command surface before normal startup. */\nexport function parseCredentialPrintCommand(args: string[]): CredentialPrintCommand | undefined {\n\tif (args[0] !== \"auth\") return undefined;\n\n\tconst kind = args[1] === \"print-api-key\" ? \"api_key\" : args[1] === \"print-bearer-token\" ? \"bearer_token\" : undefined;\n\tif (!kind) {\n\t\tthrow new CredentialPrintError(\n\t\t\t`Unknown auth command \"${args[1] ?? \"\"}\". Use \"${APP_NAME} auth print-api-key\" or \"${APP_NAME} auth print-bearer-token\".`,\n\t\t);\n\t}\n\n\tconst commandArgs: string[] = [];\n\tlet minExpiryMs: number | undefined;\n\tfor (let index = 2; index < args.length; index++) {\n\t\tif (args[index] !== \"--min-expiry\") {\n\t\t\tcommandArgs.push(args[index]);\n\t\t\tcontinue;\n\t\t}\n\t\tif (kind !== \"bearer_token\") {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry is only supported by print-bearer-token\");\n\t\t}\n\t\tconst value = args[++index];\n\t\tconst match = value ? /^(\\d+)(ms|s|m|h)$/iu.exec(value) : undefined;\n\t\tif (!match) {\n\t\t\tthrow new CredentialPrintError(\"--min-expiry must use a duration such as 30m or 1h\");\n\t\t}\n\t\tconst amount = Number(match[1]);\n\t\tconst unit = match[2];\n\t\tminExpiryMs = amount * (unit === \"ms\" ? 1 : unit === \"s\" ? 1_000 : unit === \"m\" ? 60_000 : 3_600_000);\n\t}\n\n\treturn minExpiryMs === undefined ? { kind, args: commandArgs } : { kind, args: commandArgs, minExpiryMs };\n}\n\nexport function validateCredentialPrintArgs(args: Args): void {\n\tif (!args.model?.trim()) {\n\t\tthrow new CredentialPrintError(\"Credential printing requires --model <model>\");\n\t}\n\tif (args.apiKey !== undefined) {\n\t\tthrow new CredentialPrintError(\"Credential printing reads configured credentials; --api-key is not supported\");\n\t}\n\tif (args.messages.length > 0 || args.fileArgs.length > 0 || args.unknownFlags.size > 0) {\n\t\tthrow new CredentialPrintError(\"Credential printing only accepts --provider and --model\");\n\t}\n}\n\n/**\n * Resolve one request credential for a specific provider/model pair.\n *\n * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists\n * OAuth credentials with less than five minutes remaining through the normal request-auth path.\n */\nexport async function resolveCredentialForPrint(\n\targs: Args,\n\tmodelRuntime: ModelRuntime,\n\tkind: CredentialPrintKind,\n\tminExpiryMs?: number,\n): Promise<string> {\n\tvalidateCredentialPrintArgs(args);\n\n\tconst credentialTypes = new Map<string, CredentialInfo[\"type\"]>(\n\t\t(await modelRuntime.listCredentials()).map((credential) => [credential.providerId, credential.type]),\n\t);\n\tconst models: Model<Api>[] = [];\n\tif (args.provider) {\n\t\tconst resolved = resolveCliModel({ cliProvider: args.provider, cliModel: args.model, modelRuntime });\n\t\tif (resolved.error || !resolved.model) {\n\t\t\tthrow new CredentialPrintError(resolved.error ?? \"Unable to resolve the requested provider/model\");\n\t\t}\n\t\tmodels.push(resolved.model);\n\t} else {\n\t\tfor (const provider of modelRuntime.getProviders()) {\n\t\t\tif (!credentialTypes.has(provider.id)) continue;\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel: args.model, modelRuntime });\n\t\t\tif (resolved.model && !resolved.error && !resolved.warning?.includes(\"Using custom model id\")) {\n\t\t\t\tmodels.push(resolved.model);\n\t\t\t}\n\t\t}\n\t\tif (models.length === 0) {\n\t\t\tthrow new CredentialPrintError(`Model \"${args.model}\" not found. Use --list-models to see available models.`);\n\t\t}\n\t}\n\n\tconst credentials: Array<{ providerId: string; value: string }> = [];\n\tfor (const model of models) {\n\t\tconst type = credentialTypes.get(model.provider);\n\t\tif (kind === \"api_key\" && type === \"oauth\") continue;\n\t\tif (kind === \"bearer_token\" && type !== \"oauth\") continue;\n\n\t\tconst auth = await modelRuntime.getAuth(\n\t\t\tmodel,\n\t\t\tkind === \"bearer_token\"\n\t\t\t\t? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS }\n\t\t\t\t: undefined,\n\t\t);\n\t\tconst authorization = Object.entries(auth?.auth.headers ?? {}).find(\n\t\t\t([name]) => name.toLowerCase() === \"authorization\",\n\t\t)?.[1];\n\t\tconst bearerToken = typeof authorization === \"string\" ? /^Bearer\\s+(.+)$/iu.exec(authorization)?.[1] : undefined;\n\t\tconst value = kind === \"bearer_token\" ? (auth?.auth.apiKey ?? bearerToken) : auth?.auth.apiKey;\n\t\tif (value) credentials.push({ providerId: model.provider, value });\n\t}\n\n\tif (credentials.length === 1) return credentials[0].value;\n\tif (credentials.length === 0) {\n\t\tconst providerId = models[0]?.provider;\n\t\tconst type = providerId ? credentialTypes.get(providerId) : undefined;\n\t\tif (args.provider && kind === \"api_key\" && type === \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is configured with OAuth, not an API key`);\n\t\t}\n\t\tif (args.provider && kind === \"bearer_token\" && type !== \"oauth\") {\n\t\t\tthrow new CredentialPrintError(`Provider \"${providerId}\" is not configured with an OAuth bearer token`);\n\t\t}\n\t\tthrow new CredentialPrintError(\n\t\t\t`No usable ${kind === \"api_key\" ? \"API key\" : \"OAuth bearer token\"} is configured`,\n\t\t);\n\t}\n\tthrow new CredentialPrintError(\n\t\t`Model \"${args.model}\" has multiple configured providers (${credentials.map(({ providerId }) => providerId).join(\", \")}). Specify --provider.`,\n\t);\n}\n"]}
1
+ {"version":3,"file":"credential-print.js","sourceRoot":"","sources":["../../src/cli/credential-print.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAwB,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEvH,MAAM,kCAAkC,GAAG,EAAE,GAAG,MAAM,CAAC;AAIvD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,IAAU,EACV,YAA0B,EAC1B,IAAyB,EACzB,WAAoB,EACpB,MAAoB,EACF;IAClB,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,uBAAuB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvF,MAAM,eAAe,GAAG,IAAI,GAAG,CAC9B,CAAC,MAAM,YAAY,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAC9G,CAAC;IACF,MAAM,SAAS,GAA8C,EAAE,CAAC;IAChE,IAAI,WAAW,EAAE,CAAC;QACjB,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,gBAAgB,CAAC,qBAAqB,WAAW,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AAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACtE,IAAI,WAAW,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3D,MAAM,IAAI,gBAAgB,CAAC,aAAa,UAAU,4CAA4C,CAAC,CAAC;QACjG,CAAC;QACD,IAAI,WAAW,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YAChE,MAAM,IAAI,gBAAgB,CAAC,aAAa,UAAU,gDAAgD,CAAC,CAAC;QACrG,CAAC;QACD,MAAM,IAAI,gBAAgB,CAAC,aAAa,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB,gBAAgB,CAAC,CAAC;IAChH,CAAC;IACD,MAAM,IAAI,gBAAgB,CACzB,0CAA0C,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAC5H,CAAC;AAAA,CACF","sourcesContent":["import type { Api, CredentialInfo, Model } from \"@earendil-works/pi-ai\";\nimport { resolveCliModel } from \"../core/model-resolver.ts\";\nimport type { ModelRuntime } from \"../core/model-runtime.ts\";\nimport type { Args } from \"./args.ts\";\nimport { AuthCommandError, type AuthCommandKind, getAuthCredential, validateAuthCommandArgs } from \"./auth-command.ts\";\n\nconst DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS = 30 * 60_000;\n\ntype CredentialPrintKind = Exclude<AuthCommandKind, \"check\">;\n\n/**\n * Resolve one configured provider credential.\n *\n * This intentionally calls ModelRuntime.getAuth(), which refreshes and persists\n * OAuth credentials with less than five minutes remaining through the normal request-auth path.\n */\nexport async function resolveCredentialForPrint(\n\targs: Args,\n\tmodelRuntime: ModelRuntime,\n\tkind: CredentialPrintKind,\n\tminExpiryMs?: number,\n\tsignal?: AbortSignal,\n): Promise<string> {\n\tconst { provider: cliProvider, model: cliModel } = validateAuthCommandArgs(args, kind);\n\tconst credentialTypes = new Map<string, CredentialInfo[\"type\"]>(\n\t\t(await modelRuntime.listCredentials({ signal })).map((credential) => [credential.providerId, credential.type]),\n\t);\n\tconst providers: Array<{ id: string; model?: Model<Api> }> = [];\n\tif (cliProvider) {\n\t\tconst provider = modelRuntime.getProvider(cliProvider);\n\t\tif (!provider) {\n\t\t\tthrow new AuthCommandError(`Unknown provider \"${cliProvider}\". Use --list-models to see available providers.`);\n\t\t}\n\t\tif (cliModel) {\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel, modelRuntime });\n\t\t\tif (resolved.error || !resolved.model) {\n\t\t\t\tthrow new AuthCommandError(resolved.error ?? \"Unable to resolve the requested provider/model\");\n\t\t\t}\n\t\t\tproviders.push({ id: provider.id, model: resolved.model });\n\t\t} else {\n\t\t\tproviders.push({ id: provider.id });\n\t\t}\n\t} else {\n\t\tfor (const provider of modelRuntime.getProviders()) {\n\t\t\tif (!credentialTypes.has(provider.id)) continue;\n\t\t\tconst resolved = resolveCliModel({ cliProvider: provider.id, cliModel: cliModel!, modelRuntime });\n\t\t\tif (resolved.model && !resolved.error && !resolved.warning?.includes(\"Using custom model id\")) {\n\t\t\t\tproviders.push({ id: provider.id, model: resolved.model });\n\t\t\t}\n\t\t}\n\t\tif (providers.length === 0) {\n\t\t\tthrow new AuthCommandError(`Model \"${cliModel}\" not found. Use --list-models to see available models.`);\n\t\t}\n\t}\n\n\tconst credentials: Array<{ providerId: string; value: string }> = [];\n\tfor (const provider of providers) {\n\t\tconst type = credentialTypes.get(provider.id);\n\t\tif (kind === \"api_key\" && type === \"oauth\") continue;\n\t\tif (kind === \"bearer_token\" && type !== \"oauth\") continue;\n\t\tconst authOptions = {\n\t\t\t...(kind === \"bearer_token\" ? { minOAuthValidityMs: minExpiryMs ?? DEFAULT_BEARER_TOKEN_MIN_EXPIRY_MS } : {}),\n\t\t\tsignal,\n\t\t};\n\t\tconst auth = provider.model\n\t\t\t? await modelRuntime.getAuth(provider.model, authOptions)\n\t\t\t: await modelRuntime.getAuth(provider.id, authOptions);\n\t\tconst value = getAuthCredential(auth);\n\t\tif (value) credentials.push({ providerId: provider.id, value });\n\t}\n\n\tif (credentials.length === 1) return credentials[0].value;\n\tif (credentials.length === 0) {\n\t\tconst providerId = providers[0]?.id;\n\t\tconst type = providerId ? credentialTypes.get(providerId) : undefined;\n\t\tif (cliProvider && kind === \"api_key\" && type === \"oauth\") {\n\t\t\tthrow new AuthCommandError(`Provider \"${providerId}\" is configured with OAuth, not an API key`);\n\t\t}\n\t\tif (cliProvider && kind === \"bearer_token\" && type !== \"oauth\") {\n\t\t\tthrow new AuthCommandError(`Provider \"${providerId}\" is not configured with an OAuth bearer token`);\n\t\t}\n\t\tthrow new AuthCommandError(`No usable ${kind === \"api_key\" ? \"API key\" : \"OAuth bearer token\"} is configured`);\n\t}\n\tthrow new AuthCommandError(\n\t\t`Multiple configured providers matched (${credentials.map(({ providerId }) => providerId).join(\", \")}). Specify --provider.`,\n\t);\n}\n"]}
@@ -0,0 +1,16 @@
1
+ export type AuthInput = {
2
+ readonly type: "token";
3
+ readonly token: string;
4
+ } | {
5
+ readonly type: "file";
6
+ readonly path: string;
7
+ };
8
+ export interface RawAuthOptions {
9
+ readonly authToken?: string;
10
+ readonly authTokenFile?: string;
11
+ }
12
+ export declare function parseAuthInput(options: RawAuthOptions): {
13
+ auth?: AuthInput;
14
+ errors: string[];
15
+ };
16
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/cli/experimental/auth.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAW9F","sourcesContent":["export type AuthInput =\n\t| { readonly type: \"token\"; readonly token: string }\n\t| { readonly type: \"file\"; readonly path: string };\n\nexport interface RawAuthOptions {\n\treadonly authToken?: string;\n\treadonly authTokenFile?: string;\n}\n\nexport function parseAuthInput(options: RawAuthOptions): { auth?: AuthInput; errors: string[] } {\n\tif (options.authToken !== undefined && options.authTokenFile !== undefined) {\n\t\treturn { errors: [\"--auth-token and --auth-token-file are mutually exclusive\"] };\n\t}\n\tif (options.authToken !== undefined) {\n\t\treturn { auth: { type: \"token\", token: options.authToken }, errors: [] };\n\t}\n\tif (options.authTokenFile !== undefined) {\n\t\treturn { auth: { type: \"file\", path: options.authTokenFile }, errors: [] };\n\t}\n\treturn { errors: [] };\n}\n"]}
@@ -0,0 +1,13 @@
1
+ export function parseAuthInput(options) {
2
+ if (options.authToken !== undefined && options.authTokenFile !== undefined) {
3
+ return { errors: ["--auth-token and --auth-token-file are mutually exclusive"] };
4
+ }
5
+ if (options.authToken !== undefined) {
6
+ return { auth: { type: "token", token: options.authToken }, errors: [] };
7
+ }
8
+ if (options.authTokenFile !== undefined) {
9
+ return { auth: { type: "file", path: options.authTokenFile }, errors: [] };
10
+ }
11
+ return { errors: [] };
12
+ }
13
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/cli/experimental/auth.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,cAAc,CAAC,OAAuB,EAA0C;IAC/F,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QAC5E,OAAO,EAAE,MAAM,EAAE,CAAC,2DAA2D,CAAC,EAAE,CAAC;IAClF,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC1E,CAAC;IACD,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACzC,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC5E,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAAA,CACtB","sourcesContent":["export type AuthInput =\n\t| { readonly type: \"token\"; readonly token: string }\n\t| { readonly type: \"file\"; readonly path: string };\n\nexport interface RawAuthOptions {\n\treadonly authToken?: string;\n\treadonly authTokenFile?: string;\n}\n\nexport function parseAuthInput(options: RawAuthOptions): { auth?: AuthInput; errors: string[] } {\n\tif (options.authToken !== undefined && options.authTokenFile !== undefined) {\n\t\treturn { errors: [\"--auth-token and --auth-token-file are mutually exclusive\"] };\n\t}\n\tif (options.authToken !== undefined) {\n\t\treturn { auth: { type: \"token\", token: options.authToken }, errors: [] };\n\t}\n\tif (options.authTokenFile !== undefined) {\n\t\treturn { auth: { type: \"file\", path: options.authTokenFile }, errors: [] };\n\t}\n\treturn { errors: [] };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { type ClientCommandContext } from "./commands/client.ts";
2
+ import { type PiCommandContext } from "./commands/pi.ts";
3
+ import { type ServerCommandContext } from "./commands/server.ts";
4
+ export type ExperimentalCliContext = PiCommandContext & ServerCommandContext & ClientCommandContext;
5
+ export declare const experimentalCli: import("./command.ts").Command<import("./commands/pi.ts").PiCommand, PiCommandContext & ServerCommandContext & ClientCommandContext, import("./commands/client.ts").ClientCommand | import("./commands/pi.ts").PiCommand | import("./commands/server.ts").ServerCommand>;
6
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli/experimental/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,sBAAsB,CAAC;AAEhF,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AAEpG,eAAO,MAAM,eAAe,0QAA0D,CAAC","sourcesContent":["import { type ClientCommandContext, clientCommand } from \"./commands/client.ts\";\nimport { type PiCommandContext, piCommand } from \"./commands/pi.ts\";\nimport { type ServerCommandContext, serverCommand } from \"./commands/server.ts\";\n\nexport type ExperimentalCliContext = PiCommandContext & ServerCommandContext & ClientCommandContext;\n\nexport const experimentalCli = piCommand.command(serverCommand).command(clientCommand);\n"]}
@@ -0,0 +1,5 @@
1
+ import { clientCommand } from "./commands/client.js";
2
+ import { piCommand } from "./commands/pi.js";
3
+ import { serverCommand } from "./commands/server.js";
4
+ export const experimentalCli = piCommand.command(serverCommand).command(clientCommand);
5
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli/experimental/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAyB,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAA6B,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIhF,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC","sourcesContent":["import { type ClientCommandContext, clientCommand } from \"./commands/client.ts\";\nimport { type PiCommandContext, piCommand } from \"./commands/pi.ts\";\nimport { type ServerCommandContext, serverCommand } from \"./commands/server.ts\";\n\nexport type ExperimentalCliContext = PiCommandContext & ServerCommandContext & ClientCommandContext;\n\nexport const experimentalCli = piCommand.command(serverCommand).command(clientCommand);\n"]}
@@ -0,0 +1,17 @@
1
+ import { type Args } from "../args.ts";
2
+ import { type AuthInput } from "./auth.ts";
3
+ import { type CommandOption, type ParsedCommandInput } from "./command.ts";
4
+ import { type TransportAddress } from "./transport-address.ts";
5
+ export declare const authTokenOption: CommandOption<string>;
6
+ export declare const authTokenFileOption: CommandOption<string>;
7
+ export declare function transportOption(name: "--listen" | "--connect"): CommandOption<TransportAddress>;
8
+ export declare function parseAuth(input: ParsedCommandInput): {
9
+ auth?: AuthInput;
10
+ errors: string[];
11
+ };
12
+ export declare function parseLegacyOptions(input: ParsedCommandInput): {
13
+ options: Args;
14
+ errors: string[];
15
+ };
16
+ export declare function unsupportedLegacyOptions(command: string, input: ParsedCommandInput): string[];
17
+ //# sourceMappingURL=command-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-options.d.ts","sourceRoot":"","sources":["../../../src/cli/experimental/command-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,KAAK,SAAS,EAAkB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAA6B,MAAM,cAAc,CAAC;AACtG,OAAO,EAAyB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEtF,eAAO,MAAM,eAAe,uBAA+B,CAAC;AAC5D,eAAO,MAAM,mBAAmB,uBAAoC,CAAC;AAErE,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAO/F;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,kBAAkB,GAAG;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAK3F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAQjG;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAG7F","sourcesContent":["import { type Args, parseArgs } from \"../args.ts\";\nimport { type AuthInput, parseAuthInput } from \"./auth.ts\";\nimport { type CommandOption, type ParsedCommandInput, stringOption, valueOption } from \"./command.ts\";\nimport { parseTransportAddress, type TransportAddress } from \"./transport-address.ts\";\n\nexport const authTokenOption = stringOption(\"--auth-token\");\nexport const authTokenFileOption = stringOption(\"--auth-token-file\");\n\nexport function transportOption(name: \"--listen\" | \"--connect\"): CommandOption<TransportAddress> {\n\treturn valueOption(name, (value) => {\n\t\tconst result = parseTransportAddress(value, name);\n\t\treturn result.address\n\t\t\t? { ok: true, value: result.address }\n\t\t\t: { ok: false, error: result.error ?? `Invalid ${name} address \"${value}\"` };\n\t});\n}\n\nexport function parseAuth(input: ParsedCommandInput): { auth?: AuthInput; errors: string[] } {\n\treturn parseAuthInput({\n\t\tauthToken: input.value(authTokenOption),\n\t\tauthTokenFile: input.value(authTokenFileOption),\n\t});\n}\n\nexport function parseLegacyOptions(input: ParsedCommandInput): { options: Args; errors: string[] } {\n\tconst options = parseArgs([...input.remainingArgs]);\n\treturn {\n\t\toptions,\n\t\terrors: options.diagnostics\n\t\t\t.filter((diagnostic) => diagnostic.type === \"error\")\n\t\t\t.map((diagnostic) => diagnostic.message),\n\t};\n}\n\nexport function unsupportedLegacyOptions(command: string, input: ParsedCommandInput): string[] {\n\tif (input.remainingArgs.length === 0) return [];\n\treturn [`The experimental ${command} command does not support existing CLI options yet`];\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { parseArgs } from "../args.js";
2
+ import { parseAuthInput } from "./auth.js";
3
+ import { stringOption, valueOption } from "./command.js";
4
+ import { parseTransportAddress } from "./transport-address.js";
5
+ export const authTokenOption = stringOption("--auth-token");
6
+ export const authTokenFileOption = stringOption("--auth-token-file");
7
+ export function transportOption(name) {
8
+ return valueOption(name, (value) => {
9
+ const result = parseTransportAddress(value, name);
10
+ return result.address
11
+ ? { ok: true, value: result.address }
12
+ : { ok: false, error: result.error ?? `Invalid ${name} address "${value}"` };
13
+ });
14
+ }
15
+ export function parseAuth(input) {
16
+ return parseAuthInput({
17
+ authToken: input.value(authTokenOption),
18
+ authTokenFile: input.value(authTokenFileOption),
19
+ });
20
+ }
21
+ export function parseLegacyOptions(input) {
22
+ const options = parseArgs([...input.remainingArgs]);
23
+ return {
24
+ options,
25
+ errors: options.diagnostics
26
+ .filter((diagnostic) => diagnostic.type === "error")
27
+ .map((diagnostic) => diagnostic.message),
28
+ };
29
+ }
30
+ export function unsupportedLegacyOptions(command, input) {
31
+ if (input.remainingArgs.length === 0)
32
+ return [];
33
+ return [`The experimental ${command} command does not support existing CLI options yet`];
34
+ }
35
+ //# sourceMappingURL=command-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-options.js","sourceRoot":"","sources":["../../../src/cli/experimental/command-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAkB,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAA+C,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtG,OAAO,EAAE,qBAAqB,EAAyB,MAAM,wBAAwB,CAAC;AA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,IAAI,KAAK,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChD,OAAO,CAAC,oBAAoB,OAAO,oDAAoD,CAAC,CAAC;AAAA,CACzF","sourcesContent":["import { type Args, parseArgs } from \"../args.ts\";\nimport { type AuthInput, parseAuthInput } from \"./auth.ts\";\nimport { type CommandOption, type ParsedCommandInput, stringOption, valueOption } from \"./command.ts\";\nimport { parseTransportAddress, type TransportAddress } from \"./transport-address.ts\";\n\nexport const authTokenOption = stringOption(\"--auth-token\");\nexport const authTokenFileOption = stringOption(\"--auth-token-file\");\n\nexport function transportOption(name: \"--listen\" | \"--connect\"): CommandOption<TransportAddress> {\n\treturn valueOption(name, (value) => {\n\t\tconst result = parseTransportAddress(value, name);\n\t\treturn result.address\n\t\t\t? { ok: true, value: result.address }\n\t\t\t: { ok: false, error: result.error ?? `Invalid ${name} address \"${value}\"` };\n\t});\n}\n\nexport function parseAuth(input: ParsedCommandInput): { auth?: AuthInput; errors: string[] } {\n\treturn parseAuthInput({\n\t\tauthToken: input.value(authTokenOption),\n\t\tauthTokenFile: input.value(authTokenFileOption),\n\t});\n}\n\nexport function parseLegacyOptions(input: ParsedCommandInput): { options: Args; errors: string[] } {\n\tconst options = parseArgs([...input.remainingArgs]);\n\treturn {\n\t\toptions,\n\t\terrors: options.diagnostics\n\t\t\t.filter((diagnostic) => diagnostic.type === \"error\")\n\t\t\t.map((diagnostic) => diagnostic.message),\n\t};\n}\n\nexport function unsupportedLegacyOptions(command: string, input: ParsedCommandInput): string[] {\n\tif (input.remainingArgs.length === 0) return [];\n\treturn [`The experimental ${command} command does not support existing CLI options yet`];\n}\n"]}