loopengine 0.3.75 → 0.3.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/http-notifier.js +8 -1
- package/dist/core/messaging/connector.d.ts +2 -0
- package/dist/core/messaging/connectors/telegram/index.js +5 -0
- package/dist/core/messaging/engine.d.ts +13 -0
- package/dist/core/messaging/engine.js +40 -4
- package/dist/core/messaging/threads.d.ts +3 -0
- package/dist/core/messaging/threads.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/web/agents-config-page.js +107 -127
- package/dist/web/global-config-page.js +1 -1
- package/dist/web/workflow-page.js +4 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import { DatabaseApprover } from './http-notify-triggers/database.js';
|
|
|
7
7
|
import { RedisQueueApprover } from './http-notify-triggers/redis.js';
|
|
8
8
|
import { agentDirFor, createAgentEnv } from './agent-env.js';
|
|
9
9
|
import { notifierConfigFromFile, readActiveConnections, readNotifierFile } from './notifier-file.js';
|
|
10
|
-
import { recordThread } from './messaging/threads.js';
|
|
10
|
+
import { findThreadByPending, recordThread } from './messaging/threads.js';
|
|
11
11
|
import { recordTelegramMessage } from './messaging/connectors/telegram/store.js';
|
|
12
12
|
const EMPTY = {};
|
|
13
13
|
// Keyed by the AgentConfig object itself, not its httpNotifier field
|
|
@@ -190,6 +190,13 @@ function buildResolved(httpNotifier, agentDir) {
|
|
|
190
190
|
recordTelegramMessage(agentDir, { chat, id: messageId, root: root ?? messageId, fromBot: true, text });
|
|
191
191
|
if (pendingId && kind && !root)
|
|
192
192
|
recordThread(agentDir, { app: 'telegram', conversation: chat, ts: messageId, pendingId, kind });
|
|
193
|
+
// Its buttons are on its last message, recorded so a decision
|
|
194
|
+
// made by reply can take them away.
|
|
195
|
+
if (pendingId && root) {
|
|
196
|
+
const link = findThreadByPending(agentDir, pendingId);
|
|
197
|
+
if (link)
|
|
198
|
+
recordThread(agentDir, { ...link, buttonsTs: messageId });
|
|
199
|
+
}
|
|
193
200
|
},
|
|
194
201
|
});
|
|
195
202
|
return {
|
|
@@ -60,4 +60,6 @@ export interface MessagingConnector {
|
|
|
60
60
|
/** Replaces the request message itself (and its buttons) with the
|
|
61
61
|
* outcome, so nobody acts on a decision already made. Optional. */
|
|
62
62
|
replaceMessage?(conversation: string, ts: string, text: string): Promise<void>;
|
|
63
|
+
/** Takes a message's buttons away and leaves its text. Optional. */
|
|
64
|
+
removeButtons?(conversation: string, ts: string): Promise<void>;
|
|
63
65
|
}
|
|
@@ -92,6 +92,11 @@ export function createTelegramConnector(botToken, agentDir) {
|
|
|
92
92
|
if (!edited.ok)
|
|
93
93
|
console.error('[loopengine] Telegram editMessageText failed:', edited.description);
|
|
94
94
|
},
|
|
95
|
+
async removeButtons(conversation, ts) {
|
|
96
|
+
const edited = await callTelegram(botToken, 'editMessageReplyMarkup', { chat_id: conversation, message_id: Number(ts), reply_markup: { inline_keyboard: [] } });
|
|
97
|
+
if (!edited.ok)
|
|
98
|
+
console.error('[loopengine] Telegram editMessageReplyMarkup failed:', edited.description);
|
|
99
|
+
},
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
102
|
/** Stops a clicked button's spinner, with a short note when there's one. */
|
|
@@ -51,6 +51,9 @@ export interface DecisionOutcome {
|
|
|
51
51
|
morePending?: boolean;
|
|
52
52
|
/** The agent's reply once the run finished. */
|
|
53
53
|
text?: string;
|
|
54
|
+
/** The run came from a job thread, which gets the run's own next
|
|
55
|
+
* request or result (core/messaging/jobs.ts), so nothing is added. */
|
|
56
|
+
inJob?: boolean;
|
|
54
57
|
}
|
|
55
58
|
/** Handles one person's message: a reply in a request's thread gets an
|
|
56
59
|
* answer; anything else is left alone. */
|
|
@@ -63,12 +66,22 @@ export declare function isPlainApproval(text: string): boolean;
|
|
|
63
66
|
/** For a decision made outside the thread (the request's own buttons):
|
|
64
67
|
* replaces the thread's message with buttons, if any, with `text`. */
|
|
65
68
|
export declare function settleThreadChoice(deps: MessagingDeps, pendingId: string, text: string): Promise<void>;
|
|
69
|
+
/** For a decision made away from the chat (the web link): replaces the
|
|
70
|
+
* request message, and any message with buttons in its thread, with
|
|
71
|
+
* `text`, so nobody acts on it there. Nothing when it wasn't posted in
|
|
72
|
+
* a chat. */
|
|
73
|
+
export declare function settleRequest(deps: MessagingDeps, pendingId: string, text: string): Promise<void>;
|
|
66
74
|
/** A click on one of the engine's own buttons (Approve as changed, Keep
|
|
67
75
|
* original, Confirm, Cancel) — the caller has already checked the
|
|
68
76
|
* person may decide. Returns what the clicked message should now say. */
|
|
69
77
|
export declare function handleMessagingAction(action: Exclude<MessagingAction, 'deny'>, pendingId: string, user: string, deps: MessagingDeps): Promise<string>;
|
|
70
78
|
/** What to say in the thread once a decision is recorded. */
|
|
71
79
|
export declare function outcomeText(decision: 'approve' | 'deny' | 'answer', who: string, outcome: DecisionOutcome, answer?: string): string;
|
|
80
|
+
/** What to add in the thread once a decision said there is in, if
|
|
81
|
+
* anything: nothing when the agent sent a new request, which speaks
|
|
82
|
+
* for itself (and is already above this), or when the run's job thread
|
|
83
|
+
* gets its outcome from the job. */
|
|
84
|
+
export declare function followUpText(outcome: DecisionOutcome): string | undefined;
|
|
72
85
|
/** The thread as chat messages: the agent's own replies as `assistant`,
|
|
73
86
|
* people's as `user` (with who said it), the request itself left out
|
|
74
87
|
* because the prompt already describes it. The newest message is
|
|
@@ -105,9 +105,14 @@ export async function handleInboundMessage(message, deps) {
|
|
|
105
105
|
]);
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
|
-
const outcome = await deps.decide(link.pendingId, verdict.decision === 'answer' ? { kind: 'answer', answer: verdict.answer } : { kind: 'deny' });
|
|
109
108
|
const answer = verdict.decision === 'answer' ? connector.escape(verdict.answer) : undefined;
|
|
110
|
-
|
|
109
|
+
// Said before the decision goes in: the run carries on inside
|
|
110
|
+
// deps.decide and may post its next request before it returns.
|
|
111
|
+
await say(verdict.decision === 'deny' ? `Denied by ${who}. Letting the agent know…` : `Answered by ${who}: "${answer}". The agent is carrying on…`);
|
|
112
|
+
const outcome = await deps.decide(link.pendingId, verdict.decision === 'answer' ? { kind: 'answer', answer: verdict.answer } : { kind: 'deny' });
|
|
113
|
+
const after = followUpText(outcome);
|
|
114
|
+
if (after)
|
|
115
|
+
await say(after);
|
|
111
116
|
if (!outcome.error && !outcome.alreadyResolved) {
|
|
112
117
|
const what = link.kind === 'approval' ? `\`${item.tool}\`` : 'The question';
|
|
113
118
|
await replaceRequest(connector, link, `${what} was ${verdict.decision === 'deny' ? 'denied' : `answered ("${answer}")`} by ${who} in the thread.`);
|
|
@@ -199,7 +204,9 @@ async function runApproved(deps, link, tool, args, who) {
|
|
|
199
204
|
const edited = Boolean(link.proposedArgs);
|
|
200
205
|
await connector.postInThread(link.conversation, link.ts, `Approved${edited ? ' as changed' : ''} by ${who}. Running \`${tool}\` with:\n${formatArgs(args, connector.escape, await deps.toolSchema(tool))}`);
|
|
201
206
|
const outcome = await deps.decide(link.pendingId, { kind: 'approve', ...(edited ? { editedArgs: args } : {}) });
|
|
202
|
-
|
|
207
|
+
const after = followUpText(outcome);
|
|
208
|
+
if (after)
|
|
209
|
+
await connector.postInThread(link.conversation, link.ts, after);
|
|
203
210
|
if (!outcome.error && !outcome.alreadyResolved) {
|
|
204
211
|
await replaceRequest(connector, link, `\`${tool}\` was approved${edited ? ' as changed' : ''} by ${who} in the thread.`);
|
|
205
212
|
await settleChoice(deps, link, `Approved${edited ? ' as changed' : ''} by ${who}.`);
|
|
@@ -229,10 +236,24 @@ export async function settleThreadChoice(deps, pendingId, text) {
|
|
|
229
236
|
if (link)
|
|
230
237
|
await settleChoice(deps, link, text);
|
|
231
238
|
}
|
|
239
|
+
/** For a decision made away from the chat (the web link): replaces the
|
|
240
|
+
* request message, and any message with buttons in its thread, with
|
|
241
|
+
* `text`, so nobody acts on it there. Nothing when it wasn't posted in
|
|
242
|
+
* a chat. */
|
|
243
|
+
export async function settleRequest(deps, pendingId, text) {
|
|
244
|
+
const link = findThreadByPending(deps.agentDir, pendingId);
|
|
245
|
+
if (!link || link.app !== deps.connector.app)
|
|
246
|
+
return;
|
|
247
|
+
await replaceRequest(deps.connector, link, text);
|
|
248
|
+
await settleChoice(deps, link, text);
|
|
249
|
+
}
|
|
232
250
|
async function replaceRequest(connector, link, text) {
|
|
233
251
|
if (!connector.replaceMessage)
|
|
234
252
|
return;
|
|
235
253
|
await connector.replaceMessage(link.conversation, link.ts, text).catch((err) => console.error('[loopengine] could not update the request message:', err));
|
|
254
|
+
// A long request's buttons are on its last message.
|
|
255
|
+
if (link.buttonsTs && connector.removeButtons)
|
|
256
|
+
await connector.removeButtons(link.conversation, link.buttonsTs).catch((err) => console.error('[loopengine] could not update the request message:', err));
|
|
236
257
|
}
|
|
237
258
|
/** A click on one of the engine's own buttons (Approve as changed, Keep
|
|
238
259
|
* original, Confirm, Cancel) — the caller has already checked the
|
|
@@ -275,9 +296,24 @@ export function outcomeText(decision, who, outcome, answer) {
|
|
|
275
296
|
if (outcome.stillWaiting)
|
|
276
297
|
return `${what}. The agent is still waiting on another decision from the same step.`;
|
|
277
298
|
if (outcome.morePending)
|
|
278
|
-
return `${what}. The agent
|
|
299
|
+
return `${what}. The agent needed another decision and sent a new request.`;
|
|
279
300
|
return `${what}.${outcome.text ? `\n> ${outcome.text.replace(/\n/g, '\n> ')}` : ''}`;
|
|
280
301
|
}
|
|
302
|
+
/** What to add in the thread once a decision said there is in, if
|
|
303
|
+
* anything: nothing when the agent sent a new request, which speaks
|
|
304
|
+
* for itself (and is already above this), or when the run's job thread
|
|
305
|
+
* gets its outcome from the job. */
|
|
306
|
+
export function followUpText(outcome) {
|
|
307
|
+
if (outcome.error)
|
|
308
|
+
return `Couldn't record that: ${outcome.error}`;
|
|
309
|
+
if (outcome.alreadyResolved)
|
|
310
|
+
return 'This was already decided elsewhere.';
|
|
311
|
+
if (outcome.stillWaiting)
|
|
312
|
+
return 'The agent is still waiting on another decision from the same step.';
|
|
313
|
+
if (outcome.morePending || outcome.inJob)
|
|
314
|
+
return undefined;
|
|
315
|
+
return outcome.text ? `Done.\n> ${outcome.text.replace(/\n/g, '\n> ')}` : 'Done.';
|
|
316
|
+
}
|
|
281
317
|
/** The thread as chat messages: the agent's own replies as `assistant`,
|
|
282
318
|
* people's as `user` (with who said it), the request itself left out
|
|
283
319
|
* because the prompt already describes it. The newest message is
|
|
@@ -14,6 +14,9 @@ export interface ThreadLink {
|
|
|
14
14
|
* proposed change, a Confirm), so it can be replaced once the request
|
|
15
15
|
* is decided and its buttons don't linger. */
|
|
16
16
|
choiceTs?: string;
|
|
17
|
+
/** A long request goes out as several messages (Telegram), its
|
|
18
|
+
* buttons on the last: that message, when it isn't `ts`. */
|
|
19
|
+
buttonsTs?: string;
|
|
17
20
|
}
|
|
18
21
|
/** Appends one request's thread. Never throws: a request that can't be
|
|
19
22
|
* mapped still works through its buttons and link. */
|
|
@@ -12,8 +12,8 @@ function threadsFile(agentDir) {
|
|
|
12
12
|
export function recordThread(agentDir, link) {
|
|
13
13
|
try {
|
|
14
14
|
mkdirSync(join(agentDir, '.messaging'), { recursive: true });
|
|
15
|
-
const { app, conversation, ts, pendingId, kind, proposedArgs, choiceTs } = link;
|
|
16
|
-
appendFileSync(threadsFile(agentDir), JSON.stringify({ app, conversation, ts, pendingId, kind, ...(proposedArgs ? { proposedArgs } : {}), ...(choiceTs ? { choiceTs } : {}), at: new Date().toISOString() }) + '\n');
|
|
15
|
+
const { app, conversation, ts, pendingId, kind, proposedArgs, choiceTs, buttonsTs } = link;
|
|
16
|
+
appendFileSync(threadsFile(agentDir), JSON.stringify({ app, conversation, ts, pendingId, kind, ...(proposedArgs ? { proposedArgs } : {}), ...(choiceTs ? { choiceTs } : {}), ...(buttonsTs ? { buttonsTs } : {}), at: new Date().toISOString() }) + '\n');
|
|
17
17
|
}
|
|
18
18
|
catch (err) {
|
|
19
19
|
console.error('[loopengine] could not record the thread:', err instanceof Error ? err.message : err);
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { listDeliveries, recordDelivery, type NotifierDelivery } from '#core/not
|
|
|
13
13
|
export { describeNotifier } from '#core/http-notifier.js';
|
|
14
14
|
export { Scheduler, ScheduleError, FileSchedulerStore, getSchedulerStore, setSchedulerStore, createScheduledTask, listScheduledTasks, getScheduledTask, cancelScheduledTask, pauseScheduledTask, resumeScheduledTask, runScheduledTaskNow, setScheduledTaskNotify, deleteScheduledTask, nextScheduledWakeAt, moveScheduledTasksToTimeZone, importLegacyScheduledTasks, parseEvery, describeSchedule, type ScheduledTask, type ScheduledTaskRun, type ScheduledTaskStatus, type Schedule, type SchedulerStore, type FireTask, type CreateScheduledTaskInput } from '#core/scheduler.js';
|
|
15
15
|
export { NOTIFIER_SLACK_SIGNING_SECRET_VAR } from '#core/notifier-file.js';
|
|
16
|
-
export { firstSighting, handleInboundMessage, handleMessagingAction, settleThreadChoice, isPlainApproval, outcomeText, type MessagingDeps, type MessagingDecision, type DecisionOutcome } from '#core/messaging/engine.js';
|
|
16
|
+
export { firstSighting, handleInboundMessage, handleMessagingAction, settleRequest, settleThreadChoice, isPlainApproval, outcomeText, followUpText, type MessagingDeps, type MessagingDecision, type DecisionOutcome } from '#core/messaging/engine.js';
|
|
17
17
|
export { handleJobMessage, isJobMessage, settleJobThread, jobSessionId, findJobFor, type JobDeps, type JobTurn } from '#core/messaging/jobs.js';
|
|
18
18
|
export { formatArgs, formatChange, labelFor } from '#core/messaging/format-args.js';
|
|
19
19
|
export { decideReply, proposeEdit, describeChange, type ReplyDecision, type DecisionRequest } from '#core/messaging/decide.js';
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export { listDeliveries, recordDelivery } from '#core/notifier-deliveries.js';
|
|
|
15
15
|
export { describeNotifier } from '#core/http-notifier.js';
|
|
16
16
|
export { Scheduler, ScheduleError, FileSchedulerStore, getSchedulerStore, setSchedulerStore, createScheduledTask, listScheduledTasks, getScheduledTask, cancelScheduledTask, pauseScheduledTask, resumeScheduledTask, runScheduledTaskNow, setScheduledTaskNotify, deleteScheduledTask, nextScheduledWakeAt, moveScheduledTasksToTimeZone, importLegacyScheduledTasks, parseEvery, describeSchedule } from '#core/scheduler.js';
|
|
17
17
|
export { NOTIFIER_SLACK_SIGNING_SECRET_VAR } from '#core/notifier-file.js';
|
|
18
|
-
export { firstSighting, handleInboundMessage, handleMessagingAction, settleThreadChoice, isPlainApproval, outcomeText } from '#core/messaging/engine.js';
|
|
18
|
+
export { firstSighting, handleInboundMessage, handleMessagingAction, settleRequest, settleThreadChoice, isPlainApproval, outcomeText, followUpText } from '#core/messaging/engine.js';
|
|
19
19
|
export { handleJobMessage, isJobMessage, settleJobThread, jobSessionId, findJobFor } from '#core/messaging/jobs.js';
|
|
20
20
|
export { formatArgs, formatChange, labelFor } from '#core/messaging/format-args.js';
|
|
21
21
|
export { decideReply, proposeEdit, describeChange } from '#core/messaging/decide.js';
|
|
@@ -96,7 +96,7 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
96
96
|
.wf-list-box { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; }
|
|
97
97
|
.wf-row + .wf-row { border-top: 1px solid var(--line); }
|
|
98
98
|
.wf-row.workflow-focus { box-shadow: inset 3px 0 0 var(--accent); }
|
|
99
|
-
.wf-row-head { display: grid; grid-template-columns: 14px minmax(0, 1fr)
|
|
99
|
+
.wf-row-head { display: grid; grid-template-columns: 14px minmax(0, 1fr) 210px 200px auto; align-items: center; gap: 14px; padding: 12px 16px; cursor: pointer; }
|
|
100
100
|
.wf-row-head:hover { background: var(--surface); }
|
|
101
101
|
.wf-row-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
|
|
102
102
|
.wf-row-caret { width: 7px; height: 7px; border-right: 2px solid var(--ink-muted); border-bottom: 2px solid var(--ink-muted); transform: rotate(-45deg); transition: transform .15s; }
|
|
@@ -104,7 +104,13 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
104
104
|
.wf-row-main { min-width: 0; display: grid; gap: 2px; }
|
|
105
105
|
.wf-row-main strong { font-size: 14px; font-weight: 650; color: var(--ink); }
|
|
106
106
|
.wf-row-desc { font-size: 12.5px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
107
|
-
.wf-row-starts { font-size: 12.5px; color: var(--ink-muted);
|
|
107
|
+
.wf-row-starts { display: grid; gap: 2px; font-size: 12.5px; color: var(--ink-muted); min-width: 0; }
|
|
108
|
+
.wf-start-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
109
|
+
.wf-start-state { font-size: 11px; font-weight: 700; padding: 0 6px; margin-left: 2px; border-radius: 999px; }
|
|
110
|
+
.wf-start-state + .wf-start-state { margin-left: 4px; }
|
|
111
|
+
.wf-start-state.on { background: var(--good-soft); color: var(--good); }
|
|
112
|
+
.wf-start-state.off { background: var(--warn-soft); color: var(--warn); }
|
|
113
|
+
.wf-start-state.warn { background: var(--warn-soft); color: var(--warn); }
|
|
108
114
|
.wf-row-last { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; white-space: nowrap; }
|
|
109
115
|
.wf-row-last .hint { white-space: nowrap; }
|
|
110
116
|
.wf-row-actions { display: flex; gap: 6px; }
|
|
@@ -121,7 +127,6 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
121
127
|
.wf-row .workflow-steps-text { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--surface); font-size: 13px; line-height: 1.6; max-height: 420px; overflow: auto; white-space: pre-wrap; }
|
|
122
128
|
.wf-original { margin-top: 10px; }
|
|
123
129
|
.wf-original summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-muted); margin-bottom: 6px; }
|
|
124
|
-
.wf-row .workflow-starts > .workflow-section-content { padding: 0; }
|
|
125
130
|
.wf-row .workflow-result:empty { display: none; }
|
|
126
131
|
.wf-cb { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; line-height: 1.5; }
|
|
127
132
|
.wf-cb-k { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--accent-ink); padding-top: 1px; }
|
|
@@ -135,6 +140,19 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
135
140
|
.wf-cb-decision.ask { background: var(--warn-soft); color: var(--warn); }
|
|
136
141
|
.wf-cb-decision.deny { background: var(--bad-soft); color: var(--bad); }
|
|
137
142
|
@media (max-width: 520px) { .wf-cb { grid-template-columns: minmax(0, 1fr); gap: 2px; } .wf-cb-v { margin-bottom: 8px; } }
|
|
143
|
+
.wf-trigger { gap: 6px; }
|
|
144
|
+
.wf-trigger-item { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
|
|
145
|
+
.wf-trigger-item button, .wf-trigger-add button, .wf-trigger .workflow-hook button { padding: 2px 10px; font-size: 12px; }
|
|
146
|
+
.wf-trigger .workflow-hooks:empty { display: none; }
|
|
147
|
+
.wf-trigger .workflow-hook { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
|
|
148
|
+
.wf-trigger-add { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
149
|
+
.wf-trigger-add [hidden] { display: none; }
|
|
150
|
+
.wf-api summary { cursor: pointer; font-size: 12.5px; color: var(--accent-ink); }
|
|
151
|
+
.wf-api[open] { display: grid; gap: 6px; }
|
|
152
|
+
.wf-api pre { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
153
|
+
.wf-run-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
|
|
154
|
+
.wf-run-bar .workflow-params { margin: 0; flex: 1 1 320px; }
|
|
155
|
+
.wf-run-bar-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-left: auto; }
|
|
138
156
|
.wf-sub { margin: 6px 0 0; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted); }
|
|
139
157
|
.wf-scores { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
|
|
140
158
|
.wf-score { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
|
|
@@ -179,13 +197,6 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
179
197
|
.workflow-section-content { padding: 4px 20px 24px; }
|
|
180
198
|
.workflow-section-meta { margin-left: auto; color: var(--ink-muted); font-size: 12px; font-weight: 500; }
|
|
181
199
|
.wf-card .workflow-steps-text { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--surface); font-size: 13px; line-height: 1.6; max-height: 320px; overflow: auto; }
|
|
182
|
-
.workflow-starts > .workflow-section-content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
|
|
183
|
-
.workflow-starts.wf-starts-compact > .workflow-section-content { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
184
|
-
.workflow-starts.wf-starts-compact .wf-start-api { grid-column: 1 / -1; }
|
|
185
|
-
@media (max-width: 900px) { .workflow-starts.wf-starts-compact > .workflow-section-content { grid-template-columns: minmax(0, 1fr); } }
|
|
186
|
-
.workflow-starts .wf-start { align-content: start; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
|
|
187
|
-
.workflow-starts .wf-start:first-of-type { padding-top: 14px; border-top: 1px solid var(--line); }
|
|
188
|
-
.workflow-starts .workflow-hooks:empty { display: none; }
|
|
189
200
|
@media (max-width: 640px) {
|
|
190
201
|
.wf-tab-head, .wf-card-head { flex-direction: column; }
|
|
191
202
|
.wf-card-actions { max-width: none; justify-content: flex-start; }
|
|
@@ -206,19 +217,8 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
206
217
|
form.add-source .schedule-when select, form.add-source .schedule-when input[type="datetime-local"] { width: auto; }
|
|
207
218
|
.workflow-card.workflow-focus { box-shadow: 0 0 0 2px var(--le-accent, #0f766e); transition: box-shadow 0.3s; }
|
|
208
219
|
tr.schedule-focus td { background: var(--le-accent-soft, #e6f4ef); transition: background 0.3s; }
|
|
209
|
-
.workflow-run-controls { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
|
|
210
220
|
.workflow-run-notify { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
|
|
211
221
|
.workflow-run-notify input { width: auto; margin: 0; }
|
|
212
|
-
.wf-start { padding: 10px 0; border-top: 1px solid var(--le-line, #e5e7eb); display: grid; gap: 6px; font-size: 13px; }
|
|
213
|
-
.wf-start:first-of-type { border-top: 0; padding-top: 6px; }
|
|
214
|
-
.wf-start-head { display: flex; align-items: center; gap: 6px; }
|
|
215
|
-
.wf-start-head strong { font-size: 13px; }
|
|
216
|
-
.help-q { width: 18px; height: 18px; padding: 0; border-radius: 50%; font-size: 11px; line-height: 16px; font-weight: 600; text-align: center; cursor: pointer; }
|
|
217
|
-
.help-text { margin: 0; }
|
|
218
|
-
.help-text[hidden] { display: none; }
|
|
219
|
-
.wf-start .schedule-history { margin: 0; gap: 6px; }
|
|
220
|
-
.wf-start .workflow-params { margin: 0; }
|
|
221
|
-
.wf-start pre { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--le-bg, #fff); border: 1px solid var(--le-line, #e5e7eb); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
222
222
|
.workflow-steps-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: var(--le-surface, #f6f7f9); }
|
|
223
223
|
.workflow-params { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
|
|
224
224
|
.workflow-params[hidden] { display: none; }
|
|
@@ -968,40 +968,16 @@ ${consoleShellScript}
|
|
|
968
968
|
// from "Describe a workflow": each with its instructions, what starts it
|
|
969
969
|
// (its real schedules and webhooks), its recent runs and Run now. ----
|
|
970
970
|
|
|
971
|
-
//
|
|
972
|
-
//
|
|
973
|
-
function
|
|
974
|
-
|
|
975
|
-
if (w.webhooks) parts.push(w.webhooks === 1 ? 'when its webhook is called' : 'when one of its ' + w.webhooks + ' webhooks is called');
|
|
976
|
-
if (!parts.length) return 'No schedule or webhook yet';
|
|
977
|
-
var text = parts.join(', and ');
|
|
978
|
-
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
// With no schedule and no webhook, Run now, Schedule and Webhook are
|
|
982
|
-
// small: one row; once either has something to list, one per row.
|
|
983
|
-
function startsCompact(w) {
|
|
984
|
-
return !(w.schedules || []).length && !(w.webhooks || w.webhooksWaiting || w.webhooksOff);
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
// Ways to run it: four, each with a ? that says what it is. Run now
|
|
988
|
-
// with the values a run is given, a schedule (pause, resume, remove,
|
|
989
|
-
// add), a webhook, and the API call an app makes.
|
|
990
|
-
function wfStartSection(key, title, help, body) {
|
|
991
|
-
return '<div class="wf-start wf-start-' + key.split('-')[0] + '">' +
|
|
992
|
-
'<div class="wf-start-head"><strong>' + title + '</strong>' +
|
|
993
|
-
'<button type="button" class="help-q" aria-expanded="false" aria-controls="help-' + key + '" aria-label="What is ' + title.toLowerCase() + '?">?</button></div>' +
|
|
994
|
-
'<p class="hint help-text" hidden>' + help + '</p>' + body + '</div>';
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
function workflowStartsHtml(w, agentName, paramsHtml) {
|
|
998
|
-
var schedules = (w.schedules || []).map(function (x) {
|
|
971
|
+
// A workflow's schedules, each with its state and Pause/Resume and
|
|
972
|
+
// Remove, as lines of its contract's trigger row.
|
|
973
|
+
function workflowScheduleItemsHtml(w, agentName) {
|
|
974
|
+
return (w.schedules || []).map(function (x) {
|
|
999
975
|
var state = x.waiting ? '<span class="le-pill ask">Waiting for a decision</span>'
|
|
1000
976
|
: x.status === 'paused' ? '<span class="le-pill warn">Paused</span>'
|
|
1001
977
|
: x.status === 'running' ? '<span class="le-pill accent">Running</span>'
|
|
1002
978
|
: (x.nextRunAt ? '<span class="hint">next ' + escapeHtml(new Date(x.nextRunAt).toLocaleString()) + '</span>' : '');
|
|
1003
979
|
var values = x.params ? Object.keys(x.params).map(function (k) { return escapeHtml(k) + ': ' + escapeHtml(x.params[k]); }).join(' ' + String.fromCharCode(183) + ' ') : '';
|
|
1004
|
-
return '<
|
|
980
|
+
return '<div class="wf-trigger-item">' +
|
|
1005
981
|
'<span><a href="?agent=' + encodeURIComponent(agentName) + '&tab=schedules#schedule-' + escapeHtml(x.taskId) + '" class="workflow-schedule-link" data-task="' + escapeHtml(x.taskId) + '" title="See it in the Schedules tab">' +
|
|
1006
982
|
escapeHtml(x.describe.charAt(0).toUpperCase() + x.describe.slice(1)) + '</a></span>' + state +
|
|
1007
983
|
(values ? '<span class="hint">' + values + '</span>' : '') +
|
|
@@ -1010,34 +986,34 @@ ${consoleShellScript}
|
|
|
1010
986
|
(x.status === 'paused' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="resume">Resume</button>'
|
|
1011
987
|
: x.status === 'scheduled' ? '<button type="button" class="workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="pause">Pause</button>' : '') +
|
|
1012
988
|
'<button type="button" class="delete-btn workflow-schedule-action" data-id="' + escapeHtml(x.taskId) + '" data-action="cancel">Remove</button>' +
|
|
1013
|
-
'</span></
|
|
989
|
+
'</span></div>';
|
|
1014
990
|
}).join('');
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// Run now, above the tabs: the values a run is given, and whether its
|
|
994
|
+
// result also goes to the messaging app.
|
|
995
|
+
function workflowRunBarHtml(w, paramsHtml) {
|
|
996
|
+
return '<div class="wf-run-bar">' +
|
|
997
|
+
(paramsHtml ? '<div class="workflow-params">' + paramsHtml + '</div>' : '') +
|
|
998
|
+
'<div class="wf-run-bar-controls">' +
|
|
999
|
+
'<label class="workflow-run-notify" title="Sends the completed result through this agent' + String.fromCharCode(8217) + 's configured notifier"><input type="checkbox" class="workflow-run-notify-toggle"> Send result to messaging app</label>' +
|
|
1000
|
+
'<button type="button" class="workflow-run primary">Run now</button></div>' +
|
|
1001
|
+
'</div>';
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// The call an app makes to start a run, folded under the trigger row.
|
|
1005
|
+
function workflowApiHtml(w, agentName) {
|
|
1015
1006
|
var paramNames = Object.keys(w.parameters || {});
|
|
1016
1007
|
// A body that shows what a call can carry: its values, and waiting
|
|
1017
1008
|
// for the result.
|
|
1018
1009
|
var example = '{ ' + (paramNames.length ? '"params": { ' + paramNames.map(function (p) { return '"' + p + '": "' + String.fromCharCode(8230) + '"'; }).join(', ') + ' }, ' : '') + '"wait": true }';
|
|
1019
1010
|
var apiUrl = location.origin + '/agents/' + encodeURIComponent(agentName) + '/workflows/' + encodeURIComponent(w.id) + '/run';
|
|
1020
|
-
return '<
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
'<
|
|
1025
|
-
|
|
1026
|
-
'<button type="button" class="workflow-run primary">Run now</button></div>') +
|
|
1027
|
-
wfStartSection('schedule-' + w.id, 'Schedule',
|
|
1028
|
-
'Runs it on a timer, like every day at 9:00, with the values you give the schedule. Nobody needs to be there: approvals and questions go to the agent' + String.fromCharCode(8217) + 's messaging app.',
|
|
1029
|
-
(schedules ? '<ul class="schedule-history">' + schedules + '</ul>' : '<span class="hint">None yet.</span>') +
|
|
1030
|
-
'<div><button type="button" class="workflow-add-schedule">Add a schedule</button></div>') +
|
|
1031
|
-
wfStartSection('webhook-' + w.id, 'Webhook',
|
|
1032
|
-
'A private web address another app (Stripe, GitHub, Shopify or your own) calls when something happens. Each call starts a run, with values taken from what the app sends.',
|
|
1033
|
-
'<div class="workflow-hooks"></div>' +
|
|
1034
|
-
'<div class="workflow-hooks-add"' + (w.webhooks || w.webhooksWaiting || w.webhooksOff ? ' hidden' : '') + '><button type="button" class="workflow-hooks-btn">Add a webhook</button></div>') +
|
|
1035
|
-
wfStartSection('api-' + w.id, 'API',
|
|
1036
|
-
'Your own app starts a run by calling this address with an API key. Add "wait": true to get the result in the answer, or "callback_url" to have it posted to you when the run ends.',
|
|
1037
|
-
'<pre>POST ' + escapeHtml(apiUrl) + String.fromCharCode(10) + escapeHtml(example) + '</pre>' +
|
|
1038
|
-
'<p class="hint" style="margin:0">' + (paramNames.length ? '<code>params</code>: ' + paramNames.map(function (p) { return '<code>' + escapeHtml(p) + '</code>' + (w.parameters[p].required ? ' (required)' : '') + (w.parameters[p].description ? ', ' + escapeHtml(w.parameters[p].description) : ''); }).join('; ') + '. ' : 'It takes no params. ') +
|
|
1039
|
-
'Optional: <code>"wait": true</code> answers with the result; <code>"notify": true</code> sends the result to the messaging app; <code>"callback_url"</code> posts it to your app when the run ends. Leave them out to get the run' + String.fromCharCode(8217) + 's id back at once.</p>') +
|
|
1040
|
-
'</div></div>';
|
|
1011
|
+
return '<details class="wf-api"><summary>Show the API call</summary>' +
|
|
1012
|
+
'<p class="hint" style="margin:0">Your own app starts a run by calling this address with an API key.</p>' +
|
|
1013
|
+
'<pre>POST ' + escapeHtml(apiUrl) + String.fromCharCode(10) + escapeHtml(example) + '</pre>' +
|
|
1014
|
+
'<p class="hint" style="margin:0">' + (paramNames.length ? '<code>params</code>: ' + paramNames.map(function (p) { return '<code>' + escapeHtml(p) + '</code>' + (w.parameters[p].required ? ' (required)' : '') + (w.parameters[p].description ? ', ' + escapeHtml(w.parameters[p].description) : ''); }).join('; ') + '. ' : 'It takes no params. ') +
|
|
1015
|
+
'Optional: <code>"wait": true</code> answers with the result; <code>"notify": true</code> sends the result to the messaging app; <code>"callback_url"</code> posts it to your app when the run ends. Leave them out to get the run' + String.fromCharCode(8217) + 's id back at once.</p>' +
|
|
1016
|
+
'</details>';
|
|
1041
1017
|
}
|
|
1042
1018
|
|
|
1043
1019
|
// What starts a workflow and what it's doing, as chips under its title:
|
|
@@ -1075,22 +1051,42 @@ ${consoleShellScript}
|
|
|
1075
1051
|
return (w.recentRuns || []).some(function (r) { return r.status === 'awaiting_approval'; }) || (w.schedules || []).some(function (x) { return x.waiting; });
|
|
1076
1052
|
}
|
|
1077
1053
|
|
|
1078
|
-
// How it starts,
|
|
1054
|
+
// How it starts, for its row: each schedule (saying when it's paused)
|
|
1055
|
+
// and its webhooks on or off, so its state shows without opening it.
|
|
1079
1056
|
function workflowStartsSummary(w) {
|
|
1080
|
-
var
|
|
1057
|
+
var lines = [];
|
|
1058
|
+
var state = function (text, kind) { return ' <span class="wf-start-state ' + kind + '">' + text + '</span>'; };
|
|
1081
1059
|
var schedules = (w.schedules || []).filter(function (x) { return x.status !== 'cancelled'; });
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1060
|
+
schedules.slice(0, 2).forEach(function (x) {
|
|
1061
|
+
lines.push(escapeHtml(x.describe.charAt(0).toUpperCase() + x.describe.slice(1)) + (x.status === 'paused' ? state('paused', 'off') : ''));
|
|
1062
|
+
});
|
|
1063
|
+
if (schedules.length > 2) {
|
|
1064
|
+
var more = schedules.slice(2);
|
|
1065
|
+
var pausedMore = more.filter(function (x) { return x.status === 'paused'; }).length;
|
|
1066
|
+
lines.push('<span class="hint">+' + more.length + ' more ' + (more.length === 1 ? 'schedule' : 'schedules') + '</span>' + (pausedMore ? state(pausedMore + ' paused', 'off') : ''));
|
|
1067
|
+
}
|
|
1068
|
+
var on = w.webhooks || 0, waiting = w.webhooksWaiting || 0, off = w.webhooksOff || 0;
|
|
1069
|
+
if (on + waiting + off) {
|
|
1070
|
+
var name = on + waiting + off === 1 ? 'Webhook' : 'Webhooks';
|
|
1071
|
+
var states = [];
|
|
1072
|
+
if (on) states.push(state((on + waiting + off > 1 ? on + ' ' : '') + 'on', 'on'));
|
|
1073
|
+
if (off) states.push(state((on + waiting + off > 1 ? off + ' ' : '') + 'off', 'off'));
|
|
1074
|
+
if (waiting) states.push(state('needs its signing secret', 'warn'));
|
|
1075
|
+
lines.push(name + states.join(''));
|
|
1076
|
+
}
|
|
1077
|
+
// Nothing starts it on its own: the ways it does start.
|
|
1078
|
+
if (!lines.length) return '<span class="hint">Run now or API</span>';
|
|
1079
|
+
return lines.map(function (l) { return '<span class="wf-start-line">' + l + '</span>'; }).join('');
|
|
1085
1080
|
}
|
|
1086
1081
|
|
|
1087
1082
|
function workflowLastRunHtml(r) {
|
|
1088
1083
|
if (!r) return '<span class="hint">No runs yet</span>';
|
|
1089
|
-
var
|
|
1090
|
-
|
|
1084
|
+
var when = new Date(r.started_at).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
1085
|
+
// A run that finished is just when it ran; the others say their state.
|
|
1086
|
+
if (r.status === 'done') return '<span class="hint">Last run ' + escapeHtml(when) + '</span>';
|
|
1087
|
+
var pill = r.status === 'error' ? '<span class="le-pill bad">Failed</span>'
|
|
1091
1088
|
: r.status === 'awaiting_approval' ? '<span class="le-pill ask">Waiting for a decision</span>'
|
|
1092
1089
|
: '<span class="le-pill accent">Running</span>';
|
|
1093
|
-
var when = new Date(r.started_at).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
1094
1090
|
return pill + '<span class="hint">' + escapeHtml(when) + '</span>';
|
|
1095
1091
|
}
|
|
1096
1092
|
|
|
@@ -1147,17 +1143,28 @@ ${consoleShellScript}
|
|
|
1147
1143
|
return lines.map(function (l) { return '<div class="wf-cb-line">' + l + '</div>'; }).join('');
|
|
1148
1144
|
}
|
|
1149
1145
|
function workflowContractHtml(w, name, params) {
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1146
|
+
// The trigger row is where its triggers are managed: each schedule
|
|
1147
|
+
// and webhook with its controls, a way to add either, and the other
|
|
1148
|
+
// ways any workflow starts (Run now above the tabs, the API call).
|
|
1149
|
+
var schedules = workflowScheduleItemsHtml(w, name);
|
|
1150
|
+
// Its webhooks as the contract says them, until the full rows (with
|
|
1151
|
+
// deliveries and setup steps) load into the same box.
|
|
1152
|
+
var hookLines = [];
|
|
1155
1153
|
(w.triggers || []).forEach(function (t) {
|
|
1156
|
-
|
|
1154
|
+
hookLines.push(escapeHtml(SENDER_LABELS[t.sender] || t.sender) + ' webhook' + (t.filter ? ', <code>' + escapeHtml(t.filter.values.join(' | ')) + '</code>' : '') +
|
|
1157
1155
|
(t.waiting ? ' <span class="le-pill ask">Needs its signing secret</span>' : !t.enabled ? ' <span class="le-pill warn">Off</span>' : ''));
|
|
1158
|
-
Object.keys(t.mapping || {}).forEach(function (param) {
|
|
1156
|
+
Object.keys(t.mapping || {}).forEach(function (param) { hookLines.push('<span class="wf-cb-indent"><code>' + escapeHtml(param) + '</code> ' + ARROW_L + ' <code>' + escapeHtml(t.mapping[param]) + '</code></span>'); });
|
|
1159
1157
|
});
|
|
1160
|
-
|
|
1158
|
+
var hasHooks = Boolean(w.webhooks || w.webhooksWaiting || w.webhooksOff || (w.triggers || []).length);
|
|
1159
|
+
var hasTrigger = Boolean(schedules) || hasHooks;
|
|
1160
|
+
var triggerHtml = schedules +
|
|
1161
|
+
'<div class="workflow-hooks">' + contractLinesHtml(hookLines) + '</div>' +
|
|
1162
|
+
'<div class="wf-cb-line"><span class="hint">' + (hasTrigger
|
|
1163
|
+
? 'also by hand (Run now) or from an app (API)'
|
|
1164
|
+
: 'it runs when started by hand (Run now) or from an app (API), or set up a schedule or webhook') + '</span></div>' +
|
|
1165
|
+
'<div class="wf-trigger-add"><button type="button" class="workflow-add-schedule">+ Schedule</button>' +
|
|
1166
|
+
'<span class="workflow-hooks-add"' + (w.webhooksWaiting ? ' hidden' : '') + '><button type="button" class="workflow-hooks-btn">+ Webhook</button></span></div>' +
|
|
1167
|
+
workflowApiHtml(w, name);
|
|
1161
1168
|
var names = Object.keys(w.parameters || {});
|
|
1162
1169
|
var inputs = names.length ? names.map(function (n) {
|
|
1163
1170
|
var spec = w.parameters[n];
|
|
@@ -1179,9 +1186,8 @@ ${consoleShellScript}
|
|
|
1179
1186
|
if ((w.triggers || []).some(function (t) { return t.callback; })) result.push('posted to the webhook' + RSQ + 's callback address');
|
|
1180
1187
|
var model = w.model ? escapeHtml(w.model.provider + ' ' + w.model.model) : escapeHtml(workflowsMeta.agentModel || 'the agent' + RSQ + 's') + ' <span class="hint">(the agent' + RSQ + 's model)</span>';
|
|
1181
1188
|
var row = function (k, lines) { return '<div class="wf-cb-k">' + k + '</div><div class="wf-cb-v">' + contractLinesHtml(lines) + '</div>'; };
|
|
1182
|
-
return '<div class="wf-cb">' +
|
|
1183
|
-
'<p class="hint" style="margin:0">Change the inputs, result and model with Edit
|
|
1184
|
-
'<h4 class="wf-sub">Run it, or set up its triggers</h4>' + workflowStartsHtml(w, name, params);
|
|
1189
|
+
return '<div class="wf-cb">' + '<div class="wf-cb-k">trigger</div><div class="wf-cb-v wf-trigger">' + triggerHtml + '</div>' + row('inputs', inputs) + row('tools', tools) + row('result', result) + row('model', [model]) + '</div>' +
|
|
1190
|
+
'<p class="hint" style="margin:0">Change the inputs, result and model with Edit, and what tools may do in Permissions.</p>';
|
|
1185
1191
|
}
|
|
1186
1192
|
|
|
1187
1193
|
function workflowBriefHtml(w) {
|
|
@@ -1289,12 +1295,13 @@ ${consoleShellScript}
|
|
|
1289
1295
|
'<div class="wf-row-head" role="button" tabindex="0" aria-expanded="' + open + '">' +
|
|
1290
1296
|
'<span class="wf-row-caret" aria-hidden="true"></span>' +
|
|
1291
1297
|
'<div class="wf-row-main"><strong>' + escapeHtml(w.title) + '</strong>' + (w.description ? '<span class="wf-row-desc">' + escapeHtml(w.description) + '</span>' : '') + '</div>' +
|
|
1292
|
-
'<span class="wf-row-starts">' +
|
|
1298
|
+
'<span class="wf-row-starts">' + workflowStartsSummary(w) + '</span>' +
|
|
1293
1299
|
'<span class="wf-row-last">' + workflowLastRunHtml(last) + '</span>' +
|
|
1294
1300
|
'<span class="wf-row-actions"><button type="button" class="workflow-edit">Edit</button><button type="button" class="wf-remove workflow-forget" title="Its schedules and webhooks go; its instructions stay as a skill for Chat">Remove</button></span>' +
|
|
1295
1301
|
'</div>' +
|
|
1296
1302
|
'<div class="wf-row-body"' + (open ? '' : ' hidden') + '>' +
|
|
1297
1303
|
'<div class="wf-chips">' + workflowStatusChips(w) + '</div>' +
|
|
1304
|
+
workflowRunBarHtml(w, params) +
|
|
1298
1305
|
'<div class="wf-tabs" role="tablist">' + tabBtn('contract', 'Contract') + tabBtn('brief', 'Brief') + tabBtn('evidence', 'Evidence' + (runs ? ' <span class="wf-tab-count">' + w.recentRuns.length + '</span>' : '')) + '</div>' +
|
|
1299
1306
|
panel('contract', workflowContractHtml(w, name, params)) +
|
|
1300
1307
|
panel('brief', workflowBriefHtml(w)) +
|
|
@@ -1561,10 +1568,6 @@ ${consoleShellScript}
|
|
|
1561
1568
|
|
|
1562
1569
|
// ---- A workflow's webhook triggers (core/workflow-triggers.ts): secret
|
|
1563
1570
|
// URLs an outside service posts its events to, to start a run.
|
|
1564
|
-
var HOOK_OUTCOMES = {
|
|
1565
|
-
started: ['good', 'Started a run'], filtered: ['', 'Skipped by the filter'], duplicate: ['', 'A retry, skipped'],
|
|
1566
|
-
busy: ['', 'Already running'], rejected: ['bad', 'Signature check failed'], invalid: ['bad', 'Couldn' + String.fromCharCode(8217) + 't start'], error: ['bad', 'Failed'],
|
|
1567
|
-
};
|
|
1568
1571
|
var HOOK_SENDERS = { stripe: 'Stripe', github: 'GitHub', shopify: 'Shopify', standard: 'Standard Webhooks', custom: 'your app' };
|
|
1569
1572
|
var ARROW = String.fromCharCode(8594);
|
|
1570
1573
|
// Where each sender takes the URL, and what it calls the secret.
|
|
@@ -1581,11 +1584,6 @@ ${consoleShellScript}
|
|
|
1581
1584
|
}
|
|
1582
1585
|
|
|
1583
1586
|
function hookRowHtml(t, shownUrl) {
|
|
1584
|
-
var last = (t.deliveries || []).slice(0, 3).map(function (d) {
|
|
1585
|
-
var o = HOOK_OUTCOMES[d.outcome] || ['', d.outcome];
|
|
1586
|
-
return '<li><span class="le-pill ' + o[0] + '">' + escapeHtml(o[1]) + '</span> <span class="hint">' + escapeHtml(new Date(d.at).toLocaleString()) + '</span>' +
|
|
1587
|
-
(d.detail ? '<div class="schedule-result">' + escapeHtml(d.detail) + '</div>' : '') + '</li>';
|
|
1588
|
-
}).join('');
|
|
1589
1587
|
var rules = [];
|
|
1590
1588
|
if (t.verify) rules.push(t.verify.sender === 'custom'
|
|
1591
1589
|
? 'checks the signature in ' + escapeHtml(t.verify.header || '(header not set yet)') + ' (' + escapeHtml(t.verify.algorithm || 'sha256') + ', ' + escapeHtml(t.verify.encoding || 'hex') + ')'
|
|
@@ -1617,7 +1615,6 @@ ${consoleShellScript}
|
|
|
1617
1615
|
'<button type="button" class="primary hook-secret-save">Add and turn on</button></div></li>' +
|
|
1618
1616
|
'</ol>'
|
|
1619
1617
|
: (shownUrl ? hookUrlHtml(shownUrl) : '')) +
|
|
1620
|
-
(last ? '<ul class="schedule-history">' + last + '</ul>' : '<p class="hint" style="margin:2px 0">No deliveries yet.</p>') +
|
|
1621
1618
|
'<div style="display:flex;gap:6px;flex-wrap:wrap;margin-top:4px">' +
|
|
1622
1619
|
(needsSecret ? '' : '<button type="button" class="hook-toggle">' + (t.enabled ? 'Turn off' : 'Turn on') + '</button>') +
|
|
1623
1620
|
'<button type="button" class="hook-rotate">New URL</button>' +
|
|
@@ -1771,21 +1768,18 @@ ${consoleShellScript}
|
|
|
1771
1768
|
w.webhooksOff = list.length - w.webhooks - w.webhooksWaiting;
|
|
1772
1769
|
var chips = card.querySelector('.wf-chips');
|
|
1773
1770
|
if (chips) chips.innerHTML = workflowStatusChips(w);
|
|
1774
|
-
var
|
|
1775
|
-
if (
|
|
1776
|
-
if (addBox) addBox.hidden = list.length > 0;
|
|
1771
|
+
var startsCell = card.querySelector('.wf-row-starts');
|
|
1772
|
+
if (startsCell) startsCell.innerHTML = workflowStartsSummary(w);
|
|
1777
1773
|
// One waiting for its secret, or just made: open the Run options
|
|
1778
1774
|
// row it's in, so its steps show.
|
|
1779
1775
|
var row = box.closest('details');
|
|
1780
1776
|
if (row && (shownId || w.webhooksWaiting)) row.open = true;
|
|
1781
1777
|
var setupPending = list.some(function (t) { return t.verify && !t.verify.secret_set; });
|
|
1778
|
+
// Finish a planned webhook's setup before offering a second one:
|
|
1779
|
+
// + Webhook beside + Schedule waits until then.
|
|
1780
|
+
if (addBox) addBox.hidden = setupPending;
|
|
1782
1781
|
box.innerHTML = list.map(function (t) { return hookRowHtml(t, t.trigger_id === shownId ? shownUrl : null); }).join('') +
|
|
1783
|
-
|
|
1784
|
-
(list.length
|
|
1785
|
-
? (setupPending
|
|
1786
|
-
? '<p class="hint" style="margin:8px 0 0">Finish setting up the webhook above before adding another.</p>'
|
|
1787
|
-
: '<div style="margin-top:10px"><button type="button" class="hook-add-another">Add another webhook</button></div>')
|
|
1788
|
-
: '');
|
|
1782
|
+
(setupPending ? '<p class="hint" style="margin:8px 0 0">Finish setting up the webhook above before adding another.</p>' : '');
|
|
1789
1783
|
wire();
|
|
1790
1784
|
});
|
|
1791
1785
|
}
|
|
@@ -1831,10 +1825,6 @@ ${consoleShellScript}
|
|
|
1831
1825
|
});
|
|
1832
1826
|
})(rows[i]);
|
|
1833
1827
|
}
|
|
1834
|
-
var addButton = box.querySelector('.hook-add-another');
|
|
1835
|
-
if (addButton) addButton.addEventListener('click', function () {
|
|
1836
|
-
openHookFormDialog(w, base, function (url, id) { render(url, id); });
|
|
1837
|
-
});
|
|
1838
1828
|
}
|
|
1839
1829
|
render(shown ? shown.url : null, shown ? shown.id : null);
|
|
1840
1830
|
}
|
|
@@ -1888,18 +1878,8 @@ ${consoleShellScript}
|
|
|
1888
1878
|
focusScheduleRow();
|
|
1889
1879
|
});
|
|
1890
1880
|
}
|
|
1891
|
-
//
|
|
1892
|
-
|
|
1893
|
-
for (var hq = 0; hq < helps.length; hq++) {
|
|
1894
|
-
helps[hq].addEventListener('click', function (ev) {
|
|
1895
|
-
var btn = ev.currentTarget;
|
|
1896
|
-
var text = btn.closest('.wf-start').querySelector('.help-text');
|
|
1897
|
-
text.hidden = !text.hidden;
|
|
1898
|
-
btn.setAttribute('aria-expanded', String(!text.hidden));
|
|
1899
|
-
});
|
|
1900
|
-
}
|
|
1901
|
-
// Shown only while it has none: straight to the form; once one is made,
|
|
1902
|
-
// it's listed in the tile with its setup steps.
|
|
1881
|
+
// + Webhook, beside + Schedule: straight to the form; once made, it's
|
|
1882
|
+
// listed in the trigger row with its setup steps.
|
|
1903
1883
|
card.querySelector('.workflow-hooks-btn').addEventListener('click', function () {
|
|
1904
1884
|
var w = workflowsById[id];
|
|
1905
1885
|
if (!w) return;
|
|
@@ -1181,7 +1181,7 @@ ${consoleShellScript}
|
|
|
1181
1181
|
box.innerHTML = intro +
|
|
1182
1182
|
'<form id="policiesForm" style="display:flex;flex-direction:column;gap:10px;max-width:720px">' +
|
|
1183
1183
|
'<label for="policiesText" class="hint">One rule per line, with its real numbers</label>' +
|
|
1184
|
-
'<textarea id="policiesText" rows="8" placeholder="- Refunds within 30 days of
|
|
1184
|
+
'<textarea id="policiesText" rows="8" placeholder="- Refunds within 30 days of purchase. - Never share customer details with other customers. - Reply in the language the customer wrote in. - Sign emails: The Support Team">' + escapeHtml(p.policies || '') + '</textarea>' +
|
|
1185
1185
|
'<div><button type="submit" class="primary">Save</button></div>' +
|
|
1186
1186
|
'<div id="policiesMsg" class="hint"></div>' +
|
|
1187
1187
|
'</form>';
|
|
@@ -466,7 +466,10 @@ ${consoleShellScript}
|
|
|
466
466
|
trigger.push(esc(SENDERS[w.sender] || w.sender) + ' webhook' + (w.filter ? ', <code>' + esc(w.filter.values.join(' | ')) + '</code>' : ''));
|
|
467
467
|
Object.keys(w.mapping || {}).forEach(function (k) { trigger.push('<span class="wf-cb-indent"><code>' + esc(k) + '</code> ' + String.fromCharCode(8592) + ' <code>' + esc(w.mapping[k]) + '</code></span>'); });
|
|
468
468
|
}
|
|
469
|
-
|
|
469
|
+
// Any workflow can also be started by hand or by an app: said as an
|
|
470
|
+
// extra, not as a trigger, and without one it can still be given a
|
|
471
|
+
// schedule or a webhook.
|
|
472
|
+
trigger.push('<span class="hint">' + (trigger.length ? 'also by hand (Run now) or from an app (API)' : 'it runs when started by hand (Run now) or from an app (API); a schedule or webhook can be set up once it' + String.fromCharCode(8217) + 's created') + '</span>');
|
|
470
473
|
var names = Object.keys(p.parameters || {});
|
|
471
474
|
var inputs = names.length ? names.map(function (n) { return '<code>' + esc(n) + '</code>' + (p.parameters[n].required ? ' (required)' : ''); }) : ['<span class="hint">none: every run is the same</span>'];
|
|
472
475
|
var groups = { allow: [], ask: [], deny: [] };
|