Compare commits

..

No commits in common. "668452c3eefc5ea22fb1d90ffb7be8ec9d188b25" and "a4c9433aac76f94deb0ee7196ab70a4059131073" have entirely different histories.

3 changed files with 83 additions and 49 deletions

View File

@ -1,7 +1,7 @@
version: "3.8" version: "3.8"
services: services:
postgres-agent: postgres:
image: pgvector/pgvector:pg16 image: pgvector/pgvector:pg16
container_name: qwen-agent-postgres container_name: qwen-agent-postgres
environment: environment:
@ -29,19 +29,20 @@ services:
- "8001:8001" - "8001:8001"
environment: environment:
# 应用配置 # 应用配置
- BACKEND_HOST=http://api-dev.gbase.ai
- MAX_CONTEXT_TOKENS=262144 - MAX_CONTEXT_TOKENS=262144
- DEFAULT_THINKING_ENABLE=true - DEFAULT_THINKING_ENABLE=true
- PROFILE=low_memory - PROFILE=low_memory
- RAGFLOW_API_URL=http://ragflow-cpu - RAGFLOW_API_URL=http://172.26.31.232:1080
- RAGFLOW_API_KEY=ragflow-0vldzYY_SfQLnjBIGOBDDgvdgWemdK4gmH1L7kgenQ0 - RAGFLOW_API_KEY=ragflow-0vldzYY_SfQLnjBIGOBDDgvdgWemdK4gmH1L7kgenQ0
# PostgreSQL 配置 # PostgreSQL 配置
- CHECKPOINT_DB_URL=postgresql://postgres:E5ACJo6zJub4QS@postgres-agent:5432/agent_db - CHECKPOINT_DB_URL=postgresql://postgres:E5ACJo6zJub4QS@postgres:5432/agent_db
volumes: volumes:
# 挂载项目数据目录 # 挂载项目数据目录
- ./projects:/app/projects - ./projects:/app/projects
- ./models:/app/models - ./models:/app/models
depends_on: depends_on:
postgres-agent: postgres:
condition: service_healthy condition: service_healthy
restart: unless-stopped restart: unless-stopped
healthcheck: healthcheck:
@ -50,12 +51,5 @@ services:
timeout: 10s timeout: 10s
retries: 3 retries: 3
start_period: 40s start_period: 40s
networks:
- default
- ragflow
volumes: volumes:
postgres_data: postgres_data:
networks:
ragflow:
name: docker_ragflow
external: true

View File

