Merge pull request #871 from getmaxun/dataout-fix

fix(maxun-core): broken backward compatibility for action names
This commit is contained in:
Karishma Shukla
2025-11-12 21:52:27 +05:30
committed by GitHub
4 changed files with 119 additions and 56 deletions

View File

@@ -116,6 +116,16 @@ export class WorkflowInterpreter {
*/
private currentScrapeListIndex: number = 0;
/**
* Track action counts to generate unique names
*/
private actionCounts: Record<string, number> = {};
/**
* Track used action names to prevent duplicates
*/
private usedActionNames: Set<string> = new Set();
/**
* Current run ID for real-time persistence
*/
@@ -379,6 +389,8 @@ export class WorkflowInterpreter {
};
this.binaryData = [];
this.currentScrapeListIndex = 0;
this.actionCounts = {};
this.usedActionNames = new Set();
this.currentRunId = null;
this.persistenceBuffer = [];
this.persistenceInProgress = false;
@@ -394,6 +406,43 @@ export class WorkflowInterpreter {
logger.log('debug', `Set run ID for real-time persistence: ${runId}`);
};
/**
* Generates a unique action name for data storage
* @param actionType The type of action (scrapeList, scrapeSchema, etc.)
* @param providedName Optional name provided by the action
* @returns A unique action name
*/
private getUniqueActionName = (actionType: string, providedName?: string | null): string => {
if (providedName && providedName.trim() !== '' && !this.usedActionNames.has(providedName)) {
this.usedActionNames.add(providedName);
return providedName;
}
if (!this.actionCounts[actionType]) {
this.actionCounts[actionType] = 0;
}
let uniqueName: string;
let counter = this.actionCounts[actionType];
do {
counter++;
if (actionType === 'scrapeList') {
uniqueName = `List ${counter}`;
} else if (actionType === 'scrapeSchema') {
uniqueName = `Text ${counter}`;
} else if (actionType === 'screenshot') {
uniqueName = `Screenshot ${counter}`;
} else {
uniqueName = `${actionType} ${counter}`;
}
} while (this.usedActionNames.has(uniqueName));
this.actionCounts[actionType] = counter;
this.usedActionNames.add(uniqueName);
return uniqueName;
};
/**
* Persists extracted data to database with intelligent batching for performance
* Falls back to immediate persistence for critical operations
@@ -525,20 +574,8 @@ export class WorkflowInterpreter {
}
let actionName = this.currentActionName || "";
if (!actionName) {
if (!Array.isArray(data) && Object.keys(data).length === 1) {
const soleKey = Object.keys(data)[0];
const soleValue = data[soleKey];
if (Array.isArray(soleValue) || typeof soleValue === "object") {
actionName = soleKey;
data = soleValue;
}
}
}
if (!actionName) {
actionName = "Unnamed Action";
if (typeKey === "scrapeList") {
actionName = this.getUniqueActionName(typeKey, this.currentActionName);
}
const flattened = Array.isArray(data)
@@ -570,9 +607,10 @@ export class WorkflowInterpreter {
const { name, data, mimeType } = payload;
const base64Data = data.toString("base64");
const uniqueName = this.getUniqueActionName('screenshot', name);
const binaryItem = {
name,
name: uniqueName,
mimeType,
data: base64Data
};
@@ -582,7 +620,7 @@ export class WorkflowInterpreter {
await this.persistBinaryDataToDatabase(binaryItem);
this.socket.emit("binaryCallback", {
name,
name: uniqueName,
data: base64Data,
mimeType
});