feat: API Key pro Agent statt pro User
- Neue Tabelle agent_api_keys (user_id, agent_id, key_id) - Migration: bestehende selected_api_key_id auf alle Agents verteilt - Backend: GetAgentApiKeyRecord(userId, agentId) in Chat, Telegram, Cronjobs - Endpoints: select/selected mit ?agentId Query-Parameter - Frontend: currentAgentId aus Session, alle Key-Calls agent-aware - DeleteApiKey bereinigt agent_api_keys statt users.selected_api_key_id
This commit is contained in:
1 parent
b04b1a2cf9
commit
1effc6d00f
10 files changed
+128
-43
No files matched your search
@@ -49,7 +49,7 @@ async function _initChatUsageBadge() {
|
||||
if (!container) return;
|
||||
|
||||
try {
|
||||
var selectedKey = await apiGetSelectedKey();
|
||||
var selectedKey = await apiGetSelectedKey(getCurrentAgentId());
|
||||
if (!selectedKey || !selectedKey.selected) {
|
||||
container.innerHTML = '';
|
||||
var noKeyBtn = document.createElement('button');
|
||||
@@ -85,7 +85,7 @@ async function _refreshChatUsageBadge() {
|
||||
var container = document.getElementById('chatUsageBadge');
|
||||
if (!container || !_chatUsageKeyId) return;
|
||||
try {
|
||||
var selectedKey = await apiGetSelectedKey();
|
||||
var selectedKey = await apiGetSelectedKey(getCurrentAgentId());
|
||||
if (selectedKey) _renderChatUsageBadge(container, selectedKey);
|
||||
} catch(e) { /* ignore */ }
|
||||
}
|
||||
@@ -119,7 +119,7 @@ function _renderChatUsageBadge(container, key) {
|
||||
checkBtn.querySelector('i').className = 'fa fa-spinner fa-spin';
|
||||
try {
|
||||
await apiCheckApiKey(_chatUsageKeyId);
|
||||
var selectedKey = await apiGetSelectedKey();
|
||||
var selectedKey = await apiGetSelectedKey(getCurrentAgentId());
|
||||
if (selectedKey) _renderChatUsageBadge(container, selectedKey);
|
||||
} catch(e) {
|
||||
console.error('Key check failed:', e);
|
||||
@@ -136,7 +136,7 @@ async function _showKeySwitchModal() {
|
||||
try { keys = await apiGetAvailableKeys(); } catch(e) { return; }
|
||||
|
||||
var selectedKey = null;
|
||||
try { selectedKey = await apiGetSelectedKey(); } catch(e) { /* ignore */ }
|
||||
try { selectedKey = await apiGetSelectedKey(getCurrentAgentId()); } catch(e) { /* ignore */ }
|
||||
var selectedKeyId = selectedKey ? selectedKey.keyId : null;
|
||||
|
||||
var { body, close } = _createModal('API Key wechseln', { modal: 'key-switch-modal' });
|
||||
@@ -187,7 +187,7 @@ async function _showKeySwitchModal() {
|
||||
row.addEventListener('click', async function() {
|
||||
row.classList.add('loading-state');
|
||||
try {
|
||||
await apiSelectApiKey(key.keyId);
|
||||
await apiSelectApiKey(key.keyId, getCurrentAgentId());
|
||||
close();
|
||||
await _initChatUsageBadge();
|
||||
} catch(e) {
|
||||
@@ -352,6 +352,8 @@ registerPage('chat', {
|
||||
return;
|
||||
}
|
||||
|
||||
currentAgentId = session.agentId;
|
||||
|
||||
const titleEl = document.getElementById('sessionTitle');
|
||||
if (titleEl) {
|
||||
titleEl.textContent = session.name || 'Unbenannt';
|
||||
@@ -605,6 +607,7 @@ registerPage('chat', {
|
||||
_chatAbandoned = true;
|
||||
stopTypingIndicator();
|
||||
setCurrentAgentName(null);
|
||||
currentAgentId = null;
|
||||
closeEmojiPicker();
|
||||
// Usage Badge cleanup
|
||||
if (_chatUsageScrollHandler) {
|
||||
|
||||
Reference in new issue
Block a user