Initial commit: Any-LLM Gateway with Laravel Admin Interface

- Any-LLM Gateway setup with Docker Compose
- Laravel 11 admin interface with Livewire
- Dashboard with usage statistics and charts
- Gateway Users management with budget tracking
- API Keys management with revocation
- Budget templates with assignment
- Usage Logs with filtering and CSV export
- Model Pricing management with calculator
- PostgreSQL database integration
- Complete authentication system for admins
This commit is contained in:
wtrinkl
2025-11-16 12:38:05 +01:00
commit b1363aeab9
148 changed files with 23995 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Create Budget Template
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900">
<form action="{{ route('budgets.store') }}" method="POST">
@csrf
<!-- Budget Name (for display purposes) -->
<div class="mb-4">
<label for="budget_name" class="block text-sm font-medium text-gray-700">Budget Template Name</label>
<input type="text" name="budget_name" id="budget_name"
value="{{ old('budget_name') }}"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
placeholder="e.g., Standard Monthly Budget"
required>
@error('budget_name')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<!-- Max Budget -->
<div class="mb-4">
<label for="max_budget" class="block text-sm font-medium text-gray-700">Maximum Budget ($)</label>
<input type="number" name="max_budget" id="max_budget"
value="{{ old('max_budget') }}"
step="0.01" min="0"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
placeholder="100.00"
required>
@error('max_budget')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<!-- Budget Type -->
<div class="mb-4">
<label for="budget_type" class="block text-sm font-medium text-gray-700 mb-2">Budget Duration</label>
<select name="budget_type" id="budget_type"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
required>
<option value="daily" {{ old('budget_type') == 'daily' ? 'selected' : '' }}>Daily (24 hours)</option>
<option value="weekly" {{ old('budget_type') == 'weekly' ? 'selected' : '' }}>Weekly (7 days)</option>
<option value="monthly" {{ old('budget_type') == 'monthly' ? 'selected' : '' }}>Monthly (30 days)</option>
<option value="custom" {{ old('budget_type') == 'custom' ? 'selected' : '' }}>Custom Duration</option>
<option value="unlimited" {{ old('budget_type') == 'unlimited' ? 'selected' : '' }}>Unlimited (No Reset)</option>
</select>
@error('budget_type')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<!-- Custom Duration (shown when custom is selected) -->
<div class="mb-4" id="custom_duration_field" style="display: none;">
<label for="custom_duration_days" class="block text-sm font-medium text-gray-700">Custom Duration (Days)</label>
<input type="number" name="custom_duration_days" id="custom_duration_days"
value="{{ old('custom_duration_days') }}"
min="1"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
placeholder="e.g., 14">
@error('custom_duration_days')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<!-- Info Box -->
<div class="mb-6 p-4 bg-blue-50 rounded-lg">
<h4 class="text-sm font-medium text-blue-900 mb-2"> Budget Template Info</h4>
<ul class="text-sm text-blue-700 space-y-1">
<li> Budget templates can be assigned to multiple users</li>
<li> Users will automatically reset when duration expires</li>
<li> "Unlimited" budgets never reset automatically</li>
</ul>
</div>
<!-- Actions -->
<div class="flex items-center justify-end gap-4">
<a href="{{ route('budgets.index') }}" class="text-gray-600 hover:text-gray-900">Cancel</a>
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Create Budget Template
</button>
</div>
</form>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
// Toggle custom duration field
document.getElementById('budget_type').addEventListener('change', function() {
const customField = document.getElementById('custom_duration_field');
if (this.value === 'custom') {
customField.style.display = 'block';
} else {
customField.style.display = 'none';
}
});
// Trigger on page load if custom was selected
if (document.getElementById('budget_type').value === 'custom') {
document.getElementById('custom_duration_field').style.display = 'block';
}
</script>
@endpush
</x-app-layout>

View File

