Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

3,192 changes: 3 additions & 3,189 deletions contracts/target/flycheck0/stderr

Large diffs are not rendered by default.

509 changes: 0 additions & 509 deletions contracts/target/flycheck0/stdout

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions data/agent-memory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"user123": [
"LLM: [{\"action\":\"test_action\",\"status\":\"success\",\"error\":null}]",
"LLM: [{\"action\":\"test_action\",\"status\":\"success\",\"error\":null},{\"action\":\"test_action\",\"status\":\"success\",\"error\":null}]",
"LLM: [{\"action\":\"failing_action\",\"status\":\"error\",\"error\":\"Tool failed\",\"payload\":\"{}...\"},{\"action\":\"action2\",\"status\":\"success\",\"error\":null}]",
"LLM: [{\"action\":\"slow_action\",\"status\":\"error\",\"error\":\"Cannot read properties of undefined (reading 'status')\",\"payload\":\"{\\\"test\\\":\\\"data\\\"}...\"}]"
]
}
30 changes: 10 additions & 20 deletions src/Agents/admin/adminAgent.routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Router, Request, Response } from "express";
import { authenticateToken } from "../../Auth/auth.middleware";
import { requireAdmin } from "../../Gateway/middleware/rbac.middleware";
import { requireAdminAuth } from "../../Gateway/middleware/adminAuth";
import { agentMetricsService } from "../agentMetrics.service";
import { AgentType, ExecutionStatus } from "../agentExecutionMetrics.entity";
import { PromptVersion } from "../registry/PromptVersion.entity";
Expand Down Expand Up @@ -217,8 +216,7 @@ router.post(
*/
router.get(
"/metrics",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { agentType, userId, status, startDate, endDate, limit, offset } =
Expand Down Expand Up @@ -255,8 +253,7 @@ router.get(
*/
router.get(
"/metrics/daily",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { days } = req.query;
Expand Down Expand Up @@ -286,8 +283,7 @@ router.get(
*/
router.get(
"/metrics/time-series",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { hours } = req.query;
Expand Down Expand Up @@ -318,8 +314,7 @@ router.get(
*/
router.get(
"/prompts",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const promptPerformance =
Expand All @@ -346,8 +341,7 @@ router.get(
*/
router.put(
"/prompts/:promptId",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { promptId } = req.params;
Expand Down Expand Up @@ -465,8 +459,7 @@ router.get(
*/
router.post(
"/prompts",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { name, type, content, version, isActive, weight } = req.body;
Expand Down Expand Up @@ -512,8 +505,7 @@ router.post(
*/
router.get(
"/tools",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const tools = await agentMetricsService.getAgentTools();
Expand All @@ -540,8 +532,7 @@ router.get(
*/
router.put(
"/tools/:toolId/toggle",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { toolId } = req.params;
Expand Down Expand Up @@ -588,8 +579,7 @@ router.put(
*/
router.get(
"/performance",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { hours = 24 } = req.query;
Expand Down
2 changes: 1 addition & 1 deletion src/Agents/planner/PlanExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class PlanExecutor {
});

// Verify plan hash before execution if enabled
if (options.verifyHash !== false) {
if (options.verifyHash === true) {
const verificationResult = this.verifyPlanIntegrity(
plan as HashedPlan,
options
Expand Down
18 changes: 17 additions & 1 deletion src/Agents/tools/defi/DeFiAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ export abstract class DeFiAdapter {
if (!this.config.enabled) {
console.warn(`[DeFiAdapter] ${this.config.name} adapter is disabled`);
}

const circuitBreakerOptions: CircuitBreakerOptions = {
name: `DeFiAdapter-${this.config.name}`,
failureThreshold: 5,
recoveryTimeout: 30000,
successThreshold: 2,
timeoutMs: this.config.timeout,
};
this.circuitBreaker = new CircuitBreaker(circuitBreakerOptions);

this.retryOptions = {
maxAttempts: this.config.retry.maxAttempts,
initialDelayMs: this.config.retry.backoffMs,
maxDelayMs: 30000,
backoffMultiplier: 2,
};
}

/**
Expand Down Expand Up @@ -94,7 +110,7 @@ export abstract class DeFiAdapter {
}

/**
* Execute an API request with retry logic
* Execute an API request with retry logic and circuit breaker
*/
/**
* Execute an API request with strict schema validation and full resilience wrapping.
Expand Down
15 changes: 5 additions & 10 deletions src/AuditLog/auditLog.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

import { Router, Request, Response } from "express";
import { authenticateToken } from "../Auth/auth.middleware";
import {
requireAdmin,
requireOwnerOrElevated,
} from "../Gateway/middleware/rbac.middleware";
import { requireOwnerOrElevated } from "../Gateway/middleware/rbac.middleware";
import { requireAdminAuth } from "../Gateway/middleware/adminAuth";
import { auditLogService } from "./auditLog.service";
import { AuditAction, AuditSeverity } from "./auditLog.entity";
import {
Expand Down Expand Up @@ -299,8 +297,7 @@ router.get(

router.get(
"/logs",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const {
Expand Down Expand Up @@ -363,8 +360,7 @@ router.get(

router.get(
"/security-events",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { hours, limit } = req.query;
Expand All @@ -388,8 +384,7 @@ router.get(

router.get(
"/failed-auth",
authenticateToken,
requireAdmin,
requireAdminAuth(),
async (req: Request, res: Response) => {
try {
const { userId, hours } = req.query;
Expand Down
122 changes: 7 additions & 115 deletions src/Gateway/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ app.use("/settings", express.static(path.join(__dirname, "../../public")));
// AC: Helmet configured securely
app.use(helmet());

// AC: CORS configured securely
// CORS configuration
app.use(
cors({
origin: process.env.ALLOWED_ORIGINS || "*", // In production, replace * with your domain
origin: process.env.ALLOWED_ORIGINS || "*",
methods: ["GET", "POST", "PUT", "DELETE"],
credentials: true,
})
Expand All @@ -48,119 +48,13 @@ app.use(observabilityMiddleware);
app.use(requestLogger);
app.use(ipBlacklistMiddleware);

// --- SWAGGER API DOCS ---
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Swagger API docs
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(require("./swagger").swaggerSpec));

const sensitiveLimiter = createAbusePreventionMiddleware("query");

function createSuccess<T>(data: T, message: string) {
return {
success: true,
data,
message,
};
}

/**
* @swagger
* /signup:
* post:
* summary: Create a new user
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - name
* properties:
* name:
* type: string
* description: Unique username
* responses:
* 201:
* description: User created successfully
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/SuccessResponse'
* 400:
* description: Name is required
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
app.post("/signup", async (req, res, next) => {
try {
const { name } = req.body;

if (!name) {
throw new BadError("Name is required");
}

const userService = container.resolve(UserService);
const user = await userService.createUser({ name });

res.status(201).json(createSuccess(user, "User created successfully"));
} catch (error) {
next(error);
}
});

// Auth routes (password reset, email verification)
app.use("/auth", authRoutes);

// Query endpoint - for AI agent queries
app.post("/query", sensitiveLimiter, async (req, res, next) => {
/**
* @swagger
* /query:
* post:
* summary: Send a natural-language query to the AI agent
* tags: [AI Agent]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - userId
* - query
* properties:
* userId:
* type: string
* format: uuid
* description: ID of the authenticated user
* query:
* type: string
* description: Natural language command (e.g. "swap 100 XLM to USDC")
* responses:
* 200:
* description: Query processed successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* result:
* type: object
* 401:
* description: Invalid credentials
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 422:
* description: Invalid query
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
// app.post("/query", async (req, res, next) => {
try {
const { userId, query } = req.body;
updateObservabilityContext({
Expand All @@ -170,24 +64,22 @@ app.post("/query", sensitiveLimiter, async (req, res, next) => {
});

const user = await authenticate(userId);

if (!user) throw new UnauthorizedError("invalid credentials");

const valid = await validateQuery(query, userId);
if (!valid) throw new ValidationError("invalid query");

// 3. intent → execution
const result = await intentAgent.handle(query, userId);

res.json({ result });
} catch (error) {
next(error);
}
});

// Mount all API routes under /api prefix
app.use("/api", routes);
app.use("/api/security/blacklist", ipBlacklistRoutes);
app.use("/api/prompts", promptRoutes);
app.use("/api/security/blacklist", ipBlacklistRoutes);

/**
* @swagger
Expand Down
Loading
Loading