feat(assistant): manage providers models and personal conversation recycle bin

This commit is contained in:
abaishu0730 committed 2026-10-28 09:58:11 +08:00
1 parent 506e6fbfad
commit 301cdf669d
29 files changed
+267 -83

No files matched your search

+3 -2
View File
@@ -1,13 +1,14 @@
'use strict';
window.AssistantCommands={mount(root,{getContext,onStatus,onSelect,onError}){
window.AssistantCommands={mount(root,{getContext,onStatus,onSelect,onError,onModel}){
const input=root.querySelector('#assistant-input'),menu=root.querySelector('#assistant-command-menu');let rows=[],index=0,mode='command',generation=0;
const catalog=[{name:'help',label:'帮助',detail:'/help · 固定诊断命令'},{name:'status',label:'运行概况',detail:'/status · 只读刷新'},{name:'bpm',label:'BPM 连接',detail:'/bpm · 选择连接并诊断'},{name:'storage',label:'存储连接',detail:'/storage · 选择存储并诊断'},{name:'archive',label:'归档失败',detail:'/archive · 选择归档记录'}];
const catalog=[{name:'help',label:'帮助',detail:'/help · 固定诊断命令'},{name:'status',label:'运行概况',detail:'/status · 只读刷新'},{name:'model',label:'选择模型',detail:'/model · 按供应商选择模型'},{name:'bpm',label:'BPM 连接',detail:'/bpm · 选择连接并诊断'},{name:'storage',label:'存储连接',detail:'/storage · 选择存储并诊断'},{name:'archive',label:'归档失败',detail:'/archive · 选择归档记录'}];
function close(){generation++;menu.hidden=true;menu.replaceChildren();input.removeAttribute('aria-activedescendant');input.setAttribute('aria-expanded','false');}
function draw(){menu.replaceChildren();menu.hidden=false;input.setAttribute('aria-expanded','true');for(const [i,row]of rows.entries()){const b=document.createElement('button');b.type='button';b.role='option';b.id='aw-command-'+i;b.setAttribute('aria-selected',String(i===index));const label=document.createElement('span');label.textContent=row.label;const detail=document.createElement('small');detail.textContent=row.detail||'';b.append(label,detail);b.onclick=()=>choose(row);menu.append(b);}if(!rows.length){const note=document.createElement('div');note.className='p-3 text-secondary small';note.textContent='没有可见的匹配目标';menu.append(note);}input.setAttribute('aria-activedescendant','aw-command-'+index);}
function commands(query=''){mode='command';rows=window.AssistantNative.filterOptions(catalog.map(c=>({...c,detail:c.detail+' '+c.name})),query);index=0;draw();}
async function choose(row){
if(mode!=='command'){const command=mode;close();onSelect(command,row);input.focus();return;}
const command=row.name;
if(command==='model'){close();input.dataset.diagnostic='';input.value='';await onModel?.();return;}
if(command==='help'){close();input.dataset.diagnostic='';onStatus('help',catalog);input.value='';return;}
if(command==='status'){close();input.dataset.diagnostic='';input.value='';await onStatus('status');return;}
const at=++generation;try{const context=await getContext();if(at!==generation)return;mode=command;rows=({bpm:context.connections,storage:context.servers,archive:context.archives}[command]||[]).map(item=>({id:item.id,label:item.name||item.orderNumber||item.id,detail:item.status||'',...item}));index=0;draw();input.focus();}catch(error){if(at===generation)onError(error);}