fix(api): complete anthropic direct profile support

This commit is contained in:
Tam Nhu Tran
2026-03-07 15:58:36 +07:00
parent fedb4d4cde
commit 1f29fa0b6a
11 changed files with 270 additions and 33 deletions
@@ -51,12 +51,18 @@ import type { CategorizedModel } from '@/lib/openrouter-types';
import type { CliTarget } from '@/lib/api-client';
import i18n from '@/lib/i18n';
const optionalUrlSchema = z
.string()
.refine((value) => value.trim().length === 0 || z.string().url().safeParse(value).success, {
message: 'Invalid URL format',
});
const schema = z.object({
name: z
.string()
.min(1, 'Name is required')
.regex(/^[a-zA-Z][a-zA-Z0-9._-]*$/, 'Must start with letter, only letters/numbers/.-_'),
baseUrl: z.string().url('Invalid URL format'),
baseUrl: optionalUrlSchema,
apiKey: z.string(), // Validation handled conditionally in onSubmit
model: z.string().optional(),
opusModel: z.string().optional(),
@@ -389,9 +395,7 @@ export function ProfileCreateDialog({
{/* Base URL - always editable, pre-filled from preset */}
<div className="space-y-1.5">
<Label htmlFor="baseUrl">
API Base URL <span className="text-destructive">*</span>
</Label>
<Label htmlFor="baseUrl">API Base URL</Label>
<Input
id="baseUrl"
{...register('baseUrl')}
@@ -406,7 +410,9 @@ export function ProfileCreateDialog({
</div>
) : currentPreset ? (
<p className="text-xs text-muted-foreground">
Pre-filled from {currentPreset.name}. You can customize if needed.
{currentPreset.baseUrl
? `Pre-filled from ${currentPreset.name}. You can customize if needed.`
: `Optional for ${currentPreset.name}. Leave blank to use native Anthropic auth.`}
</p>
) : (
<p className="text-xs text-muted-foreground">
@@ -19,13 +19,18 @@ import { ChevronDown, ChevronRight } from 'lucide-react';
import { useTranslation } from 'react-i18next';
const DEFAULT_MODEL = 'claude-sonnet-4-5-20250929';
const optionalUrlSchema = z
.string()
.refine((value) => value.trim().length === 0 || z.string().url().safeParse(value).success, {
message: 'Invalid URL',
});
const schema = z.object({
name: z
.string()
.min(1, 'Name is required')
.regex(/^[a-zA-Z][a-zA-Z0-9._-]*$/, 'Invalid profile name'),
baseUrl: z.string().url('Invalid URL'),
baseUrl: optionalUrlSchema,
apiKey: z.string().min(10, 'API key must be at least 10 characters'),
model: z.string().optional(),
opusModel: z.string().optional(),