mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add global permission request system with centralized context and dialog
This commit is contained in:
1 parent
6ce3548dfe
commit
e3a3cbde84
12 files changed
+371
-45
No files matched your search
@@ -35,7 +35,7 @@ function rowToRepo(row: RepoRow): Repo {
|
||||
}
|
||||
|
||||
export function createRepo(db: Database, repo: CreateRepoInput): Repo {
|
||||
const normalizedPath = repo.localPath.replace(/\/+$/, '')
|
||||
const normalizedPath = repo.localPath.trim().replace(/\/+$/, '')
|
||||
|
||||
const existing = repo.isLocal
|
||||
? getRepoByLocalPath(db, normalizedPath)
|
||||
|
||||
@@ -233,7 +233,8 @@ export async function renameOrMoveFile(userPath: string, body: { newPath: string
|
||||
}
|
||||
|
||||
function validatePath(userPath: string): string {
|
||||
const normalized = path.normalize(userPath).replace(/^(\.\.(\/|\\|$))+/, '')
|
||||
const trimmed = userPath.trim()
|
||||
const normalized = path.normalize(trimmed).replace(/^(\.\.(\/|\\|$))+/, '')
|
||||
const fullPath = path.join(SHARED_WORKSPACE_BASE, normalized)
|
||||
const resolved = path.resolve(fullPath)
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ export async function initLocalRepo(
|
||||
localPath: string,
|
||||
branch?: string
|
||||
): Promise<Repo> {
|
||||
const normalizedPath = localPath.replace(/\/+$/, '')
|
||||
const normalizedPath = localPath.trim().replace(/\/+$/, '')
|
||||
const fullPath = path.resolve(getReposPath(), normalizedPath)
|
||||
|
||||
const existing = db.getRepoByLocalPath(database, normalizedPath)
|
||||
|
||||
+31
-1
@@ -8,6 +8,9 @@ import { SettingsDialog } from './components/settings/SettingsDialog'
|
||||
import { useSettingsDialog } from './hooks/useSettingsDialog'
|
||||
import { useTheme } from './hooks/useTheme'
|
||||
import { TTSProvider } from './contexts/TTSContext'
|
||||
import { PermissionProvider } from '@/contexts/PermissionContext'
|
||||
import { PermissionRequestDialog } from '@/components/session/PermissionRequestDialog'
|
||||
import { usePermissionContext } from '@/contexts/PermissionContext'
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -38,6 +41,30 @@ function AppContent() {
|
||||
closeButton
|
||||
/>
|
||||
</BrowserRouter>
|
||||
)
|
||||
}
|
||||
|
||||
function PermissionDialogWrapper() {
|
||||
const {
|
||||
currentPermission,
|
||||
pendingCount,
|
||||
isFromDifferentSession,
|
||||
respondToPermission,
|
||||
dismissPermission,
|
||||
showDialog,
|
||||
setShowDialog,
|
||||
} = usePermissionContext()
|
||||
|
||||
return (
|
||||
<PermissionRequestDialog
|
||||
permission={currentPermission}
|
||||
pendingCount={pendingCount}
|
||||
isFromDifferentSession={isFromDifferentSession}
|
||||
onRespond={respondToPermission}
|
||||
onDismiss={dismissPermission}
|
||||
open={showDialog}
|
||||
onOpenChange={setShowDialog}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -46,7 +73,10 @@ function App() {
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<TTSProvider>
|
||||
<AppContent />
|
||||
<PermissionProvider>
|
||||
<AppContent />
|
||||
<PermissionDialogWrapper />
|
||||
</PermissionProvider>
|
||||
</TTSProvider>
|
||||
</QueryClientProvider>
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Settings } from "lucide-react";
|
||||
import { Settings, Bell } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { BackButton } from "@/components/ui/back-button";
|
||||
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
|
||||
@@ -9,9 +9,11 @@ interface HeaderProps {
|
||||
title: string;
|
||||
backTo?: string;
|
||||
action?: ReactNode;
|
||||
pendingPermissions?: number;
|
||||
onPendingPermissionsClick?: () => void;
|
||||
}
|
||||
|
||||
export function Header({ title, backTo, action }: HeaderProps) {
|
||||
export function Header({ title, backTo, action, pendingPermissions, onPendingPermissionsClick }: HeaderProps) {
|
||||
const { open: openSettings } = useSettingsDialog();
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -37,6 +39,22 @@ export function Header({ title, backTo, action }: HeaderProps) {
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{action && <div>{action}</div>}
|
||||
{pendingPermissions !== undefined && pendingPermissions > 0 && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onPendingPermissionsClick}
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-accent transition-all duration-200 relative"
|
||||
title={`${pendingPermissions} pending permission${pendingPermissions > 1 ? 's' : ''}`}
|
||||
>
|
||||
<Bell className="w-10 h-10" />
|
||||
{pendingPermissions > 0 && (
|
||||
<span className="absolute -top-1 -right-1 bg-destructive text-destructive-foreground text-xs font-bold rounded-full w-5 h-5 flex items-center justify-center">
|
||||
{pendingPermissions > 9 ? '9+' : pendingPermissions}
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
|
||||
@@ -496,10 +496,19 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
|
||||
|
||||
|
||||
return (
|
||||
return (
|
||||
<div className="relative backdrop-blur-md bg-background opacity-95 border border-border dark:border-white/30 rounded-xl p-2 md:p-3 mb-4 md:mb-1 w-full">
|
||||
|
||||
|
||||
{showStopButton && (
|
||||
<button
|
||||
onClick={handleStop}
|
||||
disabled={disabled}
|
||||
className="fixed bottom-19 right-0 md:hidden z-50 p-3 rounded-xl transition-all duration-200 active:scale-95 hover:scale-105 bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border border-red-500/60 shadow-lg shadow-red-500/30"
|
||||
title="Stop"
|
||||
>
|
||||
<Square className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
value={prompt}
|
||||
@@ -523,7 +532,7 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
<div className="flex gap-1.5 md:gap-2 items-center">
|
||||
<button
|
||||
onClick={handleModeToggle}
|
||||
className={`px-3 md:px-3.5 py-1 md:py-2 rounded-lg text-sm font-medium border w-14 flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md ${
|
||||
className={`px-3 md:px-3.5 py-1 h-[36px] rounded-lg text-sm font-medium border w-14 flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md ${
|
||||
isBashMode
|
||||
? 'bg-purple-500/20 border-purple-400 text-purple-700 dark:text-purple-300 shadow-purple-500/20 hover:shadow-purple-500/30'
|
||||
: `${modeBg} ${modeColor} ${modeShadow}`
|
||||
@@ -532,14 +541,14 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
{isBashMode ? 'BASH' : currentMode.toUpperCase()}
|
||||
</button>
|
||||
{hasActiveStream ? (
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground max-w-[120px] md:max-w-[180px] dark:border-white/30">
|
||||
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
|
||||
<SessionStatusIndicator sessionID={sessionID} />
|
||||
</div>
|
||||
) : (
|
||||
!hideSecondaryButtons && (
|
||||
<button
|
||||
onClick={onShowModelsDialog}
|
||||
className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer max-w-[150px] md:max-w-[220px] truncate dark:border-white/30"
|
||||
className="px-2.5 py-1.5 md:px-3 h-[36px] rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer max-w-[150px] md:max-w-[220px] truncate dark:border-white/30"
|
||||
>
|
||||
{displayModelName || 'Select model'}
|
||||
</button>
|
||||
@@ -559,10 +568,10 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
<button
|
||||
onClick={handleStop}
|
||||
disabled={disabled}
|
||||
className="p-1.5 px-4 md:p-2 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border border-red-500/60 hover:border-red-400 shadow-md shadow-red-500/30 hover:shadow-red-500/40 ring-1 ring-red-500/20 hover:ring-red-500/30"
|
||||
className="hidden md:block p-1.5 px-5 md:p-2 md:px-6 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border border-red-500/60 hover:border-red-400 shadow-md shadow-red-500/30 hover:shadow-red-500/40 ring-1 ring-red-500/20 hover:ring-red-500/30"
|
||||
title="Stop"
|
||||
>
|
||||
<Square className="w-4 h-4" />
|
||||
<Square className="w-4 h-4 md:w-5 md:h-5" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
|
||||
@@ -18,6 +18,8 @@ interface PermissionRequestDialogProps {
|
||||
sessionTitle?: string
|
||||
onRespond: (permissionID: string, sessionID: string, response: PermissionResponse) => Promise<void>
|
||||
onDismiss: (permissionID: string, sessionID?: string) => void
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
}
|
||||
|
||||
function getPermissionTypeLabel(type: string): string {
|
||||
@@ -113,11 +115,14 @@ export function PermissionRequestDialog({
|
||||
sessionTitle,
|
||||
onRespond,
|
||||
onDismiss,
|
||||
open: parentOpen,
|
||||
onOpenChange,
|
||||
}: PermissionRequestDialogProps) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [loadingAction, setLoadingAction] = useState<PermissionResponse | null>(null)
|
||||
|
||||
if (!permission) return null
|
||||
if (parentOpen === false) return null
|
||||
|
||||
const handleResponse = async (response: PermissionResponse) => {
|
||||
setIsLoading(true)
|
||||
@@ -139,8 +144,8 @@ export function PermissionRequestDialog({
|
||||
const displaySessionName = sessionTitle || `Session ${permission.sessionID.slice(0, 8)}...`
|
||||
|
||||
return (
|
||||
<Dialog open={true} onOpenChange={() => {}}>
|
||||
<DialogContent hideCloseButton className="max-w-[calc(100vw-2rem)] sm:max-w-md">
|
||||
<Dialog open={parentOpen ?? true} onOpenChange={onOpenChange ?? (() => {})}>
|
||||
<DialogContent className="max-w-[calc(100vw-2rem)] sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
Permission Request
|
||||
|
||||
@@ -61,7 +61,7 @@ export const FloatingActionButton = memo(function FloatingActionButton({
|
||||
onClick={onClick}
|
||||
disabled={loading}
|
||||
className={cn(
|
||||
'fixed z-50 flex items-center gap-2 px-4 py-2 rounded-full backdrop-blur-md transition-all duration-200',
|
||||
'fixed z-50 flex items-center gap-2 px-4 py-2 rounded-xl backdrop-blur-md transition-all duration-200',
|
||||
'min-w-[48px] min-h-[48px]',
|
||||
'active:scale-95 hover:scale-105',
|
||||
'transition-transform',
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
/* eslint-disable react-refresh/only-export-components */
|
||||
import { createContext, useContext, useEffect, useState, useCallback, useMemo, useRef } from 'react'
|
||||
import { OpenCodeClient } from '@/api/opencode'
|
||||
import { permissionEvents, usePermissionRequests } from '@/hooks/usePermissionRequests'
|
||||
import type { Permission, PermissionResponse } from '@/api/types'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
|
||||
type SessionInfo = {
|
||||
id: string
|
||||
directory?: string
|
||||
}
|
||||
|
||||
type ActiveRepo = {
|
||||
url: string
|
||||
directory?: string
|
||||
sessions: SessionInfo[]
|
||||
}
|
||||
|
||||
interface PermissionContextValue {
|
||||
currentPermission: Permission | null
|
||||
pendingCount: number
|
||||
isFromDifferentSession: boolean
|
||||
respondToPermission: (permissionID: string, sessionID: string, response: PermissionResponse) => Promise<void>
|
||||
dismissPermission: (permissionID: string, sessionID?: string) => void
|
||||
showDialog: boolean
|
||||
setShowDialog: (show: boolean) => void
|
||||
currentSessionId: string | null
|
||||
}
|
||||
|
||||
const PermissionContext = createContext<PermissionContextValue | null>(null)
|
||||
|
||||
function useActiveRepos(queryClient: ReturnType<typeof useQueryClient>): ActiveRepo[] {
|
||||
const [activeRepos, setActiveRepos] = useState<ActiveRepo[]>([])
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const checkRepos = () => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current)
|
||||
}
|
||||
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
const cache = queryClient.getQueryCache()
|
||||
const queries = cache.getAll()
|
||||
const repoMap = new Map<string, Set<string>>()
|
||||
|
||||
queries.forEach((query) => {
|
||||
const key = query.queryKey
|
||||
if (key[0] === 'opencode' && key[1] === 'sessions') {
|
||||
const url = key[2] as string
|
||||
|
||||
if (!url || typeof url !== 'string') return
|
||||
|
||||
if (!repoMap.has(url)) {
|
||||
repoMap.set(url, new Set())
|
||||
}
|
||||
|
||||
const sessionsData = query.state.data as Array<{ id: string }> | undefined
|
||||
if (sessionsData) {
|
||||
sessionsData.forEach((session) => {
|
||||
repoMap.get(url)!.add(session.id)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const repos = Array.from(repoMap.entries())
|
||||
.filter(([url]) => {
|
||||
try {
|
||||
new URL(url)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
})
|
||||
.map(([url, sessionIds]) => ({
|
||||
url,
|
||||
sessions: Array.from(sessionIds).map((id) => ({ id })),
|
||||
}))
|
||||
|
||||
setActiveRepos(repos)
|
||||
}, 0)
|
||||
}
|
||||
|
||||
checkRepos()
|
||||
const unsubscribe = queryClient.getQueryCache().subscribe(checkRepos)
|
||||
|
||||
return () => {
|
||||
unsubscribe()
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current)
|
||||
}
|
||||
}
|
||||
}, [queryClient])
|
||||
|
||||
return activeRepos
|
||||
}
|
||||
|
||||
export function PermissionProvider({ children }: { children: React.ReactNode }) {
|
||||
const [showDialog, setShowDialog] = useState(true)
|
||||
const [currentSessionId, setCurrentSessionId] = useState<string | null>(null)
|
||||
const queryClient = useQueryClient()
|
||||
const activeRepos = useActiveRepos(queryClient)
|
||||
const clientsRef = useRef<Map<string, OpenCodeClient>>(new Map())
|
||||
const eventSourceRefs = useRef<Map<string, EventSource>>(new Map())
|
||||
const prevPendingCountRef = useRef(0)
|
||||
|
||||
const {
|
||||
currentPermission,
|
||||
pendingCount,
|
||||
isFromDifferentSession,
|
||||
dismissPermission: dismiss,
|
||||
} = usePermissionRequests()
|
||||
|
||||
useEffect(() => {
|
||||
if (currentPermission?.sessionID) {
|
||||
setCurrentSessionId(currentPermission.sessionID)
|
||||
}
|
||||
}, [currentPermission])
|
||||
|
||||
useEffect(() => {
|
||||
if (pendingCount > prevPendingCountRef.current && pendingCount > 0 && !showDialog) {
|
||||
showToast.info(`${pendingCount} pending permission${pendingCount > 1 ? 's' : ''}`, {
|
||||
duration: 5000,
|
||||
action: {
|
||||
label: 'View',
|
||||
onClick: () => setShowDialog(true),
|
||||
},
|
||||
})
|
||||
}
|
||||
prevPendingCountRef.current = pendingCount
|
||||
}, [pendingCount, showDialog])
|
||||
|
||||
const getClient = useCallback((sessionID: string): OpenCodeClient | null => {
|
||||
for (const repo of activeRepos) {
|
||||
if (repo.sessions.some((s) => s.id === sessionID)) {
|
||||
let client = clientsRef.current.get(repo.url)
|
||||
if (!client) {
|
||||
client = new OpenCodeClient(repo.url, repo.directory)
|
||||
clientsRef.current.set(repo.url, client)
|
||||
}
|
||||
return client
|
||||
}
|
||||
}
|
||||
return null
|
||||
}, [activeRepos])
|
||||
|
||||
useEffect(() => {
|
||||
const currentRefs = eventSourceRefs.current
|
||||
const newURLs = new Set(activeRepos.map((r) => r.url))
|
||||
const existingURLs = new Set(currentRefs.keys())
|
||||
|
||||
existingURLs.forEach((url) => {
|
||||
if (!newURLs.has(url)) {
|
||||
const es = currentRefs.get(url)
|
||||
if (es) {
|
||||
es.close()
|
||||
currentRefs.delete(url)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
currentRefs.forEach((es) => es.close())
|
||||
}
|
||||
}, [activeRepos])
|
||||
|
||||
useEffect(() => {
|
||||
const currentRefs = eventSourceRefs.current
|
||||
|
||||
activeRepos.forEach((repo) => {
|
||||
if (!repo.url) return
|
||||
|
||||
const existingES = currentRefs.get(repo.url)
|
||||
if (existingES) return
|
||||
|
||||
let url: URL
|
||||
try {
|
||||
url = new URL(repo.url)
|
||||
} catch {
|
||||
console.error('Invalid URL for SSE:', repo.url)
|
||||
return
|
||||
}
|
||||
|
||||
if (url.pathname.endsWith('/')) {
|
||||
url.pathname += 'stream'
|
||||
} else {
|
||||
url.pathname += '/stream'
|
||||
}
|
||||
|
||||
const es = new EventSource(url.toString())
|
||||
currentRefs.set(repo.url, es)
|
||||
|
||||
es.addEventListener('permission.updated', (e) => {
|
||||
try {
|
||||
const event = JSON.parse(e.data)
|
||||
if ('id' in event.properties && 'sessionID' in event.properties) {
|
||||
permissionEvents.emit({ type: 'add', permission: event.properties })
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to parse permission.updated event:', err)
|
||||
}
|
||||
})
|
||||
|
||||
es.addEventListener('permission.replied', (e) => {
|
||||
try {
|
||||
const event = JSON.parse(e.data)
|
||||
if ('permissionID' in event.properties && 'sessionID' in event.properties) {
|
||||
permissionEvents.emit({
|
||||
type: 'remove',
|
||||
sessionID: event.properties.sessionID,
|
||||
permissionID: event.properties.permissionID,
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to parse permission.replied event:', err)
|
||||
}
|
||||
})
|
||||
|
||||
es.onerror = (err) => {
|
||||
console.error(`SSE connection error for ${repo.url}:`, err)
|
||||
setTimeout(() => {
|
||||
currentRefs.delete(repo.url)
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
currentRefs.forEach((es) => es.close())
|
||||
currentRefs.clear()
|
||||
}
|
||||
}, [activeRepos])
|
||||
|
||||
const respondToPermission = useCallback(
|
||||
async (permissionID: string, sessionID: string, response: PermissionResponse) => {
|
||||
const client = getClient(sessionID)
|
||||
if (!client) {
|
||||
throw new Error('No client found for session')
|
||||
}
|
||||
await client.respondToPermission(sessionID, permissionID, response)
|
||||
dismiss(permissionID, sessionID)
|
||||
},
|
||||
[getClient, dismiss],
|
||||
)
|
||||
|
||||
const value: PermissionContextValue = useMemo(
|
||||
() => ({
|
||||
currentPermission,
|
||||
pendingCount,
|
||||
isFromDifferentSession,
|
||||
respondToPermission,
|
||||
dismissPermission: dismiss,
|
||||
showDialog,
|
||||
setShowDialog,
|
||||
currentSessionId,
|
||||
}),
|
||||
[
|
||||
currentPermission,
|
||||
pendingCount,
|
||||
isFromDifferentSession,
|
||||
respondToPermission,
|
||||
dismiss,
|
||||
showDialog,
|
||||
currentSessionId,
|
||||
],
|
||||
)
|
||||
|
||||
return <PermissionContext.Provider value={value}>{children}</PermissionContext.Provider>
|
||||
}
|
||||
|
||||
export function usePermissionContext() {
|
||||
const context = useContext(PermissionContext)
|
||||
if (!context) {
|
||||
throw new Error('usePermissionContext must be used within PermissionProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState } from "react";
|
||||
import { RepoList } from "@/components/repo/RepoList";
|
||||
import { usePermissionContext } from "@/contexts/PermissionContext";
|
||||
import { AddRepoDialog } from "@/components/repo/AddRepoDialog";
|
||||
import { FileBrowserSheet } from "@/components/file-browser/FileBrowserSheet";
|
||||
import { Header } from "@/components/layout/Header";
|
||||
@@ -9,6 +10,7 @@ import { Plus, FolderOpen } from "lucide-react";
|
||||
export function Repos() {
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false);
|
||||
const [fileBrowserOpen, setFileBrowserOpen] = useState(false);
|
||||
const { pendingCount, setShowDialog } = usePermissionContext();
|
||||
|
||||
const handleCloseFileBrowser = () => {
|
||||
setFileBrowserOpen(false);
|
||||
@@ -18,6 +20,8 @@ export function Repos() {
|
||||
<div className="min-h-screen bg-gradient-to-br from-background via-background to-background">
|
||||
<Header
|
||||
title="OpenCode"
|
||||
pendingPermissions={pendingCount}
|
||||
onPendingPermissionsClick={() => setShowDialog(true)}
|
||||
action={
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
|
||||
@@ -8,10 +8,10 @@ import { X, VolumeX } from "lucide-react";
|
||||
import { ModelSelectDialog } from "@/components/model/ModelSelectDialog";
|
||||
import { SessionDetailHeader } from "@/components/session/SessionDetailHeader";
|
||||
import { SessionList } from "@/components/session/SessionList";
|
||||
import { PermissionRequestDialog } from "@/components/session/PermissionRequestDialog";
|
||||
|
||||
import { FileBrowserSheet } from "@/components/file-browser/FileBrowserSheet";
|
||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
import { useSession, useSessions, useAbortSession, useUpdateSession, useOpenCodeClient, useMessages } from "@/hooks/useOpenCode";
|
||||
import { useSession, useAbortSession, useUpdateSession, useMessages } from "@/hooks/useOpenCode";
|
||||
import { OPENCODE_API_ENDPOINT, API_BASE_URL } from "@/config";
|
||||
import { useSSE } from "@/hooks/useSSE";
|
||||
import { useUIState } from "@/stores/uiStateStore";
|
||||
@@ -19,7 +19,6 @@ import { useSettings } from "@/hooks/useSettings";
|
||||
import { useModelSelection } from "@/hooks/useModelSelection";
|
||||
import { useKeyboardShortcuts } from "@/hooks/useKeyboardShortcuts";
|
||||
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
|
||||
import { usePermissionRequests } from "@/hooks/usePermissionRequests";
|
||||
import { useAutoScroll } from "@/hooks/useAutoScroll";
|
||||
import { useSwipeBack } from "@/hooks/useMobile";
|
||||
import { useTTS } from "@/hooks/useTTS";
|
||||
@@ -27,7 +26,6 @@ import { useEffect, useRef, useCallback, useMemo } from "react";
|
||||
import { MessageSkeleton } from "@/components/message/MessageSkeleton";
|
||||
import { exportSession, downloadMarkdown } from "@/lib/exportSession";
|
||||
import { showToast } from "@/lib/toast";
|
||||
import type { PermissionResponse } from "@/api/types";
|
||||
import { RepoMcpDialog } from "@/components/repo/RepoMcpDialog";
|
||||
|
||||
export function SessionDetail() {
|
||||
@@ -74,12 +72,10 @@ export function SessionDetail() {
|
||||
});
|
||||
|
||||
const opcodeUrl = OPENCODE_API_ENDPOINT;
|
||||
const openCodeClient = useOpenCodeClient(opcodeUrl, repo?.fullPath);
|
||||
|
||||
const repoDirectory = repo?.fullPath;
|
||||
|
||||
const { data: rawMessages, isLoading: messagesLoading } = useMessages(opcodeUrl, sessionId, repoDirectory);
|
||||
const { data: sessions } = useSessions(opcodeUrl, repoDirectory);
|
||||
const { data: session, isLoading: sessionLoading } = useSession(
|
||||
opcodeUrl,
|
||||
sessionId,
|
||||
@@ -101,7 +97,6 @@ export function SessionDetail() {
|
||||
});
|
||||
|
||||
const { isConnected, isReconnecting } = useSSE(opcodeUrl, repoDirectory);
|
||||
const { currentPermission, pendingCount, isFromDifferentSession, dismissPermission } = usePermissionRequests(sessionId);
|
||||
const abortSession = useAbortSession(opcodeUrl, repoDirectory, sessionId);
|
||||
const updateSession = useUpdateSession(opcodeUrl, repoDirectory);
|
||||
const { open: openSettings } = useSettingsDialog();
|
||||
@@ -175,15 +170,6 @@ export function SessionDetail() {
|
||||
}
|
||||
}, [navigate, repoId, session?.parentID]);
|
||||
|
||||
const handlePermissionResponse = useCallback(async (
|
||||
permissionID: string,
|
||||
permissionSessionID: string,
|
||||
response: PermissionResponse
|
||||
) => {
|
||||
if (!openCodeClient) return
|
||||
await openCodeClient.respondToPermission(permissionSessionID, permissionID, response)
|
||||
}, [openCodeClient]);
|
||||
|
||||
const handleToggleDetails = useCallback(() => {
|
||||
const newValue = !preferences?.expandToolCalls
|
||||
updateSettings({ expandToolCalls: newValue })
|
||||
@@ -281,7 +267,7 @@ export function SessionDetail() {
|
||||
handleClearPrompt()
|
||||
}}
|
||||
onClick={handleClearPrompt}
|
||||
className="absolute -top-12 right-0 md:right-4 z-50 flex items-center gap-2 px-4 py-2 rounded-full bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border-2 border-red-500/60 hover:border-red-400 shadow-lg shadow-red-500/30 hover:shadow-red-500/50 backdrop-blur-md transition-all duration-200 active:scale-95 hover:scale-105 ring-2 ring-red-500/20 hover:ring-red-500/40"
|
||||
className="absolute -top-12 right-0 md:right-4 z-50 flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border-2 border-red-500/60 hover:border-red-400 shadow-lg shadow-red-500/30 hover:shadow-red-500/50 backdrop-blur-md transition-all duration-200 active:scale-95 hover:scale-105 ring-2 ring-red-500/20 hover:ring-red-500/40"
|
||||
aria-label="Clear"
|
||||
>
|
||||
<X className="w-6 h-6" />
|
||||
@@ -296,7 +282,7 @@ export function SessionDetail() {
|
||||
stop()
|
||||
}}
|
||||
onClick={stop}
|
||||
className="absolute -top-12 left-0 md:left-4 z-50 flex items-center gap-2 px-4 py-2 rounded-full bg-gradient-to-br from-red-700 to-red-800 hover:from-red-600 hover:to-red-700 text-destructive-foreground border-2 border-red-600/80 hover:border-red-500 shadow-2xl shadow-red-600/40 hover:shadow-red-600/60 backdrop-blur-md transition-all duration-200 active:scale-95 hover:scale-105 ring-2 ring-red-600/30 hover:ring-red-600/50 animate-[pulse_2s_cubic-bezier(0.4,0,0.6,1)_infinite]"
|
||||
className="absolute -top-12 left-0 md:left-4 z-50 flex items-center gap-2 px-4 py-2 rounded-xl bg-gradient-to-br from-red-700 to-red-800 hover:from-red-600 hover:to-red-700 text-destructive-foreground border-2 border-red-600/80 hover:border-red-500 shadow-2xl shadow-red-600/40 hover:shadow-red-600/60 backdrop-blur-md transition-all duration-200 active:scale-95 hover:scale-105 ring-2 ring-red-600/30 hover:ring-red-600/50 animate-[pulse_2s_cubic-bezier(0.4,0,0.6,1)_infinite]"
|
||||
aria-label="Stop Audio"
|
||||
>
|
||||
<VolumeX className="w-6 h-6" />
|
||||
@@ -366,15 +352,6 @@ export function SessionDetail() {
|
||||
config={settings}
|
||||
directory={repoDirectory}
|
||||
/>
|
||||
|
||||
<PermissionRequestDialog
|
||||
permission={currentPermission}
|
||||
pendingCount={pendingCount}
|
||||
isFromDifferentSession={isFromDifferentSession}
|
||||
sessionTitle={currentPermission ? sessions?.find(s => s.id === currentPermission.sessionID)?.title : undefined}
|
||||
onRespond={handlePermissionResponse}
|
||||
onDismiss={dismissPermission}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,11 +3,14 @@ import { Header } from '@/components/layout/Header'
|
||||
import { GeneralSettings } from '@/components/settings/GeneralSettings'
|
||||
import { KeyboardShortcuts } from '@/components/settings/KeyboardShortcuts'
|
||||
import { OpenCodeConfigManager } from '@/components/settings/OpenCodeConfigManager'
|
||||
import { usePermissionContext } from '@/contexts/PermissionContext'
|
||||
|
||||
export function Settings() {
|
||||
const { pendingCount, setShowDialog } = usePermissionContext()
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-[#0a0a0a] via-[#0d0d0d] to-[#0a0a0a]">
|
||||
<Header title="Settings" backTo="/" />
|
||||
<Header title="Settings" backTo="/" pendingPermissions={pendingCount} onPendingPermissionsClick={() => setShowDialog(true)} />
|
||||
|
||||
<div className="max-w-4xl mx-auto p-6">
|
||||
<Tabs defaultValue="general" className="w-full">
|
||||
|
||||
Reference in new issue
Block a user