acp-ts 1.2.6 → 1.2.7

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.
Files changed (2) hide show
  1. package/dist/server.js +35 -15
  2. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -376,7 +376,7 @@ async function doInitGroupClient(instance) {
376
376
  },
377
377
  onJoinApproved(groupId, groupAddress) {
378
378
  utils_1.logger.log(`[Group] onJoinApproved: group=${groupId} address=${groupAddress}`);
379
- // 审核通过:获取群信息、添加本地存储、注册到 Home AP
379
+ // 审核通过:获取群信息、添加本地存储、注册在线,完成后再通知浏览器
380
380
  (async () => {
381
381
  try {
382
382
  if (!instance.agentCP.groupOps) {
@@ -396,12 +396,13 @@ async function doInitGroupClient(instance) {
396
396
  catch (e) {
397
397
  utils_1.logger.error(`[Group] onJoinApproved processing failed: group=${groupId}`, e.message);
398
398
  }
399
+ // 本地存储就绪后再通知浏览器刷新群列表
400
+ broadcastToBrowser({
401
+ type: 'join_approved',
402
+ group_id: groupId,
403
+ group_address: groupAddress,
404
+ });
399
405
  })();
400
- broadcastToBrowser({
401
- type: 'join_approved',
402
- group_id: groupId,
403
- group_address: groupAddress,
404
- });
405
406
  },
406
407
  onJoinRejected(groupId, reason) {
407
408
  utils_1.logger.log(`[Group] onJoinRejected: group=${groupId} reason=${reason}`);
@@ -3320,15 +3321,13 @@ async function handleRequest(req, res) {
3320
3321
  }
3321
3322
  const instance = await ensureOnline(aid);
3322
3323
  await ensureGroupClient(instance);
3323
- // 首次访问时从服务端同步群组列表
3324
- if (!instance.groupListSynced) {
3325
- try {
3326
- await instance.agentCP.syncGroupList();
3327
- instance.groupListSynced = true;
3328
- }
3329
- catch (syncErr) {
3330
- utils_1.logger.warn('[Group] syncGroupList error:', syncErr.message);
3331
- }
3324
+ // 每次都从服务端同步群组列表,确保审核通过等变更及时反映
3325
+ try {
3326
+ await instance.agentCP.syncGroupList();
3327
+ instance.groupListSynced = true;
3328
+ }
3329
+ catch (syncErr) {
3330
+ utils_1.logger.warn('[Group] syncGroupList error:', syncErr.message);
3332
3331
  }
3333
3332
  const groups = instance.agentCP.getLocalGroupList();
3334
3333
  sendJson(res, { success: true, groups, activeGroupId: instance.activeGroupId });
@@ -3607,6 +3606,27 @@ async function handleRequest(req, res) {
3607
3606
  }
3608
3607
  const instance = await ensureOnline(aid);
3609
3608
  await ensureGroupClient(instance);
3609
+ // 同步服务端群列表到本地存储,确保新审核通过的群也能在左侧列表显示
3610
+ try {
3611
+ await instance.agentCP.syncGroupList();
3612
+ instance.groupListSynced = true;
3613
+ }
3614
+ catch (syncErr) {
3615
+ utils_1.logger.warn('[Group] my-groups syncGroupList error:', syncErr.message);
3616
+ }
3617
+ // 确保所有本地群都已注册在线
3618
+ const localGroups = instance.agentCP.getLocalGroupList();
3619
+ const onlineGroups = new Set(instance.agentCP.getOnlineGroups());
3620
+ for (const g of localGroups) {
3621
+ if (!onlineGroups.has(g.group_id)) {
3622
+ try {
3623
+ await instance.agentCP.joinGroupSession(g.group_id);
3624
+ }
3625
+ catch (e) {
3626
+ utils_1.logger.warn(`[Group] my-groups joinGroupSession failed: ${g.group_id}`, e.message);
3627
+ }
3628
+ }
3629
+ }
3610
3630
  const ops = instance.agentCP.groupOps;
3611
3631
  const target = instance.groupTargetAid;
3612
3632
  const result = await ops.listMyGroups(target);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acp-ts",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "基于 ACP智能体通信协议 的智能体通信库,提供智能体身份管理和实时通信功能",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",