308 lines
33 KiB
JavaScript
308 lines
33 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:'待配置',ready:'待执行',deleted:'已归档',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,...['在对话中创建和修改任务;具体工程与执行范围由原生窗口确认','实时监管当前执行、阶段、耗时与保存/失败/未命中计数','保存执行回执,重启后核对原队列并手动确认恢复','预览精确位号影响;仅有料号映射时明确标记未知匹配数量','检索历史异常经验,仅将持久化核验通过的记录标为已验证','只读同步已有 Git 工单状态与评论,查看本地证据','查看会话 Token、耗时与超时状态,配置响应时限并停止模型生成','设置任务优先级、执行时间与依赖,通过原生窗口确认排期'].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 OverviewPanel({data,notice,request,perform}){
|
||
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));
|
||
const health=data?.operations?.health;
|
||
const decisions=data?.operations?.decisions||[];
|
||
const audit=data?.operations?.decision_audit;
|
||
const auditUnavailable=audit&&['corrupt','unavailable'].includes(audit.status);
|
||
const healthText=health?.checks?.map(row=>`${row.name}: ${row.status} · ${row.message}`).join('\n')||'正在读取运行健康…';
|
||
return h('div',{'data-testid':'dx-task-overview'},
|
||
section('当前任务',data?(data.task_name||data.task_id||'尚未选择任务'):'读取中…'),
|
||
h('section',{'data-testid':'dx-health-summary',style:{marginBottom:24}},
|
||
h('h3',{style:{fontSize:14,fontWeight:500,marginBottom:10}},'运行健康 · '+(health?.status||'读取中')),
|
||
h('div',{style:{whiteSpace:'pre-wrap',color:'var(--dsw-alias-label-secondary)',lineHeight:1.8}},healthText),
|
||
h('button',{'data-testid':'dx-health-refresh',type:'button',onClick:()=>perform({operation:'health'}),style:{...buttonStyle,marginTop:8}},'重新检查健康状态')),
|
||
h('section',{'data-testid':'dx-decision-timeline',style:{marginBottom:24}},
|
||
h('h3',{style:{fontSize:14,fontWeight:500,marginBottom:10}},'自动处理决策记录'),
|
||
auditUnavailable?h('p',{'data-testid':'dx-decision-audit-error',role:'status',style:{fontSize:12,lineHeight:1.7}},audit.message):
|
||
decisions.length?decisions.slice(0,5).map(row=>h('p',{key:row.record_hash,style:{fontSize:12,lineHeight:1.7,margin:'6px 0'}},`#${row.sequence} · ${row.trigger} · ${row.outcome} · ${row.human_takeover?'人工接管':'自动策略'}`)):h('p',{style:{fontSize:12,color:'var(--dsw-alias-label-secondary)'}},'暂无自动处理记录。'),
|
||
h('button',{'data-testid':'dx-decisions-refresh',type:'button',onClick:()=>perform({operation:'decisions'}),style:{...buttonStyle,marginTop:8}},'刷新决策记录')),
|
||
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')||'等待任务事件'));
|
||
}
|
||
const secondary='var(--dsw-alias-label-secondary)';
|
||
const border='1px solid var(--dsw-alias-border-l2)';
|
||
const buttonStyle={border,background:'var(--dsw-alias-bg-base)',color:'var(--dsw-alias-label-primary)',borderRadius:8,padding:'7px 10px',font:'inherit',fontSize:12,cursor:'pointer'};
|
||
const stateNames={...names,pending:'待执行',claimed:'已领取',interrupted:'执行中断',cancelled:'已取消',synced:'已同步',not_synced:'尚未同步',unavailable:'暂不可用',open:'处理中',closed:'已关闭',idle:'待命',generating:'生成中',timeout:'响应超时',error:'出错',finished:'已结束'};
|
||
const blockers={queue_missing:'原队列检查点不存在',queue_invalid:'原队列证据无效',interrupted:'存在待核验步骤',failed_items:'仍有失败项',plan_changed:'保存计划已变化',task_unavailable:'任务不可用',task_paused:'任务已手动暂停,请先核对并接续原执行',not_due:'尚未到执行时间',worker_busy:'执行器忙碌',already_claimed:'排期已被领取',finished:'排期已结束',preflight_blocked:'执行预检未通过',preflight_unavailable:'执行预检不可用',dependency_incomplete:'依赖任务尚未完成并通过核验'};
|
||
const display=value=>value===null||value===undefined||value===''?'未报告':String(value);
|
||
const status=value=>stateNames[value]||display(value);
|
||
const count=value=>Number.isFinite(value)?value.toLocaleString():'未报告';
|
||
const time=value=>{if(!value)return '未设置';const stamp=new Date(value);return Number.isNaN(stamp.getTime())?String(value):stamp.toLocaleString();};
|
||
const elapsed=value=>Number.isFinite(value)?`${Math.max(0,Math.floor(value))} 秒`:'未报告';
|
||
const detail=(label,value)=>h('p',{style:{fontSize:12,lineHeight:1.7,margin:'5px 0',overflowWrap:'anywhere'}},h('span',{style:{color:secondary}},label+':'),value);
|
||
const empty=text=>h('p',{style:{fontSize:12,lineHeight:1.8,color:secondary}},text);
|
||
const card=(key,title,...children)=>h('section',{key,style:{border,borderRadius:10,padding:12,marginBottom:12,overflowWrap:'anywhere'}},h('h3',{style:{fontSize:13,margin:'0 0 8px',fontWeight:500}},title),...children);
|
||
const button=(testid,title,onClick,disabled=false)=>h('button',{'data-testid':testid,type:'button',disabled,onClick,style:{...buttonStyle,opacity:disabled?0.5:1}},title);
|
||
const actions=(...children)=>h('div',{style:{display:'flex',flexWrap:'wrap',gap:8,margin:'10px 0'}},...children);
|
||
const counterLine=value=>`已保存 ${count(value?.saved_items)} · 失败 ${count(value?.failed_items)} · 未命中 ${count(value?.no_match_items)}`;
|
||
const blockerList=values=>values?.length?detail('阻断原因',values.map(value=>blockers[value]||value).join(';')):null;
|
||
function ImpactPanel({report,scope,perform,pending}){
|
||
const rows=report?.rows||[];
|
||
const policy=row=>row.value_policy==='preserve'?'保留原 Value':row.value_policy==='custom'?'自定义 Value':'复制元件库标签(实际值待执行读取)';
|
||
const columns=['范围','工程 / 图页','位号 / UID','旧料号 → 新料号','旧 Value → 拟议 Value','Cell / NC'];
|
||
return h('div',{'data-testid':'dx-operations-impact'},
|
||
actions(button('dx-impact-refresh','查看当前任务影响',()=>perform({operation:'impact',task_ids:scope}),pending||!scope.length)),
|
||
!report?empty('选择任务后查看保存计划中的影响范围。'):h(React.Fragment,null,
|
||
detail('范围',report.coverage==='exact'?'已保存的精确位号计划':report.coverage==='mapping_only'?'仅料号映射':'精确位号与料号映射'),
|
||
detail('元件数量',report.component_count===null?'未知:映射尚未收集匹配元件':count(report.component_count)),
|
||
report.component_count===null&&detail('已知位号范围',count(report.known_component_count)),
|
||
detail('已启用范围',`${count(report.enabled_scope)} 条位号 / 映射`),
|
||
empty('按已保存计划展示。仅有料号映射时,匹配元件的数量、位号和 UID 尚未知。'),
|
||
h('div',{style:{overflowX:'auto'}},h('table',{'data-testid':'dx-impact-table',style:{borderCollapse:'collapse',width:'100%',fontSize:11,textAlign:'left'}},
|
||
h('thead',null,h('tr',null,...columns.map(title=>h('th',{key:title,style:{borderBottom:border,padding:8,whiteSpace:'nowrap',fontWeight:500}},title)))),
|
||
h('tbody',null,...rows.map((row,index)=>h('tr',{key:row.task_id+':'+(row.uid||index),'data-testid':'dx-impact-row',style:{opacity:row.enabled?1:.6}},
|
||
h('td',{style:{padding:8,borderBottom:border}},row.enabled?'已启用':'已禁用',h('br'),row.coverage==='mapping_only'?'映射 · 数量未知':`${row.component_count} 个元件`),
|
||
h('td',{style:{padding:8,borderBottom:border,overflowWrap:'anywhere'}},row.project||'工程范围未知',h('br'),row.coverage==='mapping_only'?'图页未知':`${row.schematic_name} / ${row.sheet}`),
|
||
h('td',{style:{padding:8,borderBottom:border}},row.refdes||'位号未知',h('br'),row.uid||'UID 未知'),
|
||
h('td',{style:{padding:8,borderBottom:border}},row.old_part_number+' → '+row.new_part_number),
|
||
h('td',{style:{padding:8,borderBottom:border}},(row.old_value===null?'未知':display(row.old_value))+' → '+(row.proposed_value===null?'待执行读取':display(row.proposed_value)),h('br'),policy(row)),
|
||
h('td',{style:{padding:8,borderBottom:border}},row.target_cell||'按保存的默认 Cell 策略',h('br'),row.sync_nc?'同步 NC':'保留 NC')))))),
|
||
!rows.length&&empty('保存范围内没有位号或映射行。'),
|
||
detail('显示范围',`${count(report.returned_rows)} / ${count(report.total_rows)} 行${report.truncated?`,省略 ${count(report.omitted_row_count)} 行`:''}`),
|
||
report.truncated&&empty('完整计划哈希包含省略的行。'),
|
||
h('details',null,h('summary',{style:{fontSize:12,cursor:'pointer'}},'范围与计划凭据'),
|
||
detail('完整范围指纹',report.full_fingerprint||report.fingerprint),
|
||
...Object.entries(report.plan_hashes||{}).map(([id,hash])=>h('p',{key:id,style:{fontSize:10,overflowWrap:'anywhere'}},id+':'+hash)))));
|
||
}
|
||
function RunningPanel({operations,perform,pending,request}){
|
||
const run=operations.live_run||{},last=operations.last_execution;
|
||
return h('div',{'data-testid':'dx-operations-running'},
|
||
card('live','当前执行',detail('状态',run.active?'执行中':'当前无执行中的队列'),
|
||
detail('任务',run.name||run.task_id||'—'),detail('执行编号',run.run_id||'—'),
|
||
detail('阶段',run.stage||'—'),run.message&&detail('进度说明',run.message),detail('耗时',elapsed(run.elapsed_seconds)),
|
||
detail('实际结果',counterLine(run)),detail('步骤',`${count(run.completed_items)} / ${count(run.total_items)}`),
|
||
run.pause_requested&&empty('已请求安全暂停,当前步骤结束后停止。'),
|
||
run.active&&button('dx-running-pause',run.pause_requested?'已请求安全暂停':'安全暂停',()=>perform({operation:'pause',task_ids:run.task_ids||[]}),run.pause_requested||!run.task_ids?.length)),
|
||
last&&card('last','最近一次执行回执',detail('状态',status(last.status)),
|
||
...(last.tasks||[]).map(task=>h('div',{key:task.task_id,style:{marginTop:8}},detail('任务',task.name||task.task_id),detail('实际结果',counterLine(task)),blockerList(task.blockers))),
|
||
!last.tasks?.length&&detail('实际结果',counterLine(last))),
|
||
actions(button('dx-history-refresh','刷新执行历史',()=>perform({operation:'history'}),pending)),
|
||
...(operations.runs||[]).map(row=>card(row.run_id,'执行 '+row.run_id,
|
||
detail('状态',status(row.status)),detail('开始时间',time(row.started_utc)),detail('原任务顺序',(row.task_ids||[]).join(' → ')),
|
||
detail('实际结果',counterLine(row.counters)),
|
||
...(row.tasks||[]).map(task=>h('p',{key:task.task_id,style:{fontSize:11}},(task.name||task.task_id)+' · '+counterLine(task))),
|
||
blockerList(row.blockers),row.resume_ready===true?button('dx-resume-'+row.run_id,'核对并恢复原队列',()=>perform({operation:'resume',run_id:row.run_id}),pending):empty('当前没有可直接恢复的原队列。'))),
|
||
!operations.runs?.length&&empty('暂无保存的执行历史。'));
|
||
}
|
||
function SchedulesPanel({operations,scope,perform,pending}){
|
||
const priorities={low:'低',normal:'普通',high:'高',urgent:'紧急'};
|
||
return h('div',{'data-testid':'dx-operations-schedules'},
|
||
actions(button('dx-schedule-new','为当前任务设置排期',()=>perform({operation:'schedule_dialog',task_ids:scope}),pending||!scope.length),
|
||
button('dx-schedules-refresh','刷新排期',()=>perform({operation:'refresh'}),pending)),
|
||
empty('时间按本机时区显示。排期在工具打开期间检查,执行前仍需核对保存范围与实际预检。'),
|
||
operations.schedule_audit?.status==='ok'&&empty(`排期审计:近期 ${operations.schedule_audit.live_events} 条,已归档 ${operations.schedule_audit.archived_events} 条;旧记录完整保留在本地审计归档。`),
|
||
operations.schedule_audit?.status==='unavailable'&&empty('排期审计归档不可用,请保留现有记录并核对本地归档。'),
|
||
...(operations.schedules||[]).map(row=>card(row.schedule_id,row.title||'任务排期',
|
||
detail('状态',status(row.status)),detail('优先级',priorities[row.priority]||display(row.priority)),detail('不早于',time(row.not_before)),
|
||
detail('截止时间',time(row.due_at)),detail('任务',(row.task_ids||[]).join(' → ')),detail('依赖',(row.dependencies||[]).join('、')||'无'),
|
||
detail('执行方式',row.auto_start?'已保存自动启动意图,依原生授权与预检执行':'等待手动确认'),
|
||
blockerList(row.blockers),actions(
|
||
button('dx-schedule-run-'+row.schedule_id,'核对并执行',()=>perform({operation:'run_schedule',schedule_id:row.schedule_id}),pending||row.ready!==true),
|
||
row.status==='claimed'&&button('dx-schedule-reconcile-'+row.schedule_id,'核对并收尾失联排期',()=>perform({operation:'reconcile_schedule',schedule_id:row.schedule_id}),pending),
|
||
button('dx-schedule-cancel-'+row.schedule_id,'取消排期',()=>perform({operation:'cancel_schedule',schedule_id:row.schedule_id}),pending||row.status!=='pending')))),
|
||
!operations.schedules?.length&&empty('暂无排期。'),
|
||
...(operations.schedule_events||[]).slice(0,10).map(row=>card('schedule-event-'+row.sequence,
|
||
row.event==='dispatch'?'排期派发记录':'排期结果记录',
|
||
detail('时间',time(row.at_utc)),detail('排期',row.schedule_id),detail('执行',row.run_id),
|
||
detail('授权',row.payload?.authority==='native_future_authorization'?'原生预先授权':row.payload?.authority==='native_confirmation'?'原生即时确认':'—'),
|
||
detail('结果',status(row.payload?.status||'claimed')))));
|
||
}
|
||
function ExperiencesPanel({operations,perform,pending}){
|
||
const[query,setQuery]=React.useState('');
|
||
return h('div',{'data-testid':'dx-operations-experiences'},
|
||
h('label',{style:{fontSize:12}},'异常代码或关键词',h('input',{'data-testid':'dx-experience-query',value:query,onChange:event=>setQuery(event.target.value),maxLength:160,placeholder:'留空查看已有经验',style:{...buttonStyle,width:'100%',boxSizing:'border-box',marginTop:8,cursor:'text'}})),
|
||
actions(button('dx-experience-search','检索本地经验',()=>perform({operation:'experience',issue_code:query}),pending)),
|
||
...(operations.experiences||[]).map(row=>card(row.incident_id,row.issue_code||'异常经验',
|
||
h('span',{'data-testid':'dx-experience-verification',style:{fontSize:11,padding:'3px 7px',border,borderRadius:6}},row.verified===true?'已验证':'未验证'),
|
||
detail('任务',row.task_name||row.task_id),detail('异常',row.message||'—'),
|
||
...(row.analyses||[]).map((analysis,index)=>h('p',{key:index,style:{fontSize:12,whiteSpace:'pre-wrap'}},analysis.phase+':'+analysis.reply)),
|
||
row.retry_skipped&&detail('处理限制',row.retry_skipped),
|
||
row.verification&&detail('核验结果',counterLine(row.verification)),
|
||
detail('证据',(row.evidence_refs||[]).join('\n')||'暂无持久化证据'),
|
||
button('dx-experience-open-'+row.incident_id,'打开事件证据',()=>perform({operation:'open_incident',incident_id:row.incident_id}),pending))),
|
||
!operations.experiences?.length&&empty('暂无匹配的本地经验。经验建议不代表已授权执行。'));
|
||
}
|
||
function TicketsPanel({operations,perform,pending}){
|
||
return h('div',{'data-testid':'dx-operations-tickets'},
|
||
actions(button('dx-tickets-refresh','读取工单列表',()=>perform({operation:'tickets'}),pending)),
|
||
empty('仅同步已有事件绑定的工单。工单关闭是反馈,本地修复结果以实际核验为准。'),
|
||
...(operations.tickets||[]).map(row=>card(row.incident_id,row.title||('工单 '+(row.number||'')),
|
||
detail('工单状态',status(row.state)),detail('同步状态',status(row.status)),detail('上次同步',time(row.last_sync_at)),
|
||
detail('工单地址',row.url||'尚未获取'),row.error&&detail('同步问题',row.error),
|
||
...(row.comments||[]).map((comment,index)=>h('blockquote',{key:comment.id||index,style:{margin:'10px 0',paddingLeft:10,borderLeft:border,fontSize:12}},
|
||
h('p',{style:{color:secondary}},display(comment.user?.login)+' · '+time(comment.updated_at||comment.created_at)),
|
||
h('p',{style:{whiteSpace:'pre-wrap'}},comment.body))),
|
||
actions(button('dx-ticket-sync-'+row.incident_id,'同步状态与评论',()=>perform({operation:'refresh_ticket',incident_id:row.incident_id}),pending),
|
||
button('dx-ticket-evidence-'+row.incident_id,'打开事件证据',()=>perform({operation:'open_incident',incident_id:row.incident_id}),pending)))),
|
||
!operations.tickets?.length&&empty('暂无已缓存的工单。'));
|
||
}
|
||
function UsagePanel({runtime,control,pending}){
|
||
const[timeout,setTimeoutValue]=React.useState('90'),[contextLimit,setContextLimit]=React.useState('16000');
|
||
React.useEffect(()=>{if(runtime?.settings){setTimeoutValue(String(runtime.settings.response_timeout_seconds));setContextLimit(String(runtime.settings.model_context_limit));}},[runtime?.settings?.response_timeout_seconds,runtime?.settings?.model_context_limit]);
|
||
const inputStyle={...buttonStyle,width:'100%',boxSizing:'border-box',cursor:'text',marginTop:6};
|
||
return h('div',{'data-testid':'dx-operations-usage'},
|
||
empty('Token 取自会话运行事件;供应商未报告的数据保持未知。停止生成仅停止模型响应,已确认的工程执行仍由任务中心管理。'),
|
||
...((runtime?.sessions)||[]).map(row=>card(row.session_id,'会话 '+row.session_id,
|
||
detail('状态',status(row.status)),detail('耗时',elapsed(row.elapsed_seconds)),
|
||
detail('输入 Token',count(row.input_tokens)),detail('输出 Token',count(row.output_tokens)),detail('缓存 Token',count(row.cached_tokens)),detail('总 Token',count(row.total_tokens)),
|
||
detail('费用',row.price===null||row.price===undefined?'未提供':String(row.price)),
|
||
button('dx-generation-cancel-'+row.session_id,'停止生成',()=>control({action:'cancel',session_id:row.session_id}),pending||!['running','generating'].includes(row.status)))),
|
||
!runtime?.sessions?.length&&empty('暂无已报告的会话用量。'),
|
||
card('settings','响应设置',h('label',{style:{display:'block',fontSize:12,marginBottom:12}},'响应超时(秒)',h('input',{'data-testid':'dx-response-timeout',type:'number',min:15,max:600,step:1,value:timeout,onChange:event=>setTimeoutValue(event.target.value),style:inputStyle})),
|
||
h('label',{style:{display:'block',fontSize:12,marginBottom:12}},'原生上下文压缩阈值(Token)',h('input',{'data-testid':'dx-context-limit',type:'number',min:2000,max:128000,step:1000,value:contextLimit,onChange:event=>setContextLimit(event.target.value),style:inputStyle})),
|
||
button('dx-usage-configure','保存响应设置',()=>control({action:'configure',response_timeout_seconds:Number(timeout),model_context_limit:Number(contextLimit)}),
|
||
pending||!Number.isInteger(Number(timeout))||Number(timeout)<15||Number(timeout)>600||!Number.isInteger(Number(contextLimit))||Number(contextLimit)<2000||Number(contextLimit)>128000)));
|
||
}
|
||
function TaskPanel(){
|
||
const[data,setData]=React.useState(null),[notice,setNotice]=React.useState(''),[tab,setTab]=React.useState('overview'),[pending,setPending]=React.useState(false),[runtime,setRuntime]=React.useState(null);
|
||
React.useEffect(()=>{
|
||
let live=true;
|
||
const read=()=>fetch('/dx/context',{credentials:'same-origin'}).then(response=>{if(!response.ok)throw Error();return response.json();}).then(value=>{if(live)setData(value);}).catch(()=>{if(live)setNotice('任务上下文暂不可用');});
|
||
read();const timer=setInterval(read,1500);return()=>{live=false;clearInterval(timer);};
|
||
},[]);
|
||
React.useEffect(()=>{
|
||
if(tab!=='usage')return;
|
||
let live=true;
|
||
const read=()=>fetch('/dx/runtime',{credentials:'same-origin'}).then(response=>{if(!response.ok)throw Error();return response.json();}).then(value=>{if(live)setRuntime(value);}).catch(()=>{if(live)setNotice('会话用量暂不可用');});
|
||
read();const timer=setInterval(read,2000);return()=>{live=false;clearInterval(timer);};
|
||
},[tab]);
|
||
async function post(path,payload){
|
||
if(pending)return;
|
||
setPending(true);setNotice('正在交给任务中心…');
|
||
try{
|
||
const response=await fetch(path,{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(payload)});
|
||
setNotice(response.ok?'请求已交给任务中心;如需确认,请核对原生窗口。':response.status===409?'状态已变化或另一个操作正在进行,请核对最新记录后重试。':'请求未完成,请核对任务中心记录。');
|
||
}catch{setNotice('任务服务暂不可用,请稍后重试。');}
|
||
finally{setPending(false);}
|
||
}
|
||
const perform=async spec=>{
|
||
if(!data||pending)return;
|
||
try{
|
||
// Live progress is published faster than this dock polls. Refresh the
|
||
// admission revision at the click without changing the clicked scope.
|
||
const fresh=await fetch('/dx/context',{credentials:'same-origin'}).then(r=>r.json());
|
||
if(fresh.task_id!==data.task_id){setData(fresh);setNotice('任务选择已变化,请核对后重新点击。');return;}
|
||
setData(fresh);await post('/dx/operations',{revision:fresh.revision,spec});
|
||
}catch{setNotice('任务上下文暂不可用,请稍后重试。');}
|
||
};
|
||
const request=action=>data&&post('/dx/action',{action,task_id:data.task_id,revision:data.revision});
|
||
const control=spec=>post('/dx/runtime/control',spec);
|
||
const operations=data?.operations||{},scope=data?.task_id?[data.task_id]:[];
|
||
const tabs=[['overview','概览'],['running','运行'],['impact','影响'],['schedules','排期'],['experiences','经验'],['tickets','工单'],['usage','用量']];
|
||
return h('div',{'data-testid':'dx-task-panel','data-task-id':data?.task_id||'',style:{padding:20,overflow:'auto',height:'100%',boxSizing:'border-box'}},
|
||
h('div',{role:'tablist','aria-label':'任务监管',style:{display:'flex',flexWrap:'wrap',gap:4,marginBottom:18,paddingBottom:10,borderBottom:border}},
|
||
...tabs.map(([id,title])=>h('button',{key:id,id:'dx-tab-'+id,role:'tab',type:'button','data-testid':'dx-operations-tab-'+id,'aria-selected':tab===id,'aria-controls':'dx-pane-'+id,onClick:()=>setTab(id),style:{...buttonStyle,border:tab===id?border:'1px solid transparent',fontWeight:tab===id?600:400,color:tab===id?'var(--dsw-alias-label-primary)':secondary}},title))),
|
||
h('div',{role:'tabpanel',id:'dx-pane-'+tab,'aria-labelledby':'dx-tab-'+tab},
|
||
tab==='overview'?h(OverviewPanel,{data,notice,request,perform}):
|
||
tab==='running'?h(RunningPanel,{operations,perform,pending:pending||operations.busy,request}):
|
||
tab==='impact'?h(ImpactPanel,{report:operations.impact,scope,perform,pending:pending||operations.busy}):
|
||
tab==='schedules'?h(SchedulesPanel,{operations,scope,perform,pending:pending||operations.busy}):
|
||
tab==='experiences'?h(ExperiencesPanel,{operations,perform,pending:pending||operations.busy}):
|
||
tab==='tickets'?h(TicketsPanel,{operations,perform,pending:pending||operations.busy}):h(UsagePanel,{runtime,control,pending})),
|
||
tab!=='overview'&&h('p',{'data-testid':'dx-operations-notice',role:'status',style:{fontSize:12,color:secondary,lineHeight:1.8,whiteSpace:'pre-wrap'}},operations.activity?.message||notice||''));
|
||
}
|
||
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 timer=0,live=true,connecting=false,adopted=false,openedSession;
|
||
const open=()=>{
|
||
if(!live)return;
|
||
const sessionId=current.getSnapshot();
|
||
if(sessionId){
|
||
if(openedSession===sessionId)return;
|
||
try{ctx.sidebarRight.openTab('dx-task');if(ctx.sidebarRight.isExpanded()){openedSession=sessionId;return;}}catch{}
|
||
}else if(!connecting&&!adopted){
|
||
connecting=true;
|
||
fetch('/dx/workspace').then(r=>{if(!r.ok&&r.ok!==undefined)throw Error();return r.json();}).then(value=>{
|
||
if(live&&!current.getSnapshot()&&typeof value.workspace_id==='string'){
|
||
adopted=true;return ctx.uiWorkspace.openWorkspace(value.workspace_id);
|
||
}
|
||
}).catch(()=>{adopted=false;}).finally(()=>{connecting=false;if(live)queue();});
|
||
}
|
||
timer=setTimeout(open,100);
|
||
};
|
||
const queue=()=>{clearTimeout(timer);timer=setTimeout(open,0);};
|
||
const stop=current.subscribe(queue);queue();return()=>{live=false;stop();clearTimeout(timer);};
|
||
},'dx-task: active session');
|
||
}};
|
||
}});
|