mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix issues (#136)
* fix: prevent delete button click when card is not swiped open * refactor: improve CreateRepoInput type safety * security: require AUTH_SECRET and use secure random generation * fix: SSH key path validation, async passphrase stripping, and port handling * fix: use correct console methods for logger levels * Add error handling to DB update functions and improve migration logging * Add error handling for session lookup in auth middleware * Add structured git error handling with user-friendly messages - Parse git errors with specific error codes (AUTH_FAILED, REPO_NOT_FOUND, PUSH_REJECTED, MERGE_CONFLICT, etc.) and appropriate HTTP status codes - Return structured error responses with summary and detail from backend - Add GitErrorBanner component for better error display in UI - Add optional onError callback to useGit hook for external error handling * Make IPC server initialization/disposal async and fix SSH host key handler * add try-catch error handling in frontend lib utilities * remove unresolved promise handlers in speech synthesizer callbacks * Extract error types to shared package * Import GitErrorCode from shared package * Refactor API layer to use shared FetchError and fetchWrapper * Update prompt parser and source control components * Extract MCP server list to separate component with improved badge menu UX * merge useSettingsDialogUrl into useSettingsDialog and extract getRepoDisplayName utility * add separate loading state for passkey sign in * refactor hooks: use fetchWrapper, improve error handling, add proper types * replace browser confirm() with DeleteDialog component in settings * fix: add missing variables parameter in React Query onError callbacks * Refactor message parts to use separate Zustand store * Update QuestionPrompt styling for light/dark mode
This commit is contained in:
1 parent
7f7d106c28
commit
5de419ee28
75 files changed
+1990
-1367
No files matched your search
@@ -4,15 +4,16 @@ import { MessagePart } from './MessagePart'
|
||||
import { UserMessageActionButtons } from './UserMessageActionButtons'
|
||||
import { EditableUserMessage, ClickableUserMessage } from './EditableUserMessage'
|
||||
import { MessageError } from './MessageError'
|
||||
import type { MessageWithParts } from '@/api/types'
|
||||
import type { Message, Part } from '@/api/types'
|
||||
import { useSessionStatusForSession } from '@/stores/sessionStatusStore'
|
||||
import { useSessionTodos } from '@/stores/sessionTodosStore'
|
||||
import { useMessageParts, usePartsForMessage, usePartsVersion } from '@/stores/messagePartsStore'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
import type { Todo } from '@/components/message/SessionTodoDisplay'
|
||||
import type { OpenCodeError } from '@/lib/opencode-errors'
|
||||
|
||||
function getMessageTextContent(msg: MessageWithParts): string {
|
||||
return msg.parts
|
||||
function getMessageTextContent(parts: Part[]): string {
|
||||
return parts
|
||||
.filter(p => p.type === 'text')
|
||||
.map(p => p.text || '')
|
||||
.join('\n\n')
|
||||
@@ -23,16 +24,16 @@ interface MessageThreadProps {
|
||||
opcodeUrl: string
|
||||
sessionID: string
|
||||
directory?: string
|
||||
messages?: MessageWithParts[]
|
||||
messages?: Message[]
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
onChildSessionClick?: (sessionId: string) => void
|
||||
onUndoMessage?: (restoredPrompt: string) => void
|
||||
model?: string
|
||||
}
|
||||
|
||||
const isMessageStreaming = (msg: MessageWithParts): boolean => {
|
||||
if (msg.info.role !== 'assistant') return false
|
||||
return !('completed' in msg.info.time && msg.info.time.completed)
|
||||
const isMessageStreaming = (msg: Message): boolean => {
|
||||
if (msg.role !== 'assistant') return false
|
||||
return !('completed' in msg.time && msg.time.completed)
|
||||
}
|
||||
|
||||
function isSessionInRetry(sessionStatus: { type?: string }): boolean {
|
||||
@@ -47,19 +48,166 @@ const compareMessageIds = (id1: string, id2: string): number => {
|
||||
}
|
||||
|
||||
const findLastMessageByRole = (
|
||||
messages: MessageWithParts[],
|
||||
messages: Message[],
|
||||
role: 'user' | 'assistant',
|
||||
predicate?: (msg: MessageWithParts) => boolean
|
||||
predicate?: (msg: Message) => boolean
|
||||
): string | undefined => {
|
||||
for (let i = messages.length - 1; i >= 0; i--) {
|
||||
const msg = messages[i]
|
||||
if (msg.info.role === role && (!predicate || predicate(msg))) {
|
||||
return msg.info.id
|
||||
if (msg.role === role && (!predicate || predicate(msg))) {
|
||||
return msg.id
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
interface MessageRowProps {
|
||||
msg: Message
|
||||
index: number
|
||||
messages: Message[]
|
||||
pendingAssistantId: string | undefined
|
||||
lastUserMessageId: string | undefined
|
||||
isSessionBusy: boolean
|
||||
onUndoMessage?: (restoredPrompt: string) => void
|
||||
editingUserMessageId: string | null
|
||||
editingForAssistantId: string | null
|
||||
opcodeUrl: string
|
||||
sessionID: string
|
||||
directory?: string
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
onChildSessionClick?: (sessionId: string) => void
|
||||
handleStartEditUserMessage: (userMessageId: string, assistantMessageId: string) => void
|
||||
handleCancelEdit: () => void
|
||||
model?: string
|
||||
}
|
||||
|
||||
const MessageRow = memo(function MessageRow({
|
||||
msg,
|
||||
index,
|
||||
messages,
|
||||
pendingAssistantId,
|
||||
lastUserMessageId,
|
||||
isSessionBusy,
|
||||
onUndoMessage,
|
||||
editingUserMessageId,
|
||||
editingForAssistantId,
|
||||
opcodeUrl,
|
||||
sessionID,
|
||||
directory,
|
||||
onFileClick,
|
||||
onChildSessionClick,
|
||||
handleStartEditUserMessage,
|
||||
handleCancelEdit,
|
||||
model,
|
||||
}: MessageRowProps) {
|
||||
const parts = usePartsForMessage(msg.id)
|
||||
const streaming = isMessageStreaming(msg)
|
||||
const isQueued = msg.role === 'user' && pendingAssistantId && compareMessageIds(msg.id, pendingAssistantId) > 0
|
||||
const isLastUserMessage = msg.role === 'user' && msg.id === lastUserMessageId
|
||||
const messageTextContent = getMessageTextContent(parts)
|
||||
|
||||
const nextAssistantMessage = messages.slice(index + 1).find(m => m.role === 'assistant')
|
||||
const isUserBeforeAssistant = msg.role === 'user' && nextAssistantMessage
|
||||
const canEditUserMessage = isLastUserMessage && isUserBeforeAssistant && !isSessionBusy
|
||||
const canUndoUserMessage = isLastUserMessage && nextAssistantMessage && !isSessionBusy && onUndoMessage
|
||||
|
||||
const isEditingThisMessage = editingUserMessageId === msg.id
|
||||
|
||||
return (
|
||||
<div
|
||||
key={msg.id}
|
||||
className="flex flex-col group"
|
||||
>
|
||||
<div
|
||||
className={`w-full rounded-lg p-1.5 ${
|
||||
msg.role === 'user'
|
||||
? isQueued
|
||||
? 'bg-amber-500/10 border border-amber-500/30'
|
||||
: isEditingThisMessage
|
||||
? 'bg-blue-600/30 border border-blue-600/50'
|
||||
: 'bg-blue-600/20 border border-blue-600/30'
|
||||
: 'bg-card/50 border border-border'
|
||||
} ${streaming ? 'animate-pulse-subtle' : ''}`}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 mb-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-medium text-muted-foreground">
|
||||
{msg.role === 'user' ? 'You' : (msg.role === 'assistant' && 'modelID' in msg ? msg.modelID : 'Assistant')}
|
||||
</span>
|
||||
{msg.time && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{new Date(msg.time.created).toLocaleTimeString()}
|
||||
</span>
|
||||
)}
|
||||
{canEditUserMessage && nextAssistantMessage && (
|
||||
<button
|
||||
onClick={() => handleStartEditUserMessage(msg.id, nextAssistantMessage.id)}
|
||||
className="p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
title="Edit message"
|
||||
>
|
||||
<Pencil className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
)}
|
||||
{isQueued && (
|
||||
<span className="text-xs font-semibold bg-amber-500 text-amber-950 px-1.5 py-0.5 rounded">
|
||||
QUEUED
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{msg.role === 'user' && canUndoUserMessage && (
|
||||
<UserMessageActionButtons
|
||||
opcodeUrl={opcodeUrl}
|
||||
sessionId={sessionID}
|
||||
directory={directory}
|
||||
userMessageId={msg.id}
|
||||
userMessageContent={messageTextContent}
|
||||
onUndo={onUndoMessage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
{msg.role === 'user' && isEditingThisMessage && editingForAssistantId ? (
|
||||
<EditableUserMessage
|
||||
opcodeUrl={opcodeUrl}
|
||||
sessionId={sessionID}
|
||||
directory={directory}
|
||||
content={messageTextContent}
|
||||
assistantMessageId={editingForAssistantId}
|
||||
onCancel={handleCancelEdit}
|
||||
model={model}
|
||||
/>
|
||||
) : msg.role === 'user' && canEditUserMessage && nextAssistantMessage ? (
|
||||
<ClickableUserMessage
|
||||
content={messageTextContent}
|
||||
onClick={() => handleStartEditUserMessage(msg.id, nextAssistantMessage.id)}
|
||||
isEditable={false}
|
||||
/>
|
||||
) : parts.length > 0 ? (
|
||||
parts.map((part: Part, partIndex: number) => (
|
||||
<div key={`${msg.id}-${part.id}-${partIndex}`}>
|
||||
<MessagePart
|
||||
part={part}
|
||||
role={msg.role}
|
||||
allParts={parts}
|
||||
partIndex={partIndex}
|
||||
onFileClick={onFileClick}
|
||||
onChildSessionClick={onChildSessionClick}
|
||||
messageTextContent={msg.role === 'assistant' ? messageTextContent : undefined}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
) : null}
|
||||
{msg.role === 'assistant' && 'error' in msg && msg.error && (
|
||||
<MessageError error={msg.error as OpenCodeError} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
export const MessageThread = memo(function MessageThread({
|
||||
opcodeUrl,
|
||||
sessionID,
|
||||
@@ -86,12 +234,21 @@ export const MessageThread = memo(function MessageThread({
|
||||
|
||||
const isSessionBusy = !!pendingAssistantId || isSessionInRetry(sessionStatus)
|
||||
const setSessionTodos = useSessionTodos((state) => state.setTodos)
|
||||
const partsVersion = usePartsVersion()
|
||||
|
||||
useEffect(() => {
|
||||
if (!messages || messages.length === 0) return
|
||||
|
||||
const latestTodoPart = messages
|
||||
.flatMap(msg => msg.parts)
|
||||
const partsMap = useMessageParts.getState().parts
|
||||
const allParts: Part[] = []
|
||||
for (const msg of messages) {
|
||||
const msgParts = partsMap.get(msg.id)
|
||||
if (msgParts) {
|
||||
allParts.push(...msgParts)
|
||||
}
|
||||
}
|
||||
|
||||
const latestTodoPart = allParts
|
||||
.filter((part): part is components['schemas']['ToolPart'] => part.type === 'tool' && (part.tool === 'todowrite' || part.tool === 'todoread'))
|
||||
.filter(part => part.state.status === 'completed' && 'time' in part.state)
|
||||
.sort((a, b) => {
|
||||
@@ -102,8 +259,8 @@ export const MessageThread = memo(function MessageThread({
|
||||
return bEndTime - aEndTime
|
||||
})[0]
|
||||
|
||||
if (latestTodoPart) {
|
||||
const state = latestTodoPart.state
|
||||
if (latestTodoPart) {
|
||||
const state = latestTodoPart.state
|
||||
let todos: Todo[] = []
|
||||
|
||||
if ('metadata' in state && state.metadata?.todos && Array.isArray(state.metadata.todos)) {
|
||||
@@ -124,7 +281,7 @@ const state = latestTodoPart.state
|
||||
setSessionTodos(sessionID, todos)
|
||||
}
|
||||
}
|
||||
}, [messages, sessionID, setSessionTodos])
|
||||
}, [messages, sessionID, setSessionTodos, partsVersion])
|
||||
|
||||
const handleStartEditUserMessage = useCallback((userMessageId: string, assistantMessageId: string) => {
|
||||
setEditingUserMessageId(userMessageId)
|
||||
@@ -146,113 +303,28 @@ const state = latestTodoPart.state
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-2 p-2 overflow-x-hidden">
|
||||
{messages.map((msg, index) => {
|
||||
const streaming = isMessageStreaming(msg)
|
||||
const isQueued = msg.info.role === 'user' && pendingAssistantId && compareMessageIds(msg.info.id, pendingAssistantId) > 0
|
||||
const isLastUserMessage = msg.info.role === 'user' && msg.info.id === lastUserMessageId
|
||||
const messageTextContent = getMessageTextContent(msg)
|
||||
|
||||
const nextAssistantMessage = messages.slice(index + 1).find(m => m.info.role === 'assistant')
|
||||
const isUserBeforeAssistant = msg.info.role === 'user' && nextAssistantMessage
|
||||
const canEditUserMessage = isLastUserMessage && isUserBeforeAssistant && !isSessionBusy
|
||||
const canUndoUserMessage = isLastUserMessage && nextAssistantMessage && !isSessionBusy && onUndoMessage
|
||||
|
||||
const isEditingThisMessage = editingUserMessageId === msg.info.id
|
||||
|
||||
return (
|
||||
<div
|
||||
key={msg.info.id}
|
||||
className="flex flex-col group"
|
||||
>
|
||||
<div
|
||||
className={`w-full rounded-lg p-1.5 ${
|
||||
msg.info.role === 'user'
|
||||
? isQueued
|
||||
? 'bg-amber-500/10 border border-amber-500/30'
|
||||
: isEditingThisMessage
|
||||
? 'bg-blue-600/30 border border-blue-600/50'
|
||||
: 'bg-blue-600/20 border border-blue-600/30'
|
||||
: 'bg-card/50 border border-border'
|
||||
} ${streaming ? 'animate-pulse-subtle' : ''}`}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 mb-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-medium text-muted-foreground">
|
||||
{msg.info.role === 'user' ? 'You' : (msg.info.role === 'assistant' && 'modelID' in msg.info ? msg.info.modelID : 'Assistant')}
|
||||
</span>
|
||||
{msg.info.time && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{new Date(msg.info.time.created).toLocaleTimeString()}
|
||||
</span>
|
||||
)}
|
||||
{canEditUserMessage && nextAssistantMessage && (
|
||||
<button
|
||||
onClick={() => handleStartEditUserMessage(msg.info.id, nextAssistantMessage.info.id)}
|
||||
className="p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors"
|
||||
title="Edit message"
|
||||
>
|
||||
<Pencil className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
)}
|
||||
{isQueued && (
|
||||
<span className="text-xs font-semibold bg-amber-500 text-amber-950 px-1.5 py-0.5 rounded">
|
||||
QUEUED
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{msg.info.role === 'user' && canUndoUserMessage && (
|
||||
<UserMessageActionButtons
|
||||
opcodeUrl={opcodeUrl}
|
||||
sessionId={sessionID}
|
||||
directory={directory}
|
||||
userMessageId={msg.info.id}
|
||||
userMessageContent={messageTextContent}
|
||||
onUndo={onUndoMessage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
{msg.info.role === 'user' && isEditingThisMessage && editingForAssistantId ? (
|
||||
<EditableUserMessage
|
||||
opcodeUrl={opcodeUrl}
|
||||
sessionId={sessionID}
|
||||
directory={directory}
|
||||
content={messageTextContent}
|
||||
assistantMessageId={editingForAssistantId}
|
||||
onCancel={handleCancelEdit}
|
||||
model={model}
|
||||
/>
|
||||
) : msg.info.role === 'user' && canEditUserMessage && nextAssistantMessage ? (
|
||||
<ClickableUserMessage
|
||||
content={messageTextContent}
|
||||
onClick={() => handleStartEditUserMessage(msg.info.id, nextAssistantMessage.info.id)}
|
||||
isEditable={false}
|
||||
/>
|
||||
) : (
|
||||
msg.parts.map((part, partIndex) => (
|
||||
<div key={`${msg.info.id}-${part.id}-${partIndex}`}>
|
||||
<MessagePart
|
||||
part={part}
|
||||
role={msg.info.role}
|
||||
allParts={msg.parts}
|
||||
partIndex={partIndex}
|
||||
onFileClick={onFileClick}
|
||||
onChildSessionClick={onChildSessionClick}
|
||||
messageTextContent={msg.info.role === 'assistant' ? messageTextContent : undefined}
|
||||
/>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
{msg.info.role === 'assistant' && 'error' in msg.info && msg.info.error && (
|
||||
<MessageError error={msg.info.error as OpenCodeError} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{messages.map((msg, index) => (
|
||||
<MessageRow
|
||||
key={msg.id}
|
||||
msg={msg}
|
||||
index={index}
|
||||
messages={messages}
|
||||
pendingAssistantId={pendingAssistantId}
|
||||
lastUserMessageId={lastUserMessageId}
|
||||
isSessionBusy={isSessionBusy}
|
||||
onUndoMessage={onUndoMessage}
|
||||
editingUserMessageId={editingUserMessageId}
|
||||
editingForAssistantId={editingForAssistantId}
|
||||
opcodeUrl={opcodeUrl}
|
||||
sessionID={sessionID}
|
||||
directory={directory}
|
||||
onFileClick={onFileClick}
|
||||
onChildSessionClick={onChildSessionClick}
|
||||
handleStartEditUserMessage={handleStartEditUserMessage}
|
||||
handleCancelEdit={handleCancelEdit}
|
||||
model={model}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -25,7 +25,7 @@ import { detectMentionTrigger, parsePromptToParts, getFilename, filterAgentsByQu
|
||||
|
||||
|
||||
import type { components } from '@/api/opencode-types'
|
||||
import type { MessageWithParts, FileInfo, ImageAttachment } from '@/api/types'
|
||||
import type { Message, FileAttachmentInfo, ImageAttachment } from '@/api/types'
|
||||
|
||||
const ACCEPTED_IMAGE_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp", "image/heic", "image/heif"]
|
||||
|
||||
@@ -82,7 +82,7 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
|
||||
const [isBashMode, setIsBashMode] = useState(false)
|
||||
const [showSuggestions, setShowSuggestions] = useState(false)
|
||||
const [suggestionQuery, setSuggestionQuery] = useState('')
|
||||
const [attachedFiles, setAttachedFiles] = useState(new Map<string, FileInfo>())
|
||||
const [attachedFiles, setAttachedFiles] = useState(new Map<string, FileAttachmentInfo>())
|
||||
const [imageAttachments, setImageAttachments] = useState<ImageAttachment[]>([])
|
||||
const [isDragging, setIsDragging] = useState(false)
|
||||
const [showMentionSuggestions, setShowMentionSuggestions] = useState(false)
|
||||
@@ -715,12 +715,12 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
}
|
||||
}
|
||||
|
||||
const isMessageIncomplete = (msg: MessageWithParts): boolean => {
|
||||
if (msg.info.role !== 'assistant') return false
|
||||
return !('completed' in msg.info.time && msg.info.time.completed)
|
||||
const isMessageIncomplete = (msg: Message): boolean => {
|
||||
if (msg.role !== 'assistant') return false
|
||||
return !('completed' in msg.time && msg.time.completed)
|
||||
}
|
||||
|
||||
const lastAssistantMessage = messages?.filter(msg => msg.info.role === 'assistant').at(-1)
|
||||
const lastAssistantMessage = messages?.filter(msg => msg.role === 'assistant').at(-1)
|
||||
const hasIncompleteMessages = lastAssistantMessage ? isMessageIncomplete(lastAssistantMessage) : false
|
||||
|
||||
const sessionAgent = useSessionAgent(opcodeUrl, sessionID, directory)
|
||||
|
||||
@@ -190,11 +190,7 @@ export function TextPart({ part }: TextPartProps) {
|
||||
}, [part.text])
|
||||
|
||||
if (!part.text || part.text.trim() === '') {
|
||||
return (
|
||||
<div className="text-muted-foreground italic text-sm">
|
||||
[Empty message content]
|
||||
</div>
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'
|
||||
import { RepoMcpServerList } from './RepoMcpServerList'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { DropdownMenuSeparator } from '@/components/ui/dropdown-menu'
|
||||
import { Loader2, XCircle, AlertCircle, Plug, Shield, MoreVertical, Key, RefreshCw } from 'lucide-react'
|
||||
import { McpOAuthDialog } from '@/components/settings/McpOAuthDialog'
|
||||
import { mcpApi, type McpStatus, type McpServerConfig, type McpAuthStartResponse } from '@/api/mcp'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
@@ -133,58 +128,12 @@ export function RepoMcpDialog({ open, onOpenChange, directory }: RepoMcpDialogPr
|
||||
fetchStatus()
|
||||
}
|
||||
}, [open, directory, fetchStatus])
|
||||
|
||||
|
||||
const getDisplayName = (serverId: string): string => {
|
||||
const name = serverId.replace(/[-_]/g, ' ')
|
||||
return name.charAt(0).toUpperCase() + name.slice(1)
|
||||
}
|
||||
|
||||
const getDescription = (serverConfig: McpServerConfig): string => {
|
||||
if (serverConfig.type === 'local' && serverConfig.command) {
|
||||
const command = serverConfig.command.join(' ')
|
||||
if (command.includes('filesystem')) return 'File system access'
|
||||
if (command.includes('git')) return 'Git repository operations'
|
||||
if (command.includes('sqlite')) return 'SQLite database access'
|
||||
if (command.includes('postgres')) return 'PostgreSQL database access'
|
||||
if (command.includes('brave-search')) return 'Web search via Brave'
|
||||
if (command.includes('github')) return 'GitHub repository access'
|
||||
if (command.includes('slack')) return 'Slack integration'
|
||||
if (command.includes('puppeteer')) return 'Web automation'
|
||||
if (command.includes('fetch')) return 'HTTP requests'
|
||||
if (command.includes('memory')) return 'Persistent memory'
|
||||
return `Local: ${command}`
|
||||
} else if (serverConfig.type === 'remote' && serverConfig.url) {
|
||||
return serverConfig.url
|
||||
}
|
||||
return 'MCP server'
|
||||
}
|
||||
|
||||
const getStatusBadge = (status?: McpStatus) => {
|
||||
if (!status) return null
|
||||
|
||||
switch (status.status) {
|
||||
case 'connected':
|
||||
return <Badge variant="default" className="text-xs bg-green-600">Connected</Badge>
|
||||
case 'disabled':
|
||||
return <Badge className="text-xs bg-gray-700 text-gray-300 border-gray-600 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600">Disabled</Badge>
|
||||
case 'failed':
|
||||
return (
|
||||
<Badge variant="destructive" className="text-xs flex items-center gap-1">
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
Failed
|
||||
</Badge>
|
||||
)
|
||||
case 'needs_auth':
|
||||
return (
|
||||
<Badge variant="outline" className="text-xs border-yellow-500 text-yellow-600">
|
||||
Needs Auth
|
||||
</Badge>
|
||||
)
|
||||
default:
|
||||
return <Badge variant="outline" className="text-xs">Unknown</Badge>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!directory) return null
|
||||
|
||||
return (
|
||||
@@ -197,124 +146,17 @@ export function RepoMcpDialog({ open, onOpenChange, directory }: RepoMcpDialogPr
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="px-4 sm:px-6 py-3 sm:py-4 flex-1 overflow-y-auto min-h-0">
|
||||
{hasFetchedStatus && serverIds.length === 0 ? (
|
||||
<div className="text-center py-6 text-muted-foreground">
|
||||
<Plug className="w-10 h-10 mx-auto mb-3 opacity-50" />
|
||||
<p className="text-sm">No MCP servers configured for this location</p>
|
||||
<p className="text-xs mt-1">Add them in Settings or in the project's opencode.json</p>
|
||||
</div>
|
||||
) : isLoadingStatus ? (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="w-4 h-4 animate-spin text-blue-600 dark:text-blue-400" />
|
||||
<span className="ml-2 text-sm text-muted-foreground">Loading...</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{serverIds.map((serverId) => {
|
||||
const serverConfig = mcpServers[serverId]
|
||||
const status = localStatus[serverId]
|
||||
const isConnected = status?.status === 'connected'
|
||||
const needsAuth = status?.status === 'needs_auth'
|
||||
const failed = status?.status === 'failed'
|
||||
const isRemote = serverConfig?.type === 'remote'
|
||||
const hasOAuthConfig = isRemote && !!serverConfig?.oauth
|
||||
const hasOAuthError = failed && isRemote && !!status?.error && /oauth|auth.*state/i.test(status.error)
|
||||
const isOAuthServer = hasOAuthConfig || hasOAuthError || (needsAuth && isRemote)
|
||||
const connectedWithOAuth = isOAuthServer && isConnected
|
||||
const showAuthButton = needsAuth || (isOAuthServer && failed)
|
||||
|
||||
return (
|
||||
<div
|
||||
key={serverId}
|
||||
className="flex items-center justify-between gap-3 p-3 rounded-lg border border-border bg-card"
|
||||
>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<p className="text-sm font-medium truncate">
|
||||
{getDisplayName(serverId)}
|
||||
</p>
|
||||
{connectedWithOAuth && (
|
||||
<span title="OAuth authenticated">
|
||||
<Shield className="h-3 w-3 text-muted-foreground" />
|
||||
</span>
|
||||
)}
|
||||
{getStatusBadge(status)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground truncate">
|
||||
{serverConfig ? getDescription(serverConfig) : 'MCP server'}
|
||||
</p>
|
||||
{failed && status.status === 'failed' && (
|
||||
<div className="flex items-center gap-1 mt-1 text-xs text-red-500">
|
||||
<XCircle className="w-3 h-3 flex-shrink-0" />
|
||||
<span className="truncate">{status.error}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{showAuthButton ? (
|
||||
<Button
|
||||
onClick={() => setAuthDialogServerId(serverId)}
|
||||
disabled={toggleMutation.isPending}
|
||||
variant="default"
|
||||
size="sm"
|
||||
>
|
||||
<Key className="h-3 w-3 mr-1" />
|
||||
Auth
|
||||
</Button>
|
||||
) : (
|
||||
<Switch
|
||||
checked={isConnected}
|
||||
disabled={toggleMutation.isPending || removeAuthMutation.isPending}
|
||||
onCheckedChange={(enabled) => {
|
||||
toggleMutation.mutate({ serverId, enable: enabled })
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
/>
|
||||
)}
|
||||
{(isOAuthServer || needsAuth) && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="h-8 w-8 p-0">
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{showAuthButton && (
|
||||
<DropdownMenuItem onClick={() => setAuthDialogServerId(serverId)}>
|
||||
<Key className="h-4 w-4 mr-2" />
|
||||
Authenticate
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{connectedWithOAuth && (
|
||||
<DropdownMenuItem onClick={() => setAuthDialogServerId(serverId)}>
|
||||
<RefreshCw className="h-4 w-4 mr-2" />
|
||||
Re-authenticate
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{connectedWithOAuth && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={() => setRemoveAuthConfirmServer(serverId)}
|
||||
disabled={removeAuthMutation.isPending}
|
||||
>
|
||||
<Shield className="h-4 w-4 mr-2" />
|
||||
{removeAuthMutation.isPending ? 'Removing...' : 'Remove Auth'}
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<RepoMcpServerList
|
||||
hasFetchedStatus={hasFetchedStatus}
|
||||
serverIds={serverIds}
|
||||
isLoadingStatus={isLoadingStatus}
|
||||
localStatus={localStatus}
|
||||
mcpServers={mcpServers}
|
||||
toggleMutation={toggleMutation}
|
||||
removeAuthMutation={removeAuthMutation}
|
||||
onAuthClick={setAuthDialogServerId}
|
||||
onRemoveAuthClick={setRemoveAuthConfirmServer}
|
||||
/>
|
||||
|
||||
<DeleteDialog
|
||||
open={!!removeAuthConfirmServer}
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'
|
||||
import { DropdownMenuSeparator } from '@/components/ui/dropdown-menu'
|
||||
import { Loader2, XCircle, AlertCircle, Plug, Shield, Key, RefreshCw, ChevronDown } from 'lucide-react'
|
||||
import type { McpStatus, McpServerConfig } from '@/api/mcp'
|
||||
|
||||
|
||||
interface RepoMcpServerListProps {
|
||||
hasFetchedStatus: boolean
|
||||
serverIds: string[]
|
||||
isLoadingStatus: boolean
|
||||
localStatus: Record<string, McpStatus>
|
||||
mcpServers: Record<string, McpServerConfig>
|
||||
toggleMutation: {
|
||||
mutate: (variables: { serverId: string; enable: boolean }) => void
|
||||
isPending: boolean
|
||||
}
|
||||
removeAuthMutation: {
|
||||
mutate: (variables: string) => void
|
||||
isPending: boolean
|
||||
}
|
||||
onAuthClick: (serverId: string) => void
|
||||
onRemoveAuthClick: (serverId: string) => void
|
||||
}
|
||||
|
||||
export function RepoMcpServerList({
|
||||
hasFetchedStatus,
|
||||
serverIds,
|
||||
isLoadingStatus,
|
||||
localStatus,
|
||||
mcpServers,
|
||||
toggleMutation,
|
||||
removeAuthMutation,
|
||||
onAuthClick,
|
||||
onRemoveAuthClick,
|
||||
}: RepoMcpServerListProps) {
|
||||
const getDisplayName = (serverId: string): string => {
|
||||
const name = serverId.replace(/[-_]/g, ' ')
|
||||
return name.charAt(0).toUpperCase() + name.slice(1)
|
||||
}
|
||||
|
||||
const getDescription = (serverConfig: McpServerConfig): string => {
|
||||
if (serverConfig.type === 'local' && serverConfig.command) {
|
||||
const command = serverConfig.command.join(' ')
|
||||
if (command.includes('filesystem')) return 'File system access'
|
||||
if (command.includes('git')) return 'Git repository operations'
|
||||
if (command.includes('sqlite')) return 'SQLite database access'
|
||||
if (command.includes('postgres')) return 'PostgreSQL database access'
|
||||
if (command.includes('brave-search')) return 'Web search via Brave'
|
||||
if (command.includes('github')) return 'GitHub repository access'
|
||||
if (command.includes('slack')) return 'Slack integration'
|
||||
if (command.includes('puppeteer')) return 'Web automation'
|
||||
if (command.includes('fetch')) return 'HTTP requests'
|
||||
if (command.includes('memory')) return 'Persistent memory'
|
||||
return `Local: ${command}`
|
||||
} else if (serverConfig.type === 'remote' && serverConfig.url) {
|
||||
return serverConfig.url
|
||||
}
|
||||
return 'MCP server'
|
||||
}
|
||||
|
||||
const getStatusBadge = (status?: McpStatus) => {
|
||||
if (!status) return null
|
||||
|
||||
switch (status.status) {
|
||||
case 'connected':
|
||||
return <Badge variant="default" className="text-xs bg-green-600">Connected</Badge>
|
||||
case 'disabled':
|
||||
return <Badge className="text-xs bg-gray-700 text-gray-300 border-gray-600 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600">Disabled</Badge>
|
||||
case 'failed':
|
||||
return (
|
||||
<Badge variant="destructive" className="text-xs flex items-center gap-1">
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
Failed
|
||||
</Badge>
|
||||
)
|
||||
case 'needs_auth':
|
||||
return (
|
||||
<Badge variant="outline" className="text-xs border-yellow-500 text-yellow-600">
|
||||
Needs Auth
|
||||
</Badge>
|
||||
)
|
||||
default:
|
||||
return <Badge variant="outline" className="text-xs">Unknown</Badge>
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="px-4 sm:px-6 py-3 sm:py-4 flex-1 overflow-y-auto min-h-0">
|
||||
{hasFetchedStatus && serverIds.length === 0 ? (
|
||||
<div className="text-center py-6 text-muted-foreground">
|
||||
<Plug className="w-10 h-10 mx-auto mb-3 opacity-50" />
|
||||
<p className="text-sm">No MCP servers configured for this location</p>
|
||||
<p className="text-xs mt-1">Add them in Settings or in the project's opencode.json</p>
|
||||
</div>
|
||||
) : isLoadingStatus ? (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="w-4 h-4 animate-spin text-blue-600 dark:text-blue-400" />
|
||||
<span className="ml-2 text-sm text-muted-foreground">Loading...</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{serverIds.map((serverId) => {
|
||||
const serverConfig = mcpServers[serverId]
|
||||
const status = localStatus[serverId]
|
||||
const isConnected = status?.status === 'connected'
|
||||
const needsAuth = status?.status === 'needs_auth'
|
||||
const failed = status?.status === 'failed'
|
||||
const isRemote = serverConfig?.type === 'remote'
|
||||
const hasOAuthConfig = isRemote && !!serverConfig?.oauth
|
||||
const hasOAuthError = failed && isRemote && !!status?.error && /oauth|auth.*state/i.test(status.error)
|
||||
const isOAuthServer = hasOAuthConfig || hasOAuthError || (needsAuth && isRemote)
|
||||
const connectedWithOAuth = isOAuthServer && isConnected
|
||||
const showAuthButton = needsAuth || (isOAuthServer && failed)
|
||||
|
||||
return (
|
||||
<div
|
||||
key={serverId}
|
||||
className="flex items-center justify-between gap-3 p-3 rounded-lg border border-border bg-card"
|
||||
>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<p className="text-sm font-medium truncate">
|
||||
{getDisplayName(serverId)}
|
||||
</p>
|
||||
{(showAuthButton || connectedWithOAuth) ? (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
className="cursor-pointer hover:bg-accent rounded inline-flex items-center gap-1"
|
||||
title="Click for options"
|
||||
>
|
||||
{status?.status === 'connected' && (
|
||||
<span className="text-xs bg-green-600 text-white px-2 py-0.5 rounded-full inline-flex items-center gap-1">
|
||||
Connected<ChevronDown className="h-3 w-3" />
|
||||
</span>
|
||||
)}
|
||||
{status?.status === 'needs_auth' && (
|
||||
<span className="text-xs border border-yellow-500 text-yellow-600 px-2 py-0.5 rounded-full inline-flex items-center gap-1">
|
||||
Needs Auth<ChevronDown className="h-3 w-3" />
|
||||
</span>
|
||||
)}
|
||||
{status?.status === 'failed' && (
|
||||
<span className="text-xs bg-red-500 text-white px-2 py-0.5 rounded-full inline-flex items-center gap-1">
|
||||
<AlertCircle className="h-3 w-3" />Failed<ChevronDown className="h-3 w-3" />
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start">
|
||||
{showAuthButton && (
|
||||
<DropdownMenuItem onClick={() => onAuthClick(serverId)}>
|
||||
<Key className="h-4 w-4 mr-2" />
|
||||
Authenticate
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{connectedWithOAuth && (
|
||||
<DropdownMenuItem onClick={() => onAuthClick(serverId)}>
|
||||
<RefreshCw className="h-4 w-4 mr-2" />
|
||||
Re-authenticate
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{connectedWithOAuth && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={() => onRemoveAuthClick(serverId)}
|
||||
disabled={removeAuthMutation.isPending}
|
||||
>
|
||||
<Shield className="h-4 w-4 mr-2" />
|
||||
{removeAuthMutation.isPending ? 'Removing...' : 'Remove Auth'}
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
) : (
|
||||
getStatusBadge(status)
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground truncate">
|
||||
{serverConfig ? getDescription(serverConfig) : 'MCP server'}
|
||||
</p>
|
||||
{failed && status.status === 'failed' && (
|
||||
<div className="flex items-center gap-1 mt-1 text-xs text-red-500">
|
||||
<XCircle className="w-3 h-3 flex-shrink-0" />
|
||||
<span className="truncate">{status.error}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
{showAuthButton ? (
|
||||
<Button
|
||||
onClick={() => onAuthClick(serverId)}
|
||||
disabled={toggleMutation.isPending}
|
||||
variant="default"
|
||||
size="sm"
|
||||
>
|
||||
<Key className="h-3 w-3 mr-1" />
|
||||
Auth
|
||||
</Button>
|
||||
) : (
|
||||
<Switch
|
||||
checked={isConnected}
|
||||
disabled={toggleMutation.isPending || removeAuthMutation.isPending}
|
||||
onCheckedChange={(enabled) => {
|
||||
toggleMutation.mutate({ serverId, enable: enabled })
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -179,20 +179,20 @@ export function QuestionPrompt({ question, onReply, onReject }: QuestionPromptPr
|
||||
|
||||
return (
|
||||
<div
|
||||
className="w-full bg-gradient-to-br from-blue-500/10 to-blue-600/5 border-2 border-blue-500/30 rounded-xl shadow-lg shadow-blue-500/10 backdrop-blur-sm mb-3 overflow-hidden"
|
||||
className="w-full bg-gradient-to-br from-blue-100 to-blue-200 dark:from-blue-950 dark:to-blue-900 border-2 border-blue-300 dark:border-blue-700 rounded-xl shadow-lg shadow-blue-500/20 mb-3 overflow-hidden"
|
||||
>
|
||||
<div className="flex items-center justify-between px-2 py-1.5 sm:px-3 sm:py-2 border-b border-blue-500/20 bg-blue-500/5">
|
||||
<div className="flex items-center justify-between px-2 py-1.5 sm:px-3 sm:py-2 border-b border-blue-200 dark:border-blue-800 bg-blue-50 dark:bg-blue-900/50">
|
||||
<div className="flex items-center gap-2">
|
||||
{totalSteps > 1 && (
|
||||
<button
|
||||
onClick={goToPrev}
|
||||
disabled={currentIndex === 0}
|
||||
className="p-0.5 sm:p-1 rounded hover:bg-blue-500/20 disabled:opacity-30 disabled:cursor-not-allowed transition-colors"
|
||||
className="p-0.5 sm:p-1 rounded hover:bg-blue-200 dark:hover:bg-blue-800 disabled:opacity-30 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
<ChevronLeft className="w-3.5 h-3.5 sm:w-4 sm:h-4 text-blue-600 dark:text-blue-400" />
|
||||
</button>
|
||||
)}
|
||||
<span className="text-xs sm:text-sm font-semibold text-blue-400">
|
||||
<span className="text-xs sm:text-sm font-semibold text-blue-600 dark:text-white">
|
||||
{isConfirmStep ? 'Review' : (
|
||||
totalSteps > 1
|
||||
? `Question ${currentIndex + 1}/${questions.length}`
|
||||
@@ -203,7 +203,7 @@ export function QuestionPrompt({ question, onReply, onReject }: QuestionPromptPr
|
||||
<button
|
||||
onClick={goToNext}
|
||||
disabled={currentIndex === totalSteps - 1}
|
||||
className="p-0.5 sm:p-1 rounded hover:bg-blue-500/20 disabled:opacity-30 disabled:cursor-not-allowed transition-colors"
|
||||
className="p-0.5 sm:p-1 rounded hover:bg-blue-200 dark:hover:bg-blue-800 disabled:opacity-30 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
<ChevronRight className="w-3.5 h-3.5 sm:w-4 sm:h-4 text-blue-600 dark:text-blue-400" />
|
||||
</button>
|
||||
@@ -218,7 +218,7 @@ export function QuestionPrompt({ question, onReply, onReject }: QuestionPromptPr
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="p-2 sm:p-3 max-h-[50vh] sm:max-h-[70vh] overflow-y-auto overflow-x-hidden">
|
||||
<div className="p-2 sm:p-3 max-h-[50vh] sm:max-h-[70vh] overflow-y-auto overflow-x-hidden bg-background/60 dark:bg-black/30">
|
||||
{isConfirmStep ? (
|
||||
<ConfirmStep
|
||||
questions={questions}
|
||||
@@ -243,7 +243,7 @@ export function QuestionPrompt({ question, onReply, onReject }: QuestionPromptPr
|
||||
</div>
|
||||
|
||||
{totalSteps > 1 && (
|
||||
<div className="flex justify-center gap-1 sm:gap-1.5 py-1.5 sm:py-2 border-t border-blue-500/10">
|
||||
<div className="flex justify-center gap-1 sm:gap-1.5 py-1.5 sm:py-2 border-t border-blue-200 dark:border-blue-800">
|
||||
{Array.from({ length: totalSteps }).map((_, i) => (
|
||||
<button
|
||||
key={i}
|
||||
@@ -264,7 +264,7 @@ export function QuestionPrompt({ question, onReply, onReject }: QuestionPromptPr
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-1.5 sm:gap-2 px-2 pb-2 sm:px-3 sm:pb-3">
|
||||
<div className="flex gap-1.5 sm:gap-2 px-2 py-2 sm:px-3 sm:py-3">
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleReject}
|
||||
@@ -362,10 +362,10 @@ function QuestionStep({
|
||||
key={i}
|
||||
onClick={() => onSelectOption(option.label)}
|
||||
className={cn(
|
||||
"w-full text-left p-2 sm:p-3 rounded-lg border-2 transition-all duration-200 active:scale-[0.98]",
|
||||
"w-full text-left p-2 sm:p-3 rounded-lg transition-all duration-200 active:scale-[0.98]",
|
||||
isSelected
|
||||
? "border-blue-500 bg-blue-500/10"
|
||||
: "border-border hover:border-blue-500/50 hover:bg-blue-500/5"
|
||||
? "bg-blue-200 dark:bg-blue-700/50"
|
||||
: "bg-white/40 dark:bg-white/5 hover:bg-white/60 dark:hover:bg-white/10"
|
||||
)}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-1.5 sm:gap-2">
|
||||
@@ -380,7 +380,7 @@ function QuestionStep({
|
||||
</div>
|
||||
<span className={cn(
|
||||
"text-xs sm:text-sm font-semibold",
|
||||
isSelected ? "text-blue-400" : "text-foreground"
|
||||
isSelected ? "text-blue-600 dark:text-blue-300" : "text-foreground"
|
||||
)}>
|
||||
{option.label}
|
||||
</span>
|
||||
@@ -404,10 +404,10 @@ function QuestionStep({
|
||||
}
|
||||
}}
|
||||
className={cn(
|
||||
"w-full text-left p-2 sm:p-3 rounded-lg border-2 transition-all duration-200",
|
||||
"w-full text-left p-2 sm:p-3 rounded-lg transition-all duration-200",
|
||||
expandedOther || isCustomSelected
|
||||
? "border-blue-500 bg-blue-500/10"
|
||||
: "border-border hover:border-blue-500/50 hover:bg-blue-500/5"
|
||||
? "bg-blue-200 dark:bg-blue-700/50"
|
||||
: "bg-white/40 dark:bg-white/5 hover:bg-white/60 dark:hover:bg-white/10"
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-1.5 sm:gap-2">
|
||||
@@ -421,7 +421,7 @@ function QuestionStep({
|
||||
</div>
|
||||
<span className={cn(
|
||||
"text-xs sm:text-sm font-semibold",
|
||||
expandedOther || isCustomSelected ? "text-blue-400" : "text-foreground"
|
||||
expandedOther || isCustomSelected ? "text-blue-600 dark:text-blue-300" : "text-foreground"
|
||||
)}>
|
||||
Other...
|
||||
</span>
|
||||
@@ -479,18 +479,18 @@ function ConfirmStep({ questions, answers, onEditQuestion }: ConfirmStepProps) {
|
||||
key={i}
|
||||
onClick={() => onEditQuestion(i)}
|
||||
className={cn(
|
||||
"w-full text-left p-2 sm:p-3 rounded-lg border transition-colors",
|
||||
"w-full text-left p-2 sm:p-3 rounded-lg transition-colors",
|
||||
hasAnswer
|
||||
? "border-green-500/40 bg-green-500/10 hover:bg-green-500/15"
|
||||
: "border-red-500/40 bg-red-500/10 hover:bg-red-500/15"
|
||||
? "bg-green-50 dark:bg-green-900/30 hover:bg-green-100 dark:hover:bg-green-900/50"
|
||||
: "bg-red-50 dark:bg-red-900/30 hover:bg-red-100 dark:hover:bg-red-900/50"
|
||||
)}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-1.5 sm:gap-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-[10px] sm:text-xs text-foreground/60 truncate">{q.header}</p>
|
||||
<p className="text-[10px] sm:text-xs text-muted-foreground truncate">{q.header}</p>
|
||||
<p className={cn(
|
||||
"text-xs sm:text-sm font-semibold mt-0.5",
|
||||
hasAnswer ? "text-green-400" : "text-red-400"
|
||||
hasAnswer ? "text-green-700 dark:text-green-400" : "text-red-700 dark:text-red-400"
|
||||
)}>
|
||||
{hasAnswer ? answer.join(', ') : '(not answered)'}
|
||||
</p>
|
||||
|
||||
@@ -45,7 +45,7 @@ export const SessionCard = ({
|
||||
<div className="relative" onClick={close}>
|
||||
<div
|
||||
className={`absolute top-0.5 right-0 bottom-0.5 w-20 bg-red-600 flex items-center justify-center rounded-r-lg transition-opacity ${
|
||||
!isSwipingBack && (isOpen || swipeOffset > 40) ? "opacity-100" : "opacity-0"
|
||||
!isSwipingBack && (isOpen || swipeOffset > 40) ? "opacity-100" : "opacity-0 pointer-events-none"
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { Loader2, User, KeyRound, LogOut, Plus, Trash2, AlertCircle, CheckCircle, Lock } from 'lucide-react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { passkey, changePassword } from '@/lib/auth-client'
|
||||
@@ -28,6 +29,7 @@ export function AccountSettings() {
|
||||
const [success, setSuccess] = useState<string | null>(null)
|
||||
const [showChangePassword, setShowChangePassword] = useState(false)
|
||||
const [editingProfile, setEditingProfile] = useState(false)
|
||||
const [deletePasskeyId, setDeletePasskeyId] = useState<string | null>(null)
|
||||
|
||||
const { data: passkeys, isLoading: passkeysLoading } = useQuery({
|
||||
queryKey: ['passkeys'],
|
||||
@@ -104,11 +106,20 @@ export function AccountSettings() {
|
||||
const handleDeletePasskey = (id: string) => {
|
||||
setError(null)
|
||||
setSuccess(null)
|
||||
if (confirm('Are you sure you want to delete this passkey?')) {
|
||||
deletePasskeyMutation.mutate(id)
|
||||
setDeletePasskeyId(id)
|
||||
}
|
||||
|
||||
const handleDeleteConfirm = () => {
|
||||
if (deletePasskeyId) {
|
||||
deletePasskeyMutation.mutate(deletePasskeyId)
|
||||
setDeletePasskeyId(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleteCancel = () => {
|
||||
setDeletePasskeyId(null)
|
||||
}
|
||||
|
||||
const handleChangePassword = () => {
|
||||
setError(null)
|
||||
setSuccess(null)
|
||||
@@ -343,6 +354,16 @@ export function AccountSettings() {
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<DeleteDialog
|
||||
open={deletePasskeyId !== null}
|
||||
onOpenChange={(open) => !open && setDeletePasskeyId(null)}
|
||||
onConfirm={handleDeleteConfirm}
|
||||
onCancel={handleDeleteCancel}
|
||||
title="Delete Passkey"
|
||||
description="Are you sure you want to delete this passkey? This action cannot be undone."
|
||||
isDeleting={deletePasskeyMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { Loader2, Check, X, Shield, ChevronDown, ChevronRight, Key, Search, Pencil, Trash2 } from 'lucide-react'
|
||||
import { providerCredentialsApi, getProviders } from '@/api/providers'
|
||||
import type { Provider } from '@/api/providers'
|
||||
@@ -23,6 +24,7 @@ export function ProviderSettings() {
|
||||
const [apiKeyDialogOpen, setApiKeyDialogOpen] = useState(false)
|
||||
const [apiKeyProvider, setApiKeyProvider] = useState<Provider | null>(null)
|
||||
const [apiKeyMode, setApiKeyMode] = useState<'add' | 'edit'>('add')
|
||||
const [deleteTarget, setDeleteTarget] = useState<string | null>(null)
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const { data: providersData, isLoading: providersLoading } = useQuery({
|
||||
@@ -53,11 +55,20 @@ export function ProviderSettings() {
|
||||
})
|
||||
|
||||
const handleDeleteCredential = (providerId: string) => {
|
||||
if (confirm(`Remove credentials for ${providerId}?`)) {
|
||||
deleteCredentialMutation.mutate(providerId)
|
||||
setDeleteTarget(providerId)
|
||||
}
|
||||
|
||||
const handleDeleteConfirm = () => {
|
||||
if (deleteTarget) {
|
||||
deleteCredentialMutation.mutate(deleteTarget)
|
||||
setDeleteTarget(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleteCancel = () => {
|
||||
setDeleteTarget(null)
|
||||
}
|
||||
|
||||
const handleOAuthAuthorize = (response: OAuthAuthorizeResponse) => {
|
||||
setOauthResponse(response)
|
||||
setOauthDialogOpen(false)
|
||||
@@ -418,6 +429,16 @@ export function ProviderSettings() {
|
||||
mode={apiKeyMode}
|
||||
/>
|
||||
)}
|
||||
|
||||
<DeleteDialog
|
||||
open={deleteTarget !== null}
|
||||
onOpenChange={(open) => !open && setDeleteTarget(null)}
|
||||
onConfirm={handleDeleteConfirm}
|
||||
onCancel={handleDeleteCancel}
|
||||
title="Remove Credentials"
|
||||
description={`Are you sure you want to remove credentials for ${deleteTarget || 'this provider'}?`}
|
||||
isDeleting={deleteCredentialMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,53 +1,41 @@
|
||||
import { useState } from 'react'
|
||||
import { useGitStatus, getApiErrorMessage } from '@/api/git'
|
||||
import { useGitStatus } from '@/api/git'
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { GitFlatFileList } from './GitFlatFileList'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
|
||||
import { FileDiffView } from '@/components/file-browser/FileDiffView'
|
||||
import { Loader2, GitCommit, FileText, AlertCircle, X } from 'lucide-react'
|
||||
import { Loader2, GitCommit, FileText, AlertCircle } from 'lucide-react'
|
||||
|
||||
interface ChangesTabProps {
|
||||
repoId: number
|
||||
onFileSelect: (path: string, staged: boolean) => void
|
||||
selectedFile?: {path: string, staged: boolean}
|
||||
isMobile: boolean
|
||||
onError?: (error: unknown) => void
|
||||
}
|
||||
|
||||
export function ChangesTab({ repoId, onFileSelect, selectedFile, isMobile }: ChangesTabProps) {
|
||||
export function ChangesTab({ repoId, onFileSelect, selectedFile, isMobile, onError }: ChangesTabProps) {
|
||||
const { data: status, isLoading, error } = useGitStatus(repoId)
|
||||
const git = useGit(repoId)
|
||||
const git = useGit(repoId, onError)
|
||||
const [commitMessage, setCommitMessage] = useState('')
|
||||
const [apiError, setApiError] = useState<string | null>(null)
|
||||
|
||||
const stagedFiles = status?.files.filter(f => f.staged) || []
|
||||
const unstagedFiles = status?.files.filter(f => !f.staged) || []
|
||||
const canCommit = commitMessage.trim() && stagedFiles.length > 0 && !git.commit.isPending
|
||||
|
||||
const handleGitAction = async (action: () => Promise<unknown>) => {
|
||||
try {
|
||||
setApiError(null)
|
||||
await action()
|
||||
} catch (error: unknown) {
|
||||
const message = getApiErrorMessage(error)
|
||||
setApiError(message)
|
||||
}
|
||||
}
|
||||
|
||||
const handleStage = (paths: string[]) => {
|
||||
handleGitAction(() => git.stageFiles.mutateAsync(paths))
|
||||
git.stageFiles.mutate(paths)
|
||||
}
|
||||
|
||||
const handleUnstage = (paths: string[]) => {
|
||||
handleGitAction(() => git.unstageFiles.mutateAsync(paths))
|
||||
git.unstageFiles.mutate(paths)
|
||||
}
|
||||
|
||||
const handleCommit = () => {
|
||||
handleGitAction(async () => {
|
||||
await git.commit.mutateAsync({ message: commitMessage.trim() })
|
||||
setCommitMessage('')
|
||||
})
|
||||
git.commit.mutate({ message: commitMessage.trim() })
|
||||
setCommitMessage('')
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
@@ -73,16 +61,6 @@ export function ChangesTab({ repoId, onFileSelect, selectedFile, isMobile }: Cha
|
||||
if (isMobile && selectedFile) {
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{apiError && (
|
||||
<div className="mx-3 mt-3 p-2 rounded border bg-destructive/10 border-destructive/20 flex items-center gap-2">
|
||||
<AlertCircle className="w-4 h-4 text-destructive flex-shrink-0" />
|
||||
<span className="text-sm text-destructive flex-1">{apiError}</span>
|
||||
<Button variant="ghost" size="sm" className="h-6 w-6 p-0" onClick={() => setApiError(null)}>
|
||||
<X className="w-3 h-3" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Tabs defaultValue="files" className="flex flex-col h-full">
|
||||
<TabsList className="flex-shrink-0">
|
||||
<TabsTrigger value="files">Files ({stagedFiles.length + unstagedFiles.length})</TabsTrigger>
|
||||
@@ -164,16 +142,6 @@ export function ChangesTab({ repoId, onFileSelect, selectedFile, isMobile }: Cha
|
||||
} else {
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{apiError && (
|
||||
<div className="mx-3 mt-3 p-2 rounded border bg-destructive/10 border-destructive/20 flex items-center gap-2">
|
||||
<AlertCircle className="w-4 h-4 text-destructive flex-shrink-0" />
|
||||
<span className="text-sm text-destructive flex-1">{apiError}</span>
|
||||
<Button variant="ghost" size="sm" className="h-6 w-6 p-0" onClick={() => setApiError(null)}>
|
||||
<X className="w-3 h-3" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 overflow-y-auto p-3 space-y-4">
|
||||
{status.hasChanges ? (
|
||||
<>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { AlertCircle, X } from 'lucide-react'
|
||||
|
||||
interface GitErrorBannerProps {
|
||||
error: { summary: string; detail?: string }
|
||||
onDismiss: () => void
|
||||
}
|
||||
|
||||
export function GitErrorBanner({ error, onDismiss }: GitErrorBannerProps) {
|
||||
return (
|
||||
<Alert variant="destructive" className="mb-0 p-3 sm:p-4 [&>svg]:hidden [&>svg~*]:pl-0">
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-start gap-2">
|
||||
<AlertCircle className="h-4 w-4 mt-0.5 flex-shrink-0" />
|
||||
<AlertDescription className="flex-1 min-w-0 text-sm">{error.summary}</AlertDescription>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 w-7 p-0 flex-shrink-0"
|
||||
onClick={onDismiss}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
{error.detail && (
|
||||
<pre className="p-2 rounded border bg-destructive/5 border-destructive/20 text-xs font-mono overflow-auto max-h-32">
|
||||
{error.detail}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import { useState } from 'react'
|
||||
import { FetchError } from '@opencode-manager/shared'
|
||||
import { useGitStatus, getApiErrorMessage } from '@/api/git'
|
||||
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { ChangesTab } from './ChangesTab'
|
||||
import { CommitsTab } from './CommitsTab'
|
||||
import { BranchesTab } from './BranchesTab'
|
||||
import { GitErrorBanner } from './GitErrorBanner'
|
||||
import { FileDiffView } from '@/components/file-browser/FileDiffView'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
@@ -23,7 +25,6 @@ import {
|
||||
} from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
interface SourceControlPanelProps {
|
||||
repoId: number
|
||||
@@ -48,15 +49,26 @@ export function SourceControlPanel({
|
||||
}: SourceControlPanelProps) {
|
||||
const [activeTab, setActiveTab] = useState<Tab>('changes')
|
||||
const [selectedFile, setSelectedFile] = useState<{path: string, staged: boolean} | undefined>()
|
||||
const [gitError, setGitError] = useState<{ summary: string; detail?: string } | null>(null)
|
||||
const { data: status } = useGitStatus(repoId)
|
||||
const git = useGit(repoId)
|
||||
const isMobile = useMobile()
|
||||
|
||||
const handleGitError = (error: unknown) => {
|
||||
if (error instanceof FetchError) {
|
||||
setGitError({ summary: getApiErrorMessage(error), detail: error.detail })
|
||||
} else {
|
||||
setGitError({ summary: getApiErrorMessage(error) })
|
||||
}
|
||||
}
|
||||
|
||||
const git = useGit(repoId, handleGitError)
|
||||
|
||||
const handleGitAction = async (action: () => Promise<unknown>) => {
|
||||
try {
|
||||
setGitError(null)
|
||||
await action()
|
||||
} catch (error: unknown) {
|
||||
const message = getApiErrorMessage(error)
|
||||
showToast.error(message)
|
||||
} catch {
|
||||
// error already handled by useGit's onError -> handleGitError
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +150,10 @@ export function SourceControlPanel({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{gitError && (
|
||||
<GitErrorBanner error={gitError} onDismiss={() => setGitError(null)} />
|
||||
)}
|
||||
|
||||
<div className="flex border-b border-border flex-shrink-0">
|
||||
{tabs.map((tab) => {
|
||||
const Icon = tab.icon
|
||||
@@ -175,6 +191,7 @@ export function SourceControlPanel({
|
||||
onFileSelect={(path, staged) => setSelectedFile({ path, staged })}
|
||||
selectedFile={selectedFile}
|
||||
isMobile={isMobile}
|
||||
onError={handleGitError}
|
||||
/>
|
||||
)}
|
||||
{activeTab === 'commits' && (
|
||||
|
||||
Reference in new issue
Block a user