webhelm 1.0.39 → 1.0.40
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/package.json
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export const PROMPT_FILE_THRESHOLD = 2000;
|
|
2
|
+
export const PROMPT_FILE_MESSAGE = 'Read prompt.md and execute the task in that file.';
|
|
3
|
+
|
|
4
|
+
export function deliveryMessage(message) {
|
|
5
|
+
return message.length > PROMPT_FILE_THRESHOLD ? PROMPT_FILE_MESSAGE : message;
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
export function targetUrl(projectId, threadId, message) {
|
|
2
9
|
if (!threadId || !message) {
|
|
3
10
|
throw new Error("thread_id and message are required");
|
|
@@ -5,7 +12,7 @@ export function targetUrl(projectId, threadId, message) {
|
|
|
5
12
|
// A thread identity is global; ChatGPT may redirect /c/id to a
|
|
6
13
|
// Project-scoped /g/project-id[-slug]/c/id. Use the ordinary URL.
|
|
7
14
|
return "https://chatgpt.com/c/" + encodeURIComponent(threadId) +
|
|
8
|
-
"?" + new URLSearchParams({ prompt: message });
|
|
15
|
+
"?" + new URLSearchParams({ prompt: deliveryMessage(message) });
|
|
9
16
|
}
|
|
10
17
|
export const PROBE_JS = `(() => {
|
|
11
18
|
const visible = e => !!e && !!e.getClientRects().length && getComputedStyle(e).visibility !== 'hidden';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DatabaseSync } from "node:sqlite";
|
|
2
|
-
import { mkdirSync, existsSync, statSync } from "node:fs";
|
|
2
|
+
import { mkdirSync, mkdtempSync, writeFileSync, rmSync, existsSync, statSync } from "node:fs";
|
|
3
3
|
import { join, resolve, isAbsolute } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
4
5
|
import { attachmentUploadScript } from "./attachment-upload.mjs";
|
|
5
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
6
|
-
import { classifyProbe, PROBE_JS, targetUrl } from "./chatgpt-probe.mjs";
|
|
7
|
+
import { classifyProbe, PROBE_JS, targetUrl, deliveryMessage, PROMPT_FILE_THRESHOLD } from "./chatgpt-probe.mjs";
|
|
7
8
|
import { SEND_ENABLED_JS } from "./lifecycle-common.mjs";
|
|
8
9
|
import { submissionScript } from "./submission-script.mjs";
|
|
9
10
|
import { DurableQueueCore } from "../durable-queue-core.mjs";
|
|
@@ -244,11 +245,22 @@ export class ChatGPTQueue extends DurableQueueCore {
|
|
|
244
245
|
const sid = this.sessions.get(item.id);
|
|
245
246
|
if (!sid) throw new Error("missing prepared browser session");
|
|
246
247
|
const attachments = JSON.parse(item.files_json || "[]");
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (
|
|
248
|
+
let tempDir;
|
|
249
|
+
try {
|
|
250
|
+
if (item.message.length > PROMPT_FILE_THRESHOLD) {
|
|
251
|
+
tempDir = mkdtempSync(join(tmpdir(), "webhelm-prompt-"));
|
|
252
|
+
const promptPath = join(tempDir, "prompt.md");
|
|
253
|
+
writeFileSync(promptPath, item.message, {encoding:"utf8",mode:0o600});
|
|
254
|
+
attachments.push(promptPath);
|
|
255
|
+
}
|
|
256
|
+
if (attachments.length) {
|
|
257
|
+
const upload = await this._exec(sid, attachmentUploadScript(attachments));
|
|
258
|
+
if (!upload?.ready) throw new Error("ChatGPT attachments not ready for Send");
|
|
259
|
+
}
|
|
260
|
+
return await this._exec(sid, submissionScript({...item, message:deliveryMessage(item.message)}));
|
|
261
|
+
} finally {
|
|
262
|
+
if (tempDir) rmSync(tempDir, {recursive:true,force:true});
|
|
250
263
|
}
|
|
251
|
-
return this._exec(sid, submissionScript(item));
|
|
252
264
|
}
|
|
253
265
|
async _finish(id) {
|
|
254
266
|
const sid = this.sessions.get(id);
|