From 8b6d9c0903589367bb6635391265e8f6c1548df7 Mon Sep 17 00:00:00 2001 From: Vukasin Date: Sun, 4 May 2025 15:49:26 +0200 Subject: [PATCH] fix: policy and share page api error --- ...0250504123828_fix_thread_select_policy.sql | 16 + frontend/src/app/share/[threadId]/page.tsx | 468 +++++++++--------- .../src/components/sidebar/nav-agents.tsx | 9 +- .../src/components/sidebar/share-modal.tsx | 16 +- .../components/thread/thread-site-header.tsx | 1 + frontend/src/lib/api.ts | 4 - 6 files changed, 261 insertions(+), 253 deletions(-) create mode 100644 backend/supabase/migrations/20250504123828_fix_thread_select_policy.sql diff --git a/backend/supabase/migrations/20250504123828_fix_thread_select_policy.sql b/backend/supabase/migrations/20250504123828_fix_thread_select_policy.sql new file mode 100644 index 00000000..b15cb8bc --- /dev/null +++ b/backend/supabase/migrations/20250504123828_fix_thread_select_policy.sql @@ -0,0 +1,16 @@ +DROP POLICY IF EXISTS thread_select_policy ON threads; + +CREATE POLICY thread_select_policy ON threads +FOR SELECT +USING ( + is_public IS TRUE + OR basejump.has_role_on_account(account_id) = true + OR EXISTS ( + SELECT 1 FROM projects + WHERE projects.project_id = threads.project_id + AND ( + projects.is_public IS TRUE + OR basejump.has_role_on_account(projects.account_id) = true + ) + ) +); diff --git a/frontend/src/app/share/[threadId]/page.tsx b/frontend/src/app/share/[threadId]/page.tsx index 7c324688..a3664362 100644 --- a/frontend/src/app/share/[threadId]/page.tsx +++ b/frontend/src/app/share/[threadId]/page.tsx @@ -99,10 +99,10 @@ function renderMarkdownContent(content: string, handleToolClick: (assistantMessa if (toolName === 'ask') { // Extract attachments from the XML attributes const attachmentsMatch = rawXml.match(/attachments=["']([^"']*)["']/i); - const attachments = attachmentsMatch + const attachments = attachmentsMatch ? attachmentsMatch[1].split(',').map(a => a.trim()) : []; - + // Extract content from the ask tag const contentMatch = rawXml.match(/]*>([\s\S]*?)<\/ask>/i); const askContent = contentMatch ? contentMatch[1] : ''; @@ -111,7 +111,7 @@ function renderMarkdownContent(content: string, handleToolClick: (assistantMessa contentParts.push(
{askContent} - + {attachments.length > 0 && (
Attachments:
@@ -122,13 +122,13 @@ function renderMarkdownContent(content: string, handleToolClick: (assistantMessa const isPdf = extension === 'pdf'; const isMd = extension === 'md'; const isCode = ['js', 'jsx', 'ts', 'tsx', 'py', 'html', 'css', 'json'].includes(extension || ''); - + let icon = ; if (isImage) icon = ; if (isPdf) icon = ; if (isMd) icon = ; if (isCode) icon = ; - + return (
); }; - + return WrappedPanel; }, []); @@ -1313,7 +1300,7 @@ export default function ThreadPage({ params }: { params: Promise }
- + {/* Skeleton Chat Messages */}
@@ -1326,7 +1313,7 @@ export default function ThreadPage({ params }: { params: Promise }
- + {/* Assistant response with tool usage */}
@@ -1339,12 +1326,12 @@ export default function ThreadPage({ params }: { params: Promise }
- + {/* Tool call button skeleton */}
- +
@@ -1357,7 +1344,7 @@ export default function ThreadPage({ params }: { params: Promise }
- + {/* Skeleton Side Panel (closed state) */}
@@ -1406,7 +1393,7 @@ export default function ThreadPage({ params }: { params: Promise }
- Kortix + Kortix
{projectName || 'Shared Conversation'}
@@ -1428,8 +1415,8 @@ export default function ThreadPage({ params }: { params: Promise } className="h-8 w-8" aria-label={isPlaying ? "Pause Replay" : "Play Replay"} > - {isPlaying ? - : + {isPlaying ? + : } @@ -1454,7 +1441,7 @@ export default function ThreadPage({ params }: { params: Promise }
-
}
{/* Gradient overlay */}
- +
@@ -1473,13 +1460,13 @@ export default function ThreadPage({ params }: { params: Promise }

This is a shared view-only agent run. Click play to replay the entire conversation with realistic timing.

-
@@ -1526,7 +1513,7 @@ export default function ThreadPage({ params }: { params: Promise } if (currentGroup) { groupedMessages.push(currentGroup); } - + return groupedMessages.map((group, groupIndex) => { if (group.type === 'user') { const message = group.messages[0]; @@ -1538,7 +1525,7 @@ export default function ThreadPage({ params }: { params: Promise } return message.content; } })(); - + return (
@@ -1551,7 +1538,7 @@ export default function ThreadPage({ params }: { params: Promise }
- Suna + Suna
@@ -1568,7 +1555,7 @@ export default function ThreadPage({ params }: { params: Promise } toolResultsMap.get(assistantId)?.push(msg); } }); - + const renderedToolResultIds = new Set(); const elements: React.ReactNode[] = []; @@ -1580,8 +1567,8 @@ export default function ThreadPage({ params }: { params: Promise } if (!parsedContent.content) return; const renderedContent = renderMarkdownContent( - parsedContent.content, - handleToolClick, + parsedContent.content, + handleToolClick, message.message_id, handleOpenFileViewer ); @@ -1600,47 +1587,47 @@ export default function ThreadPage({ params }: { params: Promise } })()} {groupIndex === groupedMessages.length - 1 && isStreamingText && ( -
+
{(() => { - let detectedTag: string | null = null; - let tagStartIndex = -1; - if (streamingText) { - for (const tag of HIDE_STREAMING_XML_TAGS) { - const openingTagPattern = `<${tag}`; - const index = streamingText.indexOf(openingTagPattern); - if (index !== -1) { - detectedTag = tag; - tagStartIndex = index; - break; - } - } + let detectedTag: string | null = null; + let tagStartIndex = -1; + if (streamingText) { + for (const tag of HIDE_STREAMING_XML_TAGS) { + const openingTagPattern = `<${tag}`; + const index = streamingText.indexOf(openingTagPattern); + if (index !== -1) { + detectedTag = tag; + tagStartIndex = index; + break; + } } + } - const textToRender = streamingText || ''; - const textBeforeTag = detectedTag ? textToRender.substring(0, tagStartIndex) : textToRender; - const showCursor = isStreamingText && !detectedTag; + const textToRender = streamingText || ''; + const textBeforeTag = detectedTag ? textToRender.substring(0, tagStartIndex) : textToRender; + const showCursor = isStreamingText && !detectedTag; - return ( - <> - {textBeforeTag && ( - {textBeforeTag} - )} - {showCursor && ( - - )} + return ( + <> + {textBeforeTag && ( + {textBeforeTag} + )} + {showCursor && ( + + )} - {detectedTag && ( -
- -
- )} - - ); + {detectedTag && ( +
+ +
+ )} + + ); })()}
)} @@ -1654,13 +1641,13 @@ export default function ThreadPage({ params }: { params: Promise } return null; }); })()} - + {/* Show tool call animation if active */} {currentToolCall && (
- Suna + Suna
@@ -1673,13 +1660,13 @@ export default function ThreadPage({ params }: { params: Promise }
)} - + {/* Show streaming indicator if no messages yet */} {visibleMessages.length === 0 && isStreamingText && (
- Suna + Suna
@@ -1698,14 +1685,13 @@ export default function ThreadPage({ params }: { params: Promise }
- + {/* Floating playback controls - moved to be centered in the chat area when side panel is open */} {messages.length > 0 && ( -
+ }`}>
- +
{Math.min(currentMessageIndex + (isStreamingText ? 0 : 1), messages.length)}/{messages.length}
- + - +