synapse-gateway 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/synapse.js +1 -2
- package/package.json +2 -1
- package/src/lib/config/index.ts +6 -3
- package/src/lib/db/index.ts +1 -1
- package/src/lib/utils/logger.ts +22 -11
- package/src/{middleware.ts → proxy.ts} +3 -3
package/bin/synapse.js
CHANGED
|
@@ -84,8 +84,7 @@ function buildIfNeeded() {
|
|
|
84
84
|
);
|
|
85
85
|
console.log('⚡ Build complete!');
|
|
86
86
|
} catch (e) {
|
|
87
|
-
console.error('❌ Build failed:'
|
|
88
|
-
console.error(' Try running: npm run build');
|
|
87
|
+
console.error('\n❌ Build failed. Try running: npm run build');
|
|
89
88
|
process.exit(1);
|
|
90
89
|
}
|
|
91
90
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "synapse-gateway",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Synapse - AI Gateway & Intelligence Platform with Neural Router, Semantic Cache, Persistent Memory, Self-Learning, and 5+ AI Providers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"src/",
|
|
38
38
|
"public/",
|
|
39
39
|
"docs/",
|
|
40
|
+
".npmrc",
|
|
40
41
|
"next.config.ts",
|
|
41
42
|
"tsconfig.json",
|
|
42
43
|
"postcss.config.mjs"
|
package/src/lib/config/index.ts
CHANGED
|
@@ -6,13 +6,16 @@ import { configDefaults } from './defaults'
|
|
|
6
6
|
|
|
7
7
|
let cachedConfig: Config | null = null
|
|
8
8
|
|
|
9
|
+
function getDataDir(): string {
|
|
10
|
+
return process.env.DATA_DIR || path.join(/*turbopackIgnore: true*/ os.homedir(), '.synapse')
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
function getConfigPath(): string {
|
|
10
|
-
|
|
11
|
-
return path.join(dataDir, 'config.json')
|
|
14
|
+
return path.join(getDataDir(), 'config.json')
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
function ensureDataDir(): void {
|
|
15
|
-
const dataDir =
|
|
18
|
+
const dataDir = getDataDir()
|
|
16
19
|
if (!fs.existsSync(dataDir)) {
|
|
17
20
|
fs.mkdirSync(dataDir, { recursive: true })
|
|
18
21
|
}
|
package/src/lib/db/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import path from 'path'
|
|
|
5
5
|
import os from 'os'
|
|
6
6
|
import fs from 'fs'
|
|
7
7
|
|
|
8
|
-
const dataDir = process.env.DATA_DIR || path.join(os.homedir(), '.synapse')
|
|
8
|
+
const dataDir = process.env.DATA_DIR || path.join(/*turbopackIgnore: true*/ os.homedir(), '.synapse')
|
|
9
9
|
const dbDir = path.join(dataDir, 'db')
|
|
10
10
|
const dbPath = path.join(dbDir, 'synapse.db')
|
|
11
11
|
|
package/src/lib/utils/logger.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import pino from 'pino'
|
|
2
|
-
import { getConfig } from '../config'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
let _logger: ReturnType<typeof pino> | null = null
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
function getLogger() {
|
|
6
|
+
if (!_logger) {
|
|
7
|
+
const config = require(['..', 'config'].join('/') + '').getConfig()
|
|
8
|
+
_logger = pino({
|
|
9
|
+
level: config.logLevel || 'info',
|
|
10
|
+
transport: {
|
|
11
|
+
target: 'pino/file',
|
|
12
|
+
options: { destination: 1 },
|
|
13
|
+
},
|
|
14
|
+
formatters: {
|
|
15
|
+
level: (label: string) => ({ level: label }),
|
|
16
|
+
},
|
|
17
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
return _logger
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const logger = new Proxy({} as ReturnType<typeof pino>, {
|
|
24
|
+
get(_target, prop) {
|
|
25
|
+
return Reflect.get(getLogger(), prop)
|
|
14
26
|
},
|
|
15
|
-
timestamp: pino.stdTimeFunctions.isoTime,
|
|
16
27
|
})
|
|
@@ -5,14 +5,14 @@ const rateLimitMap = new Map<string, { count: number; resetAt: number }>()
|
|
|
5
5
|
const WINDOW_MS = 60_000
|
|
6
6
|
const MAX_REQUESTS = 100
|
|
7
7
|
|
|
8
|
-
export function
|
|
8
|
+
export function proxy(request: NextRequest) {
|
|
9
9
|
if (request.nextUrl.pathname.startsWith('/api/')) {
|
|
10
|
-
return
|
|
10
|
+
return handleApiProxy(request)
|
|
11
11
|
}
|
|
12
12
|
return NextResponse.next()
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function handleApiProxy(request: NextRequest) {
|
|
16
16
|
const headers = new Headers()
|
|
17
17
|
|
|
18
18
|
headers.set('Access-Control-Allow-Origin', '*')
|