This directory contains the source code for the Power Abuse Analyzer application.
-
analyzer/: Core text analysis functionality
index.ts
: Main analyzer module with text analysis and pattern detection
-
api/: HTTP API endpoints
power-abuse-analyzer.ts
: API endpoint for text analysischat-api.ts
: API endpoint for chat sessions and pattern examplesstatic-file-server.ts
: Static file server for the frontend
-
database/: Database operations
index.ts
: SQLite database operations for sessions, messages, patterns, and examples
-
utils/: Utility functions
logger.ts
: Logging utilityerror-handler.ts
: Error handling and response formatting
The analyzer module provides the core functionality for identifying subtle forms of abuse in text. It uses OpenAI's GPT-4o model to analyze text and extract patterns of abuse, manipulation, and problematic language.
Key functions:
analyzeText
: Analyzes text for subtle forms of abusehandleQuestion
: Handles questions about power abuse patternshandlePatternFollowUp
: Handles follow-up questions about specific patternsprocessAIResponse
: Processes the AI response into a structured format
The database module provides functions for storing and retrieving data from SQLite. It uses recursive common table expressions (CTEs) to handle threaded conversations.
Key tables:
Sessions
: Stores chat sessions with titles and timestampsMessages
: Stores messages within sessions, with support for threaded conversationsPatterns
: Stores identified abuse patterns with severity and confidence ratingsExamples
: Stores examples of patterns, including user-provided examples
The API modules provide HTTP endpoints for interacting with the application.
Key endpoints:
power-abuse-analyzer
: Analyzes text for subtle forms of abusechat-api
: Manages chat sessions, messages, and pattern examplesstatic-file-server
: Serves the frontend files
The utils modules provide utility functions for logging and error handling.
Key utilities:
logger
: Provides logging functions with different log levelserror-handler
: Provides error classes and response formatting