@ -1314,47 +1314,87 @@ async def get_bots(authorization: Optional[str] = Header(None)):
detail="Unauthorized" detail="Unauthorized"
) )
# 检查是否是管理员
pool = get_db_pool_manager().pool pool = get_db_pool_manager().pool
async with pool.connection() as conn:
async with conn.cursor() as cursor:
await cursor.execute("""
SELECT is_admin FROM agent_user WHERE id = %s
""", (user_id,))
row = await cursor.fetchone()
is_admin = row and row[0]
async with pool.connection() as conn: async with pool.connection() as conn:
async with conn.cursor() as cursor: async with conn.cursor() as cursor:
# 所有用户(包括 admin只能看到拥有的 Bot 和分享给自己的 Bot且未过期 if is_admin:
await cursor.execute(""" # 管理员可以看到所有 Bot
SELECT DISTINCT b.id, b.name, b.bot_id, b.created_at, b.updated_at, b.settings, await cursor.execute("""
u.id as owner_id, u.username as owner_username, SELECT b.id, b.name, b.bot_id, b.created_at, b.updated_at, b.settings,
s.role, s.shared_at, s.expires_at, u.id as owner_id, u.username as owner_username,
b.is_published, b.copied_from b.is_published, b.copied_from
FROM agent_bots b FROM agent_bots b
LEFT JOIN agent_user u ON b.owner_id = u.id LEFT JOIN agent_user u ON b.owner_id = u.id
LEFT JOIN bot_shares s ON b.id = s.bot_id AND s.user_id = %s ORDER BY b.created_at DESC
WHERE b.owner_id = %s """)
OR (s.user_id IS NOT NULL rows = await cursor.fetchall()
AND s.user_id = %s
AND (s.expires_at IS NULL OR s.expires_at > NOW()))
ORDER BY b.created_at DESC
""", (user_id, user_id, user_id))
rows = await cursor.fetchall()
return [ return [
BotResponse( BotResponse(
id=str(row[0]), id=str(row[0]), # 使用 UUID 主键
name=row[1], name=row[1],
bot_id=str(row[0]), bot_id=str(row[0]), # bot_id 也指向主键 id
is_owner=(row[6] is not None and str(row[6]) == user_id), is_owner=True,
is_shared=(row[6] is not None and str(row[6]) != user_id and row[8] is not None), is_shared=False,
is_published=row[11] if row[11] else False, is_published=row[8] if row[8] else False,
copied_from=str(row[12]) if row[12] else None, copied_from=str(row[9]) if row[9] else None,
owner={"id": str(row[6]), "username": row[7]} if row[6] is not None else None, owner={"id": str(row[6]), "username": row[7]} if row[6] else None,
role=row[8] if row[8] is not None else None, role=None,
shared_at=datetime_to_str(row[9]) if row[9] is not None else None, description=row[5].get('description') if row[5] else None,
expires_at=row[10].isoformat() if row[10] is not None else None, avatar_url=row[5].get('avatar_url') if row[5] else None,
description=row[5].get('description') if row[5] else None, created_at=datetime_to_str(row[3]),
avatar_url=row[5].get('avatar_url') if row[5] else None, updated_at=datetime_to_str(row[4])
created_at=datetime_to_str(row[3]), )
updated_at=datetime_to_str(row[4]) for row in rows
) ]
for row in rows else:
] # 用户只能看到拥有的 Bot 和分享给自己的 Bot且未过期
# 使用子查询确保正确过滤,避免 LEFT JOIN 导致的 NULL 值比较问题
await cursor.execute("""
SELECT DISTINCT b.id, b.name, b.bot_id, b.created_at, b.updated_at, b.settings,
u.id as owner_id, u.username as owner_username,
s.role, s.shared_at, s.expires_at,
b.is_published, b.copied_from
FROM agent_bots b
LEFT JOIN agent_user u ON b.owner_id = u.id
LEFT JOIN bot_shares s ON b.id = s.bot_id AND s.user_id = %s
WHERE b.owner_id = %s
OR (s.user_id IS NOT NULL
AND s.user_id = %s
AND (s.expires_at IS NULL OR s.expires_at > NOW()))
ORDER BY b.created_at DESC
""", (user_id, user_id, user_id))
rows = await cursor.fetchall()
return [
BotResponse(
id=str(row[0]), # 使用 UUID 主键
name=row[1],
bot_id=str(row[0]), # bot_id 也指向主键 id
is_owner=(row[6] is not None and str(row[6]) == user_id),
is_shared=(row[6] is not None and str(row[6]) != user_id and row[8] is not None),
is_published=row[11] if row[11] else False,
copied_from=str(row[12]) if row[12] else None,
owner={"id": str(row[6]), "username": row[7]} if row[6] is not None else None,
role=row[8] if row[8] is not None else None,
shared_at=datetime_to_str(row[9]) if row[9] is not None else None,
expires_at=row[10].isoformat() if row[10] is not None else None,
description=row[5].get('description') if row[5] else None,
avatar_url=row[5].get('avatar_url') if row[5] else None,
created_at=datetime_to_str(row[3]),
updated_at=datetime_to_str(row[4])
)
for row in rows
]
@router.post("/api/v1/bots", response_model=BotResponse) @router.post("/api/v1/bots", response_model=BotResponse)

View File

@ -12,9 +12,9 @@
"mcpServers": { "mcpServers": {
"rag_retrieve": { "rag_retrieve": {
"transport": "http", "transport": "http",
"url": "http://ragflow-cpu:9382/mcp/", "url": "http://host.docker.internal:9382/mcp/",
"headers": { "headers": {
"api_key": "ragflow-0vldzYY_SfQLnjBIGOBDDgvdgWemdK4gmH1L7kgenQ0", "api_key": "ragflow-MRqxnDnYZ1yp5kklDMIlKH4f1qezvXIngSMGPhu1AG8",
"X-Dataset-Ids": "{dataset_ids}" "X-Dataset-Ids": "{dataset_ids}"
} }
} }