turboflux 1.0.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/LICENSE +21 -0
- package/README.md +177 -0
- package/bin/turboflux.mjs +28 -0
- package/dist/cli/brand.d.ts +7 -0
- package/dist/cli/brand.js +33 -0
- package/dist/cli/brand.js.map +1 -0
- package/dist/cli/commands/index.d.ts +4 -0
- package/dist/cli/commands/index.js +671 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/registry.d.ts +24 -0
- package/dist/cli/commands/registry.js +124 -0
- package/dist/cli/commands/registry.js.map +1 -0
- package/dist/cli/commands/types.d.ts +69 -0
- package/dist/cli/commands/types.js +2 -0
- package/dist/cli/commands/types.js.map +1 -0
- package/dist/cli/components/App.d.ts +15 -0
- package/dist/cli/components/App.js +1738 -0
- package/dist/cli/components/App.js.map +1 -0
- package/dist/cli/components/ConversationHistory.d.ts +15 -0
- package/dist/cli/components/ConversationHistory.js +92 -0
- package/dist/cli/components/ConversationHistory.js.map +1 -0
- package/dist/cli/components/TranscriptViewport.d.ts +25 -0
- package/dist/cli/components/TranscriptViewport.js +77 -0
- package/dist/cli/components/TranscriptViewport.js.map +1 -0
- package/dist/cli/components/agentActivityModel.d.ts +24 -0
- package/dist/cli/components/agentActivityModel.js +45 -0
- package/dist/cli/components/agentActivityModel.js.map +1 -0
- package/dist/cli/components/appHelpers.d.ts +34 -0
- package/dist/cli/components/appHelpers.js +209 -0
- package/dist/cli/components/appHelpers.js.map +1 -0
- package/dist/cli/components/design-system/StatusIcon.d.ts +5 -0
- package/dist/cli/components/design-system/StatusIcon.js +25 -0
- package/dist/cli/components/design-system/StatusIcon.js.map +1 -0
- package/dist/cli/components/developerFlowModel.d.ts +36 -0
- package/dist/cli/components/developerFlowModel.js +88 -0
- package/dist/cli/components/developerFlowModel.js.map +1 -0
- package/dist/cli/components/diff/DiffCard.d.ts +16 -0
- package/dist/cli/components/diff/DiffCard.js +30 -0
- package/dist/cli/components/diff/DiffCard.js.map +1 -0
- package/dist/cli/components/diff/DiffHunks.d.ts +11 -0
- package/dist/cli/components/diff/DiffHunks.js +58 -0
- package/dist/cli/components/diff/DiffHunks.js.map +1 -0
- package/dist/cli/components/header/Header.d.ts +13 -0
- package/dist/cli/components/header/Header.js +25 -0
- package/dist/cli/components/header/Header.js.map +1 -0
- package/dist/cli/components/header/Mascot.d.ts +4 -0
- package/dist/cli/components/header/Mascot.js +53 -0
- package/dist/cli/components/header/Mascot.js.map +1 -0
- package/dist/cli/components/header/StatusLine.d.ts +21 -0
- package/dist/cli/components/header/StatusLine.js +110 -0
- package/dist/cli/components/header/StatusLine.js.map +1 -0
- package/dist/cli/components/input/EffortPicker.d.ts +30 -0
- package/dist/cli/components/input/EffortPicker.js +126 -0
- package/dist/cli/components/input/EffortPicker.js.map +1 -0
- package/dist/cli/components/input/ModelPicker.d.ts +15 -0
- package/dist/cli/components/input/ModelPicker.js +95 -0
- package/dist/cli/components/input/ModelPicker.js.map +1 -0
- package/dist/cli/components/input/PromptInput.d.ts +79 -0
- package/dist/cli/components/input/PromptInput.js +496 -0
- package/dist/cli/components/input/PromptInput.js.map +1 -0
- package/dist/cli/components/input/RewindSelector.d.ts +8 -0
- package/dist/cli/components/input/RewindSelector.js +45 -0
- package/dist/cli/components/input/RewindSelector.js.map +1 -0
- package/dist/cli/components/input/pasteState.d.ts +6 -0
- package/dist/cli/components/input/pasteState.js +42 -0
- package/dist/cli/components/input/pasteState.js.map +1 -0
- package/dist/cli/components/input/terminalInputStateMachine.d.ts +29 -0
- package/dist/cli/components/input/terminalInputStateMachine.js +67 -0
- package/dist/cli/components/input/terminalInputStateMachine.js.map +1 -0
- package/dist/cli/components/layout/CockpitRails.d.ts +6 -0
- package/dist/cli/components/layout/CockpitRails.js +13 -0
- package/dist/cli/components/layout/CockpitRails.js.map +1 -0
- package/dist/cli/components/layout/LandingView.d.ts +15 -0
- package/dist/cli/components/layout/LandingView.js +12 -0
- package/dist/cli/components/layout/LandingView.js.map +1 -0
- package/dist/cli/components/layout/SessionSidebar.d.ts +18 -0
- package/dist/cli/components/layout/SessionSidebar.js +70 -0
- package/dist/cli/components/layout/SessionSidebar.js.map +1 -0
- package/dist/cli/components/layout/StartupAnimation.d.ts +14 -0
- package/dist/cli/components/layout/StartupAnimation.js +30 -0
- package/dist/cli/components/layout/StartupAnimation.js.map +1 -0
- package/dist/cli/components/markdown/highlighter.d.ts +1 -0
- package/dist/cli/components/markdown/highlighter.js +110 -0
- package/dist/cli/components/markdown/highlighter.js.map +1 -0
- package/dist/cli/components/markdown/index.d.ts +11 -0
- package/dist/cli/components/markdown/index.js +86 -0
- package/dist/cli/components/markdown/index.js.map +1 -0
- package/dist/cli/components/messages/MessageList.d.ts +16 -0
- package/dist/cli/components/messages/MessageList.js +56 -0
- package/dist/cli/components/messages/MessageList.js.map +1 -0
- package/dist/cli/components/messages/Messages.d.ts +26 -0
- package/dist/cli/components/messages/Messages.js +32 -0
- package/dist/cli/components/messages/Messages.js.map +1 -0
- package/dist/cli/components/messages/ThinkingBlock.d.ts +9 -0
- package/dist/cli/components/messages/ThinkingBlock.js +51 -0
- package/dist/cli/components/messages/ThinkingBlock.js.map +1 -0
- package/dist/cli/components/messages/WindowedMessageList.d.ts +21 -0
- package/dist/cli/components/messages/WindowedMessageList.js +44 -0
- package/dist/cli/components/messages/WindowedMessageList.js.map +1 -0
- package/dist/cli/components/permissions/PermissionDialog.d.ts +23 -0
- package/dist/cli/components/permissions/PermissionDialog.js +83 -0
- package/dist/cli/components/permissions/PermissionDialog.js.map +1 -0
- package/dist/cli/components/spinner/SpinnerGlyph.d.ts +6 -0
- package/dist/cli/components/spinner/SpinnerGlyph.js +55 -0
- package/dist/cli/components/spinner/SpinnerGlyph.js.map +1 -0
- package/dist/cli/components/spinner/constants.d.ts +4 -0
- package/dist/cli/components/spinner/constants.js +5 -0
- package/dist/cli/components/spinner/constants.js.map +1 -0
- package/dist/cli/components/tools/ActiveWorkPanel.d.ts +22 -0
- package/dist/cli/components/tools/ActiveWorkPanel.js +70 -0
- package/dist/cli/components/tools/ActiveWorkPanel.js.map +1 -0
- package/dist/cli/components/tools/AgentActivityLine.d.ts +13 -0
- package/dist/cli/components/tools/AgentActivityLine.js +88 -0
- package/dist/cli/components/tools/AgentActivityLine.js.map +1 -0
- package/dist/cli/components/tools/QueuedPromptList.d.ts +10 -0
- package/dist/cli/components/tools/QueuedPromptList.js +26 -0
- package/dist/cli/components/tools/QueuedPromptList.js.map +1 -0
- package/dist/cli/components/tools/TaskFlowHud.d.ts +15 -0
- package/dist/cli/components/tools/TaskFlowHud.js +55 -0
- package/dist/cli/components/tools/TaskFlowHud.js.map +1 -0
- package/dist/cli/components/tools/TerminalSessionsFooter.d.ts +6 -0
- package/dist/cli/components/tools/TerminalSessionsFooter.js +36 -0
- package/dist/cli/components/tools/TerminalSessionsFooter.js.map +1 -0
- package/dist/cli/components/tools/ToolActivityList.d.ts +11 -0
- package/dist/cli/components/tools/ToolActivityList.js +73 -0
- package/dist/cli/components/tools/ToolActivityList.js.map +1 -0
- package/dist/cli/components/tools/ToolCallTree.d.ts +11 -0
- package/dist/cli/components/tools/ToolCallTree.js +14 -0
- package/dist/cli/components/tools/ToolCallTree.js.map +1 -0
- package/dist/cli/components/tools/toolLifecycleModel.d.ts +16 -0
- package/dist/cli/components/tools/toolLifecycleModel.js +30 -0
- package/dist/cli/components/tools/toolLifecycleModel.js.map +1 -0
- package/dist/cli/components/tools/toolPresentation.d.ts +9 -0
- package/dist/cli/components/tools/toolPresentation.js +171 -0
- package/dist/cli/components/tools/toolPresentation.js.map +1 -0
- package/dist/cli/components/tools/toolTypes.d.ts +16 -0
- package/dist/cli/components/tools/toolTypes.js +2 -0
- package/dist/cli/components/tools/toolTypes.js.map +1 -0
- package/dist/cli/components/transcriptWindowing.d.ts +19 -0
- package/dist/cli/components/transcriptWindowing.js +81 -0
- package/dist/cli/components/transcriptWindowing.js.map +1 -0
- package/dist/cli/config.d.ts +1 -0
- package/dist/cli/config.js +2 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/conversations/journalWriter.d.ts +50 -0
- package/dist/cli/conversations/journalWriter.js +191 -0
- package/dist/cli/conversations/journalWriter.js.map +1 -0
- package/dist/cli/conversations/manager.d.ts +65 -0
- package/dist/cli/conversations/manager.js +435 -0
- package/dist/cli/conversations/manager.js.map +1 -0
- package/dist/cli/conversations/recoveryExport.d.ts +18 -0
- package/dist/cli/conversations/recoveryExport.js +39 -0
- package/dist/cli/conversations/recoveryExport.js.map +1 -0
- package/dist/cli/conversations/recoveryMessages.d.ts +2 -0
- package/dist/cli/conversations/recoveryMessages.js +3 -0
- package/dist/cli/conversations/recoveryMessages.js.map +1 -0
- package/dist/cli/conversations/store.d.ts +14 -0
- package/dist/cli/conversations/store.js +603 -0
- package/dist/cli/conversations/store.js.map +1 -0
- package/dist/cli/conversations/types.d.ts +142 -0
- package/dist/cli/conversations/types.js +2 -0
- package/dist/cli/conversations/types.js.map +1 -0
- package/dist/cli/globalConfiguration.d.ts +13 -0
- package/dist/cli/globalConfiguration.js +61 -0
- package/dist/cli/globalConfiguration.js.map +1 -0
- package/dist/cli/hooks/useMessageCursor.d.ts +16 -0
- package/dist/cli/hooks/useMessageCursor.js +75 -0
- package/dist/cli/hooks/useMessageCursor.js.map +1 -0
- package/dist/cli/hooks/useOverlayStack.d.ts +9 -0
- package/dist/cli/hooks/useOverlayStack.js +26 -0
- package/dist/cli/hooks/useOverlayStack.js.map +1 -0
- package/dist/cli/hooks/useTerminalSize.d.ts +16 -0
- package/dist/cli/hooks/useTerminalSize.js +37 -0
- package/dist/cli/hooks/useTerminalSize.js.map +1 -0
- package/dist/cli/i18n/index.d.ts +15 -0
- package/dist/cli/i18n/index.js +32 -0
- package/dist/cli/i18n/index.js.map +1 -0
- package/dist/cli/i18n/messages.d.ts +1305 -0
- package/dist/cli/i18n/messages.js +1305 -0
- package/dist/cli/i18n/messages.js.map +1 -0
- package/dist/cli/imageAttachments.d.ts +22 -0
- package/dist/cli/imageAttachments.js +329 -0
- package/dist/cli/imageAttachments.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +146 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/platform/terminalAttention.d.ts +46 -0
- package/dist/cli/platform/terminalAttention.js +152 -0
- package/dist/cli/platform/terminalAttention.js.map +1 -0
- package/dist/cli/platform/terminalTransparency.d.ts +11 -0
- package/dist/cli/platform/terminalTransparency.js +193 -0
- package/dist/cli/platform/terminalTransparency.js.map +1 -0
- package/dist/cli/repl.d.ts +15 -0
- package/dist/cli/repl.js +38 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/cli/setup.d.ts +17 -0
- package/dist/cli/setup.js +991 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/singleShot.d.ts +30 -0
- package/dist/cli/singleShot.js +167 -0
- package/dist/cli/singleShot.js.map +1 -0
- package/dist/cli/state/adaptiveStreamScheduler.d.ts +53 -0
- package/dist/cli/state/adaptiveStreamScheduler.js +136 -0
- package/dist/cli/state/adaptiveStreamScheduler.js.map +1 -0
- package/dist/cli/state/agentFlowController.d.ts +37 -0
- package/dist/cli/state/agentFlowController.js +402 -0
- package/dist/cli/state/agentFlowController.js.map +1 -0
- package/dist/cli/state/approvalPresentationScheduler.d.ts +28 -0
- package/dist/cli/state/approvalPresentationScheduler.js +72 -0
- package/dist/cli/state/approvalPresentationScheduler.js.map +1 -0
- package/dist/cli/state/flowFeatureFlags.d.ts +18 -0
- package/dist/cli/state/flowFeatureFlags.js +45 -0
- package/dist/cli/state/flowFeatureFlags.js.map +1 -0
- package/dist/cli/state/flowReducer.d.ts +120 -0
- package/dist/cli/state/flowReducer.js +535 -0
- package/dist/cli/state/flowReducer.js.map +1 -0
- package/dist/cli/state/flowSelectors.d.ts +45 -0
- package/dist/cli/state/flowSelectors.js +144 -0
- package/dist/cli/state/flowSelectors.js.map +1 -0
- package/dist/cli/state/flowStore.d.ts +19 -0
- package/dist/cli/state/flowStore.js +51 -0
- package/dist/cli/state/flowStore.js.map +1 -0
- package/dist/cli/state/globalCommandActivity.d.ts +25 -0
- package/dist/cli/state/globalCommandActivity.js +57 -0
- package/dist/cli/state/globalCommandActivity.js.map +1 -0
- package/dist/cli/state/goldenTraces.d.ts +2 -0
- package/dist/cli/state/goldenTraces.js +15 -0
- package/dist/cli/state/goldenTraces.js.map +1 -0
- package/dist/cli/state/notificationCoordinator.d.ts +38 -0
- package/dist/cli/state/notificationCoordinator.js +101 -0
- package/dist/cli/state/notificationCoordinator.js.map +1 -0
- package/dist/cli/stateProvider.d.ts +5 -0
- package/dist/cli/stateProvider.js +7 -0
- package/dist/cli/stateProvider.js.map +1 -0
- package/dist/cli/telemetry/localFlowTelemetry.d.ts +42 -0
- package/dist/cli/telemetry/localFlowTelemetry.js +131 -0
- package/dist/cli/telemetry/localFlowTelemetry.js.map +1 -0
- package/dist/cli/telemetry/terminalBaseline.d.ts +93 -0
- package/dist/cli/telemetry/terminalBaseline.js +199 -0
- package/dist/cli/telemetry/terminalBaseline.js.map +1 -0
- package/dist/cli/telemetry/terminalLatencyTracker.d.ts +24 -0
- package/dist/cli/telemetry/terminalLatencyTracker.js +59 -0
- package/dist/cli/telemetry/terminalLatencyTracker.js.map +1 -0
- package/dist/cli/terminalLayout.d.ts +2 -0
- package/dist/cli/terminalLayout.js +16 -0
- package/dist/cli/terminalLayout.js.map +1 -0
- package/dist/cli/terminalMouse.d.ts +10 -0
- package/dist/cli/terminalMouse.js +29 -0
- package/dist/cli/terminalMouse.js.map +1 -0
- package/dist/cli/theme/ThemeProvider.d.ts +9 -0
- package/dist/cli/theme/ThemeProvider.js +26 -0
- package/dist/cli/theme/ThemeProvider.js.map +1 -0
- package/dist/cli/theme/dark.d.ts +2 -0
- package/dist/cli/theme/dark.js +27 -0
- package/dist/cli/theme/dark.js.map +1 -0
- package/dist/cli/theme/index.d.ts +5 -0
- package/dist/cli/theme/index.js +5 -0
- package/dist/cli/theme/index.js.map +1 -0
- package/dist/cli/theme/light.d.ts +2 -0
- package/dist/cli/theme/light.js +26 -0
- package/dist/cli/theme/light.js.map +1 -0
- package/dist/cli/theme/palette.d.ts +7 -0
- package/dist/cli/theme/palette.js +8 -0
- package/dist/cli/theme/palette.js.map +1 -0
- package/dist/cli/theme/resolveColor.d.ts +4 -0
- package/dist/cli/theme/resolveColor.js +43 -0
- package/dist/cli/theme/resolveColor.js.map +1 -0
- package/dist/cli/theme/types.d.ts +27 -0
- package/dist/cli/theme/types.js +2 -0
- package/dist/cli/theme/types.js.map +1 -0
- package/dist/cli/toolExecutor.d.ts +1 -0
- package/dist/cli/toolExecutor.js +2 -0
- package/dist/cli/toolExecutor.js.map +1 -0
- package/dist/core/agentEngine.d.ts +425 -0
- package/dist/core/agentEngine.js +5170 -0
- package/dist/core/agentEngine.js.map +1 -0
- package/dist/core/agents/loader.d.ts +9 -0
- package/dist/core/agents/loader.js +144 -0
- package/dist/core/agents/loader.js.map +1 -0
- package/dist/core/applyPatch.d.ts +24 -0
- package/dist/core/applyPatch.js +158 -0
- package/dist/core/applyPatch.js.map +1 -0
- package/dist/core/cacheMonitor.d.ts +24 -0
- package/dist/core/cacheMonitor.js +211 -0
- package/dist/core/cacheMonitor.js.map +1 -0
- package/dist/core/clientIdentity.d.ts +6 -0
- package/dist/core/clientIdentity.js +44 -0
- package/dist/core/clientIdentity.js.map +1 -0
- package/dist/core/config.d.ts +99 -0
- package/dist/core/config.js +715 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/contextCompaction.d.ts +20 -0
- package/dist/core/contextCompaction.js +158 -0
- package/dist/core/contextCompaction.js.map +1 -0
- package/dist/core/contextManager.d.ts +44 -0
- package/dist/core/contextManager.js +590 -0
- package/dist/core/contextManager.js.map +1 -0
- package/dist/core/contextPolicy.d.ts +18 -0
- package/dist/core/contextPolicy.js +39 -0
- package/dist/core/contextPolicy.js.map +1 -0
- package/dist/core/credentialStore.d.ts +8 -0
- package/dist/core/credentialStore.js +37 -0
- package/dist/core/credentialStore.js.map +1 -0
- package/dist/core/diffCompute.d.ts +31 -0
- package/dist/core/diffCompute.js +116 -0
- package/dist/core/diffCompute.js.map +1 -0
- package/dist/core/editHelpers.d.ts +8 -0
- package/dist/core/editHelpers.js +35 -0
- package/dist/core/editHelpers.js.map +1 -0
- package/dist/core/fileIO.d.ts +12 -0
- package/dist/core/fileIO.js +199 -0
- package/dist/core/fileIO.js.map +1 -0
- package/dist/core/gitService.d.ts +83 -0
- package/dist/core/gitService.js +522 -0
- package/dist/core/gitService.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +19 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/mcp/client.d.ts +32 -0
- package/dist/core/mcp/client.js +186 -0
- package/dist/core/mcp/client.js.map +1 -0
- package/dist/core/mcp/settings.d.ts +2 -0
- package/dist/core/mcp/settings.js +26 -0
- package/dist/core/mcp/settings.js.map +1 -0
- package/dist/core/mcp/toolBridge.d.ts +20 -0
- package/dist/core/mcp/toolBridge.js +74 -0
- package/dist/core/mcp/toolBridge.js.map +1 -0
- package/dist/core/mcp/types.d.ts +29 -0
- package/dist/core/mcp/types.js +2 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/modelDiscovery.d.ts +14 -0
- package/dist/core/modelDiscovery.js +566 -0
- package/dist/core/modelDiscovery.js.map +1 -0
- package/dist/core/modelProtocol.d.ts +43 -0
- package/dist/core/modelProtocol.js +238 -0
- package/dist/core/modelProtocol.js.map +1 -0
- package/dist/core/modelRegistry.d.ts +56 -0
- package/dist/core/modelRegistry.js +308 -0
- package/dist/core/modelRegistry.js.map +1 -0
- package/dist/core/networkProxy.d.ts +20 -0
- package/dist/core/networkProxy.js +145 -0
- package/dist/core/networkProxy.js.map +1 -0
- package/dist/core/normalizeBaseUrl.d.ts +1 -0
- package/dist/core/normalizeBaseUrl.js +9 -0
- package/dist/core/normalizeBaseUrl.js.map +1 -0
- package/dist/core/pathUtils.d.ts +3 -0
- package/dist/core/pathUtils.js +46 -0
- package/dist/core/pathUtils.js.map +1 -0
- package/dist/core/permissions.d.ts +29 -0
- package/dist/core/permissions.js +245 -0
- package/dist/core/permissions.js.map +1 -0
- package/dist/core/persona/voiceProfile.d.ts +7 -0
- package/dist/core/persona/voiceProfile.js +14 -0
- package/dist/core/persona/voiceProfile.js.map +1 -0
- package/dist/core/profile.d.ts +35 -0
- package/dist/core/profile.js +373 -0
- package/dist/core/profile.js.map +1 -0
- package/dist/core/requestCompatibility.d.ts +13 -0
- package/dist/core/requestCompatibility.js +181 -0
- package/dist/core/requestCompatibility.js.map +1 -0
- package/dist/core/runtime/agentRuntime.d.ts +43 -0
- package/dist/core/runtime/agentRuntime.js +137 -0
- package/dist/core/runtime/agentRuntime.js.map +1 -0
- package/dist/core/runtime/approvalCoordinator.d.ts +36 -0
- package/dist/core/runtime/approvalCoordinator.js +113 -0
- package/dist/core/runtime/approvalCoordinator.js.map +1 -0
- package/dist/core/runtime/capabilityBoundary.d.ts +18 -0
- package/dist/core/runtime/capabilityBoundary.js +89 -0
- package/dist/core/runtime/capabilityBoundary.js.map +1 -0
- package/dist/core/runtime/nodeToolExecutor.d.ts +200 -0
- package/dist/core/runtime/nodeToolExecutor.js +2446 -0
- package/dist/core/runtime/nodeToolExecutor.js.map +1 -0
- package/dist/core/runtime/runtimeLogWriter.d.ts +32 -0
- package/dist/core/runtime/runtimeLogWriter.js +129 -0
- package/dist/core/runtime/runtimeLogWriter.js.map +1 -0
- package/dist/core/runtime/runtimeTaskManager.d.ts +78 -0
- package/dist/core/runtime/runtimeTaskManager.js +374 -0
- package/dist/core/runtime/runtimeTaskManager.js.map +1 -0
- package/dist/core/runtime/sessionRegistry.d.ts +19 -0
- package/dist/core/runtime/sessionRegistry.js +41 -0
- package/dist/core/runtime/sessionRegistry.js.map +1 -0
- package/dist/core/runtime/stateProvider.d.ts +69 -0
- package/dist/core/runtime/stateProvider.js +131 -0
- package/dist/core/runtime/stateProvider.js.map +1 -0
- package/dist/core/runtime/subAgentTaskManager.d.ts +111 -0
- package/dist/core/runtime/subAgentTaskManager.js +386 -0
- package/dist/core/runtime/subAgentTaskManager.js.map +1 -0
- package/dist/core/schemaValidation.d.ts +5 -0
- package/dist/core/schemaValidation.js +153 -0
- package/dist/core/schemaValidation.js.map +1 -0
- package/dist/core/skills/loader.d.ts +7 -0
- package/dist/core/skills/loader.js +91 -0
- package/dist/core/skills/loader.js.map +1 -0
- package/dist/core/skills/runtime.d.ts +19 -0
- package/dist/core/skills/runtime.js +61 -0
- package/dist/core/skills/runtime.js.map +1 -0
- package/dist/core/subAgent.d.ts +50 -0
- package/dist/core/subAgent.js +1258 -0
- package/dist/core/subAgent.js.map +1 -0
- package/dist/core/systemPrompt.d.ts +27 -0
- package/dist/core/systemPrompt.js +219 -0
- package/dist/core/systemPrompt.js.map +1 -0
- package/dist/core/taskManager.d.ts +105 -0
- package/dist/core/taskManager.js +617 -0
- package/dist/core/taskManager.js.map +1 -0
- package/dist/core/tokenCompressor.d.ts +14 -0
- package/dist/core/tokenCompressor.js +161 -0
- package/dist/core/tokenCompressor.js.map +1 -0
- package/dist/core/tokenCounter.d.ts +28 -0
- package/dist/core/tokenCounter.js +101 -0
- package/dist/core/tokenCounter.js.map +1 -0
- package/dist/core/toolDispatcher.d.ts +11 -0
- package/dist/core/toolDispatcher.js +38 -0
- package/dist/core/toolDispatcher.js.map +1 -0
- package/dist/core/toolExecutionLedger.d.ts +9 -0
- package/dist/core/toolExecutionLedger.js +84 -0
- package/dist/core/toolExecutionLedger.js.map +1 -0
- package/dist/core/toolRegistry.d.ts +19 -0
- package/dist/core/toolRegistry.js +820 -0
- package/dist/core/toolRegistry.js.map +1 -0
- package/dist/core/turnStrategy.d.ts +20 -0
- package/dist/core/turnStrategy.js +103 -0
- package/dist/core/turnStrategy.js.map +1 -0
- package/dist/platform/process.d.ts +14 -0
- package/dist/platform/process.js +28 -0
- package/dist/platform/process.js.map +1 -0
- package/dist/platform/runtime.d.ts +8 -0
- package/dist/platform/runtime.js +21 -0
- package/dist/platform/runtime.js.map +1 -0
- package/dist/server/adminPage.d.ts +1 -0
- package/dist/server/adminPage.js +755 -0
- package/dist/server/adminPage.js.map +1 -0
- package/dist/server/index.d.ts +22 -0
- package/dist/server/index.js +566 -0
- package/dist/server/index.js.map +1 -0
- package/dist/shared/agentTypes.d.ts +227 -0
- package/dist/shared/agentTypes.js +79 -0
- package/dist/shared/agentTypes.js.map +1 -0
- package/dist/shared/codeIndexTypes.d.ts +32 -0
- package/dist/shared/codeIndexTypes.js +2 -0
- package/dist/shared/codeIndexTypes.js.map +1 -0
- package/dist/shared/flowEvents.d.ts +192 -0
- package/dist/shared/flowEvents.js +37 -0
- package/dist/shared/flowEvents.js.map +1 -0
- package/dist/shared/memoryTypes.d.ts +100 -0
- package/dist/shared/memoryTypes.js +2 -0
- package/dist/shared/memoryTypes.js.map +1 -0
- package/dist/shared/pluginTypes.d.ts +345 -0
- package/dist/shared/pluginTypes.js +2 -0
- package/dist/shared/pluginTypes.js.map +1 -0
- package/dist/shared/runtimeTaskTypes.d.ts +43 -0
- package/dist/shared/runtimeTaskTypes.js +2 -0
- package/dist/shared/runtimeTaskTypes.js.map +1 -0
- package/dist/shared/skillTypes.d.ts +1 -0
- package/dist/shared/skillTypes.js +2 -0
- package/dist/shared/skillTypes.js.map +1 -0
- package/dist/shared/subAgentTypes.d.ts +99 -0
- package/dist/shared/subAgentTypes.js +2 -0
- package/dist/shared/subAgentTypes.js.map +1 -0
- package/dist/shared/terminalTypes.d.ts +102 -0
- package/dist/shared/terminalTypes.js +2 -0
- package/dist/shared/terminalTypes.js.map +1 -0
- package/dist/shared/toolCallMarkup.d.ts +10 -0
- package/dist/shared/toolCallMarkup.js +107 -0
- package/dist/shared/toolCallMarkup.js.map +1 -0
- package/dist/shared/toolTypes.d.ts +24 -0
- package/dist/shared/toolTypes.js +2 -0
- package/dist/shared/toolTypes.js.map +1 -0
- package/dist/shared/types.d.ts +81 -0
- package/dist/shared/types.js +2 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/state/types.d.ts +69 -0
- package/dist/state/types.js +2 -0
- package/dist/state/types.js.map +1 -0
- package/dist/tools/executor.d.ts +133 -0
- package/dist/tools/executor.js +2 -0
- package/dist/tools/executor.js.map +1 -0
- package/dist/tools/memory/loaders.d.ts +6 -0
- package/dist/tools/memory/loaders.js +292 -0
- package/dist/tools/memory/loaders.js.map +1 -0
- package/dist/tools/memory/sanitizer.d.ts +6 -0
- package/dist/tools/memory/sanitizer.js +48 -0
- package/dist/tools/memory/sanitizer.js.map +1 -0
- package/dist/tools/memory/service.d.ts +24 -0
- package/dist/tools/memory/service.js +273 -0
- package/dist/tools/memory/service.js.map +1 -0
- package/dist/tools/memory/writer.d.ts +17 -0
- package/dist/tools/memory/writer.js +192 -0
- package/dist/tools/memory/writer.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync } from 'fs';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { getSupportedModelSpec, normalizeNativeReasoningConfig, SUPPORTED_MODEL_SPECS } from './modelRegistry';
|
|
5
|
+
import { normalizeApprovalPolicy, normalizeCapabilityProfile, resolveCapabilityProfileForApproval, } from '../shared/agentTypes';
|
|
6
|
+
import { getCredentialsFile, loadCredentialSnapshot, serializeCredentialSnapshot, } from './credentialStore';
|
|
7
|
+
import { quarantineCorruptFileSync, recoverFilesAtomicSync, withFileLockSync, writeFileAtomicSync, writeFilesAtomicSync, } from './fileIO';
|
|
8
|
+
const CONFIG_DIR = process.env.TURBOFLUX_CONFIG_DIR || join(homedir(), '.turboflux');
|
|
9
|
+
const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
|
|
10
|
+
const CONVERSATIONS_DIR = join(CONFIG_DIR, 'conversations');
|
|
11
|
+
const CONFIG_TRANSACTION_FILE = join(CONFIG_DIR, '.config-transaction.json');
|
|
12
|
+
const CONFIG_LOCK_FILE = join(CONFIG_DIR, '.config.lock');
|
|
13
|
+
function hydrateCredentials(raw) {
|
|
14
|
+
const stored = loadCredentialSnapshot();
|
|
15
|
+
const envApiKey = process.env.TURBOFLUX_API_KEY?.trim();
|
|
16
|
+
const activeId = typeof raw.activeApiConfigId === 'string'
|
|
17
|
+
? raw.activeApiConfigId
|
|
18
|
+
: Array.isArray(raw.apiConfigs) ? raw.apiConfigs[0]?.id : undefined;
|
|
19
|
+
const profiles = Array.isArray(raw.apiConfigs)
|
|
20
|
+
? raw.apiConfigs.map(profile => ({
|
|
21
|
+
...profile,
|
|
22
|
+
apiKey: envApiKey && profile.id === activeId
|
|
23
|
+
? envApiKey
|
|
24
|
+
: stored.apiConfigs?.[profile.id] || profile.apiKey || '',
|
|
25
|
+
}))
|
|
26
|
+
: raw.apiConfigs;
|
|
27
|
+
return {
|
|
28
|
+
...raw,
|
|
29
|
+
apiKey: envApiKey || stored.apiKey || raw.apiKey || '',
|
|
30
|
+
apiConfigs: profiles,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function legacyCredentialSnapshot(raw) {
|
|
34
|
+
return {
|
|
35
|
+
apiKey: typeof raw.apiKey === 'string' && raw.apiKey ? raw.apiKey : undefined,
|
|
36
|
+
apiConfigs: Object.fromEntries((Array.isArray(raw.apiConfigs) ? raw.apiConfigs : [])
|
|
37
|
+
.filter(profile => typeof profile?.id === 'string' && typeof profile.apiKey === 'string' && profile.apiKey)
|
|
38
|
+
.map(profile => [profile.id, profile.apiKey])),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function stripCredentials(config) {
|
|
42
|
+
return {
|
|
43
|
+
...config,
|
|
44
|
+
apiKey: '',
|
|
45
|
+
apiConfigs: config.apiConfigs?.map(profile => ({ ...profile, apiKey: '' })),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function writeConfigDocument(config) {
|
|
49
|
+
writeFileAtomicSync(CONFIG_FILE, JSON.stringify(stripCredentials(config), null, 2), 0o600);
|
|
50
|
+
}
|
|
51
|
+
export const DEFAULT_FREE_MODEL = '';
|
|
52
|
+
export const DEFAULT_CONTEXT_WINDOW = 200_000;
|
|
53
|
+
export const DEFAULT_MAX_TOKENS = 16_384;
|
|
54
|
+
export const TURBOFLUX_PROVIDERS = ['openai', 'anthropic', 'deepseek', 'kimi', 'glm', 'openrouter', 'custom'];
|
|
55
|
+
export const PROVIDER_PRESETS = [
|
|
56
|
+
{
|
|
57
|
+
id: 'custom',
|
|
58
|
+
name: 'Custom OpenAI-compatible',
|
|
59
|
+
provider: 'custom',
|
|
60
|
+
baseUrl: '',
|
|
61
|
+
defaultModel: '',
|
|
62
|
+
description: 'Custom OpenAI-compatible API endpoint.',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'openai',
|
|
66
|
+
name: 'OpenAI',
|
|
67
|
+
provider: 'openai',
|
|
68
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
69
|
+
defaultModel: 'gpt-5.6',
|
|
70
|
+
description: 'Official OpenAI-compatible API.',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'anthropic',
|
|
74
|
+
name: 'Anthropic',
|
|
75
|
+
provider: 'anthropic',
|
|
76
|
+
baseUrl: 'https://api.anthropic.com/v1',
|
|
77
|
+
defaultModel: 'claude-opus-4-8',
|
|
78
|
+
description: 'Official Anthropic Messages API.',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'openrouter',
|
|
82
|
+
name: 'OpenRouter',
|
|
83
|
+
provider: 'openrouter',
|
|
84
|
+
baseUrl: 'https://openrouter.ai/api/v1',
|
|
85
|
+
defaultModel: 'gpt-5.5',
|
|
86
|
+
description: 'OpenAI-compatible model router.',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'deepseek',
|
|
90
|
+
name: 'DeepSeek',
|
|
91
|
+
provider: 'deepseek',
|
|
92
|
+
baseUrl: 'https://api.deepseek.com',
|
|
93
|
+
defaultModel: 'deepseek-v4-flash',
|
|
94
|
+
description: 'OpenAI-compatible DeepSeek API.',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'kimi',
|
|
98
|
+
name: 'Kimi',
|
|
99
|
+
provider: 'kimi',
|
|
100
|
+
baseUrl: 'https://api.moonshot.cn/v1',
|
|
101
|
+
defaultModel: 'kimi-k3',
|
|
102
|
+
description: 'Moonshot Kimi OpenAI-compatible API.',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: 'glm',
|
|
106
|
+
name: 'GLM',
|
|
107
|
+
provider: 'glm',
|
|
108
|
+
baseUrl: 'https://open.bigmodel.cn/api/paas/v4',
|
|
109
|
+
defaultModel: 'glm-5.2',
|
|
110
|
+
description: 'Zhipu GLM OpenAI-compatible API.',
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
export function getProviderPreset(idOrProvider) {
|
|
114
|
+
const key = idOrProvider.trim().toLowerCase();
|
|
115
|
+
return PROVIDER_PRESETS.find(p => p.id === key)
|
|
116
|
+
?? PROVIDER_PRESETS.find(p => p.provider === key && p.id !== 'custom')
|
|
117
|
+
?? PROVIDER_PRESETS.find(p => p.provider === key);
|
|
118
|
+
}
|
|
119
|
+
export function baseUrlForProvider(provider) {
|
|
120
|
+
return PROVIDER_PRESETS.find(p => p.provider === provider && p.id !== 'custom')?.baseUrl
|
|
121
|
+
?? '';
|
|
122
|
+
}
|
|
123
|
+
export const MODEL_PRESETS = SUPPORTED_MODEL_SPECS.map(spec => ({
|
|
124
|
+
id: spec.id,
|
|
125
|
+
name: spec.name,
|
|
126
|
+
model: spec.id,
|
|
127
|
+
provider: providerForModel(spec.id),
|
|
128
|
+
baseUrl: baseUrlForProvider(providerForModel(spec.id)),
|
|
129
|
+
contextWindow: spec.contextWindow,
|
|
130
|
+
maxTokens: spec.defaultRequestTokens,
|
|
131
|
+
maxOutputTokens: spec.maxOutputTokens,
|
|
132
|
+
reasoning: normalizeNativeReasoningConfig(spec.id, undefined, spec.provider),
|
|
133
|
+
description: spec.description,
|
|
134
|
+
capabilities: {
|
|
135
|
+
vision: spec.supportsVision,
|
|
136
|
+
reasoning: Boolean(normalizeNativeReasoningConfig(spec.id, undefined, spec.provider)),
|
|
137
|
+
},
|
|
138
|
+
metadataSources: ['builtin'],
|
|
139
|
+
availability: 'builtin',
|
|
140
|
+
}));
|
|
141
|
+
const DEFAULT_CONFIG = {
|
|
142
|
+
provider: 'custom',
|
|
143
|
+
apiKey: '',
|
|
144
|
+
baseUrl: '',
|
|
145
|
+
model: DEFAULT_FREE_MODEL,
|
|
146
|
+
contextWindow: DEFAULT_CONTEXT_WINDOW,
|
|
147
|
+
maxTokens: DEFAULT_MAX_TOKENS,
|
|
148
|
+
approvalPolicy: 'ask',
|
|
149
|
+
capabilityProfile: 'workspace-write',
|
|
150
|
+
gitEnabled: true,
|
|
151
|
+
reasoning: undefined,
|
|
152
|
+
apiConfigs: [],
|
|
153
|
+
activeApiConfigId: undefined,
|
|
154
|
+
};
|
|
155
|
+
export function providerForModel(model, fallback = 'custom') {
|
|
156
|
+
const provider = getSupportedModelSpec(model)?.provider;
|
|
157
|
+
if (!provider)
|
|
158
|
+
return fallback;
|
|
159
|
+
return provider === 'deepseek' ? 'deepseek' : provider;
|
|
160
|
+
}
|
|
161
|
+
function looksLikeLegacyBundledDefault(config) {
|
|
162
|
+
const baseUrl = config.baseUrl?.replace(/\/+$/, '');
|
|
163
|
+
const model = config.model ?? DEFAULT_FREE_MODEL;
|
|
164
|
+
return config.provider === 'openai'
|
|
165
|
+
&& (baseUrl === 'https://api.deepseek.com' || baseUrl === 'https://api.deepseek.com/v1')
|
|
166
|
+
&& (model === DEFAULT_FREE_MODEL || model === 'deepseek-v4-pro')
|
|
167
|
+
&& typeof config.apiKey === 'string'
|
|
168
|
+
&& config.apiKey.startsWith('sk-');
|
|
169
|
+
}
|
|
170
|
+
function looksLikeLegacyLocalProxyDefault(config) {
|
|
171
|
+
const rawBaseUrl = typeof config.baseUrl === 'string' ? config.baseUrl.trim() : '';
|
|
172
|
+
let isRetiredLocalEndpoint = false;
|
|
173
|
+
try {
|
|
174
|
+
const parsed = new URL(rawBaseUrl);
|
|
175
|
+
isRetiredLocalEndpoint = ['127.0.0.1', 'localhost', '::1'].includes(parsed.hostname) && parsed.port === '8787';
|
|
176
|
+
}
|
|
177
|
+
catch { }
|
|
178
|
+
return (config.provider === 'custom' || config.provider === undefined)
|
|
179
|
+
&& isRetiredLocalEndpoint
|
|
180
|
+
&& (config.apiKey === 'turboflux-local' || config.apiKey === undefined || config.apiKey === '')
|
|
181
|
+
&& (!config.model || config.model === 'gpt-5.5' || config.model === 'deepseek-v4-pro');
|
|
182
|
+
}
|
|
183
|
+
function positiveInteger(value, fallback) {
|
|
184
|
+
const parsed = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : NaN;
|
|
185
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
186
|
+
}
|
|
187
|
+
function normalizeProvider(value, fallback) {
|
|
188
|
+
return typeof value === 'string' && TURBOFLUX_PROVIDERS.includes(value)
|
|
189
|
+
? value
|
|
190
|
+
: fallback;
|
|
191
|
+
}
|
|
192
|
+
function normalizeConfig(raw) {
|
|
193
|
+
const provider = normalizeProvider(raw.provider, DEFAULT_CONFIG.provider);
|
|
194
|
+
const model = typeof raw.model === 'string' ? raw.model.trim() : DEFAULT_CONFIG.model;
|
|
195
|
+
const baseUrl = typeof raw.baseUrl === 'string' ? raw.baseUrl.trim() : DEFAULT_CONFIG.baseUrl;
|
|
196
|
+
const apiKey = typeof raw.apiKey === 'string' ? raw.apiKey : DEFAULT_CONFIG.apiKey;
|
|
197
|
+
const contextWindow = positiveInteger(raw.contextWindow, DEFAULT_CONFIG.contextWindow);
|
|
198
|
+
const maxTokens = positiveInteger(raw.maxTokens, DEFAULT_CONFIG.maxTokens);
|
|
199
|
+
const approvalPolicy = normalizeApprovalPolicy(raw.approvalPolicy, DEFAULT_CONFIG.approvalPolicy);
|
|
200
|
+
const capabilityProfile = resolveCapabilityProfileForApproval(approvalPolicy, raw.capabilityProfile, DEFAULT_CONFIG.capabilityProfile);
|
|
201
|
+
const profiles = normalizeApiConfigProfiles(raw.apiConfigs);
|
|
202
|
+
let activeApiConfigId = typeof raw.activeApiConfigId === 'string' ? raw.activeApiConfigId : undefined;
|
|
203
|
+
const activeProfile = profiles.find(profile => profile.id === activeApiConfigId);
|
|
204
|
+
const hasCurrentConfig = Boolean(model || baseUrl || apiKey);
|
|
205
|
+
const now = Date.now();
|
|
206
|
+
let nextProfiles = profiles;
|
|
207
|
+
if (!activeProfile && hasCurrentConfig) {
|
|
208
|
+
const migrated = buildApiConfigProfile({
|
|
209
|
+
id: activeApiConfigId || 'main',
|
|
210
|
+
name: 'Main',
|
|
211
|
+
provider,
|
|
212
|
+
apiKey,
|
|
213
|
+
baseUrl,
|
|
214
|
+
model,
|
|
215
|
+
contextWindow,
|
|
216
|
+
maxTokens,
|
|
217
|
+
maxOutputTokens: raw.maxOutputTokens,
|
|
218
|
+
modelCapabilities: raw.modelCapabilities,
|
|
219
|
+
modelMetadataSources: raw.modelMetadataSources,
|
|
220
|
+
reasoning: normalizeNativeReasoningConfig(model, raw.reasoning, provider, raw.modelCapabilities),
|
|
221
|
+
createdAt: now,
|
|
222
|
+
updatedAt: now,
|
|
223
|
+
});
|
|
224
|
+
nextProfiles = upsertApiConfigProfile(profiles, migrated);
|
|
225
|
+
activeApiConfigId = migrated.id;
|
|
226
|
+
}
|
|
227
|
+
else if (!activeProfile) {
|
|
228
|
+
activeApiConfigId = nextProfiles[0]?.id;
|
|
229
|
+
}
|
|
230
|
+
const selected = nextProfiles.find(profile => profile.id === activeApiConfigId);
|
|
231
|
+
return {
|
|
232
|
+
provider: selected?.provider ?? provider,
|
|
233
|
+
apiKey: selected?.apiKey ?? apiKey,
|
|
234
|
+
baseUrl: selected?.baseUrl ?? baseUrl,
|
|
235
|
+
model: selected?.model ?? model,
|
|
236
|
+
contextWindow: selected?.contextWindow ?? contextWindow,
|
|
237
|
+
maxTokens: selected?.maxTokens ?? maxTokens,
|
|
238
|
+
maxOutputTokens: selected?.maxOutputTokens,
|
|
239
|
+
modelCapabilities: selected?.modelCapabilities,
|
|
240
|
+
modelMetadataSources: selected?.modelMetadataSources,
|
|
241
|
+
approvalPolicy,
|
|
242
|
+
capabilityProfile,
|
|
243
|
+
gitEnabled: raw.gitEnabled !== false,
|
|
244
|
+
reasoning: selected?.reasoning ?? normalizeNativeReasoningConfig(model, raw.reasoning, provider, raw.modelCapabilities),
|
|
245
|
+
apiConfigs: nextProfiles,
|
|
246
|
+
activeApiConfigId,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function buildApiConfigProfile(raw) {
|
|
250
|
+
const now = Date.now();
|
|
251
|
+
const provider = normalizeProvider(raw.provider, DEFAULT_CONFIG.provider);
|
|
252
|
+
const model = typeof raw.model === 'string' ? raw.model.trim() : DEFAULT_CONFIG.model;
|
|
253
|
+
const baseUrl = typeof raw.baseUrl === 'string' ? raw.baseUrl.trim().replace(/\/+$/, '') : DEFAULT_CONFIG.baseUrl;
|
|
254
|
+
const apiKey = typeof raw.apiKey === 'string' ? raw.apiKey : DEFAULT_CONFIG.apiKey;
|
|
255
|
+
const contextWindow = positiveInteger(raw.contextWindow, DEFAULT_CONFIG.contextWindow);
|
|
256
|
+
const maxTokens = positiveInteger(raw.maxTokens, DEFAULT_CONFIG.maxTokens);
|
|
257
|
+
const maxOutputTokens = raw.maxOutputTokens === undefined ? undefined : positiveInteger(raw.maxOutputTokens, maxTokens);
|
|
258
|
+
const reasoning = normalizeNativeReasoningConfig(model, raw.reasoning, provider, raw.modelCapabilities);
|
|
259
|
+
const id = typeof raw.id === 'string' && raw.id.trim()
|
|
260
|
+
? raw.id.trim()
|
|
261
|
+
: `api_${now.toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
262
|
+
return {
|
|
263
|
+
id,
|
|
264
|
+
name: typeof raw.name === 'string' && raw.name.trim() ? raw.name.trim() : defaultApiConfigName(provider, model, id),
|
|
265
|
+
provider,
|
|
266
|
+
apiKey,
|
|
267
|
+
baseUrl,
|
|
268
|
+
model,
|
|
269
|
+
contextWindow,
|
|
270
|
+
maxTokens,
|
|
271
|
+
maxOutputTokens,
|
|
272
|
+
modelCapabilities: raw.modelCapabilities,
|
|
273
|
+
modelMetadataSources: raw.modelMetadataSources,
|
|
274
|
+
reasoning,
|
|
275
|
+
createdAt: positiveInteger(raw.createdAt, now),
|
|
276
|
+
updatedAt: positiveInteger(raw.updatedAt, now),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function normalizeApiConfigProfiles(value) {
|
|
280
|
+
if (!Array.isArray(value))
|
|
281
|
+
return [];
|
|
282
|
+
const seen = new Set();
|
|
283
|
+
const profiles = [];
|
|
284
|
+
for (const item of value) {
|
|
285
|
+
if (!item || typeof item !== 'object')
|
|
286
|
+
continue;
|
|
287
|
+
const profile = buildApiConfigProfile(item);
|
|
288
|
+
let id = profile.id;
|
|
289
|
+
let suffix = 2;
|
|
290
|
+
while (seen.has(id)) {
|
|
291
|
+
id = `${profile.id}-${suffix++}`;
|
|
292
|
+
}
|
|
293
|
+
seen.add(id);
|
|
294
|
+
profiles.push({ ...profile, id });
|
|
295
|
+
}
|
|
296
|
+
return profiles;
|
|
297
|
+
}
|
|
298
|
+
function emptyConfigWithProfiles() {
|
|
299
|
+
return {
|
|
300
|
+
...DEFAULT_CONFIG,
|
|
301
|
+
apiConfigs: [],
|
|
302
|
+
activeApiConfigId: undefined,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
export function createEmptyConfig() {
|
|
306
|
+
return emptyConfigWithProfiles();
|
|
307
|
+
}
|
|
308
|
+
function defaultApiConfigName(provider, model, id) {
|
|
309
|
+
const presetName = PROVIDER_PRESETS.find(preset => preset.provider === provider && preset.id !== 'custom')?.name
|
|
310
|
+
|| PROVIDER_PRESETS.find(preset => preset.provider === provider)?.name
|
|
311
|
+
|| provider;
|
|
312
|
+
return model ? `${presetName} / ${model}` : id;
|
|
313
|
+
}
|
|
314
|
+
function upsertApiConfigProfile(profiles, profile) {
|
|
315
|
+
const list = profiles ?? [];
|
|
316
|
+
const index = list.findIndex(item => item.id === profile.id);
|
|
317
|
+
if (index < 0)
|
|
318
|
+
return [...list, profile];
|
|
319
|
+
return list.map((item, i) => i === index ? { ...profile, createdAt: item.createdAt || profile.createdAt } : item);
|
|
320
|
+
}
|
|
321
|
+
function activeFieldsFromProfile(config, profile) {
|
|
322
|
+
if (!profile)
|
|
323
|
+
return config;
|
|
324
|
+
return {
|
|
325
|
+
...config,
|
|
326
|
+
provider: profile.provider,
|
|
327
|
+
apiKey: profile.apiKey,
|
|
328
|
+
baseUrl: profile.baseUrl,
|
|
329
|
+
model: profile.model,
|
|
330
|
+
contextWindow: profile.contextWindow,
|
|
331
|
+
maxTokens: profile.maxTokens,
|
|
332
|
+
maxOutputTokens: profile.maxOutputTokens,
|
|
333
|
+
modelCapabilities: profile.modelCapabilities,
|
|
334
|
+
modelMetadataSources: profile.modelMetadataSources,
|
|
335
|
+
reasoning: profile.reasoning,
|
|
336
|
+
activeApiConfigId: profile.id,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function syncActiveProfile(config, touchUpdatedAt = true) {
|
|
340
|
+
const normalizedProfiles = normalizeApiConfigProfiles(config.apiConfigs);
|
|
341
|
+
const hasCurrentConfig = Boolean(config.model || config.baseUrl || config.apiKey);
|
|
342
|
+
if (normalizedProfiles.length === 0 && !hasCurrentConfig) {
|
|
343
|
+
return {
|
|
344
|
+
...config,
|
|
345
|
+
provider: normalizeProvider(config.provider, DEFAULT_CONFIG.provider),
|
|
346
|
+
apiKey: '',
|
|
347
|
+
baseUrl: '',
|
|
348
|
+
model: '',
|
|
349
|
+
contextWindow: positiveInteger(config.contextWindow, DEFAULT_CONFIG.contextWindow),
|
|
350
|
+
maxTokens: positiveInteger(config.maxTokens, DEFAULT_CONFIG.maxTokens),
|
|
351
|
+
reasoning: undefined,
|
|
352
|
+
apiConfigs: [],
|
|
353
|
+
activeApiConfigId: undefined,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
const activeId = config.activeApiConfigId || normalizedProfiles[0]?.id || 'main';
|
|
357
|
+
const existing = normalizedProfiles.find(profile => profile.id === activeId);
|
|
358
|
+
const now = Date.now();
|
|
359
|
+
const activeFieldsChanged = !existing || existing.provider !== config.provider
|
|
360
|
+
|| existing.apiKey !== config.apiKey
|
|
361
|
+
|| existing.baseUrl !== config.baseUrl.replace(/\/+$/, '')
|
|
362
|
+
|| existing.model !== config.model.trim()
|
|
363
|
+
|| existing.contextWindow !== config.contextWindow
|
|
364
|
+
|| existing.maxTokens !== config.maxTokens
|
|
365
|
+
|| existing.maxOutputTokens !== config.maxOutputTokens
|
|
366
|
+
|| JSON.stringify(existing.modelCapabilities) !== JSON.stringify(config.modelCapabilities)
|
|
367
|
+
|| JSON.stringify(existing.modelMetadataSources) !== JSON.stringify(config.modelMetadataSources)
|
|
368
|
+
|| JSON.stringify(existing.reasoning) !== JSON.stringify(normalizeNativeReasoningConfig(config.model, config.reasoning, config.provider, config.modelCapabilities));
|
|
369
|
+
const activeProfile = buildApiConfigProfile({
|
|
370
|
+
...(existing ?? {}),
|
|
371
|
+
id: activeId,
|
|
372
|
+
name: existing?.name || defaultApiConfigName(config.provider, config.model, activeId),
|
|
373
|
+
provider: config.provider,
|
|
374
|
+
apiKey: config.apiKey,
|
|
375
|
+
baseUrl: config.baseUrl,
|
|
376
|
+
model: config.model,
|
|
377
|
+
contextWindow: config.contextWindow,
|
|
378
|
+
maxTokens: config.maxTokens,
|
|
379
|
+
maxOutputTokens: config.maxOutputTokens,
|
|
380
|
+
modelCapabilities: config.modelCapabilities,
|
|
381
|
+
modelMetadataSources: config.modelMetadataSources,
|
|
382
|
+
reasoning: config.reasoning,
|
|
383
|
+
createdAt: existing?.createdAt || now,
|
|
384
|
+
updatedAt: touchUpdatedAt && activeFieldsChanged ? now : existing?.updatedAt || now,
|
|
385
|
+
});
|
|
386
|
+
const profiles = upsertApiConfigProfile(normalizedProfiles, activeProfile);
|
|
387
|
+
return activeFieldsFromProfile({
|
|
388
|
+
...config,
|
|
389
|
+
apiConfigs: profiles,
|
|
390
|
+
activeApiConfigId: activeId,
|
|
391
|
+
}, activeProfile);
|
|
392
|
+
}
|
|
393
|
+
export function setConfigValue(config, key, value) {
|
|
394
|
+
const updateActive = (next) => syncActiveProfile(next);
|
|
395
|
+
switch (key) {
|
|
396
|
+
case 'provider': {
|
|
397
|
+
if (!TURBOFLUX_PROVIDERS.includes(value)) {
|
|
398
|
+
throw new Error(`Invalid provider. Use one of: ${TURBOFLUX_PROVIDERS.join(', ')}`);
|
|
399
|
+
}
|
|
400
|
+
return updateActive({ ...config, provider: value });
|
|
401
|
+
}
|
|
402
|
+
case 'apiKey':
|
|
403
|
+
return updateActive({ ...config, apiKey: value });
|
|
404
|
+
case 'baseUrl': {
|
|
405
|
+
try {
|
|
406
|
+
new URL(value);
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
throw new Error('Invalid baseUrl. Use a full URL such as https://api.example.com/v1');
|
|
410
|
+
}
|
|
411
|
+
return updateActive({ ...config, baseUrl: value.replace(/\/+$/, '') });
|
|
412
|
+
}
|
|
413
|
+
case 'model':
|
|
414
|
+
if (!value.trim())
|
|
415
|
+
throw new Error('model cannot be empty');
|
|
416
|
+
return updateActive({
|
|
417
|
+
...config,
|
|
418
|
+
model: value.trim(),
|
|
419
|
+
maxOutputTokens: undefined,
|
|
420
|
+
modelCapabilities: undefined,
|
|
421
|
+
modelMetadataSources: undefined,
|
|
422
|
+
reasoning: normalizeNativeReasoningConfig(value.trim(), config.reasoning, config.provider),
|
|
423
|
+
});
|
|
424
|
+
case 'approvalPolicy':
|
|
425
|
+
if (!['ask', 'agent', 'full', 'request', 'auto'].includes(value.toLowerCase())) {
|
|
426
|
+
throw new Error('approvalPolicy must be ask, agent, or full');
|
|
427
|
+
}
|
|
428
|
+
{
|
|
429
|
+
const approvalPolicy = normalizeApprovalPolicy(value.toLowerCase(), config.approvalPolicy);
|
|
430
|
+
const capabilityProfile = approvalPolicy === 'full'
|
|
431
|
+
? 'danger-full-access'
|
|
432
|
+
: config.approvalPolicy === 'full' && config.capabilityProfile === 'danger-full-access'
|
|
433
|
+
? 'workspace-write'
|
|
434
|
+
: normalizeCapabilityProfile(config.capabilityProfile);
|
|
435
|
+
return { ...config, approvalPolicy, capabilityProfile };
|
|
436
|
+
}
|
|
437
|
+
case 'capabilityProfile':
|
|
438
|
+
if (!['read-only', 'workspace-write', 'danger-full-access'].includes(value.toLowerCase())) {
|
|
439
|
+
throw new Error('capabilityProfile must be read-only, workspace-write, or danger-full-access');
|
|
440
|
+
}
|
|
441
|
+
{
|
|
442
|
+
const capabilityProfile = normalizeCapabilityProfile(value.toLowerCase(), config.capabilityProfile);
|
|
443
|
+
const approvalPolicy = config.approvalPolicy === 'full' && capabilityProfile !== 'danger-full-access'
|
|
444
|
+
? 'agent'
|
|
445
|
+
: config.approvalPolicy;
|
|
446
|
+
return { ...config, approvalPolicy, capabilityProfile };
|
|
447
|
+
}
|
|
448
|
+
case 'gitEnabled': {
|
|
449
|
+
const normalized = value.toLowerCase();
|
|
450
|
+
if (!['true', 'false', 'on', 'off', 'enabled', 'disabled'].includes(normalized)) {
|
|
451
|
+
throw new Error('gitEnabled must be on or off');
|
|
452
|
+
}
|
|
453
|
+
return { ...config, gitEnabled: ['true', 'on', 'enabled'].includes(normalized) };
|
|
454
|
+
}
|
|
455
|
+
case 'reasoningEnabled': {
|
|
456
|
+
const normalized = value.toLowerCase();
|
|
457
|
+
if (!['true', 'false', 'on', 'off', 'enabled', 'disabled'].includes(normalized)) {
|
|
458
|
+
throw new Error('reasoningEnabled must be on or off');
|
|
459
|
+
}
|
|
460
|
+
return updateActive({
|
|
461
|
+
...config,
|
|
462
|
+
reasoning: normalizeNativeReasoningConfig(config.model, {
|
|
463
|
+
...config.reasoning,
|
|
464
|
+
enabled: ['true', 'on', 'enabled'].includes(normalized),
|
|
465
|
+
}, config.provider, config.modelCapabilities),
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
case 'reasoningEffort':
|
|
469
|
+
return updateActive({
|
|
470
|
+
...config,
|
|
471
|
+
reasoning: normalizeNativeReasoningConfig(config.model, {
|
|
472
|
+
...config.reasoning,
|
|
473
|
+
effort: value.toLowerCase(),
|
|
474
|
+
}, config.provider, config.modelCapabilities),
|
|
475
|
+
});
|
|
476
|
+
case 'reasoningBudgetTokens': {
|
|
477
|
+
const parsed = Number(value);
|
|
478
|
+
if (!Number.isInteger(parsed) || parsed < 1024)
|
|
479
|
+
throw new Error('reasoningBudgetTokens must be at least 1024');
|
|
480
|
+
return updateActive({
|
|
481
|
+
...config,
|
|
482
|
+
reasoning: normalizeNativeReasoningConfig(config.model, {
|
|
483
|
+
...config.reasoning,
|
|
484
|
+
budgetTokens: parsed,
|
|
485
|
+
}, config.provider, config.modelCapabilities),
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
case 'contextWindow':
|
|
489
|
+
case 'maxTokens': {
|
|
490
|
+
const parsed = Number(value);
|
|
491
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
492
|
+
throw new Error(`${key} must be a positive integer`);
|
|
493
|
+
}
|
|
494
|
+
if (key === 'maxTokens' && config.maxOutputTokens && parsed > config.maxOutputTokens) {
|
|
495
|
+
throw new Error(`maxTokens cannot exceed this model's ${config.maxOutputTokens} token output limit`);
|
|
496
|
+
}
|
|
497
|
+
return updateActive({ ...config, [key]: parsed });
|
|
498
|
+
}
|
|
499
|
+
default:
|
|
500
|
+
throw new Error(`Unknown config key "${key}". Valid keys: provider, apiKey, baseUrl, model, contextWindow, maxTokens, approvalPolicy, capabilityProfile, gitEnabled, reasoningEnabled, reasoningEffort, reasoningBudgetTokens`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function applyKnownModelMetadata(config, presets) {
|
|
504
|
+
const spec = getSupportedModelSpec(config.model);
|
|
505
|
+
return spec ? {
|
|
506
|
+
...config,
|
|
507
|
+
model: spec.id,
|
|
508
|
+
reasoning: normalizeNativeReasoningConfig(spec.id, config.reasoning, spec.provider),
|
|
509
|
+
} : config;
|
|
510
|
+
}
|
|
511
|
+
export function ensureDirectories(workspacePath) {
|
|
512
|
+
const dirs = [CONFIG_DIR, CONVERSATIONS_DIR];
|
|
513
|
+
if (workspacePath) {
|
|
514
|
+
dirs.push(join(workspacePath, '.turboflux', 'memory'));
|
|
515
|
+
}
|
|
516
|
+
for (const dir of dirs) {
|
|
517
|
+
if (!existsSync(dir)) {
|
|
518
|
+
mkdirSync(dir, { recursive: true });
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function credentialSnapshotForSave(config, fallback = {}) {
|
|
523
|
+
const stored = loadCredentialSnapshot();
|
|
524
|
+
const envApiKey = process.env.TURBOFLUX_API_KEY?.trim();
|
|
525
|
+
const activeId = config.activeApiConfigId;
|
|
526
|
+
const persistentActiveKey = activeId
|
|
527
|
+
? stored.apiConfigs?.[activeId] ?? fallback.apiConfigs?.[activeId] ?? stored.apiKey ?? fallback.apiKey
|
|
528
|
+
: stored.apiKey ?? fallback.apiKey;
|
|
529
|
+
const apiConfigs = Object.fromEntries((config.apiConfigs || []).flatMap(profile => {
|
|
530
|
+
const key = envApiKey && profile.id === activeId && profile.apiKey === envApiKey
|
|
531
|
+
? stored.apiConfigs?.[profile.id] ?? fallback.apiConfigs?.[profile.id] ?? persistentActiveKey
|
|
532
|
+
: profile.apiKey;
|
|
533
|
+
return key ? [[profile.id, key]] : [];
|
|
534
|
+
}));
|
|
535
|
+
const apiKey = envApiKey && config.apiKey === envApiKey
|
|
536
|
+
? persistentActiveKey
|
|
537
|
+
: config.apiKey || undefined;
|
|
538
|
+
return { apiKey, apiConfigs };
|
|
539
|
+
}
|
|
540
|
+
function persistConfig(config, fallbackCredentials) {
|
|
541
|
+
const normalized = syncActiveProfile(normalizeConfig(config));
|
|
542
|
+
const credentials = credentialSnapshotForSave(normalized, fallbackCredentials);
|
|
543
|
+
writeFilesAtomicSync([
|
|
544
|
+
{
|
|
545
|
+
filePath: getCredentialsFile(),
|
|
546
|
+
content: serializeCredentialSnapshot(credentials),
|
|
547
|
+
mode: 0o600,
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
filePath: CONFIG_FILE,
|
|
551
|
+
content: JSON.stringify(stripCredentials(normalized), null, 2),
|
|
552
|
+
mode: 0o600,
|
|
553
|
+
},
|
|
554
|
+
], CONFIG_TRANSACTION_FILE);
|
|
555
|
+
return normalized;
|
|
556
|
+
}
|
|
557
|
+
export async function loadConfig() {
|
|
558
|
+
ensureDirectories();
|
|
559
|
+
return withFileLockSync(CONFIG_LOCK_FILE, () => {
|
|
560
|
+
recoverFilesAtomicSync(CONFIG_TRANSACTION_FILE);
|
|
561
|
+
if (!existsSync(CONFIG_FILE)) {
|
|
562
|
+
const initial = applyKnownModelMetadata(normalizeConfig(hydrateCredentials(DEFAULT_CONFIG)), MODEL_PRESETS);
|
|
563
|
+
writeConfigDocument(initial);
|
|
564
|
+
return initial;
|
|
565
|
+
}
|
|
566
|
+
let userConfig;
|
|
567
|
+
try {
|
|
568
|
+
const raw = readFileSync(CONFIG_FILE, 'utf-8').replace(/^\uFEFF/, '');
|
|
569
|
+
const parsed = JSON.parse(raw);
|
|
570
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
571
|
+
throw new Error('Configuration must be a JSON object');
|
|
572
|
+
userConfig = parsed;
|
|
573
|
+
}
|
|
574
|
+
catch (error) {
|
|
575
|
+
const backupPath = quarantineCorruptFileSync(CONFIG_FILE);
|
|
576
|
+
console.warn(`TurboFlux preserved an invalid configuration file at ${backupPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
577
|
+
const recovered = applyKnownModelMetadata(normalizeConfig(hydrateCredentials(DEFAULT_CONFIG)), MODEL_PRESETS);
|
|
578
|
+
writeConfigDocument(recovered);
|
|
579
|
+
return recovered;
|
|
580
|
+
}
|
|
581
|
+
const legacyCredentials = legacyCredentialSnapshot(userConfig);
|
|
582
|
+
const merged = normalizeConfig(hydrateCredentials({ ...DEFAULT_CONFIG, ...userConfig }));
|
|
583
|
+
if (looksLikeLegacyLocalProxyDefault(userConfig) || looksLikeLegacyBundledDefault(userConfig)) {
|
|
584
|
+
return persistConfig(emptyConfigWithProfiles());
|
|
585
|
+
}
|
|
586
|
+
const withBackendMetadata = applyKnownModelMetadata(merged, MODEL_PRESETS);
|
|
587
|
+
const hasLegacyCredentials = Boolean(userConfig.apiKey)
|
|
588
|
+
|| (Array.isArray(userConfig.apiConfigs) && userConfig.apiConfigs.some(profile => Boolean(profile.apiKey)));
|
|
589
|
+
const needsFullAccessMigration = withBackendMetadata.approvalPolicy === 'full'
|
|
590
|
+
&& userConfig.capabilityProfile !== 'danger-full-access';
|
|
591
|
+
if (withBackendMetadata.contextWindow !== merged.contextWindow ||
|
|
592
|
+
withBackendMetadata.maxTokens !== merged.maxTokens ||
|
|
593
|
+
withBackendMetadata.model !== merged.model ||
|
|
594
|
+
hasLegacyCredentials ||
|
|
595
|
+
needsFullAccessMigration) {
|
|
596
|
+
return persistConfig(withBackendMetadata, legacyCredentials);
|
|
597
|
+
}
|
|
598
|
+
return syncActiveProfile(withBackendMetadata, false);
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
export function saveConfig(config) {
|
|
602
|
+
ensureDirectories();
|
|
603
|
+
return withFileLockSync(CONFIG_LOCK_FILE, () => {
|
|
604
|
+
recoverFilesAtomicSync(CONFIG_TRANSACTION_FILE);
|
|
605
|
+
return persistConfig(config);
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
export function getConfigDir() {
|
|
609
|
+
return CONFIG_DIR;
|
|
610
|
+
}
|
|
611
|
+
export function getConfigFile() {
|
|
612
|
+
return CONFIG_FILE;
|
|
613
|
+
}
|
|
614
|
+
export function redactConfig(config) {
|
|
615
|
+
return {
|
|
616
|
+
...config,
|
|
617
|
+
apiKey: config.apiKey ? '***' : '',
|
|
618
|
+
apiConfigs: config.apiConfigs?.map(profile => ({ ...profile, apiKey: profile.apiKey ? '***' : '' })),
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
export function getConversationsDir() {
|
|
622
|
+
return CONVERSATIONS_DIR;
|
|
623
|
+
}
|
|
624
|
+
export function getPresetByIdOrModel(idOrModel) {
|
|
625
|
+
const spec = getSupportedModelSpec(idOrModel);
|
|
626
|
+
return MODEL_PRESETS.find(p => p.id === (spec?.id ?? idOrModel) || p.model === (spec?.id ?? idOrModel));
|
|
627
|
+
}
|
|
628
|
+
export function getPresetByIdOrModelFrom(presets, idOrModel) {
|
|
629
|
+
const spec = getSupportedModelSpec(idOrModel);
|
|
630
|
+
const canonical = spec?.id ?? idOrModel;
|
|
631
|
+
return presets.find(p => p.id === canonical || p.model === canonical);
|
|
632
|
+
}
|
|
633
|
+
export function applyPreset(config, preset) {
|
|
634
|
+
return syncActiveProfile({
|
|
635
|
+
...config,
|
|
636
|
+
provider: preset.provider,
|
|
637
|
+
model: preset.model,
|
|
638
|
+
baseUrl: preset.baseUrl,
|
|
639
|
+
contextWindow: preset.contextWindow,
|
|
640
|
+
maxTokens: Math.min(preset.maxTokens, preset.maxOutputTokens ?? preset.maxTokens),
|
|
641
|
+
maxOutputTokens: preset.maxOutputTokens,
|
|
642
|
+
modelCapabilities: preset.capabilities,
|
|
643
|
+
modelMetadataSources: preset.metadataSources,
|
|
644
|
+
reasoning: normalizeNativeReasoningConfig(preset.model, preset.reasoning ?? config.reasoning, preset.provider, preset.capabilities),
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
export function configFromProviderPreset(preset, apiKey, model, baseUrl) {
|
|
648
|
+
const selectedModel = model?.trim() || preset.defaultModel;
|
|
649
|
+
const spec = getSupportedModelSpec(selectedModel);
|
|
650
|
+
const selectedApiKey = apiKey || '';
|
|
651
|
+
return syncActiveProfile({
|
|
652
|
+
provider: preset.provider,
|
|
653
|
+
apiKey: selectedApiKey,
|
|
654
|
+
baseUrl: (baseUrl?.trim() || preset.baseUrl).replace(/\/+$/, ''),
|
|
655
|
+
model: spec?.id ?? selectedModel,
|
|
656
|
+
contextWindow: spec?.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
657
|
+
maxTokens: spec?.defaultRequestTokens ?? DEFAULT_MAX_TOKENS,
|
|
658
|
+
maxOutputTokens: spec?.maxOutputTokens,
|
|
659
|
+
modelCapabilities: spec ? {
|
|
660
|
+
vision: spec.supportsVision,
|
|
661
|
+
reasoning: Boolean(normalizeNativeReasoningConfig(spec.id, undefined, preset.provider)),
|
|
662
|
+
} : undefined,
|
|
663
|
+
modelMetadataSources: spec ? ['builtin'] : ['default'],
|
|
664
|
+
approvalPolicy: 'ask',
|
|
665
|
+
gitEnabled: true,
|
|
666
|
+
reasoning: normalizeNativeReasoningConfig(spec?.id ?? selectedModel, undefined, preset.provider),
|
|
667
|
+
apiConfigs: [],
|
|
668
|
+
activeApiConfigId: 'main',
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
export function getApiConfigProfiles(config) {
|
|
672
|
+
return normalizeConfig(config).apiConfigs ?? [];
|
|
673
|
+
}
|
|
674
|
+
export function getActiveApiConfigProfile(config) {
|
|
675
|
+
const normalized = normalizeConfig(config);
|
|
676
|
+
return normalized.apiConfigs?.find(profile => profile.id === normalized.activeApiConfigId);
|
|
677
|
+
}
|
|
678
|
+
export function saveApiConfigProfile(config, profile, makeActive = true) {
|
|
679
|
+
const normalized = normalizeConfig(config);
|
|
680
|
+
const profiles = upsertApiConfigProfile(normalized.apiConfigs, { ...profile, updatedAt: Date.now() });
|
|
681
|
+
const next = {
|
|
682
|
+
...normalized,
|
|
683
|
+
apiConfigs: profiles,
|
|
684
|
+
activeApiConfigId: makeActive ? profile.id : normalized.activeApiConfigId,
|
|
685
|
+
};
|
|
686
|
+
const selected = profiles.find(item => item.id === next.activeApiConfigId);
|
|
687
|
+
return activeFieldsFromProfile(next, selected);
|
|
688
|
+
}
|
|
689
|
+
export function createApiConfigProfile(input) {
|
|
690
|
+
return buildApiConfigProfile(input);
|
|
691
|
+
}
|
|
692
|
+
export function switchActiveApiConfig(config, apiConfigId) {
|
|
693
|
+
const normalized = normalizeConfig(config);
|
|
694
|
+
const profile = normalized.apiConfigs?.find(item => item.id === apiConfigId);
|
|
695
|
+
if (!profile)
|
|
696
|
+
throw new Error(`API config not found: ${apiConfigId}`);
|
|
697
|
+
return activeFieldsFromProfile({ ...normalized, activeApiConfigId: apiConfigId }, profile);
|
|
698
|
+
}
|
|
699
|
+
export function deleteApiConfigProfile(config, apiConfigId) {
|
|
700
|
+
const normalized = normalizeConfig(config);
|
|
701
|
+
const profiles = (normalized.apiConfigs ?? []).filter(profile => profile.id !== apiConfigId);
|
|
702
|
+
if (profiles.length === 0) {
|
|
703
|
+
return emptyConfigWithProfiles();
|
|
704
|
+
}
|
|
705
|
+
const nextActiveId = normalized.activeApiConfigId === apiConfigId
|
|
706
|
+
? profiles[0]?.id
|
|
707
|
+
: normalized.activeApiConfigId;
|
|
708
|
+
const next = {
|
|
709
|
+
...normalized,
|
|
710
|
+
apiConfigs: profiles,
|
|
711
|
+
activeApiConfigId: nextActiveId,
|
|
712
|
+
};
|
|
713
|
+
return activeFieldsFromProfile(next, profiles.find(profile => profile.id === nextActiveId));
|
|
714
|
+
}
|
|
715
|
+
//# sourceMappingURL=config.js.map
|