everydaycats commited on
Commit
593ef77
·
verified ·
1 Parent(s): c49cba4

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +7 -6
app.js CHANGED
@@ -7,7 +7,7 @@ import { createClient } from '@supabase/supabase-js';
7
  const PORT = 7860;
8
  const SUPABASE_URL = process.env.SUPABASE_URL;
9
  const SUPABASE_KEY = process.env.SUPABASE_SERVICE_KEY;
10
- const CORE_URL = process.env.CORE_URL;
11
 
12
  if (!SUPABASE_URL) { console.error("❌ Config Missing"); process.exit(1); }
13
 
@@ -23,7 +23,7 @@ app.use(express.json({ limit: '50mb' }));
23
 
24
  app.get('/', (req, res) => res.send('Gateway Active'));
25
 
26
- // Internal Notification Webhook
27
  app.post('/internal/notify', (req, res) => {
28
  const { user_id, type, message } = req.body;
29
  if (clients.has(user_id)) {
@@ -67,7 +67,6 @@ wss.on('connection', (ws, req, user) => {
67
  ws.send(JSON.stringify({ type: 'status', status: 'thinking' }));
68
 
69
  // Call Core
70
-
71
  const response = await fetch(`${CORE_URL}/process`, {
72
  method: 'POST',
73
  headers: { 'Content-Type': 'application/json' },
@@ -75,10 +74,12 @@ wss.on('connection', (ws, req, user) => {
75
  userId: userId,
76
  projectId: data.projectId,
77
  prompt: data.content,
78
- context: data.context
 
79
  })
80
  });
81
-
 
82
 
83
  const result = await response.json();
84
 
@@ -86,7 +87,7 @@ wss.on('connection', (ws, req, user) => {
86
  ws.send(JSON.stringify({
87
  type: 'response',
88
  text: result.text,
89
- should_reload: result.should_reload, // .NET app listens for this to refresh UI
90
  usage: result.usage
91
  }));
92
  }
 
7
  const PORT = 7860;
8
  const SUPABASE_URL = process.env.SUPABASE_URL;
9
  const SUPABASE_KEY = process.env.SUPABASE_SERVICE_KEY;
10
+ const CORE_URL = process.env.CORE_URL || "http://localhost:7862"; // Point to Core
11
 
12
  if (!SUPABASE_URL) { console.error("❌ Config Missing"); process.exit(1); }
13
 
 
23
 
24
  app.get('/', (req, res) => res.send('Gateway Active'));
25
 
26
+ // Internal Notification Webhook (Called by Core)
27
  app.post('/internal/notify', (req, res) => {
28
  const { user_id, type, message } = req.body;
29
  if (clients.has(user_id)) {
 
67
  ws.send(JSON.stringify({ type: 'status', status: 'thinking' }));
68
 
69
  // Call Core
 
70
  const response = await fetch(`${CORE_URL}/process`, {
71
  method: 'POST',
72
  headers: { 'Content-Type': 'application/json' },
 
74
  userId: userId,
75
  projectId: data.projectId,
76
  prompt: data.content,
77
+ context: data.context,
78
+ task_type: 'chat' // Default to chat for WS
79
  })
80
  });
81
+
82
+ if (!response.ok) throw new Error("Core API Failed");
83
 
84
  const result = await response.json();
85
 
 
87
  ws.send(JSON.stringify({
88
  type: 'response',
89
  text: result.text,
90
+ should_reload: result.should_reload,
91
  usage: result.usage
92
  }));
93
  }