|
@@ -362,21 +362,34 @@ export function sessionStateOf(
|
|
|
sessions: AgentSessionState[] | undefined,
|
|
sessions: AgentSessionState[] | undefined,
|
|
|
appSessionId: string | null | undefined,
|
|
appSessionId: string | null | undefined,
|
|
|
roomIdOf?: string | null,
|
|
roomIdOf?: string | null,
|
|
|
|
|
+ myUserId?: string | null,
|
|
|
): AgentSessionState | undefined {
|
|
): AgentSessionState | undefined {
|
|
|
if (!sessions?.length || !appSessionId) return undefined;
|
|
if (!sessions?.length || !appSessionId) return undefined;
|
|
|
// 去掉 App 会话 id 的域名后缀,只留主体($approot_xxx)
|
|
// 去掉 App 会话 id 的域名后缀,只留主体($approot_xxx)
|
|
|
const core = appSessionId.split(':')[0];
|
|
const core = appSessionId.split(':')[0];
|
|
|
if (!core) return undefined;
|
|
if (!core) return undefined;
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 🔴 0. 先按 userId 收窄(2026-11-11,多人共用容器时必需)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 容器可能被同公司多人共享,`currentSessions` 是容器级的一个列表。
|
|
|
|
|
+ * 若列表里同时有多个用户的会话,而群聊又共用一个 thread(roomId 相同),
|
|
|
|
|
+ * 光靠 roomId 命中会把「别人在跑」误判成「我在跑」。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 只在**容器确实上报了 userId** 时才收窄:老容器不上报 → 保持原行为。
|
|
|
|
|
+ */
|
|
|
|
|
+ const mine = myUserId ? sessions.filter((s) => !s.userId || s.userId === myUserId) : sessions;
|
|
|
|
|
+ const pool = mine.length ? mine : sessions;
|
|
|
|
|
+
|
|
|
/* ① 精确:thread 根命中 */
|
|
/* ① 精确:thread 根命中 */
|
|
|
- const byThread = sessions.find(
|
|
|
|
|
|
|
+ const byThread = pool.find(
|
|
|
(s) => s.sessionKey.includes(core) || s.sessionKey.includes(appSessionId),
|
|
(s) => s.sessionKey.includes(core) || s.sessionKey.includes(appSessionId),
|
|
|
);
|
|
);
|
|
|
if (byThread) return byThread;
|
|
if (byThread) return byThread;
|
|
|
|
|
|
|
|
/* ② 退路:roomId 命中(DM 无 thread 的场景) */
|
|
/* ② 退路:roomId 命中(DM 无 thread 的场景) */
|
|
|
if (roomIdOf) {
|
|
if (roomIdOf) {
|
|
|
- return sessions.find((s) => s.sessionKey.includes(roomIdOf));
|
|
|
|
|
|
|
+ return pool.find((s) => s.sessionKey.includes(roomIdOf));
|
|
|
}
|
|
}
|
|
|
return undefined;
|
|
return undefined;
|
|
|
}
|
|
}
|
|
@@ -391,7 +404,8 @@ export function sessionRunning(
|
|
|
sessions: AgentSessionState[] | undefined,
|
|
sessions: AgentSessionState[] | undefined,
|
|
|
appSessionId: string | null | undefined,
|
|
appSessionId: string | null | undefined,
|
|
|
roomIdOf?: string | null,
|
|
roomIdOf?: string | null,
|
|
|
|
|
+ myUserId?: string | null,
|
|
|
): boolean | undefined {
|
|
): boolean | undefined {
|
|
|
- const s = sessionStateOf(sessions, appSessionId, roomIdOf);
|
|
|
|
|
|
|
+ const s = sessionStateOf(sessions, appSessionId, roomIdOf, myUserId);
|
|
|
return s ? s.status === 'running' : undefined;
|
|
return s ? s.status === 'running' : undefined;
|
|
|
}
|
|
}
|