AlexKurian commited on
Commit
2f6a264
·
1 Parent(s): f65e5b9

feat(gateway): proxy /repos/* and /projects/* routes to API engine for CLI support

Browse files
.gitignore CHANGED
@@ -26,3 +26,8 @@ Thumbs.db
26
  .vscode/
27
  .idea/
28
 
 
 
 
 
 
 
26
  .vscode/
27
  .idea/
28
 
29
+
30
+ # Ever-Brain local cache & state
31
+ .evb/cache/
32
+ .evb/state.yaml
33
+ .evb/auth.yaml
packages/cli/src/config/constants.ts CHANGED
@@ -1,5 +1,10 @@
1
  import path from 'node:path';
2
  import os from 'node:os';
 
 
 
 
 
3
 
4
  export const EVB_DIR = '.evb';
5
  export const CONFIG_FILE = 'config.yaml';
@@ -9,10 +14,16 @@ export const CACHE_DIR = 'cache';
9
 
10
  export const GLOBAL_EVB_DIR = path.join(os.homedir(), '.evb');
11
  export const GLOBAL_AUTH_FILE = path.join(GLOBAL_EVB_DIR, 'auth.json');
 
 
 
 
 
 
12
 
13
- // Default API URL (can be overridden by EVB_API_URL or config.yaml)
14
- export const DEFAULT_API_URL = 'http://localhost:3000';
15
- export const DEFAULT_MCP_URL = 'http://localhost:3001';
16
 
17
  export function getDefaultApiUrl(): string {
18
  return process.env.EVB_API_URL || process.env.EVER_BRAIN_API_URL || DEFAULT_API_URL;
 
1
  import path from 'node:path';
2
  import os from 'node:os';
3
+ import fs from 'node:fs';
4
+ import dotenv from 'dotenv';
5
+
6
+ // Load .env from current directory
7
+ dotenv.config();
8
 
9
  export const EVB_DIR = '.evb';
10
  export const CONFIG_FILE = 'config.yaml';
 
14
 
15
  export const GLOBAL_EVB_DIR = path.join(os.homedir(), '.evb');
16
  export const GLOBAL_AUTH_FILE = path.join(GLOBAL_EVB_DIR, 'auth.json');
17
+ export const GLOBAL_ENV_FILE = path.join(GLOBAL_EVB_DIR, '.env');
18
+
19
+ // Also load ~/.evb/.env if present
20
+ if (fs.existsSync(GLOBAL_ENV_FILE)) {
21
+ dotenv.config({ path: GLOBAL_ENV_FILE });
22
+ }
23
 
24
+ // Default API and MCP URLs (live Hugging Face Space by default, overridable by env/flags)
25
+ export const DEFAULT_API_URL = 'https://projectsorg-ever-brain.hf.space';
26
+ export const DEFAULT_MCP_URL = 'https://projectsorg-ever-brain.hf.space';
27
 
28
  export function getDefaultApiUrl(): string {
29
  return process.env.EVB_API_URL || process.env.EVER_BRAIN_API_URL || DEFAULT_API_URL;
packages/mcp/src/app.ts CHANGED
@@ -54,6 +54,31 @@ app.post('/messages', handleSseMessage);
54
  app.all('/mcp/:owner/:repo', handleStreamableHttp);
55
  app.all('/mcp', handleStreamableHttp);
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  // --- Server Discovery Endpoints (Antigravity & Plugin Probes) ---
58
  app.all('/server/discover', (c) => {
59
  return c.json({
 
54
  app.all('/mcp/:owner/:repo', handleStreamableHttp);
55
  app.all('/mcp', handleStreamableHttp);
56
 
57
+ // --- Direct API Engine Proxy (for CLI & web sync over unified gateway) ---
58
+ app.all('/repos/*', async (c) => {
59
+ const targetUrl = `${config.apiUrl.replace(/\/+$/, '')}${c.req.path}${c.req.url.includes('?') ? '?' + c.req.url.split('?')[1] : ''}`;
60
+ const response = await fetch(targetUrl, {
61
+ method: c.req.method,
62
+ headers: c.req.raw.headers,
63
+ });
64
+ return new Response(response.body, {
65
+ status: response.status,
66
+ headers: response.headers,
67
+ });
68
+ });
69
+
70
+ app.all('/projects/*', async (c) => {
71
+ const targetUrl = `${config.apiUrl.replace(/\/+$/, '')}${c.req.path}${c.req.url.includes('?') ? '?' + c.req.url.split('?')[1] : ''}`;
72
+ const response = await fetch(targetUrl, {
73
+ method: c.req.method,
74
+ headers: c.req.raw.headers,
75
+ });
76
+ return new Response(response.body, {
77
+ status: response.status,
78
+ headers: response.headers,
79
+ });
80
+ });
81
+
82
  // --- Server Discovery Endpoints (Antigravity & Plugin Probes) ---
83
  app.all('/server/discover', (c) => {
84
  return c.json({