Merge gitea/main, preserving security fixes and current dependency versions

This commit is contained in:
AITBC System
2026-03-24 16:18:25 +01:00
252 changed files with 18525 additions and 1029 deletions

View File

@@ -1,7 +1,7 @@
APP_ENV=dev
APP_HOST=127.0.0.1
APP_PORT=8011
DATABASE_URL=sqlite:///./data/coordinator.db
DATABASE_URL=sqlite:////opt/aitbc/data/coordinator.db
CLIENT_API_KEYS=${CLIENT_API_KEY},client_dev_key_2
MINER_API_KEYS=${MINER_API_KEY},miner_dev_key_2
ADMIN_API_KEYS=${ADMIN_API_KEY}

View File

@@ -8,7 +8,7 @@ import json
from decimal import Decimal
# Database configurations
SQLITE_DB = "coordinator.db"
SQLITE_DB = "/opt/aitbc/data/coordinator.db"
PG_CONFIG = {
"host": "localhost",
"database": "aitbc_coordinator",

View File

@@ -16,7 +16,7 @@ from decimal import Decimal
import json
# Database configurations
SQLITE_DB = "coordinator.db"
SQLITE_DB = "/opt/aitbc/data/coordinator.db"
PG_CONFIG = {
"host": "localhost",
"database": "aitbc_coordinator",

View File

@@ -30,7 +30,7 @@ class DatabaseConfig(BaseSettings):
# Default SQLite path - consistent with blockchain-node pattern
if self.adapter == "sqlite":
return "sqlite:///./data/coordinator.db"
return "sqlite:////opt/aitbc/data/coordinator.db"
# Default PostgreSQL connection string
return f"{self.adapter}://localhost:5432/coordinator"
@@ -187,7 +187,7 @@ class Settings(BaseSettings):
if self.database.url:
return self.database.url
# Default SQLite path - consistent with blockchain-node pattern
return "sqlite:///./data/coordinator.db"
return "sqlite:////opt/aitbc/data/coordinator.db"
@database_url.setter
def database_url(self, value: str):

View File

@@ -2,13 +2,14 @@
from sqlmodel import create_engine, SQLModel
from sqlalchemy import StaticPool
from .config import settings
# Create in-memory SQLite database for now
# Create database engine using URL from config
engine = create_engine(
"sqlite:///./data/coordinator.db",
connect_args={"check_same_thread": False},
poolclass=StaticPool,
echo=True # Enable SQL logging for debugging
settings.database_url,
connect_args={"check_same_thread": False} if settings.database_url.startswith("sqlite") else {},
poolclass=StaticPool if settings.database_url.startswith("sqlite") else None,
echo=settings.test_mode # Enable SQL logging for debugging in test mode
)

View File

@@ -48,7 +48,7 @@ async def blockchain_sync_status():
rpc_url = settings.blockchain_rpc_url.rstrip('/')
async with httpx.AsyncClient() as client:
response = await client.get(f"{rpc_url}/rpc/sync", timeout=5.0)
response = await client.get(f"{rpc_url}/rpc/syncStatus", timeout=5.0)
if response.status_code == 200:
data = response.json()
return {

View File

@@ -20,7 +20,7 @@ limiter = Limiter(key_func=get_remote_address)
router = APIRouter(tags=["marketplace"])
def _get_service(session: Annotated[Session, Depends(get_session)]) -> MarketplaceService:
def _get_service(session: Session = Depends(get_session)) -> MarketplaceService:
return MarketplaceService(session)
@@ -33,7 +33,7 @@ def _get_service(session: Annotated[Session, Depends(get_session)]) -> Marketpla
async def list_marketplace_offers(
request: Request,
*,
session: Annotated[Session, Depends(get_session)],
session: Session = Depends(get_session),
status_filter: str | None = Query(default=None, alias="status", description="Filter by offer status"),
limit: int = Query(default=100, ge=1, le=500),
offset: int = Query(default=0, ge=0),
@@ -60,7 +60,7 @@ async def list_marketplace_offers(
async def get_marketplace_stats(
request: Request,
*,
session: Annotated[Session, Depends(get_session)]
session: Session = Depends(get_session)
) -> MarketplaceStatsView:
marketplace_requests_total.labels(endpoint="/marketplace/stats", method="GET").inc()
service = _get_service(session)
@@ -80,7 +80,7 @@ async def get_marketplace_stats(
async def submit_marketplace_bid(
request: Request,
payload: MarketplaceBidRequest,
session: Annotated[Session, Depends(get_session)],
session: Session = Depends(get_session),
) -> dict[str, str]:
marketplace_requests_total.labels(endpoint="/marketplace/bids", method="POST").inc()
service = _get_service(session)
@@ -102,7 +102,7 @@ async def submit_marketplace_bid(
)
async def list_marketplace_bids(
*,
session: Annotated[Session, Depends(get_session)],
session: Session = Depends(get_session),
status_filter: str | None = Query(default=None, alias="status", description="Filter by bid status"),
provider_filter: str | None = Query(default=None, alias="provider", description="Filter by provider ID"),
limit: int = Query(default=100, ge=1, le=500),
@@ -127,7 +127,7 @@ async def list_marketplace_bids(
)
async def get_marketplace_bid(
bid_id: str,
session: Annotated[Session, Depends(get_session)],
session: Session = Depends(get_session),
) -> MarketplaceBidView:
marketplace_requests_total.labels(endpoint="/marketplace/bids/{bid_id}", method="GET").inc()
service = _get_service(session)

View File

@@ -50,7 +50,7 @@ class MarketplaceAnalyticsRequest(BaseModel):
async def create_royalty_distribution(
request: RoyaltyDistributionRequest,
offer_id: str,
session: Session = Depends(Annotated[Session, Depends(get_session)]),
session: Session = Depends(get_session),
current_user: str = Depends(require_admin_key())
):
"""Create royalty distribution for marketplace offer"""
@@ -74,7 +74,7 @@ async def create_royalty_distribution(
async def calculate_royalties(
offer_id: str,
sale_amount: float,
session: Session = Depends(Annotated[Session, Depends(get_session)]),
session: Session = Depends(get_session),
current_user: str = Depends(require_admin_key())
):
"""Calculate royalties for a sale"""
@@ -97,7 +97,7 @@ async def calculate_royalties(
async def create_model_license(
request: ModelLicenseRequest,
offer_id: str,
session: Session = Depends(Annotated[Session, Depends(get_session)]),
session: Session = Depends(get_session),
current_user: str = Depends(require_admin_key())
):
"""Create model license for marketplace offer"""
@@ -123,7 +123,7 @@ async def create_model_license(
async def verify_model(
request: ModelVerificationRequest,
offer_id: str,
session: Session = Depends(Annotated[Session, Depends(get_session)]),
session: Session = Depends(get_session),
current_user: str = Depends(require_admin_key())
):
"""Verify model quality and performance"""
@@ -145,7 +145,7 @@ async def verify_model(
@router.post("/analytics")
async def get_marketplace_analytics(
request: MarketplaceAnalyticsRequest,
session: Session = Depends(Annotated[Session, Depends(get_session)]),
session: Session = Depends(get_session),
current_user: str = Depends(require_admin_key())
):
"""Get marketplace analytics and insights"""

View File

@@ -6,7 +6,7 @@ Basic marketplace enhancement features compatible with existing domain models
import asyncio
from aitbc.logging import get_logger
from typing import Dict, List, Optional, Any
from datetime import datetime
from datetime import datetime, timedelta
from uuid import uuid4
from enum import Enum
@@ -225,12 +225,12 @@ class EnhancedMarketplaceService:
offers_query = select(MarketplaceOffer).where(
MarketplaceOffer.created_at >= start_date
)
offers = self.session.execute(offers_query).all()
offers = self.session.execute(offers_query).scalars().all()
bids_query = select(MarketplaceBid).where(
MarketplaceBid.created_at >= start_date
MarketplaceBid.submitted_at >= start_date
)
bids = self.session.execute(bids_query).all()
bids = self.session.execute(bids_query).scalars().all()
# Calculate analytics
analytics = {
@@ -264,7 +264,7 @@ class EnhancedMarketplaceService:
if "revenue" in metrics:
analytics["metrics"]["revenue"] = {
"total_revenue": sum(bid.amount or 0 for bid in bids),
"total_revenue": sum(bid.price or 0 for bid in bids),
"average_price": sum(offer.price or 0 for offer in offers) / len(offers) if offers else 0,
"revenue_growth": 0.12
}