113 lines
11 KiB
JavaScript
113 lines
11 KiB
JavaScript
window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
|
const React=require('react'),h=React.createElement;
|
|
const {IconSettingsOutlineMedium}=require('@deepseek-ai/dsh-client-ui-primitives');
|
|
const names={observe:'待命',draft:'待配置',configuring:'待配置',running:'执行中',paused:'已暂停',completed:'已完成',blocked:'已阻断',uncertain:'待核验',failed:'失败'};
|
|
const stages={collecting:'收集异常证据',analyzing:'AI 自动诊断中',retrying:'按规则重试中',verifying:'核验实际执行结果',
|
|
reflecting:'AI 复盘与补充诊断中',resolved:'处理结果已通过核验',pending_issue:'证据已保存,工单待完整提交',escalated:'证据已保存并提交 Git 工单'};
|
|
function ToolSettings(){
|
|
return h('div',{'data-testid':'dx-tool-settings-panel',style:{lineHeight:1.9}},
|
|
h('h2',null,'DSH工具'),
|
|
h('p',null,'面向 DxDesigner 器件替换任务的异常分析与执行监管。发现报错后自动介入,直接使用当前任务上下文,无需另外登录。'),
|
|
h('h3',null,'工作方式'),
|
|
h('p',null,'在顶部切换任务中心和 DSH助手。会话、任务选择和未发送草稿会保留。'),
|
|
h('h3',null,'任务能力'),
|
|
h('ul',null,...['在对话中创建任务、查找和切换任务、复制配置到新工程','修改名称、备注、Value 策略与已有规则,预览同批影响后确认;归档保留证据','执行前预检所选任务,显示阻断原因;确认工程范围后启动或继续现有队列','对话请求安全暂停,返回实际保存、失败与未命中计数','异常后自动创建诊断会话,收集证据','已授权执行遇到明确失败时,按规则最多重试一次并核验','无法解决时复盘,保存诊断和完整证据链,尝试提交 Git 工单'].map(text=>h('li',{key:text},text))),
|
|
h('h3',null,'模型与数据'),
|
|
h('p',null,'使用主工具配置的模型,在输入框下方选择。会话保存在本机任务中心数据目录。'),
|
|
h('h3',null,'异常工单'),
|
|
h('p',null,'随工具预置专用工单上报身份,无需安装 Git 或登录。未解决的异常自动提交项目工单,并上传脱敏诊断证据。'),
|
|
h('p',null,'工程修改与执行核验由任务中心完成。模型不直接访问工程文件或执行命令。'));
|
|
}
|
|
function SettingsLauncher({wide,openSettings}){
|
|
return h('button',{'data-testid':'dx-tool-settings',type:'button','aria-label':'工具设置',onClick:()=>openSettings(),
|
|
style:{display:'flex',alignItems:'center',gap:8,width:wide?'100%':36,height:38,padding:wide?'0 10px':8,
|
|
border:0,borderRadius:10,background:'transparent',color:'var(--dsw-alias-label-primary)',cursor:'pointer',font:'inherit'}},
|
|
h(IconSettingsOutlineMedium,{size:18}),wide&&'工具设置');
|
|
}
|
|
function TaskPanel(){
|
|
const[data,setData]=React.useState(null),[notice,setNotice]=React.useState('');
|
|
React.useEffect(()=>{
|
|
let live=true;
|
|
const read=()=>fetch('/dx/context').then(r=>{if(!r.ok)throw Error();return r.json();}).then(v=>{if(live)setData(v);}).catch(()=>{if(live)setNotice('任务上下文暂不可用');});
|
|
read();const timer=setInterval(read,1500);return()=>{live=false;clearInterval(timer);};
|
|
},[]);
|
|
async function request(action){
|
|
setNotice('等待任务中心确认…');
|
|
try{
|
|
const response=await fetch('/dx/action',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action,task_id:data.task_id,revision:data.revision})});
|
|
setNotice(response.ok?'请求已交给任务中心,请在工具中确认。':'任务状态已改变,请刷新后重试。');
|
|
}catch{setNotice('任务服务暂不可用,请稍后重试。');}
|
|
}
|
|
const section=(title,text)=>h('section',{style:{marginBottom:24}},h('h3',{style:{fontSize:14,fontWeight:500,marginBottom:10}},title),
|
|
h('div',{style:{whiteSpace:'pre-wrap',color:'var(--dsw-alias-label-secondary)',lineHeight:1.8}},text));
|
|
return h('div',{'data-testid':'dx-task-panel',style:{padding:20,overflow:'auto',height:'100%',boxSizing:'border-box'}},
|
|
section('当前任务',data?(data.task_name||data.task_id||'尚未选择任务'):'读取中…'),
|
|
data?.lifecycle?.request_id&&h('section',{'data-testid':'dx-task-lifecycle',style:{marginBottom:24}},
|
|
h('h3',{style:{fontSize:14,fontWeight:500}},data.lifecycle.title||'对话任务操作'),
|
|
h('p',{'data-testid':'dx-lifecycle-status'},({checking:'正在核对真实任务',awaiting_confirmation:'请核对原生确认窗口',
|
|
applying:'正在保存配置',executing:'正在执行,等待实际结果',updated:'配置已更新',archived:'已移入回收站',
|
|
selected:'已切换任务',created:'已复制到新工程',preflight:'预检已完成',blocked:'执行已阻断',read:'任务记录已读取',
|
|
completed:'执行流程已结束,请核对各项计数',paused:'已安全暂停',cancelled:'已取消',rejected:'当前状态不允许操作',failed:'操作未完成'}[data.lifecycle.status]||data.lifecycle.status)),
|
|
data.lifecycle.preview&&h('p',{style:{whiteSpace:'pre-wrap',maxHeight:220,overflow:'auto',fontSize:12}},data.lifecycle.preview),
|
|
data.lifecycle.result?.tasks?.map(t=>h('p',{key:t.task_id,style:{whiteSpace:'pre-wrap',fontSize:12}},
|
|
(t.name||t.task_id)+'\n'+(t.blockers?.length?t.blockers.join('\n'):t.saved_items!==undefined?
|
|
`已保存 ${t.saved_items} · 失败 ${t.failed_items} · 未命中 ${t.no_match_items}`:''))),
|
|
data.lifecycle.result?.message&&h('p',{style:{fontSize:12}},data.lifecycle.result.message)),
|
|
data?.creation?.request_id&&h('section',{'data-testid':'dx-task-creation',style:{marginBottom:24}},
|
|
h('h3',{style:{fontSize:14,fontWeight:500}},'对话创建任务'),
|
|
h('p',null,data.creation.name),
|
|
h('p',{'data-testid':'dx-creation-status'},({awaiting_confirmation:'请在原生窗口选择工程并确认',creating:'正在创建工程任务',
|
|
created:'任务已创建,可切回任务中心继续配置',existing:'选中工程已有任务,保持原配置',cancelled:'已取消,未创建任务',failed:'创建未完成'}[data.creation.status]||data.creation.status)),
|
|
h('p',null,(data.creation.rules||[]).map(row=>row.old_part_number+' → '+row.new_part_number).join('\n')),
|
|
data.creation.result?.created_count!==undefined&&h('p',null,'新建 '+data.creation.result.created_count+' 个 · 已有 '+data.creation.result.existing_count+' 个')),
|
|
data?.automation?.incident_id&&h('section',{'data-testid':'dx-auto-incident',style:{marginBottom:24}},
|
|
h('h3',{style:{fontSize:14,fontWeight:500}},'AI 自动介入'),
|
|
h('p',null,data.automation.task_name||'异常任务'),
|
|
h('p',{'data-testid':'dx-auto-status'},stages[data.automation.status]||data.automation.status),
|
|
h('p',{style:{whiteSpace:'pre-wrap'}},data.automation.summary?.slice(0,650)||'正在保留现场并核对异常依据…'),
|
|
h('p',{style:{fontSize:12,overflowWrap:'anywhere',color:'var(--dsw-alias-label-secondary)'}},
|
|
'事件 '+data.automation.incident_id+' · '+data.automation.issue_code),
|
|
data.automation.ticket?.url&&h('p',{'data-testid':'dx-auto-ticket',style:{overflowWrap:'anywhere',userSelect:'text'}},'Git 工单:'+data.automation.ticket.url),
|
|
data.automation.task_id===data.task_id&&h('div',{style:{display:'flex',gap:8}},
|
|
h('button',{type:'button',onClick:()=>request('open_evidence')},'打开证据目录'),
|
|
data.automation.status==='pending_issue'&&h('button',{type:'button',onClick:()=>request('retry_issue')},'重新提交工单'))),
|
|
section('执行状态',data?(names[data.status]||data.status)+(data.issue_code?'\n'+data.issue_code:''):'—'),
|
|
section('异常与依据',data?.issue||'暂无异常证据'),
|
|
section('规则与进度',data?`${data.rules_count} 条规则\n已完成 ${data.progress.completed||0} / ${data.progress.total||0} 步`:'—'),
|
|
h('h3',{style:{fontSize:14,fontWeight:500}},'任务操作'),
|
|
...[['refresh_snapshot','刷新任务上下文'],['retry_failed','准备失败项重试'],['pause_task','安全暂停']].map(([action,title])=>
|
|
h('button',{key:action,disabled:!data?.task_id,onClick:()=>request(action),style:{display:'block',width:'100%',textAlign:'left',marginTop:8,padding:'10px 12px',
|
|
border:'1px solid var(--dsw-alias-border-l2)',background:'var(--dsw-alias-bg-base)',color:'var(--dsw-alias-label-primary)',borderRadius:12,cursor:'pointer'}},title)),
|
|
h('p',{role:'status',style:{fontSize:12,color:'var(--dsw-alias-label-secondary)'}},data?.action_result||notice),
|
|
section('能力边界','任务修改与执行展示具体范围后由原生窗口确认;预检核对保存的配置,不代表 CAD 已连通。\n自动诊断只读事件快照,处理沿用既有执行规则;不确定状态保留现场,转人工与工单。'),
|
|
section('监管记录',(data?.events||[]).join('\n')||'等待任务事件'));
|
|
}
|
|
return{inject:['slots','sidebarRightTabs','sidebarRight','uiSession','uiWorkspace'],apply(ctx){
|
|
ctx.effect(()=>{
|
|
let live=true,opened='';
|
|
const check=()=>fetch('/dx/context').then(r=>r.json()).then(data=>{
|
|
const id=data.automation?.session_id;
|
|
if(live&&id&&id!==opened){ctx.uiWorkspace.openSession(id);opened=id;}
|
|
}).catch(()=>{});
|
|
check();const timer=setInterval(check,700);return()=>{live=false;clearInterval(timer);};
|
|
},'dx-task: automatic incident conversation');
|
|
ctx.slots.inject('settings.launcher',()=>ctx.slots.register({name:'settings.launcher',priority:-10},SettingsLauncher));
|
|
ctx.slots.inject('settings.section',()=>ctx.slots.register({name:'settings.section',id:'dx-tool',order:-100,label:()=>'DSH工具'},ToolSettings));
|
|
ctx.slots.inject('conversation.hero.options',()=>ctx.slots.register({name:'conversation.hero.options',id:'dx-tool-hint'},
|
|
()=>h('p',{style:{fontSize:13,color:'var(--dsw-alias-label-secondary)',textAlign:'center',margin:'4px 0 12px'}},'任务异常分析 · 规则内处理 · 执行监管')));
|
|
ctx.sidebarRightTabs.register({id:'@dx/dsh-task',kind:'dx-task',priority:'extension',title:()=>'任务监管',guide:[{id:'dx-task',order:0,title:()=>'任务监管',description:()=>'当前任务与受控操作'}]});
|
|
ctx.slots.inject('sidebar.right.pane.tab',()=>ctx.slots.register({name:'sidebar.right.pane.tab',key:'@dx/dsh-task'},TaskPanel));
|
|
ctx.slots.inject('sidebar.brand.name',()=>ctx.slots.register({name:'sidebar.brand.name',priority:-10},()=>h('span',null,'DSH助手')));
|
|
const current=ctx.sidebarRight.mounted;
|
|
ctx.effect(()=>{
|
|
let frame=0,attempts=0;
|
|
const open=()=>{
|
|
if(current.getSnapshot())try{ctx.sidebarRight.openTab('dx-task');if(ctx.sidebarRight.isExpanded())return;}catch{}
|
|
if(++attempts<120)frame=requestAnimationFrame(open);
|
|
};
|
|
const queue=()=>{cancelAnimationFrame(frame);attempts=0;frame=requestAnimationFrame(()=>{frame=requestAnimationFrame(open);});};
|
|
const stop=current.subscribe(queue);queue();return()=>{stop();cancelAnimationFrame(frame);};
|
|
},'dx-task: active session');
|
|
}};
|
|
}});
|