loopengine 0.3.76 → 0.3.78

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.
@@ -76,12 +76,6 @@ export const agentsConfigPageHtml = `<!doctype html>
76
76
  .wf-card-title { min-width: 0; }
77
77
  .wf-card-title h3 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; color: var(--ink); }
78
78
  .wf-card-title p { margin: 4px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--ink-muted); }
79
- .wf-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
80
- .wf-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-muted); font-size: 12px; font-weight: 550; line-height: 1.5; }
81
- .wf-chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
82
- .wf-chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
83
- .wf-chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
84
- .wf-chip.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
85
79
  .wf-card-actions { flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 50%; }
86
80
  .wf-card-actions button { height: 32px; padding: 0 12px; border-radius: 8px; font-size: 13px; }
87
81
  .wf-card-actions .workflow-edit { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
@@ -96,23 +90,31 @@ export const agentsConfigPageHtml = `<!doctype html>
96
90
  .wf-list-box { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; }
97
91
  .wf-row + .wf-row { border-top: 1px solid var(--line); }
98
92
  .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; }
93
+ .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
94
  .wf-row-head:hover { background: var(--surface); }
101
95
  .wf-row-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
102
96
  .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; }
103
97
  .wf-row.is-open .wf-row-caret { transform: rotate(45deg); }
104
98
  .wf-row-main { min-width: 0; display: grid; gap: 2px; }
105
99
  .wf-row-main strong { font-size: 14px; font-weight: 650; color: var(--ink); }
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; }
100
+ .wf-desc { margin: 0; max-width: 72ch; font-size: 13.5px; line-height: 1.55; color: var(--ink-muted); overflow-wrap: anywhere; }
101
+ .wf-row-starts { display: grid; gap: 2px; font-size: 12.5px; color: var(--ink-muted); min-width: 0; }
102
+ .wf-start-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
103
+ .wf-start-state { font-size: 11px; font-weight: 700; padding: 0 6px; margin-left: 2px; border-radius: 999px; }
104
+ .wf-start-state + .wf-start-state { margin-left: 4px; }
105
+ .wf-start-state.on { background: var(--good-soft); color: var(--good); }
106
+ .wf-start-state.off { background: var(--warn-soft); color: var(--warn); }
107
+ .wf-start-state.warn { background: var(--warn-soft); color: var(--warn); }
108
108
  .wf-row-last { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; white-space: nowrap; }
109
109
  .wf-row-last .hint { white-space: nowrap; }
110
+ /* The row's grey notes ("Run now or API", "Last run …", "No runs yet",
111
+ "+2 more schedules") at the same size as its schedule lines. */
112
+ .wf-row-starts .hint, .wf-row-last .hint { font-size: 12.5px; }
110
113
  .wf-row-actions { display: flex; gap: 6px; }
111
114
  .wf-row-actions button, .wf-row-foot button { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
112
115
  .wf-row-actions button:hover:not(:disabled) { background: var(--accent); color: var(--on-accent); }
113
116
  .wf-row-body { padding: 4px 16px 16px 44px; display: grid; gap: 12px; }
114
117
  .wf-row-body[hidden], .wf-panel[hidden] { display: none; }
115
- .wf-row-body .wf-chips { margin-top: 0; }
116
118
  .wf-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
117
119
  .wf-tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 10px; margin-bottom: -1px; font-size: 13px; font-weight: 600; color: var(--ink-muted); }
118
120
  .wf-tab:hover:not(:disabled) { background: none; color: var(--ink); }
@@ -121,7 +123,6 @@ export const agentsConfigPageHtml = `<!doctype html>
121
123
  .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
124
  .wf-original { margin-top: 10px; }
123
125
  .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
126
  .wf-row .workflow-result:empty { display: none; }
126
127
  .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
128
  .wf-cb-k { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--accent-ink); padding-top: 1px; }
@@ -135,6 +136,21 @@ export const agentsConfigPageHtml = `<!doctype html>
135
136
  .wf-cb-decision.ask { background: var(--warn-soft); color: var(--warn); }
