This commit is contained in:
@@ -20,22 +20,18 @@ class ContactAPIClient:
|
||||
|
||||
def __init__(self, conn=None):
|
||||
"""
|
||||
初始化
|
||||
|
||||
初始化(使用延迟初始化,MCP在首次使用时初始化)
|
||||
|
||||
Args:
|
||||
conn: 数据库连接(保留用于向后兼容)
|
||||
"""
|
||||
self.conn = conn
|
||||
|
||||
# 确保MCP已初始化
|
||||
import asyncio
|
||||
try:
|
||||
asyncio.create_task(self._init_mcp())
|
||||
except RuntimeError:
|
||||
pass # 没有事件循环时跳过,延迟初始化
|
||||
self._mcp_initialized = False # 延迟初始化标志
|
||||
|
||||
async def _init_mcp(self):
|
||||
"""初始化MCP系统"""
|
||||
"""初始化MCP系统(延迟初始化)"""
|
||||
if self._mcp_initialized:
|
||||
return # 已初始化,跳过
|
||||
if not mcp_manager.get_adapter("contact"):
|
||||
# 获取repository(如果有)
|
||||
repo = None
|
||||
@@ -45,9 +41,10 @@ class ContactAPIClient:
|
||||
repo = ContactRepository(self.conn)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
mcp_manager.register_adapter(ContactAdapter(contact_repo=repo))
|
||||
await mcp_manager.initialize()
|
||||
self._mcp_initialized = True
|
||||
|
||||
async def list_contacts(self, user_id: str = "default") -> List[Contact]:
|
||||
"""获取联系人列表"""
|
||||
|
||||
@@ -8,7 +8,7 @@ from typing import Dict, Any
|
||||
from datetime import datetime
|
||||
|
||||
# 公共工具
|
||||
from app.core import MarkdownFormatter
|
||||
from ...core import MarkdownFormatter
|
||||
|
||||
from .state import ContactState
|
||||
from .api_client import ContactAPIClient
|
||||
|
||||
Reference in New Issue
Block a user