mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* feat: show variant label on model picker and add folder upload for agents/commands
- Replace three-dot variant menu trigger with selected variant label
- Add POST /api/settings/opencode-directory-files/install endpoint
- Upload agents/commands markdown folders into .config/opencode/{agents,commands}/
- Reload OpenCode server after upload so files are picked up
* fix: revalidate branch/git caches when mobile sheet opens and on vcs.branch.updated SSE
- add shared invalidateRepoGitCaches() helper for consistent invalidation
- revalidate repo list when mobile repo quick-switch sheet opens
- revalidate current repo when mobile More drawer opens
- revalidate repo/git caches when Source Control dialog opens
- handle vcs.branch.updated SSE event with optimistic cache update
- use helper in branch create/switch mutations in useGit and BranchesTab
* style: make variant selector look more like a button with chevron and compact sizing
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* feat: add opencode-directory-files listing service and consolidate settings editors
* fix: distinguish scroll from tap in suggestion popups on touch devices
* refactor: consolidate settings editors and add DirectoryFilesList component
* refactor: target repo status cache updates only to affected batch entries
* refactor: streamline settings, git hooks, and query invalidation logic
157 lines
5.9 KiB
TypeScript
157 lines
5.9 KiB
TypeScript
import type { QueryClient } from '@tanstack/react-query'
|
|
import type { GitStatusResponse } from '@/types/git'
|
|
|
|
export function messagesQueryKey(
|
|
opcodeUrl: string | null | undefined,
|
|
sessionID: string | null | undefined,
|
|
directory: string | null | undefined,
|
|
) {
|
|
return ['opencode', 'messages', opcodeUrl, sessionID, directory]
|
|
}
|
|
|
|
export function invalidateProviderCaches(queryClient: QueryClient) {
|
|
queryClient.invalidateQueries({ queryKey: ['provider-credentials'] })
|
|
queryClient.invalidateQueries({ queryKey: ['provider-auth-methods'] })
|
|
queryClient.invalidateQueries({ queryKey: ['providers'] })
|
|
queryClient.invalidateQueries({ queryKey: ['providers-with-models'] })
|
|
queryClient.invalidateQueries({ queryKey: ['opencode', 'providers'] })
|
|
queryClient.invalidateQueries({ queryKey: ['providers-for-execution-model'] })
|
|
}
|
|
|
|
export function invalidateConfigCaches(queryClient: QueryClient) {
|
|
queryClient.invalidateQueries({ queryKey: ['opencode', 'config'] })
|
|
queryClient.invalidateQueries({ queryKey: ['opencode', 'agents'] })
|
|
queryClient.invalidateQueries({ queryKey: ['opencode', 'commands'] })
|
|
queryClient.invalidateQueries({ queryKey: ['opencode-config'] })
|
|
queryClient.invalidateQueries({ queryKey: ['health'] })
|
|
queryClient.invalidateQueries({ queryKey: ['mcp-status'] })
|
|
queryClient.invalidateQueries({ queryKey: ['opencode-skills'] })
|
|
queryClient.invalidateQueries({ queryKey: ['managed-skills'] })
|
|
queryClient.invalidateQueries({ queryKey: ['opencode-directory-files'] })
|
|
invalidateProviderCaches(queryClient)
|
|
}
|
|
|
|
export function invalidateSkillCaches(queryClient: QueryClient) {
|
|
queryClient.invalidateQueries({ queryKey: ['settings', 'skills'] })
|
|
queryClient.invalidateQueries({ queryKey: ['managed-skills'] })
|
|
queryClient.invalidateQueries({ queryKey: ['opencode-skills'] })
|
|
queryClient.invalidateQueries({ queryKey: ['health'] })
|
|
}
|
|
|
|
export function invalidateSettingsCaches(queryClient: QueryClient, userId = 'default') {
|
|
queryClient.invalidateQueries({ queryKey: ['settings', userId] })
|
|
invalidateConfigCaches(queryClient)
|
|
}
|
|
|
|
export function invalidateRepoListCaches(queryClient: QueryClient) {
|
|
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
|
queryClient.invalidateQueries({ queryKey: ['reposGitStatus'] })
|
|
}
|
|
|
|
interface RepoGitInvalidationOptions {
|
|
invalidateStatus?: boolean
|
|
invalidateRepoMeta?: boolean
|
|
}
|
|
|
|
export function invalidateRepoGitCaches(
|
|
queryClient: QueryClient,
|
|
repoId?: number | null,
|
|
options: RepoGitInvalidationOptions = {},
|
|
) {
|
|
if (!repoId) {
|
|
invalidateRepoListCaches(queryClient)
|
|
queryClient.invalidateQueries({ queryKey: ['repo'] })
|
|
queryClient.invalidateQueries({ queryKey: ['branches'] })
|
|
queryClient.invalidateQueries({ queryKey: ['gitStatus'] })
|
|
queryClient.invalidateQueries({ queryKey: ['gitLog'] })
|
|
queryClient.invalidateQueries({ queryKey: ['fileDiff'] })
|
|
return
|
|
}
|
|
|
|
if (options.invalidateRepoMeta ?? true) {
|
|
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
|
queryClient.invalidateQueries({ queryKey: ['repo', repoId] })
|
|
queryClient.invalidateQueries({ queryKey: ['branches', repoId] })
|
|
}
|
|
if (options.invalidateStatus ?? true) {
|
|
queryClient.invalidateQueries({ queryKey: ['gitStatus', repoId] })
|
|
}
|
|
queryClient.invalidateQueries({ queryKey: ['gitLog', repoId] })
|
|
queryClient.invalidateQueries({ queryKey: ['fileDiff', repoId] })
|
|
}
|
|
|
|
function reposGitStatusQueryIncludesRepo(queryKey: readonly unknown[], repoId: number) {
|
|
const repoIds = queryKey[1]
|
|
return queryKey[0] === 'reposGitStatus' && Array.isArray(repoIds) && repoIds.includes(repoId)
|
|
}
|
|
|
|
export function setRepoGitStatusCaches(queryClient: QueryClient, repoId: number, data: GitStatusResponse) {
|
|
queryClient.setQueryData(['gitStatus', repoId], data)
|
|
queryClient.setQueriesData<Map<number, GitStatusResponse>>(
|
|
{
|
|
queryKey: ['reposGitStatus'],
|
|
predicate: (query) => reposGitStatusQueryIncludesRepo(query.queryKey, repoId),
|
|
},
|
|
(oldData) => {
|
|
if (!oldData) return oldData
|
|
const updated = new Map(oldData)
|
|
updated.set(repoId, data)
|
|
return updated
|
|
},
|
|
)
|
|
}
|
|
|
|
const repoGitInvalidationTimers = new WeakMap<QueryClient, Map<number, ReturnType<typeof setTimeout>>>()
|
|
|
|
export function invalidateRepoGitCachesDebounced(queryClient: QueryClient, repoId: number, delayMs = 200) {
|
|
const existingTimers = repoGitInvalidationTimers.get(queryClient)
|
|
const timers = existingTimers ?? new Map<number, ReturnType<typeof setTimeout>>()
|
|
if (!existingTimers) {
|
|
repoGitInvalidationTimers.set(queryClient, timers)
|
|
}
|
|
const existing = timers.get(repoId)
|
|
if (existing) clearTimeout(existing)
|
|
timers.set(
|
|
repoId,
|
|
setTimeout(() => {
|
|
timers.delete(repoId)
|
|
invalidateRepoGitCaches(queryClient, repoId)
|
|
}, delayMs),
|
|
)
|
|
}
|
|
|
|
export function invalidateSessionCaches(queryClient: QueryClient) {
|
|
queryClient.invalidateQueries({
|
|
predicate: (query) =>
|
|
query.queryKey[0] === 'opencode' &&
|
|
(query.queryKey[1] === 'sessions' ||
|
|
query.queryKey[1] === 'session' ||
|
|
query.queryKey[1] === 'messages'),
|
|
})
|
|
}
|
|
|
|
export function invalidateSessionListCaches(queryClient: QueryClient, opcodeUrl?: string | null) {
|
|
queryClient.invalidateQueries({
|
|
predicate: (query) => {
|
|
if (query.queryKey[0] !== 'opencode') return false
|
|
if (query.queryKey[1] !== 'sessions') return false
|
|
if (opcodeUrl && query.queryKey[2] !== opcodeUrl) return false
|
|
return true
|
|
},
|
|
})
|
|
}
|
|
|
|
const sessionListInvalidationTimers = new WeakMap<QueryClient, ReturnType<typeof setTimeout>>()
|
|
|
|
export function invalidateSessionListCachesDebounced(queryClient: QueryClient, delayMs = 200) {
|
|
const existing = sessionListInvalidationTimers.get(queryClient)
|
|
if (existing) clearTimeout(existing)
|
|
sessionListInvalidationTimers.set(
|
|
queryClient,
|
|
setTimeout(() => {
|
|
sessionListInvalidationTimers.delete(queryClient)
|
|
invalidateSessionListCaches(queryClient)
|
|
}, delayMs),
|
|
)
|
|
}
|