Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const coreActionOrder = new Map<string, number>(
"session.new",
"sidebar.left.toggle",
"session.search",
"session.activityView",
"workspace.add",
"session.rename",
"session.fork",
Expand Down
144 changes: 144 additions & 0 deletions apps/web-ui/packages/client/ui-workspace/src/client/activity-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* Pure filtering, prioritization, and unread-ID collection for the sidebar Activity View.
* Reuses the sidebar display-tree derivation so child-thread activity rolls up consistently.
*/
import type { SessionListState } from "@deepseek-ai/dsh-api-session-controller/client";
import type { SessionId } from "@deepseek-ai/dsh-session/types";
import {
deriveThreadForest,
type SessionNode,
type SessionRowState,
type SessionStatuses,
} from "./tree.ts";

/** Activity priority bucket: lower number renders higher in the Activity View. */
export type ActivityPriority = 0 | 1 | 2;

/** Derived Activity View projection and attention counts within the active scope. */
export interface ActivityViewProjection {
/** Active root sessions ordered by priority (pending > running > unread) and recency. */
readonly rows: readonly SessionNode[];
/** All unread completed session IDs in scope, including visible thread-tree descendants. */
readonly unreadSessionIds: readonly SessionId[];
/** Total sessions (including descendants) with a pending user interaction. */
readonly pendingCount: number;
/** Total sessions (including descendants) running or hosting running subagents. */
readonly runningCount: number;
/** Total sessions (including descendants) with an unread completion reminder. */
readonly unreadCount: number;
/** True when at least one session in scope needs interaction or has an unread completion. */
readonly hasAttention: boolean;
}

/** Whether a single session row has a pending user interaction. */
function hasOwnPending(node: SessionNode): boolean {
return node.pendingInteraction !== undefined;
}

/** Whether a single session row is running or has active native subagents. */
function hasOwnRunning(node: SessionNode): boolean {
return node.running || node.runningSubagentCount > 0;
}

/** Whether a single session row has an unread completion reminder. */
function hasOwnUnread(node: SessionNode): boolean {
return node.completed;
}

/**
* Determine the highest activity priority for a root session node (including its descendants).
* Returns `null` when neither the node nor any visible descendant has active work or unread state.
*/
export function activityPriorityOf(node: SessionNode): ActivityPriority | null {
if (node.archived || node.blank) return null;
if (hasOwnPending(node) || (node.tree?.activity.pendingInteraction ?? 0) > 0) return 0;
if (hasOwnRunning(node) || (node.tree?.activity.running ?? 0) > 0) return 1;
if (hasOwnUnread(node) || (node.tree?.activity.completed ?? 0) > 0) return 2;
return null;
}

/**
* Collect all unread completed session IDs from a set of display-tree roots and their descendants.
* Excludes archived sessions and deduplicates IDs while preserving traversal order.
*/
export function collectUnreadSessionIds(roots: readonly SessionNode[]): SessionId[] {
const seen = new Set<SessionId>();
const result: SessionId[] = [];
const visit = (node: SessionNode): void => {
if (!node.archived && !node.blank && hasOwnUnread(node) && !seen.has(node.id)) {
seen.add(node.id);
result.push(node.id);
}
for (const child of node.tree?.children ?? []) {
visit(child);
}
};
for (const root of roots) {
visit(root);
}
return result;
}

/**
* Derive the sorted Activity View rows and attention counters for the current session scope.
* Archived sessions and blank drafts are always excluded, regardless of the main list's archive filter.
*/
export function deriveActivityView(
list: SessionListState,
rowState: SessionRowState,
statuses: SessionStatuses,
): ActivityViewProjection {
const activeRowState: SessionRowState = {
pinnedSessionIds: rowState.pinnedSessionIds,
archivedSessionIds: rowState.archivedSessionIds,
archivedFilter: "default",
...(rowState.sectionedSessionIds === undefined
? {}
: { sectionedSessionIds: rowState.sectionedSessionIds }),
};
const forest = deriveThreadForest(list, activeRowState, statuses);

const candidates: {
readonly node: SessionNode;
readonly priority: ActivityPriority;
readonly updatedAt: number;
readonly index: number;
}[] = [];

let pendingCount = 0;
let runningCount = 0;

for (let index = 0; index < forest.length; index++) {
const node = forest[index] as SessionNode;
const priority = activityPriorityOf(node);
if (priority === null) continue;
pendingCount += Number(hasOwnPending(node)) + (node.tree?.activity.pendingInteraction ?? 0);
runningCount += Number(hasOwnRunning(node)) + (node.tree?.activity.running ?? 0);
candidates.push({
node,
priority,
updatedAt: node.tree?.updatedAt ?? node.updatedAt,
index,
});
}

candidates.sort(
(left, right) =>
left.priority - right.priority ||
right.updatedAt - left.updatedAt ||
left.index - right.index,
);

const rows = candidates.map((entry) => entry.node);
const unreadSessionIds = collectUnreadSessionIds(rows);
const unreadCount = unreadSessionIds.length;

return {
rows,
unreadSessionIds,
pendingCount,
runningCount,
unreadCount,
hasAttention: pendingCount > 0 || unreadCount > 0,
};
}
12 changes: 12 additions & 0 deletions apps/web-ui/packages/client/ui-workspace/src/client/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export const zh = {
"empty.noMatches": "无匹配结果",
"workspace.add": "添加工作区",
"search.sessions.aria": "搜索会话",
"activityView.label": "活动视图",
"activityView.unreadCount.one": "· {n} 条未读",
"activityView.unreadCount.other": "· {n} 条未读",
"activityView.markAllRead": "全部已读",
"activityView.empty": "暂无未读或进行中的会话",
"activityView.backToAll": "返回全部会话",
"search.placeholder": "搜索会话名称",
"search.clear": "清除搜索",
"search.results.aria": "搜索结果",
Expand Down Expand Up @@ -341,6 +347,12 @@ export const en = {
"empty.noMatches": "No matches",
"workspace.add": "Add workspace",
"search.sessions.aria": "Search sessions",
"activityView.label": "Activity view",
"activityView.unreadCount.one": "· {n} unread",
"activityView.unreadCount.other": "· {n} unread",
"activityView.markAllRead": "Mark all read",
"activityView.empty": "No unread or active conversations",
"activityView.backToAll": "Back to all sessions",
"search.placeholder": "Search session names",
"search.clear": "Clear search",
"search.results.aria": "Search results",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
.toolbar {
flex: none;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
min-height: 30px;
margin: 0 calc(var(--dsh-session-list-edge-inset) - 4px) 6px 0;
padding: 2px 6px 6px 8px;
border-bottom: 1px solid color-mix(in srgb, var(--dsw-alias-border-l3) 34%, transparent);
}

.titleGroup {
flex: 1;
min-width: 0;
display: inline-flex;
align-items: center;
gap: 5px;
font-size: 12px;
line-height: 17px;
white-space: nowrap;
overflow: hidden;
}

.title {
flex: none;
font-weight: 500;
color: var(--dsw-alias-label-secondary);
}

.unreadMeta {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
font-variant-numeric: tabular-nums;
color: var(--dsw-alias-label-tertiary);
}

.markAllReadButton {
flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
height: 24px;
padding: 0 8px;
border: none;
border-radius: 6px;
background: transparent;
font: inherit;
font-size: 12px;
font-weight: 500;
line-height: 16px;
color: var(--dsw-alias-state-business-primary);
cursor: pointer;
white-space: nowrap;
transition:
background-color 120ms ease,
color 120ms ease,
opacity 120ms ease;
}

.markAllReadButton:hover:not(:disabled) {
background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 10%, transparent);
}

.markAllReadButton:active:not(:disabled) {
background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 16%, transparent);
}

.markAllReadButton:disabled {
color: var(--dsw-alias-label-tertiary);
opacity: 0.45;
cursor: default;
}

.markAllReadButton:focus-visible,
.backButton:focus-visible {
outline: var(--dsw-focus-ring-width, 2px) solid
var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
outline-offset: -2px;
}

.emptyState {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
margin-top: 72px;
padding: 0 16px;
text-align: center;
color: var(--dsw-alias-label-tertiary);
font-size: 13px;
line-height: 20px;
}

.emptyIcon {
margin-bottom: 4px;
color: var(--dsw-alias-label-caption);
opacity: 0.85;
}

.emptyTitle {
color: var(--dsw-alias-label-tertiary);
}

.backButton {
margin-top: 2px;
padding: 4px 10px;
border: none;
border-radius: 6px;
background: transparent;
cursor: pointer;
font: inherit;
font-size: 13px;
font-weight: 500;
line-height: 20px;
color: var(--dsw-alias-link);
transition: background-color 120ms ease;
}

.backButton:hover {
background: var(--dsw-alias-interactive-bg-hover);
}

@media (hover: none), (pointer: coarse) {
.markAllReadButton {
min-height: 32px;
padding: 0 10px;
}

.backButton {
min-height: 36px;
padding: 6px 12px;
}
}

@media (prefers-reduced-motion: reduce) {
.markAllReadButton,
.backButton {
transition: none;
}
}
Loading
Loading