fix(dsh): restore native file tools and official loading UI
Core regression / Python core and release configuration (push) Successful in 20s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
Core regression / Python core and release configuration (push) Successful in 20s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
This commit is contained in:
1 parent
1340f6c233
commit
705c15eb93
19 files changed
+398
-42
No files matched your search
@@ -16,7 +16,9 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
||||
h('p',null,'在“模型”设置页添加模型提供商或自定义模型 API,填写地址后可获取可用模型,也可手动填写模型 ID。保存后在输入框下方选择,模型设置和会话在重启后保留。'),
|
||||
h('h3',null,'异常工单'),
|
||||
h('p',null,'随工具预置专用工单上报身份,无需安装 Git 或登录。未解决的异常自动提交项目工单,并上传脱敏诊断证据。'),
|
||||
h('p',null,'工程修改与执行核验由任务中心完成。模型不直接访问工程文件或执行命令。'));
|
||||
h('h3',null,'文件与文件夹'),
|
||||
h('p',null,'可上传文件、选择本地文件夹,或在对话中提供路径。助手可读取和搜索文件,ZIP 解压到新的文件夹后继续分析;重复解压不会覆盖已有文件。'),
|
||||
h('p',null,'工程修改与执行核验由任务中心完成。'));
|
||||
}
|
||||
function SettingsLauncher({wide,openSettings}){
|
||||
return h('button',{'data-testid':'dx-tool-settings',type:'button','aria-label':'工具设置',onClick:()=>openSettings(),
|
||||
@@ -276,8 +278,6 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
||||
},'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助手')));
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import {mkdir,mkdtemp,writeFile,realpath,rm} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {unzip} from 'fflate';
|
||||
import {defineTool} from '@deepseek-ai/dsh-tools';
|
||||
import {crc32} from 'node:zlib';
|
||||
|
||||
export const fileToolNames=['read','read_image','glob','grep','working_directory','extract_zip'];
|
||||
|
||||
function zipChecksums(bytes){
|
||||
const data=Buffer.from(bytes.buffer,bytes.byteOffset,bytes.byteLength);
|
||||
let end=data.length-22;
|
||||
for(;end>=Math.max(0,data.length-65557);end--)
|
||||
if(data.readUInt32LE(end)===0x06054b50&&end+22+data.readUInt16LE(end+20)===data.length)break;
|
||||
if(end<0||data.readUInt32LE(end)!==0x06054b50)throw Error('Invalid ZIP central directory');
|
||||
if(data.readUInt16LE(end+4)||data.readUInt16LE(end+6))throw Error('Multi-volume ZIP is unsupported');
|
||||
const count=data.readUInt16LE(end+10),entries=[];
|
||||
if(count===65535||count>10000)throw Error('ZIP exceeds 10000 entries');
|
||||
let offset=data.readUInt32LE(end+16);
|
||||
for(let i=0;i<count;i++){
|
||||
if(offset+46>end||data.readUInt32LE(offset)!==0x02014b50)throw Error('Invalid ZIP entry');
|
||||
if(data.readUInt16LE(offset+8)&1)throw Error('Encrypted ZIP is unsupported');
|
||||
const size=data.readUInt32LE(offset+24);
|
||||
if(size===0xffffffff)throw Error('ZIP64 entries are unsupported');
|
||||
entries.push({crc:data.readUInt32LE(offset+16),size});
|
||||
offset+=46+data.readUInt16LE(offset+28)+data.readUInt16LE(offset+30)+data.readUInt16LE(offset+32);
|
||||
if(offset>end)throw Error('Invalid ZIP entry length');
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
export function registerFileTools(ctx){
|
||||
ctx.tools.register(defineTool({name:'extract_zip',
|
||||
description:'Extract a local or uploaded ZIP archive into a new folder, returning its absolute path and file names. Relative paths use the conversation working directory. output_directory optionally selects an existing parent folder; defaults to the conversation working directory. Never overwrites existing files. Read the returned paths to inspect extracted content. ZIP only; encrypted archives are unsupported.',
|
||||
parameters:{file_path:{type:'string',required:true},output_directory:{type:'string'}},
|
||||
output:{schema:{type:'object',additionalProperties:true},render:(_args,value)=>[{type:'text',text:JSON.stringify(value)}]},
|
||||
execute:async(args,exec)=>{
|
||||
if(typeof args.file_path!=='string'||!args.file_path.trim())throw Error('file_path is required');
|
||||
const cwd=exec.agent?ctx.workingDirectory.get(exec.agent.session):process.env.DX_DSH_WORKSPACE;
|
||||
const target=await ctx.fs.resolve(args.file_path,{cwd,signal:exec.signal});
|
||||
const bytes=await ctx.fs.readBytes(target,exec.signal,64*1024*1024);
|
||||
const checksums=zipChecksums(bytes),expected=new Map();
|
||||
let expanded=0,count=0;
|
||||
const files=await new Promise((resolve,reject)=>unzip(bytes,{filter:entry=>{
|
||||
const name=entry.name.replaceAll('\\','/');
|
||||
if(name.startsWith('/')||name.split('/').some(part=>part==='..'||/[\x00-\x1f:]/.test(part)))
|
||||
throw Error('Unsafe ZIP entry path');
|
||||
if(expected.has(entry.name))throw Error('Duplicate ZIP entry');
|
||||
const checksum=checksums[count];
|
||||
if(!checksum||checksum.size!==entry.originalSize)throw Error('Invalid ZIP entry size');
|
||||
expected.set(entry.name,checksum);
|
||||
expanded+=entry.originalSize;
|
||||
if(++count>10000||expanded>256*1024*1024)throw Error('ZIP exceeds 10000 entries or 256 MiB expanded size');
|
||||
return true;
|
||||
}},(error,value)=>error?reject(error):resolve(value)));
|
||||
if(count!==checksums.length)throw Error('Invalid ZIP entry count');
|
||||
for(const [name,data] of Object.entries(files)){
|
||||
const checksum=expected.get(name);
|
||||
if(data.length!==checksum.size||crc32(data)!==checksum.crc)throw Error('ZIP checksum mismatch: '+name);
|
||||
}
|
||||
exec.signal.throwIfAborted();
|
||||
const parent=await realpath(path.resolve(cwd,args.output_directory||'.'));
|
||||
const directory=await mkdtemp(path.join(parent,'dsh-extracted-'));
|
||||
try{
|
||||
for(const [name,data] of Object.entries(files)){
|
||||
exec.signal.throwIfAborted();
|
||||
const output=path.resolve(directory,name.replaceAll('\\','/'));
|
||||
const relative=path.relative(directory,output);
|
||||
if(relative.startsWith('..')||path.isAbsolute(relative))throw Error('Unsafe ZIP entry path');
|
||||
if(name.endsWith('/'))await mkdir(output,{recursive:true});
|
||||
else{await mkdir(path.dirname(output),{recursive:true});await writeFile(output,data,{flag:'wx'});}
|
||||
}
|
||||
return {directory,files:Object.keys(files).slice(0,200),total_entries:count,truncated:count>200};
|
||||
}catch(error){
|
||||
// Only this invocation's newly created temporary output is removed.
|
||||
if(path.dirname(directory)===parent&&path.basename(directory).startsWith('dsh-extracted-'))
|
||||
await rm(directory,{recursive:true,force:true});
|
||||
throw error;
|
||||
}
|
||||
}}));
|
||||
}
|
||||
@@ -5,8 +5,9 @@ import {defineTool} from '@deepseek-ai/dsh-tools';
|
||||
import {registerLifecycle,lifecycleNames} from './lifecycle.mjs';
|
||||
import {registerRuntimeUsage} from './runtime_usage.mjs';
|
||||
import {modelSnapshot} from './model_results.mjs';
|
||||
import {registerFileTools,fileToolNames} from './files.mjs';
|
||||
|
||||
export const inject=['webServer','connection','tools','workspaceRegistry','sessionController','agents','llm'];
|
||||
export const inject=['webServer','connection','tools','workspaceRegistry','sessionController','agents','llm','fs','workingDirectory'];
|
||||
const actions=new Set(['retry_failed','pause_task','refresh_snapshot','retry_issue','open_evidence']);
|
||||
export async function readContext(){
|
||||
const value=JSON.parse(await readFile(process.env.DX_DSH_CONTEXT_FILE,'utf8'));
|
||||
@@ -19,7 +20,7 @@ export async function apply(ctx){
|
||||
const creations=new Map();
|
||||
let auditTail=Promise.resolve();
|
||||
ctx.on('tools/result',(exec,result)=>{
|
||||
if(!['dx_task_snapshot','dx_task_create',...lifecycleNames].includes(exec.name))return;
|
||||
if(!['dx_task_snapshot','dx_task_create',...lifecycleNames,...fileToolNames].includes(exec.name))return;
|
||||
const row={at:new Date().toISOString(),name:exec.name,call_id:exec.callId,is_error:result.isError,
|
||||
task_id:result.value?.task_id||'',revision:result.value?.revision||'',
|
||||
status:result.value?.status,task_ids:result.value?.task_ids||result.value?.tasks?.map(t=>t.task_id)||[]};
|
||||
@@ -112,7 +113,8 @@ export async function apply(ctx){
|
||||
}finally{clearTimeout(timer);exec.signal.removeEventListener('abort',cancel);creations.delete(request_id);}
|
||||
}}));
|
||||
registerLifecycle(ctx);
|
||||
ctx.tools.guard(exec=>exec.name==='dx_task_snapshot'||(['dx_task_create',...lifecycleNames].includes(exec.name)&&!incidentSnapshots.has(exec.agent?.id))?
|
||||
registerFileTools(ctx);
|
||||
ctx.tools.guard(exec=>exec.name==='dx_task_snapshot'||(['dx_task_create',...lifecycleNames,...fileToolNames].includes(exec.name)&&!incidentSnapshots.has(exec.agent?.id))?
|
||||
undefined:'This tool is not enabled for this session. Automatic incident sessions may only read their snapshot.');
|
||||
const workspace=await ctx.workspaceRegistry.create(process.env.DX_DSH_WORKSPACE,'DxDesigner 任务中心');
|
||||
ctx.webServer.register({kind:'exact',path:'/dx/workspace',handler:async(req,res)=>{
|
||||
|
||||
Reference in new issue
Block a user