Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions python/valuecell/server/api/routers/strategy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ async def create_strategy_agent(
UserRequest JSON, and returns an aggregated JSON response (non-SSE).
"""
try:
# Helper: dump request config without sensitive credentials
def _safe_config_dump(req: UserRequest) -> dict:
return req.model_dump(
exclude={
"exchange_config": {
"api_key",
"secret_key",
"passphrase",
"wallet_address",
"private_key",
}
}
)

# Ensure we only serialize the core UserRequest fields, excluding conversation_id
user_request = UserRequest(
llm_model_config=request.llm_model_config,
Expand Down Expand Up @@ -188,7 +202,7 @@ async def create_strategy_agent(
description=None,
user_id=user_input_meta.user_id,
status=status.value,
config=request.model_dump(),
config=_safe_config_dump(request),
metadata=metadata,
)
except Exception:
Expand All @@ -205,16 +219,18 @@ async def create_strategy_agent(
code=StatusCode.INTERNAL_ERROR,
msg="No status event from orchestrator",
)
except Exception as exc:
# Orchestrator failed; do NOT persist or fallback, return error only
except Exception:
# Orchestrator failed; do NOT persist or fallback, return generic error only
return ErrorResponse.create(
code=StatusCode.INTERNAL_ERROR, msg=str(exc)
code=StatusCode.INTERNAL_ERROR, msg="Internal error"
)

except Exception as e:
# As a last resort, log the exception and return error without persistence or fallback.
logger.exception(f"Failed to create strategy in API endpoint: {e}")
return ErrorResponse.create(code=StatusCode.INTERNAL_ERROR, msg=str(e))
except Exception:
# As a last resort, log without sensitive details and return generic error.
logger.exception("Failed to create strategy in API endpoint")
return ErrorResponse.create(
code=StatusCode.INTERNAL_ERROR, msg="Internal error"
)

@router.post("/test-connection")
async def test_exchange_connection(request: ExchangeConfig):
Expand Down Expand Up @@ -256,11 +272,11 @@ async def test_exchange_connection(request: ExchangeConfig):
finally:
await gateway.close()

except Exception as e:
# If create_ccxt_gateway fails or other error
logger.warning(f"Connection test failed: {e}")
except Exception:
# If create_ccxt_gateway fails or other error, avoid logging sensitive info
logger.warning("Connection test failed")
raise HTTPException(
status_code=400, detail=f"Failed, please check your API key: {str(e)}"
status_code=400, detail="Failed, please check your API key"
)

@router.delete("/delete")
Expand Down