Spaces:
Runtime error
Add auth, credential encryption, and session ownership (Items 3, 5, 6)
Browse filesItem 3 – Authentication:
- backend/core/auth.py: create_access_token() + verify_token() dependency (JWT/PyJWT)
- backend/app/api/routes/auth.py: POST /auth/login, GET /auth/me (public)
- backend/main.py: all API routers now protected with Depends(verify_token)
- Config: AUTH_USERNAME, AUTH_PASSWORD, JWT_SECRET, JWT_EXPIRE_HOURS
- Frontend: token stored in module memory (never localStorage); axios request
interceptor adds Authorization header; 401 broadcasts auth:logout event
- LoginPage.jsx: themed sign-in card shown before app loads
- App.jsx: guards main app behind isAuthenticated state
Item 5 – Credential encryption:
- backend/core/crypto.py: encrypt_credentials()/decrypt_credentials() via Fernet
- Transparent backwards-compat: legacy plaintext dicts pass through unchanged
- specs.py: encrypts on save, decrypts on GET /credentials and GET /specs/:id
- execution.py: decrypts stored creds before passing to LLM planner and executor
- Config: ENCRYPTION_KEY (Fernet key, optional — warns if unset)
- Also fixed: import traceback moved to top of specs.py; print replaced with logger
Item 6 – Session ownership:
- database.py: user_id column added to SessionModel and ChatSession (nullable)
- database.run_migrations(): ALTER TABLE IF NOT EXISTS stopgap (pre-Alembic)
- sessions.py: new sessions tagged with current_user from JWT
- chat.py: new chat sessions tagged with current_user from JWT
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- .env.example +10 -0
- backend/app/api/routes/auth.py +25 -0
- backend/app/api/routes/chat.py +8 -1
- backend/app/api/routes/execution.py +5 -4
- backend/app/api/routes/sessions.py +6 -2
- backend/app/api/routes/specs.py +7 -6
- backend/core/auth.py +29 -0
- backend/core/config.py +9 -0
- backend/core/crypto.py +36 -0
- backend/database.py +18 -1
- backend/main.py +16 -10
- frontend-react/src/App.jsx +583 -789
- frontend-react/src/components/LoginPage.jsx +142 -0
- frontend-react/src/services/api.js +29 -2
|
@@ -10,3 +10,13 @@ SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key_here
|
|
| 10 |
|
| 11 |
VITE_BACKEND_URL=http://localhost:8001
|
| 12 |
VITE_API_URL=http://localhost:8001
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
VITE_BACKEND_URL=http://localhost:8001
|
| 12 |
VITE_API_URL=http://localhost:8001
|
| 13 |
+
|
| 14 |
+
# Auth (Item 3) — set a strong password and secret before deploying
|
| 15 |
+
AUTH_USERNAME=admin
|
| 16 |
+
AUTH_PASSWORD=changeme
|
| 17 |
+
JWT_SECRET=change-this-secret-in-production
|
| 18 |
+
JWT_EXPIRE_HOURS=24
|
| 19 |
+
|
| 20 |
+
# Credential encryption (Item 5)
|
| 21 |
+
# Generate with: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
|
| 22 |
+
ENCRYPTION_KEY=
|
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Depends, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
from backend.core.auth import create_access_token, verify_token
|
| 5 |
+
from backend.core.config import settings
|
| 6 |
+
|
| 7 |
+
router = APIRouter(prefix="/auth")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class LoginRequest(BaseModel):
|
| 11 |
+
username: str
|
| 12 |
+
password: str
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@router.post("/login")
|
| 16 |
+
def login(body: LoginRequest):
|
| 17 |
+
if body.username != settings.AUTH_USERNAME or body.password != settings.AUTH_PASSWORD:
|
| 18 |
+
raise HTTPException(status_code=401, detail="Invalid credentials")
|
| 19 |
+
token = create_access_token(body.username)
|
| 20 |
+
return {"access_token": token, "token_type": "bearer"}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@router.get("/me")
|
| 24 |
+
def me(current_user: str = Depends(verify_token)):
|
| 25 |
+
return {"username": current_user}
|
|
@@ -7,6 +7,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request
|
|
| 7 |
from sqlalchemy.orm import Session
|
| 8 |
|
| 9 |
from backend import database, schemas
|
|
|
|
| 10 |
from backend.core.limiter import limiter
|
| 11 |
from backend.core.logging import get_logger
|
| 12 |
from backend.services.chat_assistant import process_message as chat_process_message
|
|
@@ -17,7 +18,12 @@ logger = get_logger(__name__)
|
|
| 17 |
|
| 18 |
@router.post("/chat", response_model=schemas.ChatResponse)
|
| 19 |
@limiter.limit("20/minute")
|
| 20 |
-
def chat_endpoint(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
try:
|
| 22 |
chat_session = None
|
| 23 |
if body.chat_session_id:
|
|
@@ -31,6 +37,7 @@ def chat_endpoint(request: Request, body: schemas.ChatRequest, db: Session = Dep
|
|
| 31 |
session_name += "..."
|
| 32 |
chat_session = database.ChatSession(
|
| 33 |
id=str(uuid.uuid4()),
|
|
|
|
| 34 |
name=session_name,
|
| 35 |
spec_id=body.spec_id,
|
| 36 |
session_id=body.session_id,
|
|
|
|
| 7 |
from sqlalchemy.orm import Session
|
| 8 |
|
| 9 |
from backend import database, schemas
|
| 10 |
+
from backend.core.auth import verify_token
|
| 11 |
from backend.core.limiter import limiter
|
| 12 |
from backend.core.logging import get_logger
|
| 13 |
from backend.services.chat_assistant import process_message as chat_process_message
|
|
|
|
| 18 |
|
| 19 |
@router.post("/chat", response_model=schemas.ChatResponse)
|
| 20 |
@limiter.limit("20/minute")
|
| 21 |
+
def chat_endpoint(
|
| 22 |
+
request: Request,
|
| 23 |
+
body: schemas.ChatRequest,
|
| 24 |
+
db: Session = Depends(database.get_db),
|
| 25 |
+
current_user: str = Depends(verify_token),
|
| 26 |
+
):
|
| 27 |
try:
|
| 28 |
chat_session = None
|
| 29 |
if body.chat_session_id:
|
|
|
|
| 37 |
session_name += "..."
|
| 38 |
chat_session = database.ChatSession(
|
| 39 |
id=str(uuid.uuid4()),
|
| 40 |
+
user_id=current_user,
|
| 41 |
name=session_name,
|
| 42 |
spec_id=body.spec_id,
|
| 43 |
session_id=body.session_id,
|
|
@@ -11,6 +11,7 @@ from sqlalchemy.orm import Session
|
|
| 11 |
from sqlalchemy.orm.attributes import flag_modified
|
| 12 |
|
| 13 |
from backend import database, schemas
|
|
|
|
| 14 |
from backend.core.limiter import limiter
|
| 15 |
from backend.core.logging import get_logger
|
| 16 |
from backend.core.url_guard import resolve_safe_ip
|
|
@@ -99,7 +100,7 @@ def generate_plan(request: Request, body: schemas.PlanRequest, db: Session = Dep
|
|
| 99 |
if body.spec_id:
|
| 100 |
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == body.spec_id).first()
|
| 101 |
if spec and spec.login_credentials:
|
| 102 |
-
credentials = spec.login_credentials
|
| 103 |
|
| 104 |
plan = generate_execution_plan(parsed_spec, body.base_url, body.scenario, credentials)
|
| 105 |
|
|
@@ -122,10 +123,10 @@ def generate_plan(request: Request, body: schemas.PlanRequest, db: Session = Dep
|
|
| 122 |
session.base_url = body.base_url
|
| 123 |
|
| 124 |
if plan.suggested_credentials and isinstance(plan.suggested_credentials, dict):
|
| 125 |
-
current_creds = dict(spec.login_credentials or {})
|
| 126 |
if any(k not in current_creds or current_creds[k] != v for k, v in plan.suggested_credentials.items()):
|
| 127 |
current_creds.update(plan.suggested_credentials)
|
| 128 |
-
spec.login_credentials = current_creds
|
| 129 |
flag_modified(spec, "login_credentials")
|
| 130 |
logger.info("AI suggested credentials merged for spec '%s'", spec.name)
|
| 131 |
|
|
@@ -177,7 +178,7 @@ async def execute_step(request: Request, body: schemas.ExecuteStepRequest, db: S
|
|
| 177 |
database.SpecDocument.id == body.spec_id
|
| 178 |
).first()
|
| 179 |
if spec and spec.login_credentials:
|
| 180 |
-
effective_credentials = spec.login_credentials
|
| 181 |
logger.info("Using stored credentials for spec '%s'", spec.name)
|
| 182 |
|
| 183 |
req_plan, executor_token_usage = await asyncio.to_thread(
|
|
|
|
| 11 |
from sqlalchemy.orm.attributes import flag_modified
|
| 12 |
|
| 13 |
from backend import database, schemas
|
| 14 |
+
from backend.core.crypto import decrypt_credentials, encrypt_credentials
|
| 15 |
from backend.core.limiter import limiter
|
| 16 |
from backend.core.logging import get_logger
|
| 17 |
from backend.core.url_guard import resolve_safe_ip
|
|
|
|
| 100 |
if body.spec_id:
|
| 101 |
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == body.spec_id).first()
|
| 102 |
if spec and spec.login_credentials:
|
| 103 |
+
credentials = decrypt_credentials(spec.login_credentials)
|
| 104 |
|
| 105 |
plan = generate_execution_plan(parsed_spec, body.base_url, body.scenario, credentials)
|
| 106 |
|
|
|
|
| 123 |
session.base_url = body.base_url
|
| 124 |
|
| 125 |
if plan.suggested_credentials and isinstance(plan.suggested_credentials, dict):
|
| 126 |
+
current_creds = decrypt_credentials(dict(spec.login_credentials or {}))
|
| 127 |
if any(k not in current_creds or current_creds[k] != v for k, v in plan.suggested_credentials.items()):
|
| 128 |
current_creds.update(plan.suggested_credentials)
|
| 129 |
+
spec.login_credentials = encrypt_credentials(current_creds)
|
| 130 |
flag_modified(spec, "login_credentials")
|
| 131 |
logger.info("AI suggested credentials merged for spec '%s'", spec.name)
|
| 132 |
|
|
|
|
| 178 |
database.SpecDocument.id == body.spec_id
|
| 179 |
).first()
|
| 180 |
if spec and spec.login_credentials:
|
| 181 |
+
effective_credentials = decrypt_credentials(spec.login_credentials)
|
| 182 |
logger.info("Using stored credentials for spec '%s'", spec.name)
|
| 183 |
|
| 184 |
req_plan, executor_token_usage = await asyncio.to_thread(
|
|
@@ -4,15 +4,19 @@ from fastapi import APIRouter, Depends
|
|
| 4 |
from sqlalchemy.orm import Session
|
| 5 |
|
| 6 |
from backend import database, schemas
|
|
|
|
| 7 |
from backend.services.context_manager import get_context, set_context_variables
|
| 8 |
|
| 9 |
router = APIRouter()
|
| 10 |
|
| 11 |
|
| 12 |
@router.post("/session")
|
| 13 |
-
def create_session(
|
|
|
|
|
|
|
|
|
|
| 14 |
session_id = str(uuid.uuid4())
|
| 15 |
-
new_session = database.SessionModel(id=session_id)
|
| 16 |
db.add(new_session)
|
| 17 |
db.commit()
|
| 18 |
return {"session_id": session_id}
|
|
|
|
| 4 |
from sqlalchemy.orm import Session
|
| 5 |
|
| 6 |
from backend import database, schemas
|
| 7 |
+
from backend.core.auth import verify_token
|
| 8 |
from backend.services.context_manager import get_context, set_context_variables
|
| 9 |
|
| 10 |
router = APIRouter()
|
| 11 |
|
| 12 |
|
| 13 |
@router.post("/session")
|
| 14 |
+
def create_session(
|
| 15 |
+
db: Session = Depends(database.get_db),
|
| 16 |
+
current_user: str = Depends(verify_token),
|
| 17 |
+
):
|
| 18 |
session_id = str(uuid.uuid4())
|
| 19 |
+
new_session = database.SessionModel(id=session_id, user_id=current_user)
|
| 20 |
db.add(new_session)
|
| 21 |
db.commit()
|
| 22 |
return {"session_id": session_id}
|
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import json
|
|
|
|
| 2 |
import uuid
|
| 3 |
from typing import Optional
|
| 4 |
|
|
@@ -7,6 +8,7 @@ from sqlalchemy.orm import Session
|
|
| 7 |
from sqlalchemy.orm.attributes import flag_modified
|
| 8 |
|
| 9 |
from backend import database, schemas
|
|
|
|
| 10 |
from backend.core.logging import get_logger
|
| 11 |
from backend.services.swagger_parser import parse_spec
|
| 12 |
from backend.services.postman_parser import parse_postman_collection as parse_postman
|
|
@@ -60,8 +62,7 @@ async def upload_spec(file: UploadFile = File(...), db: Session = Depends(databa
|
|
| 60 |
safe_spec["id"] = spec_id
|
| 61 |
return {"status": "success", "spec_id": spec_id, "parsed_spec": safe_spec}
|
| 62 |
except Exception as e:
|
| 63 |
-
|
| 64 |
-
traceback.print_exc()
|
| 65 |
raise HTTPException(status_code=400, detail=f"Failed to parse spec: {str(e)}")
|
| 66 |
|
| 67 |
|
|
@@ -83,7 +84,7 @@ def get_spec(spec_id: str, db: Session = Depends(database.get_db)):
|
|
| 83 |
"id": spec.id,
|
| 84 |
"name": spec.name,
|
| 85 |
"base_url": spec.base_url or "",
|
| 86 |
-
"login_credentials": spec.login_credentials or {},
|
| 87 |
"parsed_spec": spec.parsed_json,
|
| 88 |
"execution_plan": spec.execution_plan,
|
| 89 |
"scenario": spec.scenario,
|
|
@@ -128,7 +129,7 @@ def get_credentials(spec_id: str, db: Session = Depends(database.get_db)):
|
|
| 128 |
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == spec_id).first()
|
| 129 |
if not spec:
|
| 130 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 131 |
-
return spec.login_credentials or {}
|
| 132 |
|
| 133 |
|
| 134 |
@router.post("/specs/{spec_id}/credentials")
|
|
@@ -156,8 +157,8 @@ def save_credentials(spec_id: str, payload: schemas.CredentialUpdate, db: Sessio
|
|
| 156 |
extra_clean = {k: v for k, v in payload.extra.items() if not k.startswith("_")}
|
| 157 |
current.update(extra_clean)
|
| 158 |
|
| 159 |
-
spec.login_credentials = current
|
| 160 |
flag_modified(spec, "login_credentials")
|
| 161 |
db.commit()
|
| 162 |
db.refresh(spec)
|
| 163 |
-
return {"status": "saved", "credentials":
|
|
|
|
| 1 |
import json
|
| 2 |
+
import traceback
|
| 3 |
import uuid
|
| 4 |
from typing import Optional
|
| 5 |
|
|
|
|
| 8 |
from sqlalchemy.orm.attributes import flag_modified
|
| 9 |
|
| 10 |
from backend import database, schemas
|
| 11 |
+
from backend.core.crypto import decrypt_credentials, encrypt_credentials
|
| 12 |
from backend.core.logging import get_logger
|
| 13 |
from backend.services.swagger_parser import parse_spec
|
| 14 |
from backend.services.postman_parser import parse_postman_collection as parse_postman
|
|
|
|
| 62 |
safe_spec["id"] = spec_id
|
| 63 |
return {"status": "success", "spec_id": spec_id, "parsed_spec": safe_spec}
|
| 64 |
except Exception as e:
|
| 65 |
+
logger.error("Failed to parse spec: %s", traceback.format_exc())
|
|
|
|
| 66 |
raise HTTPException(status_code=400, detail=f"Failed to parse spec: {str(e)}")
|
| 67 |
|
| 68 |
|
|
|
|
| 84 |
"id": spec.id,
|
| 85 |
"name": spec.name,
|
| 86 |
"base_url": spec.base_url or "",
|
| 87 |
+
"login_credentials": decrypt_credentials(spec.login_credentials or {}),
|
| 88 |
"parsed_spec": spec.parsed_json,
|
| 89 |
"execution_plan": spec.execution_plan,
|
| 90 |
"scenario": spec.scenario,
|
|
|
|
| 129 |
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == spec_id).first()
|
| 130 |
if not spec:
|
| 131 |
raise HTTPException(status_code=404, detail="Spec not found")
|
| 132 |
+
return decrypt_credentials(spec.login_credentials or {})
|
| 133 |
|
| 134 |
|
| 135 |
@router.post("/specs/{spec_id}/credentials")
|
|
|
|
| 157 |
extra_clean = {k: v for k, v in payload.extra.items() if not k.startswith("_")}
|
| 158 |
current.update(extra_clean)
|
| 159 |
|
| 160 |
+
spec.login_credentials = encrypt_credentials(current)
|
| 161 |
flag_modified(spec, "login_credentials")
|
| 162 |
db.commit()
|
| 163 |
db.refresh(spec)
|
| 164 |
+
return {"status": "saved", "credentials": current}
|
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime, timedelta, timezone
|
| 2 |
+
|
| 3 |
+
import jwt
|
| 4 |
+
from fastapi import Depends, HTTPException, status
|
| 5 |
+
from fastapi.security import OAuth2PasswordBearer
|
| 6 |
+
|
| 7 |
+
from backend.core.config import settings
|
| 8 |
+
|
| 9 |
+
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def create_access_token(username: str) -> str:
|
| 13 |
+
expire = datetime.now(timezone.utc) + timedelta(hours=settings.JWT_EXPIRE_HOURS)
|
| 14 |
+
return jwt.encode({"sub": username, "exp": expire}, settings.JWT_SECRET, algorithm="HS256")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def verify_token(token: str = Depends(oauth2_scheme)) -> str:
|
| 18 |
+
try:
|
| 19 |
+
payload = jwt.decode(token, settings.JWT_SECRET, algorithms=["HS256"])
|
| 20 |
+
username: str = payload.get("sub")
|
| 21 |
+
if not username:
|
| 22 |
+
raise ValueError("Missing subject")
|
| 23 |
+
return username
|
| 24 |
+
except Exception:
|
| 25 |
+
raise HTTPException(
|
| 26 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 27 |
+
detail="Invalid or expired token",
|
| 28 |
+
headers={"WWW-Authenticate": "Bearer"},
|
| 29 |
+
)
|
|
@@ -10,6 +10,15 @@ class Settings(BaseSettings):
|
|
| 10 |
HTTP_TIMEOUT: int = 120
|
| 11 |
RESPONSE_TRUNCATION_LIMIT: int = 4000
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
model_config = {"env_file": ".env", "extra": "ignore"}
|
| 14 |
|
| 15 |
@property
|
|
|
|
| 10 |
HTTP_TIMEOUT: int = 120
|
| 11 |
RESPONSE_TRUNCATION_LIMIT: int = 4000
|
| 12 |
|
| 13 |
+
# Auth
|
| 14 |
+
AUTH_USERNAME: str = "admin"
|
| 15 |
+
AUTH_PASSWORD: str = "changeme"
|
| 16 |
+
JWT_SECRET: str = "change-this-secret-in-production"
|
| 17 |
+
JWT_EXPIRE_HOURS: int = 24
|
| 18 |
+
|
| 19 |
+
# Credential encryption (Fernet key — generate with: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())")
|
| 20 |
+
ENCRYPTION_KEY: str = ""
|
| 21 |
+
|
| 22 |
model_config = {"env_file": ".env", "extra": "ignore"}
|
| 23 |
|
| 24 |
@property
|
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
from cryptography.fernet import Fernet
|
| 4 |
+
|
| 5 |
+
from backend.core.config import settings
|
| 6 |
+
from backend.core.logging import get_logger
|
| 7 |
+
|
| 8 |
+
logger = get_logger(__name__)
|
| 9 |
+
|
| 10 |
+
_ENCRYPTED_KEY = "__enc__"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _fernet() -> Fernet:
|
| 14 |
+
if not settings.ENCRYPTION_KEY:
|
| 15 |
+
raise ValueError("ENCRYPTION_KEY is not set in environment. Cannot encrypt credentials.")
|
| 16 |
+
return Fernet(settings.ENCRYPTION_KEY.encode())
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def encrypt_credentials(data: dict) -> dict:
|
| 20 |
+
"""Encrypt a credentials dict for storage. Returns {"__enc__": "<token>"}."""
|
| 21 |
+
if not settings.ENCRYPTION_KEY:
|
| 22 |
+
logger.warning("ENCRYPTION_KEY not set — credentials stored in plaintext")
|
| 23 |
+
return data
|
| 24 |
+
token = _fernet().encrypt(json.dumps(data).encode()).decode()
|
| 25 |
+
return {_ENCRYPTED_KEY: token}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def decrypt_credentials(data: dict) -> dict:
|
| 29 |
+
"""Decrypt a stored credentials dict. Transparently handles legacy plaintext dicts."""
|
| 30 |
+
if not isinstance(data, dict):
|
| 31 |
+
return data
|
| 32 |
+
if _ENCRYPTED_KEY not in data:
|
| 33 |
+
return data # legacy plaintext — return as-is
|
| 34 |
+
if not settings.ENCRYPTION_KEY:
|
| 35 |
+
raise ValueError("ENCRYPTION_KEY is not set — cannot decrypt stored credentials.")
|
| 36 |
+
return json.loads(_fernet().decrypt(data[_ENCRYPTED_KEY].encode()))
|
|
@@ -5,7 +5,7 @@ from datetime import datetime
|
|
| 5 |
from pathlib import Path
|
| 6 |
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
-
from sqlalchemy import Column, DateTime, ForeignKey, Integer, JSON, String, Table, Text, Unicode, create_engine
|
| 9 |
from sqlalchemy.orm import declarative_base, relationship, sessionmaker
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
|
@@ -65,6 +65,7 @@ class SessionModel(Base):
|
|
| 65 |
__tablename__ = "sessions"
|
| 66 |
|
| 67 |
id = Column(String, primary_key=True, index=True)
|
|
|
|
| 68 |
spec_id = Column(String, ForeignKey("spec_documents.id"), nullable=True)
|
| 69 |
spec_name = Column(String, nullable=True)
|
| 70 |
base_url = Column(String)
|
|
@@ -119,6 +120,7 @@ class ChatSession(Base):
|
|
| 119 |
__tablename__ = "chat_sessions"
|
| 120 |
|
| 121 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
|
|
| 122 |
name = Column(String, nullable=False) # auto-named from first message, user can rename
|
| 123 |
spec_id = Column(String, ForeignKey("spec_documents.id", ondelete="SET NULL"), nullable=True)
|
| 124 |
session_id = Column(String, nullable=True) # linked API test session
|
|
@@ -145,6 +147,21 @@ class ChatMessage(Base):
|
|
| 145 |
Base.metadata.create_all(bind=engine)
|
| 146 |
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
def get_db():
|
| 149 |
db = SessionLocal()
|
| 150 |
try:
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
+
from sqlalchemy import Column, DateTime, ForeignKey, Integer, JSON, String, Table, Text, Unicode, create_engine, text
|
| 9 |
from sqlalchemy.orm import declarative_base, relationship, sessionmaker
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
|
|
|
| 65 |
__tablename__ = "sessions"
|
| 66 |
|
| 67 |
id = Column(String, primary_key=True, index=True)
|
| 68 |
+
user_id = Column(String, nullable=True, index=True)
|
| 69 |
spec_id = Column(String, ForeignKey("spec_documents.id"), nullable=True)
|
| 70 |
spec_name = Column(String, nullable=True)
|
| 71 |
base_url = Column(String)
|
|
|
|
| 120 |
__tablename__ = "chat_sessions"
|
| 121 |
|
| 122 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 123 |
+
user_id = Column(String, nullable=True, index=True)
|
| 124 |
name = Column(String, nullable=False) # auto-named from first message, user can rename
|
| 125 |
spec_id = Column(String, ForeignKey("spec_documents.id", ondelete="SET NULL"), nullable=True)
|
| 126 |
session_id = Column(String, nullable=True) # linked API test session
|
|
|
|
| 147 |
Base.metadata.create_all(bind=engine)
|
| 148 |
|
| 149 |
|
| 150 |
+
def run_migrations():
|
| 151 |
+
"""Stopgap column additions for tables that existed before Alembic was set up."""
|
| 152 |
+
stmts = [
|
| 153 |
+
"ALTER TABLE sessions ADD COLUMN IF NOT EXISTS user_id VARCHAR",
|
| 154 |
+
"ALTER TABLE chat_sessions ADD COLUMN IF NOT EXISTS user_id VARCHAR",
|
| 155 |
+
]
|
| 156 |
+
try:
|
| 157 |
+
with engine.connect() as conn:
|
| 158 |
+
for stmt in stmts:
|
| 159 |
+
conn.execute(text(stmt))
|
| 160 |
+
conn.commit()
|
| 161 |
+
except Exception as e:
|
| 162 |
+
logger.warning("Startup migration skipped: %s", e)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
def get_db():
|
| 166 |
db = SessionLocal()
|
| 167 |
try:
|
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
-
from fastapi import FastAPI, Request
|
| 4 |
from fastapi.exceptions import RequestValidationError
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from fastapi.responses import JSONResponse
|
|
@@ -9,11 +9,12 @@ from slowapi import _rate_limit_exceeded_handler
|
|
| 9 |
from slowapi.errors import RateLimitExceeded
|
| 10 |
|
| 11 |
from backend import database
|
|
|
|
| 12 |
from backend.core.config import settings
|
| 13 |
from backend.core.errors import AppError, app_error_handler
|
| 14 |
from backend.core.limiter import limiter
|
| 15 |
from backend.core.logging import get_logger
|
| 16 |
-
from backend.app.api.routes import specs, assets, sessions, history, chat, execution
|
| 17 |
|
| 18 |
logger = get_logger(__name__)
|
| 19 |
|
|
@@ -21,8 +22,9 @@ logger = get_logger(__name__)
|
|
| 21 |
for category in ["audio", "video", "documents", "images", "specs"]:
|
| 22 |
os.makedirs(os.path.join(settings.UPLOAD_DIR, category), exist_ok=True)
|
| 23 |
|
| 24 |
-
# Create DB tables
|
| 25 |
database.Base.metadata.create_all(bind=database.engine)
|
|
|
|
| 26 |
|
| 27 |
app = FastAPI(title="AI API Testing Assistant")
|
| 28 |
app.state.limiter = limiter
|
|
@@ -48,13 +50,17 @@ async def validation_exception_handler(request, exc):
|
|
| 48 |
return JSONResponse(status_code=422, content={"detail": exc.errors()})
|
| 49 |
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
app.include_router(
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
app.include_router(
|
| 57 |
-
app.include_router(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
@app.get("/")
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
from fastapi import Depends, FastAPI, Request
|
| 4 |
from fastapi.exceptions import RequestValidationError
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from fastapi.responses import JSONResponse
|
|
|
|
| 9 |
from slowapi.errors import RateLimitExceeded
|
| 10 |
|
| 11 |
from backend import database
|
| 12 |
+
from backend.core.auth import verify_token
|
| 13 |
from backend.core.config import settings
|
| 14 |
from backend.core.errors import AppError, app_error_handler
|
| 15 |
from backend.core.limiter import limiter
|
| 16 |
from backend.core.logging import get_logger
|
| 17 |
+
from backend.app.api.routes import specs, assets, sessions, history, chat, execution, auth
|
| 18 |
|
| 19 |
logger = get_logger(__name__)
|
| 20 |
|
|
|
|
| 22 |
for category in ["audio", "video", "documents", "images", "specs"]:
|
| 23 |
os.makedirs(os.path.join(settings.UPLOAD_DIR, category), exist_ok=True)
|
| 24 |
|
| 25 |
+
# Create DB tables then run any stopgap column migrations
|
| 26 |
database.Base.metadata.create_all(bind=database.engine)
|
| 27 |
+
database.run_migrations()
|
| 28 |
|
| 29 |
app = FastAPI(title="AI API Testing Assistant")
|
| 30 |
app.state.limiter = limiter
|
|
|
|
| 50 |
return JSONResponse(status_code=422, content={"detail": exc.errors()})
|
| 51 |
|
| 52 |
|
| 53 |
+
# Public routes (no auth required)
|
| 54 |
+
app.include_router(auth.router)
|
| 55 |
+
|
| 56 |
+
# Protected routes — all require a valid JWT
|
| 57 |
+
_auth = [Depends(verify_token)]
|
| 58 |
+
app.include_router(specs.router, dependencies=_auth)
|
| 59 |
+
app.include_router(assets.router, dependencies=_auth)
|
| 60 |
+
app.include_router(sessions.router, dependencies=_auth)
|
| 61 |
+
app.include_router(history.router, dependencies=_auth)
|
| 62 |
+
app.include_router(chat.router, dependencies=_auth)
|
| 63 |
+
app.include_router(execution.router, dependencies=_auth)
|
| 64 |
|
| 65 |
|
| 66 |
@app.get("/")
|
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
import React, { useState, useRef,
|
| 2 |
import {
|
| 3 |
-
|
| 4 |
ChevronRight, ChevronLeft, Send, Zap, Trash2, RefreshCw,
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
} from 'lucide-react';
|
| 9 |
import { AppProvider, useAppContext } from './components/AppContext';
|
| 10 |
import CollectionsPage from './components/CollectionsPage';
|
|
@@ -15,199 +15,18 @@ import SettingsPage from './components/SettingsPage';
|
|
| 15 |
import ChatAssistant from './components/ChatAssistant';
|
| 16 |
import { ToastContainer } from './components/Toast';
|
| 17 |
import ErrorBoundary from './components/ErrorBoundary';
|
| 18 |
-
import { SpecService, SessionService, PlanService,
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
--bg-primary: #0B0F1A;
|
| 31 |
-
--bg-secondary: #0F1420;
|
| 32 |
-
--bg-tertiary: #161B2B;
|
| 33 |
-
--bg-elevated: #1C2236;
|
| 34 |
-
--bg-hover: #232A40;
|
| 35 |
-
|
| 36 |
-
/* Borders — subtle hierarchy */
|
| 37 |
-
--border-subtle: rgba(148, 163, 184, 0.08);
|
| 38 |
-
--border-default: rgba(148, 163, 184, 0.14);
|
| 39 |
-
--border-strong: rgba(148, 163, 184, 0.24);
|
| 40 |
-
|
| 41 |
-
/* Text */
|
| 42 |
-
--text-primary: #E8ECF5;
|
| 43 |
-
--text-secondary: #8A93A8;
|
| 44 |
-
--text-tertiary: #5A6378;
|
| 45 |
-
--text-muted: #404B61;
|
| 46 |
-
|
| 47 |
-
/* Accent — confident indigo→cyan, used sparingly */
|
| 48 |
-
--accent-primary: #6366F1;
|
| 49 |
-
--accent-hover: #818CF8;
|
| 50 |
-
--accent-secondary:#22D3EE;
|
| 51 |
-
--accent-gradient: linear-gradient(135deg, #6366F1 0%, #22D3EE 100%);
|
| 52 |
-
--accent-glow: rgba(99, 102, 241, 0.18);
|
| 53 |
-
|
| 54 |
-
/* Semantic */
|
| 55 |
-
--success: #10B981;
|
| 56 |
-
--success-bg: rgba(16, 185, 129, 0.1);
|
| 57 |
-
--warning: #F59E0B;
|
| 58 |
-
--warning-bg: rgba(245, 158, 11, 0.1);
|
| 59 |
-
--danger: #EF4444;
|
| 60 |
-
--danger-bg: rgba(239, 68, 68, 0.1);
|
| 61 |
-
|
| 62 |
-
/* Typography */
|
| 63 |
-
--font-sans: 'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 64 |
-
--font-mono: 'JetBrains Mono', ui-monospace, monospace;
|
| 65 |
-
|
| 66 |
-
/* Shadows */
|
| 67 |
-
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
|
| 68 |
-
--shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.4);
|
| 69 |
-
--shadow-lg: 0 12px 32px -8px rgba(0, 0, 0, 0.5);
|
| 70 |
-
--shadow-glow: 0 0 0 1px var(--accent-glow), 0 8px 24px -8px var(--accent-glow);
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
* { font-family: var(--font-sans); }
|
| 74 |
-
code, pre, .font-mono { font-family: var(--font-mono) !important; }
|
| 75 |
-
|
| 76 |
-
body {
|
| 77 |
-
background: var(--bg-primary);
|
| 78 |
-
color: var(--text-primary);
|
| 79 |
-
font-feature-settings: "cv02", "cv03", "cv04", "cv11";
|
| 80 |
-
-webkit-font-smoothing: antialiased;
|
| 81 |
-
-moz-osx-font-smoothing: grayscale;
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
/* Atmospheric background gradient */
|
| 85 |
-
.app-shell::before {
|
| 86 |
-
content: '';
|
| 87 |
-
position: fixed;
|
| 88 |
-
inset: 0;
|
| 89 |
-
background:
|
| 90 |
-
radial-gradient(ellipse 80% 50% at 20% 0%, rgba(99, 102, 241, 0.08), transparent 50%),
|
| 91 |
-
radial-gradient(ellipse 60% 40% at 90% 100%, rgba(34, 211, 238, 0.05), transparent 50%);
|
| 92 |
-
pointer-events: none;
|
| 93 |
-
z-index: 0;
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
/* Refined scrollbars */
|
| 97 |
-
::-webkit-scrollbar { width: 10px; height: 10px; }
|
| 98 |
-
::-webkit-scrollbar-track { background: transparent; }
|
| 99 |
-
::-webkit-scrollbar-thumb {
|
| 100 |
-
background: var(--border-default);
|
| 101 |
-
border-radius: 8px;
|
| 102 |
-
border: 2px solid transparent;
|
| 103 |
-
background-clip: padding-box;
|
| 104 |
-
}
|
| 105 |
-
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }
|
| 106 |
-
|
| 107 |
-
/* Selection */
|
| 108 |
-
::selection { background: var(--accent-glow); color: var(--text-primary); }
|
| 109 |
-
|
| 110 |
-
/* Focus rings */
|
| 111 |
-
.focus-ring:focus-visible {
|
| 112 |
-
outline: none;
|
| 113 |
-
box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-primary);
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
/* Subtle grain overlay for premium feel */
|
| 117 |
-
.grain::after {
|
| 118 |
-
content: '';
|
| 119 |
-
position: absolute;
|
| 120 |
-
inset: 0;
|
| 121 |
-
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' /%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
|
| 122 |
-
opacity: 0.025;
|
| 123 |
-
pointer-events: none;
|
| 124 |
-
mix-blend-mode: overlay;
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
-
/* Animated gradient borders for active/focused elements */
|
| 128 |
-
@keyframes shimmer {
|
| 129 |
-
0%, 100% { opacity: 0.6; }
|
| 130 |
-
50% { opacity: 1; }
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
.animate-shimmer { animation: shimmer 2.5s ease-in-out infinite; }
|
| 134 |
-
|
| 135 |
-
@keyframes pulse-glow {
|
| 136 |
-
0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
|
| 137 |
-
50% { box-shadow: 0 0 0 6px transparent; }
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
.animate-pulse-glow { animation: pulse-glow 2s ease-out infinite; }
|
| 141 |
-
|
| 142 |
-
/* Step card hover treatment */
|
| 143 |
-
.step-card {
|
| 144 |
-
transition: border-color 200ms ease, transform 200ms ease, box-shadow 200ms ease;
|
| 145 |
-
}
|
| 146 |
-
.step-card:hover {
|
| 147 |
-
border-color: var(--border-strong);
|
| 148 |
-
transform: translateY(-1px);
|
| 149 |
-
box-shadow: var(--shadow-md);
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
/* Sidebar nav button refined */
|
| 153 |
-
.nav-btn {
|
| 154 |
-
position: relative;
|
| 155 |
-
transition: color 180ms ease, background 180ms ease;
|
| 156 |
-
}
|
| 157 |
-
.nav-btn::before {
|
| 158 |
-
content: '';
|
| 159 |
-
position: absolute;
|
| 160 |
-
left: 0; top: 50%;
|
| 161 |
-
width: 2px; height: 0;
|
| 162 |
-
background: var(--accent-gradient);
|
| 163 |
-
border-radius: 0 2px 2px 0;
|
| 164 |
-
transform: translateY(-50%);
|
| 165 |
-
transition: height 200ms ease;
|
| 166 |
-
}
|
| 167 |
-
.nav-btn.active::before { height: 22px; }
|
| 168 |
-
|
| 169 |
-
/* Button gradient effect */
|
| 170 |
-
.btn-primary {
|
| 171 |
-
background: var(--accent-gradient);
|
| 172 |
-
position: relative;
|
| 173 |
-
overflow: hidden;
|
| 174 |
-
transition: all 180ms ease;
|
| 175 |
-
}
|
| 176 |
-
.btn-primary::before {
|
| 177 |
-
content: '';
|
| 178 |
-
position: absolute;
|
| 179 |
-
inset: 0;
|
| 180 |
-
background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 50%);
|
| 181 |
-
opacity: 0;
|
| 182 |
-
transition: opacity 180ms ease;
|
| 183 |
-
}
|
| 184 |
-
.btn-primary:hover:not(:disabled)::before { opacity: 1; }
|
| 185 |
-
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
|
| 186 |
-
`}</style>
|
| 187 |
-
);
|
| 188 |
-
|
| 189 |
-
/* ---------------------------------------------------------------
|
| 190 |
-
Sidebar nav button — single source of truth
|
| 191 |
-
--------------------------------------------------------------- */
|
| 192 |
-
const NavButton = ({ icon: Icon, label, active, onClick }) => (
|
| 193 |
-
<button
|
| 194 |
-
onClick={onClick}
|
| 195 |
-
title={label}
|
| 196 |
-
className={`nav-btn group relative flex items-center justify-center w-10 h-10 rounded-lg
|
| 197 |
-
${active
|
| 198 |
-
? 'active text-[var(--text-primary)] bg-[var(--bg-elevated)]'
|
| 199 |
-
: 'text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)]'
|
| 200 |
-
}`}
|
| 201 |
-
>
|
| 202 |
-
<Icon size={18} strokeWidth={1.75} />
|
| 203 |
-
{/* Tooltip on hover */}
|
| 204 |
-
<span className="absolute left-full ml-3 px-2 py-1 rounded-md text-[11px] font-medium
|
| 205 |
-
bg-[var(--bg-elevated)] text-[var(--text-primary)] border border-[var(--border-default)]
|
| 206 |
-
opacity-0 group-hover:opacity-100 pointer-events-none whitespace-nowrap z-50
|
| 207 |
-
transition-opacity duration-150 shadow-lg">
|
| 208 |
-
{label}
|
| 209 |
-
</span>
|
| 210 |
-
</button>
|
| 211 |
);
|
| 212 |
|
| 213 |
function MainApp() {
|
|
@@ -223,18 +42,23 @@ function MainApp() {
|
|
| 223 |
toasts, addToast, removeToast,
|
| 224 |
} = useAppContext();
|
| 225 |
|
| 226 |
-
const [activePage, setActivePage] = useState('
|
|
|
|
|
|
|
| 227 |
const [rightPanelOpen, setRightPanelOpen] = useState(true);
|
| 228 |
const [rightPanelMode, setRightPanelMode] = useState('context');
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
}, []);
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
const [isPlanning, setIsPlanning] = useState(false);
|
| 240 |
const [executingStep, setExecutingStep] = useState(null);
|
|
@@ -243,19 +67,14 @@ function MainApp() {
|
|
| 243 |
const [otpPrompt, setOtpPrompt] = useState(null);
|
| 244 |
const [otpInput, setOtpInput] = useState('');
|
| 245 |
const [selectionPrompt, setSelectionPrompt] = useState(null);
|
| 246 |
-
|
| 247 |
-
const [assets, setAssets] = useState([]);
|
| 248 |
-
const [isAssetLoading, setIsAssetLoading] = useState(false);
|
| 249 |
-
const [activeAssetCategory, setActiveAssetCategory] = useState('all');
|
| 250 |
-
const assetFileInputRef = useRef(null);
|
| 251 |
-
|
| 252 |
const [planTokenUsage, setPlanTokenUsage] = useState(null);
|
| 253 |
const [totalScenarioTokens, setTotalScenarioTokens] = useState({ prompt: 0, completion: 0, total: 0 });
|
| 254 |
|
|
|
|
| 255 |
const handleGeneratePlan = async () => {
|
| 256 |
-
if (!activeSpecId) { addToast('warning',
|
| 257 |
-
if (!activeBaseUrl) { addToast('warning',
|
| 258 |
-
if (!scenario.trim()) { addToast('warning',
|
| 259 |
|
| 260 |
setIsPlanning(true);
|
| 261 |
setPlanTokenUsage(null);
|
|
@@ -264,15 +83,15 @@ function MainApp() {
|
|
| 264 |
|
| 265 |
try {
|
| 266 |
const newSid = await startNewSession();
|
| 267 |
-
if (!newSid) throw new Error(
|
| 268 |
|
| 269 |
const payload = {
|
| 270 |
spec_content: typeof parsedSpec === 'string' ? parsedSpec : JSON.stringify(parsedSpec),
|
| 271 |
base_url: activeBaseUrl,
|
| 272 |
-
scenario
|
| 273 |
user_credentials: storedCredentials,
|
| 274 |
spec_id: activeSpecId,
|
| 275 |
-
session_id: newSid
|
| 276 |
};
|
| 277 |
const data = await PlanService.generatePlan(payload);
|
| 278 |
setExecutionPlan(data.execution_plan || []);
|
|
@@ -285,44 +104,33 @@ function MainApp() {
|
|
| 285 |
setTotalScenarioTokens({
|
| 286 |
prompt: data.token_usage.prompt_tokens,
|
| 287 |
completion: data.token_usage.completion_tokens,
|
| 288 |
-
total: data.token_usage.total_tokens
|
| 289 |
});
|
| 290 |
}
|
| 291 |
setStepResults({});
|
| 292 |
} catch (err) {
|
| 293 |
-
|
| 294 |
-
addToast('error', err.message || "Plan generation failed.");
|
| 295 |
} finally {
|
| 296 |
setIsPlanning(false);
|
| 297 |
}
|
| 298 |
};
|
| 299 |
|
|
|
|
| 300 |
const executeStep = async (stepDef) => {
|
| 301 |
setExecutingStep(stepDef.step);
|
| 302 |
-
|
| 303 |
try {
|
| 304 |
-
if (!sessionId) {
|
| 305 |
-
|
| 306 |
-
return;
|
| 307 |
-
}
|
| 308 |
-
if (!activeBaseUrl) {
|
| 309 |
-
addToast('warning', "Base URL is missing. Please set it in the header.");
|
| 310 |
-
return;
|
| 311 |
-
}
|
| 312 |
|
| 313 |
await refreshSessionContext();
|
| 314 |
-
|
| 315 |
const payload = {
|
| 316 |
session_id: sessionId,
|
| 317 |
step_definition: stepDef,
|
| 318 |
context_variables: sessionContextVars || {},
|
| 319 |
user_credentials: storedCredentials || {},
|
| 320 |
base_url: activeBaseUrl,
|
| 321 |
-
spec_id: activeSpecId
|
| 322 |
};
|
| 323 |
-
|
| 324 |
-
console.log("Executing Step Payload:", payload);
|
| 325 |
-
|
| 326 |
const execData = await PlanService.executeStep(payload);
|
| 327 |
|
| 328 |
setStepResults(prev => ({
|
|
@@ -330,38 +138,34 @@ function MainApp() {
|
|
| 330 |
[stepDef.step]: {
|
| 331 |
request: execData.executed_request,
|
| 332 |
response: execData.response,
|
| 333 |
-
analysis: { status: 'pending', response_summary: 'Analyzing response with AI
|
| 334 |
-
token_usage: execData.token_usage || { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }
|
| 335 |
-
}
|
| 336 |
}));
|
| 337 |
|
| 338 |
const analyzePayload = {
|
| 339 |
session_id: sessionId,
|
| 340 |
step: stepDef.step,
|
| 341 |
response_data: execData.response,
|
| 342 |
-
step_definition: stepDef
|
| 343 |
};
|
| 344 |
const analyzeData = await PlanService.analyzeResponse(analyzePayload);
|
| 345 |
|
| 346 |
const stepTokens = {
|
| 347 |
prompt_tokens: (execData.token_usage?.prompt_tokens || 0) + (analyzeData.token_usage?.prompt_tokens || 0),
|
| 348 |
completion_tokens: (execData.token_usage?.completion_tokens || 0) + (analyzeData.token_usage?.completion_tokens || 0),
|
| 349 |
-
total_tokens: (execData.token_usage?.total_tokens || 0) + (analyzeData.token_usage?.total_tokens || 0)
|
| 350 |
};
|
| 351 |
|
| 352 |
setStepResults(prev => ({
|
| 353 |
...prev,
|
| 354 |
-
[stepDef.step]: {
|
| 355 |
-
...prev[stepDef.step],
|
| 356 |
-
analysis: analyzeData,
|
| 357 |
-
token_usage: stepTokens
|
| 358 |
-
}
|
| 359 |
}));
|
| 360 |
|
| 361 |
setTotalScenarioTokens(prev => ({
|
| 362 |
prompt: prev.prompt + stepTokens.prompt_tokens,
|
| 363 |
completion: prev.completion + stepTokens.completion_tokens,
|
| 364 |
-
total: prev.total + stepTokens.total_tokens
|
| 365 |
}));
|
| 366 |
|
| 367 |
await refreshSessionContext();
|
|
@@ -369,16 +173,14 @@ function MainApp() {
|
|
| 369 |
if (analyzeData.is_otp_required) {
|
| 370 |
setOtpPrompt({ stepDef, otpFieldName: analyzeData.otp_field_name || 'otp' });
|
| 371 |
}
|
| 372 |
-
|
| 373 |
if (analyzeData.is_selection_required && analyzeData.selection_options?.length > 0) {
|
| 374 |
setSelectionPrompt({
|
| 375 |
stepDef,
|
| 376 |
fieldName: analyzeData.selection_field_name || 'selected_item',
|
| 377 |
options: analyzeData.selection_options,
|
| 378 |
-
responseBody: execData.response.body
|
| 379 |
});
|
| 380 |
}
|
| 381 |
-
|
| 382 |
} catch (err) {
|
| 383 |
console.error(`Execution failed for step ${stepDef.step}`, err);
|
| 384 |
} finally {
|
|
@@ -390,7 +192,6 @@ function MainApp() {
|
|
| 390 |
if (!executionPlan?.length) return;
|
| 391 |
setIsRunningAll(true);
|
| 392 |
for (const step of executionPlan) {
|
| 393 |
-
// Stop if an OTP or selection prompt is waiting — user must resolve it manually
|
| 394 |
if (otpPrompt || selectionPrompt) break;
|
| 395 |
await executeStep(step);
|
| 396 |
}
|
|
@@ -400,403 +201,407 @@ function MainApp() {
|
|
| 400 |
const handleOtpSubmit = async () => {
|
| 401 |
if (!otpInput.trim()) return;
|
| 402 |
const { stepDef, otpFieldName } = otpPrompt;
|
| 403 |
-
|
| 404 |
try {
|
| 405 |
-
|
| 406 |
-
await saveProfile(payload);
|
| 407 |
setOtpPrompt(null);
|
| 408 |
setOtpInput('');
|
| 409 |
await refreshSessionContext();
|
| 410 |
-
addToast('success', `OTP "${otpInput}" saved as "${otpFieldName}".
|
| 411 |
} catch (err) {
|
| 412 |
-
|
| 413 |
-
addToast('error', "Failed to save OTP.");
|
| 414 |
}
|
| 415 |
};
|
| 416 |
|
| 417 |
const handleSelectionSubmit = async (option) => {
|
| 418 |
if (!selectionPrompt) return;
|
| 419 |
-
const { fieldName } = selectionPrompt;
|
| 420 |
-
|
| 421 |
try {
|
| 422 |
-
await SessionService.updateContext(sessionId, fieldName, option.value);
|
| 423 |
setSelectionPrompt(null);
|
| 424 |
await refreshSessionContext();
|
| 425 |
} catch (err) {
|
| 426 |
-
|
| 427 |
-
addToast('error', "Failed to save selection.");
|
| 428 |
}
|
| 429 |
};
|
| 430 |
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
{ id: '
|
| 434 |
-
{ id: '
|
| 435 |
-
{ id: '
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
{ id: '
|
|
|
|
|
|
|
|
|
|
| 439 |
];
|
| 440 |
|
| 441 |
return (
|
| 442 |
<>
|
| 443 |
-
<
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
<div className="
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
<div className="
|
| 452 |
-
<
|
| 453 |
</div>
|
| 454 |
-
|
| 455 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
| 468 |
</div>
|
| 469 |
-
</aside>
|
| 470 |
|
| 471 |
-
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
-
|
| 475 |
-
<
|
|
|
|
|
|
|
|
|
|
| 476 |
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
|
| 487 |
-
|
| 488 |
-
<div className="flex items-center gap-2 ml-2 pl-4 border-l border-[var(--border-subtle)]">
|
| 489 |
-
{planTokenUsage && (
|
| 490 |
-
<div className="flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-[var(--bg-tertiary)] border border-[var(--border-subtle)]">
|
| 491 |
-
<Sparkles size={10} className="text-[var(--accent-primary)]" />
|
| 492 |
-
<span className="text-[10px] font-mono text-[var(--text-secondary)]">Plan</span>
|
| 493 |
-
<span className="text-[10px] font-mono font-semibold text-[var(--text-primary)]">{planTokenUsage.total_tokens}</span>
|
| 494 |
-
</div>
|
| 495 |
-
)}
|
| 496 |
-
{totalScenarioTokens.total > 0 && (
|
| 497 |
-
<div className="flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-[var(--success-bg)] border border-[var(--success)]/20">
|
| 498 |
-
<Activity size={10} className="text-[var(--success)]" />
|
| 499 |
-
<span className="text-[10px] font-mono text-[var(--text-secondary)]">Total</span>
|
| 500 |
-
<span className="text-[10px] font-mono font-semibold text-[var(--success)]">{totalScenarioTokens.total}</span>
|
| 501 |
-
</div>
|
| 502 |
-
)}
|
| 503 |
-
</div>
|
| 504 |
-
)}
|
| 505 |
-
</div>
|
| 506 |
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
if (activeBaseUrl) {
|
| 521 |
-
try { await SpecService.updateBaseUrl(activeSpecId, activeBaseUrl); }
|
| 522 |
-
catch (e) { console.error("URL Save failed", e); }
|
| 523 |
-
}
|
| 524 |
-
}}
|
| 525 |
-
placeholder="https://api.example.com"
|
| 526 |
-
/>
|
| 527 |
-
</div>
|
| 528 |
-
</div>
|
| 529 |
)}
|
| 530 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
{!executionPlan ? (
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
<
|
| 541 |
-
<Terminal size={40} className="text-[var(--accent-primary)]" strokeWidth={1.5} />
|
| 542 |
-
</div>
|
| 543 |
</div>
|
| 544 |
-
<
|
|
|
|
| 545 |
AI-Powered API Testing
|
| 546 |
</h1>
|
| 547 |
-
<p
|
| 548 |
{activeSpecId
|
| 549 |
-
?
|
| 550 |
-
:
|
| 551 |
</p>
|
| 552 |
-
|
| 553 |
{!activeSpecId && (
|
| 554 |
<button
|
| 555 |
onClick={() => setActivePage('collections')}
|
| 556 |
-
className="
|
|
|
|
| 557 |
>
|
| 558 |
-
<Layers size={
|
| 559 |
-
Browse Collections
|
| 560 |
</button>
|
| 561 |
)}
|
| 562 |
</div>
|
| 563 |
) : (
|
| 564 |
-
|
| 565 |
-
|
|
|
|
|
|
|
| 566 |
<div>
|
| 567 |
-
<
|
| 568 |
-
<
|
| 569 |
-
|
| 570 |
-
<div className="flex items-center gap-3">
|
| 571 |
-
<div className="flex items-center gap-1.5 text-[11px] text-[var(--text-tertiary)]">
|
| 572 |
-
<div className="w-1 h-1 rounded-full bg-[var(--success)]"></div>
|
| 573 |
-
{Object.values(stepResults).filter(r => r.analysis?.status === 'success').length} completed
|
| 574 |
</div>
|
| 575 |
-
<button
|
| 576 |
-
onClick={runAllSteps}
|
| 577 |
-
disabled={isRunningAll || !!executingStep}
|
| 578 |
-
className="btn-primary disabled:opacity-50 text-white px-4 py-2 text-xs font-semibold rounded-md flex items-center gap-2 shadow-md"
|
| 579 |
-
>
|
| 580 |
-
{isRunningAll ? (
|
| 581 |
-
<><RefreshCw size={13} className="animate-spin" /> Running All…</>
|
| 582 |
-
) : (
|
| 583 |
-
<><Zap size={13} /> Run All</>
|
| 584 |
-
)}
|
| 585 |
-
</button>
|
| 586 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
</div>
|
| 588 |
|
| 589 |
-
{
|
|
|
|
| 590 |
const isRunning = executingStep === step.step;
|
| 591 |
const res = stepResults[step.step];
|
| 592 |
const status = res?.analysis?.status;
|
|
|
|
| 593 |
|
| 594 |
return (
|
| 595 |
-
<div
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
{status === 'success' ? (
|
| 605 |
-
<div className="w-8 h-8 rounded-lg bg-[var(--success-bg)] border border-[var(--success)]/30 flex items-center justify-center">
|
| 606 |
-
<CheckCircle2 size={15} className="text-[var(--success)]" />
|
| 607 |
-
</div>
|
| 608 |
-
) : status === 'failed' ? (
|
| 609 |
-
<div className="w-8 h-8 rounded-lg bg-[var(--danger-bg)] border border-[var(--danger)]/30 flex items-center justify-center">
|
| 610 |
-
<AlertCircle size={15} className="text-[var(--danger)]" />
|
| 611 |
-
</div>
|
| 612 |
-
) : isRunning ? (
|
| 613 |
-
<div className="w-8 h-8 rounded-lg bg-[var(--accent-glow)] border border-[var(--accent-primary)]/40 flex items-center justify-center animate-pulse-glow">
|
| 614 |
-
<RefreshCw size={14} className="text-[var(--accent-primary)] animate-spin" />
|
| 615 |
-
</div>
|
| 616 |
-
) : (
|
| 617 |
-
<div className="w-8 h-8 rounded-lg bg-[var(--bg-tertiary)] border border-[var(--border-default)] flex items-center justify-center">
|
| 618 |
-
<span className="text-[11px] font-mono font-semibold text-[var(--text-secondary)]">{step.step}</span>
|
| 619 |
-
</div>
|
| 620 |
-
)}
|
| 621 |
-
</div>
|
| 622 |
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
<
|
| 627 |
-
|
|
|
|
|
|
|
| 628 |
</div>
|
|
|
|
| 629 |
</div>
|
| 630 |
|
| 631 |
-
<div className="
|
| 632 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 633 |
<button
|
| 634 |
onClick={() => executeStep(step)}
|
| 635 |
disabled={isRunning || isRunningAll}
|
| 636 |
-
className="
|
| 637 |
-
|
| 638 |
>
|
| 639 |
-
<RefreshCw size={
|
| 640 |
</button>
|
| 641 |
)}
|
| 642 |
<button
|
| 643 |
onClick={() => executeStep(step)}
|
| 644 |
disabled={isRunning || isRunningAll}
|
| 645 |
-
className="btn
|
| 646 |
>
|
| 647 |
-
{isRunning
|
| 648 |
-
<><RefreshCw size={
|
| 649 |
-
|
| 650 |
-
<><Zap size={13} /> Execute</>
|
| 651 |
-
)}
|
| 652 |
</button>
|
| 653 |
</div>
|
| 654 |
</div>
|
| 655 |
|
| 656 |
-
{/*
|
| 657 |
{res && (
|
| 658 |
-
<div className="
|
| 659 |
-
{/* AI
|
| 660 |
-
<div className=
|
| 661 |
-
|
| 662 |
-
<
|
| 663 |
-
|
| 664 |
-
<div className="flex items-center justify-between gap-3 mb-0.5">
|
| 665 |
-
<span className="text-[11px] uppercase tracking-wider font-semibold text-[var(--text-secondary)]">AI Analysis</span>
|
| 666 |
-
{res.token_usage && (
|
| 667 |
-
<span className="text-[10px] font-mono text-[var(--text-tertiary)] flex-shrink-0">
|
| 668 |
-
{res.token_usage.total_tokens} tok · P:{res.token_usage.prompt_tokens} C:{res.token_usage.completion_tokens}
|
| 669 |
-
</span>
|
| 670 |
-
)}
|
| 671 |
-
</div>
|
| 672 |
-
<p className="text-xs text-[var(--text-primary)] leading-relaxed">
|
| 673 |
-
{res.analysis.response_summary || (status === 'success' ? 'Step completed successfully.' : 'Step encountered an error.')}
|
| 674 |
-
</p>
|
| 675 |
{res.analysis.extracted_variables && Object.keys(res.analysis.extracted_variables).length > 0 && (
|
| 676 |
-
<div className="
|
| 677 |
{Object.entries(res.analysis.extracted_variables).map(([k, v]) => (
|
| 678 |
-
<span
|
| 679 |
-
<span className="
|
| 680 |
-
<span className="
|
| 681 |
-
<span className="
|
| 682 |
</span>
|
| 683 |
))}
|
| 684 |
</div>
|
| 685 |
)}
|
| 686 |
</div>
|
| 687 |
</div>
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
<div
|
| 692 |
-
<div className="
|
| 693 |
-
<span className="
|
| 694 |
</div>
|
| 695 |
{!res.request ? (
|
| 696 |
-
<div
|
| 697 |
-
Preparing request…
|
| 698 |
-
</div>
|
| 699 |
) : (
|
| 700 |
-
<div
|
| 701 |
-
<div className="
|
| 702 |
-
<
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
res.request.method === 'DELETE' ? 'bg-red-500/15 text-red-400' :
|
| 707 |
-
'bg-violet-500/15 text-violet-400'}`}>
|
| 708 |
-
{res.request.method || 'REQ'}
|
| 709 |
-
</span>
|
| 710 |
-
<span className="text-[var(--text-secondary)] break-all leading-tight">{res.request.url || '(no url)'}</span>
|
| 711 |
</div>
|
| 712 |
-
|
| 713 |
{res.request.headers && Object.keys(res.request.headers).length > 0 && (
|
| 714 |
-
<
|
| 715 |
-
<
|
| 716 |
-
<div className="
|
| 717 |
{Object.entries(res.request.headers).map(([k, v]) => (
|
| 718 |
-
<div
|
|
|
|
|
|
|
|
|
|
| 719 |
))}
|
| 720 |
</div>
|
| 721 |
-
</
|
| 722 |
)}
|
| 723 |
-
|
| 724 |
{res.request.query_params && Object.keys(res.request.query_params).length > 0 && (
|
| 725 |
-
<
|
| 726 |
-
<
|
| 727 |
-
<div className="
|
| 728 |
{Object.entries(res.request.query_params).map(([k, v]) => (
|
| 729 |
-
<div
|
|
|
|
|
|
|
|
|
|
| 730 |
))}
|
| 731 |
</div>
|
| 732 |
-
</
|
| 733 |
)}
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
<
|
| 738 |
-
<pre className="bg-[var(--bg-tertiary)] rounded p-2 border border-[var(--border-subtle)] text-[var(--accent-primary)] overflow-x-auto leading-relaxed whitespace-pre-wrap break-all">{
|
| 739 |
typeof res.request.body === 'string'
|
| 740 |
-
? res.request.body
|
| 741 |
: JSON.stringify(res.request.body, null, 2)
|
| 742 |
}</pre>
|
| 743 |
-
</
|
| 744 |
)}
|
| 745 |
-
|
| 746 |
{res.request.form_data && Object.keys(res.request.form_data).length > 0 && (
|
| 747 |
-
<
|
| 748 |
-
<
|
| 749 |
-
<pre className="
|
| 750 |
-
</
|
| 751 |
-
)}
|
| 752 |
-
|
| 753 |
-
{res.request.files && Object.keys(res.request.files).length > 0 && (
|
| 754 |
-
<div>
|
| 755 |
-
<div className="text-[9px] uppercase tracking-wider text-[var(--text-tertiary)] mb-1.5 font-sans font-semibold">Files</div>
|
| 756 |
-
<div className="space-y-0.5 bg-[var(--bg-tertiary)] rounded p-2 border border-[var(--border-subtle)]">
|
| 757 |
-
{Object.entries(res.request.files).map(([k, v]) => (
|
| 758 |
-
<div key={k} className="flex gap-2"><span className="text-[var(--text-tertiary)]">{k}:</span><span className="text-[var(--accent-secondary)] truncate">{String(v)}</span></div>
|
| 759 |
-
))}
|
| 760 |
-
</div>
|
| 761 |
-
</div>
|
| 762 |
)}
|
| 763 |
</div>
|
| 764 |
)}
|
| 765 |
</div>
|
| 766 |
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
<span className="text-[10px] uppercase tracking-wider font-semibold text-[var(--text-tertiary)]">Response</span>
|
| 771 |
-
{res.response?.status_code !== undefined && (
|
| 772 |
-
<span className={`text-[10px] font-mono font-semibold px-1.5 py-0.5 rounded
|
| 773 |
-
${res.response.status_code >= 200 && res.response.status_code < 300 ? 'bg-[var(--success-bg)] text-[var(--success)]' :
|
| 774 |
-
res.response.status_code >= 400 ? 'bg-[var(--danger-bg)] text-[var(--danger)]' :
|
| 775 |
-
'bg-[var(--warning-bg)] text-[var(--warning)]'}`}>
|
| 776 |
-
{res.response.status_code}
|
| 777 |
-
</span>
|
| 778 |
-
)}
|
| 779 |
</div>
|
| 780 |
{!res.response ? (
|
| 781 |
-
<div
|
| 782 |
-
Waiting for response…
|
| 783 |
-
</div>
|
| 784 |
) : (
|
| 785 |
-
<pre className="
|
| 786 |
-
|
| 787 |
const body = res.response.body;
|
| 788 |
-
if (body ==
|
| 789 |
-
return <span className="text-[var(--text-muted)] italic">(empty body — status {res.response.status_code ?? 'unknown'})</span>;
|
| 790 |
-
}
|
| 791 |
if (typeof body === 'object') {
|
| 792 |
-
try { return JSON.stringify(body, null, 2); }
|
| 793 |
-
catch { return String(body); }
|
| 794 |
}
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
})()}
|
| 799 |
-
</pre>
|
| 800 |
)}
|
| 801 |
</div>
|
| 802 |
</div>
|
|
@@ -808,116 +613,83 @@ function MainApp() {
|
|
| 808 |
</div>
|
| 809 |
)}
|
| 810 |
|
| 811 |
-
{/* OTP
|
| 812 |
{otpPrompt && (
|
| 813 |
-
<div
|
| 814 |
-
<div
|
| 815 |
-
<div
|
| 816 |
-
<div
|
| 817 |
-
<
|
| 818 |
-
|
| 819 |
-
</div>
|
| 820 |
-
<h3 className="text-sm font-semibold text-[var(--text-primary)]">Verification Required</h3>
|
| 821 |
</div>
|
| 822 |
-
<button onClick={() => setOtpPrompt(null)} className="
|
| 823 |
-
<X size={16} />
|
| 824 |
-
</button>
|
| 825 |
</div>
|
| 826 |
-
<div
|
| 827 |
-
<p
|
| 828 |
-
|
| 829 |
</p>
|
| 830 |
-
<
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
/>
|
| 843 |
-
</div>
|
| 844 |
-
<div className="flex gap-2">
|
| 845 |
-
<button
|
| 846 |
-
onClick={handleOtpSubmit}
|
| 847 |
-
className="btn-primary flex-1 text-white py-2.5 text-xs font-semibold rounded-md shadow-md"
|
| 848 |
-
>
|
| 849 |
-
Save & Continue
|
| 850 |
-
</button>
|
| 851 |
-
<button
|
| 852 |
-
onClick={() => setOtpPrompt(null)}
|
| 853 |
-
className="px-4 border border-[var(--border-default)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] py-2.5 text-xs rounded-md transition"
|
| 854 |
-
>
|
| 855 |
-
Cancel
|
| 856 |
-
</button>
|
| 857 |
</div>
|
| 858 |
</div>
|
| 859 |
</div>
|
| 860 |
</div>
|
| 861 |
)}
|
| 862 |
|
| 863 |
-
{/*
|
| 864 |
{selectionPrompt && (
|
| 865 |
-
<div
|
| 866 |
-
<div
|
| 867 |
-
<div
|
| 868 |
-
<div
|
| 869 |
-
<
|
| 870 |
-
|
| 871 |
-
</div>
|
| 872 |
-
<h3 className="text-sm font-semibold text-[var(--text-primary)]">Choose an Option</h3>
|
| 873 |
</div>
|
| 874 |
-
<button onClick={() => setSelectionPrompt(null)} className="
|
| 875 |
-
<X size={16} />
|
| 876 |
-
</button>
|
| 877 |
</div>
|
| 878 |
-
<div
|
| 879 |
-
<p
|
| 880 |
-
|
| 881 |
</p>
|
| 882 |
-
<div
|
| 883 |
{selectionPrompt.options.map((opt, idx) => (
|
| 884 |
<button
|
| 885 |
key={idx}
|
| 886 |
onClick={() => handleSelectionSubmit(opt)}
|
| 887 |
-
className="
|
|
|
|
| 888 |
>
|
| 889 |
-
<div
|
| 890 |
-
|
| 891 |
-
{opt.label || 'Option'}
|
| 892 |
-
</span>
|
| 893 |
-
<ChevronRight size={14} className="text-[var(--text-tertiary)] group-hover:text-[var(--accent-primary)] transition" />
|
| 894 |
</div>
|
| 895 |
-
<div
|
| 896 |
{typeof opt.value === 'object' ? JSON.stringify(opt.value) : String(opt.value)}
|
| 897 |
</div>
|
| 898 |
</button>
|
| 899 |
))}
|
| 900 |
</div>
|
| 901 |
-
|
| 902 |
{selectionPrompt.responseBody && (
|
| 903 |
-
<details
|
| 904 |
-
<summary
|
| 905 |
-
<Code size={12}
|
| 906 |
-
<span>Raw API Response</span>
|
| 907 |
</summary>
|
| 908 |
-
<pre className="
|
| 909 |
-
{(() => {
|
| 910 |
-
try { return JSON.stringify(JSON.parse(selectionPrompt.responseBody), null, 2); }
|
| 911 |
-
catch { return selectionPrompt.responseBody; }
|
| 912 |
-
})()}
|
| 913 |
</pre>
|
| 914 |
</details>
|
| 915 |
)}
|
| 916 |
-
|
| 917 |
-
<button
|
| 918 |
-
onClick={() => setSelectionPrompt(null)}
|
| 919 |
-
className="w-full px-4 border border-[var(--border-default)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] py-2.5 text-xs rounded-md transition"
|
| 920 |
-
>
|
| 921 |
Cancel
|
| 922 |
</button>
|
| 923 |
</div>
|
|
@@ -927,63 +699,67 @@ function MainApp() {
|
|
| 927 |
</div>
|
| 928 |
</div>
|
| 929 |
|
| 930 |
-
{/*
|
| 931 |
-
<div
|
| 932 |
-
<div
|
| 933 |
-
<div className="
|
| 934 |
-
<div className="
|
| 935 |
-
<
|
| 936 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 937 |
</div>
|
| 938 |
-
<
|
| 939 |
-
placeholder={activeSpecId ? "Describe a scenario, e.g. 'Sign up a new user, then create their first project...'" : "Load an API collection to begin"}
|
| 940 |
-
disabled={!activeSpecId || isPlanning}
|
| 941 |
-
value={scenario}
|
| 942 |
-
onChange={e => setScenario(e.target.value)}
|
| 943 |
-
onKeyDown={e => {
|
| 944 |
-
if (e.key === 'Enter' && !e.shiftKey) {
|
| 945 |
-
e.preventDefault();
|
| 946 |
-
handleGeneratePlan();
|
| 947 |
-
}
|
| 948 |
-
}}
|
| 949 |
-
rows={1}
|
| 950 |
-
className="flex-1 bg-transparent text-sm resize-none outline-none py-1.5 max-h-32 min-h-[28px] text-[var(--text-primary)] placeholder-[var(--text-muted)] disabled:opacity-50 leading-relaxed"
|
| 951 |
-
/>
|
| 952 |
<button
|
| 953 |
onClick={handleGeneratePlan}
|
| 954 |
disabled={!activeSpecId || isPlanning || !scenario.trim()}
|
| 955 |
-
className="btn
|
| 956 |
-
title="Generate execution plan"
|
| 957 |
>
|
| 958 |
-
{isPlanning
|
|
|
|
|
|
|
| 959 |
</button>
|
| 960 |
</div>
|
| 961 |
</div>
|
| 962 |
-
<div className="flex items-center justify-between mt-2 px-1">
|
| 963 |
-
<p className="text-[10px] text-[var(--text-muted)]">
|
| 964 |
-
<kbd className="px-1 py-0.5 rounded bg-[var(--bg-tertiary)] border border-[var(--border-subtle)] font-mono text-[9px]">Enter</kbd> to generate · <kbd className="px-1 py-0.5 rounded bg-[var(--bg-tertiary)] border border-[var(--border-subtle)] font-mono text-[9px]">Shift+Enter</kbd> for newline
|
| 965 |
-
</p>
|
| 966 |
-
{activeSpecId && (
|
| 967 |
-
<p className="text-[10px] font-mono text-[var(--text-tertiary)] truncate ml-4">
|
| 968 |
-
{activeSpecName}
|
| 969 |
-
</p>
|
| 970 |
-
)}
|
| 971 |
-
</div>
|
| 972 |
</div>
|
| 973 |
</div>
|
|
|
|
| 974 |
</div>
|
| 975 |
)}
|
| 976 |
|
| 977 |
-
{
|
| 978 |
-
{activePage === '
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
{activePage === '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 982 |
{activePage === 'chat' && (
|
| 983 |
<ChatAssistant
|
| 984 |
-
onOpenInExecutionPanel={() => setActivePage('
|
| 985 |
executeStepFromChat={async (stepDef, changes) => {
|
| 986 |
-
setActivePage('
|
| 987 |
await executeStep(stepDef);
|
| 988 |
return {
|
| 989 |
step_definition: stepDef,
|
|
@@ -993,172 +769,190 @@ function MainApp() {
|
|
| 993 |
}}
|
| 994 |
/>
|
| 995 |
)}
|
|
|
|
| 996 |
</main>
|
| 997 |
|
| 998 |
-
{/*
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
<button
|
| 1021 |
-
onClick={() =>
|
| 1022 |
-
className=
|
| 1023 |
-
|
| 1024 |
-
? 'bg-[var(--bg-elevated)] text-[var(--accent-primary)] shadow-sm'
|
| 1025 |
-
: 'text-[var(--text-tertiary)] hover:text-[var(--text-secondary)]'}`}
|
| 1026 |
>
|
| 1027 |
-
<
|
| 1028 |
-
AI
|
| 1029 |
</button>
|
| 1030 |
</div>
|
| 1031 |
-
<button
|
| 1032 |
-
onClick={() => setRightPanelOpen(false)}
|
| 1033 |
-
className="p-2 rounded-md text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition"
|
| 1034 |
-
title="Collapse panel"
|
| 1035 |
-
>
|
| 1036 |
-
<ChevronRight size={15} />
|
| 1037 |
-
</button>
|
| 1038 |
-
</div>
|
| 1039 |
|
| 1040 |
-
|
| 1041 |
-
|
| 1042 |
-
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
>
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
<div className="divide-y divide-[var(--border-subtle)]">
|
| 1061 |
-
{Object.entries(sessionContextVars).map(([k, v]) => (
|
| 1062 |
-
<div key={k} className="px-3 py-2 hover:bg-[var(--bg-hover)] transition">
|
| 1063 |
-
<div className="text-[10px] font-mono text-[var(--accent-primary)] truncate font-semibold">{k}</div>
|
| 1064 |
-
<div className="text-[11px] font-mono text-[var(--accent-secondary)] truncate mt-0.5">{String(v)}</div>
|
| 1065 |
</div>
|
| 1066 |
-
))
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
</
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
<
|
| 1078 |
-
|
| 1079 |
-
|
| 1080 |
-
|
| 1081 |
-
|
| 1082 |
-
|
| 1083 |
const isSensitive = k.toLowerCase().match(/(password|token|jwt|secret|bearer)/);
|
| 1084 |
-
const
|
| 1085 |
return (
|
| 1086 |
-
<div key={k}
|
| 1087 |
-
<div
|
| 1088 |
-
|
| 1089 |
-
{isSensitive && <span className="text-[8px] text-[var(--warning)]">•</span>}
|
| 1090 |
-
</div>
|
| 1091 |
-
<div className="text-[11px] font-mono text-[var(--accent-secondary)] truncate mt-0.5">{displayVal}</div>
|
| 1092 |
</div>
|
| 1093 |
);
|
| 1094 |
-
})
|
| 1095 |
-
|
| 1096 |
-
|
| 1097 |
-
</
|
| 1098 |
-
</
|
| 1099 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1100 |
|
| 1101 |
-
{/* Chat Panel */}
|
| 1102 |
-
<div className="flex-1 min-h-0 overflow-hidden" style={{ display: rightPanelMode === 'chat' ? 'flex' : 'none', flexDirection: 'column' }}>
|
| 1103 |
-
<ChatAssistant
|
| 1104 |
-
compact={true}
|
| 1105 |
-
allStepResultsProp={stepResults}
|
| 1106 |
-
lastStepResultProp={
|
| 1107 |
-
Object.keys(stepResults).length > 0
|
| 1108 |
-
? stepResults[Math.max(...Object.keys(stepResults).map(Number))]
|
| 1109 |
-
: null
|
| 1110 |
-
}
|
| 1111 |
-
executeStepFromChat={async (stepDef, changes) => {
|
| 1112 |
-
const modifiedStep = changes && Object.keys(changes).length > 0
|
| 1113 |
-
? {
|
| 1114 |
-
...stepDef,
|
| 1115 |
-
body: changes.body !== undefined ? { ...(stepDef.body || {}), ...changes.body } : stepDef.body,
|
| 1116 |
-
query_params: changes.query_params !== undefined ? { ...(stepDef.query_params || {}), ...changes.query_params } : stepDef.query_params,
|
| 1117 |
-
headers: changes.headers !== undefined ? { ...(stepDef.headers || {}), ...changes.headers } : stepDef.headers,
|
| 1118 |
-
path_params: changes.path_params !== undefined ? { ...(stepDef.path_params || {}), ...changes.path_params } : stepDef.path_params,
|
| 1119 |
-
...Object.fromEntries(
|
| 1120 |
-
Object.entries(changes).filter(([k]) =>
|
| 1121 |
-
!['body', 'query_params', 'headers', 'path_params'].includes(k)
|
| 1122 |
-
)
|
| 1123 |
-
)
|
| 1124 |
-
}
|
| 1125 |
-
: stepDef;
|
| 1126 |
-
|
| 1127 |
-
await executeStep(modifiedStep);
|
| 1128 |
-
return {
|
| 1129 |
-
step_definition: modifiedStep,
|
| 1130 |
-
response: stepResults[modifiedStep.step]?.response,
|
| 1131 |
-
analysis: stepResults[modifiedStep.step]?.analysis,
|
| 1132 |
-
};
|
| 1133 |
-
}}
|
| 1134 |
-
/>
|
| 1135 |
</div>
|
| 1136 |
-
</
|
| 1137 |
-
|
| 1138 |
|
| 1139 |
-
{/*
|
| 1140 |
-
{!rightPanelOpen && activePage === '
|
| 1141 |
<button
|
| 1142 |
onClick={() => setRightPanelOpen(true)}
|
| 1143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1144 |
title="Open context panel"
|
| 1145 |
>
|
| 1146 |
-
<ChevronLeft size={
|
| 1147 |
</button>
|
| 1148 |
)}
|
| 1149 |
|
| 1150 |
</div>
|
| 1151 |
|
| 1152 |
-
<ToastContainer toasts={toasts} removeToast={removeToast}
|
| 1153 |
</>
|
| 1154 |
);
|
| 1155 |
}
|
| 1156 |
|
| 1157 |
export default function App() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1158 |
return (
|
| 1159 |
<AppProvider>
|
| 1160 |
<ErrorBoundary>
|
| 1161 |
-
<MainApp
|
| 1162 |
</ErrorBoundary>
|
| 1163 |
</AppProvider>
|
| 1164 |
);
|
|
|
|
| 1 |
+
import React, { useState, useRef, useEffect } from 'react';
|
| 2 |
import {
|
| 3 |
+
Settings, History,
|
| 4 |
ChevronRight, ChevronLeft, Send, Zap, Trash2, RefreshCw,
|
| 5 |
+
User, Layers, FolderOpen, X, Bot, Code,
|
| 6 |
+
Activity, Sparkles, Terminal, CheckCircle2, AlertCircle, Circle,
|
| 7 |
+
Sun, Moon, Database,
|
| 8 |
} from 'lucide-react';
|
| 9 |
import { AppProvider, useAppContext } from './components/AppContext';
|
| 10 |
import CollectionsPage from './components/CollectionsPage';
|
|
|
|
| 15 |
import ChatAssistant from './components/ChatAssistant';
|
| 16 |
import { ToastContainer } from './components/Toast';
|
| 17 |
import ErrorBoundary from './components/ErrorBoundary';
|
| 18 |
+
import { SpecService, SessionService, PlanService, AuthService } from './services/api';
|
| 19 |
+
import LoginPage from './components/LoginPage';
|
| 20 |
+
|
| 21 |
+
/* ── Workflow icon (Activity-like) ─────────────────────────── */
|
| 22 |
+
const WorkflowIcon = ({ size = 15, className = '' }) => (
|
| 23 |
+
<svg width={size} height={size} viewBox="0 0 24 24" fill="none"
|
| 24 |
+
stroke="currentColor" strokeWidth={1.6} strokeLinecap="round" strokeLinejoin="round"
|
| 25 |
+
className={className} aria-hidden="true">
|
| 26 |
+
<rect x="3" y="3" width="6" height="6" rx="1.2"/>
|
| 27 |
+
<rect x="15" y="15" width="6" height="6" rx="1.2"/>
|
| 28 |
+
<path d="M9 6h6a3 3 0 0 1 3 3v6"/>
|
| 29 |
+
</svg>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
);
|
| 31 |
|
| 32 |
function MainApp() {
|
|
|
|
| 42 |
toasts, addToast, removeToast,
|
| 43 |
} = useAppContext();
|
| 44 |
|
| 45 |
+
const [activePage, setActivePage] = useState('workflow');
|
| 46 |
+
const [theme, setTheme] = useState('dark');
|
| 47 |
+
const [collapsed, setCollapsed] = useState(false);
|
| 48 |
const [rightPanelOpen, setRightPanelOpen] = useState(true);
|
| 49 |
const [rightPanelMode, setRightPanelMode] = useState('context');
|
| 50 |
|
| 51 |
+
/* Apply theme to <html data-theme="..."> */
|
| 52 |
+
useEffect(() => {
|
| 53 |
+
document.documentElement.setAttribute('data-theme', theme);
|
| 54 |
+
}, [theme]);
|
|
|
|
| 55 |
|
| 56 |
+
/* External nav events */
|
| 57 |
+
useEffect(() => {
|
| 58 |
+
const handle = (e) => setActivePage(e.detail);
|
| 59 |
+
window.addEventListener('nav-change', handle);
|
| 60 |
+
return () => window.removeEventListener('nav-change', handle);
|
| 61 |
+
}, []);
|
| 62 |
|
| 63 |
const [isPlanning, setIsPlanning] = useState(false);
|
| 64 |
const [executingStep, setExecutingStep] = useState(null);
|
|
|
|
| 67 |
const [otpPrompt, setOtpPrompt] = useState(null);
|
| 68 |
const [otpInput, setOtpInput] = useState('');
|
| 69 |
const [selectionPrompt, setSelectionPrompt] = useState(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
const [planTokenUsage, setPlanTokenUsage] = useState(null);
|
| 71 |
const [totalScenarioTokens, setTotalScenarioTokens] = useState({ prompt: 0, completion: 0, total: 0 });
|
| 72 |
|
| 73 |
+
/* ── Plan generation ─────────────────────────────────────── */
|
| 74 |
const handleGeneratePlan = async () => {
|
| 75 |
+
if (!activeSpecId) { addToast('warning', 'Please select a collection first.'); return; }
|
| 76 |
+
if (!activeBaseUrl) { addToast('warning', 'Please set a Base URL for this collection.'); return; }
|
| 77 |
+
if (!scenario.trim()) { addToast('warning', 'Please describe a test scenario.'); return; }
|
| 78 |
|
| 79 |
setIsPlanning(true);
|
| 80 |
setPlanTokenUsage(null);
|
|
|
|
| 83 |
|
| 84 |
try {
|
| 85 |
const newSid = await startNewSession();
|
| 86 |
+
if (!newSid) throw new Error('Could not initialize fresh session');
|
| 87 |
|
| 88 |
const payload = {
|
| 89 |
spec_content: typeof parsedSpec === 'string' ? parsedSpec : JSON.stringify(parsedSpec),
|
| 90 |
base_url: activeBaseUrl,
|
| 91 |
+
scenario,
|
| 92 |
user_credentials: storedCredentials,
|
| 93 |
spec_id: activeSpecId,
|
| 94 |
+
session_id: newSid,
|
| 95 |
};
|
| 96 |
const data = await PlanService.generatePlan(payload);
|
| 97 |
setExecutionPlan(data.execution_plan || []);
|
|
|
|
| 104 |
setTotalScenarioTokens({
|
| 105 |
prompt: data.token_usage.prompt_tokens,
|
| 106 |
completion: data.token_usage.completion_tokens,
|
| 107 |
+
total: data.token_usage.total_tokens,
|
| 108 |
});
|
| 109 |
}
|
| 110 |
setStepResults({});
|
| 111 |
} catch (err) {
|
| 112 |
+
addToast('error', err.message || 'Plan generation failed.');
|
|
|
|
| 113 |
} finally {
|
| 114 |
setIsPlanning(false);
|
| 115 |
}
|
| 116 |
};
|
| 117 |
|
| 118 |
+
/* ── Step execution ──────────────────────────────────────── */
|
| 119 |
const executeStep = async (stepDef) => {
|
| 120 |
setExecutingStep(stepDef.step);
|
|
|
|
| 121 |
try {
|
| 122 |
+
if (!sessionId) { addToast('error', 'Session not initialized. Please refresh.'); return; }
|
| 123 |
+
if (!activeBaseUrl) { addToast('warning', 'Base URL is missing.'); return; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
await refreshSessionContext();
|
|
|
|
| 126 |
const payload = {
|
| 127 |
session_id: sessionId,
|
| 128 |
step_definition: stepDef,
|
| 129 |
context_variables: sessionContextVars || {},
|
| 130 |
user_credentials: storedCredentials || {},
|
| 131 |
base_url: activeBaseUrl,
|
| 132 |
+
spec_id: activeSpecId,
|
| 133 |
};
|
|
|
|
|
|
|
|
|
|
| 134 |
const execData = await PlanService.executeStep(payload);
|
| 135 |
|
| 136 |
setStepResults(prev => ({
|
|
|
|
| 138 |
[stepDef.step]: {
|
| 139 |
request: execData.executed_request,
|
| 140 |
response: execData.response,
|
| 141 |
+
analysis: { status: 'pending', response_summary: 'Analyzing response with AI…' },
|
| 142 |
+
token_usage: execData.token_usage || { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 },
|
| 143 |
+
},
|
| 144 |
}));
|
| 145 |
|
| 146 |
const analyzePayload = {
|
| 147 |
session_id: sessionId,
|
| 148 |
step: stepDef.step,
|
| 149 |
response_data: execData.response,
|
| 150 |
+
step_definition: stepDef,
|
| 151 |
};
|
| 152 |
const analyzeData = await PlanService.analyzeResponse(analyzePayload);
|
| 153 |
|
| 154 |
const stepTokens = {
|
| 155 |
prompt_tokens: (execData.token_usage?.prompt_tokens || 0) + (analyzeData.token_usage?.prompt_tokens || 0),
|
| 156 |
completion_tokens: (execData.token_usage?.completion_tokens || 0) + (analyzeData.token_usage?.completion_tokens || 0),
|
| 157 |
+
total_tokens: (execData.token_usage?.total_tokens || 0) + (analyzeData.token_usage?.total_tokens || 0),
|
| 158 |
};
|
| 159 |
|
| 160 |
setStepResults(prev => ({
|
| 161 |
...prev,
|
| 162 |
+
[stepDef.step]: { ...prev[stepDef.step], analysis: analyzeData, token_usage: stepTokens },
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
}));
|
| 164 |
|
| 165 |
setTotalScenarioTokens(prev => ({
|
| 166 |
prompt: prev.prompt + stepTokens.prompt_tokens,
|
| 167 |
completion: prev.completion + stepTokens.completion_tokens,
|
| 168 |
+
total: prev.total + stepTokens.total_tokens,
|
| 169 |
}));
|
| 170 |
|
| 171 |
await refreshSessionContext();
|
|
|
|
| 173 |
if (analyzeData.is_otp_required) {
|
| 174 |
setOtpPrompt({ stepDef, otpFieldName: analyzeData.otp_field_name || 'otp' });
|
| 175 |
}
|
|
|
|
| 176 |
if (analyzeData.is_selection_required && analyzeData.selection_options?.length > 0) {
|
| 177 |
setSelectionPrompt({
|
| 178 |
stepDef,
|
| 179 |
fieldName: analyzeData.selection_field_name || 'selected_item',
|
| 180 |
options: analyzeData.selection_options,
|
| 181 |
+
responseBody: execData.response.body,
|
| 182 |
});
|
| 183 |
}
|
|
|
|
| 184 |
} catch (err) {
|
| 185 |
console.error(`Execution failed for step ${stepDef.step}`, err);
|
| 186 |
} finally {
|
|
|
|
| 192 |
if (!executionPlan?.length) return;
|
| 193 |
setIsRunningAll(true);
|
| 194 |
for (const step of executionPlan) {
|
|
|
|
| 195 |
if (otpPrompt || selectionPrompt) break;
|
| 196 |
await executeStep(step);
|
| 197 |
}
|
|
|
|
| 201 |
const handleOtpSubmit = async () => {
|
| 202 |
if (!otpInput.trim()) return;
|
| 203 |
const { stepDef, otpFieldName } = otpPrompt;
|
|
|
|
| 204 |
try {
|
| 205 |
+
await saveProfile({ extra: { [otpFieldName]: otpInput } });
|
|
|
|
| 206 |
setOtpPrompt(null);
|
| 207 |
setOtpInput('');
|
| 208 |
await refreshSessionContext();
|
| 209 |
+
addToast('success', `OTP "${otpInput}" saved as "${otpFieldName}".`);
|
| 210 |
} catch (err) {
|
| 211 |
+
addToast('error', 'Failed to save OTP.');
|
|
|
|
| 212 |
}
|
| 213 |
};
|
| 214 |
|
| 215 |
const handleSelectionSubmit = async (option) => {
|
| 216 |
if (!selectionPrompt) return;
|
|
|
|
|
|
|
| 217 |
try {
|
| 218 |
+
await SessionService.updateContext(sessionId, selectionPrompt.fieldName, option.value);
|
| 219 |
setSelectionPrompt(null);
|
| 220 |
await refreshSessionContext();
|
| 221 |
} catch (err) {
|
| 222 |
+
addToast('error', 'Failed to save selection.');
|
|
|
|
| 223 |
}
|
| 224 |
};
|
| 225 |
|
| 226 |
+
/* ── Nav structure ───────────────────────────────────────── */
|
| 227 |
+
const NAV1 = [
|
| 228 |
+
{ id: 'workflow', label: 'Workflow', Icon: WorkflowIcon, kbd: '1' },
|
| 229 |
+
{ id: 'collections', label: 'Collections', Icon: Layers, kbd: '2' },
|
| 230 |
+
{ id: 'profile', label: 'Profile', Icon: User, kbd: '3' },
|
| 231 |
+
];
|
| 232 |
+
const NAV2 = [
|
| 233 |
+
{ id: 'history', label: 'History', Icon: History, kbd: '4' },
|
| 234 |
+
{ id: 'media', label: 'Media hub', Icon: FolderOpen, kbd: '5' },
|
| 235 |
+
{ id: 'chat', label: 'Assistant', Icon: Bot, kbd: '6' },
|
| 236 |
+
{ id: 'settings', label: 'Settings', Icon: Settings, kbd: '7' },
|
| 237 |
];
|
| 238 |
|
| 239 |
return (
|
| 240 |
<>
|
| 241 |
+
<div className="app">
|
| 242 |
+
|
| 243 |
+
{/* ── Sidebar ─────────────────────────────────��───────── */}
|
| 244 |
+
<aside className={`sidebar${collapsed ? ' collapsed' : ''}`}>
|
| 245 |
+
|
| 246 |
+
<div className="sb-head">
|
| 247 |
+
<div className="sb-mark">A</div>
|
| 248 |
+
{!collapsed && (
|
| 249 |
+
<div className="sb-name">
|
| 250 |
+
apitest <span className="dim">/ workspace</span>
|
| 251 |
</div>
|
| 252 |
+
)}
|
| 253 |
+
<button
|
| 254 |
+
className="sb-toggle"
|
| 255 |
+
onClick={() => setCollapsed(c => !c)}
|
| 256 |
+
title={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
| 257 |
+
>
|
| 258 |
+
{collapsed
|
| 259 |
+
? <ChevronRight size={13}/>
|
| 260 |
+
: <ChevronLeft size={13}/>}
|
| 261 |
+
</button>
|
| 262 |
+
</div>
|
| 263 |
|
| 264 |
+
<div className="sb-section-label">Studio</div>
|
| 265 |
+
<div className="sb-nav">
|
| 266 |
+
{NAV1.map(n => (
|
| 267 |
+
<button
|
| 268 |
+
key={n.id}
|
| 269 |
+
className={`sb-item${activePage === n.id ? ' active' : ''}`}
|
| 270 |
+
onClick={() => setActivePage(n.id)}
|
| 271 |
+
title={collapsed ? n.label : undefined}
|
| 272 |
+
>
|
| 273 |
+
<n.Icon size={15} className="ico"/>
|
| 274 |
+
<span className="lbl">{n.label}</span>
|
| 275 |
+
<span className="kbd">{n.kbd}</span>
|
| 276 |
+
</button>
|
| 277 |
+
))}
|
| 278 |
</div>
|
|
|
|
| 279 |
|
| 280 |
+
<div className="sb-section-label">More</div>
|
| 281 |
+
<div className="sb-nav">
|
| 282 |
+
{NAV2.map(n => (
|
| 283 |
+
<button
|
| 284 |
+
key={n.id}
|
| 285 |
+
className={`sb-item${activePage === n.id ? ' active' : ''}`}
|
| 286 |
+
onClick={() => setActivePage(n.id)}
|
| 287 |
+
title={collapsed ? n.label : undefined}
|
| 288 |
+
>
|
| 289 |
+
<n.Icon size={15} className="ico"/>
|
| 290 |
+
<span className="lbl">{n.label}</span>
|
| 291 |
+
<span className="kbd">{n.kbd}</span>
|
| 292 |
+
</button>
|
| 293 |
+
))}
|
| 294 |
+
</div>
|
| 295 |
|
| 296 |
+
<div className="sb-foot">
|
| 297 |
+
<span className="dot"/>
|
| 298 |
+
{!collapsed && <><span>session live</span><span style={{flex:1}}/></>}
|
| 299 |
+
</div>
|
| 300 |
+
</aside>
|
| 301 |
|
| 302 |
+
{/* ── Main ────────────────────────────────────────────── */}
|
| 303 |
+
<main className="main">
|
| 304 |
+
|
| 305 |
+
{/* ── Topbar ──────────────────────────────────────── */}
|
| 306 |
+
<header className="topbar">
|
| 307 |
+
<div className="crumb">
|
| 308 |
+
<span>workspace</span>
|
| 309 |
+
<span className="sep">/</span>
|
| 310 |
+
<span className="here">
|
| 311 |
+
{activePage === 'workflow' && activeSpecName && activeSpecName !== 'None'
|
| 312 |
+
? activeSpecName
|
| 313 |
+
: activePage}
|
| 314 |
+
</span>
|
| 315 |
+
</div>
|
| 316 |
|
| 317 |
+
<div className="spacer"/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
+
{/* Token counters (workflow page only) */}
|
| 320 |
+
{activePage === 'workflow' && (planTokenUsage || totalScenarioTokens.total > 0) && (
|
| 321 |
+
<div style={{display:'flex',alignItems:'center',gap:6}}>
|
| 322 |
+
{planTokenUsage && (
|
| 323 |
+
<span className="tokstrip">
|
| 324 |
+
<span className="dot"/>plan <b>{planTokenUsage.total_tokens}</b>
|
| 325 |
+
</span>
|
| 326 |
+
)}
|
| 327 |
+
{totalScenarioTokens.total > 0 && (
|
| 328 |
+
<span className="tokstrip">
|
| 329 |
+
<span className="dot" style={{background:'var(--ok)'}}/>
|
| 330 |
+
total <b>{totalScenarioTokens.total}</b>
|
| 331 |
+
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
)}
|
| 333 |
+
</div>
|
| 334 |
+
)}
|
| 335 |
+
|
| 336 |
+
{/* Base URL input (workflow + spec selected) */}
|
| 337 |
+
{activePage === 'workflow' && activeSpecId && (
|
| 338 |
+
<div className="url-input">
|
| 339 |
+
<span className="label">base</span>
|
| 340 |
+
<input
|
| 341 |
+
value={activeBaseUrl || ''}
|
| 342 |
+
onChange={e => setActiveBaseUrl(e.target.value)}
|
| 343 |
+
onBlur={async () => {
|
| 344 |
+
if (activeBaseUrl) {
|
| 345 |
+
try { await SpecService.updateBaseUrl(activeSpecId, activeBaseUrl); }
|
| 346 |
+
catch (e) { console.error('URL save failed', e); }
|
| 347 |
+
}
|
| 348 |
+
}}
|
| 349 |
+
placeholder="https://api.example.com"
|
| 350 |
+
spellCheck={false}
|
| 351 |
+
/>
|
| 352 |
+
</div>
|
| 353 |
+
)}
|
| 354 |
+
|
| 355 |
+
{/* Theme toggle */}
|
| 356 |
+
<div className="theme-toggle">
|
| 357 |
+
<button
|
| 358 |
+
className={theme === 'light' ? 'on' : ''}
|
| 359 |
+
onClick={() => setTheme('light')}
|
| 360 |
+
title="Light theme"
|
| 361 |
+
>
|
| 362 |
+
<Sun size={12} className="ico"/> light
|
| 363 |
+
</button>
|
| 364 |
+
<button
|
| 365 |
+
className={theme === 'dark' ? 'on' : ''}
|
| 366 |
+
onClick={() => setTheme('dark')}
|
| 367 |
+
title="Dark theme"
|
| 368 |
+
>
|
| 369 |
+
<Moon size={12} className="ico"/> dark
|
| 370 |
+
</button>
|
| 371 |
+
</div>
|
| 372 |
+
</header>
|
| 373 |
+
|
| 374 |
+
{/* ── Page content ─────────────────────────────────── */}
|
| 375 |
|
| 376 |
+
{/* WORKFLOW PAGE */}
|
| 377 |
+
{activePage === 'workflow' && (
|
| 378 |
+
<div style={{display:'flex',flexDirection:'column',flex:1,minHeight:0,overflow:'hidden'}}>
|
| 379 |
+
|
| 380 |
+
{/* Scrollable plan area */}
|
| 381 |
+
<div style={{flex:1,overflowY:'auto'}}>
|
| 382 |
+
<div style={{maxWidth:900,margin:'0 auto',padding:'32px 32px 24px'}}>
|
| 383 |
|
| 384 |
{!executionPlan ? (
|
| 385 |
+
/* ── Empty state ── */
|
| 386 |
+
<div style={{display:'flex',flexDirection:'column',alignItems:'center',justifyContent:'center',minHeight:'55vh',textAlign:'center'}}>
|
| 387 |
+
<div style={{padding:'20px',borderRadius:12,background:'var(--bg-2)',border:'1px solid var(--line-2)',marginBottom:28}}>
|
| 388 |
+
<Terminal size={36} style={{color:'var(--accent)'}} strokeWidth={1.5}/>
|
|
|
|
|
|
|
| 389 |
</div>
|
| 390 |
+
<div className="h-eyebrow" style={{marginBottom:8}}>Workflow Studio</div>
|
| 391 |
+
<h1 style={{fontSize:22,fontWeight:600,color:'var(--fg-0)',letterSpacing:'-0.01em',margin:'0 0 10px'}}>
|
| 392 |
AI-Powered API Testing
|
| 393 |
</h1>
|
| 394 |
+
<p style={{fontSize:12.5,color:'var(--fg-2)',maxWidth:420,lineHeight:1.65,margin:0}}>
|
| 395 |
{activeSpecId
|
| 396 |
+
? 'Describe a test scenario below and Claude will generate a complete execution plan for your API.'
|
| 397 |
+
: 'Start by loading a collection from the sidebar.'}
|
| 398 |
</p>
|
|
|
|
| 399 |
{!activeSpecId && (
|
| 400 |
<button
|
| 401 |
onClick={() => setActivePage('collections')}
|
| 402 |
+
className="btn"
|
| 403 |
+
style={{marginTop:24,gap:8}}
|
| 404 |
>
|
| 405 |
+
<Layers size={13}/> Browse Collections
|
|
|
|
| 406 |
</button>
|
| 407 |
)}
|
| 408 |
</div>
|
| 409 |
) : (
|
| 410 |
+
/* ── Execution plan ── */
|
| 411 |
+
<div>
|
| 412 |
+
{/* Plan header */}
|
| 413 |
+
<div className="plan-meta">
|
| 414 |
<div>
|
| 415 |
+
<div className="h-eyebrow">Execution plan</div>
|
| 416 |
+
<div style={{display:'flex',alignItems:'baseline',gap:10,marginTop:2}}>
|
| 417 |
+
<span style={{fontSize:15,fontWeight:600,color:'var(--fg-0)'}}>{executionPlan.length} steps</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
</div>
|
| 420 |
+
<div className="grow"/>
|
| 421 |
+
<div style={{display:'flex',alignItems:'center',gap:6,fontSize:12,color:'var(--fg-2)'}}>
|
| 422 |
+
<span style={{width:6,height:6,borderRadius:'50%',background:'var(--ok)',display:'inline-block'}}/>
|
| 423 |
+
{Object.values(stepResults).filter(r => r.analysis?.status === 'success').length}
|
| 424 |
+
<span style={{color:'var(--fg-3)'}}>/ {executionPlan.length} ok</span>
|
| 425 |
+
</div>
|
| 426 |
+
<div className="progress">
|
| 427 |
+
<i style={{width: `${Math.round((Object.values(stepResults).filter(r => r.analysis?.status === 'success').length / executionPlan.length) * 100)}%`}}/>
|
| 428 |
+
</div>
|
| 429 |
+
<button className="btn" onClick={() => { setExecutionPlan(null); setStepResults({}); }}>
|
| 430 |
+
<RefreshCw size={13}/> Reset
|
| 431 |
+
</button>
|
| 432 |
+
<button
|
| 433 |
+
className="btn btn-primary"
|
| 434 |
+
onClick={runAllSteps}
|
| 435 |
+
disabled={isRunningAll || !!executingStep}
|
| 436 |
+
style={{gap:6}}
|
| 437 |
+
>
|
| 438 |
+
{isRunningAll
|
| 439 |
+
? <><RefreshCw size={13} style={{animation:'spin 1s linear infinite'}}/> Running…</>
|
| 440 |
+
: <><Zap size={13}/> Run all</>}
|
| 441 |
+
</button>
|
| 442 |
</div>
|
| 443 |
|
| 444 |
+
{/* Steps */}
|
| 445 |
+
{executionPlan.map(step => {
|
| 446 |
const isRunning = executingStep === step.step;
|
| 447 |
const res = stepResults[step.step];
|
| 448 |
const status = res?.analysis?.status;
|
| 449 |
+
const stateClass = status === 'success' ? ' is-ok' : status === 'failed' ? ' is-err' : isRunning ? ' is-running' : '';
|
| 450 |
|
| 451 |
return (
|
| 452 |
+
<div key={step.step} className={`step${stateClass}`}>
|
| 453 |
+
<div className="step-row">
|
| 454 |
+
{/* Step number / status indicator */}
|
| 455 |
+
<div className="step-num">
|
| 456 |
+
{status === 'success' ? <CheckCircle2 size={14}/>
|
| 457 |
+
: status === 'failed' ? <AlertCircle size={14}/>
|
| 458 |
+
: isRunning ? <RefreshCw size={13} style={{animation:'spin 1s linear infinite'}}/>
|
| 459 |
+
: step.step}
|
| 460 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
|
| 462 |
+
<div className="step-main">
|
| 463 |
+
<div className="step-title">
|
| 464 |
+
<span className={`method m-${step.method}`}>{step.method}</span>
|
| 465 |
+
<span className="endpoint">
|
| 466 |
+
<span className="path">{step.endpoint}</span>
|
| 467 |
+
</span>
|
| 468 |
+
{isRunning && <span className="pill pill-acc">running</span>}
|
| 469 |
</div>
|
| 470 |
+
<div className="step-purpose">{step.purpose}</div>
|
| 471 |
</div>
|
| 472 |
|
| 473 |
+
<div className="step-actions">
|
| 474 |
+
{res?.token_usage && (
|
| 475 |
+
<span className="tokstrip"><b>{res.token_usage.total_tokens.toLocaleString()}</b> tok</span>
|
| 476 |
+
)}
|
| 477 |
+
{res?.response?.status_code !== undefined && (
|
| 478 |
+
<span className={`pill ${res.response.status_code >= 200 && res.response.status_code < 300 ? 'pill-ok' : res.response.status_code >= 400 ? 'pill-err' : 'pill-warn'}`}>
|
| 479 |
+
{res.response.status_code}
|
| 480 |
+
</span>
|
| 481 |
+
)}
|
| 482 |
+
{status === 'failed' && (
|
| 483 |
<button
|
| 484 |
onClick={() => executeStep(step)}
|
| 485 |
disabled={isRunning || isRunningAll}
|
| 486 |
+
className="btn"
|
| 487 |
+
style={{color:'var(--warn)',borderColor:'var(--warn-soft)'}}
|
| 488 |
>
|
| 489 |
+
<RefreshCw size={12}/> Retry
|
| 490 |
</button>
|
| 491 |
)}
|
| 492 |
<button
|
| 493 |
onClick={() => executeStep(step)}
|
| 494 |
disabled={isRunning || isRunningAll}
|
| 495 |
+
className="btn btn-primary"
|
| 496 |
>
|
| 497 |
+
{isRunning
|
| 498 |
+
? <><RefreshCw size={12} style={{animation:'spin 1s linear infinite'}}/> Running</>
|
| 499 |
+
: <><Zap size={12}/> Execute</>}
|
|
|
|
|
|
|
| 500 |
</button>
|
| 501 |
</div>
|
| 502 |
</div>
|
| 503 |
|
| 504 |
+
{/* Step result body */}
|
| 505 |
{res && (
|
| 506 |
+
<div className="step-body">
|
| 507 |
+
{/* AI analysis */}
|
| 508 |
+
<div className="step-analysis">
|
| 509 |
+
<span className="tag">analysis</span>
|
| 510 |
+
<div className="body">
|
| 511 |
+
{res.analysis.response_summary || (status === 'success' ? 'Step completed successfully.' : status === 'failed' ? 'Step encountered an error.' : 'Analyzing…')}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
{res.analysis.extracted_variables && Object.keys(res.analysis.extracted_variables).length > 0 && (
|
| 513 |
+
<div className="vars">
|
| 514 |
{Object.entries(res.analysis.extracted_variables).map(([k, v]) => (
|
| 515 |
+
<span className="var" key={k}>
|
| 516 |
+
<span className="k">{k}</span>
|
| 517 |
+
<span className="eq">=</span>
|
| 518 |
+
<span className="v">{String(v).slice(0, 60)}</span>
|
| 519 |
</span>
|
| 520 |
))}
|
| 521 |
</div>
|
| 522 |
)}
|
| 523 |
</div>
|
| 524 |
</div>
|
| 525 |
+
|
| 526 |
+
{/* Request / Response */}
|
| 527 |
+
<div className="reqres">
|
| 528 |
+
<div>
|
| 529 |
+
<div className="rr-head">
|
| 530 |
+
<span className="lbl">Request</span>
|
| 531 |
</div>
|
| 532 |
{!res.request ? (
|
| 533 |
+
<div style={{fontSize:11,color:'var(--fg-3)',fontStyle:'italic'}}>Preparing…</div>
|
|
|
|
|
|
|
| 534 |
) : (
|
| 535 |
+
<div style={{fontSize:11.5}}>
|
| 536 |
+
<div className="kv-block" style={{marginBottom:8}}>
|
| 537 |
+
<div className="kv-row">
|
| 538 |
+
<span className="k">URL</span>
|
| 539 |
+
<span className="v">{res.request.url}</span>
|
| 540 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
</div>
|
|
|
|
| 542 |
{res.request.headers && Object.keys(res.request.headers).length > 0 && (
|
| 543 |
+
<>
|
| 544 |
+
<span className="kv-label">Headers</span>
|
| 545 |
+
<div className="kv-block" style={{marginBottom:8}}>
|
| 546 |
{Object.entries(res.request.headers).map(([k, v]) => (
|
| 547 |
+
<div className="kv-row" key={k}>
|
| 548 |
+
<span className="k">{k}:</span>
|
| 549 |
+
<span className="v">{v}</span>
|
| 550 |
+
</div>
|
| 551 |
))}
|
| 552 |
</div>
|
| 553 |
+
</>
|
| 554 |
)}
|
|
|
|
| 555 |
{res.request.query_params && Object.keys(res.request.query_params).length > 0 && (
|
| 556 |
+
<>
|
| 557 |
+
<span className="kv-label">Query</span>
|
| 558 |
+
<div className="kv-block" style={{marginBottom:8}}>
|
| 559 |
{Object.entries(res.request.query_params).map(([k, v]) => (
|
| 560 |
+
<div className="kv-row" key={k}>
|
| 561 |
+
<span className="k">{k}=</span>
|
| 562 |
+
<span className="v">{v}</span>
|
| 563 |
+
</div>
|
| 564 |
))}
|
| 565 |
</div>
|
| 566 |
+
</>
|
| 567 |
)}
|
| 568 |
+
{res.request.body != null && (
|
| 569 |
+
<>
|
| 570 |
+
<span className="kv-label">Body</span>
|
| 571 |
+
<pre className="code">{
|
|
|
|
| 572 |
typeof res.request.body === 'string'
|
| 573 |
+
? (() => { try { return JSON.stringify(JSON.parse(res.request.body), null, 2); } catch { return res.request.body; } })()
|
| 574 |
: JSON.stringify(res.request.body, null, 2)
|
| 575 |
}</pre>
|
| 576 |
+
</>
|
| 577 |
)}
|
|
|
|
| 578 |
{res.request.form_data && Object.keys(res.request.form_data).length > 0 && (
|
| 579 |
+
<>
|
| 580 |
+
<span className="kv-label">Form data</span>
|
| 581 |
+
<pre className="code">{JSON.stringify(res.request.form_data, null, 2)}</pre>
|
| 582 |
+
</>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
)}
|
| 584 |
</div>
|
| 585 |
)}
|
| 586 |
</div>
|
| 587 |
|
| 588 |
+
<div>
|
| 589 |
+
<div className="rr-head">
|
| 590 |
+
<span className="lbl">Response</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
</div>
|
| 592 |
{!res.response ? (
|
| 593 |
+
<div style={{fontSize:11,color:'var(--fg-3)',fontStyle:'italic'}}>Waiting…</div>
|
|
|
|
|
|
|
| 594 |
) : (
|
| 595 |
+
<pre className="code">{
|
| 596 |
+
(() => {
|
| 597 |
const body = res.response.body;
|
| 598 |
+
if (body == null || body === '') return '(empty)';
|
|
|
|
|
|
|
| 599 |
if (typeof body === 'object') {
|
| 600 |
+
try { return JSON.stringify(body, null, 2); } catch { return String(body); }
|
|
|
|
| 601 |
}
|
| 602 |
+
try { return JSON.stringify(JSON.parse(body), null, 2); } catch { return String(body); }
|
| 603 |
+
})()
|
| 604 |
+
}</pre>
|
|
|
|
|
|
|
| 605 |
)}
|
| 606 |
</div>
|
| 607 |
</div>
|
|
|
|
| 613 |
</div>
|
| 614 |
)}
|
| 615 |
|
| 616 |
+
{/* OTP modal */}
|
| 617 |
{otpPrompt && (
|
| 618 |
+
<div style={{position:'fixed',inset:0,zIndex:50,display:'flex',alignItems:'center',justifyContent:'center',background:'rgba(0,0,0,0.7)',backdropFilter:'blur(8px)',padding:16}}>
|
| 619 |
+
<div style={{background:'var(--bg-1)',border:'1px solid var(--line-3)',borderRadius:10,width:'100%',maxWidth:420,overflow:'hidden',boxShadow:'var(--shadow-md)'}}>
|
| 620 |
+
<div style={{padding:'12px 16px',borderBottom:'1px solid var(--line-1)',display:'flex',alignItems:'center',justifyContent:'space-between'}}>
|
| 621 |
+
<div style={{display:'flex',alignItems:'center',gap:8}}>
|
| 622 |
+
<Zap size={14} style={{color:'var(--accent)'}}/>
|
| 623 |
+
<span style={{fontSize:13,fontWeight:600,color:'var(--fg-0)'}}>Verification Required</span>
|
|
|
|
|
|
|
| 624 |
</div>
|
| 625 |
+
<button onClick={() => setOtpPrompt(null)} className="ico-btn"><X size={14}/></button>
|
|
|
|
|
|
|
| 626 |
</div>
|
| 627 |
+
<div style={{padding:20}}>
|
| 628 |
+
<p style={{fontSize:12,color:'var(--fg-2)',marginBottom:14,lineHeight:1.6}}>
|
| 629 |
+
Enter the verification code to save it to your session context.
|
| 630 |
</p>
|
| 631 |
+
<span className="kv-label">Field: <span style={{color:'var(--accent)'}}>{otpPrompt.otpFieldName}</span></span>
|
| 632 |
+
<input
|
| 633 |
+
className="input"
|
| 634 |
+
autoFocus
|
| 635 |
+
placeholder="Enter code…"
|
| 636 |
+
value={otpInput}
|
| 637 |
+
onChange={e => setOtpInput(e.target.value)}
|
| 638 |
+
onKeyDown={e => { if (e.key === 'Enter') handleOtpSubmit(); }}
|
| 639 |
+
style={{marginBottom:12}}
|
| 640 |
+
/>
|
| 641 |
+
<div style={{display:'flex',gap:8}}>
|
| 642 |
+
<button onClick={handleOtpSubmit} className="btn btn-primary" style={{flex:1}}>Save & Continue</button>
|
| 643 |
+
<button onClick={() => setOtpPrompt(null)} className="btn">Cancel</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
</div>
|
| 645 |
</div>
|
| 646 |
</div>
|
| 647 |
</div>
|
| 648 |
)}
|
| 649 |
|
| 650 |
+
{/* Selection modal */}
|
| 651 |
{selectionPrompt && (
|
| 652 |
+
<div style={{position:'fixed',inset:0,zIndex:50,display:'flex',alignItems:'center',justifyContent:'center',background:'rgba(0,0,0,0.7)',backdropFilter:'blur(8px)',padding:16}}>
|
| 653 |
+
<div style={{background:'var(--bg-1)',border:'1px solid var(--line-3)',borderRadius:10,width:'100%',maxWidth:480,maxHeight:'80vh',overflow:'hidden',display:'flex',flexDirection:'column',boxShadow:'var(--shadow-md)'}}>
|
| 654 |
+
<div style={{padding:'12px 16px',borderBottom:'1px solid var(--line-1)',display:'flex',alignItems:'center',justifyContent:'space-between',flexShrink:0}}>
|
| 655 |
+
<div style={{display:'flex',alignItems:'center',gap:8}}>
|
| 656 |
+
<Layers size={14} style={{color:'var(--accent)'}}/>
|
| 657 |
+
<span style={{fontSize:13,fontWeight:600,color:'var(--fg-0)'}}>Choose an Option</span>
|
|
|
|
|
|
|
| 658 |
</div>
|
| 659 |
+
<button onClick={() => setSelectionPrompt(null)} className="ico-btn"><X size={14}/></button>
|
|
|
|
|
|
|
| 660 |
</div>
|
| 661 |
+
<div style={{padding:20,overflowY:'auto'}}>
|
| 662 |
+
<p style={{fontSize:12,color:'var(--fg-2)',marginBottom:14,lineHeight:1.6}}>
|
| 663 |
+
Select one to save as <code style={{color:'var(--accent)'}}>{selectionPrompt.fieldName}</code>.
|
| 664 |
</p>
|
| 665 |
+
<div style={{display:'flex',flexDirection:'column',gap:6,marginBottom:14}}>
|
| 666 |
{selectionPrompt.options.map((opt, idx) => (
|
| 667 |
<button
|
| 668 |
key={idx}
|
| 669 |
onClick={() => handleSelectionSubmit(opt)}
|
| 670 |
+
className="col-card"
|
| 671 |
+
style={{textAlign:'left',padding:'10px 14px',borderRadius:6,cursor:'pointer'}}
|
| 672 |
>
|
| 673 |
+
<div style={{fontSize:13,color:'var(--fg-0)',fontWeight:500,marginBottom:2}}>
|
| 674 |
+
{opt.label || 'Option'}
|
|
|
|
|
|
|
|
|
|
| 675 |
</div>
|
| 676 |
+
<div style={{fontSize:10.5,color:'var(--fg-3)',overflow:'hidden',textOverflow:'ellipsis',whiteSpace:'nowrap'}}>
|
| 677 |
{typeof opt.value === 'object' ? JSON.stringify(opt.value) : String(opt.value)}
|
| 678 |
</div>
|
| 679 |
</button>
|
| 680 |
))}
|
| 681 |
</div>
|
|
|
|
| 682 |
{selectionPrompt.responseBody && (
|
| 683 |
+
<details style={{cursor:'pointer'}}>
|
| 684 |
+
<summary style={{fontSize:11,color:'var(--fg-3)',display:'flex',alignItems:'center',gap:6,marginBottom:6}}>
|
| 685 |
+
<Code size={12}/> Raw response
|
|
|
|
| 686 |
</summary>
|
| 687 |
+
<pre className="code" style={{maxHeight:160}}>
|
| 688 |
+
{(() => { try { return JSON.stringify(JSON.parse(selectionPrompt.responseBody), null, 2); } catch { return selectionPrompt.responseBody; } })()}
|
|
|
|
|
|
|
|
|
|
| 689 |
</pre>
|
| 690 |
</details>
|
| 691 |
)}
|
| 692 |
+
<button onClick={() => setSelectionPrompt(null)} className="btn" style={{width:'100%',justifyContent:'center',marginTop:8}}>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 693 |
Cancel
|
| 694 |
</button>
|
| 695 |
</div>
|
|
|
|
| 699 |
</div>
|
| 700 |
</div>
|
| 701 |
|
| 702 |
+
{/* Scenario composer — pinned to bottom */}
|
| 703 |
+
<div style={{borderTop:'1px solid var(--line-1)',background:'var(--bg-1)',flexShrink:0}}>
|
| 704 |
+
<div style={{maxWidth:900,margin:'0 auto',padding:'14px 32px'}}>
|
| 705 |
+
<div className="composer">
|
| 706 |
+
<div className="composer-head">
|
| 707 |
+
<span className="dot"/>
|
| 708 |
+
<span>scenario.txt</span>
|
| 709 |
+
{activeSpecName && activeSpecName !== 'None' && (
|
| 710 |
+
<><span style={{color:'var(--fg-4)'}}>·</span><span style={{color:'var(--fg-3)'}}>{activeSpecName}</span></>
|
| 711 |
+
)}
|
| 712 |
+
</div>
|
| 713 |
+
<textarea
|
| 714 |
+
rows={2}
|
| 715 |
+
placeholder={activeSpecId ? "Describe a test scenario, e.g. 'Sign in, create an order, charge it, verify paid'" : "Load a collection from the sidebar to begin"}
|
| 716 |
+
disabled={!activeSpecId || isPlanning}
|
| 717 |
+
value={scenario}
|
| 718 |
+
onChange={e => setScenario(e.target.value)}
|
| 719 |
+
onKeyDown={e => {
|
| 720 |
+
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
| 721 |
+
e.preventDefault();
|
| 722 |
+
handleGeneratePlan();
|
| 723 |
+
}
|
| 724 |
+
}}
|
| 725 |
+
/>
|
| 726 |
+
<div className="composer-foot">
|
| 727 |
+
<div className="hint">
|
| 728 |
+
<kbd>⌘</kbd><kbd>↵</kbd> generate plan
|
| 729 |
</div>
|
| 730 |
+
<button className="btn btn-ghost" onClick={() => setScenario('')}>Clear</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
<button
|
| 732 |
onClick={handleGeneratePlan}
|
| 733 |
disabled={!activeSpecId || isPlanning || !scenario.trim()}
|
| 734 |
+
className="btn btn-primary"
|
|
|
|
| 735 |
>
|
| 736 |
+
{isPlanning
|
| 737 |
+
? <><RefreshCw size={13} style={{animation:'spin 1s linear infinite'}}/> Planning…</>
|
| 738 |
+
: <><Sparkles size={13}/> Generate plan</>}
|
| 739 |
</button>
|
| 740 |
</div>
|
| 741 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 742 |
</div>
|
| 743 |
</div>
|
| 744 |
+
|
| 745 |
</div>
|
| 746 |
)}
|
| 747 |
|
| 748 |
+
{/* OTHER PAGES */}
|
| 749 |
+
{activePage === 'collections' && (
|
| 750 |
+
<CollectionsPage onCollectionSelected={() => setActivePage('workflow')}/>
|
| 751 |
+
)}
|
| 752 |
+
{activePage === 'profile' && <ProfilePage/>}
|
| 753 |
+
{activePage === 'history' && <HistoryPage/>}
|
| 754 |
+
{activePage === 'media' && (
|
| 755 |
+
<MediaHubPage activeSpecId={activeSpecId} activeSpecName={activeSpecName}/>
|
| 756 |
+
)}
|
| 757 |
+
{activePage === 'settings' && <SettingsPage/>}
|
| 758 |
{activePage === 'chat' && (
|
| 759 |
<ChatAssistant
|
| 760 |
+
onOpenInExecutionPanel={() => setActivePage('workflow')}
|
| 761 |
executeStepFromChat={async (stepDef, changes) => {
|
| 762 |
+
setActivePage('workflow');
|
| 763 |
await executeStep(stepDef);
|
| 764 |
return {
|
| 765 |
step_definition: stepDef,
|
|
|
|
| 769 |
}}
|
| 770 |
/>
|
| 771 |
)}
|
| 772 |
+
|
| 773 |
</main>
|
| 774 |
|
| 775 |
+
{/* ── Right context panel (workflow page only) ───────── */}
|
| 776 |
+
{activePage === 'workflow' && (
|
| 777 |
+
<aside style={{
|
| 778 |
+
display:'flex',
|
| 779 |
+
flexShrink:0,
|
| 780 |
+
background:'var(--bg-1)',
|
| 781 |
+
borderLeft:'1px solid var(--line-1)',
|
| 782 |
+
transition:'width 280ms ease',
|
| 783 |
+
width: rightPanelOpen ? (rightPanelMode === 'chat' ? 360 : 300) : 0,
|
| 784 |
+
overflow:'hidden',
|
| 785 |
+
}}>
|
| 786 |
+
<div style={{width: rightPanelMode === 'chat' ? 360 : 300, height:'100%', display:'flex', flexDirection:'column', flexShrink:0}}>
|
| 787 |
+
|
| 788 |
+
{/* Panel tab header */}
|
| 789 |
+
<div style={{height:48,display:'flex',alignItems:'center',borderBottom:'1px solid var(--line-1)',padding:'0 8px',gap:4,flexShrink:0}}>
|
| 790 |
+
<div style={{display:'flex',flex:1,background:'var(--bg-2)',borderRadius:4,padding:2}}>
|
| 791 |
+
<button
|
| 792 |
+
onClick={() => setRightPanelMode('context')}
|
| 793 |
+
style={{
|
| 794 |
+
flex:1,padding:'4px 8px',borderRadius:3,border:0,
|
| 795 |
+
fontSize:10.5,fontWeight:600,letterSpacing:'0.08em',textTransform:'uppercase',
|
| 796 |
+
background: rightPanelMode === 'context' ? 'var(--bg-0)' : 'transparent',
|
| 797 |
+
color: rightPanelMode === 'context' ? 'var(--fg-0)' : 'var(--fg-3)',
|
| 798 |
+
display:'flex',alignItems:'center',justifyContent:'center',gap:5,
|
| 799 |
+
transition:'all 120ms',cursor:'pointer',
|
| 800 |
+
}}
|
| 801 |
+
>
|
| 802 |
+
<Database size={10}/> Context
|
| 803 |
+
</button>
|
| 804 |
+
<button
|
| 805 |
+
onClick={() => setRightPanelMode('chat')}
|
| 806 |
+
style={{
|
| 807 |
+
flex:1,padding:'4px 8px',borderRadius:3,border:0,
|
| 808 |
+
fontSize:10.5,fontWeight:600,letterSpacing:'0.08em',textTransform:'uppercase',
|
| 809 |
+
background: rightPanelMode === 'chat' ? 'var(--bg-0)' : 'transparent',
|
| 810 |
+
color: rightPanelMode === 'chat' ? 'var(--accent)' : 'var(--fg-3)',
|
| 811 |
+
display:'flex',alignItems:'center',justifyContent:'center',gap:5,
|
| 812 |
+
transition:'all 120ms',cursor:'pointer',
|
| 813 |
+
}}
|
| 814 |
+
>
|
| 815 |
+
<Bot size={10}/> AI
|
| 816 |
+
</button>
|
| 817 |
+
</div>
|
| 818 |
<button
|
| 819 |
+
onClick={() => setRightPanelOpen(false)}
|
| 820 |
+
className="ico-btn"
|
| 821 |
+
title="Collapse panel"
|
|
|
|
|
|
|
| 822 |
>
|
| 823 |
+
<ChevronRight size={14}/>
|
|
|
|
| 824 |
</button>
|
| 825 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 826 |
|
| 827 |
+
{/* Context panel */}
|
| 828 |
+
<div style={{flex:1,overflowY:'auto',padding:14,display: rightPanelMode === 'context' ? 'flex' : 'none',flexDirection:'column',gap:16}}>
|
| 829 |
+
<section>
|
| 830 |
+
<div style={{display:'flex',alignItems:'center',justifyContent:'space-between',marginBottom:8}}>
|
| 831 |
+
<span className="h-eyebrow">Session Variables</span>
|
| 832 |
+
<button onClick={refreshSessionContext} className="ico-btn" style={{width:22,height:22}} title="Refresh">
|
| 833 |
+
<RefreshCw size={11}/>
|
| 834 |
+
</button>
|
| 835 |
+
</div>
|
| 836 |
+
<div className="panel" style={{overflow:'hidden'}}>
|
| 837 |
+
{Object.keys(sessionContextVars || {}).length === 0 ? (
|
| 838 |
+
<div style={{padding:14,textAlign:'center'}}>
|
| 839 |
+
<Circle size={18} style={{margin:'0 auto 6px',color:'var(--fg-4)',display:'block'}} strokeWidth={1.5}/>
|
| 840 |
+
<p style={{fontSize:11,color:'var(--fg-3)',margin:0,fontStyle:'italic'}}>No variables extracted</p>
|
| 841 |
+
</div>
|
| 842 |
+
) : (
|
| 843 |
+
Object.entries(sessionContextVars).map(([k, v]) => (
|
| 844 |
+
<div key={k} style={{padding:'6px 12px',borderBottom:'1px solid var(--line-1)'}}>
|
| 845 |
+
<div style={{fontSize:10,fontWeight:600,color:'var(--accent)',marginBottom:2}}>{k}</div>
|
| 846 |
+
<div style={{fontSize:11,color:'var(--fg-2)',overflow:'hidden',textOverflow:'ellipsis',whiteSpace:'nowrap'}}>{String(v)}</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 847 |
</div>
|
| 848 |
+
))
|
| 849 |
+
)}
|
| 850 |
+
</div>
|
| 851 |
+
</section>
|
| 852 |
+
|
| 853 |
+
<section>
|
| 854 |
+
<div style={{marginBottom:8}}>
|
| 855 |
+
<span className="h-eyebrow">Test Credentials</span>
|
| 856 |
+
</div>
|
| 857 |
+
<div className="panel" style={{overflow:'hidden'}}>
|
| 858 |
+
{Object.keys(storedCredentials || {}).length === 0 ? (
|
| 859 |
+
<div style={{padding:14,textAlign:'center'}}>
|
| 860 |
+
<Circle size={18} style={{margin:'0 auto 6px',color:'var(--fg-4)',display:'block'}} strokeWidth={1.5}/>
|
| 861 |
+
<p style={{fontSize:11,color:'var(--fg-3)',margin:0,fontStyle:'italic'}}>No credentials loaded</p>
|
| 862 |
+
</div>
|
| 863 |
+
) : (
|
| 864 |
+
Object.entries(storedCredentials).filter(([k]) => k !== '_clear').map(([k, v]) => {
|
| 865 |
const isSensitive = k.toLowerCase().match(/(password|token|jwt|secret|bearer)/);
|
| 866 |
+
const display = isSensitive && v ? `${String(v).slice(0,4)}••••` : String(v);
|
| 867 |
return (
|
| 868 |
+
<div key={k} style={{padding:'6px 12px',borderBottom:'1px solid var(--line-1)'}}>
|
| 869 |
+
<div style={{fontSize:10,fontWeight:600,color:'var(--accent)',marginBottom:2}}>{k}</div>
|
| 870 |
+
<div style={{fontSize:11,color:'var(--fg-2)',overflow:'hidden',textOverflow:'ellipsis',whiteSpace:'nowrap'}}>{display}</div>
|
|
|
|
|
|
|
|
|
|
| 871 |
</div>
|
| 872 |
);
|
| 873 |
+
})
|
| 874 |
+
)}
|
| 875 |
+
</div>
|
| 876 |
+
</section>
|
| 877 |
+
</div>
|
| 878 |
+
|
| 879 |
+
{/* Chat panel */}
|
| 880 |
+
<div style={{flex:1,minHeight:0,overflow:'hidden',display: rightPanelMode === 'chat' ? 'flex' : 'none',flexDirection:'column'}}>
|
| 881 |
+
<ChatAssistant
|
| 882 |
+
compact={true}
|
| 883 |
+
allStepResultsProp={stepResults}
|
| 884 |
+
lastStepResultProp={
|
| 885 |
+
Object.keys(stepResults).length > 0
|
| 886 |
+
? stepResults[Math.max(...Object.keys(stepResults).map(Number))]
|
| 887 |
+
: null
|
| 888 |
+
}
|
| 889 |
+
executeStepFromChat={async (stepDef, changes) => {
|
| 890 |
+
const modifiedStep = changes && Object.keys(changes).length > 0
|
| 891 |
+
? {
|
| 892 |
+
...stepDef,
|
| 893 |
+
body: changes.body !== undefined ? { ...(stepDef.body || {}), ...changes.body } : stepDef.body,
|
| 894 |
+
query_params: changes.query_params !== undefined ? { ...(stepDef.query_params || {}), ...changes.query_params } : stepDef.query_params,
|
| 895 |
+
headers: changes.headers !== undefined ? { ...(stepDef.headers || {}), ...changes.headers } : stepDef.headers,
|
| 896 |
+
path_params: changes.path_params !== undefined ? { ...(stepDef.path_params || {}), ...changes.path_params } : stepDef.path_params,
|
| 897 |
+
...Object.fromEntries(Object.entries(changes).filter(([k]) => !['body','query_params','headers','path_params'].includes(k)))
|
| 898 |
+
}
|
| 899 |
+
: stepDef;
|
| 900 |
+
await executeStep(modifiedStep);
|
| 901 |
+
return {
|
| 902 |
+
step_definition: modifiedStep,
|
| 903 |
+
response: stepResults[modifiedStep.step]?.response,
|
| 904 |
+
analysis: stepResults[modifiedStep.step]?.analysis,
|
| 905 |
+
};
|
| 906 |
+
}}
|
| 907 |
+
/>
|
| 908 |
+
</div>
|
| 909 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 910 |
</div>
|
| 911 |
+
</aside>
|
| 912 |
+
)}
|
| 913 |
|
| 914 |
+
{/* Expand button when panel is collapsed */}
|
| 915 |
+
{!rightPanelOpen && activePage === 'workflow' && (
|
| 916 |
<button
|
| 917 |
onClick={() => setRightPanelOpen(true)}
|
| 918 |
+
style={{
|
| 919 |
+
position:'absolute',right:0,top:'50%',transform:'translateY(-50%)',
|
| 920 |
+
zIndex:20,padding:'6px 4px',
|
| 921 |
+
background:'var(--bg-1)',color:'var(--fg-2)',
|
| 922 |
+
border:'1px solid var(--line-2)',borderRight:0,
|
| 923 |
+
borderRadius:'4px 0 0 4px',
|
| 924 |
+
transition:'color 120ms',cursor:'pointer',
|
| 925 |
+
}}
|
| 926 |
title="Open context panel"
|
| 927 |
>
|
| 928 |
+
<ChevronLeft size={14}/>
|
| 929 |
</button>
|
| 930 |
)}
|
| 931 |
|
| 932 |
</div>
|
| 933 |
|
| 934 |
+
<ToastContainer toasts={toasts} removeToast={removeToast}/>
|
| 935 |
</>
|
| 936 |
);
|
| 937 |
}
|
| 938 |
|
| 939 |
export default function App() {
|
| 940 |
+
const [isAuthenticated, setIsAuthenticated] = useState(AuthService.isAuthenticated());
|
| 941 |
+
|
| 942 |
+
useEffect(() => {
|
| 943 |
+
const handle = () => setIsAuthenticated(false);
|
| 944 |
+
window.addEventListener('auth:logout', handle);
|
| 945 |
+
return () => window.removeEventListener('auth:logout', handle);
|
| 946 |
+
}, []);
|
| 947 |
+
|
| 948 |
+
if (!isAuthenticated) {
|
| 949 |
+
return <LoginPage onLogin={() => setIsAuthenticated(true)} />;
|
| 950 |
+
}
|
| 951 |
+
|
| 952 |
return (
|
| 953 |
<AppProvider>
|
| 954 |
<ErrorBoundary>
|
| 955 |
+
<MainApp/>
|
| 956 |
</ErrorBoundary>
|
| 957 |
</AppProvider>
|
| 958 |
);
|
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState } from 'react';
|
| 2 |
+
import { AuthService } from '../services/api';
|
| 3 |
+
|
| 4 |
+
export default function LoginPage({ onLogin }) {
|
| 5 |
+
const [username, setUsername] = useState('');
|
| 6 |
+
const [password, setPassword] = useState('');
|
| 7 |
+
const [error, setError] = useState('');
|
| 8 |
+
const [loading, setLoading] = useState(false);
|
| 9 |
+
|
| 10 |
+
const handleSubmit = async (e) => {
|
| 11 |
+
e.preventDefault();
|
| 12 |
+
setError('');
|
| 13 |
+
setLoading(true);
|
| 14 |
+
try {
|
| 15 |
+
await AuthService.login(username, password);
|
| 16 |
+
onLogin();
|
| 17 |
+
} catch {
|
| 18 |
+
setError('Invalid username or password.');
|
| 19 |
+
} finally {
|
| 20 |
+
setLoading(false);
|
| 21 |
+
}
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
return (
|
| 25 |
+
<div style={{
|
| 26 |
+
minHeight: '100vh',
|
| 27 |
+
display: 'flex',
|
| 28 |
+
alignItems: 'center',
|
| 29 |
+
justifyContent: 'center',
|
| 30 |
+
background: 'var(--bg-0)',
|
| 31 |
+
}}>
|
| 32 |
+
<div style={{
|
| 33 |
+
width: 360,
|
| 34 |
+
background: 'var(--bg-2)',
|
| 35 |
+
border: '1px solid var(--line-2)',
|
| 36 |
+
borderRadius: 12,
|
| 37 |
+
padding: '36px 32px',
|
| 38 |
+
boxShadow: 'var(--shadow-md)',
|
| 39 |
+
}}>
|
| 40 |
+
<div style={{ marginBottom: 28, textAlign: 'center' }}>
|
| 41 |
+
<div style={{
|
| 42 |
+
fontSize: 22,
|
| 43 |
+
fontWeight: 700,
|
| 44 |
+
color: 'var(--fg-0)',
|
| 45 |
+
fontFamily: 'var(--font-mono)',
|
| 46 |
+
letterSpacing: '-0.5px',
|
| 47 |
+
}}>
|
| 48 |
+
API Testing Assistant
|
| 49 |
+
</div>
|
| 50 |
+
<div style={{ marginTop: 6, fontSize: 13, color: 'var(--fg-2)' }}>
|
| 51 |
+
Sign in to continue
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
<form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
|
| 56 |
+
<div>
|
| 57 |
+
<label style={{ display: 'block', fontSize: 12, color: 'var(--fg-2)', marginBottom: 6 }}>
|
| 58 |
+
Username
|
| 59 |
+
</label>
|
| 60 |
+
<input
|
| 61 |
+
type="text"
|
| 62 |
+
value={username}
|
| 63 |
+
onChange={(e) => setUsername(e.target.value)}
|
| 64 |
+
autoFocus
|
| 65 |
+
required
|
| 66 |
+
style={{
|
| 67 |
+
width: '100%',
|
| 68 |
+
boxSizing: 'border-box',
|
| 69 |
+
padding: '9px 12px',
|
| 70 |
+
background: 'var(--bg-3)',
|
| 71 |
+
border: '1px solid var(--line-2)',
|
| 72 |
+
borderRadius: 7,
|
| 73 |
+
color: 'var(--fg-0)',
|
| 74 |
+
fontSize: 14,
|
| 75 |
+
fontFamily: 'var(--font-mono)',
|
| 76 |
+
outline: 'none',
|
| 77 |
+
}}
|
| 78 |
+
/>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<div>
|
| 82 |
+
<label style={{ display: 'block', fontSize: 12, color: 'var(--fg-2)', marginBottom: 6 }}>
|
| 83 |
+
Password
|
| 84 |
+
</label>
|
| 85 |
+
<input
|
| 86 |
+
type="password"
|
| 87 |
+
value={password}
|
| 88 |
+
onChange={(e) => setPassword(e.target.value)}
|
| 89 |
+
required
|
| 90 |
+
style={{
|
| 91 |
+
width: '100%',
|
| 92 |
+
boxSizing: 'border-box',
|
| 93 |
+
padding: '9px 12px',
|
| 94 |
+
background: 'var(--bg-3)',
|
| 95 |
+
border: '1px solid var(--line-2)',
|
| 96 |
+
borderRadius: 7,
|
| 97 |
+
color: 'var(--fg-0)',
|
| 98 |
+
fontSize: 14,
|
| 99 |
+
fontFamily: 'var(--font-mono)',
|
| 100 |
+
outline: 'none',
|
| 101 |
+
}}
|
| 102 |
+
/>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
{error && (
|
| 106 |
+
<div style={{
|
| 107 |
+
padding: '8px 12px',
|
| 108 |
+
background: 'var(--err-soft)',
|
| 109 |
+
border: '1px solid var(--err)',
|
| 110 |
+
borderRadius: 7,
|
| 111 |
+
color: 'var(--err)',
|
| 112 |
+
fontSize: 13,
|
| 113 |
+
}}>
|
| 114 |
+
{error}
|
| 115 |
+
</div>
|
| 116 |
+
)}
|
| 117 |
+
|
| 118 |
+
<button
|
| 119 |
+
type="submit"
|
| 120 |
+
disabled={loading}
|
| 121 |
+
style={{
|
| 122 |
+
marginTop: 6,
|
| 123 |
+
padding: '10px',
|
| 124 |
+
background: 'var(--accent)',
|
| 125 |
+
color: 'var(--accent-fg)',
|
| 126 |
+
border: 'none',
|
| 127 |
+
borderRadius: 7,
|
| 128 |
+
fontSize: 14,
|
| 129 |
+
fontWeight: 600,
|
| 130 |
+
cursor: loading ? 'not-allowed' : 'pointer',
|
| 131 |
+
opacity: loading ? 0.7 : 1,
|
| 132 |
+
fontFamily: 'var(--font-mono)',
|
| 133 |
+
transition: 'opacity 0.15s',
|
| 134 |
+
}}
|
| 135 |
+
>
|
| 136 |
+
{loading ? 'Signing in…' : 'Sign in'}
|
| 137 |
+
</button>
|
| 138 |
+
</form>
|
| 139 |
+
</div>
|
| 140 |
+
</div>
|
| 141 |
+
);
|
| 142 |
+
}
|
|
@@ -2,15 +2,30 @@ import axios from 'axios';
|
|
| 2 |
|
| 3 |
const BACKEND_URL = import.meta.env.VITE_BACKEND_URL || 'http://localhost:8001';
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
export const api = axios.create({
|
| 6 |
baseURL: BACKEND_URL,
|
| 7 |
timeout: 60000,
|
| 8 |
});
|
| 9 |
|
| 10 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
api.interceptors.response.use(
|
| 12 |
(response) => response,
|
| 13 |
(error) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
const msg =
|
| 15 |
error.response?.data?.error ||
|
| 16 |
error.response?.data?.detail ||
|
|
@@ -20,6 +35,19 @@ api.interceptors.response.use(
|
|
| 20 |
}
|
| 21 |
);
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
export const SpecService = {
|
| 24 |
getAllSpecs: async () => {
|
| 25 |
const response = await api.get('/specs');
|
|
@@ -193,4 +221,3 @@ export const ChatService = {
|
|
| 193 |
return response.data;
|
| 194 |
},
|
| 195 |
};
|
| 196 |
-
|
|
|
|
| 2 |
|
| 3 |
const BACKEND_URL = import.meta.env.VITE_BACKEND_URL || 'http://localhost:8001';
|
| 4 |
|
| 5 |
+
// Token stored in module memory — never written to localStorage or sessionStorage
|
| 6 |
+
let _token = null;
|
| 7 |
+
|
| 8 |
export const api = axios.create({
|
| 9 |
baseURL: BACKEND_URL,
|
| 10 |
timeout: 60000,
|
| 11 |
});
|
| 12 |
|
| 13 |
+
// Attach Bearer token to every request
|
| 14 |
+
api.interceptors.request.use((config) => {
|
| 15 |
+
if (_token) {
|
| 16 |
+
config.headers.Authorization = `Bearer ${_token}`;
|
| 17 |
+
}
|
| 18 |
+
return config;
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
// Normalize error shape; broadcast logout on 401
|
| 22 |
api.interceptors.response.use(
|
| 23 |
(response) => response,
|
| 24 |
(error) => {
|
| 25 |
+
if (error.response?.status === 401) {
|
| 26 |
+
_token = null;
|
| 27 |
+
window.dispatchEvent(new Event('auth:logout'));
|
| 28 |
+
}
|
| 29 |
const msg =
|
| 30 |
error.response?.data?.error ||
|
| 31 |
error.response?.data?.detail ||
|
|
|
|
| 35 |
}
|
| 36 |
);
|
| 37 |
|
| 38 |
+
export const AuthService = {
|
| 39 |
+
login: async (username, password) => {
|
| 40 |
+
// Uses plain axios (no token needed, no 401 redirect loop)
|
| 41 |
+
const response = await axios.post(`${BACKEND_URL}/auth/login`, { username, password });
|
| 42 |
+
_token = response.data.access_token;
|
| 43 |
+
return response.data;
|
| 44 |
+
},
|
| 45 |
+
logout: () => {
|
| 46 |
+
_token = null;
|
| 47 |
+
},
|
| 48 |
+
isAuthenticated: () => !!_token,
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
export const SpecService = {
|
| 52 |
getAllSpecs: async () => {
|
| 53 |
const response = await api.get('/specs');
|
|
|
|
| 221 |
return response.data;
|
| 222 |
},
|
| 223 |
};
|
|
|