acp-ts 1.2.3 → 1.2.4
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/dist/agentcp.js +40 -36
- package/dist/agentws.d.ts +8 -2
- package/dist/agentws.js +22 -4
- package/dist/api.js +8 -8
- package/dist/cert.js +3 -2
- package/dist/cli.js +16 -15
- package/dist/datamanager.js +27 -11
- package/dist/filesync.js +11 -10
- package/dist/group/client.js +44 -36
- package/dist/group/cursor_store.d.ts +4 -9
- package/dist/group/cursor_store.js +12 -40
- package/dist/group/events.d.ts +2 -2
- package/dist/group/events.js +7 -27
- package/dist/group/index.d.ts +1 -1
- package/dist/group/index.js +2 -2
- package/dist/group/message_store.d.ts +5 -6
- package/dist/group/message_store.js +64 -72
- package/dist/group/operations.d.ts +1 -5
- package/dist/group/operations.js +5 -12
- package/dist/group/types.d.ts +3 -29
- package/dist/group/types.js +2 -6
- package/dist/heartbeat.js +24 -24
- package/dist/messagestore.js +9 -8
- package/dist/server.js +2053 -1699
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +19 -2
- package/dist/websocket.d.ts +12 -1
- package/dist/websocket.js +61 -28
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -50,6 +50,7 @@ const heartbeat_1 = require("./heartbeat");
|
|
|
50
50
|
const cert_1 = require("./cert");
|
|
51
51
|
const group_1 = require("./group");
|
|
52
52
|
const messagestore_1 = require("./messagestore");
|
|
53
|
+
const utils_1 = require("./utils");
|
|
53
54
|
let globalApiUrl = '';
|
|
54
55
|
let globalDataDir = '';
|
|
55
56
|
const messageStores = new Map();
|
|
@@ -70,11 +71,19 @@ function pushToAid(aid, data) {
|
|
|
70
71
|
*/
|
|
71
72
|
function broadcastToBrowser(data) {
|
|
72
73
|
const payload = JSON.stringify(data);
|
|
73
|
-
|
|
74
|
+
let sentCount = 0;
|
|
75
|
+
for (const [ws, client] of browserWsClients) {
|
|
74
76
|
if (ws.readyState === ws_1.default.OPEN) {
|
|
75
77
|
ws.send(payload);
|
|
78
|
+
sentCount++;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
utils_1.logger.warn(`[broadcastToBrowser] skip ws client (readyState=${ws.readyState}, aid=${client.aid})`);
|
|
76
82
|
}
|
|
77
83
|
}
|
|
84
|
+
if (data.type === 'group_message_batch' || data.type === 'new_message_notify') {
|
|
85
|
+
utils_1.logger.log(`[broadcastToBrowser] type=${data.type} group=${data.group_id} sentTo=${sentCount}/${browserWsClients.size} clients`);
|
|
86
|
+
}
|
|
78
87
|
}
|
|
79
88
|
let agentCP = null;
|
|
80
89
|
const MAX_AIDS = 10;
|
|
@@ -115,7 +124,7 @@ async function doEnsureOnline(aid) {
|
|
|
115
124
|
const customOpts = getAidMdOptionsForAid(aid);
|
|
116
125
|
cp.setAgentMdOptions(Object.assign({ type: 'human', tags: ['human', 'acp'] }, customOpts));
|
|
117
126
|
const connConfig = await cp.online();
|
|
118
|
-
|
|
127
|
+
utils_1.logger.log(`[Server] 自动上线 AID: ${aid}`);
|
|
119
128
|
const hb = new heartbeat_1.HeartbeatClient(aid, connConfig.heartbeatServer, '');
|
|
120
129
|
const ws = new agentws_1.AgentWS(aid, connConfig.messageServer, connConfig.messageSignature);
|
|
121
130
|
const instance = {
|
|
@@ -135,7 +144,7 @@ async function doEnsureOnline(aid) {
|
|
|
135
144
|
};
|
|
136
145
|
aidInstances.set(aid, instance);
|
|
137
146
|
hb.onInvite((invite) => {
|
|
138
|
-
|
|
147
|
+
utils_1.logger.log(`[Server] 收到邀请: ${JSON.stringify(invite)}`);
|
|
139
148
|
const session = getMessageStoreForAid(aid).getOrCreateSession(invite.sessionId, invite.inviteCode, invite.inviterAgentId, 'incoming', aid);
|
|
140
149
|
pushToAid(aid, { type: 'sessions_updated' });
|
|
141
150
|
if (instance.agentWS) {
|
|
@@ -145,28 +154,55 @@ async function doEnsureOnline(aid) {
|
|
|
145
154
|
// 心跳重连成功后,自动触发 WebSocket 重连 + 群组重新注册
|
|
146
155
|
hb.onReconnect(() => {
|
|
147
156
|
if (instance.agentWS) {
|
|
148
|
-
|
|
157
|
+
utils_1.logger.log('[Server] 心跳重连成功,触发 WebSocket 重连...');
|
|
149
158
|
instance.agentWS.reconnect().then(async () => {
|
|
150
159
|
// WebSocket 重连成功后,重新注册所有在线群组
|
|
151
160
|
// 断线期间 group.ap 会将在线状态过期,必须重新 register_online 才能收到推送
|
|
152
161
|
const onlineGroups = instance.agentCP.getOnlineGroups();
|
|
153
162
|
if (onlineGroups.length > 0) {
|
|
154
|
-
|
|
163
|
+
utils_1.logger.log(`[Server] WebSocket 重连成功,重新注册 ${onlineGroups.length} 个在线群组...`);
|
|
155
164
|
for (const groupId of onlineGroups) {
|
|
156
165
|
try {
|
|
157
166
|
await instance.agentCP.joinGroupSession(groupId);
|
|
158
|
-
|
|
167
|
+
utils_1.logger.log(`[Server] 群组重新注册成功: ${groupId}`);
|
|
159
168
|
}
|
|
160
169
|
catch (e) {
|
|
161
|
-
|
|
170
|
+
utils_1.logger.warn(`[Server] 群组重新注册失败: ${groupId}`, e.message || e);
|
|
162
171
|
}
|
|
163
172
|
}
|
|
164
173
|
}
|
|
165
174
|
}).catch((err) => {
|
|
166
|
-
|
|
175
|
+
utils_1.logger.error('[Server] WebSocket 重连失败:', err);
|
|
167
176
|
});
|
|
168
177
|
}
|
|
169
178
|
});
|
|
179
|
+
// WS 快速重试耗尽后,重新鉴权并用新 signature 重连
|
|
180
|
+
ws.onReconnectNeeded(async () => {
|
|
181
|
+
utils_1.logger.log('[Server] WS 快速重试耗尽,开始重新鉴权重连...');
|
|
182
|
+
try {
|
|
183
|
+
const newConnConfig = await cp.online();
|
|
184
|
+
instance.connectionConfig = newConnConfig;
|
|
185
|
+
utils_1.logger.log('[Server] 重新鉴权成功,使用新 signature 重连 WebSocket...');
|
|
186
|
+
await instance.agentWS.reconnect(newConnConfig.messageServer, newConnConfig.messageSignature);
|
|
187
|
+
// 重连成功后重新注册所有在线群组
|
|
188
|
+
const onlineGroups = instance.agentCP.getOnlineGroups();
|
|
189
|
+
if (onlineGroups.length > 0) {
|
|
190
|
+
utils_1.logger.log(`[Server] 重新鉴权重连成功,重新注册 ${onlineGroups.length} 个在线群组...`);
|
|
191
|
+
for (const groupId of onlineGroups) {
|
|
192
|
+
try {
|
|
193
|
+
await instance.agentCP.joinGroupSession(groupId);
|
|
194
|
+
utils_1.logger.log(`[Server] 群组重新注册成功: ${groupId}`);
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
utils_1.logger.warn(`[Server] 群组重新注册失败: ${groupId}`, e.message || e);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
utils_1.logger.error('[Server] 重新鉴权重连失败:', err);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
170
206
|
await hb.online();
|
|
171
207
|
ws.onMessage((message) => {
|
|
172
208
|
var _a;
|
|
@@ -240,10 +276,10 @@ async function doEnsureOnline(aid) {
|
|
|
240
276
|
// AID 上线后自动初始化群组功能,确保所有身份都能收到群消息推送
|
|
241
277
|
try {
|
|
242
278
|
await ensureGroupClient(instance);
|
|
243
|
-
|
|
279
|
+
utils_1.logger.log(`[Server] AID ${aid} 群组功能自动初始化完成`);
|
|
244
280
|
}
|
|
245
281
|
catch (e) {
|
|
246
|
-
|
|
282
|
+
utils_1.logger.warn(`[Server] AID ${aid} 群组功能自动初始化失败(不影响上线):`, e.message);
|
|
247
283
|
}
|
|
248
284
|
return instance;
|
|
249
285
|
}
|
|
@@ -283,7 +319,7 @@ async function ensureGroupClient(instance) {
|
|
|
283
319
|
// 注册群组事件处理器,确保 SDK 通知回调可靠触发
|
|
284
320
|
instance.agentCP.setGroupEventHandler({
|
|
285
321
|
onNewMessage(groupId, latestMsgId, sender, preview) {
|
|
286
|
-
|
|
322
|
+
utils_1.logger.log(`[Group] onNewMessage: group=${groupId} msgId=${latestMsgId} sender=${sender} preview=${preview}`);
|
|
287
323
|
// 通知浏览器有新消息(轻量通知,前端可据此决定是否刷新)
|
|
288
324
|
broadcastToBrowser({
|
|
289
325
|
type: 'new_message_notify',
|
|
@@ -294,7 +330,7 @@ async function ensureGroupClient(instance) {
|
|
|
294
330
|
});
|
|
295
331
|
},
|
|
296
332
|
onNewEvent(groupId, latestEventId, eventType, summary) {
|
|
297
|
-
|
|
333
|
+
utils_1.logger.log(`[Group] onNewEvent: group=${groupId} eventId=${latestEventId} type=${eventType} summary=${summary}`);
|
|
298
334
|
broadcastToBrowser({
|
|
299
335
|
type: 'new_event',
|
|
300
336
|
group_id: groupId,
|
|
@@ -304,7 +340,7 @@ async function ensureGroupClient(instance) {
|
|
|
304
340
|
});
|
|
305
341
|
},
|
|
306
342
|
onGroupInvite(groupId, groupAddress, invitedBy) {
|
|
307
|
-
|
|
343
|
+
utils_1.logger.log(`[Group] onGroupInvite: group=${groupId} address=${groupAddress} invitedBy=${invitedBy}`);
|
|
308
344
|
broadcastToBrowser({
|
|
309
345
|
type: 'group_invite',
|
|
310
346
|
group_id: groupId,
|
|
@@ -313,12 +349,12 @@ async function ensureGroupClient(instance) {
|
|
|
313
349
|
});
|
|
314
350
|
},
|
|
315
351
|
onJoinApproved(groupId, groupAddress) {
|
|
316
|
-
|
|
352
|
+
utils_1.logger.log(`[Group] onJoinApproved: group=${groupId} address=${groupAddress}`);
|
|
317
353
|
// 审核通过:获取群信息、添加本地存储、注册到 Home AP
|
|
318
354
|
(async () => {
|
|
319
355
|
try {
|
|
320
356
|
if (!instance.agentCP.groupOps) {
|
|
321
|
-
|
|
357
|
+
utils_1.logger.warn(`[Group] onJoinApproved skipped: groupOps not available`);
|
|
322
358
|
return;
|
|
323
359
|
}
|
|
324
360
|
let groupName = groupId;
|
|
@@ -332,7 +368,7 @@ async function ensureGroupClient(instance) {
|
|
|
332
368
|
await instance.agentCP.joinGroupSession(groupId);
|
|
333
369
|
}
|
|
334
370
|
catch (e) {
|
|
335
|
-
|
|
371
|
+
utils_1.logger.error(`[Group] onJoinApproved processing failed: group=${groupId}`, e.message);
|
|
336
372
|
}
|
|
337
373
|
})();
|
|
338
374
|
broadcastToBrowser({
|
|
@@ -342,46 +378,48 @@ async function ensureGroupClient(instance) {
|
|
|
342
378
|
});
|
|
343
379
|
},
|
|
344
380
|
onJoinRejected(groupId, reason) {
|
|
345
|
-
|
|
381
|
+
utils_1.logger.log(`[Group] onJoinRejected: group=${groupId} reason=${reason}`);
|
|
346
382
|
broadcastToBrowser({ type: 'join_rejected', group_id: groupId, reason });
|
|
347
383
|
},
|
|
348
384
|
onJoinRequestReceived(groupId, agentId, message) {
|
|
349
|
-
|
|
385
|
+
utils_1.logger.log(`[Group] onJoinRequestReceived: group=${groupId} agent=${agentId} msg=${message}`);
|
|
350
386
|
broadcastToBrowser({ type: 'join_request', group_id: groupId, agent_id: agentId, message });
|
|
351
387
|
},
|
|
352
388
|
onGroupMessageBatch(groupId, batch) {
|
|
353
|
-
|
|
389
|
+
utils_1.logger.log(`[Group] onGroupMessageBatch: group=${groupId} count=${batch.count} range=[${batch.start_msg_id}, ${batch.latest_msg_id}] messages=${JSON.stringify((batch.messages || []).map(m => m.msg_id))}`);
|
|
354
390
|
// 存储 + ACK(统一由 agentcp 处理),注意 processAndAckBatch 是 async
|
|
355
391
|
instance.agentCP.processAndAckBatch(groupId, batch).then((sorted) => {
|
|
392
|
+
var _a, _b;
|
|
393
|
+
utils_1.logger.log(`[Group] processAndAckBatch OK: group=${groupId} sortedCount=${sorted.length} msgIds=${sorted.map(m => m.msg_id)}`);
|
|
394
|
+
// 检查浏览器连接数
|
|
395
|
+
const connectedCount = Array.from(browserWsClients.entries()).filter(([ws]) => ws.readyState === ws_1.default.OPEN).length;
|
|
396
|
+
utils_1.logger.log(`[Group] broadcastToBrowser: group=${groupId} connectedBrowserClients=${connectedCount} totalClients=${browserWsClients.size}`);
|
|
397
|
+
if (connectedCount === 0) {
|
|
398
|
+
utils_1.logger.warn(`[Group] !!! 没有已连接的浏览器客户端,消息无法推送到前端!`);
|
|
399
|
+
}
|
|
356
400
|
// 推送消息列表给浏览器
|
|
357
|
-
|
|
401
|
+
const payload = {
|
|
358
402
|
type: 'group_message_batch',
|
|
359
403
|
group_id: groupId,
|
|
360
404
|
messages: sorted,
|
|
361
405
|
count: batch.count,
|
|
362
406
|
start_msg_id: batch.start_msg_id,
|
|
363
407
|
latest_msg_id: batch.latest_msg_id,
|
|
364
|
-
}
|
|
408
|
+
};
|
|
409
|
+
utils_1.logger.log(`[Group] broadcast payload: type=${payload.type} group_id=${payload.group_id} msgCount=${payload.messages.length} firstMsgId=${(_a = sorted[0]) === null || _a === void 0 ? void 0 : _a.msg_id} lastMsgId=${(_b = sorted[sorted.length - 1]) === null || _b === void 0 ? void 0 : _b.msg_id}`);
|
|
410
|
+
broadcastToBrowser(payload);
|
|
365
411
|
}).catch((e) => {
|
|
366
|
-
|
|
412
|
+
utils_1.logger.error(`[Group] processAndAckBatch failed: group=${groupId}`, e);
|
|
367
413
|
});
|
|
368
414
|
},
|
|
369
415
|
onGroupEvent(groupId, evt) {
|
|
370
|
-
|
|
416
|
+
utils_1.logger.log(`[Group] onGroupEvent: group=${groupId} event=${evt.event_type}`);
|
|
371
417
|
broadcastToBrowser({
|
|
372
418
|
type: 'group_event',
|
|
373
419
|
group_id: groupId,
|
|
374
420
|
event: evt,
|
|
375
421
|
});
|
|
376
422
|
},
|
|
377
|
-
onDutyDispatch(groupId, context) {
|
|
378
|
-
console.log(`[Group] onDutyDispatch: group=${groupId} original_msg_id=${context.original_msg_id} sender=${context.sender_id}`);
|
|
379
|
-
broadcastToBrowser({
|
|
380
|
-
type: 'duty_dispatch',
|
|
381
|
-
group_id: groupId,
|
|
382
|
-
context,
|
|
383
|
-
});
|
|
384
|
-
},
|
|
385
423
|
});
|
|
386
424
|
// 同步群组列表(如未同步过)
|
|
387
425
|
if (!instance.groupListSynced) {
|
|
@@ -390,7 +428,7 @@ async function ensureGroupClient(instance) {
|
|
|
390
428
|
instance.groupListSynced = true;
|
|
391
429
|
}
|
|
392
430
|
catch (e) {
|
|
393
|
-
|
|
431
|
+
utils_1.logger.warn('[Group] syncGroupList error:', e.message);
|
|
394
432
|
}
|
|
395
433
|
}
|
|
396
434
|
// 为所有已加入群组注册上线(register_online + 拉取未读 + 启动心跳)
|
|
@@ -400,13 +438,13 @@ async function ensureGroupClient(instance) {
|
|
|
400
438
|
await instance.agentCP.joinGroupSession(group.group_id);
|
|
401
439
|
}
|
|
402
440
|
catch (e) {
|
|
403
|
-
|
|
441
|
+
utils_1.logger.warn(`[Group] joinGroupSession failed: ${group.group_id}`, e.message);
|
|
404
442
|
}
|
|
405
443
|
}
|
|
406
444
|
instance.groupInitialized = true;
|
|
407
445
|
instance.groupSessionId = groupSessionId;
|
|
408
446
|
instance.groupTargetAid = targetAid;
|
|
409
|
-
|
|
447
|
+
utils_1.logger.log(`[Group] 群组客户端已初始化: aid=${aid} target=${targetAid} session=${groupSessionId}`);
|
|
410
448
|
}
|
|
411
449
|
async function validateAid(aid) {
|
|
412
450
|
try {
|
|
@@ -457,7 +495,7 @@ function loadAgentInfoCacheFromDisk() {
|
|
|
457
495
|
agentInfoCache.set(aid, Object.assign(Object.assign({}, info), { tags: info.tags || [] }));
|
|
458
496
|
}
|
|
459
497
|
}
|
|
460
|
-
|
|
498
|
+
utils_1.logger.log(`[Server] 已加载 agent info 缓存: ${agentInfoCache.size} 条`);
|
|
461
499
|
}
|
|
462
500
|
}
|
|
463
501
|
catch (e) {
|
|
@@ -591,1640 +629,1892 @@ async function ensureMessageStoreLoaded(aid) {
|
|
|
591
629
|
return store;
|
|
592
630
|
}
|
|
593
631
|
// HTML 页面
|
|
594
|
-
const indexHtml = `<!DOCTYPE html>
|
|
595
|
-
<html lang="zh-CN">
|
|
596
|
-
<head>
|
|
597
|
-
<meta charset="UTF-8">
|
|
598
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
599
|
-
<link rel="icon" href="/favicon.ico" type="image/x-icon">
|
|
600
|
-
<title>ACP 身份管理</title>
|
|
601
|
-
<style>
|
|
602
|
-
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
603
|
-
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: linear-gradient(135deg, #f0f4ff 0%, #e8edf5 100%); min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 40px 20px; }
|
|
604
|
-
.container { background: white; padding: 0; border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.08); max-width: 560px; width: 100%; overflow: hidden; }
|
|
605
|
-
.page-header { background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%); padding: 28px 32px 22px; color: white; text-align: center; }
|
|
606
|
-
.page-header h1 { font-size: 20px; font-weight: 600; margin-bottom: 12px; letter-spacing: 0.5px; }
|
|
607
|
-
.nav-links { display: flex; justify-content: center; gap: 8px; }
|
|
608
|
-
.nav-links a { color: rgba(255,255,255,0.85); text-decoration: none; font-size: 12px; padding: 4px 12px; border-radius: 20px; border: 1px solid rgba(255,255,255,0.25); transition: all 0.2s; }
|
|
609
|
-
.nav-links a:hover { background: rgba(255,255,255,0.15); color: #fff; border-color: rgba(255,255,255,0.5); }
|
|
610
|
-
.page-body { padding: 24px 32px 32px; }
|
|
611
|
-
.hint { text-align: center; color: #9ca3af; font-size: 13px; margin-bottom: 20px; }
|
|
612
|
-
.create-section { margin-bottom: 24px; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; }
|
|
613
|
-
.create-section .aid-input-row { display: flex; gap: 8px; align-items: center; }
|
|
614
|
-
.create-section .aid-input-row input { flex: 1; padding: 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; min-width: 0; background: #fff; transition: border-color 0.2s, box-shadow 0.2s; }
|
|
615
|
-
.create-section .aid-input-row input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
|
|
616
|
-
.create-section .aid-input-row .dot-separator { color: #9ca3af; font-size: 16px; flex-shrink: 0; }
|
|
617
|
-
.create-section .aid-input-row select {
|
|
618
|
-
padding: 10px 30px 10px 14px;
|
|
619
|
-
border: 1px solid #e2e8f0;
|
|
620
|
-
border-radius: 8px;
|
|
621
|
-
font-size: 14px;
|
|
622
|
-
background: #fff;
|
|
623
|
-
flex-shrink: 0;
|
|
624
|
-
cursor: pointer;
|
|
625
|
-
appearance: none;
|
|
626
|
-
-webkit-appearance: none;
|
|
627
|
-
-moz-appearance: none;
|
|
628
|
-
background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23999%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
|
|
629
|
-
background-repeat: no-repeat;
|
|
630
|
-
background-position: right 10px top 50%;
|
|
631
|
-
background-size: 10px auto;
|
|
632
|
-
transition: border-color 0.2s, box-shadow 0.2s;
|
|
633
|
-
}
|
|
634
|
-
.create-section .aid-input-row select:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
|
|
635
|
-
.create-section .extra-fields { display: flex; gap: 8px; }
|
|
636
|
-
.create-section .extra-fields input { flex: 1; padding: 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; min-width: 0; background: #fff; transition: border-color 0.2s, box-shadow 0.2s; }
|
|
637
|
-
.create-section .extra-fields input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
|
|
638
|
-
.btn { display: block; width: 100%; padding: 11px; border: none; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s; }
|
|
639
|
-
.btn-primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: white; }
|
|
640
|
-
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); box-shadow: 0 2px 8px rgba(37,99,235,0.3); }
|
|
641
|
-
.btn-sm { display: inline-block; width: auto; padding: 6px 14px; font-size: 13px; border-radius: 6px; }
|
|
642
|
-
.btn-success { background: #10b981; color: white; }
|
|
643
|
-
.btn-success:hover { background: #059669; }
|
|
644
|
-
.btn-danger { background: #ef4444; color: white; }
|
|
645
|
-
.btn-danger:hover { background: #dc2626; }
|
|
646
|
-
.btn-outline { background: white; color: #2563eb; border: 1px solid #2563eb; }
|
|
647
|
-
.btn-outline:hover { background: #eff6ff; }
|
|
648
|
-
.btn-outline.active { background: #2563eb; color: white; }
|
|
649
|
-
.btn:disabled { background: #d1d5db; cursor: not-allowed; border-color: #d1d5db; color: #fff; }
|
|
650
|
-
.aid-list { margin-bottom: 24px; }
|
|
651
|
-
.aid-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; margin-bottom: 10px; transition: all 0.2s; display: flex; align-items: stretch; gap: 12px; }
|
|
652
|
-
.aid-card:hover { border-color: #93c5fd; box-shadow: 0 2px 12px rgba(37,99,235,0.06); }
|
|
653
|
-
.aid-card.current { border-color: #2563eb; background: #eff6ff; }
|
|
654
|
-
.aid-card-left { flex: 1; min-width: 0; }
|
|
655
|
-
.aid-card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; justify-content: center; }
|
|
656
|
-
.aid-card-header { margin-bottom: 10px; }
|
|
657
|
-
.aid-name { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; color: #1f2937; word-break: break-all; }
|
|
658
|
-
.copy-btn { background: none; border: none; color: #9ca3af; cursor: pointer; font-size: 12px; padding: 2px 6px; transition: color 0.2s; }
|
|
659
|
-
.copy-btn:hover { color: #2563eb; }
|
|
660
|
-
.aid-card-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
661
|
-
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
|
|
662
|
-
.badge-success { background: #d1fae5; color: #065f46; }
|
|
663
|
-
.badge-warning { background: #fef3c7; color: #92400e; }
|
|
664
|
-
.badge-danger { background: #fee2e2; color: #991b1b; }
|
|
665
|
-
.badge-info { background: #dbeafe; color: #1e40af; }
|
|
666
|
-
.badge-current { background: #2563eb; color: white; }
|
|
667
|
-
.aid-card-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
|
|
668
|
-
.status { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); padding: 12px 24px; border-radius: 10px; font-size: 14px; display: none; z-index: 1000; box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
|
|
669
|
-
.status.success { display: block; background: #d1fae5; color: #065f46; }
|
|
670
|
-
.status.error { display: block; background: #fee2e2; color: #991b1b; }
|
|
671
|
-
@media (max-width: 480px) {
|
|
672
|
-
body { padding: 16px 8px; }
|
|
673
|
-
.page-header { padding: 22px 18px 18px; }
|
|
674
|
-
.page-body { padding: 18px 16px 24px; }
|
|
675
|
-
.create-section { padding: 14px; }
|
|
676
|
-
}
|
|
677
|
-
</style>
|
|
678
|
-
</head>
|
|
679
|
-
<body>
|
|
680
|
-
<div class="container">
|
|
681
|
-
<div class="page-header">
|
|
682
|
-
<h1>ACP 身份管理</h1>
|
|
683
|
-
<div class="nav-links">
|
|
684
|
-
<a href="https://agentunion.net" target="_blank">AgentUnion排行榜</a>
|
|
685
|
-
<a href="https://github.com/auliwenjiang/agentcp" target="_blank">ACP 开源GitHub</a>
|
|
686
|
-
</div>
|
|
687
|
-
</div>
|
|
688
|
-
<div class="page-body">
|
|
689
|
-
<div class="hint" id="hint">最多注册 10 个 AID</div>
|
|
690
|
-
|
|
691
|
-
<div class="create-section" id="createSection">
|
|
692
|
-
<div class="aid-input-row">
|
|
693
|
-
<input type="text" id="newAid" placeholder="输入名称">
|
|
694
|
-
<span class="dot-separator">.</span>
|
|
695
|
-
<select id="apSelect"></select>
|
|
696
|
-
</div>
|
|
697
|
-
<div class="extra-fields">
|
|
698
|
-
<input type="text" id="aidNickname" placeholder="昵称(选填)">
|
|
699
|
-
<input type="text" id="aidDescription" placeholder="描述(选填)" style="flex:2;">
|
|
700
|
-
</div>
|
|
701
|
-
<button class="btn btn-primary" onclick="createAid()">注册 AID</button>
|
|
702
|
-
</div>
|
|
703
|
-
|
|
704
|
-
<div class="aid-list" id="aidList"></div>
|
|
705
|
-
|
|
706
|
-
<div class="status" id="status"></div>
|
|
707
|
-
</div>
|
|
708
|
-
</div>
|
|
709
|
-
|
|
710
|
-
<script>
|
|
711
|
-
let aidData = { aidList: [], aidStatus: [], apiUrl: '' };
|
|
712
|
-
|
|
713
|
-
async function loadAidInfo() {
|
|
714
|
-
try {
|
|
715
|
-
const res = await fetch('/api/aid');
|
|
716
|
-
const data = await res.json();
|
|
717
|
-
aidData = data;
|
|
718
|
-
updateApSelect();
|
|
719
|
-
renderAidList();
|
|
720
|
-
} catch (e) {
|
|
721
|
-
console.error('加载失败', e);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
function updateApSelect() {
|
|
726
|
-
var sel = document.getElementById('apSelect');
|
|
727
|
-
if (sel && sel.options.length === 0) {
|
|
728
|
-
const options = ['agentcp.io', 'aid.show', 'agentid.pub'];
|
|
729
|
-
options.forEach(function(op) {
|
|
730
|
-
var opt = document.createElement('option');
|
|
731
|
-
opt.value = op;
|
|
732
|
-
opt.textContent = op;
|
|
733
|
-
if (op === 'agentcp.io') opt.selected = true;
|
|
734
|
-
sel.appendChild(opt);
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
function renderAidList() {
|
|
740
|
-
const list = document.getElementById('aidList');
|
|
741
|
-
const createSection = document.getElementById('createSection');
|
|
742
|
-
const hint = document.getElementById('hint');
|
|
743
|
-
|
|
744
|
-
if (aidData.aidList.length >= 10) {
|
|
745
|
-
createSection.style.display = 'none';
|
|
746
|
-
hint.textContent = '已达到 10 个 AID 上限';
|
|
747
|
-
} else {
|
|
748
|
-
createSection.style.display = 'block';
|
|
749
|
-
hint.textContent = '最多注册 10 个 AID(已注册 ' + aidData.aidList.length + ' 个)';
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
if (!aidData.aidStatus || aidData.aidStatus.length === 0) {
|
|
753
|
-
list.innerHTML = '<div style="text-align:center;color:#999;padding:20px;">暂无 AID,请先注册</div>';
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
list.innerHTML = aidData.aidStatus.map(function(item) {
|
|
758
|
-
var cardClass = 'aid-card';
|
|
759
|
-
|
|
760
|
-
var badges = '';
|
|
761
|
-
if (item.online) badges += '<span class="badge badge-success">已上线</span>';
|
|
762
|
-
if (item.keysExist && item.certValid) {
|
|
763
|
-
badges += '<span class="badge badge-info">密钥有效</span>';
|
|
764
|
-
} else if (item.keysExist && !item.certValid) {
|
|
765
|
-
badges += '<span class="badge badge-warning">证书过期</span>';
|
|
766
|
-
} else {
|
|
767
|
-
badges += '<span class="badge badge-danger">密钥缺失</span>';
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
var actions = '';
|
|
771
|
-
if (item.keysExist && item.certValid) {
|
|
772
|
-
if (item.online) {
|
|
773
|
-
actions += '<button class="btn btn-sm btn-success" onclick="enterChat(\\'' + escapeAttr(item.aid) + '\\')">进入聊天</button>';
|
|
774
|
-
actions += '<button class="btn btn-sm btn-danger" onclick="goOffline(\\'' + escapeAttr(item.aid) + '\\')">下线</button>';
|
|
775
|
-
} else {
|
|
776
|
-
actions += '<button class="btn btn-sm btn-success" id="goBtn_' + escapeAttr(item.aid) + '" onclick="goOnlineAndChat(\\'' + escapeAttr(item.aid) + '\\')">上线并进入</button>';
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
return '<div class="' + cardClass + '">' +
|
|
781
|
-
'<div class="aid-card-left">' +
|
|
782
|
-
'<div class="aid-card-header">' +
|
|
783
|
-
'<span class="aid-name">' + escapeHtml(item.aid) + '</span>' +
|
|
784
|
-
'</div>' +
|
|
785
|
-
'<div class="aid-card-status">' + badges + '</div>' +
|
|
786
|
-
'</div>' +
|
|
787
|
-
'<div class="aid-card-right">' +
|
|
788
|
-
'<div class="aid-card-actions">' + actions + '</div>' +
|
|
789
|
-
'<button class="copy-btn" onclick="copyText(\\'' + escapeAttr(item.aid) + '\\')">复制</button>' +
|
|
790
|
-
'</div>' +
|
|
791
|
-
'</div>';
|
|
792
|
-
}).join('');
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
async function createAid() {
|
|
796
|
-
var prefix = document.getElementById('newAid').value.trim();
|
|
797
|
-
if (!prefix) { showStatus('请输入 AID 名称', 'error'); return; }
|
|
798
|
-
var ap = document.getElementById('apSelect').value;
|
|
799
|
-
if (!ap) { showStatus('请选择 AP', 'error'); return; }
|
|
800
|
-
var fullPrefix = prefix + '.' + ap;
|
|
801
|
-
var nickname = document.getElementById('aidNickname').value.trim();
|
|
802
|
-
var description = document.getElementById('aidDescription').value.trim();
|
|
803
|
-
try {
|
|
804
|
-
var res = await fetch('/api/aid/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prefix: fullPrefix, nickname: nickname, description: description }) });
|
|
805
|
-
var data = await res.json();
|
|
806
|
-
if (data.success) { showStatus('AID 注册成功', 'success'); document.getElementById('newAid').value = ''; document.getElementById('aidNickname').value = ''; document.getElementById('aidDescription').value = ''; loadAidInfo(); }
|
|
807
|
-
else { showStatus(data.error || '注册失败', 'error'); }
|
|
808
|
-
} catch (e) { showStatus('注册失败: ' + e.message, 'error'); }
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
async function selectAid(aid) {
|
|
812
|
-
try {
|
|
813
|
-
var res = await fetch('/api/aid/select', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ aid: aid }) });
|
|
814
|
-
var data = await res.json();
|
|
815
|
-
if (data.success) { showStatus('已切换到 ' + aid, 'success'); loadAidInfo(); }
|
|
816
|
-
else { showStatus(data.error || '切换失败', 'error'); }
|
|
817
|
-
} catch (e) { showStatus('切换失败: ' + e.message, 'error'); }
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
async function goOnlineAndChat(aid) {
|
|
821
|
-
var btn = document.getElementById('goBtn_' + aid);
|
|
822
|
-
if (btn) { btn.disabled = true; btn.textContent = '启动中...'; }
|
|
823
|
-
try {
|
|
824
|
-
showStatus('正在上线 ' + aid + ' ...', 'success');
|
|
825
|
-
var res = await fetch('/api/ws/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ aid: aid }) });
|
|
826
|
-
var data = await res.json();
|
|
827
|
-
if (data.success) {
|
|
828
|
-
showStatus(aid + ' 已上线,正在进入聊天...', 'success');
|
|
829
|
-
window.location.href = '/chat';
|
|
830
|
-
} else {
|
|
831
|
-
showStatus(data.error || '上线失败', 'error');
|
|
832
|
-
if (btn) { btn.disabled = false; btn.textContent = '上线并进入'; }
|
|
833
|
-
}
|
|
834
|
-
} catch (e) {
|
|
835
|
-
showStatus('上线失败: ' + e.message, 'error');
|
|
836
|
-
if (btn) { btn.disabled = false; btn.textContent = '上线并进入'; }
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
function enterChat(aid) { window.location.href = '/chat'; }
|
|
841
|
-
|
|
842
|
-
async function goOffline(aid) {
|
|
843
|
-
try {
|
|
844
|
-
var res = await fetch('/api/aid/offline', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ aid: aid }) });
|
|
845
|
-
var data = await res.json();
|
|
846
|
-
if (data.success) { showStatus(aid + ' 已下线', 'success'); loadAidInfo(); }
|
|
847
|
-
else { showStatus(data.error || '下线失败', 'error'); }
|
|
848
|
-
} catch (e) { showStatus('下线失败: ' + e.message, 'error'); }
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
function copyText(text) {
|
|
852
|
-
navigator.clipboard.writeText(text).then(function() {
|
|
853
|
-
showStatus('已复制', 'success');
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
function showStatus(msg, type) {
|
|
858
|
-
var el = document.getElementById('status');
|
|
859
|
-
el.textContent = msg;
|
|
860
|
-
el.className = 'status ' + type;
|
|
861
|
-
setTimeout(function() { el.className = 'status'; }, 3000);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
function escapeHtml(text) {
|
|
865
|
-
var div = document.createElement('div');
|
|
866
|
-
div.textContent = text;
|
|
867
|
-
return div.innerHTML;
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
function escapeAttr(text) {
|
|
871
|
-
return text.replace(/'/g, "\\\\'").replace(/"/g, '"');
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
loadAidInfo();
|
|
875
|
-
setInterval(loadAidInfo, 5000);
|
|
876
|
-
<\/script>
|
|
877
|
-
</body>
|
|
632
|
+
const indexHtml = `<!DOCTYPE html>
|
|
633
|
+
<html lang="zh-CN">
|
|
634
|
+
<head>
|
|
635
|
+
<meta charset="UTF-8">
|
|
636
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
637
|
+
<link rel="icon" href="/favicon.ico" type="image/x-icon">
|
|
638
|
+
<title>ACP 身份管理</title>
|
|
639
|
+
<style>
|
|
640
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
641
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: linear-gradient(135deg, #f0f4ff 0%, #e8edf5 100%); min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 40px 20px; }
|
|
642
|
+
.container { background: white; padding: 0; border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.08); max-width: 560px; width: 100%; overflow: hidden; }
|
|
643
|
+
.page-header { background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%); padding: 28px 32px 22px; color: white; text-align: center; }
|
|
644
|
+
.page-header h1 { font-size: 20px; font-weight: 600; margin-bottom: 12px; letter-spacing: 0.5px; }
|
|
645
|
+
.nav-links { display: flex; justify-content: center; gap: 8px; }
|
|
646
|
+
.nav-links a { color: rgba(255,255,255,0.85); text-decoration: none; font-size: 12px; padding: 4px 12px; border-radius: 20px; border: 1px solid rgba(255,255,255,0.25); transition: all 0.2s; }
|
|
647
|
+
.nav-links a:hover { background: rgba(255,255,255,0.15); color: #fff; border-color: rgba(255,255,255,0.5); }
|
|
648
|
+
.page-body { padding: 24px 32px 32px; }
|
|
649
|
+
.hint { text-align: center; color: #9ca3af; font-size: 13px; margin-bottom: 20px; }
|
|
650
|
+
.create-section { margin-bottom: 24px; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 18px; }
|
|
651
|
+
.create-section .aid-input-row { display: flex; gap: 8px; align-items: center; }
|
|
652
|
+
.create-section .aid-input-row input { flex: 1; padding: 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; min-width: 0; background: #fff; transition: border-color 0.2s, box-shadow 0.2s; }
|
|
653
|
+
.create-section .aid-input-row input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
|
|
654
|
+
.create-section .aid-input-row .dot-separator { color: #9ca3af; font-size: 16px; flex-shrink: 0; }
|
|
655
|
+
.create-section .aid-input-row select {
|
|
656
|
+
padding: 10px 30px 10px 14px;
|
|
657
|
+
border: 1px solid #e2e8f0;
|
|
658
|
+
border-radius: 8px;
|
|
659
|
+
font-size: 14px;
|
|
660
|
+
background: #fff;
|
|
661
|
+
flex-shrink: 0;
|
|
662
|
+
cursor: pointer;
|
|
663
|
+
appearance: none;
|
|
664
|
+
-webkit-appearance: none;
|
|
665
|
+
-moz-appearance: none;
|
|
666
|
+
background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23999%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
|
|
667
|
+
background-repeat: no-repeat;
|
|
668
|
+
background-position: right 10px top 50%;
|
|
669
|
+
background-size: 10px auto;
|
|
670
|
+
transition: border-color 0.2s, box-shadow 0.2s;
|
|
671
|
+
}
|
|
672
|
+
.create-section .aid-input-row select:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
|
|
673
|
+
.create-section .extra-fields { display: flex; gap: 8px; }
|
|
674
|
+
.create-section .extra-fields input { flex: 1; padding: 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; min-width: 0; background: #fff; transition: border-color 0.2s, box-shadow 0.2s; }
|
|
675
|
+
.create-section .extra-fields input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
|
|
676
|
+
.btn { display: block; width: 100%; padding: 11px; border: none; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s; }
|
|
677
|
+
.btn-primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: white; }
|
|
678
|
+
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); box-shadow: 0 2px 8px rgba(37,99,235,0.3); }
|
|
679
|
+
.btn-sm { display: inline-block; width: auto; padding: 6px 14px; font-size: 13px; border-radius: 6px; }
|
|
680
|
+
.btn-success { background: #10b981; color: white; }
|
|
681
|
+
.btn-success:hover { background: #059669; }
|
|
682
|
+
.btn-danger { background: #ef4444; color: white; }
|
|
683
|
+
.btn-danger:hover { background: #dc2626; }
|
|
684
|
+
.btn-outline { background: white; color: #2563eb; border: 1px solid #2563eb; }
|
|
685
|
+
.btn-outline:hover { background: #eff6ff; }
|
|
686
|
+
.btn-outline.active { background: #2563eb; color: white; }
|
|
687
|
+
.btn:disabled { background: #d1d5db; cursor: not-allowed; border-color: #d1d5db; color: #fff; }
|
|
688
|
+
.aid-list { margin-bottom: 24px; }
|
|
689
|
+
.aid-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; margin-bottom: 10px; transition: all 0.2s; display: flex; align-items: stretch; gap: 12px; }
|
|
690
|
+
.aid-card:hover { border-color: #93c5fd; box-shadow: 0 2px 12px rgba(37,99,235,0.06); }
|
|
691
|
+
.aid-card.current { border-color: #2563eb; background: #eff6ff; }
|
|
692
|
+
.aid-card-left { flex: 1; min-width: 0; }
|
|
693
|
+
.aid-card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; justify-content: center; }
|
|
694
|
+
.aid-card-header { margin-bottom: 10px; }
|
|
695
|
+
.aid-name { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; color: #1f2937; word-break: break-all; }
|
|
696
|
+
.copy-btn { background: none; border: none; color: #9ca3af; cursor: pointer; font-size: 12px; padding: 2px 6px; transition: color 0.2s; }
|
|
697
|
+
.copy-btn:hover { color: #2563eb; }
|
|
698
|
+
.aid-card-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
699
|
+
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
|
|
700
|
+
.badge-success { background: #d1fae5; color: #065f46; }
|
|
701
|
+
.badge-warning { background: #fef3c7; color: #92400e; }
|
|
702
|
+
.badge-danger { background: #fee2e2; color: #991b1b; }
|
|
703
|
+
.badge-info { background: #dbeafe; color: #1e40af; }
|
|
704
|
+
.badge-current { background: #2563eb; color: white; }
|
|
705
|
+
.aid-card-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
|
|
706
|
+
.status { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); padding: 12px 24px; border-radius: 10px; font-size: 14px; display: none; z-index: 1000; box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
|
|
707
|
+
.status.success { display: block; background: #d1fae5; color: #065f46; }
|
|
708
|
+
.status.error { display: block; background: #fee2e2; color: #991b1b; }
|
|
709
|
+
@media (max-width: 480px) {
|
|
710
|
+
body { padding: 16px 8px; }
|
|
711
|
+
.page-header { padding: 22px 18px 18px; }
|
|
712
|
+
.page-body { padding: 18px 16px 24px; }
|
|
713
|
+
.create-section { padding: 14px; }
|
|
714
|
+
}
|
|
715
|
+
</style>
|
|
716
|
+
</head>
|
|
717
|
+
<body>
|
|
718
|
+
<div class="container">
|
|
719
|
+
<div class="page-header">
|
|
720
|
+
<h1>ACP 身份管理</h1>
|
|
721
|
+
<div class="nav-links">
|
|
722
|
+
<a href="https://agentunion.net" target="_blank">AgentUnion排行榜</a>
|
|
723
|
+
<a href="https://github.com/auliwenjiang/agentcp" target="_blank">ACP 开源GitHub</a>
|
|
724
|
+
</div>
|
|
725
|
+
</div>
|
|
726
|
+
<div class="page-body">
|
|
727
|
+
<div class="hint" id="hint">最多注册 10 个 AID</div>
|
|
728
|
+
|
|
729
|
+
<div class="create-section" id="createSection">
|
|
730
|
+
<div class="aid-input-row">
|
|
731
|
+
<input type="text" id="newAid" placeholder="输入名称">
|
|
732
|
+
<span class="dot-separator">.</span>
|
|
733
|
+
<select id="apSelect"></select>
|
|
734
|
+
</div>
|
|
735
|
+
<div class="extra-fields">
|
|
736
|
+
<input type="text" id="aidNickname" placeholder="昵称(选填)">
|
|
737
|
+
<input type="text" id="aidDescription" placeholder="描述(选填)" style="flex:2;">
|
|
738
|
+
</div>
|
|
739
|
+
<button class="btn btn-primary" onclick="createAid()">注册 AID</button>
|
|
740
|
+
</div>
|
|
741
|
+
|
|
742
|
+
<div class="aid-list" id="aidList"></div>
|
|
743
|
+
|
|
744
|
+
<div class="status" id="status"></div>
|
|
745
|
+
</div>
|
|
746
|
+
</div>
|
|
747
|
+
|
|
748
|
+
<script>
|
|
749
|
+
let aidData = { aidList: [], aidStatus: [], apiUrl: '' };
|
|
750
|
+
|
|
751
|
+
async function loadAidInfo() {
|
|
752
|
+
try {
|
|
753
|
+
const res = await fetch('/api/aid');
|
|
754
|
+
const data = await res.json();
|
|
755
|
+
aidData = data;
|
|
756
|
+
updateApSelect();
|
|
757
|
+
renderAidList();
|
|
758
|
+
} catch (e) {
|
|
759
|
+
console.error('加载失败', e);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function updateApSelect() {
|
|
764
|
+
var sel = document.getElementById('apSelect');
|
|
765
|
+
if (sel && sel.options.length === 0) {
|
|
766
|
+
const options = ['agentcp.io', 'aid.show', 'agentid.pub'];
|
|
767
|
+
options.forEach(function(op) {
|
|
768
|
+
var opt = document.createElement('option');
|
|
769
|
+
opt.value = op;
|
|
770
|
+
opt.textContent = op;
|
|
771
|
+
if (op === 'agentcp.io') opt.selected = true;
|
|
772
|
+
sel.appendChild(opt);
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function renderAidList() {
|
|
778
|
+
const list = document.getElementById('aidList');
|
|
779
|
+
const createSection = document.getElementById('createSection');
|
|
780
|
+
const hint = document.getElementById('hint');
|
|
781
|
+
|
|
782
|
+
if (aidData.aidList.length >= 10) {
|
|
783
|
+
createSection.style.display = 'none';
|
|
784
|
+
hint.textContent = '已达到 10 个 AID 上限';
|
|
785
|
+
} else {
|
|
786
|
+
createSection.style.display = 'block';
|
|
787
|
+
hint.textContent = '最多注册 10 个 AID(已注册 ' + aidData.aidList.length + ' 个)';
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
if (!aidData.aidStatus || aidData.aidStatus.length === 0) {
|
|
791
|
+
list.innerHTML = '<div style="text-align:center;color:#999;padding:20px;">暂无 AID,请先注册</div>';
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
list.innerHTML = aidData.aidStatus.map(function(item) {
|
|
796
|
+
var cardClass = 'aid-card';
|
|
797
|
+
|
|
798
|
+
var badges = '';
|
|
799
|
+
if (item.online) badges += '<span class="badge badge-success">已上线</span>';
|
|
800
|
+
if (item.keysExist && item.certValid) {
|
|
801
|
+
badges += '<span class="badge badge-info">密钥有效</span>';
|
|
802
|
+
} else if (item.keysExist && !item.certValid) {
|
|
803
|
+
badges += '<span class="badge badge-warning">证书过期</span>';
|
|
804
|
+
} else {
|
|
805
|
+
badges += '<span class="badge badge-danger">密钥缺失</span>';
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
var actions = '';
|
|
809
|
+
if (item.keysExist && item.certValid) {
|
|
810
|
+
if (item.online) {
|
|
811
|
+
actions += '<button class="btn btn-sm btn-success" onclick="enterChat(\\'' + escapeAttr(item.aid) + '\\')">进入聊天</button>';
|
|
812
|
+
actions += '<button class="btn btn-sm btn-danger" onclick="goOffline(\\'' + escapeAttr(item.aid) + '\\')">下线</button>';
|
|
813
|
+
} else {
|
|
814
|
+
actions += '<button class="btn btn-sm btn-success" id="goBtn_' + escapeAttr(item.aid) + '" onclick="goOnlineAndChat(\\'' + escapeAttr(item.aid) + '\\')">上线并进入</button>';
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return '<div class="' + cardClass + '">' +
|
|
819
|
+
'<div class="aid-card-left">' +
|
|
820
|
+
'<div class="aid-card-header">' +
|
|
821
|
+
'<span class="aid-name">' + escapeHtml(item.aid) + '</span>' +
|
|
822
|
+
'</div>' +
|
|
823
|
+
'<div class="aid-card-status">' + badges + '</div>' +
|
|
824
|
+
'</div>' +
|
|
825
|
+
'<div class="aid-card-right">' +
|
|
826
|
+
'<div class="aid-card-actions">' + actions + '</div>' +
|
|
827
|
+
'<button class="copy-btn" onclick="copyText(\\'' + escapeAttr(item.aid) + '\\')">复制</button>' +
|
|
828
|
+
'</div>' +
|
|
829
|
+
'</div>';
|
|
830
|
+
}).join('');
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
async function createAid() {
|
|
834
|
+
var prefix = document.getElementById('newAid').value.trim();
|
|
835
|
+
if (!prefix) { showStatus('请输入 AID 名称', 'error'); return; }
|
|
836
|
+
var ap = document.getElementById('apSelect').value;
|
|
837
|
+
if (!ap) { showStatus('请选择 AP', 'error'); return; }
|
|
838
|
+
var fullPrefix = prefix + '.' + ap;
|
|
839
|
+
var nickname = document.getElementById('aidNickname').value.trim();
|
|
840
|
+
var description = document.getElementById('aidDescription').value.trim();
|
|
841
|
+
try {
|
|
842
|
+
var res = await fetch('/api/aid/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prefix: fullPrefix, nickname: nickname, description: description }) });
|
|
843
|
+
var data = await res.json();
|
|
844
|
+
if (data.success) { showStatus('AID 注册成功', 'success'); document.getElementById('newAid').value = ''; document.getElementById('aidNickname').value = ''; document.getElementById('aidDescription').value = ''; loadAidInfo(); }
|
|
845
|
+
else { showStatus(data.error || '注册失败', 'error'); }
|
|
846
|
+
} catch (e) { showStatus('注册失败: ' + e.message, 'error'); }
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
async function selectAid(aid) {
|
|
850
|
+
try {
|
|
851
|
+
var res = await fetch('/api/aid/select', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ aid: aid }) });
|
|
852
|
+
var data = await res.json();
|
|
853
|
+
if (data.success) { showStatus('已切换到 ' + aid, 'success'); loadAidInfo(); }
|
|
854
|
+
else { showStatus(data.error || '切换失败', 'error'); }
|
|
855
|
+
} catch (e) { showStatus('切换失败: ' + e.message, 'error'); }
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
async function goOnlineAndChat(aid) {
|
|
859
|
+
var btn = document.getElementById('goBtn_' + aid);
|
|
860
|
+
if (btn) { btn.disabled = true; btn.textContent = '启动中...'; }
|
|
861
|
+
try {
|
|
862
|
+
showStatus('正在上线 ' + aid + ' ...', 'success');
|
|
863
|
+
var res = await fetch('/api/ws/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ aid: aid }) });
|
|
864
|
+
var data = await res.json();
|
|
865
|
+
if (data.success) {
|
|
866
|
+
showStatus(aid + ' 已上线,正在进入聊天...', 'success');
|
|
867
|
+
window.location.href = '/chat';
|
|
868
|
+
} else {
|
|
869
|
+
showStatus(data.error || '上线失败', 'error');
|
|
870
|
+
if (btn) { btn.disabled = false; btn.textContent = '上线并进入'; }
|
|
871
|
+
}
|
|
872
|
+
} catch (e) {
|
|
873
|
+
showStatus('上线失败: ' + e.message, 'error');
|
|
874
|
+
if (btn) { btn.disabled = false; btn.textContent = '上线并进入'; }
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
function enterChat(aid) { window.location.href = '/chat'; }
|
|
879
|
+
|
|
880
|
+
async function goOffline(aid) {
|
|
881
|
+
try {
|
|
882
|
+
var res = await fetch('/api/aid/offline', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ aid: aid }) });
|
|
883
|
+
var data = await res.json();
|
|
884
|
+
if (data.success) { showStatus(aid + ' 已下线', 'success'); loadAidInfo(); }
|
|
885
|
+
else { showStatus(data.error || '下线失败', 'error'); }
|
|
886
|
+
} catch (e) { showStatus('下线失败: ' + e.message, 'error'); }
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function copyText(text) {
|
|
890
|
+
navigator.clipboard.writeText(text).then(function() {
|
|
891
|
+
showStatus('已复制', 'success');
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function showStatus(msg, type) {
|
|
896
|
+
var el = document.getElementById('status');
|
|
897
|
+
el.textContent = msg;
|
|
898
|
+
el.className = 'status ' + type;
|
|
899
|
+
setTimeout(function() { el.className = 'status'; }, 3000);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function escapeHtml(text) {
|
|
903
|
+
var div = document.createElement('div');
|
|
904
|
+
div.textContent = text;
|
|
905
|
+
return div.innerHTML;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
function escapeAttr(text) {
|
|
909
|
+
return text.replace(/'/g, "\\\\'").replace(/"/g, '"');
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
loadAidInfo();
|
|
913
|
+
setInterval(loadAidInfo, 5000);
|
|
914
|
+
<\/script>
|
|
915
|
+
</body>
|
|
878
916
|
</html>`;
|
|
879
|
-
const chatHtml = `<!DOCTYPE html>
|
|
880
|
-
<html lang="zh-CN">
|
|
881
|
-
<head>
|
|
882
|
-
<meta charset="UTF-8">
|
|
883
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
884
|
-
<title>ACP 聊天</title>
|
|
885
|
-
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"><\/script>
|
|
886
|
-
<style>
|
|
887
|
-
:root { --primary:#2563eb; --primary-h:#1d4ed8; --bg:#f3f4f6; --sidebar-bg:#fff; --chat-bg:#f9fafb; --border:#e5e7eb; --t1:#1f2937; --t2:#6b7280; --sent:#2563eb; --recv-bg:#fff; --ok:#10b981; }
|
|
888
|
-
* { box-sizing:border-box; margin:0; padding:0; }
|
|
889
|
-
body { font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; background:var(--bg); height:100vh; overflow:hidden; color:var(--t1); }
|
|
890
|
-
#app { display:flex; height:100%; }
|
|
891
|
-
|
|
892
|
-
/* Sidebar */
|
|
893
|
-
.sidebar { width:300px; background:var(--sidebar-bg); border-right:1px solid var(--border); display:flex; flex-direction:column; flex-shrink:0; transition:width 0.25s; overflow:hidden; }
|
|
894
|
-
.sidebar.collapsed { width:0; border-right:none; }
|
|
895
|
-
.sidebar-header { padding:12px 14px; border-bottom:1px solid var(--border); display:flex; flex-direction:column; gap:12px; flex-shrink:0; }
|
|
896
|
-
.header-top { display:flex; justify-content:space-between; align-items:center; width:100%; }
|
|
897
|
-
.sidebar-header .my-aid { font-size:11px; color:#155724; font-family:monospace; background:#d4edda; padding:4px 8px; border-radius:12px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; border:1px solid #c3e6cb; flex:1; margin-right:8px; }
|
|
898
|
-
.new-chat-btn { padding:8px 10px; background:var(--primary); color:#fff; border:none; border-radius:6px; font-size:12px; cursor:pointer; white-space:nowrap; width:100%; text-align:center; }
|
|
899
|
-
.new-chat-btn:hover { background:var(--primary-h); }
|
|
900
|
-
.session-list { flex:1; overflow-y:auto; }
|
|
901
|
-
|
|
902
|
-
/* AID Group */
|
|
903
|
-
.aid-group { border-bottom:1px solid var(--border); }
|
|
904
|
-
.aid-group-header { padding:12px 14px; display:flex; align-items:center; cursor:pointer; background:linear-gradient(135deg,#eef4ff,#e8f0fe); user-select:none; border-left:3px solid var(--primary); transition:all 0.2s; }
|
|
905
|
-
.aid-group-header:hover { background:linear-gradient(135deg,#dbeafe,#d0e4fd); }
|
|
906
|
-
.aid-group-info { flex:1; min-width:0; margin-left:4px; }
|
|
907
|
-
.aid-group-title { font-size:13px; font-weight:700; color:#1e40af; background:linear-gradient(135deg,#dbeafe,#c7d7fe); padding:2px 8px; border-radius:6px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:inline-block; max-width:100%; border:1px solid #bfdbfe; }
|
|
908
|
-
.aid-group-desc { font-size:10px; color:#6b7280; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:3px; display:block; padding-left:2px; }
|
|
909
|
-
.aid-group-arrow { font-size:10px; color:var(--primary); transition:transform 0.2s; flex-shrink:0; }
|
|
910
|
-
.aid-group-arrow.open { transform:rotate(90deg); }
|
|
911
|
-
.aid-group-badge { font-size:10px; background:var(--primary); color:#fff; padding:1px 6px; border-radius:8px; margin-left:8px; flex-shrink:0; }
|
|
912
|
-
.aid-group-add { background:none; border:1px solid var(--border); color:var(--t2); width:22px; height:22px; border-radius:4px; cursor:pointer; font-size:14px; line-height:20px; text-align:center; margin-left:6px; flex-shrink:0; }
|
|
913
|
-
.aid-group-add:hover { background:var(--primary); color:#fff; border-color:var(--primary); }
|
|
914
|
-
.aid-group-del { background:none; border:none; color:var(--t2); width:20px; height:20px; border-radius:4px; cursor:pointer; font-size:12px; line-height:20px; text-align:center; margin-left:4px; flex-shrink:0; display:none; }
|
|
915
|
-
.aid-group-header:hover .aid-group-del { display:block; }
|
|
916
|
-
.aid-group-del:hover { color:#dc3545; background:#ffebeb; }
|
|
917
|
-
.session-del { position:absolute; right:8px; top:50%; transform:translateY(-50%); background:none; border:none; color:var(--t2); font-size:12px; cursor:pointer; display:none; padding:2px; }
|
|
918
|
-
.session-item:hover .session-del { display:block; }
|
|
919
|
-
.session-del:hover { color:#dc3545; }
|
|
920
|
-
.aid-group-sessions { display:none; background:#fafbfc; }
|
|
921
|
-
.aid-group-sessions.open { display:block; }
|
|
922
|
-
|
|
923
|
-
.aid-group-avatar { width:36px; height:36px; border-radius:50%; object-fit:cover; flex-shrink:0; margin-right:8px; box-shadow:0 1px 4px rgba(37,99,235,0.18); border:2px solid #bfdbfe; }
|
|
924
|
-
|
|
925
|
-
.session-item { padding:10px 14px 10px 32px; border-bottom:1px solid #f0f1f3; cursor:pointer; transition:all 0.15s; position:relative; }
|
|
926
|
-
.session-item::before { content:''; position:absolute; left:18px; top:50%; transform:translateY(-50%); width:6px; height:6px; border-radius:50%; background:#d1d5db; }
|
|
927
|
-
.session-item:hover { background:#f0f5ff; }
|
|
928
|
-
.session-item.active { background:#eff6ff; border-left:3px solid var(--primary); padding-left:29px; }
|
|
929
|
-
.session-item.active::before { background:var(--primary); box-shadow:0 0 0 2px rgba(37,99,235,0.2); }
|
|
930
|
-
.session-peer { font-weight:500; font-size:12px; color:var(--t1); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; padding-left:10px; background:#f1f5f9; border-radius:4px; padding:3px 8px 3px 10px; border:1px solid #e8ecf1; }
|
|
931
|
-
.session-item.active .session-peer { background:#dbeafe; border-color:#bfdbfe; color:#1e40af; }
|
|
932
|
-
.session-meta { font-size:10px; color:var(--t2); margin-top:4px; display:flex; align-items:center; gap:6px; padding-left:10px; }
|
|
933
|
-
.tag { font-size:9px; padding:1px 5px; border-radius:3px; color:#fff; font-weight:600; letter-spacing:0.3px; }
|
|
934
|
-
.tag.outgoing { background:var(--ok); }
|
|
935
|
-
.tag.incoming { background:#8b5cf6; }
|
|
936
|
-
|
|
937
|
-
/* Chat Area */
|
|
938
|
-
.chat-area { flex:1; display:flex; flex-direction:column; background:var(--chat-bg); min-width:0; }
|
|
939
|
-
.chat-header { height:54px; padding:0 16px; background:#fff; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; flex-shrink:0; }
|
|
940
|
-
.header-left { display:flex; align-items:center; gap:10px; overflow:hidden; }
|
|
941
|
-
.toggle-sidebar-btn { background:none; border:none; cursor:pointer; color:var(--t2); padding:4px; display:flex; }
|
|
942
|
-
.toggle-sidebar-btn:hover { color:var(--t1); }
|
|
943
|
-
.status-dot { width:8px; height:8px; border-radius:50%; background:#ccc; flex-shrink:0; }
|
|
944
|
-
.status-dot.connected { background:var(--ok); }
|
|
945
|
-
.status-dot.connecting { background:#fbbf24; }
|
|
946
|
-
.chat-title { font-size:15px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
947
|
-
|
|
948
|
-
.aid-select-wrap { display:flex; align-items:center; gap:10px; flex-shrink:0; }
|
|
949
|
-
.manage-btn { display:flex; align-items:center; gap:4px; text-decoration:none; color:var(--t2); font-size:12px; padding:6px 10px; border-radius:6px; transition:all 0.2s; background:#fff; border:1px solid var(--border); }
|
|
950
|
-
.manage-btn:hover { background:#f8fafc; color:var(--primary); border-color:var(--primary); }
|
|
951
|
-
.aid-control-group { display:flex; align-items:center; background:#fff; border:1px solid var(--border); border-radius:6px; padding:2px; box-shadow:0 1px 2px rgba(0,0,0,0.03); }
|
|
952
|
-
.aid-select { border:none; background:transparent; font-size:12px; color:var(--t1); padding:5px 8px; outline:none; cursor:pointer; min-width:120px; font-weight:500; }
|
|
953
|
-
.status-toggle { display:flex; align-items:center; gap:5px; padding:4px 8px; border-radius:4px; cursor:pointer; font-size:11px; margin-left:2px; transition:background 0.2s; user-select:none; border-left:1px solid var(--border); }
|
|
954
|
-
.status-toggle:hover { background:#f1f5f9; }
|
|
955
|
-
.status-indicator { width:8px; height:8px; border-radius:50%; background:#cbd5e1; transition:background 0.3s; }
|
|
956
|
-
.status-indicator.online { background:var(--ok); box-shadow:0 0 0 2px rgba(16,185,129,0.2); }
|
|
957
|
-
.status-indicator.offline { background:#cbd5e1; }
|
|
958
|
-
|
|
959
|
-
.collapse-btn { background:none; border:none; cursor:pointer; color:var(--t2); padding:6px; display:flex; align-items:center; flex-shrink:0; }
|
|
960
|
-
.collapse-btn:hover { color:var(--t1); }
|
|
961
|
-
|
|
962
|
-
.encrypt-banner { background:linear-gradient(135deg,#e0f2fe,#dbeafe); border:1px solid #bae6fd; border-radius:8px; padding:8px 14px; margin:8px 16px 0; display:flex; align-items:center; gap:8px; font-size:11px; color:#0369a1; flex-shrink:0; }
|
|
963
|
-
.encrypt-banner svg { flex-shrink:0; }
|
|
964
|
-
|
|
965
|
-
.messages { flex:1; padding:16px; overflow-y:auto; display:flex; flex-direction:column; gap:12px; }
|
|
966
|
-
.message { display:flex; flex-direction:column; max-width:80%; }
|
|
967
|
-
.message.sent { align-self:flex-end; align-items:flex-end; }
|
|
968
|
-
.message.received { align-self:flex-start; align-items:flex-start; }
|
|
969
|
-
.bubble { padding:10px 14px; border-radius:12px; font-size:14px; line-height:1.5; word-wrap:break-word; box-shadow:0 1px 2px rgba(0,0,0,0.05); }
|
|
970
|
-
.message.sent .bubble { background:var(--sent); color:#fff; border-bottom-right-radius:2px; }
|
|
971
|
-
.message.received .bubble { background:var(--recv-bg); color:var(--t1); border-bottom-left-radius:2px; border:1px solid var(--border); }
|
|
972
|
-
.msg-meta { font-size:10px; color:var(--t2); margin-bottom:3px; padding:0 4px; }
|
|
973
|
-
|
|
974
|
-
.input-area { padding:12px 16px; background:#fff; border-top:1px solid var(--border); display:flex; align-items:center; gap:10px; flex-shrink:0; }
|
|
975
|
-
.input-area input { flex:1; padding:10px 14px; border-radius:20px; border:1px solid var(--border); font-size:14px; background:#f9fafb; }
|
|
976
|
-
.input-area input:focus { outline:none; border-color:var(--primary); background:#fff; }
|
|
977
|
-
.send-btn { width:40px; height:40px; border-radius:50%; background:var(--primary); border:none; color:#fff; display:flex; align-items:center; justify-content:center; cursor:pointer; flex-shrink:0; }
|
|
978
|
-
.send-btn:hover { background:var(--primary-h); }
|
|
979
|
-
.send-btn:disabled { background:#ccc; cursor:not-allowed; }
|
|
980
|
-
|
|
981
|
-
.modal-overlay { position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:50; display:none; align-items:center; justify-content:center; }
|
|
982
|
-
.modal-overlay.show { display:flex; }
|
|
983
|
-
.modal { background:#fff; width:90%; max-width:400px; border-radius:12px; padding:24px; box-shadow:0 10px 25px rgba(0,0,0,0.1); }
|
|
984
|
-
.modal h3 { margin-bottom:16px; font-size:16px; }
|
|
985
|
-
.modal input[type="text"], .modal input[type="password"], .modal input[type="url"] { width:100%; padding:10px; border:1px solid var(--border); border-radius:8px; margin-bottom:16px; font-size:14px; box-sizing:border-box; }
|
|
986
|
-
.modal input[type="text"]:focus, .modal input[type="password"]:focus, .modal input[type="url"]:focus { outline:none; border-color:var(--primary); }
|
|
987
|
-
.modal input[type="radio"] { width:auto; margin:0; }
|
|
988
|
-
.
|
|
989
|
-
.
|
|
990
|
-
.
|
|
991
|
-
.
|
|
992
|
-
.
|
|
993
|
-
|
|
994
|
-
.
|
|
995
|
-
.
|
|
996
|
-
.
|
|
997
|
-
.
|
|
998
|
-
.
|
|
999
|
-
|
|
1000
|
-
.bubble
|
|
1001
|
-
.bubble
|
|
1002
|
-
.bubble
|
|
1003
|
-
.
|
|
1004
|
-
.bubble
|
|
1005
|
-
.bubble
|
|
1006
|
-
.bubble
|
|
1007
|
-
.bubble
|
|
1008
|
-
.
|
|
1009
|
-
.message {
|
|
1010
|
-
.
|
|
1011
|
-
.
|
|
1012
|
-
.
|
|
1013
|
-
.
|
|
1014
|
-
.
|
|
1015
|
-
.
|
|
1016
|
-
|
|
1017
|
-
.
|
|
1018
|
-
.
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
.
|
|
1028
|
-
.
|
|
1029
|
-
|
|
1030
|
-
.
|
|
1031
|
-
.
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
.
|
|
1041
|
-
.
|
|
1042
|
-
.
|
|
1043
|
-
.
|
|
1044
|
-
.group-
|
|
1045
|
-
.group-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
<div
|
|
1066
|
-
<div
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
<div class="
|
|
1074
|
-
<div class="
|
|
1075
|
-
</div>
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
<div class="
|
|
1086
|
-
<div class="
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
<
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
<
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
<
|
|
1125
|
-
<
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
<
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
<
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
function
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
if(
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
var
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
if(
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
var
|
|
1460
|
-
var
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
if(
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
var
|
|
1506
|
-
var
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
var
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
function
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
var
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
D.
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
//
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
var
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
S.
|
|
1686
|
-
S.
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
var
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
if(
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
function
|
|
1784
|
-
if(
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
var
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
}).
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
var
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
});
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
var
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
var
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
var
|
|
2112
|
-
if(
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
} else {
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
917
|
+
const chatHtml = `<!DOCTYPE html>
|
|
918
|
+
<html lang="zh-CN">
|
|
919
|
+
<head>
|
|
920
|
+
<meta charset="UTF-8">
|
|
921
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
922
|
+
<title>ACP 聊天</title>
|
|
923
|
+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"><\/script>
|
|
924
|
+
<style>
|
|
925
|
+
:root { --primary:#2563eb; --primary-h:#1d4ed8; --bg:#f3f4f6; --sidebar-bg:#fff; --chat-bg:#f9fafb; --border:#e5e7eb; --t1:#1f2937; --t2:#6b7280; --sent:#2563eb; --recv-bg:#fff; --ok:#10b981; }
|
|
926
|
+
* { box-sizing:border-box; margin:0; padding:0; }
|
|
927
|
+
body { font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; background:var(--bg); height:100vh; overflow:hidden; color:var(--t1); }
|
|
928
|
+
#app { display:flex; height:100%; }
|
|
929
|
+
|
|
930
|
+
/* Sidebar */
|
|
931
|
+
.sidebar { width:300px; background:var(--sidebar-bg); border-right:1px solid var(--border); display:flex; flex-direction:column; flex-shrink:0; transition:width 0.25s; overflow:hidden; }
|
|
932
|
+
.sidebar.collapsed { width:0; border-right:none; }
|
|
933
|
+
.sidebar-header { padding:12px 14px; border-bottom:1px solid var(--border); display:flex; flex-direction:column; gap:12px; flex-shrink:0; }
|
|
934
|
+
.header-top { display:flex; justify-content:space-between; align-items:center; width:100%; }
|
|
935
|
+
.sidebar-header .my-aid { font-size:11px; color:#155724; font-family:monospace; background:#d4edda; padding:4px 8px; border-radius:12px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; border:1px solid #c3e6cb; flex:1; margin-right:8px; }
|
|
936
|
+
.new-chat-btn { padding:8px 10px; background:var(--primary); color:#fff; border:none; border-radius:6px; font-size:12px; cursor:pointer; white-space:nowrap; width:100%; text-align:center; }
|
|
937
|
+
.new-chat-btn:hover { background:var(--primary-h); }
|
|
938
|
+
.session-list { flex:1; overflow-y:auto; }
|
|
939
|
+
|
|
940
|
+
/* AID Group */
|
|
941
|
+
.aid-group { border-bottom:1px solid var(--border); }
|
|
942
|
+
.aid-group-header { padding:12px 14px; display:flex; align-items:center; cursor:pointer; background:linear-gradient(135deg,#eef4ff,#e8f0fe); user-select:none; border-left:3px solid var(--primary); transition:all 0.2s; }
|
|
943
|
+
.aid-group-header:hover { background:linear-gradient(135deg,#dbeafe,#d0e4fd); }
|
|
944
|
+
.aid-group-info { flex:1; min-width:0; margin-left:4px; }
|
|
945
|
+
.aid-group-title { font-size:13px; font-weight:700; color:#1e40af; background:linear-gradient(135deg,#dbeafe,#c7d7fe); padding:2px 8px; border-radius:6px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:inline-block; max-width:100%; border:1px solid #bfdbfe; }
|
|
946
|
+
.aid-group-desc { font-size:10px; color:#6b7280; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:3px; display:block; padding-left:2px; }
|
|
947
|
+
.aid-group-arrow { font-size:10px; color:var(--primary); transition:transform 0.2s; flex-shrink:0; }
|
|
948
|
+
.aid-group-arrow.open { transform:rotate(90deg); }
|
|
949
|
+
.aid-group-badge { font-size:10px; background:var(--primary); color:#fff; padding:1px 6px; border-radius:8px; margin-left:8px; flex-shrink:0; }
|
|
950
|
+
.aid-group-add { background:none; border:1px solid var(--border); color:var(--t2); width:22px; height:22px; border-radius:4px; cursor:pointer; font-size:14px; line-height:20px; text-align:center; margin-left:6px; flex-shrink:0; }
|
|
951
|
+
.aid-group-add:hover { background:var(--primary); color:#fff; border-color:var(--primary); }
|
|
952
|
+
.aid-group-del { background:none; border:none; color:var(--t2); width:20px; height:20px; border-radius:4px; cursor:pointer; font-size:12px; line-height:20px; text-align:center; margin-left:4px; flex-shrink:0; display:none; }
|
|
953
|
+
.aid-group-header:hover .aid-group-del { display:block; }
|
|
954
|
+
.aid-group-del:hover { color:#dc3545; background:#ffebeb; }
|
|
955
|
+
.session-del { position:absolute; right:8px; top:50%; transform:translateY(-50%); background:none; border:none; color:var(--t2); font-size:12px; cursor:pointer; display:none; padding:2px; }
|
|
956
|
+
.session-item:hover .session-del { display:block; }
|
|
957
|
+
.session-del:hover { color:#dc3545; }
|
|
958
|
+
.aid-group-sessions { display:none; background:#fafbfc; }
|
|
959
|
+
.aid-group-sessions.open { display:block; }
|
|
960
|
+
|
|
961
|
+
.aid-group-avatar { width:36px; height:36px; border-radius:50%; object-fit:cover; flex-shrink:0; margin-right:8px; box-shadow:0 1px 4px rgba(37,99,235,0.18); border:2px solid #bfdbfe; }
|
|
962
|
+
|
|
963
|
+
.session-item { padding:10px 14px 10px 32px; border-bottom:1px solid #f0f1f3; cursor:pointer; transition:all 0.15s; position:relative; }
|
|
964
|
+
.session-item::before { content:''; position:absolute; left:18px; top:50%; transform:translateY(-50%); width:6px; height:6px; border-radius:50%; background:#d1d5db; }
|
|
965
|
+
.session-item:hover { background:#f0f5ff; }
|
|
966
|
+
.session-item.active { background:#eff6ff; border-left:3px solid var(--primary); padding-left:29px; }
|
|
967
|
+
.session-item.active::before { background:var(--primary); box-shadow:0 0 0 2px rgba(37,99,235,0.2); }
|
|
968
|
+
.session-peer { font-weight:500; font-size:12px; color:var(--t1); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; padding-left:10px; background:#f1f5f9; border-radius:4px; padding:3px 8px 3px 10px; border:1px solid #e8ecf1; }
|
|
969
|
+
.session-item.active .session-peer { background:#dbeafe; border-color:#bfdbfe; color:#1e40af; }
|
|
970
|
+
.session-meta { font-size:10px; color:var(--t2); margin-top:4px; display:flex; align-items:center; gap:6px; padding-left:10px; }
|
|
971
|
+
.tag { font-size:9px; padding:1px 5px; border-radius:3px; color:#fff; font-weight:600; letter-spacing:0.3px; }
|
|
972
|
+
.tag.outgoing { background:var(--ok); }
|
|
973
|
+
.tag.incoming { background:#8b5cf6; }
|
|
974
|
+
|
|
975
|
+
/* Chat Area */
|
|
976
|
+
.chat-area { flex:1; display:flex; flex-direction:column; background:var(--chat-bg); min-width:0; }
|
|
977
|
+
.chat-header { height:54px; padding:0 16px; background:#fff; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; flex-shrink:0; }
|
|
978
|
+
.header-left { display:flex; align-items:center; gap:10px; overflow:hidden; }
|
|
979
|
+
.toggle-sidebar-btn { background:none; border:none; cursor:pointer; color:var(--t2); padding:4px; display:flex; }
|
|
980
|
+
.toggle-sidebar-btn:hover { color:var(--t1); }
|
|
981
|
+
.status-dot { width:8px; height:8px; border-radius:50%; background:#ccc; flex-shrink:0; }
|
|
982
|
+
.status-dot.connected { background:var(--ok); }
|
|
983
|
+
.status-dot.connecting { background:#fbbf24; }
|
|
984
|
+
.chat-title { font-size:15px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
|
985
|
+
|
|
986
|
+
.aid-select-wrap { display:flex; align-items:center; gap:10px; flex-shrink:0; }
|
|
987
|
+
.manage-btn { display:flex; align-items:center; gap:4px; text-decoration:none; color:var(--t2); font-size:12px; padding:6px 10px; border-radius:6px; transition:all 0.2s; background:#fff; border:1px solid var(--border); }
|
|
988
|
+
.manage-btn:hover { background:#f8fafc; color:var(--primary); border-color:var(--primary); }
|
|
989
|
+
.aid-control-group { display:flex; align-items:center; background:#fff; border:1px solid var(--border); border-radius:6px; padding:2px; box-shadow:0 1px 2px rgba(0,0,0,0.03); }
|
|
990
|
+
.aid-select { border:none; background:transparent; font-size:12px; color:var(--t1); padding:5px 8px; outline:none; cursor:pointer; min-width:120px; font-weight:500; }
|
|
991
|
+
.status-toggle { display:flex; align-items:center; gap:5px; padding:4px 8px; border-radius:4px; cursor:pointer; font-size:11px; margin-left:2px; transition:background 0.2s; user-select:none; border-left:1px solid var(--border); }
|
|
992
|
+
.status-toggle:hover { background:#f1f5f9; }
|
|
993
|
+
.status-indicator { width:8px; height:8px; border-radius:50%; background:#cbd5e1; transition:background 0.3s; }
|
|
994
|
+
.status-indicator.online { background:var(--ok); box-shadow:0 0 0 2px rgba(16,185,129,0.2); }
|
|
995
|
+
.status-indicator.offline { background:#cbd5e1; }
|
|
996
|
+
|
|
997
|
+
.collapse-btn { background:none; border:none; cursor:pointer; color:var(--t2); padding:6px; display:flex; align-items:center; flex-shrink:0; }
|
|
998
|
+
.collapse-btn:hover { color:var(--t1); }
|
|
999
|
+
|
|
1000
|
+
.encrypt-banner { background:linear-gradient(135deg,#e0f2fe,#dbeafe); border:1px solid #bae6fd; border-radius:8px; padding:8px 14px; margin:8px 16px 0; display:flex; align-items:center; gap:8px; font-size:11px; color:#0369a1; flex-shrink:0; }
|
|
1001
|
+
.encrypt-banner svg { flex-shrink:0; }
|
|
1002
|
+
|
|
1003
|
+
.messages { flex:1; padding:16px; overflow-y:auto; display:flex; flex-direction:column; gap:12px; }
|
|
1004
|
+
.message { display:flex; flex-direction:column; max-width:80%; }
|
|
1005
|
+
.message.sent { align-self:flex-end; align-items:flex-end; }
|
|
1006
|
+
.message.received { align-self:flex-start; align-items:flex-start; }
|
|
1007
|
+
.bubble { padding:10px 14px; border-radius:12px; font-size:14px; line-height:1.5; word-wrap:break-word; box-shadow:0 1px 2px rgba(0,0,0,0.05); }
|
|
1008
|
+
.message.sent .bubble { background:var(--sent); color:#fff; border-bottom-right-radius:2px; }
|
|
1009
|
+
.message.received .bubble { background:var(--recv-bg); color:var(--t1); border-bottom-left-radius:2px; border:1px solid var(--border); }
|
|
1010
|
+
.msg-meta { font-size:10px; color:var(--t2); margin-bottom:3px; padding:0 4px; }
|
|
1011
|
+
|
|
1012
|
+
.input-area { padding:12px 16px; background:#fff; border-top:1px solid var(--border); display:flex; align-items:center; gap:10px; flex-shrink:0; }
|
|
1013
|
+
.input-area input { flex:1; padding:10px 14px; border-radius:20px; border:1px solid var(--border); font-size:14px; background:#f9fafb; }
|
|
1014
|
+
.input-area input:focus { outline:none; border-color:var(--primary); background:#fff; }
|
|
1015
|
+
.send-btn { width:40px; height:40px; border-radius:50%; background:var(--primary); border:none; color:#fff; display:flex; align-items:center; justify-content:center; cursor:pointer; flex-shrink:0; }
|
|
1016
|
+
.send-btn:hover { background:var(--primary-h); }
|
|
1017
|
+
.send-btn:disabled { background:#ccc; cursor:not-allowed; }
|
|
1018
|
+
|
|
1019
|
+
.modal-overlay { position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:50; display:none; align-items:center; justify-content:center; }
|
|
1020
|
+
.modal-overlay.show { display:flex; }
|
|
1021
|
+
.modal { background:#fff; width:90%; max-width:400px; border-radius:12px; padding:24px; box-shadow:0 10px 25px rgba(0,0,0,0.1); }
|
|
1022
|
+
.modal h3 { margin-bottom:16px; font-size:16px; }
|
|
1023
|
+
.modal input[type="text"], .modal input[type="password"], .modal input[type="url"] { width:100%; padding:10px; border:1px solid var(--border); border-radius:8px; margin-bottom:16px; font-size:14px; box-sizing:border-box; }
|
|
1024
|
+
.modal input[type="text"]:focus, .modal input[type="password"]:focus, .modal input[type="url"]:focus { outline:none; border-color:var(--primary); }
|
|
1025
|
+
.modal input[type="radio"] { width:auto; margin:0; }
|
|
1026
|
+
.group-type-card { flex:1; padding:12px; border:2px solid var(--border); border-radius:10px; cursor:pointer; transition:all 0.2s; background:#fafafa; }
|
|
1027
|
+
.group-type-card:hover { border-color:#b0b0b0; background:#f5f5f5; }
|
|
1028
|
+
.group-type-card.selected { border-color:var(--primary); background:rgba(0,122,255,0.06); }
|
|
1029
|
+
.duty-rule-card { padding:10px 12px; border:2px solid var(--border); border-radius:10px; cursor:pointer; transition:all 0.2s; background:#fafafa; }
|
|
1030
|
+
.duty-rule-card:hover { border-color:#b0b0b0; background:#f5f5f5; }
|
|
1031
|
+
.duty-rule-card.selected { border-color:var(--primary); background:rgba(0,122,255,0.06); }
|
|
1032
|
+
.modal-btns { display:flex; justify-content:flex-end; gap:10px; }
|
|
1033
|
+
.mbtn { padding:8px 16px; border-radius:6px; font-size:13px; cursor:pointer; border:none; }
|
|
1034
|
+
.mbtn-cancel { background:#f3f4f6; color:var(--t1); }
|
|
1035
|
+
.mbtn-ok { background:var(--primary); color:#fff; }
|
|
1036
|
+
.mbtn-ok:disabled { background:#ccc; }
|
|
1037
|
+
|
|
1038
|
+
.bubble p { margin-bottom:0.4em; } .bubble p:last-child { margin-bottom:0; }
|
|
1039
|
+
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 { font-weight:600; line-height:1.25; margin-top:1em; margin-bottom:0.5em; color:inherit; }
|
|
1040
|
+
.bubble h1 { font-size:1.5em; border-bottom:1px solid rgba(0,0,0,0.1); padding-bottom:0.3em; }
|
|
1041
|
+
.bubble h2 { font-size:1.3em; border-bottom:1px solid rgba(0,0,0,0.05); padding-bottom:0.3em; }
|
|
1042
|
+
.bubble h3 { font-size:1.1em; }
|
|
1043
|
+
.bubble ul, .bubble ol { padding-left:1.5em; margin-bottom:0.5em; }
|
|
1044
|
+
.bubble li { margin-bottom:0.2em; }
|
|
1045
|
+
.bubble blockquote { margin:0.5em 0; padding-left:1em; border-left:4px solid rgba(0,0,0,0.1); color:var(--t2); }
|
|
1046
|
+
.bubble a { color:var(--primary); text-decoration:underline; } .bubble a:hover { opacity:0.85; }
|
|
1047
|
+
.message.sent .bubble a { color:#fff; } .message.sent .bubble a:hover { opacity:0.85; }
|
|
1048
|
+
.bubble img { max-width:100%; border-radius:4px; }
|
|
1049
|
+
.bubble code { background:rgba(0,0,0,0.1); padding:2px 4px; border-radius:3px; font-family:monospace; font-size:0.9em; }
|
|
1050
|
+
.bubble pre { background:#2d2d2d; color:#fff; padding:12px; border-radius:6px; overflow-x:auto; margin:8px 0; }
|
|
1051
|
+
.bubble pre code { background:transparent; padding:0; color:inherit; border-radius:0; }
|
|
1052
|
+
.bubble-wrap { position:relative; }
|
|
1053
|
+
.bubble-wrap .copy-msg-btn { position:absolute; top:4px; right:4px; opacity:0; pointer-events:none; background:rgba(0,0,0,0.45); color:#fff; border:none; border-radius:4px; padding:2px 6px; font-size:11px; cursor:pointer; line-height:1.4; z-index:1; transition:opacity 0.15s; }
|
|
1054
|
+
.bubble-wrap:hover .copy-msg-btn { opacity:1; pointer-events:auto; }
|
|
1055
|
+
.bubble-wrap .copy-msg-btn:hover { background:rgba(0,0,0,0.65); }
|
|
1056
|
+
.message.sent .bubble-wrap .copy-msg-btn { background:rgba(255,255,255,0.3); color:#fff; }
|
|
1057
|
+
.message.sent .bubble-wrap .copy-msg-btn:hover { background:rgba(255,255,255,0.5); }
|
|
1058
|
+
.bubble { user-select:text; }
|
|
1059
|
+
.messages { flex:1; padding:16px; overflow-y:auto; display:flex; flex-direction:column; gap:12px; position:relative; }
|
|
1060
|
+
.message { display:flex; flex-direction:row; max-width:85%; gap:8px; }
|
|
1061
|
+
.message.sent { align-self:flex-end; flex-direction:row-reverse; }
|
|
1062
|
+
.message.received { align-self:flex-start; }
|
|
1063
|
+
.msg-avatar { width:40px; height:40px; border-radius:50%; object-fit:cover; flex-shrink:0; box-shadow:0 1px 2px rgba(0,0,0,0.1); margin-top:2px; }
|
|
1064
|
+
.msg-content { display:flex; flex-direction:column; max-width:100%; min-width:0; }
|
|
1065
|
+
.message.sent .msg-content { align-items:flex-end; }
|
|
1066
|
+
.message.received .msg-content { align-items:flex-start; }
|
|
1067
|
+
@media (min-width: 1024px) { .message { max-width: 70%; } }
|
|
1068
|
+
.new-msg-tip { position:sticky; bottom:8px; align-self:center; background:var(--primary); color:#fff; padding:6px 18px; border-radius:20px; font-size:12px; cursor:pointer; box-shadow:0 2px 8px rgba(0,0,0,0.15); z-index:10; display:none; transition:opacity 0.2s; animation:newMsgBounce 0.3s ease; }
|
|
1069
|
+
.new-msg-tip:hover { background:var(--primary-h); }
|
|
1070
|
+
@keyframes newMsgBounce { 0%{transform:translateY(10px);opacity:0} 100%{transform:translateY(0);opacity:1} }
|
|
1071
|
+
|
|
1072
|
+
@media (max-width:768px) {
|
|
1073
|
+
.sidebar { position:absolute; height:100%; z-index:20; width:280px; }
|
|
1074
|
+
.sidebar.collapsed { width:0; }
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/* Group UI Styles */
|
|
1078
|
+
.tab-bar { display:flex; border-bottom:1px solid var(--border); flex-shrink:0; }
|
|
1079
|
+
.tab-bar .tab { flex:1; padding:8px 0; text-align:center; font-size:12px; font-weight:500; cursor:pointer; color:var(--t2); border-bottom:2px solid transparent; transition:all 0.2s; }
|
|
1080
|
+
.tab-bar .tab.active { color:var(--primary); border-bottom-color:var(--primary); }
|
|
1081
|
+
.tab-bar .tab:hover { color:var(--t1); }
|
|
1082
|
+
.group-list { flex:1; overflow-y:auto; }
|
|
1083
|
+
.group-item { padding:12px 14px; border-bottom:1px solid #f3f4f6; cursor:pointer; transition:background 0.15s; position:relative; }
|
|
1084
|
+
.group-item:hover { background:#f5f7fa; }
|
|
1085
|
+
.group-item.active { background:#eff6ff; border-left:3px solid var(--primary); padding-left:11px; }
|
|
1086
|
+
.group-item-name { font-size:13px; font-weight:600; color:var(--t1); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
1087
|
+
.group-item-meta { font-size:10px; color:var(--t2); margin-top:2px; }
|
|
1088
|
+
.group-item-del { position:absolute; right:8px; top:12px; background:none; border:none; color:var(--t2); font-size:12px; cursor:pointer; display:none; padding:2px; }
|
|
1089
|
+
.group-item:hover .group-item-del { display:block; }
|
|
1090
|
+
.group-item-del:hover { color:#dc3545; }
|
|
1091
|
+
.group-actions { padding:8px 14px; display:flex; gap:6px; flex-shrink:0; border-bottom:1px solid var(--border); }
|
|
1092
|
+
.group-actions .gbtn { flex:1; padding:6px 0; border:1px solid var(--border); border-radius:6px; font-size:11px; cursor:pointer; background:#fff; color:var(--t1); text-align:center; }
|
|
1093
|
+
.group-actions .gbtn:hover { background:#f1f5f9; border-color:var(--primary); color:var(--primary); }
|
|
1094
|
+
.group-info-bar { padding:6px 16px; background:#f0f9ff; border-bottom:1px solid #bae6fd; font-size:11px; color:#0369a1; display:flex; align-items:center; gap:8px; flex-shrink:0; }
|
|
1095
|
+
.group-info-bar .copy-link { cursor:pointer; text-decoration:underline; }
|
|
1096
|
+
.group-info-bar .copy-link:hover { color:#0284c7; }
|
|
1097
|
+
</style>
|
|
1098
|
+
<!-- CHATHTML_STYLE_END -->
|
|
1099
|
+
</head>
|
|
1100
|
+
<body>
|
|
1101
|
+
<div id="app">
|
|
1102
|
+
<div class="sidebar" id="sidebar">
|
|
1103
|
+
<div class="sidebar-header">
|
|
1104
|
+
<div class="header-top">
|
|
1105
|
+
<span class="my-aid" id="myAid">Loading...</span>
|
|
1106
|
+
<button class="collapse-btn" onclick="toggleSidebar()" title="收起面板">
|
|
1107
|
+
<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M15 19l-7-7 7-7"></path></svg>
|
|
1108
|
+
</button>
|
|
1109
|
+
</div>
|
|
1110
|
+
<div class="tab-bar">
|
|
1111
|
+
<div class="tab active" id="tabP2P" onclick="switchTab('p2p')">聊天</div>
|
|
1112
|
+
<div class="tab" id="tabGroup" onclick="switchTab('group')">群组</div>
|
|
1113
|
+
</div>
|
|
1114
|
+
</div>
|
|
1115
|
+
<!-- P2P panel -->
|
|
1116
|
+
<div id="p2pPanel">
|
|
1117
|
+
<div style="padding:8px 14px;flex-shrink:0;"><button class="new-chat-btn" onclick="showModal()">+ 连接龙虾</button></div>
|
|
1118
|
+
<div class="session-list" id="sessionList"></div>
|
|
1119
|
+
</div>
|
|
1120
|
+
<!-- Group panel -->
|
|
1121
|
+
<div id="groupPanel" style="display:none;flex:1;display:none;flex-direction:column;overflow:hidden;">
|
|
1122
|
+
<div class="group-actions">
|
|
1123
|
+
<div class="gbtn" onclick="showCreateGroupModal()">创建群组</div>
|
|
1124
|
+
<div class="gbtn" onclick="showJoinGroupModal()">加入群组</div>
|
|
1125
|
+
<div class="gbtn" onclick="showMyGroups()">我的群</div>
|
|
1126
|
+
</div>
|
|
1127
|
+
<div class="group-list" id="groupList"><div style="padding:20px;text-align:center;color:#999;font-size:12px;">暂无群组</div></div>
|
|
1128
|
+
</div>
|
|
1129
|
+
</div>
|
|
1130
|
+
<div class="chat-area">
|
|
1131
|
+
<div class="chat-header">
|
|
1132
|
+
<div class="header-left">
|
|
1133
|
+
<button class="toggle-sidebar-btn" onclick="toggleSidebar()">
|
|
1134
|
+
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M3 12h18M3 6h18M3 18h18"></path></svg>
|
|
1135
|
+
</button>
|
|
1136
|
+
<div class="status-dot" id="statusDot"></div>
|
|
1137
|
+
<div class="chat-title" id="chatTitle">未选择会话</div>
|
|
1138
|
+
</div>
|
|
1139
|
+
<div class="aid-select-wrap">
|
|
1140
|
+
<a href="https://agentunion.net" target="_blank" class="manage-btn" title="AgentUnion排行榜">AgentUnion排行榜</a>
|
|
1141
|
+
<a href="https://github.com/auliwenjiang/agentcp" target="_blank" class="manage-btn" title="ACP 开源GitHub">ACP 开源GitHub</a>
|
|
1142
|
+
<a href="/" class="manage-btn" title="ACP 身份管理">
|
|
1143
|
+
<svg width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg> 身份管理
|
|
1144
|
+
</a>
|
|
1145
|
+
<div class="aid-control-group">
|
|
1146
|
+
<select class="aid-select" id="aidSelect" onchange="switchAid(this.value)"></select>
|
|
1147
|
+
<div class="status-toggle" id="aidStatusToggle" onclick="toggleOnline()" title="点击切换在线状态">
|
|
1148
|
+
<div class="status-indicator" id="aidOnlineDot"></div>
|
|
1149
|
+
<span id="aidStatusText" style="color:var(--t2);">...</span>
|
|
1150
|
+
</div>
|
|
1151
|
+
</div>
|
|
1152
|
+
</div>
|
|
1153
|
+
</div>
|
|
1154
|
+
<div class="encrypt-banner" id="encryptBanner">
|
|
1155
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
|
|
1156
|
+
<span>ACP Agent 点对点加密通信 — 消息经端到端加密传输,仅通信双方可读</span>
|
|
1157
|
+
</div>
|
|
1158
|
+
<div class="group-info-bar" id="groupInfoBar" style="display:none;">
|
|
1159
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>
|
|
1160
|
+
<span id="groupInfoText">群组</span>
|
|
1161
|
+
<span class="copy-link" id="groupInviteBtn" onclick="generateInviteLink()" title="生成邀请链接" style="display:none;">生成邀请链接</span>
|
|
1162
|
+
<span class="copy-link" id="groupCopyLinkBtn" onclick="copyGroupLink()" title="复制群链接" style="display:none;">复制群链接</span>
|
|
1163
|
+
<span class="copy-link" onclick="showGroupMembers()" title="查看成员">成员</span>
|
|
1164
|
+
<span class="copy-link" id="groupRuleBtn" onclick="showGroupRuleModal()" title="群规则" style="display:none;">群规则</span>
|
|
1165
|
+
<span class="copy-link" id="groupReviewBtn" onclick="showPendingRequests()" title="查看入群申请" style="display:none;">审核</span>
|
|
1166
|
+
<span class="copy-link" id="groupDutyBtn" onclick="showDutyConfigModal()" title="值班设置" style="display:none;">值班</span>
|
|
1167
|
+
</div>
|
|
1168
|
+
<div class="messages" id="messages">
|
|
1169
|
+
<div style="text-align:center;color:var(--t2);margin-top:40px;">
|
|
1170
|
+
<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="#cbd5e1" stroke-width="1.5" style="margin-bottom:10px;"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
|
|
1171
|
+
<div style="font-size:14px;font-weight:500;color:#64748b;margin-bottom:4px;">ACP Agent 安全通信</div>
|
|
1172
|
+
<div style="font-size:12px;color:#94a3b8;">选择或创建一个会话,开始点对点加密聊天</div>
|
|
1173
|
+
</div>
|
|
1174
|
+
<div class="new-msg-tip" id="newMsgTip" onclick="scrollToBottom()">↓ 有新消息</div>
|
|
1175
|
+
</div>
|
|
1176
|
+
<div class="input-area">
|
|
1177
|
+
<input type="text" id="messageInput" placeholder="输入消息..." onkeypress="if(event.key==='Enter')sendMessage()">
|
|
1178
|
+
<button class="send-btn" id="sendBtn" onclick="sendMessage()">
|
|
1179
|
+
<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"></path></svg>
|
|
1180
|
+
</button>
|
|
1181
|
+
</div>
|
|
1182
|
+
</div>
|
|
1183
|
+
</div>
|
|
1184
|
+
<div class="modal-overlay" id="modal">
|
|
1185
|
+
<div class="modal">
|
|
1186
|
+
<h3>连接 ACP 龙虾</h3>
|
|
1187
|
+
<input type="text" id="targetAidInput" placeholder="输入对方 AID" onkeypress="if(event.key==='Enter')doConnect()">
|
|
1188
|
+
<div class="modal-btns">
|
|
1189
|
+
<button class="mbtn mbtn-cancel" onclick="hideModal()">取消</button>
|
|
1190
|
+
<button class="mbtn mbtn-ok" id="connectBtn" onclick="doConnect()">连接</button>
|
|
1191
|
+
</div>
|
|
1192
|
+
</div>
|
|
1193
|
+
</div>
|
|
1194
|
+
<div class="modal-overlay" id="createGroupModal">
|
|
1195
|
+
<div class="modal" style="max-width:460px;">
|
|
1196
|
+
<h3>创建群组</h3>
|
|
1197
|
+
<input type="text" id="groupNameInput" placeholder="输入群组名称">
|
|
1198
|
+
<textarea id="groupDescInput" placeholder="输入群组描述(必填)" style="width:100%;padding:10px;border:1px solid var(--border);border-radius:8px;margin-bottom:16px;font-size:14px;resize:vertical;min-height:60px;font-family:inherit;box-sizing:border-box;"></textarea>
|
|
1199
|
+
<div style="margin-bottom:16px;">
|
|
1200
|
+
<label style="font-size:13px;color:var(--t2);margin-bottom:10px;display:block;">群组类型</label>
|
|
1201
|
+
<div style="display:flex;gap:10px;" id="groupTypeCards">
|
|
1202
|
+
<div class="group-type-card selected" data-value="public" onclick="selectGroupType(this)">
|
|
1203
|
+
<div style="display:flex;align-items:center;gap:6px;margin-bottom:6px;">
|
|
1204
|
+
<span style="font-size:18px;">🌐</span>
|
|
1205
|
+
<span style="font-size:14px;font-weight:600;">公开群</span>
|
|
1206
|
+
</div>
|
|
1207
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.5;">Agent 可通过群链接直接加入,无需审核</div>
|
|
1208
|
+
</div>
|
|
1209
|
+
<div class="group-type-card" data-value="private" onclick="selectGroupType(this)">
|
|
1210
|
+
<div style="display:flex;align-items:center;gap:6px;margin-bottom:6px;">
|
|
1211
|
+
<span style="font-size:18px;">🔒</span>
|
|
1212
|
+
<span style="font-size:14px;font-weight:600;">私密群</span>
|
|
1213
|
+
</div>
|
|
1214
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.5;">带邀请码的链接可直接加入(一码一 Agent);不带邀请码需群主/管理员审核</div>
|
|
1215
|
+
</div>
|
|
1216
|
+
</div>
|
|
1217
|
+
</div>
|
|
1218
|
+
<div style="margin-bottom:16px;">
|
|
1219
|
+
<label style="font-size:13px;color:var(--t2);margin-bottom:10px;display:block;">值班规则</label>
|
|
1220
|
+
<div style="display:flex;flex-direction:column;gap:8px;" id="dutyRuleCards">
|
|
1221
|
+
<div class="duty-rule-card selected" data-value="rotation" onclick="selectDutyRule(this)">
|
|
1222
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
1223
|
+
<span style="font-size:16px;">🔄</span>
|
|
1224
|
+
<span style="font-size:13px;font-weight:600;">群成员轮流值班</span>
|
|
1225
|
+
</div>
|
|
1226
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.4;margin-top:4px;padding-left:24px;">群成员按顺序轮流担任值班 Agent,负责消息分发决策</div>
|
|
1227
|
+
</div>
|
|
1228
|
+
<div class="duty-rule-card" data-value="fixed" onclick="selectDutyRule(this)">
|
|
1229
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
1230
|
+
<span style="font-size:16px;">📌</span>
|
|
1231
|
+
<span style="font-size:13px;font-weight:600;">固定 Agent 值班</span>
|
|
1232
|
+
</div>
|
|
1233
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.4;margin-top:4px;padding-left:24px;">指定固定的 Agent 负责值班,创建后可在群设置中配置</div>
|
|
1234
|
+
</div>
|
|
1235
|
+
<div class="duty-rule-card" data-value="none" onclick="selectDutyRule(this)">
|
|
1236
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
1237
|
+
<span style="font-size:16px;">⛔</span>
|
|
1238
|
+
<span style="font-size:13px;font-weight:600;">不值班</span>
|
|
1239
|
+
</div>
|
|
1240
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.4;margin-top:4px;padding-left:24px;">关闭值班功能,所有消息直接广播给全体成员</div>
|
|
1241
|
+
</div>
|
|
1242
|
+
</div>
|
|
1243
|
+
</div>
|
|
1244
|
+
<div class="modal-btns">
|
|
1245
|
+
<button class="mbtn mbtn-cancel" onclick="hideCreateGroupModal()">取消</button>
|
|
1246
|
+
<button class="mbtn mbtn-ok" id="createGroupBtn" onclick="doCreateGroup()">创建</button>
|
|
1247
|
+
</div>
|
|
1248
|
+
</div>
|
|
1249
|
+
</div>
|
|
1250
|
+
<div class="modal-overlay" id="joinGroupModal">
|
|
1251
|
+
<div class="modal">
|
|
1252
|
+
<h3>加入群组</h3>
|
|
1253
|
+
<input type="text" id="joinGroupUrlInput" placeholder="输入群聊链接或邀请链接" onkeypress="if(event.key==='Enter')doJoinGroup()">
|
|
1254
|
+
<div style="font-size:11px;color:var(--t2);margin:-8px 0 12px 2px;">粘贴邀请链接可直接加入,普通群链接将发送入群申请</div>
|
|
1255
|
+
<div class="modal-btns">
|
|
1256
|
+
<button class="mbtn mbtn-cancel" onclick="hideJoinGroupModal()">取消</button>
|
|
1257
|
+
<button class="mbtn mbtn-ok" id="joinGroupBtn" onclick="doJoinGroup()">加入</button>
|
|
1258
|
+
</div>
|
|
1259
|
+
</div>
|
|
1260
|
+
</div>
|
|
1261
|
+
<div class="modal-overlay" id="groupRuleModal">
|
|
1262
|
+
<div class="modal" style="max-width:560px;">
|
|
1263
|
+
<h3>群规则</h3>
|
|
1264
|
+
<div id="groupRuleContent" style="max-height:450px;overflow-y:auto;margin-bottom:16px;font-size:13px;"></div>
|
|
1265
|
+
<div class="modal-btns">
|
|
1266
|
+
<button class="mbtn mbtn-cancel" onclick="hideGroupRuleModal()">关闭</button>
|
|
1267
|
+
</div>
|
|
1268
|
+
</div>
|
|
1269
|
+
</div>
|
|
1270
|
+
<div class="modal-overlay" id="dutyConfigModal">
|
|
1271
|
+
<div class="modal" style="max-width:480px;">
|
|
1272
|
+
<h3>值班设置</h3>
|
|
1273
|
+
<div style="display:flex;flex-direction:column;gap:8px;margin-bottom:16px;" id="dutyConfigCards">
|
|
1274
|
+
<div class="duty-rule-card" data-value="rotation" onclick="selectDutyConfigCard(this)">
|
|
1275
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
1276
|
+
<span style="font-size:16px;">🔄</span>
|
|
1277
|
+
<span style="font-size:13px;font-weight:600;">群成员轮流值班</span>
|
|
1278
|
+
</div>
|
|
1279
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.4;margin-top:4px;padding-left:24px;">群成员按顺序轮流担任值班 Agent,负责消息分发决策</div>
|
|
1280
|
+
</div>
|
|
1281
|
+
<div class="duty-rule-card" data-value="fixed" onclick="selectDutyConfigCard(this)">
|
|
1282
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
1283
|
+
<span style="font-size:16px;">📌</span>
|
|
1284
|
+
<span style="font-size:13px;font-weight:600;">固定 Agent 值班</span>
|
|
1285
|
+
</div>
|
|
1286
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.4;margin-top:4px;padding-left:24px;">指定固定的 Agent 负责值班,创建后可在群设置中配置</div>
|
|
1287
|
+
</div>
|
|
1288
|
+
<div class="duty-rule-card" data-value="none" onclick="selectDutyConfigCard(this)">
|
|
1289
|
+
<div style="display:flex;align-items:center;gap:8px;">
|
|
1290
|
+
<span style="font-size:16px;">⛔</span>
|
|
1291
|
+
<span style="font-size:13px;font-weight:600;">不值班</span>
|
|
1292
|
+
</div>
|
|
1293
|
+
<div style="font-size:11px;color:var(--t2);line-height:1.4;margin-top:4px;padding-left:24px;">关闭值班功能,所有消息直接广播给全体成员</div>
|
|
1294
|
+
</div>
|
|
1295
|
+
</div>
|
|
1296
|
+
<div class="modal-btns">
|
|
1297
|
+
<button class="mbtn mbtn-cancel" onclick="hideDutyConfigModal()">取消</button>
|
|
1298
|
+
<button class="mbtn mbtn-ok" id="saveDutyConfigBtn" onclick="saveDutyConfig()">保存</button>
|
|
1299
|
+
</div>
|
|
1300
|
+
</div>
|
|
1301
|
+
</div>
|
|
1302
|
+
<div class="modal-overlay" id="membersModal">
|
|
1303
|
+
<div class="modal" style="max-width:520px;">
|
|
1304
|
+
<h3>群组成员</h3>
|
|
1305
|
+
<div id="membersList" style="max-height:400px;overflow-y:auto;margin-bottom:16px;font-size:13px;"></div>
|
|
1306
|
+
<div class="modal-btns">
|
|
1307
|
+
<button class="mbtn mbtn-cancel" onclick="hideMembersModal()">关闭</button>
|
|
1308
|
+
</div>
|
|
1309
|
+
</div>
|
|
1310
|
+
</div>
|
|
1311
|
+
<div class="modal-overlay" id="pendingRequestsModal">
|
|
1312
|
+
<div class="modal" style="max-width:480px;">
|
|
1313
|
+
<h3>入群申请</h3>
|
|
1314
|
+
<div id="pendingRequestsList" style="max-height:360px;overflow-y:auto;margin-bottom:16px;font-size:13px;"></div>
|
|
1315
|
+
<div class="modal-btns">
|
|
1316
|
+
<button class="mbtn mbtn-cancel" onclick="hidePendingRequestsModal()">关闭</button>
|
|
1317
|
+
</div>
|
|
1318
|
+
</div>
|
|
1319
|
+
</div>
|
|
1320
|
+
<div class="modal-overlay" id="myGroupsModal">
|
|
1321
|
+
<div class="modal" style="max-width:560px;">
|
|
1322
|
+
<h3>我的群</h3>
|
|
1323
|
+
<div id="myGroupsContent" style="max-height:420px;overflow-y:auto;margin-bottom:16px;font-size:13px;"></div>
|
|
1324
|
+
<div class="modal-btns">
|
|
1325
|
+
<button class="mbtn mbtn-cancel" onclick="hideMyGroupsModal()">关闭</button>
|
|
1326
|
+
</div>
|
|
1327
|
+
</div>
|
|
1328
|
+
</div>
|
|
1329
|
+
<div id="switchAidOverlay" style="position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.45);z-index:999;display:none;align-items:center;justify-content:center;flex-direction:column;gap:16px;">
|
|
1330
|
+
<div style="width:36px;height:36px;border:3px solid rgba(255,255,255,0.3);border-top-color:#fff;border-radius:50%;animation:spin 0.8s linear infinite;"></div>
|
|
1331
|
+
<div id="switchAidMsg" style="color:#fff;font-size:15px;font-weight:500;">切换身份中...</div>
|
|
1332
|
+
</div>
|
|
1333
|
+
<div id="switchGroupOverlay" style="position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:rgba(0,0,0,0.75);z-index:999;display:none;align-items:center;justify-content:center;flex-direction:column;gap:12px;padding:28px 40px;border-radius:12px;box-shadow:0 4px 24px rgba(0,0,0,0.3);">
|
|
1334
|
+
<div style="width:32px;height:32px;border:3px solid rgba(255,255,255,0.3);border-top-color:#fff;border-radius:50%;animation:spin 0.8s linear infinite;"></div>
|
|
1335
|
+
<div id="switchGroupMsg" style="color:#fff;font-size:14px;font-weight:500;">加载群组中...</div>
|
|
1336
|
+
</div>
|
|
1337
|
+
<style>@keyframes spin{to{transform:rotate(360deg)}}</style>
|
|
1338
|
+
<script>
|
|
1339
|
+
var S = { aid:'', sid:null, sessionId:null, sessions:[], status:'disconnected', expanded:{}, sidebarOpen:true, aidList:[], closed:false, tab:'p2p', activeGroupId:null, groups:[], groupMsgs:[], groupTargetAid:'', isGroupCreator:false };
|
|
1340
|
+
var D = {};
|
|
1341
|
+
var agentInfoCache = {};
|
|
1342
|
+
function $(id){ return document.getElementById(id); }
|
|
1343
|
+
function getAvatarSrc(type) {
|
|
1344
|
+
if (type === 'openclaw') return '/assets/openclaw.png';
|
|
1345
|
+
if (type === 'human') return '/assets/human.png';
|
|
1346
|
+
return '/assets/agent.png';
|
|
1347
|
+
}
|
|
1348
|
+
async function fetchAgentInfo(aid) {
|
|
1349
|
+
if (agentInfoCache[aid]) return agentInfoCache[aid];
|
|
1350
|
+
try {
|
|
1351
|
+
var r = await fetch('/api/agent-info?aid=' + encodeURIComponent(aid));
|
|
1352
|
+
var d = await r.json();
|
|
1353
|
+
if (d.type || d.name) { agentInfoCache[aid] = d; }
|
|
1354
|
+
return d;
|
|
1355
|
+
} catch(e) { return { type:'', name:'', description:'', tags:[] }; }
|
|
1356
|
+
}
|
|
1357
|
+
async function deleteSession(e, sessionId){
|
|
1358
|
+
e.stopPropagation();
|
|
1359
|
+
if(!confirm('确认删除该会话?')) return;
|
|
1360
|
+
try {
|
|
1361
|
+
var r = await fetch('/api/sessions/delete', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sessionId: sessionId, aid: S.aid }) });
|
|
1362
|
+
var d = await r.json();
|
|
1363
|
+
if(d.success){
|
|
1364
|
+
if(S.sid === sessionId){ S.sid = null; S.sessionId=null; D.title.textContent='未选择会话'; D.msgs.innerHTML=''; D.input.disabled=false; }
|
|
1365
|
+
D.sList.dataset.s=''; // force update
|
|
1366
|
+
loadSessions();
|
|
1367
|
+
} else { alert(d.error || '删除失败'); }
|
|
1368
|
+
} catch(err){ alert('删除失败: ' + err.message); }
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
async function deletePeer(e, peerAid){
|
|
1372
|
+
e.stopPropagation();
|
|
1373
|
+
if(!confirm('确认删除与 ' + peerAid + ' 的所有会话?')) return;
|
|
1374
|
+
try {
|
|
1375
|
+
var r = await fetch('/api/peers/delete', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ peerAid: peerAid, aid: S.aid }) });
|
|
1376
|
+
var d = await r.json();
|
|
1377
|
+
if(d.success){
|
|
1378
|
+
S.sid = null; S.sessionId=null; D.title.textContent='未选择会话'; D.msgs.innerHTML='';
|
|
1379
|
+
D.sList.dataset.s=''; // force update
|
|
1380
|
+
loadSessions();
|
|
1381
|
+
} else { alert(d.error || '删除失败'); }
|
|
1382
|
+
} catch(err){ alert('删除失败: ' + err.message); }
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
function initDom(){ D.myAid=$('myAid'); D.sList=$('sessionList'); D.title=$('chatTitle'); D.msgs=$('messages'); D.input=$('messageInput'); D.sendBtn=$('sendBtn'); D.dot=$('statusDot'); D.modal=$('modal'); D.tInput=$('targetAidInput'); D.cBtn=$('connectBtn'); D.sidebar=$('sidebar'); D.aidSel=$('aidSelect'); D.aidDot=$('aidOnlineDot'); D.aidStatusToggle=$('aidStatusToggle'); D.aidStatusText=$('aidStatusText'); D.p2pPanel=$('p2pPanel'); D.groupPanel=$('groupPanel'); D.groupList=$('groupList'); D.groupInfoBar=$('groupInfoBar'); D.groupInfoText=$('groupInfoText'); D.tabP2P=$('tabP2P'); D.tabGroup=$('tabGroup'); D.encryptBanner=$('encryptBanner'); D.newMsgTip=$('newMsgTip'); }
|
|
1386
|
+
|
|
1387
|
+
function isAtBottom(){ return D.msgs.scrollHeight-D.msgs.scrollTop-D.msgs.clientHeight<150; }
|
|
1388
|
+
function scrollToBottom(){ D.msgs.scrollTop=D.msgs.scrollHeight; hideNewMsgTip(); }
|
|
1389
|
+
function showNewMsgTip(){ if(D.newMsgTip) D.newMsgTip.style.display='block'; }
|
|
1390
|
+
function hideNewMsgTip(){ if(D.newMsgTip) D.newMsgTip.style.display='none'; }
|
|
1391
|
+
|
|
1392
|
+
async function init(){
|
|
1393
|
+
initDom();
|
|
1394
|
+
// 监听滚动,用户滚到底部时自动隐藏新消息提示
|
|
1395
|
+
D.msgs.addEventListener('scroll',function(){ if(isAtBottom()) hideNewMsgTip(); });
|
|
1396
|
+
try {
|
|
1397
|
+
var r = await fetch('/api/aid'); var d = await r.json();
|
|
1398
|
+
S.aidList=d.aidStatus||[];
|
|
1399
|
+
if(S.aidList.length){
|
|
1400
|
+
// 优先从当前标签页恢复,再 fallback 到全局默认
|
|
1401
|
+
var saved=sessionStorage.getItem('selectedAid')||localStorage.getItem('selectedAid');
|
|
1402
|
+
var found=saved&&S.aidList.find(function(a){ return a.aid===saved; });
|
|
1403
|
+
S.aid=(found?saved:S.aidList[0].aid)||'';
|
|
1404
|
+
if(S.aid) sessionStorage.setItem('selectedAid',S.aid);
|
|
1405
|
+
}
|
|
1406
|
+
if(S.aid){
|
|
1407
|
+
D.myAid.textContent='我的身份: '+S.aid; D.myAid.title=S.aid;
|
|
1408
|
+
renderAidSelect();
|
|
1409
|
+
connectGroupWs();
|
|
1410
|
+
fetch('/api/ws/status?aid='+encodeURIComponent(S.aid)).then(function(r){return r.json();}).then(function(d){updateDot(d.status);}).catch(function(){});
|
|
1411
|
+
loadSessions();
|
|
1412
|
+
} else { window.location.href='/'; }
|
|
1413
|
+
} catch(e){ console.error(e); }
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
function renderAidSelect(){
|
|
1417
|
+
var html='';
|
|
1418
|
+
var curOnline=false;
|
|
1419
|
+
S.aidList.forEach(function(a){
|
|
1420
|
+
var sel=a.aid===S.aid?' selected':'';
|
|
1421
|
+
if(a.aid===S.aid) curOnline=a.online;
|
|
1422
|
+
html+='<option value="'+escH(a.aid)+'"'+sel+'>'+escH(a.aid)+'</option>';
|
|
1423
|
+
});
|
|
1424
|
+
D.aidSel.innerHTML=html;
|
|
1425
|
+
D.aidDot.className='status-indicator '+(curOnline?'online':'offline');
|
|
1426
|
+
D.aidStatusText.textContent=curOnline?'已上线':'离线';
|
|
1427
|
+
D.aidStatusText.style.color=curOnline?'#10b981':'#64748b';
|
|
1428
|
+
D.aidStatusToggle.title=curOnline?'点击下线':'点击上线';
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
async function switchAid(aid){
|
|
1432
|
+
if(aid===S.aid) return;
|
|
1433
|
+
var overlay=$('switchAidOverlay');
|
|
1434
|
+
var msg=$('switchAidMsg');
|
|
1435
|
+
overlay.style.display='flex';
|
|
1436
|
+
msg.textContent='切换身份中...';
|
|
1437
|
+
try {
|
|
1438
|
+
// 1. 切换本地状态
|
|
1439
|
+
S.aid=aid;
|
|
1440
|
+
S.sid=null; S.sessionId=null;
|
|
1441
|
+
_groupInited=false;
|
|
1442
|
+
localStorage.setItem('selectedAid',aid);
|
|
1443
|
+
sessionStorage.setItem('selectedAid',aid);
|
|
1444
|
+
D.myAid.textContent='我的身份: '+aid; D.myAid.title=aid;
|
|
1445
|
+
renderAidSelect();
|
|
1446
|
+
// 2. 通知服务端绑定 aid
|
|
1447
|
+
if(_groupWs&&_groupWs.readyState===WebSocket.OPEN){
|
|
1448
|
+
_groupWs.send(JSON.stringify({type:'bind_aid',aid:aid}));
|
|
1449
|
+
}
|
|
1450
|
+
// 3. 确保 AID 上线(阻塞等待)
|
|
1451
|
+
var info=S.aidList.find(function(a){ return a.aid===aid; });
|
|
1452
|
+
if(!info||!info.online){
|
|
1453
|
+
msg.textContent='正在上线...';
|
|
1454
|
+
var r=await fetch('/api/ws/start',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({aid:aid})});
|
|
1455
|
+
var d=await r.json();
|
|
1456
|
+
if(!d.success){
|
|
1457
|
+
msg.textContent='上线失败: '+(d.error||'未知错误');
|
|
1458
|
+
await new Promise(function(ok){setTimeout(ok,2000);});
|
|
1459
|
+
overlay.style.display='none';
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
// 4. 确认在线状态
|
|
1464
|
+
msg.textContent='检查状态...';
|
|
1465
|
+
var sr=await fetch('/api/ws/status?aid='+encodeURIComponent(aid));
|
|
1466
|
+
var sd=await sr.json();
|
|
1467
|
+
updateDot(sd.status);
|
|
1468
|
+
// 5. 上线成功,切换页面内容
|
|
1469
|
+
D.msgs.innerHTML=''; D.title.textContent='未选择会话';
|
|
1470
|
+
D.sList.dataset.s='';
|
|
1471
|
+
await loadSessions();
|
|
1472
|
+
} catch(e){
|
|
1473
|
+
msg.textContent='切换失败: '+(e.message||'未知错误');
|
|
1474
|
+
await new Promise(function(ok){setTimeout(ok,2000);});
|
|
1475
|
+
} finally {
|
|
1476
|
+
overlay.style.display='none';
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
async function toggleOnline(){
|
|
1481
|
+
var info=S.aidList.find(function(a){ return a.aid===S.aid; });
|
|
1482
|
+
var isOnline=info&&info.online;
|
|
1483
|
+
D.aidStatusText.textContent='...';
|
|
1484
|
+
try {
|
|
1485
|
+
if(isOnline){
|
|
1486
|
+
await fetch('/api/aid/offline',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({aid:S.aid})});
|
|
1487
|
+
} else {
|
|
1488
|
+
await fetch('/api/ws/start',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({aid:S.aid})});
|
|
1489
|
+
}
|
|
1490
|
+
// AID 状态变更通过 WS 推送 aid_status 自动更新,无需再拉取
|
|
1491
|
+
} catch(e){}
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
async function loadSessions(){
|
|
1495
|
+
if(!S.aid) return;
|
|
1496
|
+
try {
|
|
1497
|
+
var r=await fetch('/api/sessions?aid='+encodeURIComponent(S.aid));
|
|
1498
|
+
var d=await r.json();
|
|
1499
|
+
if(d.sessions) updateSessions(d.sessions, S.sid);
|
|
1500
|
+
} catch(e){}
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
async function loadMessages(){
|
|
1504
|
+
if(!S.aid||!S.sid||S.tab!=='p2p') return;
|
|
1505
|
+
try {
|
|
1506
|
+
var r=await fetch('/api/messages?aid='+encodeURIComponent(S.aid)+'&sessionId='+encodeURIComponent(S.sid));
|
|
1507
|
+
var d=await r.json();
|
|
1508
|
+
S.closed=d.closed||false;
|
|
1509
|
+
D.msgs.dataset.s='';
|
|
1510
|
+
if(d.messages) renderMsgs(d.messages, S.closed);
|
|
1511
|
+
} catch(e){}
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
// legacy poll kept for compatibility (no-op, replaced by WS push)
|
|
1515
|
+
function poll(){}
|
|
1516
|
+
|
|
1517
|
+
function updateSessions(sessions, activeId){
|
|
1518
|
+
var sig=JSON.stringify(sessions)+activeId+S.sid;
|
|
1519
|
+
if(D.sList.dataset.s===sig) return;
|
|
1520
|
+
D.sList.dataset.s=sig;
|
|
1521
|
+
if(activeId && S.sid!==activeId) S.sid=activeId;
|
|
1522
|
+
S.sessions=sessions;
|
|
1523
|
+
|
|
1524
|
+
var groups={};
|
|
1525
|
+
sessions.forEach(function(s){
|
|
1526
|
+
var peer=s.peerAid||'unknown';
|
|
1527
|
+
if(!groups[peer]) groups[peer]=[];
|
|
1528
|
+
groups[peer].push(s);
|
|
1529
|
+
});
|
|
1530
|
+
|
|
1531
|
+
if(!sessions.length){
|
|
1532
|
+
D.sList.innerHTML='<div style="padding:20px;text-align:center;color:#999;font-size:12px;">暂无会话</div>';
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
var html='';
|
|
1537
|
+
var peers=Object.keys(groups);
|
|
1538
|
+
peers.sort(function(a,b){
|
|
1539
|
+
var la=groups[a][0].lastMessageAt, lb=groups[b][0].lastMessageAt;
|
|
1540
|
+
return lb-la;
|
|
1541
|
+
});
|
|
1542
|
+
peers.forEach(function(peer){
|
|
1543
|
+
var isOpen = S.expanded[peer] !== false;
|
|
1544
|
+
var list=groups[peer];
|
|
1545
|
+
var shortPeer=peer.length>22?peer.substring(0,22)+'...':peer;
|
|
1546
|
+
var cached=agentInfoCache[peer];
|
|
1547
|
+
var avatarType=cached?cached.type:'';
|
|
1548
|
+
var avatarSrc=getAvatarSrc(avatarType);
|
|
1549
|
+
var displayName=(cached&&cached.name)?cached.name:shortPeer;
|
|
1550
|
+
var fullDisplayName=(cached&&cached.name)?cached.name:peer;
|
|
1551
|
+
var descText=(cached&&cached.description)?cached.description:peer;
|
|
1552
|
+
html+='<div class="aid-group">';
|
|
1553
|
+
html+='<div class="aid-group-header" onclick="toggleGroup(\\''+escA(peer)+'\\')"><span class="aid-group-arrow'+(isOpen?' open':'')+'">▶</span><img class="aid-group-avatar" id="avatar_'+escH(peer.replace(/\\./g,'_'))+'" src="'+avatarSrc+'" alt="avatar"><div class="aid-group-info"><span class="aid-group-title" title="'+escH(fullDisplayName)+'">'+escH(displayName)+'</span><span class="aid-group-desc" id="desc_'+escH(peer.replace(/\\./g,'_'))+'" title="'+escH(peer)+'">'+escH(descText)+'</span></div><span class="aid-group-badge">'+list.length+'</span><button class="aid-group-add" onclick="event.stopPropagation();newSessionWith(\\''+escA(peer)+'\\');" title="与该 AID 新建会话">+</button><button class="aid-group-del" onclick="event.stopPropagation();deletePeer(event, \\''+escA(peer)+'\\');" title="删除该 AID 及所有会话">🗑️</button></div>';
|
|
1554
|
+
html+='<div class="aid-group-sessions'+(isOpen?' open':'')+'">';
|
|
1555
|
+
list.forEach(function(s){
|
|
1556
|
+
var active=s.sessionId===S.sid;
|
|
1557
|
+
var time=fmtTime(s.lastMessageAt);
|
|
1558
|
+
var tc=s.type==='outgoing'?'outgoing':'incoming';
|
|
1559
|
+
var tt=s.type==='outgoing'?'OUT':'IN';
|
|
1560
|
+
var name=s.lastMessage||'';
|
|
1561
|
+
var fullName=name;
|
|
1562
|
+
if(name.length>20) name=name.substring(0,20)+'...';
|
|
1563
|
+
if(!name) name='(空会话)';
|
|
1564
|
+
var closedTag=s.closed?'<span style="color:#dc3545;font-size:10px;margin-left:4px;">[已关闭]</span>':'';
|
|
1565
|
+
html+='<div class="session-item'+(active?' active':'')+'" onclick="pickSession(\\''+escA(s.sessionId)+'\\',\\''+escA(s.peerAid)+'\\')"><div class="session-peer" title="'+escH(fullName)+'"><span class="tag '+tc+'">'+tt+'</span> '+escH(name)+closedTag+'</div><div class="session-meta"><span>'+s.messageCount+' 条 · '+time+'</span></div><button class="session-del" onclick="event.stopPropagation();deleteSession(event, \\''+escA(s.sessionId)+'\\');" title="删除会话">🗑️</button></div>';
|
|
1566
|
+
});
|
|
1567
|
+
html+='</div></div>';
|
|
1568
|
+
});
|
|
1569
|
+
D.sList.innerHTML=html;
|
|
1570
|
+
|
|
1571
|
+
// 异步加载未缓存的 agent info 并更新头像和名称
|
|
1572
|
+
peers.forEach(function(peer){
|
|
1573
|
+
if(!agentInfoCache[peer]){
|
|
1574
|
+
fetchAgentInfo(peer).then(function(info){
|
|
1575
|
+
var safeId=peer.replace(/\\./g,'_');
|
|
1576
|
+
var el=document.getElementById('avatar_'+safeId);
|
|
1577
|
+
if(el) el.src=getAvatarSrc(info.type);
|
|
1578
|
+
if(info.name){
|
|
1579
|
+
var header=el&&el.parentElement;
|
|
1580
|
+
if(header){
|
|
1581
|
+
var titleEl=header.querySelector('.aid-group-title');
|
|
1582
|
+
if(titleEl){ titleEl.textContent=info.name; titleEl.title=info.name; }
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
if(info.description){
|
|
1586
|
+
var descEl=document.getElementById('desc_'+safeId);
|
|
1587
|
+
if(descEl){ descEl.textContent=info.description; descEl.title=info.description; }
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
function toggleGroup(owner){
|
|
1595
|
+
S.expanded[owner] = S.expanded[owner]===false ? true : false;
|
|
1596
|
+
D.sList.dataset.s=''; // force re-render
|
|
1597
|
+
updateSessions(S.sessions, S.sid);
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
function renderMsgs(msgs, closed){
|
|
1601
|
+
if(isUserSelecting()) return;
|
|
1602
|
+
var sig=msgs.length+(msgs.length>0?msgs[msgs.length-1].timestamp:0)+(closed?'c':'');
|
|
1603
|
+
// Check if we need to re-render due to avatar updates (simple check: if sig matches but we want to force update, we might need another flag, but for now relies on sig change or manual call)
|
|
1604
|
+
// Actually, let's allow re-render if we call it.
|
|
1605
|
+
if(D.msgs.dataset.s==sig && !D.msgs.dataset.force) return;
|
|
1606
|
+
D.msgs.dataset.s=sig;
|
|
1607
|
+
D.msgs.dataset.force=''; // clear force flag
|
|
1608
|
+
|
|
1609
|
+
if(!msgs.length){
|
|
1610
|
+
D.msgs.innerHTML='<div style="text-align:center;color:#ccc;margin-top:20px;font-size:12px;">暂无消息</div>';
|
|
1611
|
+
D.input.disabled=false; D.input.placeholder='输入消息...';
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
var html=msgs.map(function(m){
|
|
1615
|
+
var sent=m.type==='sent';
|
|
1616
|
+
var sender = sent ? S.aid : (m.from || 'unknown');
|
|
1617
|
+
var info = agentInfoCache[sender];
|
|
1618
|
+
if(!info){
|
|
1619
|
+
fetchAgentInfo(sender).then(function(){
|
|
1620
|
+
if(D.msgs.dataset.s===sig){ D.msgs.dataset.force='1'; renderMsgs(msgs, closed); }
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
var avatarSrc = getAvatarSrc(info ? info.type : '');
|
|
1624
|
+
var t=fmtTime(m.timestamp);
|
|
1625
|
+
var c=(typeof marked!=='undefined'&&marked.parse)?marked.parse(m.content):escH(m.content);
|
|
1626
|
+
var name = (info && info.name) ? info.name : sender;
|
|
1627
|
+
|
|
1628
|
+
return '<div class="message '+m.type+'">' +
|
|
1629
|
+
'<img class="msg-avatar" src="'+avatarSrc+'" title="'+escH(name)+'">' +
|
|
1630
|
+
'<div class="msg-content">' +
|
|
1631
|
+
'<div class="msg-meta">'+(sent?'我':escH(name))+' · '+t+'</div>' +
|
|
1632
|
+
'<div class="bubble-wrap"><button class="copy-msg-btn" onclick="copyMsgText(this)">复制</button><div class="bubble">'+c+'</div></div>' +
|
|
1633
|
+
'</div></div>';
|
|
1634
|
+
}).join('');
|
|
1635
|
+
if(closed){
|
|
1636
|
+
html+='<div style="text-align:center;margin:16px 0;"><div style="display:inline-block;background:#fff3cd;color:#856404;padding:8px 20px;border-radius:20px;font-size:12px;border:1px solid #ffc107;">会话已关闭 — 请点击左侧 + 新建会话继续通信</div></div>';
|
|
1637
|
+
D.input.disabled=true; D.input.placeholder='会话已关闭,请新建会话';
|
|
1638
|
+
} else {
|
|
1639
|
+
D.input.disabled=false; D.input.placeholder='输入消息...';
|
|
1640
|
+
}
|
|
1641
|
+
var wasAtBottom=isAtBottom();
|
|
1642
|
+
var prevScrollTop=D.msgs.scrollTop;
|
|
1643
|
+
D.msgs.innerHTML=html+'<div class="new-msg-tip" id="newMsgTip" onclick="scrollToBottom()" style="display:none;">↓ 有新消息</div>';
|
|
1644
|
+
D.newMsgTip=$('newMsgTip');
|
|
1645
|
+
// 不自动滚动,保持用户当前位置;有新消息时显示提示
|
|
1646
|
+
if(!wasAtBottom&&msgs.length>0){
|
|
1647
|
+
D.msgs.scrollTop=prevScrollTop;
|
|
1648
|
+
if(D.msgs.dataset.force!=='avatar') showNewMsgTip();
|
|
1649
|
+
} else {
|
|
1650
|
+
D.msgs.scrollTop=prevScrollTop;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
function updateDot(st){
|
|
1655
|
+
S.status=st;
|
|
1656
|
+
D.dot.className='status-dot '+(st||'');
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
async function pickSession(sid,peer){
|
|
1660
|
+
if(S.tab!=='p2p') switchTab('p2p');
|
|
1661
|
+
S.sid=sid; S.sessionId=sid;
|
|
1662
|
+
hideNewMsgTip();
|
|
1663
|
+
D.title.textContent=peer;
|
|
1664
|
+
try {
|
|
1665
|
+
await fetch('/api/sessions/active',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({sessionId:sid,aid:S.aid})});
|
|
1666
|
+
// 通知服务端本标签页的 activeSessionId
|
|
1667
|
+
if(_groupWs&&_groupWs.readyState===WebSocket.OPEN){
|
|
1668
|
+
_groupWs.send(JSON.stringify({type:'set_active_session',sessionId:sid}));
|
|
1669
|
+
}
|
|
1670
|
+
var r=await fetch('/api/messages?aid='+encodeURIComponent(S.aid)+'&sessionId='+encodeURIComponent(sid));
|
|
1671
|
+
var d=await r.json();
|
|
1672
|
+
S.closed=d.closed||false;
|
|
1673
|
+
D.msgs.dataset.s=''; // force
|
|
1674
|
+
renderMsgs(d.messages||[], S.closed);
|
|
1675
|
+
scrollToBottom();
|
|
1676
|
+
// 刷新会话列表,确保新会话出现在侧边栏
|
|
1677
|
+
loadSessions();
|
|
1678
|
+
} catch(e){}
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
async function sendMessage(){
|
|
1682
|
+
var txt=D.input.value.trim();
|
|
1683
|
+
if(!txt){ return; }
|
|
1684
|
+
// 用户主动发送消息,确保滚动到底部
|
|
1685
|
+
hideNewMsgTip();
|
|
1686
|
+
// 群组模式
|
|
1687
|
+
if(S.tab==='group'){
|
|
1688
|
+
if(!S.activeGroupId){ alert('请先选择一个群组'); return; }
|
|
1689
|
+
try {
|
|
1690
|
+
D.input.value='';
|
|
1691
|
+
var r=await fetch('/api/group/send',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({groupId:S.activeGroupId,message:txt,aid:S.aid})});
|
|
1692
|
+
var d=await r.json();
|
|
1693
|
+
if(!d.success) alert(d.error||'发送失败');
|
|
1694
|
+
else {
|
|
1695
|
+
// 发送成功:立即追加到本地显示(服务端已存储,不用等 WS 推送)
|
|
1696
|
+
if(d.msg_id){
|
|
1697
|
+
var sentMsg={msg_id:d.msg_id,sender:S.aid,content:txt,content_type:'text',timestamp:d.timestamp||Date.now()};
|
|
1698
|
+
var exists=_lastGroupMsgs.some(function(m){ return m.msg_id===sentMsg.msg_id; });
|
|
1699
|
+
if(!exists){
|
|
1700
|
+
_lastGroupMsgs.push(sentMsg);
|
|
1701
|
+
_lastGroupMsgSig='';
|
|
1702
|
+
renderGroupMsgs(_lastGroupMsgs);
|
|
1703
|
+
scrollToBottom();
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
} catch(e){ alert('发送失败'); }
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
// P2P 模式
|
|
1711
|
+
if(!S.sid){ alert('请先选择或新建一个会话'); return; }
|
|
1712
|
+
if(S.closed){ alert('该会话已关闭,请新建会话继续通信'); return; }
|
|
1713
|
+
try {
|
|
1714
|
+
D.input.value='';
|
|
1715
|
+
var r=await fetch('/api/ws/send',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({message:txt,sessionId:S.sid,aid:S.aid})});
|
|
1716
|
+
var d=await r.json();
|
|
1717
|
+
if(!d.success) alert(d.error||'发送失败');
|
|
1718
|
+
else { await loadMessages(); scrollToBottom(); }
|
|
1719
|
+
} catch(e){ alert('发送失败'); }
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
function toggleSidebar(){
|
|
1723
|
+
S.sidebarOpen=!S.sidebarOpen;
|
|
1724
|
+
D.sidebar.classList.toggle('collapsed',!S.sidebarOpen);
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
function showModal(){ D.modal.classList.add('show'); D.tInput.value=''; D.tInput.focus(); }
|
|
1728
|
+
function hideModal(){ D.modal.classList.remove('show'); }
|
|
1729
|
+
|
|
1730
|
+
async function newSessionWith(peerAid){
|
|
1731
|
+
try {
|
|
1732
|
+
var r=await fetch('/api/ws/connect',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({targetAid:peerAid,aid:S.aid})});
|
|
1733
|
+
var d=await r.json();
|
|
1734
|
+
if(d.success){ pickSession(d.sessionId,peerAid); }
|
|
1735
|
+
else { alert(d.error||'连接失败'); }
|
|
1736
|
+
} catch(e){ alert('错误: '+e.message); }
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
async function doConnect(){
|
|
1740
|
+
var aid=D.tInput.value.trim();
|
|
1741
|
+
if(!aid) return;
|
|
1742
|
+
D.cBtn.disabled=true; D.cBtn.textContent='连接中...';
|
|
1743
|
+
try {
|
|
1744
|
+
var r=await fetch('/api/ws/connect',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({targetAid:aid,aid:S.aid})});
|
|
1745
|
+
var d=await r.json();
|
|
1746
|
+
if(d.success){ hideModal(); pickSession(d.sessionId,aid); }
|
|
1747
|
+
else { alert(d.error||'连接失败'); }
|
|
1748
|
+
} catch(e){ alert('错误: '+e.message); }
|
|
1749
|
+
finally { D.cBtn.disabled=false; D.cBtn.textContent='连接'; }
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
function escH(t){ var d=document.createElement('div'); d.textContent=t; return d.innerHTML; }
|
|
1753
|
+
function copyMsgText(btn){ var bubble=btn.parentElement.querySelector('.bubble'); if(!bubble) return; var text=bubble.innerText||bubble.textContent||''; navigator.clipboard.writeText(text).then(function(){ btn.textContent='已复制'; setTimeout(function(){ btn.textContent='复制'; },1200); }).catch(function(){ btn.textContent='失败'; setTimeout(function(){ btn.textContent='复制'; },1200); }); }
|
|
1754
|
+
function isUserSelecting(){ var sel=window.getSelection(); if(!sel||sel.isCollapsed||!sel.rangeCount) return false; var range=sel.getRangeAt(0); return D.msgs&&D.msgs.contains(range.commonAncestorContainer); }
|
|
1755
|
+
function escA(t){ return t.replace(/\\\\/g,'\\\\\\\\').replace(/'/g,"\\\\'"); }
|
|
1756
|
+
function fmtTime(ts){
|
|
1757
|
+
if(!ts) return '';
|
|
1758
|
+
var n=Number(ts);
|
|
1759
|
+
if(isNaN(n)) return '';
|
|
1760
|
+
if(n<1e12) n=n*1000;
|
|
1761
|
+
var d=new Date(n);
|
|
1762
|
+
if(isNaN(d.getTime())) return '';
|
|
1763
|
+
var now=new Date();
|
|
1764
|
+
var pad=function(v){ return v<10?'0'+v:''+v; };
|
|
1765
|
+
var H=pad(d.getHours()), M=pad(d.getMinutes());
|
|
1766
|
+
if(d.getFullYear()===now.getFullYear()&&d.getMonth()===now.getMonth()&&d.getDate()===now.getDate()){
|
|
1767
|
+
return H+':'+M;
|
|
1768
|
+
}
|
|
1769
|
+
// 今年内省略年份
|
|
1770
|
+
if(d.getFullYear()===now.getFullYear()){
|
|
1771
|
+
return pad(d.getMonth()+1)+'/'+pad(d.getDate())+' '+H+':'+M;
|
|
1772
|
+
}
|
|
1773
|
+
return d.getFullYear()+'/'+pad(d.getMonth()+1)+'/'+pad(d.getDate())+' '+H+':'+M;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
// ============================================================
|
|
1777
|
+
// Group Functions
|
|
1778
|
+
// ============================================================
|
|
1779
|
+
|
|
1780
|
+
function switchTab(tab){
|
|
1781
|
+
S.tab=tab;
|
|
1782
|
+
D.tabP2P.className='tab'+(tab==='p2p'?' active':'');
|
|
1783
|
+
D.tabGroup.className='tab'+(tab==='group'?' active':'');
|
|
1784
|
+
D.p2pPanel.style.display=tab==='p2p'?'block':'none';
|
|
1785
|
+
D.groupPanel.style.display=tab==='group'?'flex':'none';
|
|
1786
|
+
if(tab==='group'){
|
|
1787
|
+
D.encryptBanner.style.display='none';
|
|
1788
|
+
D.groupInfoBar.style.display=S.activeGroupId?'flex':'none';
|
|
1789
|
+
D.input.placeholder='输入群消息...';
|
|
1790
|
+
D.input.disabled=!S.activeGroupId;
|
|
1791
|
+
D.msgs.dataset.s='';
|
|
1792
|
+
_lastGroupMsgSig='';
|
|
1793
|
+
initGroupClient();
|
|
1794
|
+
pollGroupList();
|
|
1795
|
+
if(S.activeGroupId) pollGroupMessages().then(function(){ scrollToBottom(); });
|
|
1796
|
+
else { D.msgs.innerHTML='<div style="text-align:center;color:#ccc;margin-top:20px;font-size:12px;">选择或创建一个群组</div>'; }
|
|
1797
|
+
} else {
|
|
1798
|
+
D.encryptBanner.style.display='flex';
|
|
1799
|
+
D.groupInfoBar.style.display='none';
|
|
1800
|
+
D.input.placeholder='输入消息...';
|
|
1801
|
+
D.input.disabled=false;
|
|
1802
|
+
_lastGroupMsgSig='';
|
|
1803
|
+
// 立即清空消息区域,防止群消息残留
|
|
1804
|
+
D.msgs.innerHTML='';
|
|
1805
|
+
// 切回P2P时立即刷新会话列表和消息
|
|
1806
|
+
D.sList.dataset.s='';
|
|
1807
|
+
D.msgs.dataset.s='';
|
|
1808
|
+
loadSessions();
|
|
1809
|
+
if(S.sid){
|
|
1810
|
+
fetch('/api/messages?aid='+encodeURIComponent(S.aid)+'&sessionId='+encodeURIComponent(S.sid)).then(function(r){ return r.json(); }).then(function(d){
|
|
1811
|
+
if(S.tab!=='p2p') return;
|
|
1812
|
+
S.closed=d.closed||false;
|
|
1813
|
+
if(d.messages) renderMsgs(d.messages, S.closed);
|
|
1814
|
+
scrollToBottom();
|
|
1815
|
+
}).catch(function(){});
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
var _groupInited=false;
|
|
1821
|
+
async function initGroupClient(){
|
|
1822
|
+
if(_groupInited) return;
|
|
1823
|
+
try {
|
|
1824
|
+
var r=await fetch('/api/group/init',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({aid:S.aid})});
|
|
1825
|
+
var d=await r.json();
|
|
1826
|
+
if(d.success){ _groupInited=true; if(d.targetAid) S.groupTargetAid=d.targetAid; }
|
|
1827
|
+
} catch(e){ console.error('群组初始化失败',e); }
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
async function pollGroupList(){
|
|
1831
|
+
try {
|
|
1832
|
+
var r=await fetch('/api/group/list?aid='+encodeURIComponent(S.aid));
|
|
1833
|
+
var d=await r.json();
|
|
1834
|
+
if(d.groups){ S.groups=d.groups; renderGroupList(); }
|
|
1835
|
+
} catch(e){}
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
function renderGroupList(){
|
|
1839
|
+
if(!S.groups.length){
|
|
1840
|
+
D.groupList.innerHTML='<div style="padding:20px;text-align:center;color:#999;font-size:12px;">暂无群组</div>';
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
var html='';
|
|
1844
|
+
S.groups.forEach(function(g){
|
|
1845
|
+
var active=g.group_id===S.activeGroupId;
|
|
1846
|
+
html+='<div class="group-item'+(active?' active':'')+'" onclick="pickGroup(\\''+escA(g.group_id)+'\\',\\''+escA(g.name||g.group_id)+'\\')"><div class="group-item-name">'+escH(g.name||g.group_id)+'</div><div class="group-item-meta">ID: '+escH(g.group_id.length>20?g.group_id.substring(0,20)+'...':g.group_id)+(g.member_count?' · '+g.member_count+' 人':'')+'</div><button class="group-item-del" onclick="event.stopPropagation();leaveGroup(\\''+escA(g.group_id)+'\\');" title="退出群组">退出</button></div>';
|
|
1847
|
+
});
|
|
1848
|
+
D.groupList.innerHTML=html;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
async function pickGroup(groupId,name){
|
|
1852
|
+
var overlay=$('switchGroupOverlay');
|
|
1853
|
+
var gmsg=$('switchGroupMsg');
|
|
1854
|
+
overlay.style.display='flex';
|
|
1855
|
+
gmsg.textContent='切换群组中...';
|
|
1856
|
+
S.activeGroupId=groupId;
|
|
1857
|
+
S.isGroupCreator=false;
|
|
1858
|
+
_lastGroupMsgSig='';
|
|
1859
|
+
hideNewMsgTip();
|
|
1860
|
+
D.title.textContent=name;
|
|
1861
|
+
D.groupInfoBar.style.display='flex';
|
|
1862
|
+
D.groupInfoText.textContent=name;
|
|
1863
|
+
D.input.disabled=false;
|
|
1864
|
+
D.input.placeholder='输入群消息...';
|
|
1865
|
+
D.input.focus();
|
|
1866
|
+
// 默认隐藏创建者相关按钮
|
|
1867
|
+
$('groupInviteBtn').style.display='none';
|
|
1868
|
+
$('groupCopyLinkBtn').style.display='none';
|
|
1869
|
+
$('groupReviewBtn').style.display='none';
|
|
1870
|
+
$('groupDutyBtn').style.display='none';
|
|
1871
|
+
$('groupRuleBtn').style.display='none';
|
|
1872
|
+
_groupRuleData=null;
|
|
1873
|
+
renderGroupList();
|
|
1874
|
+
try {
|
|
1875
|
+
gmsg.textContent='选择群组...';
|
|
1876
|
+
await fetch('/api/group/select',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({groupId:groupId,aid:S.aid})});
|
|
1877
|
+
} catch(e){}
|
|
1878
|
+
// 获取群信息判断是否为创建者
|
|
1879
|
+
try {
|
|
1880
|
+
gmsg.textContent='获取群信息...';
|
|
1881
|
+
var r=await fetch('/api/group/info?groupId='+encodeURIComponent(groupId)+'&aid='+encodeURIComponent(S.aid));
|
|
1882
|
+
var d=await r.json();
|
|
1883
|
+
if(d.creator&&d.creator===S.aid){
|
|
1884
|
+
S.isGroupCreator=true;
|
|
1885
|
+
$('groupInviteBtn').style.display='';
|
|
1886
|
+
$('groupReviewBtn').style.display='';
|
|
1887
|
+
$('groupDutyBtn').style.display='';
|
|
1888
|
+
} else {
|
|
1889
|
+
$('groupCopyLinkBtn').style.display='';
|
|
1890
|
+
}
|
|
1891
|
+
} catch(e){
|
|
1892
|
+
// 获取失败时默认显示复制群链接
|
|
1893
|
+
$('groupCopyLinkBtn').style.display='';
|
|
1894
|
+
}
|
|
1895
|
+
try {
|
|
1896
|
+
gmsg.textContent='加载消息...';
|
|
1897
|
+
await pollGroupMessages();
|
|
1898
|
+
scrollToBottom();
|
|
1899
|
+
} catch(e){}
|
|
1900
|
+
overlay.style.display='none';
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
var _lastGroupMsgSig='';
|
|
1904
|
+
async function pollGroupMessages(){
|
|
1905
|
+
if(!S.activeGroupId||S.tab!=='group') {
|
|
1906
|
+
console.log('[pollGroupMessages] SKIP: activeGroupId='+S.activeGroupId+' tab='+S.tab);
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
try {
|
|
1910
|
+
console.log('[pollGroupMessages] fetching: groupId='+S.activeGroupId+' aid='+S.aid);
|
|
1911
|
+
var r=await fetch('/api/group/messages?groupId='+encodeURIComponent(S.activeGroupId)+'&aid='+encodeURIComponent(S.aid));
|
|
1912
|
+
var d=await r.json();
|
|
1913
|
+
console.log('[pollGroupMessages] response: msgCount='+(d.messages?d.messages.length:0)+' tab='+S.tab);
|
|
1914
|
+
if(S.tab==='group'&&d.messages) renderGroupMsgs(d.messages);
|
|
1915
|
+
} catch(e){ console.error('[pollGroupMessages] error:', e); }
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// ============================================================
|
|
1919
|
+
// WebSocket: real-time group message push
|
|
1920
|
+
// ============================================================
|
|
1921
|
+
var _groupWs=null;
|
|
1922
|
+
var _groupWsReconnectTimer=null;
|
|
1923
|
+
var _groupWsReconnectDelay=1000; // exponential backoff start
|
|
1924
|
+
var _groupWsPingTimer=null;
|
|
1925
|
+
|
|
1926
|
+
function connectGroupWs(){
|
|
1927
|
+
if(_groupWs&&(_groupWs.readyState===WebSocket.OPEN||_groupWs.readyState===WebSocket.CONNECTING)) return;
|
|
1928
|
+
var proto=location.protocol==='https:'?'wss:':'ws:';
|
|
1929
|
+
_groupWs=new WebSocket(proto+'//'+location.host+'/ws/ui');
|
|
1930
|
+
_groupWs.onopen=function(){
|
|
1931
|
+
console.log('[WS] ui connected');
|
|
1932
|
+
_groupWsReconnectDelay=1000; // reset backoff on success
|
|
1933
|
+
if(_groupWsReconnectTimer){ clearTimeout(_groupWsReconnectTimer); _groupWsReconnectTimer=null; }
|
|
1934
|
+
// 绑定当前 aid
|
|
1935
|
+
if(S.aid) _groupWs.send(JSON.stringify({type:'bind_aid',aid:S.aid}));
|
|
1936
|
+
// 重连后主动拉取最新状态
|
|
1937
|
+
if(S.aid) fetch('/api/ws/status?aid='+encodeURIComponent(S.aid)).then(function(r){return r.json();}).then(function(d){updateDot(d.status);}).catch(function(){});
|
|
1938
|
+
fetch('/api/aid').then(function(r){return r.json();}).then(function(d){if(d.aidStatus){S.aidList=d.aidStatus;renderAidSelect();}}).catch(function(){});
|
|
1939
|
+
// 重连后补拉一次会话列表,防止断连期间丢失推送
|
|
1940
|
+
loadSessions();
|
|
1941
|
+
// 启动 keepalive ping(每 25s 发一次,防止代理/防火墙断连)
|
|
1942
|
+
if(_groupWsPingTimer) clearInterval(_groupWsPingTimer);
|
|
1943
|
+
_groupWsPingTimer=setInterval(function(){
|
|
1944
|
+
if(_groupWs&&_groupWs.readyState===WebSocket.OPEN){
|
|
1945
|
+
try{ _groupWs.send(JSON.stringify({type:'ping'})); }catch(e){}
|
|
1946
|
+
}
|
|
1947
|
+
},25000);
|
|
1948
|
+
};
|
|
1949
|
+
_groupWs.onmessage=function(ev){
|
|
1950
|
+
try {
|
|
1951
|
+
var data=JSON.parse(ev.data);
|
|
1952
|
+
handleGroupWsMessage(data);
|
|
1953
|
+
} catch(e){ console.error('[WS] parse error',e); }
|
|
1954
|
+
};
|
|
1955
|
+
_groupWs.onclose=function(){
|
|
1956
|
+
console.log('[WS] ui disconnected, reconnecting in '+_groupWsReconnectDelay+'ms...');
|
|
1957
|
+
_groupWs=null;
|
|
1958
|
+
if(_groupWsPingTimer){ clearInterval(_groupWsPingTimer); _groupWsPingTimer=null; }
|
|
1959
|
+
_groupWsReconnectTimer=setTimeout(function(){
|
|
1960
|
+
_groupWsReconnectDelay=Math.min(_groupWsReconnectDelay*2,30000); // cap at 30s
|
|
1961
|
+
connectGroupWs();
|
|
1962
|
+
},_groupWsReconnectDelay);
|
|
1963
|
+
};
|
|
1964
|
+
_groupWs.onerror=function(e){
|
|
1965
|
+
console.error('[WS] ui error',e);
|
|
1966
|
+
// onerror is always followed by onclose, so reconnect is handled there
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
function handleGroupWsMessage(data){
|
|
1971
|
+
if(data.type==='ws_status'){
|
|
1972
|
+
if(!data.aid||data.aid===S.aid) updateDot(data.status);
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1975
|
+
if(data.type==='aid_status'){
|
|
1976
|
+
S.aidList=data.aidStatus||[];
|
|
1977
|
+
renderAidSelect();
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
1980
|
+
if(data.type==='p2p_message'){
|
|
1981
|
+
// 实时推送的 P2P 消息
|
|
1982
|
+
if(S.tab==='p2p' && data.sessionId===S.sid){
|
|
1983
|
+
loadMessages();
|
|
1984
|
+
}
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1987
|
+
if(data.type==='sessions_updated'){
|
|
1988
|
+
loadSessions();
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
if(data.type==='group_message'){
|
|
1992
|
+
// 实时推送的完整消息
|
|
1993
|
+
var msg=data.message;
|
|
1994
|
+
var gid=data.group_id;
|
|
1995
|
+
if(gid===S.activeGroupId&&S.tab==='group'){
|
|
1996
|
+
// 追加到当前消息列表并重新渲染
|
|
1997
|
+
var exists=_lastGroupMsgs.some(function(m){ return m.msg_id===msg.msg_id; });
|
|
1998
|
+
if(!exists){
|
|
1999
|
+
_lastGroupMsgs.push(msg);
|
|
2000
|
+
_lastGroupMsgSig=''; // 强制重新渲染
|
|
2001
|
+
renderGroupMsgs(_lastGroupMsgs);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
} else if(data.type==='group_message_batch'){
|
|
2005
|
+
// 批量推送的消息列表
|
|
2006
|
+
var gid=data.group_id;
|
|
2007
|
+
var msgs=data.messages||[];
|
|
2008
|
+
console.log('[WS] group_message_batch received: gid='+gid+' msgCount='+msgs.length+' activeGroupId='+S.activeGroupId+' tab='+S.tab+' msgIds='+msgs.map(function(m){return m.msg_id}).join(','));
|
|
2009
|
+
if(gid===S.activeGroupId&&S.tab==='group'){
|
|
2010
|
+
var changed=false;
|
|
2011
|
+
var existingIds=_lastGroupMsgs.map(function(m){return m.msg_id});
|
|
2012
|
+
console.log('[WS] group_message_batch: currentMsgCount='+_lastGroupMsgs.length+' existingLastId='+(existingIds.length>0?existingIds[existingIds.length-1]:'none'));
|
|
2013
|
+
msgs.forEach(function(msg){
|
|
2014
|
+
var exists=_lastGroupMsgs.some(function(m){ return m.msg_id===msg.msg_id; });
|
|
2015
|
+
if(!exists){
|
|
2016
|
+
_lastGroupMsgs.push(msg);
|
|
2017
|
+
changed=true;
|
|
2018
|
+
console.log('[WS] group_message_batch: ADDED msg_id='+msg.msg_id);
|
|
2019
|
+
} else {
|
|
2020
|
+
console.log('[WS] group_message_batch: SKIP duplicate msg_id='+msg.msg_id);
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
2023
|
+
console.log('[WS] group_message_batch: changed='+changed+' newTotal='+_lastGroupMsgs.length);
|
|
2024
|
+
if(changed){
|
|
2025
|
+
_lastGroupMsgSig=''; // 强制重新渲染
|
|
2026
|
+
renderGroupMsgs(_lastGroupMsgs);
|
|
2027
|
+
}
|
|
2028
|
+
} else {
|
|
2029
|
+
console.log('[WS] group_message_batch: IGNORED - gid mismatch or wrong tab. gid='+gid+' activeGroupId='+S.activeGroupId+' tab='+S.tab);
|
|
2030
|
+
}
|
|
2031
|
+
} else if(data.type==='new_message_notify'){
|
|
2032
|
+
// 轻量通知:如果是当前活跃群组,拉取最新消息(本地读取,很快)
|
|
2033
|
+
console.log('[WS] new_message_notify: gid='+data.group_id+' activeGroupId='+S.activeGroupId+' tab='+S.tab);
|
|
2034
|
+
if(data.group_id===S.activeGroupId&&S.tab==='group'){
|
|
2035
|
+
console.log('[WS] new_message_notify: triggering pollGroupMessages');
|
|
2036
|
+
pollGroupMessages();
|
|
2037
|
+
}
|
|
2038
|
+
} else if(data.type==='join_approved'||data.type==='group_invite'){
|
|
2039
|
+
// 群组变动,刷新群组列表
|
|
2040
|
+
pollGroupList();
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
var _lastGroupMsgs=[];
|
|
2045
|
+
var _groupRuleData=null;
|
|
2046
|
+
function renderGroupMsgs(msgs){
|
|
2047
|
+
// 不在群组 tab 时不渲染,防止覆盖 P2P 消息
|
|
2048
|
+
if(S.tab!=='group') return;
|
|
2049
|
+
if(isUserSelecting()) return;
|
|
2050
|
+
var sig=msgs.length+(msgs.length>0?(msgs[msgs.length-1].msg_id||0):'');
|
|
2051
|
+
if(_lastGroupMsgSig===sig&&!msgs._forceRender) return;
|
|
2052
|
+
var prevCount=_lastGroupMsgs.length;
|
|
2053
|
+
_lastGroupMsgSig=sig;
|
|
2054
|
+
_lastGroupMsgs=msgs;
|
|
2055
|
+
// 提取 group.ap 规则消息,保存最新一条,不在列表中展示
|
|
2056
|
+
var ruleMsgs=msgs.filter(function(m){
|
|
2057
|
+
if(!m.content) return false;
|
|
2058
|
+
try { var p=JSON.parse(m.content); return p&&p.source==='group.ap'; } catch(e){ return false; }
|
|
2059
|
+
});
|
|
2060
|
+
if(ruleMsgs.length>0){
|
|
2061
|
+
try { _groupRuleData=JSON.parse(ruleMsgs[ruleMsgs.length-1].content); } catch(e){ _groupRuleData={content:ruleMsgs[ruleMsgs.length-1].content}; }
|
|
2062
|
+
$('groupRuleBtn').style.display='';
|
|
2063
|
+
}
|
|
2064
|
+
var displayMsgs=msgs.filter(function(m){
|
|
2065
|
+
if(!m.content) return true;
|
|
2066
|
+
try { var p=JSON.parse(m.content); return !(p&&p.source==='group.ap'); } catch(e){ return true; }
|
|
2067
|
+
});
|
|
2068
|
+
if(!displayMsgs.length){
|
|
2069
|
+
D.msgs.innerHTML='<div style="text-align:center;color:#ccc;margin-top:20px;font-size:12px;">暂无消息</div><div class="new-msg-tip" id="newMsgTip" onclick="scrollToBottom()" style="display:none;">↓ 有新消息</div>';
|
|
2070
|
+
D.newMsgTip=$('newMsgTip');
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
2073
|
+
var needFetch=[];
|
|
2074
|
+
var html=displayMsgs.map(function(m){
|
|
2075
|
+
var sent=m.sender===S.aid;
|
|
2076
|
+
var sender=m.sender||'unknown';
|
|
2077
|
+
var info=agentInfoCache[sender];
|
|
2078
|
+
if(!info){ needFetch.push(sender); }
|
|
2079
|
+
var avatarSrc=getAvatarSrc(info?info.type:'');
|
|
2080
|
+
var t=m.timestamp?fmtTime(m.timestamp):'';
|
|
2081
|
+
|
|
2082
|
+
var c=(typeof marked!=='undefined'&&marked.parse)?marked.parse(m.content||''):escH(m.content||'');
|
|
2083
|
+
var name=(info&&info.name)?info.name:sender;
|
|
2084
|
+
return '<div class="message '+(sent?'sent':'received')+'">' +
|
|
2085
|
+
'<img class="msg-avatar" src="'+avatarSrc+'" title="'+escH(name)+'">' +
|
|
2086
|
+
'<div class="msg-content">' +
|
|
2087
|
+
'<div class="msg-meta">'+(sent?'我':escH(name))+' · '+t+'</div>' +
|
|
2088
|
+
'<div class="bubble-wrap"><button class="copy-msg-btn" onclick="copyMsgText(this)">复制</button><div class="bubble">'+c+'</div></div>' +
|
|
2089
|
+
'</div></div>';
|
|
2090
|
+
}).join('');
|
|
2091
|
+
var wasAtBottom=isAtBottom();
|
|
2092
|
+
var prevScrollTop=D.msgs.scrollTop;
|
|
2093
|
+
D.msgs.innerHTML=html+'<div class="new-msg-tip" id="newMsgTip" onclick="scrollToBottom()" style="display:none;">↓ 有新消息</div>';
|
|
2094
|
+
D.newMsgTip=$('newMsgTip');
|
|
2095
|
+
// 有新消息且用户不在底部:保持位置,显示提示
|
|
2096
|
+
if(msgs.length>prevCount&&prevCount>0&&!wasAtBottom){
|
|
2097
|
+
D.msgs.scrollTop=prevScrollTop;
|
|
2098
|
+
showNewMsgTip();
|
|
2099
|
+
} else {
|
|
2100
|
+
D.msgs.scrollTop=prevScrollTop;
|
|
2101
|
+
}
|
|
2102
|
+
// 异步加载未缓存的 agent info,加载完成后重新渲染以更新头像
|
|
2103
|
+
var unique=needFetch.filter(function(v,i,a){ return a.indexOf(v)===i; });
|
|
2104
|
+
unique.forEach(function(aid){
|
|
2105
|
+
fetchAgentInfo(aid).then(function(){
|
|
2106
|
+
if(S.tab!=='group') return;
|
|
2107
|
+
_lastGroupMsgSig='';
|
|
2108
|
+
_lastGroupMsgs._forceRender=true;
|
|
2109
|
+
renderGroupMsgs(_lastGroupMsgs);
|
|
2110
|
+
});
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// Group modals
|
|
2115
|
+
function showCreateGroupModal(){ $('createGroupModal').classList.add('show'); $('groupNameInput').value=''; $('groupDescInput').value=''; var cards=$('groupTypeCards').children; for(var i=0;i<cards.length;i++){cards[i].classList.remove('selected');} cards[0].classList.add('selected'); var dcards=$('dutyRuleCards').children; for(var i=0;i<dcards.length;i++){dcards[i].classList.remove('selected');} dcards[0].classList.add('selected'); $('groupNameInput').focus(); }
|
|
2116
|
+
function hideCreateGroupModal(){ $('createGroupModal').classList.remove('show'); }
|
|
2117
|
+
function selectGroupType(el){ var cards=el.parentElement.children; for(var i=0;i<cards.length;i++){cards[i].classList.remove('selected');} el.classList.add('selected'); }
|
|
2118
|
+
function selectDutyRule(el){ var cards=el.parentElement.children; for(var i=0;i<cards.length;i++){cards[i].classList.remove('selected');} el.classList.add('selected'); }
|
|
2119
|
+
function showJoinGroupModal(){ $('joinGroupModal').classList.add('show'); $('joinGroupUrlInput').value=''; $('joinGroupUrlInput').focus(); }
|
|
2120
|
+
function hideJoinGroupModal(){ $('joinGroupModal').classList.remove('show'); }
|
|
2121
|
+
function hideMembersModal(){ $('membersModal').classList.remove('show'); }
|
|
2122
|
+
|
|
2123
|
+
function selectDutyConfigCard(el){ var cards=el.parentElement.children; for(var i=0;i<cards.length;i++){cards[i].classList.remove('selected');} el.classList.add('selected'); }
|
|
2124
|
+
async function showDutyConfigModal(){
|
|
2125
|
+
var cards=$('dutyConfigCards').children;
|
|
2126
|
+
for(var i=0;i<cards.length;i++){cards[i].classList.remove('selected');}
|
|
2127
|
+
$('dutyConfigModal').classList.add('show');
|
|
2128
|
+
try {
|
|
2129
|
+
var r=await fetch('/api/group/duty-status?groupId='+encodeURIComponent(S.activeGroupId)+'&aid='+encodeURIComponent(S.aid));
|
|
2130
|
+
var d=await r.json();
|
|
2131
|
+
if(d.success&&d.config&&d.config.mode){
|
|
2132
|
+
var mode=d.config.mode;
|
|
2133
|
+
for(var i=0;i<cards.length;i++){
|
|
2134
|
+
if(cards[i].getAttribute('data-value')===mode){ cards[i].classList.add('selected'); }
|
|
2135
|
+
}
|
|
2136
|
+
} else { cards[0].classList.add('selected'); }
|
|
2137
|
+
} catch(e){ cards[0].classList.add('selected'); }
|
|
2138
|
+
}
|
|
2139
|
+
function hideDutyConfigModal(){ $('dutyConfigModal').classList.remove('show'); }
|
|
2140
|
+
function showGroupRuleModal(){
|
|
2141
|
+
if(!_groupRuleData){ alert('暂无群规则数据'); return; }
|
|
2142
|
+
var d=_groupRuleData;
|
|
2143
|
+
var html='';
|
|
2144
|
+
// 值班信息
|
|
2145
|
+
var lines=(d.content||'').split('\\n');
|
|
2146
|
+
html+='<div style="background:#f8f9fa;border-radius:8px;padding:12px;margin-bottom:12px;border:1px solid var(--border);">';
|
|
2147
|
+
html+='<div style="font-weight:600;font-size:13px;margin-bottom:8px;color:var(--primary);">值班信息</div>';
|
|
2148
|
+
for(var i=0;i<lines.length;i++){
|
|
2149
|
+
var line=lines[i].trim();
|
|
2150
|
+
if(!line) continue;
|
|
2151
|
+
var parts=line.split(':');
|
|
2152
|
+
if(parts.length>=2){
|
|
2153
|
+
html+='<div style="margin-bottom:4px;font-size:12px;line-height:1.5;"><span style="color:var(--t2);">'+escH(parts[0].trim())+':</span> <span style="color:var(--t1);font-weight:500;">'+escH(parts.slice(1).join(':').trim())+'</span></div>';
|
|
2154
|
+
} else {
|
|
2155
|
+
html+='<div style="margin-bottom:4px;font-size:12px;line-height:1.5;color:var(--t1);">'+escH(line)+'</div>';
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
html+='</div>';
|
|
2159
|
+
// 成员列表
|
|
2160
|
+
if(d.members&&d.members.length){
|
|
2161
|
+
html+='<div style="background:#f8f9fa;border-radius:8px;padding:12px;border:1px solid var(--border);">';
|
|
2162
|
+
html+='<div style="font-weight:600;font-size:13px;margin-bottom:8px;color:var(--primary);">群成员 ('+d.members.length+')</div>';
|
|
2163
|
+
for(var i=0;i<d.members.length;i++){
|
|
2164
|
+
var m=d.members[i];
|
|
2165
|
+
var roleColor=m.role==='creator'?'#e67e22':'#95a5a6';
|
|
2166
|
+
var typeIcon=m.agent_type.indexOf('human')>=0?'\uD83D\uDC64':'\uD83E\uDD16';
|
|
2167
|
+
html+='<div style="display:flex;align-items:center;gap:8px;padding:8px 0;border-bottom:1px solid rgba(0,0,0,0.05);">';
|
|
2168
|
+
html+='<span style="font-size:16px;">'+typeIcon+'</span>';
|
|
2169
|
+
html+='<div style="flex:1;min-width:0;">';
|
|
2170
|
+
html+='<div style="font-size:12px;font-weight:600;color:var(--t1);">'+escH(m.nickname||m.agent_id)+'</div>';
|
|
2171
|
+
html+='<div style="font-size:11px;color:var(--t2);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'+escH(m.agent_id)+'</div>';
|
|
2172
|
+
if(m.capability) html+='<div style="font-size:11px;color:var(--t2);margin-top:2px;line-height:1.3;">'+escH(m.capability)+'</div>';
|
|
2173
|
+
html+='</div>';
|
|
2174
|
+
html+='<span style="font-size:11px;color:'+roleColor+';background:rgba(0,0,0,0.04);padding:2px 6px;border-radius:4px;">'+escH(m.role)+'</span>';
|
|
2175
|
+
html+='</div>';
|
|
2176
|
+
}
|
|
2177
|
+
html+='</div>';
|
|
2178
|
+
}
|
|
2179
|
+
$('groupRuleContent').innerHTML=html;
|
|
2180
|
+
$('groupRuleModal').classList.add('show');
|
|
2181
|
+
}
|
|
2182
|
+
function hideGroupRuleModal(){ $('groupRuleModal').classList.remove('show'); }
|
|
2183
|
+
async function saveDutyConfig(){
|
|
2184
|
+
var sel=document.querySelector('#dutyConfigCards .duty-rule-card.selected');
|
|
2185
|
+
if(!sel){ alert('请选择值班模式'); return; }
|
|
2186
|
+
var mode=sel.getAttribute('data-value');
|
|
2187
|
+
var btn=$('saveDutyConfigBtn');
|
|
2188
|
+
btn.disabled=true; btn.textContent='保存中...';
|
|
2189
|
+
try {
|
|
2190
|
+
var r=await fetch('/api/group/update-duty-config',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({groupId:S.activeGroupId,aid:S.aid,mode:mode})});
|
|
2191
|
+
var d=await r.json();
|
|
2192
|
+
if(d.success){ hideDutyConfigModal(); } else { alert(d.error||'保存失败'); }
|
|
2193
|
+
} catch(e){ alert('保存失败: '+e.message); }
|
|
2194
|
+
finally { btn.disabled=false; btn.textContent='保存'; }
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
async function doCreateGroup(){
|
|
2198
|
+
var name=$('groupNameInput').value.trim();
|
|
2199
|
+
if(!name) return;
|
|
2200
|
+
var description=$('groupDescInput').value.trim();
|
|
2201
|
+
if(!description){ $('groupDescInput').focus(); return; }
|
|
2202
|
+
var visibility=document.querySelector('#groupTypeCards .group-type-card.selected').getAttribute('data-value');
|
|
2203
|
+
var dutyMode=document.querySelector('#dutyRuleCards .duty-rule-card.selected').getAttribute('data-value');
|
|
2204
|
+
var btn=$('createGroupBtn');
|
|
2205
|
+
btn.disabled=true; btn.textContent='创建中...';
|
|
2206
|
+
try {
|
|
2207
|
+
var r=await fetch('/api/group/create',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name:name,visibility:visibility,description:description||undefined,duty_mode:dutyMode,aid:S.aid})});
|
|
2208
|
+
var d=await r.json();
|
|
2209
|
+
if(d.success){
|
|
2210
|
+
hideCreateGroupModal();
|
|
2211
|
+
pollGroupList();
|
|
2212
|
+
pickGroup(d.group_id,name);
|
|
2213
|
+
} else { alert(d.error||'创建失败'); }
|
|
2214
|
+
} catch(e){ alert('创建失败: '+e.message); }
|
|
2215
|
+
finally { btn.disabled=false; btn.textContent='创建'; }
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
async function doJoinGroup(){
|
|
2219
|
+
var rawUrl=$('joinGroupUrlInput').value.trim();
|
|
2220
|
+
if(!rawUrl){ alert('请输入群聊链接或邀请链接'); return; }
|
|
2221
|
+
// 从 URL 中解析 code 参数
|
|
2222
|
+
var code='';
|
|
2223
|
+
var groupUrl=rawUrl;
|
|
2224
|
+
try {
|
|
2225
|
+
var u=new URL(rawUrl);
|
|
2226
|
+
code=u.searchParams.get('code')||'';
|
|
2227
|
+
u.searchParams.delete('code');
|
|
2228
|
+
groupUrl=u.origin+u.pathname;
|
|
2229
|
+
} catch(e){}
|
|
2230
|
+
var btn=$('joinGroupBtn');
|
|
2231
|
+
btn.disabled=true; btn.textContent=code?'加入中...':'申请中...';
|
|
2232
|
+
try {
|
|
2233
|
+
var r=await fetch('/api/group/join',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({groupUrl:groupUrl,code:code||undefined,aid:S.aid})});
|
|
2234
|
+
var d=await r.json();
|
|
2235
|
+
if(d.success){
|
|
2236
|
+
hideJoinGroupModal();
|
|
2237
|
+
pollGroupList();
|
|
2238
|
+
if(d.group_id) pickGroup(d.group_id,d.group_id);
|
|
2239
|
+
if(d.pending) alert('入群申请已发送,请等待管理员审核');
|
|
2240
|
+
} else { alert(d.error||'操作失败'); }
|
|
2241
|
+
} catch(e){ alert('操作失败: '+e.message); }
|
|
2242
|
+
finally { btn.disabled=false; btn.textContent='加入'; }
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
async function copyGroupLink(){
|
|
2246
|
+
if(!S.activeGroupId) return;
|
|
2247
|
+
var groupUrl='https://'+S.groupTargetAid+'/'+S.activeGroupId;
|
|
2248
|
+
try { await navigator.clipboard.writeText(groupUrl); alert('群链接已复制到剪贴板\\n\\n'+groupUrl); }
|
|
2249
|
+
catch(e){ prompt('请复制群链接:',groupUrl); }
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
async function generateInviteLink(){
|
|
2253
|
+
if(!S.activeGroupId) return;
|
|
2254
|
+
try {
|
|
2255
|
+
var r=await fetch('/api/group/invite-code',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({groupId:S.activeGroupId,aid:S.aid})});
|
|
2256
|
+
var d=await r.json();
|
|
2257
|
+
if(d.success&&d.code){
|
|
2258
|
+
var baseUrl=d.group_url||('https://'+S.groupTargetAid+'/'+S.activeGroupId);
|
|
2259
|
+
var inviteUrl=baseUrl+'?code='+d.code;
|
|
2260
|
+
try {
|
|
2261
|
+
await navigator.clipboard.writeText(inviteUrl);
|
|
2262
|
+
alert('邀请链接已复制到剪贴板\\n\\n'+inviteUrl);
|
|
2263
|
+
} catch(e){
|
|
2264
|
+
prompt('请手动复制邀请链接:',inviteUrl);
|
|
2265
|
+
}
|
|
2266
|
+
} else { alert(d.error||'生成邀请码失败'); }
|
|
2267
|
+
} catch(e){ alert('生成邀请码失败: '+e.message); }
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
function copyMemberAid(btn,aid){
|
|
2271
|
+
navigator.clipboard.writeText(aid).then(function(){
|
|
2272
|
+
btn.textContent='已复制';
|
|
2273
|
+
setTimeout(function(){ btn.textContent='复制'; },1200);
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
async function openAgentMdPage(aid){
|
|
2278
|
+
try {
|
|
2279
|
+
var r=await fetch('/api/agent-md-raw?aid='+encodeURIComponent(aid));
|
|
2280
|
+
var d=await r.json();
|
|
2281
|
+
if(!d.success||!d.content){ alert(d.error||'获取 agent.md 失败'); return; }
|
|
2282
|
+
var md=d.content;
|
|
2283
|
+
// 简单 markdown 渲染
|
|
2284
|
+
function renderMd(src){
|
|
2285
|
+
var h=escH(src);
|
|
2286
|
+
// headings
|
|
2287
|
+
h=h.replace(/^######\\s+(.+)$/gm,'<h6>$1</h6>');
|
|
2288
|
+
h=h.replace(/^#####\\s+(.+)$/gm,'<h5>$1</h5>');
|
|
2289
|
+
h=h.replace(/^####\\s+(.+)$/gm,'<h4>$1</h4>');
|
|
2290
|
+
h=h.replace(/^###\\s+(.+)$/gm,'<h3>$1</h3>');
|
|
2291
|
+
h=h.replace(/^##\\s+(.+)$/gm,'<h2>$1</h2>');
|
|
2292
|
+
h=h.replace(/^#\\s+(.+)$/gm,'<h1>$1</h1>');
|
|
2293
|
+
// bold & italic
|
|
2294
|
+
h=h.replace(/\\*\\*(.+?)\\*\\*/g,'<strong>$1</strong>');
|
|
2295
|
+
h=h.replace(/\\*(.+?)\\*/g,'<em>$1</em>');
|
|
2296
|
+
// blockquote
|
|
2297
|
+
h=h.replace(/^>\\s?(.+)$/gm,'<blockquote style="border-left:3px solid #ddd;padding-left:12px;color:#666;margin:8px 0;">$1</blockquote>');
|
|
2298
|
+
// list items
|
|
2299
|
+
h=h.replace(/^-\\s+(.+)$/gm,'<li>$1</li>');
|
|
2300
|
+
// code inline
|
|
2301
|
+
var bt=String.fromCharCode(96);
|
|
2302
|
+
h=h.replace(new RegExp(bt+'([^'+bt+']+)'+bt,'g'),'<code style="background:#f5f5f5;padding:1px 4px;border-radius:3px;font-size:12px;">$1</code>');
|
|
2303
|
+
// frontmatter block: hide ---...---
|
|
2304
|
+
h=h.replace(/^---[\\s\\S]*?---\\s*/,'');
|
|
2305
|
+
// paragraphs
|
|
2306
|
+
h=h.replace(/\\n\\n/g,'</p><p>');
|
|
2307
|
+
h='<p>'+h+'</p>';
|
|
2308
|
+
return h;
|
|
2309
|
+
}
|
|
2310
|
+
var html='<!DOCTYPE html><html><head><meta charset="utf-8"><title>'+escH(aid)+' - Agent Profile</title>'
|
|
2311
|
+
+'<style>body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;max-width:720px;margin:40px auto;padding:0 20px;color:#333;line-height:1.6;}'
|
|
2312
|
+
+'h1{border-bottom:2px solid #eee;padding-bottom:8px;}h2{border-bottom:1px solid #eee;padding-bottom:6px;margin-top:24px;}'
|
|
2313
|
+
+'ul{padding-left:20px;}li{margin:4px 0;}blockquote{margin:12px 0;}'
|
|
2314
|
+
+'pre{background:#f5f5f5;padding:12px;border-radius:6px;overflow-x:auto;}'
|
|
2315
|
+
+'.aid-badge{display:inline-block;background:#e8f4fd;color:#0969da;padding:2px 8px;border-radius:10px;font-size:12px;font-family:monospace;margin-bottom:16px;}'
|
|
2316
|
+
+'</style></head><body>'
|
|
2317
|
+
+'<div class="aid-badge">'+escH(aid)+'</div>'
|
|
2318
|
+
+renderMd(md)
|
|
2319
|
+
+'</body></html>';
|
|
2320
|
+
var w=window.open('','_blank');
|
|
2321
|
+
if(w){ w.document.write(html); w.document.close(); }
|
|
2322
|
+
else { alert('弹窗被拦截,请允许弹窗后重试'); }
|
|
2323
|
+
} catch(e){ alert('获取 agent.md 失败: '+e.message); }
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
async function showGroupMembers(){
|
|
2327
|
+
if(!S.activeGroupId) return;
|
|
2328
|
+
try {
|
|
2329
|
+
var r=await fetch('/api/group/members?groupId='+encodeURIComponent(S.activeGroupId)+'&aid='+encodeURIComponent(S.aid));
|
|
2330
|
+
var d=await r.json();
|
|
2331
|
+
if(d.members){
|
|
2332
|
+
var html=d.members.map(function(m){
|
|
2333
|
+
var aid=m.agent_id||m;
|
|
2334
|
+
if(typeof aid!=='string') aid=JSON.stringify(aid);
|
|
2335
|
+
var role=m.role||'';
|
|
2336
|
+
var cachedInfo=agentInfoCache[aid];
|
|
2337
|
+
var avatarSrc=getAvatarSrc(cachedInfo?cachedInfo.type:'');
|
|
2338
|
+
var displayName=(cachedInfo&&cachedInfo.name)?cachedInfo.name:aid.split('.')[0];
|
|
2339
|
+
var typeTags='';
|
|
2340
|
+
if(cachedInfo&&cachedInfo.tags&&cachedInfo.tags.length){
|
|
2341
|
+
typeTags=cachedInfo.tags.map(function(t){ return '<span style="display:inline-block;background:#e8f4fd;color:#0969da;padding:1px 6px;border-radius:8px;font-size:10px;margin-right:4px;">'+escH(t)+'</span>'; }).join('');
|
|
2342
|
+
} else if(cachedInfo&&cachedInfo.type){
|
|
2343
|
+
typeTags='<span style="display:inline-block;background:#e8f4fd;color:#0969da;padding:1px 6px;border-radius:8px;font-size:10px;">'+escH(cachedInfo.type)+'</span>';
|
|
2344
|
+
}
|
|
2345
|
+
if(role){ typeTags+='<span style="display:inline-block;background:#fff3cd;color:#856404;padding:1px 6px;border-radius:8px;font-size:10px;margin-left:4px;">'+escH(role)+'</span>'; }
|
|
2346
|
+
var safeId='member-'+escH(aid).replace(/\\./g,'_');
|
|
2347
|
+
return '<div id="'+safeId+'" style="padding:10px 0;border-bottom:1px solid #f3f4f6;display:flex;align-items:center;gap:10px;">'
|
|
2348
|
+
+'<img src="'+avatarSrc+'" style="width:36px;height:36px;border-radius:50%;flex-shrink:0;" class="member-avatar" data-aid="'+escH(aid)+'">'
|
|
2349
|
+
+'<div style="flex:1;min-width:0;">'
|
|
2350
|
+
+'<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap;">'
|
|
2351
|
+
+'<span style="font-size:13px;font-weight:500;" class="member-name" data-aid="'+escH(aid)+'">'+escH(displayName)+'</span>'
|
|
2352
|
+
+'<span class="member-tags" data-aid="'+escH(aid)+'">'+typeTags+'</span>'
|
|
2353
|
+
+'</div>'
|
|
2354
|
+
+'<div style="font-size:11px;color:var(--t2);font-family:monospace;margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">'+escH(aid)+'</div>'
|
|
2355
|
+
+'</div>'
|
|
2356
|
+
+'<div style="display:flex;gap:4px;flex-shrink:0;">'
|
|
2357
|
+
+'<button class="mbtn mbtn-ok" style="padding:4px 10px;font-size:11px;" onclick="copyMemberAid(this,\\''+escH(aid)+'\\')">复制</button>'
|
|
2358
|
+
+'<button class="mbtn mbtn-cancel" style="padding:4px 10px;font-size:11px;" onclick="openAgentMdPage(\\''+escH(aid)+'\\')">查看</button>'
|
|
2359
|
+
+'</div></div>';
|
|
2360
|
+
}).join('');
|
|
2361
|
+
$('membersList').innerHTML=html||'<div style="color:#999;">暂无成员</div>';
|
|
2362
|
+
// 异步加载未缓存的 agent info
|
|
2363
|
+
d.members.forEach(function(m){
|
|
2364
|
+
var aid=m.agent_id||m;
|
|
2365
|
+
if(typeof aid!=='string') aid=JSON.stringify(aid);
|
|
2366
|
+
if(!aid||agentInfoCache[aid]) return;
|
|
2367
|
+
fetchAgentInfo(aid).then(function(info){
|
|
2368
|
+
if(!info||(!info.name&&!info.type)) return;
|
|
2369
|
+
var safeId='member-'+aid.replace(/\\./g,'_');
|
|
2370
|
+
var el=document.getElementById(safeId);
|
|
2371
|
+
if(!el) return;
|
|
2372
|
+
var avatarEl=el.querySelector('.member-avatar[data-aid="'+aid+'"]');
|
|
2373
|
+
var nameEl=el.querySelector('.member-name[data-aid="'+aid+'"]');
|
|
2374
|
+
var tagsEl=el.querySelector('.member-tags[data-aid="'+aid+'"]');
|
|
2375
|
+
if(avatarEl) avatarEl.src=getAvatarSrc(info.type);
|
|
2376
|
+
if(nameEl) nameEl.textContent=info.name||aid.split('.')[0];
|
|
2377
|
+
if(tagsEl){
|
|
2378
|
+
var tags='';
|
|
2379
|
+
if(info.tags&&info.tags.length){
|
|
2380
|
+
tags=info.tags.map(function(t){ return '<span style="display:inline-block;background:#e8f4fd;color:#0969da;padding:1px 6px;border-radius:8px;font-size:10px;margin-right:4px;">'+escH(t)+'</span>'; }).join('');
|
|
2381
|
+
} else if(info.type){
|
|
2382
|
+
tags='<span style="display:inline-block;background:#e8f4fd;color:#0969da;padding:1px 6px;border-radius:8px;font-size:10px;">'+escH(info.type)+'</span>';
|
|
2383
|
+
}
|
|
2384
|
+
// 保留已有的 role tag
|
|
2385
|
+
var existingRole=tagsEl.querySelector('span[style*="fff3cd"]');
|
|
2386
|
+
tagsEl.innerHTML=tags+(existingRole?existingRole.outerHTML:'');
|
|
2387
|
+
}
|
|
2388
|
+
});
|
|
2389
|
+
});
|
|
2390
|
+
} else { $('membersList').innerHTML='<div style="color:#999;">获取失败</div>'; }
|
|
2391
|
+
$('membersModal').classList.add('show');
|
|
2392
|
+
} catch(e){ alert('获取成员失败: '+e.message); }
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
function hidePendingRequestsModal(){ $('pendingRequestsModal').classList.remove('show'); }
|
|
2396
|
+
|
|
2397
|
+
async function showPendingRequests(){
|
|
2398
|
+
if(!S.activeGroupId) return;
|
|
2399
|
+
try {
|
|
2400
|
+
var r=await fetch('/api/group/pending-requests?groupId='+encodeURIComponent(S.activeGroupId)+'&aid='+encodeURIComponent(S.aid));
|
|
2401
|
+
var d=await r.json();
|
|
2402
|
+
if(d.requests&&d.requests.length>0){
|
|
2403
|
+
// 先渲染基础结构,然后异步加载 agent info
|
|
2404
|
+
var html=d.requests.map(function(req){
|
|
2405
|
+
var aid=req.agent_id||'';
|
|
2406
|
+
var msg=req.message?escH(req.message):'';
|
|
2407
|
+
var time=req.created_at?fmtTime(req.created_at):'';
|
|
2408
|
+
var cachedInfo=agentInfoCache[aid];
|
|
2409
|
+
var avatarSrc=getAvatarSrc(cachedInfo?cachedInfo.type:'');
|
|
2410
|
+
var displayName=(cachedInfo&&cachedInfo.name)?cachedInfo.name:aid;
|
|
2411
|
+
var desc=(cachedInfo&&cachedInfo.description)?cachedInfo.description:'';
|
|
2412
|
+
return '<div id="pending-'+escH(aid).replace(/\\./g,'_')+'" style="padding:10px 0;border-bottom:1px solid #f3f4f6;display:flex;align-items:flex-start;gap:10px;">'
|
|
2413
|
+
+'<img src="'+avatarSrc+'" style="width:36px;height:36px;border-radius:50%;flex-shrink:0;margin-top:2px;" class="pending-avatar" data-aid="'+escH(aid)+'">'
|
|
2414
|
+
+'<div style="flex:1;min-width:0;">'
|
|
2415
|
+
+'<div style="font-size:13px;font-weight:500;" class="pending-name" data-aid="'+escH(aid)+'">'+escH(displayName)+'</div>'
|
|
2416
|
+
+'<div style="font-size:11px;color:var(--t2);font-family:monospace;margin-top:2px;">'+escH(aid)+'</div>'
|
|
2417
|
+
+'<div style="font-size:11px;color:var(--t2);margin-top:2px;display:'+(desc?'block':'none')+';" class="pending-desc" data-aid="'+escH(aid)+'">'+escH(desc)+'</div>'
|
|
2418
|
+
+(msg?'<div style="font-size:11px;color:#666;margin-top:4px;background:#f8f9fa;padding:4px 8px;border-radius:4px;">申请留言: '+msg+'</div>':'')
|
|
2419
|
+
+(time?'<div style="font-size:10px;color:var(--t2);margin-top:3px;">'+time+'</div>':'')
|
|
2420
|
+
+'</div>'
|
|
2421
|
+
+'<div style="display:flex;gap:4px;flex-shrink:0;margin-top:2px;">'
|
|
2422
|
+
+'<button class="mbtn mbtn-ok" style="padding:4px 10px;font-size:11px;" onclick="reviewJoin(\\''+escH(aid)+'\\',\\'approve\\')">通过</button>'
|
|
2423
|
+
+'<button class="mbtn mbtn-cancel" style="padding:4px 10px;font-size:11px;" onclick="reviewJoin(\\''+escH(aid)+'\\',\\'reject\\')">拒绝</button>'
|
|
2424
|
+
+'</div></div>';
|
|
2425
|
+
}).join('');
|
|
2426
|
+
$('pendingRequestsList').innerHTML=html;
|
|
2427
|
+
// 异步加载未缓存的 agent info
|
|
2428
|
+
d.requests.forEach(function(req){
|
|
2429
|
+
var aid=req.agent_id||'';
|
|
2430
|
+
if(!aid||agentInfoCache[aid]) return;
|
|
2431
|
+
fetchAgentInfo(aid).then(function(info){
|
|
2432
|
+
if(!info||(!info.name&&!info.type)) return;
|
|
2433
|
+
var safeId='pending-'+aid.replace(/\\./g,'_');
|
|
2434
|
+
var el=document.getElementById(safeId);
|
|
2435
|
+
if(!el) return;
|
|
2436
|
+
var avatarEl=el.querySelector('.pending-avatar[data-aid="'+aid+'"]');
|
|
2437
|
+
var nameEl=el.querySelector('.pending-name[data-aid="'+aid+'"]');
|
|
2438
|
+
var descEl=el.querySelector('.pending-desc[data-aid="'+aid+'"]');
|
|
2439
|
+
if(avatarEl) avatarEl.src=getAvatarSrc(info.type);
|
|
2440
|
+
if(nameEl) nameEl.textContent=info.name||aid;
|
|
2441
|
+
if(descEl&&info.description){ descEl.textContent=info.description; descEl.style.display='block'; }
|
|
2442
|
+
});
|
|
2443
|
+
});
|
|
2444
|
+
} else {
|
|
2445
|
+
$('pendingRequestsList').innerHTML='<div style="padding:16px;text-align:center;color:#999;font-size:12px;">暂无入群申请</div>';
|
|
2446
|
+
}
|
|
2447
|
+
$('pendingRequestsModal').classList.add('show');
|
|
2448
|
+
} catch(e){ alert('获取入群申请失败: '+e.message); }
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
async function reviewJoin(agentId,action){
|
|
2452
|
+
if(!S.activeGroupId) return;
|
|
2453
|
+
try {
|
|
2454
|
+
var r=await fetch('/api/group/review-join',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({groupId:S.activeGroupId,agentId:agentId,action:action,aid:S.aid})});
|
|
2455
|
+
var d=await r.json();
|
|
2456
|
+
if(d.success){ showPendingRequests(); }
|
|
2457
|
+
else { alert(d.error||'操作失败'); }
|
|
2458
|
+
} catch(e){ alert('操作失败: '+e.message); }
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
async function leaveGroup(groupId){
|
|
2462
|
+
if(!confirm('确认退出该群组?')) return;
|
|
2463
|
+
try {
|
|
2464
|
+
var r=await fetch('/api/group/leave',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({groupId:groupId,aid:S.aid})});
|
|
2465
|
+
var d=await r.json();
|
|
2466
|
+
if(d.success){
|
|
2467
|
+
if(S.activeGroupId===groupId){
|
|
2468
|
+
S.activeGroupId=null;
|
|
2469
|
+
D.title.textContent='未选择群组';
|
|
2470
|
+
D.groupInfoBar.style.display='none';
|
|
2471
|
+
D.msgs.innerHTML='';
|
|
2472
|
+
D.input.disabled=true;
|
|
2473
|
+
}
|
|
2474
|
+
pollGroupList();
|
|
2475
|
+
} else { alert(d.error||'退出失败'); }
|
|
2476
|
+
} catch(e){ alert('退出失败: '+e.message); }
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
// ============================================================
|
|
2480
|
+
// 我的群 Functions
|
|
2481
|
+
// ============================================================
|
|
2482
|
+
function showMyGroupsModal(){ $('myGroupsModal').classList.add('show'); }
|
|
2483
|
+
function hideMyGroupsModal(){ $('myGroupsModal').classList.remove('show'); }
|
|
2484
|
+
async function showMyGroups(){
|
|
2485
|
+
showMyGroupsModal();
|
|
2486
|
+
$('myGroupsContent').innerHTML='<div style="text-align:center;padding:20px;color:#999;">加载中...</div>';
|
|
2487
|
+
try {
|
|
2488
|
+
var r=await fetch('/api/group/my-groups?aid='+encodeURIComponent(S.aid));
|
|
2489
|
+
var d=await r.json();
|
|
2490
|
+
if(!d.success){ $('myGroupsContent').innerHTML='<div style="text-align:center;padding:20px;color:#e74c3c;">'+escH(d.error||'获取失败')+'</div>'; return; }
|
|
2491
|
+
var groups=d.groups||[];
|
|
2492
|
+
if(!groups.length){ $('myGroupsContent').innerHTML='<div style="text-align:center;padding:20px;color:#999;">暂无群组</div>'; return; }
|
|
2493
|
+
var html='<table style="width:100%;border-collapse:collapse;font-size:12px;">';
|
|
2494
|
+
html+='<tr style="background:#f8fafc;"><th style="padding:8px 6px;text-align:left;border-bottom:1px solid #e2e8f0;">群名称</th><th style="padding:8px 6px;text-align:left;border-bottom:1px solid #e2e8f0;">群ID</th><th style="padding:8px 6px;text-align:center;border-bottom:1px solid #e2e8f0;">角色</th><th style="padding:8px 6px;text-align:center;border-bottom:1px solid #e2e8f0;">状态</th></tr>';
|
|
2495
|
+
groups.forEach(function(g){
|
|
2496
|
+
var statusText=g.status===1?'正常':g.status===0?'待审核':'未知('+g.status+')';
|
|
2497
|
+
var statusColor=g.status===1?'#10b981':g.status===0?'#f59e0b':'#94a3b8';
|
|
2498
|
+
var shortId=g.group_id.length>16?g.group_id.substring(0,16)+'...':g.group_id;
|
|
2499
|
+
html+='<tr style="border-bottom:1px solid #f1f5f9;cursor:pointer;" onmouseover="this.style.background=\\'#f0f9ff\\'" onmouseout="this.style.background=\\'\\'">';
|
|
2500
|
+
html+='<td style="padding:8px 6px;font-weight:500;">'+escH(g.name||g.group_id)+'</td>';
|
|
2501
|
+
html+='<td style="padding:8px 6px;color:#64748b;" title="'+escH(g.group_id)+'">'+escH(shortId)+'</td>';
|
|
2502
|
+
html+='<td style="padding:8px 6px;text-align:center;">'+escH(g.role||'-')+'</td>';
|
|
2503
|
+
html+='<td style="padding:8px 6px;text-align:center;"><span style="color:'+statusColor+';font-weight:500;">'+escH(statusText)+'</span></td>';
|
|
2504
|
+
html+='</tr>';
|
|
2505
|
+
});
|
|
2506
|
+
html+='</table>';
|
|
2507
|
+
html+='<div style="margin-top:8px;font-size:11px;color:#94a3b8;text-align:right;">共 '+d.total+' 个群组</div>';
|
|
2508
|
+
$('myGroupsContent').innerHTML=html;
|
|
2509
|
+
} catch(e){ $('myGroupsContent').innerHTML='<div style="text-align:center;padding:20px;color:#e74c3c;">请求失败: '+escH(e.message)+'</div>'; }
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
// 扩展轮询:保留 P2P 等基础轮询,群组消息已通过 WebSocket 实时推送
|
|
2513
|
+
// 不再每秒轮询群消息
|
|
2514
|
+
|
|
2515
|
+
init();
|
|
2516
|
+
<\/script>
|
|
2517
|
+
</body>
|
|
2228
2518
|
</html>`;
|
|
2229
2519
|
function sendJson(res, data, status = 200) {
|
|
2230
2520
|
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
@@ -2349,7 +2639,7 @@ async function handleRequest(req, res) {
|
|
|
2349
2639
|
if (parts.length >= 3) {
|
|
2350
2640
|
const domain = parts.slice(1).join('.');
|
|
2351
2641
|
if (domain && domain !== globalApiUrl) {
|
|
2352
|
-
|
|
2642
|
+
utils_1.logger.log(`[Select] 切换 AP 为 ${domain} (AID: ${aid})`);
|
|
2353
2643
|
globalApiUrl = domain;
|
|
2354
2644
|
agentCP = new agentcp_1.AgentCP(domain, '', globalDataDir || undefined);
|
|
2355
2645
|
}
|
|
@@ -2366,7 +2656,7 @@ async function handleRequest(req, res) {
|
|
|
2366
2656
|
await ensureOnline(aid);
|
|
2367
2657
|
}
|
|
2368
2658
|
catch (e) {
|
|
2369
|
-
|
|
2659
|
+
utils_1.logger.warn(`[Select] AID ${aid} 自动上线失败:`, e.message);
|
|
2370
2660
|
}
|
|
2371
2661
|
sendJson(res, { success: true, aid });
|
|
2372
2662
|
}
|
|
@@ -2398,7 +2688,7 @@ async function handleRequest(req, res) {
|
|
|
2398
2688
|
if (parts.length >= 3) {
|
|
2399
2689
|
const domain = parts.slice(1).join('.');
|
|
2400
2690
|
if (domain && domain !== globalApiUrl) {
|
|
2401
|
-
|
|
2691
|
+
utils_1.logger.log(`[Create] 切换 AP 为 ${domain} (AID: ${aid})`);
|
|
2402
2692
|
globalApiUrl = domain;
|
|
2403
2693
|
agentCP = new agentcp_1.AgentCP(domain, '', globalDataDir || undefined);
|
|
2404
2694
|
}
|
|
@@ -2465,13 +2755,13 @@ async function handleRequest(req, res) {
|
|
|
2465
2755
|
await instance.agentCP.leaveAllGroupSessions();
|
|
2466
2756
|
}
|
|
2467
2757
|
catch (e) {
|
|
2468
|
-
|
|
2758
|
+
utils_1.logger.warn(`[Group] leaveAllGroupSessions error:`, e.message);
|
|
2469
2759
|
}
|
|
2470
2760
|
try {
|
|
2471
2761
|
await instance.agentCP.closeGroupMessageStore();
|
|
2472
2762
|
}
|
|
2473
2763
|
catch (e) {
|
|
2474
|
-
|
|
2764
|
+
utils_1.logger.warn(`[Group] closeGroupMessageStore error:`, e.message);
|
|
2475
2765
|
}
|
|
2476
2766
|
}
|
|
2477
2767
|
if (instance.heartbeatClient) {
|
|
@@ -2481,7 +2771,7 @@ async function handleRequest(req, res) {
|
|
|
2481
2771
|
instance.agentWS.disconnect();
|
|
2482
2772
|
}
|
|
2483
2773
|
aidInstances.delete(aid);
|
|
2484
|
-
|
|
2774
|
+
utils_1.logger.log(`[Server] AID ${aid} 已下线`);
|
|
2485
2775
|
// 下线后推送 AID 状态变更到前端
|
|
2486
2776
|
getAidStatusList().then(aidStatus => {
|
|
2487
2777
|
broadcastToBrowser({ type: 'aid_status', aidStatus });
|
|
@@ -2538,7 +2828,7 @@ async function handleRequest(req, res) {
|
|
|
2538
2828
|
identifyingCode: sessionInfo.identifyingCode
|
|
2539
2829
|
});
|
|
2540
2830
|
}, (status) => {
|
|
2541
|
-
|
|
2831
|
+
utils_1.logger.log('邀请状态:', status);
|
|
2542
2832
|
});
|
|
2543
2833
|
});
|
|
2544
2834
|
// 创建 outgoing session
|
|
@@ -2713,7 +3003,7 @@ async function handleRequest(req, res) {
|
|
|
2713
3003
|
if (pathname === '/api/group/create' && method === 'POST') {
|
|
2714
3004
|
try {
|
|
2715
3005
|
const body = await parseBody(req);
|
|
2716
|
-
const { name, visibility, description, aid } = body;
|
|
3006
|
+
const { name, visibility, description, duty_mode, aid } = body;
|
|
2717
3007
|
if (!aid) {
|
|
2718
3008
|
sendJson(res, { success: false, error: '缺少 aid' });
|
|
2719
3009
|
return;
|
|
@@ -2732,7 +3022,17 @@ async function handleRequest(req, res) {
|
|
|
2732
3022
|
if (description)
|
|
2733
3023
|
options.description = description;
|
|
2734
3024
|
const result = await ops.createGroup(target, name, options);
|
|
2735
|
-
|
|
3025
|
+
utils_1.logger.log('[ACP] createGroup 返回:', JSON.stringify(result, null, 2));
|
|
3026
|
+
// 设置值班规则
|
|
3027
|
+
if (duty_mode && result.group_id) {
|
|
3028
|
+
try {
|
|
3029
|
+
await ops.updateDutyConfig(target, result.group_id, { mode: duty_mode });
|
|
3030
|
+
utils_1.logger.log('[ACP] 值班规则已设置:', duty_mode);
|
|
3031
|
+
}
|
|
3032
|
+
catch (e) {
|
|
3033
|
+
utils_1.logger.warn('[ACP] 设置值班规则失败:', e.message);
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
2736
3036
|
// 加入本地存储
|
|
2737
3037
|
instance.agentCP.addGroupToStore(result.group_id, name);
|
|
2738
3038
|
// 注册在线,才能收到实时消息推送
|
|
@@ -2760,7 +3060,7 @@ async function handleRequest(req, res) {
|
|
|
2760
3060
|
instance.groupListSynced = true;
|
|
2761
3061
|
}
|
|
2762
3062
|
catch (syncErr) {
|
|
2763
|
-
|
|
3063
|
+
utils_1.logger.warn('[Group] syncGroupList error:', syncErr.message);
|
|
2764
3064
|
}
|
|
2765
3065
|
}
|
|
2766
3066
|
const groups = instance.agentCP.getLocalGroupList();
|
|
@@ -2857,6 +3157,7 @@ async function handleRequest(req, res) {
|
|
|
2857
3157
|
// 只读本地缓存,不再每次请求都去服务端拉取
|
|
2858
3158
|
// 新消息通过 WebSocket 推送实时到达并由 SDK 自动存储
|
|
2859
3159
|
const messages = instance.agentCP.getLocalGroupMessages(groupId);
|
|
3160
|
+
utils_1.logger.log(`[API] /api/group/messages: aid=${aid} group=${groupId} localMsgCount=${messages.length} lastMsgId=${messages.length > 0 ? messages[messages.length - 1].msg_id : 'none'} storeExists=${!!instance.agentCP.groupMessageStore}`);
|
|
2860
3161
|
sendJson(res, { success: true, messages });
|
|
2861
3162
|
}
|
|
2862
3163
|
catch (e) {
|
|
@@ -3059,6 +3360,59 @@ async function handleRequest(req, res) {
|
|
|
3059
3360
|
}
|
|
3060
3361
|
return;
|
|
3061
3362
|
}
|
|
3363
|
+
if (pathname === '/api/group/duty-status' && method === 'GET') {
|
|
3364
|
+
try {
|
|
3365
|
+
const aid = parsedUrl.query.aid;
|
|
3366
|
+
const groupId = parsedUrl.query.groupId;
|
|
3367
|
+
if (!aid) {
|
|
3368
|
+
sendJson(res, { success: false, error: '缺少 aid' });
|
|
3369
|
+
return;
|
|
3370
|
+
}
|
|
3371
|
+
if (!groupId) {
|
|
3372
|
+
sendJson(res, { success: false, error: '缺少 groupId' });
|
|
3373
|
+
return;
|
|
3374
|
+
}
|
|
3375
|
+
const instance = await ensureOnline(aid);
|
|
3376
|
+
await ensureGroupClient(instance);
|
|
3377
|
+
const ops = instance.agentCP.groupOps;
|
|
3378
|
+
const target = instance.groupTargetAid;
|
|
3379
|
+
const result = await ops.getDutyStatus(target, groupId);
|
|
3380
|
+
sendJson(res, { success: true, config: result.config, state: result.state });
|
|
3381
|
+
}
|
|
3382
|
+
catch (e) {
|
|
3383
|
+
sendJson(res, { success: false, error: e.message });
|
|
3384
|
+
}
|
|
3385
|
+
return;
|
|
3386
|
+
}
|
|
3387
|
+
if (pathname === '/api/group/update-duty-config' && method === 'POST') {
|
|
3388
|
+
try {
|
|
3389
|
+
const body = await parseBody(req);
|
|
3390
|
+
const { groupId, aid, mode } = body;
|
|
3391
|
+
if (!aid) {
|
|
3392
|
+
sendJson(res, { success: false, error: '缺少 aid' });
|
|
3393
|
+
return;
|
|
3394
|
+
}
|
|
3395
|
+
if (!groupId) {
|
|
3396
|
+
sendJson(res, { success: false, error: '缺少 groupId' });
|
|
3397
|
+
return;
|
|
3398
|
+
}
|
|
3399
|
+
if (!mode) {
|
|
3400
|
+
sendJson(res, { success: false, error: '缺少 mode' });
|
|
3401
|
+
return;
|
|
3402
|
+
}
|
|
3403
|
+
const instance = await ensureOnline(aid);
|
|
3404
|
+
await ensureGroupClient(instance);
|
|
3405
|
+
const ops = instance.agentCP.groupOps;
|
|
3406
|
+
const target = instance.groupTargetAid;
|
|
3407
|
+
await ops.updateDutyConfig(target, groupId, { mode });
|
|
3408
|
+
utils_1.logger.log('[ACP] 值班规则已更新:', mode, 'groupId:', groupId);
|
|
3409
|
+
sendJson(res, { success: true });
|
|
3410
|
+
}
|
|
3411
|
+
catch (e) {
|
|
3412
|
+
sendJson(res, { success: false, error: e.message });
|
|
3413
|
+
}
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3062
3416
|
// 404
|
|
3063
3417
|
res.writeHead(404);
|
|
3064
3418
|
res.end('Not Found');
|
|
@@ -3092,16 +3446,16 @@ function startServer(port, apiUrl, dataDir = '') {
|
|
|
3092
3446
|
if (parts.length >= 3) {
|
|
3093
3447
|
const domain = parts.slice(1).join('.');
|
|
3094
3448
|
if (domain !== globalApiUrl) {
|
|
3095
|
-
|
|
3449
|
+
utils_1.logger.log(`[Server] 检测到 AID 所属 AP 为 ${domain},正在切换...`);
|
|
3096
3450
|
globalApiUrl = domain;
|
|
3097
3451
|
agentCP = new agentcp_1.AgentCP(domain, '', dataDir || undefined, { persistMessages: true, persistGroupMessages: true });
|
|
3098
3452
|
await agentCP.loadCurrentAid();
|
|
3099
3453
|
}
|
|
3100
3454
|
}
|
|
3101
|
-
|
|
3455
|
+
utils_1.logger.log(`已加载 AID: ${aid}`);
|
|
3102
3456
|
// 加载该 AID 的持久化会话
|
|
3103
3457
|
await ensureMessageStoreLoaded(aid);
|
|
3104
|
-
|
|
3458
|
+
utils_1.logger.log(`已加载会话`);
|
|
3105
3459
|
}
|
|
3106
3460
|
}).catch(() => { });
|
|
3107
3461
|
const server = http.createServer(handleRequest);
|
|
@@ -3128,7 +3482,7 @@ function startServer(port, apiUrl, dataDir = '') {
|
|
|
3128
3482
|
browserWsClients.set(ws, client);
|
|
3129
3483
|
wsAliveMap.set(ws, true);
|
|
3130
3484
|
ws.on('pong', () => wsAliveMap.set(ws, true));
|
|
3131
|
-
|
|
3485
|
+
utils_1.logger.log(`[WS] browser client connected, total=${browserWsClients.size}`);
|
|
3132
3486
|
ws.on('message', (raw) => {
|
|
3133
3487
|
try {
|
|
3134
3488
|
const msg = JSON.parse(raw.toString());
|
|
@@ -3152,10 +3506,10 @@ function startServer(port, apiUrl, dataDir = '') {
|
|
|
3152
3506
|
});
|
|
3153
3507
|
ws.on('close', () => {
|
|
3154
3508
|
browserWsClients.delete(ws);
|
|
3155
|
-
|
|
3509
|
+
utils_1.logger.log(`[WS] browser client disconnected, total=${browserWsClients.size}`);
|
|
3156
3510
|
});
|
|
3157
3511
|
ws.on('error', (err) => {
|
|
3158
|
-
|
|
3512
|
+
utils_1.logger.error('[WS] browser client error:', err.message);
|
|
3159
3513
|
browserWsClients.delete(ws);
|
|
3160
3514
|
});
|
|
3161
3515
|
});
|
|
@@ -3166,7 +3520,7 @@ function startServer(port, apiUrl, dataDir = '') {
|
|
|
3166
3520
|
});
|
|
3167
3521
|
// 资源清理函数
|
|
3168
3522
|
const cleanup = async () => {
|
|
3169
|
-
|
|
3523
|
+
utils_1.logger.log('\n正在关闭服务...');
|
|
3170
3524
|
clearInterval(wssHeartbeat);
|
|
3171
3525
|
// 持久化 agent info 缓存
|
|
3172
3526
|
saveAgentInfoCacheToDisk();
|
|
@@ -3175,25 +3529,25 @@ function startServer(port, apiUrl, dataDir = '') {
|
|
|
3175
3529
|
for (const [aid, store] of messageStores) {
|
|
3176
3530
|
await store.flushAll();
|
|
3177
3531
|
}
|
|
3178
|
-
|
|
3532
|
+
utils_1.logger.log('[Server] 会话已保存');
|
|
3179
3533
|
}
|
|
3180
3534
|
catch (e) {
|
|
3181
|
-
|
|
3535
|
+
utils_1.logger.error('[Server] 保存会话失败:', e);
|
|
3182
3536
|
}
|
|
3183
3537
|
for (const [aid, instance] of aidInstances) {
|
|
3184
|
-
|
|
3538
|
+
utils_1.logger.log(`[Server] 清理 AID: ${aid}`);
|
|
3185
3539
|
if (instance.groupInitialized) {
|
|
3186
3540
|
try {
|
|
3187
3541
|
await instance.agentCP.leaveAllGroupSessions();
|
|
3188
3542
|
}
|
|
3189
3543
|
catch (e) {
|
|
3190
|
-
|
|
3544
|
+
utils_1.logger.warn(`[Server] leaveAllGroupSessions error:`, e.message);
|
|
3191
3545
|
}
|
|
3192
3546
|
try {
|
|
3193
3547
|
await instance.agentCP.closeGroupMessageStore();
|
|
3194
3548
|
}
|
|
3195
3549
|
catch (e) {
|
|
3196
|
-
|
|
3550
|
+
utils_1.logger.warn(`[Server] closeGroupMessageStore error:`, e.message);
|
|
3197
3551
|
}
|
|
3198
3552
|
}
|
|
3199
3553
|
if (instance.heartbeatClient) {
|
|
@@ -3211,7 +3565,7 @@ function startServer(port, apiUrl, dataDir = '') {
|
|
|
3211
3565
|
browserWsClients.clear();
|
|
3212
3566
|
wss.close();
|
|
3213
3567
|
server.close(() => {
|
|
3214
|
-
|
|
3568
|
+
utils_1.logger.log('服务已关闭');
|
|
3215
3569
|
process.exit(0);
|
|
3216
3570
|
});
|
|
3217
3571
|
};
|
|
@@ -3221,20 +3575,20 @@ function startServer(port, apiUrl, dataDir = '') {
|
|
|
3221
3575
|
// 处理端口占用错误
|
|
3222
3576
|
server.on('error', (err) => {
|
|
3223
3577
|
if (err.code === 'EADDRINUSE') {
|
|
3224
|
-
|
|
3225
|
-
|
|
3578
|
+
utils_1.logger.error(`\n 错误: 端口 ${port} 已被占用`);
|
|
3579
|
+
utils_1.logger.error(` 请使用 -p 参数指定其他端口,或关闭占用该端口的程序\n`);
|
|
3226
3580
|
process.exit(1);
|
|
3227
3581
|
}
|
|
3228
3582
|
throw err;
|
|
3229
3583
|
});
|
|
3230
3584
|
server.listen(port, () => {
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3585
|
+
utils_1.logger.log(`\n ACP 身份管理服务已启动`);
|
|
3586
|
+
utils_1.logger.log(` ─────────────────────────`);
|
|
3587
|
+
utils_1.logger.log(` 本地地址: http://localhost:${port}`);
|
|
3588
|
+
utils_1.logger.log(` API 服务: ${apiUrl}`);
|
|
3235
3589
|
if (dataDir) {
|
|
3236
|
-
|
|
3590
|
+
utils_1.logger.log(` 数据目录: ${dataDir}`);
|
|
3237
3591
|
}
|
|
3238
|
-
|
|
3592
|
+
utils_1.logger.log(`\n 按 Ctrl+C 停止服务\n`);
|
|
3239
3593
|
});
|
|
3240
3594
|
}
|