Skip to content

Commit 2af9198

Browse files
Revert SSE implementation and update Docker upgrade script
1 parent 5074934 commit 2af9198

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

backend/src/routes/sse.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hono } from 'hono'
2-
import { streamSSE } from 'hono/streaming'
2+
import { stream } from 'hono/streaming'
33
import { sseAggregator } from '../services/sse-aggregator'
44
import { SSESubscribeSchema } from '@opencode-manager/shared/schemas'
55
import { logger } from '../utils/logger'
@@ -15,32 +15,45 @@ export function createSSERoutes() {
1515
const directories = directoriesParam ? directoriesParam.split(',').filter(Boolean) : []
1616
const clientId = `client_${Date.now()}_${Math.random().toString(36).slice(2)}`
1717

18+
c.header('Content-Type', 'text/event-stream')
19+
c.header('Cache-Control', 'no-cache, no-store, no-transform')
20+
c.header('Connection', 'keep-alive')
1821
c.header('X-Accel-Buffering', 'no')
1922

20-
return streamSSE(c, async (stream) => {
23+
return stream(c, async (writer) => {
24+
const encoder = new TextEncoder()
25+
const writeSSE = (event: string, data: string) => {
26+
const lines = []
27+
if (event) lines.push(`event: ${event}`)
28+
lines.push(`data: ${data}`)
29+
lines.push('')
30+
lines.push('')
31+
writer.write(encoder.encode(lines.join('\n')))
32+
}
33+
2134
const cleanup = sseAggregator.addClient(
2235
clientId,
23-
async (event, data) => {
24-
await stream.writeSSE({ event, data })
36+
(event, data) => {
37+
writeSSE(event, data)
2538
},
2639
directories
2740
)
2841

29-
const heartbeatInterval = setInterval(async () => {
42+
const heartbeatInterval = setInterval(() => {
3043
try {
31-
await stream.writeSSE({ event: 'heartbeat', data: JSON.stringify({ timestamp: Date.now() }) })
44+
writeSSE('heartbeat', JSON.stringify({ timestamp: Date.now() }))
3245
} catch {
3346
clearInterval(heartbeatInterval)
3447
}
3548
}, HEARTBEAT_INTERVAL_MS)
3649

37-
stream.onAbort(() => {
50+
writer.onAbort(() => {
3851
clearInterval(heartbeatInterval)
3952
cleanup()
4053
})
4154

4255
try {
43-
await stream.writeSSE({ event: 'connected', data: JSON.stringify({ clientId, directories, ...sseAggregator.getConnectionStatus() }) })
56+
writeSSE('connected', JSON.stringify({ clientId, directories, ...sseAggregator.getConnectionStatus() }))
4457
} catch (err) {
4558
logger.error(`Failed to send SSE connected event for ${clientId}:`, err)
4659
}

scripts/docker-upgrade.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ fi
3939
echo -e "${YELLOW}Stopping container...${NC}"
4040
$DOCKER_COMPOSE down
4141

42-
echo -e "${YELLOW}Rebuilding image...${NC}"
43-
$DOCKER_COMPOSE build
42+
echo -e "${YELLOW}Rebuilding image with no cache...${NC}"
43+
$DOCKER_COMPOSE build --no-cache
4444

4545
echo -e "${YELLOW}Starting container...${NC}"
4646
$DOCKER_COMPOSE up -d

0 commit comments

Comments
 (0)