Skip to content

Commit 7628ced

Browse files
authored
Merge pull request #155 from kortix-ai/fix/billing
v1 Fix/billing
2 parents b784007 + b7b7eeb commit 7628ced

40 files changed

+2050
-2843
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ cython_debug/
162162
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163163
#.idea/
164164

165-
# AgentPress
166165
/threads
167166
state.json
168167
/workspace/

backend/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ cython_debug/
163163
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164164
#.idea/
165165

166-
# AgentPress
167166
/threads
168167
state.json
169168
/workspace/

backend/agent/api.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from services.supabase import DBConnection
1616
from services import redis
1717
from agent.run import run_agent
18-
from utils.auth_utils import get_current_user_id, get_user_id_from_stream_auth, verify_thread_access
18+
from utils.auth_utils import get_current_user_id_from_jwt, get_user_id_from_stream_auth, verify_thread_access
1919
from utils.logger import logger
20-
from utils.billing import check_billing_status, get_account_id_from_thread
20+
from services.billing import check_billing_status
2121
from sandbox.sandbox import create_sandbox, get_or_start_sandbox
2222
from services.llm import make_llm_api_call
2323

@@ -348,7 +348,7 @@ async def get_or_create_project_sandbox(client, project_id: str):
348348
async def start_agent(
349349
thread_id: str,
350350
body: AgentStartRequest = Body(...),
351-
user_id: str = Depends(get_current_user_id)
351+
user_id: str = Depends(get_current_user_id_from_jwt)
352352
):
353353
"""Start an agent for a specific thread in the background."""
354354
global instance_id # Ensure instance_id is accessible
@@ -412,7 +412,7 @@ async def start_agent(
412412
return {"agent_run_id": agent_run_id, "status": "running"}
413413

414414
@router.post("/agent-run/{agent_run_id}/stop")
415-
async def stop_agent(agent_run_id: str, user_id: str = Depends(get_current_user_id)):
415+
async def stop_agent(agent_run_id: str, user_id: str = Depends(get_current_user_id_from_jwt)):
416416
"""Stop a running agent."""
417417
logger.info(f"Received request to stop agent run: {agent_run_id}")
418418
client = await db.client
@@ -421,7 +421,7 @@ async def stop_agent(agent_run_id: str, user_id: str = Depends(get_current_user_
421421
return {"status": "stopped"}
422422

423423
@router.get("/thread/{thread_id}/agent-runs")
424-
async def get_agent_runs(thread_id: str, user_id: str = Depends(get_current_user_id)):
424+
async def get_agent_runs(thread_id: str, user_id: str = Depends(get_current_user_id_from_jwt)):
425425
"""Get all agent runs for a thread."""
426426
logger.info(f"Fetching agent runs for thread: {thread_id}")
427427
client = await db.client
@@ -431,7 +431,7 @@ async def get_agent_runs(thread_id: str, user_id: str = Depends(get_current_user
431431
return {"agent_runs": agent_runs.data}
432432

433433
@router.get("/agent-run/{agent_run_id}")
434-
async def get_agent_run(agent_run_id: str, user_id: str = Depends(get_current_user_id)):
434+
async def get_agent_run(agent_run_id: str, user_id: str = Depends(get_current_user_id_from_jwt)):
435435
"""Get agent run status and responses."""
436436
logger.info(f"Fetching agent run details: {agent_run_id}")
437437
client = await db.client
@@ -859,7 +859,7 @@ async def initiate_agent_with_files(
859859
stream: Optional[bool] = Form(True),
860860
enable_context_manager: Optional[bool] = Form(False),
861861
files: List[UploadFile] = File(default=[]),
862-
user_id: str = Depends(get_current_user_id)
862+
user_id: str = Depends(get_current_user_id_from_jwt)
863863
):
864864
"""Initiate a new agent session with optional file attachments."""
865865
global instance_id # Ensure instance_id is accessible

backend/agent/run.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
from agent.tools.data_providers_tool import DataProvidersTool
2121
from agent.prompt import get_system_prompt
2222
from utils import logger
23-
from utils.billing import check_billing_status, get_account_id_from_thread
23+
from utils.auth_utils import get_account_id_from_thread
24+
from services.billing import check_billing_status
2425

2526
load_dotenv()
2627

backend/api.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# Import the agent API module
1717
from agent import api as agent_api
1818
from sandbox import api as sandbox_api
19+
from services import billing as billing_api
1920

2021
# Load environment variables (these will be available through config)
2122
load_dotenv()
@@ -132,6 +133,9 @@ async def log_requests_middleware(request: Request, call_next):
132133
# Include the sandbox router with a prefix
133134
app.include_router(sandbox_api.router, prefix="/api")
134135

136+
# Include the billing router with a prefix
137+
app.include_router(billing_api.router, prefix="/api")
138+
135139
@app.get("/api/health")
136140
async def health_check():
137141
"""Health check endpoint to verify API is working."""
@@ -152,5 +156,6 @@ async def health_check():
152156
"api:app",
153157
host="0.0.0.0",
154158
port=8000,
155-
workers=workers
159+
workers=workers,
160+
reload=True
156161
)

backend/poetry.lock

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ nest-asyncio = "^1.6.0"
5050
vncdotool = "^1.2.0"
5151
tavily-python = "^0.5.4"
5252
pytesseract = "^0.3.13"
53+
stripe = "^12.0.1"
5354

5455
[tool.poetry.scripts]
5556
agentpress = "agentpress.cli:main"
5657

5758
[[tool.poetry.packages]]
5859
include = "agentpress"
5960

60-
6161
[tool.poetry.group.dev.dependencies]
6262
daytona-sdk = "^0.14.0"
6363

backend/sandbox/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pydantic import BaseModel
77

88
from utils.logger import logger
9-
from utils.auth_utils import get_current_user_id, get_user_id_from_stream_auth, get_optional_user_id
9+
from utils.auth_utils import get_current_user_id_from_jwt, get_user_id_from_stream_auth, get_optional_user_id
1010
from sandbox.sandbox import get_or_start_sandbox
1111
from services.supabase import DBConnection
1212
from agent.api import get_or_create_project_sandbox

0 commit comments

Comments
 (0)