micro-models-agent 2.16.1 → 2.17.2

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 (428) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +8 -3
  3. package/dist/assets/app.js +1 -314
  4. package/dist/assets/hljs.js +5 -1244
  5. package/dist/assets/index.html +11 -0
  6. package/dist/assets/js/api.js +1 -28
  7. package/dist/assets/js/core/menus.js +1 -0
  8. package/dist/assets/js/core/store/feed.js +1 -0
  9. package/dist/assets/js/core/store/index.js +1 -0
  10. package/dist/assets/js/core/store/session.js +1 -0
  11. package/dist/assets/js/core/store/settings.js +1 -0
  12. package/dist/assets/js/core/store/tabs.js +1 -0
  13. package/dist/assets/js/dialog.js +1 -105
  14. package/dist/assets/js/dom.js +1 -178
  15. package/dist/assets/js/feed/core.js +1 -0
  16. package/dist/assets/js/feed/history.js +1 -0
  17. package/dist/assets/js/feed/plan.js +1 -0
  18. package/dist/assets/js/feed/question.js +3 -0
  19. package/dist/assets/js/feed/sidebar.js +1 -0
  20. package/dist/assets/js/feed/stream.js +1 -0
  21. package/dist/assets/js/feed/turn.js +5 -0
  22. package/dist/assets/js/feed.js +1 -1250
  23. package/dist/assets/js/format.js +2 -122
  24. package/dist/assets/js/i18n.js +1 -46
  25. package/dist/assets/js/rail.js +1 -114
  26. package/dist/assets/js/session/cmdk.js +1 -0
  27. package/dist/assets/js/session/composer.js +1 -0
  28. package/dist/assets/js/session/sessions-menu.js +1 -0
  29. package/dist/assets/js/session/tabs.js +1 -0
  30. package/dist/assets/js/settings/controls.js +1 -0
  31. package/dist/assets/js/settings/editors.js +1 -0
  32. package/dist/assets/js/settings/form.js +1 -0
  33. package/dist/assets/js/settings/modal.js +1 -0
  34. package/dist/assets/js/settings/panels.js +1 -0
  35. package/dist/assets/js/settings/providers.js +1 -0
  36. package/dist/assets/js/settings/search.js +1 -0
  37. package/dist/assets/js/settings/subdialog.js +1 -0
  38. package/dist/assets/js/settings/write.js +1 -0
  39. package/dist/assets/js/settings.js +1 -1914
  40. package/dist/assets/js/sidebar/core.js +1 -0
  41. package/dist/assets/js/sidebar/lsp.js +2 -0
  42. package/dist/assets/js/sidebar/map.js +1 -0
  43. package/dist/assets/js/sidebar/state.js +1 -0
  44. package/dist/assets/js/sidebar/trace.js +5 -0
  45. package/dist/assets/js/sidebar.js +1 -705
  46. package/dist/assets/js/store.js +1 -82
  47. package/dist/assets/js/subdialog.js +1 -0
  48. package/dist/assets/md.js +1 -291
  49. package/dist/assets/setup.js +3 -816
  50. package/dist/assets/smd.js +29 -1665
  51. package/dist/assets/styles.css +1 -1598
  52. package/dist/certification/certifications.json +1 -494
  53. package/dist/i18n/en.json +1 -1851
  54. package/dist/i18n/ru.json +1 -1854
  55. package/dist/main.js +815 -55797
  56. package/dist/modules/browser/bridge-server.mjs +2 -252
  57. package/package.json +10 -5
  58. package/dist/assets/js/settings-controls.js +0 -452
  59. package/dist/assets/js/tabs.js +0 -867
  60. package/dist/cli/cache-line.js +0 -31
  61. package/dist/cli/command-suggest.js +0 -39
  62. package/dist/cli/commands.js +0 -781
  63. package/dist/cli/completer.js +0 -268
  64. package/dist/cli/index.js +0 -3
  65. package/dist/cli/json-payload.js +0 -32
  66. package/dist/cli/main.js +0 -346
  67. package/dist/cli/onboarding-commands.js +0 -126
  68. package/dist/cli/plugin-commands.js +0 -38
  69. package/dist/cli/relaunch.js +0 -40
  70. package/dist/cli/repl-commands-lsp.js +0 -75
  71. package/dist/cli/repl-commands-skills.js +0 -105
  72. package/dist/cli/repl-commands.js +0 -1218
  73. package/dist/cli/repl.js +0 -1238
  74. package/dist/cli/run-result.js +0 -38
  75. package/dist/cli/security-commands.js +0 -177
  76. package/dist/cli/setup-order.js +0 -6
  77. package/dist/cli/setup-prompt.js +0 -50
  78. package/dist/cli/setup.js +0 -161
  79. package/dist/cli/web-command.js +0 -98
  80. package/dist/config/budget.js +0 -48
  81. package/dist/config/config.js +0 -345
  82. package/dist/config/defaults.js +0 -197
  83. package/dist/config/domains.js +0 -135
  84. package/dist/config/env.js +0 -46
  85. package/dist/config/experts.js +0 -17
  86. package/dist/config/index.js +0 -5
  87. package/dist/config/paths.js +0 -56
  88. package/dist/config/redact.js +0 -44
  89. package/dist/config/registry-extra.js +0 -334
  90. package/dist/config/registry.js +0 -584
  91. package/dist/config/security.js +0 -212
  92. package/dist/config/timeouts.js +0 -74
  93. package/dist/config/types.js +0 -1
  94. package/dist/config/utils.js +0 -57
  95. package/dist/core/agent/artifact-progress.js +0 -59
  96. package/dist/core/agent/artifact-resolve.js +0 -79
  97. package/dist/core/agent/audit-gate.js +0 -53
  98. package/dist/core/agent/compaction.js +0 -89
  99. package/dist/core/agent/constants.js +0 -90
  100. package/dist/core/agent/context-log.js +0 -454
  101. package/dist/core/agent/context-renderer.js +0 -45
  102. package/dist/core/agent/critic-gate.js +0 -132
  103. package/dist/core/agent/hallucination-gate.js +0 -197
  104. package/dist/core/agent/loop-state.js +0 -68
  105. package/dist/core/agent/prefix-monitor.js +0 -101
  106. package/dist/core/agent/reasoning-resolver.js +0 -65
  107. package/dist/core/agent/token-tracker.js +0 -99
  108. package/dist/core/agent/tool-batch.js +0 -312
  109. package/dist/core/agent/tool-images.js +0 -18
  110. package/dist/core/agent/tool-output.js +0 -116
  111. package/dist/core/agent/tool-pairing.js +0 -60
  112. package/dist/core/agent-moe.js +0 -248
  113. package/dist/core/agent.js +0 -1299
  114. package/dist/core/bootstrap/agent-phase.js +0 -66
  115. package/dist/core/bootstrap/config-phase.js +0 -86
  116. package/dist/core/bootstrap/modules-phase.js +0 -269
  117. package/dist/core/bootstrap/provider-phase.js +0 -183
  118. package/dist/core/bootstrap/session-phase.js +0 -204
  119. package/dist/core/bootstrap/state.js +0 -94
  120. package/dist/core/bootstrap/workspace-phase.js +0 -115
  121. package/dist/core/bootstrap.js +0 -112
  122. package/dist/core/crash-handler.js +0 -62
  123. package/dist/core/environment.js +0 -224
  124. package/dist/core/host-plan.js +0 -43
  125. package/dist/core/host.js +0 -23
  126. package/dist/core/index.js +0 -3
  127. package/dist/core/prompt-builder.js +0 -95
  128. package/dist/core/prompt-overflow.js +0 -306
  129. package/dist/core/session-logger.js +0 -375
  130. package/dist/core/system-prompt.js +0 -117
  131. package/dist/core/types.js +0 -1
  132. package/dist/core/version.js +0 -28
  133. package/dist/core/web-host.js +0 -34
  134. package/dist/core/workspace.js +0 -80
  135. package/dist/i18n/index.js +0 -80
  136. package/dist/index.js +0 -30
  137. package/dist/llm/cache-usage.js +0 -76
  138. package/dist/llm/image-utils.js +0 -138
  139. package/dist/llm/index.js +0 -4
  140. package/dist/llm/llm-errors.js +0 -50
  141. package/dist/llm/model-loader.js +0 -86
  142. package/dist/llm/models-dev.js +0 -121
  143. package/dist/llm/openai-compat.js +0 -756
  144. package/dist/llm/orchestrator.js +0 -294
  145. package/dist/llm/provider-budget.js +0 -68
  146. package/dist/llm/provider-context.js +0 -233
  147. package/dist/llm/provider.js +0 -9
  148. package/dist/llm/response.js +0 -44
  149. package/dist/llm/stream-state.js +0 -26
  150. package/dist/llm/token-counter.js +0 -83
  151. package/dist/llm/types.js +0 -1
  152. package/dist/logger/app-logger.js +0 -212
  153. package/dist/logger/file-log.js +0 -160
  154. package/dist/logger/index.js +0 -2
  155. package/dist/migration/backup.js +0 -56
  156. package/dist/migration/detect.js +0 -61
  157. package/dist/migration/index.js +0 -3
  158. package/dist/modules/artifacts/store.js +0 -62
  159. package/dist/modules/browser/actions.js +0 -79
  160. package/dist/modules/browser/bridge-client.js +0 -203
  161. package/dist/modules/browser/bridge-path.js +0 -10
  162. package/dist/modules/browser/console-buffer.js +0 -37
  163. package/dist/modules/browser/cookie-store.js +0 -29
  164. package/dist/modules/browser/driver-types.js +0 -1
  165. package/dist/modules/browser/driver.js +0 -186
  166. package/dist/modules/browser/index.js +0 -9
  167. package/dist/modules/browser/module.js +0 -30
  168. package/dist/modules/browser/session.js +0 -322
  169. package/dist/modules/browser/snapshot.js +0 -154
  170. package/dist/modules/browser/types.js +0 -13
  171. package/dist/modules/certification/cli.js +0 -264
  172. package/dist/modules/certification/fact-checker.js +0 -90
  173. package/dist/modules/certification/loader.js +0 -127
  174. package/dist/modules/certification/manifest.js +0 -231
  175. package/dist/modules/certification/runner.js +0 -233
  176. package/dist/modules/certification/scenarios.js +0 -586
  177. package/dist/modules/certification/syntax-scenarios.js +0 -50
  178. package/dist/modules/certification/types.js +0 -1
  179. package/dist/modules/context/chunk-query.js +0 -122
  180. package/dist/modules/context/fact-extractor.js +0 -170
  181. package/dist/modules/context/history.js +0 -15
  182. package/dist/modules/context/index.js +0 -2
  183. package/dist/modules/context/manager.js +0 -482
  184. package/dist/modules/critic/client.js +0 -176
  185. package/dist/modules/critic/evidence.js +0 -81
  186. package/dist/modules/critic/provider.js +0 -45
  187. package/dist/modules/critic/tools.js +0 -78
  188. package/dist/modules/critic/types.js +0 -1
  189. package/dist/modules/execution/audit-runners.js +0 -206
  190. package/dist/modules/execution/auditor.js +0 -222
  191. package/dist/modules/execution/execution-plugin.js +0 -478
  192. package/dist/modules/execution/index.js +0 -8
  193. package/dist/modules/execution/input-from.js +0 -70
  194. package/dist/modules/execution/module.js +0 -891
  195. package/dist/modules/execution/moe-executor.js +0 -443
  196. package/dist/modules/execution/plan-actions.js +0 -642
  197. package/dist/modules/execution/plan-checks.js +0 -35
  198. package/dist/modules/execution/plan-coverage.js +0 -71
  199. package/dist/modules/execution/plan-persister.js +0 -46
  200. package/dist/modules/execution/plan-steps.js +0 -31
  201. package/dist/modules/execution/plan-store.js +0 -274
  202. package/dist/modules/execution/plan-tool.js +0 -249
  203. package/dist/modules/execution/plan-validator.js +0 -197
  204. package/dist/modules/execution/planner.js +0 -103
  205. package/dist/modules/execution/stuck-detector.js +0 -834
  206. package/dist/modules/execution/tracker.js +0 -92
  207. package/dist/modules/execution/transient-error.js +0 -30
  208. package/dist/modules/execution/types.js +0 -1
  209. package/dist/modules/execution/verifier.js +0 -343
  210. package/dist/modules/execution/windows-commands.js +0 -52
  211. package/dist/modules/hallucination/artifact-claim.js +0 -93
  212. package/dist/modules/hallucination/confidence.js +0 -81
  213. package/dist/modules/hallucination/consistency.js +0 -37
  214. package/dist/modules/hallucination/detector.js +0 -57
  215. package/dist/modules/hallucination/factual.js +0 -205
  216. package/dist/modules/hallucination/index.js +0 -6
  217. package/dist/modules/hallucination/js-identifiers.js +0 -261
  218. package/dist/modules/hallucination/llm-judge.js +0 -116
  219. package/dist/modules/hallucination/success-claim.js +0 -59
  220. package/dist/modules/index.js +0 -5
  221. package/dist/modules/indexer/cache.js +0 -88
  222. package/dist/modules/indexer/index.js +0 -4
  223. package/dist/modules/indexer/map-command.js +0 -33
  224. package/dist/modules/indexer/map-select.js +0 -87
  225. package/dist/modules/indexer/module.js +0 -293
  226. package/dist/modules/indexer/project-profile.js +0 -184
  227. package/dist/modules/indexer/symbols.js +0 -189
  228. package/dist/modules/indexer/walker.js +0 -285
  229. package/dist/modules/lsp/check-tool.js +0 -61
  230. package/dist/modules/lsp/client.js +0 -406
  231. package/dist/modules/lsp/command.js +0 -53
  232. package/dist/modules/lsp/config.js +0 -189
  233. package/dist/modules/lsp/index.js +0 -4
  234. package/dist/modules/lsp/module.js +0 -295
  235. package/dist/modules/lsp/probe.js +0 -86
  236. package/dist/modules/lsp/project-root.js +0 -69
  237. package/dist/modules/lsp/startup-check.js +0 -154
  238. package/dist/modules/lsp/types.js +0 -1
  239. package/dist/modules/mcp/client.js +0 -445
  240. package/dist/modules/mcp/index.js +0 -4
  241. package/dist/modules/mcp/module.js +0 -295
  242. package/dist/modules/mcp/registry.js +0 -20
  243. package/dist/modules/memory/index.js +0 -2
  244. package/dist/modules/memory/module.js +0 -101
  245. package/dist/modules/memory/search.js +0 -45
  246. package/dist/modules/memory/store.js +0 -107
  247. package/dist/modules/onboarding/init.js +0 -47
  248. package/dist/modules/onboarding/meet.js +0 -30
  249. package/dist/modules/onboarding/mode.js +0 -30
  250. package/dist/modules/onboarding/prompts.js +0 -43
  251. package/dist/modules/pipelines/engine.js +0 -70
  252. package/dist/modules/pipelines/index.js +0 -4
  253. package/dist/modules/pipelines/parser.js +0 -59
  254. package/dist/modules/pipelines/template.js +0 -18
  255. package/dist/modules/plugins/builtin/lint-on-write.js +0 -377
  256. package/dist/modules/plugins/builtin/notify.js +0 -11
  257. package/dist/modules/plugins/index.js +0 -2
  258. package/dist/modules/plugins/loader.js +0 -85
  259. package/dist/modules/plugins/manager.js +0 -244
  260. package/dist/modules/plugins/types.js +0 -1
  261. package/dist/modules/pricing/index.js +0 -70
  262. package/dist/modules/pricing/prices.js +0 -147
  263. package/dist/modules/processes/detect.js +0 -34
  264. package/dist/modules/processes/index.js +0 -4
  265. package/dist/modules/processes/kill-tree.js +0 -52
  266. package/dist/modules/processes/registry.js +0 -294
  267. package/dist/modules/processes/runner.js +0 -23
  268. package/dist/modules/providers/cache.js +0 -23
  269. package/dist/modules/providers/capabilities.js +0 -28
  270. package/dist/modules/providers/create.js +0 -21
  271. package/dist/modules/providers/factory.js +0 -28
  272. package/dist/modules/providers/fallback.js +0 -81
  273. package/dist/modules/providers/health.js +0 -47
  274. package/dist/modules/providers/index.js +0 -6
  275. package/dist/modules/providers/manager.js +0 -207
  276. package/dist/modules/providers/naming.js +0 -15
  277. package/dist/modules/providers/preflight.js +0 -71
  278. package/dist/modules/providers/presets.js +0 -232
  279. package/dist/modules/providers/registry.js +0 -27
  280. package/dist/modules/providers/types.js +0 -1
  281. package/dist/modules/reasoning/policy.js +0 -42
  282. package/dist/modules/reasoning/probe.js +0 -116
  283. package/dist/modules/registry.js +0 -48
  284. package/dist/modules/security/audit-log.js +0 -119
  285. package/dist/modules/security/audit-notifier.js +0 -267
  286. package/dist/modules/security/command-validator.js +0 -272
  287. package/dist/modules/security/content-scanner.js +0 -53
  288. package/dist/modules/security/data-sanitizer.js +0 -82
  289. package/dist/modules/security/encryption.js +0 -216
  290. package/dist/modules/security/index.js +0 -15
  291. package/dist/modules/security/network-validator.js +0 -236
  292. package/dist/modules/security/path-validator.js +0 -261
  293. package/dist/modules/security/protected-paths.js +0 -73
  294. package/dist/modules/security/rate-limiter.js +0 -98
  295. package/dist/modules/security/security-policies.js +0 -499
  296. package/dist/modules/security/session-encryption.js +0 -182
  297. package/dist/modules/security/session-isolation.js +0 -75
  298. package/dist/modules/session/auto-name.js +0 -63
  299. package/dist/modules/session/export.js +0 -98
  300. package/dist/modules/session/index.js +0 -4
  301. package/dist/modules/session/manager.js +0 -234
  302. package/dist/modules/session/module.js +0 -33
  303. package/dist/modules/session/store.js +0 -295
  304. package/dist/modules/session/types.js +0 -1
  305. package/dist/modules/setup/answers.js +0 -35
  306. package/dist/modules/setup/apply.js +0 -79
  307. package/dist/modules/setup/discovery.js +0 -72
  308. package/dist/modules/skills/index.js +0 -3
  309. package/dist/modules/skills/loader.js +0 -86
  310. package/dist/modules/skills/matcher.js +0 -27
  311. package/dist/modules/skills/module.js +0 -141
  312. package/dist/modules/types.js +0 -1
  313. package/dist/modules/updater/changelog-reader.js +0 -93
  314. package/dist/modules/updater/checker.js +0 -101
  315. package/dist/modules/updater/dev-detect.js +0 -18
  316. package/dist/modules/updater/index.js +0 -4
  317. package/dist/modules/updater/module.js +0 -129
  318. package/dist/modules/user-profile/compressor.js +0 -18
  319. package/dist/modules/user-profile/index.js +0 -2
  320. package/dist/modules/user-profile/profile.js +0 -77
  321. package/dist/modules/webui/answer-api.js +0 -29
  322. package/dist/modules/webui/assets.js +0 -50
  323. package/dist/modules/webui/body.js +0 -21
  324. package/dist/modules/webui/commands-settings.js +0 -209
  325. package/dist/modules/webui/commands-shared.js +0 -60
  326. package/dist/modules/webui/commands.js +0 -174
  327. package/dist/modules/webui/config-api.js +0 -134
  328. package/dist/modules/webui/file-api.js +0 -202
  329. package/dist/modules/webui/forward.js +0 -159
  330. package/dist/modules/webui/history-api.js +0 -112
  331. package/dist/modules/webui/host-state.js +0 -60
  332. package/dist/modules/webui/i18n-api.js +0 -9
  333. package/dist/modules/webui/limits.js +0 -6
  334. package/dist/modules/webui/log-forward.js +0 -20
  335. package/dist/modules/webui/memory-commands.js +0 -64
  336. package/dist/modules/webui/model-cache.js +0 -18
  337. package/dist/modules/webui/module.js +0 -148
  338. package/dist/modules/webui/persist.js +0 -24
  339. package/dist/modules/webui/prompt-io.js +0 -97
  340. package/dist/modules/webui/providers-api.js +0 -337
  341. package/dist/modules/webui/providers-view.js +0 -56
  342. package/dist/modules/webui/reasoning-view.js +0 -15
  343. package/dist/modules/webui/run-agent.js +0 -81
  344. package/dist/modules/webui/server.js +0 -284
  345. package/dist/modules/webui/sessions-api.js +0 -178
  346. package/dist/modules/webui/settings-api.js +0 -561
  347. package/dist/modules/webui/setup-api.js +0 -201
  348. package/dist/modules/webui/state.js +0 -74
  349. package/dist/modules/webui/util.js +0 -261
  350. package/dist/output/bus.js +0 -37
  351. package/dist/output/channel.js +0 -285
  352. package/dist/output/format.js +0 -15
  353. package/dist/output/index.js +0 -8
  354. package/dist/output/json-sink.js +0 -24
  355. package/dist/output/machine.js +0 -9
  356. package/dist/output/session-sink.js +0 -27
  357. package/dist/output/types.js +0 -1
  358. package/dist/tools/approve.js +0 -41
  359. package/dist/tools/attach-image.js +0 -102
  360. package/dist/tools/auto-fixer.js +0 -180
  361. package/dist/tools/auto-tags.js +0 -83
  362. package/dist/tools/bash.js +0 -649
  363. package/dist/tools/browser.js +0 -160
  364. package/dist/tools/chunk-query.js +0 -112
  365. package/dist/tools/create-dir.js +0 -60
  366. package/dist/tools/delete-file.js +0 -67
  367. package/dist/tools/download-file.js +0 -142
  368. package/dist/tools/edit-file.js +0 -136
  369. package/dist/tools/enable-tools.js +0 -59
  370. package/dist/tools/executor.js +0 -304
  371. package/dist/tools/file-info.js +0 -49
  372. package/dist/tools/filter-tools.js +0 -17
  373. package/dist/tools/glob-tool.js +0 -37
  374. package/dist/tools/grep-tool.js +0 -142
  375. package/dist/tools/hidden-tools-block.js +0 -37
  376. package/dist/tools/index.js +0 -88
  377. package/dist/tools/list-dir.js +0 -53
  378. package/dist/tools/load-skill.js +0 -51
  379. package/dist/tools/mcp-call.js +0 -80
  380. package/dist/tools/meet-done.js +0 -14
  381. package/dist/tools/move-file.js +0 -94
  382. package/dist/tools/path-utils.js +0 -108
  383. package/dist/tools/pipeline-run.js +0 -167
  384. package/dist/tools/preview.js +0 -2
  385. package/dist/tools/process-ids.js +0 -31
  386. package/dist/tools/process-kill.js +0 -33
  387. package/dist/tools/process-list.js +0 -38
  388. package/dist/tools/process-log.js +0 -49
  389. package/dist/tools/process-wait.js +0 -63
  390. package/dist/tools/prompt-io.js +0 -29
  391. package/dist/tools/question.js +0 -288
  392. package/dist/tools/read-file.js +0 -200
  393. package/dist/tools/recall.js +0 -124
  394. package/dist/tools/registry.js +0 -48
  395. package/dist/tools/remember.js +0 -72
  396. package/dist/tools/scope-check.js +0 -32
  397. package/dist/tools/scope-request.js +0 -96
  398. package/dist/tools/search-history.js +0 -88
  399. package/dist/tools/session-info.js +0 -46
  400. package/dist/tools/set-thinking.js +0 -75
  401. package/dist/tools/subagent.js +0 -257
  402. package/dist/tools/syntax-validator.js +0 -379
  403. package/dist/tools/types.js +0 -1
  404. package/dist/tools/user-input.js +0 -134
  405. package/dist/tools/web-browse.js +0 -93
  406. package/dist/tools/web-fetch.js +0 -108
  407. package/dist/tools/web-search.js +0 -107
  408. package/dist/tools/write-file.js +0 -128
  409. package/dist/ui/action-log.js +0 -13
  410. package/dist/ui/box.js +0 -78
  411. package/dist/ui/colors.js +0 -6
  412. package/dist/ui/diff.js +0 -189
  413. package/dist/ui/index.js +0 -7
  414. package/dist/ui/line-editor.js +0 -1083
  415. package/dist/ui/line-math.js +0 -98
  416. package/dist/ui/md-formatter.js +0 -322
  417. package/dist/ui/output.js +0 -19
  418. package/dist/ui/plan-view.js +0 -109
  419. package/dist/ui/renderer.js +0 -589
  420. package/dist/ui/spinner.js +0 -91
  421. package/dist/ui/table.js +0 -142
  422. package/dist/ui/theme.js +0 -143
  423. package/dist/utils/child-run.js +0 -20
  424. package/dist/utils/error.js +0 -4
  425. package/dist/utils/index.js +0 -6
  426. package/dist/utils/retry.js +0 -17
  427. package/dist/utils/sleep.js +0 -23
  428. package/dist/utils/truncate.js +0 -9
