@floless/app 0.155.2 → 0.157.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 +392 -0
- package/dist/floless-server.cjs +182734 -141519
- package/dist/schemas/drawing-check.profile.v1.schema.json +15 -2
- package/dist/schemas/steel.model.v2.schema.json +25 -1
- package/dist/skills/floless-app-actions/SKILL.md +199 -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 +50 -14
- package/dist/skills/floless-app-new-workflow/SKILL.md +26 -10
- package/dist/skills/floless-app-onboarding/SKILL.md +31 -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 +15 -12
- package/dist/skills/floless-app-rfi/SKILL.md +98 -73
- package/dist/skills/floless-app-routines/SKILL.md +27 -15
- package/dist/skills/floless-app-routines/references/routines-api.md +8 -2
- package/dist/skills/floless-app-steel-model/SKILL.md +1 -1
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +4 -2
- package/dist/skills/floless-app-tweak-contract/SKILL.md +25 -5
- package/dist/skills/floless-app-workflows/SKILL.md +50 -13
- package/dist/skills/floless-app-workflows/references/agent-steps.md +119 -0
- package/dist/web/agent-steps.js +1750 -0
- package/dist/web/agents.js +33 -8
- package/dist/web/app.css +681 -4
- package/dist/web/app.js +111 -11
- package/dist/web/aware-update-client.js +1 -0
- package/dist/web/aware.js +1257 -202
- package/dist/web/chat-landing-scene.js +372 -0
- package/dist/web/chat.css +254 -1
- package/dist/web/chat.js +2657 -87
- package/dist/web/commands-drawing-check.js +17 -0
- package/dist/web/commands-shell.js +1108 -4
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/connections.js +1 -0
- package/dist/web/drawing-check-editor.html +33 -5
- package/dist/web/drawing-check-editor.js +538 -22
- package/dist/web/drawing-check-overlay.js +13 -0
- package/dist/web/flo-avatar.js +28 -3
- package/dist/web/guide.js +7 -2
- package/dist/web/index.html +171 -7
- package/dist/web/instructor.js +6 -4
- 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-view-query.js +12 -2
- package/dist/web/model-viewport-revit-adapter.js +3 -1
- package/dist/web/pages.js +891 -36
- package/dist/web/panels.js +8 -5
- package/dist/web/parser-setup-recovery.js +12 -4
- package/dist/web/project-access.js +549 -0
- package/dist/web/project-reconciliation.js +357 -0
- package/dist/web/report-files.js +50 -0
- package/dist/web/revit-editor.js +116 -27
- package/dist/web/startup-admission.js +132 -0
- package/dist/web/steel-3d-core.js +9 -0
- package/dist/web/steel-editor.html +642 -22
- package/dist/web/steel-model-v2-commands.js +63 -5
- package/dist/web/step-rename.js +287 -0
- package/dist/web/terminal-requests.js +590 -0
- package/dist/web/tool-updates.js +148 -13
- package/dist/web/workspace-root-management.js +39 -0
- package/dist/web/workspaces.js +1879 -74
- package/launch.mjs +82 -2
- package/package.json +3 -1
|
@@ -0,0 +1,1750 @@
|
|
|
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 `enabled: false` while it
|
|
10
|
+
* is off; an older server answered 404, which still reads as off).
|
|
11
|
+
* Loaded before aware.js and agents.js, which call window.flolessAgentSteps.
|
|
12
|
+
*/
|
|
13
|
+
(() => {
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const STEP_AGENT = 'floless-agent-step';
|
|
17
|
+
const STEP_COMMAND = 'reason';
|
|
18
|
+
const KEEP_PREFIX = 'floless:agent-step-keep:';
|
|
19
|
+
|
|
20
|
+
const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
21
|
+
const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
22
|
+
|
|
23
|
+
const model = {
|
|
24
|
+
enabled: null, // null = not known yet, true / false = the server's answer
|
|
25
|
+
probing: null,
|
|
26
|
+
checks: new Map(), // appId -> Map(nodeId -> check), the server's last answer
|
|
27
|
+
generation: new Map(), // appId -> the newest check ask, so an older answer cannot overwrite a newer one
|
|
28
|
+
notes: new Map(), // #2448: appId -> { enabled, global, shown, off }, the AI note in that workflow's reports
|
|
29
|
+
noteSync: new Map(), // #2461: appId -> how its AI-note reads and saves are kept in order (see noteSyncOf)
|
|
30
|
+
triggers: new Map(), // S8 (#2495): appId -> the watcher's waits ({ steps, version, ... }), or null when it waits for no trigger
|
|
31
|
+
fires: new Map(), // S8: appId -> the watcher's latest events that reached an AI step (newest first)
|
|
32
|
+
firesState: new Map(), // S8: appId -> null, 'unreadable' (the log could not be read) or 'stale' (the last refresh failed)
|
|
33
|
+
context: { currentApp: () => null, openAgent: () => {}, openAgents: () => {}, toast: () => {}, repaint: () => {}, runRecordChanged: () => {} },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// ── is the feature on ───────────────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
/** The server's answer, cached once it is definite. A network error is not an answer: the next call asks again. */
|
|
39
|
+
function probe() {
|
|
40
|
+
if (model.enabled !== null) return Promise.resolve(model.enabled);
|
|
41
|
+
if (!model.probing) {
|
|
42
|
+
model.probing = Promise.resolve().then(async () => {
|
|
43
|
+
await globalThis.flolessStartupAdmission?.admit('/api/agent-steps/status');
|
|
44
|
+
return fetch('/api/agent-steps/status', { credentials: 'same-origin', ...(typeof AbortSignal !== 'undefined' && AbortSignal.timeout ? { signal: AbortSignal.timeout(4000) } : {}) });
|
|
45
|
+
})
|
|
46
|
+
.then(async (response) => {
|
|
47
|
+
if (response.status === 404) model.enabled = false;
|
|
48
|
+
else if (response.ok) {
|
|
49
|
+
const body = await response.json().catch(() => null);
|
|
50
|
+
// `pending`: FloLess does not know the AWARE version yet (start-up). Not an answer: left unknown, asked again.
|
|
51
|
+
if (!(isRecord(body) && body.pending === true)) model.enabled = !(isRecord(body) && body.enabled === false);
|
|
52
|
+
}
|
|
53
|
+
if (model.enabled === true) { startGateWatch(); void initGlobalNote(); }
|
|
54
|
+
return model.enabled === true;
|
|
55
|
+
})
|
|
56
|
+
.catch(() => false)
|
|
57
|
+
.finally(() => { model.probing = null; });
|
|
58
|
+
}
|
|
59
|
+
return model.probing;
|
|
60
|
+
}
|
|
61
|
+
const enabled = () => model.enabled === true;
|
|
62
|
+
|
|
63
|
+
// ── reading a step ─────────────────────────────────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
/** A step is a `floless-agent-step/reason` node, or any node the approved lock marks `runtime-reasoning`. */
|
|
66
|
+
function isStepNode(node) {
|
|
67
|
+
if (!node) return false;
|
|
68
|
+
return node.runtimeReasoning === true || (node.agent === STEP_AGENT && node.command === STEP_COMMAND);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** What the step itself says (its source), so the card and Inspect never wait for the server. */
|
|
72
|
+
function stepFacts(node) {
|
|
73
|
+
const config = isRecord(node.config) ? node.config : {};
|
|
74
|
+
const sourceInputs = isRecord(node.sourceInputs) ? node.sourceInputs : {};
|
|
75
|
+
const lockInputs = isRecord(node.inputs) ? node.inputs : {};
|
|
76
|
+
// 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
|
|
77
|
+
// (`config:` and `inputs:` merged, `inputs:` winning). The lock's resolved inputs may be older than the source, so they are used only
|
|
78
|
+
// when the source carries neither block (an older server that does not send `sourceInputs`).
|
|
79
|
+
const fromSource = { ...config, ...sourceInputs };
|
|
80
|
+
const merged = Object.keys(fromSource).length ? fromSource : lockInputs;
|
|
81
|
+
const body = isRecord(merged.body) ? merged.body : {};
|
|
82
|
+
const output = isRecord(body.output) ? body.output : { format: 'text' };
|
|
83
|
+
return {
|
|
84
|
+
instructions: typeof merged.instructions === 'string' ? merged.instructions : '',
|
|
85
|
+
agentId: typeof body['agent-id'] === 'string' ? body['agent-id'] : '',
|
|
86
|
+
name: typeof body['agent-name'] === 'string' && body['agent-name'] ? body['agent-name'] : 'this Agent',
|
|
87
|
+
revision: Number.isSafeInteger(body['agent-revision']) ? body['agent-revision'] : null,
|
|
88
|
+
provider: body.provider === 'codex' ? 'Codex' : body.provider === 'claude' ? 'Claude' : null,
|
|
89
|
+
output,
|
|
90
|
+
scopeCount: Array.isArray(body.scope) ? body.scope.length : 0,
|
|
91
|
+
context: typeof body.context === 'string' ? body.context : '',
|
|
92
|
+
timeoutMinutes: Number.isSafeInteger(body['timeout-minutes']) ? body['timeout-minutes'] : null,
|
|
93
|
+
// S7: the pinned Knowledge block as the source writes it (null without one).
|
|
94
|
+
kb: isRecord(body.kb) && typeof body.kb.q === 'string' ? {
|
|
95
|
+
project: typeof body.kb.project === 'string' ? body.kb.project : '',
|
|
96
|
+
q: body.kb.q,
|
|
97
|
+
maxPages: Number.isSafeInteger(body.kb['max-pages']) ? body.kb['max-pages'] : null,
|
|
98
|
+
} : null,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function answerWords(output) {
|
|
103
|
+
if (!isRecord(output) || output.format !== 'json' || !isRecord(output.fields)) return 'Plain text';
|
|
104
|
+
const names = Object.keys(output.fields);
|
|
105
|
+
return names.length ? `A structured answer with: ${names.join(', ')}` : 'Plain text';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const plainDescription = (node) => {
|
|
109
|
+
const text = typeof node.description === 'string' ? node.description.trim() : '';
|
|
110
|
+
return text;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// ── "Keep revision N" ───────────────────────────────────────────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
const keepKey = (appId, nodeId, pinned, current) => `${KEEP_PREFIX}${appId}:${nodeId}:${pinned}->${current}`;
|
|
116
|
+
function isKept(appId, nodeId, pinned, current) {
|
|
117
|
+
try { return localStorage.getItem(keepKey(appId, nodeId, pinned, current)) === '1'; } catch { return false; }
|
|
118
|
+
}
|
|
119
|
+
function keep(appId, nodeId, pinned, current) {
|
|
120
|
+
try { localStorage.setItem(keepKey(appId, nodeId, pinned, current), '1'); } catch { /* private mode: the banner simply stays */ }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ── the banner: how the step stands against its saved Agent ─────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* What to tell the person, from the server's `check` for this step. Null when there is nothing to say - including when the
|
|
127
|
+
* check is absent or failed: no check never reads as "up to date".
|
|
128
|
+
*/
|
|
129
|
+
function bannerModel(check, facts, appId, nodeId) {
|
|
130
|
+
if (!check || check.state === 'current' || !Array.isArray(check.issues) || !check.issues.length) return null;
|
|
131
|
+
const pinned = check.pinned ? check.pinned.revision : facts.revision;
|
|
132
|
+
const current = check.current ? check.current.revision : null;
|
|
133
|
+
const kept = current !== null && pinned !== null && isKept(appId, nodeId, pinned, current);
|
|
134
|
+
// Only the "newer revision" notice can be kept. Every other finding (a deleted Agent, an unavailable project, a different scope,
|
|
135
|
+
// instructions that differ at the same revision, an archived Agent) is independent of which revision is kept and stays visible.
|
|
136
|
+
const keepable = new Set(['newer-revision']);
|
|
137
|
+
// S7: the Knowledge notes are shown under the step's Knowledge facts; an AI update would not fix them.
|
|
138
|
+
const shown = check.issues.filter((issue) => !(kept && keepable.has(issue.kind)) && !KB_NOTE_KINDS.has(issue.kind));
|
|
139
|
+
const lines = shown.map((issue) => issue.message);
|
|
140
|
+
if (!lines.length) return null;
|
|
141
|
+
const missing = check.issues.some((issue) => issue.kind === 'agent-missing');
|
|
142
|
+
return {
|
|
143
|
+
lines,
|
|
144
|
+
kinds: shown.map((issue) => issue.kind),
|
|
145
|
+
missing,
|
|
146
|
+
canKeep: !missing && pinned !== null && current !== null && shown.some((issue) => keepable.has(issue.kind)),
|
|
147
|
+
pinned,
|
|
148
|
+
current,
|
|
149
|
+
canOpenAgent: !missing && !!facts.agentId,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const KB_NOTE_KINDS = new Set(['kb-no-knowledge', 'kb-no-search-words']);
|
|
154
|
+
|
|
155
|
+
/** S7: the "Knowledge it is given" section of a step's Inspect, or '' for a step that reads none. */
|
|
156
|
+
function kbInspectHtml(facts, check) {
|
|
157
|
+
const pinned = check && check.pinned && isRecord(check.pinned.kb) ? check.pinned.kb : null;
|
|
158
|
+
if (!facts.kb && !pinned) return '';
|
|
159
|
+
const project = pinned && pinned.projectLabel ? pinned.projectLabel : ((facts.kb && /^project:([^@]*)@/.exec(facts.kb.project)) || [])[1] || 'Not recorded';
|
|
160
|
+
const q = pinned ? pinned.q : facts.kb.q;
|
|
161
|
+
const pages = facts.kb && facts.kb.maxPages === null ? 'Up to 4 (the default)' : `Up to ${pinned ? pinned.maxPages : facts.kb.maxPages}`;
|
|
162
|
+
const rows = [['Project', project], ['Looks for', `“${q}”`], ['Pages given', pages]];
|
|
163
|
+
const notes = (check && Array.isArray(check.issues) ? check.issues : []).filter((issue) => KB_NOTE_KINDS.has(issue.kind) && typeof issue.message === 'string');
|
|
164
|
+
return `<h3>Knowledge it is given</h3><dl class="as-facts">${rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`).join('')}</dl>`
|
|
165
|
+
+ '<p class="dim-note">FloLess picks the best-matching pages before the Agent starts and gives them to it to check against. The Agent is not given a Knowledge search of its own.</p>'
|
|
166
|
+
+ notes.map((issue) => `<p class="dim-note" role="note">${esc(issue.message)}</p>`).join('');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ── what a card and Inspect show ───────────────────────────────────────────────────────────────────────────
|
|
170
|
+
|
|
171
|
+
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.';
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The AI-step parts of a node's entry, or null for every other node (and for everything while the feature is off).
|
|
175
|
+
* `check` is the server's last answer for this step, absent until it arrives.
|
|
176
|
+
*/
|
|
177
|
+
function entryParts(app, node, check) {
|
|
178
|
+
if (!isStepNode(node)) return null; // factual: labelled whether or not the feature is on
|
|
179
|
+
const facts = stepFacts(node);
|
|
180
|
+
const banner = bannerModel(check, facts, app.id, node.id);
|
|
181
|
+
const blurb = `Asks “${facts.name}” to answer. Its answer is written by an AI each run.`;
|
|
182
|
+
const attention = !banner ? '' : banner.missing ? 'Agent not found. Open Inspect.'
|
|
183
|
+
: banner.kinds.includes('newer-revision') ? 'Newer instructions available.' : 'Something to check. Open Inspect.';
|
|
184
|
+
return {
|
|
185
|
+
facts,
|
|
186
|
+
banner,
|
|
187
|
+
blurb: banner && banner.missing ? esc(attention) : esc(blurb) + (attention ? `<span class="as-attn">${esc(attention)}</span>` : ''),
|
|
188
|
+
badge: { text: 'AI Agent step', tip: BADGE_TIP, aria: 'AI Agent step, the answer varies each run' },
|
|
189
|
+
attention,
|
|
190
|
+
descriptionHtml: inspectHtml(app, node, facts, banner, check),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ── #2374: what FloLess found using an Agent step's answer ─────────────────────────────────────────────────
|
|
195
|
+
|
|
196
|
+
/** The analysis the server sent with the app, or null when it cannot be relied on node by node. */
|
|
197
|
+
function answerUse(app) {
|
|
198
|
+
const use = app && isRecord(app.aiAnswerUse) ? app.aiAnswerUse : null;
|
|
199
|
+
if (!use || use.readable !== true || !isRecord(use.marks)) return null;
|
|
200
|
+
return Array.isArray(use.duplicateIds) && use.duplicateIds.length ? null : use;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const quoteList = (ids) => ids.map((id) => `“${id}”`).join(', ');
|
|
204
|
+
/** "“a”, “b”, “c” and 2 more": names stay readable however many there are. */
|
|
205
|
+
const shortList = (ids, max = 4) => (ids.length > max ? `${quoteList(ids.slice(0, max - 1))} and ${ids.length - (max - 1)} more` : quoteList(ids));
|
|
206
|
+
|
|
207
|
+
const USE_TEXT = { uses: 'Uses an AI answer', decided: 'Decided by an AI answer' };
|
|
208
|
+
function useSentence(how, steps) {
|
|
209
|
+
const of = `the answer of the AI step${steps.length === 1 ? '' : 's'} ${shortList(steps, 3)}`;
|
|
210
|
+
return how === 'uses'
|
|
211
|
+
? `Its result is built from ${of}, so it can differ each run.`
|
|
212
|
+
: `Whether and how this runs depends on ${of}, so it can differ each run.`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The mark on a node that is not itself an Agent step, or null. A container whose body holds marked steps (they are not cards of their
|
|
217
|
+
* own) says so. Marks are what FloLess FOUND; an unmarked node is never presented as fixed.
|
|
218
|
+
*/
|
|
219
|
+
function useParts(app, node) {
|
|
220
|
+
const use = answerUse(app);
|
|
221
|
+
if (!use || !node || isStepNode(node)) return null;
|
|
222
|
+
const mark = isRecord(use.marks[node.id]) ? use.marks[node.id] : null;
|
|
223
|
+
const inside = Object.entries(use.marks).filter(([, m]) => isRecord(m) && m.container === node.id).map(([id]) => id);
|
|
224
|
+
if (!mark && !inside.length) return null;
|
|
225
|
+
const steps = (list) => [...new Set(list.flatMap((m) => (Array.isArray(m.steps) ? m.steps.map(String) : [])))];
|
|
226
|
+
let chip; let line;
|
|
227
|
+
if (mark && (mark.how === 'uses' || mark.how === 'decided')) {
|
|
228
|
+
line = useSentence(mark.how, steps([mark]));
|
|
229
|
+
chip = { text: USE_TEXT[mark.how], tip: line, how: mark.how };
|
|
230
|
+
} else {
|
|
231
|
+
line = `Some steps inside use the answer of the AI step ${shortList(steps(inside.map((id) => use.marks[id])), 3)}: ${shortList(inside)}.`;
|
|
232
|
+
chip = { text: 'Contains steps that use an AI answer', tip: line, how: 'container' };
|
|
233
|
+
}
|
|
234
|
+
const insideLine = mark && inside.length ? `<p class="as-use-line">${esc(`Inside it, FloLess found ${shortList(inside)} using the answer too.`)}</p>` : '';
|
|
235
|
+
return { chip, descriptionHtml: `<p class="as-use-line">${esc(line)}</p>${insideLine}` };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The Agent step's standing Inspect sentence, from what was found (never "the rest is fixed"). */
|
|
239
|
+
function standingSentence(app, node) {
|
|
240
|
+
const lead = 'This step’s answer is written by an AI and may differ each time the workflow runs.';
|
|
241
|
+
const raw = app && isRecord(app.aiAnswerUse) ? app.aiAnswerUse : null;
|
|
242
|
+
const use = answerUse(app);
|
|
243
|
+
if (!use) {
|
|
244
|
+
return raw ? `${lead} Steps that use the answer can differ too, but FloLess couldn’t work out which ones for this workflow.`
|
|
245
|
+
: `${lead} Steps that use the answer can differ too.`;
|
|
246
|
+
}
|
|
247
|
+
const found = Object.entries(use.marks).filter(([, m]) => isRecord(m) && Array.isArray(m.steps) && m.steps.includes(node.id)).map(([id]) => id);
|
|
248
|
+
return found.length
|
|
249
|
+
? `${lead} Steps that use the answer can differ too. Found: ${shortList(found)} (marked on the canvas). Other steps may use it in ways FloLess can’t trace.`
|
|
250
|
+
: `${lead} No step using the answer was found. Steps may still use it in ways FloLess can’t trace.`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The trace's label on an output a found step produced, read from THAT run's own record (the snapshot taken when it was launched),
|
|
255
|
+
* never from the workflow as it is today: a replayed older run, or a run whose record has not arrived yet, gets no label.
|
|
256
|
+
*/
|
|
257
|
+
function usePillHtml(nodeId, runId) {
|
|
258
|
+
const app = model.context.currentApp();
|
|
259
|
+
const record = app && runId ? runs.get(app.id) : null;
|
|
260
|
+
if (!record || record.runId !== runId || !Array.isArray(record.dependents)) return '';
|
|
261
|
+
const mark = record.dependents.find((row) => isRecord(row) && row.nodeId === nodeId) || null;
|
|
262
|
+
if (!mark || (mark.how !== 'uses' && mark.how !== 'decided')) return '';
|
|
263
|
+
const tip = useSentence(mark.how, Array.isArray(mark.steps) ? mark.steps.map(String) : []);
|
|
264
|
+
const words = mark.how === 'uses' ? 'uses an AI answer' : 'decided by an AI answer';
|
|
265
|
+
return `<span class="ai-pill is-uses" data-tip="${esc(tip)}" aria-label="${esc(tip)}">${esc(words)}</span>`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function scopeWords(check, facts) {
|
|
269
|
+
if (check && check.pinned && Array.isArray(check.pinned.scope) && check.pinned.scope.length) {
|
|
270
|
+
return check.pinned.scope.map((item) => esc(item.label)).join(', ');
|
|
271
|
+
}
|
|
272
|
+
return facts.scopeCount ? `${facts.scopeCount} place${facts.scopeCount === 1 ? '' : 's'} in your workspace` : 'Nothing was pinned';
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function inspectHtml(app, node, facts, banner, check) {
|
|
276
|
+
const nodeAttr = esc(node.id);
|
|
277
|
+
let html = '';
|
|
278
|
+
if (banner) {
|
|
279
|
+
const actions = [];
|
|
280
|
+
actions.push(banner.missing
|
|
281
|
+
? `<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>`
|
|
282
|
+
: `<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>`);
|
|
283
|
+
if (banner.canKeep) {
|
|
284
|
+
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>`);
|
|
285
|
+
}
|
|
286
|
+
if (banner.canOpenAgent) {
|
|
287
|
+
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>`);
|
|
288
|
+
}
|
|
289
|
+
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>`;
|
|
290
|
+
}
|
|
291
|
+
const sentence = plainDescription(node);
|
|
292
|
+
html += `<p>${esc(sentence || `This step asks the Agent “${facts.name}” a question and uses its answer.`)}</p>`;
|
|
293
|
+
html += `<p class="as-standing">${esc(standingSentence(app, node))}</p>`;
|
|
294
|
+
if (app.runState && app.runState !== 'ready') {
|
|
295
|
+
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>';
|
|
296
|
+
}
|
|
297
|
+
html += `<h3>What it is told to do</h3>${facts.instructions
|
|
298
|
+
? `<pre class="as-instructions">${esc(facts.instructions)}</pre>`
|
|
299
|
+
: '<p class="dim-note">FloLess could not read this step’s instructions.</p>'}`;
|
|
300
|
+
const rows = [
|
|
301
|
+
['Agent', esc(facts.name)],
|
|
302
|
+
['Revision', facts.revision === null ? 'Not recorded' : esc(facts.revision)],
|
|
303
|
+
['AI', facts.provider ? esc(facts.provider) : 'Not recorded'],
|
|
304
|
+
['What it can see', scopeWords(check, facts)],
|
|
305
|
+
['Answer format', esc(answerWords(facts.output))],
|
|
306
|
+
];
|
|
307
|
+
html += `<h3>The Agent</h3><dl class="as-facts">${rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${v}</dd>`).join('')}</dl>`;
|
|
308
|
+
html += kbInspectHtml(facts, check);
|
|
309
|
+
html += triggerInspectHtml(model.triggers.get(app.id), node.id, model.fires.get(app.id), model.firesState.get(app.id));
|
|
310
|
+
html += noteHtml(model.notes.get(app.id));
|
|
311
|
+
return html;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* S8 (#2495): a watcher step's wait between answers and what it did for each event, or '' when the workflow waits for no trigger.
|
|
316
|
+
* Pure. `view` is the server's trigger view, `fires` the newest events first.
|
|
317
|
+
*/
|
|
318
|
+
function triggerInspectHtml(view, nodeId, fires, firesState = null) {
|
|
319
|
+
if (!isRecord(view) || !Array.isArray(view.steps)) return '';
|
|
320
|
+
const step = view.steps.find((s) => s.nodeId === nodeId);
|
|
321
|
+
if (!step) return '';
|
|
322
|
+
const id = esc(nodeId);
|
|
323
|
+
const on = step.minutes > 0;
|
|
324
|
+
let html = '<h3>When the trigger fires</h3>'
|
|
325
|
+
+ `<div class="as-note-row"><span>Wait between answers</span><span class="as-wait-value">${esc(waitWords(step.minutes))}</span>`
|
|
326
|
+
+ `<button type="button" class="as-btn" data-as-wait-change="${id}" data-command-id="shell.agent-step-wait-change" aria-expanded="false">Change</button></div>`
|
|
327
|
+
+ `<div class="as-wait-edit" data-as-wait-edit="${id}" hidden>`
|
|
328
|
+
+ `<span class="ac-wait-field"${on ? '' : ' hidden'}><input type="number" class="ac-wait-input" data-as-wait-input="${id}" min="1" max="1440" step="1" inputmode="numeric" value="${on ? esc(step.minutes) : 1}" aria-label="Minutes between AI answers" data-command-id="shell.agent-step-wait-minutes"><span class="ac-wait-unit">minutes</span></span>`
|
|
329
|
+
+ `<label class="rtn-toggle" data-tip="Off: the AI answers every time the trigger fires, one at a time."><input type="checkbox" role="switch" data-as-wait-on="${id}"${on ? ' checked' : ''} aria-label="Limit how often this AI step runs" data-command-id="shell.agent-step-wait-limit"><span class="rtn-toggle-track"></span></label>`
|
|
330
|
+
+ `<button type="button" class="as-btn primary" data-as-wait-save="${id}" data-command-id="shell.agent-step-wait-save">Save</button>`
|
|
331
|
+
+ `<button type="button" class="as-btn" data-as-wait-cancel="${id}" data-command-id="shell.agent-step-wait-cancel">Cancel</button></div>`
|
|
332
|
+
+ '<p class="as-note-hint">The AI step answers at most once in this time. An event inside the wait skips the AI step and is listed below. A shorter wait asks you to confirm again.</p>';
|
|
333
|
+
if (step.unreadable ?? view.unreadable) html += '<p class="as-note-hint is-global-off">FloLess could not read this step’s wait, so it waits at least an hour between answers until you set it again.</p>';
|
|
334
|
+
const mine = (Array.isArray(fires) ? fires : []).filter((f) => !Array.isArray(f.steps) || !f.steps.length || f.steps.some((s) => s.nodeId === nodeId)).slice(0, 10);
|
|
335
|
+
html += '<h3>What it did for each event</h3>';
|
|
336
|
+
if (firesState === 'unreadable') html += '<p class="as-note-hint is-global-off">FloLess could not read this watcher’s history, so events may be missing below. It tries again as new events land.</p>';
|
|
337
|
+
else if (firesState === 'stale') html += '<p class="as-note-hint is-global-off">FloLess couldn’t refresh this history just now, so it may be out of date. It tries again as new events land.</p>';
|
|
338
|
+
if (!mine.length) return `${html}<p class="dim-note">Nothing yet. Each time the trigger fires and reaches this AI step, it is listed here.</p>`;
|
|
339
|
+
html += `<ul class="as-fires">${mine.map((f) => {
|
|
340
|
+
const items = (Array.isArray(f.needsYou) ? f.needsYou : []).slice(0, 4).map((n) => `<li>${esc(n.text)}</li>`).join('');
|
|
341
|
+
return `<li class="as-fire"><span class="as-fire-when">${esc(whenWords(f.startedAt) || `Event ${f.fire}`)}</span> <span class="as-fire-outcome">${esc(f.outcome)}</span>${items ? `<ul class="as-fire-needs">${items}</ul>` : ''}</li>`;
|
|
342
|
+
}).join('')}</ul>`;
|
|
343
|
+
return html;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** S8: the words a watcher routine's card adds from its events (`aiEvents` from /api/routines), or null. */
|
|
347
|
+
function watcherCardParts(aiEvents) {
|
|
348
|
+
if (!isRecord(aiEvents) || !Number.isSafeInteger(aiEvents.events) || aiEvents.events < 1) return null;
|
|
349
|
+
const q = Number.isSafeInteger(aiEvents.needsYou) && aiEvents.needsYou > 0 ? aiEvents.needsYou : 0;
|
|
350
|
+
return {
|
|
351
|
+
ai: 'AI answer',
|
|
352
|
+
aiTip: `This watcher has an AI step. Its answer can differ each time. Latest event: ${String(aiEvents.latest || 'recorded')}.`,
|
|
353
|
+
questions: q ? plural(q, 'question for you', 'questions for you') : '',
|
|
354
|
+
questionsTip: q ? 'The AI step left questions, skipped events or changes that were not made. Open the workflow and select its AI step to read them.' : '',
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** S8: read a watcher's waits and its latest events, for Inspect. Never claims anything when a read fails. */
|
|
359
|
+
async function refreshTrigger(appId, opts = {}) {
|
|
360
|
+
try {
|
|
361
|
+
const waitsPath = `/api/app/${encodeURIComponent(appId)}/agent-step-waits`;
|
|
362
|
+
await globalThis.flolessStartupAdmission?.admit(waitsPath);
|
|
363
|
+
const response = await fetch(waitsPath, { credentials: 'same-origin' });
|
|
364
|
+
const body = response.ok ? await response.json() : null;
|
|
365
|
+
if (!body || body.ok !== true) return;
|
|
366
|
+
model.triggers.set(appId, body.trigger || null);
|
|
367
|
+
if (body.trigger) {
|
|
368
|
+
const firesResponse = await fetch(`/api/app/${encodeURIComponent(appId)}/agent-step-fires`, { credentials: 'same-origin' });
|
|
369
|
+
const fires = firesResponse.ok ? await firesResponse.json().catch(() => null) : null;
|
|
370
|
+
if (fires && fires.ok === true && Array.isArray(fires.fires)) {
|
|
371
|
+
model.fires.set(appId, fires.fires);
|
|
372
|
+
model.firesState.set(appId, fires.unreadable === true ? 'unreadable' : null);
|
|
373
|
+
} else model.firesState.set(appId, 'stale');
|
|
374
|
+
}
|
|
375
|
+
if (model.context.currentApp()?.id !== appId) return;
|
|
376
|
+
// A wait editor the person has open is never closed under them by an event landing: the repaint waits until it closes.
|
|
377
|
+
if (!opts.closeEditor && document.querySelector('[data-as-wait-edit]:not([hidden])')) { model.repaintAfterEdit = appId; return; }
|
|
378
|
+
model.context.repaint(appId);
|
|
379
|
+
} catch { /* not known: Inspect shows what it had */ }
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** S8: a watcher event was recorded for `appId` (SSE): read its history again when that workflow is open (at most every 1.5 s). */
|
|
383
|
+
let watcherTimer = null;
|
|
384
|
+
function watcherChanged(appId) {
|
|
385
|
+
if (!appId || model.context.currentApp()?.id !== appId || !model.triggers.get(appId)) return;
|
|
386
|
+
if (watcherTimer) return;
|
|
387
|
+
watcherTimer = setTimeout(() => { watcherTimer = null; void refreshTrigger(appId); }, 1500);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** S8: the person saved a new wait in Inspect. Longer: saved. Shorter or off: the confirmation asks the second tick again. */
|
|
391
|
+
async function saveWait(appId, nodeId, minutes) {
|
|
392
|
+
const current = model.triggers.get(appId)?.steps?.find((s) => s.nodeId === nodeId)?.minutes;
|
|
393
|
+
const longer = Number.isInteger(current) && (minutes === 0 ? current === 0 : current === 0 || minutes >= current);
|
|
394
|
+
if (longer) {
|
|
395
|
+
try {
|
|
396
|
+
const response = await fetch(`/api/app/${encodeURIComponent(appId)}/agent-step-waits`, {
|
|
397
|
+
method: 'PUT', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ nodeId, minutes }),
|
|
398
|
+
});
|
|
399
|
+
const body = await response.json().catch(() => null);
|
|
400
|
+
if (response.ok && body && body.ok) {
|
|
401
|
+
model.context.toast(`Saved. The AI step now waits ${minutes === 0 ? 'nothing' : minutesWords(minutes)} between answers.`, 'ok');
|
|
402
|
+
await refreshTrigger(appId, { closeEditor: true });
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (!body || body.code !== 'needs-confirmation') {
|
|
406
|
+
model.context.toast(body && body.error ? body.error : 'FloLess couldn’t save the wait. Try again.', 'warn');
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
} catch { model.context.toast('FloLess couldn’t save the wait. Check that FloLess is running and try again.', 'warn'); return; }
|
|
410
|
+
}
|
|
411
|
+
const app = model.context.currentApp();
|
|
412
|
+
const opened = await consentFetch('open', { app: appId }).catch(() => null);
|
|
413
|
+
if (!app || !opened || opened.status !== 200 || !opened.data.ok) {
|
|
414
|
+
model.context.toast('FloLess couldn’t open the confirmation for the shorter wait. Nothing was changed. Try again.', 'warn');
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const outcome = await consentDialog(app, 'wait', opened.data, { [nodeId]: minutes });
|
|
418
|
+
if (outcome === 'confirmed' && !lastWaitNotSaved) model.context.toast('Confirmed. The AI step can now answer more often.', 'ok');
|
|
419
|
+
await refreshTrigger(appId, { closeEditor: true });
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// ── checks ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Ask the server how this workflow's steps stand, then repaint. A failed check says nothing (no claim either way). Each ask has a
|
|
426
|
+
* generation per workflow: a slower, older answer that lands after a newer ask (or after the checks were forgotten) is dropped, so it
|
|
427
|
+
* can never overwrite what is current.
|
|
428
|
+
*/
|
|
429
|
+
async function refreshChecks(app) {
|
|
430
|
+
if (!app) return;
|
|
431
|
+
const mine = (model.generation.get(app.id) || 0) + 1;
|
|
432
|
+
model.generation.set(app.id, mine);
|
|
433
|
+
const current = () => model.generation.get(app.id) === mine;
|
|
434
|
+
// The status probe is awaited HERE, in the detached check, never in loadApp: opening a workflow must not wait on it.
|
|
435
|
+
const on = await probe();
|
|
436
|
+
if (!current()) return;
|
|
437
|
+
if (!on || !Array.isArray(app.nodes) || !app.nodes.some(isStepNode)) { model.checks.delete(app.id); return; }
|
|
438
|
+
void refreshNote(app.id);
|
|
439
|
+
void refreshTrigger(app.id);
|
|
440
|
+
let steps = null;
|
|
441
|
+
try {
|
|
442
|
+
const path = `/api/agent-steps/check?app=${encodeURIComponent(app.id)}`;
|
|
443
|
+
await globalThis.flolessStartupAdmission?.admit(path);
|
|
444
|
+
if (!current()) return;
|
|
445
|
+
const response = await fetch(path, { credentials: 'same-origin' });
|
|
446
|
+
const body = response.ok ? await response.json() : null;
|
|
447
|
+
if (body && body.ok === true && Array.isArray(body.steps)) steps = body.steps;
|
|
448
|
+
} catch { steps = null; }
|
|
449
|
+
if (!current()) return;
|
|
450
|
+
if (!steps) {
|
|
451
|
+
// The answer is gone: whatever was shown from the earlier check must not stay up as if it were current.
|
|
452
|
+
if (model.checks.delete(app.id)) model.context.repaint(app.id);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
model.checks.set(app.id, new Map(steps.map((step) => [step.nodeId, step])));
|
|
456
|
+
model.context.repaint(app.id);
|
|
457
|
+
}
|
|
458
|
+
const checkFor = (appId, nodeId) => model.checks.get(appId)?.get(nodeId) ?? null;
|
|
459
|
+
|
|
460
|
+
/** How many AI steps the workflow has. */
|
|
461
|
+
function stepCount(app) {
|
|
462
|
+
if (!app || !Array.isArray(app.nodes)) return 0;
|
|
463
|
+
// 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
|
|
464
|
+
// deterministic (a stale lock still labels the workflow). Whether the lock matches the source is shown separately by the gate.
|
|
465
|
+
const steps = app.nodes.filter(isStepNode).length;
|
|
466
|
+
return steps || (app.nondeterministicOutput === true ? 1 : 0);
|
|
467
|
+
}
|
|
468
|
+
const headerText = (count) => (count > 1 ? `includes ${count} AI steps` : 'includes an AI step');
|
|
469
|
+
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.';
|
|
470
|
+
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.';
|
|
471
|
+
const markTip = (count) => (count > 1 ? MARK_TIP_MANY : MARK_TIP);
|
|
472
|
+
|
|
473
|
+
// ── relaying to AI Chat ─────────────────────────────────────────────────────────────────────────────────────
|
|
474
|
+
|
|
475
|
+
async function fetchBlock(agentId, extra = {}) {
|
|
476
|
+
const query = new URLSearchParams({ agent: agentId });
|
|
477
|
+
for (const [key, value] of Object.entries(extra)) if (value) query.set(key, value);
|
|
478
|
+
let response;
|
|
479
|
+
try { response = await fetch(`/api/agent-steps/block?${query}`, { credentials: 'same-origin' }); }
|
|
480
|
+
catch { throw new Error('FloLess could not be reached to load the Agent’s step. Make sure it is still running, then try again.'); }
|
|
481
|
+
let body = null;
|
|
482
|
+
try { body = await response.json(); } catch { body = null; }
|
|
483
|
+
if (!response.ok || !body || body.ok !== true) {
|
|
484
|
+
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 : '' });
|
|
485
|
+
}
|
|
486
|
+
return body;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const fence = (text) => `\`\`\`yaml\n${text.replace(/\n+$/, '')}\n\`\`\``;
|
|
490
|
+
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.';
|
|
491
|
+
|
|
492
|
+
/** What the server noted about the block (warnings) and what is still the author's to do (reminders), as one paragraph. */
|
|
493
|
+
function notes(block) {
|
|
494
|
+
const lines = [...(block.warnings || []), ...(block.next || [])].filter((line) => typeof line === 'string' && line);
|
|
495
|
+
return lines.length ? `\n\nFloLess noted: ${lines.join(' ')}` : '';
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** The marker line AWARE needs before it will compile an Agent step (not consent; the person still confirms in FloLess). */
|
|
499
|
+
function markerNote(block) {
|
|
500
|
+
const line = block.acknowledgement && block.acknowledgement.line;
|
|
501
|
+
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.` : '';
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// The Agent's name and revision come from the block the server just wrote (the truth), not from what the page remembered.
|
|
505
|
+
function addMessage({ workflowName, block }) {
|
|
506
|
+
const agentName = block.agent.name, revision = block.agent.revision;
|
|
507
|
+
const where = workflowName ? `the open workflow “${workflowName}”` : 'a workflow (ask me which one if it is not clear)';
|
|
508
|
+
const warnings = notes(block);
|
|
509
|
+
return `Add an Agent step to ${where}, using my Agent “${agentName}” (revision ${revision}).\n\n`
|
|
510
|
+
+ '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'
|
|
511
|
+
+ `${fence(block.fragment)}${warnings}\n\n${WARN_LINE}`;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function updateMessage({ nodeId, from, workflowName, block }) {
|
|
515
|
+
const agentName = block.agent.name, to = block.agent.revision; // what the server just wrote, not what the page remembered
|
|
516
|
+
const warnings = block.warnings && block.warnings.length ? `\n\nFloLess noted: ${block.warnings.join(' ')}` : '';
|
|
517
|
+
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`
|
|
518
|
+
+ 'Replace the step and its “-ok” check with exactly this block, keep the step id and the connections it already has:\n\n'
|
|
519
|
+
+ `${fence(block.fragment)}${warnings}${markerNote(block)}\n\n${WARN_LINE}`;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
async function openDraft(text) {
|
|
523
|
+
if (typeof window.flolessChat?.openDraft !== 'function') throw new Error('AI Chat is still starting. Try again in a moment.');
|
|
524
|
+
await window.flolessChat.openDraft(text);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** Put "add this Agent as a step" into the chat composer. Resolves true when drafted; says why in a toast when not. */
|
|
528
|
+
async function draftAdd({ agentId, agentName, revision, anyWorkflow = false }) {
|
|
529
|
+
try {
|
|
530
|
+
// From the Agents page no workflow is the target: the AI asks which one. From the canvas it is the open workflow.
|
|
531
|
+
const app = anyWorkflow ? null : model.context.currentApp();
|
|
532
|
+
// On the canvas FloLess's server picks the step id: free in the open workflow as it is saved now. The page guesses nothing;
|
|
533
|
+
// from the Agents page no workflow is named, and the block tells the AI to ask again once it knows which one.
|
|
534
|
+
const block = await fetchBlock(agentId, { context: '', ...(app ? { app: app.id } : {}) });
|
|
535
|
+
await openDraft(addMessage({ workflowName: app ? (app.displayName || app.id) : '', block }));
|
|
536
|
+
model.context.toast('Drafted in AI Chat. Review it and send it there.', 'ok');
|
|
537
|
+
return true;
|
|
538
|
+
} catch (error) {
|
|
539
|
+
const message = error instanceof Error && error.message ? error.message : 'FloLess could not draft that. Try again.';
|
|
540
|
+
// Nothing valid to pin (no instructions, nothing to read, instructions beyond what a step can carry): the person is not left at a
|
|
541
|
+
// 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.
|
|
542
|
+
if (error && ['cannot-pin', 'agent-no-instructions', 'agent-no-scope'].includes(error.code)) {
|
|
543
|
+
try {
|
|
544
|
+
await openDraft(`I tried to use my Agent “${agentName || 'this Agent'}” as a workflow step, but FloLess says: ${message}
|
|
545
|
+
|
|
546
|
+
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.`);
|
|
547
|
+
model.context.toast(`${message} A question about it is drafted in AI Chat.`, 'warn');
|
|
548
|
+
return false;
|
|
549
|
+
} catch { /* the toast below still tells the person */ }
|
|
550
|
+
}
|
|
551
|
+
model.context.toast(message, 'warn');
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
async function draftUpdate(appId, nodeId, replace) {
|
|
557
|
+
const app = model.context.currentApp();
|
|
558
|
+
const node = app && app.id === appId ? app.nodes.find((candidate) => candidate.id === nodeId) : null;
|
|
559
|
+
if (!node) return false;
|
|
560
|
+
const facts = stepFacts(node);
|
|
561
|
+
const check = checkFor(appId, nodeId);
|
|
562
|
+
const workflowName = app.displayName || app.id;
|
|
563
|
+
try {
|
|
564
|
+
const gone = Boolean(check && Array.isArray(check.issues) && check.issues.some((issue) => issue.kind === 'agent-missing'));
|
|
565
|
+
const where = workflowName ? `“${workflowName}”` : 'this workflow';
|
|
566
|
+
if (replace || gone) {
|
|
567
|
+
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.
|
|
568
|
+
|
|
569
|
+
${WARN_LINE}`);
|
|
570
|
+
} else if (!facts.agentId) {
|
|
571
|
+
// 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
|
|
572
|
+
// Agent is not claimed to be missing.
|
|
573
|
+
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.
|
|
574
|
+
|
|
575
|
+
${WARN_LINE}`);
|
|
576
|
+
} else {
|
|
577
|
+
// Everything the step already has is carried over, so an update changes the Agent's instructions and nothing else. The check
|
|
578
|
+
// is not needed for this (it may have been lost): the block the server writes now is the truth.
|
|
579
|
+
const block = await fetchBlock(facts.agentId, {
|
|
580
|
+
node: nodeId, context: facts.context, description: plainDescription(node), provider: facts.provider ? facts.provider.toLowerCase() : '',
|
|
581
|
+
output: JSON.stringify(facts.output), timeoutMinutes: facts.timeoutMinutes ? String(facts.timeoutMinutes) : '',
|
|
582
|
+
});
|
|
583
|
+
await openDraft(updateMessage({ nodeId, from: facts.revision ?? check?.pinned?.revision ?? '?', workflowName, block }));
|
|
584
|
+
}
|
|
585
|
+
model.context.toast('Drafted in AI Chat. Review it and send it there.', 'ok');
|
|
586
|
+
return true;
|
|
587
|
+
} catch (error) {
|
|
588
|
+
model.context.toast(error instanceof Error && error.message ? error.message : 'FloLess could not draft that. Try again.', 'warn');
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// ── Inspect buttons (delegated: Inspect is rebuilt on every render) ─────────────────────────────────────────
|
|
594
|
+
|
|
595
|
+
document.addEventListener('click', (event) => {
|
|
596
|
+
const button = event.target.closest && event.target.closest('[data-as-act]');
|
|
597
|
+
if (!button) return;
|
|
598
|
+
const app = model.context.currentApp();
|
|
599
|
+
if (!app) return;
|
|
600
|
+
const act = button.dataset.asAct;
|
|
601
|
+
if (act === 'update' || act === 'replace') { void draftUpdate(app.id, button.dataset.asNode, act === 'replace'); return; }
|
|
602
|
+
if (act === 'keep') {
|
|
603
|
+
keep(app.id, button.dataset.asNode, Number(button.dataset.asPinned), Number(button.dataset.asCurrent));
|
|
604
|
+
model.context.repaint(app.id);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (act === 'open-agent') model.context.openAgent(button.dataset.asAgent);
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
// ── the canvas chooser: "+ Agent step" ──────────────────────────────────────────────────────────────────────
|
|
611
|
+
|
|
612
|
+
let chooser = null; // { root, list, search, trigger, agents, onDocDown, onKey }
|
|
613
|
+
|
|
614
|
+
function closeChooser(returnFocus = true) {
|
|
615
|
+
if (!chooser) return;
|
|
616
|
+
const { root, trigger, onDocDown, onKey } = chooser;
|
|
617
|
+
document.removeEventListener('mousedown', onDocDown, true);
|
|
618
|
+
document.removeEventListener('keydown', onKey, true);
|
|
619
|
+
root.remove();
|
|
620
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
621
|
+
chooser = null;
|
|
622
|
+
if (returnFocus) trigger.focus();
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
async function loadAgents() {
|
|
626
|
+
await globalThis.flolessStartupAdmission?.admit('/api/chat/session');
|
|
627
|
+
const session = await fetch('/api/chat/session', { credentials: 'same-origin' });
|
|
628
|
+
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.');
|
|
629
|
+
await globalThis.flolessStartupAdmission?.admit('/api/chat/agents');
|
|
630
|
+
const response = await fetch('/api/chat/agents', { credentials: 'same-origin' });
|
|
631
|
+
const body = await response.json().catch(() => null);
|
|
632
|
+
if (!response.ok || !body || !Array.isArray(body.agents)) throw new Error('FloLess could not load your Agents just now. Try again.');
|
|
633
|
+
return body.agents.filter((agent) => !agent.archivedAt && agent.instructions && agent.scope && agent.scope.length);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function chooserRow(agent) {
|
|
637
|
+
const provider = agent.provider === 'codex' ? 'Codex' : agent.provider === 'claude' ? 'Claude' : 'AI not chosen';
|
|
638
|
+
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)}">`
|
|
639
|
+
+ `<span class="wf-option-name">${esc(agent.name)}</span><span class="wf-option-meta">${esc(provider)} · revision ${esc(agent.revision)}</span></div>`;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
async function openChooser(trigger) {
|
|
643
|
+
if (chooser) { closeChooser(); return; }
|
|
644
|
+
const root = document.createElement('div');
|
|
645
|
+
root.className = 'wf-popover as-popover';
|
|
646
|
+
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>';
|
|
647
|
+
trigger.parentElement.append(root);
|
|
648
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
649
|
+
const onDocDown = (event) => { if (!root.contains(event.target) && !trigger.contains(event.target)) closeChooser(false); };
|
|
650
|
+
document.addEventListener('mousedown', onDocDown, true);
|
|
651
|
+
// Escape closes the chooser whatever it is showing (loading, an error, the empty state, the list) and wherever focus is.
|
|
652
|
+
// Capture phase on purpose: Escape must close this popover wherever focus is. (It also reaches nothing else while the popover is open.)
|
|
653
|
+
const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeChooser(); } };
|
|
654
|
+
document.addEventListener('keydown', onKey, true);
|
|
655
|
+
chooser = { root, trigger, onDocDown, onKey };
|
|
656
|
+
const list = root.querySelector('.as-list');
|
|
657
|
+
let agents;
|
|
658
|
+
try { agents = await loadAgents(); }
|
|
659
|
+
catch (error) {
|
|
660
|
+
if (chooser?.root !== root) return;
|
|
661
|
+
list.innerHTML = `<div class="wf-empty-search" role="alert">${esc(error.message)}</div>`;
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (chooser?.root !== root) return;
|
|
665
|
+
if (!agents.length) {
|
|
666
|
+
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>'
|
|
667
|
+
+ '<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>';
|
|
668
|
+
list.querySelector('[data-as-open-agents]').addEventListener('click', () => { closeChooser(false); model.context.openAgents(); });
|
|
669
|
+
list.querySelector('button').focus();
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
list.innerHTML = agents.map(chooserRow).join('');
|
|
673
|
+
const options = () => [...list.querySelectorAll('.as-option')];
|
|
674
|
+
const move = (delta) => {
|
|
675
|
+
const all = options();
|
|
676
|
+
const at = all.indexOf(document.activeElement);
|
|
677
|
+
all[Math.max(0, Math.min(all.length - 1, at + delta))]?.focus();
|
|
678
|
+
};
|
|
679
|
+
options().forEach((option) => {
|
|
680
|
+
option.addEventListener('click', () => {
|
|
681
|
+
const agent = agents.find((candidate) => candidate.agentId === option.dataset.asAgent);
|
|
682
|
+
closeChooser(false);
|
|
683
|
+
if (agent) void draftAdd({ agentId: agent.agentId, agentName: agent.name, revision: agent.revision });
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
root.addEventListener('keydown', (event) => {
|
|
687
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); move(1); }
|
|
688
|
+
else if (event.key === 'ArrowUp') { event.preventDefault(); move(-1); }
|
|
689
|
+
else if (event.key === 'Enter' || event.key === ' ') { if (document.activeElement?.classList.contains('as-option')) { event.preventDefault(); document.activeElement.click(); } }
|
|
690
|
+
});
|
|
691
|
+
options()[0]?.focus();
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function paintCanvasControl() {
|
|
695
|
+
const group = document.getElementById('as-add-group');
|
|
696
|
+
if (!group) return;
|
|
697
|
+
const app = model.context.currentApp();
|
|
698
|
+
group.hidden = !(enabled() && app);
|
|
699
|
+
if (group.hidden) closeChooser(false);
|
|
700
|
+
}
|
|
701
|
+
const trigger = document.getElementById('as-add');
|
|
702
|
+
if (trigger) trigger.addEventListener('click', () => { void openChooser(trigger); });
|
|
703
|
+
|
|
704
|
+
// Ask early, off the critical path: the canvas control appears as soon as the server says the feature is on.
|
|
705
|
+
void probe().then(() => paintCanvasControl());
|
|
706
|
+
|
|
707
|
+
// ── the confirmation dialog (S4) ──────────────────────────────────────────────────────────────────────────────
|
|
708
|
+
// Approve and Run ask the server first (GET status). A workflow with an AI step nobody has confirmed - or one that changed since -
|
|
709
|
+
// opens #agent-consent-modal instead of going on. The person ticks one box; the SERVER records who/when/which steps and approves the
|
|
710
|
+
// exact bytes shown (the hash comes back with the model). This file never records anything itself and the AI chat cannot answer it.
|
|
711
|
+
|
|
712
|
+
const CONSENT_API = '/api/chat/agent-steps/consent';
|
|
713
|
+
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.';
|
|
714
|
+
|
|
715
|
+
function whenWords(iso) {
|
|
716
|
+
const date = new Date(iso);
|
|
717
|
+
if (Number.isNaN(date.getTime())) return '';
|
|
718
|
+
return date.toLocaleString([], { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' });
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function stepCardHtml(step, tag) {
|
|
722
|
+
const rows = [
|
|
723
|
+
['Answered by', step.provider === 'codex' ? 'Codex' : 'Claude'],
|
|
724
|
+
['Can read', (step.scope && step.scope.length ? step.scope : ['Nothing was pinned']).join(', ')],
|
|
725
|
+
['Answer format', step.answerFormat === 'json' ? 'A structured answer' : 'Plain text'],
|
|
726
|
+
['Time limit', `${step.timeoutMinutes} min`],
|
|
727
|
+
// S7: the Knowledge FloLess gives the step is part of what the person confirms.
|
|
728
|
+
...(typeof step.knowledge === 'string' && step.knowledge ? [['Reads Knowledge', step.knowledge]] : []),
|
|
729
|
+
];
|
|
730
|
+
const long = String(step.instructions || '').trim().length > String(step.firstLine || '').length;
|
|
731
|
+
return `<div class="ac-step" data-ac-node="${esc(step.nodeId)}">`
|
|
732
|
+
+ `<div class="ac-step-head"><span class="ac-step-name">${esc(step.agentName || step.nodeId)}</span>`
|
|
733
|
+
+ `<span class="ac-step-rev">${step.agentRevision !== null && step.agentRevision !== undefined ? `revision ${esc(step.agentRevision)}` : ''}${tag ? ` · ${esc(tag)}` : ''}</span></div>`
|
|
734
|
+
+ `<dl class="ac-facts">${rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`).join('')}</dl>`
|
|
735
|
+
+ (step.firstLine ? `<p class="ac-first">${esc(step.firstLine)}</p>` : '')
|
|
736
|
+
+ (long ? `<button type="button" class="ac-more" data-ac-more aria-expanded="false" data-command-id="shell.agent-consent-more">Show full instructions</button>`
|
|
737
|
+
+ `<pre class="ac-pre" hidden tabindex="0" aria-label="Full instructions, read only">${esc(step.instructions)}</pre>` : '')
|
|
738
|
+
+ '</div>';
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function diffHtml(lines) {
|
|
742
|
+
return `<pre class="ac-pre ac-diff" tabindex="0" aria-label="What changed in the instructions, read only">${lines.map((line) => {
|
|
743
|
+
const cls = line.op === '+' ? 'add' : line.op === '-' ? 'del' : '';
|
|
744
|
+
const word = line.op === '+' ? 'added: ' : line.op === '-' ? 'removed: ' : '';
|
|
745
|
+
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>`;
|
|
746
|
+
}).join('')}</pre>`;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function changeCardHtml(change, steps) {
|
|
750
|
+
const step = steps.find((candidate) => candidate.nodeId === change.nodeId);
|
|
751
|
+
if (change.kind === 'added') return step ? stepCardHtml(step, 'New step') : '';
|
|
752
|
+
const name = step ? (step.agentName || step.nodeId) : change.nodeId;
|
|
753
|
+
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>`;
|
|
754
|
+
if (change.instructionsDiff) html += diffHtml(change.instructionsDiff);
|
|
755
|
+
else if (change.fields.includes('instructionsSha256')) html += '<p class="ac-first">The instructions changed (the earlier text was not kept).</p>';
|
|
756
|
+
if (change.rows.length) {
|
|
757
|
+
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>`;
|
|
758
|
+
}
|
|
759
|
+
return `${html}</div>`;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// ── S8 (#2495): the wait between a watcher's AI answers, and the second tick ─────────────────────────────────────
|
|
763
|
+
|
|
764
|
+
const minutesWords = (minutes) => (minutes === 1 ? '1 minute' : `${minutes} minutes`);
|
|
765
|
+
const waitWords = (minutes) => (minutes === 0 ? 'No wait' : minutesWords(minutes));
|
|
766
|
+
|
|
767
|
+
/** The second tick's words for these waits — the server's own sentence (agent-step-consent-service.ts `triggerSentence`). */
|
|
768
|
+
function triggerSentenceFor(waits) {
|
|
769
|
+
const distinct = [...new Set(waits)];
|
|
770
|
+
const many = waits.length > 1;
|
|
771
|
+
const who = `Its AI step${many ? 's' : ''} can run on ${many ? 'their' : 'its'} own`;
|
|
772
|
+
if (distinct.length === 1 && distinct[0] === 0) {
|
|
773
|
+
return `This workflow waits for a trigger. ${who} every time the trigger fires, with no wait between answers, using your AI subscription. I understand.`;
|
|
774
|
+
}
|
|
775
|
+
const how = distinct.length === 1 ? `at most once every ${minutesWords(distinct[0])}` : 'at most as often as the wait set for each step';
|
|
776
|
+
return `This workflow waits for a trigger. ${who} each time the trigger fires — ${how} — using your AI subscription. I understand.`;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/** One AI step's wait control in the dialog: a whole number of minutes and a switch for "no wait". Pure. */
|
|
780
|
+
function waitRowHtml(step, many) {
|
|
781
|
+
const id = esc(step.nodeId);
|
|
782
|
+
const on = step.minutes > 0;
|
|
783
|
+
return `<div class="ac-wait-row" data-ac-wait-row="${id}">`
|
|
784
|
+
+ `<label class="ac-wait-label" for="ac-wait-${id}">Wait between AI answers${many ? ` <span class="ac-wait-step">· ${id}</span>` : ''}</label>`
|
|
785
|
+
+ `<span class="ac-wait-field"${on ? '' : ' hidden'}><input type="number" class="ac-wait-input" id="ac-wait-${id}" data-ac-wait="${id}" min="1" max="1440" step="1" inputmode="numeric" value="${on ? esc(step.minutes) : 1}" data-command-id="shell.agent-consent-wait#${esc(step.nodeId)}" data-command-instance-label="${esc(step.nodeId)}"><span class="ac-wait-unit">minutes</span></span>`
|
|
786
|
+
+ `<label class="rtn-toggle ac-wait-switch" data-tip="Off: the AI answers every time the trigger fires, one at a time."><input type="checkbox" role="switch" data-ac-wait-on="${id}"${on ? ' checked' : ''} aria-label="Limit how often the AI step ${id} runs" data-command-id="shell.agent-consent-wait-limit#${esc(step.nodeId)}" data-command-instance-label="${esc(step.nodeId)}"><span class="rtn-toggle-track"></span></label>`
|
|
787
|
+
+ `<span class="ac-wait-state">${on ? 'Limited' : 'No wait — every event'}</span></div>`;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/** The words and markup of the dialog for one server model. Pure: no DOM, so it is testable on its own. */
|
|
791
|
+
function consentView(model, via, presetWaits = null) {
|
|
792
|
+
const changed = model.state === 'changed' && Array.isArray(model.changes) && model.changes.length > 0;
|
|
793
|
+
const steps = Array.isArray(model.steps) ? model.steps : [];
|
|
794
|
+
let body;
|
|
795
|
+
if (changed) {
|
|
796
|
+
body = model.changes.map((change) => changeCardHtml(change, steps)).join('');
|
|
797
|
+
const unchanged = steps.filter((step) => !model.changes.some((change) => change.nodeId === step.nodeId)).length;
|
|
798
|
+
if (unchanged) body += `<p class="ac-unchanged">${unchanged} other AI step${unchanged === 1 ? '' : 's'} unchanged since you confirmed.</p>`;
|
|
799
|
+
} else {
|
|
800
|
+
body = steps.map((step) => stepCardHtml(step, '')).join('');
|
|
801
|
+
}
|
|
802
|
+
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>`;
|
|
803
|
+
const nameOf = (name) => (/^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(String(name)) ? 'You' : name);
|
|
804
|
+
const who = model.latest ? `${nameOf(model.latest.confirmedBy)}${whenWords(model.latest.confirmedAt) ? ` on ${whenWords(model.latest.confirmedAt)}` : ''}` : '';
|
|
805
|
+
// S8: a workflow that waits for a trigger adds each step's wait and the second tick.
|
|
806
|
+
const trigRaw = isRecord(model.trigger) && Array.isArray(model.trigger.steps) ? model.trigger : null;
|
|
807
|
+
// S8: from Inspect ('wait'), the dialog shows the shorter wait the person asked for, and says that is what they confirm.
|
|
808
|
+
const preset = (step) => (isRecord(presetWaits) && Number.isInteger(presetWaits[step.nodeId]) ? presetWaits[step.nodeId] : step.minutes);
|
|
809
|
+
const trig = trigRaw ? { ...trigRaw, steps: trigRaw.steps.map((step) => ({ ...step, was: step.minutes, minutes: preset(step) })) } : null;
|
|
810
|
+
let heading = changed ? 'The AI step changed since you last confirmed' : 'This workflow includes an AI step';
|
|
811
|
+
let sub = changed ? `${who ? `Last confirmed by ${who}. ` : ''}Look at what changed, then confirm again. ${CONSENT_FIRST_SUB}` : CONSENT_FIRST_SUB;
|
|
812
|
+
const shortening = trig && via === 'wait' ? trig.steps.filter((s) => s.minutes !== s.was) : [];
|
|
813
|
+
if (shortening.length) {
|
|
814
|
+
heading = 'You are shortening the wait between AI answers';
|
|
815
|
+
sub = `Your AI step will be able to run more often. ${shortening.map((s) => `Wait: ${waitWords(s.was)} → ${waitWords(s.minutes)}`).join('. ')}. Confirm that you are fine with that.`;
|
|
816
|
+
} else if (trig && model.state === 'changed' && !changed) {
|
|
817
|
+
const shortened = trig.steps.filter((s) => Number.isInteger(s.confirmedMinutes) && !s.covered);
|
|
818
|
+
if (shortened.length) {
|
|
819
|
+
heading = 'You shortened the wait between AI answers';
|
|
820
|
+
sub = `Your AI step will be able to run more often. ${shortened.map((s) => `Wait: ${waitWords(s.confirmedMinutes)} → ${waitWords(s.minutes)}`).join('. ')}. Confirm that you are fine with that.`;
|
|
821
|
+
} else {
|
|
822
|
+
heading = 'This workflow now waits for a trigger';
|
|
823
|
+
sub = `${who ? `Last confirmed by ${who}, ` : 'It was confirmed '}when the workflow only ran when started. Its AI step can now run by itself each time the trigger fires, so FloLess needs one more confirmation. ${CONSENT_FIRST_SUB}`;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return {
|
|
827
|
+
title: heading, sub, body,
|
|
828
|
+
warning: model.warning || '',
|
|
829
|
+
sentence: model.sentence,
|
|
830
|
+
primary: via === 'wait' ? 'Confirm the new wait' : via === 'run-dialog' ? 'Confirm and run' : 'Approve workflow',
|
|
831
|
+
trigger: trig ? {
|
|
832
|
+
html: trig.steps.map((step) => waitRowHtml(step, trig.steps.length > 1)).join(''),
|
|
833
|
+
steps: trig.steps.map((step) => ({ nodeId: step.nodeId, minutes: step.minutes })),
|
|
834
|
+
sentence: triggerSentenceFor(trig.steps.map((step) => step.minutes)),
|
|
835
|
+
unreadable: trig.unreadable === true,
|
|
836
|
+
} : null,
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
async function consentFetch(path, body) {
|
|
841
|
+
const response = await fetch(`${CONSENT_API}/${path}`, {
|
|
842
|
+
credentials: 'same-origin',
|
|
843
|
+
...(body ? { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) } : {}),
|
|
844
|
+
});
|
|
845
|
+
const data = await response.json().catch(() => ({}));
|
|
846
|
+
return { status: response.status, data };
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/** The server's view of this workflow's confirmation, or null when it cannot be asked (then the normal path goes on). */
|
|
850
|
+
async function consentStatus(appId) {
|
|
851
|
+
try {
|
|
852
|
+
if (!(await probe())) return null;
|
|
853
|
+
const { status, data } = await consentFetch(`status?app=${encodeURIComponent(appId)}`);
|
|
854
|
+
return status === 200 && data && data.ok ? data : null;
|
|
855
|
+
} catch { return null; }
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
let consentOpen = false;
|
|
859
|
+
/** #2314: the rename ask the confirmation was answered with, handed to the Compile button once. */
|
|
860
|
+
let pendingRenameAsk = null;
|
|
861
|
+
/** S8: the last confirmation was recorded but its new wait could not be saved (the dialog already said so). */
|
|
862
|
+
let lastWaitNotSaved = false;
|
|
863
|
+
function takeRenameAsk() { const ask = pendingRenameAsk; pendingRenameAsk = null; return ask; }
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Show the dialog. Resolves 'confirmed' once the server recorded it (and, from Approve, approved those exact bytes), else 'cancel'.
|
|
867
|
+
* `via` is 'approve', 'run-dialog' or (S8) 'wait' — a shorter wait from Inspect, `presetWaits` the waits it asks for. Never records
|
|
868
|
+
* anything itself.
|
|
869
|
+
*/
|
|
870
|
+
function consentDialog(app, via, initialModel, presetWaits = null) {
|
|
871
|
+
const root = document.getElementById('agent-consent-modal');
|
|
872
|
+
if (!root || consentOpen) return Promise.resolve('cancel');
|
|
873
|
+
consentOpen = true;
|
|
874
|
+
const $ = (id) => document.getElementById(id);
|
|
875
|
+
const tick = $('ac-tick'); const ok = $('ac-ok'); const hint = $('ac-hint'); const err = $('ac-error');
|
|
876
|
+
// S8: the second tick and the waits, for a workflow that waits for a trigger.
|
|
877
|
+
const trigBox = $('ac-trigger'); const tick2 = $('ac-tick2'); const waitsBox = $('ac-waits');
|
|
878
|
+
let waits = {};
|
|
879
|
+
const returnTo = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
880
|
+
let current = initialModel;
|
|
881
|
+
let busy = false;
|
|
882
|
+
return new Promise((resolve) => {
|
|
883
|
+
const needsTick2 = () => !!(trigBox && !trigBox.hidden && tick2);
|
|
884
|
+
const allTicked = () => tick.checked && (!needsTick2() || tick2.checked);
|
|
885
|
+
const syncOk = () => {
|
|
886
|
+
ok.setAttribute('aria-disabled', allTicked() && !busy ? 'false' : 'true');
|
|
887
|
+
hint.hidden = allTicked();
|
|
888
|
+
const missing = (tick.checked ? 0 : 1) + (needsTick2() && !tick2.checked ? 1 : 0);
|
|
889
|
+
hint.textContent = missing === 2 ? 'Tick both boxes to continue.' : needsTick2() && tick.checked ? 'Tick the second box to continue.' : 'Tick the box to continue.';
|
|
890
|
+
hint.classList.remove('nudge');
|
|
891
|
+
};
|
|
892
|
+
/** S8: the waits as the dialog now shows them; a field that does not hold a whole number keeps the last good value. */
|
|
893
|
+
const readWaits = () => {
|
|
894
|
+
for (const row of waitsBox ? waitsBox.querySelectorAll('[data-ac-wait-row]') : []) {
|
|
895
|
+
const id = row.getAttribute('data-ac-wait-row');
|
|
896
|
+
const on = row.querySelector('[data-ac-wait-on]');
|
|
897
|
+
const input = row.querySelector('[data-ac-wait]');
|
|
898
|
+
const field = row.querySelector('.ac-wait-field');
|
|
899
|
+
const state = row.querySelector('.ac-wait-state');
|
|
900
|
+
if (field) field.hidden = !(on && on.checked);
|
|
901
|
+
if (state) state.textContent = on && on.checked ? 'Limited' : 'No wait — every event';
|
|
902
|
+
if (on && !on.checked) { waits[id] = 0; continue; }
|
|
903
|
+
const value = input ? Number(input.value) : NaN;
|
|
904
|
+
if (Number.isInteger(value) && value >= 1 && value <= 1440) waits[id] = value;
|
|
905
|
+
else if (!waits[id]) waits[id] = 1;
|
|
906
|
+
}
|
|
907
|
+
if (tick2) $('ac-tick2-label').textContent = triggerSentenceFor(Object.values(waits));
|
|
908
|
+
};
|
|
909
|
+
const showError = (text) => { err.textContent = text || ''; err.hidden = !text; };
|
|
910
|
+
const paint = () => {
|
|
911
|
+
const view = consentView(current, via, presetWaits);
|
|
912
|
+
$('ac-title').textContent = view.title;
|
|
913
|
+
$('ac-sub').textContent = view.sub;
|
|
914
|
+
$('ac-body').innerHTML = view.body;
|
|
915
|
+
const warning = $('ac-warning');
|
|
916
|
+
warning.hidden = !view.warning;
|
|
917
|
+
warning.innerHTML = view.warning ? `<b>Heads up.</b> ${esc(view.warning)}` : '';
|
|
918
|
+
$('ac-tick-label').textContent = view.sentence;
|
|
919
|
+
if (trigBox) {
|
|
920
|
+
trigBox.hidden = !view.trigger;
|
|
921
|
+
waits = {};
|
|
922
|
+
if (view.trigger) {
|
|
923
|
+
for (const step of view.trigger.steps) waits[step.nodeId] = presetWaits && Number.isInteger(presetWaits[step.nodeId]) ? presetWaits[step.nodeId] : step.minutes;
|
|
924
|
+
waitsBox.innerHTML = view.trigger.html;
|
|
925
|
+
for (const row of waitsBox.querySelectorAll('[data-ac-wait-row]')) {
|
|
926
|
+
const id = row.getAttribute('data-ac-wait-row');
|
|
927
|
+
const on = row.querySelector('[data-ac-wait-on]'); const input = row.querySelector('[data-ac-wait]');
|
|
928
|
+
if (on) on.checked = waits[id] > 0;
|
|
929
|
+
if (input && waits[id] > 0) input.value = String(waits[id]);
|
|
930
|
+
}
|
|
931
|
+
readWaits();
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
ok.textContent = view.primary;
|
|
935
|
+
syncOk();
|
|
936
|
+
};
|
|
937
|
+
/** S8: a changed wait changes the sentence the person ticks, so the second tick is asked again. */
|
|
938
|
+
const onWaitChange = (event) => {
|
|
939
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
940
|
+
if (!target || !target.closest('[data-ac-wait-row]')) return;
|
|
941
|
+
const input = target.closest('[data-ac-wait]');
|
|
942
|
+
if (input && event.type === 'change') {
|
|
943
|
+
const value = Number(input.value);
|
|
944
|
+
if (!(Number.isInteger(value) && value >= 1 && value <= 1440)) {
|
|
945
|
+
showError('Enter a whole number of minutes from 1 to 1440, or turn the limit off. The wait stays as it was.');
|
|
946
|
+
input.value = String(waits[input.getAttribute('data-ac-wait')] || 1);
|
|
947
|
+
} else showError('');
|
|
948
|
+
}
|
|
949
|
+
readWaits();
|
|
950
|
+
if (tick2) tick2.checked = false;
|
|
951
|
+
syncOk();
|
|
952
|
+
};
|
|
953
|
+
const close = (result) => {
|
|
954
|
+
document.removeEventListener('keydown', onKey, true);
|
|
955
|
+
root.removeEventListener('click', onClick);
|
|
956
|
+
tick.removeEventListener('change', syncOk);
|
|
957
|
+
if (tick2) tick2.removeEventListener('change', syncOk);
|
|
958
|
+
if (waitsBox) { waitsBox.removeEventListener('input', onWaitChange); waitsBox.removeEventListener('change', onWaitChange); }
|
|
959
|
+
root.classList.remove('show');
|
|
960
|
+
consentOpen = false;
|
|
961
|
+
if (returnTo && returnTo.isConnected) returnTo.focus();
|
|
962
|
+
resolve(result);
|
|
963
|
+
};
|
|
964
|
+
const focusables = () => [...root.querySelectorAll('button, input, [tabindex="0"]')].filter((el) => !el.hidden && !el.closest('[hidden]'));
|
|
965
|
+
function onKey(event) {
|
|
966
|
+
if (!root.classList.contains('show')) return;
|
|
967
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); if (!busy) close('cancel'); return; }
|
|
968
|
+
if (event.key !== 'Tab') return;
|
|
969
|
+
const list = focusables();
|
|
970
|
+
if (!list.length) return;
|
|
971
|
+
const first = list[0]; const last = list[list.length - 1];
|
|
972
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
973
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
974
|
+
else if (!root.contains(document.activeElement)) { event.preventDefault(); first.focus(); }
|
|
975
|
+
}
|
|
976
|
+
async function confirm() {
|
|
977
|
+
if (busy) return;
|
|
978
|
+
if (!allTicked()) { hint.hidden = false; hint.classList.add('nudge'); (tick.checked ? tick2 : tick).focus(); return; }
|
|
979
|
+
busy = true; syncOk(); showError('');
|
|
980
|
+
ok.textContent = 'Working…';
|
|
981
|
+
try {
|
|
982
|
+
const trigger = needsTick2() ? { triggerTick: tick2.checked, waits: { ...waits }, waitsVersion: current.trigger ? current.trigger.version : 0 } : {};
|
|
983
|
+
const { status, data } = await consentFetch('confirm', { app: app.id, reviewedSourceHash: current.reviewedSourceHash, checkbox: true,
|
|
984
|
+
via: via === 'wait' ? 'run-dialog' : via, ...trigger });
|
|
985
|
+
if (status === 200 && data.ok) {
|
|
986
|
+
busy = false;
|
|
987
|
+
// S8: the confirmation is in the record, but the wait itself could not be saved, so the step waits as it did before.
|
|
988
|
+
lastWaitNotSaved = !!data.waitNotSaved;
|
|
989
|
+
if (lastWaitNotSaved) model.context.toast('Your confirmation was saved, but FloLess couldn’t save the new wait, so the AI step still waits as it did before. Change the wait again to retry.', 'warn');
|
|
990
|
+
close('confirmed'); return;
|
|
991
|
+
}
|
|
992
|
+
// #2314: two steps share one name, so nothing was approved. Close and hand over the rename ask; after a rename the
|
|
993
|
+
// caller compiles again and this dialog asks the person again.
|
|
994
|
+
if (data && data.code === 'ambiguous-step-name' && data.ask) { busy = false; pendingRenameAsk = data.ask; close('rename-step'); return; }
|
|
995
|
+
if (status === 409 && (data.code === 'source-changed-while-open' || data.code === 'waits-changed-while-open')) {
|
|
996
|
+
if (data.model) current = data.model;
|
|
997
|
+
tick.checked = false;
|
|
998
|
+
if (tick2) tick2.checked = false;
|
|
999
|
+
presetWaits = null;
|
|
1000
|
+
paint();
|
|
1001
|
+
showError(data.code === 'waits-changed-while-open'
|
|
1002
|
+
? 'The wait between AI answers was changed while this window was open, so nothing was approved. The wait above is what it is now. Look it over, then confirm again.'
|
|
1003
|
+
: '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.');
|
|
1004
|
+
} else {
|
|
1005
|
+
showError(data && data.error ? data.error : 'FloLess could not record your confirmation, so nothing was approved. Try again.');
|
|
1006
|
+
}
|
|
1007
|
+
} catch {
|
|
1008
|
+
showError('FloLess could not record your confirmation, so nothing was approved. Check that FloLess is running and try again.');
|
|
1009
|
+
}
|
|
1010
|
+
busy = false;
|
|
1011
|
+
ok.textContent = consentView(current, via).primary;
|
|
1012
|
+
syncOk();
|
|
1013
|
+
}
|
|
1014
|
+
function onClick(event) {
|
|
1015
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
1016
|
+
if (!target) return;
|
|
1017
|
+
const more = target.closest('[data-ac-more]');
|
|
1018
|
+
if (more) {
|
|
1019
|
+
const pre = more.nextElementSibling;
|
|
1020
|
+
const open = more.getAttribute('aria-expanded') !== 'true';
|
|
1021
|
+
more.setAttribute('aria-expanded', String(open));
|
|
1022
|
+
more.textContent = open ? 'Hide full instructions' : 'Show full instructions';
|
|
1023
|
+
if (pre) pre.hidden = !open;
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
const button = target.closest('button');
|
|
1027
|
+
if (!button) return;
|
|
1028
|
+
if (button.id === 'ac-ok') void confirm();
|
|
1029
|
+
else if (button.id === 'ac-cancel' && !busy) close('cancel');
|
|
1030
|
+
else if (button.id === 'ac-remove' && !busy) {
|
|
1031
|
+
const ids = (current.steps || []).map((step) => `“${step.nodeId}”`).join(', ');
|
|
1032
|
+
close('cancel');
|
|
1033
|
+
// A step FloLess cannot read has no name to give: the request then asks the AI to find and fix or remove it.
|
|
1034
|
+
openDraft((ids
|
|
1035
|
+
? `Remove the AI step ${ids} from “${app.displayName || app.id}”. ${WARN_LINE}`
|
|
1036
|
+
: `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}`))
|
|
1037
|
+
.then(() => model.context.toast('Drafted in AI Chat. Review it and send it there.', 'ok'))
|
|
1038
|
+
.catch(() => model.context.toast('AI Chat is still starting. Try again in a moment.', 'warn'));
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
tick.checked = false;
|
|
1042
|
+
if (tick2) tick2.checked = false;
|
|
1043
|
+
showError('');
|
|
1044
|
+
paint();
|
|
1045
|
+
document.addEventListener('keydown', onKey, true);
|
|
1046
|
+
root.addEventListener('click', onClick);
|
|
1047
|
+
tick.addEventListener('change', syncOk);
|
|
1048
|
+
if (tick2) tick2.addEventListener('change', syncOk);
|
|
1049
|
+
if (waitsBox) { waitsBox.addEventListener('input', onWaitChange); waitsBox.addEventListener('change', onWaitChange); }
|
|
1050
|
+
root.classList.add('show');
|
|
1051
|
+
tick.focus();
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Before Approve: 'approved' (the dialog confirmed AND approved the bytes it showed - the caller only reloads), 'cancel', or
|
|
1057
|
+
* 'proceed' (nothing to ask: no AI step, already confirmed, feature off, or the server cannot be asked - the normal path goes on),
|
|
1058
|
+
* or 'rename-step' (#2314: two steps share one name, nothing was approved; `takeRenameAsk()` hands over the ask).
|
|
1059
|
+
*/
|
|
1060
|
+
async function confirmBeforeApprove(app) {
|
|
1061
|
+
const status = await consentStatus(app.id);
|
|
1062
|
+
if (!status || (status.state !== 'needed' && status.state !== 'changed')) return 'proceed';
|
|
1063
|
+
const opened = await consentFetch('open', { app: app.id }).catch(() => null);
|
|
1064
|
+
if (!opened || opened.status !== 200 || !opened.data.ok) return 'proceed';
|
|
1065
|
+
const outcome = await consentDialog(app, 'approve', opened.data);
|
|
1066
|
+
return outcome === 'confirmed' ? 'approved' : outcome === 'rename-step' ? 'rename-step' : 'cancel';
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/** Before Run: 'proceed' once confirmed or when nothing needs asking, else 'cancel' (nothing started). */
|
|
1070
|
+
async function confirmBeforeRun(app) {
|
|
1071
|
+
const status = await consentStatus(app.id);
|
|
1072
|
+
if (!status || (status.state !== 'needed' && status.state !== 'changed')) return 'proceed';
|
|
1073
|
+
const opened = await consentFetch('open', { app: app.id }).catch(() => null);
|
|
1074
|
+
if (!opened || opened.status !== 200 || !opened.data.ok) return 'proceed';
|
|
1075
|
+
const outcome = await consentDialog(app, 'run-dialog', opened.data);
|
|
1076
|
+
if (outcome === 'rename-step') {
|
|
1077
|
+
// #2314: two steps share a name, so the workflow could not be approved. Ask to rename; the run waits for a Compile.
|
|
1078
|
+
const ask = takeRenameAsk();
|
|
1079
|
+
const renamed = globalThis.flolessStepRename && ask ? await globalThis.flolessStepRename.open(ask) : { renamed: false };
|
|
1080
|
+
model.context.toast(renamed.renamed ? 'Renamed. Compile the workflow, then run it.' : `${ask && ask.sentence ? `${ask.sentence} ` : ''}Nothing was renamed, so it can’t run yet.`, 'warn');
|
|
1081
|
+
return 'cancel';
|
|
1082
|
+
}
|
|
1083
|
+
return outcome === 'confirmed' ? 'proceed' : 'cancel';
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// ── S5: the run record, the held-change card and the routine row words ──────────────────────────────────────
|
|
1087
|
+
|
|
1088
|
+
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.';
|
|
1089
|
+
/** The small label next to anything an Agent step produced. Same words everywhere: the trace, the run record, the report. */
|
|
1090
|
+
const aiPillHtml = () => `<span class="ai-pill" data-tip="${esc(AI_PILL_TIP)}" aria-label="AI-produced">AI-produced</span>`;
|
|
1091
|
+
|
|
1092
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
1093
|
+
|
|
1094
|
+
/** What the "Questions for you" panel lists, in a fixed order: questions, then what did not answer, assumptions, then what was not done. */
|
|
1095
|
+
function needsYouGroups(items) {
|
|
1096
|
+
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']];
|
|
1097
|
+
return order.map(([kind, title]) => ({ kind, title, items: items.filter((item) => item.kind === kind) })).filter((group) => group.items.length);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
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' };
|
|
1101
|
+
|
|
1102
|
+
/** One run's AI steps as plain words. Pure: the server's record in, strings out (nothing here is invented). */
|
|
1103
|
+
function runRecordView(rec) {
|
|
1104
|
+
if (!isRecord(rec) || !Array.isArray(rec.aiSteps) || !rec.aiSteps.length) return null;
|
|
1105
|
+
const needs = Array.isArray(rec.needsYou) ? rec.needsYou.filter((item) => isRecord(item) && typeof item.text === 'string') : [];
|
|
1106
|
+
const steps = rec.aiSteps.filter(isRecord).map((step) => {
|
|
1107
|
+
const answered = step.ok === true;
|
|
1108
|
+
const outcome = answered ? 'Answered' : step.reason === 'cooldown' ? 'Skipped — the wait between answers' : (OUTCOME_WORDS[step.outcome] || (step.ok === false ? 'Did not answer' : 'Ran'));
|
|
1109
|
+
const agent = step.agentName ? `Agent ${step.agentName}${Number.isSafeInteger(step.agentRevision) ? `, revision ${step.agentRevision}` : ''}` : (Number.isSafeInteger(step.agentRevision) ? `Revision ${step.agentRevision}` : '');
|
|
1110
|
+
const who = [agent, [step.provider, step.model].filter(Boolean).join(' / '), Number.isFinite(step.durationMs) ? `${(step.durationMs / 1000).toFixed(1)} s` : ''].filter(Boolean).join(' · ');
|
|
1111
|
+
return {
|
|
1112
|
+
nodeId: String(step.nodeId), answered, outcome, who, agentId: typeof step.agentId === 'string' ? step.agentId : '',
|
|
1113
|
+
agentName: typeof step.agentName === 'string' ? step.agentName : '',
|
|
1114
|
+
stepRunId: typeof step.stepRunId === 'string' ? step.stepRunId : '',
|
|
1115
|
+
conversationId: typeof step.conversationId === 'string' ? step.conversationId : '',
|
|
1116
|
+
knowledge: runKbView(step.knowledge),
|
|
1117
|
+
};
|
|
1118
|
+
});
|
|
1119
|
+
const summary = `Last run · ${plural(steps.length, 'AI step', 'AI steps')}${needs.length ? ` · ${plural(needs.length, 'question for you', 'questions for you')}` : ''}`;
|
|
1120
|
+
return { summary, steps, needsCount: needs.length, groups: needsYouGroups(needs), open: needs.length > 0, uses: usesView(rec) };
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
const KB_NONE_WORDS = {
|
|
1124
|
+
'no-match': (q) => `No pages matched the search “${q}”.`,
|
|
1125
|
+
'no-generation': () => 'This project has no published Knowledge.',
|
|
1126
|
+
busy: () => 'The Knowledge was being organized, so none was given.',
|
|
1127
|
+
'no-search-words': () => 'The search had no words to look up.',
|
|
1128
|
+
incomplete: () => 'FloLess couldn’t look through all of the Knowledge, and found no page it could use.',
|
|
1129
|
+
'project-replaced': () => 'The project was replaced by another project with the same name, so no pages were given.',
|
|
1130
|
+
unreadable: () => 'FloLess couldn’t read the Knowledge.',
|
|
1131
|
+
};
|
|
1132
|
+
const SHORTENED_TIP = 'Only part of this page was given: the part that matched the search, cut to fit.';
|
|
1133
|
+
|
|
1134
|
+
/** S7: the Knowledge a step was given in this run, as words (cited pages first), or null for a step that reads none. */
|
|
1135
|
+
function runKbView(kb) {
|
|
1136
|
+
if (!isRecord(kb) || (kb.status !== 'supplied' && kb.status !== 'none') || !Array.isArray(kb.pages)) return null;
|
|
1137
|
+
const pages = kb.pages.filter((page) => isRecord(page) && typeof page.title === 'string')
|
|
1138
|
+
.map((page) => ({ title: page.title, cited: page.cited === true, shortened: page.shortened === true }));
|
|
1139
|
+
const ordered = [...pages.filter((page) => page.cited), ...pages.filter((page) => !page.cited)];
|
|
1140
|
+
const none = kb.status !== 'supplied' || !ordered.length;
|
|
1141
|
+
const reason = none ? (KB_NONE_WORDS[kb.reason] || KB_NONE_WORDS.unreadable)(typeof kb.query === 'string' ? kb.query : '') : null;
|
|
1142
|
+
const day = typeof kb.publishedAt === 'string' && /^\d{4}-\d{2}-\d{2}/.test(kb.publishedAt) ? kb.publishedAt.slice(0, 10) : null;
|
|
1143
|
+
const notes = none ? [] : [
|
|
1144
|
+
...(kb.incomplete === true ? ['FloLess couldn’t look through all of the Knowledge, so a page that matters may be missing.'] : []),
|
|
1145
|
+
...(kb.moreMatches === true ? ['More pages matched than this step reads.'] : []),
|
|
1146
|
+
];
|
|
1147
|
+
return { pages: none ? [] : ordered, reason, published: none ? null : day, notes };
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
function runKbHtml(nodeId, kb) {
|
|
1151
|
+
if (!kb) return '';
|
|
1152
|
+
const id = `as-kb-${esc(nodeId)}`;
|
|
1153
|
+
const head = `<div class="as-use-title" id="${id}">Knowledge it was given</div>`;
|
|
1154
|
+
if (kb.reason) return `<div class="as-run-kb" role="group" aria-labelledby="${id}">${head}<p class="as-use-note">${esc(kb.reason)}</p></div>`;
|
|
1155
|
+
const items = kb.pages.map((page) => (page.cited
|
|
1156
|
+
? `<li><span aria-hidden="true">✓</span> <b>${esc(page.title)}</b> <span class="ai-pill is-uses">cited</span>`
|
|
1157
|
+
: `<li>${esc(page.title)}`)
|
|
1158
|
+
+ `${page.shortened ? ` <span class="as-use-note" data-tip="${esc(SHORTENED_TIP)}">shortened to fit</span>` : ''}</li>`).join('');
|
|
1159
|
+
return `<div class="as-run-kb" role="group" aria-labelledby="${id}">${head}<ul class="as-use-list">${items}</ul>`
|
|
1160
|
+
+ `${kb.published ? `<p class="as-use-note">Knowledge as published on ${esc(kb.published)}.</p>` : ''}`
|
|
1161
|
+
+ kb.notes.map((note) => `<p class="as-use-note">${esc(note)}</p>`).join('') + '</div>';
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
const NOT_LISTED = {
|
|
1165
|
+
'no-snapshot': 'This run started before FloLess recorded which steps use the answer.',
|
|
1166
|
+
'changed-since-compile': 'The workflow had changed since it was approved when this run started.',
|
|
1167
|
+
unreadable: 'FloLess couldn’t read the workflow, so it can’t say which steps use the answer.',
|
|
1168
|
+
'duplicate-ids': 'Two steps share a name, so FloLess couldn’t tell which steps use the answer.',
|
|
1169
|
+
};
|
|
1170
|
+
const TRACE_NOTE = 'Other steps may use the answer in ways FloLess can’t trace.';
|
|
1171
|
+
|
|
1172
|
+
/** #2374: the parts of this run FloLess found using the answer (from the run's own record), or why they are not listed. */
|
|
1173
|
+
function usesView(rec) {
|
|
1174
|
+
if (Array.isArray(rec.dependents)) {
|
|
1175
|
+
const rows = rec.dependents.filter((row) => isRecord(row) && typeof row.nodeId === 'string' && (row.how === 'uses' || row.how === 'decided'));
|
|
1176
|
+
return {
|
|
1177
|
+
listed: true,
|
|
1178
|
+
ran: rows.filter((row) => row.ran === true).map((row) => ({ nodeId: row.nodeId, how: row.how })),
|
|
1179
|
+
notRun: rows.filter((row) => row.ran !== true).map((row) => row.nodeId),
|
|
1180
|
+
note: TRACE_NOTE,
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
if (typeof rec.dependentsUnknown === 'string') return { listed: false, reason: NOT_LISTED[rec.dependentsUnknown] || NOT_LISTED['no-snapshot'] };
|
|
1184
|
+
return null;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function usesHtml(uses) {
|
|
1188
|
+
if (!uses) return '';
|
|
1189
|
+
const head = '<div class="as-use-title" id="as-use-title">Parts FloLess found using the answer</div>';
|
|
1190
|
+
if (!uses.listed) return `<div class="as-use" role="group" aria-labelledby="as-use-title">${head}<p class="as-use-note">Not listed for this run. ${esc(uses.reason)}</p></div>`;
|
|
1191
|
+
const words = { uses: 'uses it', decided: 'decided by it' };
|
|
1192
|
+
const list = uses.ran.length
|
|
1193
|
+
? `<ul class="as-use-list">${uses.ran.map((row) => `<li><b>${esc(row.nodeId)}</b> <span class="ai-pill is-uses">${words[row.how]}</span></li>`).join('')}</ul>`
|
|
1194
|
+
: '<p class="as-use-note">None of them ran in this run.</p>';
|
|
1195
|
+
const notRun = uses.notRun.length ? `<p class="as-use-skipped">Not run this time: ${esc(uses.notRun.join(', '))}</p>` : '';
|
|
1196
|
+
if (!uses.ran.length && !uses.notRun.length) {
|
|
1197
|
+
return `<div class="as-use" role="group" aria-labelledby="as-use-title">${head}<p class="as-use-note">No step using the answer was found. ${esc(uses.note)}</p></div>`;
|
|
1198
|
+
}
|
|
1199
|
+
return `<div class="as-use" role="group" aria-labelledby="as-use-title">${head}${list}${notRun}<p class="as-use-note">${esc(uses.note)}</p></div>`;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
const runs = new Map(); // appId -> the last run's record (kept only when it had an AI step)
|
|
1203
|
+
const runGeneration = new Map();
|
|
1204
|
+
|
|
1205
|
+
function paintRunRecord() {
|
|
1206
|
+
const box = document.getElementById('as-run');
|
|
1207
|
+
if (!box) return;
|
|
1208
|
+
const app = model.context.currentApp();
|
|
1209
|
+
const view = app && enabled() ? runRecordView(runs.get(app.id)) : null;
|
|
1210
|
+
if (!view) { box.hidden = true; return; }
|
|
1211
|
+
// Open when the run left something for the person; otherwise whatever the person last chose for this workflow.
|
|
1212
|
+
const open = view.open || (box.dataset.for === app.id && box.open);
|
|
1213
|
+
box.dataset.for = app.id;
|
|
1214
|
+
document.getElementById('as-run-sum').innerHTML = `${aiPillHtml()}<span class="as-run-sum-text">${esc(view.summary)}</span>`;
|
|
1215
|
+
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>`
|
|
1216
|
+
+ `${step.who ? `<div class="as-run-who">${esc(step.who)}</div>` : ''}`
|
|
1217
|
+
+ runKbHtml(step.nodeId, step.knowledge)
|
|
1218
|
+
+ `<div class="as-run-links">${step.conversationId && step.stepRunId && step.agentId ? `<button type="button" class="as-btn as-link" data-as-run-convo="${esc(step.nodeId)}" aria-label="Open its conversation, step ${esc(step.nodeId)}" data-command-id="shell.agent-run-open-conversation">Open its conversation ▸</button>` : ''}`
|
|
1219
|
+
+ `${step.agentId ? `<button type="button" class="as-btn as-link" data-as-run-agent="${esc(step.agentId)}" aria-label="Open the Agent’s runs, step ${esc(step.nodeId)}" data-command-id="shell.agent-run-open-agent">Open the Agent’s runs ▸</button>` : ''}</div></div>`).join('');
|
|
1220
|
+
const needsHtml = view.groups.length
|
|
1221
|
+
? `<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>`
|
|
1222
|
+
: '';
|
|
1223
|
+
const note = noteOffLine(model.notes.get(app.id));
|
|
1224
|
+
document.getElementById('as-run-body').innerHTML = stepHtml + usesHtml(view.uses) + (note ? `<p class="as-use-note">${esc(note)}</p>` : '') + needsHtml;
|
|
1225
|
+
box.hidden = false;
|
|
1226
|
+
box.open = open;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/** 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. */
|
|
1230
|
+
async function refreshRunRecord(appId) {
|
|
1231
|
+
if (!appId) return;
|
|
1232
|
+
const mine = (runGeneration.get(appId) || 0) + 1;
|
|
1233
|
+
runGeneration.set(appId, mine);
|
|
1234
|
+
paintRunRecord(); // the panel always shows the OPEN workflow's own record (or none) at once, never the previous workflow's
|
|
1235
|
+
const on = await probe();
|
|
1236
|
+
if (runGeneration.get(appId) !== mine) return;
|
|
1237
|
+
if (!on) { runs.delete(appId); paintRunRecord(); return; }
|
|
1238
|
+
let body = null;
|
|
1239
|
+
try {
|
|
1240
|
+
const path = `/api/latest-run/${encodeURIComponent(appId)}`;
|
|
1241
|
+
await globalThis.flolessStartupAdmission?.admit(path);
|
|
1242
|
+
if (runGeneration.get(appId) !== mine) return;
|
|
1243
|
+
const response = await fetch(path, { credentials: 'same-origin' });
|
|
1244
|
+
body = response.ok ? await response.json() : null;
|
|
1245
|
+
} catch { body = null; }
|
|
1246
|
+
if (runGeneration.get(appId) !== mine || !body || body.ok !== true) return;
|
|
1247
|
+
if (Array.isArray(body.aiSteps) && body.aiSteps.length) {
|
|
1248
|
+
runs.set(appId, {
|
|
1249
|
+
runId: body.runId, aiSteps: body.aiSteps, needsYou: Array.isArray(body.needsYou) ? body.needsYou : [],
|
|
1250
|
+
...(Array.isArray(body.dependents) ? { dependents: body.dependents } : {}),
|
|
1251
|
+
...(typeof body.dependentsUnknown === 'string' ? { dependentsUnknown: body.dependentsUnknown } : {}),
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
else runs.delete(appId);
|
|
1255
|
+
paintRunRecord();
|
|
1256
|
+
model.context.runRecordChanged(appId); // the trace's labels read this record, so they repaint with it
|
|
1257
|
+
void checkGates();
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/** “a”, “a” and “b”, “a”, “b” and “c”, or “a”, “b”, “c” and 2 more. */
|
|
1261
|
+
function quotedList(names) {
|
|
1262
|
+
const q = names.map((name) => `“${name}”`);
|
|
1263
|
+
if (q.length <= 1) return q.join('');
|
|
1264
|
+
if (q.length <= 3) return `${q.slice(0, -1).join(', ')} and ${q[q.length - 1]}`;
|
|
1265
|
+
return `${q.slice(0, 3).join(', ')} and ${q.length - 3} more`;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* #2415: what to say when a run made no report and an AI step in it did not answer (its `-ok` check stops the run, by design).
|
|
1270
|
+
* Pure: the run's own answer in (`aiSteps`, `needsYou`, `dependents`), plain words out; null when no AI step failed to answer, so the caller
|
|
1271
|
+
* keeps its own words. It says the step STOPPED the report only when the run record shows the report is built on that step's answer and
|
|
1272
|
+
* did not run; otherwise it says only that the step did not answer and no report was made.
|
|
1273
|
+
*/
|
|
1274
|
+
function stoppedReportView(res, reportNodeId) {
|
|
1275
|
+
if (!isRecord(res) || !Array.isArray(res.aiSteps)) return null;
|
|
1276
|
+
const stopped = [...new Set(res.aiSteps.filter((step) => isRecord(step) && step.ok === false && typeof step.nodeId === 'string').map((step) => step.nodeId))];
|
|
1277
|
+
if (!stopped.length) return null;
|
|
1278
|
+
const needs = Array.isArray(res.needsYou) ? res.needsYou.filter(isRecord) : [];
|
|
1279
|
+
const asks = stopped.filter((id) => needs.some((item) => item.nodeId === id && item.kind === 'question'));
|
|
1280
|
+
const silent = stopped.filter((id) => !asks.includes(id));
|
|
1281
|
+
const row = Array.isArray(res.dependents) ? res.dependents.find((r) => isRecord(r) && r.nodeId === reportNodeId) : null;
|
|
1282
|
+
const causal = !!row && row.ran !== true && Array.isArray(row.steps) && row.steps.some((id) => stopped.includes(id));
|
|
1283
|
+
// Questions for you lists something only when the record left an item for a stopped step; otherwise the way on is Last run itself.
|
|
1284
|
+
const listed = needs.some((item) => stopped.includes(item.nodeId));
|
|
1285
|
+
const named = (ids) => `the AI ${ids.length === 1 ? 'step' : 'steps'} ${quotedList(ids)}`;
|
|
1286
|
+
const parts = [];
|
|
1287
|
+
if (asks.length) parts.push(`${named(asks)} ${asks.length === 1 ? 'has' : 'have'} questions for you`);
|
|
1288
|
+
if (silent.length) parts.push(`${named(silent)} did not give an answer the workflow could use`);
|
|
1289
|
+
const what = parts.join(', and ');
|
|
1290
|
+
const why = causal ? ', so the run stopped before the report.' : ', and the run made no report.';
|
|
1291
|
+
const whose = stopped.length === 1 ? 'the step’s' : 'the steps’';
|
|
1292
|
+
const where = listed ? 'Questions for you' : 'Last run above the canvas';
|
|
1293
|
+
const next = asks.length
|
|
1294
|
+
? ` Read them in ${where}, then adjust the inputs or ${whose} instructions and run it again.`
|
|
1295
|
+
: ` Open ${where} to see what happened, then adjust ${whose} instructions or inputs and run it again.`;
|
|
1296
|
+
return {
|
|
1297
|
+
status: 'Needs you', headline: causal ? 'The run stopped before the report' : 'No report was made',
|
|
1298
|
+
sub: causal ? 'The run stopped before the report.' : 'The run ended without a report.',
|
|
1299
|
+
body: what.charAt(0).toUpperCase() + what.slice(1) + why + next, steps: stopped, causal, listed,
|
|
1300
|
+
runId: typeof res.runId === 'string' ? res.runId : null,
|
|
1301
|
+
button: listed ? 'Open Questions for you' : 'Open Last run',
|
|
1302
|
+
commandId: listed ? 'shell.report-ai-stop-questions' : 'shell.report-ai-stop-last-run',
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* #2415: open the canvas's Last run panel on its Questions for you and move focus there. The record is read again unless the panel
|
|
1308
|
+
* already holds this very run (`runId`), so it never shows an earlier run's questions. False when it cannot show this run, so the
|
|
1309
|
+
* caller keeps the viewer open and says so. `beforeFocus` runs once the panel is shown and before focus moves, so the caller can close
|
|
1310
|
+
* a modal first: focus that lands while a modal is still up is not announced as the new place.
|
|
1311
|
+
*/
|
|
1312
|
+
async function openQuestions(appId, runId, beforeFocus) {
|
|
1313
|
+
if (!appId) return false;
|
|
1314
|
+
const current = () => (runId ? runs.get(appId)?.runId === runId : runs.has(appId));
|
|
1315
|
+
if (!current()) await refreshRunRecord(appId);
|
|
1316
|
+
const box = document.getElementById('as-run');
|
|
1317
|
+
if (!current() || !box || box.hidden || box.dataset.for !== appId) return false;
|
|
1318
|
+
box.open = true;
|
|
1319
|
+
box.scrollIntoView?.({ block: 'nearest' });
|
|
1320
|
+
// The panel scrolls inside itself, and the questions come after the steps: bring them into view, not just the panel's top.
|
|
1321
|
+
box.querySelector?.('.as-needs')?.scrollIntoView?.({ block: 'nearest' });
|
|
1322
|
+
beforeFocus?.();
|
|
1323
|
+
document.getElementById('as-run-sum')?.focus?.({ preventScroll: true });
|
|
1324
|
+
return true;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// ── #2448: the AI note in reports, which the person may turn off (per workflow, and for all workflows) ───────────
|
|
1328
|
+
|
|
1329
|
+
const NOTE_HINT = 'Adds a note to this workflow’s reports saying part of the report was written by an AI. A change applies to reports made from now on.';
|
|
1330
|
+
const NOTE_GLOBAL_OFF = 'Off for all reports in the ≡ menu (AI note in reports). This switch counts again once that is back on.';
|
|
1331
|
+
|
|
1332
|
+
/** Pure: what the Inspect switch shows for a workflow's note state (`{ enabled, global }`), or null when it is not known yet. */
|
|
1333
|
+
function noteView(state) {
|
|
1334
|
+
if (!isRecord(state) || typeof state.enabled !== 'boolean') return null;
|
|
1335
|
+
const globalOff = state.global === false;
|
|
1336
|
+
return { checked: state.enabled, hint: globalOff ? NOTE_GLOBAL_OFF : NOTE_HINT, globalOff };
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
function noteHtml(state) {
|
|
1340
|
+
const view = noteView(state);
|
|
1341
|
+
if (!view) return '';
|
|
1342
|
+
return '<h3>Its reports</h3><div class="as-note-row"><span>AI note in this workflow’s reports</span>'
|
|
1343
|
+
+ '<label class="rtn-toggle">'
|
|
1344
|
+
+ `<input type="checkbox" role="switch" data-as-report-note aria-label="AI note in this workflow’s reports" aria-describedby="as-note-hint" data-command-id="shell.agent-report-note"${view.checked ? ' checked' : ''}>`
|
|
1345
|
+
+ '<span class="rtn-toggle-track"></span></label></div>'
|
|
1346
|
+
+ `<p class="as-note-hint${view.globalOff ? ' is-global-off' : ''}" id="as-note-hint">${esc(view.hint)}</p>`;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* Pure: the Last run panel's line when reports made NOW leave the note out, or '' when they carry it (or it is not known). It names the
|
|
1351
|
+
* current setting, never the run the panel shows: that run's report was made under whatever the setting was then.
|
|
1352
|
+
*/
|
|
1353
|
+
function noteOffLine(state) {
|
|
1354
|
+
if (!isRecord(state) || state.shown !== false) return '';
|
|
1355
|
+
return state.off === 'global'
|
|
1356
|
+
? 'Reports made now leave out the AI note: it is turned off for all reports.'
|
|
1357
|
+
: 'This workflow’s reports made now leave out the AI note: it is turned off for this workflow.';
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* #2461: one workflow's AI-note reads and saves, kept in order. The server's answers are the truth, with two rules on top:
|
|
1362
|
+
* - While saves are out, Inspect shows the person's latest choice. Saves run one at a time in the order they were made;
|
|
1363
|
+
* each answer only updates what the server is known to hold, and only the newest one is shown, announced or reverted.
|
|
1364
|
+
* - A read stores its answer only if it is the newest read and no save started or answered since it began. A read that
|
|
1365
|
+
* a save overtook is made again once no save is out, so a change made elsewhere (the ≡ switch) is never lost.
|
|
1366
|
+
*/
|
|
1367
|
+
function noteSyncOf(appId) {
|
|
1368
|
+
let sync = model.noteSync.get(appId);
|
|
1369
|
+
if (!sync) {
|
|
1370
|
+
sync = { reads: 0, saves: 0, epoch: 0, latest: 0, queue: Promise.resolve(), confirmed: undefined, reread: false };
|
|
1371
|
+
model.noteSync.set(appId, sync);
|
|
1372
|
+
}
|
|
1373
|
+
return sync;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
function noteOf(body) {
|
|
1377
|
+
return { enabled: body.enabled === true, global: body.global !== false, shown: body.shown !== false, off: body.off || null };
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/** The note as it will be once the person's choice is saved: the switch, and what reports will then do. */
|
|
1381
|
+
function noteWithChoice(note, enabled) {
|
|
1382
|
+
if (!note) return note;
|
|
1383
|
+
return { ...note, enabled, shown: enabled && note.global, off: !note.global ? 'global' : enabled ? null : 'workflow' };
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
function repaintNote(appId) {
|
|
1387
|
+
if (model.context.currentApp()?.id === appId) { model.context.repaint(appId); paintRunRecord(); }
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
async function refreshNote(appId) {
|
|
1391
|
+
if (!appId) return;
|
|
1392
|
+
const sync = noteSyncOf(appId);
|
|
1393
|
+
const read = ++sync.reads;
|
|
1394
|
+
const epoch = sync.epoch;
|
|
1395
|
+
let note = null;
|
|
1396
|
+
try {
|
|
1397
|
+
const path = `/api/app/${encodeURIComponent(appId)}/report-ai-label`;
|
|
1398
|
+
// A selected-workflow read like the checks: it waits for the server's startup recovery before it goes out.
|
|
1399
|
+
await globalThis.flolessStartupAdmission?.admit(path);
|
|
1400
|
+
const response = await fetch(path, { credentials: 'same-origin' });
|
|
1401
|
+
const body = response.ok ? await response.json() : null;
|
|
1402
|
+
if (body && body.ok === true) note = noteOf(body); // otherwise not known: the switch stays as it is rather than guess
|
|
1403
|
+
} catch { note = null; }
|
|
1404
|
+
if (read !== sync.reads) return; // a newer read decides
|
|
1405
|
+
if (sync.saves > 0 || sync.epoch !== epoch) {
|
|
1406
|
+
// A save overtook this read (answered or not), so what it saw may be older than the save: read again once no save is out.
|
|
1407
|
+
sync.reread = true;
|
|
1408
|
+
if (sync.saves === 0) { sync.reread = false; void refreshNote(appId); }
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
if (!note) return;
|
|
1412
|
+
sync.confirmed = note;
|
|
1413
|
+
model.notes.set(appId, note);
|
|
1414
|
+
repaintNote(appId);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/** The person's choice for one workflow: shown at once, saved in order after any save still out. */
|
|
1418
|
+
function setNote(appId, enabled) {
|
|
1419
|
+
const sync = noteSyncOf(appId);
|
|
1420
|
+
if (sync.saves === 0) sync.confirmed = model.notes.get(appId);
|
|
1421
|
+
const mine = ++sync.latest;
|
|
1422
|
+
sync.saves += 1;
|
|
1423
|
+
sync.epoch += 1;
|
|
1424
|
+
const shown = noteWithChoice(model.notes.get(appId), enabled);
|
|
1425
|
+
if (shown) { model.notes.set(appId, shown); repaintNote(appId); }
|
|
1426
|
+
const run = sync.queue.then(() => saveNote(appId, enabled, sync, () => sync.latest === mine)).finally(() => {
|
|
1427
|
+
sync.saves -= 1;
|
|
1428
|
+
sync.epoch += 1;
|
|
1429
|
+
if (sync.saves === 0 && sync.reread) { sync.reread = false; void refreshNote(appId); }
|
|
1430
|
+
});
|
|
1431
|
+
sync.queue = run.catch(() => undefined);
|
|
1432
|
+
return run;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
async function saveNote(appId, enabled, sync, newest) {
|
|
1436
|
+
try {
|
|
1437
|
+
const response = await fetch(`/api/app/${encodeURIComponent(appId)}/report-ai-label`, {
|
|
1438
|
+
method: 'PUT', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ enabled }),
|
|
1439
|
+
});
|
|
1440
|
+
const body = response.ok ? await response.json() : null;
|
|
1441
|
+
if (!body || body.ok !== true) throw new Error('not saved');
|
|
1442
|
+
sync.confirmed = noteOf(body); // saves answer in order, so this is what the server holds now
|
|
1443
|
+
if (!newest()) return; // a newer choice is queued: it is what Inspect keeps showing, and what is announced
|
|
1444
|
+
model.notes.set(appId, sync.confirmed);
|
|
1445
|
+
model.context.toast(enabled ? 'This workflow’s next report will include the AI note.' : 'This workflow’s next report will leave out the AI note.', 'ok');
|
|
1446
|
+
} catch {
|
|
1447
|
+
if (!newest()) return; // the newer choice decides what is shown and said
|
|
1448
|
+
if (sync.confirmed) model.notes.set(appId, sync.confirmed); // back to what the server is known to hold
|
|
1449
|
+
model.context.toast('FloLess couldn’t save the AI note setting. Try again.', 'warn');
|
|
1450
|
+
}
|
|
1451
|
+
repaintNote(appId);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/** The ≡ menu row: shown once the feature is known to be on, set from the server, and saved on change. */
|
|
1455
|
+
async function initGlobalNote() {
|
|
1456
|
+
const row = document.getElementById('menu-ai-note');
|
|
1457
|
+
const toggle = document.getElementById('menu-ai-note-toggle');
|
|
1458
|
+
if (!row || !toggle) return;
|
|
1459
|
+
try {
|
|
1460
|
+
// Read once the server's startup recovery is done, like every protected read the page makes while opening.
|
|
1461
|
+
await globalThis.flolessStartupAdmission?.admit('/api/report-ai-label');
|
|
1462
|
+
const response = await fetch('/api/report-ai-label', { credentials: 'same-origin' });
|
|
1463
|
+
const body = response.ok ? await response.json() : null;
|
|
1464
|
+
if (!body || body.ok !== true) return; // unknown: the row stays hidden, never a switch in the wrong position
|
|
1465
|
+
toggle.checked = body.enabled !== false;
|
|
1466
|
+
row.hidden = !enabled();
|
|
1467
|
+
} catch { return; }
|
|
1468
|
+
if (toggle.dataset.wired) return;
|
|
1469
|
+
toggle.dataset.wired = '1';
|
|
1470
|
+
toggle.addEventListener('change', async () => {
|
|
1471
|
+
const want = toggle.checked;
|
|
1472
|
+
toggle.disabled = true;
|
|
1473
|
+
try {
|
|
1474
|
+
const response = await fetch('/api/report-ai-label', {
|
|
1475
|
+
method: 'PUT', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ enabled: want }),
|
|
1476
|
+
});
|
|
1477
|
+
const body = response.ok ? await response.json() : null;
|
|
1478
|
+
if (!body || body.ok !== true) throw new Error('not saved');
|
|
1479
|
+
toggle.checked = body.enabled !== false;
|
|
1480
|
+
model.context.toast(want ? 'Reports made from now on include the AI note again.' : 'Reports made from now on leave out the AI note, for every workflow.', 'ok');
|
|
1481
|
+
} catch {
|
|
1482
|
+
toggle.checked = !want;
|
|
1483
|
+
model.context.toast('FloLess couldn’t save the AI note setting. Try again.', 'warn');
|
|
1484
|
+
} finally { toggle.disabled = false; }
|
|
1485
|
+
const app = model.context.currentApp();
|
|
1486
|
+
if (app) void refreshNote(app.id); // the workflow's own switch says what this one now means for it
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
document.addEventListener('change', (event) => {
|
|
1491
|
+
const input = event.target instanceof Element ? event.target.closest('[data-as-report-note]') : null;
|
|
1492
|
+
if (!input) return;
|
|
1493
|
+
const app = model.context.currentApp();
|
|
1494
|
+
if (app) void setNote(app.id, input.checked === true);
|
|
1495
|
+
});
|
|
1496
|
+
|
|
1497
|
+
const CONVO_FAILED = 'FloLess couldn’t open this step’s conversation. Open the Agent’s runs to check this run.';
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
* #2375: open the conversation an Agent step ran in. Its owner (the Agent's first pinned place, not this workflow) lives on the Agent's
|
|
1501
|
+
* run, so the run is looked up first; the conversation is opened only when that run names this exact conversation.
|
|
1502
|
+
*/
|
|
1503
|
+
async function openStepConversation(step) {
|
|
1504
|
+
try {
|
|
1505
|
+
const response = await fetch(`/api/chat/agents/${encodeURIComponent(step.agentId)}/runs`, { credentials: 'same-origin' });
|
|
1506
|
+
const body = response.ok ? await response.json() : null;
|
|
1507
|
+
const list = Array.isArray(body) ? body : body && Array.isArray(body.runs) ? body.runs : [];
|
|
1508
|
+
const run = list.find((row) => isRecord(row) && row.runId === step.stepRunId);
|
|
1509
|
+
const target = run && Array.isArray(run.targets)
|
|
1510
|
+
? run.targets.find((t) => isRecord(t) && isRecord(t.owner) && t.chatId === step.conversationId) : null;
|
|
1511
|
+
if (!target) { model.context.toast(CONVO_FAILED, 'warn'); return false; }
|
|
1512
|
+
const label = `Agent “${step.agentName || 'Agent'}” · step “${step.nodeId}”`;
|
|
1513
|
+
if (document.getElementById('app')?.classList.contains('left-collapsed')) {
|
|
1514
|
+
document.querySelector('.pane-rail-left .panel-toggle[data-side="left"]')?.click();
|
|
1515
|
+
}
|
|
1516
|
+
const opened = await window.flolessChat?.openConversationIn?.({ owner: target.owner, label }, target.chatId);
|
|
1517
|
+
if (opened !== true) { model.context.toast(CONVO_FAILED, 'warn'); return false; }
|
|
1518
|
+
return true;
|
|
1519
|
+
} catch {
|
|
1520
|
+
model.context.toast(CONVO_FAILED, 'warn');
|
|
1521
|
+
return false;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
// ── the held change ("Waiting for your approval") ──────────────────────────────────────────────────────────
|
|
1526
|
+
|
|
1527
|
+
const GATE_API = '/api/chat/agent-steps/gates';
|
|
1528
|
+
const gateModel = { shown: null, timer: null, deciding: false, delay: 2000, checking: null };
|
|
1529
|
+
|
|
1530
|
+
/** Pure: how the card words a pending gate. `now` is a Date, `gate.expiresAt` an ISO time. */
|
|
1531
|
+
function gateView(gate, now = new Date()) {
|
|
1532
|
+
const until = new Date(gate.expiresAt);
|
|
1533
|
+
const clock = Number.isFinite(until.getTime()) ? until.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : '';
|
|
1534
|
+
let values = '';
|
|
1535
|
+
try { values = typeof gate.values === 'string' ? gate.values : (JSON.stringify(gate.values, null, 2) ?? ''); } catch { values = ''; }
|
|
1536
|
+
return {
|
|
1537
|
+
gateId: String(gate.gateId),
|
|
1538
|
+
title: 'Waiting for your approval',
|
|
1539
|
+
summary: String(gate.summary || 'A change is waiting for you.'),
|
|
1540
|
+
values,
|
|
1541
|
+
time: clock ? `This step stops at ${clock}. If nobody decides, the change is not made.` : 'If nobody decides, the change is not made.',
|
|
1542
|
+
expired: Number.isFinite(until.getTime()) && now.getTime() >= until.getTime(),
|
|
1543
|
+
// S8: a watcher's confirmation (it carries its fire) holds up that watcher's next events, never the run queue.
|
|
1544
|
+
queue: Number.isInteger(gate.fire) ? 'The watcher waits for your decision; its next events wait behind it.' : 'This run holds the queue; other runs wait.',
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
function paintGate(gate) {
|
|
1549
|
+
const card = document.getElementById('as-gate');
|
|
1550
|
+
if (!card) return;
|
|
1551
|
+
if (!gate) { card.hidden = true; gateModel.shown = null; return; }
|
|
1552
|
+
const view = gateView(gate);
|
|
1553
|
+
const same = gateModel.shown === view.gateId;
|
|
1554
|
+
document.getElementById('as-gate-values').textContent = view.values;
|
|
1555
|
+
document.getElementById('as-gate-label').hidden = !view.values;
|
|
1556
|
+
document.getElementById('as-gate-values').hidden = !view.values;
|
|
1557
|
+
document.getElementById('as-gate-time').textContent = view.time;
|
|
1558
|
+
const queue = document.getElementById('as-gate-queue');
|
|
1559
|
+
if (queue) queue.textContent = view.queue;
|
|
1560
|
+
// The announcement is set once when the card appears, never again on a re-poll (no repeated interruptions).
|
|
1561
|
+
if (!same) document.getElementById('as-gate-live').innerHTML = `<b>${esc(view.title)}.</b> ${esc(view.summary)}`;
|
|
1562
|
+
if (!same) document.getElementById('as-gate-error').hidden = true;
|
|
1563
|
+
gateModel.shown = view.gateId;
|
|
1564
|
+
card.dataset.gate = view.gateId;
|
|
1565
|
+
card.hidden = false;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* #2421: the gates route answers 404 while the server has Agent steps off. The page learnt "on" once and kept it, so a server that
|
|
1570
|
+
* was restarted with the feature off (or an older AWARE) drew a 404 on every look. Ask the same switch the page started from; when it
|
|
1571
|
+
* now says off, stop looking (the watch ends at its next tick) and take down anything the feature showed. Anything else is not an
|
|
1572
|
+
* answer, and the next look asks again.
|
|
1573
|
+
*/
|
|
1574
|
+
async function recheckSwitch(signal) {
|
|
1575
|
+
try {
|
|
1576
|
+
const response = await fetch('/api/agent-steps/status', { credentials: 'same-origin', signal });
|
|
1577
|
+
const body = response.ok ? await response.json() : null;
|
|
1578
|
+
if (!(isRecord(body) && body.enabled === false) || body.pending === true) return;
|
|
1579
|
+
} catch { return; }
|
|
1580
|
+
model.enabled = false;
|
|
1581
|
+
paintGate(null);
|
|
1582
|
+
const row = document.getElementById('menu-ai-note');
|
|
1583
|
+
if (row) row.hidden = true;
|
|
1584
|
+
paintRunRecord();
|
|
1585
|
+
model.context.repaint();
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
function checkGates() {
|
|
1589
|
+
if (!enabled()) return Promise.resolve();
|
|
1590
|
+
if (gateModel.checking) return gateModel.checking;
|
|
1591
|
+
gateModel.checking = Promise.resolve().then(async () => {
|
|
1592
|
+
let deadline;
|
|
1593
|
+
let gates = null;
|
|
1594
|
+
try {
|
|
1595
|
+
await globalThis.flolessStartupAdmission?.admit(GATE_API);
|
|
1596
|
+
const controller = new AbortController();
|
|
1597
|
+
deadline = setTimeout(() => controller.abort(), 30000);
|
|
1598
|
+
// This watcher can start before Chat: establish its person cookie and wait for project recovery first.
|
|
1599
|
+
const session = await fetch('/api/chat/session', { credentials: 'same-origin', signal: controller.signal });
|
|
1600
|
+
if (!session.ok || (await session.json())?.ready !== true) return;
|
|
1601
|
+
const response = await fetch(GATE_API, { credentials: 'same-origin', signal: controller.signal });
|
|
1602
|
+
// Still under the look's deadline: a status read that never answers cannot hold the watch.
|
|
1603
|
+
if (response.status === 404) { await recheckSwitch(controller.signal); return; }
|
|
1604
|
+
const body = response.ok ? await response.json() : null;
|
|
1605
|
+
if (body && body.ok === true && Array.isArray(body.gates)) gates = body.gates;
|
|
1606
|
+
} catch { gates = null; }
|
|
1607
|
+
finally { clearTimeout(deadline); }
|
|
1608
|
+
if (!gates) return; // a failed look says nothing: the card that was up stays, nothing new is invented
|
|
1609
|
+
const next = gates[0] || null;
|
|
1610
|
+
if (!next && gateModel.shown && !gateModel.deciding) {
|
|
1611
|
+
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');
|
|
1612
|
+
}
|
|
1613
|
+
paintGate(next);
|
|
1614
|
+
}).finally(() => { gateModel.checking = null; });
|
|
1615
|
+
return gateModel.checking;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* 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
|
|
1620
|
+
* 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
|
|
1621
|
+
* 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,
|
|
1622
|
+
* backing off to every ten seconds while nothing is.
|
|
1623
|
+
*/
|
|
1624
|
+
const GATE_FAST_MS = 2000;
|
|
1625
|
+
const GATE_SLOW_MS = 10000;
|
|
1626
|
+
function startGateWatch() {
|
|
1627
|
+
if (gateModel.timer || !enabled()) return;
|
|
1628
|
+
gateModel.delay = GATE_FAST_MS;
|
|
1629
|
+
const tick = async () => {
|
|
1630
|
+
gateModel.timer = null;
|
|
1631
|
+
if (!enabled()) return;
|
|
1632
|
+
await checkGates();
|
|
1633
|
+
gateModel.delay = gateModel.shown ? GATE_FAST_MS : Math.min(GATE_SLOW_MS, gateModel.delay * 2);
|
|
1634
|
+
gateModel.timer = setTimeout(tick, gateModel.delay);
|
|
1635
|
+
};
|
|
1636
|
+
gateModel.timer = setTimeout(tick, gateModel.delay);
|
|
1637
|
+
void checkGates();
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
/** Trace events of the open run: a confirmation step starting is a cue to look at once, rather than wait for the next look. */
|
|
1641
|
+
function noteTrace(ev) {
|
|
1642
|
+
if (!isRecord(ev) || !enabled()) return;
|
|
1643
|
+
if (ev.kind === 'node-start' && ev.agent === STEP_AGENT && ev.command === 'confirm') { gateModel.delay = GATE_FAST_MS; void checkGates(); }
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
async function decideGate(decision) {
|
|
1647
|
+
const gateId = gateModel.shown;
|
|
1648
|
+
if (!gateId || gateModel.deciding) return;
|
|
1649
|
+
gateModel.deciding = true;
|
|
1650
|
+
const error = document.getElementById('as-gate-error');
|
|
1651
|
+
const buttons = ['as-gate-approve', 'as-gate-skip'].map((id) => document.getElementById(id));
|
|
1652
|
+
buttons.forEach((b) => { if (b) b.setAttribute('aria-disabled', 'true'); });
|
|
1653
|
+
try {
|
|
1654
|
+
const response = await fetch(`${GATE_API}/${encodeURIComponent(gateId)}/decision`, {
|
|
1655
|
+
method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ decision }),
|
|
1656
|
+
});
|
|
1657
|
+
const body = await response.json().catch(() => ({}));
|
|
1658
|
+
if (response.ok && body.ok) {
|
|
1659
|
+
paintGate(null);
|
|
1660
|
+
model.context.toast(decision === 'approved' ? 'Approved. The workflow is making the change.' : 'Skipped. The change was not made.', 'ok');
|
|
1661
|
+
} else {
|
|
1662
|
+
if (response.status === 409) {
|
|
1663
|
+
// Already decided (here or in another window), timed out, or the run ended: say what is known, and where to look.
|
|
1664
|
+
paintGate(null);
|
|
1665
|
+
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');
|
|
1666
|
+
} else {
|
|
1667
|
+
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.';
|
|
1668
|
+
error.hidden = false;
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
} catch {
|
|
1672
|
+
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.';
|
|
1673
|
+
error.hidden = false;
|
|
1674
|
+
}
|
|
1675
|
+
gateModel.deciding = false;
|
|
1676
|
+
buttons.forEach((b) => { if (b) b.removeAttribute('aria-disabled'); });
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
/** The words a scheduled run's row adds when it had an AI step: `{ ai, aiTip, questions, questionsTip }`, or null. */
|
|
1680
|
+
function routineAiParts(lastRun) {
|
|
1681
|
+
if (!isRecord(lastRun) || lastRun.aiAnswer !== true) return null;
|
|
1682
|
+
const q = Number.isSafeInteger(lastRun.questionsForYou) && lastRun.questionsForYou > 0 ? lastRun.questionsForYou : 0;
|
|
1683
|
+
return {
|
|
1684
|
+
ai: 'AI answer',
|
|
1685
|
+
aiTip: 'This run used an AI step. Its answer can differ each run.',
|
|
1686
|
+
questions: q ? plural(q, 'question for you', 'questions for you') : '',
|
|
1687
|
+
questionsTip: q ? 'The AI step left questions, assumptions or changes that were not made. Open the workflow to read them.' : '',
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
document.addEventListener('click', (event) => {
|
|
1692
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
1693
|
+
if (!target) return;
|
|
1694
|
+
const open = target.closest('[data-as-run-agent]');
|
|
1695
|
+
if (open) { model.context.openAgent(open.getAttribute('data-as-run-agent')); return; }
|
|
1696
|
+
const convo = target.closest('[data-as-run-convo]');
|
|
1697
|
+
if (convo) {
|
|
1698
|
+
const app = model.context.currentApp();
|
|
1699
|
+
const view = app ? runRecordView(runs.get(app.id)) : null;
|
|
1700
|
+
const step = view && view.steps.find((row) => row.nodeId === convo.getAttribute('data-as-run-convo'));
|
|
1701
|
+
if (step) void openStepConversation(step);
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
// S8: the wait between a watcher step's answers, changed from Inspect.
|
|
1705
|
+
const change = target.closest('[data-as-wait-change]');
|
|
1706
|
+
if (change) {
|
|
1707
|
+
const edit = document.querySelector(`[data-as-wait-edit="${CSS.escape(change.getAttribute('data-as-wait-change'))}"]`);
|
|
1708
|
+
if (edit) { edit.hidden = !edit.hidden; change.setAttribute('aria-expanded', String(!edit.hidden)); if (!edit.hidden) edit.querySelector('input')?.focus(); }
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1711
|
+
const limit = target.closest('[data-as-wait-on]');
|
|
1712
|
+
if (limit) { const field = limit.closest('[data-as-wait-edit]')?.querySelector('.ac-wait-field'); if (field) field.hidden = !limit.checked; return; }
|
|
1713
|
+
const cancel = target.closest('[data-as-wait-cancel]');
|
|
1714
|
+
if (cancel) { const app = model.context.currentApp(); model.repaintAfterEdit = null; if (app) model.context.repaint(app.id); return; }
|
|
1715
|
+
const save = target.closest('[data-as-wait-save]');
|
|
1716
|
+
if (save) {
|
|
1717
|
+
const app = model.context.currentApp();
|
|
1718
|
+
const nodeId = save.getAttribute('data-as-wait-save');
|
|
1719
|
+
const edit = save.closest('[data-as-wait-edit]');
|
|
1720
|
+
if (!app || !edit) return;
|
|
1721
|
+
const on = edit.querySelector('[data-as-wait-on]');
|
|
1722
|
+
const value = Number(edit.querySelector('[data-as-wait-input]')?.value);
|
|
1723
|
+
if (on && on.checked && !(Number.isInteger(value) && value >= 1 && value <= 1440)) {
|
|
1724
|
+
model.context.toast('Enter a whole number of minutes from 1 to 1440, or turn the limit off. Nothing was changed.', 'warn');
|
|
1725
|
+
return;
|
|
1726
|
+
}
|
|
1727
|
+
void saveWait(app.id, nodeId, on && !on.checked ? 0 : value);
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
if (target.closest('#as-gate-approve')) void decideGate('approved');
|
|
1731
|
+
else if (target.closest('#as-gate-skip')) void decideGate('skipped');
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
void probe(); // the feature probe starts the look for a waiting change as soon as it answers yes
|
|
1735
|
+
|
|
1736
|
+
window.flolessAgentSteps = {
|
|
1737
|
+
probe, enabled, isStepNode, entryParts, refreshChecks, checkFor, stepCount, headerText, markTip, draftAdd, draftUpdate, paintCanvasControl,
|
|
1738
|
+
BADGE_TIP, answerWords, bannerModel, stepFacts, consentView, consentStatus, consentDialog, confirmBeforeApprove, confirmBeforeRun, takeRenameAsk,
|
|
1739
|
+
aiPillHtml, runRecordView, refreshRunRecord, kbInspectHtml, runKbView, paintRunRecord, gateView, checkGates, noteTrace, routineAiParts,
|
|
1740
|
+
useParts, standingSentence, usePillHtml, usesView, openStepConversation, stoppedReportView, openQuestions,
|
|
1741
|
+
noteView, noteHtml, noteOffLine, refreshNote, setNote, initGlobalNote,
|
|
1742
|
+
triggerSentenceFor, triggerInspectHtml, watcherCardParts, refreshTrigger, saveWait, watcherChanged,
|
|
1743
|
+
configure(context) { Object.assign(model.context, context); },
|
|
1744
|
+
forgetChecks(appId) {
|
|
1745
|
+
const ids = appId === undefined ? [...model.checks.keys(), ...model.generation.keys()] : [appId];
|
|
1746
|
+
for (const id of ids) { model.checks.delete(id); model.generation.set(id, (model.generation.get(id) || 0) + 1); }
|
|
1747
|
+
},
|
|
1748
|
+
_model: model,
|
|
1749
|
+
};
|
|
1750
|
+
})();
|