Compare commits

...

9 Commits

Author SHA1 Message Date
aae61ef27a docs: 添加 Model API 需求文档
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 13:54:06 +08:00
e4970c154f docs: 添加项目截图
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 13:53:58 +08:00
b894e9b21c fix: 优化 Dashboard 页面和类型定义
- Dashboard 页面样式调整
- 添加数据库相关 TypeScript 类型定义

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 13:53:53 +08:00
7e2bf7b508 feat: 新增 Knowledge 和 Settings 页面
- 添加 Knowledge 知识库页面
- 添加 Settings 设置页面
- 添加 Model 设置需求文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 13:53:41 +08:00
64f0db714d feat: 更新路由和侧边栏导航
- 侧边栏添加 Knowledge、Settings、Team 页面链接
- 路由新增对应页面配置
- 注册 Model handler 路由

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 13:53:35 +08:00
aabdf81073 feat: 新增Model管理模块
- 添加 Model 实体定义
- 实现 Model CRUD 接口
- 添加 Model 仓储层和服务层

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 13:53:27 +08:00
eda1af6938 chore: 添加数据库连接配置
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 11:51:58 +08:00
22be617905 feat: 完善子表删除逻辑和table_count同步更新
- 数据库更新时自动删除不在新列表中的子表
- 同步更新 table_count 为当前子表数量
- 删除数据库时级联删除关联的子表记录
- 添加相关需求文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 11:38:27 +08:00
189e2d61d2 chore: 添加数据库连接配置
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 11:38:12 +08:00
25 changed files with 2810 additions and 31 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
screenshots/设置栏.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -70,21 +70,24 @@ func main() {
}
// 3. 自动迁移表
db.AutoMigrate(&model.DatabaseInfo{}, &model.SubTableInfo{})
db.AutoMigrate(&model.DatabaseInfo{}, &model.SubTableInfo{}, &model.ModelInfo{})
// 4. 初始化 Repository
dbRepo := repository.NewDatabaseRepository(db)
subTableRepo := repository.NewSubTableRepository(db)
modelRepo := repository.NewModelRepository(db)
// 5. 初始化 Service
dbService := service.NewDatabaseService(dbRepo, subTableRepo)
subTableService := service.NewSubTableService(subTableRepo, dbRepo)
neo4jService := service.NewNeo4jService(dbRepo)
modelService := service.NewModelService(modelRepo)
// 6. 初始化 Handler
dbHandler := handler.NewDatabaseHandler(dbService)
subTableHandler := handler.NewSubTableHandler(subTableService)
neo4jHandler := handler.NewNeo4jHandler(neo4jService)
modelHandler := handler.NewModelHandler(modelService)
systemHandler := handler.NewSystemHandler()
// 7. 设置路由
@@ -163,6 +166,17 @@ func main() {
neo4jGroup.POST("/relationships", neo4jHandler.GetRelationships)
}
// Model 管理模块
modelGroup := r.Group("/model")
{
modelGroup.GET("/list", modelHandler.List)
modelGroup.GET("/:id", modelHandler.GetByID)
modelGroup.POST("/add", modelHandler.Create)
modelGroup.PUT("/:id", modelHandler.Update)
modelGroup.DELETE("/:id", modelHandler.Delete)
modelGroup.POST("/test", modelHandler.Test)
}
// 系统信息模块
r.GET("/system/info", systemHandler.GetSystemInfo)

View File

@@ -0,0 +1,108 @@
package handler
import (
"net/http"
"x-agents/server/internal/model"
"x-agents/server/internal/service"
"github.com/gin-gonic/gin"
)
// ModelHandler 模型处理器
type ModelHandler struct {
service *service.ModelService
}
func NewModelHandler(svc *service.ModelService) *ModelHandler {
return &ModelHandler{service: svc}
}
// List 获取列表
func (h *ModelHandler) List(c *gin.Context) {
list, err := h.service.List()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
if list == nil {
list = []model.ModelInfo{}
}
c.JSON(http.StatusOK, gin.H{"list": list})
}
// GetByID 获取详情
func (h *ModelHandler) GetByID(c *gin.Context) {
id := c.Param("id")
model, err := h.service.GetByID(id)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Model not found"})
return
}
c.JSON(http.StatusOK, model)
}
// Create 创建
func (h *ModelHandler) Create(c *gin.Context) {
var req model.CreateModelRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.service.Create(req)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, result)
}
// Update 更新
func (h *ModelHandler) Update(c *gin.Context) {
id := c.Param("id")
var req model.UpdateModelRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.service.Update(id, req)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, result)
}
// Delete 删除
func (h *ModelHandler) Delete(c *gin.Context) {
id := c.Param("id")
err := h.service.Delete(id)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"success": true})
}
// Test 测试连接
func (h *ModelHandler) Test(c *gin.Context) {
var req model.TestModelRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := h.service.TestConnection(req)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, result)
}

View File

@@ -0,0 +1,69 @@
package model
import "time"
// ModelInfo 模型信息
type ModelInfo struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
Name string `json:"name" gorm:"type:varchar(255);not null"`
ModelType string `json:"model_type" gorm:"type:varchar(50);not null"` // chat/embedding/rerank/vlm
Provider string `json:"provider" gorm:"type:varchar(50);not null"` // OpenAI/Ollama
Model string `json:"model" gorm:"type:varchar(255);not null"` // 模型标识
APIKey string `json:"api_key" gorm:"type:text"` // API 密钥
BaseURL string `json:"base_url" gorm:"type:varchar(500)"` // 基础 URL
APIEndpoint string `json:"api_endpoint" gorm:"type:varchar(500)"` // API 端点路径
Status string `json:"status" gorm:"type:varchar(20);default:active"` // active/inactive
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (ModelInfo) TableName() string {
return "model_info"
}
// ModelListRequest 获取模型列表请求
type ModelListRequest struct {
}
// ModelListResponse 获取模型列表响应
type ModelListResponse struct {
List []ModelInfo `json:"list"`
}
// CreateModelRequest 创建模型请求
type CreateModelRequest struct {
Name string `json:"name" binding:"required"`
ModelType string `json:"model_type" binding:"required"`
Provider string `json:"provider" binding:"required"`
Model string `json:"model" binding:"required"`
APIKey string `json:"api_key" binding:"required"`
BaseURL string `json:"base_url" binding:"required"`
APIEndpoint string `json:"api_endpoint"`
}
// UpdateModelRequest 更新模型请求
type UpdateModelRequest struct {
Name string `json:"name"`
ModelType string `json:"model_type"`
Provider string `json:"provider"`
Model string `json:"model"`
APIKey string `json:"api_key"`
BaseURL string `json:"base_url"`
APIEndpoint string `json:"api_endpoint"`
Status string `json:"status"`
}
// TestModelRequest 测试模型连接请求
type TestModelRequest struct {
Provider string `json:"provider" binding:"required"`
Model string `json:"model" binding:"required"`
APIKey string `json:"api_key" binding:"required"`
BaseURL string `json:"base_url" binding:"required"`
APIEndpoint string `json:"api_endpoint"`
}
// TestModelResponse 测试模型连接响应
type TestModelResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
}

