Skip to content

Commit

Permalink
fix: create sessionId in non-unique context (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick authored Jul 3, 2024
1 parent 535e1c6 commit 58986fa
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/codeium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ const transport = createConnectTransport({

const client = createPromiseClient(LanguageServerService, transport);

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

export async function getCodeiumCompletions({
text,
Expand Down

0 comments on commit 58986fa

Please sign in to comment.