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
23 changes: 23 additions & 0 deletions src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ async function handlePOST(req: Request) {
// Prepare provider options
// The Gateway passes these through to the specific provider
const isClaudeModel = modelId.includes("claude");
const vertexProject = process.env.GOOGLE_VERTEX_PROJECT;
const vertexLocation = process.env.GOOGLE_VERTEX_LOCATION || "us-central1";
const vertexClientEmail = process.env.GOOGLE_CLIENT_EMAIL;
const vertexPrivateKey = process.env.GOOGLE_PRIVATE_KEY?.replace(/\\n/g, "\n");
const hasVertexByok =
vertexProject && vertexClientEmail && vertexPrivateKey;

let providerOptions: any = {
gateway: {
// Route Claude models through Vertex AI only
Expand All @@ -302,6 +309,22 @@ async function handlePOST(req: Request) {
models: ["google/gemini-2.5-flash"],
// Track usage per end-user for analytics
...(userId ? { user: userId } : {}),
// BYOK for Vertex: use GCP credentials so Claude (Haiku, etc.) bypasses Vercel balance
...(isClaudeModel &&
hasVertexByok && {
byok: {
vertex: [
{
project: vertexProject!,
location: vertexLocation,
googleCredentials: {
clientEmail: vertexClientEmail!,
privateKey: vertexPrivateKey!,
},
},
],
},
}),
// Fail fast if provider doesn't start streaming within 30s (BYOK only)
providerTimeouts: {
byok: {
Expand Down
17 changes: 15 additions & 2 deletions src/app/api/upload-file/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { NextRequest, NextResponse } from 'next/server';
import { writeFile, mkdir } from 'fs/promises';
import { join } from 'path';
import { existsSync } from 'fs';
import {
isOfficeDocument,
getOfficeDocumentConvertUrl,
} from "@/lib/uploads/office-document-validation";
Comment on lines +8 to +11
Comment on lines +8 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Unused import: isOfficeDocument.

The isOfficeDocument function is imported but not used in this file. Only getOfficeDocumentConvertUrl is used for the validation check.

🧹 Proposed fix to remove unused import
 import {
-  isOfficeDocument,
   getOfficeDocumentConvertUrl,
 } from "@/lib/uploads/office-document-validation";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import {
isOfficeDocument,
getOfficeDocumentConvertUrl,
} from "@/lib/uploads/office-document-validation";
import {
getOfficeDocumentConvertUrl,
} from "@/lib/uploads/office-document-validation";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/api/upload-file/route.ts` around lines 8 - 11, Remove the unused
import isOfficeDocument from the import statement that currently brings in both
isOfficeDocument and getOfficeDocumentConvertUrl; update the import to only
import getOfficeDocumentConvertUrl (so only getOfficeDocumentConvertUrl is
referenced in route.ts) to eliminate the unused symbol.


export const maxDuration = 30;

Expand Down Expand Up @@ -61,8 +65,17 @@ export async function POST(request: NextRequest) {
);
}

// Accept all file types (removed image-only restriction)
// File type validation can be done client-side if needed
// Reject Office documents — convert to PDF at ilovepdf.com
const convertUrl = getOfficeDocumentConvertUrl(file);
if (convertUrl) {
return NextResponse.json(
{
error: "Word, Excel, and PowerPoint files are not supported. Convert to PDF first.",
convertUrl,
},
{ status: 400 }
);
}

// Validate file size (50MB limit)
const maxSize = 50 * 1024 * 1024; // 50MB
Expand Down
15 changes: 14 additions & 1 deletion src/app/api/upload-url/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { auth } from "@/lib/auth";
import { createClient } from '@supabase/supabase-js';
import { NextRequest, NextResponse } from 'next/server';
import { withApiLogging } from "@/lib/with-api-logging";
import { getOfficeDocumentConvertUrlFromMeta } from "@/lib/uploads/office-document-validation";

export const maxDuration = 10;

Expand All @@ -28,7 +29,7 @@ async function handlePOST(request: NextRequest) {
}

const body = await request.json();
const { filename, contentType } = body;
const { filename, contentType = "" } = body;

if (!filename || typeof filename !== 'string') {
return NextResponse.json(
Expand All @@ -37,6 +38,18 @@ async function handlePOST(request: NextRequest) {
);
}

// Reject Office documents — convert to PDF at ilovepdf.com
const convertUrl = getOfficeDocumentConvertUrlFromMeta(filename, contentType);
if (convertUrl) {
return NextResponse.json(
{
error: "Word, Excel, and PowerPoint files are not supported. Convert to PDF first.",
convertUrl,
},
{ status: 400 }
);
}

const storageType = process.env.STORAGE_TYPE || 'supabase';

if (storageType === 'local') {
Expand Down
39 changes: 39 additions & 0 deletions src/app/api/workspaces/[id]/events/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
import { NextRequest, NextResponse } from "next/server";
import type { WorkspaceEvent, EventResponse } from "@/lib/workspace/events";
import { checkAndCreateSnapshot } from "@/lib/workspace/snapshot-manager";

/** Strip ocrPages/textContent from PDF items — client doesn't need them for display. */
function stripPdfOcrFromItem(item: { type?: string; data?: unknown }): void {
if (item?.type === "pdf" && item.data && typeof item.data === "object") {
const d = item.data as Record<string, unknown>;
delete d.ocrPages;
delete d.textContent;
}
}

function stripPdfOcrFromState(state: { items?: Array<{ type?: string; data?: unknown }> } | undefined): void {
state?.items?.forEach(stripPdfOcrFromItem);
}

function stripPdfOcrFromEventPayload(event: WorkspaceEvent): void {
const p = event.payload as Record<string, unknown>;
if (event.type === "ITEM_CREATED" && p?.item) stripPdfOcrFromItem(p.item as { type?: string; data?: unknown });
if (event.type === "ITEM_UPDATED") {
const changes = p?.changes as Record<string, unknown> | undefined;
if (changes?.data && typeof changes.data === "object") {
const d = changes.data as Record<string, unknown>;
delete d.ocrPages;
delete d.textContent;
}
}
if (event.type === "BULK_ITEMS_UPDATED") {
(p?.addedItems as Array<{ type?: string; data?: unknown }> | undefined)?.forEach(stripPdfOcrFromItem);
(p?.items as Array<{ type?: string; data?: unknown }> | undefined)?.forEach(stripPdfOcrFromItem);
}
if (event.type === "WORKSPACE_SNAPSHOT" && p?.items) {
(p.items as Array<{ type?: string; data?: unknown }>).forEach(stripPdfOcrFromItem);
}
}

import { loadWorkspaceState } from "@/lib/workspace/state-loader";
import { hasDuplicateName } from "@/lib/workspace/unique-name";
import { db, workspaceEvents } from "@/lib/db/client";
Expand Down Expand Up @@ -177,6 +211,10 @@ async function handleGET(
? Math.max(...eventsData.map(e => e.version))
: (snapshotVersion || 0);

// Strip ocrPages/textContent from PDF items — client doesn't need them for display
if (latestSnapshot?.state) stripPdfOcrFromState(latestSnapshot.state as { items?: Array<{ type?: string; data?: unknown }> });
events.forEach(stripPdfOcrFromEventPayload);

const response: EventResponse = {
events,
version: maxVersion,
Expand Down Expand Up @@ -324,6 +362,7 @@ async function handlePOST(
userName: e.userName || undefined,
id: e.eventId,
} as WorkspaceEvent));
events.forEach(stripPdfOcrFromEventPayload);

const totalTime = Date.now() - startTime;
timings.total = totalTime;
Expand Down
34 changes: 18 additions & 16 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { DashboardLayout } from "@/components/layout/DashboardLayout";
import { SplitViewLayout } from "@/components/layout/SplitViewLayout";
import { ItemPanelContent } from "@/components/workspace-canvas/ItemPanelContent";
import WorkspaceHeader from "@/components/workspace-canvas/WorkspaceHeader";
import { WorkspaceSearchDialog } from "@/components/workspace-canvas/WorkspaceSearchDialog";
import { SidebarProvider, useSidebar } from "@/components/ui/sidebar";
import { MobileWarning } from "@/components/ui/MobileWarning";
import { AnonymousSessionHandler, SidebarCoordinator } from "@/components/layout/SessionHandler";
Expand Down Expand Up @@ -216,13 +217,11 @@ function DashboardContent({
const isDesktop = useMediaQuery("(min-width: 768px)");
const showJsonView = useUIStore((state) => state.showJsonView);
const isChatExpanded = useUIStore((state) => state.isChatExpanded);
const searchQuery = useUIStore((state) => state.searchQuery);
const isChatMaximized = useUIStore((state) => state.isChatMaximized);
const workspacePanelSize = useUIStore((state) => state.workspacePanelSize);
const showCreateWorkspaceModal = useUIStore((state) => state.showCreateWorkspaceModal);
const setShowJsonView = useUIStore((state) => state.setShowJsonView);
const setIsChatExpanded = useUIStore((state) => state.setIsChatExpanded);
const setSearchQuery = useUIStore((state) => state.setSearchQuery);
const setIsChatMaximized = useUIStore((state) => state.setIsChatMaximized);
const setOpenModalItemId = useUIStore((state) => state.setOpenModalItemId);
const setShowCreateWorkspaceModal = useUIStore((state) => state.setShowCreateWorkspaceModal);
Expand Down Expand Up @@ -265,14 +264,19 @@ function DashboardContent({
isDesktop,
});

// Search dialog state for Cmd+K command palette
const [searchDialogOpen, setSearchDialogOpen] = useState(false);

// Keyboard shortcuts
useKeyboardShortcuts(
toggleChatExpanded,
{
onToggleSidebar: toggleSidebar,
onToggleChatMaximize: toggleChatMaximized,
onFocusSearch: () => {
titleInputRef.current?.focus();
if (currentWorkspaceId && !isLoadingWorkspace) {
setSearchDialogOpen(true);
}
},
}
);
Expand Down Expand Up @@ -455,8 +459,7 @@ function DashboardContent({
currentSlug={currentSlug}
state={state}
showJsonView={showJsonView}
searchQuery={searchQuery}
onSearchChange={setSearchQuery}
onOpenSearch={() => setSearchDialogOpen(true)}
isSaving={isSaving}
lastSavedAt={lastSavedAt}
hasUnsavedChanges={hasUnsavedChanges}
Expand Down Expand Up @@ -494,7 +497,7 @@ function DashboardContent({
onFlushPendingChanges={operations.flushPendingChanges}
/>
);
}, [viewMode, state.items, loadingCurrentWorkspace, isLoadingWorkspace, currentWorkspaceId, currentSlug, state, showJsonView, searchQuery, isSaving, lastSavedAt, hasUnsavedChanges, isChatMaximized, isDesktop, isChatExpanded, currentWorkspaceTitle, currentWorkspaceIcon, currentWorkspaceColor, operations, manualSave, setSearchQuery, setIsChatExpanded, setOpenModalItemId, handleShowHistory, titleInputRef, scrollAreaRef, getStatePreviewJSON]);
}, [viewMode, state.items, loadingCurrentWorkspace, isLoadingWorkspace, currentWorkspaceId, currentSlug, state, showJsonView, isSaving, lastSavedAt, hasUnsavedChanges, isChatMaximized, isDesktop, isChatExpanded, currentWorkspaceTitle, currentWorkspaceIcon, currentWorkspaceColor, operations, manualSave, setSearchDialogOpen, setIsChatExpanded, setOpenModalItemId, handleShowHistory, titleInputRef, scrollAreaRef, getStatePreviewJSON]);

// Build the single panel content (for workspace+panel mode)
const panelContent = useMemo(() => {
Expand Down Expand Up @@ -553,8 +556,7 @@ function DashboardContent({
!showJsonView && !isChatMaximized && currentWorkspaceId && !isLoadingWorkspace ? (
<WorkspaceHeader
titleInputRef={titleInputRef as React.RefObject<HTMLInputElement>}
searchQuery={searchQuery}
onSearchChange={setSearchQuery}
onOpenSearch={() => setSearchDialogOpen(true)}
currentWorkspaceId={currentWorkspaceId}
isSaving={isSaving}
lastSavedAt={lastSavedAt}
Expand Down Expand Up @@ -626,8 +628,7 @@ function DashboardContent({
currentSlug={currentSlug}
state={state}
showJsonView={showJsonView}
searchQuery={searchQuery}
onSearchChange={setSearchQuery}
onOpenSearch={() => setSearchDialogOpen(true)}
isSaving={isSaving}
lastSavedAt={lastSavedAt}
hasUnsavedChanges={hasUnsavedChanges}
Expand Down Expand Up @@ -695,6 +696,13 @@ function DashboardContent({
onRevertToVersion={revertToVersion}
items={currentWorkspace?.state?.items || []}
/>
<WorkspaceSearchDialog
open={searchDialogOpen}
onOpenChange={setSearchDialogOpen}
items={state.items ?? []}
currentWorkspaceId={currentWorkspaceId}
isLoadingWorkspace={isLoadingWorkspace}
/>
</PdfEngineWrapper>
);
}
Expand Down Expand Up @@ -745,12 +753,6 @@ function DashboardView() {
lastTrackedWorkspaceIdRef.current = currentWorkspaceId;
}, [currentWorkspaceId, markWorkspaceOpened]);

// Reset search query when workspace changes
const setSearchQuery = useUIStore((state) => state.setSearchQuery);
useEffect(() => {
setSearchQuery('');
}, [currentWorkspaceId, setSearchQuery]);

// Sync active folder with URL query param (?folder=<id>)
// Reset folder/panels when workspace changes
// and enables browser-native back/forward for folder navigation
Expand Down
97 changes: 97 additions & 0 deletions src/components/assistant-ui/AIFeedbackDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"use client";

import { useState, useCallback } from "react";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";
import { usePostHog } from "posthog-js/react";
import { toast } from "sonner";
import { useAuiState } from "@assistant-ui/react";
import { useWorkspaceStore } from "@/lib/stores/workspace-store";

interface AIFeedbackDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}

export function AIFeedbackDialog({ open, onOpenChange }: AIFeedbackDialogProps) {
const [feedback, setFeedback] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const posthog = usePostHog();

const threadListItemId = useAuiState(({ threadListItem }) => (threadListItem as { id?: string })?.id);
const mainThreadId = useAuiState(({ threads }) => (threads as { mainThreadId?: string })?.mainThreadId);
const threadId = threadListItemId ?? mainThreadId;
const workspaceId = useWorkspaceStore((s) => s.currentWorkspaceId);

const handleSubmit = useCallback(() => {
setIsSubmitting(true);

@cubic-dev-ai cubic-dev-ai Bot Mar 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: isSubmitting is reset synchronously in handleSubmit, so the submit/disable guard is ineffective and duplicate feedback events can be sent.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/components/assistant-ui/AIFeedbackDialog.tsx, line 35:

<comment>`isSubmitting` is reset synchronously in `handleSubmit`, so the submit/disable guard is ineffective and duplicate feedback events can be sent.</comment>

<file context>
@@ -0,0 +1,97 @@
+  const workspaceId = useWorkspaceStore((s) => s.currentWorkspaceId);
+
+  const handleSubmit = useCallback(() => {
+    setIsSubmitting(true);
+
+    if (posthog) {
</file context>
Fix with Cubic


if (posthog) {
posthog.capture("ai-feedback-reported", {
feedback: feedback.trim(),
thread_id: threadId ?? undefined,
workspace_id: workspaceId ?? undefined,
source: "composer",
});
}

toast.success("Feedback submitted—thank you!");
setFeedback("");
onOpenChange(false);
setIsSubmitting(false);
}, [feedback, threadId, workspaceId, posthog, onOpenChange]);

const handleOpenChange = useCallback(
(nextOpen: boolean) => {
if (!nextOpen && !isSubmitting) {
setFeedback("");
}
onOpenChange(nextOpen);
},
[onOpenChange, isSubmitting]
);

return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Report AI Issue</DialogTitle>
<DialogDescription>
What went wrong with the AI? Your feedback helps us improve.
</DialogDescription>
</DialogHeader>

<div className="space-y-4">
<Textarea
placeholder="Describe what went wrong (optional)..."
value={feedback}
onChange={(e) => setFeedback(e.target.value)}
rows={4}
className="resize-none"
/>
</div>

<DialogFooter>
<Button
variant="outline"
onClick={() => handleOpenChange(false)}
disabled={isSubmitting}
>
Cancel
</Button>
<Button onClick={handleSubmit} disabled={isSubmitting}>
{isSubmitting ? "Submitting..." : "Submit Feedback"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
Loading