Skip to content

Commit f12e4d5

Browse files
committed
fix(md): file streaming patch preview
1 parent cef351f commit f12e4d5

5 files changed

Lines changed: 283 additions & 56 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
RESOURCE_TAB_ICON_BUTTON_CLASS,
3333
RESOURCE_TAB_ICON_CLASS,
3434
} from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-tabs/resource-tab-controls'
35+
import { hasRenderableFilePreviewContent } from '@/app/workspace/[workspaceId]/home/hooks/use-file-preview-sessions'
3536
import type {
3637
GenericResourceData,
3738
MothershipResource,
@@ -116,13 +117,19 @@ export const ResourceContent = memo(function ResourceContent({
116117
const disableStreamingAutoScroll = previewSession?.operation === 'patch'
117118
const rawPreviewText = previewSession?.previewText
118119
const streamingPreviewText =
119-
typeof rawPreviewText === 'string' && rawPreviewText.length > 0 ? rawPreviewText : undefined
120+
previewSession &&
121+
typeof rawPreviewText === 'string' &&
122+
hasRenderableFilePreviewContent(previewSession)
123+
? rawPreviewText
124+
: undefined
120125
const pendingOrStreamingFilePreviewText =
121-
previewSession?.fileId === resource.id && typeof rawPreviewText === 'string'
126+
previewSession?.fileId === resource.id &&
127+
typeof rawPreviewText === 'string' &&
128+
hasRenderableFilePreviewContent(previewSession)
122129
? rawPreviewText
123130
: undefined
124131

125-
if (previewSession && resource.id === 'streaming-file') {
132+
if (resource.id === 'streaming-file') {
126133
return (
127134
<div className='flex h-full flex-col overflow-hidden'>
128135
{streamingPreviewText !== undefined ? (

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/mothership-view.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { cn } from '@/lib/core/utils/cn'
66
import { getFileExtension } from '@/lib/uploads/utils/file-utils'
77
import type { PreviewMode } from '@/app/workspace/[workspaceId]/files/components/file-viewer'
88
import { RICH_PREVIEWABLE_EXTENSIONS } from '@/app/workspace/[workspaceId]/files/components/file-viewer'
9+
import { hasRenderableFilePreviewContent } from '@/app/workspace/[workspaceId]/home/hooks/use-file-preview-sessions'
910
import type {
1011
GenericResourceData,
1112
MothershipResource,
@@ -23,7 +24,7 @@ const PREVIEW_CYCLE: Record<PreviewMode, PreviewMode> = {
2324
/**
2425
* Whether the active resource should show the in-progress file stream.
2526
* The synthetic `streaming-file` tab always shows it; a real file tab only shows it
26-
* when the streamed fileId matches that exact resource.
27+
* after a preview content event has arrived for that exact resource.
2728
*/
2829
function shouldShowStreamingFilePanel(
2930
previewSession: FilePreviewSession | null | undefined,
@@ -32,7 +33,9 @@ function shouldShowStreamingFilePanel(
3233
if (!previewSession || previewSession.status === 'complete' || !active) return false
3334
if (active.id === 'streaming-file') return true
3435
if (active.type !== 'file') return false
35-
if (active.id && previewSession.fileId === active.id) return true
36+
if (active.id && previewSession.fileId === active.id) {
37+
return hasRenderableFilePreviewContent(previewSession)
38+
}
3639
return false
3740
}
3841

0 commit comments

Comments
 (0)