已合并
fix: fix codecheck #82
张雅晴创建于 4月11日
fix: fix codecheck #82
已合并
共 13 个文件变更+246-230
| @@ -1 +1 @@ | |||
| 1 | -Subproject commit 6dd2c1df8a46a39f55bb32b1f22bca036c55c301 | 1 | +Subproject commit fe293f7256627a7541f924b1b9a316e57f927d2c |
| @@ -29,20 +29,19 @@ userdata JSON 格式: | |||
| 29 | } | 29 | } |
| 30 | """ | 30 | """ |
| 31 | 31 | ||
| 32 | -import json | 32 | +import asyncio |
| 33 | import copy | 33 | import copy |
| 34 | +import json | ||
| 34 | import logging | 35 | import logging |
| 35 | import os | 36 | import os |
| 36 | import sys | 37 | import sys |
| 37 | -import uuid | ||
| 38 | -import asyncio | ||
| 39 | -from datetime import datetime | ||
| 40 | from typing import AsyncIterator, Tuple | 38 | from typing import AsyncIterator, Tuple |
| 41 | 39 | ||
| 42 | # 设置 DB_TYPE=none,避免数据库配置检查 | 40 | # 设置 DB_TYPE=none,避免数据库配置检查 |
| 43 | # 注意:使用直接赋值而不是 setdefault,确保覆盖从 runtime 服务继承的 DB_TYPE | 41 | # 注意:使用直接赋值而不是 setdefault,确保覆盖从 runtime 服务继承的 DB_TYPE |
| 44 | os.environ["DB_TYPE"] = "none" | 42 | os.environ["DB_TYPE"] = "none" |
| 45 | 43 | ||
| 44 | + | ||
| 46 | def _parse_userdata_env_vars(): | 45 | def _parse_userdata_env_vars(): |
| 47 | """ | 46 | """ |
| 48 | 从 RUNTIME_USERDATA 环境变量解析并设置环境变量 | 47 | 从 RUNTIME_USERDATA 环境变量解析并设置环境变量 |
| @@ -83,20 +82,14 @@ _CODE_SANDBOX_URL = os.getenv("CODE_SANDBOX_URL", "") | |||
| 83 | if not _CODE_SANDBOX_URL: | 82 | if not _CODE_SANDBOX_URL: |
| 84 | _CODE_SANDBOX_URL = "http://localhost:8188/run" | 83 | _CODE_SANDBOX_URL = "http://localhost:8188/run" |
| 85 | 84 | ||
| 86 | -from openjiuwen_studio.core.executor.component.code_runner.remote import remote_code_runner | ||
| 87 | -remote_code_runner.code_sandbox_url = _CODE_SANDBOX_URL | ||
| 88 | - | ||
| 89 | -from openjiuwen_runtime.service.app.agent_app import AgentApp | ||
| 90 | -from openjiuwen.core.runner import Runner | ||
| 91 | from openjiuwen.core.application.llm_agent import LLMAgent, ReActAgentConfig as LegacyReActAgentConfig | 85 | from openjiuwen.core.application.llm_agent import LLMAgent, ReActAgentConfig as LegacyReActAgentConfig |
| 92 | from openjiuwen.core.application.workflow_agent import WorkflowAgent | 86 | from openjiuwen.core.application.workflow_agent import WorkflowAgent |
| 87 | +from openjiuwen.core.runner import Runner | ||
| 93 | from openjiuwen.core.single_agent.legacy import WorkflowAgentConfig as LegacyWorkflowAgentConfig | 88 | from openjiuwen.core.single_agent.legacy import WorkflowAgentConfig as LegacyWorkflowAgentConfig |
| 94 | -from openjiuwen_studio.lowcode import AgentCompiler | 89 | + |
| 95 | -from openjiuwen_studio.lowcode.config_adapter import ConfigAdapter | ||
| 96 | -from openjiuwen_studio.lowcode.runtime_workflow_runner import RuntimeWorkflowRunner | ||
| 97 | from openjiuwen_runtime.examples.lowcode_agent.agui_converter import ( | 90 | from openjiuwen_runtime.examples.lowcode_agent.agui_converter import ( |
| 98 | - agui_assistant_text_as_answer_events, | ||
| 99 | agui_append_text_and_finish_events, | 91 | agui_append_text_and_finish_events, |
| 92 | + agui_assistant_text_as_answer_events, | ||
| 100 | agui_error_events, | 93 | agui_error_events, |
| 101 | agui_trace_context, | 94 | agui_trace_context, |
| 102 | convert_chunk_to_agui_events, | 95 | convert_chunk_to_agui_events, |
| @@ -107,6 +100,15 @@ from openjiuwen_runtime.examples.lowcode_agent.agui_converter import ( | |||
| 107 | from openjiuwen_runtime.examples.lowcode_agent.workflow_registration import ( | 100 | from openjiuwen_runtime.examples.lowcode_agent.workflow_registration import ( |
| 108 | normalize_workflow_providers_for_agent, | 101 | normalize_workflow_providers_for_agent, |
| 109 | ) | 102 | ) |
| 103 | +from openjiuwen_runtime.service.app.agent_app import AgentApp | ||
| 104 | + | ||
| 105 | +from openjiuwen_studio.core.executor.component.code_runner.remote import remote_code_runner | ||
| 106 | + | ||
| 107 | +remote_code_runner.code_sandbox_url = _CODE_SANDBOX_URL | ||
| 108 | + | ||
| 109 | +from openjiuwen_studio.lowcode import AgentCompiler | ||
| 110 | +from openjiuwen_studio.lowcode.config_adapter import ConfigAdapter | ||
| 111 | +from openjiuwen_studio.lowcode.runtime_workflow_runner import RuntimeWorkflowRunner | ||
| 110 | 112 | ||
| 111 | _STRICT_LOGGER_HANDLER_NAMES = ( | 113 | _STRICT_LOGGER_HANDLER_NAMES = ( |
| 112 | "common", | 114 | "common", |
| @@ -169,6 +171,7 @@ def _get_venv_path() -> str: | |||
| 169 | # 回退到可执行文件的父目录 | 171 | # 回退到可执行文件的父目录 |
| 170 | return os.path.dirname(os.path.dirname(sys.executable)) | 172 | return os.path.dirname(os.path.dirname(sys.executable)) |
| 171 | 173 | ||
| 174 | + | ||
| 172 | def _setup_logging(): | 175 | def _setup_logging(): |
| 173 | """配置日志系统""" | 176 | """配置日志系统""" |
| 174 | venv_path = _get_venv_path() | 177 | venv_path = _get_venv_path() |
| @@ -71,7 +71,6 @@ class Settings(BaseSettings): | |||
| 71 | raise ValueError(f"When DB_TYPE=mysql, the following fields are required: {', '.join(missing)}") | 71 | raise ValueError(f"When DB_TYPE=mysql, the following fields are required: {', '.join(missing)}") |
| 72 | return self | 72 | return self |
| 73 | 73 | ||
| 74 | - | ||
| 75 | # ======================== | 74 | # ======================== |
| 76 | # 路径校验:相对目录 → 项目根目录绝对路径 + 自动创建 | 75 | # 路径校验:相对目录 → 项目根目录绝对路径 + 自动创建 |
| 77 | # ======================== | 76 | # ======================== |
| @@ -5,6 +5,7 @@ import os | |||
| 5 | from .sqlalchemy_handler import SQLAlchemyHandler | 5 | from .sqlalchemy_handler import SQLAlchemyHandler |
| 6 | from ..config import settings | 6 | from ..config import settings |
| 7 | 7 | ||
| 8 | + | ||
| 8 | class MySQLHandler(SQLAlchemyHandler): | 9 | class MySQLHandler(SQLAlchemyHandler): |
| 9 | """MySQL数据库句柄""" | 10 | """MySQL数据库句柄""" |
| 10 | 11 | ||
| @@ -32,7 +32,7 @@ class VirtualEnvironmentManager: | |||
| 32 | Returns: | 32 | Returns: |
| 33 | 虚拟环境根目录路径 | 33 | 虚拟环境根目录路径 |
| 34 | """ | 34 | """ |
| 35 | - return settings.deploy_path/deployment_id/".venv" | 35 | + return settings.deploy_path / deployment_id / ".venv" |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | def create_venv(self, deployment_id: str) -> Path: | 38 | def create_venv(self, deployment_id: str) -> Path: |
| @@ -155,7 +155,7 @@ class VirtualEnvironmentManager: | |||
| 155 | 155 | ||
| 156 | logger.info(f"Installing WHL package: {whl_path} into {deployment_id}") | 156 | logger.info(f"Installing WHL package: {whl_path} into {deployment_id}") |
| 157 | 157 | ||
| 158 | - uv_extra_args_list = shlex.split(settings.UV_EXTRA_ARGS.strip()) | 158 | + uv_extra_args_list = shlex.split(settings.UV_EXTRA_ARGS.strip()) |
| 159 | 159 | ||
| 160 | # 使用 uv pip 安装包,通过虚拟环境路径指定目标环境 | 160 | # 使用 uv pip 安装包,通过虚拟环境路径指定目标环境 |
| 161 | cmd = [ | 161 | cmd = [ |
| @@ -229,7 +229,7 @@ class DockerDeployer(Deployer[DockerParams]): | |||
| 229 | del self._containers[deployment_id] | 229 | del self._containers[deployment_id] |
| 230 | 230 | ||
| 231 | # 清理部署目录 | 231 | # 清理部署目录 |
| 232 | - deploy_context_dir = settings.deploy_path/deployment_id | 232 | + deploy_context_dir = settings.deploy_path / deployment_id |
| 233 | logger.debug(f"Cleaning deploy directory: {deploy_context_dir}") | 233 | logger.debug(f"Cleaning deploy directory: {deploy_context_dir}") |
| 234 | shutil.rmtree(deploy_context_dir, ignore_errors=True) | 234 | shutil.rmtree(deploy_context_dir, ignore_errors=True) |
| 235 | 235 | ||
| @@ -16,6 +16,7 @@ from openjiuwen_runtime.foundation.log.utils import mask_userdata | |||
| 16 | import logging | 16 | import logging |
| 17 | logger = logging.getLogger(__name__) | 17 | logger = logging.getLogger(__name__) |
| 18 | 18 | ||
| 19 | + | ||
| 19 | class DockerStrategy(BaseDeploymentStrategy[DockerInfo]): | 20 | class DockerStrategy(BaseDeploymentStrategy[DockerInfo]): |
| 20 | """Docker 部署策略""" | 21 | """Docker 部署策略""" |
| 21 | 22 | ||
| @@ -5,8 +5,8 @@ | |||
| 5 | openjiuwen-runtime-sdk 的请求和响应模型 | 5 | openjiuwen-runtime-sdk 的请求和响应模型 |
| 6 | """ | 6 | """ |
| 7 | 7 | ||
| 8 | -from pydantic import BaseModel, Field | ||
| 9 | from typing import List, Dict, Any, Optional | 8 | from typing import List, Dict, Any, Optional |
| 9 | +from pydantic import BaseModel, Field | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | class QueryRequest(BaseModel): | 12 | class QueryRequest(BaseModel): |
| @@ -124,8 +124,8 @@ class TestMiddlewareRegistration(unittest.TestCase): | |||
| 124 | 124 | ||
| 125 | result = app.add_middleware(middleware) | 125 | result = app.add_middleware(middleware) |
| 126 | 126 | ||
| 127 | - self.assertEqual(len(app._middlewares), 1) | 127 | + self.assertEqual(len(app.middlewares), 1) |
| 128 | - self.assertIs(app._middlewares[0], middleware) | 128 | + self.assertIs(app.middlewares[0], middleware) |
| 129 | self.assertIs(result, app) | 129 | self.assertIs(result, app) |
| 130 | 130 | ||
| 131 | def test_middleware_decorator(self): | 131 | def test_middleware_decorator(self): |
| @@ -138,9 +138,9 @@ class TestMiddlewareRegistration(unittest.TestCase): | |||
| 138 | 138 | ||
| 139 | instance = app.middleware(CustomMiddleware) | 139 | instance = app.middleware(CustomMiddleware) |
| 140 | 140 | ||
| 141 | - self.assertEqual(len(app._middlewares), 1) | 141 | + self.assertEqual(len(app.middlewares), 1) |
| 142 | - self.assertIsInstance(app._middlewares[0], CustomMiddleware) | 142 | + self.assertIsInstance(app.middlewares[0], CustomMiddleware) |
| 143 | - self.assertIs(app._middlewares[0], instance) | 143 | + self.assertIs(app.middlewares[0], instance) |
| 144 | 144 | ||
| 145 | def test_chained_calls(self): | 145 | def test_chained_calls(self): |
| 146 | """测试链式调用添加多个中间件""" | 146 | """测试链式调用添加多个中间件""" |
| @@ -150,9 +150,9 @@ class TestMiddlewareRegistration(unittest.TestCase): | |||
| 150 | 150 | ||
| 151 | result = app.add_middleware(mw1).add_middleware(mw2) | 151 | result = app.add_middleware(mw1).add_middleware(mw2) |
| 152 | 152 | ||
| 153 | - self.assertEqual(len(app._middlewares), 2) | 153 | + self.assertEqual(len(app.middlewares), 2) |
| 154 | - self.assertIs(app._middlewares[0], mw1) | 154 | + self.assertIs(app.middlewares[0], mw1) |
| 155 | - self.assertIs(app._middlewares[1], mw2) | 155 | + self.assertIs(app.middlewares[1], mw2) |
| 156 | self.assertIs(result, app) | 156 | self.assertIs(result, app) |
| 157 | 157 | ||
| 158 | 158 | ||
| @@ -174,13 +174,13 @@ class TestMiddlewareExecution(unittest.TestCase): | |||
| 174 | context = MiddlewareContext() | 174 | context = MiddlewareContext() |
| 175 | messages = [{"role": "user", "content": "test"}] | 175 | messages = [{"role": "user", "content": "test"}] |
| 176 | 176 | ||
| 177 | - for mw in app._middlewares: | 177 | + for mw in app.middlewares: |
| 178 | messages = await mw.before_query(messages, None, context) | 178 | messages = await mw.before_query(messages, None, context) |
| 179 | 179 | ||
| 180 | - for mw in app._middlewares: | 180 | + for mw in app.middlewares: |
| 181 | await mw.after_query(messages, None, context) | 181 | await mw.after_query(messages, None, context) |
| 182 | 182 | ||
| 183 | - for mw in app._middlewares: | 183 | + for mw in app.middlewares: |
| 184 | await mw.before_response(messages, None, "response", context) | 184 | await mw.before_response(messages, None, "response", context) |
| 185 | 185 | ||
| 186 | asyncio.run(run_test()) | 186 | asyncio.run(run_test()) |
| @@ -279,7 +279,7 @@ class TestContextDataSharing(unittest.TestCase): | |||
| 279 | context = MiddlewareContext() | 279 | context = MiddlewareContext() |
| 280 | messages = [{"role": "user", "content": "test"}] | 280 | messages = [{"role": "user", "content": "test"}] |
| 281 | 281 | ||
| 282 | - for mw in app._middlewares: | 282 | + for mw in app.middlewares: |
| 283 | messages = await mw.before_query(messages, None, context) | 283 | messages = await mw.before_query(messages, None, context) |
| 284 | 284 | ||
| 285 | retrieved_values["mw2"] = mw2.retrieved_value | 285 | retrieved_values["mw2"] = mw2.retrieved_value |