loopengine 0.4.13 → 0.5.0
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.
- package/dist/core/audit-store.d.ts +71 -8
- package/dist/core/audit-store.js +206 -12
- package/dist/core/input-schema.d.ts +47 -0
- package/dist/core/input-schema.js +180 -0
- package/dist/core/output-schema.d.ts +30 -0
- package/dist/core/output-schema.js +105 -0
- package/dist/core/run-agent.js +35 -2
- package/dist/core/scheduler.d.ts +6 -0
- package/dist/core/scheduler.js +22 -16
- package/dist/core/system-agents/goal-planner.d.ts +3 -3
- package/dist/core/system-agents/goal-planner.js +9 -5
- package/dist/core/trace.d.ts +34 -0
- package/dist/core/trace.js +149 -0
- package/dist/core/workflow-runs.d.ts +30 -5
- package/dist/core/workflow-runs.js +62 -12
- package/dist/core/workflow-triggers.d.ts +8 -1
- package/dist/core/workflow-triggers.js +13 -0
- package/dist/core/workflows.d.ts +17 -1
- package/dist/core/workflows.js +72 -9
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/web/agents-config-page.js +372 -67
- package/dist/web/audit-admin.d.ts +2 -2
- package/dist/web/audit-admin.js +5 -3
- package/dist/web/audit-page.js +7 -5
- package/dist/web/change-log.js +4 -2
- package/dist/web/console-shell.js +1 -1
- package/dist/web/decide-page.js +1 -1
- package/dist/web/goals-admin.d.ts +8 -5
- package/dist/web/goals-admin.js +25 -5
- package/dist/web/goals-page.js +28 -8
- package/dist/web/home-page.js +3 -3
- package/dist/web/inbox-page.js +143 -1
- package/dist/web/run-trace.d.ts +114 -0
- package/dist/web/run-trace.js +79 -0
- package/dist/web/upgrade-admin.js +19 -5
- package/dist/web/workflow-admin.d.ts +12 -3
- package/dist/web/workflow-admin.js +42 -7
- package/dist/web/workflow-audit-report.js +5 -5
- package/dist/web/workflow-audit.d.ts +3 -3
- package/dist/web/workflow-audit.js +12 -11
- package/dist/web/workflow-drafts.d.ts +75 -0
- package/dist/web/workflow-drafts.js +112 -0
- package/dist/web/workflow-evidence.d.ts +17 -4
- package/dist/web/workflow-evidence.js +22 -6
- package/dist/web/workflow-health.d.ts +2 -2
- package/dist/web/workflow-health.js +7 -1
- package/package.json +9 -1
|
@@ -143,6 +143,7 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
143
143
|
.wf-tab:hover:not(:disabled) { background: none; color: var(--ink); }
|
|
144
144
|
.wf-tab[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }
|
|
145
145
|
.wf-msg-form { display: flex; flex-direction: column; gap: 14px; }
|
|
146
|
+
.wf-draft-note { margin: 0; display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--ink-muted); }
|
|
146
147
|
.wf-msg-dests { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
|
|
147
148
|
.wf-msg-dest { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
|
|
148
149
|
.wf-msg-dest-k { font-weight: 600; font-size: 13px; }
|
|
@@ -285,6 +286,19 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
285
286
|
.wf-editor-part { margin: 8px 0 0; font-size: 13px; font-weight: 700; padding-top: 10px; border-top: 1px solid var(--line); }
|
|
286
287
|
.wf-editor-part:first-of-type { border-top: 0; padding-top: 0; }
|
|
287
288
|
.wp-model-row { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
289
|
+
.wf-draft { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 14px; padding: 10px 14px; border: 1px solid var(--warn, #d9a400); border-radius: 10px; background: var(--warn-soft, #fff8e1); font-size: 13.5px; }
|
|
290
|
+
.wf-draft-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
|
|
291
|
+
.wf-publish { display: grid; gap: 12px; }
|
|
292
|
+
.wf-publish h4 { margin: 4px 0 0; font-size: 13px; }
|
|
293
|
+
.wf-pub-version { margin: 0; }
|
|
294
|
+
.wf-pub-stale { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--warn-soft, #fff8e1); font-size: 13px; }
|
|
295
|
+
.wf-publish .ed-actions { align-items: center; }
|
|
296
|
+
.wf-publish .ed-actions .hint { margin-right: auto; }
|
|
297
|
+
.workflow-editor-dialog .ed-actions .hint { margin-right: auto; font-size: 12.5px; }
|
|
298
|
+
.wp-schema { font-family: var(--font-mono); font-size: 12.5px; }
|
|
299
|
+
.wf-schema { display: block; flex-basis: 100%; width: 100%; }
|
|
300
|
+
.wf-schema summary { cursor: pointer; color: var(--ink-muted); font-size: 12.5px; }
|
|
301
|
+
.wf-schema pre { margin: 6px 0 0; padding: 8px 10px; background: var(--surface); border-radius: 8px; font-size: 12px; max-height: 260px; overflow: auto; }
|
|
288
302
|
.wp-model-row input { flex: 1 1 200px; }
|
|
289
303
|
.wp-mono { font-family: var(--font-mono); font-size: 12.5px; }
|
|
290
304
|
@media (max-width: 640px) { .wf-scores { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
@@ -395,6 +409,8 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
395
409
|
.ov-name code { font-size: 12.5px; }
|
|
396
410
|
dialog.workflow-editor-dialog { width: min(760px, calc(100vw - 24px)); }
|
|
397
411
|
.ed-body .workflow-param-row input:not([type="checkbox"]) { width: auto; }
|
|
412
|
+
.ed-body .workflow-param-row select.wp-type { width: auto; flex: 0 0 140px; }
|
|
413
|
+
.ed-body .workflow-param-row .wp-limits { padding-left: 176px; }
|
|
398
414
|
.ed-body .workflow-param-row .wp-name { flex: 0 0 170px; font-family: var(--font-mono); font-size: 13px; }
|
|
399
415
|
.ed-body .workflow-param-row .wp-desc { flex: 1 1 200px; }
|
|
400
416
|
.ed-body .workflow-param-row label { display: flex; align-items: center; gap: 6px; font-weight: 400; }
|
|
@@ -422,6 +438,10 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
422
438
|
.workflow-param-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
|
423
439
|
.workflow-param-row .wp-name { width: 160px; font-family: var(--le-mono, monospace); }
|
|
424
440
|
.workflow-param-row .wp-desc { flex: 1; min-width: 200px; }
|
|
441
|
+
.workflow-param-row select.wp-type { width: auto; flex: 0 0 140px; }
|
|
442
|
+
.workflow-param-row .wp-limits { display: flex; gap: 6px; flex-basis: 100%; padding-left: 166px; }
|
|
443
|
+
.workflow-param-row .wp-limits input { flex: 1; min-width: 140px; font-size: 12.5px; }
|
|
444
|
+
.workflow-params select, .workflow-params input[type="number"], .workflow-params input[type="date"] { font: inherit; }
|
|
425
445
|
.workflow-param { display: flex; flex-direction: column; gap: 3px; flex: 1 1 220px; font-size: 12px; min-width: 180px; }
|
|
426
446
|
.workflow-param textarea { width: 100%; box-sizing: border-box; resize: none; overflow-y: hidden; max-height: 18em; font: inherit; font-size: 13px; line-height: 1.45; }
|
|
427
447
|
.advanced-part { font-size: 17px; font-weight: 600; margin: 28px 0 12px; padding-top: 16px; border-top: 1px solid var(--line); }
|
|
@@ -914,7 +934,7 @@ ${renderMarkdownScript}
|
|
|
914
934
|
(cfg.skills.length + (cfg.skills.length === 1 ? ' skill' : ' skills')) + (toolNames.length ? ' \u00b7 ' + escapeHtml(toolNames.slice(0, 2).join(', ') + (toolNames.length > 2 ? ', \u2026' : '')) : '')) +
|
|
915
935
|
card('actauth', 'Permissions', rules.length + (rules.length === 1 ? ' rule' : ' rules'),
|
|
916
936
|
(asks ? asks + ' need approval \u00b7 ' : '') + 'unmatched calls: ' + escapeHtml(cfg.permissions.defaultDecision)) +
|
|
917
|
-
card('messaging', 'Messaging', '<span id="ovMessagingValue">…</span>', '<span id="ovMessagingDetail">Loading…</span>') +
|
|
937
|
+
card('messaging', 'Messaging Apps', '<span id="ovMessagingValue">…</span>', '<span id="ovMessagingDetail">Loading…</span>') +
|
|
918
938
|
card('schedules', 'Schedules', '<span id="ovSchedulesValue">…</span>', '<span id="ovSchedulesDetail">Loading…</span>') +
|
|
919
939
|
card('env', 'Environment', 'Settings', '<span data-le-env-count="' + escapeHtml(cfg.name) + '">' + leShell.envCountHtml(cfg.name) + '</span> Values your installed abilities read') +
|
|
920
940
|
'</div>';
|
|
@@ -931,8 +951,28 @@ ${renderMarkdownScript}
|
|
|
931
951
|
|
|
932
952
|
// A workflow's schedules, each with its state and Pause/Resume and
|
|
933
953
|
// Remove, as lines of its contract's trigger row.
|
|
954
|
+
// A schedule added in a draft, as it was asked for, in words.
|
|
955
|
+
function draftScheduleText(d) {
|
|
956
|
+
var s = d.schedule || {};
|
|
957
|
+
if (s.run_at) return 'Once at ' + new Date(s.run_at).toLocaleString();
|
|
958
|
+
var every = String(s.every || '');
|
|
959
|
+
var when = s.at ? ' at ' + s.at + (s.weekday ? ' on ' + s.weekday : '') : s.start_at ? ', from ' + new Date(s.start_at).toLocaleString() : '';
|
|
960
|
+
return 'Every ' + every + when;
|
|
961
|
+
}
|
|
934
962
|
function workflowScheduleItemsHtml(w, agentName) {
|
|
935
|
-
|
|
963
|
+
var drafted = (w.draft && w.draft.schedules) || { add: [], remove: [] };
|
|
964
|
+
var adds = (drafted.add || []).map(function (d) {
|
|
965
|
+
var values = d.params ? Object.keys(d.params).map(function (k) { return escapeHtml(k) + ': ' + escapeHtml(d.params[k]); }).join(' ' + String.fromCharCode(183) + ' ') : '';
|
|
966
|
+
return '<div class="wf-trigger-item"><span>' + escapeHtml((d.task_name ? d.task_name + ': ' : '') + draftScheduleText(d)) + '</span>' +
|
|
967
|
+
'<span class="le-pill warn">Draft: starts when published</span>' + (values ? '<span class="hint">' + values + '</span>' : '') +
|
|
968
|
+
'<span style="display:flex;gap:6px;margin-left:auto"><button type="button" class="delete-btn workflow-schedule-draft" data-id="' + escapeHtml(d.id) + '" data-action="remove">Remove</button></span></div>';
|
|
969
|
+
}).join('');
|
|
970
|
+
return adds + (w.schedules || []).map(function (x) {
|
|
971
|
+
if ((drafted.remove || []).indexOf(x.taskId) !== -1) {
|
|
972
|
+
return '<div class="wf-trigger-item"><span><s>' + escapeHtml(x.describe.charAt(0).toUpperCase() + x.describe.slice(1)) + '</s></span>' +
|
|
973
|
+
'<span class="le-pill warn">Removed in the draft</span>' +
|
|
974
|
+
'<span style="display:flex;gap:6px;margin-left:auto"><button type="button" class="workflow-schedule-draft" data-id="' + escapeHtml(x.taskId) + '" data-action="restore">Undo</button></span></div>';
|
|
975
|
+
}
|
|
936
976
|
var state = x.waiting ? '<span class="le-pill ask">Waiting for a decision</span>'
|
|
937
977
|
: x.status === 'paused' ? '<span class="le-pill warn">Paused</span>'
|
|
938
978
|
: x.status === 'running' ? '<span class="le-pill accent">Running</span>'
|
|
@@ -945,7 +985,7 @@ ${renderMarkdownScript}
|
|
|
945
985
|
'<span style="display:flex;gap:6px;margin-left:auto">' +
|
|
946
986
|
(x.status === 'paused' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="resume">Resume</button>'
|
|
947
987
|
: x.status === 'scheduled' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="pause">Pause</button>' : '') +
|
|
948
|
-
'<button type="button" class="delete-btn workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="cancel">Remove</button>' +
|
|
988
|
+
'<button type="button" class="delete-btn workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="cancel">Remove in draft</button>' +
|
|
949
989
|
'</span></div>';
|
|
950
990
|
}).join('');
|
|
951
991
|
}
|
|
@@ -970,7 +1010,7 @@ ${renderMarkdownScript}
|
|
|
970
1010
|
return '<div class="wf-api">' +
|
|
971
1011
|
'<pre>POST ' + escapeHtml(apiUrl) + String.fromCharCode(10) + escapeHtml(example) + '</pre>' +
|
|
972
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. ') +
|
|
973
|
-
'Optional: <code>"wait": true</code> answers with the result once the run finishes; without it you get the run' + String.fromCharCode(8217) + 's id back at once. Each run follows this workflow' + String.fromCharCode(8217) + 's <strong>
|
|
1013
|
+
'Optional: <code>"wait": true</code> answers with the result once the run finishes; without it you get the run' + String.fromCharCode(8217) + 's id back at once. Each run follows this workflow' + String.fromCharCode(8217) + 's <strong>Messaging</strong> tab for where its updates, approvals and result go. An app can send its own <code>"callback_url"</code> (and <code>"decisions": "callback"</code>) to get this run' + String.fromCharCode(8217) + 's updates itself.</p>' +
|
|
974
1014
|
'</div>';
|
|
975
1015
|
}
|
|
976
1016
|
|
|
@@ -1085,7 +1125,7 @@ ${renderMarkdownScript}
|
|
|
1085
1125
|
}
|
|
1086
1126
|
|
|
1087
1127
|
// The Health panel: the last 30 days of runs, as totals, day by day and
|
|
1088
|
-
// per
|
|
1128
|
+
// per workflow version, and any alert (a rate that just got worse).
|
|
1089
1129
|
function loadWorkflowHealth(card, base) {
|
|
1090
1130
|
var box = card.querySelector('.wf-health');
|
|
1091
1131
|
if (!box) return;
|
|
@@ -1180,20 +1220,22 @@ ${renderMarkdownScript}
|
|
|
1180
1220
|
// lines added (+) and removed (−), a few shown and the rest folded.
|
|
1181
1221
|
function changeDetailsHtml(d) {
|
|
1182
1222
|
var list = d.changes || [];
|
|
1183
|
-
|
|
1223
|
+
var version = d.version || d.brief;
|
|
1224
|
+
if (!list.length && !version) return '';
|
|
1184
1225
|
var MINUS = String.fromCharCode(8722);
|
|
1185
1226
|
var lineHtml = function (sign, cls, l) { return '<div class="' + cls + '">' + sign + ' ' + escapeHtml(l) + '</div>'; };
|
|
1186
1227
|
var rows = list.map(function (c) {
|
|
1187
1228
|
if (c.added || c.removed) {
|
|
1188
1229
|
var lines = (c.removed || []).map(function (l) { return lineHtml(MINUS, 'chg-del', l); }).concat((c.added || []).map(function (l) { return lineHtml('+', 'chg-ins', l); }));
|
|
1189
|
-
var head = '<strong>' + escapeHtml(c.field) + '</strong>'
|
|
1230
|
+
var head = '<strong>' + escapeHtml(c.field) + '</strong>';
|
|
1190
1231
|
var shown = lines.slice(0, 6).join('');
|
|
1191
1232
|
var more = lines.length > 6 ? '<details><summary>' + (lines.length - 6) + ' more line' + (lines.length - 6 === 1 ? '' : 's') + '</summary>' + lines.slice(6).join('') + '</details>' : '';
|
|
1192
1233
|
return '<div class="chg-field">' + head + '<div class="chg-lines">' + (shown || '<div class="chg-note">Only spacing changed.</div>') + more + '</div></div>';
|
|
1193
1234
|
}
|
|
1194
1235
|
return '<div class="chg-field"><strong>' + escapeHtml(c.field) + '</strong>: <del>' + escapeHtml(c.from) + '</del> ' + String.fromCharCode(8594) + ' <ins>' + escapeHtml(c.to) + '</ins></div>';
|
|
1195
1236
|
}).join('');
|
|
1196
|
-
|
|
1237
|
+
// The workflow's version before and after ("brief" on older changes).
|
|
1238
|
+
if (version) rows = '<div class="chg-note">Workflow v' + version.from + ' ' + String.fromCharCode(8594) + ' v' + version.to + '</div>' + rows;
|
|
1197
1239
|
return '<div class="chg">' + rows + '</div>';
|
|
1198
1240
|
}
|
|
1199
1241
|
|
|
@@ -1240,7 +1282,7 @@ ${renderMarkdownScript}
|
|
|
1240
1282
|
return ['slack', 'telegram', 'lark'].indexOf(workflowsMeta.messaging) !== -1 ? workflowChatName() : null;
|
|
1241
1283
|
}
|
|
1242
1284
|
|
|
1243
|
-
// Its
|
|
1285
|
+
// Its Messaging tab: where every run's messages go, however it starts,
|
|
1244
1286
|
// as a grid of what happens in a run (rows) by where it can go
|
|
1245
1287
|
// (columns): the agent's messaging app, the Inbox and your app's
|
|
1246
1288
|
// address. What can't be turned off is shown ticked and locked: the
|
|
@@ -1248,7 +1290,7 @@ ${renderMarkdownScript}
|
|
|
1248
1290
|
// without an address, and with one gets every decision, finish and
|
|
1249
1291
|
// failure (adapters/http.ts, reportWorkflowRun).
|
|
1250
1292
|
function workflowMessagesHtml(w, agentName) {
|
|
1251
|
-
var d = w.delivery || {};
|
|
1293
|
+
var d = draftedDelivery(w) || w.delivery || {};
|
|
1252
1294
|
var RSQ = String.fromCharCode(8217);
|
|
1253
1295
|
var chatName = workflowChatName();
|
|
1254
1296
|
var chat = workflowChatAppName();
|
|
@@ -1267,10 +1309,11 @@ ${renderMarkdownScript}
|
|
|
1267
1309
|
// Webhooks saved with settings of their own: their runs use those.
|
|
1268
1310
|
var own = (w.triggers || []).filter(function (t) { return t.callback || t.decisions_to || t.chat_notice || t.result_to_chat; });
|
|
1269
1311
|
return '<form class="wf-msg-form">' +
|
|
1312
|
+
(draftedDelivery(w) ? draftNoteHtml('Where messages go is changed in the draft: runs follow the published setting until then.') : '') +
|
|
1270
1313
|
'<p class="hint" style="margin:0">Where this workflow' + RSQ + 's messages go, for every run: started by Run now, a schedule, a webhook or the API. A ticked, greyed box can' + RSQ + 't be turned off. Your app gets nothing until you give it an address.</p>' +
|
|
1271
1314
|
'<div class="wf-msg-dests">' +
|
|
1272
1315
|
'<div class="wf-msg-dest"><div class="wf-msg-dest-k">' + chatCol + '</div><div class="hint">' +
|
|
1273
|
-
(chatName ? 'The agent' + RSQ + 's messaging app, set in its <a href="?agent=' + encodeURIComponent(agentName) + '&tab=messaging">Messaging</a> tab.'
|
|
1316
|
+
(chatName ? 'The agent' + RSQ + 's messaging app, set in its <a href="?agent=' + encodeURIComponent(agentName) + '&tab=messaging">Messaging Apps</a> tab.'
|
|
1274
1317
|
: 'Not set up. <a href="?agent=' + encodeURIComponent(agentName) + '&tab=messaging">Set one up in Messaging</a> (Slack, Telegram or Lark) to post to chat.') + '</div></div>' +
|
|
1275
1318
|
'<div class="wf-msg-dest"><div class="wf-msg-dest-k">Inbox</div><div class="hint">Always. Every run is kept as a case, and approvals and questions can be answered there.</div></div>' +
|
|
1276
1319
|
'<div class="wf-msg-dest"><div class="wf-msg-dest-k">Your app</div><div class="hint">Optional. Only when you set an address: it then gets each update as signed JSON (a webhook).</div>' +
|
|
@@ -1298,7 +1341,7 @@ ${renderMarkdownScript}
|
|
|
1298
1341
|
'<button type="button" class="wf-msg-clear-hook" data-trigger="' + escapeHtml(t.trigger_id) + '">Use these instead</button></p>';
|
|
1299
1342
|
}).join('') + '</div>'
|
|
1300
1343
|
: '') +
|
|
1301
|
-
'<div class="wf-msg-foot"><span class="hint wf-msg-result" role="status"></span><button type="submit" class="primary">Save</button></div>' +
|
|
1344
|
+
'<div class="wf-msg-foot"><span class="hint wf-msg-result" role="status"></span><button type="submit" class="primary">Save to draft</button></div>' +
|
|
1302
1345
|
'</form>';
|
|
1303
1346
|
}
|
|
1304
1347
|
|
|
@@ -1312,7 +1355,7 @@ ${renderMarkdownScript}
|
|
|
1312
1355
|
};
|
|
1313
1356
|
return '<div class="wf-ways">' +
|
|
1314
1357
|
way('run', 'Run now', 'Starts a run right away, from here. It shows under Evidence as it goes.', workflowRunBarHtml(w, params)) +
|
|
1315
|
-
way('schedule', 'Schedule', 'Runs it on a timer, like every day at 9:00. Approvals and questions go where its
|
|
1358
|
+
way('schedule', 'Schedule', 'Runs it on a timer, like every day at 9:00. Approvals and questions go where its Messaging tab says.',
|
|
1316
1359
|
(schedules || '<p class="hint" style="margin:0">None yet.</p>') +
|
|
1317
1360
|
'<div><button type="button" class="workflow-add-schedule">+ Schedule</button></div>') +
|
|
1318
1361
|
way('webhook', 'Webhook', 'Another app (Stripe, GitHub, Shopify or your own) calls a private address when something happens, and each call starts a run.',
|
|
@@ -1340,7 +1383,8 @@ ${renderMarkdownScript}
|
|
|
1340
1383
|
var names = Object.keys(w.parameters || {});
|
|
1341
1384
|
var inputs = names.length ? names.map(function (n) {
|
|
1342
1385
|
var spec = w.parameters[n];
|
|
1343
|
-
|
|
1386
|
+
var typed = inputTypeText(spec);
|
|
1387
|
+
return '<code>' + escapeHtml(n) + '</code>' + (spec.required ? ' (required)' : '') + (typed ? ' ' + escapeHtml(typed) : '') + (spec.description ? ' <span class="hint">' + escapeHtml(spec.description) + '</span>' : '');
|
|
1344
1388
|
}) : ['<span class="hint">none: every run is the same</span>'];
|
|
1345
1389
|
var groups = { allow: [], ask: [], deny: [] };
|
|
1346
1390
|
(w.tools || []).forEach(function (t) { (groups[t.decision] || groups.ask).push(t.name); });
|
|
@@ -1352,21 +1396,26 @@ ${renderMarkdownScript}
|
|
|
1352
1396
|
if (!tools.length) tools.push('<span class="hint">none named in its instructions</span>');
|
|
1353
1397
|
var result = [];
|
|
1354
1398
|
if (w.output) result.push(escapeHtml(w.output));
|
|
1399
|
+
if (w.outputSchema) {
|
|
1400
|
+
var props = w.outputSchema.type === 'object' && w.outputSchema.properties ? Object.keys(w.outputSchema.properties) : [];
|
|
1401
|
+
result.push('<span>JSON matching its output schema' + (props.length ? ': ' + props.map(function (n) { return '<code>' + escapeHtml(n) + '</code>'; }).join(', ') : '') + '</span>' +
|
|
1402
|
+
'<details class="wf-schema"><summary>Show the schema</summary><pre>' + escapeHtml(JSON.stringify(w.outputSchema, null, 2)) + '</pre></details>');
|
|
1403
|
+
}
|
|
1355
1404
|
result.push('returned to whoever starts it <span class="hint">(Run now, or the app' + RSQ + 's API call)</span>');
|
|
1356
1405
|
var notified = (w.delivery && w.delivery.result_to_chat) || (w.schedules || []).some(function (x) { return x.notify && x.status !== 'cancelled'; }) || (w.triggers || []).some(function (t) { return t.result_to_chat; });
|
|
1357
1406
|
if (notified) result.push(escapeHtml(workflowsMeta.messaging ? (APP_NAMES[workflowsMeta.messaging] || workflowsMeta.messaging) : 'messaging app') + ' report' + (w.delivery && w.delivery.result_to_chat ? '' : ' <span class="hint">(for the schedules and webhooks set to send it)</span>'));
|
|
1358
1407
|
if ((w.triggers || []).some(function (t) { return t.callback; })) result.push('posted to the webhook' + RSQ + 's update address');
|
|
1359
1408
|
if (w.delivery && w.delivery.callback_url) result.push('run updates posted to ' + escapeHtml(w.delivery.callback_url));
|
|
1360
|
-
var decisions = [(w.delivery && w.delivery.decisions_to === 'callback' ? 'your app' : escapeHtml(workflowChatName() || 'the agent' + RSQ + 's messaging app')) + ' <span class="hint">(see
|
|
1409
|
+
var decisions = [(w.delivery && w.delivery.decisions_to === 'callback' ? 'your app' : escapeHtml(workflowChatName() || 'the agent' + RSQ + 's messaging app')) + ' <span class="hint">(see Messaging)</span>'];
|
|
1361
1410
|
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>';
|
|
1362
1411
|
var row = function (k, lines) { return '<div class="wf-cb-k">' + k + '</div><div class="wf-cb-v">' + contractLinesHtml(lines) + '</div>'; };
|
|
1363
1412
|
return '<div class="wf-cb">' + row('trigger', trigger) + row('inputs', inputs) + row('tools', tools) + row('result', result) + row('approvals', decisions) + row('model', [model]) + '</div>' +
|
|
1364
|
-
'<p class="hint" style="margin:0">Change the inputs, result and model with Edit, where updates and approvals go in
|
|
1413
|
+
'<p class="hint" style="margin:0">Change the inputs, result and model with Edit, where updates and approvals go in Messaging, and what tools may do in Permissions.</p>';
|
|
1365
1414
|
}
|
|
1366
1415
|
|
|
1367
1416
|
function workflowBriefHtml(w) {
|
|
1368
1417
|
var policies = workflowsMeta.policies;
|
|
1369
|
-
// Filled by
|
|
1418
|
+
// Filled by loadWorkflowVersions once the card is on the page.
|
|
1370
1419
|
return '<div class="wf-versions" hidden></div>' +
|
|
1371
1420
|
'<div class="workflow-steps-text">' + escapeHtml(w.instructions) + '</div>' +
|
|
1372
1421
|
(policies
|
|
@@ -1415,8 +1464,21 @@ ${renderMarkdownScript}
|
|
|
1415
1464
|
|
|
1416
1465
|
// The Evaluation tab: the success criteria, the eval cases (saved, then
|
|
1417
1466
|
// suggested from real runs), and Evaluate.
|
|
1467
|
+
// A workflow's draft over its live settings, for the tabs that draft:
|
|
1468
|
+
// its success criteria and where messages go (see workflowDraftBannerHtml).
|
|
1469
|
+
function draftedCriteria(w) {
|
|
1470
|
+
return w.draft && w.draft.criteria ? w.draft.criteria : null;
|
|
1471
|
+
}
|
|
1472
|
+
function draftedDelivery(w) {
|
|
1473
|
+
return w.draft && w.draft.messages ? (w.draft.messages.delivery || {}) : null;
|
|
1474
|
+
}
|
|
1475
|
+
function draftNoteHtml(what) {
|
|
1476
|
+
return '<p class="wf-draft-note"><span class="le-pill warn">Draft</span> ' + what + ' Publish the draft to make ' + (what.indexOf('These') === 0 ? 'them' : 'it') + ' live.</p>';
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1418
1479
|
function workflowEvaluationHtml(w) {
|
|
1419
|
-
var
|
|
1480
|
+
var live = w.evals || { cases: [], criteria: [], rounds: [] };
|
|
1481
|
+
var evals = draftedCriteria(w) ? Object.assign({}, live, { criteria: draftedCriteria(w) }) : live;
|
|
1420
1482
|
var criteria = evals.criteria && evals.criteria.length ? evals.criteria : [REFERENCE_CRIT];
|
|
1421
1483
|
var round = evals.rounds[0];
|
|
1422
1484
|
var checked = round && round.passRates;
|
|
@@ -1429,6 +1491,7 @@ ${renderMarkdownScript}
|
|
|
1429
1491
|
return '<li class="wf-crit"><span><strong>' + escapeHtml(c.text) + '</strong><br><span class="wf-crit-kind">' + escapeHtml(critKindText(c)) + '</span></span>' + pill + '</li>';
|
|
1430
1492
|
}).join('');
|
|
1431
1493
|
var critSection = '<h4 class="wf-sub">Success criteria</h4>' +
|
|
1494
|
+
(draftedCriteria(w) ? draftNoteHtml('These success criteria are in the draft: evaluations use the published ones until then.') : '') +
|
|
1432
1495
|
'<p class="hint" style="margin:0">' + (evals.criteria && evals.criteria.length
|
|
1433
1496
|
? 'What every good result must get right. Each eval case is checked against every criterion, yes or no.'
|
|
1434
1497
|
: 'What every good result must get right. None set yet, so each eval case is only compared with its good result. Add the criteria that matter, or have them suggested from its instructions.') + '</p>' +
|
|
@@ -1437,7 +1500,7 @@ ${renderMarkdownScript}
|
|
|
1437
1500
|
'<div class="wf-crit-form" hidden>' +
|
|
1438
1501
|
'<div class="wf-crit-rows">' + (evals.criteria && evals.criteria.length ? evals.criteria : []).map(critRowHtml).join('') + '</div>' +
|
|
1439
1502
|
'<div class="wf-crit-bar"><button type="button" class="plain wf-crit-add">+ Add a criterion</button><button type="button" class="plain wf-crit-draft">Suggest from its instructions</button>' +
|
|
1440
|
-
'<span style="flex:1"></span><button type="button" class="plain wf-crit-cancel">Cancel</button><button type="button" class="wf-crit-save">Save
|
|
1503
|
+
'<span style="flex:1"></span><button type="button" class="plain wf-crit-cancel">Cancel</button><button type="button" class="wf-crit-save">Save to draft</button></div>' +
|
|
1441
1504
|
'<span class="hint wf-crit-status"></span>' +
|
|
1442
1505
|
'</div>';
|
|
1443
1506
|
var latest = {};
|
|
@@ -1472,7 +1535,7 @@ ${renderMarkdownScript}
|
|
|
1472
1535
|
'</details></li>';
|
|
1473
1536
|
}).join('');
|
|
1474
1537
|
var lastLine = !round ? ''
|
|
1475
|
-
: '<p class="wf-eval-last"><strong>Last evaluation: ' + escapeHtml(new Date(round.at).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })) + (round.briefVersion ? ',
|
|
1538
|
+
: '<p class="wf-eval-last"><strong>Last evaluation: ' + escapeHtml(new Date(round.at).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })) + ((round.workflowVersion || round.briefVersion) ? ', workflow v' + (round.workflowVersion || round.briefVersion) : '') + '</strong>' +
|
|
1476
1539
|
(checked ? String.fromCharCode(8212) + ' ' + round.allPassed + ' of ' + round.cases.length + ' cases met every success criterion.' : '') +
|
|
1477
1540
|
' <details class="wf-eval-details"><summary>Details</summary>Ran with ' + escapeHtml(round.model) + DOT + 'judged by ' + escapeHtml(round.judge) + DOT + escapeHtml(new Date(round.at).toLocaleString()) + '</details></p>';
|
|
1478
1541
|
return '<section class="wf-section">' + critSection + '</section>' +
|
|
@@ -1540,7 +1603,7 @@ ${renderMarkdownScript}
|
|
|
1540
1603
|
// One line to start, growing as an email or a thread is pasted in
|
|
1541
1604
|
// (wireWorkflowCard sizes it).
|
|
1542
1605
|
return '<label class="workflow-param">' + escapeHtml(p) + (spec.required ? '' : ' <span class="hint">(optional)</span>') +
|
|
1543
|
-
|
|
1606
|
+
inputControlHtml(p, spec, spec.required) + '</label>';
|
|
1544
1607
|
}).join('');
|
|
1545
1608
|
// Recent runs, one line each, opening the case (where everything
|
|
1546
1609
|
// about it is).
|
|
@@ -1555,7 +1618,7 @@ ${renderMarkdownScript}
|
|
|
1555
1618
|
return '<li class="wf-run-line">' + pill +
|
|
1556
1619
|
'<a class="wf-run-link" href="' + caseHref(r.run_id) + '"><span class="wf-run-when">' + escapeHtml(new Date(r.started_at).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })) + '</span>' +
|
|
1557
1620
|
'<span class="wf-run-text">' + escapeHtml(line.length > 160 ? line.slice(0, 160) + String.fromCharCode(8230) : line) + '</span></a>' +
|
|
1558
|
-
(r.versions && r.versions.brief ? '<span class="hint">
|
|
1621
|
+
(r.versions && (r.versions.workflow || r.versions.brief) ? '<span class="hint">v' + (r.versions.workflow || r.versions.brief) + '</span>' : '') +
|
|
1559
1622
|
runEvidenceHtml(w, r) + '</li>';
|
|
1560
1623
|
}).join('');
|
|
1561
1624
|
var last = workflowLastRun(w);
|
|
@@ -1580,8 +1643,9 @@ ${renderMarkdownScript}
|
|
|
1580
1643
|
(w.jobs && w.jobs.length ? '<span class="wf-page-meta-item"><span class="wf-page-meta-k">For goal</span><span>' + w.jobs.map(function (j) { return '<a href="/goals?goal=' + encodeURIComponent(j.id) + '">' + escapeHtml(j.title) + '</a>'; }).join(', ') + '</span></span>' : '') +
|
|
1581
1644
|
'</div>' +
|
|
1582
1645
|
'</header>' +
|
|
1646
|
+
workflowDraftBannerHtml(w) +
|
|
1583
1647
|
'<div class="wf-row-body wf-page-body">' +
|
|
1584
|
-
'<div class="wf-tabs" role="tablist">' + tabBtn('brief', 'Brief') + tabBtn('activity', 'Activity') + tabBtn('evaluation', 'Evaluation') + tabBtn('triggers', 'Triggers') + tabBtn('messages', '
|
|
1648
|
+
'<div class="wf-tabs" role="tablist">' + tabBtn('brief', 'Brief') + tabBtn('activity', 'Activity') + tabBtn('evaluation', 'Evaluation') + tabBtn('triggers', 'Triggers') + tabBtn('messages', 'Messaging') + tabBtn('contract', 'Contract') + '</div>' +
|
|
1585
1649
|
panel('brief', workflowBriefHtml(w)) +
|
|
1586
1650
|
panel('activity', workflowActivityHtml(w, runs, name)) +
|
|
1587
1651
|
panel('evaluation', workflowEvaluationHtml(w)) +
|
|
@@ -1606,7 +1670,7 @@ ${renderMarkdownScript}
|
|
|
1606
1670
|
'<div class="wf-row-body"' + (open ? '' : ' hidden') + '>' +
|
|
1607
1671
|
// What it does, in full, once it's open (the row shows just its name).
|
|
1608
1672
|
(w.description && w.description !== w.title ? '<p class="wf-desc">' + escapeHtml(w.description) + '</p>' : '') +
|
|
1609
|
-
'<div class="wf-tabs" role="tablist">' + tabBtn('brief', 'Brief') + tabBtn('activity', 'Activity') + tabBtn('evaluation', 'Evaluation') + tabBtn('contract', 'Contract') + tabBtn('triggers', 'Triggers') + tabBtn('messages', '
|
|
1673
|
+
'<div class="wf-tabs" role="tablist">' + tabBtn('brief', 'Brief') + tabBtn('activity', 'Activity') + tabBtn('evaluation', 'Evaluation') + tabBtn('contract', 'Contract') + tabBtn('triggers', 'Triggers') + tabBtn('messages', 'Messaging') + '</div>' +
|
|
1610
1674
|
panel('contract', workflowContractHtml(w, name, params)) +
|
|
1611
1675
|
panel('triggers', workflowTriggersHtml(w, name, params)) +
|
|
1612
1676
|
panel('messages', workflowMessagesHtml(w, name)) +
|
|
@@ -1684,7 +1748,7 @@ ${renderMarkdownScript}
|
|
|
1684
1748
|
// or a webhook secret or a run's values being typed.
|
|
1685
1749
|
function workflowInputInUse() {
|
|
1686
1750
|
if (document.querySelector('dialog[open]')) return true;
|
|
1687
|
-
var inputs = detail.querySelectorAll('.workflow-hooks input, .workflow-params textarea');
|
|
1751
|
+
var inputs = detail.querySelectorAll('.workflow-hooks input, .workflow-params textarea, .workflow-params input');
|
|
1688
1752
|
for (var i = 0; i < inputs.length; i++) if (inputs[i].value || inputs[i] === document.activeElement) return true;
|
|
1689
1753
|
return false;
|
|
1690
1754
|
}
|
|
@@ -1716,14 +1780,81 @@ ${renderMarkdownScript}
|
|
|
1716
1780
|
});
|
|
1717
1781
|
}
|
|
1718
1782
|
|
|
1783
|
+
// ---- An input's type (core/input-schema.ts), as the editor offers it:
|
|
1784
|
+
// a type, or text with a format. "" is plain text.
|
|
1785
|
+
var INPUT_KINDS = [['', 'Text'], ['string:email', 'Email'], ['string:date', 'Date'], ['string:uri', 'Link'], ['number', 'Number'], ['integer', 'Whole number'], ['boolean', 'Yes or no'], ['array', 'List (JSON)'], ['object', 'Object (JSON)']];
|
|
1786
|
+
function inputKindOf(spec) {
|
|
1787
|
+
if (!spec || !spec.type || spec.type === 'string') return spec && spec.format ? 'string:' + spec.format : '';
|
|
1788
|
+
return spec.type;
|
|
1789
|
+
}
|
|
1790
|
+
// An input's type and limits in words, for the contract.
|
|
1791
|
+
function inputTypeText(spec) {
|
|
1792
|
+
var kind = inputKindOf(spec);
|
|
1793
|
+
var label = INPUT_KINDS.filter(function (k) { return k[0] === kind; })[0];
|
|
1794
|
+
var parts = [];
|
|
1795
|
+
if (kind) parts.push(label ? label[1].toLowerCase() : kind);
|
|
1796
|
+
if (spec.enum) parts.push('one of ' + spec.enum.join(', '));
|
|
1797
|
+
if (spec.minimum != null) parts.push('at least ' + spec.minimum);
|
|
1798
|
+
if (spec.maximum != null) parts.push('at most ' + spec.maximum);
|
|
1799
|
+
if (spec.pattern) parts.push('matching ' + spec.pattern);
|
|
1800
|
+
if (spec.default !== undefined) parts.push('default ' + (typeof spec.default === 'string' ? spec.default : JSON.stringify(spec.default)));
|
|
1801
|
+
return parts.join(', ');
|
|
1802
|
+
}
|
|
1803
|
+
// The field a run's value is typed into: a choice for allowed values or
|
|
1804
|
+
// yes/no, a number or a date picker, else a box that grows.
|
|
1805
|
+
function inputControlHtml(fieldName, spec, required) {
|
|
1806
|
+
var req = required ? ' required' : '';
|
|
1807
|
+
var ph = escapeHtml(spec.description || '');
|
|
1808
|
+
var dflt = spec.default !== undefined ? (typeof spec.default === 'string' ? spec.default : JSON.stringify(spec.default)) : '';
|
|
1809
|
+
var opt = function (v, label, sel) { return '<option value="' + escapeHtml(v) + '"' + (sel ? ' selected' : '') + '>' + escapeHtml(label) + '</option>'; };
|
|
1810
|
+
if (spec.enum && spec.enum.length) {
|
|
1811
|
+
return '<select name="' + escapeHtml(fieldName) + '"' + req + '>' + opt('', required ? 'Choose' + String.fromCharCode(8230) : '(none)', !dflt) +
|
|
1812
|
+
spec.enum.map(function (v) { return opt(String(v), String(v), String(v) === dflt); }).join('') + '</select>';
|
|
1813
|
+
}
|
|
1814
|
+
if (spec.type === 'boolean') return '<select name="' + escapeHtml(fieldName) + '"' + req + '>' + opt('', required ? 'Choose' + String.fromCharCode(8230) : '(none)', !dflt) + opt('true', 'Yes', dflt === 'true') + opt('false', 'No', dflt === 'false') + '</select>';
|
|
1815
|
+
if (spec.type === 'number' || spec.type === 'integer') return '<input type="number" name="' + escapeHtml(fieldName) + '"' + req + (spec.type === 'integer' ? ' step="1"' : ' step="any"') + (spec.minimum != null ? ' min="' + spec.minimum + '"' : '') + (spec.maximum != null ? ' max="' + spec.maximum + '"' : '') + ' placeholder="' + ph + '" value="' + escapeHtml(dflt) + '">';
|
|
1816
|
+
if (spec.format === 'date') return '<input type="date" name="' + escapeHtml(fieldName) + '"' + req + ' value="' + escapeHtml(dflt) + '">';
|
|
1817
|
+
return '<textarea rows="1" name="' + escapeHtml(fieldName) + '"' + req + ' placeholder="' + ph + '">' + escapeHtml(dflt) + '</textarea>';
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1719
1820
|
// ---- The workflow editor: its title, its instructions (the skill body)
|
|
1720
1821
|
// and the values a run is given. What starts it is on the card.
|
|
1721
1822
|
function workflowParamRowHtml(pname, spec) {
|
|
1722
|
-
|
|
1823
|
+
var kind = inputKindOf(spec);
|
|
1824
|
+
var dflt = spec && spec.default !== undefined ? (typeof spec.default === 'string' ? spec.default : JSON.stringify(spec.default)) : '';
|
|
1825
|
+
// Limits the editor has no field for (a pattern, a minimum…), kept as
|
|
1826
|
+
// they are when the row is saved.
|
|
1827
|
+
var kept = {};
|
|
1828
|
+
['pattern', 'minimum', 'maximum', 'minLength', 'maxLength'].forEach(function (k) { if (spec && spec[k] !== undefined) kept[k] = spec[k]; });
|
|
1829
|
+
return '<div class="workflow-param-row" data-kept="' + escapeHtml(JSON.stringify(kept)) + '">' +
|
|
1723
1830
|
'<input class="wp-name" aria-label="Parameter name" placeholder="order_number" value="' + escapeHtml(pname || '') + '">' +
|
|
1724
1831
|
'<input class="wp-desc" aria-label="What it is" placeholder="What it is, e.g. The order to check" value="' + escapeHtml((spec && spec.description) || '') + '">' +
|
|
1832
|
+
'<select class="wp-type" aria-label="Type">' + INPUT_KINDS.map(function (k) { return '<option value="' + k[0] + '"' + (k[0] === kind ? ' selected' : '') + '>' + k[1] + '</option>'; }).join('') + '</select>' +
|
|
1725
1833
|
'<label class="http-tool-inline-label"><input type="checkbox" class="wp-required"' + (spec && spec.required ? ' checked' : '') + '> Required</label>' +
|
|
1726
|
-
'<button type="button" class="delete-btn wp-remove">Remove</button
|
|
1834
|
+
'<button type="button" class="delete-btn wp-remove">Remove</button>' +
|
|
1835
|
+
'<div class="wp-limits"><input class="wp-enum" aria-label="Allowed values" placeholder="Allowed values, comma-separated (optional)" value="' + escapeHtml(spec && spec.enum ? spec.enum.join(', ') : '') + '">' +
|
|
1836
|
+
'<input class="wp-default" aria-label="Default" placeholder="Default (optional)" value="' + escapeHtml(dflt) + '"></div></div>';
|
|
1837
|
+
}
|
|
1838
|
+
// A row's input, as saved: its description, whether it's required, and
|
|
1839
|
+
// its type, allowed values and default. The server checks them.
|
|
1840
|
+
function paramFromRow(row) {
|
|
1841
|
+
var kind = row.querySelector('.wp-type').value;
|
|
1842
|
+
var p = { description: row.querySelector('.wp-desc').value.trim(), required: row.querySelector('.wp-required').checked };
|
|
1843
|
+
if (kind.indexOf('string:') === 0) p.format = kind.slice(7);
|
|
1844
|
+
else if (kind) p.type = kind;
|
|
1845
|
+
var numeric = p.type === 'number' || p.type === 'integer';
|
|
1846
|
+
var allowed = row.querySelector('.wp-enum').value.split(',').map(function (v) { return v.trim(); }).filter(Boolean);
|
|
1847
|
+
if (allowed.length) p.enum = numeric ? allowed.map(Number) : allowed;
|
|
1848
|
+
var d = row.querySelector('.wp-default').value.trim();
|
|
1849
|
+
if (d) p['default'] = d;
|
|
1850
|
+
// The limits it had, where they still fit its type.
|
|
1851
|
+
var kept = {};
|
|
1852
|
+
try { kept = JSON.parse(row.getAttribute('data-kept') || '{}'); } catch (e) {}
|
|
1853
|
+
Object.keys(kept).forEach(function (k) {
|
|
1854
|
+
var forNumbers = k === 'minimum' || k === 'maximum';
|
|
1855
|
+
if (forNumbers ? numeric : !p.type) p[k] = kept[k];
|
|
1856
|
+
});
|
|
1857
|
+
return p;
|
|
1727
1858
|
}
|
|
1728
1859
|
|
|
1729
1860
|
${WORKFLOW_SECTIONS_SCRIPT}
|
|
@@ -1749,13 +1880,15 @@ ${renderMarkdownScript}
|
|
|
1749
1880
|
'<button type="button" class="wp-add" style="align-self:flex-start">Add parameter</button></div>' +
|
|
1750
1881
|
'<label>Result <span class="hint">(optional: what its final reply must be, e.g. The draft only, then a line Flag: reason if a person must act. Empty: a reply in its own words.)</span>' +
|
|
1751
1882
|
'<textarea name="output" rows="2" maxlength="2000">' + escapeHtml(w.output || '') + '</textarea></label>' +
|
|
1883
|
+
'<label>Output schema <span class="hint">(optional: a JSON Schema its result must match, for apps and the next workflow in a chain. Each run' + String.fromCharCode(8217) + 's result is checked; one that doesn' + String.fromCharCode(8217) + 't match is sent back to the agent to fix, twice at most, then the run fails.)</span>' +
|
|
1884
|
+
'<textarea name="outputSchema" class="wp-schema" rows="6" spellcheck="false" placeholder="' + escapeHtml('{ "type": "object", "properties": { "summary": { "type": "string" }, "priority": { "enum": ["low", "high"] } }, "required": ["summary", "priority"] }') + '">' + escapeHtml(w.outputSchema ? JSON.stringify(w.outputSchema, null, 2) : '') + '</textarea></label>' +
|
|
1752
1885
|
'<div class="body-field">Model <span class="hint">(optional: a model for this workflow only; empty uses the agent' + String.fromCharCode(8217) + 's' + (workflowsMeta.agentModel ? ', ' + escapeHtml(workflowsMeta.agentModel) : '') + ')</span>' +
|
|
1753
1886
|
'<div class="wp-model-row"><select name="modelProvider" aria-label="Provider"><option value="">The agent' + String.fromCharCode(8217) + 's model</option>' +
|
|
1754
1887
|
['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('') +
|
|
1755
1888
|
'</select><input name="modelName" aria-label="Model name" placeholder="e.g. gpt-6.1-sol" value="' + escapeHtml((w.model && w.model.model) || '') + '"></div></div>' +
|
|
1756
1889
|
'<p class="hint workflow-editor-check" style="margin:0"></p>' +
|
|
1757
1890
|
'<div class="hint workflow-editor-result"></div>' +
|
|
1758
|
-
'<div class="ed-actions"><button type="button" class="wp-cancel">Cancel</button><button type="submit" class="primary">Save</button></div></form>';
|
|
1891
|
+
'<div class="ed-actions"><span class="hint">Runs keep using the published workflow until you publish.</span><button type="button" class="wp-cancel">Cancel</button><button type="submit" class="primary">Save draft</button></div></form>';
|
|
1759
1892
|
}
|
|
1760
1893
|
|
|
1761
1894
|
// Placeholders the instructions use that no parameter declares, and
|
|
@@ -1777,15 +1910,122 @@ ${renderMarkdownScript}
|
|
|
1777
1910
|
form.querySelector('.workflow-editor-check').textContent = notes.join(' ');
|
|
1778
1911
|
}
|
|
1779
1912
|
|
|
1913
|
+
// A workflow with its draft's edits over it, for the editor.
|
|
1914
|
+
function withDraftFields(w) {
|
|
1915
|
+
if (!w.draft) return w;
|
|
1916
|
+
var f = w.draft.fields || {};
|
|
1917
|
+
var out = {};
|
|
1918
|
+
Object.keys(w).forEach(function (k) { out[k] = w[k]; });
|
|
1919
|
+
['title', 'description', 'instructions', 'parameters', 'output', 'outputSchema', 'model'].forEach(function (k) {
|
|
1920
|
+
if (f[k] !== undefined) out[k] = f[k] === null ? undefined : f[k];
|
|
1921
|
+
});
|
|
1922
|
+
return out;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
// A draft not yet published: who saved it and when, and what to do.
|
|
1926
|
+
function workflowDraftBannerHtml(w) {
|
|
1927
|
+
if (!w.draft) return '';
|
|
1928
|
+
var d = w.draft;
|
|
1929
|
+
var at = new Date(d.savedAt).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
1930
|
+
return '<div class="wf-draft" role="status"><span class="le-pill warn">Draft</span>' +
|
|
1931
|
+
'<span>Not published' + (d.savedBy ? ': saved by ' + escapeHtml(d.savedBy) : ': saved') + ', ' + escapeHtml(at) + '. Runs use the published workflow until you publish it.</span>' +
|
|
1932
|
+
'<span class="wf-draft-actions"><button type="button" class="primary wf-draft-publish">Review and publish</button><button type="button" class="wf-draft-edit">Edit draft</button><button type="button" class="delete-btn wf-draft-discard">Discard</button></span></div>';
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
// Its draft's banner: review and publish, edit it, or discard it.
|
|
1936
|
+
function wireDraftBanner(name, card) {
|
|
1937
|
+
var id = card.dataset.workflow;
|
|
1938
|
+
var base = '/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(id);
|
|
1939
|
+
var pub = card.querySelector('.wf-draft-publish');
|
|
1940
|
+
if (pub) pub.addEventListener('click', function () { openPublishDialog(name, workflowsById[id]); });
|
|
1941
|
+
var editDraft = card.querySelector('.wf-draft-edit');
|
|
1942
|
+
if (editDraft) editDraft.addEventListener('click', function () { openWorkflowEditor(name, card); });
|
|
1943
|
+
var discard = card.querySelector('.wf-draft-discard');
|
|
1944
|
+
if (discard) discard.addEventListener('click', function () {
|
|
1945
|
+
if (discard.getAttribute('data-confirming') !== '1') { discard.setAttribute('data-confirming', '1'); discard.textContent = 'Click again to discard'; return; }
|
|
1946
|
+
discard.disabled = true;
|
|
1947
|
+
fetchJsonRetryOnce(base + '/draft', { method: 'DELETE' }).then(function () { loadWorkflowsSection(name); });
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
// After a change made in place (a webhook's URL is on screen, so the
|
|
1951
|
+
// card isn't redrawn): the draft as it is now, and its banner.
|
|
1952
|
+
function refreshDraft(name, card) {
|
|
1953
|
+
var id = card.dataset.workflow;
|
|
1954
|
+
fetchJsonRetryOnce('/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(id) + '/draft').then(function (r) {
|
|
1955
|
+
if (!r.ok || !workflowsById[id]) return;
|
|
1956
|
+
if (r.body.draft) workflowsById[id].draft = r.body.draft;
|
|
1957
|
+
else delete workflowsById[id].draft;
|
|
1958
|
+
var old = card.querySelector('.wf-draft');
|
|
1959
|
+
var html = workflowDraftBannerHtml(workflowsById[id]);
|
|
1960
|
+
if (old) old.outerHTML = html || '';
|
|
1961
|
+
else if (html) {
|
|
1962
|
+
var body = card.querySelector('.wf-row-body');
|
|
1963
|
+
if (body) body.insertAdjacentHTML('beforebegin', html);
|
|
1964
|
+
}
|
|
1965
|
+
wireDraftBanner(name, card);
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// Review and publish: what the draft changes in the published workflow,
|
|
1970
|
+
// the version it will be, a note kept with it, then Publish.
|
|
1971
|
+
function openPublishDialog(name, w) {
|
|
1972
|
+
var base = '/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(w.id);
|
|
1973
|
+
var holder = document.createElement('div');
|
|
1974
|
+
holder.innerHTML = editDialogHtml('<h3>Publish changes</h3>', '<p>' + escapeHtml(w.title) + String.fromCharCode(8217) + 's draft, against the published workflow.</p>', '<div class="wf-publish"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div>');
|
|
1975
|
+
var dialog = holder.firstChild;
|
|
1976
|
+
dialog.classList.add('workflow-publish-dialog');
|
|
1977
|
+
document.body.appendChild(dialog);
|
|
1978
|
+
var body = dialog.querySelector('.wf-publish');
|
|
1979
|
+
var close = function () { if (dialog.open) dialog.close(); };
|
|
1980
|
+
dialog.addEventListener('close', function () { dialog.remove(); });
|
|
1981
|
+
dialog.addEventListener('click', function (ev) { if (ev.target === dialog) close(); });
|
|
1982
|
+
dialog.querySelector('.hd-close').addEventListener('click', close);
|
|
1983
|
+
dialog.showModal();
|
|
1984
|
+
fetchJsonRetryOnce(base + '/draft', { headers: { accept: 'application/json' } }).then(function (r) {
|
|
1985
|
+
if (!r.ok) { body.innerHTML = '<p class="error">' + escapeHtml(r.body.error || 'Could not load the draft') + '</p>'; return; }
|
|
1986
|
+
var v = r.body;
|
|
1987
|
+
if (!v.draft) { body.innerHTML = '<p class="hint">There' + String.fromCharCode(8217) + 's no draft: it was published or discarded.</p>'; return; }
|
|
1988
|
+
if (!v.changes.length) {
|
|
1989
|
+
body.innerHTML = '<p>The draft is the same as the published workflow: there' + String.fromCharCode(8217) + 's nothing to publish.</p><div class="ed-actions"><button type="button" class="delete-btn wf-pub-discard">Discard the draft</button></div>';
|
|
1990
|
+
body.querySelector('.wf-pub-discard').addEventListener('click', function () {
|
|
1991
|
+
fetchJsonRetryOnce(base + '/draft', { method: 'DELETE' }).then(function () { close(); loadWorkflowsSection(name); });
|
|
1992
|
+
});
|
|
1993
|
+
return;
|
|
1994
|
+
}
|
|
1995
|
+
body.innerHTML =
|
|
1996
|
+
'<p class="wf-pub-version">' + (v.current ? 'Publishing makes this <strong>version ' + v.next + '</strong>, replacing version ' + v.current + ' for every run from now on.' : 'Publishing makes this the version every run uses from now on.') + '</p>' +
|
|
1997
|
+
(v.stale ? '<p class="wf-pub-stale">The published workflow changed since this draft began (it was version ' + v.draft.basedOn + '). Publishing replaces those changes with the draft' + String.fromCharCode(8217) + 's: check below.</p>' : '') +
|
|
1998
|
+
'<h4>What' + String.fromCharCode(8217) + 's changed</h4>' + changeDetailsHtml({ changes: v.changes }) +
|
|
1999
|
+
'<label>Note <span class="hint">(optional: what changed and why, kept with the version)</span><textarea class="wf-pub-note" rows="2" maxlength="500" placeholder="e.g. Ask for the order number before looking it up"></textarea></label>' +
|
|
2000
|
+
'<div class="ed-actions"><span class="hint wf-pub-result" role="status"></span><button type="button" class="wf-pub-cancel">Cancel</button><button type="button" class="primary wf-pub-go">Publish version ' + (v.next || '') + '</button></div>';
|
|
2001
|
+
body.querySelector('.wf-pub-cancel').addEventListener('click', close);
|
|
2002
|
+
var go = body.querySelector('.wf-pub-go');
|
|
2003
|
+
go.addEventListener('click', function () {
|
|
2004
|
+
go.disabled = true;
|
|
2005
|
+
var result = body.querySelector('.wf-pub-result');
|
|
2006
|
+
result.textContent = 'Publishing' + String.fromCharCode(8230);
|
|
2007
|
+
fetchJsonRetryOnce(base + '/publish', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ note: body.querySelector('.wf-pub-note').value }) }).then(function (p) {
|
|
2008
|
+
if (!p.ok) { go.disabled = false; result.textContent = p.body.error || 'Could not publish'; return; }
|
|
2009
|
+
body.innerHTML = '<p class="wf-pub-done"><span class="le-pill good">Published</span> Version ' + p.body.version + ' is live: every run from now on uses it.</p>' +
|
|
2010
|
+
'<div class="ed-actions"><button type="button" class="primary wf-pub-close">Done</button></div>';
|
|
2011
|
+
body.querySelector('.wf-pub-close').addEventListener('click', close);
|
|
2012
|
+
loadWorkflowsSection(name);
|
|
2013
|
+
});
|
|
2014
|
+
});
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
|
|
1780
2018
|
function openWorkflowEditor(name, card) {
|
|
1781
|
-
var
|
|
1782
|
-
if (!
|
|
2019
|
+
var published = workflowsById[card.dataset.workflow];
|
|
2020
|
+
if (!published) return;
|
|
2021
|
+
// With a draft, the editor picks up where it was left.
|
|
2022
|
+
var w = withDraftFields(published);
|
|
1783
2023
|
workflowEditing = true;
|
|
1784
2024
|
// In a dialog: the editor's code holds its own form, so it needn't sit
|
|
1785
2025
|
// in the card. Closing it any way (Esc, the backdrop, x, Cancel)
|
|
1786
2026
|
// discards the edits.
|
|
1787
2027
|
var dialog = document.createElement('dialog');
|
|
1788
|
-
dialog.innerHTML = editDialogHtml('<h3>Edit workflow</h3>', '<p>Its title, what it' + String.fromCharCode(8217) + 's for, what the agent follows (what to do, its rules, policies, special cases and examples) and the values each run is given.</p>', workflowEditorHtml(w));
|
|
2028
|
+
dialog.innerHTML = editDialogHtml('<h3>' + (published.draft ? 'Edit draft' : 'Edit workflow') + '</h3>', '<p>Its title, what it' + String.fromCharCode(8217) + 's for, what the agent follows (what to do, its rules, policies, special cases and examples) and the values each run is given.</p>', workflowEditorHtml(w));
|
|
1789
2029
|
dialog = dialog.firstChild;
|
|
1790
2030
|
dialog.classList.add('workflow-editor-dialog');
|
|
1791
2031
|
document.body.appendChild(dialog);
|
|
@@ -1822,7 +2062,7 @@ ${renderMarkdownScript}
|
|
|
1822
2062
|
out.textContent = 'Loading' + String.fromCharCode(8230);
|
|
1823
2063
|
fetchJsonRetryOnce('/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(w.id) + '/preview', {
|
|
1824
2064
|
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
1825
|
-
body: JSON.stringify({ title: form.title.value, instructions: form.instructions.value, parameters: parameters, output: form.output.value }),
|
|
2065
|
+
body: JSON.stringify({ title: form.title.value, instructions: form.instructions.value, parameters: parameters, output: form.output.value, outputSchema: form.outputSchema.value }),
|
|
1826
2066
|
}).then(function (r) {
|
|
1827
2067
|
out.textContent = r.ok ? r.body.message : (r.body.error || 'Could not preview');
|
|
1828
2068
|
});
|
|
@@ -1841,13 +2081,16 @@ ${renderMarkdownScript}
|
|
|
1841
2081
|
if (!pname) continue;
|
|
1842
2082
|
if (!/^[a-z_][a-z0-9_]*$/.test(pname)) { problem = 'Parameter "' + pname + '": use lowercase letters, digits and _, starting with a letter, e.g. order_number.'; break; }
|
|
1843
2083
|
if (parameters[pname]) { problem = 'Parameter "' + pname + '" is listed twice.'; break; }
|
|
1844
|
-
parameters[pname] =
|
|
2084
|
+
parameters[pname] = paramFromRow(list[i]);
|
|
2085
|
+
}
|
|
2086
|
+
if (!problem && form.outputSchema.value.trim()) {
|
|
2087
|
+
try { JSON.parse(form.outputSchema.value); } catch (e) { problem = 'The output schema isn' + String.fromCharCode(8217) + 't valid JSON: ' + e.message; }
|
|
1845
2088
|
}
|
|
1846
2089
|
if (problem) { result.textContent = problem; return; }
|
|
1847
|
-
result.textContent = 'Saving' + String.fromCharCode(8230);
|
|
1848
|
-
fetchJsonRetryOnce('/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(w.id), {
|
|
2090
|
+
result.textContent = 'Saving the draft' + String.fromCharCode(8230);
|
|
2091
|
+
fetchJsonRetryOnce('/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(w.id) + '/draft', {
|
|
1849
2092
|
method: 'PUT', headers: { 'content-type': 'application/json' },
|
|
1850
|
-
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 }),
|
|
2093
|
+
body: JSON.stringify({ title: form.title.value, description: form.description.value, instructions: form.instructions.value, parameters: parameters, output: form.output.value, outputSchema: form.outputSchema.value, model: form.modelProvider.value && form.modelName.value.trim() ? { provider: form.modelProvider.value, model: form.modelName.value.trim() } : null }),
|
|
1851
2094
|
}).then(function (r) {
|
|
1852
2095
|
if (!r.ok) { result.textContent = r.body.error || 'Could not save'; return; }
|
|
1853
2096
|
close();
|
|
@@ -1875,7 +2118,24 @@ ${renderMarkdownScript}
|
|
|
1875
2118
|
}
|
|
1876
2119
|
}
|
|
1877
2120
|
|
|
2121
|
+
// Where a webhook stands in its workflow's draft, if anywhere.
|
|
2122
|
+
function hookDraftState(t) {
|
|
2123
|
+
var w = workflowsById[t.workflow_id];
|
|
2124
|
+
var hooks = w && w.draft && w.draft.webhooks;
|
|
2125
|
+
if (t.draft) return 'added';
|
|
2126
|
+
if (!hooks) return '';
|
|
2127
|
+
if ((hooks.remove || []).indexOf(t.trigger_id) !== -1) return 'removed';
|
|
2128
|
+
if (hooks.update && hooks.update[t.trigger_id]) return 'changed';
|
|
2129
|
+
return '';
|
|
2130
|
+
}
|
|
1878
2131
|
function hookRowHtml(t, shownUrl) {
|
|
2132
|
+
var state = hookDraftState(t);
|
|
2133
|
+
if (state === 'removed') {
|
|
2134
|
+
return '<div class="workflow-hook" data-trigger="' + escapeHtml(t.trigger_id) + '"><div style="display:flex;gap:8px;flex-wrap:wrap;align-items:baseline"><s><strong>' + escapeHtml(t.name) + '</strong></s>' +
|
|
2135
|
+
'<span class="le-pill warn">Removed in the draft</span><button type="button" class="hook-undo">Undo</button>' +
|
|
2136
|
+
'<span hidden><button class="hook-edit"></button><button class="hook-rotate"></button><button class="hook-delete"></button></span></div></div>';
|
|
2137
|
+
}
|
|
2138
|
+
var draftPill = state === 'added' ? ' <span class="le-pill warn">Not live until published</span>' : state === 'changed' ? ' <span class="le-pill warn">Changed in the draft</span>' : '';
|
|
1879
2139
|
var rules = [];
|
|
1880
2140
|
if (t.verify) rules.push(t.verify.sender === 'custom'
|
|
1881
2141
|
? 'checks the signature in ' + escapeHtml(t.verify.header || '(header not set yet)') + ' (' + escapeHtml(t.verify.algorithm || 'sha256') + ', ' + escapeHtml(t.verify.encoding || 'hex') + ')'
|
|
@@ -1892,7 +2152,7 @@ ${renderMarkdownScript}
|
|
|
1892
2152
|
var setup = needsSecret ? hookSetupSteps(t) : null;
|
|
1893
2153
|
return '<div class="workflow-hook" data-trigger="' + escapeHtml(t.trigger_id) + '">' +
|
|
1894
2154
|
'<div style="display:flex;justify-content:space-between;gap:8px;flex-wrap:wrap;align-items:baseline"><strong>' + escapeHtml(t.name) + '</strong>' +
|
|
1895
|
-
'<code class="hint">/hooks/workflows/' + escapeHtml(t.token_hint) + '</code>' + (needsSecret ? ' <span class="le-pill warn">Needs its signing secret</span>' : t.enabled ? '' : ' <span class="le-pill">Off</span>') + '</div>' +
|
|
2155
|
+
'<code class="hint">/hooks/workflows/' + escapeHtml(t.token_hint) + '</code>' + (needsSecret ? ' <span class="le-pill warn">Needs its signing secret</span>' : t.enabled ? '' : ' <span class="le-pill">Off</span>') + draftPill + '</div>' +
|
|
1896
2156
|
(rules.length ? '<p class="hint" style="margin:2px 0">' + rules.join(' ' + String.fromCharCode(183) + ' ') + '</p>' : '') +
|
|
1897
2157
|
(needsSecret
|
|
1898
2158
|
// Set up and waiting: the steps that turn it on, in order.
|
|
@@ -1961,7 +2221,7 @@ ${renderMarkdownScript}
|
|
|
1961
2221
|
field('Or give the whole payload to', '<select name="payload_param"><option value="">(none)</option>' + params.map(function (p) { return '<option>' + escapeHtml(p) + '</option>'; }).join('') + '</select>', '')
|
|
1962
2222
|
: '<p class="hd-hint">This workflow takes no inputs, so what the app sends isn' + RSQ + 't passed on. Add one with Edit to use it.</p>') +
|
|
1963
2223
|
'</section>' +
|
|
1964
|
-
'<p class="hd-hint">Where its runs' + RSQ + ' updates, approvals and questions go is set once for the workflow, in its
|
|
2224
|
+
'<p class="hd-hint">Where its runs' + RSQ + ' updates, approvals and questions go is set once for the workflow, in its Messaging tab.</p>' +
|
|
1965
2225
|
'</div>' +
|
|
1966
2226
|
'<footer class="hd-foot"><span class="hook-form-result" role="status"></span>' +
|
|
1967
2227
|
'<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>' +
|
|
@@ -2043,7 +2303,7 @@ ${renderMarkdownScript}
|
|
|
2043
2303
|
if (Object.keys(mapping).length) body.mapping = mapping;
|
|
2044
2304
|
if (form.payload_param && form.payload_param.value) body.payload_param = form.payload_param.value;
|
|
2045
2305
|
// A change says what's cleared too; a setting left out is kept (its
|
|
2046
|
-
// own message settings, from before: the
|
|
2306
|
+
// own message settings, from before: the Messaging tab clears them).
|
|
2047
2307
|
if (existing) {
|
|
2048
2308
|
['verify', 'filter', 'mapping'].forEach(function (k) { if (!(k in body)) body[k] = null; });
|
|
2049
2309
|
if (!('payload_param' in body)) body.payload_param = '';
|
|
@@ -2083,6 +2343,7 @@ ${renderMarkdownScript}
|
|
|
2083
2343
|
var addBox = card.querySelector('.workflow-hooks-add');
|
|
2084
2344
|
if (!w || !box) return;
|
|
2085
2345
|
var base = '/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(w.id) + '/triggers';
|
|
2346
|
+
var draftBase = '/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(w.id) + '/draft/webhooks';
|
|
2086
2347
|
var hooksById = {};
|
|
2087
2348
|
function render(shownUrl, shownId) {
|
|
2088
2349
|
if (!box.innerHTML) box.innerHTML = '<p class="hint" style="margin:0">Loading' + String.fromCharCode(8230) + '</p>';
|
|
@@ -2092,9 +2353,11 @@ ${renderMarkdownScript}
|
|
|
2092
2353
|
hooksById = {};
|
|
2093
2354
|
list.forEach(function (t) { hooksById[t.trigger_id] = t; });
|
|
2094
2355
|
// Keep the card's summary in step with what was just changed.
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
w.
|
|
2356
|
+
// A webhook made in the draft doesn't start runs yet.
|
|
2357
|
+
var live = list.filter(function (t) { return !t.draft; });
|
|
2358
|
+
w.webhooks = live.filter(function (t) { return t.enabled; }).length;
|
|
2359
|
+
w.webhooksWaiting = live.filter(function (t) { return !t.enabled && t.verify && !t.verify.secret_set; }).length;
|
|
2360
|
+
w.webhooksOff = live.length - w.webhooks - w.webhooksWaiting;
|
|
2098
2361
|
var startsCell = card.querySelector('.wf-row-starts');
|
|
2099
2362
|
if (startsCell) startsCell.innerHTML = workflowStartsSummary(w);
|
|
2100
2363
|
// One waiting for its secret, or just made: open the Run options
|
|
@@ -2123,8 +2386,14 @@ ${renderMarkdownScript}
|
|
|
2123
2386
|
for (var i = 0; i < rows.length; i++) {
|
|
2124
2387
|
(function (row) {
|
|
2125
2388
|
var id = row.dataset.trigger;
|
|
2389
|
+
// Editing and deleting go in the draft; on/off, the signing secret
|
|
2390
|
+
// and a new URL act now.
|
|
2126
2391
|
row.querySelector('.hook-edit').addEventListener('click', function () {
|
|
2127
|
-
if (hooksById[id]) openHookFormDialog(w,
|
|
2392
|
+
if (hooksById[id]) openHookFormDialog(w, draftBase, function () { render(null, null); refreshDraft(name, card); }, hooksById[id]);
|
|
2393
|
+
});
|
|
2394
|
+
var undo = row.querySelector('.hook-undo');
|
|
2395
|
+
if (undo) undo.addEventListener('click', function () {
|
|
2396
|
+
fetchJsonRetryOnce(draftBase + '/' + encodeURIComponent(id) + '/restore', { method: 'POST' }).then(function () { render(null, null); refreshDraft(name, card); });
|
|
2128
2397
|
});
|
|
2129
2398
|
var toggle = row.querySelector('.hook-toggle');
|
|
2130
2399
|
if (toggle) toggle.addEventListener('click', function (ev) {
|
|
@@ -2153,7 +2422,11 @@ ${renderMarkdownScript}
|
|
|
2153
2422
|
row.querySelector('.hook-delete').addEventListener('click', function (ev) {
|
|
2154
2423
|
var btn = ev.currentTarget;
|
|
2155
2424
|
if (btn.dataset.confirming !== '1') { btn.dataset.confirming = '1'; btn.textContent = 'Click again to delete'; return; }
|
|
2156
|
-
|
|
2425
|
+
fetchJsonRetryOnce(draftBase + '/' + encodeURIComponent(id), { method: 'DELETE' }).then(function (r) {
|
|
2426
|
+
if (!r.ok) { alert(r.body.error || 'That didn' + String.fromCharCode(8217) + 't work'); return; }
|
|
2427
|
+
render(null, null);
|
|
2428
|
+
refreshDraft(name, card);
|
|
2429
|
+
});
|
|
2157
2430
|
});
|
|
2158
2431
|
})(rows[i]);
|
|
2159
2432
|
}
|
|
@@ -2161,15 +2434,16 @@ ${renderMarkdownScript}
|
|
|
2161
2434
|
render(shown ? shown.url : null, shown ? shown.id : null);
|
|
2162
2435
|
}
|
|
2163
2436
|
|
|
2164
|
-
// The
|
|
2165
|
-
//
|
|
2166
|
-
//
|
|
2167
|
-
|
|
2437
|
+
// The workflow's versions (its name, inputs, model, instructions and
|
|
2438
|
+
// result format), on the Brief tab: which one is in use, who saved it
|
|
2439
|
+
// and why, and every earlier one to read or restore (restoring saves it
|
|
2440
|
+
// as a new version). Hidden where the workspace keeps no versions.
|
|
2441
|
+
function loadWorkflowVersions(card, base) {
|
|
2168
2442
|
var box = card.querySelector('.wf-versions');
|
|
2169
2443
|
if (!box) return;
|
|
2170
2444
|
fetch(base + '/versions', { headers: { accept: 'application/json' } })
|
|
2171
2445
|
.then(function (r) { return r.ok ? r.json() : null; })
|
|
2172
|
-
.then(function (data) { if (data)
|
|
2446
|
+
.then(function (data) { if (data) renderWorkflowVersions(box, base, data); })
|
|
2173
2447
|
.catch(function () {});
|
|
2174
2448
|
}
|
|
2175
2449
|
|
|
@@ -2177,12 +2451,12 @@ ${renderMarkdownScript}
|
|
|
2177
2451
|
return new Date(v.at).toLocaleString(undefined, { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
2178
2452
|
}
|
|
2179
2453
|
|
|
2180
|
-
function
|
|
2454
|
+
function renderWorkflowVersions(box, base, data) {
|
|
2181
2455
|
var versions = data.versions || [];
|
|
2182
2456
|
if (!versions.length) { box.hidden = true; return; }
|
|
2183
2457
|
var current = versions.filter(function (v) { return v.number === data.current; })[0] || versions[0];
|
|
2184
2458
|
var about = function (v) { return [v.by ? 'by ' + escapeHtml(v.by) : '', escapeHtml(versionWhen(v)), v.reason ? escapeHtml(v.reason) : ''].filter(Boolean).join(DOT); };
|
|
2185
|
-
box.innerHTML = '<div class="wf-versions-line"><strong>
|
|
2459
|
+
box.innerHTML = '<div class="wf-versions-line"><strong>Workflow version ' + current.number + '</strong><span class="hint">' + about(current) + '</span>' +
|
|
2186
2460
|
(versions.length > 1 ? '<button type="button" class="wf-link wf-versions-toggle">History (' + versions.length + ')</button>' : '') + '</div>' +
|
|
2187
2461
|
'<ol class="wf-versions-list" hidden>' + versions.map(function (v) {
|
|
2188
2462
|
var isCurrent = v.number === current.number;
|
|
@@ -2240,7 +2514,8 @@ ${renderMarkdownScript}
|
|
|
2240
2514
|
}
|
|
2241
2515
|
var tabs = card.querySelectorAll('.wf-tab');
|
|
2242
2516
|
for (var t = 0; t < tabs.length; t++) tabs[t].addEventListener('click', function (ev) { showWorkflowTab(card, ev.currentTarget.dataset.tab); });
|
|
2243
|
-
|
|
2517
|
+
loadWorkflowVersions(card, base);
|
|
2518
|
+
wireDraftBanner(name, card);
|
|
2244
2519
|
loadWorkflowHealth(card, base);
|
|
2245
2520
|
loadCandidates(card, base);
|
|
2246
2521
|
loadAuditSummary(card, base);
|
|
@@ -2295,7 +2570,7 @@ ${renderMarkdownScript}
|
|
|
2295
2570
|
if (msgForm.msgNoticeOn && msgForm.msgNoticeOn.checked && msgForm.msgNotice.value.trim()) body.chat_notice = msgForm.msgNotice.value.trim();
|
|
2296
2571
|
if (msgForm.msgResult && msgForm.msgResult.checked) body.result_to_chat = true;
|
|
2297
2572
|
msgResult.textContent = 'Saving' + String.fromCharCode(8230);
|
|
2298
|
-
fetchJsonRetryOnce(base + '/messages', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }).then(function (r) {
|
|
2573
|
+
fetchJsonRetryOnce(base + '/draft/messages', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }).then(function (r) {
|
|
2299
2574
|
if (!r.ok) { msgResult.textContent = r.body.error || 'Could not save'; return; }
|
|
2300
2575
|
reloadOnMessages();
|
|
2301
2576
|
});
|
|
@@ -2304,7 +2579,7 @@ ${renderMarkdownScript}
|
|
|
2304
2579
|
for (var cb = 0; cb < clearButtons.length; cb++) {
|
|
2305
2580
|
clearButtons[cb].addEventListener('click', function (ev) {
|
|
2306
2581
|
var tid = ev.currentTarget.dataset.trigger;
|
|
2307
|
-
fetchJsonRetryOnce(base + '/
|
|
2582
|
+
fetchJsonRetryOnce(base + '/draft/webhooks/' + encodeURIComponent(tid), {
|
|
2308
2583
|
method: 'PUT', headers: { 'content-type': 'application/json' },
|
|
2309
2584
|
body: JSON.stringify({ callback_url: null, decisions: null, chat_notice: null, result_to_chat: false }),
|
|
2310
2585
|
}).then(function (r) {
|
|
@@ -2353,7 +2628,8 @@ ${renderMarkdownScript}
|
|
|
2353
2628
|
var list = Array.prototype.map.call(rows.querySelectorAll('.wf-crit-row'), function (row) {
|
|
2354
2629
|
return { id: row.dataset.critId || undefined, kind: row.querySelector('[data-crit-kind]').value, text: row.querySelector('[data-crit-text]').value, value: row.querySelector('[data-crit-value]').value };
|
|
2355
2630
|
}).filter(function (c) { return c.text.trim() || c.value.trim(); });
|
|
2356
|
-
|
|
2631
|
+
// Saved to the draft: published with the rest of it.
|
|
2632
|
+
fetchJsonRetryOnce(base + '/draft/criteria', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ criteria: list }) }).then(function (r) {
|
|
2357
2633
|
cbtn.disabled = false;
|
|
2358
2634
|
if (!r.ok) { critStatus.textContent = r.body.error || 'That didn' + String.fromCharCode(8217) + 't save.'; return; }
|
|
2359
2635
|
workflowTabs[id] = 'evaluation';
|
|
@@ -2396,8 +2672,10 @@ ${renderMarkdownScript}
|
|
|
2396
2672
|
card.querySelector('.workflow-hooks-btn').addEventListener('click', function () {
|
|
2397
2673
|
var w = workflowsById[id];
|
|
2398
2674
|
if (!w) return;
|
|
2399
|
-
|
|
2675
|
+
// Made in the draft: its URL now, live once the draft is published.
|
|
2676
|
+
openHookFormDialog(w, base + '/draft/webhooks', function (url, triggerId) {
|
|
2400
2677
|
loadWorkflowHooks(name, card, { url: url, id: triggerId });
|
|
2678
|
+
refreshDraft(name, card);
|
|
2401
2679
|
});
|
|
2402
2680
|
});
|
|
2403
2681
|
var wf = workflowsById[id];
|
|
@@ -2407,6 +2685,17 @@ ${renderMarkdownScript}
|
|
|
2407
2685
|
pendingScheduleWorkflow = id;
|
|
2408
2686
|
switchTab('schedules');
|
|
2409
2687
|
});
|
|
2688
|
+
// Removing a schedule, or undoing that, is part of the draft; pausing
|
|
2689
|
+
// and resuming act now.
|
|
2690
|
+
var draftScheduleBtns = card.querySelectorAll('.workflow-schedule-draft');
|
|
2691
|
+
for (var dsb = 0; dsb < draftScheduleBtns.length; dsb++) {
|
|
2692
|
+
draftScheduleBtns[dsb].addEventListener('click', function (ev) {
|
|
2693
|
+
var btn = ev.currentTarget;
|
|
2694
|
+
btn.disabled = true;
|
|
2695
|
+
var path = base + '/draft/schedules/' + encodeURIComponent(btn.dataset.id);
|
|
2696
|
+
(btn.dataset.action === 'restore' ? fetchJsonRetryOnce(path + '/restore', { method: 'POST' }) : fetchJsonRetryOnce(path, { method: 'DELETE' })).then(function () { loadWorkflowsSection(name); });
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2410
2699
|
var scheduleBtns = card.querySelectorAll('.workflow-schedule-action');
|
|
2411
2700
|
for (var sb = 0; sb < scheduleBtns.length; sb++) {
|
|
2412
2701
|
scheduleBtns[sb].addEventListener('click', function (ev) {
|
|
@@ -2414,7 +2703,10 @@ ${renderMarkdownScript}
|
|
|
2414
2703
|
var action = btn.dataset.action;
|
|
2415
2704
|
if (action === 'cancel' && btn.dataset.confirming !== '1') { btn.dataset.confirming = '1'; btn.textContent = 'Click again to remove'; return; }
|
|
2416
2705
|
btn.disabled = true;
|
|
2417
|
-
|
|
2706
|
+
var request = action === 'cancel'
|
|
2707
|
+
? fetchJsonRetryOnce(base + '/draft/schedules/' + encodeURIComponent(btn.dataset.id), { method: 'DELETE' })
|
|
2708
|
+
: fetchJsonRetryOnce('/schedules/' + encodeURIComponent(btn.dataset.id) + '/' + action, { method: 'POST' });
|
|
2709
|
+
request.then(function () {
|
|
2418
2710
|
loadWorkflowsSection(name);
|
|
2419
2711
|
// The Schedules tab's count, and the Overview's tile.
|
|
2420
2712
|
fillOverviewCards(name);
|
|
@@ -2424,7 +2716,7 @@ ${renderMarkdownScript}
|
|
|
2424
2716
|
card.querySelector('.workflow-run').addEventListener('click', function (ev) {
|
|
2425
2717
|
var btn = ev.currentTarget;
|
|
2426
2718
|
var params = {};
|
|
2427
|
-
var inputs = card.querySelectorAll('.workflow-params textarea');
|
|
2719
|
+
var inputs = card.querySelectorAll('.workflow-params textarea, .workflow-params input, .workflow-params select');
|
|
2428
2720
|
for (var i = 0; i < inputs.length; i++) {
|
|
2429
2721
|
var value = inputs[i].value.trim();
|
|
2430
2722
|
if (!value && inputs[i].required) { result.textContent = 'Fill in ' + inputs[i].name + ' first.'; inputs[i].focus(); return; }
|
|
@@ -3781,17 +4073,17 @@ ${renderMarkdownScript}
|
|
|
3781
4073
|
: t.workflow_missing
|
|
3782
4074
|
? '<div><span class="le-pill bad">Workflow removed</span> <span class="hint">' + escapeHtml(t.workflow_id) + '</span></div>'
|
|
3783
4075
|
: '<div class="schedule-result hint">' + escapeHtml(t.message) + '</div>') +
|
|
3784
|
-
// A workflow's schedule follows its
|
|
4076
|
+
// A workflow's schedule follows its Messaging tab (an old tick here
|
|
3785
4077
|
// was moved there when the server started).
|
|
3786
4078
|
(t.status !== 'cancelled' && t.status !== 'done' && !t.workflow_id
|
|
3787
|
-
? '<label class="schedule-notify hint" title="Sent through its Messaging tab: Slack, email, Lark or a webhook"><input type="checkbox" class="schedule-notify-toggle" data-id="' + escapeHtml(t.task_id) + '"' + (t.notify ? ' checked' : '') + '> Send result to messaging app</label>'
|
|
4079
|
+
? '<label class="schedule-notify hint" title="Sent through its Messaging Apps tab: Slack, email, Lark or a webhook"><input type="checkbox" class="schedule-notify-toggle" data-id="' + escapeHtml(t.task_id) + '"' + (t.notify ? ' checked' : '') + '> Send result to messaging app</label>'
|
|
3788
4080
|
: (t.notify && !t.workflow_id ? '<div><span class="workflow-option-value">Send result to messaging app</span></div>' : '')) + '</td>' +
|
|
3789
4081
|
'<td>' + scheduleText(t.schedule) + (t.next_run_at ? '<div class="hint">next ' + escapeHtml(fmtScheduleTime(t.next_run_at)) + '</div>' : '') + '</td>' +
|
|
3790
4082
|
'<td><span class="le-pill ' + (SCHEDULE_PILLS[t.status] || 'neutral') + '">' + escapeHtml(SCHEDULE_LABELS[t.status] || t.status) + '</span>' +
|
|
3791
4083
|
(t.status === 'awaiting_approval' ? '<div class="hint"><a href="#" class="schedule-to-approvals">Decide in Messaging</a></div>' : '') + '</td>' +
|
|
3792
4084
|
'<td style="min-width:200px">' + last + (history ? '<details><summary class="hint">History (' + (t.history || []).length + ')</summary><ul class="schedule-history">' + history + '</ul></details>' : '') + '</td>' +
|
|
3793
4085
|
'<td><div style="display:flex;gap:6px;flex-wrap:wrap">' + actions.map(function (a) {
|
|
3794
|
-
return '<button type="button" class="schedule-action' + (a[0] === 'run' ? ' primary' : '') + (a[0] === 'cancel' || a[0] === 'delete' ? ' delete-btn' : '') + '" data-id="' + escapeHtml(t.task_id) + '" data-action="' + a[0] + '">' + a[1] + '</button>';
|
|
4086
|
+
return '<button type="button" class="schedule-action' + (a[0] === 'run' ? ' primary' : '') + (a[0] === 'cancel' || a[0] === 'delete' ? ' delete-btn' : '') + '" data-id="' + escapeHtml(t.task_id) + '" data-action="' + a[0] + '"' + (t.workflow_id ? ' data-workflow="' + escapeHtml(t.workflow_id) + '"' : '') + '>' + a[1] + '</button>';
|
|
3795
4087
|
}).join('') + '</div></td></tr>';
|
|
3796
4088
|
}
|
|
3797
4089
|
|
|
@@ -3800,7 +4092,7 @@ ${renderMarkdownScript}
|
|
|
3800
4092
|
var list = tasks.length
|
|
3801
4093
|
? '<div class="le-table-wrap"><table><thead><tr><th>Task</th><th>When</th><th>Status</th><th>Last run</th><th></th></tr></thead><tbody>' + tasks.map(renderScheduleRow).join('') + '</tbody></table></div>'
|
|
3802
4094
|
: '<p class="hint">Nothing scheduled yet.</p>';
|
|
3803
|
-
return '<p class="muted" style="margin:0 0 20px">Workflows and messages this agent runs on a timer, like a cron job. A workflow schedule runs the workflow's instructions as they are at each run. Each run works like an app calling it over HTTP: an approval goes wherever the Messaging tab sends it, and with nowhere set, a call that needs approval is denied. The agent can also schedule its own tasks when asked in Chat (“remind me tomorrow at 9”); they appear here too.</p>' +
|
|
4095
|
+
return '<p class="muted" style="margin:0 0 20px">Workflows and messages this agent runs on a timer, like a cron job. A workflow schedule runs the workflow's instructions as they are at each run. Each run works like an app calling it over HTTP: an approval goes wherever the Messaging Apps tab sends it, and with nowhere set, a call that needs approval is denied. The agent can also schedule its own tasks when asked in Chat (“remind me tomorrow at 9”); they appear here too.</p>' +
|
|
3804
4096
|
'<section><h3>Scheduled (' + active.length + ' active)</h3>' + list + '</section>' +
|
|
3805
4097
|
'<section><h3>New schedule</h3>' +
|
|
3806
4098
|
'<form class="add-source" id="scheduleForm" style="max-width:560px">' +
|
|
@@ -3827,7 +4119,7 @@ ${renderMarkdownScript}
|
|
|
3827
4119
|
'<input type="datetime-local" name="runAt" aria-label="Date and time"></div>' +
|
|
3828
4120
|
'</div>' +
|
|
3829
4121
|
'<label>Name <span class="hint">(optional)</span><input name="task_name" placeholder="Daily ticket summary"></label>' +
|
|
3830
|
-
'<label class="http-tool-inline-label" id="scheduleNotifyField"' + (schedulesWorkflows.length ? ' hidden' : '') + '><input type="checkbox" name="notify"> Send result to messaging app <span class="hint">(through its Messaging tab: Slack, email, Lark or a webhook)</span></label>' +
|
|
4122
|
+
'<label class="http-tool-inline-label" id="scheduleNotifyField"' + (schedulesWorkflows.length ? ' hidden' : '') + '><input type="checkbox" name="notify"> Send result to messaging app <span class="hint">(through its Messaging Apps tab: Slack, email, Lark or a webhook)</span></label>' +
|
|
3831
4123
|
'<div style="display:flex;gap:8px"><button type="submit">Schedule</button></div>' +
|
|
3832
4124
|
'<div id="scheduleResult" class="hint"></div>' +
|
|
3833
4125
|
'</form></section>';
|
|
@@ -3863,7 +4155,11 @@ ${renderMarkdownScript}
|
|
|
3863
4155
|
return;
|
|
3864
4156
|
}
|
|
3865
4157
|
btn.disabled = true;
|
|
3866
|
-
|
|
4158
|
+
// A workflow's schedule is removed in the workflow's draft.
|
|
4159
|
+
var wfId = btn.dataset.workflow;
|
|
4160
|
+
var request = wfId && (action === 'cancel' || action === 'delete')
|
|
4161
|
+
? fetchJsonRetryOnce('/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(wfId) + '/draft/schedules/' + encodeURIComponent(btn.dataset.id), { method: 'DELETE' })
|
|
4162
|
+
: action === 'delete'
|
|
3867
4163
|
? fetchJsonRetryOnce('/schedules/' + encodeURIComponent(btn.dataset.id), { method: 'DELETE' })
|
|
3868
4164
|
: fetchJsonRetryOnce('/schedules/' + encodeURIComponent(btn.dataset.id) + '/' + action, { method: 'POST' });
|
|
3869
4165
|
request.then(function () { setTimeout(function () { loadSchedulesTab(name); }, action === 'run' ? 800 : 0); });
|
|
@@ -3899,7 +4195,7 @@ ${renderMarkdownScript}
|
|
|
3899
4195
|
var parameters = (w && w.parameters) || {};
|
|
3900
4196
|
paramsBox.innerHTML = Object.keys(parameters).map(function (p) {
|
|
3901
4197
|
return '<label class="workflow-param">' + escapeHtml(p) + (parameters[p].required ? '' : ' <span class="hint">(optional)</span>') +
|
|
3902
|
-
'
|
|
4198
|
+
inputControlHtml('param:' + p, parameters[p], false) + '</label>';
|
|
3903
4199
|
}).join('');
|
|
3904
4200
|
}
|
|
3905
4201
|
// Opened from a workflow's "Add a schedule": that workflow, chosen.
|
|
@@ -3918,7 +4214,7 @@ ${renderMarkdownScript}
|
|
|
3918
4214
|
var byMessage = form.querySelector('input[name="runs"]:checked').value === 'message';
|
|
3919
4215
|
messageField.hidden = !byMessage;
|
|
3920
4216
|
if (paramsBox) paramsBox.hidden = byMessage;
|
|
3921
|
-
// A workflow's result goes where its
|
|
4217
|
+
// A workflow's result goes where its Messaging tab says.
|
|
3922
4218
|
var notifyField = form.querySelector('#scheduleNotifyField');
|
|
3923
4219
|
if (notifyField) notifyField.hidden = !byMessage;
|
|
3924
4220
|
});
|
|
@@ -3940,7 +4236,12 @@ ${renderMarkdownScript}
|
|
|
3940
4236
|
if (data.get('everyStart')) schedule.start_at = scheduleFormTime(data.get('everyStart'));
|
|
3941
4237
|
}
|
|
3942
4238
|
result.textContent = 'Scheduling' + String.fromCharCode(8230);
|
|
3943
|
-
|
|
4239
|
+
// A workflow's schedule goes in the workflow's draft: it starts when
|
|
4240
|
+
// the draft is published. A message schedule starts now.
|
|
4241
|
+
var target = runsWorkflow
|
|
4242
|
+
? '/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(data.get('workflow_id')) + '/draft/schedules'
|
|
4243
|
+
: '/agents/' + encodeURIComponent(name) + '/schedules';
|
|
4244
|
+
fetchJsonRetryOnce(target, {
|
|
3944
4245
|
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
3945
4246
|
body: JSON.stringify(Object.assign(
|
|
3946
4247
|
runsWorkflow ? { workflow_id: data.get('workflow_id'), params: scheduleParams(data) } : { message: data.get('message') },
|
|
@@ -3948,6 +4249,10 @@ ${renderMarkdownScript}
|
|
|
3948
4249
|
)),
|
|
3949
4250
|
}).then(function (r) {
|
|
3950
4251
|
if (!r.ok) { result.textContent = r.body.error || 'Could not schedule'; return; }
|
|
4252
|
+
if (runsWorkflow) {
|
|
4253
|
+
result.innerHTML = 'Added to the workflow' + String.fromCharCode(8217) + 's draft: it starts when the draft is published. <a href="' + workflowPageHref(name, data.get('workflow_id')) + '">Review and publish</a>';
|
|
4254
|
+
return;
|
|
4255
|
+
}
|
|
3951
4256
|
loadSchedulesTab(name);
|
|
3952
4257
|
});
|
|
3953
4258
|
});
|