loopengine 0.4.3 → 0.4.5
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-anchor.d.ts +39 -0
- package/dist/core/audit-anchor.js +90 -0
- package/dist/core/audit-store.d.ts +63 -1
- package/dist/core/audit-store.js +120 -1
- package/dist/core/mcp-abilities.js +14 -6
- package/dist/core/run-agent.d.ts +32 -6
- package/dist/core/run-agent.js +53 -8
- package/dist/core/workflow-runs.d.ts +24 -0
- package/dist/core/workflow-runs.js +50 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +8 -3
- package/dist/web/agents-config-page.js +17 -7
- package/dist/web/audit-admin.d.ts +28 -0
- package/dist/web/audit-admin.js +52 -0
- package/dist/web/audit-page.d.ts +15 -0
- package/dist/web/audit-page.js +371 -0
- package/dist/web/change-log.js +1 -0
- package/dist/web/console-shell.js +6 -2
- package/dist/web/dev-ui-styles.js +2 -0
- package/dist/web/global-config-page.js +41 -1
- package/dist/web/workflow-audit-report.d.ts +8 -0
- package/dist/web/workflow-audit-report.js +129 -0
- package/dist/web/workflow-audit.d.ts +120 -0
- package/dist/web/workflow-audit.js +208 -0
- package/dist/web/workflow-evidence.d.ts +14 -3
- package/dist/web/workflow-evidence.js +2 -2
- package/package.json +3 -1
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// The console's Audit page (/audit): the workspace's log of who changed
|
|
2
|
+
// what and who decided what (Activity), and every case kept, searched
|
|
3
|
+
// (Cases). Its data is web/audit-admin.ts's, behind /audit/events,
|
|
4
|
+
// /audit/events.csv, /audit/cases and /audit/filters. Owners, admins and
|
|
5
|
+
// editors see it; approvers and viewers use the Inbox only. Like the
|
|
6
|
+
// other console pages, its inline script avoids backslashes and template
|
|
7
|
+
// placeholders, since it lives inside a template literal.
|
|
8
|
+
import { devUiCss } from './dev-ui-styles.js';
|
|
9
|
+
import { consoleShellScript, consoleSidebarHtml } from './console-shell.js';
|
|
10
|
+
/** The page with its filters' choices in it (agents, workflows, people),
|
|
11
|
+
* so they show at once instead of after another request. */
|
|
12
|
+
export function auditPageFor(filters) {
|
|
13
|
+
// In a script element: no "</" may end it early.
|
|
14
|
+
return auditPageHtml.replace('null/*AUDIT_FILTERS*/', JSON.stringify(filters).replace(/</g, '\\u003c'));
|
|
15
|
+
}
|
|
16
|
+
export const auditPageHtml = `<!doctype html>
|
|
17
|
+
<html lang="en">
|
|
18
|
+
<head>
|
|
19
|
+
<meta charset="utf-8">
|
|
20
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
21
|
+
<title>Audit</title>
|
|
22
|
+
<style>${devUiCss}
|
|
23
|
+
.au { max-width: 1080px; display: grid; gap: 14px; }
|
|
24
|
+
.au-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
|
|
25
|
+
.au-tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--ink-muted); margin-bottom: -1px; }
|
|
26
|
+
.au-tabs button[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }
|
|
27
|
+
.au-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
28
|
+
.au-bar select, .au-bar input { font: inherit; font-size: 13px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); max-width: 180px; }
|
|
29
|
+
.au-bar input[type="search"] { flex: 1; min-width: 160px; max-width: none; }
|
|
30
|
+
.au-bar [hidden] { display: none; }
|
|
31
|
+
.au-actions { display: inline-flex; gap: 8px; margin-left: auto; }
|
|
32
|
+
.au-verify { font-size: 13px; }
|
|
33
|
+
.au-check { padding: 10px 14px; border-radius: 10px; font-size: 13px; background: var(--good-soft); color: var(--good); }
|
|
34
|
+
.au-check.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
|
|
35
|
+
.au-check .hint { display: block; margin-top: 2px; font-weight: 400; }
|
|
36
|
+
.au-summary { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 10px; background: var(--bg); }
|
|
37
|
+
.au-summary h2 { margin: 0; font-size: 15px; }
|
|
38
|
+
.au-summary ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 13.5px; line-height: 1.5; }
|
|
39
|
+
.au-summary-tools { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
40
|
+
.au-summary-tools a { font-size: 13px; font-weight: 600; color: var(--accent-ink); text-decoration: none; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; }
|
|
41
|
+
.au-summary-tools a.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
|
|
42
|
+
.au-export { font-size: 13px; font-weight: 600; color: var(--accent-ink); text-decoration: none; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; }
|
|
43
|
+
.au-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
|
|
44
|
+
.au-row { display: grid; grid-template-columns: 136px 80px minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 13px; }
|
|
45
|
+
.au-row:first-child { border-top: 0; }
|
|
46
|
+
.au-when { color: var(--ink-muted); white-space: nowrap; font-size: 12.5px; }
|
|
47
|
+
.au-kind { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); }
|
|
48
|
+
.au-kind.change { color: var(--accent-ink); }
|
|
49
|
+
.au-kind.decision.denied { color: var(--bad); }
|
|
50
|
+
.au-what { display: grid; gap: 2px; min-width: 0; }
|
|
51
|
+
.au-what strong { font-weight: 600; }
|
|
52
|
+
.au-detail { color: var(--ink-muted); overflow-wrap: anywhere; }
|
|
53
|
+
.au-where { font-size: 12.5px; color: var(--ink-muted); }
|
|
54
|
+
.au-open { color: var(--accent-ink); font-weight: 600; text-decoration: none; white-space: nowrap; font-size: 12.5px; }
|
|
55
|
+
.au-open:hover { text-decoration: underline; }
|
|
56
|
+
.au-case { grid-template-columns: 80px minmax(0, 1fr) auto; }
|
|
57
|
+
.au-state { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-muted); justify-self: start; }
|
|
58
|
+
.au-state.good { background: var(--good-soft); color: var(--good); }
|
|
59
|
+
.au-state.bad { background: var(--bad-soft); color: var(--bad); }
|
|
60
|
+
.au-state.warn { background: var(--warn-soft); color: var(--warn); }
|
|
61
|
+
.au-state.run { background: var(--accent-soft); color: var(--accent-ink); }
|
|
62
|
+
.au-empty { padding: 28px 16px; text-align: center; color: var(--ink-muted); font-size: 13.5px; }
|
|
63
|
+
.au-more { justify-self: center; }
|
|
64
|
+
.error { font-size: 13px; color: var(--bad); margin: 0; }
|
|
65
|
+
@media (max-width: 720px) {
|
|
66
|
+
.au-row, .au-case { grid-template-columns: minmax(0, 1fr) auto; }
|
|
67
|
+
.au-when { grid-column: 1 / -1; }
|
|
68
|
+
}
|
|
69
|
+
</style>
|
|
70
|
+
</head>
|
|
71
|
+
<body data-le-page="audit">
|
|
72
|
+
<div class="le-app">
|
|
73
|
+
${consoleSidebarHtml}
|
|
74
|
+
<main class="le-main">
|
|
75
|
+
<div class="le-head plain">
|
|
76
|
+
<div class="le-head-row">
|
|
77
|
+
<div class="le-title"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">☰</button>
|
|
78
|
+
<div><h1>Audit</h1><p>Who changed what, and who decided what, across the workspace; and every case kept, to search and open.</p></div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
<div class="le-scroll"><div class="le-page"><div class="au">
|
|
83
|
+
<div class="au-tabs" role="tablist">
|
|
84
|
+
<button type="button" role="tab" data-tab="activity" aria-selected="true">Activity</button>
|
|
85
|
+
<button type="button" role="tab" data-tab="cases" aria-selected="false">Cases</button>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="au-bar">
|
|
88
|
+
<select id="auAgent" aria-label="Agent"><option value="">All agents</option></select>
|
|
89
|
+
<select id="auWorkflow" aria-label="Workflow"><option value="">All workflows</option></select>
|
|
90
|
+
<select id="auBy" aria-label="Person"><option value="">Anyone</option></select>
|
|
91
|
+
<select id="auKind" aria-label="Kind">
|
|
92
|
+
<option value="">Everything</option><option value="change">Settings changed</option><option value="decision">Approvals</option><option value="answer">Answers</option><option value="feedback">Feedback</option>
|
|
93
|
+
</select>
|
|
94
|
+
<select id="auStatus" aria-label="Status" hidden>
|
|
95
|
+
<option value="">Any outcome</option><option value="done">Done</option><option value="error">Failed</option><option value="awaiting_approval">Waiting for a decision</option><option value="running">Running</option>
|
|
96
|
+
</select>
|
|
97
|
+
<select id="auPeriod" aria-label="Period">
|
|
98
|
+
<option value="7">Last 7 days</option><option value="30" selected>Last 30 days</option><option value="90">Last 90 days</option><option value="365">Last year</option><option value="">All time</option>
|
|
99
|
+
</select>
|
|
100
|
+
<input type="search" id="auQ" placeholder="Search" aria-label="Search">
|
|
101
|
+
<span class="au-actions"><button type="button" class="au-verify" id="auVerify">Verify log</button>
|
|
102
|
+
<a class="au-export" id="auExport" href="/audit/events.csv" download>Export CSV</a></span>
|
|
103
|
+
</div>
|
|
104
|
+
<div class="au-check" id="auCheck" role="status" hidden></div>
|
|
105
|
+
<section class="au-summary" id="auSummary" hidden></section>
|
|
106
|
+
<div id="auList"><p class="hint">Loading…</p></div>
|
|
107
|
+
<button type="button" class="au-more" id="auMore" hidden>Load older</button>
|
|
108
|
+
</div></div></div>
|
|
109
|
+
</main>
|
|
110
|
+
</div>
|
|
111
|
+
${consoleShellScript}
|
|
112
|
+
<script>window.AUDIT_FILTERS = null/*AUDIT_FILTERS*/;</script>
|
|
113
|
+
<script>
|
|
114
|
+
(function () {
|
|
115
|
+
var DOT = ' ' + String.fromCharCode(183) + ' ';
|
|
116
|
+
var params = new URLSearchParams(location.search);
|
|
117
|
+
var state = {
|
|
118
|
+
tab: params.get('tab') === 'cases' ? 'cases' : 'activity',
|
|
119
|
+
agent: params.get('agent') || '', workflow: params.get('workflow') || '', by: params.get('by') || '',
|
|
120
|
+
kind: params.get('kind') || '', status: params.get('status') || '',
|
|
121
|
+
period: params.has('period') ? params.get('period') : '30', q: params.get('q') || '',
|
|
122
|
+
};
|
|
123
|
+
// The filters' choices come with the page (auditPageFor), so they show
|
|
124
|
+
// at once; a page served without them fetches them.
|
|
125
|
+
var embedded = window.AUDIT_FILTERS || null;
|
|
126
|
+
var filters = embedded || { agents: [], workflows: [], people: [] };
|
|
127
|
+
var next = null;
|
|
128
|
+
var list = document.getElementById('auList');
|
|
129
|
+
var more = document.getElementById('auMore');
|
|
130
|
+
var el = {
|
|
131
|
+
agent: document.getElementById('auAgent'), workflow: document.getElementById('auWorkflow'), by: document.getElementById('auBy'),
|
|
132
|
+
kind: document.getElementById('auKind'), status: document.getElementById('auStatus'), period: document.getElementById('auPeriod'),
|
|
133
|
+
q: document.getElementById('auQ'), exportLink: document.getElementById('auExport'),
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function esc(s) {
|
|
137
|
+
return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) {
|
|
138
|
+
return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c];
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// The year only when it isn't this one.
|
|
142
|
+
function when(iso) {
|
|
143
|
+
var d = new Date(iso);
|
|
144
|
+
var opts = { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' };
|
|
145
|
+
if (d.getFullYear() !== new Date().getFullYear()) opts.year = 'numeric';
|
|
146
|
+
return d.toLocaleString(undefined, opts);
|
|
147
|
+
}
|
|
148
|
+
function agentLabel(name) {
|
|
149
|
+
if (!name) return 'Workspace';
|
|
150
|
+
var a = filters.agents.filter(function (x) { return x.name === name; })[0];
|
|
151
|
+
return a ? a.label : name;
|
|
152
|
+
}
|
|
153
|
+
function workflowTitle(agent, id) {
|
|
154
|
+
var w = filters.workflows.filter(function (x) { return x.agent === agent && x.id === id; })[0];
|
|
155
|
+
return w ? w.title : id;
|
|
156
|
+
}
|
|
157
|
+
function workflowHref(agent, id, tab) {
|
|
158
|
+
return '/agents/config?agent=' + encodeURIComponent(agent) + '&tab=workflows&workflow=' + encodeURIComponent(id) + (tab ? '&wtab=' + tab : '');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The query both lists and the CSV file share.
|
|
162
|
+
function query(extra) {
|
|
163
|
+
var q = new URLSearchParams();
|
|
164
|
+
if (state.agent) q.set('agent', state.agent);
|
|
165
|
+
if (state.workflow) q.set('workflow', state.workflow);
|
|
166
|
+
if (state.by) q.set('by', state.by);
|
|
167
|
+
if (state.tab === 'activity' && state.kind) q.set('kind', state.kind);
|
|
168
|
+
if (state.tab === 'cases' && state.status) q.set('status', state.status);
|
|
169
|
+
if (state.period) q.set('since', new Date(Date.now() - Number(state.period) * 86400000).toISOString());
|
|
170
|
+
if (state.q) q.set('q', state.q);
|
|
171
|
+
Object.keys(extra || {}).forEach(function (k) { q.set(k, extra[k]); });
|
|
172
|
+
return q.toString();
|
|
173
|
+
}
|
|
174
|
+
// The page's own address keeps the filters, so a view can be shared.
|
|
175
|
+
function remember() {
|
|
176
|
+
var q = new URLSearchParams();
|
|
177
|
+
if (state.tab === 'cases') q.set('tab', 'cases');
|
|
178
|
+
['agent', 'workflow', 'by', 'q'].forEach(function (k) { if (state[k]) q.set(k, state[k]); });
|
|
179
|
+
if (state.tab === 'activity' && state.kind) q.set('kind', state.kind);
|
|
180
|
+
if (state.tab === 'cases' && state.status) q.set('status', state.status);
|
|
181
|
+
if (state.period !== '30') q.set('period', state.period);
|
|
182
|
+
history.replaceState(null, '', '/audit' + (q.toString() ? '?' + q.toString() : ''));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Where an event leads: its case, the workflow's version or changes,
|
|
186
|
+
// the agent, or the workspace setting.
|
|
187
|
+
function eventLink(e) {
|
|
188
|
+
var d = e.data || {};
|
|
189
|
+
if (e.run_id) return { href: '/inbox?case=' + encodeURIComponent(e.run_id), text: 'Case' };
|
|
190
|
+
if (e.workflow_id) return { href: workflowHref(e.agent, e.workflow_id, /brief version/i.test(d.label || '') || /Edited the workflow/.test(d.label || '') ? 'brief' : 'changes'), text: 'Workflow' };
|
|
191
|
+
if (e.agent) return { href: '/agents/config?agent=' + encodeURIComponent(e.agent), text: 'Agent' };
|
|
192
|
+
var path = String(d.path || '');
|
|
193
|
+
if (path.indexOf('/config/models') === 0) return { href: '/config?section=models', text: 'Models' };
|
|
194
|
+
if (path.indexOf('/config/apps') === 0) return { href: '/config?section=apps', text: 'Apps' };
|
|
195
|
+
if (path.indexOf('/abilities') === 0) return { href: '/config?section=abilities', text: 'Abilities' };
|
|
196
|
+
return { href: '/config?section=settings', text: 'Settings' };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function eventWords(e) {
|
|
200
|
+
var d = e.data || {};
|
|
201
|
+
if (e.kind === 'change') return { what: d.label || 'Changed a setting', detail: '' };
|
|
202
|
+
if (e.kind === 'decision') return { what: (d.approved ? (d.edited ? 'Approved as changed ' : 'Approved ') : 'Denied ') + (d.tool || ''), detail: d.reason ? String.fromCharCode(8220) + d.reason + String.fromCharCode(8221) : '' };
|
|
203
|
+
if (e.kind === 'answer') return { what: 'Answered ' + String.fromCharCode(8220) + String(d.answer || '').slice(0, 300) + String.fromCharCode(8221), detail: d.question ? 'to: ' + String(d.question).slice(0, 200) : '' };
|
|
204
|
+
var v = [d.verdict === 'good' ? 'good' : d.verdict === 'bad' ? 'bad' : '', d.edit === 'none' ? 'used unedited' : d.edit ? d.edit + ' edits' : ''].filter(Boolean).join(', ');
|
|
205
|
+
return { what: 'Feedback' + (v ? ': ' + v : ''), detail: d.note || '' };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function eventRow(e) {
|
|
209
|
+
var words = eventWords(e);
|
|
210
|
+
var link = eventLink(e);
|
|
211
|
+
var kind = e.kind === 'change' ? 'Setting' : e.kind === 'decision' ? 'Approval' : e.kind === 'answer' ? 'Answer' : 'Feedback';
|
|
212
|
+
var denied = e.kind === 'decision' && e.data && !e.data.approved ? ' denied' : '';
|
|
213
|
+
var where = agentLabel(e.agent) + (e.workflow_id ? DOT + workflowTitle(e.agent, e.workflow_id) : '');
|
|
214
|
+
return '<div class="au-row"><span class="au-when">' + esc(when(e.at)) + '</span>' +
|
|
215
|
+
'<span class="au-kind ' + esc(e.kind) + denied + '">' + kind + '</span>' +
|
|
216
|
+
'<span class="au-what"><strong>' + esc(words.what) + '</strong>' + (words.detail ? '<span class="au-detail">' + esc(words.detail) + '</span>' : '') +
|
|
217
|
+
'<span class="au-where">' + (e.by ? esc(e.by) + DOT : '') + esc(where) + '</span></span>' +
|
|
218
|
+
'<a class="au-open" href="' + esc(link.href) + '">' + esc(link.text) + ' ' + String.fromCharCode(8594) + '</a></div>';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function caseRow(c) {
|
|
222
|
+
var pill = c.status === 'done' ? ['good', 'Done'] : c.status === 'error' ? ['bad', 'Failed'] : c.status === 'awaiting_approval' ? ['warn', 'Waiting'] : ['run', 'Running'];
|
|
223
|
+
return '<div class="au-row au-case"><span class="au-state ' + pill[0] + '">' + pill[1] + '</span>' +
|
|
224
|
+
'<span class="au-what"><strong>' + esc(c.workflowTitle) + (c.inputs ? DOT + esc(c.inputs) : '') + '</strong>' +
|
|
225
|
+
(c.outcome ? '<span class="au-detail">' + esc(c.outcome) + '</span>' : '') +
|
|
226
|
+
'<span class="au-where">' + esc(when(c.startedAt)) + DOT + esc(agentLabel(c.agent)) + (c.briefVersion ? DOT + 'brief v' + c.briefVersion : '') + (c.people.length ? DOT + 'decided by ' + esc(c.people.join(', ')) : '') + '</span></span>' +
|
|
227
|
+
'<a class="au-open" href="/inbox?case=' + encodeURIComponent(c.id) + '">Open ' + String.fromCharCode(8594) + '</a></div>';
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function load(append) {
|
|
231
|
+
var url = state.tab === 'cases' ? '/audit/cases?' : '/audit/events?';
|
|
232
|
+
var extra = append && next != null ? { before: String(next) } : {};
|
|
233
|
+
if (state.tab === 'activity') extra.limit = '100';
|
|
234
|
+
if (!append) list.innerHTML = '<p class="hint">Loading' + String.fromCharCode(8230) + '</p>';
|
|
235
|
+
more.hidden = true;
|
|
236
|
+
return fetch(url + query(extra), { headers: { accept: 'application/json' } })
|
|
237
|
+
.then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
|
|
238
|
+
.then(function (data) {
|
|
239
|
+
var rows = state.tab === 'cases' ? data.cases.map(caseRow) : data.events.map(eventRow);
|
|
240
|
+
next = data.next;
|
|
241
|
+
if (state.tab === 'activity' && data.events.length < 100) next = null;
|
|
242
|
+
var box = list.querySelector('.au-list');
|
|
243
|
+
if (append && box) box.insertAdjacentHTML('beforeend', rows.join(''));
|
|
244
|
+
else list.innerHTML = rows.length ? '<div class="au-list">' + rows.join('') + '</div>'
|
|
245
|
+
: '<div class="au-list"><p class="au-empty">' + (state.tab === 'cases' ? 'No cases match.' : 'Nothing matches. Changes to settings, and every approval, answer and feedback, are listed here as they happen.') + '</p></div>';
|
|
246
|
+
more.hidden = next == null;
|
|
247
|
+
})
|
|
248
|
+
.catch(function (err) { list.innerHTML = '<p class="error">Could not load it: ' + esc(err.message) + '</p>'; });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function fillWorkflows() {
|
|
252
|
+
var shown = filters.workflows.filter(function (w) { return !state.agent || w.agent === state.agent; });
|
|
253
|
+
el.workflow.innerHTML = '<option value="">All workflows</option>' + shown.map(function (w) {
|
|
254
|
+
return '<option value="' + esc(w.id) + '"' + (w.id === state.workflow ? ' selected' : '') + '>' + esc(w.title) + (state.agent ? '' : ' (' + esc(agentLabel(w.agent)) + ')') + '</option>';
|
|
255
|
+
}).join('');
|
|
256
|
+
if (state.workflow && !shown.some(function (w) { return w.id === state.workflow; })) state.workflow = '';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function sync() {
|
|
260
|
+
var tabs = document.querySelectorAll('.au-tabs button');
|
|
261
|
+
for (var i = 0; i < tabs.length; i++) tabs[i].setAttribute('aria-selected', String(tabs[i].getAttribute('data-tab') === state.tab));
|
|
262
|
+
el.kind.hidden = state.tab !== 'activity';
|
|
263
|
+
el.status.hidden = state.tab !== 'cases';
|
|
264
|
+
el.exportLink.hidden = state.tab !== 'activity';
|
|
265
|
+
verifyBtn.hidden = state.tab !== 'activity';
|
|
266
|
+
el.exportLink.href = '/audit/events.csv?' + query();
|
|
267
|
+
remember();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// With a workflow chosen: its audit for the period, in sentences, and
|
|
271
|
+
// its report.
|
|
272
|
+
var summaryBox = document.getElementById('auSummary');
|
|
273
|
+
function loadSummary() {
|
|
274
|
+
var wf = state.workflow && filters.workflows.filter(function (w) { return w.id === state.workflow && (!state.agent || w.agent === state.agent); })[0];
|
|
275
|
+
if (!wf) { summaryBox.hidden = true; return; }
|
|
276
|
+
var q = new URLSearchParams();
|
|
277
|
+
q.set('since', state.period ? new Date(Date.now() - Number(state.period) * 86400000).toISOString() : '2000-01-01T00:00:00.000Z');
|
|
278
|
+
var base = '/agents/' + encodeURIComponent(wf.agent) + '/workflows/' + encodeURIComponent(wf.id) + '/audit';
|
|
279
|
+
summaryBox.hidden = false;
|
|
280
|
+
summaryBox.innerHTML = '<h2>' + esc(wf.title) + '</h2><p class="hint">Loading its audit' + String.fromCharCode(8230) + '</p>';
|
|
281
|
+
fetch(base + '?' + q.toString(), { headers: { accept: 'application/json' } })
|
|
282
|
+
.then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
|
|
283
|
+
.then(function (a) {
|
|
284
|
+
if (state.workflow !== wf.id) return;
|
|
285
|
+
var period = el.period.options[el.period.selectedIndex].text.toLowerCase();
|
|
286
|
+
summaryBox.innerHTML = '<h2>' + esc(wf.title) + ' <span class="hint">' + esc(period) + '</span></h2>' +
|
|
287
|
+
'<ul>' + a.summary.map(function (line) { return '<li>' + esc(line) + '</li>'; }).join('') + '</ul>' +
|
|
288
|
+
'<div class="au-summary-tools"><a class="primary" href="' + base + '/report?' + q.toString() + '">Open the report</a>' +
|
|
289
|
+
'<a href="' + base + '/report?' + q.toString() + '&format=json" download>Download JSON</a>' +
|
|
290
|
+
'<a href="' + workflowHref(wf.agent, wf.id, '') + '">Open the workflow</a></div>';
|
|
291
|
+
})
|
|
292
|
+
.catch(function (err) { summaryBox.innerHTML = '<p class="error">Could not load its audit: ' + esc(err.message) + '</p>'; });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function changed() { sync(); load(false); loadSummary(); }
|
|
296
|
+
|
|
297
|
+
document.querySelector('.au-tabs').addEventListener('click', function (ev) {
|
|
298
|
+
var b = ev.target.closest('button[data-tab]');
|
|
299
|
+
if (!b || b.getAttribute('data-tab') === state.tab) return;
|
|
300
|
+
state.tab = b.getAttribute('data-tab');
|
|
301
|
+
changed();
|
|
302
|
+
});
|
|
303
|
+
el.agent.addEventListener('change', function () { state.agent = el.agent.value; fillWorkflows(); changed(); });
|
|
304
|
+
['workflow', 'by', 'kind', 'status', 'period'].forEach(function (k) {
|
|
305
|
+
el[k].addEventListener('change', function () { state[k] = el[k].value; changed(); });
|
|
306
|
+
});
|
|
307
|
+
var typing;
|
|
308
|
+
el.q.addEventListener('input', function () {
|
|
309
|
+
clearTimeout(typing);
|
|
310
|
+
typing = setTimeout(function () { state.q = el.q.value.trim(); changed(); }, 300);
|
|
311
|
+
});
|
|
312
|
+
more.addEventListener('click', function () { load(true); });
|
|
313
|
+
|
|
314
|
+
// Checks every event's hash, in order, and the anchors sent away.
|
|
315
|
+
var verifyBtn = document.getElementById('auVerify');
|
|
316
|
+
var check = document.getElementById('auCheck');
|
|
317
|
+
var PROBLEMS = {
|
|
318
|
+
'changed': 'it was changed after it was recorded',
|
|
319
|
+
'missing-before': 'an event before it was removed, or the order changed',
|
|
320
|
+
'missing-after-anchor': 'events up to an anchored point are missing',
|
|
321
|
+
'anchor-differs': 'it no longer matches the hash anchored for it',
|
|
322
|
+
};
|
|
323
|
+
verifyBtn.addEventListener('click', function () {
|
|
324
|
+
verifyBtn.disabled = true;
|
|
325
|
+
check.hidden = false;
|
|
326
|
+
check.className = 'au-check';
|
|
327
|
+
check.textContent = 'Checking every event' + String.fromCharCode(8230);
|
|
328
|
+
fetch('/audit/verify', { headers: { accept: 'application/json' } })
|
|
329
|
+
.then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
|
|
330
|
+
.then(function (v) {
|
|
331
|
+
var anchors = v.anchors ? v.anchors + ' anchor' + (v.anchors === 1 ? '' : 's') + ' kept at ' + v.anchoredAt + ' match' + (v.anchors === 1 ? 'es' : '') : 'no anchors yet (one is sent each day)';
|
|
332
|
+
var note = v.anchorsNote ? '<span class="hint">Anchors checked are this workspace' + String.fromCharCode(8217) + 's own: ' + esc(v.anchorsNote) + '.</span>' : '';
|
|
333
|
+
if (v.ok) {
|
|
334
|
+
check.innerHTML = 'Intact: all ' + v.events.toLocaleString() + ' events check out, and ' + anchors + '.' +
|
|
335
|
+
(v.last ? '<span class="hint">Latest event #' + v.last.id + ', ' + esc(when(v.last.at)) + DOT + 'hash ' + esc(v.last.hash.slice(0, 16)) + String.fromCharCode(8230) + '</span>' : '') + note;
|
|
336
|
+
} else {
|
|
337
|
+
check.className = 'au-check bad';
|
|
338
|
+
check.innerHTML = 'Broken at event #' + v.broken.id + (v.broken.at ? ' (' + esc(when(v.broken.at)) + ')' : '') + ': ' + esc(PROBLEMS[v.broken.problem] || v.broken.problem) + '.' +
|
|
339
|
+
'<span class="hint">' + v.events.toLocaleString() + ' events before it check out.</span>' + note;
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
.catch(function (err) { check.className = 'au-check bad'; check.textContent = 'Could not check: ' + err.message; })
|
|
343
|
+
.then(function () { verifyBtn.disabled = false; });
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
el.q.value = state.q;
|
|
347
|
+
el.kind.value = state.kind;
|
|
348
|
+
el.status.value = state.status;
|
|
349
|
+
el.period.value = state.period;
|
|
350
|
+
function fillFilters(f) {
|
|
351
|
+
filters = f;
|
|
352
|
+
el.agent.innerHTML = '<option value="">All agents</option>' + f.agents.map(function (a) { return '<option value="' + esc(a.name) + '"' + (a.name === state.agent ? ' selected' : '') + '>' + esc(a.label) + '</option>'; }).join('');
|
|
353
|
+
el.by.innerHTML = '<option value="">Anyone</option>' + f.people.map(function (p) { return '<option value="' + esc(p) + '"' + (p === state.by ? ' selected' : '') + '>' + esc(p) + '</option>'; }).join('');
|
|
354
|
+
fillWorkflows();
|
|
355
|
+
}
|
|
356
|
+
if (embedded) {
|
|
357
|
+
fillFilters(embedded);
|
|
358
|
+
changed();
|
|
359
|
+
} else {
|
|
360
|
+
// The list doesn't wait for the choices; its rows are named again once
|
|
361
|
+
// they come.
|
|
362
|
+
changed();
|
|
363
|
+
fetch('/audit/filters', { headers: { accept: 'application/json' } })
|
|
364
|
+
.then(function (r) { return r.ok ? r.json() : null; })
|
|
365
|
+
.catch(function () { return null; })
|
|
366
|
+
.then(function (f) { if (f) { fillFilters(f); load(false); } });
|
|
367
|
+
}
|
|
368
|
+
})();
|
|
369
|
+
</script>
|
|
370
|
+
</body>
|
|
371
|
+
</html>`;
|
package/dist/web/change-log.js
CHANGED
|
@@ -34,6 +34,7 @@ const LABELS = [
|
|
|
34
34
|
[/^\/agents\/[^/]+\/abilities/, 'Changed abilities'],
|
|
35
35
|
[/^\/agents\/[^/]+\/notifier/, 'Changed the messaging app'],
|
|
36
36
|
[/^\/agents\/[^/]+\/env/, 'Changed agent secrets'],
|
|
37
|
+
[/^\/config\/policies\/versions\/(\d+)\/restore$/, (_method, m) => `Restored shared policies version ${m[1]}`],
|
|
37
38
|
[/^\/config\/policies$/, 'Changed shared policies'],
|
|
38
39
|
[/^\/config\/models/, 'Changed models'],
|
|
39
40
|
[/^\/config\/time-zone$/, 'Changed the time zone'],
|
|
@@ -32,9 +32,11 @@ const AGENTS_ICON = '<svg class="le-nav-icon" viewBox="3 3 18 18" fill="currentC
|
|
|
32
32
|
const WORKFLOWS_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="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/><path d="M10 6.5h4a3.5 3.5 0 0 1 3.5 3.5v4"/><path d="M14 17.5h-4A3.5 3.5 0 0 1 6.5 14v-4"/></svg>';
|
|
33
33
|
// An inbox tray, for the Inbox.
|
|
34
34
|
const INBOX_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"><polyline points="22 12 16 12 14 15 10 15 8 12 2 12"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/></svg>';
|
|
35
|
+
// A clipboard with a tick, for Audit.
|
|
36
|
+
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>';
|
|
35
37
|
// A gear, for Settings.
|
|
36
38
|
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>';
|
|
37
|
-
// Two columns: the sections (Inbox, Agents, Workflows, Settings), and
|
|
39
|
+
// Two columns: the sections (Inbox, Agents, Workflows, Audit, Settings), and
|
|
38
40
|
// beside them what's in the current one. Goals and Jobs stay at /goals
|
|
39
41
|
// and /jobs, out of the menu: LoopEngine is about workflows. Pointing at
|
|
40
42
|
// another section shows its column instead, until the pointer leaves.
|
|
@@ -46,6 +48,7 @@ export const consoleSidebarHtml = `<aside class="le-sidebar" aria-label="Console
|
|
|
46
48
|
<a class="le-rail-item" href="/inbox" data-le-nav-head="inbox" data-le-section="inbox">${INBOX_ICON}<span>Inbox</span><span class="le-pill warn le-inbox-count" id="leInboxCount" hidden></span></a>
|
|
47
49
|
<a class="le-rail-item" href="/agents" data-le-nav-head="agents" data-le-section="agents">${AGENTS_ICON}<span>Agents</span></a>
|
|
48
50
|
<a class="le-rail-item" href="/workflows" data-le-nav-head="workflows" data-le-section="workflows">${WORKFLOWS_ICON}<span>Workflows</span></a>
|
|
51
|
+
<a class="le-rail-item" href="/audit" data-le-nav-head="audit" data-le-section="audit">${AUDIT_ICON}<span>Audit</span></a>
|
|
49
52
|
<span class="le-rail-gap"></span>
|
|
50
53
|
<a class="le-rail-item" href="/config?section=settings" data-le-nav-head="settings" data-le-section="settings">${SETTINGS_ICON}<span>Settings</span></a>
|
|
51
54
|
<div class="le-who" id="leWho" hidden></div>
|
|
@@ -386,7 +389,8 @@ export const consoleShellScript = `<script>
|
|
|
386
389
|
: page === 'agents' || page === 'agent-config' || page === 'chat' || page === 'interview' ? 'agents'
|
|
387
390
|
: page === 'workflows' || page === 'workflows-overview' ? 'workflows'
|
|
388
391
|
: page === 'config' ? 'settings'
|
|
389
|
-
: page === 'inbox' ? 'inbox'
|
|
392
|
+
: page === 'inbox' ? 'inbox'
|
|
393
|
+
: page === 'audit' ? 'audit' : '';
|
|
390
394
|
var railItems = document.querySelectorAll('[data-le-section]');
|
|
391
395
|
for (var ri = 0; ri < railItems.length; ri++) {
|
|
392
396
|
if (railItems[ri].getAttribute('data-le-section') === section0) railItems[ri].classList.add('is-current');
|
|
@@ -70,6 +70,8 @@ export const devUiCss = `
|
|
|
70
70
|
cursor: pointer;
|
|
71
71
|
font-weight: 500;
|
|
72
72
|
}
|
|
73
|
+
select { cursor: pointer; }
|
|
74
|
+
select:disabled { cursor: default; }
|
|
73
75
|
button:hover:not(:disabled) { background: var(--surface); }
|
|
74
76
|
button[type="submit"], button.primary {
|
|
75
77
|
background: var(--accent);
|
|
@@ -29,6 +29,11 @@ export const globalConfigPageHtml = `<!doctype html>
|
|
|
29
29
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
30
30
|
<title>LoopEngine Settings</title>
|
|
31
31
|
<style>${devUiCss}
|
|
32
|
+
.policy-versions { margin-top: 12px; max-width: 720px; font-size: 13px; }
|
|
33
|
+
.policy-versions summary { cursor: pointer; font-weight: 600; color: var(--accent-ink); }
|
|
34
|
+
.policy-versions ol { list-style: none; margin: 10px 0 0; padding: 0 0 0 12px; border-left: 2px solid var(--line); display: grid; gap: 10px; }
|
|
35
|
+
.policy-versions pre { white-space: pre-wrap; margin: 4px 0 0; }
|
|
36
|
+
.policy-versions .link-btn { background: none; border: 0; padding: 0; height: auto; color: var(--accent-ink); font: inherit; font-weight: 600; cursor: pointer; }
|
|
32
37
|
section { margin-bottom: 28px; }
|
|
33
38
|
.provider-name { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
|
|
34
39
|
.le-provider-icon { width: 18px; height: 18px; flex: none; }
|
|
@@ -1184,7 +1189,9 @@ ${consoleShellScript}
|
|
|
1184
1189
|
'<textarea id="policiesText" rows="8" placeholder="- Refunds within 30 days of purchase. - Never share customer details with other customers. - Reply in the language the customer wrote in. - Sign emails: The Support Team">' + escapeHtml(p.policies || '') + '</textarea>' +
|
|
1185
1190
|
'<div><button type="submit" class="primary">Save</button></div>' +
|
|
1186
1191
|
'<div id="policiesMsg" class="hint"></div>' +
|
|
1187
|
-
'</form>'
|
|
1192
|
+
'</form>' +
|
|
1193
|
+
'<div id="policiesVersions" class="policy-versions"></div>';
|
|
1194
|
+
loadPolicyVersions();
|
|
1188
1195
|
var form = document.getElementById('policiesForm');
|
|
1189
1196
|
form.addEventListener('submit', function (ev) {
|
|
1190
1197
|
ev.preventDefault();
|
|
@@ -1197,11 +1204,44 @@ ${consoleShellScript}
|
|
|
1197
1204
|
.then(function (r) {
|
|
1198
1205
|
btn.disabled = false;
|
|
1199
1206
|
msg.innerHTML = r.ok ? 'Saved. Every workflow' + String.fromCharCode(8217) + 's next run reads them.' : '<span class="error">' + escapeHtml(r.body.error || 'Could not save') + '</span>';
|
|
1207
|
+
if (r.ok) loadPolicyVersions();
|
|
1200
1208
|
})
|
|
1201
1209
|
.catch(function (err) { btn.disabled = false; msg.innerHTML = '<span class="error">' + escapeHtml(err.message) + '</span>'; });
|
|
1202
1210
|
});
|
|
1203
1211
|
}
|
|
1204
1212
|
|
|
1213
|
+
// Every saved version of the policies: who saved it, when and why; any
|
|
1214
|
+
// earlier one can be read or restored (saved as a new version).
|
|
1215
|
+
function loadPolicyVersions() {
|
|
1216
|
+
var box = document.getElementById('policiesVersions');
|
|
1217
|
+
if (!box) return;
|
|
1218
|
+
fetch('/config/policies/versions', { cache: 'no-store' })
|
|
1219
|
+
.then(function (r) { return r.ok ? r.json() : null; })
|
|
1220
|
+
.then(function (data) {
|
|
1221
|
+
var versions = (data && data.versions) || [];
|
|
1222
|
+
if (versions.length < 2) { box.innerHTML = ''; return; }
|
|
1223
|
+
var when = function (v) { return new Date(v.at).toLocaleString(undefined, { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' }); };
|
|
1224
|
+
box.innerHTML = '<details><summary>History (' + versions.length + ' versions)</summary><ol>' + versions.map(function (v) {
|
|
1225
|
+
var current = v.number === data.current;
|
|
1226
|
+
return '<li data-version="' + v.number + '"><div><strong>v' + v.number + '</strong> <span class="hint">' + [v.by ? 'by ' + escapeHtml(v.by) : '', escapeHtml(when(v)), v.reason ? escapeHtml(v.reason) : ''].filter(Boolean).join(' ' + String.fromCharCode(183) + ' ') + '</span>' +
|
|
1227
|
+
(current ? ' <span class="le-pill good">In use</span>' : ' <button type="button" class="link-btn" data-restore>Restore</button>') + '</div>' +
|
|
1228
|
+
'<pre class="hint">' + escapeHtml(v.content || '(empty)') + '</pre></li>';
|
|
1229
|
+
}).join('') + '</ol></details>';
|
|
1230
|
+
box.querySelectorAll('[data-restore]').forEach(function (btn) {
|
|
1231
|
+
btn.addEventListener('click', function () {
|
|
1232
|
+
if (btn.getAttribute('data-confirming') !== '1') { btn.setAttribute('data-confirming', '1'); btn.textContent = 'Click again to restore'; return; }
|
|
1233
|
+
btn.disabled = true;
|
|
1234
|
+
var n = btn.closest('li').getAttribute('data-version');
|
|
1235
|
+
fetch('/config/policies/versions/' + n + '/restore', { method: 'POST' })
|
|
1236
|
+
.then(function (r) { return r.json().then(function (b) { if (!r.ok) throw new Error(b.error || 'Could not restore'); }); })
|
|
1237
|
+
.then(loadPolicies)
|
|
1238
|
+
.catch(function (err) { btn.disabled = false; btn.textContent = err.message; });
|
|
1239
|
+
});
|
|
1240
|
+
});
|
|
1241
|
+
})
|
|
1242
|
+
.catch(function () {});
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1205
1245
|
function loadPolicies() {
|
|
1206
1246
|
if (!document.getElementById('policiesBox')) return;
|
|
1207
1247
|
fetch('/config/policies', { cache: 'no-store' })
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WorkflowAudit } from './workflow-audit.js';
|
|
2
|
+
export declare function workflowAuditReportHtml(audit: WorkflowAudit, options: {
|
|
3
|
+
generatedAt: string;
|
|
4
|
+
by: string;
|
|
5
|
+
jsonHref: string;
|
|
6
|
+
caseHref: (runId: string) => string;
|
|
7
|
+
pageHref: string;
|
|
8
|
+
}): string;
|