How albertocubeddu/extensionos works
Project Type and Purpose
• Extension | OS is a full-stack browser extension (Chrome MV3 via Plasmo) that embeds AI functionality into the user’s browsing context.
• It comprises a background service worker, injected UI (popup, side panel, context menu), and options/config pages.
• Purpose: let users select text → invoke an LLM (OpenAI, VAPI, Ollama, etc.) → display results inline without leaving the page.
Key Architectural Components
a. Browser Extension Host (Chrome MV3)
• Background Service Worker (background/index.ts, init.ts)
• Content/Injection Layer (plasmo automatically injects popup.tsx, sidepanel.tsx)
• Context Menus & Messaging (background/messages/*.ts)
• Storage (Plasmo Storage/localStorage for API keys & settings)
b. UI Components
• Popup UI (popup.tsx)
• Side Panel (sidepanel.tsx)
• Options Page & Sub-pages (options/*.tsx)
• Reusable React UI library (components/ui and components/blocks)
c. Business Logic & Utilities
• LLM Call Handlers (lib/openAITypeCall.ts, lib/vapiOutbound.ts)
• Configuration & Providers (lib/configurations, lib/providers)
• Helpers: anonymousTracking, clientUUID, context menu cleanup, XY calculations
d. External Services
• OpenAI, Claude, Together.ai, Groq, VAPI (HTTP/S requests from background worker)
• Local Ollama server (localhost:11434)
• Google identity (optional OAuth via chrome.identity)
Component Relationships & Data Flow
• User selects text on page → right-click → context menu item → event hits Background Worker
└─> Background Worker sends message (e.g., callOpenAIReturn) to content script/UI
• Background Worker reads settings from Storage → invokes LLM call via lib/openAITypeCall or lib/vapiOutbound
└─> HTTP request to chosen LLM endpoint (external cloud or local Ollama).
└─> On response, Worker posts result back to UI via sendToSidepanel or copyTextToClipboard.
• UI (Popup/Side Panel) listens for messages → renders result in React components.
• Options Page lets user configure providers, prompts, keys → writes into Storage → consumed by Worker & UI.
Architectural Patterns & Principles
• MV3 Service Worker pattern: short-lived background script handling all extension logic.
• Message‐based decoupling: clear chrome.runtime.sendMessage channel for cross‐component comms.
• Modular UI in React/TSX via Plasmo framework: separation of concerns between UI, logic, and storage.
• Provider abstraction: new LLMs/providers can be plugged in via lib/providers and options/promptFactory.
• Local‐first storage & privacy: user keys in localStorage, no server component.