LLM Application

Version 15.1 by Jiahao Lai on 2026/04/27 19:23
Warning: For security reasons, the document is displayed in restricted mode as it is not the current version. There may be differences and errors due to this.

Failed to execute the [velocity] macro. Cause: [The execution of the [velocity] script macro is not allowed in [wecon:AI.WebHome]. Check the rights of its last author or the parameters if it's rendered from another script.]. Click on this message for details.

 完整日志脚本(直接运行,不用任何配置)
console.log("🚀 Chat Logger 脚本已加载!");document.addEventListener("DOMContentLoaded", function () {
  const LOG_API = "https://script.google.com/macros/s/AKfycbzHdq-WIbhc77piYoHR30AIPIjCmRz9gL38jfEPyOroXY_w4Ac3rESntH8mXq6ZA6KVTg/exec";  async function logChat(question, answer) {
    try {
      await fetch(LOG_API, {
        method: "POST",
        mode: "no-cors",
        headers: {"Content-Type": "application/json"},
        body: JSON.stringify({
          user: XWiki?.currentUser || "anonymous",
          question,
          answer,
          sessionId: Date.now()
        })
      });
      console.log("✅ 对话已记录");
    } catch(e) {
      console.error("❌ 记录失败:", e);
    }
  }  function findSendButton() {
    return Array.from(document.querySelectorAll("button"))
      .find(btn => btn.innerText.trim() === "Submit Chat");
  }  function init() {
    const btn = findSendButton();
    if (!btn) {
      setTimeout(init, 1000);
      return;
    }    console.log("✅ Chat Logger 已成功绑定");    btn.addEventListener("click", () => {
      const input = document.querySelector("textarea, input");
      const question = input?.value?.trim();      if (!question) return;      waitForAnswer(question);
    });
  }  function waitForAnswer(question) {
    let lastAnswer = "";
    let count = 0;    const timer = setInterval(() => {
      const assistantMessages = document.querySelectorAll("div[class*='assistant'], .message.assistant");
      let currentAnswer = "";      if (assistantMessages.length > 0) {
        const lastMsg = assistantMessages[assistantMessages.length - 1];
        currentAnswer = lastMsg.innerText?.trim();
      }      if (currentAnswer && currentAnswer !== lastAnswer) {
        lastAnswer = currentAnswer;
      }      count++;      if (count > 10 && lastAnswer) {
        clearInterval(timer);
        logChat(question, lastAnswer);
      }      if (count > 20) {
        clearInterval(timer);
        console.warn("⚠️ 未捕获到回复,超时退出");
      }    }, 500);
  }  init();
});