diff --git a/packages/browser-runtime-core/src/open-context-runtime.ts b/packages/browser-runtime-core/src/open-context-runtime.ts index 3abba1746f..72bb9632be 100644 --- a/packages/browser-runtime-core/src/open-context-runtime.ts +++ b/packages/browser-runtime-core/src/open-context-runtime.ts @@ -33,7 +33,7 @@ export class OpenContextRuntime implements Runtime { private shellEvaluator: ShellEvaluator; private instanceState: ShellInstanceState; private evaluationListener: RuntimeEvaluationListener | null = null; - private updatedConnectionInfo = false; + private updatedConnectionInfoPromise: Promise | null = null; constructor( serviceProvider: ServiceProvider, @@ -49,9 +49,9 @@ export class OpenContextRuntime implements Runtime { async getCompletions(code: string): Promise { if (!this.autocompleter) { - await this.instanceState.fetchConnectionInfo(); - this.updatedConnectionInfo = true; this.autocompleter = new ShellApiAutocompleter(this.instanceState.getAutocompleteParameters()); + this.updatedConnectionInfoPromise ??= this.instanceState.fetchConnectionInfo(); + await this.updatedConnectionInfoPromise; } return this.autocompleter.getCompletions(code); @@ -76,10 +76,8 @@ export class OpenContextRuntime implements Runtime { } async getShellPrompt(): Promise { - if (!this.updatedConnectionInfo) { - await this.instanceState.fetchConnectionInfo(); - this.updatedConnectionInfo = true; - } + this.updatedConnectionInfoPromise ??= this.instanceState.fetchConnectionInfo(); + await this.updatedConnectionInfoPromise; return await this.instanceState.getDefaultPrompt(); } }