update workspaces on session info change
This commit is contained in:
parent
07d65112fe
commit
a894dd80ea
4 changed files with 124 additions and 92 deletions
|
|
@ -1,4 +1,7 @@
|
|||
import { ControlPlaneClient } from "../control-plane/client.js";
|
||||
import {
|
||||
ControlPlaneClient,
|
||||
ControlPlaneSessionInfo,
|
||||
} from "../control-plane/client.js";
|
||||
import {
|
||||
BrowserSerializedContinueConfig,
|
||||
ContinueConfig,
|
||||
|
|
@ -118,44 +121,20 @@ export class ConfigHandler {
|
|||
return this.profiles.filter((p) => p.profileId !== this.selectedProfileId);
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly ide: IDE,
|
||||
private ideSettingsPromise: Promise<IdeSettings>,
|
||||
private readonly writeLog: (text: string) => Promise<void>,
|
||||
private readonly controlPlaneClient: ControlPlaneClient,
|
||||
) {
|
||||
this.ide = ide;
|
||||
this.ideSettingsPromise = ideSettingsPromise;
|
||||
this.writeLog = writeLog;
|
||||
|
||||
// Set local profile as default
|
||||
const localProfileLoader = new LocalProfileLoader(
|
||||
ide,
|
||||
ideSettingsPromise,
|
||||
writeLog,
|
||||
);
|
||||
this.profiles = [new ProfileLifecycleManager(localProfileLoader)];
|
||||
this.selectedProfileId = localProfileLoader.profileId;
|
||||
|
||||
// Always load local profile immediately in case control plane doesn't load
|
||||
try {
|
||||
this.loadConfig();
|
||||
} catch (e) {
|
||||
console.error("Failed to load config: ", e);
|
||||
}
|
||||
|
||||
// Load control plane profiles
|
||||
// TODO
|
||||
private async fetchControlPlaneProfiles() {
|
||||
// Get the profiles and create their lifecycle managers
|
||||
this.controlPlaneClient.listWorkspaces().then(async (workspaces) => {
|
||||
this.profiles = this.profiles.filter(
|
||||
(profile) => profile.profileId === "local",
|
||||
);
|
||||
workspaces.forEach((workspace) => {
|
||||
const profileLoader = new ControlPlaneProfileLoader(
|
||||
workspace.id,
|
||||
workspace.name,
|
||||
this.controlPlaneClient,
|
||||
ide,
|
||||
ideSettingsPromise,
|
||||
writeLog,
|
||||
this.ide,
|
||||
this.ideSettingsPromise,
|
||||
this.writeLog,
|
||||
this.reloadConfig.bind(this),
|
||||
);
|
||||
this.profiles.push(new ProfileLifecycleManager(profileLoader));
|
||||
|
|
@ -184,6 +163,36 @@ export class ConfigHandler {
|
|||
});
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly ide: IDE,
|
||||
private ideSettingsPromise: Promise<IdeSettings>,
|
||||
private readonly writeLog: (text: string) => Promise<void>,
|
||||
private controlPlaneClient: ControlPlaneClient,
|
||||
) {
|
||||
this.ide = ide;
|
||||
this.ideSettingsPromise = ideSettingsPromise;
|
||||
this.writeLog = writeLog;
|
||||
|
||||
// Set local profile as default
|
||||
const localProfileLoader = new LocalProfileLoader(
|
||||
ide,
|
||||
ideSettingsPromise,
|
||||
writeLog,
|
||||
);
|
||||
this.profiles = [new ProfileLifecycleManager(localProfileLoader)];
|
||||
this.selectedProfileId = localProfileLoader.profileId;
|
||||
|
||||
// Always load local profile immediately in case control plane doesn't load
|
||||
try {
|
||||
this.loadConfig();
|
||||
} catch (e) {
|
||||
console.error("Failed to load config: ", e);
|
||||
}
|
||||
|
||||
// Load control plane profiles
|
||||
this.fetchControlPlaneProfiles();
|
||||
}
|
||||
|
||||
async setSelectedProfile(profileId: string) {
|
||||
this.selectedProfileId = profileId;
|
||||
const newConfig = await this.loadConfig();
|
||||
|
|
@ -209,6 +218,15 @@ export class ConfigHandler {
|
|||
this.reloadConfig();
|
||||
}
|
||||
|
||||
updateControlPlaneSessionInfo(
|
||||
sessionInfo: ControlPlaneSessionInfo | undefined,
|
||||
) {
|
||||
this.controlPlaneClient = new ControlPlaneClient(
|
||||
Promise.resolve(sessionInfo),
|
||||
);
|
||||
this.fetchControlPlaneProfiles();
|
||||
}
|
||||
|
||||
private profilesListeners: ((profiles: ProfileDescription[]) => void)[] = [];
|
||||
onDidChangeAvailableProfiles(
|
||||
listener: (profiles: ProfileDescription[]) => void,
|
||||
|
|
|
|||
21
core/core.ts
21
core/core.ts
|
|
@ -248,9 +248,9 @@ export class Core {
|
|||
(provider) => provider.description.title === "docs",
|
||||
);
|
||||
|
||||
const siteIndexingOptions: SiteIndexingConfig[] = provider ?
|
||||
(mProvider => mProvider?.options?.sites || [])({ ...provider }) :
|
||||
[];
|
||||
const siteIndexingOptions: SiteIndexingConfig[] = provider
|
||||
? ((mProvider) => mProvider?.options?.sites || [])({ ...provider })
|
||||
: [];
|
||||
|
||||
await this.indexDocs(siteIndexingOptions, msg.data.reIndex);
|
||||
this.ide.infoPopup("Docs indexing completed");
|
||||
|
|
@ -619,6 +619,9 @@ export class Core {
|
|||
on("didChangeSelectedProfile", (msg) => {
|
||||
this.configHandler.setSelectedProfile(msg.data.id);
|
||||
});
|
||||
on("didChangeControlPlaneSessionInfo", async (msg) => {
|
||||
this.configHandler.updateControlPlaneSessionInfo(msg.data.sessionInfo);
|
||||
});
|
||||
}
|
||||
|
||||
private indexingCancellationController: AbortController | undefined;
|
||||
|
|
@ -637,12 +640,18 @@ export class Core {
|
|||
}
|
||||
}
|
||||
|
||||
private async indexDocs(sites: SiteIndexingConfig[], reIndex: boolean): Promise<void> {
|
||||
private async indexDocs(
|
||||
sites: SiteIndexingConfig[],
|
||||
reIndex: boolean,
|
||||
): Promise<void> {
|
||||
for (const site of sites) {
|
||||
for await (const update of this.docsService.indexAndAdd(site, new TransformersJsEmbeddingsProvider(), reIndex)) {
|
||||
for await (const update of this.docsService.indexAndAdd(
|
||||
site,
|
||||
new TransformersJsEmbeddingsProvider(),
|
||||
reIndex,
|
||||
)) {
|
||||
// Temporary disabled posting progress updates to the UI due to
|
||||
// possible collision with code indexing progress updates.
|
||||
|
||||
// this.messenger.request("indexProgress", update);
|
||||
// this.indexingState = update;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,12 +257,12 @@ export class VsCodeExtension {
|
|||
});
|
||||
|
||||
// When GitHub sign-in status changes, reload config
|
||||
vscode.authentication.onDidChangeSessions((e) => {
|
||||
vscode.authentication.onDidChangeSessions(async (e) => {
|
||||
if (e.provider.id === "github") {
|
||||
this.configHandler.reloadConfig();
|
||||
} else if (e.provider.id === "continue") {
|
||||
const sessionInfo = await getControlPlaneSessionInfo(true);
|
||||
this.webviewProtocolPromise.then(async (webviewProtocol) => {
|
||||
const sessionInfo = await getControlPlaneSessionInfo(true);
|
||||
webviewProtocol.request("didChangeControlPlaneSessionInfo", {
|
||||
sessionInfo,
|
||||
});
|
||||
|
|
@ -270,6 +270,7 @@ export class VsCodeExtension {
|
|||
// To make sure continue-proxy models and anything else requiring it get updated access token
|
||||
this.configHandler.reloadConfig();
|
||||
});
|
||||
this.core.invoke("didChangeControlPlaneSessionInfo", { sessionInfo });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -160,58 +160,62 @@ function ProfileSwitcher(props: {}) {
|
|||
|
||||
return (
|
||||
<>
|
||||
{controlServerBetaEnabled && profiles.length > 0 && (
|
||||
<StyledListbox
|
||||
value={"GPT-4"}
|
||||
onChange={(id: string) => {
|
||||
ideMessenger.request("didChangeSelectedProfile", { id });
|
||||
}}
|
||||
>
|
||||
<div className="relative">
|
||||
<StyledListboxButton>
|
||||
<div>{selectedProfile()?.title}</div>
|
||||
<div className="pointer-events-none flex items-center">
|
||||
<ChevronUpDownIcon
|
||||
className="h-4 w-4 text-gray-400"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
</StyledListboxButton>
|
||||
{topDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<Transition
|
||||
as={Fragment}
|
||||
leave="transition ease-in duration-100"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<StyledListboxOptions>
|
||||
{profiles.map((option, idx) => (
|
||||
<ListBoxOption
|
||||
selected={option.id === selectedProfileId}
|
||||
option={option}
|
||||
idx={idx}
|
||||
key={idx}
|
||||
showDelete={profiles.length > 1}
|
||||
/>
|
||||
))}
|
||||
<div
|
||||
className="px-2 py-1"
|
||||
style={{ color: lightGray, fontSize: getFontSize() - 2 }}
|
||||
>
|
||||
{profiles.length === 0 ? (
|
||||
<i>No profiles found</i>
|
||||
) : (
|
||||
"Select profile"
|
||||
)}
|
||||
</div>
|
||||
</StyledListboxOptions>
|
||||
</Transition>,
|
||||
topDiv,
|
||||
)}
|
||||
</div>
|
||||
</StyledListbox>
|
||||
)}
|
||||
{controlServerBetaEnabled &&
|
||||
profiles.some((profile) => profile.id !== "local") && (
|
||||
<StyledListbox
|
||||
value={"GPT-4"}
|
||||
onChange={(id: string) => {
|
||||
ideMessenger.request("didChangeSelectedProfile", { id });
|
||||
}}
|
||||
>
|
||||
<div className="relative">
|
||||
<StyledListboxButton>
|
||||
<div>{selectedProfile()?.title}</div>
|
||||
<div className="pointer-events-none flex items-center">
|
||||
<ChevronUpDownIcon
|
||||
className="h-4 w-4 text-gray-400"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
</StyledListboxButton>
|
||||
{topDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<Transition
|
||||
as={Fragment}
|
||||
leave="transition ease-in duration-100"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<StyledListboxOptions>
|
||||
{profiles.map((option, idx) => (
|
||||
<ListBoxOption
|
||||
selected={option.id === selectedProfileId}
|
||||
option={option}
|
||||
idx={idx}
|
||||
key={idx}
|
||||
showDelete={profiles.length > 1}
|
||||
/>
|
||||
))}
|
||||
<div
|
||||
className="px-2 py-1"
|
||||
style={{
|
||||
color: lightGray,
|
||||
fontSize: getFontSize() - 2,
|
||||
}}
|
||||
>
|
||||
{profiles.length === 0 ? (
|
||||
<i>No profiles found</i>
|
||||
) : (
|
||||
"Select profile"
|
||||
)}
|
||||
</div>
|
||||
</StyledListboxOptions>
|
||||
</Transition>,
|
||||
topDiv,
|
||||
)}
|
||||
</div>
|
||||
</StyledListbox>
|
||||
)}
|
||||
|
||||
{/* Settings button (either opens config.json or /settings page in control plane) */}
|
||||
<HeaderButtonWithText
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue