mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:58:26 +00:00
refactor(sessions): reuse session key classifier
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
resolveStorePath,
|
resolveStorePath,
|
||||||
type SessionEntry,
|
type SessionEntry,
|
||||||
} from "../config/sessions.js";
|
} from "../config/sessions.js";
|
||||||
|
import { classifySessionKey } from "../gateway/session-utils.js";
|
||||||
import { info } from "../globals.js";
|
import { info } from "../globals.js";
|
||||||
import { formatTimeAgo } from "../infra/format-time/format-relative.ts";
|
import { formatTimeAgo } from "../infra/format-time/format-relative.ts";
|
||||||
import { isRich, theme } from "../terminal/theme.js";
|
import { isRich, theme } from "../terminal/theme.js";
|
||||||
@@ -129,29 +130,13 @@ const formatFlagsCell = (row: SessionRow, rich: boolean) => {
|
|||||||
return label.length === 0 ? "" : rich ? theme.muted(label) : label;
|
return label.length === 0 ? "" : rich ? theme.muted(label) : label;
|
||||||
};
|
};
|
||||||
|
|
||||||
function classifyKey(key: string, entry?: SessionEntry): SessionRow["kind"] {
|
|
||||||
if (key === "global") {
|
|
||||||
return "global";
|
|
||||||
}
|
|
||||||
if (key === "unknown") {
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
if (entry?.chatType === "group" || entry?.chatType === "channel") {
|
|
||||||
return "group";
|
|
||||||
}
|
|
||||||
if (key.includes(":group:") || key.includes(":channel:")) {
|
|
||||||
return "group";
|
|
||||||
}
|
|
||||||
return "direct";
|
|
||||||
}
|
|
||||||
|
|
||||||
function toRows(store: Record<string, SessionEntry>): SessionRow[] {
|
function toRows(store: Record<string, SessionEntry>): SessionRow[] {
|
||||||
return Object.entries(store)
|
return Object.entries(store)
|
||||||
.map(([key, entry]) => {
|
.map(([key, entry]) => {
|
||||||
const updatedAt = entry?.updatedAt ?? null;
|
const updatedAt = entry?.updatedAt ?? null;
|
||||||
return {
|
return {
|
||||||
key,
|
key,
|
||||||
kind: classifyKey(key, entry),
|
kind: classifySessionKey(key, entry),
|
||||||
updatedAt,
|
updatedAt,
|
||||||
ageMs: updatedAt ? Date.now() - updatedAt : null,
|
ageMs: updatedAt ? Date.now() - updatedAt : null,
|
||||||
sessionId: entry?.sessionId,
|
sessionId: entry?.sessionId,
|
||||||
|
|||||||
Reference in New Issue
Block a user