/** * Session pane — everything session-scoped: the pending-interactions card * and the session Service panels under the `Services` tab, plus a `State` * tab reading the session's registered plain-data state through * `ISessionStateService.snapshot()` (every key a Session Service registered * into the session-state container, JSON-safe). Rendered as the `Session` * tab of the chat view's right dock (`RightPanel`). The Service panels are * fetch-on-demand (no Service-event push channel exists); the State tab * instead auto-loads on mount and polls once a second, so it stays live * without a Refresh button. */ import { ISessionStateService } from '@moonshot-ai/agent-core-v2/session/state/sessionState'; import { useQuery } from '@tanstack/react-query'; import { useMemo, useState } from 'react'; import { serviceByName } from '../channel'; import { useConnection } from '../connection'; import { type AnyService } from '../panels'; import { fetchSessionWorkspaceAssociation } from '../snapshots/api'; import { InteractionsCard } from './InteractionsCard'; import { ScopePanels } from './ServicePanels'; import { StateCard } from './StateCard'; type Tab = 'services' | 'state'; export function SessionPane({ sessionId, ready }: { sessionId: string | null; ready: boolean }) { const { klient } = useConnection(); const [tab, setTab] = useState('services'); const association = useQuery({ queryKey: ['session-workspace-association', klient.baseUrl, sessionId], queryFn: () => fetchSessionWorkspaceAssociation(klient, sessionId as string), enabled: sessionId !== null && ready, refetchInterval: 1_000, }); const proxyFor = useMemo(() => { return (name: string): AnyService | null => { return ( serviceByName(klient, name, { scope: 'session', sessionId: sessionId !== null && ready ? sessionId : undefined, }) ?? null ); }; }, [klient, sessionId, ready]); const blocked = sessionId === null || !ready; return (
{(['services', 'state'] as const).map((t) => ( ))}
{blocked ? (
{sessionId === null ? 'No session selected.' : 'Loading session…'}
) : ( <>
Workspace association
workspace {association.data?.workspaceId ?? 'loading…'} cwd {association.data?.cwd ?? 'loading…'}
{tab === 'services' ? ( <> ) : ( klient.session(sessionId).service(ISessionStateService).snapshot()} /> )} )}
); }