Compare commits

..
Author SHA1 Message Date
Cursor Agent 141f6d2ed9 Fix 5 bugs: dropped events, lastVisitedAt, bootstrap thread, duplicate config, delete race
- Remove early return guard in EventRouter that silently dropped all provider
  events when no thread was active (e.g., user on index route). Use a ref for
  activeThreadId to avoid re-subscribing the event listener on navigation.

- Add VISIT_THREAD action to update lastVisitedAt when navigating to a thread,
  restoring the ability to dismiss the 'Completed' pill in the sidebar.

- Restore ADD_THREAD dispatch in AutoProjectBootstrap so first-time browser
  users get an initial thread instead of a blank placeholder.

- Delete duplicate vite.config.js that duplicated the existing vite.config.ts.

- Await navigation before dispatching DELETE_THREAD in sidebar to prevent the
  route guard redirect from racing and overriding the fallback thread navigation.
2026-02-18 18:28:25 +00:00
Julius Marminge de9c059a64 Derive active thread from route and drop persisted selection
- remove `activeThreadId` from web store state and persistence schema
- drive thread-scoped event handling and toast visibility from router params
- simplify chat index/route flow and add explicit `apps/web/vite.config.js`
2026-02-18 10:11:51 -08:00
Julius Marminge 4444c8845f move 2026-02-18 09:39:38 -08:00
17 changed files with 140 additions and 264 deletions

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { RouterProvider } from "@tanstack/react-router";
import { AnchoredToastProvider, ToastProvider } from "./components/ui/toast";
import { router } from "./router";
import { StoreProvider } from "./store";
const queryClient = new QueryClient();
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<StoreProvider>
<ToastProvider>
<AnchoredToastProvider>
<RouterProvider router={router} />
</AnchoredToastProvider>
</ToastProvider>
</StoreProvider>
</QueryClientProvider>
);
}
+5 -5
View File
@@ -300,7 +300,9 @@ const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
<Command
mode="none"
onItemHighlighted={(highlightedValue) => {
props.onHighlightedItemChange(typeof highlightedValue === "string" ? highlightedValue : null);
props.onHighlightedItemChange(
typeof highlightedValue === "string" ? highlightedValue : null,
);
}}
>
<div className="relative overflow-hidden rounded-xl border border-border/80 bg-popover/96 shadow-lg/8 backdrop-blur-xs">
@@ -550,7 +552,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
);
const keybindings = keybindingsQuery.data ?? EMPTY_KEYBINDINGS;
const threadTerminalRuntimeEnv = useMemo(() => {
if (!activeProject) return {};
if (!activeProject?.cwd) return {};
return projectScriptRuntimeEnv({
project: {
cwd: activeProject.cwd,
@@ -686,9 +688,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
}
const targetCwd = options?.cwd ?? gitCwd ?? activeProject.cwd;
const baseTerminalId =
activeThread.activeTerminalId ||
activeThread.terminalIds[0] ||
DEFAULT_THREAD_TERMINAL_ID;
activeThread.activeTerminalId || activeThread.terminalIds[0] || DEFAULT_THREAD_TERMINAL_ID;
const isBaseTerminalBusy = activeThread.runningTerminalIds.includes(baseTerminalId);
const wantsNewTerminal = Boolean(options?.preferNewTerminal) || isBaseTerminalBusy;
const shouldCreateNewTerminal =
@@ -67,13 +67,13 @@ export function buildGitActionProgressStages(input: {
return [...commitStages, pushStage, "Creating PR..."];
}
const withDescription = (title: string, description: string | undefined) =>
description ? { title, description } : { title };
export function summarizeGitResult(result: GitRunStackedActionResult): {
title: string;
description?: string;
} {
const withDescription = (title: string, description: string | undefined) =>
description ? { title, description } : { title };
if (result.pr.status === "created" || result.pr.status === "opened_existing") {
const prNumber = result.pr.number ? ` #${result.pr.number}` : "";
const title = `${result.pr.status === "created" ? "Created PR" : "Opened PR"}${prNumber}`;
+3 -3
View File
@@ -310,18 +310,18 @@ export default function Sidebar() {
const shouldNavigateToFallback = routeThreadId === threadId;
const fallbackThreadId = state.threads.find((entry) => entry.id !== threadId)?.id ?? null;
dispatch({ type: "DELETE_THREAD", threadId });
if (shouldNavigateToFallback) {
if (fallbackThreadId) {
void navigate({
await navigate({
to: "/$threadId",
params: { threadId: fallbackThreadId },
replace: true,
});
} else {
void navigate({ to: "/", replace: true });
await navigate({ to: "/", replace: true });
}
}
dispatch({ type: "DELETE_THREAD", threadId });
if (!shouldDeleteWorktree || !orphanedWorktreePath || !threadProject) {
return;
+18 -5
View File
@@ -2,6 +2,7 @@
import { Toast } from "@base-ui/react/toast";
import { useEffect } from "react";
import { useRouterState } from "@tanstack/react-router";
import {
CircleAlertIcon,
CircleCheckIcon,
@@ -12,7 +13,6 @@ import {
import { cn } from "~/lib/utils";
import { buttonVariants } from "~/components/ui/button";
import { useStore } from "~/store";
import { shouldHideCollapsedToastContent } from "./toast.logic";
type ThreadToastData = {
@@ -55,6 +55,21 @@ function shouldRenderForActiveThread(
return toastThreadId === activeThreadId;
}
function useActiveThreadIdFromRoute(): string | null {
return useRouterState({
select: (routerState) => {
for (let index = routerState.matches.length - 1; index >= 0; index -= 1) {
const params = routerState.matches[index]?.params as Record<string, unknown> | undefined;
const threadId = params?.threadId;
if (typeof threadId === "string" && threadId.length > 0) {
return threadId;
}
}
return null;
},
});
}
function ThreadToastVisibleAutoDismiss({
toastId,
dismissAfterVisibleMs,
@@ -143,9 +158,8 @@ function ToastProvider({ children, position = "top-right", ...props }: ToastProv
}
function Toasts({ position = "top-right" }: { position: ToastPosition }) {
const { state } = useStore();
const { toasts } = Toast.useToastManager<ThreadToastData>();
const activeThreadId = state.activeThreadId;
const activeThreadId = useActiveThreadIdFromRoute();
const isTop = position.startsWith("top");
const visibleToasts = toasts.filter((toast) =>
shouldRenderForActiveThread(toast.data, activeThreadId),
@@ -292,9 +306,8 @@ function AnchoredToastProvider({ children, ...props }: Toast.Provider.Props) {
}
function AnchoredToasts() {
const { state } = useStore();
const { toasts } = Toast.useToastManager<ThreadToastData>();
const activeThreadId = state.activeThreadId;
const activeThreadId = useActiveThreadIdFromRoute();
return (
<Toast.Portal data-slot="toast-portal-anchored">
+1
View File
@@ -28,6 +28,7 @@ function applyTheme(theme: Theme, suppressTransitions = false) {
document.documentElement.classList.toggle("dark", isDark);
if (suppressTransitions) {
// Force a reflow so the no-transitions class takes effect before removal
// oxlint-disable-next-line no-unused-expressions
document.documentElement.offsetHeight;
requestAnimationFrame(() => {
document.documentElement.classList.remove("no-transitions");
+32 -3
View File
@@ -1,13 +1,42 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { RouterProvider } from "@tanstack/react-router";
import { createHashHistory, createRouter, createBrowserHistory } from "@tanstack/react-router";
import { StoreProvider } from "./store";
import "@xterm/xterm/css/xterm.css";
import "highlight.js/styles/github-dark.css";
import App from "./App";
import "./index.css";
import { isElectron } from "./env";
import { routeTree } from "./routeTree.gen";
const history = isElectron ? createHashHistory() : createBrowserHistory();
const queryClient = new QueryClient();
const router = createRouter({
routeTree,
history,
context: {
queryClient,
},
Wrap: ({ children }) => (
<QueryClientProvider client={queryClient}>
<StoreProvider>{children}</StoreProvider>
</QueryClientProvider>
),
});
declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
}
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<App />
<RouterProvider router={router} />
</React.StrictMode>,
);
-2
View File
@@ -106,7 +106,6 @@ describe("hydratePersistedState", () => {
{ id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] },
]);
expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`);
expect(hydrated?.activeThreadId).toBe("t-1");
expect(hydrated?.runtimeMode).toBe("full-access");
});
@@ -323,7 +322,6 @@ describe("toPersistedState", () => {
},
],
threads: [thread],
activeThreadId: "t-1",
runtimeMode: "full-access",
});
+1 -9
View File
@@ -72,7 +72,7 @@ const persistedThreadSchema = z.object({
const persistedStateBodySchema = z.object({
projects: z.array(persistedProjectSchema),
threads: z.array(persistedThreadSchema),
activeThreadId: z.string().min(1).nullable(),
activeThreadId: z.string().min(1).nullable().optional(),
});
const runtimeModeSchema = z.enum(["approval-required", "full-access"]);
@@ -123,7 +123,6 @@ const persistedStateSchema = z.union([
export interface PersistedStoreSnapshot {
projects: Project[];
threads: Thread[];
activeThreadId: string | null;
runtimeMode: RuntimeMode;
}
@@ -299,15 +298,9 @@ export function hydratePersistedState(
const threads = parsedState.data.threads
.map((thread) => hydrateThread(thread, isLegacyPayload))
.filter((thread) => projectIds.has(thread.projectId));
const hasActiveThread = Boolean(
parsedState.data.activeThreadId &&
threads.some((thread) => thread.id === parsedState.data.activeThreadId),
);
return {
projects,
threads,
activeThreadId: hasActiveThread ? parsedState.data.activeThreadId : (threads[0]?.id ?? null),
runtimeMode:
"runtimeMode" in parsedState.data ? parsedState.data.runtimeMode : DEFAULT_RUNTIME_MODE,
};
@@ -354,7 +347,6 @@ export function toPersistedState(
branch: thread.branch,
worktreePath: thread.worktreePath,
})),
activeThreadId: state.activeThreadId,
runtimeMode: state.runtimeMode,
};
}
-18
View File
@@ -1,18 +0,0 @@
import { createHashHistory, createRouter } from "@tanstack/react-router";
import { isElectron } from "./env";
import { routeTree } from "./routeTree.gen";
const useHashHistory =
isElectron && typeof window !== "undefined" && window.location.protocol === "file:";
export const router = createRouter({
routeTree,
...(useHashHistory ? { history: createHashHistory() } : {}),
});
declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
}
+43 -39
View File
@@ -1,20 +1,58 @@
import { Outlet, createRootRoute } from "@tanstack/react-router";
import { Outlet, createRootRouteWithContext, useParams } from "@tanstack/react-router";
import { useEffect, useRef } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { QueryClient, useQueryClient } from "@tanstack/react-query";
import { AnchoredToastProvider, ToastProvider } from "../components/ui/toast";
import { isElectron } from "../env";
import { useNativeApi } from "../hooks/useNativeApi";
import { invalidateGitQueries } from "../lib/gitReactQuery";
import { DEFAULT_MODEL } from "../model-logic";
import { createThread } from "../threadFactory";
import { useStore } from "../store";
import { createThread } from "../threadFactory";
import { onServerWelcome } from "../wsNativeApi";
export const Route = createRootRouteWithContext<{
queryClient: QueryClient;
}>()({
component: RootRouteView,
});
function RootRouteView() {
const api = useNativeApi();
if (!api) {
return (
<div className="flex h-screen flex-col bg-background text-foreground">
<div className="flex flex-1 items-center justify-center">
<p className="text-sm text-muted-foreground">Connecting to T3 Code server...</p>
</div>
</div>
);
}
return (
<ToastProvider>
<AnchoredToastProvider>
<EventRouter />
<AutoProjectBootstrap />
<DesktopProjectBootstrap />
<Outlet />
</AnchoredToastProvider>
</ToastProvider>
);
}
function EventRouter() {
const api = useNativeApi();
const { dispatch } = useStore();
const queryClient = useQueryClient();
const activeAssistantItemRef = useRef<string | null>(null);
const activeThreadId = useParams({
strict: false,
select: (params) => params.threadId,
});
const activeThreadIdRef = useRef(activeThreadId);
activeThreadIdRef.current = activeThreadId;
useEffect(() => {
if (!api) return;
@@ -26,6 +64,7 @@ function EventRouter() {
type: "APPLY_EVENT",
event,
activeAssistantItemRef,
activeThreadId: activeThreadIdRef.current,
});
});
}, [api, dispatch, queryClient]);
@@ -59,14 +98,6 @@ function AutoProjectBootstrap() {
const existing = state.projects.find((project) => project.cwd === payload.cwd);
if (existing) {
bootstrappedRef.current = true;
// Ensure a thread is active
const existingThread = state.threads.find((thread) => thread.projectId === existing.id);
if (existingThread && !state.activeThreadId) {
dispatch({
type: "SET_ACTIVE_THREAD",
threadId: existingThread.id,
});
}
dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true });
return;
}
@@ -92,7 +123,7 @@ function AutoProjectBootstrap() {
});
dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true });
});
}, [state.projects, state.threads, state.activeThreadId, dispatch]);
}, [state.projects, dispatch]);
return null;
}
@@ -148,30 +179,3 @@ function DesktopProjectBootstrap() {
return null;
}
function RootRouteView() {
const api = useNativeApi();
if (!api) {
return (
<div className="flex h-screen flex-col bg-background text-foreground">
<div className="flex flex-1 items-center justify-center">
<p className="text-sm text-muted-foreground">Connecting to T3 Code server...</p>
</div>
</div>
);
}
return (
<>
<EventRouter />
<AutoProjectBootstrap />
<DesktopProjectBootstrap />
<Outlet />
</>
);
}
export const Route = createRootRoute({
component: RootRouteView,
});
+2 -6
View File
@@ -25,12 +25,8 @@ function ChatThreadRouteView() {
return;
}
if (state.activeThreadId === threadId) {
return;
}
dispatch({ type: "SET_ACTIVE_THREAD", threadId });
}, [dispatch, navigate, state.activeThreadId, state.threadsHydrated, threadExists, threadId]);
dispatch({ type: "VISIT_THREAD", threadId });
}, [dispatch, navigate, state.threadsHydrated, threadExists, threadId]);
if (!threadId || !state.threadsHydrated || !threadExists) {
return null;
+12 -72
View File
@@ -1,82 +1,22 @@
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { type FormEvent, useMemo, useState } from "react";
import { createFileRoute } from "@tanstack/react-router";
import { Button } from "../components/ui/button";
import { Textarea } from "../components/ui/textarea";
import { createThread } from "../threadFactory";
import { truncateTitle } from "../truncateTitle";
import { useStore } from "../store";
import { isElectron } from "../env";
function ChatIndexRouteView() {
const { state, dispatch } = useStore();
const navigate = useNavigate();
const [draft, setDraft] = useState("");
const defaultProject = state.projects[0] ?? null;
const canCreateThread = defaultProject !== null;
const placeholder = useMemo(() => {
if (!canCreateThread) {
return "Add a project in the sidebar to start chatting.";
}
return "Start with a goal, bug report, or implementation idea...";
}, [canCreateThread]);
const onCreateThread = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (!defaultProject) return;
const threadTitle = truncateTitle(draft);
const thread = createThread(
defaultProject.id,
threadTitle
? { model: defaultProject.model, title: threadTitle }
: { model: defaultProject.model },
);
dispatch({
type: "ADD_THREAD",
thread,
});
setDraft("");
void navigate({
to: "/$threadId",
params: { threadId: thread.id },
});
};
return (
<section className="flex min-h-0 min-w-0 flex-1 flex-col bg-background">
<div className="mx-auto flex h-full w-full max-w-3xl flex-col justify-center px-5 py-6">
<div className="mb-5">
<h1 className="text-xl font-semibold text-foreground">New chat</h1>
<p className="mt-1 text-sm text-muted-foreground/70">
Create a thread and continue in the full chat workspace.
</p>
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background text-muted-foreground/40">
{isElectron && (
<div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5">
<span className="text-xs text-muted-foreground/50">No active thread</span>
</div>
)}
<form onSubmit={onCreateThread} className="space-y-3">
<Textarea
value={draft}
onChange={(event) => setDraft(event.target.value)}
placeholder={placeholder}
className="min-h-36 resize-y"
disabled={!canCreateThread}
/>
<div className="flex items-center justify-between">
<p className="text-xs text-muted-foreground/60">
{canCreateThread
? "Create a thread first, then send your first prompt."
: "Projects are required before creating threads."}
</p>
<Button type="submit" disabled={!canCreateThread}>
Create thread
</Button>
</div>
</form>
<div className="flex flex-1 items-center justify-center">
<div className="text-center">
<p className="text-sm">Select a thread or create a new one to get started.</p>
</div>
</div>
</section>
</div>
);
}
+1 -14
View File
@@ -1,5 +1,4 @@
import { Outlet, createFileRoute, useNavigate, useParams } from "@tanstack/react-router";
import { useEffect } from "react";
import { Outlet, createFileRoute } from "@tanstack/react-router";
import DiffPanel from "../components/DiffPanel";
import Sidebar from "../components/Sidebar";
@@ -7,18 +6,6 @@ import { useStore } from "../store";
function ChatRouteLayout() {
const { state } = useStore();
const navigate = useNavigate();
const params = useParams({ strict: false });
const routeThreadId = typeof params.threadId === "string" ? params.threadId : null;
useEffect(() => {
if (routeThreadId || !state.activeThreadId) return;
void navigate({
to: "/$threadId",
params: { threadId: state.activeThreadId },
replace: true,
});
}, [navigate, routeThreadId, state.activeThreadId]);
return (
<div className="flex h-screen overflow-hidden bg-background text-foreground isolate">
+1 -23
View File
@@ -78,7 +78,6 @@ function makeState(thread: Thread): AppState {
},
],
threads: [thread],
activeThreadId: thread.id,
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: false,
@@ -530,7 +529,6 @@ describe("store reducer thread continuity", () => {
projectId: "project-old-b",
}),
],
activeThreadId: "thread-b",
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: false,
@@ -557,7 +555,6 @@ describe("store reducer thread continuity", () => {
expect(next.threads).toHaveLength(1);
expect(next.threads[0]?.id).toBe("thread-a");
expect(next.threads[0]?.projectId).toBe("project-new-a");
expect(next.activeThreadId).toBe("thread-a");
});
it("treats empty scripts from sync as authoritative", () => {
@@ -581,7 +578,6 @@ describe("store reducer thread continuity", () => {
},
],
threads: [makeThread({ id: "thread-a", projectId: "project-old-a" })],
activeThreadId: "thread-a",
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: false,
@@ -671,7 +667,6 @@ describe("store reducer thread continuity", () => {
projectId: "project-2",
}),
],
activeThreadId: "thread-a",
threadsHydrated: true,
runtimeMode: "full-access",
diffOpen: false,
@@ -686,24 +681,6 @@ describe("store reducer thread continuity", () => {
expect(next.projects[0]?.id).toBe("project-2");
expect(next.threads).toHaveLength(1);
expect(next.threads[0]?.id).toBe("thread-b");
expect(next.activeThreadId).toBe("thread-b");
});
it("marks the active thread as visited when selected", () => {
const state = makeState(
makeThread({
lastVisitedAt: "2000-01-01T00:00:00.000Z",
}),
);
const next = reducer(state, {
type: "SET_ACTIVE_THREAD",
threadId: "thread-local-1",
});
expect(next.activeThreadId).toBe("thread-local-1");
expect(next.threads[0]?.lastVisitedAt).toBeDefined();
expect(next.threads[0]?.lastVisitedAt).not.toBe("2000-01-01T00:00:00.000Z");
});
it("marks completion as seen immediately for the active thread", () => {
@@ -727,6 +704,7 @@ describe("store reducer thread continuity", () => {
payload: { turn: { id: "turn-1", status: "completed" } },
}),
activeAssistantItemRef: { current: null },
activeThreadId: "thread-local-1",
});
expect(next.threads[0]?.latestTurnCompletedAt).toBe(completedAt);
+16 -38
View File
@@ -34,7 +34,6 @@ type Action =
| { type: "TOGGLE_PROJECT"; projectId: string }
| { type: "DELETE_PROJECT"; projectId: string }
| { type: "ADD_THREAD"; thread: Thread }
| { type: "SET_ACTIVE_THREAD"; threadId: string }
| { type: "TOGGLE_THREAD_TERMINAL"; threadId: string }
| { type: "SET_THREAD_TERMINAL_OPEN"; threadId: string; open: boolean }
| { type: "SET_THREAD_TERMINAL_HEIGHT"; threadId: string; height: number }
@@ -47,6 +46,7 @@ type Action =
type: "APPLY_EVENT";
event: ProviderEvent;
activeAssistantItemRef: { current: string | null };
activeThreadId?: string | null;
}
| { type: "APPLY_TERMINAL_EVENT"; event: TerminalEvent }
| { type: "UPDATE_SESSION"; threadId: string; session: ProviderSession }
@@ -67,14 +67,14 @@ type Action =
worktreePath: string | null;
}
| { type: "SET_RUNTIME_MODE"; mode: RuntimeMode }
| { type: "DELETE_THREAD"; threadId: string };
| { type: "DELETE_THREAD"; threadId: string }
| { type: "VISIT_THREAD"; threadId: string };
// ── State ────────────────────────────────────────────────────────────
export interface AppState {
projects: Project[];
threads: Thread[];
activeThreadId: string | null;
threadsHydrated: boolean;
runtimeMode: RuntimeMode;
diffOpen: boolean;
@@ -95,7 +95,6 @@ const LEGACY_PERSISTED_STATE_KEYS = [
const initialState: AppState = {
projects: [],
threads: [],
activeThreadId: null,
threadsHydrated: false,
runtimeMode: DEFAULT_RUNTIME_MODE,
diffOpen: false,
@@ -117,14 +116,10 @@ function readPersistedState(): AppState {
if (!hydrated) return initialState;
const threads = hydrated.threads.map((thread) => normalizeThreadTerminals(thread));
const activeThreadId = threads.some((thread) => thread.id === hydrated.activeThreadId)
? hydrated.activeThreadId
: (threads[0]?.id ?? null);
return {
...hydrated,
threads,
activeThreadId,
threadsHydrated: threads.length > 0,
diffOpen: false,
};
@@ -494,15 +489,11 @@ export function reducer(state: AppState, action: Action): AppState {
});
})
.filter((thread): thread is Thread => thread !== null);
const activeThreadId = nextThreads.some((thread) => thread.id === state.activeThreadId)
? state.activeThreadId
: (nextThreads[0]?.id ?? null);
return {
...state,
projects: nextProjects,
threads: nextThreads,
activeThreadId,
};
}
@@ -521,15 +512,11 @@ export function reducer(state: AppState, action: Action): AppState {
}
const threads = state.threads.filter((thread) => thread.projectId !== action.projectId);
const activeThreadId = threads.some((thread) => thread.id === state.activeThreadId)
? state.activeThreadId
: (threads[0]?.id ?? null);
return {
...state,
projects,
threads,
activeThreadId,
};
}
@@ -542,20 +529,6 @@ export function reducer(state: AppState, action: Action): AppState {
return {
...state,
threads: [...state.threads, nextThread],
activeThreadId: action.thread.id,
threadsHydrated: true,
};
}
case "SET_ACTIVE_THREAD": {
const visitedAt = new Date().toISOString();
return {
...state,
activeThreadId: action.threadId,
threads: updateThread(state.threads, action.threadId, (t) => ({
...t,
lastVisitedAt: visitedAt,
})),
};
}
@@ -758,7 +731,7 @@ export function reducer(state: AppState, action: Action): AppState {
};
case "APPLY_EVENT": {
const { event, activeAssistantItemRef } = action;
const { event, activeAssistantItemRef, activeThreadId } = action;
const target = findThreadBySessionId(state.threads, event.sessionId);
if (!target) return state;
if (shouldIgnoreForeignThreadEvent(target, event)) return state;
@@ -782,7 +755,7 @@ export function reducer(state: AppState, action: Action): AppState {
messages: applyEventToMessages(t.messages, event, activeAssistantItemRef),
events: [event, ...t.events],
...updateTurnFields(t, event),
...(event.method === "turn/completed" && t.id === state.activeThreadId
...(event.method === "turn/completed" && t.id === activeThreadId
? { lastVisitedAt: event.createdAt }
: {}),
})),
@@ -877,12 +850,17 @@ export function reducer(state: AppState, action: Action): AppState {
runtimeMode: action.mode,
};
case "DELETE_THREAD": {
const threads = state.threads.filter((t) => t.id !== action.threadId);
const activeThreadId =
state.activeThreadId === action.threadId ? (threads[0]?.id ?? null) : state.activeThreadId;
return { ...state, threads, activeThreadId };
}
case "VISIT_THREAD":
return {
...state,
threads: updateThread(state.threads, action.threadId, (t) => ({
...t,
lastVisitedAt: new Date().toISOString(),
})),
};
case "DELETE_THREAD":
return { ...state, threads: state.threads.filter((t) => t.id !== action.threadId) };
default:
return state;
+2 -2
View File
@@ -1,13 +1,13 @@
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
import { tanstackRouter } from "@tanstack/router-plugin/vite";
import { defineConfig } from "vite";
const port = Number(process.env.PORT ?? 5173);
export default defineConfig({
plugins: [
TanStackRouterVite(),
tanstackRouter(),
react({
babel: {
plugins: [["babel-plugin-react-compiler", { target: "19" }]],