View File

@@ -0,0 +1,53 @@
package repository
import (
"x-agents/server/internal/model"
"gorm.io/gorm"
)
// ModelRepository 模型仓储
type ModelRepository struct {
db *gorm.DB
}
func NewModelRepository(db *gorm.DB) *ModelRepository {
return &ModelRepository{db: db}
}
// FindAll 获取所有模型
func (r *ModelRepository) FindAll() ([]model.ModelInfo, error) {
var models []model.ModelInfo
err := r.db.Order("created_at desc").Find(&models).Error
return models, err
}
// FindByID 根据 ID 获取模型
func (r *ModelRepository) FindByID(id string) (*model.ModelInfo, error) {
var model model.ModelInfo
err := r.db.Where("id = ?", id).First(&model).Error
if err != nil {
return nil, err
}
return &model, nil
}
// Create 创建模型
func (r *ModelRepository) Create(info *model.ModelInfo) error {
return r.db.Create(info).Error
}
// Update 更新模型
func (r *ModelRepository) Update(id string, info *model.ModelInfo) error {
return r.db.Where("id = ?", id).Updates(info).Error
}
// Delete 删除模型
func (r *ModelRepository) Delete(id string) error {
return r.db.Where("id = ?", id).Delete(&model.ModelInfo{}).Error
}
// UpdateFields 更新指定字段
func (r *ModelRepository) UpdateFields(id string, fields map[string]interface{}) error {
return r.db.Model(&model.ModelInfo{}).Where("id = ?", id).Updates(fields).Error
}

View File

@@ -704,16 +704,17 @@ func (s *DatabaseService) Update(id string, req model.UpdateDatabaseRequest) (*m
}
// 处理 SubTables - 创建或更新子表记录(包括 DDL
// 先查询当前已有的子表
existingTables, err := s.subTableRepo.FindByDatabaseID(id)
if err != nil {
log.Printf("[Update] 查询子表失败: %v", err)
}
if len(req.SubTables) > 0 {
log.Printf("[Update] 处理 %d 个子表配置", len(req.SubTables))
for _, subTableReq := range req.SubTables {
subTableReq.DatabaseID = id
// 检查是否已存在(根据 parent_table 查找)
existingTables, err := s.subTableRepo.FindByDatabaseID(id)
if err != nil {
log.Printf("[Update] 查询子表失败: %v", err)
continue
}
found := false
for _, existing := range existingTables {
if existing.ParentTable == subTableReq.ParentTable {
@@ -756,6 +757,42 @@ func (s *DatabaseService) Update(id string, req model.UpdateDatabaseRequest) (*m
}
}
// 删除不在新列表中的子表(无论 req.SubTables 是否为空都执行)
if existingTables != nil && len(existingTables) > 0 {
// 重新查询最新的子表列表
allSubTables, err := s.subTableRepo.FindByDatabaseID(id)
if err != nil {
log.Printf("[Update] 查询子表失败: %v", err)
} else {
// 构建新请求中的 parent_table 集合
newParentTables := make(map[string]bool)
for _, st := range req.SubTables {
newParentTables[st.ParentTable] = true
}
// 删除不存在的子表
for _, existing := range allSubTables {
if !newParentTables[existing.ParentTable] {
log.Printf("[Update] 删除子表: %s (不在新列表中)", existing.ID)
if err := s.subTableRepo.Delete(existing.ID); err != nil {
log.Printf("[Update] 删除子表失败: %v", err)
}
}
}
}
}
// 始终更新 table_count 为当前子表数量
allSubTables, err := s.subTableRepo.FindByDatabaseID(id)
if err != nil {
log.Printf("[Update] 查询子表数量失败: %v", err)
} else {
tableCount := len(allSubTables)
log.Printf("[Update] 更新 table_count 为: %d", tableCount)
if err := s.repo.UpdateFields(id, map[string]interface{}{"table_count": tableCount}); err != nil {
log.Printf("[Update] 更新 table_count 失败: %v", err)
}
}
return s.repo.FindByID(id)
}
@@ -922,5 +959,12 @@ func (s *DatabaseService) Delete(id string) error {
log.Printf("[Delete] 不存在: %v", err)
return ErrDatabaseNotFound
}
// 先删除关联的子表记录
if err := s.subTableRepo.DeleteByDatabaseID(id); err != nil {
log.Printf("[Delete] 删除子表失败: %v", err)
// 继续尝试删除主表
}
return s.repo.Delete(id)
}

View File

@@ -0,0 +1,166 @@
package service
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"x-agents/server/internal/model"
"x-agents/server/internal/repository"
"github.com/google/uuid"
)
// ModelService 模型服务
type ModelService struct {
repo *repository.ModelRepository
}
func NewModelService(repo *repository.ModelRepository) *ModelService {
return &ModelService{repo: repo}
}
// List 获取模型列表
func (s *ModelService) List() ([]model.ModelInfo, error) {
return s.repo.FindAll()
}
// GetByID 根据 ID 获取模型
func (s *ModelService) GetByID(id string) (*model.ModelInfo, error) {
return s.repo.FindByID(id)
}
// Create 创建模型
func (s *ModelService) Create(req model.CreateModelRequest) (*model.ModelInfo, error) {
info := &model.ModelInfo{
ID: uuid.New().String(),
Name: req.Name,
ModelType: req.ModelType,
Provider: req.Provider,
Model: req.Model,
APIKey: req.APIKey,
BaseURL: req.BaseURL,
APIEndpoint: req.APIEndpoint,
Status: "active",
}
if err := s.repo.Create(info); err != nil {
return nil, err
}
return info, nil
}
// Update 更新模型
func (s *ModelService) Update(id string, req model.UpdateModelRequest) (*model.ModelInfo, error) {
// 检查是否存在
_, err := s.repo.FindByID(id)
if err != nil {
return nil, fmt.Errorf("model not found")
}
// 构建更新字段
fields := make(map[string]interface{})
if req.Name != "" {
fields["name"] = req.Name
}
if req.ModelType != "" {
fields["model_type"] = req.ModelType
}
if req.Provider != "" {
fields["provider"] = req.Provider
}
if req.Model != "" {
fields["model"] = req.Model
}
if req.APIKey != "" {
fields["api_key"] = req.APIKey
}
if req.BaseURL != "" {
fields["base_url"] = req.BaseURL
}
if req.APIEndpoint != "" {
fields["api_endpoint"] = req.APIEndpoint
}
if req.Status != "" {
fields["status"] = req.Status
}
if err := s.repo.UpdateFields(id, fields); err != nil {
return nil, err
}
return s.repo.FindByID(id)
}
// Delete 删除模型
func (s *ModelService) Delete(id string) error {
// 检查是否存在
_, err := s.repo.FindByID(id)
if err != nil {
return fmt.Errorf("model not found")
}
return s.repo.Delete(id)
}
// TestConnection 测试模型连接
func (s *ModelService) TestConnection(req model.TestModelRequest) (*model.TestModelResponse, error) {
// 构建请求 URL
baseURL := req.BaseURL
if req.APIEndpoint != "" {
baseURL = baseURL + req.APIEndpoint
} else {
// 默认端点
switch req.Provider {
case "OpenAI":
baseURL = baseURL + "/v1/chat/completions"
case "Ollama":
baseURL = baseURL + "/api/chat"
}
}
// 构建请求体
requestBody := map[string]interface{}{
"model": req.Model,
"messages": []map[string]string{
{"role": "user", "content": "Hello"},
},
"max_tokens": 10,
}
body, err := json.Marshal(requestBody)
if err != nil {
return &model.TestModelResponse{Success: false, Message: err.Error()}, nil
}
// 创建 HTTP 请求
httpReq, err := http.NewRequest("POST", baseURL, bytes.NewBuffer(body))
if err != nil {
return &model.TestModelResponse{Success: false, Message: err.Error()}, nil
}
httpReq.Header.Set("Content-Type", "application/json")
if req.APIKey != "" {
httpReq.Header.Set("Authorization", "Bearer "+req.APIKey)
}
// 发送请求
client := &http.Client{}
resp, err := client.Do(httpReq)
if err != nil {
return &model.TestModelResponse{Success: false, Message: err.Error()}, nil
}
defer resp.Body.Close()
// 读取响应
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return &model.TestModelResponse{Success: false, Message: err.Error()}, nil
}
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
return &model.TestModelResponse{Success: true, Message: "Connection successful"}, nil
}
return &model.TestModelResponse{Success: false, Message: fmt.Sprintf("HTTP %d: %s", resp.StatusCode, string(respBody))}, nil
}

