import { useState } from 'react' import { Terminal, Copy, Check, Loader2, Play, ChevronDown, ChevronRight } from 'lucide-react' import { scriptsApi } from '@/api' import { PowerShellHighlighter } from '@/components/scripts/PowerShellHighlighter' import { toast } from '@/lib/toast' import type { StepResponseRequest } from '@/types/ai-session' interface InSessionScriptGeneratorProps { templateId: string preFilledParams: Record instructions: string sessionId: string onRespond: (response: StepResponseRequest) => void } export function InSessionScriptGenerator({ templateId, preFilledParams, instructions, sessionId, onRespond, }: InSessionScriptGeneratorProps) { const [params, setParams] = useState>(preFilledParams) const [generatedScript, setGeneratedScript] = useState(null) const [isGenerating, setIsGenerating] = useState(false) const [copied, setCopied] = useState(false) const [showParams, setShowParams] = useState(true) const handleGenerate = async () => { setIsGenerating(true) try { const result = await scriptsApi.generate({ template_id: templateId, parameters: params, ai_session_id: sessionId, }) setGeneratedScript(result.script) setShowParams(false) toast.success('Script generated') } catch { toast.error('Failed to generate script') } finally { setIsGenerating(false) } } const handleCopy = async () => { if (!generatedScript) return await navigator.clipboard.writeText(generatedScript) setCopied(true) setTimeout(() => setCopied(false), 2000) } const handleContinue = (success: boolean) => { onRespond({ action_result: { success, details: success ? 'Script generated and executed' : 'Script generated but action did not resolve the issue', }, }) } return (
Script Generator
{instructions && (

{instructions}

)} {/* Parameter editing */} {!generatedScript && ( <> {showParams && Object.keys(params).length > 0 && (
{Object.entries(params).map(([key, value]) => (
setParams(prev => ({ ...prev, [key]: e.target.value }))} className="w-full rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground placeholder:text-muted-foreground focus:border-[rgba(96,165,250,0.3)] focus:outline-none" />
))}
)} )} {/* Generated script display */} {generatedScript && ( <>
PowerShell
{/* Continue buttons */}
)}
) }