yao/agent/robot/events/handlers.go
Max bc4787f857 Update executor to support V2 execution model and enhance event handling
- Implement V2 execution model in the standard executor, simplifying task execution to a single call without validation loops.
- Introduce support for resuming suspended executions, allowing for human input during task processing.
- Enhance event handling by pushing task completion and failure events to the event bus for better tracking and integration.
- Update tests to reflect changes in execution flow and ensure robust handling of task statuses and results.
2026-02-25 18:40:48 +08:00

54 lines
1.6 KiB
Go

package events
import (
"context"
"encoding/json"
"fmt"
"github.com/yaoapp/kun/log"
eventtypes "github.com/yaoapp/yao/event/types"
)
// DeliveryHandler processes robot.delivery events asynchronously.
// It routes delivery content to configured channels (email, webhook, process).
type DeliveryHandler struct{}
// Handle processes a delivery event from the event bus.
func (h *DeliveryHandler) Handle(ctx context.Context, ev *eventtypes.Event, resp chan<- eventtypes.Result) {
var payload DeliveryPayload
if err := ev.Should(&payload); err != nil {
log.Error("delivery handler: invalid payload: %v", err)
return
}
log.Info(
"delivery handler: processing delivery for execution=%s member=%s",
payload.ExecutionID, payload.MemberID,
)
// Log delivery content summary for observability
if payload.Content != nil {
if data, err := json.Marshal(payload.Content); err == nil {
log.Debug("delivery handler: content=%s", string(data))
}
}
// Actual delivery routing is deferred to registered channel handlers.
// In the current implementation, the DeliveryCenter logic in delivery.go
// can be invoked here if needed. For now, this handler serves as the
// event-driven entry point for future channel-specific handlers.
if ev.IsCall {
resp <- eventtypes.Result{Data: fmt.Sprintf("delivery processed for %s", payload.ExecutionID)}
}
}
// Shutdown gracefully shuts down the delivery handler.
func (h *DeliveryHandler) Shutdown(ctx context.Context) error {
return nil
}
// NewDeliveryHandler creates a new DeliveryHandler.
func NewDeliveryHandler() *DeliveryHandler {
return &DeliveryHandler{}
}