UI: introduce active minutes constant for chat sessions and enhance session display names
This commit is contained in:
@@ -24,6 +24,8 @@ type ChatHost = {
|
|||||||
refreshSessionsAfterChat: Set<string>;
|
refreshSessionsAfterChat: Set<string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const CHAT_SESSIONS_ACTIVE_MINUTES = 10;
|
||||||
|
|
||||||
export function isChatBusy(host: ChatHost) {
|
export function isChatBusy(host: ChatHost) {
|
||||||
return host.chatSending || Boolean(host.chatRunId);
|
return host.chatSending || Boolean(host.chatRunId);
|
||||||
}
|
}
|
||||||
@@ -180,7 +182,9 @@ export async function handleSendChat(
|
|||||||
export async function refreshChat(host: ChatHost) {
|
export async function refreshChat(host: ChatHost) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
loadChatHistory(host as unknown as OpenClawApp),
|
loadChatHistory(host as unknown as OpenClawApp),
|
||||||
loadSessions(host as unknown as OpenClawApp, { activeMinutes: 0 }),
|
loadSessions(host as unknown as OpenClawApp, {
|
||||||
|
activeMinutes: CHAT_SESSIONS_ACTIVE_MINUTES,
|
||||||
|
}),
|
||||||
refreshChatAvatar(host),
|
refreshChatAvatar(host),
|
||||||
]);
|
]);
|
||||||
scheduleChatScroll(host as unknown as Parameters<typeof scheduleChatScroll>[0], true);
|
scheduleChatScroll(host as unknown as Parameters<typeof scheduleChatScroll>[0], true);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import type { AgentsListResult, PresenceEntry, HealthSnapshot, StatusSummary } f
|
|||||||
import type { Tab } from "./navigation";
|
import type { Tab } from "./navigation";
|
||||||
import type { UiSettings } from "./storage";
|
import type { UiSettings } from "./storage";
|
||||||
import { handleAgentEvent, resetToolStream, type AgentEventPayload } from "./app-tool-stream";
|
import { handleAgentEvent, resetToolStream, type AgentEventPayload } from "./app-tool-stream";
|
||||||
import { flushChatQueueForEvent } from "./app-chat";
|
import { CHAT_SESSIONS_ACTIVE_MINUTES, flushChatQueueForEvent } from "./app-chat";
|
||||||
import {
|
import {
|
||||||
applySettings,
|
applySettings,
|
||||||
loadCron,
|
loadCron,
|
||||||
@@ -200,7 +200,9 @@ function handleGatewayEventUnsafe(host: GatewayHost, evt: GatewayEventFrame) {
|
|||||||
if (runId && host.refreshSessionsAfterChat.has(runId)) {
|
if (runId && host.refreshSessionsAfterChat.has(runId)) {
|
||||||
host.refreshSessionsAfterChat.delete(runId);
|
host.refreshSessionsAfterChat.delete(runId);
|
||||||
if (state === "final") {
|
if (state === "final") {
|
||||||
void loadSessions(host as unknown as OpenClawApp, { activeMinutes: 0 });
|
void loadSessions(host as unknown as OpenClawApp, {
|
||||||
|
activeMinutes: CHAT_SESSIONS_ACTIVE_MINUTES,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,6 +156,17 @@ function resolveMainSessionKey(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveSessionDisplayName(
|
||||||
|
key: string,
|
||||||
|
row?: SessionsListResult["sessions"][number],
|
||||||
|
) {
|
||||||
|
const label = row?.label?.trim();
|
||||||
|
if (label) return `${label} (${key})`;
|
||||||
|
const displayName = row?.displayName?.trim();
|
||||||
|
if (displayName) return displayName;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
function resolveSessionOptions(
|
function resolveSessionOptions(
|
||||||
sessionKey: string,
|
sessionKey: string,
|
||||||
sessions: SessionsListResult | null,
|
sessions: SessionsListResult | null,
|
||||||
@@ -171,13 +182,19 @@ function resolveSessionOptions(
|
|||||||
// Add main session key first
|
// Add main session key first
|
||||||
if (mainSessionKey) {
|
if (mainSessionKey) {
|
||||||
seen.add(mainSessionKey);
|
seen.add(mainSessionKey);
|
||||||
options.push({ key: mainSessionKey, displayName: resolvedMain?.displayName });
|
options.push({
|
||||||
|
key: mainSessionKey,
|
||||||
|
displayName: resolveSessionDisplayName(mainSessionKey, resolvedMain),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add current session key next
|
// Add current session key next
|
||||||
if (!seen.has(sessionKey)) {
|
if (!seen.has(sessionKey)) {
|
||||||
seen.add(sessionKey);
|
seen.add(sessionKey);
|
||||||
options.push({ key: sessionKey, displayName: resolvedCurrent?.displayName });
|
options.push({
|
||||||
|
key: sessionKey,
|
||||||
|
displayName: resolveSessionDisplayName(sessionKey, resolvedCurrent),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add sessions from the result
|
// Add sessions from the result
|
||||||
@@ -185,7 +202,10 @@ function resolveSessionOptions(
|
|||||||
for (const s of sessions.sessions) {
|
for (const s of sessions.sessions) {
|
||||||
if (!seen.has(s.key)) {
|
if (!seen.has(s.key)) {
|
||||||
seen.add(s.key);
|
seen.add(s.key);
|
||||||
options.push({ key: s.key, displayName: s.displayName });
|
options.push({
|
||||||
|
key: s.key,
|
||||||
|
displayName: resolveSessionDisplayName(s.key, s),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user