Skip to content

Commit 3bd417a

Browse files
author
gaozhe
committed
style: 架构整理
1 parent 22176c0 commit 3bd417a

File tree

98 files changed

+3908
-1977
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3908
-1977
lines changed

backend/alembic/versions/2026-02-19-21_21_46-e4c103e92f02_.py renamed to backend/alembic/versions/2026-02-20-16_20_28-e517b6c7fdb0_.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""empty message
22
3-
Revision ID: e4c103e92f02
3+
Revision ID: e517b6c7fdb0
44
Revises:
5-
Create Date: 2026-02-19 21:21:46.368852
5+
Create Date: 2026-02-20 16:20:28.792710
66
77
"""
88

@@ -12,7 +12,7 @@
1212
from sqlalchemy.dialects import mysql, postgresql
1313

1414
# revision identifiers, used by Alembic.
15-
revision = 'e4c103e92f02'
15+
revision = 'e517b6c7fdb0'
1616
down_revision = None
1717
branch_labels = None
1818
depends_on = None
@@ -32,6 +32,20 @@ def upgrade():
3232
comment='agent category',
3333
)
3434
op.create_index(op.f('ix_agent_category_id'), 'agent_category', ['id'], unique=True)
35+
op.create_table(
36+
'agent_chat',
37+
sa.Column('thread_id', sa.String(length=64), nullable=False),
38+
sa.Column('user_id', sa.String(length=64), nullable=False),
39+
sa.Column('first_query', sa.Text(), nullable=True),
40+
sa.Column('start_time', sa.DateTime(), nullable=False),
41+
sa.Column('end_time', sa.DateTime(), nullable=True),
42+
sa.Column('chat_title', sa.String(length=200), nullable=False),
43+
sa.Column('title_generated', sa.Boolean(), nullable=False),
44+
sa.Column('created_time', sa.DateTime(timezone=True), nullable=False, comment='创建时间'),
45+
sa.Column('updated_time', sa.DateTime(timezone=True), nullable=True, comment='更新时间'),
46+
sa.PrimaryKeyConstraint('thread_id'),
47+
)
48+
op.create_index(op.f('ix_agent_chat_user_id'), 'agent_chat', ['user_id'], unique=False)
3549
op.create_table(
3650
'agent_server',
3751
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False, comment='主键 ID'),
@@ -459,6 +473,8 @@ def downgrade():
459473
op.drop_index(op.f('ix_agent_server_id'), table_name='agent_server')
460474
op.drop_index(op.f('ix_agent_server_category_id'), table_name='agent_server')
461475
op.drop_table('agent_server')
476+
op.drop_index(op.f('ix_agent_chat_user_id'), table_name='agent_chat')
477+
op.drop_table('agent_chat')
462478
op.drop_index(op.f('ix_agent_category_id'), table_name='agent_category')
463479
op.drop_table('agent_category')
464480
# ### end Alembic commands ###

backend/app/admin/api/router.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
from app.admin.api.v1.agent import router as agent_router
12
from app.admin.api.v1.auth import router as auth_router
23
from app.admin.api.v1.log import router as log_router
34
from app.admin.api.v1.mcp import router as mcp_router
45
from app.admin.api.v1.oauth import router as oauth_router
6+
from app.admin.api.v1.skill import router as skill_router
57
from app.admin.api.v1.sys import router as sys_router
68
from core.conf import settings
79
from fastapi import APIRouter
810

911
v1 = APIRouter(prefix=settings.FASTAPI_API_V1_PATH + '/admin')
1012
v1.include_router(log_router)
1113
v1.include_router(mcp_router)
14+
v1.include_router(agent_router)
15+
v1.include_router(skill_router)
1216
v1.include_router(auth_router)
1317
v1.include_router(oauth_router)
1418
v1.include_router(sys_router)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from app.admin.api.v1.agent.category import router as agent_category_router
2+
from app.admin.api.v1.agent.server import router as agent_server_router
3+
from fastapi import APIRouter
4+
5+
router = APIRouter(prefix='/agent')
6+
7+
router.include_router(agent_server_router, prefix='/servers', tags=['admin agent server'])
8+
router.include_router(agent_category_router, prefix='/categories', tags=['admin agent category'])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from app.admin.schema.category import AddCategoryParam, CategoryDetail, GetAllCategoryParam
2+
from app.admin.service.admin_agent_category_service import agent_admin_category_service
3+
from common.pagination import DependsPagination, PageData, paging_data
4+
from common.response.response_schema import ResponseModel, ResponseSchemaModel, response_base
5+
from common.security.jwt import DependsJwtAuth
6+
from database.db import CurrentSession
7+
from fastapi import APIRouter, Request
8+
9+
router = APIRouter()
10+
11+
12+
@router.post(
13+
'/create',
14+
summary='创建 agent 分类',
15+
dependencies=[DependsJwtAuth],
16+
)
17+
async def add_agent_category(request: Request, obj: AddCategoryParam) -> ResponseModel:
18+
await agent_admin_category_service.create(request=request, obj=obj)
19+
return response_base.success()
20+
21+
22+
@router.post(
23+
'/get',
24+
summary='返回所有 agent 分类',
25+
dependencies=[DependsPagination, DependsJwtAuth],
26+
)
27+
async def get_all_agent_category(
28+
db: CurrentSession, obj: GetAllCategoryParam
29+
) -> ResponseSchemaModel[PageData[CategoryDetail]]:
30+
result = await agent_admin_category_service.get_list(obj.is_recommend)
31+
page_data = await paging_data(db, result)
32+
return response_base.success(data=page_data)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from typing import Annotated
2+
3+
from app.admin.schema.agent import AdminAgentBaseDetail, AdminSearchAgentParam, GetAdminAgentDetail, UpdateAgentParam
4+
from app.admin.service.admin_agent_service import agent_admin_server_service
5+
from common.pagination import DependsPagination, PageData, paging_data
6+
from common.response.response_schema import ResponseModel, ResponseSchemaModel, response_base
7+
from common.security.jwt import DependsJwtAuth
8+
from database.db import CurrentSession, CurrentSessionTransaction
9+
from fastapi import APIRouter, Path
10+
11+
router = APIRouter()
12+
13+
14+
@router.post(
15+
'',
16+
summary='返回所有 agent',
17+
dependencies=[DependsPagination, DependsJwtAuth],
18+
)
19+
async def get_all_agent(
20+
db: CurrentSession, obj: AdminSearchAgentParam
21+
) -> ResponseSchemaModel[PageData[AdminAgentBaseDetail]]:
22+
agent_select = await agent_admin_server_service.get_all_select(**obj.model_dump())
23+
page_data = await paging_data(db, agent_select)
24+
return response_base.success(data=page_data)
25+
26+
27+
@router.get(
28+
'/{agent_id}',
29+
summary='查询 agent 详情',
30+
dependencies=[DependsJwtAuth],
31+
)
32+
async def get_agent(
33+
agent_id: Annotated[int, Path(description='agent_id')],
34+
) -> ResponseSchemaModel[GetAdminAgentDetail | None]:
35+
result = await agent_admin_server_service.get_agent(agent_id)
36+
return response_base.success(data=result)
37+
38+
39+
@router.put(
40+
'/{agent_id}',
41+
summary='更新 agent',
42+
dependencies=[DependsJwtAuth],
43+
)
44+
async def put_agent(
45+
db: CurrentSessionTransaction,
46+
agent_id: Annotated[int, Path(description='agent_id')],
47+
obj: UpdateAgentParam,
48+
) -> ResponseModel:
49+
count = await agent_admin_server_service.update_agent(db=db, agent_id=agent_id, **obj.model_dump())
50+
if count > 0:
51+
return response_base.success()
52+
return response_base.fail()
53+
54+
55+
@router.delete(
56+
'/{agent_id}',
57+
summary='删除 agent',
58+
dependencies=[DependsJwtAuth],
59+
)
60+
async def delete_agent(
61+
db: CurrentSessionTransaction,
62+
agent_id: Annotated[int, Path(description='agent_id')],
63+
) -> ResponseModel:
64+
count = await agent_admin_server_service.delete_agent(db=db, agent_id=agent_id)
65+
if count > 0:
66+
return response_base.success()
67+
return response_base.fail()

backend/app/admin/api/v1/ops/__init__.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

backend/app/admin/api/v1/ops/edit.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

backend/app/admin/api/v1/ops/statistics.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

backend/app/admin/api/v1/ops/user.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from app.admin.api.v1.skill.category import router as skill_category_router
2+
from app.admin.api.v1.skill.server import router as skill_server_router
3+
from fastapi import APIRouter
4+
5+
router = APIRouter(prefix='/skill')
6+
7+
router.include_router(skill_server_router, prefix='/servers', tags=['admin skill server'])
8+
router.include_router(skill_category_router, prefix='/categories', tags=['admin skill category'])

0 commit comments

Comments
 (0)