loopengine 0.3.83 → 0.3.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -164,7 +164,7 @@ export declare class WorkflowRunner {
|
|
|
164
164
|
task_name?: string;
|
|
165
165
|
message: string;
|
|
166
166
|
session_id: string;
|
|
167
|
-
}): Promise<RunOutcome>;
|
|
167
|
+
} & Pick<StartRunInput, 'callback_url' | 'decisions_to' | 'chat_notice' | 'warnings'>): Promise<RunOutcome>;
|
|
168
168
|
/** Waits for the runs this process has started (tests, shutdown). */
|
|
169
169
|
idle(): Promise<void>;
|
|
170
170
|
/** How many runs are executing right now (for idle-shutdown checks). */
|
|
@@ -163,6 +163,10 @@ export class WorkflowRunner {
|
|
|
163
163
|
source: 'schedule',
|
|
164
164
|
task_id: input.task_id,
|
|
165
165
|
...(input.task_name ? { task_name: input.task_name } : {}),
|
|
166
|
+
...(input.callback_url ? { callback_url: input.callback_url } : {}),
|
|
167
|
+
...(input.decisions_to ? { decisions_to: input.decisions_to } : {}),
|
|
168
|
+
...(input.chat_notice ? { chat_notice: input.chat_notice } : {}),
|
|
169
|
+
...(input.warnings?.length ? { warnings: input.warnings } : {}),
|
|
166
170
|
status: 'running',
|
|
167
171
|
started_at: new Date().toISOString(),
|
|
168
172
|
message: input.message,
|
|
@@ -170,8 +174,9 @@ export class WorkflowRunner {
|
|
|
170
174
|
};
|
|
171
175
|
await getRunStore().put(run);
|
|
172
176
|
await this.prune(input.agent);
|
|
177
|
+
this.changed(run);
|
|
173
178
|
try {
|
|
174
|
-
const outcome = await this.execute(run.agent, run.message, run.session_id, { workflowId: run.workflow_id });
|
|
179
|
+
const outcome = await this.execute(run.agent, run.message, run.session_id, { workflowId: run.workflow_id, ...(run.decisions_to ? { decisionsTo: run.decisions_to } : {}) });
|
|
175
180
|
if (outcome.kind === 'pending')
|
|
176
181
|
this.changed(await getRunStore().update(run.run_id, (r) => r && { ...r, status: 'awaiting_approval', pending_ids: outcome.pendingIds }));
|
|
177
182
|
else
|
package/dist/core/workflows.d.ts
CHANGED
|
@@ -31,6 +31,19 @@ export interface Workflow {
|
|
|
31
31
|
model?: WorkflowModel;
|
|
32
32
|
/** What its result must look like. */
|
|
33
33
|
output?: string;
|
|
34
|
+
/** Where every run's updates, decisions and start notice go, however
|
|
35
|
+
* it starts. A webhook or API call with its own callback_url overrides
|
|
36
|
+
* the address and decisions for its run. */
|
|
37
|
+
delivery?: WorkflowDelivery;
|
|
38
|
+
}
|
|
39
|
+
export interface WorkflowDelivery {
|
|
40
|
+
/** Gets each run's updates (core/run-callbacks.ts). */
|
|
41
|
+
callback_url?: string;
|
|
42
|
+
/** "callback": approvals and questions go only to callback_url. */
|
|
43
|
+
decisions_to?: 'callback';
|
|
44
|
+
/** Posted to the messaging app when a run starts; {{name}} is filled
|
|
45
|
+
* from the run's inputs. */
|
|
46
|
+
chat_notice?: string;
|
|
34
47
|
}
|
|
35
48
|
/** The front matter that makes a skill a workflow: `instructions` (the
|
|
36
49
|
* new way) replaces the body and drops any start message and label;
|
|
@@ -48,6 +61,7 @@ export interface WorkflowFields {
|
|
|
48
61
|
/** null (or empty) clears it; left out keeps what's saved. */
|
|
49
62
|
model?: WorkflowModel | null;
|
|
50
63
|
output?: string | null;
|
|
64
|
+
delivery?: WorkflowDelivery | null;
|
|
51
65
|
}
|
|
52
66
|
export declare class WorkflowParamsError extends Error {
|
|
53
67
|
}
|
package/dist/core/workflows.js
CHANGED
|
@@ -27,8 +27,16 @@
|
|
|
27
27
|
// workflow's schedules and webhook triggers themselves.
|
|
28
28
|
//
|
|
29
29
|
// A workflow's contract can also set, in its front matter: `model` (its
|
|
30
|
-
// own provider and model, instead of the agent's)
|
|
31
|
-
// result must look like, said to the agent last)
|
|
30
|
+
// own provider and model, instead of the agent's), `output` (what its
|
|
31
|
+
// result must look like, said to the agent last) and `delivery` (an app
|
|
32
|
+
// that gets every run's updates, and maybe its approvals and questions
|
|
33
|
+
// instead of the messaging app, and a message posted to the messaging app
|
|
34
|
+
// when a run starts):
|
|
35
|
+
//
|
|
36
|
+
// delivery:
|
|
37
|
+
// callback_url: https://ops.example.com/loopengine
|
|
38
|
+
// decisions: callback
|
|
39
|
+
// chat_notice: New dispute {{dispute_id}} The workspace's shared
|
|
32
40
|
// policies (policies.md in the project) go into every run, after the
|
|
33
41
|
// instructions.
|
|
34
42
|
//
|
|
@@ -48,13 +56,26 @@ const PARAMETER_NAME = /^[a-z_][a-z0-9_]*$/;
|
|
|
48
56
|
const WORKFLOW_KEYS = ['workflow', 'title', 'start_message', 'trigger', 'parameters', 'original_request'];
|
|
49
57
|
/** The contract's keys: kept when a save doesn't give them. `gather`
|
|
50
58
|
* (lookups done before the agent, since removed) is dropped. */
|
|
51
|
-
const CONTRACT_KEYS = ['model', 'output', 'gather'];
|
|
59
|
+
const CONTRACT_KEYS = ['model', 'output', 'delivery', 'gather'];
|
|
52
60
|
function modelFrom(value) {
|
|
53
61
|
if (!value || typeof value !== 'object')
|
|
54
62
|
return undefined;
|
|
55
63
|
const m = value;
|
|
56
64
|
return typeof m.provider === 'string' && m.provider.trim() && typeof m.model === 'string' && m.model.trim() ? { provider: m.provider.trim(), model: m.model.trim() } : undefined;
|
|
57
65
|
}
|
|
66
|
+
function deliveryFrom(value) {
|
|
67
|
+
if (!value || typeof value !== 'object')
|
|
68
|
+
return undefined;
|
|
69
|
+
const d = value;
|
|
70
|
+
const callbackUrl = typeof d.callback_url === 'string' && d.callback_url.trim() ? d.callback_url.trim() : undefined;
|
|
71
|
+
const notice = typeof d.chat_notice === 'string' && d.chat_notice.trim() ? d.chat_notice.trim() : undefined;
|
|
72
|
+
const delivery = {
|
|
73
|
+
...(callbackUrl ? { callback_url: callbackUrl } : {}),
|
|
74
|
+
...(callbackUrl && d.decisions === 'callback' ? { decisions_to: 'callback' } : {}),
|
|
75
|
+
...(notice ? { chat_notice: notice } : {}),
|
|
76
|
+
};
|
|
77
|
+
return Object.keys(delivery).length ? delivery : undefined;
|
|
78
|
+
}
|
|
58
79
|
function skillsDir(agentDir) {
|
|
59
80
|
return join(agentDir, 'skills');
|
|
60
81
|
}
|
|
@@ -123,6 +144,7 @@ function workflowFrom(id, frontmatter, body) {
|
|
|
123
144
|
instructions: combineInstructions(startMessage, body),
|
|
124
145
|
...(modelFrom(frontmatter.model) ? { model: modelFrom(frontmatter.model) } : {}),
|
|
125
146
|
...(typeof frontmatter.output === 'string' && frontmatter.output.trim() ? { output: frontmatter.output.trim() } : {}),
|
|
147
|
+
...(deliveryFrom(frontmatter.delivery) ? { delivery: deliveryFrom(frontmatter.delivery) } : {}),
|
|
126
148
|
};
|
|
127
149
|
}
|
|
128
150
|
/** The agent's workflows: its skills that have a start message. */
|
|
@@ -174,6 +196,13 @@ export function setWorkflowFields(agentDir, id, fields) {
|
|
|
174
196
|
else
|
|
175
197
|
delete frontmatter.output;
|
|
176
198
|
}
|
|
199
|
+
if (fields.delivery !== undefined) {
|
|
200
|
+
const delivery = fields.delivery ? deliveryFrom({ ...fields.delivery, decisions: fields.delivery.decisions_to }) : undefined;
|
|
201
|
+
if (delivery)
|
|
202
|
+
frontmatter.delivery = { ...(delivery.callback_url ? { callback_url: delivery.callback_url } : {}), ...(delivery.decisions_to ? { decisions: delivery.decisions_to } : {}), ...(delivery.chat_notice ? { chat_notice: delivery.chat_notice } : {}) };
|
|
203
|
+
else
|
|
204
|
+
delete frontmatter.delivery;
|
|
205
|
+
}
|
|
177
206
|
// Lookups done before the agent (removed): a save drops the old key.
|
|
178
207
|
delete frontmatter.gather;
|
|
179
208
|
if (fields.description)
|
|
@@ -1123,6 +1123,13 @@ ${consoleShellScript}
|
|
|
1123
1123
|
function contractLinesHtml(lines) {
|
|
1124
1124
|
return lines.map(function (l) { return '<div class="wf-cb-line">' + l + '</div>'; }).join('');
|
|
1125
1125
|
}
|
|
1126
|
+
// Where a workflow's approvals and questions go, as a phrase: its app
|
|
1127
|
+
// (the contract's address), or the agent's messaging app.
|
|
1128
|
+
function workflowDecisionsTo(w) {
|
|
1129
|
+
if (w.delivery && w.delivery.decisions_to === 'callback') return 'your app (' + escapeHtml(w.delivery.callback_url) + ')';
|
|
1130
|
+
return 'the agent' + String.fromCharCode(8217) + 's messaging app';
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1126
1133
|
// Its Triggers tab: the four ways a run starts, each in its own box
|
|
1127
1134
|
// with what it is: Run now, a schedule, a webhook, the API.
|
|
1128
1135
|
function workflowTriggersHtml(w, name, params) {
|
|
@@ -1133,7 +1140,7 @@ ${consoleShellScript}
|
|
|
1133
1140
|
};
|
|
1134
1141
|
return '<div class="wf-ways">' +
|
|
1135
1142
|
way('run', 'Run now', 'Starts a run right away, from here. It shows under Evidence as it goes.', workflowRunBarHtml(w, params)) +
|
|
1136
|
-
way('schedule', 'Schedule', 'Runs it on a timer, like every day at 9:00. Approvals and questions go to
|
|
1143
|
+
way('schedule', 'Schedule', 'Runs it on a timer, like every day at 9:00. Approvals and questions go to ' + workflowDecisionsTo(w) + '.',
|
|
1137
1144
|
(schedules || '<p class="hint" style="margin:0">None yet.</p>') +
|
|
1138
1145
|
'<div><button type="button" class="workflow-add-schedule">+ Schedule</button></div>') +
|
|
1139
1146
|
way('webhook', 'Webhook', 'Another app (Stripe, GitHub, Shopify or your own) calls a private address when something happens, and each call starts a run.',
|
|
@@ -1177,11 +1184,16 @@ ${consoleShellScript}
|
|
|
1177
1184
|
var notified = (w.schedules || []).some(function (x) { return x.notify && x.status !== 'cancelled'; }) || (w.triggers || []).some(function (t) { return t.result_to_chat; });
|
|
1178
1185
|
if (notified) result.push(escapeHtml(workflowsMeta.messaging ? (APP_NAMES[workflowsMeta.messaging] || workflowsMeta.messaging) : 'messaging app') + ' report <span class="hint">(for the schedules and webhooks set to send it)</span>');
|
|
1179
1186
|
if ((w.triggers || []).some(function (t) { return t.callback; })) result.push('posted to the webhook' + RSQ + 's update address');
|
|
1180
|
-
if (
|
|
1187
|
+
if (w.delivery && w.delivery.callback_url) result.push('run updates posted to ' + escapeHtml(w.delivery.callback_url) + ' <span class="hint">(every run, however it starts)</span>');
|
|
1188
|
+
var decisions = [w.delivery && w.delivery.decisions_to === 'callback'
|
|
1189
|
+
? 'your app at ' + escapeHtml(w.delivery.callback_url) + ' <span class="hint">(not the messaging app; every run, however it starts)</span>'
|
|
1190
|
+
: escapeHtml(workflowsMeta.messaging ? (APP_NAMES[workflowsMeta.messaging] || workflowsMeta.messaging) : 'the agent' + RSQ + 's messaging app')];
|
|
1191
|
+
if ((w.triggers || []).some(function (t) { return t.decisions_to === 'callback'; })) decisions.push('runs from a webhook set to send them to its own update address go there instead');
|
|
1192
|
+
if (w.delivery && w.delivery.chat_notice) decisions.push('a message in the messaging app when each run starts: ' + escapeHtml(w.delivery.chat_notice));
|
|
1181
1193
|
var model = w.model ? escapeHtml(w.model.provider + ' ' + w.model.model) : escapeHtml(workflowsMeta.agentModel || 'the agent' + RSQ + 's') + ' <span class="hint">(the agent' + RSQ + 's model)</span>';
|
|
1182
1194
|
var row = function (k, lines) { return '<div class="wf-cb-k">' + k + '</div><div class="wf-cb-v">' + contractLinesHtml(lines) + '</div>'; };
|
|
1183
|
-
return '<div class="wf-cb">' + row('trigger', trigger) + row('inputs', inputs) + row('tools', tools) + row('result', result) + row('model', [model]) + '</div>' +
|
|
1184
|
-
'<p class="hint" style="margin:0">Change the inputs, result and model with Edit, and what tools may do in Permissions.</p>';
|
|
1195
|
+
return '<div class="wf-cb">' + row('trigger', trigger) + row('inputs', inputs) + row('tools', tools) + row('result', result) + row('approvals', decisions) + row('model', [model]) + '</div>' +
|
|
1196
|
+
'<p class="hint" style="margin:0">Change the inputs, result, where approvals go and the model with Edit, and what tools may do in Permissions.</p>';
|
|
1185
1197
|
}
|
|
1186
1198
|
|
|
1187
1199
|
function workflowBriefHtml(w) {
|
|
@@ -1456,6 +1468,11 @@ ${consoleShellScript}
|
|
|
1456
1468
|
'<div class="wp-model-row"><select name="modelProvider" aria-label="Provider"><option value="">The agent' + String.fromCharCode(8217) + 's model</option>' +
|
|
1457
1469
|
['openai', 'anthropic', 'gemini', 'deepseek', 'kimi', 'glm', 'xai', 'meta'].map(function (p) { return '<option value="' + p + '"' + (w.model && w.model.provider === p ? ' selected' : '') + '>' + p + '</option>'; }).join('') +
|
|
1458
1470
|
'</select><input name="modelName" aria-label="Model name" placeholder="e.g. gpt-6.1-sol" value="' + escapeHtml((w.model && w.model.model) || '') + '"></div></div>' +
|
|
1471
|
+
'<div class="body-field">Your app <span class="hint">(optional: an https address in your own app, told when each run stops for a decision, finishes or fails, whether it' + String.fromCharCode(8217) + 's started by Run now, a schedule, a webhook or the API)</span>' +
|
|
1472
|
+
'<input name="deliveryUrl" inputmode="url" placeholder="https://example.com/hooks/loopengine" value="' + escapeHtml((w.delivery && w.delivery.callback_url) || '') + '">' +
|
|
1473
|
+
'<label class="http-tool-inline-label"><input type="checkbox" name="deliveryDecisions"' + (w.delivery && w.delivery.decisions_to === 'callback' ? ' checked' : '') + (w.delivery && w.delivery.callback_url ? '' : ' disabled') + '> Send approvals and questions there instead of the messaging app <span class="hint">(your app shows them and answers through the API)</span></label></div>' +
|
|
1474
|
+
'<label>Message the chat when a run starts <span class="hint">(optional: posted to the messaging app; {{name}} puts in an input' + String.fromCharCode(8217) + 's value)</span>' +
|
|
1475
|
+
'<input name="deliveryNotice" maxlength="1000" placeholder="New dispute {{dispute_id}}" value="' + escapeHtml((w.delivery && w.delivery.chat_notice) || '') + '"></label>' +
|
|
1459
1476
|
'<p class="hint workflow-editor-check" style="margin:0"></p>' +
|
|
1460
1477
|
'<div class="hint workflow-editor-result"></div>' +
|
|
1461
1478
|
'<div class="ed-actions"><button type="button" class="wp-cancel">Cancel</button><button type="submit" class="primary">Save</button></div></form>';
|
|
@@ -1480,6 +1497,18 @@ ${consoleShellScript}
|
|
|
1480
1497
|
form.querySelector('.workflow-editor-check').textContent = notes.join(' ');
|
|
1481
1498
|
}
|
|
1482
1499
|
|
|
1500
|
+
// The editor's Your app fields, as the save's delivery: null for none.
|
|
1501
|
+
function workflowDeliveryFromForm(form) {
|
|
1502
|
+
var url = form.deliveryUrl.value.trim();
|
|
1503
|
+
var notice = form.deliveryNotice.value.trim();
|
|
1504
|
+
if (!url && !notice) return null;
|
|
1505
|
+
var d = {};
|
|
1506
|
+
if (url) d.callback_url = url;
|
|
1507
|
+
if (url && form.deliveryDecisions.checked) d.decisions = 'callback';
|
|
1508
|
+
if (notice) d.chat_notice = notice;
|
|
1509
|
+
return d;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1483
1512
|
function openWorkflowEditor(name, card) {
|
|
1484
1513
|
var w = workflowsById[card.dataset.workflow];
|
|
1485
1514
|
if (!w) return;
|
|
@@ -1505,6 +1534,11 @@ ${consoleShellScript}
|
|
|
1505
1534
|
if (ev.target.classList.contains('wp-remove')) { ev.target.closest('.workflow-param-row').remove(); check(); }
|
|
1506
1535
|
});
|
|
1507
1536
|
form.addEventListener('input', check);
|
|
1537
|
+
// Decisions can only go to an address that's given.
|
|
1538
|
+
form.deliveryUrl.addEventListener('input', function () {
|
|
1539
|
+
form.deliveryDecisions.disabled = !form.deliveryUrl.value.trim();
|
|
1540
|
+
if (form.deliveryDecisions.disabled) form.deliveryDecisions.checked = false;
|
|
1541
|
+
});
|
|
1508
1542
|
form.querySelector('.wp-add').addEventListener('click', function () {
|
|
1509
1543
|
rows.insertAdjacentHTML('beforeend', workflowParamRowHtml('', null));
|
|
1510
1544
|
rows.lastElementChild.querySelector('.wp-name').focus();
|
|
@@ -1550,7 +1584,7 @@ ${consoleShellScript}
|
|
|
1550
1584
|
result.textContent = 'Saving' + String.fromCharCode(8230);
|
|
1551
1585
|
fetchJsonRetryOnce('/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(w.id), {
|
|
1552
1586
|
method: 'PUT', headers: { 'content-type': 'application/json' },
|
|
1553
|
-
body: JSON.stringify({ title: form.title.value, description: form.description.value, instructions: form.instructions.value, parameters: parameters, output: form.output.value, model: form.modelProvider.value && form.modelName.value.trim() ? { provider: form.modelProvider.value, model: form.modelName.value.trim() } : null }),
|
|
1587
|
+
body: JSON.stringify({ title: form.title.value, description: form.description.value, instructions: form.instructions.value, parameters: parameters, output: form.output.value, model: form.modelProvider.value && form.modelName.value.trim() ? { provider: form.modelProvider.value, model: form.modelName.value.trim() } : null, delivery: workflowDeliveryFromForm(form) }),
|
|
1554
1588
|
}).then(function (r) {
|
|
1555
1589
|
if (!r.ok) { result.textContent = r.body.error || 'Could not save'; return; }
|
|
1556
1590
|
close();
|
|
@@ -1990,7 +2024,9 @@ ${consoleShellScript}
|
|
|
1990
2024
|
btn.disabled = false;
|
|
1991
2025
|
notifyToggle.disabled = false;
|
|
1992
2026
|
if (!r.ok) { result.textContent = r.body.error || 'Could not start it.'; return; }
|
|
1993
|
-
|
|
2027
|
+
var started = workflowsById[id];
|
|
2028
|
+
result.innerHTML = 'Started. Questions and approvals go to ' + workflowDecisionsTo(started || {}) + '; the result shows under Evidence.' + (notifyResult ? ' The result will also be sent to the messaging app when it finishes.' : '') +
|
|
2029
|
+
(r.body.warnings ? ' ' + escapeHtml(r.body.warnings.join(' ')) : '');
|
|
1994
2030
|
setTimeout(function () { loadWorkflowsSection(name); }, 800);
|
|
1995
2031
|
});
|
|
1996
2032
|
});
|
|
@@ -13,7 +13,7 @@ import { setAgentEnvVar } from './env-admin.js';
|
|
|
13
13
|
import { installFailureReason, templateChecklist } from './templates-admin.js';
|
|
14
14
|
import { templateScheduleStart } from '../core/system-agents/templates.js';
|
|
15
15
|
import { planParameters, planWebhook, planWorkflowWithModel, workflowTemplate } from '../core/system-agents/workflow-planner.js';
|
|
16
|
-
import { createTrigger, getTriggerStore, listTriggers, publicTrigger } from '../core/workflow-triggers.js';
|
|
16
|
+
import { checkRunDelivery, createTrigger, getTriggerStore, listTriggers, publicTrigger } from '../core/workflow-triggers.js';
|
|
17
17
|
import { mcpAbilityNames } from '../core/mcp-ability-generator.js';
|
|
18
18
|
import { contextToolsFor } from '../core/mcp-apps.js';
|
|
19
19
|
import { clearWorkflowFields, migrateWorkflowsFile, readWorkflow, readWorkflows, setWorkflowFields, validateParams, workflowRunMessage } from '../core/workflows.js';
|
|
@@ -822,6 +822,19 @@ export function contractFields(input) {
|
|
|
822
822
|
throw new WorkflowError('The result format is too long: keep it under 2000 characters.');
|
|
823
823
|
fields.output = typeof input.output === 'string' ? input.output : null;
|
|
824
824
|
}
|
|
825
|
+
// Where every run's updates and decisions go: { callback_url, decisions,
|
|
826
|
+
// chat_notice }, or null for the messaging app only.
|
|
827
|
+
if (input.delivery !== undefined) {
|
|
828
|
+
if (input.delivery === null)
|
|
829
|
+
fields.delivery = null;
|
|
830
|
+
else if (typeof input.delivery !== 'object' || Array.isArray(input.delivery))
|
|
831
|
+
throw new WorkflowError('delivery must be { callback_url, decisions, chat_notice }, or null.');
|
|
832
|
+
else {
|
|
833
|
+
const d = checkRunDelivery(input.delivery, (m) => new WorkflowError(m));
|
|
834
|
+
const { result_to_chat: _r, ...kept } = d;
|
|
835
|
+
fields.delivery = Object.keys(kept).length ? kept : null;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
825
838
|
return fields;
|
|
826
839
|
}
|
|
827
840
|
export function updateWorkflow(agentDir, id, input) {
|