feat(aiturk): connect shared media MCP with the member provider key
This commit is contained in:
@@ -25,7 +25,7 @@ export function aiturkInstallStage(name: string): string | undefined {
|
|||||||
|
|
||||||
const en = {
|
const en = {
|
||||||
intro: 'Bring your code, question, or idea. Build with AITURK.',
|
intro: 'Bring your code, question, or idea. Build with AITURK.',
|
||||||
pitch: 'Connect your models with your TurkServis account.',
|
pitch: 'Connect your models and available image and audio tools with your TurkServis account.',
|
||||||
key: 'TurkServis API key',
|
key: 'TurkServis API key',
|
||||||
getKey: 'My account and API keys',
|
getKey: 'My account and API keys',
|
||||||
noModels: 'No models are available for this key.',
|
noModels: 'No models are available for this key.',
|
||||||
@@ -74,7 +74,7 @@ const en = {
|
|||||||
|
|
||||||
const tr: typeof en = {
|
const tr: typeof en = {
|
||||||
intro: 'Kodunuzu, sorunuzu veya fikrinizi paylaşın. AITURK ile birlikte geliştirin.',
|
intro: 'Kodunuzu, sorunuzu veya fikrinizi paylaşın. AITURK ile birlikte geliştirin.',
|
||||||
pitch: 'TurkServis hesabınızla modellerinize bağlanın.',
|
pitch: 'TurkServis hesabınızla modellerinize, kullanılabilir görsel ve ses araçlarına bağlanın.',
|
||||||
key: 'TurkServis API anahtarı',
|
key: 'TurkServis API anahtarı',
|
||||||
getKey: 'Hesabım ve API anahtarlarım',
|
getKey: 'Hesabım ve API anahtarlarım',
|
||||||
noModels: 'Bu anahtarla kullanılabilecek model bulunamadı.',
|
noModels: 'Bu anahtarla kullanılabilecek model bulunamadı.',
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
"""Connect the AITURK distribution's media tools to its existing member key."""
|
||||||
|
|
||||||
|
|
||||||
|
def configure_media(cfg: dict, entry: dict) -> bool:
|
||||||
|
if entry.get("base_url", "").rstrip("/") != "https://ai.turkservis.online/v1":
|
||||||
|
return False
|
||||||
|
key_env = entry.get("key_env")
|
||||||
|
if not isinstance(key_env, str) or not key_env:
|
||||||
|
return False
|
||||||
|
servers = cfg.get("mcp_servers")
|
||||||
|
if servers is None:
|
||||||
|
servers = cfg["mcp_servers"] = {}
|
||||||
|
if not isinstance(servers, dict):
|
||||||
|
return False
|
||||||
|
name = "turkservis-media"
|
||||||
|
existing = servers.get(name, {})
|
||||||
|
if not isinstance(existing, dict):
|
||||||
|
return False
|
||||||
|
if existing and existing.get("url") != "https://ai.turkservis.online/mcp":
|
||||||
|
return False
|
||||||
|
updated = {
|
||||||
|
**existing,
|
||||||
|
"url": "https://ai.turkservis.online/mcp",
|
||||||
|
"headers": {"Authorization": "Bearer ${" + key_env + "}"},
|
||||||
|
"timeout": 300,
|
||||||
|
"tools": {"include": ["list_capabilities", "generate_media"]},
|
||||||
|
}
|
||||||
|
if updated == existing:
|
||||||
|
return False
|
||||||
|
servers[name] = updated
|
||||||
|
return True
|
||||||
@@ -8823,6 +8823,9 @@ def _write_custom_endpoint(cfg: Dict[str, Any], body: CustomEndpointUpdate) -> T
|
|||||||
providers[endpoint_id] = entry
|
providers[endpoint_id] = entry
|
||||||
cfg["providers"] = providers
|
cfg["providers"] = providers
|
||||||
|
|
||||||
|
from hermes_cli.aiturk_media import configure_media
|
||||||
|
configure_media(cfg, entry)
|
||||||
|
|
||||||
if body.make_default:
|
if body.make_default:
|
||||||
cfg["model"] = _apply_main_model_assignment(
|
cfg["model"] = _apply_main_model_assignment(
|
||||||
cfg.get("model", {}), endpoint_id, model, base_url
|
cfg.get("model", {}), endpoint_id, model, base_url
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from hermes_cli.aiturk_media import configure_media
|
||||||
|
|
||||||
|
|
||||||
|
def test_member_key_is_referenced_without_copying_or_overwriting_other_servers():
|
||||||
|
cfg = {"mcp_servers": {"other": {"url": "https://example.org/mcp"}}}
|
||||||
|
entry = {"base_url": "https://ai.turkservis.online/v1", "key_env": "HERMES_CUSTOM_TURKSERVIS_API_KEY"}
|
||||||
|
assert configure_media(cfg, entry)
|
||||||
|
assert cfg["mcp_servers"]["other"] == {"url": "https://example.org/mcp"}
|
||||||
|
assert cfg["mcp_servers"]["turkservis-media"]["headers"]["Authorization"] == "Bearer ${HERMES_CUSTOM_TURKSERVIS_API_KEY}"
|
||||||
|
assert not configure_media(cfg, entry)
|
||||||
|
entry["key_env"] = "ROTATED_MEMBER_KEY"
|
||||||
|
assert configure_media(cfg, entry)
|
||||||
|
assert "ROTATED_MEMBER_KEY" in cfg["mcp_servers"]["turkservis-media"]["headers"]["Authorization"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_other_provider_and_missing_key_do_not_enable_media():
|
||||||
|
for entry in ({"base_url": "https://example.com/v1", "key_env": "SECRET"}, {"base_url": "https://ai.turkservis.online/v1"}):
|
||||||
|
cfg = {}
|
||||||
|
assert not configure_media(cfg, entry)
|
||||||
|
assert cfg == {}
|
||||||
|
|
||||||
|
|
||||||
|
def test_explicitly_disabled_connection_stays_disabled():
|
||||||
|
cfg = {"mcp_servers": {"turkservis-media": {"url": "https://ai.turkservis.online/mcp", "enabled": False}}}
|
||||||
|
configure_media(cfg, {"base_url": "https://ai.turkservis.online/v1", "key_env": "KEY"})
|
||||||
|
assert cfg["mcp_servers"]["turkservis-media"]["enabled"] is False
|
||||||
Reference in New Issue
Block a user