Skip to content

Commit ca40c28

Browse files
committed
Accept every configurable built-in provider in config commands
1 parent 79a26ef commit ca40c28

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎src/commands/settings.ts‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getTheme, initTheme, isThemeInitialized, listAvailableThemes, themedFgI
1616
import { getDefaultThemeName } from '../ui/theme/themes.js';
1717
import { showModal, showInput, showConfirm, showPassword, type ModalOption } from '../ui/ink/components/Modal.js';
1818
import { saveConfig } from '../config.js';
19-
import type { BuiltInProviderName, LoadedConfig } from '../types.js';
19+
import { BUILT_IN_PROVIDER_NAMES, type BuiltInProviderName, type LoadedConfig } from '../types.js';
2020
import { DEFAULT_MAX_CONCURRENT_THREADS_PER_SESSION, MAX_CONCURRENT_THREADS_PER_SESSION, isValidSessionThreadLimit } from '../core/agents/SessionThreadBudget.js';
2121
import { TRACE_CONSENT_VERSION } from '../integrations/ahtraces/consent.js';
2222

@@ -98,23 +98,7 @@ const SETTING_KEY_ALIASES: Record<string, string> = {
9898
ui_verbs_activity: 'ui.activityVerbsEnabled',
9999
};
100100

101-
const CONFIG_PROVIDER_NAMES: readonly BuiltInProviderName[] = [
102-
'openrouter',
103-
'anthropic',
104-
'ollama',
105-
'llamacpp',
106-
'openai',
107-
'mlx',
108-
'llmgateway',
109-
'azure',
110-
'zai',
111-
'vertexai',
112-
'xai',
113-
'cerebras',
114-
'nvidia',
115-
'deepseek',
116-
'bedrock',
117-
];
101+
const CONFIG_PROVIDER_NAMES = BUILT_IN_PROVIDER_NAMES.filter(provider => provider !== 'autohandai');
118102

119103
const PROVIDER_CONFIG_FIELD_ALIASES: Record<string, 'apiKey' | 'baseUrl' | 'model'> = {
120104
apiKey: 'apiKey',

‎src/types.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,27 @@ type Primitive = string | number | boolean | null;
3939

4040
export type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
4141

42-
export type BuiltInProviderName = 'autohandai' | 'openrouter' | 'anthropic' | 'ollama' | 'llamacpp' | 'openai' | 'mlx' | 'llmgateway' | 'azure' | 'zai' | 'sakana' | 'vertexai' | 'xai' | 'cerebras' | 'nvidia' | 'deepseek' | 'bedrock';
42+
export const BUILT_IN_PROVIDER_NAMES = [
43+
'autohandai',
44+
'openrouter',
45+
'anthropic',
46+
'ollama',
47+
'llamacpp',
48+
'openai',
49+
'mlx',
50+
'llmgateway',
51+
'azure',
52+
'zai',
53+
'sakana',
54+
'vertexai',
55+
'xai',
56+
'cerebras',
57+
'nvidia',
58+
'deepseek',
59+
'bedrock',
60+
] as const;
61+
62+
export type BuiltInProviderName = (typeof BUILT_IN_PROVIDER_NAMES)[number];
4363
export type BlueprintLocalProviderName = 'blueprint-local';
4464
export type CustomProviderId = `custom:${string}`;
4565
export type ExtensionProviderId = `extension:${string}`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { setConfigSetting } from '../../src/commands/settings.js';
3+
import { BUILT_IN_PROVIDER_NAMES, type LoadedConfig } from '../../src/types.js';
4+
5+
const providers = BUILT_IN_PROVIDER_NAMES.filter(provider => provider !== 'autohandai');
6+
7+
describe('built-in provider config commands', () => {
8+
it.each(providers)('accepts %s and its saved API key', provider => {
9+
const config: LoadedConfig = { provider: 'openrouter', configPath: 'unused.json' };
10+
expect(setConfigSetting(config, `${provider}.apiKey`, 'test-key')).toEqual({ key: `${provider}.apiKey`, value: 'test-key' });
11+
expect(setConfigSetting(config, 'provider', provider)).toEqual({ key: 'provider', value: provider });
12+
expect(config[provider]?.apiKey).toBe('test-key');
13+
});
14+
it('preserves mandatory Autohand authentication', () => {
15+
const config: LoadedConfig = { provider: 'autohandai', configPath: 'unused.json' };
16+
expect(() => setConfigSetting(config, 'autohandai.apiKey', 'test-key')).toThrow();
17+
});
18+
});

0 commit comments

Comments
 (0)