MCPcopy Create free account
hub / github.com/astercloud/aster / Execute

Method Execute

pkg/workflow/workflow.go:309–575  ·  view source on GitHub ↗

===== 执行 ===== Execute 执行 Workflow

(ctx context.Context, input *WorkflowInput)

Source from the content-addressed store, hash-verified

307
308// Execute 执行 Workflow
309func (w *Workflow) Execute(ctx context.Context, input *WorkflowInput) *stream.Reader[*RunEvent] {
310 reader, writer := stream.Pipe[*RunEvent](10)
311
312 go func() {
313 defer writer.Close()
314 // 验证输入
315 if err := w.ValidateInput(input.Input); err != nil {
316 writer.Send(nil, fmt.Errorf("input validation failed: %w", err))
317 return
318 }
319
320 // 初始化会话
321 sessionID, userID := w.InitializeSession(input.SessionID, input.UserID)
322 session := w.GetOrCreateSession(sessionID, userID)
323
324 // 生成 RunID
325 runID := uuid.New().String()
326 startTime := time.Now()
327
328 // 创建运行记录
329 run := &WorkflowRun{
330 RunID: runID,
331 SessionID: sessionID,
332 WorkflowID: w.ID,
333 Input: input.Input,
334 StepOutputs: make(map[string]*StepOutput),
335 Status: RunStatusRunning,
336 StartTime: startTime,
337 Metrics: &RunMetrics{TotalSteps: len(w.Steps), StepMetrics: make(map[string]*StepMetrics)},
338 }
339
340 // 发送开始事件
341 if writer.Send(&RunEvent{
342 Type: EventWorkflowStarted,
343 EventID: uuid.New().String(),
344 WorkflowID: w.ID,
345 WorkflowName: w.Name,
346 RunID: runID,
347 Timestamp: startTime,
348 Data: map[string]any{
349 "input": input.Input,
350 "session_id": sessionID,
351 "user_id": userID,
352 },
353 }, nil) {
354 return
355 }
356
357 // 合并会话状态
358 sessionState := make(map[string]any)
359 if session.State != nil {
360 maps.Copy(sessionState, session.State)
361 }
362 if input.SessionState != nil {
363 maps.Copy(sessionState, input.SessionState)
364 }
365
366 stepOutputs := make(map[string]*StepOutput)

Callers

nothing calls this directly

Calls 15

ValidateInputMethod · 0.95
InitializeSessionMethod · 0.95
GetOrCreateSessionMethod · 0.95
SaveRunMethod · 0.95
CopyMethod · 0.80
RecvMethod · 0.80
CloseMethod · 0.65
IDMethod · 0.65
NameMethod · 0.65
TypeMethod · 0.65
ExecuteMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected