Power Abuse Analyzer - Source Code

This directory contains the source code for the Power Abuse Analyzer application.

Directory Structure

  • 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 analysis
    • chat-api.ts: API endpoint for chat sessions and pattern examples
    • static-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 utility
    • error-handler.ts: Error handling and response formatting

Main Components

Analyzer

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 abuse
  • handleQuestion: Handles questions about power abuse patterns
  • handlePatternFollowUp: Handles follow-up questions about specific patterns
  • processAIResponse: Processes the AI response into a structured format

Database

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 timestamps
  • Messages: Stores messages within sessions, with support for threaded conversations
  • Patterns: Stores identified abuse patterns with severity and confidence ratings
  • Examples: Stores examples of patterns, including user-provided examples

API

The API modules provide HTTP endpoints for interacting with the application.

Key endpoints:

  • power-abuse-analyzer: Analyzes text for subtle forms of abuse
  • chat-api: Manages chat sessions, messages, and pattern examples
  • static-file-server: Serves the frontend files

Utils

The utils modules provide utility functions for logging and error handling.

Key utilities:

  • logger: Provides logging functions with different log levels
  • error-handler: Provides error classes and response formatting