feat: add robot retraining logic

This commit is contained in:
Rohit
2025-04-09 19:40:48 +05:30
parent f533fafa0c
commit 389a1cbdc8

View File

@@ -35,7 +35,8 @@ import {
Settings,
Power,
ContentCopy,
MoreHoriz
MoreHoriz,
Refresh
} from "@mui/icons-material";
import { useGlobalInfoStore } from "../../context/globalInfo";
import { checkRunsForRecording, deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage";
@@ -117,6 +118,7 @@ const TableRowMemoized = memo(({ row, columns, handlers }: any) => {
return (
<MemoizedTableCell key={column.id} align={column.align}>
<MemoizedOptionsButton
handleRetrain={() =>handlers.handleRetrainRobot(row.id, row.name)}
handleEdit={() => handlers.handleEditRobot(row.id, row.name, row.params || [])}
handleDuplicate={() => handlers.handleDuplicateRobot(row.id, row.name, row.params || [])}
handleDelete={() => handlers.handleDelete(row.id)}
@@ -198,6 +200,17 @@ export const RecordingsTable = ({
}
}
}
if (event.data && event.data.type === 'session-data-clear') {
window.sessionStorage.removeItem('browserId');
window.sessionStorage.removeItem('robotToRetrain');
window.sessionStorage.removeItem('robotName');
window.sessionStorage.removeItem('recordingUrl');
window.sessionStorage.removeItem('recordingSessionId');
window.sessionStorage.removeItem('pendingSessionData');
window.sessionStorage.removeItem('nextTabIsRecording');
window.sessionStorage.removeItem('initialUrl');
}
};
window.addEventListener('message', handleMessage);
@@ -303,6 +316,63 @@ export const RecordingsTable = ({
setModalOpen(true);
};
const handleRetrainRobot = useCallback(async (id: string, name: string) => {
const activeBrowserId = await getActiveBrowserId();
const robot = rows.find(row => row.id === id);
let targetUrl;
if (robot?.content?.workflow && robot.content.workflow.length > 0) {
// Get the last workflow item
const lastPair = robot.content.workflow[robot.content.workflow.length - 1];
if (lastPair?.what) {
if (Array.isArray(lastPair.what)) {
const gotoAction = lastPair.what.find(action =>
action && typeof action === 'object' && 'action' in action && action.action === "goto"
) as any;
if (gotoAction?.args?.[0]) {
targetUrl = gotoAction.args[0];
}
}
}
}
// Set the URL in state and session storage
if (targetUrl) {
setInitialUrl(targetUrl);
setRecordingUrl(targetUrl);
window.sessionStorage.setItem('initialUrl', targetUrl);
}
if (activeBrowserId) {
setActiveBrowserId(activeBrowserId);
setWarningModalOpen(true);
} else {
// Pass the URL directly to avoid timing issues with state updates
startRetrainRecording(id, name, targetUrl);
}
}, [rows, setInitialUrl, setRecordingUrl]);
const startRetrainRecording = (id: string, name: string, url?: string) => {
setBrowserId('new-recording');
setRecordingName('');
setRecordingId('');
window.sessionStorage.setItem('browserId', 'new-recording');
window.sessionStorage.setItem('robotToRetrain', id);
window.sessionStorage.setItem('robotName', name);
window.sessionStorage.setItem('recordingUrl', url || recordingUrl);
const sessionId = Date.now().toString();
window.sessionStorage.setItem('recordingSessionId', sessionId);
window.openedRecordingWindow = window.open(`/recording-setup?session=${sessionId}`, '_blank');
window.sessionStorage.setItem('nextTabIsRecording', 'true');
};
const startRecording = () => {
setModalOpen(false);
@@ -381,6 +451,7 @@ export const RecordingsTable = ({
handleSettingsRecording,
handleEditRobot,
handleDuplicateRobot,
handleRetrainRobot,
handleDelete: async (id: string) => {
const hasRuns = await checkRunsForRecording(id);
if (hasRuns) {
@@ -395,7 +466,7 @@ export const RecordingsTable = ({
fetchRecordings();
}
}
}), [handleRunRecording, handleScheduleRecording, handleIntegrateRecording, handleSettingsRecording, handleEditRobot, handleDuplicateRobot, notify, t]);
}), [handleRunRecording, handleScheduleRecording, handleIntegrateRecording, handleSettingsRecording, handleEditRobot, handleDuplicateRobot, handleRetrainRobot, notify, t]);
return (
<React.Fragment>
@@ -597,12 +668,13 @@ const SettingsButton = ({ handleSettings }: SettingsButtonProps) => {
}
interface OptionsButtonProps {
handleRetrain: () => void;
handleEdit: () => void;
handleDelete: () => void;
handleDuplicate: () => void;
}
const OptionsButton = ({ handleEdit, handleDelete, handleDuplicate }: OptionsButtonProps) => {
const OptionsButton = ({ handleRetrain, handleEdit, handleDelete, handleDuplicate }: OptionsButtonProps) => {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
@@ -629,6 +701,13 @@ const OptionsButton = ({ handleEdit, handleDelete, handleDuplicate }: OptionsBut
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem onClick={() => { handleRetrain(); handleClose(); }}>
<ListItemIcon>
<Refresh fontSize="small" />
</ListItemIcon>
<ListItemText>{t('recordingtable.retrain')}</ListItemText>
</MenuItem>
<MenuItem onClick={() => { handleEdit(); handleClose(); }}>
<ListItemIcon>
<Edit fontSize="small" />