Version: 0.9.77.dev.260505

后端:
1.阶段 6 CP4/CP5 目录收口与共享边界纯化
- 将 backend 根目录收口为 services、client、gateway、cmd、shared 五个一级目录
- 收拢 bootstrap、inits、infra/kafka、infra/outbox、conv、respond、pkg、middleware,移除根目录旧实现与空目录
- 将 utils 下沉到 services/userauth/internal/auth,将 logic 下沉到 services/schedule/core/planning
- 将迁移期 runtime 桥接实现统一收拢到 services/runtime/{conv,dao,eventsvc,model},删除 shared/legacy 与未再被 import 的旧 service 实现
- 将 gateway/shared/respond 收口为 HTTP/Gin 错误写回适配,shared/respond 仅保留共享错误语义与状态映射
- 将 HTTP IdempotencyMiddleware 与 RateLimitMiddleware 收口到 gateway/middleware
- 将 GormCachePlugin 下沉到 shared/infra/gormcache,将共享 RateLimiter 下沉到 shared/infra/ratelimit,将 agent token budget 下沉到 services/agent/shared
- 删除 InitEino 兼容壳,收缩 cmd/internal/coreinit 仅保留旧组合壳残留域初始化语义
- 更新微服务迁移计划与桌面 checklist,补齐 CP4/CP5 当前切流点、目录终态与验证结果
- 完成 go test ./...、git diff --check 与最终真实 smoke;health、register/login、task/create+get、schedule/today、task-class/list、memory/items、agent chat/meta/timeline/context-stats 全部 200,SSE 合并结果为 CP5_OK 且 [DONE] 只有 1 个
This commit is contained in:
Losita
2026-05-05 23:25:07 +08:00
parent 2a96f4c6f9
commit 3b6fca44a6
226 changed files with 731 additions and 3497 deletions

View File

@@ -7,14 +7,14 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
kafkabus "github.com/LoveLosita/smartflow/backend/infra/kafka"
"github.com/LoveLosita/smartflow/backend/inits"
activeadapters "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/adapters"
activeschedulerdao "github.com/LoveLosita/smartflow/backend/services/active_scheduler/dao"
activeschedulerrpc "github.com/LoveLosita/smartflow/backend/services/active_scheduler/rpc"
activeschedulersv "github.com/LoveLosita/smartflow/backend/services/active_scheduler/sv"
llmservice "github.com/LoveLosita/smartflow/backend/services/llm"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
einoinfra "github.com/LoveLosita/smartflow/backend/shared/infra/eino"
kafkabus "github.com/LoveLosita/smartflow/backend/shared/infra/kafka"
"github.com/spf13/viper"
)
@@ -31,7 +31,7 @@ func main() {
log.Fatalf("failed to connect active-scheduler database: %v", err)
}
aiHub, err := inits.InitEino()
aiHub, err := einoinfra.InitEino()
if err != nil {
log.Fatalf("failed to initialize active-scheduler Eino runtime: %v", err)
}

View File

