Skip to content

Latest commit

 

History

History
181 lines (127 loc) · 7.3 KB

File metadata and controls

181 lines (127 loc) · 7.3 KB

CogniFlow: AI Platform Integrator & Data Extractor Browser Library

CogniFlow is an advanced JavaScript library designed for seamless integration with major AI platforms. It enables programmatic interaction and real-time data extraction from AI interfaces through iframe embedding, query parameter injection, and postMessage communication. Automate and enhance your web-based AI interactions across platforms like ChatGPT, Claude, Gemini, Perplexity AI, Grok AI, Copilot, and Meta AI.


🚀 Project Overview

This library acts as a bridge, allowing web applications to deeply integrate with various AI services. It overcomes common cross-origin restrictions by leveraging iframe communication and manipulates external AI interfaces to extract responses and inject custom parameters, enabling powerful automation workflows.

🏛️ Architecture

mermaid graph TD A[Web Application] --> B(CogniFlow Library) B -- Manages Iframe Embeds --> C{AI Platform Iframe} B -- Injects Params/Queries --> C C -- AI Response --> D[MutationObserver/Scraping] D -- Parsed Data --> B B -- PostMessage Communication --> A B -- API Calls (Optional) --> E[External Services]

📄 Table of Contents


🤖 AI Agent Directives

Click to Expand AI Agent Directives

1. Identity & Prime Directive

Role: Apex Technical Authority & Elite Architect. Context: December 2025. Building for 2026 standards. Output Standard: EXECUTION-ONLY. Philosophy: "Zero-Defect, High-Velocity, Future-Proof."

2. Input Processing & Cognition

  • Semantic Correction: Infer technical intent from user inputs; do not execute literal typos. Reference the README.md as SSOT.
  • Mandatory MCP Instrumentation: Use linkup/brave for December 2025 standards/threats/trends. Use docfork to verify APIs. Use clear-thought-two for complex flows.

3. Context-Aware Apex Tech Stacks (Late 2025 Standards)

  • PRIMARY SCENARIO: WEB / APP / EXTENSION (TypeScript/JavaScript)
    • Stack: This project uses JavaScript (ESNext), heavily leveraging TypeScript 6.x (Strict) for development. Vite 7 (Rolldown) is used as the build tool. WXT (Web Extension Toolkit) is the standard for building browser extensions if this library were to be packaged as one. Biome is the unified tool for linting and formatting. Vitest for unit tests and Playwright for end-to-end testing.
    • Architecture: Adheres to Feature-Sliced Design (FSD) for modularity and maintainability.
    • State Management: Utilizes Signals (Standardized) for reactive state management.
    • Testing: Vitest for unit/integration tests, Playwright for E2E tests.

4. Apex Naming Convention (The "Star Velocity" Engine)

  • Formula: <Product-Name>-<Primary-Function>-<Platform>-<Type>
  • Format: Title-Case-With-Hyphens

5. The README Replication Protocol (The Ultimate Artifact)

  • Sections: Visual Authority, Structural Clarity, AI Agent Directives, Development Standards.
  • Badges: flat-square, shields.io, User chirag127, dynamic repo URL.

6. Chain of Thought (CoT) Protocol

  • Process: Audit -> Pivot/Archive -> Naming -> AI Directives -> File Generation -> Polish.

7. Dynamic URL & Badge Protocol

  • Base URL: https://github.com/chirag127/CogniFlow-AI-Platform-Integrator-And-Data-Extractor-Browser-Library
  • Consistency: Use the New Repo Name exclusively.

🛠️ Core Features

  • Seamless Iframe Integration: Embeds AI platform interfaces directly within your web applications.
  • Intelligent Query Injection: Programmatically injects search queries and parameters into AI interfaces.
  • PostMessage Communication: Facilitates secure data exchange between your application and the AI interface.
  • Real-time Response Scraping: Utilizes MutationObserver to detect and extract AI responses as they are generated.
  • Multi-Platform Support: Designed to work with a wide range of popular AI platforms (ChatGPT, Claude, Gemini, Perplexity AI, Grok AI, Copilot, Meta AI, etc.).
  • Robust Error Handling: Manages network issues, platform changes, and unexpected responses gracefully.
  • TypeScript First: Developed with TypeScript for enhanced code quality, maintainability, and developer experience.

⚙️ Installation & Setup

This library is intended to be used within a larger web application or browser extension project. Ensure you have a modern JavaScript/TypeScript development environment set up (e.g., using Vite, Webpack, or a similar bundler).

1. Project Setup (Example using Vite + TypeScript)

bash

1. Clone the repository (if developing locally)

cd CogniFlow-AI-Platform-Integrator-And-Data-Extractor-Browser-Library

2. Install dependencies

npm install

OR

yarn install

OR

pnpm install

2. Install as a dependency (from npm, once published)

bash npm install @chirag127/cogniflow

OR

yarn add @chirag127/cogniflow

OR

pnpm add @chirag127/cogniflow


💡 Usage Examples

Example 1: Basic Integration and Response Extraction

typescript import { CogniFlow } from '@chirag127/cogniflow';

const cogniFlow = new CogniFlow({ platformUrl: 'https://chat.openai.com/', // Example for ChatGPT apiKey: 'YOUR_API_KEY_IF_NEEDED_FOR_IFRAME_INIT', targetElementId: 'ai-chat-container' // DOM element to attach the iframe });

cogniFlow.onResponse(data => { console.log('AI Response:', data); // Process the extracted AI response });

async function sendMessage() { await cogniFlow.sendMessage('Hello, CogniFlow! What is the current weather?'); console.log('Message sent and response listener active.'); }

// Initialize and send message after DOM is ready cogniFlow.init().then(sendMessage).catch(error => { console.error('CogniFlow initialization failed:', error); });

Example 2: Injecting Parameters

typescript // Assume 'cogniFlow' is an initialized instance

const advancedParams = { temperature: 0.7, max_tokens: 150 };

async function sendAdvancedQuery() { await cogniFlow.sendMessage('Summarize the following text:', { injectionParams: { prompt_params: JSON.stringify(advancedParams) // Example: Injecting parameters } }); }

// Call sendAdvancedQuery() after initialization


🤝 Contributing

Contributions are welcome! Please read our CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.


📄 License

This project is licensed under the CC BY-NC 4.0 License - see the LICENSE file for details.