Normalize active session ids in frontend
This commit is contained in:
@@ -357,15 +357,20 @@ function useSidebarSessions(open: boolean) {
|
||||
repository: ExportedMessageRepository,
|
||||
) => void,
|
||||
) {
|
||||
window.localStorage.setItem("claw.activeSessionId", sessionId);
|
||||
const cleanSessionId = normalizeSessionId(sessionId);
|
||||
if (!cleanSessionId) return;
|
||||
window.localStorage.setItem("claw.activeSessionId", cleanSessionId);
|
||||
setLoadingSessionId(sessionId);
|
||||
try {
|
||||
const response = await fetch(`/api/claw/sessions/${sessionId}`, {
|
||||
const response = await fetch(`/api/claw/sessions/${cleanSessionId}`, {
|
||||
cache: "no-store",
|
||||
});
|
||||
if (!response.ok) return;
|
||||
const payload = (await response.json()) as ReplaySessionPayload;
|
||||
replaySession(sessionId, toReplayRepository(payload, sessionId));
|
||||
replaySession(
|
||||
cleanSessionId,
|
||||
toReplayRepository(payload, cleanSessionId),
|
||||
);
|
||||
} finally {
|
||||
setLoadingSessionId(null);
|
||||
}
|
||||
@@ -430,13 +435,15 @@ function AccountMenu({
|
||||
: [];
|
||||
setState(nextState);
|
||||
setSessions(nextSessions);
|
||||
const activeSessionId =
|
||||
const activeSessionId = normalizeSessionId(
|
||||
window.localStorage.getItem("claw.activeSessionId") ??
|
||||
nextState?.active_session_id;
|
||||
nextState?.active_session_id,
|
||||
);
|
||||
if (!activeSessionId) {
|
||||
setActiveSession(null);
|
||||
return;
|
||||
}
|
||||
window.localStorage.setItem("claw.activeSessionId", activeSessionId);
|
||||
const response = await fetch(`/api/claw/sessions/${activeSessionId}`, {
|
||||
cache: "no-store",
|
||||
});
|
||||
@@ -610,6 +617,12 @@ function AccountMenu({
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeSessionId(value: unknown) {
|
||||
if (typeof value !== "string") return null;
|
||||
const trimmed = value.trim();
|
||||
return trimmed || null;
|
||||
}
|
||||
|
||||
function aggregateUsageByModel(sessions: ClawSessionSummary[]) {
|
||||
const byModel = new Map<
|
||||
string,
|
||||
|
||||
Reference in New Issue
Block a user