diff --git a/backend/alembic/versions/35e6853a51d5_server_default_chosen_assistants.py b/backend/alembic/versions/35e6853a51d5_server_default_chosen_assistants.py index 057931b27494..0db3ca849bf8 100644 --- a/backend/alembic/versions/35e6853a51d5_server_default_chosen_assistants.py +++ b/backend/alembic/versions/35e6853a51d5_server_default_chosen_assistants.py @@ -20,10 +20,23 @@ DEFAULT_ASSISTANTS = [-2, -1, 0] def upgrade() -> None: # Step 1: Update any NULL values to the default value + # This upgrades existing users without ordered assistant + # to have default assistants set to visible assistants which are + # accessible by them. op.execute( - f""" - UPDATE "user" - SET chosen_assistants = '{DEFAULT_ASSISTANTS}' + """ + UPDATE "user" u + SET chosen_assistants = ( + SELECT jsonb_agg( + p.id ORDER BY + COALESCE(p.display_priority, 2147483647) ASC, + p.id ASC + ) + FROM persona p + LEFT JOIN persona__user pu ON p.id = pu.persona_id AND pu.user_id = u.id + WHERE p.is_visible = true + AND (p.is_public = true OR pu.user_id IS NOT NULL) + ) WHERE chosen_assistants IS NULL OR chosen_assistants = 'null' OR jsonb_typeof(chosen_assistants) = 'null' diff --git a/web/src/app/assistants/mine/AssistantsList.tsx b/web/src/app/assistants/mine/AssistantsList.tsx index 76f76239b618..880dcad49bc5 100644 --- a/web/src/app/assistants/mine/AssistantsList.tsx +++ b/web/src/app/assistants/mine/AssistantsList.tsx @@ -306,9 +306,11 @@ export function AssistantsList({ user?.preferences?.chosen_assistants && !user?.preferences?.chosen_assistants?.includes(assistant.id) ); + const allAssistantIds = assistants.map((assistant) => assistant.id.toString() ); + const [deletingPersona, setDeletingPersona] = useState(null); const [makePublicPersona, setMakePublicPersona] = useState( null diff --git a/web/src/lib/assistants/orderAssistants.ts b/web/src/lib/assistants/orderAssistants.ts index 0ae9d8561d49..5d52b2086e9f 100644 --- a/web/src/lib/assistants/orderAssistants.ts +++ b/web/src/lib/assistants/orderAssistants.ts @@ -14,15 +14,20 @@ export function orderAssistantsForUser( ]) ); - assistants = assistants.filter((assistant) => + let filteredAssistants = assistants.filter((assistant) => chosenAssistantsSet.has(assistant.id) ); - assistants.sort((a, b) => { + if (filteredAssistants.length == 0) { + return assistants; + } + + filteredAssistants.sort((a, b) => { const orderA = assistantOrderMap.get(a.id) ?? Number.MAX_SAFE_INTEGER; const orderB = assistantOrderMap.get(b.id) ?? Number.MAX_SAFE_INTEGER; return orderA - orderB; }); + return filteredAssistants; } return assistants;