Files
openclaw/src/sessions/classify-session-kind.ts
Eduardo Piva 9431d18aaf fix(sessions): classify spawn-child sessions correctly
Classify ACP spawn-child sessions via persisted spawnedBy metadata and share the session kind classifier across sessions/status output.

Verified with Azure Crabbox seeded ACP session-store proof, targeted session/status tests, touched-file lint, build, and green PR CI.
2026-05-13 16:39:04 -07:00

40 lines
1.1 KiB
TypeScript

import { isCronSessionKey } from "./session-key-utils.js";
export type SessionKind = "cron" | "direct" | "group" | "global" | "spawn-child" | "unknown";
/**
* Classify a session key + entry into a display kind.
*
* Evaluation order matters — more-specific signals take priority:
* 1. sentinel keys ("global", "unknown")
* 2. cron key shape
* 3. spawn-child (entry has `spawnedBy`) — checked before key-shape so ACP
* spawn-child sessions with opaque keys are not misclassified as "direct"
* 4. group/channel chatType or key-shape substring
* 5. fallback: "direct"
*/
export function classifySessionKind(
key: string,
entry?: { chatType?: string | null; spawnedBy?: string | null },
): SessionKind {
if (key === "global") {
return "global";
}
if (key === "unknown") {
return "unknown";
}
if (isCronSessionKey(key)) {
return "cron";
}
if (entry?.spawnedBy) {
return "spawn-child";
}
if (entry?.chatType === "group" || entry?.chatType === "channel") {
return "group";
}
if (key.includes(":group:") || key.includes(":channel:")) {
return "group";
}
return "direct";
}