loopengine 0.5.1 → 0.5.2

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.
@@ -6,8 +6,27 @@ export declare function eventText(e: AuditEvent): {
6
6
  what: string;
7
7
  detail: string;
8
8
  };
9
+ /** Who did what to which resource: what the event did, as "<resource>
10
+ * <done>" (Workflow published, Schedule deleted), and the resource it
11
+ * did it to. Read from the request a change kept (its method and path),
12
+ * so older events, logged with other labels, read the same way. */
13
+ export interface EventAction {
14
+ action: string;
15
+ resource: {
16
+ type: string;
17
+ name: string;
18
+ agent?: string;
19
+ workflowId?: string;
20
+ runId?: string;
21
+ };
22
+ }
23
+ export interface EventNames {
24
+ agentLabel(agent: string): string;
25
+ workflowTitle(agent: string, workflowId: string): string | undefined;
26
+ }
27
+ export declare function eventAction(e: AuditEvent, names?: EventNames): EventAction;
9
28
  /** The events as a CSV file, one row each, in the order given. */
10
- export declare function eventsCsv(events: AuditEvent[]): string;
29
+ export declare function eventsCsv(events: AuditEvent[], names?: EventNames): string;
11
30
  /** A case in the Cases list. */
12
31
  export interface AuditCaseRow {
13
32
  id: string;
@@ -25,17 +25,97 @@ export function eventText(e) {
25
25
  const edit = d.edit === 'none' ? 'used unedited' : d.edit ? `${str(d.edit)} edits` : '';
26
26
  return { what: `Feedback${verdict || edit ? `: ${[verdict, edit].filter(Boolean).join(', ')}` : ''}`, detail: str(d.note) };
27
27
  }
28
- const CSV_COLUMNS = ['When (UTC)', 'Kind', 'Person', 'Agent', 'Workflow', 'What', 'Detail', 'Case', 'Event', 'Hash'];
28
+ const PLAIN_NAMES = { agentLabel: (a) => a, workflowTitle: () => undefined };
29
+ // Each kind of change: its path, and what it did by method.
30
+ const ACTIONS = [
31
+ [/^\/workflows\/create$/, 'Workflow', () => 'created'],
32
+ [/^\/agents$/, 'Agent', () => 'created'],
33
+ [/^\/agents\/[^/]+$/, 'Agent', (method) => (method === 'DELETE' ? 'deleted' : 'updated')],
34
+ [/^\/agents\/[^/]+\/workflows$/, 'Workflow', () => 'created'],
35
+ [/^\/agents\/[^/]+\/workflows\/[^/]+$/, 'Workflow', (method) => (method === 'DELETE' ? 'deleted' : 'edited')],
36
+ [/^\/agents\/[^/]+\/workflows\/[^/]+\/publish$/, 'Workflow', () => 'published'],
37
+ [/^\/agents\/[^/]+\/workflows\/[^/]+\/versions\/(\d+)\/restore$/, 'Workflow', (_method, m) => `version ${m[1]} restored`],
38
+ [/^\/agents\/[^/]+\/workflows\/[^/]+\/messages$/, 'Workflow messaging', () => 'changed'],
39
+ [/^\/agents\/[^/]+\/workflows\/[^/]+\/triggers/, 'Webhook', (method) => (method === 'POST' ? 'created' : method === 'DELETE' ? 'deleted' : 'updated')],
40
+ [/^\/agents\/[^/]+\/workflows\/[^/]+\/evals\/criteria/, 'Success criteria', () => 'changed'],
41
+ [/^\/agents\/[^/]+\/workflows\/[^/]+\/evals/, 'Eval case', (method) => (method === 'POST' ? 'added' : method === 'DELETE' ? 'removed' : 'updated')],
42
+ [/^\/agents\/[^/]+\/schedules/, 'Schedule', (method) => (method === 'POST' ? 'created' : method === 'DELETE' ? 'deleted' : 'updated')],
43
+ [/^\/schedules\//, 'Schedule', (method) => (method === 'DELETE' ? 'deleted' : 'updated')],
44
+ [/^\/agents\/[^/]+\/actauth/, 'Permissions', () => 'changed'],
45
+ [/^\/agents\/[^/]+\/tools\/http/, 'HTTP tool', (method) => (method === 'POST' ? 'added' : method === 'DELETE' ? 'removed' : 'updated')],
46
+ [/^\/agents\/[^/]+\/gateway-tools/, 'App tools', () => 'changed'],
47
+ [/^\/agents\/[^/]+\/apps\//, 'App', (method) => (method === 'DELETE' ? 'removed' : 'changed')],
48
+ [/^\/agents\/[^/]+\/skills\//, 'Skill', (method) => (method === 'POST' ? 'added' : method === 'DELETE' ? 'removed' : 'updated')],
49
+ [/^\/agents\/[^/]+\/abilities/, 'Abilities', () => 'changed'],
50
+ [/^\/agents\/[^/]+\/notifier/, 'Messaging app', () => 'changed'],
51
+ [/^\/agents\/[^/]+\/env/, 'Agent secrets', () => 'changed'],
52
+ [/^\/config\/policies\/versions\/(\d+)\/restore$/, 'Shared policies', (_method, m) => `version ${m[1]} restored`],
53
+ [/^\/config\/policies$/, 'Shared policies', () => 'changed'],
54
+ [/^\/config\/models/, 'Models', () => 'changed'],
55
+ [/^\/config\/time-zone$/, 'Time zone', () => 'changed'],
56
+ [/^\/config\/apps/, 'Workspace apps', () => 'changed'],
57
+ [/^\/config\/gateways/, 'App gateway', () => 'changed'],
58
+ [/^\/config\/upgrade$/, 'LoopEngine', () => 'upgraded'],
59
+ [/^\/abilities\//, 'Workspace abilities', () => 'changed'],
60
+ ];
61
+ // Of an agent or a workflow, where the resource is a part of one.
62
+ const AGENT_PARTS = new Set(['Permissions', 'HTTP tool', 'App tools', 'App', 'Skill', 'Abilities', 'Messaging app', 'Agent secrets', 'Schedule']);
63
+ const WORKFLOW_PARTS = new Set(['Workflow messaging', 'Webhook', 'Success criteria', 'Eval case']);
64
+ export function eventAction(e, names = PLAIN_NAMES) {
65
+ const d = e.data;
66
+ const str = (v) => (typeof v === 'string' ? v : '');
67
+ // A workflow by its name now, or (deleted) as it was, or its id.
68
+ const workflowName = (agent, id) => {
69
+ const was = Array.isArray(d.changes) ? d.changes.find((c) => c.field === 'title')?.from : undefined;
70
+ return names.workflowTitle(agent, id) || str(d.title) || (was && was !== '(none)' ? was : '') || id;
71
+ };
72
+ const run = { type: 'Run', name: e.workflow_id ? workflowName(e.agent, e.workflow_id) : 'One-off job', agent: e.agent, ...(e.workflow_id ? { workflowId: e.workflow_id } : {}), ...(e.run_id ? { runId: e.run_id } : {}) };
73
+ if (e.kind === 'decision')
74
+ return { action: d.approved ? (d.edited ? 'Tool call approved with changes' : 'Tool call approved') : 'Tool call denied', resource: run };
75
+ if (e.kind === 'answer')
76
+ return { action: 'Question answered', resource: run };
77
+ if (e.kind === 'feedback')
78
+ return { action: 'Feedback given', resource: run };
79
+ const method = str(d.method).toUpperCase();
80
+ const path = str(d.path);
81
+ const workflow = e.workflow_id ? { workflowId: e.workflow_id } : {};
82
+ for (const [pattern, type, done] of ACTIONS) {
83
+ const m = path.match(pattern);
84
+ if (!m)
85
+ continue;
86
+ const action = `${type} ${done(method, m)}`;
87
+ if (type === 'Workflow' && e.workflow_id)
88
+ return { action, resource: { type: 'Workflow', name: workflowName(e.agent, e.workflow_id), agent: e.agent, ...workflow } };
89
+ if (type === 'Workflow')
90
+ return { action, resource: { type: 'Workflow', name: str(d.title) || 'New workflow', ...(e.agent ? { agent: e.agent } : {}) } };
91
+ if (WORKFLOW_PARTS.has(type) && e.workflow_id)
92
+ return { action, resource: { type, name: workflowName(e.agent, e.workflow_id), agent: e.agent, ...workflow } };
93
+ if (type === 'Agent' || AGENT_PARTS.has(type)) {
94
+ const agent = e.agent || (type === 'Agent' && d.body && typeof d.body === 'object' ? str(d.body.name) : '');
95
+ return { action, resource: { type: type === 'Agent' ? 'Agent' : type, name: agent ? names.agentLabel(agent) : 'Workspace', ...(agent ? { agent } : {}) } };
96
+ }
97
+ return { action, resource: { type: 'Workspace', name: type } };
98
+ }
99
+ // A change with no request kept: its label, and where it was.
100
+ const label = str(d.label) || 'Setting changed';
101
+ if (e.workflow_id)
102
+ return { action: label, resource: { type: 'Workflow', name: workflowName(e.agent, e.workflow_id), agent: e.agent, ...workflow } };
103
+ if (e.agent)
104
+ return { action: label, resource: { type: 'Agent', name: names.agentLabel(e.agent), agent: e.agent } };
105
+ return { action: label, resource: { type: 'Workspace', name: 'Settings' } };
106
+ }
107
+ const CSV_COLUMNS = ['When (UTC)', 'Person', 'Action', 'Resource type', 'Resource', 'Kind', 'Agent', 'Workflow', 'What', 'Detail', 'Case', 'Event', 'Hash'];
29
108
  function csvCell(value) {
30
109
  // A leading = + - @ would run as a formula in a spreadsheet.
31
110
  const safe = /^[=+\-@]/.test(value) ? `'${value}` : value;
32
111
  return /[",\n\r]/.test(safe) ? `"${safe.replace(/"/g, '""')}"` : safe;
33
112
  }
34
113
  /** The events as a CSV file, one row each, in the order given. */
35
- export function eventsCsv(events) {
114
+ export function eventsCsv(events, names = PLAIN_NAMES) {
36
115
  const rows = events.map((e) => {
37
116
  const { what, detail } = eventText(e);
38
- return [e.at, e.kind, e.by ?? '', e.agent, e.workflow_id ?? '', what, detail, e.run_id ?? '', String(e.id), e.hash ?? ''].map(csvCell).join(',');
117
+ const { action, resource } = eventAction(e, names);
118
+ return [e.at, e.by ?? '', action, resource.type, resource.name, e.kind, e.agent, e.workflow_id ?? '', what, detail, e.run_id ?? '', String(e.id), e.hash ?? ''].map(csvCell).join(',');
39
119
  });
40
120
  return [CSV_COLUMNS.join(','), ...rows].join('\r\n') + '\r\n';
41
121
  }
@@ -1,7 +1,10 @@
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
1
+ // The console's Audit page (/audit): the workspace's audit log, a record
2
+ // of who did what, when, and to which resource: workflows created, edited,
3
+ // published and deleted, schedules, webhooks, permissions and settings
4
+ // changed, and (filtered for) approvals, answers and feedback in runs.
5
+ // Runs themselves are on each workflow's Activity tab. Its data is
6
+ // web/audit-admin.ts's, behind /audit/events, /audit/events.csv and
7
+ // /audit/filters. Owners, admins and
5
8
  // editors see it; approvers and viewers use the Inbox only. Like the
6
9
  // other console pages, its inline script avoids backslashes and template
7
10
  // placeholders, since it lives inside a template literal.
@@ -21,9 +24,6 @@ export const auditPageHtml = `<!doctype html>
21
24
  <title>Audit</title>
22
25
  <style>${devUiCss}
23
26
  .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
27
  .au-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
28
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
29
  .au-bar input[type="search"] { flex: 1; min-width: 160px; max-width: none; }
@@ -34,6 +34,7 @@ export const auditPageHtml = `<!doctype html>
34
34
  .au-check.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
35
35
  .au-check .hint { display: block; margin-top: 2px; font-weight: 400; }
36
36
  .au-summary { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 10px; background: var(--bg); }
37
+ .au-summary[hidden], .au-check[hidden] { display: none; }
37
38
  .au-summary h2 { margin: 0; font-size: 15px; }
38
39
  .au-summary ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 13.5px; line-height: 1.5; }
39
40
  .au-summary-tools { display: flex; gap: 8px; flex-wrap: wrap; }
@@ -41,8 +42,16 @@ export const auditPageHtml = `<!doctype html>
41
42
  .au-summary-tools a.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
42
43
  .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
44
  .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; }
45
+ .au-row, .au-head { display: grid; grid-template-columns: 136px minmax(0, 170px) minmax(0, 1.2fr) minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 13px; }
46
+ .au-head { border-top: 0; padding-top: 8px; padding-bottom: 8px; background: var(--surface); font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); }
47
+ .au-who { overflow-wrap: anywhere; }
48
+ .au-who.system { color: var(--ink-muted); font-style: italic; }
49
+ .au-res { display: grid; gap: 1px; min-width: 0; }
50
+ .au-res-type { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); }
51
+ .au-res a { color: var(--accent-ink); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
52
+ .au-res a:hover { text-decoration: underline; }
53
+ .au-res .hint { font-size: 12px; }
54
+ .au-what details summary { cursor: pointer; color: var(--accent-ink); font-size: 12px; }
46
55
  .au-when { color: var(--ink-muted); white-space: nowrap; font-size: 12.5px; }
47
56
  .au-kind { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); }
48
57
  .au-kind.change { color: var(--accent-ink); }
@@ -53,13 +62,7 @@ export const auditPageHtml = `<!doctype html>
53
62
  .au-where { font-size: 12.5px; color: var(--ink-muted); }
54
63
  .au-open { color: var(--accent-ink); font-weight: 600; text-decoration: none; white-space: nowrap; font-size: 12.5px; }
55
64
  .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-evalcase { color: var(--accent-ink); font-weight: 600; }
65
+ .au-action.denied { color: var(--bad); }
63
66
  .chg { display: grid; gap: 6px; margin-top: 4px; font-size: 12.5px; flex-basis: 100%; }
64
67
  .chg-field del { color: var(--bad); }
65
68
  .chg-field ins { color: var(--good); text-decoration: none; }
@@ -72,8 +75,8 @@ export const auditPageHtml = `<!doctype html>
72
75
  .au-more { justify-self: center; }
73
76
  .error { font-size: 13px; color: var(--bad); margin: 0; }
74
77
  @media (max-width: 720px) {
75
- .au-row, .au-case { grid-template-columns: minmax(0, 1fr) auto; }
76
- .au-when { grid-column: 1 / -1; }
78
+ .au-head { display: none; }
79
+ .au-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
77
80
  }
78
81
  </style>
79
82
  </head>
@@ -84,27 +87,17 @@ ${consoleSidebarHtml}
84
87
  <div class="le-head plain">
85
88
  <div class="le-head-row">
86
89
  <div class="le-title"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">&#9776;</button>
87
- <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>
90
+ <div><h1>Audit</h1><p>Who did what, when, and to which resource, across the workspace: workflows created, edited, published and deleted, and every other setting changed. Runs are on each workflow's Activity tab.</p></div>
88
91
  </div>
89
92
  </div>
90
93
  </div>
91
94
  <div class="le-scroll"><div class="le-page"><div class="au">
92
- <div class="au-tabs" role="tablist">
93
- <button type="button" role="tab" data-tab="activity" aria-selected="true">Activity</button>
94
- <button type="button" role="tab" data-tab="cases" aria-selected="false">Cases</button>
95
- </div>
96
95
  <div class="au-bar">
97
96
  <select id="auAgent" aria-label="Agent"><option value="">All agents</option></select>
98
97
  <select id="auWorkflow" aria-label="Workflow"><option value="">All workflows</option></select>
99
98
  <select id="auBy" aria-label="Person"><option value="">Anyone</option></select>
100
99
  <select id="auKind" aria-label="Kind">
101
- <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>
102
- </select>
103
- <select id="auFlag" aria-label="Worth a look" hidden>
104
- <option value="">Any case</option><option value="overruled">Denied or changed</option><option value="bad">Marked bad</option><option value="asked">Asked a question</option>
105
- </select>
106
- <select id="auStatus" aria-label="Status" hidden>
107
- <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>
100
+ <option value="change">Changes to workflows and settings</option><option value="decision">Approvals in runs</option><option value="answer">Answers in runs</option><option value="feedback">Feedback on runs</option><option value="all">Everything</option>
108
101
  </select>
109
102
  <select id="auPeriod" aria-label="Period">
110
103
  <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>
@@ -126,10 +119,11 @@ ${consoleShellScript}
126
119
  (function () {
127
120
  var DOT = ' ' + String.fromCharCode(183) + ' ';
128
121
  var params = new URLSearchParams(location.search);
122
+ // Changes by default: who did what to which workflow or setting.
123
+ var KINDS = ['change', 'decision', 'answer', 'feedback', 'all'];
129
124
  var state = {
130
- tab: params.get('tab') === 'cases' ? 'cases' : 'activity',
131
125
  agent: params.get('agent') || '', workflow: params.get('workflow') || '', by: params.get('by') || '',
132
- kind: params.get('kind') || '', status: params.get('status') || '', flag: params.get('flag') || '',
126
+ kind: KINDS.indexOf(params.get('kind')) >= 0 ? params.get('kind') : 'change',
133
127
  period: params.has('period') ? params.get('period') : '30', q: params.get('q') || '',
134
128
  };
135
129
  // The filters' choices come with the page (auditPageFor), so they show
@@ -141,7 +135,7 @@ ${consoleShellScript}
141
135
  var more = document.getElementById('auMore');
142
136
  var el = {
143
137
  agent: document.getElementById('auAgent'), workflow: document.getElementById('auWorkflow'), by: document.getElementById('auBy'),
144
- kind: document.getElementById('auKind'), status: document.getElementById('auStatus'), flag: document.getElementById('auFlag'), period: document.getElementById('auPeriod'),
138
+ kind: document.getElementById('auKind'), period: document.getElementById('auPeriod'),
145
139
  q: document.getElementById('auQ'), exportLink: document.getElementById('auExport'),
146
140
  };
147
141
 
@@ -176,9 +170,7 @@ ${consoleShellScript}
176
170
  if (state.agent) q.set('agent', state.agent);
177
171
  if (state.workflow) q.set('workflow', state.workflow);
178
172
  if (state.by) q.set('by', state.by);
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.tab === 'cases' && state.flag) q.set('flag', state.flag);
173
+ if (state.kind !== 'all') q.set('kind', state.kind);
182
174
  if (state.period) q.set('since', new Date(Date.now() - Number(state.period) * 86400000).toISOString());
183
175
  if (state.q) q.set('q', state.q);
184
176
  Object.keys(extra || {}).forEach(function (k) { q.set(k, extra[k]); });
@@ -187,27 +179,31 @@ ${consoleShellScript}
187
179
  // The page's own address keeps the filters, so a view can be shared.
188
180
  function remember() {
189
181
  var q = new URLSearchParams();
190
- if (state.tab === 'cases') q.set('tab', 'cases');
191
182
  ['agent', 'workflow', 'by', 'q'].forEach(function (k) { if (state[k]) q.set(k, state[k]); });
192
- if (state.tab === 'activity' && state.kind) q.set('kind', state.kind);
193
- if (state.tab === 'cases' && state.status) q.set('status', state.status);
194
- if (state.tab === 'cases' && state.flag) q.set('flag', state.flag);
183
+ if (state.kind !== 'change') q.set('kind', state.kind);
195
184
  if (state.period !== '30') q.set('period', state.period);
196
185
  history.replaceState(null, '', '/audit' + (q.toString() ? '?' + q.toString() : ''));
197
186
  }
198
187
 
199
- // Where an event leads: its case, the workflow's version or changes,
200
- // the agent, or the workspace setting.
201
- function eventLink(e) {
188
+ // The resource an event acted on (e.resource, from the server), as a
189
+ // link where it still exists: a run's trace, a workflow, an agent, or
190
+ // the workspace setting.
191
+ function resourceHtml(e) {
192
+ var r = e.resource || { type: 'Workspace', name: 'Settings' };
202
193
  var d = e.data || {};
203
- if (e.run_id) return { href: '/cases/' + encodeURIComponent(e.run_id) + '?back=' + encodeURIComponent(location.pathname + location.search), text: 'Case' };
204
- if (e.workflow_id) return { href: workflowHref(e.agent, e.workflow_id, /(brief|workflow) version/i.test(d.label || '') || /Edited the workflow|Published the workflow/.test(d.label || '') ? 'brief' : 'activity'), text: 'Workflow' };
205
- if (e.agent) return { href: '/agents/config?agent=' + encodeURIComponent(e.agent), text: 'Agent' };
206
- var path = String(d.path || '');
207
- if (path.indexOf('/config/models') === 0) return { href: '/config?section=models', text: 'Models' };
208
- if (path.indexOf('/config/apps') === 0) return { href: '/config?section=apps', text: 'Apps' };
209
- if (path.indexOf('/abilities') === 0) return { href: '/config?section=abilities', text: 'Abilities' };
210
- return { href: '/config?section=settings', text: 'Settings' };
194
+ var href = '';
195
+ if (r.runId && r.workflowId) href = workflowHref(r.agent, r.workflowId, 'activity') + '&run=' + encodeURIComponent(r.runId);
196
+ else if (r.runId) href = '/inbox?item=' + encodeURIComponent(r.runId);
197
+ else if (r.workflowId && /deleted$/.test(e.action || '')) href = '';
198
+ else if (r.workflowId) href = workflowHref(r.agent, r.workflowId, /published|restored|edited/.test(e.action || '') ? 'versions' : '');
199
+ else if (r.agent && !/deleted$/.test(e.action || '')) href = '/agents/config?agent=' + encodeURIComponent(r.agent);
200
+ else if (r.type === 'Workspace') {
201
+ var path = String(d.path || '');
202
+ href = path.indexOf('/config/models') === 0 ? '/config?section=models' : path.indexOf('/config/apps') === 0 ? '/config?section=apps' : path.indexOf('/abilities') === 0 ? '/config?section=abilities' : '/config?section=settings';
203
+ }
204
+ var name = esc(r.name) + (r.type === 'Run' && r.runId ? ' <span class="hint">run ' + esc(String(r.runId).slice(0, 8)) + '</span>' : '');
205
+ var where = r.agent && r.type !== 'Agent' && r.type !== 'Workspace' ? '<span class="hint">' + esc(agentLabel(r.agent)) + '</span>' : '';
206
+ return '<span class="au-res"><span class="au-res-type">' + esc(r.type) + '</span>' + (href ? '<a href="' + esc(href) + '">' + name + '</a>' : '<span>' + name + '</span>') + where + '</span>';
211
207
  }
212
208
 
213
209
  function eventWords(e) {
@@ -242,44 +238,39 @@ ${consoleShellScript}
242
238
  return '<div class="chg">' + rows + '</div>';
243
239
  }
244
240
 
241
+ // A row: when, who, what they did (with its detail and, for a change,
242
+ // what it changed), and the resource.
245
243
  function eventRow(e) {
246
244
  var words = eventWords(e);
247
- var link = eventLink(e);
248
- var kind = e.kind === 'change' ? 'Setting' : e.kind === 'decision' ? 'Approval' : e.kind === 'answer' ? 'Answer' : 'Feedback';
245
+ var detail = e.kind === 'change' ? '' : words.detail;
246
+ var changes = e.kind === 'change' ? changeDetailsHtml(e.data || {}) : '';
249
247
  var denied = e.kind === 'decision' && e.data && !e.data.approved ? ' denied' : '';
250
- var where = agentLabel(e.agent) + (e.workflow_id ? DOT + workflowTitle(e.agent, e.workflow_id) : '');
251
248
  return '<div class="au-row"><span class="au-when">' + esc(when(e.at)) + '</span>' +
252
- '<span class="au-kind ' + esc(e.kind) + denied + '">' + kind + '</span>' +
253
- '<span class="au-what"><strong>' + esc(words.what) + '</strong>' + (words.detail ? '<span class="au-detail">' + esc(words.detail) + '</span>' : '') + (e.kind === 'change' ? changeDetailsHtml(e.data || {}) : '') +
254
- '<span class="au-where">' + (e.by ? esc(e.by) + DOT : '') + esc(where) + '</span></span>' +
255
- '<a class="au-open" href="' + esc(link.href) + '">' + esc(link.text) + ' ' + String.fromCharCode(8594) + '</a></div>';
256
- }
257
-
258
- function caseRow(c) {
259
- var pill = c.status === 'done' ? ['good', 'Done'] : c.status === 'error' ? ['bad', 'Failed'] : c.status === 'awaiting_approval' ? ['warn', 'Waiting'] : ['run', 'Running'];
260
- return '<div class="au-row au-case"><span class="au-state ' + pill[0] + '">' + pill[1] + '</span>' +
261
- '<span class="au-what"><strong>' + esc(c.workflowTitle) + (c.inputs ? DOT + esc(c.inputs) : '') + '</strong>' +
262
- (c.outcome ? '<span class="au-detail">' + esc(c.outcome) + '</span>' : '') +
263
- '<span class="au-where">' + esc(when(c.startedAt)) + DOT + esc(agentLabel(c.agent)) + (c.workflowVersion ? DOT + 'workflow v' + c.workflowVersion : '') + (c.people.length ? DOT + 'decided by ' + esc(c.people.join(', ')) : '') + (c.evalCase ? DOT + '<span class="au-evalcase">eval case</span>' : '') + '</span></span>' +
264
- '<a class="au-open" href="/cases/' + encodeURIComponent(c.id) + '?back=' + encodeURIComponent(location.pathname + location.search) + '">Open ' + String.fromCharCode(8594) + '</a></div>';
249
+ '<span class="au-who' + (e.by ? '' : ' system') + '">' + esc(e.by || 'System') + '</span>' +
250
+ '<span class="au-what"><strong class="au-action' + denied + '">' + esc(e.action || words.what) + '</strong>' +
251
+ (e.kind === 'decision' && e.data && e.data.tool ? '<span class="au-detail"><code>' + esc(e.data.tool) + '</code></span>' : '') +
252
+ (detail ? '<span class="au-detail">' + esc(detail) + '</span>' : '') +
253
+ (changes ? '<details><summary>What changed</summary>' + changes + '</details>' : '') + '</span>' +
254
+ resourceHtml(e) + '</div>';
265
255
  }
266
256
 
257
+ var HEAD = '<div class="au-head"><span>When</span><span>Who</span><span>Action</span><span>Resource</span></div>';
267
258
  function load(append) {
268
- var url = state.tab === 'cases' ? '/audit/cases?' : '/audit/events?';
259
+ var url = '/audit/events?';
269
260
  var extra = append && next != null ? { before: String(next) } : {};
270
- if (state.tab === 'activity') extra.limit = '100';
261
+ extra.limit = '100';
271
262
  if (!append) list.innerHTML = '<p class="hint">Loading' + String.fromCharCode(8230) + '</p>';
272
263
  more.hidden = true;
273
264
  return fetch(url + query(extra), { headers: { accept: 'application/json' } })
274
265
  .then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
275
266
  .then(function (data) {
276
- var rows = state.tab === 'cases' ? data.cases.map(caseRow) : data.events.map(eventRow);
267
+ var rows = data.events.map(eventRow);
277
268
  next = data.next;
278
- if (state.tab === 'activity' && data.events.length < 100) next = null;
269
+ if (data.events.length < 100) next = null;
279
270
  var box = list.querySelector('.au-list');
280
271
  if (append && box) box.insertAdjacentHTML('beforeend', rows.join(''));
281
- else list.innerHTML = rows.length ? '<div class="au-list">' + rows.join('') + '</div>'
282
- : '<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>';
272
+ else list.innerHTML = rows.length ? '<div class="au-list">' + HEAD + rows.join('') + '</div>'
273
+ : '<div class="au-list"><p class="au-empty">Nothing matches. Workflows created, edited, published and deleted, and every other change to settings, are recorded here with who made them.</p></div>';
283
274
  more.hidden = next == null;
284
275
  })
285
276
  .catch(function (err) { list.innerHTML = '<p class="error">Could not load it: ' + esc(err.message) + '</p>'; });
@@ -294,13 +285,6 @@ ${consoleShellScript}
294
285
  }
295
286
 
296
287
  function sync() {
297
- var tabs = document.querySelectorAll('.au-tabs button');
298
- for (var i = 0; i < tabs.length; i++) tabs[i].setAttribute('aria-selected', String(tabs[i].getAttribute('data-tab') === state.tab));
299
- el.kind.hidden = state.tab !== 'activity';
300
- el.status.hidden = state.tab !== 'cases';
301
- el.flag.hidden = state.tab !== 'cases';
302
- el.exportLink.hidden = state.tab !== 'activity';
303
- verifyBtn.hidden = state.tab !== 'activity';
304
288
  el.exportLink.href = '/audit/events.csv?' + query();
305
289
  remember();
306
290
  }
@@ -332,14 +316,8 @@ ${consoleShellScript}
332
316
 
333
317
  function changed() { sync(); load(false); loadSummary(); }
334
318
 
335
- document.querySelector('.au-tabs').addEventListener('click', function (ev) {
336
- var b = ev.target.closest('button[data-tab]');
337
- if (!b || b.getAttribute('data-tab') === state.tab) return;
338
- state.tab = b.getAttribute('data-tab');
339
- changed();
340
- });
341
319
  el.agent.addEventListener('change', function () { state.agent = el.agent.value; fillWorkflows(); changed(); });
342
- ['workflow', 'by', 'kind', 'status', 'flag', 'period'].forEach(function (k) {
320
+ ['workflow', 'by', 'kind', 'period'].forEach(function (k) {
343
321
  el[k].addEventListener('change', function () { state[k] = el[k].value; changed(); });
344
322
  });
345
323
  var typing;
@@ -379,8 +357,6 @@ ${consoleShellScript}
379
357
 
380
358
  el.q.value = state.q;
381
359
  el.kind.value = state.kind;
382
- el.status.value = state.status;
383
- el.flag.value = state.flag;
384
360
  el.period.value = state.period;
385
361
  function fillFilters(f) {
386
362
  filters = f;
@@ -9,10 +9,12 @@
9
9
  // deciding, feedback) isn't: decisions and feedback are events of their
10
10
  // own. The request's body is kept with anything secret blanked, and the
11
11
  // brief's own before and after are its versions.
12
- // Doing, not changing. A workflow's draft isn't live until it's published.
12
+ // Doing, not changing. A workflow's draft (restoring a version makes one)
13
+ // isn't live until it's published.
13
14
  const NOT_CHANGES = [
14
15
  /^\/agents\/[^/]+\/messages(\/stream)?$/,
15
16
  /^\/agents\/[^/]+\/workflows\/[^/]+\/draft(\/.*)?$/,
17
+ /^\/agents\/[^/]+\/workflows\/[^/]+\/versions\/\d+\/restore$/,
16
18
  /\/(feedback|run|preview|test|evals\/run|criteria\/draft|telegram-webhook|slack-channels|search|install-deps|refresh)$/,
17
19
  ];
18
20
  const LABELS = [
@@ -21,7 +23,6 @@ const LABELS = [
21
23
  [/^\/agents\/[^/]+\/workflows$/, 'Created a workflow'],
22
24
  [/^\/agents\/[^/]+\/workflows\/[^/]+$/, (method) => (method === 'DELETE' ? 'Removed the workflow' : 'Edited the workflow')],
23
25
  [/^\/agents\/[^/]+\/workflows\/[^/]+\/publish$/, 'Published the workflow'],
24
- [/^\/agents\/[^/]+\/workflows\/[^/]+\/versions\/(\d+)\/restore$/, (_method, m) => `Restored workflow version ${m[1]}`],
25
26
  [/^\/agents\/[^/]+\/workflows\/[^/]+\/messages$/, 'Changed where messages go'],
26
27
  [/^\/agents\/[^/]+\/workflows\/[^/]+\/triggers/, 'Changed webhook triggers'],
27
28
  [/^\/agents\/[^/]+\/workflows\/[^/]+\/evals\/criteria/, 'Changed the success criteria'],
@@ -21,7 +21,19 @@ export interface InboxDeps {
21
21
  run?(runId: string): Promise<WorkflowRun | undefined>;
22
22
  /** The run's model calls, oldest first (core/usage.ts). */
23
23
  usage?(run: WorkflowRun): UsageRow[];
24
+ /** An agent's display name. */
25
+ agentLabel?(agent: string): string;
26
+ /** The cases put away (web/inbox-archive.ts), by id. */
27
+ archived?(): Record<string, InboxArchived>;
24
28
  }
29
+ /** A case put away: when, and by whom. */
30
+ export interface InboxArchived {
31
+ at: string;
32
+ by?: string;
33
+ }
34
+ /** Where a case stands: waiting on a person, still running, or finished
35
+ * (done or failed). */
36
+ export type InboxState = 'needs' | 'running' | 'completed' | 'failed';
25
37
  /** One row in the list. */
26
38
  export interface InboxItem {
27
39
  /** The run's id, or "p-<pendingId>" for a decision outside a run. */
@@ -44,10 +56,20 @@ export interface InboxItem {
44
56
  /** What happened, in a few words: "Done automatically", "Approved by
45
57
  * ana@…", "Failed". */
46
58
  outcome: string;
59
+ state: InboxState;
60
+ /** The agent's display name. */
61
+ agentLabel: string;
62
+ /** What it last said, in a line: what it asks, its result, or why it
63
+ * failed. */
64
+ summary: string;
65
+ archived?: InboxArchived;
47
66
  }
48
- /** The Inbox's views: what's waiting on a person (however long), and
49
- * everything from the last RECENT_DAYS days. */
50
- export type InboxView = 'needs' | 'recent';
67
+ /** The Inbox's views: everything not archived; what waits on a person
68
+ * (however long); what's completed or failed; what's archived. "recent"
69
+ * (everything not waiting from the last RECENT_DAYS days) is the older
70
+ * view, kept for links and apps. */
71
+ export type InboxView = 'all' | 'needs' | 'completed' | 'failed' | 'archived' | 'recent';
72
+ export declare const INBOX_VIEWS: InboxView[];
51
73
  export declare const RECENT_DAYS = 7;
52
74
  /** `view`: "needs" (waiting on a person, oldest first, however long),
53
75
  * "recent" (the last RECENT_DAYS days, latest first), or "auto" (needs
@@ -63,6 +85,7 @@ export declare function listInbox(deps: InboxDeps, filter?: {
63
85
  items: InboxItem[];
64
86
  open: number;
65
87
  view: InboxView;
88
+ counts: Record<Exclude<InboxView, 'recent'>, number>;
66
89
  workflows: {
67
90
  id: string;
68
91
  title: string;
@@ -117,6 +140,8 @@ export interface InboxCase {
117
140
  id: string;
118
141
  title: string;
119
142
  agent: string;
143
+ agentLabel?: string;
144
+ archived?: InboxArchived;
120
145
  workflowId: string;
121
146
  workflowTitle: string;
122
147
  run?: WorkflowRun;