mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 02:05:22 -04:00
Await character templates before populating group dropdowns
This commit is contained in:
+12
-17
@@ -81,8 +81,7 @@ function _initGroupTab() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addBtn.addEventListener('click', async () => {
|
addBtn.addEventListener('click', async () => {
|
||||||
const models = await _getModels();
|
const [models, characters] = await Promise.all([_getModels(), _getCharacterList()]);
|
||||||
const characters = _getCharacterList();
|
|
||||||
|
|
||||||
const picker = document.createElement('div');
|
const picker = document.createElement('div');
|
||||||
picker.style.cssText = 'display:flex;gap:4px;align-items:center;';
|
picker.style.cssText = 'display:flex;gap:4px;align-items:center;';
|
||||||
@@ -244,13 +243,12 @@ function _initGroupTab() {
|
|||||||
chip.title = (g.participants || []).map(p => p.characterName || p.modelDisplay || '?').join(', ');
|
chip.title = (g.participants || []).map(p => p.characterName || p.modelDisplay || '?').join(', ');
|
||||||
chip.addEventListener('click', async () => {
|
chip.addEventListener('click', async () => {
|
||||||
// Load preset participants
|
// Load preset participants
|
||||||
const models = await _getModels();
|
const [models, chars] = await Promise.all([_getModels(), _getCharacterList()]);
|
||||||
_groupParticipants.length = 0;
|
_groupParticipants.length = 0;
|
||||||
(g.participants || []).forEach(p => {
|
(g.participants || []).forEach(p => {
|
||||||
const model = models.find(m => m.mid === p.modelId) || models[0];
|
const model = models.find(m => m.mid === p.modelId) || models[0];
|
||||||
const entry = { model: model || null, character: null };
|
const entry = { model: model || null, character: null };
|
||||||
if (p.characterId) {
|
if (p.characterId) {
|
||||||
const chars = _getCharacterList();
|
|
||||||
entry.character = chars.find(c => c.id === p.characterId) || null;
|
entry.character = chars.find(c => c.id === p.characterId) || null;
|
||||||
}
|
}
|
||||||
if (entry.model) _groupParticipants.push(entry);
|
if (entry.model) _groupParticipants.push(entry);
|
||||||
@@ -284,7 +282,7 @@ function _initGroupTab() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getCharacterList() {
|
async function _getCharacterList() {
|
||||||
// Built-in characters from PROMPT_TEMPLATES
|
// Built-in characters from PROMPT_TEMPLATES
|
||||||
const chars = PROMPT_TEMPLATES.filter(t => t.isCharacter).map(t => ({
|
const chars = PROMPT_TEMPLATES.filter(t => t.isCharacter).map(t => ({
|
||||||
id: t.id, name: t.name, prompt: t.prompt,
|
id: t.id, name: t.name, prompt: t.prompt,
|
||||||
@@ -300,18 +298,15 @@ function _getCharacterList() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
// Also try loading user templates
|
// Load user templates and wait for them before returning
|
||||||
try {
|
try {
|
||||||
fetch(API_BASE + '/api/presets/templates', { credentials: 'same-origin' })
|
const r = await fetch(API_BASE + '/api/presets/templates', { credentials: 'same-origin' });
|
||||||
.then(r => r.json())
|
const data = await r.json();
|
||||||
.then(data => {
|
(data.templates || []).forEach(t => {
|
||||||
(data.templates || []).forEach(t => {
|
if (t.isCharacter && !chars.find(c => c.id === t.id)) {
|
||||||
if (t.isCharacter && !chars.find(c => c.id === t.id)) {
|
chars.push({ id: t.id, name: t.name, prompt: t.prompt || '' });
|
||||||
chars.push({ id: t.id, name: t.name, prompt: t.prompt || '' });
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
return chars;
|
return chars;
|
||||||
}
|
}
|
||||||
@@ -475,7 +470,7 @@ export async function showModelPicker() {
|
|||||||
body.appendChild(stepTitle);
|
body.appendChild(stepTitle);
|
||||||
|
|
||||||
// Build character options
|
// Build character options
|
||||||
const characters = _getCharacterList();
|
const characters = await _getCharacterList();
|
||||||
const assignments = {}; // mid -> {characterId, characterName, characterPrompt}
|
const assignments = {}; // mid -> {characterId, characterName, characterPrompt}
|
||||||
|
|
||||||
for (const m of picked) {
|
for (const m of picked) {
|
||||||
|
|||||||
Reference in New Issue
Block a user