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

@@ -0,0 +1,78 @@
// Package respond 承载 gateway HTTP 门面使用的响应适配入口。
//
// 职责边界:
// 1. 只面向 gateway/api 与 gateway/middleware统一 HTTP JSON 写回与错误响应常量的 import 位置;
// 2. 迁移期继续复用根 backend/respond 的响应码和错误语义避免一次性改动服务层、RPC 层和 client 层;
// 3. 不承载任何服务私有业务逻辑,服务代码禁止反向 import backend/gateway/shared/respond。
package respond
import (
"errors"
"net/http"
rootrespond "github.com/LoveLosita/smartflow/backend/shared/respond"
"github.com/gin-gonic/gin"
)
type (
// Response 是 gateway 透传给前端的项目响应码结构。
Response = rootrespond.Response
// FinalResponse 是带 data 字段的统一 HTTP 响应结构。
FinalResponse = rootrespond.FinalResponse
)
var (
Ok = rootrespond.Ok
UserTasksEmpty = rootrespond.UserTasksEmpty
NoOngoingOrUpcomingSchedule = rootrespond.NoOngoingOrUpcomingSchedule
TaskAlreadyDeleted = rootrespond.TaskAlreadyDeleted
WrongParamType = rootrespond.WrongParamType
MissingParam = rootrespond.MissingParam
MissingIdempotencyKey = rootrespond.MissingIdempotencyKey
MissingToken = rootrespond.MissingToken
InvalidClaims = rootrespond.InvalidClaims
ErrUnauthorized = rootrespond.ErrUnauthorized
RequestIsProcessing = rootrespond.RequestIsProcessing
ScheduleConflict = rootrespond.ScheduleConflict
TooManyRequests = rootrespond.TooManyRequests
TokenUsageExceedsLimit = rootrespond.TokenUsageExceedsLimit
ConversationNotFound = rootrespond.ConversationNotFound
MissingConversationID = rootrespond.MissingConversationID
)
// RespWithData 为 gateway HTTP 门面生成带 data 的统一响应体。
//
// 职责边界:
// 1. 只做响应结构组装,不决定 HTTP 状态码;
// 2. 响应码来源仍是根 respond保证迁移前后前端协议不变。
func RespWithData(response Response, data interface{}) FinalResponse {
return rootrespond.RespWithData(response, data)
}
// DealWithError 将项目 error 映射为 HTTP JSON 响应。
//
// 职责边界:
// 1. 只在 gateway HTTP 层写响应;
// 2. 业务错误语义仍由根 respond 统一维护;
// 3. nil error 直接忽略,保持旧 DealWithError 的降级语义。
func DealWithError(c *gin.Context, err error) {
if err == nil {
return
}
var resp Response
if errors.Is(err, UserTasksEmpty) || errors.Is(err, NoOngoingOrUpcomingSchedule) || errors.Is(err, TaskAlreadyDeleted) {
c.JSON(http.StatusOK, err)
return
}
if errors.As(err, &resp) {
c.JSON(resp.HTTPStatus(), resp)
return
}
c.JSON(http.StatusInternalServerError, InternalError(err))
}
// InternalError 生成 500 类响应体,供 gateway 依赖缺失等边缘错误使用。
func InternalError(err error) Response {
return rootrespond.InternalError(err)
}