File size: 1,065 Bytes
7c5ed63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { useQuery } from '@tanstack/react-query';
import { api } from '../api';

/**
 * Fetch the projected context for a given agent in a session.
 *
 * The `/api/sessions/:id/context?agent=<agentId>` route returns the
 * full `ContextProjection` (messages, usage totals, contextTokens,
 * config snapshot, permission mode, plan mode, goal, swarm). Defaults
 * to `main` when no agent id is provided, but callers should pass an
 * explicit id for clarity.
 *
 * `mode` selects the projection view: `'model'` (default) mirrors what
 * the model currently sees (post-compaction/undo/clear), while `'full'`
 * requests the full reconstructed history for debugging. Both modes are
 * cached independently (the mode is part of the React Query key).
 */
export function useContext(
  sessionId: string,
  agentId: string,
  mode: 'model' | 'full' = 'model',
) {
  return useQuery({
    queryKey: ['context', sessionId, agentId, mode] as const,
    queryFn: () => api.getContext(sessionId, agentId, mode),
    enabled: sessionId.length > 0 && agentId.length > 0,
  });
}