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,1914 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// Imports loaders-adjacent chrome (closeAllMenus, setSessOpen) and data loaders
|
|
3
|
-
// share from tabs; confirm/toast from dialog. Never imports app (the locale
|
|
4
|
-
// refresh reaches the app shell through the store hooks registry).
|
|
5
|
-
import {
|
|
6
|
-
el, icon, link, inlineTextNodes, connStatus, staleBar, makeToggle,
|
|
7
|
-
} from "./dom.js";
|
|
8
|
-
import { api } from "./api.js";
|
|
9
|
-
import { t, loadI18n } from "./i18n.js";
|
|
10
|
-
import { S, setPath, getPath, THEME_KEY, hooks } from "./store.js";
|
|
11
|
-
import { contextLabel, matchesQuery } from "./format.js";
|
|
12
|
-
import { closeAllMenus, setSessOpen } from "./tabs.js";
|
|
13
|
-
import { setIndicator, closeConfirm, confirmOverlay, trapTab } from "./dialog.js";
|
|
14
|
-
import { controlFor, PANEL_SECTIONS, keyToPanel } from "./settings-controls.js";
|
|
15
|
-
import { setLayout } from "./rail.js";
|
|
16
|
-
|
|
17
|
-
function setSelButton(btn, label, value) {
|
|
18
|
-
btn.textContent = label + ":";
|
|
19
|
-
btn.appendChild(el("b", "", value));
|
|
20
|
-
btn.appendChild(icon("chevron-down"));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function menuItem(label, sub, active, onClick) {
|
|
24
|
-
const mi = el("button", "mi" + (active ? " on" : ""));
|
|
25
|
-
mi.type = "button";
|
|
26
|
-
mi.setAttribute("aria-pressed", active ? "true" : "false");
|
|
27
|
-
mi.appendChild(el("span", "", label));
|
|
28
|
-
if (sub) mi.appendChild(el("span", "sub", sub));
|
|
29
|
-
mi.addEventListener("click", (e) => {
|
|
30
|
-
e.stopPropagation();
|
|
31
|
-
onClick();
|
|
32
|
-
closeAllMenus();
|
|
33
|
-
});
|
|
34
|
-
return mi;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Menu action row (refresh, custom, add…) with an optional leading icon.
|
|
38
|
-
function menuAction(label, iconName, onClick) {
|
|
39
|
-
const mi = el("button", "mi row-mi");
|
|
40
|
-
mi.type = "button";
|
|
41
|
-
if (iconName) mi.appendChild(icon(iconName));
|
|
42
|
-
mi.appendChild(el("span", "", label));
|
|
43
|
-
mi.addEventListener("click", (e) => {
|
|
44
|
-
e.stopPropagation();
|
|
45
|
-
closeAllMenus();
|
|
46
|
-
onClick();
|
|
47
|
-
});
|
|
48
|
-
return mi;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Live filter text of the composer model dropdown. Kept module-level so a
|
|
52
|
-
// `renderSelectors()` re-read (config/models reload) preserves the query and
|
|
53
|
-
// the input is rebuilt with it; cleared once a model is actually picked.
|
|
54
|
-
let modelFilter = "";
|
|
55
|
-
|
|
56
|
-
export function renderSelectors() {
|
|
57
|
-
const cfg = S.state.config || {};
|
|
58
|
-
const provider = cfg.provider || {};
|
|
59
|
-
|
|
60
|
-
setSelButton(document.getElementById("selModelBtn"), t("web.selectors.model"), cfg.model || "—");
|
|
61
|
-
const modelMenu = document.getElementById("selModelMenu");
|
|
62
|
-
modelMenu.textContent = "";
|
|
63
|
-
// Search row stays outside the filtered list: `drawModelList` only touches
|
|
64
|
-
// `listBox`, so typing never rebuilds (or unfocuses) the input itself.
|
|
65
|
-
const search = document.createElement("input");
|
|
66
|
-
search.id = "selModelSearch";
|
|
67
|
-
search.className = "searchbox";
|
|
68
|
-
search.type = "search";
|
|
69
|
-
search.autocomplete = "off";
|
|
70
|
-
search.spellcheck = false;
|
|
71
|
-
search.placeholder = t("web.selectors.search_models");
|
|
72
|
-
search.setAttribute("aria-label", t("web.selectors.search_models"));
|
|
73
|
-
search.value = modelFilter;
|
|
74
|
-
search.addEventListener("click", (e) => e.stopPropagation());
|
|
75
|
-
modelMenu.appendChild(search);
|
|
76
|
-
const listBox = el("div", "model-menu-list");
|
|
77
|
-
modelMenu.appendChild(listBox);
|
|
78
|
-
const drawModelList = () => {
|
|
79
|
-
listBox.textContent = "";
|
|
80
|
-
const models = S.state.models.filter((m) => matchesQuery(m, modelFilter));
|
|
81
|
-
if (!models.length) {
|
|
82
|
-
listBox.appendChild(el("div", "mi dim", S.state.models.length ? t("web.settings.no_matches") : t("web.selectors.no_models")));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
models.forEach((m) => {
|
|
86
|
-
const item = menuItem(m, "", m === cfg.model, () => {
|
|
87
|
-
modelFilter = "";
|
|
88
|
-
postConfig("model", m, true);
|
|
89
|
-
});
|
|
90
|
-
// ArrowUp on the first row returns focus to the search field.
|
|
91
|
-
item.addEventListener("keydown", (e) => {
|
|
92
|
-
if (e.key === "ArrowUp" && item === listBox.querySelector(".mi:not(.dim)")) {
|
|
93
|
-
e.preventDefault();
|
|
94
|
-
e.stopPropagation();
|
|
95
|
-
search.focus();
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
listBox.appendChild(item);
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
search.addEventListener("input", () => {
|
|
102
|
-
modelFilter = search.value;
|
|
103
|
-
drawModelList();
|
|
104
|
-
});
|
|
105
|
-
search.addEventListener("keydown", (e) => {
|
|
106
|
-
e.stopPropagation();
|
|
107
|
-
if (e.key === "ArrowDown") {
|
|
108
|
-
e.preventDefault();
|
|
109
|
-
const first = listBox.querySelector(".mi:not(.dim)");
|
|
110
|
-
if (first) first.focus();
|
|
111
|
-
} else if (e.key === "Enter") {
|
|
112
|
-
e.preventDefault();
|
|
113
|
-
const first = listBox.querySelector(".mi:not(.dim)");
|
|
114
|
-
if (first) first.click();
|
|
115
|
-
} else if (e.key === "Escape") {
|
|
116
|
-
if (search.value) {
|
|
117
|
-
e.preventDefault();
|
|
118
|
-
search.value = "";
|
|
119
|
-
modelFilter = "";
|
|
120
|
-
drawModelList();
|
|
121
|
-
} else {
|
|
122
|
-
closeAllMenus();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
drawModelList();
|
|
127
|
-
modelMenu.appendChild(el("div", "sep"));
|
|
128
|
-
modelMenu.appendChild(
|
|
129
|
-
menuAction(t("web.selectors.refresh_list"), "refresh", () => {
|
|
130
|
-
loadModels().then(renderSelectors);
|
|
131
|
-
}),
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
setSelButton(document.getElementById("selProviderBtn"), t("web.selectors.provider"), provider.active || provider.type || "—");
|
|
135
|
-
const provMenu = document.getElementById("selProviderMenu");
|
|
136
|
-
provMenu.textContent = "";
|
|
137
|
-
const entries = Array.isArray(provider.entries) && provider.entries.length
|
|
138
|
-
? provider.entries
|
|
139
|
-
: [{ label: provider.active || provider.type, type: provider.type }];
|
|
140
|
-
entries.forEach((entry) => {
|
|
141
|
-
const name = entry.label || entry.type;
|
|
142
|
-
if (!name) return;
|
|
143
|
-
provMenu.appendChild(menuItem(name, entry.type || "", name === (provider.active || provider.type), () => postConfig("provider.active", name, true)));
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
setSelButton(document.getElementById("selContextBtn"), t("web.selectors.context"), contextLabel());
|
|
147
|
-
const ctxMenu = document.getElementById("selContextMenu");
|
|
148
|
-
ctxMenu.textContent = "";
|
|
149
|
-
const sizes = [8192, 16384, 32768, 65536, 131072];
|
|
150
|
-
sizes.forEach((n) => {
|
|
151
|
-
ctxMenu.appendChild(menuItem(Math.round(n / 1024) + "K", n === cfg.contextWindow ? t("web.selectors.current") : "", n === cfg.contextWindow, () => postConfig("contextWindow", n, false)));
|
|
152
|
-
});
|
|
153
|
-
ctxMenu.appendChild(el("div", "sep"));
|
|
154
|
-
// Inline custom size (no native `window.prompt`): the menu stays open while
|
|
155
|
-
// typing; Enter/save commits and closes it.
|
|
156
|
-
const custom = el("button", "mi row-mi");
|
|
157
|
-
custom.type = "button";
|
|
158
|
-
custom.appendChild(icon("settings"));
|
|
159
|
-
custom.appendChild(el("span", "", t("web.selectors.custom")));
|
|
160
|
-
custom.addEventListener("click", (e) => {
|
|
161
|
-
e.stopPropagation();
|
|
162
|
-
if (ctxMenu.querySelector(".ctx-custom")) return;
|
|
163
|
-
const wrap = el("div", "ctx-custom");
|
|
164
|
-
const input = el("input");
|
|
165
|
-
input.type = "number";
|
|
166
|
-
input.min = "1024";
|
|
167
|
-
input.step = "1024";
|
|
168
|
-
input.value = String(cfg.contextWindow || 32768);
|
|
169
|
-
input.placeholder = t("web.selectors.context_prompt");
|
|
170
|
-
input.setAttribute("aria-label", t("web.selectors.context_prompt"));
|
|
171
|
-
const commit = () => {
|
|
172
|
-
const n = Number(input.value.trim());
|
|
173
|
-
if (Number.isFinite(n) && n >= 1024) {
|
|
174
|
-
closeAllMenus();
|
|
175
|
-
postConfig("contextWindow", n, false);
|
|
176
|
-
} else {
|
|
177
|
-
input.focus();
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
input.addEventListener("click", (ev) => ev.stopPropagation());
|
|
181
|
-
input.addEventListener("keydown", (ev) => {
|
|
182
|
-
ev.stopPropagation();
|
|
183
|
-
if (ev.key === "Enter") {
|
|
184
|
-
ev.preventDefault();
|
|
185
|
-
commit();
|
|
186
|
-
} else if (ev.key === "Escape") {
|
|
187
|
-
wrap.remove();
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
const ok = link(t("web.settings.save"), "", commit);
|
|
191
|
-
wrap.appendChild(input);
|
|
192
|
-
wrap.appendChild(ok);
|
|
193
|
-
ctxMenu.appendChild(wrap);
|
|
194
|
-
setTimeout(() => input.focus(), 0);
|
|
195
|
-
});
|
|
196
|
-
ctxMenu.appendChild(custom);
|
|
197
|
-
|
|
198
|
-
renderReasoningSelector();
|
|
199
|
-
|
|
200
|
-
// Keep the pending paint in sync: boot (config === null) and an in-flight
|
|
201
|
-
// switch both show the mark; a mid-switch re-read must not clear it.
|
|
202
|
-
paintSelectorPending();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const REASONING_LEVELS_FULL = ["auto", "default", "none", "low", "medium", "high", "max"];
|
|
206
|
-
// Backends without granularity (prompt-tag, template-kwarg) collapse
|
|
207
|
-
// medium/max into low/high — show the collapsed set, no duplicates.
|
|
208
|
-
const REASONING_LEVELS_COARSE = ["auto", "default", "none", "low", "high"];
|
|
209
|
-
|
|
210
|
-
// 4th selector row: reasoning effort filtered to what the active
|
|
211
|
-
// provider+model actually supports (`GET /api/models` → `reasoning`).
|
|
212
|
-
// Unknown (boot) or `strategy: "none"` → hidden, never a wrong option list.
|
|
213
|
-
// Probe failed → the row stays with an honest `off` mark and a shortcut to
|
|
214
|
-
// Settings → Reasoning instead of dead levels.
|
|
215
|
-
function renderReasoningSelector() {
|
|
216
|
-
const wrap = document.querySelector('[data-sel="reasoning"]');
|
|
217
|
-
const btn = document.getElementById("selReasoningBtn");
|
|
218
|
-
const menu = document.getElementById("selReasoningMenu");
|
|
219
|
-
if (!wrap || !btn || !menu) return;
|
|
220
|
-
const info = S.state.reasoning;
|
|
221
|
-
if (!info || info.strategy === "none") {
|
|
222
|
-
wrap.hidden = true;
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
wrap.hidden = false;
|
|
226
|
-
if (info.supported === false) {
|
|
227
|
-
setSelButton(btn, t("web.selectors.reasoning"), t("web.selectors.reasoning_off"));
|
|
228
|
-
menu.textContent = "";
|
|
229
|
-
menu.appendChild(el("div", "mi dim", t("reasoning.probe_failed")));
|
|
230
|
-
menu.appendChild(el("div", "sep"));
|
|
231
|
-
menu.appendChild(
|
|
232
|
-
menuAction(t("web.settings.reasoning"), "settings", () => openSettingsAt("reasoning")),
|
|
233
|
-
);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
const mode = (S.state.config && getPath(S.state.config, "reasoning.mode")) || info.mode || "auto";
|
|
237
|
-
setSelButton(btn, t("web.selectors.reasoning"), String(mode));
|
|
238
|
-
menu.textContent = "";
|
|
239
|
-
const levels = info.strategy === "openai-effort" ? REASONING_LEVELS_FULL : REASONING_LEVELS_COARSE;
|
|
240
|
-
levels.forEach((lvl) => {
|
|
241
|
-
menu.appendChild(menuItem(lvl, lvl === mode ? t("web.selectors.current") : "", lvl === mode, () => postConfig("reasoning.mode", lvl, false)));
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
document.querySelectorAll("[data-sel]").forEach((sel) => {
|
|
246
|
-
const btn = sel.querySelector("button");
|
|
247
|
-
btn.setAttribute("aria-haspopup", "menu");
|
|
248
|
-
btn.setAttribute("aria-expanded", "false");
|
|
249
|
-
btn.addEventListener("click", (e) => {
|
|
250
|
-
e.stopPropagation();
|
|
251
|
-
setSessOpen(false);
|
|
252
|
-
document.querySelectorAll("[data-sel]").forEach((s) => {
|
|
253
|
-
if (s !== sel) {
|
|
254
|
-
s.classList.remove("open");
|
|
255
|
-
const b = s.querySelector("button");
|
|
256
|
-
if (b) b.setAttribute("aria-expanded", "false");
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
const open = sel.classList.toggle("open");
|
|
260
|
-
btn.setAttribute("aria-expanded", open ? "true" : "false");
|
|
261
|
-
// Opening the model menu lands focus in its search field.
|
|
262
|
-
if (open && sel.dataset && sel.dataset.sel === "model") {
|
|
263
|
-
const search = document.getElementById("selModelSearch");
|
|
264
|
-
if (search) setTimeout(() => search.focus(), 0);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// Selector keys (`provider/model/context/reasoning`) share the switch treatment:
|
|
270
|
-
// pending paint + single-flight + parallel re-reads. Settings-panel writes
|
|
271
|
-
// bypass it (plain POST + save toast).
|
|
272
|
-
const SELECTOR_KEYS = ["provider.active", "model", "contextWindow", "reasoning.mode"];
|
|
273
|
-
|
|
274
|
-
// Monotonic id for selector switches: a slow A→B→A pair must not let the
|
|
275
|
-
// stale reply repaint over the fresh one.
|
|
276
|
-
let switchSeq = 0;
|
|
277
|
-
// Key of the in-flight selector switch, if any. While set, every selector
|
|
278
|
-
// button carries the pending mark and all selector menus are inert (CSS gates
|
|
279
|
-
// on `.selectors[data-pending]`), so a double-click is answered with a toast
|
|
280
|
-
// instead of a second concurrent switch.
|
|
281
|
-
let pendingKey = null;
|
|
282
|
-
|
|
283
|
-
// Paint the pending mark (`⋯` via CSS `::after`, no label rewrites) and the
|
|
284
|
-
// `aria-busy` flag. Boot (`config === null`) paints the same mark, so the
|
|
285
|
-
// skeleton state is visible while `boot()` loads config/models/providers.
|
|
286
|
-
function paintSelectorPending() {
|
|
287
|
-
const show = pendingKey !== null || !S.state.config;
|
|
288
|
-
const wrap = document.querySelector(".selectors");
|
|
289
|
-
if (wrap) {
|
|
290
|
-
if (show) wrap.setAttribute("data-pending", pendingKey || "boot");
|
|
291
|
-
else wrap.removeAttribute("data-pending");
|
|
292
|
-
}
|
|
293
|
-
["selProviderBtn", "selModelBtn", "selContextBtn", "selReasoningBtn"].forEach((id) => {
|
|
294
|
-
const btn = document.getElementById(id);
|
|
295
|
-
if (!btn) return;
|
|
296
|
-
btn.classList.toggle("pending", show);
|
|
297
|
-
btn.setAttribute("aria-busy", show ? "true" : "false");
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
async function postConfig(key, value, refreshSettings) {
|
|
302
|
-
const isSelector = SELECTOR_KEYS.indexOf(key) !== -1;
|
|
303
|
-
if (isSelector && pendingKey !== null) {
|
|
304
|
-
setIndicator(t("web.selectors.switch_busy"), true);
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
// Non-selector writes must not touch the sequence: otherwise a settings
|
|
308
|
-
// write landing mid-switch would orphan `pendingKey` (stale-guard skips the
|
|
309
|
-
// only `finally` that clears it).
|
|
310
|
-
let seq = 0;
|
|
311
|
-
if (isSelector) {
|
|
312
|
-
seq = ++switchSeq;
|
|
313
|
-
pendingKey = key;
|
|
314
|
-
closeAllMenus();
|
|
315
|
-
paintSelectorPending();
|
|
316
|
-
}
|
|
317
|
-
try {
|
|
318
|
-
const r = await api("/api/config", { method: "POST", body: { key, value } });
|
|
319
|
-
if (!r.ok || !r.data || !r.data.ok) {
|
|
320
|
-
const err = (r.data && (r.data.error || r.data.reason)) || r.status || t("web.settings.save_failed");
|
|
321
|
-
setIndicator(String(err), true);
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
const persisted = r.data.persisted !== false;
|
|
325
|
-
setIndicator(persisted ? t("web.settings.saved") : (r.data.warning || "not persisted"), !persisted);
|
|
326
|
-
if (S.state.config && r.data.value !== undefined) setPath(S.state.config, key, r.data.value);
|
|
327
|
-
if (key === "ui.activityRail") setLayout(String(r.data.value));
|
|
328
|
-
if (key === "ui.fontSize") applyFontSize(String(r.data.value));
|
|
329
|
-
if (key === "locale") {
|
|
330
|
-
await loadI18n();
|
|
331
|
-
if (hooks.applyStaticI18n) hooks.applyStaticI18n();
|
|
332
|
-
renderSettings();
|
|
333
|
-
}
|
|
334
|
-
// A provider switch restores the per-provider model; a model change
|
|
335
|
-
// updates that provider's remembered model. Both are independent GETs,
|
|
336
|
-
// so re-read them in parallel. Context/reasoning switches only need the
|
|
337
|
-
// config back (no extra model round-trip).
|
|
338
|
-
if (key === "provider.active" || key === "model") {
|
|
339
|
-
await Promise.all([loadConfig(), loadModels()]);
|
|
340
|
-
} else if (isSelector) {
|
|
341
|
-
await loadConfig();
|
|
342
|
-
}
|
|
343
|
-
// Stale reply (a newer switch started while this one was in flight):
|
|
344
|
-
// leave the paint and the final render to the newer operation.
|
|
345
|
-
if (isSelector && seq !== switchSeq) return true;
|
|
346
|
-
renderSelectors();
|
|
347
|
-
if (refreshSettings) renderSettings();
|
|
348
|
-
return true;
|
|
349
|
-
} finally {
|
|
350
|
-
if (isSelector && seq === switchSeq) {
|
|
351
|
-
pendingKey = null;
|
|
352
|
-
paintSelectorPending();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
export async function loadConfig() {
|
|
358
|
-
const r = await api("/api/config");
|
|
359
|
-
if (!r.ok || !r.data) return;
|
|
360
|
-
S.state.config = r.data.config || {};
|
|
361
|
-
S.state.registry = Array.isArray(r.data.registry) ? r.data.registry : [];
|
|
362
|
-
S.state.webToken = typeof r.data.webToken === "string" ? r.data.webToken : null;
|
|
363
|
-
applyFontSize();
|
|
364
|
-
renderSelectors();
|
|
365
|
-
renderSettings();
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
export async function loadModels() {
|
|
369
|
-
const r = await api("/api/models");
|
|
370
|
-
if (!r.ok || !r.data) return;
|
|
371
|
-
S.state.models = Array.isArray(r.data.models) ? r.data.models : [];
|
|
372
|
-
// Reasoning support rides along with the model list (one round-trip):
|
|
373
|
-
// the 4th selector row renders from this, never from a separate GET.
|
|
374
|
-
if (r.data.reasoning && typeof r.data.reasoning === "object") S.state.reasoning = r.data.reasoning;
|
|
375
|
-
renderSelectors();
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export async function loadProviders() {
|
|
379
|
-
const r = await api("/api/providers");
|
|
380
|
-
S.state.providers = r.ok && r.data && Array.isArray(r.data.entries) ? r.data : undefined;
|
|
381
|
-
S.state.providerPresets = r.ok && r.data && Array.isArray(r.data.presets) ? r.data.presets : [];
|
|
382
|
-
renderModelPanel();
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Connection-S.state banner: shown while the SSE stream is down. The server
|
|
386
|
-
// never replays events, so a reconnect only resyncs S.state — the feed keeps
|
|
387
|
-
// whatever the live session already rendered (no duplication).
|
|
388
|
-
export function setConnStatus(disconnected) {
|
|
389
|
-
if (!connStatus) return;
|
|
390
|
-
connStatus.hidden = !disconnected;
|
|
391
|
-
connStatus.textContent = disconnected ? "⋯ " + t("web.conn.reconnecting") : "";
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// Stale-translations banner: dict files on disk are newer than the running
|
|
395
|
-
// server process, so the chrome may show raw keys. Rebuilt only on S.state
|
|
396
|
-
// change (not on every 2s poll) to keep the reload-button focus stable;
|
|
397
|
-
// `force` re-renders the label after a locale switch.
|
|
398
|
-
let lastStale = null;
|
|
399
|
-
export function setStaleBar(stale, force) {
|
|
400
|
-
if (!staleBar) return;
|
|
401
|
-
// undefined = перерисовать последнее состояние (смена локали).
|
|
402
|
-
const on = stale === undefined ? !!lastStale : !!stale;
|
|
403
|
-
if (!force && on === lastStale) return;
|
|
404
|
-
lastStale = on;
|
|
405
|
-
staleBar.hidden = !on;
|
|
406
|
-
staleBar.textContent = "";
|
|
407
|
-
if (!on) return;
|
|
408
|
-
staleBar.appendChild(el("span", "", "⚠ " + t("web.i18n.stale") + " "));
|
|
409
|
-
staleBar.appendChild(link(t("web.i18n.reload"), "", () => location.reload()));
|
|
410
|
-
return lastStale;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// Panel → named sections lives in `settings-controls.js` (PANEL_SECTIONS).
|
|
414
|
-
// Custom panels (model/ui/browser…) render a bespoke body first and then their
|
|
415
|
-
// sections; purely generic panels (general/context/…) render sections only.
|
|
416
|
-
|
|
417
|
-
// Localized label for a registry key: `config.key.<canonical>`, falling back
|
|
418
|
-
// to the raw key when no translation exists (so a new key is never blank).
|
|
419
|
-
function configLabel(def) {
|
|
420
|
-
const k = "config.key." + def.key;
|
|
421
|
-
const tr = t(k);
|
|
422
|
-
return tr === k ? def.key : tr;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// Localized enum value: `config.enum.<value>`, falling back to the raw value.
|
|
426
|
-
// The raw value is still what gets POSTed — only the label is translated.
|
|
427
|
-
function enumLabel(v) {
|
|
428
|
-
const k = "config.enum." + v;
|
|
429
|
-
const tr = t(k);
|
|
430
|
-
return tr === k ? v : tr;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
function defFor(key) {
|
|
434
|
-
return S.state.registry.find((d) => d.key === key) || null;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
function row(label, control, desc) {
|
|
438
|
-
const r = el("div", "row");
|
|
439
|
-
const left = el("div", "row-label");
|
|
440
|
-
left.appendChild(el("span", "row-name", label));
|
|
441
|
-
if (desc) left.appendChild(el("span", "row-desc", desc));
|
|
442
|
-
r.appendChild(left);
|
|
443
|
-
if (typeof control === "string") {
|
|
444
|
-
const v = el("span", "val", control);
|
|
445
|
-
v.title = control;
|
|
446
|
-
r.appendChild(v);
|
|
447
|
-
} else if (control) {
|
|
448
|
-
r.appendChild(control);
|
|
449
|
-
}
|
|
450
|
-
return r;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function descFor(key) {
|
|
454
|
-
const k = "config.desc." + key;
|
|
455
|
-
const d = t(k);
|
|
456
|
-
return d === k ? "" : d;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// Generic per-type control (`settings-controls.js`): bool toggle, enum
|
|
460
|
-
// select, int/share/list/json inputs. `post` funnels through `postConfig`.
|
|
461
|
-
function configControl(def, key) {
|
|
462
|
-
// Read-only keys carry their resolved value in the registry entry: the getter
|
|
463
|
-
// is authoritative and may differ from the raw config field (`version`).
|
|
464
|
-
const value =
|
|
465
|
-
def.readOnly && def.value !== undefined
|
|
466
|
-
? def.value
|
|
467
|
-
: S.state.config
|
|
468
|
-
? getPath(S.state.config, key)
|
|
469
|
-
: undefined;
|
|
470
|
-
return controlFor(def, value, {
|
|
471
|
-
label: configLabel(def),
|
|
472
|
-
enumLabel,
|
|
473
|
-
emptyLabel: t("config.enum.none"),
|
|
474
|
-
fieldLabel: (k) => {
|
|
475
|
-
const kk = "config.field." + k;
|
|
476
|
-
const tr = t(kk);
|
|
477
|
-
return tr === kk ? k : tr;
|
|
478
|
-
},
|
|
479
|
-
post: (v) => postConfig(key, v, false),
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// One titled section card: uppercase title + optional one-line explanation,
|
|
484
|
-
// then its setting rows. Titles come from PANEL_SECTIONS so a section name can
|
|
485
|
-
// never drift from the keys under it.
|
|
486
|
-
function sectionCard(section) {
|
|
487
|
-
const card = el("div", "settings-section");
|
|
488
|
-
const head = el("div", "sec-head");
|
|
489
|
-
head.appendChild(el("span", "sec-title", t(section.titleKey)));
|
|
490
|
-
card.appendChild(head);
|
|
491
|
-
if (section.descKey) {
|
|
492
|
-
const d = t(section.descKey);
|
|
493
|
-
if (d !== section.descKey) card.appendChild(el("div", "sec-desc", d));
|
|
494
|
-
}
|
|
495
|
-
const body = el("div", "sec-body");
|
|
496
|
-
section.keys.forEach((key) => {
|
|
497
|
-
const def = defFor(key);
|
|
498
|
-
if (!def) return;
|
|
499
|
-
body.appendChild(row(configLabel(def), configControl(def, key), descFor(def.key)));
|
|
500
|
-
});
|
|
501
|
-
card.appendChild(body);
|
|
502
|
-
return card;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
// Render the PANEL_SECTIONS table for a panel. Panels with custom bodies call
|
|
506
|
-
// this after their own content so bespoke widgets stay on top.
|
|
507
|
-
function renderSections(panel, sections) {
|
|
508
|
-
const container = document.querySelector('[data-panel="' + panel + '"]');
|
|
509
|
-
if (!container) return;
|
|
510
|
-
sections.forEach((section) => container.appendChild(sectionCard(section)));
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
function renderPanel(panel) {
|
|
514
|
-
const container = document.querySelector('[data-panel="' + panel + '"]');
|
|
515
|
-
if (!container) return;
|
|
516
|
-
container.textContent = "";
|
|
517
|
-
renderSections(panel, PANEL_SECTIONS[panel] || []);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
function providerEntries() {
|
|
521
|
-
if (S.state.providers && Array.isArray(S.state.providers.entries) && S.state.providers.entries.length) {
|
|
522
|
-
return S.state.providers.entries;
|
|
523
|
-
}
|
|
524
|
-
const provider = (S.state.config && S.state.config.provider) || {};
|
|
525
|
-
if (Array.isArray(provider.entries) && provider.entries.length) {
|
|
526
|
-
return provider.entries.map((e) => ({
|
|
527
|
-
type: e.type,
|
|
528
|
-
label: e.label || e.type,
|
|
529
|
-
baseUrl: e.baseUrl,
|
|
530
|
-
hasApiKey: !!e.apiKey,
|
|
531
|
-
contextWindow: e.contextWindow,
|
|
532
|
-
priority: e.priority,
|
|
533
|
-
}));
|
|
534
|
-
}
|
|
535
|
-
return [
|
|
536
|
-
{
|
|
537
|
-
type: provider.type,
|
|
538
|
-
label: provider.active || provider.type,
|
|
539
|
-
baseUrl: provider.baseUrl,
|
|
540
|
-
hasApiKey: !!provider.apiKey,
|
|
541
|
-
},
|
|
542
|
-
];
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function providerName(p) {
|
|
546
|
-
return p.label || p.type || "—";
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
function providerMeta(p) {
|
|
550
|
-
const parts = [p.type];
|
|
551
|
-
if (p.contextWindow) parts.push(Math.round(p.contextWindow / 1024) + "K");
|
|
552
|
-
if (typeof p.rpm === "number" || typeof p.parallel === "number") {
|
|
553
|
-
parts.push("rpm " + (p.rpm == null ? "—" : p.rpm) + " · x" + (p.parallel == null ? "—" : p.parallel));
|
|
554
|
-
}
|
|
555
|
-
return parts.join(" · ");
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function pfield(labelKey, input) {
|
|
559
|
-
const f = el("div", "pform-field");
|
|
560
|
-
f.appendChild(el("label", "", t(labelKey)));
|
|
561
|
-
input.setAttribute("aria-label", t(labelKey));
|
|
562
|
-
f.appendChild(input);
|
|
563
|
-
return f;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
function providerInput(value, type, placeholder) {
|
|
567
|
-
const input = el("input");
|
|
568
|
-
input.type = type || "text";
|
|
569
|
-
if (placeholder) input.placeholder = placeholder;
|
|
570
|
-
if (value != null) input.value = String(value);
|
|
571
|
-
return input;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function providerSelect(options, value) {
|
|
575
|
-
const sel = el("select");
|
|
576
|
-
const none = el("option", "", "—");
|
|
577
|
-
none.value = "";
|
|
578
|
-
sel.appendChild(none);
|
|
579
|
-
const seen = new Set([""]);
|
|
580
|
-
options.forEach((v) => {
|
|
581
|
-
seen.add(v);
|
|
582
|
-
const o = el("option", "", v);
|
|
583
|
-
o.value = v;
|
|
584
|
-
if (v === value) o.selected = true;
|
|
585
|
-
sel.appendChild(o);
|
|
586
|
-
});
|
|
587
|
-
// Keep a stored-but-unknown value selectable (e.g. a legacy provider type
|
|
588
|
-
// from hand-edited config) instead of silently resetting it to "—".
|
|
589
|
-
if (value != null && value !== "" && !seen.has(value)) {
|
|
590
|
-
const o = el("option", "", value);
|
|
591
|
-
o.value = value;
|
|
592
|
-
o.selected = true;
|
|
593
|
-
sel.appendChild(o);
|
|
594
|
-
}
|
|
595
|
-
if (value == null) sel.value = "";
|
|
596
|
-
return sel;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// Base-URL field: a dropdown of well-known URLs plus a "custom URL" option
|
|
600
|
-
// revealing a free-text input, so corporate proxies stay enterable.
|
|
601
|
-
// Exposes a `.value` get/set compatible with plain inputs, plus the raw
|
|
602
|
-
// `sel`/`custom` nodes for event wiring.
|
|
603
|
-
function providerBaseField(value) {
|
|
604
|
-
const node = el("div", "pform-base");
|
|
605
|
-
const sel = el("select");
|
|
606
|
-
PROVIDER_BASE_URLS.forEach(([label, url]) => {
|
|
607
|
-
const o = el("option", "", label + " — " + url);
|
|
608
|
-
o.value = url;
|
|
609
|
-
sel.appendChild(o);
|
|
610
|
-
});
|
|
611
|
-
const customOpt = el("option", "", t("web.settings.provider_baseurl_custom"));
|
|
612
|
-
customOpt.value = BASE_URL_CUSTOM;
|
|
613
|
-
sel.appendChild(customOpt);
|
|
614
|
-
const custom = providerInput("", "text", "https://…");
|
|
615
|
-
const known = new Set(PROVIDER_BASE_URLS.map(([, url]) => url));
|
|
616
|
-
const sync = () => {
|
|
617
|
-
custom.style.display = sel.value === BASE_URL_CUSTOM ? "" : "none";
|
|
618
|
-
};
|
|
619
|
-
const field = {
|
|
620
|
-
node,
|
|
621
|
-
sel,
|
|
622
|
-
custom,
|
|
623
|
-
get value() {
|
|
624
|
-
return sel.value === BASE_URL_CUSTOM ? custom.value : sel.value;
|
|
625
|
-
},
|
|
626
|
-
set value(v) {
|
|
627
|
-
if (v && known.has(v)) {
|
|
628
|
-
sel.value = v;
|
|
629
|
-
} else {
|
|
630
|
-
sel.value = BASE_URL_CUSTOM;
|
|
631
|
-
custom.value = v || "";
|
|
632
|
-
}
|
|
633
|
-
sync();
|
|
634
|
-
},
|
|
635
|
-
addEventListener(ev, fn) {
|
|
636
|
-
sel.addEventListener(ev, fn);
|
|
637
|
-
custom.addEventListener(ev, fn);
|
|
638
|
-
},
|
|
639
|
-
setAttribute(k, v) {
|
|
640
|
-
sel.setAttribute(k, v);
|
|
641
|
-
},
|
|
642
|
-
};
|
|
643
|
-
field.value = value || "";
|
|
644
|
-
sel.addEventListener("change", sync);
|
|
645
|
-
node.appendChild(sel);
|
|
646
|
-
node.appendChild(custom);
|
|
647
|
-
return field;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
function providerCheck(value) {
|
|
651
|
-
const input = el("input");
|
|
652
|
-
input.type = "checkbox";
|
|
653
|
-
input.checked = value === true;
|
|
654
|
-
return input;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const CACHE_FLAG_KEYS = [
|
|
658
|
-
"sessionHeader",
|
|
659
|
-
"requestCachePrompt",
|
|
660
|
-
"requestPromptCacheKey",
|
|
661
|
-
"requestSessionId",
|
|
662
|
-
"requestCacheControl",
|
|
663
|
-
"requestStreamUsage",
|
|
664
|
-
];
|
|
665
|
-
|
|
666
|
-
// A titled group inside a settings panel (models / providers).
|
|
667
|
-
function settingsSection(titleKey) {
|
|
668
|
-
const sec = el("div", "settings-section");
|
|
669
|
-
const head = el("div", "sec-head");
|
|
670
|
-
head.appendChild(el("span", "sec-title", t(titleKey)));
|
|
671
|
-
sec.appendChild(head);
|
|
672
|
-
const body = el("div", "sec-body");
|
|
673
|
-
sec.appendChild(body);
|
|
674
|
-
return { el: sec, head, body };
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
// Compact action control used inside list items (use / edit / delete).
|
|
678
|
-
function chip(label, cls, onClick) {
|
|
679
|
-
const b = el("button", "chip" + (cls ? " " + cls : ""), label);
|
|
680
|
-
b.type = "button";
|
|
681
|
-
b.addEventListener("click", onClick);
|
|
682
|
-
return b;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
// Known provider types (mirrors BUILTIN_PROVIDERS in src/modules/providers/presets.ts)
|
|
686
|
-
// and well-known local base URLs. Both render as real `<select>` dropdowns —
|
|
687
|
-
// `datalist` hints were replaced because they don't read as a list and behave
|
|
688
|
-
// inconsistently across browsers.
|
|
689
|
-
const PROVIDER_TYPES = [
|
|
690
|
-
"openai-compat",
|
|
691
|
-
"lmstudio",
|
|
692
|
-
"openrouter",
|
|
693
|
-
"openai",
|
|
694
|
-
"anthropic",
|
|
695
|
-
"opencode-zen",
|
|
696
|
-
"opencode-go",
|
|
697
|
-
];
|
|
698
|
-
|
|
699
|
-
const PROVIDER_BASE_URLS = [
|
|
700
|
-
["LM Studio", "http://localhost:1234/v1"],
|
|
701
|
-
["Ollama", "http://localhost:11434/v1"],
|
|
702
|
-
["OpenRouter", "https://openrouter.ai/api/v1"],
|
|
703
|
-
["OpenAI", "https://api.openai.com/v1"],
|
|
704
|
-
["Anthropic", "https://api.anthropic.com"],
|
|
705
|
-
];
|
|
706
|
-
|
|
707
|
-
const BASE_URL_CUSTOM = "__custom__";
|
|
708
|
-
|
|
709
|
-
// One-click preset row: selecting a builtin fills type/label/base URL, so
|
|
710
|
-
// hosted providers need no URL knowledge. `custom` leaves the fields free.
|
|
711
|
-
// Returns the row node (null when no presets) plus the raw select for wiring.
|
|
712
|
-
function providerPresetField(editing) {
|
|
713
|
-
const presets = S.state.providerPresets || [];
|
|
714
|
-
if (!presets.length) return { presets, sel: null, node: null };
|
|
715
|
-
const sel = el("select", "pform-preset");
|
|
716
|
-
const custom = el("option", "", t("web.settings.provider_custom"));
|
|
717
|
-
custom.value = "";
|
|
718
|
-
sel.appendChild(custom);
|
|
719
|
-
presets.forEach((p) => {
|
|
720
|
-
const o = el("option", "", p.label || p.type);
|
|
721
|
-
o.value = p.id;
|
|
722
|
-
sel.appendChild(o);
|
|
723
|
-
});
|
|
724
|
-
const match =
|
|
725
|
-
presets.find((p) => p.type === editing.type && p.baseUrl && p.baseUrl === editing.baseUrl) ||
|
|
726
|
-
presets.find((p) => p.type === editing.type && !p.baseUrl) ||
|
|
727
|
-
presets.find((p) => p.type === editing.type);
|
|
728
|
-
if (match) sel.value = match.id;
|
|
729
|
-
return { presets, sel, node: pfield("web.settings.provider_preset", sel) };
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
// Keep the preset select and the type field in sync both ways.
|
|
733
|
-
function wirePresetSync(presets, presetSel, mode, f) {
|
|
734
|
-
if (!presetSel) return;
|
|
735
|
-
presetSel.addEventListener("change", () => {
|
|
736
|
-
const p = presets.find((x) => x.id === presetSel.value);
|
|
737
|
-
if (!p) return;
|
|
738
|
-
f.type.value = p.type;
|
|
739
|
-
if (mode === "add" || !f.label.value.trim()) f.label.value = p.name;
|
|
740
|
-
f.base.value = p.baseUrl || "";
|
|
741
|
-
});
|
|
742
|
-
f.type.addEventListener("input", () => {
|
|
743
|
-
const sel = presets.find((x) => x.id === presetSel.value);
|
|
744
|
-
if (!sel || f.type.value.trim() !== sel.type) presetSel.value = "";
|
|
745
|
-
});
|
|
746
|
-
// The type control is a `<select>`: some browsers fire only `change`.
|
|
747
|
-
f.type.addEventListener("change", () => {
|
|
748
|
-
const sel = presets.find((x) => x.id === presetSel.value);
|
|
749
|
-
if (!sel || f.type.value.trim() !== sel.type) presetSel.value = "";
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// Optional tuning fields stay collapsed so the form reads as "type + URL".
|
|
754
|
-
function providerAdvancedFields(editing) {
|
|
755
|
-
const adv = el("details", "pform-adv");
|
|
756
|
-
adv.appendChild(el("summary", "", t("web.settings.provider_advanced")));
|
|
757
|
-
const advGrid = el("div", "pform-grid");
|
|
758
|
-
const cache = editing.cache || {};
|
|
759
|
-
const retry = editing.retry || {};
|
|
760
|
-
const f = {
|
|
761
|
-
ctx: providerInput(editing.contextWindow, "number", "32768"),
|
|
762
|
-
prio: providerInput(editing.priority, "number", "0"),
|
|
763
|
-
rpm: providerInput(editing.rpm, "number", "60"),
|
|
764
|
-
par: providerInput(editing.parallel, "number", "1"),
|
|
765
|
-
maxTokens: providerInput(editing.maxCompletionTokens, "number", "8192"),
|
|
766
|
-
cacheMech: providerSelect(["auto", "explicit", "local", "none"], cache.mechanism),
|
|
767
|
-
cacheReport: providerSelect(["openai", "deepseek", "anthropic", "ollama", "none"], cache.report),
|
|
768
|
-
retryMax: providerInput(retry.maxRetries, "number", "3"),
|
|
769
|
-
retryBase: providerInput(retry.baseDelay, "number", "1000"),
|
|
770
|
-
retryMaxD: providerInput(retry.maxDelay, "number", "30000"),
|
|
771
|
-
};
|
|
772
|
-
// Flags keep the raw config key in `title` so it stays searchable, but the
|
|
773
|
-
// visible label is localized like every other field of the form.
|
|
774
|
-
f.cacheFlags = CACHE_FLAG_KEYS.map((key) => {
|
|
775
|
-
const box = providerCheck(cache[key]);
|
|
776
|
-
const label = t("web.settings.provider_flag." + key);
|
|
777
|
-
box.setAttribute("aria-label", label);
|
|
778
|
-
const wrap = el("label", "pform-check");
|
|
779
|
-
wrap.title = key;
|
|
780
|
-
wrap.appendChild(box);
|
|
781
|
-
wrap.appendChild(el("span", "", label));
|
|
782
|
-
return { key, box, node: wrap };
|
|
783
|
-
});
|
|
784
|
-
advGrid.appendChild(pfield("web.settings.provider_context", f.ctx));
|
|
785
|
-
advGrid.appendChild(pfield("web.settings.provider_priority", f.prio));
|
|
786
|
-
advGrid.appendChild(pfield("web.settings.provider_rpm", f.rpm));
|
|
787
|
-
advGrid.appendChild(pfield("web.settings.provider_parallel", f.par));
|
|
788
|
-
advGrid.appendChild(pfield("web.settings.provider_max_tokens", f.maxTokens));
|
|
789
|
-
advGrid.appendChild(pfield("web.settings.provider_cache_mechanism", f.cacheMech));
|
|
790
|
-
advGrid.appendChild(pfield("web.settings.provider_cache_report", f.cacheReport));
|
|
791
|
-
adv.appendChild(advGrid);
|
|
792
|
-
|
|
793
|
-
// Retry numbers reuse the field grid (label above input) — a bare label+input
|
|
794
|
-
// pair collapses into an unreadable inline blob without the grid styles.
|
|
795
|
-
const retryGroup = el("div", "pform-checks");
|
|
796
|
-
retryGroup.appendChild(el("span", "pform-checks-title", t("web.settings.provider_retry")));
|
|
797
|
-
const retryGrid = el("div", "pform-grid");
|
|
798
|
-
retryGrid.appendChild(pfield("web.settings.provider_retry_max", f.retryMax));
|
|
799
|
-
retryGrid.appendChild(pfield("web.settings.provider_retry_base", f.retryBase));
|
|
800
|
-
retryGrid.appendChild(pfield("web.settings.provider_retry_maxdelay", f.retryMaxD));
|
|
801
|
-
retryGroup.appendChild(retryGrid);
|
|
802
|
-
adv.appendChild(retryGroup);
|
|
803
|
-
|
|
804
|
-
const flagGroup = el("div", "pform-checks");
|
|
805
|
-
flagGroup.appendChild(el("span", "pform-checks-title", t("web.settings.provider_cache_flags")));
|
|
806
|
-
const flagGrid = el("div", "pform-checks-grid");
|
|
807
|
-
f.cacheFlags.forEach(({ node }) => flagGrid.appendChild(node));
|
|
808
|
-
flagGroup.appendChild(flagGrid);
|
|
809
|
-
adv.appendChild(flagGroup);
|
|
810
|
-
return { node: adv, ...f };
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
// Validate the field bag, POST it, and refresh the panels on success.
|
|
814
|
-
async function submitProviderForm(f, mode, editing) {
|
|
815
|
-
const type = f.type.value.trim();
|
|
816
|
-
const baseUrl = f.base.value.trim();
|
|
817
|
-
if (!type || !baseUrl) {
|
|
818
|
-
setIndicator(t("web.settings.provider_required"), true);
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
const body = { type, baseUrl };
|
|
822
|
-
const label = f.label.value.trim();
|
|
823
|
-
if (label) body.label = label;
|
|
824
|
-
if (mode === "edit") {
|
|
825
|
-
const original = providerName(editing);
|
|
826
|
-
if (original && original !== "—") body.originalName = original;
|
|
827
|
-
}
|
|
828
|
-
const key = f.key.value.trim();
|
|
829
|
-
// Empty means "keep the stored key" (the field is never prefilled, only a
|
|
830
|
-
// hint). `"***"` guards password-manager autofill of a masked placeholder.
|
|
831
|
-
if (key && key !== "***") body.apiKey = key;
|
|
832
|
-
const nums = [
|
|
833
|
-
["contextWindow", f.ctx, 1024],
|
|
834
|
-
["priority", f.prio, 0],
|
|
835
|
-
["rpm", f.rpm, 1],
|
|
836
|
-
["parallel", f.par, 1],
|
|
837
|
-
["maxCompletionTokens", f.maxTokens, 512, 128000],
|
|
838
|
-
["maxRetries", f.retryMax, 0, 10],
|
|
839
|
-
["baseDelay", f.retryBase, 0, 60000],
|
|
840
|
-
["maxDelay", f.retryMaxD, 0, 300000],
|
|
841
|
-
];
|
|
842
|
-
const retry = {};
|
|
843
|
-
for (const entry of nums) {
|
|
844
|
-
const raw = entry[1].value.trim();
|
|
845
|
-
if (!raw) continue;
|
|
846
|
-
const n = Number(raw);
|
|
847
|
-
const max = entry[3] === undefined ? Number.MAX_SAFE_INTEGER : entry[3];
|
|
848
|
-
if (!Number.isInteger(n) || n < entry[2] || n > max) {
|
|
849
|
-
setIndicator(t("web.settings.provider_invalid"), true);
|
|
850
|
-
return;
|
|
851
|
-
}
|
|
852
|
-
if (entry[0] === "maxRetries" || entry[0] === "baseDelay" || entry[0] === "maxDelay") {
|
|
853
|
-
retry[entry[0]] = n;
|
|
854
|
-
} else {
|
|
855
|
-
body[entry[0]] = n;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
if (Object.keys(retry).length) body.retry = retry;
|
|
859
|
-
const cache = {};
|
|
860
|
-
if (f.cacheMech.value) cache.mechanism = f.cacheMech.value;
|
|
861
|
-
if (f.cacheReport.value) cache.report = f.cacheReport.value;
|
|
862
|
-
const prevCache = (editing && editing.cache) || {};
|
|
863
|
-
f.cacheFlags.forEach(({ key, box }) => {
|
|
864
|
-
if (box.checked !== (prevCache[key] === true)) cache[key] = box.checked;
|
|
865
|
-
});
|
|
866
|
-
if (Object.keys(cache).length) body.cache = cache;
|
|
867
|
-
const r = await api("/api/providers", { method: "POST", body });
|
|
868
|
-
if (r.ok && r.data && r.data.ok) {
|
|
869
|
-
const persisted = r.data.persisted !== false;
|
|
870
|
-
setIndicator(persisted ? t("web.settings.saved") : r.data.warning || "not persisted", !persisted);
|
|
871
|
-
closeSubDialog();
|
|
872
|
-
await loadProviders();
|
|
873
|
-
await loadConfig();
|
|
874
|
-
} else {
|
|
875
|
-
const err = (r.data && r.data.error) || "";
|
|
876
|
-
setIndicator(
|
|
877
|
-
err === "name-conflict" ? t("web.settings.provider_name_conflict") : err || t("web.settings.save_failed"),
|
|
878
|
-
true,
|
|
879
|
-
);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
function providerForm() {
|
|
884
|
-
const mode = (S.state.providerForm && S.state.providerForm.mode) || "add";
|
|
885
|
-
const editing = (S.state.providerForm && S.state.providerForm.entry) || {};
|
|
886
|
-
const box = el("div", "pform");
|
|
887
|
-
|
|
888
|
-
const { presets, sel: presetSel, node: presetNode } = providerPresetField(editing);
|
|
889
|
-
if (presetNode) box.appendChild(presetNode);
|
|
890
|
-
|
|
891
|
-
const grid = el("div", "pform-grid");
|
|
892
|
-
const fType = providerSelect(PROVIDER_TYPES, editing.type);
|
|
893
|
-
const fLabel = providerInput(editing.label, "text", "my-provider");
|
|
894
|
-
const fBase = providerBaseField(editing.baseUrl);
|
|
895
|
-
const fKey = providerInput("", "password", editing.hasApiKey ? t("web.settings.provider_key_keep") : "");
|
|
896
|
-
grid.appendChild(pfield("web.settings.provider_type", fType));
|
|
897
|
-
grid.appendChild(pfield("web.settings.provider_label_field", fLabel));
|
|
898
|
-
grid.appendChild(pfield("web.settings.provider_baseurl", fBase.node));
|
|
899
|
-
grid.appendChild(pfield("web.settings.provider_apikey", fKey));
|
|
900
|
-
box.appendChild(grid);
|
|
901
|
-
wirePresetSync(presets, presetSel, mode, { type: fType, label: fLabel, base: fBase });
|
|
902
|
-
|
|
903
|
-
const { node: advNode, ...advF } = providerAdvancedFields(editing);
|
|
904
|
-
box.appendChild(advNode);
|
|
905
|
-
const f = { type: fType, label: fLabel, base: fBase, key: fKey, ...advF };
|
|
906
|
-
|
|
907
|
-
const actions = el("div", "pform-actions");
|
|
908
|
-
actions.appendChild(link(t("web.settings.save"), "", () => submitProviderForm(f, mode, editing)));
|
|
909
|
-
actions.appendChild(link(t("web.settings.cancel"), "dim", () => closeProviderForm()));
|
|
910
|
-
box.appendChild(actions);
|
|
911
|
-
return box;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
function renderModelPanel() {
|
|
915
|
-
const container = document.querySelector('[data-panel="model"]');
|
|
916
|
-
if (!container) return;
|
|
917
|
-
container.textContent = "";
|
|
918
|
-
const cfg = S.state.config || {};
|
|
919
|
-
|
|
920
|
-
// --- Model section ---
|
|
921
|
-
const modelSec = settingsSection("web.settings.section_models");
|
|
922
|
-
const search = el("input", "searchbox");
|
|
923
|
-
search.placeholder = t("web.settings.search_models");
|
|
924
|
-
search.setAttribute("aria-label", t("web.settings.search_models"));
|
|
925
|
-
modelSec.body.appendChild(search);
|
|
926
|
-
const list = el("div", "model-list");
|
|
927
|
-
modelSec.body.appendChild(list);
|
|
928
|
-
const draw = () => {
|
|
929
|
-
list.textContent = "";
|
|
930
|
-
const q = search.value.trim().toLowerCase();
|
|
931
|
-
const models = S.state.models.filter((m) => !q || m.toLowerCase().indexOf(q) !== -1);
|
|
932
|
-
if (!models.length) {
|
|
933
|
-
list.appendChild(el("div", "placeholder", S.state.models.length ? t("web.settings.no_matches") : t("web.settings.no_models")));
|
|
934
|
-
return;
|
|
935
|
-
}
|
|
936
|
-
models.forEach((m) => {
|
|
937
|
-
const active = m === cfg.model;
|
|
938
|
-
const item = el("div", "model-item" + (active ? " active" : ""));
|
|
939
|
-
const nameEl = el("span", "m-name", m);
|
|
940
|
-
nameEl.title = m;
|
|
941
|
-
item.appendChild(nameEl);
|
|
942
|
-
if (active) {
|
|
943
|
-
item.appendChild(el("span", "m-meta", contextLabel() + " · " + t("web.settings.active_check")));
|
|
944
|
-
} else {
|
|
945
|
-
item.appendChild(chip(t("web.settings.use"), "", () => postConfig("model", m, true)));
|
|
946
|
-
}
|
|
947
|
-
list.appendChild(item);
|
|
948
|
-
});
|
|
949
|
-
};
|
|
950
|
-
search.addEventListener("input", draw);
|
|
951
|
-
draw();
|
|
952
|
-
container.appendChild(modelSec.el);
|
|
953
|
-
|
|
954
|
-
// --- Providers section ---
|
|
955
|
-
const provSec = settingsSection("web.settings.section_providers");
|
|
956
|
-
const addBtn = el("button", "sec-add");
|
|
957
|
-
addBtn.type = "button";
|
|
958
|
-
addBtn.setAttribute("aria-haspopup", "dialog");
|
|
959
|
-
addBtn.appendChild(icon("plus"));
|
|
960
|
-
addBtn.appendChild(el("span", "", t("web.settings.add_provider")));
|
|
961
|
-
addBtn.addEventListener("click", () => openProviderForm("add", null));
|
|
962
|
-
provSec.head.appendChild(addBtn);
|
|
963
|
-
|
|
964
|
-
const entries = providerEntries().filter((e) => {
|
|
965
|
-
const n = providerName(e);
|
|
966
|
-
return n && n !== "—";
|
|
967
|
-
});
|
|
968
|
-
const activeName = (S.state.providers && S.state.providers.active) || cfg.provider?.active || cfg.provider?.type || "—";
|
|
969
|
-
const provList = el("div", "provider-list");
|
|
970
|
-
entries.forEach((entry) => {
|
|
971
|
-
const name = providerName(entry);
|
|
972
|
-
const active = name === activeName;
|
|
973
|
-
const item = el("div", "provider-item" + (active ? " active" : ""));
|
|
974
|
-
const head = el("div", "p-head");
|
|
975
|
-
head.appendChild(el("span", "p-name", name));
|
|
976
|
-
if (active) head.appendChild(el("span", "badge on", t("web.settings.active")));
|
|
977
|
-
item.appendChild(head);
|
|
978
|
-
const meta = providerMeta(entry);
|
|
979
|
-
if (meta) item.appendChild(el("div", "p-meta", meta));
|
|
980
|
-
const actions = el("div", "p-actions");
|
|
981
|
-
if (!active) {
|
|
982
|
-
actions.appendChild(chip(t("web.settings.provider_make_active"), "", () => postConfig("provider.active", name, true)));
|
|
983
|
-
}
|
|
984
|
-
actions.appendChild(
|
|
985
|
-
chip(t("web.settings.edit"), "", () => openProviderForm("edit", entry)),
|
|
986
|
-
);
|
|
987
|
-
if (!active) {
|
|
988
|
-
actions.appendChild(
|
|
989
|
-
chip(t("web.settings.delete"), "danger", async () => {
|
|
990
|
-
const r = await api("/api/providers/" + encodeURIComponent(name), { method: "DELETE" });
|
|
991
|
-
if (r.ok && r.data && r.data.ok) {
|
|
992
|
-
setIndicator(t("web.settings.saved"));
|
|
993
|
-
await loadProviders();
|
|
994
|
-
await loadConfig();
|
|
995
|
-
} else {
|
|
996
|
-
const err = (r.data && r.data.error) || t("web.settings.delete_failed");
|
|
997
|
-
setIndicator(err === "active-provider" ? t("web.settings.provider_active_guard") : String(err), true);
|
|
998
|
-
}
|
|
999
|
-
}),
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
item.appendChild(actions);
|
|
1003
|
-
provList.appendChild(item);
|
|
1004
|
-
});
|
|
1005
|
-
if (!entries.length) provList.appendChild(el("div", "placeholder", t("web.settings.providers_empty")));
|
|
1006
|
-
provSec.body.appendChild(provList);
|
|
1007
|
-
container.appendChild(provSec.el);
|
|
1008
|
-
renderSections("model", PANEL_SECTIONS.model || []);
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
function renderUiPanel() {
|
|
1012
|
-
const container = document.querySelector('[data-panel="ui"]');
|
|
1013
|
-
if (!container) return;
|
|
1014
|
-
container.textContent = "";
|
|
1015
|
-
const seg = el("span", "seg");
|
|
1016
|
-
["dark", "light", "auto"].forEach((theme) => {
|
|
1017
|
-
const b = el("button", currentTheme() === theme ? "on" : "", theme);
|
|
1018
|
-
b.type = "button";
|
|
1019
|
-
b.setAttribute("aria-pressed", currentTheme() === theme ? "true" : "false");
|
|
1020
|
-
b.addEventListener("click", () => {
|
|
1021
|
-
seg.querySelectorAll("button").forEach((x) => {
|
|
1022
|
-
x.classList.remove("on");
|
|
1023
|
-
x.setAttribute("aria-pressed", "false");
|
|
1024
|
-
});
|
|
1025
|
-
b.classList.add("on");
|
|
1026
|
-
b.setAttribute("aria-pressed", "true");
|
|
1027
|
-
applyTheme(theme);
|
|
1028
|
-
});
|
|
1029
|
-
seg.appendChild(b);
|
|
1030
|
-
});
|
|
1031
|
-
// Theme is a browser-local preference (localStorage), not a config key, so it
|
|
1032
|
-
// gets its own card before the generated sections.
|
|
1033
|
-
const card = el("div", "settings-section");
|
|
1034
|
-
const head = el("div", "sec-head");
|
|
1035
|
-
head.appendChild(el("span", "sec-title", t("web.settings.sec.ui.theme")));
|
|
1036
|
-
card.appendChild(head);
|
|
1037
|
-
const desc = t("web.settings.sec.ui.theme.desc");
|
|
1038
|
-
if (desc !== "web.settings.sec.ui.theme.desc") card.appendChild(el("div", "sec-desc", desc));
|
|
1039
|
-
const body = el("div", "sec-body");
|
|
1040
|
-
body.appendChild(row(t("web.settings.theme"), seg));
|
|
1041
|
-
card.appendChild(body);
|
|
1042
|
-
container.appendChild(card);
|
|
1043
|
-
renderSections("ui", PANEL_SECTIONS.ui || []);
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
function renderSecurityPanel() {
|
|
1047
|
-
const container = document.querySelector('[data-panel="security"]');
|
|
1048
|
-
if (!container) return;
|
|
1049
|
-
container.textContent = "";
|
|
1050
|
-
renderSections("security", PANEL_SECTIONS.security || []);
|
|
1051
|
-
const access = el("div", "settings-section");
|
|
1052
|
-
const head = el("div", "sec-head");
|
|
1053
|
-
head.appendChild(el("span", "sec-title", t("web.settings.sec.security.access")));
|
|
1054
|
-
access.appendChild(head);
|
|
1055
|
-
const body = el("div", "sec-body");
|
|
1056
|
-
body.appendChild(
|
|
1057
|
-
row(t("web.settings.web_token"), el("span", "val dim", S.state.webToken || t("web.settings.web_token_none")), t("config.desc.webToken")),
|
|
1058
|
-
);
|
|
1059
|
-
const note = el("div", "placeholder");
|
|
1060
|
-
note.appendChild(el("span", "tag", t("web.settings.terminal_tag")));
|
|
1061
|
-
note.appendChild(document.createTextNode(" " + t("web.settings.security_note")));
|
|
1062
|
-
body.appendChild(note);
|
|
1063
|
-
access.appendChild(body);
|
|
1064
|
-
container.appendChild(access);
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
function placeholderFor(data, empty) {
|
|
1068
|
-
const d = el("div", "placeholder");
|
|
1069
|
-
if (data === undefined) d.textContent = t("web.settings.loading");
|
|
1070
|
-
else d.textContent = empty;
|
|
1071
|
-
return d;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
function groupHeader(label, count) {
|
|
1075
|
-
const head = el("div", "row");
|
|
1076
|
-
head.appendChild(el("span", "val accent", label));
|
|
1077
|
-
if (count != null) head.appendChild(el("span", "val dim", String(count)));
|
|
1078
|
-
return head;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
const MEMORY_CATEGORIES = ["conventions", "decisions", "errors", "facts"];
|
|
1082
|
-
|
|
1083
|
-
/** Nested dialog: pick a memory category and write the note. */
|
|
1084
|
-
function openMemoryForm() {
|
|
1085
|
-
const box = el("div", "pform");
|
|
1086
|
-
const grid = el("div", "pform-grid");
|
|
1087
|
-
const catSel = el("select");
|
|
1088
|
-
catSel.setAttribute("aria-label", t("web.settings.memory_category"));
|
|
1089
|
-
MEMORY_CATEGORIES.forEach((c) => catSel.appendChild(el("option", "", c)));
|
|
1090
|
-
catSel.value = "facts";
|
|
1091
|
-
grid.appendChild(mcpLiteralField(t("web.settings.memory_category"), catSel));
|
|
1092
|
-
box.appendChild(grid);
|
|
1093
|
-
const area = el("textarea");
|
|
1094
|
-
area.rows = 5;
|
|
1095
|
-
area.placeholder = t("web.settings.new_memory");
|
|
1096
|
-
area.value = "";
|
|
1097
|
-
box.appendChild(mcpLiteralField(t("web.settings.new_memory"), area));
|
|
1098
|
-
const actions = el("div", "pform-actions");
|
|
1099
|
-
actions.appendChild(
|
|
1100
|
-
link(t("web.settings.save"), "", async () => {
|
|
1101
|
-
const text = area.value.trim();
|
|
1102
|
-
if (!text) {
|
|
1103
|
-
area.focus();
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
const r = await api("/api/memory", { method: "POST", body: { category: catSel.value, text } });
|
|
1107
|
-
if (r.ok && r.data && r.data.ok) {
|
|
1108
|
-
closeSubDialog();
|
|
1109
|
-
await loadMemory();
|
|
1110
|
-
} else {
|
|
1111
|
-
setIndicator(t("web.settings.add_failed"), true);
|
|
1112
|
-
}
|
|
1113
|
-
}),
|
|
1114
|
-
);
|
|
1115
|
-
actions.appendChild(link(t("web.settings.cancel"), "dim", () => closeSubDialog()));
|
|
1116
|
-
box.appendChild(actions);
|
|
1117
|
-
openSubDialog(t("web.settings.memory_add_title"), box, () => renderMemoryPanel());
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
function renderMemoryPanel() {
|
|
1121
|
-
const container = document.querySelector('[data-panel="memory"]');
|
|
1122
|
-
if (!container) return;
|
|
1123
|
-
container.textContent = "";
|
|
1124
|
-
if (S.state.memory === undefined || S.state.memory === null) {
|
|
1125
|
-
container.appendChild(placeholderFor(S.state.memory, t("web.settings.memory_unavailable")));
|
|
1126
|
-
return;
|
|
1127
|
-
}
|
|
1128
|
-
const data = S.state.memory;
|
|
1129
|
-
|
|
1130
|
-
// Adding an entry opens the shared nested dialog: a category + a multi-line
|
|
1131
|
-
// note with room to write, instead of a cramped inline field.
|
|
1132
|
-
const addBtn = el("button", "sec-add");
|
|
1133
|
-
addBtn.type = "button";
|
|
1134
|
-
addBtn.appendChild(icon("plus"));
|
|
1135
|
-
addBtn.appendChild(el("span", "", t("web.settings.add")));
|
|
1136
|
-
addBtn.addEventListener("click", () => openMemoryForm());
|
|
1137
|
-
const addHead = el("div", "sec-head");
|
|
1138
|
-
addHead.appendChild(el("span", "sec-title", t("web.settings.sec.memory.add")));
|
|
1139
|
-
addHead.appendChild(addBtn);
|
|
1140
|
-
const addSec = el("div", "settings-section");
|
|
1141
|
-
addSec.appendChild(addHead);
|
|
1142
|
-
container.appendChild(addSec);
|
|
1143
|
-
|
|
1144
|
-
const search = el("input", "searchbox");
|
|
1145
|
-
search.placeholder = t("web.settings.search_memory");
|
|
1146
|
-
search.setAttribute("aria-label", t("web.settings.search_memory"));
|
|
1147
|
-
container.appendChild(search);
|
|
1148
|
-
const list = el("div", "settings-list");
|
|
1149
|
-
container.appendChild(list);
|
|
1150
|
-
|
|
1151
|
-
const categoryHeader = (label, count) => {
|
|
1152
|
-
const head = el("div", "mem-cat");
|
|
1153
|
-
head.appendChild(el("span", "", label));
|
|
1154
|
-
if (count != null) head.appendChild(el("span", "n", String(count)));
|
|
1155
|
-
return head;
|
|
1156
|
-
};
|
|
1157
|
-
|
|
1158
|
-
const entryBlock = (text, onForget) => {
|
|
1159
|
-
const block = el("div", "mem-entry");
|
|
1160
|
-
const body = el("span", "mem-text");
|
|
1161
|
-
body.appendChild(inlineTextNodes(text));
|
|
1162
|
-
body.title = String(text == null ? "" : text);
|
|
1163
|
-
block.appendChild(body);
|
|
1164
|
-
if (onForget) block.appendChild(link(t("web.settings.forget"), "mem-del", onForget));
|
|
1165
|
-
return block;
|
|
1166
|
-
};
|
|
1167
|
-
|
|
1168
|
-
const draw = () => {
|
|
1169
|
-
list.textContent = "";
|
|
1170
|
-
const q = search.value.trim().toLowerCase();
|
|
1171
|
-
let any = false;
|
|
1172
|
-
(data.categories || []).forEach((cat) => {
|
|
1173
|
-
const entries = (cat.entries || []).filter(
|
|
1174
|
-
(e) => !q || String(e.text).toLowerCase().indexOf(q) !== -1,
|
|
1175
|
-
);
|
|
1176
|
-
if (!entries.length) return;
|
|
1177
|
-
any = true;
|
|
1178
|
-
list.appendChild(categoryHeader(cat.name, entries.length));
|
|
1179
|
-
entries.forEach((e) => {
|
|
1180
|
-
list.appendChild(
|
|
1181
|
-
entryBlock(e.text, async () => {
|
|
1182
|
-
const r = await api(
|
|
1183
|
-
"/api/memory/" + encodeURIComponent(cat.name) + "/" + e.n,
|
|
1184
|
-
{ method: "DELETE" },
|
|
1185
|
-
);
|
|
1186
|
-
if (r.ok) await loadMemory();
|
|
1187
|
-
else setIndicator(t("web.settings.forget_failed"), true);
|
|
1188
|
-
}),
|
|
1189
|
-
);
|
|
1190
|
-
});
|
|
1191
|
-
});
|
|
1192
|
-
const prefs = Object.entries(data.preferences || {});
|
|
1193
|
-
if (prefs.length && !q) {
|
|
1194
|
-
any = true;
|
|
1195
|
-
list.appendChild(categoryHeader(t("web.settings.preferences"), prefs.length));
|
|
1196
|
-
prefs.forEach(([k, v]) => {
|
|
1197
|
-
list.appendChild(entryBlock(k + " = " + v));
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
if (!any) {
|
|
1201
|
-
const empty = el("div", "placeholder");
|
|
1202
|
-
empty.textContent = q ? t("web.settings.no_matches") : t("web.settings.no_memory");
|
|
1203
|
-
list.appendChild(empty);
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
search.addEventListener("input", draw);
|
|
1207
|
-
draw();
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
function renderSkillsPanel() {
|
|
1211
|
-
const container = document.querySelector('[data-panel="skills"]');
|
|
1212
|
-
if (!container) return;
|
|
1213
|
-
container.textContent = "";
|
|
1214
|
-
if (S.state.skills === undefined || S.state.skills === null) {
|
|
1215
|
-
container.appendChild(placeholderFor(S.state.skills, t("web.settings.skills_unavailable")));
|
|
1216
|
-
return;
|
|
1217
|
-
}
|
|
1218
|
-
if (!S.state.skills.length) {
|
|
1219
|
-
const empty = el("div", "placeholder");
|
|
1220
|
-
empty.textContent = t("web.settings.no_skills");
|
|
1221
|
-
container.appendChild(empty);
|
|
1222
|
-
return;
|
|
1223
|
-
}
|
|
1224
|
-
const list = el("div", "settings-list");
|
|
1225
|
-
S.state.skills.forEach((s) => {
|
|
1226
|
-
const item = el("div", "skill-item");
|
|
1227
|
-
const head = el("div", "skill-head");
|
|
1228
|
-
head.appendChild(el("span", s.enabled ? "g" : "dim", s.enabled ? "✓" : "○"));
|
|
1229
|
-
const nameEl = el("span", "name", s.name);
|
|
1230
|
-
nameEl.title = s.name;
|
|
1231
|
-
head.appendChild(nameEl);
|
|
1232
|
-
head.appendChild(el("span", "st", s.enabled ? t("web.settings.enabled") : t("web.settings.available")));
|
|
1233
|
-
item.appendChild(head);
|
|
1234
|
-
if (s.source) {
|
|
1235
|
-
const src = el("div", "skill-src", s.source);
|
|
1236
|
-
src.title = s.source;
|
|
1237
|
-
item.appendChild(src);
|
|
1238
|
-
}
|
|
1239
|
-
list.appendChild(item);
|
|
1240
|
-
});
|
|
1241
|
-
container.appendChild(list);
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
function renderPluginsPanel() {
|
|
1245
|
-
const container = document.querySelector('[data-panel="plugins"]');
|
|
1246
|
-
if (!container) return;
|
|
1247
|
-
container.textContent = "";
|
|
1248
|
-
if (S.state.pluginsData === undefined || S.state.pluginsData === null) {
|
|
1249
|
-
container.appendChild(placeholderFor(S.state.pluginsData, t("web.settings.plugins_unavailable")));
|
|
1250
|
-
return;
|
|
1251
|
-
}
|
|
1252
|
-
const data = S.state.pluginsData;
|
|
1253
|
-
const list = el("div", "settings-list");
|
|
1254
|
-
list.appendChild(groupHeader(t("web.settings.plugins_header"), (data.plugins || []).length));
|
|
1255
|
-
if (!(data.plugins || []).length) {
|
|
1256
|
-
const empty = el("div", "placeholder");
|
|
1257
|
-
empty.textContent = t("web.settings.no_plugins");
|
|
1258
|
-
list.appendChild(empty);
|
|
1259
|
-
}
|
|
1260
|
-
(data.plugins || []).forEach((p) => {
|
|
1261
|
-
const line = el("div", "list-line");
|
|
1262
|
-
line.appendChild(el("span", "g", "✓"));
|
|
1263
|
-
const nameEl = el("span", "name", p.name);
|
|
1264
|
-
nameEl.title = p.name;
|
|
1265
|
-
line.appendChild(nameEl);
|
|
1266
|
-
if (p.version) line.appendChild(el("span", "src", "v" + p.version));
|
|
1267
|
-
if (p.source) {
|
|
1268
|
-
const src = el("span", "src", p.source);
|
|
1269
|
-
src.title = p.source;
|
|
1270
|
-
line.appendChild(src);
|
|
1271
|
-
}
|
|
1272
|
-
if (p.builtin) line.appendChild(el("span", "src", t("web.settings.builtin")));
|
|
1273
|
-
line.appendChild(el("span", "st", p.enabled === false ? t("web.settings.disabled") : t("web.settings.enabled")));
|
|
1274
|
-
list.appendChild(line);
|
|
1275
|
-
});
|
|
1276
|
-
const pnote = el("div", "settings-note");
|
|
1277
|
-
pnote.textContent = t("web.settings.plugins_note");
|
|
1278
|
-
list.appendChild(pnote);
|
|
1279
|
-
|
|
1280
|
-
list.appendChild(groupHeader(t("web.settings.mcp_servers"), (data.mcp || []).length));
|
|
1281
|
-
const mcpAdd = el("button", "sec-add");
|
|
1282
|
-
mcpAdd.type = "button";
|
|
1283
|
-
mcpAdd.appendChild(icon("plus"));
|
|
1284
|
-
mcpAdd.appendChild(el("span", "", t("web.settings.mcp_add")));
|
|
1285
|
-
mcpAdd.addEventListener("click", () => openMcpForm("add", null));
|
|
1286
|
-
list.appendChild(mcpAdd);
|
|
1287
|
-
if (!(data.mcp || []).length) {
|
|
1288
|
-
const empty = el("div", "placeholder");
|
|
1289
|
-
empty.textContent = t("web.settings.no_mcp");
|
|
1290
|
-
list.appendChild(empty);
|
|
1291
|
-
}
|
|
1292
|
-
(data.mcp || []).forEach((m) => {
|
|
1293
|
-
const line = el("div", "list-line");
|
|
1294
|
-
const on = m.status !== "disabled";
|
|
1295
|
-
const toggle = makeToggle(on, (next) => {
|
|
1296
|
-
api("/api/mcp/" + encodeURIComponent(m.id || m.name), {
|
|
1297
|
-
method: "POST",
|
|
1298
|
-
body: { enabled: next },
|
|
1299
|
-
}).then(async (r) => {
|
|
1300
|
-
if (r.ok && r.data && r.data.ok) {
|
|
1301
|
-
setIndicator(t("web.settings.mcp_saved"), false);
|
|
1302
|
-
await loadPlugins();
|
|
1303
|
-
} else {
|
|
1304
|
-
setIndicator(t("web.settings.save_failed"), true);
|
|
1305
|
-
}
|
|
1306
|
-
});
|
|
1307
|
-
});
|
|
1308
|
-
toggle.title = on ? t("web.settings.mcp_disable") : t("web.settings.mcp_enable");
|
|
1309
|
-
toggle.setAttribute("aria-label", toggle.title);
|
|
1310
|
-
line.appendChild(toggle);
|
|
1311
|
-
const nameEl = el("span", "name", m.name);
|
|
1312
|
-
nameEl.title = m.name;
|
|
1313
|
-
line.appendChild(nameEl);
|
|
1314
|
-
line.appendChild(el("span", "st", m.status || "—"));
|
|
1315
|
-
line.appendChild(chip(t("web.settings.edit"), "", () => openMcpForm("edit", m)));
|
|
1316
|
-
line.appendChild(chip(t("web.settings.delete"), "danger", async () => {
|
|
1317
|
-
const r = await api("/api/mcp/" + encodeURIComponent(m.id || m.name), { method: "DELETE" });
|
|
1318
|
-
if (r.ok && r.data && r.data.ok) {
|
|
1319
|
-
setIndicator(t("web.settings.mcp_saved"), false);
|
|
1320
|
-
await loadPlugins();
|
|
1321
|
-
} else {
|
|
1322
|
-
setIndicator((r.data && r.data.error) || t("web.settings.delete_failed"), true);
|
|
1323
|
-
}
|
|
1324
|
-
}));
|
|
1325
|
-
list.appendChild(line);
|
|
1326
|
-
});
|
|
1327
|
-
if (S.state.mcpForm) list.appendChild(mcpForm());
|
|
1328
|
-
if ((data.mcp || []).length) {
|
|
1329
|
-
const mnote = el("div", "settings-note");
|
|
1330
|
-
mnote.textContent = t("web.settings.mcp_note");
|
|
1331
|
-
list.appendChild(mnote);
|
|
1332
|
-
}
|
|
1333
|
-
renderLspSection(list);
|
|
1334
|
-
container.appendChild(list);
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
// Inline MCP add/edit form. Secrets are never echoed by the API, so env/headers
|
|
1338
|
-
// start blank — leaving them blank on edit keeps the stored values (patch
|
|
1339
|
-
// semantics: absent keys are not touched).
|
|
1340
|
-
function mcpLiteralField(label, input) {
|
|
1341
|
-
const f = el("div", "pform-field");
|
|
1342
|
-
const lab = el("label", "", label);
|
|
1343
|
-
f.appendChild(lab);
|
|
1344
|
-
input.setAttribute("aria-label", label);
|
|
1345
|
-
f.appendChild(input);
|
|
1346
|
-
return f;
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
function mcpForm() {
|
|
1350
|
-
const mode = (S.state.mcpForm && S.state.mcpForm.mode) || "add";
|
|
1351
|
-
const editing = (S.state.mcpForm && S.state.mcpForm.entry) || {};
|
|
1352
|
-
const box = el("div", "pform");
|
|
1353
|
-
const grid = el("div", "pform-grid");
|
|
1354
|
-
const fName = providerInput(editing.name || "", "text", "my-server");
|
|
1355
|
-
const fTransport = providerSelect(["stdio", "sse", "http"], editing.transport || "stdio");
|
|
1356
|
-
const fCommand = providerInput(editing.command || "", "text", "npx");
|
|
1357
|
-
const fUrl = providerInput(editing.url || "", "text", "https://…");
|
|
1358
|
-
grid.appendChild(mcpLiteralField("name", fName));
|
|
1359
|
-
grid.appendChild(mcpLiteralField("transport", fTransport));
|
|
1360
|
-
grid.appendChild(mcpLiteralField("command", fCommand));
|
|
1361
|
-
grid.appendChild(mcpLiteralField("url", fUrl));
|
|
1362
|
-
box.appendChild(grid);
|
|
1363
|
-
const adv = el("details", "pform-adv");
|
|
1364
|
-
adv.appendChild(el("summary", "", t("web.settings.provider_advanced")));
|
|
1365
|
-
const fArgs = providerInput(editing.args ? JSON.stringify(editing.args) : "", "text", '["--stdio"]');
|
|
1366
|
-
const fTimeout = providerInput(editing.timeout != null ? String(editing.timeout) : "", "number", "30000");
|
|
1367
|
-
const fEnabled = providerCheck(editing.enabled !== false);
|
|
1368
|
-
adv.appendChild(mcpLiteralField("args (JSON)", fArgs));
|
|
1369
|
-
adv.appendChild(mcpLiteralField("timeout (ms)", fTimeout));
|
|
1370
|
-
const envKeys = Array.isArray(editing.envKeys) ? editing.envKeys : [];
|
|
1371
|
-
const headerKeys = Array.isArray(editing.headerKeys) ? editing.headerKeys : [];
|
|
1372
|
-
const fEnv = el("textarea");
|
|
1373
|
-
fEnv.placeholder = envKeys.length ? "stored: " + envKeys.join(", ") + " — blank keeps" : '{"TOKEN": "…"}';
|
|
1374
|
-
const fHeaders = el("textarea");
|
|
1375
|
-
fHeaders.placeholder = headerKeys.length ? "stored: " + headerKeys.join(", ") + " — blank keeps" : '{"Authorization": "…"}';
|
|
1376
|
-
adv.appendChild(mcpLiteralField("env (JSON)", fEnv));
|
|
1377
|
-
adv.appendChild(mcpLiteralField("headers (JSON)", fHeaders));
|
|
1378
|
-
adv.appendChild(mcpLiteralField("enabled", fEnabled));
|
|
1379
|
-
box.appendChild(adv);
|
|
1380
|
-
const f = { name: fName, transport: fTransport, command: fCommand, url: fUrl, args: fArgs, timeout: fTimeout, env: fEnv, headers: fHeaders, enabled: fEnabled };
|
|
1381
|
-
const actions = el("div", "pform-actions");
|
|
1382
|
-
actions.appendChild(link(t("web.settings.save"), "", () => submitMcpForm(f, mode, editing)));
|
|
1383
|
-
actions.appendChild(link(t("web.settings.cancel"), "dim", () => closeSubDialog()));
|
|
1384
|
-
box.appendChild(actions);
|
|
1385
|
-
return box;
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
/** Open the MCP add/edit nested dialog. */
|
|
1389
|
-
function openMcpForm(mode, entry) {
|
|
1390
|
-
S.state.mcpForm = { mode, entry: entry || null };
|
|
1391
|
-
openSubDialog(
|
|
1392
|
-
t(mode === "edit" ? "web.settings.mcp_edit_title" : "web.settings.mcp_add"),
|
|
1393
|
-
mcpForm(),
|
|
1394
|
-
() => {
|
|
1395
|
-
S.state.mcpForm = null;
|
|
1396
|
-
renderPluginsPanel();
|
|
1397
|
-
void loadPlugins();
|
|
1398
|
-
},
|
|
1399
|
-
);
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
function parseJsonMap(raw) {
|
|
1403
|
-
const text = raw.trim();
|
|
1404
|
-
if (!text) return { present: false, value: null };
|
|
1405
|
-
let parsed = null;
|
|
1406
|
-
try {
|
|
1407
|
-
parsed = JSON.parse(text);
|
|
1408
|
-
} catch {
|
|
1409
|
-
return { present: true, value: null };
|
|
1410
|
-
}
|
|
1411
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { present: true, value: null };
|
|
1412
|
-
if (!Object.values(parsed).every((v) => typeof v === "string")) return { present: true, value: null };
|
|
1413
|
-
return { present: true, value: parsed };
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
async function submitMcpForm(f, mode, editing) {
|
|
1417
|
-
const name = f.name.value.trim();
|
|
1418
|
-
const transport = f.transport.value || "stdio";
|
|
1419
|
-
const command = f.command.value.trim();
|
|
1420
|
-
const url = f.url.value.trim();
|
|
1421
|
-
if (!name || (transport === "stdio" ? !command : !url)) {
|
|
1422
|
-
setIndicator(t("web.settings.mcp_required"), true);
|
|
1423
|
-
return;
|
|
1424
|
-
}
|
|
1425
|
-
const body = { name, transport };
|
|
1426
|
-
if (command) body.command = command;
|
|
1427
|
-
if (url) body.url = url;
|
|
1428
|
-
const argsRaw = f.args.value.trim();
|
|
1429
|
-
if (argsRaw) {
|
|
1430
|
-
let args = null;
|
|
1431
|
-
try {
|
|
1432
|
-
args = JSON.parse(argsRaw);
|
|
1433
|
-
} catch {
|
|
1434
|
-
args = null;
|
|
1435
|
-
}
|
|
1436
|
-
if (!Array.isArray(args) || !args.every((x) => typeof x === "string")) {
|
|
1437
|
-
setIndicator(t("web.settings.mcp_invalid"), true);
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
body.args = args;
|
|
1441
|
-
}
|
|
1442
|
-
for (const key of ["env", "headers"]) {
|
|
1443
|
-
const parsed = parseJsonMap(f[key].value);
|
|
1444
|
-
if (parsed.present && !parsed.value) {
|
|
1445
|
-
setIndicator(t("web.settings.mcp_invalid"), true);
|
|
1446
|
-
return;
|
|
1447
|
-
}
|
|
1448
|
-
if (parsed.present) body[key] = parsed.value;
|
|
1449
|
-
}
|
|
1450
|
-
const timeoutRaw = f.timeout.value.trim();
|
|
1451
|
-
if (timeoutRaw) {
|
|
1452
|
-
const n = Number(timeoutRaw);
|
|
1453
|
-
if (!Number.isInteger(n) || n < 1000 || n > 300000) {
|
|
1454
|
-
setIndicator(t("web.settings.mcp_invalid"), true);
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
body.timeout = n;
|
|
1458
|
-
}
|
|
1459
|
-
body.enabled = f.enabled.checked;
|
|
1460
|
-
const target = mode === "edit" ? "/api/mcp/" + encodeURIComponent(editing.id || editing.name) : "/api/mcp";
|
|
1461
|
-
const r = await api(target, { method: mode === "edit" ? "PUT" : "POST", body });
|
|
1462
|
-
if (r.ok && r.data && r.data.ok) {
|
|
1463
|
-
setIndicator(t("web.settings.mcp_saved"), false);
|
|
1464
|
-
closeSubDialog();
|
|
1465
|
-
} else {
|
|
1466
|
-
setIndicator((r.data && r.data.error) || t("web.settings.save_failed"), true);
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
function renderLspSection(list) {
|
|
1471
|
-
const servers = S.state.lsp;
|
|
1472
|
-
list.appendChild(groupHeader(t("web.settings.lsp_servers"), Array.isArray(servers) ? servers.length : null));
|
|
1473
|
-
if (servers === undefined || servers === null) {
|
|
1474
|
-
list.appendChild(placeholderFor(servers, t("web.settings.lsp_unavailable")));
|
|
1475
|
-
return;
|
|
1476
|
-
}
|
|
1477
|
-
if (!servers.length) {
|
|
1478
|
-
const empty = el("div", "placeholder");
|
|
1479
|
-
empty.textContent = t("web.settings.no_lsp");
|
|
1480
|
-
list.appendChild(empty);
|
|
1481
|
-
}
|
|
1482
|
-
servers.forEach((entry) => {
|
|
1483
|
-
const line = el("div", "list-line");
|
|
1484
|
-
line.appendChild(el("span", entry.enabled ? "g" : "dim", entry.enabled ? "✓" : "○"));
|
|
1485
|
-
const nameEl = el("span", "name", entry.lang);
|
|
1486
|
-
nameEl.title = entry.lang;
|
|
1487
|
-
line.appendChild(nameEl);
|
|
1488
|
-
const meta = [entry.command, entry.timeout != null ? entry.timeout + " ms" : null].filter(Boolean).join(" · ");
|
|
1489
|
-
if (meta) line.appendChild(el("span", "src", meta));
|
|
1490
|
-
line.appendChild(el("span", "st", entry.enabled ? t("web.settings.enabled") : t("web.settings.disabled")));
|
|
1491
|
-
line.appendChild(chip(t("web.settings.edit"), "", () => openLspForm(entry)));
|
|
1492
|
-
list.appendChild(line);
|
|
1493
|
-
});
|
|
1494
|
-
if (servers.length) {
|
|
1495
|
-
const note = el("div", "settings-note");
|
|
1496
|
-
note.textContent = t("web.settings.lsp_note");
|
|
1497
|
-
list.appendChild(note);
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
/** Open the LSP server edit nested dialog. */
|
|
1502
|
-
function openLspForm(entry) {
|
|
1503
|
-
S.state.lspForm = { lang: entry.lang, entry };
|
|
1504
|
-
openSubDialog(entry.lang, lspForm(), () => {
|
|
1505
|
-
S.state.lspForm = null;
|
|
1506
|
-
renderPluginsPanel();
|
|
1507
|
-
void loadLsp();
|
|
1508
|
-
});
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
// LSP server edit form (enabled toggle, timeout, command, args JSON).
|
|
1512
|
-
function lspForm() {
|
|
1513
|
-
const editing = (S.state.lspForm && S.state.lspForm.entry) || {};
|
|
1514
|
-
const lang = (S.state.lspForm && S.state.lspForm.lang) || editing.lang || "";
|
|
1515
|
-
const box = el("div", "pform");
|
|
1516
|
-
const grid = el("div", "pform-grid");
|
|
1517
|
-
const fCommand = providerInput(editing.command || "", "text", "npx");
|
|
1518
|
-
const fTimeout = providerInput(editing.timeout != null ? String(editing.timeout) : "", "number", "30000");
|
|
1519
|
-
const fEnabled = providerCheck(editing.enabled !== false);
|
|
1520
|
-
grid.appendChild(mcpLiteralField("command", fCommand));
|
|
1521
|
-
grid.appendChild(mcpLiteralField("timeout (ms)", fTimeout));
|
|
1522
|
-
grid.appendChild(mcpLiteralField("enabled", fEnabled));
|
|
1523
|
-
box.appendChild(grid);
|
|
1524
|
-
const fArgs = el("textarea");
|
|
1525
|
-
fArgs.value = editing.args ? JSON.stringify(editing.args) : "";
|
|
1526
|
-
fArgs.placeholder = '["--stdio"]';
|
|
1527
|
-
box.appendChild(mcpLiteralField("args (JSON)", fArgs));
|
|
1528
|
-
const actions = el("div", "pform-actions");
|
|
1529
|
-
actions.appendChild(link(t("web.settings.save"), "", async () => {
|
|
1530
|
-
const body = {};
|
|
1531
|
-
const command = fCommand.value.trim();
|
|
1532
|
-
if (command) body.command = command;
|
|
1533
|
-
const timeoutRaw = fTimeout.value.trim();
|
|
1534
|
-
if (timeoutRaw) {
|
|
1535
|
-
const n = Number(timeoutRaw);
|
|
1536
|
-
if (!Number.isInteger(n) || n < 1000 || n > 300000) {
|
|
1537
|
-
setIndicator(t("web.settings.provider_invalid"), true);
|
|
1538
|
-
return;
|
|
1539
|
-
}
|
|
1540
|
-
body.timeout = n;
|
|
1541
|
-
}
|
|
1542
|
-
const argsRaw = fArgs.value.trim();
|
|
1543
|
-
if (argsRaw) {
|
|
1544
|
-
let args = null;
|
|
1545
|
-
try {
|
|
1546
|
-
args = JSON.parse(argsRaw);
|
|
1547
|
-
} catch {
|
|
1548
|
-
args = null;
|
|
1549
|
-
}
|
|
1550
|
-
if (!Array.isArray(args) || !args.every((x) => typeof x === "string")) {
|
|
1551
|
-
setIndicator(t("web.settings.provider_invalid"), true);
|
|
1552
|
-
return;
|
|
1553
|
-
}
|
|
1554
|
-
body.args = args;
|
|
1555
|
-
}
|
|
1556
|
-
body.enabled = fEnabled.checked;
|
|
1557
|
-
const r = await api("/api/lsp/" + encodeURIComponent(lang), { method: "PUT", body });
|
|
1558
|
-
if (r.ok && r.data && r.data.ok) {
|
|
1559
|
-
setIndicator(t("web.settings.mcp_saved"), false);
|
|
1560
|
-
closeSubDialog();
|
|
1561
|
-
} else {
|
|
1562
|
-
setIndicator((r.data && r.data.error) || t("web.settings.save_failed"), true);
|
|
1563
|
-
}
|
|
1564
|
-
}));
|
|
1565
|
-
actions.appendChild(link(t("web.settings.cancel"), "dim", () => closeSubDialog()));
|
|
1566
|
-
box.appendChild(actions);
|
|
1567
|
-
return box;
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
export async function loadLsp() {
|
|
1571
|
-
const r = await api("/api/lsp");
|
|
1572
|
-
S.state.lsp = r.ok && r.data && Array.isArray(r.data.servers) ? r.data.servers : null;
|
|
1573
|
-
renderPluginsPanel();
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
export async function loadMemory() {
|
|
1577
|
-
const r = await api("/api/memory");
|
|
1578
|
-
S.state.memory = r.ok && r.data ? r.data : null;
|
|
1579
|
-
renderMemoryPanel();
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
export async function loadSkills() {
|
|
1583
|
-
const r = await api("/api/skills");
|
|
1584
|
-
S.state.skills = r.ok && r.data && Array.isArray(r.data.skills) ? r.data.skills : null;
|
|
1585
|
-
renderSkillsPanel();
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
export async function loadPlugins() {
|
|
1589
|
-
const r = await api("/api/plugins");
|
|
1590
|
-
S.state.pluginsData =
|
|
1591
|
-
r.ok && r.data
|
|
1592
|
-
? { plugins: r.data.plugins || [], mcp: r.data.mcp || [] }
|
|
1593
|
-
: null;
|
|
1594
|
-
renderPluginsPanel();
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
export function renderSettings() {
|
|
1598
|
-
// Generic panels render straight from PANEL_SECTIONS; custom panels
|
|
1599
|
-
// (model/ui/memory/skills/plugins/security) append their sections themselves
|
|
1600
|
-
// or render bespoke widgets alongside.
|
|
1601
|
-
for (const panel of ["general", "context", "reasoning", "agent", "network", "browser", "sessions", "advanced"]) {
|
|
1602
|
-
renderPanel(panel);
|
|
1603
|
-
}
|
|
1604
|
-
renderModelPanel();
|
|
1605
|
-
renderUiPanel();
|
|
1606
|
-
renderMemoryPanel();
|
|
1607
|
-
renderSkillsPanel();
|
|
1608
|
-
renderPluginsPanel();
|
|
1609
|
-
renderSecurityPanel();
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
const overlay = document.getElementById("overlay");
|
|
1613
|
-
const settingsBtn = document.getElementById("openSettings");
|
|
1614
|
-
const closeSettingsBtn = document.getElementById("closeSettings");
|
|
1615
|
-
let settingsReturnFocus = null;
|
|
1616
|
-
|
|
1617
|
-
// Settings sections act as a real tablist: roles, roving tabindex, arrow keys.
|
|
1618
|
-
const settingsTabs = Array.from(document.querySelectorAll("#setMenu .mi"));
|
|
1619
|
-
function selectSettingsPanel(name) {
|
|
1620
|
-
settingsTabs.forEach((x) => {
|
|
1621
|
-
const on = x.dataset.p === name;
|
|
1622
|
-
x.classList.toggle("on", on);
|
|
1623
|
-
x.setAttribute("aria-selected", on ? "true" : "false");
|
|
1624
|
-
x.tabIndex = on ? 0 : -1;
|
|
1625
|
-
});
|
|
1626
|
-
document.querySelectorAll(".content-col .panel").forEach((x) => x.classList.remove("on"));
|
|
1627
|
-
const panel = document.getElementById("p-" + name);
|
|
1628
|
-
if (panel) panel.classList.add("on");
|
|
1629
|
-
}
|
|
1630
|
-
settingsTabs.forEach((mi) => {
|
|
1631
|
-
const name = mi.dataset.p;
|
|
1632
|
-
mi.setAttribute("role", "tab");
|
|
1633
|
-
mi.setAttribute("id", "tab-" + name);
|
|
1634
|
-
mi.setAttribute("aria-controls", "p-" + name);
|
|
1635
|
-
mi.setAttribute("aria-selected", mi.classList.contains("on") ? "true" : "false");
|
|
1636
|
-
mi.tabIndex = mi.classList.contains("on") ? 0 : -1;
|
|
1637
|
-
mi.addEventListener("click", () => selectSettingsPanel(name));
|
|
1638
|
-
mi.addEventListener("keydown", (e) => {
|
|
1639
|
-
const i = settingsTabs.indexOf(mi);
|
|
1640
|
-
let next = null;
|
|
1641
|
-
if (e.key === "ArrowDown" || e.key === "ArrowRight") next = settingsTabs[(i + 1) % settingsTabs.length];
|
|
1642
|
-
else if (e.key === "ArrowUp" || e.key === "ArrowLeft") next = settingsTabs[(i - 1 + settingsTabs.length) % settingsTabs.length];
|
|
1643
|
-
else if (e.key === "Home") next = settingsTabs[0];
|
|
1644
|
-
else if (e.key === "End") next = settingsTabs[settingsTabs.length - 1];
|
|
1645
|
-
if (next) {
|
|
1646
|
-
e.preventDefault();
|
|
1647
|
-
selectSettingsPanel(next.dataset.p);
|
|
1648
|
-
next.focus();
|
|
1649
|
-
}
|
|
1650
|
-
});
|
|
1651
|
-
});
|
|
1652
|
-
document.querySelectorAll(".content-col .panel").forEach((panel) => {
|
|
1653
|
-
panel.setAttribute("role", "tabpanel");
|
|
1654
|
-
panel.setAttribute("aria-labelledby", "tab-" + panel.id.replace(/^p-/, ""));
|
|
1655
|
-
});
|
|
1656
|
-
|
|
1657
|
-
// ---- settings search -------------------------------------------------------
|
|
1658
|
-
// With 100+ keys, scanning a sidebar is slower than typing. The index is the
|
|
1659
|
-
// same PANEL_SECTIONS table that renders the panels (plus each key's i18n
|
|
1660
|
-
// label/description), so search can never disagree with the layout.
|
|
1661
|
-
const setMenuEl = document.getElementById("setMenu");
|
|
1662
|
-
const setSearch = document.getElementById("setSearch");
|
|
1663
|
-
const setSearchClear = document.getElementById("setSearchClear");
|
|
1664
|
-
const setSearchIcon = document.getElementById("setSearchIcon");
|
|
1665
|
-
const setResults = document.getElementById("setResults");
|
|
1666
|
-
if (setSearchIcon) setSearchIcon.appendChild(icon("search", "set-search-svg"));
|
|
1667
|
-
|
|
1668
|
-
function searchIndex() {
|
|
1669
|
-
const owner = keyToPanel();
|
|
1670
|
-
return (S.state.registry || [])
|
|
1671
|
-
.filter((def) => def && typeof def.key === "string")
|
|
1672
|
-
.map((def) => {
|
|
1673
|
-
const label = configLabel(def);
|
|
1674
|
-
return {
|
|
1675
|
-
def,
|
|
1676
|
-
panel: owner.get(def.key) || null,
|
|
1677
|
-
label,
|
|
1678
|
-
desc: descFor(def.key),
|
|
1679
|
-
haystack: `${label} ${def.key} ${descFor(def.key)}`.toLowerCase(),
|
|
1680
|
-
};
|
|
1681
|
-
})
|
|
1682
|
-
.filter((e) => e.panel);
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
let searchRows = [];
|
|
1686
|
-
let searchCursor = -1;
|
|
1687
|
-
|
|
1688
|
-
function closeSearch() {
|
|
1689
|
-
if (setSearch) setSearch.value = "";
|
|
1690
|
-
if (setResults) {
|
|
1691
|
-
setResults.hidden = true;
|
|
1692
|
-
setResults.textContent = "";
|
|
1693
|
-
}
|
|
1694
|
-
if (setMenuEl) setMenuEl.hidden = false;
|
|
1695
|
-
if (setSearchClear) setSearchClear.hidden = true;
|
|
1696
|
-
searchRows = [];
|
|
1697
|
-
searchCursor = -1;
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
function flashRow(panel, key) {
|
|
1701
|
-
const panelEl = document.getElementById("p-" + panel);
|
|
1702
|
-
if (!panelEl) return;
|
|
1703
|
-
const rows = Array.from(panelEl.querySelectorAll(".row"));
|
|
1704
|
-
const def = defFor(key);
|
|
1705
|
-
if (!def) return;
|
|
1706
|
-
const label = configLabel(def);
|
|
1707
|
-
const target = rows.find((r) => {
|
|
1708
|
-
const nameEl = r.querySelector(".row-name");
|
|
1709
|
-
return nameEl && nameEl.textContent === label;
|
|
1710
|
-
});
|
|
1711
|
-
if (!target) return;
|
|
1712
|
-
target.scrollIntoView({ block: "center" });
|
|
1713
|
-
target.classList.add("row-flash");
|
|
1714
|
-
setTimeout(() => target.classList.remove("row-flash"), 1200);
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
function pickResult(entry) {
|
|
1718
|
-
if (!entry || !entry.panel) return;
|
|
1719
|
-
closeSearch();
|
|
1720
|
-
selectSettingsPanel(entry.panel);
|
|
1721
|
-
flashRow(entry.panel, entry.def.key);
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
function renderResults(query) {
|
|
1725
|
-
if (!setResults) return;
|
|
1726
|
-
const q = query.trim().toLowerCase();
|
|
1727
|
-
if (!q) {
|
|
1728
|
-
closeSearch();
|
|
1729
|
-
return;
|
|
1730
|
-
}
|
|
1731
|
-
const matches = searchIndex().filter((e) => e.haystack.includes(q));
|
|
1732
|
-
setResults.textContent = "";
|
|
1733
|
-
if (!matches.length) {
|
|
1734
|
-
const empty = el("div", "set-results-empty", t("web.settings.search_empty"));
|
|
1735
|
-
setResults.appendChild(empty);
|
|
1736
|
-
}
|
|
1737
|
-
searchRows = matches.slice(0, 40);
|
|
1738
|
-
searchCursor = searchRows.length ? 0 : -1;
|
|
1739
|
-
searchRows.forEach((entry, i) => {
|
|
1740
|
-
const item = el("div", "set-result" + (i === searchCursor ? " on" : ""));
|
|
1741
|
-
item.setAttribute("role", "option");
|
|
1742
|
-
item.tabIndex = -1;
|
|
1743
|
-
item.appendChild(el("span", "sr-label", entry.label));
|
|
1744
|
-
const panelName = t("web.settings." + entry.panel);
|
|
1745
|
-
item.appendChild(el("span", "sr-panel", panelName === "web.settings." + entry.panel ? entry.panel : panelName));
|
|
1746
|
-
const keyEl = el("span", "sr-key", entry.def.key);
|
|
1747
|
-
keyEl.title = entry.def.key;
|
|
1748
|
-
item.appendChild(keyEl);
|
|
1749
|
-
item.addEventListener("click", () => pickResult(entry));
|
|
1750
|
-
setResults.appendChild(item);
|
|
1751
|
-
});
|
|
1752
|
-
setResults.hidden = false;
|
|
1753
|
-
setMenuEl.hidden = true;
|
|
1754
|
-
setSearchClear.hidden = false;
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
function moveSearchCursor(delta) {
|
|
1758
|
-
if (!searchRows.length) return;
|
|
1759
|
-
searchCursor = (searchCursor + delta + searchRows.length) % searchRows.length;
|
|
1760
|
-
Array.from(setResults.children).forEach((node, i) => node.classList.toggle("on", i === searchCursor));
|
|
1761
|
-
const active = setResults.children[searchCursor];
|
|
1762
|
-
if (active) active.scrollIntoView({ block: "nearest" });
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
if (setSearch) {
|
|
1766
|
-
setSearch.addEventListener("input", () => renderResults(setSearch.value));
|
|
1767
|
-
setSearch.addEventListener("keydown", (e) => {
|
|
1768
|
-
if (e.key === "ArrowDown") {
|
|
1769
|
-
e.preventDefault();
|
|
1770
|
-
moveSearchCursor(1);
|
|
1771
|
-
} else if (e.key === "ArrowUp") {
|
|
1772
|
-
e.preventDefault();
|
|
1773
|
-
moveSearchCursor(-1);
|
|
1774
|
-
} else if (e.key === "Enter") {
|
|
1775
|
-
e.preventDefault();
|
|
1776
|
-
pickResult(searchRows[searchCursor]);
|
|
1777
|
-
} else if (e.key === "Escape" && setSearch.value) {
|
|
1778
|
-
// First Esc clears the query; a second one is handled globally (close).
|
|
1779
|
-
e.stopPropagation();
|
|
1780
|
-
closeSearch();
|
|
1781
|
-
}
|
|
1782
|
-
});
|
|
1783
|
-
}
|
|
1784
|
-
if (setSearchClear) setSearchClear.addEventListener("click", closeSearch);
|
|
1785
|
-
|
|
1786
|
-
function openSettings() {
|
|
1787
|
-
settingsReturnFocus = document.activeElement;
|
|
1788
|
-
overlay.classList.add("open");
|
|
1789
|
-
settingsBtn.setAttribute("aria-expanded", "true");
|
|
1790
|
-
void loadMemory();
|
|
1791
|
-
void loadSkills();
|
|
1792
|
-
void loadPlugins();
|
|
1793
|
-
void loadLsp();
|
|
1794
|
-
const active = document.querySelector("#setMenu .mi.on") || settingsTabs[0];
|
|
1795
|
-
if (active) setTimeout(() => active.focus(), 0);
|
|
1796
|
-
}
|
|
1797
|
-
// Open settings straight at a panel (used by the reasoning selector when the
|
|
1798
|
-
// backend probe failed: the row links to Settings → Reasoning).
|
|
1799
|
-
function openSettingsAt(panel) {
|
|
1800
|
-
openSettings();
|
|
1801
|
-
selectSettingsPanel(panel);
|
|
1802
|
-
}
|
|
1803
|
-
function closeSettings() {
|
|
1804
|
-
closeSubDialog();
|
|
1805
|
-
S.state.providerForm = null;
|
|
1806
|
-
S.state.mcpForm = null;
|
|
1807
|
-
S.state.lspForm = null;
|
|
1808
|
-
overlay.classList.remove("open");
|
|
1809
|
-
settingsBtn.setAttribute("aria-expanded", "false");
|
|
1810
|
-
if (settingsReturnFocus && settingsReturnFocus.focus) settingsReturnFocus.focus();
|
|
1811
|
-
settingsReturnFocus = null;
|
|
1812
|
-
}
|
|
1813
|
-
settingsBtn.addEventListener("click", openSettings);
|
|
1814
|
-
closeSettingsBtn.addEventListener("click", closeSettings);
|
|
1815
|
-
overlay.addEventListener("click", (e) => {
|
|
1816
|
-
if (e.target === overlay) closeSettings();
|
|
1817
|
-
});
|
|
1818
|
-
// Trap Tab inside the dialog while it is open.
|
|
1819
|
-
overlay.addEventListener("keydown", (e) => trapTab(overlay, e));
|
|
1820
|
-
// One nested dialog for every "edit a single thing" flow (provider, MCP
|
|
1821
|
-
// server, LSP server). Keeps the settings modal visible behind it, traps Tab
|
|
1822
|
-
// and returns focus to the control that opened it.
|
|
1823
|
-
const subOverlay = document.getElementById("subOverlay");
|
|
1824
|
-
const subHost = document.getElementById("subHost");
|
|
1825
|
-
const subTitle = document.getElementById("subTitle");
|
|
1826
|
-
const closeSubBtn = document.getElementById("closeSub");
|
|
1827
|
-
let subReturnFocus = null;
|
|
1828
|
-
let subOnClose = null;
|
|
1829
|
-
|
|
1830
|
-
export function isSubDialogOpen() {
|
|
1831
|
-
return !!subOverlay && subOverlay.classList.contains("open");
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
/** Open the nested dialog with a built content node. `onClose` runs after. */
|
|
1835
|
-
export function openSubDialog(title, node, onClose) {
|
|
1836
|
-
if (!subOverlay || !subHost) return;
|
|
1837
|
-
subReturnFocus = document.activeElement;
|
|
1838
|
-
subOnClose = onClose || null;
|
|
1839
|
-
subTitle.textContent = title;
|
|
1840
|
-
subHost.textContent = "";
|
|
1841
|
-
subHost.appendChild(node);
|
|
1842
|
-
subOverlay.classList.add("open");
|
|
1843
|
-
setTimeout(() => {
|
|
1844
|
-
const first = subHost.querySelector("input, select, textarea");
|
|
1845
|
-
if (first) first.focus();
|
|
1846
|
-
}, 0);
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
export function closeSubDialog() {
|
|
1850
|
-
if (!isSubDialogOpen()) return;
|
|
1851
|
-
subOverlay.classList.remove("open");
|
|
1852
|
-
const after = subOnClose;
|
|
1853
|
-
subOnClose = null;
|
|
1854
|
-
if (subReturnFocus && subReturnFocus.focus) subReturnFocus.focus();
|
|
1855
|
-
subReturnFocus = null;
|
|
1856
|
-
if (after) after();
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
if (subOverlay) {
|
|
1860
|
-
if (closeSubBtn) closeSubBtn.addEventListener("click", closeSubDialog);
|
|
1861
|
-
subOverlay.addEventListener("click", (e) => {
|
|
1862
|
-
e.stopPropagation();
|
|
1863
|
-
if (e.target === subOverlay) closeSubDialog();
|
|
1864
|
-
});
|
|
1865
|
-
subOverlay.addEventListener("keydown", (e) => trapTab(subOverlay, e));
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
function openProviderForm(mode, entry) {
|
|
1869
|
-
S.state.providerForm = { mode, entry: entry || null };
|
|
1870
|
-
openSubDialog(
|
|
1871
|
-
t(mode === "edit" ? "web.settings.provider_edit_title" : "web.settings.provider_add_title"),
|
|
1872
|
-
providerForm(),
|
|
1873
|
-
() => renderModelPanel(),
|
|
1874
|
-
);
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
function closeProviderForm() {
|
|
1878
|
-
S.state.providerForm = null;
|
|
1879
|
-
closeSubDialog();
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
document.addEventListener("keydown", (e) => {
|
|
1883
|
-
if (e.key !== "Escape") return;
|
|
1884
|
-
if (isSubDialogOpen()) closeSubDialog();
|
|
1885
|
-
else if (confirmOverlay && confirmOverlay.classList.contains("open")) closeConfirm();
|
|
1886
|
-
else if (overlay.classList.contains("open")) closeSettings();
|
|
1887
|
-
});
|
|
1888
|
-
|
|
1889
|
-
export function currentTheme() {
|
|
1890
|
-
return localStorage.getItem(THEME_KEY) || "auto";
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
// Web chat font size (`ui.fontSize`, server config — unlike the theme, which
|
|
1894
|
-
// is a browser-local preference). Applied as `body[data-font]` so the switch
|
|
1895
|
-
// is instant and survives re-renders; unknown values fall back to the default.
|
|
1896
|
-
export function applyFontSize(value) {
|
|
1897
|
-
const v = value || (S.state.config && S.state.config.ui && S.state.config.ui.fontSize) || "comfortable";
|
|
1898
|
-
const known = v === "compact" || v === "large" ? v : "comfortable";
|
|
1899
|
-
if (known === "comfortable") document.body.removeAttribute("data-font");
|
|
1900
|
-
else document.body.setAttribute("data-font", known);
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
export function applyTheme(theme) {
|
|
1904
|
-
localStorage.setItem(THEME_KEY, theme);
|
|
1905
|
-
const light = theme === "light" || (theme === "auto" && window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches);
|
|
1906
|
-
document.body.classList.toggle("light", !!light);
|
|
1907
|
-
renderUiPanel();
|
|
1908
|
-
}
|
|
1909
|
-
|
|
1910
|
-
if (window.matchMedia) {
|
|
1911
|
-
window.matchMedia("(prefers-color-scheme: light)").addEventListener("change", () => {
|
|
1912
|
-
if (currentTheme() === "auto") applyTheme("auto");
|
|
1913
|
-
});
|
|
1914
|
-
}
|
|
1
|
+
export*from"./settings/write.js";export*from"./settings/panels.js";export*from"./settings/providers.js";export*from"./settings/modal.js";export*from"./settings/subdialog.js";export*from"./settings/search.js";
|