136
137
  .wf-cb-decision.deny { background: var(--bad-soft); color: var(--bad); }
137
138
  @media (max-width: 520px) { .wf-cb { grid-template-columns: minmax(0, 1fr); gap: 2px; } .wf-cb-v { margin-bottom: 8px; } }
139
+ .wf-triggers { display: grid; gap: 8px; }
140
+ .wf-triggers .wf-sub:first-child { margin-top: 0; }
141
+ .wf-trigger { display: grid; gap: 8px; }
142
+ .wf-trigger-item { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
143
+ .wf-trigger-item button, .wf-trigger-add button, .wf-trigger .workflow-hook button { padding: 2px 10px; font-size: 12px; }
144
+ .wf-trigger .workflow-hooks:empty { display: none; }
145
+ .wf-trigger .workflow-hook { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
146
+ .wf-trigger-add { display: flex; gap: 6px; flex-wrap: wrap; }
147
+ .wf-trigger-add [hidden] { display: none; }
148
+ .wf-api summary { cursor: pointer; font-size: 12.5px; color: var(--accent-ink); }
149
+ .wf-api[open] { display: grid; gap: 6px; }
150
+ .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; }
151
+ .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); }
152
+ .wf-run-bar .workflow-params { margin: 0; flex: 1 1 320px; }
153
+ .wf-run-bar-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-left: auto; }
138
154
  .wf-sub { margin: 6px 0 0; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted); }
