Update default assistants to all visible (#2490)

* update default assistants to all visible

* update with catch-all

* minor update

* update
This commit is contained in:
pablodanswer
2024-09-17 19:08:11 -07:00
committed by GitHub
parent 5f25b243c5
commit 2073820e33
3 changed files with 25 additions and 5 deletions

View File

@@ -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'

View File

@@ -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<Persona | null>(null);
const [makePublicPersona, setMakePublicPersona] = useState<Persona | null>(
null

View File

@@ -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;