loopengine 0.5.7 → 0.5.9

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.
@@ -19,16 +19,8 @@
19
19
  // leShell.applyProviderKeys(form, keys, keep) only providers with a key
20
20
  // leShell.abilityOriginBadge(origin) Official/Public/Private badge for an ability
21
21
  // leShell.toggleAbilityDetails(btn) an ability's tools, skills and settings
22
- // leShell.advanced() whether this person has Advanced view on
23
22
  // leShell.adminNote(tech) "Only your workspace admin can change this",
24
- // with the technical how-to in Advanced view
25
- //
26
- // Simple and Advanced view: the console is for operators first, so what
27
- // only a developer or the workspace's admin needs (version history,
28
- // evaluations, the contract, the API, environment, limits) is marked
29
- // data-advanced and hidden until a person turns on Advanced in the
30
- // sidebar (kept in this browser). data-simple marks what shows only
31
- // without it.
23
+ // with the technical how-to
32
24
  // Same embedded-string conventions as the pages themselves: plain
33
25
  // string concatenation and no backslashes inside the script, so nothing
34
26
  // here needs double-escaping in the template literal.
@@ -48,7 +40,6 @@ const GOALS_ICON = '<svg class="le-nav-icon" viewBox="0 0 24 24" fill="none" str
48
40
  const AUDIT_ICON = '<svg class="le-nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="5" y="4" width="14" height="17" rx="2"/><path d="M9 4V3h6v1"/><path d="m9 13 2 2 4-4"/></svg>';
49
41
  // A gear, for Settings.
50
42
  const SCHEDULES_ICON = '<svg class="le-nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>';
51
- const ADVANCED_ICON = '<svg class="le-nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="4" y1="21" x2="4" y2="14"/><line x1="4" y1="10" x2="4" y2="3"/><line x1="12" y1="21" x2="12" y2="12"/><line x1="12" y1="8" x2="12" y2="3"/><line x1="20" y1="21" x2="20" y2="16"/><line x1="20" y1="12" x2="20" y2="3"/><line x1="1" y1="14" x2="7" y2="14"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="17" y1="16" x2="23" y2="16"/></svg>';
52
43
  const SETTINGS_ICON = '<svg class="le-nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>';
53
44
  // Two columns: the sections (Inbox, Goals, Agents, Workflows, Audit,
54
45
  // Settings), and beside them what's in the current one. A goal holds the
@@ -64,9 +55,8 @@ export const consoleSidebarHtml = `<aside class="le-sidebar" aria-label="Console
64
55
  <a class="le-rail-item" href="/agents" data-le-nav-head="agents" data-le-section="agents">${AGENTS_ICON}<span>Agents</span></a>
65
56
  <a class="le-rail-item" href="/workflows" data-le-nav-head="workflows" data-le-section="workflows">${WORKFLOWS_ICON}<span>Workflows</span></a>
66
57
  <a class="le-rail-item" href="/schedules" data-le-nav-head="schedules" data-le-section="schedules">${SCHEDULES_ICON}<span>Schedules</span></a>
67
- <a class="le-rail-item" href="/audit" data-le-nav-head="audit" data-le-section="audit">${AUDIT_ICON}<span>Audit</span></a>
68
58
  <span class="le-rail-gap"></span>
69
- <button type="button" class="le-rail-item le-adv-toggle" id="leAdvToggle" aria-pressed="false" title="Advanced view: also show version history, evaluations, the contract, the API and agent internals">${ADVANCED_ICON}<span>Advanced</span></button>
59
+ <a class="le-rail-item" href="/audit" data-le-nav-head="audit" data-le-section="audit">${AUDIT_ICON}<span>Audit</span></a>
70
60
  <a class="le-rail-item" href="/config?section=settings" data-le-nav-head="settings" data-le-section="settings">${SETTINGS_ICON}<span>Settings</span></a>
71
61
  <div class="le-who" id="leWho" hidden></div>
72
62
  </nav>
@@ -89,7 +79,7 @@ export const consoleSidebarHtml = `<aside class="le-sidebar" aria-label="Console
89
79
  <nav class="le-settings-menu" aria-label="Settings">
90
80
  <a href="/config?section=models" data-le-nav="models">Models</a>
91
81
  <a href="/config?section=apps" data-le-nav="apps">Apps</a>
92
- <a href="/config?section=abilities" data-le-nav="abilities" data-advanced>Abilities</a>
82
+ <a href="/config?section=abilities" data-le-nav="abilities">Abilities</a>
93
83
  <a href="/config?section=settings" data-le-nav="settings">General settings</a>
94
84
  </nav>
95
85
  </section>
@@ -97,25 +87,10 @@ export const consoleSidebarHtml = `<aside class="le-sidebar" aria-label="Console
97
87
  </aside>`;
