6d658b4f4d
- 工具系统从 kilostar/plugin/tool_plugin/ 迁移到 data/toolset/(manifest.json 声明式) - 新增 plugin_runtime 模块:BaseOrganization / GlobalPluginManager / loader / tool_bridge - 新增 org_task + org_task_event 表及 DAO(alembic 0009) - 新增 /api/v1/plugin 路由(submit/status/stream/install/reload) - 新增 data/plugin/example_dept 示例重型插件 - regulatory_node 支持聊天历史上下文注入 - send_file 改为 artifact 存盘 + SSE 推送下载链接 - 前端 WorkflowFileCard 组件 + ToolSettings README 渲染 - utils 整理:合并 access/role_check、standalone_proxy→ray_compat、删除废弃模块 - 项目结构文档移至 docs/STRUCTURE.md 并详细展开 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
102 lines
3.0 KiB
Python
102 lines
3.0 KiB
Python
"""KiloStar 集中式环境变量管理。
|
|
|
|
所有散落在各模块的 os.getenv/os.environ 收敛到此处,
|
|
通过 pydantic-settings 统一校验、类型转换、默认值管理。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from functools import lru_cache
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class DatabaseSettings(BaseSettings):
|
|
postgres_user: str = "postgres"
|
|
postgres_password: str = ""
|
|
postgres_host: str = "db"
|
|
postgres_port: int = 5432
|
|
postgres_db: str = "postgres"
|
|
|
|
|
|
class SecuritySettings(BaseSettings):
|
|
secret_key: str = ""
|
|
kilostar_secret_key: str = ""
|
|
kilostar_env: str = "production"
|
|
|
|
|
|
class LogSettings(BaseSettings):
|
|
kilostar_log_level: str = "DEBUG"
|
|
kilostar_log_format: str = ""
|
|
kilostar_log_json: str = ""
|
|
|
|
|
|
class OnebotSettings(BaseSettings):
|
|
onebot_access_token: str = ""
|
|
onebot_http_url: str = "http://127.0.0.1:5700"
|
|
|
|
|
|
class AppSettings(BaseSettings):
|
|
kilostar_mode: str = "distributed"
|
|
kilostar_lang: str = "zh"
|
|
kilostar_cors_origins: str = ""
|
|
kilostar_plugin_dir: str = ""
|
|
kilostar_toolset_dir: str = ""
|
|
kilostar_artifact_dir: str = ""
|
|
|
|
db: DatabaseSettings = Field(default_factory=DatabaseSettings)
|
|
security: SecuritySettings = Field(default_factory=SecuritySettings)
|
|
log: LogSettings = Field(default_factory=LogSettings)
|
|
onebot: OnebotSettings = Field(default_factory=OnebotSettings)
|
|
|
|
model_config = {"env_nested_delimiter": "__"}
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def get_settings() -> AppSettings:
|
|
return AppSettings()
|
|
|
|
|
|
def get_plugin_dir() -> "pathlib.Path":
|
|
"""返回插件根目录路径(包含 tool_plugin/ 和 skill/ 子目录)。
|
|
|
|
优先使用环境变量 KILOSTAR_PLUGIN_DIR,否则默认 <project_root>/data/plugin/。
|
|
"""
|
|
import pathlib
|
|
|
|
custom = get_settings().kilostar_plugin_dir
|
|
if custom:
|
|
return pathlib.Path(custom)
|
|
project_root = pathlib.Path(__file__).parent.parent.parent
|
|
return project_root / "data" / "plugin"
|
|
|
|
|
|
def get_toolset_dir() -> "pathlib.Path":
|
|
"""返回工具集根目录路径(包含各 toolset 子目录,如 base_toolset/)。
|
|
|
|
优先使用环境变量 KILOSTAR_TOOLSET_DIR,否则默认 <project_root>/data/toolset/。
|
|
"""
|
|
import pathlib
|
|
|
|
custom = get_settings().kilostar_toolset_dir
|
|
if custom:
|
|
return pathlib.Path(custom)
|
|
project_root = pathlib.Path(__file__).parent.parent.parent
|
|
return project_root / "data" / "toolset"
|
|
|
|
|
|
def get_artifact_dir() -> "pathlib.Path":
|
|
"""返回工作流产物(agent 通过 send_file 推送的文件)存放根目录。
|
|
|
|
优先使用环境变量 KILOSTAR_ARTIFACT_DIR,否则默认 <project_root>/data/artifact/。
|
|
每个 trace_id 一个子目录,下载链接走 /api/v1/resource/artifact/{trace_id}/{aid}。
|
|
"""
|
|
import pathlib
|
|
|
|
custom = get_settings().kilostar_artifact_dir
|
|
if custom:
|
|
return pathlib.Path(custom)
|
|
project_root = pathlib.Path(__file__).parent.parent.parent
|
|
return project_root / "data" / "artifact"
|