loopengine 0.3.82 → 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
@@ -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
  }
@@ -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) and `output` (what its
31
- // result must look like, said to the agent last). The workspace's shared
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 the agent' + RSQ + 's messaging app.',
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 ((w.triggers || []).some(function (t) { return t.decisions_to === 'callback'; })) result.push('approvals and questions go to the webhook' + RSQ + 's update address <span class="hint">(not the messaging app)</span>');
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();
@@ -1613,6 +1647,7 @@ ${consoleShellScript}
1613
1647
  '</ol>'
1614
1648
  : (shownUrl ? hookUrlHtml(shownUrl) : '')) +
1615
1649
  '<div style="display:flex;gap:6px;flex-wrap:wrap;margin-top:4px">' +
1650
+ '<button type="button" class="hook-edit">Edit</button>' +
1616
1651
  (needsSecret ? '' : '<button type="button" class="hook-toggle">' + (t.enabled ? 'Turn off' : 'Turn on') + '</button>') +
1617
1652
  '<button type="button" class="hook-rotate">New URL</button>' +
1618
1653
  '<button type="button" class="delete-btn hook-delete">Delete</button></div></div>';
@@ -1620,15 +1655,19 @@ ${consoleShellScript}
1620
1655
 
1621
1656
  // The add-webhook dialog's form: where the events come from, which ones,
1622
1657
  // what the workflow gets from each, and what happens after each run.