@@ -0,0 +1,102 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Edit Budget Template
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900">
<form action="{{ route('budgets.update', $budget->budget_id) }}" method="POST">
@csrf
@method('PUT')
<!-- Budget ID (read-only) -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Budget ID</label>
<input type="text" value="{{ $budget->budget_id }}"
class="mt-1 block w-full rounded-md border-gray-300 bg-gray-100 shadow-sm"
disabled>
</div>
<!-- Max Budget -->
<div class="mb-4">
<label for="max_budget" class="block text-sm font-medium text-gray-700">Maximum Budget ($)</label>
<input type="number" name="max_budget" id="max_budget"
value="{{ old('max_budget', $budget->max_budget) }}"
step="0.01" min="0"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
required>
@error('max_budget')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<!-- Budget Type -->
<div class="mb-4">
<label for="budget_type" class="block text-sm font-medium text-gray-700 mb-2">Budget Duration</label>
<select name="budget_type" id="budget_type"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
required>
<option value="daily" {{ old('budget_type', $budgetType) == 'daily' ? 'selected' : '' }}>Daily (24 hours)</option>
<option value="weekly" {{ old('budget_type', $budgetType) == 'weekly' ? 'selected' : '' }}>Weekly (7 days)</option>
<option value="monthly" {{ old('budget_type', $budgetType) == 'monthly' ? 'selected' : '' }}>Monthly (30 days)</option>
<option value="custom" {{ old('budget_type', $budgetType) == 'custom' ? 'selected' : '' }}>Custom Duration</option>
<option value="unlimited" {{ old('budget_type', $budgetType) == 'unlimited' ? 'selected' : '' }}>Unlimited (No Reset)</option>
</select>
@error('budget_type')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<!-- Custom Duration -->
<div class="mb-4" id="custom_duration_field" style="display: {{ $budgetType == 'custom' ? 'block' : 'none' }};">
<label for="custom_duration_days" class="block text-sm font-medium text-gray-700">Custom Duration (Days)</label>
<input type="number" name="custom_duration_days" id="custom_duration_days"
value="{{ old('custom_duration_days', $budget->budget_duration_sec ? floor($budget->budget_duration_sec / 86400) : '') }}"
min="1"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
placeholder="e.g., 14">
@error('custom_duration_days')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<!-- Warning Box -->
<div class="mb-6 p-4 bg-yellow-50 rounded-lg">
<h4 class="text-sm font-medium text-yellow-900 mb-2">⚠️ Warning</h4>
<p class="text-sm text-yellow-700">
This budget is currently assigned to <strong>{{ $budget->gatewayUsers()->count() }} user(s)</strong>.
Changes will affect all assigned users.
</p>
</div>
<!-- Actions -->
<div class="flex items-center justify-end gap-4">
<a href="{{ route('budgets.show', $budget->budget_id) }}" class="text-gray-600 hover:text-gray-900">Cancel</a>
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Update Budget
</button>
</div>
</form>
</div>
</div>
</div>
</div>
@push('scripts')
<script>
// Toggle custom duration field
document.getElementById('budget_type').addEventListener('change', function() {
const customField = document.getElementById('custom_duration_field');
if (this.value === 'custom') {
customField.style.display = 'block';
} else {
customField.style.display = 'none';
}
});
</script>
@endpush
</x-app-layout>

View File

