milwright commited on
Commit
793a92d
·
1 Parent(s): 88ca3a2

fix: resolve all console errors and CSP violations

Browse files

- Remove redundant chatInterface.initialize() call - already set up in constructor
- Fix ChatInterface to receive gameEngine instead of aiService
- Move inline script to external init-env.js to comply with CSP
- Properly structure all module dependencies and initialization

Files changed (3) hide show
  1. app.py +1 -9
  2. src/app.js +2 -3
  3. src/init-env.js +13 -0
app.py CHANGED
@@ -27,15 +27,7 @@ async def read_root():
27
  env_script = f"""
28
  <meta name="openrouter-key" content="{openrouter_key}">
29
  <meta name="hf-key" content="{hf_key}">
30
- <script>
31
- // Read keys from meta tags to avoid CSP issues
32
- document.addEventListener('DOMContentLoaded', function() {{
33
- const openrouterMeta = document.querySelector('meta[name="openrouter-key"]');
34
- const hfMeta = document.querySelector('meta[name="hf-key"]');
35
- if (openrouterMeta) window.OPENROUTER_API_KEY = openrouterMeta.content;
36
- if (hfMeta) window.HF_API_KEY = hfMeta.content;
37
- }});
38
- </script>
39
  """
40
 
41
  # Insert the script before closing head tag
 
27
  env_script = f"""
28
  <meta name="openrouter-key" content="{openrouter_key}">
29
  <meta name="hf-key" content="{hf_key}">
30
+ <script src="./src/init-env.js"></script>
 
 
 
 
 
 
 
 
31
  """
32
 
33
  # Insert the script before closing head tag
src/app.js CHANGED
@@ -10,7 +10,7 @@ class ClozeReaderApp {
10
  this.bookDataService = bookDataService; // Already instantiated
11
  this.aiService = new AIService();
12
  this.gameEngine = new ClozeGameEngine();
13
- this.chatInterface = new ChatInterface(this.aiService);
14
  this.conversationManager = new ConversationManager(this.aiService);
15
 
16
  this.init();
@@ -21,8 +21,7 @@ class ClozeReaderApp {
21
  // Start the game directly - bookDataService is already initialized
22
  await this.gameEngine.initialize();
23
 
24
- // Initialize chat interface
25
- this.chatInterface.initialize();
26
 
27
  console.log('Cloze Reader application initialized successfully');
28
  } catch (error) {
 
10
  this.bookDataService = bookDataService; // Already instantiated
11
  this.aiService = new AIService();
12
  this.gameEngine = new ClozeGameEngine();
13
+ this.chatInterface = new ChatInterface(this.gameEngine);
14
  this.conversationManager = new ConversationManager(this.aiService);
15
 
16
  this.init();
 
21
  // Start the game directly - bookDataService is already initialized
22
  await this.gameEngine.initialize();
23
 
24
+ // Chat interface is already initialized in constructor
 
25
 
26
  console.log('Cloze Reader application initialized successfully');
27
  } catch (error) {
src/init-env.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Initialize environment variables from meta tags
2
+ document.addEventListener('DOMContentLoaded', function() {
3
+ const openrouterMeta = document.querySelector('meta[name="openrouter-key"]');
4
+ const hfMeta = document.querySelector('meta[name="hf-key"]');
5
+
6
+ if (openrouterMeta) {
7
+ window.OPENROUTER_API_KEY = openrouterMeta.content;
8
+ }
9
+
10
+ if (hfMeta) {
11
+ window.HF_API_KEY = hfMeta.content;
12
+ }
13
+ });