文档阅读区

08 · Repository Layout (Core + Apps + Agent) (v0.5)

v0.4 已定义 Core 单仓 + App 多仓 + tever-agent。
v0.5 新增 Prompt Registry + LLM Gateway 相关目录。


1. tever-core(单仓)推荐结构(v0.5)

tever-core/
  docs/
  backend/
    app/
      api/
        v1/
          ingest/                # v0.4 已有:/ingest/events
          sources/               # v0.4 已有:EventSource 管理 API
          schemas/               # v0.4 已有:Schema Registry API
          prompts/               # v0.5 新增:Prompt Registry API
          llm/                   # v0.5 新增:LLM Gateway API
          views/
          entities/
          rules/
      core/
        prompts/                 # v0.5 新增:Prompt Registry
          models.py
          renderer.py
          validator.py
          pack_loader.py
          pack_installer.py
        llm/                     # v0.5 新增:LLM Gateway
          gateway.py
          providers/
            base.py
            openai.py
            dify.py
            local.py
          context_builder.py
          rate_limiter.py
          cache.py
          retry.py
          validator.py
          config.py
      kernel/
        entities/
        events/
        types/
        views/
        rules/
        projection/
        actions/
          executor.py            # v0.4 已有,v0.5 扩展 AI Actions
          ai_actions.py          # v0.5 新增:AI Actions 实现
        audit/
          models.py              # v0.4 已有,v0.5 扩展 tool_call 字段
          service.py             # v0.4 已有,v0.5 扩展审计记录
      models/
        type_definitions.py
        entities.py
        events.py                # v0.4 已有:EventEnvelopeV1
        event_sources.py         # v0.4 已有
        event_schemas.py         # v0.4 已有
        prompt_templates.py     # v0.5 新增
        alerts.py                # v0.4 已有
        audit_log.py             # v0.4 已有,v0.5 扩展
      app_host/
        installer/
        registries/
          action_registry.py
          tool_registry.py
          schema_registry.py     # v0.4 已有
          rulepack_registry.py   # v0.4 已有
          promptpack_registry.py # v0.5 新增
          source_tpl_registry.py # v0.4 已有
      infra/
        auth/
        notifications/
        storage/
        telemetry/
      workers/
        connectors/              # v0.4 已有:pull connectors
        rule_engine_worker/
        audit_worker/
  sdk/
  scripts/

2. tever-agent(v0.4 已有,v0.5 保持)

v0.4 已定义,v0.5 保持不变。

tever-agent/
  agent/
    collectors/
      gpu/
      system/
    buffer/
    transport/
      http_push.py
    config/
  docker/
  README.md

3. tever-app-(多仓)(v0.5)

tever-app-<appId>/
  app.yaml
  domain/
    events/schemas/              # v0.4 已有:必需(大多数 App)
    events/samples/
    rulepacks/                   # v0.4 已有
    sources/                     # v0.4 已有
    prompts/                     # v0.5 新增:PromptPack
      promptpack.yaml
      templates/                 # 可选:单独的 Prompt 模板文件
    types/
    views/
    rules/
  backend/
  frontend/
  README.md

4. tever-agent 运维与安全基线(v0.4 已有)

v0.4 已定义,v0.5 保持不变。

4.1 配置管理

  • 方式 A(MVP):本地 agent.yaml(由部署者管理)
  • 方式 B(推荐):agent 通过受控 API 拉取配置(仅拉取本 source 的配置)

4.2 可靠性(不丢数据)

  • 本地落盘队列(spool)
  • 重试:指数退避 + 抖动
  • 幂等:每条事件必须有 id,推荐带 dedupKey

4.3 安全基线

  • 认证:token(MVP)或 mTLS(进阶)
  • 最小权限:agent 只允许调用 /ingest/events
  • 事件签名(可选但推荐)

4.4 健康上报

  • agent 周期性上报 agent_heartbeat 事件

5. v0.5 新增目录说明

5.1 backend/app/core/prompts/

Prompt Registry 模块

  • models.py - PromptTemplate 模型
  • renderer.py - Prompt 渲染器(变量替换)
  • validator.py - 输出校验器(JSON Schema)
  • pack_loader.py - PromptPack 加载器
  • pack_installer.py - PromptPack 安装器

5.2 backend/app/core/llm/

LLM Gateway 模块

  • gateway.py - LLM Gateway 核心
  • providers/ - LLM Provider 实现(OpenAI/Dify/本地模型)
  • context_builder.py - Context Pack 组装
  • rate_limiter.py - 限流
  • cache.py - 缓存
  • retry.py - 重试
  • validator.py - 输出校验
  • config.py - 配置管理

5.3 backend/app/kernel/actions/ai_actions.py

AI Actions 实现

  • _execute_invoke_llm_summary
  • _execute_invoke_llm_report
  • _execute_invoke_llm_generate_doc

5.4 apps/{appId}/prompts/

App PromptPack 目录

  • promptpack.yaml - PromptPack 文件
  • templates/ - 可选:单独的 Prompt 模板文件

文档版本: v1.0
最后更新: 2025-12-17