minimal-agent 0.10.0 → 0.12.0
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/README.md +11 -3
- package/package.json +52 -5
- package/plugins/computer_use/.claude-plugin/plugin.json +6 -0
- package/plugins/computer_use/README.md +94 -0
- package/plugins/computer_use/app/_template.md +142 -0
- package/plugins/computer_use/app/chrome.md +165 -0
- package/plugins/computer_use/app/finder.md +76 -0
- package/plugins/computer_use/app/macos-system-settings.md +81 -0
- package/plugins/computer_use/app/microsoft-excel.md +80 -0
- package/plugins/computer_use/app/microsoft-powerpoint.md +80 -0
- package/plugins/computer_use/app/microsoft-word.md +79 -0
- package/plugins/computer_use/app/wechat.md +413 -0
- package/plugins/computer_use/app/weread.md +319 -0
- package/plugins/computer_use/commands/computeruse.md +25 -0
- package/plugins/computer_use/commands/cu.md +9 -0
- package/plugins/computer_use/plugin.js +26 -0
- package/plugins/computer_use/plugin.ts +30 -0
- package/plugins/computer_use/src/capture.js +90 -0
- package/plugins/computer_use/src/capture.ts +104 -0
- package/plugins/computer_use/src/commands.js +91 -0
- package/plugins/computer_use/src/commands.ts +103 -0
- package/plugins/computer_use/src/daemon.js +134 -0
- package/plugins/computer_use/src/daemon.ts +161 -0
- package/plugins/computer_use/src/manuals.js +135 -0
- package/plugins/computer_use/src/manuals.ts +159 -0
- package/plugins/computer_use/src/verify.js +168 -0
- package/plugins/computer_use/src/verify.ts +219 -0
- package/plugins/computer_use/test/commands.test.ts +73 -0
- package/plugins/cron-runner/plugin.ts +38 -0
- package/plugins/cron-runner/src/commands.ts +373 -0
- package/plugins/cron-runner/src/cronTime.ts +155 -0
- package/plugins/cron-runner/src/lock.ts +79 -0
- package/plugins/cron-runner/src/runs.ts +99 -0
- package/plugins/cron-runner/src/scheduleEngine.ts +76 -0
- package/plugins/cron-runner/src/scheduler.ts +376 -0
- package/plugins/cron-runner/src/schema.ts +139 -0
- package/plugins/cron-runner/src/service.ts +193 -0
- package/plugins/cron-runner/src/store.ts +333 -0
- package/plugins/cron-runner/src/types.ts +141 -0
- package/plugins/cron-runner/test/cronTime.test.ts +41 -0
- package/plugins/cron-runner/test/plugin-integration.test.ts +47 -0
- package/plugins/cron-runner/test/scheduleEngine.test.ts +41 -0
- package/plugins/cron-runner/test/service.test.ts +76 -0
- package/plugins/cron-runner/test/store-and-scheduler.test.ts +501 -0
- package/plugins/workflow-runner/plugin.js +56 -2
- package/plugins/workflow-runner/plugin.ts +113 -0
- package/plugins/workflow-runner/src/agentCommon.js +43 -4
- package/plugins/workflow-runner/src/agentCommon.ts +435 -0
- package/plugins/workflow-runner/src/controlFlow/branch.js +40 -0
- package/plugins/workflow-runner/src/controlFlow/branch.ts +46 -0
- package/plugins/workflow-runner/src/controlFlow/loop.js +211 -0
- package/plugins/workflow-runner/src/controlFlow/loop.ts +248 -0
- package/plugins/workflow-runner/src/controlFlow/pause.js +129 -0
- package/plugins/workflow-runner/src/controlFlow/pause.ts +141 -0
- package/plugins/workflow-runner/src/controlFlow/signal.js +21 -0
- package/plugins/workflow-runner/src/controlFlow/signal.ts +29 -0
- package/plugins/workflow-runner/src/controlFlow/types.js +18 -0
- package/plugins/workflow-runner/src/controlFlow/types.ts +63 -0
- package/plugins/workflow-runner/src/dslManifest.ts +127 -0
- package/plugins/workflow-runner/src/expressions.ts +622 -0
- package/plugins/workflow-runner/src/index.js +13 -4
- package/plugins/workflow-runner/src/index.ts +338 -0
- package/plugins/workflow-runner/src/jsonPayload.ts +84 -0
- package/plugins/workflow-runner/src/loader.js +23 -0
- package/plugins/workflow-runner/src/loader.ts +721 -0
- package/plugins/workflow-runner/src/multimodal.js +2 -1
- package/plugins/workflow-runner/src/multimodal.ts +64 -0
- package/plugins/workflow-runner/src/recovery.ts +149 -0
- package/plugins/workflow-runner/src/runner.js +75 -659
- package/plugins/workflow-runner/src/runner.ts +604 -0
- package/plugins/workflow-runner/src/stepExecutors/agent.ts +234 -0
- package/plugins/workflow-runner/src/stepExecutors/assert.ts +50 -0
- package/plugins/workflow-runner/src/stepExecutors/echo.js +31 -0
- package/plugins/workflow-runner/src/stepExecutors/echo.ts +38 -0
- package/plugins/workflow-runner/src/stepExecutors/llm.ts +133 -0
- package/plugins/workflow-runner/src/stepExecutors/set.js +49 -0
- package/plugins/workflow-runner/src/stepExecutors/set.ts +56 -0
- package/plugins/workflow-runner/src/stepExecutors/skill.js +5 -6
- package/plugins/workflow-runner/src/stepExecutors/skill.ts +140 -0
- package/plugins/workflow-runner/src/stepExecutors/tool.js +80 -8
- package/plugins/workflow-runner/src/stepExecutors/tool.ts +256 -0
- package/plugins/workflow-runner/src/stepExecutors/verify.ts +68 -0
- package/plugins/workflow-runner/src/stepPipeline.js +277 -0
- package/plugins/workflow-runner/src/stepPipeline.ts +366 -0
- package/plugins/workflow-runner/src/taskIdentity.ts +405 -0
- package/plugins/workflow-runner/src/toolRuntime.js +48 -0
- package/plugins/workflow-runner/src/toolRuntime.ts +64 -0
- package/plugins/workflow-runner/src/types.js +37 -1
- package/plugins/workflow-runner/src/types.ts +602 -0
- package/plugins/workflow-runner/src/workflowState.ts +733 -0
- package/plugins/workflow-runner/test/agent.test.ts +587 -0
- package/plugins/workflow-runner/test/agentLlmError.test.ts +373 -0
- package/plugins/workflow-runner/test/bashBlacklist.sweep.test.ts +65 -0
- package/plugins/workflow-runner/test/captureMisbind.test.ts +99 -0
- package/plugins/workflow-runner/test/cli.e2e.test.ts +147 -0
- package/plugins/workflow-runner/test/context-files.test.ts +320 -0
- package/plugins/workflow-runner/test/e2e.test.ts +370 -0
- package/plugins/workflow-runner/test/engineRobustness.test.ts +226 -0
- package/plugins/workflow-runner/test/expressions.test.ts +397 -0
- package/plugins/workflow-runner/test/foundation.test.ts +126 -0
- package/plugins/workflow-runner/test/graceful.test.ts +139 -0
- package/plugins/workflow-runner/test/greedyInputs.load.test.ts +47 -0
- package/plugins/workflow-runner/test/hostCapability.test.ts +108 -0
- package/plugins/workflow-runner/test/illustrate.load.test.ts +183 -0
- package/plugins/workflow-runner/test/jsonPayload.test.ts +83 -0
- package/plugins/workflow-runner/test/loader.test.ts +617 -0
- package/plugins/workflow-runner/test/maxTurnsRetryDelay.test.ts +33 -0
- package/plugins/workflow-runner/test/multimodal.test.ts +342 -0
- package/plugins/workflow-runner/test/output-schema.test.ts +213 -0
- package/plugins/workflow-runner/test/parseWorkflowArgs.test.ts +87 -0
- package/plugins/workflow-runner/test/pluginRunner.isolation.test.ts +269 -0
- package/plugins/workflow-runner/test/ppt.load.test.ts +1220 -0
- package/plugins/workflow-runner/test/ralphLoop.e2e.test.ts +220 -0
- package/plugins/workflow-runner/test/recovery.test.ts +265 -0
- package/plugins/workflow-runner/test/runner.test.ts +911 -0
- package/plugins/workflow-runner/test/runnerPreflight.test.ts +379 -0
- package/plugins/workflow-runner/test/skillTurnDone.test.ts +71 -0
- package/plugins/workflow-runner/test/stateLifecycle.test.ts +150 -0
- package/plugins/workflow-runner/test/stepPipeline.test.ts +114 -0
- package/plugins/workflow-runner/test/taskArbitration.test.ts +338 -0
- package/plugins/workflow-runner/test/taskIdentity.test.ts +237 -0
- package/plugins/workflow-runner/test/taskLifecycle.test.ts +270 -0
- package/plugins/workflow-runner/test/toolArtifactOverwrite.test.ts +221 -0
- package/plugins/workflow-runner/test/toolCapabilityBoundary.test.ts +29 -0
- package/plugins/workflow-runner/test/toolRuntimeIntegration.test.ts +168 -0
- package/plugins/workflow-runner/test/webppt.load.test.ts +250 -0
- package/plugins/workflow-runner/test/word.load.test.ts +208 -0
- package/plugins/workflow-runner/test/workflows.smoke.test.ts +76 -0
- package/plugins/workflow-runner/test/yamlGuardConditions.test.ts +207 -0
- package/skills/browser-automation/SKILL.md +9 -19
- package/skills/web-crawler/SKILL.md +9 -11
- package/src/askBridge.ts +249 -0
- package/src/bootstrap/cwdArg.js +10 -3
- package/src/bootstrap/cwdArg.ts +31 -0
- package/src/bootstrap/workingDir.ts +48 -0
- package/src/cli/args.js +70 -7
- package/src/cli/args.ts +146 -0
- package/src/cli/computerUse.js +185 -0
- package/src/cli/computerUse.ts +221 -0
- package/src/cli/configMenu.js +274 -202
- package/src/cli/configMenu.tsx +521 -0
- package/src/cli/memoryAccess.js +45 -0
- package/src/cli/memoryAccess.ts +53 -0
- package/src/cli/print.js +119 -5
- package/src/cli/print.ts +597 -0
- package/src/cli/quickModelSetup.js +60 -0
- package/src/cli/quickModelSetup.tsx +96 -0
- package/src/cli/streamJson.js +80 -4
- package/src/cli/streamJson.ts +433 -0
- package/src/cli/wizards/advisorWizard.js +1 -0
- package/src/cli/wizards/advisorWizard.tsx +195 -0
- package/src/cli/wizards/agentRuntimeWizard.js +84 -0
- package/src/cli/wizards/agentRuntimeWizard.tsx +134 -0
- package/src/cli/wizards/browserWizard.js +55 -0
- package/src/cli/wizards/browserWizard.tsx +77 -0
- package/src/cli/wizards/contextAdvisorWizard.js +84 -0
- package/src/cli/wizards/contextAdvisorWizard.tsx +124 -0
- package/src/cli/wizards/fieldForm.js +7 -4
- package/src/cli/wizards/fieldForm.tsx +250 -0
- package/src/cli/wizards/imageWizard.js +4 -5
- package/src/cli/wizards/imageWizard.tsx +96 -0
- package/src/cli/wizards/openRouterWizard.tsx +48 -0
- package/src/cli/wizards/providerPresets.js +1 -8
- package/src/cli/wizards/providerPresets.ts +106 -0
- package/src/cli/wizards/providerWizard.js +152 -205
- package/src/cli/wizards/providerWizard.tsx +266 -0
- package/src/cli/wizards/searchWizard.tsx +47 -0
- package/src/cli/wizards/ttsWizard.js +4 -3
- package/src/cli/wizards/ttsWizard.tsx +61 -0
- package/src/config/configDefaults.js +25 -0
- package/src/config/configDefaults.ts +33 -0
- package/src/config/configDiagnostics.js +117 -0
- package/src/config/configDiagnostics.ts +166 -0
- package/src/config/configFile.js +52 -32
- package/src/config/configFile.ts +633 -0
- package/src/config/configManagement.js +126 -0
- package/src/config/configManagement.ts +159 -0
- package/src/config/configService.js +66 -11
- package/src/config/configService.ts +554 -0
- package/src/config/numericLimits.js +61 -0
- package/src/config/numericLimits.ts +80 -0
- package/src/config.ts +109 -0
- package/src/context/agentHome.ts +11 -0
- package/src/context/archive.ts +144 -0
- package/src/context/budgetPlan.js +54 -0
- package/src/context/budgetPlan.ts +88 -0
- package/src/context/compact.js +179 -106
- package/src/context/compact.ts +584 -0
- package/src/context/contextBundle.js +119 -0
- package/src/context/contextBundle.ts +176 -0
- package/src/context/contextLock.ts +84 -0
- package/src/context/microCompactLite.ts +218 -0
- package/src/context/persistContext.ts +177 -0
- package/src/context/reactiveCompact.js +19 -4
- package/src/context/reactiveCompact.ts +240 -0
- package/src/context/recentDirs.ts +42 -0
- package/src/context/sessionPath.ts +206 -0
- package/src/context/sessionRegistry.js +8 -2
- package/src/context/sessionRegistry.ts +414 -0
- package/src/context/snipCompact.ts +163 -0
- package/src/context/tokenCounter.ts +106 -0
- package/src/context/workspaceIndex.js +2 -2
- package/src/context/workspaceIndex.ts +751 -0
- package/src/entry.compiled.tsx +20 -0
- package/src/harness/claimValidation.js +9 -0
- package/src/harness/claimValidation.ts +22 -0
- package/src/harness/evidenceLedger.js +92 -0
- package/src/harness/evidenceLedger.ts +96 -0
- package/src/harness/stallGuard.js +60 -0
- package/src/harness/stallGuard.ts +81 -0
- package/src/humanIntervention.js +129 -0
- package/src/humanIntervention.ts +216 -0
- package/src/infra/verification.ts +295 -0
- package/src/irreversible/rules.js +216 -0
- package/src/irreversible/rules.ts +261 -0
- package/src/llm/client.js +40 -3
- package/src/llm/client.ts +621 -0
- package/src/llm/promptCache.js +27 -0
- package/src/llm/promptCache.ts +41 -0
- package/src/llm/providers/anthropicFormat.js +41 -5
- package/src/llm/providers/anthropicFormat.ts +290 -0
- package/src/llm/providers/openaiFormat.js +186 -8
- package/src/llm/providers/openaiFormat.ts +428 -0
- package/src/loop.js +614 -63
- package/src/loop.ts +1454 -0
- package/src/main.js +67 -10
- package/src/main.tsx +344 -0
- package/src/memory/codec.js +204 -0
- package/src/memory/codec.ts +249 -0
- package/src/memory/constants.js +34 -0
- package/src/memory/constants.ts +50 -0
- package/src/memory/episodicMemory.js +684 -0
- package/src/memory/episodicMemory.ts +815 -0
- package/src/memory/fileStore.js +148 -0
- package/src/memory/fileStore.ts +184 -0
- package/src/memory/memoryService.js +570 -0
- package/src/memory/memoryService.ts +859 -0
- package/src/memory/migration.js +128 -0
- package/src/memory/migration.ts +160 -0
- package/src/memory/repository.js +789 -0
- package/src/memory/repository.ts +893 -0
- package/src/memory/retrieval.js +108 -0
- package/src/memory/retrieval.ts +145 -0
- package/src/memory/searchIndex.js +107 -0
- package/src/memory/searchIndex.ts +153 -0
- package/src/memory/topicView.js +82 -0
- package/src/memory/topicView.ts +95 -0
- package/src/memory/turnJournal.js +95 -0
- package/src/memory/turnJournal.ts +120 -0
- package/src/memory/types.js +2 -0
- package/src/memory/types.ts +186 -0
- package/src/messageQueue.ts +123 -0
- package/src/multimodal.js +128 -46
- package/src/multimodal.ts +349 -0
- package/src/plugin-sdk.js +21 -1
- package/src/plugin-sdk.ts +134 -0
- package/src/plugins/builtinPluginIds.js +47 -0
- package/src/plugins/builtinPluginIds.ts +51 -0
- package/src/plugins/builtinRegistry.ts +43 -0
- package/src/plugins/commandRouter.js +40 -26
- package/src/plugins/commandRouter.ts +261 -0
- package/src/plugins/hookEngine.ts +341 -0
- package/src/plugins/pluginApi.ts +133 -0
- package/src/plugins/pluginLifecycle.ts +34 -0
- package/src/plugins/pluginLoader.ts +147 -0
- package/src/plugins/pluginManifest.js +127 -0
- package/src/plugins/pluginManifest.ts +152 -0
- package/src/plugins/pluginRunner.js +47 -2
- package/src/plugins/pluginRunner.ts +207 -0
- package/src/plugins/transcript.ts +208 -0
- package/src/prompts/lint.js +169 -0
- package/src/prompts/lint.ts +220 -0
- package/src/prompts/pluginList.js +32 -16
- package/src/prompts/pluginList.ts +86 -0
- package/src/prompts/policyRegistry.js +318 -0
- package/src/prompts/policyRegistry.ts +358 -0
- package/src/prompts/projectInstructions.js +24 -0
- package/src/prompts/projectInstructions.ts +81 -0
- package/src/prompts/promptAssembly.js +311 -202
- package/src/prompts/promptAssembly.ts +510 -0
- package/src/prompts/skillList.js +106 -45
- package/src/prompts/skillList.ts +198 -0
- package/src/prompts/system.js +31 -6
- package/src/prompts/system.ts +81 -0
- package/src/runtime/agentRuntimeContext.js +53 -0
- package/src/runtime/agentRuntimeContext.ts +112 -0
- package/src/session/runAgentTurn.js +71 -12
- package/src/session/runAgentTurn.ts +181 -0
- package/src/session/runTurn.js +29 -0
- package/src/session/runTurn.ts +160 -0
- package/src/session/runtimeStore.js +149 -0
- package/src/session/runtimeStore.ts +197 -0
- package/src/session/sessionState.js +79 -3
- package/src/session/sessionState.ts +134 -0
- package/src/toolGate.ts +50 -0
- package/src/tools/advisor/advisor.js +76 -15
- package/src/tools/advisor/advisor.ts +512 -0
- package/src/tools/agent/agent.js +245 -29
- package/src/tools/agent/agent.ts +837 -0
- package/src/tools/agent/agentTaskService.js +60 -0
- package/src/tools/agent/agentTaskService.ts +113 -0
- package/src/tools/agent/agentTypes.js +20 -8
- package/src/tools/agent/agentTypes.ts +94 -0
- package/src/tools/agent/coordinator.ts +111 -0
- package/src/tools/agent/worktree.ts +296 -0
- package/src/tools/ask/ask.js +17 -0
- package/src/tools/ask/ask.ts +122 -0
- package/src/tools/bash/attachImage.js +223 -0
- package/src/tools/bash/attachImage.ts +281 -0
- package/src/tools/bash/bash.js +132 -14
- package/src/tools/bash/bash.ts +642 -0
- package/src/tools/bash/semantics.ts +103 -0
- package/src/tools/bash/warnings.js +17 -11
- package/src/tools/bash/warnings.ts +117 -0
- package/src/tools/capabilities.js +42 -0
- package/src/tools/capabilities.ts +69 -0
- package/src/tools/computeruse/accessibilityPermission.js +261 -0
- package/src/tools/computeruse/accessibilityPermission.ts +294 -0
- package/src/tools/computeruse/axSearch.js +96 -0
- package/src/tools/computeruse/axSearch.ts +120 -0
- package/src/tools/computeruse/axSnap.js +272 -0
- package/src/tools/computeruse/axSnap.ts +349 -0
- package/src/tools/computeruse/capabilityLabels.js +95 -0
- package/src/tools/computeruse/capabilityLabels.ts +115 -0
- package/src/tools/computeruse/computerUseService.js +2235 -0
- package/src/tools/computeruse/computerUseService.ts +2686 -0
- package/src/tools/computeruse/computeruse.js +2742 -0
- package/src/tools/computeruse/computeruse.ts +3265 -0
- package/src/tools/computeruse/diagnosticTrace.js +154 -0
- package/src/tools/computeruse/diagnosticTrace.ts +195 -0
- package/src/tools/computeruse/diagnostics.js +369 -0
- package/src/tools/computeruse/diagnostics.ts +453 -0
- package/src/tools/computeruse/grants.js +53 -0
- package/src/tools/computeruse/grants.ts +70 -0
- package/src/tools/computeruse/humanBoundary.js +159 -0
- package/src/tools/computeruse/humanBoundary.ts +199 -0
- package/src/tools/computeruse/intervention.js +77 -0
- package/src/tools/computeruse/intervention.ts +110 -0
- package/src/tools/computeruse/manualSchema.js +709 -0
- package/src/tools/computeruse/manualSchema.ts +916 -0
- package/src/tools/computeruse/observationImages.js +705 -0
- package/src/tools/computeruse/observationImages.ts +889 -0
- package/src/tools/computeruse/protocol.js +60 -0
- package/src/tools/computeruse/protocol.ts +515 -0
- package/src/tools/computeruse/telemetryLog.js +57 -0
- package/src/tools/computeruse/telemetryLog.ts +67 -0
- package/src/tools/computeruse/vision/appGuide.js +325 -0
- package/src/tools/computeruse/vision/appGuide.ts +482 -0
- package/src/tools/computeruse/vision/focus.js +291 -0
- package/src/tools/computeruse/vision/focus.ts +382 -0
- package/src/tools/computeruse/vision/frames.js +248 -0
- package/src/tools/computeruse/vision/frames.ts +329 -0
- package/src/tools/computeruse/vision/geometry.js +131 -0
- package/src/tools/computeruse/vision/geometry.ts +163 -0
- package/src/tools/computeruse/vision/imaging.js +201 -0
- package/src/tools/computeruse/vision/imaging.ts +281 -0
- package/src/tools/computeruse/vision/png.js +274 -0
- package/src/tools/computeruse/vision/png.ts +317 -0
- package/src/tools/computeruse/vision/raster.js +320 -0
- package/src/tools/computeruse/vision/raster.ts +408 -0
- package/src/tools/computeruse/vision/settle.js +131 -0
- package/src/tools/computeruse/vision/settle.ts +220 -0
- package/src/tools/computeruse/vision/telemetry.js +196 -0
- package/src/tools/computeruse/vision/telemetry.ts +241 -0
- package/src/tools/computeruse/visionOcr.js +115 -0
- package/src/tools/computeruse/visionOcr.ts +128 -0
- package/src/tools/computeruse/waitFor.js +237 -0
- package/src/tools/computeruse/waitFor.ts +291 -0
- package/src/tools/download/download.js +10 -6
- package/src/tools/download/download.ts +187 -0
- package/src/tools/edit/edit.js +30 -18
- package/src/tools/edit/edit.ts +349 -0
- package/src/tools/edit/multi-edit.js +25 -14
- package/src/tools/edit/multi-edit.ts +223 -0
- package/src/tools/effectiveToolSet.js +73 -0
- package/src/tools/effectiveToolSet.ts +91 -0
- package/src/tools/genimage/genimage.ts +257 -0
- package/src/tools/genspeech/genspeech.ts +83 -0
- package/src/tools/glob/glob.js +176 -29
- package/src/tools/glob/glob.ts +283 -0
- package/src/tools/grep/grep.js +61 -19
- package/src/tools/grep/grep.ts +239 -0
- package/src/tools/grep/rgPath.ts +206 -0
- package/src/tools/index.js +99 -5
- package/src/tools/index.ts +293 -0
- package/src/tools/lsp/config.js +113 -0
- package/src/tools/lsp/config.ts +113 -0
- package/src/tools/lsp/lsp.js +256 -0
- package/src/tools/lsp/lsp.ts +274 -0
- package/src/tools/lsp/service.js +303 -0
- package/src/tools/lsp/service.ts +296 -0
- package/src/tools/memory/memory.js +520 -0
- package/src/tools/memory/memory.ts +625 -0
- package/src/tools/memory/policy.js +53 -0
- package/src/tools/memory/policy.ts +72 -0
- package/src/tools/notebook/notebookEdit.js +114 -0
- package/src/tools/notebook/notebookEdit.ts +126 -0
- package/src/tools/powershell/powershell.js +210 -0
- package/src/tools/powershell/powershell.ts +239 -0
- package/src/tools/presentresult/presentresult.js +145 -0
- package/src/tools/presentresult/presentresult.ts +156 -0
- package/src/tools/read/read.js +371 -163
- package/src/tools/read/read.ts +558 -0
- package/src/tools/shared/diffSummary.js +44 -0
- package/src/tools/shared/diffSummary.ts +63 -0
- package/src/tools/shared/fileActivity.js +51 -0
- package/src/tools/shared/fileActivity.ts +66 -0
- package/src/tools/shared/fileMutationBus.js +13 -0
- package/src/tools/shared/fileMutationBus.ts +14 -0
- package/src/tools/shared/fileState.js +73 -65
- package/src/tools/shared/fileState.ts +145 -0
- package/src/tools/shared/fileUtils.js +81 -4
- package/src/tools/shared/fileUtils.ts +504 -0
- package/src/tools/shared/killTree.ts +50 -0
- package/src/tools/shared/permanentDeleteGuard.js +26 -0
- package/src/tools/shared/permanentDeleteGuard.ts +34 -0
- package/src/tools/shared/schemas.ts +20 -0
- package/src/tools/shared/toolOutputStore.js +97 -0
- package/src/tools/shared/toolOutputStore.ts +110 -0
- package/src/tools/skill/skill.js +86 -0
- package/src/tools/skill/skill.ts +94 -0
- package/src/tools/snip/snip.js +67 -0
- package/src/tools/snip/snip.ts +80 -0
- package/src/tools/tasks/backgroundTaskService.js +275 -0
- package/src/tools/tasks/backgroundTaskService.ts +369 -0
- package/src/tools/tasks/processEvidence.js +24 -0
- package/src/tools/tasks/processEvidence.ts +34 -0
- package/src/tools/tasks/taskManagement.js +163 -0
- package/src/tools/tasks/taskManagement.ts +180 -0
- package/src/tools/tasks/taskOutput.js +113 -0
- package/src/tools/tasks/taskOutput.ts +145 -0
- package/src/tools/tasks/taskStop.js +74 -0
- package/src/tools/tasks/taskStop.ts +99 -0
- package/src/tools/tasks/taskStore.js +46 -0
- package/src/tools/tasks/taskStore.ts +77 -0
- package/src/tools/terminal/terminalCapture.js +167 -0
- package/src/tools/terminal/terminalCapture.ts +179 -0
- package/src/tools/trash/trash.js +233 -0
- package/src/tools/trash/trash.ts +283 -0
- package/src/tools/types.js +1 -1
- package/src/tools/types.ts +24 -0
- package/src/tools/webbrowser/agentBrowserPath.ts +286 -0
- package/src/tools/webbrowser/browser.js +214 -11
- package/src/tools/webbrowser/browser.ts +293 -0
- package/src/tools/webbrowser/browserControl.js +153 -48
- package/src/tools/webbrowser/browserControl.ts +262 -0
- package/src/tools/webbrowser/browserDaemon.js +147 -39
- package/src/tools/webbrowser/browserDaemon.ts +270 -0
- package/src/tools/webbrowser/browserOutcome.js +273 -0
- package/src/tools/webbrowser/browserOutcome.ts +306 -0
- package/src/tools/webbrowser/browserRunRegistry.js +150 -0
- package/src/tools/webbrowser/browserRunRegistry.ts +179 -0
- package/src/tools/webbrowser/browserService.js +20 -6
- package/src/tools/webbrowser/browserService.ts +56 -0
- package/src/tools/webbrowser/browserStream.js +30 -1
- package/src/tools/webbrowser/browserStream.ts +216 -0
- package/src/tools/webbrowser/browserTabs.js +143 -0
- package/src/tools/webbrowser/browserTabs.ts +210 -0
- package/src/tools/webbrowser/webbrowser.js +831 -150
- package/src/tools/webbrowser/webbrowser.ts +1537 -0
- package/src/tools/webfetch/preapproved.ts +274 -0
- package/src/tools/webfetch/webfetch.js +24 -23
- package/src/tools/webfetch/webfetch.ts +383 -0
- package/src/tools/websearch/websearch.js +12 -11
- package/src/tools/websearch/websearch.ts +292 -0
- package/src/tools/worktree/sessionWorktree.js +128 -0
- package/src/tools/worktree/sessionWorktree.ts +158 -0
- package/src/tools/write/write.js +27 -44
- package/src/tools/write/write.ts +136 -0
- package/src/types.ts +960 -0
- package/src/ui/App.js +216 -12
- package/src/ui/App.tsx +879 -0
- package/src/ui/AskQuestion.tsx +300 -0
- package/src/ui/InputBox.js +77 -1
- package/src/ui/InputBox.tsx +567 -0
- package/src/ui/LiveArea.tsx +344 -0
- package/src/ui/MessageList.js +27 -6
- package/src/ui/MessageList.tsx +559 -0
- package/src/ui/ModelPicker.tsx +107 -0
- package/src/ui/QueuedMessagesBanner.tsx +51 -0
- package/src/ui/Root.js +6 -8
- package/src/ui/Root.tsx +100 -0
- package/src/ui/SessionPicker.tsx +169 -0
- package/src/ui/StatusLine.js +22 -1
- package/src/ui/StatusLine.tsx +145 -0
- package/src/ui/WorkspacePicker.tsx +84 -0
- package/src/ui/advisorCommand.js +54 -0
- package/src/ui/advisorCommand.ts +63 -0
- package/src/ui/computerCommand.js +19 -0
- package/src/ui/computerCommand.ts +35 -0
- package/src/ui/figures.ts +45 -0
- package/src/ui/hooks/askSlot.ts +112 -0
- package/src/ui/hooks/useChat.js +271 -7
- package/src/ui/hooks/useChat.ts +1578 -0
- package/src/ui/hooks/useInputHistory.ts +235 -0
- package/src/ui/hooks/usePasteHandler.ts +220 -0
- package/src/ui/hooks/useTerminalSize.ts +41 -0
- package/src/ui/hooks/useTextBuffer.ts +108 -0
- package/src/ui/hooks/useTokenUsage.ts +44 -0
- package/src/ui/liveViewport.ts +189 -0
- package/src/ui/markdown.ts +230 -0
- package/src/ui/textBuffer.ts +239 -0
- package/src/ui/theme.ts +35 -0
- package/src/utils/clipboardImage.js +358 -0
- package/src/utils/clipboardImage.ts +420 -0
- package/src/utils/debugLog.ts +50 -0
- package/src/utils/greenRoot.ts +35 -0
- package/src/utils/packageRoot.ts +40 -0
- package/src/utils/pathContains.js +28 -0
- package/src/utils/pathContains.ts +31 -0
- package/src/utils/resourcePaths.ts +71 -0
- package/src/utils/stripThink.ts +49 -0
- package/src/utils/zodToJson.ts +73 -0
- package/src/web/browserBridge.js +365 -66
- package/src/web/browserBridge.ts +672 -0
- package/src/web/protocol.ts +1804 -0
- package/vendor/computer-use/arm64-darwin/cu-helperd +0 -0
- package/workflows/ppt.yaml +13 -2
- package/workflows/wechat-reading-shots.yaml +315 -0
- package/workflows/word.yaml +11 -1
- package/skills/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/base.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/docx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/pptx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/redlining.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/__pycache__/image_stats.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/__pycache__/image_stats_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/chart_sanity_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_language_policy.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact_pptx_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/draft_coverage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/scaffold_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/text_readability_pixel.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate_test.cpython-314.pyc +0 -0
- /package/skills/ai-image/scripts/{generate_test.mjs → generate.selftest.mjs} +0 -0
- /package/skills/ai-image/scripts/{generate_from_plan_test.mjs → generate_from_plan.selftest.mjs} +0 -0
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
import type { Provider } from '../types.js';
|
|
4
|
+
import {
|
|
5
|
+
readMinimalAgentConfig,
|
|
6
|
+
updateMinimalAgentConfig,
|
|
7
|
+
defaultMaxTokens,
|
|
8
|
+
type MinimalAgentConfig,
|
|
9
|
+
type AdvisorConfig,
|
|
10
|
+
type ModelConfig,
|
|
11
|
+
type ApiFormat,
|
|
12
|
+
type ToolConfigs,
|
|
13
|
+
type SubagentsConfig,
|
|
14
|
+
type BrowserConfig,
|
|
15
|
+
type ComputerUseConfig,
|
|
16
|
+
DEFAULT_SUBAGENTS_CONFIG,
|
|
17
|
+
DEFAULT_BROWSER_CONFIG,
|
|
18
|
+
DEFAULT_COMPUTER_USE_CONFIG,
|
|
19
|
+
} from './configFile.js';
|
|
20
|
+
import { CONFIG_LIMITS, normalizeLimited } from './numericLimits.js';
|
|
21
|
+
|
|
22
|
+
export type ConfigSource = 'json' | 'environment' | 'none';
|
|
23
|
+
export type ToolConfigKey = keyof ToolConfigs;
|
|
24
|
+
export type ToolStatusState = 'unconfigured' | 'configured' | 'incomplete';
|
|
25
|
+
|
|
26
|
+
export interface ToolStatus {
|
|
27
|
+
state: ToolStatusState;
|
|
28
|
+
configured: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ConfigSnapshot {
|
|
32
|
+
source: ConfigSource;
|
|
33
|
+
readOnly: boolean;
|
|
34
|
+
config: MinimalAgentConfig | null;
|
|
35
|
+
revision: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 模型列表的三种变更操作——加/改/删,走同一个 ConfigPatch 提交(不新开一族方法)。
|
|
40
|
+
* `add` 的字段全 Partial(不是 Omit 后的必填):必填校验在 applyModelsPatch 里运行时做
|
|
41
|
+
* (防御性 `m.baseURL?.trim()` 风格 + 清晰的中文报错),类型层不重复这份校验,两者保持一致
|
|
42
|
+
* 而不是「类型说必填、实现却防着 undefined」的分裂状态。
|
|
43
|
+
*/
|
|
44
|
+
export type ModelOp =
|
|
45
|
+
| { op: 'add'; model: Partial<Omit<ModelConfig, 'id' | 'createdAt' | 'updatedAt'>> }
|
|
46
|
+
| { op: 'update'; id: string; patch: Partial<Omit<ModelConfig, 'id' | 'createdAt' | 'updatedAt'>> & { clearApiKey?: boolean } }
|
|
47
|
+
| { op: 'remove'; id: string };
|
|
48
|
+
|
|
49
|
+
export interface ConfigPatch {
|
|
50
|
+
models?: ModelOp[];
|
|
51
|
+
baseModelId?: string | null;
|
|
52
|
+
compactRatio?: number;
|
|
53
|
+
advisor?: (Partial<Omit<AdvisorConfig, 'contextPolicy'>> & { clear?: boolean });
|
|
54
|
+
subagents?: Partial<SubagentsConfig>;
|
|
55
|
+
browser?: Partial<BrowserConfig>;
|
|
56
|
+
computerUse?: Partial<ComputerUseConfig>;
|
|
57
|
+
tools?: {
|
|
58
|
+
webSearch?: Partial<NonNullable<ToolConfigs['webSearch']>> & { clear?: boolean };
|
|
59
|
+
imageGeneration?: Partial<NonNullable<ToolConfigs['imageGeneration']>> & { clear?: boolean; clearApiKey?: boolean };
|
|
60
|
+
openRouter?: Partial<NonNullable<ToolConfigs['openRouter']>> & { clear?: boolean };
|
|
61
|
+
textToSpeech?: Partial<NonNullable<ToolConfigs['textToSpeech']>> & { clear?: boolean; clearApiKey?: boolean };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const DEFAULT_CONTEXT_WINDOW = 128_000;
|
|
66
|
+
|
|
67
|
+
function positiveInt(value: string | undefined, fallback: number): number {
|
|
68
|
+
const parsed = Number.parseInt(value ?? '', 10);
|
|
69
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 纯 env 自举路径(无 JSON 配置文件时的兜底)。只产出 OpenAI 格式的模型——Anthropic 格式
|
|
74
|
+
* 只能通过 JSON 配置(Desktop/CLI)新增,这是刻意的范围限制,不是遗漏。
|
|
75
|
+
*
|
|
76
|
+
* 顾问不再有独立的 env 自举路径(ADVISOR_AGENT_* 家族整体移除)——顾问配置以后只能通过
|
|
77
|
+
* JSON 配置的 `advisor.modelId` 引用模型列表条目,没有 JSON 时顾问就是未配置。
|
|
78
|
+
*
|
|
79
|
+
* ⚠️ 这里派生的模型 id/createdAt/updatedAt 必须是固定字面量,不能用 randomUUID()/Date.now()——
|
|
80
|
+
* configFromEnv() 在每次 reload() 都会重新构造,reload() 靠 JSON.stringify 差异判断 revision
|
|
81
|
+
* 是否变化;任何一次性值都会让 env 模式下每次 reload 的 revision 都在跳,进而每轮对话都触发
|
|
82
|
+
* 桌面端 resetProvider()。
|
|
83
|
+
*/
|
|
84
|
+
function configFromEnv(): MinimalAgentConfig | null {
|
|
85
|
+
const baseURL = process.env.MINIMAL_AGENT_BASE_URL;
|
|
86
|
+
const apiKey = process.env.MINIMAL_AGENT_API_KEY;
|
|
87
|
+
const model = process.env.MINIMAL_AGENT_MODEL;
|
|
88
|
+
if (!baseURL || !apiKey || !model) return null;
|
|
89
|
+
const tools: ToolConfigs = {};
|
|
90
|
+
if (process.env.TAVILY_API_KEY) tools.webSearch = { provider: 'tavily', apiKey: process.env.TAVILY_API_KEY };
|
|
91
|
+
if (process.env.OPENAI_IMAGE_BASE_URL && process.env.OPENAI_IMAGE_API_KEY && process.env.OPENAI_IMAGE_MODEL) {
|
|
92
|
+
tools.imageGeneration = {
|
|
93
|
+
provider: process.env.OPENAI_IMAGE_PROVIDER ?? 'openai',
|
|
94
|
+
baseURL: process.env.OPENAI_IMAGE_BASE_URL,
|
|
95
|
+
apiKey: process.env.OPENAI_IMAGE_API_KEY,
|
|
96
|
+
model: process.env.OPENAI_IMAGE_MODEL,
|
|
97
|
+
protocol: process.env.OPENAI_IMAGE_PROTOCOL === 'chat' || process.env.OPENAI_IMAGE_PROTOCOL === 'images'
|
|
98
|
+
? process.env.OPENAI_IMAGE_PROTOCOL
|
|
99
|
+
: 'auto',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (process.env.OPENROUTER_API_KEY) tools.openRouter = { apiKey: process.env.OPENROUTER_API_KEY };
|
|
103
|
+
if (process.env.MINIMAX_API_KEY && process.env.MINIMAX_GROUP_ID) {
|
|
104
|
+
tools.textToSpeech = { provider: 'minimax', apiKey: process.env.MINIMAX_API_KEY, groupId: process.env.MINIMAX_GROUP_ID };
|
|
105
|
+
}
|
|
106
|
+
const compactRatio = Number(process.env.MINIMAL_AGENT_COMPACT_RATIO);
|
|
107
|
+
const name = process.env.MINIMAL_AGENT_PROVIDER ?? 'env';
|
|
108
|
+
const contextWindow = positiveInt(process.env.MINIMAL_AGENT_CONTEXT_WINDOW, DEFAULT_CONTEXT_WINDOW);
|
|
109
|
+
const envModel: ModelConfig = {
|
|
110
|
+
id: 'env-base',
|
|
111
|
+
apiFormat: 'openai',
|
|
112
|
+
...(name !== 'env' ? { displayName: name } : {}),
|
|
113
|
+
baseURL,
|
|
114
|
+
apiKey,
|
|
115
|
+
model,
|
|
116
|
+
contextWindow,
|
|
117
|
+
maxTokens: positiveInt(process.env.MINIMAL_AGENT_MAX_TOKENS, defaultMaxTokens(contextWindow)),
|
|
118
|
+
promptCache: {
|
|
119
|
+
mode: process.env.MINIMAL_AGENT_PROMPT_CACHE_MODE === 'session-key'
|
|
120
|
+
? 'session-key'
|
|
121
|
+
: process.env.MINIMAL_AGENT_PROMPT_CACHE_MODE === 'disabled'
|
|
122
|
+
? 'disabled'
|
|
123
|
+
: 'auto',
|
|
124
|
+
},
|
|
125
|
+
enabled: true,
|
|
126
|
+
createdAt: 0,
|
|
127
|
+
updatedAt: 0,
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
version: 4,
|
|
131
|
+
models: [envModel],
|
|
132
|
+
baseModelId: envModel.id,
|
|
133
|
+
...(compactRatio > 0 && compactRatio <= 1 ? { compactRatio } : {}),
|
|
134
|
+
subagents: {
|
|
135
|
+
...DEFAULT_SUBAGENTS_CONFIG,
|
|
136
|
+
maxCallsPerTurn: positiveInt(process.env.AGENT_TOOL_MAX_CALLS_PER_TURN, 6),
|
|
137
|
+
maxConcurrent: positiveInt(process.env.AGENT_TOOL_MAX_CONCURRENT, 3),
|
|
138
|
+
timeoutMs: positiveInt(process.env.AGENT_TOOL_TIMEOUT_MS, 1_800_000),
|
|
139
|
+
exploreMaxTurns: positiveInt(process.env.AGENT_TOOL_EXPLORE_MAX_TURNS, 50),
|
|
140
|
+
generalMaxTurns: positiveInt(process.env.AGENT_TOOL_GENERAL_MAX_TURNS, 100),
|
|
141
|
+
},
|
|
142
|
+
browser: DEFAULT_BROWSER_CONFIG,
|
|
143
|
+
computerUse: {
|
|
144
|
+
enabled: process.env.MINIMAL_AGENT_COMPUTER_USE_ENABLED !== 'false',
|
|
145
|
+
imagePolicy: 'single-adaptive',
|
|
146
|
+
maxImagePixels: Math.min(4_000_000, Math.max(250_000, positiveInt(
|
|
147
|
+
process.env.MINIMAL_AGENT_COMPUTER_USE_MAX_IMAGE_PIXELS,
|
|
148
|
+
DEFAULT_COMPUTER_USE_CONFIG.maxImagePixels,
|
|
149
|
+
))),
|
|
150
|
+
observationFrames: 1,
|
|
151
|
+
},
|
|
152
|
+
tools,
|
|
153
|
+
savedAt: 0,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function resolveProvider(entry: ModelConfig, compactRatio?: number): Provider {
|
|
158
|
+
return {
|
|
159
|
+
name: entry.displayName ?? entry.model,
|
|
160
|
+
baseURL: entry.baseURL,
|
|
161
|
+
apiKey: entry.apiKey,
|
|
162
|
+
model: entry.model,
|
|
163
|
+
contextWindow: entry.contextWindow,
|
|
164
|
+
maxTokens: entry.maxTokens ?? defaultMaxTokens(entry.contextWindow),
|
|
165
|
+
apiFormat: entry.apiFormat,
|
|
166
|
+
supportsVision: entry.supportsVision !== false,
|
|
167
|
+
promptCache: entry.promptCache ?? { mode: 'auto' },
|
|
168
|
+
...(compactRatio !== undefined ? { compactRatio } : {}),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function mergeRecord(base: Record<string, unknown> | undefined, patch: Record<string, unknown>): Record<string, unknown> {
|
|
173
|
+
const out: Record<string, unknown> = { ...(base ?? {}) };
|
|
174
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
175
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
176
|
+
out[key] = mergeRecord(
|
|
177
|
+
out[key] && typeof out[key] === 'object' && !Array.isArray(out[key]) ? out[key] as Record<string, unknown> : undefined,
|
|
178
|
+
value as Record<string, unknown>,
|
|
179
|
+
);
|
|
180
|
+
} else if (value !== undefined) out[key] = value;
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function hasEntries(value: object | undefined): boolean {
|
|
186
|
+
return !!value && Object.keys(value).length > 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function applyModelsPatch(models: ModelConfig[], ops: ModelOp[]): ModelConfig[] {
|
|
190
|
+
let out = [...models];
|
|
191
|
+
const now = Date.now();
|
|
192
|
+
for (const item of ops) {
|
|
193
|
+
if (item.op === 'add') {
|
|
194
|
+
const m = item.model;
|
|
195
|
+
const apiFormat: ApiFormat = m.apiFormat === 'anthropic' ? 'anthropic' : 'openai';
|
|
196
|
+
const baseURL = m.baseURL?.trim();
|
|
197
|
+
const modelId = m.model?.trim();
|
|
198
|
+
const apiKey = m.apiKey?.trim();
|
|
199
|
+
if (!baseURL || !modelId || !apiKey) throw new Error('模型缺少 Base URL、模型 ID 或 API Key');
|
|
200
|
+
out.push({
|
|
201
|
+
id: randomUUID(),
|
|
202
|
+
apiFormat,
|
|
203
|
+
...(m.displayName?.trim() ? { displayName: m.displayName.trim() } : {}),
|
|
204
|
+
baseURL,
|
|
205
|
+
apiKey,
|
|
206
|
+
model: modelId,
|
|
207
|
+
contextWindow: m.contextWindow && m.contextWindow > 0 ? m.contextWindow : DEFAULT_CONTEXT_WINDOW,
|
|
208
|
+
...(m.maxTokens ? { maxTokens: m.maxTokens } : {}),
|
|
209
|
+
supportsVision: m.supportsVision !== false,
|
|
210
|
+
promptCache: m.promptCache ?? { mode: 'auto' },
|
|
211
|
+
enabled: m.enabled ?? true,
|
|
212
|
+
createdAt: now,
|
|
213
|
+
updatedAt: now,
|
|
214
|
+
});
|
|
215
|
+
} else if (item.op === 'update') {
|
|
216
|
+
const index = out.findIndex((entry) => entry.id === item.id);
|
|
217
|
+
if (index === -1) throw new Error('要修改的模型不存在(可能已被删除)');
|
|
218
|
+
const existing = out[index]!;
|
|
219
|
+
const patch = item.patch;
|
|
220
|
+
const next: ModelConfig = {
|
|
221
|
+
...existing,
|
|
222
|
+
...(patch.apiFormat ? { apiFormat: patch.apiFormat === 'anthropic' ? 'anthropic' : 'openai' } : {}),
|
|
223
|
+
...(patch.displayName !== undefined ? { displayName: patch.displayName.trim() || undefined } : {}),
|
|
224
|
+
...(patch.baseURL?.trim() ? { baseURL: patch.baseURL.trim() } : {}),
|
|
225
|
+
...(patch.model?.trim() ? { model: patch.model.trim() } : {}),
|
|
226
|
+
...(patch.contextWindow ? { contextWindow: patch.contextWindow } : {}),
|
|
227
|
+
...(patch.maxTokens !== undefined ? { maxTokens: patch.maxTokens || undefined } : {}),
|
|
228
|
+
...(patch.supportsVision !== undefined ? { supportsVision: patch.supportsVision !== false } : {}),
|
|
229
|
+
...(patch.promptCache ? { promptCache: patch.promptCache } : {}),
|
|
230
|
+
...(patch.enabled !== undefined ? { enabled: patch.enabled } : {}),
|
|
231
|
+
updatedAt: now,
|
|
232
|
+
};
|
|
233
|
+
if (patch.apiKey?.trim()) next.apiKey = patch.apiKey.trim();
|
|
234
|
+
if (patch.clearApiKey) next.apiKey = '';
|
|
235
|
+
out[index] = next;
|
|
236
|
+
} else {
|
|
237
|
+
out = out.filter((entry) => entry.id !== item.id);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function applyConfigPatch(base: MinimalAgentConfig | null, patch: ConfigPatch): Omit<MinimalAgentConfig, 'version' | 'savedAt'> {
|
|
244
|
+
const wasEmpty = (base?.models.length ?? 0) === 0 && (base?.baseModelId ?? null) === null;
|
|
245
|
+
let models = base?.models ?? [];
|
|
246
|
+
let baseModelId = base?.baseModelId ?? null;
|
|
247
|
+
|
|
248
|
+
if (patch.models?.length) models = applyModelsPatch(models, patch.models);
|
|
249
|
+
|
|
250
|
+
// 全新安装加第一个模型时自动设为基座——否则用户加完模型还是没法聊天。
|
|
251
|
+
if (wasEmpty && baseModelId === null && models.length > 0) baseModelId = models[0]!.id;
|
|
252
|
+
|
|
253
|
+
if (patch.baseModelId !== undefined) {
|
|
254
|
+
if (patch.baseModelId !== null && !models.some((entry) => entry.id === patch.baseModelId)) {
|
|
255
|
+
throw new Error('要设为基座的模型不存在');
|
|
256
|
+
}
|
|
257
|
+
baseModelId = patch.baseModelId;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 不变量:禁止删除/禁用当前基座模型指向的条目(先设别的为基座)。
|
|
261
|
+
if (baseModelId !== null) {
|
|
262
|
+
const baseEntry = models.find((entry) => entry.id === baseModelId);
|
|
263
|
+
if (!baseEntry) throw new Error('当前基座模型已被删除,请先设置其他模型为基座');
|
|
264
|
+
if (baseEntry.enabled === false) throw new Error('不能禁用当前基座模型,请先设置其他模型为基座');
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
let advisor = base?.advisor;
|
|
268
|
+
if (patch.advisor) {
|
|
269
|
+
if (patch.advisor.clear) {
|
|
270
|
+
advisor = undefined;
|
|
271
|
+
} else {
|
|
272
|
+
advisor = {
|
|
273
|
+
enabled: patch.advisor.enabled ?? advisor?.enabled ?? true,
|
|
274
|
+
mode: patch.advisor.mode ?? advisor?.mode ?? 'auto',
|
|
275
|
+
modelId: patch.advisor.modelId !== undefined ? patch.advisor.modelId : (advisor?.modelId ?? null),
|
|
276
|
+
contextPolicy: 'full-relevant',
|
|
277
|
+
shareSensitive: patch.advisor.shareSensitive ?? advisor?.shareSensitive ?? false,
|
|
278
|
+
inputTokenBudget: normalizeLimited(
|
|
279
|
+
patch.advisor.inputTokenBudget ?? advisor?.inputTokenBudget,
|
|
280
|
+
CONFIG_LIMITS.advisorInputTokenBudget, 128_000),
|
|
281
|
+
timeoutMs: normalizeLimited(
|
|
282
|
+
patch.advisor.timeoutMs ?? advisor?.timeoutMs,
|
|
283
|
+
CONFIG_LIMITS.advisorTimeoutMs, 180_000),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// 顾问引用的模型若已被删除或禁用,级联置空(软失联——解析层已把 null/悬空 id 当
|
|
288
|
+
// 「未配置」优雅处理,不留死链接;这与基座模型的硬阻止是刻意的不对称:顾问本来就是
|
|
289
|
+
// 可降级的第二意见,不像基座那样「没有就整个应用跑不起来」)。
|
|
290
|
+
if (advisor?.modelId) {
|
|
291
|
+
const referenced = models.find((entry) => entry.id === advisor!.modelId);
|
|
292
|
+
if (!referenced || referenced.enabled === false) advisor = { ...advisor, modelId: null };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 比例类:保留 4 位小数(= 百分比 2 位),否则 UI 上下箭头按 0.01 步进会累加出
|
|
296
|
+
// `0.8500000000000001` 这种浮点脏值直接写进 config.json。
|
|
297
|
+
const compactRatio = patch.compactRatio !== undefined
|
|
298
|
+
? (patch.compactRatio > 0 && patch.compactRatio <= 1
|
|
299
|
+
? normalizeLimited(patch.compactRatio, CONFIG_LIMITS.compactRatio, CONFIG_LIMITS.compactRatio.max)
|
|
300
|
+
: undefined)
|
|
301
|
+
: base?.compactRatio;
|
|
302
|
+
|
|
303
|
+
const tools: ToolConfigs = { ...(base?.tools ?? {}) };
|
|
304
|
+
const drafts = structuredClone(base?.drafts ?? {});
|
|
305
|
+
const toolPatch = patch.tools;
|
|
306
|
+
if (toolPatch?.webSearch) {
|
|
307
|
+
if (toolPatch.webSearch.clear) { delete tools.webSearch; delete drafts.tools?.webSearch; }
|
|
308
|
+
else tools.webSearch = mergeRecord(tools.webSearch, { provider: 'tavily', ...toolPatch.webSearch }) as ToolConfigs['webSearch'];
|
|
309
|
+
}
|
|
310
|
+
if (toolPatch?.imageGeneration) {
|
|
311
|
+
if (toolPatch.imageGeneration.clear) { delete tools.imageGeneration; delete drafts.tools?.imageGeneration; }
|
|
312
|
+
else {
|
|
313
|
+
const next = mergeRecord(tools.imageGeneration, toolPatch.imageGeneration) as NonNullable<ToolConfigs['imageGeneration']>;
|
|
314
|
+
if (toolPatch.imageGeneration.clearApiKey) next.apiKey = '';
|
|
315
|
+
delete (next as typeof next & { clear?: boolean; clearApiKey?: boolean }).clear;
|
|
316
|
+
delete (next as typeof next & { clear?: boolean; clearApiKey?: boolean }).clearApiKey;
|
|
317
|
+
if (!next.baseURL || !next.apiKey || !next.model) throw new Error('图片生成缺少 Base URL、API Key 或模型名称');
|
|
318
|
+
tools.imageGeneration = next;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (toolPatch?.openRouter) {
|
|
322
|
+
if (toolPatch.openRouter.clear) { delete tools.openRouter; delete drafts.tools?.openRouter; }
|
|
323
|
+
else tools.openRouter = mergeRecord(tools.openRouter, toolPatch.openRouter) as ToolConfigs['openRouter'];
|
|
324
|
+
}
|
|
325
|
+
if (toolPatch?.textToSpeech) {
|
|
326
|
+
if (toolPatch.textToSpeech.clear) { delete tools.textToSpeech; delete drafts.tools?.textToSpeech; }
|
|
327
|
+
else {
|
|
328
|
+
const next = mergeRecord(tools.textToSpeech, { provider: 'minimax', ...toolPatch.textToSpeech }) as NonNullable<ToolConfigs['textToSpeech']>;
|
|
329
|
+
if (toolPatch.textToSpeech.clearApiKey) next.apiKey = '';
|
|
330
|
+
delete (next as typeof next & { clear?: boolean; clearApiKey?: boolean }).clear;
|
|
331
|
+
delete (next as typeof next & { clear?: boolean; clearApiKey?: boolean }).clearApiKey;
|
|
332
|
+
if (!next.apiKey || !next.groupId) throw new Error('MiniMax 语音缺少 API Key 或 Group ID');
|
|
333
|
+
tools.textToSpeech = next;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// 数字字段必须在**写入时**就按同一份边界规整——此前这里是裸 spread,读回时才被
|
|
337
|
+
// parseSubagents 的边界收窄,于是「存进去 300、读出来 100」,UI 表现成静默变回原值。
|
|
338
|
+
const mergedSubagents = { ...(base?.subagents ?? DEFAULT_SUBAGENTS_CONFIG), ...(patch.subagents ?? {}) };
|
|
339
|
+
const subagents: SubagentsConfig = {
|
|
340
|
+
...mergedSubagents,
|
|
341
|
+
maxCallsPerTurn: normalizeLimited(mergedSubagents.maxCallsPerTurn, CONFIG_LIMITS.subagentMaxCallsPerTurn, DEFAULT_SUBAGENTS_CONFIG.maxCallsPerTurn),
|
|
342
|
+
maxConcurrent: normalizeLimited(mergedSubagents.maxConcurrent, CONFIG_LIMITS.subagentMaxConcurrent, DEFAULT_SUBAGENTS_CONFIG.maxConcurrent),
|
|
343
|
+
timeoutMs: normalizeLimited(mergedSubagents.timeoutMs, CONFIG_LIMITS.subagentTimeoutMs, DEFAULT_SUBAGENTS_CONFIG.timeoutMs),
|
|
344
|
+
exploreMaxTurns: normalizeLimited(mergedSubagents.exploreMaxTurns, CONFIG_LIMITS.subagentExploreMaxTurns, DEFAULT_SUBAGENTS_CONFIG.exploreMaxTurns),
|
|
345
|
+
generalMaxTurns: normalizeLimited(mergedSubagents.generalMaxTurns, CONFIG_LIMITS.subagentGeneralMaxTurns, DEFAULT_SUBAGENTS_CONFIG.generalMaxTurns),
|
|
346
|
+
};
|
|
347
|
+
const browser: BrowserConfig = { ...(base?.browser ?? DEFAULT_BROWSER_CONFIG), ...(patch.browser ?? {}), profileId: 'default' };
|
|
348
|
+
const computerUse: ComputerUseConfig = {
|
|
349
|
+
...(base?.computerUse ?? DEFAULT_COMPUTER_USE_CONFIG),
|
|
350
|
+
...(patch.computerUse ?? {}),
|
|
351
|
+
};
|
|
352
|
+
computerUse.observationFrames = 1;
|
|
353
|
+
computerUse.maxImagePixels = normalizeLimited(
|
|
354
|
+
computerUse.maxImagePixels, CONFIG_LIMITS.computerUseMaxImagePixels, DEFAULT_COMPUTER_USE_CONFIG.maxImagePixels);
|
|
355
|
+
if (!hasEntries(drafts.tools)) delete drafts.tools;
|
|
356
|
+
return { models, baseModelId, ...(compactRatio !== undefined ? { compactRatio } : {}), advisor, subagents, browser, computerUse, tools, ...(hasEntries(drafts) ? { drafts } : {}) };
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** 仅不完整工具凭据使用草稿桶;其余设置都通过 patch 立即生效。 */
|
|
360
|
+
export type AutosaveSection = 'tools';
|
|
361
|
+
export type AutosaveState = 'applied' | 'draft';
|
|
362
|
+
|
|
363
|
+
export class ConfigService {
|
|
364
|
+
private snapshot: ConfigSnapshot = { source: 'none', readOnly: false, config: null, revision: 0 };
|
|
365
|
+
|
|
366
|
+
get revision(): number { return this.snapshot.revision; }
|
|
367
|
+
|
|
368
|
+
async reload(): Promise<ConfigSnapshot> {
|
|
369
|
+
const envOnly = process.env.MINIMAL_AGENT_CONFIG_MODE === 'env';
|
|
370
|
+
const json = envOnly ? null : await readMinimalAgentConfig();
|
|
371
|
+
const env = configFromEnv();
|
|
372
|
+
const next: Omit<ConfigSnapshot, 'revision'> = {
|
|
373
|
+
source: json ? 'json' : env ? 'environment' : 'none',
|
|
374
|
+
readOnly: envOnly,
|
|
375
|
+
config: json ?? env,
|
|
376
|
+
};
|
|
377
|
+
const changed = this.snapshot.revision === 0
|
|
378
|
+
|| this.snapshot.source !== next.source
|
|
379
|
+
|| this.snapshot.readOnly !== next.readOnly
|
|
380
|
+
|| JSON.stringify(this.snapshot.config) !== JSON.stringify(next.config);
|
|
381
|
+
this.snapshot = { ...next, revision: changed ? this.snapshot.revision + 1 : this.snapshot.revision };
|
|
382
|
+
return this.getSnapshot();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async getSnapshot(): Promise<ConfigSnapshot> {
|
|
386
|
+
if (this.snapshot.revision === 0) await this.reload();
|
|
387
|
+
return structuredClone(this.snapshot);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
async provider(): Promise<Provider | null> {
|
|
391
|
+
const { config } = await this.getSnapshot();
|
|
392
|
+
const entry = config?.models.find((m) => m.id === config.baseModelId);
|
|
393
|
+
if (!entry?.apiKey) return null;
|
|
394
|
+
return resolveProvider(entry, config?.compactRatio);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async providerForModel(modelId?: string | null): Promise<Provider | null> {
|
|
398
|
+
if (!modelId) return this.provider();
|
|
399
|
+
const { config } = await this.getSnapshot();
|
|
400
|
+
const entry = config?.models.find((m) => m.id === modelId);
|
|
401
|
+
if (!entry?.apiKey) return null;
|
|
402
|
+
return resolveProvider(entry, config?.compactRatio);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** 带 apiKey 的原始列表——仅服务端内部消费(桌面端 store.ts 的 readConfig() 会脱敏成 ModelView)。 */
|
|
406
|
+
async models(): Promise<ModelConfig[]> {
|
|
407
|
+
return (await this.getSnapshot()).config?.models ?? [];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
async model(id: string): Promise<ModelConfig | null> {
|
|
411
|
+
return (await this.getSnapshot()).config?.models.find((entry) => entry.id === id) ?? null;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* 保留「未启用但已配置」和「完全未配置」两种返回值的区分——advisor.ts 的两条不同报错
|
|
416
|
+
* 文案依赖这个区分,所以只按 modelId+对应条目 apiKey 是否非空判定可解析性,不掺 .enabled。
|
|
417
|
+
*
|
|
418
|
+
* `supportsVision` 现在是模型条目的属性(不再是顾问自己的行为字段),这里从所引用的
|
|
419
|
+
* ModelConfig 镜像到返回对象顶层,让 advisor.ts 的 `advisor.supportsVision` 读取方式
|
|
420
|
+
* 保持不变——它是解析后的便利视图,不是存储形状本身。
|
|
421
|
+
*/
|
|
422
|
+
async advisor(): Promise<(AdvisorConfig & { provider: Provider; supportsVision: boolean }) | null> {
|
|
423
|
+
// fresh reload(不用 getSnapshot 的缓存)——CLI/TUI/Desktop/Cron 共享同一份 config.json,
|
|
424
|
+
// 跨进程时缓存会读到过期状态(如 A 进程 /advisor off 后 B 进程仍判定已启用)。这条不变量
|
|
425
|
+
// 由 test/configService.test.ts 的 "advisor() always does a fresh reload" 用例锁定。
|
|
426
|
+
const { config } = await this.reload();
|
|
427
|
+
const advisor = config?.advisor;
|
|
428
|
+
if (!advisor?.modelId) return null;
|
|
429
|
+
const entry = config!.models.find((m) => m.id === advisor.modelId);
|
|
430
|
+
if (!entry?.apiKey) return null;
|
|
431
|
+
return { ...advisor, provider: resolveProvider(entry), supportsVision: entry.supportsVision !== false };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
async subagents(): Promise<SubagentsConfig> {
|
|
435
|
+
return (await this.reload()).config?.subagents ?? DEFAULT_SUBAGENTS_CONFIG;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async browser(): Promise<BrowserConfig> {
|
|
439
|
+
return (await this.reload()).config?.browser ?? DEFAULT_BROWSER_CONFIG;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
async computerUse(): Promise<ComputerUseConfig> {
|
|
443
|
+
return (await this.reload()).config?.computerUse ?? DEFAULT_COMPUTER_USE_CONFIG;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async tool<K extends ToolConfigKey>(key: K): Promise<ToolConfigs[K]> {
|
|
447
|
+
return (await this.reload()).config?.tools[key];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async toolStatus(): Promise<Record<ToolConfigKey, ToolStatus>> {
|
|
451
|
+
const tools = (await this.reload()).config?.tools ?? {};
|
|
452
|
+
return {
|
|
453
|
+
webSearch: { state: tools.webSearch ? 'configured' : 'unconfigured', configured: !!tools.webSearch },
|
|
454
|
+
imageGeneration: { state: tools.imageGeneration ? 'configured' : 'unconfigured', configured: !!tools.imageGeneration },
|
|
455
|
+
openRouter: { state: tools.openRouter ? 'configured' : 'unconfigured', configured: !!tools.openRouter },
|
|
456
|
+
textToSpeech: { state: tools.textToSpeech ? 'configured' : 'unconfigured', configured: !!tools.textToSpeech },
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
async savePatch(patch: ConfigPatch): Promise<ConfigSnapshot> {
|
|
461
|
+
const current = await this.getSnapshot();
|
|
462
|
+
if (current.readOnly) throw new Error('当前使用环境变量只读配置,不能从设置页修改');
|
|
463
|
+
await updateMinimalAgentConfig((latest) => applyConfigPatch(latest ?? current.config, patch));
|
|
464
|
+
return this.reload();
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/** 现在只服务 tools 分区的实时录入表单(imageGeneration/textToSpeech 多字段、可能中途非法)。 */
|
|
468
|
+
async autosave(section: AutosaveSection, patch: ConfigPatch): Promise<{ snapshot: ConfigSnapshot; state: AutosaveState; draftFields: string[] }> {
|
|
469
|
+
void section;
|
|
470
|
+
const current = await this.getSnapshot();
|
|
471
|
+
if (current.readOnly) throw new Error('当前使用环境变量只读配置,不能从设置页修改');
|
|
472
|
+
if (!current.config) throw new Error('请先添加至少一个模型');
|
|
473
|
+
let state: AutosaveState = 'applied';
|
|
474
|
+
const draftFields: string[] = [];
|
|
475
|
+
await updateMinimalAgentConfig((latest) => {
|
|
476
|
+
let active = latest ?? current.config!;
|
|
477
|
+
if (patch.subagents) active = { version: 4, ...applyConfigPatch(active, { subagents: patch.subagents }), savedAt: active.savedAt };
|
|
478
|
+
if (patch.computerUse) active = { version: 4, ...applyConfigPatch(active, { computerUse: patch.computerUse }), savedAt: active.savedAt };
|
|
479
|
+
const drafts = structuredClone(active.drafts ?? {});
|
|
480
|
+
for (const key of Object.keys(patch.tools ?? {})) {
|
|
481
|
+
const rawPiece = patch.tools![key as keyof NonNullable<ConfigPatch['tools']>];
|
|
482
|
+
if (!rawPiece) continue;
|
|
483
|
+
const previous = (drafts.tools ?? {})[key];
|
|
484
|
+
const merged = mergeRecord(previous, rawPiece as Record<string, unknown>);
|
|
485
|
+
try {
|
|
486
|
+
active = { version: 4, ...applyConfigPatch(active, { tools: { [key]: merged } as ConfigPatch['tools'] }), savedAt: active.savedAt };
|
|
487
|
+
delete drafts.tools?.[key];
|
|
488
|
+
} catch {
|
|
489
|
+
state = 'draft';
|
|
490
|
+
draftFields.push(key);
|
|
491
|
+
(drafts.tools ??= {})[key] = merged;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (!hasEntries(drafts.tools)) delete drafts.tools;
|
|
495
|
+
return {
|
|
496
|
+
models: active.models, baseModelId: active.baseModelId,
|
|
497
|
+
...(active.compactRatio !== undefined ? { compactRatio: active.compactRatio } : {}),
|
|
498
|
+
advisor: active.advisor, subagents: active.subagents, browser: active.browser,
|
|
499
|
+
computerUse: active.computerUse, tools: active.tools,
|
|
500
|
+
...(hasEntries(drafts) ? { drafts } : {}),
|
|
501
|
+
};
|
|
502
|
+
});
|
|
503
|
+
return { snapshot: await this.reload(), state, draftFields };
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export const configService = new ConfigService();
|
|
508
|
+
|
|
509
|
+
export const SENSITIVE_ENV_KEYS = new Set([
|
|
510
|
+
'MINIMAL_AGENT_API_KEY', 'TAVILY_API_KEY', 'OPENAI_IMAGE_API_KEY',
|
|
511
|
+
'OPENROUTER_API_KEY', 'MINIMAX_API_KEY', 'MINIMAX_GROUP_ID',
|
|
512
|
+
]);
|
|
513
|
+
|
|
514
|
+
/** Child processes inherit normal runtime variables, never model or tool credentials. */
|
|
515
|
+
export function sanitizeCredentialEnv(source: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
|
|
516
|
+
const env: NodeJS.ProcessEnv = { ...source };
|
|
517
|
+
for (const key of SENSITIVE_ENV_KEYS) delete env[key];
|
|
518
|
+
return env;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export async function trustedToolEnv(
|
|
522
|
+
kind: 'imageGeneration' | 'openRouter' | 'textToSpeech',
|
|
523
|
+
service: ConfigService = configService,
|
|
524
|
+
): Promise<NodeJS.ProcessEnv> {
|
|
525
|
+
const env = sanitizeCredentialEnv();
|
|
526
|
+
if (kind === 'imageGeneration') {
|
|
527
|
+
let cfg = await service.tool('imageGeneration');
|
|
528
|
+
if (!cfg) {
|
|
529
|
+
const openRouter = await service.tool('openRouter');
|
|
530
|
+
if (openRouter) cfg = {
|
|
531
|
+
provider: 'openrouter',
|
|
532
|
+
baseURL: 'https://openrouter.ai/api/v1',
|
|
533
|
+
apiKey: openRouter.apiKey,
|
|
534
|
+
model: 'google/gemini-3-pro-image-preview',
|
|
535
|
+
protocol: 'chat',
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
if (cfg) {
|
|
539
|
+
env.OPENAI_IMAGE_PROVIDER = cfg.provider;
|
|
540
|
+
env.OPENAI_IMAGE_BASE_URL = cfg.baseURL;
|
|
541
|
+
env.OPENAI_IMAGE_API_KEY = cfg.apiKey;
|
|
542
|
+
env.OPENAI_IMAGE_MODEL = cfg.model;
|
|
543
|
+
if (cfg.protocol && cfg.protocol !== 'auto') env.OPENAI_IMAGE_PROTOCOL = cfg.protocol;
|
|
544
|
+
else delete env.OPENAI_IMAGE_PROTOCOL;
|
|
545
|
+
}
|
|
546
|
+
} else if (kind === 'openRouter') {
|
|
547
|
+
const cfg = await service.tool('openRouter');
|
|
548
|
+
if (cfg) env.OPENROUTER_API_KEY = cfg.apiKey;
|
|
549
|
+
} else {
|
|
550
|
+
const cfg = await service.tool('textToSpeech');
|
|
551
|
+
if (cfg) { env.MINIMAX_API_KEY = cfg.apiKey; env.MINIMAX_GROUP_ID = cfg.groupId; }
|
|
552
|
+
}
|
|
553
|
+
return env;
|
|
554
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置里每一个「数字输入」的边界与取值语义——**唯一真值**。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有这个文件(真实事故):同一个数字此前在**三层各写一份**互不相同的边界——
|
|
5
|
+
* 前端 input 的 `min/max/step`、写入时 `applyConfigPatch` 的 clamp、读回时
|
|
6
|
+
* `parseAdvisor/parseSubagents` 的 `boundedNumber`。三份一旦不一致,用户在设置页输入
|
|
7
|
+
* 一个「前端允许、后端不允许」的值,回车/失焦后会**静默变回原值**:前端没报错(它认为
|
|
8
|
+
* 合法),后端也没报错(它认为自己只是在纠偏),中间没有任何提示。顾问「输入预算」被
|
|
9
|
+
* 死钉在 128000 就是这么来的——用户的顾问模型是 90 万上下文窗口,却怎么改都跳回 12.8 万。
|
|
10
|
+
*
|
|
11
|
+
* 因此:**边界只准在这里声明**,minimal-agent 的读/写两层与 minimal-desktop 的设置页
|
|
12
|
+
* 全部 import 这里。前端 clamp 后再提交,后端再 clamp 一次兜底——两次 clamp 结果必然
|
|
13
|
+
* 相同,用户看到的值就是存下来的值。
|
|
14
|
+
*
|
|
15
|
+
* 单位约定:这里的边界一律用**存储单位**(毫秒 / 比例 / 绝对个数)。UI 若按秒/分钟/
|
|
16
|
+
* 百分比展示,自己换算(见 minimal-desktop `NumberInput`),不在这里再开一份显示单位的
|
|
17
|
+
* 边界,否则又回到多份真值。
|
|
18
|
+
*/
|
|
19
|
+
export const CONFIG_LIMITS = {
|
|
20
|
+
/** 顾问单次咨询喂进去的输入 token 上限。上界给到 200 万是为了容纳百万级上下文模型;
|
|
21
|
+
* 真正生效值还会再被「所选顾问模型的 contextWindow」二次收窄(见 advisor.ts)。 */
|
|
22
|
+
advisorInputTokenBudget: { min: 1_000, max: 2_000_000, step: 1_000, kind: 'integer' },
|
|
23
|
+
/** 顾问单次咨询的最长等待(毫秒)。重思考模型 + 大上下文可以跑很久,上界给到 10 分钟。 */
|
|
24
|
+
advisorTimeoutMs: { min: 5_000, max: 600_000, step: 5_000, kind: 'integer' },
|
|
25
|
+
/** 单个回合内最多派生几个子任务。 */
|
|
26
|
+
subagentMaxCallsPerTurn: { min: 1, max: 50, step: 1, kind: 'integer' },
|
|
27
|
+
/** 子任务并发上限。 */
|
|
28
|
+
subagentMaxConcurrent: { min: 1, max: 20, step: 1, kind: 'integer' },
|
|
29
|
+
/** 单个子任务的总时长兜底(毫秒),上界 2 小时。 */
|
|
30
|
+
subagentTimeoutMs: { min: 60_000, max: 7_200_000, step: 60_000, kind: 'integer' },
|
|
31
|
+
/** explore(只读调研)子任务的轮数上限。 */
|
|
32
|
+
subagentExploreMaxTurns: { min: 5, max: 500, step: 5, kind: 'integer' },
|
|
33
|
+
/** general(读写执行)子任务的轮数上限。 */
|
|
34
|
+
subagentGeneralMaxTurns: { min: 10, max: 1_000, step: 10, kind: 'integer' },
|
|
35
|
+
/** 电脑操作每帧画面的像素预算。 */
|
|
36
|
+
computerUseMaxImagePixels: { min: 100_000, max: 10_000_000, step: 100_000, kind: 'integer' },
|
|
37
|
+
/** 自动压缩触发阈值,占 contextWindow 的比例(0,1]。UI 按百分比展示,保留 2 位小数。 */
|
|
38
|
+
compactRatio: { min: 0.01, max: 1, step: 0.01, kind: 'ratio' },
|
|
39
|
+
/** 模型条目的上下文窗口。 */
|
|
40
|
+
modelContextWindow: { min: 1_000, max: 20_000_000, step: 1_000, kind: 'integer' },
|
|
41
|
+
/** 模型条目的单次输出上限(可留空 = 用公式推荐值,故 UI 允许空串,这里只约束填了值的情况)。 */
|
|
42
|
+
modelMaxTokens: { min: 256, max: 1_000_000, step: 256, kind: 'integer' },
|
|
43
|
+
};
|
|
44
|
+
/** 比例类字段保留的小数位(4 位比例 = 2 位百分比)。 */
|
|
45
|
+
const RATIO_DECIMALS = 4;
|
|
46
|
+
/**
|
|
47
|
+
* 把任意输入规整成该字段合法的存储值:非法/空 → fallback;整数类四舍五入;
|
|
48
|
+
* 比例类保留 4 位小数(否则 `0.85` 会被步进累加成 `0.8500000000000001` 存进 config.json)。
|
|
49
|
+
* 最后按 min/max 收口。
|
|
50
|
+
*/
|
|
51
|
+
export function normalizeLimited(value, limit, fallback) {
|
|
52
|
+
const raw = typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
53
|
+
const rounded = limit.kind === 'integer'
|
|
54
|
+
? Math.round(raw)
|
|
55
|
+
: Number(raw.toFixed(RATIO_DECIMALS));
|
|
56
|
+
return Math.min(limit.max, Math.max(limit.min, rounded));
|
|
57
|
+
}
|
|
58
|
+
/** 判断一个值是否已经落在合法范围内(UI 用来决定要不要提示「已自动调整」)。 */
|
|
59
|
+
export function withinLimit(value, limit) {
|
|
60
|
+
return Number.isFinite(value) && value >= limit.min && value <= limit.max;
|
|
61
|
+
}
|