@@ -324,33 +324,25 @@ def _put_once(k=key, d=desc, z=zh):
324324 await run_in_threadpool (_put_once )
325325 zh_by_md5 [key ] = zh
326326
327- # 1. 假设这是你从 repo 获取到的收藏列表(按时间倒序:['skillA', 'skillB'])
328- # 请确保在实际代码中调用 repo 获取这个列表
327+ # 1. 获取收藏列表
329328 favorite_skills = await run_in_threadpool (
330329 lambda : favorite_skill_repo .list ()
331330 )
332331
333332 # --- 排序逻辑开始 ---
334-
335- # 构建一个优先级字典:{ "skill_name": 排序权重 }
336- # 收藏的技能按照列表顺序获得权重(0, 1, 2...),未收藏的统一给一个很大的权重(例如 99999)
337333 priority_map = {name : idx for idx , name in enumerate (favorite_skills )}
338334
339335 def get_sort_key (item ):
340336 name = item .get ("name" , "" )
341337 if name in priority_map :
342- # 第一梯队:已收藏。保留收藏列表的顺序(index 越小越靠前)
343338 return (0 , priority_map [name ])
344339 else :
345- # 第二梯队:未收藏。这里可以选择按名字字母排序,方便查阅
346340 return (1 , name )
347341
348- # 先过滤掉非字典的数据,然后根据规则排序
349342 sorted_items = sorted (
350343 [s for s in items if isinstance (s , dict )],
351344 key = get_sort_key
352345 )
353-
354346 # --- 排序逻辑结束 ---
355347
356348 return ok (
@@ -364,15 +356,16 @@ def get_sort_key(item):
364356 if isinstance (s .get ("description" ), str ) and s .get ("description" )
365357 else "" ,
366358 "source" : "openclaw-bundled" if (
367- isinstance (s .get ("name" ), str ) and s .get ("name" ) == "302ai-search" ) else (
359+ isinstance (s .get ("name" ), str ) and s .get ("name" ) == "302ai-search" ) else (
368360 (s .get ("source" ) or "" ) if isinstance (s .get ("source" ), str ) else "" ),
369361 "eligible" : bool (s .get ("eligible" )) if "eligible" in s else None ,
370362 "disabled" : bool (s .get ("disabled" )) if "disabled" in s else None ,
371363 "bundled" : bool (s .get ("bundled" )) if "bundled" in s else None ,
372364 "blockedByAllowlist" : bool (s .get ("blockedByAllowlist" )) if "blockedByAllowlist" in s else None ,
373365 "missing" : s .get ("missing" ) if isinstance (s .get ("missing" ), dict ) else None ,
366+ "is_favorite" : s .get ("name" ) in priority_map ,
367+
374368 }
375- # 这里改用排序后的 sorted_items
376369 for s in sorted_items
377370 ],
378371 "builtin_skills" : [],
0 commit comments