Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit 58986fa

Browse files
authored
fix: create sessionId in non-unique context (#37)
1 parent 535e1c6 commit 58986fa

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/codeium.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,24 @@ const transport = createConnectTransport({
1717

1818
const client = createPromiseClient(LanguageServerService, transport);
1919

20-
/**
21-
* Note that this won't be available in 'insecure contexts',
22-
* websites served under HTTP not HTTPS, but those are rare.
23-
* And it'll work in localhost for development.
24-
*/
25-
const sessionId = crypto.randomUUID();
20+
let sessionId: string;
21+
try {
22+
/**
23+
* Note that this won't be available in 'insecure contexts',
24+
* websites served under HTTP not HTTPS, but those are rare.
25+
* And it'll work in localhost for development.
26+
*/
27+
sessionId = crypto.randomUUID();
28+
} catch {
29+
// When not in a secure context
30+
// https://stackoverflow.com/questions/105034/how-do-i-create-a-guid-uuid
31+
function uuidv4() {
32+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
33+
(+c ^ (crypto.getRandomValues(new Uint8Array(1))[0] ?? 0) & 15 >> +c / 4).toString(16)
34+
);
35+
}
36+
sessionId = uuidv4();
37+
}
2638

2739
export async function getCodeiumCompletions({
2840
text,

0 commit comments

Comments
 (0)