feat: sort action buttons by valve priority (#21790)

feat: sort action buttons by valve priority

Action buttons under assistant messages were rendered in
non-deterministic order due to set() deduplication. They now
respect the priority field from function Valves, sorted ascending
(lower value = appears first, default 0), matching the existing
filter priority mechanism.
This commit is contained in:
Classic298
2026-02-23 20:52:12 +01:00
committed by GitHub
parent f4a1d99f00
commit 1808d7fd2f

View File

@@ -331,12 +331,18 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
elif meta.get(key) is None:
meta[key] = copy.deepcopy(value)
def get_action_priority(action_id):
valves = Functions.get_function_valves_by_id(action_id)
return valves.get("priority", 0) if valves else 0
for model in models:
action_ids = [
action_id
for action_id in list(set(model.pop("action_ids", []) + global_action_ids))
if action_id in enabled_action_ids
]
action_ids.sort(key=get_action_priority)
filter_ids = [
filter_id
for filter_id in list(set(model.pop("filter_ids", []) + global_filter_ids))