Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(ai): expose Prompture providers and saved connections

Juan Denis569b052659db
diff --git a/ROADMAP.md b/ROADMAP.md
index 582a93f2..61b84fce 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -610,6 +610,19 @@ Spin up and manage cloud servers directly from the panel.
Current focus areas on the `dev` branch. Core work centers on the deploy experience and
platform infrastructure; new capability areas ship as Marketplace extensions.
+## AI Assistant: Prompture Provider Connections (implemented)
+
+Community request: D3M4L, September 1, 2026 — connect the assistant to OmniRoute.
+
+- [x] Discover native chat providers from Prompture metadata instead of an eight-entry dropdown, deduplicate aliases, and label missing optional dependencies.
+- [x] Provide provider-specific fields, compatible-endpoint presets, and named encrypted connections with a panel default.
+- [x] Support OmniRoute and other compatible gateways with exact model IDs, including slashes and routing aliases, plus discovery and manual entry.
+- [x] Select a connection/model for new chats; retain it on resume and allow credential rotation without rerouting old chats.
+- [x] Test compatible endpoints with a real bounded chat request; verify native model discovery and surface failures rather than treating driver construction as success.
+- [x] Migrate existing settings and matching conversations, preserve write confirmations and RBAC, and test secret isolation, streaming, tool protocol, and fresh/resumed conversations.
+
+See [AI provider connections](docs/AI_PROVIDERS.md) for setup and compatibility details. ServerKit uses Prompture's existing drivers; compatible gateways use its OpenAI driver because the generic driver in 1.10 lacks native streaming and tools. Automatic cross-connection fallback remains a separate feature. OmniRoute-compatible protocol behavior is covered by SDK transport tests; a live OmniRoute instance is still needed for deployment-specific verification.
+
## Deploy Console & Live Run Logs
The publish pipeline is becoming ServerKit's signature experience: deploy anything, watch it
diff --git a/backend/app/api/ai.py b/backend/app/api/ai.py
index a15f51e0..7b730ec0 100644
--- a/backend/app/api/ai.py
+++ b/backend/app/api/ai.py
@@ -35,6 +35,7 @@ from app import db
from app.middleware.rbac import admin_required, get_current_user
from app.models.ai import AiConversation, AiMessage, AiPendingAction
from app.services import ai_service
+from app.services import ai_connections
from app.services.ai_attachment_registry import (
normalize_references,
resolve_attachments,
@@ -104,14 +105,22 @@ def _owned_conversation(conversation_id: str, user):
return row
-def _load_or_create(conversation_id, user, mode):
+def _load_or_create(conversation_id, user, mode, connection_id=None, model=None):
if conversation_id:
row = _owned_conversation(conversation_id, user)
return row # may be None -> caller 404s
+ connection = None
+ if connection_id is not None and (not isinstance(connection_id, str) or len(connection_id) > 64):
+ raise ValidationError('Invalid connection ID')
+ if connection_id or ai_connections.default_id():
+ connection = ai_connections.get_connection(connection_id)
+ if model is not None and (not isinstance(model, str) or not model.strip() or len(model) > 256):
+ raise ValidationError('Invalid model ID')
row = AiConversation(
user_id=user.id,
mode=mode or AiConversation.MODE_ASSISTANT,
- model_name=ai_service.current_model_name(),
+ model_name=ai_connections.model_name(connection, model) if connection else ai_service.current_model_name(),
+ connection_id=connection.id if connection else None,
)
db.session.add(row)
db.session.commit()
@@ -159,6 +168,9 @@ def get_settings():
'injection_detection': bool(SettingsService.get('ai_injection_detection', True)),
# Never return the key itself — only whether one is configured.
'api_key_set': bool(SettingsService.get('ai_api_key_encrypted', '')),
+ 'connections': [ai_connections.public_connection(r, details=True)
+ for r in ai_connections.AiProviderConnection.query.order_by(ai_connections.AiProviderConnection.name).all()],
+ 'default_connection_id': ai_connections.default_id(),
})
@@ -214,7 +226,7 @@ def test_settings():
endpoint = data.get('endpoint')
# Use the posted key if present, else the stored (decrypted) one.
api_key = data.get('api_key')
- if not api_key:
+ if api_key is None and provider == SettingsService.get('ai_provider', '') and endpoint == SettingsService.get('ai_endpoint', ''):
api_key = ai_service._decrypted_key()
if not provider or not model:
return jsonify({'ok': False, 'error': 'provider and model are required'}), 400
@@ -227,6 +239,70 @@ def providers():
return jsonify({'providers': ai_service.list_providers()})
+@ai_bp.route('/connections', methods=['GET'])
+@jwt_required()
+def connections():
+ # The chat selector needs names/models only, never configuration or keys.
+ rows = ai_connections.AiProviderConnection.query.order_by(ai_connections.AiProviderConnection.name).all()
+ return jsonify({'connections': [ai_connections.public_connection(r) for r in rows],
+ 'default_connection_id': ai_connections.default_id()})
+
+
+@ai_bp.route('/connections', methods=['POST'])
+@admin_required
+def add_connection():
+ try:
+ row = ai_connections.save(request.get_json(silent=True))
+ return jsonify(ai_connections.public_connection(row, details=True)), 201
+ except ValueError as exc:
+ return jsonify({'error': str(exc)}), 400
+
+
+@ai_bp.route('/connections/<connection_id>', methods=['PUT'])
+@admin_required
+def update_connection(connection_id):
+ row = db.session.get(ai_connections.AiProviderConnection, connection_id)
+ if row is None:
+ return jsonify({'error': 'Connection not found'}), 404
+ try:
+ row = ai_connections.save(request.get_json(silent=True), row)
+ return jsonify(ai_connections.public_connection(row, details=True))
+ except ValueError as exc:
+ return jsonify({'error': str(exc)}), 400
+
+
+@ai_bp.route('/connections/<connection_id>', methods=['DELETE'])
+@admin_required
+def delete_connection(connection_id):
+ row = db.session.get(ai_connections.AiProviderConnection, connection_id)
+ if row is None:
+ return jsonify({'error': 'Connection not found'}), 404
+ if row.conversations or ai_connections.default_id() == row.id:
+ return jsonify({'error': 'Choose another default and delete conversations using this connection before removing it.'}), 409
+ db.session.delete(row)
+ db.session.commit()
+ return jsonify({'ok': True})
+
+
+@ai_bp.route('/connections/probe', methods=['POST'])
+@admin_required
+def probe_connection():
+ data = request.get_json(silent=True)
+ if not isinstance(data, dict):
+ return jsonify({'error': 'Connection must be an object.'}), 400
+ existing = None
+ if data.get('id'):
+ if not isinstance(data['id'], str) or len(data['id']) > 64:
+ return jsonify({'error': 'Invalid connection ID'}), 400
+ existing = db.session.get(ai_connections.AiProviderConnection, data['id'])
+ if existing is None:
+ return jsonify({'error': 'Connection not found'}), 404
+ try:
+ return jsonify(ai_connections.probe(data, existing, test=data.get('test') is True))
+ except ValueError as exc:
+ return jsonify({'error': str(exc)}), 400
+
+
@ai_bp.route('/models', methods=['GET'])
@admin_required
def models():
@@ -271,9 +347,11 @@ def create_conversation():
user = get_current_user()
data = request.get_json(silent=True) or {}
mode = data.get('mode') or AiConversation.MODE_ASSISTANT
- row = AiConversation(user_id=user.id, mode=mode, title=data.get('title'),
- model_name=ai_service.current_model_name())
- db.session.add(row)
+ try:
+ row = _load_or_create(None, user, mode, data.get('connection_id'), data.get('model'))
+ except ValueError as exc:
+ return jsonify({'error': str(exc)}), 400
+ row.title = data.get('title')
db.session.commit()
return jsonify(row.to_dict()), 201
@@ -342,7 +420,10 @@ def chat():
# global handler renders the 400 with a code and request_id.
attachment_refs = _attachment_references(data)
- row = _load_or_create(data.get('conversation_id'), user, mode)
+ try:
+ row = _load_or_create(data.get('conversation_id'), user, mode, data.get('connection_id'), data.get('model'))
+ except ValueError as exc:
+ return jsonify({'error': str(exc)}), 400
if row is None:
return jsonify({'error': 'Conversation not found'}), 404
@@ -409,7 +490,10 @@ def chat_stream():
# global handler renders the 400 with a code and request_id.
attachment_refs = _attachment_references(data)
- row = _load_or_create(data.get('conversation_id'), user, mode)
+ try:
+ row = _load_or_create(data.get('conversation_id'), user, mode, data.get('connection_id'), data.get('model'))
+ except ValueError as exc:
+ return jsonify({'error': str(exc)}), 400
if row is None:
return jsonify({'error': 'Conversation not found'}), 404
diff --git a/backend/app/models/ai.py b/backend/app/models/ai.py
index fd24fca9..cfc7d957 100644
--- a/backend/app/models/ai.py
+++ b/backend/app/models/ai.py
@@ -39,7 +39,8 @@ class AiConversation(JsonColumnMixin, TimestampMixin, db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True, nullable=False)
title = db.Column(db.String(256))
mode = db.Column(db.String(16), default=MODE_ASSISTANT)
- model_name = db.Column(db.String(128)) # 'provider/model' snapshot at creation
+ model_name = db.Column(db.String(384)) # 'provider/model' snapshot at creation
+ connection_id = db.Column(db.String(64), db.ForeignKey('ai_provider_connections.id'), index=True)
export_json = db.Column(db.Text) # Prompture conv.export(strip_images=True)
last_page = db.Column(db.String(256)) # last route the assistant saw (for resume context)
@@ -70,6 +71,7 @@ class AiConversation(JsonColumnMixin, TimestampMixin, db.Model):
'title': self.title or 'New chat',
'mode': self.mode,
'model_name': self.model_name,
+ 'connection_id': self.connection_id,
'last_page': self.last_page,
'message_count': self.messages.count(),
'created_at': self.created_at.isoformat() if self.created_at else None,
@@ -80,6 +82,28 @@ class AiConversation(JsonColumnMixin, TimestampMixin, db.Model):
return data
+class AiProviderConnection(TimestampMixin, db.Model):
+ """Admin-managed AI connection. All driver configuration is encrypted."""
+ __tablename__ = 'ai_provider_connections'
+
+ id = db.Column(db.String(64), primary_key=True, default=_new_id)
+ name = db.Column(db.String(100), nullable=False)
+ provider = db.Column(db.String(64), nullable=False)
+ model = db.Column(db.String(256), nullable=False)
+ config_encrypted = db.Column(db.Text, nullable=False)
+ conversations = db.relationship('AiConversation', backref='connection')
+
+ @property
+ def config(self):
+ from app.utils.crypto import decrypt_secret
+ return json.loads(decrypt_secret(self.config_encrypted))
+
+ @config.setter
+ def config(self, value):
+ from app.utils.crypto import encrypt_secret
+ self.config_encrypted = encrypt_secret(json.dumps(value))
+
+
class AiMessage(JsonColumnMixin, db.Model):
"""One persisted turn in a conversation (user, assistant, or tool)."""
__tablename__ = 'ai_messages'
diff --git a/backend/app/services/ai_connections.py b/backend/app/services/ai_connections.py
new file mode 100644
index 00000000..3883ea8f
--- /dev/null
+++ b/backend/app/services/ai_connections.py
@@ -0,0 +1,315 @@
+"""Prompture-backed chat provider catalog and isolated saved connections.
+
+Prompture imports stay inside functions: the panel does not load the SDK until
+someone uses the assistant. Only installed chat drivers appear in the catalog.
+"""
+import importlib.util
+import json
+import os
+from urllib.parse import urlsplit
+
+from app import db
+from app.models.ai import AiProviderConnection
+from app.models.system_settings import SystemSettings
+
+
+# UI metadata complements Prompture's constructor maps (which are not a form
+# schema). Never copy secret defaults from Prompture's environment settings.
+_DEPENDENCIES = {
+ 'openai_compatible': ['openai'], 'lmstudio': ['openai'],
+ 'openai': ['openai'], 'claude': ['anthropic'], 'google': ['google.genai'],
+ 'azure': ['openai'], 'google_vertexai': ['google.genai', 'anthropic'],
+ 'bedrock': ['boto3'], 'groq': ['groq'], 'cohere': ['cohere'],
+ 'mistral': ['mistralai'], 'airllm': ['airllm'],
+}
+_OPTIONAL_KEYS = {'openai_compatible', 'lmstudio'}
+
+
+def is_secret(name):
+ return any(part in name for part in ('key', 'token', 'secret', 'password'))
+
+
+def _installed(module):
+ try:
+ return importlib.util.find_spec(module) is not None
+ except (ImportError, ValueError):
+ return False
+
+
+def catalog():
+ from prompture.drivers.provider_descriptors import PROVIDER_DESCRIPTORS
+ from prompture.drivers.openai_compatible_driver import OPENAI_COMPATIBLE_PROFILES
+ from prompture.infra.settings import Settings
+
+ result = []
+ for descriptor in PROVIDER_DESCRIPTORS:
+ if descriptor.alias_for or not descriptor.llm_sync:
+ continue
+ provider = descriptor.name
+ mapping = dict(descriptor.llm_sync.kwarg_map)
+ if provider == 'openai_compatible':
+ mapping = {'api_key': '', 'endpoint': ''}
+ if provider == 'openai':
+ mapping['base_url'] = ''
+ fields = []
+ for name, attr in mapping.items():
+ secret = is_secret(name)
+ definition = Settings.model_fields.get(attr)
+ default = definition.default if definition and not secret else ''
+ default = default if isinstance(default, str) else ''
+ if name == 'base_url':
+ default = 'https://api.openai.com/v1'
+ required = secret and provider not in _OPTIONAL_KEYS
+ if 'endpoint' in name or name == 'base_url':
+ required = True
+ if provider in ('azure', 'google_vertexai'):
+ required = False # model-dependent alternatives validated below
+ fields.append({
+ 'name': name, 'label': name.replace('_', ' ').capitalize(),
+ 'secret': secret, 'required': required, 'default': default,
+ 'type': 'url' if 'endpoint' in name or name == 'base_url' else 'text',
+ })
+ missing = [m for m in _DEPENDENCIES.get(provider, []) if not _installed(m)]
+ result.append({
+ 'id': provider, 'label': descriptor.display_name or provider,
+ 'fields': fields, 'available': not missing,
+ 'unavailable_reason': f"Missing Python dependencies: {', '.join(missing)}" if missing else '',
+ 'needs_key': any(f['secret'] and f['required'] for f in fields),
+ 'supports_endpoint': any(f['type'] == 'url' for f in fields),
+ 'presets': ([{'id': k, 'endpoint': v['endpoint']} for k, v in OPENAI_COMPATIBLE_PROFILES.items()]
+ if provider == 'openai_compatible' else []),
+ })
+ hub = next((p for p in result if p['id'] == 'openai_compatible'), None)
+ if hub:
+ result.append({**hub, 'id': 'prompture-hub', 'label': 'Prompture Hub (self-hosted)', 'presets': []})
+ return sorted(result, key=lambda p: p['label'].lower())
+
+
+def provider_meta(provider):
+ meta = next((p for p in catalog() if p['id'] == provider), None)
+ if meta is None:
+ raise ValueError('Unknown chat provider. Choose an installed Prompture provider.')
+ return meta
+
+
+def public_connection(row, *, details=False):
+ data = {'id': row.id, 'name': row.name, 'provider': row.provider, 'model': row.model}
+ if details:
+ config = row.config
+ data['config'] = {k: v for k, v in config.items() if not is_secret(k)}
+ data['secrets_set'] = [k for k, v in config.items() if is_secret(k) and v]
+ return data
+
+
+def default_id():
+ return SystemSettings.get('ai_default_connection_id', '') or ''
+
+
+def get_connection(connection_id=None):
+ selected = connection_id if connection_id is not None else default_id()
+ row = db.session.get(AiProviderConnection, selected) if selected else None
+ if row is None:
+ raise ValueError('Select a saved AI connection in Settings → AI Assistant.')
+ return row
+
+
+def model_name(row, model=None):
+ provider = 'openai_compatible' if row.provider in ('prompture-hub', 'lmstudio') else row.provider
+ return f'{provider}/{model or row.model}'
+
+
+def _text(value, label, maximum=2048):
+ if not isinstance(value, str) or len(value) > maximum:
+ raise ValueError(f'{label} must be a string of at most {maximum} characters.')
+ return value.strip()
+
+
+def validate_url(value):
+ try:
+ url = urlsplit(value)
+ port = url.port
+ except ValueError:
+ raise ValueError('Invalid endpoint URL.') from None
+ if (url.scheme not in ('http', 'https') or not url.hostname or url.username
+ or url.password or url.query or url.fragment or any(c.isspace() for c in value)):
+ raise ValueError('Endpoint must be an HTTP(S) URL without credentials, query, or fragment.')
+ if port is not None and port < 1:
+ raise ValueError('Invalid endpoint port.')
+ return value.rstrip('/')
+
+
+def prepare(data, existing=None):
+ """Validate an admin draft; never reuse keys across provider/endpoint changes."""
+ if not isinstance(data, dict):
+ raise ValueError('Connection must be an object.')
+ provider = _text(data.get('provider', ''), 'Provider', 64)
+ meta = provider_meta(provider)
+ if not meta['available']:
+ raise ValueError(meta['unavailable_reason'])
+ name = _text(data.get('name', 'Connection test'), 'Name', 100)
+ model = _text(data.get('model', ''), 'Model', 256)
+ if not name or not model:
+ raise ValueError('Connection name and model are required.')
+ posted = data.get('config', {})
+ if not isinstance(posted, dict):
+ raise ValueError('Configuration must be an object.')
+ fields = {f['name']: f for f in meta['fields']}
+ if set(posted) - set(fields):
+ raise ValueError('Unsupported provider configuration field.')
+ previous = existing.config if existing and existing.provider == provider else {}
+ config = {k: v for k, v in previous.items() if k in fields}
+ for key, field in fields.items():
+ if key in posted:
+ config[key] = _text(posted[key], field['label'], 16384 if field['secret'] else 2048)
+ elif key not in config:
+ config[key] = field['default']
+ if field['type'] == 'url' and config[key]:
+ config[key] = validate_url(config[key])
+ endpoint_changed = any(f['type'] == 'url' and config.get(k) != (previous.get(k) or f['default']).rstrip('/')
+ for k, f in fields.items())
+ if endpoint_changed:
+ for key, field in fields.items():
+ if field['secret'] and key not in posted:
+ config[key] = ''
+ for key, field in fields.items():
+ if field['required'] and not config.get(key):
+ raise ValueError(f"{field['label']} is required. Re-enter credentials when changing an endpoint.")
+ if provider == 'azure':
+ prefix = 'claude_' if model.startswith('claude') else ('mistral_' if model.startswith(('mistral', 'mixtral')) else '')
+ if not config.get(prefix + 'api_key') or not config.get(prefix + 'endpoint'):
+ raise ValueError(f'Azure requires {prefix}api_key and {prefix}endpoint for this model.')
+ if provider == 'google_vertexai':
+ if model.startswith('claude'):
+ if not all(config.get(k) for k in ('project_id', 'location', 'access_token')):
+ raise ValueError('Vertex Claude requires project ID, location and access token.')
+ elif not config.get('api_key'):
+ raise ValueError('Vertex Gemini requires an explicit API key; ambient cloud credentials are not used.')
+ if provider == 'bedrock' and not config.get('aws_region'):
+ raise ValueError('AWS region is required.')
+ return {'name': name, 'provider': provider, 'model': model, 'config': config}
+
+
+def save(data, existing=None):
+ draft = prepare(data, existing)
+ if 'make_default' in data and not isinstance(data['make_default'], bool):
+ raise ValueError('make_default must be a boolean.')
+ row = existing or AiProviderConnection()
+ # A connection used by a chat keeps its provider/endpoint identity. Credentials
+ # may be rotated; changing the destination requires creating a new connection.
+ if existing and existing.conversations:
+ before = existing.config
+ urls = [f for f in provider_meta(draft['provider'])['fields'] if f['type'] == 'url']
+ if existing.provider != draft['provider'] or any(
+ (before.get(f['name']) or f['default']).rstrip('/') != draft['config'].get(f['name'], '') for f in urls):
+ raise ValueError('This connection has conversations. Add a new connection to change its provider or endpoint.')
+ for key in ('name', 'provider', 'model', 'config'):
+ setattr(row, key, draft[key])
+ db.session.add(row)
+ db.session.flush()
+ if data.get('make_default') or not default_id():
+ SystemSettings.set('ai_default_connection_id', row.id)
+ db.session.commit()
+ return row
+
+
+def build_driver(row, model=None):
+ from prompture.drivers import get_driver_for_model
+ from prompture.drivers.provider_descriptors import PROVIDER_DESCRIPTOR_MAP
+
+ # Revalidate saved credentials and required fields; a missing value must not
+ # silently resolve through Prompture's process-global environment.
+ draft = prepare({'name': row.name, 'provider': row.provider,
+ 'model': model or row.model, 'config': row.config})
+ provider = row.provider
+ config = draft['config']
+ if provider == 'claude' and os.environ.get('ANTHROPIC_BASE_URL', '').rstrip('/') not in ('', 'https://api.anthropic.com'):
+ raise ValueError('The installed native Anthropic driver inherits ANTHROPIC_BASE_URL. Remove that process override or configure an explicit compatible gateway connection.')
+ if provider in ('openai_compatible', 'prompture-hub', 'lmstudio'):
+ endpoint = config['endpoint'].removesuffix('/chat/completions')
+ # Prompture's generic driver has no native tools/streaming in 1.10.
+ # Its OpenAI driver accepts the same base URL and supports both, without
+ # CachiBot's process-global short-model alias map changing gateway IDs.
+ driver = get_driver_for_model(
+ f'openai/{model or row.model}', base_url=endpoint,
+ api_key=config.get('api_key') or 'serverkit-no-auth',
+ )
+ if not config.get('api_key'):
+ # SDK versions differ in how they validate omitted auth headers.
+ # Strip the placeholder in this client's request hook, after SDK
+ # validation and before transport, including streaming requests.
+ driver.client._client.event_hooks['request'].append(
+ lambda request: request.headers.pop('Authorization', None))
+ driver.api_key = None
+ return driver
+ # Blank overrides suppress factory-level global settings resolution. Required
+ # credentials and endpoints above prevent constructor-level fallback as well.
+ mapping = PROVIDER_DESCRIPTOR_MAP[provider].llm_sync.kwarg_map
+ overrides = {key: config.get(key, '') for key in mapping}
+ if provider == 'openai':
+ overrides['base_url'] = config['base_url']
+ if provider == 'azure':
+ for prefix in ('claude_', 'mistral_'):
+ overrides[prefix + 'api_key'] = config.get(prefix + 'api_key') or config.get('api_key') or 'serverkit-unconfigured'
+ overrides[prefix + 'endpoint'] = config.get(prefix + 'endpoint') or config.get('endpoint') or 'http://127.0.0.1:1'
+ driver = get_driver_for_model(model_name(row, model), **overrides)
+ if provider == 'azure':
+ # Bypass Prompture's global per-model resolver using this instance only.
+ prefix = 'claude_' if draft['model'].startswith('claude') else ('mistral_' if draft['model'].startswith(('mistral', 'mixtral')) else '')
+ explicit = {'api_key': config[prefix + 'api_key'], 'endpoint': config[prefix + 'endpoint'],
+ 'deployment_id': config.get('deployment_id') or draft['model'], 'api_version': '2024-02-15-preview'}
+ driver._resolve_model_config = lambda model, options: dict(explicit)
+ return driver
+
+
+def probe(data, existing=None, *, test=False):
+ """Bounded network discovery/test with sanitized failures (no SDK tracebacks)."""
+ import requests
+
+ draft = prepare({**data, 'name': data.get('name') or 'Connection test',
+ 'model': data.get('model') or ('' if test else '_discovery')}, existing)
+ provider, config = draft['provider'], draft['config']
+ try:
+ if provider in ('openai_compatible', 'prompture-hub', 'lmstudio', 'openai'):
+ base = (config.get('base_url') or config['endpoint']).removesuffix('/chat/completions')
+ headers = {'Authorization': f"Bearer {config['api_key']}"} if config.get('api_key') else {}
+ if test:
+ response = requests.post(base + '/chat/completions', headers=headers,
+ json={'model': draft['model'], 'messages': [{'role': 'user', 'content': 'Reply OK.'}],
+ 'max_tokens': 8, 'stream': False},
+ timeout=(5, 15), allow_redirects=False)
+ else:
+ response = requests.get(base + '/models', headers=headers, timeout=(5, 10), allow_redirects=False)
+ response.raise_for_status()
+ if not 200 <= response.status_code < 300:
+ raise ValueError('Endpoint redirected. Configure its final URL directly.')
+ body = response.json()
+ if test:
+ if not isinstance(body, dict) or not body.get('choices'):
+ raise ValueError('Endpoint did not return a chat completion.')
+ return {'ok': True, 'message': 'Chat completion succeeded.'}
+ models = [m['id'] for m in body.get('data', []) if isinstance(m, dict) and isinstance(m.get('id'), str)]
+ else:
+ from prompture.drivers import PROVIDER_DRIVER_MAP
+ cls = PROVIDER_DRIVER_MAP[provider][0]
+ lister = getattr(cls, 'list_models', None)
+ try:
+ models = lister(**config, timeout=10) if callable(lister) else None
+ except Exception:
+ raise ValueError('Provider model discovery failed. Check credentials and configuration, or enter a model manually.') from None
+ if models is None:
+ raise ValueError('Model discovery could not be verified. Check credentials and endpoint, or enter a model manually.')
+ models = sorted({m for m in models if isinstance(m, str)})
+ if test:
+ if draft['model'] not in models:
+ raise ValueError('Model was not returned by this provider. Check the model ID or verify it in chat.')
+ return {'ok': True, 'message': 'Model discovery succeeded. Streaming and tool support depend on the selected model.'}
+ return {'models': models, 'source': 'live'}
+ except requests.HTTPError as exc:
+ code = exc.response.status_code if exc.response is not None else 'error'
+ raise ValueError(f'Provider returned HTTP {code}. Check credentials, endpoint and model.') from None
+ except requests.RequestException:
+ raise ValueError('Could not reach the provider within the timeout. Check its address and TLS configuration.') from None
+ except (ImportError, ModuleNotFoundError):
+ raise ValueError('A required provider dependency is not installed.') from None
+ except (TypeError, KeyError, json.JSONDecodeError):
+ raise ValueError('Provider returned an unsupported response; enter a model manually.') from None
diff --git a/backend/app/services/ai_service.py b/backend/app/services/ai_service.py
index b5881752..3bbbb5bf 100644
--- a/backend/app/services/ai_service.py
+++ b/backend/app/services/ai_service.py
@@ -188,6 +188,15 @@ def is_enabled() -> bool:
def is_configured() -> bool:
"""A provider + model are set and any required key is present."""
+ from app.services import ai_connections
+ if ai_connections.default_id():
+ try:
+ row = ai_connections.get_connection()
+ ai_connections.prepare({'name': row.name, 'provider': row.provider,
+ 'model': row.model, 'config': row.config})
+ return True
+ except ValueError:
+ return False
provider = (_setting("ai_provider", "") or "").strip()
model = (_setting("ai_model", "") or "").strip()
if not provider or not model:
@@ -200,6 +209,9 @@ def is_configured() -> bool:
def current_model_name() -> str:
+ from app.services import ai_connections
+ if ai_connections.default_id():
+ return ai_connections.model_name(ai_connections.get_connection())
provider = (_setting("ai_provider", "") or "").strip()
model = (_setting("ai_model", "") or "").strip()
return f"{_driver_provider(provider)}/{model}" if provider and model else ""
@@ -240,45 +252,35 @@ def build_provider_env(*, provider: Optional[str] = None, api_key: Optional[str]
def list_providers() -> list[dict]:
"""Provider catalog for the settings dropdown (models = fallback suggestions)."""
- return [
- {"id": p["id"], "label": p["label"], "needs_key": p["needs_key"],
- "supports_endpoint": p["supports_endpoint"]}
- for p in CURATED_PROVIDERS
- ]
+ from app.services.ai_connections import catalog
+ return catalog()
def list_models(provider: str) -> dict:
"""Best-effort live model list for *provider*, falling back to curated suggestions."""
+ from app.services import ai_connections
provider = (provider or "").strip()
fallback = _PROVIDER_BY_ID.get(provider, {}).get("models", [])
try:
- from prompture.drivers import get_driver_for_model
- driver = get_driver_for_model(f"{_driver_provider(provider)}/", env=build_provider_env(provider=provider))
- lister = getattr(driver, "list_models", None)
- if callable(lister):
- models = lister()
- if models:
- return {"models": list(models), "source": "live"}
- except Exception:
- logger.debug("list_models(%s): live lookup failed, using fallback", provider, exc_info=True)
+ row = ai_connections.get_connection()
+ if row.provider == provider:
+ return ai_connections.probe({'name': row.name, 'provider': row.provider,
+ 'model': row.model, 'config': row.config})
+ except ValueError:
+ pass # Never borrow a different provider's credentials for discovery.
return {"models": fallback, "source": "fallback"}
def test_settings(provider: str, model: str, api_key: Optional[str] = None,
endpoint: Optional[str] = None) -> dict:
- """Validate a provider/model/key by constructing the driver and probing models."""
+ """Legacy settings probe; use the same real request as saved connections."""
+ from app.services.ai_connections import probe
try:
- from prompture.drivers import get_driver_for_model
- env = build_provider_env(provider=provider, api_key=api_key, endpoint=endpoint)
- driver = get_driver_for_model(f"{_driver_provider(provider)}/{model}", env=env)
- lister = getattr(driver, "list_models", None)
- if callable(lister):
- try:
- lister()
- except Exception:
- pass # not all providers support listing; driver constructed = good enough
- return {"ok": True}
- except Exception as exc:
+ config = {'api_key': api_key} if api_key else {}
+ if endpoint:
+ config['base_url' if provider == 'openai' else 'endpoint'] = endpoint
+ return probe({'provider': provider, 'model': model, 'config': config}, test=True)
+ except ValueError as exc:
return {"ok": False, "error": str(exc)}
@@ -522,26 +524,53 @@ def build_conversation(row, user, mode: str, page_context: Optional[dict],
attachment_context: Optional[list[dict]] = None) -> Conversation:
"""Create a fresh Conversation or resume from the stored export (re-supplying tools)."""
from prompture import Conversation
+ from app.services import ai_connections
registry = build_tool_registry(user, mode, gate)
system = build_system_prompt(
user, mode, page_context, attachment_context=attachment_context,
)
+ connection_id = getattr(row, 'connection_id', None)
+ if connection_id:
+ connection = ai_connections.get_connection(connection_id)
+ model = (row.model_name or '').split('/', 1)[-1] or connection.model
+ driver = ai_connections.build_driver(connection, model)
+ resolved_model = ai_connections.model_name(connection, model)
+ else:
+ # Compatibility for pre-migration/test conversations. Never attach a
+ # different provider's current credentials to an old conversation.
+ if ai_connections.default_id():
+ raise ValueError('This older conversation has no saved connection. Start a new chat using its original provider.')
+ resolved_model = row.model_name or current_model_name()
+ if resolved_model.split('/', 1)[0] != current_model_name().split('/', 1)[0]:
+ raise ValueError('This older conversation needs its original provider configuration.')
+ from prompture.drivers import get_driver_for_model
+ driver = get_driver_for_model(resolved_model, env=build_provider_env())
+
+ # Prompture 1.10 from_export does not accept a driver/env. Inject the already
+ # configured instance through its constructor hook, so resume never builds
+ # an ambient/global driver, even temporarily. History/usage restoration stays
+ # owned by Prompture. Reapply current policy instead of trusting export options.
+ class ConfiguredConversation(Conversation):
+ def __init__(self, **kwargs):
+ kwargs.update(driver=driver, model_name=resolved_model,
+ max_tool_rounds=(6 if mode == 'assistant' else 0),
+ max_tool_result_length=4000, max_cost=_max_cost(),
+ budget_policy=None, fallback_models=None, options={})
+ super().__init__(**kwargs)
+
export = row.export
if export:
- conv = Conversation.from_export(_maybe_redact_result(export), tools=registry)
+ conv = ConfiguredConversation.from_export(_maybe_redact_result(export), tools=registry)
conv.system_prompt = system # refresh page context each turn
return conv
- return Conversation(
- model_name=row.model_name or current_model_name(),
+ return ConfiguredConversation(
+ model_name=resolved_model,
system_prompt=system,
tools=registry,
- env=build_provider_env(),
max_tool_rounds=(6 if mode == "assistant" else 0),
max_tool_result_length=4000,
max_cost=_max_cost(),
- budget_policy="degrade" if _fallback_models() else None,
- fallback_models=_fallback_models() or None,
simulated_tools="auto",
conversation_id=row.id,
)
@@ -582,12 +611,15 @@ def derive_title(message: str) -> str:
# ===========================================================================
def _oneshot_conversation(user, mode: str, page_context: Optional[dict]) -> Conversation:
from prompture import Conversation
+ from app.services import ai_connections
ensure_initialized()
registry = build_tool_registry(user, mode, gate=None)
system = build_system_prompt(user, mode, page_context)
return Conversation(
model_name=current_model_name(),
+ driver=(ai_connections.build_driver(ai_connections.get_connection())
+ if ai_connections.default_id() else None),
system_prompt=system,
tools=registry,
env=build_provider_env(),
diff --git a/backend/migrations/versions/098_ai_provider_connections.py b/backend/migrations/versions/098_ai_provider_connections.py
new file mode 100644
index 00000000..8fe3c9fc
--- /dev/null
+++ b/backend/migrations/versions/098_ai_provider_connections.py
@@ -0,0 +1,71 @@
+"""Saved Prompture connections and conversation affinity."""
+import json
+
+from alembic import op
+import sqlalchemy as sa
+
+revision = '098_ai_provider_connections'
+down_revision = '097_user_auth_version'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ conn = op.get_bind()
+ inspector = sa.inspect(conn)
+ if 'ai_provider_connections' not in inspector.get_table_names():
+ op.create_table(
+ 'ai_provider_connections',
+ sa.Column('id', sa.String(64), primary_key=True),
+ sa.Column('name', sa.String(100), nullable=False),
+ sa.Column('provider', sa.String(64), nullable=False),
+ sa.Column('model', sa.String(256), nullable=False),
+ sa.Column('config_encrypted', sa.Text, nullable=False),
+ sa.Column('created_at', sa.DateTime),
+ sa.Column('updated_at', sa.DateTime),
+ )
+ columns = {c['name'] for c in inspector.get_columns('ai_conversations')}
+ if 'connection_id' not in columns:
+ with op.batch_alter_table('ai_conversations') as batch:
+ batch.add_column(sa.Column('connection_id', sa.String(64)))
+ batch.create_foreign_key('fk_ai_conversation_connection', 'ai_provider_connections', ['connection_id'], ['id'])
+ batch.create_index('ix_ai_conversations_connection_id', ['connection_id'])
+ with op.batch_alter_table('ai_conversations') as batch:
+ batch.alter_column('model_name', existing_type=sa.String(128), type_=sa.String(384))
+
+ settings = dict(conn.execute(sa.text(
+ "SELECT key, value FROM system_settings WHERE key LIKE 'ai_%'"
+ )).fetchall())
+ provider, model = settings.get('ai_provider'), settings.get('ai_model')
+ if not provider or not model:
+ return
+ if conn.execute(sa.text("SELECT id FROM ai_provider_connections WHERE id = 'legacy'")).first():
+ return
+ from app.utils.crypto import decrypt_secret, encrypt_secret
+ config = {}
+ if settings.get('ai_api_key_encrypted'):
+ config['api_key'] = decrypt_secret(settings['ai_api_key_encrypted'])
+ if settings.get('ai_endpoint'):
+ config['base_url' if provider == 'openai' else 'endpoint'] = settings['ai_endpoint']
+ conn.execute(sa.text(
+ 'INSERT INTO ai_provider_connections (id, name, provider, model, config_encrypted, created_at, updated_at) '
+ "VALUES ('legacy', 'Existing connection', :provider, :model, :config, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
+ ), {'provider': provider, 'model': model, 'config': encrypt_secret(json.dumps(config))})
+ conn.execute(sa.text(
+ "INSERT INTO system_settings (key, value, value_type) SELECT 'ai_default_connection_id', 'legacy', 'string' "
+ "WHERE NOT EXISTS (SELECT 1 FROM system_settings WHERE key = 'ai_default_connection_id')"
+ ))
+ # Only attach conversations from this provider. Older chats from a different
+ # provider must be explicitly configured, never routed using the wrong key.
+ driver = 'cachibot' if provider == 'prompture-hub' else provider
+ conn.execute(sa.text(
+ "UPDATE ai_conversations SET connection_id = 'legacy' "
+ "WHERE connection_id IS NULL AND model_name LIKE :prefix"
+ ), {'prefix': driver + '/%'})
+
+
+def downgrade():
+ with op.batch_alter_table('ai_conversations') as batch:
+ batch.drop_column('connection_id')
+ op.drop_table('ai_provider_connections')
+ op.execute("DELETE FROM system_settings WHERE key = 'ai_default_connection_id'")
diff --git a/backend/requirements.txt b/backend/requirements.txt
index 5d58e034..1d518a51 100644
--- a/backend/requirements.txt
+++ b/backend/requirements.txt
@@ -90,7 +90,7 @@ marshmallow==3.26.2
# AI assistant (core primitive — powered by Prompture)
# Multi-provider LLM orchestration: Conversation, ToolRegistry, ask_live streaming,
-# ProviderEnvironment, guardrails. Provider SDKs (openai/anthropic/...) are optional
-# extras installed per the configured provider; the base package is provider-agnostic.
-# Installed from the Prompture repo (pip install -e path/to/prompture) until published.
-prompture>=1.4
+# ProviderEnvironment, guardrails. OpenAI (also compatible gateways) and Anthropic
+# SDKs ship with the panel. Other provider SDKs remain optional. The minor range
+# pins the descriptor/factory APIs and Conversation restoration used by the panel.
+prompture[openai,anthropic]>=1.10.0,<1.11
diff --git a/backend/tests/test_ai_connections.py b/backend/tests/test_ai_connections.py
new file mode 100644
index 00000000..e5978076
--- /dev/null
+++ b/backend/tests/test_ai_connections.py
@@ -0,0 +1,253 @@
+"""Provider discovery, credential boundaries, migration, and real SDK wire format."""
+import importlib.util
+import json
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+
+from app import db
+from app.models.ai import AiConversation, AiProviderConnection
+from app.models.system_settings import SystemSettings
+from app.services import ai_connections as service, ai_service
+
+
+def draft(**overrides):
+ return {'name': 'OmniRoute', 'provider': 'openai_compatible', 'model': 'anthropic/team/model',
+ 'config': {'endpoint': 'http://gateway.local:20128/v1', 'api_key': 'private-test-key'}, **overrides}
+
+
+def test_catalog_uses_prompture_descriptors_and_deduplicates():
+ from prompture.drivers.provider_descriptors import PROVIDER_DESCRIPTORS
+ catalog = service.catalog()
+ names = [p['id'] for p in catalog]
+ assert len(names) == len(set(names))
+ assert {d.name for d in PROVIDER_DESCRIPTORS if d.llm_sync and not d.alias_for} <= set(names)
+ assert {'claude', 'google', 'openai', 'openai_compatible', 'bedrock', 'mistral'} <= set(names)
+ assert service.provider_meta('openai_compatible')['presets']
+
+
+def test_catalog_reports_missing_dependencies(monkeypatch):
+ monkeypatch.setattr(service, '_installed', lambda module: False)
+ assert service.provider_meta('claude')['available'] is False
+ with pytest.raises(ValueError, match='dependencies'):
+ service.prepare(draft(provider='claude', config={'api_key': 'key'}))
+
+
[email protected]('url', ['file:///tmp/a', 'http://user:pass@host/v1', 'https://host/v1?key=x',
+ 'http://host/#fragment', 'http://host:99999', 'http://host/a b'])
+def test_invalid_endpoint(url):
+ with pytest.raises(ValueError):
+ service.prepare(draft(config={'endpoint': url}))
+
+
+def test_profile_storage_and_api_never_return_secrets(app, client, auth_headers):
+ response = client.post('/api/v1/ai/connections', json=draft(), headers=auth_headers)
+ assert response.status_code == 201
+ data = response.get_json()
+ assert data['secrets_set'] == ['api_key']
+ assert 'api_key' not in data['config']
+ with app.app_context():
+ row = db.session.get(AiProviderConnection, data['id'])
+ assert 'private-test-key' not in row.config_encrypted
+ assert row.config['api_key'] == 'private-test-key'
+ assert service.default_id() == row.id
+ for path in ('/api/v1/ai/connections', '/api/v1/ai/settings'):
+ body = client.get(path, headers=auth_headers).get_data(as_text=True)
+ assert 'private-test-key' not in body
+ selector = client.get('/api/v1/ai/connections', headers=auth_headers).get_json()['connections'][0]
+ assert set(selector) == {'id', 'name', 'provider', 'model'}
+
+
+def test_secret_retention_clear_and_endpoint_change(app):
+ with app.app_context():
+ row = service.save(draft())
+ same = service.prepare(draft(config={'endpoint': 'http://gateway.local:20128/v1'}), row)
+ assert same['config']['api_key'] == 'private-test-key'
+ changed = service.prepare(draft(config={'endpoint': 'http://different.local/v1'}), row)
+ assert changed['config']['api_key'] == ''
+ cleared = service.prepare(draft(config={'api_key': ''}), row)
+ assert cleared['config']['api_key'] == ''
+ with pytest.raises(ValueError, match='required'):
+ service.prepare(draft(provider='claude', config={}), row)
+
+
+def test_native_fields_and_global_credentials_are_not_used(monkeypatch):
+ monkeypatch.setenv('OPENAI_API_KEY', 'ambient-secret')
+ monkeypatch.setenv('OPENAI_BASE_URL', 'https://unintended.local/v1')
+ with pytest.raises(ValueError, match='required'):
+ service.prepare(draft(provider='openai', config={}))
+ prepared = service.prepare(draft(provider='openai', config={'api_key': 'explicit'}))
+ row = SimpleNamespace(**prepared)
+ driver = service.build_driver(row)
+ assert driver.api_key == 'explicit'
+ assert str(driver.client.base_url) == 'https://api.openai.com/v1/'
+ driver.client.close()
+
+
+def test_native_anthropic_driver_uses_explicit_credentials(monkeypatch):
+ monkeypatch.setenv('CLAUDE_API_KEY', 'ambient-secret')
+ row = SimpleNamespace(**service.prepare(draft(provider='claude', model='claude-test', config={'api_key': 'explicit-claude'})))
+ driver = service.build_driver(row)
+ assert driver.api_key == 'explicit-claude'
+ assert driver.model == 'claude-test'
+
+
+def test_probe_uses_draft_credentials_preserves_ids_and_rejects_failure(app, monkeypatch):
+ import requests
+ calls = []
+ def get(url, **kwargs):
+ calls.append((url, kwargs))
+ return SimpleNamespace(status_code=200, raise_for_status=lambda: None,
+ json=lambda: {'data': [{'id': 'anthropic/team/model'}, {'id': 'auto'}]})
+ monkeypatch.setattr(requests, 'get', get)
+ with app.app_context():
+ row = service.save(draft())
+ result = service.probe(draft(config={'endpoint': 'http://other.local/v1', 'api_key': 'new-key'}), row)
+ assert result['models'] == ['anthropic/team/model', 'auto']
+ assert calls[0][1]['headers']['Authorization'] == 'Bearer new-key'
+ assert calls[0][1]['timeout'] == (5, 10)
+ assert calls[0][1]['allow_redirects'] is False
+ def fail(*args, **kwargs):
+ raise requests.Timeout('private-test-key')
+ monkeypatch.setattr(requests, 'get', fail)
+ with pytest.raises(ValueError, match='timeout') as exc:
+ service.probe(draft())
+ assert 'private-test-key' not in str(exc.value)
+
+
+def test_connection_test_requires_real_response(monkeypatch):
+ import requests
+ monkeypatch.setattr(requests, 'post', lambda *a, **kw: SimpleNamespace(
+ status_code=200, raise_for_status=lambda: None, json=lambda: {}))
+ with pytest.raises(ValueError, match='chat completion'):
+ service.probe(draft(), test=True)
+
+
+def test_chats_keep_connection_and_model_and_block_destination_changes(app, client, auth_headers):
+ first = client.post('/api/v1/ai/connections', json=draft(), headers=auth_headers).get_json()
+ chat = client.post('/api/v1/ai/conversations', json={'connection_id': first['id'], 'model': 'auto/fast'}, headers=auth_headers)
+ assert chat.status_code == 201
+ second = client.post('/api/v1/ai/connections', json=draft(name='Second', make_default=True), headers=auth_headers).get_json()
+ with app.app_context():
+ row = db.session.get(AiConversation, chat.get_json()['id'])
+ assert row.connection_id == first['id']
+ assert row.model_name == 'openai_compatible/auto/fast'
+ assert service.default_id() == second['id']
+ response = client.put('/api/v1/ai/connections/' + first['id'], json=draft(config={'endpoint': 'http://other/v1'}), headers=auth_headers)
+ assert response.status_code == 400
+ assert client.delete('/api/v1/ai/connections/' + first['id'], headers=auth_headers).status_code == 409
+
+
+def _mock_transport(driver, handler):
+ # Support both SDK transport module names; newer OpenAI SDKs use httpx2.
+ module = importlib.import_module(type(driver.client._client._transport).__module__.split('.')[0])
+ driver.client = driver.client.with_options(http_client=module.Client(
+ transport=module.MockTransport(handler), event_hooks=driver.client._client.event_hooks), max_retries=0)
+ return module
+
+
+def test_compatible_driver_streaming_and_tool_protocol_preserve_model(monkeypatch):
+ from prompture.drivers.cachibot_driver import CachiBotDriver
+ monkeypatch.setattr(CachiBotDriver, '_MODEL_MAP', {'auto': 'wrong/provider'})
+ monkeypatch.setenv('OPENAI_API_KEY', 'ambient')
+ row = SimpleNamespace(**service.prepare(draft(model='auto', config={'endpoint': 'http://gateway.local/v1'})))
+ driver = service.build_driver(row)
+ calls = []
+ def respond(request):
+ payload = json.loads(request.content)
+ calls.append((dict(request.headers), payload))
+ if payload.get('stream'):
+ content = 'data: ' + json.dumps({'id': 'c1', 'choices': [{'index': 0, 'delta': {'content': 'OK'}, 'finish_reason': None}]})
+ return http.Response(200, content=(content + '\n\ndata: [DONE]\n\n').encode(), headers={'content-type': 'text/event-stream'})
+ return http.Response(200, json={'id': 'c1', 'object': 'chat.completion', 'created': 1,
+ 'model': 'auto', 'choices': [{'index': 0, 'finish_reason': 'tool_calls', 'message': {'role': 'assistant', 'content': None,
+ 'tool_calls': [{'id': 'call1', 'type': 'function', 'function': {'name': 'peek', 'arguments': '{}'}}]}}],
+ 'usage': {'prompt_tokens': 3, 'completion_tokens': 2, 'total_tokens': 5}})
+ http = _mock_transport(driver, respond)
+ assert driver.supports_streaming and driver.supports_tool_use
+ chunks = list(driver.generate_messages_stream([{'role': 'user', 'content': 'Hi'}], {}))
+ assert any(c.get('text') == 'OK' for c in chunks)
+ result = driver.generate_messages_with_tools([{'role': 'user', 'content': 'Peek'}],
+ [{'type': 'function', 'function': {'name': 'peek', 'parameters': {'type': 'object', 'properties': {}}}}], {})
+ assert result['tool_calls'][0]['name'] == 'peek'
+ assert all(payload['model'] == 'auto' for _, payload in calls)
+ assert all('authorization' not in headers for headers, _ in calls)
+ assert calls[-1][1]['tools'][0]['function']['name'] == 'peek'
+ driver.client.close()
+
+
+def test_resume_restores_history_with_original_connection_not_ambient(app, monkeypatch):
+ from prompture import Conversation
+ from prompture.drivers.base import Driver
+ calls = []
+ class FakeDriver(Driver):
+ def generate(self, prompt, options):
+ return {'text': 'OK', 'meta': {}}
+ monkeypatch.setattr(ai_service, 'build_tool_registry', lambda *a: None)
+ monkeypatch.setattr(ai_service, 'build_system_prompt', lambda *a, **kw: 'Current policy')
+ monkeypatch.setattr(ai_service, '_maybe_redact_result', lambda data: data)
+ monkeypatch.setattr(service, 'build_driver', lambda row, model=None: calls.append((row.id, model, row.config['api_key'])) or FakeDriver())
+ with app.app_context():
+ first = service.save(draft())
+ row = SimpleNamespace(id='chat', connection_id=first.id, model_name='openai_compatible/auto', export=None)
+ fresh = ai_service.build_conversation(row, None, 'simple', {}, None)
+ fresh._messages = [{'role': 'user', 'content': 'Remember me'}]
+ row.export = fresh.export()
+ service.save(draft(name='Other', make_default=True, config={'endpoint': 'http://other/v1', 'api_key': 'different'}))
+ resumed = ai_service.build_conversation(row, None, 'simple', {}, None)
+ assert isinstance(resumed, Conversation)
+ assert resumed._messages[0]['content'] == 'Remember me'
+ assert calls == [(first.id, 'auto', 'private-test-key')] * 2
+ assert resumed._fallback_models is None
+ assert 'private-test-key' not in json.dumps(resumed.export())
+
+
+def test_migration_preserves_legacy_key_and_conversation(app):
+ from alembic.migration import MigrationContext
+ from alembic.operations import Operations
+ from app.utils.crypto import encrypt_secret
+ path = Path(__file__).parents[1] / 'migrations/versions/098_ai_provider_connections.py'
+ spec = importlib.util.spec_from_file_location('migration098', path)
+ migration = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(migration)
+ with app.app_context():
+ SystemSettings.set('ai_provider', 'openai')
+ SystemSettings.set('ai_model', 'gpt-test')
+ SystemSettings.set('ai_api_key_encrypted', encrypt_secret('legacy-key'))
+ db.session.commit()
+ with db.engine.begin() as connection:
+ with Operations.context(MigrationContext.configure(connection)):
+ migration.upgrade()
+ migration.upgrade() # startup schema sync / rerun is safe
+ db.session.expire_all()
+ row = db.session.get(AiProviderConnection, 'legacy')
+ assert row.config['api_key'] == 'legacy-key'
+ assert service.default_id() == 'legacy'
+ # Legacy OpenAI records predate the explicit base_url field. Editing the
+ # name must not count the official default URL as a destination change.
+ prepared = service.prepare({'name': 'Renamed', 'provider': 'openai', 'model': 'gpt-test', 'config': {}}, row)
+ assert prepared['config']['api_key'] == 'legacy-key'
+
+
+def test_migration_from_old_schema_adds_connection_foreign_key():
+ import sqlalchemy as sa
+ from alembic.migration import MigrationContext
+ from alembic.operations import Operations
+ path = Path(__file__).parents[1] / 'migrations/versions/098_ai_provider_connections.py'
+ spec = importlib.util.spec_from_file_location('migration098_old', path)
+ migration = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(migration)
+ engine = sa.create_engine('sqlite:///:memory:')
+ with engine.begin() as conn:
+ conn.execute(sa.text('CREATE TABLE system_settings (key TEXT, value TEXT, value_type TEXT)'))
+ conn.execute(sa.text('CREATE TABLE ai_conversations (id TEXT PRIMARY KEY, model_name VARCHAR(128))'))
+ conn.execute(sa.text("INSERT INTO ai_conversations VALUES ('old', 'claude/old-model')"))
+ with Operations.context(MigrationContext.configure(conn)):
+ migration.upgrade()
+ inspector = sa.inspect(conn)
+ assert 'ai_provider_connections' in inspector.get_table_names()
+ assert any(c['name'] == 'connection_id' for c in inspector.get_columns('ai_conversations'))
+ assert inspector.get_foreign_keys('ai_conversations')[0]['referred_table'] == 'ai_provider_connections'
+ assert conn.execute(sa.text("SELECT model_name FROM ai_conversations WHERE id = 'old'")).scalar() == 'claude/old-model'
+ engine.dispose()
diff --git a/docs/AI_PROVIDERS.md b/docs/AI_PROVIDERS.md
new file mode 100644
index 00000000..1b07cf32
--- /dev/null
+++ b/docs/AI_PROVIDERS.md
@@ -0,0 +1,71 @@
+# AI provider connections
+
+In **Settings → AI Assistant**, add a named connection, choose a provider, fill
+in its configuration, and enter a default model ID. **Discover models** uses the
+current form values; manual model entry remains available when a provider does
+not support discovery. **Save connection** stores credentials encrypted. The
+first connection becomes the default automatically; another connection can be
+made default when saving it. Enable the assistant using the settings below the
+connection editor and save those settings.
+
+New chats offer a connection selector and an optional model override. Once a
+chat starts, its connection and model stay fixed. Changing the panel default
+does not reroute existing chats. You can rotate a connection's credentials, but
+changing a provider or endpoint used by existing chats requires a new connection.
+Delete those chats before deleting their connection, and select another default
+before deleting the current default.
+
+## Native providers and gateways
+
+The catalog comes from the installed Prompture chat-provider descriptors, with
+aliases deduplicated. Anthropic/Claude, OpenAI, Google, Azure, Bedrock, Mistral,
+and other registered chat drivers appear together. Providers needing optional
+Python dependencies are labeled in the selector. The backend requirements include
+the OpenAI and Anthropic SDKs; other providers may require their SDKs to be
+installed in the same backend environment before they become available.
+
+For **OmniRoute**, select **OpenAI-Compatible**, set the API base URL to your
+backend-reachable OmniRoute address (for example `http://omniroute:20128/v1` on a
+shared Docker network), and enter the gateway key if authentication is enabled.
+Enter the exact model ID or routing alias from that instance. Slashes are
+preserved; ServerKit does not add an upstream-provider prefix. The endpoint preset
+selector also exposes Prompture's curated compatible-provider URLs. Prompture Hub
+has its own friendly entry and uses the same connection mechanism.
+
+`localhost` means the machine or container running the ServerKit backend, not
+the browser. Endpoints accept HTTP or HTTPS but cannot embed credentials, query
+strings, or fragments. When changing an endpoint, re-enter credentials; ServerKit
+does not forward the previous endpoint's saved key to the new address.
+
+## Testing and capabilities
+
+For compatible endpoints and OpenAI, **Test connection** makes a small chat
+completion request, which may consume tokens. For other native providers, it
+verifies model discovery and checks that the requested model is returned. An
+unsupported or failed discovery reports an error, never a successful connection
+based only on constructing a driver. Discovery does not prove streaming or tool
+support; these depend on the provider and model. Error responses omit raw SDK
+errors and credentials.
+
+Prompture 1.10's generic compatible driver lacks native streaming/tool support.
+ServerKit uses Prompture's OpenAI driver with an explicit base URL for compatible
+connections, preserving those capabilities without writing another API client.
+Unauthenticated local gateways omit the Authorization header. Native Anthropic's
+installed driver does not accept an endpoint argument: ServerKit refuses a
+conflicting process-level `ANTHROPIC_BASE_URL` override instead of silently using
+it. Vertex Gemini requires an explicit API key; Vertex Claude requires a project,
+location, and access token. Ambient cloud credentials are not a connection option.
+
+Existing assistant RBAC, redaction, and write-action confirmations remain active.
+Gateway routing aliases may have unknown pricing; enforce authoritative spending
+limits at the gateway. Automatic fallback to another connection is not enabled.
+
+## Upgrade behavior
+
+Migration `098_ai_provider_connections` creates encrypted connection records,
+copies the existing single-provider configuration into **Existing connection**,
+and attaches matching legacy conversations to it. Older conversations from a
+different provider cannot borrow the current connection's credentials: start a
+new chat using an explicitly configured connection. Resumed chats reconstruct
+their Prompture driver with their saved connection, and restore history and
+usage without exporting credentials or using global provider configuration.
diff --git a/frontend/src/components/ai/ChatDrawer.jsx b/frontend/src/components/ai/ChatDrawer.jsx
index 1973074b..59789d25 100644
--- a/frontend/src/components/ai/ChatDrawer.jsx
+++ b/frontend/src/components/ai/ChatDrawer.jsx
@@ -7,6 +7,7 @@ import DrawerHeader from './DrawerHeader';
import ContextChip from './ContextChip';
import MessageList from './MessageList';
import Composer from './Composer';
+import ConnectionSelector from './ConnectionSelector';
import ShellDockTabs from '../ShellDockTabs';
import { useTranslation } from 'react-i18next';
@@ -70,6 +71,7 @@ const ChatDrawer = () => {
<ShellDockTabs expandable={false} />
</div>
<DrawerHeader />
+ <ConnectionSelector />
<ContextChip />
<MessageList />
<Composer />
diff --git a/frontend/src/components/ai/ConnectionSelector.jsx b/frontend/src/components/ai/ConnectionSelector.jsx
new file mode 100644
index 00000000..d4004eb3
--- /dev/null
+++ b/frontend/src/components/ai/ConnectionSelector.jsx
@@ -0,0 +1,22 @@
+import { FormField } from '../FormField';
+import { useServerkitAI } from '../../contexts/useServerkitAI';
+import { useTranslation } from 'react-i18next';
+
+export default function ConnectionSelector() {
+ const { t } = useTranslation();
+ const { connections, selectedConnection, selectedModel, selectConnection, selectModel, activeId, isStreaming } = useServerkitAI();
+ if (activeId || !connections.length) return null;
+ return (
+ <div className="sk-ai-connection-selector">
+ <FormField htmlFor="ai-chat-connection" label={<>{t('ai.connections.connection', 'Connection')}</>}>
+ <select id="ai-chat-connection" value={selectedConnection} disabled={isStreaming} onChange={(event) => selectConnection(event.target.value)}>
+ <option value="">{t('ai.connections.panelDefault', 'Panel default')}</option>
+ {connections.map((connection) => <option key={connection.id} value={connection.id}>{connection.name}</option>)}
+ </select>
+ </FormField>
+ <FormField htmlFor="ai-chat-model" label={<>{t('ai.connections.model', 'Model')}</>}>
+ <input id="ai-chat-model" value={selectedModel} disabled={isStreaming} maxLength={256} onChange={(event) => selectModel(event.target.value)} placeholder={t('ai.connections.connectionDefault', 'Connection default')} />
+ </FormField>
+ </div>
+ );
+}
diff --git a/frontend/src/components/settings/AIConnectionsSettings.jsx b/frontend/src/components/settings/AIConnectionsSettings.jsx
new file mode 100644
index 00000000..91e994e5
--- /dev/null
+++ b/frontend/src/components/settings/AIConnectionsSettings.jsx
@@ -0,0 +1,134 @@
+import { FormField } from '../FormField';
+import { useRef, useState } from 'react';
+import api from '../../services/api';
+import { useConfirm } from '../../hooks/useConfirm';
+import { Button } from '../ui/button';
+import { useTranslation } from 'react-i18next';
+
+const empty = () => ({ id: '', name: '', provider: '', model: '', config: {}, secrets_set: [], make_default: false });
+
+export default function AIConnectionsSettings({ connections, providers, defaultId, onSaved }) {
+ const { t } = useTranslation();
+ const { confirm } = useConfirm();
+ const [draft, setDraft] = useState(empty);
+ const [models, setModels] = useState([]);
+ const [busy, setBusy] = useState(false);
+ const [message, setMessage] = useState(null);
+ const revision = useRef(0);
+ const meta = providers.find((provider) => provider.id === draft.provider);
+
+ const edit = (next) => {
+ revision.current += 1;
+ setDraft(next);
+ setModels([]);
+ setMessage(null);
+ };
+ const selectConnection = (id) => {
+ const row = connections.find((connection) => connection.id === id);
+ edit(row ? { ...row, config: { ...row.config }, make_default: row.id === defaultId } : empty());
+ };
+ const selectProvider = (provider) => {
+ const selected = providers.find((item) => item.id === provider);
+ edit({ ...draft, provider, model: '', secrets_set: [],
+ config: Object.fromEntries((selected?.fields || []).filter((field) => !field.secret).map((field) => [field.name, field.default])) });
+ };
+ const setField = (field, value, clear = false) => {
+ const config = { ...draft.config, [field.name]: value };
+ if (field.secret && !value && !clear) delete config[field.name];
+ let secretsSet = draft.secrets_set;
+ if (field.type === 'url') {
+ for (const secret of meta.fields.filter((item) => item.secret)) delete config[secret.name];
+ secretsSet = [];
+ }
+ revision.current += 1;
+ setDraft({ ...draft, config, secrets_set: secretsSet });
+ setModels([]);
+ setMessage(null);
+ };
+ const run = async (operation) => {
+ const current = revision.current;
+ setBusy(true);
+ setMessage(null);
+ try {
+ if (operation === 'save') {
+ const row = await api.aiSaveConnection(draft);
+ const fresh = await onSaved();
+ if (current === revision.current) setDraft({ ...row, make_default: row.id === fresh.default_connection_id });
+ setMessage({ type: 'success', text: t('ai.connections.savedMessage', 'Connection saved. Existing chats keep their connection and model.') });
+ } else {
+ const result = await api.aiProbeConnection({ ...draft, test: operation === 'test' });
+ if (current !== revision.current) return;
+ if (operation === 'models') {
+ setModels(result.models || []);
+ setMessage({ type: 'success', text: t('ai.connections.modelsFound', '{{count}} models found. You can also enter a model ID manually.', { count: result.models?.length || 0 }) });
+ } else setMessage({ type: 'success', text: result.message || t('ai.connections.verified', 'Connection verified.') });
+ }
+ } catch (error) {
+ if (current === revision.current) setMessage({ type: 'error', text: error.message });
+ } finally { setBusy(false); }
+ };
+ const remove = async () => {
+ if (!await confirm({ title: t('ai.connections.deleteTitle', 'Delete AI connection?'), message: t('ai.connections.deleteMessage', 'Remove {{name}}? Connections used by chats or selected as default cannot be deleted.', { name: draft.name }), confirmText: t('ai.connections.delete', 'Delete'), variant: 'danger' })) return;
+ setBusy(true);
+ try {
+ await api.aiDeleteConnection(draft.id);
+ await onSaved();
+ edit(empty());
+ } catch (error) { setMessage({ type: 'error', text: error.message }); }
+ finally { setBusy(false); }
+ };
+
+ return (
+ <div className="settings-card">
+ <h3>{t('ai.connections.title', 'Provider connections')}</h3>
+ <p className="section-description">{t('ai.connections.description', 'Configure native Prompture providers or connect a gateway such as OmniRoute. Credentials stay encrypted on the server.')}</p>
+ <FormField htmlFor="ai-connection" label={<>{t('ai.connections.saved', 'Saved connection')}</>}>
+ <select id="ai-connection" value={draft.id} onChange={(event) => selectConnection(event.target.value)} disabled={busy}>
+ <option value="">{t('ai.connections.add', 'Add a connection…')}</option>
+ {connections.map((connection) => <option key={connection.id} value={connection.id}>{connection.name}{connection.id === defaultId ? t('ai.connections.defaultSuffix', ' (default)') : ''}</option>)}
+ </select>
+ </FormField>
+ <FormField htmlFor="ai-connection-name" label={<>{t('ai.connections.name', 'Connection name')}</>}>
+ <input id="ai-connection-name" value={draft.name} maxLength={100} disabled={busy} onChange={(event) => setDraft({ ...draft, name: event.target.value })} placeholder={t('ai.connections.namePlaceholder', 'e.g. Team Anthropic or Local OmniRoute')} />
+ </FormField>
+ <FormField htmlFor="ai-provider" label={<>{t('ai.connections.provider', 'Provider')}</>}>
+ <select id="ai-provider" value={draft.provider} disabled={busy} onChange={(event) => selectProvider(event.target.value)}>
+ <option value="">{t('ai.connections.selectProvider', 'Select a provider…')}</option>
+ {providers.map((provider) => <option key={provider.id} value={provider.id}>{provider.label}{provider.available ? '' : t('ai.connections.missingDependency', ' (dependency required)')}</option>)}
+ </select>
+ {meta && !meta.available && <p className="error-message">{meta.unavailable_reason}</p>}
+ </FormField>
+ {!!meta?.presets?.length && <FormField htmlFor="ai-preset" label={<>{t('ai.connections.preset', 'Endpoint preset')}</>}>
+ <select id="ai-preset" value="" disabled={busy} onChange={(event) => {
+ const preset = meta.presets.find((item) => item.id === event.target.value);
+ if (preset) setField({ name: 'endpoint', type: 'url' }, preset.endpoint);
+ }}>
+ <option value="">{t('ai.connections.choosePreset', 'Custom URL, or choose a preset…')}</option>
+ {meta.presets.map((preset) => <option key={preset.id} value={preset.id}>{preset.id}</option>)}
+ </select>
+ </FormField>}
+ {(meta?.fields || []).map((field) => <FormField key={field.name} htmlFor={`ai-config-${field.name}`} label={<>{field.label}{field.required ? t('ai.connections.required', ' (required)') : t('ai.connections.optional', ' (optional)')}</>}>
+ <input id={`ai-config-${field.name}`} type={field.secret ? 'password' : field.type}
+ autoComplete="off" disabled={busy} value={draft.config[field.name] ?? ''}
+ placeholder={field.secret && draft.secrets_set.includes(field.name) ? t('ai.connections.secretConfigured', 'Configured — leave blank to keep') : field.default || ''}
+ onChange={(event) => setField(field, event.target.value)} />
+ {field.secret && draft.secrets_set.includes(field.name) && <Button variant="unstyled" type="button" className="btn btn-ghost btn-sm" disabled={busy} onClick={() => setField(field, '', true)}>{t('ai.connections.clearSecret', 'Clear saved credential')}</Button>}
+ {field.type === 'url' && <p className="form-hint">{t('ai.connections.endpointHelp', 'Use an address reachable from the ServerKit backend. In Docker, localhost refers to the panel container. Changing this URL requires re-entering credentials.')}</p>}
+ </FormField>)}
+ <FormField htmlFor="ai-model" label={<>{t('ai.connections.defaultModel', 'Default model ID')}</>}>
+ <input id="ai-model" list="ai-model-options" value={draft.model} maxLength={256} disabled={busy} onChange={(event) => { revision.current += 1; setDraft({ ...draft, model: event.target.value }); }} placeholder={t('ai.connections.modelPlaceholder', 'Model ID or gateway routing alias')} />
+ <datalist id="ai-model-options">{models.map((model) => <option key={model} value={model} />)}</datalist>
+ </FormField>
+ <FormField>
+ <label><input type="checkbox" checked={draft.make_default} disabled={busy} onChange={(event) => setDraft({ ...draft, make_default: event.target.checked })} /> {t('ai.connections.makeDefault', 'Use as the default for new chats')}</label>
+ </FormField>
+ {message && <div className={`message ${message.type}`} role="status">{message.text}</div>}
+ <div className="settings-actions">
+ <Button variant="unstyled" type="button" className="btn btn-ghost" disabled={busy || !meta?.available} onClick={() => run('models')}>{t('ai.connections.discover', 'Discover models')}</Button>
+ <Button variant="unstyled" type="button" className="btn btn-ghost" disabled={busy || !meta?.available || !draft.model} onClick={() => run('test')}>{t('ai.connections.test', 'Test connection')}</Button>
+ <Button variant="unstyled" type="button" className="btn btn-primary" disabled={busy || !meta?.available || !draft.name || !draft.model} onClick={() => run('save')}>{busy ? t('ai.connections.working', 'Working…') : t('ai.connections.save', 'Save connection')}</Button>
+ {draft.id && <Button variant="unstyled" type="button" className="btn btn-danger" disabled={busy} onClick={remove}>{t('ai.connections.delete', 'Delete')}</Button>}
+ </div>
+ </div>
+ );
+}
diff --git a/frontend/src/components/settings/AISettingsTab.jsx b/frontend/src/components/settings/AISettingsTab.jsx
index bff0de80..0cb144d6 100644
--- a/frontend/src/components/settings/AISettingsTab.jsx
+++ b/frontend/src/components/settings/AISettingsTab.jsx
@@ -5,6 +5,7 @@ import { useAuth } from '../../contexts/useAuth.js';
import { Switch } from '@/components/ui/switch';
import { Label } from '@/components/ui/label';
import { Button } from '@/components/ui/button';
+import AIConnectionsSettings from './AIConnectionsSettings';
import { useTranslation } from 'react-i18next';
const AI_CONFIG_CHANGED_EVENT = 'serverkit:ai-config-changed';
@@ -19,11 +20,8 @@ const AISettingsTab = () => {
api_key_set: false,
});
const [providers, setProviders] = useState([]);
- const [models, setModels] = useState([]);
- const [apiKey, setApiKey] = useState(''); // write-only; '' means "unchanged"
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
- const [testing, setTesting] = useState(false);
const [message, setMessage] = useState(null);
useEffect(() => {
@@ -32,33 +30,25 @@ const AISettingsTab = () => {
.then(([s, p]) => {
setSettings((prev) => ({ ...prev, ...s, max_cost_usd: String(s.max_cost_usd ?? '0.5') }));
setProviders(p.providers || []);
- if (s.provider) loadModels(s.provider);
})
.catch((e) => setMessage({ type: 'error', text: e.message || 'Failed to load AI settings' }))
.finally(() => setLoading(false));
}, [isAdmin]);
- const loadModels = (provider) => {
- if (!provider) { setModels([]); return; }
- api.aiGetModels(provider).then((d) => setModels(d.models || [])).catch(() => setModels([]));
- };
-
- const onProviderChange = (provider) => {
- setSettings((s) => ({ ...s, provider, model: '' }));
- loadModels(provider);
+ const refreshConnections = async () => {
+ const fresh = await api.aiGetSettings();
+ setSettings((prev) => ({ ...prev, ...fresh, max_cost_usd: String(fresh.max_cost_usd ?? '0.5') }));
+ window.dispatchEvent(new Event(AI_CONFIG_CHANGED_EVENT));
+ return fresh;
};
const buildPayload = () => {
const payload = {
enabled: settings.enabled,
- provider: settings.provider,
- model: settings.model,
- endpoint: settings.endpoint,
pii_redaction: settings.pii_redaction,
injection_detection: settings.injection_detection,
max_cost_usd: settings.max_cost_usd,
};
- if (apiKey.trim()) payload.api_key = apiKey.trim();
return payload;
};
@@ -67,7 +57,6 @@ const AISettingsTab = () => {
setMessage(null);
try {
await api.aiUpdateSettings(buildPayload());
- setApiKey('');
const fresh = await api.aiGetSettings();
setSettings((prev) => ({ ...prev, ...fresh, max_cost_usd: String(fresh.max_cost_usd ?? '0.5') }));
window.dispatchEvent(new Event(AI_CONFIG_CHANGED_EVENT));
@@ -79,23 +68,6 @@ const AISettingsTab = () => {
}
};
- const handleTest = async () => {
- setTesting(true);
- setMessage(null);
- try {
- const body = { provider: settings.provider, model: settings.model, endpoint: settings.endpoint };
- if (apiKey.trim()) body.api_key = apiKey.trim();
- const res = await api.aiTestSettings(body);
- setMessage(res.ok
- ? { type: 'success', text: 'Connection OK' }
- : { type: 'error', text: `Connection failed: ${res.error || 'unknown error'}` });
- } catch (e) {
- setMessage({ type: 'error', text: e.message || 'Test failed' });
- } finally {
- setTesting(false);
- }
- };
-
if (!isAdmin) {
return <div className="settings-section"><p>{t('app.aISettingsTab.adminAccessRequired', 'Admin access required.')}</p></div>;
}
@@ -103,8 +75,6 @@ const AISettingsTab = () => {
return <div className="settings-section"><p>{t('common.loading', 'Loading…')}</p></div>;
}
- const activeProvider = providers.find((p) => p.id === settings.provider);
- const needsKey = activeProvider ? activeProvider.needs_key : true;
return (
<div className="settings-section">
@@ -115,7 +85,11 @@ const AISettingsTab = () => {
{message && <div className={`message ${message.type}`}>{message.text}</div>}
- <div {...register('ai-provider', 'settings-card')}>
+ <div {...register('ai-provider')}>
+ <AIConnectionsSettings connections={settings.connections || []} providers={providers}
+ defaultId={settings.default_connection_id} onSaved={refreshConnections} />
+ </div>
+ <div className="settings-card">
<div className="form-group">
<div className="settings-row">
<div className="settings-label"><Label>{t('app.aISettingsTab.enableAiAssistant', 'Enable AI assistant')}</Label></div>
@@ -126,62 +100,6 @@ const AISettingsTab = () => {
</div>
</div>
- <div className="form-group">
- <label htmlFor="ai-provider">{t('app.aISettingsTab.provider', 'Provider')}</label>
- <select
- id="ai-provider"
- value={settings.provider}
- onChange={(e) => onProviderChange(e.target.value)}
- >
- <option value="">{t('app.aISettingsTab.selectAProvider', 'Select a provider…')}</option>
- {providers.map((p) => (
- <option key={p.id} value={p.id}>{p.label}</option>
- ))}
- </select>
- </div>
-
- <div className="form-group">
- <label htmlFor="ai-model">{t('app.aISettingsTab.model', 'Model')}</label>
- <input
- id="ai-model"
- type="text"
- list="ai-model-options"
- placeholder={t('app.aISettingsTab.eGGpt4o', 'e.g. gpt-4o')}
- value={settings.model}
- onChange={(e) => setSettings((s) => ({ ...s, model: e.target.value }))}
- />
- <datalist id="ai-model-options">
- {models.map((m) => <option key={m} value={m} />)}
- </datalist>
- </div>
-
- {needsKey && (
- <div className="form-group">
- <label htmlFor="ai-key">{t('app.aISettingsTab.apiKey', 'API key')}</label>
- <input
- id="ai-key"
- type="password"
- autoComplete="off"
- placeholder={settings.api_key_set ? t('app.aISettingsTab.configuredLeaveBlankToKeep', 'Configured ✓ (leave blank to keep)') : t('app.aISettingsTab.pasteYourApiKey', 'Paste your API key')}
- value={apiKey}
- onChange={(e) => setApiKey(e.target.value)}
- />
- </div>
- )}
-
- {activeProvider && activeProvider.supports_endpoint && (
- <div className="form-group">
- <label htmlFor="ai-endpoint">{t('app.aISettingsTab.endpointOptional', 'Endpoint (optional)')}</label>
- <input
- id="ai-endpoint"
- type="text"
- placeholder="http://localhost:11434"
- value={settings.endpoint}
- onChange={(e) => setSettings((s) => ({ ...s, endpoint: e.target.value }))}
- />
- </div>
- )}
-
<div className="form-group">
<label htmlFor="ai-max-cost">{t('app.aISettingsTab.perConversationCostCeilingUsd', 'Per-conversation cost ceiling (USD)')}</label>
<input
@@ -214,9 +132,6 @@ const AISettingsTab = () => {
</div>
<div className="settings-actions">
- <Button variant="outline" onClick={handleTest} disabled={testing || !settings.provider || !settings.model}>
- {testing ? 'Testing…' : 'Test connection'}
- </Button>
<Button variant="primary" onClick={handleSave} disabled={saving}>
{saving ? 'Saving…' : 'Save'}
</Button>
diff --git a/frontend/src/contexts/AIContext.jsx b/frontend/src/contexts/AIContext.jsx
index 22c5bc31..24b534d0 100644
--- a/frontend/src/contexts/AIContext.jsx
+++ b/frontend/src/contexts/AIContext.jsx
@@ -24,6 +24,9 @@ const initialState = {
providerConfigured: false,
statusLoaded: false,
conversations: [],
+ connections: [],
+ selectedConnection: '',
+ selectedModel: '',
activeId: null,
attachments: [],
messages: [], // [{ id, role, content, toolCalls, thinking, status, error }]
@@ -68,6 +71,18 @@ function reducer(state, action) {
return { ...state, includeContext: action.value };
case 'SET_STATUS':
return { ...state, providerConfigured: action.configured, statusLoaded: true };
+ case 'SET_CONNECTIONS': {
+ const selected = action.connections.find((connection) => connection.id === state.selectedConnection)
+ || action.connections.find((connection) => connection.id === action.defaultId);
+ return { ...state, connections: action.connections, selectedConnection: selected?.id || '',
+ selectedModel: state.selectedConnection === selected?.id ? state.selectedModel : selected?.model || '' };
+ }
+ case 'SELECT_CONNECTION': {
+ const connection = state.connections.find((item) => item.id === action.id);
+ return { ...state, selectedConnection: action.id, selectedModel: connection?.model || '' };
+ }
+ case 'SELECT_MODEL':
+ return { ...state, selectedModel: action.model };
case 'SET_CONVERSATIONS':
return { ...state, conversations: action.conversations };
case 'SET_ACTIVE':
@@ -206,6 +221,9 @@ export function AIProvider({ children }) {
// --- status ---
const loadStatus = useCallback(() => {
+ api.aiGetConnections()
+ .then((data) => dispatch({ type: 'SET_CONNECTIONS', connections: data.connections || [], defaultId: data.default_connection_id }))
+ .catch(() => {});
api.aiStatus()
.then((s) => dispatch({ type: 'SET_STATUS', configured: !!s.configured }))
.catch(() => dispatch({ type: 'SET_STATUS', configured: false }));
@@ -299,6 +317,8 @@ export function AIProvider({ children }) {
conversation_id: activeIdRef.current || undefined,
message: text,
mode,
+ connection_id: activeIdRef.current ? undefined : state.selectedConnection || undefined,
+ model: activeIdRef.current ? undefined : state.selectedModel || undefined,
};
if (requestedAttachments.length) {
payload.attachments = requestedAttachments.map(toAttachmentPayload).filter(Boolean);
@@ -334,6 +354,7 @@ export function AIProvider({ children }) {
}
}, [
state.isStreaming, state.mode, state.includeContext, state.attachments,
+ state.selectedConnection, state.selectedModel,
buildPageContext, handleEvent, loadConversations,
]);
@@ -405,6 +426,8 @@ export function AIProvider({ children }) {
// state
...state,
isOpen: state.open,
+ selectConnection: (id) => dispatch({ type: 'SELECT_CONNECTION', id }),
+ selectModel: (model) => dispatch({ type: 'SELECT_MODEL', model }),
pageContext,
// controls
open, close, toggle, ask, send, stop, confirmAction, setMode, setIncludeContext,
diff --git a/frontend/src/i18n/locales/ar.json b/frontend/src/i18n/locales/ar.json
index 570c68c7..5a04c1f7 100644
--- a/frontend/src/i18n/locales/ar.json
+++ b/frontend/src/i18n/locales/ar.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "مطلوب وصول المشرف.",
"aiAssistant": "مساعد الذكاء الاصطناعي",
- "apiKey": "مفتاح API",
"blockPromptInjectionAttempts": "منع محاولات الحقن السريع",
"configureTheInPanelAssistantPowered": "قم بتكوين المساعد الموجود داخل اللوحة - المدعوم من Prompture. يتم تخزين مفتاح API بشكل مشفر ولا يتم إعادته مطلقًا بواسطة API.",
- "configuredLeaveBlankToKeep": "تم التهيئة ✓ (اتركه فارغًا للاحتفاظ به)",
- "eGGpt4o": "على سبيل المثال gpt-4o",
"enableAiAssistant": "تمكين مساعد الذكاء الاصطناعي",
- "endpointOptional": "نقطة النهاية (اختياري)",
- "model": "نموذج",
- "pasteYourApiKey": "الصق مفتاح API",
"perConversationCostCeilingUsd": "سقف التكلفة لكل محادثة (بالدولار الأمريكي)",
- "provider": "مزود",
- "redactPiiFromMessagesToolOutput": "قم بتنقيح معلومات تحديد الهوية الشخصية (PII) من الرسائل ومخرجات الأداة",
- "selectAProvider": "اختر مزود…"
+ "redactPiiFromMessagesToolOutput": "قم بتنقيح معلومات تحديد الهوية الشخصية (PII) من الرسائل ومخرجات الأداة"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "لوحة إدارة خادم حديثة وخفيفة الوزن لإدارة تطبيقات الويب وقواعد البيانات والمجالات والمزيد. تم تصميمه باستخدام Flask وReact.",
diff --git a/frontend/src/i18n/locales/bn.json b/frontend/src/i18n/locales/bn.json
index 7f880046..7ffd0b95 100644
--- a/frontend/src/i18n/locales/bn.json
+++ b/frontend/src/i18n/locales/bn.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "অ্যাডমিন অ্যাক্সেস প্রয়োজন.",
"aiAssistant": "এআই সহকারী",
- "apiKey": "API কী",
"blockPromptInjectionAttempts": "প্রম্পট-ইনজেকশন প্রচেষ্টা ব্লক করুন",
"configureTheInPanelAssistantPowered": "ইন-প্যানেল সহকারী কনফিগার করুন — প্রম্পচার দ্বারা চালিত। API কী এনক্রিপ্ট করা সংরক্ষিত এবং API দ্বারা ফেরত দেওয়া হয় না।",
- "configuredLeaveBlankToKeep": "কনফিগার করা ✓ (রাখতে ফাঁকা ছেড়ে দিন)",
- "eGGpt4o": "যেমন gpt-4o",
"enableAiAssistant": "এআই সহকারী সক্ষম করুন",
- "endpointOptional": "শেষবিন্দু (ঐচ্ছিক)",
- "model": "মডেল",
- "pasteYourApiKey": "আপনার API কী পেস্ট করুন",
"perConversationCostCeilingUsd": "প্রতি-কথোপকথনের খরচ সিলিং (USD)",
- "provider": "প্রদানকারী",
- "redactPiiFromMessagesToolOutput": "বার্তা এবং টুল আউটপুট থেকে PII রিড্যাক্ট করুন",
- "selectAProvider": "একটি প্রদানকারী নির্বাচন করুন..."
+ "redactPiiFromMessagesToolOutput": "বার্তা এবং টুল আউটপুট থেকে PII রিড্যাক্ট করুন"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "ওয়েব অ্যাপ্লিকেশন, ডাটাবেস, ডোমেন এবং আরও অনেক কিছু পরিচালনার জন্য একটি আধুনিক, লাইটওয়েট সার্ভার ম্যানেজমেন্ট প্যানেল। Flask এবং React দিয়ে নির্মিত।",
diff --git a/frontend/src/i18n/locales/de.json b/frontend/src/i18n/locales/de.json
index c06b1d3c..4ceca4f6 100644
--- a/frontend/src/i18n/locales/de.json
+++ b/frontend/src/i18n/locales/de.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Administratorzugriff erforderlich.",
"aiAssistant": "KI-Assistent",
- "apiKey": "API-Schlüssel",
"blockPromptInjectionAttempts": "Blockieren Sie Versuche zur sofortigen Injektion",
"configureTheInPanelAssistantPowered": "Konfigurieren Sie den In-Panel-Assistenten – unterstützt von Prompture. Der API-Schlüssel wird verschlüsselt gespeichert und niemals von der API zurückgegeben.",
- "configuredLeaveBlankToKeep": "Konfiguriert ✓ (zum Behalten leer lassen)",
- "eGGpt4o": "z.B. gpt-4o",
"enableAiAssistant": "Aktivieren Sie den KI-Assistenten",
- "endpointOptional": "Endpunkt (optional)",
- "model": "Modell",
- "pasteYourApiKey": "Fügen Sie Ihren API-Schlüssel ein",
"perConversationCostCeilingUsd": "Kostenobergrenze pro Gespräch (USD)",
- "provider": "Anbieter",
- "redactPiiFromMessagesToolOutput": "PII aus Nachrichten und Tool-Ausgaben schwärzen",
- "selectAProvider": "Wählen Sie einen Anbieter aus…"
+ "redactPiiFromMessagesToolOutput": "PII aus Nachrichten und Tool-Ausgaben schwärzen"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Ein modernes, leichtes Serververwaltungspanel zur Verwaltung von Webanwendungen, Datenbanken, Domänen und mehr. Gebaut mit Flask und React.",
diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json
index 58464b54..1f4546b2 100644
--- a/frontend/src/i18n/locales/en.json
+++ b/frontend/src/i18n/locales/en.json
@@ -1,21 +1,51 @@
{
+ "ai": {
+ "connections": {
+ "add": "Add a connection…",
+ "choosePreset": "Custom URL, or choose a preset…",
+ "clearSecret": "Clear saved credential",
+ "connection": "Connection",
+ "connectionDefault": "Connection default",
+ "defaultModel": "Default model ID",
+ "defaultSuffix": " (default)",
+ "delete": "Delete",
+ "deleteMessage": "Remove {{name}}? Connections used by chats or selected as default cannot be deleted.",
+ "deleteTitle": "Delete AI connection?",
+ "description": "Configure native Prompture providers or connect a gateway such as OmniRoute. Credentials stay encrypted on the server.",
+ "discover": "Discover models",
+ "endpointHelp": "Use an address reachable from the ServerKit backend. In Docker, localhost refers to the panel container. Changing this URL requires re-entering credentials.",
+ "makeDefault": "Use as the default for new chats",
+ "missingDependency": " (dependency required)",
+ "model": "Model",
+ "modelPlaceholder": "Model ID or gateway routing alias",
+ "modelsFound": "{{count}} models found. You can also enter a model ID manually.",
+ "name": "Connection name",
+ "namePlaceholder": "e.g. Team Anthropic or Local OmniRoute",
+ "optional": " (optional)",
+ "panelDefault": "Panel default",
+ "preset": "Endpoint preset",
+ "provider": "Provider",
+ "required": " (required)",
+ "save": "Save connection",
+ "saved": "Saved connection",
+ "savedMessage": "Connection saved. Existing chats keep their connection and model.",
+ "secretConfigured": "Configured — leave blank to keep",
+ "selectProvider": "Select a provider…",
+ "test": "Test connection",
+ "title": "Provider connections",
+ "verified": "Connection verified.",
+ "working": "Working…"
+ }
+ },
"app": {
"aISettingsTab": {
"adminAccessRequired": "Admin access required.",
"aiAssistant": "AI Assistant",
- "apiKey": "API key",
"blockPromptInjectionAttempts": "Block prompt-injection attempts",
"configureTheInPanelAssistantPowered": "Configure the in-panel assistant — powered by Prompture. The API key is stored encrypted and never returned by the API.",
- "configuredLeaveBlankToKeep": "Configured ✓ (leave blank to keep)",
- "eGGpt4o": "e.g. gpt-4o",
"enableAiAssistant": "Enable AI assistant",
- "endpointOptional": "Endpoint (optional)",
- "model": "Model",
- "pasteYourApiKey": "Paste your API key",
"perConversationCostCeilingUsd": "Per-conversation cost ceiling (USD)",
- "provider": "Provider",
- "redactPiiFromMessagesToolOutput": "Redact PII from messages & tool output",
- "selectAProvider": "Select a provider…"
+ "redactPiiFromMessagesToolOutput": "Redact PII from messages & tool output"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "A modern, lightweight server management panel for managing web applications, databases, domains, and more. Built with Flask and React.",
diff --git a/frontend/src/i18n/locales/es.json b/frontend/src/i18n/locales/es.json
index 49e8845a..3cd04bf5 100644
--- a/frontend/src/i18n/locales/es.json
+++ b/frontend/src/i18n/locales/es.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Se requiere acceso de administrador.",
"aiAssistant": "Asistente de IA",
- "apiKey": "Clave de API",
"blockPromptInjectionAttempts": "Bloquear intentos de inyección de prompts",
"configureTheInPanelAssistantPowered": "Configura el asistente integrado en el panel, con tecnología de Prompture. La clave de API se guarda cifrada y la API nunca la devuelve.",
- "configuredLeaveBlankToKeep": "Configurada ✓ (deja en blanco para conservarla)",
- "eGGpt4o": "p. ej. gpt-4o",
"enableAiAssistant": "Activar el asistente de IA",
- "endpointOptional": "Endpoint (opcional)",
- "model": "Modelo",
- "pasteYourApiKey": "Pega tu clave de API",
"perConversationCostCeilingUsd": "Límite de costo por conversación (USD)",
- "provider": "Proveedor",
- "redactPiiFromMessagesToolOutput": "Ocultar PII en mensajes y salida de herramientas",
- "selectAProvider": "Selecciona un proveedor…"
+ "redactPiiFromMessagesToolOutput": "Ocultar PII en mensajes y salida de herramientas"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Un panel de administración de servidores moderno y ligero para gestionar aplicaciones web, bases de datos, dominios y más. Creado con Flask y React.",
diff --git a/frontend/src/i18n/locales/fr.json b/frontend/src/i18n/locales/fr.json
index bffa7117..4961c86f 100644
--- a/frontend/src/i18n/locales/fr.json
+++ b/frontend/src/i18n/locales/fr.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Accès administrateur requis.",
"aiAssistant": "Assistant IA",
- "apiKey": "Clé API",
"blockPromptInjectionAttempts": "Bloquer les tentatives d'injection rapide",
"configureTheInPanelAssistantPowered": "Configurez l'assistant intégré au panneau, optimisé par Prompture. La clé API est stockée cryptée et n'est jamais renvoyée par le API.",
- "configuredLeaveBlankToKeep": "Configuré ✓ (laisser vide pour conserver)",
- "eGGpt4o": "par ex. gpt-4o",
"enableAiAssistant": "Activer l'assistant IA",
- "endpointOptional": "Point de terminaison (facultatif)",
- "model": "Modèle",
- "pasteYourApiKey": "Collez votre clé API",
"perConversationCostCeilingUsd": "Plafond du coût par conversation (USD)",
- "provider": "Fournisseur",
- "redactPiiFromMessagesToolOutput": "Rédiger les informations personnelles à partir des messages et des résultats de l'outil",
- "selectAProvider": "Sélectionnez un fournisseur…"
+ "redactPiiFromMessagesToolOutput": "Rédiger les informations personnelles à partir des messages et des résultats de l'outil"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Un panneau de gestion de serveur moderne et léger pour gérer les applications Web, les bases de données, les domaines et bien plus encore. Construit avec Flask et React.",
diff --git a/frontend/src/i18n/locales/id.json b/frontend/src/i18n/locales/id.json
index 8249ec24..e56f4287 100644
--- a/frontend/src/i18n/locales/id.json
+++ b/frontend/src/i18n/locales/id.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Diperlukan akses admin.",
"aiAssistant": "Asisten AI",
- "apiKey": "Kunci API",
"blockPromptInjectionAttempts": "Blokir upaya injeksi cepat",
"configureTheInPanelAssistantPowered": "Konfigurasikan asisten dalam panel — didukung oleh Prompture. Kunci API disimpan terenkripsi dan tidak pernah dikembalikan oleh API.",
- "configuredLeaveBlankToKeep": "Dikonfigurasi ✓ (biarkan kosong untuk disimpan)",
- "eGGpt4o": "misalnya gpt-4o",
"enableAiAssistant": "Aktifkan asisten AI",
- "endpointOptional": "Titik akhir (opsional)",
- "model": "Model",
- "pasteYourApiKey": "Tempelkan kunci API Anda",
"perConversationCostCeilingUsd": "Batas atas biaya per percakapan (USD)",
- "provider": "Penyedia",
- "redactPiiFromMessagesToolOutput": "Sunting PII dari pesan & keluaran alat",
- "selectAProvider": "Pilih penyedia…"
+ "redactPiiFromMessagesToolOutput": "Sunting PII dari pesan & keluaran alat"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Panel manajemen server yang modern dan ringan untuk mengelola aplikasi web, database, domain, dan banyak lagi. Dibangun dengan Flask dan React.",
diff --git a/frontend/src/i18n/locales/it.json b/frontend/src/i18n/locales/it.json
index b18859f6..263280a9 100644
--- a/frontend/src/i18n/locales/it.json
+++ b/frontend/src/i18n/locales/it.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "È richiesto l'accesso amministrativo.",
"aiAssistant": "Assistente AI",
- "apiKey": "Chiave API",
"blockPromptInjectionAttempts": "Blocca i tentativi di pronta iniezione",
"configureTheInPanelAssistantPowered": "Configura l'assistente nel pannello, basato su Prompture. La chiave API viene archiviata crittografata e non viene mai restituita da API.",
- "configuredLeaveBlankToKeep": "Configurato ✓ (lasciare vuoto per mantenere)",
- "eGGpt4o": "per esempio. gpt-4o",
"enableAiAssistant": "Abilita l'assistente AI",
- "endpointOptional": "Endpoint (facoltativo)",
- "model": "Modello",
- "pasteYourApiKey": "Incolla la tua chiave API",
"perConversationCostCeilingUsd": "Tetto massimo del costo per conversazione (USD)",
- "provider": "Fornitore",
- "redactPiiFromMessagesToolOutput": "Oscura le PII dai messaggi e dall'output dello strumento",
- "selectAProvider": "Seleziona un fornitore..."
+ "redactPiiFromMessagesToolOutput": "Oscura le PII dai messaggi e dall'output dello strumento"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Un pannello di gestione server moderno e leggero per la gestione di applicazioni Web, database, domini e altro ancora. Costruito con Flask e React.",
diff --git a/frontend/src/i18n/locales/ko.json b/frontend/src/i18n/locales/ko.json
index 6e3be60f..b8371486 100644
--- a/frontend/src/i18n/locales/ko.json
+++ b/frontend/src/i18n/locales/ko.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "관리자 액세스가 필요합니다.",
"aiAssistant": "AI 어시스턴트",
- "apiKey": "API 키",
"blockPromptInjectionAttempts": "프롬프트 주입 시도 차단",
"configureTheInPanelAssistantPowered": "Prompture에서 제공하는 패널 내 도우미를 구성하세요. API 키는 암호화되어 저장되며 API에 의해 반환되지 않습니다.",
- "configuredLeaveBlankToKeep": "구성됨 ✓ (유지하려면 비워두세요)",
- "eGGpt4o": "예를 들어 gpt-4o",
"enableAiAssistant": "AI 어시스턴트 활성화",
- "endpointOptional": "엔드포인트(선택사항)",
- "model": "모델",
- "pasteYourApiKey": "API 키를 붙여넣으세요.",
"perConversationCostCeilingUsd": "대화당 비용 상한선(USD)",
- "provider": "공급자",
- "redactPiiFromMessagesToolOutput": "메시지 및 도구 출력에서 PII 수정",
- "selectAProvider": "제공업체를 선택하세요…"
+ "redactPiiFromMessagesToolOutput": "메시지 및 도구 출력에서 PII 수정"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "웹 애플리케이션, 데이터베이스, 도메인 등을 관리하기 위한 현대적이고 가벼운 서버 관리 패널입니다. Flask와 React로 제작되었습니다.",
diff --git a/frontend/src/i18n/locales/pl.json b/frontend/src/i18n/locales/pl.json
index 4ceb2a56..a73927e7 100644
--- a/frontend/src/i18n/locales/pl.json
+++ b/frontend/src/i18n/locales/pl.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Wymagany dostęp administratora.",
"aiAssistant": "Asystent AI",
- "apiKey": "Klucz API",
"blockPromptInjectionAttempts": "Blokuj próby wstrzyknięcia monitu",
"configureTheInPanelAssistantPowered": "Skonfiguruj asystenta w panelu — obsługiwanego przez Prompture. Klucz API jest przechowywany w postaci zaszyfrowanej i nigdy nie jest zwracany przez API.",
- "configuredLeaveBlankToKeep": "Skonfigurowano ✓ (pozostaw puste, aby zachować)",
- "eGGpt4o": "np. gpt-4o",
"enableAiAssistant": "Włącz asystenta AI",
- "endpointOptional": "Punkt końcowy (opcjonalnie)",
- "model": "Model",
- "pasteYourApiKey": "Wklej klucz API",
"perConversationCostCeilingUsd": "Pułap kosztu rozmowy (USD)",
- "provider": "Dostawca",
- "redactPiiFromMessagesToolOutput": "Redaguj informacje umożliwiające identyfikację z komunikatów i wyników narzędzi",
- "selectAProvider": "Wybierz dostawcę…"
+ "redactPiiFromMessagesToolOutput": "Redaguj informacje umożliwiające identyfikację z komunikatów i wyników narzędzi"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Nowoczesny, lekki panel zarządzania serwerem umożliwiający zarządzanie aplikacjami internetowymi, bazami danych, domenami i nie tylko. Zbudowany z Flask i React.",
diff --git a/frontend/src/i18n/locales/pt.json b/frontend/src/i18n/locales/pt.json
index aef1cb92..99e0f4a5 100644
--- a/frontend/src/i18n/locales/pt.json
+++ b/frontend/src/i18n/locales/pt.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "É necessário acesso de administrador.",
"aiAssistant": "Assistente de IA",
- "apiKey": "Chave de API",
"blockPromptInjectionAttempts": "Bloquear tentativas de injeção imediata",
"configureTheInPanelAssistantPowered": "Configure o assistente no painel – desenvolvido pela Prompture. A chave da API é armazenada criptografada e nunca retornada pela API.",
- "configuredLeaveBlankToKeep": "Configurado ✓ (deixe em branco para manter)",
- "eGGpt4o": "por exemplo gpt-4o",
"enableAiAssistant": "Habilitar assistente de IA",
- "endpointOptional": "Ponto final (opcional)",
- "model": "Modelo",
- "pasteYourApiKey": "Cole sua chave de API",
"perConversationCostCeilingUsd": "Teto de custo por conversa (USD)",
- "provider": "Provedor",
- "redactPiiFromMessagesToolOutput": "Editar PII de mensagens e resultados de ferramentas",
- "selectAProvider": "Selecione um provedor…"
+ "redactPiiFromMessagesToolOutput": "Editar PII de mensagens e resultados de ferramentas"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Um painel de gerenciamento de servidor moderno e leve para gerenciar aplicativos web, bancos de dados, domínios e muito mais. Construído com Flask e React.",
diff --git a/frontend/src/i18n/locales/ru.json b/frontend/src/i18n/locales/ru.json
index 6ef007ea..cd281ef3 100644
--- a/frontend/src/i18n/locales/ru.json
+++ b/frontend/src/i18n/locales/ru.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Требуется доступ администратора.",
"aiAssistant": "ИИ-помощник",
- "apiKey": "API-ключ",
"blockPromptInjectionAttempts": "Блокировать попытки быстрого внедрения",
"configureTheInPanelAssistantPowered": "Настройте встроенного в панель помощника на базе Prompture. Ключ API хранится в зашифрованном виде и никогда не возвращается API.",
- "configuredLeaveBlankToKeep": "Настроено ✓ (оставьте пустым, чтобы сохранить)",
- "eGGpt4o": "например gpt-4o",
"enableAiAssistant": "Включить AI-помощника",
- "endpointOptional": "Конечная точка (необязательно)",
- "model": "Модель",
- "pasteYourApiKey": "Вставьте свой ключ API",
"perConversationCostCeilingUsd": "Максимальная стоимость разговора (долл. США)",
- "provider": "Поставщик",
- "redactPiiFromMessagesToolOutput": "Удаление личных данных из сообщений и выходных данных инструмента",
- "selectAProvider": "Выберите провайдера…"
+ "redactPiiFromMessagesToolOutput": "Удаление личных данных из сообщений и выходных данных инструмента"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Современная, легкая панель управления сервером для управления веб-приложениями, базами данных, доменами и многим другим. Создан с помощью Flask и React.",
diff --git a/frontend/src/i18n/locales/th.json b/frontend/src/i18n/locales/th.json
index fc7eba44..6a21ed9d 100644
--- a/frontend/src/i18n/locales/th.json
+++ b/frontend/src/i18n/locales/th.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "จำเป็นต้องเข้าถึงระดับผู้ดูแลระบบ",
"aiAssistant": "ผู้ช่วยเอไอ",
- "apiKey": "คีย์ API",
"blockPromptInjectionAttempts": "บล็อกความพยายามในการฉีดพร้อมท์",
"configureTheInPanelAssistantPowered": "กำหนดค่าผู้ช่วยในแผง — ขับเคลื่อนโดย Prompture คีย์ API จะถูกจัดเก็บแบบเข้ารหัสและไม่เคยส่งคืนโดย API",
- "configuredLeaveBlankToKeep": "กำหนดค่า ✓ แล้ว (เว้นว่างไว้เพื่อเก็บไว้)",
- "eGGpt4o": "เช่น GPT-4o",
"enableAiAssistant": "เปิดใช้งานผู้ช่วย AI",
- "endpointOptional": "จุดสิ้นสุด (ไม่บังคับ)",
- "model": "แบบอย่าง",
- "pasteYourApiKey": "วางคีย์ API ของคุณ",
"perConversationCostCeilingUsd": "เพดานค่าใช้จ่ายต่อการสนทนา (USD)",
- "provider": "ผู้ให้บริการ",
- "redactPiiFromMessagesToolOutput": "ปกปิด PII จากข้อความและเอาต์พุตของเครื่องมือ",
- "selectAProvider": "เลือกผู้ให้บริการ..."
+ "redactPiiFromMessagesToolOutput": "ปกปิด PII จากข้อความและเอาต์พุตของเครื่องมือ"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "แผงการจัดการเซิร์ฟเวอร์ที่ทันสมัยและมีน้ำหนักเบาสำหรับการจัดการแอปพลิเคชันเว็บ ฐานข้อมูล โดเมน และอื่นๆ สร้างด้วย Flask และ React",
diff --git a/frontend/src/i18n/locales/tr.json b/frontend/src/i18n/locales/tr.json
index cc372ec2..774b343a 100644
--- a/frontend/src/i18n/locales/tr.json
+++ b/frontend/src/i18n/locales/tr.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Yönetici erişimi gerekli.",
"aiAssistant": "Yapay Zeka Asistanı",
- "apiKey": "API anahtarı",
"blockPromptInjectionAttempts": "İstem ekleme girişimlerini engelle",
"configureTheInPanelAssistantPowered": "Prompture tarafından desteklenen panel içi asistanı yapılandırın. API anahtarı şifrelenmiş olarak saklanır ve API tarafından asla döndürülmez.",
- "configuredLeaveBlankToKeep": "Yapılandırılmış ✓ (saklamak için boş bırakın)",
- "eGGpt4o": "örneğin gpt-4o",
"enableAiAssistant": "AI asistanını etkinleştir",
- "endpointOptional": "Uç nokta (isteğe bağlı)",
- "model": "Modeli",
- "pasteYourApiKey": "API anahtarınızı yapıştırın",
"perConversationCostCeilingUsd": "Görüşme başına maliyet tavanı (USD)",
- "provider": "sağlayıcı",
- "redactPiiFromMessagesToolOutput": "Mesajlardan ve araç çıktılarından PII'yi çıkarın",
- "selectAProvider": "Bir sağlayıcı seçin…"
+ "redactPiiFromMessagesToolOutput": "Mesajlardan ve araç çıktılarından PII'yi çıkarın"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Web uygulamalarını, veritabanlarını, etki alanlarını ve daha fazlasını yönetmek için modern, hafif bir sunucu yönetim paneli. Flask ve React ile oluşturulmuştur.",
diff --git a/frontend/src/i18n/locales/vi.json b/frontend/src/i18n/locales/vi.json
index e900a454..5d6c48e0 100644
--- a/frontend/src/i18n/locales/vi.json
+++ b/frontend/src/i18n/locales/vi.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "Yêu cầu quyền truy cập của quản trị viên.",
"aiAssistant": "Trợ lý AI",
- "apiKey": "Phím API",
"blockPromptInjectionAttempts": "Chặn các nỗ lực tiêm nhắc nhở",
"configureTheInPanelAssistantPowered": "Định cấu hình trợ lý trong bảng điều khiển - được cung cấp bởi Nhắc nhở. Khóa API được lưu trữ dưới dạng mã hóa và không bao giờ được API trả về.",
- "configuredLeaveBlankToKeep": "Đã cấu hình ✓ (để trống để giữ)",
- "eGGpt4o": "ví dụ. gpt-4o",
"enableAiAssistant": "Kích hoạt trợ lý AI",
- "endpointOptional": "Điểm cuối (tùy chọn)",
- "model": "Người mẫu",
- "pasteYourApiKey": "Dán khóa API của bạn",
"perConversationCostCeilingUsd": "Mức trần chi phí cho mỗi cuộc trò chuyện (USD)",
- "provider": "nhà cung cấp",
- "redactPiiFromMessagesToolOutput": "Sắp xếp lại PII từ thông báo và đầu ra công cụ",
- "selectAProvider": "Chọn nhà cung cấp…"
+ "redactPiiFromMessagesToolOutput": "Sắp xếp lại PII từ thông báo và đầu ra công cụ"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "Bảng quản lý máy chủ hiện đại, gọn nhẹ để quản lý các ứng dụng web, cơ sở dữ liệu, miền, v.v. Được xây dựng với Flask và React.",
diff --git a/frontend/src/i18n/locales/zh-Hans.json b/frontend/src/i18n/locales/zh-Hans.json
index 589e3eb8..450d337e 100644
--- a/frontend/src/i18n/locales/zh-Hans.json
+++ b/frontend/src/i18n/locales/zh-Hans.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "需要管理员访问权限。",
"aiAssistant": "AI 助手",
- "apiKey": "API 密钥",
"blockPromptInjectionAttempts": "阻止提示注入尝试",
"configureTheInPanelAssistantPowered": "配置面板内助手 — 由 Prompture 提供支持。 API 密钥以加密方式存储,并且 API 绝不会返回。",
- "configuredLeaveBlankToKeep": "已配置 ✓(留空保留)",
- "eGGpt4o": "例如GPT-4O",
"enableAiAssistant": "启用AI助手",
- "endpointOptional": "端点(可选)",
- "model": "模型",
- "pasteYourApiKey": "粘贴您的 API 密钥",
"perConversationCostCeilingUsd": "每次对话成本上限(美元)",
- "provider": "提供商",
- "redactPiiFromMessagesToolOutput": "从消息和工具输出中编辑 PII",
- "selectAProvider": "选择提供商..."
+ "redactPiiFromMessagesToolOutput": "从消息和工具输出中编辑 PII"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "一个现代、轻量级的服务器管理面板,用于管理 Web 应用程序、数据库、域等。使用 Flask 和 React 构建。",
diff --git a/frontend/src/i18n/locales/zh-Hant.json b/frontend/src/i18n/locales/zh-Hant.json
index ba4f64f2..87b88925 100644
--- a/frontend/src/i18n/locales/zh-Hant.json
+++ b/frontend/src/i18n/locales/zh-Hant.json
@@ -3,19 +3,11 @@
"aISettingsTab": {
"adminAccessRequired": "需要管理員存取權限。",
"aiAssistant": "人工智慧助手",
- "apiKey": "API鑰匙",
"blockPromptInjectionAttempts": "阻止提示注入嘗試",
"configureTheInPanelAssistantPowered": "配置面板內助理 — 由 Prompture 提供支援。 API 金鑰以加密方式存儲,並且不會由 API 傳回。",
- "configuredLeaveBlankToKeep": "已配置 ✓(留空保留)",
- "eGGpt4o": "例如GPT-4O",
"enableAiAssistant": "啟用AI助手",
- "endpointOptional": "端點(可選)",
- "model": "模型",
- "pasteYourApiKey": "貼上您的 API 金鑰",
"perConversationCostCeilingUsd": "每次對話成本上限(美元)",
- "provider": "提供者",
- "redactPiiFromMessagesToolOutput": "從訊息和工具輸出編輯 PII",
- "selectAProvider": "選擇提供者..."
+ "redactPiiFromMessagesToolOutput": "從訊息和工具輸出編輯 PII"
},
"aboutTab": {
"aModernLightweightServerManagementPanel": "一個現代、輕量級的伺服器管理面板,用於管理 Web 應用程式、資料庫、網域等。採用 Flask 和 React 建構。",
diff --git a/frontend/src/services/api/ai.js b/frontend/src/services/api/ai.js
index ef3f95c8..87885061 100644
--- a/frontend/src/services/api/ai.js
+++ b/frontend/src/services/api/ai.js
@@ -29,6 +29,23 @@ export async function aiGetProviders() {
return this.request('/ai/providers');
}
+export async function aiGetConnections() {
+ return this.request('/ai/connections');
+}
+
+export async function aiSaveConnection(body) {
+ const path = body.id ? `/ai/connections/${encodeURIComponent(body.id)}` : '/ai/connections';
+ return this.request(path, { method: body.id ? 'PUT' : 'POST', body });
+}
+
+export async function aiDeleteConnection(id) {
+ return this.request(`/ai/connections/${encodeURIComponent(id)}`, { method: 'DELETE' });
+}
+
+export async function aiProbeConnection(body) {
+ return this.request('/ai/connections/probe', { method: 'POST', body });
+}
+
export async function aiGetModels(provider) {
return this.request(`/ai/models?provider=${encodeURIComponent(provider)}`);
}
diff --git a/frontend/src/styles/components/_ai-assistant.scss b/frontend/src/styles/components/_ai-assistant.scss
index b37cf9f4..e31abc6a 100644
--- a/frontend/src/styles/components/_ai-assistant.scss
+++ b/frontend/src/styles/components/_ai-assistant.scss
@@ -5,6 +5,24 @@
$sk-ai-z: 1100;
+.sk-ai-connection-selector {
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ gap: $spacing-sm;
+ padding: $spacing-sm $spacing-md;
+ border-block-end: 1px solid $border-color;
+
+ .form-field {
+ min-inline-size: 0;
+ margin-block-end: 0;
+ }
+
+ input, select {
+ inline-size: 100%;
+ min-inline-size: 0;
+ }
+}
+
%sk-ai-tokens {
--sk-ai-bg: var(--bg-card, #{$bg-card-raw});
--sk-ai-bg-body: var(--bg-body, #{$bg-body-raw});