1623
- function hookFormHtml(w) {
1658
+ // With t, the same form changes that webhook (filled in by
1659
+ // fillHookForm); its URL stays the same.
1660
+ function hookFormHtml(w, t) {
1624
1661
  var params = Object.keys(w.parameters || {});
1625
1662
  var RSQ = String.fromCharCode(8217);
1626
1663
  var field = function (label, input, hint, attrs) {
1627
1664
  return '<div class="hd-field"' + (attrs || '') + '><label class="hd-label">' + label + input + '</label>' + (hint ? '<p class="hd-hint">' + hint + '</p>' : '') + '</div>';
1628
1665
  };
1629
1666
  return '<form class="hook-form hd">' +
1630
- '<header class="hd-head"><div><h3>Add a webhook</h3>' +
1631
- '<p>Another app calls a private URL when something happens, and each call starts a run of ' + String.fromCharCode(8220) + escapeHtml(w.title || w.id) + String.fromCharCode(8221) + '.</p></div>' +
1667
+ '<header class="hd-head"><div><h3>' + (t ? 'Edit webhook' : 'Add a webhook') + '</h3>' +
1668
+ (t
1669
+ ? '<p>Changes apply from the next call. Its URL stays the same, so nothing changes in the sending app.</p></div>'
1670
+ : '<p>Another app calls a private URL when something happens, and each call starts a run of ' + String.fromCharCode(8220) + escapeHtml(w.title || w.id) + String.fromCharCode(8221) + '.</p></div>') +
1632
1671
  '<button type="button" class="hd-close hook-dialog-close" aria-label="Close">&times;</button></header>' +
1633
1672
  '<div class="hd-body">' +
1634
1673
  '<section class="hd-section"><h4>Source</h4>' +
@@ -1670,14 +1709,41 @@ ${consoleShellScript}
1670
1709
  '</section>' +
1671
1710
  '</div>' +
1672
1711
  '<footer class="hd-foot"><span class="hook-form-result" role="status"></span>' +
1673
- '<div class="hd-actions"><button type="button" class="hook-dialog-cancel">Cancel</button><button type="submit" class="primary">Create webhook</button></div></footer>' +
1712
+ '<div class="hd-actions"><button type="button" class="hook-dialog-cancel">Cancel</button><button type="submit" class="primary">' + (t ? 'Save' : 'Create webhook') + '</button></div></footer>' +
1674
1713
  '</form>';
1675
1714
  }
1676
1715
 
1677
- function openHookFormDialog(w, base, onCreated) {
1716
+ // A webhook's saved settings, in the form. Its secret is never shown:
1717
+ // left empty, the saved one is kept.
1718
+ function fillHookForm(form, t) {
1719
+ form.sender.value = t.verify ? t.verify.sender : '';
1720
+ if (t.verify && t.verify.sender === 'custom') {
1721
+ form.sig_header.value = t.verify.header || '';
1722
+ form.sig_algorithm.value = t.verify.algorithm || 'sha256';
1723
+ form.sig_encoding.value = t.verify.encoding || 'hex';
1724
+ form.sig_prefix.value = t.verify.prefix || '';
1725
+ }
1726
+ if (t.verify && t.verify.secret_set) {
1727
+ form.secret.placeholder = 'Saved. Leave empty to keep it';
1728
+ var hint = form.querySelector('.hook-secret .hd-hint');
1729
+ if (hint) hint.textContent = 'Paste a new one only if the sender gave you a new secret.';
1730
+ }
1731
+ if (t.filter) { form.filter_path.value = t.filter.path; form.filter_values.value = t.filter.values.join(', '); }
1732
+ form.name.value = t.name || '';
1733
+ Object.keys(t.mapping || {}).forEach(function (p) { var input = form.querySelector('input[name="map:' + p + '"]'); if (input) input.value = t.mapping[p]; });
1734
+ if (form.payload_param && t.payload_param) form.payload_param.value = t.payload_param;
1735
+ form.chat_notice.value = t.chat_notice || '';
1736
+ form.result_to_chat.checked = Boolean(t.result_to_chat || t.notify);
1737
+ form.callback_url.value = t.callback_url || '';
1738
+ form.decisions_callback.checked = t.decisions_to === 'callback';
1739
+ }
1740
+
1741
+ // existing: a webhook to change instead of making one; onDone then gets
1742
+ // only its new settings.
1743
+ function openHookFormDialog(w, base, onCreated, existing) {
1678
1744
  var dialog = document.createElement('dialog');
1679
1745
  dialog.className = 'le-dialog hook-dialog';
1680
- dialog.innerHTML = hookFormHtml(w);
1746
+ dialog.innerHTML = hookFormHtml(w, existing);
1681
1747
  document.body.appendChild(dialog);
1682
1748
  dialog.addEventListener('close', function () { dialog.remove(); });
1683
1749
  dialog.addEventListener('click', function (ev) { if (ev.target === dialog) dialog.close(); });
@@ -1706,6 +1772,9 @@ ${consoleShellScript}
1706
1772
  if (form.decisions_callback.disabled) form.decisions_callback.checked = false;
1707
1773
  }
1708
1774
  form.callback_url.addEventListener('input', callbackChanged);
1775
+ if (existing) fillHookForm(form, existing);
1776
+ callbackChanged();
1777
+ if (existing) form.decisions_callback.checked = existing.decisions_to === 'callback' && !form.decisions_callback.disabled;
1709
1778
  senderChanged();
1710
1779
  form.addEventListener('submit', function (ev) {
1711
1780
  ev.preventDefault();
@@ -1713,8 +1782,10 @@ ${consoleShellScript}
1713
1782
  var body = { name: form.name.value.trim() || defaultName() };
1714
1783
  if (form.sender.value) body.verify = { sender: form.sender.value, secret: form.secret.value.trim() };
1715
1784
  // No secret yet (most senders only show it once they have the URL):
1716
- // made turned off, with steps to finish it.
1717
- if (form.sender.value && !form.secret.value.trim()) { delete body.verify.secret; body.enabled = false; }
1785
+ // made turned off, with steps to finish it. A change keeps the saved
1786
+ // secret, unless the sender changed and there is none for it.
1787
+ var keepsSecret = existing && existing.verify && existing.verify.secret_set && existing.verify.sender === form.sender.value;
1788
+ if (form.sender.value && !form.secret.value.trim()) { delete body.verify.secret; if (!keepsSecret) body.enabled = false; }
1718
1789
  if (form.sender.value === 'custom') {
1719
1790
  body.verify.header = form.sig_header.value.trim();
1720
1791
  body.verify.algorithm = form.sig_algorithm.value;
@@ -1732,15 +1803,25 @@ ${consoleShellScript}
1732
1803
  if (form.callback_url.value.trim()) body.callback_url = form.callback_url.value.trim();
1733
1804
  if (body.callback_url && form.decisions_callback.checked) body.decisions = 'callback';
1734
1805
  if (form.chat_notice.value.trim()) body.chat_notice = form.chat_notice.value.trim();
1735
- result.textContent = 'Making it' + String.fromCharCode(8230);
1806
+ // A change says what's cleared too; a setting left out is kept.
1807
+ if (existing) {
1808
+ ['verify', 'filter', 'mapping', 'callback_url', 'decisions', 'chat_notice'].forEach(function (k) { if (!(k in body)) body[k] = null; });
1809
+ if (!('payload_param' in body)) body.payload_param = '';
1810
+ if (!body.result_to_chat) body.result_to_chat = false;
1811
+ }
1812
+ var failed = existing ? 'Could not save it' : 'Could not make it';
1813
+ result.textContent = (existing ? 'Saving' : 'Making it') + String.fromCharCode(8230);
1736
1814
  var submit = form.querySelector('button[type="submit"]');
1737
1815
  submit.disabled = true;
1738
- fetchJsonRetryOnce(base, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }).then(function (r) {
1739
- if (!r.ok) { result.textContent = r.body.error || 'Could not make it'; submit.disabled = false; return; }
1816
+ var request = existing
1817
+ ? fetchJsonRetryOnce(base + '/' + encodeURIComponent(existing.trigger_id), { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
1818
+ : fetchJsonRetryOnce(base, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
1819
+ request.then(function (r) {
1820
+ if (!r.ok) { result.textContent = r.body.error || failed; submit.disabled = false; return; }
1740
1821
  dialog.close();
1741
1822
  onCreated(r.body.url, r.body.trigger && r.body.trigger.trigger_id, r.body.trigger);
1742
1823
  }).catch(function (err) {
1743
- result.textContent = err && err.message ? err.message : 'Could not make it';
1824
+ result.textContent = err && err.message ? err.message : failed;
1744
1825
  submit.disabled = false;
1745
1826
  });
1746
1827
  });
@@ -1803,6 +1884,9 @@ ${consoleShellScript}
1803
1884
  for (var i = 0; i < rows.length; i++) {
1804
1885
  (function (row) {
1805
1886
  var id = row.dataset.trigger;
1887
+ row.querySelector('.hook-edit').addEventListener('click', function () {
1888
+ if (hooksById[id]) openHookFormDialog(w, base, function () { render(null, null); }, hooksById[id]);
1889
+ });
1806
1890
  var toggle = row.querySelector('.hook-toggle');
1807
1891
  if (toggle) toggle.addEventListener('click', function (ev) {
1808
1892
  act(id, '', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ enabled: ev.currentTarget.textContent === 'Turn on' }) });
@@ -1940,7 +2024,9 @@ ${consoleShellScript}
1940
2024
  btn.disabled = false;
1941
2025
  notifyToggle.disabled = false;
1942
2026
  if (!r.ok) { result.textContent = r.body.error || 'Could not start it.'; return; }
1943
- result.textContent = 'Started. Questions and approvals go to this agent' + String.fromCharCode(8217) + 's messaging app; the result shows under History.' + (notifyResult ? ' The result will also be sent to the messaging app when it finishes.' : '');
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(' ')) : '');
1944
2030
  setTimeout(function () { loadWorkflowsSection(name); }, 800);
1945
2031
  });
1946
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopengine",
3
- "version": "0.3.82",
3
+ "version": "0.3.84",
4
4
  "type": "module",
5
5
  "description": "Runtime for tool-using AI agents with a transparent ReAct loop.",
6
6
  "license": "MIT",