Introduction & Core Concepts
Relevant source files
The following files were used as context for generating this wiki page:
ThinkEx is an open-source visual thinking environment designed to bridge the gap between AI reasoning and fragmented personal information. Unlike traditional chat-based AI interfaces where context resets every session, ThinkEx provides a persistent spatial canvas where notes, PDFs, YouTube videos, and AI conversations compound into lasting knowledge. The platform focuses on user-controlled context, allowing developers and researchers to manually select specific cards or document sections for AI analysis, ensuring transparency in what the AI "sees."
Sources: README.md:14-34, README.md:43-52
The system architecture is built on a modern web stack including Next.js, PostgreSQL with Drizzle ORM, and Tailwind CSS. It leverages a multi-model approach, allowing users to switch AI providers per task. Core concepts revolve around "Workspaces," which serve as organized containers for "Items" (documents, quizzes, flashcards, etc.) that the AI can interact with using specialized tools like web search, OCR extraction, and automated content generation.
Sources: README.md:61-70, src/lib/utils/format-workspace-context.ts:102-130
Workspace Context & AI Reasoning
The core of ThinkEx's AI interaction is the management of workspace context. The system formats workspace metadata and item content into structured XML-like blocks (<workspace>, <context>, <system>) to guide the AI assistant. This context allows the AI to reference items by path or name rather than internal IDs, creating a more human-readable interaction model.
Sources: src/lib/utils/format-workspace-context.ts:58-95, src/lib/utils/format-workspace-context.ts:119-125
Context Prioritization Logic
The AI is instructed to prioritize items marked as (currently viewing), as these represent the user's immediate focus. For PDFs, the specific activePage is provided to the model to ground its reasoning in the visible section of the document.
Sources: src/lib/utils/format-workspace-context.ts:11-54, src/lib/utils/format-workspace-context.ts:112-118
The diagram above illustrates how the system aggregates item states (selected vs. viewed) into the final context used by the AI engine. Sources: src/lib/utils/format-workspace-context.ts:58-95
Automated Workspace Generation (Autogen)
ThinkEx features an advanced "Autogen" system that creates fully populated workspaces from a single user prompt. This process involves a multi-phase distillation pipeline that executes web searches, fetches link content, and processes uploaded files (like PDFs) in parallel to synthesize new documents, quizzes, and YouTube references.
Sources: src/app/api/workspaces/autogen/route.ts:115-180, src/app/generate/page.tsx:55-150
The Autogen Pipeline Phases
- Search Phase: Determines if current events or niche facts require external web grounding via Google Search.
- Distillation Phase: Uses a "flash-lite" model to extract metadata (title, icon, color) and a core content summary.
- Generation Phase: Produces structured markdown documents and quiz questions based on the distilled summary.
- Bulk Creation: Finalizes the workspace by inserting items into the database and starting asynchronous OCR for media.
Sources: src/app/api/workspaces/autogen/route.ts:145-212, src/app/api/workspaces/autogen/route.ts:405-470
| Phase | Responsibility | Model/Tool Used |
|---|---|---|
| Search | Identifying search needs & executing queries | gemini-2.5-flash-lite + webSearch |
| Distillation | Generating metadata & content summary | gemini-2.5-flash-lite |
| Content Gen | Creating docs and quizzes | gemini-2.5-flash |
| OCR | Extracting text from PDFs/Images | ocrDispatchWorkflow |
Sources: src/app/api/workspaces/autogen/route.ts:117-140, src/app/api/workspaces/autogen/route.ts:407-425
Media Handling & OCR
ThinkEx treats media—specifically PDFs, YouTube videos, and images—as first-class citizens. When a PDF or image is added to a workspace, the system triggers an OCR (Optical Character Recognition) workflow. The extracted text is formatted as markdown, preserving structure like headers, footers, and tables.
Sources: src/lib/utils/format-workspace-context.ts:316-335, src/app/api/workspaces/autogen/route.ts:255-320
PDF Processing Flow
This sequence shows the asynchronous nature of media processing where the item is created immediately, but content becomes available once OCR finishes. Sources: src/app/api/workspaces/autogen/route.ts:284-330
User Interface & Interaction
The interface utilizes a spatial canvas for arranging cards. Users interact with the AI through a persistent input that supports file attachments and link detection. Responses from the AI include specialized rendering for citations, math (LaTeX), and diagrams (Mermaid).
Sources: src/components/assistant-ui/markdown-text.tsx:185-210, src/lib/utils/format-workspace-context.ts:145-185
Formatting Standards
- Math: Single
$for inline, double$$for blocks. Currency must be escaped as\$to avoid math parsing errors. - Citations: Rendered as interactive badges (
<citation>). Clicking a citation navigates the user to the source item and highlights relevant text. - Diagrams: AI outputs standard Mermaid code blocks which are rendered dynamically in the chat UI.
Sources: src/lib/utils/format-workspace-context.ts:187-220, src/components/assistant-ui/markdown-text.tsx:88-120
Conclusion
ThinkEx is built around the philosophy that knowledge compounds when context is visible and organized. By combining automated content generation with granular user control over what information the AI processes, it creates a "visual desk" environment. The system's robustness is grounded in its multi-phase processing of inputs—from web searches to deep OCR—ensuring the AI assistant has high-fidelity data to support the user's thinking process.
Sources: README.md:23-40, src/lib/utils/format-workspace-context.ts:102-110