function call can be expire
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
|
||||
var socket;
|
||||
let system_message_idx = 0
|
||||
const activeApprovals = {};
|
||||
// 清理过期的批准记录
|
||||
function cleanupExpiredApprovals() {
|
||||
const now = Date.now();
|
||||
for (const name in activeApprovals) {
|
||||
if (now - activeApprovals[name] > 30000) { // 30秒过期
|
||||
delete activeApprovals[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 定时清理过期记录
|
||||
setInterval(cleanupExpiredApprovals, 3000); // 每3秒检查一次
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
data = window.appData;
|
||||
const host = window.location.host;
|
||||
@@ -52,14 +65,32 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
if (typeof data === 'object') {
|
||||
data = [data];
|
||||
}
|
||||
cleanupExpiredApprovals();// 先清理一次过期记录
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const element = data[i];
|
||||
const funcName = element.data.name;
|
||||
|
||||
if (activeApprovals.hasOwnProperty(funcName)) {
|
||||
// 如果存在,找到并移除之前的元素
|
||||
const existingElements = document.querySelectorAll(`.approve-message[data-function="${funcName}"]`);
|
||||
existingElements.forEach(el => el.remove());
|
||||
}
|
||||
activeApprovals[funcName] = Date.now();
|
||||
|
||||
const requestMessage = document.createElement('div');
|
||||
requestMessage.className = 'chat-message server-message approve-message';
|
||||
requestMessage.setAttribute('data-function', funcName);
|
||||
|
||||
const description = document.createElement('div');
|
||||
description.innerHTML = `<b>Function:</b> ${element.data.name}(${JSON.stringify(element.data.args)})`;
|
||||
const argsDescription = JSON.stringify(element.data.args);
|
||||
if (argsDescription) {
|
||||
description.innerHTML = `<b>Function:</b> ${element.data.name}(${argsDescription})`;
|
||||
}else {
|
||||
description.innerHTML = `<b>Function:</b> ${element.data.name}()`;
|
||||
}
|
||||
|
||||
const approveButton = document.createElement('button');
|
||||
approveButton.innerHTML = '√'; // 使用勾选符号
|
||||
approveButton.innerHTML = '<i class="fas fa-check-circle-check"></i>';
|
||||
approveButton.data = element;
|
||||
approveButton.className = 'approve-button';
|
||||
approveButton.onclick = function (event) {
|
||||
|
||||
Reference in New Issue
Block a user