Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/qa/workflow-drafts/draft-after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/qa/workflow-drafts/draft-before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 3 additions & 11 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1876,17 +1876,9 @@ function rememberOpenWorkflow(){
async function applyFlowRoute(){
const id=flowRouteId();
if(!id||state.workflow?.id===id)return;
const wf=openableWorkflow(id);
if(!wf){rememberOpenWorkflow();return}
if(state.workflowDirty&&!(await afConfirm({title:'未保存更改',message:'当前流程有未保存修改,切换将放弃这些修改。继续?',danger:true}))){rememberOpenWorkflow();return}
if(flowRouteId()!==id)return;
state.workflow=clone(wf);
state.workflowSaved=clone(wf);
state.workflowDirty=false;
state.selectedNode=null;
localStorage.setItem('agentflow.activeWorkflow',id);
renderWorkflowMeta();renderCanvas();renderProperties();
refreshGenericWorkflowRoles();
if(!openableWorkflow(id)){rememberOpenWorkflow();return}
const changed=await switchFlowWorkflow(id,{fromRoute:true});
if(!changed&&flowRouteId()===id)rememberOpenWorkflow();
}
function runViewHash(id){return id?`#/runs/${encodeURIComponent(id)}`:'#/runs'}
function syncRunHash(id){
Expand Down
2 changes: 1 addition & 1 deletion web/app/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function commandCatalog(){
const pages=[['collaboration','AI 工作台','和 AI 对话,派发与跟进任务'],['issues','需求列表','查看进度,触发或重试'],['approvals','待我确认','批准或退回卡住的需求'],['observability','统计','用量分析 · Token 与质量'],['settings','个人配置','账号、模型与执行凭据'],['projects','项目配置','项目、成员和仓库'],['bots','通道管理','企业微信单聊或群聊通知通道'],['sops','流程模板','Issue 修复与需求开发'],['runs','运行记录','查看节点日志和产物'],['aiSchedules','定时任务','提示词任务、SOP 触发与共享任务'],['agents','角色定义','管理角色和能力资产'],['mcp','能力资产 · MCP','添加项目级或个人 MCP'],['rules','能力资产 · 规则','当前项目的行为与执行约束'],['skills','能力资产 · 技能','当前项目的技能和附加文件'],['runners','执行机器','用自己的电脑或 CVM 跑任务'],['dockerfiles','环境资产 · Dockerfile','管理项目容器构建定义'],['environments','环境资产 · 安装脚本','管理隔离环境的工具安装脚本'],['sandboxes','环境资产 · 沙箱','管理项目运行隔离策略'],['guide','访问密钥','创建和撤销访问密钥']].map(([view,title,meta])=>({kind:'页面',title,meta,action:()=>switchView(view)}));
const issues=(state.data.issues||[]).map(i=>({kind:'需求',title:i.title,meta:`${i.priority||'—'} · ${issueStatusLabel(i.status)}`,action:()=>openIssueDetail(i.id)}));
const runs=sopRuns(state.data.runs).map(r=>({kind:'运行',title:runIssueTitle(r),meta:`${runDisplayStatus(r)} · ${r.workflowSnapshot?.name||r.workflowId}`,action:()=>openRunFromId(r.id)}));
const sops=catalogWorkflows().map(w=>({kind:'SOP',title:w.name,meta:`${w.status==='published'?'已发布':'草稿'} · ${w.nodes?.length||0} 个节点`,action:()=>{state.workflow=clone(w);state.selectedNode=null;switchView('flow')}}));
const sops=catalogWorkflows().map(w=>({kind:'SOP',title:w.name,meta:`${w.status==='published'?'已发布':'草稿'} · ${w.nodes?.length||0} 个节点`,action:()=>openSOPDesigner(w.id)}));
const agents=(state.data.agents||[]).map(a=>({kind:'Agent',title:a.name,meta:a.description||a.id,action:()=>{switchView('agents');openAgentWizard(a)}}));
const actions=[{kind:'操作',title:'新建 SOP',meta:'创建流程草稿',action:openSOPWizard}];
return [...actions,...pages,...issues,...runs,...sops,...agents];
Expand Down
21 changes: 16 additions & 5 deletions web/app/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,24 @@ function renderWorkflowMeta(){
renderFlowHeader();
if(typeof flowPalette!=='undefined')flowPalette.render();
}
async function switchFlowWorkflow(id){
if(!id||id===state.workflow?.id)return false;
async function switchFlowWorkflow(id,{openDesigner=false,fromRoute=false,missing='SOP 不存在或已删除'}={}){
if(!id)return false;
if(id===state.workflow?.id){
if(openDesigner)switchView('flow');
return false;
}
const next=(state.data?.workflows||[]).find(w=>w.id===id);
if(!next){toast('SOP 不存在或已删除');return false}
if(state.workflowDirty&&!(await afConfirm({title:'放弃修改并切换流程?',message:'当前流程有未保存修改。切换后将丢弃这些修改。',danger:true,confirmText:'放弃修改并切换',cancelText:'继续编辑'}))){renderWorkflowMeta();return false}
if(!next){toast(missing);return false}
if(state.workflowDirty){
const discard=await afConfirm({title:'放弃修改并切换流程?',message:'当前流程有未保存修改。切换后将丢弃这些修改。',danger:true,confirmText:'放弃修改并切换',cancelText:'继续编辑'});
if(!discard){renderWorkflowMeta();return false}
}
if(fromRoute&&flowRouteId()!==id)return false;
state.workflow=clone(next);state.selectedNode=null;state.connectFrom=null;state.connectCursor=null;state.renamingNode=null;
markWorkflowClean();flowHistory.clear();rememberOpenWorkflow();renderAll();refreshGenericWorkflowRoles();
markWorkflowClean();flowHistory.clear();clearGenericTemplateAgents();
if(openDesigner)switchView('flow');
renderAll();
await refreshGenericWorkflowRoles();
return true;
}
function sopWorkflowChoices(exceptId){
Expand Down
9 changes: 2 additions & 7 deletions web/app/sops.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ function restoreSOPCatalogFocus(root,focus){
}
function liveSOPCards(root){return [...root.querySelectorAll('.sop-card:not(.is-leaving)')]}
function openSOPDesigner(id,missing='SOP 不存在或已删除'){
const wf=(state.data.workflows||[]).find(x=>x.id===id);
if(!wf)return toast(missing);
state.workflow=clone(wf);state.selectedNode=null;renderWorkflowMeta();renderCanvas();renderProperties();switchView('flow');
return switchFlowWorkflow(id,{openDesigner:true,missing});
}
function activateSOPCard(card){
if(card.dataset.genericId)openGenericTemplateModal(card.dataset.genericId);
Expand Down Expand Up @@ -406,10 +404,7 @@ async function openGenericTemplateEditor(id){
const w=(state.data?.workflows||[]).find(x=>x.id===id&&catalogGeneric(x));
if(!w)return toast('通用模板不存在或已下架');
if(!isPlatformAdmin())return toast('只有平台管理员可以编辑通用模板');
state.workflow=clone(w);state.selectedNode=null;markWorkflowClean();
clearGenericTemplateAgents();
renderWorkflowMeta();renderCanvas();renderProperties();switchView('flow');
await refreshGenericWorkflowRoles();
return openSOPDesigner(id);
}
function openGenericTemplateModal(id){
const w=(state.data?.workflows||[]).find(x=>x.id===id&&catalogGeneric(x));
Expand Down
7 changes: 3 additions & 4 deletions web/sop_catalog_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ Object.assign(ctx, {
createElement: tag => new FakeEl(tag),
addEventListener: (type, fn) => (docListeners[type] ||= []).push(fn),
},
clone: v => JSON.parse(JSON.stringify(v)),
renderWorkflowMeta() {}, renderCanvas() {}, renderProperties() {},
switchView: name => switched.push(name),
switchFlowWorkflow(id, {openDesigner}) { switched.push({id,openDesigner}); },
toast() {},
});
Object.assign(ctx.window, { innerWidth: 1280, innerHeight: 800, addEventListener() {} });
Expand All @@ -244,11 +242,12 @@ assert.ok(menuOpen() && moreA.attrs['aria-expanded'] === 'true', '⋯ opens the
click(openB);
assert.ok(!menuOpen(), 'opening another card closes the menu');
assert.strictEqual(moreA.attrs['aria-expanded'], 'false');
assert.deepStrictEqual(switched, ['flow']);
assert.deepStrictEqual(switched, [{id:'own-shared',openDesigner:true}]);

click(moreA);
click(cardB);
assert.ok(!menuOpen(), 'clicking another card body closes the menu');
assert.deepStrictEqual(switched[1], {id:'own-shared',openDesigner:true});

click(moreA);
ctx.hideSOPCardMenu();
Expand Down
18 changes: 18 additions & 0 deletions webtest/tests/flows-editor.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,21 @@ test('switching workflows explicitly offers to discard edits or continue editing
app.document.querySelector('#confirmCancelBtn').click();
assert.equal(await pending,false);
});

test('search and catalog retain the current SOP draft until the user changes it explicitly',async(t)=>{
const app=await loadApp();t.after(app.close);
app.evaluate(`state.data.workflows=[{id:'draft-a',name:'Alpha',nodes:[],edges:[]},{id:'draft-b',name:'Beta',nodes:[],edges:[]}];
state.workflow={...state.data.workflows[0],name:'Edited Alpha'};state.workflowDirty=true;`);
await app.evaluate(`openSOPDesigner('draft-a')`);
assert.equal(app.evaluate('state.workflow.name'),'Edited Alpha');
const search=app.evaluate(`commandCatalog().find(item=>item.kind==='SOP'&&item.title==='Beta').action()`);
assert.equal(app.document.querySelector('#confirmModal').classList.contains('open'),true);
app.document.querySelector('#confirmCancelBtn').click();await search;
assert.equal(app.evaluate('state.workflowDirty'),true);
assert.equal(app.evaluate('state.workflow.name'),'Edited Alpha');
const catalog=app.evaluate(`openSOPDesigner('draft-b')`);
app.document.querySelector('#confirmOkBtn').click();await catalog;
assert.equal(app.evaluate('state.workflow.id'),'draft-b');
assert.equal(app.evaluate('state.workflowSaved.id'),'draft-b');
assert.equal(app.evaluate('state.workflowDirty'),false);
});
Loading