Repository: TabbyML/tabby
File: clients/vscode/src/Config.ts (TypeScript)

Code before:

  async updateServerEndpoint(value: string) {
    if (value !== this.serverEndpoint) {
      await this.workspace.update("endpoint", value, ConfigurationTarget.Global);
    }
  }

  get serverRecords(): ServerRecords {
    const records = this.memento.get("server.serverRecords", {});
    return new Map(Object.entries(records));
  }

  async updateServerRecords(value: ServerRecords) {
    const obj: Record<string, ServerRecordValue> = {};
    value.forEach((v, k) => {
      obj[k] = v;
    });
    await this.memento.update("server.serverRecords", obj);
    this.emit("updated");
  }

  private get approvedTokenRequestIds(): string[] {
    return this.memento.get("token.approvedRequestIds", []);
  }

  private async updateApprovedTokenRequestIds(ids: string[]) {
    await this.memento.update("token.approvedRequestIds", ids);
  }

  async clearApprovedTokenRequestIds() {
    await this.updateApprovedTokenRequestIds([]);
  }

  async addApprovedTokenRequestId(id: string) {
    const ids = this.approvedTokenRequestIds;
    if (!ids.includes(id)) {
      ids.push(id);
      await this.updateApprovedTokenRequestIds(ids);
    }
  }

  isTokenRequestApproved(id: string): boolean {
    return this.approvedTokenRequestIds.includes(id);
  }

  private async migrateServerRecordFromPastServerConfigs() {
    const pastServerConfigs = this.memento.get("server.pastServerConfigs", []);
    if (pastServerConfigs.length > 0) {
      await this.updateServerRecords(
        pastServerConfigs.reduce((acc: ServerRecords, config) => {
          acc.set(config["endpoint"], {

Review comment (security):
```suggestion
  private async updateAuthenticationTokenRequestIds(ids: string[]) {
```

Code after:

  async updateServerEndpoint(value: string) {
    if (value !== this.serverEndpoint) {
      await this.workspace.update("endpoint", value, ConfigurationTarget.Global);
    }
  }

  get serverRecords(): ServerRecords {
    const records = this.memento.get("server.serverRecords", {});
    return new Map(Object.entries(records));
  }

  async updateServerRecords(value: ServerRecords) {
    const obj: Record<string, ServerRecordValue> = {};
    value.forEach((v, k) => {
      obj[k] = v;
    });
    await this.memento.update("server.serverRecords", obj);
    this.emit("updated");
  }

  private async migrateServerRecordFromPastServerConfigs() {
    const pastServerConfigs = this.memento.get("server.pastServerConfigs", []);
    if (pastServerConfigs.length > 0) {
      await this.updateServerRecords(
        pastServerConfigs.reduce((acc: ServerRecords, config) => {
          acc.set(config["endpoint"], {
            token: config["token"],
            updatedAt: Date.now(),
          });
          return acc;
        }, this.serverRecords),
      );
      this.memento.update("server.pastServerConfigs", undefined);
    }
  }

  get inlineCompletionTriggerMode(): "automatic" | "manual" {
    const advancedSettings = this.workspace.get("settings.advanced", {}) as AdvancedSettings;
    return advancedSettings["inlineCompletion.triggerMode"] || "automatic";
  }

  async updateInlineCompletionTriggerMode(value: "automatic" | "manual") {
    if (value !== this.inlineCompletionTriggerMode) {
      const advancedSettings = this.workspace.get("settings.advanced", {}) as AdvancedSettings;
      advancedSettings["inlineCompletion.triggerMode"] = value;
      await this.workspace.update("settings.advanced", advancedSettings, ConfigurationTarget.Global);
    }
  }

  get useVSCodeProxy(): boolean {