@blackbelt-technology/pi-dashboard-flows-plugin 0.10.0 → 0.12.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/README.md +5 -1
- package/package.json +33 -4
- package/src/bridge/flow-catalog-publisher.ts +138 -0
- package/src/bridge/flow-event-forward.ts +132 -0
- package/src/bridge/flow-files-reporter.ts +16 -14
- package/src/bridge/flow-open-tool.ts +124 -0
- package/src/bridge/flow-probe.ts +20 -0
- package/src/bridge/flow-tool-registry.ts +298 -0
- package/src/bridge/flow-tools-guideline.ts +52 -0
- package/src/bridge/index.ts +67 -10
- package/src/bridge/run-snapshot-reporter.ts +146 -0
- package/src/catalog-timings.ts +70 -0
- package/src/client/AskSession.tsx +82 -0
- package/src/client/FlowActionDialogs.tsx +143 -0
- package/src/client/FlowActivityBadge.tsx +47 -9
- package/src/client/FlowAgentCard.tsx +63 -8
- package/src/client/FlowAgentDetail.tsx +3 -5
- package/src/client/FlowDashboard.tsx +381 -273
- package/src/client/FlowEditMenu.tsx +69 -0
- package/src/client/FlowEditPopover.tsx +130 -0
- package/src/client/FlowGraph.tsx +127 -44
- package/src/client/FlowHeaderActions.tsx +83 -0
- package/src/client/FlowInputWiring.tsx +1 -1
- package/src/client/FlowOpenListener.tsx +82 -0
- package/src/client/FlowQuestionBlock.tsx +226 -0
- package/src/client/FlowStepCards.tsx +189 -0
- package/src/client/FlowSummary.tsx +72 -240
- package/src/client/FlowWriteToolRenderer.tsx +46 -17
- package/src/client/FlowYamlPopoverButton.tsx +2 -2
- package/src/client/FlowsContextGroup.tsx +156 -0
- package/src/client/FlowsSessionStateContext.tsx +202 -54
- package/src/client/FlowsSettings.tsx +145 -18
- package/src/client/SessionFlowActions.tsx +65 -10
- package/src/client/SessionFlowMenuClaim.tsx +48 -248
- package/src/client/ask-session-store.ts +243 -0
- package/src/client/flow-attach-store.ts +2 -0
- package/src/client/flow-card-grid.ts +2 -2
- package/src/client/flow-collapse-storage.ts +36 -6
- package/src/client/flow-edges.ts +91 -35
- package/src/client/flow-files.ts +16 -4
- package/src/client/flow-idle-state.ts +93 -37
- package/src/client/flowsActionsGate.ts +1 -1
- package/src/client/flowsAvailability.ts +8 -2
- package/src/client/index.tsx +13 -11
- package/src/client/shouldRender.ts +1 -1
- package/src/client/useEditModeState.ts +78 -0
- package/src/client/useFlowActions.tsx +191 -0
- package/src/client/useFlowCatalog.ts +69 -0
- package/src/client/useMinuteClock.ts +21 -0
- package/src/client/useRunReattach.ts +50 -0
- package/src/configSchema.json +37 -2
- package/src/flow-catalog-contract.ts +65 -0
- package/src/flow-questions.ts +138 -0
- package/src/flow-reducer.ts +434 -13
- package/src/flow-state-serialize.ts +132 -0
- package/src/i18n.ts +144 -6
- package/src/server/automation-actions.ts +4 -3
- package/src/server/edit-mode.ts +307 -0
- package/src/server/flow-catalog.ts +127 -0
- package/src/server/flow-control.ts +263 -0
- package/src/server/flow-files.ts +140 -14
- package/src/server/flow-inputs.ts +56 -1
- package/src/server/flow-open.ts +385 -0
- package/src/server/index.ts +123 -40
- package/src/server/render-actions.ts +3 -2
- package/src/server/state-store.ts +11 -5
- package/src/types.ts +180 -0
- package/src/bridge/flow-question-adapter.ts +0 -93
- package/src/client/FlowQuestionCard.tsx +0 -218
- package/src/client/FlowQuestionTranscriptPill.tsx +0 -58
- package/src/client/FlowsCommandRoutes.tsx +0 -245
- package/src/client/flow-yaml-parse.ts +0 -140
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FlowQuestionCard — renders a pending `flow-question` prompt inside
|
|
3
|
-
* FlowDashboard's upper slot, above the agent grid.
|
|
4
|
-
*
|
|
5
|
-
* Routes to the appropriate input affordance based on the prompt's
|
|
6
|
-
* `type` (`confirm` / `select` / `multiselect` / `input`). On submit,
|
|
7
|
-
* dispatches `prompt_response` via the plugin's send fn. On dismiss,
|
|
8
|
-
* dispatches `prompt_cancel`.
|
|
9
|
-
*
|
|
10
|
-
* V1 inlines minimal renderers for the 4 prompt types. Extracting these
|
|
11
|
-
* into shared UI primitives is tracked as follow-up tech debt — for now
|
|
12
|
-
* each renderer is ~10 LOC and the duplication is contained.
|
|
13
|
-
*
|
|
14
|
-
* See change: route-flow-asks-to-upper-slot.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
18
|
-
import { mdiClose, mdiHelpCircleOutline } from "@mdi/js";
|
|
19
|
-
import { Icon } from "@mdi/react";
|
|
20
|
-
import React, { useState } from "react";
|
|
21
|
-
|
|
22
|
-
export interface FlowQuestionCardProps {
|
|
23
|
-
sessionId: string;
|
|
24
|
-
promptId: string;
|
|
25
|
-
flowId: string;
|
|
26
|
-
stepId: string;
|
|
27
|
-
question: string;
|
|
28
|
-
type: "select" | "input" | "confirm" | "editor" | "multiselect";
|
|
29
|
-
options?: string[];
|
|
30
|
-
defaultValue?: string;
|
|
31
|
-
/** Number of queued questions for this flow (head + queue). 0 or 1 hides the badge. */
|
|
32
|
-
queueDepth: number;
|
|
33
|
-
/** Dispatch `prompt_response`. */
|
|
34
|
-
onSubmit: (answer: string) => void;
|
|
35
|
-
/** Dispatch `prompt_cancel`. */
|
|
36
|
-
onDismiss: () => void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function FlowQuestionCard({
|
|
40
|
-
question,
|
|
41
|
-
type,
|
|
42
|
-
options,
|
|
43
|
-
defaultValue,
|
|
44
|
-
queueDepth,
|
|
45
|
-
onSubmit,
|
|
46
|
-
onDismiss,
|
|
47
|
-
}: FlowQuestionCardProps) {
|
|
48
|
-
const t = useT();
|
|
49
|
-
return (
|
|
50
|
-
<div
|
|
51
|
-
data-testid="flow-question-card"
|
|
52
|
-
data-widget-bar-slot=""
|
|
53
|
-
tabIndex={-1}
|
|
54
|
-
className="mt-2 mb-2 p-3 border border-purple-500/40 bg-purple-500/5 rounded"
|
|
55
|
-
>
|
|
56
|
-
<div className="flex items-start gap-2 mb-2">
|
|
57
|
-
<Icon path={mdiHelpCircleOutline} size={0.7} className="text-purple-400 flex-shrink-0 mt-0.5" />
|
|
58
|
-
<div className="flex-1 min-w-0">
|
|
59
|
-
<div className="text-sm text-[var(--text-primary)] font-medium">{question}</div>
|
|
60
|
-
</div>
|
|
61
|
-
{queueDepth > 1 && (
|
|
62
|
-
<span className="text-[10px] text-purple-300 bg-purple-500/20 px-1.5 py-0.5 rounded flex-shrink-0">
|
|
63
|
-
+{queueDepth - 1} more queued
|
|
64
|
-
</span>
|
|
65
|
-
)}
|
|
66
|
-
<button
|
|
67
|
-
onClick={onDismiss}
|
|
68
|
-
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] flex-shrink-0"
|
|
69
|
-
title={t("dismiss", undefined, "Dismiss")}
|
|
70
|
-
>
|
|
71
|
-
<Icon path={mdiClose} size={0.6} />
|
|
72
|
-
</button>
|
|
73
|
-
</div>
|
|
74
|
-
<FlowQuestionInput
|
|
75
|
-
type={type}
|
|
76
|
-
options={options}
|
|
77
|
-
defaultValue={defaultValue}
|
|
78
|
-
onSubmit={onSubmit}
|
|
79
|
-
/>
|
|
80
|
-
</div>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function FlowQuestionInput({
|
|
85
|
-
type,
|
|
86
|
-
options,
|
|
87
|
-
defaultValue,
|
|
88
|
-
onSubmit,
|
|
89
|
-
}: {
|
|
90
|
-
type: FlowQuestionCardProps["type"];
|
|
91
|
-
options?: string[];
|
|
92
|
-
defaultValue?: string;
|
|
93
|
-
onSubmit: (answer: string) => void;
|
|
94
|
-
}) {
|
|
95
|
-
if (type === "confirm") return <ConfirmRow onSubmit={onSubmit} />;
|
|
96
|
-
if (type === "select") return <SelectRow options={options ?? []} onSubmit={onSubmit} />;
|
|
97
|
-
if (type === "multiselect") return <MultiselectRow options={options ?? []} onSubmit={onSubmit} />;
|
|
98
|
-
return <InputRow defaultValue={defaultValue} onSubmit={onSubmit} />;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function ConfirmRow({ onSubmit }: { onSubmit: (answer: string) => void }) {
|
|
102
|
-
return (
|
|
103
|
-
<div className="flex gap-2 justify-end">
|
|
104
|
-
<button
|
|
105
|
-
onClick={() => onSubmit("no")}
|
|
106
|
-
className="px-3 py-1 text-xs rounded border border-[var(--border-primary)] hover:bg-[var(--bg-surface)]"
|
|
107
|
-
>
|
|
108
|
-
No
|
|
109
|
-
</button>
|
|
110
|
-
<button
|
|
111
|
-
onClick={() => onSubmit("yes")}
|
|
112
|
-
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600"
|
|
113
|
-
>
|
|
114
|
-
Yes
|
|
115
|
-
</button>
|
|
116
|
-
</div>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function SelectRow({
|
|
121
|
-
options,
|
|
122
|
-
onSubmit,
|
|
123
|
-
}: {
|
|
124
|
-
options: string[];
|
|
125
|
-
onSubmit: (answer: string) => void;
|
|
126
|
-
}) {
|
|
127
|
-
return (
|
|
128
|
-
<div className="flex flex-wrap gap-1.5">
|
|
129
|
-
{options.map((opt) => (
|
|
130
|
-
<button
|
|
131
|
-
key={opt}
|
|
132
|
-
onClick={() => onSubmit(opt)}
|
|
133
|
-
className="px-2.5 py-1 text-xs rounded border border-[var(--border-primary)] hover:bg-purple-500/10 hover:border-purple-500/40"
|
|
134
|
-
>
|
|
135
|
-
{opt}
|
|
136
|
-
</button>
|
|
137
|
-
))}
|
|
138
|
-
</div>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function MultiselectRow({
|
|
143
|
-
options,
|
|
144
|
-
onSubmit,
|
|
145
|
-
}: {
|
|
146
|
-
options: string[];
|
|
147
|
-
onSubmit: (answer: string) => void;
|
|
148
|
-
}) {
|
|
149
|
-
const [picked, setPicked] = useState<Set<string>>(new Set());
|
|
150
|
-
const toggle = (opt: string) =>
|
|
151
|
-
setPicked((prev) => {
|
|
152
|
-
const next = new Set(prev);
|
|
153
|
-
if (next.has(opt)) next.delete(opt);
|
|
154
|
-
else next.add(opt);
|
|
155
|
-
return next;
|
|
156
|
-
});
|
|
157
|
-
return (
|
|
158
|
-
<div className="space-y-2">
|
|
159
|
-
<div className="flex flex-wrap gap-1.5">
|
|
160
|
-
{options.map((opt) => (
|
|
161
|
-
<button
|
|
162
|
-
key={opt}
|
|
163
|
-
onClick={() => toggle(opt)}
|
|
164
|
-
className={`px-2.5 py-1 text-xs rounded border ${
|
|
165
|
-
picked.has(opt)
|
|
166
|
-
? "bg-purple-500/20 border-purple-500"
|
|
167
|
-
: "border-[var(--border-primary)] hover:bg-purple-500/10 hover:border-purple-500/40"
|
|
168
|
-
}`}
|
|
169
|
-
>
|
|
170
|
-
{opt}
|
|
171
|
-
</button>
|
|
172
|
-
))}
|
|
173
|
-
</div>
|
|
174
|
-
<div className="flex justify-end">
|
|
175
|
-
<button
|
|
176
|
-
onClick={() => onSubmit(JSON.stringify(Array.from(picked)))}
|
|
177
|
-
disabled={picked.size === 0}
|
|
178
|
-
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
179
|
-
>
|
|
180
|
-
Submit ({picked.size})
|
|
181
|
-
</button>
|
|
182
|
-
</div>
|
|
183
|
-
</div>
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function InputRow({
|
|
188
|
-
defaultValue,
|
|
189
|
-
onSubmit,
|
|
190
|
-
}: {
|
|
191
|
-
defaultValue?: string;
|
|
192
|
-
onSubmit: (answer: string) => void;
|
|
193
|
-
}) {
|
|
194
|
-
const [val, setVal] = useState(defaultValue ?? "");
|
|
195
|
-
return (
|
|
196
|
-
<form
|
|
197
|
-
onSubmit={(e) => {
|
|
198
|
-
e.preventDefault();
|
|
199
|
-
onSubmit(val);
|
|
200
|
-
}}
|
|
201
|
-
className="flex gap-2"
|
|
202
|
-
>
|
|
203
|
-
<input
|
|
204
|
-
autoFocus
|
|
205
|
-
type="text"
|
|
206
|
-
value={val}
|
|
207
|
-
onChange={(e) => setVal(e.target.value)}
|
|
208
|
-
className="flex-1 px-2 py-1 text-xs bg-[var(--bg-surface)] border border-[var(--border-primary)] rounded focus:outline-none focus:border-purple-500"
|
|
209
|
-
/>
|
|
210
|
-
<button
|
|
211
|
-
type="submit"
|
|
212
|
-
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600"
|
|
213
|
-
>
|
|
214
|
-
Submit
|
|
215
|
-
</button>
|
|
216
|
-
</form>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FlowQuestionTranscriptPill — collapsed pill rendering an answered or
|
|
3
|
-
* cancelled flow-question prompt in the FlowDashboard upper-slot
|
|
4
|
-
* transcript. The pending head is rendered by FlowQuestionCard; this
|
|
5
|
-
* pill covers everything else (resolved / cancelled / dismissed).
|
|
6
|
-
*
|
|
7
|
-
* See change: fix-flows-plugin-polish (C3).
|
|
8
|
-
*/
|
|
9
|
-
import React from "react";
|
|
10
|
-
import { Icon } from "@mdi/react";
|
|
11
|
-
import { mdiCheckCircle, mdiCloseCircle, mdiHelpCircleOutline } from "@mdi/js";
|
|
12
|
-
|
|
13
|
-
export interface FlowQuestionTranscriptPillProps {
|
|
14
|
-
question: string;
|
|
15
|
-
/** Resolved answer (string for non-multiselect, JSON array for multiselect). */
|
|
16
|
-
answer?: string;
|
|
17
|
-
status: "resolved" | "cancelled" | "dismissed" | "pending";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function FlowQuestionTranscriptPill({
|
|
21
|
-
question,
|
|
22
|
-
answer,
|
|
23
|
-
status,
|
|
24
|
-
}: FlowQuestionTranscriptPillProps) {
|
|
25
|
-
const { iconPath, color } =
|
|
26
|
-
status === "resolved"
|
|
27
|
-
? { iconPath: mdiCheckCircle, color: "text-green-400" }
|
|
28
|
-
: status === "cancelled" || status === "dismissed"
|
|
29
|
-
? { iconPath: mdiCloseCircle, color: "text-[var(--text-muted)]" }
|
|
30
|
-
: { iconPath: mdiHelpCircleOutline, color: "text-purple-400" };
|
|
31
|
-
|
|
32
|
-
const displayAnswer = (() => {
|
|
33
|
-
if (typeof answer !== "string") return null;
|
|
34
|
-
// For multiselect answers stored as JSON array, render compactly.
|
|
35
|
-
try {
|
|
36
|
-
const parsed = JSON.parse(answer);
|
|
37
|
-
if (Array.isArray(parsed)) return parsed.join(", ");
|
|
38
|
-
} catch {
|
|
39
|
-
// fall through
|
|
40
|
-
}
|
|
41
|
-
return answer;
|
|
42
|
-
})();
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<div
|
|
46
|
-
data-testid="flow-question-transcript-pill"
|
|
47
|
-
className="mt-1 px-2 py-1 border border-[var(--border-subtle)] bg-[var(--bg-tertiary)] rounded text-[11px] flex items-center gap-2"
|
|
48
|
-
>
|
|
49
|
-
<Icon path={iconPath} size={0.45} className={`${color} flex-shrink-0`} />
|
|
50
|
-
<span className="text-[var(--text-secondary)] truncate flex-1 min-w-0">{question}</span>
|
|
51
|
-
{displayAnswer && (
|
|
52
|
-
<span className={`${color} font-medium truncate flex-shrink-0 max-w-[40%]`}>
|
|
53
|
-
→ {displayAnswer}
|
|
54
|
-
</span>
|
|
55
|
-
)}
|
|
56
|
-
</div>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slash-command route components for /flows, /flows:new,
|
|
3
|
-
* /flows:edit, /flows:delete. Each renders the appropriate launcher /
|
|
4
|
-
* picker / dialog, dispatches via pluginContext.send, and calls
|
|
5
|
-
* `onClose` on dismissal so the shell's command-route slot consumer
|
|
6
|
-
* navigates back.
|
|
7
|
-
*
|
|
8
|
-
* Replaces the four flow dialog blocks in App.tsx (lines 1199-1313)
|
|
9
|
-
* once the shell deletes them in Part H.
|
|
10
|
-
*
|
|
11
|
-
* See change: pluginize-flows-via-registry.
|
|
12
|
-
*/
|
|
13
|
-
import React, { useState } from "react";
|
|
14
|
-
import type {
|
|
15
|
-
CommandInfo,
|
|
16
|
-
DashboardSession,
|
|
17
|
-
FlowInfo,
|
|
18
|
-
} from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
19
|
-
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
20
|
-
import type { UiSelectOption as SelectOption } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
21
|
-
import {
|
|
22
|
-
useUiPrimitive,
|
|
23
|
-
usePluginSend,
|
|
24
|
-
useSessionData,
|
|
25
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
26
|
-
import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
|
|
27
|
-
import { makeSafeSend, type PluginSend } from "./send-safe.js";
|
|
28
|
-
|
|
29
|
-
// ── Helpers ────────────────────────────────────────────────────────
|
|
30
|
-
|
|
31
|
-
// Every flow action routes through here, so the discard is stated once at the
|
|
32
|
-
// shared seam rather than at each of the five call sites. A dropped
|
|
33
|
-
// `flow_management` message otherwise leaves the UI showing a run the server
|
|
34
|
-
// never started. See change: cleanup-client-plugin-promises.
|
|
35
|
-
function dispatchFlowAction(
|
|
36
|
-
send: PluginSend,
|
|
37
|
-
sessionId: string,
|
|
38
|
-
action: string,
|
|
39
|
-
opts?: { flowName?: string; task?: string; description?: string },
|
|
40
|
-
): void {
|
|
41
|
-
makeSafeSend(send)({
|
|
42
|
-
type: "flow_management",
|
|
43
|
-
sessionId,
|
|
44
|
-
action,
|
|
45
|
-
flowName: opts?.flowName,
|
|
46
|
-
task: opts?.task,
|
|
47
|
-
description: opts?.description,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
interface RouteProps {
|
|
52
|
-
session: DashboardSession;
|
|
53
|
-
routeParams: Record<string, string>;
|
|
54
|
-
onClose: () => void;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// ── /flows — main picker ───────────────────────────────────────────
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Three-state machine: pick → launch (taskRequired) | direct-run.
|
|
61
|
-
* When the user picks a flow, either run it (no task required) and
|
|
62
|
-
* close, or open the launch dialog to capture a task.
|
|
63
|
-
*/
|
|
64
|
-
export function FlowsListRoute({ session, onClose }: RouteProps) {
|
|
65
|
-
const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
|
|
66
|
-
const send = usePluginSend();
|
|
67
|
-
// Dialog `onSelect` cannot own the send promise — discard it explicitly.
|
|
68
|
-
// See change: cleanup-client-plugin-promises.
|
|
69
|
-
const dispatch = makeSafeSend(send);
|
|
70
|
-
const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
|
|
71
|
-
const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
|
|
72
|
-
const [launchTarget, setLaunchTarget] = useState<FlowInfo | null>(null);
|
|
73
|
-
|
|
74
|
-
const hasFlowsNew = commands.some((c) => c.name === "flows:new");
|
|
75
|
-
const hasFlowsEdit = commands.some((c) => c.name === "flows:edit");
|
|
76
|
-
const hasFlowsDelete = commands.some((c) => c.name === "flows:delete");
|
|
77
|
-
|
|
78
|
-
if (launchTarget) {
|
|
79
|
-
return (
|
|
80
|
-
<FlowLaunchDialog
|
|
81
|
-
flowName={launchTarget.name}
|
|
82
|
-
description={launchTarget.description}
|
|
83
|
-
session={session}
|
|
84
|
-
onSubmit={(task) => {
|
|
85
|
-
dispatchFlowAction(send, session.id, "run", {
|
|
86
|
-
flowName: launchTarget.name,
|
|
87
|
-
task: task || undefined,
|
|
88
|
-
});
|
|
89
|
-
onClose();
|
|
90
|
-
}}
|
|
91
|
-
onCancel={() => {
|
|
92
|
-
setLaunchTarget(null);
|
|
93
|
-
onClose();
|
|
94
|
-
}}
|
|
95
|
-
/>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const flowOptions: SelectOption[] = [
|
|
100
|
-
...(hasFlowsNew
|
|
101
|
-
? [{ value: "__new__", label: "+ New Flow", description: "Design a new flow with the Flow Architect" }]
|
|
102
|
-
: []),
|
|
103
|
-
...(hasFlowsEdit && flows.length > 0
|
|
104
|
-
? [{ value: "__edit__", label: "\u270E\uFE0E Edit Flow...", description: "Edit an existing flow" }]
|
|
105
|
-
: []),
|
|
106
|
-
...(hasFlowsDelete && flows.length > 0
|
|
107
|
-
? [{ value: "__delete__", label: "\u00D7 Delete Flow...", description: "Delete a saved flow" }]
|
|
108
|
-
: []),
|
|
109
|
-
...flows.map((f) => ({ value: f.name, label: f.name, description: f.description })),
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<SearchableSelectDialog
|
|
114
|
-
title="Flows"
|
|
115
|
-
options={flowOptions}
|
|
116
|
-
placeholder="Search flows..."
|
|
117
|
-
emptyMessage="No flows available"
|
|
118
|
-
onSelect={(value) => {
|
|
119
|
-
if (value === "__new__") {
|
|
120
|
-
// Send the user to the /flows:new route via pluginRouter.
|
|
121
|
-
// Until pluginRouter wiring lands, just open the new dialog
|
|
122
|
-
// inline by closing this and dispatching the new command.
|
|
123
|
-
dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:new" });
|
|
124
|
-
onClose();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (value === "__edit__") {
|
|
128
|
-
dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:edit" });
|
|
129
|
-
onClose();
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (value === "__delete__") {
|
|
133
|
-
dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:delete" });
|
|
134
|
-
onClose();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const flow = flows.find((f) => f.name === value);
|
|
138
|
-
if (!flow) {
|
|
139
|
-
onClose();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (flow.taskRequired) {
|
|
143
|
-
setLaunchTarget(flow);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
dispatchFlowAction(send, session.id, "run", { flowName: flow.name });
|
|
147
|
-
onClose();
|
|
148
|
-
}}
|
|
149
|
-
onCancel={onClose}
|
|
150
|
-
/>
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// ── /flows:new ─────────────────────────────────────────────────────
|
|
155
|
-
|
|
156
|
-
export function FlowsNewRoute({ session, onClose }: RouteProps) {
|
|
157
|
-
const send = usePluginSend();
|
|
158
|
-
return (
|
|
159
|
-
<FlowLaunchDialog
|
|
160
|
-
flowName="flows:new"
|
|
161
|
-
description="Design a new flow with the Flow Architect"
|
|
162
|
-
onSubmit={(task) => {
|
|
163
|
-
if (task.trim()) {
|
|
164
|
-
dispatchFlowAction(send, session.id, "new", { description: task.trim() });
|
|
165
|
-
}
|
|
166
|
-
onClose();
|
|
167
|
-
}}
|
|
168
|
-
onCancel={onClose}
|
|
169
|
-
/>
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// ── /flows:edit ────────────────────────────────────────────────────
|
|
174
|
-
|
|
175
|
-
export function FlowsEditRoute({ session, onClose }: RouteProps) {
|
|
176
|
-
const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
|
|
177
|
-
const send = usePluginSend();
|
|
178
|
-
const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
|
|
179
|
-
const [editTarget, setEditTarget] = useState<string | null>(null);
|
|
180
|
-
|
|
181
|
-
if (editTarget) {
|
|
182
|
-
return (
|
|
183
|
-
<FlowLaunchDialog
|
|
184
|
-
flowName={editTarget}
|
|
185
|
-
description="Describe how this flow should be updated"
|
|
186
|
-
onSubmit={(desc) => {
|
|
187
|
-
if (desc.trim()) {
|
|
188
|
-
dispatchFlowAction(send, session.id, "edit", {
|
|
189
|
-
flowName: editTarget,
|
|
190
|
-
description: desc.trim(),
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
onClose();
|
|
194
|
-
}}
|
|
195
|
-
onCancel={onClose}
|
|
196
|
-
/>
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return (
|
|
201
|
-
<SearchableSelectDialog
|
|
202
|
-
title="Edit Flow"
|
|
203
|
-
options={flows.map((f) => ({ value: f.name, label: f.name, description: f.description }))}
|
|
204
|
-
placeholder="Search flows..."
|
|
205
|
-
emptyMessage="No flows available"
|
|
206
|
-
onSelect={(value) => setEditTarget(value)}
|
|
207
|
-
onCancel={onClose}
|
|
208
|
-
/>
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// ── /flows:delete ──────────────────────────────────────────────────
|
|
213
|
-
|
|
214
|
-
export function FlowsDeleteRoute({ session, onClose }: RouteProps) {
|
|
215
|
-
const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
|
|
216
|
-
const ConfirmDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.confirmDialog);
|
|
217
|
-
const send = usePluginSend();
|
|
218
|
-
const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
|
|
219
|
-
const [deleteTarget, setDeleteTarget] = useState<string | null>(null);
|
|
220
|
-
|
|
221
|
-
if (deleteTarget) {
|
|
222
|
-
return (
|
|
223
|
-
<ConfirmDialog
|
|
224
|
-
message={`Delete flow "${deleteTarget}"? This will remove the flow file and any associated agents.`}
|
|
225
|
-
confirmLabel="Delete"
|
|
226
|
-
onConfirm={() => {
|
|
227
|
-
dispatchFlowAction(send, session.id, "delete", { flowName: deleteTarget });
|
|
228
|
-
onClose();
|
|
229
|
-
}}
|
|
230
|
-
onCancel={onClose}
|
|
231
|
-
/>
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return (
|
|
236
|
-
<SearchableSelectDialog
|
|
237
|
-
title="Delete Flow"
|
|
238
|
-
options={flows.map((f) => ({ value: f.name, label: f.name, description: f.description }))}
|
|
239
|
-
placeholder="Search flows..."
|
|
240
|
-
emptyMessage="No flows available"
|
|
241
|
-
onSelect={(value) => setDeleteTarget(value)}
|
|
242
|
-
onCancel={onClose}
|
|
243
|
-
/>
|
|
244
|
-
);
|
|
245
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shallow client-side parser for a flow YAML document, used by the
|
|
3
|
-
* `flow_write` tool renderer to build a Mermaid snapshot + step/agent/code
|
|
4
|
-
* counts from the tool ARGS (the submitted `content`). The tool result
|
|
5
|
-
* carries no parsed steps, so we parse the args here.
|
|
6
|
-
*
|
|
7
|
-
* Intentionally shallow + graceful: it extracts only what the snapshot needs
|
|
8
|
-
* (id, type, blockedBy, branches) and returns null on any parse failure so the
|
|
9
|
-
* renderer degrades to the plain success state without erroring.
|
|
10
|
-
*
|
|
11
|
-
* See change: rework-flows-plugin-for-new-pi-flows.
|
|
12
|
-
*/
|
|
13
|
-
import { parse as parseYaml } from "yaml";
|
|
14
|
-
import { deriveFlowEdges, type FlowEdgeStep } from "./flow-edges.js";
|
|
15
|
-
|
|
16
|
-
export interface ParsedFlowStep {
|
|
17
|
-
id: string;
|
|
18
|
-
/** Node kind from the flow `type:` field (agent | code | code-decision | …). */
|
|
19
|
-
type: string;
|
|
20
|
-
blockedBy: string[];
|
|
21
|
-
/** Decision branch label → target step id (code-decision / agent-decision). */
|
|
22
|
-
branches?: Record<string, string>;
|
|
23
|
-
onComplete?: string;
|
|
24
|
-
onError?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ParsedFlow {
|
|
28
|
-
name?: string;
|
|
29
|
-
steps: ParsedFlowStep[];
|
|
30
|
-
counts: { total: number; agents: number; code: number };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function asStringArray(v: unknown): string[] {
|
|
34
|
-
if (Array.isArray(v)) return v.filter((x): x is string => typeof x === "string");
|
|
35
|
-
if (typeof v === "string") return [v];
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Parse a flow YAML string into a shallow step model. Returns null on failure. */
|
|
40
|
-
export function parseFlowYaml(content: string): ParsedFlow | null {
|
|
41
|
-
let doc: unknown;
|
|
42
|
-
try {
|
|
43
|
-
doc = parseYaml(content);
|
|
44
|
-
} catch {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
if (!doc || typeof doc !== "object") return null;
|
|
48
|
-
const root = doc as Record<string, unknown>;
|
|
49
|
-
const rawSteps = root.steps;
|
|
50
|
-
if (!Array.isArray(rawSteps)) return null;
|
|
51
|
-
|
|
52
|
-
const steps: ParsedFlowStep[] = [];
|
|
53
|
-
for (const rs of rawSteps) {
|
|
54
|
-
if (!rs || typeof rs !== "object") continue;
|
|
55
|
-
const s = rs as Record<string, unknown>;
|
|
56
|
-
const id = typeof s.id === "string" ? s.id : undefined;
|
|
57
|
-
if (!id) continue;
|
|
58
|
-
const type = typeof s.type === "string" ? s.type : "agent";
|
|
59
|
-
const branchesRaw = s.branches;
|
|
60
|
-
let branches: Record<string, string> | undefined;
|
|
61
|
-
if (branchesRaw && typeof branchesRaw === "object" && !Array.isArray(branchesRaw)) {
|
|
62
|
-
branches = {};
|
|
63
|
-
for (const [k, v] of Object.entries(branchesRaw as Record<string, unknown>)) {
|
|
64
|
-
if (typeof v === "string") branches[k] = v;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
steps.push({
|
|
68
|
-
id,
|
|
69
|
-
type,
|
|
70
|
-
blockedBy: asStringArray(s.blockedBy),
|
|
71
|
-
branches,
|
|
72
|
-
onComplete: typeof s.on_complete === "string" ? s.on_complete : undefined,
|
|
73
|
-
onError: typeof s.on_error === "string" ? s.on_error : undefined,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (steps.length === 0) return null;
|
|
77
|
-
|
|
78
|
-
const agents = steps.filter((s) => s.type === "agent" || s.type === "agent-decision").length;
|
|
79
|
-
const code = steps.filter((s) => s.type === "code" || s.type === "code-decision").length;
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
name: typeof root.name === "string" ? root.name : undefined,
|
|
83
|
-
steps,
|
|
84
|
-
counts: { total: steps.length, agents, code },
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Mermaid node shape per node type, mirroring the live FlowGraph glyphs. */
|
|
89
|
-
function nodeShape(type: string, id: string, label: string): string {
|
|
90
|
-
switch (type) {
|
|
91
|
-
case "code": return `${id}[["⌗ ${label}"]]`;
|
|
92
|
-
case "code-decision": return `${id}{"◈ ${label}"}`;
|
|
93
|
-
case "agent-decision":
|
|
94
|
-
case "fork": return `${id}{"◇ ${label}"}`;
|
|
95
|
-
default: return `${id}(["${label}"])`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Build a `graph LR` Mermaid string from a parsed flow. Edges come from the
|
|
100
|
-
* shared `deriveFlowEdges` (blockedBy + branches + on_complete/on_error +
|
|
101
|
-
* implicit-segment), so the snapshot matches the live FlowGraph. Backward
|
|
102
|
-
* edges (loops) render dashed. See change: improve-flow-ui. */
|
|
103
|
-
export function flowToMermaid(flow: ParsedFlow): string {
|
|
104
|
-
const lines: string[] = ["graph LR"];
|
|
105
|
-
for (const s of flow.steps) {
|
|
106
|
-
lines.push(` ${nodeShape(s.type, s.id, s.id)}`);
|
|
107
|
-
}
|
|
108
|
-
const edges = deriveFlowEdges(
|
|
109
|
-
flow.steps.map((s): FlowEdgeStep => ({
|
|
110
|
-
id: s.id,
|
|
111
|
-
type: s.type,
|
|
112
|
-
blockedBy: s.blockedBy,
|
|
113
|
-
branches: s.branches,
|
|
114
|
-
onComplete: s.onComplete,
|
|
115
|
-
onError: s.onError,
|
|
116
|
-
})),
|
|
117
|
-
);
|
|
118
|
-
for (const e of edges) {
|
|
119
|
-
if (e.kind === "route" && e.label === "on_error") {
|
|
120
|
-
// Topology-distinct on_error, mirroring the live FlowGraph: ↺ returning
|
|
121
|
-
// (handler rejoins the flow — a recovery loop) vs ⊗ terminal (a sink/exit).
|
|
122
|
-
// Always dashed so it reads as an exception edge, never the happy path.
|
|
123
|
-
const marker = e.routeTopology === "terminal" ? "⊗" : "↺";
|
|
124
|
-
lines.push(` ${e.from} -. "on_error ${marker}" .-> ${e.to}`);
|
|
125
|
-
} else {
|
|
126
|
-
// `on_complete` is the happy-path default — render unlabeled so an
|
|
127
|
-
// on_complete-wired flow's spine reads as plain arrows, not repeated
|
|
128
|
-
// labels (matches the live FlowGraph). See change: fix-flow-ui-graph-zoom-summary.
|
|
129
|
-
const lbl = e.label === "on_complete" ? undefined : e.label;
|
|
130
|
-
if (e.backward) {
|
|
131
|
-
lines.push(` ${e.from} -. "${lbl ?? ""} ↺" .-> ${e.to}`);
|
|
132
|
-
} else if (lbl) {
|
|
133
|
-
lines.push(` ${e.from} -->|${lbl}| ${e.to}`);
|
|
134
|
-
} else {
|
|
135
|
-
lines.push(` ${e.from} --> ${e.to}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return lines.join("\n");
|
|
140
|
-
}
|