File size: 3,606 Bytes
020776c
274c55b
 
 
769c39b
e412b9c
274c55b
 
 
 
 
 
 
e412b9c
 
274c55b
 
 
 
 
020776c
769c39b
020776c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769c39b
e412b9c
 
 
 
769c39b
 
 
 
 
 
 
 
274c55b
 
 
 
e412b9c
 
 
274c55b
e412b9c
769c39b
e412b9c
 
 
 
274c55b
e412b9c
 
 
274c55b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e412b9c
 
274c55b
 
 
e412b9c
 
274c55b
 
 
 
 
 
 
769c39b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Patch ChatInput.tsx - Fixed import for DatasetUploadResponse."""

CHAT_INPUT = "/source/frontend/src/components/Chat/ChatInput.tsx"

def patch():
    import os, re
    if not os.path.exists(CHAT_INPUT):
        print(f"SKIP: {CHAT_INPUT} not found")
        return
        
    with open(CHAT_INPUT, "r", encoding="utf-8") as f:
        content = f.read()
    
    # 1. Add Button to MUI imports
    if "Button" not in content and "@mui/material" in content:
        content = content.replace(
            "import { Box, IconButton, Stack, Tooltip } from '@mui/material';",
            "import { Box, IconButton, Stack, Tooltip, Button } from '@mui/material';"
        )
    
    # 2. Fix DatasetUploadResponse import - check existing imports
    if "DatasetUploadResponse" not in content:
        # Find existing import from types/agent
        if "from '@/types/agent'" in content:
            content = content.replace(
                "from '@/types/agent'",
                "from '@/types/agent'"
            )
            # Add DatasetUploadResponse to existing import
            content = content.replace(
                "import type { ",
                "import type { DatasetUploadResponse, "
            )
        else:
            content = content.replace(
                "import { apiFetch } from '@/utils/api';",
                "import { apiFetch } from '@/utils/api';\nimport type { DatasetUploadResponse } from '@/types/agent';"
            )
    
    # 3. Add props to interface
    if "showAutoContinue" not in content:
        props_code = '''
interface ChatInputProps {
  sessionId: string;
  initialModelPath: string | null | undefined;
  onSend: (text: string) => Promise<void>;
  onStop: () => void;
  onDatasetUploaded: () => Promise<boolean>;
  isProcessing: boolean;
  disabled: boolean;
  placeholder?: string;
  showAutoContinue?: boolean;
  taskIncompleteInfo?: { incompletePlan: Array<{ id: string; content: string; status: string }> } | null;
  startAutoContinue?: () => void;
  cancelAutoContinue?: () => void;
}
'''
        match = re.search(r'interface ChatInputProps[^}]*[}][^}]*[}]', content, re.DOTALL)
        if match:
            content = content.replace(match.group(0), props_code)
        else:
            content = content.replace(
                "export default function ChatInput",
                props_code + "\nexport default function ChatInput"
            )
    
    # 4. Add auto-continue buttons before the flex box
    buttons_code = '''
      {/* Auto-continue controls for free models */}
      {showAutoContinue && taskIncompleteInfo && (
        <Stack direction="row" spacing={1} sx={{ mb: 1, px: 1 }}>
          <Button
            variant="contained"
            color="primary"
            size="small"
            onClick={startAutoContinue}
            sx={{ textTransform: 'none', fontSize: '0.75rem' }}
          >
            Tự động tiếp tục (10s)
          </Button>
          <Button
            variant="outlined"
            color="secondary"
            size="small"
            onClick={cancelAutoContinue}
            sx={{ textTransform: 'none', fontSize: '0.75rem' }}
          >
            Tạm dừng
          </Button>
        </Stack>
      )}
'''
    
    if "Tự động tiếp tục" not in content:
        content = content.replace(
            "<Box sx={{ flex: 1 ",
            buttons_code + "        <Box sx={{ flex: 1 "
        )
    
    with open(CHAT_INPUT, "w", encoding="utf-8") as f:
        f.write(content)
    print(f"OK: Patched {CHAT_INPUT}")

if __name__ == "__main__":
    patch()