from fastapi import FastAPI,Request,HTTPException,Response from pydantic import BaseModel from fastapi.responses import JSONResponse from components.mongodbconnection import provideClient from components.agentcreation import VelocityPayableAgent from components.agentcreation import load_keypair from fastapi.middleware.cors import CORSMiddleware app=FastAPI() origins=["*"] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) client=provideClient() db=client["agentpaymentdb"] coll=db["agentpaymentcol"] class Agent(BaseModel): agent_id:str class Payment(BaseModel): instruction:str @app.post("/init_agent") async def AgentI(request:Agent): try: velocitypayableinstance=VelocityPayableAgent() await velocitypayableinstance.Agentinit(request.agent_id) return {"status_":True} except Exception as e: print(e) return {"status_":False} @app.post("/payment") async def PaymentInstruction(request:Payment): try: velocitypayableinstance=VelocityPayableAgent() output=velocitypayableinstance.Agent(request.instruction) return {"status_":output} except error: return {"status_":False} @app.get("/agent/{id}") def getAgentKey(id): pkey=load_keypair(id) return {"wallet":pkey}