Skip to content
Merged
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
3 changes: 0 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ jobs:
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY }}
CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY}}
NEXT_PUBLIC_CLERK_SIGN_OUT_FORCE_REDIRECT_URL: ${{ secrets.NEXT_PUBLIC_CLERK_SIGN_OUT_FORCE_REDIRECT_URL }}
UPLOADTHING_TOKEN: ${{ secrets.UPLOADTHING_TOKEN }}
NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL: ${{ secrets.NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL }}
NEXT_PUBLIC_CLERK_SIGN_IN_FORCE_REDIRECT_URL: ${{ secrets.NEXT_PUBLIC_CLERK_SIGN_IN_FORCE_REDIRECT_URL }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
POSTGRES_URL_NO_SSL: ${{ secrets.POSTGRES_URL_NO_SSL }}
PGUSER: ${{ secrets.PGUSER }}
Expand Down
1,598 changes: 766 additions & 832 deletions README.md

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions drizzle/0013_file_uploads.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Migration: Add file_uploads table for local file storage when UploadThing is disabled
-- This table stores uploaded files as base64-encoded text data in the database

CREATE TABLE IF NOT EXISTS "file_uploads" (
"id" SERIAL PRIMARY KEY,
"user_id" VARCHAR(256) NOT NULL,
"filename" VARCHAR(256) NOT NULL,
"mime_type" VARCHAR(128) NOT NULL,
"file_data" TEXT NOT NULL,
"file_size" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
);

-- Index for faster lookups by user
CREATE INDEX IF NOT EXISTS "file_uploads_user_id_idx" ON "file_uploads" ("user_id");

5 changes: 5 additions & 0 deletions drizzle/0014_company_upload_preference.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Migration: Add use_uploadthing column to company table
-- This allows per-company configuration of upload storage method

ALTER TABLE "company" ADD COLUMN IF NOT EXISTS "use_uploadthing" BOOLEAN NOT NULL DEFAULT true;

29 changes: 25 additions & 4 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ const config: NextConfig = {
env: {
TRANSFORMERS_BACKEND: "wasm",
USE_ONNX_NODE: "false",
ONNX_EXECUTION_PROVIDERS: "wasm",
},

// Webpack config to completely ignore onnxruntime-node
// eslint-disable-next-line @typescript-eslint/no-explicit-any
webpack: (webpackConfig: any, { isServer }: { isServer: boolean }) => {
if (isServer) {
// Mark onnxruntime-node as external - never bundle it
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
webpackConfig.externals = webpackConfig.externals ?? [];
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
webpackConfig.externals.push({
"onnxruntime-node": "commonjs onnxruntime-node",
});
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return webpackConfig;
},

images: {
Expand All @@ -22,11 +39,14 @@ const config: NextConfig = {
},

// Exclude unnecessary files from Vercel output (moved from experimental in Next.js 15)
// Apply to all routes using "/*" wildcard
outputFileTracingExcludes: {
"/api/inngest": [
// Exclude the massive onnxruntime-node package (404MB) - not needed for Inngest
"/*": [
// Exclude the massive onnxruntime-node package (404MB) - we use web/WASM backend only
"node_modules/.pnpm/onnxruntime-node@*/**",
// Exclude sharp native bindings - not needed for Inngest
"node_modules/onnxruntime-node/**",
"**/onnxruntime-node/**",
// Exclude sharp native bindings - use external package
"node_modules/.pnpm/@img+sharp-libvips-linuxmusl-x64@*/**",
"node_modules/.pnpm/@img+sharp-libvips-linux-x64@*/**",
// Exclude HuggingFace heavy files since we lazy load
Expand All @@ -35,8 +55,9 @@ const config: NextConfig = {
// Exclude pdfjs heavy files since we lazy load
"node_modules/.pnpm/pdfjs-dist@*/node_modules/pdfjs-dist/build/**/*.map",
"node_modules/.pnpm/pdfjs-dist@*/node_modules/pdfjs-dist/legacy/**",
// Exclude pdf-parse test data
// Exclude pdf-parse test data (8MB)
"node_modules/.pnpm/pdf-parse@*/node_modules/pdf-parse/test/**",
"node_modules/pdf-parse/test/**",
],
},

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@
"duck-duck-scrape": "^2.2.7",
"embla-carousel-react": "^8.6.0",
"formdata-node": "^6.0.3",
"framer-motion": "^12.29.2",
"geist": "^1.5.1",
"inngest": "^3.49.3",
"input-otp": "^1.4.2",
"katex": "^0.16.25",
"langchain": "^0.3.33",
"lucide-react": "^0.487.0",
"motion": "^12.29.2",
"next": "^15.5.7",
"next-themes": "^0.4.6",
"node-fetch": "^3.3.2",
Expand Down
335 changes: 233 additions & 102 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

33 changes: 6 additions & 27 deletions src/app/_components/ThemeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,16 @@

import React, { useEffect, useState } from 'react';
import { Moon, Sun } from 'lucide-react';

type Theme = 'light' | 'dark';
import { useTheme } from 'next-themes';

export function ThemeToggle() {
const [theme, setTheme] = useState<Theme>('dark');
const { theme, setTheme } = useTheme();
const [mounted, setMounted] = useState(false);

useEffect(() => {
setMounted(true);
const savedTheme = localStorage.getItem('theme') as Theme | null;
if (savedTheme) {
setTheme(savedTheme);
} else {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
setTheme(prefersDark ? 'dark' : 'light');
}
}, []);

useEffect(() => {
if (mounted) {
localStorage.setItem('theme', theme);
document.documentElement.setAttribute('data-theme', theme);
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}
}, [theme, mounted]);

const toggleTheme = () => {
setTheme(prev => prev === 'dark' ? 'light' : 'dark');
};

if (!mounted) {
return (
<button
Expand All @@ -48,6 +24,10 @@ export function ThemeToggle() {
);
}

const toggleTheme = () => {
setTheme(theme === 'dark' ? 'light' : 'dark');
};

return (
<button
onClick={toggleTheme}
Expand All @@ -62,4 +42,3 @@ export function ThemeToggle() {
</button>
);
}

6 changes: 6 additions & 0 deletions src/app/api/agents/documentQ&A/services/tavilySearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export async function performTavilySearch(
query: string,
maxResults = 5
): Promise<WebSearchResult[]> {
// Return empty results if Tavily API key is not configured
if (!env.server.TAVILY_API_KEY) {
console.warn('Tavily API key not configured. Web search disabled.');
return [];
}

try {
const response = await fetch('https://api.tavily.com/search', {
method: 'POST',
Expand Down
16 changes: 16 additions & 0 deletions src/app/api/config/uploadthing/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* UploadThing Configuration Check API
* Returns whether UploadThing is configured based on environment variable presence
*/

import { NextResponse } from "next/server";
import { env } from "~/env";

export async function GET() {
const isConfigured = Boolean(env.server.UPLOADTHING_TOKEN);

return NextResponse.json({
configured: isConfigured,
});
}

69 changes: 69 additions & 0 deletions src/app/api/files/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* File Serving API Route
* Retrieves and serves files stored in the database
*/

import { NextResponse } from "next/server";
import { eq } from "drizzle-orm";
import { db } from "~/server/db";
import { fileUploads } from "~/server/db/schema";

interface RouteParams {
params: Promise<{
id: string;
}>;
}

export async function GET(
request: Request,
{ params }: RouteParams
) {
try {
const { id } = await params;
const fileId = parseInt(id, 10);

if (isNaN(fileId)) {
return NextResponse.json(
{ error: "Invalid file ID" },
{ status: 400 }
);
}

// Fetch file from database
const [file] = await db
.select()
.from(fileUploads)
.where(eq(fileUploads.id, fileId));

if (!file) {
return NextResponse.json(
{ error: "File not found" },
{ status: 404 }
);
}

// Decode base64 data back to binary
const binaryData = Buffer.from(file.fileData, "base64");

// Return file with appropriate headers
return new NextResponse(binaryData, {
status: 200,
headers: {
"Content-Type": file.mimeType,
"Content-Length": binaryData.length.toString(),
"Content-Disposition": `inline; filename="${file.filename}"`,
"Cache-Control": "private, max-age=31536000", // Cache for 1 year (immutable content)
},
});
} catch (error) {
console.error("Error serving file:", error);
return NextResponse.json(
{
error: "Failed to serve file",
details: error instanceof Error ? error.message : "Unknown error",
},
{ status: 500 }
);
}
}

65 changes: 54 additions & 11 deletions src/app/api/inngest/route.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
/**
* Inngest API Route
* This endpoint serves the Inngest SDK and allows Inngest to trigger functions
*
* When Inngest is disabled (INNGEST_EVENT_KEY not set), this route returns 404
*/

import { serve } from "inngest/next";
import { inngest } from "~/server/inngest/client";
import { uploadDocument } from "~/server/inngest/functions/processDocument";

// Register all Inngest functions
export const { GET, POST, PUT } = serve({
client: inngest,
functions: [
uploadDocument,
],
});
import { NextResponse } from "next/server";
import { isInngestEnabled } from "~/lib/ocr/trigger";

// Disabled handler - returns 404 when Inngest is not enabled
const disabledHandler = () => {
return NextResponse.json(
{
error: "Inngest is disabled",
message: "Set INNGEST_EVENT_KEY environment variable to enable background processing"
},
{ status: 404 }
);
};

// Dynamic handler creation based on Inngest configuration
async function createHandlers() {
if (!isInngestEnabled()) {
return {
GET: disabledHandler,
POST: disabledHandler,
PUT: disabledHandler,
};
}

// Only import Inngest dependencies when enabled
const { serve } = await import("inngest/next");
const { inngest } = await import("~/server/inngest/client");
const { uploadDocument } = await import("~/server/inngest/functions/processDocument");

if (!inngest || !uploadDocument) {
console.error("[Inngest Route] Inngest client or functions not available despite INNGEST_EVENT_KEY being set");
return {
GET: disabledHandler,
POST: disabledHandler,
PUT: disabledHandler,
};
}

// Register all Inngest functions
return serve({
client: inngest,
functions: [uploadDocument],
});
}

// Create handlers at module load time
// Note: This uses top-level await which is supported in Next.js 13+
const handlers = await createHandlers();

export const GET = handlers.GET;
export const POST = handlers.POST;
export const PUT = handlers.PUT;
27 changes: 20 additions & 7 deletions src/app/api/updateCompany/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function POST(request: Request) {
if (!validation.success) {
return validation.response;
}
const { name, employerPasskey, employeePasskey, numberOfEmployees } = validation.data;
const { name, employerPasskey, employeePasskey, numberOfEmployees, useUploadThing } = validation.data;

const [userRecord] = await db
.select({
Expand Down Expand Up @@ -57,14 +57,27 @@ export async function POST(request: Request) {
);
}

const updateData: Partial<{
name: string;
employerpasskey: string;
employeepasskey: string;
numberOfEmployees: string;
useUploadThing: boolean;
}> = {
name,
employerpasskey: employerPasskey,
employeepasskey: employeePasskey,
numberOfEmployees,
};

// Only include useUploadThing if it was explicitly provided
if (useUploadThing !== undefined) {
updateData.useUploadThing = useUploadThing;
}

const updateResult = await db
.update(company)
.set({
name,
employerpasskey: employerPasskey,
employeepasskey: employeePasskey,
numberOfEmployees,
})
.set(updateData)
.where(eq(company.id, Number(userRecord.companyId)))
.returning({ id: company.id });

Expand Down
Loading
Loading