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
4 changes: 2 additions & 2 deletions src/app/api/cards/from-message/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
const userId = session.user.id;

const body = await request.json();
const { content, workspaceId } = body;
const { content, workspaceId, folderId } = body;



Expand Down Expand Up @@ -99,7 +99,7 @@ Return ONLY the reformatted note content in markdown format. Do not include any
workspaceId,
title,
content: cleanedContent,

folderId,
});

logger.debug("📝 [CREATE-CARD-FROM-MESSAGE] Card created successfully", {
Expand Down
6 changes: 3 additions & 3 deletions src/app/api/notes/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const createNoteSchema = z.object({
workspaceId: z.string().uuid(),
title: z.string().min(1),
content: z.string().optional(),

folderId: z.string().uuid().optional(),
});

export async function POST(req: Request) {
Expand All @@ -31,15 +31,15 @@ export async function POST(req: Request) {
});
}

const { workspaceId, title, content } = result.data;
const { workspaceId, title, content, folderId } = result.data;

logger.info("📝 [API] Creating note via manual confirmation:", { workspaceId, title });

const workerResult = await workspaceWorker("create", {
workspaceId,
title,
content,

folderId,
});

if (!workerResult.success) {
Expand Down
10 changes: 8 additions & 2 deletions src/components/assistant-ui/AssistantTextSelectionManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,18 @@ export default function AssistantTextSelectionManager({
setIsProcessing(true);

// Call the API endpoint that uses the workspace worker (same as createNote tool)
// Get the current active folder ID
const activeFolderId = useUIStore.getState().activeFolderId;

const response = await fetch("/api/cards/from-message", {
method: "POST",
headers: {
"Content-Type": "application/json",

},
body: JSON.stringify({
content: currentSelection.text,
workspaceId,
folderId: activeFolderId ?? undefined,
}),
});

Expand Down Expand Up @@ -742,15 +745,18 @@ export default function AssistantTextSelectionManager({
}

// Call the API endpoint that uses the workspace worker (same as createNote tool)
// Get the current active folder ID
const activeFolderId = useUIStore.getState().activeFolderId;

const response = await fetch("/api/cards/from-message", {
method: "POST",
headers: {
"Content-Type": "application/json",

},
body: JSON.stringify({
content: combinedContent,
workspaceId,
folderId: activeFolderId ?? undefined,
}),
});

Expand Down
15 changes: 10 additions & 5 deletions src/hooks/ai/use-create-card-from-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState, useCallback, useRef } from "react";
import { useMessage } from "@assistant-ui/react";
import { toast } from "sonner";
import { useWorkspaceStore } from "@/lib/stores/workspace-store";
import { useUIStore } from "@/lib/stores/ui-store";
import { useQueryClient } from "@tanstack/react-query";
import { logger } from "@/lib/utils/logger";

Expand All @@ -19,7 +20,7 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) {
const { debounceMs = 300 } = options; // Reduced from 1000ms to 300ms
const [isCreating, setIsCreating] = useState(false);
const debounceTimerRef = useRef<NodeJS.Timeout | null>(null);

const message = useMessage();
const currentWorkspaceId = useWorkspaceStore((state) => state.currentWorkspaceId);
const queryClient = useQueryClient();
Expand Down Expand Up @@ -58,6 +59,9 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) {
const toastId = toast.loading("Creating card...");

try {
// Get the current active folder ID
const activeFolderId = useUIStore.getState().activeFolderId;

const response = await fetch("/api/cards/from-message", {
method: "POST",
headers: {
Expand All @@ -66,6 +70,7 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) {
body: JSON.stringify({
content,
workspaceId: currentWorkspaceId,
folderId: activeFolderId ?? undefined,
}),
});

Expand All @@ -75,21 +80,21 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) {
}

const result = await response.json();

// Invalidate React Query cache to refresh the UI immediately
if (currentWorkspaceId) {
logger.debug("🔄 [CREATE-CARD-BUTTON] Invalidating workspace cache", {
workspaceId: currentWorkspaceId.substring(0, 8),
});

// Force refetch workspace events to show the new card
queryClient.invalidateQueries({
queryKey: ["workspace", currentWorkspaceId, "events"],
});
}

toast.success("Card created successfully!", { id: toastId });

return result;
} catch (error) {
console.error("Error creating card:", error);
Expand Down