myagent-ai 1.23.55 → 1.23.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* ── admin-core.js — Shared infrastructure (loaded FIRST) ── */
|
|
2
2
|
|
|
3
3
|
const API='';
|
|
4
|
-
const pages={dashboard:'📊 仪表盘',agents:'🤖 Agent 管理',platforms:'🌐 聊天平台',organization:'🏢 组织管理',departments:'🏛 部门管理',sessions:'💬 会话管理',memory:'🧠 记忆管理',permissions:'🔑 权限管理',llm:'🧬 大模型设置',system:'⚙️ 系统配置',executor:'🔧 执行引擎',skills:'🛠 技能管理',files:'📁 工作目录',logs:'📜 查看日志',tasks:'📌 任务记录'};
|
|
4
|
+
const pages={dashboard:'📊 仪表盘',agents:'🤖 Agent 管理',platforms:'🌐 聊天平台',organization:'🏢 组织管理',departments:'🏛 部门管理',agentchat:'🔒 Agent私聊',sessions:'💬 会话管理',memory:'🧠 记忆管理',permissions:'🔑 权限管理',llm:'🧬 大模型设置',system:'⚙️ 系统配置',executor:'🔧 执行引擎',skills:'🛠 技能管理',files:'📁 工作目录',logs:'📜 查看日志',tasks:'📌 任务记录'};
|
|
5
5
|
let currentPage='dashboard';
|
|
6
6
|
let allAgentsCache=[];
|
|
7
7
|
let allModelsCache=[];
|
|
@@ -119,7 +119,8 @@ function showPage(page, addHistory){
|
|
|
119
119
|
closeMobileSidebar();
|
|
120
120
|
currentPage=page;
|
|
121
121
|
$('content').setAttribute('data-page',page);
|
|
122
|
-
|
|
122
|
+
// [v1.23.56] 使用 onclick 属性匹配页面,而非索引(避免 DOM 与 pages 对象顺序不一致)
|
|
123
|
+
document.querySelectorAll('.nav-item').forEach(n=>n.classList.toggle('active',n.getAttribute('onclick','').includes("'"+page+"'")));
|
|
123
124
|
$('pageTitle').textContent=pages[page]||page;
|
|
124
125
|
const renderers=window._adminRenderers||{};
|
|
125
126
|
if(renderers[page]){
|
|
@@ -149,7 +150,8 @@ function navigateTo(page, sub, renderFn){
|
|
|
149
150
|
var hash=page+(sub?'~'+sub:'');
|
|
150
151
|
history.pushState({page:page,sub:sub},'','#'+hash);
|
|
151
152
|
// 更新导航高亮
|
|
152
|
-
|
|
153
|
+
// [v1.23.56] 使用 onclick 属性匹配
|
|
154
|
+
document.querySelectorAll('.nav-item').forEach(n=>n.classList.toggle('active',n.getAttribute('onclick','').includes("'"+page+"'")));
|
|
153
155
|
// 渲染页面
|
|
154
156
|
if(renderFn){
|
|
155
157
|
try{renderFn();}catch(e){console.error('Navigate render error:',e);}
|
|
@@ -168,7 +170,9 @@ function goBack(){
|
|
|
168
170
|
if(renderers[prev.page]){
|
|
169
171
|
try{renderers[prev.page]();}catch(e){}
|
|
170
172
|
}
|
|
171
|
-
|
|
173
|
+
// [v1.23.56] 使用 onclick 属性匹配
|
|
174
|
+
document.querySelectorAll('.nav-item').forEach(n=>n.classList.toggle('active',n.getAttribute('onclick','').includes("'"+prev.page+"'")));
|
|
175
|
+
|
|
172
176
|
}else{
|
|
173
177
|
// 没有内部历史,尝试浏览器后退
|
|
174
178
|
history.back();
|
|
@@ -181,7 +185,9 @@ window.addEventListener('popstate',function(e){
|
|
|
181
185
|
if(s&&s.page){
|
|
182
186
|
currentPage=s.page;
|
|
183
187
|
_navSubState=s.sub||null;
|
|
184
|
-
|
|
188
|
+
// [v1.23.56] 使用 onclick 属性匹配
|
|
189
|
+
document.querySelectorAll('.nav-item').forEach(n=>n.classList.toggle('active',n.getAttribute('onclick','').includes("'"+s.page+"'")));
|
|
190
|
+
|
|
185
191
|
var renderers=window._adminRenderers||{};
|
|
186
192
|
if(renderers[s.page]){
|
|
187
193
|
try{renderers[s.page]();}catch(e){}
|
|
@@ -13,18 +13,32 @@ async function renderPlatforms(){
|
|
|
13
13
|
const displayName=p.display_name||(icons[p.platform]||'📡')+' '+p.platform;
|
|
14
14
|
const bindInfo=p.bind_agent?'绑定: '+escHtml(p.bind_agent):(p.bind_agents&&p.bind_agents.length?'绑定: '+p.bind_agents.map(a=>escHtml(a)).join(', '):'');
|
|
15
15
|
const _supportsQR=['telegram','wechat','whatsapp'].includes(p.platform);
|
|
16
|
+
const _isEnabled=!!p.enabled;
|
|
17
|
+
const _btnClass=_isEnabled?'btn-danger':'btn-success';
|
|
18
|
+
const _btnText=_isEnabled?'停用':'启用';
|
|
19
|
+
const _newState=!_isEnabled;
|
|
20
|
+
// [v1.23.56] 使用 data 属性避免 onclick 中特殊字符问题
|
|
16
21
|
html+=`<div class="card"><div class="flex justify-between items-center">
|
|
17
22
|
<h3 style="color:var(--text)">${icons[p.platform]||'📡'} ${escHtml(p.display_name||p.platform)}</h3>
|
|
18
23
|
<span class="badge ${p.enabled?'badge-green':'badge-red'}">${p.enabled?'已启用':'未启用'}</span>
|
|
19
24
|
</div><p style="font-size:13px;color:var(--text2);margin-top:8px">Token: ${p.token?'已配置':'未配置'} ${p.app_id?'· App ID: '+escHtml(p.app_id):''}</p>
|
|
20
25
|
${bindInfo?'<p style="font-size:12px;color:var(--text3);margin-top:4px">'+bindInfo+'</p>':''}
|
|
21
26
|
<div class="mt-8 flex gap-8">
|
|
22
|
-
<button class="btn btn-sm ${
|
|
27
|
+
<button class="btn btn-sm ${_btnClass}" data-toggle-platform="${escHtml(pid)}" data-toggle-state="${_newState}">${_btnText}</button>
|
|
23
28
|
<button class="btn btn-sm btn-ghost" onclick="showEditPlatformModal('${escHtml(pid)}')">配置</button>
|
|
24
29
|
${_supportsQR?'<button class="btn btn-sm btn-primary" onclick="showPlatformQRModal(\''+escHtml(pid)+'\')">📱 QR绑定</button>':''}
|
|
25
30
|
</div></div>`;
|
|
26
31
|
}
|
|
27
32
|
html+='</div>';$('content').innerHTML=html;
|
|
33
|
+
// [v1.23.56] 使用事件委托处理启用/停用按钮,避免 onclick 中特殊字符导致 JS 错误
|
|
34
|
+
$('content').addEventListener('click',function _platformToggleHandler(e){
|
|
35
|
+
var btn=e.target.closest('[data-toggle-platform]');
|
|
36
|
+
if(!btn)return;
|
|
37
|
+
var id=btn.getAttribute('data-toggle-platform');
|
|
38
|
+
var state=btn.getAttribute('data-toggle-state')==='true';
|
|
39
|
+
togglePlatform(id,state);
|
|
40
|
+
e.stopPropagation();
|
|
41
|
+
});
|
|
28
42
|
}
|
|
29
43
|
async function togglePlatform(id,enable){
|
|
30
44
|
try{
|
|
@@ -161,8 +175,12 @@ async function requestNewQR(platformId){
|
|
|
161
175
|
}
|
|
162
176
|
|
|
163
177
|
// Agent 选择器(从部门树选择 Agent)
|
|
178
|
+
// [v1.23.56] 修复: 不再覆盖 modalContainer,而是保存/恢复编辑表单 HTML
|
|
179
|
+
var _savedEditModalHtml='';
|
|
164
180
|
async function showAgentSelectorForPlatform(inputId,containerId){
|
|
165
181
|
try{
|
|
182
|
+
// 保存当前编辑表单 HTML
|
|
183
|
+
_savedEditModalHtml=$('modalContainer').innerHTML;
|
|
166
184
|
var agents=await api('/api/agents');
|
|
167
185
|
if(!Array.isArray(agents)){showToast('加载 Agent 列表失败','danger');return}
|
|
168
186
|
var agentList=agents.filter(function(a){return!a.system&&a.path!=='default'});
|
|
@@ -172,28 +190,38 @@ async function showAgentSelectorForPlatform(inputId,containerId){
|
|
|
172
190
|
if(!deptMap[dept])deptMap[dept]=[];
|
|
173
191
|
deptMap[dept].push(a);
|
|
174
192
|
});
|
|
175
|
-
var html='<div class="modal-overlay"
|
|
193
|
+
var html='<div class="modal-overlay"><div class="modal" onclick="event.stopPropagation()" style="max-width:480px;max-height:70vh;overflow-y:auto">';
|
|
176
194
|
html+='<h3>选择 Agent</h3>';
|
|
177
195
|
for(var dept in deptMap){
|
|
178
196
|
html+='<div style="margin-bottom:12px"><div style="font-size:13px;font-weight:600;color:var(--text2);margin-bottom:4px">📁 '+escHtml(dept)+'</div>';
|
|
179
197
|
deptMap[dept].forEach(function(a){
|
|
180
198
|
var selected=false;
|
|
181
|
-
|
|
182
|
-
|
|
199
|
+
if(_savedEditModalHtml){
|
|
200
|
+
// 从保存的编辑表单中查找已选中的 agent
|
|
201
|
+
var tmp=document.createElement('div');
|
|
202
|
+
tmp.innerHTML=_savedEditModalHtml;
|
|
203
|
+
var existing=tmp.querySelectorAll('#'+containerId+' .selected-agent-tag');
|
|
204
|
+
existing.forEach(function(el){if(el.getAttribute('data-agent')===a.path)selected=true;});
|
|
205
|
+
}
|
|
183
206
|
html+='<label style="display:flex;align-items:center;gap:8px;padding:4px 0;cursor:pointer;font-size:13px"><input type="checkbox" value="'+escHtml(a.path)+'" '+(selected?'checked':'')+' onchange="toggleAgentSelection(this,\''+inputId+'\',\''+containerId+'\')"> '+(a.avatar_emoji||'🤖')+' '+escHtml(a.name)+' <span style="color:var(--text3);font-size:11px">('+escHtml(a.path)+')</span></label>';
|
|
184
207
|
});
|
|
185
208
|
html+='</div>';
|
|
186
209
|
}
|
|
187
|
-
html+='<div class="flex gap-8 mt-16"><button class="btn btn-primary" onclick="
|
|
210
|
+
html+='<div class="flex gap-8 mt-16"><button class="btn btn-primary" onclick="confirmAgentSelection(\''+inputId+'\',\''+containerId+'\')">确定</button><button class="btn btn-ghost" onclick="cancelAgentSelection()">取消</button></div></div></div>';
|
|
188
211
|
$('modalContainer').innerHTML=html;
|
|
189
212
|
}catch(e){showToast('加载失败: '+e.message,'danger')}
|
|
190
213
|
}
|
|
191
|
-
function
|
|
192
|
-
|
|
214
|
+
function confirmAgentSelection(inputId,containerId){
|
|
215
|
+
// 收集选中的 agent 列表
|
|
216
|
+
var checked=[];
|
|
217
|
+
document.querySelectorAll('.modal input[type="checkbox"]:checked').forEach(function(cb){checked.push(cb.value);});
|
|
218
|
+
// 恢复编辑表单
|
|
219
|
+
if(_savedEditModalHtml){$('modalContainer').innerHTML=_savedEditModalHtml;_savedEditModalHtml='';}
|
|
220
|
+
// 更新编辑表单中的 agent 标签
|
|
193
221
|
var container=document.getElementById(containerId);
|
|
194
|
-
if(
|
|
195
|
-
|
|
196
|
-
|
|
222
|
+
if(container){
|
|
223
|
+
container.innerHTML='';
|
|
224
|
+
checked.forEach(function(agentPath){
|
|
197
225
|
var tag=document.createElement('span');
|
|
198
226
|
tag.className='selected-agent-tag';
|
|
199
227
|
tag.setAttribute('data-agent',agentPath);
|
|
@@ -202,16 +230,19 @@ function toggleAgentSelection(cb,inputId,containerId){
|
|
|
202
230
|
tag.textContent=agentPath+' ×';
|
|
203
231
|
tag.onclick=function(){this.remove();};
|
|
204
232
|
container.appendChild(tag);
|
|
205
|
-
}
|
|
206
|
-
// 同步到输入框
|
|
207
|
-
var first=container.querySelector('.selected-agent-tag');
|
|
208
|
-
if(first)document.getElementById(inputId).value=first.getAttribute('data-agent');
|
|
209
|
-
}else{
|
|
210
|
-
var existing=container.querySelector('[data-agent="'+agentPath+'"]');
|
|
211
|
-
if(existing)existing.remove();
|
|
212
|
-
var first=container.querySelector('.selected-agent-tag');
|
|
213
|
-
document.getElementById(inputId).value=first?first.getAttribute('data-agent'):'';
|
|
233
|
+
});
|
|
214
234
|
}
|
|
235
|
+
// 同步第一个到输入框
|
|
236
|
+
var input=document.getElementById(inputId);
|
|
237
|
+
if(input){input.value=checked[0]||'';}
|
|
238
|
+
}
|
|
239
|
+
function cancelAgentSelection(){
|
|
240
|
+
// 恢复编辑表单
|
|
241
|
+
if(_savedEditModalHtml){$('modalContainer').innerHTML=_savedEditModalHtml;_savedEditModalHtml='';}
|
|
242
|
+
}
|
|
243
|
+
function toggleAgentSelection(cb,inputId,containerId){
|
|
244
|
+
// 在 Agent 选择器内部,仅切换 checkbox 状态(不做 DOM 操作)
|
|
245
|
+
// 实际的 tag 更新在 confirmAgentSelection 中统一处理
|
|
215
246
|
}
|
|
216
247
|
|
|
217
248
|
if (typeof window._adminRenderers === 'undefined') window._adminRenderers = {};
|