4e076c36d2
1. Built-in tool type seeding (apps/api/src/seeds/builtin_tool_types.py):
- Seeds code-server, jupyter-notebook, and opencode on startup.
- Adapts to current dev model: uses interface_type (single string)
instead of interfaces array, and created_by_id=None instead of
is_builtin flag.
- Called from main.py startup event.
2. Config profile default management:
- Adds default_profile_id and default_profiles properties to
UserConfig model for JSON-backed per-tool-type defaults.
- Adds GET /config-profiles/defaults, PUT /config-profiles/defaults,
and GET /config-profiles/defaults/{tool_type_id} endpoints.
- Validates that all profile IDs in default mappings belong to the
authenticated user before persisting.
3. Config profile unique constraint:
- Adds __table_args__ with UniqueConstraint(user_id, name) to
ConfigProfile model. The constraint already exists in the DB
from migration 2026_05_24_add_config_profiles.py; this just
aligns the SQLAlchemy model with the schema.
Quality gates: py_compile passed, ruff passed on all modified files.
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import uuid
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import ForeignKey, JSON
|
|
from sqlalchemy import Uuid as UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from src.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
|
|
|
|
if TYPE_CHECKING:
|
|
from src.models.user import User
|
|
|
|
|
|
class UserConfig(UUIDPrimaryKeyMixin, TimestampMixin, Base):
|
|
__tablename__ = "user_configs"
|
|
|
|
user_id: Mapped[uuid.UUID] = mapped_column(UUID(), ForeignKey("users.id"), nullable=False, unique=True)
|
|
config: Mapped[dict[str, object]] = mapped_column(JSON, default=dict, nullable=False)
|
|
|
|
user: Mapped["User"] = relationship(back_populates="user_config")
|
|
|
|
@property
|
|
def default_profile_id(self) -> uuid.UUID | None:
|
|
"""Return the legacy global default profile ID from config JSON."""
|
|
profile_id = self.config.get("default_profile_id")
|
|
if isinstance(profile_id, str):
|
|
return uuid.UUID(profile_id)
|
|
return None
|
|
|
|
@default_profile_id.setter
|
|
def default_profile_id(self, value: uuid.UUID | None) -> None:
|
|
if value is not None:
|
|
self.config["default_profile_id"] = str(value)
|
|
elif "default_profile_id" in self.config:
|
|
del self.config["default_profile_id"]
|
|
|
|
@property
|
|
def default_profiles(self) -> dict[str, str]:
|
|
"""Return per-tool-type default profile IDs from config JSON."""
|
|
value = self.config.get("default_profiles", {})
|
|
if isinstance(value, dict):
|
|
return {str(k): str(v) for k, v in value.items()}
|
|
return {}
|
|
|
|
@default_profiles.setter
|
|
def default_profiles(self, value: dict[str, str]) -> None:
|
|
self.config["default_profiles"] = value
|