98
88
  export const consoleShellScript = `<script>
99
89
  (function () {
100
- // Simple view unless this person turned Advanced on.
101
- var advancedOn = false;
102
- try { advancedOn = localStorage.getItem('le-advanced') === '1'; } catch (e) {}
103
- document.documentElement.classList.toggle('le-simple', !advancedOn);
104
- var advToggle = document.getElementById('leAdvToggle');
105
- if (advToggle) {
106
- advToggle.setAttribute('aria-pressed', String(advancedOn));
107
- advToggle.addEventListener('click', function () {
108
- advancedOn = !advancedOn;
109
- try { localStorage.setItem('le-advanced', advancedOn ? '1' : '0'); } catch (e) {}
110
- document.documentElement.classList.toggle('le-simple', !advancedOn);
111
- advToggle.setAttribute('aria-pressed', String(advancedOn));
112
- document.dispatchEvent(new CustomEvent('le-advanced', { detail: advancedOn }));
113
- });
114
- }
115
90
  // A setting only the workspace's admin can change: said plainly, with
116
- // the technical how-to for Advanced view.
91
+ // the technical how-to.
117
92
  function adminNote(tech) {
118
- return '<p class="hint le-admin-note"><span data-simple>Only your workspace admin can change this.</span><span data-advanced>' + tech + '</span></p>';
93
+ return '<p class="hint le-admin-note">Only your workspace admin can change this. ' + tech + '</p>';
119
94
  }
120
95
  var page = document.body.getAttribute('data-le-page') || '';
121
96
  var params = new URLSearchParams(location.search);
@@ -137,9 +112,6 @@ export const consoleShellScript = `<script>
137
112
  ['schedules', 'Schedules'], ['chat', 'Chat'], ['actauth', 'Permissions'], ['env', 'Environment'], ['advanced', 'Advanced']
138
113
  ];
139
114
 
140
- // The agent tabs for Advanced view only.
141
- var ADVANCED_TABS = ['env', 'advanced'];
142
-
143
115
  function esc(s) {
144
116
  return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) {
145
117
  return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c];
@@ -351,12 +323,12 @@ export const consoleShellScript = `<script>
351
323
  var count = t[0] === 'env'
352
324
  ? '<span data-le-env-count="' + esc(opts.name) + '">' + envCountHtml(opts.name) + '</span>'
353
325
  : (counts[t[0]] != null ? '<span class="le-count">' + counts[t[0]] + '</span>' : '');
354
- return '<a class="le-tab" data-tab="' + t[0] + '" href="' + tabHref(opts.name, t[0]) + '" aria-selected="' + (t[0] === opts.tab) + '"' + (ADVANCED_TABS.indexOf(t[0]) !== -1 ? ' data-advanced' : '') + '>' + t[1] + count + '</a>';
326
+ return '<a class="le-tab" data-tab="' + t[0] + '" href="' + tabHref(opts.name, t[0]) + '" aria-selected="' + (t[0] === opts.tab) + '">' + t[1] + count + '</a>';
355
327
  }).join('');
356
328
  return '<div class="le-head"><div class="le-head-row">' +
357
329
  '<div class="le-title"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">&#9776;</button>' +
358
330
  '<div style="min-width:0"><h1><span data-le-head-name>' + esc(opts.displayName || opts.name) + '</span>' +
359
- '<span class="le-head-id" data-le-head-id data-advanced' + (opts.displayName ? '' : ' hidden') + '>' + esc(opts.name) + '</span></h1>' + (opts.prompt ? '<p>' + esc(opts.prompt) + '</p>' : '') + '</div></div>' +
331
+ '<span class="le-head-id" data-le-head-id' + (opts.displayName ? '' : ' hidden') + '>' + esc(opts.name) + '</span></h1>' + (opts.prompt ? '<p>' + esc(opts.prompt) + '</p>' : '') + '</div></div>' +
360
332
  '<div class="le-chips">' + chips + '</div></div>' +
361
333
  '<nav class="le-tabs" aria-label="Agent sections">' + tabs + '</nav></div>';
362
334
  }
@@ -708,6 +680,6 @@ export const consoleShellScript = `<script>
708
680
  }
709
681
 
710
682
 
711
- window.leShell = { advanced: function () { return advancedOn; }, adminNote: adminNote, loadError: function () { return loadError; }, ready: ready, settings: function () { return settings; }, getJson: getJson, reloadGoals: reloadGoals, reloadJobs: reloadJobs, reloadWorkflows: reloadWorkflows, reloadInboxCount: reloadInboxCount, renderHead: renderHead, setTab: setTab, setActive: setActive, setDisplayName: setDisplayName, displayNameOf: displayNameOf, esc: esc, tabHref: tabHref, envCountHtml: envCountHtml, setCount: setCount, wireModelPicker: wireModelPicker, loadProviderKeys: loadProviderKeys, applyProviderKeys: applyProviderKeys, abilityOriginBadge: abilityOriginBadge, toggleAbilityDetails: toggleAbilityDetails };
683
+ window.leShell = { adminNote: adminNote, loadError: function () { return loadError; }, ready: ready, settings: function () { return settings; }, getJson: getJson, reloadGoals: reloadGoals, reloadJobs: reloadJobs, reloadWorkflows: reloadWorkflows, reloadInboxCount: reloadInboxCount, renderHead: renderHead, setTab: setTab, setActive: setActive, setDisplayName: setDisplayName, displayNameOf: displayNameOf, esc: esc, tabHref: tabHref, envCountHtml: envCountHtml, setCount: setCount, wireModelPicker: wireModelPicker, loadProviderKeys: loadProviderKeys, applyProviderKeys: applyProviderKeys, abilityOriginBadge: abilityOriginBadge, toggleAbilityDetails: toggleAbilityDetails };
712
684
  })();
713
685
  </script>`;
@@ -151,10 +151,6 @@ export const devUiCss = `
151
151
  .le-rail-item .le-inbox-count { position: absolute; top: 2px; right: 4px; margin: 0; padding: 0 5px; font-size: 10px; }
152
152
  .le-inbox-count[hidden] { display: none; }
153
153
  .le-rail-gap { flex: 1; }
154
- button.le-rail-item { border: 0; background: none; height: 40px; font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; width: 100%; }
155
- .le-adv-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }
156
- .le-simple [data-advanced] { display: none !important; }
157
- html:not(.le-simple) [data-simple] { display: none !important; }
158
154
  .le-nav-icon { width: 15px; height: 15px; flex-shrink: 0; }
