Spaces:
Running
Running
fix: resolve module import errors and CSP issues
Browse files- Fix export/import mismatches between modules
- Update app.js to use correct import syntax
- Fix CSP inline script violations with meta tags
- Properly instantiate services in app.js
- app.py +10 -2
- src/app.js +6 -6
- src/clozeGameEngine.js +3 -1
app.py
CHANGED
@@ -23,10 +23,18 @@ async def read_root():
|
|
23 |
openrouter_key = os.getenv("OPENROUTER_API_KEY", "")
|
24 |
hf_key = os.getenv("HF_API_KEY", "")
|
25 |
|
|
|
26 |
env_script = f"""
|
|
|
|
|
27 |
<script>
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
</script>
|
31 |
"""
|
32 |
|
|
|
23 |
openrouter_key = os.getenv("OPENROUTER_API_KEY", "")
|
24 |
hf_key = os.getenv("HF_API_KEY", "")
|
25 |
|
26 |
+
# Create a CSP-compliant way to inject the keys
|
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 |
|
src/app.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
// Main application entry point
|
2 |
-
import
|
3 |
-
import
|
4 |
import { AIService } from './aiService.js';
|
5 |
-
import
|
6 |
-
import
|
7 |
|
8 |
class ClozeReaderApp {
|
9 |
constructor() {
|
10 |
-
this.bookDataService =
|
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 |
|
|
|
1 |
// Main application entry point
|
2 |
+
import ClozeGameEngine from './clozeGameEngine.js';
|
3 |
+
import bookDataService from './bookDataService.js';
|
4 |
import { AIService } from './aiService.js';
|
5 |
+
import ChatInterface from './chatInterface.js';
|
6 |
+
import ConversationManager from './conversationManager.js';
|
7 |
|
8 |
class ClozeReaderApp {
|
9 |
constructor() {
|
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 |
|
src/clozeGameEngine.js
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
// Core game logic for minimal cloze reader
|
2 |
import bookDataService from './bookDataService.js';
|
3 |
-
import
|
4 |
import ChatService from './conversationManager.js';
|
5 |
|
|
|
|
|
6 |
class ClozeGame {
|
7 |
constructor() {
|
8 |
this.currentBook = null;
|
|
|
1 |
// Core game logic for minimal cloze reader
|
2 |
import bookDataService from './bookDataService.js';
|
3 |
+
import { AIService } from './aiService.js';
|
4 |
import ChatService from './conversationManager.js';
|
5 |
|
6 |
+
const aiService = new AIService();
|
7 |
+
|
8 |
class ClozeGame {
|
9 |
constructor() {
|
10 |
this.currentBook = null;
|