@blackbelt-technology/pi-dashboard-flows-plugin 0.11.0 → 0.12.1
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 +23 -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 +42 -4
- 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 -17
- package/src/client/SessionFlowActions.tsx +65 -10
- package/src/client/SessionFlowMenuClaim.tsx +48 -241
- 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-open.ts +385 -0
- package/src/server/index.ts +112 -34
- 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,234 +1,94 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Summary-only sections of a completed flow, rendered by `FlowDashboard` in
|
|
3
|
+
* `summary` mode (the separate `FlowSummary` shell is gone). Exports the
|
|
4
|
+
* completion `statusConfig` map, `FlowSummaryStatus` (header status icon +
|
|
5
|
+
* label + steps · duration · files), `FlowSummarySections` (Summaries list +
|
|
6
|
+
* Next suggestion) and `FlowSummaryRow`.
|
|
7
|
+
* See change: unify-flow-rendering (D1, D3).
|
|
8
|
+
*/
|
|
9
|
+
import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
2
10
|
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
3
|
-
import type {
|
|
4
|
-
import { mdiAlertCircle, mdiCheckCircle, mdiChevronDown, mdiChevronRight, mdiCircleOutline, mdiCloseCircle,
|
|
11
|
+
import type { FlowAgentState, FlowState } from "../types.js";
|
|
12
|
+
import { mdiAlertCircle, mdiCheckCircle, mdiChevronDown, mdiChevronRight, mdiCircleOutline, mdiCloseCircle, mdiStopCircle } from "@mdi/js";
|
|
5
13
|
import { Icon } from "@mdi/react";
|
|
6
|
-
import { type ReactNode,
|
|
7
|
-
import { FlowAgentCard } from "./FlowAgentCard.js";
|
|
8
|
-
import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
|
|
9
|
-
import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
|
|
10
|
-
import { FlowYamlPopoverButton } from "./FlowYamlPopoverButton.js";
|
|
11
|
-
import { FLOW_CARD_GRID_CLASS, FLOW_CARD_GRID_CONTAINER_CLASS } from "./flow-card-grid.js";
|
|
12
|
-
import { useFlowNodeFiles, withNodeFiles } from "./flow-files.js";
|
|
13
|
-
import { useFlowCollapsePersisted } from "./flow-collapse-storage.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// formatDuration moved to registry primitive lookup inside FlowSummary
|
|
17
|
-
// (PH-2 fix from validation report).
|
|
14
|
+
import { type ReactNode, useState } from "react";
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
const statusConfig: Record<string, { icon: ReactNode; label: string; color: string }> = {
|
|
16
|
+
export const statusConfig: Record<string, { icon: ReactNode; label: string; color: string }> = {
|
|
21
17
|
success: { icon: <Icon path={mdiCheckCircle} size={0.55} />, label: "complete", color: "text-green-400" },
|
|
22
18
|
error: { icon: <Icon path={mdiAlertCircle} size={0.55} />, label: "failed", color: "text-red-400" },
|
|
23
19
|
aborted: { icon: <Icon path={mdiStopCircle} size={0.55} />, label: "aborted", color: "text-orange-400" },
|
|
24
20
|
};
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
/** Completed-flow header status: icon + "<name> complete" + steps · duration · files. */
|
|
23
|
+
export function FlowSummaryStatus({ flowState, agents }: { flowState: FlowState; agents: FlowAgentState[] }) {
|
|
24
|
+
const formatDuration = useUiPrimitive(UI_PRIMITIVE_KEYS.formatDuration);
|
|
25
|
+
const { icon, label, color } = statusConfig[flowState.status] ?? statusConfig.success;
|
|
26
|
+
const totalDuration = flowState.flowResult?.totalDuration as number | undefined;
|
|
27
|
+
const totalFiles = agents.reduce((sum, a) => sum + (a.files?.length ?? 0), 0);
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<span className={`${color} inline-flex`}>{icon}</span>
|
|
31
|
+
<span className="text-sm text-[var(--text-primary)] flex-1">
|
|
32
|
+
{flowState.flowName} {label}
|
|
33
|
+
<span className="text-[var(--text-tertiary)] ml-1.5">
|
|
34
|
+
· {agents.length} steps
|
|
35
|
+
{totalDuration ? ` · ${formatDuration(totalDuration)}` : ""}
|
|
36
|
+
{totalFiles > 0 ? ` · ${totalFiles} files` : ""}
|
|
37
|
+
</span>
|
|
38
|
+
</span>
|
|
39
|
+
</>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Summaries list (summary-bearing agents only; hidden when none qualify) and
|
|
45
|
+
* the Next: /step suggestion. Lives in the summary scroll box under the Agent
|
|
46
|
+
* cards. See changes: fix-flow-ui-graph-zoom-summary, unify-flow-rendering (D3).
|
|
47
|
+
*/
|
|
48
|
+
export function FlowSummarySections({
|
|
27
49
|
flowState,
|
|
28
|
-
|
|
50
|
+
agents,
|
|
29
51
|
onSendPrompt,
|
|
30
|
-
session,
|
|
31
|
-
sessionId,
|
|
32
52
|
}: {
|
|
33
53
|
flowState: FlowState;
|
|
34
|
-
|
|
54
|
+
agents: FlowAgentState[];
|
|
35
55
|
onSendPrompt?: (text: string) => void;
|
|
36
|
-
/** Parent session — threaded to the frozen cards for their detail/popout affordances. */
|
|
37
|
-
session?: DashboardSession;
|
|
38
|
-
sessionId?: string;
|
|
39
56
|
}) {
|
|
40
|
-
const formatDuration = useUiPrimitive(UI_PRIMITIVE_KEYS.formatDuration);
|
|
41
|
-
const Dialog = useUiPrimitiveOrNull(UI_PRIMITIVE_KEYS.dialog);
|
|
42
57
|
const [collapsed, setCollapsed] = useState(false);
|
|
43
|
-
|
|
44
|
-
// hides the Summaries list). Shrinks the completed-flow summary to its header
|
|
45
|
-
// bar, mirroring FlowDashboard's collapse affordance. See change: improve-flow-graph-fidelity.
|
|
46
|
-
// Persisted per session so a collapsed panel stays collapsed across remounts.
|
|
47
|
-
// See change: fix-flow-ui-graph-zoom-summary.
|
|
48
|
-
const [panelCollapsed, togglePanelCollapsed] = useFlowCollapsePersisted(
|
|
49
|
-
sessionId ?? session?.id,
|
|
50
|
-
"summary",
|
|
51
|
-
);
|
|
52
|
-
const [graphOpen, setGraphOpen] = useState(false);
|
|
53
|
-
// Shared graph⇄card selection (ephemeral). See change:
|
|
54
|
-
// improve-flow-graph-dialog-and-card-interaction.
|
|
55
|
-
const [selectedStepId, setSelectedStepId] = useState<string | null>(null);
|
|
56
|
-
const rootRef = useRef<HTMLDivElement>(null);
|
|
57
|
-
// Agent / handler file paths for the frozen cards' file buttons.
|
|
58
|
-
// See change: attach-flow-before-run.
|
|
59
|
-
const nodeFiles = useFlowNodeFiles(sessionId ?? session?.id);
|
|
60
|
-
const agents = Array.from(withNodeFiles(flowState, nodeFiles).agents.values());
|
|
61
|
-
// Only summary-bearing agents are listed in the Summaries subsection (others
|
|
62
|
-
// stay in the frozen cards + graph). See change: fix-flow-ui-graph-zoom-summary.
|
|
63
|
-
const summarised = agents.filter(a => a.summary);
|
|
64
|
-
const { icon, label, color } = statusConfig[flowState.status] ?? statusConfig.success;
|
|
65
|
-
const totalDuration = flowState.flowResult?.totalDuration as number | undefined;
|
|
66
|
-
const totalFiles = agents.reduce((sum, a) => sum + (a.files?.length ?? 0), 0);
|
|
67
|
-
|
|
68
|
-
const handleSelectStep = useCallback((stepId: string) => {
|
|
69
|
-
setSelectedStepId((prev) => (prev === stepId ? null : stepId));
|
|
70
|
-
}, []);
|
|
71
|
-
|
|
72
|
-
// Reset selection when the agent set changes (selection is ephemeral).
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
setSelectedStepId(null);
|
|
75
|
-
}, [flowState.agents]);
|
|
76
|
-
|
|
77
|
-
// Esc clears selection (the Dialog handles its own Esc independently).
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (!selectedStepId) return;
|
|
80
|
-
const onKey = (e: KeyboardEvent) => {
|
|
81
|
-
if (e.key === "Escape") setSelectedStepId(null);
|
|
82
|
-
};
|
|
83
|
-
window.addEventListener("keydown", onKey);
|
|
84
|
-
return () => window.removeEventListener("keydown", onKey);
|
|
85
|
-
}, [selectedStepId]);
|
|
86
|
-
|
|
87
|
-
// Scroll the matching node + card into view on selection (counterpart sync).
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (!selectedStepId || !rootRef.current) return;
|
|
90
|
-
const esc = selectedStepId.replace(/["\\]/g, "\\$&");
|
|
91
|
-
for (const attr of ["data-node", "data-step"]) {
|
|
92
|
-
rootRef.current
|
|
93
|
-
.querySelector(`[${attr}="${esc}"]`)
|
|
94
|
-
?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
95
|
-
}
|
|
96
|
-
}, [selectedStepId]);
|
|
97
|
-
|
|
58
|
+
const summarised = agents.filter((a) => a.summary);
|
|
98
59
|
return (
|
|
99
|
-
|
|
100
|
-
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
>
|
|
110
|
-
<Icon path={panelCollapsed ? mdiChevronRight : mdiChevronDown} size={0.6} />
|
|
111
|
-
</button>
|
|
112
|
-
<span className={`${color} inline-flex`}>{icon}</span>
|
|
113
|
-
<span className="text-sm text-[var(--text-primary)] flex-1">
|
|
114
|
-
{flowState.flowName} {label}
|
|
115
|
-
<span className="text-[var(--text-tertiary)] ml-1.5">
|
|
116
|
-
· {agents.length} steps
|
|
117
|
-
{totalDuration ? ` · ${formatDuration(totalDuration)}` : ""}
|
|
118
|
-
{totalFiles > 0 ? ` · ${totalFiles} files` : ""}
|
|
119
|
-
</span>
|
|
120
|
-
</span>
|
|
121
|
-
<button
|
|
122
|
-
onClick={onDismiss}
|
|
123
|
-
className="text-[10px] px-1.5 py-0.5 rounded border border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"
|
|
124
|
-
>
|
|
125
|
-
<Icon path={mdiCloseCircleOutline} size={0.4} className="inline mr-0.5" />Dismiss
|
|
126
|
-
</button>
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
{!panelCollapsed && (<>
|
|
130
|
-
{/* Flow graph — bounded + fit-to-window; ⤢ expand opens the centered Dialog
|
|
131
|
-
with pan/zoom. Bounded so it cannot be dragged over the cards/summaries.
|
|
132
|
-
See change: show-flow-cards-in-summary. */}
|
|
133
|
-
<FlowGraph
|
|
134
|
-
steps={flowStateToGraphSteps(flowState)}
|
|
135
|
-
fit
|
|
136
|
-
selectedStepId={selectedStepId}
|
|
137
|
-
onSelectStep={handleSelectStep}
|
|
138
|
-
onExpand={Dialog ? () => setGraphOpen(true) : undefined}
|
|
139
|
-
/>
|
|
140
|
-
{flowState.flowSource && (
|
|
141
|
-
<div className="mt-1">
|
|
142
|
-
<FlowYamlPopoverButton
|
|
143
|
-
flowSource={flowState.flowSource}
|
|
144
|
-
flowName={flowState.flowName}
|
|
145
|
-
sessionId={sessionId ?? session?.id}
|
|
146
|
-
/>
|
|
147
|
-
</div>
|
|
148
|
-
)}
|
|
149
|
-
|
|
150
|
-
{/* Everything UNDER the graph lives in ONE fixed-height scrollable box so
|
|
151
|
-
the whole panel always fits the viewport (no page scroll). The summaries
|
|
152
|
-
section and each agent row stay independently collapsible inside it. */}
|
|
153
|
-
<div className="mt-2 overflow-y-auto" style={{ maxHeight: "48vh" }} data-testid="flow-summary-scrollbox">
|
|
154
|
-
{/* Frozen agent cards — read-only. Same grid geometry as the live panel
|
|
155
|
-
(shared helper); the wrapper is the query container (design D1/D5). */}
|
|
156
|
-
{agents.length > 0 && (
|
|
157
|
-
<div className={FLOW_CARD_GRID_CONTAINER_CLASS}>
|
|
158
|
-
<div className={FLOW_CARD_GRID_CLASS}>
|
|
159
|
-
{agents.map(agent => (
|
|
160
|
-
<FlowAgentCard
|
|
161
|
-
key={agent.stepId || agent.agentName}
|
|
162
|
-
agent={agent}
|
|
163
|
-
session={session}
|
|
164
|
-
sessionId={sessionId ?? session?.id}
|
|
165
|
-
selected={selectedStepId === (agent.stepId || agent.agentName)}
|
|
166
|
-
onSelect={handleSelectStep}
|
|
167
|
-
/>
|
|
168
|
-
))}
|
|
169
|
-
</div>
|
|
60
|
+
<>
|
|
61
|
+
{summarised.length > 0 && (
|
|
62
|
+
<div className="mt-2 pt-1.5 border-t border-[var(--border-subtle)]">
|
|
63
|
+
<div
|
|
64
|
+
data-testid="flow-summary-toggle"
|
|
65
|
+
className="flex items-center gap-1.5 text-[11px] text-[var(--text-tertiary)] cursor-pointer mb-1 hover:text-[var(--text-primary)]"
|
|
66
|
+
onClick={() => setCollapsed(!collapsed)}
|
|
67
|
+
>
|
|
68
|
+
<Icon path={collapsed ? mdiChevronRight : mdiChevronDown} size={0.5} />
|
|
69
|
+
<span>Summaries ({summarised.length})</span>
|
|
170
70
|
</div>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
See change: fix-flow-ui-graph-zoom-summary. */}
|
|
177
|
-
{summarised.length > 0 && (
|
|
178
|
-
<div className="mt-2 pt-1.5 border-t border-[var(--border-subtle)]">
|
|
179
|
-
<div
|
|
180
|
-
data-testid="flow-summary-toggle"
|
|
181
|
-
className="flex items-center gap-1.5 text-[11px] text-[var(--text-tertiary)] cursor-pointer mb-1 hover:text-[var(--text-primary)]"
|
|
182
|
-
onClick={() => setCollapsed(!collapsed)}
|
|
183
|
-
>
|
|
184
|
-
<Icon path={collapsed ? mdiChevronRight : mdiChevronDown} size={0.5} />
|
|
185
|
-
<span>Summaries ({summarised.length})</span>
|
|
71
|
+
{!collapsed && (
|
|
72
|
+
<div className="space-y-0.5" data-testid="flow-summaries">
|
|
73
|
+
{summarised.map((agent) => (
|
|
74
|
+
<FlowSummaryRow key={agent.stepId || agent.agentName} agent={agent} />
|
|
75
|
+
))}
|
|
186
76
|
</div>
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
<FlowSummaryRow key={agent.stepId || agent.agentName} agent={agent} />
|
|
191
|
-
))}
|
|
192
|
-
</div>
|
|
193
|
-
)}
|
|
194
|
-
</div>
|
|
195
|
-
)}
|
|
196
|
-
|
|
197
|
-
{/* Next step suggestion */}
|
|
198
|
-
{flowState.nextStep && onSendPrompt && (
|
|
199
|
-
<div className="mt-1.5 pt-1.5 border-t border-[var(--border-subtle)]">
|
|
200
|
-
<button
|
|
201
|
-
onClick={() => onSendPrompt(`/${flowState.nextStep}`)}
|
|
202
|
-
className="text-[11px] px-2 py-1 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10"
|
|
203
|
-
>
|
|
204
|
-
Next: /{flowState.nextStep}
|
|
205
|
-
</button>
|
|
206
|
-
</div>
|
|
207
|
-
)}
|
|
208
|
-
</div>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
209
80
|
|
|
210
|
-
{
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
height cap so the horizontal DAG gets a wide stage. See change:
|
|
220
|
-
improve-flow-graph-dialog-and-card-interaction. */}
|
|
221
|
-
<div style={{ height: "82vh", overflow: "hidden" }}>
|
|
222
|
-
<FlowGraph
|
|
223
|
-
steps={flowStateToGraphSteps(flowState)}
|
|
224
|
-
selectedStepId={selectedStepId}
|
|
225
|
-
onSelectStep={handleSelectStep}
|
|
226
|
-
/>
|
|
227
|
-
</div>
|
|
228
|
-
</Dialog>
|
|
81
|
+
{flowState.nextStep && onSendPrompt && (
|
|
82
|
+
<div className="mt-1.5 pt-1.5 border-t border-[var(--border-subtle)]">
|
|
83
|
+
<button
|
|
84
|
+
onClick={() => onSendPrompt(`/${flowState.nextStep}`)}
|
|
85
|
+
className="text-[11px] px-2 py-1 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10"
|
|
86
|
+
>
|
|
87
|
+
Next: /{flowState.nextStep}
|
|
88
|
+
</button>
|
|
89
|
+
</div>
|
|
229
90
|
)}
|
|
230
|
-
|
|
231
|
-
</div>
|
|
91
|
+
</>
|
|
232
92
|
);
|
|
233
93
|
}
|
|
234
94
|
|
|
@@ -239,7 +99,7 @@ export function FlowSummary({
|
|
|
239
99
|
* Mirrors the ToolCallStep chevron idiom; failed steps auto-expand.
|
|
240
100
|
* See change: expandable-flow-summary-rows.
|
|
241
101
|
*/
|
|
242
|
-
function FlowSummaryRow({ agent }: { agent: FlowAgentState }) {
|
|
102
|
+
export function FlowSummaryRow({ agent }: { agent: FlowAgentState }) {
|
|
243
103
|
const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
|
|
244
104
|
const fileCount = agent.files?.length ?? 0;
|
|
245
105
|
const outputs = agent.typedOutputs
|
|
@@ -318,31 +178,3 @@ function FlowSummaryRow({ agent }: { agent: FlowAgentState }) {
|
|
|
318
178
|
</div>
|
|
319
179
|
);
|
|
320
180
|
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Slot-consumer wrapper for the `content-inline-footer` claim. Self-
|
|
324
|
-
* derives flow state, dispatches dismissal via pluginContext.send,
|
|
325
|
-
* navigates agent detail via the plugin-internal UI state context.
|
|
326
|
-
* Returns null when no flow is active. See change:
|
|
327
|
-
* pluginize-flows-via-registry.
|
|
328
|
-
*/
|
|
329
|
-
export function FlowSummaryClaim({ session }: { session: DashboardSession }) {
|
|
330
|
-
const { flowState } = useFlowsSessionState(session.id);
|
|
331
|
-
const send = usePluginSend();
|
|
332
|
-
|
|
333
|
-
if (!flowState) return null;
|
|
334
|
-
|
|
335
|
-
return (
|
|
336
|
-
<FlowSummary
|
|
337
|
-
flowState={flowState}
|
|
338
|
-
session={session}
|
|
339
|
-
sessionId={session.id}
|
|
340
|
-
onDismiss={() =>
|
|
341
|
-
send({ type: "flow_control", sessionId: session.id, action: "dismiss_summary" })
|
|
342
|
-
}
|
|
343
|
-
onSendPrompt={(text) =>
|
|
344
|
-
send({ type: "send_prompt", sessionId: session.id, text })
|
|
345
|
-
}
|
|
346
|
-
/>
|
|
347
|
-
);
|
|
348
|
-
}
|
|
@@ -4,16 +4,20 @@
|
|
|
4
4
|
* Renders from the real tool contract: result JSON is
|
|
5
5
|
* `{ written, name, namespace, command, path, diagnostics[] }` (success) or
|
|
6
6
|
* `{ written:false, diagnostics[] }` / `{ written:false, error }` (failure).
|
|
7
|
-
* The result carries no parsed steps, so the
|
|
8
|
-
*
|
|
7
|
+
* The result carries no parsed steps, so the graph + step/agent/code counts are
|
|
8
|
+
* built client-side from the tool ARGS (`toolInput.content`) with the same
|
|
9
|
+
* not-started pipeline as Open flow (`buildIdleFlowState`, lenient) and drawn
|
|
10
|
+
* by the shared `FlowGraph` (expand-to-dialog, error-route toggle).
|
|
9
11
|
*
|
|
10
|
-
* See
|
|
12
|
+
* See changes: rework-flows-plugin-for-new-pi-flows, unify-flow-rendering (D4).
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
|
-
import { useT,
|
|
15
|
+
import { useT, useUiPrimitiveOrNull } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
14
16
|
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
17
|
+
import type { FlowState } from "../types.js";
|
|
15
18
|
import React, { useMemo, useState } from "react";
|
|
16
|
-
import {
|
|
19
|
+
import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
|
|
20
|
+
import { buildIdleFlowState } from "./flow-idle-state.js";
|
|
17
21
|
|
|
18
22
|
interface FlowWriteResult {
|
|
19
23
|
written?: boolean;
|
|
@@ -30,6 +34,18 @@ function safeParse(result: string | undefined): FlowWriteResult | null {
|
|
|
30
34
|
try { return JSON.parse(result) as FlowWriteResult; } catch { return null; }
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
/** Step counts from the built step list; agent = agent | agent-decision, code = code | code-decision. */
|
|
38
|
+
function stepCounts(state: FlowState): { total: number; agents: number; code: number } {
|
|
39
|
+
const steps = state.dagSteps ?? [];
|
|
40
|
+
const isAgent = (t: string) => t === "agent" || t === "agent-decision";
|
|
41
|
+
const isCode = (t: string) => t === "code" || t === "code-decision";
|
|
42
|
+
return {
|
|
43
|
+
total: steps.length,
|
|
44
|
+
agents: steps.filter((s) => isAgent(s.stepType)).length,
|
|
45
|
+
code: steps.filter((s) => isCode(s.stepType)).length,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
33
49
|
function diagText(d: { message?: string } | string): string {
|
|
34
50
|
return typeof d === "string" ? d : (d.message ?? JSON.stringify(d));
|
|
35
51
|
}
|
|
@@ -46,16 +62,22 @@ export function FlowWriteToolRenderer({
|
|
|
46
62
|
result?: string;
|
|
47
63
|
}) {
|
|
48
64
|
const t = useT();
|
|
49
|
-
const
|
|
65
|
+
const Dialog = useUiPrimitiveOrNull(UI_PRIMITIVE_KEYS.dialog);
|
|
50
66
|
const [showYaml, setShowYaml] = useState(false);
|
|
67
|
+
const [graphOpen, setGraphOpen] = useState(false);
|
|
51
68
|
|
|
52
69
|
const content = typeof toolInput.content === "string" ? toolInput.content : "";
|
|
53
70
|
const parsed = safeParse(result);
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
const flowName = parsed?.command ?? parsed?.name ?? "flow";
|
|
72
|
+
const flowPath = parsed?.path;
|
|
73
|
+
// Same pipeline as Open flow; lenient so older/incomplete persisted YAML keeps its graph.
|
|
74
|
+
const flowState = useMemo(() => {
|
|
75
|
+
if (!content) return null;
|
|
76
|
+
const r = buildIdleFlowState(content, { name: flowName, source: flowPath }, { lenient: true });
|
|
77
|
+
return r.kind === "ready" ? r.flowState : null;
|
|
78
|
+
}, [content, flowName, flowPath]);
|
|
79
|
+
const graphSteps = useMemo(() => (flowState ? flowStateToGraphSteps(flowState) : null), [flowState]);
|
|
80
|
+
const counts = useMemo(() => (flowState ? stepCounts(flowState) : null), [flowState]);
|
|
59
81
|
|
|
60
82
|
const diagnostics = (parsed?.diagnostics ?? []).map(diagText);
|
|
61
83
|
const written = parsed?.written === true;
|
|
@@ -74,18 +96,25 @@ export function FlowWriteToolRenderer({
|
|
|
74
96
|
{isError && <span className="text-red-400">not written — validation failed</span>}
|
|
75
97
|
</div>
|
|
76
98
|
|
|
77
|
-
{/* Counts
|
|
78
|
-
{written &&
|
|
99
|
+
{/* Counts built from args */}
|
|
100
|
+
{written && counts && (
|
|
79
101
|
<div className="mt-1 text-[var(--text-tertiary)]">
|
|
80
|
-
{
|
|
102
|
+
{counts.total} steps · {counts.agents} agents, {counts.code} code
|
|
81
103
|
</div>
|
|
82
104
|
)}
|
|
83
105
|
|
|
84
|
-
{/*
|
|
85
|
-
{written &&
|
|
106
|
+
{/* Shared flow graph built from args */}
|
|
107
|
+
{written && graphSteps && (
|
|
86
108
|
<div className="mt-2">
|
|
87
109
|
<div className="text-[10px] uppercase tracking-wide text-[var(--text-muted)] mb-1">{t("flowGraph", undefined, "Flow graph")}</div>
|
|
88
|
-
<
|
|
110
|
+
<FlowGraph steps={graphSteps} fit onExpand={Dialog ? () => setGraphOpen(true) : undefined} />
|
|
111
|
+
{Dialog && (
|
|
112
|
+
<Dialog open={graphOpen} onClose={() => setGraphOpen(false)} title={`Flow graph · ${flowName}`} size="full">
|
|
113
|
+
<div style={{ height: "82vh", overflow: "hidden" }}>
|
|
114
|
+
<FlowGraph steps={graphSteps} />
|
|
115
|
+
</div>
|
|
116
|
+
</Dialog>
|
|
117
|
+
)}
|
|
89
118
|
</div>
|
|
90
119
|
)}
|
|
91
120
|
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* host's built-in editor (Split view) via `useOpenFileInEditor`. Hidden without
|
|
4
4
|
* a session (no editor to target).
|
|
5
5
|
*
|
|
6
|
-
* Used by `FlowDashboard` (
|
|
6
|
+
* Used by `FlowDashboard` (idle, live and completed/summary mode).
|
|
7
7
|
*
|
|
8
8
|
* The flow's YAML path is emitted by pi-flows in the `flow:flow-started`
|
|
9
9
|
* event (`source: flow.source`) and stored on `FlowState.flowSource` by the
|
|
10
|
-
* flow reducer; an attached idle flow carries it from
|
|
10
|
+
* flow reducer; an attached idle flow carries it from the flow catalog.
|
|
11
11
|
*
|
|
12
12
|
* See change: add-ui-popover-primitive, attach-flow-before-run.
|
|
13
13
|
*/
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `composer-context-group` claim: the FLOWS chip in the composer dock's
|
|
3
|
+
* Context lane. Renders only when the session's flow catalog lists at least
|
|
4
|
+
* one flow (unknown / empty → nothing, no label, no container).
|
|
5
|
+
*
|
|
6
|
+
* Shows the open or last flow's name and a text status pill (running d/t,
|
|
7
|
+
* failed · N steps, done, aborted, not started), then Run flow… / Open flow…
|
|
8
|
+
* / Edit… icon buttons. Run and Open are disabled with "A flow is running"
|
|
9
|
+
* while any flow in the session runs; the chip is never disabled for an agent
|
|
10
|
+
* turn. As the viewed session's surface it re-asks for an unknown catalog.
|
|
11
|
+
*
|
|
12
|
+
* See change: flows-dock-chip-and-panel-actions (D5–D7, D9).
|
|
13
|
+
*/
|
|
14
|
+
import { ComposerContextGroup, useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
15
|
+
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
16
|
+
import type { FlowState } from "../types.js";
|
|
17
|
+
import { mdiEyeOutline, mdiPlay } from "@mdi/js";
|
|
18
|
+
import { Icon } from "@mdi/react";
|
|
19
|
+
import { useState } from "react";
|
|
20
|
+
import { FLOW_ICON_BUTTON_CLASS, FlowEditMenu } from "./FlowEditMenu.js";
|
|
21
|
+
import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
|
|
22
|
+
import { useFlowAttachment } from "./flow-attach-store.js";
|
|
23
|
+
import { type FlowAttachment, findRunning, isAttachmentConsumed } from "./flow-idle-state.js";
|
|
24
|
+
import { FlowActionDialogs, useFlowActions } from "./useFlowActions.js";
|
|
25
|
+
import { useRunReattach } from "./useRunReattach.js";
|
|
26
|
+
|
|
27
|
+
export type ChipStatus =
|
|
28
|
+
| { kind: "running"; done: number; total: number }
|
|
29
|
+
| { kind: "failed"; steps: number }
|
|
30
|
+
| { kind: "done" }
|
|
31
|
+
| { kind: "aborted" }
|
|
32
|
+
| { kind: "not-started" };
|
|
33
|
+
|
|
34
|
+
export interface ChipFlow {
|
|
35
|
+
name: string;
|
|
36
|
+
status: ChipStatus;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function stepCounts(s: FlowState): { done: number; total: number } {
|
|
40
|
+
const agents = Array.from(s.agents.values());
|
|
41
|
+
const done = agents.filter((a) => a.status === "complete" || a.status === "error" || a.status === "blocked").length;
|
|
42
|
+
return { done, total: agents.length };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The flow the chip names: a running flow wins (slot priority; the last
|
|
47
|
+
* running entry in rank order, never one older than the slot run), then an
|
|
48
|
+
* attached not-yet-started flow, then the last completed flow; none → null.
|
|
49
|
+
* See change: fix-flow-reattach-per-run-state (D2).
|
|
50
|
+
*/
|
|
51
|
+
export function deriveChipFlow(input: {
|
|
52
|
+
flowState: FlowState | null;
|
|
53
|
+
flowStates: ReadonlyMap<string, FlowState>;
|
|
54
|
+
attachment: FlowAttachment | null;
|
|
55
|
+
lastFlowStartedAt?: unknown;
|
|
56
|
+
}): ChipFlow | null {
|
|
57
|
+
const { flowState, flowStates, attachment, lastFlowStartedAt } = input;
|
|
58
|
+
const running = findRunning(flowState, flowStates);
|
|
59
|
+
if (running) return { name: running.flowName, status: { kind: "running", ...stepCounts(running) } };
|
|
60
|
+
if (attachment && !isAttachmentConsumed(attachment.baselineStartedAt, lastFlowStartedAt)) {
|
|
61
|
+
return { name: attachment.name, status: { kind: "not-started" } };
|
|
62
|
+
}
|
|
63
|
+
if (!flowState) return null;
|
|
64
|
+
if (flowState.status === "error") return { name: flowState.flowName, status: { kind: "failed", steps: stepCounts(flowState).total } };
|
|
65
|
+
if (flowState.status === "aborted") return { name: flowState.flowName, status: { kind: "aborted" } };
|
|
66
|
+
return { name: flowState.flowName, status: { kind: "done" } };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function useStatusText(): (s: ChipStatus) => string {
|
|
70
|
+
const t = useT();
|
|
71
|
+
return (s) => {
|
|
72
|
+
switch (s.kind) {
|
|
73
|
+
case "running":
|
|
74
|
+
return t("chipRunning", { done: s.done, total: s.total }, `running ${s.done}/${s.total}`);
|
|
75
|
+
case "failed":
|
|
76
|
+
return t("chipFailed", { steps: s.steps }, `failed · ${s.steps} steps`);
|
|
77
|
+
case "done":
|
|
78
|
+
return t("chipDone", undefined, "done");
|
|
79
|
+
case "aborted":
|
|
80
|
+
return t("chipAborted", undefined, "aborted");
|
|
81
|
+
default:
|
|
82
|
+
return t("flowNotStarted", undefined, "not started");
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const PILL_TONE: Record<ChipStatus["kind"], string> = {
|
|
88
|
+
running: "text-[var(--severity-info-fg)] border-[var(--severity-info-border)] bg-[var(--severity-info-bg)]",
|
|
89
|
+
failed: "text-[var(--severity-error-fg)] border-[var(--severity-error-border)] bg-[var(--severity-error-bg)]",
|
|
90
|
+
done: "text-[var(--severity-success-fg)] border-[var(--severity-success-border)] bg-[var(--severity-success-bg)]",
|
|
91
|
+
aborted: "text-[var(--severity-warning-fg)] border-[var(--severity-warning-border)] bg-[var(--severity-warning-bg)]",
|
|
92
|
+
"not-started": "text-[var(--severity-neutral-fg)] border-[var(--severity-neutral-border)] bg-[var(--severity-neutral-bg)]",
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export function FlowsContextGroup({ session }: { session: DashboardSession }) {
|
|
96
|
+
const t = useT();
|
|
97
|
+
const statusText = useStatusText();
|
|
98
|
+
const [editOpen, setEditOpen] = useState(false);
|
|
99
|
+
const actions = useFlowActions(session.id, { editModeWhen: "has-flows", menuOpen: editOpen, autoAskCatalog: true });
|
|
100
|
+
const { flowState, flowStates, lastFlowStartedAt } = useFlowsSessionState(session.id);
|
|
101
|
+
const attachment = useFlowAttachment(session.id);
|
|
102
|
+
// Single host per viewed session for the orphan-run re-ask (D5).
|
|
103
|
+
useRunReattach(session.id);
|
|
104
|
+
|
|
105
|
+
if (!actions.catalogKnown || !actions.hasFlows) return null;
|
|
106
|
+
|
|
107
|
+
const chipFlow = deriveChipFlow({ flowState, flowStates, attachment, lastFlowStartedAt });
|
|
108
|
+
const runningReason = t("openFlowDisabledRunning", undefined, "A flow is running");
|
|
109
|
+
const runLabel = t("runFlowButton", undefined, "Run flow…");
|
|
110
|
+
const openLabel = t("openFlowButton", undefined, "Open flow…");
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<>
|
|
114
|
+
<ComposerContextGroup label={t("flowsChipLabel", undefined, "FLOWS")} testId="flows-context-group">
|
|
115
|
+
{chipFlow && (
|
|
116
|
+
<span className="inline-flex items-center gap-1.5 min-w-0 text-xs" data-testid="flows-chip-flow">
|
|
117
|
+
<span className="truncate max-w-[12rem] text-[var(--text-primary)]" data-testid="flows-chip-name" title={chipFlow.name}>
|
|
118
|
+
{chipFlow.name}
|
|
119
|
+
</span>
|
|
120
|
+
<span
|
|
121
|
+
data-testid="flows-chip-status"
|
|
122
|
+
data-status={chipFlow.status.kind}
|
|
123
|
+
className={`whitespace-nowrap rounded border px-1 text-[11px] leading-4 ${PILL_TONE[chipFlow.status.kind]}`}
|
|
124
|
+
>
|
|
125
|
+
{statusText(chipFlow.status)}
|
|
126
|
+
</span>
|
|
127
|
+
</span>
|
|
128
|
+
)}
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
data-testid="flows-chip-run"
|
|
132
|
+
aria-label={runLabel}
|
|
133
|
+
title={actions.anyRunning ? runningReason : runLabel}
|
|
134
|
+
disabled={actions.anyRunning}
|
|
135
|
+
onClick={actions.run}
|
|
136
|
+
className={FLOW_ICON_BUTTON_CLASS}
|
|
137
|
+
>
|
|
138
|
+
<Icon path={mdiPlay} size={0.6} aria-hidden="true" />
|
|
139
|
+
</button>
|
|
140
|
+
<button
|
|
141
|
+
type="button"
|
|
142
|
+
data-testid="flows-chip-open"
|
|
143
|
+
aria-label={openLabel}
|
|
144
|
+
title={actions.anyRunning ? runningReason : openLabel}
|
|
145
|
+
disabled={actions.anyRunning}
|
|
146
|
+
onClick={actions.open}
|
|
147
|
+
className={FLOW_ICON_BUTTON_CLASS}
|
|
148
|
+
>
|
|
149
|
+
<Icon path={mdiEyeOutline} size={0.6} aria-hidden="true" />
|
|
150
|
+
</button>
|
|
151
|
+
<FlowEditMenu actions={actions} open={editOpen} onOpenChange={setEditOpen} testIdPrefix="flows-chip-edit" />
|
|
152
|
+
</ComposerContextGroup>
|
|
153
|
+
<FlowActionDialogs actions={actions} />
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
}
|