Files
wtrinkl 6573e15ba4 Add complete Laravel LLM Gateway implementation
Core Features:
- Multi-provider support (OpenAI, Anthropic, DeepSeek, Gemini, Mistral)
- Provider service architecture with abstract base class
- Dynamic model discovery from provider APIs
- Encrypted per-user provider credentials storage

Admin Interface:
- Complete admin panel with Livewire components
- User management with CRUD operations
- API key management with testing capabilities
- Budget system with limits and reset schedules
- Usage logs with filtering and CSV export
- Model pricing management with cost calculator
- Dashboard with Chart.js visualizations

Database Schema:
- MariaDB migrations for all tables
- User provider credentials (encrypted)
- LLM request logging
- Budget tracking and rate limiting
- Model pricing configuration

API Implementation:
- OpenAI-compatible endpoints
- Budget checking middleware
- Rate limit enforcement
- Request logging jobs
- Cost calculation service

Testing:
- Unit tests for all provider services
- Provider factory tests
- Cost calculator tests

Documentation:
- Admin user seeder
- Model pricing seeder
- Configuration files
2025-11-18 22:18:36 +01:00

231 lines
13 KiB
PHP

<x-app-layout>
<x-slot name="header">
<div class="flex justify-between items-center">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Provider Credentials') }}
</h2>
<a href="{{ route('admin.credentials.create') }}" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Add New Credentials
</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<!-- Success/Error Messages -->
@if(session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
{{ session('success') }}
</div>
@endif
@if(session('error'))
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
{{ session('error') }}
</div>
@endif
<!-- Filters -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg mb-6">
<div class="p-6">
<form method="GET" action="{{ route('admin.credentials.index') }}" class="space-y-4">
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<!-- Provider Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Provider</label>
<select name="provider" class="w-full rounded-md border-gray-300">
<option value="">All Providers</option>
@foreach($providers as $provider)
<option value="{{ $provider }}" {{ request('provider') == $provider ? 'selected' : '' }}>
{{ ucfirst($provider) }}
</option>
@endforeach
</select>
</div>
<!-- User Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">User</label>
<select name="user_id" class="w-full rounded-md border-gray-300">
<option value="">All Users</option>
@foreach($users as $user)
<option value="{{ $user->id }}" {{ request('user_id') == $user->id ? 'selected' : '' }}>
{{ $user->name }}
</option>
@endforeach
</select>
</div>
<!-- Status Filter -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Status</label>
<select name="status" class="w-full rounded-md border-gray-300">
<option value="">All Status</option>
<option value="active" {{ request('status') == 'active' ? 'selected' : '' }}>Active</option>
<option value="inactive" {{ request('status') == 'inactive' ? 'selected' : '' }}>Inactive</option>
</select>
</div>
<!-- Search -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Search User</label>
<input
type="text"
name="search"
value="{{ request('search') }}"
placeholder="Name or email"
class="w-full rounded-md border-gray-300"
>
</div>
</div>
<div class="flex space-x-2">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Apply Filters
</button>
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
Reset
</a>
</div>
</form>
</div>
</div>
<!-- Credentials Table -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
User
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Provider
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Organization ID
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Status
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Last Used
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@forelse($credentials as $credential)
<tr>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm font-medium text-gray-900">{{ $credential->user->name }}</div>
<div class="text-sm text-gray-500">{{ $credential->user->email }}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium
@if($credential->provider == 'openai') bg-green-100 text-green-800
@elseif($credential->provider == 'anthropic') bg-purple-100 text-purple-800
@elseif($credential->provider == 'mistral') bg-blue-100 text-blue-800
@elseif($credential->provider == 'gemini') bg-yellow-100 text-yellow-800
@else bg-gray-100 text-gray-800
@endif">
{{ ucfirst($credential->provider) }}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $credential->organization_id ?? '-' }}
</td>
<td class="px-6 py-4 whitespace-nowrap">
@if($credential->is_active)
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
Active
</span>
@else
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
Inactive
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $credential->last_used_at ? $credential->last_used_at->diffForHumans() : 'Never' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium space-x-2">
<button
onclick="testCredential({{ $credential->id }})"
class="text-blue-600 hover:text-blue-900"
title="Test API Key">
🧪 Test
</button>
<a href="{{ route('admin.credentials.show', $credential) }}" class="text-indigo-600 hover:text-indigo-900">
View
</a>
<a href="{{ route('admin.credentials.edit', $credential) }}" class="text-yellow-600 hover:text-yellow-900">
Edit
</a>
<form action="{{ route('admin.credentials.destroy', $credential) }}" method="POST" class="inline" onsubmit="return confirm('Are you sure you want to delete these credentials?');">
@csrf
@method('DELETE')
<button type="submit" class="text-red-600 hover:text-red-900">
Delete
</button>
</form>
</td>
</tr>
@empty
<tr>
<td colspan="6" class="px-6 py-4 text-center text-gray-500">
No credentials found. <a href="{{ route('admin.credentials.create') }}" class="text-blue-600 hover:text-blue-900">Add your first credentials</a>
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="mt-4">
{{ $credentials->links() }}
</div>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
function testCredential(credentialId) {
const button = event.target;
button.textContent = '🔄 Testing...';
button.disabled = true;
fetch(`/admin/credentials/${credentialId}/test`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert(`✅ Success!\n\n${data.message}\n${data.details || ''}`);
} else {
alert(`❌ Failed!\n\n${data.message}`);
}
})
.catch(error => {
alert(`❌ Error!\n\n${error.message}`);
})
.finally(() => {
button.textContent = '🧪 Test';
button.disabled = false;
});
}
</script>
@endpush
</x-app-layout>