@cjhyy/code-shell-core 0.5.0-rc.2 → 0.6.0-rc.10

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 (396) hide show
  1. package/README.md +13 -10
  2. package/dist/agent/agent-definition-registry.d.ts +3 -0
  3. package/dist/agent/agent-definition-registry.js +3 -1
  4. package/dist/agent/agent-definition.d.ts +15 -0
  5. package/dist/agent/agent-definition.js +27 -3
  6. package/dist/arena/context/context-tools.js +47 -4
  7. package/dist/arena/ledger.js +9 -1
  8. package/dist/arena/strategies/utils.d.ts +1 -4
  9. package/dist/arena/strategies/utils.js +7 -84
  10. package/dist/automation/cron-expr.d.ts +10 -0
  11. package/dist/automation/cron-expr.js +23 -5
  12. package/dist/automation/runner.d.ts +21 -4
  13. package/dist/automation/runner.js +48 -12
  14. package/dist/automation/scheduler.d.ts +38 -0
  15. package/dist/automation/scheduler.js +89 -12
  16. package/dist/automation/store.js +5 -2
  17. package/dist/capability-control/disabled-lists.d.ts +25 -0
  18. package/dist/capability-control/disabled-lists.js +57 -0
  19. package/dist/capability-control/overlay.d.ts +15 -0
  20. package/dist/capability-control/overlay.js +27 -0
  21. package/dist/cc-orchestrator/agent-adapter.d.ts +50 -0
  22. package/dist/cc-orchestrator/agent-adapter.js +133 -0
  23. package/dist/cc-orchestrator/cc-capability.d.ts +19 -0
  24. package/dist/cc-orchestrator/cc-capability.js +53 -0
  25. package/dist/cc-orchestrator/codex-session-discovery.d.ts +24 -0
  26. package/dist/cc-orchestrator/codex-session-discovery.js +191 -0
  27. package/dist/cc-orchestrator/codex-session-history.d.ts +25 -0
  28. package/dist/cc-orchestrator/codex-session-history.js +187 -0
  29. package/dist/cc-orchestrator/external-agent-changes.d.ts +19 -0
  30. package/dist/cc-orchestrator/external-agent-changes.js +214 -0
  31. package/dist/cc-orchestrator/external-agent-driver.d.ts +18 -0
  32. package/dist/cc-orchestrator/external-agent-driver.js +69 -0
  33. package/dist/cc-orchestrator/index.d.ts +8 -0
  34. package/dist/cc-orchestrator/index.js +8 -0
  35. package/dist/cc-orchestrator/relevance-judge.d.ts +15 -0
  36. package/dist/cc-orchestrator/relevance-judge.js +29 -0
  37. package/dist/cc-orchestrator/session-discovery.d.ts +46 -0
  38. package/dist/cc-orchestrator/session-discovery.js +125 -0
  39. package/dist/cc-orchestrator/session-history.d.ts +19 -0
  40. package/dist/cc-orchestrator/session-history.js +67 -0
  41. package/dist/cli/agent-server-stdio.d.ts +15 -1
  42. package/dist/cli/agent-server-stdio.js +115 -17
  43. package/dist/cli/agent-server-tcp.js +40 -26
  44. package/dist/context/compaction.d.ts +86 -0
  45. package/dist/context/compaction.js +279 -0
  46. package/dist/context/manager.d.ts +18 -0
  47. package/dist/context/manager.js +181 -48
  48. package/dist/context/token-counter.js +13 -0
  49. package/dist/cost-tracker.js +5 -61
  50. package/dist/credentials/cipher.d.ts +49 -0
  51. package/dist/credentials/cipher.js +45 -0
  52. package/dist/credentials/cookie-jar.d.ts +24 -0
  53. package/dist/credentials/cookie-jar.js +40 -0
  54. package/dist/credentials/index.d.ts +7 -0
  55. package/dist/credentials/index.js +5 -0
  56. package/dist/credentials/inject-credential-tool.d.ts +20 -0
  57. package/dist/credentials/inject-credential-tool.js +130 -0
  58. package/dist/credentials/store.d.ts +72 -0
  59. package/dist/credentials/store.js +184 -0
  60. package/dist/credentials/types.d.ts +56 -0
  61. package/dist/credentials/use-credential-tool.d.ts +29 -0
  62. package/dist/credentials/use-credential-tool.js +205 -0
  63. package/dist/credentials/use-gate.d.ts +56 -0
  64. package/dist/credentials/use-gate.js +52 -0
  65. package/dist/data/model-metadata.d.ts +77 -0
  66. package/dist/data/model-metadata.js +56 -0
  67. package/dist/data/model-metadata.json +216 -0
  68. package/dist/data/openrouter-models.d.ts +18 -7
  69. package/dist/data/openrouter-models.js +35 -8
  70. package/dist/engine/aux-key.d.ts +10 -0
  71. package/dist/engine/aux-key.js +11 -0
  72. package/dist/engine/dynamic-tool-defs.d.ts +19 -0
  73. package/dist/engine/dynamic-tool-defs.js +36 -0
  74. package/dist/engine/engine.d.ts +280 -141
  75. package/dist/engine/engine.js +1193 -245
  76. package/dist/engine/friendly-error.d.ts +18 -0
  77. package/dist/engine/friendly-error.js +63 -0
  78. package/dist/engine/goal.d.ts +145 -0
  79. package/dist/engine/goal.js +144 -0
  80. package/dist/engine/image-policy.d.ts +13 -0
  81. package/dist/engine/image-policy.js +24 -0
  82. package/dist/engine/model-connections-pool.d.ts +17 -0
  83. package/dist/engine/model-connections-pool.js +67 -0
  84. package/dist/engine/model-facade.d.ts +10 -0
  85. package/dist/engine/model-facade.js +15 -0
  86. package/dist/engine/patch-orphaned-tools.js +3 -0
  87. package/dist/engine/query.js +2 -0
  88. package/dist/engine/resolve-llm-config.d.ts +16 -0
  89. package/dist/engine/resolve-llm-config.js +44 -0
  90. package/dist/engine/runtime.d.ts +2 -0
  91. package/dist/engine/runtime.js +27 -1
  92. package/dist/engine/sandbox-cache-key.d.ts +10 -0
  93. package/dist/engine/sandbox-cache-key.js +9 -0
  94. package/dist/engine/sandbox-config.d.ts +31 -0
  95. package/dist/engine/sandbox-config.js +38 -0
  96. package/dist/engine/session-usage.d.ts +31 -0
  97. package/dist/engine/session-usage.js +81 -0
  98. package/dist/engine/steer-queue.d.ts +33 -0
  99. package/dist/engine/steer-queue.js +26 -0
  100. package/dist/engine/streaming-tool-queue.d.ts +12 -0
  101. package/dist/engine/streaming-tool-queue.js +50 -10
  102. package/dist/engine/turn-loop.d.ts +94 -4
  103. package/dist/engine/turn-loop.js +432 -54
  104. package/dist/engine/types.d.ts +175 -0
  105. package/dist/engine/types.js +13 -0
  106. package/dist/external-agents/config.d.ts +2 -0
  107. package/dist/external-agents/config.js +15 -0
  108. package/dist/external-agents/types.d.ts +31 -0
  109. package/dist/external-agents/types.js +1 -0
  110. package/dist/git/utils.d.ts +12 -0
  111. package/dist/git/utils.js +38 -6
  112. package/dist/git/worktree.d.ts +48 -0
  113. package/dist/git/worktree.js +86 -10
  114. package/dist/hooks/goal-stop-hook.d.ts +28 -0
  115. package/dist/hooks/goal-stop-hook.js +186 -9
  116. package/dist/hooks/registry.d.ts +8 -0
  117. package/dist/hooks/registry.js +19 -0
  118. package/dist/hooks/shell-runner.js +10 -21
  119. package/dist/index.d.ts +51 -7
  120. package/dist/index.js +62 -5
  121. package/dist/llm/capabilities/param-specs.d.ts +14 -0
  122. package/dist/llm/capabilities/param-specs.js +62 -0
  123. package/dist/llm/capabilities/rules.js +5 -1
  124. package/dist/llm/capabilities/types.d.ts +10 -0
  125. package/dist/llm/client-base.d.ts +28 -1
  126. package/dist/llm/client-base.js +119 -13
  127. package/dist/llm/model-cache.js +4 -2
  128. package/dist/llm/model-pool.d.ts +21 -0
  129. package/dist/llm/model-pool.js +21 -1
  130. package/dist/llm/provider-auth.d.ts +41 -0
  131. package/dist/llm/provider-auth.js +76 -0
  132. package/dist/llm/provider-catalog.d.ts +4 -0
  133. package/dist/llm/providers/anthropic.js +64 -14
  134. package/dist/llm/providers/openai.d.ts +36 -0
  135. package/dist/llm/providers/openai.js +257 -51
  136. package/dist/llm/reasoning-setting.d.ts +3 -3
  137. package/dist/llm/reasoning-setting.js +9 -1
  138. package/dist/llm/stream-watchdog.js +5 -1
  139. package/dist/llm/token-counter.js +9 -2
  140. package/dist/llm/types.d.ts +4 -0
  141. package/dist/logging/sanitize-messages.js +22 -0
  142. package/dist/lsp/manager.d.ts +1 -1
  143. package/dist/lsp/manager.js +40 -10
  144. package/dist/model-catalog/builtin.d.ts +12 -0
  145. package/dist/model-catalog/builtin.js +412 -0
  146. package/dist/model-catalog/gen-connections.d.ts +20 -0
  147. package/dist/model-catalog/gen-connections.js +28 -0
  148. package/dist/model-catalog/index.d.ts +41 -0
  149. package/dist/model-catalog/index.js +90 -0
  150. package/dist/model-catalog/params.d.ts +20 -0
  151. package/dist/model-catalog/params.js +45 -0
  152. package/dist/model-catalog/resolve.d.ts +48 -0
  153. package/dist/model-catalog/resolve.js +33 -0
  154. package/dist/model-catalog/save-entry.d.ts +32 -0
  155. package/dist/model-catalog/save-entry.js +104 -0
  156. package/dist/model-catalog/types.d.ts +561 -0
  157. package/dist/model-catalog/types.js +93 -0
  158. package/dist/model-catalog/upsert.d.ts +9 -0
  159. package/dist/model-catalog/upsert.js +8 -0
  160. package/dist/onboarding.d.ts +12 -82
  161. package/dist/onboarding.js +61 -326
  162. package/dist/plugins/gitOps.d.ts +19 -0
  163. package/dist/plugins/gitOps.js +73 -4
  164. package/dist/plugins/installer/checkUpdate.d.ts +16 -0
  165. package/dist/plugins/installer/checkUpdate.js +32 -0
  166. package/dist/plugins/installer/codex/convertCommands.d.ts +19 -0
  167. package/dist/plugins/installer/codex/convertCommands.js +46 -0
  168. package/dist/plugins/installer/codex/convertMcp.d.ts +5 -2
  169. package/dist/plugins/installer/codex/convertMcp.js +45 -5
  170. package/dist/plugins/installer/install.js +25 -1
  171. package/dist/plugins/installer/installFromArchive.d.ts +43 -0
  172. package/dist/plugins/installer/installFromArchive.js +134 -0
  173. package/dist/plugins/installer/installFromSource.js +8 -2
  174. package/dist/plugins/installer/loadPluginAgents.js +6 -2
  175. package/dist/plugins/installer/loadPluginMcp.d.ts +9 -2
  176. package/dist/plugins/installer/loadPluginMcp.js +35 -2
  177. package/dist/plugins/installer/pruneDisabled.d.ts +24 -0
  178. package/dist/plugins/installer/pruneDisabled.js +73 -0
  179. package/dist/plugins/installer/types.d.ts +5 -2
  180. package/dist/plugins/installer/types.js +1 -0
  181. package/dist/plugins/installer/uninstall.js +4 -0
  182. package/dist/plugins/installer/unzip.d.ts +14 -0
  183. package/dist/plugins/installer/unzip.js +82 -0
  184. package/dist/plugins/installer/update.d.ts +14 -0
  185. package/dist/plugins/installer/update.js +53 -21
  186. package/dist/plugins/loadPluginHooks.d.ts +47 -1
  187. package/dist/plugins/loadPluginHooks.js +73 -1
  188. package/dist/plugins/marketplaceManager.d.ts +7 -0
  189. package/dist/plugins/marketplaceManager.js +20 -0
  190. package/dist/plugins/pluginCommandHook.js +4 -18
  191. package/dist/plugins/pluginContent.d.ts +30 -0
  192. package/dist/plugins/pluginContent.js +83 -0
  193. package/dist/plugins/pluginInstaller.d.ts +13 -0
  194. package/dist/plugins/pluginInstaller.js +42 -8
  195. package/dist/plugins/schemas.js +1 -0
  196. package/dist/plugins/types.d.ts +6 -0
  197. package/dist/preset/index.d.ts +11 -1
  198. package/dist/preset/index.js +115 -6
  199. package/dist/product/types.d.ts +1 -1
  200. package/dist/prompt/composer.d.ts +32 -0
  201. package/dist/prompt/composer.js +75 -21
  202. package/dist/prompt/instruction-scanner.js +5 -3
  203. package/dist/prompt/section-loader.js +1 -0
  204. package/dist/prompt/sections/base.md +2 -0
  205. package/dist/prompt/sections/browser.md +10 -0
  206. package/dist/prompt/sections/coding.md +4 -0
  207. package/dist/protocol/chat-session-manager.d.ts +9 -2
  208. package/dist/protocol/chat-session-manager.js +38 -0
  209. package/dist/protocol/chat-session.d.ts +69 -1
  210. package/dist/protocol/chat-session.js +102 -4
  211. package/dist/protocol/client.d.ts +31 -0
  212. package/dist/protocol/client.js +44 -0
  213. package/dist/protocol/server.d.ts +120 -7
  214. package/dist/protocol/server.js +753 -51
  215. package/dist/protocol/transport.js +3 -2
  216. package/dist/protocol/types.d.ts +60 -0
  217. package/dist/protocol/types.js +16 -0
  218. package/dist/quota/credentials.d.ts +3 -0
  219. package/dist/quota/credentials.js +80 -0
  220. package/dist/quota/index.d.ts +36 -0
  221. package/dist/quota/index.js +155 -0
  222. package/dist/quota/types.d.ts +48 -0
  223. package/dist/quota/types.js +13 -0
  224. package/dist/review/review-prompt.d.ts +28 -0
  225. package/dist/review/review-prompt.js +81 -0
  226. package/dist/run/FileRunStore.js +8 -3
  227. package/dist/run/RunApprovalBackend.js +25 -5
  228. package/dist/run/RunManager.d.ts +12 -0
  229. package/dist/run/RunManager.js +35 -0
  230. package/dist/run/factory.d.ts +1 -1
  231. package/dist/runtime/background-shell.d.ts +139 -0
  232. package/dist/runtime/background-shell.js +509 -0
  233. package/dist/runtime/output-clean.d.ts +24 -0
  234. package/dist/runtime/output-clean.js +41 -0
  235. package/dist/runtime/ring-file.d.ts +64 -0
  236. package/dist/runtime/ring-file.js +174 -0
  237. package/dist/runtime/safe-spawn.js +98 -39
  238. package/dist/runtime/spawn-common.d.ts +159 -0
  239. package/dist/runtime/spawn-common.js +404 -0
  240. package/dist/runtime/truncate-output.d.ts +22 -0
  241. package/dist/runtime/truncate-output.js +49 -0
  242. package/dist/runtime/utf8-cut.d.ts +11 -0
  243. package/dist/runtime/utf8-cut.js +23 -0
  244. package/dist/services/auto-dream.d.ts +4 -0
  245. package/dist/services/auto-dream.js +26 -26
  246. package/dist/services/diagnostics.d.ts +1 -2
  247. package/dist/services/diagnostics.js +12 -7
  248. package/dist/services/extract-memories.d.ts +14 -1
  249. package/dist/services/extract-memories.js +45 -6
  250. package/dist/services/memory-orchestrator.d.ts +21 -0
  251. package/dist/services/memory-orchestrator.js +125 -50
  252. package/dist/services/session-memory.js +24 -12
  253. package/dist/session/file-history.d.ts +124 -1
  254. package/dist/session/file-history.js +222 -6
  255. package/dist/session/memory.d.ts +116 -2
  256. package/dist/session/memory.js +250 -28
  257. package/dist/session/session-manager.d.ts +40 -0
  258. package/dist/session/session-manager.js +119 -3
  259. package/dist/session/simple-diff.d.ts +23 -0
  260. package/dist/session/simple-diff.js +84 -0
  261. package/dist/session/transcript.d.ts +29 -1
  262. package/dist/session/transcript.js +56 -2
  263. package/dist/session/undo-target.d.ts +67 -0
  264. package/dist/session/undo-target.js +144 -0
  265. package/dist/settings/disk-defaults.d.ts +9 -2
  266. package/dist/settings/disk-defaults.js +11 -2
  267. package/dist/settings/feature-flags.d.ts +64 -0
  268. package/dist/settings/feature-flags.js +61 -0
  269. package/dist/settings/manager.d.ts +68 -1
  270. package/dist/settings/manager.js +266 -29
  271. package/dist/settings/migrate-config.d.ts +45 -0
  272. package/dist/settings/migrate-config.js +125 -0
  273. package/dist/settings/schema-export.d.ts +25 -0
  274. package/dist/settings/schema-export.js +38 -0
  275. package/dist/settings/schema.d.ts +1186 -771
  276. package/dist/settings/schema.js +268 -97
  277. package/dist/skills/scanner.d.ts +9 -0
  278. package/dist/skills/scanner.js +30 -2
  279. package/dist/stt/resolve-transcribe.d.ts +31 -0
  280. package/dist/stt/resolve-transcribe.js +108 -0
  281. package/dist/stt/transcribe.d.ts +51 -0
  282. package/dist/stt/transcribe.js +65 -0
  283. package/dist/tool-system/browser-bridge.d.ts +226 -0
  284. package/dist/tool-system/browser-bridge.js +163 -0
  285. package/dist/tool-system/builtin/agent-heartbeat.d.ts +49 -0
  286. package/dist/tool-system/builtin/agent-heartbeat.js +89 -0
  287. package/dist/tool-system/builtin/agent-notifications.d.ts +12 -3
  288. package/dist/tool-system/builtin/agent-notifications.js +9 -3
  289. package/dist/tool-system/builtin/agent-output-file.d.ts +38 -0
  290. package/dist/tool-system/builtin/agent-output-file.js +72 -0
  291. package/dist/tool-system/builtin/agent-registry.d.ts +12 -0
  292. package/dist/tool-system/builtin/agent-registry.js +8 -0
  293. package/dist/tool-system/builtin/agent.d.ts +21 -1
  294. package/dist/tool-system/builtin/agent.js +489 -42
  295. package/dist/tool-system/builtin/apply-patch/applier.js +66 -8
  296. package/dist/tool-system/builtin/apply-patch/backup-targets.d.ts +10 -0
  297. package/dist/tool-system/builtin/apply-patch/backup-targets.js +30 -0
  298. package/dist/tool-system/builtin/apply-patch/index.js +0 -15
  299. package/dist/tool-system/builtin/background-jobs.d.ts +76 -0
  300. package/dist/tool-system/builtin/background-jobs.js +124 -0
  301. package/dist/tool-system/builtin/background-shell-tools.d.ts +20 -0
  302. package/dist/tool-system/builtin/background-shell-tools.js +108 -0
  303. package/dist/tool-system/builtin/background-work.d.ts +67 -0
  304. package/dist/tool-system/builtin/background-work.js +86 -0
  305. package/dist/tool-system/builtin/bash-output-style.d.ts +32 -0
  306. package/dist/tool-system/builtin/bash-output-style.js +40 -0
  307. package/dist/tool-system/builtin/bash.d.ts +5 -2
  308. package/dist/tool-system/builtin/bash.js +101 -64
  309. package/dist/tool-system/builtin/browser-tools.d.ts +33 -0
  310. package/dist/tool-system/builtin/browser-tools.js +312 -0
  311. package/dist/tool-system/builtin/cancel-goal.d.ts +31 -0
  312. package/dist/tool-system/builtin/cancel-goal.js +64 -0
  313. package/dist/tool-system/builtin/check-quota.d.ts +15 -0
  314. package/dist/tool-system/builtin/check-quota.js +34 -0
  315. package/dist/tool-system/builtin/config.js +7 -0
  316. package/dist/tool-system/builtin/cron.d.ts +7 -0
  317. package/dist/tool-system/builtin/cron.js +64 -4
  318. package/dist/tool-system/builtin/drive-claude-code.d.ts +30 -0
  319. package/dist/tool-system/builtin/drive-claude-code.js +157 -0
  320. package/dist/tool-system/builtin/edit-model-catalog.d.ts +3 -0
  321. package/dist/tool-system/builtin/edit-model-catalog.js +104 -0
  322. package/dist/tool-system/builtin/edit.js +20 -16
  323. package/dist/tool-system/builtin/eol.d.ts +29 -0
  324. package/dist/tool-system/builtin/eol.js +37 -0
  325. package/dist/tool-system/builtin/file-cache.d.ts +6 -0
  326. package/dist/tool-system/builtin/file-cache.js +8 -0
  327. package/dist/tool-system/builtin/generate-image.d.ts +35 -0
  328. package/dist/tool-system/builtin/generate-image.js +278 -50
  329. package/dist/tool-system/builtin/generate-video.d.ts +55 -0
  330. package/dist/tool-system/builtin/generate-video.js +364 -0
  331. package/dist/tool-system/builtin/glob.js +0 -7
  332. package/dist/tool-system/builtin/grep.d.ts +9 -0
  333. package/dist/tool-system/builtin/grep.js +106 -11
  334. package/dist/tool-system/builtin/image-providers.d.ts +86 -0
  335. package/dist/tool-system/builtin/image-providers.js +190 -0
  336. package/dist/tool-system/builtin/image-uploader.d.ts +33 -0
  337. package/dist/tool-system/builtin/image-uploader.js +74 -0
  338. package/dist/tool-system/builtin/index.d.ts +10 -2
  339. package/dist/tool-system/builtin/index.js +251 -27
  340. package/dist/tool-system/builtin/mcp-tools.js +23 -3
  341. package/dist/tool-system/builtin/memory.js +45 -7
  342. package/dist/tool-system/builtin/notebook-edit.js +0 -7
  343. package/dist/tool-system/builtin/powershell.js +8 -2
  344. package/dist/tool-system/builtin/read.js +10 -10
  345. package/dist/tool-system/builtin/repl.js +4 -1
  346. package/dist/tool-system/builtin/skill.js +9 -0
  347. package/dist/tool-system/builtin/sleep.js +8 -2
  348. package/dist/tool-system/builtin/tool-search.js +25 -7
  349. package/dist/tool-system/builtin/video-providers.d.ts +154 -0
  350. package/dist/tool-system/builtin/video-providers.js +235 -0
  351. package/dist/tool-system/builtin/web-fetch.js +12 -2
  352. package/dist/tool-system/builtin/web-search.js +21 -7
  353. package/dist/tool-system/builtin/worktree.d.ts +2 -1
  354. package/dist/tool-system/builtin/worktree.js +31 -4
  355. package/dist/tool-system/builtin/write.js +0 -6
  356. package/dist/tool-system/context.d.ts +164 -6
  357. package/dist/tool-system/executor.d.ts +3 -1
  358. package/dist/tool-system/executor.js +197 -90
  359. package/dist/tool-system/investigation-guard.js +1 -1
  360. package/dist/tool-system/mcp-manager.d.ts +42 -4
  361. package/dist/tool-system/mcp-manager.js +203 -20
  362. package/dist/tool-system/mcp-stdio-diagnostics.d.ts +9 -0
  363. package/dist/tool-system/mcp-stdio-diagnostics.js +93 -0
  364. package/dist/tool-system/path-policy.d.ts +5 -0
  365. package/dist/tool-system/path-policy.js +307 -8
  366. package/dist/tool-system/permission.d.ts +39 -2
  367. package/dist/tool-system/permission.js +283 -70
  368. package/dist/tool-system/plan-mode-allowlist.d.ts +13 -2
  369. package/dist/tool-system/plan-mode-allowlist.js +24 -2
  370. package/dist/tool-system/registry.d.ts +1 -0
  371. package/dist/tool-system/registry.js +16 -2
  372. package/dist/tool-system/sandbox/index.d.ts +8 -0
  373. package/dist/tool-system/sandbox/index.js +7 -2
  374. package/dist/tool-system/sandbox/off.js +7 -1
  375. package/dist/tool-system/validate-tool-metadata.d.ts +36 -0
  376. package/dist/tool-system/validate-tool-metadata.js +63 -0
  377. package/dist/types.d.ts +252 -7
  378. package/dist/updater.js +20 -9
  379. package/dist/utils/envUtils.d.ts +0 -9
  380. package/dist/utils/envUtils.js +3 -28
  381. package/dist/utils/exec.d.ts +48 -0
  382. package/dist/utils/exec.js +154 -0
  383. package/dist/utils/json.d.ts +12 -0
  384. package/dist/utils/json.js +92 -0
  385. package/dist/utils/theme.d.ts +1 -1
  386. package/dist/utils/theme.js +1 -1
  387. package/dist/utils/toolDisplay.js +0 -1
  388. package/package.json +13 -7
  389. package/dist/agent/coordinator.d.ts +0 -49
  390. package/dist/agent/coordinator.js +0 -77
  391. package/dist/settings/manager.test.js +0 -73
  392. package/dist/tool-system/builtin/remote-trigger.d.ts +0 -6
  393. package/dist/tool-system/builtin/remote-trigger.js +0 -54
  394. package/dist/tool-system/builtin/send-message.d.ts +0 -6
  395. package/dist/tool-system/builtin/send-message.js +0 -47
  396. /package/dist/{settings/manager.test.d.ts → credentials/types.js} +0 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * CredentialUseGate — 凭证取用前的轻量三档审批(凭证模块第二期 §5)。
