mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix: preserve prompt text on network error and allow offline typing (#276)
* fix: preserve prompt text on network error and allow offline typing * fix: preserve prompt on network error, swallow 524 to avoid duplicate sends * feat: add service worker precaching with app shell and runtime cache strategies * fix: copy frontend/plugins into Docker build context * fix: improve service worker update checks with visibility and focus handlers * fix: add connect timeout to event stream to recover from failed connections * fix: remove optimistic message insert, keep prompt in input until server confirms
This commit is contained in:
1 parent
a7d0c13f9a
commit
3e617c2df8
18 files changed
+569
-57
No files matched your search
@@ -21,7 +21,7 @@ interface OpenCodeEventStreamOptions {
|
||||
transport?: EventStreamTransport
|
||||
}
|
||||
|
||||
const { RECONNECT_DELAY_MS, MAX_RECONNECT_DELAY_MS, STALL_THRESHOLD_MS, WATCHDOG_TICK_MS } = DEFAULTS.SSE
|
||||
const { RECONNECT_DELAY_MS, MAX_RECONNECT_DELAY_MS, CONNECT_TIMEOUT_MS, STALL_THRESHOLD_MS, WATCHDOG_TICK_MS } = DEFAULTS.SSE
|
||||
|
||||
export class OpenCodeEventStream {
|
||||
private connection: { close(): void } | null = null
|
||||
@@ -30,6 +30,7 @@ export class OpenCodeEventStream {
|
||||
private directoryRefCounts = new Map<string, number>()
|
||||
private pendingDirectories = new Set<string>()
|
||||
private reconnectTimeout: ReturnType<typeof setTimeout> | null = null
|
||||
private connectTimeout: ReturnType<typeof setTimeout> | null = null
|
||||
private reconnectDelay: number = RECONNECT_DELAY_MS
|
||||
private connected = false
|
||||
private subscriberIdCounter = 0
|
||||
@@ -194,9 +195,26 @@ export class OpenCodeEventStream {
|
||||
onConnected: (data) => this.handleConnected(data),
|
||||
onHeartbeat: () => this.markActivity(),
|
||||
})
|
||||
this.startConnectTimeout()
|
||||
}
|
||||
|
||||
private startConnectTimeout(): void {
|
||||
this.clearConnectTimeout()
|
||||
this.connectTimeout = setTimeout(() => {
|
||||
this.connectTimeout = null
|
||||
this.handleError()
|
||||
}, CONNECT_TIMEOUT_MS)
|
||||
}
|
||||
|
||||
private clearConnectTimeout(): void {
|
||||
if (this.connectTimeout) {
|
||||
clearTimeout(this.connectTimeout)
|
||||
this.connectTimeout = null
|
||||
}
|
||||
}
|
||||
|
||||
private handleOpen(): void {
|
||||
this.clearConnectTimeout()
|
||||
this.connected = true
|
||||
this.reconnectDelay = RECONNECT_DELAY_MS
|
||||
this.startWatchdog()
|
||||
@@ -205,6 +223,7 @@ export class OpenCodeEventStream {
|
||||
}
|
||||
|
||||
private handleError(): void {
|
||||
this.clearConnectTimeout()
|
||||
this.connected = false
|
||||
this.clientId = null
|
||||
this.upstreamConnectedCount = null
|
||||
@@ -250,6 +269,7 @@ export class OpenCodeEventStream {
|
||||
this.clientId = null
|
||||
}
|
||||
|
||||
this.clearConnectTimeout()
|
||||
this.connected = true
|
||||
this.startWatchdog()
|
||||
this.markActivity()
|
||||
@@ -263,6 +283,7 @@ export class OpenCodeEventStream {
|
||||
this.reconnectTimeout = null
|
||||
}
|
||||
|
||||
this.clearConnectTimeout()
|
||||
this.stopWatchdog()
|
||||
this.connection?.close()
|
||||
this.connection = null
|
||||
@@ -289,6 +310,7 @@ export class OpenCodeEventStream {
|
||||
this.reconnectTimeout = null
|
||||
}
|
||||
|
||||
this.clearConnectTimeout()
|
||||
this.stopWatchdog()
|
||||
this.connection?.close()
|
||||
this.connection = null
|
||||
|
||||
Reference in new issue
Block a user