mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 13: Phase 13: Session status from the client type, compaction-dr
This commit is contained in:
1 parent
717536c5a6
commit
2d4abe79e1
21 files changed
+194
-100
No files matched your search
@@ -153,7 +153,7 @@ describe('useActiveWork', () => {
|
||||
|
||||
await waitFor(() => expect(recentIDs(result.current.groups)).toContain('root2'))
|
||||
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledWith({ cursor: 'page2', includeChildren: true }, 'local')
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledWith({ cursor: 'page2' }, 'local')
|
||||
})
|
||||
|
||||
it('does not request another page when the oldest loaded session is outside the window', async () => {
|
||||
@@ -333,7 +333,7 @@ describe('useActiveWork', () => {
|
||||
expect(row.repo).toBeNull()
|
||||
expect(row.path).toBe('/servers/srv_kitchen/sessions/ses_remote_recent')
|
||||
expect(mocks.listRemoteSessionPage).toHaveBeenCalledWith(
|
||||
{ limit: 50, order: 'desc', includeChildren: true },
|
||||
{ limit: 50, order: 'desc' },
|
||||
'srv_kitchen',
|
||||
)
|
||||
expect(result.current.isError).toBe(false)
|
||||
|
||||
@@ -303,7 +303,7 @@ export function useActiveWork(windowMs: number): {
|
||||
queryKey: activeWorkSessionsQueryKey(serverId),
|
||||
queryFn: async (): Promise<SessionInfo[]> => {
|
||||
const page = await listSessionPage(
|
||||
{ limit: ACTIVE_WORK_SESSION_LIMIT, order: 'desc', includeChildren: true },
|
||||
{ limit: ACTIVE_WORK_SESSION_LIMIT, order: 'desc' },
|
||||
serverId,
|
||||
)
|
||||
return page.items
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { openCodeLocation } from '@opencode-manager/shared/opencode'
|
||||
import { useDebouncedValue } from '@/hooks/useDebouncedValue'
|
||||
import { findFiles } from '@/api/opencode'
|
||||
import { useOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
@@ -20,7 +21,7 @@ export function useFileSearch(
|
||||
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: serverScopedKey(['file-search', debouncedQuery, directory], serverId),
|
||||
queryFn: () => findFiles({ directory, query: debouncedQuery }, serverId),
|
||||
queryFn: () => findFiles({ ...openCodeLocation(directory), query: debouncedQuery }, serverId),
|
||||
enabled: enabled && !!debouncedQuery,
|
||||
staleTime: 60000,
|
||||
})
|
||||
|
||||
@@ -95,12 +95,14 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: undefined,
|
||||
parentID: null,
|
||||
}, 'local')
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledWith({
|
||||
directory: '/w/b',
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: undefined,
|
||||
parentID: null,
|
||||
}, 'local')
|
||||
|
||||
await act(async () => {
|
||||
@@ -111,7 +113,7 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
expect(result.current.data).toHaveLength(3)
|
||||
})
|
||||
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledWith({ directory: '/w/a', cursor: 'cursor_a' }, 'local')
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledWith({ directory: '/w/a', cursor: 'cursor_a', parentID: null }, 'local')
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_a1', 'ses_b1', 'ses_a2'])
|
||||
})
|
||||
|
||||
@@ -130,6 +132,7 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: 'deploy',
|
||||
parentID: null,
|
||||
}, 'local')
|
||||
})
|
||||
})
|
||||
@@ -157,6 +160,7 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: undefined,
|
||||
parentID: null,
|
||||
}, 'local')
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_all1'])
|
||||
expect(result.current.hasNextPage).toBe(true)
|
||||
@@ -170,7 +174,7 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
})
|
||||
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledTimes(2)
|
||||
expect(mocks.listSessionPage).toHaveBeenLastCalledWith({ cursor: 'cursor_all' }, 'local')
|
||||
expect(mocks.listSessionPage).toHaveBeenLastCalledWith({ cursor: 'cursor_all', parentID: null }, 'local')
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_all1', 'ses_all2'])
|
||||
})
|
||||
|
||||
@@ -194,6 +198,7 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: undefined,
|
||||
parentID: null,
|
||||
}, 'local')
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_all'])
|
||||
})
|
||||
@@ -216,7 +221,6 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: undefined,
|
||||
includeChildren: true,
|
||||
}, 'local')
|
||||
expect(queryClient.getQueryCache().getAll()[0]?.queryKey).toEqual([
|
||||
'opencode',
|
||||
@@ -278,6 +282,7 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
search: undefined,
|
||||
project: 'proj_x',
|
||||
subpath: '',
|
||||
parentID: null,
|
||||
}, 'local')
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_root'])
|
||||
expect(result.current.hasNextPage).toBe(true)
|
||||
@@ -291,7 +296,7 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
})
|
||||
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledTimes(2)
|
||||
expect(mocks.listSessionPage).toHaveBeenLastCalledWith({ cursor: 'cursor_project' }, 'local')
|
||||
expect(mocks.listSessionPage).toHaveBeenLastCalledWith({ cursor: 'cursor_project', parentID: null }, 'local')
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_root', 'ses_wt'])
|
||||
})
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ export const useSessionsAcrossDirectories = (
|
||||
*/
|
||||
const persistedGcTime = normalizedSearch === undefined ? PERSISTED_CACHE_MAX_AGE_MS : undefined;
|
||||
const directoryKey = uniqueDirectories.join('|');
|
||||
const childSessionsParam = includeChildren ? { includeChildren: true } : {};
|
||||
const childSessionsParam = includeChildren ? {} : { parentID: null };
|
||||
const isQueryEnabled = uniqueDirectories.length > 0 || allDirectories;
|
||||
|
||||
const query = useInfiniteQuery<
|
||||
|
||||
@@ -217,7 +217,7 @@ describe('useRemoteProjectsByActivity', () => {
|
||||
await waitFor(() => expect(mocks.listSessionPage).toHaveBeenCalledTimes(1))
|
||||
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledWith(
|
||||
{ limit: 100, order: 'desc' },
|
||||
{ limit: 100, order: 'desc', search: undefined, parentID: null },
|
||||
'srv_kitchen',
|
||||
)
|
||||
})
|
||||
|
||||
@@ -59,7 +59,7 @@ describe('resolveDefaultSessionAgent', () => {
|
||||
|
||||
it('ignores agents that are not primary or all mode', () => {
|
||||
const agents = [
|
||||
{ id: 'sub-agent', name: 'sub-agent', mode: 'secondary' },
|
||||
{ id: 'sub-agent', name: 'sub-agent', mode: 'subagent' },
|
||||
{ id: 'build', name: 'build', mode: 'primary' },
|
||||
]
|
||||
expect(resolveDefaultSessionAgent(agents, true)).toBe('build')
|
||||
|
||||
@@ -2,18 +2,13 @@ import { useMemo, useEffect } from 'react'
|
||||
import { useSession, useAgents } from './useOpenCode'
|
||||
import { useSessionAgentStore } from '@/stores/sessionAgentStore'
|
||||
import { getPrimaryAgents } from '@/lib/primaryAgents'
|
||||
import type { ModelRef } from '@opencode-manager/shared/opencode'
|
||||
import type { AgentInfo, ModelRef } from '@opencode-manager/shared/opencode'
|
||||
|
||||
interface AgentInfo {
|
||||
id: string
|
||||
name?: string
|
||||
mode?: string
|
||||
hidden?: boolean
|
||||
}
|
||||
type SessionAgentInfo = Pick<AgentInfo, 'id' | 'mode' | 'hidden'>
|
||||
|
||||
const resolveAvailableAgentId = (
|
||||
agentId: string | undefined,
|
||||
agents: AgentInfo[] | undefined,
|
||||
agents: SessionAgentInfo[] | undefined,
|
||||
agentsLoaded: boolean
|
||||
): string | undefined => {
|
||||
if (!agentId) return undefined
|
||||
@@ -26,7 +21,7 @@ const resolveAvailableAgentId = (
|
||||
}
|
||||
|
||||
export function resolveDefaultSessionAgent(
|
||||
agents: AgentInfo[] | undefined,
|
||||
agents: SessionAgentInfo[] | undefined,
|
||||
agentsLoaded: boolean
|
||||
): string {
|
||||
const primaryAgents = getPrimaryAgents(agents)
|
||||
|
||||
Reference in new issue
Block a user