Repository: sunner/ChatALL
File: src/bots/ChatGLMBot.js (JavaScript)

Code before:
  // Remove Electron from the user agent to avoid blank login screen
  static _userAgent =
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) chatall/1.29.40 Chrome/114.0.5735.134 Safari/537.36";
  _glmLogin = "https://chatglm.cn/chatglm/backend-api/v1/user/login";
  _glmLogout = "https://chatglm.cn/chatglm/backend-api/v1/user/logout";
  _glmRefreshToken = "https://chatglm.cn/chatglm/backend-api/v1/user/refresh";

  constructor() {
    super();
  }

  getAuthHeader() {
    return {
      headers: {
        Authorization: `Bearer ${store.state.chatglm?.token}`,
      },
    };
  }

  /**
   * Check whether the bot is logged in, settings are correct, etc.
   * @returns {boolean} - true if the bot is available, false otherwise.
   */
  async _checkAvailability() {
    let available = false;
    let _glmUserInfo = "https://chatglm.cn/chatglm/backend-api/v3/user/info";
    const context = await this.getChatContext();
    await axios
      .get(_glmUserInfo, this.getAuthHeader())
      .then((response) => {
        available = response.data?.message == "success";
        this.setChatContext({
          ...context,
          user_id: response.data?.result._id,
        });
      })
      .catch((error) => {
        console.error("Error checking ChatGLM login status:", error);
      });

    return available;
  }

  /**
   * Send a prompt to the bot and call onResponse(response, callbackParam)
   * when the response is ready.
   * @param {string} prompt
   * @param {function} onUpdateResponse params: callbackParam, Object {content, done}
   * @param {object} callbackParam - Just pass it to onUpdateResponse() as is
   */
  async _sendPrompt(prompt, onUpdateResponse, callbackParam) {

Review comment (suggestion):
```suggestion
    let userInfoUrl = "https://chatglm.cn/chatglm/backend-api/v3/user/info";
```

Code after:

  constructor() {
    super();
  }

  getAuthHeader() {
    return {
      headers: {
        Authorization: `Bearer ${store.state.chatGlm?.token}`,
      },
    };
  }

  /**
   * Check whether the bot is logged in, settings are correct, etc.
   * @returns {boolean} - true if the bot is available, false otherwise.
   */
  async _checkAvailability() {
    let available = false;
    let userInfoUrl = "https://chatglm.cn/chatglm/backend-api/v3/user/info";
    const context = await this.getChatContext();
    await axios
      .get(userInfoUrl, this.getAuthHeader())
      .then((response) => {
        available = response.data?.message == "success";
        this.setChatContext({
          ...context,
          user_id: response.data?.result._id,
        });
      })
      .catch((error) => {
        console.error("Error checking ChatGLM login status:", error);
      });

    return available;
  }

  /**
   * Send a prompt to the bot and call onResponse(response, callbackParam)
   * when the response is ready.
   * @param {string} prompt
   * @param {function} onUpdateResponse params: callbackParam, Object {content, done}
   * @param {object} callbackParam - Just pass it to onUpdateResponse() as is
   */
  async _sendPrompt(prompt, onUpdateResponse, callbackParam) {
    let context = await this.getChatContext();
    if (context.user_id == null || context.user_id == undefined) {
      await this._checkAvailability();
      context = await this.getChatContext();
    }
    const uuid = uuidv4();