|
21 | 21 | AppRotateResponse, |
22 | 22 | ErrorResponse, |
23 | 23 | DocumentUploadItem, |
| 24 | + AppUpdateRequest, |
| 25 | + AppUpdateResponse |
24 | 26 | ) |
25 | 27 | from mcp_clients.kb_mcp_endpoint_service import KnowledgeBaseMCPEndpointService |
26 | 28 |
|
@@ -239,3 +241,56 @@ async def get_documents( |
239 | 241 | kb_id=current_app.knowledge_base_id, |
240 | 242 | ) |
241 | 243 | return res |
| 244 | + |
| 245 | + |
| 246 | +@router.patch( |
| 247 | + "", |
| 248 | + response_model=AppUpdateResponse, |
| 249 | + responses={ |
| 250 | + 400: {"model": ErrorResponse, "description": "Validation error"}, |
| 251 | + 401: {"model": ErrorResponse, "description": "Unauthorized - Invalid or missing token"}, |
| 252 | + 403: {"model": ErrorResponse, "description": "Forbidden - Inactive app"}, |
| 253 | + 404: {"model": ErrorResponse, "description": "App not found"}, |
| 254 | + }, |
| 255 | +) |
| 256 | +def update_app( |
| 257 | + *, |
| 258 | + db: Session = Depends(get_db), |
| 259 | + current_app: App = Depends(get_current_app), |
| 260 | + update_data: AppUpdateRequest, |
| 261 | +) -> Any: |
| 262 | + """ |
| 263 | + Partially update app metadata. |
| 264 | +
|
| 265 | + Only provided fields will be updated. Access token and client_id |
| 266 | + will remain unchanged. |
| 267 | +
|
| 268 | + Requires Bearer token authentication. |
| 269 | + """ |
| 270 | + if not AppService.is_app_active(current_app): |
| 271 | + raise HTTPException( |
| 272 | + status_code=status.HTTP_403_FORBIDDEN, |
| 273 | + detail="App is not active", |
| 274 | + ) |
| 275 | + |
| 276 | + try: |
| 277 | + updated_app = AppService.update_app( |
| 278 | + db=db, |
| 279 | + app=current_app, |
| 280 | + update_data=update_data, |
| 281 | + ) |
| 282 | + |
| 283 | + return AppUpdateResponse( |
| 284 | + app_id=updated_app.app_id, |
| 285 | + app_name=updated_app.app_name, |
| 286 | + domain=updated_app.domain, |
| 287 | + default_chat_prompt=updated_app.default_chat_prompt, |
| 288 | + chat_callback=updated_app.chat_callback_url, |
| 289 | + upload_callback=updated_app.upload_callback_url, |
| 290 | + callback_token=updated_app.callback_token, |
| 291 | + updated_at=updated_app.updated_at, |
| 292 | + ) |
| 293 | + except ValueError as e: |
| 294 | + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e)) |
| 295 | + except Exception as e: |
| 296 | + raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to update app: {str(e)}") |
0 commit comments