Skip to content

Commit f607ba0

Browse files
authored
feat(control-ui): session grouping with drag & drop and channel categorization (#100262)
* feat(control-ui): session grouping with drag & drop and channel categorization * fix(control-ui): restrict session drag&drop to private session-key payloads * chore(i18n): translate session grouping strings across control ui locales * chore(protocol): regenerate swift gateway models for session category * chore(protocol): regenerate swift gateway models for session category
1 parent 286d0b9 commit f607ba0

81 files changed

Lines changed: 1814 additions & 124 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,7 @@ public struct SessionsPatchParams: Codable, Sendable {
24372437
public let key: String
24382438
public let agentid: String?
24392439
public let label: AnyCodable?
2440+
public let category: AnyCodable?
24402441
public let archived: Bool?
24412442
public let pinned: Bool?
24422443
public let thinkinglevel: AnyCodable?
@@ -2466,6 +2467,7 @@ public struct SessionsPatchParams: Codable, Sendable {
24662467
key: String,
24672468
agentid: String? = nil,
24682469
label: AnyCodable?,
2470+
category: AnyCodable?,
24692471
archived: Bool? = nil,
24702472
pinned: Bool? = nil,
24712473
thinkinglevel: AnyCodable?,
@@ -2494,6 +2496,7 @@ public struct SessionsPatchParams: Codable, Sendable {
24942496
self.key = key
24952497
self.agentid = agentid
24962498
self.label = label
2499+
self.category = category
24972500
self.archived = archived
24982501
self.pinned = pinned
24992502
self.thinkinglevel = thinkinglevel
@@ -2524,6 +2527,7 @@ public struct SessionsPatchParams: Codable, Sendable {
25242527
case key
25252528
case agentid = "agentId"
25262529
case label
2530+
case category
25272531
case archived
25282532
case pinned
25292533
case thinkinglevel = "thinkingLevel"

‎docs/web/control-ui.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Appearance also has a browser-local Text size setting, stored with the rest of C
127127
- Channel probe refreshes keep the previous snapshot visible while slow provider checks finish, and label partial snapshots when a probe or audit exceeds its UI budget.
128128
- Instances: presence list and refresh (`system-presence`).
129129
- Sessions: list configured-agent sessions by default, pin frequent sessions, rename them, archive or restore inactive sessions, fall back from stale unconfigured agent session keys, and apply per-session model/thinking/fast/verbose/trace/reasoning overrides (`sessions.list`, `sessions.patch`). Pinned sessions sort above recent unpinned sessions; archived sessions live in the Sessions page's archived view and keep their transcripts.
130+
- Session grouping: a Group by control organizes the sessions table into sections by custom groups, channel, kind, agent, or date. Custom groups persist per session via `sessions.patch` (`category`), so sessions started from message channels (Discord, Telegram, WhatsApp, ...) can be categorized too; assign groups by dragging rows onto a section, or with the per-row group selector, and create groups with the New group action.
130131
- Dreams: dreaming status, enable/disable toggle, and Dream Diary reader (`doctor.memory.status`, `doctor.memory.dreamDiary`, `config.patch`).
131132

132133
</Accordion>

‎packages/gateway-protocol/src/schema/sessions.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ export const SessionsPatchParamsSchema = Type.Object(
303303
key: NonEmptyString,
304304
agentId: Type.Optional(NonEmptyString),
305305
label: Type.Optional(Type.Union([SessionLabelString, Type.Null()])),
306+
/** User-defined organization bucket ("category", not chat-group); null clears it. */
307+
category: Type.Optional(Type.Union([SessionLabelString, Type.Null()])),
306308
archived: Type.Optional(Type.Boolean()),
307309
pinned: Type.Optional(Type.Boolean()),
308310
thinkingLevel: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),

‎src/config/sessions/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ export type SessionEntry = {
423423
cliSessionBindings?: Record<string, CliSessionBinding>;
424424
claudeCliSessionId?: string;
425425
label?: string;
426+
/** User-defined organization bucket for session lists; unrelated to chat groupId/groupChannel. */
427+
category?: string;
426428
displayName?: string;
427429
channel?: string;
428430
groupId?: string;

‎src/gateway/session-event-payload.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export function buildGatewaySessionEventFields(params: {
3232
subagentRole: sessionRow.subagentRole,
3333
subagentControlScope: sessionRow.subagentControlScope,
3434
label: params.label ?? sessionRow.label ?? null,
35+
// Explicit null so subscribed clients drop a cleared category during merge-reconcile.
36+
category: sessionRow.category ?? null,
3537
displayName: params.displayName ?? sessionRow.displayName ?? null,
3638
deliveryContext: sessionRow.deliveryContext,
3739
parentSessionKey: params.parentSessionKey ?? sessionRow.parentSessionKey,

‎src/gateway/session-utils.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,7 @@ export function buildGatewaySessionRow(params: {
21572157
subagentControlScope: entry?.subagentControlScope,
21582158
kind: classifySessionKey(key, entry),
21592159
label: entry?.label,
2160+
category: entry?.category,
21602161
displayName,
21612162
derivedTitle,
21622163
lastMessagePreview,

‎src/gateway/session-utils.types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export type GatewaySessionRow = {
5050
subagentControlScope?: SessionEntry["subagentControlScope"];
5151
kind: "direct" | "group" | "global" | "unknown";
5252
label?: string;
53+
/** User-defined organization bucket; unrelated to chat-group kind/groupChannel. */
54+
category?: string;
5355
displayName?: string;
5456
derivedTitle?: string;
5557
lastMessagePreview?: string;

‎src/gateway/sessions-patch.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,53 @@ describe("gateway sessions patch", () => {
367367
expect(entry.fastMode).toBe(true);
368368
});
369369

370+
test("persists, trims, and clears category", async () => {
371+
const store = mainStoreEntry({});
372+
const entry = expectPatchOk(
373+
await runPatch({
374+
store,
375+
patch: { key: MAIN_SESSION_KEY, category: " Research " },
376+
}),
377+
);
378+
expect(entry.category).toBe("Research");
379+
380+
const cleared = expectPatchOk(
381+
await runPatch({
382+
store: mainStoreEntry({ category: "Research" }),
383+
patch: { key: MAIN_SESSION_KEY, category: null },
384+
}),
385+
);
386+
expect(cleared.category).toBeUndefined();
387+
});
388+
389+
test("allows duplicate categories across sessions", async () => {
390+
const store: Record<string, SessionEntry> = {
391+
...mainStoreEntry({}),
392+
"agent:main:discord:channel:123": {
393+
sessionId: "other",
394+
updatedAt: 1,
395+
category: "Research",
396+
} as SessionEntry,
397+
};
398+
const entry = expectPatchOk(
399+
await runPatch({
400+
store,
401+
patch: { key: MAIN_SESSION_KEY, category: "Research" },
402+
}),
403+
);
404+
expect(entry.category).toBe("Research");
405+
});
406+
407+
test("rejects empty category", async () => {
408+
expectPatchError(
409+
await runPatch({
410+
store: mainStoreEntry({}),
411+
patch: { key: MAIN_SESSION_KEY, category: " " },
412+
}),
413+
"invalid category: empty",
414+
);
415+
});
416+
370417
test("clears fastMode when patch sets null", async () => {
371418
const store = mainStoreEntry({ fastMode: true });
372419
const entry = expectPatchOk(

‎src/gateway/sessions-patch.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
} from "../sessions/level-overrides.js";
5252
import { applyModelOverrideToSessionEntry } from "../sessions/model-overrides.js";
5353
import { normalizeSendPolicy } from "../sessions/send-policy.js";
54-
import { parseSessionLabel } from "../sessions/session-label.js";
54+
import { parseSessionLabel, SESSION_LABEL_MAX_LENGTH } from "../sessions/session-label.js";
5555

5656
function invalid(message: string): { ok: false; error: ErrorShape } {
5757
return { ok: false, error: errorShape(ErrorCodes.INVALID_REQUEST, message) };
@@ -183,6 +183,7 @@ export async function projectSessionsPatchEntry(params: {
183183
};
184184
if (existing && !existing.sessionId) {
185185
delete next.label;
186+
delete next.category;
186187
delete next.displayName;
187188
}
188189

@@ -369,6 +370,23 @@ export async function projectSessionsPatchEntry(params: {
369370
}
370371
}
371372

373+
if ("category" in patch) {
374+
const raw = patch.category;
375+
if (raw === null) {
376+
delete next.category;
377+
} else if (raw !== undefined) {
378+
// Categories are shared organization buckets, so duplicates are expected (unlike labels).
379+
const trimmed = normalizeOptionalString(raw) ?? "";
380+
if (!trimmed) {
381+
return invalid("invalid category: empty");
382+
}
383+
if (trimmed.length > SESSION_LABEL_MAX_LENGTH) {
384+
return invalid(`invalid category: too long (max ${SESSION_LABEL_MAX_LENGTH})`);
385+
}
386+
next.category = trimmed;
387+
}
388+
}
389+
372390
if ("archived" in patch) {
373391
if (patch.archived === true) {
374392
// Archived sessions leave the active quick-access set in the same write.

‎src/plugins/session-entry-slot-keys.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const SESSION_ENTRY_RESERVED_SLOT_KEY_LIST = [
114114
"cliSessionBindings",
115115
"claudeCliSessionId",
116116
"label",
117+
"category",
117118
"displayName",
118119
"channel",
119120
"groupId",

0 commit comments

Comments
 (0)