初始化提交
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
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
This commit is contained in:
79
crates/openfang-api/static/js/pages/workflows.js
Normal file
79
crates/openfang-api/static/js/pages/workflows.js
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user