ia_rewrite_ntapp 1.0.3 → 1.0.5
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 +9 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -52,8 +52,13 @@ async function readClipboard() {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
function writeClipboardFallback(text) {
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const tmpPath = path.join(os.tmpdir(), `ia_rewrite_clip_${Date.now()}_${Math.random()}.txt`);
|
|
56
|
+
fs.writeFileSync(tmpPath, String(text), "utf8");
|
|
57
|
+
try {
|
|
58
|
+
execSync(`powershell -NoProfile -Command "Set-Clipboard -Value (Get-Content -Raw -LiteralPath '${tmpPath}')"`, { encoding: "utf8" });
|
|
59
|
+
} finally {
|
|
60
|
+
try { fs.unlinkSync(tmpPath); } catch (_) {}
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
async function writeClipboard(text) {
|
|
@@ -76,6 +81,7 @@ async function callModel(config, text) {
|
|
|
76
81
|
const model = config.OPENAI_API_MODEL;
|
|
77
82
|
const apiKey = config.OPENAI_API_KEY;
|
|
78
83
|
const systemPrompt = config.SYSTEM_PROMPT;
|
|
84
|
+
const timeoutMs = Number(config.OPENAI_TIMEOUT_MS || 120000);
|
|
79
85
|
|
|
80
86
|
const payload = {
|
|
81
87
|
model,
|
|
@@ -92,7 +98,7 @@ async function callModel(config, text) {
|
|
|
92
98
|
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
|
93
99
|
|
|
94
100
|
const url = `${baseUrl}/chat/completions`;
|
|
95
|
-
const response = await axios.post(url, payload, { headers, timeout:
|
|
101
|
+
const response = await axios.post(url, payload, { headers, timeout: timeoutMs });
|
|
96
102
|
const content = response?.data?.choices?.[0]?.message?.content;
|
|
97
103
|
if (!content) throw new Error("Resposta vazia da API");
|
|
98
104
|
return String(content).trim();
|