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

Function NewHumanInTheLoopMiddleware

pkg/middleware/hitl.go:84–114  ·  view source on GitHub ↗

NewHumanInTheLoopMiddleware 创建 HITL 中间件

(config *HumanInTheLoopMiddlewareConfig)

Source from the content-addressed store, hash-verified

82
83// NewHumanInTheLoopMiddleware 创建 HITL 中间件
84func NewHumanInTheLoopMiddleware(config *HumanInTheLoopMiddlewareConfig) (*HumanInTheLoopMiddleware, error) {
85 if config == nil {
86 config = &HumanInTheLoopMiddlewareConfig{}
87 }
88
89 // 默认允许的决策
90 defaultAllowedDecisions := config.DefaultAllowedDecisions
91 if len(defaultAllowedDecisions) == 0 {
92 defaultAllowedDecisions = []DecisionType{DecisionApprove, DecisionEdit, DecisionReject}
93 }
94
95 m := &HumanInTheLoopMiddleware{
96 BaseMiddleware: NewBaseMiddleware("hitl", 150),
97 interruptConfigs: make(map[string]*InterruptConfig),
98 approvalHandler: config.ApprovalHandler,
99 defaultAllowedDecisions: defaultAllowedDecisions,
100 }
101
102 // 解析 InterruptOn 配置
103 if config.InterruptOn != nil {
104 for toolName, cfg := range config.InterruptOn {
105 interruptCfg := m.parseInterruptConfig(toolName, cfg)
106 if interruptCfg != nil && interruptCfg.Enabled {
107 m.interruptConfigs[toolName] = interruptCfg
108 }
109 }
110 }
111
112 hitlLog.Info(context.Background(), "initialized", map[string]any{"tools_count": len(m.interruptConfigs)})
113 return m, nil
114}
115
116var hitlLog = logging.ForComponent("HumanInTheLoopMiddleware")
117

Calls 3

parseInterruptConfigMethod · 0.95
NewBaseMiddlewareFunction · 0.85
InfoMethod · 0.65