@earendil-works/pi-coding-agent 0.85.0 → 0.86.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (544) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +2 -3
  3. package/dist/bun/cli.d.ts +3 -1
  4. package/dist/bun/cli.d.ts.map +1 -1
  5. package/dist/bun/cli.js +3 -12
  6. package/dist/bun/cli.js.map +1 -1
  7. package/dist/bun/sandbox-env-setup.d.ts +2 -0
  8. package/dist/bun/sandbox-env-setup.d.ts.map +1 -0
  9. package/dist/bun/sandbox-env-setup.js +4 -0
  10. package/dist/bun/sandbox-env-setup.js.map +1 -0
  11. package/dist/bundle/chunks/anthropic-messages-MYU5ZMRF.js +6 -0
  12. package/dist/bundle/chunks/azure-openai-responses-HUSQ3GP2.js +2 -0
  13. package/dist/bundle/chunks/bedrock-converse-stream.js +47 -38
  14. package/dist/bundle/chunks/chunk-7IOYH2SY.js +2 -0
  15. package/dist/bundle/chunks/chunk-7YM6BE7Y.js +1561 -0
  16. package/dist/bundle/chunks/chunk-A3JYRWB6.js +2 -0
  17. package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +42 -0
  18. package/dist/bundle/chunks/chunk-FUXEF6JQ.js +44 -0
  19. package/dist/bundle/chunks/{chunk-IDDQWTHI.js → chunk-RCZIEVGO.js} +10 -1
  20. package/dist/bundle/chunks/chunk-S7SZN6Z3.js +2 -0
  21. package/dist/bundle/chunks/chunk-WIUZI2CJ.js +11 -0
  22. package/dist/bundle/chunks/github-copilot.js +1 -1
  23. package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +2 -0
  24. package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +2 -0
  25. package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +21 -0
  26. package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +2 -0
  27. package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +5 -0
  28. package/dist/bundle/chunks/{node-EM5FIVUN.js → node-O3RIBJRH.js} +1 -1
  29. package/dist/bundle/chunks/openai-codex-responses-QDSOTBBO.js +10 -0
  30. package/dist/bundle/chunks/openai-completions-KQPOPEVM.js +7 -0
  31. package/dist/bundle/chunks/openai-responses-HWEUZ6WZ.js +2 -0
  32. package/dist/bundle/chunks/{pi-messages-EGZIFQGG.js → pi-messages-GFKBWJHZ.js} +1 -1
  33. package/dist/bundle/chunks/virtual-modules-XW5APVUE.js +2 -0
  34. package/dist/bundle/cli.js +1 -1
  35. package/dist/bundle/index.js +1 -1
  36. package/dist/bundle/rpc-entry.js +1 -1
  37. package/dist/cli/args.d.ts.map +1 -1
  38. package/dist/cli/args.js +0 -2
  39. package/dist/cli/args.js.map +1 -1
  40. package/dist/cli/session-picker.d.ts +1 -1
  41. package/dist/cli/session-picker.d.ts.map +1 -1
  42. package/dist/cli/session-picker.js.map +1 -1
  43. package/dist/cli/setup.d.ts +2 -0
  44. package/dist/cli/setup.d.ts.map +1 -0
  45. package/dist/cli/setup.js +12 -0
  46. package/dist/cli/setup.js.map +1 -0
  47. package/dist/cli.d.ts.map +1 -1
  48. package/dist/cli.js +3 -25
  49. package/dist/cli.js.map +1 -1
  50. package/dist/config.d.ts.map +1 -1
  51. package/dist/config.js +1 -1
  52. package/dist/config.js.map +1 -1
  53. package/dist/core/agent-session.d.ts +56 -6
  54. package/dist/core/agent-session.d.ts.map +1 -1
  55. package/dist/core/agent-session.js +293 -155
  56. package/dist/core/agent-session.js.map +1 -1
  57. package/dist/core/bug-report-upload.d.ts +12 -0
  58. package/dist/core/bug-report-upload.d.ts.map +1 -0
  59. package/dist/core/bug-report-upload.js +22 -0
  60. package/dist/core/bug-report-upload.js.map +1 -0
  61. package/dist/core/bug-report.d.ts +176 -0
  62. package/dist/core/bug-report.d.ts.map +1 -0
  63. package/dist/core/bug-report.js +292 -0
  64. package/dist/core/bug-report.js.map +1 -0
  65. package/dist/core/cache-stats.d.ts.map +1 -1
  66. package/dist/core/cache-stats.js +12 -1
  67. package/dist/core/cache-stats.js.map +1 -1
  68. package/dist/core/cache-warmer.d.ts +102 -0
  69. package/dist/core/cache-warmer.d.ts.map +1 -0
  70. package/dist/core/cache-warmer.js +342 -0
  71. package/dist/core/cache-warmer.js.map +1 -0
  72. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  73. package/dist/core/compaction/branch-summarization.js +2 -2
  74. package/dist/core/compaction/branch-summarization.js.map +1 -1
  75. package/dist/core/compaction/compaction.d.ts +2 -2
  76. package/dist/core/compaction/compaction.d.ts.map +1 -1
  77. package/dist/core/compaction/compaction.js +11 -12
  78. package/dist/core/compaction/compaction.js.map +1 -1
  79. package/dist/core/crash-log.d.ts +22 -0
  80. package/dist/core/crash-log.d.ts.map +1 -0
  81. package/dist/core/crash-log.js +71 -0
  82. package/dist/core/crash-log.js.map +1 -0
  83. package/dist/core/experimental.d.ts +0 -4
  84. package/dist/core/experimental.d.ts.map +1 -1
  85. package/dist/core/experimental.js +0 -4
  86. package/dist/core/experimental.js.map +1 -1
  87. package/dist/core/extensions/index.d.ts +1 -1
  88. package/dist/core/extensions/index.d.ts.map +1 -1
  89. package/dist/core/extensions/index.js.map +1 -1
  90. package/dist/core/extensions/jiti-loader.d.ts +2 -0
  91. package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
  92. package/dist/core/extensions/jiti-loader.js +4 -0
  93. package/dist/core/extensions/jiti-loader.js.map +1 -0
  94. package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
  95. package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
  96. package/dist/core/extensions/jiti-static-loader.js +4 -0
  97. package/dist/core/extensions/jiti-static-loader.js.map +1 -0
  98. package/dist/core/extensions/loader.d.ts.map +1 -1
  99. package/dist/core/extensions/loader.js +38 -51
  100. package/dist/core/extensions/loader.js.map +1 -1
  101. package/dist/core/extensions/runner.d.ts +10 -7
  102. package/dist/core/extensions/runner.d.ts.map +1 -1
  103. package/dist/core/extensions/runner.js +85 -67
  104. package/dist/core/extensions/runner.js.map +1 -1
  105. package/dist/core/extensions/types.d.ts +60 -50
  106. package/dist/core/extensions/types.d.ts.map +1 -1
  107. package/dist/core/extensions/types.js.map +1 -1
  108. package/dist/core/extensions/virtual-modules.d.ts +3 -0
  109. package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
  110. package/dist/core/extensions/virtual-modules.js +38 -0
  111. package/dist/core/extensions/virtual-modules.js.map +1 -0
  112. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  113. package/dist/core/extensions/wrapper.js +1 -20
  114. package/dist/core/extensions/wrapper.js.map +1 -1
  115. package/dist/core/index.d.ts +2 -1
  116. package/dist/core/index.d.ts.map +1 -1
  117. package/dist/core/index.js.map +1 -1
  118. package/dist/core/keybindings.d.ts +6 -1
  119. package/dist/core/keybindings.d.ts.map +1 -1
  120. package/dist/core/keybindings.js +5 -1
  121. package/dist/core/keybindings.js.map +1 -1
  122. package/dist/core/messages.d.ts.map +1 -1
  123. package/dist/core/messages.js +1 -0
  124. package/dist/core/messages.js.map +1 -1
  125. package/dist/core/model-config.d.ts +101 -20
  126. package/dist/core/model-config.d.ts.map +1 -1
  127. package/dist/core/model-config.js +25 -18
  128. package/dist/core/model-config.js.map +1 -1
  129. package/dist/core/model-registry.d.ts +5 -1
  130. package/dist/core/model-registry.d.ts.map +1 -1
  131. package/dist/core/model-registry.js +8 -0
  132. package/dist/core/model-registry.js.map +1 -1
  133. package/dist/core/model-resolver.d.ts.map +1 -1
  134. package/dist/core/model-resolver.js +1 -1
  135. package/dist/core/model-resolver.js.map +1 -1
  136. package/dist/core/model-runtime.d.ts.map +1 -1
  137. package/dist/core/model-runtime.js +5 -3
  138. package/dist/core/model-runtime.js.map +1 -1
  139. package/dist/core/provider-composer.d.ts +3 -2
  140. package/dist/core/provider-composer.d.ts.map +1 -1
  141. package/dist/core/provider-composer.js +2 -0
  142. package/dist/core/provider-composer.js.map +1 -1
  143. package/dist/core/radius.d.ts +3 -0
  144. package/dist/core/radius.d.ts.map +1 -1
  145. package/dist/core/radius.js +6 -0
  146. package/dist/core/radius.js.map +1 -1
  147. package/dist/core/sdk.d.ts.map +1 -1
  148. package/dist/core/sdk.js +60 -38
  149. package/dist/core/sdk.js.map +1 -1
  150. package/dist/core/session-export.d.ts +6 -2
  151. package/dist/core/session-export.d.ts.map +1 -1
  152. package/dist/core/session-export.js +14 -13
  153. package/dist/core/session-export.js.map +1 -1
  154. package/dist/core/session-manager.d.ts +29 -6
  155. package/dist/core/session-manager.d.ts.map +1 -1
  156. package/dist/core/session-manager.js +159 -96
  157. package/dist/core/session-manager.js.map +1 -1
  158. package/dist/core/settings-manager.d.ts +20 -4
  159. package/dist/core/settings-manager.d.ts.map +1 -1
  160. package/dist/core/settings-manager.js +43 -7
  161. package/dist/core/settings-manager.js.map +1 -1
  162. package/dist/core/slash-commands.d.ts.map +1 -1
  163. package/dist/core/slash-commands.js +1 -0
  164. package/dist/core/slash-commands.js.map +1 -1
  165. package/dist/core/system-prompt.d.ts +49 -6
  166. package/dist/core/system-prompt.d.ts.map +1 -1
  167. package/dist/core/system-prompt.js +121 -92
  168. package/dist/core/system-prompt.js.map +1 -1
  169. package/dist/core/tools/bash.d.ts +2 -1
  170. package/dist/core/tools/bash.d.ts.map +1 -1
  171. package/dist/core/tools/bash.js +10 -4
  172. package/dist/core/tools/bash.js.map +1 -1
  173. package/dist/core/tools/edit.d.ts.map +1 -1
  174. package/dist/core/tools/edit.js +1 -2
  175. package/dist/core/tools/edit.js.map +1 -1
  176. package/dist/core/tools/read.d.ts.map +1 -1
  177. package/dist/core/tools/read.js +1 -2
  178. package/dist/core/tools/read.js.map +1 -1
  179. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  180. package/dist/core/tools/renderers/bash.js +9 -1
  181. package/dist/core/tools/renderers/bash.js.map +1 -1
  182. package/dist/core/tools/write.d.ts.map +1 -1
  183. package/dist/core/tools/write.js +1 -2
  184. package/dist/core/tools/write.js.map +1 -1
  185. package/dist/core/usage-totals.d.ts +1 -1
  186. package/dist/core/usage-totals.d.ts.map +1 -1
  187. package/dist/core/usage-totals.js +5 -1
  188. package/dist/core/usage-totals.js.map +1 -1
  189. package/dist/extensions/llama/client.d.ts +2 -0
  190. package/dist/extensions/llama/client.d.ts.map +1 -1
  191. package/dist/extensions/llama/client.js +7 -3
  192. package/dist/extensions/llama/client.js.map +1 -1
  193. package/dist/extensions/llama/provider.d.ts.map +1 -1
  194. package/dist/extensions/llama/provider.js +20 -5
  195. package/dist/extensions/llama/provider.js.map +1 -1
  196. package/dist/index.d.ts +3 -2
  197. package/dist/index.d.ts.map +1 -1
  198. package/dist/index.js.map +1 -1
  199. package/dist/main.d.ts.map +1 -1
  200. package/dist/main.js +13 -131
  201. package/dist/main.js.map +1 -1
  202. package/dist/migrations.d.ts.map +1 -1
  203. package/dist/migrations.js +2 -2
  204. package/dist/migrations.js.map +1 -1
  205. package/dist/modes/interactive/bug-report.d.ts +14 -0
  206. package/dist/modes/interactive/bug-report.d.ts.map +1 -0
  207. package/dist/modes/interactive/bug-report.js +209 -0
  208. package/dist/modes/interactive/bug-report.js.map +1 -0
  209. package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
  210. package/dist/modes/interactive/chat-viewport.js +1 -1
  211. package/dist/modes/interactive/chat-viewport.js.map +1 -1
  212. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  213. package/dist/modes/interactive/components/branch-summary-message.js +12 -5
  214. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  215. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  216. package/dist/modes/interactive/components/compaction-summary-message.js +12 -5
  217. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  218. package/dist/modes/interactive/components/custom-editor.d.ts +3 -3
  219. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  220. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  221. package/dist/modes/interactive/components/extension-input.d.ts +2 -0
  222. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  223. package/dist/modes/interactive/components/extension-input.js +6 -0
  224. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  225. package/dist/modes/interactive/components/extension-selector.d.ts +1 -0
  226. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  227. package/dist/modes/interactive/components/extension-selector.js +4 -0
  228. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  229. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  230. package/dist/modes/interactive/components/footer.js +4 -1
  231. package/dist/modes/interactive/components/footer.js.map +1 -1
  232. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  233. package/dist/modes/interactive/components/model-selector.js +5 -5
  234. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  235. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  236. package/dist/modes/interactive/components/scoped-models-selector.js +8 -8
  237. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  238. package/dist/modes/interactive/components/session-selector.d.ts +5 -5
  239. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  240. package/dist/modes/interactive/components/session-selector.js +74 -48
  241. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  242. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  243. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  244. package/dist/modes/interactive/components/settings-selector.js +11 -0
  245. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  246. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  247. package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
  248. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  249. package/dist/modes/interactive/components/status-indicator.d.ts +2 -2
  250. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  251. package/dist/modes/interactive/components/status-indicator.js +7 -7
  252. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  253. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  254. package/dist/modes/interactive/components/thinking-selector.js +4 -4
  255. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  256. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  257. package/dist/modes/interactive/components/tool-execution.js +18 -9
  258. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  259. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  260. package/dist/modes/interactive/components/tree-selector.js +2 -0
  261. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  262. package/dist/modes/interactive/interactive-mode.d.ts +13 -1
  263. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  264. package/dist/modes/interactive/interactive-mode.js +220 -84
  265. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  266. package/dist/modes/interactive/session-share.d.ts +2 -0
  267. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  268. package/dist/modes/interactive/session-share.js +8 -4
  269. package/dist/modes/interactive/session-share.js.map +1 -1
  270. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
  271. package/dist/modes/interactive/tui-renderer.js +2 -2
  272. package/dist/modes/interactive/tui-renderer.js.map +1 -1
  273. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  274. package/dist/modes/rpc/rpc-mode.js +2 -2
  275. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  276. package/dist/utils/clipboard-command.d.ts +7 -0
  277. package/dist/utils/clipboard-command.d.ts.map +1 -0
  278. package/dist/utils/clipboard-command.js +45 -0
  279. package/dist/utils/clipboard-command.js.map +1 -0
  280. package/dist/utils/clipboard-image.d.ts.map +1 -1
  281. package/dist/utils/clipboard-image.js +52 -69
  282. package/dist/utils/clipboard-image.js.map +1 -1
  283. package/dist/utils/clipboard.d.ts.map +1 -1
  284. package/dist/utils/clipboard.js +61 -125
  285. package/dist/utils/clipboard.js.map +1 -1
  286. package/dist/utils/zip.d.ts +7 -0
  287. package/dist/utils/zip.d.ts.map +1 -0
  288. package/dist/utils/zip.js +60 -0
  289. package/dist/utils/zip.js.map +1 -0
  290. package/docs/compaction.md +39 -13
  291. package/docs/containerization.md +45 -0
  292. package/docs/custom-provider.md +22 -13
  293. package/docs/development.md +23 -4
  294. package/docs/docs.json +4 -0
  295. package/docs/environment-variables.md +3 -2
  296. package/docs/extensions.md +57 -43
  297. package/docs/json.md +4 -4
  298. package/docs/keybindings.md +2 -1
  299. package/docs/models.md +34 -3
  300. package/docs/providers.md +2 -2
  301. package/docs/sdk.md +4 -2
  302. package/docs/security.md +1 -1
  303. package/docs/session-format.md +82 -40
  304. package/docs/sessions.md +27 -0
  305. package/docs/settings.md +60 -1
  306. package/docs/termux.md +0 -1
  307. package/docs/tui.md +2 -2
  308. package/docs/usage.md +1 -0
  309. package/examples/extensions/README.md +0 -1
  310. package/examples/extensions/custom-provider-anthropic/index.ts +18 -12
  311. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  312. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  313. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  314. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  315. package/examples/extensions/gondolin/package-lock.json +2 -2
  316. package/examples/extensions/gondolin/package.json +1 -1
  317. package/examples/extensions/prompt-customizer.ts +19 -67
  318. package/examples/extensions/sandbox/package-lock.json +2 -2
  319. package/examples/extensions/sandbox/package.json +1 -1
  320. package/examples/extensions/with-deps/package-lock.json +2 -2
  321. package/examples/extensions/with-deps/package.json +1 -1
  322. package/npm-shrinkwrap.json +425 -778
  323. package/package.json +22 -27
  324. package/dist/bundle/chunks/anthropic-messages-QAQLEQIY.js +0 -6
  325. package/dist/bundle/chunks/azure-openai-responses-Q7MJBRE6.js +0 -2
  326. package/dist/bundle/chunks/chunk-2KVJKXS2.js +0 -50
  327. package/dist/bundle/chunks/chunk-AXIIZGTV.js +0 -2
  328. package/dist/bundle/chunks/chunk-EQ6DR6XK.js +0 -5
  329. package/dist/bundle/chunks/chunk-GMWCTUPB.js +0 -2
  330. package/dist/bundle/chunks/chunk-LZKJTKCT.js +0 -2
  331. package/dist/bundle/chunks/chunk-OUXLLA64.js +0 -11
  332. package/dist/bundle/chunks/chunk-R7UUJ4C2.js +0 -42
  333. package/dist/bundle/chunks/chunk-UAQELI3K.js +0 -2
  334. package/dist/bundle/chunks/chunk-WBE4J4AU.js +0 -9
  335. package/dist/bundle/chunks/chunk-WZB2R5YO.js +0 -1558
  336. package/dist/bundle/chunks/google-generative-ai-BSMTYDAM.js +0 -2
  337. package/dist/bundle/chunks/google-vertex-5C3HASOJ.js +0 -2
  338. package/dist/bundle/chunks/mistral-conversations-4M6BZBX6.js +0 -5
  339. package/dist/bundle/chunks/openai-codex-responses-YJOO52RW.js +0 -10
  340. package/dist/bundle/chunks/openai-completions-QOT3QX7D.js +0 -7
  341. package/dist/bundle/chunks/openai-responses-U7LNPQN4.js +0 -2
  342. package/dist/bundle/client.js +0 -2
  343. package/dist/bundle/coordinator.js +0 -3
  344. package/dist/cli/experimental/cli.d.ts +0 -10
  345. package/dist/cli/experimental/cli.d.ts.map +0 -1
  346. package/dist/cli/experimental/cli.js +0 -9
  347. package/dist/cli/experimental/cli.js.map +0 -1
  348. package/dist/cli/experimental/command-options.d.ts +0 -28
  349. package/dist/cli/experimental/command-options.d.ts.map +0 -1
  350. package/dist/cli/experimental/command-options.js +0 -84
  351. package/dist/cli/experimental/command-options.js.map +0 -1
  352. package/dist/cli/experimental/command.d.ts +0 -70
  353. package/dist/cli/experimental/command.d.ts.map +0 -1
  354. package/dist/cli/experimental/command.js +0 -144
  355. package/dist/cli/experimental/command.js.map +0 -1
  356. package/dist/cli/experimental/commands/client.d.ts +0 -19
  357. package/dist/cli/experimental/commands/client.d.ts.map +0 -1
  358. package/dist/cli/experimental/commands/client.js +0 -63
  359. package/dist/cli/experimental/commands/client.js.map +0 -1
  360. package/dist/cli/experimental/commands/server.d.ts +0 -17
  361. package/dist/cli/experimental/commands/server.d.ts.map +0 -1
  362. package/dist/cli/experimental/commands/server.js +0 -44
  363. package/dist/cli/experimental/commands/server.js.map +0 -1
  364. package/dist/client/index.d.ts +0 -2
  365. package/dist/client/index.d.ts.map +0 -1
  366. package/dist/client/index.js +0 -2
  367. package/dist/client/index.js.map +0 -1
  368. package/dist/experimental/client-runtime.d.ts +0 -43
  369. package/dist/experimental/client-runtime.d.ts.map +0 -1
  370. package/dist/experimental/client-runtime.js +0 -183
  371. package/dist/experimental/client-runtime.js.map +0 -1
  372. package/dist/experimental/client-tui-chat.d.ts +0 -14
  373. package/dist/experimental/client-tui-chat.d.ts.map +0 -1
  374. package/dist/experimental/client-tui-chat.js +0 -171
  375. package/dist/experimental/client-tui-chat.js.map +0 -1
  376. package/dist/experimental/client-tui.d.ts +0 -37
  377. package/dist/experimental/client-tui.d.ts.map +0 -1
  378. package/dist/experimental/client-tui.js +0 -702
  379. package/dist/experimental/client-tui.js.map +0 -1
  380. package/dist/experimental/client.d.ts +0 -25
  381. package/dist/experimental/client.d.ts.map +0 -1
  382. package/dist/experimental/client.js +0 -99
  383. package/dist/experimental/client.js.map +0 -1
  384. package/dist/experimental/coordinator-entry.d.ts +0 -3
  385. package/dist/experimental/coordinator-entry.d.ts.map +0 -1
  386. package/dist/experimental/coordinator-entry.js +0 -11
  387. package/dist/experimental/coordinator-entry.js.map +0 -1
  388. package/dist/experimental/coordinator.d.ts +0 -38
  389. package/dist/experimental/coordinator.d.ts.map +0 -1
  390. package/dist/experimental/coordinator.js +0 -570
  391. package/dist/experimental/coordinator.js.map +0 -1
  392. package/dist/experimental/mini/main.d.ts +0 -7
  393. package/dist/experimental/mini/main.d.ts.map +0 -1
  394. package/dist/experimental/mini/main.js +0 -21
  395. package/dist/experimental/mini/main.js.map +0 -1
  396. package/dist/experimental/mini/server/entry.d.ts +0 -3
  397. package/dist/experimental/mini/server/entry.d.ts.map +0 -1
  398. package/dist/experimental/mini/server/entry.js +0 -11
  399. package/dist/experimental/mini/server/entry.js.map +0 -1
  400. package/dist/experimental/mini/server/run.d.ts +0 -13
  401. package/dist/experimental/mini/server/run.d.ts.map +0 -1
  402. package/dist/experimental/mini/server/run.js +0 -150
  403. package/dist/experimental/mini/server/run.js.map +0 -1
  404. package/dist/experimental/mini/shared/protocol.d.ts +0 -127
  405. package/dist/experimental/mini/shared/protocol.d.ts.map +0 -1
  406. package/dist/experimental/mini/shared/protocol.js +0 -13
  407. package/dist/experimental/mini/shared/protocol.js.map +0 -1
  408. package/dist/experimental/mini/shared/rpc.d.ts +0 -49
  409. package/dist/experimental/mini/shared/rpc.d.ts.map +0 -1
  410. package/dist/experimental/mini/shared/rpc.js +0 -171
  411. package/dist/experimental/mini/shared/rpc.js.map +0 -1
  412. package/dist/experimental/mini/shared/transport.d.ts +0 -35
  413. package/dist/experimental/mini/shared/transport.d.ts.map +0 -1
  414. package/dist/experimental/mini/shared/transport.js +0 -94
  415. package/dist/experimental/mini/shared/transport.js.map +0 -1
  416. package/dist/experimental/mini/tui/run.d.ts +0 -9
  417. package/dist/experimental/mini/tui/run.d.ts.map +0 -1
  418. package/dist/experimental/mini/tui/run.js +0 -62
  419. package/dist/experimental/mini/tui/run.js.map +0 -1
  420. package/dist/experimental/mini/tui/session.d.ts +0 -26
  421. package/dist/experimental/mini/tui/session.d.ts.map +0 -1
  422. package/dist/experimental/mini/tui/session.js +0 -94
  423. package/dist/experimental/mini/tui/session.js.map +0 -1
  424. package/dist/experimental/mini/tui/view.d.ts +0 -10
  425. package/dist/experimental/mini/tui/view.d.ts.map +0 -1
  426. package/dist/experimental/mini/tui/view.js +0 -459
  427. package/dist/experimental/mini/tui/view.js.map +0 -1
  428. package/dist/experimental/mini/worker/entry.d.ts +0 -3
  429. package/dist/experimental/mini/worker/entry.d.ts.map +0 -1
  430. package/dist/experimental/mini/worker/entry.js +0 -10
  431. package/dist/experimental/mini/worker/entry.js.map +0 -1
  432. package/dist/experimental/mini/worker/lane-service.d.ts +0 -44
  433. package/dist/experimental/mini/worker/lane-service.d.ts.map +0 -1
  434. package/dist/experimental/mini/worker/lane-service.js +0 -97
  435. package/dist/experimental/mini/worker/lane-service.js.map +0 -1
  436. package/dist/experimental/mini/worker/models-service.d.ts +0 -19
  437. package/dist/experimental/mini/worker/models-service.d.ts.map +0 -1
  438. package/dist/experimental/mini/worker/models-service.js +0 -136
  439. package/dist/experimental/mini/worker/models-service.js.map +0 -1
  440. package/dist/experimental/mini/worker/run.d.ts +0 -14
  441. package/dist/experimental/mini/worker/run.d.ts.map +0 -1
  442. package/dist/experimental/mini/worker/run.js +0 -88
  443. package/dist/experimental/mini/worker/run.js.map +0 -1
  444. package/dist/experimental/plugin.d.ts +0 -4
  445. package/dist/experimental/plugin.d.ts.map +0 -1
  446. package/dist/experimental/plugin.js +0 -4
  447. package/dist/experimental/plugin.js.map +0 -1
  448. package/dist/experimental/plugins/bundled.d.ts +0 -7
  449. package/dist/experimental/plugins/bundled.d.ts.map +0 -1
  450. package/dist/experimental/plugins/bundled.js +0 -48
  451. package/dist/experimental/plugins/bundled.js.map +0 -1
  452. package/dist/experimental/plugins/package.d.ts +0 -18
  453. package/dist/experimental/plugins/package.d.ts.map +0 -1
  454. package/dist/experimental/plugins/package.js +0 -113
  455. package/dist/experimental/plugins/package.js.map +0 -1
  456. package/dist/experimental/process.d.ts +0 -20
  457. package/dist/experimental/process.d.ts.map +0 -1
  458. package/dist/experimental/process.js +0 -85
  459. package/dist/experimental/process.js.map +0 -1
  460. package/dist/experimental/radius-auth.d.ts +0 -17
  461. package/dist/experimental/radius-auth.d.ts.map +0 -1
  462. package/dist/experimental/radius-auth.js +0 -52
  463. package/dist/experimental/radius-auth.js.map +0 -1
  464. package/dist/experimental/radius-relay.d.ts +0 -90
  465. package/dist/experimental/radius-relay.d.ts.map +0 -1
  466. package/dist/experimental/radius-relay.js +0 -582
  467. package/dist/experimental/radius-relay.js.map +0 -1
  468. package/dist/experimental/server.d.ts +0 -75
  469. package/dist/experimental/server.d.ts.map +0 -1
  470. package/dist/experimental/server.js +0 -682
  471. package/dist/experimental/server.js.map +0 -1
  472. package/dist/experimental/services/agent-controller-provider.d.ts +0 -4
  473. package/dist/experimental/services/agent-controller-provider.d.ts.map +0 -1
  474. package/dist/experimental/services/agent-controller-provider.js +0 -84
  475. package/dist/experimental/services/agent-controller-provider.js.map +0 -1
  476. package/dist/experimental/services/agent-controller.d.ts +0 -57
  477. package/dist/experimental/services/agent-controller.d.ts.map +0 -1
  478. package/dist/experimental/services/agent-controller.js +0 -3
  479. package/dist/experimental/services/agent-controller.js.map +0 -1
  480. package/dist/experimental/services/connection.d.ts +0 -40
  481. package/dist/experimental/services/connection.d.ts.map +0 -1
  482. package/dist/experimental/services/connection.js +0 -300
  483. package/dist/experimental/services/connection.js.map +0 -1
  484. package/dist/experimental/services/models-provider.d.ts +0 -16
  485. package/dist/experimental/services/models-provider.d.ts.map +0 -1
  486. package/dist/experimental/services/models-provider.js +0 -116
  487. package/dist/experimental/services/models-provider.js.map +0 -1
  488. package/dist/experimental/services/models.d.ts +0 -36
  489. package/dist/experimental/services/models.d.ts.map +0 -1
  490. package/dist/experimental/services/models.js +0 -3
  491. package/dist/experimental/services/models.js.map +0 -1
  492. package/dist/experimental/services/plugins.d.ts +0 -16
  493. package/dist/experimental/services/plugins.d.ts.map +0 -1
  494. package/dist/experimental/services/plugins.js +0 -4
  495. package/dist/experimental/services/plugins.js.map +0 -1
  496. package/dist/experimental/services/presentation-ui.d.ts +0 -13
  497. package/dist/experimental/services/presentation-ui.d.ts.map +0 -1
  498. package/dist/experimental/services/presentation-ui.js +0 -3
  499. package/dist/experimental/services/presentation-ui.js.map +0 -1
  500. package/dist/experimental/services/server.d.ts +0 -19
  501. package/dist/experimental/services/server.d.ts.map +0 -1
  502. package/dist/experimental/services/server.js +0 -104
  503. package/dist/experimental/services/server.js.map +0 -1
  504. package/dist/experimental/services/sessions.d.ts +0 -28
  505. package/dist/experimental/services/sessions.d.ts.map +0 -1
  506. package/dist/experimental/services/sessions.js +0 -4
  507. package/dist/experimental/services/sessions.js.map +0 -1
  508. package/dist/experimental/services/slash-commands-provider.d.ts +0 -14
  509. package/dist/experimental/services/slash-commands-provider.d.ts.map +0 -1
  510. package/dist/experimental/services/slash-commands-provider.js +0 -200
  511. package/dist/experimental/services/slash-commands-provider.js.map +0 -1
  512. package/dist/experimental/services/slash-commands.d.ts +0 -24
  513. package/dist/experimental/services/slash-commands.d.ts.map +0 -1
  514. package/dist/experimental/services/slash-commands.js +0 -3
  515. package/dist/experimental/services/slash-commands.js.map +0 -1
  516. package/dist/experimental/services/transcript-provider.d.ts +0 -12
  517. package/dist/experimental/services/transcript-provider.d.ts.map +0 -1
  518. package/dist/experimental/services/transcript-provider.js +0 -109
  519. package/dist/experimental/services/transcript-provider.js.map +0 -1
  520. package/dist/experimental/services/transcript.d.ts +0 -13
  521. package/dist/experimental/services/transcript.d.ts.map +0 -1
  522. package/dist/experimental/services/transcript.js +0 -3
  523. package/dist/experimental/services/transcript.js.map +0 -1
  524. package/dist/experimental/services/worker.d.ts +0 -28
  525. package/dist/experimental/services/worker.d.ts.map +0 -1
  526. package/dist/experimental/services/worker.js +0 -107
  527. package/dist/experimental/services/worker.js.map +0 -1
  528. package/dist/experimental/session-worker-manager.d.ts +0 -24
  529. package/dist/experimental/session-worker-manager.d.ts.map +0 -1
  530. package/dist/experimental/session-worker-manager.js +0 -691
  531. package/dist/experimental/session-worker-manager.js.map +0 -1
  532. package/dist/experimental/session-worker.d.ts +0 -188
  533. package/dist/experimental/session-worker.d.ts.map +0 -1
  534. package/dist/experimental/session-worker.js +0 -785
  535. package/dist/experimental/session-worker.js.map +0 -1
  536. package/dist/experimental/source-resolver.d.ts +0 -2
  537. package/dist/experimental/source-resolver.d.ts.map +0 -1
  538. package/dist/experimental/source-resolver.js +0 -71
  539. package/dist/experimental/source-resolver.js.map +0 -1
  540. package/dist/utils/clipboard-native.d.ts +0 -11
  541. package/dist/utils/clipboard-native.d.ts.map +0 -1
  542. package/dist/utils/clipboard-native.js +0 -20
  543. package/dist/utils/clipboard-native.js.map +0 -1
  544. package/examples/extensions/kimi-deferred-tools.ts +0 -61
