Refactor OpenViking Memory API and User Management

- Updated API authentication headers to use `X-API-Key` for both admin and user APIs.
- Modified the account creation process to directly create user-specific accounts without requiring an admin workspace.
- Enhanced user creation to return account-specific details, including `admin_user_id`.
- Introduced new endpoints for retrieving task status and user profiles, allowing for more flexible user data management.
- Updated search functionality to include additional parameters such as `level` and `score_threshold`.
- Improved the handling of user keys in the storage layer to associate them with specific accounts.
- Added tests to validate the new user account creation process and search functionalities, ensuring proper integration with the OpenViking service.
- Included new documentation to reflect changes in API usage and expected request/response formats.
This commit is contained in:
2026-05-27 16:09:28 +08:00
parent a89807b174
commit 70cda923b2
13 changed files with 543 additions and 165 deletions

View File

@ -6,9 +6,11 @@ from fastapi import APIRouter, Depends, HTTPException, Query, status
from .auth import verify_api_key
from .schemas import (
MessageIngestRequest,
ProfileRequest,
SearchRequest,
SessionContextRequest,
SessionUserRequest,
TaskStatusRequest,
UserCreateRequest,
)
from .service import MemorySystemService
@ -123,6 +125,23 @@ async def get_openviking_task(
raise user_auth_error(exc) from exc
@router.post("/openviking/tasks/{task_id}")
async def get_openviking_task_from_body(
task_id: str,
request: TaskStatusRequest,
service: MemorySystemService = Depends(get_service),
):
try:
return await service.get_openviking_task(
request.user_id,
request.user_key,
task_id,
session_id=request.session_id,
)
except PermissionError as exc:
raise user_auth_error(exc) from exc
@router.post("/search")
async def search(
request: SearchRequest,
@ -134,14 +153,34 @@ async def search(
raise user_auth_error(exc) from exc
@router.post("/users/{user_id}/profile")
async def get_profile_from_body(
user_id: str,
request: ProfileRequest,
service: MemorySystemService = Depends(get_service),
):
try:
return await service.get_profile(
user_id,
request.user_key,
query=request.query,
limit=request.limit,
level=request.level,
)
except PermissionError as exc:
raise user_auth_error(exc) from exc
@router.get("/users/{user_id}/profile")
async def get_profile(
user_id: str,
user_key: str = Query(min_length=1),
query: str = Query(default="用户画像", min_length=1),
limit: int = Query(default=10, ge=1, le=100),
level: int = Query(default=2, ge=0),
service: MemorySystemService = Depends(get_service),
):
try:
service.openviking.credential_for_user(user_id, user_key)
return await service.get_profile(user_id, user_key, query=query, limit=limit, level=level)
except PermissionError as exc:
raise user_auth_error(exc) from exc
return await service.get_profile(user_id)