File size: 2,628 Bytes
34450be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
with open("App.tsx", "r") as f:
    content = f.read()

# Fix the hook definition issue by moving the interval into a functional form correctly

import re

# Let's replace the whole interval logic with something simpler since we just wrote it
interval_regex = re.compile(r"// Timer interval to process HF Deployment Cues every 10 seconds.*?// --- Message Sending & Event Streaming ---", re.DOTALL)

new_interval = """  // Timer interval to process HF Deployment Cues every 10 seconds
  useEffect(() => {
      const interval = setInterval(() => {
          const stored = localStorage.getItem('jules_hf_timer_queue');
          if (!stored) return;

          let currentQueue = JSON.parse(stored);
          const now = Date.now();
          let hasChanges = false;

          for (const sessionId of Object.keys(currentQueue)) {
              const queueData = currentQueue[sessionId];
              if (queueData.templates && queueData.templates.length > 0 && now >= queueData.nextExecutionTime) {
                  const templateToFire = queueData.templates[0];
                  const remainingTemplates = queueData.templates.slice(1);

                  console.log(`[TimerQueue] Firing template for session ${sessionId}`);

                  // Fire out of band so we don't block
                  setTimeout(() => {
                      _sendText(sessionId, templateToFire).catch(e => console.error("Timer send failed", e));
                  }, 0);

                  if (remainingTemplates.length > 0) {
                      currentQueue[sessionId] = {
                          templates: remainingTemplates,
                          nextExecutionTime: now + 30 * 60 * 1000
                      };
                  } else {
                      delete currentQueue[sessionId];
                  }
                  hasChanges = true;
              }
          }

          if (hasChanges) {
              setHfTimerQueue(currentQueue);
              localStorage.setItem('jules_hf_timer_queue', JSON.stringify(currentQueue));
          }
      }, 10000);
      return () => clearInterval(interval);
  }, []);

  // --- Message Sending & Event Streaming ---"""

content = interval_regex.sub(new_interval, content)

# Include HFCueWizardModal
imports_search = """import { TemplateFillerModal } from './components/TemplateFillerModal';"""
imports_replace = """import { TemplateFillerModal } from './components/TemplateFillerModal';
import { HFCueWizardModal } from './components/HFCueWizardModal';"""
content = content.replace(imports_search, imports_replace)

with open("App.tsx", "w") as f:
    f.write(content)