159
155
  .le-panel { width: 228px; flex: none; display: flex; flex-direction: column; min-height: 0; padding-top: 14px; }
160
156
  .le-panel[hidden] { display: none; }
@@ -0,0 +1,14 @@
1
+ import type { RunFeedback } from '../core/workflow-runs.js';
2
+ export declare function feedbackPageHtml(view: {
3
+ state: 'ask';
4
+ title: string;
5
+ result: string;
6
+ verdict?: 'good' | 'bad';
7
+ given?: RunFeedback;
8
+ error?: string;
9
+ } | {
10
+ state: 'thanks';
11
+ title: string;
12
+ } | {
13
+ state: 'invalid';
14
+ }): string;
@@ -0,0 +1,56 @@
1
+ // The page a signed feedback link opens (GET /feedback/<token>, from a
2
+ // messaging app, an email or a callback): a run's result, and a form to
3
+ // say whether it was good, add a note, give the text actually used, and a
4
+ // name, sent with no sign-in (POST, the link is the permission). Plain
5
+ // HTML and a form, so it works anywhere, scripts or not.
6
+ import { devUiCss } from './dev-ui-styles.js';
7
+ const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
8
+ export function feedbackPageHtml(view) {
9
+ const page = (title, body) => `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${esc(title)}</title>
10
+ <style>${devUiCss}
11
+ body { background: var(--canvas); }
12
+ .fb { max-width: 640px; margin: 6vh auto 40px; padding: 0 16px; display: grid; gap: 18px; }
13
+ .fb-card { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px; display: grid; gap: 16px; box-shadow: 0 2px 10px rgba(0, 0, 0, .04); }
14
+ .fb h1 { margin: 0; font-size: 24px; font-weight: 500; letter-spacing: -0.02em; }
15
+ .fb h1 .soft { color: var(--ink-faint); }
16
+ .fb-result { max-height: 280px; overflow: auto; padding: 12px 14px; border-radius: 10px; background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.55; }
17
+ .fb-k { font-size: 12px; font-family: var(--font-mono); color: var(--ink-faint); margin: 0 0 6px; }
18
+ .fb-verdict { display: flex; gap: 10px; }
19
+ .fb-verdict label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; height: 46px; border: 1px solid var(--line); border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; }
20
+ .fb-verdict input { position: absolute; opacity: 0; pointer-events: none; }
21
+ .fb-verdict label:has(input:checked) { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
22
+ .fb textarea, .fb input[type="text"] { width: 100%; font-size: 14px; border-radius: 10px; padding: 10px 12px; }
23
+ .fb textarea { min-height: 80px; }
24
+ .fb details summary { cursor: pointer; font-size: 13.5px; color: var(--ink-muted); }
25
+ .fb details[open] summary { margin-bottom: 8px; }
26
+ .fb .send { height: 42px; border-radius: 11px; border: 0; background: var(--primary); color: var(--on-primary); font-size: 14.5px; font-weight: 600; }
27
+ .fb .hint { font-size: 12.5px; color: var(--ink-muted); margin: 0; }
28
+ .fb .error { color: var(--bad); font-size: 13.5px; margin: 0; }
29
+ .fb-done { text-align: center; padding: 34px 24px; }
30
+ .fb-done .big { font-size: 40px; }
31
+ </style></head><body><main class="fb">${body}</main></body></html>`;
32
+ if (view.state === 'invalid') {
33
+ return page('Feedback link', '<div class="fb-card fb-done"><div class="big">⌛</div><h1>This link has expired</h1><p class="hint">Feedback links last 30 days. Give feedback on this run from the Inbox instead.</p></div>');
34
+ }
35
+ if (view.state === 'thanks') {
36
+ return page('Thanks', `<div class="fb-card fb-done"><div class="big">🙏</div><h1>Thanks, that helps</h1><p class="hint">Your feedback on ${esc(view.title)} is saved. It's used to improve the workflow; you can close this page.</p></div>`);
37
+ }
38
+ const given = view.given;
39
+ const verdict = view.verdict ?? given?.verdict;
40
+ const check = (v) => (verdict === v ? ' checked' : '');
41
+ return page(`Feedback: ${view.title}`, `
42
+ <h1><span class="soft">How did</span> ${esc(view.title)} <span class="soft">do?</span></h1>
43
+ <form class="fb-card" method="post">
44
+ <div><p class="fb-k">// Its result</p><div class="fb-result">${esc(view.result || '(no result)')}</div></div>
45
+ ${given ? `<p class="hint">Feedback was already given${given.by ? ` by ${esc(given.by)}` : ''}; sending again replaces it.</p>` : ''}
46
+ <div class="fb-verdict" role="radiogroup" aria-label="Was it good?">
47
+ <label><input type="radio" name="verdict" value="good"${check('good')} required>👍 Good</label>
48
+ <label><input type="radio" name="verdict" value="bad"${check('bad')}>👎 Needs work</label>
49
+ </div>
50
+ <label><span class="fb-k">// What should change? (optional)</span><textarea name="note" maxlength="1000" placeholder="e.g. It should give the tracking number, and keep it shorter">${esc(given?.note ?? '')}</textarea></label>
51
+ <details><summary>Fix the result yourself (optional)</summary><textarea name="final" maxlength="50000" style="min-height:160px">${esc(given?.final ?? view.result)}</textarea><p class="hint">Change it to what you'd actually send. The workflow learns from the difference.</p></details>
52
+ <label><span class="fb-k">// Your name (optional)</span><input type="text" name="name" maxlength="80" placeholder="So the team knows who said it"></label>
53
+ ${view.error ? `<p class="error">${esc(view.error)}</p>` : ''}
54
+ <button type="submit" class="send">Send feedback</button>
55
+ </form>`);
56
+ }
@@ -1024,7 +1024,7 @@ ${consoleShellScript}
1024
1024
  (si.dashboardUrl ? ' &middot; <a href="' + escapeHtml(si.dashboardUrl) + '">Dashboard</a>' : '')