View File

@@ -0,0 +1,22 @@
{
"database_id": "1ee87735-9ddd-4831-85ce-c1a571ab996b",
"database_name": "1231",
"db_type": "mysql",
"tables": [
{
"id": "4402a7c4-7ff4-4084-a76b-4b7e0a34695c",
"database_id": "1ee87735-9ddd-4831-85ce-c1a571ab996b",
"parent_table": "scores",
"sub_table_name": "scores",
"sub_table_comment": "",
"mapping_type": "",
"relation_field": "",
"relation_type": "",
"fields": null,
"ddl": "CREATE TABLE `scores` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `student_id` int(10) unsigned NOT NULL,\n `subject` varchar(50) NOT NULL COMMENT '科目',\n `score` double DEFAULT NULL COMMENT '分数',\n `teacher_id` int(10) unsigned DEFAULT NULL,\n `exam_date` date DEFAULT NULL COMMENT '考试日期',\n `created_at` datetime DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8mb4",
"created_at": "2026-03-07T10:33:25.752+08:00",
"updated_at": "2026-03-07T10:33:25.752+08:00"
}
],
"updated_at": "2026-03-07T10:33:25.8031128+08:00"
}

View File

@@ -0,0 +1,22 @@
{
"database_id": "4e3ce862-5936-45f8-baf2-c9c2895c2303",
"database_name": "1231",
"db_type": "mysql",
"tables": [
{
"id": "f394a250-623b-4da0-81e5-1e5d93bed982",
"database_id": "4e3ce862-5936-45f8-baf2-c9c2895c2303",
"parent_table": "scores",
"sub_table_name": "scores",
"sub_table_comment": "",
"mapping_type": "",
"relation_field": "",
"relation_type": "",
"fields": null,
"ddl": "CREATE TABLE `scores` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `student_id` int(10) unsigned NOT NULL,\n `subject` varchar(50) NOT NULL COMMENT '科目',\n `score` double DEFAULT NULL COMMENT '分数',\n `teacher_id` int(10) unsigned DEFAULT NULL,\n `exam_date` date DEFAULT NULL COMMENT '考试日期',\n `created_at` datetime DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8mb4",
"created_at": "2026-03-07T10:37:08.868+08:00",
"updated_at": "2026-03-07T10:37:08.868+08:00"
}
],
"updated_at": "2026-03-07T10:37:08.918463+08:00"
}

View File

