Skip to content

Commit

Permalink
update config fetch and default config read
Browse files Browse the repository at this point in the history
  • Loading branch information
tyaginidhi committed May 2, 2024
1 parent ed81fce commit d9f30aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
12 changes: 3 additions & 9 deletions src/common/copilot/PowerPagesCopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IActiveFileParams, IActiveFileData, IOrgInfo } from './model';
import { escapeDollarSign, getLastThreePartsOfFileName, getNonce, getSelectedCode, getSelectedCodeLineRange, getUserName, openWalkthrough, showConnectedOrgMessage, showInputBoxAndGetOrgUrl, showProgressWithNotification } from "../Utils";
import { CESUserFeedback } from "./user-feedback/CESSurvey";
import { ActiveOrgOutput } from "../../client/pac/PacTypes";
import { CopilotWalkthroughEvent, CopilotCopyCodeToClipboardEvent, CopilotInsertCodeToEditorEvent, CopilotLoadedEvent, CopilotOrgChangedEvent, CopilotUserFeedbackThumbsDownEvent, CopilotUserFeedbackThumbsUpEvent, CopilotUserPromptedEvent, CopilotCodeLineCountEvent, CopilotClearChatEvent, CopilotNotAvailable, CopilotExplainCode, CopilotExplainCodeSize } from "./telemetry/telemetryConstants";
import { CopilotWalkthroughEvent, CopilotCopyCodeToClipboardEvent, CopilotInsertCodeToEditorEvent, CopilotLoadedEvent, CopilotOrgChangedEvent, CopilotUserFeedbackThumbsDownEvent, CopilotUserFeedbackThumbsUpEvent, CopilotUserPromptedEvent, CopilotCodeLineCountEvent, CopilotClearChatEvent, CopilotNotAvailable, CopilotExplainCode, CopilotExplainCodeSize, CopilotNotAvailableECSConfig } from "./telemetry/telemetryConstants";
import { sendTelemetryEvent } from "./telemetry/copilotTelemetry";
import { INTELLIGENCE_SCOPE_DEFAULT, PROVIDER_ID } from "../../web/client/common/constants";
import { getIntelligenceEndpoint } from "../ArtemisService";
Expand Down Expand Up @@ -212,13 +212,11 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {
value: copilotStrings
});

console.log("copilot orgs 1", getDisabledOrgList(), orgID, tenantId, getDisabledTenantList());
if (this.aibEndpoint === COPILOT_UNAVAILABLE) {
this.sendMessageToWebview({ type: 'Unavailable' });
return;
} else if (getDisabledOrgList()?.includes(orgID) || getDisabledTenantList()?.includes(tenantId ?? "")) {
console.log("copilot not available");
sendTelemetryEvent(this.telemetry, { eventName: CopilotNotAvailable, copilotSessionId: sessionID, orgId: orgID });
sendTelemetryEvent(this.telemetry, { eventName: CopilotNotAvailableECSConfig, copilotSessionId: sessionID, orgId: orgID });
this.sendMessageToWebview({ type: 'Unavailable' });
return;
}
Expand Down Expand Up @@ -412,16 +410,12 @@ export class PowerPagesCopilot implements vscode.WebviewViewProvider {
this.aibEndpoint = intelligenceEndpoint;
this.geoName = geoName;

console.log("copilot orgs 2", getDisabledOrgList(), orgID, tenantId, getDisabledTenantList());
if (this.aibEndpoint === COPILOT_UNAVAILABLE) {
sendTelemetryEvent(this.telemetry, { eventName: CopilotNotAvailable, copilotSessionId: sessionID, orgId: orgID });
this.sendMessageToWebview({ type: 'Unavailable' });
return;
} else if (getDisabledOrgList()?.includes(orgID) || getDisabledTenantList()?.includes(tenantId ?? "")) {
console.log("copilot not available");
sendTelemetryEvent(this.telemetry, { eventName: CopilotNotAvailable, copilotSessionId: sessionID, orgId: orgID });
sendTelemetryEvent(this.telemetry, { eventName: CopilotNotAvailableECSConfig, copilotSessionId: sessionID, orgId: orgID });
this.sendMessageToWebview({ type: 'Unavailable' });
return;
}
else {
this.sendMessageToWebview({ type: 'Available' });
Expand Down
7 changes: 3 additions & 4 deletions src/common/copilot/utils/copilotUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import { ECSFeaturesClient } from "../../ecs-features/ecsFeatureClient";
import { CopilotDisableList } from "../../ecs-features/ecsFeatureGates";

export function getDisabledOrgList() {
console.log("copilot orgs", CopilotDisableList.getConfig().disallowedProDevCopilotOrgs);
return CopilotDisableList.getConfig().disallowedProDevCopilotOrgs?.split(',');
return ECSFeaturesClient.getConfig(CopilotDisableList).disallowedProDevCopilotOrgs?.split(',').map(org => org.trim());
}

export function getDisabledTenantList() {
console.log("Copilot tenant", CopilotDisableList.getConfig().disallowedProDevCopilotTenants);
return CopilotDisableList.getConfig().disallowedProDevCopilotTenants?.split(',');
return ECSFeaturesClient.getConfig(CopilotDisableList).disallowedProDevCopilotTenants?.split(',').map(tenant => tenant.trim());
}
8 changes: 2 additions & 6 deletions src/common/ecs-features/ecsFeatureClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ECSAPIFeatureFlagFilters } from "./ecsFeatureFlagFilters";

export abstract class ECSFeaturesClient {
private static _ecsConfig: Record<string, string | boolean>;
private static _featuresConfig = {};

// Initialize ECSFeatureClient - any client config can be fetched with utility function like below
// EnableMultifileVscodeWeb.getConfig().enableMultifileVscodeWeb
Expand Down Expand Up @@ -41,10 +40,7 @@ export abstract class ECSFeaturesClient {
public static getConfig<TConfig extends Record<string, boolean | string>, TeamName extends string>(
feature: ECSFeatureProperties<TConfig, TeamName>
) {
if (Object.keys(this._featuresConfig).length === 0) {
this._featuresConfig = this._ecsConfig && feature.extractECSFeatureFlagConfig?.(this._ecsConfig as TConfig);
}

return Object.keys(this._featuresConfig).length === 0 ? feature.fallback : this._featuresConfig;
const featuresConfig = this._ecsConfig && feature.extractECSFeatureFlagConfig?.(this._ecsConfig as TConfig);
return { ...feature.fallback, ...featuresConfig };
}
}

0 comments on commit d9f30aa

Please sign in to comment.