Skip to content

Commit 82f4d7d

Browse files
authored
Merge pull request #1022 from getmaxun/run-status
feat: add run status for cli and mcp
2 parents a1b2faf + d933533 commit 82f4d7d

12 files changed

Lines changed: 64 additions & 16 deletions

File tree

public/locales/de.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@
555555
"manual_run": "Manuelle Ausführung",
556556
"scheduled_run": "Geplante Ausführung",
557557
"api": "API",
558+
"sdk": "SDK",
559+
"mcp": "MCP",
560+
"cli": "CLI",
558561
"unknown_run_type": "Unbekannter Ausführungstyp"
559562
},
560563
"run_status_chips": {

public/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@
556556
"scheduled_run": "Scheduled",
557557
"api": "API",
558558
"sdk": "SDK",
559+
"mcp": "MCP",
560+
"cli": "CLI",
559561
"unknown_run_type": "Unknown Run Type"
560562
},
561563
"run_status_chips": {

public/locales/es.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@
555555
"manual_run": "Ejecución Manual",
556556
"scheduled_run": "Ejecución Programada",
557557
"api": "API",
558+
"sdk": "SDK",
559+
"mcp": "MCP",
560+
"cli": "CLI",
558561
"unknown_run_type": "Tipo de Ejecución Desconocido"
559562
},
560563
"run_status_chips": {

public/locales/ja.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@
556556
"manual_run": "手動実行",
557557
"scheduled_run": "スケジュール実行",
558558
"api": "API",
559+
"sdk": "SDK",
560+
"mcp": "MCP",
561+
"cli": "CLI",
559562
"unknown_run_type": "不明な実行タイプ"
560563
},
561564
"run_status_chips": {

public/locales/tr.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@
555555
"manual_run": "Manuel",
556556
"scheduled_run": "Zamanlanmış",
557557
"api": "API",
558+
"sdk": "SDK",
559+
"mcp": "MCP",
560+
"cli": "CLI",
558561
"unknown_run_type": "Bilinmeyen"
559562
},
560563
"run_status_chips": {

public/locales/zh.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@
556556
"manual_run": "手动运行",
557557
"scheduled_run": "计划运行",
558558
"api": "API",
559+
"sdk": "SDK",
560+
"mcp": "MCP",
561+
"cli": "CLI",
559562
"unknown_run_type": "未知运行类型"
560563
},
561564
"run_status_chips": {

server/src/api/record.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ function formatRunResponse(run: any) {
340340
runByScheduleId: run.runByScheduleId,
341341
runByAPI: run.runByAPI,
342342
runBySDK: run.runBySDK,
343+
runByMCP: run.runByMCP,
344+
runByCLI: run.runByCLI,
343345
data: {
344346
textData: {},
345347
listData: {},
@@ -477,7 +479,7 @@ router.get("/robots/:id/runs/:runId", requireAPIKey, async (req: Request, res: R
477479
}
478480
});
479481

480-
async function createWorkflowAndStoreMetadata(id: string, userId: string, isSDK: boolean) {
482+
async function createWorkflowAndStoreMetadata(id: string, userId: string, runSource: 'api' | 'sdk' | 'mcp' | 'cli') {
481483
try {
482484
const recording = await Robot.findOne({
483485
where: {
@@ -522,8 +524,10 @@ async function createWorkflowAndStoreMetadata(id: string, userId: string, isSDK:
522524
log: '',
523525
runId,
524526
runByUserId: userId,
525-
runByAPI: !isSDK,
526-
runBySDK: isSDK,
527+
runByAPI: runSource === 'api',
528+
runBySDK: runSource === 'sdk',
529+
runByMCP: runSource === 'mcp',
530+
runByCLI: runSource === 'cli',
527531
serializableOutput: {},
528532
binaryOutput: {},
529533
retryCount: 0
@@ -1194,11 +1198,11 @@ async function executeRun(id: string, userId: string, requestedFormats?: string[
11941198
}
11951199
}
11961200

1197-
export async function handleRunRecording(id: string, userId: string, isSDK: boolean = false, requestedFormats?: string[]) {
1201+
export async function handleRunRecording(id: string, userId: string, runSource: 'api' | 'sdk' | 'mcp' | 'cli' = 'api', requestedFormats?: string[]) {
11981202
let socket: Socket | null = null;
11991203

12001204
try {
1201-
const result = await createWorkflowAndStoreMetadata(id, userId, isSDK);
1205+
const result = await createWorkflowAndStoreMetadata(id, userId, runSource);
12021206
const { browserId, runId: newRunId } = result;
12031207

12041208
if (!browserId || !newRunId || !userId) {
@@ -1378,7 +1382,8 @@ router.post("/robots/:id/runs", requireAPIKey, async (req: AuthenticatedRequest,
13781382
}
13791383

13801384
const requestedFormats = req.body?.formats;
1381-
const runId = await handleRunRecording(req.params.id, req.user.id, false, requestedFormats);
1385+
const runSource = req.headers['x-run-source'] === 'mcp' ? 'mcp' : 'api';
1386+
const runId = await handleRunRecording(req.params.id, req.user.id, runSource, requestedFormats);
13821387

13831388
if (!runId) {
13841389
throw new Error('Run ID is undefined');

server/src/api/sdk.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ router.post("/sdk/robots/:id/execute", requireAPIKey, async (req: AuthenticatedR
489489

490490
logger.info(`[SDK] Starting execution for robot ${robotId}`);
491491

492-
const runId = await handleRunRecording(robotId, user.id.toString(), true);
492+
const runSource = req.headers['x-run-source'] === 'cli' ? 'cli' : 'sdk';
493+
const runId = await handleRunRecording(robotId, user.id.toString(), runSource);
493494
if (!runId) {
494495
throw new Error('Failed to start robot execution');
495496
}

server/src/mcp-worker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class MaxunMCPWorker {
3838
const headers = {
3939
'Content-Type': 'application/json',
4040
'x-api-key': this.apiKey,
41+
'x-run-source': 'mcp',
4142
...options.headers
4243
};
4344

server/src/models/Run.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface RunAttributes {
2424
runByScheduleId?: string;
2525
runByAPI?: boolean;
2626
runBySDK?: boolean;
27+
runByMCP?: boolean;
28+
runByCLI?: boolean;
2729
serializableOutput: Record<string, any>;
2830
binaryOutput: Record<string, string>;
2931
retryCount?: number;
@@ -47,6 +49,8 @@ class Run extends Model<RunAttributes, RunCreationAttributes> implements RunAttr
4749
public runByScheduleId!: string;
4850
public runByAPI!: boolean;
4951
public runBySDK!: boolean;
52+
public runByMCP!: boolean;
53+
public runByCLI!: boolean;
5054
public serializableOutput!: Record<string, any>;
5155
public binaryOutput!: Record<string, any>;
5256
public retryCount!: number;
@@ -119,6 +123,14 @@ Run.init(
119123
type: DataTypes.BOOLEAN,
120124
allowNull: true,
121125
},
126+
runByMCP: {
127+
type: DataTypes.BOOLEAN,
128+
allowNull: true,
129+
},
130+
runByCLI: {
131+
type: DataTypes.BOOLEAN,
132+
allowNull: true,
133+
},
122134
serializableOutput: {
123135
type: DataTypes.JSONB,
124136
allowNull: true,

0 commit comments

Comments
 (0)