-
Notifications
You must be signed in to change notification settings - Fork 37
Feature/refactor web/1201 #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
huangli28926
wants to merge
32
commits into
LianjiaTech:develop
from
huangli28926:feature/refactorWeb/1201
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3181f90
[紧急]重构等登录页面
huangli090 a37fc72
[紧急]调整登录文案
huangli090 1efb53f
refactor: 重构前端布局架构,统一应用导航和设置系统
huangli090 d4ffa89
feat: 新增首页和顶部导航栏组件
huangli090 ae1f4bb
style: 优化首页主题色和布局样式
huangli090 de12951
feat: 新增模型管理页面和端点选择工具函数
huangli090 be664ac
refactor: 优化模型管理页面架构和UI组件
huangli090 3ac98eb
feat: 优化模型管理页面数据展示和类型定义
huangli090 190ab31
refactor: 清理模型管理页面中的Mock数据和冗余代码
huangli090 f733aab
refactor: 重构模型管理页面,提取模型卡片组件
huangli090 02a3538
refactor: 将web目录重命名为webV2以支持新版本架构
huangli090 7b38bdc
web为旧目录
huangli090 8b98517
style: 优化模型卡片样式和主题配色
huangli090 f6f5201
feat: 实现模型页面标签筛选功能并优化代码
huangli090 59e6a46
refactor: 重构模型页面,提取自定义Hook和工具函数
huangli090 7f2962b
feat: 实现模型页面搜索功能
huangli090 2c75911
refactor: 优化模型页面数据管理和加载状态
huangli090 0665757
feat: 为模型页面搜索框添加清除按钮
huangli090 56aa9b6
refactor(playground): 重构playground模块,优化页面结构和组件
huangli090 1d733e7
refactor: 清理废弃组件并优化 playground 侧边栏菜单
huangli090 033ed32
refactor: 重构 playground 和 sidebar 组件结构
huangli090 6dd9723
fix(playground): 限制模型选择下拉框最大高度
huangli090 535ee8e
refactor(playground): 优化类型定义,Model接口字段改为可选
huangli090 44ab09f
chore: 移除 webV2/.env 文件并更新 .gitignore
huangli090 960d28a
refactor: 优化 Switch 组件样式,改进暗色模式显示效果
huangli090 cced2f8
feat: 重构 webV2 playground chat 功能,新增 SSE 处理库
huangli090 e57c5bd
feat(playground): 重构聊天页面,分离组件与类型定义
huangli090 69b45c5
优化 Markdown 渲染器行内代码显示样式
huangli090 665fa21
refactor: 重构 playground chat 功能,新增组件和类型定义
huangli090 aa7e1ee
重构: 优化 playground 页面的模型数据展示
huangli090 28d2ee1
feat: 集成 Embedding API 并优化响应处理
huangli090 3a28a7a
重构(playground): 将 Embedding 配置面板提取为独立组件
huangli090 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,21 @@ server { | |
| # 访问日志 | ||
| access_log /var/log/nginx/host.access.log main; | ||
|
|
||
| # /v1/chat/completions 路径转发到本地SSE服务 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 本地环境代码,因该在PR中移除。 |
||
| location ^~ /v1/chat/completions { | ||
| proxy_pass http://localhost:3010/sse; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| proxy_set_header Upgrade $http_upgrade; | ||
| proxy_set_header Connection "upgrade"; | ||
|
|
||
| proxy_connect_timeout 60s; | ||
| proxy_send_timeout 300s; | ||
| proxy_read_timeout 300s; | ||
| } | ||
|
|
||
| # /v1 路径转发到 api 服务 | ||
| location ^~ /v1/ { | ||
| proxy_pass http://bella-openapi-api:8080; | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 跟本次提交无关系的代码改动需要回滚。 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| .env.local | ||
|
|
||
| # Logs | ||
| logs | ||
| *.log* | ||
|
|
||
| # node | ||
| node_modules | ||
| .husky | ||
| .next | ||
|
|
||
| # vscode | ||
| .vscode | ||
|
|
||
| # webstorm | ||
| .idea | ||
| *.iml | ||
| *.iws | ||
| *.ipr | ||
|
|
||
|
|
||
| # Jetbrains | ||
| .idea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| NEXT_PUBLIC_API_HOST=localhost:8080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| This is **Bella OpenAPI Web** - a Next.js 14 web application that serves as an API management and testing console for OpenAPI endpoints. It provides a comprehensive interface for testing, monitoring, and managing various AI/ML APIs including chat completions, audio processing, and embeddings. | ||
|
|
||
| ## Common Commands | ||
|
|
||
| ### Development | ||
| ```bash | ||
| npm run dev # Start development server (http://localhost:3000) | ||
| npm run build # Build for production | ||
| npm run start # Start production server | ||
| npm run lint # Run ESLint linting | ||
| ``` | ||
|
|
||
| ### Docker (Multi-stage build with optimizations) | ||
| ```bash | ||
| # Build with build args for API host | ||
| docker build --build-arg NEXT_PUBLIC_API_HOST=your-api-host -t bella-openapi-web . | ||
| docker run -p 3000:3000 bella-openapi-web | ||
|
|
||
| # Development with volume mounting | ||
| docker run -v $(pwd):/app/web -p 3000:3000 bella-openapi-web | ||
| ``` | ||
|
|
||
| ## Architecture Overview | ||
|
|
||
| ### Technology Stack | ||
| - **Framework**: Next.js 14 with App Router and React Server Components | ||
| - **Language**: TypeScript with strict type checking | ||
| - **Styling**: Tailwind CSS + shadcn/ui components (New York style) | ||
| - **State Management**: React Context API with custom providers | ||
| - **HTTP Client**: Axios with custom interceptors and authentication | ||
| - **Forms**: React Hook Form with resolvers | ||
| - **Data Tables**: TanStack React Table | ||
| - **Charts**: Recharts for data visualization | ||
|
|
||
| ### Key Directory Structure | ||
| ``` | ||
| /src | ||
| ├── app/ # Next.js App Router | ||
| │ ├── api/ # API routes (logs, metrics, config) | ||
| │ ├── playground/v1/ # API testing interfaces | ||
| │ │ ├── audio/ # Audio processing APIs | ||
| │ │ ├── chat/ # Chat completion APIs | ||
| │ │ └── embeddings/ # Embedding APIs | ||
| │ ├── apikey/ # API key management | ||
| │ ├── monitor/ # Monitoring dashboard | ||
| │ ├── meta/ # API metadata & main console | ||
| │ └── logs/ # Logging interface | ||
| ├── components/ # React components (feature-organized) | ||
| ├── lib/ # Utilities and configurations | ||
| │ ├── api/ # API client functions | ||
| │ ├── context/ # React contexts (UserProvider, etc.) | ||
| │ └── types/ # TypeScript definitions | ||
| └── hooks/ # Custom React hooks | ||
| ``` | ||
|
|
||
| ### Core Features | ||
| - **API Console**: Browse and test OpenAPI endpoints via `/meta` | ||
| - **Playground**: Interactive testing for Chat, Audio, and Embedding APIs | ||
| - **API Key Management**: Create and manage API keys with quotas | ||
| - **Real-time Monitoring**: Metrics dashboard and comprehensive logging | ||
| - **Multi-tenant Architecture**: Configurable tenant and workflow support | ||
|
|
||
| ### Configuration & Environment | ||
| The application uses Next.js standalone output mode and requires these environment variables: | ||
|
|
||
| **Public (Build-time)**: | ||
| - `NEXT_PUBLIC_API_HOST` - Backend API host | ||
| - `NEXT_PUBLIC_APIKEY_QUOTA_APPLY_URL` - URL for API key quota applications | ||
| - `NEXT_PUBLIC_SAFETY_APPLY_URL` - URL for safety feature applications | ||
| - `NEXT_PUBLIC_AGENT_URL` - Agent service URL | ||
|
|
||
| **Server-side (Runtime)**: | ||
| - `WORKFLOW_URL`, `WORKFLOW_API_KEY` - Workflow service configuration | ||
| - `ES_URL`, `ES_API_KEY` - ElasticSearch for logging | ||
| - `TENANT_ID` - Multi-tenant identifier | ||
| - `METRICS_WORKFLOW_ID`, `LOGS_TRACE_WORKFLOW_ID`, `SERVICE_WORKFLOW_ID` - Workflow identifiers | ||
|
|
||
| ### Key Patterns | ||
| - **Provider Pattern**: Global state via UserProvider and ThemeProvider contexts | ||
| - **Custom Axios Instance**: Centralized API client with authentication and error handling interceptors | ||
| - **Feature-based Components**: Components organized by feature area (apikey/, meta/, playground/, etc.) | ||
| - **Type-safe APIs**: Comprehensive TypeScript types for all API interactions | ||
| - **shadcn/ui Integration**: Consistent design system with Radix UI primitives (New York style) | ||
| - **Standalone Output**: Docker-optimized production builds with PM2 process management | ||
|
|
||
| ### Key Architecture Components | ||
|
|
||
| **Authentication Flow**: | ||
| - `src/lib/context/user-context.tsx` - Global user state management | ||
| - `src/lib/api/openapi.ts` - Axios instance with 401 redirect handling | ||
| - `X-BELLA-CONSOLE` header for backend identification | ||
|
|
||
| **API Client Structure**: | ||
| - `src/lib/api/openapi.ts` - Main HTTP client with interceptors | ||
| - `src/lib/api/meta.ts` - Metadata and model management APIs | ||
| - `src/lib/api/apikey.ts` - API key management functions | ||
| - `src/lib/api/workflow.ts` - Workflow service integration | ||
|
|
||
| **Component Organization**: | ||
| - Feature-based: `components/apikey/`, `components/meta/`, `components/playground/` | ||
| - UI primitives: `components/ui/` (shadcn/ui components) | ||
| - Business logic: Audio processing classes in `components/playground/` | ||
|
|
||
| ### Path Aliases | ||
| - `@/*` maps to `./src/*` for clean imports | ||
|
|
||
| ## Development Notes | ||
|
|
||
| ### Key Routes & Pages | ||
| - Root (`/`) redirects to `/meta` - the main API console interface | ||
| - `/playground/v1/` - Interactive API testing interfaces (chat, audio, embeddings) | ||
| - `/apikey/` - API key management and quota tracking | ||
| - `/monitor/` - Real-time metrics and monitoring dashboard | ||
| - `/logs/` - Comprehensive logging interface with trace capabilities | ||
|
|
||
| ### Audio Processing Architecture | ||
| - Real-time audio processing with WebSocket connections | ||
| - Multiple recorder implementations: `RealtimeAudioRecorder`, `FlashAudioRecorder` | ||
| - PCM audio playback and device selection utilities | ||
| - Voice synthesis and ASR (Automatic Speech Recognition) support | ||
|
|
||
| ### API Response Handling | ||
| - Standardized response format with `code: 200` success indicator | ||
| - Automatic login redirect on 401 responses via `X-Redirect-Login` header | ||
| - Error boundary handling throughout the application | ||
|
|
||
| ### Deployment Features | ||
| - Multi-stage Docker build with Chinese mirror optimizations | ||
| - PM2 process management in production | ||
| - Standalone Next.js output for optimized Docker images | ||
| - Timezone configuration (Asia/Shanghai) in containers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # base image | ||
| FROM node:20.11-alpine3.19 AS base | ||
|
|
||
| # 国内使用阿里云镜像源 | ||
| #RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories | ||
|
|
||
| # install packages | ||
| FROM base AS packages | ||
|
|
||
| WORKDIR /app/web | ||
|
|
||
| COPY package.json . | ||
| COPY package-lock.json . | ||
|
|
||
| # 设置 npm 配置以提高稳定性 | ||
| RUN npm config set registry https://registry.npmmirror.com/ | ||
|
|
||
| # 使用 cnpm 安装依赖,更稳定 | ||
| RUN npm install -g cnpm --registry=https://registry.npmmirror.com/ \ | ||
| && cnpm install --no-audit --no-fund --ignore-scripts | ||
|
|
||
| # build resources | ||
| FROM base AS builder | ||
| WORKDIR /app/web | ||
| COPY --from=packages /app/web/ . | ||
| COPY . . | ||
|
|
||
| ARG NODE_ENV=production | ||
| ARG DEPLOY_ENV=production | ||
| ARG NEXT_PUBLIC_API_HOST | ||
|
|
||
| # 设置环境变量 | ||
| ENV NODE_ENV=${NODE_ENV} | ||
| ENV DEPLOY_ENV=${DEPLOY_ENV} | ||
| ENV NEXT_PUBLIC_API_HOST=${NEXT_PUBLIC_API_HOST} | ||
|
|
||
| # 使用 npm 构建 | ||
| RUN NODE_ENV=${NODE_ENV} npm run build | ||
|
|
||
| # production stage | ||
| FROM base AS production | ||
| ENV PORT=3000 | ||
| ENV HOSTNAME=127.0.0.1 | ||
|
|
||
| # set timezone | ||
| ENV TZ=Asia/Shanghai | ||
| RUN ln -s /usr/share/zoneinfo/${TZ} /etc/localtime \ | ||
| && echo ${TZ} > /etc/timezone | ||
|
|
||
| # global runtime packages | ||
| # 使用 cnpm 安装全局包 | ||
| RUN npm install -g cnpm --registry=https://registry.npmmirror.com \ | ||
| && cnpm install -g pm2 \ | ||
| && npm cache clean --force | ||
|
|
||
| WORKDIR /app/web | ||
| COPY --from=builder /app/web/.next/standalone ./ | ||
| COPY --from=builder /app/web/.next/static ./.next/static | ||
|
|
||
| COPY docker/pm2.json ./pm2.json | ||
| COPY docker/entrypoint.sh ./entrypoint.sh | ||
|
|
||
| EXPOSE 3000 | ||
| ENTRYPOINT ["/bin/sh", "./entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). | ||
|
|
||
| ## Getting Started | ||
|
|
||
| First, run the development server: | ||
|
|
||
| ```bash | ||
| npm run dev | ||
| # or | ||
| yarn dev | ||
| # or | ||
| pnpm dev | ||
| # or | ||
| bun dev | ||
| ``` | ||
|
|
||
| Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
|
||
| You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. | ||
|
|
||
| This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. | ||
|
|
||
| ## Learn More | ||
|
|
||
| To learn more about Next.js, take a look at the following resources: | ||
|
|
||
| - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
| - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
|
||
| You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! | ||
|
|
||
| ## Deploy on Vercel | ||
|
|
||
| The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
|
||
| Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "$schema": "https://ui.shadcn.com/schema.json", | ||
| "style": "new-york", | ||
| "rsc": true, | ||
| "tsx": true, | ||
| "tailwind": { | ||
| "config": "tailwind.config.ts", | ||
| "css": "src/app/globals.css", | ||
| "baseColor": "zinc", | ||
| "cssVariables": true, | ||
| "prefix": "" | ||
| }, | ||
| "aliases": { | ||
| "components": "@/components", | ||
| "utils": "@/lib/utils", | ||
| "ui": "@/components/ui", | ||
| "lib": "@/lib", | ||
| "hooks": "@/hooks" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
|
|
||
|
|
||
|
|
||
| # if you are using windows, you may need to convert the file to unix format | ||
| # you can use the Ubuntu terminal to convert this file to unix format | ||
| # otherwise, you may get the error after running the docker container | ||
|
|
||
| # sudo apt-get install dos2unix | ||
| # dos2unix entrypoint.sh | ||
|
|
||
|
|
||
| set -e | ||
|
|
||
| export NEXT_PUBLIC_DEPLOY_ENV=${DEPLOY_ENV} | ||
| export HOSTNAME=0.0.0.0 | ||
|
|
||
| echo "NEXT_PUBLIC_DEPLOY_ENV: ${NEXT_PUBLIC_DEPLOY_ENV}" | ||
| echo "HOSTNAME: ${HOSTNAME}" | ||
| echo "NODE_ENV: ${NODE_ENV}" | ||
|
|
||
| pm2 start ./pm2.json --no-daemon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "apps": [ | ||
| { | ||
| "name": "bella-openapi-web", | ||
| "script": "/app/web/server.js", | ||
| "cwd": "/app/web", | ||
| "exec_mode": "cluster", | ||
| "instances": 2 | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不应该对外暴露8080端口