Skip to content

Commit ef87ecc

Browse files
committed
Remove version checking and auto-reload logic from WebSocket communication
1 parent e33d43d commit ef87ecc

5 files changed

Lines changed: 12 additions & 91 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Code Web Chat (CWC) is a free and open-source (FOSS), privacy-first **AI coding
1818
1919
<br/>
2020

21-
<p align="center"><i>Select files for context, enter prompt...</i></p>
21+
<p align="center"><i>Select files for context, enter a prompt...</i></p>
2222

2323
<p align="center"><img src="https://github.com/robertpiosik/CodeWebChat/raw/HEAD/packages/shared/src/media/screenshot-1.png"></p>
2424

‎apps/editor/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "Free AI coding in chatbots (CWC)",
5-
"version": "1.836.0",
5+
"version": "1.837.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

‎apps/editor/src/services/websocket-manager.ts‎

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ export class WebSocketManager {
2929
private reconnect_timer: NodeJS.Timeout | null = null
3030
private has_connected_browsers: boolean = false
3131
private client_id: number | null = null
32-
private current_extension_version: string
33-
private should_reconnect: boolean = true
3432

3533
public readonly on_connection_status_change: vscode.Event<boolean> =
3634
this._on_connection_status_change.event
3735

3836
constructor(context: vscode.ExtensionContext) {
3937
this.context = context
40-
this.current_extension_version = context.extension.packageJSON.version
4138
this._initialize_server()
4239
}
4340

@@ -128,14 +125,12 @@ export class WebSocketManager {
128125
message: 'Failed to restart WebSocket server',
129126
data: error
130127
})
131-
if (this.should_reconnect) {
132-
this._schedule_reconnect()
133-
}
128+
this._schedule_reconnect()
134129
return
135130
}
136131
}
137132

138-
const ws_url = `ws://localhost:${this.port}?token=${this.security_token}&vscode_extension_version=${this.current_extension_version}`
133+
const ws_url = `ws://localhost:${this.port}?token=${this.security_token}`
139134
this.client = new WebSocket.WebSocket(ws_url)
140135

141136
this.client.on('open', () => {
@@ -166,20 +161,6 @@ export class WebSocketManager {
166161
edit_format: message.edit_format,
167162
url: message.url
168163
})
169-
} else if (message.action == 'ping') {
170-
if (message.vscode_extension_version) {
171-
const is_newer = this._is_version_newer(
172-
message.vscode_extension_version,
173-
this.current_extension_version
174-
)
175-
if (is_newer) {
176-
this.should_reconnect = false
177-
this.client?.close()
178-
vscode.window.showErrorMessage(
179-
dictionary.error_message.CWC_UPDATED_RELOAD_WINDOW
180-
)
181-
}
182-
}
183164
}
184165
} catch (error) {
185166
Logger.error({
@@ -199,9 +180,7 @@ export class WebSocketManager {
199180
this.has_connected_browsers = false
200181
this._on_connection_status_change.fire(false)
201182

202-
if (this.should_reconnect) {
203-
this._schedule_reconnect()
204-
}
183+
this._schedule_reconnect()
205184
})
206185

207186
this.client.on('close', () => {
@@ -212,9 +191,7 @@ export class WebSocketManager {
212191
this.has_connected_browsers = false
213192
this._on_connection_status_change.fire(false)
214193

215-
if (this.should_reconnect) {
216-
this._schedule_reconnect()
217-
}
194+
this._schedule_reconnect()
218195
})
219196
}
220197

@@ -228,19 +205,6 @@ export class WebSocketManager {
228205
}, 3000)
229206
}
230207

231-
private _is_version_newer(v1: string, v2: string): boolean {
232-
const parts1 = v1.split('.').map(Number)
233-
const parts2 = v2.split('.').map(Number)
234-
235-
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
236-
const p1 = parts1[i] || 0
237-
const p2 = parts2[i] || 0
238-
if (p1 > p2) return true
239-
if (p1 < p2) return false
240-
}
241-
return false
242-
}
243-
244208
is_connected_with_browser(): boolean {
245209
return this.has_connected_browsers
246210
}

