Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ export function pluginRuntimeInfoFor(agent: string | undefined, model: string |
const CHILD_CONVERSATION_SUFFIX = /:(?:side(?::conversation)?|sub):[^:]+$/;
const MAX_CHILD_CONVERSATION_DEPTH = 4;

function parentConversationId(conversationId: string): string | undefined {
export function parentConversationId(conversationId: string): string | undefined {
const parent = conversationId.replace(CHILD_CONVERSATION_SUFFIX, "");
return parent !== conversationId && parent.length > 0 ? parent : undefined;
}
Expand Down
6 changes: 4 additions & 2 deletions src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ async function sendDiagnostics(res: http.ServerResponse, url: string | null): Pr
res.end(JSON.stringify(await buildDiagnostics(topic), null, 2));
}

/** #1937:携带搜索、协议、客户端、状态或分页参数时,启用服务端筛选分页。
/** #1937:携带搜索、协议、客户端、状态、层级、side/sub 开关或分页参数时,启用服务端筛选分页。
* 无参数时保留原响应结构,兼容旧界面;每页最多返回 200 条。 */
async function sendWebSessions(res: http.ServerResponse, req: http.IncomingMessage): Promise<void> {
const u = new URL(req.url ?? "/__bili/sessions", "http://localhost");
Expand All @@ -1605,7 +1605,8 @@ async function sendWebSessions(res: http.ServerResponse, req: http.IncomingMessa
u.searchParams.has("protocol") ||
u.searchParams.has("client") ||
u.searchParams.has("state") ||
u.searchParams.has("kind");
u.searchParams.has("kind") ||
u.searchParams.has("children");
if (paged) {
const rawSize = Number(u.searchParams.get("pageSize"));
const pageSize = Number.isFinite(rawSize) && rawSize > 0 ? Math.min(Math.floor(rawSize), 200) : 50;
Expand All @@ -1622,6 +1623,7 @@ async function sendWebSessions(res: http.ServerResponse, req: http.IncomingMessa
client: u.searchParams.get("client") ?? undefined,
state,
kind,
showChildren: u.searchParams.get("children") === "1",
page,
pageSize,
})),
Expand Down
27 changes: 21 additions & 6 deletions src/web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ export const WEB_CLIENT = `(function () {
// not live.
const named = Boolean(s.title || s.label || s.firstBlockHint);
const name = s.title || s.label || s.firstBlockHint || t("ses.no_title");
const live = s.live && !s.restored;
const live = s.live;
// Only actively running sessions get a status tag; disk/restored rows carry none.
// The whole cell is a real hash anchor: plain clicks route inside the SPA exactly as
// before (the row handler bails on <a>), while Ctrl/Cmd+click or middle-click opens
Expand Down Expand Up @@ -812,9 +812,16 @@ export const WEB_CLIENT = `(function () {
const laneChip = s.engineLane === "inline"
? ' <span class="badge proto" title="' + escapeHtml(t("det.engine_lane_inline")) + '">inline</span>'
: s.engineLane === "server" ? ' <span class="badge proto dim" title="' + escapeHtml(t("det.engine_lane_server")) + '">srv</span>' : "";
// #7876: child (:side:/:sub:) sessions are one-shot auxiliary calls —
// mark them so the row reads as a sub-call, not a top-level session.
// Declared-lineage children (parentSessionId) already carry the
// title-cell "child" badge — no second badge.
const childChip = s.child && !s.parentSessionId
? ' <span class="badge child" title="' + escapeHtml(t("ses.badge_aux_tip")) + '">' + t("ses.badge_aux") + "</span>"
: "";
const clientCell = clientHint
? '<span class="mono small clip w-client" title="' + escapeHtml(clientHint) + '">' + escapeHtml(clientHint) + "</span>" + laneChip
: '<span class="dim">' + t("common.none") + "</span>" + laneChip;
? '<span class="mono small clip w-client" title="' + escapeHtml(clientHint) + '">' + escapeHtml(clientHint) + "</span>" + laneChip + childChip
: '<span class="dim">' + t("common.none") + "</span>" + laneChip + childChip;
tr.innerHTML = "<td>" + sessionTitleCell(s) + '</td><td class="client-cell">' + clientCell + '</td><td>' + protoBadge(s.protocol) + '</td><td><span class="mono dim small clip w-up">' + escapeHtml(hostOf(s.upstreamOrigin)) + '</td><td class="num">' + (s.requests ? s.requests : t("common.none")) + '</td><td class="num">' + fmtW(s.contextBest ? s.contextBest.tokens : s.contextTokens) + '</td><td class="num">' + (s.inputTokens ? fmtW(s.inputTokens) : '<span class="dim">' + t("common.none") + "</span>") + "</td>" + savedTd(s) + hitTd(s) + switchTd(s) + '<td class="num">' + (s.foldCount || 0) + '</td><td class="num">' + (s.blocks || 0) + '</td><td class="dim">' + timeAgo(s.lastSeen) + "</td>";
}
let navTimer = null;
Expand Down Expand Up @@ -1939,12 +1946,15 @@ function changelogCatOf(rawLine) {
const client = filterValue("ses-client");
const state = filterValue("ses-state");
const kind = filterValue("ses-kind");
const childrenEl = $("ses-children");
const showChildren = Boolean(childrenEl && childrenEl.checked);
return API_ROOT + "/sessions?page=" + page + "&pageSize=" + SES_PAGE_SIZE +
(q ? "&q=" + encodeURIComponent(q) : "") +
(protocol ? "&protocol=" + encodeURIComponent(protocol) : "") +
(client ? "&client=" + encodeURIComponent(client) : "") +
(state ? "&state=" + encodeURIComponent(state) : "") +
(kind ? "&kind=" + encodeURIComponent(kind) : "");
(kind ? "&kind=" + encodeURIComponent(kind) : "") +
(showChildren ? "&children=1" : "");
}
function filterValue(id) {
const el = $(id);
Expand Down Expand Up @@ -1986,7 +1996,8 @@ function changelogCatOf(rawLine) {
}
function hasActiveFilters() {
const q = (($("ses-search") && $("ses-search").value) || "").trim();
return Boolean(q || filterValue("ses-protocol") || filterValue("ses-client") || filterValue("ses-state") || filterValue("ses-kind"));
const childrenEl = $("ses-children");
return Boolean(q || filterValue("ses-protocol") || filterValue("ses-client") || filterValue("ses-state") || filterValue("ses-kind") || (childrenEl && childrenEl.checked));
}
function updatePager() {
const prev = $("ses-prev");
Expand Down Expand Up @@ -2015,6 +2026,8 @@ function changelogCatOf(rawLine) {
const search = $("ses-search");
if (search) search.value = "";
["ses-protocol", "ses-client", "ses-state", "ses-kind"].forEach((id) => { const el = $(id); if (el) el.value = ""; });
const childrenEl = $("ses-children");
if (childrenEl) childrenEl.checked = false;
return refreshSessions(false, 1);
}
function renderSessionTable() {
Expand Down Expand Up @@ -2828,7 +2841,7 @@ function changelogCatOf(rawLine) {
return plain.length > 48 ? plain.slice(0, 48) + "…" : plain || b.blockId;
}
function detailBadges(d) {
const live = d.live && !d.restored;
const live = d.live;
let html = "";
if (live) html = '<span class="badge live" title="' + escapeHtml(t("ses.badge_live_tip")) + '">' + t("common.live") + "</span>";
if (d.protocol) html += (html ? " " : "") + protoBadge(d.protocol);
Expand Down Expand Up @@ -5900,6 +5913,8 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " +
const el = $(id);
if (el) el.addEventListener("change", () => refreshSessions(false, 1));
});
const sesChildren = $("ses-children");
if (sesChildren) sesChildren.addEventListener("change", () => refreshSessions(false, 1));
const reset = $("ses-reset-filters");
if (reset) reset.addEventListener("click", resetSessionFilters);
const prev = $("ses-prev");
Expand Down
18 changes: 15 additions & 3 deletions src/web/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"common.live": "运行中",
"common.sessions": "会话",
"common.copied_hint": "已复制 ✓",
"ses.badge_live_tip": "当前进程正在处理的会话(实时数据)",
"ses.badge_live_tip": "最近 10 分钟内有活动的会话(在内存中且最近使用)",
"ses.badge_child": "子会话",
"ses.badge_child_tip": "由父会话派生的 subagent/子会话",
"ses.badge_aux": "side",
"ses.badge_aux_tip": "客户端辅助调用(一次性 side/sub 请求),默认隐藏",
"ses.slow_short": "长会话",
"ses.slow_tip": "已处理 {n} 次模型请求——宿主侧对话历史只增不减(压缩只缩发给模型的量,不缩宿主自己的文件),步耗时会随之变慢。建议开一个新会话继续。",
"common.requests": "请求",
Expand Down Expand Up @@ -370,6 +372,8 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"ses.filter_kind_all": "全部层级",
"ses.filter_kind_top": "仅顶层会话",
"ses.filter_kind_child": "仅子会话",
"ses.filter_children": "显示 side/sub 会话",
"ses.filter_children_tip": "客户端辅助调用(:side:/:sub:)默认隐藏,勾选后显示",
"ses.filter_unknown": "未知",
"ses.reset_filters": "重置筛选",
"ses.prev_page": "上一页",
Expand Down Expand Up @@ -891,9 +895,11 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"common.live": "live",
"common.sessions": "sessions",
"common.copied_hint": "Copied ✓",
"ses.badge_live_tip": "Session being processed by the current daemon (live data)",
"ses.badge_live_tip": "Active in the last 10 minutes (in memory and recently used)",
"ses.badge_child": "child",
"ses.badge_child_tip": "Subagent/derived session spawned by a parent session",
"ses.badge_aux": "side",
"ses.badge_aux_tip": "Client auxiliary call (one-shot side/sub request), hidden by default",
"ses.slow_short": "slow",
"ses.slow_tip": "{n} requests so far — the host-side history only grows (compression shrinks what is sent to the model, not the host's own file), so each step gets slower over time. Consider starting a new session.",
"common.requests": "requests",
Expand Down Expand Up @@ -1193,6 +1199,8 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"ses.filter_kind_all": "All levels",
"ses.filter_kind_top": "Top-level only",
"ses.filter_kind_child": "Child sessions only",
"ses.filter_children": "Show side/sub sessions",
"ses.filter_children_tip": "Client auxiliary calls (:side:/:sub:) are hidden by default; check to show them",
"ses.filter_unknown": "Unknown",
"ses.reset_filters": "Reset filters",
"ses.prev_page": "Previous",
Expand Down Expand Up @@ -1714,9 +1722,11 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"common.live": "실시간",
"common.sessions": "세션",
"common.copied_hint": "복사됨 ✓",
"ses.badge_live_tip": "현재 데몬이 처리 중인 세션 (실시간 데이터)",
"ses.badge_live_tip": "최근 10분 동안 활동이 있는 세션 (메모리에 존재하고 최근에 사용됨)",
"ses.badge_child": "자식 세션",
"ses.badge_child_tip": "부모 세션에서 파생된 subagent/자식 세션",
"ses.badge_aux": "side",
"ses.badge_aux_tip": "클라이언트 보조 호출 (일회성 side/sub 요청), 기본적으로 숨김",
"ses.filter_kind_all": "모든 레벨",
"ses.filter_kind_child": "자식 세션만",
"ses.filter_kind_tip": "상위/자식 레벨로 필터",
Expand Down Expand Up @@ -2008,6 +2018,8 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"ses.filter_state_all": "모든 상태",
"ses.filter_state_live": "실행 중",
"ses.filter_state_history": "과거",
"ses.filter_children": "side/sub 세션 표시",
"ses.filter_children_tip": "클라이언트 보조 호출(:side:/:sub:)은 기본적으로 숨겨지며, 체크하면 표시됩니다",
"ses.filter_unknown": "알 수 없음",
"ses.reset_filters": "필터 초기화",
"ses.prev_page": "이전",
Expand Down
2 changes: 1 addition & 1 deletion src/web/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function renderPage(origin: string, version: string, embed = false, theme
<section id="page-sessions" class="page" hidden>
<div id="sessions-list-view">
<div class="page-head"><div><h1 data-i18n="ses.title">${zh("ses.title")}</h1><div class="sub" data-i18n="ses.sub">${zh("ses.sub")}</div></div>
<div class="ses-toolbar"><input id="ses-search" type="search" class="search" placeholder="${zh("ses.search_ph")}" data-i18n-ph="ses.search_ph"><select id="ses-protocol" class="ses-filter" data-i18n-title="ses.filter_protocol_tip" title="${zh("ses.filter_protocol_tip")}"></select><select id="ses-client" class="ses-filter" data-i18n-title="ses.filter_client_tip" title="${zh("ses.filter_client_tip")}"></select><select id="ses-state" class="ses-filter" data-i18n-title="ses.filter_state_tip" title="${zh("ses.filter_state_tip")}"><option value="" data-i18n="ses.filter_state_all">${zh("ses.filter_state_all")}</option><option value="live" data-i18n="ses.filter_state_live">${zh("ses.filter_state_live")}</option><option value="history" data-i18n="ses.filter_state_history">${zh("ses.filter_state_history")}</option></select><select id="ses-kind" class="ses-filter" data-i18n-title="ses.filter_kind_tip" title="${zh("ses.filter_kind_tip")}"><option value="" data-i18n="ses.filter_kind_all">${zh("ses.filter_kind_all")}</option><option value="top" data-i18n="ses.filter_kind_top">${zh("ses.filter_kind_top")}</option><option value="child" data-i18n="ses.filter_kind_child">${zh("ses.filter_kind_child")}</option></select><button id="ses-reset-filters" class="btn sm" data-i18n="ses.reset_filters">${zh("ses.reset_filters")}</button><button id="ses-refresh" class="btn sm"><span data-i18n="ses.refresh">${zh("ses.refresh")}</span></button></div></div>
<div class="ses-toolbar"><input id="ses-search" type="search" class="search" placeholder="${zh("ses.search_ph")}" data-i18n-ph="ses.search_ph"><select id="ses-protocol" class="ses-filter" data-i18n-title="ses.filter_protocol_tip" title="${zh("ses.filter_protocol_tip")}"></select><select id="ses-client" class="ses-filter" data-i18n-title="ses.filter_client_tip" title="${zh("ses.filter_client_tip")}"></select><select id="ses-state" class="ses-filter" data-i18n-title="ses.filter_state_tip" title="${zh("ses.filter_state_tip")}"><option value="" data-i18n="ses.filter_state_all">${zh("ses.filter_state_all")}</option><option value="live" data-i18n="ses.filter_state_live">${zh("ses.filter_state_live")}</option><option value="history" data-i18n="ses.filter_state_history">${zh("ses.filter_state_history")}</option></select><select id="ses-kind" class="ses-filter" data-i18n-title="ses.filter_kind_tip" title="${zh("ses.filter_kind_tip")}"><option value="" data-i18n="ses.filter_kind_all">${zh("ses.filter_kind_all")}</option><option value="top" data-i18n="ses.filter_kind_top">${zh("ses.filter_kind_top")}</option><option value="child" data-i18n="ses.filter_kind_child">${zh("ses.filter_kind_child")}</option></select><label class="ses-toggle" data-i18n-title="ses.filter_children_tip" title="${zh("ses.filter_children_tip")}"><input id="ses-children" type="checkbox"><span data-i18n="ses.filter_children">${zh("ses.filter_children")}</span></label><button id="ses-reset-filters" class="btn sm" data-i18n="ses.reset_filters">${zh("ses.reset_filters")}</button><button id="ses-refresh" class="btn sm"><span data-i18n="ses.refresh">${zh("ses.refresh")}</span></button></div></div>
<div class="ses-meta"><span id="ses-count" class="dim small"></span><span id="ses-empty-hint" class="dim small" hidden></span></div>
<div class="card"><div class="card-b flush"><div class="twrap twide"><table class="data"><colgroup><col><col style="width:52px"><col style="width:84px"><col style="width:104px"><col style="width:48px"><col style="width:62px"><col style="width:62px"><col style="width:62px"><col style="width:190px"><col style="width:72px"><col style="width:48px"><col style="width:48px"><col style="width:56px"></colgroup><thead><tr>
<th data-i18n="ses.th_title">${zh("ses.th_title")}</th><th data-i18n="ses.th_client">${zh("ses.th_client")}</th><th data-i18n="ses.th_proto">${zh("ses.th_proto")}</th><th data-i18n="ses.th_upstream">${zh("ses.th_upstream")}</th><th class="num" data-i18n="ses.th_reqs">${zh("ses.th_reqs")}</th><th class="num" data-i18n="ses.th_ctx">${zh("ses.th_ctx")}</th><th class="num" data-i18n="ses.th_input">${zh("ses.th_input")}</th><th class="num" data-i18n="ses.th_saved">${zh("ses.th_saved")}</th><th class="num" data-i18n="ses.th_hit">${zh("ses.th_hit")}</th><th class="num" title="${zh("ses.th_switches_tip")}" data-i18n-title="ses.th_switches_tip" data-i18n="ses.th_switches">${zh("ses.th_switches")}</th><th class="num" data-i18n="ses.th_folds">${zh("ses.th_folds")}</th><th class="num" data-i18n="ses.th_blocks">${zh("ses.th_blocks")}</th><th data-i18n="ses.th_seen">${zh("ses.th_seen")}</th>
Expand Down
Loading
Loading