Fix active session replay state
This commit is contained in:
@@ -19,6 +19,10 @@ import {
|
||||
SidebarProvider,
|
||||
SidebarTrigger,
|
||||
} from "@/components/ui/sidebar";
|
||||
import {
|
||||
readActiveSessionId,
|
||||
writeActiveSessionId,
|
||||
} from "@/lib/claw-active-session";
|
||||
import { ClawSessionReplayProvider } from "@/lib/claw-session-replay";
|
||||
import { ClawAccountGate, useClawAccount } from "./claw-account-gate";
|
||||
|
||||
@@ -31,21 +35,13 @@ export const Assistant = () => {
|
||||
prepareSendMessagesRequest: async (options) => {
|
||||
const body = options.body as Record<string, unknown>;
|
||||
const messages = options.messages as UIMessage[];
|
||||
const selectedSessionId =
|
||||
typeof window !== "undefined"
|
||||
? window.localStorage.getItem("claw.activeSessionId")
|
||||
: null;
|
||||
const selectedSessionId = readActiveSessionId();
|
||||
const lastSessionId = getLastSessionId(messages);
|
||||
const selectedResumeSessionId =
|
||||
messages.length > 1 ? selectedSessionId : null;
|
||||
const outgoingSessionId =
|
||||
lastSessionId ?? selectedResumeSessionId ?? options.id;
|
||||
if (typeof window !== "undefined" && outgoingSessionId) {
|
||||
window.localStorage.setItem(
|
||||
"claw.activeSessionId",
|
||||
outgoingSessionId,
|
||||
);
|
||||
}
|
||||
writeActiveSessionId(outgoingSessionId);
|
||||
|
||||
return {
|
||||
body: {
|
||||
@@ -65,7 +61,7 @@ export const Assistant = () => {
|
||||
});
|
||||
const replaySession = useCallback(
|
||||
(sessionId: string, repository: ExportedMessageRepository) => {
|
||||
window.localStorage.setItem("claw.activeSessionId", sessionId);
|
||||
writeActiveSessionId(sessionId);
|
||||
runtime.thread.import(repository);
|
||||
},
|
||||
[runtime],
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ReactNode } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { clearActiveSessionId } from "@/lib/claw-active-session";
|
||||
|
||||
export type ClawAccount = {
|
||||
id: string;
|
||||
@@ -131,7 +132,7 @@ export function ClawAccountBar({
|
||||
}) {
|
||||
async function logout() {
|
||||
await fetch("/api/claw/auth/logout", { method: "POST" });
|
||||
window.localStorage.removeItem("claw.activeSessionId");
|
||||
clearActiveSessionId();
|
||||
onLogout();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user