Skip to content

Commit

Permalink
Merge branch 'dev' into zamilmajdy/secrt-999-charge-block-credits-pre…
Browse files Browse the repository at this point in the history
…-execution-as-opposed-to-post
  • Loading branch information
aarushik93 authored Nov 18, 2024
2 parents feb1e2f + f36d95a commit 3ceefc4
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 59 deletions.
9 changes: 7 additions & 2 deletions autogpt_platform/autogpt_libs/autogpt_libs/auth/depends.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fastapi

from .middleware import auth_middleware
from .models import User
from .models import User, DEFAULT_USER_ID, DEFAULT_EMAIL
from .config import Settings


def requires_user(payload: dict = fastapi.Depends(auth_middleware)) -> User:
Expand All @@ -16,8 +17,12 @@ def requires_admin_user(

def verify_user(payload: dict | None, admin_only: bool) -> User:
if not payload:
if Settings.ENABLE_AUTH:
raise fastapi.HTTPException(
status_code=401, detail="Authorization header is missing"
)
# This handles the case when authentication is disabled
payload = {"sub": "3e53486c-cf57-477e-ba2a-cb02dc828e1a", "role": "admin"}
payload = {"sub": DEFAULT_USER_ID, "role": "admin"}

user_id = payload.get("sub")

Expand Down
3 changes: 3 additions & 0 deletions autogpt_platform/autogpt_libs/autogpt_libs/auth/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from dataclasses import dataclass

DEFAULT_USER_ID = "3e53486c-cf57-477e-ba2a-cb02dc828e1a"
DEFAULT_EMAIL = "[email protected]"


# Using dataclass here to avoid adding dependency on pydantic
@dataclass(frozen=True)
Expand Down
4 changes: 1 addition & 3 deletions autogpt_platform/backend/backend/data/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from typing import Optional, cast

from autogpt_libs.auth.models import DEFAULT_USER_ID
from autogpt_libs.supabase_integration_credentials_store.types import (
UserIntegrations,
UserMetadata,
Expand All @@ -15,9 +16,6 @@

logger = logging.getLogger(__name__)

DEFAULT_USER_ID = "3e53486c-cf57-477e-ba2a-cb02dc828e1a"
DEFAULT_EMAIL = "[email protected]"


async def get_or_create_user(user_data: dict) -> User:
user_id = user_data.get("sub")
Expand Down
17 changes: 5 additions & 12 deletions autogpt_platform/backend/backend/server/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
from autogpt_libs.auth.middleware import auth_middleware
from fastapi import Depends, HTTPException
from autogpt_libs.auth.depends import requires_user
from autogpt_libs.auth.models import User
from fastapi import Depends

from backend.data.user import DEFAULT_USER_ID
from backend.util.settings import Settings

settings = Settings()


def get_user_id(payload: dict = Depends(auth_middleware)) -> str:
if not payload:
# This handles the case when authentication is disabled
return DEFAULT_USER_ID

user_id = payload.get("sub")
if not user_id:
raise HTTPException(status_code=401, detail="User ID not found in token")
return user_id
def get_user_id(user: User = Depends(requires_user)) -> str:
return user.user_id
32 changes: 16 additions & 16 deletions autogpt_platform/backend/backend/server/ws_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ async def event_broadcaster(manager: ConnectionManager):


async def authenticate_websocket(websocket: WebSocket) -> str:
if settings.config.enable_auth:
token = websocket.query_params.get("token")
if not token:
await websocket.close(code=4001, reason="Missing authentication token")
return ""
if not settings.config.enable_auth:
return DEFAULT_USER_ID

token = websocket.query_params.get("token")
if not token:
await websocket.close(code=4001, reason="Missing authentication token")
return ""

try:
payload = parse_jwt_token(token)
user_id = payload.get("sub")
if not user_id:
await websocket.close(code=4002, reason="Invalid token")
return ""
return user_id
except ValueError:
await websocket.close(code=4003, reason="Invalid token")
try:
payload = parse_jwt_token(token)
user_id = payload.get("sub")
if not user_id:
await websocket.close(code=4002, reason="Invalid token")
return ""
else:
return DEFAULT_USER_ID
return user_id
except ValueError:
await websocket.close(code=4003, reason="Invalid token")
return ""


async def handle_subscribe(
Expand Down
8 changes: 0 additions & 8 deletions autogpt_platform/backend/backend/util/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
import sys


def get_secrets_path() -> pathlib.Path:
return get_data_path() / "secrets"


def get_config_path() -> pathlib.Path:
return get_data_path()


def get_frontend_path() -> pathlib.Path:
if getattr(sys, "frozen", False):
# The application is frozen
Expand Down
11 changes: 1 addition & 10 deletions autogpt_platform/backend/backend/util/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SettingsConfigDict,
)

from backend.util.data import get_data_path, get_secrets_path
from backend.util.data import get_data_path

T = TypeVar("T", bound=BaseSettings)

Expand Down Expand Up @@ -272,7 +272,6 @@ class Secrets(UpdateTrackingModel["Secrets"], BaseSettings):
# Add more secret fields as needed

model_config = SettingsConfigDict(
secrets_dir=get_secrets_path(),
env_file=".env",
env_file_encoding="utf-8",
extra="allow",
Expand All @@ -299,11 +298,3 @@ def save(self) -> None:
with open(config_path, "w") as f:
json.dump(config_to_save, f, indent=2)
self.config.clear_updates()

# Save updated secrets to individual files
secrets_dir = get_secrets_path()
for key in self.secrets.updated_fields:
secret_file = os.path.join(secrets_dir, key)
with open(secret_file, "w") as f:
f.write(str(getattr(self.secrets, key)))
self.secrets.clear_updates()
2 changes: 1 addition & 1 deletion autogpt_platform/backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "autogpt-platform-backend"
version = "0.3.0"
version = "0.3.1"
description = "A platform for building AI-powered agentic workflows"
authors = ["AutoGPT <[email protected]>"]
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions autogpt_platform/docker-compose.platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ services:
- PYRO_HOST=0.0.0.0
- AGENTSERVER_HOST=rest_server
- DATABASEMANAGER_HOST=0.0.0.0
- EXECUTIONMANAGER_HOST=0.0.0.0
- ENCRYPTION_KEY=dvziYgz0KSK8FENhju0ZYi8-fRTfAdlz6YLhdB_jhNw= # DO NOT USE IN PRODUCTION!!
ports:
- "8002:8000"
Expand Down
2 changes: 1 addition & 1 deletion autogpt_platform/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "0.3.0",
"version": "0.3.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
7 changes: 4 additions & 3 deletions autogpt_platform/frontend/src/components/monitor/FlowInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ export const FlowInfo: React.FC<
</DropdownMenu>
)}
<Link
className={buttonVariants({ variant: "outline" })}
className={buttonVariants({ variant: "default" })}
href={`/build?flowID=${flow.id}`}
>
<Pencil2Icon />
<Pencil2Icon className="mr-2" />
Open in Builder
</Link>
<Button
variant="outline"
Expand All @@ -126,7 +127,7 @@ export const FlowInfo: React.FC<
)
}
>
<ExitIcon />
<ExitIcon className="mr-2" /> Export
</Button>
<Button variant="outline" onClick={() => setIsDeleteModalOpen(true)}>
<Trash2Icon className="h-full" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export const FlowRunInfo: React.FC<
</Button>
)}
<Link
className={buttonVariants({ variant: "outline" })}
className={buttonVariants({ variant: "default" })}
href={`/build?flowID=${flow.id}`}
>
<Pencil2Icon className="mr-2" /> Edit Agent
<Pencil2Icon className="mr-2" /> Open in Builder
</Link>
</div>
</CardHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ const NodeKeyValueInput: FC<{
>
<div>
{keyValuePairs.map(({ key, value }, index) => (
<div key={getEntryKey(key)}>
/*
The `index` is used as a DOM key instead of the actual `key`
because the `key` can change with each input, causing the input to lose focus.
*/
<div key={index}>
<NodeHandle
keyName={getEntryKey(key)}
schema={{ type: "string" }}
Expand Down

0 comments on commit 3ceefc4

Please sign in to comment.