Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,42 @@ function HomePage() {
let pdfFileName: string | undefined;
let pdfProviderId: string | undefined;
let pdfProviderConfig: { apiKey?: string; baseUrl?: string } | undefined;
let directText = '';

if (form.pdfFile) {
pdfStorageKey = await storePdfBlob(form.pdfFile);
pdfFileName = form.pdfFile.name;

const settings = useSettingsStore.getState();
pdfProviderId = settings.pdfProviderId;
const providerCfg = settings.pdfProvidersConfig?.[settings.pdfProviderId];
if (providerCfg) {
pdfProviderConfig = {
apiKey: providerCfg.apiKey,
baseUrl: providerCfg.baseUrl,
};
const ext = form.pdfFile.name.split('.').pop()?.toLowerCase() ?? '';
const isTextFile = ['md', 'txt', 'markdown'].includes(ext);

if (isTextFile) {
// Text-based files: read content directly, skip OCR pipeline
directText = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.onerror = () => reject(new Error('Failed to read file'));
reader.readAsText(form.pdfFile!);
});
pdfFileName = form.pdfFile.name;
} else {
// PDF files: store blob for later OCR parsing
pdfStorageKey = await storePdfBlob(form.pdfFile);
pdfFileName = form.pdfFile.name;

const settings = useSettingsStore.getState();
pdfProviderId = settings.pdfProviderId;
const providerCfg = settings.pdfProvidersConfig?.[settings.pdfProviderId];
if (providerCfg) {
pdfProviderConfig = {
apiKey: providerCfg.apiKey,
baseUrl: providerCfg.baseUrl,
};
}
}
}

const sessionState = {
sessionId: nanoid(),
requirements,
pdfText: '',
pdfText: directText,
pdfImages: [],
imageStorageIds: [],
pdfStorageKey,
Expand Down
16 changes: 13 additions & 3 deletions components/generation/generation-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ import { MediaPopover } from '@/components/generation/media-popover';
// ─── Constants ───────────────────────────────────────────────
const MAX_PDF_SIZE_MB = 50;
const MAX_PDF_SIZE_BYTES = MAX_PDF_SIZE_MB * 1024 * 1024;
const ACCEPTED_EXTENSIONS = '.pdf,.md,.txt,.markdown';

/** Check whether a File is one of our supported document types */
function isSupportedFile(file: File): boolean {
const ext = file.name.split('.').pop()?.toLowerCase() ?? '';
if (['md', 'txt', 'markdown'].includes(ext)) return true;
if (ext === 'pdf' || file.type === 'application/pdf') return true;
if (file.type.startsWith('text/')) return true;
return false;
}

// ─── Types ───────────────────────────────────────────────────
export interface GenerationToolbarProps {
Expand Down Expand Up @@ -98,7 +108,7 @@ export function GenerationToolbar({

// PDF handler
const handleFileSelect = (file: File) => {
if (file.type !== 'application/pdf') return;
if (!isSupportedFile(file)) return;
if (file.size > MAX_PDF_SIZE_BYTES) {
onPdfError(t('upload.fileTooLarge'));
return;
Expand Down Expand Up @@ -212,7 +222,7 @@ export function GenerationToolbar({
type="file"
ref={fileInputRef}
className="hidden"
accept=".pdf"
accept={ACCEPTED_EXTENSIONS}
onChange={(e) => {
const f = e.target.files?.[0];
if (f) handleFileSelect(f);
Expand Down Expand Up @@ -261,7 +271,7 @@ export function GenerationToolbar({
}}
>
<Paperclip className="size-5 text-muted-foreground/50 mb-1.5" />
<p className="text-xs font-medium">{t('toolbar.pdfUpload')}</p>
<p className="text-xs font-medium">{t('toolbar.docUpload')}</p>
<p className="text-[10px] text-muted-foreground/60 mt-0.5">
{t('upload.pdfSizeLimit')}
</p>
Expand Down
32 changes: 30 additions & 2 deletions components/whiteboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use client';

import { useRef } from 'react';
import { useRef, useState } from 'react';
import { motion, AnimatePresence } from 'motion/react';
import { Eraser, Minimize2, PencilLine } from 'lucide-react';
import { Eraser, History, Minimize2, PencilLine } from 'lucide-react';
import { WhiteboardCanvas } from './whiteboard-canvas';
import { WhiteboardHistory } from './whiteboard-history';
import { useStageStore } from '@/lib/store';
import { useCanvasStore } from '@/lib/store/canvas';
import { useWhiteboardHistoryStore } from '@/lib/store/whiteboard-history';
import { createStageAPI } from '@/lib/api/stage-api';
import { toast } from 'sonner';
import { useI18n } from '@/lib/hooks/use-i18n';
Expand All @@ -23,6 +25,8 @@ export function Whiteboard({ isOpen, onClose }: WhiteboardProps) {
const stage = useStageStore.use.stage();
const isClearing = useCanvasStore.use.whiteboardClearing();
const clearingRef = useRef(false);
const [historyOpen, setHistoryOpen] = useState(false);
const snapshotCount = useWhiteboardHistoryStore((s) => s.snapshots.length);

// Get element count for indicator
const whiteboard = stage?.whiteboard?.[0];
Expand All @@ -34,6 +38,13 @@ export function Whiteboard({ isOpen, onClose }: WhiteboardProps) {
if (!whiteboard || elementCount === 0 || clearingRef.current) return;
clearingRef.current = true;

// Save snapshot before clearing
if (whiteboard.elements && whiteboard.elements.length > 0) {
useWhiteboardHistoryStore
.getState()
.pushSnapshot(whiteboard.elements, t('whiteboard.beforeClear'));
}

// Trigger cascade exit animation
useCanvasStore.getState().setWhiteboardClearing(true);

Expand Down Expand Up @@ -108,6 +119,20 @@ export function Whiteboard({ isOpen, onClose }: WhiteboardProps) {
<Eraser className="w-4 h-4" />
</motion.div>
</motion.button>
<motion.button
type="button"
onClick={() => setHistoryOpen(!historyOpen)}
whileTap={{ scale: 0.9 }}
className="relative p-2 text-gray-400 dark:text-gray-500 hover:text-purple-500 dark:hover:text-purple-400 hover:bg-purple-50 dark:hover:bg-purple-900/20 rounded-lg transition-colors"
title={t('whiteboard.history')}
>
<History className="w-4 h-4" />
{snapshotCount > 0 && (
<span className="absolute -top-0.5 -right-0.5 min-w-[16px] h-4 px-1 rounded-full bg-purple-500 text-white text-[10px] font-bold flex items-center justify-center">
{snapshotCount}
</span>
)}
</motion.button>
<div className="w-px h-4 bg-gray-200 dark:bg-gray-700 mx-1" />
<button
type="button"
Expand All @@ -124,6 +149,9 @@ export function Whiteboard({ isOpen, onClose }: WhiteboardProps) {
<div className="flex-1 relative bg-[radial-gradient(#e5e7eb_1px,transparent_1px)] dark:bg-[radial-gradient(#374151_1px,transparent_1px)] [background-size:24px_24px] overflow-hidden">
<WhiteboardCanvas />

{/* History panel */}
<WhiteboardHistory isOpen={historyOpen} onClose={() => setHistoryOpen(false)} />

{/* Test panel */}
{/* <WhiteboardTestPanel /> */}
</div>
Expand Down
Loading
Loading