feat: 管线四阶段进度上报 + 图片预览 + Vite 代理
后端: - pipeline.go: ProgressReporter 回调类型 + WithProgressReporter 注入 context - nodes.go: 各节点 pre/post handler 调用 reportProgress() 上报阶段进度 - generate.go: TaskResponse 新增 stage 字段,runPipelineBg 注入进度回调 前端: - vite.config.ts: 添加 /generation 代理到后端静态文件服务 - generation.ts: 轮询读取 stage 字段,暴露 stage/retryCount/rejectReason - GeneratePage.tsx: ProgressBar 接收真实管线阶段数据
This commit is contained in:
@@ -57,8 +57,10 @@ var promptOptimizerNode = compose.InvokableLambda(func(ctx context.Context, in P
|
||||
func promptOptimizerPreHandler(ctx context.Context, in PipelineInput, state *PipelineState) (PipelineInput, error) {
|
||||
if state.RetryCount == 0 {
|
||||
state.Input = in
|
||||
reportProgress(ctx, "prompt_builder", 10)
|
||||
} else if state.RejectReason != "" {
|
||||
in.RejectReason = state.RejectReason
|
||||
reportProgress(ctx, "prompt_builder", 30+state.RetryCount*10)
|
||||
}
|
||||
return in, nil
|
||||
}
|
||||
@@ -66,6 +68,7 @@ func promptOptimizerPreHandler(ctx context.Context, in PipelineInput, state *Pip
|
||||
// promptOptimizerPostHandler 将最终提示词写入全局状态。
|
||||
func promptOptimizerPostHandler(ctx context.Context, out string, state *PipelineState) (string, error) {
|
||||
state.FinalPrompt = out
|
||||
reportProgress(ctx, "asset_generator", 35)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -82,6 +85,7 @@ var assetGeneratorNode = compose.InvokableLambda(func(ctx context.Context, promp
|
||||
// assetGeneratorPostHandler 将原始图片写入全局状态。
|
||||
func assetGeneratorPostHandler(ctx context.Context, out []GeneratedImage, state *PipelineState) ([]GeneratedImage, error) {
|
||||
state.RawImages = out
|
||||
reportProgress(ctx, "quality_supervisor", 60)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -104,11 +108,14 @@ var qualitySupervisorNode = compose.InvokableLambda(func(ctx context.Context, im
|
||||
|
||||
if pass {
|
||||
state.NextNode = nodeFormatAdapter
|
||||
reportProgress(ctx, "format_adapter", 85)
|
||||
} else if state.RetryCount >= 3 {
|
||||
state.NextNode = nodeFormatAdapter
|
||||
reportProgress(ctx, "format_adapter", 85)
|
||||
} else {
|
||||
state.RetryCount++
|
||||
state.NextNode = nodePromptOptimizer
|
||||
reportProgress(ctx, "quality_supervisor", 50+state.RetryCount*10)
|
||||
}
|
||||
|
||||
input = state.Input
|
||||
|
||||
@@ -14,6 +14,25 @@ const (
|
||||
nodeFormatAdapter = "format_adapter"
|
||||
)
|
||||
|
||||
// ProgressReporter 管线进度回调:stage 为当前节点名,progress 为 0-100。
|
||||
type ProgressReporter func(stage string, progress int)
|
||||
|
||||
type progressKeyType struct{}
|
||||
|
||||
var progressCtxKey progressKeyType
|
||||
|
||||
// WithProgressReporter 将进度回调注入 context。
|
||||
func WithProgressReporter(ctx context.Context, r ProgressReporter) context.Context {
|
||||
return context.WithValue(ctx, progressCtxKey, r)
|
||||
}
|
||||
|
||||
// reportProgress 从 context 取出回调上报进度。
|
||||
func reportProgress(ctx context.Context, stage string, progress int) {
|
||||
if r, ok := ctx.Value(progressCtxKey).(ProgressReporter); ok {
|
||||
r(stage, progress)
|
||||
}
|
||||
}
|
||||
|
||||
// NewGenerateGraph 创建生成管线 Graph(PromptOptimizer → AssetGenerator → QualitySupervisor → FormatAdapter)。
|
||||
//
|
||||
// START → PromptOptimizer → AssetGenerator → QualitySupervisor
|
||||
|
||||
Reference in New Issue
Block a user