Sync session URL when opening chats
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
|||||||
readPendingWorkspaceSessionId,
|
readPendingWorkspaceSessionId,
|
||||||
writeActiveSessionId,
|
writeActiveSessionId,
|
||||||
} from "@/lib/claw-active-session";
|
} from "@/lib/claw-active-session";
|
||||||
|
import { pushSessionUrl } from "@/lib/claw-session-url";
|
||||||
import { ClawSessionReplayProvider } from "@/lib/claw-session-replay";
|
import { ClawSessionReplayProvider } from "@/lib/claw-session-replay";
|
||||||
import { ClawAccountGate, useClawAccount } from "./claw-account-gate";
|
import { ClawAccountGate, useClawAccount } from "./claw-account-gate";
|
||||||
|
|
||||||
@@ -112,6 +113,7 @@ export const Assistant = ({ initialSessionId }: AssistantProps = {}) => {
|
|||||||
targetSessionId,
|
targetSessionId,
|
||||||
toReplayRepository(payload, targetSessionId, runStatus),
|
toReplayRepository(payload, targetSessionId, runStatus),
|
||||||
);
|
);
|
||||||
|
pushSessionUrl(targetSessionId);
|
||||||
} catch {
|
} catch {
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
loadedInitialSessionRef.current = null;
|
loadedInitialSessionRef.current = null;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
readActiveSessionId,
|
readActiveSessionId,
|
||||||
writeActiveSessionId,
|
writeActiveSessionId,
|
||||||
} from "@/lib/claw-active-session";
|
} from "@/lib/claw-active-session";
|
||||||
|
import { pushHomeUrl, pushSessionUrl } from "@/lib/claw-session-url";
|
||||||
import { useClawSessionReplay } from "@/lib/claw-session-replay";
|
import { useClawSessionReplay } from "@/lib/claw-session-replay";
|
||||||
|
|
||||||
type ClawSession = {
|
type ClawSession = {
|
||||||
@@ -121,6 +122,7 @@ const ThreadListNew: FC = () => {
|
|||||||
<div
|
<div
|
||||||
onClickCapture={() => {
|
onClickCapture={() => {
|
||||||
clearActiveSessionId();
|
clearActiveSessionId();
|
||||||
|
pushHomeUrl();
|
||||||
window.dispatchEvent(new Event("claw-active-session-cleared"));
|
window.dispatchEvent(new Event("claw-active-session-cleared"));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -262,6 +264,7 @@ const ClawSessionList: FC = () => {
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setOpenMenuSessionId(null);
|
setOpenMenuSessionId(null);
|
||||||
writeActiveSessionId(session.session_id);
|
writeActiveSessionId(session.session_id);
|
||||||
|
pushSessionUrl(session.session_id);
|
||||||
setActiveSessionId(session.session_id);
|
setActiveSessionId(session.session_id);
|
||||||
setLoadingSessionId(session.session_id);
|
setLoadingSessionId(session.session_id);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import {
|
|||||||
writeActiveSessionId,
|
writeActiveSessionId,
|
||||||
} from "@/lib/claw-active-session";
|
} from "@/lib/claw-active-session";
|
||||||
import { useClawSessionReplay } from "@/lib/claw-session-replay";
|
import { useClawSessionReplay } from "@/lib/claw-session-replay";
|
||||||
|
import { pushHomeUrl, pushSessionUrl } from "@/lib/claw-session-url";
|
||||||
|
|
||||||
type ThreadListSidebarProps = React.ComponentProps<typeof Sidebar> & {
|
type ThreadListSidebarProps = React.ComponentProps<typeof Sidebar> & {
|
||||||
account: ClawAccount;
|
account: ClawAccount;
|
||||||
@@ -201,6 +202,7 @@ function CollapsedSidebarRail({
|
|||||||
<div
|
<div
|
||||||
onClickCapture={() => {
|
onClickCapture={() => {
|
||||||
clearActiveSessionId();
|
clearActiveSessionId();
|
||||||
|
pushHomeUrl();
|
||||||
window.dispatchEvent(new Event("claw-active-session-cleared"));
|
window.dispatchEvent(new Event("claw-active-session-cleared"));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -404,6 +406,7 @@ function useSidebarSessions(open: boolean) {
|
|||||||
const cleanSessionId = normalizeSessionId(sessionId);
|
const cleanSessionId = normalizeSessionId(sessionId);
|
||||||
if (!cleanSessionId) return;
|
if (!cleanSessionId) return;
|
||||||
writeActiveSessionId(cleanSessionId);
|
writeActiveSessionId(cleanSessionId);
|
||||||
|
pushSessionUrl(cleanSessionId);
|
||||||
setLoadingSessionId(sessionId);
|
setLoadingSessionId(sessionId);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/claw/sessions/${cleanSessionId}`, {
|
const response = await fetch(`/api/claw/sessions/${cleanSessionId}`, {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
export function pushSessionUrl(sessionId: string) {
|
||||||
|
if (typeof window === "undefined") return;
|
||||||
|
const target = `/session/${encodeURIComponent(sessionId)}`;
|
||||||
|
if (window.location.pathname === target) return;
|
||||||
|
window.history.pushState(null, "", target);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function pushHomeUrl() {
|
||||||
|
if (typeof window === "undefined") return;
|
||||||
|
if (window.location.pathname === "/") return;
|
||||||
|
window.history.pushState(null, "", "/");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user