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.
- package/CHANGELOG.md +34 -0
- package/README.md +8 -3
- package/dist/assets/app.js +1 -314
- package/dist/assets/hljs.js +5 -1244
- package/dist/assets/index.html +11 -0
- package/dist/assets/js/api.js +1 -28
- package/dist/assets/js/core/menus.js +1 -0
- package/dist/assets/js/core/store/feed.js +1 -0
- package/dist/assets/js/core/store/index.js +1 -0
- package/dist/assets/js/core/store/session.js +1 -0
- package/dist/assets/js/core/store/settings.js +1 -0
- package/dist/assets/js/core/store/tabs.js +1 -0
- package/dist/assets/js/dialog.js +1 -105
- package/dist/assets/js/dom.js +1 -178
- package/dist/assets/js/feed/core.js +1 -0
- package/dist/assets/js/feed/history.js +1 -0
- package/dist/assets/js/feed/plan.js +1 -0
- package/dist/assets/js/feed/question.js +3 -0
- package/dist/assets/js/feed/sidebar.js +1 -0
- package/dist/assets/js/feed/stream.js +1 -0
- package/dist/assets/js/feed/turn.js +5 -0
- package/dist/assets/js/feed.js +1 -1250
- package/dist/assets/js/format.js +2 -122
- package/dist/assets/js/i18n.js +1 -46
- package/dist/assets/js/rail.js +1 -114
- package/dist/assets/js/session/cmdk.js +1 -0
- package/dist/assets/js/session/composer.js +1 -0
- package/dist/assets/js/session/sessions-menu.js +1 -0
- package/dist/assets/js/session/tabs.js +1 -0
- package/dist/assets/js/settings/controls.js +1 -0
- package/dist/assets/js/settings/editors.js +1 -0
- package/dist/assets/js/settings/form.js +1 -0
- package/dist/assets/js/settings/modal.js +1 -0
- package/dist/assets/js/settings/panels.js +1 -0
- package/dist/assets/js/settings/providers.js +1 -0
- package/dist/assets/js/settings/search.js +1 -0
- package/dist/assets/js/settings/subdialog.js +1 -0
- package/dist/assets/js/settings/write.js +1 -0
- package/dist/assets/js/settings.js +1 -1914
- package/dist/assets/js/sidebar/core.js +1 -0
- package/dist/assets/js/sidebar/lsp.js +2 -0
- package/dist/assets/js/sidebar/map.js +1 -0
- package/dist/assets/js/sidebar/state.js +1 -0
- package/dist/assets/js/sidebar/trace.js +5 -0
- package/dist/assets/js/sidebar.js +1 -705
- package/dist/assets/js/store.js +1 -82
- package/dist/assets/js/subdialog.js +1 -0
- package/dist/assets/md.js +1 -291
- package/dist/assets/setup.js +3 -816
- package/dist/assets/smd.js +29 -1665
- package/dist/assets/styles.css +1 -1598
- package/dist/certification/certifications.json +1 -494
- package/dist/i18n/en.json +1 -1851
- package/dist/i18n/ru.json +1 -1854
- package/dist/main.js +815 -55797
- package/dist/modules/browser/bridge-server.mjs +2 -252
- package/package.json +10 -5
- package/dist/assets/js/settings-controls.js +0 -452
- package/dist/assets/js/tabs.js +0 -867
- package/dist/cli/cache-line.js +0 -31
- package/dist/cli/command-suggest.js +0 -39
- package/dist/cli/commands.js +0 -781
- package/dist/cli/completer.js +0 -268
- package/dist/cli/index.js +0 -3
- package/dist/cli/json-payload.js +0 -32
- package/dist/cli/main.js +0 -346
- package/dist/cli/onboarding-commands.js +0 -126
- package/dist/cli/plugin-commands.js +0 -38
- package/dist/cli/relaunch.js +0 -40
- package/dist/cli/repl-commands-lsp.js +0 -75
- package/dist/cli/repl-commands-skills.js +0 -105
- package/dist/cli/repl-commands.js +0 -1218
- package/dist/cli/repl.js +0 -1238
- package/dist/cli/run-result.js +0 -38
- package/dist/cli/security-commands.js +0 -177
- package/dist/cli/setup-order.js +0 -6
- package/dist/cli/setup-prompt.js +0 -50
- package/dist/cli/setup.js +0 -161
- package/dist/cli/web-command.js +0 -98
- package/dist/config/budget.js +0 -48
- package/dist/config/config.js +0 -345
- package/dist/config/defaults.js +0 -197
- package/dist/config/domains.js +0 -135
- package/dist/config/env.js +0 -46
- package/dist/config/experts.js +0 -17
- package/dist/config/index.js +0 -5
- package/dist/config/paths.js +0 -56
- package/dist/config/redact.js +0 -44
- package/dist/config/registry-extra.js +0 -334
- package/dist/config/registry.js +0 -584
- package/dist/config/security.js +0 -212
- package/dist/config/timeouts.js +0 -74
- package/dist/config/types.js +0 -1
- package/dist/config/utils.js +0 -57
- package/dist/core/agent/artifact-progress.js +0 -59
- package/dist/core/agent/artifact-resolve.js +0 -79
- package/dist/core/agent/audit-gate.js +0 -53
- package/dist/core/agent/compaction.js +0 -89
- package/dist/core/agent/constants.js +0 -90
- package/dist/core/agent/context-log.js +0 -454
- package/dist/core/agent/context-renderer.js +0 -45
- package/dist/core/agent/critic-gate.js +0 -132
- package/dist/core/agent/hallucination-gate.js +0 -197
- package/dist/core/agent/loop-state.js +0 -68
- package/dist/core/agent/prefix-monitor.js +0 -101
- package/dist/core/agent/reasoning-resolver.js +0 -65
- package/dist/core/agent/token-tracker.js +0 -99
- package/dist/core/agent/tool-batch.js +0 -312
- package/dist/core/agent/tool-images.js +0 -18
- package/dist/core/agent/tool-output.js +0 -116
- package/dist/core/agent/tool-pairing.js +0 -60
- package/dist/core/agent-moe.js +0 -248
- package/dist/core/agent.js +0 -1299
- package/dist/core/bootstrap/agent-phase.js +0 -66
- package/dist/core/bootstrap/config-phase.js +0 -86
- package/dist/core/bootstrap/modules-phase.js +0 -269
- package/dist/core/bootstrap/provider-phase.js +0 -183
- package/dist/core/bootstrap/session-phase.js +0 -204
- package/dist/core/bootstrap/state.js +0 -94
- package/dist/core/bootstrap/workspace-phase.js +0 -115
- package/dist/core/bootstrap.js +0 -112
- package/dist/core/crash-handler.js +0 -62
- package/dist/core/environment.js +0 -224
- package/dist/core/host-plan.js +0 -43
- package/dist/core/host.js +0 -23
- package/dist/core/index.js +0 -3
- package/dist/core/prompt-builder.js +0 -95
- package/dist/core/prompt-overflow.js +0 -306
- package/dist/core/session-logger.js +0 -375
- package/dist/core/system-prompt.js +0 -117
- package/dist/core/types.js +0 -1
- package/dist/core/version.js +0 -28
- package/dist/core/web-host.js +0 -34
- package/dist/core/workspace.js +0 -80
- package/dist/i18n/index.js +0 -80
- package/dist/index.js +0 -30
- package/dist/llm/cache-usage.js +0 -76
- package/dist/llm/image-utils.js +0 -138
- package/dist/llm/index.js +0 -4
- package/dist/llm/llm-errors.js +0 -50
- package/dist/llm/model-loader.js +0 -86
- package/dist/llm/models-dev.js +0 -121
- package/dist/llm/openai-compat.js +0 -756
- package/dist/llm/orchestrator.js +0 -294
- package/dist/llm/provider-budget.js +0 -68
- package/dist/llm/provider-context.js +0 -233
- package/dist/llm/provider.js +0 -9
- package/dist/llm/response.js +0 -44
- package/dist/llm/stream-state.js +0 -26
- package/dist/llm/token-counter.js +0 -83
- package/dist/llm/types.js +0 -1
- package/dist/logger/app-logger.js +0 -212
- package/dist/logger/file-log.js +0 -160
- package/dist/logger/index.js +0 -2
- package/dist/migration/backup.js +0 -56
- package/dist/migration/detect.js +0 -61
- package/dist/migration/index.js +0 -3
- package/dist/modules/artifacts/store.js +0 -62
- package/dist/modules/browser/actions.js +0 -79
- package/dist/modules/browser/bridge-client.js +0 -203
- package/dist/modules/browser/bridge-path.js +0 -10
- package/dist/modules/browser/console-buffer.js +0 -37
- package/dist/modules/browser/cookie-store.js +0 -29
- package/dist/modules/browser/driver-types.js +0 -1
- package/dist/modules/browser/driver.js +0 -186
- package/dist/modules/browser/index.js +0 -9
- package/dist/modules/browser/module.js +0 -30
- package/dist/modules/browser/session.js +0 -322
- package/dist/modules/browser/snapshot.js +0 -154
- package/dist/modules/browser/types.js +0 -13
- package/dist/modules/certification/cli.js +0 -264
- package/dist/modules/certification/fact-checker.js +0 -90
- package/dist/modules/certification/loader.js +0 -127
- package/dist/modules/certification/manifest.js +0 -231
- package/dist/modules/certification/runner.js +0 -233
- package/dist/modules/certification/scenarios.js +0 -586
- package/dist/modules/certification/syntax-scenarios.js +0 -50
- package/dist/modules/certification/types.js +0 -1
- package/dist/modules/context/chunk-query.js +0 -122
- package/dist/modules/context/fact-extractor.js +0 -170
- package/dist/modules/context/history.js +0 -15
- package/dist/modules/context/index.js +0 -2
- package/dist/modules/context/manager.js +0 -482
- package/dist/modules/critic/client.js +0 -176
- package/dist/modules/critic/evidence.js +0 -81
- package/dist/modules/critic/provider.js +0 -45
- package/dist/modules/critic/tools.js +0 -78
- package/dist/modules/critic/types.js +0 -1
- package/dist/modules/execution/audit-runners.js +0 -206
- package/dist/modules/execution/auditor.js +0 -222
- package/dist/modules/execution/execution-plugin.js +0 -478
- package/dist/modules/execution/index.js +0 -8
- package/dist/modules/execution/input-from.js +0 -70
- package/dist/modules/execution/module.js +0 -891
- package/dist/modules/execution/moe-executor.js +0 -443
- package/dist/modules/execution/plan-actions.js +0 -642
- package/dist/modules/execution/plan-checks.js +0 -35
- package/dist/modules/execution/plan-coverage.js +0 -71
- package/dist/modules/execution/plan-persister.js +0 -46
- package/dist/modules/execution/plan-steps.js +0 -31
- package/dist/modules/execution/plan-store.js +0 -274
- package/dist/modules/execution/plan-tool.js +0 -249
- package/dist/modules/execution/plan-validator.js +0 -197
- package/dist/modules/execution/planner.js +0 -103
- package/dist/modules/execution/stuck-detector.js +0 -834
- package/dist/modules/execution/tracker.js +0 -92
- package/dist/modules/execution/transient-error.js +0 -30
- package/dist/modules/execution/types.js +0 -1
- package/dist/modules/execution/verifier.js +0 -343
- package/dist/modules/execution/windows-commands.js +0 -52
- package/dist/modules/hallucination/artifact-claim.js +0 -93
- package/dist/modules/hallucination/confidence.js +0 -81
- package/dist/modules/hallucination/consistency.js +0 -37
- package/dist/modules/hallucination/detector.js +0 -57
- package/dist/modules/hallucination/factual.js +0 -205
- package/dist/modules/hallucination/index.js +0 -6
- package/dist/modules/hallucination/js-identifiers.js +0 -261
- package/dist/modules/hallucination/llm-judge.js +0 -116
- package/dist/modules/hallucination/success-claim.js +0 -59
- package/dist/modules/index.js +0 -5
- package/dist/modules/indexer/cache.js +0 -88
- package/dist/modules/indexer/index.js +0 -4
- package/dist/modules/indexer/map-command.js +0 -33
- package/dist/modules/indexer/map-select.js +0 -87
- package/dist/modules/indexer/module.js +0 -293
- package/dist/modules/indexer/project-profile.js +0 -184
- package/dist/modules/indexer/symbols.js +0 -189
- package/dist/modules/indexer/walker.js +0 -285
- package/dist/modules/lsp/check-tool.js +0 -61
- package/dist/modules/lsp/client.js +0 -406
- package/dist/modules/lsp/command.js +0 -53
- package/dist/modules/lsp/config.js +0 -189
- package/dist/modules/lsp/index.js +0 -4
- package/dist/modules/lsp/module.js +0 -295
- package/dist/modules/lsp/probe.js +0 -86
- package/dist/modules/lsp/project-root.js +0 -69
- package/dist/modules/lsp/startup-check.js +0 -154
- package/dist/modules/lsp/types.js +0 -1
- package/dist/modules/mcp/client.js +0 -445
- package/dist/modules/mcp/index.js +0 -4
- package/dist/modules/mcp/module.js +0 -295
- package/dist/modules/mcp/registry.js +0 -20
- package/dist/modules/memory/index.js +0 -2
- package/dist/modules/memory/module.js +0 -101
- package/dist/modules/memory/search.js +0 -45
- package/dist/modules/memory/store.js +0 -107
- package/dist/modules/onboarding/init.js +0 -47
- package/dist/modules/onboarding/meet.js +0 -30
- package/dist/modules/onboarding/mode.js +0 -30
- package/dist/modules/onboarding/prompts.js +0 -43
- package/dist/modules/pipelines/engine.js +0 -70
- package/dist/modules/pipelines/index.js +0 -4
- package/dist/modules/pipelines/parser.js +0 -59
- package/dist/modules/pipelines/template.js +0 -18
- package/dist/modules/plugins/builtin/lint-on-write.js +0 -377
- package/dist/modules/plugins/builtin/notify.js +0 -11
- package/dist/modules/plugins/index.js +0 -2
- package/dist/modules/plugins/loader.js +0 -85
- package/dist/modules/plugins/manager.js +0 -244
- package/dist/modules/plugins/types.js +0 -1
- package/dist/modules/pricing/index.js +0 -70
- package/dist/modules/pricing/prices.js +0 -147
- package/dist/modules/processes/detect.js +0 -34
- package/dist/modules/processes/index.js +0 -4
- package/dist/modules/processes/kill-tree.js +0 -52
- package/dist/modules/processes/registry.js +0 -294
- package/dist/modules/processes/runner.js +0 -23
- package/dist/modules/providers/cache.js +0 -23
- package/dist/modules/providers/capabilities.js +0 -28
- package/dist/modules/providers/create.js +0 -21
- package/dist/modules/providers/factory.js +0 -28
- package/dist/modules/providers/fallback.js +0 -81
- package/dist/modules/providers/health.js +0 -47
- package/dist/modules/providers/index.js +0 -6
- package/dist/modules/providers/manager.js +0 -207
- package/dist/modules/providers/naming.js +0 -15
- package/dist/modules/providers/preflight.js +0 -71
- package/dist/modules/providers/presets.js +0 -232
- package/dist/modules/providers/registry.js +0 -27
- package/dist/modules/providers/types.js +0 -1
- package/dist/modules/reasoning/policy.js +0 -42
- package/dist/modules/reasoning/probe.js +0 -116
- package/dist/modules/registry.js +0 -48
- package/dist/modules/security/audit-log.js +0 -119
- package/dist/modules/security/audit-notifier.js +0 -267
- package/dist/modules/security/command-validator.js +0 -272
- package/dist/modules/security/content-scanner.js +0 -53
- package/dist/modules/security/data-sanitizer.js +0 -82
- package/dist/modules/security/encryption.js +0 -216
- package/dist/modules/security/index.js +0 -15
- package/dist/modules/security/network-validator.js +0 -236
- package/dist/modules/security/path-validator.js +0 -261
- package/dist/modules/security/protected-paths.js +0 -73
- package/dist/modules/security/rate-limiter.js +0 -98
- package/dist/modules/security/security-policies.js +0 -499
- package/dist/modules/security/session-encryption.js +0 -182
- package/dist/modules/security/session-isolation.js +0 -75
- package/dist/modules/session/auto-name.js +0 -63
- package/dist/modules/session/export.js +0 -98
- package/dist/modules/session/index.js +0 -4
- package/dist/modules/session/manager.js +0 -234
- package/dist/modules/session/module.js +0 -33
- package/dist/modules/session/store.js +0 -295
- package/dist/modules/session/types.js +0 -1
- package/dist/modules/setup/answers.js +0 -35
- package/dist/modules/setup/apply.js +0 -79
- package/dist/modules/setup/discovery.js +0 -72
- package/dist/modules/skills/index.js +0 -3
- package/dist/modules/skills/loader.js +0 -86
- package/dist/modules/skills/matcher.js +0 -27
- package/dist/modules/skills/module.js +0 -141
- package/dist/modules/types.js +0 -1
- package/dist/modules/updater/changelog-reader.js +0 -93
- package/dist/modules/updater/checker.js +0 -101
- package/dist/modules/updater/dev-detect.js +0 -18
- package/dist/modules/updater/index.js +0 -4
- package/dist/modules/updater/module.js +0 -129
- package/dist/modules/user-profile/compressor.js +0 -18
- package/dist/modules/user-profile/index.js +0 -2
- package/dist/modules/user-profile/profile.js +0 -77
- package/dist/modules/webui/answer-api.js +0 -29
- package/dist/modules/webui/assets.js +0 -50
- package/dist/modules/webui/body.js +0 -21
- package/dist/modules/webui/commands-settings.js +0 -209
- package/dist/modules/webui/commands-shared.js +0 -60
- package/dist/modules/webui/commands.js +0 -174
- package/dist/modules/webui/config-api.js +0 -134
- package/dist/modules/webui/file-api.js +0 -202
- package/dist/modules/webui/forward.js +0 -159
- package/dist/modules/webui/history-api.js +0 -112
- package/dist/modules/webui/host-state.js +0 -60
- package/dist/modules/webui/i18n-api.js +0 -9
- package/dist/modules/webui/limits.js +0 -6
- package/dist/modules/webui/log-forward.js +0 -20
- package/dist/modules/webui/memory-commands.js +0 -64
- package/dist/modules/webui/model-cache.js +0 -18
- package/dist/modules/webui/module.js +0 -148
- package/dist/modules/webui/persist.js +0 -24
- package/dist/modules/webui/prompt-io.js +0 -97
- package/dist/modules/webui/providers-api.js +0 -337
- package/dist/modules/webui/providers-view.js +0 -56
- package/dist/modules/webui/reasoning-view.js +0 -15
- package/dist/modules/webui/run-agent.js +0 -81
- package/dist/modules/webui/server.js +0 -284
- package/dist/modules/webui/sessions-api.js +0 -178
- package/dist/modules/webui/settings-api.js +0 -561
- package/dist/modules/webui/setup-api.js +0 -201
- package/dist/modules/webui/state.js +0 -74
- package/dist/modules/webui/util.js +0 -261
- package/dist/output/bus.js +0 -37
- package/dist/output/channel.js +0 -285
- package/dist/output/format.js +0 -15
- package/dist/output/index.js +0 -8
- package/dist/output/json-sink.js +0 -24
- package/dist/output/machine.js +0 -9
- package/dist/output/session-sink.js +0 -27
- package/dist/output/types.js +0 -1
- package/dist/tools/approve.js +0 -41
- package/dist/tools/attach-image.js +0 -102
- package/dist/tools/auto-fixer.js +0 -180
- package/dist/tools/auto-tags.js +0 -83
- package/dist/tools/bash.js +0 -649
- package/dist/tools/browser.js +0 -160
- package/dist/tools/chunk-query.js +0 -112
- package/dist/tools/create-dir.js +0 -60
- package/dist/tools/delete-file.js +0 -67
- package/dist/tools/download-file.js +0 -142
- package/dist/tools/edit-file.js +0 -136
- package/dist/tools/enable-tools.js +0 -59
- package/dist/tools/executor.js +0 -304
- package/dist/tools/file-info.js +0 -49
- package/dist/tools/filter-tools.js +0 -17
- package/dist/tools/glob-tool.js +0 -37
- package/dist/tools/grep-tool.js +0 -142
- package/dist/tools/hidden-tools-block.js +0 -37
- package/dist/tools/index.js +0 -88
- package/dist/tools/list-dir.js +0 -53
- package/dist/tools/load-skill.js +0 -51
- package/dist/tools/mcp-call.js +0 -80
- package/dist/tools/meet-done.js +0 -14
- package/dist/tools/move-file.js +0 -94
- package/dist/tools/path-utils.js +0 -108
- package/dist/tools/pipeline-run.js +0 -167
- package/dist/tools/preview.js +0 -2
- package/dist/tools/process-ids.js +0 -31
- package/dist/tools/process-kill.js +0 -33
- package/dist/tools/process-list.js +0 -38
- package/dist/tools/process-log.js +0 -49
- package/dist/tools/process-wait.js +0 -63
- package/dist/tools/prompt-io.js +0 -29
- package/dist/tools/question.js +0 -288
- package/dist/tools/read-file.js +0 -200
- package/dist/tools/recall.js +0 -124
- package/dist/tools/registry.js +0 -48
- package/dist/tools/remember.js +0 -72
- package/dist/tools/scope-check.js +0 -32
- package/dist/tools/scope-request.js +0 -96
- package/dist/tools/search-history.js +0 -88
- package/dist/tools/session-info.js +0 -46
- package/dist/tools/set-thinking.js +0 -75
- package/dist/tools/subagent.js +0 -257
- package/dist/tools/syntax-validator.js +0 -379
- package/dist/tools/types.js +0 -1
- package/dist/tools/user-input.js +0 -134
- package/dist/tools/web-browse.js +0 -93
- package/dist/tools/web-fetch.js +0 -108
- package/dist/tools/web-search.js +0 -107
- package/dist/tools/write-file.js +0 -128
- package/dist/ui/action-log.js +0 -13
- package/dist/ui/box.js +0 -78
- package/dist/ui/colors.js +0 -6
- package/dist/ui/diff.js +0 -189
- package/dist/ui/index.js +0 -7
- package/dist/ui/line-editor.js +0 -1083
- package/dist/ui/line-math.js +0 -98
- package/dist/ui/md-formatter.js +0 -322
- package/dist/ui/output.js +0 -19
- package/dist/ui/plan-view.js +0 -109
- package/dist/ui/renderer.js +0 -589
- package/dist/ui/spinner.js +0 -91
- package/dist/ui/table.js +0 -142
- package/dist/ui/theme.js +0 -143
- package/dist/utils/child-run.js +0 -20
- package/dist/utils/error.js +0 -4
- package/dist/utils/index.js +0 -6
- package/dist/utils/retry.js +0 -17
- package/dist/utils/sleep.js +0 -23
- 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
|
-
}
|