agentscope-runtime 0.2.0b2__py3-none-any.whl → 1.0.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentscope_runtime/adapters/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/__init__.py +0 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/long_term_memory/_long_term_memory_adapter.py +258 -0
- agentscope_runtime/adapters/agentscope/memory/__init__.py +6 -0
- agentscope_runtime/adapters/agentscope/memory/_memory_adapter.py +152 -0
- agentscope_runtime/adapters/agentscope/message.py +535 -0
- agentscope_runtime/adapters/agentscope/stream.py +474 -0
- agentscope_runtime/adapters/agentscope/tool/__init__.py +9 -0
- agentscope_runtime/adapters/agentscope/tool/sandbox_tool.py +69 -0
- agentscope_runtime/adapters/agentscope/tool/tool.py +233 -0
- agentscope_runtime/adapters/autogen/__init__.py +0 -0
- agentscope_runtime/adapters/autogen/tool/__init__.py +7 -0
- agentscope_runtime/adapters/autogen/tool/tool.py +211 -0
- agentscope_runtime/adapters/text/__init__.py +0 -0
- agentscope_runtime/adapters/text/stream.py +29 -0
- agentscope_runtime/common/collections/redis_mapping.py +4 -1
- agentscope_runtime/common/container_clients/fc_client.py +855 -0
- agentscope_runtime/common/utils/__init__.py +0 -0
- agentscope_runtime/common/utils/lazy_loader.py +57 -0
- agentscope_runtime/engine/__init__.py +25 -18
- agentscope_runtime/engine/app/agent_app.py +161 -91
- agentscope_runtime/engine/app/base_app.py +4 -118
- agentscope_runtime/engine/constant.py +8 -0
- agentscope_runtime/engine/deployers/__init__.py +8 -0
- agentscope_runtime/engine/deployers/adapter/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_adapter_utils.py +0 -21
- agentscope_runtime/engine/deployers/adapter/a2a/a2a_protocol_adapter.py +28 -9
- agentscope_runtime/engine/deployers/adapter/responses/__init__.py +2 -0
- agentscope_runtime/engine/deployers/adapter/responses/response_api_adapter_utils.py +5 -2
- agentscope_runtime/engine/deployers/adapter/responses/response_api_protocol_adapter.py +1 -1
- agentscope_runtime/engine/deployers/agentrun_deployer.py +2541 -0
- agentscope_runtime/engine/deployers/cli_fc_deploy.py +1 -1
- agentscope_runtime/engine/deployers/kubernetes_deployer.py +9 -21
- agentscope_runtime/engine/deployers/local_deployer.py +47 -74
- agentscope_runtime/engine/deployers/modelstudio_deployer.py +216 -50
- agentscope_runtime/engine/deployers/utils/app_runner_utils.py +29 -0
- agentscope_runtime/engine/deployers/utils/detached_app.py +510 -0
- agentscope_runtime/engine/deployers/utils/docker_image_utils/__init__.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/dockerfile_generator.py +1 -1
- agentscope_runtime/engine/deployers/utils/docker_image_utils/{runner_image_factory.py → image_factory.py} +121 -61
- agentscope_runtime/engine/deployers/utils/package.py +693 -0
- agentscope_runtime/engine/deployers/utils/service_utils/__init__.py +0 -5
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_factory.py +256 -282
- agentscope_runtime/engine/deployers/utils/service_utils/fastapi_templates.py +2 -4
- agentscope_runtime/engine/deployers/utils/service_utils/process_manager.py +23 -1
- agentscope_runtime/engine/deployers/utils/templates/app_main.py.j2 +84 -0
- agentscope_runtime/engine/deployers/utils/templates/runner_main.py.j2 +95 -0
- agentscope_runtime/engine/deployers/utils/{service_utils → templates}/standalone_main.py.j2 +0 -45
- agentscope_runtime/engine/deployers/utils/wheel_packager.py +119 -18
- agentscope_runtime/engine/helpers/runner.py +40 -0
- agentscope_runtime/engine/runner.py +170 -130
- agentscope_runtime/engine/schemas/agent_schemas.py +114 -3
- agentscope_runtime/engine/schemas/modelstudio_llm.py +4 -2
- agentscope_runtime/engine/schemas/oai_llm.py +23 -23
- agentscope_runtime/engine/schemas/response_api.py +65 -0
- agentscope_runtime/engine/schemas/session.py +24 -0
- agentscope_runtime/engine/services/__init__.py +0 -9
- agentscope_runtime/engine/services/agent_state/__init__.py +16 -0
- agentscope_runtime/engine/services/agent_state/redis_state_service.py +113 -0
- agentscope_runtime/engine/services/agent_state/state_service.py +179 -0
- agentscope_runtime/engine/services/memory/__init__.py +24 -0
- agentscope_runtime/engine/services/{mem0_memory_service.py → memory/mem0_memory_service.py} +17 -13
- agentscope_runtime/engine/services/{memory_service.py → memory/memory_service.py} +28 -7
- agentscope_runtime/engine/services/{redis_memory_service.py → memory/redis_memory_service.py} +1 -1
- agentscope_runtime/engine/services/{reme_personal_memory_service.py → memory/reme_personal_memory_service.py} +9 -6
- agentscope_runtime/engine/services/{reme_task_memory_service.py → memory/reme_task_memory_service.py} +2 -2
- agentscope_runtime/engine/services/{tablestore_memory_service.py → memory/tablestore_memory_service.py} +12 -18
- agentscope_runtime/engine/services/sandbox/__init__.py +13 -0
- agentscope_runtime/engine/services/{sandbox_service.py → sandbox/sandbox_service.py} +86 -71
- agentscope_runtime/engine/services/session_history/__init__.py +23 -0
- agentscope_runtime/engine/services/{redis_session_history_service.py → session_history/redis_session_history_service.py} +3 -2
- agentscope_runtime/engine/services/{session_history_service.py → session_history/session_history_service.py} +44 -34
- agentscope_runtime/engine/services/{tablestore_session_history_service.py → session_history/tablestore_session_history_service.py} +14 -19
- agentscope_runtime/engine/services/utils/tablestore_service_utils.py +2 -2
- agentscope_runtime/engine/tracing/base.py +10 -9
- agentscope_runtime/engine/tracing/message_util.py +1 -1
- agentscope_runtime/engine/tracing/tracing_util.py +7 -2
- agentscope_runtime/sandbox/__init__.py +10 -2
- agentscope_runtime/sandbox/box/agentbay/__init__.py +4 -0
- agentscope_runtime/sandbox/box/agentbay/agentbay_sandbox.py +559 -0
- agentscope_runtime/sandbox/box/base/base_sandbox.py +12 -0
- agentscope_runtime/sandbox/box/browser/browser_sandbox.py +115 -11
- agentscope_runtime/sandbox/box/cloud/__init__.py +4 -0
- agentscope_runtime/sandbox/box/cloud/cloud_sandbox.py +254 -0
- agentscope_runtime/sandbox/box/filesystem/filesystem_sandbox.py +66 -0
- agentscope_runtime/sandbox/box/gui/gui_sandbox.py +42 -0
- agentscope_runtime/sandbox/box/mobile/__init__.py +4 -0
- agentscope_runtime/sandbox/box/mobile/box/__init__.py +0 -0
- agentscope_runtime/sandbox/box/mobile/mobile_sandbox.py +216 -0
- agentscope_runtime/sandbox/box/training_box/training_box.py +2 -2
- agentscope_runtime/sandbox/client/http_client.py +1 -0
- agentscope_runtime/sandbox/enums.py +2 -0
- agentscope_runtime/sandbox/manager/sandbox_manager.py +18 -2
- agentscope_runtime/sandbox/manager/server/app.py +12 -0
- agentscope_runtime/sandbox/manager/server/config.py +19 -0
- agentscope_runtime/sandbox/model/manager_config.py +79 -2
- agentscope_runtime/sandbox/utils.py +0 -18
- agentscope_runtime/tools/RAGs/__init__.py +0 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag.py +377 -0
- agentscope_runtime/tools/RAGs/modelstudio_rag_lite.py +219 -0
- agentscope_runtime/tools/__init__.py +119 -0
- agentscope_runtime/tools/_constants.py +18 -0
- agentscope_runtime/tools/alipay/__init__.py +4 -0
- agentscope_runtime/tools/alipay/base.py +334 -0
- agentscope_runtime/tools/alipay/payment.py +835 -0
- agentscope_runtime/tools/alipay/subscribe.py +551 -0
- agentscope_runtime/tools/base.py +264 -0
- agentscope_runtime/tools/cli/__init__.py +0 -0
- agentscope_runtime/tools/cli/modelstudio_mcp_server.py +78 -0
- agentscope_runtime/tools/generations/__init__.py +75 -0
- agentscope_runtime/tools/generations/async_image_to_video.py +350 -0
- agentscope_runtime/tools/generations/async_image_to_video_wan25.py +366 -0
- agentscope_runtime/tools/generations/async_speech_to_video.py +422 -0
- agentscope_runtime/tools/generations/async_text_to_video.py +320 -0
- agentscope_runtime/tools/generations/async_text_to_video_wan25.py +334 -0
- agentscope_runtime/tools/generations/image_edit.py +208 -0
- agentscope_runtime/tools/generations/image_edit_wan25.py +193 -0
- agentscope_runtime/tools/generations/image_generation.py +202 -0
- agentscope_runtime/tools/generations/image_generation_wan25.py +201 -0
- agentscope_runtime/tools/generations/image_style_repaint.py +208 -0
- agentscope_runtime/tools/generations/image_to_video.py +233 -0
- agentscope_runtime/tools/generations/qwen_image_edit.py +205 -0
- agentscope_runtime/tools/generations/qwen_image_generation.py +214 -0
- agentscope_runtime/tools/generations/qwen_text_to_speech.py +154 -0
- agentscope_runtime/tools/generations/speech_to_text.py +260 -0
- agentscope_runtime/tools/generations/speech_to_video.py +314 -0
- agentscope_runtime/tools/generations/text_to_video.py +221 -0
- agentscope_runtime/tools/mcp_wrapper.py +215 -0
- agentscope_runtime/tools/realtime_clients/__init__.py +13 -0
- agentscope_runtime/tools/realtime_clients/asr_client.py +27 -0
- agentscope_runtime/tools/realtime_clients/azure_asr_client.py +195 -0
- agentscope_runtime/tools/realtime_clients/azure_tts_client.py +383 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_asr_client.py +151 -0
- agentscope_runtime/tools/realtime_clients/modelstudio_tts_client.py +199 -0
- agentscope_runtime/tools/realtime_clients/realtime_tool.py +55 -0
- agentscope_runtime/tools/realtime_clients/tts_client.py +33 -0
- agentscope_runtime/tools/searches/__init__.py +3 -0
- agentscope_runtime/tools/searches/modelstudio_search.py +877 -0
- agentscope_runtime/tools/searches/modelstudio_search_lite.py +310 -0
- agentscope_runtime/tools/utils/__init__.py +0 -0
- agentscope_runtime/tools/utils/api_key_util.py +45 -0
- agentscope_runtime/tools/utils/crypto_utils.py +99 -0
- agentscope_runtime/tools/utils/mcp_util.py +35 -0
- agentscope_runtime/version.py +1 -1
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/METADATA +234 -165
- agentscope_runtime-1.0.0b1.dist-info/RECORD +240 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/entry_points.txt +1 -0
- agentscope_runtime/engine/agents/__init__.py +0 -2
- agentscope_runtime/engine/agents/agentscope_agent.py +0 -488
- agentscope_runtime/engine/agents/agno_agent.py +0 -220
- agentscope_runtime/engine/agents/autogen_agent.py +0 -250
- agentscope_runtime/engine/agents/base_agent.py +0 -29
- agentscope_runtime/engine/agents/langgraph_agent.py +0 -59
- agentscope_runtime/engine/agents/utils.py +0 -53
- agentscope_runtime/engine/deployers/utils/package_project_utils.py +0 -1163
- agentscope_runtime/engine/deployers/utils/service_utils/service_config.py +0 -75
- agentscope_runtime/engine/deployers/utils/service_utils/service_factory.py +0 -220
- agentscope_runtime/engine/helpers/helper.py +0 -179
- agentscope_runtime/engine/schemas/context.py +0 -54
- agentscope_runtime/engine/services/context_manager.py +0 -164
- agentscope_runtime/engine/services/environment_manager.py +0 -50
- agentscope_runtime/engine/services/manager.py +0 -174
- agentscope_runtime/engine/services/rag_service.py +0 -195
- agentscope_runtime/engine/services/tablestore_rag_service.py +0 -143
- agentscope_runtime/sandbox/tools/__init__.py +0 -12
- agentscope_runtime/sandbox/tools/base/__init__.py +0 -8
- agentscope_runtime/sandbox/tools/base/tool.py +0 -52
- agentscope_runtime/sandbox/tools/browser/__init__.py +0 -57
- agentscope_runtime/sandbox/tools/browser/tool.py +0 -597
- agentscope_runtime/sandbox/tools/filesystem/__init__.py +0 -32
- agentscope_runtime/sandbox/tools/filesystem/tool.py +0 -319
- agentscope_runtime/sandbox/tools/function_tool.py +0 -321
- agentscope_runtime/sandbox/tools/gui/__init__.py +0 -7
- agentscope_runtime/sandbox/tools/gui/tool.py +0 -77
- agentscope_runtime/sandbox/tools/mcp_tool.py +0 -195
- agentscope_runtime/sandbox/tools/sandbox_tool.py +0 -104
- agentscope_runtime/sandbox/tools/tool.py +0 -238
- agentscope_runtime/sandbox/tools/utils.py +0 -68
- agentscope_runtime-0.2.0b2.dist-info/RECORD +0 -183
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/WHEEL +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/licenses/LICENSE +0 -0
- {agentscope_runtime-0.2.0b2.dist-info → agentscope_runtime-1.0.0b1.dist-info}/top_level.txt +0 -0
|
@@ -109,7 +109,7 @@ async def _run(
|
|
|
109
109
|
if mode == "native":
|
|
110
110
|
# Build the current project directly as a wheel, then upload/deploy
|
|
111
111
|
project_dir_path = Path.cwd()
|
|
112
|
-
built_whl =
|
|
112
|
+
built_whl = build_wheel(project_dir_path)
|
|
113
113
|
return await deployer.deploy(
|
|
114
114
|
project_dir=None,
|
|
115
115
|
cmd=None,
|
|
@@ -9,13 +9,9 @@ from pydantic import BaseModel, Field
|
|
|
9
9
|
from .adapter.protocol_adapter import ProtocolAdapter
|
|
10
10
|
from .base import DeployManager
|
|
11
11
|
from .utils.docker_image_utils import (
|
|
12
|
-
|
|
12
|
+
ImageFactory,
|
|
13
13
|
RegistryConfig,
|
|
14
14
|
)
|
|
15
|
-
from .utils.service_utils import (
|
|
16
|
-
ServicesConfig,
|
|
17
|
-
)
|
|
18
|
-
from ..runner import Runner
|
|
19
15
|
from ...common.container_clients.kubernetes_client import (
|
|
20
16
|
KubernetesClient,
|
|
21
17
|
)
|
|
@@ -60,7 +56,7 @@ class KubernetesDeployManager(DeployManager):
|
|
|
60
56
|
super().__init__()
|
|
61
57
|
self.kubeconfig = kube_config
|
|
62
58
|
self.registry_config = registry_config
|
|
63
|
-
self.image_factory =
|
|
59
|
+
self.image_factory = ImageFactory()
|
|
64
60
|
self.use_deployment = use_deployment
|
|
65
61
|
self.build_context_dir = build_context_dir
|
|
66
62
|
self._deployed_resources = {}
|
|
@@ -73,10 +69,10 @@ class KubernetesDeployManager(DeployManager):
|
|
|
73
69
|
|
|
74
70
|
async def deploy(
|
|
75
71
|
self,
|
|
76
|
-
|
|
72
|
+
app=None,
|
|
73
|
+
runner=None,
|
|
77
74
|
endpoint_path: str = "/process",
|
|
78
75
|
stream: bool = True,
|
|
79
|
-
services_config: Optional[Union[ServicesConfig, dict]] = None,
|
|
80
76
|
custom_endpoints: Optional[List[Dict]] = None,
|
|
81
77
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
82
78
|
requirements: Optional[Union[str, List[str]]] = None,
|
|
@@ -96,11 +92,11 @@ class KubernetesDeployManager(DeployManager):
|
|
|
96
92
|
Deploy runner to Kubernetes.
|
|
97
93
|
|
|
98
94
|
Args:
|
|
95
|
+
app: Agent app to be deployed
|
|
99
96
|
runner: Complete Runner object with agent, environment_manager,
|
|
100
97
|
context_manager
|
|
101
98
|
endpoint_path: API endpoint path
|
|
102
99
|
stream: Enable streaming responses
|
|
103
|
-
services_config: Services configuration for context manager
|
|
104
100
|
custom_endpoints: Custom endpoints from agent app
|
|
105
101
|
protocol_adapters: protocol adapters
|
|
106
102
|
requirements: PyPI dependencies (following _agent_engines.py
|
|
@@ -130,20 +126,11 @@ class KubernetesDeployManager(DeployManager):
|
|
|
130
126
|
try:
|
|
131
127
|
logger.info(f"Starting deployment {deploy_id}")
|
|
132
128
|
|
|
133
|
-
# Handle backward compatibility
|
|
134
|
-
if runner is None:
|
|
135
|
-
raise ValueError(
|
|
136
|
-
"Runner must be provided",
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
# convert services_config to Model body
|
|
140
|
-
if services_config and isinstance(services_config, dict):
|
|
141
|
-
services_config = ServicesConfig(**services_config)
|
|
142
|
-
|
|
143
129
|
# Step 1: Build image with proper error handling
|
|
144
130
|
logger.info("Building runner image...")
|
|
145
131
|
try:
|
|
146
|
-
built_image_name = self.image_factory.
|
|
132
|
+
built_image_name = self.image_factory.build_image(
|
|
133
|
+
app=app,
|
|
147
134
|
runner=runner,
|
|
148
135
|
requirements=requirements,
|
|
149
136
|
extra_packages=extra_packages or [],
|
|
@@ -156,7 +143,6 @@ class KubernetesDeployManager(DeployManager):
|
|
|
156
143
|
image_tag=image_tag,
|
|
157
144
|
push_to_registry=push_to_registry,
|
|
158
145
|
port=port,
|
|
159
|
-
services_config=services_config, # type: ignore[arg-type]
|
|
160
146
|
protocol_adapters=protocol_adapters,
|
|
161
147
|
custom_endpoints=custom_endpoints,
|
|
162
148
|
**kwargs,
|
|
@@ -189,6 +175,8 @@ class KubernetesDeployManager(DeployManager):
|
|
|
189
175
|
|
|
190
176
|
resource_name = f"agent-{deploy_id[:8]}"
|
|
191
177
|
|
|
178
|
+
logger.info(f"Building kubernetes deployment for {deploy_id}")
|
|
179
|
+
|
|
192
180
|
# Create Deployment
|
|
193
181
|
_id, ports, ip = self.k8s_client.create_deployment(
|
|
194
182
|
image=built_image_name,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
# pylint:disable=protected-access
|
|
2
|
+
# pylint:disable=protected-access, unused-argument
|
|
3
3
|
|
|
4
4
|
import asyncio
|
|
5
5
|
import logging
|
|
@@ -13,12 +13,13 @@ import uvicorn
|
|
|
13
13
|
from .adapter.protocol_adapter import ProtocolAdapter
|
|
14
14
|
from .base import DeployManager
|
|
15
15
|
from .utils.deployment_modes import DeploymentMode
|
|
16
|
-
from .utils.
|
|
16
|
+
from .utils.detached_app import (
|
|
17
|
+
build_detached_app,
|
|
18
|
+
get_bundle_entry_script,
|
|
19
|
+
)
|
|
17
20
|
from .utils.service_utils import (
|
|
18
21
|
FastAPIAppFactory,
|
|
19
|
-
FastAPITemplateManager,
|
|
20
22
|
ProcessManager,
|
|
21
|
-
ServicesConfig,
|
|
22
23
|
)
|
|
23
24
|
|
|
24
25
|
|
|
@@ -63,13 +64,10 @@ class LocalDeployManager(DeployManager):
|
|
|
63
64
|
shutdown_timeout=shutdown_timeout,
|
|
64
65
|
)
|
|
65
66
|
|
|
66
|
-
# Template manager
|
|
67
|
-
self.template_manager = FastAPITemplateManager()
|
|
68
|
-
|
|
69
67
|
async def deploy(
|
|
70
68
|
self,
|
|
71
69
|
app=None,
|
|
72
|
-
runner
|
|
70
|
+
runner=None,
|
|
73
71
|
endpoint_path: str = "/process",
|
|
74
72
|
request_model: Optional[Type] = None,
|
|
75
73
|
response_type: str = "sse",
|
|
@@ -77,7 +75,6 @@ class LocalDeployManager(DeployManager):
|
|
|
77
75
|
before_start: Optional[Callable] = None,
|
|
78
76
|
after_finish: Optional[Callable] = None,
|
|
79
77
|
mode: DeploymentMode = DeploymentMode.DAEMON_THREAD,
|
|
80
|
-
services_config: Optional[ServicesConfig] = None,
|
|
81
78
|
custom_endpoints: Optional[List[Dict]] = None,
|
|
82
79
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
83
80
|
broker_url: Optional[str] = None,
|
|
@@ -88,6 +85,7 @@ class LocalDeployManager(DeployManager):
|
|
|
88
85
|
"""Deploy using unified FastAPI architecture.
|
|
89
86
|
|
|
90
87
|
Args:
|
|
88
|
+
app: Agent app to be deployed
|
|
91
89
|
runner: Runner instance (for DAEMON_THREAD mode)
|
|
92
90
|
endpoint_path: API endpoint path
|
|
93
91
|
request_model: Pydantic model for request validation
|
|
@@ -96,7 +94,6 @@ class LocalDeployManager(DeployManager):
|
|
|
96
94
|
before_start: Callback function called before server starts
|
|
97
95
|
after_finish: Callback function called after server finishes
|
|
98
96
|
mode: Deployment mode
|
|
99
|
-
services_config: Services configuration
|
|
100
97
|
custom_endpoints: Custom endpoints from agent app
|
|
101
98
|
protocol_adapters: Protocol adapters
|
|
102
99
|
broker_url: Celery broker URL for background task processing
|
|
@@ -137,7 +134,6 @@ class LocalDeployManager(DeployManager):
|
|
|
137
134
|
stream=stream,
|
|
138
135
|
before_start=before_start,
|
|
139
136
|
after_finish=after_finish,
|
|
140
|
-
services_config=services_config,
|
|
141
137
|
custom_endpoints=custom_endpoints,
|
|
142
138
|
protocol_adapters=protocol_adapters,
|
|
143
139
|
broker_url=broker_url,
|
|
@@ -154,7 +150,6 @@ class LocalDeployManager(DeployManager):
|
|
|
154
150
|
stream=stream,
|
|
155
151
|
before_start=before_start,
|
|
156
152
|
after_finish=after_finish,
|
|
157
|
-
services_config=services_config,
|
|
158
153
|
custom_endpoints=custom_endpoints,
|
|
159
154
|
protocol_adapters=protocol_adapters,
|
|
160
155
|
**kwargs,
|
|
@@ -227,7 +222,6 @@ class LocalDeployManager(DeployManager):
|
|
|
227
222
|
async def _deploy_detached_process(
|
|
228
223
|
self,
|
|
229
224
|
runner: Optional[Any] = None,
|
|
230
|
-
services_config: Optional[ServicesConfig] = None,
|
|
231
225
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
232
226
|
**kwargs,
|
|
233
227
|
) -> Dict[str, str]:
|
|
@@ -236,27 +230,29 @@ class LocalDeployManager(DeployManager):
|
|
|
236
230
|
"Deploying FastAPI service in detached process mode...",
|
|
237
231
|
)
|
|
238
232
|
|
|
239
|
-
|
|
240
|
-
if not runner or not runner._agent:
|
|
233
|
+
if runner is None and self._app is None:
|
|
241
234
|
raise ValueError(
|
|
242
|
-
"Detached process mode requires
|
|
235
|
+
"Detached process mode requires an app or runner",
|
|
243
236
|
)
|
|
244
237
|
|
|
245
|
-
agent = runner._agent
|
|
246
238
|
if "agent" in kwargs:
|
|
247
239
|
kwargs.pop("agent")
|
|
240
|
+
if "app" in kwargs:
|
|
241
|
+
kwargs.pop("app")
|
|
248
242
|
|
|
249
243
|
# Create package project for detached deployment
|
|
250
244
|
project_dir = await self.create_detached_project(
|
|
251
|
-
|
|
252
|
-
|
|
245
|
+
app=self._app,
|
|
246
|
+
runner=runner,
|
|
253
247
|
protocol_adapters=protocol_adapters,
|
|
254
248
|
**kwargs,
|
|
255
249
|
)
|
|
256
250
|
|
|
257
251
|
try:
|
|
252
|
+
entry_script = get_bundle_entry_script(project_dir)
|
|
253
|
+
script_path = os.path.join(project_dir, entry_script)
|
|
254
|
+
|
|
258
255
|
# Start detached process using the packaged project
|
|
259
|
-
script_path = os.path.join(project_dir, "main.py")
|
|
260
256
|
pid = await self.process_manager.start_detached_process(
|
|
261
257
|
script_path=script_path,
|
|
262
258
|
host=self.host,
|
|
@@ -304,68 +300,24 @@ class LocalDeployManager(DeployManager):
|
|
|
304
300
|
|
|
305
301
|
@staticmethod
|
|
306
302
|
async def create_detached_project(
|
|
307
|
-
|
|
303
|
+
app=None,
|
|
304
|
+
runner: Optional[Any] = None,
|
|
308
305
|
endpoint_path: str = "/process",
|
|
309
306
|
requirements: Optional[Union[str, List[str]]] = None,
|
|
310
307
|
extra_packages: Optional[List[str]] = None,
|
|
311
|
-
services_config: Optional[ServicesConfig] = None,
|
|
312
308
|
protocol_adapters: Optional[list[ProtocolAdapter]] = None,
|
|
313
|
-
custom_endpoints: Optional[
|
|
314
|
-
List[Dict]
|
|
315
|
-
] = None, # New parameter for custom endpoints
|
|
316
|
-
# Celery parameters
|
|
309
|
+
custom_endpoints: Optional[List[Dict]] = None,
|
|
317
310
|
broker_url: Optional[str] = None,
|
|
318
311
|
backend_url: Optional[str] = None,
|
|
319
312
|
enable_embedded_worker: bool = False,
|
|
320
|
-
**kwargs,
|
|
313
|
+
**kwargs,
|
|
321
314
|
) -> str:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if isinstance(requirements, str):
|
|
327
|
-
requirements = [requirements]
|
|
328
|
-
|
|
329
|
-
# Create package configuration for detached deployment
|
|
330
|
-
package_config = PackageConfig(
|
|
331
|
-
endpoint_path=endpoint_path,
|
|
332
|
-
deployment_mode="detached_process",
|
|
315
|
+
project_dir, _ = build_detached_app(
|
|
316
|
+
app=app,
|
|
317
|
+
runner=runner,
|
|
318
|
+
requirements=requirements,
|
|
333
319
|
extra_packages=extra_packages,
|
|
334
|
-
|
|
335
|
-
services_config=services_config,
|
|
336
|
-
custom_endpoints=custom_endpoints, # Add custom endpoints
|
|
337
|
-
# Celery configuration
|
|
338
|
-
broker_url=broker_url,
|
|
339
|
-
backend_url=backend_url,
|
|
340
|
-
enable_embedded_worker=enable_embedded_worker,
|
|
341
|
-
requirements=requirements
|
|
342
|
-
+ (
|
|
343
|
-
["redis"]
|
|
344
|
-
if services_config
|
|
345
|
-
and any(
|
|
346
|
-
getattr(config, "provider", None) == "redis"
|
|
347
|
-
for config in [
|
|
348
|
-
services_config.memory,
|
|
349
|
-
services_config.session_history,
|
|
350
|
-
]
|
|
351
|
-
if config
|
|
352
|
-
)
|
|
353
|
-
else []
|
|
354
|
-
)
|
|
355
|
-
+ (
|
|
356
|
-
[
|
|
357
|
-
"celery",
|
|
358
|
-
"redis",
|
|
359
|
-
] # Add Celery and Redis if Celery is configured
|
|
360
|
-
if broker_url or backend_url
|
|
361
|
-
else []
|
|
362
|
-
),
|
|
363
|
-
)
|
|
364
|
-
|
|
365
|
-
# Use package_project to create the detached project
|
|
366
|
-
project_dir, _ = package_project(
|
|
367
|
-
agent=agent,
|
|
368
|
-
config=package_config,
|
|
320
|
+
**kwargs,
|
|
369
321
|
)
|
|
370
322
|
|
|
371
323
|
return project_dir
|
|
@@ -442,13 +394,34 @@ class LocalDeployManager(DeployManager):
|
|
|
442
394
|
def _is_server_ready(self) -> bool:
|
|
443
395
|
"""Check if the server is ready to accept connections."""
|
|
444
396
|
try:
|
|
397
|
+
# Normalize host for connection check
|
|
398
|
+
# When service binds to 0.0.0.0, we need to connect to 127.0.0.1
|
|
399
|
+
check_host = self._normalize_host_for_check(self.host)
|
|
445
400
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
446
401
|
s.settimeout(0.1)
|
|
447
|
-
result = s.connect_ex((
|
|
402
|
+
result = s.connect_ex((check_host, self.port))
|
|
448
403
|
return result == 0
|
|
449
404
|
except Exception:
|
|
450
405
|
return False
|
|
451
406
|
|
|
407
|
+
@staticmethod
|
|
408
|
+
def _normalize_host_for_check(host: str) -> str:
|
|
409
|
+
"""Normalize host for connection check.
|
|
410
|
+
|
|
411
|
+
When a service binds to 0.0.0.0 (all interfaces), it cannot be
|
|
412
|
+
directly connected to. We need to connect to 127.0.0.1 instead
|
|
413
|
+
to check if the service is running locally.
|
|
414
|
+
|
|
415
|
+
Args:
|
|
416
|
+
host: The host the service binds to
|
|
417
|
+
|
|
418
|
+
Returns:
|
|
419
|
+
The host to use for connection check
|
|
420
|
+
"""
|
|
421
|
+
if host in ("0.0.0.0", "::"):
|
|
422
|
+
return "127.0.0.1"
|
|
423
|
+
return host
|
|
424
|
+
|
|
452
425
|
async def _wait_for_server_ready(self, timeout: int = 30):
|
|
453
426
|
"""Wait for server to become ready."""
|
|
454
427
|
end_time = asyncio.get_event_loop().time() + timeout
|