Skip to content

Commit 99b9362

Browse files
fix(cli): use random UUID for WS session ID, not sessionKey
The WebSocket URL path segment is a browser connection identifier, not the chat sessionKey. The sessionKey goes in message payloads.
1 parent 686d304 commit 99b9362

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/cli/src/commands/chat.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ export const chatCmd = new Command("chat")
6464
}
6565
}
6666

67-
// Build WS URL
67+
// Build WS URL — sessionId in the URL is a random browser session identifier,
68+
// NOT the chat sessionKey. The sessionKey goes in the message payload.
69+
const wsSessionId = randomUUID();
6870
const wsProtocol = cfg.url.startsWith("https") ? "wss" : "ws";
6971
const wsHost = cfg.url.replace(/^https?:\/\//, "");
70-
const wsUrl = `${wsProtocol}://${wsHost}/api/ws/${cfg.userId}/${encodeURIComponent(sessionId!)}`;
72+
const wsUrl = `${wsProtocol}://${wsHost}/api/ws/${cfg.userId}/${wsSessionId}`;
7173

7274
const timeoutMs = parseFloat(opts.timeout) * 1000;
7375

packages/plugin/bin/botschat-cli.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,9 +1149,10 @@ var chatCmd = new Command9("chat").description("Chat with an AI agent").argument
11491149
updateConfig({ defaultSession: sessionId });
11501150
}
11511151
}
1152+
const wsSessionId = randomUUID3();
11521153
const wsProtocol = cfg.url.startsWith("https") ? "wss" : "ws";
11531154
const wsHost = cfg.url.replace(/^https?:\/\//, "");
1154-
const wsUrl = `${wsProtocol}://${wsHost}/api/ws/${cfg.userId}/${encodeURIComponent(sessionId)}`;
1155+
const wsUrl = `${wsProtocol}://${wsHost}/api/ws/${cfg.userId}/${wsSessionId}`;
11551156
const timeoutMs = parseFloat(opts.timeout) * 1e3;
11561157
if (interactive) {
11571158
await runInteractive(wsUrl, sessionId, opts.agent, cfg.userId);

0 commit comments

Comments
 (0)