Skip to content

Commit e92d944

Browse files
authored
feat: App build enhancements and agent optimization (#161)
1 parent 91abb74 commit e92d944

114 files changed

Lines changed: 1593 additions & 472 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/derisk-app/src/derisk_app/openapi/api_v1/tool_management_api.py

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,60 @@ def ensure_tools_initialized():
2929
register_builtin_tools()
3030

3131

32+
def get_sandbox_enabled_from_app(app_id: Optional[str]) -> bool:
33+
"""
34+
从应用配置中获取沙箱是否启用
35+
36+
Args:
37+
app_id: 应用ID
38+
39+
Returns:
40+
是否启用沙箱环境
41+
"""
42+
if not app_id:
43+
return False
44+
45+
try:
46+
from derisk_serve.building.config.models.models import ServeEntity
47+
from derisk.storage.metadata import get_storage
48+
import json
49+
50+
storage = get_storage()
51+
with storage.session() as session:
52+
config = (
53+
session.query(ServeEntity)
54+
.filter(
55+
ServeEntity.app_code == app_id, ServeEntity.is_published == True
56+
)
57+
.first()
58+
)
59+
60+
if config and config.param_need:
61+
param_need = config.param_need
62+
if isinstance(param_need, str):
63+
param_need = json.loads(param_need)
64+
65+
for item in param_need:
66+
if isinstance(item, dict) and item.get("key") == "sandbox":
67+
sandbox_value = item.get("value", {})
68+
if isinstance(sandbox_value, str):
69+
sandbox_value = json.loads(sandbox_value)
70+
sandbox_type = (
71+
sandbox_value.get("type", "local")
72+
if isinstance(sandbox_value, dict)
73+
else "local"
74+
)
75+
return sandbox_type and sandbox_type != "local"
76+
except Exception as e:
77+
import logging
78+
79+
logging.getLogger(__name__).debug(
80+
f"Could not get sandbox config for app {app_id}: {e}"
81+
)
82+
83+
return False
84+
85+
3286
# ========== 请求/响应模型 ==========
3387

3488

@@ -79,14 +133,22 @@ async def get_tool_groups(
79133
"""
80134
获取工具分组列表
81135
82-
返回按分组类型组织的工具列表,包括绑定状态信息
136+
返回按分组类型组织的工具列表,包括绑定状态信息。
137+
沙箱状态自动从应用配置中获取:
138+
- 如果应用配置了沙箱且 type != "local": 沙箱工具显示为默认绑定
139+
- 否则: 本地工具 (read, bash) 显示为默认绑定
83140
"""
84141
try:
85-
# 确保工具已初始化
86142
ensure_tools_initialized()
87143

144+
# 自动从应用配置中获取沙箱状态
145+
sandbox_enabled = get_sandbox_enabled_from_app(app_id)
146+
88147
groups = tool_manager.get_tool_groups(
89-
app_id=app_id, agent_name=agent_name, lang=lang
148+
app_id=app_id,
149+
agent_name=agent_name,
150+
lang=lang,
151+
sandbox_enabled=sandbox_enabled,
90152
)
91153

92154
return JSONResponse(
@@ -107,10 +169,12 @@ async def get_agent_tool_config(
107169
返回指定 Agent 的完整工具绑定配置
108170
"""
109171
try:
110-
# 确保工具已初始化
111172
ensure_tools_initialized()
112173

113-
config = tool_manager.get_agent_config(app_id, agent_name)
174+
sandbox_enabled = get_sandbox_enabled_from_app(app_id)
175+
config = tool_manager.get_agent_config(
176+
app_id, agent_name, sandbox_enabled=sandbox_enabled
177+
)
114178
if not config:
115179
return JSONResponse(
116180
content={"success": False, "message": "Configuration not found"}
@@ -141,7 +205,6 @@ async def update_tool_binding(request: ToolBindingUpdateRequest):
141205
用于绑定或解绑工具
142206
"""
143207
try:
144-
# 确保工具已初始化
145208
ensure_tools_initialized()
146209

147210
success = tool_manager.update_tool_binding(
@@ -173,7 +236,6 @@ async def batch_update_tool_bindings(request: BatchToolBindingUpdateRequest):
173236
用于一次性更新多个工具的绑定状态
174237
"""
175238
try:
176-
# 确保工具已初始化
177239
ensure_tools_initialized()
178240

179241
results = []
@@ -209,11 +271,13 @@ async def get_runtime_tools(request: RuntimeToolsRequest):
209271
返回 Agent 实际可用的工具列表(已排除被禁用的工具)
210272
"""
211273
try:
212-
# 确保工具已初始化
213274
ensure_tools_initialized()
214275

276+
sandbox_enabled = get_sandbox_enabled_from_app(request.app_id)
215277
tools = tool_manager.get_runtime_tools(
216-
app_id=request.app_id, agent_name=request.agent_name
278+
app_id=request.app_id,
279+
agent_name=request.agent_name,
280+
sandbox_enabled=sandbox_enabled,
217281
)
218282

219283
tool_list = []
@@ -251,13 +315,14 @@ async def get_runtime_tool_schemas(request: RuntimeToolsRequest):
251315
返回用于 LLM 工具调用的 Schema 列表
252316
"""
253317
try:
254-
# 确保工具已初始化
255318
ensure_tools_initialized()
256319

320+
sandbox_enabled = get_sandbox_enabled_from_app(request.app_id)
257321
schemas = tool_manager.get_runtime_tool_schemas(
258322
app_id=request.app_id,
259323
agent_name=request.agent_name,
260324
format_type=request.format_type,
325+
sandbox_enabled=sandbox_enabled,
261326
)
262327

263328
return JSONResponse(
@@ -286,7 +351,6 @@ async def list_all_tools(
286351
支持按类别、来源过滤和搜索
287352
"""
288353
try:
289-
# 确保工具已初始化
290354
ensure_tools_initialized()
291355

292356
tools = tool_registry.list_all()
@@ -295,15 +359,12 @@ async def list_all_tools(
295359
for tool in tools:
296360
metadata = tool.metadata
297361

298-
# 类别过滤
299362
if category and metadata.category and metadata.category.value != category:
300363
continue
301364

302-
# 来源过滤
303365
if source and metadata.source and metadata.source.value != source:
304366
continue
305367

306-
# 搜索过滤
307368
if query:
308369
query_lower = query.lower()
309370
if (
@@ -345,7 +406,6 @@ async def get_tool_detail(tool_id: str):
345406
返回指定工具的完整信息
346407
"""
347408
try:
348-
# 确保工具已初始化
349409
ensure_tools_initialized()
350410

351411
tool = tool_registry.get(tool_id)
@@ -413,7 +473,6 @@ async def clear_tool_cache(
413473
用于配置更新后刷新缓存
414474
"""
415475
try:
416-
# 确保工具已初始化
417476
ensure_tools_initialized()
418477

419478
tool_manager.clear_cache(app_id, agent_name)

packages/derisk-app/src/derisk_app/static/web/404.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/derisk-app/src/derisk_app/static/web/404/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/derisk-app/src/derisk_app/static/web/_next/static/8ZaJEcD2RCFq8rMtZkYj-/_buildManifest.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
self.__SSG_MANIFEST=new Set(["\u002Fprompt\u002F[type]"]);self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()

packages/derisk-app/src/derisk_app/static/web/_next/static/chunks/1725-3ce9aa2c1109ec34.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/derisk-app/src/derisk_app/static/web/_next/static/chunks/2159-8c6f91d2b77c9976.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/derisk-app/src/derisk_app/static/web/_next/static/chunks/2260-e47b004077ae558d.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/derisk-app/src/derisk_app/static/web/_next/static/chunks/2530-e4f9bd784ccd2826.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/derisk-app/src/derisk_app/static/web/_next/static/chunks/2585-509a6bfe79017904.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)