refactor: normalize group session keys
This commit is contained in:
@@ -470,7 +470,7 @@ export async function agentCommand(
|
||||
}
|
||||
if (deliveryProvider === "signal" && !signalTarget) {
|
||||
const err = new Error(
|
||||
"Delivering to Signal requires --to <E.164|group:ID|signal:+E.164>",
|
||||
"Delivering to Signal requires --to <E.164|group:ID|signal:group:ID|signal:+E.164>",
|
||||
);
|
||||
if (!bestEffortDeliver) throw err;
|
||||
logDeliveryError(err);
|
||||
|
||||
@@ -77,7 +77,7 @@ describe("sessionsCommand", () => {
|
||||
|
||||
it("shows placeholder rows when tokens are missing", async () => {
|
||||
const store = writeStore({
|
||||
"group:demo": {
|
||||
"discord:group:demo": {
|
||||
sessionId: "xyz",
|
||||
updatedAt: Date.now() - 5 * 60_000,
|
||||
thinkingLevel: "high",
|
||||
@@ -89,7 +89,7 @@ describe("sessionsCommand", () => {
|
||||
|
||||
fs.rmSync(store);
|
||||
|
||||
const row = logs.find((line) => line.includes("group:demo")) ?? "";
|
||||
const row = logs.find((line) => line.includes("discord:group:demo")) ?? "";
|
||||
expect(row).toContain("-".padEnd(20));
|
||||
expect(row).toContain("think:high");
|
||||
expect(row).toContain("5m ago");
|
||||
|
||||
@@ -119,10 +119,17 @@ const formatAge = (ms: number | null | undefined) => {
|
||||
return `${days}d ago`;
|
||||
};
|
||||
|
||||
function classifyKey(key: string): SessionRow["kind"] {
|
||||
function classifyKey(key: string, entry?: SessionEntry): SessionRow["kind"] {
|
||||
if (key === "global") return "global";
|
||||
if (key.startsWith("group:")) return "group";
|
||||
if (key === "unknown") return "unknown";
|
||||
if (entry?.chatType === "group" || entry?.chatType === "room") return "group";
|
||||
if (
|
||||
key.startsWith("group:") ||
|
||||
key.includes(":group:") ||
|
||||
key.includes(":channel:")
|
||||
) {
|
||||
return "group";
|
||||
}
|
||||
return "direct";
|
||||
}
|
||||
|
||||
@@ -132,7 +139,7 @@ function toRows(store: Record<string, SessionEntry>): SessionRow[] {
|
||||
const updatedAt = entry?.updatedAt ?? null;
|
||||
return {
|
||||
key,
|
||||
kind: classifyKey(key),
|
||||
kind: classifyKey(key, entry),
|
||||
updatedAt,
|
||||
ageMs: updatedAt ? Date.now() - updatedAt : null,
|
||||
sessionId: entry?.sessionId,
|
||||
|
||||
@@ -102,7 +102,7 @@ export async function getStatusSummary(): Promise<StatusSummary> {
|
||||
|
||||
return {
|
||||
key,
|
||||
kind: classifyKey(key),
|
||||
kind: classifyKey(key, entry),
|
||||
sessionId: entry?.sessionId,
|
||||
updatedAt,
|
||||
age,
|
||||
@@ -169,10 +169,17 @@ const formatContextUsage = (
|
||||
return `tokens: ${formatKTokens(used)} used, ${formatKTokens(left)} left of ${formatKTokens(contextTokens)} (${pctLabel})`;
|
||||
};
|
||||
|
||||
const classifyKey = (key: string): SessionStatus["kind"] => {
|
||||
const classifyKey = (key: string, entry?: SessionEntry): SessionStatus["kind"] => {
|
||||
if (key === "global") return "global";
|
||||
if (key.startsWith("group:")) return "group";
|
||||
if (key === "unknown") return "unknown";
|
||||
if (entry?.chatType === "group" || entry?.chatType === "room") return "group";
|
||||
if (
|
||||
key.startsWith("group:") ||
|
||||
key.includes(":group:") ||
|
||||
key.includes(":channel:")
|
||||
) {
|
||||
return "group";
|
||||
}
|
||||
return "direct";
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user