diff --git a/src/backend/langflow/api/router.py b/src/backend/langflow/api/router.py index ae221435a..569014acf 100644 --- a/src/backend/langflow/api/router.py +++ b/src/backend/langflow/api/router.py @@ -12,6 +12,7 @@ from langflow.api.v1 import ( store_router, users_router, validate_router, + variables_router, ) router = APIRouter( diff --git a/src/backend/langflow/interface/custom/custom_component/custom_component.py b/src/backend/langflow/interface/custom/custom_component/custom_component.py index 1cc1a514c..d15622a61 100644 --- a/src/backend/langflow/interface/custom/custom_component/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component/custom_component.py @@ -1,7 +1,6 @@ import operator from pathlib import Path -from typing import (TYPE_CHECKING, Any, Callable, ClassVar, List, Optional, - Sequence, Union) +from typing import TYPE_CHECKING, Any, Callable, ClassVar, List, Optional, Sequence, Union from uuid import UUID import yaml @@ -12,14 +11,14 @@ from sqlmodel import select from langflow.interface.custom.code_parser.utils import ( extract_inner_type_from_generic_alias, - extract_union_types_from_generic_alias) + extract_union_types_from_generic_alias, +) from langflow.interface.custom.custom_component.component import Component from langflow.schema import Record from langflow.schema.dotdict import dotdict from langflow.services.database.models.flow import Flow from langflow.services.database.utils import session_getter from langflow.services.deps import get_db_service, get_storage_service, get_variable_service - get_variable_service) from langflow.services.storage.service import StorageService from langflow.utils import validate diff --git a/src/backend/langflow/services/database/models/variable/model.py b/src/backend/langflow/services/database/models/variable/model.py new file mode 100644 index 000000000..93b74b28e --- /dev/null +++ b/src/backend/langflow/services/database/models/variable/model.py @@ -0,0 +1,46 @@ +from datetime import UTC, datetime +from typing import TYPE_CHECKING, Optional +from uuid import UUID, uuid4 + +from sqlmodel import Field, Relationship, SQLModel + + +if TYPE_CHECKING: + from langflow.services.database.models.user.model import User + + +def utc_now(): + return datetime.now(UTC) + + +class VariableBase(SQLModel): + name: Optional[str] = Field(None, description="Name of the variable") + value: Optional[str] = Field(None, description="Encrypted value of the variable") + type: Optional[str] = Field(None, description="Type of the variable") + + +class Variable(VariableBase, table=True): + id: Optional[UUID] = Field(default_factory=uuid4, primary_key=True, description="Unique ID for the variable") + # name is unique per user + created_at: datetime = Field(default_factory=utc_now, description="Creation time of the variable") + updated_at: Optional[datetime] = Field(None, description="Last update time of the variable") + # foreign key to user table + user_id: UUID = Field(description="User ID associated with this variable", foreign_key="user.id") + user: "User" = Relationship(back_populates="variables") + + +class VariableCreate(VariableBase): + # AcceptedProviders is a custom Enum + type: Optional[str] = Field(None, description="Type of the variable") + + +class VariableRead(SQLModel): + id: UUID + name: Optional[str] = Field(None, description="Name of the variable") + type: Optional[str] = Field(None, description="Type of the variable") + + +class VariableUpdate(SQLModel): + id: UUID # Include the ID for updating + name: Optional[str] = Field(None, description="Name of the variable") + value: Optional[str] = Field(None, description="Encrypted value of the variable")