Swadhin Biswas Feature/ai code reviewer (#73) · 8/2/2026
105a287
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
---
import BaseLayout from "@/layouts/BaseLayout.astro";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import {
parseAIConfigFromStorage,
sanitizeAIConfigForClient,
type PublicAIConfig,
} from "@/lib/ai-config";
const user = Astro.locals.user;
if (!user) return Astro.redirect("/login");
// Parse existing config
let aiConfig: PublicAIConfig = {
provider: "openai",
model: "gpt-4-turbo",
apiKeys: {
openai: { isSet: false },
anthropic: { isSet: false },
groq: { isSet: false },
bytez: { isSet: false },
openrouter: { isSet: false },
together: { isSet: false },
google: { isSet: false },
local: { isSet: false },
externalAgent: { isSet: false },
},
localBaseUrl: "",
externalAgentWebhookUrl: "",
};
try {
if (user.aiConfig) {
aiConfig = sanitizeAIConfigForClient(parseAIConfigFromStorage(user.aiConfig));
}
} catch (e) {}
const sideNav = [
{ name: "Profile", href: "/settings/profile" },
{ name: "Account", href: "/settings/account" },
{ name: "Security", href: "/settings/security" },
{ name: "SSH Keys", href: "/settings/ssh-keys" },
{
name: "Notification Preferences",
href: "/settings/notification-preferences",
},
{ name: "AI Settings", href: "/settings/ai", active: true },
];
---
<BaseLayout title="AI Settings">
<div class="container max-w-screen-lg py-10">
<div
class="flex flex-col space-y-8 lg:flex-row lg:space-x-12 lg:space-y-0"
>
<aside class="-mx-4 lg:w-1/5">
<nav
class="flex space-x-2 lg:flex-col lg:space-x-0 lg:space-y-1"
>
{
sideNav.map((item) => (
<a
href={item.href}
class={`justify-start rounded-md px-3 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground ${
item.active
? "bg-accent text-accent-foreground"
: "text-muted-foreground"
}`}
>
{item.name}
</a>
))
}
</nav>
</aside>
<div class="flex-1 lg:max-w-2xl">
<div class="space-y-6">
<div>
<h3 class="text-lg font-medium">AI Settings</h3>
<p class="text-sm text-muted-foreground">
Configure AI providers for code review and
generation features.
</p>
</div>
<hr class="border-border" />
<form id="ai-settings-form" class="space-y-8">
<Card>
<CardHeader>
<CardTitle>Default Provider</CardTitle>
<CardDescription>
Select which AI provider to use for
automated code reviews.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div class="space-y-2">
<Label htmlFor="provider"
>Active Provider</Label
>
<select
id="provider"
name="provider"
class="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
>
<option
value="openai"
selected={aiConfig.provider ===
"openai"}
>OpenAI (Default)</option
>
<option
value="groq"
selected={aiConfig.provider ===
"groq"}
>Groq (Fast & Cheap)</option
>
<option
value="bytez"
selected={aiConfig.provider ===
"bytez"}
>Bytez (Many Models)</option
>
<option
value="openrouter"
selected={aiConfig.provider ===
"openrouter"}
>OpenRouter (Free models)</option
>
<option
value="together"
selected={aiConfig.provider ===
"together"}
>Together AI (Open models)</option
>
<option
value="google"
selected={aiConfig.provider ===
"google"}
>Google Gemini</option
>
<option
value="external_agent"
selected={aiConfig.provider ===
"external_agent"}
>External Agent (Greptile-like)</option
>
<option
value="anthropic"
selected={aiConfig.provider ===
"anthropic"}
>Anthropic</option
>
<option
value="local"
selected={aiConfig.provider ===
"local"}
>Local LLM (Ollama/OpenAI-compatible)</option
>
</select>
</div>
<div class="space-y-2">
<Label htmlFor="model">Model Name</Label>
<Input
id="model"
name="model"
placeholder="e.g. gpt-4-turbo, llama3-70b-8192"
value={aiConfig.model}
/>
<p class="text-xs text-muted-foreground">
Leave blank to use provider default.
Recommended: `gpt-4-turbo` (OpenAI),
`llama3-70b-8192` (Groq),
`meta-llama/llama-3.1-8b-instruct:free` (OpenRouter),
`llama3.1` (Local).
</p>
</div>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>API Keys</CardTitle>
<CardDescription>
Your keys are stored securely and encrypted
in the database.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div class="space-y-2">
<Label htmlFor="openai-key"
>OpenAI API Key</Label
>
<Input
id="openai-key"
name="openaiKey"
type="password"
placeholder={aiConfig.apiKeys.openai.masked || "sk-..."}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="anthropic-key"
>Anthropic API Key</Label
>
<Input
id="anthropic-key"
name="anthropicKey"
type="password"
placeholder={aiConfig.apiKeys.anthropic.masked || "sk-ant-..."}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="groq-key"
>Groq API Key</Label
>
<Input
id="groq-key"
name="groqKey"
type="password"
placeholder={aiConfig.apiKeys.groq.masked || "gsk_..."}
value=""
/>
<p class="text-xs text-muted-foreground">
Get a free key at <a
href="https://console.groq.com"
target="_blank"
class="underline hover:text-blue-400"
>console.groq.com</a
>
</p>
</div>
<div class="space-y-2">
<Label htmlFor="bytez-key"
>Bytez API Key</Label
>
<Input
id="bytez-key"
name="bytezKey"
type="password"
placeholder={aiConfig.apiKeys.bytez.masked || "bytez_..."}
value=""
/>
<p class="text-xs text-muted-foreground">
Get a key at <a
href="https://bytez.com"
target="_blank"
class="underline hover:text-blue-400"
>bytez.com</a
>
</p>
</div>
<div class="space-y-2">
<Label htmlFor="openrouter-key"
>OpenRouter API Key</Label
>
<Input
id="openrouter-key"
name="openrouterKey"
type="password"
placeholder={aiConfig.apiKeys.openrouter.masked || "sk-or-..."}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="together-key"
>Together API Key</Label
>
<Input
id="together-key"
name="togetherKey"
type="password"
placeholder={aiConfig.apiKeys.together.masked || "together_..."}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="google-key"
>Google AI API Key</Label
>
<Input
id="google-key"
name="googleKey"
type="password"
placeholder={aiConfig.apiKeys.google.masked || "AIza..."}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="local-base-url"
>Local AI Base URL</Label
>
<Input
id="local-base-url"
name="localBaseUrl"
type="url"
placeholder={aiConfig.localBaseUrl || "http://127.0.0.1:11434/v1"}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="local-key"
>Local AI API Key (optional)</Label
>
<Input
id="local-key"
name="localKey"
type="password"
placeholder={aiConfig.apiKeys.local.masked || "ollama"}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="external-agent-webhook"
>External Agent Webhook URL</Label
>
<Input
id="external-agent-webhook"
name="externalAgentWebhookUrl"
type="url"
placeholder={aiConfig.externalAgentWebhookUrl || "https://your-agent/webhooks/review"}
value=""
/>
</div>
<div class="space-y-2">
<Label htmlFor="external-agent-key"
>External Agent Token</Label
>
<Input
id="external-agent-key"
name="externalAgentKey"
type="password"
placeholder={aiConfig.apiKeys.externalAgent.masked || "agent_..."}
value=""
/>
</div>
</CardContent>
</Card>
<div class="flex justify-end">
<Button type="submit">Save Changes</Button>
</div>
</form>
</div>
</div>
</div>
</div>
</BaseLayout>
<script>
import { toast } from "sonner";
const form = document.getElementById("ai-settings-form") as HTMLFormElement;
form.addEventListener("submit", async (e) => {
e.preventDefault();
const formData = new FormData(form);
const payload = {
provider: formData.get("provider"),
model: formData.get("model"),
apiKeys: {
openai: formData.get("openaiKey"),
anthropic: formData.get("anthropicKey"),
groq: formData.get("groqKey"),
bytez: formData.get("bytezKey"),
openrouter: formData.get("openrouterKey"),
together: formData.get("togetherKey"),
google: formData.get("googleKey"),
local: formData.get("localKey"),
externalAgent: formData.get("externalAgentKey"),
},
localBaseUrl: formData.get("localBaseUrl"),
externalAgentWebhookUrl: formData.get("externalAgentWebhookUrl"),
};
try {
const res = await fetch("/api/user/ai-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (!res.ok) throw new Error("Failed to save settings");
toast.success("AI settings saved successfully");
} catch (error) {
toast.error("Failed to save settings");
}
});
</script>