ia_rewrite_ntapp 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +23 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -51,6 +51,10 @@ async function readClipboard() {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function normalizeClipboardText(value) {
|
|
55
|
+
return String(value ?? "").replace(/\r\n/g, "\n");
|
|
56
|
+
}
|
|
57
|
+
|
|
54
58
|
async function readClipboardWithRetry(previousValue, maxWaitMs = 1500) {
|
|
55
59
|
const start = Date.now();
|
|
56
60
|
let current = await readClipboard();
|
|
@@ -80,6 +84,22 @@ async function writeClipboard(text) {
|
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
async function writeClipboardWithVerify(text, maxWaitMs = 1500) {
|
|
88
|
+
const expected = normalizeClipboardText(text);
|
|
89
|
+
await writeClipboard(text);
|
|
90
|
+
const start = Date.now();
|
|
91
|
+
let current = normalizeClipboardText(await readClipboard());
|
|
92
|
+
while (Date.now() - start < maxWaitMs) {
|
|
93
|
+
if (current === expected) return true;
|
|
94
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
95
|
+
current = normalizeClipboardText(await readClipboard());
|
|
96
|
+
}
|
|
97
|
+
// força fallback se não confirmou
|
|
98
|
+
writeClipboardFallback(text);
|
|
99
|
+
current = normalizeClipboardText(await readClipboardFallback());
|
|
100
|
+
return current === expected;
|
|
101
|
+
}
|
|
102
|
+
|
|
83
103
|
function loadConfig() {
|
|
84
104
|
if (!fs.existsSync(CONFIG_FILE)) return null;
|
|
85
105
|
const raw = fs.readFileSync(CONFIG_FILE, "utf8").trim();
|
|
@@ -136,7 +156,9 @@ async function main() {
|
|
|
136
156
|
log("Chamando API...");
|
|
137
157
|
const rewritten = await callModel(config, original);
|
|
138
158
|
log(`Resposta recebida. Tamanho: ${rewritten.length}`);
|
|
139
|
-
await
|
|
159
|
+
const ok = await writeClipboardWithVerify(rewritten);
|
|
160
|
+
log(`Clipboard gravado: ${ok ? "ok" : "falha"}`);
|
|
161
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
140
162
|
runVbsSendKeys("^v");
|
|
141
163
|
notify("ia_rewrite_ntapp", "Texto reescrito e colado com sucesso.");
|
|
142
164
|
log("Sucesso: texto colado.");
|