From aca61333184478f67b1344154cc34c8d2efa9bb0 Mon Sep 17 00:00:00 2001 From: Askhz <1361267452@qq.com> Date: Sat, 9 May 2026 09:59:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20serve=20=E6=A8=A1=E5=BC=8F=20session=20?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8C=89=E5=B7=A5=E4=BD=9C=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 从请求头 x-csc-directory 读取工作目录(cs-cloud 通过此头传递), GET /session 和 GET /session/status 只返回该目录下的历史会话 Co-Authored-By: Claude Opus 4.7 --- src/server/routes/session.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/server/routes/session.ts b/src/server/routes/session.ts index e2de66a41..b580b059f 100644 --- a/src/server/routes/session.ts +++ b/src/server/routes/session.ts @@ -169,7 +169,12 @@ export function createSessionRoutes( const url = new URL(c.req.url) const limit = parseInt(url.searchParams.get('limit') ?? '50', 10) const offset = parseInt(url.searchParams.get('offset') ?? '0', 10) - const dir = url.searchParams.get('dir') ?? undefined + // 优先从请求头 x-csc-directory 取工作目录(cs-cloud 通过此头传递), + // fallback 到 query string 的 dir 参数 + const headerDir = c.req.header('x-csc-directory') + const dir = (headerDir ? decodeURIComponent(headerDir) : undefined) + ?? url.searchParams.get('dir') + ?? undefined // roots=true 时只返回没有 parentID 的顶层 session(csc 无 parent 概念,全部视为 root) // const rootsOnly = url.searchParams.get('roots') === 'true' @@ -242,10 +247,16 @@ export function createSessionRoutes( // 内存中活跃 session 的状态 const activeStatuses = sessionManager.getSessionStatuses() + // 从请求头或 query 取目录过滤 + const headerDir = c.req.header('x-csc-directory') + const statusDir = (headerDir ? decodeURIComponent(headerDir) : undefined) + ?? c.req.query('dir') + ?? undefined + // 补充磁盘历史 session(全部视为 idle) let historySessions: Awaited> = [] try { - historySessions = await listSessionsImpl({ limit: 200 }) + historySessions = await listSessionsImpl({ dir: statusDir, limit: 200 }) } catch {} const sessions: Record = {}