loopengine 0.3.76 → 0.3.77

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.
@@ -96,7 +96,7 @@ export const agentsConfigPageHtml = `<!doctype html>
96
96
  .wf-list-box { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; }
97
97
  .wf-row + .wf-row { border-top: 1px solid var(--line); }
98
98
  .wf-row.workflow-focus { box-shadow: inset 3px 0 0 var(--accent); }
99
- .wf-row-head { display: grid; grid-template-columns: 14px minmax(0, 1fr) 160px 250px auto; align-items: center; gap: 14px; padding: 12px 16px; cursor: pointer; }
99
+ .wf-row-head { display: grid; grid-template-columns: 14px minmax(0, 1fr) 210px 200px auto; align-items: center; gap: 14px; padding: 12px 16px; cursor: pointer; }
100
100
  .wf-row-head:hover { background: var(--surface); }
101
101
  .wf-row-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
102
102
  .wf-row-caret { width: 7px; height: 7px; border-right: 2px solid var(--ink-muted); border-bottom: 2px solid var(--ink-muted); transform: rotate(-45deg); transition: transform .15s; }
@@ -104,7 +104,13 @@ export const agentsConfigPageHtml = `<!doctype html>
104
104
  .wf-row-main { min-width: 0; display: grid; gap: 2px; }
105
105
  .wf-row-main strong { font-size: 14px; font-weight: 650; color: var(--ink); }
