@apmantza/greedysearch-pi 2.0.0 → 2.1.3

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.
@@ -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
- '.chat-control div.ProseMirror[contenteditable="true"][role="textbox"]',
38
- submitButton: '.chat-control button[class*="MuiButton-black"]',
39
- answerContainer: "#last-message .chat-content",
40
- citationSpan: "#last-message .chat-content span[title]",
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
- await cdpWithInput(["type", tab, "--stdin"], text);
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([