refactor: Business logic and dependencies updates

- 核心服务代码更新 (db, server, auth, proxy)
- Agent 相关模块更新 (mindspace, experience)
- 前端组件和 hooks 更新
- 数据库 schema 更新
- 依赖版本更新
This commit is contained in:
john
2026-06-27 08:25:02 +08:00
parent f1220a7905
commit 25f8223253
20 changed files with 1458 additions and 116 deletions
+28 -5
View File
@@ -639,15 +639,27 @@ export function createUserAuth(pool, options = {}) {
}
};
const registerAgentSession = async (userId, agentSessionId, goosedNode = 0) => {
// goosedTarget may be the upstream URL the session is pinned to (preferred), or
// a legacy integer index into the targets list. We persist the URL in
// goosed_target and still derive a numeric goosed_node so older readers keep
// working; a string target stores goosed_node = 0 (its value is ignored once
// goosed_target is set).
const registerAgentSession = async (userId, agentSessionId, goosedTarget = 0) => {
const isLegacyIndex =
typeof goosedTarget === 'number' || /^\d+$/.test(String(goosedTarget));
const goosedNode = isLegacyIndex ? Number(goosedTarget) : 0;
const targetUrl = isLegacyIndex ? null : String(goosedTarget);
await pool.query(
`INSERT INTO h5_user_sessions (agent_session_id, user_id, goosed_node, created_at)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE user_id = VALUES(user_id), goosed_node = VALUES(goosed_node)`,
[agentSessionId, userId, goosedNode, Date.now()],
`INSERT INTO h5_user_sessions (agent_session_id, user_id, goosed_node, goosed_target, created_at)
VALUES (?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE user_id = VALUES(user_id),
goosed_node = VALUES(goosed_node), goosed_target = VALUES(goosed_target)`,
[agentSessionId, userId, goosedNode, targetUrl, Date.now()],
);
};
// Legacy integer-index accessor, kept for callers/bundles that still route by
// array index. Prefer getSessionTarget.
const getSessionNode = async (agentSessionId) => {
const [rows] = await pool.query(
`SELECT goosed_node FROM h5_user_sessions WHERE agent_session_id = ? LIMIT 1`,
@@ -656,6 +668,16 @@ export function createUserAuth(pool, options = {}) {
return rows[0]?.goosed_node ?? 0;
};
// Returns { target, node }: target is the pinned upstream URL (null if the row
// predates goosed_target), node is the legacy integer index fallback.
const getSessionTarget = async (agentSessionId) => {
const [rows] = await pool.query(
`SELECT goosed_node, goosed_target FROM h5_user_sessions WHERE agent_session_id = ? LIMIT 1`,
[agentSessionId],
);
return { target: rows[0]?.goosed_target ?? null, node: rows[0]?.goosed_node ?? 0 };
};
const ownsSession = async (userId, agentSessionId) => {
const [rows] = await pool.query(
`SELECT 1 FROM h5_user_sessions WHERE agent_session_id = ? AND user_id = ? LIMIT 1`,
@@ -2645,6 +2667,7 @@ export function createUserAuth(pool, options = {}) {
repairAllUserPublishDirs,
registerAgentSession,
getSessionNode,
getSessionTarget,
unregisterAgentSession,
ownsSession,
listOwnedSessionIds,