后端:
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 个
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package conv
|
|
|
|
import (
|
|
"github.com/LoveLosita/smartflow/backend/services/runtime/model"
|
|
"github.com/cloudwego/eino/schema"
|
|
)
|
|
|
|
// ToEinoMessages 将数据库模型转换为 Eino 模型
|
|
func ToEinoMessages(dbMsgs []model.ChatHistory) []*schema.Message {
|
|
res := make([]*schema.Message, 0)
|
|
for _, m := range dbMsgs {
|
|
var role schema.RoleType
|
|
switch safeChatHistoryRole(m.Role) {
|
|
case "user":
|
|
role = schema.User
|
|
case "assistant":
|
|
role = schema.Assistant
|
|
default:
|
|
role = schema.System
|
|
}
|
|
msg := &schema.Message{
|
|
Role: role,
|
|
Content: safeChatHistoryText(m.MessageContent),
|
|
ReasoningContent: safeChatHistoryText(m.ReasoningContent),
|
|
}
|
|
// retry 机制已整体下线:历史数据里的 retry_* 列不再回灌到运行期上下文。
|
|
extra := make(map[string]any)
|
|
extra["history_id"] = m.ID
|
|
if m.ReasoningDurationSeconds > 0 {
|
|
extra["reasoning_duration_seconds"] = m.ReasoningDurationSeconds
|
|
}
|
|
if len(extra) > 0 {
|
|
msg.Extra = extra
|
|
}
|
|
res = append(res, msg)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func safeChatHistoryRole(role *string) string {
|
|
if role == nil {
|
|
return ""
|
|
}
|
|
return *role
|
|
}
|
|
|
|
func safeChatHistoryText(text *string) string {
|
|
if text == nil {
|
|
return ""
|
|
}
|
|
return *text
|
|
}
|