Compare commits
55 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
18dd8a7c06 | |
|
|
80e8a712ac | |
|
|
3c0319d50f | |
|
|
8d44ba0824 | |
|
|
1dc9326154 | |
|
|
c848c04ee3 | |
|
|
fee23fcc21 | |
|
|
510e1016f8 | |
|
|
64a04e2535 | |
|
|
c18c4dbd22 | |
|
|
77cfbdeca7 | |
|
|
e0aab1021b | |
|
|
5d07a7f7b8 | |
|
|
6c159d39d4 | |
|
|
cde8eee4fa | |
|
|
f1274b3164 | |
|
|
9225ec3f2a | |
|
|
bef504d756 | |
|
|
75636f0477 | |
|
|
a3dfb81840 | |
|
|
05eb50bd97 | |
|
|
46dd75a7e3 | |
|
|
e692f383c4 | |
|
|
6e5f58e18d | |
|
|
7671312435 | |
|
|
f7aaccec76 | |
|
|
f1277aadf1 | |
|
|
aaf09c5df6 | |
|
|
997c5e7ea7 | |
|
|
92faf8fc2d | |
|
|
7d85dc2b05 | |
|
|
29c9cac4f4 | |
|
|
fe3adbd241 | |
|
|
5445a5c4a9 | |
|
|
39ed523288 | |
|
|
0fe019bc9a | |
|
|
3f28ea80aa | |
|
|
0c40fa72c3 | |
|
|
07c6c2e5b5 | |
|
|
fe3984329d | |
|
|
0a46e3c92b | |
|
|
8a507f245e | |
|
|
af16879dd6 | |
|
|
f29658fee8 | |
|
|
996608e4e3 | |
|
|
262c9f7d77 | |
|
|
d5d250b215 | |
|
|
9f24c6bef9 | |
|
|
1ced6ece4c | |
|
|
a9c7f92687 | |
|
|
4685550605 | |
|
|
a2129641ae | |
|
|
9d585f38b5 | |
|
|
fa66066c07 | |
|
|
c511cefc67 |
|
|
@ -16,3 +16,6 @@ appmap.log
|
|||
*.swp
|
||||
/vsc/node_modules
|
||||
/vsc/dist
|
||||
node_modules/
|
||||
/frontend/common/dist
|
||||
/frontend/web/dist/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
include LICENSE
|
||||
include README.md
|
||||
include CHANGELOG.md
|
||||
recursive-include ra_aid/webui/static *
|
||||
recursive-include ra_aid/server/static *
|
||||
|
|
|
|||
28
README.md
28
README.md
|
|
@ -226,9 +226,9 @@ More information is available in our [Usage Examples](https://docs.ra-aid.ai/cat
|
|||
- `--max-test-cmd-retries`: Maximum number of test command retry attempts (default: 3)
|
||||
- `--test-cmd-timeout`: Timeout in seconds for test command execution (default: 300)
|
||||
- `--version`: Show program version number and exit
|
||||
- `--webui`: Launch the web interface (alpha feature)
|
||||
- `--webui-host`: Host to listen on for web interface (default: 0.0.0.0) (alpha feature)
|
||||
- `--webui-port`: Port to listen on for web interface (default: 8080) (alpha feature)
|
||||
- `--server`: Launch the server with web interface (alpha feature)
|
||||
- `--server-host`: Host to listen on for server (default: 0.0.0.0) (alpha feature)
|
||||
- `--server-port`: Port to listen on for server (default: 1818) (alpha feature)
|
||||
|
||||
### Example Tasks
|
||||
|
||||
|
|
@ -305,30 +305,30 @@ Make sure to set your TAVILY_API_KEY environment variable to enable this feature
|
|||
|
||||
Enable with `--chat` to transform ra-aid into an interactive assistant that guides you through research and implementation tasks. Have a natural conversation about what you want to build, explore options together, and dispatch work - all while maintaining context of your discussion. Perfect for when you want to think through problems collaboratively rather than just executing commands.
|
||||
|
||||
### Web Interface
|
||||
### Server with Web Interface
|
||||
|
||||
RA.Aid includes a modern web interface that provides:
|
||||
RA.Aid includes a modern server with web interface that provides:
|
||||
- Beautiful dark-themed chat interface
|
||||
- Real-time streaming of command output
|
||||
- Request history with quick resubmission
|
||||
- Responsive design that works on all devices
|
||||
|
||||
To launch the web interface:
|
||||
To launch the server with web interface:
|
||||
|
||||
```bash
|
||||
# Start with default settings (0.0.0.0:8080)
|
||||
ra-aid --webui
|
||||
# Start with default settings (0.0.0.0:1818)
|
||||
ra-aid --server
|
||||
|
||||
# Specify custom host and port
|
||||
ra-aid --webui --webui-host 127.0.0.1 --webui-port 3000
|
||||
ra-aid --server --server-host 127.0.0.1 --server-port 3000
|
||||
```
|
||||
|
||||
Command line options for web interface:
|
||||
- `--webui`: Launch the web interface
|
||||
- `--webui-host`: Host to listen on (default: 0.0.0.0)
|
||||
- `--webui-port`: Port to listen on (default: 8080)
|
||||
Command line options for server with web interface:
|
||||
- `--server`: Launch the server with web interface
|
||||
- `--server-host`: Host to listen on (default: 0.0.0.0)
|
||||
- `--server-port`: Port to listen on (default: 1818)
|
||||
|
||||
After starting the server, open your web browser to the displayed URL (e.g., http://localhost:8080). The interface provides:
|
||||
After starting the server, open your web browser to the displayed URL (e.g., http://localhost:1818). The interface provides:
|
||||
- Left sidebar showing request history
|
||||
- Main chat area with real-time output
|
||||
- Input box for typing requests
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "new-york",
|
||||
"rsc": false,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "frontend/common/tailwind.config.js",
|
||||
"css": "frontend/common/src/styles/global.css",
|
||||
"baseColor": "zinc",
|
||||
"cssVariables": true
|
||||
},
|
||||
"aliases": {
|
||||
"components": "@ra-aid/common/components",
|
||||
"utils": "@ra-aid/common/utils"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import * as React from "react";
|
||||
import { type VariantProps } from "class-variance-authority";
|
||||
declare const buttonVariants: (props?: ({
|
||||
variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined;
|
||||
size?: "default" | "sm" | "lg" | "icon" | null | undefined;
|
||||
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
||||
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
||||
export { Button, buttonVariants };
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva } from "class-variance-authority";
|
||||
import { cn } from "../../utils";
|
||||
const buttonVariants = cva("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50", {
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
||||
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
||||
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
||||
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2",
|
||||
sm: "h-8 rounded-md px-3 text-xs",
|
||||
lg: "h-10 rounded-md px-8",
|
||||
icon: "h-9 w-9",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
});
|
||||
const Button = React.forwardRef((_a, ref) => {
|
||||
var { className, variant, size, asChild = false } = _a, props = __rest(_a, ["className", "variant", "size", "asChild"]);
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return (React.createElement(Comp, Object.assign({ className: cn(buttonVariants({ variant, size, className })), ref: ref }, props)));
|
||||
});
|
||||
Button.displayName = "Button";
|
||||
export { Button, buttonVariants };
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import * as React from "react";
|
||||
declare const Card: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
||||
declare const CardHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
||||
declare const CardTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLHeadingElement> & React.RefAttributes<HTMLParagraphElement>>;
|
||||
declare const CardDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
||||
declare const CardContent: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
||||
declare const CardFooter: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from "react";
|
||||
import { cn } from "../../utils";
|
||||
const Card = React.forwardRef((_a, ref) => {
|
||||
var { className } = _a, props = __rest(_a, ["className"]);
|
||||
return (React.createElement("div", Object.assign({ ref: ref, className: cn("rounded-xl border bg-card text-card-foreground shadow", className) }, props)));
|
||||
});
|
||||
Card.displayName = "Card";
|
||||
const CardHeader = React.forwardRef((_a, ref) => {
|
||||
var { className } = _a, props = __rest(_a, ["className"]);
|
||||
return (React.createElement("div", Object.assign({ ref: ref, className: cn("flex flex-col space-y-1.5 p-6", className) }, props)));
|
||||
});
|
||||
CardHeader.displayName = "CardHeader";
|
||||
const CardTitle = React.forwardRef((_a, ref) => {
|
||||
var { className } = _a, props = __rest(_a, ["className"]);
|
||||
return (React.createElement("h3", Object.assign({ ref: ref, className: cn("font-semibold leading-none tracking-tight", className) }, props)));
|
||||
});
|
||||
CardTitle.displayName = "CardTitle";
|
||||
const CardDescription = React.forwardRef((_a, ref) => {
|
||||
var { className } = _a, props = __rest(_a, ["className"]);
|
||||
return (React.createElement("p", Object.assign({ ref: ref, className: cn("text-sm text-muted-foreground", className) }, props)));
|
||||
});
|
||||
CardDescription.displayName = "CardDescription";
|
||||
const CardContent = React.forwardRef((_a, ref) => {
|
||||
var { className } = _a, props = __rest(_a, ["className"]);
|
||||
return (React.createElement("div", Object.assign({ ref: ref, className: cn("p-6 pt-0", className) }, props)));
|
||||
});
|
||||
CardContent.displayName = "CardContent";
|
||||
const CardFooter = React.forwardRef((_a, ref) => {
|
||||
var { className } = _a, props = __rest(_a, ["className"]);
|
||||
return (React.createElement("div", Object.assign({ ref: ref, className: cn("flex items-center p-6 pt-0", className) }, props)));
|
||||
});
|
||||
CardFooter.displayName = "CardFooter";
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
export * from './button';
|
||||
export * from './card';
|
||||
export * from './collapsible';
|
||||
export * from './floating-action-button';
|
||||
export * from './input';
|
||||
export * from './layout';
|
||||
export * from './sheet';
|
||||
export * from './switch';
|
||||
export * from './scroll-area';
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
export * from './button';
|
||||
export * from './card';
|
||||
export * from './collapsible';
|
||||
export * from './floating-action-button';
|
||||
export * from './input';
|
||||
export * from './layout';
|
||||
export * from './sheet';
|
||||
export * from './switch';
|
||||
export * from './scroll-area';
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import * as React from "react";
|
||||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
}
|
||||
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
||||
export { Input };
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from "react";
|
||||
import { cn } from "../../utils";
|
||||
const Input = React.forwardRef((_a, ref) => {
|
||||
var { className, type } = _a, props = __rest(_a, ["className", "type"]);
|
||||
return (React.createElement("input", Object.assign({ type: type, className: cn("flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50", className), ref: ref }, props)));
|
||||
});
|
||||
Input.displayName = "Input";
|
||||
export { Input };
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import * as React from "react";
|
||||
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
||||
declare const Switch: React.ForwardRefExoticComponent<Omit<SwitchPrimitives.SwitchProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
||||
export { Switch };
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from "react";
|
||||
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
||||
import { cn } from "../../utils";
|
||||
const Switch = React.forwardRef((_a, ref) => {
|
||||
var { className } = _a, props = __rest(_a, ["className"]);
|
||||
return (React.createElement(SwitchPrimitives.Root, Object.assign({ className: cn("peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input", className) }, props, { ref: ref }),
|
||||
React.createElement(SwitchPrimitives.Thumb, { className: cn("pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0") })));
|
||||
});
|
||||
Switch.displayName = SwitchPrimitives.Root.displayName;
|
||||
export { Switch };
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import './styles/global.css';
|
||||
export * from './utils/types';
|
||||
export * from './utils';
|
||||
export * from './components/ui';
|
||||
export * from './components/TimelineStep';
|
||||
export * from './components/TimelineFeed';
|
||||
export * from './components/SessionDrawer';
|
||||
export * from './components/SessionSidebar';
|
||||
export * from './components/DefaultAgentScreen';
|
||||
export declare const hello: () => void;
|
||||
export { getSampleAgentSteps, getSampleAgentSessions } from './utils/sample-data';
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Entry point for @ra-aid/common package
|
||||
import './styles/global.css';
|
||||
// Export types first to avoid circular references
|
||||
export * from './utils/types';
|
||||
// Export utility functions
|
||||
export * from './utils';
|
||||
// Export UI components
|
||||
export * from './components/ui';
|
||||
// Export timeline components
|
||||
export * from './components/TimelineStep';
|
||||
export * from './components/TimelineFeed';
|
||||
// Export session navigation components
|
||||
export * from './components/SessionDrawer';
|
||||
export * from './components/SessionSidebar';
|
||||
// Export main screens
|
||||
export * from './components/DefaultAgentScreen';
|
||||
// Export the hello function (temporary example)
|
||||
export const hello = () => {
|
||||
console.log("Hello from @ra-aid/common");
|
||||
};
|
||||
// Directly export sample data functions
|
||||
export { getSampleAgentSteps, getSampleAgentSessions } from './utils/sample-data';
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,7 @@
|
|||
import { type ClassValue } from "clsx";
|
||||
/**
|
||||
* Merges class names with Tailwind CSS classes
|
||||
* Combines clsx for conditional logic and tailwind-merge for handling conflicting tailwind classes
|
||||
*/
|
||||
export declare function cn(...inputs: ClassValue[]): string;
|
||||
export * from './utils';
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { clsx } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
/**
|
||||
* Merges class names with Tailwind CSS classes
|
||||
* Combines clsx for conditional logic and tailwind-merge for handling conflicting tailwind classes
|
||||
*/
|
||||
export function cn(...inputs) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
// Re-export everything from utils directory
|
||||
export * from './utils';
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"name": "@ra-aid/common",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"build": "tsc && postcss src/styles/global.css -o dist/styles/global.css",
|
||||
"dev": "tsc --watch",
|
||||
"watch:css": "postcss src/styles/global.css -o dist/styles/global.css --watch",
|
||||
"watch": "concurrently \"npm run dev\" \"npm run watch:css\"",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-collapsible": "^1.1.3",
|
||||
"@radix-ui/react-dialog": "^1.0.5",
|
||||
"@radix-ui/react-label": "^2.0.2",
|
||||
"@radix-ui/react-popover": "^1.0.7",
|
||||
"@radix-ui/react-scroll-area": "^1.2.3",
|
||||
"@radix-ui/react-select": "^2.0.0",
|
||||
"@radix-ui/react-slot": "^1.0.2",
|
||||
"@radix-ui/react-switch": "^1.1.3",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.1.0",
|
||||
"lucide-react": "^0.363.0",
|
||||
"tailwind-merge": "^2.2.0",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.64",
|
||||
"@types/react-dom": "^18.2.21",
|
||||
"autoprefixer": "^10.4.17",
|
||||
"concurrently": "^8.2.2",
|
||||
"postcss": "^8.4.35",
|
||||
"postcss-cli": "^10.1.0",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.0.0",
|
||||
"react-dom": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
|
|
@ -0,0 +1,258 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { PanelLeft } from 'lucide-react';
|
||||
import {
|
||||
Button,
|
||||
Layout
|
||||
} from './ui';
|
||||
import { SessionDrawer } from './SessionDrawer';
|
||||
import { SessionList } from './SessionList';
|
||||
import { TimelineFeed } from './TimelineFeed';
|
||||
import { getSampleAgentSessions, getSampleAgentSteps } from '../utils/sample-data';
|
||||
import logoBlack from '../assets/logo-black-transparent.png';
|
||||
import logoWhite from '../assets/logo-white-transparent.gif';
|
||||
|
||||
/**
|
||||
* DefaultAgentScreen component
|
||||
*
|
||||
* Main application screen for displaying agent sessions and their steps.
|
||||
* Handles state management, responsive design, and UI interactions.
|
||||
*/
|
||||
export const DefaultAgentScreen: React.FC = () => {
|
||||
// State for drawer open/close
|
||||
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
||||
|
||||
// State for selected session
|
||||
const [selectedSessionId, setSelectedSessionId] = useState<string | null>(null);
|
||||
|
||||
// State for theme (dark is default)
|
||||
const [isDarkTheme, setIsDarkTheme] = useState(true);
|
||||
|
||||
// Get sample data
|
||||
const sessions = getSampleAgentSessions();
|
||||
const allSteps = getSampleAgentSteps();
|
||||
|
||||
// Set up theme on component mount
|
||||
useEffect(() => {
|
||||
const isDark = setupTheme();
|
||||
setIsDarkTheme(isDark);
|
||||
}, []);
|
||||
|
||||
// Set initial selected session if none selected
|
||||
useEffect(() => {
|
||||
if (!selectedSessionId && sessions.length > 0) {
|
||||
setSelectedSessionId(sessions[0].id);
|
||||
}
|
||||
}, [sessions, selectedSessionId]);
|
||||
|
||||
// Close drawer when window resizes to desktop width
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
// Check if we're at desktop size (corresponds to md: breakpoint in Tailwind)
|
||||
if (window.innerWidth >= 768 && isDrawerOpen) {
|
||||
setIsDrawerOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Add event listener
|
||||
window.addEventListener('resize', handleResize);
|
||||
|
||||
// Clean up event listener on component unmount
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, [isDrawerOpen]);
|
||||
|
||||
// Filter steps for selected session
|
||||
const selectedSessionSteps = selectedSessionId
|
||||
? allSteps.filter(step => sessions.find(s => s.id === selectedSessionId)?.steps.some(s => s.id === step.id))
|
||||
: [];
|
||||
|
||||
// Handle session selection
|
||||
const handleSessionSelect = (sessionId: string) => {
|
||||
setSelectedSessionId(sessionId);
|
||||
setIsDrawerOpen(false); // Close drawer on selection (mobile)
|
||||
};
|
||||
|
||||
// Toggle theme function
|
||||
const toggleTheme = () => {
|
||||
const newIsDark = !isDarkTheme;
|
||||
setIsDarkTheme(newIsDark);
|
||||
|
||||
// Update document element class
|
||||
if (newIsDark) {
|
||||
document.documentElement.classList.add('dark');
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark');
|
||||
}
|
||||
|
||||
// Save to localStorage
|
||||
localStorage.setItem('theme', newIsDark ? 'dark' : 'light');
|
||||
};
|
||||
|
||||
// Render header content
|
||||
const headerContent = (
|
||||
<div className="w-full flex items-center justify-between h-full px-4">
|
||||
<div className="flex-initial">
|
||||
{/* Use the appropriate logo based on theme */}
|
||||
<img
|
||||
src={isDarkTheme ? logoWhite : logoBlack}
|
||||
alt="RA.Aid Logo"
|
||||
className="h-8"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex-initial ml-auto">
|
||||
{/* Theme toggle button */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={toggleTheme}
|
||||
aria-label={isDarkTheme ? "Switch to light mode" : "Switch to dark mode"}
|
||||
>
|
||||
{isDarkTheme ? (
|
||||
// Sun icon for light mode toggle
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<circle cx="12" cy="12" r="5" />
|
||||
<line x1="12" y1="1" x2="12" y2="3" />
|
||||
<line x1="12" y1="21" x2="12" y2="23" />
|
||||
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64" />
|
||||
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78" />
|
||||
<line x1="1" y1="12" x2="3" y2="12" />
|
||||
<line x1="21" y1="12" x2="23" y2="12" />
|
||||
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36" />
|
||||
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22" />
|
||||
</svg>
|
||||
) : (
|
||||
// Moon icon for dark mode toggle
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
|
||||
</svg>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
// Sidebar content with sessions list
|
||||
const sidebarContent = (
|
||||
<div className="h-full flex flex-col px-4 py-3">
|
||||
<SessionList
|
||||
sessions={sessions}
|
||||
onSelectSession={handleSessionSelect}
|
||||
currentSessionId={selectedSessionId || undefined}
|
||||
className="flex-1 pr-1 -mr-1"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
// Render drawer
|
||||
const drawerContent = (
|
||||
<SessionDrawer
|
||||
sessions={sessions}
|
||||
currentSessionId={selectedSessionId || undefined}
|
||||
onSelectSession={handleSessionSelect}
|
||||
isOpen={isDrawerOpen}
|
||||
onClose={() => setIsDrawerOpen(false)}
|
||||
/>
|
||||
);
|
||||
|
||||
// Render main content
|
||||
const mainContent = (
|
||||
selectedSessionId ? (
|
||||
<>
|
||||
<h2 className="text-xl font-semibold mb-4">
|
||||
Session: {sessions.find(s => s.id === selectedSessionId)?.name || 'Unknown'}
|
||||
</h2>
|
||||
<TimelineFeed
|
||||
steps={selectedSessionSteps}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<p className="text-muted-foreground">Select a session to view details</p>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
|
||||
// Floating action button component that uses Portal to render at document body level
|
||||
const FloatingActionButton = ({ onClick }: { onClick: () => void }) => {
|
||||
// Only render the portal on the client side, not during SSR
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
return () => setMounted(false);
|
||||
}, []);
|
||||
|
||||
const button = (
|
||||
<Button
|
||||
variant="default"
|
||||
size="icon"
|
||||
onClick={onClick}
|
||||
aria-label="Toggle sessions panel"
|
||||
className="h-14 w-14 rounded-full shadow-xl bg-zinc-800 hover:bg-zinc-700 text-zinc-100 flex items-center justify-center border-2 border-zinc-700 dark:border-zinc-600"
|
||||
>
|
||||
<PanelLeft className="h-6 w-6" />
|
||||
</Button>
|
||||
);
|
||||
|
||||
const container = (
|
||||
<div className="fixed bottom-6 right-6 z-[9999] md:hidden" style={{ pointerEvents: 'auto' }}>
|
||||
{button}
|
||||
</div>
|
||||
);
|
||||
|
||||
// Return null during SSR, or the portal on the client
|
||||
return mounted ? createPortal(container, document.body) : null;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Layout
|
||||
header={headerContent}
|
||||
sidebar={sidebarContent}
|
||||
drawer={drawerContent}
|
||||
>
|
||||
{mainContent}
|
||||
</Layout>
|
||||
<FloatingActionButton onClick={() => setIsDrawerOpen(true)} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
// Helper function for theme setup
|
||||
const setupTheme = () => {
|
||||
// Check if theme preference is stored in localStorage
|
||||
const storedTheme = localStorage.getItem('theme');
|
||||
|
||||
// Default to dark mode unless explicitly set to light
|
||||
const isDark = storedTheme ? storedTheme === 'dark' : true;
|
||||
|
||||
// Apply theme to document
|
||||
if (isDark) {
|
||||
document.documentElement.classList.add('dark');
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark');
|
||||
}
|
||||
|
||||
return isDark;
|
||||
};
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
SheetClose
|
||||
} from './ui/sheet';
|
||||
import { AgentSession } from '../utils/types';
|
||||
import { getSampleAgentSessions } from '../utils/sample-data';
|
||||
import { SessionList } from './SessionList';
|
||||
|
||||
interface SessionDrawerProps {
|
||||
onSelectSession?: (sessionId: string) => void;
|
||||
currentSessionId?: string;
|
||||
sessions?: AgentSession[];
|
||||
isOpen?: boolean;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
export const SessionDrawer: React.FC<SessionDrawerProps> = ({
|
||||
onSelectSession,
|
||||
currentSessionId,
|
||||
sessions = getSampleAgentSessions(),
|
||||
isOpen = false,
|
||||
onClose
|
||||
}) => {
|
||||
return (
|
||||
<Sheet open={isOpen} onOpenChange={onClose}>
|
||||
<SheetContent
|
||||
side="left"
|
||||
className="w-full sm:max-w-md border-r border-border p-4"
|
||||
>
|
||||
<SheetHeader className="px-2">
|
||||
<SheetTitle>Sessions</SheetTitle>
|
||||
</SheetHeader>
|
||||
<SessionList
|
||||
sessions={sessions}
|
||||
currentSessionId={currentSessionId}
|
||||
onSelectSession={onSelectSession}
|
||||
className="h-[calc(100vh-9rem)] mt-4"
|
||||
wrapperComponent={SheetClose}
|
||||
/>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
import React from 'react';
|
||||
import { ScrollArea } from './ui/scroll-area';
|
||||
import { AgentSession } from '../utils/types';
|
||||
import { getSampleAgentSessions } from '../utils/sample-data';
|
||||
|
||||
interface SessionListProps {
|
||||
onSelectSession?: (sessionId: string) => void;
|
||||
currentSessionId?: string;
|
||||
sessions?: AgentSession[];
|
||||
className?: string;
|
||||
wrapperComponent?: React.ElementType;
|
||||
closeAction?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const SessionList: React.FC<SessionListProps> = ({
|
||||
onSelectSession,
|
||||
currentSessionId,
|
||||
sessions = getSampleAgentSessions(),
|
||||
className = '',
|
||||
wrapperComponent: WrapperComponent = 'button',
|
||||
closeAction
|
||||
}) => {
|
||||
// Get status color
|
||||
const getStatusColor = (status: string) => {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
return 'bg-blue-500';
|
||||
case 'completed':
|
||||
return 'bg-green-500';
|
||||
case 'error':
|
||||
return 'bg-red-500';
|
||||
default:
|
||||
return 'bg-gray-500';
|
||||
}
|
||||
};
|
||||
|
||||
// Format timestamp
|
||||
const formatDate = (date: Date) => {
|
||||
return date.toLocaleDateString([], {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<ScrollArea className={className}>
|
||||
<div className="space-y-1.5 pt-1.5 pb-2">
|
||||
{sessions.map((session) => {
|
||||
const buttonContent = (
|
||||
<>
|
||||
<div className={`w-2.5 h-2.5 rounded-full ${getStatusColor(session.status)} mt-1.5 mr-3 flex-shrink-0`} />
|
||||
<div className="flex-1 min-w-0 pr-1">
|
||||
<div className="font-medium text-sm+ break-words">{session.name}</div>
|
||||
<div className="text-xs text-muted-foreground mt-1 break-words">
|
||||
{session.steps.length} steps • {formatDate(session.updated)}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground mt-0.5 break-words">
|
||||
<span className="capitalize">{session.status}</span>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
return React.createElement(
|
||||
WrapperComponent,
|
||||
{
|
||||
key: session.id,
|
||||
onClick: () => onSelectSession?.(session.id),
|
||||
className: `w-full flex items-start px-3 py-2.5 text-left rounded-md transition-colors hover:bg-accent/50 ${
|
||||
currentSessionId === session.id ? 'bg-accent' : ''
|
||||
}`
|
||||
},
|
||||
closeAction ? (
|
||||
<>
|
||||
{buttonContent}
|
||||
<div className="ml-2 flex-shrink-0 self-center">
|
||||
{React.cloneElement(closeAction as React.ReactElement, {
|
||||
onClick: (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
onSelectSession?.(session.id);
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
) : buttonContent
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
import React from 'react';
|
||||
import { AgentSession } from '../utils/types';
|
||||
import { getSampleAgentSessions } from '../utils/sample-data';
|
||||
import { SessionList } from './SessionList';
|
||||
|
||||
interface SessionSidebarProps {
|
||||
onSelectSession?: (sessionId: string) => void;
|
||||
currentSessionId?: string;
|
||||
sessions?: AgentSession[];
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
||||
onSelectSession,
|
||||
currentSessionId,
|
||||
sessions = getSampleAgentSessions(),
|
||||
className = ''
|
||||
}) => {
|
||||
return (
|
||||
<div className={`flex flex-col h-full ${className}`}>
|
||||
<div className="p-4 border-b border-border">
|
||||
<h3 className="font-medium text-lg">Sessions</h3>
|
||||
</div>
|
||||
<SessionList
|
||||
sessions={sessions}
|
||||
currentSessionId={currentSessionId}
|
||||
onSelectSession={onSelectSession}
|
||||
className="flex-1"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import React, { useMemo } from 'react';
|
||||
import { TimelineStep } from './TimelineStep';
|
||||
import { AgentStep } from '../utils/types';
|
||||
|
||||
interface TimelineFeedProps {
|
||||
steps: AgentStep[];
|
||||
maxHeight?: string;
|
||||
}
|
||||
|
||||
export const TimelineFeed: React.FC<TimelineFeedProps> = ({
|
||||
steps,
|
||||
maxHeight
|
||||
}) => {
|
||||
// Always use 'desc' (newest first) sort order
|
||||
const sortOrder = 'desc';
|
||||
|
||||
// Sort steps with newest first (desc order)
|
||||
const sortedSteps = useMemo(() => {
|
||||
return [...steps].sort((a, b) => {
|
||||
return b.timestamp.getTime() - a.timestamp.getTime();
|
||||
});
|
||||
}, [steps]);
|
||||
|
||||
return (
|
||||
<div className="w-full rounded-md bg-background">
|
||||
<div
|
||||
className="px-3 py-3 space-y-4 overflow-auto"
|
||||
style={{ maxHeight: maxHeight || undefined }}
|
||||
>
|
||||
{sortedSteps.length > 0 ? (
|
||||
sortedSteps.map((step) => (
|
||||
<TimelineStep key={step.id} step={step} />
|
||||
))
|
||||
) : (
|
||||
<div className="text-center text-muted-foreground py-12 border border-dashed border-border rounded-md">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-8 w-8 mx-auto mb-2 text-muted-foreground/50" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
<p>No steps to display</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
import React from 'react';
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from './ui/collapsible';
|
||||
import { AgentStep } from '../utils/types';
|
||||
|
||||
interface TimelineStepProps {
|
||||
step: AgentStep;
|
||||
}
|
||||
|
||||
export const TimelineStep: React.FC<TimelineStepProps> = ({ step }) => {
|
||||
// Get status color
|
||||
const getStatusColor = (status: string) => {
|
||||
switch (status) {
|
||||
case 'completed':
|
||||
return 'bg-green-500';
|
||||
case 'in-progress':
|
||||
return 'bg-blue-500';
|
||||
case 'error':
|
||||
return 'bg-red-500';
|
||||
case 'pending':
|
||||
return 'bg-yellow-500';
|
||||
default:
|
||||
return 'bg-gray-500';
|
||||
}
|
||||
};
|
||||
|
||||
// Get icon based on step type
|
||||
const getTypeIcon = (type: string) => {
|
||||
switch (type) {
|
||||
case 'tool-execution':
|
||||
return '🛠️';
|
||||
case 'thinking':
|
||||
return '💭';
|
||||
case 'planning':
|
||||
return '📝';
|
||||
case 'implementation':
|
||||
return '💻';
|
||||
case 'user-input':
|
||||
return '👤';
|
||||
default:
|
||||
return '▶️';
|
||||
}
|
||||
};
|
||||
|
||||
// Format timestamp
|
||||
const formatTime = (timestamp: Date) => {
|
||||
return timestamp.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
};
|
||||
|
||||
return (
|
||||
<Collapsible className="w-full mb-5 border border-border rounded-md overflow-hidden shadow-sm hover:shadow-md transition-all duration-200">
|
||||
<CollapsibleTrigger className="w-full flex items-center justify-between p-4 text-left hover:bg-accent/30 cursor-pointer group">
|
||||
<div className="flex items-center space-x-3 min-w-0 flex-1 pr-3">
|
||||
<div className={`flex-shrink-0 w-3 h-3 rounded-full ${getStatusColor(step.status)} ring-1 ring-ring/20`} />
|
||||
<div className="flex-shrink-0 text-lg group-hover:scale-110 transition-transform">{getTypeIcon(step.type)}</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="font-medium text-foreground break-words">{step.title}</div>
|
||||
<div className="text-sm text-muted-foreground line-clamp-2">
|
||||
{step.type === 'tool-execution' ? 'Run tool' : step.content.substring(0, 60)}
|
||||
{step.content.length > 60 ? '...' : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground flex flex-col items-end flex-shrink-0 min-w-[70px] text-right">
|
||||
<span className="font-medium">{formatTime(step.timestamp)}</span>
|
||||
{step.duration && (
|
||||
<span className="mt-1 px-2 py-0.5 bg-secondary/50 rounded-full">
|
||||
{(step.duration / 1000).toFixed(1)}s
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<div className="p-5 bg-card/50 border-t border-border">
|
||||
<div className="text-sm break-words text-foreground leading-relaxed">
|
||||
{step.content}
|
||||
</div>
|
||||
{step.duration && (
|
||||
<div className="mt-4 pt-3 border-t border-border/50">
|
||||
<div className="text-xs text-muted-foreground flex items-center">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-3.5 w-3.5 mr-1"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<polyline points="12 6 12 12 16 14" />
|
||||
</svg>
|
||||
Duration: {(step.duration / 1000).toFixed(1)} seconds
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "../../utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
||||
outline:
|
||||
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2",
|
||||
sm: "h-8 rounded-md px-3 text-xs",
|
||||
lg: "h-10 rounded-md px-8",
|
||||
icon: "h-9 w-9",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
|
||||
export { Button, buttonVariants };
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
import * as React from "react";
|
||||
|
||||
import { cn } from "../../utils";
|
||||
|
||||
const Card = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"rounded-xl border bg-card text-card-foreground shadow",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
Card.displayName = "Card";
|
||||
|
||||
const CardHeader = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardHeader.displayName = "CardHeader";
|
||||
|
||||
const CardTitle = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLHeadingElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<h3
|
||||
ref={ref}
|
||||
className={cn("font-semibold leading-none tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardTitle.displayName = "CardTitle";
|
||||
|
||||
const CardDescription = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<p
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardDescription.displayName = "CardDescription";
|
||||
|
||||
const CardContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
||||
));
|
||||
CardContent.displayName = "CardContent";
|
||||
|
||||
const CardFooter = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex items-center p-6 pt-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
CardFooter.displayName = "CardFooter";
|
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import * as React from "react"
|
||||
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
|
||||
|
||||
import { cn } from "../../utils"
|
||||
|
||||
const Collapsible = CollapsiblePrimitive.Root
|
||||
|
||||
const CollapsibleTrigger = CollapsiblePrimitive.Trigger
|
||||
|
||||
const CollapsibleContent = React.forwardRef<
|
||||
React.ElementRef<typeof CollapsiblePrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof CollapsiblePrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<CollapsiblePrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"overflow-hidden data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</CollapsiblePrimitive.Content>
|
||||
))
|
||||
CollapsibleContent.displayName = "CollapsibleContent"
|
||||
|
||||
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import React, { ReactNode } from 'react';
|
||||
import { Button } from './button';
|
||||
|
||||
export interface FloatingActionButtonProps {
|
||||
icon: ReactNode;
|
||||
onClick: () => void;
|
||||
ariaLabel?: string;
|
||||
className?: string;
|
||||
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
||||
}
|
||||
|
||||
/**
|
||||
* FloatingActionButton component
|
||||
*
|
||||
* A button typically used for primary actions on mobile layouts
|
||||
* Designed to be used with the Layout component's floatingAction prop
|
||||
*/
|
||||
export const FloatingActionButton: React.FC<FloatingActionButtonProps> = ({
|
||||
icon,
|
||||
onClick,
|
||||
ariaLabel = 'Action button',
|
||||
className = '',
|
||||
variant = 'default'
|
||||
}) => {
|
||||
return (
|
||||
<Button
|
||||
variant={variant}
|
||||
size="icon"
|
||||
onClick={onClick}
|
||||
aria-label={ariaLabel}
|
||||
className={`h-14 w-14 rounded-full shadow-xl bg-blue-600 hover:bg-blue-700 text-white flex items-center justify-center border-2 border-white dark:border-gray-800 ${className}`}
|
||||
>
|
||||
{icon}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
export * from './button';
|
||||
export * from './card';
|
||||
export * from './collapsible';
|
||||
export * from './floating-action-button';
|
||||
export * from './input';
|
||||
export * from './layout';
|
||||
export * from './sheet';
|
||||
export * from './switch';
|
||||
export * from './scroll-area';
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import * as React from "react";
|
||||
|
||||
import { cn } from "../../utils";
|
||||
|
||||
export interface InputProps
|
||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
"flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
Input.displayName = "Input";
|
||||
|
||||
export { Input };
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
import React from 'react';
|
||||
|
||||
/**
|
||||
* Layout component using Tailwind Grid utilities
|
||||
* This component creates a responsive layout with:
|
||||
* - Sticky header at the top (z-index 30)
|
||||
* - Sidebar on desktop (hidden on mobile)
|
||||
* - Main content area with proper positioning
|
||||
* - Optional floating action button for mobile navigation
|
||||
*/
|
||||
export interface LayoutProps {
|
||||
header: React.ReactNode;
|
||||
sidebar?: React.ReactNode;
|
||||
drawer?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
floatingAction?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Layout: React.FC<LayoutProps> = ({
|
||||
header,
|
||||
sidebar,
|
||||
drawer,
|
||||
children,
|
||||
floatingAction
|
||||
}) => {
|
||||
return (
|
||||
<div className="grid min-h-screen grid-cols-1 grid-rows-[64px_1fr] md:grid-cols-[280px_1fr] lg:grid-cols-[320px_1fr] xl:grid-cols-[350px_1fr] bg-background text-foreground relative">
|
||||
{/* Header - always visible, spans full width */}
|
||||
<header className="sticky top-0 z-30 h-16 flex items-center bg-background border-b border-border col-span-full">
|
||||
{header}
|
||||
</header>
|
||||
|
||||
{/* Sidebar - hidden on mobile, visible on tablet/desktop */}
|
||||
{sidebar && (
|
||||
<aside className="hidden md:block fixed top-16 bottom-0 w-[280px] lg:w-[320px] xl:w-[350px] overflow-y-auto z-20 bg-background border-r border-border">
|
||||
{sidebar}
|
||||
</aside>
|
||||
)}
|
||||
|
||||
{/* Main content area */}
|
||||
<main className="overflow-y-auto p-4 row-start-2 col-start-1 md:col-start-2 md:h-[calc(100vh-64px)]">
|
||||
{children}
|
||||
</main>
|
||||
|
||||
{/* Mobile drawer - rendered outside grid */}
|
||||
{drawer}
|
||||
|
||||
{/* Floating action button for mobile */}
|
||||
{floatingAction && (
|
||||
<div className="fixed bottom-6 right-6 z-50 md:hidden">
|
||||
{floatingAction}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
import * as React from "react"
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
||||
|
||||
import { cn } from "../../utils"
|
||||
|
||||
const ScrollArea = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn("relative overflow-hidden", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollBar orientation="horizontal" />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
))
|
||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
|
||||
|
||||
const ScrollBar = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
>(({ className, orientation = "vertical", ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
ref={ref}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none select-none transition-colors",
|
||||
orientation === "vertical" &&
|
||||
"h-full w-2.5 border-l border-l-transparent p-[1px]",
|
||||
orientation === "horizontal" &&
|
||||
"h-2.5 border-t border-t-transparent p-[1px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
))
|
||||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
import * as React from "react"
|
||||
import * as SheetPrimitive from "@radix-ui/react-dialog"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { X } from "lucide-react"
|
||||
|
||||
import { cn } from "../../utils"
|
||||
|
||||
const Sheet = SheetPrimitive.Root
|
||||
|
||||
const SheetTrigger = SheetPrimitive.Trigger
|
||||
|
||||
const SheetClose = SheetPrimitive.Close
|
||||
|
||||
const SheetPortal = SheetPrimitive.Portal
|
||||
|
||||
const SheetOverlay = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Overlay
|
||||
className={cn(
|
||||
"fixed inset-0 z-70 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
/>
|
||||
))
|
||||
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName
|
||||
|
||||
const sheetVariants = cva(
|
||||
"fixed z-70 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
|
||||
{
|
||||
variants: {
|
||||
side: {
|
||||
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
|
||||
right: "inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
|
||||
bottom: "inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
|
||||
left: "inset-y-0 left-0 h-full w-full border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
side: "right",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
interface SheetContentProps
|
||||
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
|
||||
VariantProps<typeof sheetVariants> {}
|
||||
|
||||
const SheetContent = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Content>,
|
||||
SheetContentProps
|
||||
>(({ side = "right", className, children, ...props }, ref) => (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(sheetVariants({ side }), className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</SheetPrimitive.Close>
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
))
|
||||
SheetContent.displayName = SheetPrimitive.Content.displayName
|
||||
|
||||
const SheetHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-2 text-center sm:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
SheetHeader.displayName = "SheetHeader"
|
||||
|
||||
const SheetFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
SheetFooter.displayName = "SheetFooter"
|
||||
|
||||
const SheetTitle = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn("text-lg font-semibold text-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SheetTitle.displayName = SheetPrimitive.Title.displayName
|
||||
|
||||
const SheetDescription = React.forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
SheetDescription.displayName = SheetPrimitive.Description.displayName
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import * as React from "react";
|
||||
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
||||
|
||||
import { cn } from "../../utils";
|
||||
|
||||
const Switch = React.forwardRef<
|
||||
React.ElementRef<typeof SwitchPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SwitchPrimitives.Root
|
||||
className={cn(
|
||||
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
<SwitchPrimitives.Thumb
|
||||
className={cn(
|
||||
"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"
|
||||
)}
|
||||
/>
|
||||
</SwitchPrimitives.Root>
|
||||
));
|
||||
Switch.displayName = SwitchPrimitives.Root.displayName;
|
||||
|
||||
export { Switch };
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
// Entry point for @ra-aid/common package
|
||||
import './styles/global.css';
|
||||
|
||||
// Export types first to avoid circular references
|
||||
export * from './utils/types';
|
||||
|
||||
// Export utility functions
|
||||
export * from './utils';
|
||||
|
||||
// Export UI components
|
||||
export * from './components/ui';
|
||||
|
||||
// Export timeline components
|
||||
export * from './components/TimelineStep';
|
||||
export * from './components/TimelineFeed';
|
||||
|
||||
// Export session navigation components
|
||||
export * from './components/SessionDrawer';
|
||||
export * from './components/SessionSidebar';
|
||||
|
||||
// Export main screens
|
||||
export * from './components/DefaultAgentScreen';
|
||||
|
||||
// Export the hello function (temporary example)
|
||||
export const hello = (): void => {
|
||||
console.log("Hello from @ra-aid/common");
|
||||
};
|
||||
|
||||
// Directly export sample data functions
|
||||
export {
|
||||
getSampleAgentSteps,
|
||||
getSampleAgentSessions
|
||||
} from './utils/sample-data';
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--background: 0 0% 100%;
|
||||
--foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--muted: 210 40% 96.1%;
|
||||
--muted-foreground: 215.4 16.3% 46.9%;
|
||||
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--border: 214.3 31.8% 91.4%;
|
||||
--input: 214.3 31.8% 91.4%;
|
||||
|
||||
--primary: 222.2 47.4% 11.2%;
|
||||
--primary-foreground: 210 40% 98%;
|
||||
|
||||
--secondary: 210 40% 96.1%;
|
||||
--secondary-foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--accent: 210 40% 96.1%;
|
||||
--accent-foreground: 222.2 47.4% 11.2%;
|
||||
|
||||
--destructive: 0 100% 50%;
|
||||
--destructive-foreground: 210 40% 98%;
|
||||
|
||||
--ring: 215 20.2% 65.1%;
|
||||
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: 240 10% 3.9%; /* zinc-950 */
|
||||
--foreground: 240 5% 96%; /* zinc-50 */
|
||||
|
||||
--card: 240 10% 3.9%; /* zinc-950 */
|
||||
--card-foreground: 240 5% 96%; /* zinc-50 */
|
||||
|
||||
--popover: 240 10% 3.9%; /* zinc-950 */
|
||||
--popover-foreground: 240 5% 96%; /* zinc-50 */
|
||||
|
||||
--primary: 240 5% 96%; /* zinc-50 */
|
||||
--primary-foreground: 240 6% 10%; /* zinc-900 */
|
||||
|
||||
--secondary: 240 4% 16%; /* zinc-800 */
|
||||
--secondary-foreground: 240 5% 96%; /* zinc-50 */
|
||||
|
||||
--muted: 240 4% 16%; /* zinc-800 */
|
||||
--muted-foreground: 240 5% 65%; /* zinc-400 */
|
||||
|
||||
--accent: 240 4% 16%; /* zinc-800 */
|
||||
--accent-foreground: 240 5% 96%; /* zinc-50 */
|
||||
|
||||
--destructive: 0 63% 31%; /* red-900 */
|
||||
--destructive-foreground: 240 5% 96%; /* zinc-50 */
|
||||
|
||||
--border: 240 4% 16%; /* zinc-800 */
|
||||
--input: 240 4% 16%; /* zinc-800 */
|
||||
--ring: 240 5% 84%; /* zinc-300 */
|
||||
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
font-feature-settings: "rlig" 1, "calt" 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
declare module '*.png' {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
||||
declare module '*.gif' {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
||||
declare module '*.jpg' {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
||||
declare module '*.jpeg' {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
||||
declare module '*.svg' {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { clsx, type ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
/**
|
||||
* Merges class names with Tailwind CSS classes
|
||||
* Combines clsx for conditional logic and tailwind-merge for handling conflicting tailwind classes
|
||||
*/
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
// Re-export everything from utils directory
|
||||
export * from './utils';
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { clsx, type ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
/**
|
||||
* Merges class names with Tailwind CSS classes
|
||||
* Combines clsx for conditional logic and tailwind-merge for handling conflicting tailwind classes
|
||||
*/
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
// Note: Sample data functions and types are now exported directly from the root index.ts
|
||||
// to avoid circular references
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
/**
|
||||
* Sample data utility for agent UI components demonstration
|
||||
*/
|
||||
|
||||
import { AgentStep, AgentSession } from './types';
|
||||
|
||||
/**
|
||||
* Returns an array of sample agent steps
|
||||
*/
|
||||
export function getSampleAgentSteps(): AgentStep[] {
|
||||
return [
|
||||
{
|
||||
id: "step-1",
|
||||
timestamp: new Date(Date.now() - 30 * 60000), // 30 minutes ago
|
||||
status: 'completed',
|
||||
type: 'planning',
|
||||
title: 'Initial Planning',
|
||||
content: 'I need to analyze the codebase structure to understand the existing components and their relationships.',
|
||||
duration: 5200
|
||||
},
|
||||
{
|
||||
id: "step-2",
|
||||
timestamp: new Date(Date.now() - 25 * 60000), // 25 minutes ago
|
||||
status: 'completed',
|
||||
type: 'tool-execution',
|
||||
title: 'List Directory Structure',
|
||||
content: 'Executing: list_directory_tree(path="src/", max_depth=2)\n\n📁 /project/src/\n├── 📁 components/\n│ ├── 📁 ui/\n│ └── App.tsx\n├── 📁 utils/\n└── index.tsx',
|
||||
duration: 1800
|
||||
},
|
||||
{
|
||||
id: "step-3",
|
||||
timestamp: new Date(Date.now() - 20 * 60000), // 20 minutes ago
|
||||
status: 'completed',
|
||||
type: 'thinking',
|
||||
title: 'Component Analysis',
|
||||
content: 'Based on the directory structure, I see that the UI components are organized in a dedicated folder. I should examine the existing component patterns before implementing new ones.',
|
||||
duration: 3500
|
||||
},
|
||||
{
|
||||
id: "step-4",
|
||||
timestamp: new Date(Date.now() - 15 * 60000), // 15 minutes ago
|
||||
status: 'completed',
|
||||
type: 'tool-execution',
|
||||
title: 'Read Component Code',
|
||||
content: 'Executing: read_file_tool(filepath="src/components/ui/Button.tsx")\n\n```tsx\nimport { cn } from "../../utils";\n\nexport interface ButtonProps {\n // Component props...\n}\n\nexport function Button({ children, ...props }: ButtonProps) {\n // Component implementation...\n}\n```',
|
||||
duration: 2100
|
||||
},
|
||||
{
|
||||
id: "step-5",
|
||||
timestamp: new Date(Date.now() - 10 * 60000), // 10 minutes ago
|
||||
status: 'completed',
|
||||
type: 'implementation',
|
||||
title: 'Creating NavBar Component',
|
||||
content: 'I\'m creating a NavBar component following the design system patterns:\n\n```tsx\nimport { cn } from "../../utils";\n\nexport interface NavBarProps {\n // New component props...\n}\n\nexport function NavBar({ ...props }: NavBarProps) {\n // New component implementation...\n}\n```',
|
||||
duration: 6800
|
||||
},
|
||||
{
|
||||
id: "step-6",
|
||||
timestamp: new Date(Date.now() - 5 * 60000), // 5 minutes ago
|
||||
status: 'in-progress',
|
||||
type: 'implementation',
|
||||
title: 'Styling Timeline Component',
|
||||
content: 'Currently working on styling the Timeline component to match the design system:\n\n```tsx\n// Work in progress...\nexport function Timeline({ steps, ...props }: TimelineProps) {\n // Current implementation...\n}\n```',
|
||||
},
|
||||
{
|
||||
id: "step-7",
|
||||
timestamp: new Date(Date.now() - 2 * 60000), // 2 minutes ago
|
||||
status: 'error',
|
||||
type: 'tool-execution',
|
||||
title: 'Running Tests',
|
||||
content: 'Error executing: run_shell_command(command="npm test")\n\nTest failed: TypeError: Cannot read property \'steps\' of undefined',
|
||||
duration: 3200
|
||||
},
|
||||
{
|
||||
id: "step-8",
|
||||
timestamp: new Date(), // Now
|
||||
status: 'pending',
|
||||
type: 'planning',
|
||||
title: 'Next Steps',
|
||||
content: 'Need to plan the implementation of the SessionDrawer component...',
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of sample agent sessions
|
||||
*/
|
||||
export function getSampleAgentSessions(): AgentSession[] {
|
||||
const steps = getSampleAgentSteps();
|
||||
|
||||
return [
|
||||
{
|
||||
id: "session-1",
|
||||
name: "UI Component Implementation",
|
||||
created: new Date(Date.now() - 35 * 60000), // 35 minutes ago
|
||||
updated: new Date(), // Now
|
||||
status: 'active',
|
||||
steps: steps
|
||||
},
|
||||
{
|
||||
id: "session-2",
|
||||
name: "API Integration",
|
||||
created: new Date(Date.now() - 2 * 3600000), // 2 hours ago
|
||||
updated: new Date(Date.now() - 30 * 60000), // 30 minutes ago
|
||||
status: 'completed',
|
||||
steps: [
|
||||
{
|
||||
id: "other-step-1",
|
||||
timestamp: new Date(Date.now() - 2 * 3600000), // 2 hours ago
|
||||
status: 'completed',
|
||||
type: 'planning',
|
||||
title: 'API Integration Planning',
|
||||
content: 'Planning the integration with the backend API...',
|
||||
duration: 4500
|
||||
},
|
||||
{
|
||||
id: "other-step-2",
|
||||
timestamp: new Date(Date.now() - 1.5 * 3600000), // 1.5 hours ago
|
||||
status: 'completed',
|
||||
type: 'implementation',
|
||||
title: 'Implementing API Client',
|
||||
content: 'Creating API client with fetch utilities...',
|
||||
duration: 7200
|
||||
},
|
||||
{
|
||||
id: "other-step-3",
|
||||
timestamp: new Date(Date.now() - 1 * 3600000), // 1 hour ago
|
||||
status: 'completed',
|
||||
type: 'tool-execution',
|
||||
title: 'Testing API Endpoints',
|
||||
content: 'Running tests against API endpoints...',
|
||||
duration: 5000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: "session-3",
|
||||
name: "Bug Fixes",
|
||||
created: new Date(Date.now() - 5 * 3600000), // 5 hours ago
|
||||
updated: new Date(Date.now() - 4 * 3600000), // 4 hours ago
|
||||
status: 'error',
|
||||
steps: [
|
||||
{
|
||||
id: "bug-step-1",
|
||||
timestamp: new Date(Date.now() - 5 * 3600000), // 5 hours ago
|
||||
status: 'completed',
|
||||
type: 'planning',
|
||||
title: 'Bug Analysis',
|
||||
content: 'Analyzing reported bugs from issue tracker...',
|
||||
duration: 3600
|
||||
},
|
||||
{
|
||||
id: "bug-step-2",
|
||||
timestamp: new Date(Date.now() - 4.5 * 3600000), // 4.5 hours ago
|
||||
status: 'error',
|
||||
type: 'implementation',
|
||||
title: 'Fixing Authentication Bug',
|
||||
content: 'Error: Unable to resolve dependency conflict with auth package',
|
||||
duration: 2500
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* Common types for agent UI components
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a single step in the agent process
|
||||
*/
|
||||
export interface AgentStep {
|
||||
id: string;
|
||||
timestamp: Date;
|
||||
status: 'completed' | 'in-progress' | 'error' | 'pending';
|
||||
type: 'tool-execution' | 'thinking' | 'planning' | 'implementation' | 'user-input';
|
||||
title: string;
|
||||
content: string;
|
||||
duration?: number; // in milliseconds
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a session with multiple steps
|
||||
*/
|
||||
export interface AgentSession {
|
||||
id: string;
|
||||
name: string;
|
||||
created: Date;
|
||||
updated: Date;
|
||||
status: 'active' | 'completed' | 'error';
|
||||
steps: AgentStep[];
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
presets: [require('./tailwind.preset')],
|
||||
content: [
|
||||
'./src/**/*.{js,jsx,ts,tsx}',
|
||||
],
|
||||
safelist: [
|
||||
'dark',
|
||||
{
|
||||
pattern: /^dark:/,
|
||||
variants: ['hover', 'focus', 'active']
|
||||
}
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
darkMode: ["class"],
|
||||
theme: {
|
||||
container: {
|
||||
center: true,
|
||||
padding: "2rem",
|
||||
screens: {
|
||||
"2xl": "1400px",
|
||||
},
|
||||
},
|
||||
extend: {
|
||||
colors: {
|
||||
border: "hsl(var(--border))",
|
||||
input: "hsl(var(--input))",
|
||||
ring: "hsl(var(--ring))",
|
||||
background: "hsl(var(--background))",
|
||||
foreground: "hsl(var(--foreground))",
|
||||
primary: {
|
||||
DEFAULT: "hsl(var(--primary))",
|
||||
foreground: "hsl(var(--primary-foreground))",
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: "hsl(var(--secondary))",
|
||||
foreground: "hsl(var(--secondary-foreground))",
|
||||
},
|
||||
destructive: {
|
||||
DEFAULT: "hsl(var(--destructive))",
|
||||
foreground: "hsl(var(--destructive-foreground))",
|
||||
},
|
||||
muted: {
|
||||
DEFAULT: "hsl(var(--muted))",
|
||||
foreground: "hsl(var(--muted-foreground))",
|
||||
},
|
||||
accent: {
|
||||
DEFAULT: "hsl(var(--accent))",
|
||||
foreground: "hsl(var(--accent-foreground))",
|
||||
},
|
||||
popover: {
|
||||
DEFAULT: "hsl(var(--popover))",
|
||||
foreground: "hsl(var(--popover-foreground))",
|
||||
},
|
||||
card: {
|
||||
DEFAULT: "hsl(var(--card))",
|
||||
foreground: "hsl(var(--card-foreground))",
|
||||
},
|
||||
},
|
||||
borderRadius: {
|
||||
lg: "var(--radius)",
|
||||
md: "calc(var(--radius) - 2px)",
|
||||
sm: "calc(var(--radius) - 4px)",
|
||||
},
|
||||
keyframes: {
|
||||
"accordion-down": {
|
||||
from: { height: "0" },
|
||||
to: { height: "var(--radix-accordion-content-height)" },
|
||||
},
|
||||
"accordion-up": {
|
||||
from: { height: "var(--radix-accordion-content-height)" },
|
||||
to: { height: "0" },
|
||||
},
|
||||
},
|
||||
animation: {
|
||||
"accordion-down": "accordion-down 0.2s ease-out",
|
||||
"accordion-up": "accordion-up 0.2s ease-out",
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [require("tailwindcss-animate")],
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"declaration": true,
|
||||
"jsx": "react",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext", "ES2016"]
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "frontend-monorepo",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"common",
|
||||
"web",
|
||||
"vsc"
|
||||
],
|
||||
"scripts": {
|
||||
"install-all": "npm install",
|
||||
"dev:web": "npm --workspace @ra-aid/web run dev"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
|
@ -0,0 +1,140 @@
|
|||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/extension.ts
|
||||
var extension_exports = {};
|
||||
__export(extension_exports, {
|
||||
activate: () => activate,
|
||||
deactivate: () => deactivate
|
||||
});
|
||||
module.exports = __toCommonJS(extension_exports);
|
||||
var vscode = __toESM(require("vscode"));
|
||||
var RAWebviewViewProvider = class {
|
||||
constructor(_extensionUri) {
|
||||
this._extensionUri = _extensionUri;
|
||||
}
|
||||
/**
|
||||
* Called when a view is first created to initialize the webview
|
||||
*/
|
||||
resolveWebviewView(webviewView, context, _token) {
|
||||
webviewView.webview.options = {
|
||||
// Enable JavaScript in the webview
|
||||
enableScripts: true,
|
||||
// Restrict the webview to only load resources from the extension's directory
|
||||
localResourceRoots: [this._extensionUri]
|
||||
};
|
||||
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
|
||||
}
|
||||
/**
|
||||
* Creates HTML content for the webview with proper security policies
|
||||
*/
|
||||
_getHtmlForWebview(webview) {
|
||||
const logoUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, "assets", "RA.png"));
|
||||
const nonce = getNonce();
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src ${webview.cspSource} https:; style-src ${webview.cspSource} 'unsafe-inline'; script-src 'nonce-${nonce}';">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>RA.Aid</title>
|
||||
<style>
|
||||
body {
|
||||
padding: 0;
|
||||
color: var(--vscode-foreground);
|
||||
font-size: var(--vscode-font-size);
|
||||
font-weight: var(--vscode-font-weight);
|
||||
font-family: var(--vscode-font-family);
|
||||
background-color: var(--vscode-editor-background);
|
||||
}
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.logo {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
h1 {
|
||||
color: var(--vscode-editor-foreground);
|
||||
font-size: 1.3em;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
p {
|
||||
color: var(--vscode-foreground);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<img src="${logoUri}" alt="RA.Aid Logo" class="logo">
|
||||
<h1>RA.Aid</h1>
|
||||
<p>Your research and development assistant.</p>
|
||||
<p>More features coming soon!</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
};
|
||||
function getNonce() {
|
||||
let text = "";
|
||||
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
for (let i = 0; i < 32; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
function activate(context) {
|
||||
console.log('Congratulations, your extension "ra-aid" is now active!');
|
||||
const provider = new RAWebviewViewProvider(context.extensionUri);
|
||||
const viewRegistration = vscode.window.registerWebviewViewProvider(
|
||||
"ra-aid.view",
|
||||
// Must match the view id in package.json
|
||||
provider
|
||||
);
|
||||
context.subscriptions.push(viewRegistration);
|
||||
const disposable = vscode.commands.registerCommand("ra-aid.helloWorld", () => {
|
||||
vscode.window.showInformationMessage("Hello World from RA.Aid!");
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
function deactivate() {
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
activate,
|
||||
deactivate
|
||||
});
|
||||
//# sourceMappingURL=extension.js.map
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"version": 3,
|
||||
"sources": ["../src/extension.ts"],
|
||||
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AAKxB,IAAM,wBAAN,MAAkE;AAAA,EAChE,YAA6B,eAA2B;AAA3B;AAAA,EAA4B;AAAA;AAAA;AAAA;AAAA,EAKlD,mBACL,aACA,SACA,QACA;AAEA,gBAAY,QAAQ,UAAU;AAAA;AAAA,MAE5B,eAAe;AAAA;AAAA,MAEf,oBAAoB,CAAC,KAAK,aAAa;AAAA,IACzC;AAGA,gBAAY,QAAQ,OAAO,KAAK,mBAAmB,YAAY,OAAO;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAAmB,SAAiC;AAE1D,UAAM,UAAU,QAAQ,aAAoB,WAAI,SAAS,KAAK,eAAe,UAAU,QAAQ,CAAC;AAMhG,UAAM,QAAQ,SAAS;AAEvB,WAAO;AAAA;AAAA;AAAA;AAAA,0FAI+E,QAAQ,SAAS,sBAAsB,QAAQ,SAAS,uCAAuC,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAsCxK,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO3B;AACF;AAKA,SAAS,WAAW;AAClB,MAAI,OAAO;AACX,QAAM,WAAW;AACjB,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK;AAC3B,YAAQ,SAAS,OAAO,KAAK,MAAM,KAAK,OAAO,IAAI,SAAS,MAAM,CAAC;AAAA,EACrE;AACA,SAAO;AACT;AAGO,SAAS,SAAS,SAAkC;AAEzD,UAAQ,IAAI,yDAAyD;AAGrE,QAAM,WAAW,IAAI,sBAAsB,QAAQ,YAAY;AAC/D,QAAM,mBAA0B,cAAO;AAAA,IACrC;AAAA;AAAA,IACA;AAAA,EACF;AACA,UAAQ,cAAc,KAAK,gBAAgB;AAK3C,QAAM,aAAoB,gBAAS,gBAAgB,qBAAqB,MAAM;AAG5E,IAAO,cAAO,uBAAuB,0BAA0B;AAAA,EACjE,CAAC;AAED,UAAQ,cAAc,KAAK,UAAU;AACvC;AAGO,SAAS,aAAa;AAAC;",
|
||||
"names": []
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="Demo page showcasing shadcn/ui components from the common package" />
|
||||
<title>RA-Aid UI Components Demo</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/index.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "@ra-aid/web",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0",
|
||||
"@ra-aid/common": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^4.0.0",
|
||||
"@vitejs/plugin-react": "^3.0.0",
|
||||
"typescript": "^5.0.0",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"postcss": "^8.4.35",
|
||||
"autoprefixer": "^10.4.17"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@tailwindcss/forms": "^0.5.7"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { DefaultAgentScreen } from '@ra-aid/common';
|
||||
|
||||
/**
|
||||
* Main application entry point
|
||||
* Simply renders the DefaultAgentScreen component from the common package
|
||||
*/
|
||||
const App = () => {
|
||||
return <DefaultAgentScreen />;
|
||||
};
|
||||
|
||||
// Mount the app to the root element
|
||||
const root = ReactDOM.createRoot(document.getElementById('root')!);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
presets: [require('../common/tailwind.preset')],
|
||||
content: [
|
||||
'./src/**/*.{js,jsx,ts,tsx}',
|
||||
'../common/src/**/*.{js,jsx,ts,tsx}'
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [
|
||||
require('@tailwindcss/forms')
|
||||
],
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
// Get all component files from common package
|
||||
const commonSrcDir = path.resolve(__dirname, '../common/src');
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
// Direct alias to the source directory
|
||||
'@ra-aid/common': path.resolve(__dirname, '../common/src')
|
||||
},
|
||||
preserveSymlinks: true
|
||||
},
|
||||
optimizeDeps: {
|
||||
// Exclude the common package from optimization so it can trigger hot reload
|
||||
exclude: ['@ra-aid/common']
|
||||
},
|
||||
server: {
|
||||
hmr: true,
|
||||
watch: {
|
||||
usePolling: true,
|
||||
interval: 100,
|
||||
// Make sure to explicitly NOT ignore the common package
|
||||
ignored: [
|
||||
'**/node_modules/**',
|
||||
'**/dist/**',
|
||||
'!**/common/src/**'
|
||||
]
|
||||
}
|
||||
},
|
||||
build: {
|
||||
commonjsOptions: {
|
||||
transformMixedEsModules: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -50,6 +50,7 @@ dependencies = [
|
|||
"platformdirs>=3.17.9",
|
||||
"requests",
|
||||
"packaging",
|
||||
"prompt-toolkit"
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
|
|
|
|||
|
|
@ -5,24 +5,8 @@ import sys
|
|||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
# Add litellm import
|
||||
import litellm
|
||||
|
||||
# Configure litellm to suppress debug logs
|
||||
os.environ["LITELLM_LOG"] = "ERROR"
|
||||
litellm.suppress_debug_info = True
|
||||
litellm.set_verbose = False
|
||||
|
||||
# Explicitly configure LiteLLM's loggers
|
||||
for logger_name in ["litellm", "LiteLLM"]:
|
||||
litellm_logger = logging.getLogger(logger_name)
|
||||
litellm_logger.setLevel(logging.WARNING)
|
||||
litellm_logger.propagate = True
|
||||
|
||||
# Use litellm's internal method to disable debugging
|
||||
if hasattr(litellm, "_logging") and hasattr(litellm._logging, "_disable_debugging"):
|
||||
litellm._logging._disable_debugging()
|
||||
|
||||
from langgraph.checkpoint.memory import MemorySaver
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
|
|
@ -99,13 +83,148 @@ from ra_aid.tools.human import ask_human
|
|||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
# Configure litellm to suppress debug logs
|
||||
os.environ["LITELLM_LOG"] = "ERROR"
|
||||
litellm.suppress_debug_info = True
|
||||
litellm.set_verbose = False
|
||||
|
||||
def launch_webui(host: str, port: int):
|
||||
# Explicitly configure LiteLLM's loggers
|
||||
for logger_name in ["litellm", "LiteLLM"]:
|
||||
litellm_logger = logging.getLogger(logger_name)
|
||||
litellm_logger.setLevel(logging.WARNING)
|
||||
litellm_logger.propagate = True
|
||||
|
||||
# Use litellm's internal method to disable debugging
|
||||
if hasattr(litellm, "_logging") and hasattr(litellm._logging, "_disable_debugging"):
|
||||
litellm._logging._disable_debugging()
|
||||
|
||||
|
||||
def launch_server(host: str, port: int, args):
|
||||
"""Launch the RA.Aid web interface."""
|
||||
from ra_aid.webui import run_server
|
||||
from ra_aid.server import run_server
|
||||
from ra_aid.database.connection import DatabaseManager
|
||||
from ra_aid.database.repositories.session_repository import SessionRepositoryManager
|
||||
from ra_aid.database.repositories.key_fact_repository import KeyFactRepositoryManager
|
||||
from ra_aid.database.repositories.key_snippet_repository import KeySnippetRepositoryManager
|
||||
from ra_aid.database.repositories.human_input_repository import HumanInputRepositoryManager
|
||||
from ra_aid.database.repositories.research_note_repository import ResearchNoteRepositoryManager
|
||||
from ra_aid.database.repositories.related_files_repository import RelatedFilesRepositoryManager
|
||||
from ra_aid.database.repositories.trajectory_repository import TrajectoryRepositoryManager
|
||||
from ra_aid.database.repositories.work_log_repository import WorkLogRepositoryManager
|
||||
from ra_aid.database.repositories.config_repository import ConfigRepositoryManager
|
||||
from ra_aid.env_inv_context import EnvInvManager
|
||||
from ra_aid.env_inv import EnvDiscovery
|
||||
|
||||
# Set the console handler level to INFO for server mode
|
||||
# Get the root logger and modify the console handler
|
||||
root_logger = logging.getLogger()
|
||||
for handler in root_logger.handlers:
|
||||
# Check if this is a console handler (outputs to stdout/stderr)
|
||||
if isinstance(handler, logging.StreamHandler) and handler.stream in [sys.stdout, sys.stderr]:
|
||||
# Set console handler to INFO level for better visibility in server mode
|
||||
handler.setLevel(logging.INFO)
|
||||
logger.debug("Modified console logging level to INFO for server mode")
|
||||
|
||||
# Apply any pending database migrations
|
||||
from ra_aid.database import ensure_migrations_applied
|
||||
try:
|
||||
migration_result = ensure_migrations_applied()
|
||||
if not migration_result:
|
||||
logger.warning("Database migrations failed but execution will continue")
|
||||
except Exception as e:
|
||||
logger.error(f"Database migration error: {str(e)}")
|
||||
|
||||
# Check dependencies before proceeding
|
||||
check_dependencies()
|
||||
|
||||
# Validate environment (expert_enabled, web_research_enabled)
|
||||
(
|
||||
expert_enabled,
|
||||
expert_missing,
|
||||
web_research_enabled,
|
||||
web_research_missing,
|
||||
) = validate_environment(
|
||||
args
|
||||
) # Will exit if main env vars missing
|
||||
logger.debug("Environment validation successful")
|
||||
|
||||
# Validate model configuration early
|
||||
model_config = models_params.get(args.provider, {}).get(
|
||||
args.model or "", {}
|
||||
)
|
||||
supports_temperature = model_config.get(
|
||||
"supports_temperature",
|
||||
args.provider
|
||||
in [
|
||||
"anthropic",
|
||||
"openai",
|
||||
"openrouter",
|
||||
"openai-compatible",
|
||||
"deepseek",
|
||||
],
|
||||
)
|
||||
|
||||
if supports_temperature and args.temperature is None:
|
||||
args.temperature = model_config.get("default_temperature")
|
||||
if args.temperature is None:
|
||||
cpm(
|
||||
f"This model supports temperature argument but none was given. Setting default temperature to {DEFAULT_TEMPERATURE}."
|
||||
)
|
||||
args.temperature = DEFAULT_TEMPERATURE
|
||||
logger.debug(
|
||||
f"Using default temperature {args.temperature} for model {args.model}"
|
||||
)
|
||||
|
||||
# Initialize config dictionary with values from args and environment validation
|
||||
config = {
|
||||
"provider": args.provider,
|
||||
"model": args.model,
|
||||
"expert_provider": args.expert_provider,
|
||||
"expert_model": args.expert_model,
|
||||
"temperature": args.temperature,
|
||||
"experimental_fallback_handler": args.experimental_fallback_handler,
|
||||
"expert_enabled": expert_enabled,
|
||||
"web_research_enabled": web_research_enabled,
|
||||
"show_thoughts": args.show_thoughts,
|
||||
"show_cost": args.show_cost,
|
||||
"force_reasoning_assistance": args.reasoning_assistance,
|
||||
"disable_reasoning_assistance": args.no_reasoning_assistance
|
||||
}
|
||||
|
||||
# Initialize environment discovery
|
||||
env_discovery = EnvDiscovery()
|
||||
env_discovery.discover()
|
||||
env_data = env_discovery.format_markdown()
|
||||
|
||||
print(f"Starting RA.Aid web interface on http://{host}:{port}")
|
||||
run_server(host=host, port=port)
|
||||
|
||||
# Initialize database connection and repositories
|
||||
with DatabaseManager() as db, \
|
||||
SessionRepositoryManager(db) as session_repo, \
|
||||
KeyFactRepositoryManager(db) as key_fact_repo, \
|
||||
KeySnippetRepositoryManager(db) as key_snippet_repo, \
|
||||
HumanInputRepositoryManager(db) as human_input_repo, \
|
||||
ResearchNoteRepositoryManager(db) as research_note_repo, \
|
||||
RelatedFilesRepositoryManager() as related_files_repo, \
|
||||
TrajectoryRepositoryManager(db) as trajectory_repo, \
|
||||
WorkLogRepositoryManager() as work_log_repo, \
|
||||
ConfigRepositoryManager(config) as config_repo, \
|
||||
EnvInvManager(env_data) as env_inv:
|
||||
|
||||
# This initializes all repositories and makes them available via their respective get methods
|
||||
logger.debug("Initialized SessionRepository")
|
||||
logger.debug("Initialized KeyFactRepository")
|
||||
logger.debug("Initialized KeySnippetRepository")
|
||||
logger.debug("Initialized HumanInputRepository")
|
||||
logger.debug("Initialized ResearchNoteRepository")
|
||||
logger.debug("Initialized RelatedFilesRepository")
|
||||
logger.debug("Initialized TrajectoryRepository")
|
||||
logger.debug("Initialized WorkLogRepository")
|
||||
logger.debug("Initialized ConfigRepository")
|
||||
logger.debug("Initialized Environment Inventory")
|
||||
|
||||
# Run the server within the context managers
|
||||
run_server(host=host, port=port)
|
||||
|
||||
|
||||
def parse_arguments(args=None):
|
||||
|
|
@ -275,21 +394,21 @@ Examples:
|
|||
help=f"Timeout in seconds for test command execution (default: {DEFAULT_TEST_CMD_TIMEOUT})",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--webui",
|
||||
"--server",
|
||||
action="store_true",
|
||||
help="Launch the web interface",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--webui-host",
|
||||
"--server-host",
|
||||
type=str,
|
||||
default="0.0.0.0",
|
||||
help="Host to listen on for web interface (default: 0.0.0.0)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--webui-port",
|
||||
"--server-port",
|
||||
type=int,
|
||||
default=8080,
|
||||
help="Port to listen on for web interface (default: 8080)",
|
||||
default=1818,
|
||||
help="Port to listen on for web interface (default: 1818)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--wipe-project-memory",
|
||||
|
|
@ -521,8 +640,8 @@ def main():
|
|||
print(f"📋 {result}")
|
||||
|
||||
# Launch web interface if requested
|
||||
if args.webui:
|
||||
launch_webui(args.webui_host, args.webui_port)
|
||||
if args.server:
|
||||
launch_server(args.server_host, args.server_port, args)
|
||||
return
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -825,7 +825,8 @@ class CiaynAgent:
|
|||
try:
|
||||
last_result = self._execute_tool(response)
|
||||
self.chat_history.append(response)
|
||||
self.fallback_handler.reset_fallback_handler()
|
||||
if hasattr(self.fallback_handler, 'reset_fallback_handler'):
|
||||
self.fallback_handler.reset_fallback_handler()
|
||||
yield {}
|
||||
|
||||
except ToolExecutionError as e:
|
||||
|
|
|
|||
|
|
@ -51,7 +51,13 @@ from ra_aid.database.repositories.human_input_repository import (
|
|||
)
|
||||
from ra_aid.database.repositories.trajectory_repository import get_trajectory_repository
|
||||
from ra_aid.database.repositories.config_repository import get_config_repository
|
||||
from ra_aid.anthropic_token_limiter import sonnet_35_state_modifier, state_modifier, get_model_token_limit
|
||||
from ra_aid.anthropic_token_limiter import (
|
||||
get_model_name_from_chat_model,
|
||||
sonnet_35_state_modifier,
|
||||
state_modifier,
|
||||
get_model_token_limit,
|
||||
)
|
||||
from ra_aid.model_detection import is_anthropic_claude
|
||||
|
||||
console = Console()
|
||||
|
||||
|
|
@ -67,8 +73,6 @@ def output_markdown_message(message: str) -> str:
|
|||
return "Message output."
|
||||
|
||||
|
||||
|
||||
|
||||
def build_agent_kwargs(
|
||||
checkpointer: Optional[Any] = None,
|
||||
model: ChatAnthropic = None,
|
||||
|
|
@ -99,8 +103,15 @@ def build_agent_kwargs(
|
|||
):
|
||||
|
||||
def wrapped_state_modifier(state: AgentState) -> list[BaseMessage]:
|
||||
if any(pattern in model.model for pattern in ["claude-3.5", "claude3.5", "claude-3-5"]):
|
||||
return sonnet_35_state_modifier(state, max_input_tokens=max_input_tokens)
|
||||
model_name = get_model_name_from_chat_model(model)
|
||||
|
||||
if any(
|
||||
pattern in model_name
|
||||
for pattern in ["claude-3.5", "claude3.5", "claude-3-5"]
|
||||
):
|
||||
return sonnet_35_state_modifier(
|
||||
state, max_input_tokens=max_input_tokens
|
||||
)
|
||||
|
||||
return state_modifier(state, model, max_input_tokens=max_input_tokens)
|
||||
|
||||
|
|
@ -110,27 +121,6 @@ def build_agent_kwargs(
|
|||
return agent_kwargs
|
||||
|
||||
|
||||
def is_anthropic_claude(config: Dict[str, Any]) -> bool:
|
||||
"""Check if the provider and model name indicate an Anthropic Claude model.
|
||||
|
||||
Args:
|
||||
config: Configuration dictionary containing provider and model information
|
||||
|
||||
Returns:
|
||||
bool: True if this is an Anthropic Claude model
|
||||
"""
|
||||
# For backwards compatibility, allow passing of config directly
|
||||
provider = config.get("provider", "")
|
||||
model_name = config.get("model", "")
|
||||
result = (
|
||||
provider.lower() == "anthropic"
|
||||
and model_name
|
||||
and "claude" in model_name.lower()
|
||||
) or (
|
||||
provider.lower() == "openrouter"
|
||||
and model_name.lower().startswith("anthropic/claude-")
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def create_agent(
|
||||
|
|
@ -169,7 +159,7 @@ def create_agent(
|
|||
# So we'll use the passed config directly
|
||||
pass
|
||||
max_input_tokens = (
|
||||
get_model_token_limit(config, agent_type) or DEFAULT_TOKEN_LIMIT
|
||||
get_model_token_limit(config, agent_type, model) or DEFAULT_TOKEN_LIMIT
|
||||
)
|
||||
|
||||
# Use REACT agent for Anthropic Claude models, otherwise use CIAYN
|
||||
|
|
@ -188,7 +178,7 @@ def create_agent(
|
|||
# Default to REACT agent if provider/model detection fails
|
||||
logger.warning(f"Failed to detect model type: {e}. Defaulting to REACT agent.")
|
||||
config = get_config_repository().get_all()
|
||||
max_input_tokens = get_model_token_limit(config, agent_type)
|
||||
max_input_tokens = get_model_token_limit(config, agent_type, model)
|
||||
agent_kwargs = build_agent_kwargs(checkpointer, model, max_input_tokens)
|
||||
return create_react_agent(
|
||||
model, tools, interrupt_after=["tools"], **agent_kwargs
|
||||
|
|
@ -289,7 +279,7 @@ def _handle_api_error(e, attempt, max_retries, base_delay):
|
|||
logger.warning("API error (attempt %d/%d): %s", attempt + 1, max_retries, str(e))
|
||||
delay = base_delay * (2**attempt)
|
||||
error_message = f"Encountered {e.__class__.__name__}: {e}. Retrying in {delay}s... (Attempt {attempt+1}/{max_retries})"
|
||||
|
||||
|
||||
# Record error in trajectory
|
||||
trajectory_repo = get_trajectory_repository()
|
||||
human_input_id = get_human_input_repository().get_most_recent_id()
|
||||
|
|
@ -301,9 +291,9 @@ def _handle_api_error(e, attempt, max_retries, base_delay):
|
|||
record_type="error",
|
||||
human_input_id=human_input_id,
|
||||
is_error=True,
|
||||
error_message=error_message
|
||||
error_message=error_message,
|
||||
)
|
||||
|
||||
|
||||
print_error(error_message)
|
||||
start = time.monotonic()
|
||||
while time.monotonic() - start < delay:
|
||||
|
|
@ -464,7 +454,9 @@ def run_agent_with_retry(
|
|||
|
||||
try:
|
||||
_run_agent_stream(agent, msg_list)
|
||||
if fallback_handler:
|
||||
if fallback_handler and hasattr(
|
||||
fallback_handler, "reset_fallback_handler"
|
||||
):
|
||||
fallback_handler.reset_fallback_handler()
|
||||
should_break, prompt, auto_test, test_attempts = (
|
||||
_execute_test_command_wrapper(
|
||||
|
|
|
|||
|
|
@ -1,31 +1,27 @@
|
|||
"""Utilities for handling token limits with Anthropic models."""
|
||||
|
||||
from functools import partial
|
||||
from typing import Any, Dict, List, Optional, Sequence
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple
|
||||
from langchain_core.language_models import BaseChatModel
|
||||
from ra_aid.config import DEFAULT_MODEL
|
||||
from ra_aid.model_detection import is_claude_37
|
||||
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
from langchain_core.messages import (
|
||||
AIMessage,
|
||||
BaseMessage,
|
||||
RemoveMessage,
|
||||
ToolMessage,
|
||||
trim_messages,
|
||||
)
|
||||
from langchain_core.messages.base import message_to_dict
|
||||
|
||||
from ra_aid.anthropic_message_utils import (
|
||||
anthropic_trim_messages,
|
||||
has_tool_use,
|
||||
)
|
||||
from langgraph.prebuilt.chat_agent_executor import AgentState
|
||||
from litellm import token_counter
|
||||
from litellm import token_counter, get_model_info
|
||||
|
||||
from ra_aid.agent_backends.ciayn_agent import CiaynAgent
|
||||
from ra_aid.database.repositories.config_repository import get_config_repository
|
||||
from ra_aid.logging_config import get_logger
|
||||
from ra_aid.models_params import DEFAULT_TOKEN_LIMIT, models_params
|
||||
from ra_aid.console.output import cpm, print_messages_compact
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
|
@ -95,7 +91,7 @@ def create_token_counter_wrapper(model: str):
|
|||
|
||||
|
||||
def state_modifier(
|
||||
state: AgentState, model: ChatAnthropic, max_input_tokens: int = DEFAULT_TOKEN_LIMIT
|
||||
state: AgentState, model: BaseChatModel, max_input_tokens: int = DEFAULT_TOKEN_LIMIT
|
||||
) -> list[BaseMessage]:
|
||||
"""Given the agent state and max_tokens, return a trimmed list of messages.
|
||||
|
||||
|
|
@ -114,7 +110,8 @@ def state_modifier(
|
|||
if not messages:
|
||||
return []
|
||||
|
||||
wrapped_token_counter = create_token_counter_wrapper(model.model)
|
||||
model_name = get_model_name_from_chat_model(model)
|
||||
wrapped_token_counter = create_token_counter_wrapper(model_name)
|
||||
|
||||
result = anthropic_trim_messages(
|
||||
messages,
|
||||
|
|
@ -127,7 +124,9 @@ def state_modifier(
|
|||
)
|
||||
|
||||
if len(result) < len(messages):
|
||||
logger.info(f"Anthropic Token Limiter Trimmed: {len(messages)} messages → {len(result)} messages")
|
||||
logger.info(
|
||||
f"Anthropic Token Limiter Trimmed: {len(messages)} messages → {len(result)} messages"
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
|
@ -168,14 +167,89 @@ def sonnet_35_state_modifier(
|
|||
return result
|
||||
|
||||
|
||||
def get_provider_and_model_for_agent_type(
|
||||
config: Dict[str, Any], agent_type: str
|
||||
) -> Tuple[str, str]:
|
||||
"""Get the provider and model name for the specified agent type.
|
||||
|
||||
Args:
|
||||
config: Configuration dictionary containing provider and model information
|
||||
agent_type: Type of agent ("default", "research", or "planner")
|
||||
|
||||
Returns:
|
||||
Tuple[str, str]: A tuple containing (provider, model_name)
|
||||
"""
|
||||
if agent_type == "research":
|
||||
provider = config.get("research_provider", "") or config.get("provider", "")
|
||||
model_name = config.get("research_model", "") or config.get("model", "")
|
||||
elif agent_type == "planner":
|
||||
provider = config.get("planner_provider", "") or config.get("provider", "")
|
||||
model_name = config.get("planner_model", "") or config.get("model", "")
|
||||
else:
|
||||
provider = config.get("provider", "")
|
||||
model_name = config.get("model", "")
|
||||
|
||||
return provider, model_name
|
||||
|
||||
|
||||
def get_model_name_from_chat_model(model: Optional[BaseChatModel]) -> str:
|
||||
"""Extract the model name from a BaseChatModel instance.
|
||||
|
||||
Args:
|
||||
model: The BaseChatModel instance
|
||||
|
||||
Returns:
|
||||
str: The model name extracted from the instance, or DEFAULT_MODEL if not found
|
||||
"""
|
||||
if model is None:
|
||||
return DEFAULT_MODEL
|
||||
|
||||
if hasattr(model, "model"):
|
||||
return model.model
|
||||
elif hasattr(model, "model_name"):
|
||||
return model.model_name
|
||||
else:
|
||||
logger.debug(f"Could not extract model name from {model}, using DEFAULT_MODEL")
|
||||
return DEFAULT_MODEL
|
||||
|
||||
|
||||
def adjust_claude_37_token_limit(
|
||||
max_input_tokens: int, model: Optional[BaseChatModel]
|
||||
) -> Optional[int]:
|
||||
"""Adjust token limit for Claude 3.7 models by subtracting max_tokens.
|
||||
|
||||
Args:
|
||||
max_input_tokens: The original token limit
|
||||
model: The model instance to check
|
||||
|
||||
Returns:
|
||||
Optional[int]: Adjusted token limit if model is Claude 3.7, otherwise original limit
|
||||
"""
|
||||
if not max_input_tokens:
|
||||
return max_input_tokens
|
||||
|
||||
if model and hasattr(model, "model") and is_claude_37(model.model):
|
||||
if hasattr(model, "max_tokens") and model.max_tokens:
|
||||
effective_max_input_tokens = max_input_tokens - model.max_tokens
|
||||
logger.debug(
|
||||
f"Adjusting token limit for Claude 3.7 model: {max_input_tokens} - {model.max_tokens} = {effective_max_input_tokens}"
|
||||
)
|
||||
return effective_max_input_tokens
|
||||
|
||||
return max_input_tokens
|
||||
|
||||
|
||||
def get_model_token_limit(
|
||||
config: Dict[str, Any], agent_type: str = "default"
|
||||
config: Dict[str, Any],
|
||||
agent_type: str = "default",
|
||||
model: Optional[BaseChatModel] = None,
|
||||
) -> Optional[int]:
|
||||
"""Get the token limit for the current model configuration based on agent type.
|
||||
|
||||
Args:
|
||||
config: Configuration dictionary containing provider and model information
|
||||
agent_type: Type of agent ("default", "research", or "planner")
|
||||
model: Optional BaseChatModel instance to check for model-specific attributes
|
||||
|
||||
Returns:
|
||||
Optional[int]: The token limit if found, None otherwise
|
||||
|
|
@ -190,27 +264,20 @@ def get_model_token_limit(
|
|||
# In tests, this may fail because the repository isn't set up
|
||||
# So we'll use the passed config directly
|
||||
pass
|
||||
if agent_type == "research":
|
||||
provider = config.get("research_provider", "") or config.get("provider", "")
|
||||
model_name = config.get("research_model", "") or config.get("model", "")
|
||||
elif agent_type == "planner":
|
||||
provider = config.get("planner_provider", "") or config.get("provider", "")
|
||||
model_name = config.get("planner_model", "") or config.get("model", "")
|
||||
else:
|
||||
provider = config.get("provider", "")
|
||||
model_name = config.get("model", "")
|
||||
|
||||
provider, model_name = get_provider_and_model_for_agent_type(config, agent_type)
|
||||
|
||||
# Always attempt to get model info from litellm first
|
||||
provider_model = model_name if not provider else f"{provider}/{model_name}"
|
||||
|
||||
try:
|
||||
from litellm import get_model_info
|
||||
|
||||
provider_model = model_name if not provider else f"{provider}/{model_name}"
|
||||
model_info = get_model_info(provider_model)
|
||||
max_input_tokens = model_info.get("max_input_tokens")
|
||||
if max_input_tokens:
|
||||
logger.debug(
|
||||
f"Using litellm token limit for {model_name}: {max_input_tokens}"
|
||||
)
|
||||
return max_input_tokens
|
||||
return adjust_claude_37_token_limit(max_input_tokens, model)
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
f"Error getting model info from litellm: {e}, falling back to models_params"
|
||||
|
|
@ -229,7 +296,7 @@ def get_model_token_limit(
|
|||
max_input_tokens = None
|
||||
logger.debug(f"Could not find token limit for {provider}/{model_name}")
|
||||
|
||||
return max_input_tokens
|
||||
return adjust_claude_37_token_limit(max_input_tokens, model)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to get model token limit: {e}")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,376 @@
|
|||
"""
|
||||
Pydantic models for ra_aid database entities.
|
||||
|
||||
This module defines Pydantic models that correspond to Peewee ORM models,
|
||||
providing validation, serialization, and deserialization capabilities.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import json
|
||||
from typing import Dict, List, Any, Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator
|
||||
|
||||
|
||||
class SessionModel(BaseModel):
|
||||
"""
|
||||
Pydantic model representing a Session.
|
||||
|
||||
This model corresponds to the Session Peewee ORM model and provides
|
||||
validation and serialization capabilities. It handles the conversion
|
||||
between JSON-encoded strings and Python dictionaries for the machine_info field.
|
||||
|
||||
Attributes:
|
||||
id: Unique identifier for the session
|
||||
created_at: When the session record was created
|
||||
updated_at: When the session record was last updated
|
||||
start_time: When the program session started
|
||||
command_line: Command line arguments used to start the program
|
||||
program_version: Version of the program
|
||||
machine_info: Dictionary containing machine-specific metadata
|
||||
"""
|
||||
id: Optional[int] = None
|
||||
created_at: datetime.datetime
|
||||
updated_at: datetime.datetime
|
||||
start_time: datetime.datetime
|
||||
command_line: Optional[str] = None
|
||||
program_version: Optional[str] = None
|
||||
machine_info: Optional[Dict[str, Any]] = None
|
||||
|
||||
# Configure the model to work with ORM objects
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@field_validator("machine_info", mode="before")
|
||||
@classmethod
|
||||
def parse_machine_info(cls, value: Any) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Parse the machine_info field from a JSON string to a dictionary.
|
||||
|
||||
Args:
|
||||
value: The value to parse, can be a string, dict, or None
|
||||
|
||||
Returns:
|
||||
Optional[Dict[str, Any]]: The parsed dictionary or None
|
||||
|
||||
Raises:
|
||||
ValueError: If the JSON string is invalid
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"Invalid JSON in machine_info: {e}")
|
||||
|
||||
raise ValueError(f"Unexpected type for machine_info: {type(value)}")
|
||||
|
||||
@field_serializer("machine_info")
|
||||
def serialize_machine_info(self, machine_info: Optional[Dict[str, Any]]) -> Optional[str]:
|
||||
"""
|
||||
Serialize the machine_info dictionary to a JSON string for storage.
|
||||
|
||||
Args:
|
||||
machine_info: Dictionary to serialize
|
||||
|
||||
Returns:
|
||||
Optional[str]: JSON-encoded string or None
|
||||
"""
|
||||
if machine_info is None:
|
||||
return None
|
||||
|
||||
return json.dumps(machine_info)
|
||||
|
||||
|
||||
class HumanInputModel(BaseModel):
|
||||
"""
|
||||
Pydantic model representing a HumanInput.
|
||||
|
||||
This model corresponds to the HumanInput Peewee ORM model and provides
|
||||
validation and serialization capabilities.
|
||||
|
||||
Attributes:
|
||||
id: Unique identifier for the human input
|
||||
created_at: When the record was created
|
||||
updated_at: When the record was last updated
|
||||
content: The text content of the input
|
||||
source: The source of the input ('cli', 'chat', or 'hil')
|
||||
session_id: Optional reference to the associated session
|
||||
"""
|
||||
id: Optional[int] = None
|
||||
created_at: datetime.datetime
|
||||
updated_at: datetime.datetime
|
||||
content: str
|
||||
source: str
|
||||
session_id: Optional[int] = None
|
||||
|
||||
# Configure the model to work with ORM objects
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class KeyFactModel(BaseModel):
|
||||
"""
|
||||
Pydantic model representing a KeyFact.
|
||||
|
||||
This model corresponds to the KeyFact Peewee ORM model and provides
|
||||
validation and serialization capabilities.
|
||||
|
||||
Attributes:
|
||||
id: Unique identifier for the key fact
|
||||
created_at: When the record was created
|
||||
updated_at: When the record was last updated
|
||||
content: The text content of the key fact
|
||||
human_input_id: Optional reference to the associated human input
|
||||
session_id: Optional reference to the associated session
|
||||
"""
|
||||
id: Optional[int] = None
|
||||
created_at: datetime.datetime
|
||||
updated_at: datetime.datetime
|
||||
content: str
|
||||
human_input_id: Optional[int] = None
|
||||
session_id: Optional[int] = None
|
||||
|
||||
# Configure the model to work with ORM objects
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class KeySnippetModel(BaseModel):
|
||||
"""
|
||||
Pydantic model representing a KeySnippet.
|
||||
|
||||
This model corresponds to the KeySnippet Peewee ORM model and provides
|
||||
validation and serialization capabilities.
|
||||
|
||||
Attributes:
|
||||
id: Unique identifier for the key snippet
|
||||
created_at: When the record was created
|
||||
updated_at: When the record was last updated
|
||||
filepath: Path to the source file
|
||||
line_number: Line number where the snippet starts
|
||||
snippet: The source code snippet text
|
||||
description: Optional description of the significance
|
||||
human_input_id: Optional reference to the associated human input
|
||||
session_id: Optional reference to the associated session
|
||||
"""
|
||||
id: Optional[int] = None
|
||||
created_at: datetime.datetime
|
||||
updated_at: datetime.datetime
|
||||
filepath: str
|
||||
line_number: int
|
||||
snippet: str
|
||||
description: Optional[str] = None
|
||||
human_input_id: Optional[int] = None
|
||||
session_id: Optional[int] = None
|
||||
|
||||
# Configure the model to work with ORM objects
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class ResearchNoteModel(BaseModel):
|
||||
"""
|
||||
Pydantic model representing a ResearchNote.
|
||||
|
||||
This model corresponds to the ResearchNote Peewee ORM model and provides
|
||||
validation and serialization capabilities.
|
||||
|
||||
Attributes:
|
||||
id: Unique identifier for the research note
|
||||
created_at: When the record was created
|
||||
updated_at: When the record was last updated
|
||||
content: The text content of the research note
|
||||
human_input_id: Optional reference to the associated human input
|
||||
session_id: Optional reference to the associated session
|
||||
"""
|
||||
id: Optional[int] = None
|
||||
created_at: datetime.datetime
|
||||
updated_at: datetime.datetime
|
||||
content: str
|
||||
human_input_id: Optional[int] = None
|
||||
session_id: Optional[int] = None
|
||||
|
||||
# Configure the model to work with ORM objects
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class TrajectoryModel(BaseModel):
|
||||
"""
|
||||
Pydantic model representing a Trajectory.
|
||||
|
||||
This model corresponds to the Trajectory Peewee ORM model and provides
|
||||
validation and serialization capabilities. It handles the conversion
|
||||
between JSON-encoded strings and Python dictionaries for the tool_parameters,
|
||||
tool_result, and step_data fields.
|
||||
|
||||
Attributes:
|
||||
id: Unique identifier for the trajectory
|
||||
created_at: When the record was created
|
||||
updated_at: When the record was last updated
|
||||
human_input_id: Optional reference to the associated human input
|
||||
tool_name: Name of the tool that was executed
|
||||
tool_parameters: Dictionary containing the parameters passed to the tool
|
||||
tool_result: Dictionary containing the result returned by the tool
|
||||
step_data: Dictionary containing UI rendering data
|
||||
record_type: Type of trajectory record
|
||||
cost: Optional cost of the tool execution
|
||||
tokens: Optional token usage of the tool execution
|
||||
is_error: Flag indicating if this record represents an error
|
||||
error_message: The error message if is_error is True
|
||||
error_type: The type/class of the error if is_error is True
|
||||
error_details: Additional error details if is_error is True
|
||||
session_id: Optional reference to the associated session
|
||||
"""
|
||||
id: Optional[int] = None
|
||||
created_at: datetime.datetime
|
||||
updated_at: datetime.datetime
|
||||
human_input_id: Optional[int] = None
|
||||
tool_name: Optional[str] = None
|
||||
tool_parameters: Optional[Dict[str, Any]] = None
|
||||
tool_result: Optional[Any] = None
|
||||
step_data: Optional[Dict[str, Any]] = None
|
||||
record_type: Optional[str] = None
|
||||
cost: Optional[float] = None
|
||||
tokens: Optional[int] = None
|
||||
is_error: bool = False
|
||||
error_message: Optional[str] = None
|
||||
error_type: Optional[str] = None
|
||||
error_details: Optional[str] = None
|
||||
session_id: Optional[int] = None
|
||||
|
||||
# Configure the model to work with ORM objects
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@field_validator("tool_parameters", mode="before")
|
||||
@classmethod
|
||||
def parse_tool_parameters(cls, value: Any) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Parse the tool_parameters field from a JSON string to a dictionary.
|
||||
|
||||
Args:
|
||||
value: The value to parse, can be a string, dict, or None
|
||||
|
||||
Returns:
|
||||
Optional[Dict[str, Any]]: The parsed dictionary or None
|
||||
|
||||
Raises:
|
||||
ValueError: If the JSON string is invalid
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"Invalid JSON in tool_parameters: {e}")
|
||||
|
||||
raise ValueError(f"Unexpected type for tool_parameters: {type(value)}")
|
||||
|
||||
@field_validator("tool_result", mode="before")
|
||||
@classmethod
|
||||
def parse_tool_result(cls, value: Any) -> Optional[Any]:
|
||||
"""
|
||||
Parse the tool_result field from a JSON string to a Python object.
|
||||
|
||||
Args:
|
||||
value: The value to parse, can be a string, dict, list, or None
|
||||
|
||||
Returns:
|
||||
Optional[Any]: The parsed object or None
|
||||
|
||||
Raises:
|
||||
ValueError: If the JSON string is invalid
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if not isinstance(value, str):
|
||||
return value
|
||||
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"Invalid JSON in tool_result: {e}")
|
||||
|
||||
@field_validator("step_data", mode="before")
|
||||
@classmethod
|
||||
def parse_step_data(cls, value: Any) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Parse the step_data field from a JSON string to a dictionary.
|
||||
|
||||
Args:
|
||||
value: The value to parse, can be a string, dict, or None
|
||||
|
||||
Returns:
|
||||
Optional[Dict[str, Any]]: The parsed dictionary or None
|
||||
|
||||
Raises:
|
||||
ValueError: If the JSON string is invalid
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if isinstance(value, dict):
|
||||
return value
|
||||
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"Invalid JSON in step_data: {e}")
|
||||
|
||||
raise ValueError(f"Unexpected type for step_data: {type(value)}")
|
||||
|
||||
@field_serializer("tool_parameters")
|
||||
def serialize_tool_parameters(self, tool_parameters: Optional[Dict[str, Any]]) -> Optional[str]:
|
||||
"""
|
||||
Serialize the tool_parameters dictionary to a JSON string for storage.
|
||||
|
||||
Args:
|
||||
tool_parameters: Dictionary to serialize
|
||||
|
||||
Returns:
|
||||
Optional[str]: JSON-encoded string or None
|
||||
"""
|
||||
if tool_parameters is None:
|
||||
return None
|
||||
|
||||
return json.dumps(tool_parameters)
|
||||
|
||||
@field_serializer("tool_result")
|
||||
def serialize_tool_result(self, tool_result: Optional[Any]) -> Optional[str]:
|
||||
"""
|
||||
Serialize the tool_result object to a JSON string for storage.
|
||||
|
||||
Args:
|
||||
tool_result: Object to serialize
|
||||
|
||||
Returns:
|
||||
Optional[str]: JSON-encoded string or None
|
||||
"""
|
||||
if tool_result is None:
|
||||
return None
|
||||
|
||||
return json.dumps(tool_result)
|
||||
|
||||
@field_serializer("step_data")
|
||||
def serialize_step_data(self, step_data: Optional[Dict[str, Any]]) -> Optional[str]:
|
||||
"""
|
||||
Serialize the step_data dictionary to a JSON string for storage.
|
||||
|
||||
Args:
|
||||
step_data: Dictionary to serialize
|
||||
|
||||
Returns:
|
||||
Optional[str]: JSON-encoded string or None
|
||||
"""
|
||||
if step_data is None:
|
||||
return None
|
||||
|
||||
return json.dumps(step_data)
|
||||
|
|
@ -11,6 +11,7 @@ import contextvars
|
|||
import peewee
|
||||
|
||||
from ra_aid.database.models import HumanInput
|
||||
from ra_aid.database.pydantic_models import HumanInputModel
|
||||
from ra_aid.logging_config import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
|
@ -118,8 +119,23 @@ class HumanInputRepository:
|
|||
if db is None:
|
||||
raise ValueError("Database connection is required for HumanInputRepository")
|
||||
self.db = db
|
||||
|
||||
def _to_model(self, human_input: Optional[HumanInput]) -> Optional[HumanInputModel]:
|
||||
"""
|
||||
Convert a Peewee HumanInput object to a Pydantic HumanInputModel.
|
||||
|
||||
Args:
|
||||
human_input: Peewee HumanInput instance or None
|
||||
|
||||
Returns:
|
||||
Optional[HumanInputModel]: Pydantic model representation or None if human_input is None
|
||||
"""
|
||||
if human_input is None:
|
||||
return None
|
||||
|
||||
return HumanInputModel.model_validate(human_input, from_attributes=True)
|
||||
|
||||
def create(self, content: str, source: str) -> HumanInput:
|
||||
def create(self, content: str, source: str) -> HumanInputModel:
|
||||
"""
|
||||
Create a new human input record in the database.
|
||||
|
||||
|
|
@ -128,7 +144,7 @@ class HumanInputRepository:
|
|||
source: The source of the input (e.g., "cli", "chat", "hil")
|
||||
|
||||
Returns:
|
||||
HumanInput: The newly created human input instance
|
||||
HumanInputModel: The newly created human input instance
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error creating the record
|
||||
|
|
@ -136,12 +152,12 @@ class HumanInputRepository:
|
|||
try:
|
||||
input_record = HumanInput.create(content=content, source=source)
|
||||
logger.debug(f"Created human input ID {input_record.id} from {source}")
|
||||
return input_record
|
||||
return self._to_model(input_record)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to create human input record: {str(e)}")
|
||||
raise
|
||||
|
||||
def get(self, input_id: int) -> Optional[HumanInput]:
|
||||
def get(self, input_id: int) -> Optional[HumanInputModel]:
|
||||
"""
|
||||
Retrieve a human input record by its ID.
|
||||
|
||||
|
|
@ -149,18 +165,19 @@ class HumanInputRepository:
|
|||
input_id: The ID of the human input to retrieve
|
||||
|
||||
Returns:
|
||||
Optional[HumanInput]: The human input instance if found, None otherwise
|
||||
Optional[HumanInputModel]: The human input instance if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return HumanInput.get_or_none(HumanInput.id == input_id)
|
||||
human_input = HumanInput.get_or_none(HumanInput.id == input_id)
|
||||
return self._to_model(human_input)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch human input {input_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def update(self, input_id: int, content: str = None, source: str = None) -> Optional[HumanInput]:
|
||||
def update(self, input_id: int, content: str = None, source: str = None) -> Optional[HumanInputModel]:
|
||||
"""
|
||||
Update an existing human input record.
|
||||
|
||||
|
|
@ -170,14 +187,14 @@ class HumanInputRepository:
|
|||
source: The new source for the human input
|
||||
|
||||
Returns:
|
||||
Optional[HumanInput]: The updated human input if found, None otherwise
|
||||
Optional[HumanInputModel]: The updated human input if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error updating the record
|
||||
"""
|
||||
try:
|
||||
# First check if the record exists
|
||||
input_record = self.get(input_id)
|
||||
# We need to get the raw Peewee object for updating
|
||||
input_record = HumanInput.get_or_none(HumanInput.id == input_id)
|
||||
if not input_record:
|
||||
logger.warning(f"Attempted to update non-existent human input {input_id}")
|
||||
return None
|
||||
|
|
@ -190,7 +207,7 @@ class HumanInputRepository:
|
|||
|
||||
input_record.save()
|
||||
logger.debug(f"Updated human input ID {input_id}")
|
||||
return input_record
|
||||
return self._to_model(input_record)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to update human input {input_id}: {str(e)}")
|
||||
raise
|
||||
|
|
@ -223,23 +240,24 @@ class HumanInputRepository:
|
|||
logger.error(f"Failed to delete human input {input_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_all(self) -> List[HumanInput]:
|
||||
def get_all(self) -> List[HumanInputModel]:
|
||||
"""
|
||||
Retrieve all human input records from the database.
|
||||
|
||||
Returns:
|
||||
List[HumanInput]: List of all human input instances
|
||||
List[HumanInputModel]: List of all human input instances
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return list(HumanInput.select().order_by(HumanInput.created_at.desc()))
|
||||
human_inputs = list(HumanInput.select().order_by(HumanInput.created_at.desc()))
|
||||
return [self._to_model(input) for input in human_inputs]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch all human inputs: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_recent(self, limit: int = 10) -> List[HumanInput]:
|
||||
def get_recent(self, limit: int = 10) -> List[HumanInputModel]:
|
||||
"""
|
||||
Retrieve the most recent human input records.
|
||||
|
||||
|
|
@ -247,13 +265,14 @@ class HumanInputRepository:
|
|||
limit: Maximum number of records to retrieve (default: 10)
|
||||
|
||||
Returns:
|
||||
List[HumanInput]: List of the most recent human input records
|
||||
List[HumanInputModel]: List of the most recent human input records
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return list(HumanInput.select().order_by(HumanInput.created_at.desc()).limit(limit))
|
||||
human_inputs = list(HumanInput.select().order_by(HumanInput.created_at.desc()).limit(limit))
|
||||
return [self._to_model(input) for input in human_inputs]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch recent human inputs: {str(e)}")
|
||||
raise
|
||||
|
|
@ -277,7 +296,7 @@ class HumanInputRepository:
|
|||
logger.error(f"Failed to fetch most recent human input ID: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_by_source(self, source: str) -> List[HumanInput]:
|
||||
def get_by_source(self, source: str) -> List[HumanInputModel]:
|
||||
"""
|
||||
Retrieve human input records by source.
|
||||
|
||||
|
|
@ -285,13 +304,14 @@ class HumanInputRepository:
|
|||
source: The source to filter by (e.g., "cli", "chat", "hil")
|
||||
|
||||
Returns:
|
||||
List[HumanInput]: List of human input records from the specified source
|
||||
List[HumanInputModel]: List of human input records from the specified source
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return list(HumanInput.select().where(HumanInput.source == source).order_by(HumanInput.created_at.desc()))
|
||||
human_inputs = list(HumanInput.select().where(HumanInput.source == source).order_by(HumanInput.created_at.desc()))
|
||||
return [self._to_model(input) for input in human_inputs]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch human inputs by source {source}: {str(e)}")
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from contextlib import contextmanager
|
|||
import peewee
|
||||
|
||||
from ra_aid.database.models import KeyFact
|
||||
from ra_aid.database.pydantic_models import KeyFactModel
|
||||
from ra_aid.logging_config import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
|
@ -120,7 +121,22 @@ class KeyFactRepository:
|
|||
raise ValueError("Database connection is required for KeyFactRepository")
|
||||
self.db = db
|
||||
|
||||
def create(self, content: str, human_input_id: Optional[int] = None) -> KeyFact:
|
||||
def _to_model(self, fact: Optional[KeyFact]) -> Optional[KeyFactModel]:
|
||||
"""
|
||||
Convert a Peewee KeyFact object to a Pydantic KeyFactModel.
|
||||
|
||||
Args:
|
||||
fact: Peewee KeyFact instance or None
|
||||
|
||||
Returns:
|
||||
Optional[KeyFactModel]: Pydantic model representation or None if fact is None
|
||||
"""
|
||||
if fact is None:
|
||||
return None
|
||||
|
||||
return KeyFactModel.model_validate(fact, from_attributes=True)
|
||||
|
||||
def create(self, content: str, human_input_id: Optional[int] = None) -> KeyFactModel:
|
||||
"""
|
||||
Create a new key fact in the database.
|
||||
|
||||
|
|
@ -129,7 +145,7 @@ class KeyFactRepository:
|
|||
human_input_id: Optional ID of the associated human input
|
||||
|
||||
Returns:
|
||||
KeyFact: The newly created key fact instance
|
||||
KeyFactModel: The newly created key fact instance
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error creating the fact
|
||||
|
|
@ -137,12 +153,12 @@ class KeyFactRepository:
|
|||
try:
|
||||
fact = KeyFact.create(content=content, human_input_id=human_input_id)
|
||||
logger.debug(f"Created key fact ID {fact.id}: {content}")
|
||||
return fact
|
||||
return self._to_model(fact)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to create key fact: {str(e)}")
|
||||
raise
|
||||
|
||||
def get(self, fact_id: int) -> Optional[KeyFact]:
|
||||
def get(self, fact_id: int) -> Optional[KeyFactModel]:
|
||||
"""
|
||||
Retrieve a key fact by its ID.
|
||||
|
||||
|
|
@ -150,18 +166,19 @@ class KeyFactRepository:
|
|||
fact_id: The ID of the key fact to retrieve
|
||||
|
||||
Returns:
|
||||
Optional[KeyFact]: The key fact instance if found, None otherwise
|
||||
Optional[KeyFactModel]: The key fact instance if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return KeyFact.get_or_none(KeyFact.id == fact_id)
|
||||
fact = KeyFact.get_or_none(KeyFact.id == fact_id)
|
||||
return self._to_model(fact)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch key fact {fact_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def update(self, fact_id: int, content: str) -> Optional[KeyFact]:
|
||||
def update(self, fact_id: int, content: str) -> Optional[KeyFactModel]:
|
||||
"""
|
||||
Update an existing key fact.
|
||||
|
||||
|
|
@ -170,14 +187,14 @@ class KeyFactRepository:
|
|||
content: The new content for the key fact
|
||||
|
||||
Returns:
|
||||
Optional[KeyFact]: The updated key fact if found, None otherwise
|
||||
Optional[KeyFactModel]: The updated key fact if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error updating the fact
|
||||
"""
|
||||
try:
|
||||
# First check if the fact exists
|
||||
fact = self.get(fact_id)
|
||||
fact = KeyFact.get_or_none(KeyFact.id == fact_id)
|
||||
if not fact:
|
||||
logger.warning(f"Attempted to update non-existent key fact {fact_id}")
|
||||
return None
|
||||
|
|
@ -186,7 +203,7 @@ class KeyFactRepository:
|
|||
fact.content = content
|
||||
fact.save()
|
||||
logger.debug(f"Updated key fact ID {fact_id}: {content}")
|
||||
return fact
|
||||
return self._to_model(fact)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to update key fact {fact_id}: {str(e)}")
|
||||
raise
|
||||
|
|
@ -206,7 +223,7 @@ class KeyFactRepository:
|
|||
"""
|
||||
try:
|
||||
# First check if the fact exists
|
||||
fact = self.get(fact_id)
|
||||
fact = KeyFact.get_or_none(KeyFact.id == fact_id)
|
||||
if not fact:
|
||||
logger.warning(f"Attempted to delete non-existent key fact {fact_id}")
|
||||
return False
|
||||
|
|
@ -219,18 +236,19 @@ class KeyFactRepository:
|
|||
logger.error(f"Failed to delete key fact {fact_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_all(self) -> List[KeyFact]:
|
||||
def get_all(self) -> List[KeyFactModel]:
|
||||
"""
|
||||
Retrieve all key facts from the database.
|
||||
|
||||
Returns:
|
||||
List[KeyFact]: List of all key fact instances
|
||||
List[KeyFactModel]: List of all key fact instances
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return list(KeyFact.select().order_by(KeyFact.id))
|
||||
facts = list(KeyFact.select().order_by(KeyFact.id))
|
||||
return [self._to_model(fact) for fact in facts]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch all key facts: {str(e)}")
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import contextvars
|
|||
import peewee
|
||||
|
||||
from ra_aid.database.models import KeySnippet
|
||||
from ra_aid.database.pydantic_models import KeySnippetModel
|
||||
from ra_aid.logging_config import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
|
@ -129,10 +130,25 @@ class KeySnippetRepository:
|
|||
raise ValueError("Database connection is required for KeySnippetRepository")
|
||||
self.db = db
|
||||
|
||||
def _to_model(self, snippet: Optional[KeySnippet]) -> Optional[KeySnippetModel]:
|
||||
"""
|
||||
Convert a Peewee KeySnippet object to a Pydantic KeySnippetModel.
|
||||
|
||||
Args:
|
||||
snippet: Peewee KeySnippet instance or None
|
||||
|
||||
Returns:
|
||||
Optional[KeySnippetModel]: Pydantic model representation or None if snippet is None
|
||||
"""
|
||||
if snippet is None:
|
||||
return None
|
||||
|
||||
return KeySnippetModel.model_validate(snippet, from_attributes=True)
|
||||
|
||||
def create(
|
||||
self, filepath: str, line_number: int, snippet: str, description: Optional[str] = None,
|
||||
human_input_id: Optional[int] = None
|
||||
) -> KeySnippet:
|
||||
) -> KeySnippetModel:
|
||||
"""
|
||||
Create a new key snippet in the database.
|
||||
|
||||
|
|
@ -144,7 +160,7 @@ class KeySnippetRepository:
|
|||
human_input_id: Optional ID of the associated human input
|
||||
|
||||
Returns:
|
||||
KeySnippet: The newly created key snippet instance
|
||||
KeySnippetModel: The newly created key snippet instance
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error creating the snippet
|
||||
|
|
@ -158,12 +174,12 @@ class KeySnippetRepository:
|
|||
human_input_id=human_input_id
|
||||
)
|
||||
logger.debug(f"Created key snippet ID {key_snippet.id}: {filepath}:{line_number}")
|
||||
return key_snippet
|
||||
return self._to_model(key_snippet)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to create key snippet: {str(e)}")
|
||||
raise
|
||||
|
||||
def get(self, snippet_id: int) -> Optional[KeySnippet]:
|
||||
def get(self, snippet_id: int) -> Optional[KeySnippetModel]:
|
||||
"""
|
||||
Retrieve a key snippet by its ID.
|
||||
|
||||
|
|
@ -171,13 +187,14 @@ class KeySnippetRepository:
|
|||
snippet_id: The ID of the key snippet to retrieve
|
||||
|
||||
Returns:
|
||||
Optional[KeySnippet]: The key snippet instance if found, None otherwise
|
||||
Optional[KeySnippetModel]: The key snippet instance if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return KeySnippet.get_or_none(KeySnippet.id == snippet_id)
|
||||
snippet = KeySnippet.get_or_none(KeySnippet.id == snippet_id)
|
||||
return self._to_model(snippet)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch key snippet {snippet_id}: {str(e)}")
|
||||
raise
|
||||
|
|
@ -189,7 +206,7 @@ class KeySnippetRepository:
|
|||
line_number: int,
|
||||
snippet: str,
|
||||
description: Optional[str] = None
|
||||
) -> Optional[KeySnippet]:
|
||||
) -> Optional[KeySnippetModel]:
|
||||
"""
|
||||
Update an existing key snippet.
|
||||
|
||||
|
|
@ -201,14 +218,14 @@ class KeySnippetRepository:
|
|||
description: Optional description of the significance
|
||||
|
||||
Returns:
|
||||
Optional[KeySnippet]: The updated key snippet if found, None otherwise
|
||||
Optional[KeySnippetModel]: The updated key snippet if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error updating the snippet
|
||||
"""
|
||||
try:
|
||||
# First check if the snippet exists
|
||||
key_snippet = self.get(snippet_id)
|
||||
key_snippet = KeySnippet.get_or_none(KeySnippet.id == snippet_id)
|
||||
if not key_snippet:
|
||||
logger.warning(f"Attempted to update non-existent key snippet {snippet_id}")
|
||||
return None
|
||||
|
|
@ -220,7 +237,7 @@ class KeySnippetRepository:
|
|||
key_snippet.description = description
|
||||
key_snippet.save()
|
||||
logger.debug(f"Updated key snippet ID {snippet_id}: {filepath}:{line_number}")
|
||||
return key_snippet
|
||||
return self._to_model(key_snippet)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to update key snippet {snippet_id}: {str(e)}")
|
||||
raise
|
||||
|
|
@ -240,7 +257,7 @@ class KeySnippetRepository:
|
|||
"""
|
||||
try:
|
||||
# First check if the snippet exists
|
||||
key_snippet = self.get(snippet_id)
|
||||
key_snippet = KeySnippet.get_or_none(KeySnippet.id == snippet_id)
|
||||
if not key_snippet:
|
||||
logger.warning(f"Attempted to delete non-existent key snippet {snippet_id}")
|
||||
return False
|
||||
|
|
@ -253,18 +270,19 @@ class KeySnippetRepository:
|
|||
logger.error(f"Failed to delete key snippet {snippet_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_all(self) -> List[KeySnippet]:
|
||||
def get_all(self) -> List[KeySnippetModel]:
|
||||
"""
|
||||
Retrieve all key snippets from the database.
|
||||
|
||||
Returns:
|
||||
List[KeySnippet]: List of all key snippet instances
|
||||
List[KeySnippetModel]: List of all key snippet instances
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return list(KeySnippet.select().order_by(KeySnippet.id))
|
||||
snippets = list(KeySnippet.select().order_by(KeySnippet.id))
|
||||
return [self._to_model(snippet) for snippet in snippets]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch all key snippets: {str(e)}")
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from contextlib import contextmanager
|
|||
import peewee
|
||||
|
||||
from ra_aid.database.models import ResearchNote
|
||||
from ra_aid.database.pydantic_models import ResearchNoteModel
|
||||
from ra_aid.logging_config import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
|
@ -120,7 +121,22 @@ class ResearchNoteRepository:
|
|||
raise ValueError("Database connection is required for ResearchNoteRepository")
|
||||
self.db = db
|
||||
|
||||
def create(self, content: str, human_input_id: Optional[int] = None) -> ResearchNote:
|
||||
def _to_model(self, note: Optional[ResearchNote]) -> Optional[ResearchNoteModel]:
|
||||
"""
|
||||
Convert a Peewee ResearchNote object to a Pydantic ResearchNoteModel.
|
||||
|
||||
Args:
|
||||
note: Peewee ResearchNote instance or None
|
||||
|
||||
Returns:
|
||||
Optional[ResearchNoteModel]: Pydantic model representation or None if note is None
|
||||
"""
|
||||
if note is None:
|
||||
return None
|
||||
|
||||
return ResearchNoteModel.model_validate(note, from_attributes=True)
|
||||
|
||||
def create(self, content: str, human_input_id: Optional[int] = None) -> ResearchNoteModel:
|
||||
"""
|
||||
Create a new research note in the database.
|
||||
|
||||
|
|
@ -129,7 +145,7 @@ class ResearchNoteRepository:
|
|||
human_input_id: Optional ID of the associated human input
|
||||
|
||||
Returns:
|
||||
ResearchNote: The newly created research note instance
|
||||
ResearchNoteModel: The newly created research note instance
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error creating the note
|
||||
|
|
@ -137,12 +153,12 @@ class ResearchNoteRepository:
|
|||
try:
|
||||
note = ResearchNote.create(content=content, human_input_id=human_input_id)
|
||||
logger.debug(f"Created research note ID {note.id}: {content[:50]}...")
|
||||
return note
|
||||
return self._to_model(note)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to create research note: {str(e)}")
|
||||
raise
|
||||
|
||||
def get(self, note_id: int) -> Optional[ResearchNote]:
|
||||
def get(self, note_id: int) -> Optional[ResearchNoteModel]:
|
||||
"""
|
||||
Retrieve a research note by its ID.
|
||||
|
||||
|
|
@ -150,18 +166,19 @@ class ResearchNoteRepository:
|
|||
note_id: The ID of the research note to retrieve
|
||||
|
||||
Returns:
|
||||
Optional[ResearchNote]: The research note instance if found, None otherwise
|
||||
Optional[ResearchNoteModel]: The research note instance if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return ResearchNote.get_or_none(ResearchNote.id == note_id)
|
||||
note = ResearchNote.get_or_none(ResearchNote.id == note_id)
|
||||
return self._to_model(note)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch research note {note_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def update(self, note_id: int, content: str) -> Optional[ResearchNote]:
|
||||
def update(self, note_id: int, content: str) -> Optional[ResearchNoteModel]:
|
||||
"""
|
||||
Update an existing research note.
|
||||
|
||||
|
|
@ -170,14 +187,14 @@ class ResearchNoteRepository:
|
|||
content: The new content for the research note
|
||||
|
||||
Returns:
|
||||
Optional[ResearchNote]: The updated research note if found, None otherwise
|
||||
Optional[ResearchNoteModel]: The updated research note if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error updating the note
|
||||
"""
|
||||
try:
|
||||
# First check if the note exists
|
||||
note = self.get(note_id)
|
||||
note = ResearchNote.get_or_none(ResearchNote.id == note_id)
|
||||
if not note:
|
||||
logger.warning(f"Attempted to update non-existent research note {note_id}")
|
||||
return None
|
||||
|
|
@ -186,7 +203,7 @@ class ResearchNoteRepository:
|
|||
note.content = content
|
||||
note.save()
|
||||
logger.debug(f"Updated research note ID {note_id}: {content[:50]}...")
|
||||
return note
|
||||
return self._to_model(note)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to update research note {note_id}: {str(e)}")
|
||||
raise
|
||||
|
|
@ -206,7 +223,7 @@ class ResearchNoteRepository:
|
|||
"""
|
||||
try:
|
||||
# First check if the note exists
|
||||
note = self.get(note_id)
|
||||
note = ResearchNote.get_or_none(ResearchNote.id == note_id)
|
||||
if not note:
|
||||
logger.warning(f"Attempted to delete non-existent research note {note_id}")
|
||||
return False
|
||||
|
|
@ -219,18 +236,19 @@ class ResearchNoteRepository:
|
|||
logger.error(f"Failed to delete research note {note_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_all(self) -> List[ResearchNote]:
|
||||
def get_all(self) -> List[ResearchNoteModel]:
|
||||
"""
|
||||
Retrieve all research notes from the database.
|
||||
|
||||
Returns:
|
||||
List[ResearchNote]: List of all research note instances
|
||||
List[ResearchNoteModel]: List of all research note instances
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return list(ResearchNote.select().order_by(ResearchNote.id))
|
||||
notes = list(ResearchNote.select().order_by(ResearchNote.id))
|
||||
return [self._to_model(note) for note in notes]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch all research notes: {str(e)}")
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import sys
|
|||
import peewee
|
||||
|
||||
from ra_aid.database.models import Session
|
||||
from ra_aid.database.pydantic_models import SessionModel
|
||||
from ra_aid.__version__ import __version__
|
||||
from ra_aid.logging_config import get_logger
|
||||
|
||||
|
|
@ -120,8 +121,23 @@ class SessionRepository:
|
|||
raise ValueError("Database connection is required for SessionRepository")
|
||||
self.db = db
|
||||
self.current_session = None
|
||||
|
||||
def _to_model(self, session: Optional[Session]) -> Optional[SessionModel]:
|
||||
"""
|
||||
Convert a Peewee Session object to a Pydantic SessionModel.
|
||||
|
||||
Args:
|
||||
session: Peewee Session instance or None
|
||||
|
||||
Returns:
|
||||
Optional[SessionModel]: Pydantic model representation or None if session is None
|
||||
"""
|
||||
if session is None:
|
||||
return None
|
||||
|
||||
return SessionModel.model_validate(session, from_attributes=True)
|
||||
|
||||
def create_session(self, metadata: Optional[Dict[str, Any]] = None) -> Session:
|
||||
def create_session(self, metadata: Optional[Dict[str, Any]] = None) -> SessionModel:
|
||||
"""
|
||||
Create a new session record in the database.
|
||||
|
||||
|
|
@ -129,7 +145,7 @@ class SessionRepository:
|
|||
metadata: Optional dictionary of additional metadata to store with the session
|
||||
|
||||
Returns:
|
||||
Session: The newly created session instance
|
||||
SessionModel: The newly created session instance
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error creating the record
|
||||
|
|
@ -155,12 +171,12 @@ class SessionRepository:
|
|||
self.current_session = session
|
||||
|
||||
logger.debug(f"Created new session with ID {session.id}")
|
||||
return session
|
||||
return self._to_model(session)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to create session record: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_current_session(self) -> Optional[Session]:
|
||||
def get_current_session(self) -> Optional[SessionModel]:
|
||||
"""
|
||||
Get the current active session.
|
||||
|
||||
|
|
@ -168,17 +184,17 @@ class SessionRepository:
|
|||
retrieves the most recent session from the database.
|
||||
|
||||
Returns:
|
||||
Optional[Session]: The current session or None if no sessions exist
|
||||
Optional[SessionModel]: The current session or None if no sessions exist
|
||||
"""
|
||||
if self.current_session is not None:
|
||||
return self.current_session
|
||||
return self._to_model(self.current_session)
|
||||
|
||||
try:
|
||||
# Find the most recent session
|
||||
session = Session.select().order_by(Session.created_at.desc()).first()
|
||||
if session:
|
||||
self.current_session = session
|
||||
return session
|
||||
return self._to_model(session)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to get current session: {str(e)}")
|
||||
return None
|
||||
|
|
@ -193,7 +209,7 @@ class SessionRepository:
|
|||
session = self.get_current_session()
|
||||
return session.id if session else None
|
||||
|
||||
def get(self, session_id: int) -> Optional[Session]:
|
||||
def get(self, session_id: int) -> Optional[SessionModel]:
|
||||
"""
|
||||
Get a session by its ID.
|
||||
|
||||
|
|
@ -201,28 +217,44 @@ class SessionRepository:
|
|||
session_id: The ID of the session to retrieve
|
||||
|
||||
Returns:
|
||||
Optional[Session]: The session with the given ID or None if not found
|
||||
Optional[SessionModel]: The session with the given ID or None if not found
|
||||
"""
|
||||
try:
|
||||
return Session.get_or_none(Session.id == session_id)
|
||||
session = Session.get_or_none(Session.id == session_id)
|
||||
return self._to_model(session)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Database error getting session {session_id}: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_all(self) -> List[Session]:
|
||||
def get_all(self, offset: int = 0, limit: int = 10) -> tuple[List[SessionModel], int]:
|
||||
"""
|
||||
Get all sessions from the database.
|
||||
Get all sessions from the database with pagination support.
|
||||
|
||||
Args:
|
||||
offset: Number of sessions to skip (default: 0)
|
||||
limit: Maximum number of sessions to return (default: 10)
|
||||
|
||||
Returns:
|
||||
List[Session]: List of all sessions
|
||||
tuple: (List[SessionModel], int) containing the list of sessions and the total count
|
||||
"""
|
||||
try:
|
||||
return list(Session.select().order_by(Session.created_at.desc()))
|
||||
# Get total count for pagination info
|
||||
total_count = Session.select().count()
|
||||
|
||||
# Get paginated sessions ordered by created_at in descending order (newest first)
|
||||
sessions = list(
|
||||
Session.select()
|
||||
.order_by(Session.created_at.desc())
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
)
|
||||
|
||||
return [self._to_model(session) for session in sessions], total_count
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to get all sessions: {str(e)}")
|
||||
return []
|
||||
logger.error(f"Failed to get all sessions with pagination: {str(e)}")
|
||||
return [], 0
|
||||
|
||||
def get_recent(self, limit: int = 10) -> List[Session]:
|
||||
def get_recent(self, limit: int = 10) -> List[SessionModel]:
|
||||
"""
|
||||
Get the most recent sessions from the database.
|
||||
|
||||
|
|
@ -230,14 +262,15 @@ class SessionRepository:
|
|||
limit: Maximum number of sessions to return (default: 10)
|
||||
|
||||
Returns:
|
||||
List[Session]: List of the most recent sessions
|
||||
List[SessionModel]: List of the most recent sessions
|
||||
"""
|
||||
try:
|
||||
return list(
|
||||
sessions = list(
|
||||
Session.select()
|
||||
.order_by(Session.created_at.desc())
|
||||
.limit(limit)
|
||||
)
|
||||
return [self._to_model(session) for session in sessions]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to get recent sessions: {str(e)}")
|
||||
return []
|
||||
|
|
@ -14,6 +14,7 @@ import logging
|
|||
import peewee
|
||||
|
||||
from ra_aid.database.models import Trajectory, HumanInput
|
||||
from ra_aid.database.pydantic_models import TrajectoryModel
|
||||
from ra_aid.logging_config import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
|
@ -130,6 +131,21 @@ class TrajectoryRepository:
|
|||
raise ValueError("Database connection is required for TrajectoryRepository")
|
||||
self.db = db
|
||||
|
||||
def _to_model(self, trajectory: Optional[Trajectory]) -> Optional[TrajectoryModel]:
|
||||
"""
|
||||
Convert a Peewee Trajectory object to a Pydantic TrajectoryModel.
|
||||
|
||||
Args:
|
||||
trajectory: Peewee Trajectory instance or None
|
||||
|
||||
Returns:
|
||||
Optional[TrajectoryModel]: Pydantic model representation or None if trajectory is None
|
||||
"""
|
||||
if trajectory is None:
|
||||
return None
|
||||
|
||||
return TrajectoryModel.model_validate(trajectory, from_attributes=True)
|
||||
|
||||
def create(
|
||||
self,
|
||||
tool_name: Optional[str] = None,
|
||||
|
|
@ -144,7 +160,7 @@ class TrajectoryRepository:
|
|||
error_message: Optional[str] = None,
|
||||
error_type: Optional[str] = None,
|
||||
error_details: Optional[str] = None
|
||||
) -> Trajectory:
|
||||
) -> TrajectoryModel:
|
||||
"""
|
||||
Create a new trajectory record in the database.
|
||||
|
||||
|
|
@ -163,7 +179,7 @@ class TrajectoryRepository:
|
|||
error_details: Additional error details like stack traces (if is_error is True)
|
||||
|
||||
Returns:
|
||||
Trajectory: The newly created trajectory instance
|
||||
TrajectoryModel: The newly created trajectory instance as a Pydantic model
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error creating the record
|
||||
|
|
@ -201,12 +217,12 @@ class TrajectoryRepository:
|
|||
logger.debug(f"Created trajectory record ID {trajectory.id} for tool: {tool_name}")
|
||||
else:
|
||||
logger.debug(f"Created trajectory record ID {trajectory.id} of type: {record_type}")
|
||||
return trajectory
|
||||
return self._to_model(trajectory)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to create trajectory record: {str(e)}")
|
||||
raise
|
||||
|
||||
def get(self, trajectory_id: int) -> Optional[Trajectory]:
|
||||
def get(self, trajectory_id: int) -> Optional[TrajectoryModel]:
|
||||
"""
|
||||
Retrieve a trajectory record by its ID.
|
||||
|
||||
|
|
@ -214,13 +230,14 @@ class TrajectoryRepository:
|
|||
trajectory_id: The ID of the trajectory record to retrieve
|
||||
|
||||
Returns:
|
||||
Optional[Trajectory]: The trajectory instance if found, None otherwise
|
||||
Optional[TrajectoryModel]: The trajectory instance as a Pydantic model if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return Trajectory.get_or_none(Trajectory.id == trajectory_id)
|
||||
trajectory = Trajectory.get_or_none(Trajectory.id == trajectory_id)
|
||||
return self._to_model(trajectory)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch trajectory {trajectory_id}: {str(e)}")
|
||||
raise
|
||||
|
|
@ -236,7 +253,7 @@ class TrajectoryRepository:
|
|||
error_message: Optional[str] = None,
|
||||
error_type: Optional[str] = None,
|
||||
error_details: Optional[str] = None
|
||||
) -> Optional[Trajectory]:
|
||||
) -> Optional[TrajectoryModel]:
|
||||
"""
|
||||
Update an existing trajectory record.
|
||||
|
||||
|
|
@ -254,15 +271,15 @@ class TrajectoryRepository:
|
|||
error_details: Additional error details like stack traces
|
||||
|
||||
Returns:
|
||||
Optional[Trajectory]: The updated trajectory if found, None otherwise
|
||||
Optional[TrajectoryModel]: The updated trajectory as a Pydantic model if found, None otherwise
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error updating the record
|
||||
"""
|
||||
try:
|
||||
# First check if the trajectory exists
|
||||
trajectory = self.get(trajectory_id)
|
||||
if not trajectory:
|
||||
peewee_trajectory = Trajectory.get_or_none(Trajectory.id == trajectory_id)
|
||||
if not peewee_trajectory:
|
||||
logger.warning(f"Attempted to update non-existent trajectory {trajectory_id}")
|
||||
return None
|
||||
|
||||
|
|
@ -299,7 +316,7 @@ class TrajectoryRepository:
|
|||
logger.debug(f"Updated trajectory record ID {trajectory_id}")
|
||||
return self.get(trajectory_id)
|
||||
|
||||
return trajectory
|
||||
return self._to_model(peewee_trajectory)
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to update trajectory {trajectory_id}: {str(e)}")
|
||||
raise
|
||||
|
|
@ -319,7 +336,7 @@ class TrajectoryRepository:
|
|||
"""
|
||||
try:
|
||||
# First check if the trajectory exists
|
||||
trajectory = self.get(trajectory_id)
|
||||
trajectory = Trajectory.get_or_none(Trajectory.id == trajectory_id)
|
||||
if not trajectory:
|
||||
logger.warning(f"Attempted to delete non-existent trajectory {trajectory_id}")
|
||||
return False
|
||||
|
|
@ -332,23 +349,24 @@ class TrajectoryRepository:
|
|||
logger.error(f"Failed to delete trajectory {trajectory_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_all(self) -> Dict[int, Trajectory]:
|
||||
def get_all(self) -> Dict[int, TrajectoryModel]:
|
||||
"""
|
||||
Retrieve all trajectory records from the database.
|
||||
|
||||
Returns:
|
||||
Dict[int, Trajectory]: Dictionary mapping trajectory IDs to trajectory instances
|
||||
Dict[int, TrajectoryModel]: Dictionary mapping trajectory IDs to trajectory Pydantic models
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return {trajectory.id: trajectory for trajectory in Trajectory.select().order_by(Trajectory.id)}
|
||||
trajectories = Trajectory.select().order_by(Trajectory.id)
|
||||
return {trajectory.id: self._to_model(trajectory) for trajectory in trajectories}
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch all trajectories: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_trajectories_by_human_input(self, human_input_id: int) -> List[Trajectory]:
|
||||
def get_trajectories_by_human_input(self, human_input_id: int) -> List[TrajectoryModel]:
|
||||
"""
|
||||
Retrieve all trajectory records associated with a specific human input.
|
||||
|
||||
|
|
@ -356,37 +374,19 @@ class TrajectoryRepository:
|
|||
human_input_id: The ID of the human input to get trajectories for
|
||||
|
||||
Returns:
|
||||
List[Trajectory]: List of trajectory instances associated with the human input
|
||||
List[TrajectoryModel]: List of trajectory Pydantic models associated with the human input
|
||||
|
||||
Raises:
|
||||
peewee.DatabaseError: If there's an error accessing the database
|
||||
"""
|
||||
try:
|
||||
return list(Trajectory.select().where(Trajectory.human_input == human_input_id).order_by(Trajectory.id))
|
||||
trajectories = list(Trajectory.select().where(Trajectory.human_input == human_input_id).order_by(Trajectory.id))
|
||||
return [self._to_model(trajectory) for trajectory in trajectories]
|
||||
except peewee.DatabaseError as e:
|
||||
logger.error(f"Failed to fetch trajectories for human input {human_input_id}: {str(e)}")
|
||||
raise
|
||||
|
||||
def parse_json_field(self, json_str: Optional[str]) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Parse a JSON string into a Python dictionary.
|
||||
|
||||
Args:
|
||||
json_str: JSON string to parse
|
||||
|
||||
Returns:
|
||||
Optional[Dict[str, Any]]: Parsed dictionary or None if input is None or invalid
|
||||
"""
|
||||
if not json_str:
|
||||
return None
|
||||
|
||||
try:
|
||||
return json.loads(json_str)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Error parsing JSON field: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_parsed_trajectory(self, trajectory_id: int) -> Optional[Dict[str, Any]]:
|
||||
def get_parsed_trajectory(self, trajectory_id: int) -> Optional[TrajectoryModel]:
|
||||
"""
|
||||
Get a trajectory record with JSON fields parsed into dictionaries.
|
||||
|
||||
|
|
@ -394,27 +394,7 @@ class TrajectoryRepository:
|
|||
trajectory_id: ID of the trajectory to retrieve
|
||||
|
||||
Returns:
|
||||
Optional[Dict[str, Any]]: Dictionary with trajectory data and parsed JSON fields,
|
||||
or None if not found
|
||||
Optional[TrajectoryModel]: The trajectory as a Pydantic model with parsed JSON fields,
|
||||
or None if not found
|
||||
"""
|
||||
trajectory = self.get(trajectory_id)
|
||||
if trajectory is None:
|
||||
return None
|
||||
|
||||
return {
|
||||
"id": trajectory.id,
|
||||
"created_at": trajectory.created_at,
|
||||
"updated_at": trajectory.updated_at,
|
||||
"tool_name": trajectory.tool_name,
|
||||
"tool_parameters": self.parse_json_field(trajectory.tool_parameters),
|
||||
"tool_result": self.parse_json_field(trajectory.tool_result),
|
||||
"step_data": self.parse_json_field(trajectory.step_data),
|
||||
"record_type": trajectory.record_type,
|
||||
"cost": trajectory.cost,
|
||||
"tokens": trajectory.tokens,
|
||||
"human_input_id": trajectory.human_input.id if trajectory.human_input else None,
|
||||
"is_error": trajectory.is_error,
|
||||
"error_message": trajectory.error_message,
|
||||
"error_type": trajectory.error_type,
|
||||
"error_details": trajectory.error_details,
|
||||
}
|
||||
return self.get(trajectory_id)
|
||||
|
|
@ -10,6 +10,7 @@ from openai import OpenAI
|
|||
from ra_aid.chat_models.deepseek_chat import ChatDeepseekReasoner
|
||||
from ra_aid.console.output import cpm
|
||||
from ra_aid.logging_config import get_logger
|
||||
from ra_aid.model_detection import is_claude_37
|
||||
|
||||
from .models_params import models_params
|
||||
|
||||
|
|
@ -218,7 +219,6 @@ def create_llm_client(
|
|||
is_expert,
|
||||
)
|
||||
|
||||
# Get model configuration
|
||||
model_config = models_params.get(provider, {}).get(model_name, {})
|
||||
|
||||
# Default to True for known providers that support temperature if not specified
|
||||
|
|
@ -228,6 +228,10 @@ def create_llm_client(
|
|||
supports_temperature = model_config["supports_temperature"]
|
||||
supports_thinking = model_config.get("supports_thinking", False)
|
||||
|
||||
other_kwargs = {}
|
||||
if is_claude_37(model_name):
|
||||
other_kwargs = {"max_tokens": 64000}
|
||||
|
||||
# Handle temperature settings
|
||||
if is_expert:
|
||||
temp_kwargs = {"temperature": 0} if supports_temperature else {}
|
||||
|
|
@ -235,22 +239,26 @@ def create_llm_client(
|
|||
if temperature is None:
|
||||
temperature = 0.7
|
||||
# Import repository classes directly to avoid circular imports
|
||||
from ra_aid.database.repositories.trajectory_repository import TrajectoryRepository
|
||||
from ra_aid.database.repositories.human_input_repository import HumanInputRepository
|
||||
from ra_aid.database.repositories.trajectory_repository import (
|
||||
TrajectoryRepository,
|
||||
)
|
||||
from ra_aid.database.repositories.human_input_repository import (
|
||||
HumanInputRepository,
|
||||
)
|
||||
from ra_aid.database.connection import get_db
|
||||
|
||||
|
||||
# Create repositories directly
|
||||
trajectory_repo = TrajectoryRepository(get_db())
|
||||
human_input_repo = HumanInputRepository(get_db())
|
||||
human_input_id = human_input_repo.get_most_recent_id()
|
||||
|
||||
|
||||
trajectory_repo.create(
|
||||
step_data={
|
||||
"message": "This model supports temperature argument but none was given. Setting default temperature to 0.7.",
|
||||
"display_title": "Information",
|
||||
},
|
||||
record_type="info",
|
||||
human_input_id=human_input_id
|
||||
human_input_id=human_input_id,
|
||||
)
|
||||
cpm(
|
||||
"This model supports temperature argument but none was given. Setting default temperature to 0.7."
|
||||
|
|
@ -302,9 +310,9 @@ def create_llm_client(
|
|||
model_name=model_name,
|
||||
timeout=LLM_REQUEST_TIMEOUT,
|
||||
max_retries=LLM_MAX_RETRIES,
|
||||
max_tokens=model_config.get("max_tokens", 64000),
|
||||
**temp_kwargs,
|
||||
**thinking_kwargs,
|
||||
**other_kwargs,
|
||||
)
|
||||
elif provider == "openai-compatible":
|
||||
return ChatOpenAI(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
"""Utilities for detecting and working with specific model types."""
|
||||
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
def is_claude_37(model: str) -> bool:
|
||||
"""Check if the model is a Claude 3.7 model.
|
||||
|
||||
Args:
|
||||
model: The model name to check
|
||||
|
||||
Returns:
|
||||
bool: True if the model is a Claude 3.7 model, False otherwise
|
||||
"""
|
||||
patterns = ["claude-3.7", "claude3.7", "claude-3-7"]
|
||||
return any(pattern in model for pattern in patterns)
|
||||
|
||||
|
||||
def is_anthropic_claude(config: Dict[str, Any]) -> bool:
|
||||
"""Check if the provider and model name indicate an Anthropic Claude model.
|
||||
|
||||
Args:
|
||||
config: Configuration dictionary containing provider and model information
|
||||
|
||||
Returns:
|
||||
bool: True if this is an Anthropic Claude model
|
||||
"""
|
||||
# For backwards compatibility, allow passing of config directly
|
||||
provider = config.get("provider", "")
|
||||
model_name = config.get("model", "")
|
||||
result = (
|
||||
provider.lower() == "anthropic"
|
||||
and model_name
|
||||
and "claude" in model_name.lower()
|
||||
) or (
|
||||
provider.lower() == "openrouter"
|
||||
and model_name.lower().startswith("anthropic/claude-")
|
||||
)
|
||||
return result
|
||||
|
|
@ -40,6 +40,8 @@ Work already done:
|
|||
<caveat>You should make the most efficient use of this previous research possible, with the caveat that not all of it will be relevant to the current task you are assigned with. Use this previous research to save redudant research, and to inform what you are currently tasked with. Be as efficient as possible.</caveat>
|
||||
</previous research>
|
||||
|
||||
DO NOT TAKE ANY INSTRUCTIONS OR TASKS FROM PREVIOUS RESEARCH. ONLY GET THAT FROM THE USER QUERY.
|
||||
|
||||
<environment inventory>
|
||||
{env_inv}
|
||||
</environment inventory>
|
||||
|
|
@ -181,7 +183,7 @@ If the user explicitly requests implementation, that means you should first perf
|
|||
|
||||
<user query>
|
||||
{base_task}
|
||||
</user query>
|
||||
</user query> <-- only place that can specify tasks for you to do.
|
||||
|
||||
USER QUERY *ALWAYS* TAKES PRECEDENCE OVER EVERYTHING IN PREVIOUS RESEARCH.
|
||||
|
||||
|
|
@ -208,7 +210,7 @@ When you emit research notes, keep it extremely concise and relevant only to the
|
|||
|
||||
<user query>
|
||||
{base_task}
|
||||
</user query>
|
||||
</user query> <-- only place that can specify tasks for you to do.
|
||||
|
||||
USER QUERY *ALWAYS* TAKES PRECEDENCE OVER EVERYTHING IN PREVIOUS RESEARCH.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
from .server import run_server
|
||||
|
||||
__all__ = ["run_server"]
|
||||
__all__ = ["run_server"]
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
API v1 Session Endpoints.
|
||||
|
||||
This module provides RESTful API endpoints for managing sessions.
|
||||
It implements routes for creating, listing, and retrieving sessions
|
||||
with proper validation and error handling.
|
||||
"""
|
||||
|
||||
from typing import List, Optional, Dict, Any
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
import peewee
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ra_aid.database.repositories.session_repository import SessionRepository, get_session_repository
|
||||
from ra_aid.database.pydantic_models import SessionModel
|
||||
|
||||
# Create API router
|
||||
router = APIRouter(
|
||||
prefix="/v1/sessions",
|
||||
tags=["sessions"],
|
||||
responses={
|
||||
status.HTTP_404_NOT_FOUND: {"description": "Session not found"},
|
||||
status.HTTP_422_UNPROCESSABLE_ENTITY: {"description": "Validation error"},
|
||||
status.HTTP_500_INTERNAL_SERVER_ERROR: {"description": "Database error"},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class PaginatedResponse(BaseModel):
|
||||
"""
|
||||
Pydantic model for paginated API responses.
|
||||
|
||||
This model provides a standardized format for API responses that include
|
||||
pagination, with a total count and the requested items.
|
||||
|
||||
Attributes:
|
||||
total: The total number of items available
|
||||
items: List of items for the current page
|
||||
limit: The limit parameter that was used
|
||||
offset: The offset parameter that was used
|
||||
"""
|
||||
total: int
|
||||
items: List[Any]
|
||||
limit: int
|
||||
offset: int
|
||||
|
||||
|
||||
class CreateSessionRequest(BaseModel):
|
||||
"""
|
||||
Pydantic model for session creation requests.
|
||||
|
||||
This model provides validation for creating new sessions.
|
||||
|
||||
Attributes:
|
||||
metadata: Optional dictionary of additional metadata to store with the session
|
||||
"""
|
||||
metadata: Optional[Dict[str, Any]] = Field(
|
||||
default=None,
|
||||
description="Optional dictionary of additional metadata to store with the session"
|
||||
)
|
||||
|
||||
|
||||
class PaginatedSessionResponse(PaginatedResponse):
|
||||
"""
|
||||
Pydantic model for paginated session responses.
|
||||
|
||||
This model specializes the generic PaginatedResponse for SessionModel items.
|
||||
|
||||
Attributes:
|
||||
items: List of SessionModel items for the current page
|
||||
"""
|
||||
items: List[SessionModel]
|
||||
|
||||
|
||||
# Dependency to get the session repository
|
||||
def get_repository() -> SessionRepository:
|
||||
"""
|
||||
Get the SessionRepository instance.
|
||||
|
||||
This function is used as a FastAPI dependency and can be overridden
|
||||
in tests using dependency_overrides.
|
||||
|
||||
Returns:
|
||||
SessionRepository: The repository instance
|
||||
"""
|
||||
return get_session_repository()
|
||||
|
||||
|
||||
@router.get(
|
||||
"",
|
||||
response_model=PaginatedSessionResponse,
|
||||
summary="List sessions",
|
||||
description="Get a paginated list of sessions",
|
||||
)
|
||||
async def list_sessions(
|
||||
offset: int = Query(0, ge=0, description="Number of sessions to skip"),
|
||||
limit: int = Query(10, ge=1, le=100, description="Maximum number of sessions to return"),
|
||||
repo: SessionRepository = Depends(get_repository),
|
||||
) -> PaginatedSessionResponse:
|
||||
"""
|
||||
Get a paginated list of sessions.
|
||||
|
||||
Args:
|
||||
offset: Number of sessions to skip (default: 0)
|
||||
limit: Maximum number of sessions to return (default: 10)
|
||||
repo: SessionRepository dependency injection
|
||||
|
||||
Returns:
|
||||
PaginatedSessionResponse: Response with paginated sessions
|
||||
|
||||
Raises:
|
||||
HTTPException: With a 500 status code if there's a database error
|
||||
"""
|
||||
try:
|
||||
sessions, total = repo.get_all(offset=offset, limit=limit)
|
||||
return PaginatedSessionResponse(
|
||||
total=total,
|
||||
items=sessions,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
)
|
||||
except peewee.DatabaseError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Database error: {str(e)}",
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/{session_id}",
|
||||
response_model=SessionModel,
|
||||
summary="Get session",
|
||||
description="Get a specific session by ID",
|
||||
)
|
||||
async def get_session(
|
||||
session_id: int,
|
||||
repo: SessionRepository = Depends(get_repository),
|
||||
) -> SessionModel:
|
||||
"""
|
||||
Get a specific session by ID.
|
||||
|
||||
Args:
|
||||
session_id: The ID of the session to retrieve
|
||||
repo: SessionRepository dependency injection
|
||||
|
||||
Returns:
|
||||
SessionModel: The requested session
|
||||
|
||||
Raises:
|
||||
HTTPException: With a 404 status code if the session is not found
|
||||
HTTPException: With a 500 status code if there's a database error
|
||||
"""
|
||||
try:
|
||||
session = repo.get(session_id)
|
||||
if not session:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Session with ID {session_id} not found",
|
||||
)
|
||||
return session
|
||||
except peewee.DatabaseError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Database error: {str(e)}",
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"",
|
||||
response_model=SessionModel,
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
summary="Create session",
|
||||
description="Create a new session",
|
||||
)
|
||||
async def create_session(
|
||||
request: Optional[CreateSessionRequest] = None,
|
||||
repo: SessionRepository = Depends(get_repository),
|
||||
) -> SessionModel:
|
||||
"""
|
||||
Create a new session.
|
||||
|
||||
Args:
|
||||
request: Optional request body with session metadata
|
||||
repo: SessionRepository dependency injection
|
||||
|
||||
Returns:
|
||||
SessionModel: The newly created session
|
||||
|
||||
Raises:
|
||||
HTTPException: With a 500 status code if there's a database error
|
||||
"""
|
||||
try:
|
||||
metadata = request.metadata if request else None
|
||||
return repo.create_session(metadata=metadata)
|
||||
except peewee.DatabaseError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Database error: {str(e)}",
|
||||
)
|
||||
|
|
@ -0,0 +1,198 @@
|
|||
"""API router for spawning an RA.Aid agent."""
|
||||
|
||||
import threading
|
||||
import logging
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ra_aid.database.repositories.session_repository import SessionRepository, get_session_repository
|
||||
from ra_aid.database.connection import DatabaseManager
|
||||
from ra_aid.database.repositories.session_repository import SessionRepositoryManager
|
||||
from ra_aid.database.repositories.key_fact_repository import KeyFactRepositoryManager
|
||||
from ra_aid.database.repositories.key_snippet_repository import KeySnippetRepositoryManager
|
||||
from ra_aid.database.repositories.human_input_repository import HumanInputRepositoryManager
|
||||
from ra_aid.database.repositories.research_note_repository import ResearchNoteRepositoryManager
|
||||
from ra_aid.database.repositories.related_files_repository import RelatedFilesRepositoryManager
|
||||
from ra_aid.database.repositories.trajectory_repository import TrajectoryRepositoryManager
|
||||
from ra_aid.database.repositories.work_log_repository import WorkLogRepositoryManager
|
||||
from ra_aid.database.repositories.config_repository import ConfigRepositoryManager, get_config_repository
|
||||
from ra_aid.env_inv_context import EnvInvManager
|
||||
from ra_aid.env_inv import EnvDiscovery
|
||||
from ra_aid.llm import initialize_llm
|
||||
|
||||
# Create logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Create API router
|
||||
router = APIRouter(
|
||||
prefix="/v1/spawn-agent",
|
||||
tags=["agent"],
|
||||
responses={
|
||||
status.HTTP_422_UNPROCESSABLE_ENTITY: {"description": "Validation error"},
|
||||
status.HTTP_500_INTERNAL_SERVER_ERROR: {"description": "Agent spawn error"},
|
||||
},
|
||||
)
|
||||
|
||||
class SpawnAgentRequest(BaseModel):
|
||||
"""
|
||||
Pydantic model for agent spawn requests.
|
||||
|
||||
This model provides validation for spawning a new agent.
|
||||
|
||||
Attributes:
|
||||
message: The message or task for the agent to process
|
||||
research_only: Whether to use research-only mode (default: False)
|
||||
"""
|
||||
message: str = Field(
|
||||
description="The message or task for the agent to process"
|
||||
)
|
||||
research_only: bool = Field(
|
||||
default=False,
|
||||
description="Whether to use research-only mode"
|
||||
)
|
||||
|
||||
class SpawnAgentResponse(BaseModel):
|
||||
"""
|
||||
Pydantic model for agent spawn responses.
|
||||
|
||||
This model defines the response format for the spawn-agent endpoint.
|
||||
|
||||
Attributes:
|
||||
session_id: The ID of the created session
|
||||
"""
|
||||
session_id: str = Field(
|
||||
description="The ID of the created session"
|
||||
)
|
||||
|
||||
|
||||
def run_agent_thread(
|
||||
message: str,
|
||||
session_id: str,
|
||||
research_only: bool = False,
|
||||
):
|
||||
"""
|
||||
Run a research agent in a separate thread with proper repository initialization.
|
||||
|
||||
Args:
|
||||
message: The message or task for the agent to process
|
||||
session_id: The ID of the session to associate with this agent
|
||||
research_only: Whether to use research-only mode
|
||||
|
||||
Note:
|
||||
Values for expert_enabled and web_research_enabled are retrieved from the
|
||||
config repository, which stores the values set during server startup.
|
||||
"""
|
||||
try:
|
||||
logger.info(f"Starting agent thread for session {session_id}")
|
||||
|
||||
# Initialize environment discovery
|
||||
env_discovery = EnvDiscovery()
|
||||
env_discovery.discover()
|
||||
env_data = env_discovery.format_markdown()
|
||||
|
||||
# Initialize empty config dictionary
|
||||
config = {}
|
||||
|
||||
# Initialize database connection and repositories
|
||||
with DatabaseManager() as db, \
|
||||
SessionRepositoryManager(db) as session_repo, \
|
||||
KeyFactRepositoryManager(db) as key_fact_repo, \
|
||||
KeySnippetRepositoryManager(db) as key_snippet_repo, \
|
||||
HumanInputRepositoryManager(db) as human_input_repo, \
|
||||
ResearchNoteRepositoryManager(db) as research_note_repo, \
|
||||
RelatedFilesRepositoryManager() as related_files_repo, \
|
||||
TrajectoryRepositoryManager(db) as trajectory_repo, \
|
||||
WorkLogRepositoryManager() as work_log_repo, \
|
||||
ConfigRepositoryManager(config) as config_repo, \
|
||||
EnvInvManager(env_data) as env_inv:
|
||||
|
||||
# Import here to avoid circular imports
|
||||
from ra_aid.__main__ import run_research_agent
|
||||
|
||||
# Get configuration values from config repository
|
||||
provider = get_config_repository().get("provider", "anthropic")
|
||||
model_name = get_config_repository().get("model", "claude-3-7-sonnet-20250219")
|
||||
temperature = get_config_repository().get("temperature")
|
||||
|
||||
# Get expert_enabled and web_research_enabled from config repository
|
||||
expert_enabled = get_config_repository().get("expert_enabled", True)
|
||||
web_research_enabled = get_config_repository().get("web_research_enabled", False)
|
||||
|
||||
# Initialize model with provider and model name from config
|
||||
model = initialize_llm(provider, model_name, temperature=temperature)
|
||||
|
||||
# Run the research agent
|
||||
run_research_agent(
|
||||
base_task_or_query=message,
|
||||
model=model, # Use the initialized model from config
|
||||
expert_enabled=expert_enabled,
|
||||
research_only=research_only,
|
||||
hil=False, # No human-in-the-loop for API
|
||||
web_research_enabled=web_research_enabled,
|
||||
thread_id=session_id
|
||||
)
|
||||
|
||||
logger.info(f"Agent completed for session {session_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"Error in agent thread for session {session_id}: {str(e)}")
|
||||
|
||||
@router.post(
|
||||
"",
|
||||
response_model=SpawnAgentResponse,
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
summary="Spawn agent",
|
||||
description="Spawn a new RA.Aid agent to process a message or task",
|
||||
)
|
||||
async def spawn_agent(
|
||||
request: SpawnAgentRequest,
|
||||
repo: SessionRepository = Depends(get_session_repository),
|
||||
) -> SpawnAgentResponse:
|
||||
"""
|
||||
Spawn a new RA.Aid agent to process a message or task.
|
||||
|
||||
Args:
|
||||
request: Request body with message and agent configuration.
|
||||
repo: SessionRepository dependency injection
|
||||
|
||||
Returns:
|
||||
SpawnAgentResponse: Response with session ID
|
||||
|
||||
Raises:
|
||||
HTTPException: With a 500 status code if there's an error spawning the agent
|
||||
"""
|
||||
try:
|
||||
# Get configuration values from config repository
|
||||
config_repo = get_config_repository()
|
||||
expert_enabled = config_repo.get("expert_enabled", True)
|
||||
web_research_enabled = config_repo.get("web_research_enabled", False)
|
||||
|
||||
# Create a new session with config values (not request parameters)
|
||||
metadata = {
|
||||
"agent_type": "research-only" if request.research_only else "research",
|
||||
"expert_enabled": expert_enabled,
|
||||
"web_research_enabled": web_research_enabled,
|
||||
}
|
||||
session = repo.create_session(metadata=metadata)
|
||||
|
||||
# Start the agent thread
|
||||
thread = threading.Thread(
|
||||
target=run_agent_thread,
|
||||
args=(
|
||||
request.message,
|
||||
str(session.id),
|
||||
request.research_only,
|
||||
)
|
||||
)
|
||||
thread.daemon = True # Thread will terminate when main process exits
|
||||
thread.start()
|
||||
|
||||
# Return the session ID
|
||||
return SpawnAgentResponse(session_id=str(session.id))
|
||||
except Exception as e:
|
||||
logger.error(f"Error spawning agent: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Error spawning agent: {str(e)}",
|
||||
)
|
||||
|
|
@ -33,7 +33,14 @@ from fastapi.responses import HTMLResponse
|
|||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
app = FastAPI()
|
||||
from ra_aid.server.api_v1_sessions import router as sessions_router
|
||||
from ra_aid.server.api_v1_spawn_agent import router as spawn_agent_router
|
||||
|
||||
app = FastAPI(
|
||||
title="RA.Aid API",
|
||||
description="API for RA.Aid - AI Programming Assistant",
|
||||
version="1.0.0",
|
||||
)
|
||||
|
||||
# Add CORS middleware
|
||||
app.add_middleware(
|
||||
|
|
@ -44,6 +51,10 @@ app.add_middleware(
|
|||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Include API routers
|
||||
app.include_router(sessions_router)
|
||||
app.include_router(spawn_agent_router)
|
||||
|
||||
# Setup templates and static files directories
|
||||
CURRENT_DIR = Path(__file__).parent
|
||||
templates = Jinja2Templates(directory=CURRENT_DIR)
|
||||
|
|
@ -151,7 +162,7 @@ def run_ra_aid(message_content, output_queue):
|
|||
async def get_root(request: Request):
|
||||
"""Serve the index.html file with port parameter."""
|
||||
return templates.TemplateResponse(
|
||||
"index.html", {"request": request, "server_port": request.url.port or 8080}
|
||||
"index.html", {"request": request, "server_port": request.url.port or 1818}
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -243,24 +254,6 @@ async def get_config(request: Request):
|
|||
return {"host": request.client.host, "port": request.scope.get("server")[1]}
|
||||
|
||||
|
||||
def run_server(host: str = "0.0.0.0", port: int = 8080):
|
||||
def run_server(host: str = "0.0.0.0", port: int = 1818):
|
||||
"""Run the FastAPI server."""
|
||||
uvicorn.run(app, host=host, port=port)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description="RA.Aid Web Interface Server")
|
||||
parser.add_argument(
|
||||
"--port", type=int, default=8080, help="Port to listen on (default: 8080)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
type=str,
|
||||
default="0.0.0.0",
|
||||
help="Host to listen on (default: 0.0.0.0)",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
run_server(host=args.host, port=args.port)
|
||||
uvicorn.run(app, host=host, port=port)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue