From 82e9f12b7f84c5a1f8bc286848231bb71f1c4861 Mon Sep 17 00:00:00 2001 From: Acbox Date: Sat, 14 Feb 2026 19:51:55 +0800 Subject: [PATCH] refactor(web): change old port (7003) and deploy port (80) to port 8082 --- agent/package.json | 1 + agent/src/config.ts | 22 ---------- agent/src/index.ts | 23 +---------- agent/tsconfig.json | 2 +- docker-compose.yml | 2 +- docker/Dockerfile.web | 4 +- docker/config/nginx.conf | 4 +- packages/config/.gitignore | 34 ++++++++++++++++ packages/config/README.md | 2 + packages/config/package.json | 17 ++++++++ packages/config/src/index.ts | 28 +++++++++++++ packages/config/src/types.ts | 76 +++++++++++++++++++++++++++++++++++ packages/config/tsconfig.json | 20 +++++++++ packages/sdk/src/types.gen.ts | 12 ++++-- packages/web/package.json | 1 + packages/web/vite.config.ts | 16 ++++---- pnpm-lock.yaml | 15 +++++++ scripts/install.sh | 2 +- 18 files changed, 219 insertions(+), 62 deletions(-) delete mode 100644 agent/src/config.ts create mode 100644 packages/config/.gitignore create mode 100644 packages/config/README.md create mode 100644 packages/config/package.json create mode 100644 packages/config/src/index.ts create mode 100644 packages/config/src/types.ts create mode 100644 packages/config/tsconfig.json diff --git a/agent/package.json b/agent/package.json index 24b7a82a..29ab508b 100644 --- a/agent/package.json +++ b/agent/package.json @@ -7,6 +7,7 @@ "start": "pnpm run build && bun run dist/index.js" }, "dependencies": { + "@memoh/config": "workspace:*", "@ai-sdk/amazon-bedrock": "^4.0.56", "@ai-sdk/anthropic": "^3.0.9", "@ai-sdk/azure": "^3.0.28", diff --git a/agent/src/config.ts b/agent/src/config.ts deleted file mode 100644 index 9875a18e..00000000 --- a/agent/src/config.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { readFileSync } from 'fs' -import { parse } from 'toml' - -type AgentGatewayConfig = { - 'agent_gateway': { - host?: string - server_addr?: string - port?: number - }, - 'server': { - addr?: string - }, - 'brave'?: { - api_key?: string - base_url?: string - } -} - -export const loadConfig = (path: string = './config.toml'): AgentGatewayConfig => { - const config = parse(readFileSync(path, 'utf-8')) - return config satisfies AgentGatewayConfig -} \ No newline at end of file diff --git a/agent/src/index.ts b/agent/src/index.ts index eef30d5a..7cc39d68 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -2,7 +2,7 @@ import { Elysia } from 'elysia' import { chatModule } from './modules/chat' import { corsMiddleware } from './middlewares/cors' import { errorMiddleware } from './middlewares/error' -import { loadConfig } from './config' +import { loadConfig, getBaseUrl as getBaseUrlByConfig } from '@memoh/config' const config = loadConfig('../config.toml') @@ -19,26 +19,7 @@ export const getBraveConfig = () => { } export const getBaseUrl = () => { - const rawAddr = - typeof config.agent_gateway.server_addr === 'string' - ? config.agent_gateway.server_addr.trim() - : typeof config.server.addr === 'string' - ? config.server.addr.trim() - : '' - - if (!rawAddr) { - return 'http://127.0.0.1' - } - - if (rawAddr.startsWith('http://') || rawAddr.startsWith('https://')) { - return rawAddr.replace(/\/+$/, '') - } - - if (rawAddr.startsWith(':')) { - return `http://127.0.0.1${rawAddr}` - } - - return `http://${rawAddr}` + return getBaseUrlByConfig(config) } export type AuthFetcher = ( diff --git a/agent/tsconfig.json b/agent/tsconfig.json index 1ca2350a..d28b8791 100644 --- a/agent/tsconfig.json +++ b/agent/tsconfig.json @@ -27,7 +27,7 @@ /* Modules */ "module": "ES2022", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ diff --git a/docker-compose.yml b/docker-compose.yml index 9825fe0d..e6ea2fa0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -118,7 +118,7 @@ services: - VITE_AGENT_URL=http://localhost:8081 container_name: memoh-web ports: - - "80:80" + - "8082:8082" depends_on: - server - agent diff --git a/docker/Dockerfile.web b/docker/Dockerfile.web index 5e185850..6b436152 100644 --- a/docker/Dockerfile.web +++ b/docker/Dockerfile.web @@ -27,9 +27,9 @@ COPY --from=builder /build/packages/web/dist /usr/share/nginx/html COPY docker/config/nginx.conf /etc/nginx/conf.d/default.conf -EXPOSE 80 +EXPOSE 8082 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 1 + CMD wget --no-verbose --tries=1 --spider http://localhost:8082/health || exit 1 CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/config/nginx.conf b/docker/config/nginx.conf index 255c8b65..77807793 100644 --- a/docker/config/nginx.conf +++ b/docker/config/nginx.conf @@ -1,6 +1,6 @@ server { - listen 80; - listen [::]:80; + listen 8082; + listen [::]:8082; server_name _; root /usr/share/nginx/html; index index.html; diff --git a/packages/config/.gitignore b/packages/config/.gitignore new file mode 100644 index 00000000..a14702c4 --- /dev/null +++ b/packages/config/.gitignore @@ -0,0 +1,34 @@ +# dependencies (bun install) +node_modules + +# output +out +dist +*.tgz + +# code coverage +coverage +*.lcov + +# logs +logs +_.log +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# caches +.eslintcache +.cache +*.tsbuildinfo + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/packages/config/README.md b/packages/config/README.md new file mode 100644 index 00000000..dca6aec8 --- /dev/null +++ b/packages/config/README.md @@ -0,0 +1,2 @@ +# @memoh/config + diff --git a/packages/config/package.json b/packages/config/package.json new file mode 100644 index 00000000..9022f029 --- /dev/null +++ b/packages/config/package.json @@ -0,0 +1,17 @@ +{ + "name": "@memoh/config", + "version": "1.0.0", + "exports": { + ".": "./src/index.ts" + }, + "packageManager": "pnpm@10.27.0", + "module": "src/index.ts", + "type": "module", + "private": true, + "peerDependencies": { + "typescript": "^5" + }, + "dependencies": { + "toml": "^3.0.0" + } +} diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts new file mode 100644 index 00000000..035c86d9 --- /dev/null +++ b/packages/config/src/index.ts @@ -0,0 +1,28 @@ +import { parse } from 'toml' +import { readFileSync } from 'fs' +import type { Config } from './types' + +export const loadConfig = (path: string = './config.toml'): Config => { + const config = parse(readFileSync(path, 'utf-8')) + return config satisfies Config +} + +export const getBaseUrl = (config: Config) => { + const rawAddr = typeof config.server.addr === 'string' ? config.server.addr.trim() : '' + + if (!rawAddr) { + return 'http://127.0.0.1' + } + + if (rawAddr.startsWith('http://') || rawAddr.startsWith('https://')) { + return rawAddr.replace(/\/+$/, '') + } + + if (rawAddr.startsWith(':')) { + return `http://127.0.0.1${rawAddr}` + } + + return `http://${rawAddr}` +} + +export * from './types' diff --git a/packages/config/src/types.ts b/packages/config/src/types.ts new file mode 100644 index 00000000..62eece8b --- /dev/null +++ b/packages/config/src/types.ts @@ -0,0 +1,76 @@ +export interface Config { + log: LogConfig; + server: ServerConfig; + admin: AdminConfig; + auth: AuthConfig; + containerd: ContainerdConfig; + mcp: McpConfig; + postgres: PostgresConfig; + qdrant: QdrantConfig; + agent_gateway: AgentGatewayConfig; + web: WebConfig; + brave: BraveConfig; +} + +export interface LogConfig { + level: string; + format: string; +} + +export interface ServerConfig { + addr: string; +} + +export interface AdminConfig { + username: string; + password: string; + email: string; +} + +export interface AuthConfig { + jwt_secret: string; + jwt_expires_in: string; +} + +export interface ContainerdConfig { + socket_path: string; + namespace: string; +} + +export interface McpConfig { + image: string; + snapshotter: string; + data_root: string; + data_mount: string; +} + +export interface PostgresConfig { + host: string; + port: number; + user: string; + password: string; + database: string; + sslmode: string; +} + +export interface QdrantConfig { + base_url: string; + api_key: string; + collection: string; + timeout_seconds: number; +} + +export interface AgentGatewayConfig { + host: string; + port: number; +} + +export interface WebConfig { + host: string; + port: number; +} + +export interface BraveConfig { + api_key: string; + base_url: string; +} diff --git a/packages/config/tsconfig.json b/packages/config/tsconfig.json new file mode 100644 index 00000000..5237a457 --- /dev/null +++ b/packages/config/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "lib": ["ES2022"], + "moduleResolution": "bundler", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + "jsx": "react-jsx", + "outDir": "./dist", + "rootDir": "./src", + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} + diff --git a/packages/sdk/src/types.gen.ts b/packages/sdk/src/types.gen.ts index 2973d0a7..2effa732 100644 --- a/packages/sdk/src/types.gen.ts +++ b/packages/sdk/src/types.gen.ts @@ -503,6 +503,7 @@ export type HandlersMemorySearchPayload = { [key: string]: unknown; }; limit?: number; + no_stats?: boolean; query?: string; run_id?: string; sources?: Array; @@ -597,6 +598,7 @@ export type MemoryDeleteResponse = { export type MemoryMemoryItem = { agent_id?: string; bot_id?: string; + cdf_curve?: Array; created_at?: string; hash?: string; id?: string; @@ -606,6 +608,7 @@ export type MemoryMemoryItem = { }; run_id?: string; score?: number; + top_k_buckets?: Array; updated_at?: string; }; @@ -622,10 +625,8 @@ export type MemoryRebuildResult = { }; export type MemorySearchResponse = { - cdf_curve?: Array; relations?: Array; results?: Array; - top_k_buckets?: Array; }; export type MemoryTopKBucket = { @@ -1791,7 +1792,12 @@ export type GetBotsByBotIdMemoryData = { */ bot_id: string; }; - query?: never; + query?: { + /** + * Skip sparse vector stats (top_k_buckets, cdf_curve) to reduce overhead + */ + no_stats?: boolean; + }; url: '/bots/{bot_id}/memory'; }; diff --git a/packages/web/package.json b/packages/web/package.json index cb987073..f0748c6a 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -44,6 +44,7 @@ "@types/node": "^24.10.1", "@vitejs/plugin-vue": "^6.0.1", "@vue/tsconfig": "^0.8.1", + "@memoh/config": "workspace:*", "typescript": "~5.9.3", "vite": "^7.2.4", "vue-tsc": "^3.1.4" diff --git a/packages/web/vite.config.ts b/packages/web/vite.config.ts index c4f52b90..a78b9591 100644 --- a/packages/web/vite.config.ts +++ b/packages/web/vite.config.ts @@ -1,24 +1,22 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' -import { config } from 'dotenv' import tailwindcss from '@tailwindcss/vite' import { fileURLToPath } from 'url' +import { loadConfig, getBaseUrl } from '@memoh/config' -config({ - path: '../../.env', -}) - -const port = Number(process.env.WEB_PORT || 7003) +const config = loadConfig('../../config.toml') +const { web: { port = 8082, host = '127.0.0.1' } } = config +const baseUrl = getBaseUrl(config) // https://vite.dev/config/ export default defineConfig({ plugins: [vue(), tailwindcss()], server: { port, - host: '0.0.0.0', + host, proxy: { '/api': { - target: 'http://localhost:8080', + target: baseUrl, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '') } @@ -29,7 +27,7 @@ export default defineConfig({ host: '0.0.0.0', proxy: { '/api': { - target: 'http://localhost:8080', + target: baseUrl, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '') } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 571ec29b..564a537e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,6 +72,9 @@ importers: '@elysiajs/cors': specifier: ^1.4.1 version: 1.4.1(elysia@1.4.22(@sinclair/typebox@0.34.47)(@types/bun@1.3.8)(exact-mirror@0.2.6(@sinclair/typebox@0.34.47))(file-type@21.3.0)(openapi-types@12.1.3)(typescript@5.9.3)) + '@memoh/config': + specifier: workspace:* + version: link:../packages/config '@modelcontextprotocol/sdk': specifier: ^1.25.2 version: 1.25.2(@cfworker/json-schema@4.1.1)(hono@4.11.4)(zod@4.3.5) @@ -156,6 +159,15 @@ importers: specifier: latest version: 1.3.8 + packages/config: + dependencies: + toml: + specifier: ^3.0.0 + version: 3.0.0 + typescript: + specifier: ^5 + version: 5.9.3 + packages/sdk: dependencies: '@pinia/colada': @@ -343,6 +355,9 @@ importers: specifier: ^4.3.5 version: 4.3.5 devDependencies: + '@memoh/config': + specifier: workspace:* + version: link:../config '@types/node': specifier: ^24.10.1 version: 24.10.4 diff --git a/scripts/install.sh b/scripts/install.sh index 1924c63d..f8cc44d9 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -145,7 +145,7 @@ echo "${GREEN}========================================${NC}" echo "${GREEN} Memoh is running!${NC}" echo "${GREEN}========================================${NC}" echo "" -echo " Web UI: http://localhost" +echo " Web UI: http://localhost:8082" echo " API: http://localhost:8080" echo " Agent Gateway: http://localhost:8081" echo ""