mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 16:03:34 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98aef6a321 | ||
|
|
564285f244 | ||
|
|
b8b7c13e03 | ||
|
|
240f837767 | ||
|
|
01a380520c | ||
|
|
6ec3c165b3 | ||
|
|
78dd85ad50 | ||
|
|
b3d4deedc8 | ||
|
|
0445b4d0c0 | ||
|
|
24e23e4a6e | ||
|
|
e117805487 | ||
|
|
665ca097f9 | ||
|
|
0140e46894 |
No files matched your search
@@ -6,6 +6,7 @@ yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
.ai/
|
||||
|
||||
node_modules
|
||||
dist
|
||||
@@ -29,3 +30,4 @@ dist-ssr
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
@@ -23,17 +23,19 @@ import { buildProject } from "@/lib/build";
|
||||
interface ChatPaneProps {
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
onBuildComplete?: (projectId: string) => void;
|
||||
}
|
||||
|
||||
type AIMessage = (CoreUserMessage | CoreAssistantMessage | CoreToolMessage) & { id: string };
|
||||
|
||||
export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
||||
export function ChatPane({ projectId, projectName, onBuildComplete }: ChatPaneProps) {
|
||||
const [messages, setMessages] = useState<AIMessage[]>([]);
|
||||
const [input, setInput] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isBuildLoading, setIsBuildLoading] = useState(false);
|
||||
const [isDeployLoading, setIsDeployLoading] = useState(false);
|
||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const { settings, isConfigured } = useAISettings();
|
||||
const { fs: browserFS } = useFS();
|
||||
const { runtime } = useJSRuntime();
|
||||
@@ -202,7 +204,7 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
const provider = openai(settings.model);
|
||||
const cwd = `/projects/${projectId}`;
|
||||
|
||||
return generateText({
|
||||
const result = await generateText({
|
||||
model: provider,
|
||||
messages,
|
||||
maxSteps: 100,
|
||||
@@ -257,6 +259,56 @@ The project uses:
|
||||
|
||||
When creating new components or pages, follow the existing patterns in the codebase.`
|
||||
});
|
||||
|
||||
// After the entire generation is complete, check if we should auto-build
|
||||
console.log('Agent finished with reason:', result.finishReason);
|
||||
|
||||
// Only auto-build if:
|
||||
// 1. The agent completed successfully (not stopped due to errors or limits)
|
||||
// 2. The previous response before the stop was from the assistant invoking tool calls
|
||||
// (meaning actual work was performed, not just conversational response)
|
||||
const responseMessages = result.response.messages;
|
||||
const hasToolResults = responseMessages.some(msg => msg.role === 'tool');
|
||||
|
||||
if (result.finishReason === 'stop' && hasToolResults) {
|
||||
console.log('Agent performed tool work successfully, auto-building project...');
|
||||
|
||||
setTimeout(async () => {
|
||||
if (isBuildLoading || isDeployLoading) {
|
||||
addMessage({
|
||||
id: generateId(),
|
||||
role: 'assistant',
|
||||
content: '⏸️ Build or deploy already in progress. Skipping auto-build.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await runBuild();
|
||||
if (onBuildComplete) {
|
||||
onBuildComplete(projectId);
|
||||
}
|
||||
addMessage({
|
||||
id: generateId(),
|
||||
role: 'assistant',
|
||||
content: '✅ Agent completed successfully. Project built! Switch to the "Preview" tab to see your changes.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Auto-build failed:', error);
|
||||
addMessage({
|
||||
id: generateId(),
|
||||
role: 'assistant',
|
||||
content: `❌ Auto-build failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
});
|
||||
}
|
||||
}, 1000);
|
||||
} else if (result.finishReason === 'stop' && !hasToolResults) {
|
||||
console.log('Agent completed but no tool work was performed - skipping auto-build');
|
||||
} else {
|
||||
console.log('Agent finished with reason:', result.finishReason, '- skipping auto-build');
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const handleSend = async () => {
|
||||
@@ -279,6 +331,7 @@ When creating new components or pages, follow the existing patterns in the codeb
|
||||
await createAIChat(projectId, aiMessages);
|
||||
} catch (error) {
|
||||
console.error('AI chat error:', error);
|
||||
|
||||
const errorMessage: AIMessage = {
|
||||
id: generateId(),
|
||||
role: 'assistant',
|
||||
@@ -353,8 +406,6 @@ When creating new components or pages, follow the existing patterns in the codeb
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<div className="border-b bg-gradient-to-r from-primary/5 to-accent/5 px-4 py-3 flex justify-between items-center">
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { AssistantContent } from './AssistantContent';
|
||||
import { TestApp } from '@/test/TestApp';
|
||||
import type { CoreToolMessage } from 'ai';
|
||||
|
||||
|
||||
describe('AssistantContent', () => {
|
||||
const mockToolResults: CoreToolMessage[] = [];
|
||||
|
||||
describe('Build Action Detection', () => {
|
||||
it('should render build action for auto-build success message', () => {
|
||||
const content = '✅ Agent completed successfully. Project built and preview updated!';
|
||||
|
||||
render(
|
||||
<TestApp>
|
||||
<AssistantContent content={content} toolResults={mockToolResults} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// Check if BuildAction component is rendered with auto-build title
|
||||
expect(screen.getByText('Auto-Build Project')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render regular markdown for non-build-action string content', () => {
|
||||
const content = 'Hello, I can help you with your project.';
|
||||
|
||||
render(
|
||||
<TestApp>
|
||||
<AssistantContent content={content} toolResults={mockToolResults} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Hello, I can help you with your project.')).toBeInTheDocument();
|
||||
expect(screen.queryByText(/Project|Action/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render tool calls for array content with tool-call items', () => {
|
||||
const content = [
|
||||
{ type: 'tool-call' as const, toolName: 'some_custom_tool', toolCallId: 'test-id', args: { param1: 'value1' } }
|
||||
];
|
||||
|
||||
render(
|
||||
<TestApp>
|
||||
<AssistantContent content={content} toolResults={mockToolResults} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByText(/some_custom_tool/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import { FileWriter } from '@/components/ai/FileWriter';
|
||||
import { ShellCommand } from '@/components/ai/ShellCommand';
|
||||
import { PackageManager } from '@/components/ai/PackageManager';
|
||||
import { GitCommit } from '@/components/ai/GitCommit';
|
||||
import { BuildAction } from '@/components/ai/BuildAction';
|
||||
import type { CoreAssistantMessage, CoreToolMessage } from 'ai';
|
||||
|
||||
interface AssistantContentProps {
|
||||
@@ -64,8 +65,64 @@ export const AssistantContent = memo(({ content, toolResults = [] }: AssistantCo
|
||||
|
||||
return { isError: toolResult.isError || false };
|
||||
};
|
||||
|
||||
// Helper function to check if text represents a build action
|
||||
const isBuildAction = (text: string): boolean => {
|
||||
return /(✅|❌|⏸️|🎉)/.test(text) && /(Agent completed successfully|Auto-build|Build|Deploy|Building|Deploying)/i.test(text);
|
||||
};
|
||||
|
||||
// Helper function to determine build action type
|
||||
const getActionType = (text: string): 'build' | 'deploy' | 'auto-build' => {
|
||||
if (text.includes('Auto-build') || text.includes('Auto-building') ||
|
||||
(text.includes('Agent completed successfully') && text.includes('built'))) {
|
||||
return 'auto-build';
|
||||
}
|
||||
if (text.includes('Deploy') || text.includes('Deploying')) {
|
||||
return 'deploy';
|
||||
}
|
||||
return 'build';
|
||||
};
|
||||
|
||||
// Helper function to determine build action status
|
||||
const getActionStatus = (text: string): { isError: boolean; isLoading: boolean } => {
|
||||
const icon = text.match(/(✅|❌|⏸️|🎉)/)?.[1];
|
||||
const hasFailed = icon === '❌' || text.toLowerCase().includes('failed');
|
||||
const isRunning = icon === '⏸️' || /(Building|Deploying)/i.test(text);
|
||||
|
||||
return {
|
||||
isError: hasFailed,
|
||||
isLoading: isRunning && !hasFailed
|
||||
};
|
||||
};
|
||||
|
||||
// Helper function to render build action
|
||||
const renderBuildAction = (text: string, key: number | string) => {
|
||||
if (!isBuildAction(text)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const actionType = getActionType(text);
|
||||
const { isError, isLoading } = getActionStatus(text);
|
||||
|
||||
return (
|
||||
<BuildAction
|
||||
key={key}
|
||||
action={actionType}
|
||||
result={text}
|
||||
isError={isError}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// Handle string content (simple text messages)
|
||||
if (typeof content === 'string') {
|
||||
// Check if this is a build action message
|
||||
const buildAction = renderBuildAction(content, 'string-content');
|
||||
if (buildAction) {
|
||||
return buildAction;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="prose prose-sm max-w-none dark:prose-invert">
|
||||
<ReactMarkdown
|
||||
@@ -117,6 +174,12 @@ export const AssistantContent = memo(({ content, toolResults = [] }: AssistantCo
|
||||
<>
|
||||
{content.map((item, index) => {
|
||||
if (item.type === 'text') {
|
||||
// Check if this is a build action message
|
||||
const buildAction = renderBuildAction(item.text, index);
|
||||
if (buildAction) {
|
||||
return buildAction;
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={index} className="prose prose-sm max-w-none dark:prose-invert">
|
||||
<ReactMarkdown
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { memo } from 'react';
|
||||
import { ActionCard } from './shared/ActionCard';
|
||||
|
||||
interface BuildActionProps {
|
||||
action: 'build' | 'deploy' | 'auto-build';
|
||||
result?: string;
|
||||
status?: 'RUNNING' | 'SUCCESS' | 'FAILED' | 'PENDING';
|
||||
isError?: boolean;
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export const BuildAction = memo(({ action, result, status, isError, isLoading }: BuildActionProps) => {
|
||||
const actionConfig = {
|
||||
build: { title: 'Build Project', verb: 'build' },
|
||||
deploy: { title: 'Deploy Project', verb: 'deploy' },
|
||||
'auto-build': { title: 'Auto-Build Project', verb: 'auto-build' },
|
||||
}[action] || { title: 'Build Action', verb: 'process' };
|
||||
|
||||
const getActionDescription = () => {
|
||||
const effectiveStatus = status || (
|
||||
isLoading ? 'RUNNING' :
|
||||
isError ? 'FAILED' : 'SUCCESS'
|
||||
);
|
||||
|
||||
if (effectiveStatus === 'RUNNING') return `${actionConfig.verb.charAt(0).toUpperCase() + actionConfig.verb.slice(1)}ing project...`;
|
||||
if (effectiveStatus === 'FAILED') return `${actionConfig.verb.charAt(0).toUpperCase() + actionConfig.verb.slice(1)} failed`;
|
||||
if (effectiveStatus === 'SUCCESS') return `${actionConfig.verb.charAt(0).toUpperCase() + actionConfig.verb.slice(1)} completed`;
|
||||
return `Starting ${actionConfig.verb} process...`;
|
||||
};
|
||||
|
||||
return (
|
||||
<ActionCard
|
||||
title={actionConfig.title}
|
||||
description={getActionDescription()}
|
||||
result={result}
|
||||
status={status}
|
||||
isError={isError}
|
||||
isLoading={isLoading}
|
||||
successLabel="Completed"
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
BuildAction.displayName = 'BuildAction';
|
||||
@@ -4,7 +4,7 @@ import { TestApp } from '@/test/TestApp';
|
||||
import { GitCommit } from './GitCommit';
|
||||
|
||||
describe('GitCommit', () => {
|
||||
it('renders commit message and shows committing state', () => {
|
||||
it('renders commit message', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitCommit message="feat: add new feature" />
|
||||
@@ -12,8 +12,6 @@ describe('GitCommit', () => {
|
||||
);
|
||||
|
||||
expect(screen.getByText('feat: add new feature')).toBeInTheDocument();
|
||||
expect(screen.getByText('Committing')).toBeInTheDocument();
|
||||
expect(screen.getByText('Git commit')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows success state with commit details', () => {
|
||||
@@ -38,7 +36,7 @@ describe('GitCommit', () => {
|
||||
|
||||
expect(screen.getByText('Committed')).toBeInTheDocument();
|
||||
expect(screen.getByText('Successfully committed 3 files')).toBeInTheDocument();
|
||||
expect(screen.getByText('abc1234')).toBeInTheDocument();
|
||||
expect(screen.getByText('main branch')).toBeInTheDocument();
|
||||
expect(screen.getByText('2 added')).toBeInTheDocument();
|
||||
expect(screen.getByText('1 modified')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Card, CardContent, CardHeader } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { GitCommit as GitCommitIcon, CheckCircle, XCircle, GitBranch, Plus, Minus, Edit } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ActionCard } from './shared/ActionCard';
|
||||
import { GitCommit as GitCommitIcon, GitBranch, Plus, Minus, Edit } from 'lucide-react';
|
||||
|
||||
interface GitCommitProps {
|
||||
message: string;
|
||||
@@ -80,61 +78,33 @@ export function GitCommit({
|
||||
const firstLine = getFirstLine(message);
|
||||
const commitEmoji = getCommitEmoji(message);
|
||||
|
||||
return (
|
||||
<Card className={cn("mt-2", isError ? "border-destructive/50" : "border-muted", className)}>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<GitCommitIcon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg">{commitEmoji}</span>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="font-mono text-sm font-medium truncate">
|
||||
{firstLine}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Git commit
|
||||
{stats?.branch && (
|
||||
<span className="ml-2 inline-flex items-center gap-1">
|
||||
<GitBranch className="h-3 w-3" />
|
||||
{stats.branch}
|
||||
</span>
|
||||
)}
|
||||
{stats?.hash && (
|
||||
<span className="ml-2 font-mono">
|
||||
{stats.hash}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{result !== undefined ? (
|
||||
isError ? (
|
||||
<Badge variant="destructive" className="text-xs">
|
||||
<XCircle className="h-3 w-3 mr-1" />
|
||||
Failed
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-xs bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400">
|
||||
<CheckCircle className="h-3 w-3 mr-1" />
|
||||
Committed
|
||||
</Badge>
|
||||
)
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-xs bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400">
|
||||
<GitCommitIcon className="h-3 w-3 mr-1" />
|
||||
Committing
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
const getCommitDescription = () => {
|
||||
let desc = 'Git commit';
|
||||
if (stats?.branch) {
|
||||
desc += ` • ${stats.branch} branch`;
|
||||
}
|
||||
if (stats?.hash) {
|
||||
desc += ` • ${stats.hash}`;
|
||||
}
|
||||
return desc;
|
||||
};
|
||||
|
||||
return (
|
||||
<ActionCard
|
||||
title={firstLine}
|
||||
description={getCommitDescription()}
|
||||
icon={<span className="text-lg">{commitEmoji}</span>}
|
||||
result={result}
|
||||
isError={isError}
|
||||
className={className}
|
||||
showResult={false}
|
||||
runningIcon={<GitCommitIcon className="h-3 w-3" />}
|
||||
runningLabel="Committing"
|
||||
successLabel="Committed"
|
||||
>
|
||||
{/* Full commit message - only show if multi-line */}
|
||||
{message.includes('\n') && (
|
||||
<CardContent className="pt-0">
|
||||
<div className="mb-3">
|
||||
<details className="group">
|
||||
<summary className="cursor-pointer text-xs text-muted-foreground hover:text-foreground transition-colors mb-2 flex items-center gap-1">
|
||||
<span className="group-open:rotate-90 transition-transform">▶</span>
|
||||
@@ -148,19 +118,14 @@ export function GitCommit({
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</CardContent>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{result && (
|
||||
<CardContent className={cn("pt-0", message.includes('\n') ? "pt-3" : "")}>
|
||||
<>
|
||||
{/* Summary */}
|
||||
{summary && (
|
||||
<div className={cn(
|
||||
"mb-3 p-3 rounded-md text-sm font-medium",
|
||||
isError
|
||||
? "bg-destructive/10 text-destructive border border-destructive/20"
|
||||
: "bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-400 border border-green-200 dark:border-green-800/30"
|
||||
)}>
|
||||
<div className="mb-3 p-3 rounded-md text-sm font-muted-foreground">
|
||||
{summary}
|
||||
</div>
|
||||
)}
|
||||
@@ -207,8 +172,8 @@ export function GitCommit({
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
</ActionCard>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Card, CardContent, CardHeader } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Play, CheckCircle, XCircle } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ActionCard } from './shared/ActionCard';
|
||||
import { Play } from 'lucide-react';
|
||||
|
||||
interface ScriptRunnerProps {
|
||||
script: string;
|
||||
@@ -104,52 +102,21 @@ export function ScriptRunner({ script, result, isError = false, className }: Scr
|
||||
const { summary, details } = parseOutput(result || '');
|
||||
|
||||
return (
|
||||
<Card className={cn("mt-2", isError ? "border-destructive/50" : "border-muted", className)}>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Play className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg">{scriptInfo.icon}</span>
|
||||
</div>
|
||||
<div>
|
||||
<div className="font-mono text-sm font-medium">npm run {script}</div>
|
||||
<div className="text-xs text-muted-foreground">{scriptInfo.description}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{result !== undefined ? (
|
||||
isError ? (
|
||||
<Badge variant="destructive" className="text-xs">
|
||||
<XCircle className="h-3 w-3 mr-1" />
|
||||
Failed
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-xs bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400">
|
||||
<CheckCircle className="h-3 w-3 mr-1" />
|
||||
Success
|
||||
</Badge>
|
||||
)
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-xs bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400">
|
||||
<Play className="h-3 w-3 mr-1" />
|
||||
Running
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<ActionCard
|
||||
title={`npm run ${script}`}
|
||||
description={scriptInfo.description}
|
||||
icon={<span className="text-lg">{scriptInfo.icon}</span>}
|
||||
result={result}
|
||||
isError={isError}
|
||||
className={className}
|
||||
runningIcon={<Play className="h-3 w-3" />}
|
||||
runningLabel="Running"
|
||||
>
|
||||
{result && (
|
||||
<CardContent className="pt-0">
|
||||
<>
|
||||
{/* Summary */}
|
||||
{summary && (
|
||||
<div className={cn(
|
||||
"mb-3 p-3 rounded-md text-sm font-medium",
|
||||
isError
|
||||
? "bg-destructive/10 text-destructive border border-destructive/20"
|
||||
: "bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-400 border border-green-200 dark:border-green-800/30"
|
||||
)}>
|
||||
<div className="mb-3 p-3 rounded-md text-sm font-muted-foreground">
|
||||
{summary}
|
||||
</div>
|
||||
)}
|
||||
@@ -201,8 +168,8 @@ export function ScriptRunner({ script, result, isError = false, className }: Scr
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
</ActionCard>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Card, CardContent, CardHeader } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Terminal, CheckCircle, XCircle, Play } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ActionCard } from './shared/ActionCard';
|
||||
import { Terminal } from 'lucide-react';
|
||||
|
||||
interface ShellCommandProps {
|
||||
command: string;
|
||||
@@ -122,52 +120,21 @@ export function ShellCommand({ command, result, isError = false, className }: Sh
|
||||
const { summary, details } = parseOutput(result || '');
|
||||
|
||||
return (
|
||||
<Card className={cn("mt-2", isError ? "border-destructive/50" : "border-muted", className)}>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Terminal className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg">{commandInfo.icon}</span>
|
||||
</div>
|
||||
<div>
|
||||
<div className="font-mono text-sm font-medium">$ {commandInfo.fullCommand}</div>
|
||||
<div className="text-xs text-muted-foreground">{commandInfo.description}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{result !== undefined ? (
|
||||
isError ? (
|
||||
<Badge variant="destructive" className="text-xs">
|
||||
<XCircle className="h-3 w-3 mr-1" />
|
||||
Failed
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-xs bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400">
|
||||
<CheckCircle className="h-3 w-3 mr-1" />
|
||||
Success
|
||||
</Badge>
|
||||
)
|
||||
) : (
|
||||
<Badge variant="secondary" className="text-xs bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400">
|
||||
<Play className="h-3 w-3 mr-1" />
|
||||
Running
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<ActionCard
|
||||
title={`$ ${commandInfo.fullCommand}`}
|
||||
description={commandInfo.description}
|
||||
icon={<span className="text-lg">{commandInfo.icon}</span>}
|
||||
result={result}
|
||||
isError={isError}
|
||||
className={className}
|
||||
runningIcon={<Terminal className="h-3 w-3" />}
|
||||
runningLabel="Executing"
|
||||
>
|
||||
{result && (
|
||||
<CardContent className="pt-0">
|
||||
<>
|
||||
{/* Summary */}
|
||||
{summary && (
|
||||
<div className={cn(
|
||||
"mb-3 p-3 rounded-md text-sm font-medium",
|
||||
isError
|
||||
? "bg-destructive/10 text-destructive border border-destructive/20"
|
||||
: "bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-400 border border-green-200 dark:border-green-800/30"
|
||||
)}>
|
||||
<div className="mb-3 p-3 rounded-md text-sm font-muted-foreground">
|
||||
{summary}
|
||||
</div>
|
||||
)}
|
||||
@@ -210,8 +177,8 @@ export function ShellCommand({ command, result, isError = false, className }: Sh
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
</ActionCard>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Card, CardContent, CardHeader } from '@/components/ui/card';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ActionStatus, type ActionStatusProps } from './ActionStatus';
|
||||
|
||||
export interface ActionCardProps extends Omit<ActionStatusProps, 'status'> {
|
||||
title: string;
|
||||
description?: string;
|
||||
icon?: React.ReactNode;
|
||||
result?: string;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
showResult?: boolean;
|
||||
status?: ActionStatusProps['status'];
|
||||
}
|
||||
|
||||
export function ActionCard({
|
||||
title,
|
||||
description,
|
||||
icon,
|
||||
result,
|
||||
children,
|
||||
className,
|
||||
showResult = true,
|
||||
...statusProps
|
||||
}: ActionCardProps) {
|
||||
const { Badge, Icon, ResultClass, BorderClass } = ActionStatus({
|
||||
_result: result,
|
||||
...statusProps,
|
||||
status: statusProps.status
|
||||
});
|
||||
|
||||
return (
|
||||
<Card className={cn("mt-2", BorderClass(), className)}>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
{icon && (
|
||||
<div className="flex items-center gap-2">
|
||||
{Icon('md')}
|
||||
{icon}
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<div className="font-mono text-sm font-medium">{title}</div>
|
||||
{description && (
|
||||
<div className="text-xs text-muted-foreground">{description}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge />
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
{(children || (showResult && result)) && (
|
||||
<CardContent className="pt-0">
|
||||
{children}
|
||||
|
||||
{showResult && result && (
|
||||
<div className={ResultClass()}>
|
||||
<pre className="whitespace-pre-wrap break-words">{result}</pre>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Loader2, XCircle, CheckCircle, Play } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export interface ActionStatusProps {
|
||||
status?: 'RUNNING' | 'SUCCESS' | 'FAILED' | 'PENDING';
|
||||
isLoading?: boolean;
|
||||
isError?: boolean;
|
||||
_result?: string;
|
||||
runningIcon?: React.ReactNode;
|
||||
successIcon?: React.ReactNode;
|
||||
failedIcon?: React.ReactNode;
|
||||
successLabel?: string;
|
||||
failedLabel?: string;
|
||||
runningLabel?: string;
|
||||
}
|
||||
|
||||
export function ActionStatus({
|
||||
status,
|
||||
isLoading,
|
||||
isError,
|
||||
_result,
|
||||
runningIcon = <Loader2 className="h-3 w-3 animate-spin" />,
|
||||
successIcon = <CheckCircle className="h-3 w-3" />,
|
||||
failedIcon = <XCircle className="h-3 w-3" />,
|
||||
successLabel = 'Success',
|
||||
failedLabel = 'Failed',
|
||||
runningLabel = 'Running'
|
||||
}: ActionStatusProps) {
|
||||
// Handle both new status-based and old boolean-based props for compatibility
|
||||
const effectiveStatus = status || (
|
||||
isLoading ? 'RUNNING' :
|
||||
isError ? 'FAILED' : 'SUCCESS'
|
||||
) as 'RUNNING' | 'SUCCESS' | 'FAILED' | 'PENDING';
|
||||
|
||||
const getBadge = () => {
|
||||
if (effectiveStatus === 'RUNNING') {
|
||||
return (
|
||||
<Badge variant="secondary" className="text-xs bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400">
|
||||
{runningIcon}
|
||||
{runningLabel}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
if (effectiveStatus === 'FAILED') {
|
||||
return (
|
||||
<Badge variant="destructive" className="text-xs">
|
||||
{failedIcon}
|
||||
{failedLabel}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Badge variant="secondary" className="text-xs bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400">
|
||||
{successIcon}
|
||||
{successLabel}
|
||||
</Badge>
|
||||
);
|
||||
};
|
||||
|
||||
const getIcon = (size: 'sm' | 'md' = 'md') => {
|
||||
const sizeClass = size === 'sm' ? 'h-3 w-3' : 'h-4 w-4';
|
||||
|
||||
if (effectiveStatus === 'RUNNING') return <Loader2 className={`${sizeClass} animate-spin`} />;
|
||||
if (effectiveStatus === 'FAILED') return <XCircle className={`${sizeClass} text-destructive`} />;
|
||||
return <Play className={sizeClass} />;
|
||||
};
|
||||
|
||||
const getResultClass = () => {
|
||||
return cn(
|
||||
"p-3 rounded-md text-sm",
|
||||
effectiveStatus === 'FAILED'
|
||||
? "bg-destructive/10 text-destructive border border-destructive/20"
|
||||
: "bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-400 border border-green-200 dark:border-green-800/30"
|
||||
);
|
||||
};
|
||||
|
||||
const getBorderClass = () => {
|
||||
return effectiveStatus === 'FAILED' ? "border-destructive/50" : "border-muted";
|
||||
};
|
||||
|
||||
return {
|
||||
Badge: getBadge,
|
||||
Icon: getIcon,
|
||||
ResultClass: getResultClass,
|
||||
BorderClass: getBorderClass,
|
||||
status: effectiveStatus
|
||||
};
|
||||
}
|
||||
@@ -17,6 +17,16 @@ export function ProjectView() {
|
||||
const [project, setProject] = useState<Project | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState<'preview' | 'code'>('preview');
|
||||
|
||||
const handleBuildComplete = useCallback((projectId: string) => {
|
||||
setActiveTab('preview');
|
||||
// Dispatch custom event to notify PreviewPane that build is complete
|
||||
const event = new CustomEvent('buildComplete', {
|
||||
detail: { projectId }
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
console.log('Dispatched buildComplete event for project:', projectId);
|
||||
}, []);
|
||||
const [mobileView, setMobileView] = useState<'chat' | 'preview' | 'code'>('chat');
|
||||
const projectsManager = useProjectsManager();
|
||||
const navigate = useNavigate();
|
||||
@@ -117,7 +127,11 @@ export function ProjectView() {
|
||||
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{mobileView === 'chat' && (
|
||||
<ChatPane projectId={project.id} projectName={project.name} />
|
||||
<ChatPane
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onBuildComplete={handleBuildComplete}
|
||||
/>
|
||||
)}
|
||||
{(mobileView === 'preview' || mobileView === 'code') && (
|
||||
<PreviewPane
|
||||
@@ -221,7 +235,11 @@ export function ProjectView() {
|
||||
|
||||
{/* Chat Content */}
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<ChatPane projectId={project.id} projectName={project.name} />
|
||||
<ChatPane
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onBuildComplete={handleBuildComplete}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
|
||||
Reference in new issue
Block a user