Wire catalog policy, v2 manifests, stage access, activation metadata fixes, and coordinator instance advance around frozen workflow snapshots. Co-authored-by: Cursor <cursoragent@cursor.com>
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package coordinator
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"chat-agent-system/internal/intent"
|
|
"chat-agent-system/internal/projectinstance"
|
|
)
|
|
|
|
func (e *CoordinatorEngine) tryAdvanceWorkflowInstance(ctx context.Context, projectID int64, userID int64) (*CoordinationResult, bool, error) {
|
|
if e == nil || e.instSvc == nil || !e.instSvc.Available() {
|
|
return nil, false, nil
|
|
}
|
|
live, err := e.instSvc.GetSettings(ctx, projectID, userID, true)
|
|
if err != nil || live == nil || live.LiveInstance == nil {
|
|
return nil, false, nil
|
|
}
|
|
stageKey := live.ActiveStageKey
|
|
if stageKey == "" {
|
|
return nil, false, nil
|
|
}
|
|
readiness, err := e.instSvc.GetStageReadiness(ctx, live.LiveInstance.ID, stageKey, userID, true)
|
|
if err != nil {
|
|
return nil, true, err
|
|
}
|
|
if !readiness.Ready {
|
|
return &CoordinationResult{
|
|
Status: StatusRejected,
|
|
Intent: intent.IntentAdvanceStage,
|
|
RejectReason: "STAGE_GATE_NOT_READY",
|
|
NaturalReply: fmt.Sprintf("当前阶段尚未满足推进条件,仍有 %d 项阻断。", len(readiness.BlockingIssues)),
|
|
}, true, projectinstance.ErrStageGateNotReady
|
|
}
|
|
result, err := e.instSvc.AdvanceStage(ctx, live.LiveInstance.ID, userID, true, projectinstance.AdvanceStageInput{
|
|
StageKey: stageKey,
|
|
ExpectedConfigRevision: readiness.ConfigRevision,
|
|
})
|
|
if err != nil {
|
|
return nil, true, err
|
|
}
|
|
reply := fmt.Sprintf("已确认推进阶段【%s】。", stageKey)
|
|
if result.InstanceDone {
|
|
reply = "工作流已完成。您现在可以配置下一个工作流。"
|
|
} else if result.NextStageKey != "" {
|
|
reply = fmt.Sprintf("已确认推进至下一阶段【%s】。", result.NextStageKey)
|
|
}
|
|
return &CoordinationResult{
|
|
Status: StatusAccepted,
|
|
Intent: intent.IntentAdvanceStage,
|
|
NaturalReply: reply,
|
|
}, true, nil
|
|
}
|