|
@@ -54,6 +54,22 @@ class FunctionModel(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
|
|
|
|
|
|
+class FunctionWithValvesModel(BaseModel):
|
|
|
|
+ id: str
|
|
|
|
+ user_id: str
|
|
|
|
+ name: str
|
|
|
|
+ type: str
|
|
|
|
+ content: str
|
|
|
|
+ meta: FunctionMeta
|
|
|
|
+ valves: Optional[dict] = None
|
|
|
|
+ is_active: bool = False
|
|
|
|
+ is_global: bool = False
|
|
|
|
+ updated_at: int # timestamp in epoch
|
|
|
|
+ created_at: int # timestamp in epoch
|
|
|
|
+
|
|
|
|
+ model_config = ConfigDict(from_attributes=True)
|
|
|
|
+
|
|
|
|
+
|
|
####################
|
|
####################
|
|
# Forms
|
|
# Forms
|
|
####################
|
|
####################
|
|
@@ -111,8 +127,8 @@ class FunctionsTable:
|
|
return None
|
|
return None
|
|
|
|
|
|
def sync_functions(
|
|
def sync_functions(
|
|
- self, user_id: str, functions: list[FunctionModel]
|
|
|
|
- ) -> list[FunctionModel]:
|
|
|
|
|
|
+ self, user_id: str, functions: list[FunctionWithValvesModel]
|
|
|
|
+ ) -> list[FunctionWithValvesModel]:
|
|
# Synchronize functions for a user by updating existing ones, inserting new ones, and removing those that are no longer present.
|
|
# Synchronize functions for a user by updating existing ones, inserting new ones, and removing those that are no longer present.
|
|
try:
|
|
try:
|
|
with get_db() as db:
|
|
with get_db() as db:
|
|
@@ -166,17 +182,24 @@ class FunctionsTable:
|
|
except Exception:
|
|
except Exception:
|
|
return None
|
|
return None
|
|
|
|
|
|
- def get_functions(self, active_only=False) -> list[FunctionModel]:
|
|
|
|
|
|
+ def get_functions(
|
|
|
|
+ self, active_only=False, include_valves=False
|
|
|
|
+ ) -> list[FunctionModel | FunctionWithValvesModel]:
|
|
with get_db() as db:
|
|
with get_db() as db:
|
|
if active_only:
|
|
if active_only:
|
|
|
|
+ functions = db.query(Function).filter_by(is_active=True).all()
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ functions = db.query(Function).all()
|
|
|
|
+
|
|
|
|
+ if include_valves:
|
|
return [
|
|
return [
|
|
- FunctionModel.model_validate(function)
|
|
|
|
- for function in db.query(Function).filter_by(is_active=True).all()
|
|
|
|
|
|
+ FunctionWithValvesModel.model_validate(function)
|
|
|
|
+ for function in functions
|
|
]
|
|
]
|
|
else:
|
|
else:
|
|
return [
|
|
return [
|
|
- FunctionModel.model_validate(function)
|
|
|
|
- for function in db.query(Function).all()
|
|
|
|
|
|
+ FunctionModel.model_validate(function) for function in functions
|
|
]
|
|
]
|
|
|
|
|
|
def get_functions_by_type(
|
|
def get_functions_by_type(
|