@@ -1,70 +0,0 @@
1
- export interface NamedCommandInvocation {
2
- readonly command: string;
3
- }
4
- export type CommandParseResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> = {
5
- readonly ok: true;
6
- readonly command: TInvocation;
7
- } | {
8
- readonly ok: false;
9
- readonly errors: readonly string[];
10
- };
11
- export type CommandExecutionResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> = {
12
- readonly ok: true;
13
- readonly command: TInvocation;
14
- } | {
15
- readonly ok: false;
16
- readonly errors: readonly string[];
17
- };
18
- export type CommandOptionParseResult<TValue> = {
19
- readonly ok: true;
20
- readonly value: TValue;
21
- } | {
22
- readonly ok: false;
23
- readonly error: string;
24
- };
25
- export interface CommandOption<TValue> {
26
- readonly name: `-${string}`;
27
- readonly flag?: boolean;
28
- readonly repeatable?: boolean;
29
- parse(value: string): CommandOptionParseResult<TValue>;
30
- }
31
- export declare function valueOption<TValue>(name: `-${string}`, parse: (value: string) => CommandOptionParseResult<TValue>, options?: {
32
- readonly repeatable?: boolean;
33
- }): CommandOption<TValue>;
34
- export declare function stringOption(name: `-${string}`, options?: {
35
- readonly repeatable?: boolean;
36
- }): CommandOption<string>;
37
- export declare function flagOption(name: `-${string}`): CommandOption<boolean>;
38
- export interface ParsedCommandInput {
39
- readonly remainingArgs: readonly string[];
40
- value<TValue>(option: CommandOption<TValue>): TValue | undefined;
41
- values<TValue>(option: CommandOption<TValue>): readonly TValue[];
42
- }
43
- export type CommandBuildResult<TInvocation extends NamedCommandInvocation> = {
44
- readonly ok: true;
45
- readonly command: TInvocation;
46
- } | {
47
- readonly ok: false;
48
- readonly errors: readonly string[];
49
- };
50
- type CommandBuilder<TInvocation extends NamedCommandInvocation> = (input: ParsedCommandInput) => CommandBuildResult<TInvocation>;
51
- type CommandAction<TInvocation extends NamedCommandInvocation, TContext> = (command: TInvocation, context: TContext) => void | Promise<void>;
52
- export declare class Command<TOwnInvocation extends NamedCommandInvocation, TContext, TInvocation extends NamedCommandInvocation = TOwnInvocation> {
53
- readonly name: string;
54
- private readonly options;
55
- private readonly subcommands;
56
- private builder?;
57
- private commandAction?;
58
- constructor(name: string);
59
- option<TValue>(option: CommandOption<TValue>): this;
60
- build(builder: CommandBuilder<TOwnInvocation>): this;
61
- action(action: CommandAction<TOwnInvocation, TContext>): this;
62
- command<TSubcommandOwnInvocation extends NamedCommandInvocation, TSubcommandContext, TSubcommandInvocation extends NamedCommandInvocation>(command: Command<TSubcommandOwnInvocation, TSubcommandContext, TSubcommandInvocation>): Command<TOwnInvocation, TContext & TSubcommandContext, TInvocation | TSubcommandInvocation>;
63
- parse(argv: readonly string[]): CommandParseResult<TInvocation>;
64
- execute(argv: readonly string[], context: TContext): Promise<CommandExecutionResult<TInvocation>>;
65
- private select;
66
- private parseOwn;
67
- private parseOptions;
68
- }
69
- export {};
70
- //# sourceMappingURL=command.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/cli/experimental/command.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,kBAAkB,CAAC,WAAW,SAAS,sBAAsB,GAAG,sBAAsB,IAC/F;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,sBAAsB,CAAC,WAAW,SAAS,sBAAsB,GAAG,sBAAsB,IACnG;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,E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AC,MAAM,EAAE,aAAa,CAAC,cAAc,EAAE,QAAQ,CAAC,GAAG,IAAI,CAG5D;IAED,OAAO,CACN,wBAAwB,SAAS,sBAAsB,EACvD,kBAAkB,EAClB,qBAAqB,SAAS,sBAAsB,EAEpD,OAAO,EAAE,OAAO,CAAC,wBAAwB,EAAE,kBAAkB,EAAE,qBAAqB,CAAC,GACnF,OAAO,CAAC,cAAc,EAAE,QAAQ,GAAG,kBAAkB,EAAE,WAAW,GAAG,qBAAqB,CAAC,CAW7F;IAED,KAAK,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAI9D;IAEK,OAAO,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC,CAWtG;IAED,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,YAAY;CA2DpB","sourcesContent":["export interface NamedCommandInvocation {\n\treadonly command: string;\n}\n\nexport type CommandParseResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandExecutionResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandOptionParseResult<TValue> =\n\t| { readonly ok: true; readonly value: TValue }\n\t| { readonly ok: false; readonly error: string };\n\nexport interface CommandOption<TValue> {\n\treadonly name: `-${string}`;\n\treadonly flag?: boolean;\n\treadonly repeatable?: boolean;\n\tparse(value: string): CommandOptionParseResult<TValue>;\n}\n\nexport function valueOption<TValue>(\n\tname: `-${string}`,\n\tparse: (value: string) => CommandOptionParseResult<TValue>,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<TValue> {\n\treturn { name, parse, ...options };\n}\n\nexport function stringOption(\n\tname: `-${string}`,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<string> {\n\treturn valueOption(name, (value) => ({ ok: true, value }), options);\n}\n\nexport function flagOption(name: `-${string}`): CommandOption<boolean> {\n\treturn { name, flag: true, parse: () => ({ ok: true, value: true }) };\n}\n\nexport interface ParsedCommandInput {\n\treadonly remainingArgs: readonly string[];\n\tvalue<TValue>(option: CommandOption<TValue>): TValue | undefined;\n\tvalues<TValue>(option: CommandOption<TValue>): readonly TValue[];\n}\n\nexport type CommandBuildResult<TInvocation extends NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\ninterface MutableParsedCommandInput {\n\treadonly values: Map<string, unknown[]>;\n\treadonly remainingArgs: string[];\n\treadonly errors: string[];\n}\n\ntype CommandBuilder<TInvocation extends NamedCommandInvocation> = (\n\tinput: ParsedCommandInput,\n) => CommandBuildResult<TInvocation>;\n\ntype CommandAction<TInvocation extends NamedCommandInvocation, TContext> = (\n\tcommand: TInvocation,\n\tcontext: TContext,\n) => void | Promise<void>;\n\ninterface RegisteredCommand {\n\tparse(argv: readonly string[]): CommandParseResult;\n\texecute(argv: readonly string[], context: unknown): Promise<CommandExecutionResult>;\n}\n\nexport class Command<\n\tTOwnInvocation extends NamedCommandInvocation,\n\tTContext,\n\tTInvocation extends NamedCommandInvocation = TOwnInvocation,\n> {\n\treadonly name: string;\n\tprivate readonly options = new Map<string, CommandOption<unknown>>();\n\tprivate readonly subcommands = new Map<string, RegisteredCommand>();\n\tprivate builder?: CommandBuilder<TOwnInvocation>;\n\tprivate commandAction?: CommandAction<TOwnInvocation, TContext>;\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\toption<TValue>(option: CommandOption<TValue>): this {\n\t\tif (this.options.has(option.name)) {\n\t\t\tthrow new Error(`Option ${option.name} is already registered for ${this.name}`);\n\t\t}\n\t\tthis.options.set(option.name, option);\n\t\treturn this;\n\t}\n\n\tbuild(builder: CommandBuilder<TOwnInvocation>): this {\n\t\tthis.builder = builder;\n\t\treturn this;\n\t}\n\n\taction(action: CommandAction<TOwnInvocation, TContext>): this {\n\t\tthis.commandAction = action;\n\t\treturn this;\n\t}\n\n\tcommand<\n\t\tTSubcommandOwnInvocation extends NamedCommandInvocation,\n\t\tTSubcommandContext,\n\t\tTSubcommandInvocation extends NamedCommandInvocation,\n\t>(\n\t\tcommand: Command<TSubcommandOwnInvocation, TSubcommandContext, TSubcommandInvocation>,\n\t): Command<TOwnInvocation, TContext & TSubcommandContext, TInvocation | TSubcommandInvocation> {\n\t\tif (this.subcommands.has(command.name)) throw new Error(`Command ${command.name} is already registered`);\n\t\tthis.subcommands.set(command.name, {\n\t\t\tparse: (argv) => command.parse(argv),\n\t\t\texecute: (argv, context) => command.execute(argv, context as TSubcommandContext),\n\t\t});\n\t\treturn this as unknown as Command<\n\t\t\tTOwnInvocation,\n\t\t\tTContext & TSubcommandContext,\n\t\t\tTInvocation | TSubcommandInvocation\n\t\t>;\n\t}\n\n\tparse(argv: readonly string[]): CommandParseResult<TInvocation> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) return selected.command.parse(selected.argv) as CommandParseResult<TInvocation>;\n\t\treturn this.parseOwn(argv) as CommandParseResult<TInvocation>;\n\t}\n\n\tasync execute(argv: readonly string[], context: TContext): Promise<CommandExecutionResult<TInvocation>> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) {\n\t\t\treturn selected.command.execute(selected.argv, context) as Promise<CommandExecutionResult<TInvocation>>;\n\t\t}\n\n\t\tconst parsed = this.parseOwn(argv);\n\t\tif (!parsed.ok) return parsed;\n\t\tif (!this.commandAction) throw new Error(`Command ${this.name} does not define an action`);\n\t\tawait this.commandAction(parsed.command, context);\n\t\treturn { ok: true, command: parsed.command as unknown as TInvocation };\n\t}\n\n\tprivate select(argv: readonly string[]): { command: RegisteredCommand; argv: readonly string[] } | undefined {\n\t\tconst candidate = argv[0];\n\t\tif (candidate === undefined) return undefined;\n\t\tconst command = this.subcommands.get(candidate);\n\t\treturn command ? { command, argv: argv.slice(1) } : undefined;\n\t}\n\n\tprivate parseOwn(argv: readonly string[]): CommandParseResult<TOwnInvocation> {\n\t\tif (!this.builder) throw new Error(`Command ${this.name} does not define a builder`);\n\t\tconst parsed = this.parseOptions(argv);\n\t\tconst input: ParsedCommandInput = {\n\t\t\tremainingArgs: parsed.remainingArgs,\n\t\t\tvalue: <TValue>(option: CommandOption<TValue>) => parsed.values.get(option.name)?.[0] as TValue | undefined,\n\t\t\tvalues: <TValue>(option: CommandOption<TValue>) => (parsed.values.get(option.name) ?? []) as readonly TValue[],\n\t\t};\n\t\tconst built = this.builder(input);\n\t\tconst errors = [...parsed.errors, ...(built.ok ? [] : built.errors)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\tif (!built.ok) throw new Error(`Command ${this.name} failed without an error`);\n\t\treturn { ok: true, command: built.command };\n\t}\n\n\tprivate parseOptions(argv: readonly string[]): MutableParsedCommandInput {\n\t\tconst parsed: MutableParsedCommandInput = {\n\t\t\tvalues: new Map(),\n\t\t\tremainingArgs: [],\n\t\t\terrors: [],\n\t\t};\n\t\tfor (let index = 0; index < argv.length; index++) {\n\t\t\tconst argument = argv[index]!;\n\t\t\tif (argument === \"--\") {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst equals = argument.indexOf(\"=\");\n\t\t\tconst name = equals === -1 ? argument : argument.slice(0, equals);\n\t\t\tconst option = this.options.get(name);\n\t\t\tif (!option) {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tlet value: string;\n\t\t\tif (option.flag === true) {\n\t\t\t\tif (equals !== -1) {\n\t\t\t\t\tparsed.errors.push(`${name} does not take a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = \"\";\n\t\t\t} else {\n\t\t\t\tlet candidate = equals === -1 ? undefined : argument.slice(equals + 1);\n\t\t\t\tif (candidate === undefined) {\n\t\t\t\t\tconst next = argv[index + 1];\n\t\t\t\t\tif (next !== undefined && !next.startsWith(\"-\")) {\n\t\t\t\t\t\tcandidate = next;\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (candidate === undefined || candidate === \"\") {\n\t\t\t\t\tparsed.errors.push(`${name} requires a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = candidate;\n\t\t\t}\n\n\t\t\tconst values = parsed.values.get(name) ?? [];\n\t\t\tif (values.length > 0 && option.repeatable !== true) {\n\t\t\t\tparsed.errors.push(`${name} may only be specified once`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = option.parse(value);\n\t\t\tif (!result.ok) {\n\t\t\t\tparsed.errors.push(result.error);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalues.push(result.value);\n\t\t\tparsed.values.set(name, values);\n\t\t}\n\t\treturn parsed;\n\t}\n}\n"]}
@@ -1,144 +0,0 @@
1
- export function valueOption(name, parse, options = {}) {
2
- return { name, parse, ...options };
3
- }
4
- export function stringOption(name, options = {}) {
5
- return valueOption(name, (value) => ({ ok: true, value }), options);
6
- }
7
- export function flagOption(name) {
8
- return { name, flag: true, parse: () => ({ ok: true, value: true }) };
9
- }
10
- export class Command {
11
- name;
12
- options = new Map();
13
- subcommands = new Map();
14
- builder;
15
- commandAction;
16
- constructor(name) {
17
- this.name = name;
18
- }
19
- option(option) {
20
- if (this.options.has(option.name)) {
21
- throw new Error(`Option ${option.name} is already registered for ${this.name}`);
22
- }
23
- this.options.set(option.name, option);
24
- return this;
25
- }
26
- build(builder) {
27
- this.builder = builder;
28
- return this;
29
- }
30
- action(action) {
31
- this.commandAction = action;
32
- return this;
33
- }
34
- command(command) {
35
- if (this.subcommands.has(command.name))
36
- throw new Error(`Command ${command.name} is already registered`);
37
- this.subcommands.set(command.name, {
38
- parse: (argv) => command.parse(argv),
39
- execute: (argv, context) => command.execute(argv, context),
40
- });
41
- return this;
42
- }
43
- parse(argv) {
44
- const selected = this.select(argv);
45
- if (selected)
46
- return selected.command.parse(selected.argv);
47
- return this.parseOwn(argv);
48
- }
49
- async execute(argv, context) {
50
- const selected = this.select(argv);
51
- if (selected) {
52
- return selected.command.execute(selected.argv, context);
53
- }
54
- const parsed = this.parseOwn(argv);
55
- if (!parsed.ok)
56
- return parsed;
57
- if (!this.commandAction)
58
- throw new Error(`Command ${this.name} does not define an action`);
59
- await this.commandAction(parsed.command, context);
60
- return { ok: true, command: parsed.command };
61
- }
62
- select(argv) {
63
- const candidate = argv[0];
64
- if (candidate === undefined)
65
- return undefined;
66
- const command = this.subcommands.get(candidate);
67
- return command ? { command, argv: argv.slice(1) } : undefined;
68
- }
69
- parseOwn(argv) {
70
- if (!this.builder)
71
- throw new Error(`Command ${this.name} does not define a builder`);
72
- const parsed = this.parseOptions(argv);
73
- const input = {
74
- remainingArgs: parsed.remainingArgs,
75
- value: (option) => parsed.values.get(option.name)?.[0],
76
- values: (option) => (parsed.values.get(option.name) ?? []),
77
- };
78
- const built = this.builder(input);
79
- const errors = [...parsed.errors, ...(built.ok ? [] : built.errors)];
80
- if (errors.length > 0)
81
- return { ok: false, errors };
82
- if (!built.ok)
83
- throw new Error(`Command ${this.name} failed without an error`);
84
- return { ok: true, command: built.command };
85
- }
86
- parseOptions(argv) {
87
- const parsed = {
88
- values: new Map(),
89
- remainingArgs: [],
90
- errors: [],
91
- };
92
- for (let index = 0; index < argv.length; index++) {
93
- const argument = argv[index];
94
- if (argument === "--") {
95
- parsed.remainingArgs.push(...argv.slice(index));
96
- break;
97
- }
98
- const equals = argument.indexOf("=");
99
- const name = equals === -1 ? argument : argument.slice(0, equals);
100
- const option = this.options.get(name);
101
- if (!option) {
102
- parsed.remainingArgs.push(...argv.slice(index));
103
- break;
104
- }
105
- let value;
106
- if (option.flag === true) {
107
- if (equals !== -1) {
108
- parsed.errors.push(`${name} does not take a value`);
109
- continue;
110
- }
111
- value = "";
112
- }
113
- else {
114
- let candidate = equals === -1 ? undefined : argument.slice(equals + 1);
115
- if (candidate === undefined) {
116
- const next = argv[index + 1];
117
- if (next !== undefined && !next.startsWith("-")) {
118
- candidate = next;
119
- index++;
120
- }
121
- }
122
- if (candidate === undefined || candidate === "") {
123
- parsed.errors.push(`${name} requires a value`);
124
- continue;
125
- }
126
- value = candidate;
127
- }
128
- const values = parsed.values.get(name) ?? [];
129
- if (values.length > 0 && option.repeatable !== true) {
130
- parsed.errors.push(`${name} may only be specified once`);
131
- continue;
132
- }
133
- const result = option.parse(value);
134
- if (!result.ok) {
135
- parsed.errors.push(result.error);
136
- continue;
137
- }
138
- values.push(result.value);
139
- parsed.values.set(name, values);
140
- }
141
- return parsed;
142
- }
143
- }
144
- //# sourceMappingURL=command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/cli/experimental/command.ts"],"names":[],"mappings":"AAuBA,MAAM,UAAU,WAAW,CAC1B,IAAkB,EAClB,KAA0D,EAC1D,OAAO,GAAsC,EAAE,EACvB;IACxB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;AAAA,CACnC;AAED,MAAM,UAAU,YAAY,CAC3B,IAAkB,EAClB,OAAO,GAAsC,EAAE,EACvB;IACxB,OAAO,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;AAAA,CACpE;AAED,MAAM,UAAU,UAAU,CAAC,IAAkB,EAA0B;IACtE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EA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AAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC;IAAA,CACd;CACD","sourcesContent":["export interface NamedCommandInvocation {\n\treadonly command: string;\n}\n\nexport type CommandParseResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandExecutionResult<TInvocation extends NamedCommandInvocation = NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\nexport type CommandOptionParseResult<TValue> =\n\t| { readonly ok: true; readonly value: TValue }\n\t| { readonly ok: false; readonly error: string };\n\nexport interface CommandOption<TValue> {\n\treadonly name: `-${string}`;\n\treadonly flag?: boolean;\n\treadonly repeatable?: boolean;\n\tparse(value: string): CommandOptionParseResult<TValue>;\n}\n\nexport function valueOption<TValue>(\n\tname: `-${string}`,\n\tparse: (value: string) => CommandOptionParseResult<TValue>,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<TValue> {\n\treturn { name, parse, ...options };\n}\n\nexport function stringOption(\n\tname: `-${string}`,\n\toptions: { readonly repeatable?: boolean } = {},\n): CommandOption<string> {\n\treturn valueOption(name, (value) => ({ ok: true, value }), options);\n}\n\nexport function flagOption(name: `-${string}`): CommandOption<boolean> {\n\treturn { name, flag: true, parse: () => ({ ok: true, value: true }) };\n}\n\nexport interface ParsedCommandInput {\n\treadonly remainingArgs: readonly string[];\n\tvalue<TValue>(option: CommandOption<TValue>): TValue | undefined;\n\tvalues<TValue>(option: CommandOption<TValue>): readonly TValue[];\n}\n\nexport type CommandBuildResult<TInvocation extends NamedCommandInvocation> =\n\t| { readonly ok: true; readonly command: TInvocation }\n\t| { readonly ok: false; readonly errors: readonly string[] };\n\ninterface MutableParsedCommandInput {\n\treadonly values: Map<string, unknown[]>;\n\treadonly remainingArgs: string[];\n\treadonly errors: string[];\n}\n\ntype CommandBuilder<TInvocation extends NamedCommandInvocation> = (\n\tinput: ParsedCommandInput,\n) => CommandBuildResult<TInvocation>;\n\ntype CommandAction<TInvocation extends NamedCommandInvocation, TContext> = (\n\tcommand: TInvocation,\n\tcontext: TContext,\n) => void | Promise<void>;\n\ninterface RegisteredCommand {\n\tparse(argv: readonly string[]): CommandParseResult;\n\texecute(argv: readonly string[], context: unknown): Promise<CommandExecutionResult>;\n}\n\nexport class Command<\n\tTOwnInvocation extends NamedCommandInvocation,\n\tTContext,\n\tTInvocation extends NamedCommandInvocation = TOwnInvocation,\n> {\n\treadonly name: string;\n\tprivate readonly options = new Map<string, CommandOption<unknown>>();\n\tprivate readonly subcommands = new Map<string, RegisteredCommand>();\n\tprivate builder?: CommandBuilder<TOwnInvocation>;\n\tprivate commandAction?: CommandAction<TOwnInvocation, TContext>;\n\n\tconstructor(name: string) {\n\t\tthis.name = name;\n\t}\n\n\toption<TValue>(option: CommandOption<TValue>): this {\n\t\tif (this.options.has(option.name)) {\n\t\t\tthrow new Error(`Option ${option.name} is already registered for ${this.name}`);\n\t\t}\n\t\tthis.options.set(option.name, option);\n\t\treturn this;\n\t}\n\n\tbuild(builder: CommandBuilder<TOwnInvocation>): this {\n\t\tthis.builder = builder;\n\t\treturn this;\n\t}\n\n\taction(action: CommandAction<TOwnInvocation, TContext>): this {\n\t\tthis.commandAction = action;\n\t\treturn this;\n\t}\n\n\tcommand<\n\t\tTSubcommandOwnInvocation extends NamedCommandInvocation,\n\t\tTSubcommandContext,\n\t\tTSubcommandInvocation extends NamedCommandInvocation,\n\t>(\n\t\tcommand: Command<TSubcommandOwnInvocation, TSubcommandContext, TSubcommandInvocation>,\n\t): Command<TOwnInvocation, TContext & TSubcommandContext, TInvocation | TSubcommandInvocation> {\n\t\tif (this.subcommands.has(command.name)) throw new Error(`Command ${command.name} is already registered`);\n\t\tthis.subcommands.set(command.name, {\n\t\t\tparse: (argv) => command.parse(argv),\n\t\t\texecute: (argv, context) => command.execute(argv, context as TSubcommandContext),\n\t\t});\n\t\treturn this as unknown as Command<\n\t\t\tTOwnInvocation,\n\t\t\tTContext & TSubcommandContext,\n\t\t\tTInvocation | TSubcommandInvocation\n\t\t>;\n\t}\n\n\tparse(argv: readonly string[]): CommandParseResult<TInvocation> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) return selected.command.parse(selected.argv) as CommandParseResult<TInvocation>;\n\t\treturn this.parseOwn(argv) as CommandParseResult<TInvocation>;\n\t}\n\n\tasync execute(argv: readonly string[], context: TContext): Promise<CommandExecutionResult<TInvocation>> {\n\t\tconst selected = this.select(argv);\n\t\tif (selected) {\n\t\t\treturn selected.command.execute(selected.argv, context) as Promise<CommandExecutionResult<TInvocation>>;\n\t\t}\n\n\t\tconst parsed = this.parseOwn(argv);\n\t\tif (!parsed.ok) return parsed;\n\t\tif (!this.commandAction) throw new Error(`Command ${this.name} does not define an action`);\n\t\tawait this.commandAction(parsed.command, context);\n\t\treturn { ok: true, command: parsed.command as unknown as TInvocation };\n\t}\n\n\tprivate select(argv: readonly string[]): { command: RegisteredCommand; argv: readonly string[] } | undefined {\n\t\tconst candidate = argv[0];\n\t\tif (candidate === undefined) return undefined;\n\t\tconst command = this.subcommands.get(candidate);\n\t\treturn command ? { command, argv: argv.slice(1) } : undefined;\n\t}\n\n\tprivate parseOwn(argv: readonly string[]): CommandParseResult<TOwnInvocation> {\n\t\tif (!this.builder) throw new Error(`Command ${this.name} does not define a builder`);\n\t\tconst parsed = this.parseOptions(argv);\n\t\tconst input: ParsedCommandInput = {\n\t\t\tremainingArgs: parsed.remainingArgs,\n\t\t\tvalue: <TValue>(option: CommandOption<TValue>) => parsed.values.get(option.name)?.[0] as TValue | undefined,\n\t\t\tvalues: <TValue>(option: CommandOption<TValue>) => (parsed.values.get(option.name) ?? []) as readonly TValue[],\n\t\t};\n\t\tconst built = this.builder(input);\n\t\tconst errors = [...parsed.errors, ...(built.ok ? [] : built.errors)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\tif (!built.ok) throw new Error(`Command ${this.name} failed without an error`);\n\t\treturn { ok: true, command: built.command };\n\t}\n\n\tprivate parseOptions(argv: readonly string[]): MutableParsedCommandInput {\n\t\tconst parsed: MutableParsedCommandInput = {\n\t\t\tvalues: new Map(),\n\t\t\tremainingArgs: [],\n\t\t\terrors: [],\n\t\t};\n\t\tfor (let index = 0; index < argv.length; index++) {\n\t\t\tconst argument = argv[index]!;\n\t\t\tif (argument === \"--\") {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst equals = argument.indexOf(\"=\");\n\t\t\tconst name = equals === -1 ? argument : argument.slice(0, equals);\n\t\t\tconst option = this.options.get(name);\n\t\t\tif (!option) {\n\t\t\t\tparsed.remainingArgs.push(...argv.slice(index));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tlet value: string;\n\t\t\tif (option.flag === true) {\n\t\t\t\tif (equals !== -1) {\n\t\t\t\t\tparsed.errors.push(`${name} does not take a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = \"\";\n\t\t\t} else {\n\t\t\t\tlet candidate = equals === -1 ? undefined : argument.slice(equals + 1);\n\t\t\t\tif (candidate === undefined) {\n\t\t\t\t\tconst next = argv[index + 1];\n\t\t\t\t\tif (next !== undefined && !next.startsWith(\"-\")) {\n\t\t\t\t\t\tcandidate = next;\n\t\t\t\t\t\tindex++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (candidate === undefined || candidate === \"\") {\n\t\t\t\t\tparsed.errors.push(`${name} requires a value`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tvalue = candidate;\n\t\t\t}\n\n\t\t\tconst values = parsed.values.get(name) ?? [];\n\t\t\tif (values.length > 0 && option.repeatable !== true) {\n\t\t\t\tparsed.errors.push(`${name} may only be specified once`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = option.parse(value);\n\t\t\tif (!result.ok) {\n\t\t\t\tparsed.errors.push(result.error);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tvalues.push(result.value);\n\t\t\tparsed.values.set(name, values);\n\t\t}\n\t\treturn parsed;\n\t}\n}\n"]}
@@ -1,19 +0,0 @@
1
- import { Command } from "../command.ts";
2
- import { type AuthInput, type TransportAddress } from "../command-options.ts";
3
- export interface ClientCommand {
4
- readonly command: "client";
5
- readonly auth?: AuthInput;
6
- readonly connect?: TransportAddress;
7
- readonly sessionId?: string;
8
- readonly continue?: boolean;
9
- readonly resume?: boolean;
10
- readonly provider?: string;
11
- readonly model?: string;
12
- readonly pluginPackages?: readonly string[];
13
- readonly prompt?: string;
14
- }
15
- export interface ClientCommandContext {
16
- runClient(command: ClientCommand): void | Promise<void>;
17
- }
18
- export declare const clientCommand: Command<ClientCommand, ClientCommandContext, ClientCommand>;
19
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA4B,MAAM,eAAe,CAAC;AAClE,OAAO,EACN,KAAK,SAAS,EAKd,KAAK,gBAAgB,EAErB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACpC,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAWD,eAAO,MAAM,aAAa,6DAqDgC,CAAC","sourcesContent":["import { Command, flagOption, stringOption } from \"../command.ts\";\nimport {\n\ttype AuthInput,\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tconnectOption,\n\tparseAuth,\n\ttype TransportAddress,\n\tunsupportedOptions,\n} from \"../command-options.ts\";\n\nexport interface ClientCommand {\n\treadonly command: \"client\";\n\treadonly auth?: AuthInput;\n\treadonly connect?: TransportAddress;\n\treadonly sessionId?: string;\n\treadonly continue?: boolean;\n\treadonly resume?: boolean;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly pluginPackages?: readonly string[];\n\treadonly prompt?: string;\n}\n\nexport interface ClientCommandContext {\n\trunClient(command: ClientCommand): void | Promise<void>;\n}\n\nconst sessionIdOption = stringOption(\"--session-id\");\nconst continueOption = flagOption(\"--continue\");\nconst continueShortOption = flagOption(\"-c\");\nconst resumeOption = flagOption(\"--resume\");\nconst resumeShortOption = flagOption(\"-r\");\nconst providerOption = stringOption(\"--provider\");\nconst modelOption = stringOption(\"--model\");\nconst pluginPackageOption = stringOption(\"-e\", { repeatable: true });\n\nexport const clientCommand = new Command<ClientCommand, ClientCommandContext>(\"client\")\n\t.option(connectOption)\n\t.option(sessionIdOption)\n\t.option(continueOption)\n\t.option(continueShortOption)\n\t.option(resumeOption)\n\t.option(resumeShortOption)\n\t.option(providerOption)\n\t.option(modelOption)\n\t.option(pluginPackageOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst connect = input.value(connectOption);\n\t\tconst sessionId = input.value(sessionIdOption);\n\t\tconst shouldContinue = input.value(continueOption) === true || input.value(continueShortOption) === true;\n\t\tconst shouldResume = input.value(resumeOption) === true || input.value(resumeShortOption) === true;\n\t\tconst provider = input.value(providerOption);\n\t\tconst model = input.value(modelOption);\n\t\tconst pluginPackages = input.values(pluginPackageOption);\n\t\tconst promptArgs = input.remainingArgs[0] === \"--\" ? input.remainingArgs.slice(1) : input.remainingArgs;\n\t\tconst prompt =\n\t\t\tpromptArgs.length === 1 &&\n\t\t\t(input.remainingArgs[0] === \"--\" || !promptArgs[0]!.startsWith(\"-\")) &&\n\t\t\tpromptArgs[0]!.length > 0\n\t\t\t\t? promptArgs[0]\n\t\t\t\t: undefined;\n\t\tconst modelErrors = provider !== undefined && model === undefined ? [\"--provider requires --model\"] : [];\n\t\tconst sessionSelectionErrors =\n\t\t\t[sessionId !== undefined, shouldContinue, shouldResume].filter(Boolean).length > 1\n\t\t\t\t? [\"--session-id, --continue, and --resume are mutually exclusive\"]\n\t\t\t\t: [];\n\t\tconst unsupportedErrors =\n\t\t\tinput.remainingArgs.length === 0 || prompt !== undefined ? [] : unsupportedOptions(\"client\", input);\n\t\tconst errors = [...authErrors, ...modelErrors, ...sessionSelectionErrors, ...unsupportedErrors];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"client\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(connect === undefined ? {} : { connect }),\n\t\t\t\t...(sessionId === undefined ? {} : { sessionId }),\n\t\t\t\t...(shouldContinue ? { continue: true } : {}),\n\t\t\t\t...(shouldResume ? { resume: true } : {}),\n\t\t\t\t...(provider === undefined ? {} : { provider }),\n\t\t\t\t...(model === undefined ? {} : { model }),\n\t\t\t\t...(pluginPackages.length === 0 ? {} : { pluginPackages }),\n\t\t\t\t...(prompt === undefined ? {} : { prompt }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runClient(command));\n"]}
@@ -1,63 +0,0 @@
1
- import { Command, flagOption, stringOption } from "../command.js";
2
- import { authTokenFileOption, authTokenOption, connectOption, parseAuth, unsupportedOptions, } from "../command-options.js";
3
- const sessionIdOption = stringOption("--session-id");
4
- const continueOption = flagOption("--continue");
5
- const continueShortOption = flagOption("-c");
6
- const resumeOption = flagOption("--resume");
7
- const resumeShortOption = flagOption("-r");
8
- const providerOption = stringOption("--provider");
9
- const modelOption = stringOption("--model");
10
- const pluginPackageOption = stringOption("-e", { repeatable: true });
11
- export const clientCommand = new Command("client")
12
- .option(connectOption)
13
- .option(sessionIdOption)
14
- .option(continueOption)
15
- .option(continueShortOption)
16
- .option(resumeOption)
17
- .option(resumeShortOption)
18
- .option(providerOption)
19
- .option(modelOption)
20
- .option(pluginPackageOption)
21
- .option(authTokenOption)
22
- .option(authTokenFileOption)
23
- .build((input) => {
24
- const { auth, errors: authErrors } = parseAuth(input);
25
- const connect = input.value(connectOption);
26
- const sessionId = input.value(sessionIdOption);
27
- const shouldContinue = input.value(continueOption) === true || input.value(continueShortOption) === true;
28
- const shouldResume = input.value(resumeOption) === true || input.value(resumeShortOption) === true;
29
- const provider = input.value(providerOption);
30
- const model = input.value(modelOption);
31
- const pluginPackages = input.values(pluginPackageOption);
32
- const promptArgs = input.remainingArgs[0] === "--" ? input.remainingArgs.slice(1) : input.remainingArgs;
33
- const prompt = promptArgs.length === 1 &&
34
- (input.remainingArgs[0] === "--" || !promptArgs[0].startsWith("-")) &&
35
- promptArgs[0].length > 0
36
- ? promptArgs[0]
37
- : undefined;
38
- const modelErrors = provider !== undefined && model === undefined ? ["--provider requires --model"] : [];
39
- const sessionSelectionErrors = [sessionId !== undefined, shouldContinue, shouldResume].filter(Boolean).length > 1
40
- ? ["--session-id, --continue, and --resume are mutually exclusive"]
41
- : [];
42
- const unsupportedErrors = input.remainingArgs.length === 0 || prompt !== undefined ? [] : unsupportedOptions("client", input);
43
- const errors = [...authErrors, ...modelErrors, ...sessionSelectionErrors, ...unsupportedErrors];
44
- if (errors.length > 0)
45
- return { ok: false, errors };
46
- return {
47
- ok: true,
48
- command: {
49
- command: "client",
50
- ...(auth === undefined ? {} : { auth }),
51
- ...(connect === undefined ? {} : { connect }),
52
- ...(sessionId === undefined ? {} : { sessionId }),
53
- ...(shouldContinue ? { continue: true } : {}),
54
- ...(shouldResume ? { resume: true } : {}),
55
- ...(provider === undefined ? {} : { provider }),
56
- ...(model === undefined ? {} : { model }),
57
- ...(pluginPackages.length === 0 ? {} : { pluginPackages }),
58
- ...(prompt === undefined ? {} : { prompt }),
59
- },
60
- };
61
- })
62
- .action((command, context) => context.runClient(command));
63
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAEN,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,SAAS,EAET,kBAAkB,GAClB,MAAM,uBAAuB,CAAC;AAmB/B,MAAM,eAAe,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AACrD,MAAM,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAChD,MAAM,mBAAmB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AAC7C,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;AAC5C,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AAC3C,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,WAAW,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;AAC5C,MAAM,mBAAmB,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,aAAa,GAAG,IAA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AC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;YACvC,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;YAC7C,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;YACjD,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7C,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;YAC/C,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YACzC,GAAG,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC;YAC1D,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;SAC3C;KACD,CAAC;AAAA,CACF,CAAC;KACD,MAAM,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC","sourcesContent":["import { Command, flagOption, stringOption } from \"../command.ts\";\nimport {\n\ttype AuthInput,\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tconnectOption,\n\tparseAuth,\n\ttype TransportAddress,\n\tunsupportedOptions,\n} from \"../command-options.ts\";\n\nexport interface ClientCommand {\n\treadonly command: \"client\";\n\treadonly auth?: AuthInput;\n\treadonly connect?: TransportAddress;\n\treadonly sessionId?: string;\n\treadonly continue?: boolean;\n\treadonly resume?: boolean;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly pluginPackages?: readonly string[];\n\treadonly prompt?: string;\n}\n\nexport interface ClientCommandContext {\n\trunClient(command: ClientCommand): void | Promise<void>;\n}\n\nconst sessionIdOption = stringOption(\"--session-id\");\nconst continueOption = flagOption(\"--continue\");\nconst continueShortOption = flagOption(\"-c\");\nconst resumeOption = flagOption(\"--resume\");\nconst resumeShortOption = flagOption(\"-r\");\nconst providerOption = stringOption(\"--provider\");\nconst modelOption = stringOption(\"--model\");\nconst pluginPackageOption = stringOption(\"-e\", { repeatable: true });\n\nexport const clientCommand = new Command<ClientCommand, ClientCommandContext>(\"client\")\n\t.option(connectOption)\n\t.option(sessionIdOption)\n\t.option(continueOption)\n\t.option(continueShortOption)\n\t.option(resumeOption)\n\t.option(resumeShortOption)\n\t.option(providerOption)\n\t.option(modelOption)\n\t.option(pluginPackageOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst connect = input.value(connectOption);\n\t\tconst sessionId = input.value(sessionIdOption);\n\t\tconst shouldContinue = input.value(continueOption) === true || input.value(continueShortOption) === true;\n\t\tconst shouldResume = input.value(resumeOption) === true || input.value(resumeShortOption) === true;\n\t\tconst provider = input.value(providerOption);\n\t\tconst model = input.value(modelOption);\n\t\tconst pluginPackages = input.values(pluginPackageOption);\n\t\tconst promptArgs = input.remainingArgs[0] === \"--\" ? input.remainingArgs.slice(1) : input.remainingArgs;\n\t\tconst prompt =\n\t\t\tpromptArgs.length === 1 &&\n\t\t\t(input.remainingArgs[0] === \"--\" || !promptArgs[0]!.startsWith(\"-\")) &&\n\t\t\tpromptArgs[0]!.length > 0\n\t\t\t\t? promptArgs[0]\n\t\t\t\t: undefined;\n\t\tconst modelErrors = provider !== undefined && model === undefined ? [\"--provider requires --model\"] : [];\n\t\tconst sessionSelectionErrors =\n\t\t\t[sessionId !== undefined, shouldContinue, shouldResume].filter(Boolean).length > 1\n\t\t\t\t? [\"--session-id, --continue, and --resume are mutually exclusive\"]\n\t\t\t\t: [];\n\t\tconst unsupportedErrors =\n\t\t\tinput.remainingArgs.length === 0 || prompt !== undefined ? [] : unsupportedOptions(\"client\", input);\n\t\tconst errors = [...authErrors, ...modelErrors, ...sessionSelectionErrors, ...unsupportedErrors];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"client\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(connect === undefined ? {} : { connect }),\n\t\t\t\t...(sessionId === undefined ? {} : { sessionId }),\n\t\t\t\t...(shouldContinue ? { continue: true } : {}),\n\t\t\t\t...(shouldResume ? { resume: true } : {}),\n\t\t\t\t...(provider === undefined ? {} : { provider }),\n\t\t\t\t...(model === undefined ? {} : { model }),\n\t\t\t\t...(pluginPackages.length === 0 ? {} : { pluginPackages }),\n\t\t\t\t...(prompt === undefined ? {} : { prompt }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runClient(command));\n"]}
@@ -1,17 +0,0 @@
1
- import { type ServerId } from "@earendil-works/pi-protocol";
2
- import { Command } from "../command.ts";
3
- import { type AuthInput } from "../command-options.ts";
4
- export interface ServerCommand {
5
- readonly command: "server";
6
- readonly auth?: AuthInput;
7
- readonly provider?: string;
8
- readonly model?: string;
9
- readonly pluginPackages?: readonly string[];
10
- readonly serverId?: ServerId;
11
- readonly sessionDir?: string;
12
- }
13
- export interface ServerCommandContext {
14
- runServer(command: ServerCommand): void | Promise<void>;
15
- }
16
- export declare const serverCommand: Command<ServerCommand, ServerCommandContext, ServerCommand>;
17
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,OAAO,EAA6B,MAAM,eAAe,CAAC;AACnE,OAAO,EACN,KAAK,SAAS,EAKd,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACpC,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAYD,eAAO,MAAM,aAAa,6DA+BgC,CAAC","sourcesContent":["import { isServerId, type ServerId } from \"@earendil-works/pi-protocol\";\nimport { Command, stringOption, valueOption } from \"../command.ts\";\nimport {\n\ttype AuthInput,\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tparseAuth,\n\tunsupportedOptions,\n} from \"../command-options.ts\";\n\nexport interface ServerCommand {\n\treadonly command: \"server\";\n\treadonly auth?: AuthInput;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly pluginPackages?: readonly string[];\n\treadonly serverId?: ServerId;\n\treadonly sessionDir?: string;\n}\n\nexport interface ServerCommandContext {\n\trunServer(command: ServerCommand): void | Promise<void>;\n}\n\nconst serverIdOption = valueOption(\"--server-id\", (value) =>\n\tisServerId(value)\n\t\t? { ok: true, value }\n\t\t: { ok: false, error: `Invalid --server-id \"${value}\"; expected a lowercase UUIDv4` },\n);\nconst sessionDirOption = stringOption(\"--session-dir\");\nconst providerOption = stringOption(\"--provider\");\nconst modelOption = stringOption(\"--model\");\nconst pluginPackageOption = stringOption(\"-e\", { repeatable: true });\n\nexport const serverCommand = new Command<ServerCommand, ServerCommandContext>(\"server\")\n\t.option(serverIdOption)\n\t.option(sessionDirOption)\n\t.option(providerOption)\n\t.option(modelOption)\n\t.option(pluginPackageOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst serverId = input.value(serverIdOption);\n\t\tconst sessionDir = input.value(sessionDirOption);\n\t\tconst provider = input.value(providerOption);\n\t\tconst model = input.value(modelOption);\n\t\tconst pluginPackages = input.values(pluginPackageOption);\n\t\tconst modelErrors = provider !== undefined && model === undefined ? [\"--provider requires --model\"] : [];\n\t\tconst errors = [...authErrors, ...modelErrors, ...unsupportedOptions(\"server\", input)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"server\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(provider === undefined ? {} : { provider }),\n\t\t\t\t...(model === undefined ? {} : { model }),\n\t\t\t\t...(pluginPackages.length === 0 ? {} : { pluginPackages }),\n\t\t\t\t...(serverId === undefined ? {} : { serverId }),\n\t\t\t\t...(sessionDir === undefined ? {} : { sessionDir }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runServer(command));\n"]}
@@ -1,44 +0,0 @@
1
- import { isServerId } from "@earendil-works/pi-protocol";
2
- import { Command, stringOption, valueOption } from "../command.js";
3
- import { authTokenFileOption, authTokenOption, parseAuth, unsupportedOptions, } from "../command-options.js";
4
- const serverIdOption = valueOption("--server-id", (value) => isServerId(value)
5
- ? { ok: true, value }
6
- : { ok: false, error: `Invalid --server-id "${value}"; expected a lowercase UUIDv4` });
7
- const sessionDirOption = stringOption("--session-dir");
8
- const providerOption = stringOption("--provider");
9
- const modelOption = stringOption("--model");
10
- const pluginPackageOption = stringOption("-e", { repeatable: true });
11
- export const serverCommand = new Command("server")
12
- .option(serverIdOption)
13
- .option(sessionDirOption)
14
- .option(providerOption)
15
- .option(modelOption)
16
- .option(pluginPackageOption)
17
- .option(authTokenOption)
18
- .option(authTokenFileOption)
19
- .build((input) => {
20
- const { auth, errors: authErrors } = parseAuth(input);
21
- const serverId = input.value(serverIdOption);
22
- const sessionDir = input.value(sessionDirOption);
23
- const provider = input.value(providerOption);
24
- const model = input.value(modelOption);
25
- const pluginPackages = input.values(pluginPackageOption);
26
- const modelErrors = provider !== undefined && model === undefined ? ["--provider requires --model"] : [];
27
- const errors = [...authErrors, ...modelErrors, ...unsupportedOptions("server", input)];
28
- if (errors.length > 0)
29
- return { ok: false, errors };
30
- return {
31
- ok: true,
32
- command: {
33
- command: "server",
34
- ...(auth === undefined ? {} : { auth }),
35
- ...(provider === undefined ? {} : { provider }),
36
- ...(model === undefined ? {} : { model }),
37
- ...(pluginPackages.length === 0 ? {} : { pluginPackages }),
38
- ...(serverId === undefined ? {} : { serverId }),
39
- ...(sessionDir === undefined ? {} : { sessionDir }),
40
- },
41
- };
42
- })
43
- .action((command, context) => context.runServer(command));
44
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/cli/experimental/commands/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAEN,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,kBAAkB,GAClB,MAAM,uBAAuB,CAAC;AAgB/B,MAAM,cAAc,GAAG,WAAW,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAC3D,UA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ol\";\nimport { Command, stringOption, valueOption } from \"../command.ts\";\nimport {\n\ttype AuthInput,\n\tauthTokenFileOption,\n\tauthTokenOption,\n\tparseAuth,\n\tunsupportedOptions,\n} from \"../command-options.ts\";\n\nexport interface ServerCommand {\n\treadonly command: \"server\";\n\treadonly auth?: AuthInput;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly pluginPackages?: readonly string[];\n\treadonly serverId?: ServerId;\n\treadonly sessionDir?: string;\n}\n\nexport interface ServerCommandContext {\n\trunServer(command: ServerCommand): void | Promise<void>;\n}\n\nconst serverIdOption = valueOption(\"--server-id\", (value) =>\n\tisServerId(value)\n\t\t? { ok: true, value }\n\t\t: { ok: false, error: `Invalid --server-id \"${value}\"; expected a lowercase UUIDv4` },\n);\nconst sessionDirOption = stringOption(\"--session-dir\");\nconst providerOption = stringOption(\"--provider\");\nconst modelOption = stringOption(\"--model\");\nconst pluginPackageOption = stringOption(\"-e\", { repeatable: true });\n\nexport const serverCommand = new Command<ServerCommand, ServerCommandContext>(\"server\")\n\t.option(serverIdOption)\n\t.option(sessionDirOption)\n\t.option(providerOption)\n\t.option(modelOption)\n\t.option(pluginPackageOption)\n\t.option(authTokenOption)\n\t.option(authTokenFileOption)\n\t.build((input) => {\n\t\tconst { auth, errors: authErrors } = parseAuth(input);\n\t\tconst serverId = input.value(serverIdOption);\n\t\tconst sessionDir = input.value(sessionDirOption);\n\t\tconst provider = input.value(providerOption);\n\t\tconst model = input.value(modelOption);\n\t\tconst pluginPackages = input.values(pluginPackageOption);\n\t\tconst modelErrors = provider !== undefined && model === undefined ? [\"--provider requires --model\"] : [];\n\t\tconst errors = [...authErrors, ...modelErrors, ...unsupportedOptions(\"server\", input)];\n\t\tif (errors.length > 0) return { ok: false, errors };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tcommand: {\n\t\t\t\tcommand: \"server\",\n\t\t\t\t...(auth === undefined ? {} : { auth }),\n\t\t\t\t...(provider === undefined ? {} : { provider }),\n\t\t\t\t...(model === undefined ? {} : { model }),\n\t\t\t\t...(pluginPackages.length === 0 ? {} : { pluginPackages }),\n\t\t\t\t...(serverId === undefined ? {} : { serverId }),\n\t\t\t\t...(sessionDir === undefined ? {} : { sessionDir }),\n\t\t\t},\n\t\t};\n\t})\n\t.action((command, context) => context.runServer(command));\n"]}
@@ -1,2 +0,0 @@
1
- export * from "@earendil-works/pi-client";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC","sourcesContent":["export * from \"@earendil-works/pi-client\";\n"]}
@@ -1,2 +0,0 @@
1
- export * from "@earendil-works/pi-client";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC","sourcesContent":["export * from \"@earendil-works/pi-client\";\n"]}
@@ -1,43 +0,0 @@
1
- import { Client } from "@earendil-works/pi-client";
2
- import { type UnixServerRoute } from "@earendil-works/pi-client/unix";
3
- import { type ServerId } from "@earendil-works/pi-protocol";
4
- import type { ClientCommand } from "../cli/experimental/commands/client.ts";
5
- import { AgentController } from "./services/agent-controller.ts";
6
- import { type ServerServiceSource, type SessionServiceSource } from "./services/connection.ts";
7
- import { Models } from "./services/models.ts";
8
- import { PresentationPlugins } from "./services/plugins.ts";
9
- import { SessionDirectory, SessionManagement } from "./services/sessions.ts";
10
- import { Transcript } from "./services/transcript.ts";
11
- export type ClientRuntimeRoute = ({
12
- readonly transport: "unix";
13
- } & UnixServerRoute) | {
14
- readonly transport: "radius";
15
- readonly serverId: ServerId;
16
- };
17
- export interface ClientRuntimeServer {
18
- readonly route: ClientRuntimeRoute;
19
- readonly client: Client;
20
- readonly server: ServerServiceSource;
21
- readonly session: SessionServiceSource;
22
- }
23
- export interface ActivatedClientRuntimeServer extends ClientRuntimeServer {
24
- readonly directory: SessionDirectory;
25
- readonly management: SessionManagement;
26
- readonly plugins: PresentationPlugins;
27
- readonly models: Models;
28
- readonly agent: AgentController;
29
- readonly transcript: Transcript;
30
- }
31
- export interface ClientRuntime {
32
- readonly servers: readonly ClientRuntimeServer[];
33
- dispose(): Promise<void>;
34
- }
35
- export interface OpenClientRuntimeOptions {
36
- /** Directory searched when --connect is omitted. Defaults to PI_SERVER_DIR or ~/.pi/server. */
37
- readonly directory?: string;
38
- }
39
- /** Open live server/session service namespaces for one experimental presentation. */
40
- export declare function openClientRuntime(command: ClientCommand, options?: OpenClientRuntimeOptions): Promise<ClientRuntime>;
41
- /** Acquire and connect the built-in service facades used by the non-interactive client. */
42
- export declare function activateBuiltinClientServices(server: ClientRuntimeServer): Promise<ActivatedClientRuntimeServer>;
43
- //# sourceMappingURL=client-runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-runtime.d.ts","sourceRoot":"","sources":["../../src/experimental/client-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAe,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAmD,KAAK,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACvH,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAI5E,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAGN,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,MAAM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ONTEXT } from \"@earendil-works/chord/context\";\nimport { Client, ServerError } from \"@earendil-works/pi-client\";\nimport { createUnixTransportFactory, discoverUnixServers, type UnixServerRoute } from \"@earendil-works/pi-client/unix\";\nimport { isServerId, type ServerId } from \"@earendil-works/pi-protocol\";\nimport type { ClientCommand } from \"../cli/experimental/commands/client.ts\";\nimport { RadiusRelayAuthResolver } from \"./radius-auth.ts\";\nimport { createRadiusClientTransportFactory, RadiusClientReconnect } from \"./radius-relay.ts\";\nimport { activateServer, ENV_SERVER_ID, resolveServerDirectory, resolveSessionDirectory } from \"./server.ts\";\nimport { AgentController } from \"./services/agent-controller.ts\";\nimport {\n\tcreateServerServiceSource,\n\tcreateSessionServiceSource,\n\ttype ServerServiceSource,\n\ttype SessionServiceSource,\n} from \"./services/connection.ts\";\nimport { Models } from \"./services/models.ts\";\nimport { PresentationPlugins } from \"./services/plugins.ts\";\nimport { SessionDirectory, SessionManagement } from \"./services/sessions.ts\";\nimport { Transcript } from \"./services/transcript.ts\";\n\nexport type ClientRuntimeRoute =\n\t| ({ readonly transport: \"unix\" } & UnixServerRoute)\n\t| { readonly transport: \"radius\"; readonly serverId: ServerId };\n\nexport interface ClientRuntimeServer {\n\treadonly route: ClientRuntimeRoute;\n\treadonly client: Client;\n\treadonly server: ServerServiceSource;\n\treadonly session: SessionServiceSource;\n}\n\nexport interface ActivatedClientRuntimeServer extends ClientRuntimeServer {\n\treadonly directory: SessionDirectory;\n\treadonly management: SessionManagement;\n\treadonly plugins: PresentationPlugins;\n\treadonly models: Models;\n\treadonly agent: AgentController;\n\treadonly transcript: Transcript;\n}\n\nexport interface ClientRuntime {\n\treadonly servers: readonly ClientRuntimeServer[];\n\tdispose(): Promise<void>;\n}\n\nexport interface OpenClientRuntimeOptions {\n\t/** Directory searched when --connect is omitted. Defaults to PI_SERVER_DIR or ~/.pi/server. */\n\treadonly directory?: string;\n}\n\n/** Open live server/session service namespaces for one experimental presentation. */\nexport async function openClientRuntime(\n\tcommand: ClientCommand,\n\toptions: OpenClientRuntimeOptions = {},\n): Promise<ClientRuntime> {\n\tif (command.auth !== undefined && command.connect?.transport !== \"radius\") {\n\t\tthrow new Error(\"Authentication is only supported for experimental Radius connections\");\n\t}\n\tif (command.provider !== undefined && command.model === undefined) {\n\t\tthrow new Error(\"Server model provider requires a model\");\n\t}\n\tif (command.connect && command.model !== undefined) {\n\t\tthrow new Error(\"Model selection is only valid when automatically activating a new server\");\n\t}\n\tif (command.connect?.transport === \"radius\" && command.pluginPackages !== undefined) {\n\t\tthrow new Error(\"Plugin package paths can only be configured on a local Unix server\");\n\t}\n\tconst directory = resolveServerDirectory(options.directory);\n\tlet routes: ClientRuntimeRoute[];\n\tlet activatedClient: Client | undefined;\n\tif (command.connect) {\n\t\troutes = [\n\t\t\tcommand.connect.transport === \"radius\"\n\t\t\t\t? { transport: \"radius\", serverId: command.connect.serverId }\n\t\t\t\t: { transport: \"unix\", ...routeFromExplicitPath(command.connect.path) },\n\t\t];\n\t} else {\n\t\troutes = (await discoverUnixServers({ directory })).map((route) => ({ transport: \"unix\", ...route }));\n\t\tif (routes.length > 0 && command.model !== undefined) {\n\t\t\tthrow new Error(\"Model selection is only valid when automatically activating a new server\");\n\t\t}\n\t\tif (routes.length === 0) {\n\t\t\tconst activated = await activateServer({\n\t\t\t\tdirectory,\n\t\t\t\trequestedServerId: process.env[ENV_SERVER_ID],\n\t\t\t\tsessionDir: resolveSessionDirectory(),\n\t\t\t\tprovider: command.provider,\n\t\t\t\tmodel: command.model,\n\t\t\t});\n\t\t\troutes = [{ transport: \"unix\", ...activated.route }];\n\t\t\tactivatedClient = activated.client;\n\t\t}\n\t}\n\tif (command.pluginPackages !== undefined && routes.length !== 1) {\n\t\tthrow new Error(\"Plugin selection requires exactly one local server\");\n\t}\n\n\tconst clients: Client[] = [];\n\tconst reconnectors: RadiusClientReconnect[] = [];\n\tconst serviceSources: Array<ServerServiceSource | SessionServiceSource> = [];\n\tconst servers: ClientRuntimeServer[] = [];\n\tlet disposed = false;\n\tconst dispose = async (): Promise<void> => {\n\t\tif (disposed) return;\n\t\tdisposed = true;\n\t\tconst reconnectResults = await Promise.allSettled(reconnectors.map((reconnector) => reconnector.dispose()));\n\t\tconst sourceResults = await Promise.allSettled(\n\t\t\tserviceSources.map((source) => source.dispose(BACKGROUND_CONTEXT)),\n\t\t);\n\t\tconst clientResults = await Promise.allSettled(clients.map((client) => client.dispose()));\n\t\tconst errors = [...reconnectResults, ...sourceResults, ...clientResults].flatMap((result) =>\n\t\t\tresult.status === \"rejected\" ? [result.reason] : [],\n\t\t);\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose experimental client runtime\");\n\t};\n\n\ttry {\n\t\tfor (const route of routes) {\n\t\t\tlet client = activatedClient;\n\t\t\tif (client === undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tclient = await Client.connect({\n\t\t\t\t\t\tserverId: route.serverId,\n\t\t\t\t\t\ttransportFactory:\n\t\t\t\t\t\t\troute.transport === \"unix\"\n\t\t\t\t\t\t\t\t? createUnixTransportFactory({ path: route.path })\n\t\t\t\t\t\t\t\t: createRadiusClientTransportFactory({\n\t\t\t\t\t\t\t\t\t\tserverId: route.serverId,\n\t\t\t\t\t\t\t\t\t\tauth: new RadiusRelayAuthResolver(command.auth),\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tcommand.connect !== undefined ||\n\t\t\t\t\t\troute.transport !== \"unix\" ||\n\t\t\t\t\t\t!(error instanceof ServerError) ||\n\t\t\t\t\t\terror.code !== \"version\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tclient = (\n\t\t\t\t\t\tawait activateServer({\n\t\t\t\t\t\t\tdirectory,\n\t\t\t\t\t\t\trequestedServerId: route.serverId,\n\t\t\t\t\t\t\tsessionDir: resolveSessionDirectory(),\n\t\t\t\t\t\t})\n\t\t\t\t\t).client;\n\t\t\t\t}\n\t\t\t}\n\t\t\tactivatedClient = undefined;\n\t\t\tclients.push(client);\n\t\t\tconst server = createServerServiceSource(client);\n\t\t\tserviceSources.push(server);\n\t\t\tif (route.transport === \"radius\") {\n\t\t\t\tconst reconnectServices = server.open({\n\t\t\t\t\tservices: [SessionManagement],\n\t\t\t\t\tassertAccess() {},\n\t\t\t\t\tonError() {},\n\t\t\t\t});\n\t\t\t\tconst reconnectManagement = reconnectServices.use(SessionManagement);\n\t\t\t\treconnectors.push(\n\t\t\t\t\tnew RadiusClientReconnect(client, async (sessionId) => {\n\t\t\t\t\t\tawait reconnectServices.ready(BACKGROUND_CONTEXT);\n\t\t\t\t\t\tawait reconnectManagement.attach(sessionId, BACKGROUND_CONTEXT);\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst session = createSessionServiceSource(client);\n\t\t\tserviceSources.push(session);\n\t\t\tservers.push({ route, client, server, session });\n\t\t}\n\t\treturn { servers, dispose };\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait dispose();\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], \"Experimental client startup and cleanup failed\");\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/** Acquire and connect the built-in service facades used by the non-interactive client. */\nexport async function activateBuiltinClientServices(\n\tserver: ClientRuntimeServer,\n): Promise<ActivatedClientRuntimeServer> {\n\tconst serverServices = server.server.open({\n\t\tservices: [SessionDirectory, SessionManagement, PresentationPlugins],\n\t\tassertAccess() {},\n\t\tonError() {},\n\t});\n\tconst sessionServices = server.session.open({\n\t\tservices: [Models, AgentController, Transcript],\n\t\tassertAccess() {},\n\t\tonError() {},\n\t});\n\tconst directory = serverServices.use(SessionDirectory);\n\tconst remoteManagement = serverServices.use(SessionManagement);\n\tconst management: SessionManagement = {\n\t\tcreate: (options, context) => remoteManagement.create(options, context),\n\t\tasync remove(sessionId, context) {\n\t\t\tconst removesCurrentAttachment = server.client.attachment?.sessionId === sessionId;\n\t\t\tawait remoteManagement.remove(sessionId, context);\n\t\t\tif (removesCurrentAttachment) await server.session.whenDetached(context);\n\t\t},\n\t\tasync attach(sessionId, context) {\n\t\t\tawait remoteManagement.attach(sessionId, context);\n\t\t\tawait server.session.whenAttached(sessionId, context);\n\t\t},\n\t\tasync detach(context) {\n\t\t\tawait remoteManagement.detach(context);\n\t\t\tawait server.session.whenDetached(context);\n\t\t},\n\t};\n\tconst plugins = serverServices.use(PresentationPlugins);\n\tconst models = sessionServices.use(Models);\n\tconst agent = sessionServices.use(AgentController);\n\tconst transcript = sessionServices.use(Transcript);\n\tawait Promise.all([serverServices.ready(BACKGROUND_CONTEXT), sessionServices.ready(BACKGROUND_CONTEXT)]);\n\treturn { ...server, directory, management, plugins, models, agent, transcript };\n}\n\nfunction routeFromExplicitPath(path: string): UnixServerRoute {\n\tconst name = basename(path);\n\tconst serverId = name.endsWith(\".sock\") ? name.slice(0, -\".sock\".length) : \"\";\n\tif (!isServerId(serverId)) throw new Error(\"--connect path must end with <uuidv4-server-id>.sock\");\n\treturn { serverId, path };\n}\n"]}