@@ -7,8 +7,6 @@ import (
"strings"
"time"
rootdao "github.com/LoveLosita/smartflow/backend/dao"
"github.com/LoveLosita/smartflow/backend/model"
activeapplyadapter "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/applyadapter"
activefeedbacklocate "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/feedbacklocate"
activegraph "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/graph"
@@ -18,6 +16,8 @@ import (
activeTrigger "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/trigger"
agentstream "github.com/LoveLosita/smartflow/backend/services/agent/stream"
agentsv "github.com/LoveLosita/smartflow/backend/services/agent/sv"
rootdao "github.com/LoveLosita/smartflow/backend/services/runtime/dao"
"github.com/LoveLosita/smartflow/backend/services/runtime/model"
)
func buildActiveSchedulePreviewConfirmService(activeDAO *rootdao.ActiveScheduleDAO, dryRun *activesvc.DryRunService, scheduleApplyAdapter interface {

View File

@@ -7,8 +7,8 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
agentrpc "github.com/LoveLosita/smartflow/backend/services/agent/rpc"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
"github.com/spf13/viper"
)

View File

@@ -8,19 +8,11 @@ import (
"os"
"strings"
rootdao "github.com/LoveLosita/smartflow/backend/dao"
gatewaymemory "github.com/LoveLosita/smartflow/backend/gateway/client/memory"
gatewayschedule "github.com/LoveLosita/smartflow/backend/gateway/client/schedule"
gatewaytask "github.com/LoveLosita/smartflow/backend/gateway/client/task"
gatewaytaskclass "github.com/LoveLosita/smartflow/backend/gateway/client/taskclass"
gatewayuserauth "github.com/LoveLosita/smartflow/backend/gateway/client/userauth"
kafkabus "github.com/LoveLosita/smartflow/backend/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/infra/outbox"
"github.com/LoveLosita/smartflow/backend/inits"
rootmiddleware "github.com/LoveLosita/smartflow/backend/middleware"
"github.com/LoveLosita/smartflow/backend/model"
rootsvc "github.com/LoveLosita/smartflow/backend/service"
eventsvc "github.com/LoveLosita/smartflow/backend/service/events"
memoryclient "github.com/LoveLosita/smartflow/backend/client/memory"
scheduleclient "github.com/LoveLosita/smartflow/backend/client/schedule"
taskclient "github.com/LoveLosita/smartflow/backend/client/task"
taskclassclient "github.com/LoveLosita/smartflow/backend/client/taskclass"
userauthclient "github.com/LoveLosita/smartflow/backend/client/userauth"
activeadapters "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/adapters"
activefeedbacklocate "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/feedbacklocate"
activegraph "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/graph"
@@ -35,6 +27,19 @@ import (
memoryobserve "github.com/LoveLosita/smartflow/backend/services/memory/observe"
ragservice "github.com/LoveLosita/smartflow/backend/services/rag"
ragconfig "github.com/LoveLosita/smartflow/backend/services/rag/config"
rootdao "github.com/LoveLosita/smartflow/backend/services/runtime/dao"
eventsvc "github.com/LoveLosita/smartflow/backend/services/runtime/eventsvc"
"github.com/LoveLosita/smartflow/backend/services/runtime/model"
scheduledao "github.com/LoveLosita/smartflow/backend/services/schedule/dao"
schedulesv "github.com/LoveLosita/smartflow/backend/services/schedule/sv"
taskdao "github.com/LoveLosita/smartflow/backend/services/task/dao"
tasksv "github.com/LoveLosita/smartflow/backend/services/task/sv"
einoinfra "github.com/LoveLosita/smartflow/backend/shared/infra/eino"
gormcache "github.com/LoveLosita/smartflow/backend/shared/infra/gormcache"
kafkabus "github.com/LoveLosita/smartflow/backend/shared/infra/kafka"
mysqlinfra "github.com/LoveLosita/smartflow/backend/shared/infra/mysql"
outboxinfra "github.com/LoveLosita/smartflow/backend/shared/infra/outbox"
redisinfra "github.com/LoveLosita/smartflow/backend/shared/infra/redis"
"github.com/LoveLosita/smartflow/backend/shared/ports"
"github.com/go-redis/redis/v8"
"github.com/spf13/viper"
@@ -48,7 +53,7 @@ type agentRuntime struct {
repoManager *rootdao.RepoManager
agentRepo *rootdao.AgentDAO
cacheRepo *rootdao.CacheDAO
userAuthClient *gatewayuserauth.Client
userAuthClient *userauthclient.Client
service *agentsv.AgentService
workersStarted bool
}
@@ -59,7 +64,7 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
return nil, fmt.Errorf("connect agent database failed: %w", err)
}
redisClient, err := inits.OpenRedisFromConfig()
redisClient, err := redisinfra.OpenRedisFromConfig()
if err != nil {
return nil, fmt.Errorf("connect agent redis failed: %w", err)
}
@@ -69,7 +74,7 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
}
cacheRepo := rootdao.NewCacheDAO(redisClient)
if err = db.Use(rootmiddleware.NewGormCachePlugin(cacheRepo)); err != nil {
if err = db.Use(gormcache.NewGormCachePlugin(cacheRepo)); err != nil {
return fail(fmt.Errorf("initialize agent cache deleter failed: %w", err))
}
@@ -94,8 +99,9 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
manager := rootdao.NewManager(db)
agentRepo := rootdao.NewAgentDAO(db)
taskRepo := rootdao.NewTaskDAO(db)
taskServiceRepo := taskdao.NewTaskDAO(db)
taskClassRepo := rootdao.NewTaskClassDAO(db)
scheduleRepo := rootdao.NewScheduleDAO(db)
scheduleServiceRepo := scheduledao.NewScheduleDAO(db)
agentCacheRepo := rootdao.NewAgentCache(redisClient)
outboxRepo := outboxinfra.NewRepository(db)
@@ -110,9 +116,9 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
eventPublisher := buildAgentOutboxPublisher(outboxRepo)
taskOutboxPublisher := buildTaskOutboxPublisher(outboxRepo)
var userAuthClient *gatewayuserauth.Client
var userAuthClient *userauthclient.Client
if eventBus != nil {
userAuthClient, err = gatewayuserauth.NewClient(gatewayuserauth.ClientConfig{
userAuthClient, err = userauthclient.NewClient(userauthclient.ClientConfig{
Endpoints: viper.GetStringSlice("userauth.rpc.endpoints"),
Target: viper.GetString("userauth.rpc.target"),
Timeout: viper.GetDuration("userauth.rpc.timeout"),
@@ -122,7 +128,7 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
}
}
taskClient, err := gatewaytask.NewClient(gatewaytask.ClientConfig{
taskClient, err := taskclient.NewClient(taskclient.ClientConfig{
Endpoints: viper.GetStringSlice("task.rpc.endpoints"),
Target: viper.GetString("task.rpc.target"),
Timeout: viper.GetDuration("task.rpc.timeout"),
@@ -130,7 +136,7 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
if err != nil {
return fail(fmt.Errorf("initialize task zrpc client failed: %w", err))
}
taskClassClient, err := gatewaytaskclass.NewClient(gatewaytaskclass.ClientConfig{
taskClassClient, err := taskclassclient.NewClient(taskclassclient.ClientConfig{
Endpoints: viper.GetStringSlice("taskClass.rpc.endpoints"),
Target: viper.GetString("taskClass.rpc.target"),
Timeout: viper.GetDuration("taskClass.rpc.timeout"),
@@ -138,7 +144,7 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
if err != nil {
return fail(fmt.Errorf("initialize task-class zrpc client failed: %w", err))
}
scheduleClient, err := gatewayschedule.NewClient(gatewayschedule.ClientConfig{
scheduleClient, err := scheduleclient.NewClient(scheduleclient.ClientConfig{
Endpoints: viper.GetStringSlice("schedule.rpc.endpoints"),
Target: viper.GetString("schedule.rpc.target"),
Timeout: viper.GetDuration("schedule.rpc.timeout"),
@@ -146,7 +152,7 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
if err != nil {
return fail(fmt.Errorf("initialize schedule zrpc client failed: %w", err))
}
memoryClient, err := gatewaymemory.NewClient(gatewaymemory.ClientConfig{
memoryClient, err := memoryclient.NewClient(memoryclient.ClientConfig{
Endpoints: viper.GetStringSlice("memory.rpc.endpoints"),
Target: viper.GetString("memory.rpc.target"),
Timeout: viper.GetDuration("memory.rpc.timeout"),
@@ -155,9 +161,9 @@ func buildAgentRuntime(ctx context.Context) (*agentRuntime, error) {
return fail(fmt.Errorf("initialize memory zrpc client failed: %w", err))
}
taskService := rootsvc.NewTaskService(taskRepo, cacheRepo, taskOutboxPublisher)
taskService := tasksv.NewTaskService(taskServiceRepo, cacheRepo, taskOutboxPublisher)
taskService.SetActiveScheduleDAO(manager.ActiveSchedule)
scheduleService := rootsvc.NewScheduleService(scheduleRepo, taskClassRepo, manager, cacheRepo)
scheduleService := schedulesv.NewScheduleService(scheduleServiceRepo, taskClassRepo, manager, cacheRepo)
agentService := agentsv.NewAgentService(
llmService,
agentRepo,
@@ -286,7 +292,7 @@ func (r *agentRuntime) close() {
}
func openAgentDBFromConfig() (*gorm.DB, error) {
db, err := inits.OpenDBFromConfig()
db, err := mysqlinfra.OpenDBFromConfig()
if err != nil {
return nil, err
}
@@ -364,7 +370,7 @@ func ensureAgentRuntimeDependencyTables(db *gorm.DB) error {
}
func buildAgentLLMService() (*llmservice.Service, error) {
aiHub, err := inits.InitEino()
aiHub, err := einoinfra.InitEino()
if err != nil {
return nil, err
}

View File

@@ -7,12 +7,12 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
rootdao "github.com/LoveLosita/smartflow/backend/dao"
coursedao "github.com/LoveLosita/smartflow/backend/services/course/dao"
courserpc "github.com/LoveLosita/smartflow/backend/services/course/rpc"
coursesv "github.com/LoveLosita/smartflow/backend/services/course/sv"
llmservice "github.com/LoveLosita/smartflow/backend/services/llm"
rootdao "github.com/LoveLosita/smartflow/backend/services/runtime/dao"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
"github.com/spf13/viper"
)

View File

@@ -0,0 +1,144 @@
package coreinit
import (
"fmt"
"log"
"github.com/LoveLosita/smartflow/backend/services/runtime/model"
mysqlinfra "github.com/LoveLosita/smartflow/backend/shared/infra/mysql"
outboxinfra "github.com/LoveLosita/smartflow/backend/shared/infra/outbox"
"gorm.io/gorm"
)
// autoMigrateCoreModels 只迁移仍留在当前单体进程内的业务表。
//
// 职责边界:
// 1. 负责 agent / task / schedule / memory 等尚未独立拆出的表;
// 2. 不负责 users、notification_records、JWT、黑名单、token 额度等已拆服务表;
// 3. user/auth 与 notification 表由各自独立进程在自己的 DAO 初始化阶段迁移,避免 all 启动时跨服务碰核心表。
func autoMigrateCoreModels(db *gorm.DB) error {
models := []any{
&model.AgentChat{},
&model.ChatHistory{},
&model.AgentTimelineEvent{},
&model.Task{},
&model.TaskClass{},
&model.TaskClassItem{},
&model.ScheduleEvent{},
&model.Schedule{},
&model.ActiveScheduleJob{},
&model.ActiveScheduleTrigger{},
&model.ActiveSchedulePreview{},
&model.AgentScheduleState{},
&model.ActiveScheduleSession{},
&model.AgentStateSnapshotRecord{},
&model.MemoryItem{},
&model.MemoryJob{},
&model.MemoryAuditLog{},
&model.MemoryUserSetting{},
}
for _, m := range models {
if err := db.AutoMigrate(m); err != nil {
return fmt.Errorf("auto migrate failed for %T: %w", m, err)
}
}
if err := autoMigrateOutboxTables(db); err != nil {
return err
}
if err := backfillAutoMigrateData(db); err != nil {
return err
}
return nil
}
// autoMigrateOutboxTables 按服务目录一次性创建各服务的 outbox 物理表。
//
// 职责边界:
// 1. 只创建 outbox 目录,不改写业务表;
// 2. 每张表都复用同一套模型结构,保证字段和索引一致;
// 3. 这里显式列出服务目录,避免把共享单表误当成终态。
func autoMigrateOutboxTables(db *gorm.DB) error {
// 1. 这里必须按服务目录读取最终生效的 table 名,而不能只看默认内置映射。
// 2. 这样即使后续通过配置覆盖 outbox.services.*.table启动建表也会和运行时写入保持一致。
for _, serviceName := range outboxinfra.ServiceNames() {
cfg, ok := outboxinfra.ResolveServiceConfig(serviceName)
if !ok {
return fmt.Errorf("resolve outbox config failed for service %s", serviceName)
}
if err := db.Table(cfg.TableName).AutoMigrate(&model.AgentOutboxMessage{}); err != nil {
return fmt.Errorf("auto migrate outbox table failed for %s (%s): %w", cfg.Name, cfg.TableName, err)
}
}
return nil
}
// backfillAutoMigrateData 补齐 AutoMigrate 无法表达的条件回填。
//
// 职责边界:
// 1. 只处理新增列上线后的兼容数据修复,不替代业务迁移系统;
// 2. 当前仅回填历史动态任务日程来源,确保旧的 type=task 记录按 task_item 解释;
// 3. 失败时直接返回错误,避免服务在 schema 半迁移状态下继续启动。
func backfillAutoMigrateData(db *gorm.DB) error {
// 1. AutoMigrate 只能新增列和默认值,不能表达"仅 type=task 时回填"。
// 2. 这里把历史任务日程显式标记为 task_item避免后续主动调度读取 rel_id 时误判来源。
// 3. 新增 task_pool 正式落库仍必须由 apply 链路显式写 task_source_type=task_pool。
result := db.Exec(
"UPDATE schedule_events SET task_source_type = ? WHERE type = ? AND (task_source_type IS NULL OR task_source_type = '')",
"task_item",
"task",
)
if result.Error != nil {
return fmt.Errorf("backfill schedule_events.task_source_type failed: %w", result.Error)
}
return nil
}
// OpenDBFromConfig 只按配置创建 MySQL 连接,不执行任何自动迁移。
//
// 职责边界:
// 1. 负责把 viper 中的 database 配置转换成 *gorm.DB
// 2. 不负责选择要迁移哪些模型,迁移入口必须由具体服务显式调用;
// 3. 调用方负责决定这是单体残留域、user/auth 还是后续新服务的连接。
func OpenDBFromConfig() (*gorm.DB, error) {
return mysqlinfra.OpenDBFromConfig()
}
// AutoMigrateCoreStorage 执行当前单体残留域拥有的 schema 初始化。
//
// 职责边界:
// 1. 只迁移当前 all/api/worker 仍直接拥有的表和这些域的 outbox 表;
// 2. 不迁移 userauth.User避免 gateway/all 在阶段 2 之后继续直接管理用户核心表;
// 3. 回填逻辑仍保留在当前域内,因为 schedule_events 仍属于单体残留域。
func AutoMigrateCoreStorage(db *gorm.DB) error {
if err := autoMigrateCoreModels(db); err != nil {
return err
}
return nil
}
// ConnectCoreDB 创建当前单体残留域的 MySQL 连接,并执行该域自己的迁移。
//
// 迁移期约束:
// 1. all/api/worker 仍需要这条入口来承载尚未拆出的业务域;
// 2. 已拆出的 user/auth 不再通过这里迁移;
// 3. 后续每拆出一个服务,就从 autoMigrateCoreModels 中移走对应模型。
func ConnectCoreDB() (*gorm.DB, error) {
db, err := OpenDBFromConfig()
if err != nil {
return nil, err
}
if err = AutoMigrateCoreStorage(db); err != nil {
return nil, err
}
log.Println("Database connected successfully")
log.Println("Database auto migration completed")
return db, nil
}
// ConnectDB 保留历史兼容入口,新的装配代码应优先调用 ConnectCoreDB。
func ConnectDB() (*gorm.DB, error) {
return ConnectCoreDB()
}

View File

@@ -0,0 +1,32 @@
package coreinit
import (
"log"
redisinfra "github.com/LoveLosita/smartflow/backend/shared/infra/redis"
"github.com/go-redis/redis/v8"
)
// OpenRedisFromConfig 只创建 Redis client 并做连通性校验。
//
// 职责边界:
// 1. 负责当前调用方声明需要 Redis 时的连接初始化;
// 2. 不承载 user/auth 黑名单、token 额度等业务语义,那些语义已经收进 userauth 服务;
// 3. 返回 error 给服务入口统一处理,避免基础设施包直接 log.Fatal 终止进程。
func OpenRedisFromConfig() (*redis.Client, error) {
return redisinfra.OpenRedisFromConfig()
}
// InitCoreRedis 初始化当前单体残留域使用的 Redis 连接。
func InitCoreRedis() (*redis.Client, error) {
return OpenRedisFromConfig()
}
// InitRedis 保留历史兼容入口,新的装配代码应优先使用 InitCoreRedis。
func InitRedis() *redis.Client {
rdb, err := InitCoreRedis()
if err != nil {
log.Fatalf("Redis 连接失败: %v", err)
}
return rdb
}

View File

@@ -8,10 +8,6 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
kafkabus "github.com/LoveLosita/smartflow/backend/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/infra/outbox"
"github.com/LoveLosita/smartflow/backend/inits"
llmservice "github.com/LoveLosita/smartflow/backend/services/llm"
memorymodule "github.com/LoveLosita/smartflow/backend/services/memory"
memorydao "github.com/LoveLosita/smartflow/backend/services/memory/dao"
@@ -20,6 +16,10 @@ import (
memorysv "github.com/LoveLosita/smartflow/backend/services/memory/sv"
ragservice "github.com/LoveLosita/smartflow/backend/services/rag"
ragconfig "github.com/LoveLosita/smartflow/backend/services/rag/config"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
einoinfra "github.com/LoveLosita/smartflow/backend/shared/infra/eino"
kafkabus "github.com/LoveLosita/smartflow/backend/shared/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/shared/infra/outbox"
"github.com/spf13/viper"
)
@@ -99,7 +99,7 @@ func main() {
// 2. 当前启动入口与 cmd/start.go / cmd/active-scheduler 都需要 Eino 初始化,后续若出现第三处重复装配,应抽公共 bootstrap
// 3. 返回 ProClient 是因为现有 memory.Module 只需要 llmservice.Client不需要完整 Service。
func buildMemoryLLMClient() (*llmservice.Client, error) {
aiHub, err := inits.InitEino()
aiHub, err := einoinfra.InitEino()
if err != nil {
return nil, err
}

View File

@@ -7,12 +7,12 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
kafkabus "github.com/LoveLosita/smartflow/backend/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/infra/outbox"
notificationdao "github.com/LoveLosita/smartflow/backend/services/notification/dao"
notificationrpc "github.com/LoveLosita/smartflow/backend/services/notification/rpc"
notificationsv "github.com/LoveLosita/smartflow/backend/services/notification/sv"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
kafkabus "github.com/LoveLosita/smartflow/backend/shared/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/shared/infra/outbox"
"github.com/spf13/viper"
)

View File

@@ -7,13 +7,13 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
rootdao "github.com/LoveLosita/smartflow/backend/dao"
rootmiddleware "github.com/LoveLosita/smartflow/backend/middleware"
rootdao "github.com/LoveLosita/smartflow/backend/services/runtime/dao"
"github.com/LoveLosita/smartflow/backend/services/schedule/core/applyadapter"
scheduledao "github.com/LoveLosita/smartflow/backend/services/schedule/dao"
schedulerpc "github.com/LoveLosita/smartflow/backend/services/schedule/rpc"
schedulesv "github.com/LoveLosita/smartflow/backend/services/schedule/sv"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
gormcache "github.com/LoveLosita/smartflow/backend/shared/infra/gormcache"
"github.com/spf13/viper"
)
@@ -36,7 +36,7 @@ func main() {
defer redisClient.Close()
cacheRepo := rootdao.NewCacheDAO(redisClient)
if err := db.Use(rootmiddleware.NewGormCachePlugin(cacheRepo)); err != nil {
if err := db.Use(gormcache.NewGormCachePlugin(cacheRepo)); err != nil {
log.Fatalf("failed to initialize schedule cache deleter: %v", err)
}

View File

@@ -11,27 +11,18 @@ import (
"syscall"
"time"
"github.com/LoveLosita/smartflow/backend/bootstrap"
"github.com/LoveLosita/smartflow/backend/dao"
activeschedulerclient "github.com/LoveLosita/smartflow/backend/client/activescheduler"
agentclient "github.com/LoveLosita/smartflow/backend/client/agent"
courseclient "github.com/LoveLosita/smartflow/backend/client/course"
memoryclient "github.com/LoveLosita/smartflow/backend/client/memory"
notificationclient "github.com/LoveLosita/smartflow/backend/client/notification"
scheduleclient "github.com/LoveLosita/smartflow/backend/client/schedule"
taskclient "github.com/LoveLosita/smartflow/backend/client/task"
taskclassclient "github.com/LoveLosita/smartflow/backend/client/taskclass"
userauthclient "github.com/LoveLosita/smartflow/backend/client/userauth"
coreinit "github.com/LoveLosita/smartflow/backend/cmd/internal/coreinit"
"github.com/LoveLosita/smartflow/backend/gateway/api"
gatewayactivescheduler "github.com/LoveLosita/smartflow/backend/gateway/client/activescheduler"
gatewayagent "github.com/LoveLosita/smartflow/backend/gateway/client/agent"
gatewaycourse "github.com/LoveLosita/smartflow/backend/gateway/client/course"
gatewaymemory "github.com/LoveLosita/smartflow/backend/gateway/client/memory"
gatewaynotification "github.com/LoveLosita/smartflow/backend/gateway/client/notification"
gatewayschedule "github.com/LoveLosita/smartflow/backend/gateway/client/schedule"
gatewaytask "github.com/LoveLosita/smartflow/backend/gateway/client/task"
gatewaytaskclass "github.com/LoveLosita/smartflow/backend/gateway/client/taskclass"
gatewayuserauth "github.com/LoveLosita/smartflow/backend/gateway/client/userauth"
gatewayrouter "github.com/LoveLosita/smartflow/backend/gateway/router"
kafkabus "github.com/LoveLosita/smartflow/backend/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/infra/outbox"
"github.com/LoveLosita/smartflow/backend/inits"
"github.com/LoveLosita/smartflow/backend/middleware"
"github.com/LoveLosita/smartflow/backend/model"
"github.com/LoveLosita/smartflow/backend/pkg"
"github.com/LoveLosita/smartflow/backend/service"
eventsvc "github.com/LoveLosita/smartflow/backend/service/events"
activeadapters "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/adapters"
activeapplyadapter "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/applyadapter"
activefeedbacklocate "github.com/LoveLosita/smartflow/backend/services/active_scheduler/core/feedbacklocate"
@@ -44,12 +35,27 @@ import (
agentsv "github.com/LoveLosita/smartflow/backend/services/agent/sv"
agenttools "github.com/LoveLosita/smartflow/backend/services/agent/tools"
"github.com/LoveLosita/smartflow/backend/services/agent/tools/web"
coursedao "github.com/LoveLosita/smartflow/backend/services/course/dao"
coursesv "github.com/LoveLosita/smartflow/backend/services/course/sv"
llmservice "github.com/LoveLosita/smartflow/backend/services/llm"
"github.com/LoveLosita/smartflow/backend/services/memory"
memorymodel "github.com/LoveLosita/smartflow/backend/services/memory/model"
memoryobserve "github.com/LoveLosita/smartflow/backend/services/memory/observe"
ragservice "github.com/LoveLosita/smartflow/backend/services/rag"
ragconfig "github.com/LoveLosita/smartflow/backend/services/rag/config"
"github.com/LoveLosita/smartflow/backend/services/runtime/dao"
eventsvc "github.com/LoveLosita/smartflow/backend/services/runtime/eventsvc"
"github.com/LoveLosita/smartflow/backend/services/runtime/model"
scheduledao "github.com/LoveLosita/smartflow/backend/services/schedule/dao"
schedulesv "github.com/LoveLosita/smartflow/backend/services/schedule/sv"
taskdao "github.com/LoveLosita/smartflow/backend/services/task/dao"
tasksv "github.com/LoveLosita/smartflow/backend/services/task/sv"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
einoinfra "github.com/LoveLosita/smartflow/backend/shared/infra/eino"
gormcache "github.com/LoveLosita/smartflow/backend/shared/infra/gormcache"
kafkabus "github.com/LoveLosita/smartflow/backend/shared/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/shared/infra/outbox"
ratelimit "github.com/LoveLosita/smartflow/backend/shared/infra/ratelimit"
"github.com/LoveLosita/smartflow/backend/shared/ports"
"github.com/go-redis/redis/v8"
"github.com/spf13/viper"
@@ -75,9 +81,9 @@ type appRuntime struct {
agentCache *dao.AgentCache
manager *dao.RepoManager
outboxRepo *outboxinfra.Repository
limiter *pkg.RateLimiter
limiter *ratelimit.RateLimiter
handlers *api.ApiHandlers
userAuthClient *gatewayuserauth.Client
userAuthClient *userauthclient.Client
}
// loadConfig 锻炼?
@@ -154,23 +160,23 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
return nil, err
}
db, err := inits.ConnectCoreDB()
db, err := coreinit.ConnectCoreDB()
if err != nil {
return nil, fmt.Errorf("failed to connect to database: %w", err)
}
rdb, err := inits.InitCoreRedis()
rdb, err := coreinit.InitCoreRedis()
if err != nil {
return nil, fmt.Errorf("failed to connect to redis: %w", err)
}
limiter := pkg.NewRateLimiter(rdb)
limiter := ratelimit.NewRateLimiter(rdb)
// DAO 层初始化。
cacheRepo := dao.NewCacheDAO(rdb)
_ = db.Use(middleware.NewGormCachePlugin(cacheRepo))
_ = db.Use(gormcache.NewGormCachePlugin(cacheRepo))
// Service 层初始化。
userAuthClient, err := gatewayuserauth.NewClient(gatewayuserauth.ClientConfig{
userAuthClient, err := userauthclient.NewClient(userauthclient.ClientConfig{
Endpoints: viper.GetStringSlice("userauth.rpc.endpoints"),
Target: viper.GetString("userauth.rpc.target"),
Timeout: viper.GetDuration("userauth.rpc.timeout"),
@@ -178,7 +184,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize userauth zrpc client: %w", err)
}
notificationClient, err := gatewaynotification.NewClient(gatewaynotification.ClientConfig{
notificationClient, err := notificationclient.NewClient(notificationclient.ClientConfig{
Endpoints: viper.GetStringSlice("notification.rpc.endpoints"),
Target: viper.GetString("notification.rpc.target"),
Timeout: viper.GetDuration("notification.rpc.timeout"),
@@ -186,7 +192,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize notification zrpc client: %w", err)
}
scheduleClient, err := gatewayschedule.NewClient(gatewayschedule.ClientConfig{
scheduleClient, err := scheduleclient.NewClient(scheduleclient.ClientConfig{
Endpoints: viper.GetStringSlice("schedule.rpc.endpoints"),
Target: viper.GetString("schedule.rpc.target"),
Timeout: viper.GetDuration("schedule.rpc.timeout"),
@@ -194,7 +200,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize schedule zrpc client: %w", err)
}
taskClient, err := gatewaytask.NewClient(gatewaytask.ClientConfig{
taskClient, err := taskclient.NewClient(taskclient.ClientConfig{
Endpoints: viper.GetStringSlice("task.rpc.endpoints"),
Target: viper.GetString("task.rpc.target"),
Timeout: viper.GetDuration("task.rpc.timeout"),
@@ -202,7 +208,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize task zrpc client: %w", err)
}
taskClassClient, err := gatewaytaskclass.NewClient(gatewaytaskclass.ClientConfig{
taskClassClient, err := taskclassclient.NewClient(taskclassclient.ClientConfig{
Endpoints: viper.GetStringSlice("taskClass.rpc.endpoints"),
Target: viper.GetString("taskClass.rpc.target"),
Timeout: viper.GetDuration("taskClass.rpc.timeout"),
@@ -210,7 +216,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize task-class zrpc client: %w", err)
}
courseClient, err := gatewaycourse.NewClient(gatewaycourse.ClientConfig{
courseClient, err := courseclient.NewClient(courseclient.ClientConfig{
Endpoints: viper.GetStringSlice("course.rpc.endpoints"),
Target: viper.GetString("course.rpc.target"),
Timeout: viper.GetDuration("course.rpc.timeout"),
@@ -219,7 +225,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize course zrpc client: %w", err)
}
memoryClient, err := gatewaymemory.NewClient(gatewaymemory.ClientConfig{
memoryClient, err := memoryclient.NewClient(memoryclient.ClientConfig{
Endpoints: viper.GetStringSlice("memory.rpc.endpoints"),
Target: viper.GetString("memory.rpc.target"),
Timeout: viper.GetDuration("memory.rpc.timeout"),
@@ -227,7 +233,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize memory zrpc client: %w", err)
}
agentRPCClient, err := gatewayagent.NewClient(gatewayagent.ClientConfig{
agentRPCClient, err := agentclient.NewClient(agentclient.ClientConfig{
Endpoints: viper.GetStringSlice("agent.rpc.endpoints"),
Target: viper.GetString("agent.rpc.target"),
Timeout: viper.GetDuration("agent.rpc.timeout"),
@@ -235,7 +241,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if err != nil {
return nil, fmt.Errorf("failed to initialize agent zrpc client: %w", err)
}
activeSchedulerClient, err := gatewayactivescheduler.NewClient(gatewayactivescheduler.ClientConfig{
activeSchedulerClient, err := activeschedulerclient.NewClient(activeschedulerclient.ClientConfig{
Endpoints: viper.GetStringSlice("activeScheduler.rpc.endpoints"),
Target: viper.GetString("activeScheduler.rpc.target"),
Timeout: viper.GetDuration("activeScheduler.rpc.timeout"),
@@ -251,7 +257,7 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
if shouldBuildGatewayAgentFallback() {
log.Println("Gateway agent RPC fallback is enabled; building local AgentService compatibility path")
aiHub, err := inits.InitEino()
aiHub, err := einoinfra.InitEino()
if err != nil {
return nil, fmt.Errorf("failed to initialize Eino: %w", err)
}
@@ -273,8 +279,9 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
agentCacheRepo = dao.NewAgentCache(rdb)
taskRepo := dao.NewTaskDAO(db)
taskServiceRepo := taskdao.NewTaskDAO(db)
taskClassRepo := dao.NewTaskClassDAO(db)
scheduleRepo := dao.NewScheduleDAO(db)
scheduleServiceRepo := scheduledao.NewScheduleDAO(db)
manager = dao.NewManager(db)
agentRepo = dao.NewAgentDAO(db)
outboxRepo = outboxinfra.NewRepository(db)
@@ -286,9 +293,9 @@ func buildRuntime(ctx context.Context) (*appRuntime, error) {
return nil, fmt.Errorf("failed to register task outbox route: %w", err)
}
taskOutboxPublisher := buildTaskOutboxPublisher(outboxRepo)
taskSv := service.NewTaskService(taskRepo, cacheRepo, taskOutboxPublisher)
taskSv := tasksv.NewTaskService(taskServiceRepo, cacheRepo, taskOutboxPublisher)
taskSv.SetActiveScheduleDAO(manager.ActiveSchedule)
scheduleService := service.NewScheduleService(scheduleRepo, taskClassRepo, manager, cacheRepo)
scheduleService := schedulesv.NewScheduleService(scheduleServiceRepo, taskClassRepo, manager, cacheRepo)
agentService = agentsv.NewAgentService(
llmService,
agentRepo,
@@ -488,13 +495,13 @@ func (p *repositoryOutboxPublisher) Publish(ctx context.Context, req outboxinfra
return err
}
func buildCourseService(llmService *llmservice.Service, courseRepo *dao.CourseDAO, scheduleRepo *dao.ScheduleDAO) *service.CourseService {
func buildCourseService(llmService *llmservice.Service, courseRepo *coursedao.CourseDAO, scheduleRepo *dao.ScheduleDAO) *coursesv.CourseService {
courseImageResponsesClient := llmService.CourseImageResponsesClient()
return service.NewCourseService(
return coursesv.NewCourseService(
courseRepo,
scheduleRepo,
courseImageResponsesClient,
service.NewCourseImageParseConfig(
coursesv.NewCourseImageParseConfig(
viper.GetInt64("courseImport.maxImageBytes"),
viper.GetInt("courseImport.maxTokens"),
),
@@ -827,7 +834,7 @@ func buildAPIHandlers(
courseClient ports.CourseCommandClient,
scheduleClient ports.ScheduleCommandClient,
agentService *agentsv.AgentService,
agentRPCClient *gatewayagent.Client,
agentRPCClient *agentclient.Client,
memoryClient ports.MemoryCommandClient,
activeSchedulerClient ports.ActiveSchedulerCommandClient,
notificationClient ports.NotificationCommandClient,

View File

@@ -7,12 +7,12 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
rootdao "github.com/LoveLosita/smartflow/backend/dao"
rootmiddleware "github.com/LoveLosita/smartflow/backend/middleware"
rootdao "github.com/LoveLosita/smartflow/backend/services/runtime/dao"
taskclassdao "github.com/LoveLosita/smartflow/backend/services/task_class/dao"
taskclassrpc "github.com/LoveLosita/smartflow/backend/services/task_class/rpc"
taskclasssv "github.com/LoveLosita/smartflow/backend/services/task_class/sv"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
gormcache "github.com/LoveLosita/smartflow/backend/shared/infra/gormcache"
"github.com/spf13/viper"
)
@@ -35,7 +35,7 @@ func main() {
defer redisClient.Close()
cacheRepo := rootdao.NewCacheDAO(redisClient)
if err := db.Use(rootmiddleware.NewGormCachePlugin(cacheRepo)); err != nil {
if err := db.Use(gormcache.NewGormCachePlugin(cacheRepo)); err != nil {
log.Fatalf("failed to initialize task-class cache deleter: %v", err)
}

View File

@@ -7,14 +7,14 @@ import (
"os/signal"
"syscall"
"github.com/LoveLosita/smartflow/backend/bootstrap"
rootdao "github.com/LoveLosita/smartflow/backend/dao"
kafkabus "github.com/LoveLosita/smartflow/backend/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/infra/outbox"
rootmiddleware "github.com/LoveLosita/smartflow/backend/middleware"
rootdao "github.com/LoveLosita/smartflow/backend/services/runtime/dao"
taskdao "github.com/LoveLosita/smartflow/backend/services/task/dao"
taskrpc "github.com/LoveLosita/smartflow/backend/services/task/rpc"
tasksv "github.com/LoveLosita/smartflow/backend/services/task/sv"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
gormcache "github.com/LoveLosita/smartflow/backend/shared/infra/gormcache"
kafkabus "github.com/LoveLosita/smartflow/backend/shared/infra/kafka"
outboxinfra "github.com/LoveLosita/smartflow/backend/shared/infra/outbox"
"github.com/spf13/viper"
)
@@ -37,7 +37,7 @@ func main() {
defer redisClient.Close()
cacheRepo := rootdao.NewCacheDAO(redisClient)
if err := db.Use(rootmiddleware.NewGormCachePlugin(cacheRepo)); err != nil {
if err := db.Use(gormcache.NewGormCachePlugin(cacheRepo)); err != nil {
log.Fatalf("failed to initialize task cache deleter: %v", err)
}

View File

@@ -3,10 +3,10 @@ package main
import (
"log"
"github.com/LoveLosita/smartflow/backend/bootstrap"
userauthdao "github.com/LoveLosita/smartflow/backend/services/userauth/dao"
userauthrpc "github.com/LoveLosita/smartflow/backend/services/userauth/rpc"
userauthsv "github.com/LoveLosita/smartflow/backend/services/userauth/sv"
"github.com/LoveLosita/smartflow/backend/shared/infra/bootstrap"
"github.com/spf13/viper"
)