File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -176,12 +176,42 @@ func togobaev(ev *zero.Event) *goba.Event {
176176 }
177177}
178178
179+ // countParamsLength 统计 params 中所有叶子节点字符串的长度之和(非递归实现)
180+ func countParamsLength (params map [string ]any ) int {
181+ total := 0
182+ // 使用栈存储待处理的 map
183+ stack := []map [string ]any {params }
184+
185+ for len (stack ) > 0 {
186+ // 弹出栈顶元素
187+ current := stack [len (stack )- 1 ]
188+ stack = stack [:len (stack )- 1 ]
189+
190+ // 遍历当前 map 的所有值
191+ for _ , v := range current {
192+ switch val := v .(type ) {
193+ case string :
194+ // 叶子节点,累加长度
195+ total += len (val )
196+ case map [string ]any :
197+ // 非叶子节点,压入栈中待处理
198+ stack = append (stack , val )
199+ }
200+ }
201+ }
202+
203+ return total
204+ }
205+
179206func logev (ctx * zero.Ctx ) {
180207 if ! IsAgentCharReady {
181208 return
182209 }
183210 vevent .HookCtxCaller (ctx , vevent .NewAPICallerReturnHook (
184211 ctx , func (req zero.APIRequest , rsp zero.APIResponse , err error ) {
212+ if countParamsLength (req .Params ) > 256 { // skip too long req&resp
213+ return
214+ }
185215 k := zero .StateKeyPrefixKeep + "_chat_agent_logev_logged__"
186216 _ , ok := ctx .State [k ]
187217 if ok {
You can’t perform that action at this time.
0 commit comments