mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Add local repository support and permission request handling
This commit is contained in:
1 parent
9a2ebc9652
commit
83834e7ed7
22 files changed
+685
-120
No files matched your search
@@ -111,6 +111,11 @@ export class OpenCodeClient {
|
||||
return response.data
|
||||
}
|
||||
|
||||
async respondToPermission(sessionID: string, permissionID: string, response: 'once' | 'always' | 'reject') {
|
||||
const result = await this.client.post(`/session/${sessionID}/permissions/${permissionID}`, { response })
|
||||
return result.data
|
||||
}
|
||||
|
||||
getEventSourceURL() {
|
||||
const base = this.baseURL.startsWith('http')
|
||||
? this.baseURL
|
||||
|
||||
@@ -2,7 +2,8 @@ import type { Repo } from './types'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
|
||||
export async function createRepo(
|
||||
repoUrl: string,
|
||||
repoUrl?: string,
|
||||
localPath?: string,
|
||||
branch?: string,
|
||||
openCodeConfigName?: string,
|
||||
useWorktree?: boolean
|
||||
@@ -10,7 +11,7 @@ export async function createRepo(
|
||||
const response = await fetch(`${API_BASE_URL}/api/repos`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ repoUrl, branch, openCodeConfigName, useWorktree }),
|
||||
body: JSON.stringify({ repoUrl, localPath, branch, openCodeConfigName, useWorktree }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -18,6 +18,8 @@ import type { components } from './opencode-types'
|
||||
export type Message = components['schemas']['Message']
|
||||
export type Part = components['schemas']['Part']
|
||||
export type Session = components['schemas']['Session']
|
||||
export type Permission = components['schemas']['Permission']
|
||||
export type PermissionResponse = 'once' | 'always' | 'reject'
|
||||
|
||||
export type MessageWithParts = {
|
||||
info: Message
|
||||
@@ -86,6 +88,20 @@ export interface SSETodoUpdatedEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export interface SSEPermissionUpdatedEvent {
|
||||
type: 'permission.updated'
|
||||
properties: Permission
|
||||
}
|
||||
|
||||
export interface SSEPermissionRepliedEvent {
|
||||
type: 'permission.replied'
|
||||
properties: {
|
||||
sessionID: string
|
||||
permissionID: string
|
||||
response: string
|
||||
}
|
||||
}
|
||||
|
||||
export type SSEEvent =
|
||||
| SSEMessagePartUpdatedEvent
|
||||
| SSEMessageUpdatedEvent
|
||||
@@ -95,8 +111,8 @@ export type SSEEvent =
|
||||
| SSESessionDeletedEvent
|
||||
| SSESessionCompactedEvent
|
||||
| SSETodoUpdatedEvent
|
||||
| { type: 'permission.updated'; properties: Record<string, unknown> }
|
||||
| { type: 'permission.replied'; properties: Record<string, unknown> }
|
||||
| SSEPermissionUpdatedEvent
|
||||
| SSEPermissionRepliedEvent
|
||||
|
||||
export type ContentPart =
|
||||
| { type: 'text', content: string }
|
||||
|
||||
@@ -28,7 +28,7 @@ export function AddBranchWorkspaceDialog({
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: () =>
|
||||
createRepo(repoUrl, branch || undefined, undefined, useWorktree),
|
||||
createRepo(repoUrl, undefined, branch || undefined, undefined, useWorktree),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["repos"] });
|
||||
setBranch("");
|
||||
|
||||
@@ -12,23 +12,33 @@ interface AddRepoDialogProps {
|
||||
}
|
||||
|
||||
export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) {
|
||||
const [repoType, setRepoType] = useState<'remote' | 'local'>('remote')
|
||||
const [repoUrl, setRepoUrl] = useState('')
|
||||
const [localPath, setLocalPath] = useState('')
|
||||
const [branch, setBranch] = useState('')
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: () => createRepo(repoUrl, branch || undefined, undefined, false),
|
||||
mutationFn: () => {
|
||||
if (repoType === 'local') {
|
||||
return createRepo(undefined, localPath, branch || undefined, undefined, false)
|
||||
} else {
|
||||
return createRepo(repoUrl, undefined, branch || undefined, undefined, false)
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repos'] })
|
||||
setRepoUrl('')
|
||||
setLocalPath('')
|
||||
setBranch('')
|
||||
setRepoType('remote')
|
||||
onOpenChange(false)
|
||||
},
|
||||
})
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (repoUrl) {
|
||||
if ((repoType === 'remote' && repoUrl) || (repoType === 'local' && localPath)) {
|
||||
mutation.mutate()
|
||||
}
|
||||
}
|
||||
@@ -43,15 +53,61 @@ export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) {
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit} className="space-y-4 mt-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm text-zinc-400">Repository URL</label>
|
||||
<Input
|
||||
placeholder="https://github.com/user/repo.git"
|
||||
value={repoUrl}
|
||||
onChange={(e) => setRepoUrl(e.target.value)}
|
||||
disabled={mutation.isPending}
|
||||
className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500"
|
||||
/>
|
||||
<label className="text-sm text-zinc-400">Repository Type</label>
|
||||
<div className="flex gap-4">
|
||||
<label className="flex items-center space-x-2 cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="repoType"
|
||||
value="remote"
|
||||
checked={repoType === 'remote'}
|
||||
onChange={(e) => setRepoType(e.target.value as 'remote')}
|
||||
disabled={mutation.isPending}
|
||||
className="text-blue-600 bg-[#1a1a1a] border-[#2a2a2a]"
|
||||
/>
|
||||
<span className="text-sm text-white">Remote Repository</span>
|
||||
</label>
|
||||
<label className="flex items-center space-x-2 cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="repoType"
|
||||
value="local"
|
||||
checked={repoType === 'local'}
|
||||
onChange={(e) => setRepoType(e.target.value as 'local')}
|
||||
disabled={mutation.isPending}
|
||||
className="text-blue-600 bg-[#1a1a1a] border-[#2a2a2a]"
|
||||
/>
|
||||
<span className="text-sm text-white">Local Repository</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{repoType === 'remote' ? (
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm text-zinc-400">Repository URL</label>
|
||||
<Input
|
||||
placeholder="https://github.com/user/repo.git"
|
||||
value={repoUrl}
|
||||
onChange={(e) => setRepoUrl(e.target.value)}
|
||||
disabled={mutation.isPending}
|
||||
className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm text-zinc-400">Local Path</label>
|
||||
<Input
|
||||
placeholder="my-local-project"
|
||||
value={localPath}
|
||||
onChange={(e) => setLocalPath(e.target.value)}
|
||||
disabled={mutation.isPending}
|
||||
className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500"
|
||||
/>
|
||||
<p className="text-xs text-zinc-500">
|
||||
Directory name will be created in the repos folder
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm text-zinc-400">Branch</label>
|
||||
@@ -64,21 +120,25 @@ export function AddRepoDialog({ open, onOpenChange }: AddRepoDialogProps) {
|
||||
/>
|
||||
<p className="text-xs text-zinc-500">
|
||||
{branch
|
||||
? `Clones repository directly to '${branch}' branch`
|
||||
: "Clones repository to default branch"
|
||||
? repoType === 'remote'
|
||||
? `Clones repository directly to '${branch}' branch`
|
||||
: `Initializes repository with '${branch}' branch`
|
||||
: repoType === 'remote'
|
||||
? "Clones repository to default branch"
|
||||
: "Initializes repository with 'main' branch"
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={!repoUrl || mutation.isPending}
|
||||
disabled={(!repoUrl && repoType === 'remote') || (!localPath && repoType === 'local') || mutation.isPending}
|
||||
className="w-full bg-blue-600 hover:bg-blue-700 text-white"
|
||||
>
|
||||
{mutation.isPending ? (
|
||||
<>
|
||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||
Cloning...
|
||||
{repoType === 'local' ? 'Initializing...' : 'Cloning...'}
|
||||
</>
|
||||
) : (
|
||||
'Add Repository'
|
||||
|
||||
@@ -18,7 +18,7 @@ interface BranchSwitcherProps {
|
||||
repoId: number;
|
||||
currentBranch: string;
|
||||
isWorktree?: boolean;
|
||||
repoUrl: string;
|
||||
repoUrl?: string | null;
|
||||
repoLocalPath?: string;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
|
||||
const queryClient = useQueryClient();
|
||||
const { data: gitStatus } = useGitStatus(repoId);
|
||||
|
||||
const { data: branches } = useQuery({
|
||||
const { data: branches, isLoading: branchesLoading } = useQuery({
|
||||
queryKey: ["branches", repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
enabled: !!repoId,
|
||||
@@ -60,8 +60,12 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="bg-card border-border min-w-[200px]">
|
||||
{branches?.remote && branches.remote.length > 0 ? (
|
||||
branches.remote.map((branch: string) => (
|
||||
{branchesLoading ? (
|
||||
<DropdownMenuItem disabled className="text-muted-foreground">
|
||||
Loading branches...
|
||||
</DropdownMenuItem>
|
||||
) : branches?.local && branches.local.length > 0 ? (
|
||||
branches.local.map((branch: string) => (
|
||||
<DropdownMenuItem
|
||||
key={branch}
|
||||
onClick={() => switchBranchMutation.mutate(branch)}
|
||||
@@ -77,7 +81,7 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
|
||||
))
|
||||
) : (
|
||||
<DropdownMenuItem disabled className="text-muted-foreground">
|
||||
Loading branches...
|
||||
No branches available
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuSeparator />
|
||||
@@ -95,7 +99,7 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
|
||||
)}
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
{!isWorktree && (
|
||||
{!isWorktree && repoUrl && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
@@ -112,11 +116,13 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
<AddBranchWorkspaceDialog
|
||||
open={addBranchOpen}
|
||||
onOpenChange={setAddBranchOpen}
|
||||
repoUrl={repoUrl}
|
||||
/>
|
||||
{repoUrl && (
|
||||
<AddBranchWorkspaceDialog
|
||||
open={addBranchOpen}
|
||||
onOpenChange={setAddBranchOpen}
|
||||
repoUrl={repoUrl}
|
||||
/>
|
||||
)}
|
||||
|
||||
<GitChangesSheet
|
||||
isOpen={gitChangesOpen}
|
||||
|
||||
@@ -8,11 +8,13 @@ import { AddBranchWorkspaceDialog } from "./AddBranchWorkspaceDialog";
|
||||
interface RepoCardProps {
|
||||
repo: {
|
||||
id: number;
|
||||
repoUrl: string;
|
||||
repoUrl?: string | null;
|
||||
localPath?: string;
|
||||
branch?: string;
|
||||
currentBranch?: string;
|
||||
cloneStatus: string;
|
||||
isWorktree?: boolean;
|
||||
isLocal?: boolean;
|
||||
};
|
||||
onDelete: (id: number) => void;
|
||||
isDeleting: boolean;
|
||||
@@ -29,7 +31,9 @@ export function RepoCard({
|
||||
}: RepoCardProps) {
|
||||
const navigate = useNavigate();
|
||||
const [addBranchOpen, setAddBranchOpen] = useState(false);
|
||||
const repoName = repo.repoUrl.split("/").slice(-1)[0].replace(".git", "");
|
||||
const repoName = repo.repoUrl
|
||||
? repo.repoUrl.split("/").slice(-1)[0].replace(".git", "")
|
||||
: repo.localPath || "Local Repo";
|
||||
const branchToDisplay = repo.currentBranch || repo.branch;
|
||||
const isReady = repo.cloneStatus === "ready";
|
||||
|
||||
@@ -115,18 +119,20 @@ export function RepoCard({
|
||||
<ExternalLink className="w-4 h-4 mr-2" />
|
||||
Open
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setAddBranchOpen(true);
|
||||
}}
|
||||
disabled={!isReady}
|
||||
className="h-10 sm:h-9 w-10 p-0"
|
||||
>
|
||||
<GitBranch className="w-4 h-4" />
|
||||
</Button>
|
||||
{repo.repoUrl && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setAddBranchOpen(true);
|
||||
}}
|
||||
disabled={!isReady}
|
||||
className="h-10 sm:h-9 w-10 p-0"
|
||||
>
|
||||
<GitBranch className="w-4 h-4" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -148,11 +154,13 @@ export function RepoCard({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AddBranchWorkspaceDialog
|
||||
open={addBranchOpen}
|
||||
onOpenChange={setAddBranchOpen}
|
||||
repoUrl={repo.repoUrl}
|
||||
/>
|
||||
{repo.repoUrl && (
|
||||
<AddBranchWorkspaceDialog
|
||||
open={addBranchOpen}
|
||||
onOpenChange={setAddBranchOpen}
|
||||
repoUrl={repo.repoUrl}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -76,8 +76,8 @@ export function RepoList() {
|
||||
if (repo.isWorktree) {
|
||||
acc.push(repo);
|
||||
} else {
|
||||
const key = repo.repoUrl;
|
||||
const existing = acc.find(r => r.repoUrl === key && !r.isWorktree);
|
||||
const key = repo.repoUrl || repo.localPath;
|
||||
const existing = acc.find(r => (r.repoUrl || r.localPath) === key && !r.isWorktree);
|
||||
|
||||
if (!existing) {
|
||||
acc.push(repo);
|
||||
@@ -88,10 +88,13 @@ export function RepoList() {
|
||||
}, [] as typeof repos);
|
||||
|
||||
const filteredRepos = dedupedRepos.filter((repo) => {
|
||||
const repoName = repo.repoUrl.split("/").slice(-1)[0].replace(".git", "");
|
||||
const repoName = repo.repoUrl
|
||||
? repo.repoUrl.split("/").slice(-1)[0].replace(".git", "")
|
||||
: repo.localPath;
|
||||
const searchTarget = repo.repoUrl || repo.localPath || "";
|
||||
return (
|
||||
repoName.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
repo.repoUrl.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
searchTarget.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import type { Permission, PermissionResponse } from '@/api/types'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface PermissionRequestDialogProps {
|
||||
permission: Permission | null
|
||||
pendingCount: number
|
||||
onRespond: (permissionID: string, sessionID: string, response: PermissionResponse) => Promise<void>
|
||||
onDismiss: (permissionID: string) => void
|
||||
}
|
||||
|
||||
function getPermissionTypeLabel(type: string): string {
|
||||
switch (type) {
|
||||
case 'bash':
|
||||
return 'Run Command'
|
||||
case 'edit':
|
||||
return 'Edit File'
|
||||
case 'webfetch':
|
||||
return 'Fetch URL'
|
||||
default:
|
||||
return type.charAt(0).toUpperCase() + type.slice(1)
|
||||
}
|
||||
}
|
||||
|
||||
function getPermissionDescription(permission: Permission): string {
|
||||
const patterns = Array.isArray(permission.pattern)
|
||||
? permission.pattern
|
||||
: permission.pattern
|
||||
? [permission.pattern]
|
||||
: []
|
||||
|
||||
if (patterns.length > 0) {
|
||||
return patterns.join('\n')
|
||||
}
|
||||
|
||||
if (permission.metadata?.command) {
|
||||
return String(permission.metadata.command)
|
||||
}
|
||||
|
||||
if (permission.metadata?.path) {
|
||||
return String(permission.metadata.path)
|
||||
}
|
||||
|
||||
if (permission.metadata?.url) {
|
||||
return String(permission.metadata.url)
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
export function PermissionRequestDialog({
|
||||
permission,
|
||||
pendingCount,
|
||||
onRespond,
|
||||
onDismiss,
|
||||
}: PermissionRequestDialogProps) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [loadingAction, setLoadingAction] = useState<PermissionResponse | null>(null)
|
||||
|
||||
if (!permission) return null
|
||||
|
||||
const handleResponse = async (response: PermissionResponse) => {
|
||||
setIsLoading(true)
|
||||
setLoadingAction(response)
|
||||
try {
|
||||
await onRespond(permission.id, permission.sessionID, response)
|
||||
} catch (error) {
|
||||
console.error('Failed to respond to permission:', error)
|
||||
onDismiss(permission.id)
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
setLoadingAction(null)
|
||||
}
|
||||
}
|
||||
|
||||
const typeLabel = getPermissionTypeLabel(permission.type)
|
||||
const description = getPermissionDescription(permission)
|
||||
const hasMultiple = pendingCount > 1
|
||||
|
||||
return (
|
||||
<Dialog open={true} onOpenChange={() => {}}>
|
||||
<DialogContent hideCloseButton className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
Permission Request
|
||||
{hasMultiple && (
|
||||
<span className="text-xs font-normal text-muted-foreground bg-muted px-2 py-0.5 rounded-full">
|
||||
+{pendingCount - 1} more
|
||||
</span>
|
||||
)}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{permission.title || `Allow ${typeLabel.toLowerCase()}?`}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
|
||||
{typeLabel}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{description && (
|
||||
<div className="bg-muted/50 border rounded-md p-3 max-h-32 overflow-y-auto">
|
||||
<pre className="text-sm font-mono whitespace-pre-wrap break-all">
|
||||
{description}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Session: <span className="font-mono">{permission.sessionID.slice(0, 12)}...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="flex-row gap-2 sm:justify-between">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => handleResponse('reject')}
|
||||
disabled={isLoading}
|
||||
className={cn(
|
||||
"flex-1",
|
||||
loadingAction === 'reject' && "opacity-70"
|
||||
)}
|
||||
>
|
||||
{loadingAction === 'reject' ? 'Denying...' : 'Deny'}
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => handleResponse('once')}
|
||||
disabled={isLoading}
|
||||
className={cn(
|
||||
"flex-1",
|
||||
loadingAction === 'once' && "opacity-70"
|
||||
)}
|
||||
>
|
||||
{loadingAction === 'once' ? 'Allowing...' : 'Allow Once'}
|
||||
</Button>
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={() => handleResponse('always')}
|
||||
disabled={isLoading}
|
||||
className={cn(
|
||||
"flex-1",
|
||||
loadingAction === 'always' && "opacity-70"
|
||||
)}
|
||||
>
|
||||
{loadingAction === 'always' ? 'Allowing...' : 'Allow Always'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -7,11 +7,12 @@ import { useState } from "react";
|
||||
|
||||
interface Repo {
|
||||
id: number;
|
||||
repoUrl: string;
|
||||
repoUrl?: string | null;
|
||||
fullPath: string;
|
||||
localPath: string;
|
||||
currentBranch?: string;
|
||||
isWorktree?: boolean;
|
||||
isLocal?: boolean;
|
||||
cloneStatus: 'ready' | 'cloning' | 'error';
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ export function SessionDetailHeader({
|
||||
);
|
||||
}
|
||||
|
||||
const repoName = repo.repoUrl.split("/").pop()?.replace(".git", "") || "Repository";
|
||||
const repoName = repo.repoUrl?.split("/").pop()?.replace(".git", "") || repo.localPath || "Repository";
|
||||
const currentBranch = repo.currentBranch || "main";
|
||||
|
||||
const handleTitleClick = () => {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import type { Permission } from '@/api/types'
|
||||
|
||||
type PermissionEventType = 'add' | 'remove'
|
||||
|
||||
interface PermissionEvent {
|
||||
type: PermissionEventType
|
||||
permission?: Permission
|
||||
permissionID?: string
|
||||
}
|
||||
|
||||
type PermissionListener = (event: PermissionEvent) => void
|
||||
|
||||
const listeners = new Set<PermissionListener>()
|
||||
|
||||
export const permissionEvents = {
|
||||
emit: (event: PermissionEvent) => {
|
||||
listeners.forEach(listener => listener(event))
|
||||
},
|
||||
subscribe: (listener: PermissionListener) => {
|
||||
listeners.add(listener)
|
||||
return () => {
|
||||
listeners.delete(listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function usePermissionRequests() {
|
||||
const [permissions, setPermissions] = useState<Permission[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = permissionEvents.subscribe((event) => {
|
||||
if (event.type === 'add' && event.permission) {
|
||||
setPermissions(prev => {
|
||||
const exists = prev.some(p => p.id === event.permission!.id)
|
||||
if (exists) return prev
|
||||
return [...prev, event.permission!]
|
||||
})
|
||||
} else if (event.type === 'remove' && event.permissionID) {
|
||||
setPermissions(prev => prev.filter(p => p.id !== event.permissionID))
|
||||
}
|
||||
})
|
||||
return unsubscribe
|
||||
}, [])
|
||||
|
||||
const currentPermission = permissions[0] || null
|
||||
|
||||
const dismissPermission = useCallback((permissionID: string) => {
|
||||
setPermissions(prev => prev.filter(p => p.id !== permissionID))
|
||||
}, [])
|
||||
|
||||
const clearAllPermissions = useCallback(() => {
|
||||
setPermissions([])
|
||||
}, [])
|
||||
|
||||
return {
|
||||
currentPermission,
|
||||
pendingCount: permissions.length,
|
||||
dismissPermission,
|
||||
clearAllPermissions
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useOpenCodeClient } from './useOpenCode'
|
||||
import type { SSEEvent, MessageListResponse } from '@/api/types'
|
||||
import { permissionEvents } from './usePermissionRequests'
|
||||
|
||||
export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) => {
|
||||
const client = useOpenCodeClient(opcodeUrl, directory)
|
||||
@@ -231,7 +232,15 @@ case 'message.updated':
|
||||
}
|
||||
|
||||
case 'permission.updated':
|
||||
if ('id' in event.properties) {
|
||||
permissionEvents.emit({ type: 'add', permission: event.properties })
|
||||
}
|
||||
break
|
||||
|
||||
case 'permission.replied':
|
||||
if ('permissionID' in event.properties) {
|
||||
permissionEvents.emit({ type: 'remove', permissionID: event.properties.permissionID })
|
||||
}
|
||||
break
|
||||
|
||||
case 'todo.updated':
|
||||
|
||||
@@ -82,8 +82,9 @@ export function RepoDetail() {
|
||||
);
|
||||
}
|
||||
|
||||
const repoName =
|
||||
repo.repoUrl.split("/").pop()?.replace(".git", "") || "Repository";
|
||||
const repoName = repo.repoUrl
|
||||
? repo.repoUrl.split("/").pop()?.replace(".git", "") || "Repository"
|
||||
: repo.localPath || "Local Repository";
|
||||
const branchToDisplay = repo.currentBranch || repo.branch;
|
||||
const displayName = branchToDisplay ? `${repoName} (${branchToDisplay})` : repoName;
|
||||
const isNotMainBranch = branchToDisplay && branchToDisplay !== repo.defaultBranch;
|
||||
|
||||
@@ -7,16 +7,19 @@ import { PromptInput } from "@/components/message/PromptInput";
|
||||
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, useAbortSession, useUpdateSession } from "@/hooks/useOpenCode";
|
||||
import { useSession, useAbortSession, useUpdateSession, useOpenCodeClient } from "@/hooks/useOpenCode";
|
||||
import { OPENCODE_API_ENDPOINT } from "@/config";
|
||||
import { useSSE } from "@/hooks/useSSE";
|
||||
import { useSettings } from "@/hooks/useSettings";
|
||||
import { useKeyboardShortcuts } from "@/hooks/useKeyboardShortcuts";
|
||||
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
|
||||
import { usePermissionRequests } from "@/hooks/usePermissionRequests";
|
||||
import { useEffect, useRef, useCallback } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import type { PermissionResponse } from "@/api/types";
|
||||
|
||||
export function SessionDetail() {
|
||||
const { id, sessionId } = useParams<{ id: string; sessionId: string }>();
|
||||
@@ -35,9 +38,10 @@ export function SessionDetail() {
|
||||
enabled: !!repoId,
|
||||
});
|
||||
|
||||
const { currentPermission, pendingCount, dismissPermission } = usePermissionRequests();
|
||||
|
||||
|
||||
const opcodeUrl = OPENCODE_API_ENDPOINT;
|
||||
const openCodeClient = useOpenCodeClient(opcodeUrl, repo?.fullPath);
|
||||
|
||||
const repoDirectory = repo?.fullPath;
|
||||
|
||||
@@ -107,6 +111,15 @@ export function SessionDetail() {
|
||||
setSelectedFilePath(undefined)
|
||||
}, []);
|
||||
|
||||
const handlePermissionResponse = useCallback(async (
|
||||
permissionID: string,
|
||||
permissionSessionID: string,
|
||||
response: PermissionResponse
|
||||
) => {
|
||||
if (!openCodeClient) return
|
||||
await openCodeClient.respondToPermission(permissionSessionID, permissionID, response)
|
||||
}, [openCodeClient]);
|
||||
|
||||
if (repoLoading || sessionLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-gradient-to-br from-background via-background to-background">
|
||||
@@ -215,9 +228,16 @@ export function SessionDetail() {
|
||||
isOpen={fileBrowserOpen}
|
||||
onClose={handleFileBrowserClose}
|
||||
basePath={repo.localPath}
|
||||
repoName={repo.repoUrl.split("/").pop()?.replace(".git", "") || "Repository"}
|
||||
repoName={repo.repoUrl?.split("/").pop()?.replace(".git", "") || repo.localPath || "Repository"}
|
||||
initialSelectedFile={selectedFilePath}
|
||||
/>
|
||||
|
||||
<PermissionRequestDialog
|
||||
permission={currentPermission}
|
||||
pendingCount={pendingCount}
|
||||
onRespond={handlePermissionResponse}
|
||||
onDismiss={dismissPermission}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user