Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 52 additions & 27 deletions legacy/src/RobotEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface RobotSettings {
google_access_token?: string | null;
google_refresh_token?: string | null;
schedule?: ScheduleConfig | null;
proxy?: string | null;
}

interface RobotSettingsProps {
Expand Down Expand Up @@ -128,20 +129,19 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
const extractedCredentials = extractInitialCredentials(robot.recording.workflow);
setCredentials(extractedCredentials);
setCredentialGroups(groupCredentialsByType(extractedCredentials));

findScrapeListLimits(robot.recording.workflow);
}
}, [robot]);

const findScrapeListLimits = (workflow: WhereWhatPair[]) => {
const limits: ScrapeListLimit[] = [];

workflow.forEach((pair, pairIndex) => {
if (!pair.what) return;

pair.what.forEach((action, actionIndex) => {
if (action.action === 'scrapeList' && action.args && action.args.length > 0) {
// Check if first argument has a limit property
const arg = action.args[0];
if (arg && typeof arg === 'object' && 'limit' in arg) {
limits.push({
Expand All @@ -154,7 +154,7 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
}
});
});

setScrapeListLimits(limits);
};

Expand Down Expand Up @@ -183,12 +183,12 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin

const selector = action.args[0];

// Handle full word type actions first
if (action.action === 'type' &&
if (
action.action === 'type' &&
action.args?.length >= 2 &&
typeof action.args[1] === 'string' &&
action.args[1].length > 1) {

action.args[1].length > 1
) {
if (!credentials[selector]) {
credentials[selector] = {
value: action.args[1],
Expand All @@ -199,11 +199,11 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
continue;
}

// Handle character-by-character sequences (both type and press)
if ((action.action === 'type' || action.action === 'press') &&
if (
(action.action === 'type' || action.action === 'press') &&
action.args?.length >= 2 &&
typeof action.args[1] === 'string') {

typeof action.args[1] === 'string'
) {
if (selector !== currentSelector) {
if (currentSelector && currentValue) {
credentials[currentSelector] = {
Expand Down Expand Up @@ -231,9 +231,12 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
let j = i + 1;
while (j < step.what.length) {
const nextAction = step.what[j];
if (!nextAction.action || !nextAction.args?.[0] ||
if (
!nextAction.action ||
!nextAction.args?.[0] ||
nextAction.args[0] !== selector ||
(nextAction.action !== 'type' && nextAction.action !== 'press')) {
(nextAction.action !== 'type' && nextAction.action !== 'press')
) {
break;
}
if (nextAction.args[1] === 'Backspace') {
Expand Down Expand Up @@ -290,8 +293,11 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin

const getRobot = async () => {
if (recordingId) {
const robot = await getStoredRecording(recordingId);
setRobot(robot);
const robotData = await getStoredRecording(recordingId);
setRobot({
...robotData,
proxy: robotData?.proxy ?? null
});
} else {
notify('error', t('robot_edit.notifications.update_failed'));
}
Expand All @@ -310,6 +316,12 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
);
};

const handleProxyChange = (newProxy: string) => {
setRobot((prev) =>
prev ? { ...prev, proxy: newProxy } : prev
);
};

const handleCredentialChange = (selector: string, value: string) => {
setCredentials(prev => ({
...prev,
Expand All @@ -333,12 +345,14 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
updatedWorkflow[pairIndex].what[actionIndex].args.length > argIndex
) {
updatedWorkflow[pairIndex].what[actionIndex].args[argIndex].limit = newLimit;

setScrapeListLimits(prev => {
return prev.map(item => {
if (item.pairIndex === pairIndex &&
item.actionIndex === actionIndex &&
item.argIndex === argIndex) {

setScrapeListLimits(prevLimits => {
return prevLimits.map(item => {
if (
item.pairIndex === pairIndex &&
item.actionIndex === actionIndex &&
item.argIndex === argIndex
) {
return { ...item, currentLimit: newLimit };
}
return item;
Expand Down Expand Up @@ -437,13 +451,13 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin

const renderScrapeListLimitFields = () => {
if (scrapeListLimits.length === 0) return null;

return (
<>
<Typography variant="body1" style={{ marginBottom: '20px' }}>
{t('List Limits')}
</Typography>

{scrapeListLimits.map((limitInfo, index) => (
<TextField
key={`limit-${limitInfo.pairIndex}-${limitInfo.actionIndex}`}
Expand Down Expand Up @@ -496,13 +510,13 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
})),
credentials: credentialsForPayload,
targetUrl: targetUrl,
proxy: robot.proxy ?? null,
};

const success = await updateRecording(robot.recording_meta.id, payload);

if (success) {
setRerenderRobots(true);

notify('success', t('robot_edit.notifications.update_success'));
handleStart(robot);
handleClose();
Expand Down Expand Up @@ -549,6 +563,16 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
style={{ marginBottom: '20px' }}
/>

<TextField
label="Proxy"
key="Robot Proxy"
type='text'
value={robot.proxy || ''}
onChange={(e) => handleProxyChange(e.target.value)}
placeholder="http://username:password@host:port"
style={{ marginBottom: '20px' }}
/>

{renderScrapeListLimitFields()}

{(Object.keys(credentials).length > 0) && (
Expand All @@ -573,7 +597,8 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: 'whitesmoke !important',
}}>
}}
>
{t('robot_edit.cancel')}
</Button>
</Box>
Expand Down
76 changes: 42 additions & 34 deletions server/src/api/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,20 +493,27 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string, isSDK:
};
}

const proxyConfig = await getDecryptedProxyConfig(userId);
let proxyOptions: any = {};

if (proxyConfig.proxy_url) {
if ((recording as any).proxy) {
proxyOptions = {
server: proxyConfig.proxy_url,
...(proxyConfig.proxy_username && proxyConfig.proxy_password && {
username: proxyConfig.proxy_username,
password: proxyConfig.proxy_password,
}),
server: (recording as any).proxy,
};
} else {
const proxyConfig = await getDecryptedProxyConfig(userId);

if (proxyConfig.proxy_url) {
proxyOptions = {
server: proxyConfig.proxy_url,
...(proxyConfig.proxy_username && proxyConfig.proxy_password && {
username: proxyConfig.proxy_username,
password: proxyConfig.proxy_password,
}),
};
}
}

const browserId = createRemoteBrowserForRun(userId);
const browserId = createRemoteBrowserForRun(userId, proxyOptions);

const runId = uuid();

Expand Down Expand Up @@ -543,7 +550,7 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string, isSDK:
runByAPI: plainRun.runByAPI || false,
browserId: plainRun.browserId
};

serverIo.of('/queued-run').to(`user-${userId}`).emit('run-started', runStartedData);
logger.log('info', `API run started notification sent for run: ${plainRun.runId} to user-${userId}`);
} catch (socketError: any) {
Expand Down Expand Up @@ -1518,31 +1525,32 @@ router.post("/robots/:id/duplicate", requireAPIKey, async (req: Request, res: Re
const currentTimestamp = new Date().toLocaleString();

const newRobot = await Robot.create({
id: uuid(),
userId: originalRobot.userId,
recording_meta: {
...originalRobot.recording_meta,
id: uuid(),
name: `${originalRobot.recording_meta.name} (${lastWord})`,
url: targetUrl,
createdAt: currentTimestamp,
updatedAt: currentTimestamp,
},
recording: { ...originalRobot.recording, workflow },
google_sheet_email: null,
google_sheet_name: null,
google_sheet_id: null,
google_access_token: null,
google_refresh_token: null,
airtable_base_id: null,
airtable_base_name: null,
airtable_table_name: null,
airtable_table_id: null,
airtable_access_token: null,
airtable_refresh_token: null,
webhooks: null,
schedule: null,
});
id: uuid(),
userId: originalRobot.userId,
recording_meta: {
...originalRobot.recording_meta,
id: uuid(),
name: `${originalRobot.recording_meta.name} (${lastWord})`,
url: targetUrl,
createdAt: currentTimestamp,
updatedAt: currentTimestamp,
},
recording: { ...originalRobot.recording, workflow },
proxy: originalRobot.proxy,
google_sheet_email: null,
google_sheet_name: null,
google_sheet_id: null,
google_access_token: null,
google_refresh_token: null,
airtable_base_id: null,
airtable_base_name: null,
airtable_table_name: null,
airtable_table_id: null,
airtable_access_token: null,
airtable_refresh_token: null,
webhooks: null,
schedule: null,
});

logger.log('info', `Robot with ID ${id} duplicated successfully as ${newRobot.id}.`);

Expand Down
1 change: 1 addition & 0 deletions server/src/api/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ router.post("/sdk/extract/llm", requireAPIKey, async (req: AuthenticatedRequest,
capture("maxun-oss-llm-robot-created", {
robot_meta: robot.recording_meta,
recording: robot.recording,
proxy: null,
prompt: prompt
});

Expand Down
Loading