Files
iven 92e5def702
Some checks failed
CI / Check / macos-latest (push) Has been cancelled
CI / Check / ubuntu-latest (push) Has been cancelled
CI / Check / windows-latest (push) Has been cancelled
CI / Test / macos-latest (push) Has been cancelled
CI / Test / ubuntu-latest (push) Has been cancelled
CI / Test / windows-latest (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Security Audit (push) Has been cancelled
CI / Secrets Scan (push) Has been cancelled
CI / Install Script Smoke Test (push) Has been cancelled
初始化提交
2026-03-01 16:24:24 +08:00

80 lines
2.5 KiB
JavaScript

// OpenFang Workflows Page — Workflow builder + run history
'use strict';
function workflowsPage() {
return {
// -- Workflows state --
workflows: [],
showCreateModal: false,
runModal: null,
runInput: '',
runResult: '',
running: false,
loading: true,
loadError: '',
newWf: { name: '', description: '', steps: [{ name: '', agent_name: '', mode: 'sequential', prompt: '{{input}}' }] },
// -- Workflows methods --
async loadWorkflows() {
this.loading = true;
this.loadError = '';
try {
this.workflows = await OpenFangAPI.get('/api/workflows');
} catch(e) {
this.workflows = [];
this.loadError = e.message || 'Could not load workflows.';
}
this.loading = false;
},
async loadData() { return this.loadWorkflows(); },
async createWorkflow() {
var steps = this.newWf.steps.map(function(s) {
return { name: s.name || 'step', agent_name: s.agent_name, mode: s.mode, prompt: s.prompt || '{{input}}' };
});
try {
var wfName = this.newWf.name;
await OpenFangAPI.post('/api/workflows', { name: wfName, description: this.newWf.description, steps: steps });
this.showCreateModal = false;
this.newWf = { name: '', description: '', steps: [{ name: '', agent_name: '', mode: 'sequential', prompt: '{{input}}' }] };
OpenFangToast.success('Workflow "' + wfName + '" created');
await this.loadWorkflows();
} catch(e) {
OpenFangToast.error('Failed to create workflow: ' + e.message);
}
},
showRunModal(wf) {
this.runModal = wf;
this.runInput = '';
this.runResult = '';
},
async executeWorkflow() {
if (!this.runModal) return;
this.running = true;
this.runResult = '';
try {
var res = await OpenFangAPI.post('/api/workflows/' + this.runModal.id + '/run', { input: this.runInput });
this.runResult = res.output || JSON.stringify(res, null, 2);
OpenFangToast.success('Workflow completed');
} catch(e) {
this.runResult = 'Error: ' + e.message;
OpenFangToast.error('Workflow failed: ' + e.message);
}
this.running = false;
},
async viewRuns(wf) {
try {
var runs = await OpenFangAPI.get('/api/workflows/' + wf.id + '/runs');
this.runResult = JSON.stringify(runs, null, 2);
this.runModal = wf;
} catch(e) {
OpenFangToast.error('Failed to load run history: ' + e.message);
}
}
};
}