@@ -1,148 +0,0 @@
1
- import { CONFIG_FILE, saveConfig as persistConfig } from "../../config/config";
2
- import { buildSetupDisplay } from "../setup/answers";
3
- import { WebHost } from "../../core/web-host";
4
- import { loadAssets } from "./assets";
5
- import { makeWebCommands } from "./commands";
6
- import { makeForwarder } from "./forward";
7
- import { installOutputForwarding } from "./log-forward";
8
- import { installWebPromptIO } from "./prompt-io";
9
- import { startServer, stopServer } from "./server";
10
- import { makeModelCache } from "./model-cache";
11
- import { makeRunAgent } from "./run-agent";
12
- import { buildHostState } from "./host-state";
13
- import { cancelPendingQuestions } from "./prompt-io";
14
- import { broadcast, createWebUiState, } from "./state";
15
- // Чистые снапшот-хелперы живут в `./host-state`; реэкспорт, чтобы существующие
16
- // импортёры (`webui-usage`, `webui-plan` тесты) не чинить.
17
- export { buildHostState, captureUsage, planEventFor, } from "./host-state";
18
- /**
19
- * Строит вебовый хук `reconfigure`. Он может менять окно/бюджет контекста,
20
- * и кешнутый лимит сайдбара (история прошлого хода, `budget.history`) протухает.
21
- * Перечитываем живой бюджет и пушим событие `state`, чтобы браузер обновился
22
- * сразу, не дожидаясь следующего хода или 2с-полла `/api/state`.
23
- */
24
- export function makeReconfigure(state, agent, after) {
25
- return async (config) => {
26
- await agent.reconfigure(config);
27
- state.usage = { ...state.usage, contextLimit: agent.contextManager.getBudget().history };
28
- // Провайдер мог смениться: сначала рефрешим список моделей под провайдера,
29
- // чтобы follow-up `/api/models` клиента увидел модели нового провайдера.
30
- if (after) {
31
- try {
32
- await after();
33
- }
34
- catch {
35
- /* результат reconfigure сохраняем, даже если рефреш моделей упал */
36
- }
37
- }
38
- broadcast({ type: "state", ts: Date.now(), busy: state.busy, usage: state.usage }, state);
39
- };
40
- }
41
- /**
42
- * Стартует браузерный UI. Сначала состояние, затем `WebHost`, затем сервер —
43
- * чтобы флаг busy был общим сквозняком.
44
- */
45
- export async function startWebUi(deps) {
46
- const state = createWebUiState();
47
- if (deps.host)
48
- state.host = deps.host;
49
- if (deps.token)
50
- state.token = deps.token;
51
- // Гейтинг первого запуска + данные визарда. `buildSetupDisplay` дёшев и
52
- // зависит только от пресетов провайдеров, поэтому заполняется всегда.
53
- state.setupRequired = deps.setupRequired ?? false;
54
- state.setup = buildSetupDisplay();
55
- // Коллабораторы REST конфига/сессий/моделей. `state.config` — алиас живого
56
- // объекта конфига, так что записи `/api/config` мутят тот же объект, что
57
- // читает агент после `reconfigure`.
58
- state.config = deps.config;
59
- state.sessionManager = deps.sessionManager;
60
- state.execModule = deps.execModule;
61
- state.memory = deps.memory;
62
- state.skills = deps.skills;
63
- state.plugins = deps.plugins;
64
- state.workspace = deps.baseDir;
65
- state.agentsMd = deps.agentsMd;
66
- if (deps.indexer)
67
- state.projectMapStats = () => deps.indexer?.stats() ?? null;
68
- state.saveConfig = (config) => persistConfig(config, CONFIG_FILE, deps.configDir);
69
- // Веб-онли интерактивные тулы: `question`/`approve` через SSE + `/api/answer`.
70
- installWebPromptIO({
71
- state,
72
- agent: deps.agent,
73
- registry: deps.toolRegistry,
74
- toolCtx: deps.toolCtx,
75
- });
76
- // Список моделей: явный источник побеждает; иначе фоновый кеш за активным
77
- // провайдером (рефреш на каждый reconfigure).
78
- const modelCache = deps.knownModels ? null : makeModelCache(deps.agent, deps.config);
79
- state.knownModels = deps.knownModels ?? modelCache.get;
80
- if (modelCache)
81
- void modelCache.refresh();
82
- state.reconfigure = makeReconfigure(state, deps.agent, modelCache ? () => modelCache.refresh() : undefined);
83
- const forwarder = makeForwarder(state);
84
- const stopOutputForwarding = installOutputForwarding(state);
85
- // Context probe: резолвится в фоне; `undefined`, пока не устоялся, чтобы
86
- // сайдбар рисовал прочерк "pending", не стопая старт.
87
- let probe;
88
- if (deps.contextProbe) {
89
- void deps.contextProbe
90
- .then((p) => {
91
- probe = p;
92
- })
93
- .catch(() => {
94
- probe = null;
95
- });
96
- }
97
- const runAgent = makeRunAgent({
98
- agent: deps.agent,
99
- state,
100
- forwarder,
101
- sessionManager: deps.sessionManager,
102
- execModule: deps.execModule,
103
- contextWindow: deps.config.contextWindow,
104
- });
105
- const host = new WebHost({
106
- isBusy: () => state.agentRunning,
107
- runAgent: runAgent.run,
108
- interrupt: () => runAgent.interrupt(),
109
- // Слеш-команды идут через shared карту хендлеров; вывод стримится по SSE
110
- // событиями `command` (HTTP POST лишь подтверждает приём).
111
- executeCommand: makeWebCommands({ state }),
112
- getState: () => buildHostState({
113
- config: deps.config,
114
- sessionManager: deps.sessionManager,
115
- execModule: deps.execModule,
116
- usage: state.usage,
117
- contextProbe: probe,
118
- workspace: deps.baseDir,
119
- instructions: deps.agentsMd,
120
- projectMap: (() => {
121
- const s = deps.indexer?.stats();
122
- return s ? { indexed: true, ...s } : { indexed: false, files: 0, symbols: 0, tokens: 0 };
123
- })(),
124
- }, state.busy),
125
- addPendingImage: (url) => {
126
- deps.agent.contextManager?.addPendingImage?.({
127
- type: "image_url",
128
- image_url: { url },
129
- });
130
- },
131
- });
132
- state.bridge = host;
133
- // Ассеты отдаём свежими с диска, чтобы правки `assets/*` не требовали рестарта сервера.
134
- state.assetSource = loadAssets;
135
- const url = startServer(loadAssets(), state);
136
- return {
137
- state,
138
- host,
139
- forwarder,
140
- url,
141
- stop: () => {
142
- cancelPendingQuestions(state);
143
- forwarder.flushNow();
144
- stopOutputForwarding();
145
- stopServer(state);
146
- },
147
- };
148
- }
@@ -1,24 +0,0 @@
1
- /** Сначала персист, затем reconfigure; ни один провал не глотается. */
2
- export async function persistAndReconfigure(s, config) {
3
- let persisted = true;
4
- let warning;
5
- try {
6
- s.saveConfig?.(config);
7
- }
8
- catch {
9
- persisted = false;
10
- warning = "config not persisted";
11
- }
12
- if (s.reconfigure) {
13
- try {
14
- await s.reconfigure(config);
15
- }
16
- catch {
17
- warning = warning ? `${warning}; reconfigure failed` : "reconfigure failed";
18
- }
19
- }
20
- const out = { persisted };
21
- if (warning)
22
- out.warning = warning;
23
- return out;
24
- }
@@ -1,97 +0,0 @@
1
- import { questionTool } from "../../tools/question";
2
- import { approveTool } from "../../tools/approve";
3
- import { broadcast } from "./state";
4
- let questionSeq = 0;
5
- /** Монотонный id висящего вопроса без коллизий. */
6
- function nextQuestionId() {
7
- questionSeq += 1;
8
- return `q${Date.now().toString(36)}-${questionSeq}`;
9
- }
10
- /**
11
- * Приводит произвольный пейлоад браузера к массиву индексов для `askChoice`.
12
- * `-1` ({@link CUSTOM_INDEX}) сохраняется: метка пункта «свой ответ»,
13
- * который тул затем дорезолвит follow-up вызовом `askText`.
14
- */
15
- function toIndexes(value) {
16
- if (!Array.isArray(value))
17
- return [];
18
- const out = [];
19
- for (const item of value) {
20
- const n = typeof item === "number" ? item : Number(item);
21
- if (Number.isInteger(n) && n >= -1)
22
- out.push(n);
23
- }
24
- return out;
25
- }
26
- /** Приводит произвольный пейлоад браузера к строке для `askText`. */
27
- function toText(value) {
28
- if (typeof value === "string")
29
- return value;
30
- if (value == null)
31
- return "";
32
- return String(value);
33
- }
34
- /** Регистрирует висящий вопрос, бродкастит его, резолвится приведённым ответом. */
35
- function ask(state, payload, coerce) {
36
- return new Promise((resolve) => {
37
- const id = nextQuestionId();
38
- state.pendingQuestions.set(id, (value) => resolve(coerce(value)));
39
- broadcast({ type: "question", ts: Date.now(), id, ...payload }, state);
40
- });
41
- }
42
- /** Браузерный `PromptIO`: спрашивает через SSE, закрывается в `resolveAnswer`. */
43
- export function createWebPromptIO(state) {
44
- return {
45
- askText(question) {
46
- return ask(state, { text: question, kind: "text" }, toText);
47
- },
48
- askChoice(question, options, opts = {}) {
49
- return ask(state, {
50
- text: question,
51
- kind: "choice",
52
- options: options.map((o) => o.label ?? String(o)),
53
- multiple: !!opts.multiple,
54
- allowCustom: !!opts.allowCustom,
55
- }, toIndexes);
56
- },
57
- };
58
- }
59
- /** Закрывает висящий вопрос по id. False — id неизвестен. */
60
- export function resolveAnswer(state, id, value) {
61
- const resolver = state.pendingQuestions.get(id);
62
- if (!resolver)
63
- return false;
64
- state.pendingQuestions.delete(id);
65
- resolver(value);
66
- return true;
67
- }
68
- /**
69
- * Закрывает все висящие вопросы через `undefined` (тулы прочтут пусто/`[]`).
70
- * Звать на interrupt/shutdown, чтобы заблокированный `question`/`approve`
71
- * не держал ход после того, как браузер перестал отвечать.
72
- */
73
- export function cancelPendingQuestions(state) {
74
- const pending = [...state.pendingQuestions.values()];
75
- state.pendingQuestions.clear();
76
- for (const resolve of pending)
77
- resolve(undefined);
78
- }
79
- /**
80
- * Веб-онли wiring: регистрирует интерактивные тулы, снимает `exitOnComplete`
81
- * с shared тул-контекста (веб-ходы интерактивны, не one-shot — иначе
82
- * `question`/`approve` коротко замыкаются) и ставит браузерный `PromptIO`.
83
- * Терминал сюда не ходит, его поведение не меняется.
84
- */
85
- export function installWebPromptIO(deps) {
86
- if (deps.registry) {
87
- for (const tool of [questionTool, approveTool]) {
88
- if (!deps.registry.has(tool.name))
89
- deps.registry.register(tool);
90
- }
91
- }
92
- if (deps.toolCtx)
93
- deps.toolCtx.exitOnComplete = false;
94
- const io = createWebPromptIO(deps.state);
95
- deps.agent.setPromptIO(io);
96
- return io;
97
- }
@@ -1,337 +0,0 @@
1
- import { DEFAULTS } from "../../config/defaults";
2
- import { providerEntryName, providerNameTaken } from "../providers/naming";
3
- import { readBodyError, sendJson } from "./util";
4
- import { readJsonBody } from "./body";
5
- import { persistAndReconfigure } from "./persist";
6
- import { buildProviderViews } from "./providers-view";
7
- /** `GET /api/providers` — отредактированные записи + имя активного. */
8
- export function handleProvidersGet(res, s) {
9
- if (!s.config) {
10
- sendJson(res, 503, { error: "config_unavailable" });
11
- return;
12
- }
13
- sendJson(res, 200, buildProviderViews(s.config));
14
- }
15
- function optionalInt(rec, key, min) {
16
- return optionalIntRange(rec, key, min, Number.MAX_SAFE_INTEGER);
17
- }
18
- function optionalIntRange(rec, key, min, max) {
19
- const v = rec[key];
20
- if (v === undefined || v === null || v === "")
21
- return undefined;
22
- const n = typeof v === "number" ? v : Number(v);
23
- if (!Number.isFinite(n) || !Number.isInteger(n) || n < min || n > max)
24
- return null;
25
- return n;
26
- }
27
- const CACHE_MECHANISMS = ["auto", "explicit", "local", "none"];
28
- const CACHE_REPORTS = ["openai", "deepseek", "anthropic", "ollama", "none"];
29
- const CACHE_FLAGS = [
30
- "sessionHeader",
31
- "requestCachePrompt",
32
- "requestPromptCacheKey",
33
- "requestSessionId",
34
- "requestCacheControl",
35
- "requestStreamUsage",
36
- ];
37
- function coerceFlag(v) {
38
- if (typeof v === "boolean")
39
- return v;
40
- if (v === 0 || v === 1)
41
- return v === 1;
42
- if (typeof v === "string") {
43
- const s = v.trim().toLowerCase();
44
- if (s === "true" || s === "1")
45
- return true;
46
- if (s === "false" || s === "0")
47
- return false;
48
- }
49
- return null;
50
- }
51
- /** Парсит потуловой объект оверрайда `cache`. `null` — мусор (400). */
52
- function parseCache(v) {
53
- if (v === undefined || v === null)
54
- return undefined;
55
- if (typeof v !== "object" || Array.isArray(v))
56
- return null;
57
- const rec = v;
58
- const out = {};
59
- if (rec.mechanism !== undefined) {
60
- if (typeof rec.mechanism !== "string" || !CACHE_MECHANISMS.includes(rec.mechanism))
61
- return null;
62
- out.mechanism = rec.mechanism;
63
- }
64
- if (rec.report !== undefined) {
65
- if (typeof rec.report !== "string" || !CACHE_REPORTS.includes(rec.report))
66
- return null;
67
- out.report = rec.report;
68
- }
69
- for (const flag of CACHE_FLAGS) {
70
- const fv = rec[flag];
71
- if (fv === undefined)
72
- continue;
73
- const b = coerceFlag(fv);
74
- if (b === null)
75
- return null;
76
- out[flag] = b;
77
- }
78
- return out;
79
- }
80
- /** Парсит потуловой объект оверрайда `retry`. `null` — мусор (400). */
81
- function parseRetry(v) {
82
- if (v === undefined || v === null)
83
- return undefined;
84
- if (typeof v !== "object" || Array.isArray(v))
85
- return null;
86
- const rec = v;
87
- const specs = [
88
- ["maxRetries", 0, 10],
89
- ["baseDelay", 0, 60000],
90
- ["maxDelay", 0, 300000],
91
- ];
92
- const out = {};
93
- for (const [key, min, max] of specs) {
94
- const n = optionalIntRange(rec, key, min, max);
95
- if (n === null)
96
- return null;
97
- if (n !== undefined)
98
- out[key] = n;
99
- }
100
- return out;
101
- }
102
- /** Парсит и валидирует тело POST. `null` — реджект с 400. */
103
- function parseProviderInput(rec) {
104
- const type = typeof rec.type === "string" ? rec.type.trim() : "";
105
- const baseUrl = typeof rec.baseUrl === "string" ? rec.baseUrl.trim() : "";
106
- if (!type || !baseUrl)
107
- return null;
108
- if (rec.apiKey !== undefined && rec.apiKey !== null && typeof rec.apiKey !== "string")
109
- return null;
110
- if (rec.label !== undefined && rec.label !== null && typeof rec.label !== "string")
111
- return null;
112
- if (rec.originalName !== undefined && rec.originalName !== null && typeof rec.originalName !== "string") {
113
- return null;
114
- }
115
- const contextWindow = optionalInt(rec, "contextWindow", 1024);
116
- const priority = optionalInt(rec, "priority", 0);
117
- const rpm = optionalInt(rec, "rpm", 1);
118
- const parallel = optionalInt(rec, "parallel", 1);
119
- if (contextWindow === null || priority === null || rpm === null || parallel === null)
120
- return null;
121
- const maxCompletionTokens = optionalIntRange(rec, "maxCompletionTokens", 512, 128000);
122
- if (maxCompletionTokens === null)
123
- return null;
124
- const cache = parseCache(rec.cache);
125
- if (cache === null)
126
- return null;
127
- const retry = parseRetry(rec.retry);
128
- if (retry === null)
129
- return null;
130
- const input = { type, baseUrl };
131
- if (typeof rec.label === "string" && rec.label.trim())
132
- input.label = rec.label.trim();
133
- if (typeof rec.originalName === "string" && rec.originalName.trim()) {
134
- input.originalName = rec.originalName.trim();
135
- }
136
- if (typeof rec.apiKey === "string" && rec.apiKey.trim())
137
- input.apiKey = rec.apiKey.trim();
138
- if (contextWindow !== undefined)
139
- input.contextWindow = contextWindow;
140
- if (priority !== undefined)
141
- input.priority = priority;
142
- if (rpm !== undefined)
143
- input.rpm = rpm;
144
- if (parallel !== undefined)
145
- input.parallel = parallel;
146
- if (maxCompletionTokens !== undefined)
147
- input.maxCompletionTokens = maxCompletionTokens;
148
- if (cache !== undefined)
149
- input.cache = cache;
150
- if (retry !== undefined)
151
- input.retry = retry;
152
- return input;
153
- }
154
- /** Зеркалит активную запись на легаси-плоские поля `provider`. */
155
- function mirrorLegacy(config, entry) {
156
- config.provider.type = entry.type;
157
- config.provider.baseUrl = entry.baseUrl;
158
- if (entry.apiKey !== undefined)
159
- config.provider.apiKey = entry.apiKey;
160
- if (entry.maxCompletionTokens !== undefined) {
161
- config.provider.maxCompletionTokens = entry.maxCompletionTokens;
162
- }
163
- }
164
- /**
165
- * Существующие записи с подсевом легаси-однопровайдерного конфига. Легаси
166
- * (`provider.type`/`baseUrl` без `entries`) должен пережить первый add —
167
- * иначе новая запись молча его заменит.
168
- */
169
- function seededEntries(config) {
170
- const provider = config.provider;
171
- const entries = Array.isArray(provider.entries) ? [...provider.entries] : [];
172
- if (entries.length === 0 && provider.type) {
173
- entries.push({
174
- type: provider.type,
175
- label: provider.active || provider.type,
176
- baseUrl: provider.baseUrl,
177
- apiKey: provider.apiKey,
178
- });
179
- }
180
- return entries;
181
- }
182
- /**
183
- * Создаёт запись провайдера или обновляет названную в `input.originalName`.
184
- * POST без `originalName` всегда создаёт. Имя, бьющееся с чужим label/type, —
185
- * отказ. Возвращает имя записанной записи.
186
- */
187
- export function upsertProvider(config, input) {
188
- const provider = config.provider;
189
- const fromLegacySeed = !Array.isArray(provider.entries) || provider.entries.length === 0;
190
- const entries = seededEntries(config);
191
- const name = input.label || input.type;
192
- if (providerNameTaken(entries, name, input.originalName)) {
193
- // Вырожденный случай: virgin-легаси без `entries` сидирует ровно одну запись,
194
- // и create-POST с её именем — in-place upsert мигрированного конфига,
195
- // а не коллизия с другим провайдером.
196
- const loneSeeded = fromLegacySeed && entries.length === 1 && providerEntryName(entries[0]) === name;
197
- if (!loneSeeded || input.originalName) {
198
- return { ok: false, error: "name-conflict" };
199
- }
200
- }
201
- let idx = input.originalName
202
- ? entries.findIndex((e) => providerEntryName(e) === input.originalName || e.type === input.originalName)
203
- : -1;
204
- if (idx < 0 && fromLegacySeed && entries.length === 1 && providerEntryName(entries[0]) === name) {
205
- idx = 0;
206
- }
207
- const entry = idx >= 0 ? { ...entries[idx] } : { type: input.type, baseUrl: input.baseUrl };
208
- entry.type = input.type;
209
- entry.baseUrl = input.baseUrl;
210
- if (input.label !== undefined)
211
- entry.label = input.label;
212
- if (input.apiKey !== undefined)
213
- entry.apiKey = input.apiKey;
214
- if (input.contextWindow !== undefined)
215
- entry.contextWindow = input.contextWindow;
216
- if (input.priority !== undefined)
217
- entry.priority = input.priority;
218
- if (input.maxCompletionTokens !== undefined)
219
- entry.maxCompletionTokens = input.maxCompletionTokens;
220
- if (input.cache !== undefined)
221
- entry.cache = { ...(entry.cache ?? {}), ...input.cache };
222
- if (input.retry !== undefined) {
223
- const prev = entry.retry ?? {};
224
- entry.retry = {
225
- maxRetries: input.retry.maxRetries ?? prev.maxRetries ?? DEFAULTS.retry.maxRetries,
226
- baseDelay: input.retry.baseDelay ?? prev.baseDelay ?? DEFAULTS.retry.baseDelay,
227
- maxDelay: input.retry.maxDelay ?? prev.maxDelay ?? DEFAULTS.retry.maxDelay,
228
- };
229
- }
230
- if (input.rpm !== undefined || input.parallel !== undefined) {
231
- const prev = entry.rateLimits ?? { maxRequestsPerMinute: 60, maxParallelTasks: 1 };
232
- entry.rateLimits = {
233
- maxRequestsPerMinute: input.rpm ?? prev.maxRequestsPerMinute,
234
- maxParallelTasks: input.parallel ?? prev.maxParallelTasks,
235
- };
236
- }
237
- if (idx >= 0)
238
- entries[idx] = entry;
239
- else
240
- entries.push(entry);
241
- config.provider.entries = entries;
242
- // Активный провайдер сохраняем; активным становится только первый в истории.
243
- const wasActive = provider.active || provider.type;
244
- if (!provider.active)
245
- config.provider.active = providerEntryName(entries[0]);
246
- if (providerEntryName(entry) === wasActive || entries.length === 1)
247
- mirrorLegacy(config, entry);
248
- return { ok: true, name: providerEntryName(entry) };
249
- }
250
- /** `POST /api/providers` — add/update, персист, reconfigure. */
251
- export function handleProvidersPost(req, res, s) {
252
- if (!s.config) {
253
- sendJson(res, 503, { error: "config_unavailable" });
254
- return;
255
- }
256
- const config = s.config;
257
- readJsonBody(req, s.maxBodyBytes)
258
- .then(async (rec) => {
259
- if (!rec) {
260
- sendJson(res, 400, { ok: false, error: "invalid JSON" });
261
- return;
262
- }
263
- const input = parseProviderInput(rec);
264
- if (!input) {
265
- sendJson(res, 400, { ok: false, error: "invalid-provider" });
266
- return;
267
- }
268
- const result = upsertProvider(config, input);
269
- if (!result.ok) {
270
- sendJson(res, 409, { ok: false, error: "name-conflict" });
271
- return;
272
- }
273
- const persisted = await persistAndReconfigure(s, config);
274
- sendJson(res, 200, { ok: true, name: result.name, ...buildProviderViews(config), ...persisted });
275
- })
276
- .catch((err) => {
277
- readBodyError(req, res, err);
278
- });
279
- }
280
- /**
281
- * Удаляет запись провайдера. Активный удалять отказывается (сначала
282
- * переключись), чтобы агент не потерял живой бэкенд.
283
- */
284
- export function removeProvider(config, name) {
285
- const provider = config.provider;
286
- if (name === (provider.active || provider.type))
287
- return "active";
288
- const entries = Array.isArray(provider.entries) ? provider.entries : [];
289
- const idx = entries.findIndex((e) => (e.label || e.type) === name || e.type === name);
290
- if (idx < 0)
291
- return "missing";
292
- config.provider.entries = entries.filter((_, i) => i !== idx);
293
- return "ok";
294
- }
295
- /** `DELETE /api/providers/:name` — удалить, персист, reconfigure. */
296
- export function handleProvidersDelete(res, name, s) {
297
- if (!s.config) {
298
- sendJson(res, 503, { error: "config_unavailable" });
299
- return;
300
- }
301
- if (!name) {
302
- sendJson(res, 400, { ok: false, error: "invalid-name" });
303
- return;
304
- }
305
- const config = s.config;
306
- const outcome = removeProvider(config, name);
307
- if (outcome === "active") {
308
- sendJson(res, 409, { ok: false, error: "active-provider" });
309
- return;
310
- }
311
- if (outcome === "missing") {
312
- sendJson(res, 404, { ok: false, error: "not_found" });
313
- return;
314
- }
315
- void persistAndReconfigure(s, config).then((result) => {
316
- sendJson(res, 200, { ok: true, ...buildProviderViews(config), ...result });
317
- }, () => {
318
- sendJson(res, 500, { ok: false, error: "delete_failed" });
319
- });
320
- }
321
- /** Диспатч `/api/providers*`; возвращает, обработан ли запрос. */
322
- export function handleProvidersApi(req, res, reqUrl, s) {
323
- const p = reqUrl.pathname;
324
- if (p === "/api/providers" && req.method === "GET") {
325
- handleProvidersGet(res, s);
326
- return true;
327
- }
328
- if (p === "/api/providers" && req.method === "POST") {
329
- handleProvidersPost(req, res, s);
330
- return true;
331
- }
332
- if (p.startsWith("/api/providers/") && req.method === "DELETE") {
333
- handleProvidersDelete(res, decodeURIComponent(p.slice("/api/providers/".length)), s);
334
- return true;
335
- }
336
- return false;
337
- }
@@ -1,56 +0,0 @@
1
- import { BUILTIN_PROVIDERS } from "../providers/presets";
2
- /**
3
- * Именованные локальные эндпоинты: тот же тип `openai-compat` с известными base URL,
4
- * чтобы локальному сетапу тоже не нужно было знание URL. (LM Studio вырос в
5
- * настоящий builtin-пресет `lmstudio` и здесь больше не дублируется.)
6
- */
7
- const LOCAL_PRESETS = [
8
- { id: "ollama", type: "openai-compat", name: "ollama", label: "Ollama (localhost:11434)", baseUrl: "http://localhost:11434/v1" },
9
- { id: "vllm", type: "openai-compat", name: "vllm", label: "vLLM (localhost:8000)", baseUrl: "http://localhost:8000/v1" },
10
- ];
11
- /** Встроенные пресеты с фиксированными base URL (у хостедных он есть). */
12
- export function buildProviderPresets() {
13
- const builtin = BUILTIN_PROVIDERS.map((spec) => {
14
- const preset = {
15
- id: spec.type,
16
- type: spec.type,
17
- name: spec.type,
18
- label: spec.label,
19
- };
20
- if (spec.baseUrl)
21
- preset.baseUrl = spec.baseUrl;
22
- return preset;
23
- });
24
- return [...builtin, ...LOCAL_PRESETS];
25
- }
26
- /** Нормализует `config.provider` в список для показа + имя активного. */
27
- export function buildProviderViews(config) {
28
- const provider = config.provider;
29
- const raw = Array.isArray(provider.entries) && provider.entries.length > 0
30
- ? provider.entries
31
- : [{ type: provider.type, baseUrl: provider.baseUrl, apiKey: provider.apiKey }];
32
- const entries = raw.map((e) => {
33
- const view = {
34
- type: e.type,
35
- label: e.label || e.type,
36
- baseUrl: e.baseUrl,
37
- hasApiKey: Boolean(e.apiKey),
38
- };
39
- if (e.contextWindow !== undefined)
40
- view.contextWindow = e.contextWindow;
41
- if (e.priority !== undefined)
42
- view.priority = e.priority;
43
- if (e.maxCompletionTokens !== undefined)
44
- view.maxCompletionTokens = e.maxCompletionTokens;
45
- if (e.cache !== undefined)
46
- view.cache = { ...e.cache };
47
- if (e.retry !== undefined)
48
- view.retry = { ...e.retry };
49
- if (e.rateLimits) {
50
- view.rpm = e.rateLimits.maxRequestsPerMinute;
51
- view.parallel = e.rateLimits.maxParallelTasks;
52
- }
53
- return view;
54
- });
55
- return { entries, active: provider.active || provider.type, presets: buildProviderPresets() };
56
- }
@@ -1,15 +0,0 @@
1
- import { BUILTIN_PROVIDERS } from "../providers/presets";
2
- import { activeProviderEndpoint } from "../providers/manager";
3
- import { getCachedProbeResult } from "../reasoning/probe";
4
- /** Строит вид из живого конфига (entries побеждают легаси-плоские поля). */
5
- export function buildReasoningView(config) {
6
- const endpoint = activeProviderEndpoint(config.provider);
7
- const spec = BUILTIN_PROVIDERS.find((p) => p.type === endpoint.type);
8
- const strategy = spec?.capabilities.reasoningStrategy ?? "none";
9
- const cached = getCachedProbeResult(`${endpoint.baseUrl}|${config.model}`);
10
- return {
11
- strategy,
12
- supported: cached === undefined ? null : cached,
13
- mode: config.reasoning?.mode ?? "auto",
14
- };
15
- }