This commit is contained in:
Timothy Jaeryang Baek
2026-03-15 17:21:14 -05:00
parent 7611762e04
commit bc5b3ec6b8
+59 -27
View File
@@ -653,19 +653,35 @@ async def get_tools_valves_by_id(
id: str, user=Depends(get_verified_user), db: Session = Depends(get_session) id: str, user=Depends(get_verified_user), db: Session = Depends(get_session)
): ):
tools = Tools.get_tool_by_id(id, db=db) tools = Tools.get_tool_by_id(id, db=db)
if tools: if not tools:
try: raise HTTPException(
valves = Tools.get_tool_valves_by_id(id, db=db) status_code=status.HTTP_404_NOT_FOUND,
return valves detail=ERROR_MESSAGES.NOT_FOUND,
except Exception as e: )
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, if (
detail=ERROR_MESSAGES.DEFAULT(str(e)), tools.user_id != user.id
) and not AccessGrants.has_access(
else: user_id=user.id,
resource_type="tool",
resource_id=tools.id,
permission="write",
db=db,
)
and user.role != "admin"
):
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.NOT_FOUND, detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
)
try:
valves = Tools.get_tool_valves_by_id(id, db=db)
return valves
except Exception as e:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=ERROR_MESSAGES.DEFAULT(str(e)),
) )
@@ -682,26 +698,42 @@ async def get_tools_valves_spec_by_id(
db: Session = Depends(get_session), db: Session = Depends(get_session),
): ):
tools = Tools.get_tool_by_id(id, db=db) tools = Tools.get_tool_by_id(id, db=db)
if tools: if not tools:
if id in request.app.state.TOOLS:
tools_module = request.app.state.TOOLS[id]
else:
tools_module, _ = load_tool_module_by_id(id)
request.app.state.TOOLS[id] = tools_module
if hasattr(tools_module, "Valves"):
Valves = tools_module.Valves
schema = Valves.schema()
# Resolve dynamic options for select dropdowns
schema = resolve_valves_schema_options(Valves, schema, user)
return schema
return None
else:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_404_NOT_FOUND,
detail=ERROR_MESSAGES.NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND,
) )
if (
tools.user_id != user.id
and not AccessGrants.has_access(
user_id=user.id,
resource_type="tool",
resource_id=tools.id,
permission="write",
db=db,
)
and user.role != "admin"
):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
)
if id in request.app.state.TOOLS:
tools_module = request.app.state.TOOLS[id]
else:
tools_module, _ = load_tool_module_by_id(id)
request.app.state.TOOLS[id] = tools_module
if hasattr(tools_module, "Valves"):
Valves = tools_module.Valves
schema = Valves.schema()
# Resolve dynamic options for select dropdowns
schema = resolve_valves_schema_options(Valves, schema, user)
return schema
return None
############################ ############################
# UpdateToolValves # UpdateToolValves