micro-models-agent 2.16.0 → 2.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- 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 -1211
- 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 -277
- package/dist/assets/setup.js +3 -816
- package/dist/assets/smd.js +29 -1665
- package/dist/assets/styles.css +1 -1592
- 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,21 +0,0 @@
|
|
|
1
|
-
import { readBody } from "./util";
|
|
2
|
-
/** Парсит сырое тело; `null` — битый JSON. Не бросает. */
|
|
3
|
-
export function parseJsonBody(raw) {
|
|
4
|
-
let parsed;
|
|
5
|
-
try {
|
|
6
|
-
parsed = JSON.parse(raw);
|
|
7
|
-
}
|
|
8
|
-
catch {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
return typeof parsed === "object" && parsed !== null
|
|
12
|
-
? parsed
|
|
13
|
-
: {};
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Читает тело запроса (до `cap`) и парсит как JSON.
|
|
17
|
-
* Резолвится в `null` на битом JSON; транспортные ошибки реджектятся.
|
|
18
|
-
*/
|
|
19
|
-
export function readJsonBody(req, cap) {
|
|
20
|
-
return readBody(req, cap).then((raw) => parseJsonBody(raw));
|
|
21
|
-
}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
// Расширенные слеш-хендлеры `mma web`: reasoning/verbosity/context/security/session/export.
|
|
2
|
-
/**
|
|
3
|
-
* Зеркалит REPL-семантику `src/cli/repl-commands.ts` для подмножества без
|
|
4
|
-
* терминала. Вне скоупа терминальное (`/meet`, `/wizard`, `/init`,
|
|
5
|
-
* интерактивные промпты, `/provider add`) — им нужны `PromptIO`/канал вывода REPL.
|
|
6
|
-
*
|
|
7
|
-
* Каждый хендлер эмитит plain-строки без цвета (дим — на браузере) и не бросает;
|
|
8
|
-
* ошибки становятся дим-подсказкой `↳ ...`.
|
|
9
|
-
*/
|
|
10
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
11
|
-
import { dirname, join } from "node:path";
|
|
12
|
-
import { getConfigValue } from "../../config/registry";
|
|
13
|
-
import { t } from "../../i18n";
|
|
14
|
-
import { extensionFor, formatExport, redactExport, sanitizeFileName, } from "../session/export";
|
|
15
|
-
import { errMsg } from "../../utils/error";
|
|
16
|
-
import { applyConfigWrite, withConfig } from "./commands-shared";
|
|
17
|
-
import { globalExportsDir } from "../../config/paths";
|
|
18
|
-
const REASONING_USAGE = "/reasoning [show|hide|on|off|level <auto|default|none|low|medium|high|max>]";
|
|
19
|
-
const CONTEXT_USAGE = "/context [<tokens> | system <share> | reserve <share>]";
|
|
20
|
-
const SECURITY_USAGE = "/security [status|<key> [value]]";
|
|
21
|
-
/** Хендлеры, вмёрженные в ядерный диспатч; ключи — имена команд в нижнем регистре. */
|
|
22
|
-
export function makeSettingsHandlers(state) {
|
|
23
|
-
return {
|
|
24
|
-
reasoning: (args, o) => withConfig(state, o, (cfg) => reasoningCmd(cfg, args, o, state)),
|
|
25
|
-
verbose: (args, o) => withConfig(state, o, (cfg) => verboseCmd(cfg, args, o, state)),
|
|
26
|
-
context: (args, o) => withConfig(state, o, (cfg) => contextCmd(cfg, args, o, state)),
|
|
27
|
-
security: (args, o) => withConfig(state, o, (cfg) => securityCmd(cfg, args, o, state)),
|
|
28
|
-
session: (args, o) => sessionCmd(state, args, o),
|
|
29
|
-
export: (args, o) => exportCmd(state, args, o),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function reasoningCmd(cfg, args, out, state) {
|
|
33
|
-
const sub = args[0]?.trim().toLowerCase();
|
|
34
|
-
if (!sub) {
|
|
35
|
-
const show = cfg.showReasoning ? "on" : "off";
|
|
36
|
-
const mode = cfg.reasoning?.mode ?? "auto";
|
|
37
|
-
out(`reasoning: ${show} · level ${mode}${mode === "auto" ? " (auto)" : ""}`);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (sub === "show" || sub === "on" || sub === "hide" || sub === "off") {
|
|
41
|
-
const on = sub === "show" || sub === "on";
|
|
42
|
-
return applyConfigWrite(cfg, "showReasoning", on ? "on" : "off", out, state);
|
|
43
|
-
}
|
|
44
|
-
if (sub === "level") {
|
|
45
|
-
const lvl = args[1]?.trim().toLowerCase();
|
|
46
|
-
if (!lvl) {
|
|
47
|
-
out(`usage: ${REASONING_USAGE}`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
return applyConfigWrite(cfg, "reasoning.mode", lvl, out, state);
|
|
51
|
-
}
|
|
52
|
-
out(`↳ unknown subcommand: reasoning ${sub}`);
|
|
53
|
-
out(`usage: ${REASONING_USAGE}`);
|
|
54
|
-
}
|
|
55
|
-
function verboseCmd(cfg, args, out, state) {
|
|
56
|
-
const level = args[0]?.trim().toLowerCase();
|
|
57
|
-
if (!level) {
|
|
58
|
-
const r = getConfigValue(cfg, "ui.verbosity");
|
|
59
|
-
out(`verbosity: ${r.ok ? r.display : "—"}`);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
return applyConfigWrite(cfg, "ui.verbosity", level, out, state);
|
|
63
|
-
}
|
|
64
|
-
function contextCmd(cfg, args, out, state) {
|
|
65
|
-
if (args.length === 0) {
|
|
66
|
-
const used = state.usage?.contextUsed;
|
|
67
|
-
const limit = state.usage?.contextLimit ?? cfg.contextWindow;
|
|
68
|
-
out(used !== undefined ? `context: ${used} / ${limit} tok` : `context: ${cfg.contextWindow} tok`);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (args[0] === "system" || args[0] === "reserve") {
|
|
72
|
-
const raw = args[1];
|
|
73
|
-
if (!raw) {
|
|
74
|
-
out(`usage: ${CONTEXT_USAGE}`);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const key = args[0] === "system" ? "contextBudget.systemPrompt" : "contextBudget.responseReserve";
|
|
78
|
-
return applyConfigWrite(cfg, key, raw, out, state);
|
|
79
|
-
}
|
|
80
|
-
if (!/^\d+$/.test(args[0])) {
|
|
81
|
-
out(`↳ unknown argument: ${args[0]}`);
|
|
82
|
-
out(`usage: ${CONTEXT_USAGE}`);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
return applyConfigWrite(cfg, "contextWindow", args[0], out, state);
|
|
86
|
-
}
|
|
87
|
-
function securityCmd(cfg, args, out, state) {
|
|
88
|
-
const sub = args[0]?.trim().toLowerCase();
|
|
89
|
-
if (!sub || sub === "status") {
|
|
90
|
-
const flag = (v) => (v ? t("reasoning.on") : t("reasoning.off"));
|
|
91
|
-
const s = cfg.security;
|
|
92
|
-
out(`security · ${flag(s?.enabled)}`);
|
|
93
|
-
out(`↳ bash ${flag(s?.bash.enabled)} · paths ${flag(s?.paths.enabled)} · network ${flag(s?.network.enabled)}`);
|
|
94
|
-
out(`↳ contentScan ${flag(s?.contentScan.enabled)} · encryption ${flag(s?.sessionEncryption.enabled)}`);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (args.length >= 2) {
|
|
98
|
-
return applyConfigWrite(cfg, args[0], args.slice(1).join(" "), out, state);
|
|
99
|
-
}
|
|
100
|
-
out(`↳ ${t("web.security.unknown_sub", { sub: args[0] })}`);
|
|
101
|
-
out(`usage: ${SECURITY_USAGE}`);
|
|
102
|
-
}
|
|
103
|
-
function sessionCmd(state, args, out) {
|
|
104
|
-
const mgr = state.sessionManager;
|
|
105
|
-
if (!mgr) {
|
|
106
|
-
out("↳ sessions unavailable");
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const [sub, ...rest] = args;
|
|
110
|
-
if (!sub || sub === "list") {
|
|
111
|
-
const sessions = mgr.list();
|
|
112
|
-
if (sessions.length === 0) {
|
|
113
|
-
out("no sessions");
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const active = mgr.getActive();
|
|
117
|
-
for (const s of sessions) {
|
|
118
|
-
const marker = s.id === active ? "* " : " ";
|
|
119
|
-
out(`${marker}${s.id.slice(0, 12)} ${s.name} (${s.messageCount} msgs)`);
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (sub === "use") {
|
|
124
|
-
const query = rest.join(" ").trim();
|
|
125
|
-
if (!query) {
|
|
126
|
-
out("usage: /session use <id>");
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const match = mgr
|
|
130
|
-
.list()
|
|
131
|
-
.find((s) => s.id === query ||
|
|
132
|
-
s.id.startsWith(query) ||
|
|
133
|
-
s.name.toLowerCase().includes(query.toLowerCase()));
|
|
134
|
-
if (!match) {
|
|
135
|
-
out(`↳ no matching session: ${query}`);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
mgr.setActive(match.id);
|
|
140
|
-
}
|
|
141
|
-
catch (err) {
|
|
142
|
-
out(`↳ ${errMsg(err)}`);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
out(`active session: ${match.name} (${match.id.slice(0, 12)})`);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
out(`↳ unknown subcommand: session ${sub}`);
|
|
149
|
-
}
|
|
150
|
-
function exportCmd(state, args, out) {
|
|
151
|
-
const mgr = state.sessionManager;
|
|
152
|
-
if (!mgr) {
|
|
153
|
-
out("↳ sessions unavailable");
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
let format = "md";
|
|
157
|
-
let outPath;
|
|
158
|
-
const positional = [];
|
|
159
|
-
for (let i = 0; i < args.length; i++) {
|
|
160
|
-
const a = args[i];
|
|
161
|
-
if (a === "--out") {
|
|
162
|
-
const v = args[++i];
|
|
163
|
-
if (v === undefined) {
|
|
164
|
-
out("↳ --out requires a value");
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
outPath = v;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
positional.push(a);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const first = positional[0]?.toLowerCase();
|
|
174
|
-
if (first === "md" || first === "json" || first === "jsonl")
|
|
175
|
-
format = first;
|
|
176
|
-
else if (first) {
|
|
177
|
-
out(`↳ unknown format: ${positional[0]}`);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if (!mgr.getHistory || !mgr.loadSessionLog) {
|
|
181
|
-
out("↳ export unavailable: this web session store does not expose history");
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const active = mgr.getActive();
|
|
185
|
-
const match = active ? mgr.get(active) : null;
|
|
186
|
-
if (!active || !match) {
|
|
187
|
-
out("↳ no active session");
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const messages = mgr.getHistory(active);
|
|
191
|
-
const log = mgr.loadSessionLog(active);
|
|
192
|
-
if (format === "jsonl" ? log.length === 0 : messages.length === 0) {
|
|
193
|
-
out("↳ nothing to export");
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const text = redactExport(formatExport({ meta: match, messages, log }, format), true);
|
|
197
|
-
const dir = outPath ? dirname(outPath) : globalExportsDir();
|
|
198
|
-
const path = outPath ??
|
|
199
|
-
join(dir, `${sanitizeFileName(match.name)}-${match.id.slice(0, 8)}.${extensionFor(format)}`);
|
|
200
|
-
try {
|
|
201
|
-
mkdirSync(dir, { recursive: true });
|
|
202
|
-
writeFileSync(path, text, "utf-8");
|
|
203
|
-
}
|
|
204
|
-
catch (err) {
|
|
205
|
-
out(`↳ export failed: ${errMsg(err)}`);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
out(`exported ${format} → ${path}`);
|
|
209
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { setLocale } from "../../i18n";
|
|
2
|
-
import { setConfigValue } from "../../config/registry";
|
|
3
|
-
/** Гоняет `fn` только при wired конфиге; иначе — подсказка. */
|
|
4
|
-
export function withConfig(state, out, fn) {
|
|
5
|
-
if (!state.config) {
|
|
6
|
-
out("↳ config unavailable");
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
return fn(state.config);
|
|
10
|
-
}
|
|
11
|
-
/** Мета активной сессии; null, если сессий нет. */
|
|
12
|
-
export function activeMeta(state) {
|
|
13
|
-
const id = state.sessionManager?.getActive();
|
|
14
|
-
return id ? (state.sessionManager?.get(id) ?? null) : null;
|
|
15
|
-
}
|
|
16
|
-
/** Человекочитаемый текст ошибки записи конфига по причине реестра. */
|
|
17
|
-
export function configErrorText(reason, input, key) {
|
|
18
|
-
const target = key ?? input;
|
|
19
|
-
switch (reason) {
|
|
20
|
-
case "unknown-key":
|
|
21
|
-
return `unknown key: ${input}`;
|
|
22
|
-
case "read-only":
|
|
23
|
-
return `${target} is read-only`;
|
|
24
|
-
case "range":
|
|
25
|
-
return `value out of range for ${target}`;
|
|
26
|
-
case "combined":
|
|
27
|
-
return "shares exceed the combined limit";
|
|
28
|
-
default:
|
|
29
|
-
return `invalid value for ${target}`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/** Персист + reconfigure после успешной записи реестра, затем отчёт. */
|
|
33
|
-
export async function applyConfigWrite(cfg, name, value, out, state) {
|
|
34
|
-
const result = setConfigValue(cfg, name, value);
|
|
35
|
-
if (!result.ok) {
|
|
36
|
-
out(`↳ ${configErrorText(result.reason, result.input, result.key)}`);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
// У `locale` в реестре `reconfigure: false`, так что больше некому применить
|
|
40
|
-
// его к процесс-глобальному i18n. Делаем здесь, чтобы серверный вывод и
|
|
41
|
-
// перезапрошенный словарь браузера сошлись сразу (зеркалит `handleConfigPost`).
|
|
42
|
-
if (result.key === "locale")
|
|
43
|
-
setLocale(cfg.locale);
|
|
44
|
-
let note = "saved";
|
|
45
|
-
try {
|
|
46
|
-
state.saveConfig?.(cfg);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
note = "not persisted";
|
|
50
|
-
}
|
|
51
|
-
if (result.reconfigure && state.reconfigure) {
|
|
52
|
-
try {
|
|
53
|
-
await state.reconfigure(cfg);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
note = `${note}; reconfigure failed`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
out(`${result.key} = ${result.display} · ${note}`);
|
|
60
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { t } from "../../i18n";
|
|
2
|
-
import { canonicalKeys, getConfigValue } from "../../config/registry";
|
|
3
|
-
import { redactContextSecrets } from "../../core/agent/context-log";
|
|
4
|
-
import { errMsg } from "../../utils/error";
|
|
5
|
-
import { memoryLines } from "./memory-commands";
|
|
6
|
-
import { makeSettingsHandlers } from "./commands-settings";
|
|
7
|
-
import { activeMeta, applyConfigWrite, withConfig } from "./commands-shared";
|
|
8
|
-
import { broadcast } from "./state";
|
|
9
|
-
/**
|
|
10
|
-
* Поддерживаемое подмножество для `/help` (по строке). Описания — ключи i18n
|
|
11
|
-
* (`web.command.*`), резолвятся в момент эмита, чтобы `/help` и
|
|
12
|
-
* `GET /api/commands` шли за серверной локалью.
|
|
13
|
-
*/
|
|
14
|
-
const HELP = [
|
|
15
|
-
{ usage: "/help", descKey: "web.command.help" },
|
|
16
|
-
{ usage: "/status", descKey: "web.command.status" },
|
|
17
|
-
{ usage: "/config <key> [value]", descKey: "web.command.config" },
|
|
18
|
-
{ usage: "/model list | /model use <name>", descKey: "web.command.model" },
|
|
19
|
-
{ usage: "/provider list | /provider use <name>", descKey: "web.command.provider" },
|
|
20
|
-
{ usage: "/reasoning [show|hide|on|off|level <lvl>]", descKey: "web.command.reasoning" },
|
|
21
|
-
{ usage: "/verbose <quiet|normal|verbose>", descKey: "web.command.verbose" },
|
|
22
|
-
{ usage: "/context [<tokens>]", descKey: "web.command.context" },
|
|
23
|
-
{ usage: "/security [status|<key> [value]]", descKey: "web.command.security" },
|
|
24
|
-
{ usage: "/session list | /session use <id>", descKey: "web.command.session" },
|
|
25
|
-
{ usage: "/export [md|json|jsonl]", descKey: "web.command.export" },
|
|
26
|
-
{ usage: "/memory [get|set|unset|find|forget]", descKey: "web.command.memory" },
|
|
27
|
-
{ usage: "/clear", descKey: "web.command.clear" },
|
|
28
|
-
{ usage: "/new", descKey: "web.command.new" },
|
|
29
|
-
];
|
|
30
|
-
/** Пейлоад `GET /api/commands`: имя + usage + описание на команду. */
|
|
31
|
-
export function webCommandList() {
|
|
32
|
-
return HELP.map((h) => ({
|
|
33
|
-
name: h.usage.slice(1).split(/[\s|]/)[0],
|
|
34
|
-
usage: h.usage,
|
|
35
|
-
desc: t(h.descKey),
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
/** Строит диспатчер `(line) => Promise<void>`, ввязанный в `WebHost`. */
|
|
39
|
-
export function makeWebCommands(deps) {
|
|
40
|
-
const { state } = deps;
|
|
41
|
-
const raw = deps.emit ??
|
|
42
|
-
((text) => broadcast({ type: "command", ts: Date.now(), text }, state));
|
|
43
|
-
// Каждая эмитимая строка — через точечную редактуру: чтения конфига могут
|
|
44
|
-
// эхом вернуть только что заданный ключ, а лента видна пользователю.
|
|
45
|
-
const out = (text) => raw(redactContextSecrets(text));
|
|
46
|
-
const handlers = {
|
|
47
|
-
help: (_args, o) => HELP.forEach((h) => o(`${h.usage} · ${t(h.descKey)}`)),
|
|
48
|
-
status: (_args, o) => withConfig(state, o, (cfg) => status(cfg, state, o)),
|
|
49
|
-
config: (args, o) => withConfig(state, o, (cfg) => configCmd(cfg, args, o, state)),
|
|
50
|
-
model: (args, o) => withConfig(state, o, (cfg) => modelCmd(cfg, args, o, state)),
|
|
51
|
-
provider: (args, o) => withConfig(state, o, (cfg) => providerCmd(cfg, args, o, state)),
|
|
52
|
-
memory: (args, o) => memoryCmd(state, args, o),
|
|
53
|
-
...makeSettingsHandlers(state),
|
|
54
|
-
};
|
|
55
|
-
return async (line) => {
|
|
56
|
-
const trimmed = line.trim();
|
|
57
|
-
if (!trimmed.startsWith("/"))
|
|
58
|
-
return;
|
|
59
|
-
const parts = trimmed.slice(1).trim().split(/\s+/);
|
|
60
|
-
const name = (parts.shift() ?? "").toLowerCase();
|
|
61
|
-
if (!name)
|
|
62
|
-
return;
|
|
63
|
-
const handler = handlers[name];
|
|
64
|
-
if (!handler) {
|
|
65
|
-
out(`↳ unknown command: ${name}`);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
await handler(parts, out);
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
out(`↳ ${errMsg(err)}`);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/** Однострочный статус: модель · провайдер · контекст · сессия · verbosity (+ окружение). */
|
|
77
|
-
function status(cfg, state, out) {
|
|
78
|
-
const provider = cfg.provider.active ?? cfg.provider.type;
|
|
79
|
-
const parts = [cfg.model, provider, `${cfg.contextWindow} tok`];
|
|
80
|
-
const meta = activeMeta(state);
|
|
81
|
-
if (meta)
|
|
82
|
-
parts.push(`${meta.name} (${meta.messageCount} msgs)`);
|
|
83
|
-
const verbosity = getConfigValue(cfg, "ui.verbosity");
|
|
84
|
-
parts.push(verbosity.ok ? verbosity.display : "—");
|
|
85
|
-
out(parts.join(" · "));
|
|
86
|
-
if (state.workspace)
|
|
87
|
-
out(`dir: ${state.workspace}`);
|
|
88
|
-
if (state.agentsMd) {
|
|
89
|
-
if (state.agentsMd.disabled)
|
|
90
|
-
out("AGENTS.md: disabled");
|
|
91
|
-
else if (state.agentsMd.files.length)
|
|
92
|
-
out(`AGENTS.md: ${state.agentsMd.files.join(", ")}`);
|
|
93
|
-
else
|
|
94
|
-
out("AGENTS.md: not found");
|
|
95
|
-
}
|
|
96
|
-
if (state.projectMapStats) {
|
|
97
|
-
const map = state.projectMapStats();
|
|
98
|
-
out(map ? `map: ${map.files} file(s) · ${map.symbols} sym · ~${map.tokens} tok` : "map: not indexed");
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/** `/config`: без аргументов — весь реестр, с ключом — чтение, с ключом+значением — запись. */
|
|
102
|
-
async function configCmd(cfg, args, out, state) {
|
|
103
|
-
if (args.length === 0) {
|
|
104
|
-
for (const key of canonicalKeys()) {
|
|
105
|
-
const r = getConfigValue(cfg, key);
|
|
106
|
-
if (r.ok)
|
|
107
|
-
out(`${key} = ${r.display}`);
|
|
108
|
-
}
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const [key, ...rest] = args;
|
|
112
|
-
if (rest.length === 0) {
|
|
113
|
-
const r = getConfigValue(cfg, key);
|
|
114
|
-
out(r.ok ? `${r.key} = ${r.display}` : `↳ unknown key: ${key}`);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
await applyConfigWrite(cfg, key, rest.join(" "), out, state);
|
|
118
|
-
}
|
|
119
|
-
async function modelCmd(cfg, args, out, state) {
|
|
120
|
-
const [sub, ...rest] = args;
|
|
121
|
-
if (!sub || sub === "list") {
|
|
122
|
-
out(`current: ${cfg.model}`);
|
|
123
|
-
const models = state.knownModels?.() ?? [];
|
|
124
|
-
if (models.length === 0) {
|
|
125
|
-
out("↳ no models reported by provider");
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
for (const m of models)
|
|
129
|
-
out(`${m === cfg.model ? "* " : " "}${m}`);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (sub === "use") {
|
|
133
|
-
const name = rest[0];
|
|
134
|
-
if (!name) {
|
|
135
|
-
out("usage: /model use <name>");
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
await applyConfigWrite(cfg, "model", name, out, state);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
out(`↳ unknown subcommand: model ${sub}`);
|
|
142
|
-
}
|
|
143
|
-
async function providerCmd(cfg, args, out, state) {
|
|
144
|
-
const [sub, ...rest] = args;
|
|
145
|
-
if (!sub || sub === "list") {
|
|
146
|
-
const active = cfg.provider.active ?? cfg.provider.type;
|
|
147
|
-
const entries = cfg.provider.entries?.length
|
|
148
|
-
? cfg.provider.entries
|
|
149
|
-
: [{ type: cfg.provider.type, label: active }];
|
|
150
|
-
for (const e of entries) {
|
|
151
|
-
const name = e.label ?? e.type;
|
|
152
|
-
out(`${name === active ? "* " : " "}${name} (${e.type})`);
|
|
153
|
-
}
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (sub === "use") {
|
|
157
|
-
const name = rest[0];
|
|
158
|
-
if (!name) {
|
|
159
|
-
out("usage: /provider use <name>");
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
await applyConfigWrite(cfg, "provider.active", name, out, state);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
out(`↳ unknown subcommand: provider ${sub}`);
|
|
166
|
-
}
|
|
167
|
-
function memoryCmd(state, args, out) {
|
|
168
|
-
if (!state.memory) {
|
|
169
|
-
out("↳ memory unavailable");
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
for (const line of memoryLines(state.memory, args))
|
|
173
|
-
out(line);
|
|
174
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { setLocale } from "../../i18n";
|
|
2
|
-
import { redactConfigSecrets } from "../../config/redact";
|
|
3
|
-
import { configDefs, setConfigValue } from "../../config/registry";
|
|
4
|
-
import { readBodyError, sendJson } from "./util";
|
|
5
|
-
import { readJsonBody } from "./body";
|
|
6
|
-
import { persistAndReconfigure } from "./persist";
|
|
7
|
-
import { buildReasoningView } from "./reasoning-view";
|
|
8
|
-
/** Сериализует реестр в порядке реестра (только канонические ключи). */
|
|
9
|
-
export function buildConfigRegistry(config) {
|
|
10
|
-
return configDefs().map((def) => {
|
|
11
|
-
const entry = {
|
|
12
|
-
key: def.key,
|
|
13
|
-
aliases: def.aliases,
|
|
14
|
-
valueType: def.valueType,
|
|
15
|
-
group: def.domain,
|
|
16
|
-
};
|
|
17
|
-
if (def.enumValues)
|
|
18
|
-
entry.enum = def.enumValues;
|
|
19
|
-
if (def.min !== undefined)
|
|
20
|
-
entry.min = def.min;
|
|
21
|
-
if (def.max !== undefined)
|
|
22
|
-
entry.max = def.max;
|
|
23
|
-
if (def.step !== undefined)
|
|
24
|
-
entry.step = def.step;
|
|
25
|
-
if (def.readOnly) {
|
|
26
|
-
entry.readOnly = true;
|
|
27
|
-
if (config)
|
|
28
|
-
entry.value = def.get(config);
|
|
29
|
-
}
|
|
30
|
-
if (def.editor)
|
|
31
|
-
entry.editor = def.editor;
|
|
32
|
-
return entry;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
/** Маскирует секрет для показа: последние 4 символа видны, остальное скрыто. */
|
|
36
|
-
function maskToken(token) {
|
|
37
|
-
if (!token)
|
|
38
|
-
return null;
|
|
39
|
-
return token.length <= 4 ? "••••" : `••••${token.slice(-4)}`;
|
|
40
|
-
}
|
|
41
|
-
/** `GET /api/config` — отредактированный живой конфиг + реестр ключей. */
|
|
42
|
-
export function handleConfigGet(res, s) {
|
|
43
|
-
if (!s.config) {
|
|
44
|
-
sendJson(res, 503, { error: "config_unavailable" });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
sendJson(res, 200, {
|
|
48
|
-
config: redactConfigSecrets(s.config),
|
|
49
|
-
registry: buildConfigRegistry(s.config),
|
|
50
|
-
webToken: maskToken(s.token),
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/** Коэрсит JSON-`value` в сырую строку для `setConfigValue`. */
|
|
54
|
-
function toRawValue(value) {
|
|
55
|
-
if (typeof value === "string")
|
|
56
|
-
return value;
|
|
57
|
-
if (typeof value === "number" || typeof value === "boolean")
|
|
58
|
-
return String(value);
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
/** `POST /api/config {key, value}` — валидация, применение, персист, reconfigure. */
|
|
62
|
-
export function handleConfigPost(req, res, s) {
|
|
63
|
-
if (!s.config) {
|
|
64
|
-
sendJson(res, 503, { error: "config_unavailable" });
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const config = s.config;
|
|
68
|
-
readJsonBody(req, s.maxBodyBytes)
|
|
69
|
-
.then(async (rec) => {
|
|
70
|
-
if (!rec) {
|
|
71
|
-
sendJson(res, 400, { ok: false, error: "invalid JSON" });
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const key = typeof rec.key === "string" ? rec.key : "";
|
|
75
|
-
const rawValue = toRawValue(rec.value);
|
|
76
|
-
if (!key || rawValue === null) {
|
|
77
|
-
sendJson(res, 400, { ok: false, error: "invalid-value" });
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const result = setConfigValue(config, key, rawValue);
|
|
81
|
-
if (!result.ok) {
|
|
82
|
-
sendJson(res, 400, { ok: false, error: result.reason });
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// У `locale` в реестре `reconfigure: false`, так что больше некому применить
|
|
86
|
-
// его к процесс-глобальному i18n. Делаем здесь, чтобы серверный вывод и
|
|
87
|
-
// перезапрошенный словарь браузера сошлись сразу.
|
|
88
|
-
if (key === "locale")
|
|
89
|
-
setLocale(config.locale);
|
|
90
|
-
// Сначала персист, затем reconfigure — но только когда реестр требует
|
|
91
|
-
// реконфига для ключа; иначе shared шаг зря дёргал бы провайдеров/модели
|
|
92
|
-
// на каждое нажатие.
|
|
93
|
-
let persisted = true;
|
|
94
|
-
let warning;
|
|
95
|
-
if (result.reconfigure) {
|
|
96
|
-
({ persisted, warning } = await persistAndReconfigure(s, config));
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
try {
|
|
100
|
-
s.saveConfig?.(config);
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
persisted = false;
|
|
104
|
-
warning = "config not persisted";
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const body = {
|
|
108
|
-
ok: true,
|
|
109
|
-
value: result.value,
|
|
110
|
-
display: result.display,
|
|
111
|
-
persisted,
|
|
112
|
-
};
|
|
113
|
-
if (warning)
|
|
114
|
-
body.warning = warning;
|
|
115
|
-
sendJson(res, 200, body);
|
|
116
|
-
})
|
|
117
|
-
.catch((err) => {
|
|
118
|
-
readBodyError(req, res, err);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/** `GET /api/models` — id моделей активного провайдера. */
|
|
122
|
-
export function handleModelsGet(res, s) {
|
|
123
|
-
if (!s.knownModels) {
|
|
124
|
-
sendJson(res, 503, { error: "models_unavailable" });
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
// `reasoning` аддитивен и выводится на запрос из живого конфига, так что ряд
|
|
128
|
-
// селекторов всегда отражает активных провайдера+модель без reconfigure-обвязки.
|
|
129
|
-
// Без wired конфига опускается (легаси-стабы).
|
|
130
|
-
const body = { models: s.knownModels() };
|
|
131
|
-
if (s.config)
|
|
132
|
-
body.reasoning = buildReasoningView(s.config);
|
|
133
|
-
sendJson(res, 200, body);
|
|
134
|
-
}
|