-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch-code3.cjs
More file actions
52 lines (38 loc) · 2.42 KB
/
Copy pathpatch-code3.cjs
File metadata and controls
52 lines (38 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs');
const file = 'src/ai/circuitChatAI.js';
let code = fs.readFileSync(file, 'utf8');
const t1 = ` } else if (mcuPin && mcuPin.startsWith('A')) {
mcuPinSetups.add(\` pinMode(\${mcuPin}, INPUT); // \${compId}\`);
// ── Main Chat AI class ────────────────────────────────────────────────────────`;
const t2 = ` } else if (mcuPin && mcuPin.startsWith('A')) {
mcuPinSetups.add(\` pinMode(\${mcuPin}, INPUT); // \${compId}\`);
// ── Main Chat AI class ────────────────────────────────────────────────────────`;
const t3 = ` } else if (mcuPin && mcuPin.startsWith('A')) {
mcuPinSetups.add(\` pinMode(\${mcuPin}, INPUT); // \${compId}\`);
// ── Main Chat AI class ────────────────────────────────────────────────────────`;
const r1 = ` } else if (mcuPin && mcuPin.startsWith('A')) {
mcuPinSetups.add(\` pinMode(\${mcuPin}, INPUT); // \${compId}\`);
}
});
mcuPinSetups.forEach(s => codeStr += s + '\\n');
codeStr += \`}\\n\\nvoid loop() {\\n // Auto-generated by TinkerAI Offline Engine\\n}\\n\`;
payload.code = codeStr;
out += '\\n\`\`\`cpp\\n' + codeStr + '\`\`\`\\n';
out += \`\\n<!-- ACTION: \${JSON.stringify(payload)} -->\\n\`;
out += \`<button class="ai-action-btn" onclick="window.executeAIAction(this.parentElement)">🚀 Generate Circuit</button>\\n\`;
return out;
}
// ── Main Chat AI class ────────────────────────────────────────────────────────`;
let matched = false;
[t1, t2, t3].forEach(t => {
if (code.includes(t)) { code = code.replace(t, r1); matched = true; }
else if (code.includes(t.replace(/\n/g, '\r\n'))) { code = code.replace(t.replace(/\n/g, '\r\n'), r1.replace(/\n/g, '\r\n')); matched = true; }
});
if (!matched) {
console.error("Not found! Here is the code snippet around line 1204:");
const lines = code.split('\n');
console.error(lines.slice(1200, 1210).join('\n'));
process.exit(1);
}
fs.writeFileSync(file, code, 'utf8');
console.log("Restored successfully");