loopengine 0.3.88 → 0.3.90

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.
@@ -10,6 +10,9 @@ export interface ProxyIdentity {
10
10
  /** Where the person manages this workspace on the host, shown as the
11
11
  * console's "Dashboard" link. */
12
12
  dashboardUrl?: string;
13
+ /** For an approver or viewer limited to some agents (set in the host's
14
+ * dashboard): the ones they see. Absent for every agent. */
15
+ agents?: string[];
13
16
  /** Expiry, Unix seconds. */
14
17
  exp: number;
15
18
  }
@@ -4,6 +4,10 @@ export declare function workspaceRole(raw: string | undefined): WorkspaceRole;
4
4
  export declare function canDecide(role: WorkspaceRole): boolean;
5
5
  /** Sees only the Inbox. */
6
6
  export declare function inboxOnly(role: WorkspaceRole): boolean;
7
+ /** The agents a caller may see, or undefined for every agent: only an
8
+ * approver or viewer is ever limited, to the agents their signed identity
9
+ * lists (chosen in the host's dashboard). */
10
+ export declare function agentsFor(role: WorkspaceRole, agents: unknown): string[] | undefined;
7
11
  /** A role's name for people. */
8
12
  export declare function roleLabel(role: WorkspaceRole): string;
9
13
  /** What an Inbox-only role may reach: the Inbox and its data, deciding
@@ -26,6 +26,14 @@ export function canDecide(role) {
26
26
  export function inboxOnly(role) {
27
27
  return role === 'approver' || role === 'viewer';
28
28
  }
29
+ /** The agents a caller may see, or undefined for every agent: only an
30
+ * approver or viewer is ever limited, to the agents their signed identity
31
+ * lists (chosen in the host's dashboard). */
32
+ export function agentsFor(role, agents) {
33
+ if (!inboxOnly(role) || !Array.isArray(agents))
34
+ return undefined;
35
+ return agents.filter((a) => typeof a === 'string');
36
+ }
29
37
  /** A role's name for people. */
