@apmantza/greedysearch-pi 2.0.0 → 2.1.2
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/CHANGELOG.md +54 -3
- package/README.md +2 -2
- package/bin/search.mjs +121 -13
- package/extractors/bing-copilot.mjs +6 -14
- package/extractors/chatgpt.mjs +130 -13
- package/extractors/common.mjs +58 -1
- package/extractors/consent.mjs +182 -18
- package/extractors/gemini.mjs +51 -36
- package/extractors/google-ai.mjs +129 -128
- package/extractors/logically.mjs +68 -6
- package/extractors/perplexity.mjs +547 -217
- package/package.json +2 -2
- package/skills/greedy-search/skill.md +20 -18
- package/src/fetcher.mjs +15 -0
- package/src/formatters/results.ts +24 -2
- package/src/search/challenge-detect.mjs +205 -0
- package/src/search/constants.mjs +5 -0
- package/src/search/progress.mjs +145 -0
- package/src/search/recovery.mjs +25 -3
- package/src/search/research.mjs +366 -7
- package/src/search/scale-aware.mjs +93 -0
- package/src/search/simple-research.mjs +520 -0
- package/src/tools/greedy-search-handler.ts +8 -10
- package/src/tools/shared.ts +145 -20
- package/test.mjs +160 -12
package/extractors/logically.mjs
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
import {
|
|
14
14
|
buildEnvelope,
|
|
15
15
|
cdp,
|
|
16
|
-
cdpWithInput,
|
|
17
16
|
formatAnswer,
|
|
18
17
|
getOrOpenTab,
|
|
19
18
|
handleError,
|
|
@@ -34,10 +33,11 @@ const START_URL = "https://logically.app/research-assistant/";
|
|
|
34
33
|
|
|
35
34
|
const SELECTORS = {
|
|
36
35
|
input:
|
|
37
|
-
'
|
|
38
|
-
submitButton:
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
'div.ProseMirror[contenteditable="true"]',
|
|
37
|
+
submitButton:
|
|
38
|
+
'.chat-control button[class*="MuiButton-black"], button[type="submit"]',
|
|
39
|
+
answerContainer: "#last-message .chat-content, [class*=\"chat-content\"]",
|
|
40
|
+
citationSpan: "#last-message .chat-content span[title], [class*=\"chat-content\"] span[title]",
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
async function startNewChat(tab) {
|
|
@@ -115,7 +115,32 @@ async function typeIntoLogically(tab, text) {
|
|
|
115
115
|
await new Promise((r) => setTimeout(r, jitter(120)));
|
|
116
116
|
await cdp(["clickxy", tab, String(point.x), String(point.y)]);
|
|
117
117
|
await new Promise((r) => setTimeout(r, jitter(TIMING.postClick)));
|
|
118
|
-
|
|
118
|
+
// Use tiptap's commands API to insert text. CDP's Input.insertText
|
|
119
|
+
// targets input/textarea elements and doesn't dispatch the events
|
|
120
|
+
// that ProseMirror/tiptap's editor view listens for. The tiptap
|
|
121
|
+
// editor instance is accessible via ed.editor.commands.
|
|
122
|
+
const typeResult = await cdp(
|
|
123
|
+
[
|
|
124
|
+
"eval",
|
|
125
|
+
tab,
|
|
126
|
+
`(() => {
|
|
127
|
+
const ed = document.querySelector('${SELECTORS.input}');
|
|
128
|
+
if (!ed) return 'no-input';
|
|
129
|
+
ed.focus();
|
|
130
|
+
if (!ed.editor || !ed.editor.commands) {
|
|
131
|
+
// Fallback to execCommand for non-tiptap editors
|
|
132
|
+
const ok = document.execCommand('insertText', false, ${JSON.stringify(text)});
|
|
133
|
+
return ok ? 'ok' : 'exec-failed';
|
|
134
|
+
}
|
|
135
|
+
const ok = ed.editor.commands.insertContent(${JSON.stringify(text)});
|
|
136
|
+
return ok ? 'ok' : 'tiptap-failed';
|
|
137
|
+
})()`,
|
|
138
|
+
],
|
|
139
|
+
5000,
|
|
140
|
+
);
|
|
141
|
+
if (typeResult !== "ok") {
|
|
142
|
+
throw new Error(`Logically type failed: ${typeResult}`);
|
|
143
|
+
}
|
|
119
144
|
await new Promise((r) => setTimeout(r, jitter(TIMING.postType)));
|
|
120
145
|
|
|
121
146
|
const inserted = await cdp([
|
|
@@ -499,6 +524,43 @@ async function main() {
|
|
|
499
524
|
);
|
|
500
525
|
}
|
|
501
526
|
|
|
527
|
+
// Detect free-tier quota wall. Logically shows "Chat messages: N/5"
|
|
528
|
+
// in the sidebar. If the user is at 5/5, the "Create" button is
|
|
529
|
+
// disabled and queries can't be submitted. Same pattern as
|
|
530
|
+
// Perplexity's rate-limit wall — visible-mode cookies can't bypass
|
|
531
|
+
// this, it's account-level.
|
|
532
|
+
if (process.env.GREEDY_SEARCH_HEADLESS === "1") {
|
|
533
|
+
const quotaResult = await cdp(
|
|
534
|
+
[
|
|
535
|
+
"eval",
|
|
536
|
+
tab,
|
|
537
|
+
`(() => {
|
|
538
|
+
const text = document.body?.innerText || '';
|
|
539
|
+
const m = text.match(/Chat messages\\s*\\n?\\s*(\\d+)\\s*\\/\\s*(\\d+)/i);
|
|
540
|
+
if (m && parseInt(m[1], 10) >= parseInt(m[2], 10)) {
|
|
541
|
+
return 'quota-exceeded';
|
|
542
|
+
}
|
|
543
|
+
// Also check if Create button is disabled
|
|
544
|
+
const createBtn = Array.from(document.querySelectorAll('button')).find(
|
|
545
|
+
(b) => b.innerText.trim() === 'Create',
|
|
546
|
+
);
|
|
547
|
+
if (createBtn && createBtn.disabled) return 'create-disabled';
|
|
548
|
+
return 'ok';
|
|
549
|
+
})()`,
|
|
550
|
+
],
|
|
551
|
+
5000,
|
|
552
|
+
).catch(() => "ok");
|
|
553
|
+
if (quotaResult === "quota-exceeded" || quotaResult === "create-disabled") {
|
|
554
|
+
console.error(
|
|
555
|
+
"[logically] Rate Limited — skipping (visible retry won't help)",
|
|
556
|
+
);
|
|
557
|
+
env.blockedBy = "rate-limit";
|
|
558
|
+
throw new Error(
|
|
559
|
+
"Rate Limited — Logically free message quota exhausted. Wait until reset.",
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
502
564
|
logStage(env, "type-and-submit", startTime);
|
|
503
565
|
await typeIntoLogically(tab, query);
|
|
504
566
|
const submitted = await cdp([
|