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

Code before:
  _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) {
    let context = await this.getChatContext();
    if (context.user_id == null || context.user_id == undefined) {
      await this._checkAvailability();

Review comment (security):
```suggestion
      .get(userInfoUrl, this.getAuthHeader())
```

Code after:
  }

  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();
    const streamContext = await axios.post(
      `https://chatglm.cn/chatglm/backend-api/v1/stream_context?__requestid=${uuid}`,
      {