@@ -0,0 +1,36 @@
{
"database_id": "a89dfc3e-5089-4a9e-8f6b-991d5bebd85d",
"database_name": "1231",
"db_type": "mysql",
"tables": [
{
"id": "0fbec3c2-ab05-4288-a797-bdf03eec9f2b",
"database_id": "a89dfc3e-5089-4a9e-8f6b-991d5bebd85d",
"parent_table": "students",
"sub_table_name": "students",
"sub_table_comment": "",
"mapping_type": "",
"relation_field": "",
"relation_type": "",
"fields": null,
"ddl": "CREATE TABLE `students` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `name` varchar(50) NOT NULL COMMENT '学生姓名',\n `age` int(11) DEFAULT NULL COMMENT '年龄',\n `gender` varchar(10) DEFAULT NULL COMMENT '性别',\n `class` varchar(50) DEFAULT NULL COMMENT '班级',\n `phone` varchar(20) DEFAULT NULL COMMENT '电话',\n `created_at` datetime DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb4",
"created_at": "2026-03-07T10:44:27.61+08:00",
"updated_at": "2026-03-07T10:44:27.61+08:00"
},
{
"id": "693944e2-d610-4a09-aee9-1af0c8246fb4",
"database_id": "a89dfc3e-5089-4a9e-8f6b-991d5bebd85d",
"parent_table": "scores",
"sub_table_name": "scores",
"sub_table_comment": "",
"mapping_type": "",
"relation_field": "",
"relation_type": "",
"fields": null,
"ddl": "CREATE TABLE `scores` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `student_id` int(10) unsigned NOT NULL,\n `subject` varchar(50) NOT NULL COMMENT '科目',\n `score` double DEFAULT NULL COMMENT '分数',\n `teacher_id` int(10) unsigned DEFAULT NULL,\n `exam_date` date DEFAULT NULL COMMENT '考试日期',\n `created_at` datetime DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8mb4",
"created_at": "2026-03-07T10:44:27.56+08:00",
"updated_at": "2026-03-07T10:44:27.56+08:00"
}
],
"updated_at": "2026-03-07T10:44:27.6628932+08:00"
}

View File

@@ -0,0 +1,208 @@
# Model Settings 接口文档
## 接口列表
### 1. 获取模型列表
**接口地址:** `GET /model/list`
**返回参数:**
```json
{
"list": [
{
"id": "xxx-xxx-xxx",
"name": "OpenAI",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions",
"status": "active",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
]
}
```
---
### 2. 获取模型详情
**接口地址:** `GET /model/:id`
**返回参数:**
```json
{
"id": "xxx-xxx-xxx",
"name": "OpenAI",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions",
"status": "active",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
```
---
### 3. 创建模型
**接口地址:** `POST /model/add`
**请求参数:**
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 是 | 模型名称 |
| model_type | string | 是 | 模型类型chat/embedding/rerank/vlm |
| provider | string | 是 | 提供商OpenAI/Ollama |
| model | string | 是 | 模型标识,如 gpt-4o |
| api_key | string | 是 | API 密钥 |
| base_url | string | 是 | 基础 URL |
| api_endpoint | string | 否 | API 端点路径 |
**请求示例:**
```json
{
"name": "OpenAI",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions"
}
```
**返回参数:**
```json
{
"id": "xxx-xxx-xxx",
"name": "OpenAI",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions",
"status": "active",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
```
---
### 4. 更新模型
**接口地址:** `PUT /model/:id`
**请求参数:**
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 否 | 模型名称 |
| model_type | string | 否 | 模型类型chat/embedding/rerank/vlm |
| provider | string | 否 | 提供商OpenAI/Ollama |
| model | string | 否 | 模型标识 |
| api_key | string | 否 | API 密钥 |
| base_url | string | 否 | 基础 URL |
| api_endpoint | string | 否 | API 端点路径 |
| status | string | 否 | 状态active/inactive |
**请求示例:**
```json
{
"name": "OpenAI Updated",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions",
"status": "active"
}
```
---
### 5. 删除模型
**接口地址:** `DELETE /model/:id`
**返回参数:**
```json
{
"success": true
}
```
---
### 6. 测试连接
**接口地址:** `POST /model/test`
**请求参数:**
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| provider | string | 是 | 提供商OpenAI/Ollama |
| model | string | 是 | 模型标识 |
| api_key | string | 是 | API 密钥 |
| base_url | string | 是 | 基础 URL |
| api_endpoint | string | 否 | API 端点路径 |
**请求示例:**
```json
{
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions"
}
```
**返回参数:**
```json
{
"success": true,
"message": "Connection successful"
}
```
或失败时:
```json
{
"success": false,
"message": "HTTP 401: Unauthorized"
}
```
---
## 数据结构
### ModelInfo 模型信息
| 字段 | 类型 | 说明 |
|------|------|------|
| id | string | 主键 UUID |
| name | string | 模型名称 |
| model_type | string | 模型类型chat/embedding/rerank/vlm |
| provider | string | 提供商OpenAI/Ollama |
| model | string | 模型标识 |
| api_key | string | API 密钥 |
| base_url | string | 基础 URL |
| api_endpoint | string | API 端点路径 |
| status | string | 状态active/inactive |
| created_at | datetime | 创建时间 |
| updated_at | datetime | 更新时间 |

View File

@@ -0,0 +1,193 @@
# Model Settings 需求文档
## 需求概述
Model Settings 页面用于管理 AI 模型配置,支持添加、编辑、删除和测试模型连接。
## 功能列表
### 1. 模型列表展示
展示已配置的模型列表,包含以下字段:
- Model Name模型名称
- Model Type模型类型Chat / Embedding / Rerank / VLM
- API EndpointAPI 端点)
- Status状态Active / Inactive
### 2. 添加新模型
点击 "Add New Model" 按钮,弹出表单包含以下字段:
- Model Name必填
- Model Type必选Chat / Embedding / Rerank / VLM
- Provider必选OpenAI / Ollama
- Model必填模型名称如 gpt-4o
- API Key必填
- Base URL必填
- API Endpoint可选
### 3. 测试连接
在添加模型表单中提供 "Test Connection" 按钮,用于验证模型连接是否可用。
### 4. 编辑模型
点击编辑按钮,弹出编辑表单,可修改模型信息。
### 5. 删除模型
点击删除按钮,确认后删除模型记录。
---
## 后端接口需求
### 1. 获取模型列表
**接口地址:** `GET /api/models``GET /model/list`
**返回参数:**
```json
{
"list": [
{
"id": "1",
"name": "OpenAI",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions",
"status": "active",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
]
}
```
### 2. 添加模型
**接口地址:** `POST /api/models``POST /model/add`
**请求参数:**
```json
{
"name": "OpenAI",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions"
}
```
**返回参数:**
```json
{
"id": "1",
"name": "OpenAI",
"model_type": "chat",
...
}
```
### 3. 更新模型
**接口地址:** `PUT /api/models/{id}``PUT /model/{id}`
**请求参数:**
```json
{
"name": "OpenAI Updated",
"model_type": "chat",
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions",
"status": "active"
}
```
### 4. 删除模型
**接口地址:** `DELETE /api/models/{id}``DELETE /model/{id}`
**返回参数:**
```json
{
"success": true
}
```
### 5. 测试连接
**接口地址:** `POST /api/models/test``POST /model/test`
**请求参数:**
```json
{
"provider": "OpenAI",
"model": "gpt-4o",
"api_key": "sk-xxx",
"base_url": "https://api.openai.com",
"api_endpoint": "/v1/chat/completions"
}
```
**返回参数:**
```json
{
"success": true,
"message": "Connection successful"
}
```
---
## 数据结构
### Model 表结构(参考)
| 字段 | 类型 | 说明 |
|------|------|------|
| id | string | 主键 UUID |
| name | string | 模型名称 |
| model_type | string | 模型类型chat/embedding/rerank/vlm |
| provider | string | 提供商OpenAI/Ollama |
| model | string | 模型标识 |
| api_key | string | API 密钥(加密存储) |
| base_url | string | 基础 URL |
| api_endpoint | string | API 端点路径 |
| status | string | 状态active/inactive |
| created_at | datetime | 创建时间 |
| updated_at | datetime | 更新时间 |
---
## 前端组件状态
### 表单数据 (newModelForm)
```typescript
{
name: string,
apiKey: string,
apiEndpoint: string,
baseUrl: string,
provider: string,
model: string,
modelType: string
}
```
### 模型类型选项 (modelTypeOptions)
- Chat
- Embedding
- Rerank
- VLM
### 提供商选项 (providerOptions)
- OpenAI
- Ollama

