Spaces:
Paused
Paused
Upload patch_chat_input.py
Browse files- patch_chat_input.py +34 -22
patch_chat_input.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
-
"""Patch ChatInput.tsx
|
| 2 |
|
| 3 |
CHAT_INPUT = "/source/frontend/src/components/Chat/ChatInput.tsx"
|
| 4 |
|
| 5 |
-
def
|
| 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
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
if match:
|
| 37 |
-
content = content.replace(match.group(0),
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
# Add auto-continue buttons before the
|
| 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
|
| 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 |
-
|
| 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()
|
|
|