loopengine 0.3.86 → 0.3.88

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.
@@ -31,7 +31,8 @@ export interface MessagingDeps {
31
31
  * schema, or a permission rule denies them), or undefined when they can. */
32
32
  checkArgs(pendingId: string, args: Record<string, unknown>): Promise<string | undefined>;
33
33
  }
34
- export type MessagingDecision = {
34
+ /** by: who decided, as the chat app names them. */
35
+ export type MessagingDecision = ({
35
36
  kind: 'approve';
36
37
  editedArgs?: Record<string, unknown>;
37
38
  } | {
@@ -39,6 +40,8 @@ export type MessagingDecision = {
39
40
  } | {
40
41
  kind: 'answer';
41
42
  answer: string;
43
+ }) & {
44
+ by?: string;
42
45
  };
43
46
  export interface DecisionOutcome {
44
47
  /** Couldn't be recorded (an invalid request, a server error). */
@@ -109,7 +109,7 @@ export async function handleInboundMessage(message, deps) {
109
109
  // Said before the decision goes in: the run carries on inside
110
110
  // deps.decide and may post its next request before it returns.
111
111
  await say(verdict.decision === 'deny' ? `Denied by ${who}. Letting the agent know…` : `Answered by ${who}: "${answer}". The agent is carrying on…`);
112
- const outcome = await deps.decide(link.pendingId, verdict.decision === 'answer' ? { kind: 'answer', answer: verdict.answer } : { kind: 'deny' });
112
+ const outcome = await deps.decide(link.pendingId, verdict.decision === 'answer' ? { kind: 'answer', answer: verdict.answer, by: who } : { kind: 'deny', by: who });
113
113
  const after = followUpText(outcome);
114
114
  if (after)
115
115
  await say(after);
@@ -203,7 +203,7 @@ async function runApproved(deps, link, tool, args, who) {
203
203
  const { connector } = deps;
204
204
  const edited = Boolean(link.proposedArgs);
205
205
  await connector.postInThread(link.conversation, link.ts, `Approved${edited ? ' as changed' : ''} by ${who}. Running \`${tool}\` with:\n${formatArgs(args, connector.escape, await deps.toolSchema(tool))}`);
206
- const outcome = await deps.decide(link.pendingId, { kind: 'approve', ...(edited ? { editedArgs: args } : {}) });
206
+ const outcome = await deps.decide(link.pendingId, { kind: 'approve', ...(edited ? { editedArgs: args } : {}), by: who });
207
207
  const after = followUpText(outcome);
208
208
  if (after)
209
209
  await connector.postInThread(link.conversation, link.ts, after);
@@ -54,11 +54,21 @@ export interface WorkflowRun {
54
54
  warnings?: string[];
55
55
  /** Each callback delivery, oldest first (the latest 10). */
56
56
  callbacks?: CallbackDelivery[];
57
- /** Each approval decided while it ran, oldest first. */
57
+ /** Each approval decided while it ran, oldest first, with who decided
58
+ * (an email, or a chat name) when known. */
58
59
  decisions?: {
59
60
  tool: string;
60
61
  approved: boolean;
61
62
  at: string;
63
+ by?: string;
64
+ edited?: boolean;
65
+ }[];
66
+ /** Each question it asked that was answered, oldest first. */
67
+ answers?: {
68
+ question: string;
69
+ answer: string;
70
+ at: string;
71
+ by?: string;
62
72
  }[];
63
73
  /** What the app or person reported after it ended
64
74
  * (POST /agents/:name/runs/:id/feedback): the text actually used, how
@@ -184,6 +194,14 @@ export declare class WorkflowRunner {
184
194
  recordDecision(sessionId: string, decision: {
185
195
  tool: string;
186
196
  approved: boolean;
197
+ by?: string;
198
+ edited?: boolean;
199
+ }): Promise<void>;
200
+ /** Records a question answered in a run's session. */
201
+ recordAnswer(sessionId: string, answer: {
202
+ question: string;
203
+ answer: string;
204
+ by?: string;
187
205
  }): Promise<void>;
188
206
  /** On startup: a run a restart cut off can't continue, so it's an
189
207
  * error. One waiting on a decision is kept: its checkpoint survives. */
@@ -238,7 +238,16 @@ export class WorkflowRunner {
238
238
  const run = await this.forSession(sessionId);
239
239
  if (!run)
240
240
  return;
241
- await getRunStore().update(run.run_id, (r) => r && { ...r, decisions: [...(r.decisions ?? []), { ...decision, at: new Date().toISOString() }].slice(-50) });
241
+ const entry = { tool: decision.tool, approved: decision.approved, at: new Date().toISOString(), ...(decision.by ? { by: decision.by } : {}), ...(decision.edited ? { edited: true } : {}) };
242
+ await getRunStore().update(run.run_id, (r) => r && { ...r, decisions: [...(r.decisions ?? []), entry].slice(-50) });
243
+ }
244
+ /** Records a question answered in a run's session. */
245
+ async recordAnswer(sessionId, answer) {
246
+ const run = await this.forSession(sessionId);
247
+ if (!run)
248
+ return;
249
+ const entry = { question: answer.question.slice(0, 4000), answer: answer.answer.slice(0, 4000), at: new Date().toISOString(), ...(answer.by ? { by: answer.by } : {}) };
250
+ await getRunStore().update(run.run_id, (r) => r && { ...r, answers: [...(r.answers ?? []), entry].slice(-50) });
242
251
  }
243
252
  /** On startup: a run a restart cut off can't continue, so it's an
244
253
  * error. One waiting on a decision is kept: its checkpoint survives. */
@@ -0,0 +1,21 @@
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;
@@ -0,0 +1,75 @@
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
+ }
@@ -0,0 +1,11 @@
1
+ export type WorkspaceRole = 'owner' | 'admin' | 'editor' | 'approver' | 'viewer' | 'api';
2
+ export declare function workspaceRole(raw: string | undefined): WorkspaceRole;
3
+ /** May answer questions and approve or deny tool calls. */
4
+ export declare function canDecide(role: WorkspaceRole): boolean;
5
+ /** Sees only the Inbox. */
6
+ export declare function inboxOnly(role: WorkspaceRole): boolean;
7
+ /** A role's name for people. */
8
+ export declare function roleLabel(role: WorkspaceRole): string;
9
+ /** What an Inbox-only role may reach: the Inbox and its data, deciding
10
+ * (refused later for a viewer), and the console's sign-in line. */
11
+ export declare function inboxOnlyAllows(method: string, pathname: string): boolean;
@@ -0,0 +1,43 @@
1
+ // Who may do what in a workspace. A hosted workspace gets each person's
2
+ // role from the router's signed identity (core/trusted-proxy.ts), as the
3
+ // control plane set it for them; a self-hosted one has a single admin
4
+ // (Basic Auth, or no sign-in), who is the owner.
5
+ //
6
+ // owner, admin everything in the workspace
7
+ // editor everything in the workspace (inviting people and API keys
8
+ // are in the dashboard, for owners and admins)
9
+ // approver the Inbox only: see cases, answer questions, approve or
10
+ // deny
11
+ // viewer the Inbox only, read-only
12
+ //
13
+ // An API key's role is "api": a program with full access. A role this
14
+ // version doesn't know is treated as viewer, the least it can do.
15
+ const KNOWN = ['owner', 'admin', 'editor', 'approver', 'viewer', 'api'];
16
+ export function workspaceRole(raw) {
17
+ if (raw === undefined)
18
+ return 'owner';
19
+ return KNOWN.includes(raw) ? raw : 'viewer';
20
+ }
21
+ /** May answer questions and approve or deny tool calls. */
22
+ export function canDecide(role) {
23
+ return role !== 'viewer';
24
+ }
25
+ /** Sees only the Inbox. */
26
+ export function inboxOnly(role) {
27
+ return role === 'approver' || role === 'viewer';
28
+ }
29
+ /** A role's name for people. */
30
+ export function roleLabel(role) {
31
+ return role === 'api' ? 'API key' : role.charAt(0).toUpperCase() + role.slice(1);
32
+ }
33
+ /** What an Inbox-only role may reach: the Inbox and its data, deciding
34
+ * (refused later for a viewer), and the console's sign-in line. */
35
+ export function inboxOnlyAllows(method, pathname) {
36
+ if (pathname === '/inbox' || pathname.startsWith('/inbox/'))
37
+ return true;
38
+ if (method === 'POST' && /^\/pending-(approvals\/[^/]+\/resolve|questions\/[^/]+\/answer)$/.test(pathname))
39
+ return true;
40
+ if (method === 'GET' && (pathname === '/config/settings' || pathname === '/healthz'))
41
+ return true;
42
+ return false;
43
+ }
package/dist/index.d.ts CHANGED
@@ -133,3 +133,7 @@ export { sendLeverEvents, sharesLeverStats, startLeverEventsSync } from './web/l
133
133
  export { runGoalPipeline, shapeJob, type GoalPlan, type GoalContext, type ShapedJob } from './core/system-agents/goal-planner.js';
134
134
  export { LEVERS, PLAYBOOK_VERSION, activePlaybook, setPlaybookProjectDir, type Lever } from './core/system-agents/goal-playbooks.js';
135
135
  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';
138
+ export { inboxPageHtml, renderInboxOnlyPage } from './web/inbox-page.js';
139
+ export { listInbox, getInboxCase, timelineOf, type InboxDeps, type InboxItem, type InboxCase, type InboxPending, type InboxStep } from './web/inbox-admin.js';
package/dist/index.js CHANGED
@@ -124,3 +124,7 @@ export { sendLeverEvents, sharesLeverStats, startLeverEventsSync } from './web/l
124
124
  export { runGoalPipeline, shapeJob } from './core/system-agents/goal-planner.js';
125
125
  export { LEVERS, PLAYBOOK_VERSION, activePlaybook, setPlaybookProjectDir } from './core/system-agents/goal-playbooks.js';
126
126
  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';
129
+ export { inboxPageHtml, renderInboxOnlyPage } from './web/inbox-page.js';
130
+ export { listInbox, getInboxCase, timelineOf } from './web/inbox-admin.js';
@@ -1156,10 +1156,10 @@ ${consoleShellScript}
1156
1156
  var d = w.delivery || {};
1157
1157
  var chat = workflowChatAppName();
1158
1158
  var chatLabel = escapeHtml(chat || 'chat');
1159
- // With no messaging app, an unattended run's approvals are refused and
1160
- // its questions go unanswered (adapters/http.ts, executeUnattendedRun).
1159
+ // With no messaging app, an unattended run's approvals and questions
1160
+ // wait in the Inbox (adapters/http.ts, executeUnattendedRun).
1161
1161
  var decisionsLabel = workflowChatName() ? escapeHtml(workflowChatName())
1162
- : 'The messaging app <span class="hint">(none set up: approvals are refused and questions go unanswered)</span>';
1162
+ : 'The Inbox <span class="hint">(no messaging app is set up, so they wait in the Inbox)</span>';
1163
1163
  var noChat = chat ? '' : ' disabled';
1164
1164
  var RSQ = String.fromCharCode(8217);
1165
1165
  var row = function (label, body) { return '<div class="wf-msg-row"><div class="wf-msg-k">' + label + '</div><div class="wf-msg-v">' + body + '</div></div>'; };
@@ -32,8 +32,11 @@ 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
+ // An inbox tray, for the Inbox.
36
+ 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
37
  export const consoleSidebarHtml = `<aside class="le-sidebar" aria-label="Console navigation">
36
38
  <a class="le-brand" href="/agents"><span class="le-brand-mark">${BRAND_MARK}</span><span class="le-brand-name">LoopEngine</span></a>
39
+ <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>
37
40
  <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>
38
41
  <ul class="le-agent-list le-goal-list" id="leGoalList"></ul>
39
42
  <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>
@@ -78,6 +81,30 @@ export const consoleShellScript = `<script>
78
81
  }
79
82
  function enc(s) { return encodeURIComponent(s); }
80
83
 
84
+ // Who is signed in and their role (GET /config/settings), read once.
85
+ var settings = fetch('/config/settings')
86
+ .then(function (r) { return r.ok ? r.json() : null; })
87
+ .catch(function () { return null; });
88
+ // On the Inbox, the lists wait for the role: an approver or viewer sees
89
+ // the Inbox only, and the rest of the sidebar is hidden. Other pages
90
+ // are only open to the roles that see everything.
91
+ // The server marks the page for an Inbox-only role before it's shown.
92
+ var markedInboxOnly = Boolean(app && app.classList.contains('le-inbox-only'));
93
+ if (markedInboxOnly) {
94
+ var inboxBrand = document.querySelector('.le-brand');
95
+ if (inboxBrand) inboxBrand.setAttribute('href', '/inbox');
96
+ }
97
+ var fullAccess = markedInboxOnly ? Promise.resolve(false) : page === 'inbox' ? settings.then(function (s) {
98
+ var role = s && s.signIn && s.signIn.role;
99
+ var only = role === 'approver' || role === 'viewer';
100
+ if (only && app) {
101
+ app.classList.add('le-inbox-only');
102
+ var brand = document.querySelector('.le-brand');
103
+ if (brand) brand.setAttribute('href', '/inbox');
104
+ }
105
+ return !only;
106
+ }) : Promise.resolve(true);
107
+
81
108
  function tabHref(name, tab) {
82
109
  if (tab === 'chat') return '/playground?agent=' + enc(name);
83
110
  return '/agents/config?agent=' + enc(name) + (tab && tab !== 'overview' ? '&tab=' + enc(tab) : '');
@@ -154,7 +181,7 @@ export const consoleShellScript = `<script>
154
181
  })
155
182
  .catch(function () { goalList.innerHTML = ''; });
156
183
  }
157
- reloadGoals();
184
+ fullAccess.then(function (full) { if (full) reloadGoals(); });
158
185
 
159
186
  // ---- Jobs, listed under Goals: the person's own jobs (GET /jobs), newest
160
187
  // added first, each opening on the Jobs page; its dot says whether it's
@@ -183,10 +210,26 @@ export const consoleShellScript = `<script>
183
210
  })
184
211
  .catch(function () { jobList.innerHTML = ''; });
185
212
  }
186
- reloadJobs();
213
+ fullAccess.then(function (full) { if (full) reloadJobs(); });
214
+
215
+ // ---- The Inbox, at the top: how many cases wait on a person, kept
216
+ // current. The Inbox page marks itself.
217
+ var inboxCount = document.getElementById('leInboxCount');
218
+ var inboxHead = document.querySelector('[data-le-nav-head="inbox"]');
219
+ if (inboxHead && page === 'inbox') inboxHead.setAttribute('aria-current', 'page');
220
+ function reloadInboxCount() {
221
+ if (!inboxCount) return;
222
+ fetch('/inbox/count', { headers: { accept: 'application/json' } })
223
+ .then(function (r) { return r.ok ? r.json() : { open: 0 }; })
224
+ .then(function (d) { inboxCount.textContent = String(d.open || 0); inboxCount.hidden = !d.open; inboxCount.title = (d.open || 0) + ' waiting for a decision'; })
225
+ .catch(function () {});
226
+ }
227
+ reloadInboxCount();
228
+ setInterval(function () { if (!document.hidden) reloadInboxCount(); }, 30000);
187
229
 
188
230
  var loadError = null;
189
- var ready = fetch('/agents', { headers: { accept: 'application/json' } })
231
+ var ready = fullAccess.then(function (full) { return full ? loadAgents() : []; });
232
+ function loadAgents() { return fetch('/agents', { headers: { accept: 'application/json' } })
190
233
  .then(function (r) {
191
234
  if (!r.ok) throw new Error(r.status === 401 ? 'sign-in required (HTTP 401)' : 'HTTP ' + r.status);
192
235
  return r.json();
@@ -202,6 +245,7 @@ export const consoleShellScript = `<script>
202
245
  if (list) list.innerHTML = '<li class="le-agent-item"><span></span><span class="le-meta">Could not load agents: ' + esc(err.message) + '</span><span></span></li>';
203
246
  return [];
204
247
  });
248
+ }
205
249
 
206
250
  // opts: { name, displayName, prompt, chips: [{ text, mono }], tab, counts: { tools, skills, abilities, actauth } }
207
251
  function renderHead(opts) {
@@ -272,13 +316,13 @@ export const consoleShellScript = `<script>
272
316
  // hosting router signs requests, otherwise how this server is protected.
273
317
  var who = document.getElementById('leWho');
274
318
  if (who) {
275
- fetch('/config/settings')
276
- .then(function (r) { return r.ok ? r.json() : null; })
319
+ settings
277
320
  .then(function (s) {
278
321
  if (!s || !s.signIn) return;
279
322
  var si = s.signIn;
280
323
  if (si.mode === 'hosted') {
281
- who.innerHTML = '<span class="le-who-name" title="' + esc(si.email || '') + '">' + esc(si.email || 'Signed in') + '</span>' +
324
+ var roleName = si.role && si.role !== 'owner' ? si.role.charAt(0).toUpperCase() + si.role.slice(1) : '';
325
+ who.innerHTML = '<span class="le-who-name" title="' + esc(si.email || '') + '">' + esc(si.email || 'Signed in') + (roleName ? ' (' + esc(roleName) + ')' : '') + '</span>' +
282
326
  (si.dashboardUrl ? '<a href="' + esc(si.dashboardUrl) + '">Dashboard</a>' : '');
283
327
  } else {
284
328
  who.innerHTML = '<span class="le-who-name">' + (si.mode === 'basic' ? 'Signed in with Basic Auth' : 'No sign-in configured') + '</span>';
@@ -528,6 +572,6 @@ export const consoleShellScript = `<script>
528
572
  }
529
573
 
530
574
 
531
- window.leShell = { loadError: function () { return loadError; }, ready: ready, reloadGoals: reloadGoals, reloadJobs: reloadJobs, 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 };
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 };
532
576
  })();
533
577
  </script>`;
@@ -148,6 +148,8 @@ export const devUiCss = `
148
148
  .le-agent-item .le-meta { font-size: 12px; color: var(--ink-faint); }
149
149
  .le-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
150
150
  .le-dot.warn { background: var(--warn); }
151
+ .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; }
151
153
  .le-dot.idle { background: var(--ink-faint); }
152
154
  .le-foot { border-top: 1px solid var(--line); padding: 8px; display: grid; gap: 2px; }
153
155
  .le-foot a { padding: 7px 8px; border-radius: 6px; color: var(--ink-muted); text-decoration: none; }
@@ -1015,6 +1015,7 @@ ${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>' : '') +
1018
1019
  '<section><h3>Shared policies</h3><div class="source" id="policiesBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' +
1019
1020
  '<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>' +
1020
1021
  '<section><h3>Updates</h3><div class="source" id="upgradeBox"><p class="hint">Checking for a newer LoopEngine' + String.fromCharCode(8230) + '</p></div></section>';
@@ -1202,6 +1203,126 @@ ${consoleShellScript}
1202
1203
  });
1203
1204
  }
1204
1205
 
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
+
1205
1326
  function loadPolicies() {
1206
1327
  if (!document.getElementById('policiesBox')) return;
1207
1328
  fetch('/config/policies', { cache: 'no-store' })
@@ -1355,9 +1476,11 @@ ${consoleShellScript}
1355
1476
  fetch('/config/settings')
1356
1477
  .then(function (r) { return r.json(); })
1357
1478
  .then(function (d) {
1479
+ settingsDashboardUrl = d.signIn && d.signIn.dashboardUrl ? d.signIn.dashboardUrl : '';
1358
1480
  content.innerHTML = renderSettings(d);
1359
1481
  loadedSections.settings = true;
1360
1482
  loadTimeZone();
1483
+ loadPeople();
1361
1484
  loadPolicies();
1362
1485
  loadAbilitySources();
1363
1486
  loadUpgrade();
@@ -0,0 +1,83 @@
1
+ import type { Message } from '../core/run-agent.js';
2
+ import type { WorkflowRun } from '../core/workflow-runs.js';
3
+ /** An open approval or question, as listAgentPending gives it. */
4
+ export interface InboxPending {
5
+ pendingId: string;
6
+ kind: 'approval' | 'question';
7
+ tool: string;
8
+ args: Record<string, unknown>;
9
+ reason: string;
10
+ sessionId: string;
11
+ createdAt: string | null;
12
+ agent: string;
13
+ }
14
+ export interface InboxDeps {
15
+ runs(): Promise<WorkflowRun[]>;
16
+ pending(): Promise<InboxPending[]>;
17
+ history(run: WorkflowRun): Promise<Message[]>;
18
+ workflowTitle(agent: string, workflowId: string): string | undefined;
19
+ }
20
+ /** One row in the list. */
21
+ export interface InboxItem {
22
+ /** The run's id, or "p-<pendingId>" for a decision outside a run. */
23
+ id: string;
24
+ title: string;
25
+ agent: string;
26
+ workflowId: string;
27
+ workflowTitle: string;
28
+ status: WorkflowRun['status'];
29
+ /** What it waits on now: "approval", "question", or both. */
30
+ waiting: ('approval' | 'question')[];
31
+ startedAt: string;
32
+ finishedAt?: string;
33
+ /** The latest person who decided something in it. */
34
+ lastBy?: string;
35
+ }
36
+ export declare function listInbox(deps: InboxDeps, filter?: {
37
+ open?: boolean;
38
+ q?: string;
39
+ workflow?: string;
40
+ limit?: number;
41
+ }): Promise<{
42
+ items: InboxItem[];
43
+ open: number;
44
+ workflows: {
45
+ id: string;
46
+ title: string;
47
+ }[];
48
+ }>;
49
+ /** A step in a case's timeline. */
50
+ export type InboxStep = {
51
+ kind: 'text';
52
+ text: string;
53
+ } | {
54
+ kind: 'tool';
55
+ tool: string;
56
+ args: Record<string, unknown>;
57
+ result?: string;
58
+ failed?: boolean;
59
+ } | {
60
+ kind: 'question';
61
+ question: string;
62
+ answer?: string;
63
+ };
64
+ /** What the agent did, in order: its words, the tools it used with what
65
+ * came back, and the questions it asked with their answers. The run's
66
+ * first message (its instructions) is left out; its inputs are shown
67
+ * apart. */
68
+ export declare function timelineOf(history: Message[]): InboxStep[];
69
+ export interface InboxCase {
70
+ id: string;
71
+ title: string;
72
+ agent: string;
73
+ workflowId: string;
74
+ workflowTitle: string;
75
+ run?: WorkflowRun;
76
+ /** What it waits on now, in full. */
77
+ pending: (InboxPending & {
78
+ question?: string;
79
+ options?: string[];
80
+ })[];
81
+ steps: InboxStep[];
82
+ }
83
+ export declare function getInboxCase(deps: InboxDeps, id: string): Promise<InboxCase | undefined>;
@@ -0,0 +1,118 @@
1
+ const OUTSIDE = 'p-';
2
+ function short(text, max) {
3
+ const flat = text.replace(/\s+/g, ' ').trim();
4
+ return flat.length > max ? flat.slice(0, max - 1) + '…' : flat;
5
+ }
6
+ /** A case's name: its start message, else its workflow and first input. */
7
+ function titleOf(run, workflowTitle) {
8
+ if (run.chat_notice)
9
+ return short(run.chat_notice, 120);
10
+ const first = run.params ? Object.values(run.params)[0] : undefined;
11
+ return first ? `${workflowTitle}: ${short(first, 60)}` : workflowTitle;
12
+ }
13
+ function questionOf(p) {
14
+ return typeof p.args.question === 'string' ? p.args.question : p.reason;
15
+ }
16
+ export async function listInbox(deps, filter = {}) {
17
+ const [runs, pending] = await Promise.all([deps.runs(), deps.pending()]);
18
+ const bySession = new Map();
19
+ for (const p of pending)
20
+ bySession.set(p.sessionId, [...(bySession.get(p.sessionId) ?? []), p]);
21
+ const runSessions = new Set(runs.map((r) => r.session_id));
22
+ const items = runs.map((run) => {
23
+ const wfTitle = deps.workflowTitle(run.agent, run.workflow_id) ?? (run.workflow_id || 'One-off job');
24
+ const waits = run.status === 'awaiting_approval' ? (bySession.get(run.session_id) ?? []) : [];
25
+ const lastBy = [...(run.decisions ?? []), ...(run.answers ?? [])].sort((a, b) => a.at.localeCompare(b.at)).pop()?.by;
26
+ return {
27
+ id: run.run_id, title: titleOf(run, wfTitle), agent: run.agent, workflowId: run.workflow_id, workflowTitle: wfTitle, status: run.status,
28
+ waiting: [...new Set(waits.map((p) => p.kind))], startedAt: run.started_at, ...(run.finished_at ? { finishedAt: run.finished_at } : {}), ...(lastBy ? { lastBy } : {}),
29
+ };
30
+ });
31
+ for (const p of pending) {
32
+ if (runSessions.has(p.sessionId))
33
+ continue;
34
+ items.push({
35
+ id: OUTSIDE + p.pendingId, title: short(p.kind === 'question' ? questionOf(p) : `Approve ${p.tool}`, 120), agent: p.agent, workflowId: '', workflowTitle: 'Chat',
36
+ status: 'awaiting_approval', waiting: [p.kind], startedAt: p.createdAt ?? new Date(0).toISOString(),
37
+ });
38
+ }
39
+ const open = items.filter((i) => i.waiting.length).length;
40
+ const q = filter.q?.trim().toLowerCase();
41
+ const runParams = new Map(runs.map((r) => [r.run_id, Object.values(r.params ?? {}).join(' ')]));
42
+ const shown = items
43
+ .filter((i) => !filter.open || i.waiting.length)
44
+ .filter((i) => !filter.workflow || i.workflowId === filter.workflow)
45
+ .filter((i) => !q || `${i.title} ${i.agent} ${i.workflowTitle} ${runParams.get(i.id) ?? ''} ${i.lastBy ?? ''}`.toLowerCase().includes(q))
46
+ // Waiting first, newest first within each.
47
+ .sort((a, b) => (b.waiting.length ? 1 : 0) - (a.waiting.length ? 1 : 0) || b.startedAt.localeCompare(a.startedAt));
48
+ // Every workflow with a case, whatever the filter, for the workflow picker.
49
+ const workflows = [...new Map(items.filter((i) => i.workflowId).map((i) => [i.workflowId, i.workflowTitle])).entries()]
50
+ .map(([id, title]) => ({ id, title }))
51
+ .sort((a, b) => a.title.localeCompare(b.title));
52
+ return { items: shown.slice(0, filter.limit ?? 200), open, workflows };
53
+ }
54
+ /** What the agent did, in order: its words, the tools it used with what
55
+ * came back, and the questions it asked with their answers. The run's
56
+ * first message (its instructions) is left out; its inputs are shown
57
+ * apart. */
58
+ export function timelineOf(history) {
59
+ const steps = [];
60
+ const byToolUse = new Map();
61
+ history.forEach((m, index) => {
62
+ if (index === 0 && m.role === 'user')
63
+ return;
64
+ const blocks = typeof m.content === 'string' ? [{ type: 'text', text: m.content }] : m.content;
65
+ for (const b of blocks) {
66
+ if (m.role === 'assistant' && b.type === 'text' && b.text?.trim())
67
+ steps.push({ kind: 'text', text: b.text.trim() });
68
+ else if (b.type === 'tool_use' && b.name) {
69
+ const step = b.name === 'system_ask_user'
70
+ ? { kind: 'question', question: String(b.input?.question ?? '') }
71
+ : { kind: 'tool', tool: b.name, args: b.input ?? {} };
72
+ steps.push(step);
73
+ if (b.id)
74
+ byToolUse.set(b.id, step);
75
+ }
76
+ else if (b.type === 'tool_result' && b.tool_use_id) {
77
+ const step = byToolUse.get(b.tool_use_id);
78
+ const text = typeof b.content === 'string' ? b.content : JSON.stringify(b.content ?? '');
79
+ if (step?.kind === 'question')
80
+ step.answer = text;
81
+ else if (step?.kind === 'tool') {
82
+ step.result = text.length > 2000 ? text.slice(0, 2000) + '…' : text;
83
+ if (b.is_error)
84
+ step.failed = true;
85
+ }
86
+ }
87
+ }
88
+ });
89
+ return steps;
90
+ }
91
+ export async function getInboxCase(deps, id) {
92
+ const [runs, pending] = await Promise.all([deps.runs(), deps.pending()]);
93
+ const full = (p) => ({
94
+ ...p,
95
+ ...(p.kind === 'question' ? { question: questionOf(p) } : {}),
96
+ ...(p.kind === 'question' && Array.isArray(p.args.options) ? { options: p.args.options.map(String) } : {}),
97
+ });
98
+ if (id.startsWith(OUTSIDE)) {
99
+ const p = pending.find((x) => x.pendingId === id.slice(OUTSIDE.length));
100
+ if (!p)
101
+ return undefined;
102
+ return { id, title: short(p.kind === 'question' ? questionOf(p) : `Approve ${p.tool}`, 120), agent: p.agent, workflowId: '', workflowTitle: 'Chat', pending: [full(p)], steps: [] };
103
+ }
104
+ const run = runs.find((r) => r.run_id === id);
105
+ if (!run)
106
+ return undefined;
107
+ const wfTitle = deps.workflowTitle(run.agent, run.workflow_id) ?? (run.workflow_id || 'One-off job');
108
+ const waits = run.status === 'awaiting_approval' ? pending.filter((p) => p.sessionId === run.session_id).map(full) : [];
109
+ let steps = [];
110
+ try {
111
+ steps = timelineOf(await deps.history(run));
112
+ }
113
+ catch {
114
+ // An unreadable history still shows the run and what it waits on.
115
+ }
116
+ const { session_id: _s, message: _m, callbacks: _c, ...shown } = run;
117
+ return { id, title: titleOf(run, wfTitle), agent: run.agent, workflowId: run.workflow_id, workflowTitle: wfTitle, run: shown, pending: waits, steps };
118
+ }
@@ -0,0 +1,3 @@
1
+ export declare const inboxPageHtml: string;
2
+ /** What an Inbox-only role sees on any other page. */
3
+ export declare function renderInboxOnlyPage(message: string): string;
@@ -0,0 +1,339 @@
1
+ // The console's Inbox: /inbox lists every workflow run as a case, the ones
2
+ // waiting on a person first; /inbox?case=<id> opens one, with what it was
3
+ // given, what the agent did, what it asks now (answer, approve, approve
4
+ // as changed, deny) and who decided what (web/inbox-admin.ts behind
5
+ // /inbox/*). An approver or viewer sees only this page; a viewer can't
6
+ // decide. Like the other console pages, its inline script avoids
7
+ // backslashes and template placeholders, since it lives inside a template
8
+ // literal.
9
+ import { devUiCss } from './dev-ui-styles.js';
10
+ import { consoleShellScript, consoleSidebarHtml } from './console-shell.js';
11
+ export const inboxPageHtml = `<!doctype html>
12
+ <html lang="en">
13
+ <head>
14
+ <meta charset="utf-8">
15
+ <meta name="viewport" content="width=device-width, initial-scale=1">
16
+ <title>Inbox</title>
17
+ <style>${devUiCss}
18
+ .ib { max-width: 980px; display: grid; gap: 16px; }
19
+ .ib-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
20
+ .ib-filter { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
21
+ .ib-filter button { border: 0; border-radius: 0; background: var(--bg); padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--ink-muted); }
22
+ .ib-filter button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }
23
+ .ib-bar select, .ib-bar input { font: inherit; font-size: 13px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
24
+ .ib-bar input { flex: 1; min-width: 160px; }
25
+ .ib-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
26
+ .ib-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; }
27
+ .ib-row:first-child { border-top: 0; }
28
+ .ib-row:hover { background: var(--surface); }
29
+ .ib-row-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
30
+ .ib-row-meta { font-size: 12.5px; color: var(--ink-muted); }
31
+ .ib-row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12px; color: var(--ink-muted); white-space: nowrap; }
32
+ .ib-state { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-muted); }
33
+ .ib-state.warn { background: var(--warn-soft); color: var(--warn); }
34
+ .ib-state.good { background: var(--good-soft); color: var(--good); }
35
+ .ib-state.bad { background: var(--bad-soft); color: var(--bad); }
36
+ .ib-state.run { background: var(--accent-soft); color: var(--accent-ink); }
37
+ .ib-empty { padding: 28px 16px; text-align: center; color: var(--ink-muted); font-size: 13.5px; }
38
+ .ib-back { font-size: 13px; color: var(--accent-ink); text-decoration: none; font-weight: 600; }
39
+ .ib-case-head h2 { margin: 4px 0 6px; font-size: 20px; letter-spacing: -0.01em; }
40
+ .ib-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--ink-muted); }
41
+ .ib-card { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 14px 16px; display: grid; gap: 10px; }
42
+ .ib-card h3 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted); }
43
+ .ib-card.needs { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
44
+ .ib-kv { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: 6px 14px; font-size: 13.5px; }
45
+ .ib-kv dt { color: var(--ink-muted); font-family: var(--font-mono); font-size: 12.5px; padding-top: 1px; }
46
+ .ib-kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
47
+ .ib-pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; background: var(--surface); padding: 10px 12px; border-radius: 8px; max-height: 360px; overflow: auto; }
48
+ .ib-question { margin: 0; font-size: 14.5px; white-space: pre-wrap; }
49
+ .ib-card textarea { width: 100%; box-sizing: border-box; min-height: 80px; font: inherit; font-size: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); resize: vertical; }
50
+ .ib-card textarea.mono { font-family: var(--font-mono); font-size: 12.5px; min-height: 200px; }
51
+ .ib-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
52
+ .ib-btn { height: 34px; padding: 0 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; }
53
+ .ib-btn.plain { background: none; border-color: var(--line); color: var(--ink); font-weight: 500; }
54
+ .ib-btn.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
55
+ .ib-btn.opt { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; font-weight: 500; }
56
+ .ib-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
57
+ .ib-step { display: grid; gap: 4px; padding-left: 14px; border-left: 2px solid var(--line); font-size: 13.5px; }
58
+ .ib-step.q { border-left-color: var(--warn); }
59
+ .ib-step-k { font-size: 12px; font-weight: 700; color: var(--ink-muted); }
60
+ .ib-step details summary { cursor: pointer; font-size: 12.5px; color: var(--ink-muted); }
61
+ .ib-who { font-size: 13px; display: grid; gap: 4px; }
62
+ .hint { font-size: 12.5px; color: var(--ink-muted); }
63
+ .error { font-size: 13px; color: var(--bad); margin: 0; }
64
+ @media (max-width: 640px) { .ib-row { grid-template-columns: 12px minmax(0, 1fr); } .ib-row-side { grid-column: 2; align-items: flex-start; flex-direction: row; gap: 8px; } .ib-kv { grid-template-columns: 1fr; } }
65
+ </style>
66
+ </head>
67
+ <body data-le-page="inbox">
68
+ <div class="le-app">
69
+ ${consoleSidebarHtml}
70
+ <main class="le-main">
71
+ <div class="le-head plain">
72
+ <div class="le-head-row">
73
+ <div class="le-title"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">&#9776;</button>
74
+ <div><h1>Inbox</h1><p>Questions and approvals from your agents' runs, and the history of each case: what it was given, what the agent did and who decided what.</p></div>
75
+ </div>
76
+ </div>
77
+ </div>
78
+ <div class="le-scroll"><div class="le-page"><div class="ib" id="ibPage"><p class="hint">Loading&hellip;</p></div></div></div>
79
+ </main>
80
+ </div>
81
+ ${consoleShellScript}
82
+ <script>
83
+ (function () {
84
+ var page = document.getElementById('ibPage');
85
+ var ELLIPSIS = String.fromCharCode(8230);
86
+ var DOT = ' ' + String.fromCharCode(183) + ' ';
87
+ var params = new URLSearchParams(location.search);
88
+ var state = { open: params.get('all') !== '1', q: params.get('q') || '', workflow: params.get('workflow') || '' };
89
+ var role = 'owner';
90
+ var workflows = {};
91
+
92
+ function esc(s) {
93
+ return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) {
94
+ return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c];
95
+ });
96
+ }
97
+ function ago(iso) {
98
+ if (!iso) return '';
99
+ var s = Math.max(0, (Date.now() - new Date(iso).getTime()) / 1000);
100
+ if (s < 60) return 'just now';
101
+ if (s < 3600) return Math.floor(s / 60) + ' min ago';
102
+ if (s < 86400) return Math.floor(s / 3600) + ' h ago';
103
+ return new Date(iso).toLocaleDateString();
104
+ }
105
+ function when(iso) { return iso ? new Date(iso).toLocaleString() : ''; }
106
+ function canDecide() { return role !== 'viewer'; }
107
+
108
+ function stateHtml(item) {
109
+ if (item.waiting && item.waiting.length) return '<span class="ib-state warn">' + (item.waiting.indexOf('approval') !== -1 ? 'Needs approval' : 'Question') + '</span>';
110
+ if (item.status === 'running') return '<span class="ib-state run">Running</span>';
111
+ if (item.status === 'error') return '<span class="ib-state bad">Failed</span>';
112
+ if (item.status === 'done') return '<span class="ib-state good">Done</span>';
113
+ return '<span class="ib-state">' + esc(item.status) + '</span>';
114
+ }
115
+
116
+ function listUrl() {
117
+ var q = new URLSearchParams();
118
+ if (state.open) q.set('open', '1');
119
+ if (state.q) q.set('q', state.q);
120
+ if (state.workflow) q.set('workflow', state.workflow);
121
+ return '/inbox/items?' + q.toString();
122
+ }
123
+ function pageUrl() {
124
+ var q = new URLSearchParams();
125
+ if (!state.open) q.set('all', '1');
126
+ if (state.q) q.set('q', state.q);
127
+ if (state.workflow) q.set('workflow', state.workflow);
128
+ var s = q.toString();
129
+ return '/inbox' + (s ? '?' + s : '');
130
+ }
131
+
132
+ function renderList(data) {
133
+ var items = data.items || [];
134
+ (data.workflows || []).forEach(function (w) { workflows[w.id] = w.title; });
135
+ var options = Object.keys(workflows).sort(function (a, b) { return workflows[a].localeCompare(workflows[b]); }).map(function (id) { return '<option value="' + esc(id) + '"' + (id === state.workflow ? ' selected' : '') + '>' + esc(workflows[id]) + '</option>'; }).join('');
136
+ var rows = items.map(function (i) {
137
+ return '<a class="ib-row" href="/inbox?case=' + encodeURIComponent(i.id) + '">' +
138
+ '<span class="le-dot' + (i.waiting.length ? ' warn' : i.status === 'running' ? '' : ' idle') + '" aria-hidden="true"></span>' +
139
+ '<span style="min-width:0"><div class="ib-row-title">' + esc(i.title) + '</div>' +
140
+ '<div class="ib-row-meta">' + esc(i.workflowTitle) + DOT + esc(i.agent) + (i.lastBy ? DOT + 'last decided by ' + esc(i.lastBy) : '') + '</div></span>' +
141
+ '<span class="ib-row-side">' + stateHtml(i) + '<span>' + esc(ago(i.startedAt)) + '</span></span></a>';
142
+ }).join('');
143
+ page.innerHTML =
144
+ '<div class="ib-bar">' +
145
+ '<span class="ib-filter" role="group" aria-label="Show"><button type="button" data-open="1" aria-pressed="' + state.open + '">Needs you (' + (data.open || 0) + ')</button><button type="button" data-open="0" aria-pressed="' + !state.open + '">All</button></span>' +
146
+ '<select id="ibWorkflow" aria-label="Workflow"><option value="">All workflows</option>' + options + '</select>' +
147
+ '<input id="ibSearch" type="search" placeholder="Search cases, inputs or people" value="' + esc(state.q) + '" aria-label="Search">' +
148
+ '</div>' +
149
+ (items.length ? '<div class="ib-list">' + rows + '</div>'
150
+ : '<div class="ib-list"><p class="ib-empty">' + (state.open ? 'Nothing needs you right now. Questions and approvals from your agents land here.' : 'No cases yet. Each workflow run shows here.') + '</p></div>');
151
+ var buttons = page.querySelectorAll('[data-open]');
152
+ for (var b = 0; b < buttons.length; b++) buttons[b].addEventListener('click', function (ev) { state.open = ev.currentTarget.getAttribute('data-open') === '1'; refreshList(); });
153
+ page.querySelector('#ibWorkflow').addEventListener('change', function (ev) { state.workflow = ev.currentTarget.value; refreshList(); });
154
+ var search = page.querySelector('#ibSearch');
155
+ var timer = null;
156
+ search.addEventListener('input', function () {
157
+ clearTimeout(timer);
158
+ timer = setTimeout(function () { state.q = search.value.trim(); refreshList(true); }, 300);
159
+ });
160
+ }
161
+
162
+ function refreshList(keepFocus) {
163
+ history.replaceState(null, '', pageUrl());
164
+ return fetch(listUrl(), { headers: { accept: 'application/json' } })
165
+ .then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
166
+ .then(function (data) {
167
+ var had = keepFocus && document.activeElement && document.activeElement.id === 'ibSearch';
168
+ renderList(data);
169
+ if (had) { var s = page.querySelector('#ibSearch'); s.focus(); s.setSelectionRange(s.value.length, s.value.length); }
170
+ })
171
+ .catch(function (err) { page.innerHTML = '<p class="error">Could not load the Inbox: ' + esc(err.message) + '</p>'; });
172
+ }
173
+
174
+ function valueHtml(v) {
175
+ if (v == null) return '<span class="hint">(empty)</span>';
176
+ if (typeof v === 'object') return '<pre class="ib-pre">' + esc(JSON.stringify(v, null, 2)) + '</pre>';
177
+ return esc(String(v));
178
+ }
179
+ function kvHtml(obj) {
180
+ var keys = Object.keys(obj || {});
181
+ if (!keys.length) return '<p class="hint" style="margin:0">None.</p>';
182
+ return '<dl class="ib-kv">' + keys.map(function (k) { return '<dt>' + esc(k) + '</dt><dd>' + valueHtml(obj[k]) + '</dd>'; }).join('') + '</dl>';
183
+ }
184
+
185
+ function pendingHtml(p) {
186
+ var locked = canDecide() ? '' : '<p class="hint" style="margin:0">Your role can see this but not decide.</p>';
187
+ if (p.kind === 'question') {
188
+ return '<div class="ib-card needs" data-pending="' + esc(p.pendingId) + '" data-kind="question"><h3>Question for you</h3>' +
189
+ '<p class="ib-question">' + esc(p.question) + '</p>' +
190
+ (canDecide()
191
+ ? (p.options && p.options.length ? '<div class="ib-actions">' + p.options.map(function (o) { return '<button type="button" class="ib-btn opt" data-option="' + esc(o) + '">' + esc(o) + '</button>'; }).join('') + '</div>' : '') +
192
+ '<textarea class="ib-answer" placeholder="Your answer"></textarea>' +
193
+ '<div class="ib-actions"><button type="button" class="ib-btn" data-act="answer">Answer</button><span class="hint ib-result" role="status"></span></div>'
194
+ : locked) +
195
+ '</div>';
196
+ }
197
+ return '<div class="ib-card needs" data-pending="' + esc(p.pendingId) + '" data-kind="approval"><h3>Approve this?</h3>' +
198
+ '<p class="ib-question">The agent wants to run <code>' + esc(p.tool) + '</code> with:</p>' + kvHtml(p.args) +
199
+ (canDecide()
200
+ ? '<textarea class="ib-args mono" hidden>' + esc(JSON.stringify(p.args, null, 2)) + '</textarea>' +
201
+ '<div class="ib-actions"><button type="button" class="ib-btn" data-act="approve">Approve</button>' +
202
+ '<button type="button" class="ib-btn plain" data-act="change">Change</button>' +
203
+ '<button type="button" class="ib-btn bad" data-act="deny">Deny</button><span class="hint ib-result" role="status"></span></div>'
204
+ : locked) +
205
+ '</div>';
206
+ }
207
+
208
+ function stepHtml(s) {
209
+ if (s.kind === 'text') return '<li class="ib-step"><span class="ib-step-k">Agent</span><div style="white-space:pre-wrap">' + esc(s.text) + '</div></li>';
210
+ if (s.kind === 'question') return '<li class="ib-step q"><span class="ib-step-k">Asked</span><div style="white-space:pre-wrap">' + esc(s.question) + '</div>' +
211
+ (s.answer != null ? '<span class="ib-step-k">Answer</span><div style="white-space:pre-wrap">' + esc(s.answer) + '</div>' : '<span class="hint">Waiting for an answer</span>') + '</li>';
212
+ return '<li class="ib-step"><span class="ib-step-k">Used ' + esc(s.tool) + (s.failed ? ' (failed)' : '') + '</span>' +
213
+ '<details><summary>What it sent' + (s.result != null ? ' and got back' : '') + '</summary><pre class="ib-pre">' + esc(JSON.stringify(s.args, null, 2)) + '</pre>' +
214
+ (s.result != null ? '<pre class="ib-pre" style="margin-top:6px">' + esc(s.result) + '</pre>' : '') + '</details></li>';
215
+ }
216
+
217
+ function decidedHtml(run) {
218
+ var rows = [];
219
+ (run.decisions || []).forEach(function (d) { rows.push({ at: d.at, text: (d.approved ? (d.edited ? 'Approved as changed' : 'Approved') : 'Denied') + ' ' + d.tool, by: d.by }); });
220
+ (run.answers || []).forEach(function (a) { rows.push({ at: a.at, text: 'Answered: ' + a.answer, by: a.by }); });
221
+ rows.sort(function (a, b) { return String(a.at).localeCompare(String(b.at)); });
222
+ if (!rows.length) return '';
223
+ return '<div class="ib-card"><h3>Decisions</h3><div class="ib-who">' + rows.map(function (r) {
224
+ return '<div>' + esc(r.text) + ' <span class="hint">' + (r.by ? 'by ' + esc(r.by) + DOT : '') + esc(when(r.at)) + '</span></div>';
225
+ }).join('') + '</div></div>';
226
+ }
227
+
228
+ function renderCase(c) {
229
+ var run = c.run;
230
+ var status = run ? stateHtml({ waiting: c.pending.map(function (p) { return p.kind; }), status: run.status }) : stateHtml({ waiting: c.pending.map(function (p) { return p.kind; }), status: 'awaiting_approval' });
231
+ page.innerHTML =
232
+ '<a class="ib-back" href="' + pageUrl() + '">' + String.fromCharCode(8592) + ' Inbox</a>' +
233
+ '<div class="ib-case-head"><h2>' + esc(c.title) + '</h2><div class="ib-chips">' + status + '<span>' + esc(c.workflowTitle) + DOT + esc(c.agent) + (run ? DOT + 'started ' + esc(when(run.started_at)) + (run.source ? ' by ' + esc(run.source === 'webhook' ? 'a webhook' : run.source === 'schedule' ? 'a schedule' : run.source === 'console' ? 'Run now' : run.source === 'api' ? 'an app' : run.source) : '') : '') + '</span></div></div>' +
234
+ c.pending.map(pendingHtml).join('') +
235
+ (run && run.params ? '<div class="ib-card"><h3>Inputs</h3>' + kvHtml(run.params) + '</div>' : '') +
236
+ (c.steps.length ? '<div class="ib-card"><h3>What the agent did</h3><ol class="ib-steps">' + c.steps.map(stepHtml).join('') + '</ol></div>' : '') +
237
+ (run ? decidedHtml(run) : '') +
238
+ (run && run.result ? '<div class="ib-card"><h3>Result</h3><div style="white-space:pre-wrap;font-size:14px">' + esc(run.result) + '</div></div>' : '') +
239
+ (run && run.error ? '<div class="ib-card"><h3>Failed</h3><p class="error">' + esc(run.error) + '</p></div>' : '');
240
+ wireCase(c);
241
+ }
242
+
243
+ function send(card, path, body) {
244
+ var result = card.querySelector('.ib-result');
245
+ var buttons = card.querySelectorAll('button');
246
+ for (var i = 0; i < buttons.length; i++) buttons[i].disabled = true;
247
+ result.textContent = 'Sending' + ELLIPSIS;
248
+ return fetch(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
249
+ .then(function (r) { return r.json().then(function (b) { return { ok: r.ok, body: b }; }); })
250
+ .then(function (r) {
251
+ if (!r.ok) throw new Error(r.body.error || 'That did not work');
252
+ result.textContent = 'Done. The agent is carrying on' + ELLIPSIS;
253
+ if (window.leShell && window.leShell.reloadInboxCount) window.leShell.reloadInboxCount();
254
+ setTimeout(openCase, 1200);
255
+ })
256
+ .catch(function (err) {
257
+ result.textContent = err.message;
258
+ for (var j = 0; j < buttons.length; j++) buttons[j].disabled = false;
259
+ });
260
+ }
261
+
262
+ function wireCase(c) {
263
+ var cards = page.querySelectorAll('[data-pending]');
264
+ for (var i = 0; i < cards.length; i++) {
265
+ (function (card) {
266
+ var id = card.getAttribute('data-pending');
267
+ if (card.getAttribute('data-kind') === 'question') {
268
+ var answer = card.querySelector('.ib-answer');
269
+ var opts = card.querySelectorAll('[data-option]');
270
+ for (var o = 0; o < opts.length; o++) opts[o].addEventListener('click', function (ev) { answer.value = ev.currentTarget.getAttribute('data-option'); answer.focus(); });
271
+ var btn = card.querySelector('[data-act="answer"]');
272
+ if (btn) btn.addEventListener('click', function () {
273
+ if (!answer.value.trim()) { card.querySelector('.ib-result').textContent = 'Write an answer first.'; return; }
274
+ send(card, '/pending-questions/' + encodeURIComponent(id) + '/answer', { answer: answer.value.trim() });
275
+ });
276
+ return;
277
+ }
278
+ var args = card.querySelector('.ib-args');
279
+ var approve = card.querySelector('[data-act="approve"]');
280
+ var change = card.querySelector('[data-act="change"]');
281
+ var deny = card.querySelector('[data-act="deny"]');
282
+ if (change) change.addEventListener('click', function () {
283
+ args.hidden = !args.hidden;
284
+ approve.textContent = args.hidden ? 'Approve' : 'Approve as changed';
285
+ change.textContent = args.hidden ? 'Change' : 'Cancel change';
286
+ if (!args.hidden) args.focus();
287
+ });
288
+ if (approve) approve.addEventListener('click', function () {
289
+ var body = { decision: 'approve' };
290
+ if (!args.hidden) {
291
+ try { body.editedArgs = JSON.parse(args.value); }
292
+ catch (e) { card.querySelector('.ib-result').textContent = 'The changed arguments are not valid JSON: ' + e.message; return; }
293
+ }
294
+ send(card, '/pending-approvals/' + encodeURIComponent(id) + '/resolve', body);
295
+ });
296
+ if (deny) deny.addEventListener('click', function (ev) {
297
+ var b = ev.currentTarget;
298
+ if (b.getAttribute('data-confirming') !== '1') { b.setAttribute('data-confirming', '1'); b.textContent = 'Click again to deny'; return; }
299
+ send(card, '/pending-approvals/' + encodeURIComponent(id) + '/resolve', { decision: 'deny' });
300
+ });
301
+ })(cards[i]);
302
+ }
303
+ }
304
+
305
+ function openCase() {
306
+ var id = new URLSearchParams(location.search).get('case');
307
+ return fetch('/inbox/cases/' + encodeURIComponent(id), { headers: { accept: 'application/json' } })
308
+ .then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
309
+ .then(renderCase)
310
+ .catch(function (err) { page.innerHTML = '<a class="ib-back" href="/inbox">' + String.fromCharCode(8592) + ' Inbox</a><p class="error">Could not open this case: ' + esc(err.message) + '</p>'; });
311
+ }
312
+
313
+ function start() {
314
+ if (new URLSearchParams(location.search).get('case')) openCase();
315
+ else refreshList();
316
+ // The list keeps itself current while it's open.
317
+ setInterval(function () {
318
+ if (document.hidden || new URLSearchParams(location.search).get('case')) return;
319
+ if (document.activeElement && document.activeElement.id === 'ibSearch') return;
320
+ refreshList();
321
+ }, 15000);
322
+ }
323
+
324
+ fetch('/config/settings')
325
+ .then(function (r) { return r.ok ? r.json() : null; })
326
+ .then(function (s) { if (s && s.signIn && s.signIn.role) role = s.signIn.role; })
327
+ .catch(function () {})
328
+ .then(start);
329
+ })();
330
+ </script>
331
+ </body>
332
+ </html>`;
333
+ /** What an Inbox-only role sees on any other page. */
334
+ export function renderInboxOnlyPage(message) {
335
+ const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
336
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Inbox only</title>
337
+ <style>${devUiCss} .io { max-width: 460px; margin: 18vh auto 0; padding: 0 20px; display: grid; gap: 12px; } .io a { color: var(--accent-ink); font-weight: 600; }</style></head>
338
+ <body><div class="io"><h1 style="margin:0;font-size:20px">Inbox only</h1><p style="margin:0">${esc(message)}</p><p style="margin:0"><a href="/inbox">Open the Inbox</a></p></div></body></html>`;
339
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopengine",
3
- "version": "0.3.86",
3
+ "version": "0.3.88",
4
4
  "type": "module",
5
5
  "description": "Runtime for tool-using AI agents with a transparent ReAct loop.",
6
6
  "license": "MIT",
@@ -45,6 +45,10 @@
45
45
  "dist/core/secret-store.d.ts",
46
46
  "dist/core/trusted-proxy.js",
47
47
  "dist/core/trusted-proxy.d.ts",
48
+ "dist/core/workspace-roles.js",
49
+ "dist/core/workspace-roles.d.ts",
50
+ "dist/core/workspace-people.js",
51
+ "dist/core/workspace-people.d.ts",
48
52
  "dist/core/unattended.js",
49
53
  "dist/core/unattended.d.ts",
50
54
  "dist/core/usage.js",