139
155
  .wf-scores { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
140
156
  .wf-score { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
@@ -159,8 +175,8 @@ export const agentsConfigPageHtml = `<!doctype html>
159
175
  .wp-mono { font-family: var(--font-mono); font-size: 12.5px; }
160
176
  @media (max-width: 640px) { .wf-scores { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
161
177
  .wf-row-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
162
- .wf-row-actions .wf-remove { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
163
- .wf-row-actions .wf-remove:hover:not(:disabled) { background: var(--bad); color: var(--bg); }
178
+ .wf-row-foot .wf-remove { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
179
+ .wf-row-foot .wf-remove:hover:not(:disabled) { background: var(--bad); color: var(--bg); }
164
180
  @media (max-width: 760px) {
165
181
  .wf-row-head { grid-template-columns: 14px minmax(0, 1fr) auto; row-gap: 6px; }
166
182
  .wf-row-starts, .wf-row-last { white-space: normal; }
@@ -179,13 +195,6 @@ export const agentsConfigPageHtml = `<!doctype html>
179
195
  .workflow-section-content { padding: 4px 20px 24px; }
180
196
  .workflow-section-meta { margin-left: auto; color: var(--ink-muted); font-size: 12px; font-weight: 500; }
181
197
  .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
198
  @media (max-width: 640px) {
190
199
  .wf-tab-head, .wf-card-head { flex-direction: column; }
191
200
  .wf-card-actions { max-width: none; justify-content: flex-start; }
@@ -206,19 +215,8 @@ export const agentsConfigPageHtml = `<!doctype html>
206
215
  form.add-source .schedule-when select, form.add-source .schedule-when input[type="datetime-local"] { width: auto; }
207
216
  .workflow-card.workflow-focus { box-shadow: 0 0 0 2px var(--le-accent, #0f766e); transition: box-shadow 0.3s; }
208
217
  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
218
  .workflow-run-notify { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
211
219
  .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
220
  .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
221
  .workflow-params { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
224
222
  .workflow-params[hidden] { display: none; }
@@ -968,40 +966,16 @@ ${consoleShellScript}
968
966
  // from "Describe a workflow": each with its instructions, what starts it
969
967
  // (its real schedules and webhooks), its recent runs and Run now. ----
970
968
 
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) {
969
+ // A workflow's schedules, each with its state and Pause/Resume and
970
+ // Remove, as lines of its contract's trigger row.
971
+ function workflowScheduleItemsHtml(w, agentName) {
972
+ return (w.schedules || []).map(function (x) {
999
973
  var state = x.waiting ? '<span class="le-pill ask">Waiting for a decision</span>'
1000
974
  : x.status === 'paused' ? '<span class="le-pill warn">Paused</span>'
1001
975
  : x.status === 'running' ? '<span class="le-pill accent">Running</span>'
1002
976
  : (x.nextRunAt ? '<span class="hint">next ' + escapeHtml(new Date(x.nextRunAt).toLocaleString()) + '</span>' : '');
1003
977
  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">' +
978
+ return '<div class="wf-trigger-item">' +
1005
979
  '<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
980
  escapeHtml(x.describe.charAt(0).toUpperCase() + x.describe.slice(1)) + '</a></span>' + state +
1007
981
  (values ? '<span class="hint">' + values + '</span>' : '') +
@@ -1010,58 +984,38 @@ ${consoleShellScript}
1010
984
  (x.status === 'paused' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="resume">Resume</button>'
1011
985
  : x.status === 'scheduled' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="pause">Pause</button>' : '') +
1012
986
  '<button type="button" class="delete-btn workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="cancel">Remove</button>' +
1013
- '</span></li>';
987
+ '</span></div>';
1014
988
  }).join('');
989
+ }
990
+
991
+ // Run now, above the tabs: the values a run is given, and whether its
992
+ // result also goes to the messaging app.
993
+ function workflowRunBarHtml(w, paramsHtml) {
994
+ return '<div class="wf-run-bar">' +
995
+ (paramsHtml ? '<div class="workflow-params">' + paramsHtml + '</div>' : '') +
996
+ '<div class="wf-run-bar-controls">' +
997
+ '<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>' +
998
+ '<button type="button" class="workflow-run primary">Run now</button></div>' +
999
+ '</div>';
1000
+ }
1001
+
1002
+ // The call an app makes to start a run, folded under the trigger row.
1003
+ function workflowApiHtml(w, agentName) {
1015
1004
  var paramNames = Object.keys(w.parameters || {});
1016
1005
  // A body that shows what a call can carry: its values, and waiting
1017
1006
  // for the result.
1018
1007
  var example = '{ ' + (paramNames.length ? '"params": { ' + paramNames.map(function (p) { return '"' + p + '": "' + String.fromCharCode(8230) + '"'; }).join(', ') + ' }, ' : '') + '"wait": true }';
1019
1008
  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>';
1041
- }
1042
-
1043
- // What starts a workflow and what it's doing, as chips under its title:
1044
- // each schedule, then its webhooks; one line when nothing starts it.
1045
- function workflowStatusChips(w) {
1046
- var chips = [];
1047
- var cap = function (t) { return t ? t.charAt(0).toUpperCase() + t.slice(1) : t; };
1048
- var when = function (iso) { return new Date(iso).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); };
1049
- var DOT = ' ' + String.fromCharCode(183) + ' ';
1050
- (w.schedules || []).forEach(function (x) {
1051
- var what = escapeHtml(cap(x.describe));
1052
- if (x.waiting) chips.push('<span class="wf-chip warn">' + what + DOT + 'waiting for a decision</span>');
1053
- else if (x.status === 'running') chips.push('<span class="wf-chip accent">' + what + DOT + 'running</span>');
1054
- else if (x.status === 'paused') chips.push('<span class="wf-chip warn">' + what + DOT + 'paused</span>');
1055
- else chips.push('<span class="wf-chip good">' + what + (x.nextRunAt ? DOT + 'next ' + escapeHtml(when(x.nextRunAt)) : '') + '</span>');
1056
- });
1057
- var n = function (count, one, many) { return count === 1 ? one : count + ' ' + many; };
1058
- if (w.webhooks) chips.push('<span class="wf-chip good">' + n(w.webhooks, 'Webhook on', 'webhooks on') + '</span>');
1059
- if (w.webhooksWaiting) chips.push('<span class="wf-chip warn">' + n(w.webhooksWaiting, 'Webhook needs its signing secret', 'webhooks need their signing secrets') + '</span>');
1060
- if (w.webhooksOff) chips.push('<span class="wf-chip">' + n(w.webhooksOff, 'Webhook off', 'webhooks off') + '</span>');
1061
- if (!chips.length) chips.push('<span class="wf-chip">Runs when you start it: Run now, the API or Chat</span>');
1062
- return chips.join('');
1009
+ return '<details class="wf-api"><summary>Show the API call</summary>' +
1010
+ '<p class="hint" style="margin:0">Your own app starts a run by calling this address with an API key.</p>' +
1011
+ '<pre>POST ' + escapeHtml(apiUrl) + String.fromCharCode(10) + escapeHtml(example) + '</pre>' +
1012
+ '<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. ') +
1013
+ '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>' +
1014
+ '</details>';
1063
1015
  }
1064
1016
 
1017
+
1018
+
1065
1019
  // Which workflow is open in the list, and each one's chosen tab: kept
1066
1020
  // across redraws (a running run's refresh, a save), and in the URL.
1067
1021
  var openWorkflowId = new URLSearchParams(location.search).get('workflow') || null;
@@ -1075,22 +1029,42 @@ ${consoleShellScript}
1075
1029
  return (w.recentRuns || []).some(function (r) { return r.status === 'awaiting_approval'; }) || (w.schedules || []).some(function (x) { return x.waiting; });
1076
1030
  }
1077
1031
 
1078
- // How it starts, in a few words for its row.
1032
+ // How it starts, for its row: each schedule (saying when it's paused)
1033
+ // and its webhooks on or off, so its state shows without opening it.
1079
1034
  function workflowStartsSummary(w) {
1080
- var parts = [];
1035
+ var lines = [];
1036
+ var state = function (text, kind) { return ' <span class="wf-start-state ' + kind + '">' + text + '</span>'; };
1081
1037
  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';
1038
+ schedules.slice(0, 2).forEach(function (x) {
1039
+ lines.push(escapeHtml(x.describe.charAt(0).toUpperCase() + x.describe.slice(1)) + (x.status === 'paused' ? state('paused', 'off') : ''));
1040
+ });
1041
+ if (schedules.length > 2) {
1042
+ var more = schedules.slice(2);
1043
+ var pausedMore = more.filter(function (x) { return x.status === 'paused'; }).length;
1044
+ lines.push('<span class="hint">+' + more.length + ' more ' + (more.length === 1 ? 'schedule' : 'schedules') + '</span>' + (pausedMore ? state(pausedMore + ' paused', 'off') : ''));
1045
+ }
1046
+ var on = w.webhooks || 0, waiting = w.webhooksWaiting || 0, off = w.webhooksOff || 0;
1047
+ if (on + waiting + off) {
1048
+ var name = on + waiting + off === 1 ? 'Webhook' : 'Webhooks';
1049
+ var states = [];
1050
+ if (on) states.push(state((on + waiting + off > 1 ? on + ' ' : '') + 'on', 'on'));
1051
+ if (off) states.push(state((on + waiting + off > 1 ? off + ' ' : '') + 'off', 'off'));
1052
+ if (waiting) states.push(state('needs its signing secret', 'warn'));
1053
+ lines.push(name + states.join(''));
1054
+ }
1055
+ // Nothing starts it on its own: the ways it does start.
1056
+ if (!lines.length) return '<span class="hint">Run now or API</span>';
1057
+ return lines.map(function (l) { return '<span class="wf-start-line">' + l + '</span>'; }).join('');
1085
1058
  }
1086
1059
 
1087
1060
  function workflowLastRunHtml(r) {
1088
1061
  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>'
1062
+ var when = new Date(r.started_at).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
1063
+ // A run that finished is just when it ran; the others say their state.
1064
+ if (r.status === 'done') return '<span class="hint">Last run ' + escapeHtml(when) + '</span>';
1065
+ var pill = r.status === 'error' ? '<span class="le-pill bad">Failed</span>'
1091
1066
  : r.status === 'awaiting_approval' ? '<span class="le-pill ask">Waiting for a decision</span>'
1092
1067
  : '<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
1068
  return pill + '<span class="hint">' + escapeHtml(when) + '</span>';
1095
1069
  }
1096
1070
 
@@ -1146,18 +1120,37 @@ ${consoleShellScript}
1146
1120
  function contractLinesHtml(lines) {
1147
1121
  return lines.map(function (l) { return '<div class="wf-cb-line">' + l + '</div>'; }).join('');
1148
1122
  }
1123
+ // Its Triggers tab: Run now, its schedules and webhooks with their
1124
+ // controls, a way to add either, and the call an app makes.
1125
+ function workflowTriggersHtml(w, name, params) {
1126
+ var schedules = workflowScheduleItemsHtml(w, name);
1127
+ return '<div class="wf-triggers">' +
1128
+ '<h4 class="wf-sub">Run now</h4>' + workflowRunBarHtml(w, params) +
1129
+ '<h4 class="wf-sub">Schedules and webhooks</h4>' +
1130
+ '<div class="wf-trigger">' + schedules +
1131
+ '<div class="workflow-hooks"></div>' +
1132
+ (!schedules && !(w.webhooks || w.webhooksWaiting || w.webhooksOff) ? '<p class="hint wf-trigger-none" style="margin:0">None yet: it runs only when started by hand or from an app.</p>' : '') +
1133
+ '<div class="wf-trigger-add"><button type="button" class="workflow-add-schedule">+ Schedule</button>' +
1134
+ '<span class="workflow-hooks-add"' + (w.webhooksWaiting ? ' hidden' : '') + '><button type="button" class="workflow-hooks-btn">+ Webhook</button></span></div>' +
1135
+ '</div>' +
1136
+ '<h4 class="wf-sub">API</h4>' + workflowApiHtml(w, name) +
1137
+ '</div>';
1138
+ }
1139
+
1149
1140
  function workflowContractHtml(w, name, params) {
1141
+ // What starts it, as the contract says it; they're set up in Triggers.
1150
1142
  var trigger = [];
1151
1143
  (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>' : ''));
1144
+ trigger.push('schedule, ' + escapeHtml(x.describe) + (x.status === 'paused' ? ' <span class="le-pill warn">Paused</span>' : ''));
1154
1145
  });
1155
1146
  (w.triggers || []).forEach(function (t) {
1156
1147
  trigger.push(escapeHtml(SENDER_LABELS[t.sender] || t.sender) + ' webhook' + (t.filter ? ', <code>' + escapeHtml(t.filter.values.join(' | ')) + '</code>' : '') +
1157
1148
  (t.waiting ? ' <span class="le-pill ask">Needs its signing secret</span>' : !t.enabled ? ' <span class="le-pill warn">Off</span>' : ''));
1158
1149
  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>'); });
1159
1150
  });
1160
- trigger.push('<span class="hint">by hand (Run now) or from an app (API)</span>');
1151
+ trigger.push('<span class="hint">' + (trigger.length
1152
+ ? 'also by hand (Run now) or from an app (API); set them up in Triggers'
1153
+ : 'it runs when started by hand (Run now) or from an app (API), or set up a schedule or webhook in Triggers') + '</span>');
1161
1154
  var names = Object.keys(w.parameters || {});
1162
1155
  var inputs = names.length ? names.map(function (n) {
1163
1156
  var spec = w.parameters[n];
@@ -1180,8 +1173,7 @@ ${consoleShellScript}
1180
1173
  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
1174
  var row = function (k, lines) { return '<div class="wf-cb-k">' + k + '</div><div class="wf-cb-v">' + contractLinesHtml(lines) + '</div>'; };
1182
1175
  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);
1176
+ '<p class="hint" style="margin:0">Change the inputs, result and model with Edit, and what tools may do in Permissions.</p>';
1185
1177
  }
1186
1178
 
1187
1179
  function workflowBriefHtml(w) {
@@ -1288,19 +1280,21 @@ ${consoleShellScript}
1288
1280
  return '<article class="workflow-card wf-row' + (open ? ' is-open' : '') + '" data-workflow="' + escapeHtml(w.id) + '">' +
1289
1281
  '<div class="wf-row-head" role="button" tabindex="0" aria-expanded="' + open + '">' +
1290
1282
  '<span class="wf-row-caret" aria-hidden="true"></span>' +
1291
- '<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>' +
1283
+ '<div class="wf-row-main"><strong>' + escapeHtml(w.title) + '</strong></div>' +
1284
+ '<span class="wf-row-starts">' + workflowStartsSummary(w) + '</span>' +
1293
1285
  '<span class="wf-row-last">' + workflowLastRunHtml(last) + '</span>' +
1294
- '<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>' +
1286
+ '<span class="wf-row-actions"><button type="button" class="workflow-triggers-open">Triggers</button><button type="button" class="workflow-edit">Edit</button></span>' +
1295
1287
  '</div>' +
1296
1288
  '<div class="wf-row-body"' + (open ? '' : ' hidden') + '>' +
1297
- '<div class="wf-chips">' + workflowStatusChips(w) + '</div>' +
1298
- '<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>' +
1289
+ // What it does, in full, once it's open (the row shows just its name).
1290
+ (w.description && w.description !== w.title ? '<p class="wf-desc">' + escapeHtml(w.description) + '</p>' : '') +
1291
+ '<div class="wf-tabs" role="tablist">' + tabBtn('contract', 'Contract') + tabBtn('triggers', 'Triggers') + tabBtn('brief', 'Brief') + tabBtn('evidence', 'Evidence' + (runs ? ' <span class="wf-tab-count">' + w.recentRuns.length + '</span>' : '')) + '</div>' +
1299
1292
  panel('contract', workflowContractHtml(w, name, params)) +
1293
+ panel('triggers', workflowTriggersHtml(w, name, params)) +
1300
1294
  panel('brief', workflowBriefHtml(w)) +
1301
1295
  panel('evidence', workflowEvidenceHtml(w, runs)) +
1302
1296
  '<div class="hint workflow-result"></div>' +
1303
- '<div class="wf-row-foot"><span class="hint">Skill <code>' + escapeHtml(w.id) + '</code></span></div>' +
1297
+ '<div class="wf-row-foot"><span class="hint">Skill <code>' + escapeHtml(w.id) + '</code></span><button type="button" class="wf-remove workflow-forget" title="Its schedules and webhooks go; its instructions stay as a skill for Chat">Remove</button></div>' +
1304
1298
  '</div>' +
1305
1299
  '</article>';
1306
1300
  }).join('') + '</div>';
@@ -1561,10 +1555,6 @@ ${consoleShellScript}
1561
1555
 
1562
1556
  // ---- A workflow's webhook triggers (core/workflow-triggers.ts): secret
1563
1557
  // 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
1558
  var HOOK_SENDERS = { stripe: 'Stripe', github: 'GitHub', shopify: 'Shopify', standard: 'Standard Webhooks', custom: 'your app' };
1569
1559
  var ARROW = String.fromCharCode(8594);
1570
1560
  // Where each sender takes the URL, and what it calls the secret.
@@ -1581,11 +1571,6 @@ ${consoleShellScript}
1581
1571
  }
1582
1572
 
1583
1573
  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
1574
  var rules = [];
1590
1575
  if (t.verify) rules.push(t.verify.sender === 'custom'
1591
1576
  ? 'checks the signature in ' + escapeHtml(t.verify.header || '(header not set yet)') + ' (' + escapeHtml(t.verify.algorithm || 'sha256') + ', ' + escapeHtml(t.verify.encoding || 'hex') + ')'
@@ -1617,7 +1602,6 @@ ${consoleShellScript}
1617
1602
  '<button type="button" class="primary hook-secret-save">Add and turn on</button></div></li>' +
1618
1603
  '</ol>'
1619
1604
  : (shownUrl ? hookUrlHtml(shownUrl) : '')) +
1620
- (last ? '<ul class="schedule-history">' + last + '</ul>' : '<p class="hint" style="margin:2px 0">No deliveries yet.</p>') +
1621
1605
  '<div style="display:flex;gap:6px;flex-wrap:wrap;margin-top:4px">' +
1622
1606
  (needsSecret ? '' : '<button type="button" class="hook-toggle">' + (t.enabled ? 'Turn off' : 'Turn on') + '</button>') +
1623
1607
  '<button type="button" class="hook-rotate">New URL</button>' +
@@ -1769,23 +1753,18 @@ ${consoleShellScript}
1769
1753
  w.webhooks = list.filter(function (t) { return t.enabled; }).length;
1770
1754
  w.webhooksWaiting = list.filter(function (t) { return !t.enabled && t.verify && !t.verify.secret_set; }).length;
1771
1755
  w.webhooksOff = list.length - w.webhooks - w.webhooksWaiting;
1772
- var chips = card.querySelector('.wf-chips');
1773
- 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;
1756
+ var startsCell = card.querySelector('.wf-row-starts');
1757
+ if (startsCell) startsCell.innerHTML = workflowStartsSummary(w);
1777
1758
  // One waiting for its secret, or just made: open the Run options
1778
1759
  // row it's in, so its steps show.
1779
1760
  var row = box.closest('details');
1780
1761
  if (row && (shownId || w.webhooksWaiting)) row.open = true;
1781
1762
  var setupPending = list.some(function (t) { return t.verify && !t.verify.secret_set; });
1763
+ // Finish a planned webhook's setup before offering a second one:
1764
+ // + Webhook beside + Schedule waits until then.
1765
+ if (addBox) addBox.hidden = setupPending;
1782
1766
  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
- : '');
1767
+ (setupPending ? '<p class="hint" style="margin:8px 0 0">Finish setting up the webhook above before adding another.</p>' : '');
1789
1768
  wire();
1790
1769
  });
1791
1770
  }
@@ -1831,10 +1810,6 @@ ${consoleShellScript}
1831
1810
  });
1832
1811
  })(rows[i]);
1833
1812
  }
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
1813
  }
1839
1814
  render(shown ? shown.url : null, shown ? shown.id : null);
1840
1815
  }
@@ -1856,6 +1831,11 @@ ${consoleShellScript}
1856
1831
  var tabs = card.querySelectorAll('.wf-tab');
1857
1832
  for (var t = 0; t < tabs.length; t++) tabs[t].addEventListener('click', function (ev) { showWorkflowTab(card, ev.currentTarget.dataset.tab); });
1858
1833
  card.querySelector('.workflow-edit').addEventListener('click', function () { openWorkflowEditor(name, card); });
1834
+ // Opens the row (if it's closed) on its Triggers tab.
1835
+ card.querySelector('.workflow-triggers-open').addEventListener('click', function () {
1836
+ if (!card.classList.contains('is-open')) setWorkflowOpen(card, true);
1837
+ showWorkflowTab(card, 'triggers');
1838
+ });
1859
1839
  // Evidence: save a run as an eval case, change or remove a case, run them.
1860
1840
  card.querySelector('.wf-row-body').addEventListener('click', function (ev) {
1861
1841
  var btn = ev.target.closest('.wf-save-case, .wf-case-remove, .wf-case-save, .wf-evals-run');
@@ -1888,18 +1868,8 @@ ${consoleShellScript}
1888
1868
  focusScheduleRow();
1889
1869
  });
1890
1870
  }
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.
1871
+ // + Webhook, beside + Schedule: straight to the form; once made, it's
1872
+ // listed in the trigger row with its setup steps.
1903
1873
  card.querySelector('.workflow-hooks-btn').addEventListener('click', function () {
1904
1874
  var w = workflowsById[id];
1905
1875
  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.78",
4
4
  "type": "module",
5
5
  "description": "Runtime for tool-using AI agents with a transparent ReAct loop.",
6
6
  "license": "MIT",