binary-collections 2.0.9 → 2.0.10
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/binaries/binary-executor.cjs +43 -0
- package/{bin → binaries}/clean-nodemodule +0 -0
- package/binaries/clean-nodemodule.cjs +43 -0
- package/binaries/clean-nodemodule.cmd +4 -0
- package/{bin → binaries}/clean-nodemodules +0 -0
- package/binaries/clean-nodemodules.cjs +43 -0
- package/binaries/clean-nodemodules.cmd +5 -0
- package/{bin → binaries}/dev +0 -0
- package/binaries/dev.cjs +43 -0
- package/{bin → binaries}/empty +0 -0
- package/binaries/empty.cjs +43 -0
- package/{bin → binaries}/git-reduce-size +0 -0
- package/binaries/git-reduce-size.cjs +43 -0
- package/binaries/javakill.cjs +43 -0
- package/{bin → binaries}/javakill.cmd +0 -0
- package/{bin → binaries}/kill-process +0 -0
- package/binaries/kill-process.cjs +43 -0
- package/binaries/nodekill.cjs +43 -0
- package/{bin → binaries}/nodekill.ps1 +0 -0
- package/{bin → binaries}/prod +0 -0
- package/binaries/prod.cjs +43 -0
- package/{bin → binaries}/rmfind +0 -0
- package/binaries/rmfind.cjs +43 -0
- package/{bin → binaries}/rmx +0 -0
- package/binaries/rmx.cjs +43 -0
- package/{bin → binaries}/submodule-token +0 -0
- package/binaries/submodule-token.cjs +43 -0
- package/docs-src/clean-github-actions-caches.md +26 -0
- package/docs-src/free-chatgpt.md +26 -0
- package/lib/binary-collections-config.cjs +3 -2
- package/lib/binary-collections-config.mjs +2 -2
- package/lib/binary-collections.cjs +452 -105
- package/lib/binary-collections.mjs +131 -84
- package/lib/changelog.cjs +3 -3
- package/lib/changelog.mjs +177 -171
- package/lib/chunk-4EWQC6GZ.mjs +382 -0
- package/lib/chunk-4ZI7BQKQ.mjs +381 -0
- package/lib/chunk-5J2BEPY5.mjs +83 -0
- package/lib/{chunk-4BYBVEYC.mjs → chunk-66PAU5PS.mjs} +5 -4
- package/lib/chunk-6HHJRKFB.mjs +59 -0
- package/lib/chunk-6S4NXESK.mjs +26 -0
- package/lib/{chunk-ZYAQRPUL.mjs → chunk-7YD7IPFF.mjs} +2 -2
- package/lib/{chunk-SH3L6HHV.mjs → chunk-A2JQXI5Z.mjs} +2 -2
- package/lib/{chunk-EGSSKVDH.mjs → chunk-A3VUZEJK.mjs} +1 -1
- package/lib/chunk-AGZYRDC2.mjs +323 -0
- package/lib/{chunk-VVEZVNIV.mjs → chunk-AI4CVPJ7.mjs} +6 -6
- package/lib/chunk-BDCHCWHD.mjs +136 -0
- package/lib/chunk-BEZKJ25G.mjs +140 -0
- package/lib/chunk-DI5MDPSN.mjs +386 -0
- package/lib/{chunk-ONIBBBQ3.mjs → chunk-E6FDDAOO.mjs} +4 -3
- package/lib/chunk-FKI7IEB5.mjs +172 -0
- package/lib/chunk-GJTGHXRA.mjs +356 -0
- package/lib/{chunk-YV7DO3YV.mjs → chunk-HLGOWBEO.mjs} +1 -1
- package/lib/chunk-HMRMTYZM.mjs +40 -0
- package/lib/chunk-HN52G2YL.mjs +305 -0
- package/lib/chunk-HO6GHCOB.mjs +385 -0
- package/lib/chunk-LEM5OMRP.mjs +384 -0
- package/lib/{chunk-YX5U7XDR.mjs → chunk-M3YIYRHT.mjs} +6 -5
- package/lib/chunk-O6SWBEOQ.mjs +81 -0
- package/lib/{chunk-JGR2NW6D.mjs → chunk-PDSXF5HY.mjs} +3 -3
- package/lib/{chunk-AASHBCRW.mjs → chunk-QQ4A6DLD.mjs} +8 -0
- package/lib/chunk-RCP7DHVY.mjs +190 -0
- package/lib/chunk-SBNDSKG5.mjs +136 -0
- package/lib/chunk-U6SO4QEV.mjs +320 -0
- package/lib/{chunk-APBWENF6.mjs → chunk-V3N3JEUF.mjs} +3 -3
- package/lib/chunk-XD6BJK6Q.mjs +351 -0
- package/lib/chunk-XVBFFVCJ.mjs +209 -0
- package/lib/chunk-YXSFGA2D.mjs +383 -0
- package/lib/clean-github-actions-caches.cjs +243 -148
- package/lib/clean-github-actions-caches.mjs +3 -2
- package/lib/del-gradle.cjs +2 -2
- package/lib/del-gradle.js +1 -1
- package/lib/del-gradle.mjs +2 -2
- package/lib/del-node-modules.cjs +2 -2
- package/lib/del-node-modules.js +1 -1
- package/lib/del-node-modules.mjs +2 -2
- package/lib/del-ps.cjs +29 -8
- package/lib/del-ps.js +2 -2
- package/lib/del-ps.mjs +7 -5
- package/lib/del-yarn-caches.cjs +26 -5
- package/lib/del-yarn-caches.js +38 -3
- package/lib/del-yarn-caches.mjs +6 -6
- package/lib/find-node-modules-cli.cjs +5 -4
- package/lib/find-node-modules-cli.js +1 -1
- package/lib/find-node-modules-cli.mjs +2 -2
- package/lib/find-node-modules.cjs +4 -3
- package/lib/{find-node-modules.d.ts → find-node-modules.d.cts} +1 -1
- package/lib/find-node-modules.mjs +2 -2
- package/lib/free-chatgpt.cjs +548 -0
- package/lib/free-chatgpt.js +51 -0
- package/lib/free-chatgpt.mjs +50 -0
- package/lib/git/gitattributes.cjs +1 -1
- package/lib/git/{gitattributes.d.mts → gitattributes.d.cts} +5 -7
- package/lib/git/gitattributes.mjs +2 -2
- package/lib/git/line-endings.cjs +297 -64
- package/lib/git/line-endings.mjs +4 -4
- package/lib/git/normalize.cjs +26 -36
- package/lib/git/normalize.mjs +2 -2
- package/lib/git/permissions.cjs +77 -11
- package/lib/git/permissions.mjs +3 -3
- package/lib/git/pull-strategy.cjs +76 -9
- package/lib/git/pull-strategy.mjs +3 -3
- package/lib/git/user-config.cjs +266 -83
- package/lib/git/user-config.mjs +4 -4
- package/lib/git/utils.cjs +40 -60
- package/lib/git/utils.mjs +2 -2
- package/lib/git-diff-cli.cjs +651 -0
- package/lib/git-diff-cli.d.ts +1 -0
- package/lib/git-diff-cli.js +15 -0
- package/lib/git-diff-cli.mjs +16 -0
- package/lib/git-diff.cjs +657 -58
- package/lib/git-diff.d.ts +38 -83
- package/lib/git-diff.js +152 -0
- package/lib/git-diff.mjs +23 -85
- package/lib/git-fix.cjs +685 -97
- package/lib/git-fix.mjs +14 -13
- package/lib/git-purge.cjs +3 -3
- package/lib/git-purge.d.cts +1 -0
- package/lib/git-purge.mjs +43 -37
- package/lib/index.cjs +7 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -5
- package/lib/index.mjs +4 -4
- package/lib/npm-run-series.cjs +3 -3
- package/lib/npm-run-series.mjs +42 -36
- package/lib/package-resolutions-updater.cjs +5 -5
- package/lib/package-resolutions-updater.mjs +266 -309
- package/lib/print-directory-tree.cjs +275 -210
- package/lib/print-directory-tree.mjs +2 -2
- package/lib/ps/connected-domain.cjs +25 -2
- package/lib/ps/connected-domain.d.ts +10 -2
- package/lib/ps/connected-domain.js +5 -2
- package/lib/ps/connected-domain.mjs +8 -4
- package/lib/ps/index.cjs +345 -322
- package/lib/ps/index.d.mjs +1 -1
- package/lib/ps/index.js +1 -1
- package/lib/ps/index.mjs +179 -182
- package/lib/ps/isWin.cjs +24 -1
- package/lib/ps/isWin.d.ts +1 -1
- package/lib/ps/isWin.js +3 -1
- package/lib/ps/isWin.mjs +8 -4
- package/lib/ps/table-parser.cjs +167 -159
- package/lib/ps/table-parser.d.ts +5 -0
- package/lib/ps/table-parser.js +10 -4
- package/lib/ps/table-parser.mjs +9 -5
- package/lib/remove-module.cjs +262 -0
- package/lib/remove-module.d.mts +1 -0
- package/lib/remove-module.mjs +111 -0
- package/lib/rmpath.cjs +274 -0
- package/lib/rmpath.d.mts +3 -0
- package/lib/rmpath.mjs +108 -0
- package/lib/submodule-install.cjs +264 -86
- package/lib/submodule-install.mjs +51 -3
- package/lib/submodule-remove-cli.cjs +103 -0
- package/lib/submodule-remove-cli.d.ts +1 -0
- package/lib/submodule-remove-cli.js +31 -0
- package/lib/submodule-remove-cli.mjs +28 -0
- package/lib/submodule-remove.cjs +43 -0
- package/lib/submodule-remove.d.cts +2 -0
- package/lib/submodule-remove.mjs +6 -0
- package/lib/utils/chatgpt.cjs +383 -0
- package/lib/utils/chatgpt.d.ts +31 -0
- package/lib/utils/chatgpt.js +541 -0
- package/lib/utils/chatgpt.mjs +8 -0
- package/lib/{utils.cjs → utils/index.cjs} +1 -1
- package/lib/{utils.mjs → utils/index.mjs} +2 -2
- package/lib/yarn-reinstall.cjs +172 -38
- package/lib/yarn-reinstall.mjs +2 -2
- package/package.json +91 -71
- package/readme.md +43 -69
- package/releases/readme.md +36 -0
- package/test/README.md +101 -0
- package/test/package.json +2 -1
- package/test-project/readme.md +26 -0
- package/tmp/test-repo/README.md +35 -0
- package/tmp/test-repo/package.json +1 -1
- package/tmp/typedoc/readme.md +320 -0
- package/bin/bash-dummy +0 -56
- package/bin/bash-dummy.cmd +0 -25
- package/bin/dir-tree.cmd +0 -7
- package/bin/git-diff +0 -4
- package/bin/git-diff.cmd +0 -7
- package/bin/git-fix +0 -36
- package/bin/git-fix.cmd +0 -7
- package/bin/rmpath +0 -70
- package/bin/submodule-install.txt +0 -118
- package/bin/submodule-remove +0 -46
- package/bin/submodule.txt +0 -172
- package/lib/binary-collections-config.d.mts +0 -18
- package/lib/binary-collections-config.js +0 -39
- package/lib/binary-collections.d.mts +0 -137
- package/lib/binary-collections.d.ts +0 -137
- package/lib/changelog.d.mts +0 -2
- package/lib/changelog.js +0 -226
- package/lib/chunk-DPKAJKFO.mjs +0 -171
- package/lib/chunk-G3THLIDT.mjs +0 -200
- package/lib/chunk-W3ENOM53.mjs +0 -18
- package/lib/clean-github-actions-caches.d.mts +0 -169
- package/lib/clean-github-actions-caches.d.ts +0 -169
- package/lib/del-gradle.d.mts +0 -2
- package/lib/del-node-modules.d.mts +0 -2
- package/lib/del-ps.d.mts +0 -2
- package/lib/del-yarn-caches.d.mts +0 -2
- package/lib/find-node-modules-cli.d.mts +0 -1
- package/lib/find-node-modules.d.mts +0 -13
- package/lib/find-node-modules.js +0 -53
- package/lib/git/line-endings.d.mts +0 -83
- package/lib/git/line-endings.d.ts +0 -83
- package/lib/git/normalize.d.mts +0 -43
- package/lib/git/normalize.d.ts +0 -43
- package/lib/git/permissions.d.mts +0 -17
- package/lib/git/permissions.d.ts +0 -17
- package/lib/git/pull-strategy.d.mts +0 -15
- package/lib/git/pull-strategy.d.ts +0 -15
- package/lib/git/user-config.d.mts +0 -105
- package/lib/git/user-config.d.ts +0 -105
- package/lib/git/utils.d.mts +0 -69
- package/lib/git/utils.d.ts +0 -69
- package/lib/git-diff.d.mts +0 -84
- package/lib/git-fix.d.mts +0 -141
- package/lib/git-fix.d.ts +0 -141
- package/lib/git-purge.d.mts +0 -2
- package/lib/git-purge.js +0 -59
- package/lib/index.d.mts +0 -1
- package/lib/npm-run-series.d.mts +0 -1
- package/lib/npm-run-series.d.ts +0 -2
- package/lib/npm-run-series.js +0 -86
- package/lib/package-resolutions-updater.d.ts +0 -352
- package/lib/print-directory-tree.d.mts +0 -234
- package/lib/print-directory-tree.d.ts +0 -234
- package/lib/ps/connected-domain.d.mts +0 -3
- package/lib/ps/index.d.d.mts +0 -26
- package/lib/ps/index.d.d.ts +0 -26
- package/lib/ps/index.d.mts +0 -26
- package/lib/ps/isWin.d.mts +0 -3
- package/lib/ps/table-parser.d.mts +0 -3
- package/lib/submodule-install.d.mts +0 -121
- package/lib/submodule-install.d.ts +0 -121
- package/lib/utils.d.mts +0 -40
- package/lib/utils.js +0 -181
- package/lib/yarn-reinstall.d.mts +0 -49
- package/lib/yarn-reinstall.d.ts +0 -49
- package/src/package-resolutions-updater.mjs +0 -350
- package/src/print-directory-tree.cjs +0 -234
- package/src/ps/index.js +0 -286
- package/src/yarn-reinstall.cjs +0 -49
- /package/{bin → binaries}/nodekill +0 -0
- /package/{bin → binaries}/nodekill.cmd +0 -0
- /package/lib/{binary-collections-config.d.ts → binary-collections-config.d.cts} +0 -0
- /package/lib/{changelog.d.ts → changelog.d.cts} +0 -0
- /package/lib/{git-purge.d.ts → free-chatgpt.d.ts} +0 -0
- /package/lib/{git-diff.d.cts → npm-run-series.d.cts} +0 -0
- /package/lib/{utils.d.ts → utils/index.d.cts} +0 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
__require,
|
|
4
|
+
init_esm_shims
|
|
5
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
6
|
+
|
|
7
|
+
// src/utils/chatgpt.js
|
|
8
|
+
init_esm_shims();
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
import puppeteer from "puppeteer-extra";
|
|
11
|
+
import StealthPlugin from "puppeteer-extra-plugin-stealth";
|
|
12
|
+
import path from "upath";
|
|
13
|
+
import { pathToFileURL } from "url";
|
|
14
|
+
var COOKIE_DIR = path.join(process.cwd(), "tmp", "cookies");
|
|
15
|
+
var DEFAULT_COOKIE_PATH = path.join(COOKIE_DIR, "cookies.json");
|
|
16
|
+
fs.ensureDirSync(COOKIE_DIR);
|
|
17
|
+
async function saveCookies(page, path2 = DEFAULT_COOKIE_PATH) {
|
|
18
|
+
const cookies = await page.cookies();
|
|
19
|
+
fs.writeFileSync(path2, JSON.stringify(cookies, null, 2));
|
|
20
|
+
}
|
|
21
|
+
function getCookiePathForUrl(url) {
|
|
22
|
+
try {
|
|
23
|
+
const { hostname } = new URL(url);
|
|
24
|
+
return path.join(COOKIE_DIR, `cookies_${hostname}.json`);
|
|
25
|
+
} catch {
|
|
26
|
+
return DEFAULT_COOKIE_PATH;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function navigatePage(page, url) {
|
|
30
|
+
const cookiePath = getCookiePathForUrl(url);
|
|
31
|
+
const cookies = loadCookies(cookiePath);
|
|
32
|
+
if (cookies) {
|
|
33
|
+
await page.setCookie(...cookies);
|
|
34
|
+
}
|
|
35
|
+
await page.goto(url, { waitUntil: "networkidle0" });
|
|
36
|
+
await page.evaluate(() => {
|
|
37
|
+
window.__domStillUpdating = true;
|
|
38
|
+
if (window.__domObserver) {
|
|
39
|
+
window.__domObserver.disconnect();
|
|
40
|
+
}
|
|
41
|
+
window.__domObserver = new MutationObserver(() => {
|
|
42
|
+
window.__lastDomMutation = Date.now();
|
|
43
|
+
});
|
|
44
|
+
window.__lastDomMutation = Date.now();
|
|
45
|
+
window.__domObserver.observe(document.body, {
|
|
46
|
+
childList: true,
|
|
47
|
+
subtree: true,
|
|
48
|
+
attributes: true,
|
|
49
|
+
characterData: true
|
|
50
|
+
});
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
window.__domStillUpdating = false;
|
|
53
|
+
window.__domObserver.disconnect();
|
|
54
|
+
}, 3e4);
|
|
55
|
+
});
|
|
56
|
+
const waitForDomIdle = async (idleMs = 1e3, timeout = 1e4) => {
|
|
57
|
+
const start = Date.now();
|
|
58
|
+
while (Date.now() - start < timeout) {
|
|
59
|
+
const lastMutation = await page.evaluate(() => window.__lastDomMutation);
|
|
60
|
+
const idle = Date.now() - lastMutation;
|
|
61
|
+
if (idle >= idleMs) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
65
|
+
}
|
|
66
|
+
throw new Error("DOM did not stabilize within timeout");
|
|
67
|
+
};
|
|
68
|
+
return { waitForDomIdle };
|
|
69
|
+
}
|
|
70
|
+
function loadCookies(cookieFilePath = DEFAULT_COOKIE_PATH) {
|
|
71
|
+
if (!fs.existsSync(cookieFilePath)) return null;
|
|
72
|
+
return JSON.parse(fs.readFileSync(cookieFilePath));
|
|
73
|
+
}
|
|
74
|
+
async function writeQuestion(page, question) {
|
|
75
|
+
const questions = question.split("\n");
|
|
76
|
+
const promptTextarea = await page.waitForSelector("#prompt-textarea", { timeout: 3e4 });
|
|
77
|
+
if (!promptTextarea) {
|
|
78
|
+
console.log(
|
|
79
|
+
"Cannot find the prompt input on the webpage. Please check whether you have access to chat.openai.com without logging in via your browser."
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
await page.evaluate(() => {
|
|
83
|
+
document.querySelector("#prompt-textarea").innerHTML = `<p></p>`;
|
|
84
|
+
});
|
|
85
|
+
if (questions.length === 1) {
|
|
86
|
+
await page.type("#prompt-textarea", questions[0], { delay: 100 });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
for (const q of questions) {
|
|
90
|
+
await page.type("#prompt-textarea", q, { delay: 100 });
|
|
91
|
+
if (q !== questions[questions.length - 1]) {
|
|
92
|
+
await page.keyboard.down("Shift");
|
|
93
|
+
await page.keyboard.press("Enter");
|
|
94
|
+
await page.keyboard.up("Shift");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function clickSubmitButton(page) {
|
|
99
|
+
try {
|
|
100
|
+
const fruitjuiceSendButton = await page.evaluate(() => {
|
|
101
|
+
return document.querySelector('[data-testid="fruitjuice-send-button"]') !== null;
|
|
102
|
+
});
|
|
103
|
+
const sendButton = await page.evaluate(() => {
|
|
104
|
+
return document.querySelector('[data-testid="send-button"]') !== null;
|
|
105
|
+
});
|
|
106
|
+
if (fruitjuiceSendButton) {
|
|
107
|
+
await page.click('[data-testid="fruitjuice-send-button"]');
|
|
108
|
+
} else if (sendButton) {
|
|
109
|
+
await page.click('[data-testid="send-button"]');
|
|
110
|
+
} else {
|
|
111
|
+
console.log("Neither send button is present");
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.log(`Failed to click the send button: ${e}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
var lastMessageId = null;
|
|
118
|
+
var messageCount = 0;
|
|
119
|
+
var is_streaming = false;
|
|
120
|
+
function sleep(ms) {
|
|
121
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
122
|
+
}
|
|
123
|
+
async function waitForInitialResponse(page, timeout = 3e4) {
|
|
124
|
+
const startTime = Date.now();
|
|
125
|
+
while (Date.now() - startTime < timeout) {
|
|
126
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
127
|
+
const currentMessageCount = assistantMessages.length;
|
|
128
|
+
if (currentMessageCount > messageCount) {
|
|
129
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
130
|
+
const isThinking = await lastMessage.$(".result-thinking");
|
|
131
|
+
if (!isThinking) {
|
|
132
|
+
lastMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
133
|
+
messageCount = currentMessageCount;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
await sleep(100);
|
|
138
|
+
}
|
|
139
|
+
console.log("Timed out waiting for the initial response.");
|
|
140
|
+
}
|
|
141
|
+
async function handleStreamingResponse(page, outputFile = path.join(process.cwd(), "tmp/response.txt")) {
|
|
142
|
+
let previousText = "";
|
|
143
|
+
let completeResponse = "";
|
|
144
|
+
let newContentDetected = false;
|
|
145
|
+
while (!newContentDetected) {
|
|
146
|
+
const assistantMessages = await page.$$('[data-message-author-role="assistant"]');
|
|
147
|
+
if (assistantMessages.length > 0) {
|
|
148
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
149
|
+
const currentMessageId = await page.evaluate((element) => element.getAttribute("data-message-id"), lastMessage);
|
|
150
|
+
if (currentMessageId === lastMessageId) {
|
|
151
|
+
const currentText = await page.evaluate((element) => element.textContent, lastMessage);
|
|
152
|
+
console.log(`Current text: ${currentText}`);
|
|
153
|
+
if (currentText !== previousText) {
|
|
154
|
+
if (is_streaming) {
|
|
155
|
+
process.stdout.write(currentText.slice(previousText.length));
|
|
156
|
+
} else {
|
|
157
|
+
completeResponse += currentText.slice(previousText.length);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
previousText = currentText;
|
|
161
|
+
const isStreaming = await lastMessage.$(".result-streaming");
|
|
162
|
+
if (!isStreaming) {
|
|
163
|
+
newContentDetected = true;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
lastMessageId = currentMessageId;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
await sleep(100);
|
|
170
|
+
}
|
|
171
|
+
if (!is_streaming) {
|
|
172
|
+
console.log(completeResponse.trim());
|
|
173
|
+
console.log("\n\n");
|
|
174
|
+
fs.ensureDirSync(path.dirname(outputFile));
|
|
175
|
+
fs.writeFileSync(outputFile, completeResponse.trim());
|
|
176
|
+
console.log(`Response saved to ${outputFile}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function isLoggedIn(page) {
|
|
180
|
+
const result = await page.evaluate(() => {
|
|
181
|
+
const loginButton = document.querySelector('[data-testid="login-button"]');
|
|
182
|
+
return !(loginButton && loginButton.offsetParent !== null);
|
|
183
|
+
});
|
|
184
|
+
return result === true;
|
|
185
|
+
}
|
|
186
|
+
async function createBrowser(browserOptions = {}) {
|
|
187
|
+
const defaultOptions = {
|
|
188
|
+
headless: false,
|
|
189
|
+
userDataDir: path.join(process.cwd(), "tmp/puppeteer-profile"),
|
|
190
|
+
// Windows-specific options to help with browser launch issues
|
|
191
|
+
args: [
|
|
192
|
+
"--no-sandbox",
|
|
193
|
+
"--disable-setuid-sandbox",
|
|
194
|
+
"--disable-dev-shm-usage",
|
|
195
|
+
"--disable-accelerated-2d-canvas",
|
|
196
|
+
"--no-first-run",
|
|
197
|
+
"--no-zygote",
|
|
198
|
+
"--disable-gpu"
|
|
199
|
+
]
|
|
200
|
+
};
|
|
201
|
+
return await puppeteer.use(StealthPlugin()).launch({ ...defaultOptions, ...browserOptions });
|
|
202
|
+
}
|
|
203
|
+
async function loginToChatGpt() {
|
|
204
|
+
const browser = await createBrowser({ headless: false });
|
|
205
|
+
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
206
|
+
const url = "https://chat.openai.com";
|
|
207
|
+
const navigate = await navigatePage(page, url);
|
|
208
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
209
|
+
const loginButtonExists = await page.evaluate(() => {
|
|
210
|
+
return document.querySelector('[data-testid="login-button"]') !== null;
|
|
211
|
+
});
|
|
212
|
+
if (loginButtonExists) {
|
|
213
|
+
console.log("Login button found, clicking to log in...");
|
|
214
|
+
await page.click('[data-testid="login-button"]');
|
|
215
|
+
await page.waitForNavigation({ waitUntil: "networkidle0" });
|
|
216
|
+
console.log("Login process completed.");
|
|
217
|
+
} else {
|
|
218
|
+
console.log("No login required - user appears to be already logged in.");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
async function runChatGpt(chatgptOptions = {}) {
|
|
222
|
+
const headless = chatgptOptions.headless !== void 0 ? chatgptOptions.headless : true;
|
|
223
|
+
const questionFile = chatgptOptions.questionFile;
|
|
224
|
+
let question = chatgptOptions.question;
|
|
225
|
+
const responseFile = chatgptOptions.responseFile || path.join(process.cwd(), "tmp", "response.txt");
|
|
226
|
+
const noInputProvided = !question && !questionFile;
|
|
227
|
+
const questionIsEmpty = question && question.trim().length === 0;
|
|
228
|
+
const questionFileIsEmpty = questionFile && questionFile.trim().length === 0;
|
|
229
|
+
if (noInputProvided || questionIsEmpty || questionFileIsEmpty) {
|
|
230
|
+
throw new Error("You must provide a question or a question file.");
|
|
231
|
+
}
|
|
232
|
+
let browser;
|
|
233
|
+
try {
|
|
234
|
+
browser = await createBrowser({ headless });
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (error.message.includes("Failed to launch the browser process")) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`Failed to launch browser. This is often a Windows-specific issue. Try:
|
|
239
|
+
1. Install Google Chrome or Chromium
|
|
240
|
+
2. Run with --no-headless flag for visible browser mode
|
|
241
|
+
3. Restart your terminal/command prompt
|
|
242
|
+
Original error: ${error.message}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
const page = (await browser.pages()).length > 0 ? (await browser.pages())[0] : await browser.newPage();
|
|
248
|
+
const url = "https://chat.openai.com";
|
|
249
|
+
const navigate = await navigatePage(page, url);
|
|
250
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
251
|
+
try {
|
|
252
|
+
const tempChatButton = await page.$('button[aria-label="Turn on temporary chat"]');
|
|
253
|
+
if (tempChatButton) {
|
|
254
|
+
await page.evaluate((el) => el.click(), tempChatButton);
|
|
255
|
+
console.log("Successfully clicked temporary chat button");
|
|
256
|
+
await navigate.waitForDomIdle(1e3, 1e4);
|
|
257
|
+
} else {
|
|
258
|
+
console.log("Temporary chat button not found, proceeding without it.");
|
|
259
|
+
}
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.log(`Failed to click temporary chat button: ${error.message}`);
|
|
262
|
+
}
|
|
263
|
+
if (question) {
|
|
264
|
+
await writeQuestion(page, question);
|
|
265
|
+
await clickSubmitButton(page);
|
|
266
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
267
|
+
await waitForInitialResponse(page);
|
|
268
|
+
await handleStreamingResponse(page, responseFile);
|
|
269
|
+
await saveCookies(page, getCookiePathForUrl(url));
|
|
270
|
+
} else if (questionFile) {
|
|
271
|
+
await navigate.waitForDomIdle(2e3, 1e4);
|
|
272
|
+
const isUserLoggedIn = await isLoggedIn(page);
|
|
273
|
+
console.log(`Login status: ${isUserLoggedIn ? "Logged in" : "Not logged in"}`);
|
|
274
|
+
if (!isUserLoggedIn) {
|
|
275
|
+
console.log(
|
|
276
|
+
"Not logged in. Please log in to ChatGPT in the browser window, then close it and run the command again."
|
|
277
|
+
);
|
|
278
|
+
return loginToChatGpt();
|
|
279
|
+
}
|
|
280
|
+
const plusButtonExists = await page.evaluate(() => {
|
|
281
|
+
const button = document.querySelector('[data-testid="composer-plus-btn"]');
|
|
282
|
+
return button !== null;
|
|
283
|
+
});
|
|
284
|
+
if (plusButtonExists) {
|
|
285
|
+
await page.click('[data-testid="composer-plus-btn"]');
|
|
286
|
+
await sleep(500);
|
|
287
|
+
const menuItems = await page.$$('[role="menuitem"]');
|
|
288
|
+
let clicked = false;
|
|
289
|
+
for (const item of menuItems) {
|
|
290
|
+
const text = await page.evaluate((el) => el.innerText, item);
|
|
291
|
+
if (text && text.includes("Add photos") && text.includes("files")) {
|
|
292
|
+
await item.hover();
|
|
293
|
+
clicked = true;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (!clicked) {
|
|
298
|
+
console.log('Could not find the "Add photos & files" menu item.');
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
await sleep(1e3);
|
|
303
|
+
const fileInput = await page.waitForSelector('input[type="file"]', { timeout: 1e4 });
|
|
304
|
+
if (fileInput) {
|
|
305
|
+
console.log(`Uploading file: ${questionFile}`);
|
|
306
|
+
await fileInput.uploadFile(questionFile);
|
|
307
|
+
await navigate.waitForDomIdle(2e3, 15e3);
|
|
308
|
+
console.log("File uploaded successfully");
|
|
309
|
+
await clickSubmitButton(page);
|
|
310
|
+
await navigate.waitForDomIdle(1e3, 3e4);
|
|
311
|
+
await waitForInitialResponse(page);
|
|
312
|
+
await handleStreamingResponse(page, responseFile);
|
|
313
|
+
} else {
|
|
314
|
+
console.log("Could not find file input element");
|
|
315
|
+
}
|
|
316
|
+
} catch (error) {
|
|
317
|
+
console.log(`Error uploading file: ${error.message}`);
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
console.log('Could not find the [data-testid="composer-plus-btn"] button.');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
await browser.close();
|
|
324
|
+
}
|
|
325
|
+
var isMain = false;
|
|
326
|
+
try {
|
|
327
|
+
if (typeof __require !== "undefined" && typeof module !== "undefined" && __require.main === module) {
|
|
328
|
+
isMain = true;
|
|
329
|
+
}
|
|
330
|
+
} catch (_e) {
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
const mainArg = process.argv[1] && path.resolve(process.argv[1]);
|
|
334
|
+
if (mainArg && import.meta.url === pathToFileURL(mainArg).href) {
|
|
335
|
+
isMain = true;
|
|
336
|
+
}
|
|
337
|
+
} catch (_e) {
|
|
338
|
+
}
|
|
339
|
+
if (isMain) {
|
|
340
|
+
(async () => {
|
|
341
|
+
try {
|
|
342
|
+
await runChatGpt({ headless: false, questionFile: path.join(process.cwd(), "tmp/gpt-question.txt") });
|
|
343
|
+
} catch (error) {
|
|
344
|
+
console.error("Error running ChatGPT:", error);
|
|
345
|
+
}
|
|
346
|
+
})();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export {
|
|
350
|
+
runChatGpt
|
|
351
|
+
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
connected_domain_default,
|
|
4
|
+
init_connected_domain
|
|
5
|
+
} from "./chunk-FKI7IEB5.mjs";
|
|
6
|
+
import {
|
|
7
|
+
__esm,
|
|
8
|
+
__export,
|
|
9
|
+
init_esm_shims
|
|
10
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
11
|
+
|
|
12
|
+
// src/ps/table-parser.js
|
|
13
|
+
var table_parser_exports = {};
|
|
14
|
+
__export(table_parser_exports, {
|
|
15
|
+
parse: () => parse
|
|
16
|
+
});
|
|
17
|
+
function parse(output) {
|
|
18
|
+
var linesTmp = output.split(/(\r\n)|(\n\r)|\n|\r/);
|
|
19
|
+
var lines = [];
|
|
20
|
+
var titleInfo = {};
|
|
21
|
+
var twoDimArray = [];
|
|
22
|
+
linesTmp.forEach(function(line) {
|
|
23
|
+
if (line && line.trim()) {
|
|
24
|
+
lines.push(line);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
lines.forEach(function(line, index) {
|
|
28
|
+
if (index == 0) {
|
|
29
|
+
var fields = line.split(/\s+/);
|
|
30
|
+
var currentIndex = 0;
|
|
31
|
+
fields.forEach(function(field, idx) {
|
|
32
|
+
if (field) {
|
|
33
|
+
var info = titleInfo[field] = {};
|
|
34
|
+
var indexBegin = line.indexOf(field, currentIndex);
|
|
35
|
+
var indexEnd = currentIndex = indexBegin + field.length;
|
|
36
|
+
if (idx == 0) {
|
|
37
|
+
info.titleBegin = 0;
|
|
38
|
+
} else {
|
|
39
|
+
info.titleBegin = indexBegin;
|
|
40
|
+
}
|
|
41
|
+
if (idx == fields.length - 1) {
|
|
42
|
+
info.titleEnd = line.length - 1;
|
|
43
|
+
} else {
|
|
44
|
+
info.titleEnd = indexEnd;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
twoDimArray[index - 1] = line.split("");
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
var connectedDomains = connected_domain_default(
|
|
53
|
+
twoDimArray,
|
|
54
|
+
function(value) {
|
|
55
|
+
if (EMPTY_EX.test(value)) {
|
|
56
|
+
return -1;
|
|
57
|
+
} else {
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
true
|
|
62
|
+
);
|
|
63
|
+
var valuesDomainsVerticalGroups = [];
|
|
64
|
+
connectedDomains.domains.sort(function(a, b) {
|
|
65
|
+
return a.bounding.x - b.bounding.x;
|
|
66
|
+
});
|
|
67
|
+
connectedDomains.domains.forEach(function(domain) {
|
|
68
|
+
if (domain.identifier === 1) {
|
|
69
|
+
var overlapped = false;
|
|
70
|
+
valuesDomainsVerticalGroups.forEach(function(group) {
|
|
71
|
+
var bounding = domain.bounding;
|
|
72
|
+
var left = bounding.x;
|
|
73
|
+
var right = bounding.x + bounding.w;
|
|
74
|
+
if (overlap(left, right, group.begin, group.end)) {
|
|
75
|
+
overlapped = true;
|
|
76
|
+
group.domains.push(domain);
|
|
77
|
+
group.begin = group.begin > left ? left : group.begin;
|
|
78
|
+
group.end = group.end < right ? right : group.end;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (!overlapped) {
|
|
82
|
+
valuesDomainsVerticalGroups.push({
|
|
83
|
+
begin: domain.bounding.x,
|
|
84
|
+
end: domain.bounding.x + domain.bounding.w,
|
|
85
|
+
domains: [domain]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
valuesDomainsVerticalGroups.forEach(function(group) {
|
|
91
|
+
var title = null;
|
|
92
|
+
var info = null;
|
|
93
|
+
var overlapped = false;
|
|
94
|
+
var minimunLeftDistance = null;
|
|
95
|
+
var nearestLeftTitle = null;
|
|
96
|
+
var distance = null;
|
|
97
|
+
for (title in titleInfo) {
|
|
98
|
+
info = titleInfo[title];
|
|
99
|
+
if (group.begin > info.titleBegin) {
|
|
100
|
+
distance = group.begin - info.titleBegin;
|
|
101
|
+
if (!nearestLeftTitle || distance < minimunLeftDistance) {
|
|
102
|
+
nearestLeftTitle = title;
|
|
103
|
+
minimunLeftDistance = distance;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (overlap(group.begin, group.end, info.titleBegin, info.titleEnd)) {
|
|
107
|
+
overlapped = true;
|
|
108
|
+
info.titleBegin = info.titleBegin > group.begin ? group.begin : info.titleBegin;
|
|
109
|
+
info.titleEnd = info.titleEnd < group.end ? group.end : info.titleEnd;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!overlapped && nearestLeftTitle) {
|
|
113
|
+
var nearestTitleField = titleInfo[nearestLeftTitle];
|
|
114
|
+
nearestTitleField.titleBegin = nearestTitleField.titleBegin > group.begin ? group.begin : nearestTitleField.titleBegin;
|
|
115
|
+
nearestTitleField.titleEnd = nearestTitleField.titleEnd < group.end ? group.end : nearestTitleField.titleEnd;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
var result = [];
|
|
119
|
+
lines.forEach(function(line, index) {
|
|
120
|
+
if (index > 0) {
|
|
121
|
+
var lineItem = {};
|
|
122
|
+
var title = null;
|
|
123
|
+
var info = null;
|
|
124
|
+
var value = null;
|
|
125
|
+
for (title in titleInfo) {
|
|
126
|
+
info = titleInfo[title];
|
|
127
|
+
value = line.substring(info.titleBegin, info.titleEnd + 1);
|
|
128
|
+
lineItem[title] = splitValue(value.trim());
|
|
129
|
+
}
|
|
130
|
+
result.push(lineItem);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
function overlap(begin1, end1, begin2, end2) {
|
|
136
|
+
return begin1 > begin2 && begin1 < end2 || // 2--1--2--1 or 2--1--1--2
|
|
137
|
+
end1 > begin2 && end1 < end2 || // 1--2--1--2 or 2--1--1--2
|
|
138
|
+
begin1 <= begin2 && end1 >= end2;
|
|
139
|
+
}
|
|
140
|
+
function splitValue(value) {
|
|
141
|
+
var match = value.match(/"/g);
|
|
142
|
+
if (!match || match.length == 1) {
|
|
143
|
+
return value.split(/\s+/);
|
|
144
|
+
} else {
|
|
145
|
+
var result = [];
|
|
146
|
+
var chunk = null;
|
|
147
|
+
var ifInWrappedChunk = false;
|
|
148
|
+
var ifInPureWrappedChunk = false;
|
|
149
|
+
var quotaCount = 0;
|
|
150
|
+
var maxQuotaCount = match.length % 2 == 0 ? match.length : match.length - 1;
|
|
151
|
+
var previousItem = null;
|
|
152
|
+
var values = value.split("");
|
|
153
|
+
values.forEach(function(item, index) {
|
|
154
|
+
if (item !== " ") {
|
|
155
|
+
if (item === '"') {
|
|
156
|
+
if (ifInWrappedChunk === false && quotaCount <= maxQuotaCount) {
|
|
157
|
+
ifInWrappedChunk = true;
|
|
158
|
+
quotaCount++;
|
|
159
|
+
if (previousItem === " " || previousItem === null) {
|
|
160
|
+
ifInPureWrappedChunk = true;
|
|
161
|
+
chunk = "";
|
|
162
|
+
} else {
|
|
163
|
+
chunk += item;
|
|
164
|
+
}
|
|
165
|
+
} else if (ifInWrappedChunk === true) {
|
|
166
|
+
ifInWrappedChunk = false;
|
|
167
|
+
quotaCount++;
|
|
168
|
+
if (ifInPureWrappedChunk === true) {
|
|
169
|
+
ifInPureWrappedChunk = false;
|
|
170
|
+
result.push(chunk);
|
|
171
|
+
chunk = null;
|
|
172
|
+
} else {
|
|
173
|
+
chunk += item;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} else if (ifInWrappedChunk === false && (previousItem === " " || previousItem === null)) {
|
|
177
|
+
chunk = item;
|
|
178
|
+
} else {
|
|
179
|
+
chunk += item;
|
|
180
|
+
}
|
|
181
|
+
} else if (ifInWrappedChunk) {
|
|
182
|
+
chunk += item;
|
|
183
|
+
} else if (chunk !== null) {
|
|
184
|
+
result.push(chunk);
|
|
185
|
+
chunk = null;
|
|
186
|
+
}
|
|
187
|
+
previousItem = item;
|
|
188
|
+
if (index == values.length - 1 && chunk !== null) {
|
|
189
|
+
result.push(chunk);
|
|
190
|
+
chunk = null;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
var EMPTY_EX;
|
|
197
|
+
var init_table_parser = __esm({
|
|
198
|
+
"src/ps/table-parser.js"() {
|
|
199
|
+
init_esm_shims();
|
|
200
|
+
init_connected_domain();
|
|
201
|
+
EMPTY_EX = /\s/;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
export {
|
|
206
|
+
parse,
|
|
207
|
+
table_parser_exports,
|
|
208
|
+
init_table_parser
|
|
209
|
+
};
|