Skip to content

Commit 5966882

Browse files
authored
Merge branch 'main' into feat/dockerize
2 parents 7a785ca + 3ba0d79 commit 5966882

31 files changed

Lines changed: 857 additions & 72 deletions

backend/MIGRATIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Database Migrations Guide
22

3-
This guide explains how to work with database migrations in SyftAI Server. Whether you're new to migrations or just new to this project, this document will help you get started.
3+
This guide explains how to work with database migrations in Syft Space. Whether you're new to migrations or just new to this project, this document will help you get started.
44

55
## What Are Migrations?
66

backend/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Syft AI Server
1+
# Syft Space
22

33
A powerful RAG (Retrieval-Augmented Generation) platform that enables you to create, manage, and query AI-powered endpoints backed by vector databases and language models.
44

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "syftai_space"
77
version = "0.1.0"
8-
description = "Syft AI Server Backend API"
8+
description = "Syft Space Backend API"
99
authors = [
1010
{name = "OpenMined", email = "support@openmined.org"}
1111
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Components package for syftai-server."""
1+
"""Components package for Syft Space."""

backend/syftai_space/components/auth/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AdminKeyMiddleware(BaseHTTPMiddleware):
1818
All other routes require Authorization: Bearer <key> header.
1919
"""
2020

21-
STATIC_PUBLIC_PATHS = ["/docs", "/redoc", "/openapi.json", "/syftai-server"]
21+
STATIC_PUBLIC_PATHS = ["/docs", "/redoc", "/openapi.json", "/frontend"]
2222
STATIC_PUBLIC_EXACT = ["/"]
2323

2424
async def dispatch(

backend/syftai_space/components/endpoints/handlers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ def _publish_to_marketplace(
587587
for policy in endpoint.policies
588588
]
589589
connection_config = {
590-
"host": "localhost:8080",
591590
"path": f"/api/v1/endpoints/{endpoint.slug}/query",
592591
}
593592

backend/syftai_space/components/policy_types/accounting/accounting_type.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def pre_hook(
182182
credentials = AccountingCredentials.from_context(context)
183183
amount = config.price
184184

185+
transaction = None
185186
try:
186187
transaction = self._create_transaction(
187188
credentials,
@@ -193,6 +194,9 @@ def pre_hook(
193194
transactions.append({"id": transaction.id, "amount": amount})
194195
total_amount += amount
195196
except Exception as e:
197+
if transaction:
198+
self._cancel_transaction(credentials, transaction.id)
199+
196200
raise PolicyViolationError(
197201
message=f"Failed to create accounting transaction: {e}",
198202
policy_type=self.NAME,
@@ -221,7 +225,7 @@ def _create_transaction(
221225
return accounting_client.create_delegated_transaction(
222226
senderEmail=sender_email,
223227
amount=amount,
224-
transaction_token=transaction_token,
228+
token=transaction_token,
225229
appEpPath=endpoint_slug,
226230
)
227231

@@ -259,6 +263,9 @@ def post_hook(
259263
try:
260264
self._confirm_transaction(credentials, transaction["id"])
261265
except Exception as e:
266+
if transaction.get("id"):
267+
self._cancel_transaction(credentials, transaction["id"])
268+
262269
raise PolicyViolationError(
263270
message=f"Failed to confirm accounting transaction: {e}",
264271
policy_type=self.NAME,
@@ -277,6 +284,17 @@ def post_hook(
277284

278285
return context
279286

287+
def _cancel_transaction(
288+
self, credentials: AccountingCredentials, transaction_id: str
289+
) -> None:
290+
"""Cancel a transaction with the accounting service."""
291+
accounting_client = UserClient(
292+
url=str(credentials.url),
293+
email=str(credentials.email),
294+
password=credentials.password,
295+
)
296+
accounting_client.cancel_transaction(id=transaction_id)
297+
280298
def _confirm_transaction(
281299
self, credentials: AccountingCredentials, transaction_id: str
282300
) -> None:

backend/syftai_space/components/settings/entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class Settings(SQLModel, table=True):
1212

1313
id: int = Field(default=1, primary_key=True)
1414
public_url: str | None = Field(
15-
default=None, description="Public URL for the SyftAI Space"
15+
default=None, description="Public URL for the Syft Space"
1616
)
1717
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))

backend/syftai_space/components/settings/handlers.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""Settings handlers for business logic."""
22

33
from fastapi import HTTPException
4+
from loguru import logger
45
from pydantic import HttpUrl
56

67
from syftai_space.components.marketplaces.handlers import MarketplaceHandler
78
from syftai_space.components.settings.repository import SettingsRepository
89
from syftai_space.components.settings.schemas import PublicUrlResponse
910
from syftai_space.components.shared.syfthub_client import SyftHubClient, SyftHubError
1011
from syftai_space.components.tenants.entities import Tenant
11-
from syftai_space.config import AppSettings
12+
from syftai_space.config import app_settings
1213

1314

1415
class SettingsHandler:
@@ -18,7 +19,6 @@ def __init__(
1819
self,
1920
settings_repository: SettingsRepository,
2021
marketplace_handler: MarketplaceHandler,
21-
config: AppSettings,
2222
) -> None:
2323
"""Initialize the settings handler.
2424
@@ -29,7 +29,6 @@ def __init__(
2929
"""
3030
self.settings_repository = settings_repository
3131
self.marketplace_handler = marketplace_handler
32-
self.config = config
3332

3433
def get_public_url(self) -> PublicUrlResponse:
3534
"""Get the current public URL from database (source of truth).
@@ -66,6 +65,9 @@ def update_public_url(
6665
# Sync to SyftHub if marketplace is configured
6766
try:
6867
marketplace = self.marketplace_handler.get_default_marketplace(tenant)
68+
logger.info(
69+
f"Updating public URL to {url_str} for marketplace {marketplace.url}"
70+
)
6971
with SyftHubClient(str(marketplace.url)) as syfthub:
7072
syfthub.login(marketplace.email, marketplace.password)
7173
syfthub.update_profile(domain=url_str)
@@ -81,12 +83,16 @@ def update_public_url(
8183
detail=f"Failed to sync public URL to marketplace: {e.message}",
8284
) from e
8385

86+
app_settings.public_url = HttpUrl(url_str) if url_str else None
8487
return PublicUrlResponse(public_url=url_str)
8588

86-
def initialize_from_config(self) -> None:
89+
def initialize_from_config(self, tenants: list[Tenant]) -> None:
8790
"""Initialize settings from config on startup.
8891
8992
If SYFT_PUBLIC_URL env var is set, it overwrites the database value.
9093
"""
91-
if self.config.public_url:
92-
self.settings_repository.update_public_url(str(self.config.public_url))
94+
if not app_settings.public_url:
95+
return
96+
97+
for tenant in tenants:
98+
self.update_public_url(tenant, app_settings.public_url)

backend/syftai_space/components/shared/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Shared utilities and types for syftai-server."""
1+
"""Shared utilities and types for Syft Space."""
22

33
from .syfthub_client import SyftHubClient
44

0 commit comments

Comments
 (0)