-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathAgentSettingsPanel.tsx
More file actions
165 lines (160 loc) · 7.08 KB
/
AgentSettingsPanel.tsx
File metadata and controls
165 lines (160 loc) · 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { ProviderMeta } from '../hooks/useConfigState';
import { Select } from './Select';
import { EditableField } from './EditableField';
import { InfoTip } from './InfoTip';
interface AgentSettingsPanelProps {
getLocal: (key: string) => string;
getServer?: (key: string) => string;
setLocal: (key: string, value: string) => void;
saveConfig: (key: string, value: string) => Promise<void>;
cancelLocal?: (key: string) => void;
modelOptions: Array<{ value: string; name: string; reasoning?: boolean }>;
pendingProvider: string | null;
pendingMeta: ProviderMeta | null;
pendingApiKey: string;
setPendingApiKey: (v: string) => void;
pendingValidating: boolean;
pendingError: string | null;
setPendingError: (v: string | null) => void;
handleProviderChange: (provider: string) => Promise<void>;
handleProviderConfirm: () => Promise<void>;
handleProviderCancel: () => void;
/** Hide temperature/tokens/iterations (Dashboard mode) */
compact?: boolean;
}
export function AgentSettingsPanel({
getLocal, getServer = () => '', setLocal, saveConfig, cancelLocal = () => {},
modelOptions,
pendingProvider, pendingMeta, pendingApiKey, setPendingApiKey,
pendingValidating, pendingError, setPendingError,
handleProviderChange, handleProviderConfirm, handleProviderCancel,
compact = false,
}: AgentSettingsPanelProps) {
const supportsReasoning = modelOptions.find((m) => m.value === getLocal('agent.model'))?.reasoning ?? false;
return (
<>
<div style={{ display: 'grid', gap: '16px' }}>
<div className="form-group" style={{ marginBottom: 0 }}>
<label>Provider <InfoTip text="LLM provider" /></label>
<Select
value={pendingProvider ?? getLocal('agent.provider')}
options={['claude-code', 'anthropic', 'openai', 'google', 'xai', 'groq', 'openrouter', 'moonshot', 'mistral', 'cerebras', 'zai', 'minimax', 'huggingface', 'cocoon', 'local']}
labels={['Claude Code', 'Anthropic', 'OpenAI', 'Google', 'xAI', 'Groq', 'OpenRouter', 'Moonshot', 'Mistral', 'Cerebras', 'ZAI (Zhipu)', 'MiniMax', 'HuggingFace', 'Cocoon', 'Local']}
onChange={handleProviderChange}
/>
</div>
{/* Gated provider switch zone */}
{pendingProvider && pendingMeta && (
<div className="provider-switch-zone">
<div style={{ fontSize: '13px', fontWeight: 500, marginBottom: '12px' }}>
Switching to {pendingMeta.displayName}
</div>
{pendingMeta.needsKey && (
<div className="form-group" style={{ marginBottom: '8px' }}>
<label>API Key</label>
<input
type="password"
placeholder={pendingMeta.keyHint}
value={pendingApiKey}
onChange={(e) => { setPendingApiKey(e.target.value); setPendingError(null); }}
onKeyDown={(e) => e.key === 'Enter' && handleProviderConfirm()}
style={{ width: '100%' }}
autoFocus
/>
{pendingMeta.consoleUrl && (
<a
href={pendingMeta.consoleUrl}
target="_blank"
rel="noopener noreferrer"
style={{ fontSize: '12px', color: 'var(--text-secondary)', marginTop: '4px', display: 'inline-block' }}
>
Get key at {new URL(pendingMeta.consoleUrl).hostname} ↗
</a>
)}
</div>
)}
{pendingError && (
<div style={{ fontSize: '12px', color: 'var(--red)', marginBottom: '8px' }}>
{pendingError}
</div>
)}
<div style={{ display: 'flex', gap: '8px' }}>
<button className="btn-ghost btn-sm" onClick={handleProviderCancel} disabled={pendingValidating}>
Cancel
</button>
<button className="btn-sm" onClick={handleProviderConfirm} disabled={pendingValidating}>
{pendingValidating ? <><span className="spinner sm" /> Validating...</> : 'Validate & Save'}
</button>
</div>
</div>
)}
<div className="form-group" style={{ marginBottom: 0 }}>
<label>Model <InfoTip text="Main LLM model ID" /></label>
<Select
value={getLocal('agent.model')}
options={modelOptions.map((m) => m.value)}
labels={modelOptions.map((m) => m.name)}
onChange={(v) => saveConfig('agent.model', v)}
/>
</div>
<div className="form-group" style={{ marginBottom: 0, opacity: supportsReasoning ? 1 : 0.45 }}>
<label>Reasoning <InfoTip text={supportsReasoning ? "Thinking depth for this reasoning model" : "Current model does not support reasoning"} /></label>
<Select
value={getLocal('agent.reasoning_effort') || 'low'}
options={['off', 'low', 'medium', 'high']}
labels={['Off', 'Low', 'Medium', 'High']}
onChange={(v) => saveConfig('agent.reasoning_effort', v)}
disabled={!supportsReasoning}
/>
</div>
{!compact && (
<div style={{ display: 'grid', gap: '12px' }}>
<EditableField
label="Temperature"
description="Response creativity (0.0 = deterministic, 1.0 = max)"
configKey="agent.temperature"
type="number"
value={getLocal('agent.temperature')}
serverValue={getServer('agent.temperature')}
onChange={(v) => setLocal('agent.temperature', v)}
onSave={(v) => saveConfig('agent.temperature', v)}
onCancel={() => cancelLocal('agent.temperature')}
min={0}
max={1}
step={0.1}
inline
/>
<EditableField
label="Max Tokens"
description="Maximum response length in tokens"
configKey="agent.max_tokens"
type="number"
value={getLocal('agent.max_tokens')}
serverValue={getServer('agent.max_tokens')}
onChange={(v) => setLocal('agent.max_tokens', v)}
onSave={(v) => saveConfig('agent.max_tokens', v)}
onCancel={() => cancelLocal('agent.max_tokens')}
min={100}
step={100}
inline
/>
<EditableField
label="Max Iterations"
description="Max tool-call loop iterations per message"
configKey="agent.max_agentic_iterations"
type="number"
value={getLocal('agent.max_agentic_iterations')}
serverValue={getServer('agent.max_agentic_iterations')}
onChange={(v) => setLocal('agent.max_agentic_iterations', v)}
onSave={(v) => saveConfig('agent.max_agentic_iterations', v)}
onCancel={() => cancelLocal('agent.max_agentic_iterations')}
min={1}
max={20}
inline
/>
</div>
)}
</div>
</>
);
}