3
+ *
4
+ * AI 的 `UseCredential` 工具在把某条凭证的值/cookies.txt 交给命令**之前**过这道门:
5
+ * 1. **全自动**:settings `credentialUse.autoApprove === true` → 直接放行,不弹。
6
+ * 2. **本会话记住**:用户上次选了「本会话记住」→ 该凭证 id 进内存 allow 集 → 后续放行。
7
+ * 3. **默认弹审批**:经 `askUser`(InteractiveApprovalBackend)问一次。
8
+ *
9
+ * 关键决策(见设计稿 §5 + memory project_permission_session_cache):
10
+ * - 本会话记住**按凭证 id 键**,不按工具名 —— 否则一次批准会放行对无关凭证的取用。
11
+ * - 会话 allow 集是**纯内存**(关 app 即忘),由 Engine 持有并注入,故 gate 本身无模块级单例,
12
+ * 多 Engine 并发互不干扰、可整块外移。
13
+ *
14
+ * 边界:gate 只依赖 `askUser`(既有审批后端)+ 一个内存 Set + settings 读取,不耦合 core 其它部分。
15
+ */
16
+ /** AI 取用一条凭证的请求(供审批文案 + 记忆键)。 */
17
+ export interface CredentialUseRequest {
18
+ /** 凭证 id(记忆键)。 */
19
+ id: string;
20
+ /** 展示名(审批文案)。 */
21
+ label: string;
22
+ /** 可选用途(审批文案)。 */
23
+ purpose?: string;
24
+ }
25
+ export type CredentialUseDecision = {
26
+ allowed: true;
27
+ } | {
28
+ allowed: false;
29
+ reason: "denied" | "no-ui";
30
+ };
31
+ /** 本会话已批准的凭证 id 集(纯内存,Engine 持有并跨 turn 复用)。 */
32
+ export type SessionCredentialAllow = Set<string>;
33
+ /** 审批问询函数(对接 ToolContext.askUser;返回用户所选 label)。 */
34
+ export type CredentialAskFn = (question: string, opts: {
35
+ header?: string;
36
+ options: {
37
+ label: string;
38
+ description: string;
39
+ tone?: "ok" | "danger" | "neutral";
40
+ }[];
41
+ optionsOnly: true;
42
+ }) => Promise<string>;
43
+ export interface CredentialUseGateDeps {
44
+ /** settings `credentialUse.autoApprove`(全局总闸)。 */
45
+ autoApprove: boolean;
46
+ /** 该凭证自身的逐条「AI 可自动取用」标志(Credential.autoUseByAI);命中即放行。 */
47
+ credentialAutoUse?: boolean;
48
+ /** 本会话 allow 集(内存,可变;gate 命中「本会话记住」时写入)。 */
49
+ sessionAllow: SessionCredentialAllow;
50
+ /** 审批问询(undefined → 无 UI,headless 直接拒)。 */
51
+ ask?: CredentialAskFn;
52
+ }
53
+ /**
54
+ * 过门并返回是否放行。命中「本会话记住」会写入 `deps.sessionAllow`。
55
+ */
56
+ export declare function credentialUseGate(req: CredentialUseRequest, deps: CredentialUseGateDeps): Promise<CredentialUseDecision>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * CredentialUseGate — 凭证取用前的轻量三档审批(凭证模块第二期 §5)。
3
+ *
4
+ * AI 的 `UseCredential` 工具在把某条凭证的值/cookies.txt 交给命令**之前**过这道门:
5
+ * 1. **全自动**:settings `credentialUse.autoApprove === true` → 直接放行,不弹。
6
+ * 2. **本会话记住**:用户上次选了「本会话记住」→ 该凭证 id 进内存 allow 集 → 后续放行。
7
+ * 3. **默认弹审批**:经 `askUser`(InteractiveApprovalBackend)问一次。
8
+ *
9
+ * 关键决策(见设计稿 §5 + memory project_permission_session_cache):
10
+ * - 本会话记住**按凭证 id 键**,不按工具名 —— 否则一次批准会放行对无关凭证的取用。
11
+ * - 会话 allow 集是**纯内存**(关 app 即忘),由 Engine 持有并注入,故 gate 本身无模块级单例,
12
+ * 多 Engine 并发互不干扰、可整块外移。
13
+ *
14
+ * 边界:gate 只依赖 `askUser`(既有审批后端)+ 一个内存 Set + settings 读取,不耦合 core 其它部分。
15
+ */
16
+ const ALLOW_ONCE = "允许本次";
17
+ const ALLOW_SESSION = "本会话都允许";
18
+ const DENY = "拒绝";
19
+ /**
20
+ * 过门并返回是否放行。命中「本会话记住」会写入 `deps.sessionAllow`。
21
+ */
22
+ export async function credentialUseGate(req, deps) {
23
+ // 1. 全自动(全局总闸,或该凭证逐条开了「AI 可自动取用」)
24
+ if (deps.autoApprove || deps.credentialAutoUse)
25
+ return { allowed: true };
26
+ // 2. 本会话记住
27
+ if (deps.sessionAllow.has(req.id))
28
+ return { allowed: true };
29
+ // 3. 默认弹审批
30
+ if (!deps.ask)
31
+ return { allowed: false, reason: "no-ui" };
32
+ const purpose = req.purpose?.trim();
33
+ const question = purpose
34
+ ? `AI 想用凭证「${req.label}」(${purpose}),是否允许?`
35
+ : `AI 想用凭证「${req.label}」,是否允许?`;
36
+ const choice = await deps.ask(question, {
37
+ header: "凭证取用",
38
+ options: [
39
+ { label: ALLOW_ONCE, description: "仅本次取用该凭证", tone: "ok" },
40
+ { label: ALLOW_SESSION, description: "本会话内该凭证不再询问(关 app 后失效)", tone: "ok" },
41
+ { label: DENY, description: "拒绝本次取用", tone: "danger" },
42
+ ],
43
+ optionsOnly: true,
44
+ });
45
+ if (choice === ALLOW_SESSION) {
46
+ deps.sessionAllow.add(req.id);
47
+ return { allowed: true };
48
+ }
49
+ if (choice === ALLOW_ONCE)
50
+ return { allowed: true };
51
+ return { allowed: false, reason: "denied" };
52
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Hand-maintained model metadata for direct-provider models and onboarding
3
+ * picker tuning, extracted out of onboarding.ts so updating a model's
4
+ * max-output / context-window or the picker vendor list is a data edit
5
+ * (model-metadata.json) rather than a code change.
6
+ *
7
+ * Scope: only what the build-time OpenRouter snapshot does NOT cover —
8
+ * direct-provider ids (no "vendor/" prefix) for the metadata tables, plus the
9
+ * curated OpenRouter vendor ordering for the picker. OpenRouter "vendor/model"
10
+ * ids get their context/max-output from the snapshot (see data/openrouter-*).
11
+ *
12
+ * Loaded with createRequire so the bundled JSON ships in dist (the build copies
13
+ * src/data/*.json → dist/data/), matching static-catalogs.ts.
14
+ */
15
+ export interface OpenRouterVendor {
16
+ prefix: string;
17
+ take: number;
18
+ }
19
+ /** Per-1M-token pricing (USD). Mirrors cost-tracker's ModelPricing. */
20
+ export interface ModelPricing {
21
+ input: number;
22
+ output: number;
23
+ cacheRead: number;
24
+ cacheWrite: number;
25
+ }
26
+ /**
27
+ * Onboarding provider catalog entry. Pure data — the onboarding flow's logic
28
+ * (key validation, model registration, env detection) lives in onboarding.ts
29
+ * and consumes this shape. Lives here so the catalog is a data edit.
30
+ */
31
+ export interface ProviderDef {
32
+ id: string;
33
+ name: string;
34
+ envKey: string;
35
+ provider: string;
36
+ baseUrl: string;
37
+ keyUrl: string;
38
+ keyPrefix: string;
39
+ /**
40
+ * The catalog of model IDs to register for this provider. The first entry
41
+ * doubles as the zero-config default — auto-activated when the user boots
42
+ * with just an env key (no onboarding). Users override in the wizard or via
43
+ * `/model`.
44
+ */
45
+ models: string[];
46
+ /** When true, skip API key prompt (e.g. local providers like Ollama). */
47
+ noKey?: boolean;
48
+ }
49
+ /** Known max output tokens for direct-provider models (id → tokens). */
50
+ export declare const KNOWN_MAX_OUTPUT: Record<string, number>;
51
+ /** Known context window sizes for direct-provider models (id → tokens). */
52
+ export declare const KNOWN_CONTEXT_WINDOWS: Record<string, number>;
53
+ /**
54
+ * Curated vendors and how many of their newest models to surface in the
55
+ * onboarding picker. Order matters — first vendors appear first.
56
+ */
57
+ export declare const OPENROUTER_VENDORS: readonly OpenRouterVendor[];
58
+ /**
59
+ * Model-id prefix → env var holding a Vertex region override. First matching
60
+ * prefix wins (order matters); the resolver reads `process.env[name]` and falls
61
+ * back to the default region when unset. Consumed by envUtils.getVertexRegionForModel.
62
+ */
63
+ export declare const VERTEX_REGION_OVERRIDES: ReadonlyArray<readonly [string, string]>;
64
+ /**
65
+ * Per-model pricing for direct-provider ids (USD per 1M tokens), resolved to
66
+ * full ModelPricing (input/output from data, cacheRead/cacheWrite derived).
67
+ * OpenRouter vendor/model ids price from the build-time snapshot instead.
68
+ */
69
+ export declare const MODEL_PRICING: Record<string, ModelPricing>;
70
+ /** Fallback pricing for models absent from MODEL_PRICING and the snapshot. */
71
+ export declare const DEFAULT_PRICING: ModelPricing;
72
+ /**
73
+ * Onboarding provider catalog. First entry (openrouter) doubles as the
74
+ * zero-config default; each entry's models[0] is that provider's default pick.
75
+ * Consumed by onboarding.ts (key validation / model registration / env detect).
76
+ */
77
+ export declare const PROVIDERS: readonly ProviderDef[];
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Hand-maintained model metadata for direct-provider models and onboarding
3
+ * picker tuning, extracted out of onboarding.ts so updating a model's
4
+ * max-output / context-window or the picker vendor list is a data edit
5
+ * (model-metadata.json) rather than a code change.
6
+ *
7
+ * Scope: only what the build-time OpenRouter snapshot does NOT cover —
8
+ * direct-provider ids (no "vendor/" prefix) for the metadata tables, plus the
9
+ * curated OpenRouter vendor ordering for the picker. OpenRouter "vendor/model"
10
+ * ids get their context/max-output from the snapshot (see data/openrouter-*).
11
+ *
12
+ * Loaded with createRequire so the bundled JSON ships in dist (the build copies
13
+ * src/data/*.json → dist/data/), matching static-catalogs.ts.
14
+ */
15
+ import { createRequire } from "node:module";
16
+ const requireJson = createRequire(import.meta.url);
17
+ const METADATA = requireJson("./model-metadata.json");
18
+ /**
19
+ * Derive a full ModelPricing from an [input, output] pair, applying the
20
+ * standard cache-price heuristic (read = 10% of input, write = 125% of input).
21
+ * This is the same derivation the old `pricing()` helper in cost-tracker used;
22
+ * the previously-explicit Anthropic cacheRead/cacheWrite values equalled this
23
+ * heuristic exactly, so moving every entry to a pair causes zero value drift.
24
+ */
25
+ function pricingFromPair([input, output]) {
26
+ return { input, output, cacheRead: input * 0.1, cacheWrite: input * 1.25 };
27
+ }
28
+ /** Known max output tokens for direct-provider models (id → tokens). */
29
+ export const KNOWN_MAX_OUTPUT = METADATA.knownMaxOutput;
30
+ /** Known context window sizes for direct-provider models (id → tokens). */
31
+ export const KNOWN_CONTEXT_WINDOWS = METADATA.knownContextWindows;
32
+ /**
33
+ * Curated vendors and how many of their newest models to surface in the
34
+ * onboarding picker. Order matters — first vendors appear first.
35
+ */
36
+ export const OPENROUTER_VENDORS = METADATA.openRouterVendors;
37
+ /**
38
+ * Model-id prefix → env var holding a Vertex region override. First matching
39
+ * prefix wins (order matters); the resolver reads `process.env[name]` and falls
40
+ * back to the default region when unset. Consumed by envUtils.getVertexRegionForModel.
41
+ */
42
+ export const VERTEX_REGION_OVERRIDES = METADATA.vertexRegionOverrides;
43
+ /**
44
+ * Per-model pricing for direct-provider ids (USD per 1M tokens), resolved to
45
+ * full ModelPricing (input/output from data, cacheRead/cacheWrite derived).
46
+ * OpenRouter vendor/model ids price from the build-time snapshot instead.
47
+ */
48
+ export const MODEL_PRICING = Object.fromEntries(Object.entries(METADATA.pricing).map(([id, pair]) => [id, pricingFromPair(pair)]));
49
+ /** Fallback pricing for models absent from MODEL_PRICING and the snapshot. */
50
+ export const DEFAULT_PRICING = pricingFromPair(METADATA.pricingDefault);
51
+ /**
52
+ * Onboarding provider catalog. First entry (openrouter) doubles as the
53
+ * zero-config default; each entry's models[0] is that provider's default pick.
54
+ * Consumed by onboarding.ts (key validation / model registration / env detect).
55
+ */
56
+ export const PROVIDERS = METADATA.providers;
@@ -0,0 +1,216 @@
1
+ {
2
+ "_comment": "Hand-maintained metadata for direct-provider models (ids without a 'vendor/' prefix) and onboarding picker tuning. OpenRouter 'vendor/model' ids get their metadata from the build-time openrouter snapshot instead; these tables only cover what the snapshot doesn't. Edit this file (no code change) when a vendor ships a new direct-provider model or you want to tune the picker. Consumed by data/model-metadata.ts.",
3
+ "knownMaxOutput": {
4
+ "anthropic/claude-opus-4.7": 32000,
5
+ "anthropic/claude-opus-4-7": 32000,
6
+ "claude-opus-4-7": 32000,
7
+ "anthropic/claude-sonnet-4.6": 16000,
8
+ "anthropic/claude-sonnet-4-6": 16000,
9
+ "claude-sonnet-4-6": 16000,
10
+ "anthropic/claude-haiku-4.5": 8192,
11
+ "anthropic/claude-haiku-4-5": 8192,
12
+ "claude-haiku-4-5": 8192,
13
+ "openai/gpt-5": 32000,
14
+ "openai/gpt-5-mini": 32000,
15
+ "openai/gpt-5-nano": 16000,
16
+ "gpt-5": 32000,
17
+ "gpt-5-mini": 32000,
18
+ "gpt-5-nano": 16000,
19
+ "openai/gpt-4o": 16384,
20
+ "gpt-4o": 16384,
21
+ "openai/o4-mini": 100000,
22
+ "o4-mini": 100000,
23
+ "openai/o3": 100000,
24
+ "o3": 100000,
25
+ "google/gemini-2.5-pro": 65536,
26
+ "google/gemini-2.5-flash": 65536,
27
+ "gemini-2.5-pro": 65536,
28
+ "gemini-2.5-flash": 65536,
29
+ "gemini-2.0-flash": 8192,
30
+ "deepseek/deepseek-v3.2": 8192,
31
+ "deepseek/deepseek-r1": 8192,
32
+ "deepseek-v4-flash": 8192,
33
+ "deepseek-v4-pro": 65536,
34
+ "deepseek-chat": 8192,
35
+ "qwen/qwen3-coder": 16384,
36
+ "meta-llama/llama-4-maverick": 32000
37
+ },
38
+ "knownContextWindows": {
39
+ "deepseek-v4-pro": 1000000,
40
+ "deepseek-v4-flash": 1000000,
41
+ "deepseek-chat": 1000000,
42
+ "deepseek/deepseek-chat": 1000000,
43
+ "deepseek/deepseek-v4-pro": 1000000,
44
+ "deepseek/deepseek-v4-flash": 1000000
45
+ },
46
+ "openRouterVendors": [
47
+ { "prefix": "anthropic/", "take": 4 },
48
+ { "prefix": "openai/", "take": 5 },
49
+ { "prefix": "google/", "take": 3 },
50
+ { "prefix": "deepseek/", "take": 3 },
51
+ { "prefix": "x-ai/", "take": 2 },
52
+ { "prefix": "qwen/", "take": 2 },
53
+ { "prefix": "meta-llama/", "take": 2 },
54
+ { "prefix": "mistralai/", "take": 1 }
55
+ ],
56
+ "vertexRegionOverrides": [
57
+ ["claude-haiku-4-5", "VERTEX_REGION_CLAUDE_HAIKU_4_5"],
58
+ ["claude-3-5-haiku", "VERTEX_REGION_CLAUDE_3_5_HAIKU"],
59
+ ["claude-3-5-sonnet", "VERTEX_REGION_CLAUDE_3_5_SONNET"],
60
+ ["claude-3-7-sonnet", "VERTEX_REGION_CLAUDE_3_7_SONNET"],
61
+ ["claude-opus-4-1", "VERTEX_REGION_CLAUDE_4_1_OPUS"],
62
+ ["claude-opus-4", "VERTEX_REGION_CLAUDE_4_0_OPUS"],
63
+ ["claude-sonnet-4-6", "VERTEX_REGION_CLAUDE_4_6_SONNET"],
64
+ ["claude-sonnet-4-5", "VERTEX_REGION_CLAUDE_4_5_SONNET"],
65
+ ["claude-sonnet-4", "VERTEX_REGION_CLAUDE_4_0_SONNET"]
66
+ ],
67
+ "_pricingComment": "Per-1M-token USD pricing [input, output] for direct-provider models (no vendor/ snapshot). cacheRead/cacheWrite are derived by the loader: cacheRead = input*0.1, cacheWrite = input*1.25 (matches the original pricing() helper; verified the prior explicit Anthropic cacheRead/cacheWrite equalled this heuristic exactly). 'default' is the fallback for unknown models. OpenRouter vendor/model ids price from the build-time snapshot, not here.",
68
+ "pricingDefault": [3, 15],
69
+ "pricing": {
70
+ "claude-opus-4.6": [15, 75],
71
+ "claude-opus-4-6": [15, 75],
72
+ "claude-opus-4.5": [15, 75],
73
+ "claude-opus-4.1": [15, 75],
74
+ "claude-opus-4": [15, 75],
75
+ "claude-sonnet-4.6": [3, 15],
76
+ "claude-sonnet-4-6": [3, 15],
77
+ "claude-sonnet-4.5": [3, 15],
78
+ "claude-sonnet-4": [3, 15],
79
+ "claude-3.7-sonnet": [3, 15],
80
+ "claude-3-7-sonnet": [3, 15],
81
+ "claude-3.5-haiku": [0.8, 4],
82
+ "claude-haiku-4.5": [1, 5],
83
+ "claude-haiku-4-5": [1, 5],
84
+ "gpt-5.4": [5, 20],
85
+ "gpt-5.4-mini": [1.5, 6],
86
+ "gpt-5.4-pro": [10, 40],
87
+ "gpt-5": [5, 20],
88
+ "gpt-4o": [2.5, 10],
89
+ "gpt-4o-mini": [0.15, 0.6],
90
+ "gpt-4.1": [2, 8],
91
+ "gpt-4.1-mini": [0.4, 1.6],
92
+ "o4-mini": [1.1, 4.4],
93
+ "o3": [10, 40],
94
+ "o3-mini": [1.1, 4.4],
95
+ "gemini-2.5-pro": [1.25, 10],
96
+ "gemini-2.5-pro-preview": [1.25, 10],
97
+ "gemini-2.5-flash": [0.15, 0.6],
98
+ "gemini-3.1-pro-preview": [2, 10],
99
+ "gemini-3-flash-preview": [0.15, 0.6],
100
+ "gemini-2.0-flash": [0.1, 0.4],
101
+ "deepseek-v4-flash": [0.126, 0.252],
102
+ "deepseek-v4-pro": [0.5, 2],
103
+ "deepseek-v3.2": [0.14, 0.28],
104
+ "deepseek-chat": [0.14, 0.28],
105
+ "deepseek-r1": [0.55, 2.19],
106
+ "deepseek-reasoner": [0.55, 2.19],
107
+ "qwen3-coder": [0.3, 0.6],
108
+ "qwen3-235b-a22b": [0.3, 1.2],
109
+ "qwen3-30b-a3b": [0.1, 0.3],
110
+ "qwen3-max": [0.5, 2],
111
+ "llama-4-maverick": [0.2, 0.8],
112
+ "llama-4-scout": [0.15, 0.4],
113
+ "devstral-medium": [0.5, 1.5],
114
+ "mistral-large": [2, 6],
115
+ "devstral-small": [0.1, 0.3]
116
+ },
117
+ "_providersComment": "Onboarding provider catalog (consumed by onboarding.ts). First entry (openrouter) doubles as the zero-config default; its model list is ordered so models[0] is the default pick. 'provider' is the adapterKind. Edit this (no code change) to add/retune a provider in the first-run wizard. name 文案随之在此(原 onboarding hardcoded 中文).",
118
+ "providers": [
119
+ {
120
+ "id": "openrouter",
121
+ "name": "OpenRouter (推荐 — 支持所有模型)",
122
+ "envKey": "OPENROUTER_API_KEY",
123
+ "provider": "openai",
124
+ "baseUrl": "https://openrouter.ai/api/v1",
125
+ "keyUrl": "https://openrouter.ai/keys",
126
+ "keyPrefix": "sk-or-",
127
+ "models": [
128
+ "anthropic/claude-sonnet-4.6",
129
+ "anthropic/claude-opus-4.7",
130
+ "anthropic/claude-haiku-4.5",
131
+ "openai/gpt-5",
132
+ "openai/gpt-5-mini",
133
+ "openai/gpt-4o",
134
+ "openai/o4-mini",
135
+ "openai/o3",
136
+ "google/gemini-2.5-pro",
137
+ "google/gemini-2.5-flash",
138
+ "deepseek/deepseek-chat",
139
+ "deepseek/deepseek-reasoner",
140
+ "qwen/qwen3-coder",
141
+ "meta-llama/llama-4-maverick"
142
+ ]
143
+ },
144
+ {
145
+ "id": "anthropic",
146
+ "name": "Anthropic (直连 Claude API)",
147
+ "envKey": "ANTHROPIC_API_KEY",
148
+ "provider": "anthropic",
149
+ "baseUrl": "https://api.anthropic.com",
150
+ "keyUrl": "https://console.anthropic.com/settings/keys",
151
+ "keyPrefix": "sk-ant-",
152
+ "models": ["claude-sonnet-4-6", "claude-opus-4-7", "claude-haiku-4-5"]
153
+ },
154
+ {
155
+ "id": "openai",
156
+ "name": "OpenAI",
157
+ "envKey": "OPENAI_API_KEY",
158
+ "provider": "openai",
159
+ "baseUrl": "https://api.openai.com/v1",
160
+ "keyUrl": "https://platform.openai.com/api-keys",
161
+ "keyPrefix": "sk-",
162
+ "models": ["gpt-5", "gpt-5-mini", "gpt-5-nano", "gpt-4o", "o4-mini", "o3"]
163
+ },
164
+ {
165
+ "id": "deepseek",
166
+ "name": "DeepSeek (官方直连)",
167
+ "envKey": "DEEPSEEK_API_KEY",
168
+ "provider": "openai",
169
+ "baseUrl": "https://api.deepseek.com/v1",
170
+ "keyUrl": "https://platform.deepseek.com/api_keys",
171
+ "keyPrefix": "sk-",
172
+ "models": ["deepseek-v4-pro", "deepseek-v4-flash", "deepseek-chat"]
173
+ },
174
+ {
175
+ "id": "zai",
176
+ "name": "Z.AI (GLM 官方)",
177
+ "envKey": "ZAI_API_KEY",
178
+ "provider": "openai",
179
+ "baseUrl": "https://api.z.ai/api/paas/v4",
180
+ "keyUrl": "https://z.ai/manage-apikey/apikey-list",
181
+ "keyPrefix": "",
182
+ "models": ["glm-5.1", "glm-4.6", "glm-4.5-air"]
183
+ },
184
+ {
185
+ "id": "gemini",
186
+ "name": "Google Gemini (官方直连)",
187
+ "envKey": "GEMINI_API_KEY",
188
+ "provider": "openai",
189
+ "baseUrl": "https://generativelanguage.googleapis.com/v1beta/openai",
190
+ "keyUrl": "https://aistudio.google.com/apikey",
191
+ "keyPrefix": "",
192
+ "models": ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"]
193
+ },
194
+ {
195
+ "id": "ollama",
196
+ "name": "Ollama (本地,无需 Key)",
197
+ "envKey": "",
198
+ "provider": "openai",
199
+ "baseUrl": "http://localhost:11434/v1",
200
+ "keyUrl": "https://ollama.com/library",
201
+ "keyPrefix": "",
202
+ "models": ["llama3.1", "qwen2.5-coder", "deepseek-r1", "mistral", "gemma3"],
203
+ "noKey": true
204
+ },
205
+ {
206
+ "id": "custom",
207
+ "name": "自定义 (任何 OpenAI 兼容 API)",
208
+ "envKey": "",
209
+ "provider": "openai",
210
+ "baseUrl": "",
211
+ "keyUrl": "",
212
+ "keyPrefix": "",
213
+ "models": []
214
+ }
215
+ ]
216
+ }
@@ -1,13 +1,18 @@
1
1
  /**
2
- * Runtime accessor for the OpenRouter model snapshot.
2
+ * Runtime accessor for the OpenRouter model snapshot (model pricing / context /
3
+ * modality metadata). Consumers: cost-tracker, model-pool, model-fetcher,
4
+ * onboarding, and the TUI connect screen.
3
5
  *
4
- * The snapshot is generated at build time by `scripts/sync-models.ts`
5
- * from https://openrouter.ai/api/v1/models. Reading happens lazily on
6
- * first call, so the JSON is parsed at most once per process.
6
+ * The snapshot is a committed JSON file (`openrouter-models.json`), regenerated
7
+ * manually by `scripts/sync-models.ts` (NOT run automatically during build —
8
+ * copy-assets ships the existing file). It is `require`d ONCE at module load.
7
9
  *
8
- * If the snapshot is missing or empty (e.g. first checkout before a
9
- * build, or sync failure with no prior file), accessors return [] and
10
- * callers should fall back to hardcoded defaults.
10
+ * If the file is missing at load (e.g. it was deleted, mis-gitignored, or
11
+ * copy-assets was broken), the require falls back to an EMPTY snapshot instead
12
+ * of throwing the whole module would otherwise crash at import, taking down
13
+ * everything that transitively imports it. Callers already treat an empty
14
+ * `models: []` as "no metadata, use hardcoded defaults" (see model-fetcher's
15
+ * static-catalog fallback), so degrading to empty is safe.
11
16
  */
12
17
  export interface OpenRouterModel {
13
18
  id: string;
@@ -25,6 +30,12 @@ interface Snapshot {
25
30
  count: number;
26
31
  models: OpenRouterModel[];
27
32
  }
33
+ /**
34
+ * Coerce an arbitrary `require`d value into a valid Snapshot, or the empty
35
+ * snapshot if it's malformed (missing/non-array `models`). Pure + exported so
36
+ * the missing/corrupt-file degradation is unit-testable without touching disk.
37
+ */
38
+ export declare function coerceSnapshot(raw: unknown): Snapshot;
28
39
  /** Replace the in-memory snapshot for the rest of this process. */
29
40
  export declare function setOpenRouterSnapshot(next: Snapshot): void;
30
41
  export declare function getOpenRouterSnapshot(): Snapshot;
@@ -1,18 +1,45 @@
1
1
  /**
2
- * Runtime accessor for the OpenRouter model snapshot.
2
+ * Runtime accessor for the OpenRouter model snapshot (model pricing / context /
3
+ * modality metadata). Consumers: cost-tracker, model-pool, model-fetcher,
4
+ * onboarding, and the TUI connect screen.
3
5
  *
4
- * The snapshot is generated at build time by `scripts/sync-models.ts`
5
- * from https://openrouter.ai/api/v1/models. Reading happens lazily on
6
- * first call, so the JSON is parsed at most once per process.
6
+ * The snapshot is a committed JSON file (`openrouter-models.json`), regenerated
7
+ * manually by `scripts/sync-models.ts` (NOT run automatically during build —
8
+ * copy-assets ships the existing file). It is `require`d ONCE at module load.
7
9
  *
8
- * If the snapshot is missing or empty (e.g. first checkout before a
9
- * build, or sync failure with no prior file), accessors return [] and
10
- * callers should fall back to hardcoded defaults.
10
+ * If the file is missing at load (e.g. it was deleted, mis-gitignored, or
11
+ * copy-assets was broken), the require falls back to an EMPTY snapshot instead
12
+ * of throwing the whole module would otherwise crash at import, taking down
13
+ * everything that transitively imports it. Callers already treat an empty
14
+ * `models: []` as "no metadata, use hardcoded defaults" (see model-fetcher's
15
+ * static-catalog fallback), so degrading to empty is safe.
11
16
  */
12
17
  import { createRequire } from "node:module";
13
18
  const requireJson = createRequire(import.meta.url);
14
- const bundled = requireJson("./openrouter-models.json");
19
+ const EMPTY_SNAPSHOT = { fetchedAt: "", source: "", count: 0, models: [] };
20
+ const bundled = loadBundled();
15
21
  let runtimeOverride = null;
22
+ /**
23
+ * Coerce an arbitrary `require`d value into a valid Snapshot, or the empty
24
+ * snapshot if it's malformed (missing/non-array `models`). Pure + exported so
25
+ * the missing/corrupt-file degradation is unit-testable without touching disk.
26
+ */
27
+ export function coerceSnapshot(raw) {
28
+ if (raw && typeof raw === "object" && Array.isArray(raw.models)) {
29
+ return raw;
30
+ }
31
+ return EMPTY_SNAPSHOT;
32
+ }
33
+ /** require the committed snapshot once; degrade to empty (never throw) if the
34
+ * file is missing/corrupt so importing this module can't crash the process. */
35
+ function loadBundled() {
36
+ try {
37
+ return coerceSnapshot(requireJson("./openrouter-models.json"));
38
+ }
39
+ catch {
40
+ return EMPTY_SNAPSHOT;
41
+ }
42
+ }
16
43
  function loadSnapshot() {
17
44
  return runtimeOverride ?? bundled;
18
45
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * resolveAuxKey — pick the pool key for the background/aux client. Reads the
3
+ * unified store's settings.defaults.auxText (a connection id, also the pool
4
+ * key). Empty strings are treated as unset. (legacy settings.auxModelKey 已删除)
5
+ */
6
+ export declare function resolveAuxKey(settings: {
7
+ defaults?: {
8
+ auxText?: string;
9
+ };
10
+ }): string | undefined;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * resolveAuxKey — pick the pool key for the background/aux client. Reads the
3
+ * unified store's settings.defaults.auxText (a connection id, also the pool
4
+ * key). Empty strings are treated as unset. (legacy settings.auxModelKey 已删除)
5
+ */
6
+ export function resolveAuxKey(settings) {
7
+ const unified = settings.defaults?.auxText;
8
+ if (unified)
9
+ return unified;
10
+ return undefined;
11
+ }
@@ -0,0 +1,19 @@
1
+ import type { ToolDefinition } from "../types.js";
2
+ import type { AgentDefinitionRegistry } from "../agent/agent-definition-registry.js";
3
+ /**
4
+ * Rewrite a single tool definition with the live, per-engine dynamic bits the
5
+ * static def can't carry (the model only ever sees what we hand it each turn):
6
+ *
7
+ * - Agent: append the available-agent-types listing to the description AND
8
+ * forward the rebuilt inputSchema. The schema carries the `agent_type` enum
9
+ * of loaded role names — forwarding ONLY the description (the prior bug) left
10
+ * agent_type a free optional string, so the model silently omitted it and the
11
+ * configured roles' model/tools/skills never applied.
12
+ * - GenerateImage / GenerateVideo: name the configured providers in the
13
+ * description (these defs never rebuild inputSchema, so description-only is
14
+ * correct and intentional for them).
15
+ *
16
+ * Non-matching tools are returned by identity (no allocation). Pure: it never
17
+ * mutates the input or any shared const.
18
+ */
19
+ export declare function applyDynamicToolDef(t: ToolDefinition, agentDefinitions: AgentDefinitionRegistry | undefined, guardCwd: string): ToolDefinition;
@@ -0,0 +1,36 @@
1
+ import { agentToolDefWithTypes } from "../tool-system/builtin/agent.js";
2
+ import { generateImageToolDefFor } from "../tool-system/builtin/generate-image.js";
3
+ import { generateVideoToolDefFor } from "../tool-system/builtin/generate-video.js";
4
+ import { useCredentialToolDefFor } from "../credentials/use-credential-tool.js";
5
+ /**
6
+ * Rewrite a single tool definition with the live, per-engine dynamic bits the
7
+ * static def can't carry (the model only ever sees what we hand it each turn):
8
+ *
9
+ * - Agent: append the available-agent-types listing to the description AND
10
+ * forward the rebuilt inputSchema. The schema carries the `agent_type` enum
11
+ * of loaded role names — forwarding ONLY the description (the prior bug) left
12
+ * agent_type a free optional string, so the model silently omitted it and the
13
+ * configured roles' model/tools/skills never applied.
14
+ * - GenerateImage / GenerateVideo: name the configured providers in the
15
+ * description (these defs never rebuild inputSchema, so description-only is
16
+ * correct and intentional for them).
17
+ *
18
+ * Non-matching tools are returned by identity (no allocation). Pure: it never
19
+ * mutates the input or any shared const.
20
+ */
21
+ export function applyDynamicToolDef(t, agentDefinitions, guardCwd) {
22
+ if (t.name === "Agent") {
23
+ const def = agentToolDefWithTypes(agentDefinitions);
24
+ return { ...t, description: def.description, inputSchema: def.inputSchema };
25
+ }
26
+ if (t.name === "GenerateImage") {
27
+ return { ...t, description: generateImageToolDefFor(guardCwd).description };
28
+ }
29
+ if (t.name === "GenerateVideo") {
30
+ return { ...t, description: generateVideoToolDefFor(guardCwd).description };
31
+ }
32
+ if (t.name === "UseCredential") {
33
+ return { ...t, description: useCredentialToolDefFor(guardCwd).description };
34
+ }
35
+ return t;
36
+ }