mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-03-21 04:43:09 +00:00
Compare commits
7 Commits
b0490be501
...
9eb08d3f71
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9eb08d3f71 | ||
|
|
8d76deb75f | ||
|
|
3a31761542 | ||
|
|
96feb38aea | ||
|
|
1925818d49 | ||
|
|
38fc8788a2 | ||
|
|
b439e2d241 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "autoforge-ai",
|
||||
"version": "0.1.8",
|
||||
"version": "0.1.9",
|
||||
"description": "Autonomous coding agent with web UI - build complete apps with AI",
|
||||
"license": "AGPL-3.0",
|
||||
"bin": {
|
||||
|
||||
47
ui/e2e/tooltip.spec.ts
Normal file
47
ui/e2e/tooltip.spec.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
/**
|
||||
* E2E tooltip tests for header icon buttons.
|
||||
*
|
||||
* Run tests:
|
||||
* cd ui && npm run test:e2e
|
||||
* cd ui && npm run test:e2e -- tooltip.spec.ts
|
||||
*/
|
||||
test.describe('Header tooltips', () => {
|
||||
test.setTimeout(30000)
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/')
|
||||
await page.waitForSelector('button:has-text("Select Project")', { timeout: 10000 })
|
||||
})
|
||||
|
||||
async function selectProject(page: import('@playwright/test').Page) {
|
||||
const projectSelector = page.locator('button:has-text("Select Project")')
|
||||
if (await projectSelector.isVisible()) {
|
||||
await projectSelector.click()
|
||||
const items = page.locator('.neo-dropdown-item')
|
||||
const itemCount = await items.count()
|
||||
if (itemCount === 0) return false
|
||||
await items.first().click()
|
||||
await expect(projectSelector).not.toBeVisible({ timeout: 5000 }).catch(() => {})
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
test('Settings tooltip shows on hover', async ({ page }) => {
|
||||
const hasProject = await selectProject(page)
|
||||
if (!hasProject) {
|
||||
test.skip(true, 'No projects available')
|
||||
return
|
||||
}
|
||||
|
||||
const settingsButton = page.locator('button[aria-label="Open Settings"]')
|
||||
await expect(settingsButton).toBeVisible()
|
||||
|
||||
await settingsButton.hover()
|
||||
|
||||
const tooltip = page.locator('[data-slot="tooltip-content"]', { hasText: 'Settings' })
|
||||
await expect(tooltip).toBeVisible({ timeout: 2000 })
|
||||
})
|
||||
})
|
||||
78
ui/package-lock.json
generated
78
ui/package-lock.json
generated
@@ -15,6 +15,7 @@
|
||||
"@radix-ui/react-separator": "^1.1.8",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@radix-ui/react-switch": "^1.2.6",
|
||||
"@radix-ui/react-tooltip": "^1.2.8",
|
||||
"@tanstack/react-query": "^5.72.0",
|
||||
"@xterm/addon-fit": "^0.11.0",
|
||||
"@xterm/addon-web-links": "^0.12.0",
|
||||
@@ -55,7 +56,7 @@
|
||||
},
|
||||
"..": {
|
||||
"name": "autoforge-ai",
|
||||
"version": "0.1.8",
|
||||
"version": "0.1.9",
|
||||
"license": "AGPL-3.0",
|
||||
"bin": {
|
||||
"autoforge": "bin/autoforge.js"
|
||||
@@ -1765,6 +1766,58 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-tooltip": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.2.8.tgz",
|
||||
"integrity": "sha512-tY7sVt1yL9ozIxvmbtN5qtmH2krXcBCfjEiCgKGLqunJHvgvZG2Pcl2oQ3kbcZARb1BGEHdkLzcYGO8ynVlieg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/primitive": "1.1.3",
|
||||
"@radix-ui/react-compose-refs": "1.1.2",
|
||||
"@radix-ui/react-context": "1.1.2",
|
||||
"@radix-ui/react-dismissable-layer": "1.1.11",
|
||||
"@radix-ui/react-id": "1.1.1",
|
||||
"@radix-ui/react-popper": "1.2.8",
|
||||
"@radix-ui/react-portal": "1.1.9",
|
||||
"@radix-ui/react-presence": "1.1.5",
|
||||
"@radix-ui/react-primitive": "2.1.3",
|
||||
"@radix-ui/react-slot": "1.2.3",
|
||||
"@radix-ui/react-use-controllable-state": "1.2.2",
|
||||
"@radix-ui/react-visually-hidden": "1.2.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-dom": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-slot": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.3.tgz",
|
||||
"integrity": "sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/react-compose-refs": "1.1.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-use-callback-ref": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.1.1.tgz",
|
||||
@@ -1901,6 +1954,29 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-visually-hidden": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-visually-hidden/-/react-visually-hidden-1.2.3.tgz",
|
||||
"integrity": "sha512-pzJq12tEaaIhqjbzpCuv/OypJY/BPavOofm+dbab+MHLajy277+1lLm6JFcGgF5eskJ6mquGirhXY2GD/8u8Ug==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/react-primitive": "2.1.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-dom": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/rect": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/rect/-/rect-1.1.1.tgz",
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"@radix-ui/react-separator": "^1.1.8",
|
||||
"@radix-ui/react-slot": "^1.2.4",
|
||||
"@radix-ui/react-switch": "^1.2.6",
|
||||
"@radix-ui/react-tooltip": "^1.2.8",
|
||||
"@tanstack/react-query": "^5.72.0",
|
||||
"@xterm/addon-fit": "^0.11.0",
|
||||
"@xterm/addon-web-links": "^0.12.0",
|
||||
|
||||
196
ui/src/App.tsx
196
ui/src/App.tsx
@@ -33,6 +33,7 @@ import type { Feature } from './lib/types'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip'
|
||||
|
||||
const STORAGE_KEY = 'autoforge-selected-project'
|
||||
const VIEW_MODE_KEY = 'autoforge-view-mode'
|
||||
@@ -260,18 +261,19 @@ function App() {
|
||||
<div className="min-h-screen bg-background">
|
||||
{/* Header */}
|
||||
<header className="sticky top-0 z-50 bg-card/80 backdrop-blur-md text-foreground border-b-2 border-border">
|
||||
<div className="max-w-7xl mx-auto px-4 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
{/* Logo and Title */}
|
||||
<div className="max-w-7xl mx-auto px-4 py-3">
|
||||
<TooltipProvider>
|
||||
{/* Row 1: Branding + Project + Utility icons */}
|
||||
<div className="flex items-center gap-3">
|
||||
<img src="/logo.png" alt="AutoForge" className="h-9 w-9 rounded-full" />
|
||||
<h1 className="font-display text-2xl font-bold tracking-tight uppercase">
|
||||
AutoForge
|
||||
</h1>
|
||||
</div>
|
||||
{/* Logo and Title */}
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
<img src="/logo.png" alt="AutoForge" className="h-9 w-9 rounded-full" />
|
||||
<h1 className="font-display text-2xl font-bold tracking-tight uppercase hidden md:block">
|
||||
AutoForge
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Controls */}
|
||||
<div className="flex items-center gap-4">
|
||||
{/* Project selector */}
|
||||
<ProjectSelector
|
||||
projects={projects ?? []}
|
||||
selectedProject={selectedProject}
|
||||
@@ -280,94 +282,114 @@ function App() {
|
||||
onSpecCreatingChange={setIsSpecCreating}
|
||||
/>
|
||||
|
||||
{selectedProject && (
|
||||
<>
|
||||
<AgentControl
|
||||
projectName={selectedProject}
|
||||
status={wsState.agentStatus}
|
||||
defaultConcurrency={selectedProjectData?.default_concurrency}
|
||||
/>
|
||||
{/* Spacer */}
|
||||
<div className="flex-1" />
|
||||
|
||||
<DevServerControl
|
||||
projectName={selectedProject}
|
||||
status={wsState.devServerStatus}
|
||||
url={wsState.devServerUrl}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onClick={() => setShowSettings(true)}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title="Settings (,)"
|
||||
aria-label="Open Settings"
|
||||
>
|
||||
<Settings size={18} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={() => setShowResetModal(true)}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title="Reset Project (R)"
|
||||
aria-label="Reset Project"
|
||||
disabled={wsState.agentStatus === 'running'}
|
||||
>
|
||||
<RotateCcw size={18} />
|
||||
</Button>
|
||||
|
||||
{/* Ollama Mode Indicator */}
|
||||
{settings?.ollama_mode && (
|
||||
<div
|
||||
className="flex items-center gap-1.5 px-2 py-1 bg-card rounded border-2 border-border shadow-sm"
|
||||
title="Using Ollama local models"
|
||||
>
|
||||
<img src="/ollama.png" alt="Ollama" className="w-5 h-5" />
|
||||
<span className="text-xs font-bold text-foreground">Ollama</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* GLM Mode Badge */}
|
||||
{settings?.glm_mode && (
|
||||
<Badge
|
||||
className="bg-purple-500 text-white hover:bg-purple-600"
|
||||
title="Using GLM API"
|
||||
>
|
||||
GLM
|
||||
</Badge>
|
||||
)}
|
||||
</>
|
||||
{/* Ollama Mode Indicator */}
|
||||
{selectedProject && settings?.ollama_mode && (
|
||||
<div
|
||||
className="hidden sm:flex items-center gap-1.5 px-2 py-1 bg-card rounded border-2 border-border shadow-sm"
|
||||
title="Using Ollama local models"
|
||||
>
|
||||
<img src="/ollama.png" alt="Ollama" className="w-5 h-5" />
|
||||
<span className="text-xs font-bold text-foreground">Ollama</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Docs link */}
|
||||
<Button
|
||||
onClick={() => window.open('https://autoforge.cc', '_blank')}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title="Documentation"
|
||||
aria-label="Open Documentation"
|
||||
>
|
||||
<BookOpen size={18} />
|
||||
</Button>
|
||||
{/* GLM Mode Badge */}
|
||||
{selectedProject && settings?.glm_mode && (
|
||||
<Badge
|
||||
className="hidden sm:inline-flex bg-purple-500 text-white hover:bg-purple-600"
|
||||
title="Using GLM API"
|
||||
>
|
||||
GLM
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
{/* Utility icons - always visible */}
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
onClick={() => window.open('https://autoforge.cc', '_blank')}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-label="Open Documentation"
|
||||
>
|
||||
<BookOpen size={18} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Docs</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
{/* Theme selector */}
|
||||
<ThemeSelector
|
||||
themes={themes}
|
||||
currentTheme={theme}
|
||||
onThemeChange={setTheme}
|
||||
/>
|
||||
|
||||
{/* Dark mode toggle - always visible */}
|
||||
<Button
|
||||
onClick={toggleDarkMode}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title="Toggle dark mode"
|
||||
aria-label="Toggle dark mode"
|
||||
>
|
||||
{darkMode ? <Sun size={18} /> : <Moon size={18} />}
|
||||
</Button>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
onClick={toggleDarkMode}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-label="Toggle dark mode"
|
||||
>
|
||||
{darkMode ? <Sun size={18} /> : <Moon size={18} />}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Toggle theme</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Row 2: Project controls - only when a project is selected */}
|
||||
{selectedProject && (
|
||||
<div className="flex items-center gap-3 mt-2 pt-2 border-t border-border/50">
|
||||
<AgentControl
|
||||
projectName={selectedProject}
|
||||
status={wsState.agentStatus}
|
||||
defaultConcurrency={selectedProjectData?.default_concurrency}
|
||||
/>
|
||||
|
||||
<DevServerControl
|
||||
projectName={selectedProject}
|
||||
status={wsState.devServerStatus}
|
||||
url={wsState.devServerUrl}
|
||||
/>
|
||||
|
||||
<div className="flex-1" />
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
onClick={() => setShowSettings(true)}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-label="Open Settings"
|
||||
>
|
||||
<Settings size={18} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Settings (,)</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
onClick={() => setShowResetModal(true)}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-label="Reset Project"
|
||||
disabled={wsState.agentStatus === 'running'}
|
||||
>
|
||||
<RotateCcw size={18} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Reset (R)</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
)}
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ export function AgentControl({ projectName, status, defaultConcurrency = 3 }: Ag
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="flex items-center gap-2 sm:gap-4">
|
||||
{/* Concurrency slider - visible when stopped */}
|
||||
{isStopped && (
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Manages conversation state with localStorage persistence.
|
||||
*/
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useState, useEffect, useCallback, useRef } from 'react'
|
||||
import { X, Bot } from 'lucide-react'
|
||||
import { AssistantChat } from './AssistantChat'
|
||||
import { useConversation } from '../hooks/useConversations'
|
||||
@@ -20,6 +20,10 @@ interface AssistantPanelProps {
|
||||
}
|
||||
|
||||
const STORAGE_KEY_PREFIX = 'assistant-conversation-'
|
||||
const WIDTH_STORAGE_KEY = 'assistant-panel-width'
|
||||
const DEFAULT_WIDTH = 400
|
||||
const MIN_WIDTH = 300
|
||||
const MAX_WIDTH_VW = 90
|
||||
|
||||
function getStoredConversationId(projectName: string): number | null {
|
||||
try {
|
||||
@@ -100,6 +104,49 @@ export function AssistantPanel({ projectName, isOpen, onClose }: AssistantPanelP
|
||||
setConversationId(id)
|
||||
}, [])
|
||||
|
||||
// Resizable panel width
|
||||
const [panelWidth, setPanelWidth] = useState<number>(() => {
|
||||
try {
|
||||
const stored = localStorage.getItem(WIDTH_STORAGE_KEY)
|
||||
if (stored) return Math.max(MIN_WIDTH, parseInt(stored, 10))
|
||||
} catch { /* ignore */ }
|
||||
return DEFAULT_WIDTH
|
||||
})
|
||||
const isResizing = useRef(false)
|
||||
|
||||
const handleMouseDown = useCallback((e: React.MouseEvent) => {
|
||||
e.preventDefault()
|
||||
isResizing.current = true
|
||||
const startX = e.clientX
|
||||
const startWidth = panelWidth
|
||||
const maxWidth = window.innerWidth * (MAX_WIDTH_VW / 100)
|
||||
|
||||
const handleMouseMove = (e: MouseEvent) => {
|
||||
if (!isResizing.current) return
|
||||
const delta = startX - e.clientX
|
||||
const newWidth = Math.min(maxWidth, Math.max(MIN_WIDTH, startWidth + delta))
|
||||
setPanelWidth(newWidth)
|
||||
}
|
||||
|
||||
const handleMouseUp = () => {
|
||||
isResizing.current = false
|
||||
document.removeEventListener('mousemove', handleMouseMove)
|
||||
document.removeEventListener('mouseup', handleMouseUp)
|
||||
document.body.style.cursor = ''
|
||||
document.body.style.userSelect = ''
|
||||
// Persist width
|
||||
setPanelWidth((w) => {
|
||||
localStorage.setItem(WIDTH_STORAGE_KEY, String(w))
|
||||
return w
|
||||
})
|
||||
}
|
||||
|
||||
document.body.style.cursor = 'col-resize'
|
||||
document.body.style.userSelect = 'none'
|
||||
document.addEventListener('mousemove', handleMouseMove)
|
||||
document.addEventListener('mouseup', handleMouseUp)
|
||||
}, [panelWidth])
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Backdrop - click to close */}
|
||||
@@ -115,17 +162,25 @@ export function AssistantPanel({ projectName, isOpen, onClose }: AssistantPanelP
|
||||
<div
|
||||
className={`
|
||||
fixed right-0 top-0 bottom-0 z-50
|
||||
w-[400px] max-w-[90vw]
|
||||
bg-card
|
||||
border-l border-border
|
||||
transform transition-transform duration-300 ease-out
|
||||
flex flex-col shadow-xl
|
||||
${isOpen ? 'translate-x-0' : 'translate-x-full'}
|
||||
`}
|
||||
style={{ width: `${panelWidth}px`, maxWidth: `${MAX_WIDTH_VW}vw` }}
|
||||
role="dialog"
|
||||
aria-label="Project Assistant"
|
||||
aria-hidden={!isOpen}
|
||||
>
|
||||
{/* Resize handle */}
|
||||
<div
|
||||
className="absolute left-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group"
|
||||
onMouseDown={handleMouseDown}
|
||||
>
|
||||
<div className="absolute inset-y-0 left-0 w-0.5 bg-border group-hover:bg-primary transition-colors" />
|
||||
</div>
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-border bg-primary text-primary-foreground">
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
182
ui/src/components/DevServerConfigDialog.tsx
Normal file
182
ui/src/components/DevServerConfigDialog.tsx
Normal file
@@ -0,0 +1,182 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Loader2, RotateCcw, Terminal } from 'lucide-react'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { useDevServerConfig, useUpdateDevServerConfig } from '@/hooks/useProjects'
|
||||
import { startDevServer } from '@/lib/api'
|
||||
|
||||
interface DevServerConfigDialogProps {
|
||||
projectName: string
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
autoStartOnSave?: boolean
|
||||
}
|
||||
|
||||
export function DevServerConfigDialog({
|
||||
projectName,
|
||||
isOpen,
|
||||
onClose,
|
||||
autoStartOnSave = false,
|
||||
}: DevServerConfigDialogProps) {
|
||||
const { data: config } = useDevServerConfig(isOpen ? projectName : null)
|
||||
const updateConfig = useUpdateDevServerConfig(projectName)
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const [command, setCommand] = useState('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [isSaving, setIsSaving] = useState(false)
|
||||
|
||||
// Sync input with config when dialog opens or config loads
|
||||
useEffect(() => {
|
||||
if (isOpen && config) {
|
||||
setCommand(config.custom_command ?? config.effective_command ?? '')
|
||||
setError(null)
|
||||
}
|
||||
}, [isOpen, config])
|
||||
|
||||
const hasCustomCommand = !!config?.custom_command
|
||||
|
||||
const handleSaveAndStart = async () => {
|
||||
const trimmed = command.trim()
|
||||
if (!trimmed) {
|
||||
setError('Please enter a dev server command.')
|
||||
return
|
||||
}
|
||||
|
||||
setIsSaving(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
await updateConfig.mutateAsync(trimmed)
|
||||
|
||||
if (autoStartOnSave) {
|
||||
await startDevServer(projectName)
|
||||
queryClient.invalidateQueries({ queryKey: ['dev-server-status', projectName] })
|
||||
}
|
||||
|
||||
onClose()
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to save configuration')
|
||||
} finally {
|
||||
setIsSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClear = async () => {
|
||||
setIsSaving(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
await updateConfig.mutateAsync(null)
|
||||
setCommand(config?.detected_command ?? '')
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to clear configuration')
|
||||
} finally {
|
||||
setIsSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-primary/10 text-primary">
|
||||
<Terminal size={20} />
|
||||
</div>
|
||||
<DialogTitle>Dev Server Configuration</DialogTitle>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
<DialogDescription asChild>
|
||||
<div className="space-y-4">
|
||||
{/* Detection info */}
|
||||
<div className="rounded-lg border-2 border-border bg-muted/50 p-3 text-sm">
|
||||
{config?.detected_type ? (
|
||||
<p>
|
||||
Detected project type: <strong className="text-foreground">{config.detected_type}</strong>
|
||||
{config.detected_command && (
|
||||
<span className="text-muted-foreground"> — {config.detected_command}</span>
|
||||
)}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-muted-foreground">
|
||||
No project type detected. Enter a custom command below.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Command input */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="dev-command" className="text-foreground">Dev server command</Label>
|
||||
<Input
|
||||
id="dev-command"
|
||||
value={command}
|
||||
onChange={(e) => {
|
||||
setCommand(e.target.value)
|
||||
setError(null)
|
||||
}}
|
||||
placeholder="npm run dev"
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && !isSaving) {
|
||||
handleSaveAndStart()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Allowed runners: npm, npx, pnpm, yarn, python, uvicorn, flask, poetry, cargo, go
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Clear custom command button */}
|
||||
{hasCustomCommand && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleClear}
|
||||
disabled={isSaving}
|
||||
className="gap-1.5"
|
||||
>
|
||||
<RotateCcw size={14} />
|
||||
Clear custom command (use auto-detection)
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Error display */}
|
||||
{error && (
|
||||
<p className="text-sm font-mono text-destructive">{error}</p>
|
||||
)}
|
||||
</div>
|
||||
</DialogDescription>
|
||||
|
||||
<DialogFooter className="gap-2 sm:gap-0">
|
||||
<Button variant="outline" onClick={onClose} disabled={isSaving}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleSaveAndStart} disabled={isSaving}>
|
||||
{isSaving ? (
|
||||
<>
|
||||
<Loader2 size={16} className="animate-spin mr-1.5" />
|
||||
Saving...
|
||||
</>
|
||||
) : autoStartOnSave ? (
|
||||
'Save & Start'
|
||||
) : (
|
||||
'Save'
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Globe, Square, Loader2, ExternalLink, AlertTriangle } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Globe, Square, Loader2, ExternalLink, AlertTriangle, Settings2 } from 'lucide-react'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import type { DevServerStatus } from '../lib/types'
|
||||
import { startDevServer, stopDevServer } from '../lib/api'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DevServerConfigDialog } from './DevServerConfigDialog'
|
||||
|
||||
// Re-export DevServerStatus from lib/types for consumers that import from here
|
||||
export type { DevServerStatus }
|
||||
@@ -59,17 +61,27 @@ interface DevServerControlProps {
|
||||
* - Shows loading state during operations
|
||||
* - Displays clickable URL when server is running
|
||||
* - Uses neobrutalism design with cyan accent when running
|
||||
* - Config dialog for setting custom dev commands
|
||||
*/
|
||||
export function DevServerControl({ projectName, status, url }: DevServerControlProps) {
|
||||
const startDevServerMutation = useStartDevServer(projectName)
|
||||
const stopDevServerMutation = useStopDevServer(projectName)
|
||||
const [showConfigDialog, setShowConfigDialog] = useState(false)
|
||||
const [autoStartOnSave, setAutoStartOnSave] = useState(false)
|
||||
|
||||
const isLoading = startDevServerMutation.isPending || stopDevServerMutation.isPending
|
||||
|
||||
const handleStart = () => {
|
||||
// Clear any previous errors before starting
|
||||
stopDevServerMutation.reset()
|
||||
startDevServerMutation.mutate()
|
||||
startDevServerMutation.mutate(undefined, {
|
||||
onError: (err) => {
|
||||
if (err.message?.includes('No dev command available')) {
|
||||
setAutoStartOnSave(true)
|
||||
setShowConfigDialog(true)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
const handleStop = () => {
|
||||
// Clear any previous errors before stopping
|
||||
@@ -77,6 +89,19 @@ export function DevServerControl({ projectName, status, url }: DevServerControlP
|
||||
stopDevServerMutation.mutate()
|
||||
}
|
||||
|
||||
const handleOpenConfig = () => {
|
||||
setAutoStartOnSave(false)
|
||||
setShowConfigDialog(true)
|
||||
}
|
||||
|
||||
const handleCloseConfig = () => {
|
||||
setShowConfigDialog(false)
|
||||
// Clear the start error if config dialog was opened reactively
|
||||
if (startDevServerMutation.error?.message?.includes('No dev command available')) {
|
||||
startDevServerMutation.reset()
|
||||
}
|
||||
}
|
||||
|
||||
// Server is stopped when status is 'stopped' or 'crashed' (can restart)
|
||||
const isStopped = status === 'stopped' || status === 'crashed'
|
||||
// Server is in a running state
|
||||
@@ -84,25 +109,40 @@ export function DevServerControl({ projectName, status, url }: DevServerControlP
|
||||
// Server has crashed
|
||||
const isCrashed = status === 'crashed'
|
||||
|
||||
// Hide inline error when config dialog is handling it
|
||||
const startError = startDevServerMutation.error
|
||||
const showInlineError = startError && !startError.message?.includes('No dev command available')
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
{isStopped ? (
|
||||
<Button
|
||||
onClick={handleStart}
|
||||
disabled={isLoading}
|
||||
variant={isCrashed ? "destructive" : "outline"}
|
||||
size="sm"
|
||||
title={isCrashed ? "Dev Server Crashed - Click to Restart" : "Start Dev Server"}
|
||||
aria-label={isCrashed ? "Restart Dev Server (crashed)" : "Start Dev Server"}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Loader2 size={18} className="animate-spin" />
|
||||
) : isCrashed ? (
|
||||
<AlertTriangle size={18} />
|
||||
) : (
|
||||
<Globe size={18} />
|
||||
)}
|
||||
</Button>
|
||||
<>
|
||||
<Button
|
||||
onClick={handleStart}
|
||||
disabled={isLoading}
|
||||
variant={isCrashed ? "destructive" : "outline"}
|
||||
size="sm"
|
||||
title={isCrashed ? "Dev Server Crashed - Click to Restart" : "Start Dev Server"}
|
||||
aria-label={isCrashed ? "Restart Dev Server (crashed)" : "Start Dev Server"}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Loader2 size={18} className="animate-spin" />
|
||||
) : isCrashed ? (
|
||||
<AlertTriangle size={18} />
|
||||
) : (
|
||||
<Globe size={18} />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleOpenConfig}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
title="Configure Dev Server"
|
||||
aria-label="Configure Dev Server"
|
||||
>
|
||||
<Settings2 size={16} />
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button
|
||||
onClick={handleStop}
|
||||
@@ -139,12 +179,20 @@ export function DevServerControl({ projectName, status, url }: DevServerControlP
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Error display */}
|
||||
{(startDevServerMutation.error || stopDevServerMutation.error) && (
|
||||
{/* Error display (hide "no dev command" error when config dialog handles it) */}
|
||||
{(showInlineError || stopDevServerMutation.error) && (
|
||||
<span className="text-xs font-mono text-destructive ml-2">
|
||||
{String((startDevServerMutation.error || stopDevServerMutation.error)?.message || 'Operation failed')}
|
||||
{String((showInlineError ? startError : stopDevServerMutation.error)?.message || 'Operation failed')}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Dev Server Config Dialog */}
|
||||
<DevServerConfigDialog
|
||||
projectName={projectName}
|
||||
isOpen={showConfigDialog}
|
||||
onClose={handleCloseConfig}
|
||||
autoStartOnSave={autoStartOnSave}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -73,16 +73,16 @@ export function ProjectSelector({
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="min-w-[200px] justify-between"
|
||||
className="min-w-[140px] sm:min-w-[200px] justify-between"
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading ? (
|
||||
<Loader2 size={18} className="animate-spin" />
|
||||
) : selectedProject ? (
|
||||
<>
|
||||
<span className="flex items-center gap-2">
|
||||
<FolderOpen size={18} />
|
||||
{selectedProject}
|
||||
<span className="flex items-center gap-2 truncate">
|
||||
<FolderOpen size={18} className="shrink-0" />
|
||||
<span className="truncate">{selectedProject}</span>
|
||||
</span>
|
||||
{selectedProjectData && selectedProjectData.stats.total > 0 && (
|
||||
<Badge className="ml-2">{selectedProjectData.stats.percentage}%</Badge>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import { Palette, Check } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip'
|
||||
import type { ThemeId, ThemeOption } from '../hooks/useTheme'
|
||||
|
||||
interface ThemeSelectorProps {
|
||||
@@ -97,16 +98,20 @@ export function ThemeSelector({ themes, currentTheme, onThemeChange }: ThemeSele
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title="Theme"
|
||||
aria-label="Select theme"
|
||||
aria-expanded={isOpen}
|
||||
aria-haspopup="true"
|
||||
>
|
||||
<Palette size={18} />
|
||||
</Button>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-label="Select theme"
|
||||
aria-expanded={isOpen}
|
||||
aria-haspopup="true"
|
||||
>
|
||||
<Palette size={18} />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Theme</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
{/* Dropdown */}
|
||||
{isOpen && (
|
||||
|
||||
65
ui/src/components/ui/tooltip.tsx
Normal file
65
ui/src/components/ui/tooltip.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as React from "react"
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function TooltipProvider({
|
||||
delayDuration = 250,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Provider> & {
|
||||
delayDuration?: number
|
||||
}) {
|
||||
return (
|
||||
<TooltipPrimitive.Provider
|
||||
data-slot="tooltip-provider"
|
||||
delayDuration={delayDuration}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function Tooltip({
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
||||
return <TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||
}
|
||||
|
||||
function TooltipTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
||||
}
|
||||
|
||||
function TooltipContent({
|
||||
className,
|
||||
side = "bottom",
|
||||
align = "center",
|
||||
sideOffset = 8,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
||||
return (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
data-slot="tooltip-content"
|
||||
side={side}
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 overflow-hidden rounded-md border bg-neutral-900 px-3 py-2 text-sm text-white shadow-md leading-tight min-h-7",
|
||||
"data-[state=delayed-open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=delayed-open]:fade-in-0 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<TooltipPrimitive.Arrow
|
||||
data-slot="tooltip-arrow"
|
||||
className="fill-neutral-900"
|
||||
/>
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import * as api from '../lib/api'
|
||||
import type { FeatureCreate, FeatureUpdate, ModelsResponse, ProjectSettingsUpdate, ProvidersResponse, Settings, SettingsUpdate } from '../lib/types'
|
||||
import type { DevServerConfig, FeatureCreate, FeatureUpdate, ModelsResponse, ProjectSettingsUpdate, ProvidersResponse, Settings, SettingsUpdate } from '../lib/types'
|
||||
|
||||
// ============================================================================
|
||||
// Projects
|
||||
@@ -345,3 +345,36 @@ export function useUpdateSettings() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Dev Server Config
|
||||
// ============================================================================
|
||||
|
||||
// Default config for placeholder (until API responds)
|
||||
const DEFAULT_DEV_SERVER_CONFIG: DevServerConfig = {
|
||||
detected_type: null,
|
||||
detected_command: null,
|
||||
custom_command: null,
|
||||
effective_command: null,
|
||||
}
|
||||
|
||||
export function useDevServerConfig(projectName: string | null) {
|
||||
return useQuery({
|
||||
queryKey: ['dev-server-config', projectName],
|
||||
queryFn: () => api.getDevServerConfig(projectName!),
|
||||
enabled: !!projectName,
|
||||
staleTime: 30_000,
|
||||
placeholderData: DEFAULT_DEV_SERVER_CONFIG,
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateDevServerConfig(projectName: string) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (customCommand: string | null) =>
|
||||
api.updateDevServerConfig(projectName, customCommand),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['dev-server-config', projectName] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -445,6 +445,16 @@ export async function getDevServerConfig(projectName: string): Promise<DevServer
|
||||
return fetchJSON(`/projects/${encodeURIComponent(projectName)}/devserver/config`)
|
||||
}
|
||||
|
||||
export async function updateDevServerConfig(
|
||||
projectName: string,
|
||||
customCommand: string | null
|
||||
): Promise<DevServerConfig> {
|
||||
return fetchJSON(`/projects/${encodeURIComponent(projectName)}/devserver/config`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ custom_command: customCommand }),
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Terminal API
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user