1025
1025
  : si.mode === 'basic'
1026
1026
  ? 'Basic Auth (<code>LOOPENGINE_ADMIN_AUTH</code>)'
1027
- : '<span class="error">None: anyone who can reach this workspace can use it.</span><span class="hint" data-advanced> Set <code>LOOPENGINE_ADMIN_AUTH</code>.</span>';
1027
+ : '<span class="error">None: anyone who can reach this workspace can use it.</span><span class="hint"> Set <code>LOOPENGINE_ADMIN_AUTH</code>.</span>';
1028
1028
  var rows = [
1029
1029
  ['Admin sign-in', signIn],
1030
1030
  ['LoopEngine version', '<code>' + escapeHtml(d.version) + '</code>'],
@@ -1036,11 +1036,12 @@ ${consoleShellScript}
1036
1036
  ['Theme', 'Follows your system'],
1037
1037
  ];
1038
1038
  return '<section><table><thead><tr><th>Setting</th><th>Value</th></tr></thead><tbody>' +
1039
- rows.filter(Boolean).map(function (r) { return '<tr' + (r[2] ? ' data-advanced' : '') + '><td>' + r[0] + '</td><td>' + r[1] + '</td></tr>'; }).join('') +
1039
+ rows.filter(Boolean).map(function (r) { return '<tr><td>' + r[0] + '</td><td>' + r[1] + '</td></tr>'; }).join('') +
1040
1040
  '</tbody></table></section>' +
1041
1041
  (d.timeZone ? '<section><h3>Time zone</h3><div class="source" id="timeZoneBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' : '') +
1042
+ '<section><h3>Publishing</h3><div class="source" id="publishingBox"></div></section>' +
1042
1043
  '<section><h3>Shared policies</h3><div class="source" id="policiesBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' +
1043
- '<section data-advanced><h3>Private ability sources</h3><p class="muted" style="margin:0 0 10px">Where your own abilities come from, listed under Private on the Abilities page next to LoopEngine&#39;s official ones.</p><div class="source" id="abilitySourcesBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' +
1044
+ '<section><h3>Private ability sources</h3><p class="muted" style="margin:0 0 10px">Where your own abilities come from, listed under Private on the Abilities page next to LoopEngine&#39;s official ones.</p><div class="source" id="abilitySourcesBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' +
1044
1045
  '<section><h3>Updates</h3><div class="source" id="upgradeBox"><p class="hint">Checking for a newer LoopEngine' + String.fromCharCode(8230) + '</p></div></section>';
1045
1046
  }
1046
1047
 
@@ -1192,6 +1193,46 @@ ${consoleShellScript}
1192
1193
  });
1193
1194
  }
1194
1195
 
1196
+ // ---- Publishing: whether a change to what a workflow's runs do (its
1197
+ // prompt, inputs, model, result format, success criteria) can be
1198
+ // published in one click from the editor, or must be saved as a draft
1199
+ // and published after its review. Schedules, webhooks and where messages
1200
+ // go change straight away either way. ----
1201
+ function renderPublishing(d) {
1202
+ var box = document.getElementById('publishingBox');
1203
+ if (!box) return;
1204
+ var on = d.requireReview === true;
1205
+ var intro = '<p>Changes to what a workflow does (its prompt, inputs, model, result format and success criteria) become a new version when they' + String.fromCharCode(8217) + 're published. Schedules, webhooks and where messages go change straight away, and are recorded in Audit.</p>';
1206
+ if (!d.canChangeSettings) {
1207
+ box.innerHTML = intro + '<p>' + (on ? 'Review is required before publishing.' : 'Changes can be saved and published in one step.') + '</p>' +
1208
+ leShell.adminNote('Set <code>LOOPENGINE_ADMIN_AUTH</code> to change it here, or put <code>LOOPENGINE_REQUIRE_REVIEW=1</code> in .env.');
1209
+ return;
1210
+ }
1211
+ box.innerHTML = intro +
1212
+ '<label style="display:flex;gap:8px;align-items:flex-start;max-width:560px"><input type="checkbox" id="requireReview"' + (on ? ' checked' : '') + ' style="margin-top:3px">' +
1213
+ '<span><strong>Require review before publishing</strong><br><span class="hint">Every change is saved as a draft first, then published from Review and publish. Off, the editor also offers Save and publish.</span></span></label>' +
1214
+ '<div id="publishingMsg" class="hint" style="margin-top:8px"></div>';
1215
+ var box2 = document.getElementById('requireReview');
1216
+ box2.addEventListener('change', function () {
1217
+ var msg = document.getElementById('publishingMsg');
1218
+ box2.disabled = true;
1219
+ msg.textContent = 'Saving' + String.fromCharCode(8230);
1220
+ fetch('/config/publishing', {
1221
+ method: 'PUT',
1222
+ headers: { 'content-type': 'application/json' },
1223
+ body: JSON.stringify({ requireReview: box2.checked }),
1224
+ })
1225
+ .then(function (r) { return r.json().then(function (b) { return { ok: r.ok, body: b }; }); })
1226
+ .then(function (r) {
1227
+ box2.disabled = false;
1228
+ if (!r.ok) { box2.checked = !box2.checked; msg.innerHTML = '<span class="error">' + escapeHtml(r.body.error || 'Could not save') + '</span>'; return; }
1229
+ box2.checked = r.body.requireReview === true;
1230
+ msg.textContent = r.body.requireReview ? 'Saved: changes now wait for review.' : 'Saved: changes can be published in one step.';
1231
+ })
1232
+ .catch(function (err) { box2.disabled = false; box2.checked = !box2.checked; msg.innerHTML = '<span class="error">' + escapeHtml(err.message) + '</span>'; });
1233
+ });
1234
+ }
1235
+
1195
1236
  // ---- Shared policies: the business's rules every workflow run reads,
