Skip to content

Commit 0982d4f

Browse files
authored
feat: unified config management with encrypted secrets storage (#166)
1 parent f6e48f6 commit 0982d4f

224 files changed

Lines changed: 4652 additions & 1983 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.

assets/schema/derisk.sql

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use derisk;
99
-- MySQL DDL Script for Derisk
1010
-- Version: 0.3.0
1111
-- Generated from SQLAlchemy ORM Models
12-
-- Generated: 2026-03-13 14:14:55
12+
-- Generated: 2026-03-16 15:22:00
1313
-- ============================================================
1414

1515
SET NAMES utf8mb4;
@@ -37,6 +37,27 @@ CREATE TABLE IF NOT EXISTS `derisk_cluster_registry_instance` (
3737
UNIQUE KEY `uk_model_instance` (`model_name`, `host`, `port`, `sys_code`)
3838
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3939

40+
-- Table: streaming_tool_config
41+
-- Source Model: StreamingToolConfig
42+
CREATE TABLE IF NOT EXISTS `streaming_tool_config` (
43+
`id` BIGINT NOT NULL AUTO_INCREMENT,
44+
`app_code` VARCHAR(128) NOT NULL COMMENT '应用代码',
45+
`tool_name` VARCHAR(128) NOT NULL COMMENT '工具名称',
46+
`tool_display_name` VARCHAR(256) NULL COMMENT '工具显示名称',
47+
`tool_description` TEXT NULL COMMENT '工具描述',
48+
`param_configs` JSON NOT NULL COMMENT '参数配置',
49+
`global_threshold` INT NULL DEFAULT 256 COMMENT '全局阈值',
50+
`global_strategy` VARCHAR(32) NULL COMMENT '全局策略',
51+
`global_renderer` VARCHAR(32) NULL COMMENT '全局渲染器',
52+
`enabled` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否启用流式',
53+
`priority` INT NOT NULL DEFAULT 0 COMMENT '优先级',
54+
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
55+
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
56+
`created_by` VARCHAR(128) NULL COMMENT '创建人',
57+
`updated_by` VARCHAR(128) NULL COMMENT '更新人',
58+
PRIMARY KEY (`id`)
59+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
60+
4061
-- Table: chat_history
4162
-- Source Model: ChatHistoryEntity
4263
CREATE TABLE IF NOT EXISTS `chat_history` (

configs/derisk.default.json

Lines changed: 0 additions & 69 deletions
This file was deleted.

derisk.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "OpenDeRisk",
3+
"version": "0.1.0",
4+
"default_model": {
5+
"provider": "openai",
6+
"model_id": "gpt-4",
7+
"api_key": "sk-s6bVede3eiCFhJ35WHUa4WSDj8Z4nXutLPUrOxg7Swcl0JkV",
8+
"temperature": 0.7,
9+
"max_tokens": 4096
10+
},
11+
"agents": {
12+
"primary": {
13+
"name": "primary",
14+
"description": "主Agent",
15+
"permission": {
16+
"default_action": "ask",
17+
"rules": {
18+
"*": "allow",
19+
"*.env": "ask",
20+
"*.secret*": "ask"
21+
}
22+
},
23+
"max_steps": 20,
24+
"color": "#4A90E2"
25+
}
26+
},
27+
"sandbox": {
28+
"enabled": false,
29+
"image": "python:3.11-slim",
30+
"memory_limit": "512m",
31+
"timeout": 300,
32+
"network_enabled": false
33+
},
34+
"oauth2": {
35+
"enabled": false,
36+
"providers": [],
37+
"admin_users": []
38+
},
39+
"workspace": "/Users/tuyang/.derisk/workspace",
40+
"log_level": "INFO",
41+
"server": {
42+
"host": "127.0.0.1",
43+
"port": 7777
44+
}
45+
}

packages/derisk-app/src/derisk_app/derisk_server.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import sys
4+
from pathlib import Path
45

56
from derisk.util.logger import (
67
logging_str_to_uvicorn_level,
@@ -14,6 +15,21 @@
1415
ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1516
sys.path.append(ROOT_PATH)
1617

18+
DEFAULT_JSON_CONFIG_PATH = Path.home() / ".derisk" / "derisk.json"
19+
20+
21+
def init_json_config_manager():
22+
"""Initialize the JSON config manager for UI configuration"""
23+
try:
24+
from derisk_core.config import ConfigManager
25+
26+
ConfigManager.init(str(DEFAULT_JSON_CONFIG_PATH))
27+
logger.info(
28+
f"JSON config manager initialized: {ConfigManager.get_config_path()}"
29+
)
30+
except Exception as e:
31+
logger.warning(f"Failed to initialize JSON config manager: {e}")
32+
1733

1834
def run_uvicorn(creator: AppCreator):
1935
import uvicorn
@@ -27,13 +43,15 @@ def run_uvicorn(creator: AppCreator):
2743
loop = "auto"
2844
try:
2945
import uvloop
46+
3047
loop = "uvloop"
3148
except ImportError:
3249
pass
3350

3451
http = "auto"
3552
try:
3653
import httptools
54+
3755
http = "httptools"
3856
except ImportError:
3957
pass
@@ -51,7 +69,16 @@ def run_uvicorn(creator: AppCreator):
5169

5270

5371
def run_webserver(config_file: str):
54-
creator = next((creator for creator in AppCreator.__subclasses__() if creator.config_file and creator.config_file.endswith(config_file)), CustomAppCreator)(config_file)
72+
init_json_config_manager()
73+
74+
creator = next(
75+
(
76+
creator
77+
for creator in AppCreator.__subclasses__()
78+
if creator.config_file and creator.config_file.endswith(config_file)
79+
),
80+
CustomAppCreator,
81+
)(config_file)
5582
with root_tracer.start_span(
5683
"run_webserver",
5784
span_type=SpanType.RUN,
@@ -73,7 +100,9 @@ def parse_args():
73100
"--config",
74101
type=str,
75102
default=None,
76-
help="Path to the configuration file. Default: configs/derisk-siliconflow.toml",
103+
help=f"Path to the TOML configuration file for service infrastructure. "
104+
f"Default: configs/derisk-proxy-aliyun.toml. "
105+
f"Application settings (JSON) are stored in: {DEFAULT_JSON_CONFIG_PATH}",
77106
)
78107
return parser.parse_args()
79108

0 commit comments

Comments
 (0)