@denizokcu/haze 0.10.0 → 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/CHANGELOG.md +100 -1
- package/README.md +77 -27
- package/SECURITY.md +22 -0
- package/bin/haze.js +102 -1
- package/dist/buildInfo.json +7 -0
- package/dist/cli/chat/TaskBar.d.ts +2 -1
- package/dist/cli/chat/TaskBar.js +7 -4
- package/dist/cli/chat/chatMetrics.d.ts +2 -2
- package/dist/cli/chat/chatMetrics.js +1 -1
- package/dist/cli/chat/contextReport.js +2 -0
- package/dist/cli/chat/fileMentionSuggestions.js +3 -2
- package/dist/cli/chat/inputSuggestions.d.ts +8 -16
- package/dist/cli/chat/inputSuggestions.js +9 -41
- package/dist/cli/chat/liveRegion.d.ts +25 -0
- package/dist/cli/chat/liveRegion.js +48 -0
- package/dist/cli/chat/messages.d.ts +33 -4
- package/dist/cli/chat/messages.js +218 -35
- package/dist/cli/chat/sessionLifecycle.d.ts +11 -1
- package/dist/cli/chat/sessionLifecycle.js +64 -14
- package/dist/cli/chat/sessionRecorder.js +75 -7
- package/dist/cli/chat/startupInfo.d.ts +0 -1
- package/dist/cli/chat/startupInfo.js +11 -15
- package/dist/cli/chat/turnState.d.ts +1 -1
- package/dist/cli/chat/wizardDispatch.d.ts +90 -28
- package/dist/cli/chat/wizardDispatch.js +349 -133
- package/dist/cli/commands/chat.d.ts +5 -0
- package/dist/cli/commands/chat.js +216 -172
- package/dist/cli/commands/chatModes.d.ts +8 -1
- package/dist/cli/commands/chatModes.js +9 -44
- package/dist/cli/commands/commands.d.ts +2 -0
- package/dist/cli/commands/commands.js +10 -5
- package/dist/cli/commands/doctor.d.ts +19 -0
- package/dist/cli/commands/doctor.js +76 -0
- package/dist/cli/commands/formatters.d.ts +3 -3
- package/dist/cli/commands/formatters.js +8 -25
- package/dist/cli/commands/ndjsonSink.d.ts +23 -0
- package/dist/cli/commands/ndjsonSink.js +38 -0
- package/dist/cli/commands/providerWizard.d.ts +9 -2
- package/dist/cli/commands/providerWizard.js +39 -7
- package/dist/cli/commands/runCommand.d.ts +3 -0
- package/dist/cli/commands/runCommand.js +117 -11
- package/dist/cli/commands/serverWizard.d.ts +34 -0
- package/dist/cli/commands/{mcpWizard.js → serverWizard.js} +44 -2
- package/dist/cli/commands/skillsWizard.d.ts +41 -0
- package/dist/cli/commands/{skillWizard.js → skillsWizard.js} +33 -11
- package/dist/cli/commands/streaming/abortCause.d.ts +25 -0
- package/dist/cli/commands/streaming/abortCause.js +16 -0
- package/dist/cli/commands/streaming/agentAttempt.d.ts +43 -0
- package/dist/cli/commands/streaming/agentAttempt.js +79 -0
- package/dist/cli/commands/streaming/assistantText.js +9 -2
- package/dist/cli/commands/streaming/attemptLifecycle.d.ts +56 -0
- package/dist/cli/commands/streaming/attemptLifecycle.js +110 -0
- package/dist/cli/commands/streaming/attemptOutcome.d.ts +96 -0
- package/dist/cli/commands/streaming/attemptOutcome.js +206 -0
- package/dist/cli/commands/streaming/attemptSetup.d.ts +78 -0
- package/dist/cli/commands/streaming/attemptSetup.js +167 -0
- package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
- package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
- package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
- package/dist/cli/commands/streaming/goalSupervisor.js +130 -0
- package/dist/cli/commands/streaming/stallRecovery.d.ts +94 -0
- package/dist/cli/commands/streaming/stallRecovery.js +105 -0
- package/dist/cli/commands/streaming/streamLoop.d.ts +72 -0
- package/dist/cli/commands/streaming/streamLoop.js +448 -0
- package/dist/cli/commands/streaming/toolCallRecovery.d.ts +16 -0
- package/dist/cli/commands/streaming/toolCallRecovery.js +80 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -1
- package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -4
- package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
- package/dist/cli/commands/streaming/toolResultState.js +29 -7
- package/dist/cli/commands/streaming/turnRuntime.d.ts +4 -0
- package/dist/cli/commands/streaming/turnRuntime.js +6 -0
- package/dist/cli/commands/streaming.d.ts +65 -9
- package/dist/cli/commands/streaming.js +133 -430
- package/dist/cli/commands/wizardFlow.d.ts +334 -0
- package/dist/cli/commands/wizardFlow.js +377 -0
- package/dist/cli/contextReport.js +3 -0
- package/dist/cli/index.js +68 -22
- package/dist/cli/terminalTitle.js +1 -1
- package/dist/config/contextFiles.js +9 -3
- package/dist/config/inputHistory.d.ts +0 -1
- package/dist/config/inputHistory.js +1 -1
- package/dist/config/modelDiscovery.d.ts +36 -0
- package/dist/config/modelDiscovery.js +164 -1
- package/dist/config/privateStorage.js +28 -2
- package/dist/config/providerAuth.d.ts +14 -0
- package/dist/config/providerAuth.js +49 -0
- package/dist/config/providerPresets.d.ts +39 -7
- package/dist/config/providerPresets.js +371 -100
- package/dist/config/providers.js +2 -0
- package/dist/config/settings.d.ts +43 -0
- package/dist/config/settings.js +12 -0
- package/dist/config/skillSettings.js +4 -4
- package/dist/config/updateCheck.d.ts +0 -1
- package/dist/config/updateCheck.js +1 -1
- package/dist/core/agent/budgets.d.ts +73 -1
- package/dist/core/agent/budgets.js +94 -1
- package/dist/core/agent/compaction.d.ts +38 -0
- package/dist/core/agent/compaction.js +92 -17
- package/dist/core/agent/completionController.d.ts +224 -0
- package/dist/core/agent/completionController.js +296 -0
- package/dist/core/agent/contextBudget.d.ts +36 -2
- package/dist/core/agent/contextBudget.js +62 -9
- package/dist/core/agent/errors.d.ts +0 -1
- package/dist/core/agent/errors.js +1 -1
- package/dist/core/agent/events.d.ts +78 -0
- package/dist/core/agent/goalPolicy.d.ts +47 -0
- package/dist/core/agent/goalPolicy.js +106 -0
- package/dist/core/agent/reasoningPolicy.d.ts +31 -0
- package/dist/core/agent/reasoningPolicy.js +27 -0
- package/dist/core/agent/requestAssembly.d.ts +2 -2
- package/dist/core/agent/requestAssembly.js +16 -4
- package/dist/core/agent/toolCapabilities.d.ts +27 -0
- package/dist/core/agent/toolCapabilities.js +58 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +11 -11
- package/dist/core/agent/toolResults.d.ts +12 -0
- package/dist/core/agent/toolResults.js +38 -0
- package/dist/core/agent/turnPolicy.d.ts +11 -0
- package/dist/core/agent/turnPolicy.js +19 -0
- package/dist/core/agent/workState.d.ts +81 -3
- package/dist/core/agent/workState.js +176 -10
- package/dist/core/attachments/imageAttachments.js +90 -42
- package/dist/core/deadline.d.ts +27 -0
- package/dist/core/deadline.js +74 -0
- package/dist/core/io/boundedRead.js +1 -1
- package/dist/core/limits.d.ts +51 -0
- package/dist/core/limits.js +51 -0
- package/dist/core/log/llmLog.js +8 -1
- package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
- package/dist/core/persistence/orderedFileWriter.js +16 -2
- package/dist/core/process/backgroundRegistry.d.ts +2 -3
- package/dist/core/process/backgroundRegistry.js +15 -10
- package/dist/core/process/runBoundedProcess.d.ts +8 -2
- package/dist/core/process/runBoundedProcess.js +15 -6
- package/dist/core/process/userShell.d.ts +16 -0
- package/dist/core/process/userShell.js +59 -0
- package/dist/core/safety/missingExecutable.d.ts +42 -0
- package/dist/core/safety/missingExecutable.js +77 -0
- package/dist/core/safety/shellClassifier.d.ts +11 -0
- package/dist/core/safety/{bashClassifier.js → shellClassifier.js} +5 -3
- package/dist/core/safety/urlGuard.d.ts +1 -1
- package/dist/core/session/sessionSlimming.d.ts +0 -3
- package/dist/core/session/sessionSlimming.js +2 -3
- package/dist/core/session/sessionStore.d.ts +38 -0
- package/dist/core/session/sessionStore.js +242 -59
- package/dist/core/{bashOutput → shellOutput}/lineFilter.js +8 -2
- package/dist/core/{bashOutput → shellOutput}/reducers/search.d.ts +0 -1
- package/dist/core/{bashOutput → shellOutput}/reducers/search.js +1 -1
- package/dist/core/shellOutput/registry.d.ts +2 -0
- package/dist/core/{bashOutput → shellOutput}/registry.js +3 -3
- package/dist/core/{bashOutput → shellOutput}/types.d.ts +6 -5
- package/dist/core/subagent/contracts.d.ts +6 -14
- package/dist/core/subagent/contracts.js +4 -3
- package/dist/core/subagent/executionProfiles.js +2 -2
- package/dist/core/subagent/subagentCoordinator.d.ts +4 -0
- package/dist/core/subagent/subagentCoordinator.js +32 -2
- package/dist/core/subagent/subagentRunner.js +19 -40
- package/dist/core/toolOutput/reduction.d.ts +0 -12
- package/dist/core/toolOutput/reduction.js +1 -1
- package/dist/core/validation/outputParser.d.ts +2 -2
- package/dist/llm/client.d.ts +17 -1
- package/dist/llm/client.js +86 -14
- package/dist/llm/hazeTools.d.ts +693 -204
- package/dist/llm/hazeTools.js +110 -28
- package/dist/llm/initPrompt.js +1 -1
- package/dist/llm/lsp/client.d.ts +45 -0
- package/dist/llm/lsp/client.js +195 -0
- package/dist/llm/lsp/pool.d.ts +23 -0
- package/dist/llm/lsp/pool.js +86 -0
- package/dist/llm/lsp/protocol.d.ts +64 -0
- package/dist/llm/lsp/protocol.js +128 -0
- package/dist/llm/lsp/requests.d.ts +94 -0
- package/dist/llm/lsp/requests.js +119 -0
- package/dist/llm/lspTools.d.ts +5653 -33
- package/dist/llm/lspTools.js +152 -80
- package/dist/llm/openaiCodex.d.ts +1 -0
- package/dist/llm/openaiCodex.js +43 -0
- package/dist/llm/openaiCodexOAuth.d.ts +51 -0
- package/dist/llm/openaiCodexOAuth.js +217 -0
- package/dist/llm/requestContext.d.ts +7 -0
- package/dist/llm/requestContext.js +30 -4
- package/dist/llm/systemPrompt.d.ts +12 -0
- package/dist/llm/systemPrompt.js +24 -11
- package/dist/llm/toolResultTypes.d.ts +7 -14
- package/dist/llm/toolResultTypes.js +1 -4
- package/dist/llm/tools/editMatch.d.ts +14 -9
- package/dist/llm/tools/editMatch.js +73 -1
- package/dist/llm/tools/failures.d.ts +2 -0
- package/dist/llm/tools/failures.js +1 -0
- package/dist/llm/tools/fetchTool.d.ts +16 -0
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +8 -5
- package/dist/llm/tools/fileToolShared.js +22 -23
- package/dist/llm/tools/gitIgnore.d.ts +42 -0
- package/dist/llm/tools/gitIgnore.js +247 -0
- package/dist/llm/tools/grepParse.d.ts +2 -1
- package/dist/llm/tools/grepRunner.d.ts +1 -1
- package/dist/llm/tools/grepRunner.js +2 -2
- package/dist/llm/tools/outputCap.d.ts +2 -7
- package/dist/llm/tools/outputCap.js +3 -3
- package/dist/llm/tools/processTool.d.ts +16 -16
- package/dist/llm/tools/processTool.js +1 -1
- package/dist/llm/tools/readRecovery.d.ts +8 -0
- package/dist/llm/tools/readRecovery.js +135 -0
- package/dist/llm/tools/{bashTool.d.ts → shellTool.d.ts} +171 -123
- package/dist/llm/tools/{bashTool.js → shellTool.js} +20 -14
- package/dist/llm/tools/toolContext.d.ts +1 -1
- package/dist/llm/tools/toolContext.js +66 -37
- package/dist/llm/tools/workspaceFile.d.ts +0 -1
- package/dist/llm/tools/workspaceFile.js +1 -6
- package/dist/llm/webFetch.d.ts +18 -1
- package/dist/llm/webFetch.js +64 -97
- package/dist/skills/SkillLoader.d.ts +1 -11
- package/dist/skills/SkillLoader.js +1 -2
- package/dist/skills/types.d.ts +2 -1
- package/dist/ui/codeHighlight.d.ts +4 -0
- package/dist/ui/codeHighlight.js +31 -0
- package/dist/ui/components/Header.d.ts +1 -1
- package/dist/ui/components/MarkdownText.d.ts +16 -2
- package/dist/ui/components/MarkdownText.js +244 -34
- package/dist/ui/components/TextInput.d.ts +8 -1
- package/dist/ui/components/TextInput.js +6 -2
- package/dist/ui/theme.d.ts +4 -3
- package/dist/ui/theme.js +5 -4
- package/dist/utils/buildInfo.d.ts +97 -0
- package/dist/utils/buildInfo.js +244 -0
- package/dist/utils/fs.d.ts +11 -0
- package/dist/utils/fs.js +91 -26
- package/dist/utils/openPath.d.ts +2 -2
- package/dist/utils/openPath.js +19 -6
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +6 -2
- package/dist/utils/utf8.d.ts +22 -0
- package/dist/utils/utf8.js +54 -0
- package/dist/utils/version.d.ts +9 -3
- package/dist/utils/version.js +28 -2
- package/package.json +28 -21
- package/dist/cli/commands/lspWizard.d.ts +0 -14
- package/dist/cli/commands/lspWizard.js +0 -44
- package/dist/cli/commands/mcpWizard.d.ts +0 -15
- package/dist/cli/commands/skillConfirmRemove.d.ts +0 -11
- package/dist/cli/commands/skillConfirmRemove.js +0 -20
- package/dist/cli/commands/skillCreation.d.ts +0 -12
- package/dist/cli/commands/skillCreation.js +0 -14
- package/dist/cli/commands/skillWizard.d.ts +0 -17
- package/dist/cli/commands/streaming/idleTimer.d.ts +0 -26
- package/dist/cli/commands/streaming/idleTimer.js +0 -24
- package/dist/cli/commands/streaming/turnOutcome.d.ts +0 -10
- package/dist/cli/commands/streaming/turnOutcome.js +0 -13
- package/dist/cli/commands/wizardActions.d.ts +0 -46
- package/dist/cli/commands/wizardActions.js +0 -46
- package/dist/cli/commands/wizardInput.d.ts +0 -4
- package/dist/cli/commands/wizardInput.js +0 -19
- package/dist/cli/commands/wizardPrompts.d.ts +0 -22
- package/dist/cli/commands/wizardPrompts.js +0 -52
- package/dist/cli/commands/wizardSuggestions.d.ts +0 -31
- package/dist/cli/commands/wizardSuggestions.js +0 -188
- package/dist/cli/commands/wizardTransition.d.ts +0 -37
- package/dist/cli/commands/wizardTransition.js +0 -43
- package/dist/core/bashOutput/ansi.d.ts +0 -1
- package/dist/core/bashOutput/ansi.js +0 -7
- package/dist/core/bashOutput/registry.d.ts +0 -4
- package/dist/core/goal/completionPolicy.d.ts +0 -2
- package/dist/core/goal/completionPolicy.js +0 -7
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -18
- package/dist/core/goal/sessionGoal.d.ts +0 -8
- package/dist/core/goal/sessionGoal.js +0 -30
- package/dist/core/limits/byteBudgets.d.ts +0 -18
- package/dist/core/limits/byteBudgets.js +0 -18
- package/dist/core/limits/textBudgets.d.ts +0 -23
- package/dist/core/limits/textBudgets.js +0 -23
- package/dist/core/safety/bashClassifier.d.ts +0 -10
- package/dist/llm/lsp.d.ts +0 -129
- package/dist/llm/lsp.js +0 -307
- package/dist/ui/components/ErrorView.d.ts +0 -4
- package/dist/ui/components/ErrorView.js +0 -7
- package/dist/utils/yaml.d.ts +0 -2
- package/dist/utils/yaml.js +0 -8
- package/examples/skills/files/SKILL.md +0 -16
- package/examples/skills/files/examples/file-editing.md +0 -3
- /package/dist/core/{bashOutput → shellOutput}/command.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/command.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/lineFilter.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/content.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/gh.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/git.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.d.ts +0 -0
- /package/dist/core/{bashOutput → shellOutput}/reducers/validation.js +0 -0
- /package/dist/core/{bashOutput → shellOutput}/types.js +0 -0
|
@@ -1,25 +1,102 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import { updateSettings } from '../../config/settings.js';
|
|
3
|
-
import {
|
|
3
|
+
import { removeProviderAuth, setProviderAuth } from '../../config/providerAuth.js';
|
|
4
|
+
import { findProvider, modelSelector, resolveModelSelector, upsertProvider } from '../../config/providers.js';
|
|
4
5
|
import { discoverProviderModels } from '../../config/modelDiscovery.js';
|
|
5
6
|
import { removeLspServer } from '../../config/lspSettings.js';
|
|
6
7
|
import { removeMcpServer } from '../../config/mcpSettings.js';
|
|
7
|
-
import { findPreset, PROVIDER_PRESETS } from '../../config/providerPresets.js';
|
|
8
|
+
import { findPreset, presetModelLimitsForModels, PROVIDER_PRESETS } from '../../config/providerPresets.js';
|
|
9
|
+
import { ollamaModelLimits } from '../../config/modelDiscovery.js';
|
|
10
|
+
import { isLocalProviderUrl } from '../../llm/client.js';
|
|
11
|
+
import { FALLBACK_LOCAL_CONTEXT_TOKENS } from '../../core/agent/contextBudget.js';
|
|
8
12
|
import { loadSkillRegistry } from '../../skills/SkillRegistry.js';
|
|
9
13
|
import { createSkill, toSkillDirName } from '../../skills/builder/SkillBuilder.js';
|
|
10
|
-
import { PROVIDER_ACTIONS, PROVIDER_CHOICES, MODEL_CHOICES, SERVER_CHOICES } from '../commands/
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { providerActionResult, providerAppendModels, providerFinishAdd, providerRemove, providerRemoveModels, providerSetImageCapable, providerSetKey } from '../commands/providerWizard.js';
|
|
15
|
-
import { selectSkillActionResult, selectSkillResult } from '../commands/skillWizard.js';
|
|
16
|
-
import { captureSkillDescription as captureSkillDescriptionResult, skillCreationFailure, skillCreationMessage } from '../commands/skillCreation.js';
|
|
17
|
-
import { skillConfirmRemoveResult as skillConfirmRemove } from '../commands/skillConfirmRemove.js';
|
|
18
|
-
import { isYesConfirmation } from '../commands/wizardInput.js';
|
|
14
|
+
import { PROVIDER_ACTIONS, PROVIDER_CHOICES, MODEL_CHOICES, SERVER_CHOICES, captureLspName, captureMcpCommand, captureMcpName, captureMcpTransport, captureMcpUrl, captureProviderName, captureProviderUrl, commaList, isYesConfirmation } from '../commands/wizardFlow.js';
|
|
15
|
+
import { finishLspCustomResult, selectLspActionResult, selectLspPresetResult, selectLspServerResult, finishMcpCustomResult, selectMcpActionResult, selectMcpPresetResult, selectMcpServerResult, setMcpServerKeyResult } from '../commands/serverWizard.js';
|
|
16
|
+
import { chatgptCodexUrlWarning, providerActionResult, providerAppendModels, providerFinishAdd, providerRemove, providerRemoveModels, providerSetImageCapable, providerSetKey } from '../commands/providerWizard.js';
|
|
17
|
+
import { selectSkillActionResult, selectSkillResult, captureSkillDescription as captureSkillDescriptionResult, skillCreationFailure, skillCreationMessage, skillConfirmRemoveResult as skillConfirmRemove } from '../commands/skillsWizard.js';
|
|
19
18
|
import { startupProviderInfo } from './startupInfo.js';
|
|
20
19
|
import { SESSION_ACTIONS } from '../commands/sessionPicker.js';
|
|
20
|
+
import { openBrowser, startChatGptBrowserLogin } from '../../llm/openaiCodexOAuth.js';
|
|
21
|
+
export function transitionProviderField(input) {
|
|
22
|
+
if (input.mode === 'providerAddKey') {
|
|
23
|
+
const key = input.value.trim();
|
|
24
|
+
return [
|
|
25
|
+
{ type: 'provider-draft', patch: key ? { key } : {} },
|
|
26
|
+
{ type: 'discover-provider-models', draft: { ...input.draft, ...(key ? { key } : {}) } },
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
const result = input.mode === 'providerAddName' ? captureProviderName(input.settings, input.value)
|
|
30
|
+
: input.mode === 'providerAddUrl' ? captureProviderUrl(input.value)
|
|
31
|
+
: undefined;
|
|
32
|
+
if (!result)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (result.message)
|
|
35
|
+
return [{ type: 'message', text: result.message }];
|
|
36
|
+
const patch = result.draft ?? {};
|
|
37
|
+
return [
|
|
38
|
+
...(Object.keys(patch).length ? [{ type: 'provider-draft', patch, replace: input.mode === 'providerAddName' }] : []),
|
|
39
|
+
...(result.nextMode ? [{ type: 'mode', mode: result.nextMode }] : []),
|
|
40
|
+
{ type: 'message', text: result.systemMessage },
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
export function transitionMcpField(input) {
|
|
44
|
+
const result = input.mode === 'mcpAddName' ? captureMcpName(input.settings, input.value)
|
|
45
|
+
: input.mode === 'mcpAddTransport' ? captureMcpTransport(input.value)
|
|
46
|
+
: input.mode === 'mcpAddUrl' ? captureMcpUrl(input.value)
|
|
47
|
+
: input.mode === 'mcpAddCommand' ? captureMcpCommand(input.value)
|
|
48
|
+
: undefined;
|
|
49
|
+
if (!result)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (result.message)
|
|
52
|
+
return [{ type: 'message', text: result.message }];
|
|
53
|
+
const patch = result.draft ?? {};
|
|
54
|
+
const nextDraft = { ...input.draft, ...patch };
|
|
55
|
+
if (result.nextMode === 'chat' && input.mode === 'mcpAddCommand')
|
|
56
|
+
return [{ type: 'finish-mcp-stdio', draft: nextDraft }];
|
|
57
|
+
return [
|
|
58
|
+
...(Object.keys(patch).length ? [{ type: 'mcp-draft', patch }] : []),
|
|
59
|
+
...(result.nextMode ? [{ type: 'mode', mode: result.nextMode }] : []),
|
|
60
|
+
{ type: 'message', text: result.systemMessage },
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
export function initialWizardUiState() {
|
|
64
|
+
return { discoveredModels: [], suggestedModels: [], providerDraft: {}, skillDraft: {}, lspDraft: {}, mcpDraft: {} };
|
|
65
|
+
}
|
|
66
|
+
export function wizardUiReducer(state, action) {
|
|
67
|
+
switch (action.type) {
|
|
68
|
+
case 'set': return { ...state, [action.key]: action.value };
|
|
69
|
+
case 'providerDraft': return { ...state, providerDraft: action.value };
|
|
70
|
+
case 'skillDraft': return { ...state, skillDraft: action.value };
|
|
71
|
+
case 'lspDraft': return { ...state, lspDraft: action.value };
|
|
72
|
+
case 'mcpDraft': return { ...state, mcpDraft: action.value };
|
|
73
|
+
case 'discoveredModels': return { ...state, discoveredModels: action.value };
|
|
74
|
+
case 'suggestedModels': return { ...state, suggestedModels: action.value };
|
|
75
|
+
case 'reset': return initialWizardUiState();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
21
78
|
export function createWizardDispatch(deps) {
|
|
22
79
|
const { setMode, setSettings, showMessage } = deps;
|
|
80
|
+
// Setter shims over the single wizard-state reducer, so the handler bodies
|
|
81
|
+
// keep the historical per-field setter vocabulary (minimal diff; the
|
|
82
|
+
// dispatch tests mirror React state through updateWizard).
|
|
83
|
+
const setSelectedProviderName = (value) => deps.updateWizard({ type: 'set', key: 'selectedProviderName', value });
|
|
84
|
+
const setSelectedSkillName = (value) => deps.updateWizard({ type: 'set', key: 'selectedSkillName', value });
|
|
85
|
+
const setSelectedLspName = (value) => deps.updateWizard({ type: 'set', key: 'selectedLspName', value });
|
|
86
|
+
const setSelectedMcpName = (value) => deps.updateWizard({ type: 'set', key: 'selectedMcpName', value });
|
|
87
|
+
const setSelectedSessionId = (id) => deps.updateWizard({ type: 'set', key: 'selectedSessionId', value: id });
|
|
88
|
+
const setModelProviderFilter = (value) => deps.updateWizard({ type: 'set', key: 'modelProviderFilter', value });
|
|
89
|
+
const setProviderDraft = (value) => deps.updateWizard({ type: 'providerDraft', value });
|
|
90
|
+
const setSkillDraft = (value) => deps.updateWizard({ type: 'skillDraft', value });
|
|
91
|
+
const setLspDraft = (value) => deps.updateWizard({ type: 'lspDraft', value });
|
|
92
|
+
const setMcpDraft = (value) => deps.updateWizard({ type: 'mcpDraft', value });
|
|
93
|
+
const setDiscoveredModels = (value) => deps.updateWizard({ type: 'discoveredModels', value });
|
|
94
|
+
const setSuggestedModels = (value) => deps.updateWizard({ type: 'suggestedModels', value });
|
|
95
|
+
// Limits harvested from the provider's own /models listing during the most
|
|
96
|
+
// recent discovery. Written through with the models being added (provider-
|
|
97
|
+
// specific and fresher than the static preset catalog) and cleared when a
|
|
98
|
+
// flow restarts, so stale harvests never leak into a later add.
|
|
99
|
+
let lastDiscoveredLimits = {};
|
|
23
100
|
// Shared applier for the uniform wizard result shape (CR-006 / useSettingsPatch).
|
|
24
101
|
async function applyResult(result) {
|
|
25
102
|
if (result.settingsPatch)
|
|
@@ -34,12 +111,12 @@ export function createWizardDispatch(deps) {
|
|
|
34
111
|
setMode('chat');
|
|
35
112
|
return;
|
|
36
113
|
}
|
|
37
|
-
|
|
114
|
+
setSelectedSessionId(id);
|
|
38
115
|
setMode('sessionAction');
|
|
39
116
|
showMessage(`Session ${id}: press Enter to resume, or choose fork.`);
|
|
40
117
|
}
|
|
41
118
|
async function selectSessionAction(action) {
|
|
42
|
-
const id = deps.selectedSessionId;
|
|
119
|
+
const id = deps.wizard.selectedSessionId;
|
|
43
120
|
if (!id) {
|
|
44
121
|
showMessage('No session selected. Start over with /resume.');
|
|
45
122
|
setMode('chat');
|
|
@@ -53,12 +130,12 @@ export function createWizardDispatch(deps) {
|
|
|
53
130
|
showMessage(`Unknown session action: ${action}.`);
|
|
54
131
|
return;
|
|
55
132
|
}
|
|
56
|
-
|
|
133
|
+
setSelectedSessionId(undefined);
|
|
57
134
|
setMode('chat');
|
|
58
135
|
}
|
|
59
136
|
async function selectProvider(providerName) {
|
|
60
137
|
if (providerName === PROVIDER_CHOICES.addProvider) {
|
|
61
|
-
|
|
138
|
+
setProviderDraft({});
|
|
62
139
|
setMode('providerAddPreset');
|
|
63
140
|
showMessage('Choose a provider preset, or select "custom" to enter details manually.');
|
|
64
141
|
return;
|
|
@@ -69,13 +146,52 @@ export function createWizardDispatch(deps) {
|
|
|
69
146
|
setMode('chat');
|
|
70
147
|
return;
|
|
71
148
|
}
|
|
72
|
-
|
|
149
|
+
setSelectedProviderName(provider.name);
|
|
73
150
|
setMode('providerAction');
|
|
74
|
-
|
|
151
|
+
// Surface canonical-endpoint divergence for ChatGPT sign-in providers up
|
|
152
|
+
// front: a hand-edited URL is silently ignored by the Codex fetch (F-14).
|
|
153
|
+
const divergence = chatgptCodexUrlWarning(provider);
|
|
154
|
+
showMessage(`${provider.name}: choose an action.${divergence ? `\n${divergence}` : ''}`);
|
|
155
|
+
}
|
|
156
|
+
async function loginWithChatGpt(input) {
|
|
157
|
+
deps.setBusyLabel('Waiting for ChatGPT sign-in');
|
|
158
|
+
deps.setBusy(true);
|
|
159
|
+
let login;
|
|
160
|
+
try {
|
|
161
|
+
login = await startChatGptBrowserLogin();
|
|
162
|
+
showMessage(`Complete ChatGPT sign-in in your browser.\nIf it does not open, visit:\n${login.url}`);
|
|
163
|
+
await openBrowser(login.url);
|
|
164
|
+
const auth = await login.complete();
|
|
165
|
+
await setProviderAuth(input.name, auth);
|
|
166
|
+
if (input.existing) {
|
|
167
|
+
showMessage(`ChatGPT sign-in updated for ${input.name}.`);
|
|
168
|
+
setSelectedProviderName(undefined);
|
|
169
|
+
setMode('chat');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const provider = { name: input.name, url: input.url, kind: 'chatgpt-codex', models: input.models, ...presetModelLimitsForModels({ name: input.name, url: input.url }, input.models) };
|
|
173
|
+
const next = await updateSettings({ providers: upsertProvider(deps.settings, provider), provider: provider.name, model: undefined });
|
|
174
|
+
setSettings(next);
|
|
175
|
+
setProviderDraft({});
|
|
176
|
+
setSuggestedModels([]);
|
|
177
|
+
setModelProviderFilter(provider.name);
|
|
178
|
+
setMode('model');
|
|
179
|
+
showMessage(`ChatGPT connected as ${provider.name}. Choose a model explicitly.`);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
await login?.close().catch(() => undefined);
|
|
183
|
+
showMessage(`ChatGPT sign-in failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
184
|
+
setProviderDraft({});
|
|
185
|
+
setMode('chat');
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
deps.setBusy(false);
|
|
189
|
+
deps.setBusyLabel(deps.idleBusyLabel);
|
|
190
|
+
}
|
|
75
191
|
}
|
|
76
192
|
async function selectPreset(presetId) {
|
|
77
193
|
if (presetId === PROVIDER_CHOICES.custom) {
|
|
78
|
-
|
|
194
|
+
setProviderDraft({});
|
|
79
195
|
setMode('providerAddName');
|
|
80
196
|
showMessage('Provider name? Example: openrouter, local, lmstudio.');
|
|
81
197
|
return;
|
|
@@ -91,12 +207,15 @@ export function createWizardDispatch(deps) {
|
|
|
91
207
|
if (nameConflict) {
|
|
92
208
|
showMessage(`Provider ${existingName} already exists. Use /provider to manage existing providers.`);
|
|
93
209
|
setMode('chat');
|
|
94
|
-
|
|
210
|
+
setProviderDraft({});
|
|
95
211
|
return;
|
|
96
212
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (preset.
|
|
213
|
+
setProviderDraft({ name: existingName, url: preset.baseUrl, ...(preset.auth === 'chatgpt-oauth' ? { kind: 'chatgpt-codex' } : {}) });
|
|
214
|
+
setSuggestedModels(preset.suggestedModels ?? []);
|
|
215
|
+
if (preset.auth === 'chatgpt-oauth') {
|
|
216
|
+
await loginWithChatGpt({ name: existingName, url: preset.baseUrl, models: preset.suggestedModels ?? [] });
|
|
217
|
+
}
|
|
218
|
+
else if (preset.needsApiKey) {
|
|
100
219
|
setMode('providerAddKey');
|
|
101
220
|
const keyHint = preset.apiKeyHint ?? (preset.apiKeyEnvVar ? `commonly ${preset.apiKeyEnvVar}` : undefined);
|
|
102
221
|
showMessage(`${preset.name} (${preset.baseUrl})\nAPI key${keyHint ? ` (${keyHint})` : ''}?`);
|
|
@@ -112,49 +231,58 @@ export function createWizardDispatch(deps) {
|
|
|
112
231
|
if (!provider) {
|
|
113
232
|
showMessage(`No provider named ${providerName}.`);
|
|
114
233
|
setMode('chat');
|
|
115
|
-
|
|
234
|
+
setSelectedProviderName(undefined);
|
|
116
235
|
return;
|
|
117
236
|
}
|
|
118
237
|
const next = await updateSettings({ provider: provider.name });
|
|
119
238
|
setSettings(next);
|
|
120
|
-
|
|
121
|
-
|
|
239
|
+
setSelectedProviderName(undefined);
|
|
240
|
+
setModelProviderFilter(provider.name);
|
|
122
241
|
setMode('model');
|
|
123
242
|
showMessage(`Provider set to ${provider.name}. Choose a model.`);
|
|
124
243
|
}
|
|
125
244
|
async function selectProviderAction(action) {
|
|
126
|
-
if (!deps.selectedProviderName) {
|
|
245
|
+
if (!deps.wizard.selectedProviderName) {
|
|
127
246
|
setMode('provider');
|
|
128
247
|
return;
|
|
129
248
|
}
|
|
130
|
-
const provider = findProvider(deps.settings, deps.selectedProviderName);
|
|
249
|
+
const provider = findProvider(deps.settings, deps.wizard.selectedProviderName);
|
|
131
250
|
if (!provider) {
|
|
132
|
-
showMessage(`Provider ${deps.selectedProviderName} not found.`);
|
|
251
|
+
showMessage(`Provider ${deps.wizard.selectedProviderName} not found.`);
|
|
133
252
|
setMode('chat');
|
|
134
|
-
|
|
253
|
+
setSelectedProviderName(undefined);
|
|
135
254
|
return;
|
|
136
255
|
}
|
|
137
256
|
if (action === PROVIDER_ACTIONS.useProvider) {
|
|
138
|
-
await useProvider(deps.selectedProviderName);
|
|
257
|
+
await useProvider(deps.wizard.selectedProviderName);
|
|
139
258
|
return;
|
|
140
259
|
}
|
|
141
260
|
if (action === PROVIDER_ACTIONS.markImageCapable || action === PROVIDER_ACTIONS.clearImageCapable) {
|
|
142
|
-
const result = providerSetImageCapable(deps.settings, deps.selectedProviderName, action === PROVIDER_ACTIONS.markImageCapable);
|
|
261
|
+
const result = providerSetImageCapable(deps.settings, deps.wizard.selectedProviderName, action === PROVIDER_ACTIONS.markImageCapable);
|
|
143
262
|
if (result.settingsPatch)
|
|
144
263
|
setSettings(await updateSettings(result.settingsPatch));
|
|
145
|
-
|
|
264
|
+
setSelectedProviderName(undefined);
|
|
146
265
|
setMode('chat');
|
|
147
266
|
showMessage(result.message);
|
|
148
267
|
return;
|
|
149
268
|
}
|
|
150
269
|
if (action === PROVIDER_ACTIONS.addModels) {
|
|
151
|
-
|
|
152
|
-
|
|
270
|
+
setSelectedProviderName(provider.name);
|
|
271
|
+
if (provider.kind === 'chatgpt-codex') {
|
|
272
|
+
setMode('providerAppendModels');
|
|
273
|
+
showMessage(`Comma-separated supported Codex model names to add to ${provider.name}?`);
|
|
274
|
+
}
|
|
275
|
+
else
|
|
276
|
+
await discoverModelsFor(provider, `Comma-separated model names to add to ${provider.name}?`);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (action === PROVIDER_ACTIONS.signInChatGpt && provider.kind === 'chatgpt-codex') {
|
|
280
|
+
await loginWithChatGpt({ name: provider.name, url: provider.url, models: provider.models, existing: provider });
|
|
153
281
|
return;
|
|
154
282
|
}
|
|
155
283
|
const actionResult = providerActionResult(action, provider);
|
|
156
284
|
if ('selectedName' in actionResult)
|
|
157
|
-
|
|
285
|
+
setSelectedProviderName(actionResult.selectedName);
|
|
158
286
|
if (actionResult.mode)
|
|
159
287
|
setMode(actionResult.mode);
|
|
160
288
|
showMessage(actionResult.message);
|
|
@@ -170,6 +298,13 @@ export function createWizardDispatch(deps) {
|
|
|
170
298
|
setMode('chat');
|
|
171
299
|
return;
|
|
172
300
|
}
|
|
301
|
+
const existing = findProvider(deps.settings, target.name);
|
|
302
|
+
if (target.kind === 'chatgpt-codex' || existing?.kind === 'chatgpt-codex') {
|
|
303
|
+
setSelectedProviderName(target.name);
|
|
304
|
+
setMode(existing ? 'providerAppendModels' : 'providerAddModels');
|
|
305
|
+
showMessage(fallbackPrompt);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
173
308
|
deps.setBusyLabel(`Discovering models on ${target.name}`);
|
|
174
309
|
deps.setBusy(true);
|
|
175
310
|
let result;
|
|
@@ -181,20 +316,21 @@ export function createWizardDispatch(deps) {
|
|
|
181
316
|
deps.setBusyLabel(deps.idleBusyLabel);
|
|
182
317
|
}
|
|
183
318
|
if (result.status === 'ok') {
|
|
184
|
-
|
|
319
|
+
setDiscoveredModels(result.models);
|
|
320
|
+
lastDiscoveredLimits = result.modelLimits ?? {};
|
|
185
321
|
setMode('modelPick');
|
|
186
322
|
showMessage(`Found ${result.models.length} model${result.models.length === 1 ? '' : 's'} on ${target.name}. Choose one to add, or select "${MODEL_CHOICES.enterModelNames}".`);
|
|
187
323
|
return;
|
|
188
324
|
}
|
|
189
|
-
|
|
325
|
+
lastDiscoveredLimits = {};
|
|
190
326
|
setMode(existing ? 'providerAppendModels' : 'providerAddModels');
|
|
191
327
|
showMessage(`Could not list models on ${target.name} (${result.error}).\n${fallbackPrompt}`);
|
|
192
328
|
}
|
|
193
329
|
async function selectModel(selector) {
|
|
194
330
|
if (selector === MODEL_CHOICES.addModels) {
|
|
195
|
-
const filteredProvider = deps.modelProviderFilter ? findProvider(deps.settings, deps.modelProviderFilter) : undefined;
|
|
331
|
+
const filteredProvider = deps.wizard.modelProviderFilter ? findProvider(deps.settings, deps.wizard.modelProviderFilter) : undefined;
|
|
196
332
|
if (filteredProvider) {
|
|
197
|
-
|
|
333
|
+
setSelectedProviderName(filteredProvider.name);
|
|
198
334
|
await discoverModelsFor(filteredProvider, `Comma-separated model names to add to ${filteredProvider.name}?`);
|
|
199
335
|
return;
|
|
200
336
|
}
|
|
@@ -202,7 +338,7 @@ export function createWizardDispatch(deps) {
|
|
|
202
338
|
showMessage('Choose a provider to add models to.');
|
|
203
339
|
return;
|
|
204
340
|
}
|
|
205
|
-
const scopedSelector = deps.modelProviderFilter ? `${deps.modelProviderFilter}:${selector}` : selector;
|
|
341
|
+
const scopedSelector = deps.wizard.modelProviderFilter ? `${deps.wizard.modelProviderFilter}:${selector}` : selector;
|
|
206
342
|
const resolved = resolveModelSelector(deps.settings, scopedSelector);
|
|
207
343
|
if (resolved.status === 'ambiguous') {
|
|
208
344
|
showMessage(`Model ${resolved.model} exists on multiple providers: ${resolved.providers.map(provider => modelSelector(provider, resolved.model)).join(', ')}`);
|
|
@@ -214,7 +350,7 @@ export function createWizardDispatch(deps) {
|
|
|
214
350
|
}
|
|
215
351
|
const next = await updateSettings({ provider: resolved.provider.name, model: resolved.model });
|
|
216
352
|
setSettings(next);
|
|
217
|
-
|
|
353
|
+
setModelProviderFilter(undefined);
|
|
218
354
|
setMode('chat');
|
|
219
355
|
showMessage(`Model set to ${resolved.model} on ${resolved.provider.name}.\n\n${startupProviderInfo(next)}`);
|
|
220
356
|
}
|
|
@@ -225,14 +361,15 @@ export function createWizardDispatch(deps) {
|
|
|
225
361
|
setMode('chat');
|
|
226
362
|
return;
|
|
227
363
|
}
|
|
228
|
-
|
|
364
|
+
setSelectedProviderName(provider.name);
|
|
229
365
|
await discoverModelsFor(provider, `Comma-separated model names to add to ${provider.name}?`);
|
|
230
366
|
}
|
|
231
367
|
async function pickModelToAdd(value) {
|
|
232
|
-
const provider = deps.selectedProviderName ? findProvider(deps.settings, deps.selectedProviderName) : undefined;
|
|
368
|
+
const provider = deps.wizard.selectedProviderName ? findProvider(deps.settings, deps.wizard.selectedProviderName) : undefined;
|
|
233
369
|
if (value === MODEL_CHOICES.enterModelNames) {
|
|
234
|
-
|
|
235
|
-
|
|
370
|
+
setDiscoveredModels([]);
|
|
371
|
+
setSuggestedModels([]);
|
|
372
|
+
lastDiscoveredLimits = {};
|
|
236
373
|
if (provider) {
|
|
237
374
|
setMode('providerAppendModels');
|
|
238
375
|
showMessage(`Comma-separated model names to add to ${provider.name}?`);
|
|
@@ -259,13 +396,35 @@ export function createWizardDispatch(deps) {
|
|
|
259
396
|
// Preset match by URL restores curated hints on the cloud key-step path.
|
|
260
397
|
const preset = PROVIDER_PRESETS.find(candidate => draft.url === candidate.baseUrl);
|
|
261
398
|
const hint = preset?.suggestedModels?.length ? ` Example: ${preset.suggestedModels.join(', ')}` : '';
|
|
262
|
-
await discoverModelsFor({ name: draft.name, url: draft.url, key: draft.key }, `Comma-separated model names?${hint}`);
|
|
399
|
+
await discoverModelsFor({ name: draft.name, url: draft.url, key: draft.key, kind: draft.kind }, `Comma-separated model names?${hint}`);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Native Ollama enrichment at save time (the one place that knows the exact
|
|
403
|
+
* model ids being added): /v1/models reports nothing for Ollama, but /api/ps
|
|
404
|
+
* exposes the actually-loaded runtime context and /api/show the model's
|
|
405
|
+
* declared maximum. Probed only for the user's loopback server; the cap for
|
|
406
|
+
* a declared maximum (which may exceed the VRAM-sized effective window) is
|
|
407
|
+
* the user's own local fallback setting, defaulting to 32K. Failures are
|
|
408
|
+
* ignored — providers that are not Ollama simply 404 the /api/* paths.
|
|
409
|
+
*/
|
|
410
|
+
async function localNativeLimits(url, models) {
|
|
411
|
+
if (!url || !isLocalProviderUrl(url) || models.length === 0)
|
|
412
|
+
return {};
|
|
413
|
+
const conservativeCap = deps.settings.localContextWindowFallbackTokens ?? FALLBACK_LOCAL_CONTEXT_TOKENS;
|
|
414
|
+
return await ollamaModelLimits({ baseUrl: url, models, conservativeCap }).catch(() => ({}));
|
|
263
415
|
}
|
|
264
416
|
async function appendModelsToProvider(modelsValue) {
|
|
265
|
-
const
|
|
417
|
+
const provider = deps.wizard.selectedProviderName ? findProvider(deps.settings, deps.wizard.selectedProviderName) : undefined;
|
|
418
|
+
if (provider) {
|
|
419
|
+
const native = await localNativeLimits(provider.url, commaList(modelsValue));
|
|
420
|
+
if (Object.keys(native).length > 0)
|
|
421
|
+
lastDiscoveredLimits = { ...lastDiscoveredLimits, ...native };
|
|
422
|
+
}
|
|
423
|
+
const result = providerAppendModels(deps.settings, deps.wizard.selectedProviderName, modelsValue, lastDiscoveredLimits);
|
|
266
424
|
if (!result.provider) {
|
|
267
|
-
|
|
268
|
-
|
|
425
|
+
setDiscoveredModels([]);
|
|
426
|
+
setSuggestedModels([]);
|
|
427
|
+
lastDiscoveredLimits = {};
|
|
269
428
|
showMessage(result.message);
|
|
270
429
|
setMode('chat');
|
|
271
430
|
return;
|
|
@@ -276,34 +435,40 @@ export function createWizardDispatch(deps) {
|
|
|
276
435
|
}
|
|
277
436
|
const next = await updateSettings(result.settingsPatch);
|
|
278
437
|
setSettings(next);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
438
|
+
setSelectedProviderName(undefined);
|
|
439
|
+
setDiscoveredModels([]);
|
|
440
|
+
setSuggestedModels([]);
|
|
441
|
+
lastDiscoveredLimits = {};
|
|
442
|
+
setModelProviderFilter(result.provider.name);
|
|
283
443
|
setMode('model');
|
|
284
444
|
showMessage(result.message);
|
|
285
445
|
}
|
|
286
446
|
async function finishProviderAdd(modelsValue) {
|
|
287
|
-
const
|
|
447
|
+
const native = await localNativeLimits(deps.wizard.providerDraft.url, commaList(modelsValue));
|
|
448
|
+
if (Object.keys(native).length > 0)
|
|
449
|
+
lastDiscoveredLimits = { ...lastDiscoveredLimits, ...native };
|
|
450
|
+
const result = providerFinishAdd(deps.settings, deps.wizard.providerDraft, modelsValue, lastDiscoveredLimits);
|
|
288
451
|
if (!result.provider || !result.settingsPatch) {
|
|
289
452
|
showMessage(result.message);
|
|
290
453
|
setMode('chat');
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
454
|
+
setProviderDraft({});
|
|
455
|
+
setDiscoveredModels([]);
|
|
456
|
+
setSuggestedModels([]);
|
|
457
|
+
lastDiscoveredLimits = {};
|
|
294
458
|
return;
|
|
295
459
|
}
|
|
296
460
|
const next = await updateSettings(result.settingsPatch);
|
|
297
461
|
setSettings(next);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
462
|
+
setProviderDraft({});
|
|
463
|
+
setDiscoveredModels([]);
|
|
464
|
+
setSuggestedModels([]);
|
|
465
|
+
lastDiscoveredLimits = {};
|
|
466
|
+
setModelProviderFilter(result.provider.name);
|
|
302
467
|
setMode('model');
|
|
303
468
|
showMessage(result.message);
|
|
304
469
|
}
|
|
305
470
|
async function providerSetKeyMode(value) {
|
|
306
|
-
const result = providerSetKey(deps.settings, deps.selectedProviderName, value);
|
|
471
|
+
const result = providerSetKey(deps.settings, deps.wizard.selectedProviderName, value);
|
|
307
472
|
if (!result.provider) {
|
|
308
473
|
showMessage(result.message);
|
|
309
474
|
setMode('chat');
|
|
@@ -314,12 +479,12 @@ export function createWizardDispatch(deps) {
|
|
|
314
479
|
return;
|
|
315
480
|
}
|
|
316
481
|
setSettings(await updateSettings(result.settingsPatch));
|
|
317
|
-
|
|
482
|
+
setSelectedProviderName(undefined);
|
|
318
483
|
setMode('chat');
|
|
319
484
|
showMessage(result.message);
|
|
320
485
|
}
|
|
321
486
|
async function providerRemoveModelsMode(value) {
|
|
322
|
-
const result = providerRemoveModels(deps.settings, deps.selectedProviderName, value);
|
|
487
|
+
const result = providerRemoveModels(deps.settings, deps.wizard.selectedProviderName, value);
|
|
323
488
|
if (!result.provider) {
|
|
324
489
|
showMessage(result.message);
|
|
325
490
|
setMode('chat');
|
|
@@ -331,12 +496,12 @@ export function createWizardDispatch(deps) {
|
|
|
331
496
|
}
|
|
332
497
|
const next = await updateSettings(result.settingsPatch);
|
|
333
498
|
setSettings(next);
|
|
334
|
-
|
|
499
|
+
setSelectedProviderName(undefined);
|
|
335
500
|
setMode('chat');
|
|
336
501
|
showMessage(result.message);
|
|
337
502
|
}
|
|
338
503
|
async function providerConfirmRemoveMode(value) {
|
|
339
|
-
const provider = deps.selectedProviderName ? findProvider(deps.settings, deps.selectedProviderName) : undefined;
|
|
504
|
+
const provider = deps.wizard.selectedProviderName ? findProvider(deps.settings, deps.wizard.selectedProviderName) : undefined;
|
|
340
505
|
if (!provider) {
|
|
341
506
|
showMessage('No provider selected.');
|
|
342
507
|
setMode('chat');
|
|
@@ -344,33 +509,34 @@ export function createWizardDispatch(deps) {
|
|
|
344
509
|
}
|
|
345
510
|
if (!isYesConfirmation(value)) {
|
|
346
511
|
showMessage('Cancelled. Provider not removed.');
|
|
347
|
-
|
|
512
|
+
setSelectedProviderName(undefined);
|
|
348
513
|
setMode('chat');
|
|
349
514
|
return;
|
|
350
515
|
}
|
|
351
|
-
const result = providerRemove(deps.settings, deps.selectedProviderName);
|
|
516
|
+
const result = providerRemove(deps.settings, deps.wizard.selectedProviderName);
|
|
352
517
|
const next = await updateSettings(result.settingsPatch ?? {});
|
|
518
|
+
await removeProviderAuth(provider.name);
|
|
353
519
|
setSettings(next);
|
|
354
|
-
|
|
520
|
+
setSelectedProviderName(undefined);
|
|
355
521
|
setMode('chat');
|
|
356
522
|
showMessage(result.message);
|
|
357
523
|
}
|
|
358
524
|
async function selectSkill(name) {
|
|
359
525
|
const result = selectSkillResult(deps.skills, name);
|
|
360
526
|
if (result.clearDraft)
|
|
361
|
-
|
|
527
|
+
setSkillDraft({});
|
|
362
528
|
if ('selectedName' in result)
|
|
363
|
-
|
|
529
|
+
setSelectedSkillName(result.selectedName);
|
|
364
530
|
if (result.mode)
|
|
365
531
|
setMode(result.mode);
|
|
366
532
|
showMessage(result.message);
|
|
367
533
|
}
|
|
368
534
|
async function selectSkillAction(action) {
|
|
369
|
-
const result = selectSkillActionResult(deps.settings, deps.skills, deps.selectedSkillName, action);
|
|
535
|
+
const result = selectSkillActionResult(deps.settings, deps.skills, deps.wizard.selectedSkillName, action);
|
|
370
536
|
if (result.settingsPatch)
|
|
371
537
|
setSettings(await updateSettings(result.settingsPatch));
|
|
372
538
|
if ('selectedName' in result)
|
|
373
|
-
|
|
539
|
+
setSelectedSkillName(result.selectedName);
|
|
374
540
|
if (result.mode)
|
|
375
541
|
setMode(result.mode);
|
|
376
542
|
if (result.validate && result.skill) {
|
|
@@ -393,7 +559,7 @@ export function createWizardDispatch(deps) {
|
|
|
393
559
|
showMessage('Skill name must contain at least one letter or number. Try again, or press ESC to cancel.');
|
|
394
560
|
return;
|
|
395
561
|
}
|
|
396
|
-
|
|
562
|
+
setSkillDraft({ ...deps.wizard.skillDraft, name: dirName });
|
|
397
563
|
setMode('skillsAddScope');
|
|
398
564
|
showMessage(`Where should "${dirName}" be created? Choose this project or global explicitly.`);
|
|
399
565
|
}
|
|
@@ -404,9 +570,9 @@ export function createWizardDispatch(deps) {
|
|
|
404
570
|
showMessage('Choose "this project" or "global".');
|
|
405
571
|
return;
|
|
406
572
|
}
|
|
407
|
-
const name = deps.skillDraft.name;
|
|
573
|
+
const name = deps.wizard.skillDraft.name;
|
|
408
574
|
if (!name) {
|
|
409
|
-
|
|
575
|
+
setSkillDraft({});
|
|
410
576
|
setMode('chat');
|
|
411
577
|
showMessage('Skill wizard lost the name. Start over with /skills.');
|
|
412
578
|
return;
|
|
@@ -416,25 +582,25 @@ export function createWizardDispatch(deps) {
|
|
|
416
582
|
showMessage(`A ${scope} skill named "${name}" already exists. Choose another scope or press ESC to cancel.`);
|
|
417
583
|
return;
|
|
418
584
|
}
|
|
419
|
-
|
|
585
|
+
setSkillDraft({ ...deps.wizard.skillDraft, scope });
|
|
420
586
|
setMode('skillsAddDescription');
|
|
421
587
|
showMessage(`Describe what "${name}" should do. This is the work the LLM will expand into the skill body.`);
|
|
422
588
|
}
|
|
423
589
|
async function captureSkillDescription(value) {
|
|
424
|
-
const result = captureSkillDescriptionResult(value, deps.skillDraft.name);
|
|
590
|
+
const result = captureSkillDescriptionResult(value, deps.wizard.skillDraft.name);
|
|
425
591
|
if (result.message)
|
|
426
592
|
showMessage(result.message);
|
|
427
593
|
if (result.mode === 'chat')
|
|
428
594
|
setMode('chat');
|
|
429
595
|
if (result.clearDraft)
|
|
430
|
-
|
|
596
|
+
setSkillDraft({});
|
|
431
597
|
if (result.description && result.draftName) {
|
|
432
598
|
const name = result.draftName;
|
|
433
599
|
const description = result.description;
|
|
434
600
|
deps.setBusyLabel(result.busyLabel ?? 'Creating skill');
|
|
435
601
|
deps.setBusy(true);
|
|
436
602
|
try {
|
|
437
|
-
const created = await createSkill({ name, description, scope: deps.skillDraft.scope ?? 'global' });
|
|
603
|
+
const created = await createSkill({ name, description, scope: deps.wizard.skillDraft.scope ?? 'global' });
|
|
438
604
|
showMessage(skillCreationMessage(created.name, created.file));
|
|
439
605
|
await deps.refreshSkills();
|
|
440
606
|
}
|
|
@@ -448,11 +614,11 @@ export function createWizardDispatch(deps) {
|
|
|
448
614
|
}
|
|
449
615
|
}
|
|
450
616
|
async function skillsConfirmRemoveMode(value) {
|
|
451
|
-
const result = skillConfirmRemove(deps.settings, deps.skills, deps.selectedSkillName, value);
|
|
617
|
+
const result = skillConfirmRemove(deps.settings, deps.skills, deps.wizard.selectedSkillName, value);
|
|
452
618
|
if (result.message)
|
|
453
619
|
showMessage(result.message);
|
|
454
620
|
if (result.selectedName === undefined)
|
|
455
|
-
|
|
621
|
+
setSelectedSkillName(undefined);
|
|
456
622
|
if (result.mode === 'chat')
|
|
457
623
|
setMode('chat');
|
|
458
624
|
if (result.removedDir)
|
|
@@ -465,37 +631,37 @@ export function createWizardDispatch(deps) {
|
|
|
465
631
|
async function selectLspServer(serverName) {
|
|
466
632
|
const result = selectLspServerResult(deps.settings, serverName);
|
|
467
633
|
if (result.clearDraft)
|
|
468
|
-
|
|
634
|
+
setLspDraft({});
|
|
469
635
|
if (serverName === SERVER_CHOICES.addServer)
|
|
470
636
|
setMode('lspAddPreset');
|
|
471
637
|
else if (result.mode)
|
|
472
638
|
setMode(result.mode);
|
|
473
639
|
if (result.selectedName !== undefined)
|
|
474
|
-
|
|
640
|
+
setSelectedLspName(result.selectedName);
|
|
475
641
|
showMessage(result.message);
|
|
476
642
|
}
|
|
477
643
|
async function selectLspPreset(presetId) {
|
|
478
644
|
const result = selectLspPresetResult(deps.settings, presetId);
|
|
479
645
|
if (result.clearDraft)
|
|
480
|
-
|
|
646
|
+
setLspDraft({});
|
|
481
647
|
await applyResult(result);
|
|
482
648
|
}
|
|
483
649
|
async function selectLspAction(action) {
|
|
484
|
-
const result = selectLspActionResult(deps.settings, deps.selectedLspName, action);
|
|
650
|
+
const result = selectLspActionResult(deps.settings, deps.wizard.selectedLspName, action);
|
|
485
651
|
if (result.settingsPatch)
|
|
486
652
|
setSettings(await updateSettings(result.settingsPatch));
|
|
487
653
|
if ('selectedName' in result)
|
|
488
|
-
|
|
654
|
+
setSelectedLspName(result.selectedName);
|
|
489
655
|
if (result.mode)
|
|
490
656
|
setMode(result.mode);
|
|
491
657
|
showMessage(result.message);
|
|
492
658
|
}
|
|
493
659
|
async function finishLspCustom(commandLine) {
|
|
494
|
-
const result = finishLspCustomResult(deps.settings, deps.lspDraft.name, commandLine);
|
|
660
|
+
const result = finishLspCustomResult(deps.settings, deps.wizard.lspDraft.name, commandLine);
|
|
495
661
|
if (result.settingsPatch)
|
|
496
662
|
setSettings(await updateSettings(result.settingsPatch));
|
|
497
663
|
if (result.clearDraft)
|
|
498
|
-
|
|
664
|
+
setLspDraft({});
|
|
499
665
|
if (result.mode)
|
|
500
666
|
setMode(result.mode);
|
|
501
667
|
showMessage(result.message);
|
|
@@ -507,97 +673,106 @@ export function createWizardDispatch(deps) {
|
|
|
507
673
|
return;
|
|
508
674
|
}
|
|
509
675
|
if (result.draft)
|
|
510
|
-
|
|
676
|
+
setLspDraft({ name: result.draft.name });
|
|
511
677
|
if (result.nextMode)
|
|
512
678
|
setMode(result.nextMode);
|
|
513
679
|
showMessage(result.systemMessage);
|
|
514
680
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
681
|
+
/**
|
|
682
|
+
* Generic typed-"yes" confirm-remove step shared by the LSP and MCP flows.
|
|
683
|
+
* Cancel and no-selection paths are identical; `remove` applies the domain
|
|
684
|
+
* settings mutation and returns the success message.
|
|
685
|
+
*/
|
|
686
|
+
function confirmRemoveStep(input) {
|
|
687
|
+
return async (value) => {
|
|
688
|
+
const name = input.selectedName();
|
|
689
|
+
if (!name) {
|
|
690
|
+
setMode('chat');
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
if (!isYesConfirmation(value)) {
|
|
694
|
+
showMessage(input.cancelMessage);
|
|
695
|
+
input.clearSelection();
|
|
696
|
+
setMode('chat');
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
showMessage(await input.remove(name));
|
|
700
|
+
input.clearSelection();
|
|
523
701
|
setMode('chat');
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
const lspConfirmRemoveMode = confirmRemoveStep({
|
|
705
|
+
selectedName: () => deps.wizard.selectedLspName,
|
|
706
|
+
cancelMessage: 'Cancelled. LSP server not removed.',
|
|
707
|
+
clearSelection: () => setSelectedLspName(undefined),
|
|
708
|
+
remove: async (name) => {
|
|
709
|
+
const next = await updateSettings({ lspServers: removeLspServer(deps.settings, name) });
|
|
710
|
+
setSettings(next);
|
|
711
|
+
return `Removed LSP server ${name}.`;
|
|
712
|
+
},
|
|
713
|
+
});
|
|
714
|
+
const mcpConfirmRemoveMode = confirmRemoveStep({
|
|
715
|
+
selectedName: () => deps.wizard.selectedMcpName,
|
|
716
|
+
cancelMessage: 'Cancelled. MCP server not removed.',
|
|
717
|
+
clearSelection: () => setSelectedMcpName(undefined),
|
|
718
|
+
remove: async (name) => {
|
|
719
|
+
const next = await updateSettings({ mcpServers: removeMcpServer(deps.settings, name) });
|
|
720
|
+
setSettings(next);
|
|
721
|
+
return `Removed MCP server ${name}.`;
|
|
722
|
+
},
|
|
723
|
+
});
|
|
532
724
|
async function selectMcpServer(serverName) {
|
|
533
725
|
const result = selectMcpServerResult(deps.settings, serverName);
|
|
534
726
|
if (result.clearDraft)
|
|
535
|
-
|
|
727
|
+
setMcpDraft({});
|
|
536
728
|
if (serverName === SERVER_CHOICES.addServer)
|
|
537
729
|
setMode('mcpAddPreset');
|
|
538
730
|
else if (result.mode)
|
|
539
731
|
setMode(result.mode);
|
|
540
732
|
if (result.selectedName !== undefined)
|
|
541
|
-
|
|
733
|
+
setSelectedMcpName(result.selectedName);
|
|
542
734
|
showMessage(result.message);
|
|
543
735
|
}
|
|
544
736
|
async function selectMcpPreset(presetId) {
|
|
545
737
|
const result = selectMcpPresetResult(deps.settings, presetId);
|
|
546
738
|
if (result.clearDraft)
|
|
547
|
-
|
|
739
|
+
setMcpDraft({});
|
|
548
740
|
if (result.draft)
|
|
549
|
-
|
|
741
|
+
setMcpDraft(result.draft);
|
|
550
742
|
if (result.mode)
|
|
551
743
|
setMode(result.mode);
|
|
552
744
|
showMessage(result.message);
|
|
553
745
|
}
|
|
554
746
|
async function selectMcpAction(action) {
|
|
555
|
-
const result = selectMcpActionResult(deps.settings, deps.selectedMcpName, action);
|
|
747
|
+
const result = selectMcpActionResult(deps.settings, deps.wizard.selectedMcpName, action);
|
|
556
748
|
if (result.settingsPatch)
|
|
557
749
|
setSettings(await updateSettings(result.settingsPatch));
|
|
558
750
|
if ('selectedName' in result)
|
|
559
|
-
|
|
751
|
+
setSelectedMcpName(result.selectedName);
|
|
560
752
|
if (result.mode)
|
|
561
753
|
setMode(result.mode);
|
|
562
754
|
showMessage(result.message);
|
|
563
755
|
}
|
|
564
|
-
async function finishMcpCustom(keyValue, draft = deps.mcpDraft) {
|
|
756
|
+
async function finishMcpCustom(keyValue, draft = deps.wizard.mcpDraft) {
|
|
565
757
|
const result = finishMcpCustomResult(deps.settings, draft, keyValue);
|
|
566
758
|
if (result.settingsPatch)
|
|
567
759
|
setSettings(await updateSettings(result.settingsPatch));
|
|
568
760
|
if (result.clearDraft)
|
|
569
|
-
|
|
761
|
+
setMcpDraft({});
|
|
570
762
|
if (result.mode)
|
|
571
763
|
setMode(result.mode);
|
|
572
764
|
showMessage(result.message);
|
|
573
765
|
}
|
|
574
766
|
async function setMcpServerKey(keyValue) {
|
|
575
|
-
const result = setMcpServerKeyResult(deps.settings, deps.selectedMcpName, keyValue);
|
|
767
|
+
const result = setMcpServerKeyResult(deps.settings, deps.wizard.selectedMcpName, keyValue);
|
|
576
768
|
if (result.settingsPatch)
|
|
577
769
|
setSettings(await updateSettings(result.settingsPatch));
|
|
578
770
|
if ('selectedName' in result)
|
|
579
|
-
|
|
771
|
+
setSelectedMcpName(result.selectedName);
|
|
580
772
|
if (result.mode)
|
|
581
773
|
setMode(result.mode);
|
|
582
774
|
showMessage(result.message);
|
|
583
775
|
}
|
|
584
|
-
async function mcpConfirmRemoveMode(value) {
|
|
585
|
-
if (!deps.selectedMcpName) {
|
|
586
|
-
setMode('chat');
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
if (!isYesConfirmation(value)) {
|
|
590
|
-
showMessage('Cancelled. MCP server not removed.');
|
|
591
|
-
deps.setSelectedMcpName(undefined);
|
|
592
|
-
setMode('chat');
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
const next = await updateSettings({ mcpServers: removeMcpServer(deps.settings, deps.selectedMcpName) });
|
|
596
|
-
setSettings(next);
|
|
597
|
-
showMessage(`Removed MCP server ${deps.selectedMcpName}.`);
|
|
598
|
-
deps.setSelectedMcpName(undefined);
|
|
599
|
-
setMode('chat');
|
|
600
|
-
}
|
|
601
776
|
const handlers = {
|
|
602
777
|
sessions: selectSession,
|
|
603
778
|
sessionAction: selectSessionAction,
|
|
@@ -631,8 +806,49 @@ export function createWizardDispatch(deps) {
|
|
|
631
806
|
mcpSetKey: setMcpServerKey,
|
|
632
807
|
mcpConfirmRemove: mcpConfirmRemoveMode,
|
|
633
808
|
};
|
|
809
|
+
/** Apply one field-transition effect at the submit boundary (was chat.tsx inline branching). */
|
|
810
|
+
async function applyProviderEffect(effect) {
|
|
811
|
+
if (effect.type === 'message')
|
|
812
|
+
showMessage(effect.text);
|
|
813
|
+
else if (effect.type === 'mode')
|
|
814
|
+
setMode(effect.mode);
|
|
815
|
+
else if (effect.type === 'provider-draft') {
|
|
816
|
+
if (effect.replace)
|
|
817
|
+
setProviderDraft(effect.patch);
|
|
818
|
+
else
|
|
819
|
+
setProviderDraft({ ...deps.wizard.providerDraft, ...effect.patch });
|
|
820
|
+
}
|
|
821
|
+
else if (effect.type === 'discover-provider-models') {
|
|
822
|
+
// The draft patch above is still pending React state, so discovery
|
|
823
|
+
// receives the merged draft explicitly (same pattern as MCP stdio).
|
|
824
|
+
await discoverProviderModelsForDraft(effect.draft);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
async function applyMcpEffect(effect) {
|
|
828
|
+
if (effect.type === 'message')
|
|
829
|
+
showMessage(effect.text);
|
|
830
|
+
else if (effect.type === 'mode')
|
|
831
|
+
setMode(effect.mode);
|
|
832
|
+
else if (effect.type === 'mcp-draft')
|
|
833
|
+
setMcpDraft({ ...deps.wizard.mcpDraft, ...effect.patch });
|
|
834
|
+
else if (effect.type === 'finish-mcp-stdio')
|
|
835
|
+
await finishMcpCustom(undefined, effect.draft);
|
|
836
|
+
}
|
|
634
837
|
return {
|
|
635
838
|
async dispatch(mode, value) {
|
|
839
|
+
// Field-capture steps first (same order chat.tsx used), then the submit table.
|
|
840
|
+
const providerEffects = transitionProviderField({ mode, value, settings: deps.settings, draft: deps.wizard.providerDraft });
|
|
841
|
+
if (providerEffects) {
|
|
842
|
+
for (const effect of providerEffects)
|
|
843
|
+
await applyProviderEffect(effect);
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
const mcpEffects = transitionMcpField({ mode, value, settings: deps.settings, draft: deps.wizard.mcpDraft });
|
|
847
|
+
if (mcpEffects) {
|
|
848
|
+
for (const effect of mcpEffects)
|
|
849
|
+
await applyMcpEffect(effect);
|
|
850
|
+
return true;
|
|
851
|
+
}
|
|
636
852
|
const handler = handlers[mode];
|
|
637
853
|
if (!handler)
|
|
638
854
|
return false;
|