Skip to content

Commit eb5c1d0

Browse files
committed
use smooth streaming hook
1 parent ef71e3b commit eb5c1d0

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ interface FileViewerProps {
9494
isAgentEditing?: boolean
9595
disableStreamingAutoScroll?: boolean
9696
previewContextKey?: string
97+
showBubbleMenu?: boolean
9798
}
9899

99100
export function FileViewer({
@@ -110,6 +111,7 @@ export function FileViewer({
110111
isAgentEditing,
111112
disableStreamingAutoScroll = false,
112113
previewContextKey,
114+
showBubbleMenu = true,
113115
}: FileViewerProps) {
114116
const category = resolveFileCategory(file.type, file.name)
115117

@@ -152,6 +154,7 @@ export function FileViewer({
152154
isAgentEditing={isAgentEditing}
153155
disableStreamingAutoScroll={disableStreamingAutoScroll}
154156
previewContextKey={previewContextKey}
157+
showBubbleMenu={showBubbleMenu}
155158
/>
156159
)
157160
}

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-editor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ interface RichMarkdownEditorProps {
4242
isAgentEditing?: boolean
4343
disableStreamingAutoScroll?: boolean
4444
previewContextKey?: string
45+
showBubbleMenu?: boolean
4546
}
4647

4748
/**
@@ -68,6 +69,7 @@ export const RichMarkdownEditor = memo(function RichMarkdownEditor({
6869
isAgentEditing,
6970
disableStreamingAutoScroll = false,
7071
previewContextKey,
72+
showBubbleMenu = true,
7173
}: RichMarkdownEditorProps) {
7274
const {
7375
content,
@@ -108,6 +110,7 @@ export const RichMarkdownEditor = memo(function RichMarkdownEditor({
108110
canEdit={canEdit}
109111
autoFocus={autoFocus}
110112
disableStreamingAutoScroll={disableStreamingAutoScroll}
113+
showBubbleMenu={showBubbleMenu}
111114
onChange={setDraftContent}
112115
onSaveShortcut={saveImmediately}
113116
/>
@@ -124,6 +127,7 @@ interface LoadedRichMarkdownEditorProps {
124127
canEdit: boolean
125128
autoFocus?: boolean
126129
disableStreamingAutoScroll?: boolean
130+
showBubbleMenu: boolean
127131
onChange: (markdown: string) => void
128132
onSaveShortcut: () => Promise<void>
129133
}
@@ -160,6 +164,7 @@ export function LoadedRichMarkdownEditor({
160164
canEdit,
161165
autoFocus,
162166
disableStreamingAutoScroll,
167+
showBubbleMenu,
163168
onChange,
164169
onSaveShortcut,
165170
}: LoadedRichMarkdownEditorProps) {
@@ -377,7 +382,7 @@ export function LoadedRichMarkdownEditor({
377382
ref={containerRef}
378383
className={cn('flex flex-1 flex-col overflow-y-auto', isEditable && 'cursor-text')}
379384
>
380-
{editor && <EditorBubbleMenu editor={editor} />}
385+
{showBubbleMenu && editor && <EditorBubbleMenu editor={editor} />}
381386
<EditorContent
382387
editor={editor}
383388
className='mx-auto flex w-full max-w-[48rem] flex-1 flex-col px-8 py-6 selection:bg-[var(--selection-bg)] selection:text-[var(--text-primary)] dark:selection:bg-[var(--selection-dark)] dark:selection:text-white'

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/use-editable-file-content.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
useWorkspaceFileContent,
88
} from '@/hooks/queries/workspace-files'
99
import { type SaveStatus, useAutosave } from '@/hooks/use-autosave'
10+
import { useSmoothText } from '@/hooks/use-smooth-text'
1011
import {
1112
INITIAL_TEXT_EDITOR_CONTENT_STATE,
1213
type SyncTextEditorContentStateOptions,
@@ -128,6 +129,19 @@ export function useEditableFileContent({
128129
const updateContentRef = useRef(updateContent)
129130
updateContentRef.current = updateContent
130131

132+
// Pace only the streamed text (never user edits) so the preview reveals at the same word-by-word
133+
// cadence as chat. Off-stream it reverts to undefined so the engine reconciles to the agent's
134+
// persisted write; snapOnNonAppend shows in-place rewrites/patches in full instead of re-revealing.
135+
const pacedStreamingContent = useSmoothText(
136+
streamingContent ?? '',
137+
streamingContent !== undefined,
138+
{
139+
snapOnNonAppend: true,
140+
}
141+
)
142+
const effectiveStreamingContent =
143+
streamingContent !== undefined ? pacedStreamingContent : undefined
144+
131145
const {
132146
content,
133147
savedContent,
@@ -138,7 +152,7 @@ export function useEditableFileContent({
138152
} = useFileContentState({
139153
canReconcileToFetchedContent: file.key.length > 0,
140154
fetchedContent,
141-
streamingContent,
155+
streamingContent: effectiveStreamingContent,
142156
})
143157

144158
const isStreamInteractionLocked = isStreamPhaseLocked || Boolean(isAgentEditing)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export const ResourceContent = memo(function ResourceContent({
150150
isAgentEditing={isAgentEditing}
151151
disableStreamingAutoScroll={disableStreamingAutoScroll}
152152
previewContextKey={previewContextKey}
153+
showBubbleMenu={false}
153154
/>
154155
</div>
155156
)
@@ -612,6 +613,7 @@ function EmbeddedFile({
612613
isAgentEditing={isAgentEditing}
613614
disableStreamingAutoScroll={disableStreamingAutoScroll}
614615
previewContextKey={previewContextKey}
616+
showBubbleMenu={false}
615617
/>
616618
</div>
617619
)

0 commit comments

Comments
 (0)