@denizokcu/haze 0.8.0 → 0.10.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 +67 -17
- package/README.md +121 -64
- package/dist/cli/chat/chatMetrics.d.ts +17 -1
- package/dist/cli/chat/chatMetrics.js +22 -5
- package/dist/cli/chat/contextReport.d.ts +11 -0
- package/dist/cli/chat/contextReport.js +44 -0
- package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
- package/dist/cli/chat/fileMentionSuggestions.js +91 -0
- package/dist/cli/chat/inputSuggestions.d.ts +5 -0
- package/dist/cli/chat/inputSuggestions.js +17 -3
- package/dist/cli/chat/sessionLifecycle.d.ts +58 -0
- package/dist/cli/chat/sessionLifecycle.js +155 -0
- package/dist/cli/chat/sessionRecorder.d.ts +3 -0
- package/dist/cli/chat/sessionRecorder.js +21 -8
- package/dist/cli/chat/startupInfo.d.ts +1 -0
- package/dist/cli/chat/startupInfo.js +11 -0
- package/dist/cli/chat/tips.d.ts +21 -0
- package/dist/cli/chat/tips.js +43 -0
- package/dist/cli/chat/wizardDispatch.d.ts +64 -0
- package/dist/cli/chat/wizardDispatch.js +645 -0
- package/dist/cli/commands/chat.d.ts +1 -0
- package/dist/cli/commands/chat.js +246 -779
- package/dist/cli/commands/chatModes.d.ts +1 -1
- package/dist/cli/commands/chatModes.js +7 -2
- package/dist/cli/commands/commandHelp.js +5 -3
- package/dist/cli/commands/commands.d.ts +4 -3
- package/dist/cli/commands/commands.js +12 -13
- package/dist/cli/commands/fleetCommand.d.ts +14 -0
- package/dist/cli/commands/fleetCommand.js +46 -0
- package/dist/cli/commands/formatters.d.ts +5 -0
- package/dist/cli/commands/formatters.js +36 -9
- package/dist/cli/commands/logsCommand.js +8 -28
- package/dist/cli/commands/mcpWizard.js +24 -2
- package/dist/cli/commands/modelCommand.js +1 -1
- package/dist/cli/commands/providerWizard.d.ts +1 -0
- package/dist/cli/commands/providerWizard.js +31 -5
- package/dist/cli/commands/runCommand.d.ts +1 -0
- package/dist/cli/commands/runCommand.js +32 -20
- package/dist/cli/commands/sessionPicker.d.ts +9 -0
- package/dist/cli/commands/sessionPicker.js +29 -0
- package/dist/cli/commands/settingsSummary.js +8 -4
- package/dist/cli/commands/skillConfirmRemove.js +4 -3
- package/dist/cli/commands/skillWizard.d.ts +2 -0
- package/dist/cli/commands/skillWizard.js +16 -6
- package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
- package/dist/cli/commands/streaming/idleTimer.js +24 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +2 -0
- package/dist/cli/commands/streaming/toolGroupRenderer.js +4 -2
- package/dist/cli/commands/streaming/turnOutcome.d.ts +10 -0
- package/dist/cli/commands/streaming/turnOutcome.js +13 -0
- package/dist/cli/commands/streaming/turnRuntime.js +6 -4
- package/dist/cli/commands/streaming.d.ts +13 -1
- package/dist/cli/commands/streaming.js +104 -44
- package/dist/cli/commands/wizardActions.d.ts +6 -0
- package/dist/cli/commands/wizardActions.js +6 -0
- package/dist/cli/commands/wizardPrompts.js +1 -1
- package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
- package/dist/cli/commands/wizardSuggestions.js +62 -13
- package/dist/cli/commands/wizardTransition.d.ts +37 -0
- package/dist/cli/commands/wizardTransition.js +43 -0
- package/dist/cli/index.js +17 -3
- package/dist/cli/terminalTitle.d.ts +6 -0
- package/dist/cli/terminalTitle.js +36 -0
- package/dist/config/contextFiles.js +6 -3
- package/dist/config/endpointSecurity.d.ts +2 -0
- package/dist/config/endpointSecurity.js +28 -0
- package/dist/config/inputHistory.d.ts +3 -3
- package/dist/config/inputHistory.js +13 -17
- package/dist/config/modelDiscovery.d.ts +20 -0
- package/dist/config/modelDiscovery.js +51 -0
- package/dist/config/privateStorage.d.ts +6 -0
- package/dist/config/privateStorage.js +61 -0
- package/dist/config/providerPresets.d.ts +16 -4
- package/dist/config/providerPresets.js +263 -34
- package/dist/config/providers.d.ts +2 -0
- package/dist/config/providers.js +7 -0
- package/dist/config/settings.d.ts +22 -0
- package/dist/config/settings.js +33 -5
- package/dist/config/skillSettings.d.ts +6 -13
- package/dist/config/skillSettings.js +20 -19
- package/dist/config/updateCheck.js +4 -2
- package/dist/core/agent/budgets.d.ts +26 -0
- package/dist/core/agent/budgets.js +34 -0
- package/dist/core/agent/compaction.js +17 -3
- package/dist/core/agent/contextBudget.d.ts +8 -0
- package/dist/core/agent/contextBudget.js +29 -0
- package/dist/core/agent/errors.js +6 -2
- package/dist/core/agent/events.d.ts +12 -0
- package/dist/core/agent/toolOutputStore.d.ts +8 -0
- package/dist/core/agent/toolOutputStore.js +49 -11
- package/dist/core/agent/workState.d.ts +1 -1
- package/dist/core/agent/workState.js +0 -4
- package/dist/core/attachments/imageAttachments.d.ts +90 -0
- package/dist/core/attachments/imageAttachments.js +245 -0
- package/dist/core/attachments/readBlessings.d.ts +37 -0
- package/dist/core/attachments/readBlessings.js +79 -0
- package/dist/core/goal/completionPolicy.d.ts +0 -28
- package/dist/core/goal/completionPolicy.js +0 -88
- package/dist/core/goal/requestClassifier.d.ts +0 -3
- package/dist/core/goal/requestClassifier.js +0 -13
- package/dist/core/io/boundedRead.d.ts +15 -0
- package/dist/core/io/boundedRead.js +144 -0
- package/dist/core/limits/byteBudgets.d.ts +18 -0
- package/dist/core/limits/byteBudgets.js +18 -0
- package/dist/core/limits/textBudgets.d.ts +23 -0
- package/dist/core/limits/textBudgets.js +23 -0
- package/dist/core/log/llmLog.d.ts +10 -0
- package/dist/core/log/llmLog.js +59 -13
- package/dist/core/persistence/orderedFileWriter.d.ts +11 -0
- package/dist/core/persistence/orderedFileWriter.js +29 -0
- package/dist/core/process/backgroundRegistry.d.ts +35 -0
- package/dist/core/process/backgroundRegistry.js +194 -0
- package/dist/core/process/runBoundedProcess.d.ts +30 -0
- package/dist/core/process/runBoundedProcess.js +116 -0
- package/dist/core/safety/urlGuard.d.ts +2 -1
- package/dist/core/safety/urlGuard.js +3 -2
- package/dist/core/session/sessionSlimming.js +47 -4
- package/dist/core/session/sessionStore.d.ts +37 -0
- package/dist/core/session/sessionStore.js +136 -27
- package/dist/core/subagent/contracts.d.ts +116 -0
- package/dist/core/subagent/contracts.js +54 -0
- package/dist/core/subagent/executionProfiles.d.ts +28 -0
- package/dist/core/subagent/executionProfiles.js +45 -0
- package/dist/core/subagent/subagentCoordinator.d.ts +74 -0
- package/dist/core/subagent/subagentCoordinator.js +134 -0
- package/dist/core/subagent/subagentRunner.d.ts +211 -145
- package/dist/core/subagent/subagentRunner.js +228 -98
- package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
- package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
- package/dist/core/tasks/taskStorage.js +12 -1
- package/dist/llm/client.d.ts +20 -29
- package/dist/llm/client.js +33 -29
- package/dist/llm/hazeTools.d.ts +2396 -67
- package/dist/llm/hazeTools.js +50 -37
- package/dist/llm/lsp.d.ts +23 -3
- package/dist/llm/lsp.js +73 -16
- package/dist/llm/lspTools.d.ts +96 -48
- package/dist/llm/mcp.d.ts +1 -1
- package/dist/llm/mcp.js +65 -16
- package/dist/llm/requestContext.d.ts +23 -1
- package/dist/llm/requestContext.js +50 -7
- package/dist/llm/systemPrompt.d.ts +4 -1
- package/dist/llm/systemPrompt.js +14 -4
- package/dist/llm/toolResultTypes.d.ts +1 -1
- package/dist/llm/tools/bashTool.d.ts +1210 -16
- package/dist/llm/tools/bashTool.js +43 -60
- package/dist/llm/tools/fetchTool.d.ts +26 -26
- package/dist/llm/tools/fetchTool.js +1 -1
- package/dist/llm/tools/fileToolShared.d.ts +2 -1
- package/dist/llm/tools/fileToolShared.js +5 -5
- package/dist/llm/tools/grepRunner.d.ts +20 -0
- package/dist/llm/tools/grepRunner.js +66 -0
- package/dist/llm/tools/outputCap.d.ts +2 -6
- package/dist/llm/tools/outputCap.js +2 -6
- package/dist/llm/tools/processTool.d.ts +1077 -0
- package/dist/llm/tools/processTool.js +41 -0
- package/dist/llm/tools/toolContext.d.ts +8 -0
- package/dist/llm/tools/toolContext.js +22 -11
- package/dist/llm/tools/workspaceFile.d.ts +9 -1
- package/dist/llm/tools/workspaceFile.js +33 -4
- package/dist/llm/webFetch.js +24 -11
- package/dist/llm/workerContext.d.ts +18 -0
- package/dist/llm/workerContext.js +55 -0
- package/dist/skills/SkillLoader.d.ts +2 -2
- package/dist/skills/SkillLoader.js +17 -5
- package/dist/skills/SkillRegistry.d.ts +3 -2
- package/dist/skills/SkillRegistry.js +53 -10
- package/dist/skills/builder/SkillBuilder.d.ts +3 -0
- package/dist/skills/builder/SkillBuilder.js +23 -5
- package/dist/skills/skillTools.js +11 -4
- package/dist/skills/types.d.ts +11 -1
- package/dist/ui/components/TextInput.d.ts +5 -2
- package/dist/ui/components/TextInput.js +76 -8
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.js +8 -0
- package/dist/utils/fs.d.ts +0 -1
- package/dist/utils/fs.js +0 -4
- package/dist/utils/openPath.d.ts +2 -0
- package/dist/utils/openPath.js +9 -0
- package/dist/utils/path.d.ts +2 -0
- package/dist/utils/path.js +9 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type Mode = 'chat' | 'provider' | 'providerAction' | 'model' | 'providerAddPreset' | 'providerAddName' | 'providerAddUrl' | 'providerAddKey' | 'providerAddModels' | 'providerAppendModels' | 'providerSetKey' | 'providerRemoveModels' | 'providerConfirmRemove' | 'skills' | 'skillsAction' | 'skillsAddName' | 'skillsAddDescription' | 'skillsConfirmRemove' | 'lsp' | 'lspAction' | 'lspAddPreset' | 'lspAddName' | 'lspAddCommand' | 'lspConfirmRemove' | 'mcp' | 'mcpAction' | 'mcpAddPreset' | 'mcpAddName' | 'mcpAddTransport' | 'mcpAddUrl' | 'mcpAddCommand' | 'mcpAddKey' | 'mcpSetKey' | 'mcpConfirmRemove';
|
|
1
|
+
export type Mode = 'chat' | 'sessions' | 'sessionAction' | 'provider' | 'providerAction' | 'model' | 'modelAddProvider' | 'modelPick' | 'providerAddPreset' | 'providerAddName' | 'providerAddUrl' | 'providerAddKey' | 'providerAddModels' | 'providerAppendModels' | 'providerSetKey' | 'providerRemoveModels' | 'providerConfirmRemove' | 'skills' | 'skillsAction' | 'skillsAddName' | 'skillsAddScope' | 'skillsAddDescription' | 'skillsConfirmRemove' | 'lsp' | 'lspAction' | 'lspAddPreset' | 'lspAddName' | 'lspAddCommand' | 'lspConfirmRemove' | 'mcp' | 'mcpAction' | 'mcpAddPreset' | 'mcpAddName' | 'mcpAddTransport' | 'mcpAddUrl' | 'mcpAddCommand' | 'mcpAddKey' | 'mcpSetKey' | 'mcpConfirmRemove';
|
|
2
2
|
/** Modes that show an always-on suggestion picker (server/preset lists). */
|
|
3
3
|
export declare const PICKER_MODES: ReadonlySet<Mode>;
|
|
4
4
|
/** Modes that mask input (secrets/API keys). */
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/** Modes that show an always-on suggestion picker (server/preset lists). */
|
|
2
|
-
export const PICKER_MODES = new Set(['provider', 'providerAction', 'providerAddPreset', 'model', 'skills', 'skillsAction', 'lsp', 'lspAction', 'lspAddPreset', 'mcp', 'mcpAction', 'mcpAddPreset', 'mcpAddTransport']);
|
|
2
|
+
export const PICKER_MODES = new Set(['sessions', 'sessionAction', 'provider', 'providerAction', 'providerAddPreset', 'model', 'modelAddProvider', 'modelPick', 'skills', 'skillsAction', 'skillsAddScope', 'lsp', 'lspAction', 'lspAddPreset', 'mcp', 'mcpAction', 'mcpAddPreset', 'mcpAddTransport']);
|
|
3
3
|
/** Modes that mask input (secrets/API keys). */
|
|
4
4
|
export const MASKED_MODES = new Set(['providerAddKey', 'providerSetKey', 'mcpAddKey', 'mcpSetKey']);
|
|
5
5
|
/** Modes where submitting an empty value is valid (optional steps). */
|
|
6
6
|
export const SUBMIT_EMPTY_MODES = new Set(['providerAddKey', 'mcpAddKey']);
|
|
7
7
|
const PLACEHOLDERS = {
|
|
8
|
+
sessions: 'Choose a saved session',
|
|
9
|
+
sessionAction: 'Resume or fork this session',
|
|
8
10
|
provider: 'Choose provider',
|
|
9
11
|
providerAction: 'Choose provider action',
|
|
10
12
|
providerAddPreset: 'Choose a provider preset or custom',
|
|
11
|
-
model: 'Choose model',
|
|
13
|
+
model: 'Choose model, or add model',
|
|
14
|
+
modelAddProvider: 'Choose a provider to add models to',
|
|
15
|
+
modelPick: 'Choose a model to add',
|
|
12
16
|
providerAddName: 'Provider name',
|
|
13
17
|
providerAddUrl: 'https://example.com/v1',
|
|
14
18
|
providerAddKey: 'API key, or blank for local',
|
|
@@ -20,6 +24,7 @@ const PLACEHOLDERS = {
|
|
|
20
24
|
skills: 'Choose a skill or add skill',
|
|
21
25
|
skillsAction: 'show info, enable, disable, validate, or remove',
|
|
22
26
|
skillsAddName: 'Skill name (kebab-case, e.g. security-review)',
|
|
27
|
+
skillsAddScope: 'Choose this project or global',
|
|
23
28
|
skillsAddDescription: 'Describe what the skill should do',
|
|
24
29
|
skillsConfirmRemove: 'Type "yes" to confirm',
|
|
25
30
|
lsp: 'Choose LSP server or add server',
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export const COMMAND_HELP_ENTRIES = [
|
|
2
2
|
{ usage: '/help', description: 'Show all available slash commands and what they do.' },
|
|
3
|
-
{ usage: '/provider', description: 'Choose a provider, then use it, add/remove models, set API key, or remove it.' },
|
|
4
|
-
{ usage: '/model', description: 'Choose a model from
|
|
3
|
+
{ usage: '/provider', description: 'Choose a provider, then use it, add/remove models, set API key, toggle image input, or remove it.' },
|
|
4
|
+
{ usage: '/model', description: 'Choose a model, or add models from a provider\'s models endpoint.' },
|
|
5
5
|
{ usage: '/model <name-or-provider:name>', description: 'Set a model directly. Selecting a model also sets its provider.' },
|
|
6
6
|
{ usage: '/settings', description: 'Show the configured provider, model, API key status, LSP/MCP servers, skills, and loaded context files.' },
|
|
7
7
|
{ usage: '/settings open', description: 'Open ~/.haze/settings.json with the OS default app.' },
|
|
8
8
|
{ usage: '/skills', description: 'Manage Markdown skills: generate a custom skill, show info, enable/disable, validate, or remove.' },
|
|
9
|
+
{ usage: '/tips', description: 'Toggle the rotating tips shown under the busy label while the model is thinking.' },
|
|
10
|
+
{ usage: '/fleet [--review] [--profile <name>] [--workers <provider:model>] [--concurrency <n>] [--] <prompt>', description: 'Run genuinely independent tasks through disposable contexts. Runtime enforces profile concurrency, deadlines, and mutation serialization; control guidance is not persisted. Declines non-parallel work.' },
|
|
9
11
|
{ usage: '/init', description: 'Inspect the current workspace and create or update AGENTS.md project instructions.' },
|
|
10
12
|
{ usage: '/context', description: 'Show a token breakdown of the current request: system prompt, project context, tools (incl. MCP), and chat messages.' },
|
|
11
13
|
{ usage: '/session', description: 'Show the current durable session file.' },
|
|
12
|
-
{ usage: '/resume', description: '
|
|
14
|
+
{ usage: '/resume [id]', description: 'Browse this workspace’s saved sessions, or resume an exact session id.' },
|
|
13
15
|
{ usage: '/new', description: 'Start a fresh durable session.' },
|
|
14
16
|
{ usage: '/logs', description: 'List recent log files with sizes and dates.' },
|
|
15
17
|
{ usage: '/lsp', description: 'Configure Language Server Protocol navigation tools (interactive picker).' },
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { ContextFile } from '../../config/contextFiles.js';
|
|
2
2
|
import { type HazeSettings } from '../../config/settings.js';
|
|
3
3
|
import type { Mode } from './chatModes.js';
|
|
4
|
+
import type { TurnExecutionOptions } from './streaming.js';
|
|
4
5
|
export type CommandContext = {
|
|
5
6
|
settings: HazeSettings;
|
|
6
7
|
contextFiles: ContextFile[];
|
|
7
8
|
setMode: (mode: Mode) => void;
|
|
8
9
|
setModelProviderFilter?: (providerName: string | undefined) => void;
|
|
9
10
|
addSystemMessage: (text: string) => void;
|
|
10
|
-
clearConversation: () => void
|
|
11
|
+
clearConversation: () => void | Promise<void>;
|
|
11
12
|
newSession?: () => Promise<void>;
|
|
12
|
-
resumeSession?: () => Promise<void>;
|
|
13
|
+
resumeSession?: (id?: string) => Promise<void>;
|
|
13
14
|
sessionInfo?: () => string;
|
|
14
15
|
compactConversation?: (instructions?: string) => boolean;
|
|
15
|
-
runAgentTurn: (prompt: string, displayValue?: string) => Promise<void>;
|
|
16
|
+
runAgentTurn: (prompt: string, displayValue?: string, options?: TurnExecutionOptions) => Promise<void>;
|
|
16
17
|
refreshContextFiles: () => Promise<ContextFile[]>;
|
|
17
18
|
updateSettings: (patch: Partial<HazeSettings>) => Promise<HazeSettings>;
|
|
18
19
|
getContextReport?: () => Promise<string>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
1
|
import fs from 'fs-extra';
|
|
3
2
|
import { SETTINGS_FILE, writeSettings } from '../../config/settings.js';
|
|
3
|
+
import { openPath } from '../../utils/openPath.js';
|
|
4
4
|
import { clearTasks } from '../../core/tasks/taskStorage.js';
|
|
5
5
|
import { COMMAND_HELP_ENTRIES, formatCommandHelp } from './commandHelp.js';
|
|
6
|
+
import { handleFleetCommand } from './fleetCommand.js';
|
|
6
7
|
import { handleInitCommand } from './initCommand.js';
|
|
7
8
|
import { handleLogsCommand } from './logsCommand.js';
|
|
8
9
|
import { handleModelCommand } from './modelCommand.js';
|
|
@@ -12,15 +13,6 @@ async function ensureSettingsFile(settings) {
|
|
|
12
13
|
await writeSettings(settings);
|
|
13
14
|
return SETTINGS_FILE;
|
|
14
15
|
}
|
|
15
|
-
function openPath(filePath) {
|
|
16
|
-
if (process.env.VITEST || process.env.NODE_ENV === 'test')
|
|
17
|
-
return;
|
|
18
|
-
const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
19
|
-
const args = process.platform === 'win32' ? ['/c', 'start', '', filePath] : [filePath];
|
|
20
|
-
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
21
|
-
child.on('error', () => undefined);
|
|
22
|
-
child.unref();
|
|
23
|
-
}
|
|
24
16
|
const HANDLED = 'handled';
|
|
25
17
|
function exact(command) {
|
|
26
18
|
return value => value === command ? { args: '' } : false;
|
|
@@ -33,8 +25,8 @@ const SLASH_COMMANDS = [
|
|
|
33
25
|
{ match: exact('/help'), run: (_args, ctx) => { ctx.addSystemMessage(formatCommandHelp(COMMAND_HELP_ENTRIES)); return HANDLED; } },
|
|
34
26
|
{ match: exact('/context'), run: async (_args, ctx) => { ctx.addSystemMessage(ctx.getContextReport ? await ctx.getContextReport() : 'Context overview is unavailable.'); return HANDLED; } },
|
|
35
27
|
{ match: exact('/session'), run: (_args, ctx) => { ctx.addSystemMessage(ctx.sessionInfo?.() ?? 'Session persistence is unavailable.'); return HANDLED; } },
|
|
36
|
-
{ match:
|
|
37
|
-
await ctx.resumeSession();
|
|
28
|
+
{ match: exactOrArgs('/resume'), run: async (args, ctx) => { if (ctx.resumeSession)
|
|
29
|
+
await ctx.resumeSession(args || undefined);
|
|
38
30
|
else
|
|
39
31
|
ctx.addSystemMessage('Session persistence is unavailable.'); return HANDLED; } },
|
|
40
32
|
{ match: exact('/new'), run: async (_args, ctx) => { if (ctx.newSession)
|
|
@@ -45,7 +37,7 @@ const SLASH_COMMANDS = [
|
|
|
45
37
|
ctx.compactConversation(args || undefined);
|
|
46
38
|
else
|
|
47
39
|
ctx.addSystemMessage('Compaction is unavailable.'); return HANDLED; } },
|
|
48
|
-
{ match: exact('/clear'), run: async (_args, ctx) => { ctx.clearConversation(); await clearTasks();
|
|
40
|
+
{ match: exact('/clear'), run: async (_args, ctx) => { await ctx.clearConversation(); await clearTasks(); return HANDLED; } },
|
|
49
41
|
{ match: exactOrArgs('/logs'), run: async (args, ctx) => await handleLogsCommand(args, ctx) },
|
|
50
42
|
{ match: exactOrArgs('/lsp'), run: (_args, ctx) => { ctx.setMode('lsp'); ctx.addSystemMessage('Choose an LSP server to enable, disable, or remove it. Choose "add server" to add one from presets (e.g. typescript) or enter a custom command.'); return HANDLED; } },
|
|
51
43
|
{ match: exactOrArgs('/mcp'), run: (_args, ctx) => { ctx.setMode('mcp'); ctx.addSystemMessage('Choose an MCP server to enable, disable, remove, or set a key for it. Choose "add server" to add one from presets (e.g. context7) or enter custom details.'); return HANDLED; } },
|
|
@@ -54,6 +46,13 @@ const SLASH_COMMANDS = [
|
|
|
54
46
|
{ match: exact('/provider'), run: (_args, ctx) => { ctx.setModelProviderFilter?.(undefined); ctx.setMode('provider'); ctx.addSystemMessage('Choose a provider. Selecting one opens provider actions. Choose "add provider" to pick from presets or enter custom details.'); return HANDLED; } },
|
|
55
47
|
{ match: exact('/init'), run: async (_args, ctx) => await handleInitCommand(ctx) },
|
|
56
48
|
{ match: exact('/skills'), run: (_args, ctx) => { ctx.setMode('skills'); ctx.addSystemMessage('Choose a skill to show info, enable/disable, or remove it. Choose "add skill" to generate a new one from a description.'); return HANDLED; } },
|
|
49
|
+
{ match: exact('/tips'), run: async (_args, ctx) => {
|
|
50
|
+
const currentlyEnabled = ctx.settings.tips?.enabled !== false;
|
|
51
|
+
await ctx.updateSettings({ tips: { enabled: !currentlyEnabled } });
|
|
52
|
+
ctx.addSystemMessage(`Tips rotation ${currentlyEnabled ? 'disabled' : 'enabled'}.`);
|
|
53
|
+
return HANDLED;
|
|
54
|
+
} },
|
|
55
|
+
{ match: exactOrArgs('/fleet'), run: (args, ctx) => handleFleetCommand(args, ctx) },
|
|
57
56
|
];
|
|
58
57
|
export async function handleSlashCommand(value, ctx) {
|
|
59
58
|
for (const command of SLASH_COMMANDS) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TurnExecutionOptions } from './streaming.js';
|
|
2
|
+
import type { CommandContext, CommandResult } from './commands.js';
|
|
3
|
+
export interface ParsedFleetCommand {
|
|
4
|
+
prompt: string;
|
|
5
|
+
options: TurnExecutionOptions;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseFleetArgs(args: string): {
|
|
8
|
+
ok: true;
|
|
9
|
+
value: ParsedFleetCommand;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
error: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function handleFleetCommand(args: string, ctx: CommandContext): Promise<CommandResult>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SUBAGENT_MAX_CONCURRENCY } from '../../core/agent/budgets.js';
|
|
2
|
+
const FLEET_CONTROL = `This is an ephemeral /fleet parallel-only control. Decompose the durable request into genuinely independent, self-contained subagent capsules; decline if fewer than two exist and never invent tasks. For a repository-wide request, first do one bounded structure lookup, then give workers focused directory/file scope hints instead of all of src. Every call requires objective, deliverable, and mode; keep objective under 1000 characters, prefer at most 12 scope paths, and put output formatting in deliverable/acceptanceCriteria. Mode is inspect, research, implement, or validate. Never call subagent with {}. Runtime owns queueing, concurrency, deadlines, provider policy, and mutation serialization. Submit independent read-only calls together; submit mutation conservatively and validate after it settles. Aggregate every capsule truthfully by termination, usability, truncation, changed paths, validation, and coverage gaps. Retry a failed/limited worker at most once, only with materially narrower scope; otherwise report the gap. Never request private worker transcripts.`;
|
|
3
|
+
export function parseFleetArgs(args) {
|
|
4
|
+
const tokens = args.trim().split(/\s+/).filter(Boolean);
|
|
5
|
+
const overrides = {};
|
|
6
|
+
let index = 0;
|
|
7
|
+
while (index < tokens.length && tokens[index].startsWith('-')) {
|
|
8
|
+
const flag = tokens[index++];
|
|
9
|
+
if (flag === '--')
|
|
10
|
+
break;
|
|
11
|
+
if (flag === '--review') {
|
|
12
|
+
overrides.forceMode = 'inspect';
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (!['--profile', '--workers', '--concurrency'].includes(flag))
|
|
16
|
+
return { ok: false, error: `Unknown /fleet flag: ${flag}` };
|
|
17
|
+
const value = tokens[index++];
|
|
18
|
+
if (!value || value.startsWith('--'))
|
|
19
|
+
return { ok: false, error: `${flag} requires a value.` };
|
|
20
|
+
if (flag === '--profile')
|
|
21
|
+
overrides.profile = value;
|
|
22
|
+
if (flag === '--workers')
|
|
23
|
+
overrides.workerModel = value;
|
|
24
|
+
if (flag === '--concurrency') {
|
|
25
|
+
const concurrency = Number(value);
|
|
26
|
+
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > SUBAGENT_MAX_CONCURRENCY)
|
|
27
|
+
return { ok: false, error: `--concurrency must be an integer from 1 to ${SUBAGENT_MAX_CONCURRENCY}.` };
|
|
28
|
+
overrides.maxConcurrency = concurrency;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const prompt = tokens.slice(index).join(' ').trim();
|
|
32
|
+
if (!prompt)
|
|
33
|
+
return { ok: false, error: '/fleet needs a prompt describing parallel work.' };
|
|
34
|
+
return { ok: true, value: { prompt, options: { ephemeralControl: FLEET_CONTROL, subagentOverrides: overrides } } };
|
|
35
|
+
}
|
|
36
|
+
const USAGE = '/fleet [--review] [--profile <name>] [--workers <provider:model>] [--concurrency <n>] [--] <prompt>';
|
|
37
|
+
export async function handleFleetCommand(args, ctx) {
|
|
38
|
+
const parsed = parseFleetArgs(args);
|
|
39
|
+
if (!parsed.ok) {
|
|
40
|
+
ctx.addSystemMessage(`${parsed.error} Usage: ${USAGE}`);
|
|
41
|
+
return 'handled';
|
|
42
|
+
}
|
|
43
|
+
const durable = `/fleet ${args.trim()}`;
|
|
44
|
+
await ctx.runAgentTurn(durable, durable, parsed.value.options);
|
|
45
|
+
return 'handled';
|
|
46
|
+
}
|
|
@@ -12,6 +12,11 @@ export declare function toolResultSummary(event: {
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function busyToolLabel(toolName: string, input: unknown): string;
|
|
14
14
|
export declare function formatSeconds(milliseconds: number): string;
|
|
15
|
+
/** Compact transcript row for a user-attached image (F03); never dumps bytes. */
|
|
16
|
+
export declare function imageAttachmentLine(attachment: {
|
|
17
|
+
fileName: string;
|
|
18
|
+
bytes: number;
|
|
19
|
+
}): string;
|
|
15
20
|
export declare function formatElapsedTime(milliseconds: number): string;
|
|
16
21
|
export declare function formatElapsedTimeWhole(milliseconds: number): string;
|
|
17
22
|
export declare function toolOutputDetails(value: unknown): string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatBytes } from '../../utils/format.js';
|
|
1
2
|
export function compact(value, maxLength = 180) {
|
|
2
3
|
let text;
|
|
3
4
|
if (value instanceof Error) {
|
|
@@ -18,9 +19,11 @@ export function compact(value, maxLength = 180) {
|
|
|
18
19
|
export function toolCallSummary(toolName, input) {
|
|
19
20
|
const data = input;
|
|
20
21
|
if (toolName === 'bash' && typeof data?.command === 'string') {
|
|
21
|
-
const
|
|
22
|
-
return `bash $ ${data.command}${
|
|
22
|
+
const mode = data.background === true ? ' (background)' : typeof data.timeoutSeconds === 'number' ? ` (timeout ${data.timeoutSeconds}s)` : '';
|
|
23
|
+
return `bash $ ${data.command}${mode}`;
|
|
23
24
|
}
|
|
25
|
+
if (toolName === 'process' && typeof data?.action === 'string')
|
|
26
|
+
return `process ${data.action}${typeof data.backgroundId === 'string' ? ` ${data.backgroundId}` : ''}`;
|
|
24
27
|
if (toolName === 'grep' && typeof data?.pattern === 'string') {
|
|
25
28
|
const path = typeof data.path === 'string' && data.path !== '.' ? ` in ${data.path}` : '';
|
|
26
29
|
const glob = typeof data.glob === 'string' ? ` (${data.glob})` : '';
|
|
@@ -42,9 +45,12 @@ export function toolCallSummary(toolName, input) {
|
|
|
42
45
|
return `replaceLines ${data.path}:${data.startLine}-${data.endLine}`;
|
|
43
46
|
if ((toolName === 'editFile' || toolName === 'replaceLines') && (data == null || (typeof data === 'object' && Object.keys(data).length === 0)))
|
|
44
47
|
return toolName;
|
|
45
|
-
if (toolName === 'subagent'
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
+
if (toolName === 'subagent') {
|
|
49
|
+
const task = typeof data?.objective === 'string' ? data.objective : typeof data?.task === 'string' ? data.task : undefined;
|
|
50
|
+
if (task) {
|
|
51
|
+
const taskPreview = task.length > 60 ? `${task.slice(0, 60).trimEnd()}…` : task;
|
|
52
|
+
return `subagent "${taskPreview}"`;
|
|
53
|
+
}
|
|
48
54
|
}
|
|
49
55
|
if (toolName === 'writeTasks') {
|
|
50
56
|
const tasks = Array.isArray(data?.tasks) ? data.tasks : [];
|
|
@@ -59,14 +65,17 @@ export function toolCallSummary(toolName, input) {
|
|
|
59
65
|
return `${toolName} ${compact(input)}`;
|
|
60
66
|
}
|
|
61
67
|
export function toolResultSummary(event) {
|
|
62
|
-
if (!event.success)
|
|
63
|
-
return `failed: ${compact(event.error)}`;
|
|
64
68
|
const output = event.output;
|
|
69
|
+
if (!event.success)
|
|
70
|
+
return `failed: ${compact(event.error ?? output?.error ?? event.output)}`;
|
|
65
71
|
if (output?.duplicateSkipped === true)
|
|
66
72
|
return 'skipped duplicate';
|
|
73
|
+
if (output?.background === true && typeof output.backgroundId === 'string') {
|
|
74
|
+
return `⏵ ${output.backgroundId} ${compact(output.command, 80)}${typeof output.pid === 'number' ? ` (pid ${output.pid})` : ''}`;
|
|
75
|
+
}
|
|
67
76
|
if (typeof output?.totalMatches === 'number') {
|
|
68
77
|
const count = output.totalMatches;
|
|
69
|
-
return count === 0 ? 'no matches' : `${count} match${count === 1 ? '' : 'es'}`;
|
|
78
|
+
return count === 0 ? 'no matches' : `${output.matchCountIsLowerBound === true ? 'at least ' : ''}${count} match${count === 1 ? '' : 'es'}`;
|
|
70
79
|
}
|
|
71
80
|
if (typeof output?.validationSummary === 'object' && output.validationSummary != null && 'summaryText' in output.validationSummary) {
|
|
72
81
|
const summary = output.validationSummary;
|
|
@@ -79,6 +88,18 @@ export function toolResultSummary(event) {
|
|
|
79
88
|
: '';
|
|
80
89
|
return `exited with code ${output.code}${risk}`;
|
|
81
90
|
}
|
|
91
|
+
const resultOutput = output ?? {};
|
|
92
|
+
const capsule = typeof resultOutput.capsule === 'object' && resultOutput.capsule != null ? resultOutput.capsule : undefined;
|
|
93
|
+
if (capsule && typeof capsule.termination === 'string' && typeof capsule.deliverable === 'string') {
|
|
94
|
+
const summary = capsule.deliverable.split('\n')[0] ?? '';
|
|
95
|
+
const preview = summary.length > 120 ? `${summary.slice(0, 120).trimEnd()}…` : summary;
|
|
96
|
+
const telemetry = typeof resultOutput.telemetry === 'object' && resultOutput.telemetry != null ? resultOutput.telemetry : undefined;
|
|
97
|
+
const calls = typeof telemetry?.toolCallCount === 'number' ? telemetry.toolCallCount : typeof resultOutput.toolCallCount === 'number' ? resultOutput.toolCallCount : 0;
|
|
98
|
+
const durationMs = typeof telemetry?.durationMs === 'number' ? telemetry.durationMs : resultOutput.durationMs;
|
|
99
|
+
const duration = typeof durationMs === 'number' ? ` in ${(durationMs / 1000).toFixed(1)}s` : '';
|
|
100
|
+
const meta = calls > 0 ? ` (${calls} call${calls === 1 ? '' : 's'}${duration})` : '';
|
|
101
|
+
return `${capsule.termination}${capsule.usable === false ? ' · unusable' : ''}${capsule.truncated === true ? ' · truncated' : ''}${meta}: ${preview}`;
|
|
102
|
+
}
|
|
82
103
|
if (typeof output?.status === 'string' && typeof output?.summary === 'string') {
|
|
83
104
|
const summary = output.summary.split('\n')[0] ?? '';
|
|
84
105
|
const preview = summary.length > 120 ? `${summary.slice(0, 120).trimEnd()}…` : summary;
|
|
@@ -123,7 +144,9 @@ export function busyToolLabel(toolName, input) {
|
|
|
123
144
|
const pathLabel = typeof data?.path === 'string' ? compact(data.path, 80) : undefined;
|
|
124
145
|
switch (toolName) {
|
|
125
146
|
case 'bash':
|
|
126
|
-
return 'Running command';
|
|
147
|
+
return data?.background === true ? 'Starting background process' : 'Running command';
|
|
148
|
+
case 'process':
|
|
149
|
+
return 'Managing background process';
|
|
127
150
|
case 'grep':
|
|
128
151
|
return 'Searching';
|
|
129
152
|
case 'listFiles':
|
|
@@ -154,6 +177,10 @@ export function busyToolLabel(toolName, input) {
|
|
|
154
177
|
export function formatSeconds(milliseconds) {
|
|
155
178
|
return `${(milliseconds / 1000).toFixed(1)}s`;
|
|
156
179
|
}
|
|
180
|
+
/** Compact transcript row for a user-attached image (F03); never dumps bytes. */
|
|
181
|
+
export function imageAttachmentLine(attachment) {
|
|
182
|
+
return `🖼 ${attachment.fileName} (${formatBytes(attachment.bytes)})`;
|
|
183
|
+
}
|
|
157
184
|
export function formatElapsedTime(milliseconds) {
|
|
158
185
|
const totalSeconds = Math.max(0, milliseconds / 1000);
|
|
159
186
|
const wholeSeconds = Math.floor(totalSeconds);
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { listLogs,
|
|
2
|
-
|
|
3
|
-
if (bytes < 1024)
|
|
4
|
-
return `${bytes} B`;
|
|
5
|
-
if (bytes < 1024 * 1024)
|
|
6
|
-
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
7
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
8
|
-
}
|
|
1
|
+
import { listLogs, summarizeLog } from '../../core/log/llmLog.js';
|
|
2
|
+
import { formatBytes } from '../../utils/format.js';
|
|
9
3
|
export async function handleLogsCommand(args, ctx) {
|
|
10
4
|
const id = args.trim();
|
|
11
5
|
if (!id) {
|
|
@@ -21,39 +15,25 @@ export async function handleLogsCommand(args, ctx) {
|
|
|
21
15
|
ctx.addSystemMessage(['Recent logs:', ' ID Size Modified', ...lines].join('\n'));
|
|
22
16
|
return 'handled';
|
|
23
17
|
}
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
18
|
+
const summary = await summarizeLog(id);
|
|
19
|
+
if (!summary) {
|
|
26
20
|
ctx.addSystemMessage(`No log found with id ${id}.`);
|
|
27
21
|
return 'handled';
|
|
28
22
|
}
|
|
29
|
-
const
|
|
30
|
-
let totalInput = 0;
|
|
31
|
-
let totalOutput = 0;
|
|
32
|
-
const toolCallCounts = {};
|
|
33
|
-
for (const entry of entries) {
|
|
34
|
-
typeCounts[entry.type] = (typeCounts[entry.type] ?? 0) + 1;
|
|
35
|
-
if (entry.usage) {
|
|
36
|
-
totalInput += entry.usage.inputTokens ?? 0;
|
|
37
|
-
totalOutput += entry.usage.outputTokens ?? 0;
|
|
38
|
-
}
|
|
39
|
-
if (entry.type === 'tool_call' && entry.toolCall) {
|
|
40
|
-
toolCallCounts[entry.toolCall.name] = (toolCallCounts[entry.toolCall.name] ?? 0) + 1;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const typeLines = Object.entries(typeCounts)
|
|
23
|
+
const typeLines = Object.entries(summary.typeCounts)
|
|
44
24
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
45
25
|
.map(([type, count]) => ` ${type}: ${count}`);
|
|
46
|
-
const toolLines = Object.entries(toolCallCounts)
|
|
26
|
+
const toolLines = Object.entries(summary.toolCallCounts)
|
|
47
27
|
.sort(([, a], [, b]) => b - a)
|
|
48
28
|
.map(([name, count]) => ` ${name}: ${count}`);
|
|
49
29
|
const parts = [
|
|
50
30
|
`Log: ${id}`,
|
|
51
|
-
`Entries: ${entries
|
|
31
|
+
`Entries: ${summary.entries}`,
|
|
52
32
|
'',
|
|
53
33
|
'Entry counts by type:',
|
|
54
34
|
...typeLines,
|
|
55
35
|
'',
|
|
56
|
-
`Total token usage: in=${totalInput} out=${totalOutput}`,
|
|
36
|
+
`Total token usage: in=${summary.totalInput} out=${summary.totalOutput}`,
|
|
57
37
|
];
|
|
58
38
|
if (toolLines.length > 0) {
|
|
59
39
|
parts.push('', 'Tool call counts:', ...toolLines);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findMcpPreset, findMcpServer, toggleMcpServer, upsertMcpServer } from '../../config/mcpSettings.js';
|
|
2
2
|
import { COMMON_ACTIONS, MCP_ACTIONS, MCP_TRANSPORTS, SERVER_CHOICES } from './wizardActions.js';
|
|
3
|
+
import { assertCredentialedEndpointSecure } from '../../config/endpointSecurity.js';
|
|
3
4
|
export function selectMcpServerResult(settings, serverName) {
|
|
4
5
|
if (serverName === SERVER_CHOICES.addServer)
|
|
5
6
|
return { mode: 'mcpAddName', clearDraft: true, message: 'Choose an MCP preset, or select "custom" to enter details manually.' };
|
|
@@ -32,8 +33,11 @@ export function selectMcpActionResult(settings, selectedName, action) {
|
|
|
32
33
|
const enabled = action === COMMON_ACTIONS.enable;
|
|
33
34
|
return { mode: 'chat', selectedName: undefined, settingsPatch: { mcpServers: toggleMcpServer(settings, selectedName, enabled) ?? [] }, message: `MCP server ${selectedName} ${enabled ? 'enabled' : 'disabled'}.` };
|
|
34
35
|
}
|
|
35
|
-
if (action === MCP_ACTIONS.setApiKey)
|
|
36
|
+
if (action === MCP_ACTIONS.setApiKey) {
|
|
37
|
+
if (server.transport === 'stdio')
|
|
38
|
+
return { mode: 'chat', selectedName: undefined, message: 'Stdio MCP authentication must be handled by its command or wrapper; HTTP headers do not apply.' };
|
|
36
39
|
return { mode: 'mcpSetKey', message: `New API key for ${selectedName}? (current: ${server.headers?.length ? 'saved' : 'not set'}) Sent as Authorization: Bearer <value>.` };
|
|
40
|
+
}
|
|
37
41
|
if (action === MCP_ACTIONS.removeServer)
|
|
38
42
|
return { mode: 'mcpConfirmRemove', message: `Remove MCP server ${selectedName}? Type "yes" to confirm. Esc to cancel.` };
|
|
39
43
|
return { message: `Unknown MCP action: ${action}` };
|
|
@@ -45,12 +49,20 @@ export function finishMcpCustomResult(settings, draft, keyValue) {
|
|
|
45
49
|
return { mode: 'chat', clearDraft: true, message: 'MCP server name and transport are required.' };
|
|
46
50
|
const headers = keyValue?.trim() ? [{ name: 'Authorization', value: `Bearer ${keyValue.trim()}` }] : undefined;
|
|
47
51
|
const server = transport === MCP_TRANSPORTS.stdio
|
|
48
|
-
? { name, transport, command: draft.command, args: draft.args,
|
|
52
|
+
? { name, transport, command: draft.command, args: draft.args, enabled: true }
|
|
49
53
|
: { name, transport, url: draft.url, ...(headers ? { headers } : {}), enabled: true };
|
|
50
54
|
if (transport === MCP_TRANSPORTS.stdio && !server.command)
|
|
51
55
|
return { mode: 'chat', clearDraft: true, message: 'Command is required for stdio transport.' };
|
|
52
56
|
if (transport !== MCP_TRANSPORTS.stdio && !server.url)
|
|
53
57
|
return { mode: 'chat', clearDraft: true, message: `URL is required for ${transport} transport.` };
|
|
58
|
+
if (server.url) {
|
|
59
|
+
try {
|
|
60
|
+
assertCredentialedEndpointSecure(server.url, server.headers);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return { mode: 'chat', clearDraft: true, message: error instanceof Error ? error.message : String(error) };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
54
66
|
const location = transport === MCP_TRANSPORTS.stdio ? `${server.command}${(server.args ?? []).length ? ` ${(server.args ?? []).join(' ')}` : ''}` : server.url;
|
|
55
67
|
return { mode: 'chat', clearDraft: true, server, settingsPatch: { mcpServers: upsertMcpServer(settings, server) }, message: `Added MCP server ${name} (${transport}, ${location}). Tools load on the next turn.` };
|
|
56
68
|
}
|
|
@@ -60,10 +72,20 @@ export function setMcpServerKeyResult(settings, selectedName, keyValue) {
|
|
|
60
72
|
const server = findMcpServer(settings, selectedName);
|
|
61
73
|
if (!server)
|
|
62
74
|
return { mode: 'chat', selectedName: undefined, message: `MCP server ${selectedName} not found.` };
|
|
75
|
+
if (server.transport === 'stdio')
|
|
76
|
+
return { mode: 'chat', selectedName: undefined, message: 'Stdio MCP authentication must be handled by its command or wrapper.' };
|
|
63
77
|
const key = keyValue.trim();
|
|
64
78
|
if (!key)
|
|
65
79
|
return { message: 'API key cannot be empty. Esc to cancel.' };
|
|
66
80
|
const headers = (server.headers ?? []).filter(header => header.name !== 'Authorization');
|
|
67
81
|
headers.push({ name: 'Authorization', value: `Bearer ${key}` });
|
|
82
|
+
if (server.url) {
|
|
83
|
+
try {
|
|
84
|
+
assertCredentialedEndpointSecure(server.url, headers);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return { mode: 'chat', selectedName: undefined, message: error instanceof Error ? error.message : String(error) };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
68
90
|
return { mode: 'chat', selectedName: undefined, settingsPatch: { mcpServers: upsertMcpServer(settings, { ...server, headers }) }, message: `API key updated for ${server.name}.` };
|
|
69
91
|
}
|
|
@@ -3,7 +3,7 @@ export async function handleModelCommand(value, ctx) {
|
|
|
3
3
|
if (value === '/model') {
|
|
4
4
|
ctx.setModelProviderFilter?.(undefined);
|
|
5
5
|
ctx.setMode('model');
|
|
6
|
-
ctx.addSystemMessage('Choose a model. Selecting a model also sets its provider.');
|
|
6
|
+
ctx.addSystemMessage('Choose a model, or select "add models" to fetch a provider\'s model list and pick from it. Selecting a model also sets its provider.');
|
|
7
7
|
return 'handled';
|
|
8
8
|
}
|
|
9
9
|
if (value === '/model list') {
|
|
@@ -18,6 +18,7 @@ export declare function providerRemoveModels(settings: HazeSettings, providerNam
|
|
|
18
18
|
export declare function providerRemove(settings: HazeSettings, providerName: string | undefined): WizardPatch & {
|
|
19
19
|
wasActiveProvider?: boolean;
|
|
20
20
|
};
|
|
21
|
+
export declare function providerSetImageCapable(settings: HazeSettings, providerName: string | undefined, enabled: boolean): WizardPatch;
|
|
21
22
|
export declare function providerSetKey(settings: HazeSettings, providerName: string | undefined, value: string): WizardPatch & {
|
|
22
23
|
key?: string;
|
|
23
24
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { configuredProviders, findProvider, upsertProvider } from '../../config/providers.js';
|
|
2
2
|
import { PROVIDER_ACTIONS } from './wizardActions.js';
|
|
3
3
|
import { commaList } from './wizardInput.js';
|
|
4
|
+
import { assertCredentialedEndpointSecure } from '../../config/endpointSecurity.js';
|
|
4
5
|
export function providerAppendModels(settings, providerName, modelsValue) {
|
|
5
6
|
const provider = providerName ? findProvider(settings, providerName) : undefined;
|
|
6
7
|
const models = commaList(modelsValue);
|
|
@@ -21,6 +22,12 @@ export function providerFinishAdd(settings, draft, modelsValue) {
|
|
|
21
22
|
if (!draft.name || !draft.url || models.length === 0) {
|
|
22
23
|
return { models, message: 'Provider name, URL, and at least one model are required.' };
|
|
23
24
|
}
|
|
25
|
+
try {
|
|
26
|
+
assertCredentialedEndpointSecure(draft.url, draft.key);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return { models, message: error instanceof Error ? error.message : String(error) };
|
|
30
|
+
}
|
|
24
31
|
const provider = {
|
|
25
32
|
name: draft.name,
|
|
26
33
|
url: draft.url,
|
|
@@ -52,7 +59,7 @@ export function providerRemoveModels(settings, providerName, modelsValue) {
|
|
|
52
59
|
if (notFound.length)
|
|
53
60
|
parts.push(`Not found: ${notFound.join(', ')}.`);
|
|
54
61
|
if (wasActive)
|
|
55
|
-
parts.push(
|
|
62
|
+
parts.push('Active model selection cleared. Choose a model explicitly.');
|
|
56
63
|
return {
|
|
57
64
|
provider,
|
|
58
65
|
remaining,
|
|
@@ -61,7 +68,7 @@ export function providerRemoveModels(settings, providerName, modelsValue) {
|
|
|
61
68
|
wasActive,
|
|
62
69
|
settingsPatch: {
|
|
63
70
|
providers: upsertProvider(settings, updated),
|
|
64
|
-
...(wasActive ? { model:
|
|
71
|
+
...(wasActive ? { model: undefined } : {}),
|
|
65
72
|
},
|
|
66
73
|
message: parts.join(' '),
|
|
67
74
|
};
|
|
@@ -71,16 +78,29 @@ export function providerRemove(settings, providerName) {
|
|
|
71
78
|
if (!provider)
|
|
72
79
|
return { message: 'No provider selected.' };
|
|
73
80
|
const providers = configuredProviders(settings).filter(candidate => candidate.name !== providerName);
|
|
74
|
-
const wasActiveProvider = settings.provider === providerName
|
|
81
|
+
const wasActiveProvider = settings.provider === providerName;
|
|
75
82
|
return {
|
|
76
83
|
provider,
|
|
77
84
|
providers,
|
|
78
85
|
wasActiveProvider,
|
|
79
86
|
settingsPatch: {
|
|
80
87
|
providers,
|
|
81
|
-
...(wasActiveProvider ? { provider:
|
|
88
|
+
...(wasActiveProvider ? { provider: undefined, model: undefined } : {}),
|
|
82
89
|
},
|
|
83
|
-
message: `Removed provider ${provider.name}.${wasActiveProvider ?
|
|
90
|
+
message: `Removed provider ${provider.name}.${wasActiveProvider ? ' Active provider and model selection cleared.' : ''}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export function providerSetImageCapable(settings, providerName, enabled) {
|
|
94
|
+
const provider = providerName ? findProvider(settings, providerName) : undefined;
|
|
95
|
+
if (!provider)
|
|
96
|
+
return { message: 'No provider selected.' };
|
|
97
|
+
const capabilities = { ...(provider.capabilities ?? {}), images: enabled };
|
|
98
|
+
return {
|
|
99
|
+
provider,
|
|
100
|
+
settingsPatch: { providers: upsertProvider(settings, { ...provider, capabilities }) },
|
|
101
|
+
message: enabled
|
|
102
|
+
? `Provider ${provider.name} marked image-capable. Attached images will be sent to it.`
|
|
103
|
+
: `Provider ${provider.name} is no longer image-capable.`,
|
|
84
104
|
};
|
|
85
105
|
}
|
|
86
106
|
export function providerSetKey(settings, providerName, value) {
|
|
@@ -90,6 +110,12 @@ export function providerSetKey(settings, providerName, value) {
|
|
|
90
110
|
const key = value.trim();
|
|
91
111
|
if (!key)
|
|
92
112
|
return { provider, message: 'API key cannot be empty. Esc to cancel.' };
|
|
113
|
+
try {
|
|
114
|
+
assertCredentialedEndpointSecure(provider.url, key);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
return { provider, message: error instanceof Error ? error.message : String(error) };
|
|
118
|
+
}
|
|
93
119
|
return {
|
|
94
120
|
provider,
|
|
95
121
|
key,
|