1196
1237
  // above its own instructions (policies.md in the project). ----
1197
1238
  function renderPolicies(p) {
@@ -1416,6 +1457,7 @@ ${consoleShellScript}
1416
1457
  .then(function (d) {
1417
1458
  content.innerHTML = renderSettings(d);
1418
1459
  loadedSections.settings = true;
1460
+ renderPublishing(d);
1419
1461
  loadTimeZone();
1420
1462
  loadPolicies();
1421
1463
  loadAbilitySources();
@@ -160,3 +160,11 @@ export declare function setWorkspaceTimeZone(value: unknown, options?: {
160
160
  timeZone: string;
161
161
  moved: number;
162
162
  }>;
163
+ /** Settings → Publishing: whether a workflow's changes must go through
164
+ * Review and publish. Off (the default), the editor, the success
165
+ * criteria and Self-Improve also offer Save and publish in one click; on,
166
+ * every change to what a run does is saved as a draft and published only
167
+ * after its review. Saved like the time zone (the project's .env). */
168
+ export declare const REQUIRE_REVIEW_ENV = "LOOPENGINE_REQUIRE_REVIEW";
169
+ export declare function requireReview(): boolean;
170
+ export declare function setRequireReview(on: boolean): Promise<boolean>;
@@ -328,3 +328,19 @@ export async function setWorkspaceTimeZone(value, options = {}) {
328
328
  const moved = options.moveSchedules && timeZone !== before ? await moveScheduledTasksToTimeZone(before, timeZone) : 0;
329
329
  return { timeZone, moved };
330
330
  }
331
+ /** Settings → Publishing: whether a workflow's changes must go through
332
+ * Review and publish. Off (the default), the editor, the success
333
+ * criteria and Self-Improve also offer Save and publish in one click; on,
334
+ * every change to what a run does is saved as a draft and published only
335
+ * after its review. Saved like the time zone (the project's .env). */
336
+ export const REQUIRE_REVIEW_ENV = 'LOOPENGINE_REQUIRE_REVIEW';
337
+ export function requireReview() {
338
+ return /^(1|true|yes|on)$/i.test(process.env[REQUIRE_REVIEW_ENV]?.trim() ?? '');
339
+ }
340
+ export async function setRequireReview(on) {
341
+ if (on)
342
+ await setEnvVar(REQUIRE_REVIEW_ENV, '1');
343
+ else
344
+ await unsetEnvVar(REQUIRE_REVIEW_ENV);
345
+ return requireReview();
346
+ }
@@ -79,6 +79,19 @@ export const inboxPageHtml = `<!doctype html>
79
79
  .ib-act summary code { font-size: 12px; }
80
80
  .ib-act.failed summary { color: var(--bad); }
81
81
  .ib-typing { font-size: 13px; color: var(--ink-muted); font-style: italic; }
82
+ .ib-fb { display: grid; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
83
+ .ib-fb-ask { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
84
+ .ib-fb-ask[hidden], .ib-fb-form[hidden], .ib-fb-given[hidden] { display: none; }
85
+ .ib-fb-q { font-size: 14px; font-weight: 600; margin-right: auto; }
86
+ .ib-fb-pick { display: inline-flex; gap: 6px; }
87
+ .ib-fb-pick button { height: 34px; padding: 0 14px; border-radius: 9px; font-size: 13.5px; font-weight: 600; background: var(--bg); }
88
+ .ib-fb-pick button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
89
+ .ib-fb-form { display: grid; gap: 8px; }
90
+ .ib-fb-form textarea { width: 100%; box-sizing: border-box; min-height: 64px; font-size: 13.5px; border-radius: 9px; }
91
+ .ib-fb-form textarea.ib-fb-final { min-height: 140px; margin-top: 6px; }
92
+ .ib-fb-form details summary { cursor: pointer; font-size: 13px; color: var(--ink-muted); }
93
+ .ib-fb-given { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 13.5px; }
94
+ .ib-fb-given .ib-fb-change { margin-left: auto; height: 28px; padding: 0 10px; font-size: 12.5px; }
82
95
  @media (max-width: 860px) {
83
96
  .ib-split { grid-template-columns: minmax(0, 1fr); }
84
97
  .ib-split.has-thread .ib-items { display: none; }
@@ -411,10 +424,69 @@ ${renderMarkdownScript}
411
424
  if (run.status === 'done' && !(run.output === undefined && lastText && lastText === String(run.result || '').trim())) out.push(msgHtml('agent', agent, run.finished_at, run.output !== undefined
412
425
  ? '<pre class="ib-pre">' + esc(JSON.stringify(run.output, null, 2)) + '</pre>'
413
426
  : '<div class="ib-md">' + renderMarkdownPreview(run.result || 'Done.') + '</div>'));
427
+ if (run.status === 'done') out.push(feedbackHtml(run));
414
428
  }
415
429
  return out.join('');
416
430
  }
417
431
 
432
+ // How a finished run did, in a person's words: Good or Needs work, a
433
+ // note, and the result as it should have been. It feeds the workflow's
434
+ // Feedback tab and Self-Improve. Shown as given once given, to change.
435
+ function feedbackHtml(run) {
436
+ var f = run.feedback;
437
+ if (!canDecide()) return f ? '<li class="ib-fb"><span class="hint">Feedback: ' + esc(f.verdict === 'good' ? 'Good' : f.verdict === 'bad' ? 'Needs work' : 'given') + (f.note ? DOT + esc(f.note) : '') + '</span></li>' : '';
438
+ var given = f ? '<div class="ib-fb-given"><span class="ib-state ' + (f.verdict === 'bad' ? 'bad' : 'good') + '">' + (f.verdict === 'bad' ? 'Needs work' : f.verdict === 'good' ? 'Good' : 'Feedback given') + '</span>' +
439
+ (f.note ? '<span>' + String.fromCharCode(8220) + esc(f.note) + String.fromCharCode(8221) + '</span>' : '') +
440
+ '<span class="hint">' + esc((f.by ? f.by + DOT : '') + ago(f.at)) + '</span><button type="button" class="ib-fb-change">Change</button></div>' : '';
441
+ return '<li class="ib-fb" data-run="' + esc(run.run_id) + '">' + given +
442
+ '<div class="ib-fb-ask"' + (f ? ' hidden' : '') + '><span class="ib-fb-q">How did it do?</span>' +
443
+ '<span class="ib-fb-pick"><button type="button" data-verdict="good"' + (f && f.verdict === 'good' ? ' aria-pressed="true"' : '') + '>' + String.fromCodePoint(128077) + ' Good</button>' +
444
+ '<button type="button" data-verdict="bad"' + (f && f.verdict === 'bad' ? ' aria-pressed="true"' : '') + '>' + String.fromCodePoint(128078) + ' Needs work</button></span></div>' +
445
+ '<form class="ib-fb-form" hidden>' +
446
+ '<textarea name="note" maxlength="1000" placeholder="What should change? (optional) e.g. give the tracking number, keep it shorter">' + esc(f && f.note ? f.note : '') + '</textarea>' +
447
+ '<details><summary>Fix the result yourself (optional)</summary><textarea name="final" class="ib-fb-final">' + esc(f && f.final != null ? f.final : (run.result || '')) + '</textarea><span class="hint">Change it to what you' + String.fromCharCode(8217) + 'd actually send. The workflow learns from the difference.</span></details>' +
448
+ '<div class="ib-actions"><button type="submit" class="ib-btn">Send feedback</button><button type="button" class="ib-btn plain ib-fb-cancel">Cancel</button><span class="hint ib-fb-result" role="status"></span></div>' +
449
+ '</form></li>';
450
+ }
451
+
452
+ function wireFeedback(c) {
453
+ var box = page.querySelector('.ib-thread .ib-fb[data-run]');
454
+ if (!box) return;
455
+ var run = c.run;
456
+ var verdict = run.feedback && run.feedback.verdict;
457
+ var ask = box.querySelector('.ib-fb-ask');
458
+ var form = box.querySelector('.ib-fb-form');
459
+ var change = box.querySelector('.ib-fb-change');
460
+ if (change) change.addEventListener('click', function () { box.querySelector('.ib-fb-given').hidden = true; ask.hidden = false; form.hidden = false; });
461
+ ask.addEventListener('click', function (ev) {
462
+ var b = ev.target.closest('[data-verdict]');
463
+ if (!b) return;
464
+ verdict = b.getAttribute('data-verdict');
465
+ var all = ask.querySelectorAll('[data-verdict]');
466
+ for (var i = 0; i < all.length; i++) all[i].setAttribute('aria-pressed', String(all[i] === b));
467
+ form.hidden = false;
468
+ form.querySelector('textarea[name="note"]').focus();
469
+ });
470
+ form.querySelector('.ib-fb-cancel').addEventListener('click', function () { form.hidden = true; });
471
+ form.addEventListener('submit', function (ev) {
472
+ ev.preventDefault();
473
+ var result = form.querySelector('.ib-fb-result');
474
+ if (!verdict) { result.textContent = 'Choose Good or Needs work first.'; return; }
475
+ var body = { verdict: verdict };
476
+ var note = form.querySelector('textarea[name="note"]').value.trim();
477
+ if (note) body.note = note;
478
+ var final = form.querySelector('textarea[name="final"]').value;
479
+ if (final !== (run.result || '')) body.final = final;
480
+ var send = form.querySelector('[type="submit"]');
481
+ send.disabled = true;
482
+ result.textContent = 'Sending' + ELLIPSIS;
483
+ fetch('/inbox/cases/' + encodeURIComponent(run.run_id) + '/feedback', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
484
+ .then(function (r) { return r.json().then(function (b) { if (!r.ok) throw new Error(b.error || 'Could not send it'); return b; }); })
485
+ .then(function () { openThread = null; loadThread(c.id); })
486
+ .catch(function (err) { send.disabled = false; result.textContent = err.message; });
487
+ });
488
+ }
489
+
418
490
  function renderThread(c) {
419
491
  var box = page.querySelector('.ib-thread');
420
492
  var run = c.run;
@@ -446,6 +518,7 @@ ${renderMarkdownScript}
446
518
  .catch(function (err) { archive.disabled = false; archive.textContent = err.message; });
447
519
  });
448
520
  wireCase(c);
521
+ wireFeedback(c);
449
522
  }
450
523
 
451
524
  function valueHtml(v) {
@@ -161,7 +161,10 @@ export declare function setAgentPrimaryNotifier(config: AgentConfig, channel: un
161
161
  * regardless of which events they subscribed to. A webhook gets a signed
162
162
  * `run_finish` payload with `data` merged in; the apps get `text`.
163
163
  * Returns whether any notifier took it. */
164
- export declare function announceToNotifier(config: AgentConfig, text: string, data: Record<string, unknown>, defaultWebhook?: DefaultWebhook): boolean;
164
+ /** `feedback`, for a finished run: its signed feedback link for each
165
+ * channel (slack, telegram, lark, webhook), added to each app's message as
166
+ * Good / Needs work links and to a webhook's payload as feedback_url. */
167
+ export declare function announceToNotifier(config: AgentConfig, text: string, data: Record<string, unknown>, defaultWebhook?: DefaultWebhook, feedback?: (channel: string) => string | undefined): boolean;
165
168
  /** Posts `text` to the agent's messaging apps only (Slack, Lark,
166
169
  * Telegram), not to a webhook: a run's chat notice. Whether any app got
167
170
  * it. */
@@ -293,7 +293,14 @@ function activeNotifierTargets(config, defaultWebhook) {
293
293
  * regardless of which events they subscribed to. A webhook gets a signed
294
294
  * `run_finish` payload with `data` merged in; the apps get `text`.
295
295
  * Returns whether any notifier took it. */
296
- export function announceToNotifier(config, text, data, defaultWebhook) {
296
+ /** `feedback`, for a finished run: its signed feedback link for each
297
+ * channel (slack, telegram, lark, webhook), added to each app's message as
298
+ * Good / Needs work links and to a webhook's payload as feedback_url. */
299
+ export function announceToNotifier(config, text, data, defaultWebhook, feedback) {
300
+ const ask = (channel) => {
301
+ const url = feedback?.(channel);
302
+ return url ? `${text}\n\nHow did it do? Good: ${url}?v=good · Needs work: ${url}?v=bad` : text;
303
+ };
297
304
  let targets;
298
305
  try {
299
306
  targets = activeNotifierTargets(config, defaultWebhook);
@@ -305,19 +312,19 @@ export function announceToNotifier(config, text, data, defaultWebhook) {
305
312
  for (const target of targets) {
306
313
  switch (target.channel) {
307
314
  case 'webhook':
308
- postLifecycleWebhook(target.config.webhookUrl, target.config.webhookSecret, 'run_finish', { agent: config.name, text, ...data });
315
+ postLifecycleWebhook(target.config.webhookUrl, target.config.webhookSecret, 'run_finish', { agent: config.name, text, ...data, ...(feedback?.('webhook') ? { feedback_url: feedback('webhook') } : {}) });
309
316
  sent = true;
310
317
  break;
311
318
  case 'slack':
312
- new SlackNotifier({ botToken: target.config.botToken, channelId: target.config.channelId }).postMessage(text);
319
+ new SlackNotifier({ botToken: target.config.botToken, channelId: target.config.channelId }).postMessage(ask('slack'));
313
320
  sent = true;
314
321
  break;
315
322
  case 'lark':
316
- new LarkNotifier({ appId: target.config.appId, appSecret: target.config.appSecret, chatId: target.config.chatId }).postMessage(text);
323
+ new LarkNotifier({ appId: target.config.appId, appSecret: target.config.appSecret, chatId: target.config.chatId }).postMessage(ask('lark'));
317
324
  sent = true;
318
325
  break;
319
326
  case 'telegram':
320
- new TelegramNotifier({ botToken: target.config.botToken, chatId: target.config.chatId }).postMessage(text);
327
+ new TelegramNotifier({ botToken: target.config.botToken, chatId: target.config.chatId }).postMessage(ask('telegram'));
321
328
  sent = true;
322
329
  break;
323
330
  }
@@ -13,9 +13,9 @@
13
13
  // + Add schedule opens Create schedule: which workflow, its name, how
14
14
  // often (an interval, daily at a time, weekly on a day, or once), whether
15
15
  // each result goes to the messaging app, and the workflow's inputs for
16
- // every run. A schedule is part of its workflow, so it's added to that
17
- // workflow's draft (POST .../draft/schedules); when that's all the draft
18
- // holds, it can be published right there.
16
+ // every run. It starts at once (POST /agents/:name/schedules): a schedule
17
+ // is how a workflow starts, not what it does, so it has no draft, and the
18
+ // change is in Audit.
19
19
  //
20
20
  // Its data is each agent's /agents/:name/schedules. Like the other
21
21
  // console pages, its inline script avoids backslashes and template
@@ -174,7 +174,7 @@ ${consoleSidebarHtml}
174
174
  </div>
175
175
  <div class="sc-dlg-col">
176
176
  <div class="sc-field"><span class="sc-field-k">Inputs for every run</span><div class="sc-inputs" id="scInputs"></div></div>
177
- <div class="sc-field"><span class="sc-field-k">Before it starts</span><p class="hint">A schedule is part of its workflow, so it goes into the workflow's draft. Publish the draft and it starts running; until then nothing runs.</p></div>
177
+ <div class="sc-field"><span class="sc-field-k">When it starts</span><p class="hint">Right away: the first run is at the next time you chose. Switch it off on its card to pause it.</p></div>
178
178
  </div>
179
179
  </div>
180
180
  <div class="sc-dlg-foot" id="scFoot"></div>
@@ -530,25 +530,13 @@ ${consoleShellScript}
530
530
  var save = document.getElementById('scSave');
531
531
  save.disabled = true;
532
532
  foot.textContent = 'Saving' + String.fromCharCode(8230);
533
- var base = '/agents/' + encodeURIComponent(w.agent) + '/workflows/' + encodeURIComponent(w.id);
534
- api('POST', base + '/draft/schedules', body).then(function (r) {
533
+ // Live at once: a schedule is how a workflow starts, not what it does,
534
+ // so it needs no draft (and is in Audit).
535
+ body.workflow_id = w.id;
536
+ api('POST', '/agents/' + encodeURIComponent(w.agent) + '/schedules', body).then(function (r) {
535
537
  if (!r.ok) { save.disabled = false; foot.innerHTML = '<span class="error">' + esc(r.body.error || 'Could not add it') + '</span>'; return; }
536
- var only = (r.body.changes || []).length === 1;
537
- // On its own in the draft, it can go live now; with other changes,
538
- // they're reviewed together on the workflow's page.
539
- foot.innerHTML = only
540
- ? '<span>Added to ' + esc(w.title) + String.fromCharCode(8217) + 's draft. Publish it to start the schedule.</span><span style="flex:1"></span><button type="button" class="le-btn-dark" id="scPublish">Publish now</button>'
541
- : '<span>Added to ' + esc(w.title) + String.fromCharCode(8217) + 's draft, with its other changes.</span><span style="flex:1"></span><a class="le-btn-dark" href="' + wfHref(w.agent, w.id, 'triggers') + '">Review and publish</a>';
542
- var pub = document.getElementById('scPublish');
543
- if (pub) pub.addEventListener('click', function () {
544
- pub.disabled = true;
545
- pub.textContent = 'Publishing' + String.fromCharCode(8230);
546
- api('POST', base + '/publish', { note: 'Added a schedule' + (name ? ': ' + name : '') }).then(function (p) {
547
- if (!p.ok) { pub.disabled = false; pub.textContent = 'Publish now'; foot.insertAdjacentHTML('beforeend', '<span class="error">' + esc(p.body.error || 'Could not publish') + '</span>'); return; }
548
- dlg.close();
549
- load();
550
- });
551
- });
538
+ dlg.close();
539
+ load();
552
540
  });
553
541
  });
554
542
 
@@ -1,5 +1,5 @@
1
1
  import type { ModelCall } from '#core/run-agent.js';
2
- import type { RunFeedback, WorkflowRun } from '#core/workflow-runs.js';
2
+ import { type FeedbackSource, type RunFeedback, type WorkflowRun } from '#core/workflow-runs.js';
3
3
  import { type JsonSchema } from '#core/output-schema.js';
4
4
  export declare class EvidenceError extends Error {
5
5
  }
@@ -26,8 +26,15 @@ export interface WorkflowScores {
26
26
  export declare function workflowScores(runs: WorkflowRun[]): WorkflowScores;
27
27
  /** Feedback on a finished run, from an app or a person: `final`, the text
28
28
  * actually used (an edited draft, say), and/or `verdict` good or bad,
29
- * and a short `note`. */
30
- export declare function runFeedbackFrom(run: WorkflowRun, body: Record<string, unknown>): RunFeedback;
29
+ * and a short `note`; `source`, where it came from, and `by`, who gave
30
+ * it, when the caller says (see FeedbackSource). */
31
+ export declare function runFeedbackFrom(run: WorkflowRun, body: Record<string, unknown>, given?: {
32
+ source?: FeedbackSource;
33
+ by?: string;
34
+ }): RunFeedback;
35
+ /** A source an app names for its feedback, or undefined for none or one
36
+ * not known. */
37
+ export declare function feedbackSourceOf(value: unknown): FeedbackSource | undefined;
31
38
  export interface EvalCase {
32
39
  id: string;
33
40
  params: Record<string, string>;
@@ -24,6 +24,7 @@
24
24
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
25
25
  import { dirname, join } from 'node:path';
26
26
  import { randomUUID } from 'node:crypto';
27
+ import { FEEDBACK_SOURCES } from '#core/workflow-runs.js';
27
28
  import { checkOutput } from '#core/output-schema.js';
28
29
  import { editAmount } from './goals-admin.js';
29
30
  export class EvidenceError extends Error {
@@ -63,8 +64,9 @@ export function workflowScores(runs) {
63
64
  }
64
65
  /** Feedback on a finished run, from an app or a person: `final`, the text
65
66
  * actually used (an edited draft, say), and/or `verdict` good or bad,
66
- * and a short `note`. */
67
- export function runFeedbackFrom(run, body) {
67
+ * and a short `note`; `source`, where it came from, and `by`, who gave
68
+ * it, when the caller says (see FeedbackSource). */
69
+ export function runFeedbackFrom(run, body, given = {}) {
68
70
  if (run.status !== 'done')
69
71
  throw new EvidenceError('Only a run that finished with a result can get feedback.');
70
72
  const verdict = body.verdict === 'good' || body.verdict === 'bad' ? body.verdict : undefined;
@@ -78,9 +80,16 @@ export function runFeedbackFrom(run, body) {
78
80
  ...(verdict ? { verdict } : {}),
79
81
  ...(final !== undefined ? { final, edit: editAmount(run.result ?? '', final) } : {}),
80
82
  ...(note ? { note } : {}),
83
+ ...(given.source ? { source: given.source } : {}),
84
+ ...(given.by ? { by: given.by.slice(0, 120) } : {}),
81
85
  at: new Date().toISOString(),
82
86
  };
83
87
  }
88
+ /** A source an app names for its feedback, or undefined for none or one
89
+ * not known. */
90
+ export function feedbackSourceOf(value) {
91
+ return typeof value === 'string' && FEEDBACK_SOURCES.includes(value) ? value : undefined;
92
+ }
84
93
  /** The check every round adds for a workflow with an output schema: its
85
94
  * result matches the schema (core/output-schema.ts), checked in code. */
86
95
  export const OUTPUT_SCHEMA_CRITERION = { id: 'output-schema', text: 'Matches the output schema', kind: 'output_schema' };