@@ -8,7 +8,11 @@ import { type CodiumCompletionResult } from "@srcbook/shared";
88const EDITOR_API_KEY = 'd49954eb-cfba-4992-980f-d8fb37f0e942' ;
99const LANGUAGE_SERVER_PROTO_FILE_PATH = path . join ( __dirname , "language_server.proto" ) ;
1010
11- export async function runCodiumAiAutocomplete ( source : string , cursorOffset : number ) : Promise < CodiumCompletionResult > {
11+ export async function runCodiumAiAutocomplete (
12+ apiKey : string | null ,
13+ source : string ,
14+ cursorOffset : number ,
15+ ) : Promise < CodiumCompletionResult > {
1216 const protos = await protobuf . load ( LANGUAGE_SERVER_PROTO_FILE_PATH )
1317 const GetCompletionsRequest = protos . lookupType ( "GetCompletionsRequest" ) ;
1418 const Metadata = protos . lookupType ( "Metadata" ) ;
@@ -18,13 +22,14 @@ export async function runCodiumAiAutocomplete(source: string, cursorOffset: numb
1822 const GetCompletionsResponse = protos . lookupType ( "GetCompletionsResponse" ) ;
1923
2024 const sessionId = `react-editor-${ crypto . randomUUID ( ) } ` ;
25+ const apiKey = apiKey ?? EDITOR_API_KEY ;
2126
2227 const payload = {
2328 otherDocuments : [ ] ,
2429 metadata : Metadata . create ( {
2530 ideName : 'web' ,
2631 extensionVersion : '1.0.12' ,
27- apiKey : 'd49954eb-cfba-4992-980f-d8fb37f0e942' ,
32+ apiKey,
2833 ideVersion : 'unknown' ,
2934 extensionName : '@codeium/react-code-editor' ,
3035 sessionId,
@@ -56,7 +61,7 @@ export async function runCodiumAiAutocomplete(source: string, cursorOffset: numb
5661 headers : {
5762 'Connect-Protocol-Version' : '1' ,
5863 'Content-Type' : 'application/proto' ,
59- Authorization : `Basic ${ EDITOR_API_KEY } -${ sessionId } ` ,
64+ Authorization : `Basic ${ apiKey } -${ sessionId } ` ,
6065 } ,
6166 } ) ;
6267 // console.log('RESPONSE:', response.status);
0 commit comments