View File

@@ -0,0 +1,35 @@
# 后端需求 - 编辑数据库时正确处理 sub_tables
## 问题描述
用户点击 Action 修改数据库,进入 Map Tables 页面后:
1. 初始显示 2 个已选中的表
2. 用户取消选中 1 个表,只保留 1 个
3. 点击 Save Mapping 保存
4. 再次点击 Map Tables 查看时,仍然显示 2 个表,而不是修改后的 1 个
## 原因
可能的问题:
1. 编辑时没有正确从数据库加载已保存的 sub_tables 数据
2. Save Mapping 时没有正确更新 sub_tables可能只是创建新的没有删除已取消的
## 需求
### 1. 加载数据库时返回 sub_tables 数据
在获取数据库详情时,需要返回该数据库已保存的子表映射信息(包括 parent_table 等),以便前端正确显示已选中的表。
### 2. 保存时正确处理子表
- 新增的子表:创建新记录
- 保留的子表:更新记录
- 取消的子表:删除对应记录
或者使用更简单的方案:
- 保存时删除该数据库所有的旧 sub_tables
- 重新创建新的 sub_tables 记录
## 状态
- [ ] 后端修改待实现

View File

@@ -0,0 +1,22 @@
# 后端需求 - 编辑数据库时更新 table_count
## 问题描述
用户点击 Action 修改数据库,从 2 个子表修改为 1 个子表并保存后,数据库列表中的 Tables 列没有更新为新的数量。
## 原因
编辑数据库并保存 sub_tables 时,后端没有更新 `table_count` 字段。
## 需求
在 UpdateDatabaseRequest 处理 `SubTables` 字段时,需要同步更新数据库记录的 `table_count` 字段为当前 sub_tables 的数量。
### 修改位置
- `server/internal/service/database_service.go` 或 handler
- 在 Update 方法中处理 SubTables 时更新 table_count
## 状态
- [x] 后端修改已完成

View File

@@ -0,0 +1,30 @@
# 后端需求 - 保存映射时更新 table_count
## 问题描述
用户在 Database 列表页面看到 Table Mapping 选中 2 个表并保存后,表格的 Tables 列仍然显示 1没有更新为实际选中的表数量。
## 原因
保存 Table Mapping 时,后端没有更新数据库的 `table_count` 字段。
## 需求
在保存子表映射时,需要同时更新数据库的 `table_count` 字段为实际保存的子表数量。
### 修改位置
- `server/internal/service/database_service.go` 或 handler
- 在处理 `SubTables` 保存逻辑后,更新 `database_info` 表的 `table_count` 字段
### 逻辑
```go
// 保存 sub_tables 后,更新 table_count
tableCount := len(subTables)
// 更新数据库记录的 table_count 字段
```
## 状态
- [x] 后端修改已完成

View File

@@ -8,6 +8,18 @@
- 前端只发送 ddl 字段,不再发送 fields 字段
- 详细需求:[ddl-edit.md](./ddl-edit.md)
- [x] **保存映射时更新 table_count** - 后端已完成 ✔
- 问题:用户保存 2 个子表后Tables 列仍显示 1
- 详细需求:[table-count-update.md](./table-count-update.md)
- [x] **编辑数据库时更新 table_count** - 后端已完成 ✔
- 问题:用户从 2 个子表修改为 1 个后Tables 列没有更新
- 详细需求:[table-count-update-edit.md](./table-count-update-edit.md)
- [ ] **编辑时正确处理 sub_tables** - 后端待实现
- 问题:取消选中 1 个表后保存,再次进入仍显示 2 个表
- 详细需求:[sub-tables-edit.md](./sub-tables-edit.md)
---
> 需求完成后请完成者打 ✔

View File

