Normalize active session ids in frontend
This commit is contained in:
@@ -519,8 +519,9 @@ function useComposerContextStatus() {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof latestSessionId === "string" && latestSessionId) {
|
||||
window.localStorage.setItem("claw.activeSessionId", latestSessionId);
|
||||
const cleanLatestSessionId = normalizeSessionId(latestSessionId);
|
||||
if (cleanLatestSessionId) {
|
||||
window.localStorage.setItem("claw.activeSessionId", cleanLatestSessionId);
|
||||
window.setTimeout(() => {
|
||||
window.dispatchEvent(new Event("claw-sessions-changed"));
|
||||
}, 0);
|
||||
@@ -548,11 +549,15 @@ function useComposerContextStatus() {
|
||||
const statePayload = stateResponse.ok
|
||||
? ((await stateResponse.json()) as ClawState)
|
||||
: {};
|
||||
const sessionId =
|
||||
(typeof latestSessionId === "string" && latestSessionId) ||
|
||||
window.localStorage.getItem("claw.activeSessionId") ||
|
||||
statePayload.active_session_id ||
|
||||
null;
|
||||
const sessionId = normalizeSessionId(
|
||||
normalizeSessionId(latestSessionId) ||
|
||||
normalizeSessionId(
|
||||
window.localStorage.getItem("claw.activeSessionId"),
|
||||
) ||
|
||||
normalizeSessionId(statePayload.active_session_id),
|
||||
);
|
||||
if (sessionId)
|
||||
window.localStorage.setItem("claw.activeSessionId", sessionId);
|
||||
let sessionPayload: ClawStoredSession | null = null;
|
||||
let contextBudget: ContextBudget | undefined;
|
||||
if (sessionId) {
|
||||
@@ -680,6 +685,12 @@ function readMetadataValue(metadata: unknown, key: string): unknown {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function normalizeSessionId(value: unknown) {
|
||||
if (typeof value !== "string") return null;
|
||||
const trimmed = value.trim();
|
||||
return trimmed || null;
|
||||
}
|
||||
|
||||
function formatCompactTokenCount(value: number) {
|
||||
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`;
|
||||
if (value >= 1_000) return `${(value / 1_000).toFixed(1)}K`;
|
||||
|
||||
Reference in New Issue
Block a user