‎apps/editor/src/services/websocket-server-process.ts‎

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class WebSocketServer {
2323
private browser_clients: Map<number, BrowserClient> = new Map()
2424
private browser_client_counter: number = 0
2525
private connections: Set<WebSocket> = new Set()
26-
private vscode_extension_version: string | null = null
2726
private server: http.Server
2827
private wss: any
2928

@@ -84,7 +83,7 @@ class WebSocketServer {
8483
if (is_browser_client) {
8584
this._handle_browser_connection(ws, url)
8685
} else {
87-
this._handle_vscode_connection(ws, url)
86+
this._handle_vscode_connection(ws)
8887
}
8988

9089
this.connections.add(ws)
@@ -107,28 +106,7 @@ class WebSocketServer {
107106
ws.send(JSON.stringify({ action: 'connected', id }))
108107
}
109108

110-
private _handle_vscode_connection(ws: WebSocket, url: URL) {
111-
const incoming_vscode_extension_version = url.searchParams.get(
112-
'vscode_extension_version'
113-
)
114-
115-
if (incoming_vscode_extension_version) {
116-
if (this.vscode_extension_version == null) {
117-
this.vscode_extension_version = incoming_vscode_extension_version
118-
} else {
119-
if (
120-
this.is_version_newer(
121-
incoming_vscode_extension_version,
122-
this.vscode_extension_version
123-
)
124-
) {
125-
ws.close(1000, 'Server shutting down due to newer client version.')
126-
this._shutdown()
127-
return
128-
}
129-
}
130-
}
131-
109+
private _handle_vscode_connection(ws: WebSocket) {
132110
const client_id = this._generate_client_id()
133111
this.vscode_clients.set(client_id, { ws, client_id })
134112

@@ -151,8 +129,7 @@ class WebSocketServer {
151129
client.ws.send(
152130
JSON.stringify({
153131
action: 'vscode-client-connected',
154-
client_id,
155-
vscode_extension_version: this.vscode_extension_version
132+
client_id
156133
})
157134
)
158135
}
@@ -248,22 +225,17 @@ class WebSocketServer {
248225
}
249226

250227
private _ping_clients() {
251-
const pingMessage = JSON.stringify({ action: 'ping' })
228+
const ping_message = JSON.stringify({ action: 'ping' })
252229

253230
for (const client of this.browser_clients.values()) {
254231
if (client.ws.readyState === WebSocket.OPEN) {
255-
client.ws.send(pingMessage)
232+
client.ws.send(ping_message)
256233
}
257234
}
258235

259236
for (const client of this.vscode_clients.values()) {
260237
if (client.ws.readyState == WebSocket.OPEN) {
261-
client.ws.send(
262-
JSON.stringify({
263-
action: 'ping',
264-
vscode_extension_version: this.vscode_extension_version
265-
})
266-
)
238+
client.ws.send(ping_message)
267239
}
268240
}
269241
}
@@ -285,19 +257,6 @@ class WebSocketServer {
285257
process.exit(0)
286258
})
287259
}
288-
289-
private is_version_newer(v1: string, v2: string): boolean {
290-
const parts1 = v1.split('.').map(Number)
291-
const parts2 = v2.split('.').map(Number)
292-
293-
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
294-
const p1 = parts1[i] || 0
295-
const p2 = parts2[i] || 0
296-
if (p1 > p2) return true
297-
if (p1 < p2) return false
298-
}
299-
return false
300-
}
301260
}
302261

303262
const server = new WebSocketServer()

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,6 @@ export const dictionary = {
273273
`Error reading file ${file_path}: ${message}.`,
274274
FAILED_TO_INITIALIZE_WEBSOCKET_SERVER: (error: any) =>
275275
`Failed to initialize WebSocket server: ${error}.`,
276-
CWC_UPDATED_RELOAD_WINDOW:
277-
'CWC has been updated. To continue using it in this workspace, open the command palette and run "Reload Window".',
278276
NO_WORKSPACE_FOLDERS_FOUND: 'No workspace folders found.',
279277
NO_GIT_BRANCHES_FOUND_IN_WORKSPACE:
280278
'No Git branches found in any workspace folder.',

0 commit comments

Comments
 (0)