106
106
  .wf-row-desc { font-size: 12.5px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
107
- .wf-row-starts { font-size: 12.5px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
107
+ .wf-row-starts { display: grid; gap: 2px; font-size: 12.5px; color: var(--ink-muted); min-width: 0; }
108
+ .wf-start-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
109
+ .wf-start-state { font-size: 11px; font-weight: 700; padding: 0 6px; margin-left: 2px; border-radius: 999px; }
110
+ .wf-start-state + .wf-start-state { margin-left: 4px; }
111
+ .wf-start-state.on { background: var(--good-soft); color: var(--good); }
112
+ .wf-start-state.off { background: var(--warn-soft); color: var(--warn); }
113
+ .wf-start-state.warn { background: var(--warn-soft); color: var(--warn); }
108
114
  .wf-row-last { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; white-space: nowrap; }
109
115
  .wf-row-last .hint { white-space: nowrap; }
110
116
  .wf-row-actions { display: flex; gap: 6px; }
@@ -121,7 +127,6 @@ export const agentsConfigPageHtml = `<!doctype html>
121
127
  .wf-row .workflow-steps-text { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--surface); font-size: 13px; line-height: 1.6; max-height: 420px; overflow: auto; white-space: pre-wrap; }
122
128
  .wf-original { margin-top: 10px; }
123
129
  .wf-original summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-muted); margin-bottom: 6px; }
124
- .wf-row .workflow-starts > .workflow-section-content { padding: 0; }
125
130
  .wf-row .workflow-result:empty { display: none; }
126
131
  .wf-cb { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; line-height: 1.5; }
127
132
  .wf-cb-k { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--accent-ink); padding-top: 1px; }
@@ -135,6 +140,19 @@ export const agentsConfigPageHtml = `<!doctype html>
135
140
  .wf-cb-decision.ask { background: var(--warn-soft); color: var(--warn); }
136
141
  .wf-cb-decision.deny { background: var(--bad-soft); color: var(--bad); }
137
142
  @media (max-width: 520px) { .wf-cb { grid-template-columns: minmax(0, 1fr); gap: 2px; } .wf-cb-v { margin-bottom: 8px; } }
143
+ .wf-trigger { gap: 6px; }
144
+ .wf-trigger-item { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
145
+ .wf-trigger-item button, .wf-trigger-add button, .wf-trigger .workflow-hook button { padding: 2px 10px; font-size: 12px; }
146
+ .wf-trigger .workflow-hooks:empty { display: none; }
147
+ .wf-trigger .workflow-hook { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
148
+ .wf-trigger-add { display: flex; gap: 6px; flex-wrap: wrap; }
149
+ .wf-trigger-add [hidden] { display: none; }
150
+ .wf-api summary { cursor: pointer; font-size: 12.5px; color: var(--accent-ink); }
151
+ .wf-api[open] { display: grid; gap: 6px; }
152
+ .wf-api pre { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
153
+ .wf-run-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
154
+ .wf-run-bar .workflow-params { margin: 0; flex: 1 1 320px; }
155
+ .wf-run-bar-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-left: auto; }
138
156
  .wf-sub { margin: 6px 0 0; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted); }
139
157
  .wf-scores { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
140
158
  .wf-score { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
@@ -179,13 +197,6 @@ export const agentsConfigPageHtml = `<!doctype html>
179
197
  .workflow-section-content { padding: 4px 20px 24px; }
180
198
  .workflow-section-meta { margin-left: auto; color: var(--ink-muted); font-size: 12px; font-weight: 500; }
181
199
  .wf-card .workflow-steps-text { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--surface); font-size: 13px; line-height: 1.6; max-height: 320px; overflow: auto; }
182
- .workflow-starts > .workflow-section-content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
183
- .workflow-starts.wf-starts-compact > .workflow-section-content { grid-template-columns: repeat(3, minmax(0, 1fr)); }
184
- .workflow-starts.wf-starts-compact .wf-start-api { grid-column: 1 / -1; }
185
- @media (max-width: 900px) { .workflow-starts.wf-starts-compact > .workflow-section-content { grid-template-columns: minmax(0, 1fr); } }
186
- .workflow-starts .wf-start { align-content: start; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
187
- .workflow-starts .wf-start:first-of-type { padding-top: 14px; border-top: 1px solid var(--line); }
188
- .workflow-starts .workflow-hooks:empty { display: none; }
189
200
  @media (max-width: 640px) {
190
201
  .wf-tab-head, .wf-card-head { flex-direction: column; }
191
202
  .wf-card-actions { max-width: none; justify-content: flex-start; }
@@ -206,19 +217,8 @@ export const agentsConfigPageHtml = `<!doctype html>
206
217
  form.add-source .schedule-when select, form.add-source .schedule-when input[type="datetime-local"] { width: auto; }
207
218
  .workflow-card.workflow-focus { box-shadow: 0 0 0 2px var(--le-accent, #0f766e); transition: box-shadow 0.3s; }
208
219
  tr.schedule-focus td { background: var(--le-accent-soft, #e6f4ef); transition: background 0.3s; }
209
- .workflow-run-controls { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
210
220
  .workflow-run-notify { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
211
221
  .workflow-run-notify input { width: auto; margin: 0; }
212
- .wf-start { padding: 10px 0; border-top: 1px solid var(--le-line, #e5e7eb); display: grid; gap: 6px; font-size: 13px; }
213
- .wf-start:first-of-type { border-top: 0; padding-top: 6px; }
214
- .wf-start-head { display: flex; align-items: center; gap: 6px; }
215
- .wf-start-head strong { font-size: 13px; }
216
- .help-q { width: 18px; height: 18px; padding: 0; border-radius: 50%; font-size: 11px; line-height: 16px; font-weight: 600; text-align: center; cursor: pointer; }
217
- .help-text { margin: 0; }
218
- .help-text[hidden] { display: none; }
219
- .wf-start .schedule-history { margin: 0; gap: 6px; }
220
- .wf-start .workflow-params { margin: 0; }
221
- .wf-start pre { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--le-bg, #fff); border: 1px solid var(--le-line, #e5e7eb); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
222
222
  .workflow-steps-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: var(--le-surface, #f6f7f9); }
223
223
  .workflow-params { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
224
224
  .workflow-params[hidden] { display: none; }
@@ -968,40 +968,16 @@ ${consoleShellScript}
968
968
  // from "Describe a workflow": each with its instructions, what starts it
969
969
  // (its real schedules and webhooks), its recent runs and Run now. ----
970
970
 
971
- // What starts a workflow, in a few words, from its schedules and
972
- // webhooks: never a label that could say something else.
973
- function workflowStartsSummary(w) {
974
- var parts = (w.schedules || []).filter(function (x) { return x.repeating && x.status !== 'paused'; }).map(function (x) { return x.describe; });
975
- if (w.webhooks) parts.push(w.webhooks === 1 ? 'when its webhook is called' : 'when one of its ' + w.webhooks + ' webhooks is called');
976
- if (!parts.length) return 'No schedule or webhook yet';
977
- var text = parts.join(', and ');
978
- return text.charAt(0).toUpperCase() + text.slice(1);
979
- }
980
-
981
- // With no schedule and no webhook, Run now, Schedule and Webhook are
982
- // small: one row; once either has something to list, one per row.
983
- function startsCompact(w) {
984
- return !(w.schedules || []).length && !(w.webhooks || w.webhooksWaiting || w.webhooksOff);
985
- }
986
-
987
- // Ways to run it: four, each with a ? that says what it is. Run now
988
- // with the values a run is given, a schedule (pause, resume, remove,
989
- // add), a webhook, and the API call an app makes.
990
- function wfStartSection(key, title, help, body) {
991
- return '<div class="wf-start wf-start-' + key.split('-')[0] + '">' +
992
- '<div class="wf-start-head"><strong>' + title + '</strong>' +
993
- '<button type="button" class="help-q" aria-expanded="false" aria-controls="help-' + key + '" aria-label="What is ' + title.toLowerCase() + '?">?</button></div>' +
994
- '<p class="hint help-text" hidden>' + help + '</p>' + body + '</div>';
995
- }
996
-
997
- function workflowStartsHtml(w, agentName, paramsHtml) {
998
- var schedules = (w.schedules || []).map(function (x) {
971
+ // A workflow's schedules, each with its state and Pause/Resume and
972
+ // Remove, as lines of its contract's trigger row.
973
+ function workflowScheduleItemsHtml(w, agentName) {
974
+ return (w.schedules || []).map(function (x) {
999
975
  var state = x.waiting ? '<span class="le-pill ask">Waiting for a decision</span>'
1000
976
  : x.status === 'paused' ? '<span class="le-pill warn">Paused</span>'
1001
977
  : x.status === 'running' ? '<span class="le-pill accent">Running</span>'
1002
978
  : (x.nextRunAt ? '<span class="hint">next ' + escapeHtml(new Date(x.nextRunAt).toLocaleString()) + '</span>' : '');
1003
979
  var values = x.params ? Object.keys(x.params).map(function (k) { return escapeHtml(k) + ': ' + escapeHtml(x.params[k]); }).join(' ' + String.fromCharCode(183) + ' ') : '';
1004
- return '<li style="display:flex;gap:8px;flex-wrap:wrap;align-items:center">' +
980
+ return '<div class="wf-trigger-item">' +
1005
981
  '<span><a href="?agent=' + encodeURIComponent(agentName) + '&amp;tab=schedules#schedule-' + escapeHtml(x.taskId) + '" class="workflow-schedule-link" data-task="' + escapeHtml(x.taskId) + '" title="See it in the Schedules tab">' +
1006
982
  escapeHtml(x.describe.charAt(0).toUpperCase() + x.describe.slice(1)) + '</a></span>' + state +
1007
983
  (values ? '<span class="hint">' + values + '</span>' : '') +
@@ -1010,34 +986,34 @@ ${consoleShellScript}
1010
986
  (x.status === 'paused' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="resume">Resume</button>'
1011
987
  : x.status === 'scheduled' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="pause">Pause</button>' : '') +
1012
988
  '<button type="button" class="delete-btn workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="cancel">Remove</button>' +
1013
- '</span></li>';
989
+ '</span></div>';
1014
990
  }).join('');
991
+ }
992
+
993
+ // Run now, above the tabs: the values a run is given, and whether its
994
+ // result also goes to the messaging app.
995
+ function workflowRunBarHtml(w, paramsHtml) {
996
+ return '<div class="wf-run-bar">' +
997
+ (paramsHtml ? '<div class="workflow-params">' + paramsHtml + '</div>' : '') +
998
+ '<div class="wf-run-bar-controls">' +
999
+ '<label class="workflow-run-notify" title="Sends the completed result through this agent' + String.fromCharCode(8217) + 's configured notifier"><input type="checkbox" class="workflow-run-notify-toggle"> Send result to messaging app</label>' +
1000
+ '<button type="button" class="workflow-run primary">Run now</button></div>' +
1001
+ '</div>';
1002
+ }
1003
+
1004
+ // The call an app makes to start a run, folded under the trigger row.
1005
+ function workflowApiHtml(w, agentName) {
1015
1006
  var paramNames = Object.keys(w.parameters || {});
1016
1007
  // A body that shows what a call can carry: its values, and waiting
1017
1008
  // for the result.
1018
1009
  var example = '{ ' + (paramNames.length ? '"params": { ' + paramNames.map(function (p) { return '"' + p + '": "' + String.fromCharCode(8230) + '"'; }).join(', ') + ' }, ' : '') + '"wait": true }';
1019
1010
  var apiUrl = location.origin + '/agents/' + encodeURIComponent(agentName) + '/workflows/' + encodeURIComponent(w.id) + '/run';
1020
- return '<div class="workflow-starts' + (startsCompact(w) ? ' wf-starts-compact' : '') + '"><div class="workflow-section-content">' +
1021
- wfStartSection('run-' + w.id, 'Run now',
1022
- 'Starts a run right away, from here' + (paramNames.length ? ', with the values you fill in' : '') + '. It shows under History as it goes.',
1023
- (paramsHtml ? '<div class="workflow-params">' + paramsHtml + '</div>' : '') +
1024
- '<div class="workflow-run-controls">' +
1025
- '<label class="workflow-run-notify" title="Sends the completed result through this agent' + String.fromCharCode(8217) + 's configured notifier"><input type="checkbox" class="workflow-run-notify-toggle"> Send result to messaging app</label>' +
1026
- '<button type="button" class="workflow-run primary">Run now</button></div>') +
1027
- wfStartSection('schedule-' + w.id, 'Schedule',
1028
- 'Runs it on a timer, like every day at 9:00, with the values you give the schedule. Nobody needs to be there: approvals and questions go to the agent' + String.fromCharCode(8217) + 's messaging app.',
1029
- (schedules ? '<ul class="schedule-history">' + schedules + '</ul>' : '<span class="hint">None yet.</span>') +
1030
- '<div><button type="button" class="workflow-add-schedule">Add a schedule</button></div>') +
1031
- wfStartSection('webhook-' + w.id, 'Webhook',
1032
- 'A private web address another app (Stripe, GitHub, Shopify or your own) calls when something happens. Each call starts a run, with values taken from what the app sends.',
1033
- '<div class="workflow-hooks"></div>' +
1034
- '<div class="workflow-hooks-add"' + (w.webhooks || w.webhooksWaiting || w.webhooksOff ? ' hidden' : '') + '><button type="button" class="workflow-hooks-btn">Add a webhook</button></div>') +
1035
- wfStartSection('api-' + w.id, 'API',
1036
- 'Your own app starts a run by calling this address with an API key. Add "wait": true to get the result in the answer, or "callback_url" to have it posted to you when the run ends.',
1037
- '<pre>POST ' + escapeHtml(apiUrl) + String.fromCharCode(10) + escapeHtml(example) + '</pre>' +
1038
- '<p class="hint" style="margin:0">' + (paramNames.length ? '<code>params</code>: ' + paramNames.map(function (p) { return '<code>' + escapeHtml(p) + '</code>' + (w.parameters[p].required ? ' (required)' : '') + (w.parameters[p].description ? ', ' + escapeHtml(w.parameters[p].description) : ''); }).join('; ') + '. ' : 'It takes no params. ') +
1039
- 'Optional: <code>"wait": true</code> answers with the result; <code>"notify": true</code> sends the result to the messaging app; <code>"callback_url"</code> posts it to your app when the run ends. Leave them out to get the run' + String.fromCharCode(8217) + 's id back at once.</p>') +
1040
- '</div></div>';
1011
+ return '<details class="wf-api"><summary>Show the API call</summary>' +
1012
+ '<p class="hint" style="margin:0">Your own app starts a run by calling this address with an API key.</p>' +
1013
+ '<pre>POST ' + escapeHtml(apiUrl) + String.fromCharCode(10) + escapeHtml(example) + '</pre>' +
1014
+ '<p class="hint" style="margin:0">' + (paramNames.length ? '<code>params</code>: ' + paramNames.map(function (p) { return '<code>' + escapeHtml(p) + '</code>' + (w.parameters[p].required ? ' (required)' : '') + (w.parameters[p].description ? ', ' + escapeHtml(w.parameters[p].description) : ''); }).join('; ') + '. ' : 'It takes no params. ') +
1015
+ 'Optional: <code>"wait": true</code> answers with the result; <code>"notify": true</code> sends the result to the messaging app; <code>"callback_url"</code> posts it to your app when the run ends. Leave them out to get the run' + String.fromCharCode(8217) + 's id back at once.</p>' +
1016
+ '</details>';
1041
1017
  }
1042
1018
 
1043
1019
  // What starts a workflow and what it's doing, as chips under its title:
@@ -1075,22 +1051,42 @@ ${consoleShellScript}
1075
1051
  return (w.recentRuns || []).some(function (r) { return r.status === 'awaiting_approval'; }) || (w.schedules || []).some(function (x) { return x.waiting; });
1076
1052
  }
1077
1053
 
1078
- // How it starts, in a few words for its row.
1054
+ // How it starts, for its row: each schedule (saying when it's paused)
1055
+ // and its webhooks on or off, so its state shows without opening it.
1079
1056
  function workflowStartsSummary(w) {
1080
- var parts = [];
1057
+ var lines = [];
1058
+ var state = function (text, kind) { return ' <span class="wf-start-state ' + kind + '">' + text + '</span>'; };
1081
1059
  var schedules = (w.schedules || []).filter(function (x) { return x.status !== 'cancelled'; });
1082
- if (schedules.length) parts.push(schedules[0].describe.charAt(0).toUpperCase() + schedules[0].describe.slice(1) + (schedules.length > 1 ? ' +' + (schedules.length - 1) : ''));
1083
- if (w.webhooks || w.webhooksWaiting || w.webhooksOff) parts.push('Webhook');
1084
- return parts.length ? parts.join(' ' + String.fromCharCode(183) + ' ') : 'When started';
1060
+ schedules.slice(0, 2).forEach(function (x) {
1061
+ lines.push(escapeHtml(x.describe.charAt(0).toUpperCase() + x.describe.slice(1)) + (x.status === 'paused' ? state('paused', 'off') : ''));
1062
+ });
1063
+ if (schedules.length > 2) {
1064
+ var more = schedules.slice(2);
1065
+ var pausedMore = more.filter(function (x) { return x.status === 'paused'; }).length;
1066
+ lines.push('<span class="hint">+' + more.length + ' more ' + (more.length === 1 ? 'schedule' : 'schedules') + '</span>' + (pausedMore ? state(pausedMore + ' paused', 'off') : ''));
1067
+ }
1068
+ var on = w.webhooks || 0, waiting = w.webhooksWaiting || 0, off = w.webhooksOff || 0;
1069
+ if (on + waiting + off) {
1070
+ var name = on + waiting + off === 1 ? 'Webhook' : 'Webhooks';
1071
+ var states = [];
1072
+ if (on) states.push(state((on + waiting + off > 1 ? on + ' ' : '') + 'on', 'on'));
1073
+ if (off) states.push(state((on + waiting + off > 1 ? off + ' ' : '') + 'off', 'off'));
1074
+ if (waiting) states.push(state('needs its signing secret', 'warn'));
1075
+ lines.push(name + states.join(''));
1076
+ }
1077
+ // Nothing starts it on its own: the ways it does start.
1078
+ if (!lines.length) return '<span class="hint">Run now or API</span>';
1079
+ return lines.map(function (l) { return '<span class="wf-start-line">' + l + '</span>'; }).join('');
1085
1080
  }
1086
1081
 
1087
1082
  function workflowLastRunHtml(r) {
1088
1083
  if (!r) return '<span class="hint">No runs yet</span>';
1089
- var pill = r.status === 'done' ? '<span class="le-pill good">Done</span>'
1090
- : r.status === 'error' ? '<span class="le-pill bad">Failed</span>'
1084
+ var when = new Date(r.started_at).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
1085
+ // A run that finished is just when it ran; the others say their state.
1086
+ if (r.status === 'done') return '<span class="hint">Last run ' + escapeHtml(when) + '</span>';
1087
+ var pill = r.status === 'error' ? '<span class="le-pill bad">Failed</span>'
1091
1088
  : r.status === 'awaiting_approval' ? '<span class="le-pill ask">Waiting for a decision</span>'
1092
1089
  : '<span class="le-pill accent">Running</span>';
1093
- var when = new Date(r.started_at).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
1094
1090
  return pill + '<span class="hint">' + escapeHtml(when) + '</span>';
1095
1091
  }
1096
1092
 
@@ -1147,17 +1143,28 @@ ${consoleShellScript}
1147
1143
  return lines.map(function (l) { return '<div class="wf-cb-line">' + l + '</div>'; }).join('');
1148
1144
  }
1149
1145
  function workflowContractHtml(w, name, params) {
1150
- var trigger = [];
1151
- (w.schedules || []).filter(function (x) { return x.status !== 'cancelled'; }).forEach(function (x) {
1152
- var values = x.params ? Object.keys(x.params).map(function (k) { return escapeHtml(k) + ' = ' + escapeHtml(x.params[k]); }).join(', ') : '';
1153
- trigger.push('schedule, ' + escapeHtml(x.describe) + (values ? ' <span class="hint">(' + values + ')</span>' : '') + (x.status === 'paused' ? ' <span class="le-pill warn">Paused</span>' : ''));
1154
- });
1146
+ // The trigger row is where its triggers are managed: each schedule
1147
+ // and webhook with its controls, a way to add either, and the other
1148
+ // ways any workflow starts (Run now above the tabs, the API call).
1149
+ var schedules = workflowScheduleItemsHtml(w, name);
1150
+ // Its webhooks as the contract says them, until the full rows (with
1151
+ // deliveries and setup steps) load into the same box.
1152
+ var hookLines = [];
1155
1153
  (w.triggers || []).forEach(function (t) {
1156
- trigger.push(escapeHtml(SENDER_LABELS[t.sender] || t.sender) + ' webhook' + (t.filter ? ', <code>' + escapeHtml(t.filter.values.join(' | ')) + '</code>' : '') +
1154
+ hookLines.push(escapeHtml(SENDER_LABELS[t.sender] || t.sender) + ' webhook' + (t.filter ? ', <code>' + escapeHtml(t.filter.values.join(' | ')) + '</code>' : '') +
1157
1155
  (t.waiting ? ' <span class="le-pill ask">Needs its signing secret</span>' : !t.enabled ? ' <span class="le-pill warn">Off</span>' : ''));
1158
- Object.keys(t.mapping || {}).forEach(function (param) { trigger.push('<span class="wf-cb-indent"><code>' + escapeHtml(param) + '</code> ' + ARROW_L + ' <code>' + escapeHtml(t.mapping[param]) + '</code></span>'); });
1156
+ Object.keys(t.mapping || {}).forEach(function (param) { hookLines.push('<span class="wf-cb-indent"><code>' + escapeHtml(param) + '</code> ' + ARROW_L + ' <code>' + escapeHtml(t.mapping[param]) + '</code></span>'); });
1159
1157
  });
1160
- trigger.push('<span class="hint">by hand (Run now) or from an app (API)</span>');
1158
+ var hasHooks = Boolean(w.webhooks || w.webhooksWaiting || w.webhooksOff || (w.triggers || []).length);
1159
+ var hasTrigger = Boolean(schedules) || hasHooks;
1160
+ var triggerHtml = schedules +
1161
+ '<div class="workflow-hooks">' + contractLinesHtml(hookLines) + '</div>' +
1162
+ '<div class="wf-cb-line"><span class="hint">' + (hasTrigger
1163
+ ? 'also by hand (Run now) or from an app (API)'
1164
+ : 'it runs when started by hand (Run now) or from an app (API), or set up a schedule or webhook') + '</span></div>' +
1165
+ '<div class="wf-trigger-add"><button type="button" class="workflow-add-schedule">+ Schedule</button>' +
1166
+ '<span class="workflow-hooks-add"' + (w.webhooksWaiting ? ' hidden' : '') + '><button type="button" class="workflow-hooks-btn">+ Webhook</button></span></div>' +
1167
+ workflowApiHtml(w, name);
1161
1168
  var names = Object.keys(w.parameters || {});
1162
1169
  var inputs = names.length ? names.map(function (n) {
1163
1170
  var spec = w.parameters[n];
@@ -1179,9 +1186,8 @@ ${consoleShellScript}
1179
1186
  if ((w.triggers || []).some(function (t) { return t.callback; })) result.push('posted to the webhook' + RSQ + 's callback address');
1180
1187
  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>';
1181
1188
  var row = function (k, lines) { return '<div class="wf-cb-k">' + k + '</div><div class="wf-cb-v">' + contractLinesHtml(lines) + '</div>'; };
1182
- return '<div class="wf-cb">' + row('trigger', trigger) + row('inputs', inputs) + row('tools', tools) + row('result', result) + row('model', [model]) + '</div>' +
1183
- '<p class="hint" style="margin:0">Change the inputs, result and model with Edit; what tools may do in Permissions; triggers below.</p>' +
1184
- '<h4 class="wf-sub">Run it, or set up its triggers</h4>' + workflowStartsHtml(w, name, params);
1189
+ return '<div class="wf-cb">' + '<div class="wf-cb-k">trigger</div><div class="wf-cb-v wf-trigger">' + triggerHtml + '</div>' + row('inputs', inputs) + row('tools', tools) + row('result', result) + row('model', [model]) + '</div>' +
1190
+ '<p class="hint" style="margin:0">Change the inputs, result and model with Edit, and what tools may do in Permissions.</p>';
1185
1191
  }
1186
1192
 
1187
1193
  function workflowBriefHtml(w) {
@@ -1289,12 +1295,13 @@ ${consoleShellScript}
1289
1295
  '<div class="wf-row-head" role="button" tabindex="0" aria-expanded="' + open + '">' +
1290
1296
  '<span class="wf-row-caret" aria-hidden="true"></span>' +
1291
1297
  '<div class="wf-row-main"><strong>' + escapeHtml(w.title) + '</strong>' + (w.description ? '<span class="wf-row-desc">' + escapeHtml(w.description) + '</span>' : '') + '</div>' +
1292
- '<span class="wf-row-starts">' + escapeHtml(workflowStartsSummary(w)) + '</span>' +
1298
+ '<span class="wf-row-starts">' + workflowStartsSummary(w) + '</span>' +
1293
1299
  '<span class="wf-row-last">' + workflowLastRunHtml(last) + '</span>' +
1294
1300
  '<span class="wf-row-actions"><button type="button" class="workflow-edit">Edit</button><button type="button" class="wf-remove workflow-forget" title="Its schedules and webhooks go; its instructions stay as a skill for Chat">Remove</button></span>' +
1295
1301
  '</div>' +
1296
1302
  '<div class="wf-row-body"' + (open ? '' : ' hidden') + '>' +
1297
1303
  '<div class="wf-chips">' + workflowStatusChips(w) + '</div>' +
1304
+ workflowRunBarHtml(w, params) +
1298
1305
  '<div class="wf-tabs" role="tablist">' + tabBtn('contract', 'Contract') + tabBtn('brief', 'Brief') + tabBtn('evidence', 'Evidence' + (runs ? ' <span class="wf-tab-count">' + w.recentRuns.length + '</span>' : '')) + '</div>' +
1299
1306
  panel('contract', workflowContractHtml(w, name, params)) +
1300
1307
  panel('brief', workflowBriefHtml(w)) +
@@ -1561,10 +1568,6 @@ ${consoleShellScript}
1561
1568
 
1562
1569
  // ---- A workflow's webhook triggers (core/workflow-triggers.ts): secret
1563
1570
  // URLs an outside service posts its events to, to start a run.
1564
- var HOOK_OUTCOMES = {
1565
- started: ['good', 'Started a run'], filtered: ['', 'Skipped by the filter'], duplicate: ['', 'A retry, skipped'],
1566
- busy: ['', 'Already running'], rejected: ['bad', 'Signature check failed'], invalid: ['bad', 'Couldn' + String.fromCharCode(8217) + 't start'], error: ['bad', 'Failed'],
1567
- };
1568
1571
  var HOOK_SENDERS = { stripe: 'Stripe', github: 'GitHub', shopify: 'Shopify', standard: 'Standard Webhooks', custom: 'your app' };
1569
1572
  var ARROW = String.fromCharCode(8594);
1570
1573
  // Where each sender takes the URL, and what it calls the secret.
@@ -1581,11 +1584,6 @@ ${consoleShellScript}
1581
1584
  }
1582
1585
 
1583
1586
  function hookRowHtml(t, shownUrl) {
1584
- var last = (t.deliveries || []).slice(0, 3).map(function (d) {
1585
- var o = HOOK_OUTCOMES[d.outcome] || ['', d.outcome];
1586
- return '<li><span class="le-pill ' + o[0] + '">' + escapeHtml(o[1]) + '</span> <span class="hint">' + escapeHtml(new Date(d.at).toLocaleString()) + '</span>' +
1587
- (d.detail ? '<div class="schedule-result">' + escapeHtml(d.detail) + '</div>' : '') + '</li>';
1588
- }).join('');
1589
1587
  var rules = [];
1590
1588
  if (t.verify) rules.push(t.verify.sender === 'custom'
1591
1589
  ? 'checks the signature in ' + escapeHtml(t.verify.header || '(header not set yet)') + ' (' + escapeHtml(t.verify.algorithm || 'sha256') + ', ' + escapeHtml(t.verify.encoding || 'hex') + ')'
@@ -1617,7 +1615,6 @@ ${consoleShellScript}
1617
1615
  '<button type="button" class="primary hook-secret-save">Add and turn on</button></div></li>' +
1618
1616
  '</ol>'
1619
1617
  : (shownUrl ? hookUrlHtml(shownUrl) : '')) +
1620
- (last ? '<ul class="schedule-history">' + last + '</ul>' : '<p class="hint" style="margin:2px 0">No deliveries yet.</p>') +
1621
1618
  '<div style="display:flex;gap:6px;flex-wrap:wrap;margin-top:4px">' +
1622
1619
  (needsSecret ? '' : '<button type="button" class="hook-toggle">' + (t.enabled ? 'Turn off' : 'Turn on') + '</button>') +
1623
1620
  '<button type="button" class="hook-rotate">New URL</button>' +
@@ -1771,21 +1768,18 @@ ${consoleShellScript}
1771
1768
  w.webhooksOff = list.length - w.webhooks - w.webhooksWaiting;
1772
1769
  var chips = card.querySelector('.wf-chips');
1773
1770
  if (chips) chips.innerHTML = workflowStatusChips(w);
1774
- var starts = card.querySelector('.workflow-starts');
1775
- if (starts) starts.classList.toggle('wf-starts-compact', startsCompact(w));
1776
- if (addBox) addBox.hidden = list.length > 0;
1771
+ var startsCell = card.querySelector('.wf-row-starts');
1772
+ if (startsCell) startsCell.innerHTML = workflowStartsSummary(w);
1777
1773
  // One waiting for its secret, or just made: open the Run options
1778
1774
  // row it's in, so its steps show.
1779
1775
  var row = box.closest('details');
1780
1776
  if (row && (shownId || w.webhooksWaiting)) row.open = true;
1781
1777
  var setupPending = list.some(function (t) { return t.verify && !t.verify.secret_set; });
1778
+ // Finish a planned webhook's setup before offering a second one:
1779
+ // + Webhook beside + Schedule waits until then.
1780
+ if (addBox) addBox.hidden = setupPending;
1782
1781
  box.innerHTML = list.map(function (t) { return hookRowHtml(t, t.trigger_id === shownId ? shownUrl : null); }).join('') +
1783
- // Finish a planned webhook's setup before offering a second one.
1784
- (list.length
1785
- ? (setupPending
1786
- ? '<p class="hint" style="margin:8px 0 0">Finish setting up the webhook above before adding another.</p>'
1787
- : '<div style="margin-top:10px"><button type="button" class="hook-add-another">Add another webhook</button></div>')
1788
- : '');
1782
+ (setupPending ? '<p class="hint" style="margin:8px 0 0">Finish setting up the webhook above before adding another.</p>' : '');
1789
1783
  wire();
1790
1784
  });
1791
1785
  }
@@ -1831,10 +1825,6 @@ ${consoleShellScript}
1831
1825
  });
1832
1826
  })(rows[i]);
1833
1827
  }
1834
- var addButton = box.querySelector('.hook-add-another');
1835
- if (addButton) addButton.addEventListener('click', function () {
1836
- openHookFormDialog(w, base, function (url, id) { render(url, id); });
1837
- });
1838
1828
  }
1839
1829
  render(shown ? shown.url : null, shown ? shown.id : null);
1840
1830
  }
@@ -1888,18 +1878,8 @@ ${consoleShellScript}
1888
1878
  focusScheduleRow();
1889
1879
  });
1890
1880
  }
1891
- // The ? beside each way it starts shows or hides what it is.
1892
- var helps = card.querySelectorAll('.help-q');
1893
- for (var hq = 0; hq < helps.length; hq++) {
1894
- helps[hq].addEventListener('click', function (ev) {
1895
- var btn = ev.currentTarget;
1896
- var text = btn.closest('.wf-start').querySelector('.help-text');
1897
- text.hidden = !text.hidden;
1898
- btn.setAttribute('aria-expanded', String(!text.hidden));
1899
- });
1900
- }
1901
- // Shown only while it has none: straight to the form; once one is made,
1902
- // it's listed in the tile with its setup steps.
1881
+ // + Webhook, beside + Schedule: straight to the form; once made, it's
1882
+ // listed in the trigger row with its setup steps.
1903
1883
  card.querySelector('.workflow-hooks-btn').addEventListener('click', function () {
1904
1884
  var w = workflowsById[id];
1905
1885
  if (!w) return;
@@ -1181,7 +1181,7 @@ ${consoleShellScript}
1181
1181
  box.innerHTML = intro +
1182
1182
  '<form id="policiesForm" style="display:flex;flex-direction:column;gap:10px;max-width:720px">' +
1183
1183
  '<label for="policiesText" class="hint">One rule per line, with its real numbers</label>' +
1184
- '<textarea id="policiesText" rows="8" placeholder="- Refunds within 30 days of delivery.&#10;- Parcels lost over 15 days are reshipped, not refunded.&#10;- Sign customer emails: Everymarket Support">' + escapeHtml(p.policies || '') + '</textarea>' +
1184
+ '<textarea id="policiesText" rows="8" placeholder="- Refunds within 30 days of purchase.&#10;- Never share customer details with other customers.&#10;- Reply in the language the customer wrote in.&#10;- Sign emails: The Support Team">' + escapeHtml(p.policies || '') + '</textarea>' +
1185
1185
  '<div><button type="submit" class="primary">Save</button></div>' +
1186
1186
  '<div id="policiesMsg" class="hint"></div>' +
1187
1187
  '</form>';
@@ -466,7 +466,10 @@ ${consoleShellScript}
466
466
  trigger.push(esc(SENDERS[w.sender] || w.sender) + ' webhook' + (w.filter ? ', <code>' + esc(w.filter.values.join(' | ')) + '</code>' : ''));
467
467
  Object.keys(w.mapping || {}).forEach(function (k) { trigger.push('<span class="wf-cb-indent"><code>' + esc(k) + '</code> ' + String.fromCharCode(8592) + ' <code>' + esc(w.mapping[k]) + '</code></span>'); });
468
468
  }
469
- trigger.push('<span class="hint">by hand (Run now) or from an app (API)</span>');
469
+ // Any workflow can also be started by hand or by an app: said as an
470
+ // extra, not as a trigger, and without one it can still be given a
471
+ // schedule or a webhook.
472
+ trigger.push('<span class="hint">' + (trigger.length ? 'also by hand (Run now) or from an app (API)' : 'it runs when started by hand (Run now) or from an app (API); a schedule or webhook can be set up once it' + String.fromCharCode(8217) + 's created') + '</span>');
470
473
  var names = Object.keys(p.parameters || {});
471
474
  var inputs = names.length ? names.map(function (n) { return '<code>' + esc(n) + '</code>' + (p.parameters[n].required ? ' (required)' : ''); }) : ['<span class="hint">none: every run is the same</span>'];
472
475
  var groups = { allow: [], ask: [], deny: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopengine",
3
- "version": "0.3.76",
3
+ "version": "0.3.77",
4
4
  "type": "module",
5
5
  "description": "Runtime for tool-using AI agents with a transparent ReAct loop.",
6
6
  "license": "MIT",