-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomModelModal.tsx
More file actions
152 lines (141 loc) · 5.31 KB
/
Copy pathCustomModelModal.tsx
File metadata and controls
152 lines (141 loc) · 5.31 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
import { useState, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
DialogDescription
} from './ui/dialog';
import { Button } from './ui/button';
import { Label } from './ui/label';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue
} from './ui/select';
import { THINKING_LEVELS } from '../../shared/constants';
import { getInsightsProviderOptions, getAvailableModelsForProvider } from '../../shared/constants/insights-providers';
import type { InsightsModelConfig, InsightsProvider } from '../../shared/types';
import type { ModelType, ThinkingLevel } from '../../shared/types';
interface CustomModelModalProps {
currentConfig?: InsightsModelConfig;
onSave: (config: InsightsModelConfig) => void;
onClose: () => void;
open?: boolean;
}
export function CustomModelModal({ currentConfig, onSave, onClose, open = true }: CustomModelModalProps) {
const { t } = useTranslation(['dialogs', 'common']);
const [model, setModel] = useState<ModelType>(
currentConfig?.model || 'sonnet'
);
const [thinkingLevel, setThinkingLevel] = useState<ThinkingLevel>(
currentConfig?.thinkingLevel || 'medium'
);
const [provider, setProvider] = useState<InsightsProvider>(
currentConfig?.provider || 'claude'
);
// Build provider options with i18n
const insightsProviders = useMemo(() => getInsightsProviderOptions(t), [t]);
// Sync internal state when modal opens or config changes
useEffect(() => {
if (open) {
setModel(currentConfig?.model || 'sonnet');
setThinkingLevel(currentConfig?.thinkingLevel || 'medium');
setProvider(currentConfig?.provider || 'claude');
}
}, [open, currentConfig]);
// Get available models for the selected provider
const availableModels = useMemo(() => getAvailableModelsForProvider(provider), [provider]);
const handleSave = () => {
onSave({
profileId: 'custom',
model,
thinkingLevel,
provider
});
};
return (
<Dialog open={open} onOpenChange={onClose}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>{t('dialogs:customModel.title')}</DialogTitle>
<DialogDescription>
{t('dialogs:customModel.description')}
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<Label htmlFor="provider-select">{t('dialogs:customModel.provider')}</Label>
<Select value={provider} onValueChange={(v) => setProvider(v as InsightsProvider)}>
<SelectTrigger id="provider-select">
<SelectValue />
</SelectTrigger>
<SelectContent>
{insightsProviders.map((p) => (
<SelectItem key={p.id} value={p.id}>
<div className="flex flex-col">
<span className="font-medium">{p.label}</span>
<span className="text-xs text-muted-foreground">{p.description}</span>
</div>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="model-select">{t('dialogs:customModel.model')}</Label>
<Select value={model} onValueChange={(v) => setModel(v as ModelType)}>
<SelectTrigger id="model-select">
<SelectValue />
</SelectTrigger>
<SelectContent>
{availableModels.map((m) => (
<SelectItem key={m.value} value={m.value}>
<div className="flex flex-col">
<span className="font-medium">{m.label}</span>
{m.description && (
<span className="text-xs text-muted-foreground">{m.description}</span>
)}
</div>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="thinking-select">{t('dialogs:customModel.thinkingLevel')}</Label>
<Select value={thinkingLevel} onValueChange={(v) => setThinkingLevel(v as ThinkingLevel)}>
<SelectTrigger id="thinking-select">
<SelectValue />
</SelectTrigger>
<SelectContent>
{THINKING_LEVELS.map((level) => (
<SelectItem key={level.value} value={level.value}>
<div className="flex items-center gap-2">
<span className="font-medium">{level.label}</span>
<span className="text-xs text-muted-foreground">
{level.description}
</span>
</div>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={onClose}>
{t('dialogs:customModel.cancel')}
</Button>
<Button onClick={handleSave}>
{t('dialogs:customModel.apply')}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}