@@ -0,0 +1,98 @@
<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">
Budget Templates
</h2>
<a href="{{ route('budgets.create') }}" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Create Budget Template
</a>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
@if(session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative 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 relative mb-4">
{{ session('error') }}
</div>
@endif
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900">
@if($budgets->count() > 0)
<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">
Budget ID
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Max Budget
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Duration
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Assigned Users
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Created
</th>
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($budgets as $budget)
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
{{ $budget->budget_id }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<span class="font-semibold text-green-600">{{ $budget->max_budget_formatted }}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $budget->duration_human }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
{{ $budget->gateway_users_count }} users
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $budget->created_at->format('M d, Y') }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="{{ route('budgets.show', $budget->budget_id) }}" class="text-blue-600 hover:text-blue-900 mr-3">View</a>
<a href="{{ route('budgets.edit', $budget->budget_id) }}" class="text-indigo-600 hover:text-indigo-900 mr-3">Edit</a>
<form action="{{ route('budgets.destroy', $budget->budget_id) }}" method="POST" class="inline"
onsubmit="return confirm('Are you sure? This budget will be deleted.');">
@csrf
@method('DELETE')
<button type="submit" class="text-red-600 hover:text-red-900">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="mt-4">
{{ $budgets->links() }}
</div>
@else
<p class="text-gray-500 text-center py-8">No budget templates found. Create your first budget template to get started.</p>
@endif
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,164 @@
<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">
Budget Details
</h2>
<div class="flex gap-2">
<a href="{{ route('budgets.edit', $budget->budget_id) }}"
class="bg-indigo-500 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded">
Edit Budget
</a>
<form action="{{ route('budgets.destroy', $budget->budget_id) }}" method="POST"
onsubmit="return confirm('Are you sure? This will delete the budget.');" 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
</button>
</form>
</div>
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
@if(session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded">
{{ session('success') }}
</div>
@endif
<!-- Budget Info Card -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<h3 class="text-lg font-semibold mb-4">Budget Information</h3>
<dl class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div>
<dt class="text-sm font-medium text-gray-500">Budget ID</dt>
<dd class="mt-1 text-sm text-gray-900 font-mono">{{ $budget->budget_id }}</dd>
</div>
<div>
<dt class="text-sm font-medium text-gray-500">Maximum Budget</dt>
<dd class="mt-1 text-2xl font-bold text-green-600">{{ $budget->max_budget_formatted }}</dd>
</div>
<div>
<dt class="text-sm font-medium text-gray-500">Duration</dt>
<dd class="mt-1 text-sm text-gray-900">{{ $budget->duration_human }}</dd>
</div>
<div>
<dt class="text-sm font-medium text-gray-500">Assigned Users</dt>
<dd class="mt-1 text-2xl font-bold text-blue-600">{{ $budget->gatewayUsers()->count() }}</dd>
</div>
<div>
<dt class="text-sm font-medium text-gray-500">Created</dt>
<dd class="mt-1 text-sm text-gray-900">{{ $budget->created_at->format('M d, Y H:i') }}</dd>
</div>
<div>
<dt class="text-sm font-medium text-gray-500">Last Updated</dt>
<dd class="mt-1 text-sm text-gray-900">{{ $budget->updated_at->format('M d, Y H:i') }}</dd>
</div>
</dl>
</div>
</div>
<!-- Assigned Users Table -->
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<h3 class="text-lg font-semibold mb-4">Assigned Users ({{ $budget->gatewayUsers()->count() }})</h3>
@if($budget->gatewayUsers()->count() > 0)
<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">User ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Alias</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Current Spend</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Budget Started</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Next Reset</th>
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase">Actions</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($budget->gatewayUsers as $user)
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-mono text-gray-900">
{{ $user->user_id }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
{{ $user->alias ?? '-' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<span class="font-semibold {{ $user->spend >= $budget->max_budget ? 'text-red-600' : 'text-green-600' }}">
{{ $user->spend_formatted }}
</span>
<span class="text-gray-500">/ {{ $budget->max_budget_formatted }}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $user->budget_started_at?->format('M d, Y') ?? '-' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $user->next_budget_reset_at?->format('M d, Y') ?? 'Never' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="{{ route('gateway-users.show', $user->user_id) }}" class="text-blue-600 hover:text-blue-900">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@else
<p class="text-gray-500 text-center py-8">No users assigned to this budget yet.</p>
@endif
</div>
</div>
<!-- Assign Users Form -->
@if($availableUsers->count() > 0)
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<h3 class="text-lg font-semibold mb-4">Assign Users to Budget</h3>
<form action="{{ route('budgets.assign-users', $budget->budget_id) }}" method="POST">
@csrf
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-2">Select Users</label>
<div class="border rounded-lg p-4 max-h-64 overflow-y-auto">
@foreach($availableUsers as $user)
<div class="flex items-center mb-2">
<input type="checkbox" name="user_ids[]" value="{{ $user->user_id }}"
id="user_{{ $user->user_id }}"
class="rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<label for="user_{{ $user->user_id }}" class="ml-2 text-sm text-gray-900 cursor-pointer">
<span class="font-mono">{{ $user->user_id }}</span>
@if($user->alias)
<span class="text-gray-500">({{ $user->alias }})</span>
@endif
</label>
</div>
@endforeach
</div>
@error('user_ids')
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
@enderror
</div>
<div class="flex items-center justify-end">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Assign Selected Users
</button>
</div>
</form>
</div>
</div>
@else
<div class="bg-gray-50 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-center text-gray-500">
All users are currently assigned to budgets. No available users to assign.
</div>
</div>
@endif
</div>
</div>
</x-app-layout>