@@ -1,6 +1,10 @@
<script setup lang="ts">
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessageBox } from 'element-plus'
// 下拉菜单展开状态
const userDropdownVisible = ref(false)
const router = useRouter()
const route = useRoute()
@@ -19,13 +23,13 @@ const mainMenu: MenuItem[] = [
{ name: 'Skills', icon: 'fa-wand-magic-sparkles', badge: 21, path: '/mcp' },
{ name: 'Tools', icon: 'fa-tools', badge: 13, path: '/model-apis' },
{ name: 'Database', icon: 'fa-database', path: '/database' },
{ name: 'Knowledge', icon: 'fa-book' },
{ name: 'Knowledge', icon: 'fa-brain', path: '/knowledge' },
]
const bottomMenu: MenuItem[] = [
{ name: 'API Keys', icon: 'fa-key' },
{ name: 'Settings', icon: 'fa-gear' },
{ name: 'Team', icon: 'fa-users' },
{ name: 'API Keys', icon: 'fa-key', path: '/api-keys' },
{ name: 'Settings', icon: 'fa-gear', path: '/settings' },
{ name: 'Team', icon: 'fa-users', path: '/team' },
{ name: 'Service Accounts', icon: 'fa-user-shield' },
{ name: 'Integrations', icon: 'fa-plug' },
]
@@ -37,8 +41,13 @@ const bottomMenu2: MenuItem[] = [
const activeMenu = computed(() => {
const currentPath = route.path
// Check main menu
const menuItem = mainMenu.find(item => item.path === currentPath)
return menuItem ? menuItem.name : 'Dashboard'
if (menuItem) return menuItem.name
// Check bottom menu
const bottomItem = bottomMenu.find(item => item.path === currentPath)
if (bottomItem) return bottomItem.name
return 'Dashboard'
})
const navigateTo = (item: MenuItem) => {
@@ -46,6 +55,32 @@ const navigateTo = (item: MenuItem) => {
router.push(item.path)
}
}
// 用户菜单操作
const handleUserCommand = (command: string) => {
switch (command) {
case 'settings':
// 全局设置
router.push('/settings')
break
case 'userManagement':
// 用户管理
router.push('/user-management')
break
case 'logout':
// 退出登录
ElMessageBox.confirm('确定要退出登录吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
// 清除登录状态
localStorage.removeItem('token')
router.push('/login')
}).catch(() => {})
break
}
}
</script>
<template>
@@ -90,7 +125,9 @@ const navigateTo = (item: MenuItem) => {
<li v-for="item in bottomMenu" :key="item.name">
<a
href="#"
class="flex items-center justify-between px-3 py-2.5 rounded-lg hover:bg-dark-600 text-gray-400 hover:text-white transition-colors text-sm"
class="flex items-center justify-between px-3 py-2.5 rounded-lg transition-colors text-sm"
:class="activeMenu === item.name ? 'bg-dark-600 text-white' : 'text-gray-400 hover:bg-dark-600 hover:text-white'"
@click="navigateTo(item)"
>
<div class="flex items-center gap-3">
<i :class="['fa-solid', item.icon, 'w-5', 'text-center']"></i>
@@ -117,6 +154,7 @@ const navigateTo = (item: MenuItem) => {
<a
href="#"
class="flex items-center gap-3 px-3 py-2.5 rounded-lg hover:bg-dark-600 text-gray-400 hover:text-white transition-colors text-sm"
@click="navigateTo(item)"
>
<i :class="['fa-solid', item.icon, 'w-5', 'text-center']"></i>
<span>{{ item.name }}</span>
@@ -126,14 +164,66 @@ const navigateTo = (item: MenuItem) => {
</nav>
<!-- 底部用户信息 -->
<div class="p-4 border-t border-dark-500">
<div class="flex items-center gap-3">
<img src="https://picsum.photos/id/64/40/40" alt="User Avatar" class="w-8 h-8 rounded-full object-cover">
<div>
<div class="font-medium text-sm text-gray-300">Alex Smith</div>
<div class="text-xs text-gray-500">alex@gmail.com</div>
<div class="border-t border-dark-500">
<el-dropdown trigger="click" @command="handleUserCommand" class="user-dropdown" @visible-change="(v: boolean) => userDropdownVisible = v">
<div class="w-full flex items-center justify-between cursor-pointer hover:bg-dark-600 px-4 py-3 transition-colors">
<div class="flex items-center gap-3">
<img src="https://picsum.photos/id/64/40/40" alt="User Avatar" class="w-8 h-8 rounded-full object-cover">
<div class="min-w-0">
<div class="font-medium text-sm text-gray-300 truncate">Alex Smith</div>
<div class="text-xs text-gray-500 truncate">alex@gmail.com</div>
</div>
</div>
<i :class="['fa-solid', userDropdownVisible ? 'fa-chevron-up' : 'fa-chevron-down', 'text-xs', 'text-gray-500']"></i>
</div>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="settings">
<i class="fa-solid fa-gear w-4 text-center"></i>
Settings
</el-dropdown-item>
<el-dropdown-item command="userManagement">
<i class="fa-solid fa-user w-4 text-center"></i>
Users
</el-dropdown-item>
<el-dropdown-item divided command="logout">
<i class="fa-solid fa-arrow-right-from-bracket w-4 text-center"></i>
Sign Out
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</aside>
</template>
<style>
.user-dropdown {
width: 100%;
}
.user-dropdown .el-dropdown-menu {
background-color: #262626;
border: none;
padding: 6px;
border-radius: 10px;
min-width: 200px;
}
.user-dropdown .el-dropdown-menu__item {
color: white;
padding: 8px 14px;
border-radius: 6px;
font-size: 13px;
display: flex;
align-items: center;
gap: 10px;
}
.user-dropdown .el-dropdown-menu__item:hover {
background-color: #F97316;
color: white;
}
.user-dropdown .el-dropdown-menu__item--divided {
border-top: 1px solid #404040;
margin-top: 4px;
padding-top: 8px;
}
</style>

View File

@@ -5,6 +5,8 @@ import Agents from '@/views/Agents.vue'
import MCP from '@/views/MCP.vue'
import ModelAPIs from '@/views/ModelAPIs.vue'
import Database from '@/views/Database.vue'
import Knowledge from '@/views/Knowledge.vue'
import Settings from '@/views/Settings.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@@ -38,6 +40,16 @@ const router = createRouter({
path: '/database',
name: 'database',
component: Database
},
{
path: '/knowledge',
name: 'knowledge',
component: Knowledge
},
{
path: '/settings',
name: 'settings',
component: Settings
}
]
})

View File

@@ -192,17 +192,8 @@ const topRequestsTab = ref<'general' | 'errors'>('general')
<h3 class="font-semibold text-lg">Active Agents</h3>
<div class="flex items-center gap-2">
<span class="text-sm text-gray-400">Errors</span>
<!-- 开启状态开关 -->
<div
class="w-10 h-5 rounded-full relative cursor-pointer transition-colors"
:class="agentErrorEnabled ? 'bg-primary-orange' : 'bg-dark-500'"
@click="agentErrorEnabled = !agentErrorEnabled"
>
<div
class="absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform"
:class="agentErrorEnabled ? 'right-0.5' : 'left-0.5'"
></div>
</div>
<!-- 使用 Element Plus 开关组件 -->
<el-switch v-model="agentErrorEnabled" class="error-switch" />
</div>
</div>
<div class="text-4xl font-bold mb-4">{{ displayStats.activeAgents }}</div>
@@ -394,3 +385,13 @@ const topRequestsTab = ref<'general' | 'errors'>('general')
</div>
</div>
</template>
<style scoped>
.error-switch {
--el-switch-on-color: #f97316;
--el-switch-off-color: #374151;
}
.error-switch :deep(.el-switch__action) {
background-color: white;
}
</style>

