"use strict"; const HEADER = "// Auto-generated by Netcatty Script Recorder\n"; function escapeJsString(value) { return JSON.stringify(String(value ?? "")); } function stepsToJavaScript(steps, recordedAt) { const lines = [ HEADER.trimEnd(), recordedAt ? `// Recorded on ${recordedAt}` : "", "", "async function main() {", ].filter(Boolean); for (let index = 0; index < steps.length; index += 1) { const step = steps[index]; if (step.type === "send") { if (step.sensitive) { lines.push(` const sensitiveValue${index} = await nct.dialog.prompt("Enter sensitive value", "", { sensitive: true });`); lines.push(` await nct.screen.sendLine(sensitiveValue${index}, { sensitive: true });`); continue; } lines.push(` await nct.screen.sendLine(${escapeJsString(step.value)});`); } else if (step.type === "waitFor") { lines.push(` await nct.screen.waitForText(${escapeJsString(step.value)}, ${step.timeoutMs || 5000});`); } else if (step.type === "waitForPrompt") { lines.push(` await nct.screen.waitForPrompt(${step.timeoutMs || 30000});`); } else if (step.type === "sleep") { lines.push(` await nct.session.sleep(${Number(step.value) || 1000});`); } } lines.push("}", "", "await main();"); return lines.join("\n"); } module.exports = { stepsToJavaScript, };