Skip to content

Commit

Permalink
fix: update websocket close code and encode api-key
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 3, 2024
1 parent b7f9567 commit e0ff8b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export async function startServer(options: { port: string; apiKey?: string }) {
const hash = search.get("api-key")
if (req.headers.authorization !== apiKey && hash !== apiKey) {
logError(`clients: connection unauthorized ${url}, ${hash}`)
ws.close(401, "Unauthorized")
ws.close(1008, "Unauthorized")
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/src/servermanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TerminalServerManager implements ServerManager {
)

this.client = new WebSocketClient(
`http://localhost:${SERVER_PORT}?api-key=${sessionApiKey}`
`http://localhost:${SERVER_PORT}?api-key=${encodeURIComponent(sessionApiKey)}`
)
this.client.chatRequest = createChatModelRunner(this.state)
this.client.addEventListener(OPEN, async () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/vscode/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class ExtensionState extends EventTarget {
AIRequestSnapshot
> = undefined
readonly output: vscode.LogOutputChannel
readonly sessionApiKey = randomHex(128)
readonly sessionApiKey = randomHex(64)

constructor(public readonly context: ExtensionContext) {
super()
Expand Down Expand Up @@ -365,8 +365,7 @@ export class ExtensionState extends EventTarget {
}

get project() {
if (!this._project)
this.parseWorkspace()
if (!this._project) this.parseWorkspace()
return this._project
}

Expand Down

0 comments on commit e0ff8b8

Please sign in to comment.