@floless/app 0.149.0 → 0.150.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/floless-server.cjs +102295 -88314
- package/dist/schemas/drawing-check.profile.v1.schema.json +45 -2
- package/dist/schemas/steel.model.v2.schema.json +9 -0
- package/dist/skills/floless-app-approval/SKILL.md +79 -4
- package/dist/skills/floless-app-onboarding/SKILL.md +4 -4
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +1 -1
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +15 -13
- package/dist/skills/floless-app-routines/SKILL.md +4 -1
- package/dist/skills/floless-app-routines/references/routines-api.md +14 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +4 -2
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +14 -9
- package/dist/skills/floless-app-workflows/SKILL.md +2 -2
- package/dist/templates/tekla-parser.flo +13 -3
- package/dist/web/agents.js +887 -0
- package/dist/web/app.css +458 -23
- package/dist/web/app.js +20 -5
- package/dist/web/aware.js +1339 -134
- package/dist/web/chat.css +68 -4
- package/dist/web/chat.js +1770 -55
- package/dist/web/commands-drawing-check.js +15 -0
- package/dist/web/commands-revit.js +5 -0
- package/dist/web/commands-shell.js +785 -50
- package/dist/web/commands-tekla-parser.js +8 -1
- package/dist/web/connections.js +57 -14
- package/dist/web/drawing-check-editor.html +10 -2
- package/dist/web/drawing-check-editor.js +569 -40
- package/dist/web/drawing-check-overlay.js +45 -2
- package/dist/web/index.html +102 -27
- package/dist/web/instructor.js +85 -8
- package/dist/web/leave-guard.js +1 -0
- package/dist/web/left-pane.js +20 -1
- package/dist/web/local-discovery.js +12 -2
- package/dist/web/model-editor.css +32 -32
- package/dist/web/model-panel-bridge.js +11 -3
- package/dist/web/model-viewport-lighting.js +4 -2
- package/dist/web/model-viewport-revit-adapter.js +3 -0
- package/dist/web/model-viewport-toolbar.js +6 -3
- package/dist/web/model-viewport.js +11 -1
- package/dist/web/revit-editor.css +14 -14
- package/dist/web/revit-editor.js +64 -12
- package/dist/web/steel-3d-core.js +133 -0
- package/dist/web/steel-3d-view.js +10 -0
- package/dist/web/steel-editor.html +171 -39
- package/dist/web/steel-model-v2-client-validation.js +11 -0
- package/dist/web/steel-model-v2-commands.js +80 -5
- package/dist/web/tool-updates.js +367 -0
- package/dist/web/workspaces.js +679 -59
- package/package.json +1 -1
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Agents tab (#2007, #1337 step 5): delegated responsibilities run by hand.
|
|
3
|
+
*
|
|
4
|
+
* An agent is a name, plain-English instructions and an explicit scope (projects and owned workflows). Run starts
|
|
5
|
+
* ordinary AI Chat conversations through the server's shared coordinator — one per project ("each separately") or
|
|
6
|
+
* one across them ("compare"). This file only renders and relays: the server decides what runs, where, and when
|
|
7
|
+
* (server/delegated-agent-runs.ts). It never talks to an AI.
|
|
8
|
+
*
|
|
9
|
+
* Not the AWARE library: that is Tools (≡ menu, /api/agents). Everything here is /api/chat/agents, under the chat
|
|
10
|
+
* session cookie.
|
|
11
|
+
*/
|
|
12
|
+
(() => {
|
|
13
|
+
const $surface = document.getElementById('agents-surface');
|
|
14
|
+
if (!$surface) return;
|
|
15
|
+
|
|
16
|
+
const LS_PROVIDER = 'floless:agents-provider';
|
|
17
|
+
const state = {
|
|
18
|
+
open: false,
|
|
19
|
+
view: 'list', // 'list' | 'page'
|
|
20
|
+
agents: [],
|
|
21
|
+
unreadable: [],
|
|
22
|
+
showArchived: false,
|
|
23
|
+
loading: false,
|
|
24
|
+
loadError: null,
|
|
25
|
+
agent: null, // the saved agent on the page (null for a new one)
|
|
26
|
+
draft: null, // { name, instructions, scope, mode, allowChanges }
|
|
27
|
+
dirty: false,
|
|
28
|
+
banner: null, // { text, action?: { label, run } }
|
|
29
|
+
saving: false,
|
|
30
|
+
runs: [],
|
|
31
|
+
runsKey: null,
|
|
32
|
+
runsUnreadable: [],
|
|
33
|
+
runsPaused: false,
|
|
34
|
+
runsProblem: null, // why waiting runs could not be started just now (server)
|
|
35
|
+
runsError: null, // why the last poll of the runs failed
|
|
36
|
+
optionsError: null, // why the project and workflow lists could not be read
|
|
37
|
+
options: null, // { projects:[], workflows:[] } for the scope picker
|
|
38
|
+
pickerOpen: false,
|
|
39
|
+
pickerQuery: '',
|
|
40
|
+
selected: null, // { runId, index }
|
|
41
|
+
chatScope: null, // what AI Chat shows while a run row is selected
|
|
42
|
+
pollTimer: null,
|
|
43
|
+
pageGeneration: 0,
|
|
44
|
+
sessionReady: false,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// ── helpers ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
const el = (tag, props = {}, ...children) => {
|
|
50
|
+
const node = document.createElement(tag);
|
|
51
|
+
for (const [key, value] of Object.entries(props)) {
|
|
52
|
+
if (value === undefined || value === null || value === false) continue;
|
|
53
|
+
if (key === 'class') node.className = value;
|
|
54
|
+
else if (key === 'text') node.textContent = value;
|
|
55
|
+
else if (key === 'dataset') Object.assign(node.dataset, value);
|
|
56
|
+
else if (key.startsWith('on') && typeof value === 'function') node.addEventListener(key.slice(2), value);
|
|
57
|
+
else node.setAttribute(key, value === true ? '' : String(value));
|
|
58
|
+
}
|
|
59
|
+
for (const child of children.flat()) if (child !== null && child !== undefined && child !== false) node.append(child);
|
|
60
|
+
return node;
|
|
61
|
+
};
|
|
62
|
+
const toast = (text, kind) => { try { showToast(text, kind); } catch { /* app.js not ready */ } };
|
|
63
|
+
const agoText = (iso) => {
|
|
64
|
+
if (!iso) return '';
|
|
65
|
+
try { return typeof relAgo === 'function' ? relAgo(iso) : new Date(iso).toLocaleString(); } catch { return ''; }
|
|
66
|
+
};
|
|
67
|
+
const timeText = (iso) => {
|
|
68
|
+
try { return new Date(iso).toLocaleString(undefined, { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' }); }
|
|
69
|
+
catch { return iso; }
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
async function ensureSession() {
|
|
73
|
+
if (state.sessionReady) return;
|
|
74
|
+
let response;
|
|
75
|
+
try { response = await fetch('/api/chat/session', { credentials: 'same-origin' }); }
|
|
76
|
+
catch {
|
|
77
|
+
const failure = new Error('FloLess could not be reached. Make sure it is still running, then try again.');
|
|
78
|
+
failure.code = 'local-unreachable';
|
|
79
|
+
throw failure;
|
|
80
|
+
}
|
|
81
|
+
if (!response.ok) throw new Error('FloLess could not open AI Chat’s session, so agents could not load. Reload FloLess and try again.');
|
|
82
|
+
state.sessionReady = true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function api(path, options = {}) {
|
|
86
|
+
await ensureSession();
|
|
87
|
+
const init = { credentials: 'same-origin', ...options };
|
|
88
|
+
if (init.body && typeof init.body !== 'string') { init.body = JSON.stringify(init.body); init.headers = { 'content-type': 'application/json' }; }
|
|
89
|
+
if (!init.signal && typeof AbortSignal?.timeout === 'function') init.signal = AbortSignal.timeout(30_000);
|
|
90
|
+
let response;
|
|
91
|
+
try { response = await fetch(path, init); }
|
|
92
|
+
catch (error) {
|
|
93
|
+
const failure = new Error(error?.name === 'TimeoutError'
|
|
94
|
+
? 'FloLess took too long to answer, most likely because it is busy. Try again in a moment.'
|
|
95
|
+
: 'FloLess could not be reached. Make sure it is still running, then try again.');
|
|
96
|
+
failure.code = 'local-unreachable';
|
|
97
|
+
throw failure;
|
|
98
|
+
}
|
|
99
|
+
let body = null;
|
|
100
|
+
if ((response.headers.get('content-type') || '').includes('application/json')) {
|
|
101
|
+
try { body = await response.json(); } catch { body = null; }
|
|
102
|
+
}
|
|
103
|
+
if (response.status === 401 && body?.code === 'chat-session-required' && !options.retried) {
|
|
104
|
+
state.sessionReady = false;
|
|
105
|
+
return api(path, { ...options, retried: true });
|
|
106
|
+
}
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
if (!body?.error) console.warn(`[agents] ${path} answered ${response.status} with no explanation`);
|
|
109
|
+
const failure = new Error(body?.error || 'FloLess couldn’t do that just now. Try again; if it keeps happening, restart FloLess.');
|
|
110
|
+
failure.code = body?.code || null; failure.body = body; failure.status = response.status;
|
|
111
|
+
throw failure;
|
|
112
|
+
}
|
|
113
|
+
return body;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function scopeKey(entry) { return entry.kind === 'project' ? `project:${entry.projectId}` : `workflow:${entry.workflowId}`; }
|
|
117
|
+
function scopeLabel(entry) {
|
|
118
|
+
const options = state.options;
|
|
119
|
+
if (entry.kind === 'project') return options?.projects.find((p) => p.id === entry.projectId)?.name || entry.projectId;
|
|
120
|
+
return options?.workflows.find((w) => w.workflowId === entry.workflowId)?.displayName || 'A workflow';
|
|
121
|
+
}
|
|
122
|
+
function scopeAvailable(entry) {
|
|
123
|
+
const options = state.options;
|
|
124
|
+
if (!options) return true;
|
|
125
|
+
if (entry.kind === 'project') {
|
|
126
|
+
const project = options.projects.find((p) => p.id === entry.projectId);
|
|
127
|
+
return Boolean(project && String(project.uuid || '').toLowerCase() === String(entry.projectUuid || '').toLowerCase());
|
|
128
|
+
}
|
|
129
|
+
return options.workflows.some((w) => w.workflowId === entry.workflowId && w.status !== 'archived');
|
|
130
|
+
}
|
|
131
|
+
function scopeSummary(agent) {
|
|
132
|
+
const projects = agent.scope.filter((s) => s.kind === 'project').length;
|
|
133
|
+
const workflows = agent.scope.length - projects;
|
|
134
|
+
const parts = [];
|
|
135
|
+
if (projects) parts.push(`${projects} project${projects === 1 ? '' : 's'}`);
|
|
136
|
+
if (workflows) parts.push(`${workflows} workflow${workflows === 1 ? '' : 's'}`);
|
|
137
|
+
if (!parts.length) return 'No projects or workflows yet';
|
|
138
|
+
return `${parts.join(', ')}${agent.scope.length > 1 ? (agent.mode === 'compare' ? ' · compared' : ' · each separately') : ''}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// A list that could not be read is never shown as an empty one: that would mark every project "Not available".
|
|
142
|
+
async function loadOptions() {
|
|
143
|
+
const read = async (path) => {
|
|
144
|
+
const response = await fetch(path, { credentials: 'same-origin' });
|
|
145
|
+
if (!response.ok) throw new Error(`${path} answered ${response.status}`);
|
|
146
|
+
return response.json();
|
|
147
|
+
};
|
|
148
|
+
try {
|
|
149
|
+
const [projects, workflows] = await Promise.all([read('/api/projects'), read('/api/workflows/owned')]);
|
|
150
|
+
state.options = {
|
|
151
|
+
projects: (projects.projects || []).filter((p) => p.uuid).map((p) => ({ id: p.id, uuid: p.uuid, name: p.name || p.id })),
|
|
152
|
+
workflows: (workflows.workflows || []).filter((w) => w.status !== 'archived')
|
|
153
|
+
.map((w) => ({ workflowId: w.workflowId, displayName: w.displayName, ownerLabel: w.ownerLabel || 'Standalone', status: w.status })),
|
|
154
|
+
};
|
|
155
|
+
state.optionsError = null;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.warn('[agents] could not load the project and workflow lists:', error);
|
|
158
|
+
state.optionsError = 'FloLess couldn’t load your projects and workflows, so their names and whether they are still available can’t be shown. Reload FloLess to try again.';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ── chat pane hand-off ────────────────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
|
|
164
|
+
function notifyChatScope() {
|
|
165
|
+
window.dispatchEvent(new CustomEvent('floless:chat-scope-changed', { detail: window.flolessBridge?.getChatScope?.() || null }));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function showRunInChat(target) {
|
|
169
|
+
const agentName = state.agent?.name || 'Agent';
|
|
170
|
+
const where = target.covers.length > 1 ? target.covers.join(', ') : target.label;
|
|
171
|
+
state.chatScope = { owner: target.owner, label: `Agent “${agentName}” · run on ${where}`, chatId: target.chatId };
|
|
172
|
+
paint();
|
|
173
|
+
// The person asked to see it: a collapsed AI Chat opens (the same route left-pane.js uses).
|
|
174
|
+
if (document.getElementById('app')?.classList.contains('left-collapsed')) {
|
|
175
|
+
document.querySelector('.pane-rail-left .panel-toggle[data-side="left"]')?.click();
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const opened = await window.flolessChat?.openConversationIn?.(state.chatScope, target.chatId);
|
|
179
|
+
if (opened === false) toast('This run’s conversation could not be opened. Use Open in project to find it.', 'warn');
|
|
180
|
+
} catch (error) {
|
|
181
|
+
toast(error?.message || 'This run’s conversation could not be opened.', 'warn');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function backToWorkspaceChat() {
|
|
186
|
+
state.selected = null;
|
|
187
|
+
state.chatScope = null;
|
|
188
|
+
paint();
|
|
189
|
+
notifyChatScope();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ── data ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
193
|
+
|
|
194
|
+
async function loadAgents() {
|
|
195
|
+
state.loading = true; state.loadError = null; paint();
|
|
196
|
+
try {
|
|
197
|
+
const body = await api('/api/chat/agents');
|
|
198
|
+
state.agents = body.agents || []; state.unreadable = body.unreadable || [];
|
|
199
|
+
} catch (error) { state.loadError = error.message; }
|
|
200
|
+
finally { state.loading = false; }
|
|
201
|
+
paint();
|
|
202
|
+
// The scope names on the cards come from the project and workflow lists; they fill in when those arrive.
|
|
203
|
+
if (!state.options) void loadOptions().then(paint);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function loadRuns() {
|
|
207
|
+
if (!state.agent) { state.runs = []; return; }
|
|
208
|
+
const generation = state.pageGeneration;
|
|
209
|
+
try {
|
|
210
|
+
const body = await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}/runs`);
|
|
211
|
+
if (generation !== state.pageGeneration) return;
|
|
212
|
+
const runs = body.runs || [];
|
|
213
|
+
const problem = typeof body.problem === 'string' ? body.problem : null;
|
|
214
|
+
const key = JSON.stringify([runs, body.unreadable || [], Boolean(body.paused), problem]);
|
|
215
|
+
const hadError = Boolean(state.runsError);
|
|
216
|
+
state.runs = runs; state.runsUnreadable = body.unreadable || []; state.runsPaused = Boolean(body.paused);
|
|
217
|
+
state.runsProblem = problem; state.runsError = null;
|
|
218
|
+
// A poll that changed nothing repaints nothing, and one that did repaints only the Runs section: rebuilding the
|
|
219
|
+
// whole page every few seconds would swap a button out from under a click.
|
|
220
|
+
if (key !== state.runsKey || hadError) { state.runsKey = key; paintRuns(); }
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (generation !== state.pageGeneration) return;
|
|
223
|
+
// Shown in the Runs section only, and cleared by the next poll that works: a passing hiccup never sticks.
|
|
224
|
+
const changed = state.runsError !== error.message;
|
|
225
|
+
state.runsError = error.message;
|
|
226
|
+
if (changed) paintRuns();
|
|
227
|
+
}
|
|
228
|
+
schedulePoll();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function paintRuns() {
|
|
232
|
+
if (!state.open || state.view !== 'page') return;
|
|
233
|
+
const current = $surface.querySelector('.ag-runs');
|
|
234
|
+
if (!current || !state.agent) { paint(); return; }
|
|
235
|
+
const focusedCommand = current.contains(document.activeElement) ? document.activeElement.dataset.commandId : null;
|
|
236
|
+
const next = renderRuns();
|
|
237
|
+
current.replaceWith(next);
|
|
238
|
+
if (focusedCommand) [...next.querySelectorAll('[data-command-id]')].find((node) => node.dataset.commandId === focusedCommand)?.focus({ preventScroll: true });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Still changing, so the Runs list keeps checking: a run that needs you changes when you recover or answer it.
|
|
242
|
+
const MOVING = new Set(['waiting', 'starting', 'working', 'waiting-for-you', 'needs-recovery']);
|
|
243
|
+
function schedulePoll() {
|
|
244
|
+
clearTimeout(state.pollTimer);
|
|
245
|
+
if (!state.open || state.view !== 'page') return;
|
|
246
|
+
const moving = state.runs.some((run) => run.targets.some((target) => MOVING.has(target.live)));
|
|
247
|
+
if (moving) state.pollTimer = setTimeout(() => { void loadRuns(); }, 4000);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function blankDraft() {
|
|
251
|
+
// Default scope is where you came from (#1337, 2026-10-02): the project or workflow you last had open.
|
|
252
|
+
const scope = [];
|
|
253
|
+
let lastProject = null;
|
|
254
|
+
try { lastProject = localStorage.getItem('floless:last-project'); } catch { /* private mode */ }
|
|
255
|
+
const project = lastProject && state.options?.projects.find((p) => p.id === lastProject);
|
|
256
|
+
if (project) scope.push({ kind: 'project', projectId: project.id, projectUuid: project.uuid });
|
|
257
|
+
return { name: '', instructions: '', scope, mode: 'separate', allowChanges: false };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function draftOf(agent) {
|
|
261
|
+
return { name: agent.name, instructions: agent.instructions, scope: agent.scope.map((s) => ({ ...s })), mode: agent.mode, allowChanges: agent.allowChanges };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ── navigation ───────────────────────────────────────────────────────────────────────────────────────────────
|
|
265
|
+
|
|
266
|
+
async function confirmLeave() {
|
|
267
|
+
if (state.view !== 'page' || !state.dirty) return true;
|
|
268
|
+
const choice = await dialog({
|
|
269
|
+
title: 'Unsaved changes',
|
|
270
|
+
sub: `“${state.draft?.name || 'This agent'}” has changes you haven’t saved.`,
|
|
271
|
+
actions: [
|
|
272
|
+
{ id: 'discard', label: 'Discard', commandId: 'shell.agents-leave-discard' },
|
|
273
|
+
{ id: 'stay', label: 'Stay', commandId: 'shell.agents-leave-stay' },
|
|
274
|
+
{ id: 'save', label: 'Save', primary: true, commandId: 'shell.agents-leave-save' },
|
|
275
|
+
],
|
|
276
|
+
});
|
|
277
|
+
if (choice === 'save') return save();
|
|
278
|
+
return choice === 'discard';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function openList() {
|
|
282
|
+
if (!(await confirmLeave())) return;
|
|
283
|
+
state.view = 'list'; state.agent = null; state.draft = null; state.dirty = false; state.banner = null; state.runs = [];
|
|
284
|
+
state.pageGeneration += 1; state.pickerOpen = false;
|
|
285
|
+
if (state.selected || state.chatScope) backToWorkspaceChat();
|
|
286
|
+
await loadAgents();
|
|
287
|
+
$surface.querySelector('#ag-landing-title')?.focus();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function openAgent(agentId) {
|
|
291
|
+
if (!(await confirmLeave())) return;
|
|
292
|
+
if (!state.options) await loadOptions();
|
|
293
|
+
state.pageGeneration += 1;
|
|
294
|
+
state.view = 'page'; state.banner = null; state.pickerOpen = false; state.runs = []; state.runsKey = null;
|
|
295
|
+
if (state.selected || state.chatScope) { state.selected = null; state.chatScope = null; notifyChatScope(); }
|
|
296
|
+
if (agentId) {
|
|
297
|
+
try {
|
|
298
|
+
const body = await api(`/api/chat/agents/${encodeURIComponent(agentId)}`);
|
|
299
|
+
state.agent = body.agent; state.draft = draftOf(body.agent); state.dirty = false;
|
|
300
|
+
} catch (error) { toast(error.message, 'warn'); state.view = 'list'; await loadAgents(); return; }
|
|
301
|
+
paint();
|
|
302
|
+
$surface.querySelector('#ag-name')?.focus();
|
|
303
|
+
await loadRuns();
|
|
304
|
+
} else {
|
|
305
|
+
state.agent = null; state.draft = blankDraft(); state.dirty = false;
|
|
306
|
+
paint();
|
|
307
|
+
$surface.querySelector('#ag-name')?.focus();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function markDirty() {
|
|
312
|
+
state.dirty = true;
|
|
313
|
+
const dirty = $surface.querySelector('.ag-dirty');
|
|
314
|
+
if (dirty) dirty.hidden = false;
|
|
315
|
+
const saveBtn = $surface.querySelector('#ag-save');
|
|
316
|
+
if (saveBtn) saveBtn.disabled = false;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async function save() {
|
|
320
|
+
if (state.saving) return false;
|
|
321
|
+
const draft = state.draft;
|
|
322
|
+
if (!draft.name.trim()) {
|
|
323
|
+
state.banner = { text: 'Give the agent a name before you save it.' };
|
|
324
|
+
paint(); $surface.querySelector('#ag-name')?.focus();
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
state.saving = true; paint();
|
|
328
|
+
try {
|
|
329
|
+
const body = state.agent
|
|
330
|
+
? await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}`, { method: 'PUT', body: { agent: draft, revision: state.agent.revision } })
|
|
331
|
+
: await api('/api/chat/agents', { method: 'POST', body: draft });
|
|
332
|
+
const created = !state.agent;
|
|
333
|
+
state.agent = body.agent; state.draft = draftOf(body.agent); state.dirty = false; state.banner = null;
|
|
334
|
+
toast(created ? `Agent “${body.agent.name}” created.` : 'Agent saved.', 'ok');
|
|
335
|
+
if (created) void loadRuns();
|
|
336
|
+
return true;
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error.code === 'agent-revision-stale' && error.body?.agent) {
|
|
339
|
+
const current = error.body.agent;
|
|
340
|
+
state.banner = { text: error.message, action: { label: 'Load the current version', commandId: 'shell.agents-reload', run: () => {
|
|
341
|
+
state.agent = current; state.draft = draftOf(current); state.dirty = false; state.banner = null; paint();
|
|
342
|
+
} } };
|
|
343
|
+
} else state.banner = { text: error.message };
|
|
344
|
+
return false;
|
|
345
|
+
} finally { state.saving = false; paint(); }
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async function setArchived(archived) {
|
|
349
|
+
if (!state.agent) return;
|
|
350
|
+
if (archived) {
|
|
351
|
+
// Unsaved edits are the person's to keep or drop, never lost by an Archive that only asked about archiving.
|
|
352
|
+
const dirty = state.dirty;
|
|
353
|
+
const choice = await dialog({
|
|
354
|
+
title: `Archive “${state.agent.name}”?`,
|
|
355
|
+
sub: dirty
|
|
356
|
+
? 'It moves to Archived and can’t be run until you restore it. Past runs are kept, and runs already going keep going. You have unsaved changes: save them first, or archive without them.'
|
|
357
|
+
: 'It moves to Archived and can’t be run until you restore it. Past runs are kept, and runs already going keep going.',
|
|
358
|
+
actions: dirty ? [
|
|
359
|
+
{ id: 'cancel', label: 'Cancel', commandId: 'shell.agents-archive-cancel' },
|
|
360
|
+
{ id: 'discard', label: 'Archive without changes', commandId: 'shell.agents-archive-discard' },
|
|
361
|
+
{ id: 'save', label: 'Save and archive', primary: true, commandId: 'shell.agents-archive-save' },
|
|
362
|
+
] : [
|
|
363
|
+
{ id: 'cancel', label: 'Cancel', commandId: 'shell.agents-archive-cancel' },
|
|
364
|
+
{ id: 'archive', label: 'Archive', primary: true, commandId: 'shell.agents-archive-confirm' },
|
|
365
|
+
],
|
|
366
|
+
});
|
|
367
|
+
if (choice !== 'archive' && choice !== 'discard' && choice !== 'save') return;
|
|
368
|
+
if (choice === 'save' && !(await save())) return; // a save that failed says why and keeps the edits
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
const body = await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}/archive`, { method: 'POST', body: { archived, revision: state.agent.revision } });
|
|
372
|
+
state.agent = body.agent; state.draft = draftOf(body.agent); state.dirty = false; state.banner = null;
|
|
373
|
+
toast(archived ? 'Agent archived.' : 'Agent restored.', 'ok');
|
|
374
|
+
paint();
|
|
375
|
+
} catch (error) { state.banner = { text: error.message }; paint(); }
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ── run ──────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
379
|
+
|
|
380
|
+
function preferredProvider() {
|
|
381
|
+
let stored = null;
|
|
382
|
+
try { stored = localStorage.getItem(LS_PROVIDER); } catch { /* private mode */ }
|
|
383
|
+
return stored === 'codex' || stored === 'claude' ? stored : 'claude';
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async function openRunSheet() {
|
|
387
|
+
if (state.dirty || !state.agent) {
|
|
388
|
+
const saved = await save();
|
|
389
|
+
if (!saved) return;
|
|
390
|
+
}
|
|
391
|
+
let provider = state.agent.provider || preferredProvider();
|
|
392
|
+
let preview = null;
|
|
393
|
+
let error = null;
|
|
394
|
+
const backdrop = el('div', { class: 'modal-backdrop show ag-run-modal', role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': 'ag-run-title' });
|
|
395
|
+
const modal = el('div', { class: 'modal ag-run-sheet' });
|
|
396
|
+
backdrop.append(modal);
|
|
397
|
+
document.body.append(backdrop);
|
|
398
|
+
const previous = document.activeElement;
|
|
399
|
+
let busy = false;
|
|
400
|
+
const close = () => {
|
|
401
|
+
backdrop.remove(); document.removeEventListener('keydown', onKey, true);
|
|
402
|
+
if (previous?.isConnected) previous.focus();
|
|
403
|
+
};
|
|
404
|
+
const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); close(); } };
|
|
405
|
+
document.addEventListener('keydown', onKey, true);
|
|
406
|
+
backdrop.addEventListener('mousedown', (event) => { if (event.target === backdrop) close(); });
|
|
407
|
+
|
|
408
|
+
const load = async () => {
|
|
409
|
+
error = null;
|
|
410
|
+
try { preview = (await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}/run/preview`, { method: 'POST', body: { provider } })).preview; }
|
|
411
|
+
catch (failure) { error = failure.message; }
|
|
412
|
+
render();
|
|
413
|
+
};
|
|
414
|
+
const start = async () => {
|
|
415
|
+
if (busy || !preview) return;
|
|
416
|
+
busy = true; render();
|
|
417
|
+
try {
|
|
418
|
+
try { localStorage.setItem(LS_PROVIDER, provider); } catch { /* private mode */ }
|
|
419
|
+
const body = await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}/runs`, { method: 'POST',
|
|
420
|
+
body: { runKey: preview.runKey, previewToken: preview.previewToken, provider } });
|
|
421
|
+
close();
|
|
422
|
+
// They start in the background (some may wait their turn), so this says what was set going, not what began.
|
|
423
|
+
const queued = body.run.targets.filter((t) => t.live !== 'skipped').length;
|
|
424
|
+
toast(`${state.agent.name}: ${queued} conversation${queued === 1 ? '' : 's'} on the way. Each row below shows when it starts.`, 'ok');
|
|
425
|
+
await loadRuns();
|
|
426
|
+
$surface.querySelector('#ag-runs-title')?.focus();
|
|
427
|
+
} catch (failure) {
|
|
428
|
+
if (failure.code === 'agent-run-preview-changed' && failure.body?.preview) { preview = failure.body.preview; error = failure.message; }
|
|
429
|
+
else error = failure.message;
|
|
430
|
+
busy = false; render();
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const render = () => {
|
|
434
|
+
modal.replaceChildren();
|
|
435
|
+
modal.append(el('div', { class: 'modal-title', id: 'ag-run-title', text: preview && !preview.canRun && preview.issues.some((i) => i.kind !== 'provider')
|
|
436
|
+
? 'Nothing to run yet' : `Run “${state.agent.name}”?` }));
|
|
437
|
+
if (!preview && !error) { modal.append(el('div', { class: 'modal-sub', text: 'Checking what this run will start…' })); return; }
|
|
438
|
+
if (error) modal.append(el('div', { class: 'ag-banner', role: 'alert', text: error }));
|
|
439
|
+
if (!preview) { modal.append(el('div', { class: 'modal-actions' }, el('button', { type: 'button', text: 'Close', 'data-command-id': 'shell.agents-run-cancel', onclick: close }))); return; }
|
|
440
|
+
const nonProvider = preview.issues.filter((i) => i.kind !== 'provider');
|
|
441
|
+
for (const issue of nonProvider) modal.append(el('p', { class: 'ag-run-issue', text: issue.message }));
|
|
442
|
+
if (preview.conversations.length) {
|
|
443
|
+
const count = preview.conversations.length;
|
|
444
|
+
const head = preview.mode === 'compare'
|
|
445
|
+
? `This starts one conversation across ${preview.conversations[0].covers.join(', ')}.`
|
|
446
|
+
: count === 1 ? 'This starts one conversation, on:' : `This starts ${count} conversations, one per project or workflow:`;
|
|
447
|
+
modal.append(el('p', { class: 'modal-sub', text: head }));
|
|
448
|
+
if (preview.mode !== 'compare') {
|
|
449
|
+
modal.append(el('ul', { class: 'ag-run-list' }, preview.conversations.map((c) => el('li', { text: c.home }))));
|
|
450
|
+
} else modal.append(el('p', { class: 'ag-run-line', text: `Home: ${preview.conversations[0].home}` }));
|
|
451
|
+
}
|
|
452
|
+
const skipped = preview.items.filter((item) => !item.available);
|
|
453
|
+
if (skipped.length && preview.conversations.length) {
|
|
454
|
+
modal.append(el('div', { class: 'ag-run-skipped' }, skipped.map((item) => el('p', { text: item.reason }))));
|
|
455
|
+
}
|
|
456
|
+
// The AI that answers.
|
|
457
|
+
const seg = el('div', { class: 'ag-seg', role: 'radiogroup', 'aria-label': 'Which AI runs this' });
|
|
458
|
+
for (const [value, label] of [['claude', 'Claude'], ['codex', 'Codex']]) {
|
|
459
|
+
seg.append(el('button', { type: 'button', role: 'radio', 'aria-checked': String(provider === value), class: provider === value ? 'on' : '',
|
|
460
|
+
'data-command-id': `shell.agents-run-provider#${label}`, disabled: busy,
|
|
461
|
+
onclick: () => { if (provider !== value) { provider = value; preview = null; render(); void load(); } } }, label));
|
|
462
|
+
}
|
|
463
|
+
modal.append(el('div', { class: 'ag-run-field' }, el('span', { class: 'ag-run-label', text: 'AI' }), seg));
|
|
464
|
+
if (preview.providerMessage) modal.append(el('p', { class: 'ag-run-issue', role: 'status', text: preview.providerMessage }));
|
|
465
|
+
if (preview.conversations.length) {
|
|
466
|
+
modal.append(el('p', { class: 'ag-run-line', text: preview.allowChanges
|
|
467
|
+
? 'Can change files: yes, in the project or workflow each conversation is homed in. A file edit anywhere else asks you first; commands follow your Claude or Codex approval settings.'
|
|
468
|
+
: 'Can change files: no — it reads and reports.' }));
|
|
469
|
+
if (preview.conversations.length > preview.maxActive) modal.append(el('p', { class: 'ag-run-line', text: `Up to ${preview.maxActive} run at a time; the rest wait their turn.` }));
|
|
470
|
+
modal.append(el('p', { class: 'ag-note', text: isolationNote(preview.mode, preview.allowChanges) }));
|
|
471
|
+
}
|
|
472
|
+
const actions = el('div', { class: 'modal-actions' });
|
|
473
|
+
actions.append(el('button', { type: 'button', text: 'Cancel', 'data-command-id': 'shell.agents-run-cancel', onclick: close }));
|
|
474
|
+
if (nonProvider.length) {
|
|
475
|
+
const fixable = nonProvider.some((i) => i.kind === 'no-scope' || i.kind === 'nothing-available' || i.kind === 'no-instructions');
|
|
476
|
+
if (fixable) {
|
|
477
|
+
actions.append(el('button', { type: 'button', class: 'primary', text: nonProvider.some((i) => i.kind === 'no-instructions') && !nonProvider.some((i) => i.kind !== 'no-instructions') ? 'Write instructions' : 'Edit scope',
|
|
478
|
+
'data-command-id': 'shell.agents-run-edit', onclick: () => {
|
|
479
|
+
close();
|
|
480
|
+
const target = nonProvider.some((i) => i.kind !== 'no-instructions') ? '#ag-scope-add' : '#ag-instructions';
|
|
481
|
+
$surface.querySelector(target)?.focus();
|
|
482
|
+
} }));
|
|
483
|
+
}
|
|
484
|
+
} else {
|
|
485
|
+
actions.append(el('button', { type: 'button', class: 'primary', 'data-command-id': 'shell.agents-run-confirm',
|
|
486
|
+
disabled: busy || !preview.canRun, text: busy ? 'Starting…' : skipped.length ? 'Run on the rest' : 'Run', onclick: start,
|
|
487
|
+
'data-blocked-reason': busy ? 'Starting this run now.' : !preview.canRun ? (preview.providerMessage || preview.issues[0]?.message || 'This agent can’t run yet.') : null }));
|
|
488
|
+
}
|
|
489
|
+
modal.append(actions);
|
|
490
|
+
(actions.querySelector('button.primary:not([disabled])') || actions.querySelector('button'))?.focus();
|
|
491
|
+
};
|
|
492
|
+
render();
|
|
493
|
+
await load();
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function isolationNote(mode, allowChanges) {
|
|
497
|
+
const where = mode === 'compare' ? 'This run is told only about these projects' : 'Each run is told only about its own project';
|
|
498
|
+
const change = allowChanges
|
|
499
|
+
? '; it may change files in the project or workflow its conversation is homed in, and a file edit anywhere else asks you first'
|
|
500
|
+
: ' and only reads';
|
|
501
|
+
return `${where}${change}. This is not a lock: the AI on this computer can still open other folders you can open.`;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async function retryTarget(run, target) {
|
|
505
|
+
if (target.retryNeedsConfirm) {
|
|
506
|
+
const choice = await dialog({
|
|
507
|
+
title: 'Start this one again?',
|
|
508
|
+
sub: 'FloLess can’t tell whether this one already started. Starting again may send the instructions to its conversation a second time.',
|
|
509
|
+
actions: [
|
|
510
|
+
{ id: 'cancel', label: 'Cancel', commandId: 'shell.agents-retry-cancel' },
|
|
511
|
+
{ id: 'go', label: 'Start again', primary: true, commandId: 'shell.agents-retry-confirm' },
|
|
512
|
+
],
|
|
513
|
+
});
|
|
514
|
+
if (choice !== 'go') return;
|
|
515
|
+
}
|
|
516
|
+
try {
|
|
517
|
+
await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}/runs/${encodeURIComponent(run.runId)}/targets/${target.index}/retry`,
|
|
518
|
+
{ method: 'POST', body: { confirmed: Boolean(target.retryNeedsConfirm) } });
|
|
519
|
+
} catch (error) { toast(error.message, 'warn'); }
|
|
520
|
+
await loadRuns();
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
async function cancelTarget(run, target) {
|
|
524
|
+
try {
|
|
525
|
+
await api(`/api/chat/agents/${encodeURIComponent(state.agent.agentId)}/runs/${encodeURIComponent(run.runId)}/targets/${target.index}/cancel`, { method: 'POST', body: {} });
|
|
526
|
+
} catch (error) { toast(error.message, 'warn'); }
|
|
527
|
+
await loadRuns();
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
async function openInProject(target) {
|
|
531
|
+
if (!(await confirmLeave())) return;
|
|
532
|
+
state.dirty = false;
|
|
533
|
+
try {
|
|
534
|
+
await window.flolessWorkspaces.openChatOwner(target.owner);
|
|
535
|
+
await window.flolessChat?.openConversationIn?.({ owner: target.owner, label: target.label }, target.chatId);
|
|
536
|
+
} catch (error) { toast(error?.message || 'That project could not be opened. Open it from Workspaces.', 'warn'); }
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// ── a small themed dialog (no native confirm: it would leak the OS theme) ──────────────────────────────────────
|
|
540
|
+
|
|
541
|
+
function dialog({ title, sub, actions }) {
|
|
542
|
+
return new Promise((resolve) => {
|
|
543
|
+
const previous = document.activeElement;
|
|
544
|
+
const backdrop = el('div', { class: 'modal-backdrop show ag-dialog', role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': 'ag-dialog-title' });
|
|
545
|
+
const finish = (value) => { backdrop.remove(); document.removeEventListener('keydown', onKey, true); if (previous?.isConnected) previous.focus(); resolve(value); };
|
|
546
|
+
const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); finish(null); } };
|
|
547
|
+
backdrop.append(el('div', { class: 'modal' },
|
|
548
|
+
el('div', { class: 'modal-title', id: 'ag-dialog-title', text: title }),
|
|
549
|
+
el('div', { class: 'modal-sub', text: sub }),
|
|
550
|
+
el('div', { class: 'modal-actions' }, actions.map((action) => el('button', { type: 'button', class: action.primary ? 'primary' : '',
|
|
551
|
+
'data-command-id': action.commandId, text: action.label, onclick: () => finish(action.id) })))));
|
|
552
|
+
document.addEventListener('keydown', onKey, true);
|
|
553
|
+
document.body.append(backdrop);
|
|
554
|
+
backdrop.querySelector('button.primary')?.focus();
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// ── render ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
559
|
+
|
|
560
|
+
function paint() {
|
|
561
|
+
if (!state.open) return;
|
|
562
|
+
const scrollTop = $surface.scrollTop;
|
|
563
|
+
const focusId = document.activeElement?.id && $surface.contains(document.activeElement) ? document.activeElement.id : null;
|
|
564
|
+
const caret = focusId && document.activeElement.selectionStart !== undefined
|
|
565
|
+
? [document.activeElement.selectionStart, document.activeElement.selectionEnd] : null;
|
|
566
|
+
$surface.replaceChildren(state.view === 'page' ? renderPage() : renderList());
|
|
567
|
+
$surface.scrollTop = scrollTop;
|
|
568
|
+
if (focusId) {
|
|
569
|
+
const node = document.getElementById(focusId);
|
|
570
|
+
if (node && $surface.contains(node)) {
|
|
571
|
+
node.focus({ preventScroll: true });
|
|
572
|
+
if (caret && typeof node.setSelectionRange === 'function') { try { node.setSelectionRange(caret[0], caret[1]); } catch { /* not a text field */ } }
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function renderList() {
|
|
578
|
+
const active = state.agents.filter((agent) => !agent.archivedAt);
|
|
579
|
+
const archived = state.agents.filter((agent) => agent.archivedAt);
|
|
580
|
+
const rows = state.showArchived ? archived : active;
|
|
581
|
+
const wrap = el('div', { class: 'ag-list' });
|
|
582
|
+
const head = el('div', { class: 'ws-head' },
|
|
583
|
+
el('div', { class: 'ws-head-text' },
|
|
584
|
+
el('h2', { id: 'ag-landing-title', tabindex: '-1', text: 'Agents' }),
|
|
585
|
+
el('p', { class: 'ws-sub', text: 'An agent is a responsibility you hand over: what to check, and where. You run it by hand and review what it finds in AI Chat.' })));
|
|
586
|
+
if (archived.length) {
|
|
587
|
+
const seg = el('div', { class: 'ag-seg', role: 'radiogroup', 'aria-label': 'Which agents to show' });
|
|
588
|
+
for (const [value, label] of [[false, 'Active'], [true, `Archived (${archived.length})`]]) {
|
|
589
|
+
seg.append(el('button', { type: 'button', role: 'radio', 'aria-checked': String(state.showArchived === value), class: state.showArchived === value ? 'on' : '',
|
|
590
|
+
'data-command-id': `shell.agents-filter#${value ? 'Archived' : 'Active'}`, onclick: () => { state.showArchived = value; paint(); } }, label));
|
|
591
|
+
}
|
|
592
|
+
head.append(el('div', { class: 'ws-head-actions' }, seg));
|
|
593
|
+
}
|
|
594
|
+
wrap.append(head);
|
|
595
|
+
if (!state.showArchived) {
|
|
596
|
+
wrap.append(el('div', { class: 'ws-create-grid' },
|
|
597
|
+
el('div', { class: 'ws-card ws-create ag-create', role: 'button', tabindex: '0', 'data-ag-new': '1', 'data-command-id': 'shell.agents-new' },
|
|
598
|
+
el('div', { class: 'ws-thumb', 'aria-hidden': 'true', text: '+' }),
|
|
599
|
+
el('div', { class: 'ws-body' }, el('div', {},
|
|
600
|
+
el('div', { class: 'ws-name', text: 'New agent' }),
|
|
601
|
+
el('div', { class: 'ws-meta', text: 'Name it, say what to check and where. Runs show up in AI Chat.' }))))));
|
|
602
|
+
}
|
|
603
|
+
if (state.loading && !state.agents.length) wrap.append(el('div', { class: 'ws-empty-note', role: 'status', text: 'Loading agents…' }));
|
|
604
|
+
else if (state.loadError) {
|
|
605
|
+
wrap.append(el('div', { class: 'ag-banner', role: 'alert' }, el('span', { text: state.loadError }),
|
|
606
|
+
el('button', { type: 'button', class: 'ag-link', text: 'Try again', 'data-command-id': 'shell.agents-reload-list', onclick: () => void loadAgents() })));
|
|
607
|
+
} else if (!rows.length) {
|
|
608
|
+
wrap.append(el('div', { class: 'ws-empty-note', text: state.showArchived ? 'No archived agents.'
|
|
609
|
+
: 'No agents yet. Start with New agent: give it a name, say what it should check, and choose the projects it works on.' }));
|
|
610
|
+
} else {
|
|
611
|
+
wrap.append(el('div', { class: 'ws-grid' }, rows.map((agent) => el('div', { class: `ws-card wf-card ag-card${agent.archivedAt ? ' is-archived' : ''}`, role: 'button', tabindex: '0',
|
|
612
|
+
'data-ag-id': agent.agentId, 'data-command-id': `shell.agents-open#${agent.name}`, 'data-command-instance-label': agent.name },
|
|
613
|
+
el('div', { class: 'ws-body' }, el('div', { class: 'wf-card-text' },
|
|
614
|
+
el('span', { class: 'ws-kind wf-kind', text: agent.archivedAt ? 'Archived' : agent.mode === 'compare' && agent.scope.length > 1 ? 'Compares' : 'Agent' }),
|
|
615
|
+
el('div', { class: 'ws-name', text: agent.name }),
|
|
616
|
+
el('div', { class: 'ws-meta', text: scopeSummary(agent) }),
|
|
617
|
+
el('div', { class: 'ws-meta wf-card-nodes', text: agent.lastRunAt ? `Last run ${agoText(agent.lastRunAt)}` : agent.lastRunUnreadable ? 'Last run unknown' : 'Never run' })))))));
|
|
618
|
+
}
|
|
619
|
+
if (state.unreadable.length) {
|
|
620
|
+
wrap.append(el('div', { class: 'ag-banner', role: 'status', text: `${state.unreadable.length} agent${state.unreadable.length === 1 ? '' : 's'} could not be read and ${state.unreadable.length === 1 ? 'is' : 'are'} not shown. Its saved file may be damaged.` }));
|
|
621
|
+
}
|
|
622
|
+
return wrap;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function renderPage() {
|
|
626
|
+
const draft = state.draft;
|
|
627
|
+
const archived = Boolean(state.agent?.archivedAt);
|
|
628
|
+
const page = el('div', { class: 'ag-page' });
|
|
629
|
+
page.append(el('div', { class: 'ag-head' },
|
|
630
|
+
el('button', { type: 'button', class: 'ag-back', 'data-command-id': 'shell.agents-back', 'aria-label': 'Back to all agents', 'data-tip': 'Back to all agents', onclick: () => void openList() }, '‹ Agents'),
|
|
631
|
+
el('input', { id: 'ag-name', class: 'ag-name', type: 'text', value: draft.name, maxlength: '120', placeholder: 'Name this agent', 'aria-label': 'Agent name',
|
|
632
|
+
autocomplete: 'off', spellcheck: 'false', disabled: archived, 'data-command-id': 'shell.agents-name',
|
|
633
|
+
oninput: (event) => { draft.name = event.target.value; markDirty(); } }),
|
|
634
|
+
el('span', { class: 'ag-dirty', hidden: !state.dirty, text: 'Unsaved changes' }),
|
|
635
|
+
el('div', { class: 'ag-head-actions' },
|
|
636
|
+
archived
|
|
637
|
+
? el('button', { type: 'button', class: 'primary', 'data-command-id': 'shell.agents-restore', text: 'Restore', onclick: () => void setArchived(false) })
|
|
638
|
+
: [
|
|
639
|
+
state.agent ? el('button', { type: 'button', class: 'ag-quiet', 'data-command-id': 'shell.agents-archive', text: 'Archive', onclick: () => void setArchived(true) }) : null,
|
|
640
|
+
el('button', { type: 'button', id: 'ag-save', 'data-command-id': 'shell.agents-save', disabled: state.saving || (!state.dirty && Boolean(state.agent)),
|
|
641
|
+
'data-blocked-reason': state.saving ? 'Saving now.' : !state.dirty && state.agent ? 'Nothing has changed since you last saved.' : null,
|
|
642
|
+
text: state.saving ? 'Saving…' : state.agent ? 'Save' : 'Create', onclick: () => void save() }),
|
|
643
|
+
el('button', { type: 'button', id: 'ag-run', class: 'primary', 'data-command-id': 'shell.agents-run', text: 'Run…',
|
|
644
|
+
'data-tip': state.dirty || !state.agent ? 'Saves your changes, then shows what will start' : 'Shows exactly what will start before anything runs',
|
|
645
|
+
onclick: () => void openRunSheet() }),
|
|
646
|
+
])));
|
|
647
|
+
if (state.banner) {
|
|
648
|
+
page.append(el('div', { class: 'ag-banner', role: 'alert' }, el('span', { text: state.banner.text }),
|
|
649
|
+
state.banner.action ? el('button', { type: 'button', class: 'ag-link', 'data-command-id': state.banner.action.commandId, text: state.banner.action.label, onclick: state.banner.action.run }) : null));
|
|
650
|
+
}
|
|
651
|
+
if (archived) page.append(el('p', { class: 'ag-note', text: 'This agent is archived. Restore it to change or run it. Its past runs are below.' }));
|
|
652
|
+
|
|
653
|
+
// What it does
|
|
654
|
+
const count = el('div', { class: 'ag-count', id: 'ag-count', 'aria-live': 'polite' });
|
|
655
|
+
const paintCount = () => {
|
|
656
|
+
const n = draft.instructions.length;
|
|
657
|
+
count.textContent = n >= 8000 ? 'You’ve reached the limit of 8,000 characters.' : n > 7200 ? `${n.toLocaleString('en-US')} / 8,000` : '';
|
|
658
|
+
};
|
|
659
|
+
paintCount();
|
|
660
|
+
page.append(el('section', { class: 'ag-section' },
|
|
661
|
+
el('label', { class: 'ag-label', for: 'ag-instructions', text: 'What should it do?' }),
|
|
662
|
+
el('p', { class: 'ag-help', text: 'Plain English, as you would brief a colleague. This is the first message of every run.' }),
|
|
663
|
+
el('textarea', { id: 'ag-instructions', class: 'ag-instructions', rows: '7', maxlength: '8000', disabled: archived, 'data-command-id': 'shell.agents-instructions',
|
|
664
|
+
placeholder: 'For example: List the RFIs that are still open, oldest first, with who they are waiting on.',
|
|
665
|
+
oninput: (event) => { draft.instructions = event.target.value; paintCount(); markDirty(); } }, draft.instructions),
|
|
666
|
+
count));
|
|
667
|
+
|
|
668
|
+
// Where it works
|
|
669
|
+
const chips = el('div', { class: 'ag-chips', role: 'list', 'aria-label': 'Projects and workflows this agent works on' });
|
|
670
|
+
if (!draft.scope.length) chips.append(el('span', { class: 'ag-empty', text: 'Nothing yet. Add a project or workflow.' }));
|
|
671
|
+
draft.scope.forEach((entry, i) => {
|
|
672
|
+
const label = scopeLabel(entry);
|
|
673
|
+
const ok = scopeAvailable(entry);
|
|
674
|
+
chips.append(el('span', { class: `ag-chip${ok ? '' : ' is-missing'}`, role: 'listitem' },
|
|
675
|
+
el('span', { class: 'ag-chip-kind', text: entry.kind === 'project' ? 'Project' : 'Workflow' }),
|
|
676
|
+
el('span', { class: 'ag-chip-name', text: label }),
|
|
677
|
+
ok ? null : el('span', { class: 'ag-chip-warn', text: 'Not available' }),
|
|
678
|
+
archived ? null : el('button', { type: 'button', class: 'ag-chip-x', 'aria-label': `Remove ${label}`, 'data-tip': `Remove ${label} from this agent`,
|
|
679
|
+
'data-command-id': `shell.agents-scope-remove#${label}`, 'data-command-instance-label': label,
|
|
680
|
+
onclick: () => { draft.scope.splice(i, 1); markDirty(); paint(); $surface.querySelector('#ag-scope-add')?.focus(); } }, '×')));
|
|
681
|
+
});
|
|
682
|
+
const scopeSection = el('section', { class: 'ag-section' },
|
|
683
|
+
el('h3', { class: 'ag-label', text: 'Where it works' }),
|
|
684
|
+
el('p', { class: 'ag-help', text: 'Only the projects and workflows you add. New projects are never added on their own.' }),
|
|
685
|
+
state.optionsError ? el('div', { class: 'ag-banner', role: 'alert', text: state.optionsError }) : null,
|
|
686
|
+
chips);
|
|
687
|
+
if (!archived) scopeSection.append(renderPicker());
|
|
688
|
+
page.append(scopeSection);
|
|
689
|
+
|
|
690
|
+
// How several projects are treated
|
|
691
|
+
if (draft.scope.length > 1) {
|
|
692
|
+
const seg = el('div', { class: 'ag-seg', role: 'radiogroup', 'aria-label': 'How it treats several projects' });
|
|
693
|
+
for (const [value, label] of [['separate', 'Each separately'], ['compare', 'Compare across them']]) {
|
|
694
|
+
seg.append(el('button', { type: 'button', role: 'radio', 'aria-checked': String(draft.mode === value), class: draft.mode === value ? 'on' : '', disabled: archived,
|
|
695
|
+
'data-command-id': `shell.agents-mode#${label}`, onclick: () => { if (draft.mode !== value) { draft.mode = value; markDirty(); paint(); } } }, label));
|
|
696
|
+
}
|
|
697
|
+
page.append(el('section', { class: 'ag-section' },
|
|
698
|
+
el('h3', { class: 'ag-label', text: 'How should it treat several projects?' }), seg,
|
|
699
|
+
el('p', { class: 'ag-help', text: draft.mode === 'compare'
|
|
700
|
+
? 'One conversation sees all of them together, to compare across them.'
|
|
701
|
+
: 'One conversation per project. Each is told about only its own project.' })));
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// Changes
|
|
705
|
+
page.append(el('section', { class: 'ag-section ag-switch-row' },
|
|
706
|
+
el('button', { type: 'button', class: 'kb-toggle', role: 'switch', id: 'ag-allow-changes', 'aria-checked': String(draft.allowChanges), disabled: archived,
|
|
707
|
+
'aria-labelledby': 'ag-allow-label', 'data-command-id': 'shell.agents-allow-changes',
|
|
708
|
+
onclick: () => { draft.allowChanges = !draft.allowChanges; markDirty(); paint(); } }),
|
|
709
|
+
el('div', {},
|
|
710
|
+
el('div', { class: 'ag-label', id: 'ag-allow-label', text: 'Can change files' }),
|
|
711
|
+
el('p', { class: 'ag-help', text: draft.allowChanges
|
|
712
|
+
? 'On: it may change files in the project or workflow its conversation is homed in. A file edit anywhere else asks you first; commands follow your Claude or Codex approval settings.'
|
|
713
|
+
: 'Off: it only reads and reports.' }))));
|
|
714
|
+
page.append(el('p', { class: 'ag-note', text: isolationNote(draft.mode, draft.allowChanges) }));
|
|
715
|
+
|
|
716
|
+
if (state.agent) page.append(renderRuns());
|
|
717
|
+
else page.append(el('p', { class: 'ag-help', text: 'Create the agent to run it. Its runs will be listed here.' }));
|
|
718
|
+
return page;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function renderPicker() {
|
|
722
|
+
const wrap = el('div', { class: 'ag-picker' });
|
|
723
|
+
const toggle = el('button', { type: 'button', id: 'ag-scope-add', class: 'ag-add', 'aria-haspopup': 'listbox', 'aria-expanded': String(state.pickerOpen),
|
|
724
|
+
'data-command-id': 'shell.agents-scope-add', onclick: () => { state.pickerOpen = !state.pickerOpen; state.pickerQuery = ''; paint();
|
|
725
|
+
if (state.pickerOpen) $surface.querySelector('#ag-scope-search')?.focus(); } }, '+ Add project or workflow');
|
|
726
|
+
wrap.append(toggle);
|
|
727
|
+
if (!state.pickerOpen) return wrap;
|
|
728
|
+
const taken = new Set(state.draft.scope.map(scopeKey));
|
|
729
|
+
const query = state.pickerQuery.trim().toLowerCase();
|
|
730
|
+
const match = (text) => !query || text.toLowerCase().includes(query);
|
|
731
|
+
const options = state.options || { projects: [], workflows: [] };
|
|
732
|
+
const projects = options.projects.filter((p) => !taken.has(`project:${p.id}`) && match(p.name));
|
|
733
|
+
const flows = options.workflows.filter((w) => !taken.has(`workflow:${w.workflowId}`) && match(`${w.displayName} ${w.ownerLabel}`));
|
|
734
|
+
const add = (entry) => {
|
|
735
|
+
if (state.draft.scope.length >= 32) { state.banner = { text: 'An agent can cover up to 32 projects and workflows. Remove one before adding another.' }; paint(); return; }
|
|
736
|
+
state.draft.scope.push(entry); state.pickerOpen = false; markDirty(); paint();
|
|
737
|
+
$surface.querySelector('#ag-scope-add')?.focus();
|
|
738
|
+
};
|
|
739
|
+
const pop = el('div', { class: 'wf-popover ag-popover' });
|
|
740
|
+
pop.append(el('div', { class: 'wf-search-wrap' }, el('input', { type: 'search', id: 'ag-scope-search', class: 'wf-search', placeholder: 'Search projects and workflows',
|
|
741
|
+
'aria-label': 'Search projects and workflows', autocomplete: 'off', spellcheck: 'false', value: state.pickerQuery, 'data-command-id': 'shell.agents-scope-search',
|
|
742
|
+
oninput: (event) => { state.pickerQuery = event.target.value; paint(); },
|
|
743
|
+
onkeydown: (event) => {
|
|
744
|
+
if (event.key === 'Escape') { event.stopPropagation(); state.pickerOpen = false; paint(); $surface.querySelector('#ag-scope-add')?.focus(); }
|
|
745
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); $surface.querySelector('.ag-popover .wf-option')?.focus(); }
|
|
746
|
+
} })));
|
|
747
|
+
const list = el('div', { class: 'wf-list', role: 'listbox', 'aria-label': 'Projects and workflows' });
|
|
748
|
+
const group = (title, rows, make) => {
|
|
749
|
+
if (!rows.length) return;
|
|
750
|
+
list.append(el('div', { class: 'wf-group' }, el('div', { class: 'wf-group-header', text: title }), rows.map(make)));
|
|
751
|
+
};
|
|
752
|
+
const optionKeys = (event) => {
|
|
753
|
+
const items = [...list.querySelectorAll('.wf-option')];
|
|
754
|
+
const i = items.indexOf(event.currentTarget);
|
|
755
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); items[Math.min(i + 1, items.length - 1)]?.focus(); }
|
|
756
|
+
if (event.key === 'ArrowUp') { event.preventDefault(); (i <= 0 ? $surface.querySelector('#ag-scope-search') : items[i - 1])?.focus(); }
|
|
757
|
+
if (event.key === 'Escape') { event.stopPropagation(); state.pickerOpen = false; paint(); $surface.querySelector('#ag-scope-add')?.focus(); }
|
|
758
|
+
};
|
|
759
|
+
// Two projects can share a name; the folder name tells them apart.
|
|
760
|
+
const named = new Map();
|
|
761
|
+
for (const p of options.projects) named.set(p.name, (named.get(p.name) || 0) + 1);
|
|
762
|
+
group('Projects', projects, (p) => el('button', { type: 'button', role: 'option', class: 'wf-option', 'aria-selected': 'false',
|
|
763
|
+
'data-command-id': `shell.agents-scope-option#${p.name}`, 'data-command-instance-label': p.name, onkeydown: optionKeys,
|
|
764
|
+
onclick: () => add({ kind: 'project', projectId: p.id, projectUuid: p.uuid }) }, el('span', { class: 'wf-option-name', text: p.name }),
|
|
765
|
+
named.get(p.name) > 1 ? el('span', { class: 'wf-option-meta', text: p.id }) : null));
|
|
766
|
+
group('Workflows', flows, (w) => el('button', { type: 'button', role: 'option', class: 'wf-option', 'aria-selected': 'false',
|
|
767
|
+
'data-command-id': `shell.agents-scope-option#${w.displayName}`, 'data-command-instance-label': w.displayName, onkeydown: optionKeys,
|
|
768
|
+
onclick: () => add({ kind: 'workflow', workflowId: w.workflowId }) }, el('span', { class: 'wf-option-name', text: w.displayName }), el('span', { class: 'wf-option-meta', text: w.ownerLabel })));
|
|
769
|
+
if (!projects.length && !flows.length) list.append(el('div', { class: 'ag-empty ag-pad', text: query ? 'Nothing matches that search.' : 'Every project and workflow is already in this agent.' }));
|
|
770
|
+
pop.append(list);
|
|
771
|
+
wrap.append(pop);
|
|
772
|
+
return wrap;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const LIVE_LABEL = {
|
|
776
|
+
waiting: 'Waiting', starting: 'Starting', working: 'Working', 'waiting-for-you': 'Waiting for you', 'needs-recovery': 'Needs you',
|
|
777
|
+
done: 'Done', 'failed-reply': 'Stopped with an error', stopped: 'Stopped', skipped: 'Skipped', failed: 'Didn’t start',
|
|
778
|
+
uncertain: 'Not sure it started', stale: 'Earlier workspace', archived: 'Archived', unreadable: 'Can’t open',
|
|
779
|
+
};
|
|
780
|
+
const LIVE_TONE = {
|
|
781
|
+
working: 'accent', starting: 'accent', 'waiting-for-you': 'warn', 'needs-recovery': 'warn', done: 'ok', 'failed-reply': 'err',
|
|
782
|
+
failed: 'warn', uncertain: 'warn', unreadable: 'warn',
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
function renderRuns() {
|
|
786
|
+
const section = el('section', { class: 'ag-section ag-runs' });
|
|
787
|
+
const head = el('div', { class: 'ag-runs-head' }, el('h3', { class: 'ag-label', id: 'ag-runs-title', tabindex: '-1', text: `Runs (${state.runs.length})` }));
|
|
788
|
+
if (state.chatScope) {
|
|
789
|
+
head.append(el('button', { type: 'button', class: 'ag-link', 'data-command-id': 'shell.agents-back-to-chat', text: 'Back to workspace chat',
|
|
790
|
+
'data-tip': 'AI Chat on the left goes back to the workspace conversation', onclick: () => backToWorkspaceChat() }));
|
|
791
|
+
}
|
|
792
|
+
section.append(head);
|
|
793
|
+
if (state.runsError) section.append(el('div', { class: 'ag-banner', role: 'alert', text: `Couldn’t refresh these runs: ${state.runsError}` }));
|
|
794
|
+
if (state.runsProblem) section.append(el('div', { class: 'ag-banner', role: 'alert', text: state.runsProblem }));
|
|
795
|
+
if (state.runsPaused) section.append(el('div', { class: 'ag-banner', role: 'alert', text: 'FloLess couldn’t finish checking conversations after it started, so agent runs are paused. Restart FloLess to try again.' }));
|
|
796
|
+
if (!state.runs.length) {
|
|
797
|
+
section.append(el('p', { class: 'ag-help', text: 'No runs yet. Press Run… to see exactly what will start.' }));
|
|
798
|
+
return section;
|
|
799
|
+
}
|
|
800
|
+
for (const run of state.runs) {
|
|
801
|
+
const group = el('div', { class: 'ag-run' });
|
|
802
|
+
group.append(el('div', { class: 'ag-run-meta', text: `${timeText(run.startedAt)} · ${run.provider === 'codex' ? 'Codex' : 'Claude'} · ${run.allowChanges ? 'can change files' : 'read only'}${run.mode === 'compare' ? ' · compare' : ''}` }));
|
|
803
|
+
for (const target of run.targets) {
|
|
804
|
+
const selected = state.selected?.runId === run.runId && state.selected?.index === target.index;
|
|
805
|
+
const canOpen = Boolean(target.chatId) && !['stale', 'skipped', 'unreadable'].includes(target.live);
|
|
806
|
+
const row = el('div', { class: `ag-target${selected ? ' is-selected' : ''}`, 'aria-current': selected ? 'true' : null });
|
|
807
|
+
const label = target.covers.length > 1 ? target.covers.join(' · ') : target.label;
|
|
808
|
+
const info = el('div', { class: 'ag-target-info' },
|
|
809
|
+
el('span', { class: 'ag-target-name', text: label }),
|
|
810
|
+
el('span', { class: `ag-state${LIVE_TONE[target.live] ? ` tone-${LIVE_TONE[target.live]}` : ''}`, text: LIVE_LABEL[target.live] || target.live }),
|
|
811
|
+
target.message ? el('span', { class: 'ag-target-msg', text: target.message }) : null);
|
|
812
|
+
row.append(info);
|
|
813
|
+
const actions = el('div', { class: 'ag-target-actions' });
|
|
814
|
+
if (canOpen) {
|
|
815
|
+
actions.append(el('button', { type: 'button', class: 'ag-act', 'data-command-id': `shell.agents-run-open#${label}`, 'data-command-instance-label': label,
|
|
816
|
+
text: selected ? 'Shown in AI Chat' : 'Open conversation', 'aria-pressed': String(selected),
|
|
817
|
+
'data-tip': 'Show this run’s conversation in AI Chat on the left',
|
|
818
|
+
onclick: () => { state.selected = { runId: run.runId, index: target.index }; void showRunInChat(target); } }));
|
|
819
|
+
actions.append(el('button', { type: 'button', class: 'ag-act ag-quiet', 'data-command-id': `shell.agents-run-open-home#${label}`, 'data-command-instance-label': label,
|
|
820
|
+
text: target.owner.kind === 'project' ? 'Open in project' : 'Open workflow', 'data-tip': 'Go to where this conversation is kept',
|
|
821
|
+
onclick: () => void openInProject(target) }));
|
|
822
|
+
}
|
|
823
|
+
if (target.canRetry) actions.append(el('button', { type: 'button', class: 'ag-act', 'data-command-id': `shell.agents-run-retry#${label}`, 'data-command-instance-label': label,
|
|
824
|
+
text: 'Start this one again', onclick: () => void retryTarget(run, target) }));
|
|
825
|
+
if (target.canCancel) actions.append(el('button', { type: 'button', class: 'ag-act ag-quiet', 'data-command-id': `shell.agents-run-cancel-target#${label}`, 'data-command-instance-label': label,
|
|
826
|
+
text: 'Don’t run this one', onclick: () => void cancelTarget(run, target) }));
|
|
827
|
+
row.append(actions);
|
|
828
|
+
group.append(row);
|
|
829
|
+
}
|
|
830
|
+
section.append(group);
|
|
831
|
+
}
|
|
832
|
+
if (state.runsUnreadable.length) section.append(el('p', { class: 'ag-help', text: `${state.runsUnreadable.length} earlier run record${state.runsUnreadable.length === 1 ? '' : 's'} could not be read.` }));
|
|
833
|
+
return section;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// ── landing interaction ──────────────────────────────────────────────────────────────────────────────────────
|
|
837
|
+
|
|
838
|
+
$surface.addEventListener('click', (event) => {
|
|
839
|
+
if (state.view !== 'list') return;
|
|
840
|
+
const card = event.target.closest('[data-ag-id], [data-ag-new]');
|
|
841
|
+
if (!card) return;
|
|
842
|
+
void openAgent(card.dataset.agId || null);
|
|
843
|
+
});
|
|
844
|
+
$surface.addEventListener('keydown', (event) => {
|
|
845
|
+
if (state.view === 'list' && (event.key === 'Enter' || event.key === ' ')) {
|
|
846
|
+
const card = event.target.closest('[data-ag-id], [data-ag-new]');
|
|
847
|
+
if (card && event.target === card) { event.preventDefault(); void openAgent(card.dataset.agId || null); }
|
|
848
|
+
}
|
|
849
|
+
if (state.view === 'page' && event.key === 'Escape' && state.pickerOpen) { state.pickerOpen = false; paint(); }
|
|
850
|
+
});
|
|
851
|
+
document.addEventListener('mousedown', (event) => {
|
|
852
|
+
if (state.pickerOpen && !event.target.closest?.('.ag-picker')) { state.pickerOpen = false; paint(); }
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
// ── public ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
856
|
+
|
|
857
|
+
window.flolessAgents = {
|
|
858
|
+
/** Called by workspaces.js when the Agents tab opens or closes. */
|
|
859
|
+
show(on) {
|
|
860
|
+
const next = Boolean(on);
|
|
861
|
+
if (next === state.open) { if (next && state.view === 'list') void loadAgents(); return; }
|
|
862
|
+
state.open = next;
|
|
863
|
+
$surface.hidden = !next;
|
|
864
|
+
if (next) {
|
|
865
|
+
state.view = 'list'; void loadAgents();
|
|
866
|
+
} else {
|
|
867
|
+
clearTimeout(state.pollTimer);
|
|
868
|
+
state.selected = null; state.chatScope = null; state.pickerOpen = false;
|
|
869
|
+
}
|
|
870
|
+
},
|
|
871
|
+
isOpen: () => state.open,
|
|
872
|
+
/** The active Agents tab clicked again: back to the list (asks first about unsaved changes). */
|
|
873
|
+
home: () => openList(),
|
|
874
|
+
/** Leaving the tab with unsaved changes asks first; resolves false when the person chose to stay. */
|
|
875
|
+
confirmLeave,
|
|
876
|
+
/** What AI Chat shows here: a selected run's conversation, else the shared workspace conversation. */
|
|
877
|
+
chatScope() {
|
|
878
|
+
if (!state.open) return null;
|
|
879
|
+
if (state.chatScope) return { owner: state.chatScope.owner, label: state.chatScope.label, chatId: state.chatScope.chatId };
|
|
880
|
+
return { owner: { kind: 'workspace' }, label: state.view === 'page' && state.agent ? `Agents · ${state.agent.name}` : 'All projects and workflows' };
|
|
881
|
+
},
|
|
882
|
+
/** For AI Chat's context line: which Agents surface is on screen. */
|
|
883
|
+
surface: () => (state.view === 'page' ? 'agent-page' : 'agent-list'),
|
|
884
|
+
};
|
|
885
|
+
// workspaces.js applies the saved mode before this file loads; pick it up here.
|
|
886
|
+
if (document.body.classList.contains('mode-agents')) window.flolessAgents.show(true);
|
|
887
|
+
})();
|