|
@@ -1,12 +1,69 @@
|
|
|
// LLM Providers management page
|
|
// LLM Providers management page
|
|
|
|
|
|
|
|
import { useState, useEffect, useCallback } from 'react'
|
|
import { useState, useEffect, useCallback } from 'react'
|
|
|
-import { Plus, Trash2, Edit2, RefreshCw, CheckCircle, XCircle, Loader2 } from 'lucide-react'
|
|
|
|
|
import * as chatApi from '@/api/chat'
|
|
import * as chatApi from '@/api/chat'
|
|
|
import Button from '@/components/Button'
|
|
import Button from '@/components/Button'
|
|
|
import Input from '@/components/Input'
|
|
import Input from '@/components/Input'
|
|
|
import type { LlmProvider, CreateProviderRequest, UpdateProviderRequest } from '@/types/chat'
|
|
import type { LlmProvider, CreateProviderRequest, UpdateProviderRequest } from '@/types/chat'
|
|
|
|
|
|
|
|
|
|
+// Inline SVG Icons
|
|
|
|
|
+function PlusIcon({ className = 'h-4 w-4' }: { className?: string }) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
|
|
|
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function TrashIcon({ className = 'h-4 w-4' }: { className?: string }) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
|
|
|
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function EditIcon({ className = 'h-4 w-4' }: { className?: string }) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
|
|
|
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function RefreshIcon({ className = 'h-4 w-4' }: { className?: string }) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
|
|
|
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function CheckCircleIcon({ className = 'h-3 w-3' }: { className?: string }) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
|
|
|
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function XCircleIcon({ className = 'h-3 w-3' }: { className?: string }) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
|
|
|
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function LoaderIcon({ className = 'h-8 w-8' }: { className?: string }) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <svg className={className} fill="none" viewBox="0 0 24 24">
|
|
|
|
|
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
|
|
|
+ <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
|
|
|
|
+ </svg>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const PROVIDER_TYPES = [
|
|
const PROVIDER_TYPES = [
|
|
|
{ value: 'PROVIDER_TYPE_OPENAI', label: 'OpenAI Compatible', defaultUrl: 'https://api.openai.com/v1' },
|
|
{ value: 'PROVIDER_TYPE_OPENAI', label: 'OpenAI Compatible', defaultUrl: 'https://api.openai.com/v1' },
|
|
|
{ value: 'PROVIDER_TYPE_ANTHROPIC', label: 'Anthropic Compatible', defaultUrl: 'https://api.anthropic.com/v1' },
|
|
{ value: 'PROVIDER_TYPE_ANTHROPIC', label: 'Anthropic Compatible', defaultUrl: 'https://api.anthropic.com/v1' },
|
|
@@ -329,7 +386,7 @@ export default function LlmProviders() {
|
|
|
</p>
|
|
</p>
|
|
|
</div>
|
|
</div>
|
|
|
<Button onClick={() => setIsModalOpen(true)}>
|
|
<Button onClick={() => setIsModalOpen(true)}>
|
|
|
- <Plus className="mr-2 h-4 w-4" />
|
|
|
|
|
|
|
+ <PlusIcon className="mr-2 h-4 w-4" />
|
|
|
Add Provider
|
|
Add Provider
|
|
|
</Button>
|
|
</Button>
|
|
|
</div>
|
|
</div>
|
|
@@ -340,13 +397,13 @@ export default function LlmProviders() {
|
|
|
|
|
|
|
|
{isLoading ? (
|
|
{isLoading ? (
|
|
|
<div className="mt-8 flex justify-center">
|
|
<div className="mt-8 flex justify-center">
|
|
|
- <Loader2 className="h-8 w-8 animate-spin text-gray-400" />
|
|
|
|
|
|
|
+ <LoaderIcon className="h-8 w-8 animate-spin text-gray-400" />
|
|
|
</div>
|
|
</div>
|
|
|
) : providers.length === 0 ? (
|
|
) : providers.length === 0 ? (
|
|
|
<div className="mt-8 text-center">
|
|
<div className="mt-8 text-center">
|
|
|
<p className="text-gray-500">No providers configured yet.</p>
|
|
<p className="text-gray-500">No providers configured yet.</p>
|
|
|
<Button onClick={() => setIsModalOpen(true)} className="mt-4">
|
|
<Button onClick={() => setIsModalOpen(true)} className="mt-4">
|
|
|
- <Plus className="mr-2 h-4 w-4" />
|
|
|
|
|
|
|
+ <PlusIcon className="mr-2 h-4 w-4" />
|
|
|
Add your first provider
|
|
Add your first provider
|
|
|
</Button>
|
|
</Button>
|
|
|
</div>
|
|
</div>
|
|
@@ -369,12 +426,12 @@ export default function LlmProviders() {
|
|
|
{provider.enabled && healthStatus[provider.id] !== undefined && (
|
|
{provider.enabled && healthStatus[provider.id] !== undefined && (
|
|
|
healthStatus[provider.id]?.healthy ? (
|
|
healthStatus[provider.id]?.healthy ? (
|
|
|
<span className="flex items-center gap-1 rounded-full bg-green-100 px-2 py-0.5 text-xs text-green-700">
|
|
<span className="flex items-center gap-1 rounded-full bg-green-100 px-2 py-0.5 text-xs text-green-700">
|
|
|
- <CheckCircle className="h-3 w-3" />
|
|
|
|
|
|
|
+ <CheckCircleIcon className="h-3 w-3" />
|
|
|
{healthStatus[provider.id]?.latency_ms}ms
|
|
{healthStatus[provider.id]?.latency_ms}ms
|
|
|
</span>
|
|
</span>
|
|
|
) : (
|
|
) : (
|
|
|
<span className="flex items-center gap-1 rounded-full bg-red-100 px-2 py-0.5 text-xs text-red-700">
|
|
<span className="flex items-center gap-1 rounded-full bg-red-100 px-2 py-0.5 text-xs text-red-700">
|
|
|
- <XCircle className="h-3 w-3" />
|
|
|
|
|
|
|
+ <XCircleIcon className="h-3 w-3" />
|
|
|
Unhealthy
|
|
Unhealthy
|
|
|
</span>
|
|
</span>
|
|
|
)
|
|
)
|
|
@@ -394,7 +451,7 @@ export default function LlmProviders() {
|
|
|
className="rounded p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-600 disabled:opacity-50"
|
|
className="rounded p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-600 disabled:opacity-50"
|
|
|
title="Refresh models"
|
|
title="Refresh models"
|
|
|
>
|
|
>
|
|
|
- <RefreshCw className={`h-4 w-4 ${refreshingProvider === provider.id ? 'animate-spin' : ''}`} />
|
|
|
|
|
|
|
+ <RefreshIcon className={`h-4 w-4 ${refreshingProvider === provider.id ? 'animate-spin' : ''}`} />
|
|
|
</button>
|
|
</button>
|
|
|
<button
|
|
<button
|
|
|
onClick={() => {
|
|
onClick={() => {
|
|
@@ -404,14 +461,14 @@ export default function LlmProviders() {
|
|
|
className="rounded p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-600"
|
|
className="rounded p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-600"
|
|
|
title="Edit provider"
|
|
title="Edit provider"
|
|
|
>
|
|
>
|
|
|
- <Edit2 className="h-4 w-4" />
|
|
|
|
|
|
|
+ <EditIcon className="h-4 w-4" />
|
|
|
</button>
|
|
</button>
|
|
|
<button
|
|
<button
|
|
|
onClick={() => setDeletingProvider(provider)}
|
|
onClick={() => setDeletingProvider(provider)}
|
|
|
className="rounded p-2 text-gray-400 hover:bg-red-50 hover:text-red-600"
|
|
className="rounded p-2 text-gray-400 hover:bg-red-50 hover:text-red-600"
|
|
|
title="Delete provider"
|
|
title="Delete provider"
|
|
|
>
|
|
>
|
|
|
- <Trash2 className="h-4 w-4" />
|
|
|
|
|
|
|
+ <TrashIcon className="h-4 w-4" />
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|