Skip to content

feat: optional description for robots #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 2 additions & 3 deletions server/src/db/config/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from 'dotenv';
dotenv.config({ path: './.env' });
// CommonJS format for database.js
require('dotenv').config({ path: './.env' });

// Validate required environment variables
const requiredEnvVars = ['DB_USER', 'DB_PASSWORD', 'DB_NAME', 'DB_HOST', 'DB_PORT'];
Expand All @@ -10,7 +10,6 @@ requiredEnvVars.forEach(envVar => {
}
});


module.exports = {
development: {
username: process.env.DB_USER,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn('robot', 'description', {
type: Sequelize.TEXT,
allowNull: true
});
},

down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn('robot', 'description');
}
};
28 changes: 17 additions & 11 deletions server/src/models/Robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ interface RobotWorkflow {
interface RobotAttributes {
id: string;
userId?: number;
description?: string | null;
recording_meta: RobotMeta;
recording: RobotWorkflow;
google_sheet_email?: string | null;
google_sheet_name?: string | null;
google_sheet_id?: string | null;
google_access_token?: string | null;
google_refresh_token?: string | null;
airtable_base_id?: string | null;
airtable_base_name?: string | null;
airtable_table_name?: string | null;
airtable_access_token?: string | null;
airtable_refresh_token?: string | null;
airtable_base_id?: string | null;
airtable_base_name?: string | null;
airtable_table_name?: string | null;
airtable_access_token?: string | null;
airtable_refresh_token?: string | null;
schedule?: ScheduleConfig | null;
airtable_table_id?: string | null;
}
Expand All @@ -52,19 +53,20 @@ interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> { }
class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements RobotAttributes {
public id!: string;
public userId!: number;
public description!: string | null;
public recording_meta!: RobotMeta;
public recording!: RobotWorkflow;
public google_sheet_email!: string | null;
public google_sheet_name!: string | null;
public google_sheet_id!: string | null;
public google_access_token!: string | null;
public google_refresh_token!: string | null;
public airtable_base_id!: string | null;
public airtable_base_name!: string | null;
public airtable_table_name!: string | null;
public airtable_access_token!: string | null;
public airtable_refresh_token!: string | null;
public airtable_table_id!: string | null;
public airtable_base_id!: string | null;
public airtable_base_name!: string | null;
public airtable_table_name!: string | null;
public airtable_access_token!: string | null;
public airtable_refresh_token!: string | null;
public airtable_table_id!: string | null;
public schedule!: ScheduleConfig | null;
}

Expand All @@ -79,6 +81,10 @@ Robot.init(
type: DataTypes.INTEGER,
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
recording_meta: {
type: DataTypes.JSONB,
allowNull: false,
Expand Down
6 changes: 5 additions & 1 deletion server/src/routes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function handleWorkflowActions(workflow: any[], credentials: Credentials) {
router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, res) => {
try {
const { id } = req.params;
const { name, limit, credentials, targetUrl } = req.body;
const { name, limit, credentials, targetUrl,description } = req.body;

// Validate input
if (!name && limit === undefined && !targetUrl) {
Expand Down Expand Up @@ -288,6 +288,10 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
return step;
});

if(description){
robot.set('description', description);
}

robot.set('recording', { ...robot.recording, workflow: updatedWorkflow });
robot.changed('recording', true);
}
Expand Down
12 changes: 7 additions & 5 deletions server/src/workflow-management/classes/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ export class WorkflowGenerator {
*/
private registerEventHandlers = (socket: Socket) => {
socket.on('save', (data) => {
const { fileName, userId, isLogin, robotId } = data;
const { fileName, userId, isLogin, robotId,description } = data;
logger.log('debug', `Saving workflow ${fileName} for user ID ${userId}`);
this.saveNewWorkflow(fileName, userId, isLogin, robotId);
this.saveNewWorkflow(fileName, userId, isLogin, robotId,description);
});
socket.on('new-recording', (data) => {
this.workflowRecord = {
Expand Down Expand Up @@ -767,7 +767,7 @@ export class WorkflowGenerator {
* @param fileName The name of the file.
* @returns {Promise<void>}
*/
public saveNewWorkflow = async (fileName: string, userId: number, isLogin: boolean, robotId?: string) => {
public saveNewWorkflow = async (fileName: string, userId: number, isLogin: boolean, robotId?: string,description?: string) => {
const recording = this.optimizeWorkflow(this.workflowRecord);
let actionType = 'saved';

Expand All @@ -784,10 +784,11 @@ export class WorkflowGenerator {
params: this.getParams() || [],
updatedAt: new Date().toLocaleString(),
},
description: description,
})

actionType = 'retrained';
logger.log('info', `Robot retrained with id: ${robot.id}`);
logger.log('info', `Robot retrained with id: ${robot.id} and name: ${robot.description}`);
}
} else {
this.recordingMeta = {
Expand All @@ -803,6 +804,7 @@ export class WorkflowGenerator {
userId,
recording_meta: this.recordingMeta,
recording: recording,
description: description,
});
capture(
'maxun-oss-robot-created',
Expand All @@ -813,7 +815,7 @@ export class WorkflowGenerator {
)

actionType = 'saved';
logger.log('info', `Robot saved with id: ${robot.id}`);
logger.log('info', `Robot saved with id: ${robot.id} with description: ${robot.description}`);
}
}
catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getStoredRecordings = async (): Promise<string[] | null> => {
}
};

export const updateRecording = async (id: string, data: { name?: string; limit?: number, credentials?: Credentials, targetUrl?: string }): Promise<boolean> => {
export const updateRecording = async (id: string, data: { name?: string; limit?: number, credentials?: Credentials, targetUrl?: string,description?:string }): Promise<boolean> => {
try {
const response = await axios.put(`${apiUrl}/storage/recordings/${id}`, data);
if (response.status === 200) {
Expand Down
Loading