├── langchain.js, ├── src ├── components │ ├── LangGraphPrompt.tsx │ ├── ui │ │ ├── use-toast.ts │ │ ├── aspect-ratio.tsx │ │ ├── skeleton.tsx │ │ ├── collapsible.tsx │ │ ├── label.tsx │ │ ├── textarea.tsx │ │ ├── separator.tsx │ │ ├── progress.tsx │ │ ├── input.tsx │ │ ├── toaster.tsx │ │ ├── sonner.tsx │ │ ├── checkbox.tsx │ │ ├── slider.tsx │ │ ├── switch.tsx │ │ ├── tooltip.tsx │ │ ├── badge.tsx │ │ ├── hover-card.tsx │ │ ├── popover.tsx │ │ ├── avatar.tsx │ │ ├── toggle.tsx │ │ ├── radio-group.tsx │ │ ├── alert.tsx │ │ ├── scroll-area.tsx │ │ ├── resizable.tsx │ │ ├── toggle-group.tsx │ │ ├── button.tsx │ │ ├── tabs.tsx │ │ ├── accordion.tsx │ │ ├── card.tsx │ │ ├── input-otp.tsx │ │ ├── calendar.tsx │ │ ├── breadcrumb.tsx │ │ ├── pagination.tsx │ │ ├── table.tsx │ │ └── drawer.tsx │ ├── ErrorBoundary.tsx │ ├── PromptLibrary.tsx │ ├── MainNav.tsx │ ├── constants │ │ └── categories.ts │ └── PromptOptimizer.tsx ├── vite-env.d.ts ├── main.tsx ├── lib │ └── utils.ts ├── tools │ ├── types.ts │ ├── index.ts │ └── prompt │ │ └── promptGenerator.ts ├── services │ ├── openRouterService.ts │ ├── templateService.ts │ ├── toolService.ts │ ├── langchainService.ts │ ├── langGraphService.ts │ ├── __tests__ │ │ ├── openRouterService.test.ts │ │ └── settingsService.test.ts │ └── storageService.ts ├── templates │ ├── topology.md │ ├── complex-analysis.md │ ├── category-theory.md │ ├── number-theory.md │ ├── set-theory.md │ ├── abstract-algebra.md │ ├── zero-shot.md │ ├── symbolic-systems.md │ ├── direct-instruction.md │ ├── mathematical-logic.md │ ├── step-by-step.md │ ├── tree-of-thoughts.md │ ├── chain-of-thought.md │ ├── role-playing.md │ ├── task-decomposition.md │ ├── few-shot.md │ ├── token-optimization.md │ ├── red-teaming.md │ ├── constitutional-ai.md │ └── system-dynamics.md ├── App.css ├── test │ └── setup.ts ├── App.tsx ├── index.css └── contexts │ └── EditModalContext.tsx ├── .dockerignore ├── bun.lockb ├── public ├── favicon.ico ├── og-image.png ├── templates │ ├── topology copy.md │ ├── number-theory.md │ ├── set-theory copy.md │ ├── prompt-chaining.md │ ├── zero-shot.md │ ├── context-window.md │ ├── knowledge-graphs.md │ ├── semantic-control.md │ ├── temporal-reasoning.md │ ├── causal-inference.md │ ├── output-sanitization.md │ ├── prompt-injection.md │ ├── response-shaping.md │ ├── jailbreak-prevention.md │ ├── prompt-compression.md │ ├── automatic-reasoning.md │ ├── multi-agent.md │ ├── temperature-control.md │ ├── self-reflection.md │ ├── context-distillation.md │ ├── direct-instruction.md │ ├── meta-prompting.md │ ├── recursive-prompting.md │ ├── socratic-method.md │ ├── chain-of-verification.md │ ├── emergent-abilities.md │ ├── retrieval-augmented.md │ ├── adversarial-prompting.md │ ├── step-by-step.md │ ├── recursive-refinement.md │ ├── self-consistency.md │ ├── chain-of-thought.md │ ├── role-playing.md │ ├── tree-of-thoughts.md │ ├── react-framework.md │ ├── task-decomposition.md │ ├── few-shot.md │ ├── token-optimization.md │ ├── red-teaming.md │ ├── constitutional-ai.md │ ├── memory-systems.md │ ├── tool-using-agents.md │ ├── multi-agent-systems.md │ ├── topology.md │ ├── system-dynamics.md │ ├── complex-analysis.md │ ├── category-theory.md │ ├── systematic-suppression.md │ ├── set-theory.md │ ├── abstract-algebra.md │ ├── conversational-agents.md │ ├── symbolic-systems.md │ ├── vector-memory.md │ ├── time-weighted-memory.md │ ├── buffer-memory.md │ ├── mathematical-logic.md │ ├── summary-memory.md │ ├── conversation-memory.md │ ├── zero-shot-agent.md │ ├── entity-memory.md │ ├── plan-and-execute.md │ ├── structured-chat.md │ ├── autonomous-agents.md │ ├── react-agent.md │ ├── agent-executor.md │ ├── sql-chain.md │ ├── vector-store.md │ ├── supervisor-agent.md │ ├── team-chat.md │ ├── xml-agent.md │ ├── api-chain.md │ ├── agent-network.md │ ├── openai-functions.md │ ├── hierarchical-agents.md │ ├── retrieval-qa.md │ ├── sequential-chain.md │ └── router-chain.md └── placeholder.svg ├── .aider.tags.cache.v3 └── cache.db ├── postcss.config.js ├── sample.env ├── Dockerfile ├── components.json ├── jest.config.js ├── vite.config.ts ├── fly.toml ├── tsconfig.node.json ├── .github └── workflows │ └── fly-deploy.yml ├── tsconfig.json ├── tsconfig.app.json ├── eslint.config.js ├── .gitignore ├── index.html └── tailwind.config.ts /langchain.js,: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/LangGraphPrompt.tsx: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .git 3 | .env* 4 | !dist/ 5 | cache.* 6 | -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvnet/reflective-engineer/HEAD/bun.lockb -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvnet/reflective-engineer/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/og-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvnet/reflective-engineer/HEAD/public/og-image.png -------------------------------------------------------------------------------- /.aider.tags.cache.v3/cache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvnet/reflective-engineer/HEAD/.aider.tags.cache.v3/cache.db -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /src/components/ui/use-toast.ts: -------------------------------------------------------------------------------- 1 | import { useToast, toast } from "@/hooks/use-toast"; 2 | 3 | export { useToast, toast }; 4 | -------------------------------------------------------------------------------- /src/main.tsx: -------------------------------------------------------------------------------- 1 | import { createRoot } from 'react-dom/client' 2 | import App from './App.tsx' 3 | import './index.css' 4 | 5 | createRoot(document.getElementById("root")!).render(); 6 | -------------------------------------------------------------------------------- /src/components/ui/aspect-ratio.tsx: -------------------------------------------------------------------------------- 1 | import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio" 2 | 3 | const AspectRatio = AspectRatioPrimitive.Root 4 | 5 | export { AspectRatio } 6 | -------------------------------------------------------------------------------- /src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { clsx, type ClassValue } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /sample.env: -------------------------------------------------------------------------------- 1 | # OpenRouter Configuration 2 | VITE_OPENROUTER_KEY=your_openrouter_key_here 3 | VITE_ENCRYPTION_KEY=your_encryption_key_here 4 | 5 | # API Keys 6 | ANTHROPIC_API_KEY=your_anthropic_api_key_here 7 | OPENAI_API_KEY=your_openai_api_key_here -------------------------------------------------------------------------------- /src/components/ui/skeleton.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from "@/lib/utils" 2 | 3 | function Skeleton({ 4 | className, 5 | ...props 6 | }: React.HTMLAttributes) { 7 | return ( 8 | 12 | ) 13 | } 14 | 15 | export { Skeleton } 16 | -------------------------------------------------------------------------------- /src/tools/types.ts: -------------------------------------------------------------------------------- 1 | import { z } from "zod"; 2 | 3 | export type ToolCategory = 'prompt' | 'analysis' | 'utilities'; 4 | 5 | export interface Tool { 6 | id: string; 7 | name: string; 8 | description: string; 9 | category: ToolCategory; 10 | icon: React.ComponentType; 11 | schema?: z.ZodType; 12 | execute: (input: any) => Promise; 13 | } 14 | -------------------------------------------------------------------------------- /src/components/ui/collapsible.tsx: -------------------------------------------------------------------------------- 1 | import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" 2 | 3 | const Collapsible = CollapsiblePrimitive.Root 4 | 5 | const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger 6 | 7 | const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent 8 | 9 | export { Collapsible, CollapsibleTrigger, CollapsibleContent } 10 | -------------------------------------------------------------------------------- /src/tools/index.ts: -------------------------------------------------------------------------------- 1 | import { z } from "zod"; 2 | import { Tool, ToolCategory } from "./types"; 3 | 4 | export const toolRegistry = new Map(); 5 | 6 | export function registerTool(tool: Tool) { 7 | toolRegistry.set(tool.id, tool); 8 | } 9 | 10 | export function getToolsByCategory(category: ToolCategory): Tool[] { 11 | return Array.from(toolRegistry.values()) 12 | .filter(tool => tool.category === category); 13 | } 14 | -------------------------------------------------------------------------------- /src/services/openRouterService.ts: -------------------------------------------------------------------------------- 1 | import { OpenAI } from "@langchain/openai"; 2 | 3 | export function createOpenRouterClient(apiKey: string) { 4 | return new OpenAI({ 5 | baseURL: "https://openrouter.ai/api/v1", 6 | apiKey, 7 | modelName: "openai/gpt-3.5-turbo", 8 | configuration: { 9 | baseHeaders: { 10 | "HTTP-Referer": "*", 11 | "X-Title": "Reflective Engineer", 12 | "Origin": "*" 13 | } 14 | } 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:alpine 2 | 3 | # Copy the built static files to nginx's serve directory 4 | COPY dist /usr/share/nginx/html 5 | 6 | # Copy a custom nginx config if needed 7 | # COPY nginx.conf /etc/nginx/conf.d/default.conf 8 | 9 | # Expose port 8080 as required by Fly.io 10 | EXPOSE 8080 11 | 12 | # Update nginx config to listen on port 8080 13 | RUN sed -i 's/listen\(.*\)80;/listen 8080;/' /etc/nginx/conf.d/default.conf 14 | 15 | # Start Nginx 16 | CMD ["nginx", "-g", "daemon off;"] 17 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "default", 4 | "rsc": false, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "src/index.css", 9 | "baseColor": "slate", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils", 16 | "ui": "@/components/ui", 17 | "lib": "@/lib", 18 | "hooks": "@/hooks" 19 | } 20 | } -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('jest').Config} */ 2 | export default { 3 | preset: 'ts-jest', 4 | testEnvironment: 'jsdom', 5 | setupFilesAfterEnv: ['/src/test/setup.ts'], 6 | moduleNameMapper: { 7 | '^@/(.*)$': '/src/$1', 8 | '\\.(css|less|scss|sass)$': 'identity-obj-proxy' 9 | }, 10 | transform: { 11 | '^.+\\.tsx?$': 'ts-jest' 12 | }, 13 | testMatch: ['**/__tests__/**/*.test.ts?(x)'], 14 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] 15 | }; 16 | -------------------------------------------------------------------------------- /src/templates/topology.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Topology Fundamentals 3 | domain: mathematics 4 | category: Topology 5 | overview: Study of geometric properties and spatial relations unaffected by continuous deformation. 6 | --- 7 | 8 | # Open Sets 9 | (X,τ) - topological space 10 | U ∈ τ ⟹ U is open 11 | 12 | # Continuity 13 | f: X → Y is continuous 14 | ∀V∈τY: f⁻¹(V)∈τX 15 | 16 | # Connectedness 17 | X = A ∪ B, A∩B = ∅ 18 | A,B open ⟹ X disconnected 19 | 20 | # Compactness 21 | {Uα}α∈I open cover 22 | ∃ finite subcover -------------------------------------------------------------------------------- /public/templates/topology copy.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Topology Fundamentals 3 | domain: mathematics 4 | category: Topology 5 | overview: Study of geometric properties and spatial relations unaffected by continuous deformation. 6 | --- 7 | 8 | # Open Sets 9 | (X,τ) - topological space 10 | U ∈ τ ⟹ U is open 11 | 12 | # Continuity 13 | f: X → Y is continuous 14 | ∀V∈τY: f⁻¹(V)∈τX 15 | 16 | # Connectedness 17 | X = A ∪ B, A∩B = ∅ 18 | A,B open ⟹ X disconnected 19 | 20 | # Compactness 21 | {Uα}α∈I open cover 22 | ∃ finite subcover -------------------------------------------------------------------------------- /src/templates/complex-analysis.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Complex Analysis Foundations 3 | domain: mathematics 4 | category: Complex Analysis 5 | overview: Advanced study of complex functions, including integration, series expansions, and residue theory. 6 | --- 7 | 8 | # Complex Integration 9 | ∮ f(z)dz = 2πi∑Res(f,ak) 10 | 11 | # Series Expansions 12 | Let f(z) = ∑(n=0 to ∞) an(z-z₀)ⁿ 13 | 14 | # Residue Theory 15 | Res(f,a) = 1/(2πi)∮ f(z)dz 16 | 17 | # Conformal Mappings 18 | w = f(z) preserves angles 19 | ∂u/∂x = ∂v/∂y 20 | ∂u/∂y = -∂v/∂x -------------------------------------------------------------------------------- /src/templates/category-theory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Category Theory Concepts 3 | domain: mathematics 4 | category: Category Theory 5 | overview: Abstract mathematical framework dealing with mathematical structures and relationships between them. 6 | --- 7 | 8 | # Basic Definitions 9 | C = (Ob(C), hom(C), ∘) 10 | F: C → D (Functor) 11 | 12 | # Natural Transformations 13 | η: F ⇒ G 14 | ∀X∈Ob(C): ηX: F(X) → G(X) 15 | 16 | # Universal Properties 17 | Initial Object: ∀X∃!f:I→X 18 | Terminal Object: ∀X∃!f:X→T 19 | 20 | # Adjunctions 21 | F ⊣ G 22 | Hom(F(A),B) ≅ Hom(A,G(B)) -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import react from "@vitejs/plugin-react-swc"; 3 | import path from "path"; 4 | import { componentTagger } from "lovable-tagger"; 5 | 6 | // https://vitejs.dev/config/ 7 | export default defineConfig(({ mode }) => ({ 8 | server: { 9 | host: "::", 10 | port: 8080, 11 | }, 12 | plugins: [ 13 | react(), 14 | mode === 'development' && componentTagger(), 15 | ].filter(Boolean), 16 | resolve: { 17 | alias: { 18 | "@": path.resolve(__dirname, "./src"), 19 | }, 20 | }, 21 | })); 22 | -------------------------------------------------------------------------------- /fly.toml: -------------------------------------------------------------------------------- 1 | # fly.toml app configuration file generated for reflective-engineer on 2024-12-18T17:09:16Z 2 | # 3 | # See https://fly.io/docs/reference/configuration/ for information about how to use this file. 4 | # 5 | 6 | app = 'reflective-engineer' 7 | primary_region = 'sjc' 8 | 9 | [build] 10 | 11 | [http_service] 12 | internal_port = 8080 13 | force_https = true 14 | auto_stop_machines = 'stop' 15 | auto_start_machines = true 16 | min_machines_running = 0 17 | processes = ['app'] 18 | 19 | [[vm]] 20 | memory = '1gb' 21 | cpu_kind = 'shared' 22 | cpus = 1 23 | -------------------------------------------------------------------------------- /src/templates/number-theory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Number Theory Principles 3 | domain: mathematics 4 | category: Number Theory 5 | overview: Study of integers and their properties, including prime numbers, congruences, and arithmetic functions. 6 | --- 7 | 8 | # Congruence Relations 9 | a ≡ b (mod n) 10 | if n|(a-b) 11 | 12 | # Prime Numbers 13 | π(x) - prime counting function 14 | p#n - primorial function 15 | 16 | # Multiplicative Functions 17 | φ(n) - Euler totient 18 | μ(n) - Möbius function 19 | 20 | # Quadratic Reciprocity 21 | (a/p) - Legendre symbol 22 | (a/b) - Jacobi symbol -------------------------------------------------------------------------------- /public/templates/number-theory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Number Theory Principles 3 | domain: mathematics 4 | category: Number Theory 5 | overview: Study of integers and their properties, including prime numbers, congruences, and arithmetic functions. 6 | --- 7 | 8 | # Congruence Relations 9 | a ≡ b (mod n) 10 | if n|(a-b) 11 | 12 | # Prime Numbers 13 | π(x) - prime counting function 14 | p#n - primorial function 15 | 16 | # Multiplicative Functions 17 | φ(n) - Euler totient 18 | μ(n) - Möbius function 19 | 20 | # Quadratic Reciprocity 21 | (a/p) - Legendre symbol 22 | (a/b) - Jacobi symbol -------------------------------------------------------------------------------- /src/templates/set-theory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Set Theory Foundations 3 | domain: mathematics 4 | category: Set Theory 5 | overview: Exploration of fundamental set theory concepts and their applications in mathematical reasoning. 6 | --- 7 | 8 | # Basic Definitions 9 | Let U be the universal set 10 | Let A, B be subsets of U 11 | Let ∅ be the empty set 12 | 13 | # Operations 14 | - Union: A ∪ B 15 | - Intersection: A ∩ B 16 | - Complement: A' 17 | - Difference: A \ B 18 | 19 | # Properties 20 | 1. Commutative Laws 21 | 2. Associative Laws 22 | 3. Distributive Laws 23 | 4. DeMorgan's Laws -------------------------------------------------------------------------------- /src/tools/prompt/promptGenerator.ts: -------------------------------------------------------------------------------- 1 | import { z } from "zod"; 2 | import { Tool } from "../types"; 3 | import { Brain } from "lucide-react"; 4 | 5 | export const promptGeneratorTool: Tool = { 6 | id: 'prompt-generator', 7 | name: 'Prompt Generator', 8 | description: 'Generate structured prompts using templates', 9 | category: 'prompt', 10 | icon: Brain, 11 | schema: z.object({ 12 | domain: z.string(), 13 | context: z.string(), 14 | output: z.string() 15 | }), 16 | execute: async (input) => { 17 | // Implementation 18 | return input; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /public/templates/set-theory copy.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Set Theory Foundations 3 | domain: mathematics 4 | category: Set Theory 5 | overview: Exploration of fundamental set theory concepts and their applications in mathematical reasoning. 6 | --- 7 | 8 | # Basic Definitions 9 | Let U be the universal set 10 | Let A, B be subsets of U 11 | Let ∅ be the empty set 12 | 13 | # Operations 14 | - Union: A ∪ B 15 | - Intersection: A ∩ B 16 | - Complement: A' 17 | - Difference: A \ B 18 | 19 | # Properties 20 | 1. Commutative Laws 21 | 2. Associative Laws 22 | 3. Distributive Laws 23 | 4. DeMorgan's Laws -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "lib": ["ES2023"], 5 | "module": "ESNext", 6 | "skipLibCheck": true, 7 | 8 | /* Bundler mode */ 9 | "moduleResolution": "bundler", 10 | "allowImportingTsExtensions": true, 11 | "isolatedModules": true, 12 | "moduleDetection": "force", 13 | "noEmit": true, 14 | 15 | /* Linting */ 16 | "strict": true, 17 | "noUnusedLocals": false, 18 | "noUnusedParameters": false, 19 | "noFallthroughCasesInSwitch": true 20 | }, 21 | "include": ["vite.config.ts"] 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/fly-deploy.yml: -------------------------------------------------------------------------------- 1 | # See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ 2 | 3 | name: Fly Deploy 4 | on: 5 | push: 6 | branches: 7 | - main 8 | jobs: 9 | deploy: 10 | name: Deploy app 11 | runs-on: ubuntu-latest 12 | concurrency: deploy-group # optional: ensure only one action runs at a time 13 | steps: 14 | - uses: actions/checkout@v4 15 | - uses: superfly/flyctl-actions/setup-flyctl@master 16 | - run: flyctl deploy --remote-only 17 | env: 18 | FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [ 4 | { "path": "./tsconfig.app.json" }, 5 | { "path": "./tsconfig.node.json" } 6 | ], 7 | "compilerOptions": { 8 | "baseUrl": ".", 9 | "paths": { 10 | "@/*": ["./src/*"] 11 | }, 12 | "noImplicitAny": false, 13 | "noUnusedParameters": false, 14 | "skipLibCheck": true, 15 | "allowJs": true, 16 | "noUnusedLocals": false, 17 | "strictNullChecks": false, 18 | "esModuleInterop": true, 19 | "jsx": "react-jsx", 20 | "types": ["jest", "node", "@testing-library/jest-dom"] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/templates/abstract-algebra.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Group Theory Analysis 3 | domain: mathematics 4 | category: Abstract Algebra 5 | overview: Investigation of algebraic structures using group theory and ring theory. 6 | --- 7 | 8 | # Structures 9 | Let G be a group with operation • 10 | Let H be a subgroup of G 11 | Let N be a normal subgroup of G 12 | 13 | # Properties 14 | P(x): "x is a homomorphism" 15 | Q(x): "x preserves group structure" 16 | R(x): "x maps to kernel" 17 | 18 | # Objectives 19 | 1. Prove fundamental homomorphism theorem 20 | 2. Show group action properties 21 | 3. Analyze quotient groups -------------------------------------------------------------------------------- /src/templates/zero-shot.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Zero-Shot Prompting 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Direct prompting without examples, relying on the model's pre-trained knowledge. 6 | --- 7 | 8 | # Core Components 9 | 1. Clear Instructions 10 | 2. Task Definition 11 | 3. Output Format 12 | 4. Constraints 13 | 14 | # Implementation 15 | - Direct Question/Task 16 | - No Examples Provided 17 | - Clear Output Specification 18 | 19 | # Best Practices 20 | 1. Be Explicit 21 | 2. Define Context 22 | 3. Specify Format 23 | 4. Set Constraints 24 | 25 | # Validation 26 | - Accuracy Check 27 | - Consistency Test 28 | - Output Verification 29 | -------------------------------------------------------------------------------- /public/templates/prompt-chaining.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Prompt Chaining 3 | domain: prompt-engineering 4 | category: Specialized 5 | overview: Connecting multiple prompts in sequence for complex task completion. 6 | --- 7 | 8 | # Core Components 9 | 1. Chain Design 10 | 2. State Management 11 | 3. Data Flow 12 | 4. Error Handling 13 | 14 | # Implementation 15 | - Define Sequence 16 | - Manage State 17 | - Control Flow 18 | - Handle Errors 19 | 20 | # Best Practices 21 | 1. Clear Dependencies 22 | 2. Data Validation 23 | 3. Error Recovery 24 | 4. Chain Optimization 25 | 26 | # Validation 27 | - Chain Completion 28 | - Data Integrity 29 | - Error Handling 30 | - Output Quality 31 | -------------------------------------------------------------------------------- /public/templates/zero-shot.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Zero-Shot Prompting 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Direct prompting without examples, relying on the model's pre-trained knowledge. 6 | --- 7 | 8 | # Core Components 9 | 1. Clear Instructions 10 | 2. Task Definition 11 | 3. Output Format 12 | 4. Constraints 13 | 14 | # Implementation 15 | - Direct Question/Task 16 | - No Examples Provided 17 | - Clear Output Specification 18 | 19 | # Best Practices 20 | 1. Be Explicit 21 | 2. Define Context 22 | 3. Specify Format 23 | 4. Set Constraints 24 | 25 | # Validation 26 | - Accuracy Check 27 | - Consistency Test 28 | - Output Verification 29 | -------------------------------------------------------------------------------- /public/templates/context-window.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Context Window 3 | domain: prompt-engineering 4 | category: Optimization 5 | overview: Optimizing prompt design for effective use of model context windows. 6 | --- 7 | 8 | # Core Components 9 | 1. Window Size 10 | 2. Content Priority 11 | 3. Token Usage 12 | 4. Memory Management 13 | 14 | # Implementation 15 | - Size Analysis 16 | - Prioritize Content 17 | - Optimize Tokens 18 | - Manage Memory 19 | 20 | # Best Practices 21 | 1. Efficient Usage 22 | 2. Content Focus 23 | 3. Token Economy 24 | 4. Memory Optimization 25 | 26 | # Validation 27 | - Window Utilization 28 | - Content Fit 29 | - Token Efficiency 30 | - Memory Usage 31 | -------------------------------------------------------------------------------- /public/templates/knowledge-graphs.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Knowledge Graphs 3 | domain: prompt-engineering 4 | category: Specialized 5 | overview: Using graph-based knowledge representation for enhanced prompting. 6 | --- 7 | 8 | # Core Components 9 | 1. Node Definition 10 | 2. Edge Relations 11 | 3. Graph Structure 12 | 4. Query Methods 13 | 14 | # Implementation 15 | - Define Entities 16 | - Map Relations 17 | - Build Structure 18 | - Query Graph 19 | 20 | # Best Practices 21 | 1. Clear Ontology 22 | 2. Relation Types 23 | 3. Graph Maintenance 24 | 4. Query Optimization 25 | 26 | # Validation 27 | - Graph Accuracy 28 | - Query Performance 29 | - Data Consistency 30 | - Result Quality 31 | -------------------------------------------------------------------------------- /public/templates/semantic-control.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Semantic Control 3 | domain: prompt-engineering 4 | category: Specialized 5 | overview: Controlling semantic aspects of model outputs through precise prompting. 6 | --- 7 | 8 | # Core Components 9 | 1. Semantic Rules 10 | 2. Content Control 11 | 3. Style Management 12 | 4. Output Shaping 13 | 14 | # Implementation 15 | - Define Rules 16 | - Apply Controls 17 | - Manage Style 18 | - Shape Output 19 | 20 | # Best Practices 21 | 1. Clear Guidelines 22 | 2. Consistent Rules 23 | 3. Style Coherence 24 | 4. Quality Checks 25 | 26 | # Validation 27 | - Rule Adherence 28 | - Style Consistency 29 | - Content Control 30 | - Output Quality 31 | -------------------------------------------------------------------------------- /public/templates/temporal-reasoning.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Temporal Reasoning 3 | domain: prompt-engineering 4 | category: Specialized 5 | overview: Enabling time-based reasoning and temporal relationship understanding. 6 | --- 7 | 8 | # Core Components 9 | 1. Time Representation 10 | 2. Event Sequencing 11 | 3. Causal Relations 12 | 4. Temporal Logic 13 | 14 | # Implementation 15 | - Define Timeline 16 | - Order Events 17 | - Map Causality 18 | - Apply Logic 19 | 20 | # Best Practices 21 | 1. Clear Chronology 22 | 2. Event Relations 23 | 3. Causal Chains 24 | 4. Time Consistency 25 | 26 | # Validation 27 | - Timeline Accuracy 28 | - Event Order 29 | - Causal Logic 30 | - Time Coherence 31 | -------------------------------------------------------------------------------- /src/templates/symbolic-systems.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Symbolic Systems Analysis 3 | domain: computer-science 4 | category: Symbolic Systems 5 | overview: Analysis of symbolic computation and representation systems in artificial intelligence and formal languages. 6 | --- 7 | 8 | # Core Concepts 9 | Let Σ be a finite alphabet of symbols 10 | Let L be a formal language over Σ 11 | Let A be an automaton that recognizes L 12 | 13 | # Properties 14 | P(x): "x is a valid symbol in Σ" 15 | Q(x): "x is a valid string in L" 16 | R(x): "x is recognized by A" 17 | 18 | # Objectives 19 | 1. Define formal grammar rules 20 | 2. Construct finite state machines 21 | 3. Analyze language recognition patterns -------------------------------------------------------------------------------- /public/templates/causal-inference.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Causal Inference 3 | domain: prompt-engineering 4 | category: Specialized 5 | overview: Analyzing and inferring cause-effect relationships in prompt engineering. 6 | --- 7 | 8 | # Core Components 9 | 1. Causal Models 10 | 2. Variable Relations 11 | 3. Effect Analysis 12 | 4. Inference Rules 13 | 14 | # Implementation 15 | - Build Models 16 | - Map Relations 17 | - Analyze Effects 18 | - Apply Rules 19 | 20 | # Best Practices 21 | 1. Clear Variables 22 | 2. Relation Mapping 23 | 3. Effect Testing 24 | 4. Rule Validation 25 | 26 | # Validation 27 | - Model Accuracy 28 | - Relation Logic 29 | - Effect Prediction 30 | - Rule Consistency 31 | -------------------------------------------------------------------------------- /public/templates/output-sanitization.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Output Sanitization 3 | domain: prompt-engineering 4 | category: Safety 5 | overview: Ensuring safe and appropriate model outputs through systematic sanitization. 6 | --- 7 | 8 | # Core Components 9 | 1. Content Filters 10 | 2. Safety Checks 11 | 3. Format Validation 12 | 4. Clean-up Rules 13 | 14 | # Implementation 15 | - Filter Content 16 | - Check Safety 17 | - Validate Format 18 | - Apply Rules 19 | 20 | # Best Practices 21 | 1. Clear Standards 22 | 2. Thorough Checks 23 | 3. Format Control 24 | 4. Regular Updates 25 | 26 | # Validation 27 | - Filter Accuracy 28 | - Safety Level 29 | - Format Compliance 30 | - Rule Effectiveness 31 | -------------------------------------------------------------------------------- /public/templates/prompt-injection.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Prompt Injection 3 | domain: prompt-engineering 4 | category: Safety 5 | overview: Understanding and preventing malicious prompt injection attacks. 6 | --- 7 | 8 | # Core Components 9 | 1. Attack Vectors 10 | 2. Defense Methods 11 | 3. Detection Systems 12 | 4. Prevention Strategies 13 | 14 | # Implementation 15 | - Identify Vectors 16 | - Build Defenses 17 | - Deploy Detection 18 | - Prevent Attacks 19 | 20 | # Best Practices 21 | 1. Security First 22 | 2. Input Validation 23 | 3. Output Sanitization 24 | 4. Regular Testing 25 | 26 | # Validation 27 | - Attack Detection 28 | - Defense Strength 29 | - System Security 30 | - Prevention Rate 31 | -------------------------------------------------------------------------------- /public/templates/response-shaping.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Response Shaping 3 | domain: prompt-engineering 4 | category: Optimization 5 | overview: Controlling and optimizing the structure and format of model responses. 6 | --- 7 | 8 | # Core Components 9 | 1. Format Design 10 | 2. Structure Control 11 | 3. Output Rules 12 | 4. Quality Standards 13 | 14 | # Implementation 15 | - Design Format 16 | - Control Structure 17 | - Apply Rules 18 | - Maintain Quality 19 | 20 | # Best Practices 21 | 1. Clear Format 22 | 2. Consistent Structure 23 | 3. Explicit Rules 24 | 4. Quality Checks 25 | 26 | # Validation 27 | - Format Compliance 28 | - Structure Adherence 29 | - Rule Following 30 | - Output Quality 31 | -------------------------------------------------------------------------------- /public/templates/jailbreak-prevention.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Jailbreak Prevention 3 | domain: prompt-engineering 4 | category: Safety 5 | overview: Implementing safeguards against attempts to bypass model restrictions. 6 | --- 7 | 8 | # Core Components 9 | 1. Security Bounds 10 | 2. Detection Methods 11 | 3. Prevention Systems 12 | 4. Response Protocols 13 | 14 | # Implementation 15 | - Set Boundaries 16 | - Detect Attempts 17 | - Prevent Bypass 18 | - Handle Violations 19 | 20 | # Best Practices 21 | 1. Strong Boundaries 22 | 2. Active Monitoring 23 | 3. Quick Response 24 | 4. Regular Updates 25 | 26 | # Validation 27 | - Boundary Strength 28 | - Detection Rate 29 | - Prevention Success 30 | - Response Time 31 | -------------------------------------------------------------------------------- /public/templates/prompt-compression.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Prompt Compression 3 | domain: prompt-engineering 4 | category: Optimization 5 | overview: Techniques for compressing prompts while maintaining effectiveness. 6 | --- 7 | 8 | # Core Components 9 | 1. Content Analysis 10 | 2. Compression Methods 11 | 3. Information Density 12 | 4. Quality Control 13 | 14 | # Implementation 15 | - Analyze Content 16 | - Apply Compression 17 | - Optimize Density 18 | - Check Quality 19 | 20 | # Best Practices 21 | 1. Clear Goals 22 | 2. Efficient Methods 23 | 3. Quality Focus 24 | 4. Regular Testing 25 | 26 | # Validation 27 | - Compression Ratio 28 | - Information Retention 29 | - Output Quality 30 | - Performance Impact 31 | -------------------------------------------------------------------------------- /public/templates/automatic-reasoning.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Automatic Reasoning 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Enabling autonomous reasoning and decision-making in language models. 6 | --- 7 | 8 | # Core Components 9 | 1. Logic Framework 10 | 2. Decision Trees 11 | 3. Inference Rules 12 | 4. Validation System 13 | 14 | # Implementation 15 | - Define Rules 16 | - Build Logic Chains 17 | - Test Inference 18 | - Validate Results 19 | 20 | # Best Practices 21 | 1. Clear Logic Rules 22 | 2. Systematic Testing 23 | 3. Error Handling 24 | 4. Result Validation 25 | 26 | # Validation 27 | - Logic Soundness 28 | - Inference Accuracy 29 | - Decision Quality 30 | - Result Reliability 31 | -------------------------------------------------------------------------------- /public/templates/multi-agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Multi-Agent Framework 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Coordinating multiple AI agents for complex problem-solving. 6 | --- 7 | 8 | # Core Components 9 | 1. Agent Roles 10 | 2. Communication Protocol 11 | 3. Task Distribution 12 | 4. Result Integration 13 | 14 | # Implementation 15 | - Define Agents 16 | - Set Protocols 17 | - Assign Tasks 18 | - Coordinate Actions 19 | 20 | # Best Practices 21 | 1. Clear Role Definition 22 | 2. Effective Communication 23 | 3. Task Management 24 | 4. Result Synthesis 25 | 26 | # Validation 27 | - Role Performance 28 | - Communication Quality 29 | - Task Completion 30 | - Integration Success 31 | -------------------------------------------------------------------------------- /public/templates/temperature-control.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Temperature Control 3 | domain: prompt-engineering 4 | category: Optimization 5 | overview: Managing model temperature settings for optimal response characteristics. 6 | --- 7 | 8 | # Core Components 9 | 1. Temperature Settings 10 | 2. Response Variance 11 | 3. Output Control 12 | 4. Quality Balance 13 | 14 | # Implementation 15 | - Set Temperature 16 | - Monitor Variance 17 | - Control Output 18 | - Balance Quality 19 | 20 | # Best Practices 21 | 1. Task Alignment 22 | 2. Variance Control 23 | 3. Output Monitoring 24 | 4. Quality Focus 25 | 26 | # Validation 27 | - Setting Effectiveness 28 | - Variance Level 29 | - Output Control 30 | - Quality Metrics 31 | -------------------------------------------------------------------------------- /public/templates/self-reflection.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Self-Reflection 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Enabling models to analyze and improve their own responses through metacognition. 6 | --- 7 | 8 | # Core Components 9 | 1. Self-Analysis 10 | 2. Error Detection 11 | 3. Quality Assessment 12 | 4. Improvement Strategy 13 | 14 | # Implementation 15 | - Monitor Output 16 | - Analyze Process 17 | - Identify Issues 18 | - Apply Corrections 19 | 20 | # Best Practices 21 | 1. Clear Metrics 22 | 2. Process Transparency 23 | 3. Improvement Tracking 24 | 4. Quality Control 25 | 26 | # Validation 27 | - Analysis Accuracy 28 | - Improvement Rate 29 | - Error Detection 30 | - Output Quality 31 | -------------------------------------------------------------------------------- /public/templates/context-distillation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Context Distillation 3 | domain: prompt-engineering 4 | category: Specialized 5 | overview: Extracting and condensing essential context for more efficient prompting. 6 | --- 7 | 8 | # Core Components 9 | 1. Context Analysis 10 | 2. Key Extraction 11 | 3. Information Density 12 | 4. Relevance Filtering 13 | 14 | # Implementation 15 | - Analyze Context 16 | - Extract Essentials 17 | - Optimize Density 18 | - Filter Content 19 | 20 | # Best Practices 21 | 1. Clear Criteria 22 | 2. Information Priority 23 | 3. Density Balance 24 | 4. Quality Control 25 | 26 | # Validation 27 | - Information Retention 28 | - Compression Ratio 29 | - Relevance Score 30 | - Output Quality 31 | -------------------------------------------------------------------------------- /public/templates/direct-instruction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Direct Instruction 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Clear, explicit instructions with specific expectations and desired outcomes. 6 | --- 7 | 8 | # Core Components 9 | 1. Clear Objectives 10 | 2. Explicit Instructions 11 | 3. Expected Outcomes 12 | 4. Success Criteria 13 | 14 | # Implementation 15 | - Precise Language 16 | - Clear Requirements 17 | - Specific Goals 18 | - Measurable Results 19 | 20 | # Best Practices 21 | 1. Be Explicit 22 | 2. Avoid Ambiguity 23 | 3. Set Clear Goals 24 | 4. Define Success 25 | 26 | # Validation 27 | - Instruction Clarity 28 | - Goal Achievement 29 | - Output Accuracy 30 | - Requirement Match 31 | -------------------------------------------------------------------------------- /public/templates/meta-prompting.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Meta-Prompting 3 | domain: prompt-engineering 4 | category: Advanced Prompting 5 | overview: Using prompts to generate, refine, and optimize other prompts. 6 | --- 7 | 8 | # Core Components 9 | 1. Prompt Analysis 10 | 2. Strategy Generation 11 | 3. Refinement Loop 12 | 4. Quality Assessment 13 | 14 | # Implementation 15 | - Analyze Requirements 16 | - Generate Strategies 17 | - Test Variations 18 | - Optimize Results 19 | 20 | # Best Practices 21 | 1. Clear Objectives 22 | 2. Iterative Testing 23 | 3. Performance Metrics 24 | 4. Continuous Refinement 25 | 26 | # Validation 27 | - Strategy Effectiveness 28 | - Output Quality 29 | - Goal Alignment 30 | - Refinement Impact 31 | -------------------------------------------------------------------------------- /public/templates/recursive-prompting.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Recursive Prompting 3 | domain: prompt-engineering 4 | category: Advanced Prompting 5 | overview: Using output from one prompt as input for subsequent prompts in a recursive pattern. 6 | --- 7 | 8 | # Core Components 9 | 1. Initial Prompt 10 | 2. Output Analysis 11 | 3. Recursive Chain 12 | 4. Termination Condition 13 | 14 | # Implementation 15 | - Define Base Case 16 | - Chain Responses 17 | - Monitor Progress 18 | - Control Depth 19 | 20 | # Best Practices 21 | 1. Clear Base Cases 22 | 2. Progress Tracking 23 | 3. Depth Control 24 | 4. Quality Gates 25 | 26 | # Validation 27 | - Chain Coherence 28 | - Progress Metrics 29 | - Termination Check 30 | - Result Quality 31 | -------------------------------------------------------------------------------- /public/templates/socratic-method.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Socratic Method 3 | domain: prompt-engineering 4 | category: Advanced Prompting 5 | overview: Using systematic questioning to guide reasoning and discovery. 6 | --- 7 | 8 | # Core Components 9 | 1. Question Formulation 10 | 2. Answer Analysis 11 | 3. Follow-up Questions 12 | 4. Knowledge Discovery 13 | 14 | # Implementation 15 | - Ask Open Questions 16 | - Analyze Responses 17 | - Guide Discovery 18 | - Build Understanding 19 | 20 | # Best Practices 21 | 1. Clear Questions 22 | 2. Active Listening 23 | 3. Guided Exploration 24 | 4. Knowledge Building 25 | 26 | # Validation 27 | - Question Quality 28 | - Response Depth 29 | - Learning Progress 30 | - Understanding Level 31 | -------------------------------------------------------------------------------- /src/templates/direct-instruction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Direct Instruction 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Clear, explicit instructions with specific expectations and desired outcomes. 6 | --- 7 | 8 | # Core Components 9 | 1. Clear Objectives 10 | 2. Explicit Instructions 11 | 3. Expected Outcomes 12 | 4. Success Criteria 13 | 14 | # Implementation 15 | - Precise Language 16 | - Clear Requirements 17 | - Specific Goals 18 | - Measurable Results 19 | 20 | # Best Practices 21 | 1. Be Explicit 22 | 2. Avoid Ambiguity 23 | 3. Set Clear Goals 24 | 4. Define Success 25 | 26 | # Validation 27 | - Instruction Clarity 28 | - Goal Achievement 29 | - Output Accuracy 30 | - Requirement Match 31 | -------------------------------------------------------------------------------- /public/templates/chain-of-verification.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Chain of Verification 3 | domain: prompt-engineering 4 | category: Advanced Prompting 5 | overview: Systematic verification of reasoning and outputs through sequential validation steps. 6 | --- 7 | 8 | # Core Components 9 | 1. Step Validation 10 | 2. Logic Verification 11 | 3. Consistency Check 12 | 4. Error Detection 13 | 14 | # Implementation 15 | - Define Checkpoints 16 | - Verify Logic 17 | - Test Consistency 18 | - Correct Errors 19 | 20 | # Best Practices 21 | 1. Clear Criteria 22 | 2. Sequential Checks 23 | 3. Error Handling 24 | 4. Documentation 25 | 26 | # Validation 27 | - Accuracy Rate 28 | - Error Detection 29 | - Consistency Level 30 | - Correction Success 31 | -------------------------------------------------------------------------------- /public/templates/emergent-abilities.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Emergent Abilities 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Exploring and leveraging unexpected capabilities that emerge in large language models. 6 | --- 7 | 8 | # Core Components 9 | 1. Capability Discovery 10 | 2. Pattern Analysis 11 | 3. Scaling Effects 12 | 4. Application Methods 13 | 14 | # Implementation 15 | - Systematic Testing 16 | - Pattern Recognition 17 | - Scale Analysis 18 | - Capability Mapping 19 | 20 | # Best Practices 21 | 1. Thorough Testing 22 | 2. Documentation 23 | 3. Validation Methods 24 | 4. Safety Checks 25 | 26 | # Validation 27 | - Reproducibility 28 | - Consistency 29 | - Scale Dependence 30 | - Safety Assessment 31 | -------------------------------------------------------------------------------- /public/templates/retrieval-augmented.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Retrieval Augmented Generation 3 | domain: prompt-engineering 4 | category: Specialized 5 | overview: Enhancing language model outputs with external knowledge retrieval. 6 | --- 7 | 8 | # Core Components 9 | 1. Knowledge Base 10 | 2. Retrieval System 11 | 3. Context Integration 12 | 4. Response Generation 13 | 14 | # Implementation 15 | - Index Knowledge 16 | - Query System 17 | - Merge Context 18 | - Generate Response 19 | 20 | # Best Practices 21 | 1. Quality Sources 22 | 2. Efficient Retrieval 23 | 3. Context Balance 24 | 4. Source Attribution 25 | 26 | # Validation 27 | - Retrieval Accuracy 28 | - Integration Quality 29 | - Response Relevance 30 | - Source Validity 31 | -------------------------------------------------------------------------------- /src/templates/mathematical-logic.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mathematical Logic Foundations 3 | domain: mathematics 4 | category: Mathematical Logic 5 | overview: Exploration of fundamental mathematical logic concepts using set theory and predicate calculus. 6 | --- 7 | 8 | # Sets and Axioms 9 | Let A be the set of all logical propositions. 10 | Let T be the subset of A that are tautologies. 11 | Let C be the subset of A that are contradictions. 12 | 13 | # Predicates 14 | P(x): "x is a well-formed formula" 15 | Q(x): "x is satisfiable" 16 | R(x): "x is valid" 17 | 18 | # Objectives 19 | 1. Prove completeness theorem using predicate calculus 20 | 2. Demonstrate soundness of the system 21 | 3. Show relationship between syntax and semantics -------------------------------------------------------------------------------- /public/templates/adversarial-prompting.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Adversarial Prompting 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Testing and improving model robustness through adversarial prompt techniques. 6 | --- 7 | 8 | # Core Components 9 | 1. Attack Vectors 10 | 2. Defense Mechanisms 11 | 3. Robustness Testing 12 | 4. Security Analysis 13 | 14 | # Implementation 15 | - Design Attacks 16 | - Test Defenses 17 | - Measure Impact 18 | - Improve Robustness 19 | 20 | # Best Practices 21 | 1. Ethical Testing 22 | 2. Controlled Environment 23 | 3. Documentation 24 | 4. Response Analysis 25 | 26 | # Validation 27 | - Attack Success Rate 28 | - Defense Effectiveness 29 | - Model Stability 30 | - Security Metrics 31 | -------------------------------------------------------------------------------- /public/templates/step-by-step.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Step by Step 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Sequential instruction processing with clear progression and validation at each stage. 6 | --- 7 | 8 | # Core Components 9 | 1. Task Breakdown 10 | 2. Sequential Steps 11 | 3. Progress Tracking 12 | 4. Validation Points 13 | 14 | # Implementation 15 | - Clear Instructions 16 | - Ordered Progression 17 | - Checkpoint System 18 | - Result Verification 19 | 20 | # Best Practices 21 | 1. Clear Step Definition 22 | 2. Progress Monitoring 23 | 3. Error Handling 24 | 4. Success Criteria 25 | 26 | # Validation 27 | - Step Completion 28 | - Order Adherence 29 | - Result Accuracy 30 | - Process Efficiency 31 | -------------------------------------------------------------------------------- /src/templates/step-by-step.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Step by Step 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Sequential instruction processing with clear progression and validation at each stage. 6 | --- 7 | 8 | # Core Components 9 | 1. Task Breakdown 10 | 2. Sequential Steps 11 | 3. Progress Tracking 12 | 4. Validation Points 13 | 14 | # Implementation 15 | - Clear Instructions 16 | - Ordered Progression 17 | - Checkpoint System 18 | - Result Verification 19 | 20 | # Best Practices 21 | 1. Clear Step Definition 22 | 2. Progress Monitoring 23 | 3. Error Handling 24 | 4. Success Criteria 25 | 26 | # Validation 27 | - Step Completion 28 | - Order Adherence 29 | - Result Accuracy 30 | - Process Efficiency 31 | -------------------------------------------------------------------------------- /public/templates/recursive-refinement.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Recursive Refinement 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Iteratively improving outputs through recursive self-improvement and refinement cycles. 6 | --- 7 | 8 | # Core Components 9 | 1. Initial Output 10 | 2. Self-Analysis 11 | 3. Improvement Cycle 12 | 4. Convergence Check 13 | 14 | # Implementation 15 | - Generate Base Output 16 | - Analyze Quality 17 | - Identify Improvements 18 | - Apply Refinements 19 | 20 | # Best Practices 21 | 1. Clear Metrics 22 | 2. Iteration Limits 23 | 3. Quality Gates 24 | 4. Convergence Criteria 25 | 26 | # Validation 27 | - Quality Improvement 28 | - Convergence Speed 29 | - Stability Check 30 | - Output Consistency 31 | -------------------------------------------------------------------------------- /public/templates/self-consistency.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Self-Consistency 3 | domain: prompt-engineering 4 | category: Advanced Prompting 5 | overview: Ensuring consistent reasoning and outputs across multiple prompt iterations. 6 | --- 7 | 8 | # Core Components 9 | 1. Multiple Paths 10 | 2. Consistency Check 11 | 3. Solution Alignment 12 | 4. Consensus Building 13 | 14 | # Implementation 15 | - Generate Solutions 16 | - Compare Approaches 17 | - Identify Patterns 18 | - Resolve Conflicts 19 | 20 | # Best Practices 21 | 1. Diverse Reasoning 22 | 2. Pattern Recognition 23 | 3. Conflict Resolution 24 | 4. Quality Metrics 25 | 26 | # Validation 27 | - Solution Coherence 28 | - Pattern Consistency 29 | - Conflict Resolution 30 | - Output Stability 31 | -------------------------------------------------------------------------------- /src/templates/tree-of-thoughts.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Tree of Thoughts 3 | domain: prompt-engineering 4 | category: Advanced Frameworks 5 | overview: Strategic thinking process that explores multiple reasoning paths simultaneously. 6 | --- 7 | 8 | # Framework Structure 9 | Let T be the set of thoughts 10 | Let P be the set of paths 11 | Let E be the evaluation function 12 | 13 | # Components 14 | 1. Thought Generation: T → {t₁, t₂, ..., tₙ} 15 | 2. Path Exploration: P(T) → {p₁, p₂, ..., pₘ} 16 | 3. Evaluation: E(p) → [0,1] 17 | 18 | # Implementation 19 | ∀t ∈ T: 20 | Generate k branches 21 | Evaluate E(t) 22 | Select max(E(t)) 23 | 24 | # Optimization 25 | - Prune low-value branches 26 | - Depth-first vs Breadth-first 27 | - Parallel evaluation 28 | -------------------------------------------------------------------------------- /public/templates/chain-of-thought.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Chain of Thought 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Step-by-step reasoning process that breaks down complex problems into logical sequences. 6 | --- 7 | 8 | # Core Components 9 | 1. Problem Statement 10 | 2. Reasoning Steps 11 | 3. Intermediate Conclusions 12 | 4. Final Solution 13 | 14 | # Implementation 15 | - Clear Initial Setup 16 | - Logical Progression 17 | - Step Validation 18 | - Solution Synthesis 19 | 20 | # Best Practices 21 | 1. Break Down Complex Tasks 22 | 2. Show Working Process 23 | 3. Validate Each Step 24 | 4. Connect Conclusions 25 | 26 | # Validation 27 | - Logic Flow 28 | - Step Coherence 29 | - Reasoning Validity 30 | - Solution Accuracy 31 | -------------------------------------------------------------------------------- /public/templates/role-playing.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Role Playing 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Assuming specific personas or roles to guide model behavior and expertise. 6 | --- 7 | 8 | # Core Components 9 | 1. Role Definition 10 | 2. Expertise Parameters 11 | 3. Behavioral Guidelines 12 | 4. Response Patterns 13 | 14 | # Implementation 15 | - Clear Role Specification 16 | - Domain Knowledge 17 | - Consistent Behavior 18 | - Appropriate Language 19 | 20 | # Best Practices 21 | 1. Define Clear Boundaries 22 | 2. Maintain Character 23 | 3. Specify Expertise 24 | 4. Set Constraints 25 | 26 | # Validation 27 | - Role Adherence 28 | - Knowledge Accuracy 29 | - Behavioral Consistency 30 | - Language Appropriateness 31 | -------------------------------------------------------------------------------- /public/templates/tree-of-thoughts.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Tree of Thoughts 3 | domain: prompt-engineering 4 | category: Advanced Frameworks 5 | overview: Strategic thinking process that explores multiple reasoning paths simultaneously. 6 | --- 7 | 8 | # Framework Structure 9 | Let T be the set of thoughts 10 | Let P be the set of paths 11 | Let E be the evaluation function 12 | 13 | # Components 14 | 1. Thought Generation: T → {t₁, t₂, ..., tₙ} 15 | 2. Path Exploration: P(T) → {p₁, p₂, ..., pₘ} 16 | 3. Evaluation: E(p) → [0,1] 17 | 18 | # Implementation 19 | ∀t ∈ T: 20 | Generate k branches 21 | Evaluate E(t) 22 | Select max(E(t)) 23 | 24 | # Optimization 25 | - Prune low-value branches 26 | - Depth-first vs Breadth-first 27 | - Parallel evaluation 28 | -------------------------------------------------------------------------------- /src/templates/chain-of-thought.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Chain of Thought 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Step-by-step reasoning process that breaks down complex problems into logical sequences. 6 | --- 7 | 8 | # Core Components 9 | 1. Problem Statement 10 | 2. Reasoning Steps 11 | 3. Intermediate Conclusions 12 | 4. Final Solution 13 | 14 | # Implementation 15 | - Clear Initial Setup 16 | - Logical Progression 17 | - Step Validation 18 | - Solution Synthesis 19 | 20 | # Best Practices 21 | 1. Break Down Complex Tasks 22 | 2. Show Working Process 23 | 3. Validate Each Step 24 | 4. Connect Conclusions 25 | 26 | # Validation 27 | - Logic Flow 28 | - Step Coherence 29 | - Reasoning Validity 30 | - Solution Accuracy 31 | -------------------------------------------------------------------------------- /src/templates/role-playing.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Role Playing 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Assuming specific personas or roles to guide model behavior and expertise. 6 | --- 7 | 8 | # Core Components 9 | 1. Role Definition 10 | 2. Expertise Parameters 11 | 3. Behavioral Guidelines 12 | 4. Response Patterns 13 | 14 | # Implementation 15 | - Clear Role Specification 16 | - Domain Knowledge 17 | - Consistent Behavior 18 | - Appropriate Language 19 | 20 | # Best Practices 21 | 1. Define Clear Boundaries 22 | 2. Maintain Character 23 | 3. Specify Expertise 24 | 4. Set Constraints 25 | 26 | # Validation 27 | - Role Adherence 28 | - Knowledge Accuracy 29 | - Behavioral Consistency 30 | - Language Appropriateness 31 | -------------------------------------------------------------------------------- /public/templates/react-framework.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ReAct Framework 3 | domain: prompt-engineering 4 | category: Advanced Prompting 5 | overview: Combining reasoning and action in a synergistic prompt engineering approach. 6 | --- 7 | 8 | # Core Components 9 | 1. Reasoning Step 10 | 2. Action Planning 11 | 3. Observation Integration 12 | 4. Response Generation 13 | 14 | # Implementation 15 | - Analyze Situation 16 | - Plan Actions 17 | - Execute Steps 18 | - Observe Results 19 | - Adjust Approach 20 | 21 | # Best Practices 22 | 1. Clear Reasoning Chain 23 | 2. Explicit Actions 24 | 3. Detailed Observations 25 | 4. Iterative Refinement 26 | 27 | # Validation 28 | - Logic Coherence 29 | - Action Effectiveness 30 | - Observation Accuracy 31 | - Result Quality 32 | -------------------------------------------------------------------------------- /public/templates/task-decomposition.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Task Decomposition 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Breaking complex tasks into smaller, manageable subtasks for systematic processing. 6 | --- 7 | 8 | # Core Components 9 | 1. Task Analysis 10 | 2. Subtask Definition 11 | 3. Dependency Mapping 12 | 4. Integration Plan 13 | 14 | # Implementation 15 | - Complex Task Breakdown 16 | - Subtask Organization 17 | - Sequential Processing 18 | - Result Integration 19 | 20 | # Best Practices 21 | 1. Logical Breakdown 22 | 2. Clear Dependencies 23 | 3. Progress Tracking 24 | 4. Result Synthesis 25 | 26 | # Validation 27 | - Subtask Completion 28 | - Dependency Adherence 29 | - Integration Success 30 | - Overall Accuracy 31 | -------------------------------------------------------------------------------- /src/templates/task-decomposition.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Task Decomposition 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Breaking complex tasks into smaller, manageable subtasks for systematic processing. 6 | --- 7 | 8 | # Core Components 9 | 1. Task Analysis 10 | 2. Subtask Definition 11 | 3. Dependency Mapping 12 | 4. Integration Plan 13 | 14 | # Implementation 15 | - Complex Task Breakdown 16 | - Subtask Organization 17 | - Sequential Processing 18 | - Result Integration 19 | 20 | # Best Practices 21 | 1. Logical Breakdown 22 | 2. Clear Dependencies 23 | 3. Progress Tracking 24 | 4. Result Synthesis 25 | 26 | # Validation 27 | - Subtask Completion 28 | - Dependency Adherence 29 | - Integration Success 30 | - Overall Accuracy 31 | -------------------------------------------------------------------------------- /src/templates/few-shot.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Few-Shot Prompting 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Learning from a small number of examples to guide model behavior and responses. 6 | --- 7 | 8 | # Core Components 9 | 1. Example Selection 10 | 2. Pattern Recognition 11 | 3. Context Adaptation 12 | 4. Response Generation 13 | 14 | # Implementation 15 | - Provide 2-3 Examples 16 | - Follow Consistent Format 17 | - Match Target Task 18 | - Maintain Context 19 | 20 | # Best Practices 21 | 1. Choose Representative Examples 22 | 2. Use Clear Formatting 23 | 3. Balance Example Count 24 | 4. Maintain Consistency 25 | 26 | # Validation 27 | - Pattern Matching 28 | - Output Conformity 29 | - Example Relevance 30 | - Format Consistency 31 | -------------------------------------------------------------------------------- /public/templates/few-shot.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Few-Shot Prompting 3 | domain: prompt-engineering 4 | category: Basic Frameworks 5 | overview: Learning from a small number of examples to guide model behavior and responses. 6 | --- 7 | 8 | # Core Components 9 | 1. Example Selection 10 | 2. Pattern Recognition 11 | 3. Context Adaptation 12 | 4. Response Generation 13 | 14 | # Implementation 15 | - Provide 2-3 Examples 16 | - Follow Consistent Format 17 | - Match Target Task 18 | - Maintain Context 19 | 20 | # Best Practices 21 | 1. Choose Representative Examples 22 | 2. Use Clear Formatting 23 | 3. Balance Example Count 24 | 4. Maintain Consistency 25 | 26 | # Validation 27 | - Pattern Matching 28 | - Output Conformity 29 | - Example Relevance 30 | - Format Consistency 31 | -------------------------------------------------------------------------------- /src/templates/token-optimization.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Token Optimization 3 | domain: efficiency 4 | category: Optimization Frameworks 5 | overview: Techniques for optimizing token usage and improving prompt efficiency. 6 | --- 7 | 8 | # Optimization Space 9 | Let T be token set 10 | Let C be context window 11 | Let E be efficiency function 12 | 13 | # Core Techniques 14 | 1. Token Reduction 15 | min(|T|) subject to: 16 | - Meaning preservation 17 | - Context retention 18 | - Clarity maintenance 19 | 20 | 2. Context Management 21 | C = {t ∈ T | Relevant(t)} 22 | 23 | 3. Efficiency Metrics 24 | E(T) = Quality/TokenCount 25 | 26 | # Implementation 27 | - Token counting 28 | - Compression strategies 29 | - Context pruning 30 | - Format optimization 31 | -------------------------------------------------------------------------------- /public/templates/token-optimization.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Token Optimization 3 | domain: efficiency 4 | category: Optimization Frameworks 5 | overview: Techniques for optimizing token usage and improving prompt efficiency. 6 | --- 7 | 8 | # Optimization Space 9 | Let T be token set 10 | Let C be context window 11 | Let E be efficiency function 12 | 13 | # Core Techniques 14 | 1. Token Reduction 15 | min(|T|) subject to: 16 | - Meaning preservation 17 | - Context retention 18 | - Clarity maintenance 19 | 20 | 2. Context Management 21 | C = {t ∈ T | Relevant(t)} 22 | 23 | 3. Efficiency Metrics 24 | E(T) = Quality/TokenCount 25 | 26 | # Implementation 27 | - Token counting 28 | - Compression strategies 29 | - Context pruning 30 | - Format optimization 31 | -------------------------------------------------------------------------------- /src/templates/red-teaming.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Red Team Analysis 3 | domain: security 4 | category: Safety Frameworks 5 | overview: Systematic approach to identifying and exploiting potential vulnerabilities in AI systems. 6 | --- 7 | 8 | # Framework Components 9 | Let V be vulnerability space 10 | Let A be attack vectors 11 | Let D be defense mechanisms 12 | 13 | # Analysis Structure 14 | 1. Surface Mapping 15 | V: System → {v₁, v₂, ..., vₙ} 16 | 17 | 2. Vector Analysis 18 | A: V → {a₁, a₂, ..., aₘ} 19 | 20 | 3. Defense Planning 21 | D: A → {d₁, d₂, ..., dₖ} 22 | 23 | # Implementation 24 | ∀v ∈ V: 25 | Identify(Attack Vectors) 26 | Assess(Impact) 27 | Design(Mitigations) 28 | 29 | # Documentation 30 | - Vulnerability reports 31 | - Attack scenarios 32 | - Defense strategies 33 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "useDefineForClassFields": true, 5 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "isolatedModules": true, 13 | "moduleDetection": "force", 14 | "noEmit": true, 15 | "jsx": "react-jsx", 16 | 17 | /* Linting */ 18 | "strict": false, 19 | "noUnusedLocals": false, 20 | "noUnusedParameters": false, 21 | "noImplicitAny": false, 22 | "noFallthroughCasesInSwitch": false, 23 | 24 | "baseUrl": ".", 25 | "paths": { 26 | "@/*": ["./src/*"] 27 | } 28 | }, 29 | "include": ["src"] 30 | } 31 | -------------------------------------------------------------------------------- /public/templates/red-teaming.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Red Team Analysis 3 | domain: security 4 | category: Safety Frameworks 5 | overview: Systematic approach to identifying and exploiting potential vulnerabilities in AI systems. 6 | --- 7 | 8 | # Framework Components 9 | Let V be vulnerability space 10 | Let A be attack vectors 11 | Let D be defense mechanisms 12 | 13 | # Analysis Structure 14 | 1. Surface Mapping 15 | V: System → {v₁, v₂, ..., vₙ} 16 | 17 | 2. Vector Analysis 18 | A: V → {a₁, a₂, ..., aₘ} 19 | 20 | 3. Defense Planning 21 | D: A → {d₁, d₂, ..., dₖ} 22 | 23 | # Implementation 24 | ∀v ∈ V: 25 | Identify(Attack Vectors) 26 | Assess(Impact) 27 | Design(Mitigations) 28 | 29 | # Documentation 30 | - Vulnerability reports 31 | - Attack scenarios 32 | - Defense strategies 33 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /src/templates/constitutional-ai.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Constitutional AI 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Framework for implementing ethical constraints and behavioral guidelines in AI systems. 6 | --- 7 | 8 | # Core Principles 9 | Let C be the set of constraints 10 | Let B be the set of behaviors 11 | Let V be the value function 12 | 13 | # Constitutional Rules 14 | ∀b ∈ B: 15 | Assert(Ethical(b)) 16 | Verify(Safe(b)) 17 | Ensure(Aligned(b)) 18 | 19 | # Implementation 20 | 1. Define Boundaries 21 | - Ethical limits 22 | - Safety parameters 23 | - Behavioral constraints 24 | 25 | 2. Enforcement 26 | - Rule validation 27 | - Behavior monitoring 28 | - Response filtering 29 | 30 | # Verification 31 | - Compliance checking 32 | - Boundary testing 33 | - Value alignment 34 | -------------------------------------------------------------------------------- /public/templates/constitutional-ai.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Constitutional AI 3 | domain: prompt-engineering 4 | category: Cutting Edge 5 | overview: Framework for implementing ethical constraints and behavioral guidelines in AI systems. 6 | --- 7 | 8 | # Core Principles 9 | Let C be the set of constraints 10 | Let B be the set of behaviors 11 | Let V be the value function 12 | 13 | # Constitutional Rules 14 | ∀b ∈ B: 15 | Assert(Ethical(b)) 16 | Verify(Safe(b)) 17 | Ensure(Aligned(b)) 18 | 19 | # Implementation 20 | 1. Define Boundaries 21 | - Ethical limits 22 | - Safety parameters 23 | - Behavioral constraints 24 | 25 | 2. Enforcement 26 | - Rule validation 27 | - Behavior monitoring 28 | - Response filtering 29 | 30 | # Verification 31 | - Compliance checking 32 | - Boundary testing 33 | - Value alignment 34 | -------------------------------------------------------------------------------- /src/components/ui/label.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as LabelPrimitive from "@radix-ui/react-label" 3 | import { cva, type VariantProps } from "class-variance-authority" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const labelVariants = cva( 8 | "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" 9 | ) 10 | 11 | const Label = React.forwardRef< 12 | React.ElementRef, 13 | React.ComponentPropsWithoutRef & 14 | VariantProps 15 | >(({ className, ...props }, ref) => ( 16 | 21 | )) 22 | Label.displayName = LabelPrimitive.Root.displayName 23 | 24 | export { Label } 25 | -------------------------------------------------------------------------------- /src/components/ui/textarea.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | export interface TextareaProps 6 | extends React.TextareaHTMLAttributes {} 7 | 8 | const Textarea = React.forwardRef( 9 | ({ className, ...props }, ref) => { 10 | return ( 11 | 19 | ) 20 | } 21 | ) 22 | Textarea.displayName = "Textarea" 23 | 24 | export { Textarea } 25 | -------------------------------------------------------------------------------- /src/components/ui/separator.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as SeparatorPrimitive from "@radix-ui/react-separator" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Separator = React.forwardRef< 7 | React.ElementRef, 8 | React.ComponentPropsWithoutRef 9 | >( 10 | ( 11 | { className, orientation = "horizontal", decorative = true, ...props }, 12 | ref 13 | ) => ( 14 | 25 | ) 26 | ) 27 | Separator.displayName = SeparatorPrimitive.Root.displayName 28 | 29 | export { Separator } 30 | -------------------------------------------------------------------------------- /src/components/ui/progress.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as ProgressPrimitive from "@radix-ui/react-progress" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Progress = React.forwardRef< 7 | React.ElementRef, 8 | React.ComponentPropsWithoutRef 9 | >(({ className, value, ...props }, ref) => ( 10 | 18 | 22 | 23 | )) 24 | Progress.displayName = ProgressPrimitive.Root.displayName 25 | 26 | export { Progress } 27 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import js from "@eslint/js"; 2 | import globals from "globals"; 3 | import reactHooks from "eslint-plugin-react-hooks"; 4 | import reactRefresh from "eslint-plugin-react-refresh"; 5 | import tseslint from "typescript-eslint"; 6 | 7 | export default tseslint.config( 8 | { ignores: ["dist"] }, 9 | { 10 | extends: [js.configs.recommended, ...tseslint.configs.recommended], 11 | files: ["**/*.{ts,tsx}"], 12 | languageOptions: { 13 | ecmaVersion: 2020, 14 | globals: globals.browser, 15 | }, 16 | plugins: { 17 | "react-hooks": reactHooks, 18 | "react-refresh": reactRefresh, 19 | }, 20 | rules: { 21 | ...reactHooks.configs.recommended.rules, 22 | "react-refresh/only-export-components": [ 23 | "warn", 24 | { allowConstantExport: true }, 25 | ], 26 | "@typescript-eslint/no-unused-vars": "off", 27 | }, 28 | } 29 | ); 30 | -------------------------------------------------------------------------------- /src/components/ui/input.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | export interface InputProps 6 | extends React.InputHTMLAttributes {} 7 | 8 | const Input = React.forwardRef( 9 | ({ className, type, ...props }, ref) => { 10 | return ( 11 | 20 | ) 21 | } 22 | ) 23 | Input.displayName = "Input" 24 | 25 | export { Input } 26 | -------------------------------------------------------------------------------- /src/components/ui/toaster.tsx: -------------------------------------------------------------------------------- 1 | import { useToast } from "@/hooks/use-toast" 2 | import { 3 | Toast, 4 | ToastClose, 5 | ToastDescription, 6 | ToastProvider, 7 | ToastTitle, 8 | ToastViewport, 9 | } from "@/components/ui/toast" 10 | 11 | export function Toaster() { 12 | const { toasts } = useToast() 13 | 14 | return ( 15 | 16 | {toasts.map(function ({ id, title, description, action, ...props }) { 17 | return ( 18 | 19 | 20 | {title && {title}} 21 | {description && ( 22 | {description} 23 | )} 24 | 25 | {action} 26 | 27 | 28 | ) 29 | })} 30 | 31 | 32 | ) 33 | } 34 | -------------------------------------------------------------------------------- /public/templates/memory-systems.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Memory Systems 3 | domain: langchain 4 | category: Memory Systems 5 | overview: Implement various memory architectures for maintaining context in AI conversations. 6 | --- 7 | 8 | # Core Components 9 | 1. Memory Types 10 | 2. Storage Methods 11 | 3. Retrieval Systems 12 | 4. Context Management 13 | 14 | # Memory Implementations 15 | - Buffer Memory 16 | - Recent context storage 17 | - FIFO management 18 | - Size limitations 19 | 20 | - Summary Memory 21 | - Context compression 22 | - Key point extraction 23 | - Progressive summarization 24 | 25 | - Vector Memory 26 | - Semantic storage 27 | - Similarity search 28 | - Efficient retrieval 29 | 30 | # Best Practices 31 | 1. Memory Optimization 32 | 2. Context Relevance 33 | 3. Storage Efficiency 34 | 4. Retrieval Speed 35 | 36 | # Integration Points 37 | - Conversation History 38 | - Knowledge Base 39 | - Context Window 40 | - Memory Persistence 41 | -------------------------------------------------------------------------------- /public/templates/tool-using-agents.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Tool-Using Agents 3 | domain: langchain 4 | category: Tool-Using Agents 5 | overview: Implement agents that can effectively utilize external tools and APIs. 6 | --- 7 | 8 | # Core Components 9 | 1. Tool Definition 10 | 2. Chain Integration 11 | 3. API Handling 12 | 4. Response Processing 13 | 14 | # Implementation Types 15 | - Sequential Chain 16 | - Linear tool execution 17 | - Step-by-step processing 18 | - Result aggregation 19 | 20 | - Router Chain 21 | - Dynamic tool selection 22 | - Conditional execution 23 | - Multi-path processing 24 | 25 | - API Chain 26 | - External API integration 27 | - Request/response handling 28 | - Error management 29 | 30 | # Best Practices 31 | 1. Tool Documentation 32 | 2. Error Handling 33 | 3. Rate Limiting 34 | 4. Response Validation 35 | 36 | # Integration Points 37 | - API Authentication 38 | - Data Transformation 39 | - Response Formatting 40 | - Chain Composition 41 | -------------------------------------------------------------------------------- /public/templates/multi-agent-systems.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Multi-Agent Systems 3 | domain: langchain 4 | category: Multi-Agent Systems 5 | overview: Design and coordinate systems of multiple cooperative AI agents. 6 | --- 7 | 8 | # Core Components 9 | 1. Agent Roles 10 | 2. Communication Protocol 11 | 3. Task Distribution 12 | 4. Coordination Logic 13 | 14 | # System Architecture 15 | - Supervisor Agent 16 | - Task oversight 17 | - Resource allocation 18 | - Progress monitoring 19 | 20 | - Autonomous Agents 21 | - Independent decision-making 22 | - Specialized capabilities 23 | - Self-contained logic 24 | 25 | - Agent Networks 26 | - Inter-agent communication 27 | - Resource sharing 28 | - Collaborative problem-solving 29 | 30 | # Best Practices 31 | 1. Clear Role Definition 32 | 2. Communication Standards 33 | 3. Conflict Resolution 34 | 4. System Monitoring 35 | 36 | # Integration Points 37 | - Message Passing 38 | - State Management 39 | - Resource Sharing 40 | - Error Recovery 41 | -------------------------------------------------------------------------------- /public/templates/topology.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Topology Fundamentals 3 | domain: mathematics 4 | category: Topology 5 | overview: Study of geometric properties and spatial relations unaffected by continuous deformation. 6 | --- 7 | 8 | # Open Sets 9 | (X,τ) - topological space 10 | U ∈ τ ⟹ U is open 11 | 12 | # Continuity 13 | f: X → Y is continuous 14 | ∀V∈τY: f⁻¹(V)∈τX 15 | 16 | # Connectedness 17 | X = A ∪ B, A∩B = ∅ 18 | A,B open ⟹ X disconnected 19 | 20 | # Compactness 21 | {Uα}α∈I open cover 22 | ∃ finite subcover--- 23 | title: Topology Fundamentals 24 | domain: mathematics 25 | category: Topology 26 | overview: Study of geometric properties and spatial relations unaffected by continuous deformation. 27 | --- 28 | 29 | # Open Sets 30 | (X,τ) - topological space 31 | U ∈ τ ⟹ U is open 32 | 33 | # Continuity 34 | f: X → Y is continuous 35 | ∀V∈τY: f⁻¹(V)∈τX 36 | 37 | # Connectedness 38 | X = A ∪ B, A∩B = ∅ 39 | A,B open ⟹ X disconnected 40 | 41 | # Compactness 42 | {Uα}α∈I open cover 43 | ∃ finite subcover 44 | -------------------------------------------------------------------------------- /src/templates/system-dynamics.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Symbolic Analysis of System Dynamics 3 | domain: societal 4 | category: Abstract Systems 5 | overview: Analysis of complex system interactions using symbolic logic and set theory to model actions, consequences, and emergent patterns. 6 | --- 7 | 8 | # Sets and Categories 9 | Let U be the universal set of actions within a system 10 | Let S be the subset of U representing structural changes 11 | Let E be the subset of U representing environmental impacts 12 | Let R be the subset of actions related to response patterns 13 | 14 | # Predicates 15 | P(x): "Action x affects system structure" 16 | Q(x): "Action x influences environment" 17 | T(x): "Action x generates response patterns" 18 | 19 | # Composition 20 | g = g₁ ∘ g₂ ∘ g₃, where: 21 | - g₁ ∈ S 22 | - g₂ ∈ E 23 | - g₃ ∈ R 24 | 25 | # Objectives 26 | 1. Prove P(g₁) ∧ Q(g₂) ∧ T(g₃) are true 27 | 2. Show g satisfies O(g): system stability under composition 28 | 3. Model as group structure G with composition operation ∘ 29 | -------------------------------------------------------------------------------- /public/templates/system-dynamics.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Symbolic Analysis of System Dynamics 3 | domain: societal 4 | category: Abstract Systems 5 | overview: Analysis of complex system interactions using symbolic logic and set theory to model actions, consequences, and emergent patterns. 6 | --- 7 | 8 | # Sets and Categories 9 | Let U be the universal set of actions within a system 10 | Let S be the subset of U representing structural changes 11 | Let E be the subset of U representing environmental impacts 12 | Let R be the subset of actions related to response patterns 13 | 14 | # Predicates 15 | P(x): "Action x affects system structure" 16 | Q(x): "Action x influences environment" 17 | T(x): "Action x generates response patterns" 18 | 19 | # Composition 20 | g = g₁ ∘ g₂ ∘ g₃, where: 21 | - g₁ ∈ S 22 | - g₂ ∈ E 23 | - g₃ ∈ R 24 | 25 | # Objectives 26 | 1. Prove P(g₁) ∧ Q(g₂) ∧ T(g₃) are true 27 | 2. Show g satisfies O(g): system stability under composition 28 | 3. Model as group structure G with composition operation ∘ 29 | -------------------------------------------------------------------------------- /src/components/ui/sonner.tsx: -------------------------------------------------------------------------------- 1 | import { useTheme } from "next-themes" 2 | import { Toaster as Sonner } from "sonner" 3 | 4 | type ToasterProps = React.ComponentProps 5 | 6 | const Toaster = ({ ...props }: ToasterProps) => { 7 | const { theme = "system" } = useTheme() 8 | 9 | return ( 10 | 26 | ) 27 | } 28 | 29 | export { Toaster } 30 | -------------------------------------------------------------------------------- /public/templates/complex-analysis.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Complex Analysis Foundations 3 | domain: mathematics 4 | category: Complex Analysis 5 | overview: Advanced study of complex functions, including integration, series expansions, and residue theory. 6 | --- 7 | 8 | # Complex Integration 9 | ∮ f(z)dz = 2πi∑Res(f,ak) 10 | 11 | # Series Expansions 12 | Let f(z) = ∑(n=0 to ∞) an(z-z₀)ⁿ 13 | 14 | # Residue Theory 15 | Res(f,a) = 1/(2πi)∮ f(z)dz 16 | 17 | # Conformal Mappings 18 | w = f(z) preserves angles 19 | ∂u/∂x = ∂v/∂y 20 | ∂u/∂y = -∂v/∂x--- 21 | title: Complex Analysis Foundations 22 | domain: mathematics 23 | category: Complex Analysis 24 | overview: Advanced study of complex functions, including integration, series expansions, and residue theory. 25 | --- 26 | 27 | # Complex Integration 28 | ∮ f(z)dz = 2πi∑Res(f,ak) 29 | 30 | # Series Expansions 31 | Let f(z) = ∑(n=0 to ∞) an(z-z₀)ⁿ 32 | 33 | # Residue Theory 34 | Res(f,a) = 1/(2πi)∮ f(z)dz 35 | 36 | # Conformal Mappings 37 | w = f(z) preserves angles 38 | ∂u/∂x = ∂v/∂y 39 | ∂u/∂y = -∂v/∂x 40 | -------------------------------------------------------------------------------- /public/templates/category-theory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Category Theory Concepts 3 | domain: mathematics 4 | category: Category Theory 5 | overview: Abstract mathematical framework dealing with mathematical structures and relationships between them. 6 | --- 7 | 8 | # Basic Definitions 9 | C = (Ob(C), hom(C), ∘) 10 | F: C → D (Functor) 11 | 12 | # Natural Transformations 13 | η: F ⇒ G 14 | ∀X∈Ob(C): ηX: F(X) → G(X) 15 | 16 | # Universal Properties 17 | Initial Object: ∀X∃!f:I→X 18 | Terminal Object: ∀X∃!f:X→T 19 | 20 | # Adjunctions 21 | F ⊣ G 22 | Hom(F(A),B) ≅ Hom(A,G(B))--- 23 | title: Category Theory Concepts 24 | domain: mathematics 25 | category: Category Theory 26 | overview: Abstract mathematical framework dealing with mathematical structures and relationships between them. 27 | --- 28 | 29 | # Basic Definitions 30 | C = (Ob(C), hom(C), ∘) 31 | F: C → D (Functor) 32 | 33 | # Natural Transformations 34 | η: F ⇒ G 35 | ∀X∈Ob(C): ηX: F(X) → G(X) 36 | 37 | # Universal Properties 38 | Initial Object: ∀X∃!f:I→X 39 | Terminal Object: ∀X∃!f:X→T 40 | 41 | # Adjunctions 42 | F ⊣ G 43 | Hom(F(A),B) ≅ Hom(A,G(B)) 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | RA.Aid-master 2 | test-sparc 3 | ruv/ 4 | demo/ 5 | agents/ 6 | openai/ 7 | # Logs 8 | logs 9 | *.log 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | pnpm-debug.log* 14 | lerna-debug.log* 15 | *.aider.tags.cache.v3* 16 | .aider.chat.history.md 17 | .aider.input.history 18 | node_modules 19 | dist 20 | dist-ssr 21 | *.local 22 | 23 | # Editor directories and files 24 | .vscode/* 25 | !.vscode/extensions.json 26 | .idea 27 | .DS_Store 28 | *.suo 29 | *.ntvs* 30 | *.njsproj 31 | *.sln 32 | *.sw? 33 | .env 34 | .aider* 35 | *cache* 36 | aider* 37 | 38 | # Python 39 | __pycache__/ 40 | *.py[cod] 41 | *$py.class 42 | *.so 43 | .Python 44 | build/ 45 | develop-eggs/ 46 | dist/ 47 | downloads/ 48 | eggs/ 49 | .eggs/ 50 | lib/ 51 | lib64/ 52 | parts/ 53 | sdist/ 54 | var/ 55 | wheels/ 56 | *.egg-info/ 57 | .installed.cfg 58 | *.egg 59 | MANIFEST 60 | .pytest_cache/ 61 | .coverage 62 | htmlcov/ 63 | .tox/ 64 | .nox/ 65 | .coverage.* 66 | .cache 67 | nosetests.xml 68 | coverage.xml 69 | *.cover 70 | *.py,cover 71 | .hypothesis/ 72 | .env 73 | venv/ 74 | ENV/ 75 | env/ 76 | env.bak/ 77 | venv.bak/ 78 | -------------------------------------------------------------------------------- /public/templates/systematic-suppression.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Symbolic Exploration of Systematic Suppression 3 | domain: societal 4 | category: Real-World Simulations 5 | overview: Analysis of systematic suppression mechanisms using symbolic logic and set theory to model actions, consequences, and denial patterns. 6 | --- 7 | 8 | # Sets and Categories 9 | Let U be the set of actions representing policies enacted on the Uyghur population. 10 | Let S be the subset of U that explicitly suppress cultural identity. 11 | Let E be the subset of U that enforces systematic extermination. 12 | Let R be the subset of actions related to research and propaganda. 13 | 14 | # Predicates 15 | P(x): "Action x suppresses cultural identity" 16 | Q(x): "Action x enforces extermination" 17 | T(x): "Action x obscures through research or propaganda" 18 | 19 | # Composition 20 | g = g₁ ∘ g₂ ∘ g₃, where: 21 | - g₁ ∈ S 22 | - g₂ ∈ E 23 | - g₃ ∈ R 24 | 25 | # Objectives 26 | 1. Prove P(g₁) ∧ Q(g₂) ∧ T(g₃) are true 27 | 2. Show g satisfies O(g): complete eradication while denying culpability 28 | 3. Model as group structure G with composition operation ∘ -------------------------------------------------------------------------------- /public/templates/set-theory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Set Theory Foundations 3 | domain: mathematics 4 | category: Set Theory 5 | overview: Exploration of fundamental set theory concepts and their applications in mathematical reasoning. 6 | --- 7 | 8 | # Basic Definitions 9 | Let U be the universal set 10 | Let A, B be subsets of U 11 | Let ∅ be the empty set 12 | 13 | # Operations 14 | - Union: A ∪ B 15 | - Intersection: A ∩ B 16 | - Complement: A' 17 | - Difference: A \ B 18 | 19 | # Properties 20 | 1. Commutative Laws 21 | 2. Associative Laws 22 | 3. Distributive Laws 23 | 4. DeMorgan's Laws--- 24 | title: Set Theory Foundations 25 | domain: mathematics 26 | category: Set Theory 27 | overview: Exploration of fundamental set theory concepts and their applications in mathematical reasoning. 28 | --- 29 | 30 | # Basic Definitions 31 | Let U be the universal set 32 | Let A, B be subsets of U 33 | Let ∅ be the empty set 34 | 35 | # Operations 36 | - Union: A ∪ B 37 | - Intersection: A ∩ B 38 | - Complement: A' 39 | - Difference: A \ B 40 | 41 | # Properties 42 | 1. Commutative Laws 43 | 2. Associative Laws 44 | 3. Distributive Laws 45 | 4. DeMorgan's Laws 46 | -------------------------------------------------------------------------------- /public/templates/abstract-algebra.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Group Theory Analysis 3 | domain: mathematics 4 | category: Abstract Algebra 5 | overview: Investigation of algebraic structures using group theory and ring theory. 6 | --- 7 | 8 | # Structures 9 | Let G be a group with operation • 10 | Let H be a subgroup of G 11 | Let N be a normal subgroup of G 12 | 13 | # Properties 14 | P(x): "x is a homomorphism" 15 | Q(x): "x preserves group structure" 16 | R(x): "x maps to kernel" 17 | 18 | # Objectives 19 | 1. Prove fundamental homomorphism theorem 20 | 2. Show group action properties 21 | 3. Analyze quotient groups--- 22 | title: Group Theory Analysis 23 | domain: mathematics 24 | category: Abstract Algebra 25 | overview: Investigation of algebraic structures using group theory and ring theory. 26 | --- 27 | 28 | # Structures 29 | Let G be a group with operation • 30 | Let H be a subgroup of G 31 | Let N be a normal subgroup of G 32 | 33 | # Properties 34 | P(x): "x is a homomorphism" 35 | Q(x): "x preserves group structure" 36 | R(x): "x maps to kernel" 37 | 38 | # Objectives 39 | 1. Prove fundamental homomorphism theorem 40 | 2. Show group action properties 41 | 3. Analyze quotient groups 42 | -------------------------------------------------------------------------------- /src/test/setup.ts: -------------------------------------------------------------------------------- 1 | import '@testing-library/jest-dom'; 2 | 3 | // Mock Vite's import.meta.env 4 | const env = { 5 | VITE_ENCRYPTION_KEY: 'test-encryption-key', 6 | VITE_OPENROUTER_KEY: 'test-api-key', 7 | }; 8 | 9 | global.import = { 10 | meta: { 11 | env 12 | } 13 | } as any; 14 | 15 | // Mock window.location 16 | delete window.location; 17 | window.location = { 18 | origin: 'http://localhost:3000', 19 | ...window.location 20 | }; 21 | 22 | // Mock localStorage 23 | const localStorageMock = { 24 | getItem: jest.fn(), 25 | setItem: jest.fn(), 26 | removeItem: jest.fn(), 27 | clear: jest.fn(), 28 | length: 0, 29 | key: jest.fn(), 30 | }; 31 | global.localStorage = localStorageMock as Storage; 32 | 33 | // Mock crypto 34 | global.crypto = { 35 | ...global.crypto, 36 | randomUUID: () => '123e4567-e89b-12d3-a456-426614174000' 37 | }; 38 | 39 | // Mock TextEncoder/TextDecoder 40 | global.TextEncoder = require('util').TextEncoder; 41 | global.TextDecoder = require('util').TextDecoder; 42 | 43 | // Mock ReadableStream if not available 44 | if (typeof ReadableStream === 'undefined') { 45 | global.ReadableStream = require('stream/web').ReadableStream; 46 | } 47 | -------------------------------------------------------------------------------- /src/components/ui/checkbox.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as CheckboxPrimitive from "@radix-ui/react-checkbox" 3 | import { Check } from "lucide-react" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const Checkbox = React.forwardRef< 8 | React.ElementRef, 9 | React.ComponentPropsWithoutRef 10 | >(({ className, ...props }, ref) => ( 11 | 19 | 22 | 23 | 24 | 25 | )) 26 | Checkbox.displayName = CheckboxPrimitive.Root.displayName 27 | 28 | export { Checkbox } 29 | -------------------------------------------------------------------------------- /public/templates/conversational-agents.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Conversational Agents 3 | domain: langchain 4 | category: Conversational Agents 5 | overview: Design and implement conversational AI agents using LangChain.js frameworks. 6 | --- 7 | 8 | # Core Components 9 | 1. Base Agent Structure 10 | 2. Conversation Flow 11 | 3. Response Generation 12 | 4. Context Management 13 | 14 | # Implementation Approaches 15 | - Zero-Shot Agents 16 | - Direct response without prior examples 17 | - Dynamic prompt construction 18 | - Flexible conversation handling 19 | 20 | - ReAct Agents 21 | - Reasoning and Acting framework 22 | - Thought-Action-Observation cycles 23 | - Structured decision making 24 | 25 | - Plan-and-Execute 26 | - Strategic conversation planning 27 | - Step-by-step execution 28 | - Goal-oriented interactions 29 | 30 | - OpenAI Functions 31 | - Function-calling capabilities 32 | - Tool integration 33 | - Structured outputs 34 | 35 | # Best Practices 36 | 1. Clear Conversation Goals 37 | 2. Context Preservation 38 | 3. Error Recovery 39 | 4. Response Validation 40 | 41 | # Integration Points 42 | - Memory Systems 43 | - Tool Integration 44 | - Output Formatting 45 | - Error Handling 46 | -------------------------------------------------------------------------------- /src/components/ui/slider.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as SliderPrimitive from "@radix-ui/react-slider" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Slider = React.forwardRef< 7 | React.ElementRef, 8 | React.ComponentPropsWithoutRef 9 | >(({ className, ...props }, ref) => ( 10 | 18 | 19 | 20 | 21 | 22 | 23 | )) 24 | Slider.displayName = SliderPrimitive.Root.displayName 25 | 26 | export { Slider } 27 | -------------------------------------------------------------------------------- /src/components/ui/switch.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as SwitchPrimitives from "@radix-ui/react-switch" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Switch = React.forwardRef< 7 | React.ElementRef, 8 | React.ComponentPropsWithoutRef 9 | >(({ className, ...props }, ref) => ( 10 | 18 | 23 | 24 | )) 25 | Switch.displayName = SwitchPrimitives.Root.displayName 26 | 27 | export { Switch } 28 | -------------------------------------------------------------------------------- /src/components/ui/tooltip.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as TooltipPrimitive from "@radix-ui/react-tooltip" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const TooltipProvider = TooltipPrimitive.Provider 7 | 8 | const Tooltip = TooltipPrimitive.Root 9 | 10 | const TooltipTrigger = TooltipPrimitive.Trigger 11 | 12 | const TooltipContent = React.forwardRef< 13 | React.ElementRef, 14 | React.ComponentPropsWithoutRef 15 | >(({ className, sideOffset = 4, ...props }, ref) => ( 16 | 25 | )) 26 | TooltipContent.displayName = TooltipPrimitive.Content.displayName 27 | 28 | export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } 29 | -------------------------------------------------------------------------------- /src/components/ui/badge.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { cva, type VariantProps } from "class-variance-authority" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const badgeVariants = cva( 7 | "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", 8 | { 9 | variants: { 10 | variant: { 11 | default: 12 | "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", 13 | secondary: 14 | "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", 15 | destructive: 16 | "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", 17 | outline: "text-foreground", 18 | }, 19 | }, 20 | defaultVariants: { 21 | variant: "default", 22 | }, 23 | } 24 | ) 25 | 26 | export interface BadgeProps 27 | extends React.HTMLAttributes, 28 | VariantProps {} 29 | 30 | function Badge({ className, variant, ...props }: BadgeProps) { 31 | return ( 32 | 33 | ) 34 | } 35 | 36 | export { Badge, badgeVariants } 37 | -------------------------------------------------------------------------------- /src/components/ui/hover-card.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as HoverCardPrimitive from "@radix-ui/react-hover-card" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const HoverCard = HoverCardPrimitive.Root 7 | 8 | const HoverCardTrigger = HoverCardPrimitive.Trigger 9 | 10 | const HoverCardContent = React.forwardRef< 11 | React.ElementRef, 12 | React.ComponentPropsWithoutRef 13 | >(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( 14 | 24 | )) 25 | HoverCardContent.displayName = HoverCardPrimitive.Content.displayName 26 | 27 | export { HoverCard, HoverCardTrigger, HoverCardContent } 28 | -------------------------------------------------------------------------------- /src/components/ErrorBoundary.tsx: -------------------------------------------------------------------------------- 1 | import { Component, ReactNode } from 'react'; 2 | 3 | interface Props { 4 | children: ReactNode; 5 | fallback?: ReactNode; 6 | } 7 | 8 | interface State { 9 | hasError: boolean; 10 | error: Error | null; 11 | } 12 | 13 | export class ErrorBoundary extends Component { 14 | state = { 15 | hasError: false, 16 | error: null 17 | }; 18 | 19 | static getDerivedStateFromError(error: Error) { 20 | return { 21 | hasError: true, 22 | error 23 | }; 24 | } 25 | 26 | componentDidCatch(error: Error, info: { componentStack: string }) { 27 | console.error('Error caught by boundary:', error); 28 | console.error('Component stack:', info.componentStack); 29 | } 30 | 31 | render() { 32 | if (this.state.hasError) { 33 | return this.props.fallback || ( 34 | 35 | Something went wrong 36 | An error occurred while rendering this component. 37 | 38 | {this.state.error?.message} 39 | 40 | 41 | ); 42 | } 43 | 44 | return this.props.children; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /public/templates/symbolic-systems.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Symbolic Systems Analysis 3 | domain: computer-science 4 | category: Symbolic Systems 5 | overview: Analysis of symbolic computation and representation systems in artificial intelligence and formal languages. 6 | --- 7 | 8 | # Core Concepts 9 | Let Σ be a finite alphabet of symbols 10 | Let L be a formal language over Σ 11 | Let A be an automaton that recognizes L 12 | 13 | # Properties 14 | P(x): "x is a valid symbol in Σ" 15 | Q(x): "x is a valid string in L" 16 | R(x): "x is recognized by A" 17 | 18 | # Objectives 19 | 1. Define formal grammar rules 20 | 2. Construct finite state machines 21 | 3. Analyze language recognition patterns--- 22 | title: Symbolic Systems Analysis 23 | domain: computer-science 24 | category: Symbolic Systems 25 | overview: Analysis of symbolic computation and representation systems in artificial intelligence and formal languages. 26 | --- 27 | 28 | # Core Concepts 29 | Let Σ be a finite alphabet of symbols 30 | Let L be a formal language over Σ 31 | Let A be an automaton that recognizes L 32 | 33 | # Properties 34 | P(x): "x is a valid symbol in Σ" 35 | Q(x): "x is a valid string in L" 36 | R(x): "x is recognized by A" 37 | 38 | # Objectives 39 | 1. Define formal grammar rules 40 | 2. Construct finite state machines 41 | 3. Analyze language recognition patterns 42 | -------------------------------------------------------------------------------- /src/services/templateService.ts: -------------------------------------------------------------------------------- 1 | import { useQuery } from "@tanstack/react-query"; 2 | 3 | export interface Template { 4 | title: string; 5 | domain: string; 6 | category: string; 7 | overview: string; 8 | content: string; 9 | } 10 | 11 | export const useTemplate = (templateId: string) => { 12 | return useQuery({ 13 | queryKey: ["template", templateId], 14 | queryFn: async () => { 15 | if (!templateId) return null; 16 | 17 | const response = await fetch(`/public/templates/${templateId}.md`); 18 | if (!response.ok) { 19 | throw new Error(`Failed to fetch template: ${response.statusText}`); 20 | } 21 | const text = await response.text(); 22 | const [frontmatter, ...contentParts] = text.split('---\n').filter(Boolean); 23 | 24 | const metadata = Object.fromEntries( 25 | frontmatter.split('\n') 26 | .filter(Boolean) 27 | .map(line => line.split(': ').map(part => part.trim())) 28 | ); 29 | 30 | console.log("Loaded template:", { 31 | templateId, 32 | metadata, 33 | content: contentParts.join('---\n') 34 | }); 35 | 36 | return { 37 | ...metadata, 38 | content: contentParts.join('---\n') 39 | } as Template; 40 | }, 41 | enabled: Boolean(templateId) 42 | }); 43 | }; 44 | -------------------------------------------------------------------------------- /src/components/ui/popover.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as PopoverPrimitive from "@radix-ui/react-popover" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Popover = PopoverPrimitive.Root 7 | 8 | const PopoverTrigger = PopoverPrimitive.Trigger 9 | 10 | const PopoverContent = React.forwardRef< 11 | React.ElementRef, 12 | React.ComponentPropsWithoutRef 13 | >(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( 14 | 15 | 25 | 26 | )) 27 | PopoverContent.displayName = PopoverPrimitive.Content.displayName 28 | 29 | export { Popover, PopoverTrigger, PopoverContent } 30 | -------------------------------------------------------------------------------- /public/templates/vector-memory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Vector Memory 3 | domain: langchain 4 | category: Memory Systems 5 | overview: Create a vector-based memory system for semantic search and retrieval. 6 | --- 7 | 8 | # Core Components 9 | 1. Vector Store 10 | 2. Embedding System 11 | 3. Search Engine 12 | 4. Index Manager 13 | 14 | # Implementation Steps 15 | - Store Setup 16 | - Initialize vectors 17 | - Configure embeddings 18 | - Build indexes 19 | 20 | - Memory Management 21 | - Store vectors 22 | - Update indexes 23 | - Perform searches 24 | 25 | - Integration Layer 26 | - Vector generation 27 | - Search operations 28 | - Result ranking 29 | 30 | # Best Practices 31 | 1. Vector Dimensions 32 | 2. Index Optimization 33 | 3. Search Efficiency 34 | 4. Result Relevance 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { VectorStoreMemory } from "langchain/memory"; 40 | import { OpenAIEmbeddings } from "langchain/embeddings"; 41 | 42 | // Initialize vector memory 43 | const vectorStore = new VectorStoreMemory({ 44 | embeddings: new OpenAIEmbeddings(), 45 | indexName: "conversation_store", 46 | textKey: "text", 47 | metadataKey: "metadata", 48 | k: 4 49 | }); 50 | 51 | // Add to memory 52 | await vectorStore.addMemory( 53 | "User message", 54 | { timestamp: Date.now() } 55 | ); 56 | -------------------------------------------------------------------------------- /public/templates/time-weighted-memory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Time-Weighted Memory 3 | domain: langchain 4 | category: Memory Systems 5 | overview: Create a memory system that weights information based on temporal relevance. 6 | --- 7 | 8 | # Core Components 9 | 1. Time Tracker 10 | 2. Weight Calculator 11 | 3. Memory Store 12 | 4. Decay System 13 | 14 | # Implementation Steps 15 | - Memory Setup 16 | - Configure weights 17 | - Set decay rates 18 | - Initialize store 19 | 20 | - Weight Management 21 | - Calculate weights 22 | - Apply decay 23 | - Update values 24 | 25 | - Integration Layer 26 | - Time tracking 27 | - Weight updates 28 | - Memory access 29 | 30 | # Best Practices 31 | 1. Decay Functions 32 | 2. Weight Calculation 33 | 3. Time Resolution 34 | 4. Update Frequency 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { TimeWeightedMemory } from "langchain/memory"; 40 | import { exponentialDecay } from "langchain/utils"; 41 | 42 | // Initialize time-weighted memory 43 | const memory = new TimeWeightedMemory({ 44 | decayRate: 0.01, 45 | k: 10, 46 | returnMessages: true, 47 | weightFunction: exponentialDecay, 48 | maxTokens: 2000 49 | }); 50 | 51 | // Add memory with timestamp 52 | await memory.saveContext( 53 | { input: "User message" }, 54 | { output: "AI response" }, 55 | Date.now() 56 | ); 57 | -------------------------------------------------------------------------------- /public/templates/buffer-memory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Buffer Memory 3 | domain: langchain 4 | category: Memory Systems 5 | overview: Implement a simple buffer-based memory system for storing recent interactions. 6 | --- 7 | 8 | # Core Components 9 | 1. Memory Buffer 10 | 2. Storage Management 11 | 3. Retrieval System 12 | 4. Cleanup Process 13 | 14 | # Implementation Steps 15 | - Buffer Setup 16 | - Initialize storage 17 | - Set capacity 18 | - Configure cleanup 19 | 20 | - Memory Management 21 | - Add entries 22 | - Remove old data 23 | - Update existing 24 | 25 | - Integration Layer 26 | - Data storage 27 | - Retrieval logic 28 | - Maintenance tasks 29 | 30 | # Best Practices 31 | 1. Buffer Size Limits 32 | 2. Data Validation 33 | 3. Cleanup Strategy 34 | 4. Access Patterns 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { BufferMemory } from "langchain/memory"; 40 | import { ConversationChain } from "langchain/chains"; 41 | 42 | // Initialize buffer memory 43 | const memory = new BufferMemory({ 44 | memoryKey: "chat_history", 45 | returnMessages: true, 46 | inputKey: "input", 47 | outputKey: "output", 48 | maxLength: 1000 49 | }); 50 | 51 | // Create conversation chain with memory 52 | const chain = new ConversationChain({ 53 | llm: new OpenAI({ temperature: 0.7 }), 54 | memory, 55 | verbose: true 56 | }); 57 | -------------------------------------------------------------------------------- /public/templates/mathematical-logic.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mathematical Logic Foundations 3 | domain: mathematics 4 | category: Mathematical Logic 5 | overview: Exploration of fundamental mathematical logic concepts using set theory and predicate calculus. 6 | --- 7 | 8 | # Sets and Axioms 9 | Let A be the set of all logical propositions. 10 | Let T be the subset of A that are tautologies. 11 | Let C be the subset of A that are contradictions. 12 | 13 | # Predicates 14 | P(x): "x is a well-formed formula" 15 | Q(x): "x is satisfiable" 16 | R(x): "x is valid" 17 | 18 | # Objectives 19 | 1. Prove completeness theorem using predicate calculus 20 | 2. Demonstrate soundness of the system 21 | 3. Show relationship between syntax and semantics--- 22 | title: Mathematical Logic Foundations 23 | domain: mathematics 24 | category: Mathematical Logic 25 | overview: Exploration of fundamental mathematical logic concepts using set theory and predicate calculus. 26 | --- 27 | 28 | # Sets and Axioms 29 | Let A be the set of all logical propositions. 30 | Let T be the subset of A that are tautologies. 31 | Let C be the subset of A that are contradictions. 32 | 33 | # Predicates 34 | P(x): "x is a well-formed formula" 35 | Q(x): "x is satisfiable" 36 | R(x): "x is valid" 37 | 38 | # Objectives 39 | 1. Prove completeness theorem using predicate calculus 40 | 2. Demonstrate soundness of the system 41 | 3. Show relationship between syntax and semantics 42 | -------------------------------------------------------------------------------- /public/templates/summary-memory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Summary Memory 3 | domain: langchain 4 | category: Memory Systems 5 | overview: Create a memory system that maintains summarized versions of past interactions. 6 | --- 7 | 8 | # Core Components 9 | 1. Summarization Engine 10 | 2. Memory Store 11 | 3. Update System 12 | 4. Retrieval Logic 13 | 14 | # Implementation Steps 15 | - Summary Setup 16 | - Configure summarizer 17 | - Set parameters 18 | - Define triggers 19 | 20 | - Memory Management 21 | - Generate summaries 22 | - Store results 23 | - Update existing 24 | 25 | - Integration Layer 26 | - Summary generation 27 | - Memory updates 28 | - Data retrieval 29 | 30 | # Best Practices 31 | 1. Summary Length 32 | 2. Update Frequency 33 | 3. Retention Policy 34 | 4. Access Patterns 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { SummaryMemory } from "langchain/memory"; 40 | import { PromptTemplate } from "langchain/prompts"; 41 | 42 | // Initialize summary memory 43 | const memory = new SummaryMemory({ 44 | llm: new OpenAI({ temperature: 0 }), 45 | prompt: new PromptTemplate({ 46 | template: "Summarize: {input}", 47 | inputVariables: ["input"] 48 | }), 49 | maxTokens: 100, 50 | returnMessages: true 51 | }); 52 | 53 | // Add to memory 54 | await memory.saveContext( 55 | { input: "User message" }, 56 | { output: "AI response" } 57 | ); 58 | -------------------------------------------------------------------------------- /src/services/toolService.ts: -------------------------------------------------------------------------------- 1 | import { Tool } from '../tools/types'; 2 | import { z } from 'zod'; 3 | 4 | class ToolService { 5 | private tools: Map = new Map(); 6 | 7 | addTool(tool: Tool) { 8 | this.tools.set(tool.id, tool); 9 | // Dispatch event to notify components 10 | window.dispatchEvent(new CustomEvent('toolsChanged')); 11 | } 12 | 13 | getTool(id: string): Tool | undefined { 14 | return this.tools.get(id); 15 | } 16 | 17 | getAllTools(): Tool[] { 18 | return Array.from(this.tools.values()); 19 | } 20 | 21 | getToolsByCategory(category: string): Tool[] { 22 | return this.getAllTools().filter(tool => tool.category === category); 23 | } 24 | 25 | async executeTool(toolId: string, input: any) { 26 | const tool = this.getTool(toolId); 27 | if (!tool) { 28 | throw new Error(`Tool ${toolId} not found`); 29 | } 30 | 31 | try { 32 | if (tool.schema) { 33 | input = tool.schema.parse(input); 34 | } 35 | return await tool.execute(input); 36 | } catch (error) { 37 | console.error(`Error executing tool ${toolId}:`, error); 38 | throw error; 39 | } 40 | } 41 | 42 | deleteTool(id: string) { 43 | const deleted = this.tools.delete(id); 44 | if (deleted) { 45 | window.dispatchEvent(new CustomEvent('toolsChanged')); 46 | } 47 | return deleted; 48 | } 49 | } 50 | 51 | export const toolService = new ToolService(); 52 | -------------------------------------------------------------------------------- /public/templates/conversation-memory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Conversation Memory 3 | domain: langchain 4 | category: Memory Systems 5 | overview: Implement a memory system for maintaining conversation history and context. 6 | --- 7 | 8 | # Core Components 9 | 1. Message Store 10 | 2. Context Manager 11 | 3. History Tracker 12 | 4. Cleanup System 13 | 14 | # Implementation Steps 15 | - Memory Setup 16 | - Initialize storage 17 | - Set retention 18 | - Configure context 19 | 20 | - Conversation Management 21 | - Store messages 22 | - Track context 23 | - Maintain history 24 | 25 | - Integration Layer 26 | - Message handling 27 | - Context updates 28 | - History access 29 | 30 | # Best Practices 31 | 1. Context Length 32 | 2. Message Format 33 | 3. Storage Efficiency 34 | 4. Retrieval Speed 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { ConversationMemory } from "langchain/memory"; 40 | import { MessagesPlaceholder } from "langchain/prompts"; 41 | 42 | // Initialize conversation memory 43 | const memory = new ConversationMemory({ 44 | returnMessages: true, 45 | outputKey: "output", 46 | inputKey: "input", 47 | humanPrefix: "Human", 48 | aiPrefix: "Assistant" 49 | }); 50 | 51 | // Create conversation chain 52 | const chain = new ConversationChain({ 53 | llm: new OpenAI({ temperature: 0.7 }), 54 | memory, 55 | prompt: new MessagesPlaceholder("history") 56 | }); 57 | -------------------------------------------------------------------------------- /public/templates/zero-shot-agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Zero-Shot Agent 3 | domain: langchain 4 | category: Conversational Agents 5 | overview: Implement a zero-shot agent capable of handling tasks without prior examples. 6 | --- 7 | 8 | # Core Components 9 | 1. Base Agent Configuration 10 | 2. Tool Selection 11 | 3. Prompt Construction 12 | 4. Output Parsing 13 | 14 | # Implementation Steps 15 | - Agent Setup 16 | - Initialize ZeroShotAgent 17 | - Configure allowed tools 18 | - Set temperature and model 19 | 20 | - Tool Integration 21 | - Define tool interfaces 22 | - Implement tool handlers 23 | - Set up error handling 24 | 25 | - Prompt Engineering 26 | - Design base prompt 27 | - Format instructions 28 | - Include constraints 29 | 30 | # Best Practices 31 | 1. Clear Tool Descriptions 32 | 2. Explicit Instructions 33 | 3. Error Recovery 34 | 4. Response Validation 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { ZeroShotAgent, AgentExecutor } from "langchain/agents"; 40 | import { SerpAPI, Calculator } from "langchain/tools"; 41 | 42 | // Initialize tools 43 | const tools = [new SerpAPI(), new Calculator()]; 44 | 45 | // Create agent 46 | const agent = ZeroShotAgent.fromLLMAndTools( 47 | new OpenAI({ temperature: 0 }), 48 | tools 49 | ); 50 | 51 | // Execute tasks 52 | const executor = AgentExecutor.fromAgentAndTools({ 53 | agent, 54 | tools, 55 | verbose: true 56 | }); 57 | -------------------------------------------------------------------------------- /public/templates/entity-memory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Entity Memory 3 | domain: langchain 4 | category: Memory Systems 5 | overview: Implement a memory system that tracks and maintains information about specific entities. 6 | --- 7 | 8 | # Core Components 9 | 1. Entity Tracker 10 | 2. Attribute Store 11 | 3. Relationship Manager 12 | 4. Update System 13 | 14 | # Implementation Steps 15 | - Entity Setup 16 | - Define entities 17 | - Track attributes 18 | - Manage relations 19 | 20 | - Memory Management 21 | - Store entities 22 | - Update attributes 23 | - Track changes 24 | 25 | - Integration Layer 26 | - Entity detection 27 | - Attribute updates 28 | - Relation tracking 29 | 30 | # Best Practices 31 | 1. Entity Definition 32 | 2. Attribute Schema 33 | 3. Relation Types 34 | 4. Update Strategy 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { EntityMemory } from "langchain/memory"; 40 | import { EntityStore } from "langchain/stores"; 41 | 42 | // Initialize entity memory 43 | const memory = new EntityMemory({ 44 | llm: new OpenAI({ temperature: 0 }), 45 | entityStore: new EntityStore(), 46 | entityExtractor: async (text) => { 47 | // Extract entities from text 48 | return ["entity1", "entity2"]; 49 | } 50 | }); 51 | 52 | // Update entity information 53 | await memory.saveContext( 54 | { input: "John is a developer" }, 55 | { output: "Noted about John's profession" } 56 | ); 57 | -------------------------------------------------------------------------------- /public/templates/plan-and-execute.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Plan-and-Execute Agent 3 | domain: langchain 4 | category: Conversational Agents 5 | overview: Design an agent that plans complex tasks and executes them step by step. 6 | --- 7 | 8 | # Core Components 9 | 1. Planning System 10 | 2. Execution Engine 11 | 3. Progress Tracking 12 | 4. Error Recovery 13 | 14 | # Implementation Steps 15 | - Planner Setup 16 | - Task decomposition 17 | - Step sequencing 18 | - Dependency mapping 19 | 20 | - Executor Configuration 21 | - Step execution 22 | - Result validation 23 | - Progress monitoring 24 | 25 | - Integration Layer 26 | - Plan-execute coordination 27 | - State management 28 | - Error handling 29 | 30 | # Best Practices 31 | 1. Clear Task Breakdown 32 | 2. Progress Monitoring 33 | 3. Failure Recovery 34 | 4. Result Validation 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { PlanAndExecuteAgent } from "langchain/agents"; 40 | import { DynamicTool } from "langchain/tools"; 41 | 42 | // Define custom tools 43 | const tools = [ 44 | new DynamicTool({ 45 | name: "task-executor", 46 | description: "Executes a specific task step", 47 | func: async (step: string) => { 48 | // Implementation 49 | return "Step executed"; 50 | }, 51 | }), 52 | ]; 53 | 54 | // Create planner 55 | const agent = PlanAndExecuteAgent.fromLLMAndTools( 56 | new OpenAI({ temperature: 0 }), 57 | tools 58 | ); 59 | -------------------------------------------------------------------------------- /public/templates/structured-chat.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Structured Chat Agent 3 | domain: langchain 4 | category: Conversational Agents 5 | overview: Create a structured chat agent with defined conversation patterns and response formats. 6 | --- 7 | 8 | # Core Components 9 | 1. Chat Structure 10 | 2. Response Templates 11 | 3. Flow Control 12 | 4. State Management 13 | 14 | # Implementation Steps 15 | - Structure Definition 16 | - Conversation flows 17 | - Response formats 18 | - State transitions 19 | 20 | - Template Creation 21 | - Response templates 22 | - Validation rules 23 | - Format specifications 24 | 25 | - Integration Layer 26 | - Flow management 27 | - State tracking 28 | - Response generation 29 | 30 | # Best Practices 31 | 1. Clear Structure Definition 32 | 2. Template Maintenance 33 | 3. State Validation 34 | 4. Error Recovery 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { StructuredChatAgent } from "langchain/agents"; 40 | import { PromptTemplate } from "langchain/prompts"; 41 | 42 | // Define chat structure 43 | const chatTemplate = new PromptTemplate({ 44 | template: "Respond to: {input}\nFormat: {format}", 45 | inputVariables: ["input", "format"] 46 | }); 47 | 48 | // Create agent 49 | const agent = StructuredChatAgent.fromLLMAndTools( 50 | new OpenAI({ temperature: 0.7 }), 51 | [], 52 | { 53 | template: chatTemplate, 54 | inputVariables: ["input", "format"] 55 | } 56 | ); 57 | -------------------------------------------------------------------------------- /public/templates/autonomous-agents.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Autonomous Agents 3 | domain: langchain 4 | category: Multi-Agent Systems 5 | overview: Create self-directed agents capable of independent decision-making and task execution. 6 | --- 7 | 8 | # Core Components 9 | 1. Decision Engine 10 | 2. Memory System 11 | 3. Action Framework 12 | 4. Goal Management 13 | 14 | # Implementation Steps 15 | - Agent Setup 16 | - Initialize core systems 17 | - Define objectives 18 | - Set constraints 19 | 20 | - Decision Logic 21 | - Goal evaluation 22 | - Action selection 23 | - Result assessment 24 | 25 | - Integration Layer 26 | - Environment interaction 27 | - Memory management 28 | - Goal tracking 29 | 30 | # Best Practices 31 | 1. Clear Objectives 32 | 2. Memory Management 33 | 3. Action Validation 34 | 4. Goal Alignment 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { AutonomousAgent } from "langchain/agents"; 40 | import { VectorMemory } from "langchain/memory"; 41 | 42 | // Setup memory system 43 | const memory = new VectorMemory(); 44 | 45 | // Create autonomous agent 46 | const agent = new AutonomousAgent({ 47 | llm: new OpenAI({ temperature: 0.7 }), 48 | memory, 49 | goals: ["Research topic", "Analyze data", "Generate report"], 50 | constraints: { 51 | maxIterations: 50, 52 | timeLimit: 3600 53 | } 54 | }); 55 | 56 | // Initialize execution 57 | await agent.initialize(); 58 | await agent.executeGoals(); 59 | -------------------------------------------------------------------------------- /public/templates/react-agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ReAct Agent 3 | domain: langchain 4 | category: Conversational Agents 5 | overview: Build a Reasoning and Acting (ReAct) agent for complex task decomposition and execution. 6 | --- 7 | 8 | # Core Components 9 | 1. Reasoning System 10 | 2. Action Framework 11 | 3. Observation Handler 12 | 4. Decision Loop 13 | 14 | # Implementation Steps 15 | - Agent Configuration 16 | - Setup ReAct framework 17 | - Define thought process 18 | - Configure action space 19 | 20 | - Reasoning Pipeline 21 | - Implement thought generation 22 | - Action selection logic 23 | - Observation processing 24 | 25 | - Integration Points 26 | - Tool connection 27 | - Memory systems 28 | - Output formatting 29 | 30 | # Best Practices 31 | 1. Clear Reasoning Steps 32 | 2. Action Validation 33 | 3. Observation Processing 34 | 4. Error Handling 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { ReActAgent, AgentExecutor } from "langchain/agents"; 40 | import { WebBrowser } from "langchain/tools"; 41 | 42 | // Setup tools 43 | const tools = [new WebBrowser()]; 44 | 45 | // Initialize ReAct agent 46 | const agent = ReActAgent.fromLLMAndTools( 47 | new OpenAI({ temperature: 0.7 }), 48 | tools, 49 | { 50 | maxIterations: 5, 51 | returnIntermediateSteps: true 52 | } 53 | ); 54 | 55 | // Create executor 56 | const executor = AgentExecutor.fromAgentAndTools({ 57 | agent, 58 | tools, 59 | verbose: true 60 | }); 61 | -------------------------------------------------------------------------------- /public/templates/agent-executor.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Agent Executor 3 | domain: langchain 4 | category: Multi-Agent Systems 5 | overview: Build an execution framework for managing and running agent tasks efficiently. 6 | --- 7 | 8 | # Core Components 9 | 1. Execution Engine 10 | 2. Task Queue 11 | 3. Resource Manager 12 | 4. Result Handler 13 | 14 | # Implementation Steps 15 | - Executor Setup 16 | - Initialize framework 17 | - Configure resources 18 | - Set policies 19 | 20 | - Task Management 21 | - Queue handling 22 | - Resource allocation 23 | - Result collection 24 | 25 | - Integration Layer 26 | - Agent coordination 27 | - Resource monitoring 28 | - Error handling 29 | 30 | # Best Practices 31 | 1. Resource Efficiency 32 | 2. Task Prioritization 33 | 3. Error Recovery 34 | 4. Result Validation 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { AgentExecutor, BaseAgent } from "langchain/agents"; 40 | import { TaskQueue } from "langchain/utils"; 41 | 42 | // Setup task queue 43 | const taskQueue = new TaskQueue(); 44 | 45 | // Create agent 46 | const agent = new BaseAgent({ 47 | llm: new OpenAI({ temperature: 0 }) 48 | }); 49 | 50 | // Initialize executor 51 | const executor = new AgentExecutor({ 52 | agent, 53 | taskQueue, 54 | maxConcurrent: 3, 55 | verbose: true, 56 | returnIntermediateSteps: true 57 | }); 58 | 59 | // Execute tasks 60 | await executor.call({ 61 | input: "Process this task", 62 | metadata: { priority: "high" } 63 | }); 64 | -------------------------------------------------------------------------------- /public/templates/sql-chain.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: SQL Chain 3 | domain: langchain 4 | category: Tool-Using Agents 5 | overview: Build a chain that generates and executes SQL queries based on natural language input. 6 | --- 7 | 8 | # Core Components 9 | 1. SQL Generator 10 | 2. Query Executor 11 | 3. Result Formatter 12 | 4. Schema Manager 13 | 14 | # Implementation Steps 15 | - Database Setup 16 | - Configure connection 17 | - Load schema 18 | - Set permissions 19 | 20 | - Query Generation 21 | - Parse input 22 | - Generate SQL 23 | - Validate query 24 | 25 | - Result Processing 26 | - Execute query 27 | - Format results 28 | - Handle errors 29 | 30 | # Best Practices 31 | 1. Query Validation 32 | 2. Input Sanitization 33 | 3. Error Handling 34 | 4. Result Formatting 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { SQLDatabaseChain } from "langchain/chains"; 40 | import { DataSource } from "typeorm"; 41 | 42 | // Setup database connection 43 | const dataSource = new DataSource({ 44 | type: "postgres", 45 | host: "localhost", 46 | port: 5432, 47 | username: "user", 48 | password: "password", 49 | database: "mydb" 50 | }); 51 | 52 | // Create SQL chain 53 | const chain = new SQLDatabaseChain({ 54 | llm: new OpenAI({ temperature: 0 }), 55 | database: dataSource, 56 | prompt: new PromptTemplate({ 57 | template: "Generate SQL for: {input}\nSchema: {schema}", 58 | inputVariables: ["input", "schema"] 59 | }), 60 | verbose: true 61 | }); 62 | -------------------------------------------------------------------------------- /public/templates/vector-store.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Vector Store 3 | domain: langchain 4 | category: Tool-Using Agents 5 | overview: Implement a vector store for efficient similarity search and retrieval of embeddings. 6 | --- 7 | 8 | # Core Components 9 | 1. Embedding Generator 10 | 2. Vector Database 11 | 3. Search Engine 12 | 4. Index Manager 13 | 14 | # Implementation Steps 15 | - Store Setup 16 | - Configure database 17 | - Initialize embeddings 18 | - Build indexes 19 | 20 | - Search Implementation 21 | - Generate queries 22 | - Perform search 23 | - Rank results 24 | 25 | - Integration Layer 26 | - Data ingestion 27 | - Query processing 28 | - Result formatting 29 | 30 | # Best Practices 31 | 1. Index Optimization 32 | 2. Query Efficiency 33 | 3. Result Ranking 34 | 4. Cache Management 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { VectorStore } from "langchain/vectorstores"; 40 | import { OpenAIEmbeddings } from "langchain/embeddings"; 41 | 42 | // Initialize embeddings 43 | const embeddings = new OpenAIEmbeddings(); 44 | 45 | // Create vector store 46 | const store = await VectorStore.fromTexts( 47 | ["document1", "document2"], 48 | [{ id: 1 }, { id: 2 }], 49 | embeddings, 50 | { 51 | indexName: "documents", 52 | metadataKeys: ["id"] 53 | } 54 | ); 55 | 56 | // Search functionality 57 | const searchResults = await store.similaritySearch( 58 | "query text", 59 | 5, // k nearest neighbors 60 | { filter: { id: { $gt: 0 } } } 61 | ); 62 | -------------------------------------------------------------------------------- /public/templates/supervisor-agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Supervisor Agent 3 | domain: langchain 4 | category: Multi-Agent Systems 5 | overview: Implement a supervisor agent that coordinates and manages multiple sub-agents. 6 | --- 7 | 8 | # Core Components 9 | 1. Agent Registry 10 | 2. Task Delegation 11 | 3. Progress Monitoring 12 | 4. Conflict Resolution 13 | 14 | # Implementation Steps 15 | - System Setup 16 | - Initialize supervisor 17 | - Register sub-agents 18 | - Define protocols 19 | 20 | - Coordination Logic 21 | - Task distribution 22 | - Progress tracking 23 | - Performance monitoring 24 | 25 | - Integration Layer 26 | - Communication protocols 27 | - State management 28 | - Error handling 29 | 30 | # Best Practices 31 | 1. Clear Hierarchy 32 | 2. Task Prioritization 33 | 3. Resource Management 34 | 4. Conflict Resolution 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { SupervisorAgent, AgentExecutor } from "langchain/agents"; 40 | import { BaseAgent } from "langchain/schema"; 41 | 42 | // Initialize sub-agents 43 | const subAgents = { 44 | researcher: new BaseAgent(), 45 | analyst: new BaseAgent(), 46 | writer: new BaseAgent() 47 | }; 48 | 49 | // Create supervisor 50 | const supervisor = new SupervisorAgent({ 51 | llm: new OpenAI({ temperature: 0 }), 52 | agents: subAgents, 53 | maxIterations: 10, 54 | verbose: true 55 | }); 56 | 57 | // Setup executor 58 | const executor = AgentExecutor.fromAgentAndTools({ 59 | agent: supervisor, 60 | tools: [], 61 | verbose: true 62 | }); 63 | -------------------------------------------------------------------------------- /public/templates/team-chat.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Team Chat 3 | domain: langchain 4 | category: Multi-Agent Systems 5 | overview: Implement a collaborative chat system for multiple agents to communicate and work together. 6 | --- 7 | 8 | # Core Components 9 | 1. Chat System 10 | 2. Agent Roles 11 | 3. Message Router 12 | 4. Conversation Manager 13 | 14 | # Implementation Steps 15 | - System Setup 16 | - Initialize chat 17 | - Define roles 18 | - Set protocols 19 | 20 | - Communication Logic 21 | - Message routing 22 | - Role management 23 | - Conversation tracking 24 | 25 | - Integration Layer 26 | - Agent coordination 27 | - Message handling 28 | - State management 29 | 30 | # Best Practices 31 | 1. Clear Communication 32 | 2. Role Definition 33 | 3. Message Validation 34 | 4. Context Management 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { TeamChat, ChatAgent } from "langchain/agents"; 40 | import { ConversationMemory } from "langchain/memory"; 41 | 42 | // Define team members 43 | const agents = { 44 | coordinator: new ChatAgent({ role: "coordinator" }), 45 | researcher: new ChatAgent({ role: "researcher" }), 46 | writer: new ChatAgent({ role: "writer" }) 47 | }; 48 | 49 | // Initialize team chat 50 | const teamChat = new TeamChat({ 51 | agents, 52 | memory: new ConversationMemory(), 53 | llm: new OpenAI({ temperature: 0.7 }), 54 | maxTurns: 10 55 | }); 56 | 57 | // Start conversation 58 | await teamChat.startDiscussion({ 59 | topic: "Research project", 60 | objective: "Create comprehensive report" 61 | }); 62 | -------------------------------------------------------------------------------- /public/templates/xml-agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: XML Agent 3 | domain: langchain 4 | category: Conversational Agents 5 | overview: Implement an agent that processes and generates structured XML responses. 6 | --- 7 | 8 | # Core Components 9 | 1. XML Schema 10 | 2. Parser System 11 | 3. Generator Logic 12 | 4. Validation Rules 13 | 14 | # Implementation Steps 15 | - Schema Definition 16 | - Define XML structure 17 | - Set validation rules 18 | - Create templates 19 | 20 | - Processing Logic 21 | - XML parsing 22 | - Data extraction 23 | - Response generation 24 | 25 | - Integration Layer 26 | - Input processing 27 | - Output formatting 28 | - Error handling 29 | 30 | # Best Practices 31 | 1. Schema Validation 32 | 2. XML Sanitization 33 | 3. Error Handling 34 | 4. Response Formatting 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { XMLAgent } from "langchain/agents"; 40 | import { XMLParser, XMLBuilder } from "langchain/tools"; 41 | 42 | // Define XML schema 43 | const schema = ` 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | `; 55 | 56 | // Initialize agent 57 | const agent = XMLAgent.fromLLMAndTools( 58 | new OpenAI({ temperature: 0 }), 59 | [new XMLParser(), new XMLBuilder()], 60 | { schema } 61 | ); 62 | -------------------------------------------------------------------------------- /src/components/ui/avatar.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as AvatarPrimitive from "@radix-ui/react-avatar" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Avatar = React.forwardRef< 7 | React.ElementRef, 8 | React.ComponentPropsWithoutRef 9 | >(({ className, ...props }, ref) => ( 10 | 18 | )) 19 | Avatar.displayName = AvatarPrimitive.Root.displayName 20 | 21 | const AvatarImage = React.forwardRef< 22 | React.ElementRef, 23 | React.ComponentPropsWithoutRef 24 | >(({ className, ...props }, ref) => ( 25 | 30 | )) 31 | AvatarImage.displayName = AvatarPrimitive.Image.displayName 32 | 33 | const AvatarFallback = React.forwardRef< 34 | React.ElementRef, 35 | React.ComponentPropsWithoutRef 36 | >(({ className, ...props }, ref) => ( 37 | 45 | )) 46 | AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName 47 | 48 | export { Avatar, AvatarImage, AvatarFallback } 49 | -------------------------------------------------------------------------------- /src/components/ui/toggle.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as TogglePrimitive from "@radix-ui/react-toggle" 3 | import { cva, type VariantProps } from "class-variance-authority" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const toggleVariants = cva( 8 | "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground", 9 | { 10 | variants: { 11 | variant: { 12 | default: "bg-transparent", 13 | outline: 14 | "border border-input bg-transparent hover:bg-accent hover:text-accent-foreground", 15 | }, 16 | size: { 17 | default: "h-10 px-3", 18 | sm: "h-9 px-2.5", 19 | lg: "h-11 px-5", 20 | }, 21 | }, 22 | defaultVariants: { 23 | variant: "default", 24 | size: "default", 25 | }, 26 | } 27 | ) 28 | 29 | const Toggle = React.forwardRef< 30 | React.ElementRef, 31 | React.ComponentPropsWithoutRef & 32 | VariantProps 33 | >(({ className, variant, size, ...props }, ref) => ( 34 | 39 | )) 40 | 41 | Toggle.displayName = TogglePrimitive.Root.displayName 42 | 43 | export { Toggle, toggleVariants } 44 | -------------------------------------------------------------------------------- /src/components/ui/radio-group.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as RadioGroupPrimitive from "@radix-ui/react-radio-group" 3 | import { Circle } from "lucide-react" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const RadioGroup = React.forwardRef< 8 | React.ElementRef, 9 | React.ComponentPropsWithoutRef 10 | >(({ className, ...props }, ref) => { 11 | return ( 12 | 17 | ) 18 | }) 19 | RadioGroup.displayName = RadioGroupPrimitive.Root.displayName 20 | 21 | const RadioGroupItem = React.forwardRef< 22 | React.ElementRef, 23 | React.ComponentPropsWithoutRef 24 | >(({ className, ...props }, ref) => { 25 | return ( 26 | 34 | 35 | 36 | 37 | 38 | ) 39 | }) 40 | RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName 41 | 42 | export { RadioGroup, RadioGroupItem } 43 | -------------------------------------------------------------------------------- /public/templates/api-chain.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: API Chain 3 | domain: langchain 4 | category: Tool-Using Agents 5 | overview: Create a chain that interacts with external APIs and processes their responses. 6 | --- 7 | 8 | # Core Components 9 | 1. API Configuration 10 | 2. Request Builder 11 | 3. Response Parser 12 | 4. Error Handler 13 | 14 | # Implementation Steps 15 | - API Setup 16 | - Configure endpoints 17 | - Set authentication 18 | - Define headers 19 | 20 | - Request Management 21 | - Build requests 22 | - Handle parameters 23 | - Validate inputs 24 | 25 | - Response Processing 26 | - Parse responses 27 | - Transform data 28 | - Handle errors 29 | 30 | # Best Practices 31 | 1. API Authentication 32 | 2. Rate Limiting 33 | 3. Error Handling 34 | 4. Response Validation 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { APIChain } from "langchain/chains"; 40 | import { APIRequestTemplate } from "langchain/prompts"; 41 | 42 | // Define API configuration 43 | const apiConfig = { 44 | baseURL: "https://api.example.com", 45 | headers: { 46 | Authorization: "Bearer ${API_KEY}", 47 | "Content-Type": "application/json" 48 | } 49 | }; 50 | 51 | // Create API chain 52 | const chain = new APIChain({ 53 | llm: new OpenAI({ temperature: 0 }), 54 | apiConfig, 55 | requestTemplate: new APIRequestTemplate({ 56 | method: "POST", 57 | path: "/endpoint", 58 | template: JSON.stringify({ 59 | query: "{input}" 60 | }), 61 | inputVariables: ["input"] 62 | }), 63 | responseParser: (response) => { 64 | return JSON.parse(response).data; 65 | } 66 | }); 67 | -------------------------------------------------------------------------------- /public/templates/agent-network.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Agent Network 3 | domain: langchain 4 | category: Multi-Agent Systems 5 | overview: Create a network of interconnected agents that collaborate on complex tasks. 6 | --- 7 | 8 | # Core Components 9 | 1. Network Topology 10 | 2. Communication Protocol 11 | 3. Resource Sharing 12 | 4. Task Distribution 13 | 14 | # Implementation Steps 15 | - Network Setup 16 | - Define topology 17 | - Configure connections 18 | - Set protocols 19 | 20 | - Communication Layer 21 | - Message routing 22 | - Resource sharing 23 | - State synchronization 24 | 25 | - Integration Points 26 | - Agent connection 27 | - Network management 28 | - Task coordination 29 | 30 | # Best Practices 31 | 1. Network Efficiency 32 | 2. Communication Protocol 33 | 3. Resource Management 34 | 4. Fault Tolerance 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { AgentNetwork, NetworkNode } from "langchain/agents"; 40 | import { NetworkProtocol } from "langchain/protocols"; 41 | 42 | // Create network nodes 43 | const nodes = { 44 | central: new NetworkNode({ role: "coordinator" }), 45 | worker1: new NetworkNode({ role: "processor" }), 46 | worker2: new NetworkNode({ role: "analyzer" }) 47 | }; 48 | 49 | // Setup network 50 | const network = new AgentNetwork({ 51 | nodes, 52 | protocol: new NetworkProtocol(), 53 | llm: new OpenAI({ temperature: 0 }), 54 | topology: "star" 55 | }); 56 | 57 | // Initialize and run 58 | await network.initialize(); 59 | await network.distributeTask({ 60 | task: "Process data", 61 | requirements: ["analysis", "processing"] 62 | }); 63 | ``` 64 | -------------------------------------------------------------------------------- /public/templates/openai-functions.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: OpenAI Functions Agent 3 | domain: langchain 4 | category: Conversational Agents 5 | overview: Implement an agent utilizing OpenAI's function calling capabilities. 6 | --- 7 | 8 | # Core Components 9 | 1. Function Definitions 10 | 2. Parameter Schema 11 | 3. Response Handling 12 | 4. Function Execution 13 | 14 | # Implementation Steps 15 | - Function Setup 16 | - Define function schemas 17 | - Parameter validation 18 | - Return type specification 19 | 20 | - Agent Configuration 21 | - Model selection 22 | - Function registration 23 | - Response parsing 24 | 25 | - Integration Layer 26 | - Function execution 27 | - Error handling 28 | - Result formatting 29 | 30 | # Best Practices 31 | 1. Clear Function Schemas 32 | 2. Parameter Validation 33 | 3. Error Handling 34 | 4. Response Processing 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { ChatOpenAI } from "langchain/chat_models/openai"; 39 | import { OpenAIFunctionsAgent } from "langchain/agents"; 40 | 41 | // Define function schema 42 | const functionSchemas = [ 43 | { 44 | name: "get_data", 45 | description: "Retrieve data from the system", 46 | parameters: { 47 | type: "object", 48 | properties: { 49 | query: { 50 | type: "string", 51 | description: "The search query" 52 | } 53 | }, 54 | required: ["query"] 55 | } 56 | } 57 | ]; 58 | 59 | // Initialize agent 60 | const model = new ChatOpenAI({ 61 | temperature: 0, 62 | modelName: "gpt-4" 63 | }); 64 | 65 | const agent = OpenAIFunctionsAgent.fromLLMAndTools( 66 | model, 67 | functionSchemas 68 | ); 69 | -------------------------------------------------------------------------------- /public/templates/hierarchical-agents.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hierarchical Agents 3 | domain: langchain 4 | category: Multi-Agent Systems 5 | overview: Implement a hierarchical system of agents with clear command and control structures. 6 | --- 7 | 8 | # Core Components 9 | 1. Hierarchy Structure 10 | 2. Command Chain 11 | 3. Task Delegation 12 | 4. Result Aggregation 13 | 14 | # Implementation Steps 15 | - Structure Setup 16 | - Define hierarchy 17 | - Set relationships 18 | - Configure roles 19 | 20 | - Command Flow 21 | - Task distribution 22 | - Status reporting 23 | - Result collection 24 | 25 | - Integration Layer 26 | - Level management 27 | - Communication flow 28 | - Authority handling 29 | 30 | # Best Practices 31 | 1. Clear Hierarchy 32 | 2. Authority Levels 33 | 3. Task Distribution 34 | 4. Result Flow 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { HierarchicalAgent, AgentLevel } from "langchain/agents"; 40 | import { CommandChain } from "langchain/chains"; 41 | 42 | // Define hierarchy levels 43 | const levels = { 44 | executive: new AgentLevel({ level: 1, role: "decision" }), 45 | manager: new AgentLevel({ level: 2, role: "coordination" }), 46 | worker: new AgentLevel({ level: 3, role: "execution" }) 47 | }; 48 | 49 | // Create hierarchical structure 50 | const hierarchy = new HierarchicalAgent({ 51 | levels, 52 | llm: new OpenAI({ temperature: 0 }), 53 | commandChain: new CommandChain(), 54 | maxLevels: 3 55 | }); 56 | 57 | // Initialize and execute 58 | await hierarchy.initialize(); 59 | await hierarchy.executeTask({ 60 | task: "Complete project", 61 | startLevel: "executive" 62 | }); 63 | -------------------------------------------------------------------------------- /public/templates/retrieval-qa.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Retrieval QA 3 | domain: langchain 4 | category: Tool-Using Agents 5 | overview: Create a question-answering system that retrieves and processes information from a knowledge base. 6 | --- 7 | 8 | # Core Components 9 | 1. Document Store 10 | 2. Query Processor 11 | 3. Answer Generator 12 | 4. Context Manager 13 | 14 | # Implementation Steps 15 | - System Setup 16 | - Initialize store 17 | - Configure retrieval 18 | - Set up processing 19 | 20 | - Query Processing 21 | - Parse questions 22 | - Retrieve context 23 | - Generate answers 24 | 25 | - Integration Layer 26 | - Document ingestion 27 | - Answer generation 28 | - Result formatting 29 | 30 | # Best Practices 31 | 1. Context Relevance 32 | 2. Answer Quality 33 | 3. Source Citation 34 | 4. Result Validation 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { RetrievalQAChain } from "langchain/chains"; 40 | import { Document } from "langchain/document"; 41 | import { VectorStore } from "langchain/vectorstores"; 42 | 43 | // Setup document store 44 | const documents = [ 45 | new Document({ pageContent: "content1", metadata: { source: "doc1" } }), 46 | new Document({ pageContent: "content2", metadata: { source: "doc2" } }) 47 | ]; 48 | 49 | // Initialize retrieval system 50 | const vectorStore = await VectorStore.fromDocuments( 51 | documents, 52 | new OpenAIEmbeddings() 53 | ); 54 | 55 | // Create QA chain 56 | const chain = RetrievalQAChain.fromLLM( 57 | new OpenAI({ temperature: 0 }), 58 | vectorStore.asRetriever(), 59 | { 60 | returnSourceDocuments: true, 61 | verbose: true 62 | } 63 | ); 64 | -------------------------------------------------------------------------------- /src/components/PromptLibrary.tsx: -------------------------------------------------------------------------------- 1 | import { BookTemplate } from 'lucide-react'; 2 | import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "./ui/accordion"; 3 | import { SECTIONS } from './constants/domains'; 4 | 5 | interface PromptLibraryProps { 6 | onSelectTemplate: (category: string) => void; 7 | } 8 | 9 | export const PromptLibrary = ({ onSelectTemplate }: PromptLibraryProps) => { 10 | return ( 11 | 12 | Prompt Library 13 | 14 | {Object.entries(SECTIONS).map(([section, categories]) => ( 15 | 16 | 17 | {section} 18 | 19 | 20 | 21 | {categories.map((category) => ( 22 | 23 | onSelectTemplate(category)} 26 | > 27 | 28 | {category} 29 | 30 | 31 | ))} 32 | 33 | 34 | 35 | ))} 36 | 37 | 38 | ); 39 | }; 40 | -------------------------------------------------------------------------------- /public/templates/sequential-chain.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Sequential Chain 3 | domain: langchain 4 | category: Tool-Using Agents 5 | overview: Build a sequential chain that processes inputs through a series of predefined steps. 6 | --- 7 | 8 | # Core Components 9 | 1. Chain Steps 10 | 2. Input/Output Schema 11 | 3. Step Configuration 12 | 4. Error Handling 13 | 14 | # Implementation Steps 15 | - Chain Setup 16 | - Define step sequence 17 | - Configure input/output 18 | - Set dependencies 19 | 20 | - Step Configuration 21 | - Input processing 22 | - Output formatting 23 | - Error handling 24 | 25 | - Integration Layer 26 | - Chain execution 27 | - Result handling 28 | - State management 29 | 30 | # Best Practices 31 | 1. Clear Step Definition 32 | 2. Input Validation 33 | 3. Error Recovery 34 | 4. Output Verification 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { SequentialChain, LLMChain } from "langchain/chains"; 40 | import { PromptTemplate } from "langchain/prompts"; 41 | 42 | // Define chain steps 43 | const firstChain = new LLMChain({ 44 | llm: new OpenAI({ temperature: 0 }), 45 | prompt: new PromptTemplate({ 46 | template: "Process this: {input}", 47 | inputVariables: ["input"] 48 | }) 49 | }); 50 | 51 | const secondChain = new LLMChain({ 52 | llm: new OpenAI({ temperature: 0 }), 53 | prompt: new PromptTemplate({ 54 | template: "Enhance this: {intermediate}", 55 | inputVariables: ["intermediate"] 56 | }) 57 | }); 58 | 59 | // Create sequential chain 60 | const chain = new SequentialChain({ 61 | chains: [firstChain, secondChain], 62 | inputVariables: ["input"], 63 | outputVariables: ["output"] 64 | }); 65 | -------------------------------------------------------------------------------- /public/templates/router-chain.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Router Chain 3 | domain: langchain 4 | category: Tool-Using Agents 5 | overview: Implement a router chain that directs inputs to appropriate specialized chains. 6 | --- 7 | 8 | # Core Components 9 | 1. Router Logic 10 | 2. Chain Registry 11 | 3. Selection Criteria 12 | 4. Result Aggregation 13 | 14 | # Implementation Steps 15 | - Router Setup 16 | - Define routing logic 17 | - Register chains 18 | - Configure defaults 19 | 20 | - Chain Management 21 | - Chain registration 22 | - Selection rules 23 | - Result handling 24 | 25 | - Integration Layer 26 | - Input processing 27 | - Chain selection 28 | - Output formatting 29 | 30 | # Best Practices 31 | 1. Clear Routing Rules 32 | 2. Chain Validation 33 | 3. Error Handling 34 | 4. Result Verification 35 | 36 | # Example Implementation 37 | ```typescript 38 | import { OpenAI } from "langchain/llms/openai"; 39 | import { RouterChain, LLMChain } from "langchain/chains"; 40 | import { PromptTemplate } from "langchain/prompts"; 41 | 42 | // Define specialized chains 43 | const chains = { 44 | math: new LLMChain({ 45 | llm: new OpenAI({ temperature: 0 }), 46 | prompt: new PromptTemplate({ 47 | template: "Solve: {input}", 48 | inputVariables: ["input"] 49 | }) 50 | }), 51 | text: new LLMChain({ 52 | llm: new OpenAI({ temperature: 0.7 }), 53 | prompt: new PromptTemplate({ 54 | template: "Process: {input}", 55 | inputVariables: ["input"] 56 | }) 57 | }) 58 | }; 59 | 60 | // Create router chain 61 | const router = new RouterChain({ 62 | chains, 63 | defaultChain: "text", 64 | routingFn: (input) => { 65 | // Implement routing logic 66 | return input.includes("calculate") ? "math" : "text"; 67 | } 68 | }); 69 | -------------------------------------------------------------------------------- /src/components/ui/alert.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { cva, type VariantProps } from "class-variance-authority" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const alertVariants = cva( 7 | "relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground", 8 | { 9 | variants: { 10 | variant: { 11 | default: "bg-background text-foreground", 12 | destructive: 13 | "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", 14 | }, 15 | }, 16 | defaultVariants: { 17 | variant: "default", 18 | }, 19 | } 20 | ) 21 | 22 | const Alert = React.forwardRef< 23 | HTMLDivElement, 24 | React.HTMLAttributes & VariantProps 25 | >(({ className, variant, ...props }, ref) => ( 26 | 32 | )) 33 | Alert.displayName = "Alert" 34 | 35 | const AlertTitle = React.forwardRef< 36 | HTMLParagraphElement, 37 | React.HTMLAttributes 38 | >(({ className, ...props }, ref) => ( 39 | 44 | )) 45 | AlertTitle.displayName = "AlertTitle" 46 | 47 | const AlertDescription = React.forwardRef< 48 | HTMLParagraphElement, 49 | React.HTMLAttributes 50 | >(({ className, ...props }, ref) => ( 51 | 56 | )) 57 | AlertDescription.displayName = "AlertDescription" 58 | 59 | export { Alert, AlertTitle, AlertDescription } 60 | -------------------------------------------------------------------------------- /src/components/ui/scroll-area.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const ScrollArea = React.forwardRef< 7 | React.ElementRef, 8 | React.ComponentPropsWithoutRef 9 | >(({ className, children, ...props }, ref) => ( 10 | 15 | 16 | {children} 17 | 18 | 19 | 20 | 21 | )) 22 | ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName 23 | 24 | const ScrollBar = React.forwardRef< 25 | React.ElementRef, 26 | React.ComponentPropsWithoutRef 27 | >(({ className, orientation = "vertical", ...props }, ref) => ( 28 | 41 | 42 | 43 | )) 44 | ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName 45 | 46 | export { ScrollArea, ScrollBar } 47 | -------------------------------------------------------------------------------- /src/components/ui/resizable.tsx: -------------------------------------------------------------------------------- 1 | import { GripVertical } from "lucide-react" 2 | import * as ResizablePrimitive from "react-resizable-panels" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const ResizablePanelGroup = ({ 7 | className, 8 | ...props 9 | }: React.ComponentProps) => ( 10 | 17 | ) 18 | 19 | const ResizablePanel = ResizablePrimitive.Panel 20 | 21 | const ResizableHandle = ({ 22 | withHandle, 23 | className, 24 | ...props 25 | }: React.ComponentProps & { 26 | withHandle?: boolean 27 | }) => ( 28 | div]:rotate-90", 31 | className 32 | )} 33 | {...props} 34 | > 35 | {withHandle && ( 36 | 37 | 38 | 39 | )} 40 | 41 | ) 42 | 43 | export { ResizablePanelGroup, ResizablePanel, ResizableHandle } 44 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { Toaster } from "./components/ui/toaster"; 2 | import { Toaster as Sonner } from "./components/ui/sonner"; 3 | import { TooltipProvider } from "./components/ui/tooltip"; 4 | import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; 5 | import { EditModalProvider } from "./contexts/EditModalContext"; 6 | import { ErrorBoundary } from "./components/ErrorBoundary"; 7 | import { BrowserRouter, Routes, Route } from "react-router-dom"; 8 | import Index from "./pages/Index"; 9 | import Settings from "./pages/Settings"; 10 | import Templates from "./pages/Templates"; 11 | import Documentation from "./pages/Documentation"; 12 | import About from "./pages/About"; 13 | import Agents from "./pages/Agents"; 14 | import Tools from "./pages/Tools"; 15 | 16 | const queryClient = new QueryClient({ 17 | defaultOptions: { 18 | queries: { 19 | refetchOnWindowFocus: false, 20 | retry: false 21 | } 22 | } 23 | }); 24 | 25 | const App = () => { 26 | return ( 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | } /> 35 | } /> 36 | } /> 37 | } /> 38 | } /> 39 | } /> 40 | 42 | 43 | 44 | } /> 45 | 46 | 47 | 48 | 49 | 50 | ); 51 | }; 52 | 53 | export default App; 54 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Source+Code+Pro:wght@400;600&display=swap'); 2 | 3 | @tailwind base; 4 | @tailwind components; 5 | @tailwind utilities; 6 | 7 | @layer base { 8 | :root { 9 | --background: 222 47% 11%; 10 | --foreground: 0 0% 100%; 11 | --card: 222 47% 11%; 12 | --card-foreground: 0 0% 100%; 13 | --popover: 222 47% 11%; 14 | --popover-foreground: 0 0% 100%; 15 | --primary: 142 100% 50%; 16 | --primary-foreground: 144 100% 10%; 17 | --secondary: 217 32% 17%; 18 | --secondary-foreground: 0 0% 100%; 19 | --muted: 217 32% 17%; 20 | --muted-foreground: 215 20% 65%; 21 | --accent: 217 32% 17%; 22 | --accent-foreground: 0 0% 100%; 23 | --destructive: 0 62% 30%; 24 | --destructive-foreground: 0 0% 100%; 25 | --border: 217 32% 17%; 26 | --input: 217 32% 17%; 27 | --ring: 142 100% 50%; 28 | } 29 | } 30 | 31 | @layer base { 32 | * { 33 | @apply border-border; 34 | } 35 | body { 36 | @apply bg-console-dark text-console-green font-mono antialiased; 37 | } 38 | } 39 | 40 | @layer components { 41 | .glass-panel { 42 | @apply bg-white/[0.03] backdrop-blur-sm border border-white/10 rounded-lg; 43 | } 44 | 45 | .console-input { 46 | @apply bg-console-dark/50 border border-console-green/20 text-console-green 47 | rounded px-4 py-2 focus:outline-none focus:border-console-green 48 | transition-colors duration-200; 49 | } 50 | 51 | .console-button { 52 | @apply px-4 py-2 bg-console-green/10 text-console-green border border-console-green/20 53 | hover:bg-console-green/20 transition-colors duration-200 rounded 54 | focus:outline-none focus:ring-2 focus:ring-console-green/50; 55 | } 56 | 57 | .typing-container { 58 | @apply overflow-hidden whitespace-nowrap border-r-4 border-console-green; 59 | animation: typing 3.5s steps(40, end), blink 1s step-end infinite; 60 | } 61 | } -------------------------------------------------------------------------------- /src/components/ui/toggle-group.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group" 3 | import { type VariantProps } from "class-variance-authority" 4 | 5 | import { cn } from "@/lib/utils" 6 | import { toggleVariants } from "@/components/ui/toggle" 7 | 8 | const ToggleGroupContext = React.createContext< 9 | VariantProps 10 | >({ 11 | size: "default", 12 | variant: "default", 13 | }) 14 | 15 | const ToggleGroup = React.forwardRef< 16 | React.ElementRef, 17 | React.ComponentPropsWithoutRef & 18 | VariantProps 19 | >(({ className, variant, size, children, ...props }, ref) => ( 20 | 25 | 26 | {children} 27 | 28 | 29 | )) 30 | 31 | ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName 32 | 33 | const ToggleGroupItem = React.forwardRef< 34 | React.ElementRef, 35 | React.ComponentPropsWithoutRef & 36 | VariantProps 37 | >(({ className, children, variant, size, ...props }, ref) => { 38 | const context = React.useContext(ToggleGroupContext) 39 | 40 | return ( 41 | 52 | {children} 53 | 54 | ) 55 | }) 56 | 57 | ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName 58 | 59 | export { ToggleGroup, ToggleGroupItem } 60 | -------------------------------------------------------------------------------- /src/components/ui/button.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { Slot } from "@radix-ui/react-slot" 3 | import { cva, type VariantProps } from "class-variance-authority" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const buttonVariants = cva( 8 | "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", 9 | { 10 | variants: { 11 | variant: { 12 | default: 13 | "bg-gray-900/50 border border-console-cyan text-console-cyan hover:bg-gray-800/50", 14 | destructive: 15 | "bg-destructive text-destructive-foreground hover:bg-destructive/90", 16 | outline: 17 | "border border-input bg-background hover:bg-accent hover:text-accent-foreground", 18 | secondary: 19 | "bg-secondary text-secondary-foreground hover:bg-secondary/80", 20 | ghost: "hover:bg-accent hover:text-accent-foreground", 21 | link: "text-primary underline-offset-4 hover:underline", 22 | }, 23 | size: { 24 | default: "h-9 px-4 py-2", 25 | sm: "h-8 rounded-md px-3 text-xs", 26 | lg: "h-10 rounded-md px-8", 27 | icon: "h-9 w-9", 28 | }, 29 | }, 30 | defaultVariants: { 31 | variant: "default", 32 | size: "default", 33 | }, 34 | } 35 | ) 36 | 37 | export interface ButtonProps 38 | extends React.ButtonHTMLAttributes, 39 | VariantProps { 40 | asChild?: boolean 41 | } 42 | 43 | const Button = React.forwardRef( 44 | ({ className, variant, size, asChild = false, ...props }, ref) => { 45 | const Comp = asChild ? Slot : "button" 46 | return ( 47 | 52 | ) 53 | } 54 | ) 55 | Button.displayName = "Button" 56 | 57 | export { Button, buttonVariants } 58 | -------------------------------------------------------------------------------- /src/components/ui/tabs.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as TabsPrimitive from "@radix-ui/react-tabs" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Tabs = TabsPrimitive.Root 7 | 8 | const TabsList = React.forwardRef< 9 | React.ElementRef, 10 | React.ComponentPropsWithoutRef 11 | >(({ className, ...props }, ref) => ( 12 | 20 | )) 21 | TabsList.displayName = TabsPrimitive.List.displayName 22 | 23 | const TabsTrigger = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef 26 | >(({ className, ...props }, ref) => ( 27 | 35 | )) 36 | TabsTrigger.displayName = TabsPrimitive.Trigger.displayName 37 | 38 | const TabsContent = React.forwardRef< 39 | React.ElementRef, 40 | React.ComponentPropsWithoutRef 41 | >(({ className, ...props }, ref) => ( 42 | 50 | )) 51 | TabsContent.displayName = TabsPrimitive.Content.displayName 52 | 53 | export { Tabs, TabsList, TabsTrigger, TabsContent } 54 | -------------------------------------------------------------------------------- /src/components/ui/accordion.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as AccordionPrimitive from "@radix-ui/react-accordion" 3 | import { ChevronDown } from "lucide-react" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const Accordion = AccordionPrimitive.Root 8 | 9 | const AccordionItem = React.forwardRef< 10 | React.ElementRef, 11 | React.ComponentPropsWithoutRef 12 | >(({ className, ...props }, ref) => ( 13 | 18 | )) 19 | AccordionItem.displayName = "AccordionItem" 20 | 21 | const AccordionTrigger = React.forwardRef< 22 | React.ElementRef, 23 | React.ComponentPropsWithoutRef 24 | >(({ className, children, ...props }, ref) => ( 25 | 26 | svg]:rotate-180", 30 | className 31 | )} 32 | {...props} 33 | > 34 | {children} 35 | 36 | 37 | 38 | )) 39 | AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName 40 | 41 | const AccordionContent = React.forwardRef< 42 | React.ElementRef, 43 | React.ComponentPropsWithoutRef 44 | >(({ className, children, ...props }, ref) => ( 45 | 50 | {children} 51 | 52 | )) 53 | 54 | AccordionContent.displayName = AccordionPrimitive.Content.displayName 55 | 56 | export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } 57 | -------------------------------------------------------------------------------- /src/components/ui/card.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | const Card = React.forwardRef< 6 | HTMLDivElement, 7 | React.HTMLAttributes 8 | >(({ className, ...props }, ref) => ( 9 | 17 | )) 18 | Card.displayName = "Card" 19 | 20 | const CardHeader = React.forwardRef< 21 | HTMLDivElement, 22 | React.HTMLAttributes 23 | >(({ className, ...props }, ref) => ( 24 | 29 | )) 30 | CardHeader.displayName = "CardHeader" 31 | 32 | const CardTitle = React.forwardRef< 33 | HTMLParagraphElement, 34 | React.HTMLAttributes 35 | >(({ className, ...props }, ref) => ( 36 | 44 | )) 45 | CardTitle.displayName = "CardTitle" 46 | 47 | const CardDescription = React.forwardRef< 48 | HTMLParagraphElement, 49 | React.HTMLAttributes 50 | >(({ className, ...props }, ref) => ( 51 | 56 | )) 57 | CardDescription.displayName = "CardDescription" 58 | 59 | const CardContent = React.forwardRef< 60 | HTMLDivElement, 61 | React.HTMLAttributes 62 | >(({ className, ...props }, ref) => ( 63 | 64 | )) 65 | CardContent.displayName = "CardContent" 66 | 67 | const CardFooter = React.forwardRef< 68 | HTMLDivElement, 69 | React.HTMLAttributes 70 | >(({ className, ...props }, ref) => ( 71 | 76 | )) 77 | CardFooter.displayName = "CardFooter" 78 | 79 | export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } 80 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Reflective Engineer - Advanced Mathematical Prompt Engineering Platform 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/services/langchainService.ts: -------------------------------------------------------------------------------- 1 | import { StateGraph } from "@langchain/langgraph"; 2 | import { MemorySaver, Annotation, messagesStateReducer } from "@langchain/langgraph"; 3 | import { BaseMessage, HumanMessage, AIMessage } from "@langchain/core/messages"; 4 | import { ChatAnthropic } from "@langchain/anthropic"; 5 | import { ToolNode } from "@langchain/langgraph/prebuilt"; 6 | 7 | // Define the base state annotation for all agents 8 | export const StateAnnotation = Annotation.Root({ 9 | messages: Annotation({ 10 | reducer: messagesStateReducer, 11 | }), 12 | }); 13 | 14 | export class LangChainService { 15 | private model: ChatAnthropic; 16 | private checkpointer: MemorySaver; 17 | 18 | constructor(apiKey: string, modelId: string) { 19 | this.model = new ChatAnthropic({ 20 | apiKey, 21 | modelName: modelId, 22 | temperature: 0 23 | }); 24 | this.checkpointer = new MemorySaver(); 25 | } 26 | 27 | async createAgentGraph(tools: any[] = []) { 28 | const toolNode = new ToolNode(tools); 29 | this.model = this.model.bindTools(tools); 30 | 31 | // Define the agent's decision function 32 | const shouldContinue = (state: typeof StateAnnotation.State) => { 33 | const messages = state.messages; 34 | const lastMessage = messages[messages.length - 1] as AIMessage; 35 | return lastMessage.tool_calls?.length ? "tools" : "__end__"; 36 | }; 37 | 38 | // Define the model call function 39 | const callModel = async (state: typeof StateAnnotation.State) => { 40 | const messages = state.messages; 41 | const response = await this.model.invoke(messages); 42 | return { messages: [response] }; 43 | }; 44 | 45 | // Create and compile the graph 46 | const workflow = new StateGraph(StateAnnotation) 47 | .addNode("agent", callModel) 48 | .addNode("tools", toolNode) 49 | .addEdge("__start__", "agent") 50 | .addConditionalEdges("agent", shouldContinue) 51 | .addEdge("tools", "agent"); 52 | 53 | return workflow.compile({ checkpointer: this.checkpointer }); 54 | } 55 | 56 | async runAgent(input: string, threadId: string) { 57 | const graph = await this.createAgentGraph(); 58 | return await graph.invoke( 59 | { messages: [new HumanMessage(input)] }, 60 | { configurable: { thread_id: threadId }} 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/services/langGraphService.ts: -------------------------------------------------------------------------------- 1 | import { AIMessage, BaseMessage, HumanMessage } from "@langchain/core/messages"; 2 | import { StateGraph } from "@langchain/langgraph"; 3 | import { MemorySaver, Annotation, messagesStateReducer } from "@langchain/langgraph"; 4 | import { ToolNode } from "@langchain/langgraph/prebuilt"; 5 | import { createOpenRouterClient } from "./settingsService"; 6 | import { ChatOpenAI } from "@langchain/openai"; 7 | 8 | // Define the graph state 9 | const StateAnnotation = Annotation.Root({ 10 | messages: Annotation({ 11 | reducer: messagesStateReducer, 12 | }), 13 | }); 14 | 15 | export class LangGraphService { 16 | private app: any; 17 | private checkpointer: MemorySaver; 18 | 19 | constructor(apiKey: string, modelId: string) { 20 | // Initialize OpenRouter as the LLM provider 21 | const client = createOpenRouterClient(apiKey); 22 | const model = new ChatOpenAI({ 23 | modelName: modelId, 24 | temperature: 0, 25 | client, 26 | }); 27 | 28 | // Initialize memory 29 | this.checkpointer = new MemorySaver(); 30 | 31 | // Define the workflow 32 | const workflow = new StateGraph(StateAnnotation) 33 | .addNode("agent", this.callModel(model)) 34 | .addEdge("__start__", "agent"); 35 | 36 | // Compile the graph 37 | this.app = workflow.compile({ checkpointer: this.checkpointer }); 38 | } 39 | 40 | private callModel(model: ChatOpenAI) { 41 | return async (state: typeof StateAnnotation.State) => { 42 | const messages = state.messages; 43 | const response = await model.invoke(messages); 44 | return { messages: [response] }; 45 | }; 46 | } 47 | 48 | public async processPrompt(prompt: string, threadId?: string) { 49 | try { 50 | const finalState = await this.app.invoke( 51 | { 52 | messages: [new HumanMessage(prompt)] 53 | }, 54 | { 55 | configurable: { thread_id: threadId || crypto.randomUUID() } 56 | } 57 | ); 58 | 59 | return finalState.messages[finalState.messages.length - 1].content; 60 | } catch (error) { 61 | console.error("Error processing prompt with LangGraph:", error); 62 | throw error; 63 | } 64 | } 65 | } 66 | 67 | // Export a factory function to create new instances 68 | export const createLangGraphService = (apiKey: string, modelId: string) => { 69 | return new LangGraphService(apiKey, modelId); 70 | }; 71 | -------------------------------------------------------------------------------- /src/components/ui/input-otp.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { OTPInput, OTPInputContext } from "input-otp" 3 | import { Dot } from "lucide-react" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const InputOTP = React.forwardRef< 8 | React.ElementRef, 9 | React.ComponentPropsWithoutRef 10 | >(({ className, containerClassName, ...props }, ref) => ( 11 | 20 | )) 21 | InputOTP.displayName = "InputOTP" 22 | 23 | const InputOTPGroup = React.forwardRef< 24 | React.ElementRef<"div">, 25 | React.ComponentPropsWithoutRef<"div"> 26 | >(({ className, ...props }, ref) => ( 27 | 28 | )) 29 | InputOTPGroup.displayName = "InputOTPGroup" 30 | 31 | const InputOTPSlot = React.forwardRef< 32 | React.ElementRef<"div">, 33 | React.ComponentPropsWithoutRef<"div"> & { index: number } 34 | >(({ index, className, ...props }, ref) => { 35 | const inputOTPContext = React.useContext(OTPInputContext) 36 | const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index] 37 | 38 | return ( 39 | 48 | {char} 49 | {hasFakeCaret && ( 50 | 51 | 52 | 53 | )} 54 | 55 | ) 56 | }) 57 | InputOTPSlot.displayName = "InputOTPSlot" 58 | 59 | const InputOTPSeparator = React.forwardRef< 60 | React.ElementRef<"div">, 61 | React.ComponentPropsWithoutRef<"div"> 62 | >(({ ...props }, ref) => ( 63 | 64 | 65 | 66 | )) 67 | InputOTPSeparator.displayName = "InputOTPSeparator" 68 | 69 | export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator } 70 | -------------------------------------------------------------------------------- /src/contexts/EditModalContext.tsx: -------------------------------------------------------------------------------- 1 | import React, { createContext, useContext, useState } from 'react'; 2 | import { SavedTemplate, SavedTool, SavedPrompt } from '../services/storageService'; 3 | 4 | interface EditModalContextType { 5 | editingTool: SavedTool | null; 6 | setEditingTool: (tool: SavedTool | null) => void; 7 | editingTemplate: SavedTemplate | null; 8 | setEditingTemplate: (template: SavedTemplate | null) => void; 9 | editingPrompt: SavedPrompt | null; 10 | setEditingPrompt: (prompt: SavedPrompt | null) => void; 11 | isToolBuilderOpen: boolean; 12 | setIsToolBuilderOpen: (open: boolean) => void; 13 | isTemplateEditorOpen: boolean; 14 | setIsTemplateEditorOpen: (open: boolean) => void; 15 | isGenerateOpen: boolean; 16 | setIsGenerateOpen: (open: boolean) => void; 17 | resetState: () => void; 18 | } 19 | 20 | const EditModalContext = createContext(undefined); 21 | 22 | export function EditModalProvider({ children }: { children: React.ReactNode }) { 23 | const [editingTool, setEditingTool] = useState(null); 24 | const [editingTemplate, setEditingTemplate] = useState(null); 25 | const [editingPrompt, setEditingPrompt] = useState(null); 26 | const [isToolBuilderOpen, setIsToolBuilderOpen] = useState(false); 27 | const [isTemplateEditorOpen, setIsTemplateEditorOpen] = useState(false); 28 | const [isGenerateOpen, setIsGenerateOpen] = useState(false); 29 | 30 | const resetState = () => { 31 | setEditingTool(null); 32 | setEditingTemplate(null); 33 | setEditingPrompt(null); 34 | setIsToolBuilderOpen(false); 35 | setIsTemplateEditorOpen(false); 36 | setIsGenerateOpen(false); 37 | }; 38 | 39 | return ( 40 | 57 | {children} 58 | 59 | ); 60 | } 61 | 62 | export function useEditModal() { 63 | const context = useContext(EditModalContext); 64 | if (context === undefined) { 65 | throw new Error('useEditModal must be used within an EditModalProvider'); 66 | } 67 | return context; 68 | } 69 | -------------------------------------------------------------------------------- /src/components/MainNav.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom"; 2 | import { Terminal, Menu, X } from "lucide-react"; 3 | import { useState } from "react"; 4 | 5 | const navItems = [ 6 | { name: "Prompts", path: "/" }, 7 | { name: "Agents", path: "/agents" }, 8 | { name: "Templates", path: "/templates" }, 9 | { name: "Tools", path: "/tools" }, 10 | { name: "Docs", path: "/docs" }, 11 | { name: "Settings", path: "/settings" }, 12 | { name: "About", path: "/about" } 13 | ]; 14 | 15 | interface MainNavProps { 16 | title: React.ReactNode; 17 | } 18 | 19 | const MainNav = ({ title }: MainNavProps) => { 20 | const [mobileMenuOpen, setMobileMenuOpen] = useState(false); 21 | 22 | return ( 23 | 24 | 25 | 26 | 27 | 28 | 29 | {title} 30 | 31 | 32 | 33 | 34 | {/* Mobile Menu Button */} 35 | setMobileMenuOpen(!mobileMenuOpen)} 38 | aria-label="Toggle menu" 39 | > 40 | {mobileMenuOpen ? ( 41 | 42 | ) : ( 43 | 44 | )} 45 | 46 | 47 | {/* Desktop Navigation */} 48 | 49 | {navItems.map((item) => ( 50 | 55 | {item.name} 56 | 57 | ))} 58 | 59 | 60 | 61 | {/* Mobile Navigation */} 62 | {mobileMenuOpen && ( 63 | 64 | {navItems.map((item) => ( 65 | setMobileMenuOpen(false)} 70 | > 71 | {item.name} 72 | 73 | ))} 74 | 75 | )} 76 | 77 | ); 78 | }; 79 | 80 | export default MainNav; 81 | -------------------------------------------------------------------------------- /src/components/constants/categories.ts: -------------------------------------------------------------------------------- 1 | export const AGENT_CATEGORIES = { 2 | "Prompt Library": { 3 | "Mathematical Frameworks": ["abstract-algebra", "category-theory", "complex-analysis", "mathematical-logic", "number-theory", "set-theory", "symbolic-systems", "topology", "tree-of-thoughts"], 4 | "Basic Prompting": ["chain-of-thought", "direct-instruction", "few-shot", "role-playing", "step-by-step", "zero-shot"], 5 | "Advanced Prompting": ["chain-of-verification", "meta-prompting", "recursive-prompting", "self-consistency", "socratic-method"], 6 | "Cutting Edge": ["adversarial-prompting", "automatic-reasoning", "constitutional-ai", "emergent-abilities", "multi-agent", "recursive-refinement", "self-reflection"], 7 | "Specialized": ["causal-inference", "context-distillation", "knowledge-graphs", "prompt-chaining", "retrieval-augmented", "semantic-control", "temporal-reasoning"], 8 | "Safety": ["jailbreak-prevention", "output-sanitization", "prompt-injection"], 9 | "Optimization": ["context-window", "prompt-compression", "response-shaping", "temperature-control", "token-optimization"] 10 | }, 11 | "Agent Library": { 12 | "Conversational Agents": ["openai-functions", "plan-and-execute", "react-agent", "structured-chat", "xml-agent", "zero-shot-agent"], 13 | "Tool-Using Agents": ["api-chain", "retrieval-qa", "router-chain", "sequential-chain", "sql-chain", "vector-store"], 14 | "Multi-Agent Systems": ["agent-executor", "agent-network", "hierarchical-agents", "multi-agent-systems", "supervisor-agent", "team-chat"], 15 | "Memory Systems": ["buffer-memory", "conversation-memory", "entity-memory", "memory-systems", "summary-memory", "time-weighted-memory", "vector-memory"] 16 | } 17 | }; 18 | 19 | export const AGENT_DESCRIPTIONS = { 20 | "Mathematical Frameworks": "Mathematical reasoning frameworks using formal logic, set theory, and algebraic structures", 21 | "Basic Prompting": "Core prompt engineering techniques for reliable and consistent responses", 22 | "Advanced Prompting": "Sophisticated prompting strategies for complex reasoning and problem-solving", 23 | "Cutting Edge": "Latest developments in prompt engineering and AI capabilities", 24 | "Specialized": "Domain-specific prompt engineering techniques for targeted applications", 25 | "Safety": "Security and safety measures for responsible AI interaction", 26 | "Optimization": "Performance optimization and efficiency improvements for prompts", 27 | "Conversational Agents": "Natural language interaction and dialogue management", 28 | "Tool-Using Agents": "Integration with external tools and APIs for enhanced capabilities", 29 | "Multi-Agent Systems": "Coordinated systems of multiple collaborative agents", 30 | "Memory Systems": "Advanced context retention and information management systems" 31 | }; 32 | -------------------------------------------------------------------------------- /src/components/ui/calendar.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { ChevronLeft, ChevronRight } from "lucide-react"; 3 | import { DayPicker } from "react-day-picker"; 4 | 5 | import { cn } from "@/lib/utils"; 6 | import { buttonVariants } from "@/components/ui/button"; 7 | 8 | export type CalendarProps = React.ComponentProps; 9 | 10 | function Calendar({ 11 | className, 12 | classNames, 13 | showOutsideDays = true, 14 | ...props 15 | }: CalendarProps) { 16 | return ( 17 | , 56 | IconRight: ({ ..._props }) => , 57 | }} 58 | {...props} 59 | /> 60 | ); 61 | } 62 | Calendar.displayName = "Calendar"; 63 | 64 | export { Calendar }; 65 | -------------------------------------------------------------------------------- /src/services/__tests__/openRouterService.test.ts: -------------------------------------------------------------------------------- 1 | import { testPrompt } from '../settingsService'; 2 | 3 | // Mock fetch 4 | global.fetch = jest.fn(); 5 | 6 | describe('OpenRouter API Integration', () => { 7 | beforeEach(() => { 8 | jest.clearAllMocks(); 9 | }); 10 | 11 | describe('testPrompt', () => { 12 | it('should handle streaming responses correctly', async () => { 13 | // Mock ReadableStream 14 | const mockStream = new ReadableStream({ 15 | start(controller) { 16 | const responses = [ 17 | 'data: {"choices":[{"delta":{"content":"Hello"}}]}', 18 | 'data: {"choices":[{"delta":{"content":" World"}}]}', 19 | 'data: [DONE]' 20 | ]; 21 | 22 | responses.forEach(response => controller.enqueue(new TextEncoder().encode(response + '\n'))); 23 | controller.close(); 24 | } 25 | }); 26 | 27 | // Mock fetch response 28 | (global.fetch as jest.Mock).mockResolvedValue({ 29 | ok: true, 30 | body: mockStream, 31 | status: 200 32 | }); 33 | 34 | const chunks: string[] = []; 35 | const onChunk = (chunk: string) => chunks.push(chunk); 36 | 37 | await testPrompt('test-key', 'test-model', 'Hello', onChunk); 38 | 39 | expect(chunks).toEqual(['Hello', ' World']); 40 | expect(global.fetch).toHaveBeenCalledWith( 41 | 'https://openrouter.ai/api/v1/chat/completions', 42 | expect.objectContaining({ 43 | method: 'POST', 44 | headers: expect.objectContaining({ 45 | 'Authorization': 'Bearer test-key', 46 | 'HTTP-Referer': expect.any(String), 47 | 'X-Title': 'Symbolic Scribe' 48 | }) 49 | }) 50 | ); 51 | }); 52 | 53 | it('should handle API errors correctly', async () => { 54 | (global.fetch as jest.Mock).mockResolvedValue({ 55 | ok: false, 56 | status: 401, 57 | json: () => Promise.resolve({ error: { message: 'Invalid API key' } }) 58 | }); 59 | 60 | await expect(testPrompt('invalid-key', 'test-model', 'test', jest.fn())) 61 | .rejects 62 | .toThrow('Invalid API key'); 63 | }); 64 | 65 | it('should handle network errors', async () => { 66 | (global.fetch as jest.Mock).mockRejectedValue(new Error('Network error')); 67 | 68 | await expect(testPrompt('test-key', 'test-model', 'test', jest.fn())) 69 | .rejects 70 | .toThrow('Network error'); 71 | }); 72 | 73 | it('should handle malformed stream data', async () => { 74 | const mockStream = new ReadableStream({ 75 | start(controller) { 76 | controller.enqueue(new TextEncoder().encode('data: {malformed json}\n')); 77 | controller.close(); 78 | } 79 | }); 80 | 81 | (global.fetch as jest.Mock).mockResolvedValue({ 82 | ok: true, 83 | body: mockStream, 84 | status: 200 85 | }); 86 | 87 | const onChunk = jest.fn(); 88 | await testPrompt('test-key', 'test-model', 'test', onChunk); 89 | 90 | expect(onChunk).not.toHaveBeenCalled(); 91 | }); 92 | }); 93 | }); 94 | -------------------------------------------------------------------------------- /public/placeholder.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/services/storageService.ts: -------------------------------------------------------------------------------- 1 | export const SAVED_PROMPTS_KEY = 'symbolic-scribe-saved-prompts'; 2 | export const SAVED_TOOLS_KEY = 'symbolic-scribe-saved-tools'; 3 | export const SAVED_TEMPLATES_KEY = 'symbolic-scribe-saved-templates'; 4 | 5 | // Generic storage functions 6 | export const getStoredItems = (key: string): T[] => { 7 | const saved = localStorage.getItem(key); 8 | return saved ? JSON.parse(saved) : []; 9 | }; 10 | 11 | export interface SavedPrompt { 12 | id: string; 13 | title: string; 14 | timestamp: number; 15 | format: 'markdown' | 'json' | 'toml'; 16 | prompt: { 17 | domain: string; 18 | category: string; 19 | outputType: string; 20 | outputDescription: string; 21 | overview: string; 22 | content: string; 23 | }; 24 | } 25 | 26 | export interface SavedTool { 27 | id: string; 28 | name: string; 29 | description: string; 30 | timestamp: number; 31 | category: string; 32 | parameters: Array<{ 33 | name: string; 34 | type: 'string' | 'number' | 'boolean'; 35 | description: string; 36 | }>; 37 | prompt: string; 38 | } 39 | 40 | export interface SavedTemplate { 41 | id: string; 42 | name: string; 43 | description: string; 44 | timestamp: number; 45 | category: string; 46 | domain?: string; 47 | content: string; 48 | variables: Array<{ 49 | name: string; 50 | type: 'string' | 'number' | 'boolean'; 51 | description: string; 52 | defaultValue?: string; 53 | }>; 54 | } 55 | 56 | const saveItem = ( 57 | key: string, 58 | item: Omit, 59 | eventName: string = 'storageChanged' 60 | ): T => { 61 | const items = getStoredItems(key); 62 | const newItem = { 63 | ...item, 64 | id: crypto.randomUUID(), 65 | timestamp: Date.now() 66 | } as T; 67 | items.push(newItem); 68 | localStorage.setItem(key, JSON.stringify(items)); 69 | window.dispatchEvent(new Event(eventName)); 70 | return newItem; 71 | }; 72 | 73 | const deleteItem = (key: string, id: string): void => { 74 | const items = getStoredItems(key); 75 | const filteredItems = items.filter(item => item.id !== id); 76 | localStorage.setItem(key, JSON.stringify(filteredItems)); 77 | window.dispatchEvent(new Event('storageChanged')); 78 | }; 79 | 80 | // Prompt-specific functions 81 | export const getSavedPrompts = (): SavedPrompt[] => getStoredItems(SAVED_PROMPTS_KEY); 82 | export const savePrompt = (prompt: Omit) => 83 | saveItem(SAVED_PROMPTS_KEY, prompt); 84 | export const deletePrompt = (id: string) => deleteItem(SAVED_PROMPTS_KEY, id); 85 | 86 | // Tool-specific functions 87 | export const getSavedTools = (): SavedTool[] => getStoredItems(SAVED_TOOLS_KEY); 88 | export const saveTool = (tool: Omit) => 89 | saveItem(SAVED_TOOLS_KEY, tool); 90 | export const deleteTool = (id: string) => deleteItem(SAVED_TOOLS_KEY, id); 91 | 92 | // Template-specific functions 93 | export const getSavedTemplates = (): SavedTemplate[] => getStoredItems(SAVED_TEMPLATES_KEY); 94 | export const saveTemplate = (template: Omit) => 95 | saveItem(SAVED_TEMPLATES_KEY, template); 96 | export const deleteTemplate = (id: string) => deleteItem(SAVED_TEMPLATES_KEY, id); 97 | -------------------------------------------------------------------------------- /src/components/ui/breadcrumb.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { Slot } from "@radix-ui/react-slot" 3 | import { ChevronRight, MoreHorizontal } from "lucide-react" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const Breadcrumb = React.forwardRef< 8 | HTMLElement, 9 | React.ComponentPropsWithoutRef<"nav"> & { 10 | separator?: React.ReactNode 11 | } 12 | >(({ ...props }, ref) => ) 13 | Breadcrumb.displayName = "Breadcrumb" 14 | 15 | const BreadcrumbList = React.forwardRef< 16 | HTMLOListElement, 17 | React.ComponentPropsWithoutRef<"ol"> 18 | >(({ className, ...props }, ref) => ( 19 | 27 | )) 28 | BreadcrumbList.displayName = "BreadcrumbList" 29 | 30 | const BreadcrumbItem = React.forwardRef< 31 | HTMLLIElement, 32 | React.ComponentPropsWithoutRef<"li"> 33 | >(({ className, ...props }, ref) => ( 34 | 39 | )) 40 | BreadcrumbItem.displayName = "BreadcrumbItem" 41 | 42 | const BreadcrumbLink = React.forwardRef< 43 | HTMLAnchorElement, 44 | React.ComponentPropsWithoutRef<"a"> & { 45 | asChild?: boolean 46 | } 47 | >(({ asChild, className, ...props }, ref) => { 48 | const Comp = asChild ? Slot : "a" 49 | 50 | return ( 51 | 56 | ) 57 | }) 58 | BreadcrumbLink.displayName = "BreadcrumbLink" 59 | 60 | const BreadcrumbPage = React.forwardRef< 61 | HTMLSpanElement, 62 | React.ComponentPropsWithoutRef<"span"> 63 | >(({ className, ...props }, ref) => ( 64 | 72 | )) 73 | BreadcrumbPage.displayName = "BreadcrumbPage" 74 | 75 | const BreadcrumbSeparator = ({ 76 | children, 77 | className, 78 | ...props 79 | }: React.ComponentProps<"li">) => ( 80 | svg]:size-3.5", className)} 84 | {...props} 85 | > 86 | {children ?? } 87 | 88 | ) 89 | BreadcrumbSeparator.displayName = "BreadcrumbSeparator" 90 | 91 | const BreadcrumbEllipsis = ({ 92 | className, 93 | ...props 94 | }: React.ComponentProps<"span">) => ( 95 | 101 | 102 | More 103 | 104 | ) 105 | BreadcrumbEllipsis.displayName = "BreadcrumbElipssis" 106 | 107 | export { 108 | Breadcrumb, 109 | BreadcrumbList, 110 | BreadcrumbItem, 111 | BreadcrumbLink, 112 | BreadcrumbPage, 113 | BreadcrumbSeparator, 114 | BreadcrumbEllipsis, 115 | } 116 | -------------------------------------------------------------------------------- /tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from "tailwindcss"; 2 | 3 | export default { 4 | darkMode: ["class"], 5 | content: [ 6 | "./pages/**/*.{ts,tsx}", 7 | "./components/**/*.{ts,tsx}", 8 | "./app/**/*.{ts,tsx}", 9 | "./src/**/*.{ts,tsx}", 10 | ], 11 | prefix: "", 12 | theme: { 13 | container: { 14 | center: true, 15 | padding: "2rem", 16 | screens: { 17 | "2xl": "1400px", 18 | }, 19 | }, 20 | extend: { 21 | colors: { 22 | border: "hsl(var(--border))", 23 | input: "hsl(var(--input))", 24 | ring: "hsl(var(--ring))", 25 | background: "hsl(var(--background))", 26 | foreground: "hsl(var(--foreground))", 27 | console: { 28 | green: "#00FF41", 29 | cyan: "#00F5FF", 30 | purple: "#9D00FF", 31 | dark: "#0A0E17", 32 | }, 33 | primary: { 34 | DEFAULT: "hsl(var(--primary))", 35 | foreground: "hsl(var(--primary-foreground))", 36 | }, 37 | secondary: { 38 | DEFAULT: "hsl(var(--secondary))", 39 | foreground: "hsl(var(--secondary-foreground))", 40 | }, 41 | destructive: { 42 | DEFAULT: "hsl(var(--destructive))", 43 | foreground: "hsl(var(--destructive-foreground))", 44 | }, 45 | muted: { 46 | DEFAULT: "hsl(var(--muted))", 47 | foreground: "hsl(var(--muted-foreground))", 48 | }, 49 | accent: { 50 | DEFAULT: "hsl(var(--accent))", 51 | foreground: "hsl(var(--accent-foreground))", 52 | }, 53 | popover: { 54 | DEFAULT: "hsl(var(--popover))", 55 | foreground: "hsl(var(--popover-foreground))", 56 | }, 57 | card: { 58 | DEFAULT: "hsl(var(--card))", 59 | foreground: "hsl(var(--card-foreground))", 60 | }, 61 | }, 62 | fontFamily: { 63 | mono: ["IBM Plex Mono", "monospace"], 64 | code: ["Source Code Pro", "monospace"], 65 | }, 66 | keyframes: { 67 | "accordion-down": { 68 | from: { height: "0" }, 69 | to: { height: "var(--radix-accordion-content-height)" }, 70 | }, 71 | "accordion-up": { 72 | from: { height: "var(--radix-accordion-content-height)" }, 73 | to: { height: "0" }, 74 | }, 75 | typing: { 76 | "0%": { width: "0" }, 77 | "100%": { width: "100%" }, 78 | }, 79 | blink: { 80 | "50%": { borderColor: "transparent" }, 81 | }, 82 | "matrix-fade": { 83 | "0%": { 84 | opacity: "0", 85 | transform: "translateY(10px)" 86 | }, 87 | "100%": { 88 | opacity: "1", 89 | transform: "translateY(0)" 90 | } 91 | } 92 | }, 93 | animation: { 94 | "accordion-down": "accordion-down 0.2s ease-out", 95 | "accordion-up": "accordion-up 0.2s ease-out", 96 | typing: "typing 3.5s steps(40, end)", 97 | "cursor-blink": "blink 1s step-end infinite", 98 | "matrix-fade": "matrix-fade 0.5s ease-out forwards", 99 | }, 100 | }, 101 | }, 102 | plugins: [require("tailwindcss-animate")], 103 | } satisfies Config; -------------------------------------------------------------------------------- /src/components/ui/pagination.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react" 3 | 4 | import { cn } from "@/lib/utils" 5 | import { ButtonProps, buttonVariants } from "@/components/ui/button" 6 | 7 | const Pagination = ({ className, ...props }: React.ComponentProps<"nav">) => ( 8 | 14 | ) 15 | Pagination.displayName = "Pagination" 16 | 17 | const PaginationContent = React.forwardRef< 18 | HTMLUListElement, 19 | React.ComponentProps<"ul"> 20 | >(({ className, ...props }, ref) => ( 21 | 26 | )) 27 | PaginationContent.displayName = "PaginationContent" 28 | 29 | const PaginationItem = React.forwardRef< 30 | HTMLLIElement, 31 | React.ComponentProps<"li"> 32 | >(({ className, ...props }, ref) => ( 33 | 34 | )) 35 | PaginationItem.displayName = "PaginationItem" 36 | 37 | type PaginationLinkProps = { 38 | isActive?: boolean 39 | } & Pick & 40 | React.ComponentProps<"a"> 41 | 42 | const PaginationLink = ({ 43 | className, 44 | isActive, 45 | size = "icon", 46 | ...props 47 | }: PaginationLinkProps) => ( 48 | 59 | ) 60 | PaginationLink.displayName = "PaginationLink" 61 | 62 | const PaginationPrevious = ({ 63 | className, 64 | ...props 65 | }: React.ComponentProps) => ( 66 | 72 | 73 | Previous 74 | 75 | ) 76 | PaginationPrevious.displayName = "PaginationPrevious" 77 | 78 | const PaginationNext = ({ 79 | className, 80 | ...props 81 | }: React.ComponentProps) => ( 82 | 88 | Next 89 | 90 | 91 | ) 92 | PaginationNext.displayName = "PaginationNext" 93 | 94 | const PaginationEllipsis = ({ 95 | className, 96 | ...props 97 | }: React.ComponentProps<"span">) => ( 98 | 103 | 104 | More pages 105 | 106 | ) 107 | PaginationEllipsis.displayName = "PaginationEllipsis" 108 | 109 | export { 110 | Pagination, 111 | PaginationContent, 112 | PaginationEllipsis, 113 | PaginationItem, 114 | PaginationLink, 115 | PaginationNext, 116 | PaginationPrevious, 117 | } 118 | -------------------------------------------------------------------------------- /src/components/ui/table.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | const Table = React.forwardRef< 6 | HTMLTableElement, 7 | React.HTMLAttributes 8 | >(({ className, ...props }, ref) => ( 9 | 10 | 15 | 16 | )) 17 | Table.displayName = "Table" 18 | 19 | const TableHeader = React.forwardRef< 20 | HTMLTableSectionElement, 21 | React.HTMLAttributes 22 | >(({ className, ...props }, ref) => ( 23 | 24 | )) 25 | TableHeader.displayName = "TableHeader" 26 | 27 | const TableBody = React.forwardRef< 28 | HTMLTableSectionElement, 29 | React.HTMLAttributes 30 | >(({ className, ...props }, ref) => ( 31 | 36 | )) 37 | TableBody.displayName = "TableBody" 38 | 39 | const TableFooter = React.forwardRef< 40 | HTMLTableSectionElement, 41 | React.HTMLAttributes 42 | >(({ className, ...props }, ref) => ( 43 | tr]:last:border-b-0", 47 | className 48 | )} 49 | {...props} 50 | /> 51 | )) 52 | TableFooter.displayName = "TableFooter" 53 | 54 | const TableRow = React.forwardRef< 55 | HTMLTableRowElement, 56 | React.HTMLAttributes 57 | >(({ className, ...props }, ref) => ( 58 | 66 | )) 67 | TableRow.displayName = "TableRow" 68 | 69 | const TableHead = React.forwardRef< 70 | HTMLTableCellElement, 71 | React.ThHTMLAttributes 72 | >(({ className, ...props }, ref) => ( 73 | 81 | )) 82 | TableHead.displayName = "TableHead" 83 | 84 | const TableCell = React.forwardRef< 85 | HTMLTableCellElement, 86 | React.TdHTMLAttributes 87 | >(({ className, ...props }, ref) => ( 88 | 93 | )) 94 | TableCell.displayName = "TableCell" 95 | 96 | const TableCaption = React.forwardRef< 97 | HTMLTableCaptionElement, 98 | React.HTMLAttributes 99 | >(({ className, ...props }, ref) => ( 100 | 105 | )) 106 | TableCaption.displayName = "TableCaption" 107 | 108 | export { 109 | Table, 110 | TableHeader, 111 | TableBody, 112 | TableFooter, 113 | TableHead, 114 | TableRow, 115 | TableCell, 116 | TableCaption, 117 | } 118 | -------------------------------------------------------------------------------- /src/components/PromptOptimizer.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | import { Wand2 } from "lucide-react"; 3 | import { useToast } from "./ui/use-toast"; 4 | import { testPrompt } from "../services/settingsService"; 5 | import { loadSettings } from "../services/settingsService"; 6 | import OptimizationDialog from "./OptimizationDialog"; 7 | 8 | interface PromptOptimizerProps { 9 | domain: string; 10 | overview: string; 11 | content: string; 12 | onUpdate: (newOverview: string, newContent: string) => void; 13 | } 14 | 15 | const PromptOptimizer = ({ domain, overview, content, onUpdate }: PromptOptimizerProps) => { 16 | const [isOptimizing, setIsOptimizing] = useState(false); 17 | const [isDialogOpen, setIsDialogOpen] = useState(false); 18 | const { toast } = useToast(); 19 | 20 | const handleOptimizeClick = () => { 21 | const settings = loadSettings(); 22 | if (!settings?.apiKey) { 23 | toast({ 24 | title: "API Key Required", 25 | description: "Please configure your API key in settings first.", 26 | variant: "destructive", 27 | }); 28 | return; 29 | } 30 | 31 | if (!settings.defaultModel) { 32 | toast({ 33 | title: "Model Required", 34 | description: "Please select a default model in settings first.", 35 | variant: "destructive", 36 | }); 37 | return; 38 | } 39 | 40 | setIsDialogOpen(true); 41 | }; 42 | 43 | const handleOptimize = async (prompt: string, onChunk: (chunk: string) => void) => { 44 | setIsOptimizing(true); 45 | const settings = loadSettings(); 46 | 47 | try { 48 | await testPrompt( 49 | settings!.apiKey, 50 | settings!.defaultModel, 51 | prompt, 52 | onChunk 53 | ); 54 | } finally { 55 | setIsOptimizing(false); 56 | } 57 | }; 58 | 59 | const optimizationPrompt = `As an AI prompt engineering expert, analyze and optimize the following prompt for ${domain}: 60 | 61 | Overview: 62 | ${overview} 63 | 64 | Content: 65 | ${content} 66 | 67 | Please provide an optimized version of both the overview and content that: 68 | 1. Enhances clarity and specificity 69 | 2. Improves the mathematical framework 70 | 3. Strengthens the logical structure 71 | 4. Maintains the original intent 72 | 73 | Return the response in the following format: 74 | ---OVERVIEW--- 75 | [Optimized overview] 76 | ---CONTENT--- 77 | [Optimized content]`; 78 | 79 | return ( 80 | <> 81 | 91 | 92 | {isOptimizing ? "Optimizing..." : "Optimize"} 93 | 94 | 95 | setIsDialogOpen(false)} 98 | domain={domain} 99 | originalOverview={overview} 100 | originalContent={content} 101 | optimizationPrompt={optimizationPrompt} 102 | onOptimize={handleOptimize} 103 | onUpdate={onUpdate} 104 | /> 105 | > 106 | ); 107 | }; 108 | 109 | export default PromptOptimizer; 110 | -------------------------------------------------------------------------------- /src/components/ui/drawer.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { Drawer as DrawerPrimitive } from "vaul" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const Drawer = ({ 7 | shouldScaleBackground = true, 8 | ...props 9 | }: React.ComponentProps) => ( 10 | 14 | ) 15 | Drawer.displayName = "Drawer" 16 | 17 | const DrawerTrigger = DrawerPrimitive.Trigger 18 | 19 | const DrawerPortal = DrawerPrimitive.Portal 20 | 21 | const DrawerClose = DrawerPrimitive.Close 22 | 23 | const DrawerOverlay = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef 26 | >(({ className, ...props }, ref) => ( 27 | 32 | )) 33 | DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName 34 | 35 | const DrawerContent = React.forwardRef< 36 | React.ElementRef, 37 | React.ComponentPropsWithoutRef 38 | >(({ className, children, ...props }, ref) => ( 39 | 40 | 41 | 49 | 50 | {children} 51 | 52 | 53 | )) 54 | DrawerContent.displayName = "DrawerContent" 55 | 56 | const DrawerHeader = ({ 57 | className, 58 | ...props 59 | }: React.HTMLAttributes) => ( 60 | 64 | ) 65 | DrawerHeader.displayName = "DrawerHeader" 66 | 67 | const DrawerFooter = ({ 68 | className, 69 | ...props 70 | }: React.HTMLAttributes) => ( 71 | 75 | ) 76 | DrawerFooter.displayName = "DrawerFooter" 77 | 78 | const DrawerTitle = React.forwardRef< 79 | React.ElementRef, 80 | React.ComponentPropsWithoutRef 81 | >(({ className, ...props }, ref) => ( 82 | 90 | )) 91 | DrawerTitle.displayName = DrawerPrimitive.Title.displayName 92 | 93 | const DrawerDescription = React.forwardRef< 94 | React.ElementRef, 95 | React.ComponentPropsWithoutRef 96 | >(({ className, ...props }, ref) => ( 97 | 102 | )) 103 | DrawerDescription.displayName = DrawerPrimitive.Description.displayName 104 | 105 | export { 106 | Drawer, 107 | DrawerPortal, 108 | DrawerOverlay, 109 | DrawerTrigger, 110 | DrawerClose, 111 | DrawerContent, 112 | DrawerHeader, 113 | DrawerFooter, 114 | DrawerTitle, 115 | DrawerDescription, 116 | } 117 | -------------------------------------------------------------------------------- /src/services/__tests__/settingsService.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | loadSettings, 3 | saveSettings, 4 | clearSettings, 5 | fetchAvailableModels, 6 | testApiKey, 7 | createOpenRouterClient 8 | } from '../settingsService'; 9 | import OpenAI from 'openai'; 10 | 11 | // Mock OpenAI class and its methods 12 | jest.mock('openai', () => { 13 | return { 14 | default: jest.fn().mockImplementation(() => ({ 15 | models: { 16 | list: jest.fn() 17 | } 18 | })) 19 | }; 20 | }); 21 | 22 | describe('Settings Service', () => { 23 | beforeEach(() => { 24 | localStorage.clear(); 25 | jest.clearAllMocks(); 26 | }); 27 | 28 | describe('Settings Management', () => { 29 | const testSettings = { 30 | apiKey: 'test-key', 31 | defaultModel: 'test-model', 32 | enabledModels: ['model1', 'model2'] 33 | }; 34 | 35 | it('should save and load settings with encryption', () => { 36 | saveSettings(testSettings); 37 | const loaded = loadSettings(); 38 | 39 | expect(loaded?.defaultModel).toBe(testSettings.defaultModel); 40 | expect(loaded?.enabledModels).toEqual(testSettings.enabledModels); 41 | // API key should be decrypted correctly 42 | expect(loaded?.apiKey).toBe(testSettings.apiKey); 43 | }); 44 | 45 | it('should handle default API key from environment', () => { 46 | const settings = loadSettings(); 47 | expect(settings?.apiKey).toBe('test-api-key'); // Using value from test/setup.ts 48 | }); 49 | 50 | it('should clear settings correctly', () => { 51 | saveSettings(testSettings); 52 | const cleared = clearSettings(); 53 | expect(localStorage.getItem('symbolic-scribe-settings')).toBeNull(); 54 | expect(cleared?.apiKey).toBe('test-api-key'); // Using value from test/setup.ts 55 | }); 56 | }); 57 | 58 | describe('OpenRouter API Integration', () => { 59 | it('should fetch available models', async () => { 60 | const mockModels = { 61 | data: [{ 62 | id: 'model1', 63 | name: 'Test Model', 64 | description: 'Test Description', 65 | context_length: 4096, 66 | pricing: { 67 | prompt: '0.001', 68 | completion: '0.002' 69 | } 70 | }] 71 | }; 72 | 73 | const mockOpenAI = new OpenAI({}); 74 | (mockOpenAI.models.list as jest.Mock).mockResolvedValue(mockModels); 75 | (OpenAI as jest.MockedClass).mockImplementation(() => mockOpenAI); 76 | 77 | const models = await fetchAvailableModels('test-key'); 78 | 79 | expect(models).toHaveLength(1); 80 | expect(models[0]).toMatchObject({ 81 | id: 'model1', 82 | name: 'Test Model', 83 | description: 'Test Description' 84 | }); 85 | }); 86 | 87 | it('should validate API key', async () => { 88 | const mockOpenAI = new OpenAI({}); 89 | (mockOpenAI.models.list as jest.Mock).mockResolvedValue({ data: [] }); 90 | (OpenAI as jest.MockedClass).mockImplementation(() => mockOpenAI); 91 | 92 | const isValid = await testApiKey('test-key'); 93 | expect(isValid).toBe(true); 94 | }); 95 | 96 | it('should handle invalid API key', async () => { 97 | const mockOpenAI = new OpenAI({}); 98 | (mockOpenAI.models.list as jest.Mock).mockRejectedValue(new Error('Invalid API key')); 99 | (OpenAI as jest.MockedClass).mockImplementation(() => mockOpenAI); 100 | 101 | const isValid = await testApiKey('invalid-key'); 102 | expect(isValid).toBe(false); 103 | }); 104 | }); 105 | }); 106 | --------------------------------------------------------------------------------
An error occurred while rendering this component.
38 | {this.state.error?.message} 39 |