@floless/app 0.155.2 → 0.156.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/cli-actions.mjs +376 -0
- package/dist/floless-server.cjs +100135 -86559
- package/dist/skills/floless-app-actions/SKILL.md +137 -0
- package/dist/skills/floless-app-approval/SKILL.md +8 -5
- package/dist/skills/floless-app-bridge/SKILL.md +12 -9
- package/dist/skills/floless-app-knowledge/SKILL.md +30 -13
- package/dist/skills/floless-app-new-workflow/SKILL.md +4 -4
- package/dist/skills/floless-app-onboarding/SKILL.md +1 -1
- package/dist/skills/floless-app-onboarding/references/aware-runtime.md +4 -4
- package/dist/skills/floless-app-queue/SKILL.md +10 -6
- package/dist/skills/floless-app-report-issue/SKILL.md +13 -10
- package/dist/skills/floless-app-rfi/SKILL.md +59 -68
- package/dist/skills/floless-app-routines/SKILL.md +19 -14
- package/dist/skills/floless-app-routines/references/routines-api.md +8 -2
- package/dist/skills/floless-app-workflows/SKILL.md +5 -4
- package/dist/web/agent-steps.js +933 -0
- package/dist/web/agents.js +5 -0
- package/dist/web/app.css +205 -3
- package/dist/web/app.js +1 -0
- package/dist/web/aware.js +584 -44
- package/dist/web/chat.css +9 -0
- package/dist/web/chat.js +195 -13
- package/dist/web/commands-shell.js +288 -1
- package/dist/web/index.html +52 -1
- package/dist/web/instructor.js +4 -2
- package/dist/web/leave-guard.js +4 -2
- package/dist/web/left-pane.js +8 -3
- package/dist/web/model-revit-module.js +15 -0
- package/dist/web/model-viewport-revit-adapter.js +3 -1
- package/dist/web/pages.js +27 -3
- package/dist/web/panels.js +3 -3
- package/dist/web/project-reconciliation.js +357 -0
- package/dist/web/revit-editor.js +116 -27
- package/dist/web/terminal-requests.js +541 -0
- package/dist/web/tool-updates.js +147 -13
- package/dist/web/workspaces.js +213 -12
- package/launch.mjs +80 -2
- package/package.json +1 -1
|
@@ -0,0 +1,933 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Agents as workflow steps, the canvas side (#2241, slice S3b).
|
|
3
|
+
*
|
|
4
|
+
* What this file does: it LABELS an Agent step honestly (card badge, Inspect blocks, the "newer instructions" banner, the
|
|
5
|
+
* header and picker marks) and it RELAYS "add / update an Agent step" to AI Chat by putting a drafted request, with the
|
|
6
|
+
* exact block the server wrote, into the chat composer for the person to send. It never edits a workflow, never calls an
|
|
7
|
+
* AI and never sends anything for the person: the UI is not the brain.
|
|
8
|
+
*
|
|
9
|
+
* Everything is hidden until the server says the feature is on (GET /api/agent-steps/status answers 404 while it is off).
|
|
10
|
+
* Loaded before aware.js and agents.js, which call window.flolessAgentSteps.
|
|
11
|
+
*/
|
|
12
|
+
(() => {
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const STEP_AGENT = 'floless-agent-step';
|
|
16
|
+
const STEP_COMMAND = 'reason';
|
|
17
|
+
const KEEP_PREFIX = 'floless:agent-step-keep:';
|
|
18
|
+
|
|
19
|
+
const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
20
|
+
const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
21
|
+
|
|
22
|
+
const model = {
|
|
23
|
+
enabled: null, // null = not known yet, true / false = the server's answer
|
|
24
|
+
probing: null,
|
|
25
|
+
checks: new Map(), // appId -> Map(nodeId -> check), the server's last answer
|
|
26
|
+
generation: new Map(), // appId -> the newest check ask, so an older answer cannot overwrite a newer one
|
|
27
|
+
context: { currentApp: () => null, openAgent: () => {}, openAgents: () => {}, toast: () => {}, repaint: () => {} },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// ── is the feature on ───────────────────────────────────────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
/** The server's answer, cached once it is definite. A network error is not an answer: the next call asks again. */
|
|
33
|
+
function probe() {
|
|
34
|
+
if (model.enabled !== null) return Promise.resolve(model.enabled);
|
|
35
|
+
if (!model.probing) {
|
|
36
|
+
model.probing = fetch('/api/agent-steps/status', { credentials: 'same-origin', ...(typeof AbortSignal !== 'undefined' && AbortSignal.timeout ? { signal: AbortSignal.timeout(4000) } : {}) })
|
|
37
|
+
.then((response) => { if (response.status === 404) model.enabled = false; else if (response.ok) model.enabled = true; if (model.enabled === true) startGateWatch(); return model.enabled === true; })
|
|
38
|
+
.catch(() => false)
|
|
39
|
+
.finally(() => { model.probing = null; });
|
|
40
|
+
}
|
|
41
|
+
return model.probing;
|
|
42
|
+
}
|
|
43
|
+
const enabled = () => model.enabled === true;
|
|
44
|
+
|
|
45
|
+
// ── reading a step ─────────────────────────────────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
/** A step is a `floless-agent-step/reason` node, or any node the approved lock marks `runtime-reasoning`. */
|
|
48
|
+
function isStepNode(node) {
|
|
49
|
+
if (!node) return false;
|
|
50
|
+
return node.runtimeReasoning === true || (node.agent === STEP_AGENT && node.command === STEP_COMMAND);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** What the step itself says (its source), so the card and Inspect never wait for the server. */
|
|
54
|
+
function stepFacts(node) {
|
|
55
|
+
const config = isRecord(node.config) ? node.config : {};
|
|
56
|
+
const sourceInputs = isRecord(node.sourceInputs) ? node.sourceInputs : {};
|
|
57
|
+
const lockInputs = isRecord(node.inputs) ? node.inputs : {};
|
|
58
|
+
// The SOURCE's own settings are what the person is looking at and what an update must carry over, read the way AWARE reads them
|
|
59
|
+
// (`config:` and `inputs:` merged, `inputs:` winning). The lock's resolved inputs may be older than the source, so they are used only
|
|
60
|
+
// when the source carries neither block (an older server that does not send `sourceInputs`).
|
|
61
|
+
const fromSource = { ...config, ...sourceInputs };
|
|
62
|
+
const merged = Object.keys(fromSource).length ? fromSource : lockInputs;
|
|
63
|
+
const body = isRecord(merged.body) ? merged.body : {};
|
|
64
|
+
const output = isRecord(body.output) ? body.output : { format: 'text' };
|
|
65
|
+
return {
|
|
66
|
+
instructions: typeof merged.instructions === 'string' ? merged.instructions : '',
|
|
67
|
+
agentId: typeof body['agent-id'] === 'string' ? body['agent-id'] : '',
|
|
68
|
+
name: typeof body['agent-name'] === 'string' && body['agent-name'] ? body['agent-name'] : 'this Agent',
|
|
69
|
+
revision: Number.isSafeInteger(body['agent-revision']) ? body['agent-revision'] : null,
|
|
70
|
+
provider: body.provider === 'codex' ? 'Codex' : body.provider === 'claude' ? 'Claude' : null,
|
|
71
|
+
output,
|
|
72
|
+
scopeCount: Array.isArray(body.scope) ? body.scope.length : 0,
|
|
73
|
+
context: typeof body.context === 'string' ? body.context : '',
|
|
74
|
+
timeoutMinutes: Number.isSafeInteger(body['timeout-minutes']) ? body['timeout-minutes'] : null,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function answerWords(output) {
|
|
79
|
+
if (!isRecord(output) || output.format !== 'json' || !isRecord(output.fields)) return 'Plain text';
|
|
80
|
+
const names = Object.keys(output.fields);
|
|
81
|
+
return names.length ? `A structured answer with: ${names.join(', ')}` : 'Plain text';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const plainDescription = (node) => {
|
|
85
|
+
const text = typeof node.description === 'string' ? node.description.trim() : '';
|
|
86
|
+
return text;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// ── "Keep revision N" ───────────────────────────────────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
const keepKey = (appId, nodeId, pinned, current) => `${KEEP_PREFIX}${appId}:${nodeId}:${pinned}->${current}`;
|
|
92
|
+
function isKept(appId, nodeId, pinned, current) {
|
|
93
|
+
try { return localStorage.getItem(keepKey(appId, nodeId, pinned, current)) === '1'; } catch { return false; }
|
|
94
|
+
}
|
|
95
|
+
function keep(appId, nodeId, pinned, current) {
|
|
96
|
+
try { localStorage.setItem(keepKey(appId, nodeId, pinned, current), '1'); } catch { /* private mode: the banner simply stays */ }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── the banner: how the step stands against its saved Agent ─────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* What to tell the person, from the server's `check` for this step. Null when there is nothing to say - including when the
|
|
103
|
+
* check is absent or failed: no check never reads as "up to date".
|
|
104
|
+
*/
|
|
105
|
+
function bannerModel(check, facts, appId, nodeId) {
|
|
106
|
+
if (!check || check.state === 'current' || !Array.isArray(check.issues) || !check.issues.length) return null;
|
|
107
|
+
const pinned = check.pinned ? check.pinned.revision : facts.revision;
|
|
108
|
+
const current = check.current ? check.current.revision : null;
|
|
109
|
+
const kept = current !== null && pinned !== null && isKept(appId, nodeId, pinned, current);
|
|
110
|
+
// Only the "newer revision" notice can be kept. Every other finding (a deleted Agent, an unavailable project, a different scope,
|
|
111
|
+
// instructions that differ at the same revision, an archived Agent) is independent of which revision is kept and stays visible.
|
|
112
|
+
const keepable = new Set(['newer-revision']);
|
|
113
|
+
const shown = check.issues.filter((issue) => !(kept && keepable.has(issue.kind)));
|
|
114
|
+
const lines = shown.map((issue) => issue.message);
|
|
115
|
+
if (!lines.length) return null;
|
|
116
|
+
const missing = check.issues.some((issue) => issue.kind === 'agent-missing');
|
|
117
|
+
return {
|
|
118
|
+
lines,
|
|
119
|
+
kinds: shown.map((issue) => issue.kind),
|
|
120
|
+
missing,
|
|
121
|
+
canKeep: !missing && pinned !== null && current !== null && shown.some((issue) => keepable.has(issue.kind)),
|
|
122
|
+
pinned,
|
|
123
|
+
current,
|
|
124
|
+
canOpenAgent: !missing && !!facts.agentId,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── what a card and Inspect show ───────────────────────────────────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
const BADGE_TIP = 'An Agent writes this step’s answer each time the workflow runs, so the answer can differ from run to run. Steps that use the answer can differ too.';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The AI-step parts of a node's entry, or null for every other node (and for everything while the feature is off).
|
|
134
|
+
* `check` is the server's last answer for this step, absent until it arrives.
|
|
135
|
+
*/
|
|
136
|
+
function entryParts(app, node, check) {
|
|
137
|
+
if (!isStepNode(node)) return null; // factual: labelled whether or not the feature is on
|
|
138
|
+
const facts = stepFacts(node);
|
|
139
|
+
const banner = bannerModel(check, facts, app.id, node.id);
|
|
140
|
+
const blurb = `Asks “${facts.name}” to answer. Its answer is written by an AI each run.`;
|
|
141
|
+
const attention = !banner ? '' : banner.missing ? 'Agent not found. Open Inspect.'
|
|
142
|
+
: banner.kinds.includes('newer-revision') ? 'Newer instructions available.' : 'Something to check. Open Inspect.';
|
|
143
|
+
return {
|
|
144
|
+
facts,
|
|
145
|
+
banner,
|
|
146
|
+
blurb: banner && banner.missing ? esc(attention) : esc(blurb) + (attention ? `<span class="as-attn">${esc(attention)}</span>` : ''),
|
|
147
|
+
badge: { text: 'AI Agent step', tip: BADGE_TIP, aria: 'AI Agent step, the answer varies each run' },
|
|
148
|
+
attention,
|
|
149
|
+
descriptionHtml: inspectHtml(app, node, facts, banner, check),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function scopeWords(check, facts) {
|
|
154
|
+
if (check && check.pinned && Array.isArray(check.pinned.scope) && check.pinned.scope.length) {
|
|
155
|
+
return check.pinned.scope.map((item) => esc(item.label)).join(', ');
|
|
156
|
+
}
|
|
157
|
+
return facts.scopeCount ? `${facts.scopeCount} place${facts.scopeCount === 1 ? '' : 's'} in your workspace` : 'Nothing was pinned';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function inspectHtml(app, node, facts, banner, check) {
|
|
161
|
+
const nodeAttr = esc(node.id);
|
|
162
|
+
let html = '';
|
|
163
|
+
if (banner) {
|
|
164
|
+
const actions = [];
|
|
165
|
+
actions.push(banner.missing
|
|
166
|
+
? `<button type="button" class="as-btn primary" data-as-act="replace" data-as-node="${nodeAttr}" data-command-id="shell.agent-step-update">Ask the AI to remove or replace this step</button>`
|
|
167
|
+
: `<button type="button" class="as-btn primary" data-as-act="update" data-as-node="${nodeAttr}" data-command-id="shell.agent-step-update">Ask the AI to update it</button>`);
|
|
168
|
+
if (banner.canKeep) {
|
|
169
|
+
actions.push(`<button type="button" class="as-btn" data-as-act="keep" data-as-node="${nodeAttr}" data-as-pinned="${esc(banner.pinned)}" data-as-current="${esc(banner.current)}" data-command-id="shell.agent-step-keep">Keep revision ${esc(banner.pinned)}</button>`);
|
|
170
|
+
}
|
|
171
|
+
if (banner.canOpenAgent) {
|
|
172
|
+
actions.push(`<button type="button" class="as-btn as-link" data-as-act="open-agent" data-as-agent="${esc(facts.agentId)}" data-command-id="shell.agent-step-open-agent">Open Agent ▸</button>`);
|
|
173
|
+
}
|
|
174
|
+
html += `<div class="as-banner" role="status"><div class="as-banner-text">${banner.lines.map((line) => `<p>${esc(line)}</p>`).join('')}</div><div class="as-actions">${actions.join('')}</div></div>`;
|
|
175
|
+
}
|
|
176
|
+
const sentence = plainDescription(node);
|
|
177
|
+
html += `<p>${esc(sentence || `This step asks the Agent “${facts.name}” a question and uses its answer.`)}</p>`;
|
|
178
|
+
html += '<p class="as-standing">This step’s answer is written by an AI and may differ each time the workflow runs. Steps that use the answer can differ too, and FloLess does not yet mark which ones they are.</p>';
|
|
179
|
+
if (app.runState && app.runState !== 'ready') {
|
|
180
|
+
html += '<p class="dim-note">These settings are read from the workflow file. It has not been approved in this form yet, so the approved version may differ.</p>';
|
|
181
|
+
}
|
|
182
|
+
html += `<h3>What it is told to do</h3>${facts.instructions
|
|
183
|
+
? `<pre class="as-instructions">${esc(facts.instructions)}</pre>`
|
|
184
|
+
: '<p class="dim-note">FloLess could not read this step’s instructions.</p>'}`;
|
|
185
|
+
const rows = [
|
|
186
|
+
['Agent', esc(facts.name)],
|
|
187
|
+
['Revision', facts.revision === null ? 'Not recorded' : esc(facts.revision)],
|
|
188
|
+
['AI', facts.provider ? esc(facts.provider) : 'Not recorded'],
|
|
189
|
+
['What it can see', scopeWords(check, facts)],
|
|
190
|
+
['Answer format', esc(answerWords(facts.output))],
|
|
191
|
+
];
|
|
192
|
+
html += `<h3>The Agent</h3><dl class="as-facts">${rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${v}</dd>`).join('')}</dl>`;
|
|
193
|
+
return html;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ── checks ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Ask the server how this workflow's steps stand, then repaint. A failed check says nothing (no claim either way). Each ask has a
|
|
200
|
+
* generation per workflow: a slower, older answer that lands after a newer ask (or after the checks were forgotten) is dropped, so it
|
|
201
|
+
* can never overwrite what is current.
|
|
202
|
+
*/
|
|
203
|
+
async function refreshChecks(app) {
|
|
204
|
+
if (!app) return;
|
|
205
|
+
const mine = (model.generation.get(app.id) || 0) + 1;
|
|
206
|
+
model.generation.set(app.id, mine);
|
|
207
|
+
const current = () => model.generation.get(app.id) === mine;
|
|
208
|
+
// The status probe is awaited HERE, in the detached check, never in loadApp: opening a workflow must not wait on it.
|
|
209
|
+
const on = await probe();
|
|
210
|
+
if (!current()) return;
|
|
211
|
+
if (!on || !Array.isArray(app.nodes) || !app.nodes.some(isStepNode)) { model.checks.delete(app.id); return; }
|
|
212
|
+
let steps = null;
|
|
213
|
+
try {
|
|
214
|
+
const response = await fetch(`/api/agent-steps/check?app=${encodeURIComponent(app.id)}`, { credentials: 'same-origin' });
|
|
215
|
+
const body = response.ok ? await response.json() : null;
|
|
216
|
+
if (body && body.ok === true && Array.isArray(body.steps)) steps = body.steps;
|
|
217
|
+
} catch { steps = null; }
|
|
218
|
+
if (!current()) return;
|
|
219
|
+
if (!steps) {
|
|
220
|
+
// The answer is gone: whatever was shown from the earlier check must not stay up as if it were current.
|
|
221
|
+
if (model.checks.delete(app.id)) model.context.repaint(app.id);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
model.checks.set(app.id, new Map(steps.map((step) => [step.nodeId, step])));
|
|
225
|
+
model.context.repaint(app.id);
|
|
226
|
+
}
|
|
227
|
+
const checkFor = (appId, nodeId) => model.checks.get(appId)?.get(nodeId) ?? null;
|
|
228
|
+
|
|
229
|
+
/** How many AI steps the workflow has. */
|
|
230
|
+
function stepCount(app) {
|
|
231
|
+
if (!app || !Array.isArray(app.nodes)) return 0;
|
|
232
|
+
// Factual, so not gated by the feature: a step in the source, a node the lock marks, or a lock that says its output is not
|
|
233
|
+
// deterministic (a stale lock still labels the workflow). Whether the lock matches the source is shown separately by the gate.
|
|
234
|
+
const steps = app.nodes.filter(isStepNode).length;
|
|
235
|
+
return steps || (app.nondeterministicOutput === true ? 1 : 0);
|
|
236
|
+
}
|
|
237
|
+
const headerText = (count) => (count > 1 ? `includes ${count} AI steps` : 'includes an AI step');
|
|
238
|
+
const MARK_TIP = 'One step in this workflow is answered by an AI Agent, so that answer can differ each run. Steps that use the answer can differ too.';
|
|
239
|
+
const MARK_TIP_MANY = 'Some steps in this workflow are answered by an AI Agent, so those answers can differ each run. Steps that use an answer can differ too.';
|
|
240
|
+
const markTip = (count) => (count > 1 ? MARK_TIP_MANY : MARK_TIP);
|
|
241
|
+
|
|
242
|
+
// ── relaying to AI Chat ─────────────────────────────────────────────────────────────────────────────────────
|
|
243
|
+
|
|
244
|
+
async function fetchBlock(agentId, extra = {}) {
|
|
245
|
+
const query = new URLSearchParams({ agent: agentId });
|
|
246
|
+
for (const [key, value] of Object.entries(extra)) if (value) query.set(key, value);
|
|
247
|
+
let response;
|
|
248
|
+
try { response = await fetch(`/api/agent-steps/block?${query}`, { credentials: 'same-origin' }); }
|
|
249
|
+
catch { throw new Error('FloLess could not be reached to load the Agent’s step. Make sure it is still running, then try again.'); }
|
|
250
|
+
let body = null;
|
|
251
|
+
try { body = await response.json(); } catch { body = null; }
|
|
252
|
+
if (!response.ok || !body || body.ok !== true) {
|
|
253
|
+
throw Object.assign(new Error(typeof body?.error === 'string' && body.error ? body.error : 'FloLess could not load the Agent’s step just now. Try again.'), { code: typeof body?.code === 'string' ? body.code : '' });
|
|
254
|
+
}
|
|
255
|
+
return body;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const fence = (text) => `\`\`\`yaml\n${text.replace(/\n+$/, '')}\n\`\`\``;
|
|
259
|
+
const WARN_LINE = 'Show me the change before I approve it. I will confirm myself, when I approve the workflow, that this step’s answer is not deterministic. Do not write that confirmation for me.';
|
|
260
|
+
|
|
261
|
+
/** What the server noted about the block (warnings) and what is still the author's to do (reminders), as one paragraph. */
|
|
262
|
+
function notes(block) {
|
|
263
|
+
const lines = [...(block.warnings || []), ...(block.next || [])].filter((line) => typeof line === 'string' && line);
|
|
264
|
+
return lines.length ? `\n\nFloLess noted: ${lines.join(' ')}` : '';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The marker line AWARE needs before it will compile an Agent step (not consent; the person still confirms in FloLess). */
|
|
268
|
+
function markerNote(block) {
|
|
269
|
+
const line = block.acknowledgement && block.acknowledgement.line;
|
|
270
|
+
return line ? `\n\nIf the workflow source does not already have the top-level line \`${line}\`, add it once next to \`nodes:\`: AWARE needs it to compile an Agent step, and it is only a marker. I still confirm in FloLess before the workflow is approved or runs.` : '';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// The Agent's name and revision come from the block the server just wrote (the truth), not from what the page remembered.
|
|
274
|
+
function addMessage({ workflowName, block }) {
|
|
275
|
+
const agentName = block.agent.name, revision = block.agent.revision;
|
|
276
|
+
const where = workflowName ? `the open workflow “${workflowName}”` : 'a workflow (ask me which one if it is not clear)';
|
|
277
|
+
const warnings = notes(block);
|
|
278
|
+
return `Add an Agent step to ${where}, using my Agent “${agentName}” (revision ${revision}).\n\n`
|
|
279
|
+
+ 'Use exactly this block and copy it as it is. The only part you may fill in is “context”, which is what the step is given to read (for example the output of an earlier step). Then connect the step: what feeds it goes into the step, and the step’s “-ok” check goes into the first step that uses its answer. If the step’s id or its “-ok” id turns out to be taken when you apply it, do not pick another yourself: ask FloLess for the block again (the agent-steps.block action, with this workflow’s id) and use the ids it gives.\n\n'
|
|
280
|
+
+ `${fence(block.fragment)}${warnings}\n\n${WARN_LINE}`;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function updateMessage({ nodeId, from, workflowName, block }) {
|
|
284
|
+
const agentName = block.agent.name, to = block.agent.revision; // what the server just wrote, not what the page remembered
|
|
285
|
+
const warnings = block.warnings && block.warnings.length ? `\n\nFloLess noted: ${block.warnings.join(' ')}` : '';
|
|
286
|
+
return `Update the Agent step “${nodeId}” in ${workflowName ? `the open workflow “${workflowName}”` : 'this workflow'} from revision ${from} to revision ${to} of my Agent “${agentName}”.\n\n`
|
|
287
|
+
+ 'Replace the step and its “-ok” check with exactly this block, keep the step id and the connections it already has:\n\n'
|
|
288
|
+
+ `${fence(block.fragment)}${warnings}${markerNote(block)}\n\n${WARN_LINE}`;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function openDraft(text) {
|
|
292
|
+
if (typeof window.flolessChat?.openDraft !== 'function') throw new Error('AI Chat is still starting. Try again in a moment.');
|
|
293
|
+
await window.flolessChat.openDraft(text);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Put "add this Agent as a step" into the chat composer. Resolves true when drafted; says why in a toast when not. */
|
|
297
|
+
async function draftAdd({ agentId, agentName, revision, anyWorkflow = false }) {
|
|
298
|
+
try {
|
|
299
|
+
// From the Agents page no workflow is the target: the AI asks which one. From the canvas it is the open workflow.
|
|
300
|
+
const app = anyWorkflow ? null : model.context.currentApp();
|
|
301
|
+
// On the canvas FloLess's server picks the step id: free in the open workflow as it is saved now. The page guesses nothing;
|
|
302
|
+
// from the Agents page no workflow is named, and the block tells the AI to ask again once it knows which one.
|
|
303
|
+
const block = await fetchBlock(agentId, { context: '', ...(app ? { app: app.id } : {}) });
|
|
304
|
+
await openDraft(addMessage({ workflowName: app ? (app.displayName || app.id) : '', block }));
|
|
305
|
+
model.context.toast('Drafted in AI Chat. Review it and send it there.', 'ok');
|
|
306
|
+
return true;
|
|
307
|
+
} catch (error) {
|
|
308
|
+
const message = error instanceof Error && error.message ? error.message : 'FloLess could not draft that. Try again.';
|
|
309
|
+
// Nothing valid to pin (no instructions, nothing to read, instructions beyond what a step can carry): the person is not left at a
|
|
310
|
+
// dead end. The reason goes to AI Chat as a drafted question, to be sent or not, and the Agent is never changed from here.
|
|
311
|
+
if (error && ['cannot-pin', 'agent-no-instructions', 'agent-no-scope'].includes(error.code)) {
|
|
312
|
+
try {
|
|
313
|
+
await openDraft(`I tried to use my Agent “${agentName || 'this Agent'}” as a workflow step, but FloLess says: ${message}
|
|
314
|
+
|
|
315
|
+
Help me decide what to change on the Agents page (for example shorten or split the instructions, or choose what it may read). Do not change the Agent yourself.`);
|
|
316
|
+
model.context.toast(`${message} A question about it is drafted in AI Chat.`, 'warn');
|
|
317
|
+
return false;
|
|
318
|
+
} catch { /* the toast below still tells the person */ }
|
|
319
|
+
}
|
|
320
|
+
model.context.toast(message, 'warn');
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async function draftUpdate(appId, nodeId, replace) {
|
|
326
|
+
const app = model.context.currentApp();
|
|
327
|
+
const node = app && app.id === appId ? app.nodes.find((candidate) => candidate.id === nodeId) : null;
|
|
328
|
+
if (!node) return false;
|
|
329
|
+
const facts = stepFacts(node);
|
|
330
|
+
const check = checkFor(appId, nodeId);
|
|
331
|
+
const workflowName = app.displayName || app.id;
|
|
332
|
+
try {
|
|
333
|
+
const gone = Boolean(check && Array.isArray(check.issues) && check.issues.some((issue) => issue.kind === 'agent-missing'));
|
|
334
|
+
const where = workflowName ? `“${workflowName}”` : 'this workflow';
|
|
335
|
+
if (replace || gone) {
|
|
336
|
+
await openDraft(`The Agent “${facts.name}”, used by the step “${nodeId}” in ${where}, is no longer saved. Ask me which saved Agent should replace it, or whether to remove the step.
|
|
337
|
+
|
|
338
|
+
${WARN_LINE}`);
|
|
339
|
+
} else if (!facts.agentId) {
|
|
340
|
+
// The step does not say which Agent it came from (its file may have been edited by hand): it is asked, not refused, and the
|
|
341
|
+
// Agent is not claimed to be missing.
|
|
342
|
+
await openDraft(`FloLess could not tell which saved Agent the step “${nodeId}” in ${where} was made from. Ask me which saved Agent it should use, or whether to remove the step.
|
|
343
|
+
|
|
344
|
+
${WARN_LINE}`);
|
|
345
|
+
} else {
|
|
346
|
+
// Everything the step already has is carried over, so an update changes the Agent's instructions and nothing else. The check
|
|
347
|
+
// is not needed for this (it may have been lost): the block the server writes now is the truth.
|
|
348
|
+
const block = await fetchBlock(facts.agentId, {
|
|
349
|
+
node: nodeId, context: facts.context, description: plainDescription(node), provider: facts.provider ? facts.provider.toLowerCase() : '',
|
|
350
|
+
output: JSON.stringify(facts.output), timeoutMinutes: facts.timeoutMinutes ? String(facts.timeoutMinutes) : '',
|
|
351
|
+
});
|
|
352
|
+
await openDraft(updateMessage({ nodeId, from: facts.revision ?? check?.pinned?.revision ?? '?', workflowName, block }));
|
|
353
|
+
}
|
|
354
|
+
model.context.toast('Drafted in AI Chat. Review it and send it there.', 'ok');
|
|
355
|
+
return true;
|
|
356
|
+
} catch (error) {
|
|
357
|
+
model.context.toast(error instanceof Error && error.message ? error.message : 'FloLess could not draft that. Try again.', 'warn');
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ── Inspect buttons (delegated: Inspect is rebuilt on every render) ─────────────────────────────────────────
|
|
363
|
+
|
|
364
|
+
document.addEventListener('click', (event) => {
|
|
365
|
+
const button = event.target.closest && event.target.closest('[data-as-act]');
|
|
366
|
+
if (!button) return;
|
|
367
|
+
const app = model.context.currentApp();
|
|
368
|
+
if (!app) return;
|
|
369
|
+
const act = button.dataset.asAct;
|
|
370
|
+
if (act === 'update' || act === 'replace') { void draftUpdate(app.id, button.dataset.asNode, act === 'replace'); return; }
|
|
371
|
+
if (act === 'keep') {
|
|
372
|
+
keep(app.id, button.dataset.asNode, Number(button.dataset.asPinned), Number(button.dataset.asCurrent));
|
|
373
|
+
model.context.repaint(app.id);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (act === 'open-agent') model.context.openAgent(button.dataset.asAgent);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// ── the canvas chooser: "+ Agent step" ──────────────────────────────────────────────────────────────────────
|
|
380
|
+
|
|
381
|
+
let chooser = null; // { root, list, search, trigger, agents, onDocDown, onKey }
|
|
382
|
+
|
|
383
|
+
function closeChooser(returnFocus = true) {
|
|
384
|
+
if (!chooser) return;
|
|
385
|
+
const { root, trigger, onDocDown, onKey } = chooser;
|
|
386
|
+
document.removeEventListener('mousedown', onDocDown, true);
|
|
387
|
+
document.removeEventListener('keydown', onKey, true);
|
|
388
|
+
root.remove();
|
|
389
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
390
|
+
chooser = null;
|
|
391
|
+
if (returnFocus) trigger.focus();
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async function loadAgents() {
|
|
395
|
+
const session = await fetch('/api/chat/session', { credentials: 'same-origin' });
|
|
396
|
+
if (!session.ok) throw new Error('FloLess could not open AI Chat’s session, so the Agents could not load. Reload FloLess and try again.');
|
|
397
|
+
const response = await fetch('/api/chat/agents', { credentials: 'same-origin' });
|
|
398
|
+
const body = await response.json().catch(() => null);
|
|
399
|
+
if (!response.ok || !body || !Array.isArray(body.agents)) throw new Error('FloLess could not load your Agents just now. Try again.');
|
|
400
|
+
return body.agents.filter((agent) => !agent.archivedAt && agent.instructions && agent.scope && agent.scope.length);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function chooserRow(agent) {
|
|
404
|
+
const provider = agent.provider === 'codex' ? 'Codex' : agent.provider === 'claude' ? 'Claude' : 'AI not chosen';
|
|
405
|
+
return `<div class="wf-option as-option" role="option" tabindex="-1" aria-selected="false" data-as-agent="${esc(agent.agentId)}" data-command-id="shell.agent-step-choose#${esc(agent.name)}" data-command-instance-label="${esc(agent.name)}">`
|
|
406
|
+
+ `<span class="wf-option-name">${esc(agent.name)}</span><span class="wf-option-meta">${esc(provider)} · revision ${esc(agent.revision)}</span></div>`;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async function openChooser(trigger) {
|
|
410
|
+
if (chooser) { closeChooser(); return; }
|
|
411
|
+
const root = document.createElement('div');
|
|
412
|
+
root.className = 'wf-popover as-popover';
|
|
413
|
+
root.innerHTML = '<div class="wf-list as-list" role="listbox" aria-label="Choose an Agent for the new step"><div class="wf-empty-search" role="status">Loading your Agents…</div></div>';
|
|
414
|
+
trigger.parentElement.append(root);
|
|
415
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
416
|
+
const onDocDown = (event) => { if (!root.contains(event.target) && !trigger.contains(event.target)) closeChooser(false); };
|
|
417
|
+
document.addEventListener('mousedown', onDocDown, true);
|
|
418
|
+
// Escape closes the chooser whatever it is showing (loading, an error, the empty state, the list) and wherever focus is.
|
|
419
|
+
// Capture phase on purpose: Escape must close this popover wherever focus is. (It also reaches nothing else while the popover is open.)
|
|
420
|
+
const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeChooser(); } };
|
|
421
|
+
document.addEventListener('keydown', onKey, true);
|
|
422
|
+
chooser = { root, trigger, onDocDown, onKey };
|
|
423
|
+
const list = root.querySelector('.as-list');
|
|
424
|
+
let agents;
|
|
425
|
+
try { agents = await loadAgents(); }
|
|
426
|
+
catch (error) {
|
|
427
|
+
if (chooser?.root !== root) return;
|
|
428
|
+
list.innerHTML = `<div class="wf-empty-search" role="alert">${esc(error.message)}</div>`;
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (chooser?.root !== root) return;
|
|
432
|
+
if (!agents.length) {
|
|
433
|
+
list.innerHTML = '<div class="wf-empty-search">You have no saved Agents that can be a step yet. An Agent needs instructions and a project or workflow to read.</div>'
|
|
434
|
+
+ '<div class="as-empty-actions"><button type="button" class="as-btn primary" data-as-open-agents="1" data-command-id="shell.agent-step-open-agents">Open the Agents page</button></div>';
|
|
435
|
+
list.querySelector('[data-as-open-agents]').addEventListener('click', () => { closeChooser(false); model.context.openAgents(); });
|
|
436
|
+
list.querySelector('button').focus();
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
list.innerHTML = agents.map(chooserRow).join('');
|
|
440
|
+
const options = () => [...list.querySelectorAll('.as-option')];
|
|
441
|
+
const move = (delta) => {
|
|
442
|
+
const all = options();
|
|
443
|
+
const at = all.indexOf(document.activeElement);
|
|
444
|
+
all[Math.max(0, Math.min(all.length - 1, at + delta))]?.focus();
|
|
445
|
+
};
|
|
446
|
+
options().forEach((option) => {
|
|
447
|
+
option.addEventListener('click', () => {
|
|
448
|
+
const agent = agents.find((candidate) => candidate.agentId === option.dataset.asAgent);
|
|
449
|
+
closeChooser(false);
|
|
450
|
+
if (agent) void draftAdd({ agentId: agent.agentId, agentName: agent.name, revision: agent.revision });
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
root.addEventListener('keydown', (event) => {
|
|
454
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); move(1); }
|
|
455
|
+
else if (event.key === 'ArrowUp') { event.preventDefault(); move(-1); }
|
|
456
|
+
else if (event.key === 'Enter' || event.key === ' ') { if (document.activeElement?.classList.contains('as-option')) { event.preventDefault(); document.activeElement.click(); } }
|
|
457
|
+
});
|
|
458
|
+
options()[0]?.focus();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function paintCanvasControl() {
|
|
462
|
+
const group = document.getElementById('as-add-group');
|
|
463
|
+
if (!group) return;
|
|
464
|
+
const app = model.context.currentApp();
|
|
465
|
+
group.hidden = !(enabled() && app);
|
|
466
|
+
if (group.hidden) closeChooser(false);
|
|
467
|
+
}
|
|
468
|
+
const trigger = document.getElementById('as-add');
|
|
469
|
+
if (trigger) trigger.addEventListener('click', () => { void openChooser(trigger); });
|
|
470
|
+
|
|
471
|
+
// Ask early, off the critical path: the canvas control appears as soon as the server says the feature is on.
|
|
472
|
+
void probe().then(() => paintCanvasControl());
|
|
473
|
+
|
|
474
|
+
// ── the confirmation dialog (S4) ──────────────────────────────────────────────────────────────────────────────
|
|
475
|
+
// Approve and Run ask the server first (GET status). A workflow with an AI step nobody has confirmed - or one that changed since -
|
|
476
|
+
// opens #agent-consent-modal instead of going on. The person ticks one box; the SERVER records who/when/which steps and approves the
|
|
477
|
+
// exact bytes shown (the hash comes back with the model). This file never records anything itself and the AI chat cannot answer it.
|
|
478
|
+
|
|
479
|
+
const CONSENT_API = '/api/chat/agent-steps/consent';
|
|
480
|
+
const CONSENT_FIRST_SUB = 'The AI writes its answer each time the workflow runs, so that answer can differ from run to run. Everything else in the workflow stays exactly as approved.';
|
|
481
|
+
|
|
482
|
+
function whenWords(iso) {
|
|
483
|
+
const date = new Date(iso);
|
|
484
|
+
if (Number.isNaN(date.getTime())) return '';
|
|
485
|
+
return date.toLocaleString([], { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' });
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function stepCardHtml(step, tag) {
|
|
489
|
+
const rows = [
|
|
490
|
+
['Answered by', step.provider === 'codex' ? 'Codex' : 'Claude'],
|
|
491
|
+
['Can read', (step.scope && step.scope.length ? step.scope : ['Nothing was pinned']).join(', ')],
|
|
492
|
+
['Answer format', step.answerFormat === 'json' ? 'A structured answer' : 'Plain text'],
|
|
493
|
+
['Time limit', `${step.timeoutMinutes} min`],
|
|
494
|
+
];
|
|
495
|
+
const long = String(step.instructions || '').trim().length > String(step.firstLine || '').length;
|
|
496
|
+
return `<div class="ac-step" data-ac-node="${esc(step.nodeId)}">`
|
|
497
|
+
+ `<div class="ac-step-head"><span class="ac-step-name">${esc(step.agentName || step.nodeId)}</span>`
|
|
498
|
+
+ `<span class="ac-step-rev">${step.agentRevision !== null && step.agentRevision !== undefined ? `revision ${esc(step.agentRevision)}` : ''}${tag ? ` · ${esc(tag)}` : ''}</span></div>`
|
|
499
|
+
+ `<dl class="ac-facts">${rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`).join('')}</dl>`
|
|
500
|
+
+ (step.firstLine ? `<p class="ac-first">${esc(step.firstLine)}</p>` : '')
|
|
501
|
+
+ (long ? `<button type="button" class="ac-more" data-ac-more aria-expanded="false" data-command-id="shell.agent-consent-more">Show full instructions</button>`
|
|
502
|
+
+ `<pre class="ac-pre" hidden tabindex="0" aria-label="Full instructions, read only">${esc(step.instructions)}</pre>` : '')
|
|
503
|
+
+ '</div>';
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function diffHtml(lines) {
|
|
507
|
+
return `<pre class="ac-pre ac-diff" tabindex="0" aria-label="What changed in the instructions, read only">${lines.map((line) => {
|
|
508
|
+
const cls = line.op === '+' ? 'add' : line.op === '-' ? 'del' : '';
|
|
509
|
+
const word = line.op === '+' ? 'added: ' : line.op === '-' ? 'removed: ' : '';
|
|
510
|
+
return `<span class="ac-line ${cls}"><span class="ac-glyph" aria-hidden="true">${line.op === ' ' ? '' : esc(line.op)}</span>${word ? `<span class="ac-vis">${word}</span>` : ''}${esc(line.text)}\n</span>`;
|
|
511
|
+
}).join('')}</pre>`;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function changeCardHtml(change, steps) {
|
|
515
|
+
const step = steps.find((candidate) => candidate.nodeId === change.nodeId);
|
|
516
|
+
if (change.kind === 'added') return step ? stepCardHtml(step, 'New step') : '';
|
|
517
|
+
const name = step ? (step.agentName || step.nodeId) : change.nodeId;
|
|
518
|
+
let html = `<div class="ac-step" data-ac-node="${esc(change.nodeId)}"><div class="ac-step-head"><span class="ac-step-name">${esc(name)}</span><span class="ac-step-rev">changed</span></div>`;
|
|
519
|
+
if (change.instructionsDiff) html += diffHtml(change.instructionsDiff);
|
|
520
|
+
else if (change.fields.includes('instructionsSha256')) html += '<p class="ac-first">The instructions changed (the earlier text was not kept).</p>';
|
|
521
|
+
if (change.rows.length) {
|
|
522
|
+
html += `<div class="ac-rows">${change.rows.map((row) => `<span>${esc(row.label)}</span><span><span class="ac-was">${esc(row.before)}</span> <span class="ac-arrow" aria-hidden="true">→</span><span class="ac-vis"> now </span> ${esc(row.after)}</span>`).join('')}</div>`;
|
|
523
|
+
}
|
|
524
|
+
return `${html}</div>`;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** The words and markup of the dialog for one server model. Pure: no DOM, so it is testable on its own. */
|
|
528
|
+
function consentView(model, via) {
|
|
529
|
+
const changed = model.state === 'changed' && Array.isArray(model.changes) && model.changes.length > 0;
|
|
530
|
+
const steps = Array.isArray(model.steps) ? model.steps : [];
|
|
531
|
+
let body;
|
|
532
|
+
if (changed) {
|
|
533
|
+
body = model.changes.map((change) => changeCardHtml(change, steps)).join('');
|
|
534
|
+
const unchanged = steps.filter((step) => !model.changes.some((change) => change.nodeId === step.nodeId)).length;
|
|
535
|
+
if (unchanged) body += `<p class="ac-unchanged">${unchanged} other AI step${unchanged === 1 ? '' : 's'} unchanged since you confirmed.</p>`;
|
|
536
|
+
} else {
|
|
537
|
+
body = steps.map((step) => stepCardHtml(step, '')).join('');
|
|
538
|
+
}
|
|
539
|
+
if (model.unreadableSteps) body += `<p class="ac-unchanged">${esc(model.unreadableSteps)} AI step${model.unreadableSteps === 1 ? '' : 's'} could not be read, so ${model.unreadableSteps === 1 ? 'it' : 'they'} will not run until fixed.</p>`;
|
|
540
|
+
const nameOf = (name) => (/^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(String(name)) ? 'You' : name);
|
|
541
|
+
const who = model.latest ? `${nameOf(model.latest.confirmedBy)}${whenWords(model.latest.confirmedAt) ? ` on ${whenWords(model.latest.confirmedAt)}` : ''}` : '';
|
|
542
|
+
return {
|
|
543
|
+
title: changed ? 'The AI step changed since you last confirmed' : 'This workflow includes an AI step',
|
|
544
|
+
sub: changed ? `${who ? `Last confirmed by ${who}. ` : ''}Look at what changed, then confirm again. ${CONSENT_FIRST_SUB}` : CONSENT_FIRST_SUB,
|
|
545
|
+
body,
|
|
546
|
+
warning: model.warning || '',
|
|
547
|
+
sentence: model.sentence,
|
|
548
|
+
primary: via === 'run-dialog' ? 'Confirm and run' : 'Approve workflow',
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
async function consentFetch(path, body) {
|
|
553
|
+
const response = await fetch(`${CONSENT_API}/${path}`, {
|
|
554
|
+
credentials: 'same-origin',
|
|
555
|
+
...(body ? { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) } : {}),
|
|
556
|
+
});
|
|
557
|
+
const data = await response.json().catch(() => ({}));
|
|
558
|
+
return { status: response.status, data };
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** The server's view of this workflow's confirmation, or null when it cannot be asked (then the normal path goes on). */
|
|
562
|
+
async function consentStatus(appId) {
|
|
563
|
+
try {
|
|
564
|
+
if (!(await probe())) return null;
|
|
565
|
+
const { status, data } = await consentFetch(`status?app=${encodeURIComponent(appId)}`);
|
|
566
|
+
return status === 200 && data && data.ok ? data : null;
|
|
567
|
+
} catch { return null; }
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
let consentOpen = false;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Show the dialog. Resolves 'confirmed' once the server recorded it (and, from Approve, approved those exact bytes), else 'cancel'.
|
|
574
|
+
* `via` is 'approve' or 'run-dialog'. Never records anything itself.
|
|
575
|
+
*/
|
|
576
|
+
function consentDialog(app, via, initialModel) {
|
|
577
|
+
const root = document.getElementById('agent-consent-modal');
|
|
578
|
+
if (!root || consentOpen) return Promise.resolve('cancel');
|
|
579
|
+
consentOpen = true;
|
|
580
|
+
const $ = (id) => document.getElementById(id);
|
|
581
|
+
const tick = $('ac-tick'); const ok = $('ac-ok'); const hint = $('ac-hint'); const err = $('ac-error');
|
|
582
|
+
const returnTo = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
583
|
+
let current = initialModel;
|
|
584
|
+
let busy = false;
|
|
585
|
+
return new Promise((resolve) => {
|
|
586
|
+
const syncOk = () => {
|
|
587
|
+
ok.setAttribute('aria-disabled', tick.checked && !busy ? 'false' : 'true');
|
|
588
|
+
hint.hidden = tick.checked;
|
|
589
|
+
hint.classList.remove('nudge');
|
|
590
|
+
};
|
|
591
|
+
const showError = (text) => { err.textContent = text || ''; err.hidden = !text; };
|
|
592
|
+
const paint = () => {
|
|
593
|
+
const view = consentView(current, via);
|
|
594
|
+
$('ac-title').textContent = view.title;
|
|
595
|
+
$('ac-sub').textContent = view.sub;
|
|
596
|
+
$('ac-body').innerHTML = view.body;
|
|
597
|
+
const warning = $('ac-warning');
|
|
598
|
+
warning.hidden = !view.warning;
|
|
599
|
+
warning.innerHTML = view.warning ? `<b>Heads up.</b> ${esc(view.warning)}` : '';
|
|
600
|
+
$('ac-tick-label').textContent = view.sentence;
|
|
601
|
+
ok.textContent = view.primary;
|
|
602
|
+
syncOk();
|
|
603
|
+
};
|
|
604
|
+
const close = (result) => {
|
|
605
|
+
document.removeEventListener('keydown', onKey, true);
|
|
606
|
+
root.removeEventListener('click', onClick);
|
|
607
|
+
tick.removeEventListener('change', syncOk);
|
|
608
|
+
root.classList.remove('show');
|
|
609
|
+
consentOpen = false;
|
|
610
|
+
if (returnTo && returnTo.isConnected) returnTo.focus();
|
|
611
|
+
resolve(result);
|
|
612
|
+
};
|
|
613
|
+
const focusables = () => [...root.querySelectorAll('button, input, [tabindex="0"]')].filter((el) => !el.hidden && !el.closest('[hidden]'));
|
|
614
|
+
function onKey(event) {
|
|
615
|
+
if (!root.classList.contains('show')) return;
|
|
616
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); if (!busy) close('cancel'); return; }
|
|
617
|
+
if (event.key !== 'Tab') return;
|
|
618
|
+
const list = focusables();
|
|
619
|
+
if (!list.length) return;
|
|
620
|
+
const first = list[0]; const last = list[list.length - 1];
|
|
621
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
622
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
623
|
+
else if (!root.contains(document.activeElement)) { event.preventDefault(); first.focus(); }
|
|
624
|
+
}
|
|
625
|
+
async function confirm() {
|
|
626
|
+
if (busy) return;
|
|
627
|
+
if (!tick.checked) { hint.hidden = false; hint.classList.add('nudge'); tick.focus(); return; }
|
|
628
|
+
busy = true; syncOk(); showError('');
|
|
629
|
+
ok.textContent = 'Working…';
|
|
630
|
+
try {
|
|
631
|
+
const { status, data } = await consentFetch('confirm', { app: app.id, reviewedSourceHash: current.reviewedSourceHash, checkbox: true, via });
|
|
632
|
+
if (status === 200 && data.ok) { busy = false; close('confirmed'); return; }
|
|
633
|
+
if (status === 409 && data.code === 'source-changed-while-open') {
|
|
634
|
+
if (data.model) current = data.model;
|
|
635
|
+
tick.checked = false;
|
|
636
|
+
paint();
|
|
637
|
+
showError('This workflow changed while this window was open, so nothing was approved. The details above are what it says now. Look them over, then confirm again.');
|
|
638
|
+
} else {
|
|
639
|
+
showError(data && data.error ? data.error : 'FloLess could not record your confirmation, so nothing was approved. Try again.');
|
|
640
|
+
}
|
|
641
|
+
} catch {
|
|
642
|
+
showError('FloLess could not record your confirmation, so nothing was approved. Check that FloLess is running and try again.');
|
|
643
|
+
}
|
|
644
|
+
busy = false;
|
|
645
|
+
ok.textContent = consentView(current, via).primary;
|
|
646
|
+
syncOk();
|
|
647
|
+
}
|
|
648
|
+
function onClick(event) {
|
|
649
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
650
|
+
if (!target) return;
|
|
651
|
+
const more = target.closest('[data-ac-more]');
|
|
652
|
+
if (more) {
|
|
653
|
+
const pre = more.nextElementSibling;
|
|
654
|
+
const open = more.getAttribute('aria-expanded') !== 'true';
|
|
655
|
+
more.setAttribute('aria-expanded', String(open));
|
|
656
|
+
more.textContent = open ? 'Hide full instructions' : 'Show full instructions';
|
|
657
|
+
if (pre) pre.hidden = !open;
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const button = target.closest('button');
|
|
661
|
+
if (!button) return;
|
|
662
|
+
if (button.id === 'ac-ok') void confirm();
|
|
663
|
+
else if (button.id === 'ac-cancel' && !busy) close('cancel');
|
|
664
|
+
else if (button.id === 'ac-remove' && !busy) {
|
|
665
|
+
const ids = (current.steps || []).map((step) => `“${step.nodeId}”`).join(', ');
|
|
666
|
+
close('cancel');
|
|
667
|
+
// A step FloLess cannot read has no name to give: the request then asks the AI to find and fix or remove it.
|
|
668
|
+
openDraft((ids
|
|
669
|
+
? `Remove the AI step ${ids} from “${app.displayName || app.id}”. ${WARN_LINE}`
|
|
670
|
+
: `An AI step in “${app.displayName || app.id}” is not written the way FloLess needs, so it cannot be confirmed. Find it, show me what is wrong, and propose the change that fixes it or removes it. ${WARN_LINE}`))
|
|
671
|
+
.then(() => model.context.toast('Drafted in AI Chat. Review it and send it there.', 'ok'))
|
|
672
|
+
.catch(() => model.context.toast('AI Chat is still starting. Try again in a moment.', 'warn'));
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
tick.checked = false;
|
|
676
|
+
showError('');
|
|
677
|
+
paint();
|
|
678
|
+
document.addEventListener('keydown', onKey, true);
|
|
679
|
+
root.addEventListener('click', onClick);
|
|
680
|
+
tick.addEventListener('change', syncOk);
|
|
681
|
+
root.classList.add('show');
|
|
682
|
+
tick.focus();
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Before Approve: 'approved' (the dialog confirmed AND approved the bytes it showed - the caller only reloads), 'cancel', or
|
|
688
|
+
* 'proceed' (nothing to ask: no AI step, already confirmed, feature off, or the server cannot be asked - the normal path goes on).
|
|
689
|
+
*/
|
|
690
|
+
async function confirmBeforeApprove(app) {
|
|
691
|
+
const status = await consentStatus(app.id);
|
|
692
|
+
if (!status || (status.state !== 'needed' && status.state !== 'changed')) return 'proceed';
|
|
693
|
+
const opened = await consentFetch('open', { app: app.id }).catch(() => null);
|
|
694
|
+
if (!opened || opened.status !== 200 || !opened.data.ok) return 'proceed';
|
|
695
|
+
return (await consentDialog(app, 'approve', opened.data)) === 'confirmed' ? 'approved' : 'cancel';
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/** Before Run: 'proceed' once confirmed or when nothing needs asking, else 'cancel' (nothing started). */
|
|
699
|
+
async function confirmBeforeRun(app) {
|
|
700
|
+
const status = await consentStatus(app.id);
|
|
701
|
+
if (!status || (status.state !== 'needed' && status.state !== 'changed')) return 'proceed';
|
|
702
|
+
const opened = await consentFetch('open', { app: app.id }).catch(() => null);
|
|
703
|
+
if (!opened || opened.status !== 200 || !opened.data.ok) return 'proceed';
|
|
704
|
+
return (await consentDialog(app, 'run-dialog', opened.data)) === 'confirmed' ? 'proceed' : 'cancel';
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// ── S5: the run record, the held-change card and the routine row words ──────────────────────────────────────
|
|
708
|
+
|
|
709
|
+
const AI_PILL_TIP = 'This answer was written by an AI Agent. It can differ each time the workflow runs, and steps that use it can differ too.';
|
|
710
|
+
/** The small label next to anything an Agent step produced. Same words everywhere: the trace, the run record, the report. */
|
|
711
|
+
const aiPillHtml = () => `<span class="ai-pill" data-tip="${esc(AI_PILL_TIP)}" aria-label="AI-produced">AI-produced</span>`;
|
|
712
|
+
|
|
713
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
714
|
+
|
|
715
|
+
/** What the "Questions for you" panel lists, in a fixed order: questions, then what did not answer, assumptions, then what was not done. */
|
|
716
|
+
function needsYouGroups(items) {
|
|
717
|
+
const order = [['question', 'Questions the Agent could not settle'], ['did-not-answer', 'A step did not answer'], ['assumption', 'What the Agent assumed'], ['held-change', 'Changes that were not made']];
|
|
718
|
+
return order.map(([kind, title]) => ({ kind, title, items: items.filter((item) => item.kind === kind) })).filter((group) => group.items.length);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
const OUTCOME_WORDS = { answered: 'Answered', 'needs-you': 'Needs you', 'timed-out': 'Did not answer in time', 'invalid-output': 'Answer not usable', failed: 'Did not answer', 'not-started': 'Did not start' };
|
|
722
|
+
|
|
723
|
+
/** One run's AI steps as plain words. Pure: the server's record in, strings out (nothing here is invented). */
|
|
724
|
+
function runRecordView(rec) {
|
|
725
|
+
if (!isRecord(rec) || !Array.isArray(rec.aiSteps) || !rec.aiSteps.length) return null;
|
|
726
|
+
const needs = Array.isArray(rec.needsYou) ? rec.needsYou.filter((item) => isRecord(item) && typeof item.text === 'string') : [];
|
|
727
|
+
const steps = rec.aiSteps.filter(isRecord).map((step) => {
|
|
728
|
+
const answered = step.ok === true;
|
|
729
|
+
const outcome = answered ? 'Answered' : (OUTCOME_WORDS[step.outcome] || (step.ok === false ? 'Did not answer' : 'Ran'));
|
|
730
|
+
const agent = step.agentName ? `Agent ${step.agentName}${Number.isSafeInteger(step.agentRevision) ? `, revision ${step.agentRevision}` : ''}` : (Number.isSafeInteger(step.agentRevision) ? `Revision ${step.agentRevision}` : '');
|
|
731
|
+
const who = [agent, [step.provider, step.model].filter(Boolean).join(' / '), Number.isFinite(step.durationMs) ? `${(step.durationMs / 1000).toFixed(1)} s` : ''].filter(Boolean).join(' · ');
|
|
732
|
+
return { nodeId: String(step.nodeId), answered, outcome, who, agentId: typeof step.agentId === 'string' ? step.agentId : '' };
|
|
733
|
+
});
|
|
734
|
+
const summary = `Last run · ${plural(steps.length, 'AI step', 'AI steps')}${needs.length ? ` · ${plural(needs.length, 'question for you', 'questions for you')}` : ''}`;
|
|
735
|
+
return { summary, steps, needsCount: needs.length, groups: needsYouGroups(needs), open: needs.length > 0 };
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const runs = new Map(); // appId -> the last run's record (kept only when it had an AI step)
|
|
739
|
+
const runGeneration = new Map();
|
|
740
|
+
|
|
741
|
+
function paintRunRecord() {
|
|
742
|
+
const box = document.getElementById('as-run');
|
|
743
|
+
if (!box) return;
|
|
744
|
+
const app = model.context.currentApp();
|
|
745
|
+
const view = app && enabled() ? runRecordView(runs.get(app.id)) : null;
|
|
746
|
+
if (!view) { box.hidden = true; return; }
|
|
747
|
+
// Open when the run left something for the person; otherwise whatever the person last chose for this workflow.
|
|
748
|
+
const open = view.open || (box.dataset.for === app.id && box.open);
|
|
749
|
+
box.dataset.for = app.id;
|
|
750
|
+
document.getElementById('as-run-sum').innerHTML = `${aiPillHtml()}<span class="as-run-sum-text">${esc(view.summary)}</span>`;
|
|
751
|
+
const stepHtml = view.steps.map((step) => `<div class="as-run-step"><div class="as-run-line"><b>${esc(step.nodeId)}</b>${aiPillHtml()}<span class="as-run-out ${step.answered ? 'ok' : 'warn'}">${step.answered ? '✓' : '△'} ${esc(step.outcome)}</span></div>`
|
|
752
|
+
+ `${step.who ? `<div class="as-run-who">${esc(step.who)}</div>` : ''}`
|
|
753
|
+
+ `${step.agentId ? `<button type="button" class="as-btn as-link" data-as-run-agent="${esc(step.agentId)}" data-command-id="shell.agent-run-open-agent">Open the Agent’s runs ▸</button>` : ''}</div>`).join('');
|
|
754
|
+
const needsHtml = view.groups.length
|
|
755
|
+
? `<div class="as-needs" role="group" aria-label="Questions for you"><div class="as-needs-title">Questions for you (${view.needsCount})</div>${view.groups.map((group) => `<div class="as-needs-group"><div class="as-needs-kind">${esc(group.title)}</div><ul>${group.items.map((item) => `<li><b>${esc(item.nodeId)}</b>: ${esc(item.text)}</li>`).join('')}</ul></div>`).join('')}</div>`
|
|
756
|
+
: '';
|
|
757
|
+
document.getElementById('as-run-body').innerHTML = stepHtml + needsHtml;
|
|
758
|
+
box.hidden = false;
|
|
759
|
+
box.open = open;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** Read the app's newest run and show how its AI steps went. A failed read says nothing and removes nothing it knew for sure. */
|
|
763
|
+
async function refreshRunRecord(appId) {
|
|
764
|
+
if (!appId) return;
|
|
765
|
+
const mine = (runGeneration.get(appId) || 0) + 1;
|
|
766
|
+
runGeneration.set(appId, mine);
|
|
767
|
+
paintRunRecord(); // the panel always shows the OPEN workflow's own record (or none) at once, never the previous workflow's
|
|
768
|
+
const on = await probe();
|
|
769
|
+
if (runGeneration.get(appId) !== mine) return;
|
|
770
|
+
if (!on) { runs.delete(appId); paintRunRecord(); return; }
|
|
771
|
+
let body = null;
|
|
772
|
+
try {
|
|
773
|
+
const response = await fetch(`/api/latest-run/${encodeURIComponent(appId)}`, { credentials: 'same-origin' });
|
|
774
|
+
body = response.ok ? await response.json() : null;
|
|
775
|
+
} catch { body = null; }
|
|
776
|
+
if (runGeneration.get(appId) !== mine || !body || body.ok !== true) return;
|
|
777
|
+
if (Array.isArray(body.aiSteps) && body.aiSteps.length) runs.set(appId, { runId: body.runId, aiSteps: body.aiSteps, needsYou: Array.isArray(body.needsYou) ? body.needsYou : [] });
|
|
778
|
+
else runs.delete(appId);
|
|
779
|
+
paintRunRecord();
|
|
780
|
+
void checkGates();
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// ── the held change ("Waiting for your approval") ──────────────────────────────────────────────────────────
|
|
784
|
+
|
|
785
|
+
const GATE_API = '/api/chat/agent-steps/gates';
|
|
786
|
+
const gateModel = { shown: null, timer: null, deciding: false, delay: 2000 };
|
|
787
|
+
|
|
788
|
+
/** Pure: how the card words a pending gate. `now` is a Date, `gate.expiresAt` an ISO time. */
|
|
789
|
+
function gateView(gate, now = new Date()) {
|
|
790
|
+
const until = new Date(gate.expiresAt);
|
|
791
|
+
const clock = Number.isFinite(until.getTime()) ? until.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : '';
|
|
792
|
+
let values = '';
|
|
793
|
+
try { values = typeof gate.values === 'string' ? gate.values : (JSON.stringify(gate.values, null, 2) ?? ''); } catch { values = ''; }
|
|
794
|
+
return {
|
|
795
|
+
gateId: String(gate.gateId),
|
|
796
|
+
title: 'Waiting for your approval',
|
|
797
|
+
summary: String(gate.summary || 'A change is waiting for you.'),
|
|
798
|
+
values,
|
|
799
|
+
time: clock ? `This step stops at ${clock}. If nobody decides, the change is not made.` : 'If nobody decides, the change is not made.',
|
|
800
|
+
expired: Number.isFinite(until.getTime()) && now.getTime() >= until.getTime(),
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function paintGate(gate) {
|
|
805
|
+
const card = document.getElementById('as-gate');
|
|
806
|
+
if (!card) return;
|
|
807
|
+
if (!gate) { card.hidden = true; gateModel.shown = null; return; }
|
|
808
|
+
const view = gateView(gate);
|
|
809
|
+
const same = gateModel.shown === view.gateId;
|
|
810
|
+
document.getElementById('as-gate-values').textContent = view.values;
|
|
811
|
+
document.getElementById('as-gate-label').hidden = !view.values;
|
|
812
|
+
document.getElementById('as-gate-values').hidden = !view.values;
|
|
813
|
+
document.getElementById('as-gate-time').textContent = view.time;
|
|
814
|
+
// The announcement is set once when the card appears, never again on a re-poll (no repeated interruptions).
|
|
815
|
+
if (!same) document.getElementById('as-gate-live').innerHTML = `<b>${esc(view.title)}.</b> ${esc(view.summary)}`;
|
|
816
|
+
if (!same) document.getElementById('as-gate-error').hidden = true;
|
|
817
|
+
gateModel.shown = view.gateId;
|
|
818
|
+
card.dataset.gate = view.gateId;
|
|
819
|
+
card.hidden = false;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
async function checkGates() {
|
|
823
|
+
if (!enabled()) return;
|
|
824
|
+
let gates = null;
|
|
825
|
+
try {
|
|
826
|
+
const response = await fetch(GATE_API, { credentials: 'same-origin' });
|
|
827
|
+
const body = response.ok ? await response.json() : null;
|
|
828
|
+
if (body && body.ok === true && Array.isArray(body.gates)) gates = body.gates;
|
|
829
|
+
} catch { gates = null; }
|
|
830
|
+
if (!gates) return; // a failed look says nothing: the card that was up stays, nothing new is invented
|
|
831
|
+
const next = gates[0] || null;
|
|
832
|
+
if (!next && gateModel.shown && !gateModel.deciding) {
|
|
833
|
+
model.context.toast('A change that was waiting for you is no longer waiting. Open the last run to see whether it was made.', 'warn');
|
|
834
|
+
}
|
|
835
|
+
paintGate(next);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* A run can stop at a confirmation step at any moment, wherever it was started (this window, AI Chat, a routine's run-now), and the
|
|
840
|
+
* page only hears a run's trace once the run is over. So as soon as the feature is known to be on, the page looks for a waiting
|
|
841
|
+
* change on its own, workflow open or not. It is one small local read: every two seconds while something is held or was just seen,
|
|
842
|
+
* backing off to every ten seconds while nothing is.
|
|
843
|
+
*/
|
|
844
|
+
const GATE_FAST_MS = 2000;
|
|
845
|
+
const GATE_SLOW_MS = 10000;
|
|
846
|
+
function startGateWatch() {
|
|
847
|
+
if (gateModel.timer || !enabled()) return;
|
|
848
|
+
gateModel.delay = GATE_FAST_MS;
|
|
849
|
+
const tick = async () => {
|
|
850
|
+
gateModel.timer = null;
|
|
851
|
+
if (!enabled()) return;
|
|
852
|
+
await checkGates();
|
|
853
|
+
gateModel.delay = gateModel.shown ? GATE_FAST_MS : Math.min(GATE_SLOW_MS, gateModel.delay * 2);
|
|
854
|
+
gateModel.timer = setTimeout(tick, gateModel.delay);
|
|
855
|
+
};
|
|
856
|
+
gateModel.timer = setTimeout(tick, gateModel.delay);
|
|
857
|
+
void checkGates();
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/** Trace events of the open run: a confirmation step starting is a cue to look at once, rather than wait for the next look. */
|
|
861
|
+
function noteTrace(ev) {
|
|
862
|
+
if (!isRecord(ev) || !enabled()) return;
|
|
863
|
+
if (ev.kind === 'node-start' && ev.agent === STEP_AGENT && ev.command === 'confirm') { gateModel.delay = GATE_FAST_MS; void checkGates(); }
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
async function decideGate(decision) {
|
|
867
|
+
const gateId = gateModel.shown;
|
|
868
|
+
if (!gateId || gateModel.deciding) return;
|
|
869
|
+
gateModel.deciding = true;
|
|
870
|
+
const error = document.getElementById('as-gate-error');
|
|
871
|
+
const buttons = ['as-gate-approve', 'as-gate-skip'].map((id) => document.getElementById(id));
|
|
872
|
+
buttons.forEach((b) => { if (b) b.setAttribute('aria-disabled', 'true'); });
|
|
873
|
+
try {
|
|
874
|
+
const response = await fetch(`${GATE_API}/${encodeURIComponent(gateId)}/decision`, {
|
|
875
|
+
method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ decision }),
|
|
876
|
+
});
|
|
877
|
+
const body = await response.json().catch(() => ({}));
|
|
878
|
+
if (response.ok && body.ok) {
|
|
879
|
+
paintGate(null);
|
|
880
|
+
model.context.toast(decision === 'approved' ? 'Approved. The workflow is making the change.' : 'Skipped. The change was not made.', 'ok');
|
|
881
|
+
} else {
|
|
882
|
+
if (response.status === 409) {
|
|
883
|
+
// Already decided (here or in another window), timed out, or the run ended: say what is known, and where to look.
|
|
884
|
+
paintGate(null);
|
|
885
|
+
model.context.toast('That change is no longer waiting for a decision: it was decided already, the time ran out, or the run ended. Open the last run to see whether it was made.', 'warn');
|
|
886
|
+
} else {
|
|
887
|
+
error.textContent = 'FloLess could not confirm your decision. Check that FloLess is running, then open the last run to see whether the change was made before you decide again.';
|
|
888
|
+
error.hidden = false;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
} catch {
|
|
892
|
+
error.textContent = 'FloLess could not confirm your decision. Check that FloLess is running, then open the last run to see whether the change was made before you decide again.';
|
|
893
|
+
error.hidden = false;
|
|
894
|
+
}
|
|
895
|
+
gateModel.deciding = false;
|
|
896
|
+
buttons.forEach((b) => { if (b) b.removeAttribute('aria-disabled'); });
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/** The words a scheduled run's row adds when it had an AI step: `{ ai, aiTip, questions, questionsTip }`, or null. */
|
|
900
|
+
function routineAiParts(lastRun) {
|
|
901
|
+
if (!isRecord(lastRun) || lastRun.aiAnswer !== true) return null;
|
|
902
|
+
const q = Number.isSafeInteger(lastRun.questionsForYou) && lastRun.questionsForYou > 0 ? lastRun.questionsForYou : 0;
|
|
903
|
+
return {
|
|
904
|
+
ai: 'AI answer',
|
|
905
|
+
aiTip: 'This run used an AI step. Its answer can differ each run.',
|
|
906
|
+
questions: q ? plural(q, 'question for you', 'questions for you') : '',
|
|
907
|
+
questionsTip: q ? 'The AI step left questions, assumptions or changes that were not made. Open the workflow to read them.' : '',
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
document.addEventListener('click', (event) => {
|
|
912
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
913
|
+
if (!target) return;
|
|
914
|
+
const open = target.closest('[data-as-run-agent]');
|
|
915
|
+
if (open) { model.context.openAgent(open.getAttribute('data-as-run-agent')); return; }
|
|
916
|
+
if (target.closest('#as-gate-approve')) void decideGate('approved');
|
|
917
|
+
else if (target.closest('#as-gate-skip')) void decideGate('skipped');
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
void probe(); // the feature probe starts the look for a waiting change as soon as it answers yes
|
|
921
|
+
|
|
922
|
+
window.flolessAgentSteps = {
|
|
923
|
+
probe, enabled, isStepNode, entryParts, refreshChecks, checkFor, stepCount, headerText, markTip, draftAdd, draftUpdate, paintCanvasControl,
|
|
924
|
+
BADGE_TIP, answerWords, bannerModel, stepFacts, consentView, consentStatus, consentDialog, confirmBeforeApprove, confirmBeforeRun,
|
|
925
|
+
aiPillHtml, runRecordView, refreshRunRecord, paintRunRecord, gateView, checkGates, noteTrace, routineAiParts,
|
|
926
|
+
configure(context) { Object.assign(model.context, context); },
|
|
927
|
+
forgetChecks(appId) {
|
|
928
|
+
const ids = appId === undefined ? [...model.checks.keys(), ...model.generation.keys()] : [appId];
|
|
929
|
+
for (const id of ids) { model.checks.delete(id); model.generation.set(id, (model.generation.get(id) || 0) + 1); }
|
|
930
|
+
},
|
|
931
|
+
_model: model,
|
|
932
|
+
};
|
|
933
|
+
})();
|