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
This commit is contained in:
198
laravel-app/resources/views/admin/credentials/create.blade.php
Normal file
198
laravel-app/resources/views/admin/credentials/create.blade.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<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">
|
||||
{{ __('Add Provider Credentials') }}
|
||||
</h2>
|
||||
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
|
||||
@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
|
||||
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<form method="POST" action="{{ route('admin.credentials.store') }}" class="space-y-6">
|
||||
@csrf
|
||||
|
||||
<!-- User Selection -->
|
||||
<div>
|
||||
<label for="user_id" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
User <span class="text-red-500">*</span>
|
||||
</label>
|
||||
<select
|
||||
name="user_id"
|
||||
id="user_id"
|
||||
required
|
||||
class="w-full rounded-md border-gray-300 @error('user_id') border-red-500 @enderror"
|
||||
>
|
||||
<option value="">Select a user</option>
|
||||
@foreach($users as $user)
|
||||
<option value="{{ $user->id }}" {{ old('user_id') == $user->id ? 'selected' : '' }}>
|
||||
{{ $user->name }} ({{ $user->email }})
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('user_id')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<!-- Provider Selection -->
|
||||
<div>
|
||||
<label for="provider" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
AI Provider <span class="text-red-500">*</span>
|
||||
</label>
|
||||
<select
|
||||
name="provider"
|
||||
id="provider"
|
||||
required
|
||||
class="w-full rounded-md border-gray-300 @error('provider') border-red-500 @enderror"
|
||||
onchange="updateProviderHelp()"
|
||||
>
|
||||
<option value="">Select a provider</option>
|
||||
@foreach($providers as $key => $label)
|
||||
<option value="{{ $key }}" {{ old('provider') == $key ? 'selected' : '' }}>
|
||||
{{ $label }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('provider')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
<!-- Provider-specific help text -->
|
||||
<div id="provider-help" class="mt-2 text-sm text-gray-600">
|
||||
<p class="hidden" data-provider="openai">
|
||||
📝 Get your API key from: <a href="https://platform.openai.com/api-keys" target="_blank" class="text-blue-600 hover:underline">OpenAI Dashboard</a>
|
||||
</p>
|
||||
<p class="hidden" data-provider="anthropic">
|
||||
📝 Get your API key from: <a href="https://console.anthropic.com/settings/keys" target="_blank" class="text-blue-600 hover:underline">Anthropic Console</a>
|
||||
</p>
|
||||
<p class="hidden" data-provider="mistral">
|
||||
📝 Get your API key from: <a href="https://console.mistral.ai/api-keys" target="_blank" class="text-blue-600 hover:underline">Mistral Console</a>
|
||||
</p>
|
||||
<p class="hidden" data-provider="gemini">
|
||||
📝 Get your API key from: <a href="https://makersuite.google.com/app/apikey" target="_blank" class="text-blue-600 hover:underline">Google AI Studio</a>
|
||||
</p>
|
||||
<p class="hidden" data-provider="deepseek">
|
||||
📝 Get your API key from: <a href="https://platform.deepseek.com/api_keys" target="_blank" class="text-blue-600 hover:underline">DeepSeek Platform</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- API Key -->
|
||||
<div>
|
||||
<label for="api_key" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
API Key <span class="text-red-500">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
name="api_key"
|
||||
id="api_key"
|
||||
required
|
||||
placeholder="sk-..."
|
||||
class="w-full rounded-md border-gray-300 @error('api_key') border-red-500 @enderror"
|
||||
value="{{ old('api_key') }}"
|
||||
>
|
||||
@error('api_key')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
🔒 The API key will be encrypted before storage
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Organization ID (Optional) -->
|
||||
<div>
|
||||
<label for="organization_id" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
Organization ID <span class="text-gray-400">(optional)</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="organization_id"
|
||||
id="organization_id"
|
||||
placeholder="org-..."
|
||||
class="w-full rounded-md border-gray-300 @error('organization_id') border-red-500 @enderror"
|
||||
value="{{ old('organization_id') }}"
|
||||
>
|
||||
@error('organization_id')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
Required for some OpenAI enterprise accounts
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Active Status -->
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="is_active"
|
||||
id="is_active"
|
||||
value="1"
|
||||
checked
|
||||
class="rounded border-gray-300 text-blue-600 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50"
|
||||
>
|
||||
<label for="is_active" class="ml-2 block text-sm text-gray-900">
|
||||
Active (enable for immediate use)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="flex items-center justify-end space-x-3">
|
||||
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
|
||||
Cancel
|
||||
</a>
|
||||
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Add Credentials
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Info Box -->
|
||||
<div class="mt-6 bg-blue-50 border border-blue-200 rounded-lg p-4">
|
||||
<h3 class="font-semibold text-blue-900 mb-2">ℹ️ Important Information</h3>
|
||||
<ul class="text-sm text-blue-800 space-y-1 list-disc list-inside">
|
||||
<li>Each user can only have one set of credentials per provider</li>
|
||||
<li>API keys are encrypted using Laravel's encryption (AES-256-CBC)</li>
|
||||
<li>You can test credentials after creation to verify they work</li>
|
||||
<li>Usage and costs will be tracked per user and provider</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
function updateProviderHelp() {
|
||||
const provider = document.getElementById('provider').value;
|
||||
const helpTexts = document.querySelectorAll('#provider-help p');
|
||||
|
||||
helpTexts.forEach(text => text.classList.add('hidden'));
|
||||
|
||||
if (provider) {
|
||||
const selectedHelp = document.querySelector(`#provider-help p[data-provider="${provider}"]`);
|
||||
if (selectedHelp) {
|
||||
selectedHelp.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize on page load if provider is already selected
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
updateProviderHelp();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
</x-app-layout>
|
||||
208
laravel-app/resources/views/admin/credentials/edit.blade.php
Normal file
208
laravel-app/resources/views/admin/credentials/edit.blade.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<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">
|
||||
{{ __('Edit Provider Credentials') }}
|
||||
</h2>
|
||||
<div class="space-x-2">
|
||||
<a href="{{ route('admin.credentials.show', $credential) }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
|
||||
View Details
|
||||
</a>
|
||||
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
|
||||
@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
|
||||
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<form method="POST" action="{{ route('admin.credentials.update', $credential) }}" class="space-y-6">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<!-- User (Read-only) -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">
|
||||
User
|
||||
</label>
|
||||
<div class="w-full px-3 py-2 bg-gray-100 rounded-md border border-gray-300">
|
||||
<div class="font-medium">{{ $credential->user->name }}</div>
|
||||
<div class="text-sm text-gray-500">{{ $credential->user->email }}</div>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
User cannot be changed after creation
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Provider (Read-only) -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">
|
||||
AI Provider
|
||||
</label>
|
||||
<div class="w-full px-3 py-2 bg-gray-100 rounded-md border border-gray-300">
|
||||
<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">
|
||||
{{ $providers[$credential->provider] ?? ucfirst($credential->provider) }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
Provider cannot be changed after creation
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- API Key (Update) -->
|
||||
<div>
|
||||
<label for="api_key" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
API Key <span class="text-gray-400">(leave empty to keep current)</span>
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
name="api_key"
|
||||
id="api_key"
|
||||
placeholder="sk-... (enter new key to update)"
|
||||
class="w-full rounded-md border-gray-300 @error('api_key') border-red-500 @enderror"
|
||||
value="{{ old('api_key') }}"
|
||||
>
|
||||
@error('api_key')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
🔒 Current API key is encrypted and hidden. Enter a new key only if you want to update it.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Organization ID -->
|
||||
<div>
|
||||
<label for="organization_id" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
Organization ID <span class="text-gray-400">(optional)</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="organization_id"
|
||||
id="organization_id"
|
||||
placeholder="org-..."
|
||||
class="w-full rounded-md border-gray-300 @error('organization_id') border-red-500 @enderror"
|
||||
value="{{ old('organization_id', $credential->organization_id) }}"
|
||||
>
|
||||
@error('organization_id')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
Required for some OpenAI enterprise accounts
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Active Status -->
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="is_active"
|
||||
id="is_active"
|
||||
value="1"
|
||||
{{ old('is_active', $credential->is_active) ? 'checked' : '' }}
|
||||
class="rounded border-gray-300 text-blue-600 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50"
|
||||
>
|
||||
<label for="is_active" class="ml-2 block text-sm text-gray-900">
|
||||
Active (enable for use in requests)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Metadata Info -->
|
||||
<div class="bg-gray-50 rounded-lg p-4">
|
||||
<h3 class="font-semibold text-gray-900 mb-2">Metadata</h3>
|
||||
<div class="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span class="text-gray-600">Created:</span>
|
||||
<span class="font-medium">{{ $credential->created_at->format('M d, Y H:i') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-600">Last Updated:</span>
|
||||
<span class="font-medium">{{ $credential->updated_at->format('M d, Y H:i') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-600">Last Used:</span>
|
||||
<span class="font-medium">{{ $credential->last_used_at ? $credential->last_used_at->diffForHumans() : 'Never' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="flex items-center justify-end space-x-3">
|
||||
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
|
||||
Cancel
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
onclick="testCredential({{ $credential->id }})"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
🧪 Test Current Key
|
||||
</button>
|
||||
<button type="submit" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
|
||||
Update Credentials
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Info Box -->
|
||||
<div class="mt-6 bg-yellow-50 border border-yellow-200 rounded-lg p-4">
|
||||
<h3 class="font-semibold text-yellow-900 mb-2">⚠️ Important Notes</h3>
|
||||
<ul class="text-sm text-yellow-800 space-y-1 list-disc list-inside">
|
||||
<li>User and Provider cannot be changed once created</li>
|
||||
<li>Test the API key before saving to ensure it works</li>
|
||||
<li>Old API key will be replaced if you enter a new one</li>
|
||||
<li>Disabling credentials will prevent any API requests using this key</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
function testCredential(credentialId) {
|
||||
const button = event.target;
|
||||
const originalText = button.textContent;
|
||||
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 = originalText;
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
</x-app-layout>
|
||||
230
laravel-app/resources/views/admin/credentials/index.blade.php
Normal file
230
laravel-app/resources/views/admin/credentials/index.blade.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<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>
|
||||
232
laravel-app/resources/views/admin/credentials/show.blade.php
Normal file
232
laravel-app/resources/views/admin/credentials/show.blade.php
Normal file
@@ -0,0 +1,232 @@
|
||||
<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 Details') }}
|
||||
</h2>
|
||||
<div class="space-x-2">
|
||||
<button
|
||||
onclick="testCredential({{ $credential->id }})"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
🧪 Test API Key
|
||||
</button>
|
||||
<a href="{{ route('admin.credentials.edit', $credential) }}" class="bg-yellow-500 hover:bg-yellow-700 text-white font-bold py-2 px-4 rounded">
|
||||
Edit
|
||||
</a>
|
||||
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
|
||||
|
||||
<!-- Basic Information -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Basic Information</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<!-- User -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">User</label>
|
||||
<div class="text-lg font-semibold">{{ $credential->user->name }}</div>
|
||||
<div class="text-sm text-gray-500">{{ $credential->user->email }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Provider -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Provider</label>
|
||||
<span class="inline-flex items-center px-4 py-2 rounded-full text-base 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>
|
||||
</div>
|
||||
|
||||
<!-- Organization ID -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Organization ID</label>
|
||||
<div class="text-base">{{ $credential->organization_id ?? 'Not set' }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Status -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Status</label>
|
||||
@if($credential->is_active)
|
||||
<span class="px-4 inline-flex text-base leading-7 font-semibold rounded-full bg-green-100 text-green-800">
|
||||
✓ Active
|
||||
</span>
|
||||
@else
|
||||
<span class="px-4 inline-flex text-base leading-7 font-semibold rounded-full bg-red-100 text-red-800">
|
||||
✗ Inactive
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<!-- Created At -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Created</label>
|
||||
<div class="text-base">{{ $credential->created_at->format('M d, Y H:i') }}</div>
|
||||
<div class="text-sm text-gray-500">{{ $credential->created_at->diffForHumans() }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Last Used -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Last Used</label>
|
||||
<div class="text-base">
|
||||
@if($credential->last_used_at)
|
||||
{{ $credential->last_used_at->format('M d, Y H:i') }}
|
||||
<div class="text-sm text-gray-500">{{ $credential->last_used_at->diffForHumans() }}</div>
|
||||
@else
|
||||
<span class="text-gray-500">Never used</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Usage Statistics -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Usage Statistics</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<!-- Total Requests -->
|
||||
<div class="bg-blue-50 rounded-lg p-4">
|
||||
<div class="text-sm text-blue-600 font-medium">Total Requests</div>
|
||||
<div class="text-2xl font-bold text-blue-900">{{ number_format($stats['total_requests']) }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Total Cost -->
|
||||
<div class="bg-green-50 rounded-lg p-4">
|
||||
<div class="text-sm text-green-600 font-medium">Total Cost</div>
|
||||
<div class="text-2xl font-bold text-green-900">${{ number_format($stats['total_cost'], 2) }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Total Tokens -->
|
||||
<div class="bg-purple-50 rounded-lg p-4">
|
||||
<div class="text-sm text-purple-600 font-medium">Total Tokens</div>
|
||||
<div class="text-2xl font-bold text-purple-900">{{ number_format($stats['total_tokens']) }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Last 30 Days -->
|
||||
<div class="bg-yellow-50 rounded-lg p-4">
|
||||
<div class="text-sm text-yellow-600 font-medium">Last 30 Days</div>
|
||||
<div class="text-2xl font-bold text-yellow-900">{{ number_format($stats['last_30_days_requests']) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Security Information -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Security Information</h3>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-start">
|
||||
<span class="text-green-500 text-xl mr-3">🔒</span>
|
||||
<div>
|
||||
<div class="font-medium">Encryption Status</div>
|
||||
<div class="text-sm text-gray-600">API key is encrypted using AES-256-CBC encryption</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-start">
|
||||
<span class="text-blue-500 text-xl mr-3">🔑</span>
|
||||
<div>
|
||||
<div class="font-medium">API Key Format</div>
|
||||
<div class="text-sm text-gray-600">
|
||||
<code class="bg-gray-100 px-2 py-1 rounded">{{ $credential->provider }}-*********************</code>
|
||||
(hidden for security)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-start">
|
||||
<span class="text-purple-500 text-xl mr-3">📊</span>
|
||||
<div>
|
||||
<div class="font-medium">Usage Tracking</div>
|
||||
<div class="text-sm text-gray-600">All requests using this credential are logged and tracked</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Actions</h3>
|
||||
|
||||
<div class="flex space-x-3">
|
||||
<button
|
||||
onclick="testCredential({{ $credential->id }})"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
🧪 Test API Key
|
||||
</button>
|
||||
|
||||
<a href="{{ route('admin.credentials.edit', $credential) }}" class="bg-yellow-500 hover:bg-yellow-700 text-white font-bold py-2 px-4 rounded">
|
||||
✏️ Edit Credentials
|
||||
</a>
|
||||
|
||||
<form
|
||||
action="{{ route('admin.credentials.destroy', $credential) }}"
|
||||
method="POST"
|
||||
onsubmit="return confirm('Are you sure you want to delete these credentials? This action cannot be undone.');"
|
||||
class="inline">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
|
||||
🗑️ Delete Credentials
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
function testCredential(credentialId) {
|
||||
const button = event.target;
|
||||
const originalText = button.textContent;
|
||||
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 = originalText;
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
</x-app-layout>
|
||||
Reference in New Issue
Block a user