466
web/src/views/Knowledge.vue Normal file
View File

@@ -0,0 +1,466 @@
<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import './database/database.css'
// 模拟知识库数据
const knowledgeBases = ref([
{
id: '1',
name: 'Product Documentation',
description: 'Product user manual and API docs',
document_count: 156,
chunk_count: 1248,
created_at: '2024-01-15T10:30:00Z',
status: 'ready'
},
{
id: '2',
name: 'Company Policies',
description: 'Internal company policies and procedures',
document_count: 42,
chunk_count: 320,
created_at: '2024-01-20T14:20:00Z',
status: 'ready'
},
{
id: '3',
name: 'Technical Wiki',
description: 'Engineering documentation and RFCs',
document_count: 89,
chunk_count: 756,
created_at: '2024-02-01T09:15:00Z',
status: 'processing'
},
])
const loading = ref(false)
const searchQuery = ref('')
// 筛选知识库
const filteredKnowledgeBases = () => {
if (!searchQuery.value) return knowledgeBases.value
const query = searchQuery.value.toLowerCase()
return knowledgeBases.value.filter(kb =>
kb.name.toLowerCase().includes(query) ||
kb.description.toLowerCase().includes(query)
)
}
// 新建知识库
const showCreateDialog = ref(false)
const newKbForm = ref({
name: '',
description: '',
})
const createKnowledgeBase = () => {
if (!newKbForm.value.name) {
ElMessage.warning('Please enter knowledge base name')
return
}
knowledgeBases.value.push({
id: Date.now().toString(),
name: newKbForm.value.name,
description: newKbForm.value.description,
document_count: 0,
chunk_count: 0,
created_at: new Date().toISOString(),
status: 'ready'
})
newKbForm.value = { name: '', description: '' }
showCreateDialog.value = false
ElMessage.success('Knowledge base created successfully')
}
const cancelCreate = () => {
newKbForm.value = { name: '', description: '' }
showCreateDialog.value = false
}
// 编辑知识库
const showEditDialog = ref(false)
const editForm = ref({
id: '',
name: '',
description: '',
})
const openEdit = (kb: any) => {
editForm.value = {
id: kb.id,
name: kb.name,
description: kb.description
}
showEditDialog.value = true
}
const saveEdit = () => {
const kb = knowledgeBases.value.find(k => k.id === editForm.value.id)
if (kb) {
kb.name = editForm.value.name
kb.description = editForm.value.description
}
showEditDialog.value = false
ElMessage.success('Knowledge base updated successfully')
}
const cancelEdit = () => {
showEditDialog.value = false
}
// 删除知识库
const deleteKb = (id: string) => {
const index = knowledgeBases.value.findIndex(k => k.id === id)
if (index > -1) {
knowledgeBases.value.splice(index, 1)
ElMessage.success('Knowledge base deleted')
}
}
// 查看详情
const viewDetail = (kb: any) => {
ElMessage.info(`Viewing ${kb.name}`)
}
</script>
<template>
<div class="p-6 min-h-screen">
<!-- 顶部导航 -->
<div class="flex justify-between items-center mb-6">
<div class="flex items-center gap-2">
<i class="fa-solid fa-brain text-gray-400"></i>
<span class="font-medium">Knowledge Base</span>
</div>
<button @click="showCreateDialog = true" class="btn-primary">
<i class="fa-solid fa-plus"></i>
New Knowledge Base
</button>
</div>
<!-- 搜索 -->
<div class="flex gap-4 mb-6">
<div class="flex-1 relative">
<i class="fa-solid fa-search absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"></i>
<input
v-model="searchQuery"
type="text"
placeholder="Search knowledge bases by name or description..."
class="search-input w-full"
>
</div>
</div>
<!-- Knowledge Base 列表 -->
<div class="bg-dark-700 rounded-xl overflow-hidden">
<div v-if="loading" class="py-12 text-center text-gray-400">
<i class="fa-solid fa-circle-notch fa-spin text-2xl mb-2"></i>
<p>Loading...</p>
</div>
<table v-else-if="filteredKnowledgeBases().length > 0" class="w-full">
<thead class="bg-dark-600">
<tr>
<th class="text-left px-5 py-3 text-sm font-medium text-gray-400">Name</th>
<th class="text-center px-5 py-3 text-sm font-medium text-gray-400">Documents</th>
<th class="text-center px-5 py-3 text-sm font-medium text-gray-400">Chunks</th>
<th class="text-center px-5 py-3 text-sm font-medium text-gray-400">Status</th>
<th class="text-center px-5 py-3 text-sm font-medium text-gray-400">Created</th>
<th class="text-center px-5 py-3 text-sm font-medium text-gray-400">Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="kb in filteredKnowledgeBases()" :key="kb.id" class="table-row">
<td class="px-5 py-4">
<div class="font-medium">{{ kb.name }}</div>
<div class="text-sm text-gray-500">{{ kb.description }}</div>
</td>
<td class="px-5 py-4 text-center">
<span class="text-primary-cyan">{{ kb.document_count }}</span>
</td>
<td class="px-5 py-4 text-center text-gray-400 text-sm">
{{ kb.chunk_count }}
</td>
<td class="px-5 py-4 text-center">
<span v-if="kb.status === 'ready'" class="bg-primary-success/20 text-primary-success px-2 py-1 rounded text-sm">
Ready
</span>
<span v-else-if="kb.status === 'processing'" class="bg-primary-warning/20 text-primary-warning px-2 py-1 rounded text-sm">
Processing
</span>
</td>
<td class="px-5 py-4 text-center text-gray-400 text-sm">
{{ kb.created_at?.split('T')[0] }}
</td>
<td class="px-5 py-4">
<div class="flex items-center justify-center gap-2">
<button
@click="viewDetail(kb)"
class="p-2 rounded-lg hover:bg-dark-600 transition-colors"
title="View"
>
<i class="fa-solid fa-eye text-gray-400"></i>
</button>
<button
@click="openEdit(kb)"
class="p-2 rounded-lg hover:bg-dark-600 transition-colors"
title="Edit"
>
<i class="fa-solid fa-pen text-gray-400"></i>
</button>
<button
@click="deleteKb(kb.id)"
class="p-2 rounded-lg hover:bg-dark-600 transition-colors"
title="Delete"
>
<i class="fa-solid fa-trash text-gray-400 hover:text-primary-danger"></i>
</button>
</div>
</td>
</tr>
</tbody>
</table>
<!-- 空状态 -->
<div v-else class="empty-box">
<div class="empty-icon">
<i class="fa-solid fa-brain"></i>
</div>
<p class="empty-text">No knowledge bases found</p>
<p class="empty-tip">Click "New Knowledge Base" to create one</p>
</div>
</div>
<!-- 新建知识库弹窗 -->
<el-dialog
v-model="showCreateDialog"
title="Create Knowledge Base"
width="500px"
:close-on-click-modal="false"
class="kb-dialog"
>
<p class="dialog-desc">Create a new knowledge base to store your documents</p>
<el-form label-position="top" class="kb-form">
<el-form-item label="Name">
<el-input v-model="newKbForm.name" placeholder="Enter knowledge base name" />
</el-form-item>
<el-form-item label="Description">
<el-input v-model="newKbForm.description" type="textarea" :rows="3" placeholder="Enter description" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button text @click="cancelCreate">Cancel</el-button>
<el-button type="primary" @click="createKnowledgeBase">Confirm</el-button>
</div>
</template>
</el-dialog>
<!-- 编辑知识库弹窗 -->
<el-dialog
v-model="showEditDialog"
title="Edit Knowledge Base"
width="500px"
:close-on-click-modal="false"
class="kb-dialog"
>
<p class="dialog-desc">Edit knowledge base information</p>
<el-form label-position="top" class="kb-form">
<el-form-item label="Name">
<el-input v-model="editForm.name" placeholder="Enter knowledge base name" />
</el-form-item>
<el-form-item label="Description">
<el-input v-model="editForm.description" type="textarea" :rows="3" placeholder="Enter description" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button text @click="cancelEdit">Cancel</el-button>
<el-button type="primary" @click="saveEdit">Save</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<style scoped>
/* 按钮样式 */
.btn-primary {
background-color: #f97316;
border: none;
color: white;
padding: 10px 16px;
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
transition: all 0.2s;
}
.btn-primary:hover {
background-color: #ea580c;
}
/* 搜索框 */
.search-input {
background-color: #171922;
border: 1px solid #374151;
color: white;
padding: 10px 12px 10px 36px;
border-radius: 8px;
outline: none;
transition: border-color 0.2s;
}
.search-input:focus {
border-color: #f97316;
}
.search-input::placeholder {
color: #6b7280;
}
/* 表格样式 */
.bg-dark-700 {
background-color: #1f2937;
}
.bg-dark-600 {
background-color: #111827;
}
.table-row {
border-bottom: 1px solid #374151;
transition: background-color 0.2s;
}
.table-row:hover {
background-color: #374151;
}
/* 空状态 - 使用 database.css 中的样式 */
.empty-box {
min-height: 340px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.empty-icon {
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #1f2937, #111827);
border-radius: 24px;
margin-bottom: 20px;
}
.empty-icon i {
font-size: 40px;
color: #6b7280;
}
.empty-text {
color: #d1d5db;
font-size: 1.25rem;
font-weight: 500;
margin-bottom: 8px;
}
.empty-tip {
color: #6b7280;
font-size: 0.875rem;
}
/* 弹窗样式 */
.kb-dialog :deep(.el-dialog) {
background-color: #1f2937;
border-radius: 12px;
border: 1px solid #374151;
}
.kb-dialog :deep(.el-dialog__header) {
padding: 20px 24px;
border-bottom: 1px solid #374151;
}
.kb-dialog :deep(.el-dialog__title) {
color: white;
font-size: 18px;
font-weight: 600;
}
.kb-dialog :deep(.el-dialog__headerbtn) {
top: 20px;
right: 20px;
}
.kb-dialog :deep(.el-dialog__headerbtn .el-dialog__close) {
color: #9ca3af;
}
.kb-dialog :deep(.el-dialog__headerbtn:hover .el-dialog__close) {
color: #f97316;
}
.kb-dialog :deep(.el-dialog__body) {
padding: 24px;
}
.kb-dialog :deep(.el-dialog__footer) {
padding: 16px 24px;
border-top: 1px solid #374151;
}
.dialog-desc {
font-size: 14px;
color: #9ca3af;
margin-bottom: 20px;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 12px;
}
.kb-form :deep(.el-form-item__label) {
color: #d1d5db;
font-size: 14px;
}
.kb-form :deep(.el-input__wrapper) {
background-color: #171922;
border: 1px solid #374151;
box-shadow: none;
}
.kb-form :deep(.el-input__inner) {
color: white;
}
.kb-form :deep(.el-textarea__inner) {
background-color: #171922;
border: 1px solid #374151;
color: white;
box-shadow: none;
}
.kb-dialog :deep(.el-button--primary) {
background-color: #f97316;
border-color: #f97316;
}
.kb-dialog :deep(.el-button--primary:hover) {
background-color: #ea580c;
border-color: #ea580c;
}
</style>

1090
web/src/views/Settings.vue Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -43,3 +43,89 @@ export interface DbForm {
password: string
database: string
}
// Neo4j 图谱相关类型
export interface Neo4jLabel {
name: string
count: number
}
export interface Neo4jRelType {
name: string
count: number
}
export interface Neo4jGraphData {
labels: Neo4jLabel[]
relationshipTypes: Neo4jRelType[]
}
export interface Neo4jCheckResponse {
success: boolean
message: string
version?: string
databases?: string[]
databaseId?: string
name?: string
description?: string
graphs?: Neo4jGraphData
}
export interface Neo4jNodeProperty {
label: string
properties: {
name: string
type: string
}[]
}
export interface Neo4jRelProperty {
type: string
properties: {
name: string
type: string
}[]
}
export interface Neo4jNodeRequest {
uri?: string
host?: string
port?: number
username: string
password: string
database: string
label: string
limit?: number
}
export interface Neo4jNodesResponse {
success: boolean
message: string
nodes: any[]
properties: {
name: string
type: string
}[]
}
export interface Neo4jRelRequest {
uri?: string
host?: string
port?: number
username: string
password: string
database: string
relationshipType: string
limit?: number
}
export interface Neo4jRelationshipsResponse {
success: boolean
message: string
relationships: {
id: string
source: string
target: string
properties: any
}[]
}