Spaces:
Runtime error
Runtime error
Commit ·
3c8d218
0
Parent(s):
Clean and flattened project initialization
Browse files- .env.example +21 -0
- .gitattributes +4 -0
- .gitignore +36 -0
- Procfile +1 -0
- README.md +67 -0
- backend/__init__.py +0 -0
- backend/database.py +171 -0
- backend/main.py +693 -0
- backend/schemas.py +64 -0
- backend/services/__init__.py +0 -0
- backend/services/api_executor.py +125 -0
- backend/services/asset_service.py +135 -0
- backend/services/context_manager.py +29 -0
- backend/services/llm_planner.py +104 -0
- backend/services/postman_parser.py +129 -0
- backend/services/response_analyzer.py +68 -0
- backend/services/storage.py +37 -0
- backend/services/swagger_parser.py +47 -0
- backend/uploads/documents/a1f57578-141b-4520-963b-c1023c93bfa6.png +3 -0
- backend/uploads/documents/be351df0-6bd3-46dc-b154-805f9ec8d127.jpg +3 -0
- backend/uploads/documents/dd08cd23-5485-4ab7-8c05-8ee9d9e345da.jpg +3 -0
- frontend-react/.env.production +1 -0
- frontend-react/.gitignore +24 -0
- frontend-react/README.md +16 -0
- frontend-react/eslint.config.js +29 -0
- frontend-react/index.html +13 -0
- frontend-react/package-lock.json +0 -0
- frontend-react/package.json +32 -0
- frontend-react/public/favicon.svg +1 -0
- frontend-react/public/icons.svg +24 -0
- frontend-react/src/App.css +184 -0
- frontend-react/src/App.jsx +575 -0
- frontend-react/src/assets/hero.png +3 -0
- frontend-react/src/assets/react.svg +1 -0
- frontend-react/src/assets/vite.svg +1 -0
- frontend-react/src/components/AppContext.jsx +167 -0
- frontend-react/src/components/CollectionsPage.jsx +129 -0
- frontend-react/src/components/HistoryPage.jsx +407 -0
- frontend-react/src/components/MediaHubPage.jsx +353 -0
- frontend-react/src/components/ProfilePage.jsx +228 -0
- frontend-react/src/index.css +22 -0
- frontend-react/src/main.jsx +10 -0
- frontend-react/src/services/api.js +132 -0
- frontend-react/vite.config.js +8 -0
- openapi.yaml +1078 -0
- package-lock.json +372 -0
- package.json +18 -0
- requirements.txt +13 -0
- runtime.txt +1 -0
- start.ps1 +48 -0
.env.example
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI API Testing Tool - Environment Variables
|
| 2 |
+
|
| 3 |
+
# Mistral AI configuration
|
| 4 |
+
MISTRAL_API_KEY=your_mistral_api_key_here
|
| 5 |
+
MISTRAL_MODEL=mistral-large-latest
|
| 6 |
+
|
| 7 |
+
# Backend configuration (Local default: 8001)
|
| 8 |
+
# On Render, the PORT will be assigned automatically.
|
| 9 |
+
PORT=8001
|
| 10 |
+
|
| 11 |
+
# Database Configuration
|
| 12 |
+
# Local default: sqlite:///./backend/apitest.db
|
| 13 |
+
# Render: Paste your External Database URL here
|
| 14 |
+
# DATABASE_URL=postgresql://user:password@hostname:5432/dbname
|
| 15 |
+
|
| 16 |
+
# Frontend Configuration (Vite)
|
| 17 |
+
# Points to the Backend URL.
|
| 18 |
+
# Local: http://localhost:8001
|
| 19 |
+
# Render: https://your-backend.onrender.com
|
| 20 |
+
VITE_BACKEND_URL=http://localhost:8001
|
| 21 |
+
VITE_API_URL=http://localhost:8001
|
.gitattributes
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto detect text files and perform LF normalization
|
| 2 |
+
* text=auto
|
| 3 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dependencies
|
| 2 |
+
node_modules/
|
| 3 |
+
dist/
|
| 4 |
+
build/
|
| 5 |
+
|
| 6 |
+
# Python
|
| 7 |
+
__pycache__/
|
| 8 |
+
*.pyc
|
| 9 |
+
*.pyo
|
| 10 |
+
*.pyd
|
| 11 |
+
.Python
|
| 12 |
+
env/
|
| 13 |
+
venv/
|
| 14 |
+
pip-log.txt
|
| 15 |
+
pip-delete-this-directory.txt
|
| 16 |
+
|
| 17 |
+
# Databases
|
| 18 |
+
*.db
|
| 19 |
+
*.sqlite3
|
| 20 |
+
|
| 21 |
+
# Environment variables
|
| 22 |
+
.env
|
| 23 |
+
|
| 24 |
+
# Logs
|
| 25 |
+
*.log
|
| 26 |
+
|
| 27 |
+
# OS files
|
| 28 |
+
.DS_Store
|
| 29 |
+
Thumbs.db
|
| 30 |
+
desktop.ini
|
| 31 |
+
|
| 32 |
+
# IDEs
|
| 33 |
+
.vscode/
|
| 34 |
+
.idea/
|
| 35 |
+
*.swp
|
| 36 |
+
*.swo
|
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: gunicorn backend.main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT
|
README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI API Testing Assistant
|
| 2 |
+
|
| 3 |
+
An automated API testing system powered by Mistral AI, FastAPI, and React. This tool parses an OpenAPI (Swagger) specification, takes a natural-language test scenario from the user, and dynamically generates and executes an API execution plan.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
- **OpenAPI Parsing**: Upload your API spec (JSON or YAML) — extracts all endpoints, schemas, methods, and auth details.
|
| 8 |
+
- **LLM-Powered Execution Plan**: Mistral AI analyzes your natural-language intent and builds a step-by-step execution plan.
|
| 9 |
+
- **Dynamic API Execution**: Executes HTTP requests based on the plan, chaining responses automatically.
|
| 10 |
+
- **Context Management**: Extracts tokens/IDs from responses and passes them to subsequent steps.
|
| 11 |
+
- **React Frontend**: Modern UI built with React + Vite + Tailwind CSS.
|
| 12 |
+
|
| 13 |
+
## Requirements
|
| 14 |
+
|
| 15 |
+
- **Python** 3.9+
|
| 16 |
+
- **Node.js** 18+
|
| 17 |
+
- A valid **Mistral AI API Key**
|
| 18 |
+
|
| 19 |
+
## Setup (First Time)
|
| 20 |
+
|
| 21 |
+
1. Clone the repo and install all dependencies:
|
| 22 |
+
```bash
|
| 23 |
+
npm run setup
|
| 24 |
+
```
|
| 25 |
+
2. Open `.env` and add your Mistral API key:
|
| 26 |
+
```ini
|
| 27 |
+
MISTRAL_API_KEY=your_actual_api_key_here
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
## Starting the App
|
| 31 |
+
|
| 32 |
+
### Option 1 — Recommended (single command, colour-coded output)
|
| 33 |
+
```bash
|
| 34 |
+
npm run dev
|
| 35 |
+
```
|
| 36 |
+
Starts both the FastAPI backend and the React frontend concurrently in one terminal.
|
| 37 |
+
|
| 38 |
+
### Option 2 — PowerShell script (opens separate windows per service)
|
| 39 |
+
```powershell
|
| 40 |
+
.\start.ps1
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
### Option 3 — Manual (two terminals)
|
| 44 |
+
```bash
|
| 45 |
+
# Terminal 1 — Backend
|
| 46 |
+
python -m uvicorn backend.main:app --reload --port 8001
|
| 47 |
+
|
| 48 |
+
# Terminal 2 — Frontend
|
| 49 |
+
cd frontend-react && npm run dev
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## URLs
|
| 53 |
+
|
| 54 |
+
| Service | URL |
|
| 55 |
+
|----------|------------------------------|
|
| 56 |
+
| Frontend | http://localhost:5173 |
|
| 57 |
+
| Backend | http://localhost:8001 |
|
| 58 |
+
| API Docs | http://localhost:8001/docs |
|
| 59 |
+
|
| 60 |
+
## Usage
|
| 61 |
+
|
| 62 |
+
1. Open the frontend at `http://localhost:5173`.
|
| 63 |
+
2. Upload a valid `swagger.json` or `openapi.yaml`.
|
| 64 |
+
3. Provide the base URL of the server to test.
|
| 65 |
+
4. Describe your test scenario in natural language.
|
| 66 |
+
5. Generate an execution plan and run your steps!
|
| 67 |
+
|
backend/__init__.py
ADDED
|
File without changes
|
backend/database.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime, JSON, text, ForeignKey, Table
|
| 2 |
+
import uuid
|
| 3 |
+
from sqlalchemy.orm import declarative_base, sessionmaker, relationship
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./backend/apitest.db")
|
| 8 |
+
# Fix for Render/Postgres who uses 'postgres://' instead of 'postgresql://'
|
| 9 |
+
if DATABASE_URL.startswith("postgres://"):
|
| 10 |
+
DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://", 1)
|
| 11 |
+
|
| 12 |
+
connect_args = {}
|
| 13 |
+
if DATABASE_URL.startswith("sqlite"):
|
| 14 |
+
connect_args["check_same_thread"] = False
|
| 15 |
+
|
| 16 |
+
engine = create_engine(DATABASE_URL, connect_args=connect_args)
|
| 17 |
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
| 18 |
+
|
| 19 |
+
Base = declarative_base()
|
| 20 |
+
|
| 21 |
+
# Many-to-Many junction table for assets and collections
|
| 22 |
+
asset_collections = Table(
|
| 23 |
+
"asset_collections",
|
| 24 |
+
Base.metadata,
|
| 25 |
+
Column("asset_id", String, ForeignKey("assets.id"), primary_key=True),
|
| 26 |
+
Column("collection_id", String, ForeignKey("collections.id"), primary_key=True)
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
class SpecDocument(Base):
|
| 30 |
+
__tablename__ = "spec_documents"
|
| 31 |
+
|
| 32 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 33 |
+
name = Column(String, nullable=False)
|
| 34 |
+
raw_content = Column(Text, nullable=False)
|
| 35 |
+
parsed_json = Column(JSON, nullable=False)
|
| 36 |
+
base_url = Column(String, nullable=True)
|
| 37 |
+
login_credentials = Column(JSON, nullable=True) # Per-spec stored credentials
|
| 38 |
+
execution_plan = Column(JSON, nullable=True) # Persisted LLM execution plan
|
| 39 |
+
scenario = Column(Text, nullable=True) # Saved test scenario text
|
| 40 |
+
uploaded_at = Column(DateTime, default=datetime.utcnow)
|
| 41 |
+
|
| 42 |
+
# Relationships
|
| 43 |
+
assets = relationship("Asset", back_populates="spec")
|
| 44 |
+
|
| 45 |
+
class SessionModel(Base):
|
| 46 |
+
__tablename__ = "sessions"
|
| 47 |
+
|
| 48 |
+
id = Column(String, primary_key=True, index=True)
|
| 49 |
+
spec_id = Column(String, ForeignKey("spec_documents.id"), nullable=True)
|
| 50 |
+
spec_name = Column(String, nullable=True)
|
| 51 |
+
base_url = Column(String)
|
| 52 |
+
scenario = Column(Text)
|
| 53 |
+
context_variables = Column(JSON, default={})
|
| 54 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 55 |
+
|
| 56 |
+
class ExecutionHistory(Base):
|
| 57 |
+
__tablename__ = "execution_history"
|
| 58 |
+
|
| 59 |
+
id = Column(Integer, primary_key=True, index=True)
|
| 60 |
+
session_id = Column(String, index=True)
|
| 61 |
+
step = Column(Integer)
|
| 62 |
+
request_json = Column(JSON)
|
| 63 |
+
response_json = Column(JSON)
|
| 64 |
+
analysis_json = Column(JSON, nullable=True)
|
| 65 |
+
step_definition_json = Column(JSON, nullable=True) # Historical step metadata
|
| 66 |
+
timestamp = Column(DateTime, default=datetime.utcnow)
|
| 67 |
+
|
| 68 |
+
class Collection(Base):
|
| 69 |
+
__tablename__ = "collections"
|
| 70 |
+
|
| 71 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 72 |
+
name = Column(String, nullable=False)
|
| 73 |
+
description = Column(Text, nullable=True)
|
| 74 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
| 75 |
+
|
| 76 |
+
# Relationships
|
| 77 |
+
assets = relationship("Asset", secondary=asset_collections, back_populates="collections")
|
| 78 |
+
|
| 79 |
+
class Asset(Base):
|
| 80 |
+
__tablename__ = "assets"
|
| 81 |
+
|
| 82 |
+
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 83 |
+
name = Column(String, nullable=False)
|
| 84 |
+
file_type = Column(String, nullable=False)
|
| 85 |
+
file_path = Column(String, nullable=False)
|
| 86 |
+
file_size = Column(Integer)
|
| 87 |
+
category = Column(String, default="documents") # audio, video, documents, images
|
| 88 |
+
description = Column(Text, nullable=True)
|
| 89 |
+
tags = Column(JSON, default=[]) # e.g. ["aadhar", "identity"]
|
| 90 |
+
metadata_json = Column(JSON, default={}) # thumbnails, dimensions, etc.
|
| 91 |
+
spec_id = Column(String, ForeignKey("spec_documents.id"), nullable=True)
|
| 92 |
+
uploaded_at = Column(DateTime, default=datetime.utcnow)
|
| 93 |
+
|
| 94 |
+
# Relationships
|
| 95 |
+
spec = relationship("SpecDocument", back_populates="assets")
|
| 96 |
+
collections = relationship("Collection", secondary=asset_collections, back_populates="assets")
|
| 97 |
+
|
| 98 |
+
# Create tables
|
| 99 |
+
Base.metadata.create_all(bind=engine)
|
| 100 |
+
|
| 101 |
+
def run_migrations():
|
| 102 |
+
"""Apply any pending schema migrations safely."""
|
| 103 |
+
with engine.connect() as conn:
|
| 104 |
+
# Columns to add to spec_documents
|
| 105 |
+
spec_cols = [
|
| 106 |
+
("execution_plan", "TEXT"),
|
| 107 |
+
("scenario", "TEXT")
|
| 108 |
+
]
|
| 109 |
+
for col_name, col_type in spec_cols:
|
| 110 |
+
try:
|
| 111 |
+
conn.execute(text(f"ALTER TABLE spec_documents ADD COLUMN {col_name} {col_type}"))
|
| 112 |
+
conn.commit()
|
| 113 |
+
except Exception:
|
| 114 |
+
pass
|
| 115 |
+
|
| 116 |
+
# Columns to add to execution_history
|
| 117 |
+
hist_cols = [
|
| 118 |
+
("analysis_json", "TEXT"),
|
| 119 |
+
("step_definition_json", "TEXT")
|
| 120 |
+
]
|
| 121 |
+
for col_name, col_type in hist_cols:
|
| 122 |
+
try:
|
| 123 |
+
conn.execute(text(f"ALTER TABLE execution_history ADD COLUMN {col_name} {col_type}"))
|
| 124 |
+
conn.commit()
|
| 125 |
+
except Exception:
|
| 126 |
+
pass
|
| 127 |
+
|
| 128 |
+
# Columns to add to assets
|
| 129 |
+
asset_cols = [
|
| 130 |
+
("description", "TEXT"),
|
| 131 |
+
("tags", "TEXT"), # JSON handled as TEXT in sqlite
|
| 132 |
+
("metadata_json", "TEXT")
|
| 133 |
+
]
|
| 134 |
+
for col_name, col_type in asset_cols:
|
| 135 |
+
try:
|
| 136 |
+
conn.execute(text(f"ALTER TABLE assets ADD COLUMN {col_name} {col_type}"))
|
| 137 |
+
conn.commit()
|
| 138 |
+
except Exception:
|
| 139 |
+
pass
|
| 140 |
+
|
| 141 |
+
# Columns to add to sessions
|
| 142 |
+
session_cols = [
|
| 143 |
+
("spec_id", "VARCHAR"),
|
| 144 |
+
("spec_name", "VARCHAR"),
|
| 145 |
+
("base_url", "VARCHAR"),
|
| 146 |
+
("scenario", "TEXT")
|
| 147 |
+
]
|
| 148 |
+
for col_name, col_type in session_cols:
|
| 149 |
+
try:
|
| 150 |
+
conn.execute(text(f"ALTER TABLE sessions ADD COLUMN {col_name} {col_type}"))
|
| 151 |
+
conn.commit()
|
| 152 |
+
except Exception:
|
| 153 |
+
pass
|
| 154 |
+
|
| 155 |
+
# Ensure collection table exists
|
| 156 |
+
try:
|
| 157 |
+
conn.execute(text("CREATE TABLE IF NOT EXISTS collections (id VARCHAR PRIMARY KEY, name VARCHAR, description TEXT, created_at TIMESTAMP)"))
|
| 158 |
+
conn.execute(text("CREATE TABLE IF NOT EXISTS asset_collections (asset_id VARCHAR, collection_id VARCHAR, PRIMARY KEY (asset_id, collection_id))"))
|
| 159 |
+
conn.commit()
|
| 160 |
+
except Exception:
|
| 161 |
+
pass
|
| 162 |
+
|
| 163 |
+
run_migrations()
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def get_db():
|
| 167 |
+
db = SessionLocal()
|
| 168 |
+
try:
|
| 169 |
+
yield db
|
| 170 |
+
finally:
|
| 171 |
+
db.close()
|
backend/main.py
ADDED
|
@@ -0,0 +1,693 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Depends, HTTPException, File, UploadFile, Form
|
| 2 |
+
from fastapi.staticfiles import StaticFiles
|
| 3 |
+
from sqlalchemy.orm import Session
|
| 4 |
+
from sqlalchemy.orm.attributes import flag_modified
|
| 5 |
+
from . import database, schemas
|
| 6 |
+
from typing import Dict, Any, Optional
|
| 7 |
+
import httpx
|
| 8 |
+
import json
|
| 9 |
+
import uuid
|
| 10 |
+
import os
|
| 11 |
+
import shutil
|
| 12 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 13 |
+
from fastapi.exceptions import RequestValidationError
|
| 14 |
+
from fastapi.responses import JSONResponse
|
| 15 |
+
|
| 16 |
+
from backend.services.swagger_parser import parse_spec
|
| 17 |
+
from backend.services.postman_parser import parse_postman_collection as parse_postman
|
| 18 |
+
from backend.services.llm_planner import generate_execution_plan
|
| 19 |
+
from backend.services.api_executor import prepare_step_request
|
| 20 |
+
from backend.services.response_analyzer import analyze_api_response
|
| 21 |
+
from backend.services.context_manager import get_context, set_context_variables
|
| 22 |
+
from backend.services.asset_service import AssetService
|
| 23 |
+
|
| 24 |
+
# Ensure uploads subdirectories exist
|
| 25 |
+
UPLOAD_DIR = "backend/uploads"
|
| 26 |
+
CATEGORIES = ["audio", "video", "documents", "images"]
|
| 27 |
+
for cat in CATEGORIES:
|
| 28 |
+
os.makedirs(os.path.join(UPLOAD_DIR, cat), exist_ok=True)
|
| 29 |
+
|
| 30 |
+
app = FastAPI(title="AI API Testing Assistant")
|
| 31 |
+
|
| 32 |
+
# Mount static files for uploads
|
| 33 |
+
app.mount("/uploads", StaticFiles(directory=UPLOAD_DIR), name="uploads")
|
| 34 |
+
|
| 35 |
+
@app.exception_handler(RequestValidationError)
|
| 36 |
+
async def validation_exception_handler(request, exc):
|
| 37 |
+
print(f"VALIDATION ERROR: {exc.errors()}")
|
| 38 |
+
print(f"BODY: {await request.body()}")
|
| 39 |
+
return JSONResponse(
|
| 40 |
+
status_code=422,
|
| 41 |
+
content={"detail": exc.errors(), "body": str(await request.body())},
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Configure CORS
|
| 45 |
+
app.add_middleware(
|
| 46 |
+
CORSMiddleware,
|
| 47 |
+
allow_origins=["*"], # Allow all origins for production ease
|
| 48 |
+
allow_credentials=True,
|
| 49 |
+
allow_methods=["*"],
|
| 50 |
+
allow_headers=["*"],
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
@app.get("/")
|
| 54 |
+
def read_root():
|
| 55 |
+
return {"status": "ok", "message": "AI API Testing Tool Backend running."}
|
| 56 |
+
|
| 57 |
+
@app.post("/session")
|
| 58 |
+
def create_session(db: Session = Depends(database.get_db)):
|
| 59 |
+
session_id = str(uuid.uuid4())
|
| 60 |
+
new_session = database.SessionModel(id=session_id)
|
| 61 |
+
db.add(new_session)
|
| 62 |
+
db.commit()
|
| 63 |
+
return {"session_id": session_id}
|
| 64 |
+
|
| 65 |
+
@app.post("/upload-spec")
|
| 66 |
+
async def upload_spec(file: UploadFile = File(...), db: Session = Depends(database.get_db)):
|
| 67 |
+
content = await file.read()
|
| 68 |
+
try:
|
| 69 |
+
decoded_content = content.decode("utf-8", errors="replace")
|
| 70 |
+
|
| 71 |
+
# Detect if it's a Postman collection
|
| 72 |
+
is_postman = False
|
| 73 |
+
try:
|
| 74 |
+
temp_json = json.loads(decoded_content)
|
| 75 |
+
if isinstance(temp_json, dict):
|
| 76 |
+
# Primary check: schema URL
|
| 77 |
+
info = temp_json.get("info", {})
|
| 78 |
+
if isinstance(info, dict) and "postman.com/json/collection" in info.get("schema", ""):
|
| 79 |
+
is_postman = True
|
| 80 |
+
# Secondary check: unique structure (info + item)
|
| 81 |
+
elif "info" in temp_json and "item" in temp_json:
|
| 82 |
+
# Swagger/OpenAPI usually has 'openapi' or 'swagger' key at top level
|
| 83 |
+
if "openapi" not in temp_json and "swagger" not in temp_json:
|
| 84 |
+
is_postman = True
|
| 85 |
+
except:
|
| 86 |
+
pass
|
| 87 |
+
|
| 88 |
+
if is_postman:
|
| 89 |
+
parsed_spec = parse_postman(decoded_content)
|
| 90 |
+
else:
|
| 91 |
+
parsed_spec = parse_spec(decoded_content)
|
| 92 |
+
|
| 93 |
+
safe_spec = json.loads(json.dumps(parsed_spec, ensure_ascii=True))
|
| 94 |
+
|
| 95 |
+
# Persist the spec to the database
|
| 96 |
+
spec_id = str(uuid.uuid4())
|
| 97 |
+
spec_doc = database.SpecDocument(
|
| 98 |
+
id=spec_id,
|
| 99 |
+
name=file.filename,
|
| 100 |
+
raw_content=decoded_content,
|
| 101 |
+
parsed_json=safe_spec
|
| 102 |
+
)
|
| 103 |
+
db.add(spec_doc)
|
| 104 |
+
db.commit()
|
| 105 |
+
|
| 106 |
+
# Prepare return object including the ID for the frontend
|
| 107 |
+
safe_spec["id"] = spec_id
|
| 108 |
+
|
| 109 |
+
return {"status": "success", "spec_id": spec_id, "parsed_spec": safe_spec}
|
| 110 |
+
except Exception as e:
|
| 111 |
+
raise HTTPException(status_code=400, detail=f"Failed to parse spec: {str(e)}")
|
| 112 |
+
|
| 113 |
+
@app.get("/specs")
|
| 114 |
+
def list_specs(db: Session = Depends(database.get_db)):
|
| 115 |
+
specs = db.query(database.SpecDocument).order_by(database.SpecDocument.uploaded_at.desc()).all()
|
| 116 |
+
return [
|
| 117 |
+
{"id": s.id, "name": s.name, "base_url": s.base_url or "", "uploaded_at": s.uploaded_at.isoformat()}
|
| 118 |
+
for s in specs
|
| 119 |
+
]
|
| 120 |
+
|
| 121 |
+
@app.get("/specs/{spec_id}")
|
| 122 |
+
def get_spec(spec_id: str, db: Session = Depends(database.get_db)):
|
| 123 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == spec_id).first()
|
| 124 |
+
if not spec:
|
| 125 |
+
raise HTTPException(status_code=404, detail="Spec not found")
|
| 126 |
+
return {
|
| 127 |
+
"id": spec.id,
|
| 128 |
+
"name": spec.name,
|
| 129 |
+
"base_url": spec.base_url or "",
|
| 130 |
+
"login_credentials": spec.login_credentials or {},
|
| 131 |
+
"parsed_spec": spec.parsed_json,
|
| 132 |
+
"execution_plan": spec.execution_plan,
|
| 133 |
+
"scenario": spec.scenario,
|
| 134 |
+
"uploaded_at": spec.uploaded_at.isoformat()
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
@app.patch("/specs/{spec_id}")
|
| 138 |
+
def update_spec(spec_id: str, payload: dict, db: Session = Depends(database.get_db)):
|
| 139 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == spec_id).first()
|
| 140 |
+
if not spec:
|
| 141 |
+
raise HTTPException(status_code=404, detail="Spec not found")
|
| 142 |
+
if "base_url" in payload:
|
| 143 |
+
spec.base_url = payload["base_url"]
|
| 144 |
+
db.commit()
|
| 145 |
+
return {"status": "updated", "id": spec.id, "base_url": spec.base_url}
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def get_category(filename: str, content_type: str) -> str:
|
| 149 |
+
ext = os.path.splitext(filename)[1].lower()
|
| 150 |
+
if ext in ['.mp3', '.wav', '.ogg', '.m4a'] or (content_type and content_type.startswith('audio/')):
|
| 151 |
+
return 'audio'
|
| 152 |
+
if ext in ['.mp4', '.mov', '.avi', '.mkv'] or (content_type and content_type.startswith('video/')):
|
| 153 |
+
return 'video'
|
| 154 |
+
return 'documents'
|
| 155 |
+
|
| 156 |
+
@app.post("/assets")
|
| 157 |
+
async def upload_asset(
|
| 158 |
+
spec_id: str = Form(None),
|
| 159 |
+
description: str = Form(None),
|
| 160 |
+
tags: str = Form("[]"),
|
| 161 |
+
file: UploadFile = File(...),
|
| 162 |
+
db: Session = Depends(database.get_db)
|
| 163 |
+
):
|
| 164 |
+
try:
|
| 165 |
+
import json
|
| 166 |
+
tag_list = json.loads(tags)
|
| 167 |
+
asset = AssetService.upload_asset(db, file, spec_id, description, tag_list)
|
| 168 |
+
return {
|
| 169 |
+
"id": asset.id,
|
| 170 |
+
"name": asset.name,
|
| 171 |
+
"type": asset.file_type,
|
| 172 |
+
"size": asset.file_size,
|
| 173 |
+
"category": asset.category,
|
| 174 |
+
"description": asset.description,
|
| 175 |
+
"tags": asset.tags,
|
| 176 |
+
"spec_id": asset.spec_id,
|
| 177 |
+
"uploaded_at": asset.uploaded_at.isoformat()
|
| 178 |
+
}
|
| 179 |
+
except Exception as e:
|
| 180 |
+
raise HTTPException(status_code=500, detail=f"Upload failed: {str(e)}")
|
| 181 |
+
|
| 182 |
+
@app.get("/assets")
|
| 183 |
+
def list_assets(spec_id: Optional[str] = None, category: Optional[str] = None, db: Session = Depends(database.get_db)):
|
| 184 |
+
assets = AssetService.get_assets(db, spec_id, category)
|
| 185 |
+
return [
|
| 186 |
+
{
|
| 187 |
+
"id": a.id,
|
| 188 |
+
"name": a.name,
|
| 189 |
+
"type": a.file_type,
|
| 190 |
+
"size": a.file_size,
|
| 191 |
+
"category": a.category,
|
| 192 |
+
"description": a.description,
|
| 193 |
+
"tags": a.tags,
|
| 194 |
+
"spec_id": a.spec_id,
|
| 195 |
+
"path": a.file_path,
|
| 196 |
+
"uploaded_at": a.uploaded_at.isoformat()
|
| 197 |
+
}
|
| 198 |
+
for a in assets
|
| 199 |
+
]
|
| 200 |
+
|
| 201 |
+
@app.delete("/assets/{asset_id}")
|
| 202 |
+
def delete_asset(asset_id: str, db: Session = Depends(database.get_db)):
|
| 203 |
+
success = AssetService.delete_asset(db, asset_id)
|
| 204 |
+
if not success:
|
| 205 |
+
raise HTTPException(status_code=404, detail="Asset not found")
|
| 206 |
+
return {"status": "deleted", "id": asset_id}
|
| 207 |
+
|
| 208 |
+
@app.get("/collections")
|
| 209 |
+
def list_collections(db: Session = Depends(database.get_db)):
|
| 210 |
+
cols = db.query(database.Collection).all()
|
| 211 |
+
return [{"id": c.id, "name": c.name, "description": c.description} for c in cols]
|
| 212 |
+
|
| 213 |
+
@app.post("/collections")
|
| 214 |
+
def create_collection(name: str = Form(...), description: str = Form(None), db: Session = Depends(database.get_db)):
|
| 215 |
+
col = AssetService.create_collection(db, name, description)
|
| 216 |
+
return {"id": col.id, "name": col.name}
|
| 217 |
+
|
| 218 |
+
@app.post("/collections/{collection_id}/assets/{asset_id}")
|
| 219 |
+
def add_asset_to_collection(collection_id: str, asset_id: str, db: Session = Depends(database.get_db)):
|
| 220 |
+
success = AssetService.add_to_collection(db, asset_id, collection_id)
|
| 221 |
+
if not success:
|
| 222 |
+
raise HTTPException(status_code=404, detail="Asset or Collection not found")
|
| 223 |
+
return {"status": "success"}
|
| 224 |
+
|
| 225 |
+
@app.delete("/specs/{spec_id}")
|
| 226 |
+
def delete_spec(spec_id: str, db: Session = Depends(database.get_db)):
|
| 227 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == spec_id).first()
|
| 228 |
+
if not spec:
|
| 229 |
+
raise HTTPException(status_code=404, detail="Spec not found")
|
| 230 |
+
|
| 231 |
+
# NEW: Delete all associated assets first (disk + DB)
|
| 232 |
+
assets = db.query(database.Asset).filter(database.Asset.spec_id == spec_id).all()
|
| 233 |
+
for asset in assets:
|
| 234 |
+
if os.path.exists(asset.file_path):
|
| 235 |
+
try:
|
| 236 |
+
os.remove(asset.file_path)
|
| 237 |
+
except Exception as e:
|
| 238 |
+
print(f"[CLEANUP ERROR] Failed to delete file {asset.file_path}: {e}")
|
| 239 |
+
db.delete(asset)
|
| 240 |
+
|
| 241 |
+
db.delete(spec)
|
| 242 |
+
db.commit()
|
| 243 |
+
return {"status": "deleted", "id": spec_id, "assets_removed": len(assets)}
|
| 244 |
+
|
| 245 |
+
@app.post("/plan", response_model=schemas.ExecutionPlan)
|
| 246 |
+
def generate_plan(request: schemas.PlanRequest, db: Session = Depends(database.get_db)):
|
| 247 |
+
try:
|
| 248 |
+
# Expected `request.spec_content` to be the dict from `/upload-spec`
|
| 249 |
+
parsed_spec = json.loads(request.spec_content) if isinstance(request.spec_content, str) else request.spec_content
|
| 250 |
+
|
| 251 |
+
# Override with DB-stored credentials if a spec_id is provided
|
| 252 |
+
credentials = request.user_credentials or {}
|
| 253 |
+
if request.spec_id:
|
| 254 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == request.spec_id).first()
|
| 255 |
+
if spec and spec.login_credentials:
|
| 256 |
+
credentials = spec.login_credentials
|
| 257 |
+
|
| 258 |
+
plan = generate_execution_plan(
|
| 259 |
+
parsed_spec,
|
| 260 |
+
request.base_url,
|
| 261 |
+
request.scenario,
|
| 262 |
+
credentials
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
# PERSIST: Save the generated plan and update session metadata
|
| 266 |
+
if request.spec_id:
|
| 267 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == request.spec_id).first()
|
| 268 |
+
if spec:
|
| 269 |
+
spec.execution_plan = plan.model_dump()["execution_plan"]
|
| 270 |
+
spec.scenario = request.scenario
|
| 271 |
+
flag_modified(spec, "execution_plan")
|
| 272 |
+
flag_modified(spec, "scenario")
|
| 273 |
+
|
| 274 |
+
# Update session metadata if session_id provided
|
| 275 |
+
if request.session_id:
|
| 276 |
+
session = db.query(database.SessionModel).filter(database.SessionModel.id == request.session_id).first()
|
| 277 |
+
if session:
|
| 278 |
+
session.spec_id = spec.id
|
| 279 |
+
session.spec_name = spec.name
|
| 280 |
+
session.scenario = request.scenario
|
| 281 |
+
session.base_url = request.base_url
|
| 282 |
+
|
| 283 |
+
# NEW: Merge AI-generated credentials if present
|
| 284 |
+
if plan.suggested_credentials and isinstance(plan.suggested_credentials, dict):
|
| 285 |
+
current_creds = dict(spec.login_credentials or {})
|
| 286 |
+
# Only merge if there's actually something new to add
|
| 287 |
+
if any(k not in current_creds or current_creds[k] != v for k, v in plan.suggested_credentials.items()):
|
| 288 |
+
current_creds.update(plan.suggested_credentials)
|
| 289 |
+
spec.login_credentials = current_creds
|
| 290 |
+
flag_modified(spec, "login_credentials")
|
| 291 |
+
print(f"[AUTH MERGE] AI suggested credentials for '{spec.name}' merged into DB.")
|
| 292 |
+
|
| 293 |
+
db.commit()
|
| 294 |
+
|
| 295 |
+
return plan
|
| 296 |
+
except Exception as e:
|
| 297 |
+
raise HTTPException(status_code=500, detail=f"Planning failed: {str(e)}")
|
| 298 |
+
|
| 299 |
+
@app.post("/execute-step")
|
| 300 |
+
async def execute_step(request: schemas.ExecuteStepRequest, db: Session = Depends(database.get_db)):
|
| 301 |
+
try:
|
| 302 |
+
# Extract endpoint string (e.g., "GET /buses/{bus_id}" or "/buses/{bus_id}")
|
| 303 |
+
endpoint_str = request.step_definition.get("endpoint", "")
|
| 304 |
+
|
| 305 |
+
def resolve_refs(obj, full_spec, _resolving=None):
|
| 306 |
+
"""Recursively inline all $ref pointers so the LLM gets a flat, self-contained spec."""
|
| 307 |
+
if _resolving is None:
|
| 308 |
+
_resolving = set()
|
| 309 |
+
if isinstance(obj, dict):
|
| 310 |
+
if "$ref" in obj:
|
| 311 |
+
ref = obj["$ref"]
|
| 312 |
+
if ref in _resolving:
|
| 313 |
+
return {"$ref_loop": ref}
|
| 314 |
+
_resolving = _resolving | {ref}
|
| 315 |
+
# Only support local refs: "#/components/schemas/Foo"
|
| 316 |
+
parts = ref.lstrip("#/").split("/")
|
| 317 |
+
target = full_spec
|
| 318 |
+
for part in parts:
|
| 319 |
+
target = target.get(part, {}) if isinstance(target, dict) else {}
|
| 320 |
+
return resolve_refs(target, full_spec, _resolving)
|
| 321 |
+
return {k: resolve_refs(v, full_spec, _resolving) for k, v in obj.items()}
|
| 322 |
+
elif isinstance(obj, list):
|
| 323 |
+
return [resolve_refs(item, full_spec, _resolving) for item in obj]
|
| 324 |
+
return obj
|
| 325 |
+
|
| 326 |
+
def shorthand_spec(obj):
|
| 327 |
+
"""Convert JSON schema to ultra-compact shorthand string including enums and formats."""
|
| 328 |
+
if isinstance(obj, dict):
|
| 329 |
+
if "type" in obj:
|
| 330 |
+
t = obj["type"]
|
| 331 |
+
fmt = f":{obj['format']}" if "format" in obj else ""
|
| 332 |
+
enum_vals = f"[{'|'.join(map(str, obj['enum']))}]" if "enum" in obj else ""
|
| 333 |
+
|
| 334 |
+
if t == "object" and "properties" in obj:
|
| 335 |
+
req_list = obj.get("required", [])
|
| 336 |
+
props = []
|
| 337 |
+
for k, v in obj["properties"].items():
|
| 338 |
+
req = "*" if k in req_list or v.get("nullable") == False else ""
|
| 339 |
+
props.append(f"{k}{req}({shorthand_spec(v)})")
|
| 340 |
+
return "{" + ",".join(props) + "}"
|
| 341 |
+
if t == "array" and "items" in obj:
|
| 342 |
+
return f"[{shorthand_spec(obj['items'])}]"
|
| 343 |
+
|
| 344 |
+
return f"{t}{fmt}{enum_vals}"
|
| 345 |
+
return {k: shorthand_spec(v) for k, v in obj.items()}
|
| 346 |
+
return str(obj)
|
| 347 |
+
|
| 348 |
+
def prune_spec_for_execution(obj):
|
| 349 |
+
"""Recursively remove non-functional metadata (descriptions, examples, formats) to save tokens."""
|
| 350 |
+
if isinstance(obj, dict):
|
| 351 |
+
# Keys we definitely don't need for building an HTTP request
|
| 352 |
+
DROP_KEYS = {"description", "summary", "example", "examples", "format", "title", "default", "enum_descriptions"}
|
| 353 |
+
pruned = {}
|
| 354 |
+
for k, v in obj.items():
|
| 355 |
+
if k in DROP_KEYS:
|
| 356 |
+
continue
|
| 357 |
+
pruned[k] = prune_spec_for_execution(v)
|
| 358 |
+
return pruned
|
| 359 |
+
elif isinstance(obj, list):
|
| 360 |
+
return [prune_spec_for_execution(item) for item in obj]
|
| 361 |
+
return obj
|
| 362 |
+
|
| 363 |
+
actual_endpoint_spec = {"endpoint": endpoint_str}
|
| 364 |
+
|
| 365 |
+
if request.spec_id:
|
| 366 |
+
spec_doc = db.query(database.SpecDocument).filter(database.SpecDocument.id == request.spec_id).first()
|
| 367 |
+
if spec_doc and spec_doc.parsed_json:
|
| 368 |
+
full_spec = spec_doc.parsed_json
|
| 369 |
+
paths = full_spec.get("paths", {})
|
| 370 |
+
parts = endpoint_str.split(" ", 1)
|
| 371 |
+
def _match_path(path_template, actual_path):
|
| 372 |
+
"""Simple matcher for OpenAPI path templates like /buses/{bus_id}"""
|
| 373 |
+
import re
|
| 374 |
+
# Replace {param} with a regex group
|
| 375 |
+
pattern = re.sub(r'\{[^}]+\}', r'[^/]+', path_template)
|
| 376 |
+
# Handle trailing slashes
|
| 377 |
+
pattern = "^" + pattern.rstrip("/") + "/?$"
|
| 378 |
+
return bool(re.match(pattern, actual_path.split("?")[0]))
|
| 379 |
+
|
| 380 |
+
parts = endpoint_str.split(" ", 1)
|
| 381 |
+
path_only = parts[1] if len(parts) == 2 else parts[0]
|
| 382 |
+
|
| 383 |
+
# Try to find the exact or template match
|
| 384 |
+
matched_path = None
|
| 385 |
+
if path_only in paths:
|
| 386 |
+
matched_path = path_only
|
| 387 |
+
else:
|
| 388 |
+
for p in paths:
|
| 389 |
+
if _match_path(p, path_only):
|
| 390 |
+
matched_path = p
|
| 391 |
+
break
|
| 392 |
+
|
| 393 |
+
if matched_path:
|
| 394 |
+
raw_spec = {matched_path: paths[matched_path]}
|
| 395 |
+
# Inline all $ref so LLM sees the exact required fields
|
| 396 |
+
resolved = resolve_refs(raw_spec, full_spec)
|
| 397 |
+
|
| 398 |
+
# Optimization: Prune 'responses' as they are not needed for building the request
|
| 399 |
+
path_data = resolved.get(matched_path, {})
|
| 400 |
+
for method in path_data:
|
| 401 |
+
if isinstance(path_data[method], dict):
|
| 402 |
+
path_data[method].pop("responses", None)
|
| 403 |
+
|
| 404 |
+
# Pass through aggressive pruning to remove descriptions, examples, etc.
|
| 405 |
+
pruned = prune_spec_for_execution(resolved)
|
| 406 |
+
# CONVERT TO SHORTHAND
|
| 407 |
+
actual_endpoint_spec = shorthand_spec(pruned)
|
| 408 |
+
else:
|
| 409 |
+
print(f"[PATH MATCH FAIL] Could not find match for {path_only}. Falling back to simplified path list.")
|
| 410 |
+
# Fallback: Just send the relevant path/method info if we can't find the full schema
|
| 411 |
+
actual_endpoint_spec = {"endpoint": endpoint_str, "warning": "Full schema match failed"}
|
| 412 |
+
|
| 413 |
+
# Fetch semantic assets for AI context
|
| 414 |
+
rich_assets = AssetService.get_ai_context(db, request.spec_id)
|
| 415 |
+
|
| 416 |
+
# NEW: Fallback to stored credentials if none provided in request
|
| 417 |
+
effective_credentials = request.user_credentials
|
| 418 |
+
if not effective_credentials and request.spec_id:
|
| 419 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == request.spec_id).first()
|
| 420 |
+
if spec and spec.login_credentials:
|
| 421 |
+
effective_credentials = spec.login_credentials
|
| 422 |
+
print(f"[AUTH FALLBACK] Using stored credentials for spec '{spec.name}'")
|
| 423 |
+
|
| 424 |
+
# 1. Ask LLM to format the actual httpx request
|
| 425 |
+
req_plan, executor_token_usage = prepare_step_request(
|
| 426 |
+
endpoint_spec=actual_endpoint_spec,
|
| 427 |
+
base_url=request.base_url,
|
| 428 |
+
scenario="",
|
| 429 |
+
step_definition=request.step_definition,
|
| 430 |
+
context_variables=request.context_variables,
|
| 431 |
+
user_credentials=effective_credentials,
|
| 432 |
+
available_assets=rich_assets
|
| 433 |
+
)
|
| 434 |
+
|
| 435 |
+
# Sanitize URL: fix relative, missing-scheme, or placeholder URLs from the LLM
|
| 436 |
+
url = req_plan.request.url.strip()
|
| 437 |
+
PLACEHOLDER_HOSTS = {"api.example.com", "example.com", "<base_url>", "your-api.com"}
|
| 438 |
+
|
| 439 |
+
def _is_placeholder(u: str) -> bool:
|
| 440 |
+
try:
|
| 441 |
+
from urllib.parse import urlparse
|
| 442 |
+
host = urlparse(u).hostname or ""
|
| 443 |
+
return host.lower() in PLACEHOLDER_HOSTS or u.startswith("<BASE_URL>")
|
| 444 |
+
except Exception:
|
| 445 |
+
return False
|
| 446 |
+
|
| 447 |
+
if url.startswith("/"):
|
| 448 |
+
# Relative path — prepend base URL
|
| 449 |
+
url = request.base_url.rstrip("/") + url
|
| 450 |
+
elif _is_placeholder(url):
|
| 451 |
+
# LLM returned a placeholder domain — extract just the path and rebuild
|
| 452 |
+
from urllib.parse import urlparse
|
| 453 |
+
parsed = urlparse(url)
|
| 454 |
+
path = parsed.path or "/"
|
| 455 |
+
url = request.base_url.rstrip("/") + path
|
| 456 |
+
if parsed.query:
|
| 457 |
+
url += "?" + parsed.query
|
| 458 |
+
print(f"[URL FIX] Placeholder URL detected, rebuilt to: {url}")
|
| 459 |
+
elif not url.startswith("http"):
|
| 460 |
+
url = f"https://{url}"
|
| 461 |
+
|
| 462 |
+
# 2. Execute via httpx
|
| 463 |
+
async with httpx.AsyncClient(timeout=60.0) as client:
|
| 464 |
+
http_req = client.build_request(
|
| 465 |
+
method=req_plan.request.method.strip().upper(),
|
| 466 |
+
url=url,
|
| 467 |
+
headers=req_plan.request.headers,
|
| 468 |
+
params=req_plan.request.query_params,
|
| 469 |
+
data=req_plan.request.form_data if req_plan.request.form_data else None,
|
| 470 |
+
json=req_plan.request.body if req_plan.request.body and not req_plan.request.form_data else None
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
# Handle File Attachments if provided by LLM
|
| 474 |
+
files_payload = {}
|
| 475 |
+
opened_files = []
|
| 476 |
+
|
| 477 |
+
try:
|
| 478 |
+
if req_plan.request.files:
|
| 479 |
+
# Strip manually set Content-Type if files are present to let httpx handle the boundary
|
| 480 |
+
original_headers = {k: v for k, v in req_plan.request.headers.items() if k.lower() != 'content-type'}
|
| 481 |
+
req_plan.request.headers = original_headers
|
| 482 |
+
|
| 483 |
+
for field_name, file_name in req_plan.request.files.items():
|
| 484 |
+
# Find asset record by name
|
| 485 |
+
asset = db.query(database.Asset).filter(database.Asset.name == file_name).first()
|
| 486 |
+
if asset:
|
| 487 |
+
# Use StorageProvider to get full path
|
| 488 |
+
from backend.services.asset_service import storage
|
| 489 |
+
full_path = storage.get_full_path(asset.file_path)
|
| 490 |
+
if os.path.exists(full_path):
|
| 491 |
+
# Open file for reading
|
| 492 |
+
f = open(full_path, "rb")
|
| 493 |
+
opened_files.append(f)
|
| 494 |
+
files_payload[field_name] = (asset.name, f, asset.file_type)
|
| 495 |
+
else:
|
| 496 |
+
print(f"[ASSET ERROR] File '{file_name}' not found on disk at {full_path}")
|
| 497 |
+
else:
|
| 498 |
+
print(f"[ASSET ERROR] File '{file_name}' not found in Media Hub.")
|
| 499 |
+
|
| 500 |
+
# Print to backend console for debugging
|
| 501 |
+
print(f"Executing: {http_req.method} {http_req.url}")
|
| 502 |
+
|
| 503 |
+
try:
|
| 504 |
+
if files_payload:
|
| 505 |
+
response = await client.request(
|
| 506 |
+
method=req_plan.request.method.strip().upper(),
|
| 507 |
+
url=url,
|
| 508 |
+
headers=req_plan.request.headers,
|
| 509 |
+
params=req_plan.request.query_params,
|
| 510 |
+
data=req_plan.request.form_data if req_plan.request.form_data else None,
|
| 511 |
+
files=files_payload
|
| 512 |
+
)
|
| 513 |
+
else:
|
| 514 |
+
response = await client.send(http_req)
|
| 515 |
+
except Exception as e:
|
| 516 |
+
raise HTTPException(status_code=500, detail=f"Request to {url} failed: {str(e)}")
|
| 517 |
+
finally:
|
| 518 |
+
# CLOSE ALL FILE HANDLES
|
| 519 |
+
for f in opened_files:
|
| 520 |
+
f.close()
|
| 521 |
+
|
| 522 |
+
# Format the raw response
|
| 523 |
+
resp_data = {
|
| 524 |
+
"status_code": response.status_code,
|
| 525 |
+
"body": response.text,
|
| 526 |
+
"headers": dict(response.headers)
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
# Update the plan to reflect any URL cleanup
|
| 530 |
+
req_plan.request.url = url
|
| 531 |
+
|
| 532 |
+
# 3. Save to History
|
| 533 |
+
history = database.ExecutionHistory(
|
| 534 |
+
session_id=request.session_id,
|
| 535 |
+
step=req_plan.step,
|
| 536 |
+
request_json=req_plan.request.model_dump(),
|
| 537 |
+
response_json=resp_data,
|
| 538 |
+
step_definition_json=request.step_definition
|
| 539 |
+
)
|
| 540 |
+
db.add(history)
|
| 541 |
+
db.commit()
|
| 542 |
+
|
| 543 |
+
return {
|
| 544 |
+
"executed_request": req_plan.request.model_dump(),
|
| 545 |
+
"response": resp_data,
|
| 546 |
+
"analysis_needed": req_plan.step,
|
| 547 |
+
"token_usage": executor_token_usage
|
| 548 |
+
}
|
| 549 |
+
except Exception as e:
|
| 550 |
+
import traceback
|
| 551 |
+
trace = traceback.format_exc()
|
| 552 |
+
print(f"EXECUTION ERROR: {trace}")
|
| 553 |
+
raise HTTPException(status_code=500, detail=f"Execution failed: {str(e)}\n{trace}")
|
| 554 |
+
|
| 555 |
+
@app.post("/analyze-response", response_model=schemas.AnalyzeResponse)
|
| 556 |
+
def analyze_response_endpoint(request: schemas.AnalyzeRequest, db: Session = Depends(database.get_db)):
|
| 557 |
+
try:
|
| 558 |
+
step_def = request.step_definition or {}
|
| 559 |
+
endpoint_str = step_def.get("endpoint", "Unknown")
|
| 560 |
+
purpose_str = step_def.get("purpose", "Unknown")
|
| 561 |
+
|
| 562 |
+
# 1. Analyze it
|
| 563 |
+
analysis = analyze_api_response(
|
| 564 |
+
step=request.step,
|
| 565 |
+
endpoint=endpoint_str,
|
| 566 |
+
purpose=purpose_str,
|
| 567 |
+
status_code=request.response_data.get("status_code", 0),
|
| 568 |
+
response_body=request.response_data.get("body", "")
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
# 2. Save extracted variables ONLY to session context (session-scoped, not persisted to spec)
|
| 572 |
+
if analysis.extracted_variables:
|
| 573 |
+
set_context_variables(db, request.session_id, analysis.extracted_variables)
|
| 574 |
+
|
| 575 |
+
# 3. Update History
|
| 576 |
+
history = db.query(database.ExecutionHistory).filter(
|
| 577 |
+
database.ExecutionHistory.session_id == request.session_id,
|
| 578 |
+
database.ExecutionHistory.step == request.step
|
| 579 |
+
).order_by(database.ExecutionHistory.id.desc()).first()
|
| 580 |
+
|
| 581 |
+
if history:
|
| 582 |
+
history.analysis_json = analysis.model_dump()
|
| 583 |
+
db.commit()
|
| 584 |
+
|
| 585 |
+
return analysis
|
| 586 |
+
except Exception as e:
|
| 587 |
+
raise HTTPException(status_code=500, detail=f"Analysis failed: {str(e)}")
|
| 588 |
+
|
| 589 |
+
# ─────────────────────────────────────────────
|
| 590 |
+
# CREDENTIAL ENDPOINTS (per spec)
|
| 591 |
+
# ─────────────────────────────────────────────
|
| 592 |
+
|
| 593 |
+
@app.get("/specs/{spec_id}/credentials")
|
| 594 |
+
def get_credentials(spec_id: str, db: Session = Depends(database.get_db)):
|
| 595 |
+
"""Return stored login credentials for a spec."""
|
| 596 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == spec_id).first()
|
| 597 |
+
if not spec:
|
| 598 |
+
raise HTTPException(status_code=404, detail="Spec not found")
|
| 599 |
+
return spec.login_credentials or {}
|
| 600 |
+
|
| 601 |
+
@app.post("/specs/{spec_id}/credentials")
|
| 602 |
+
def save_credentials(spec_id: str, payload: schemas.CredentialUpdate, db: Session = Depends(database.get_db)):
|
| 603 |
+
"""Save/merge login credentials to a spec. Called manually from the UI."""
|
| 604 |
+
spec = db.query(database.SpecDocument).filter(database.SpecDocument.id == spec_id).first()
|
| 605 |
+
if not spec:
|
| 606 |
+
raise HTTPException(status_code=404, detail="Spec not found")
|
| 607 |
+
|
| 608 |
+
# If _clear flag is present, wipe all credentials
|
| 609 |
+
if payload.extra and payload.extra.get("_clear"):
|
| 610 |
+
spec.login_credentials = {}
|
| 611 |
+
flag_modified(spec, "login_credentials")
|
| 612 |
+
db.commit()
|
| 613 |
+
db.refresh(spec)
|
| 614 |
+
return {"status": "cleared", "credentials": {}}
|
| 615 |
+
|
| 616 |
+
current: dict = dict(spec.login_credentials or {})
|
| 617 |
+
if payload.name is not None:
|
| 618 |
+
current["name"] = payload.name
|
| 619 |
+
if payload.username is not None:
|
| 620 |
+
current["username"] = payload.username
|
| 621 |
+
current["email"] = payload.username # store under both keys
|
| 622 |
+
if payload.password is not None:
|
| 623 |
+
current["password"] = payload.password
|
| 624 |
+
if payload.extra:
|
| 625 |
+
# Filter out internal-only keys like _clear before saving
|
| 626 |
+
extra_clean = {k: v for k, v in payload.extra.items() if not k.startswith("_")}
|
| 627 |
+
current.update(extra_clean)
|
| 628 |
+
spec.login_credentials = current
|
| 629 |
+
flag_modified(spec, "login_credentials")
|
| 630 |
+
db.commit()
|
| 631 |
+
db.refresh(spec)
|
| 632 |
+
return {"status": "saved", "credentials": spec.login_credentials}
|
| 633 |
+
|
| 634 |
+
@app.get("/context/{session_id}")
|
| 635 |
+
def get_context_endpoint(session_id: str, db: Session = Depends(database.get_db)):
|
| 636 |
+
"""Return only session context variables (dynamic values from previous steps)."""
|
| 637 |
+
context = get_context(db, session_id)
|
| 638 |
+
return context
|
| 639 |
+
|
| 640 |
+
@app.delete("/session/{session_id}")
|
| 641 |
+
def clear_session(session_id: str, db: Session = Depends(database.get_db)):
|
| 642 |
+
session = db.query(database.SessionModel).filter(database.SessionModel.id == session_id).first()
|
| 643 |
+
if session:
|
| 644 |
+
db.delete(session)
|
| 645 |
+
db.query(database.ExecutionHistory).filter(database.ExecutionHistory.session_id == session_id).delete()
|
| 646 |
+
db.commit()
|
| 647 |
+
return {"status": "ok"}
|
| 648 |
+
|
| 649 |
+
@app.get("/history")
|
| 650 |
+
def get_all_history(db: Session = Depends(database.get_db)):
|
| 651 |
+
"""Fetch all execution history joined with session metadata."""
|
| 652 |
+
results = db.query(
|
| 653 |
+
database.ExecutionHistory,
|
| 654 |
+
database.SessionModel
|
| 655 |
+
).join(
|
| 656 |
+
database.SessionModel,
|
| 657 |
+
database.ExecutionHistory.session_id == database.SessionModel.id
|
| 658 |
+
).order_by(database.ExecutionHistory.timestamp.desc()).all()
|
| 659 |
+
|
| 660 |
+
history_list = []
|
| 661 |
+
for hist, sess in results:
|
| 662 |
+
history_list.append({
|
| 663 |
+
"id": hist.id,
|
| 664 |
+
"session_id": hist.session_id,
|
| 665 |
+
"spec_id": sess.spec_id,
|
| 666 |
+
"spec_name": sess.spec_name or "Unknown",
|
| 667 |
+
"scenario": sess.scenario or "No scenario",
|
| 668 |
+
"context_variables": sess.context_variables or {},
|
| 669 |
+
"step": hist.step,
|
| 670 |
+
"request": hist.request_json,
|
| 671 |
+
"response": hist.response_json,
|
| 672 |
+
"analysis": hist.analysis_json,
|
| 673 |
+
"step_definition": hist.step_definition_json,
|
| 674 |
+
"timestamp": hist.timestamp.isoformat()
|
| 675 |
+
})
|
| 676 |
+
return history_list
|
| 677 |
+
|
| 678 |
+
@app.delete("/history/{session_id}")
|
| 679 |
+
def delete_history_session(session_id: str, db: Session = Depends(database.get_db)):
|
| 680 |
+
"""Delete a specific session and all its execution history."""
|
| 681 |
+
db.query(database.ExecutionHistory).filter(database.ExecutionHistory.session_id == session_id).delete()
|
| 682 |
+
db.query(database.SessionModel).filter(database.SessionModel.id == session_id).delete()
|
| 683 |
+
db.commit()
|
| 684 |
+
return {"status": "deleted", "session_id": session_id}
|
| 685 |
+
|
| 686 |
+
@app.delete("/history")
|
| 687 |
+
def clear_all_history_endpoint(db: Session = Depends(database.get_db)):
|
| 688 |
+
"""Wipe all execution history and session metadata."""
|
| 689 |
+
db.query(database.ExecutionHistory).delete()
|
| 690 |
+
db.query(database.SessionModel).delete()
|
| 691 |
+
db.commit()
|
| 692 |
+
return {"status": "cleared"}
|
| 693 |
+
|
backend/schemas.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel, HttpUrl, Field
|
| 2 |
+
from typing import Dict, Any, List, Optional
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
class TokenUsage(BaseModel):
|
| 6 |
+
prompt_tokens: int
|
| 7 |
+
completion_tokens: int
|
| 8 |
+
total_tokens: int
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class PlanRequest(BaseModel):
|
| 12 |
+
spec_content: Any
|
| 13 |
+
base_url: str
|
| 14 |
+
scenario: str
|
| 15 |
+
user_credentials: Optional[Dict[str, Any]] = None
|
| 16 |
+
spec_id: Optional[str] = None
|
| 17 |
+
session_id: Optional[str] = None
|
| 18 |
+
|
| 19 |
+
class StepDefinition(BaseModel):
|
| 20 |
+
step: int
|
| 21 |
+
endpoint: str
|
| 22 |
+
purpose: str
|
| 23 |
+
|
| 24 |
+
class ExecutionPlan(BaseModel):
|
| 25 |
+
execution_plan: List[StepDefinition]
|
| 26 |
+
suggested_credentials: Optional[Dict[str, Any]] = None
|
| 27 |
+
token_usage: Optional[TokenUsage] = None
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class ExecuteStepRequest(BaseModel):
|
| 31 |
+
session_id: str
|
| 32 |
+
step_definition: Dict[str, Any]
|
| 33 |
+
context_variables: Dict[str, Any]
|
| 34 |
+
user_credentials: Dict[str, Any] = {} # Separate from context — static auth info (name, email, password, token)
|
| 35 |
+
base_url: str
|
| 36 |
+
spec_id: Optional[str] = None
|
| 37 |
+
|
| 38 |
+
class AnalyzeRequest(BaseModel):
|
| 39 |
+
session_id: str
|
| 40 |
+
step: int
|
| 41 |
+
response_data: Dict[str, Any]
|
| 42 |
+
spec_id: Optional[str] = None # Which spec to save credentials to
|
| 43 |
+
step_definition: Optional[Dict[str, Any]] = None # Step info for login detection
|
| 44 |
+
|
| 45 |
+
class ContextUpdate(BaseModel):
|
| 46 |
+
session_id: str
|
| 47 |
+
key: str
|
| 48 |
+
value: Any
|
| 49 |
+
|
| 50 |
+
class AnalyzeResponse(BaseModel):
|
| 51 |
+
step: int
|
| 52 |
+
status: str
|
| 53 |
+
is_otp_required: bool = False
|
| 54 |
+
otp_field_name: Optional[str] = None
|
| 55 |
+
response_summary: Optional[str] = ""
|
| 56 |
+
extracted_variables: Dict[str, Any] = Field(default_factory=dict)
|
| 57 |
+
token_usage: Optional[TokenUsage] = None
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class CredentialUpdate(BaseModel):
|
| 61 |
+
name: Optional[str] = None
|
| 62 |
+
username: Optional[str] = None
|
| 63 |
+
password: Optional[str] = None
|
| 64 |
+
extra: Optional[Dict[str, Any]] = None # Additional fields (tokens, custom KVs etc.)
|
backend/services/__init__.py
ADDED
|
File without changes
|
backend/services/api_executor.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Dict, Any, List
|
| 3 |
+
from langchain_core.prompts import PromptTemplate
|
| 4 |
+
from langchain_mistralai.chat_models import ChatMistralAI
|
| 5 |
+
from langchain_core.output_parsers import JsonOutputParser
|
| 6 |
+
from pydantic import BaseModel, Field
|
| 7 |
+
|
| 8 |
+
# Using Pydantic to structure LangChain output for step execution
|
| 9 |
+
class APIRequest(BaseModel):
|
| 10 |
+
method: str
|
| 11 |
+
url: str
|
| 12 |
+
headers: Dict[str, Any] = Field(default_factory=dict)
|
| 13 |
+
query_params: Dict[str, Any] = Field(default_factory=dict)
|
| 14 |
+
form_data: Dict[str, Any] = Field(default_factory=dict)
|
| 15 |
+
body: Dict[str, Any] = Field(default_factory=dict)
|
| 16 |
+
files: Dict[str, str] = Field(default_factory=dict) # NEW: {fieldName: fileName}
|
| 17 |
+
|
| 18 |
+
class StepAnalysis(BaseModel):
|
| 19 |
+
required_inputs: List[Any] = Field(default_factory=list)
|
| 20 |
+
values_from_previous_steps: List[Any] = Field(default_factory=list)
|
| 21 |
+
generated_test_data: List[Any] = Field(default_factory=list)
|
| 22 |
+
|
| 23 |
+
class StepExecutionPlan(BaseModel):
|
| 24 |
+
step: int
|
| 25 |
+
request: APIRequest
|
| 26 |
+
analysis: StepAnalysis
|
| 27 |
+
|
| 28 |
+
# Prompt template for step preparation
|
| 29 |
+
STEP_PROMPT = """
|
| 30 |
+
You are an API execution assistant. Your job is to build a precise HTTP request for the CURRENT step.
|
| 31 |
+
|
| 32 |
+
NOTATION IN SPEC:
|
| 33 |
+
- {{prop*(str)}}: 'prop' is a REQUIRED string.
|
| 34 |
+
- {{prop(int)}}: 'prop' is an OPTIONAL integer.
|
| 35 |
+
- {{status(str[active|inactive])}}: 'status' is a string that MUST be one of the enum values [active, inactive].
|
| 36 |
+
- {{date(string:date-time)}}: 'date' is a string in date-time format.
|
| 37 |
+
|
| 38 |
+
INPUTS:
|
| 39 |
+
1. API Spec (current endpoint): {endpoint_spec}
|
| 40 |
+
2. Base URL: {base_url}
|
| 41 |
+
3. Scenario: {scenario}
|
| 42 |
+
4. Current Step: {step_definition}
|
| 43 |
+
5. User Credentials: {user_credentials}
|
| 44 |
+
6. Context Variables (Priority): {context_variables}
|
| 45 |
+
7. Assets (Semantic Context): {available_assets}
|
| 46 |
+
|
| 47 |
+
CORE EXECUTION RULES:
|
| 48 |
+
1. URL & PATH PARAMETERS:
|
| 49 |
+
- You MUST replace all path variables like {{id}} or {{bus_id}} with actual values from Context or Step Definition.
|
| 50 |
+
- Example: If URL is "/buses/{{bus_id}}" and Context has bus_id=101, result URL must be "/buses/101".
|
| 51 |
+
2. AUTHORIZATION:
|
| 52 |
+
- If User Credentials or Context Variables contain a "token", "access_token", or "jwt", you MUST include an "Authorization": "Bearer <token>" header unless otherwise specified.
|
| 53 |
+
3. DATA SOURCE PRIORITY:
|
| 54 |
+
- Priority 1: Context Variables (from previous steps).
|
| 55 |
+
- Priority 2: User Credentials (for login/auth).
|
| 56 |
+
- Priority 3: Step Definition / Scenario data.
|
| 57 |
+
4. STRICT ENUM ADHERENCE:
|
| 58 |
+
- If a field has an enum like [A|B|C], you MUST pick one of those exact values.
|
| 59 |
+
5. FORM vs JSON:
|
| 60 |
+
- Content-Type: application/x-www-form-urlencoded -> use 'form_data'.
|
| 61 |
+
- Content-Type: application/json -> use 'body'.
|
| 62 |
+
6. FILES: Use 'files' object {{"field": "filename"}} using names from the provided Assets.
|
| 63 |
+
|
| 64 |
+
RETURN JSON ONLY:
|
| 65 |
+
{{
|
| 66 |
+
"step": 1,
|
| 67 |
+
"request": {{
|
| 68 |
+
"method": "POST", "url": "<FULL_URL_WITH_PARAMS_REPLACED>", "headers": {{"Authorization": "Bearer ..."}},
|
| 69 |
+
"query_params": {{}}, "form_data": {{}}, "body": {{}}, "files": {{}}
|
| 70 |
+
}},
|
| 71 |
+
"analysis": {{
|
| 72 |
+
"required_inputs": ["list_of_fields_you_filled"],
|
| 73 |
+
"values_from_previous_steps": ["list_of_fields_taken_from_context"],
|
| 74 |
+
"generated_test_data": ["list_of_fields_you_invented"]
|
| 75 |
+
}}
|
| 76 |
+
}}
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
def prepare_step_request(
|
| 80 |
+
endpoint_spec: Dict[str, Any],
|
| 81 |
+
base_url: str,
|
| 82 |
+
scenario: str,
|
| 83 |
+
step_definition: Dict[str, Any],
|
| 84 |
+
context_variables: Dict[str, Any],
|
| 85 |
+
user_credentials: Dict[str, Any] = {},
|
| 86 |
+
available_assets: Dict[str, Any] = {}
|
| 87 |
+
) -> StepExecutionPlan:
|
| 88 |
+
"""
|
| 89 |
+
Uses Mistral AI via LangChain to build the exact HTTP request for a single step.
|
| 90 |
+
'available_assets' is now a structured dict with collections and uncategorized files.
|
| 91 |
+
"""
|
| 92 |
+
parser = JsonOutputParser(pydantic_object=StepExecutionPlan)
|
| 93 |
+
|
| 94 |
+
prompt = PromptTemplate(
|
| 95 |
+
template=STEP_PROMPT,
|
| 96 |
+
input_variables=["endpoint_spec", "base_url", "scenario", "step_definition", "user_credentials", "context_variables", "available_assets"],
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
llm = ChatMistralAI(model_name="mistral-large-latest", temperature=0)
|
| 100 |
+
chain = prompt | llm | parser
|
| 101 |
+
|
| 102 |
+
msg = prompt.format_prompt(
|
| 103 |
+
endpoint_spec=json.dumps(endpoint_spec, separators=(',', ':')),
|
| 104 |
+
base_url=base_url,
|
| 105 |
+
scenario=scenario,
|
| 106 |
+
step_definition=json.dumps(step_definition, separators=(',', ':')),
|
| 107 |
+
user_credentials=json.dumps(user_credentials, separators=(',', ':')),
|
| 108 |
+
context_variables=json.dumps(context_variables, separators=(',', ':')),
|
| 109 |
+
available_assets=json.dumps(available_assets, separators=(',', ':'))
|
| 110 |
+
).to_messages()
|
| 111 |
+
|
| 112 |
+
ai_msg = llm.invoke(msg)
|
| 113 |
+
parsed_response = parser.parse(ai_msg.content)
|
| 114 |
+
|
| 115 |
+
# Extract token usage
|
| 116 |
+
usage = ai_msg.response_metadata.get("token_usage", {})
|
| 117 |
+
token_usage = None
|
| 118 |
+
if usage:
|
| 119 |
+
token_usage = {
|
| 120 |
+
"prompt_tokens": usage.get("prompt_tokens", 0),
|
| 121 |
+
"completion_tokens": usage.get("completion_tokens", 0),
|
| 122 |
+
"total_tokens": usage.get("total_tokens", 0)
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return StepExecutionPlan(**parsed_response), token_usage
|
backend/services/asset_service.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
from typing import List, Optional, Dict, Any
|
| 4 |
+
from sqlalchemy.orm import Session
|
| 5 |
+
from ..database import Asset, Collection, SpecDocument
|
| 6 |
+
from .storage import LocalStorageProvider
|
| 7 |
+
|
| 8 |
+
storage = LocalStorageProvider()
|
| 9 |
+
|
| 10 |
+
def get_category(filename: str, content_type: str) -> str:
|
| 11 |
+
ext = os.path.splitext(filename)[1].lower()
|
| 12 |
+
if ext in ['.mp3', '.wav', '.ogg', '.m4a'] or (content_type and content_type.startswith('audio/')):
|
| 13 |
+
return 'audio'
|
| 14 |
+
if ext in ['.mp4', '.mov', '.avi', '.mkv'] or (content_type and content_type.startswith('video/')):
|
| 15 |
+
return 'video'
|
| 16 |
+
if ext in ['.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp'] or (content_type and content_type.startswith('image/')):
|
| 17 |
+
return 'images'
|
| 18 |
+
return 'documents'
|
| 19 |
+
|
| 20 |
+
class AssetService:
|
| 21 |
+
@staticmethod
|
| 22 |
+
def upload_asset(
|
| 23 |
+
db: Session,
|
| 24 |
+
file: Any,
|
| 25 |
+
spec_id: Optional[str] = None,
|
| 26 |
+
description: Optional[str] = None,
|
| 27 |
+
tags: List[str] = []
|
| 28 |
+
) -> Asset:
|
| 29 |
+
file_id = str(uuid.uuid4())
|
| 30 |
+
file_ext = os.path.splitext(file.filename)[1]
|
| 31 |
+
category = get_category(file.filename, file.content_type)
|
| 32 |
+
|
| 33 |
+
relative_path = os.path.join(category, f"{file_id}{file_ext}")
|
| 34 |
+
full_path = storage.save(file.file, relative_path)
|
| 35 |
+
|
| 36 |
+
file_size = os.path.getsize(full_path)
|
| 37 |
+
|
| 38 |
+
new_asset = Asset(
|
| 39 |
+
id=file_id,
|
| 40 |
+
name=file.filename,
|
| 41 |
+
file_type=file.content_type or "application/octet-stream",
|
| 42 |
+
file_path=relative_path, # store relative path
|
| 43 |
+
file_size=file_size,
|
| 44 |
+
category=category,
|
| 45 |
+
description=description,
|
| 46 |
+
tags=tags,
|
| 47 |
+
spec_id=spec_id
|
| 48 |
+
)
|
| 49 |
+
db.add(new_asset)
|
| 50 |
+
db.commit()
|
| 51 |
+
db.refresh(new_asset)
|
| 52 |
+
return new_asset
|
| 53 |
+
|
| 54 |
+
@staticmethod
|
| 55 |
+
def get_assets(db: Session, spec_id: Optional[str] = None, category: Optional[str] = None) -> List[Asset]:
|
| 56 |
+
query = db.query(Asset)
|
| 57 |
+
if spec_id:
|
| 58 |
+
query = query.filter(Asset.spec_id == spec_id)
|
| 59 |
+
if category:
|
| 60 |
+
query = query.filter(Asset.category == category)
|
| 61 |
+
return query.order_by(Asset.uploaded_at.desc()).all()
|
| 62 |
+
|
| 63 |
+
@staticmethod
|
| 64 |
+
def delete_asset(db: Session, asset_id: str):
|
| 65 |
+
asset = db.query(Asset).filter(Asset.id == asset_id).first()
|
| 66 |
+
if asset:
|
| 67 |
+
storage.delete(asset.file_path)
|
| 68 |
+
db.delete(asset)
|
| 69 |
+
db.commit()
|
| 70 |
+
return True
|
| 71 |
+
return False
|
| 72 |
+
|
| 73 |
+
@staticmethod
|
| 74 |
+
def get_ai_context(db: Session, spec_id: Optional[str] = None) -> Dict[str, Any]:
|
| 75 |
+
"""Returns a structured view of assets for the AI to pick from."""
|
| 76 |
+
assets = AssetService.get_assets(db, spec_id)
|
| 77 |
+
collections = db.query(Collection).all()
|
| 78 |
+
|
| 79 |
+
context = {
|
| 80 |
+
"collections": [],
|
| 81 |
+
"uncategorized": []
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
# Build collections view
|
| 85 |
+
collection_map = {}
|
| 86 |
+
for col in collections:
|
| 87 |
+
col_data = {
|
| 88 |
+
"name": col.name,
|
| 89 |
+
"description": col.description,
|
| 90 |
+
"assets": []
|
| 91 |
+
}
|
| 92 |
+
context["collections"].append(col_data)
|
| 93 |
+
collection_map[col.id] = col_data
|
| 94 |
+
|
| 95 |
+
asset_in_collection_ids = set()
|
| 96 |
+
for col in collections:
|
| 97 |
+
for asset in col.assets:
|
| 98 |
+
asset_in_collection_ids.add(asset.id)
|
| 99 |
+
collection_map[col.id]["assets"].append({
|
| 100 |
+
"name": asset.name,
|
| 101 |
+
"type": asset.file_type,
|
| 102 |
+
"tags": asset.tags,
|
| 103 |
+
"purpose": asset.description
|
| 104 |
+
})
|
| 105 |
+
|
| 106 |
+
# Add uncategorized assets
|
| 107 |
+
for asset in assets:
|
| 108 |
+
if asset.id not in asset_in_collection_ids:
|
| 109 |
+
context["uncategorized"].append({
|
| 110 |
+
"name": asset.name,
|
| 111 |
+
"type": asset.file_type,
|
| 112 |
+
"tags": asset.tags,
|
| 113 |
+
"purpose": asset.description
|
| 114 |
+
})
|
| 115 |
+
|
| 116 |
+
return context
|
| 117 |
+
|
| 118 |
+
@staticmethod
|
| 119 |
+
def create_collection(db: Session, name: str, description: Optional[str] = None) -> Collection:
|
| 120 |
+
new_col = Collection(name=name, description=description)
|
| 121 |
+
db.add(new_col)
|
| 122 |
+
db.commit()
|
| 123 |
+
db.refresh(new_col)
|
| 124 |
+
return new_col
|
| 125 |
+
|
| 126 |
+
@staticmethod
|
| 127 |
+
def add_to_collection(db: Session, asset_id: str, collection_id: str):
|
| 128 |
+
asset = db.query(Asset).filter(Asset.id == asset_id).first()
|
| 129 |
+
collection = db.query(Collection).filter(Collection.id == collection_id).first()
|
| 130 |
+
if asset and collection:
|
| 131 |
+
if asset not in collection.assets:
|
| 132 |
+
collection.assets.append(asset)
|
| 133 |
+
db.commit()
|
| 134 |
+
return True
|
| 135 |
+
return False
|
backend/services/context_manager.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from sqlalchemy.orm import Session
|
| 3 |
+
from sqlalchemy.orm.attributes import flag_modified
|
| 4 |
+
from backend.database import SessionModel
|
| 5 |
+
|
| 6 |
+
def get_context(db: Session, session_id: str) -> dict:
|
| 7 |
+
session = db.query(SessionModel).filter(SessionModel.id == session_id).first()
|
| 8 |
+
if not session:
|
| 9 |
+
return {}
|
| 10 |
+
return session.context_variables or {}
|
| 11 |
+
|
| 12 |
+
def set_context_variables(db: Session, session_id: str, variables: dict) -> dict:
|
| 13 |
+
session = db.query(SessionModel).filter(SessionModel.id == session_id).first()
|
| 14 |
+
if session:
|
| 15 |
+
current_context = session.context_variables or {}
|
| 16 |
+
current_context.update(variables)
|
| 17 |
+
session.context_variables = current_context
|
| 18 |
+
|
| 19 |
+
# Explicitly flag JSON column as modified for SQLAlchemy
|
| 20 |
+
flag_modified(session, "context_variables")
|
| 21 |
+
|
| 22 |
+
db.commit()
|
| 23 |
+
db.refresh(session)
|
| 24 |
+
return session.context_variables
|
| 25 |
+
return {}
|
| 26 |
+
|
| 27 |
+
def get_context_variable(db: Session, session_id: str, key: str) -> any:
|
| 28 |
+
context = get_context(db, session_id)
|
| 29 |
+
return context.get(key)
|
backend/services/llm_planner.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Dict, Any, List, Optional
|
| 3 |
+
from langchain_core.prompts import PromptTemplate
|
| 4 |
+
from langchain_mistralai.chat_models import ChatMistralAI
|
| 5 |
+
from langchain_core.output_parsers import JsonOutputParser
|
| 6 |
+
from backend.schemas import ExecutionPlan
|
| 7 |
+
|
| 8 |
+
# Prompt template from the user prompt
|
| 9 |
+
PLANNER_PROMPT = """
|
| 10 |
+
You are an intelligent AI API testing planner and execution assistant.
|
| 11 |
+
|
| 12 |
+
Your job is to read API documentation extracted from a Swagger/OpenAPI file and execute API testing scenarios provided by the user in natural language.
|
| 13 |
+
|
| 14 |
+
You must perform reasoning before every step and plan API execution carefully.
|
| 15 |
+
|
| 16 |
+
INPUTS PROVIDED TO YOU
|
| 17 |
+
1. Parsed Swagger/OpenAPI documentation containing endpoints, methods, parameters, etc.
|
| 18 |
+
2. Base URL of the API server.
|
| 19 |
+
3. A tester scenario written in natural language.
|
| 20 |
+
|
| 21 |
+
OBJECTIVE
|
| 22 |
+
You must convert the tester scenario into a sequence of API calls and manage dependencies between requests.
|
| 23 |
+
|
| 24 |
+
EXECUTION PLAN FORMAT
|
| 25 |
+
You must return ONLY a JSON object representing the execution plan. DO NOT include markdown formatting or explanations. The format must exactly match:
|
| 26 |
+
{{
|
| 27 |
+
"execution_plan": [
|
| 28 |
+
{{
|
| 29 |
+
"step": 1,
|
| 30 |
+
"endpoint": "POST /auth/register",
|
| 31 |
+
"purpose": "Register a new user"
|
| 32 |
+
}},
|
| 33 |
+
{{
|
| 34 |
+
"step": 2,
|
| 35 |
+
"endpoint": "POST /auth/login",
|
| 36 |
+
"purpose": "Authenticate the user"
|
| 37 |
+
}}
|
| 38 |
+
],
|
| 39 |
+
"suggested_credentials": {{
|
| 40 |
+
"username": "tester_user",
|
| 41 |
+
"password": "Password123!",
|
| 42 |
+
"email": "tester@example.com"
|
| 43 |
+
}}
|
| 44 |
+
}}
|
| 45 |
+
|
| 46 |
+
API DOCUMENTATION:
|
| 47 |
+
{parsed_spec}
|
| 48 |
+
|
| 49 |
+
BASE URL:
|
| 50 |
+
{base_url}
|
| 51 |
+
|
| 52 |
+
TESTER SCENARIO:
|
| 53 |
+
{scenario}
|
| 54 |
+
|
| 55 |
+
USER CREDENTIALS (If present, user already exists):
|
| 56 |
+
{user_credentials_str}
|
| 57 |
+
|
| 58 |
+
IMPORTANT:
|
| 59 |
+
- If the USER CREDENTIALS section above contains data (i.e. is not an empty {{}} object), it means a test user profile already exists. You MUST NOT include any steps in your execution plan to register, sign up, or create a new user. You should skip user creation entirely and proceed directly with login or other actions.
|
| 60 |
+
- If the USER CREDENTIALS section is empty AND your plan requires authentication or user creation, you MUST provide a "suggested_credentials" object with realistic data (username, password, name, etc.) that can be used for these new accounts.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
def generate_execution_plan(parsed_spec: Dict[str, Any], base_url: str, scenario: str, user_credentials: Optional[Dict[str, Any]] = None) -> ExecutionPlan:
|
| 64 |
+
"""
|
| 65 |
+
Uses Mistral AI via LangChain to generate an execution plan based on the scenario.
|
| 66 |
+
"""
|
| 67 |
+
# Initialize JSON parser to enforce structured output
|
| 68 |
+
parser = JsonOutputParser(pydantic_object=ExecutionPlan)
|
| 69 |
+
|
| 70 |
+
# Initialize Prompt Template
|
| 71 |
+
prompt = PromptTemplate(
|
| 72 |
+
template=PLANNER_PROMPT,
|
| 73 |
+
input_variables=["parsed_spec", "base_url", "scenario", "user_credentials_str"],
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# Initialize Mistral Model (requires MISTRAL_API_KEY in env)
|
| 77 |
+
llm = ChatMistralAI(model_name="mistral-large-latest", temperature=0)
|
| 78 |
+
|
| 79 |
+
msg = prompt.format_prompt(
|
| 80 |
+
parsed_spec=json.dumps(parsed_spec.get("endpoints", parsed_spec), separators=(',', ':')),
|
| 81 |
+
base_url=base_url,
|
| 82 |
+
scenario=scenario,
|
| 83 |
+
user_credentials_str=json.dumps(user_credentials or {}, separators=(',', ':'))
|
| 84 |
+
).to_messages()
|
| 85 |
+
|
| 86 |
+
ai_msg = llm.invoke(msg)
|
| 87 |
+
parsed_response = parser.parse(ai_msg.content)
|
| 88 |
+
|
| 89 |
+
# Extract token usage
|
| 90 |
+
usage = ai_msg.response_metadata.get("token_usage", {})
|
| 91 |
+
token_usage = None
|
| 92 |
+
if usage:
|
| 93 |
+
token_usage = {
|
| 94 |
+
"prompt_tokens": usage.get("prompt_tokens", 0),
|
| 95 |
+
"completion_tokens": usage.get("completion_tokens", 0),
|
| 96 |
+
"total_tokens": usage.get("total_tokens", 0)
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
# Return as Pydantic model
|
| 100 |
+
return ExecutionPlan(
|
| 101 |
+
execution_plan=parsed_response["execution_plan"],
|
| 102 |
+
suggested_credentials=parsed_response.get("suggested_credentials"),
|
| 103 |
+
token_usage=token_usage
|
| 104 |
+
)
|
backend/services/postman_parser.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Dict, Any, List
|
| 3 |
+
|
| 4 |
+
def parse_postman_collection(content_str: str) -> Dict[str, Any]:
|
| 5 |
+
"""
|
| 6 |
+
Parses a Postman Collection (V2.1) JSON string.
|
| 7 |
+
Returns a structure compatible with the LLM planner and executor.
|
| 8 |
+
"""
|
| 9 |
+
try:
|
| 10 |
+
data = json.loads(content_str)
|
| 11 |
+
except json.JSONDecodeError as e:
|
| 12 |
+
raise ValueError(f"Failed to parse Postman collection as JSON: {e}")
|
| 13 |
+
|
| 14 |
+
# Check if it's a Postman collection
|
| 15 |
+
info = data.get("info", {})
|
| 16 |
+
schema = info.get("schema", "")
|
| 17 |
+
if "postman.com/json/collection" not in schema:
|
| 18 |
+
raise ValueError("Not a valid Postman collection (missing schema identifier)")
|
| 19 |
+
|
| 20 |
+
title = info.get("name", "Postman Collection")
|
| 21 |
+
version = "2.1" # Standard for most modern exports
|
| 22 |
+
|
| 23 |
+
all_requests = []
|
| 24 |
+
|
| 25 |
+
def extract_items(items):
|
| 26 |
+
for item in items:
|
| 27 |
+
if "item" in item:
|
| 28 |
+
# This is a folder, recurse
|
| 29 |
+
extract_items(item["item"])
|
| 30 |
+
elif "request" in item:
|
| 31 |
+
# This is a request
|
| 32 |
+
request = item["request"]
|
| 33 |
+
name = item.get("name", "")
|
| 34 |
+
|
| 35 |
+
# Extract path and method
|
| 36 |
+
method = request.get("method", "GET").upper()
|
| 37 |
+
url_obj = request.get("url", {})
|
| 38 |
+
|
| 39 |
+
path = ""
|
| 40 |
+
raw_url = ""
|
| 41 |
+
if isinstance(url_obj, str):
|
| 42 |
+
raw_url = url_obj
|
| 43 |
+
# Try to get path from string
|
| 44 |
+
path = url_obj.split("?")[0]
|
| 45 |
+
elif isinstance(url_obj, dict):
|
| 46 |
+
raw_url = url_obj.get("raw", "")
|
| 47 |
+
path_parts = url_obj.get("path", [])
|
| 48 |
+
if isinstance(path_parts, list):
|
| 49 |
+
path = "/" + "/".join([str(p) for p in path_parts])
|
| 50 |
+
else:
|
| 51 |
+
path = str(path_parts)
|
| 52 |
+
|
| 53 |
+
# Extract headers
|
| 54 |
+
headers = {}
|
| 55 |
+
for h in request.get("header", []):
|
| 56 |
+
if not h.get("disabled"):
|
| 57 |
+
headers[h.get("key")] = h.get("value")
|
| 58 |
+
|
| 59 |
+
# Extract body
|
| 60 |
+
body_info = request.get("body", {})
|
| 61 |
+
body = None
|
| 62 |
+
if body_info.get("mode") == "raw":
|
| 63 |
+
try:
|
| 64 |
+
body = json.loads(body_info.get("raw", "{}"))
|
| 65 |
+
except:
|
| 66 |
+
body = body_info.get("raw")
|
| 67 |
+
elif body_info.get("mode") == "urlencoded":
|
| 68 |
+
body = {p.get("key"): p.get("value") for p in body_info.get("urlencoded", []) if not p.get("disabled")}
|
| 69 |
+
elif body_info.get("mode") == "formdata":
|
| 70 |
+
body = {p.get("key"): p.get("value") for p in body_info.get("formdata", []) if not p.get("disabled")}
|
| 71 |
+
|
| 72 |
+
# Extract description
|
| 73 |
+
description = request.get("description", "")
|
| 74 |
+
if isinstance(description, dict):
|
| 75 |
+
description = description.get("content", "")
|
| 76 |
+
|
| 77 |
+
all_requests.append({
|
| 78 |
+
"name": name,
|
| 79 |
+
"method": method,
|
| 80 |
+
"path": path,
|
| 81 |
+
"raw_url": raw_url,
|
| 82 |
+
"headers": headers,
|
| 83 |
+
"body": body,
|
| 84 |
+
"description": description
|
| 85 |
+
})
|
| 86 |
+
|
| 87 |
+
extract_items(data.get("item", []))
|
| 88 |
+
|
| 89 |
+
# Build simplified endpoints for the LLM planner
|
| 90 |
+
simplified_endpoints = []
|
| 91 |
+
for req in all_requests:
|
| 92 |
+
simplified_endpoints.append({
|
| 93 |
+
"path": req["path"],
|
| 94 |
+
"method": str(req.get("method", "GET")),
|
| 95 |
+
"summary": str(req.get("name", "Unnamed Request"))[:100]
|
| 96 |
+
})
|
| 97 |
+
|
| 98 |
+
# Prepare the "paths" object for the executor, mimicking OpenAPI structure
|
| 99 |
+
# The executor uses this to find schemas, but for Postman we just provide the request details directly
|
| 100 |
+
# since there's no formal schema in the same way.
|
| 101 |
+
paths = {}
|
| 102 |
+
for req in all_requests:
|
| 103 |
+
p = req["path"]
|
| 104 |
+
m = str(req.get("method", "get")).lower()
|
| 105 |
+
if p not in paths:
|
| 106 |
+
paths[p] = {}
|
| 107 |
+
|
| 108 |
+
# Structure this to be somewhat compatible with what api_executor expects
|
| 109 |
+
paths[p][m] = {
|
| 110 |
+
"summary": req["name"],
|
| 111 |
+
"description": req["description"],
|
| 112 |
+
"parameters": [], # Postman doesn't always have typed params
|
| 113 |
+
"requestBody": {
|
| 114 |
+
"content": {
|
| 115 |
+
"application/json": {
|
| 116 |
+
"example": req["body"]
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
} if req["body"] else None
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
return {
|
| 123 |
+
"title": title,
|
| 124 |
+
"version": version,
|
| 125 |
+
"endpoints": simplified_endpoints,
|
| 126 |
+
"paths": paths,
|
| 127 |
+
"components": {}, # No global components in Postman
|
| 128 |
+
"raw_requests": all_requests # Keep extra detail just in case
|
| 129 |
+
}
|
backend/services/response_analyzer.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Dict, Any
|
| 3 |
+
from langchain_core.prompts import PromptTemplate
|
| 4 |
+
from langchain_mistralai.chat_models import ChatMistralAI
|
| 5 |
+
from langchain_core.output_parsers import JsonOutputParser
|
| 6 |
+
from backend.schemas import AnalyzeResponse
|
| 7 |
+
|
| 8 |
+
ANALYSIS_PROMPT = """
|
| 9 |
+
You are a response analyzer.
|
| 10 |
+
Analyze status {status_code} and body {response_body} for step {step_info}.
|
| 11 |
+
Extracted generalized variables for future steps.
|
| 12 |
+
Set 'is_otp_required':true if OTP/Verification is needed.
|
| 13 |
+
|
| 14 |
+
RETURN JSON ONLY:
|
| 15 |
+
{{
|
| 16 |
+
"step": 1, "status": "success", "is_otp_required": false, "otp_field_name": "otp",
|
| 17 |
+
"extracted_variables": {{}}
|
| 18 |
+
}}
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
def analyze_api_response(
|
| 22 |
+
step: int,
|
| 23 |
+
endpoint: str,
|
| 24 |
+
purpose: str,
|
| 25 |
+
status_code: int,
|
| 26 |
+
response_body: str
|
| 27 |
+
) -> AnalyzeResponse:
|
| 28 |
+
"""
|
| 29 |
+
Uses Mistral AI via LangChain to analyze an API response and extract dynamic variables.
|
| 30 |
+
"""
|
| 31 |
+
parser = JsonOutputParser(pydantic_object=AnalyzeResponse)
|
| 32 |
+
|
| 33 |
+
prompt = PromptTemplate(
|
| 34 |
+
template=ANALYSIS_PROMPT,
|
| 35 |
+
input_variables=["step_info", "status_code", "response_body"],
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
llm = ChatMistralAI(model_name="mistral-large-latest", temperature=0)
|
| 39 |
+
chain = prompt | llm | parser
|
| 40 |
+
|
| 41 |
+
# Aggressive truncation: keep only 500 chars from start and end (1KB total)
|
| 42 |
+
if len(response_body) > 1000:
|
| 43 |
+
response_body = response_body[:500] + "\n... [TRUNCATED] ...\n" + response_body[-500:]
|
| 44 |
+
|
| 45 |
+
msg = prompt.format_prompt(
|
| 46 |
+
step_info=f"Step {step}: {endpoint} - {purpose}",
|
| 47 |
+
status_code=str(status_code),
|
| 48 |
+
response_body=response_body
|
| 49 |
+
).to_messages()
|
| 50 |
+
|
| 51 |
+
ai_msg = llm.invoke(msg)
|
| 52 |
+
parsed_response = parser.parse(ai_msg.content)
|
| 53 |
+
|
| 54 |
+
# Extract token usage
|
| 55 |
+
usage = ai_msg.response_metadata.get("token_usage", {})
|
| 56 |
+
token_usage = None
|
| 57 |
+
if usage:
|
| 58 |
+
token_usage = {
|
| 59 |
+
"prompt_tokens": usage.get("prompt_tokens", 0),
|
| 60 |
+
"completion_tokens": usage.get("completion_tokens", 0),
|
| 61 |
+
"total_tokens": usage.get("total_tokens", 0)
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
# Ensure step matches the requested step and add token usage
|
| 65 |
+
parsed_response["step"] = step
|
| 66 |
+
parsed_response["token_usage"] = token_usage
|
| 67 |
+
|
| 68 |
+
return AnalyzeResponse(**parsed_response)
|
backend/services/storage.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
from abc import ABC, abstractmethod
|
| 4 |
+
from typing import BinaryIO
|
| 5 |
+
|
| 6 |
+
class StorageProvider(ABC):
|
| 7 |
+
@abstractmethod
|
| 8 |
+
def save(self, file_content: BinaryIO, path: str) -> str:
|
| 9 |
+
pass
|
| 10 |
+
|
| 11 |
+
@abstractmethod
|
| 12 |
+
def delete(self, path: str):
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
@abstractmethod
|
| 16 |
+
def get_full_path(self, path: str) -> str:
|
| 17 |
+
pass
|
| 18 |
+
|
| 19 |
+
class LocalStorageProvider(StorageProvider):
|
| 20 |
+
def __init__(self, base_dir: str = "backend/uploads"):
|
| 21 |
+
self.base_dir = base_dir
|
| 22 |
+
os.makedirs(self.base_dir, exist_ok=True)
|
| 23 |
+
|
| 24 |
+
def save(self, file_content: BinaryIO, relative_path: str) -> str:
|
| 25 |
+
full_path = os.path.join(self.base_dir, relative_path)
|
| 26 |
+
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
| 27 |
+
with open(full_path, "wb") as buffer:
|
| 28 |
+
shutil.copyfileobj(file_content, buffer)
|
| 29 |
+
return full_path
|
| 30 |
+
|
| 31 |
+
def delete(self, relative_path: str):
|
| 32 |
+
full_path = os.path.join(self.base_dir, relative_path)
|
| 33 |
+
if os.path.exists(full_path):
|
| 34 |
+
os.remove(full_path)
|
| 35 |
+
|
| 36 |
+
def get_full_path(self, relative_path: str) -> str:
|
| 37 |
+
return os.path.join(self.base_dir, relative_path)
|
backend/services/swagger_parser.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import yaml
|
| 3 |
+
from prance import ResolvingParser
|
| 4 |
+
from typing import Dict, Any
|
| 5 |
+
|
| 6 |
+
def parse_spec(spec_content: str) -> Dict[str, Any]:
|
| 7 |
+
"""
|
| 8 |
+
Parses a Swagger/OpenAPI spec (JSON or YAML string).
|
| 9 |
+
Returns the FULL resolved spec (all $refs inlined by prance) so that
|
| 10 |
+
the executor can look up exact request body schemas from `paths`.
|
| 11 |
+
"""
|
| 12 |
+
try:
|
| 13 |
+
spec_dict = json.loads(spec_content)
|
| 14 |
+
except json.JSONDecodeError:
|
| 15 |
+
try:
|
| 16 |
+
spec_dict = yaml.safe_load(spec_content)
|
| 17 |
+
except yaml.YAMLError as e:
|
| 18 |
+
raise ValueError(f"Failed to parse spec as JSON or YAML: {e}")
|
| 19 |
+
|
| 20 |
+
# prance resolves all $ref references inline — use the fully resolved spec
|
| 21 |
+
parser = ResolvingParser(spec_string=json.dumps(spec_dict), backend='openapi-spec-validator')
|
| 22 |
+
resolved_spec = parser.specification
|
| 23 |
+
|
| 24 |
+
# Build a simplified endpoint list for the planner LLM (no $refs remain since prance resolved them)
|
| 25 |
+
simplified_endpoints = []
|
| 26 |
+
paths = resolved_spec.get("paths", {})
|
| 27 |
+
for path, methods in paths.items():
|
| 28 |
+
for method, details in methods.items():
|
| 29 |
+
if method.lower() not in ["get", "post", "put", "delete", "patch"]:
|
| 30 |
+
continue
|
| 31 |
+
endpoint_info = {
|
| 32 |
+
"path": path,
|
| 33 |
+
"method": method.upper(),
|
| 34 |
+
"summary": details.get("summary", details.get("description", ""))[:100] # Cap summary length
|
| 35 |
+
}
|
| 36 |
+
simplified_endpoints.append(endpoint_info)
|
| 37 |
+
|
| 38 |
+
return {
|
| 39 |
+
# Full resolved spec — used by executor to look up exact endpoint schemas
|
| 40 |
+
"paths": paths,
|
| 41 |
+
"components": resolved_spec.get("components", {}),
|
| 42 |
+
# Metadata
|
| 43 |
+
"title": resolved_spec.get("info", {}).get("title", "API Spec"),
|
| 44 |
+
"version": resolved_spec.get("info", {}).get("version", "1.0"),
|
| 45 |
+
# Simplified list — used by planner LLM
|
| 46 |
+
"endpoints": simplified_endpoints
|
| 47 |
+
}
|
backend/uploads/documents/a1f57578-141b-4520-963b-c1023c93bfa6.png
ADDED
|
Git LFS Details
|
backend/uploads/documents/be351df0-6bd3-46dc-b154-805f9ec8d127.jpg
ADDED
|
Git LFS Details
|
backend/uploads/documents/dd08cd23-5485-4ab7-8c05-8ee9d9e345da.jpg
ADDED
|
Git LFS Details
|
frontend-react/.env.production
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
VITE_BACKEND_URL=https://your-backend-app-name.onrender.com
|
frontend-react/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
dist
|
| 12 |
+
dist-ssr
|
| 13 |
+
*.local
|
| 14 |
+
|
| 15 |
+
# Editor directories and files
|
| 16 |
+
.vscode/*
|
| 17 |
+
!.vscode/extensions.json
|
| 18 |
+
.idea
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.suo
|
| 21 |
+
*.ntvs*
|
| 22 |
+
*.njsproj
|
| 23 |
+
*.sln
|
| 24 |
+
*.sw?
|
frontend-react/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# React + Vite
|
| 2 |
+
|
| 3 |
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
| 4 |
+
|
| 5 |
+
Currently, two official plugins are available:
|
| 6 |
+
|
| 7 |
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
| 8 |
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
| 9 |
+
|
| 10 |
+
## React Compiler
|
| 11 |
+
|
| 12 |
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
| 13 |
+
|
| 14 |
+
## Expanding the ESLint configuration
|
| 15 |
+
|
| 16 |
+
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
frontend-react/eslint.config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import js from '@eslint/js'
|
| 2 |
+
import globals from 'globals'
|
| 3 |
+
import reactHooks from 'eslint-plugin-react-hooks'
|
| 4 |
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
| 5 |
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
| 6 |
+
|
| 7 |
+
export default defineConfig([
|
| 8 |
+
globalIgnores(['dist']),
|
| 9 |
+
{
|
| 10 |
+
files: ['**/*.{js,jsx}'],
|
| 11 |
+
extends: [
|
| 12 |
+
js.configs.recommended,
|
| 13 |
+
reactHooks.configs.flat.recommended,
|
| 14 |
+
reactRefresh.configs.vite,
|
| 15 |
+
],
|
| 16 |
+
languageOptions: {
|
| 17 |
+
ecmaVersion: 2020,
|
| 18 |
+
globals: globals.browser,
|
| 19 |
+
parserOptions: {
|
| 20 |
+
ecmaVersion: 'latest',
|
| 21 |
+
ecmaFeatures: { jsx: true },
|
| 22 |
+
sourceType: 'module',
|
| 23 |
+
},
|
| 24 |
+
},
|
| 25 |
+
rules: {
|
| 26 |
+
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
| 27 |
+
},
|
| 28 |
+
},
|
| 29 |
+
])
|
frontend-react/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>frontend-react</title>
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div id="root"></div>
|
| 11 |
+
<script type="module" src="/src/main.jsx"></script>
|
| 12 |
+
</body>
|
| 13 |
+
</html>
|
frontend-react/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend-react/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "frontend-react",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "0.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "vite build",
|
| 9 |
+
"lint": "eslint .",
|
| 10 |
+
"preview": "vite preview"
|
| 11 |
+
},
|
| 12 |
+
"dependencies": {
|
| 13 |
+
"@tailwindcss/postcss": "^4.2.1",
|
| 14 |
+
"@tailwindcss/vite": "^4.2.1",
|
| 15 |
+
"axios": "^1.13.6",
|
| 16 |
+
"lucide-react": "^0.577.0",
|
| 17 |
+
"react": "^19.2.4",
|
| 18 |
+
"react-dom": "^19.2.4",
|
| 19 |
+
"react-router-dom": "^7.13.1"
|
| 20 |
+
},
|
| 21 |
+
"devDependencies": {
|
| 22 |
+
"@eslint/js": "^9.39.4",
|
| 23 |
+
"@types/react": "^19.2.14",
|
| 24 |
+
"@types/react-dom": "^19.2.3",
|
| 25 |
+
"@vitejs/plugin-react": "^6.0.0",
|
| 26 |
+
"eslint": "^9.39.4",
|
| 27 |
+
"eslint-plugin-react-hooks": "^7.0.1",
|
| 28 |
+
"eslint-plugin-react-refresh": "^0.5.2",
|
| 29 |
+
"globals": "^17.4.0",
|
| 30 |
+
"vite": "^8.0.0"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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.counter {
|
| 2 |
+
font-size: 16px;
|
| 3 |
+
padding: 5px 10px;
|
| 4 |
+
border-radius: 5px;
|
| 5 |
+
color: var(--accent);
|
| 6 |
+
background: var(--accent-bg);
|
| 7 |
+
border: 2px solid transparent;
|
| 8 |
+
transition: border-color 0.3s;
|
| 9 |
+
margin-bottom: 24px;
|
| 10 |
+
|
| 11 |
+
&:hover {
|
| 12 |
+
border-color: var(--accent-border);
|
| 13 |
+
}
|
| 14 |
+
&:focus-visible {
|
| 15 |
+
outline: 2px solid var(--accent);
|
| 16 |
+
outline-offset: 2px;
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.hero {
|
| 21 |
+
position: relative;
|
| 22 |
+
|
| 23 |
+
.base,
|
| 24 |
+
.framework,
|
| 25 |
+
.vite {
|
| 26 |
+
inset-inline: 0;
|
| 27 |
+
margin: 0 auto;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.base {
|
| 31 |
+
width: 170px;
|
| 32 |
+
position: relative;
|
| 33 |
+
z-index: 0;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.framework,
|
| 37 |
+
.vite {
|
| 38 |
+
position: absolute;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.framework {
|
| 42 |
+
z-index: 1;
|
| 43 |
+
top: 34px;
|
| 44 |
+
height: 28px;
|
| 45 |
+
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
|
| 46 |
+
scale(1.4);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.vite {
|
| 50 |
+
z-index: 0;
|
| 51 |
+
top: 107px;
|
| 52 |
+
height: 26px;
|
| 53 |
+
width: auto;
|
| 54 |
+
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
|
| 55 |
+
scale(0.8);
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
#center {
|
| 60 |
+
display: flex;
|
| 61 |
+
flex-direction: column;
|
| 62 |
+
gap: 25px;
|
| 63 |
+
place-content: center;
|
| 64 |
+
place-items: center;
|
| 65 |
+
flex-grow: 1;
|
| 66 |
+
|
| 67 |
+
@media (max-width: 1024px) {
|
| 68 |
+
padding: 32px 20px 24px;
|
| 69 |
+
gap: 18px;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
#next-steps {
|
| 74 |
+
display: flex;
|
| 75 |
+
border-top: 1px solid var(--border);
|
| 76 |
+
text-align: left;
|
| 77 |
+
|
| 78 |
+
& > div {
|
| 79 |
+
flex: 1 1 0;
|
| 80 |
+
padding: 32px;
|
| 81 |
+
@media (max-width: 1024px) {
|
| 82 |
+
padding: 24px 20px;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.icon {
|
| 87 |
+
margin-bottom: 16px;
|
| 88 |
+
width: 22px;
|
| 89 |
+
height: 22px;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
@media (max-width: 1024px) {
|
| 93 |
+
flex-direction: column;
|
| 94 |
+
text-align: center;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
#docs {
|
| 99 |
+
border-right: 1px solid var(--border);
|
| 100 |
+
|
| 101 |
+
@media (max-width: 1024px) {
|
| 102 |
+
border-right: none;
|
| 103 |
+
border-bottom: 1px solid var(--border);
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
#next-steps ul {
|
| 108 |
+
list-style: none;
|
| 109 |
+
padding: 0;
|
| 110 |
+
display: flex;
|
| 111 |
+
gap: 8px;
|
| 112 |
+
margin: 32px 0 0;
|
| 113 |
+
|
| 114 |
+
.logo {
|
| 115 |
+
height: 18px;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
a {
|
| 119 |
+
color: var(--text-h);
|
| 120 |
+
font-size: 16px;
|
| 121 |
+
border-radius: 6px;
|
| 122 |
+
background: var(--social-bg);
|
| 123 |
+
display: flex;
|
| 124 |
+
padding: 6px 12px;
|
| 125 |
+
align-items: center;
|
| 126 |
+
gap: 8px;
|
| 127 |
+
text-decoration: none;
|
| 128 |
+
transition: box-shadow 0.3s;
|
| 129 |
+
|
| 130 |
+
&:hover {
|
| 131 |
+
box-shadow: var(--shadow);
|
| 132 |
+
}
|
| 133 |
+
.button-icon {
|
| 134 |
+
height: 18px;
|
| 135 |
+
width: 18px;
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
@media (max-width: 1024px) {
|
| 140 |
+
margin-top: 20px;
|
| 141 |
+
flex-wrap: wrap;
|
| 142 |
+
justify-content: center;
|
| 143 |
+
|
| 144 |
+
li {
|
| 145 |
+
flex: 1 1 calc(50% - 8px);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
a {
|
| 149 |
+
width: 100%;
|
| 150 |
+
justify-content: center;
|
| 151 |
+
box-sizing: border-box;
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
#spacer {
|
| 157 |
+
height: 88px;
|
| 158 |
+
border-top: 1px solid var(--border);
|
| 159 |
+
@media (max-width: 1024px) {
|
| 160 |
+
height: 48px;
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
.ticks {
|
| 165 |
+
position: relative;
|
| 166 |
+
width: 100%;
|
| 167 |
+
|
| 168 |
+
&::before,
|
| 169 |
+
&::after {
|
| 170 |
+
content: '';
|
| 171 |
+
position: absolute;
|
| 172 |
+
top: -4.5px;
|
| 173 |
+
border: 5px solid transparent;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
&::before {
|
| 177 |
+
left: 0;
|
| 178 |
+
border-left-color: var(--border);
|
| 179 |
+
}
|
| 180 |
+
&::after {
|
| 181 |
+
right: 0;
|
| 182 |
+
border-right-color: var(--border);
|
| 183 |
+
}
|
| 184 |
+
}
|
frontend-react/src/App.jsx
ADDED
|
@@ -0,0 +1,575 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useRef } from 'react';
|
| 2 |
+
import { MessageSquare, LayoutTemplate, Settings, Database, History, ChevronRight, ChevronLeft, Send, Zap, Trash2, RefreshCw, Upload, Image, FileText, Music, Video, Filter } from 'lucide-react';
|
| 3 |
+
import { AppProvider, useAppContext } from './components/AppContext';
|
| 4 |
+
import CollectionsPage from './components/CollectionsPage';
|
| 5 |
+
import ProfilePage from './components/ProfilePage';
|
| 6 |
+
import HistoryPage from './components/HistoryPage';
|
| 7 |
+
import MediaHubPage from './components/MediaHubPage';
|
| 8 |
+
import { SpecService, SessionService, PlanService, CredentialService, AssetService } from './services/api';
|
| 9 |
+
|
| 10 |
+
function MainApp() {
|
| 11 |
+
const {
|
| 12 |
+
collections, loadSpec, deleteSpec,
|
| 13 |
+
activeSpecId, activeSpecName, activeBaseUrl, setActiveBaseUrl,
|
| 14 |
+
isLoading, fetchCollections,
|
| 15 |
+
storedCredentials, setStoredCredentials, saveProfile, parsedSpec,
|
| 16 |
+
sessionContextVars, refreshSessionContext, sessionId,
|
| 17 |
+
executionPlan, setExecutionPlan,
|
| 18 |
+
scenario, setScenario,
|
| 19 |
+
startNewSession
|
| 20 |
+
} = useAppContext();
|
| 21 |
+
|
| 22 |
+
const [activePage, setActivePage] = useState('testing'); // 'testing', 'collections', 'profile', 'history', 'media'
|
| 23 |
+
const [rightPanelOpen, setRightPanelOpen] = useState(true);
|
| 24 |
+
|
| 25 |
+
// Global Navigation Listener
|
| 26 |
+
React.useEffect(() => {
|
| 27 |
+
const handleNav = (e) => setActivePage(e.detail);
|
| 28 |
+
window.addEventListener('nav-change', handleNav);
|
| 29 |
+
return () => window.removeEventListener('nav-change', handleNav);
|
| 30 |
+
}, []);
|
| 31 |
+
|
| 32 |
+
const fileInputRef = useRef(null);
|
| 33 |
+
const [isUploading, setIsUploading] = useState(false);
|
| 34 |
+
|
| 35 |
+
// Chat/Execution State
|
| 36 |
+
// scenario input is handled by AppContext now
|
| 37 |
+
const [isPlanning, setIsPlanning] = useState(false);
|
| 38 |
+
const [executingStep, setExecutingStep] = useState(null);
|
| 39 |
+
const [stepResults, setStepResults] = useState({});
|
| 40 |
+
const [otpPrompt, setOtpPrompt] = useState(null); // { stepDef, otpFieldName }
|
| 41 |
+
const [otpInput, setOtpInput] = useState('');
|
| 42 |
+
|
| 43 |
+
// Media Hub / Assets State
|
| 44 |
+
const [assets, setAssets] = useState([]);
|
| 45 |
+
const [isAssetLoading, setIsAssetLoading] = useState(false);
|
| 46 |
+
const [activeAssetCategory, setActiveAssetCategory] = useState('all'); // all, audio, video, documents
|
| 47 |
+
const assetFileInputRef = useRef(null);
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
const [planTokenUsage, setPlanTokenUsage] = useState(null);
|
| 51 |
+
const [totalScenarioTokens, setTotalScenarioTokens] = useState({ prompt: 0, completion: 0, total: 0 });
|
| 52 |
+
|
| 53 |
+
const handleGeneratePlan = async () => {
|
| 54 |
+
if (!activeSpecId) return alert("Please select a collection first.");
|
| 55 |
+
if (!activeBaseUrl) return alert("Please set a Base URL for this collection.");
|
| 56 |
+
if (!scenario.trim()) return alert("Please describe a test scenario.");
|
| 57 |
+
|
| 58 |
+
setIsPlanning(true);
|
| 59 |
+
setPlanTokenUsage(null); // Reset
|
| 60 |
+
setStepResults({}); // Clear old results
|
| 61 |
+
setTotalScenarioTokens({ prompt: 0, completion: 0, total: 0 }); // Reset tokens
|
| 62 |
+
|
| 63 |
+
try {
|
| 64 |
+
// START A FRESH SESSION for this plan
|
| 65 |
+
const newSid = await startNewSession();
|
| 66 |
+
if (!newSid) throw new Error("Could not initialize fresh session");
|
| 67 |
+
|
| 68 |
+
const payload = {
|
| 69 |
+
spec_content: typeof parsedSpec === 'string' ? parsedSpec : JSON.stringify(parsedSpec),
|
| 70 |
+
base_url: activeBaseUrl,
|
| 71 |
+
scenario: scenario,
|
| 72 |
+
user_credentials: storedCredentials,
|
| 73 |
+
spec_id: activeSpecId,
|
| 74 |
+
session_id: newSid
|
| 75 |
+
};
|
| 76 |
+
const data = await PlanService.generatePlan(payload);
|
| 77 |
+
setExecutionPlan(data.execution_plan || []);
|
| 78 |
+
setPlanTokenUsage(data.token_usage);
|
| 79 |
+
|
| 80 |
+
// NEW: Merge suggested credentials to the UI/Context
|
| 81 |
+
if (data.suggested_credentials && Object.keys(data.suggested_credentials).length > 0) {
|
| 82 |
+
setStoredCredentials(prev => ({ ...prev, ...data.suggested_credentials }));
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// Initialize scenario total with plan generation tokens
|
| 86 |
+
if (data.token_usage) {
|
| 87 |
+
setTotalScenarioTokens({
|
| 88 |
+
prompt: data.token_usage.prompt_tokens,
|
| 89 |
+
completion: data.token_usage.completion_tokens,
|
| 90 |
+
total: data.token_usage.total_tokens
|
| 91 |
+
});
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// We no longer clear scenario on success so it stays visible
|
| 95 |
+
setStepResults({}); // clear old results
|
| 96 |
+
} catch (err) {
|
| 97 |
+
console.error("Failed to generate plan", err);
|
| 98 |
+
alert("Plan generation failed. See console.");
|
| 99 |
+
} finally {
|
| 100 |
+
setIsPlanning(false);
|
| 101 |
+
}
|
| 102 |
+
};
|
| 103 |
+
|
| 104 |
+
const executeStep = async (stepDef) => {
|
| 105 |
+
setExecutingStep(stepDef.step);
|
| 106 |
+
|
| 107 |
+
try {
|
| 108 |
+
if (!sessionId) {
|
| 109 |
+
alert("Session not initialized. Please refresh the page.");
|
| 110 |
+
return;
|
| 111 |
+
}
|
| 112 |
+
if (!activeBaseUrl) {
|
| 113 |
+
alert("Base URL is missing. Please set it in the header.");
|
| 114 |
+
return;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
await refreshSessionContext();
|
| 118 |
+
|
| 119 |
+
const payload = {
|
| 120 |
+
session_id: sessionId,
|
| 121 |
+
step_definition: stepDef,
|
| 122 |
+
context_variables: sessionContextVars || {},
|
| 123 |
+
user_credentials: storedCredentials || {},
|
| 124 |
+
base_url: activeBaseUrl,
|
| 125 |
+
spec_id: activeSpecId
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
console.log("Executing Step Payload:", payload);
|
| 129 |
+
|
| 130 |
+
const execData = await PlanService.executeStep(payload);
|
| 131 |
+
|
| 132 |
+
const analyzePayload = {
|
| 133 |
+
session_id: sessionId,
|
| 134 |
+
step: stepDef.step,
|
| 135 |
+
response_data: execData.response,
|
| 136 |
+
step_definition: stepDef
|
| 137 |
+
};
|
| 138 |
+
const analyzeData = await PlanService.analyzeResponse(analyzePayload);
|
| 139 |
+
|
| 140 |
+
// Calculate cumulative tokens for this specific step (Prep + Analysis)
|
| 141 |
+
const stepTokens = {
|
| 142 |
+
prompt_tokens: (execData.token_usage?.prompt_tokens || 0) + (analyzeData.token_usage?.prompt_tokens || 0),
|
| 143 |
+
completion_tokens: (execData.token_usage?.completion_tokens || 0) + (analyzeData.token_usage?.completion_tokens || 0),
|
| 144 |
+
total_tokens: (execData.token_usage?.total_tokens || 0) + (analyzeData.token_usage?.total_tokens || 0)
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
setStepResults(prev => ({
|
| 148 |
+
...prev,
|
| 149 |
+
[stepDef.step]: {
|
| 150 |
+
request: execData.executed_request,
|
| 151 |
+
response: execData.response,
|
| 152 |
+
analysis: analyzeData,
|
| 153 |
+
token_usage: stepTokens
|
| 154 |
+
}
|
| 155 |
+
}));
|
| 156 |
+
|
| 157 |
+
// Update cumulative scenario total
|
| 158 |
+
setTotalScenarioTokens(prev => ({
|
| 159 |
+
prompt: prev.prompt + stepTokens.prompt_tokens,
|
| 160 |
+
completion: prev.completion + stepTokens.completion_tokens,
|
| 161 |
+
total: prev.total + stepTokens.total_tokens
|
| 162 |
+
}));
|
| 163 |
+
|
| 164 |
+
await refreshSessionContext();
|
| 165 |
+
|
| 166 |
+
// Handle OTP requirement
|
| 167 |
+
if (analyzeData.is_otp_required) {
|
| 168 |
+
setOtpPrompt({ stepDef, otpFieldName: analyzeData.otp_field_name || 'otp' });
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
} catch (err) {
|
| 172 |
+
console.error(`Execution failed for step ${stepDef.step}`, err);
|
| 173 |
+
} finally {
|
| 174 |
+
setExecutingStep(null);
|
| 175 |
+
}
|
| 176 |
+
};
|
| 177 |
+
|
| 178 |
+
const handleOtpSubmit = async () => {
|
| 179 |
+
if (!otpInput.trim()) return;
|
| 180 |
+
const { stepDef, otpFieldName } = otpPrompt;
|
| 181 |
+
|
| 182 |
+
try {
|
| 183 |
+
// Save OTP to Extra Fields
|
| 184 |
+
const payload = {
|
| 185 |
+
extra: { [otpFieldName]: otpInput }
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
// Use saveProfile from context to update both DB and local state
|
| 189 |
+
await saveProfile(payload);
|
| 190 |
+
|
| 191 |
+
// Clear OTP state
|
| 192 |
+
setOtpPrompt(null);
|
| 193 |
+
setOtpInput('');
|
| 194 |
+
|
| 195 |
+
// Refresh context (though saveProfile already updated local storedCredentials)
|
| 196 |
+
await refreshSessionContext();
|
| 197 |
+
alert(`OTP "${otpInput}" saved to profile as "${otpFieldName}". You can now proceed.`);
|
| 198 |
+
} catch (err) {
|
| 199 |
+
console.error("Failed to save OTP", err);
|
| 200 |
+
alert("Failed to save OTP. See console.");
|
| 201 |
+
}
|
| 202 |
+
};
|
| 203 |
+
|
| 204 |
+
return (
|
| 205 |
+
<div className="flex h-screen w-full bg-[#1e1e1e] text-[#cccccc] font-sans selection:bg-[#264f78] overflow-hidden">
|
| 206 |
+
|
| 207 |
+
{/* 1. LEFT SIDEBAR (Activity Bar) */}
|
| 208 |
+
<div className="flex flex-shrink-0 border-r border-[#333333] h-full">
|
| 209 |
+
{/* Activity Bar */}
|
| 210 |
+
<div className="w-12 bg-[#333333] flex flex-col items-center py-4 space-y-6">
|
| 211 |
+
<button
|
| 212 |
+
onClick={() => setActivePage('collections')}
|
| 213 |
+
className={`p-2 rounded-lg transition-colors duration-200 ${activePage === 'collections' ? 'text-white' : 'text-zinc-500 hover:text-white'}`}
|
| 214 |
+
title="Collections / Specs"
|
| 215 |
+
>
|
| 216 |
+
<Database size={24} strokeWidth={1.5} />
|
| 217 |
+
</button>
|
| 218 |
+
|
| 219 |
+
<button
|
| 220 |
+
onClick={() => setActivePage('testing')}
|
| 221 |
+
className={`p-2 rounded-lg transition-colors duration-200 ${activePage === 'testing' ? 'text-white' : 'text-zinc-500 hover:text-white'}`}
|
| 222 |
+
title="Execution Workflow"
|
| 223 |
+
>
|
| 224 |
+
<Zap size={24} strokeWidth={1.5} />
|
| 225 |
+
</button>
|
| 226 |
+
|
| 227 |
+
<button
|
| 228 |
+
onClick={() => setActivePage('profile')}
|
| 229 |
+
className={`p-2 rounded-lg transition-colors duration-200 ${activePage === 'profile' ? 'text-white' : 'text-zinc-500 hover:text-white'}`}
|
| 230 |
+
title="Test User Profile"
|
| 231 |
+
>
|
| 232 |
+
<Settings size={24} strokeWidth={1.5} />
|
| 233 |
+
</button>
|
| 234 |
+
|
| 235 |
+
<button
|
| 236 |
+
onClick={() => setActivePage('history')}
|
| 237 |
+
className={`p-2 rounded-lg transition-colors duration-200 ${activePage === 'history' ? 'text-white' : 'text-zinc-500 hover:text-white'}`}
|
| 238 |
+
title="Execution History"
|
| 239 |
+
>
|
| 240 |
+
<History size={24} strokeWidth={1.5} />
|
| 241 |
+
</button>
|
| 242 |
+
|
| 243 |
+
<button
|
| 244 |
+
onClick={() => setActivePage('media')}
|
| 245 |
+
className={`p-2 rounded-lg transition-colors duration-200 ${activePage === 'media' ? 'text-white' : 'text-zinc-500 hover:text-white'}`}
|
| 246 |
+
title="Media Hub (Docs/Audio/Video)"
|
| 247 |
+
>
|
| 248 |
+
<Image size={24} strokeWidth={1.5} />
|
| 249 |
+
</button>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
|
| 253 |
+
<div className="flex-1 flex flex-col bg-[#1e1e1e] min-w-0 min-h-0 relative">
|
| 254 |
+
|
| 255 |
+
{activePage === 'testing' && (
|
| 256 |
+
<div className="flex-1 flex flex-col overflow-hidden animate-in fade-in duration-300">
|
| 257 |
+
{/* Header / Tabs */}
|
| 258 |
+
<div className="h-10 flex items-center justify-between border-b border-[#333333] bg-[#2d2d2d] px-4">
|
| 259 |
+
<div className="flex items-center space-x-2 italic text-sm text-white">
|
| 260 |
+
<LayoutTemplate size={14} className="text-[#519aba]" />
|
| 261 |
+
<span>{activeSpecName !== 'None' ? activeSpecName : 'workflow.plan'}</span>
|
| 262 |
+
{planTokenUsage && (
|
| 263 |
+
<span className="ml-4 text-[10px] text-zinc-500 font-mono bg-[#1e1e1e] px-2 py-0.5 rounded border border-[#333333]">
|
| 264 |
+
LLM Plan: <span className="text-[#9cdcfe]">{planTokenUsage.total_tokens}</span>
|
| 265 |
+
</span>
|
| 266 |
+
)}
|
| 267 |
+
{totalScenarioTokens.total > 0 && (
|
| 268 |
+
<span className="ml-2 text-[10px] text-zinc-500 font-mono bg-[#1e1e1e] px-2 py-0.5 rounded border border-emerald-500/30">
|
| 269 |
+
Scenario Total: <span className="text-emerald-400">{totalScenarioTokens.total}</span> tokens
|
| 270 |
+
</span>
|
| 271 |
+
)}
|
| 272 |
+
</div>
|
| 273 |
+
{/* Base URL Input in Header */}
|
| 274 |
+
{activeSpecId && (
|
| 275 |
+
<div className="flex items-center space-x-2 text-xs">
|
| 276 |
+
<span className="text-zinc-500 font-mono">BASE_URL:</span>
|
| 277 |
+
<input
|
| 278 |
+
type="text"
|
| 279 |
+
className="bg-[#1e1e1e] border border-[#3c3c3c] text-white px-2 py-1 outline-none focus:border-[#0e639c] w-64 rounded-sm font-mono"
|
| 280 |
+
value={activeBaseUrl || ""}
|
| 281 |
+
onChange={(e) => setActiveBaseUrl(e.target.value)}
|
| 282 |
+
onBlur={async () => {
|
| 283 |
+
if (activeBaseUrl) {
|
| 284 |
+
try { await SpecService.updateBaseUrl(activeSpecId, activeBaseUrl); }
|
| 285 |
+
catch(e) { console.error("URL Save failed", e); }
|
| 286 |
+
}
|
| 287 |
+
}}
|
| 288 |
+
placeholder="https://api.example.com"
|
| 289 |
+
/>
|
| 290 |
+
</div>
|
| 291 |
+
)}
|
| 292 |
+
</div>
|
| 293 |
+
|
| 294 |
+
{/* Workflow Feed Area */}
|
| 295 |
+
<div className="flex-1 overflow-y-auto p-6 space-y-6">
|
| 296 |
+
<div className="max-w-4xl mx-auto space-y-4">
|
| 297 |
+
{!executionPlan ? (
|
| 298 |
+
<div className="flex flex-col items-center justify-center py-20 text-center opacity-70">
|
| 299 |
+
<Zap size={64} className="text-[#0e639c] mb-6 opacity-30" />
|
| 300 |
+
<h1 className="text-2xl font-light text-zinc-300">AI API Testing Assistant</h1>
|
| 301 |
+
<p className="mt-2 text-zinc-500 max-w-lg">
|
| 302 |
+
{activeSpecId ? "Specify a test scenario below to generate an API execution workflow." : "Load a collection from the sidebar to begin."}
|
| 303 |
+
</p>
|
| 304 |
+
</div>
|
| 305 |
+
) : (
|
| 306 |
+
<div className="space-y-4">
|
| 307 |
+
{executionPlan.map((step) => {
|
| 308 |
+
const isRunning = executingStep === step.step;
|
| 309 |
+
const res = stepResults[step.step];
|
| 310 |
+
return (
|
| 311 |
+
<div key={step.step} className="bg-[#252526] border border-[#333333] rounded-lg overflow-hidden shadow-sm">
|
| 312 |
+
<div className="p-4 flex items-center justify-between bg-[#2d2d2d] border-b border-[#333333]">
|
| 313 |
+
<div>
|
| 314 |
+
<div className="flex items-center space-x-2">
|
| 315 |
+
<span className="bg-[#333333] text-zinc-300 text-xs px-2 py-0.5 rounded font-mono">Step {step.step}</span>
|
| 316 |
+
<span className="text-sm font-medium text-white">{step.endpoint}</span>
|
| 317 |
+
</div>
|
| 318 |
+
<p className="text-xs text-zinc-400 mt-1">{step.purpose}</p>
|
| 319 |
+
</div>
|
| 320 |
+
<button
|
| 321 |
+
onClick={() => executeStep(step)}
|
| 322 |
+
disabled={isRunning}
|
| 323 |
+
className="bg-[#0e639c] hover:bg-[#1177bb] disabled:opacity-50 text-white px-4 py-1.5 text-xs rounded transition flex items-center space-x-2"
|
| 324 |
+
>
|
| 325 |
+
{isRunning ? <RefreshCw size={14} className="animate-spin" /> : <Zap size={14} />}
|
| 326 |
+
<span>{isRunning ? 'Executing...' : 'Execute'}</span>
|
| 327 |
+
</button>
|
| 328 |
+
</div>
|
| 329 |
+
|
| 330 |
+
{/* Results Dropdown Area */}
|
| 331 |
+
{res && (
|
| 332 |
+
<div className="p-4 space-y-4 bg-[#1e1e1e] text-xs font-mono">
|
| 333 |
+
{/* Analysis */}
|
| 334 |
+
<div className={`p-3 text-white border-l-4 ${res.analysis.status === 'success' ? 'border-green-500 bg-green-500/10' : 'border-red-500 bg-red-500/10'}`}>
|
| 335 |
+
<div className="flex items-center justify-between mb-1">
|
| 336 |
+
<div className="font-semibold">AI Analysis</div>
|
| 337 |
+
{res.token_usage && (
|
| 338 |
+
<div className="text-[10px] text-zinc-400 font-mono">
|
| 339 |
+
{res.token_usage.total_tokens} tokens (P:{res.token_usage.prompt_tokens} / C:{res.token_usage.completion_tokens})
|
| 340 |
+
</div>
|
| 341 |
+
)}
|
| 342 |
+
</div>
|
| 343 |
+
<div className="text-zinc-300">{res.analysis.response_summary || (res.analysis.status === 'success' ? 'Step completed successfully.' : 'Step encountered an error.')}</div>
|
| 344 |
+
{res.analysis.extracted_variables && Object.keys(res.analysis.extracted_variables).length > 0 && (
|
| 345 |
+
<div className="mt-2 text-[#9cdcfe]">Extracted: {JSON.stringify(res.analysis.extracted_variables)}</div>
|
| 346 |
+
)}
|
| 347 |
+
</div>
|
| 348 |
+
|
| 349 |
+
<div className="grid grid-cols-2 gap-4">
|
| 350 |
+
{/* Request Container */}
|
| 351 |
+
<div className="space-y-2">
|
| 352 |
+
<div className="text-zinc-500 font-semibold">Request</div>
|
| 353 |
+
<div className="bg-[#2d2d2d] p-3 rounded text-zinc-300 overflow-x-auto space-y-3">
|
| 354 |
+
<div className="text-[#569cd6] font-bold">{res.request.method} <span className="text-[#ce9178] font-normal">{res.request.url}</span></div>
|
| 355 |
+
|
| 356 |
+
{res.request.headers && Object.keys(res.request.headers).length > 0 && (
|
| 357 |
+
<div className="space-y-1">
|
| 358 |
+
<div className="text-[10px] text-zinc-500 uppercase font-bold">Headers</div>
|
| 359 |
+
{Object.entries(res.request.headers).map(([k,v]) => (
|
| 360 |
+
<div key={k} className="text-[#9cdcfe]"><span className="text-zinc-400">{k}:</span> {v}</div>
|
| 361 |
+
))}
|
| 362 |
+
</div>
|
| 363 |
+
)}
|
| 364 |
+
|
| 365 |
+
{res.request.query_params && Object.keys(res.request.query_params).length > 0 && (
|
| 366 |
+
<div className="space-y-1">
|
| 367 |
+
<div className="text-[10px] text-zinc-500 uppercase font-bold">Query Params</div>
|
| 368 |
+
{Object.entries(res.request.query_params).map(([k,v]) => (
|
| 369 |
+
<div key={k} className="text-[#9cdcfe]"><span className="text-zinc-400">{k}=</span>{v}</div>
|
| 370 |
+
))}
|
| 371 |
+
</div>
|
| 372 |
+
)}
|
| 373 |
+
|
| 374 |
+
{res.request.body && <div className="space-y-1">
|
| 375 |
+
<div className="text-[10px] text-zinc-500 uppercase font-bold">Body</div>
|
| 376 |
+
<pre className="text-[#9cdcfe]">{JSON.stringify(res.request.body, null, 2)}</pre>
|
| 377 |
+
</div>}
|
| 378 |
+
|
| 379 |
+
{res.request.form_data && Object.keys(res.request.form_data).length > 0 && (
|
| 380 |
+
<div className="space-y-1">
|
| 381 |
+
<div className="text-[10px] text-zinc-500 uppercase font-bold">Form Data</div>
|
| 382 |
+
<pre className="text-[#9cdcfe]">{JSON.stringify(res.request.form_data, null, 2)}</pre>
|
| 383 |
+
</div>
|
| 384 |
+
)}
|
| 385 |
+
|
| 386 |
+
{res.request.files && Object.keys(res.request.files).length > 0 && (
|
| 387 |
+
<div className="space-y-1">
|
| 388 |
+
<div className="text-[10px] text-zinc-500 uppercase font-bold">Files</div>
|
| 389 |
+
{Object.entries(res.request.files).map(([k,v]) => (
|
| 390 |
+
<div key={k} className="text-[#ce9178]"><span className="text-zinc-400">{k}:</span> {v}</div>
|
| 391 |
+
))}
|
| 392 |
+
</div>
|
| 393 |
+
)}
|
| 394 |
+
</div>
|
| 395 |
+
</div>
|
| 396 |
+
{/* Response Container */}
|
| 397 |
+
<div className="space-y-2">
|
| 398 |
+
<div className="text-zinc-500 font-semibold">Response ({res.response.status_code})</div>
|
| 399 |
+
<div className="bg-[#2d2d2d] p-3 rounded text-zinc-300 overflow-x-auto max-h-64">
|
| 400 |
+
<pre className="text-[#ce9178]">
|
| 401 |
+
{(() => {
|
| 402 |
+
try { return JSON.stringify(JSON.parse(res.response.body), null, 2); }
|
| 403 |
+
catch { return res.response.body; }
|
| 404 |
+
})()}
|
| 405 |
+
</pre>
|
| 406 |
+
</div>
|
| 407 |
+
</div>
|
| 408 |
+
</div>
|
| 409 |
+
</div>
|
| 410 |
+
)}
|
| 411 |
+
</div>
|
| 412 |
+
);
|
| 413 |
+
})}
|
| 414 |
+
</div>
|
| 415 |
+
)}
|
| 416 |
+
|
| 417 |
+
{/* OTP PROMPT MODAL/OVERLAY */}
|
| 418 |
+
{otpPrompt && (
|
| 419 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
|
| 420 |
+
<div className="bg-[#252526] border border-[#333333] rounded-lg shadow-2xl w-full max-w-md overflow-hidden animate-in fade-in zoom-in duration-200">
|
| 421 |
+
<div className="p-4 border-b border-[#333333] bg-[#2d2d2d] flex items-center justify-between">
|
| 422 |
+
<h3 className="text-sm font-semibold text-white flex items-center space-x-2">
|
| 423 |
+
<Zap size={16} className="text-[#0e639c]" />
|
| 424 |
+
<span>OTP Required</span>
|
| 425 |
+
</h3>
|
| 426 |
+
<button onClick={() => setOtpPrompt(null)} className="text-zinc-500 hover:text-white transition">
|
| 427 |
+
<Trash2 size={16} />
|
| 428 |
+
</button>
|
| 429 |
+
</div>
|
| 430 |
+
<div className="p-6 space-y-4">
|
| 431 |
+
<p className="text-xs text-zinc-400">
|
| 432 |
+
The API response indicates that an OTP or verification code is required.
|
| 433 |
+
Please enter it below to save it to your session context.
|
| 434 |
+
</p>
|
| 435 |
+
<div className="space-y-2">
|
| 436 |
+
<label className="text-[10px] text-zinc-500 font-bold uppercase tracking-wider">
|
| 437 |
+
Field Name: <span className="text-[#9cdcfe] font-mono lowercase">{otpPrompt.otpFieldName}</span>
|
| 438 |
+
</label>
|
| 439 |
+
<input
|
| 440 |
+
type="text"
|
| 441 |
+
autoFocus
|
| 442 |
+
placeholder="Enter Code..."
|
| 443 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white p-3 text-sm rounded outline-none focus:border-[#0e639c] font-mono"
|
| 444 |
+
value={otpInput}
|
| 445 |
+
onChange={e => setOtpInput(e.target.value)}
|
| 446 |
+
onKeyDown={e => { if (e.key === 'Enter') handleOtpSubmit(); }}
|
| 447 |
+
/>
|
| 448 |
+
</div>
|
| 449 |
+
<div className="flex space-x-2 pt-2">
|
| 450 |
+
<button
|
| 451 |
+
onClick={handleOtpSubmit}
|
| 452 |
+
className="flex-1 bg-[#0e639c] hover:bg-[#1177bb] text-white py-2 text-xs font-semibold rounded transition"
|
| 453 |
+
>
|
| 454 |
+
Save & Continue
|
| 455 |
+
</button>
|
| 456 |
+
<button
|
| 457 |
+
onClick={() => setOtpPrompt(null)}
|
| 458 |
+
className="px-4 border border-[#3c3c3c] text-zinc-400 hover:text-white hover:bg-[#2d2d2d] py-2 text-xs rounded transition"
|
| 459 |
+
>
|
| 460 |
+
Cancel
|
| 461 |
+
</button>
|
| 462 |
+
</div>
|
| 463 |
+
</div>
|
| 464 |
+
</div>
|
| 465 |
+
</div>
|
| 466 |
+
)}
|
| 467 |
+
</div>
|
| 468 |
+
</div>
|
| 469 |
+
|
| 470 |
+
{/* Bottom Chat Input */}
|
| 471 |
+
<div className="p-4 border-t border-[#333333] shrink-0">
|
| 472 |
+
<div className="max-w-4xl mx-auto flex items-end space-x-2 bg-[#1e1e1e] border border-[#3c3c3c] rounded-lg focus-within:border-[#0e639c] transition-colors shadow-sm overflow-hidden p-2">
|
| 473 |
+
<textarea
|
| 474 |
+
placeholder={activeSpecId ? "Describe your test scenario... (e.g. 'Register a new user, log in, get profile')" : "Load an API Collection first."}
|
| 475 |
+
disabled={!activeSpecId || isPlanning}
|
| 476 |
+
value={scenario}
|
| 477 |
+
onChange={e => setScenario(e.target.value)}
|
| 478 |
+
onKeyDown={e => {
|
| 479 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 480 |
+
e.preventDefault();
|
| 481 |
+
handleGeneratePlan();
|
| 482 |
+
}
|
| 483 |
+
}}
|
| 484 |
+
className="w-full bg-transparent text-sm resize-none outline-none p-2 max-h-40 min-h-[44px] text-white placeholder-zinc-500 disabled:opacity-50"
|
| 485 |
+
style={{ height: '44px' }}
|
| 486 |
+
/>
|
| 487 |
+
<button
|
| 488 |
+
onClick={handleGeneratePlan}
|
| 489 |
+
disabled={!activeSpecId || isPlanning || !scenario.trim()}
|
| 490 |
+
className="p-2 mb-1 rounded-md bg-[#0e639c] hover:bg-[#1177bb] disabled:opacity-50 transition text-white"
|
| 491 |
+
>
|
| 492 |
+
{isPlanning ? <RefreshCw className="animate-spin" size={18} /> : <Send size={18} />}
|
| 493 |
+
</button>
|
| 494 |
+
</div>
|
| 495 |
+
</div>
|
| 496 |
+
</div>
|
| 497 |
+
)}
|
| 498 |
+
|
| 499 |
+
{activePage === 'collections' && <CollectionsPage onCollectionSelected={() => setActivePage('testing')} />}
|
| 500 |
+
{activePage === 'profile' && <ProfilePage />}
|
| 501 |
+
{activePage === 'history' && <HistoryPage />}
|
| 502 |
+
{activePage === 'media' && <MediaHubPage />}
|
| 503 |
+
</div>
|
| 504 |
+
|
| 505 |
+
{/* 3. RIGHT SIDEBAR (Context Variables) */}
|
| 506 |
+
<div className={`flex flex-shrink-0 bg-[#252526] border-l border-[#333333] transition-all duration-300 ${rightPanelOpen && activePage === 'testing' ? 'w-72' : 'w-0'}`}>
|
| 507 |
+
{/* Toggle Button (when closed, we might want it lingering on the UI or just controlled via header - we will put a small hovering toggle) */}
|
| 508 |
+
<div className="w-full h-full flex flex-col overflow-hidden whitespace-nowrap">
|
| 509 |
+
<div className="h-10 flex items-center justify-between px-4 shrink-0 border-b border-[#333333]">
|
| 510 |
+
<span className="font-semibold text-xs tracking-wider text-zinc-400 uppercase">Context & Variables</span>
|
| 511 |
+
<button onClick={() => setRightPanelOpen(false)} className="text-zinc-500 hover:text-white">
|
| 512 |
+
<ChevronRight size={16} />
|
| 513 |
+
</button>
|
| 514 |
+
</div>
|
| 515 |
+
|
| 516 |
+
<div className="flex-1 overflow-y-auto p-4 space-y-6">
|
| 517 |
+
{/* Session Context */}
|
| 518 |
+
<div>
|
| 519 |
+
<div className="flex items-center justify-between mb-2">
|
| 520 |
+
<h3 className="text-xs uppercase text-zinc-500 font-semibold">Session Extracted</h3>
|
| 521 |
+
<button onClick={() => refreshSessionContext()} className="text-zinc-500 hover:text-white" title="Refresh Context"><RefreshCw size={12}/></button>
|
| 522 |
+
</div>
|
| 523 |
+
<div className="bg-[#1e1e1e] p-3 rounded text-xs border border-[#333333] text-zinc-300 font-mono space-y-1">
|
| 524 |
+
{Object.keys(sessionContextVars || {}).length === 0 ? (
|
| 525 |
+
<span className="text-zinc-500 italic">No variables extracted safely yet</span>
|
| 526 |
+
) : (
|
| 527 |
+
Object.entries(sessionContextVars).map(([k,v]) => (
|
| 528 |
+
<div key={k} className="flex"><span className="text-[#9cdcfe] w-24 truncate">{k}:</span> <span className="text-[#ce9178] truncate flex-1 ml-2">"{String(v)}"</span></div>
|
| 529 |
+
))
|
| 530 |
+
)}
|
| 531 |
+
</div>
|
| 532 |
+
</div>
|
| 533 |
+
|
| 534 |
+
{/* Test User Credentials */}
|
| 535 |
+
<div>
|
| 536 |
+
<h3 className="text-xs uppercase text-zinc-500 font-semibold mb-2">Test Credentials</h3>
|
| 537 |
+
<div className="bg-[#1e1e1e] p-3 rounded text-xs border border-[#333333] text-zinc-300 font-mono space-y-1">
|
| 538 |
+
{Object.keys(storedCredentials || {}).length === 0 ? (
|
| 539 |
+
<span className="text-zinc-500 italic">No credentials loaded</span>
|
| 540 |
+
) : (
|
| 541 |
+
Object.entries(storedCredentials).filter(([k]) => k !== '_clear').map(([k,v]) => {
|
| 542 |
+
const isSensitive = k.toLowerCase().match(/(password|token|jwt|secret|bearer)/);
|
| 543 |
+
const displayVal = isSensitive && v ? String(v).slice(0,4) + '****' + String(v).slice(-2) : String(v);
|
| 544 |
+
return (
|
| 545 |
+
<div key={k} className="flex"><span className="text-[#4fc1ff] w-24 truncate">{k}:</span> <span className="text-[#d16969] truncate flex-1 ml-2">"{displayVal}"</span></div>
|
| 546 |
+
)
|
| 547 |
+
})
|
| 548 |
+
)}
|
| 549 |
+
</div>
|
| 550 |
+
</div>
|
| 551 |
+
</div>
|
| 552 |
+
</div>
|
| 553 |
+
</div>
|
| 554 |
+
|
| 555 |
+
{/* Floating Toggle if Right sidebar is closed */}
|
| 556 |
+
{!rightPanelOpen && (
|
| 557 |
+
<button
|
| 558 |
+
onClick={() => setRightPanelOpen(true)}
|
| 559 |
+
className="absolute right-0 top-1/2 transform -translate-y-1/2 p-1 bg-[#333333] text-zinc-400 hover:text-white rounded-l-md border border-r-0 border-[#3c3c3c] shadow-lg"
|
| 560 |
+
>
|
| 561 |
+
<ChevronLeft size={20} />
|
| 562 |
+
</button>
|
| 563 |
+
)}
|
| 564 |
+
|
| 565 |
+
</div>
|
| 566 |
+
);
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
export default function App() {
|
| 570 |
+
return (
|
| 571 |
+
<AppProvider>
|
| 572 |
+
<MainApp />
|
| 573 |
+
</AppProvider>
|
| 574 |
+
);
|
| 575 |
+
}
|
frontend-react/src/assets/hero.png
ADDED
|
Git LFS Details
|
frontend-react/src/assets/react.svg
ADDED
|
|
frontend-react/src/assets/vite.svg
ADDED
|
|
frontend-react/src/components/AppContext.jsx
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { createContext, useContext, useState, useEffect } from 'react';
|
| 2 |
+
import { SessionService, SpecService, CredentialService } from '../services/api';
|
| 3 |
+
|
| 4 |
+
const AppContext = createContext();
|
| 5 |
+
|
| 6 |
+
export const useAppContext = () => useContext(AppContext);
|
| 7 |
+
|
| 8 |
+
export const AppProvider = ({ children }) => {
|
| 9 |
+
const [sessionId, setSessionId] = useState(null);
|
| 10 |
+
const [collections, setCollections] = useState([]);
|
| 11 |
+
const [activeSpecId, setActiveSpecId] = useState(null);
|
| 12 |
+
const [activeSpecName, setActiveSpecName] = useState('None');
|
| 13 |
+
const [activeBaseUrl, setActiveBaseUrl] = useState('');
|
| 14 |
+
const [parsedSpec, setParsedSpec] = useState(null);
|
| 15 |
+
const [storedCredentials, setStoredCredentials] = useState({});
|
| 16 |
+
const [sessionContextVars, setSessionContextVars] = useState({});
|
| 17 |
+
const [executionPlan, setExecutionPlan] = useState(null);
|
| 18 |
+
const [scenario, setScenario] = useState('');
|
| 19 |
+
const [isLoading, setIsLoading] = useState(true);
|
| 20 |
+
|
| 21 |
+
// Initialize Session
|
| 22 |
+
useEffect(() => {
|
| 23 |
+
const initSession = async () => {
|
| 24 |
+
try {
|
| 25 |
+
const data = await SessionService.createSession();
|
| 26 |
+
setSessionId(data.session_id);
|
| 27 |
+
} catch (err) {
|
| 28 |
+
console.error("Failed to init session", err);
|
| 29 |
+
}
|
| 30 |
+
};
|
| 31 |
+
initSession();
|
| 32 |
+
fetchCollections();
|
| 33 |
+
}, []);
|
| 34 |
+
|
| 35 |
+
const fetchCollections = async () => {
|
| 36 |
+
try {
|
| 37 |
+
const data = await SpecService.getAllSpecs();
|
| 38 |
+
setCollections(data);
|
| 39 |
+
setIsLoading(false);
|
| 40 |
+
} catch (err) {
|
| 41 |
+
console.error("Failed to fetch collections", err);
|
| 42 |
+
setIsLoading(false);
|
| 43 |
+
}
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
const loadSpec = async (id) => {
|
| 47 |
+
try {
|
| 48 |
+
const data = await SpecService.getSpec(id);
|
| 49 |
+
setParsedSpec(data.parsed_spec);
|
| 50 |
+
setActiveSpecName(data.name);
|
| 51 |
+
setActiveSpecId(data.id);
|
| 52 |
+
setActiveBaseUrl(data.base_url || '');
|
| 53 |
+
|
| 54 |
+
// We no longer auto-load previous execution plans or scenarios
|
| 55 |
+
// to keep the testing workspace fresh. They are available in History.
|
| 56 |
+
setExecutionPlan(null);
|
| 57 |
+
setScenario('');
|
| 58 |
+
|
| 59 |
+
// Load Profile/Credentials for this spec
|
| 60 |
+
const creds = await CredentialService.getCredentials(id);
|
| 61 |
+
setStoredCredentials(creds || {});
|
| 62 |
+
|
| 63 |
+
// Load any existing session context if we needed it (usually empty on new spec)
|
| 64 |
+
setSessionContextVars({});
|
| 65 |
+
} catch (err) {
|
| 66 |
+
console.error("Failed to load spec", err);
|
| 67 |
+
}
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
const saveProfile = async (payload) => {
|
| 71 |
+
if (!activeSpecId) return;
|
| 72 |
+
try {
|
| 73 |
+
const data = await CredentialService.saveCredentials(activeSpecId, payload);
|
| 74 |
+
setStoredCredentials(data.credentials || {});
|
| 75 |
+
} catch (err) {
|
| 76 |
+
console.error("Failed to save credentials", err);
|
| 77 |
+
throw err;
|
| 78 |
+
}
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
const deleteSpec = async (id) => {
|
| 82 |
+
try {
|
| 83 |
+
await SpecService.deleteSpec(id);
|
| 84 |
+
if (activeSpecId === id) {
|
| 85 |
+
setActiveSpecId(null);
|
| 86 |
+
setActiveSpecName('None');
|
| 87 |
+
setParsedSpec(null);
|
| 88 |
+
setActiveBaseUrl('');
|
| 89 |
+
setExecutionPlan(null);
|
| 90 |
+
setStoredCredentials({});
|
| 91 |
+
}
|
| 92 |
+
fetchCollections(); // refresh list
|
| 93 |
+
} catch (err) {
|
| 94 |
+
console.error("Failed to delete spec", err);
|
| 95 |
+
}
|
| 96 |
+
};
|
| 97 |
+
|
| 98 |
+
const refreshSessionContext = async () => {
|
| 99 |
+
if (!sessionId) return;
|
| 100 |
+
try {
|
| 101 |
+
const data = await SessionService.getContext(sessionId);
|
| 102 |
+
setSessionContextVars(data || {});
|
| 103 |
+
} catch (err) {
|
| 104 |
+
console.error("Failed to refresh session context", err);
|
| 105 |
+
}
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
const importSession = async (sessionData) => {
|
| 109 |
+
// 1. Ensure the correct Spec is loaded if it's different
|
| 110 |
+
if (sessionData.spec_id && sessionData.spec_id !== activeSpecId) {
|
| 111 |
+
await loadSpec(sessionData.spec_id);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// 2. Set the restored data
|
| 115 |
+
if (sessionData.stepsForImport) {
|
| 116 |
+
setExecutionPlan(sessionData.stepsForImport);
|
| 117 |
+
} else if (sessionData.steps) {
|
| 118 |
+
setExecutionPlan(sessionData.steps);
|
| 119 |
+
}
|
| 120 |
+
if (sessionData.scenario) {
|
| 121 |
+
setScenario(sessionData.scenario);
|
| 122 |
+
}
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
const startNewSession = async () => {
|
| 126 |
+
try {
|
| 127 |
+
const data = await SessionService.createSession();
|
| 128 |
+
setSessionId(data.session_id);
|
| 129 |
+
setSessionContextVars({});
|
| 130 |
+
return data.session_id;
|
| 131 |
+
} catch (err) {
|
| 132 |
+
console.error("Failed to start new session", err);
|
| 133 |
+
return null;
|
| 134 |
+
}
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
return (
|
| 138 |
+
<AppContext.Provider
|
| 139 |
+
value={{
|
| 140 |
+
sessionId,
|
| 141 |
+
collections,
|
| 142 |
+
activeSpecId,
|
| 143 |
+
activeSpecName,
|
| 144 |
+
activeBaseUrl,
|
| 145 |
+
parsedSpec,
|
| 146 |
+
storedCredentials,
|
| 147 |
+
sessionContextVars,
|
| 148 |
+
executionPlan,
|
| 149 |
+
scenario,
|
| 150 |
+
isLoading,
|
| 151 |
+
setActiveBaseUrl,
|
| 152 |
+
setExecutionPlan,
|
| 153 |
+
setStoredCredentials,
|
| 154 |
+
fetchCollections,
|
| 155 |
+
loadSpec,
|
| 156 |
+
deleteSpec,
|
| 157 |
+
refreshSessionContext,
|
| 158 |
+
saveProfile,
|
| 159 |
+
setScenario,
|
| 160 |
+
importSession,
|
| 161 |
+
startNewSession
|
| 162 |
+
}}
|
| 163 |
+
>
|
| 164 |
+
{children}
|
| 165 |
+
</AppContext.Provider>
|
| 166 |
+
);
|
| 167 |
+
};
|
frontend-react/src/components/CollectionsPage.jsx
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useRef, useState } from 'react';
|
| 2 |
+
import { Database, Upload, Trash2, LayoutTemplate, Search, RefreshCw, Plus, Check } from 'lucide-react';
|
| 3 |
+
import { useAppContext } from './AppContext';
|
| 4 |
+
import { SpecService } from '../services/api';
|
| 5 |
+
|
| 6 |
+
const CollectionsPage = ({ onCollectionSelected }) => {
|
| 7 |
+
const {
|
| 8 |
+
collections, activeSpecId, loadSpec, deleteSpec,
|
| 9 |
+
fetchCollections, isLoading
|
| 10 |
+
} = useAppContext();
|
| 11 |
+
|
| 12 |
+
const fileInputRef = useRef(null);
|
| 13 |
+
const [isUploading, setIsUploading] = useState(false);
|
| 14 |
+
const [searchQuery, setSearchQuery] = useState('');
|
| 15 |
+
|
| 16 |
+
const handleFileUpload = async (e) => {
|
| 17 |
+
const file = e.target.files?.[0];
|
| 18 |
+
if (!file) return;
|
| 19 |
+
|
| 20 |
+
setIsUploading(true);
|
| 21 |
+
try {
|
| 22 |
+
await SpecService.uploadSpec(file);
|
| 23 |
+
await fetchCollections();
|
| 24 |
+
} catch (err) {
|
| 25 |
+
console.error("Upload failed", err);
|
| 26 |
+
alert("Failed to upload spec.");
|
| 27 |
+
} finally {
|
| 28 |
+
setIsUploading(false);
|
| 29 |
+
if (fileInputRef.current) fileInputRef.current.value = '';
|
| 30 |
+
}
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
const filteredSpecs = collections.filter(spec =>
|
| 34 |
+
spec.name.toLowerCase().includes(searchQuery.toLowerCase())
|
| 35 |
+
);
|
| 36 |
+
|
| 37 |
+
return (
|
| 38 |
+
<div className="flex-1 flex flex-col bg-[#1e1e1e] overflow-hidden animate-in fade-in slide-in-from-bottom-2 duration-300">
|
| 39 |
+
{/* Header */}
|
| 40 |
+
<div className="h-14 border-b border-[#333333] flex items-center justify-between px-6 bg-[#252526]">
|
| 41 |
+
<div className="flex items-center space-x-4">
|
| 42 |
+
<h1 className="text-lg font-medium text-white flex items-center space-x-2">
|
| 43 |
+
<Database size={20} className="text-[#519aba]" />
|
| 44 |
+
<span>API Collections</span>
|
| 45 |
+
</h1>
|
| 46 |
+
</div>
|
| 47 |
+
<div className="flex items-center space-x-3">
|
| 48 |
+
<div className="relative">
|
| 49 |
+
<Search size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500" />
|
| 50 |
+
<input
|
| 51 |
+
type="text"
|
| 52 |
+
placeholder="Search collections..."
|
| 53 |
+
className="bg-[#1e1e1e] border border-[#3c3c3c] text-white text-xs pl-9 pr-3 py-1.5 rounded-md w-64 outline-none focus:border-[#0e639c]"
|
| 54 |
+
value={searchQuery}
|
| 55 |
+
onChange={e => setSearchQuery(e.target.value)}
|
| 56 |
+
/>
|
| 57 |
+
</div>
|
| 58 |
+
<button
|
| 59 |
+
onClick={() => fileInputRef.current?.click()}
|
| 60 |
+
disabled={isUploading}
|
| 61 |
+
className="bg-[#0e639c] hover:bg-[#1177bb] text-white px-4 py-1.5 text-xs rounded flex items-center space-x-2 transition shadow-sm"
|
| 62 |
+
>
|
| 63 |
+
{isUploading ? <RefreshCw size={14} className="animate-spin" /> : <Plus size={14} />}
|
| 64 |
+
<span>{isUploading ? 'Uploading...' : 'Upload Spec'}</span>
|
| 65 |
+
</button>
|
| 66 |
+
<input
|
| 67 |
+
type="file"
|
| 68 |
+
ref={fileInputRef}
|
| 69 |
+
className="hidden"
|
| 70 |
+
accept=".json,.yaml,.yml"
|
| 71 |
+
onChange={handleFileUpload}
|
| 72 |
+
/>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
<div className="flex-1 overflow-y-auto p-6">
|
| 77 |
+
{isLoading ? (
|
| 78 |
+
<div className="flex flex-col items-center justify-center h-64">
|
| 79 |
+
<RefreshCw size={48} className="text-[#333333] animate-spin mb-4" />
|
| 80 |
+
<p className="text-zinc-500 text-sm">Loading collections...</p>
|
| 81 |
+
</div>
|
| 82 |
+
) : filteredSpecs.length === 0 ? (
|
| 83 |
+
<div className="flex flex-col items-center justify-center h-64 opacity-50">
|
| 84 |
+
<Database size={64} className="mb-4 text-zinc-700" />
|
| 85 |
+
<p className="text-zinc-500">No collections found. Upload a Swagger/OpenAPI spec to get started.</p>
|
| 86 |
+
</div>
|
| 87 |
+
) : (
|
| 88 |
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
| 89 |
+
{filteredSpecs.map(spec => (
|
| 90 |
+
<div
|
| 91 |
+
key={spec.id}
|
| 92 |
+
onClick={() => { loadSpec(spec.id); onCollectionSelected(); }}
|
| 93 |
+
className={`group bg-[#252526] border rounded-lg p-5 cursor-pointer transition relative overflow-hidden flex flex-col items-center text-center ${activeSpecId === spec.id ? 'border-[#0e639c] bg-[#2a2d2e] ring-1 ring-[#0e639c]' : 'border-[#333333] hover:border-[#444444] hover:bg-[#2d2d2d]'}`}
|
| 94 |
+
>
|
| 95 |
+
<div className={`p-4 rounded-xl border mb-4 transition ${activeSpecId === spec.id ? 'bg-[#1e1e1e] border-[#0e639c]' : 'bg-[#1e1e1e] border-[#333333]'}`}>
|
| 96 |
+
<LayoutTemplate size={32} className={activeSpecId === spec.id ? 'text-[#519aba]' : 'text-zinc-500'} />
|
| 97 |
+
</div>
|
| 98 |
+
|
| 99 |
+
<div className="w-full">
|
| 100 |
+
<div className="text-sm font-semibold text-white truncate" title={spec.name}>{spec.name}</div>
|
| 101 |
+
<div className="text-[10px] text-zinc-500 mt-1 uppercase tracking-widest font-bold">API Specification</div>
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
<div className="mt-4 pt-4 border-t border-[#333333] w-full flex items-center justify-between">
|
| 105 |
+
<span className="text-[10px] text-zinc-600">ID: {spec.id.slice(0,8)}...</span>
|
| 106 |
+
<button
|
| 107 |
+
onClick={(e) => { e.stopPropagation(); deleteSpec(spec.id); }}
|
| 108 |
+
className="p-1.5 text-zinc-500 hover:text-red-400 hover:bg-red-400/10 rounded transition"
|
| 109 |
+
>
|
| 110 |
+
<Trash2 size={14} />
|
| 111 |
+
</button>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
{activeSpecId === spec.id && (
|
| 115 |
+
<div className="absolute top-2 right-2 flex items-center bg-[#0e639c] text-white text-[8px] font-bold px-2 py-1 rounded shadow-lg uppercase tracking-wider">
|
| 116 |
+
<Check size={8} className="mr-1" />
|
| 117 |
+
Active
|
| 118 |
+
</div>
|
| 119 |
+
)}
|
| 120 |
+
</div>
|
| 121 |
+
))}
|
| 122 |
+
</div>
|
| 123 |
+
)}
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
);
|
| 127 |
+
};
|
| 128 |
+
|
| 129 |
+
export default CollectionsPage;
|
frontend-react/src/components/Histo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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from 'react';
|
| 2 |
+
import { History, Clock, CheckCircle, XCircle, ChevronRight, Activity, Search, Filter, Trash2, ArrowRight, Zap } from 'lucide-react';
|
| 3 |
+
import { HistoryService } from '../services/api';
|
| 4 |
+
import { useAppContext } from './AppContext';
|
| 5 |
+
|
| 6 |
+
const HistoryPage = () => {
|
| 7 |
+
const { importSession } = useAppContext();
|
| 8 |
+
const [history, setHistory] = useState([]);
|
| 9 |
+
const [isLoading, setIsLoading] = useState(true);
|
| 10 |
+
const [searchQuery, setSearchQuery] = useState('');
|
| 11 |
+
const [expandedSessionId, setExpandedSessionId] = useState(null);
|
| 12 |
+
const [expandedStepId, setExpandedStepId] = useState(null);
|
| 13 |
+
|
| 14 |
+
useEffect(() => {
|
| 15 |
+
fetchHistory();
|
| 16 |
+
}, []);
|
| 17 |
+
|
| 18 |
+
const handleImport = (session) => {
|
| 19 |
+
importSession(session);
|
| 20 |
+
// Navigate to testing page
|
| 21 |
+
const event = new CustomEvent('nav-change', { detail: 'testing' });
|
| 22 |
+
window.dispatchEvent(event);
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
const fetchHistory = async () => {
|
| 26 |
+
setIsLoading(true);
|
| 27 |
+
try {
|
| 28 |
+
const data = await HistoryService.getHistory();
|
| 29 |
+
setHistory(data);
|
| 30 |
+
} catch (e) {
|
| 31 |
+
console.error("Failed to fetch history", e);
|
| 32 |
+
} finally {
|
| 33 |
+
setIsLoading(false);
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
const handleDeleteSession = async (sessionId) => {
|
| 38 |
+
if (!window.confirm("Are you sure you want to delete this test session?")) return;
|
| 39 |
+
try {
|
| 40 |
+
await HistoryService.deleteHistorySession(sessionId);
|
| 41 |
+
setHistory(prev => prev.filter(item => item.session_id !== sessionId));
|
| 42 |
+
if (expandedSessionId === sessionId) setExpandedSessionId(null);
|
| 43 |
+
} catch (e) {
|
| 44 |
+
console.error("Delete failed", e);
|
| 45 |
+
alert("Failed to delete session.");
|
| 46 |
+
}
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
const handleClearAll = async () => {
|
| 50 |
+
if (!window.confirm("CRITICAL: This will permanently wipe ALL test history. Proceed?")) return;
|
| 51 |
+
try {
|
| 52 |
+
await HistoryService.clearAllHistory();
|
| 53 |
+
setHistory([]);
|
| 54 |
+
setExpandedSessionId(null);
|
| 55 |
+
} catch (e) {
|
| 56 |
+
console.error("Clear failed", e);
|
| 57 |
+
alert("Failed to clear history.");
|
| 58 |
+
}
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
// Grouping logic: Create a map of sessions, then convert to array
|
| 62 |
+
const sessionsMap = (history || []).reduce((acc, curr) => {
|
| 63 |
+
if (!curr) return acc;
|
| 64 |
+
const sid = curr.session_id || 'unknown';
|
| 65 |
+
if (!acc[sid]) {
|
| 66 |
+
acc[sid] = {
|
| 67 |
+
session_id: sid,
|
| 68 |
+
spec_id: curr.spec_id,
|
| 69 |
+
spec_name: curr.spec_name || 'Unknown Spec',
|
| 70 |
+
scenario: curr.scenario || 'No scenario text',
|
| 71 |
+
timestamp: curr.timestamp,
|
| 72 |
+
steps: [],
|
| 73 |
+
status: 'success'
|
| 74 |
+
};
|
| 75 |
+
}
|
| 76 |
+
acc[sid].steps.push(curr);
|
| 77 |
+
if (curr.analysis?.status === 'failure') acc[sid].status = 'failure';
|
| 78 |
+
|
| 79 |
+
// Capture context variables from the session metadata
|
| 80 |
+
if (curr.context_variables && Object.keys(curr.context_variables).length > 0) {
|
| 81 |
+
if (!acc[sid].context_variables) acc[sid].context_variables = {};
|
| 82 |
+
Object.assign(acc[sid].context_variables, curr.context_variables);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// Capture step definition if it exists (for restoration)
|
| 86 |
+
if (curr.step_definition) {
|
| 87 |
+
if (!acc[sid].plan_steps) acc[sid].plan_steps = {};
|
| 88 |
+
acc[sid].plan_steps[curr.step] = curr.step_definition;
|
| 89 |
+
}
|
| 90 |
+
// Keep the most recent timestamp as session timestamp
|
| 91 |
+
if (new Date(curr.timestamp) > new Date(acc[sid].timestamp)) {
|
| 92 |
+
acc[sid].timestamp = curr.timestamp;
|
| 93 |
+
}
|
| 94 |
+
return acc;
|
| 95 |
+
}, {});
|
| 96 |
+
|
| 97 |
+
// Sort steps within sessions and convert map to sorted array
|
| 98 |
+
const groupedSessions = Object.values(sessionsMap)
|
| 99 |
+
.map(s => {
|
| 100 |
+
// Reconstruct the plan from plan_steps or fallback to minimal info from steps
|
| 101 |
+
const stepsForImport = Object.keys(s.plan_steps || {}).length > 0
|
| 102 |
+
? Object.values(s.plan_steps).sort((a,b) => a.step - b.step)
|
| 103 |
+
: s.steps.map(st => ({
|
| 104 |
+
step: st.step,
|
| 105 |
+
endpoint: st.request.method + ' ' + st.request.url.split('/').pop(),
|
| 106 |
+
purpose: st.analysis?.response_summary?.slice(0, 50) || 'Step execution'
|
| 107 |
+
})).sort((a,b) => a.step - b.step);
|
| 108 |
+
|
| 109 |
+
return {
|
| 110 |
+
...s,
|
| 111 |
+
stepsForImport,
|
| 112 |
+
steps: s.steps.sort((a, b) => a.step - b.step)
|
| 113 |
+
};
|
| 114 |
+
})
|
| 115 |
+
.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp));
|
| 116 |
+
|
| 117 |
+
const filteredSessions = groupedSessions.filter(s =>
|
| 118 |
+
s.spec_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
| 119 |
+
s.scenario.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
| 120 |
+
s.steps.some(st => (st.analysis?.response_summary || '').toLowerCase().includes(searchQuery.toLowerCase()))
|
| 121 |
+
);
|
| 122 |
+
|
| 123 |
+
const formatDate = (dateStr) => {
|
| 124 |
+
const d = new Date(dateStr);
|
| 125 |
+
return d.toLocaleString('en-US', {
|
| 126 |
+
month: 'short',
|
| 127 |
+
day: 'numeric',
|
| 128 |
+
hour: '2-digit',
|
| 129 |
+
minute: '2-digit'
|
| 130 |
+
});
|
| 131 |
+
};
|
| 132 |
+
|
| 133 |
+
return (
|
| 134 |
+
<div className="flex-1 flex flex-col bg-[#1e1e1e] overflow-hidden animate-in fade-in slide-in-from-bottom-2 duration-300">
|
| 135 |
+
{/* Header */}
|
| 136 |
+
<div className="h-14 border-b border-[#333333] flex items-center justify-between px-6 bg-[#252526] shrink-0">
|
| 137 |
+
<div className="flex items-center space-x-4">
|
| 138 |
+
<h1 className="text-lg font-medium text-white flex items-center space-x-2">
|
| 139 |
+
<History size={20} className="text-[#519aba]" />
|
| 140 |
+
<span>Execution History</span>
|
| 141 |
+
</h1>
|
| 142 |
+
<span className="text-xs bg-[#333333] text-zinc-500 px-2 py-0.5 rounded-full font-mono">
|
| 143 |
+
{groupedSessions.length} sessions
|
| 144 |
+
</span>
|
| 145 |
+
</div>
|
| 146 |
+
|
| 147 |
+
<div className="flex items-center space-x-3">
|
| 148 |
+
<div className="relative">
|
| 149 |
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500" size={14} />
|
| 150 |
+
<input
|
| 151 |
+
type="text"
|
| 152 |
+
placeholder="Search specs, scenarios..."
|
| 153 |
+
value={searchQuery}
|
| 154 |
+
onChange={e => setSearchQuery(e.target.value)}
|
| 155 |
+
className="bg-[#1e1e1e] border border-[#3c3c3c] text-white pl-9 pr-4 py-1.5 text-xs rounded-lg outline-none focus:border-[#0e639c] w-64 transition-all"
|
| 156 |
+
/>
|
| 157 |
+
</div>
|
| 158 |
+
<button
|
| 159 |
+
onClick={fetchHistory}
|
| 160 |
+
className="p-2 text-zinc-400 hover:text-white hover:bg-[#333333] rounded-lg transition-colors"
|
| 161 |
+
title="Refresh History"
|
| 162 |
+
>
|
| 163 |
+
<Activity size={18} />
|
| 164 |
+
</button>
|
| 165 |
+
|
| 166 |
+
{groupedSessions.length > 0 && (
|
| 167 |
+
<button
|
| 168 |
+
onClick={handleClearAll}
|
| 169 |
+
className="px-3 py-1.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 text-[10px] font-bold uppercase tracking-wider rounded-lg border border-red-500/20 transition-all flex items-center space-x-2"
|
| 170 |
+
title="Clear All History"
|
| 171 |
+
>
|
| 172 |
+
<Trash2 size={14} />
|
| 173 |
+
<span>Clear All</span>
|
| 174 |
+
</button>
|
| 175 |
+
)}
|
| 176 |
+
</div>
|
| 177 |
+
</div>
|
| 178 |
+
|
| 179 |
+
{isLoading ? (
|
| 180 |
+
<div className="flex-1 flex flex-col items-center justify-center space-y-4 opacity-50">
|
| 181 |
+
<Activity size={32} className="text-[#0e639c] animate-pulse" />
|
| 182 |
+
<p className="text-sm font-light text-zinc-400">Loading history records...</p>
|
| 183 |
+
</div>
|
| 184 |
+
) : filteredSessions.length === 0 ? (
|
| 185 |
+
<div className="flex-1 flex flex-col items-center justify-center p-12 text-center">
|
| 186 |
+
<div className="w-16 h-16 bg-[#252526] border border-[#333333] rounded-2xl flex items-center justify-center mb-6">
|
| 187 |
+
<History size={32} className="text-zinc-600" />
|
| 188 |
+
</div>
|
| 189 |
+
<h3 className="text-lg font-light text-zinc-300">No History Found</h3>
|
| 190 |
+
<p className="text-sm text-zinc-500 max-w-xs mt-2">
|
| 191 |
+
Run some test scenarios on the Workflow page to see execution logs appear here.
|
| 192 |
+
</p>
|
| 193 |
+
</div>
|
| 194 |
+
) : (
|
| 195 |
+
<div className="flex-1 overflow-y-auto p-6">
|
| 196 |
+
<div className="max-w-5xl mx-auto space-y-4">
|
| 197 |
+
{filteredSessions.map((session) => (
|
| 198 |
+
<div
|
| 199 |
+
key={session.session_id}
|
| 200 |
+
className={`group border transition-all duration-200 overflow-hidden rounded-xl ${
|
| 201 |
+
expandedSessionId === session.session_id
|
| 202 |
+
? 'bg-[#252526] border-[#444444] shadow-2xl'
|
| 203 |
+
: 'bg-[#252526]/50 border-[#333333] hover:border-[#444444]'
|
| 204 |
+
}`}
|
| 205 |
+
>
|
| 206 |
+
{/* Session Header (Collapsible) */}
|
| 207 |
+
<div
|
| 208 |
+
onClick={() => setExpandedSessionId(expandedSessionId === session.session_id ? null : session.session_id)}
|
| 209 |
+
className="p-4 flex items-center cursor-pointer select-none"
|
| 210 |
+
>
|
| 211 |
+
<div className={`mr-4 p-2 rounded-lg ${
|
| 212 |
+
session.status === 'success' ? 'bg-emerald-500/10' : 'bg-red-500/10'
|
| 213 |
+
}`}>
|
| 214 |
+
{session.status === 'success'
|
| 215 |
+
? <Zap size={20} className="text-emerald-500" />
|
| 216 |
+
: <XCircle size={20} className="text-red-500" />
|
| 217 |
+
}
|
| 218 |
+
</div>
|
| 219 |
+
|
| 220 |
+
<div className="flex-1 min-w-0">
|
| 221 |
+
<div className="flex items-center space-x-2 text-[10px] font-bold uppercase tracking-wider text-zinc-500 mb-1">
|
| 222 |
+
<span className="text-[#519aba]">{session.spec_name}</span>
|
| 223 |
+
<span>•</span>
|
| 224 |
+
<span>{session.steps.length} steps</span>
|
| 225 |
+
</div>
|
| 226 |
+
<div className="text-sm text-white font-medium truncate">
|
| 227 |
+
{session.scenario}
|
| 228 |
+
</div>
|
| 229 |
+
</div>
|
| 230 |
+
|
| 231 |
+
<div className="flex items-center shrink-0 ml-6 space-x-4">
|
| 232 |
+
<button
|
| 233 |
+
onClick={(e) => { e.stopPropagation(); handleDeleteSession(session.session_id); }}
|
| 234 |
+
className="p-2 text-zinc-500 hover:text-red-500 hover:bg-red-500/10 rounded-lg transition-all"
|
| 235 |
+
title="Delete Session"
|
| 236 |
+
>
|
| 237 |
+
<Trash2 size={16} />
|
| 238 |
+
</button>
|
| 239 |
+
<button
|
| 240 |
+
onClick={(e) => { e.stopPropagation(); handleImport(session); }}
|
| 241 |
+
className="p-2 text-zinc-500 hover:text-[#519aba] hover:bg-[#333333] rounded-lg transition-all flex items-center space-x-2 group/btn"
|
| 242 |
+
title="Import to Testing Workspace"
|
| 243 |
+
>
|
| 244 |
+
<ArrowRight size={16} className="group-hover/btn:translate-x-0.5 transition-transform" />
|
| 245 |
+
<span className="text-[10px] uppercase font-bold tracking-tight hidden group-hover/btn:inline">Import</span>
|
| 246 |
+
</button>
|
| 247 |
+
<div className="flex flex-col items-end">
|
| 248 |
+
<div className="flex items-center text-xs text-zinc-500 font-mono mb-1">
|
| 249 |
+
<Clock size={12} className="mr-1" />
|
| 250 |
+
{formatDate(session.timestamp)}
|
| 251 |
+
</div>
|
| 252 |
+
<ChevronRight
|
| 253 |
+
size={16}
|
| 254 |
+
className={`text-zinc-600 transition-transform duration-200 ${expandedSessionId === session.session_id ? 'rotate-90' : ''}`}
|
| 255 |
+
/>
|
| 256 |
+
</div>
|
| 257 |
+
</div>
|
| 258 |
+
</div>
|
| 259 |
+
|
| 260 |
+
{/* Session Steps (Expanded View) */}
|
| 261 |
+
{expandedSessionId === session.session_id && (
|
| 262 |
+
<div className="px-4 pb-6 overflow-hidden animate-in slide-in-from-top-2 duration-200">
|
| 263 |
+
|
| 264 |
+
{/* Session Extraction History */}
|
| 265 |
+
{session.context_variables && Object.keys(session.context_variables).length > 0 && (
|
| 266 |
+
<div className="mb-6 bg-[#1e1e1e] border border-[#333333] rounded-lg p-4">
|
| 267 |
+
<h4 className="text-[10px] font-bold uppercase text-zinc-500 mb-3 tracking-wider flex items-center">
|
| 268 |
+
<Activity size={12} className="mr-2 text-[#4fc1ff]" />
|
| 269 |
+
Session Extraction History
|
| 270 |
+
</h4>
|
| 271 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3">
|
| 272 |
+
{Object.entries(session.context_variables).map(([k, v]) => (
|
| 273 |
+
<div key={k} className="flex flex-col space-y-1 bg-[#2d2d2d] p-2 rounded border border-[#3c3c3c]">
|
| 274 |
+
<span className="text-[9px] text-[#9cdcfe] font-mono">{k}</span>
|
| 275 |
+
<span className="text-xs text-[#ce9178] truncate">"{String(v)}"</span>
|
| 276 |
+
</div>
|
| 277 |
+
))}
|
| 278 |
+
</div>
|
| 279 |
+
</div>
|
| 280 |
+
)}
|
| 281 |
+
|
| 282 |
+
<div className="pt-4 border-t border-[#333333] space-y-3">
|
| 283 |
+
{session.steps.map((item) => (
|
| 284 |
+
<div key={item.id} className="border border-[#333333] rounded-lg overflow-hidden bg-[#1e1e1e]">
|
| 285 |
+
<div
|
| 286 |
+
onClick={() => setExpandedStepId(expandedStepId === item.id ? null : item.id)}
|
| 287 |
+
className="p-3 flex items-center justify-between cursor-pointer hover:bg-[#252526] transition-colors"
|
| 288 |
+
>
|
| 289 |
+
<div className="flex items-center space-x-3">
|
| 290 |
+
<span className={`px-2 py-0.5 rounded text-[10px] font-mono ${
|
| 291 |
+
item.analysis?.status === 'success' ? 'bg-green-500/20 text-green-400' : 'bg-red-500/20 text-red-400'
|
| 292 |
+
}`}>
|
| 293 |
+
Step {item.step}
|
| 294 |
+
</span>
|
| 295 |
+
<span className="text-xs text-zinc-300 font-medium">{item.request.method} {item.request.url.split('/').pop()}</span>
|
| 296 |
+
</div>
|
| 297 |
+
<ChevronRight
|
| 298 |
+
size={14}
|
| 299 |
+
className={`text-zinc-500 transition-transform duration-200 ${expandedStepId === item.id ? 'rotate-90' : ''}`}
|
| 300 |
+
/>
|
| 301 |
+
</div>
|
| 302 |
+
|
| 303 |
+
{/* Step Details */}
|
| 304 |
+
{expandedStepId === item.id && (
|
| 305 |
+
<div className="p-4 bg-[#1e1e1e] border-t border-[#333333] space-y-4 animate-in fade-in duration-200">
|
| 306 |
+
{/* AI Analysis Result */}
|
| 307 |
+
<div className={`p-4 rounded-lg border-l-4 ${
|
| 308 |
+
item.analysis?.status === 'success' ? 'border-emerald-500 bg-emerald-500/5' : 'border-red-500 bg-red-500/5'
|
| 309 |
+
}`}>
|
| 310 |
+
<div className="text-[10px] font-bold uppercase text-zinc-500 mb-2">AI Step Analysis</div>
|
| 311 |
+
<p className="text-xs text-zinc-300 leading-relaxed">
|
| 312 |
+
{item.analysis?.response_summary || "Summary not available."}
|
| 313 |
+
</p>
|
| 314 |
+
{item.analysis?.extracted_variables && Object.keys(item.analysis.extracted_variables).length > 0 && (
|
| 315 |
+
<div className="mt-3 flex flex-wrap gap-2">
|
| 316 |
+
{Object.entries(item.analysis.extracted_variables).map(([k, v]) => (
|
| 317 |
+
<div key={k} className="px-2 py-1 bg-[#2d2d2d] rounded text-[9px] text-[#9cdcfe] font-mono border border-[#3c3c3c]">
|
| 318 |
+
{k}: <span className="text-[#ce9178]">"{String(v)}"</span>
|
| 319 |
+
</div>
|
| 320 |
+
))}
|
| 321 |
+
</div>
|
| 322 |
+
)}
|
| 323 |
+
</div>
|
| 324 |
+
|
| 325 |
+
{/* Request/Response Grid */}
|
| 326 |
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 327 |
+
<div className="space-y-2">
|
| 328 |
+
<div className="text-[9px] uppercase font-bold text-zinc-500 flex items-center">
|
| 329 |
+
<ArrowRight size={10} className="mr-1" />
|
| 330 |
+
Request Details
|
| 331 |
+
</div>
|
| 332 |
+
<div className="bg-[#252526] border border-[#333333] rounded p-3 text-[10px] font-mono overflow-auto max-h-48 space-y-3">
|
| 333 |
+
<div className="text-[#569cd6] font-bold mb-2 break-all">{item.request.method} {item.request.url}</div>
|
| 334 |
+
|
| 335 |
+
{item.request.headers && Object.keys(item.request.headers).length > 0 && (
|
| 336 |
+
<div>
|
| 337 |
+
<div className="text-zinc-500 font-bold uppercase mb-1">Headers</div>
|
| 338 |
+
{Object.entries(item.request.headers).map(([k,v]) => (
|
| 339 |
+
<div key={k} className="text-[#9cdcfe]"><span className="text-zinc-500">{k}:</span> {v}</div>
|
| 340 |
+
))}
|
| 341 |
+
</div>
|
| 342 |
+
)}
|
| 343 |
+
|
| 344 |
+
{item.request.query_params && Object.keys(item.request.query_params).length > 0 && (
|
| 345 |
+
<div>
|
| 346 |
+
<div className="text-zinc-500 font-bold uppercase mb-1">Query Params</div>
|
| 347 |
+
{Object.entries(item.request.query_params).map(([k,v]) => (
|
| 348 |
+
<div key={k} className="text-[#9cdcfe]"><span className="text-zinc-500">{k}=</span>{v}</div>
|
| 349 |
+
))}
|
| 350 |
+
</div>
|
| 351 |
+
)}
|
| 352 |
+
|
| 353 |
+
{item.request.body && <div>
|
| 354 |
+
<div className="text-zinc-500 font-bold uppercase mb-1">Body</div>
|
| 355 |
+
<pre className="text-zinc-400">{JSON.stringify(item.request.body, null, 2)}</pre>
|
| 356 |
+
</div>}
|
| 357 |
+
|
| 358 |
+
{item.request.form_data && Object.keys(item.request.form_data).length > 0 && (
|
| 359 |
+
<div>
|
| 360 |
+
<div className="text-zinc-500 font-bold uppercase mb-1">Form Data</div>
|
| 361 |
+
<pre className="text-zinc-400">{JSON.stringify(item.request.form_data, null, 2)}</pre>
|
| 362 |
+
</div>
|
| 363 |
+
)}
|
| 364 |
+
|
| 365 |
+
{item.request.files && Object.keys(item.request.files).length > 0 && (
|
| 366 |
+
<div>
|
| 367 |
+
<div className="text-zinc-500 font-bold uppercase mb-1">Files</div>
|
| 368 |
+
{Object.entries(item.request.files).map(([k,v]) => (
|
| 369 |
+
<div key={k} className="text-[#ce9178]"><span className="text-zinc-500">{k}:</span> {v}</div>
|
| 370 |
+
))}
|
| 371 |
+
</div>
|
| 372 |
+
)}
|
| 373 |
+
</div>
|
| 374 |
+
</div>
|
| 375 |
+
|
| 376 |
+
<div className="space-y-2">
|
| 377 |
+
<div className="text-[9px] uppercase font-bold text-zinc-500 flex items-center">
|
| 378 |
+
<Zap size={10} className="mr-1" />
|
| 379 |
+
Response Body ({item.response.status_code})
|
| 380 |
+
</div>
|
| 381 |
+
<div className="bg-[#252526] border border-[#333333] rounded p-3 text-[10px] font-mono overflow-auto max-h-48">
|
| 382 |
+
<pre className="text-[#ce9178]">
|
| 383 |
+
{(() => {
|
| 384 |
+
try { return JSON.stringify(JSON.parse(item.response.body), null, 2); }
|
| 385 |
+
catch { return item.response.body; }
|
| 386 |
+
})()}
|
| 387 |
+
</pre>
|
| 388 |
+
</div>
|
| 389 |
+
</div>
|
| 390 |
+
</div>
|
| 391 |
+
</div>
|
| 392 |
+
)}
|
| 393 |
+
</div>
|
| 394 |
+
))}
|
| 395 |
+
</div>
|
| 396 |
+
</div>
|
| 397 |
+
)}
|
| 398 |
+
</div>
|
| 399 |
+
))}
|
| 400 |
+
</div>
|
| 401 |
+
</div>
|
| 402 |
+
)}
|
| 403 |
+
</div>
|
| 404 |
+
);
|
| 405 |
+
};
|
| 406 |
+
|
| 407 |
+
export default HistoryPage;
|
frontend-react/src/components/MediaHubPage.jsx
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from 'react';
|
| 2 |
+
import {
|
| 3 |
+
File, Image as ImageIcon, Music, Video, Folder,
|
| 4 |
+
Plus, Trash2, Search, Filter, Upload, Tags,
|
| 5 |
+
ChevronRight, MoreVertical, X, Check, Info
|
| 6 |
+
} from 'lucide-react';
|
| 7 |
+
import { AssetService } from '../services/api';
|
| 8 |
+
|
| 9 |
+
const MediaHubPage = () => {
|
| 10 |
+
const [assets, setAssets] = useState([]);
|
| 11 |
+
const [collections, setCollections] = useState([]);
|
| 12 |
+
const [isLoading, setIsLoading] = useState(true);
|
| 13 |
+
const [activeCategory, setActiveCategory] = useState('all');
|
| 14 |
+
const [activeCollectionId, setActiveCollectionId] = useState(null);
|
| 15 |
+
const [searchQuery, setSearchQuery] = useState('');
|
| 16 |
+
|
| 17 |
+
// Upload State
|
| 18 |
+
const [isUploading, setIsUploading] = useState(false);
|
| 19 |
+
const [uploadForm, setUploadForm] = useState({
|
| 20 |
+
description: '',
|
| 21 |
+
tags: ''
|
| 22 |
+
});
|
| 23 |
+
const [selectedFile, setSelectedFile] = useState(null);
|
| 24 |
+
const [showUploadModal, setShowUploadModal] = useState(false);
|
| 25 |
+
|
| 26 |
+
// New Collection State
|
| 27 |
+
const [showNewCollectionModal, setShowNewCollectionModal] = useState(false);
|
| 28 |
+
const [newColForm, setNewColForm] = useState({ name: '', description: '' });
|
| 29 |
+
|
| 30 |
+
useEffect(() => {
|
| 31 |
+
fetchData();
|
| 32 |
+
}, []);
|
| 33 |
+
|
| 34 |
+
const fetchData = async () => {
|
| 35 |
+
setIsLoading(true);
|
| 36 |
+
try {
|
| 37 |
+
const [assetsData, colsData] = await Promise.all([
|
| 38 |
+
AssetService.getAllAssets(),
|
| 39 |
+
AssetService.getCollections()
|
| 40 |
+
]);
|
| 41 |
+
setAssets(assetsData);
|
| 42 |
+
setCollections(colsData);
|
| 43 |
+
} catch (e) {
|
| 44 |
+
console.error("Failed to fetch media data", e);
|
| 45 |
+
} finally {
|
| 46 |
+
setIsLoading(false);
|
| 47 |
+
}
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
const handleFileUpload = async () => {
|
| 51 |
+
if (!selectedFile) return;
|
| 52 |
+
setIsUploading(true);
|
| 53 |
+
try {
|
| 54 |
+
const tags = uploadForm.tags.split(',').map(t => t.trim()).filter(t => t);
|
| 55 |
+
await AssetService.uploadAsset(null, selectedFile, uploadForm.description, tags);
|
| 56 |
+
setShowUploadModal(false);
|
| 57 |
+
setSelectedFile(null);
|
| 58 |
+
setUploadForm({ description: '', tags: '' });
|
| 59 |
+
fetchData();
|
| 60 |
+
} catch (e) {
|
| 61 |
+
console.error("Upload failed", e);
|
| 62 |
+
alert("Failed to upload asset");
|
| 63 |
+
} finally {
|
| 64 |
+
setIsUploading(false);
|
| 65 |
+
}
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
const handleCreateCollection = async () => {
|
| 69 |
+
if (!newColForm.name.trim()) return;
|
| 70 |
+
try {
|
| 71 |
+
await AssetService.createCollection(newColForm.name, newColForm.description);
|
| 72 |
+
setShowNewCollectionModal(false);
|
| 73 |
+
setNewColForm({ name: '', description: '' });
|
| 74 |
+
fetchData();
|
| 75 |
+
} catch (e) {
|
| 76 |
+
console.error("Collection creation failed", e);
|
| 77 |
+
}
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
const handleDeleteAsset = async (id) => {
|
| 81 |
+
if (!confirm('Permanent delete this asset?')) return;
|
| 82 |
+
try {
|
| 83 |
+
await AssetService.deleteAsset(id);
|
| 84 |
+
fetchData();
|
| 85 |
+
} catch (e) {
|
| 86 |
+
console.error("Delete failed", e);
|
| 87 |
+
}
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
const filteredAssets = assets.filter(a => {
|
| 91 |
+
const matchesCategory = activeCategory === 'all' || a.category === activeCategory;
|
| 92 |
+
const matchesSearch = a.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
| 93 |
+
(a.description && a.description.toLowerCase().includes(searchQuery.toLowerCase())) ||
|
| 94 |
+
(a.tags && a.tags.some(t => t.toLowerCase().includes(searchQuery.toLowerCase())));
|
| 95 |
+
return matchesCategory && matchesSearch;
|
| 96 |
+
});
|
| 97 |
+
|
| 98 |
+
const getIcon = (category) => {
|
| 99 |
+
switch(category) {
|
| 100 |
+
case 'images': return <ImageIcon size={20} className="text-purple-400" />;
|
| 101 |
+
case 'audio': return <Music size={20} className="text-pink-400" />;
|
| 102 |
+
case 'video': return <Video size={20} className="text-orange-400" />;
|
| 103 |
+
default: return <File size={20} className="text-blue-400" />;
|
| 104 |
+
}
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
return (
|
| 108 |
+
<div className="flex-1 flex flex-col bg-[#1e1e1e] overflow-hidden">
|
| 109 |
+
{/* Header */}
|
| 110 |
+
<div className="h-14 border-b border-[#333333] flex items-center justify-between px-6 bg-[#252526]">
|
| 111 |
+
<div className="flex items-center space-x-4">
|
| 112 |
+
<h1 className="text-lg font-medium text-white">Media Hub</h1>
|
| 113 |
+
<div className="h-6 w-px bg-[#333333]" />
|
| 114 |
+
<div className="flex space-x-2">
|
| 115 |
+
{['all', 'documents', 'images', 'audio', 'video'].map(cat => (
|
| 116 |
+
<button
|
| 117 |
+
key={cat}
|
| 118 |
+
onClick={() => setActiveCategory(cat)}
|
| 119 |
+
className={`px-3 py-1 text-xs capitalize rounded-full transition ${activeCategory === cat ? 'bg-[#0e639c] text-white' : 'text-zinc-500 hover:text-zinc-300 bg-[#2d2d2d]'}`}
|
| 120 |
+
>
|
| 121 |
+
{cat}
|
| 122 |
+
</button>
|
| 123 |
+
))}
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
<div className="flex items-center space-x-3">
|
| 127 |
+
<div className="relative">
|
| 128 |
+
<Search size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500" />
|
| 129 |
+
<input
|
| 130 |
+
type="text"
|
| 131 |
+
placeholder="Search assets, tags, descriptions..."
|
| 132 |
+
className="bg-[#1e1e1e] border border-[#3c3c3c] text-white text-xs pl-9 pr-3 py-1.5 rounded-md w-64 outline-none focus:border-[#0e639c]"
|
| 133 |
+
value={searchQuery}
|
| 134 |
+
onChange={e => setSearchQuery(e.target.value)}
|
| 135 |
+
/>
|
| 136 |
+
</div>
|
| 137 |
+
<button
|
| 138 |
+
onClick={() => setShowUploadModal(true)}
|
| 139 |
+
className="bg-[#0e639c] hover:bg-[#1177bb] text-white px-4 py-1.5 text-xs rounded flex items-center space-x-2 transition shadow-sm"
|
| 140 |
+
>
|
| 141 |
+
<Upload size={14} />
|
| 142 |
+
<span>Upload Asset</span>
|
| 143 |
+
</button>
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
|
| 147 |
+
<div className="flex-1 flex overflow-hidden">
|
| 148 |
+
{/* Sidebar: Collections */}
|
| 149 |
+
<div className="w-64 border-r border-[#333333] bg-[#252526] flex flex-col p-4">
|
| 150 |
+
<div className="flex items-center justify-between mb-4">
|
| 151 |
+
<h3 className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider">Collections</h3>
|
| 152 |
+
<button onClick={() => setShowNewCollectionModal(true)} className="text-zinc-500 hover:text-white"><Plus size={16}/></button>
|
| 153 |
+
</div>
|
| 154 |
+
<div className="flex-1 overflow-y-auto space-y-1">
|
| 155 |
+
<button
|
| 156 |
+
onClick={() => setActiveCollectionId(null)}
|
| 157 |
+
className={`w-full flex items-center space-x-2 px-3 py-2 rounded text-xs transition ${!activeCollectionId ? 'bg-[#37373d] text-white' : 'text-zinc-400 hover:bg-[#2d2d2d] hover:text-zinc-200'}`}
|
| 158 |
+
>
|
| 159 |
+
<Folder size={14} />
|
| 160 |
+
<span>All Assets</span>
|
| 161 |
+
</button>
|
| 162 |
+
{collections.map(col => (
|
| 163 |
+
<button
|
| 164 |
+
key={col.id}
|
| 165 |
+
onClick={() => setActiveCollectionId(col.id)}
|
| 166 |
+
className={`w-full flex items-center justify-between px-3 py-2 rounded text-xs transition ${activeCollectionId === col.id ? 'bg-[#37373d] text-white' : 'text-zinc-400 hover:bg-[#2d2d2d] hover:text-zinc-200'}`}
|
| 167 |
+
>
|
| 168 |
+
<div className="flex items-center space-x-2">
|
| 169 |
+
<Folder size={14} />
|
| 170 |
+
<span>{col.name}</span>
|
| 171 |
+
</div>
|
| 172 |
+
</button>
|
| 173 |
+
))}
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
{/* Main Grid */}
|
| 178 |
+
<div className="flex-1 overflow-y-auto p-6">
|
| 179 |
+
{isLoading ? (
|
| 180 |
+
<div className="flex items-center justify-center h-64">
|
| 181 |
+
<Upload size={48} className="text-[#333333] animate-pulse" />
|
| 182 |
+
</div>
|
| 183 |
+
) : filteredAssets.length === 0 ? (
|
| 184 |
+
<div className="flex flex-col items-center justify-center h-64 opacity-50">
|
| 185 |
+
<ImageIcon size={64} className="mb-4 text-zinc-700" />
|
| 186 |
+
<p className="text-zinc-500">No assets found in this category.</p>
|
| 187 |
+
</div>
|
| 188 |
+
) : (
|
| 189 |
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
| 190 |
+
{filteredAssets.map(asset => (
|
| 191 |
+
<div key={asset.id} className="bg-[#252526] border border-[#333333] rounded-lg group hover:border-[#444444] transition overflow-hidden">
|
| 192 |
+
<div className="h-32 bg-[#1e1e1e] flex items-center justify-center relative overflow-hidden">
|
| 193 |
+
{asset.category === 'images' ? (
|
| 194 |
+
<div className="w-full h-full bg-cover bg-center opacity-40 group-hover:opacity-60 transition" style={{ backgroundImage: `url(${import.meta.env.VITE_BACKEND_URL}/uploads/${asset.path})` }} />
|
| 195 |
+
) : (
|
| 196 |
+
<div className="text-zinc-700 opacity-20 uppercase font-black text-4xl select-none">{asset.type.split('/')[1]}</div>
|
| 197 |
+
)}
|
| 198 |
+
<div className="absolute inset-0 flex items-center justify-center">
|
| 199 |
+
{getIcon(asset.category)}
|
| 200 |
+
</div>
|
| 201 |
+
</div>
|
| 202 |
+
<div className="p-3 space-y-2">
|
| 203 |
+
<div className="flex items-start justify-between">
|
| 204 |
+
<div className="truncate pr-4">
|
| 205 |
+
<div className="text-xs font-medium text-white truncate" title={asset.name}>{asset.name}</div>
|
| 206 |
+
<div className="text-[10px] text-zinc-500 mt-0.5">{(asset.size / 1024).toFixed(1)} KB • {asset.type.split('/')[1]}</div>
|
| 207 |
+
</div>
|
| 208 |
+
<button onClick={() => handleDeleteAsset(asset.id)} className="text-zinc-600 hover:text-red-400 transition opacity-0 group-hover:opacity-100">
|
| 209 |
+
<Trash2 size={14} />
|
| 210 |
+
</button>
|
| 211 |
+
</div>
|
| 212 |
+
{asset.description && (
|
| 213 |
+
<p className="text-[10px] text-zinc-400 line-clamp-2 italic leading-relaxed">"{asset.description}"</p>
|
| 214 |
+
)}
|
| 215 |
+
{asset.tags && asset.tags.length > 0 && (
|
| 216 |
+
<div className="flex flex-wrap gap-1 pt-1">
|
| 217 |
+
{asset.tags.map(tag => (
|
| 218 |
+
<span key={tag} className="bg-[#1e1e1e] border border-[#333333] text-[#9cdcfe] text-[9px] px-1.5 py-0.5 rounded flex items-center space-x-1">
|
| 219 |
+
<Tags size={8} />
|
| 220 |
+
<span>{tag}</span>
|
| 221 |
+
</span>
|
| 222 |
+
))}
|
| 223 |
+
</div>
|
| 224 |
+
)}
|
| 225 |
+
</div>
|
| 226 |
+
</div>
|
| 227 |
+
))}
|
| 228 |
+
</div>
|
| 229 |
+
)}
|
| 230 |
+
</div>
|
| 231 |
+
</div>
|
| 232 |
+
|
| 233 |
+
{/* Upload Modal */}
|
| 234 |
+
{showUploadModal && (
|
| 235 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
|
| 236 |
+
<div className="bg-[#252526] border border-[#333333] rounded-lg shadow-2xl w-full max-w-lg overflow-hidden animate-in fade-in zoom-in duration-200">
|
| 237 |
+
<div className="p-4 border-b border-[#333333] bg-[#2d2d2d] flex items-center justify-between">
|
| 238 |
+
<h3 className="text-sm font-semibold text-white flex items-center space-x-2">
|
| 239 |
+
<Upload size={16} className="text-[#0e639c]" />
|
| 240 |
+
<span>Upload New Asset</span>
|
| 241 |
+
</h3>
|
| 242 |
+
<button onClick={() => setShowUploadModal(false)} className="text-zinc-500 hover:text-white transition"><X size={18} /></button>
|
| 243 |
+
</div>
|
| 244 |
+
<div className="p-6 space-y-4">
|
| 245 |
+
<div
|
| 246 |
+
onClick={() => document.getElementById('asset-file-input').click()}
|
| 247 |
+
className="border-2 border-dashed border-[#333333] rounded-lg p-8 flex flex-col items-center justify-center cursor-pointer hover:border-[#0e639c] hover:bg-[#0e639c]/5 transition"
|
| 248 |
+
>
|
| 249 |
+
<input
|
| 250 |
+
id="asset-file-input"
|
| 251 |
+
type="file"
|
| 252 |
+
className="hidden"
|
| 253 |
+
onChange={(e) => setSelectedFile(e.target.files[0])}
|
| 254 |
+
/>
|
| 255 |
+
{selectedFile ? (
|
| 256 |
+
<div className="text-center">
|
| 257 |
+
<Check size={32} className="text-green-500 mb-2 mx-auto" />
|
| 258 |
+
<div className="text-xs text-white font-medium">{selectedFile.name}</div>
|
| 259 |
+
<div className="text-[10px] text-zinc-500 mt-1">{(selectedFile.size / 1024).toFixed(1)} KB</div>
|
| 260 |
+
</div>
|
| 261 |
+
) : (
|
| 262 |
+
<div className="text-center">
|
| 263 |
+
<Upload size={32} className="text-zinc-600 mb-2 mx-auto" />
|
| 264 |
+
<div className="text-xs text-zinc-400">Drag and drop or click to browse</div>
|
| 265 |
+
<div className="text-[10px] text-zinc-600 mt-1 italic">Format reasoning: Images, Audio, Video, Docs</div>
|
| 266 |
+
</div>
|
| 267 |
+
)}
|
| 268 |
+
</div>
|
| 269 |
+
|
| 270 |
+
<div className="space-y-3">
|
| 271 |
+
<div className="space-y-1">
|
| 272 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider">Semantic Description (AI Hint)</label>
|
| 273 |
+
<textarea
|
| 274 |
+
placeholder="Explain what this file is for (e.g. 'This is the Aadhar card used for user identity verification')"
|
| 275 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white p-2.5 text-xs rounded outline-none focus:border-[#0e639c] resize-none h-20"
|
| 276 |
+
value={uploadForm.description}
|
| 277 |
+
onChange={e => setUploadForm({...uploadForm, description: e.target.value})}
|
| 278 |
+
/>
|
| 279 |
+
</div>
|
| 280 |
+
<div className="space-y-1">
|
| 281 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider">Tags (comma separated)</label>
|
| 282 |
+
<div className="relative">
|
| 283 |
+
<Tags size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500" />
|
| 284 |
+
<input
|
| 285 |
+
type="text"
|
| 286 |
+
placeholder="aadhar, identity, personal, legal"
|
| 287 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white pl-10 pr-3 py-2 text-xs rounded outline-none focus:border-[#0e639c]"
|
| 288 |
+
value={uploadForm.tags}
|
| 289 |
+
onChange={e => setUploadForm({...uploadForm, tags: e.target.value})}
|
| 290 |
+
/>
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
| 293 |
+
</div>
|
| 294 |
+
|
| 295 |
+
<button
|
| 296 |
+
onClick={handleFileUpload}
|
| 297 |
+
disabled={!selectedFile || isUploading}
|
| 298 |
+
className="w-full bg-[#0e639c] hover:bg-[#1177bb] disabled:opacity-50 text-white py-2.5 text-sm font-semibold rounded transition flex items-center justify-center space-x-2"
|
| 299 |
+
>
|
| 300 |
+
{isUploading ? <Upload className="animate-spin" size={16} /> : <Check size={16} />}
|
| 301 |
+
<span>{isUploading ? 'Uploading...' : 'Finalize Upload'}</span>
|
| 302 |
+
</button>
|
| 303 |
+
</div>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
)}
|
| 307 |
+
|
| 308 |
+
{/* New Collection Modal */}
|
| 309 |
+
{showNewCollectionModal && (
|
| 310 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
|
| 311 |
+
<div className="bg-[#252526] border border-[#333333] rounded-lg shadow-2xl w-full max-w-sm overflow-hidden animate-in fade-in zoom-in duration-200">
|
| 312 |
+
<div className="p-4 border-b border-[#333333] bg-[#2d2d2d] flex items-center justify-between">
|
| 313 |
+
<h3 className="text-sm font-semibold text-white flex items-center space-x-2">
|
| 314 |
+
<Plus size={16} className="text-green-500" />
|
| 315 |
+
<span>New Collection</span>
|
| 316 |
+
</h3>
|
| 317 |
+
<button onClick={() => setShowNewCollectionModal(false)} className="text-zinc-500 hover:text-white transition"><X size={18} /></button>
|
| 318 |
+
</div>
|
| 319 |
+
<div className="p-6 space-y-4">
|
| 320 |
+
<div className="space-y-3">
|
| 321 |
+
<div className="space-y-1">
|
| 322 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider">Collection Name</label>
|
| 323 |
+
<input
|
| 324 |
+
type="text"
|
| 325 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white px-3 py-2 text-xs rounded outline-none focus:border-[#0e639c]"
|
| 326 |
+
value={newColForm.name}
|
| 327 |
+
onChange={e => setNewColForm({...newColForm, name: e.target.value})}
|
| 328 |
+
/>
|
| 329 |
+
</div>
|
| 330 |
+
<div className="space-y-1">
|
| 331 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider">Description</label>
|
| 332 |
+
<textarea
|
| 333 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white p-2.5 text-xs rounded outline-none focus:border-[#0e639c] resize-none h-20"
|
| 334 |
+
value={newColForm.description}
|
| 335 |
+
onChange={e => setNewColForm({...newColForm, description: e.target.value})}
|
| 336 |
+
/>
|
| 337 |
+
</div>
|
| 338 |
+
</div>
|
| 339 |
+
<button
|
| 340 |
+
onClick={handleCreateCollection}
|
| 341 |
+
className="w-full bg-emerald-600 hover:bg-emerald-700 text-white py-2.5 text-sm font-semibold rounded transition"
|
| 342 |
+
>
|
| 343 |
+
Create Collection
|
| 344 |
+
</button>
|
| 345 |
+
</div>
|
| 346 |
+
</div>
|
| 347 |
+
</div>
|
| 348 |
+
)}
|
| 349 |
+
</div>
|
| 350 |
+
);
|
| 351 |
+
};
|
| 352 |
+
|
| 353 |
+
export default MediaHubPage;
|
frontend-react/src/components/ProfilePage.jsx
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from 'react';
|
| 2 |
+
import { Settings, Save, Trash2, Key, User, Lock, Plus, X, RefreshCw, Server, Database } from 'lucide-react';
|
| 3 |
+
import { useAppContext } from './AppContext';
|
| 4 |
+
|
| 5 |
+
const ProfilePage = () => {
|
| 6 |
+
const {
|
| 7 |
+
activeSpecId, activeSpecName, storedCredentials, saveProfile
|
| 8 |
+
} = useAppContext();
|
| 9 |
+
|
| 10 |
+
const [profileForm, setProfileForm] = useState({ name: '', email: '', password: '', token: '' });
|
| 11 |
+
const [extraKvs, setExtraKvs] = useState([]);
|
| 12 |
+
const [isSaving, setIsSaving] = useState(false);
|
| 13 |
+
|
| 14 |
+
// Sync stored credentials into local form
|
| 15 |
+
useEffect(() => {
|
| 16 |
+
if (!storedCredentials) return;
|
| 17 |
+
|
| 18 |
+
setProfileForm({
|
| 19 |
+
name: storedCredentials.name || '',
|
| 20 |
+
email: storedCredentials.email || storedCredentials.username || '',
|
| 21 |
+
password: '', // Don't prefill password
|
| 22 |
+
token: storedCredentials.access_token || storedCredentials.token || ''
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
const standardKeys = new Set(['name', 'email', 'username', 'password', 'access_token', 'token', 'refresh_token', 'id_token']);
|
| 26 |
+
const kvs = Object.entries(storedCredentials)
|
| 27 |
+
.filter(([k, v]) => !standardKeys.has(k) && k !== '_clear')
|
| 28 |
+
.map(([k, v]) => ({ key: k, val: String(v) }));
|
| 29 |
+
setExtraKvs(kvs);
|
| 30 |
+
}, [storedCredentials]);
|
| 31 |
+
|
| 32 |
+
const handleSave = async () => {
|
| 33 |
+
if (!activeSpecId) return;
|
| 34 |
+
setIsSaving(true);
|
| 35 |
+
try {
|
| 36 |
+
const payload = {
|
| 37 |
+
name: profileForm.name,
|
| 38 |
+
username: profileForm.email,
|
| 39 |
+
extra: {}
|
| 40 |
+
};
|
| 41 |
+
if (profileForm.password) payload.password = profileForm.password;
|
| 42 |
+
if (profileForm.token) payload.extra.token = profileForm.token;
|
| 43 |
+
|
| 44 |
+
extraKvs.forEach(kv => {
|
| 45 |
+
if (kv.key && kv.val) payload.extra[kv.key] = kv.val;
|
| 46 |
+
});
|
| 47 |
+
await saveProfile(payload);
|
| 48 |
+
} catch (err) {
|
| 49 |
+
console.error("Save failed", err);
|
| 50 |
+
alert("Failed to save profile.");
|
| 51 |
+
} finally {
|
| 52 |
+
setIsSaving(false);
|
| 53 |
+
}
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
if (!activeSpecId) {
|
| 57 |
+
return (
|
| 58 |
+
<div className="flex-1 flex flex-col items-center justify-center p-8 text-center bg-[#1e1e1e] animate-in fade-in duration-500">
|
| 59 |
+
<div className="p-8 bg-[#252526] border border-[#333333] rounded-3xl shadow-2xl max-w-md w-full animate-in zoom-in duration-300">
|
| 60 |
+
<div className="w-16 h-16 bg-[#1e1e1e] border border-[#3c3c3c] rounded-2xl flex items-center justify-center mx-auto mb-6">
|
| 61 |
+
<Server size={32} className="text-zinc-700" />
|
| 62 |
+
</div>
|
| 63 |
+
<h2 className="text-2xl font-semibold text-white mb-2">No Collection Selected</h2>
|
| 64 |
+
<p className="text-zinc-500 text-sm mb-8 leading-relaxed">
|
| 65 |
+
Test user profiles are isolated per collection. Please select an API specification first to manage its credentials.
|
| 66 |
+
</p>
|
| 67 |
+
<button
|
| 68 |
+
onClick={() => window.dispatchEvent(new CustomEvent('nav-change', { detail: 'collections' }))}
|
| 69 |
+
className="w-full py-3 bg-[#0e639c] hover:bg-[#1177bb] text-white text-sm font-bold rounded-xl transition shadow-lg flex items-center justify-center space-x-2"
|
| 70 |
+
>
|
| 71 |
+
<Database size={16} />
|
| 72 |
+
<span>Browse Collections</span>
|
| 73 |
+
</button>
|
| 74 |
+
</div>
|
| 75 |
+
</div>
|
| 76 |
+
);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
return (
|
| 80 |
+
<div className="flex-1 flex flex-col bg-[#1e1e1e] overflow-hidden animate-in fade-in slide-in-from-bottom-2 duration-300">
|
| 81 |
+
{/* Header */}
|
| 82 |
+
<div className="h-14 border-b border-[#333333] flex items-center justify-between px-6 bg-[#252526]">
|
| 83 |
+
<div className="flex items-center space-x-4">
|
| 84 |
+
<h1 className="text-lg font-medium text-white flex items-center space-x-2">
|
| 85 |
+
<Settings size={20} className="text-[#519aba]" />
|
| 86 |
+
<span>Test User Profile</span>
|
| 87 |
+
</h1>
|
| 88 |
+
<div className="h-6 w-px bg-[#333333]" />
|
| 89 |
+
<div className="text-xs text-zinc-500">
|
| 90 |
+
Current Spec: <span className="text-[#9cdcfe] font-mono">{activeSpecName}</span>
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
<button
|
| 94 |
+
onClick={handleSave}
|
| 95 |
+
disabled={isSaving}
|
| 96 |
+
className="bg-emerald-600 hover:bg-emerald-700 text-white px-6 py-1.5 text-xs font-semibold rounded-lg flex items-center space-x-2 transition shadow-lg disabled:opacity-50"
|
| 97 |
+
>
|
| 98 |
+
{isSaving ? <RefreshCw size={14} className="animate-spin" /> : <Save size={14} />}
|
| 99 |
+
<span>Save Profile</span>
|
| 100 |
+
</button>
|
| 101 |
+
</div>
|
| 102 |
+
|
| 103 |
+
<div className="flex-1 overflow-y-auto p-8">
|
| 104 |
+
<div className="max-w-3xl mx-auto space-y-8">
|
| 105 |
+
{/* Core Credentials */}
|
| 106 |
+
<section className="space-y-4">
|
| 107 |
+
<div className="flex items-center space-x-3 mb-6">
|
| 108 |
+
<div className="p-2 bg-[#0e639c]/10 border border-[#0e639c]/20 rounded-lg">
|
| 109 |
+
<Lock size={18} className="text-[#0e639c]" />
|
| 110 |
+
</div>
|
| 111 |
+
<h3 className="text-sm font-semibold text-zinc-300">Core Authentication</h3>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 bg-[#252526] p-6 rounded-2xl border border-[#333333] shadow-sm">
|
| 115 |
+
<div className="space-y-2">
|
| 116 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider flex items-center gap-2">
|
| 117 |
+
Full Name
|
| 118 |
+
</label>
|
| 119 |
+
<input
|
| 120 |
+
type="text"
|
| 121 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white p-2.5 text-sm rounded-lg outline-none focus:border-[#0e639c] transition-colors"
|
| 122 |
+
value={profileForm.name}
|
| 123 |
+
onChange={e => setProfileForm({...profileForm, name: e.target.value})}
|
| 124 |
+
placeholder="e.g. John Doe"
|
| 125 |
+
/>
|
| 126 |
+
</div>
|
| 127 |
+
<div className="space-y-2">
|
| 128 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider flex items-center gap-2">
|
| 129 |
+
Email / Username
|
| 130 |
+
</label>
|
| 131 |
+
<input
|
| 132 |
+
type="text"
|
| 133 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white p-2.5 text-sm rounded-lg outline-none focus:border-[#0e639c] transition-colors"
|
| 134 |
+
value={profileForm.email}
|
| 135 |
+
onChange={e => setProfileForm({...profileForm, email: e.target.value})}
|
| 136 |
+
placeholder="e.g. john.doe@example.com"
|
| 137 |
+
/>
|
| 138 |
+
</div>
|
| 139 |
+
<div className="space-y-2">
|
| 140 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider flex items-center gap-2">
|
| 141 |
+
Password
|
| 142 |
+
</label>
|
| 143 |
+
<input
|
| 144 |
+
type="password"
|
| 145 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white p-2.5 text-sm rounded-lg outline-none focus:border-[#0e639c] transition-colors"
|
| 146 |
+
value={profileForm.password}
|
| 147 |
+
onChange={e => setProfileForm({...profileForm, password: e.target.value})}
|
| 148 |
+
placeholder="Leave blank to keep current"
|
| 149 |
+
/>
|
| 150 |
+
</div>
|
| 151 |
+
<div className="space-y-2">
|
| 152 |
+
<label className="text-[10px] uppercase font-bold text-zinc-500 tracking-wider flex items-center gap-2">
|
| 153 |
+
Static Access Token
|
| 154 |
+
</label>
|
| 155 |
+
<input
|
| 156 |
+
type="text"
|
| 157 |
+
className="w-full bg-[#1e1e1e] border border-[#3c3c3c] text-white p-2.5 text-sm rounded-lg outline-none focus:border-[#0e639c] transition-colors"
|
| 158 |
+
value={profileForm.token}
|
| 159 |
+
onChange={e => setProfileForm({...profileForm, token: e.target.value})}
|
| 160 |
+
placeholder="Skip login flow with a manual token"
|
| 161 |
+
/>
|
| 162 |
+
</div>
|
| 163 |
+
</div>
|
| 164 |
+
</section>
|
| 165 |
+
|
| 166 |
+
{/* Extra Variables */}
|
| 167 |
+
<section className="space-y-4">
|
| 168 |
+
<div className="flex items-center justify-between mb-4 px-1">
|
| 169 |
+
<div className="flex items-center space-x-3">
|
| 170 |
+
<div className="p-2 bg-emerald-500/10 border border-emerald-500/20 rounded-lg">
|
| 171 |
+
<Key size={18} className="text-emerald-500" />
|
| 172 |
+
</div>
|
| 173 |
+
<h3 className="text-sm font-semibold text-zinc-300">Custom Fields & Context</h3>
|
| 174 |
+
</div>
|
| 175 |
+
<button
|
| 176 |
+
onClick={() => setExtraKvs([...extraKvs, {key: '', val: ''}])}
|
| 177 |
+
className="text-xs bg-[#2d2d2d] hover:bg-[#3d3d3d] text-zinc-300 px-3 py-1.5 rounded-lg border border-[#3c3c3c] flex items-center gap-1.5 transition shadow-sm"
|
| 178 |
+
>
|
| 179 |
+
<Plus size={14} />
|
| 180 |
+
<span>Add Variables</span>
|
| 181 |
+
</button>
|
| 182 |
+
</div>
|
| 183 |
+
|
| 184 |
+
{extraKvs.length === 0 ? (
|
| 185 |
+
<div className="py-16 bg-[#252526] border-2 border-dashed border-[#333333] rounded-2xl text-center shadow-inner">
|
| 186 |
+
<p className="text-zinc-600 text-sm italic">No custom variables defined. Use these for OTPs, User IDs, or custom test data pointers.</p>
|
| 187 |
+
</div>
|
| 188 |
+
) : (
|
| 189 |
+
<div className="grid grid-cols-1 gap-3">
|
| 190 |
+
{extraKvs.map((kv, i) => (
|
| 191 |
+
<div key={i} className="flex space-x-3 group animate-in slide-in-from-left-2 duration-300">
|
| 192 |
+
<div className="flex-1 bg-[#252526] border border-[#3c3c3c] rounded-xl overflow-hidden shadow-sm flex items-center group-hover:border-[#444444] transition-colors">
|
| 193 |
+
<div className="bg-[#1e1e1e] border-r border-[#3c3c3c] px-3 py-2 flex items-center justify-center">
|
| 194 |
+
<span className="text-[10px] text-zinc-600 font-bold uppercase tracking-tighter w-4 text-center">KV</span>
|
| 195 |
+
</div>
|
| 196 |
+
<input
|
| 197 |
+
type="text"
|
| 198 |
+
placeholder="Key"
|
| 199 |
+
className="w-1/3 bg-transparent border-r border-[#3c3c3c] text-[#9cdcfe] px-4 py-2.5 text-xs outline-none focus:bg-[#2d2d2d] transition-colors font-mono"
|
| 200 |
+
value={kv.key}
|
| 201 |
+
onChange={e => { const n = [...extraKvs]; n[i].key = e.target.value; setExtraKvs(n); }}
|
| 202 |
+
/>
|
| 203 |
+
<input
|
| 204 |
+
type="text"
|
| 205 |
+
placeholder="Value"
|
| 206 |
+
className="flex-1 bg-transparent text-[#ce9178] px-4 py-2.5 text-xs outline-none focus:bg-[#2d2d2d] transition-colors font-mono"
|
| 207 |
+
value={kv.val}
|
| 208 |
+
onChange={e => { const n = [...extraKvs]; n[i].val = e.target.value; setExtraKvs(n); }}
|
| 209 |
+
/>
|
| 210 |
+
</div>
|
| 211 |
+
<button
|
| 212 |
+
onClick={() => setExtraKvs(extraKvs.filter((_, idx) => idx !== i))}
|
| 213 |
+
className="text-zinc-600 hover:text-red-400 p-2 opacity-0 group-hover:opacity-100 transition-all self-center"
|
| 214 |
+
>
|
| 215 |
+
<Trash2 size={16} />
|
| 216 |
+
</button>
|
| 217 |
+
</div>
|
| 218 |
+
))}
|
| 219 |
+
</div>
|
| 220 |
+
)}
|
| 221 |
+
</section>
|
| 222 |
+
</div>
|
| 223 |
+
</div>
|
| 224 |
+
</div>
|
| 225 |
+
);
|
| 226 |
+
};
|
| 227 |
+
|
| 228 |
+
export default ProfilePage;
|
frontend-react/src/index.css
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import "tailwindcss";
|
| 2 |
+
|
| 3 |
+
@layer base {
|
| 4 |
+
body {
|
| 5 |
+
@apply bg-zinc-900 text-zinc-100 antialiased overflow-hidden;
|
| 6 |
+
}
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
/* Custom scrollbar for webkit */
|
| 10 |
+
::-webkit-scrollbar {
|
| 11 |
+
width: 8px;
|
| 12 |
+
height: 8px;
|
| 13 |
+
}
|
| 14 |
+
::-webkit-scrollbar-track {
|
| 15 |
+
background: transparent;
|
| 16 |
+
}
|
| 17 |
+
::-webkit-scrollbar-thumb {
|
| 18 |
+
@apply bg-zinc-700/50 rounded-full;
|
| 19 |
+
}
|
| 20 |
+
::-webkit-scrollbar-thumb:hover {
|
| 21 |
+
@apply bg-zinc-600;
|
| 22 |
+
}
|
frontend-react/src/main.jsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StrictMode } from 'react'
|
| 2 |
+
import { createRoot } from 'react-dom/client'
|
| 3 |
+
import './index.css'
|
| 4 |
+
import App from './App.jsx'
|
| 5 |
+
|
| 6 |
+
createRoot(document.getElementById('root')).render(
|
| 7 |
+
<StrictMode>
|
| 8 |
+
<App />
|
| 9 |
+
</StrictMode>,
|
| 10 |
+
)
|
frontend-react/src/services/api.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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 |
+
export const SpecService = {
|
| 11 |
+
getAllSpecs: async () => {
|
| 12 |
+
const response = await api.get('/specs');
|
| 13 |
+
return response.data;
|
| 14 |
+
},
|
| 15 |
+
getSpec: async (id) => {
|
| 16 |
+
const response = await api.get(`/specs/${id}`);
|
| 17 |
+
return response.data;
|
| 18 |
+
},
|
| 19 |
+
deleteSpec: async (id) => {
|
| 20 |
+
const response = await api.delete(`/specs/${id}`);
|
| 21 |
+
return response.data;
|
| 22 |
+
},
|
| 23 |
+
uploadSpec: async (file) => {
|
| 24 |
+
const formData = new FormData();
|
| 25 |
+
formData.append('file', file);
|
| 26 |
+
const response = await api.post('/upload-spec', formData, {
|
| 27 |
+
headers: { 'Content-Type': 'multipart/form-data' },
|
| 28 |
+
});
|
| 29 |
+
return response.data;
|
| 30 |
+
},
|
| 31 |
+
updateBaseUrl: async (id, baseUrl) => {
|
| 32 |
+
const response = await api.patch(`/specs/${id}`, { base_url: baseUrl });
|
| 33 |
+
return response.data;
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
export const SessionService = {
|
| 38 |
+
createSession: async () => {
|
| 39 |
+
const response = await api.post('/session');
|
| 40 |
+
return response.data;
|
| 41 |
+
},
|
| 42 |
+
clearSession: async (id) => {
|
| 43 |
+
const response = await api.delete(`/session/${id}`);
|
| 44 |
+
return response.data;
|
| 45 |
+
},
|
| 46 |
+
getContext: async (id) => {
|
| 47 |
+
const response = await api.get(`/context/${id}`);
|
| 48 |
+
return response.data;
|
| 49 |
+
}
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
export const PlanService = {
|
| 53 |
+
generatePlan: async (payload) => {
|
| 54 |
+
const response = await api.post('/plan', payload);
|
| 55 |
+
return response.data;
|
| 56 |
+
},
|
| 57 |
+
executeStep: async (payload) => {
|
| 58 |
+
const response = await api.post('/execute-step', payload);
|
| 59 |
+
return response.data;
|
| 60 |
+
},
|
| 61 |
+
analyzeResponse: async (payload) => {
|
| 62 |
+
const response = await api.post('/analyze-response', payload);
|
| 63 |
+
return response.data;
|
| 64 |
+
}
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
export const CredentialService = {
|
| 68 |
+
getCredentials: async (specId) => {
|
| 69 |
+
const response = await api.get(`/specs/${specId}/credentials`);
|
| 70 |
+
return response.data;
|
| 71 |
+
},
|
| 72 |
+
saveCredentials: async (specId, payload) => {
|
| 73 |
+
const response = await api.post(`/specs/${specId}/credentials`, payload);
|
| 74 |
+
return response.data;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
export const AssetService = {
|
| 79 |
+
uploadAsset: async (specId, file, description = '', tags = []) => {
|
| 80 |
+
const formData = new FormData();
|
| 81 |
+
if (specId) formData.append('spec_id', specId);
|
| 82 |
+
formData.append('file', file);
|
| 83 |
+
formData.append('description', description);
|
| 84 |
+
formData.append('tags', JSON.stringify(tags));
|
| 85 |
+
const response = await api.post('/assets', formData, {
|
| 86 |
+
headers: { 'Content-Type': 'multipart/form-data' },
|
| 87 |
+
});
|
| 88 |
+
return response.data;
|
| 89 |
+
},
|
| 90 |
+
getAllAssets: async (specId = null, category = null) => {
|
| 91 |
+
const params = {};
|
| 92 |
+
if (specId) params.spec_id = specId;
|
| 93 |
+
if (category) params.category = category;
|
| 94 |
+
const response = await api.get('/assets', { params });
|
| 95 |
+
return response.data;
|
| 96 |
+
},
|
| 97 |
+
deleteAsset: async (id) => {
|
| 98 |
+
const response = await api.delete(`/assets/${id}`);
|
| 99 |
+
return response.data;
|
| 100 |
+
},
|
| 101 |
+
// Collections
|
| 102 |
+
getCollections: async () => {
|
| 103 |
+
const response = await api.get('/collections');
|
| 104 |
+
return response.data;
|
| 105 |
+
},
|
| 106 |
+
createCollection: async (name, description = '') => {
|
| 107 |
+
const formData = new FormData();
|
| 108 |
+
formData.append('name', name);
|
| 109 |
+
formData.append('description', description);
|
| 110 |
+
const response = await api.post('/collections', formData);
|
| 111 |
+
return response.data;
|
| 112 |
+
},
|
| 113 |
+
addToCollection: async (collectionId, asset_id) => {
|
| 114 |
+
const response = await api.post(`/collections/${collectionId}/assets/${asset_id}`);
|
| 115 |
+
return response.data;
|
| 116 |
+
}
|
| 117 |
+
};
|
| 118 |
+
|
| 119 |
+
export const HistoryService = {
|
| 120 |
+
getHistory: async () => {
|
| 121 |
+
const response = await api.get('/history');
|
| 122 |
+
return response.data;
|
| 123 |
+
},
|
| 124 |
+
async deleteHistorySession(sessionId) {
|
| 125 |
+
const response = await api.delete(`/history/${sessionId}`);
|
| 126 |
+
return response.data;
|
| 127 |
+
},
|
| 128 |
+
async clearAllHistory() {
|
| 129 |
+
const response = await api.delete('/history');
|
| 130 |
+
return response.data;
|
| 131 |
+
}
|
| 132 |
+
};
|
frontend-react/vite.config.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from 'vite'
|
| 2 |
+
import react from '@vitejs/plugin-react'
|
| 3 |
+
import tailwindcore from '@tailwindcss/vite'
|
| 4 |
+
|
| 5 |
+
// https://vite.dev/config/
|
| 6 |
+
export default defineConfig({
|
| 7 |
+
plugins: [react(), tailwindcore()],
|
| 8 |
+
})
|
openapi.yaml
ADDED
|
@@ -0,0 +1,1078 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openapi: 3.0.1
|
| 2 |
+
info:
|
| 3 |
+
title: The ParaBank REST API
|
| 4 |
+
description: This API provides access to various ParaBank internal operations
|
| 5 |
+
termsOfService: /parabank/about.htm
|
| 6 |
+
contact:
|
| 7 |
+
name: ParaBank Web Administrator
|
| 8 |
+
url: http://www.parasoft.com
|
| 9 |
+
email: webadmin@parabank.parasoft.com
|
| 10 |
+
license:
|
| 11 |
+
name: Apache 2.0
|
| 12 |
+
url: http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
version: 3.0.0
|
| 14 |
+
servers:
|
| 15 |
+
- url: /parabank/services/bank
|
| 16 |
+
tags:
|
| 17 |
+
- name: Accounts
|
| 18 |
+
description: account centric operations
|
| 19 |
+
- name: Customers
|
| 20 |
+
description: customer centric operations
|
| 21 |
+
- name: Database
|
| 22 |
+
description: data management operations
|
| 23 |
+
- name: JMS
|
| 24 |
+
description: message service operations
|
| 25 |
+
- name: Loans
|
| 26 |
+
description: request loan operations
|
| 27 |
+
- name: Misc
|
| 28 |
+
description: miscelaneous operations
|
| 29 |
+
- name: Positions
|
| 30 |
+
description: stock centric operations
|
| 31 |
+
- name: Transactions
|
| 32 |
+
description: banking transactions centric operations
|
| 33 |
+
paths:
|
| 34 |
+
/billpay:
|
| 35 |
+
post:
|
| 36 |
+
tags:
|
| 37 |
+
- Accounts
|
| 38 |
+
summary: Pay bill
|
| 39 |
+
operationId: billPay
|
| 40 |
+
parameters:
|
| 41 |
+
- name: accountId
|
| 42 |
+
in: query
|
| 43 |
+
description: Bill payment source account
|
| 44 |
+
required: true
|
| 45 |
+
schema:
|
| 46 |
+
type: integer
|
| 47 |
+
format: int32
|
| 48 |
+
- name: amount
|
| 49 |
+
in: query
|
| 50 |
+
description: Amount
|
| 51 |
+
required: true
|
| 52 |
+
schema:
|
| 53 |
+
type: number
|
| 54 |
+
requestBody:
|
| 55 |
+
description: Payee
|
| 56 |
+
content:
|
| 57 |
+
application/json:
|
| 58 |
+
schema:
|
| 59 |
+
$ref: "#/components/schemas/Payee"
|
| 60 |
+
application/xml:
|
| 61 |
+
schema:
|
| 62 |
+
$ref: "#/components/schemas/Payee"
|
| 63 |
+
required: true
|
| 64 |
+
responses:
|
| 65 |
+
default:
|
| 66 |
+
description: default response
|
| 67 |
+
content:
|
| 68 |
+
application/xml:
|
| 69 |
+
schema:
|
| 70 |
+
$ref: "#/components/schemas/BillPayResult"
|
| 71 |
+
application/json:
|
| 72 |
+
schema:
|
| 73 |
+
$ref: "#/components/schemas/BillPayResult"
|
| 74 |
+
/customers/{customerId}/buyPosition:
|
| 75 |
+
post:
|
| 76 |
+
tags:
|
| 77 |
+
- Positions
|
| 78 |
+
summary: Buy a Position
|
| 79 |
+
operationId: buyPosition
|
| 80 |
+
parameters:
|
| 81 |
+
- name: customerId
|
| 82 |
+
in: path
|
| 83 |
+
description: Customer's id
|
| 84 |
+
required: true
|
| 85 |
+
schema:
|
| 86 |
+
type: integer
|
| 87 |
+
format: int32
|
| 88 |
+
- name: accountId
|
| 89 |
+
in: query
|
| 90 |
+
description: Customer funds source account
|
| 91 |
+
required: true
|
| 92 |
+
schema:
|
| 93 |
+
type: integer
|
| 94 |
+
format: int32
|
| 95 |
+
- name: name
|
| 96 |
+
in: query
|
| 97 |
+
description: Instrument's Name
|
| 98 |
+
required: true
|
| 99 |
+
schema:
|
| 100 |
+
type: string
|
| 101 |
+
- name: symbol
|
| 102 |
+
in: query
|
| 103 |
+
description: Instrument's exchange symbol
|
| 104 |
+
required: true
|
| 105 |
+
schema:
|
| 106 |
+
type: string
|
| 107 |
+
- name: shares
|
| 108 |
+
in: query
|
| 109 |
+
description: number of shares
|
| 110 |
+
required: true
|
| 111 |
+
schema:
|
| 112 |
+
type: integer
|
| 113 |
+
format: int32
|
| 114 |
+
- name: pricePerShare
|
| 115 |
+
in: query
|
| 116 |
+
description: Price of each share
|
| 117 |
+
required: true
|
| 118 |
+
schema:
|
| 119 |
+
type: number
|
| 120 |
+
responses:
|
| 121 |
+
default:
|
| 122 |
+
description: default response
|
| 123 |
+
content:
|
| 124 |
+
application/xml:
|
| 125 |
+
schema:
|
| 126 |
+
type: array
|
| 127 |
+
items:
|
| 128 |
+
$ref: "#/components/schemas/Position"
|
| 129 |
+
application/json:
|
| 130 |
+
schema:
|
| 131 |
+
type: array
|
| 132 |
+
items:
|
| 133 |
+
$ref: "#/components/schemas/Position"
|
| 134 |
+
/cleanDB:
|
| 135 |
+
post:
|
| 136 |
+
tags:
|
| 137 |
+
- Database
|
| 138 |
+
summary: Clean the Database
|
| 139 |
+
operationId: cleanDB
|
| 140 |
+
responses:
|
| 141 |
+
default:
|
| 142 |
+
description: default response
|
| 143 |
+
content:
|
| 144 |
+
application/xml: {}
|
| 145 |
+
application/json: {}
|
| 146 |
+
/createAccount:
|
| 147 |
+
post:
|
| 148 |
+
tags:
|
| 149 |
+
- Customers
|
| 150 |
+
- Accounts
|
| 151 |
+
summary: Create a new account
|
| 152 |
+
operationId: createAccount
|
| 153 |
+
parameters:
|
| 154 |
+
- name: customerId
|
| 155 |
+
in: query
|
| 156 |
+
description: Customer's id
|
| 157 |
+
required: true
|
| 158 |
+
schema:
|
| 159 |
+
type: integer
|
| 160 |
+
format: int32
|
| 161 |
+
- name: newAccountType
|
| 162 |
+
in: query
|
| 163 |
+
description: "Account type (CHECKING, SAVINGS, LOAN)"
|
| 164 |
+
required: true
|
| 165 |
+
schema:
|
| 166 |
+
type: integer
|
| 167 |
+
format: int32
|
| 168 |
+
- name: fromAccountId
|
| 169 |
+
in: query
|
| 170 |
+
description: Customer funds source account
|
| 171 |
+
required: true
|
| 172 |
+
schema:
|
| 173 |
+
type: integer
|
| 174 |
+
format: int32
|
| 175 |
+
responses:
|
| 176 |
+
default:
|
| 177 |
+
description: default response
|
| 178 |
+
content:
|
| 179 |
+
application/xml:
|
| 180 |
+
schema:
|
| 181 |
+
$ref: "#/components/schemas/Account"
|
| 182 |
+
application/json:
|
| 183 |
+
schema:
|
| 184 |
+
$ref: "#/components/schemas/Account"
|
| 185 |
+
/deposit:
|
| 186 |
+
post:
|
| 187 |
+
tags:
|
| 188 |
+
- Accounts
|
| 189 |
+
summary: Deposit funds
|
| 190 |
+
operationId: deposit
|
| 191 |
+
parameters:
|
| 192 |
+
- name: accountId
|
| 193 |
+
in: query
|
| 194 |
+
description: Customer funds target account
|
| 195 |
+
required: true
|
| 196 |
+
schema:
|
| 197 |
+
type: integer
|
| 198 |
+
format: int32
|
| 199 |
+
- name: amount
|
| 200 |
+
in: query
|
| 201 |
+
description: Amount
|
| 202 |
+
required: true
|
| 203 |
+
schema:
|
| 204 |
+
type: number
|
| 205 |
+
responses:
|
| 206 |
+
default:
|
| 207 |
+
description: default response
|
| 208 |
+
content:
|
| 209 |
+
application/xml:
|
| 210 |
+
schema:
|
| 211 |
+
type: string
|
| 212 |
+
application/json:
|
| 213 |
+
schema:
|
| 214 |
+
type: string
|
| 215 |
+
/accounts/{accountId}:
|
| 216 |
+
get:
|
| 217 |
+
tags:
|
| 218 |
+
- Accounts
|
| 219 |
+
summary: Get Account by Id
|
| 220 |
+
operationId: getAccount
|
| 221 |
+
parameters:
|
| 222 |
+
- name: accountId
|
| 223 |
+
in: path
|
| 224 |
+
description: Account id
|
| 225 |
+
required: true
|
| 226 |
+
schema:
|
| 227 |
+
type: integer
|
| 228 |
+
format: int32
|
| 229 |
+
responses:
|
| 230 |
+
default:
|
| 231 |
+
description: default response
|
| 232 |
+
content:
|
| 233 |
+
application/xml:
|
| 234 |
+
schema:
|
| 235 |
+
$ref: "#/components/schemas/Account"
|
| 236 |
+
application/json:
|
| 237 |
+
schema:
|
| 238 |
+
$ref: "#/components/schemas/Account"
|
| 239 |
+
/customers/{customerId}/accounts:
|
| 240 |
+
get:
|
| 241 |
+
tags:
|
| 242 |
+
- Customers
|
| 243 |
+
- Accounts
|
| 244 |
+
summary: Get Customer Accounts
|
| 245 |
+
operationId: getAccounts
|
| 246 |
+
parameters:
|
| 247 |
+
- name: customerId
|
| 248 |
+
in: path
|
| 249 |
+
description: Customer's id
|
| 250 |
+
required: true
|
| 251 |
+
schema:
|
| 252 |
+
type: integer
|
| 253 |
+
format: int32
|
| 254 |
+
responses:
|
| 255 |
+
default:
|
| 256 |
+
description: default response
|
| 257 |
+
content:
|
| 258 |
+
application/xml:
|
| 259 |
+
schema:
|
| 260 |
+
type: array
|
| 261 |
+
items:
|
| 262 |
+
$ref: "#/components/schemas/Account"
|
| 263 |
+
application/json:
|
| 264 |
+
schema:
|
| 265 |
+
type: array
|
| 266 |
+
items:
|
| 267 |
+
$ref: "#/components/schemas/Account"
|
| 268 |
+
/customers/{customerId}:
|
| 269 |
+
get:
|
| 270 |
+
tags:
|
| 271 |
+
- Customers
|
| 272 |
+
summary: Get Customer Details
|
| 273 |
+
operationId: getCustomer
|
| 274 |
+
parameters:
|
| 275 |
+
- name: customerId
|
| 276 |
+
in: path
|
| 277 |
+
description: Customer's id
|
| 278 |
+
required: true
|
| 279 |
+
schema:
|
| 280 |
+
type: integer
|
| 281 |
+
format: int32
|
| 282 |
+
responses:
|
| 283 |
+
default:
|
| 284 |
+
description: default response
|
| 285 |
+
content:
|
| 286 |
+
application/xml:
|
| 287 |
+
schema:
|
| 288 |
+
$ref: "#/components/schemas/Customer"
|
| 289 |
+
application/json:
|
| 290 |
+
schema:
|
| 291 |
+
$ref: "#/components/schemas/Customer"
|
| 292 |
+
/positions/{positionId}:
|
| 293 |
+
get:
|
| 294 |
+
tags:
|
| 295 |
+
- Positions
|
| 296 |
+
summary: Get Position by id
|
| 297 |
+
operationId: getPosition
|
| 298 |
+
parameters:
|
| 299 |
+
- name: positionId
|
| 300 |
+
in: path
|
| 301 |
+
description: Unique identifier for the position
|
| 302 |
+
required: true
|
| 303 |
+
schema:
|
| 304 |
+
type: integer
|
| 305 |
+
format: int32
|
| 306 |
+
responses:
|
| 307 |
+
default:
|
| 308 |
+
description: default response
|
| 309 |
+
content:
|
| 310 |
+
application/xml:
|
| 311 |
+
schema:
|
| 312 |
+
$ref: "#/components/schemas/Position"
|
| 313 |
+
application/json:
|
| 314 |
+
schema:
|
| 315 |
+
$ref: "#/components/schemas/Position"
|
| 316 |
+
/positions/{positionId}/{startDate}/{endDate}:
|
| 317 |
+
get:
|
| 318 |
+
tags:
|
| 319 |
+
- Positions
|
| 320 |
+
summary: Get Position history by id within a date range
|
| 321 |
+
operationId: getPositionHistory
|
| 322 |
+
parameters:
|
| 323 |
+
- name: positionId
|
| 324 |
+
in: path
|
| 325 |
+
description: Unique identifier for the position
|
| 326 |
+
required: true
|
| 327 |
+
schema:
|
| 328 |
+
type: integer
|
| 329 |
+
format: int32
|
| 330 |
+
- name: startDate
|
| 331 |
+
in: path
|
| 332 |
+
description: Search starting date
|
| 333 |
+
required: true
|
| 334 |
+
schema:
|
| 335 |
+
type: string
|
| 336 |
+
- name: endDate
|
| 337 |
+
in: path
|
| 338 |
+
description: Search ending date
|
| 339 |
+
required: true
|
| 340 |
+
schema:
|
| 341 |
+
type: string
|
| 342 |
+
responses:
|
| 343 |
+
default:
|
| 344 |
+
description: default response
|
| 345 |
+
content:
|
| 346 |
+
application/xml:
|
| 347 |
+
schema:
|
| 348 |
+
type: array
|
| 349 |
+
items:
|
| 350 |
+
$ref: "#/components/schemas/HistoryPoint"
|
| 351 |
+
application/json:
|
| 352 |
+
schema:
|
| 353 |
+
type: array
|
| 354 |
+
items:
|
| 355 |
+
$ref: "#/components/schemas/HistoryPoint"
|
| 356 |
+
/customers/{customerId}/positions:
|
| 357 |
+
get:
|
| 358 |
+
tags:
|
| 359 |
+
- Customers
|
| 360 |
+
- Positions
|
| 361 |
+
summary: Get Positions for Customer
|
| 362 |
+
operationId: getPositions
|
| 363 |
+
parameters:
|
| 364 |
+
- name: customerId
|
| 365 |
+
in: path
|
| 366 |
+
description: Customer's id
|
| 367 |
+
required: true
|
| 368 |
+
schema:
|
| 369 |
+
type: integer
|
| 370 |
+
format: int32
|
| 371 |
+
responses:
|
| 372 |
+
default:
|
| 373 |
+
description: default response
|
| 374 |
+
content:
|
| 375 |
+
application/xml:
|
| 376 |
+
schema:
|
| 377 |
+
type: array
|
| 378 |
+
items:
|
| 379 |
+
$ref: "#/components/schemas/Position"
|
| 380 |
+
application/json:
|
| 381 |
+
schema:
|
| 382 |
+
type: array
|
| 383 |
+
items:
|
| 384 |
+
$ref: "#/components/schemas/Position"
|
| 385 |
+
/transactions/{transactionId}:
|
| 386 |
+
get:
|
| 387 |
+
tags:
|
| 388 |
+
- Transactions
|
| 389 |
+
summary: Get the transaction for the id
|
| 390 |
+
operationId: getTransaction
|
| 391 |
+
parameters:
|
| 392 |
+
- name: transactionId
|
| 393 |
+
in: path
|
| 394 |
+
description: Unique identifier for the transaction
|
| 395 |
+
required: true
|
| 396 |
+
schema:
|
| 397 |
+
type: integer
|
| 398 |
+
format: int32
|
| 399 |
+
responses:
|
| 400 |
+
default:
|
| 401 |
+
description: default response
|
| 402 |
+
content:
|
| 403 |
+
application/xml:
|
| 404 |
+
schema:
|
| 405 |
+
$ref: "#/components/schemas/Transaction"
|
| 406 |
+
application/json:
|
| 407 |
+
schema:
|
| 408 |
+
$ref: "#/components/schemas/Transaction"
|
| 409 |
+
/accounts/{accountId}/transactions:
|
| 410 |
+
get:
|
| 411 |
+
tags:
|
| 412 |
+
- Accounts
|
| 413 |
+
- Transactions
|
| 414 |
+
summary: Get the list of Transactions for the account
|
| 415 |
+
operationId: getTransactions
|
| 416 |
+
parameters:
|
| 417 |
+
- name: accountId
|
| 418 |
+
in: path
|
| 419 |
+
description: Account id
|
| 420 |
+
required: true
|
| 421 |
+
schema:
|
| 422 |
+
type: integer
|
| 423 |
+
format: int32
|
| 424 |
+
responses:
|
| 425 |
+
default:
|
| 426 |
+
description: default response
|
| 427 |
+
content:
|
| 428 |
+
application/xml:
|
| 429 |
+
schema:
|
| 430 |
+
type: array
|
| 431 |
+
items:
|
| 432 |
+
$ref: "#/components/schemas/Transaction"
|
| 433 |
+
application/json:
|
| 434 |
+
schema:
|
| 435 |
+
type: array
|
| 436 |
+
items:
|
| 437 |
+
$ref: "#/components/schemas/Transaction"
|
| 438 |
+
/accounts/{accountId}/transactions/amount/{amount}:
|
| 439 |
+
get:
|
| 440 |
+
tags:
|
| 441 |
+
- Accounts
|
| 442 |
+
- Transactions
|
| 443 |
+
summary: Create transactions by amount for account
|
| 444 |
+
operationId: getTransactionsByAmount
|
| 445 |
+
parameters:
|
| 446 |
+
- name: accountId
|
| 447 |
+
in: path
|
| 448 |
+
description: Account id
|
| 449 |
+
required: true
|
| 450 |
+
schema:
|
| 451 |
+
type: integer
|
| 452 |
+
format: int32
|
| 453 |
+
- name: amount
|
| 454 |
+
in: path
|
| 455 |
+
description: Amount
|
| 456 |
+
required: true
|
| 457 |
+
schema:
|
| 458 |
+
type: number
|
| 459 |
+
responses:
|
| 460 |
+
default:
|
| 461 |
+
description: default response
|
| 462 |
+
content:
|
| 463 |
+
application/xml:
|
| 464 |
+
schema:
|
| 465 |
+
type: array
|
| 466 |
+
items:
|
| 467 |
+
$ref: "#/components/schemas/Transaction"
|
| 468 |
+
application/json:
|
| 469 |
+
schema:
|
| 470 |
+
type: array
|
| 471 |
+
items:
|
| 472 |
+
$ref: "#/components/schemas/Transaction"
|
| 473 |
+
/accounts/{accountId}/transactions/month/{month}/type/{type}:
|
| 474 |
+
get:
|
| 475 |
+
tags:
|
| 476 |
+
- Accounts
|
| 477 |
+
- Transactions
|
| 478 |
+
summary: Fetch transactions by month and type for account
|
| 479 |
+
operationId: getTransactionsByMonthAndType
|
| 480 |
+
parameters:
|
| 481 |
+
- name: accountId
|
| 482 |
+
in: path
|
| 483 |
+
description: Account id
|
| 484 |
+
required: true
|
| 485 |
+
schema:
|
| 486 |
+
type: integer
|
| 487 |
+
format: int32
|
| 488 |
+
- name: month
|
| 489 |
+
in: path
|
| 490 |
+
description: Month to use for the search range
|
| 491 |
+
required: true
|
| 492 |
+
schema:
|
| 493 |
+
type: string
|
| 494 |
+
- name: type
|
| 495 |
+
in: path
|
| 496 |
+
description: "Transaction type (CREDIT, DEBIT)"
|
| 497 |
+
required: true
|
| 498 |
+
schema:
|
| 499 |
+
type: string
|
| 500 |
+
responses:
|
| 501 |
+
default:
|
| 502 |
+
description: default response
|
| 503 |
+
content:
|
| 504 |
+
application/xml:
|
| 505 |
+
schema:
|
| 506 |
+
type: array
|
| 507 |
+
items:
|
| 508 |
+
$ref: "#/components/schemas/Transaction"
|
| 509 |
+
application/json:
|
| 510 |
+
schema:
|
| 511 |
+
type: array
|
| 512 |
+
items:
|
| 513 |
+
$ref: "#/components/schemas/Transaction"
|
| 514 |
+
/accounts/{accountId}/transactions/fromDate/{fromDate}/toDate/{toDate}:
|
| 515 |
+
get:
|
| 516 |
+
tags:
|
| 517 |
+
- Accounts
|
| 518 |
+
- Transactions
|
| 519 |
+
summary: Fetch transactions for date range for account
|
| 520 |
+
operationId: getTransactionsByToFromDate
|
| 521 |
+
parameters:
|
| 522 |
+
- name: accountId
|
| 523 |
+
in: path
|
| 524 |
+
description: Account id
|
| 525 |
+
required: true
|
| 526 |
+
schema:
|
| 527 |
+
type: integer
|
| 528 |
+
format: int32
|
| 529 |
+
- name: fromDate
|
| 530 |
+
in: path
|
| 531 |
+
description: Search starting date
|
| 532 |
+
required: true
|
| 533 |
+
schema:
|
| 534 |
+
type: string
|
| 535 |
+
- name: toDate
|
| 536 |
+
in: path
|
| 537 |
+
description: Search ending date
|
| 538 |
+
required: true
|
| 539 |
+
schema:
|
| 540 |
+
type: string
|
| 541 |
+
responses:
|
| 542 |
+
default:
|
| 543 |
+
description: default response
|
| 544 |
+
content:
|
| 545 |
+
application/xml:
|
| 546 |
+
schema:
|
| 547 |
+
type: array
|
| 548 |
+
items:
|
| 549 |
+
$ref: "#/components/schemas/Transaction"
|
| 550 |
+
application/json:
|
| 551 |
+
schema:
|
| 552 |
+
type: array
|
| 553 |
+
items:
|
| 554 |
+
$ref: "#/components/schemas/Transaction"
|
| 555 |
+
/accounts/{accountId}/transactions/onDate/{onDate}:
|
| 556 |
+
get:
|
| 557 |
+
tags:
|
| 558 |
+
- Accounts
|
| 559 |
+
- Transactions
|
| 560 |
+
summary: Fetch transactions for a specific date for account
|
| 561 |
+
operationId: getTransactionsOnDate
|
| 562 |
+
parameters:
|
| 563 |
+
- name: accountId
|
| 564 |
+
in: path
|
| 565 |
+
description: Account id
|
| 566 |
+
required: true
|
| 567 |
+
schema:
|
| 568 |
+
type: integer
|
| 569 |
+
format: int32
|
| 570 |
+
- name: onDate
|
| 571 |
+
in: path
|
| 572 |
+
description: Search specific date
|
| 573 |
+
required: true
|
| 574 |
+
schema:
|
| 575 |
+
type: string
|
| 576 |
+
responses:
|
| 577 |
+
default:
|
| 578 |
+
description: default response
|
| 579 |
+
content:
|
| 580 |
+
application/xml:
|
| 581 |
+
schema:
|
| 582 |
+
type: array
|
| 583 |
+
items:
|
| 584 |
+
$ref: "#/components/schemas/Transaction"
|
| 585 |
+
application/json:
|
| 586 |
+
schema:
|
| 587 |
+
type: array
|
| 588 |
+
items:
|
| 589 |
+
$ref: "#/components/schemas/Transaction"
|
| 590 |
+
/initializeDB:
|
| 591 |
+
post:
|
| 592 |
+
tags:
|
| 593 |
+
- Database
|
| 594 |
+
summary: Initialize the Database
|
| 595 |
+
operationId: initializeDB
|
| 596 |
+
responses:
|
| 597 |
+
default:
|
| 598 |
+
description: default response
|
| 599 |
+
content:
|
| 600 |
+
application/xml: {}
|
| 601 |
+
application/json: {}
|
| 602 |
+
/login/{username}/{password}:
|
| 603 |
+
get:
|
| 604 |
+
tags:
|
| 605 |
+
- Misc
|
| 606 |
+
summary: Login (john/demo)
|
| 607 |
+
operationId: login
|
| 608 |
+
parameters:
|
| 609 |
+
- name: username
|
| 610 |
+
in: path
|
| 611 |
+
description: Customer's user name
|
| 612 |
+
required: true
|
| 613 |
+
schema:
|
| 614 |
+
type: string
|
| 615 |
+
- name: password
|
| 616 |
+
in: path
|
| 617 |
+
description: Customer's password
|
| 618 |
+
required: true
|
| 619 |
+
schema:
|
| 620 |
+
type: string
|
| 621 |
+
responses:
|
| 622 |
+
default:
|
| 623 |
+
description: default response
|
| 624 |
+
content:
|
| 625 |
+
application/xml:
|
| 626 |
+
schema:
|
| 627 |
+
$ref: "#/components/schemas/Customer"
|
| 628 |
+
application/json:
|
| 629 |
+
schema:
|
| 630 |
+
$ref: "#/components/schemas/Customer"
|
| 631 |
+
/requestLoan:
|
| 632 |
+
post:
|
| 633 |
+
tags:
|
| 634 |
+
- Loans
|
| 635 |
+
summary: Request a loan
|
| 636 |
+
operationId: requestLoan
|
| 637 |
+
parameters:
|
| 638 |
+
- name: customerId
|
| 639 |
+
in: query
|
| 640 |
+
description: Customer's id
|
| 641 |
+
required: true
|
| 642 |
+
schema:
|
| 643 |
+
type: integer
|
| 644 |
+
format: int32
|
| 645 |
+
- name: amount
|
| 646 |
+
in: query
|
| 647 |
+
description: Amount
|
| 648 |
+
required: true
|
| 649 |
+
schema:
|
| 650 |
+
type: number
|
| 651 |
+
- name: downPayment
|
| 652 |
+
in: query
|
| 653 |
+
description: Downpayment for the loan
|
| 654 |
+
required: true
|
| 655 |
+
schema:
|
| 656 |
+
type: number
|
| 657 |
+
- name: fromAccountId
|
| 658 |
+
in: query
|
| 659 |
+
description: Customer funds source account
|
| 660 |
+
required: true
|
| 661 |
+
schema:
|
| 662 |
+
type: integer
|
| 663 |
+
format: int32
|
| 664 |
+
responses:
|
| 665 |
+
default:
|
| 666 |
+
description: default response
|
| 667 |
+
content:
|
| 668 |
+
application/xml:
|
| 669 |
+
schema:
|
| 670 |
+
$ref: "#/components/schemas/LoanResponse"
|
| 671 |
+
application/json:
|
| 672 |
+
schema:
|
| 673 |
+
$ref: "#/components/schemas/LoanResponse"
|
| 674 |
+
/customers/{customerId}/sellPosition:
|
| 675 |
+
post:
|
| 676 |
+
tags:
|
| 677 |
+
- Positions
|
| 678 |
+
summary: Sell a Position
|
| 679 |
+
operationId: sellPosition
|
| 680 |
+
parameters:
|
| 681 |
+
- name: customerId
|
| 682 |
+
in: path
|
| 683 |
+
description: Customer's id
|
| 684 |
+
required: true
|
| 685 |
+
schema:
|
| 686 |
+
type: integer
|
| 687 |
+
format: int32
|
| 688 |
+
- name: accountId
|
| 689 |
+
in: query
|
| 690 |
+
description: Customer funds target account
|
| 691 |
+
required: true
|
| 692 |
+
schema:
|
| 693 |
+
type: integer
|
| 694 |
+
format: int32
|
| 695 |
+
- name: positionId
|
| 696 |
+
in: query
|
| 697 |
+
description: Unique identifier for the position
|
| 698 |
+
required: true
|
| 699 |
+
schema:
|
| 700 |
+
type: integer
|
| 701 |
+
format: int32
|
| 702 |
+
- name: shares
|
| 703 |
+
in: query
|
| 704 |
+
description: number of shares
|
| 705 |
+
required: true
|
| 706 |
+
schema:
|
| 707 |
+
type: integer
|
| 708 |
+
format: int32
|
| 709 |
+
- name: pricePerShare
|
| 710 |
+
in: query
|
| 711 |
+
description: Price of each share
|
| 712 |
+
required: true
|
| 713 |
+
schema:
|
| 714 |
+
type: number
|
| 715 |
+
responses:
|
| 716 |
+
default:
|
| 717 |
+
description: default response
|
| 718 |
+
content:
|
| 719 |
+
application/xml:
|
| 720 |
+
schema:
|
| 721 |
+
type: array
|
| 722 |
+
items:
|
| 723 |
+
$ref: "#/components/schemas/Position"
|
| 724 |
+
application/json:
|
| 725 |
+
schema:
|
| 726 |
+
type: array
|
| 727 |
+
items:
|
| 728 |
+
$ref: "#/components/schemas/Position"
|
| 729 |
+
/setParameter/{name}/{value}:
|
| 730 |
+
post:
|
| 731 |
+
tags:
|
| 732 |
+
- Misc
|
| 733 |
+
summary: Set Parameters
|
| 734 |
+
operationId: setParameter
|
| 735 |
+
parameters:
|
| 736 |
+
- name: name
|
| 737 |
+
in: path
|
| 738 |
+
description: Parameter Name
|
| 739 |
+
required: true
|
| 740 |
+
schema:
|
| 741 |
+
type: string
|
| 742 |
+
- name: value
|
| 743 |
+
in: path
|
| 744 |
+
description: Parameter Value
|
| 745 |
+
required: true
|
| 746 |
+
schema:
|
| 747 |
+
type: string
|
| 748 |
+
responses:
|
| 749 |
+
default:
|
| 750 |
+
description: default response
|
| 751 |
+
content:
|
| 752 |
+
application/xml: {}
|
| 753 |
+
application/json: {}
|
| 754 |
+
/shutdownJmsListener:
|
| 755 |
+
post:
|
| 756 |
+
tags:
|
| 757 |
+
- JMS
|
| 758 |
+
summary: Stop JMS Listener
|
| 759 |
+
operationId: shutdownJmsListener
|
| 760 |
+
responses:
|
| 761 |
+
default:
|
| 762 |
+
description: default response
|
| 763 |
+
content:
|
| 764 |
+
application/xml: {}
|
| 765 |
+
application/json: {}
|
| 766 |
+
/startupJmsListener:
|
| 767 |
+
post:
|
| 768 |
+
tags:
|
| 769 |
+
- JMS
|
| 770 |
+
summary: Start JMS Listener
|
| 771 |
+
operationId: startupJmsListener
|
| 772 |
+
responses:
|
| 773 |
+
default:
|
| 774 |
+
description: default response
|
| 775 |
+
content:
|
| 776 |
+
application/xml: {}
|
| 777 |
+
application/json: {}
|
| 778 |
+
/transfer:
|
| 779 |
+
post:
|
| 780 |
+
tags:
|
| 781 |
+
- Accounts
|
| 782 |
+
summary: Transfer funds
|
| 783 |
+
operationId: transfer
|
| 784 |
+
parameters:
|
| 785 |
+
- name: fromAccountId
|
| 786 |
+
in: query
|
| 787 |
+
description: Customer funds source account
|
| 788 |
+
required: true
|
| 789 |
+
schema:
|
| 790 |
+
type: integer
|
| 791 |
+
format: int32
|
| 792 |
+
- name: toAccountId
|
| 793 |
+
in: query
|
| 794 |
+
description: Customer funds target account
|
| 795 |
+
required: true
|
| 796 |
+
schema:
|
| 797 |
+
type: integer
|
| 798 |
+
format: int32
|
| 799 |
+
- name: amount
|
| 800 |
+
in: query
|
| 801 |
+
description: Amount
|
| 802 |
+
required: true
|
| 803 |
+
schema:
|
| 804 |
+
type: number
|
| 805 |
+
responses:
|
| 806 |
+
default:
|
| 807 |
+
description: default response
|
| 808 |
+
content:
|
| 809 |
+
application/xml:
|
| 810 |
+
schema:
|
| 811 |
+
type: string
|
| 812 |
+
application/json:
|
| 813 |
+
schema:
|
| 814 |
+
type: string
|
| 815 |
+
/customers/update/{customerId}:
|
| 816 |
+
post:
|
| 817 |
+
tags:
|
| 818 |
+
- Customers
|
| 819 |
+
summary: Update customer information
|
| 820 |
+
operationId: updateCustomer
|
| 821 |
+
parameters:
|
| 822 |
+
- name: customerId
|
| 823 |
+
in: path
|
| 824 |
+
description: Customer's id
|
| 825 |
+
required: true
|
| 826 |
+
schema:
|
| 827 |
+
type: integer
|
| 828 |
+
format: int32
|
| 829 |
+
- name: firstName
|
| 830 |
+
in: query
|
| 831 |
+
description: Customer's given (first) name
|
| 832 |
+
required: true
|
| 833 |
+
schema:
|
| 834 |
+
type: string
|
| 835 |
+
- name: lastName
|
| 836 |
+
in: query
|
| 837 |
+
description: Customer's surname (last name)
|
| 838 |
+
required: true
|
| 839 |
+
schema:
|
| 840 |
+
type: string
|
| 841 |
+
- name: street
|
| 842 |
+
in: query
|
| 843 |
+
description: Street Address including bilding number and apartment (if any)
|
| 844 |
+
required: true
|
| 845 |
+
schema:
|
| 846 |
+
type: string
|
| 847 |
+
- name: city
|
| 848 |
+
in: query
|
| 849 |
+
description: City
|
| 850 |
+
required: true
|
| 851 |
+
schema:
|
| 852 |
+
type: string
|
| 853 |
+
- name: state
|
| 854 |
+
in: query
|
| 855 |
+
description: US state or Region name
|
| 856 |
+
required: true
|
| 857 |
+
schema:
|
| 858 |
+
type: string
|
| 859 |
+
- name: zipCode
|
| 860 |
+
in: query
|
| 861 |
+
description: ZIP code or province id
|
| 862 |
+
required: true
|
| 863 |
+
schema:
|
| 864 |
+
type: string
|
| 865 |
+
- name: phoneNumber
|
| 866 |
+
in: query
|
| 867 |
+
description: Contact Phone Number
|
| 868 |
+
required: true
|
| 869 |
+
schema:
|
| 870 |
+
type: string
|
| 871 |
+
- name: ssn
|
| 872 |
+
in: query
|
| 873 |
+
description: Social Security Number
|
| 874 |
+
required: true
|
| 875 |
+
schema:
|
| 876 |
+
type: string
|
| 877 |
+
- name: username
|
| 878 |
+
in: query
|
| 879 |
+
description: Customer's user name
|
| 880 |
+
required: true
|
| 881 |
+
schema:
|
| 882 |
+
type: string
|
| 883 |
+
- name: password
|
| 884 |
+
in: query
|
| 885 |
+
description: Customer's password
|
| 886 |
+
required: true
|
| 887 |
+
schema:
|
| 888 |
+
type: string
|
| 889 |
+
responses:
|
| 890 |
+
default:
|
| 891 |
+
description: default response
|
| 892 |
+
content:
|
| 893 |
+
application/xml:
|
| 894 |
+
schema:
|
| 895 |
+
type: string
|
| 896 |
+
application/json:
|
| 897 |
+
schema:
|
| 898 |
+
type: string
|
| 899 |
+
/withdraw:
|
| 900 |
+
post:
|
| 901 |
+
tags:
|
| 902 |
+
- Accounts
|
| 903 |
+
summary: Withdraw funds
|
| 904 |
+
operationId: withdraw
|
| 905 |
+
parameters:
|
| 906 |
+
- name: accountId
|
| 907 |
+
in: query
|
| 908 |
+
description: Customer funds source account
|
| 909 |
+
required: true
|
| 910 |
+
schema:
|
| 911 |
+
type: integer
|
| 912 |
+
format: int32
|
| 913 |
+
- name: amount
|
| 914 |
+
in: query
|
| 915 |
+
description: Amount
|
| 916 |
+
required: true
|
| 917 |
+
schema:
|
| 918 |
+
type: number
|
| 919 |
+
responses:
|
| 920 |
+
default:
|
| 921 |
+
description: default response
|
| 922 |
+
content:
|
| 923 |
+
application/xml:
|
| 924 |
+
schema:
|
| 925 |
+
type: string
|
| 926 |
+
application/json:
|
| 927 |
+
schema:
|
| 928 |
+
type: string
|
| 929 |
+
components:
|
| 930 |
+
schemas:
|
| 931 |
+
BillPayResult:
|
| 932 |
+
type: object
|
| 933 |
+
properties:
|
| 934 |
+
payeeName:
|
| 935 |
+
type: string
|
| 936 |
+
amount:
|
| 937 |
+
type: number
|
| 938 |
+
accountId:
|
| 939 |
+
type: integer
|
| 940 |
+
format: int32
|
| 941 |
+
xml:
|
| 942 |
+
name: billPayResult
|
| 943 |
+
Address:
|
| 944 |
+
type: object
|
| 945 |
+
properties:
|
| 946 |
+
street:
|
| 947 |
+
type: string
|
| 948 |
+
city:
|
| 949 |
+
type: string
|
| 950 |
+
state:
|
| 951 |
+
type: string
|
| 952 |
+
zipCode:
|
| 953 |
+
type: string
|
| 954 |
+
Payee:
|
| 955 |
+
type: object
|
| 956 |
+
properties:
|
| 957 |
+
name:
|
| 958 |
+
type: string
|
| 959 |
+
address:
|
| 960 |
+
$ref: "#/components/schemas/Address"
|
| 961 |
+
phoneNumber:
|
| 962 |
+
type: string
|
| 963 |
+
accountNumber:
|
| 964 |
+
type: integer
|
| 965 |
+
format: int32
|
| 966 |
+
Position:
|
| 967 |
+
type: object
|
| 968 |
+
properties:
|
| 969 |
+
positionId:
|
| 970 |
+
type: integer
|
| 971 |
+
format: int32
|
| 972 |
+
customerId:
|
| 973 |
+
type: integer
|
| 974 |
+
format: int32
|
| 975 |
+
name:
|
| 976 |
+
type: string
|
| 977 |
+
symbol:
|
| 978 |
+
type: string
|
| 979 |
+
shares:
|
| 980 |
+
type: integer
|
| 981 |
+
format: int32
|
| 982 |
+
purchasePrice:
|
| 983 |
+
type: number
|
| 984 |
+
xml:
|
| 985 |
+
name: position
|
| 986 |
+
Account:
|
| 987 |
+
type: object
|
| 988 |
+
properties:
|
| 989 |
+
id:
|
| 990 |
+
type: integer
|
| 991 |
+
format: int32
|
| 992 |
+
customerId:
|
| 993 |
+
type: integer
|
| 994 |
+
format: int32
|
| 995 |
+
type:
|
| 996 |
+
type: string
|
| 997 |
+
enum:
|
| 998 |
+
- CHECKING
|
| 999 |
+
- SAVINGS
|
| 1000 |
+
- LOAN
|
| 1001 |
+
balance:
|
| 1002 |
+
type: number
|
| 1003 |
+
xml:
|
| 1004 |
+
name: account
|
| 1005 |
+
Customer:
|
| 1006 |
+
type: object
|
| 1007 |
+
properties:
|
| 1008 |
+
id:
|
| 1009 |
+
type: integer
|
| 1010 |
+
format: int32
|
| 1011 |
+
firstName:
|
| 1012 |
+
type: string
|
| 1013 |
+
lastName:
|
| 1014 |
+
type: string
|
| 1015 |
+
address:
|
| 1016 |
+
$ref: "#/components/schemas/Address"
|
| 1017 |
+
phoneNumber:
|
| 1018 |
+
type: string
|
| 1019 |
+
ssn:
|
| 1020 |
+
type: string
|
| 1021 |
+
xml:
|
| 1022 |
+
name: customer
|
| 1023 |
+
HistoryPoint:
|
| 1024 |
+
type: object
|
| 1025 |
+
properties:
|
| 1026 |
+
symbol:
|
| 1027 |
+
type: string
|
| 1028 |
+
date:
|
| 1029 |
+
type: string
|
| 1030 |
+
format: date-time
|
| 1031 |
+
closingPrice:
|
| 1032 |
+
type: number
|
| 1033 |
+
xml:
|
| 1034 |
+
name: historyPoint
|
| 1035 |
+
namespace: http://service.parabank.parasoft.com/
|
| 1036 |
+
Transaction:
|
| 1037 |
+
type: object
|
| 1038 |
+
properties:
|
| 1039 |
+
id:
|
| 1040 |
+
type: integer
|
| 1041 |
+
format: int32
|
| 1042 |
+
accountId:
|
| 1043 |
+
type: integer
|
| 1044 |
+
format: int32
|
| 1045 |
+
type:
|
| 1046 |
+
type: string
|
| 1047 |
+
enum:
|
| 1048 |
+
- Credit
|
| 1049 |
+
- Debit
|
| 1050 |
+
date:
|
| 1051 |
+
type: string
|
| 1052 |
+
format: date-time
|
| 1053 |
+
amount:
|
| 1054 |
+
type: number
|
| 1055 |
+
description:
|
| 1056 |
+
type: string
|
| 1057 |
+
xml:
|
| 1058 |
+
name: transaction
|
| 1059 |
+
LoanResponse:
|
| 1060 |
+
required:
|
| 1061 |
+
- loanProviderName
|
| 1062 |
+
type: object
|
| 1063 |
+
properties:
|
| 1064 |
+
responseDate:
|
| 1065 |
+
type: string
|
| 1066 |
+
format: date-time
|
| 1067 |
+
loanProviderName:
|
| 1068 |
+
type: string
|
| 1069 |
+
approved:
|
| 1070 |
+
type: boolean
|
| 1071 |
+
message:
|
| 1072 |
+
type: string
|
| 1073 |
+
accountId:
|
| 1074 |
+
type: integer
|
| 1075 |
+
format: int32
|
| 1076 |
+
xml:
|
| 1077 |
+
name: loanResponse
|
| 1078 |
+
namespace: http://service.parabank.parasoft.com/
|
package-lock.json
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ai-api-testing-tool",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"lockfileVersion": 3,
|
| 5 |
+
"requires": true,
|
| 6 |
+
"packages": {
|
| 7 |
+
"": {
|
| 8 |
+
"name": "ai-api-testing-tool",
|
| 9 |
+
"version": "1.0.0",
|
| 10 |
+
"devDependencies": {
|
| 11 |
+
"concurrently": "^8.2.2"
|
| 12 |
+
}
|
| 13 |
+
},
|
| 14 |
+
"node_modules/@babel/runtime": {
|
| 15 |
+
"version": "7.28.6",
|
| 16 |
+
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.6.tgz",
|
| 17 |
+
"integrity": "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA==",
|
| 18 |
+
"dev": true,
|
| 19 |
+
"license": "MIT",
|
| 20 |
+
"engines": {
|
| 21 |
+
"node": ">=6.9.0"
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
"node_modules/ansi-regex": {
|
| 25 |
+
"version": "5.0.1",
|
| 26 |
+
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
| 27 |
+
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
| 28 |
+
"dev": true,
|
| 29 |
+
"license": "MIT",
|
| 30 |
+
"engines": {
|
| 31 |
+
"node": ">=8"
|
| 32 |
+
}
|
| 33 |
+
},
|
| 34 |
+
"node_modules/ansi-styles": {
|
| 35 |
+
"version": "4.3.0",
|
| 36 |
+
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
| 37 |
+
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
| 38 |
+
"dev": true,
|
| 39 |
+
"license": "MIT",
|
| 40 |
+
"dependencies": {
|
| 41 |
+
"color-convert": "^2.0.1"
|
| 42 |
+
},
|
| 43 |
+
"engines": {
|
| 44 |
+
"node": ">=8"
|
| 45 |
+
},
|
| 46 |
+
"funding": {
|
| 47 |
+
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
| 48 |
+
}
|
| 49 |
+
},
|
| 50 |
+
"node_modules/chalk": {
|
| 51 |
+
"version": "4.1.2",
|
| 52 |
+
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
| 53 |
+
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
| 54 |
+
"dev": true,
|
| 55 |
+
"license": "MIT",
|
| 56 |
+
"dependencies": {
|
| 57 |
+
"ansi-styles": "^4.1.0",
|
| 58 |
+
"supports-color": "^7.1.0"
|
| 59 |
+
},
|
| 60 |
+
"engines": {
|
| 61 |
+
"node": ">=10"
|
| 62 |
+
},
|
| 63 |
+
"funding": {
|
| 64 |
+
"url": "https://github.com/chalk/chalk?sponsor=1"
|
| 65 |
+
}
|
| 66 |
+
},
|
| 67 |
+
"node_modules/chalk/node_modules/supports-color": {
|
| 68 |
+
"version": "7.2.0",
|
| 69 |
+
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
| 70 |
+
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
| 71 |
+
"dev": true,
|
| 72 |
+
"license": "MIT",
|
| 73 |
+
"dependencies": {
|
| 74 |
+
"has-flag": "^4.0.0"
|
| 75 |
+
},
|
| 76 |
+
"engines": {
|
| 77 |
+
"node": ">=8"
|
| 78 |
+
}
|
| 79 |
+
},
|
| 80 |
+
"node_modules/cliui": {
|
| 81 |
+
"version": "8.0.1",
|
| 82 |
+
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
| 83 |
+
"integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
|
| 84 |
+
"dev": true,
|
| 85 |
+
"license": "ISC",
|
| 86 |
+
"dependencies": {
|
| 87 |
+
"string-width": "^4.2.0",
|
| 88 |
+
"strip-ansi": "^6.0.1",
|
| 89 |
+
"wrap-ansi": "^7.0.0"
|
| 90 |
+
},
|
| 91 |
+
"engines": {
|
| 92 |
+
"node": ">=12"
|
| 93 |
+
}
|
| 94 |
+
},
|
| 95 |
+
"node_modules/color-convert": {
|
| 96 |
+
"version": "2.0.1",
|
| 97 |
+
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
| 98 |
+
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
| 99 |
+
"dev": true,
|
| 100 |
+
"license": "MIT",
|
| 101 |
+
"dependencies": {
|
| 102 |
+
"color-name": "~1.1.4"
|
| 103 |
+
},
|
| 104 |
+
"engines": {
|
| 105 |
+
"node": ">=7.0.0"
|
| 106 |
+
}
|
| 107 |
+
},
|
| 108 |
+
"node_modules/color-name": {
|
| 109 |
+
"version": "1.1.4",
|
| 110 |
+
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
| 111 |
+
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
| 112 |
+
"dev": true,
|
| 113 |
+
"license": "MIT"
|
| 114 |
+
},
|
| 115 |
+
"node_modules/concurrently": {
|
| 116 |
+
"version": "8.2.2",
|
| 117 |
+
"resolved": "https://registry.npmjs.org/concurrently/-/concurrently-8.2.2.tgz",
|
| 118 |
+
"integrity": "sha512-1dP4gpXFhei8IOtlXRE/T/4H88ElHgTiUzh71YUmtjTEHMSRS2Z/fgOxHSxxusGHogsRfxNq1vyAwxSC+EVyDg==",
|
| 119 |
+
"dev": true,
|
| 120 |
+
"license": "MIT",
|
| 121 |
+
"dependencies": {
|
| 122 |
+
"chalk": "^4.1.2",
|
| 123 |
+
"date-fns": "^2.30.0",
|
| 124 |
+
"lodash": "^4.17.21",
|
| 125 |
+
"rxjs": "^7.8.1",
|
| 126 |
+
"shell-quote": "^1.8.1",
|
| 127 |
+
"spawn-command": "0.0.2",
|
| 128 |
+
"supports-color": "^8.1.1",
|
| 129 |
+
"tree-kill": "^1.2.2",
|
| 130 |
+
"yargs": "^17.7.2"
|
| 131 |
+
},
|
| 132 |
+
"bin": {
|
| 133 |
+
"conc": "dist/bin/concurrently.js",
|
| 134 |
+
"concurrently": "dist/bin/concurrently.js"
|
| 135 |
+
},
|
| 136 |
+
"engines": {
|
| 137 |
+
"node": "^14.13.0 || >=16.0.0"
|
| 138 |
+
},
|
| 139 |
+
"funding": {
|
| 140 |
+
"url": "https://github.com/open-cli-tools/concurrently?sponsor=1"
|
| 141 |
+
}
|
| 142 |
+
},
|
| 143 |
+
"node_modules/date-fns": {
|
| 144 |
+
"version": "2.30.0",
|
| 145 |
+
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
|
| 146 |
+
"integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
|
| 147 |
+
"dev": true,
|
| 148 |
+
"license": "MIT",
|
| 149 |
+
"dependencies": {
|
| 150 |
+
"@babel/runtime": "^7.21.0"
|
| 151 |
+
},
|
| 152 |
+
"engines": {
|
| 153 |
+
"node": ">=0.11"
|
| 154 |
+
},
|
| 155 |
+
"funding": {
|
| 156 |
+
"type": "opencollective",
|
| 157 |
+
"url": "https://opencollective.com/date-fns"
|
| 158 |
+
}
|
| 159 |
+
},
|
| 160 |
+
"node_modules/emoji-regex": {
|
| 161 |
+
"version": "8.0.0",
|
| 162 |
+
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
| 163 |
+
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
|
| 164 |
+
"dev": true,
|
| 165 |
+
"license": "MIT"
|
| 166 |
+
},
|
| 167 |
+
"node_modules/escalade": {
|
| 168 |
+
"version": "3.2.0",
|
| 169 |
+
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
|
| 170 |
+
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
|
| 171 |
+
"dev": true,
|
| 172 |
+
"license": "MIT",
|
| 173 |
+
"engines": {
|
| 174 |
+
"node": ">=6"
|
| 175 |
+
}
|
| 176 |
+
},
|
| 177 |
+
"node_modules/get-caller-file": {
|
| 178 |
+
"version": "2.0.5",
|
| 179 |
+
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
| 180 |
+
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
|
| 181 |
+
"dev": true,
|
| 182 |
+
"license": "ISC",
|
| 183 |
+
"engines": {
|
| 184 |
+
"node": "6.* || 8.* || >= 10.*"
|
| 185 |
+
}
|
| 186 |
+
},
|
| 187 |
+
"node_modules/has-flag": {
|
| 188 |
+
"version": "4.0.0",
|
| 189 |
+
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
| 190 |
+
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
| 191 |
+
"dev": true,
|
| 192 |
+
"license": "MIT",
|
| 193 |
+
"engines": {
|
| 194 |
+
"node": ">=8"
|
| 195 |
+
}
|
| 196 |
+
},
|
| 197 |
+
"node_modules/is-fullwidth-code-point": {
|
| 198 |
+
"version": "3.0.0",
|
| 199 |
+
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
| 200 |
+
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
| 201 |
+
"dev": true,
|
| 202 |
+
"license": "MIT",
|
| 203 |
+
"engines": {
|
| 204 |
+
"node": ">=8"
|
| 205 |
+
}
|
| 206 |
+
},
|
| 207 |
+
"node_modules/lodash": {
|
| 208 |
+
"version": "4.17.23",
|
| 209 |
+
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.23.tgz",
|
| 210 |
+
"integrity": "sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==",
|
| 211 |
+
"dev": true,
|
| 212 |
+
"license": "MIT"
|
| 213 |
+
},
|
| 214 |
+
"node_modules/require-directory": {
|
| 215 |
+
"version": "2.1.1",
|
| 216 |
+
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
| 217 |
+
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
|
| 218 |
+
"dev": true,
|
| 219 |
+
"license": "MIT",
|
| 220 |
+
"engines": {
|
| 221 |
+
"node": ">=0.10.0"
|
| 222 |
+
}
|
| 223 |
+
},
|
| 224 |
+
"node_modules/rxjs": {
|
| 225 |
+
"version": "7.8.2",
|
| 226 |
+
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
|
| 227 |
+
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
| 228 |
+
"dev": true,
|
| 229 |
+
"license": "Apache-2.0",
|
| 230 |
+
"dependencies": {
|
| 231 |
+
"tslib": "^2.1.0"
|
| 232 |
+
}
|
| 233 |
+
},
|
| 234 |
+
"node_modules/shell-quote": {
|
| 235 |
+
"version": "1.8.3",
|
| 236 |
+
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.3.tgz",
|
| 237 |
+
"integrity": "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==",
|
| 238 |
+
"dev": true,
|
| 239 |
+
"license": "MIT",
|
| 240 |
+
"engines": {
|
| 241 |
+
"node": ">= 0.4"
|
| 242 |
+
},
|
| 243 |
+
"funding": {
|
| 244 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 245 |
+
}
|
| 246 |
+
},
|
| 247 |
+
"node_modules/spawn-command": {
|
| 248 |
+
"version": "0.0.2",
|
| 249 |
+
"resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz",
|
| 250 |
+
"integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ==",
|
| 251 |
+
"dev": true
|
| 252 |
+
},
|
| 253 |
+
"node_modules/string-width": {
|
| 254 |
+
"version": "4.2.3",
|
| 255 |
+
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
| 256 |
+
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
| 257 |
+
"dev": true,
|
| 258 |
+
"license": "MIT",
|
| 259 |
+
"dependencies": {
|
| 260 |
+
"emoji-regex": "^8.0.0",
|
| 261 |
+
"is-fullwidth-code-point": "^3.0.0",
|
| 262 |
+
"strip-ansi": "^6.0.1"
|
| 263 |
+
},
|
| 264 |
+
"engines": {
|
| 265 |
+
"node": ">=8"
|
| 266 |
+
}
|
| 267 |
+
},
|
| 268 |
+
"node_modules/strip-ansi": {
|
| 269 |
+
"version": "6.0.1",
|
| 270 |
+
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
| 271 |
+
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
| 272 |
+
"dev": true,
|
| 273 |
+
"license": "MIT",
|
| 274 |
+
"dependencies": {
|
| 275 |
+
"ansi-regex": "^5.0.1"
|
| 276 |
+
},
|
| 277 |
+
"engines": {
|
| 278 |
+
"node": ">=8"
|
| 279 |
+
}
|
| 280 |
+
},
|
| 281 |
+
"node_modules/supports-color": {
|
| 282 |
+
"version": "8.1.1",
|
| 283 |
+
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
|
| 284 |
+
"integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",
|
| 285 |
+
"dev": true,
|
| 286 |
+
"license": "MIT",
|
| 287 |
+
"dependencies": {
|
| 288 |
+
"has-flag": "^4.0.0"
|
| 289 |
+
},
|
| 290 |
+
"engines": {
|
| 291 |
+
"node": ">=10"
|
| 292 |
+
},
|
| 293 |
+
"funding": {
|
| 294 |
+
"url": "https://github.com/chalk/supports-color?sponsor=1"
|
| 295 |
+
}
|
| 296 |
+
},
|
| 297 |
+
"node_modules/tree-kill": {
|
| 298 |
+
"version": "1.2.2",
|
| 299 |
+
"resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz",
|
| 300 |
+
"integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==",
|
| 301 |
+
"dev": true,
|
| 302 |
+
"license": "MIT",
|
| 303 |
+
"bin": {
|
| 304 |
+
"tree-kill": "cli.js"
|
| 305 |
+
}
|
| 306 |
+
},
|
| 307 |
+
"node_modules/tslib": {
|
| 308 |
+
"version": "2.8.1",
|
| 309 |
+
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
| 310 |
+
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
| 311 |
+
"dev": true,
|
| 312 |
+
"license": "0BSD"
|
| 313 |
+
},
|
| 314 |
+
"node_modules/wrap-ansi": {
|
| 315 |
+
"version": "7.0.0",
|
| 316 |
+
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
| 317 |
+
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
| 318 |
+
"dev": true,
|
| 319 |
+
"license": "MIT",
|
| 320 |
+
"dependencies": {
|
| 321 |
+
"ansi-styles": "^4.0.0",
|
| 322 |
+
"string-width": "^4.1.0",
|
| 323 |
+
"strip-ansi": "^6.0.0"
|
| 324 |
+
},
|
| 325 |
+
"engines": {
|
| 326 |
+
"node": ">=10"
|
| 327 |
+
},
|
| 328 |
+
"funding": {
|
| 329 |
+
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
| 330 |
+
}
|
| 331 |
+
},
|
| 332 |
+
"node_modules/y18n": {
|
| 333 |
+
"version": "5.0.8",
|
| 334 |
+
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
| 335 |
+
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
|
| 336 |
+
"dev": true,
|
| 337 |
+
"license": "ISC",
|
| 338 |
+
"engines": {
|
| 339 |
+
"node": ">=10"
|
| 340 |
+
}
|
| 341 |
+
},
|
| 342 |
+
"node_modules/yargs": {
|
| 343 |
+
"version": "17.7.2",
|
| 344 |
+
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
| 345 |
+
"integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
|
| 346 |
+
"dev": true,
|
| 347 |
+
"license": "MIT",
|
| 348 |
+
"dependencies": {
|
| 349 |
+
"cliui": "^8.0.1",
|
| 350 |
+
"escalade": "^3.1.1",
|
| 351 |
+
"get-caller-file": "^2.0.5",
|
| 352 |
+
"require-directory": "^2.1.1",
|
| 353 |
+
"string-width": "^4.2.3",
|
| 354 |
+
"y18n": "^5.0.5",
|
| 355 |
+
"yargs-parser": "^21.1.1"
|
| 356 |
+
},
|
| 357 |
+
"engines": {
|
| 358 |
+
"node": ">=12"
|
| 359 |
+
}
|
| 360 |
+
},
|
| 361 |
+
"node_modules/yargs-parser": {
|
| 362 |
+
"version": "21.1.1",
|
| 363 |
+
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
|
| 364 |
+
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
|
| 365 |
+
"dev": true,
|
| 366 |
+
"license": "ISC",
|
| 367 |
+
"engines": {
|
| 368 |
+
"node": ">=12"
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
}
|
package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "ai-api-testing-tool",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "AI-powered API testing tool with FastAPI backend and React frontend",
|
| 5 |
+
"private": true,
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "concurrently --names \"BACKEND,FRONTEND\" --prefix-colors \"cyan,magenta\" \"npm run dev:backend\" \"npm run dev:frontend\"",
|
| 8 |
+
"dev:backend": "uvicorn backend.main:app --reload --port 8001",
|
| 9 |
+
"dev:frontend": "npm run dev --prefix frontend-react",
|
| 10 |
+
"setup:frontend": "npm install --prefix frontend-react",
|
| 11 |
+
"setup:backend": "pip install -r requirements.txt",
|
| 12 |
+
"setup": "npm run setup:backend && npm run setup:frontend",
|
| 13 |
+
"build": "npm run build --prefix frontend-react"
|
| 14 |
+
},
|
| 15 |
+
"devDependencies": {
|
| 16 |
+
"concurrently": "^8.2.2"
|
| 17 |
+
}
|
| 18 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi>=0.109.0
|
| 2 |
+
uvicorn[standard]>=0.27.0
|
| 3 |
+
pydantic>=2.6.0
|
| 4 |
+
streamlit==1.28.2
|
| 5 |
+
httpx==0.25.1
|
| 6 |
+
python-dotenv==1.0.0
|
| 7 |
+
mistralai==0.4.2
|
| 8 |
+
sqlalchemy==2.0.23
|
| 9 |
+
python-multipart==0.0.6
|
| 10 |
+
langchain==0.1.0
|
| 11 |
+
langchain-mistralai==0.0.1
|
| 12 |
+
gunicorn==21.2.0
|
| 13 |
+
psycopg2-binary==2.9.9
|
runtime.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
python-3.11.7
|
start.ps1
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ============================================================
|
| 2 |
+
# AI API Testing Tool - Dev Startup Script
|
| 3 |
+
# Usage: .\start.ps1
|
| 4 |
+
# ============================================================
|
| 5 |
+
|
| 6 |
+
$ErrorActionPreference = "Stop"
|
| 7 |
+
|
| 8 |
+
Write-Host ""
|
| 9 |
+
Write-Host " AI API Testing Tool" -ForegroundColor Cyan
|
| 10 |
+
Write-Host " ===================" -ForegroundColor Cyan
|
| 11 |
+
Write-Host ""
|
| 12 |
+
|
| 13 |
+
# --- 1. Kill any stale process on port 8001 ---
|
| 14 |
+
Write-Host "[1/3] Checking for processes on port 8001..." -ForegroundColor Yellow
|
| 15 |
+
$stale = netstat -aon | Select-String ":8001 " | Select-String "LISTENING"
|
| 16 |
+
if ($stale) {
|
| 17 |
+
$pid_ = ($stale -split "\s+")[-1]
|
| 18 |
+
Write-Host " Killing stale process (PID $pid_)..." -ForegroundColor DarkYellow
|
| 19 |
+
Stop-Process -Id $pid_ -Force -ErrorAction SilentlyContinue
|
| 20 |
+
Start-Sleep -Seconds 2
|
| 21 |
+
} else {
|
| 22 |
+
Write-Host " Port 8001 is free." -ForegroundColor Green
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# --- 2. Start FastAPI Backend ---
|
| 26 |
+
Write-Host "[2/3] Starting FastAPI backend (port 8001)..." -ForegroundColor Yellow
|
| 27 |
+
$backend = Start-Process -FilePath "cmd.exe" `
|
| 28 |
+
-ArgumentList "/k", "title Backend && python -m uvicorn backend.main:app --reload --port 8001" `
|
| 29 |
+
-WorkingDirectory $PSScriptRoot `
|
| 30 |
+
-PassThru
|
| 31 |
+
|
| 32 |
+
Write-Host " Backend PID: $($backend.Id)" -ForegroundColor Green
|
| 33 |
+
Write-Host " Waiting 8s for backend to initialize..." -ForegroundColor DarkGray
|
| 34 |
+
Start-Sleep -Seconds 8
|
| 35 |
+
|
| 36 |
+
# --- 3. Start React Frontend ---
|
| 37 |
+
Write-Host "[3/3] Starting React frontend (Vite dev server)..." -ForegroundColor Yellow
|
| 38 |
+
Start-Process -FilePath "cmd.exe" `
|
| 39 |
+
-ArgumentList "/k", "title Frontend && npm run dev" `
|
| 40 |
+
-WorkingDirectory (Join-Path $PSScriptRoot "frontend-react")
|
| 41 |
+
|
| 42 |
+
Write-Host ""
|
| 43 |
+
Write-Host " All services started!" -ForegroundColor Green
|
| 44 |
+
Write-Host ""
|
| 45 |
+
Write-Host " Backend -> http://localhost:8001" -ForegroundColor Cyan
|
| 46 |
+
Write-Host " Frontend -> http://localhost:5173" -ForegroundColor Cyan
|
| 47 |
+
Write-Host " API Docs -> http://localhost:8001/docs" -ForegroundColor Cyan
|
| 48 |
+
Write-Host ""
|