feat(memory-gateway): 引入 Memory Gateway 配置、凭据存储和服务编排
* 新增 MemoryGatewayConfig 和 MemoryConfig dataclass,用于配置管理。 * 实现 MemoryGatewayUserCredential 和 MemoryGatewayCredentialStore,用于处理用户凭据。 * 创建 MemoryGatewayService,用于管理与 Memory Gateway 的交互。 * 开发用于记忆设置的 JSON 配置文件。 * 增强单元测试,覆盖新功能,包括凭据存储和服务行为。 * 更新 entrypoint 和实例创建脚本,以初始化 Memory Gateway 用户存储。
This commit is contained in:
@ -88,6 +88,7 @@ def test_websocket_message_returns_chat_metadata_and_session_updated() -> None:
|
||||
"session_id": "web:alpha",
|
||||
"source": "websocket",
|
||||
"user_id": None,
|
||||
"gateway_user_id": None,
|
||||
"title": None,
|
||||
"execution_context": None,
|
||||
"prompt_locale": "zh-Hant",
|
||||
@ -134,6 +135,7 @@ def test_websocket_message_uses_direct_processing_when_loop_is_not_running() ->
|
||||
"session_id": "web:alpha",
|
||||
"source": "websocket",
|
||||
"user_id": None,
|
||||
"gateway_user_id": None,
|
||||
"title": None,
|
||||
"execution_context": None,
|
||||
"prompt_locale": None,
|
||||
@ -164,6 +166,7 @@ def test_rest_chat_uses_direct_processing_when_loop_is_not_running() -> None:
|
||||
"session_id": "web:alpha",
|
||||
"source": "web",
|
||||
"user_id": None,
|
||||
"gateway_user_id": None,
|
||||
"title": None,
|
||||
"execution_context": None,
|
||||
"prompt_locale": "en",
|
||||
@ -181,6 +184,72 @@ def test_rest_chat_uses_direct_processing_when_loop_is_not_running() -> None:
|
||||
assert response.json()["output_text"] == "echo:hello"
|
||||
|
||||
|
||||
def test_rest_chat_uses_authenticated_user_for_gateway_identity() -> None:
|
||||
service = DirectModeOnlyAgentService()
|
||||
app = create_app(service=service, manage_service_lifecycle=False)
|
||||
app.state.auth_tokens["token-1"] = "tom"
|
||||
|
||||
with TestClient(app) as client:
|
||||
response = client.post(
|
||||
"/api/chat",
|
||||
headers={"Authorization": "Bearer token-1"},
|
||||
json={"session_id": "web:alpha", "message": "hello", "user_id": "other"},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert service.calls == [
|
||||
{
|
||||
"message": "hello",
|
||||
"session_id": "web:alpha",
|
||||
"source": "web",
|
||||
"user_id": "other",
|
||||
"gateway_user_id": "tom",
|
||||
"title": None,
|
||||
"execution_context": None,
|
||||
"prompt_locale": None,
|
||||
"model": None,
|
||||
"provider_name": None,
|
||||
"embedding_model": None,
|
||||
"temperature": None,
|
||||
"max_tokens": None,
|
||||
"max_tool_iterations": None,
|
||||
"fallback_target": None,
|
||||
"auxiliary_target": None,
|
||||
"embedding_target": None,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_websocket_uses_authenticated_user_for_gateway_identity() -> None:
|
||||
service = StubAgentService()
|
||||
app = create_app(service=service, manage_service_lifecycle=False)
|
||||
app.state.auth_tokens["token-1"] = "tom"
|
||||
|
||||
with TestClient(app) as client:
|
||||
with client.websocket_connect("/ws/web:alpha?token=token-1") as websocket:
|
||||
websocket.send_json({"type": "message", "content": "hello", "user_id": "other"})
|
||||
assert websocket.receive_json() == {"type": "status", "status": "thinking"}
|
||||
websocket.receive_json()
|
||||
websocket.receive_json()
|
||||
|
||||
assert service.calls == [
|
||||
{
|
||||
"message": "hello",
|
||||
"session_id": "web:alpha",
|
||||
"source": "websocket",
|
||||
"user_id": "other",
|
||||
"gateway_user_id": "tom",
|
||||
"title": None,
|
||||
"execution_context": None,
|
||||
"prompt_locale": None,
|
||||
"model": None,
|
||||
"provider_name": None,
|
||||
"embedding_model": None,
|
||||
"max_tool_iterations": None,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_websocket_empty_content_returns_error_without_runtime_call() -> None:
|
||||
service = StubAgentService()
|
||||
app = create_app(service=service, manage_service_lifecycle=False)
|
||||
|
||||
Reference in New Issue
Block a user