30
38
  export function roleLabel(role) {
31
39
  return role === 'api' ? 'API key' : role.charAt(0).toUpperCase() + role.slice(1);
package/dist/index.d.ts CHANGED
@@ -130,10 +130,12 @@ export type { AgentTemplateOptions } from './bin/cli.js';
130
130
  export { goalsPageHtml } from './web/goals-page.js';
131
131
  export { GoalError, acceptJob, addJob, assignJob, assignmentMessage, listJob, listJobs, submitJob, MY_JOBS_ID, type ListedJob, chainedRuns, chainConditionMet, checkChain, editJob, MAX_CHAIN_DEPTH, type ChainStep, goalView, type AssignmentView, checkBuiltWorkflows, createGoal, deleteGoal, editAmount, generateMore, getGoal, goalContextFrom, listGoals, markBuilt, prepareBuild, readAbout, readGoalSettings, readLeverEvents, setWorkflowState, writeAbout, writeGoalSettings, type Goal, type GoalJob, type GoalJobState, type JobDoer, type GoalWorkflow, type GoalsDeps, type LeverEvent, migrateGoal, migrateGoalFiles } from './web/goals-admin.js';
132
132
  export { sendLeverEvents, sharesLeverStats, startLeverEventsSync } from './web/lever-events-sync.js';
133
+ export { createAgentNamesReporter, type AgentNamesReporter } from './web/agent-names-sync.js';
133
134
  export { runGoalPipeline, shapeJob, type GoalPlan, type GoalContext, type ShapedJob } from './core/system-agents/goal-planner.js';
134
135
  export { LEVERS, PLAYBOOK_VERSION, activePlaybook, setPlaybookProjectDir, type Lever } from './core/system-agents/goal-playbooks.js';
135
136
  export { startPlaybookSync, syncPlaybook, playbookSyncConfig } from './core/playbook-sync.js';
136
- export { workspaceRole, canDecide, inboxOnly, inboxOnlyAllows, roleLabel, type WorkspaceRole } from './core/workspace-roles.js';
137
- export { readPeople, recordVisit, setPersonAgents, removePerson, agentsFor, type WorkspacePerson } from './core/workspace-people.js';
137
+ export { workspaceRole, canDecide, inboxOnly, inboxOnlyAllows, roleLabel, agentsFor, type WorkspaceRole } from './core/workspace-roles.js';
138
138
  export { inboxPageHtml, renderInboxOnlyPage } from './web/inbox-page.js';
139
+ export { workflowsOverviewPageHtml } from './web/workflows-overview-page.js';
140
+ export { workflowsOverview, startsOf, type WorkflowsOverview, type WorkflowOverviewRow } from './web/workflows-overview.js';
139
141
  export { listInbox, getInboxCase, timelineOf, type InboxDeps, type InboxItem, type InboxCase, type InboxPending, type InboxStep } from './web/inbox-admin.js';
package/dist/index.js CHANGED
@@ -121,10 +121,12 @@ export { scaffoldAgent, scaffoldSubagent, AgentNameError, AgentExistsError, Agen
121
121
  export { goalsPageHtml } from './web/goals-page.js';
122
122
  export { GoalError, acceptJob, addJob, assignJob, assignmentMessage, listJob, listJobs, submitJob, MY_JOBS_ID, chainedRuns, chainConditionMet, checkChain, editJob, MAX_CHAIN_DEPTH, goalView, checkBuiltWorkflows, createGoal, deleteGoal, editAmount, generateMore, getGoal, goalContextFrom, listGoals, markBuilt, prepareBuild, readAbout, readGoalSettings, readLeverEvents, setWorkflowState, writeAbout, writeGoalSettings, migrateGoal, migrateGoalFiles } from './web/goals-admin.js';
123
123
  export { sendLeverEvents, sharesLeverStats, startLeverEventsSync } from './web/lever-events-sync.js';
124
+ export { createAgentNamesReporter } from './web/agent-names-sync.js';
124
125
  export { runGoalPipeline, shapeJob } from './core/system-agents/goal-planner.js';
125
126
  export { LEVERS, PLAYBOOK_VERSION, activePlaybook, setPlaybookProjectDir } from './core/system-agents/goal-playbooks.js';
126
127
  export { startPlaybookSync, syncPlaybook, playbookSyncConfig } from './core/playbook-sync.js';
127
- export { workspaceRole, canDecide, inboxOnly, inboxOnlyAllows, roleLabel } from './core/workspace-roles.js';
128
- export { readPeople, recordVisit, setPersonAgents, removePerson, agentsFor } from './core/workspace-people.js';
128
+ export { workspaceRole, canDecide, inboxOnly, inboxOnlyAllows, roleLabel, agentsFor } from './core/workspace-roles.js';
129
129
  export { inboxPageHtml, renderInboxOnlyPage } from './web/inbox-page.js';
130
+ export { workflowsOverviewPageHtml } from './web/workflows-overview-page.js';
131
+ export { workflowsOverview, startsOf } from './web/workflows-overview.js';
130
132
  export { listInbox, getInboxCase, timelineOf } from './web/inbox-admin.js';
@@ -0,0 +1,11 @@
1
+ export declare const AGENT_NAMES_PATH = "/api/workspace/agents";
2
+ export interface AgentNamesReporter {
3
+ /** Sends the names if they changed since the last send that worked. */
4
+ report(): Promise<void>;
5
+ }
6
+ export declare function createAgentNamesReporter(list: () => string[], deps?: {
7
+ env?: NodeJS.ProcessEnv;
8
+ fetch?: typeof fetch;
9
+ log?: (message: string) => void;
10
+ retryMs?: number;
11
+ }): AgentNamesReporter;
@@ -0,0 +1,51 @@
1
+ // Tells loopengine.co the workspace's agents' names, so its dashboard can
2
+ // offer them when an owner or admin chooses which agents an approver or
3
+ // viewer sees. Only the names: nothing about what the agents do. Sent when
4
+ // the server starts and whenever an agent is added or removed; a send that
5
+ // fails is tried again a few minutes later.
6
+ //
7
+ // Signed like the workspace's run reports (web/lever-events-sync.ts):
8
+ // X-LoopEngine-Workspace names it, X-LoopEngine-Signature is t=<unix
9
+ // seconds>,v1=<HMAC-SHA256 of "<t>.<body>"> with
10
+ // LOOPENGINE_TRUSTED_PROXY_SECRET. Off outside LoopEngine Cloud.
11
+ import { leverEventsSyncConfig, signLeverEvents } from './lever-events-sync.js';
12
+ export const AGENT_NAMES_PATH = '/api/workspace/agents';
13
+ const RETRY_MS = 5 * 60 * 1000;
14
+ export function createAgentNamesReporter(list, deps = {}) {
15
+ const config = leverEventsSyncConfig(deps.env ?? process.env);
16
+ const doFetch = deps.fetch ?? fetch;
17
+ let sent;
18
+ let retry;
19
+ async function report() {
20
+ if ('off' in config)
21
+ return;
22
+ const body = JSON.stringify({ agents: [...new Set(list())].sort() });
23
+ if (body === sent)
24
+ return;
25
+ if (retry)
26
+ clearTimeout(retry);
27
+ retry = undefined;
28
+ try {
29
+ const res = await doFetch(config.url.replace(/\/api\/workspace\/lever-events$/, AGENT_NAMES_PATH), {
30
+ method: 'POST',
31
+ headers: { 'content-type': 'application/json', 'x-loopengine-workspace': config.slug, 'x-loopengine-signature': signLeverEvents(body, Math.floor(Date.now() / 1000), config.secret) },
32
+ body,
33
+ signal: AbortSignal.timeout(10_000),
34
+ });
35
+ // An older loopengine.co doesn't take them yet; nothing to retry.
36
+ if (res.status === 404) {
37
+ sent = body;
38
+ return;
39
+ }
40
+ if (!res.ok)
41
+ throw new Error(`HTTP ${res.status}`);
42
+ sent = body;
43
+ }
44
+ catch (err) {
45
+ deps.log?.(`[loopengine] couldn't send the agent list to loopengine.co (trying again shortly): ${err instanceof Error ? err.message : String(err)}`);
46
+ retry = setTimeout(() => void report(), deps.retryMs ?? RETRY_MS);
47
+ retry.unref?.();
48
+ }
49
+ }
50
+ return { report };
51
+ }
@@ -1463,6 +1463,8 @@ ${consoleShellScript}
1463
1463
  function loadWorkflowsSection(name) {
1464
1464
  var el = detail.querySelector('#workflowsContent');
1465
1465
  if (!el) return;
1466
+ // Keep the sidebar's workflow list in step (running or pending).
1467
+ if (window.leShell && window.leShell.reloadWorkflows) window.leShell.reloadWorkflows();
1466
1468
  if (workflowsRefreshTimer) { clearTimeout(workflowsRefreshTimer); workflowsRefreshTimer = null; }
1467
1469
  fetchJsonRetryOnce('/agents/' + encodeURIComponent(name) + '/workflows').then(function (r) {
1468
1470
  if (currentName !== name) return;
@@ -32,17 +32,22 @@ const JOBS_ICON = '<svg class="le-nav-icon" viewBox="0 0 24 24" fill="currentCol
32
32
  // The robot is drawn smaller in its 24 box than the others: cropped to
33
33
  // its middle 18, it shows at the same size.
34
34
  const AGENTS_ICON = '<svg class="le-nav-icon" viewBox="3 3 18 18" fill="currentColor" aria-hidden="true"><path d="M11 12a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm3.5 1.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M12 5.5a1 1 0 0 1 1 1V7h4a3 3 0 0 1 3 3v3.5a5 5 0 0 1-5 5H9a5 5 0 0 1-5-5V10a3 3 0 0 1 3-3h4v-.5a1 1 0 0 1 1-1ZM7 9h10a1 1 0 0 1 1 1v3.5a3 3 0 0 1-3 3H9a3 3 0 0 1-3-3V10a1 1 0 0 1 1-1Z"/></svg>';
35
+ // Two linked steps going round, for Workflows.
36
+ 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>';
35
37
  // An inbox tray, for the Inbox.
36
38
  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>';
37
39
  export const consoleSidebarHtml = `<aside class="le-sidebar" aria-label="Console navigation">
38
- <a class="le-brand" href="/agents"><span class="le-brand-mark">${BRAND_MARK}</span><span class="le-brand-name">LoopEngine</span></a>
40
+ <a class="le-brand" href="/"><span class="le-brand-mark">${BRAND_MARK}</span><span class="le-brand-name">LoopEngine</span></a>
39
41
  <div class="le-nav-label le-inbox-nav"><a class="le-nav-head" href="/inbox" data-le-nav-head="inbox">${INBOX_ICON}Inbox</a><span class="le-pill warn le-inbox-count" id="leInboxCount" hidden></span></div>
42
+ <div class="le-nav-label"><a class="le-nav-head" href="/agents" data-le-nav-head="agents">${AGENTS_ICON}Agents</a><a href="/agents?new=1">+ New</a></div>
43
+ <ul class="le-agent-list" id="leAgentList"></ul>
44
+ <div class="le-nav-label"><a class="le-nav-head" href="/workflows" data-le-nav-head="workflows">${WORKFLOWS_ICON}Workflows</a><a href="/workflows/new">+ New</a></div>
45
+ <ul class="le-agent-list le-goal-list" id="leWorkflowList"></ul>
46
+ <div class="le-nav-group">Plan</div>
40
47
  <div class="le-nav-label"><a class="le-nav-head" href="/goals" data-le-nav-head="goals">${GOALS_ICON}Goals</a><a href="/goals?new=1" data-le-goal-new>+ New</a></div>
41
48
  <ul class="le-agent-list le-goal-list" id="leGoalList"></ul>
42
49
  <div class="le-nav-label"><a class="le-nav-head" href="/jobs" data-le-nav-head="jobs">${JOBS_ICON}Jobs</a><a href="/jobs?new=1" data-le-job-new>+ New</a></div>
43
50
  <ul class="le-agent-list le-goal-list" id="leJobList"></ul>
44
- <div class="le-nav-label"><a class="le-nav-head" href="/agents" data-le-nav-head="agents">${AGENTS_ICON}Agents</a><a href="/agents?new=1">+ New</a></div>
45
- <ul class="le-agent-list" id="leAgentList"></ul>
46
51
  <a class="le-find" href="/interview" data-le-nav="interview">Find your first agent</a>
47
52
  <nav class="le-foot" aria-label="Settings">
48
53
  <a href="/config?section=models" data-le-nav="models">Models</a>
@@ -212,11 +217,38 @@ export const consoleShellScript = `<script>
212
217
  }
213
218
  fullAccess.then(function (full) { if (full) reloadJobs(); });
214
219
 
220
+ // ---- Workflows, listed under the agents (GET /workflows/overview),
221
+ // each opening on its agent's Workflows tab. A tinted dot is running (a
222
+ // run under way, or a schedule or webhook on); yellow is pending (it
223
+ // only runs when someone starts it).
224
+ var workflowList = document.getElementById('leWorkflowList');
225
+ function reloadWorkflows() {
226
+ if (!workflowList) return Promise.resolve();
227
+ var q = new URLSearchParams(location.search);
228
+ var currentAgent = page === 'agent-config' && q.get('tab') === 'workflows' ? q.get('agent') : null;
229
+ var currentId = currentAgent ? q.get('workflow') : null;
230
+ return fetch('/workflows/overview', { headers: { accept: 'application/json' } })
231
+ .then(function (r) { return r.ok ? r.json() : { workflows: [] }; })
232
+ .then(function (data) {
233
+ var list = (data.workflows || []).slice().sort(function (a, b) { return a.title.localeCompare(b.title); });
234
+ workflowList.innerHTML = list.length ? list.map(function (w) {
235
+ var on = w.agent === currentAgent && w.id === currentId;
236
+ return '<li><a class="le-agent-item le-goal-item" href="/agents/config?agent=' + enc(w.agent) + '&tab=workflows&workflow=' + enc(w.id) + '" title="' + esc(w.title) + ' (' + esc(w.agentLabel) + DOT_SEP + (w.live ? 'Running' : 'Pending') + ')"' + (on ? ' aria-current="page"' : '') + '>' +
237
+ '<span class="le-dot ' + (w.live ? 'tint' : 'pending') + '" aria-hidden="true"></span><span class="le-name">' + esc(w.title) + '</span></a></li>';
238
+ }).join('') : '<li class="le-agent-item"><span></span><span class="le-meta">No workflows yet</span><span></span></li>';
239
+ })
240
+ .catch(function () { workflowList.innerHTML = ''; });
241
+ }
242
+ var DOT_SEP = ', ';
243
+ fullAccess.then(function (full) { if (full) reloadWorkflows(); });
244
+
215
245
  // ---- The Inbox, at the top: how many cases wait on a person, kept
216
246
  // current. The Inbox page marks itself.
217
247
  var inboxCount = document.getElementById('leInboxCount');
218
248
  var inboxHead = document.querySelector('[data-le-nav-head="inbox"]');
219
249
  if (inboxHead && page === 'inbox') inboxHead.setAttribute('aria-current', 'page');
250
+ var workflowsHead = document.querySelector('[data-le-nav-head="workflows"]');
251
+ if (workflowsHead && page === 'workflows-overview') workflowsHead.setAttribute('aria-current', 'page');
220
252
  function reloadInboxCount() {
221
253
  if (!inboxCount) return;
222
254
  fetch('/inbox/count', { headers: { accept: 'application/json' } })
@@ -572,6 +604,6 @@ export const consoleShellScript = `<script>
572
604
  }
573
605
 
574
606
 
575
- window.leShell = { loadError: function () { return loadError; }, ready: ready, reloadGoals: reloadGoals, reloadJobs: reloadJobs, 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 };
607
+ window.leShell = { loadError: function () { return loadError; }, ready: ready, 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 };
576
608
  })();
577
609
  </script>`;
@@ -128,6 +128,7 @@ export const devUiCss = `
128
128
  .le-brand { display: flex; align-items: center; gap: 8px; padding: 16px 16px 12px; text-decoration: none; color: var(--ink); }
129
129
  .le-brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
130
130
  .le-brand-name { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
131
+ .le-nav-group { margin: 14px 16px 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
131
132
  .le-nav-label { padding: 10px 16px 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); display: flex; justify-content: space-between; align-items: center; }
132
133
  .le-nav-label a { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 12px; text-decoration: none; }
133
134
  .le-nav-label a[aria-current="page"] { font-weight: 700; }
@@ -137,8 +138,9 @@ export const devUiCss = `
137
138
  .le-nav-label a.le-nav-head[aria-current="page"] { color: var(--accent-ink); font-weight: 700; }
138
139
  .le-agent-list.le-goal-list { flex: 0 1 auto; max-height: 34vh; }
139
140
  .le-goal-item .le-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
140
- .le-agent-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; min-height: 0; }
141
- .le-find { margin: 6px 16px 10px; font-size: 12.5px; font-weight: 500; color: var(--accent-ink); text-decoration: none; }
141
+ .le-agent-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 0 1 auto; max-height: 40vh; min-height: 0; }
142
+ /* The lists sit together at the top; the rest goes to the bottom. */
143
+ .le-find { margin: auto 16px 10px; font-size: 12.5px; font-weight: 500; color: var(--accent-ink); text-decoration: none; }
142
144
  .le-find[aria-current="page"] { font-weight: 600; }
143
145
  .le-find + .le-find { margin-top: -4px; }
144
146
  .le-agent-item { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; color: var(--ink); text-decoration: none; }
@@ -148,8 +150,10 @@ export const devUiCss = `
148
150
  .le-agent-item .le-meta { font-size: 12px; color: var(--ink-faint); }
149
151
  .le-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
150
152
  .le-dot.warn { background: var(--warn); }
153
+ .le-dot.tint { background: var(--accent); }
154
+ .le-dot.pending { background: #E8B06A; }
151
155
  .le-inbox-count { margin-left: auto; font-size: 11px; padding: 0 7px; }
152
- .le-inbox-only .le-nav-label:not(.le-inbox-nav), .le-inbox-only .le-agent-list, .le-inbox-only .le-find, .le-inbox-only .le-foot > a { display: none; }
156
+ .le-inbox-only .le-nav-group, .le-inbox-only .le-nav-label:not(.le-inbox-nav), .le-inbox-only .le-agent-list, .le-inbox-only .le-find, .le-inbox-only .le-foot > a { display: none; }
153
157
  .le-dot.idle { background: var(--ink-faint); }
154
158
  .le-foot { border-top: 1px solid var(--line); padding: 8px; display: grid; gap: 2px; }
155
159
  .le-foot a { padding: 7px 8px; border-radius: 6px; color: var(--ink-muted); text-decoration: none; }
@@ -1015,7 +1015,6 @@ ${consoleShellScript}
1015
1015
  rows.map(function (r) { return '<tr><td>' + r[0] + '</td><td>' + r[1] + '</td></tr>'; }).join('') +
1016
1016
  '</tbody></table></section>' +
1017
1017
  (d.timeZone ? '<section><h3>Time zone</h3><div class="source" id="timeZoneBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' : '') +
1018
- (si.mode === 'hosted' ? '<section><h3>People</h3><div class="source" id="peopleBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' : '') +
1019
1018
  '<section><h3>Shared policies</h3><div class="source" id="policiesBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' +
1020
1019
  '<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>' +
1021
1020
  '<section><h3>Updates</h3><div class="source" id="upgradeBox"><p class="hint">Checking for a newer LoopEngine' + String.fromCharCode(8230) + '</p></div></section>';
@@ -1203,126 +1202,6 @@ ${consoleShellScript}
1203
1202
  });
1204
1203
  }
1205
1204
 
1206
- // ---- People: which agents each approver or viewer sees (hosted
1207
- // workspaces; invites and roles are in the dashboard). ----
1208
- var peopleData = null;
1209
- var settingsDashboardUrl = '';
1210
- var peopleEditing = '';
1211
- function roleName(role) {
1212
- return role ? role.charAt(0).toUpperCase() + role.slice(1) : 'Not here yet';
1213
- }
1214
- function limitedRole(role) {
1215
- return role === 'approver' || role === 'viewer';
1216
- }
1217
- function agentChecks(selected, all) {
1218
- if (!all.length) return '<p class="hint">No agents yet.</p>';
1219
- return '<div style="display:flex;flex-wrap:wrap;gap:6px 14px">' + all.map(function (a) {
1220
- return '<label style="display:inline-flex;gap:6px;align-items:center"><input type="checkbox" name="agent" value="' + escapeHtml(a) + '"' + (selected.indexOf(a) !== -1 ? ' checked' : '') + '> ' + escapeHtml(a) + '</label>';
1221
- }).join('') + '</div>';
1222
- }
1223
- function agentsText(p) {
1224
- return p.agents ? (p.agents.length ? p.agents.map(escapeHtml).join(', ') : 'No agents') : 'All agents';
1225
- }
1226
- function renderPeople() {
1227
- var box = document.getElementById('peopleBox');
1228
- if (!box || !peopleData) return;
1229
- var d = peopleData;
1230
- var intro = '<p style="margin:0 0 10px">Choose which agents each approver or viewer sees. The Inbox shows them only those agents' + String.fromCharCode(8217) + ' cases, and an approver can decide only on those. Owners, admins and editors always see every agent. Invite people and set their role in the ' +
1231
- '<a href="#" id="peopleDashboard">dashboard</a>.</p>';
1232
- var rows = d.people.map(function (p) {
1233
- var editing = peopleEditing === p.email;
1234
- var full = p.role && !limitedRole(p.role);
1235
- var agentsCell = full
1236
- ? '<span class="hint">All agents (' + escapeHtml(roleName(p.role)) + ')</span>'
1237
- : editing
1238
- ? '<form class="peopleForm" data-email="' + escapeHtml(p.email) + '" style="display:flex;flex-direction:column;gap:8px">' +
1239
- '<label style="display:inline-flex;gap:6px;align-items:center"><input type="checkbox" name="all"' + (p.agents ? '' : ' checked') + '> All agents, including new ones</label>' +
1240
- '<div class="peopleAgents"' + (p.agents ? '' : ' hidden') + '>' + agentChecks(p.agents || [], d.agents) + '</div>' +
1241
- '<div style="display:flex;gap:6px"><button type="submit" class="primary">Save</button><button type="button" data-people-cancel="1">Cancel</button></div>' +
1242
- '</form>'
1243
- : agentsText(p);
1244
- var actions = !d.canChange || full || editing ? ''
1245
- : '<button type="button" data-people-edit="' + escapeHtml(p.email) + '">Change</button>' +
1246
- (p.role ? '' : ' <button type="button" data-people-remove="' + escapeHtml(p.email) + '">Remove</button>');
1247
- return '<tr><td>' + escapeHtml(p.email) + '</td><td>' + escapeHtml(roleName(p.role)) + (p.seen ? '<div class="hint">last here ' + escapeHtml(new Date(p.seen).toLocaleDateString()) + '</div>' : '') + '</td><td>' + agentsCell + '</td><td style="white-space:nowrap">' + actions + '</td></tr>';
1248
- }).join('');
1249
- var table = d.people.length
1250
- ? '<table><thead><tr><th>Person</th><th>Role</th><th>Sees</th><th></th></tr></thead><tbody>' + rows + '</tbody></table>'
1251
- : '<p class="hint">Nobody else has signed in yet. People show here after their first visit, or add someone by email below.</p>';
1252
- var add = d.canChange
1253
- ? '<form id="peopleAddForm" style="display:flex;flex-direction:column;gap:8px;margin-top:12px;max-width:720px">' +
1254
- '<label for="peopleEmail" class="hint">Limit someone before their first visit</label>' +
1255
- '<div style="display:flex;gap:6px;flex-wrap:wrap"><input id="peopleEmail" type="email" placeholder="jane@example.com" style="flex:1;min-width:200px" required></div>' +
1256
- agentChecks([], d.agents) +
1257
- '<div><button type="submit">Add</button></div>' +
1258
- '</form>'
1259
- : '<p class="hint">Only an owner or admin can change who sees which agents.</p>';
1260
- box.innerHTML = intro + table + add + '<div id="peopleMsg" class="hint" style="margin-top:8px"></div>';
1261
- var dash = document.getElementById('peopleDashboard');
1262
- if (dash) {
1263
- if (settingsDashboardUrl) dash.setAttribute('href', settingsDashboardUrl);
1264
- else dash.outerHTML = 'dashboard';
1265
- }
1266
- }
1267
- function sendPeople(method, body) {
1268
- var msg = document.getElementById('peopleMsg');
1269
- if (msg) msg.textContent = 'Saving' + String.fromCharCode(8230);
1270
- return fetch('/config/people', { method: method, headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
1271
- .then(function (r) { return r.json().then(function (b) { return { ok: r.ok, body: b }; }); })
1272
- .then(function (r) {
1273
- if (!r.ok) throw new Error(r.body.error || 'Could not save');
1274
- peopleData = r.body;
1275
- peopleEditing = '';
1276
- renderPeople();
1277
- var m = document.getElementById('peopleMsg');
1278
- if (m) m.textContent = 'Saved. It applies on their next page load.';
1279
- })
1280
- .catch(function (err) {
1281
- var m = document.getElementById('peopleMsg');
1282
- if (m) m.innerHTML = '<span class="error">' + escapeHtml(err.message) + '</span>';
1283
- });
1284
- }
1285
- function checkedAgents(form) {
1286
- return Array.prototype.map.call(form.querySelectorAll('input[name="agent"]:checked'), function (i) { return i.value; });
1287
- }
1288
- document.getElementById('settingsContent').addEventListener('click', function (ev) {
1289
- var t = ev.target;
1290
- if (!t || !t.getAttribute) return;
1291
- if (t.getAttribute('data-people-edit')) { peopleEditing = t.getAttribute('data-people-edit'); renderPeople(); }
1292
- else if (t.getAttribute('data-people-cancel')) { peopleEditing = ''; renderPeople(); }
1293
- else if (t.getAttribute('data-people-remove')) sendPeople('DELETE', { email: t.getAttribute('data-people-remove') });
1294
- });
1295
- document.getElementById('settingsContent').addEventListener('change', function (ev) {
1296
- var t = ev.target;
1297
- if (!t || t.name !== 'all') return;
1298
- var form = t.closest('.peopleForm');
1299
- var list = form && form.querySelector('.peopleAgents');
1300
- if (list) list.hidden = t.checked;
1301
- });
1302
- document.getElementById('settingsContent').addEventListener('submit', function (ev) {
1303
- var form = ev.target;
1304
- if (form.classList && form.classList.contains('peopleForm')) {
1305
- ev.preventDefault();
1306
- sendPeople('PUT', { email: form.getAttribute('data-email'), agents: form.querySelector('input[name="all"]').checked ? null : checkedAgents(form) });
1307
- } else if (form.id === 'peopleAddForm') {
1308
- ev.preventDefault();
1309
- sendPeople('PUT', { email: document.getElementById('peopleEmail').value, agents: checkedAgents(form) });
1310
- }
1311
- });
1312
- function loadPeople() {
1313
- if (!document.getElementById('peopleBox')) return;
1314
- fetch('/config/people', { cache: 'no-store' })
1315
- .then(function (r) {
1316
- if (r.status === 404) throw new Error('this server' + String.fromCharCode(8217) + 's template is older; update it (Updates, below) to choose who sees which agents');
1317
- return r.json();
1318
- })
1319
- .then(function (d) { peopleData = d; renderPeople(); })
1320
- .catch(function (err) {
1321
- var box = document.getElementById('peopleBox');
1322
- if (box) box.innerHTML = '<p class="hint">People aren' + String.fromCharCode(8217) + 't available: ' + escapeHtml(err.message) + '.</p>';
1323
- });
1324
- }
1325
-
1326
1205
  function loadPolicies() {
1327
1206
  if (!document.getElementById('policiesBox')) return;
1328
1207
  fetch('/config/policies', { cache: 'no-store' })
@@ -1476,11 +1355,9 @@ ${consoleShellScript}
1476
1355
  fetch('/config/settings')
1477
1356
  .then(function (r) { return r.json(); })
1478
1357
  .then(function (d) {
1479
- settingsDashboardUrl = d.signIn && d.signIn.dashboardUrl ? d.signIn.dashboardUrl : '';
1480
1358
  content.innerHTML = renderSettings(d);
1481
1359
  loadedSections.settings = true;
1482
1360
  loadTimeZone();
1483
- loadPeople();
1484
1361
  loadPolicies();
1485
1362
  loadAbilitySources();
1486
1363
  loadUpgrade();
@@ -0,0 +1 @@
1
+ export declare const workflowsOverviewPageHtml: string;
@@ -0,0 +1,142 @@
1
+ // The console's front page: / and /workflows list every workflow in the
2
+ // workspace with how it starts, how it's been running and what's waiting
3
+ // in the Inbox (web/workflows-overview.ts behind /workflows/overview).
4
+ // Goals and Jobs are the way in when there's nothing to automate yet.
5
+ // Like the other console pages, its inline script avoids backslashes and
6
+ // template placeholders, since it lives inside a template literal.
7
+ import { devUiCss } from './dev-ui-styles.js';
8
+ import { consoleShellScript, consoleSidebarHtml } from './console-shell.js';
9
+ export const workflowsOverviewPageHtml = `<!doctype html>
10
+ <html lang="en">
11
+ <head>
12
+ <meta charset="utf-8">
13
+ <meta name="viewport" content="width=device-width, initial-scale=1">
14
+ <title>Workflows</title>
15
+ <style>${devUiCss}
16
+ .wo { max-width: 1040px; display: grid; gap: 20px; }
17
+ .wo-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
18
+ .wo-stat { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 14px 16px; display: grid; gap: 2px; color: var(--ink); text-decoration: none; }
19
+ a.wo-stat:hover { border-color: var(--accent); }
20
+ .wo-stat b { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
21
+ .wo-stat span { font-size: 12.5px; color: var(--ink-muted); }
22
+ .wo-stat.warn { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
23
+ .wo-stat.warn b { color: var(--warn); }
24
+ .wo-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
25
+ .wo-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.2fr) minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 14px 16px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; }
26
+ .wo-row:first-child { border-top: 0; }
27
+ .wo-row:hover { background: var(--surface); }
28
+ .wo-head { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted); background: var(--surface); }
29
+ .wo-head:hover { background: var(--surface); }
30
+ .wo-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
31
+ .wo-sub { font-size: 12.5px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
32
+ .wo-runs { font-size: 13px; display: grid; gap: 2px; }
33
+ .wo-side { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
34
+ .wo-pill { font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-muted); white-space: nowrap; }
35
+ .wo-pill.warn { background: var(--warn-soft); color: var(--warn); }
36
+ .wo-pill.good { background: var(--good-soft); color: var(--good); }
37
+ .wo-pill.bad { background: var(--bad-soft); color: var(--bad); }
38
+ .wo-pill.run { background: var(--accent-soft); color: var(--accent-ink); }
39
+ .wo-new { display: inline-flex; align-items: center; height: 34px; padding: 0 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; background: var(--accent); color: var(--on-accent); text-decoration: none; white-space: nowrap; }
40
+ .wo-empty { border: 1px dashed var(--line); border-radius: 12px; padding: 28px 24px; display: grid; gap: 14px; }
41
+ .wo-empty h2 { margin: 0; font-size: 17px; }
42
+ .wo-ways { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
43
+ .wo-way { border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 4px; color: var(--ink); text-decoration: none; background: var(--bg); }
44
+ .wo-way:hover { border-color: var(--accent); }
45
+ .wo-way b { font-size: 14px; }
46
+ .wo-way span { font-size: 12.5px; color: var(--ink-muted); }
47
+ .wo-plan { border-radius: 12px; background: var(--surface); padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; font-size: 13.5px; }
48
+ .wo-plan a { font-weight: 600; color: var(--accent-ink); text-decoration: none; }
49
+ .hint { font-size: 12.5px; color: var(--ink-muted); }
50
+ .error { font-size: 13px; color: var(--bad); margin: 0; }
51
+ @media (max-width: 760px) { .wo-row { grid-template-columns: minmax(0, 1fr) auto; } .wo-row .wo-col-starts, .wo-row .wo-col-runs { display: none; } .wo-head { display: none; } }
52
+ </style>
53
+ </head>
54
+ <body data-le-page="workflows-overview">
55
+ <div class="le-app">
56
+ ${consoleSidebarHtml}
57
+ <main class="le-main">
58
+ <div class="le-head plain">
59
+ <div class="le-head-row">
60
+ <div class="le-title"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">&#9776;</button>
61
+ <div><h1>Workflows</h1><p>Every job your agents run: how each one starts, how it's been going, and what's waiting for you.</p></div>
62
+ </div>
63
+ <a class="wo-new" href="/workflows/new">New workflow</a>
64
+ </div>
65
+ </div>
66
+ <div class="le-scroll"><div class="le-page"><div class="wo" id="woPage"><p class="hint">Loading&hellip;</p></div></div></div>
67
+ </main>
68
+ </div>
69
+ ${consoleShellScript}
70
+ <script>
71
+ (function () {
72
+ var page = document.getElementById('woPage');
73
+ var DOT = ' ' + String.fromCharCode(183) + ' ';
74
+ var esc = window.leShell.esc;
75
+
76
+ function ago(iso) {
77
+ var s = Math.max(0, (Date.now() - Date.parse(iso)) / 1000);
78
+ if (s < 60) return 'just now';
79
+ if (s < 3600) return Math.round(s / 60) + ' min ago';
80
+ if (s < 86400) return Math.round(s / 3600) + ' h ago';
81
+ return Math.round(s / 86400) + ' d ago';
82
+ }
83
+ function lastRunPill(w) {
84
+ if (w.waiting) return '<span class="wo-pill warn">' + w.waiting + ' waiting</span>';
85
+ if (!w.lastRun) return '<span class="wo-pill">Not run yet</span>';
86
+ var st = w.lastRun.status;
87
+ if (st === 'running') return '<span class="wo-pill run">Running</span>';
88
+ if (st === 'error') return '<span class="wo-pill bad">Last run failed</span>';
89
+ if (st === 'awaiting_approval') return '<span class="wo-pill warn">Waiting</span>';
90
+ return '<span class="wo-pill good">Done</span>';
91
+ }
92
+ function href(w) {
93
+ return '/agents/config?agent=' + encodeURIComponent(w.agent) + '&tab=workflows&workflow=' + encodeURIComponent(w.id);
94
+ }
95
+ function plural(n, one, many) { return n + ' ' + (n === 1 ? one : many); }
96
+
97
+ var PLAN = '<div class="wo-plan"><span>Not sure what to automate next? Say what you want to achieve, and LoopEngine suggests the jobs that move it.</span><a href="/goals?new=1">Start from a goal &rarr;</a></div>';
98
+
99
+ function renderEmpty() {
100
+ page.innerHTML =
101
+ '<div class="wo-empty"><h2>No workflows yet</h2>' +
102
+ '<p class="hint" style="margin:0">A workflow is a job an agent does again and again: it runs on a schedule, from a webhook or from your app, asks you when it needs to, and every run is kept to check and improve.</p>' +
103
+ '<div class="wo-ways">' +
104
+ '<a class="wo-way" href="/workflows/new"><b>Describe a workflow</b><span>Write the job in a sentence or two and review the plan.</span></a>' +
105
+ '<a class="wo-way" href="/workflows/new#examples"><b>Start from an example</b><span>A ready-made workflow for a common job.</span></a>' +
106
+ '<a class="wo-way" href="/goals?new=1"><b>Start from a goal</b><span>Not sure what to automate? Get jobs suggested for what you want to achieve.</span></a>' +
107
+ '</div></div>';
108
+ }
109
+
110
+ function render(d) {
111
+ if (!d.workflows.length) return renderEmpty();
112
+ var s = d.summary;
113
+ var stats =
114
+ '<div class="wo-stats">' +
115
+ '<a class="wo-stat' + (s.waiting ? ' warn' : '') + '" href="/inbox"><b>' + s.waiting + '</b><span>' + (s.waiting === 1 ? 'Case waiting for you' : 'Cases waiting for you') + '</span></a>' +
116
+ '<div class="wo-stat"><b>' + s.runsThisWeek + '</b><span>Runs in the last 7 days</span></div>' +
117
+ '<div class="wo-stat"><b>' + s.failedThisWeek + '</b><span>Failed in the last 7 days</span></div>' +
118
+ '<div class="wo-stat"><b>' + s.workflows + '</b><span>' + (s.workflows === 1 ? 'Workflow' : 'Workflows') + '</span></div>' +
119
+ '</div>';
120
+ var rows = d.workflows.map(function (w) {
121
+ var decided = w.approved + w.refused;
122
+ return '<a class="wo-row" href="' + href(w) + '">' +
123
+ '<span style="min-width:0"><div class="wo-title">' + esc(w.title) + '</div><div class="wo-sub">' + esc(w.agentLabel) + '</div></span>' +
124
+ '<span class="wo-col-starts wo-sub" title="' + esc(w.starts.join(', ')) + '">' + esc(w.starts.join(DOT)) + '</span>' +
125
+ '<span class="wo-col-runs wo-runs"><span>' + plural(w.runsThisWeek, 'run', 'runs') + ' this week' + (w.failedThisWeek ? ', <span style="color:var(--bad)">' + w.failedThisWeek + ' failed</span>' : '') + '</span>' +
126
+ '<span class="wo-sub">' + (w.lastRun ? 'Last ' + esc(ago(w.lastRun.at)) : 'Not run yet') + (decided ? DOT + w.approved + ' of ' + decided + ' approved' : '') + '</span></span>' +
127
+ '<span class="wo-side">' + lastRunPill(w) + '</span>' +
128
+ '</a>';
129
+ }).join('');
130
+ page.innerHTML = stats +
131
+ '<div class="wo-list"><div class="wo-row wo-head"><span>Workflow</span><span class="wo-col-starts">Starts</span><span class="wo-col-runs">Runs</span><span></span></div>' + rows + '</div>' +
132
+ PLAN;
133
+ }
134
+
135
+ fetch('/workflows/overview', { cache: 'no-store' })
136
+ .then(function (r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json(); })
137
+ .then(render)
138
+ .catch(function (err) { page.innerHTML = '<p class="error">Couldn' + String.fromCharCode(8217) + 't load your workflows: ' + esc(err.message) + '</p>'; });
139
+ })();
140
+ </script>
141
+ </body>
142
+ </html>`;
@@ -0,0 +1,47 @@
1
+ import type { WorkflowRun } from '../core/workflow-runs.js';
2
+ import type { InboxItem } from './inbox-admin.js';
3
+ import type { AgentWorkflowView } from './workflow-admin.js';
4
+ export interface WorkflowOverviewRow {
5
+ agent: string;
6
+ agentLabel: string;
7
+ id: string;
8
+ title: string;
9
+ /** How it starts, in words: its schedules and webhooks; "Run now" when
10
+ * nothing else starts it. */
11
+ starts: string[];
12
+ /** Running: a run under way, or a schedule or webhook on to start it.
13
+ * Otherwise it's pending: it only runs when someone starts it. */
14
+ live: boolean;
15
+ /** Runs started in the last 7 days, and how many of them failed. */
16
+ runsThisWeek: number;
17
+ failedThisWeek: number;
18
+ lastRun?: {
19
+ status: WorkflowRun['status'];
20
+ at: string;
21
+ };
22
+ /** Its cases waiting for a person in the Inbox. */
23
+ waiting: number;
24
+ /** Decisions on its recent runs. */
25
+ approved: number;
26
+ refused: number;
27
+ }
28
+ export interface WorkflowsOverview {
29
+ workflows: WorkflowOverviewRow[];
30
+ summary: {
31
+ workflows: number;
32
+ runsThisWeek: number;
33
+ failedThisWeek: number;
34
+ waiting: number;
35
+ };
36
+ }
37
+ export declare function startsOf(view: AgentWorkflowView): string[];
38
+ export declare function workflowsOverview(input: {
39
+ workflows: {
40
+ agent: string;
41
+ agentLabel: string;
42
+ view: AgentWorkflowView;
43
+ }[];
44
+ runs: WorkflowRun[];
45
+ waiting: InboxItem[];
46
+ now?: Date;
47
+ }): WorkflowsOverview;
@@ -0,0 +1,45 @@
1
+ const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
2
+ function plural(n, one, many) {
3
+ return `${n} ${n === 1 ? one : many}`;
4
+ }
5
+ export function startsOf(view) {
6
+ const starts = view.schedules.map((s) => (s.status === 'paused' ? `${s.describe} (paused)` : s.describe));
7
+ if (view.webhooks)
8
+ starts.push(plural(view.webhooks, 'webhook', 'webhooks'));
9
+ if (view.webhooksWaiting)
10
+ starts.push(`${plural(view.webhooksWaiting, 'webhook', 'webhooks')} waiting for a secret`);
11
+ return starts.length ? starts : ['Run now'];
12
+ }
13
+ export function workflowsOverview(input) {
14
+ const since = (input.now ?? new Date()).getTime() - WEEK_MS;
15
+ const rows = input.workflows.map(({ agent, agentLabel, view }) => {
16
+ const own = input.runs.filter((r) => r.agent === agent && r.workflow_id === view.id);
17
+ const week = own.filter((r) => Date.parse(r.started_at) >= since);
18
+ const latest = [...own].sort((a, b) => b.started_at.localeCompare(a.started_at))[0];
19
+ return {
20
+ agent,
21
+ agentLabel,
22
+ id: view.id,
23
+ title: view.title || view.id,
24
+ starts: startsOf(view),
25
+ live: own.some((r) => r.status === 'running') || view.webhooks > 0 || view.schedules.some((s) => s.status !== 'paused' && s.status !== 'done' && s.status !== 'cancelled'),
26
+ runsThisWeek: week.length,
27
+ failedThisWeek: week.filter((r) => r.status === 'error').length,
28
+ ...(latest ? { lastRun: { status: latest.status, at: latest.started_at } } : {}),
29
+ waiting: input.waiting.filter((i) => i.agent === agent && i.workflowId === view.id && i.waiting.length).length,
30
+ approved: view.scores?.approvals.approved ?? 0,
31
+ refused: view.scores?.approvals.refused ?? 0,
32
+ };
33
+ });
34
+ // Waiting ones first, then the most recently run, then by name.
35
+ rows.sort((a, b) => b.waiting - a.waiting || (b.lastRun?.at ?? '').localeCompare(a.lastRun?.at ?? '') || a.title.localeCompare(b.title));
36
+ return {
37
+ workflows: rows,
38
+ summary: {
39
+ workflows: rows.length,
40
+ runsThisWeek: rows.reduce((n, r) => n + r.runsThisWeek, 0),
41
+ failedThisWeek: rows.reduce((n, r) => n + r.failedThisWeek, 0),
42
+ waiting: input.waiting.filter((i) => i.waiting.length).length,
43
+ },
44
+ };
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopengine",
3
- "version": "0.3.88",
3
+ "version": "0.3.90",
4
4
  "type": "module",
5
5
  "description": "Runtime for tool-using AI agents with a transparent ReAct loop.",
6
6
  "license": "MIT",
@@ -47,8 +47,6 @@
47
47
  "dist/core/trusted-proxy.d.ts",
48
48
  "dist/core/workspace-roles.js",
49
49
  "dist/core/workspace-roles.d.ts",
50
- "dist/core/workspace-people.js",
51
- "dist/core/workspace-people.d.ts",
52
50
  "dist/core/unattended.js",
53
51
  "dist/core/unattended.d.ts",
54
52
  "dist/core/usage.js",
@@ -1,21 +0,0 @@
1
- import { type WorkspaceRole } from './workspace-roles.js';
2
- export interface WorkspacePerson {
3
- email: string;
4
- role?: WorkspaceRole;
5
- /** When they were last here (ISO). */
6
- seen?: string;
7
- /** The agents they see; absent for every agent. */
8
- agents?: string[];
9
- }
10
- export declare function readPeople(projectDir: string): WorkspacePerson[];
11
- /** Notes a signed-in person's visit: a new person, a changed role, or an
12
- * hour since "last here" is written; anything else costs nothing. */
13
- export declare function recordVisit(projectDir: string, rawEmail: string, role: WorkspaceRole, now?: Date): void;
14
- /** Sets which agents `email` sees; undefined for every agent. Adds them
15
- * if they haven't been here yet. */
16
- export declare function setPersonAgents(projectDir: string, rawEmail: string, agents: string[] | undefined): WorkspacePerson;
17
- /** Forgets `email` (they see every agent again, if they still have access). */
18
- export declare function removePerson(projectDir: string, rawEmail: string): void;
19
- /** The agents a caller may see, or undefined for every agent. Only an
20
- * approver or viewer is ever limited. */
21
- export declare function agentsFor(projectDir: string, role: WorkspaceRole, rawEmail: string | undefined): string[] | undefined;
@@ -1,75 +0,0 @@
1
- // Which agents each person sees, for a hosted workspace with a team
2
- // (core/workspace-roles.ts). The control plane says who may come in and
3
- // with what role; this says where an approver or viewer may look: the
4
- // Inbox shows them only those agents' cases, and they decide only on
5
- // those. Owners, admins and editors always see every agent.
6
- //
7
- // Kept in .loopengine/people.json by email, with each person's role and
8
- // when they were last here, so Settings → People can list everyone who
9
- // has signed in. Someone can be added by email before their first visit.
10
- // No entry, or no agent list, means every agent.
11
- import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
12
- import { dirname, join } from 'node:path';
13
- import { inboxOnly } from './workspace-roles.js';
14
- /** How often a visit updates "last here". */
15
- const SEEN_EVERY_MS = 60 * 60 * 1000;
16
- function peopleFile(projectDir) {
17
- return join(projectDir, '.loopengine', 'people.json');
18
- }
19
- function normalEmail(raw) {
20
- return raw.trim().toLowerCase();
21
- }
22
- export function readPeople(projectDir) {
23
- try {
24
- const parsed = JSON.parse(readFileSync(peopleFile(projectDir), 'utf8'));
25
- return Array.isArray(parsed.people) ? parsed.people.filter((p) => p && typeof p.email === 'string') : [];
26
- }
27
- catch {
28
- return [];
29
- }
30
- }
31
- function writePeople(projectDir, people) {
32
- const file = peopleFile(projectDir);
33
- mkdirSync(dirname(file), { recursive: true });
34
- const temp = `${file}.${process.pid}.tmp`;
35
- writeFileSync(temp, JSON.stringify({ people: [...people].sort((a, b) => a.email.localeCompare(b.email)) }, null, 2) + '\n');
36
- renameSync(temp, file);
37
- }
38
- /** Notes a signed-in person's visit: a new person, a changed role, or an
39
- * hour since "last here" is written; anything else costs nothing. */
40
- export function recordVisit(projectDir, rawEmail, role, now = new Date()) {
41
- const email = normalEmail(rawEmail);
42
- if (!email)
43
- return;
44
- const people = readPeople(projectDir);
45
- const known = people.find((p) => p.email === email);
46
- if (known && known.role === role && known.seen && now.getTime() - Date.parse(known.seen) < SEEN_EVERY_MS)
47
- return;
48
- const updated = { ...(known ?? { email }), role, seen: now.toISOString() };
49
- writePeople(projectDir, [...people.filter((p) => p.email !== email), updated]);
50
- }
51
- /** Sets which agents `email` sees; undefined for every agent. Adds them
52
- * if they haven't been here yet. */
53
- export function setPersonAgents(projectDir, rawEmail, agents) {
54
- const email = normalEmail(rawEmail);
55
- const people = readPeople(projectDir);
56
- const { agents: _old, ...rest } = people.find((p) => p.email === email) ?? { email };
57
- const updated = agents ? { ...rest, agents: [...new Set(agents)].sort() } : rest;
58
- writePeople(projectDir, [...people.filter((p) => p.email !== email), updated]);
59
- return updated;
60
- }
61
- /** Forgets `email` (they see every agent again, if they still have access). */
62
- export function removePerson(projectDir, rawEmail) {
63
- const email = normalEmail(rawEmail);
64
- writePeople(projectDir, readPeople(projectDir).filter((p) => p.email !== email));
65
- }
66
- /** The agents a caller may see, or undefined for every agent. Only an
67
- * approver or viewer is ever limited. */
68
- export function agentsFor(projectDir, role, rawEmail) {
69
- if (!inboxOnly(role))
70
- return undefined;
71
- if (!rawEmail)
72
- return undefined;
73
- const email = normalEmail(rawEmail);
74
- return readPeople(projectDir).find((p) => p.email === email)?.agents;
75
- }