Version: 0.9.75.dev.260505
后端: 1.收口阶段 6 agent 结构迁移,将 newAgent 内核与 agentsvc 编排层迁入 services/agent - 切换 Agent 启动装配与 HTTP handler 直连 agent sv,移除旧 service agent bridge - 补齐 Agent 对 memory、task、task-class、schedule 的 RPC 适配与契约字段 - 扩展 schedule、task、task-class RPC/contract 支撑 Agent 查询、写入与 provider 切流 - 更新迁移文档、README 与相关注释,明确 agent 当前切流点和剩余 memory 迁移面
This commit is contained in:
@@ -108,6 +108,18 @@ func (h *Handler) SmartPlanningMulti(ctx context.Context, req *pb.SmartPlanningM
|
||||
return jsonResponse(data, err)
|
||||
}
|
||||
|
||||
func (h *Handler) GetAgentWeekSchedule(ctx context.Context, req *pb.JSONRequest) (*pb.JSONResponse, error) {
|
||||
if err := h.ensureReady(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var contractReq schedulecontracts.AgentScheduleWeekRequest
|
||||
if err := json.Unmarshal(req.PayloadJson, &contractReq); err != nil {
|
||||
return nil, grpcErrorFromServiceError(respond.WrongParamType)
|
||||
}
|
||||
data, err := h.svc.GetAgentWeekSchedule(ctx, contractReq)
|
||||
return jsonResponse(data, err)
|
||||
}
|
||||
|
||||
func (h *Handler) GetScheduleFactsByWindow(ctx context.Context, req *pb.JSONRequest) (*pb.JSONResponse, error) {
|
||||
if err := h.ensureReady(req); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -18,6 +18,7 @@ const (
|
||||
Schedule_RevokeTaskItem_FullMethodName = "/smartflow.schedule.Schedule/RevokeTaskItem"
|
||||
Schedule_SmartPlanning_FullMethodName = "/smartflow.schedule.Schedule/SmartPlanning"
|
||||
Schedule_SmartPlanningMulti_FullMethodName = "/smartflow.schedule.Schedule/SmartPlanningMulti"
|
||||
Schedule_GetAgentWeekSchedule_FullMethodName = "/smartflow.schedule.Schedule/GetAgentWeekSchedule"
|
||||
Schedule_GetScheduleFactsByWindow_FullMethodName = "/smartflow.schedule.Schedule/GetScheduleFactsByWindow"
|
||||
Schedule_GetFeedbackSignal_FullMethodName = "/smartflow.schedule.Schedule/GetFeedbackSignal"
|
||||
Schedule_ApplyActiveScheduleChanges_FullMethodName = "/smartflow.schedule.Schedule/ApplyActiveScheduleChanges"
|
||||
@@ -33,6 +34,7 @@ type ScheduleClient interface {
|
||||
RevokeTaskItem(ctx context.Context, in *RevokeTaskItemRequest, opts ...grpc.CallOption) (*StatusResponse, error)
|
||||
SmartPlanning(ctx context.Context, in *SmartPlanningRequest, opts ...grpc.CallOption) (*JSONResponse, error)
|
||||
SmartPlanningMulti(ctx context.Context, in *SmartPlanningMultiRequest, opts ...grpc.CallOption) (*JSONResponse, error)
|
||||
GetAgentWeekSchedule(ctx context.Context, in *JSONRequest, opts ...grpc.CallOption) (*JSONResponse, error)
|
||||
GetScheduleFactsByWindow(ctx context.Context, in *JSONRequest, opts ...grpc.CallOption) (*JSONResponse, error)
|
||||
GetFeedbackSignal(ctx context.Context, in *JSONRequest, opts ...grpc.CallOption) (*JSONResponse, error)
|
||||
ApplyActiveScheduleChanges(ctx context.Context, in *JSONRequest, opts ...grpc.CallOption) (*JSONResponse, error)
|
||||
@@ -100,6 +102,12 @@ func (c *scheduleClient) SmartPlanningMulti(ctx context.Context, in *SmartPlanni
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *scheduleClient) GetAgentWeekSchedule(ctx context.Context, in *JSONRequest, opts ...grpc.CallOption) (*JSONResponse, error) {
|
||||
out := new(JSONResponse)
|
||||
err := c.cc.Invoke(ctx, Schedule_GetAgentWeekSchedule_FullMethodName, in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *scheduleClient) GetScheduleFactsByWindow(ctx context.Context, in *JSONRequest, opts ...grpc.CallOption) (*JSONResponse, error) {
|
||||
out := new(JSONResponse)
|
||||
err := c.cc.Invoke(ctx, Schedule_GetScheduleFactsByWindow_FullMethodName, in, out, opts...)
|
||||
@@ -128,6 +136,7 @@ type ScheduleServer interface {
|
||||
RevokeTaskItem(context.Context, *RevokeTaskItemRequest) (*StatusResponse, error)
|
||||
SmartPlanning(context.Context, *SmartPlanningRequest) (*JSONResponse, error)
|
||||
SmartPlanningMulti(context.Context, *SmartPlanningMultiRequest) (*JSONResponse, error)
|
||||
GetAgentWeekSchedule(context.Context, *JSONRequest) (*JSONResponse, error)
|
||||
GetScheduleFactsByWindow(context.Context, *JSONRequest) (*JSONResponse, error)
|
||||
GetFeedbackSignal(context.Context, *JSONRequest) (*JSONResponse, error)
|
||||
ApplyActiveScheduleChanges(context.Context, *JSONRequest) (*JSONResponse, error)
|
||||
@@ -163,6 +172,9 @@ func (UnimplementedScheduleServer) SmartPlanning(context.Context, *SmartPlanning
|
||||
func (UnimplementedScheduleServer) SmartPlanningMulti(context.Context, *SmartPlanningMultiRequest) (*JSONResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method SmartPlanningMulti not implemented")
|
||||
}
|
||||
func (UnimplementedScheduleServer) GetAgentWeekSchedule(context.Context, *JSONRequest) (*JSONResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetAgentWeekSchedule not implemented")
|
||||
}
|
||||
func (UnimplementedScheduleServer) GetScheduleFactsByWindow(context.Context, *JSONRequest) (*JSONResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetScheduleFactsByWindow not implemented")
|
||||
}
|
||||
@@ -312,6 +324,21 @@ func _Schedule_SmartPlanningMulti_Handler(srv interface{}, ctx context.Context,
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Schedule_GetAgentWeekSchedule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(JSONRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ScheduleServer).GetAgentWeekSchedule(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: Schedule_GetAgentWeekSchedule_FullMethodName}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ScheduleServer).GetAgentWeekSchedule(ctx, req.(*JSONRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Schedule_GetScheduleFactsByWindow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(JSONRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -370,6 +397,7 @@ var Schedule_ServiceDesc = grpc.ServiceDesc{
|
||||
{MethodName: "RevokeTaskItem", Handler: _Schedule_RevokeTaskItem_Handler},
|
||||
{MethodName: "SmartPlanning", Handler: _Schedule_SmartPlanning_Handler},
|
||||
{MethodName: "SmartPlanningMulti", Handler: _Schedule_SmartPlanningMulti_Handler},
|
||||
{MethodName: "GetAgentWeekSchedule", Handler: _Schedule_GetAgentWeekSchedule_Handler},
|
||||
{MethodName: "GetScheduleFactsByWindow", Handler: _Schedule_GetScheduleFactsByWindow_Handler},
|
||||
{MethodName: "GetFeedbackSignal", Handler: _Schedule_GetFeedbackSignal_Handler},
|
||||
{MethodName: "ApplyActiveScheduleChanges", Handler: _Schedule_ApplyActiveScheduleChanges_Handler},
|
||||
|
||||
@@ -14,6 +14,7 @@ service Schedule {
|
||||
rpc RevokeTaskItem(RevokeTaskItemRequest) returns (StatusResponse);
|
||||
rpc SmartPlanning(SmartPlanningRequest) returns (JSONResponse);
|
||||
rpc SmartPlanningMulti(SmartPlanningMultiRequest) returns (JSONResponse);
|
||||
rpc GetAgentWeekSchedule(JSONRequest) returns (JSONResponse);
|
||||
rpc GetScheduleFactsByWindow(JSONRequest) returns (JSONResponse);
|
||||
rpc GetFeedbackSignal(JSONRequest) returns (JSONResponse);
|
||||
rpc ApplyActiveScheduleChanges(JSONRequest) returns (JSONResponse);
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
|
||||
rootmodel "github.com/LoveLosita/smartflow/backend/model"
|
||||
"github.com/LoveLosita/smartflow/backend/respond"
|
||||
"github.com/LoveLosita/smartflow/backend/services/schedule/core/applyadapter"
|
||||
schedulecontracts "github.com/LoveLosita/smartflow/backend/shared/contracts/schedule"
|
||||
)
|
||||
@@ -30,6 +31,26 @@ func (ss *ScheduleService) GetScheduleFactsByWindow(ctx context.Context, req sch
|
||||
return ss.scheduleDAO.GetScheduleFactsByWindow(ctx, req)
|
||||
}
|
||||
|
||||
// GetAgentWeekSchedule 为 agent provider 暴露原始周日程槽位事实。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只读取 schedule 服务拥有的 schedules / schedule_events 数据;
|
||||
// 2. 保留 embedded_task_id 和 can_be_embedded,避免 agent 用前端 DTO 还原时丢语义;
|
||||
// 3. 不做缓存、不做前端展示聚合,调用侧负责组装 ScheduleState。
|
||||
func (ss *ScheduleService) GetAgentWeekSchedule(ctx context.Context, req schedulecontracts.AgentScheduleWeekRequest) (schedulecontracts.AgentScheduleWeekResponse, error) {
|
||||
if ss == nil || ss.scheduleDAO == nil {
|
||||
return schedulecontracts.AgentScheduleWeekResponse{}, errors.New("schedule agent week service 未初始化")
|
||||
}
|
||||
if req.Week < 0 || req.Week > 25 {
|
||||
return schedulecontracts.AgentScheduleWeekResponse{}, respond.WeekOutOfRange
|
||||
}
|
||||
schedules, err := ss.scheduleDAO.GetUserWeeklySchedule(ctx, req.UserID, req.Week)
|
||||
if err != nil {
|
||||
return schedulecontracts.AgentScheduleWeekResponse{}, err
|
||||
}
|
||||
return schedulesToAgentWeekContract(schedules), nil
|
||||
}
|
||||
|
||||
// GetFeedbackSignal 暴露主动调度 unfinished_feedback 的日程目标定位事实。
|
||||
func (ss *ScheduleService) GetFeedbackSignal(ctx context.Context, req schedulecontracts.FeedbackRequest) (schedulecontracts.FeedbackFact, bool, error) {
|
||||
if ss == nil || ss.scheduleDAO == nil {
|
||||
@@ -83,6 +104,92 @@ func toAdapterApplyRequest(req schedulecontracts.ApplyActiveScheduleRequest) app
|
||||
}
|
||||
}
|
||||
|
||||
func schedulesToAgentWeekContract(schedules []rootmodel.Schedule) schedulecontracts.AgentScheduleWeekResponse {
|
||||
out := make([]schedulecontracts.AgentScheduleSlot, 0, len(schedules))
|
||||
for _, item := range schedules {
|
||||
out = append(out, schedulecontracts.AgentScheduleSlot{
|
||||
ID: item.ID,
|
||||
EventID: item.EventID,
|
||||
UserID: item.UserID,
|
||||
Week: item.Week,
|
||||
DayOfWeek: item.DayOfWeek,
|
||||
Section: item.Section,
|
||||
EmbeddedTaskID: cloneIntPtr(item.EmbeddedTaskID),
|
||||
Status: item.Status,
|
||||
Event: scheduleEventToAgentContract(item.Event),
|
||||
EmbeddedTask: scheduleTaskItemToAgentContract(item.EmbeddedTask),
|
||||
})
|
||||
}
|
||||
return schedulecontracts.AgentScheduleWeekResponse{Schedules: out}
|
||||
}
|
||||
|
||||
func scheduleEventToAgentContract(event *rootmodel.ScheduleEvent) *schedulecontracts.AgentScheduleEvent {
|
||||
if event == nil {
|
||||
return nil
|
||||
}
|
||||
return &schedulecontracts.AgentScheduleEvent{
|
||||
ID: event.ID,
|
||||
UserID: event.UserID,
|
||||
Name: event.Name,
|
||||
Location: cloneStringPtr(event.Location),
|
||||
Type: event.Type,
|
||||
RelID: cloneIntPtr(event.RelID),
|
||||
TaskSourceType: event.TaskSourceType,
|
||||
CanBeEmbedded: event.CanBeEmbedded,
|
||||
StartTime: event.StartTime,
|
||||
EndTime: event.EndTime,
|
||||
}
|
||||
}
|
||||
|
||||
func scheduleTaskItemToAgentContract(item *rootmodel.TaskClassItem) *schedulecontracts.AgentScheduleTaskItem {
|
||||
if item == nil {
|
||||
return nil
|
||||
}
|
||||
return &schedulecontracts.AgentScheduleTaskItem{
|
||||
ID: item.ID,
|
||||
CategoryID: cloneIntPtr(item.CategoryID),
|
||||
Order: cloneIntPtr(item.Order),
|
||||
Content: derefString(item.Content),
|
||||
EmbeddedTime: scheduleTargetTimeToAgentContract(item.EmbeddedTime),
|
||||
Status: cloneIntPtr(item.Status),
|
||||
}
|
||||
}
|
||||
|
||||
func scheduleTargetTimeToAgentContract(value *rootmodel.TargetTime) *schedulecontracts.AgentScheduleTargetTime {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
return &schedulecontracts.AgentScheduleTargetTime{
|
||||
Week: value.Week,
|
||||
DayOfWeek: value.DayOfWeek,
|
||||
SectionFrom: value.SectionFrom,
|
||||
SectionTo: value.SectionTo,
|
||||
}
|
||||
}
|
||||
|
||||
func cloneIntPtr(value *int) *int {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
copied := *value
|
||||
return &copied
|
||||
}
|
||||
|
||||
func cloneStringPtr(value *string) *string {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
copied := *value
|
||||
return &copied
|
||||
}
|
||||
|
||||
func derefString(value *string) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
func toAdapterSlotSpan(span *schedulecontracts.SlotSpan) *applyadapter.SlotSpan {
|
||||
if span == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user