bep40 commited on
Commit
769c39b
·
verified ·
1 Parent(s): aa15811

Upload patch_chat_input.py

Browse files
Files changed (1) hide show
  1. patch_chat_input.py +34 -22
patch_chat_input.py CHANGED
@@ -1,9 +1,10 @@
1
- """Patch ChatInput.tsx for auto-continue buttons."""
2
 
3
  CHAT_INPUT = "/source/frontend/src/components/Chat/ChatInput.tsx"
4
 
5
- def patch_chat_input():
6
  import os
 
7
  if not os.path.exists(CHAT_INPUT):
8
  print(f"SKIP: {CHAT_INPUT} not found")
9
  return
@@ -18,27 +19,40 @@ def patch_chat_input():
18
  "import { Box, IconButton, Stack, Tooltip, Button } from '@mui/material';"
19
  )
20
 
21
- # Add props
22
- props_code = '''
23
- interface ChatInputProps {
24
- isProcessing?: boolean;
25
- disabled?: boolean;
26
- onUndoTurn?: () => void;
 
 
 
 
 
 
 
 
 
 
 
27
  showAutoContinue?: boolean;
28
  taskIncompleteInfo?: { incompletePlan: Array<{ id: string; content: string; status: string }> } | null;
29
  startAutoContinue?: () => void;
30
  cancelAutoContinue?: () => void;
31
- }
32
- '''
33
  if "showAutoContinue" not in content:
34
  # Find existing interface
35
- match = re.search(r'interface ChatInputProps[^}]*[}][^}]*[}]', content, re.DOTALL)
36
  if match:
37
- content = content.replace(match.group(0), props_code)
 
 
 
38
 
39
- # Add auto-continue buttons before the bottom bar
40
- buttons_code = '''
41
- {/* Auto-continue controls for free models */}
42
  {showAutoContinue && taskIncompleteInfo && (
43
  <Stack direction="row" spacing={1} sx={{ mb: 1, px: 1 }}>
44
  <Button
@@ -60,21 +74,19 @@ interface ChatInputProps {
60
  Tạm dừng
61
  </Button>
62
  </Stack>
63
- )}
64
- '''
65
 
66
- # Find a good insertion point - after the message area, before flex box
67
  if "Tự động tiếp tục" not in content:
68
  # Insert before <Box sx={{ flex: 1 }}
69
  content = content.replace(
70
- "<Box sx={{ flex",
71
- buttons_code + "\n <Box sx={{"
72
  )
 
73
 
74
  with open(CHAT_INPUT, "w", encoding="utf-8") as f:
75
  f.write(content)
76
  print(f"OK: Patched {CHAT_INPUT}")
77
 
78
  if __name__ == "__main__":
79
- import re
80
- patch_chat_input()
 
1
+ """Patch ChatInput.tsx - Fixed version with all required props."""
2
 
3
  CHAT_INPUT = "/source/frontend/src/components/Chat/ChatInput.tsx"
4
 
5
+ def patch():
6
  import os
7
+ import re
8
  if not os.path.exists(CHAT_INPUT):
9
  print(f"SKIP: {CHAT_INPUT} not found")
10
  return
 
19
  "import { Box, IconButton, Stack, Tooltip, Button } from '@mui/material';"
20
  )
21
 
22
+ # Add import for DatasetUploadResponse if needed
23
+ if "DatasetUploadResponse" not in content:
24
+ content = content.replace(
25
+ "import { apiFetch } from '@/utils/api';",
26
+ "import { apiFetch } from '@/utils/api';\nimport type { DatasetUploadResponse } from '@/types/agent';"
27
+ )
28
+
29
+ # Replace interface ChatInputProps with complete version including auto-continue props
30
+ new_props = '''interface ChatInputProps {
31
+ sessionId: string;
32
+ initialModelPath: string | null | undefined;
33
+ onSend: (text: string) => Promise<void>;
34
+ onStop: () => void;
35
+ onDatasetUploaded: () => Promise<boolean>;
36
+ isProcessing: boolean;
37
+ disabled: boolean;
38
+ placeholder?: string;
39
  showAutoContinue?: boolean;
40
  taskIncompleteInfo?: { incompletePlan: Array<{ id: string; content: string; status: string }> } | null;
41
  startAutoContinue?: () => void;
42
  cancelAutoContinue?: () => void;
43
+ }'''
44
+
45
  if "showAutoContinue" not in content:
46
  # Find existing interface
47
+ match = re.search(r'interface ChatInputProps\s*\{[^}]*\}', content, re.DOTALL)
48
  if match:
49
+ content = content.replace(match.group(0), new_props)
50
+ print("OK: Replaced ChatInputProps interface")
51
+ else:
52
+ print("WARN: Could not find ChatInputProps interface")
53
 
54
+ # Add auto-continue buttons before the flex:1 Box
55
+ buttons_code = ''' {/* Auto-continue controls for free models */}
 
56
  {showAutoContinue && taskIncompleteInfo && (
57
  <Stack direction="row" spacing={1} sx={{ mb: 1, px: 1 }}>
58
  <Button
 
74
  Tạm dừng
75
  </Button>
76
  </Stack>
77
+ )}'''
 
78
 
 
79
  if "Tự động tiếp tục" not in content:
80
  # Insert before <Box sx={{ flex: 1 }}
81
  content = content.replace(
82
+ "<Box sx={{ flex: 1 }} />",
83
+ buttons_code + "\n <Box sx={{ flex: 1 }} />"
84
  )
85
+ print("OK: Added auto-continue buttons")
86
 
87
  with open(CHAT_INPUT, "w", encoding="utf-8") as f:
88
  f.write(content)
89
  print(f"OK: Patched {CHAT_INPUT}")
90
 
91
  if __name__ == "__main__":
92
+ patch()