Fix useDaemonSession to return combined state + APIs
Problem: After migrating to pure Zustand, useDaemonSession returned only SessionState from the store, but components need both state AND imperative APIs (like sendAgentMessage, createAgent, etc.). Solution: Create DaemonSession type that combines: - SessionState (from Zustand store) - Imperative APIs (from SessionContext) - Wrapped store actions (getDraftInput, setFocusedAgentId, etc.) Changes: - Added DaemonSession type to use-daemon-session.ts - useDaemonSession now merges sessionState + context + store actions - Wraps store actions to bind serverId automatically - Updated prop types in components to use DaemonSession - Fixed use-session-directory.ts to use SessionState This restores component compatibility while keeping pure Zustand architecture. Still TODO: Fix remaining components that use SessionContext directly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useStoreWithEqualityFn } from "zustand/traditional";
|
||||
import { useSessionStore, type SessionData } from "@/stores/session-store";
|
||||
import { useSessionStore, type SessionState } from "@/stores/session-store";
|
||||
|
||||
export function useSessionDirectory(): Map<string, SessionData> {
|
||||
export function useSessionDirectory(): Map<string, SessionState> {
|
||||
const sessions = useSessionStore((state) => state.sessions);
|
||||
|
||||
return useMemo(() => {
|
||||
return new Map<string, SessionData>(Object.entries(sessions));
|
||||
return new Map<string, SessionState>(Object.entries(sessions));
|
||||
}, [sessions]);
|
||||
}
|
||||
|
||||
type SessionSelector<T> = (session: SessionData | null) => T;
|
||||
type SessionSelector<T> = (session: SessionState | null) => T;
|
||||
type EqualityFn<T> = ((left: T, right: T) => boolean) | undefined;
|
||||
|
||||
export function useSessionForServer(serverId: string | null): SessionData | null;
|
||||
export function useSessionForServer(serverId: string | null): SessionState | null;
|
||||
export function useSessionForServer<T>(
|
||||
serverId: string | null,
|
||||
selector: SessionSelector<T>,
|
||||
@@ -23,7 +23,7 @@ export function useSessionForServer<T>(
|
||||
serverId: string | null,
|
||||
selector?: SessionSelector<T>,
|
||||
equalityFn?: EqualityFn<T>
|
||||
): SessionData | null | T {
|
||||
): SessionState | null | T {
|
||||
const baseSelector = useCallback(
|
||||
(state: ReturnType<typeof useSessionStore.getState>) =>
|
||||
(serverId ? state.sessions[serverId] ?? null : null),
|
||||
|
||||
Reference in New Issue
Block a user