Merge #4010 into stage-mk

This commit is contained in:
nesquena-hermes
2026-06-12 23:18:00 +00:00
3 changed files with 69 additions and 0 deletions

View File

@@ -101,6 +101,8 @@ let _slashModelCache=null;
let _slashModelCachePromise=null;
let _slashPersonalityCache=null;
let _slashPersonalityCachePromise=null;
let _slashSkillCache=null;
let _slashSkillCachePromise=null;
let _agentCommandCache=null;
let _agentCommandCachePromise=null;
@@ -118,6 +120,7 @@ function _invalidateSlashModelCache(){
// define a window global — see tests/test_cli_only_slash_commands.py.
if(typeof window!=='undefined'){
window._invalidateSlashModelCache=_invalidateSlashModelCache;
window.invalidateSlashSkillCaches=invalidateSlashSkillCaches;
}
function _normalizeSlashSubArg(value){
@@ -199,10 +202,43 @@ async function _loadSlashPersonalitySubArgs(force=false){
return _slashPersonalityCachePromise;
}
async function _loadSlashSkillSubArgs(force=false){
if(_slashSkillCache&&!force) return _slashSkillCache;
if(_slashSkillCachePromise&&!force) return _slashSkillCachePromise;
_slashSkillCachePromise=(async()=>{
try{
const data=await api('/api/skills');
const values=[];
for(const skill of (data&&data.skills)||[]){
const name=_normalizeSlashSubArg(skill&&skill.name);
if(name) values.push(name);
}
const deduped=Array.from(new Set(values)).sort((a,b)=>a.localeCompare(b));
_slashSkillCache=deduped;
return deduped;
}catch(_){
_slashSkillCache=null;
return [];
}finally{
_slashSkillCachePromise=null;
}
})();
return _slashSkillCachePromise;
}
function invalidateSlashSkillCaches(){
_slashSkillCache=null;
_slashSkillCachePromise=null;
_skillCommandCache=[];
_skillCommandCacheReady=false;
_skillCommandLoadPromise=null;
}
function _getSlashSubArgOptions(spec){
if(Array.isArray(spec)) return Promise.resolve(spec.slice());
if(spec==='models') return _loadSlashModelSubArgs();
if(spec==='personalities') return _loadSlashPersonalitySubArgs();
if(spec==='skills') return _loadSlashSkillSubArgs();
return Promise.resolve([]);
}

View File

@@ -3865,6 +3865,7 @@ async function toggleSkill(name, currentlyEnabled) {
const skill = _skillsData.find(s => s.name === name);
if (skill) skill.disabled = !newEnabled;
}
if(typeof window!=='undefined'&&typeof window.invalidateSlashSkillCaches==='function') window.invalidateSlashSkillCaches();
renderSkills(_skillsData || []);
} else {
setStatus((result && result.error) || t('skill_toggle_failed'));
@@ -4119,6 +4120,7 @@ async function saveSkillForm() {
showToast(_editingSkillName ? t('skill_updated') : t('skill_created'));
_skillsData = null;
_cronSkillsCache = null;
if(typeof window!=='undefined'&&typeof window.invalidateSlashSkillCaches==='function') window.invalidateSlashSkillCaches();
_editingSkillName = null;
_skillPreFormDetail = null;
await loadSkills();
@@ -4158,6 +4160,7 @@ async function deleteCurrentSkill() {
_skillPreFormDetail = null;
_skillsData = null;
_cronSkillsCache = null;
if(typeof window!=='undefined'&&typeof window.invalidateSlashSkillCaches==='function') window.invalidateSlashSkillCaches();
_skillMode = 'empty';
const body = $('skillDetailBody');
const empty = $('skillDetailEmpty');