Skip to content

Commit 9a49fcd

Browse files
committed
refactor(streaming): import SSE helpers directly
1 parent ed71881 commit 9a49fcd

5 files changed

Lines changed: 4 additions & 6 deletions

File tree

apps/sim/app/api/copilot/chat/stream/route.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ vi.mock('@/lib/copilot/request/session', () => ({
3838
}),
3939
encodeSSEEnvelope: (event: Record<string, unknown>) =>
4040
new TextEncoder().encode(`data: ${JSON.stringify(event)}\n\n`),
41-
encodeSSEComment: (comment: string) => new TextEncoder().encode(`: ${comment}\n\n`),
4241
SSE_RESPONSE_HEADERS: {
4342
'Content-Type': 'text/event-stream',
4443
},

apps/sim/app/api/copilot/chat/stream/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import { getCopilotTracer, markSpanForError } from '@/lib/copilot/request/otel'
2222
import {
2323
checkForReplayGap,
2424
createEvent,
25-
encodeSSEComment,
2625
encodeSSEEnvelope,
2726
readEvents,
2827
readFilePreviewSessions,
2928
SSE_RESPONSE_HEADERS,
3029
} from '@/lib/copilot/request/session'
3130
import { toStreamBatchEvent } from '@/lib/copilot/request/session/types'
31+
import { encodeSSEComment } from '@/lib/core/utils/sse'
3232
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
3333

3434
export const maxDuration = 3600

apps/sim/lib/copilot/request/session/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ export {
7171
isFilePreviewSession,
7272
} from './file-preview-session-contract'
7373
export { checkForReplayGap, type ReplayGapResult } from './recovery'
74-
export { encodeSSEComment, encodeSSEEnvelope, SSE_RESPONSE_HEADERS } from './sse'
74+
export { encodeSSEEnvelope, SSE_RESPONSE_HEADERS } from './sse'
7575
export type { StreamBatchEvent } from './types'
7676
export { StreamWriter, type StreamWriterOptions } from './writer'

apps/sim/lib/copilot/request/session/sse.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { SSE_HEADERS } from '@/lib/core/utils/sse'
22

3-
export { encodeSSEComment } from '@/lib/core/utils/sse'
4-
53
const encoder = new TextEncoder()
64

75
export function encodeSSEEnvelope(envelope: unknown): Uint8Array {

apps/sim/lib/copilot/request/session/writer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { createLogger } from '@sim/logger'
22
import { toError } from '@sim/utils/errors'
33
import { MothershipStreamV1EventType } from '@/lib/copilot/generated/mothership-stream-v1'
4+
import { encodeSSEComment } from '@/lib/core/utils/sse'
45
import { appendEvents } from './buffer'
56
import type { PersistedStreamEventEnvelope } from './contract'
67
import { createEvent } from './event'
7-
import { encodeSSEComment, encodeSSEEnvelope } from './sse'
8+
import { encodeSSEEnvelope } from './sse'
89
import type { StreamEvent } from './types'
910

1011
const logger = createLogger('StreamWriter')

0 commit comments

Comments
 (0)