@blackbelt-technology/pi-dashboard-flows-plugin 0.5.2 → 0.5.4
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/package.json +39 -4
- package/src/__tests__/FlowsSessionStateContext.test.tsx +260 -0
- package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
- package/src/__tests__/flowsAvailability.test.ts +92 -0
- package/src/__tests__/manifest-discoverability.test.ts +97 -0
- package/src/__tests__/render-actions.test.ts +63 -0
- package/src/bridge/flow-question-adapter.ts +93 -0
- package/src/bridge/index.ts +30 -0
- package/src/client/FlowActivityBadge.tsx +36 -9
- package/src/client/FlowAgentCard.tsx +180 -41
- package/src/client/FlowAgentDetail.tsx +95 -154
- package/src/client/FlowAgentPopoutClaim.tsx +66 -0
- package/src/client/FlowAgentPopoutPage.tsx +177 -0
- package/src/client/FlowArchitect.tsx +297 -220
- package/src/client/FlowArchitectPopoutClaim.tsx +52 -0
- package/src/client/FlowArchitectPopoutPage.tsx +133 -0
- package/src/client/FlowDashboard.tsx +194 -31
- package/src/client/FlowGraph.tsx +6 -2
- package/src/client/FlowLaunchDialog.tsx +8 -2
- package/src/client/FlowQuestionCard.tsx +213 -0
- package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
- package/src/client/FlowSummary.tsx +43 -21
- package/src/client/FlowYamlPopoverButton.tsx +109 -0
- package/src/client/FlowYamlPreview.tsx +65 -0
- package/src/client/FlowsCommandRoutes.tsx +237 -0
- package/src/client/FlowsSessionStateContext.tsx +161 -0
- package/src/client/FlowsUiStateContext.tsx +169 -0
- package/src/client/SessionFlowActions.tsx +96 -5
- package/src/client/flowsAvailability.ts +103 -0
- package/src/client/index.tsx +94 -7
- package/src/client/popout-url.ts +59 -0
- package/src/client/shouldRender.ts +26 -0
- package/src/server/index.ts +87 -0
- package/src/server/render-actions.ts +88 -0
- package/src/server/state-store.ts +85 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlowArchitectPopoutPage — fullscreen route content for
|
|
3
|
+
* `/session/:sid/architect`.
|
|
4
|
+
*
|
|
5
|
+
* Mounts `FlowArchitectDetail` in popout mode plus a chrome header.
|
|
6
|
+
* Graceful empty-state ladder mirrors `FlowAgentPopoutPage`:
|
|
7
|
+
* 1. Subscription not yet resolved → "Loading parent session…"
|
|
8
|
+
* 2. Parent session not found → close-tab CTA
|
|
9
|
+
* 3. No architect active → "No architect active"
|
|
10
|
+
* 4. Resolved → FlowArchitectDetail render
|
|
11
|
+
*
|
|
12
|
+
* See change: fix-flows-plugin-polish (A4).
|
|
13
|
+
*/
|
|
14
|
+
import React, { useEffect } from "react";
|
|
15
|
+
import { Icon } from "@mdi/react";
|
|
16
|
+
import { mdiArrowLeft, mdiClose } from "@mdi/js";
|
|
17
|
+
import type { ArchitectState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
18
|
+
import { FlowArchitectDetail } from "./FlowArchitect.js";
|
|
19
|
+
|
|
20
|
+
export interface FlowArchitectPopoutPageProps {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
/** The resolved architect state (or undefined if not yet subscribed / not active). */
|
|
23
|
+
architectState: ArchitectState | undefined;
|
|
24
|
+
/** True once the parent session's subscription has resolved. */
|
|
25
|
+
subscriptionResolved: boolean;
|
|
26
|
+
/** Optional parent-session display label (e.g. cwd) for the breadcrumb. */
|
|
27
|
+
parentLabel?: string;
|
|
28
|
+
onBack?: () => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function FlowArchitectPopoutPage({
|
|
32
|
+
sessionId,
|
|
33
|
+
architectState,
|
|
34
|
+
subscriptionResolved,
|
|
35
|
+
parentLabel,
|
|
36
|
+
onBack,
|
|
37
|
+
}: FlowArchitectPopoutPageProps) {
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
document.title = `Flow Architect · ${parentLabel ?? sessionId} · pi`;
|
|
40
|
+
return () => {
|
|
41
|
+
document.title = "pi";
|
|
42
|
+
};
|
|
43
|
+
}, [parentLabel, sessionId]);
|
|
44
|
+
|
|
45
|
+
// (1) Loading
|
|
46
|
+
if (!subscriptionResolved) {
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
data-testid="flow-architect-popout-loading"
|
|
50
|
+
className="flex flex-col h-full items-center justify-center text-sm text-[var(--text-muted)] gap-2"
|
|
51
|
+
>
|
|
52
|
+
<div>Loading parent session…</div>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// (2) Parent session not found (cannot derive parentLabel and architect is
|
|
58
|
+
// absent — best heuristic available since the runtime DashboardSession is
|
|
59
|
+
// not threaded down).
|
|
60
|
+
if (!parentLabel && !architectState) {
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
data-testid="flow-architect-popout-no-session"
|
|
64
|
+
className="flex flex-col h-full items-center justify-center text-sm text-[var(--text-muted)] gap-3 px-6 text-center"
|
|
65
|
+
>
|
|
66
|
+
<div className="text-base text-[var(--text-primary)]">Parent session not found</div>
|
|
67
|
+
<div className="max-w-md">
|
|
68
|
+
It may have been archived or deleted. Close this tab — the session
|
|
69
|
+
this architect was launched from is no longer available.
|
|
70
|
+
</div>
|
|
71
|
+
<button
|
|
72
|
+
onClick={() => window.close()}
|
|
73
|
+
className="text-xs text-[var(--text-tertiary)] hover:text-[var(--text-primary)] inline-flex items-center gap-1 mt-2 px-3 py-1 border border-[var(--border-primary)] rounded"
|
|
74
|
+
>
|
|
75
|
+
<Icon path={mdiClose} size={0.5} /> Close tab
|
|
76
|
+
</button>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// (3) No architect active
|
|
82
|
+
if (!architectState) {
|
|
83
|
+
return (
|
|
84
|
+
<div data-testid="flow-architect-popout-no-architect" className="flex flex-col h-full overflow-hidden">
|
|
85
|
+
<div className="px-3 py-2 border-b border-[var(--border-subtle)] bg-[var(--bg-secondary)] flex items-center gap-2 flex-shrink-0">
|
|
86
|
+
{onBack && (
|
|
87
|
+
<button
|
|
88
|
+
onClick={onBack}
|
|
89
|
+
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
|
|
90
|
+
title="Back"
|
|
91
|
+
>
|
|
92
|
+
<Icon path={mdiArrowLeft} size={0.7} />
|
|
93
|
+
</button>
|
|
94
|
+
)}
|
|
95
|
+
<span className="text-sm text-[var(--text-primary)]">
|
|
96
|
+
Flow Architect · {parentLabel ?? sessionId}
|
|
97
|
+
</span>
|
|
98
|
+
</div>
|
|
99
|
+
<div className="flex-1 flex items-center justify-center text-sm text-[var(--text-muted)] px-6 text-center">
|
|
100
|
+
No architect active on this session.
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// (4) Found
|
|
107
|
+
return (
|
|
108
|
+
<div data-testid="flow-architect-popout" className="flex flex-col h-full overflow-hidden">
|
|
109
|
+
<div className="px-3 py-2 border-b border-[var(--border-primary)] bg-[var(--bg-primary)] flex items-center gap-2 flex-shrink-0">
|
|
110
|
+
{onBack && (
|
|
111
|
+
<button
|
|
112
|
+
onClick={onBack}
|
|
113
|
+
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
|
|
114
|
+
title="Back"
|
|
115
|
+
>
|
|
116
|
+
<Icon path={mdiArrowLeft} size={0.7} />
|
|
117
|
+
</button>
|
|
118
|
+
)}
|
|
119
|
+
<span className="text-[11px] text-[var(--text-tertiary)] truncate flex-shrink-0">
|
|
120
|
+
{parentLabel ?? sessionId} ›
|
|
121
|
+
</span>
|
|
122
|
+
<span className="text-sm font-medium text-[var(--text-primary)] truncate flex-1 min-w-0">
|
|
123
|
+
Flow Architect
|
|
124
|
+
</span>
|
|
125
|
+
</div>
|
|
126
|
+
{/* `min-h-0` required so body scrolls instead of overflowing.
|
|
127
|
+
See change: fix-flows-plugin-polish (scrollbar fix). */}
|
|
128
|
+
<div className="flex-1 min-h-0 overflow-hidden">
|
|
129
|
+
<FlowArchitectDetail state={architectState} sessionId={sessionId} />
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -1,42 +1,48 @@
|
|
|
1
1
|
import React, { useState, useMemo, useEffect, useRef } from "react";
|
|
2
2
|
import { Icon } from "@mdi/react";
|
|
3
3
|
import { mdiRobotOutline, mdiStop, mdiChevronUp, mdiChevronRight, mdiChevronDown, mdiFileDocumentOutline, mdiLoading } from "@mdi/js";
|
|
4
|
-
import type { DashboardSession, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
4
|
+
import type { DashboardSession, FlowState, ImageContent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
5
|
+
import {
|
|
6
|
+
usePluginSend,
|
|
7
|
+
useSessionInteractiveRequests,
|
|
8
|
+
type InteractiveUiRequestSnapshot,
|
|
9
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
5
10
|
import { FlowAgentCard } from "./FlowAgentCard.js";
|
|
11
|
+
import { FlowQuestionCard } from "./FlowQuestionCard.js";
|
|
12
|
+
import { FlowQuestionTranscriptPill } from "./FlowQuestionTranscriptPill.js";
|
|
6
13
|
import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
|
|
7
14
|
import { FlowSummary } from "./FlowSummary.js";
|
|
15
|
+
import { FlowYamlPopoverButton } from "./FlowYamlPopoverButton.js";
|
|
8
16
|
import { FlowTabBar, type FlowTab } from "./FlowTabBar.js";
|
|
9
|
-
import { useMobile } from "
|
|
10
|
-
import { BreadcrumbSlot } from "
|
|
17
|
+
import { useMobile } from "@blackbelt-technology/pi-dashboard-client-utils/useMobile";
|
|
18
|
+
import { BreadcrumbSlot } from "@blackbelt-technology/pi-dashboard-client-utils/extension-ui/BreadcrumbSlot";
|
|
19
|
+
import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
11
23
|
|
|
12
24
|
export function FlowDashboard({
|
|
13
25
|
flowState,
|
|
14
26
|
flowStates,
|
|
15
|
-
onAgentClick,
|
|
16
|
-
selectedAgent,
|
|
17
27
|
onAbort,
|
|
18
28
|
onToggleAutonomous,
|
|
19
29
|
onDismiss,
|
|
20
30
|
onSendPrompt,
|
|
21
|
-
onViewYaml,
|
|
22
|
-
onViewAgentSource,
|
|
23
|
-
sourceOpenAgent,
|
|
24
31
|
session,
|
|
32
|
+
sessionId,
|
|
25
33
|
}: {
|
|
26
34
|
flowState: FlowState;
|
|
27
35
|
/** All flow states (main + subflows) for tab navigation */
|
|
28
36
|
flowStates?: Map<string, FlowState>;
|
|
29
|
-
onAgentClick: (agentName: string | null) => void;
|
|
30
|
-
selectedAgent?: string | null;
|
|
31
37
|
onAbort: () => void;
|
|
32
38
|
onToggleAutonomous: () => void;
|
|
33
39
|
onDismiss: () => void;
|
|
34
40
|
onSendPrompt?: (text: string, images?: import("@blackbelt-technology/pi-dashboard-shared/types.js").ImageContent[]) => void;
|
|
35
|
-
onViewYaml?: () => void;
|
|
36
|
-
onViewAgentSource?: (sourcePath: string, agentName: string) => void;
|
|
37
|
-
sourceOpenAgent?: string | null;
|
|
38
41
|
/** Phase-2 decorator host — carries breadcrumb + agent-metric descriptors. */
|
|
39
42
|
session?: Pick<DashboardSession, "uiDecorators">;
|
|
43
|
+
/** Session id — threaded so child cards can render popout URLs and the
|
|
44
|
+
upper-slot question card can submit responses. See change: add-flow-agent-popout. */
|
|
45
|
+
sessionId?: string;
|
|
40
46
|
}) {
|
|
41
47
|
const isMobile = useMobile();
|
|
42
48
|
const [collapsed, setCollapsed] = useState(false);
|
|
@@ -83,10 +89,8 @@ export function FlowDashboard({
|
|
|
83
89
|
return (
|
|
84
90
|
<FlowSummary
|
|
85
91
|
flowState={flowState}
|
|
86
|
-
onAgentClick={onAgentClick}
|
|
87
92
|
onDismiss={onDismiss}
|
|
88
93
|
onSendPrompt={onSendPrompt}
|
|
89
|
-
onViewYaml={onViewYaml}
|
|
90
94
|
/>
|
|
91
95
|
);
|
|
92
96
|
}
|
|
@@ -187,18 +191,24 @@ export function FlowDashboard({
|
|
|
187
191
|
{/* Phase-2 breadcrumb decorator slot. See change: add-extension-ui-decorations. */}
|
|
188
192
|
<BreadcrumbSlot session={session} />
|
|
189
193
|
|
|
194
|
+
{/* Pending flow-question card — head of the per-flow FIFO queue.
|
|
195
|
+
See change: route-flow-asks-to-upper-slot. */}
|
|
196
|
+
{sessionId && (
|
|
197
|
+
<FlowQuestionsSection
|
|
198
|
+
sessionId={sessionId}
|
|
199
|
+
flowId={displayState.flowName}
|
|
200
|
+
/>
|
|
201
|
+
)}
|
|
202
|
+
|
|
190
203
|
<FlowGraph
|
|
191
204
|
steps={flowStateToGraphSteps(displayState)}
|
|
192
205
|
/>
|
|
193
|
-
{
|
|
206
|
+
{displayState.flowSource && (
|
|
194
207
|
<div className="mt-1">
|
|
195
|
-
<
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
>
|
|
200
|
-
<Icon path={mdiFileDocumentOutline} size={0.5} />
|
|
201
|
-
</button>
|
|
208
|
+
<FlowYamlPopoverButton
|
|
209
|
+
flowSource={displayState.flowSource}
|
|
210
|
+
flowName={displayState.flowName}
|
|
211
|
+
/>
|
|
202
212
|
</div>
|
|
203
213
|
)}
|
|
204
214
|
|
|
@@ -212,14 +222,8 @@ export function FlowDashboard({
|
|
|
212
222
|
key={agent.stepId || agent.agentName}
|
|
213
223
|
agent={agent}
|
|
214
224
|
session={session}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
onAgentClick(selectedAgent === key ? null : key);
|
|
218
|
-
}}
|
|
219
|
-
selected={selectedAgent === (agent.stepId || agent.agentName)}
|
|
220
|
-
isDetailOpen={selectedAgent === (agent.stepId || agent.agentName)}
|
|
221
|
-
isSourceOpen={sourceOpenAgent === (agent.label || agent.stepId || agent.agentName)}
|
|
222
|
-
onViewSource={agent.sourcePath && onViewAgentSource ? () => onViewAgentSource(agent.sourcePath!, agent.label || agent.stepId || agent.agentName) : undefined}
|
|
225
|
+
sessionId={sessionId}
|
|
226
|
+
flowId={displayState.flowName}
|
|
223
227
|
/>
|
|
224
228
|
))}
|
|
225
229
|
</div>
|
|
@@ -228,3 +232,162 @@ export function FlowDashboard({
|
|
|
228
232
|
</div>
|
|
229
233
|
);
|
|
230
234
|
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Renders the head of the per-flow `flow-question` queue. Derived from
|
|
238
|
+
* the shell's active interactive UI requests, filtered by component
|
|
239
|
+
* type `flow-question` and grouped by `flowId`. The first matching
|
|
240
|
+
* request is the head; queue depth shown as a "+N more queued" badge
|
|
241
|
+
* on the rendered card.
|
|
242
|
+
*
|
|
243
|
+
* Returns null when no flow-question is pending for `flowId`.
|
|
244
|
+
*
|
|
245
|
+
* See change: route-flow-asks-to-upper-slot.
|
|
246
|
+
*/
|
|
247
|
+
/** Most recent N transcript entries kept visible. See change: fix-flows-plugin-polish (C3). */
|
|
248
|
+
const FLOW_QUESTION_TRANSCRIPT_CAP = 10;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Renders the per-flow flow-question transcript above the agent grid.
|
|
252
|
+
*
|
|
253
|
+
* Includes ALL flow-question prompts for `flowId` — pending AND answered —
|
|
254
|
+
* in insertion order (oldest first), capped at {@link FLOW_QUESTION_TRANSCRIPT_CAP}.
|
|
255
|
+
* Pending entries render as the interactive `FlowQuestionCard`;
|
|
256
|
+
* answered/cancelled/dismissed entries render as a collapsed
|
|
257
|
+
* `FlowQuestionTranscriptPill`.
|
|
258
|
+
*
|
|
259
|
+
* Chat suppresses widget-bar prompts (B2) so the slot is the single visible
|
|
260
|
+
* site — no double-render.
|
|
261
|
+
*
|
|
262
|
+
* See change: fix-flows-plugin-polish (C3).
|
|
263
|
+
*/
|
|
264
|
+
function FlowQuestionsSection({
|
|
265
|
+
sessionId,
|
|
266
|
+
flowId,
|
|
267
|
+
}: {
|
|
268
|
+
sessionId: string;
|
|
269
|
+
flowId: string;
|
|
270
|
+
}) {
|
|
271
|
+
const requests = useSessionInteractiveRequests(sessionId);
|
|
272
|
+
const send = usePluginSend();
|
|
273
|
+
|
|
274
|
+
const queue = useMemo<InteractiveUiRequestSnapshot[]>(() => {
|
|
275
|
+
const out: InteractiveUiRequestSnapshot[] = [];
|
|
276
|
+
for (const req of requests) {
|
|
277
|
+
const cmp = req.params._promptBusComponent as
|
|
278
|
+
| { type?: string; props?: { flowId?: unknown } }
|
|
279
|
+
| undefined;
|
|
280
|
+
if (cmp?.type !== "flow-question") continue;
|
|
281
|
+
if (cmp?.props?.flowId !== flowId) continue;
|
|
282
|
+
out.push(req);
|
|
283
|
+
}
|
|
284
|
+
return out.slice(-FLOW_QUESTION_TRANSCRIPT_CAP);
|
|
285
|
+
}, [requests, flowId]);
|
|
286
|
+
|
|
287
|
+
if (queue.length === 0) return null;
|
|
288
|
+
|
|
289
|
+
const pendingCount = queue.filter((r) => r.status === "pending").length;
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<div data-testid="flow-questions-transcript" className="flex flex-col gap-1">
|
|
293
|
+
{queue.map((req) => {
|
|
294
|
+
const props =
|
|
295
|
+
(req.params._promptBusComponent as { props?: Record<string, unknown> }).props ?? {};
|
|
296
|
+
const question = typeof props.question === "string" ? props.question : "";
|
|
297
|
+
if (req.status === "pending") {
|
|
298
|
+
const submit = (answer: string) => {
|
|
299
|
+
send({
|
|
300
|
+
type: "prompt_response",
|
|
301
|
+
sessionId,
|
|
302
|
+
promptId: req.requestId,
|
|
303
|
+
answer,
|
|
304
|
+
source: "dashboard-flow-question",
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
const dismiss = () => {
|
|
308
|
+
send({ type: "prompt_cancel", sessionId, promptId: req.requestId });
|
|
309
|
+
};
|
|
310
|
+
return (
|
|
311
|
+
<FlowQuestionCard
|
|
312
|
+
key={req.requestId}
|
|
313
|
+
sessionId={sessionId}
|
|
314
|
+
promptId={req.requestId}
|
|
315
|
+
flowId={typeof props.flowId === "string" ? props.flowId : flowId}
|
|
316
|
+
stepId={typeof props.stepId === "string" ? props.stepId : ""}
|
|
317
|
+
question={question}
|
|
318
|
+
type={(props.type as FlowQuestionCardType) ?? "input"}
|
|
319
|
+
options={Array.isArray(props.options) ? (props.options as string[]) : undefined}
|
|
320
|
+
defaultValue={
|
|
321
|
+
typeof props.defaultValue === "string" ? props.defaultValue : undefined
|
|
322
|
+
}
|
|
323
|
+
queueDepth={pendingCount}
|
|
324
|
+
onSubmit={submit}
|
|
325
|
+
onDismiss={dismiss}
|
|
326
|
+
/>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
const answer = typeof req.result === "string" ? req.result : undefined;
|
|
330
|
+
return (
|
|
331
|
+
<FlowQuestionTranscriptPill
|
|
332
|
+
key={req.requestId}
|
|
333
|
+
question={question}
|
|
334
|
+
answer={answer}
|
|
335
|
+
status={req.status}
|
|
336
|
+
/>
|
|
337
|
+
);
|
|
338
|
+
})}
|
|
339
|
+
</div>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
type FlowQuestionCardType = "select" | "input" | "confirm" | "editor" | "multiselect";
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Slot-consumer wrapper for the `content-header-sticky` claim.
|
|
347
|
+
* Self-derives flow state from useFlowsSessionState; selection state
|
|
348
|
+
* and callbacks come from useFlowsUiState / pluginContext.send.
|
|
349
|
+
* Returns null when no flow is active. See change:
|
|
350
|
+
* pluginize-flows-via-registry.
|
|
351
|
+
*/
|
|
352
|
+
export function FlowDashboardClaim({ session }: { session: DashboardSession }) {
|
|
353
|
+
const { flowState, flowStates, architectState } = useFlowsSessionState(session.id);
|
|
354
|
+
const send = usePluginSend();
|
|
355
|
+
|
|
356
|
+
// Diagnostic logging — helps trace why the upper slot might be empty when
|
|
357
|
+
// a flow is running. Gated to dev builds. See change: fix-flows-plugin-polish (C1).
|
|
358
|
+
if (typeof import.meta !== "undefined" && (import.meta as { env?: { DEV?: boolean } }).env?.DEV) {
|
|
359
|
+
// eslint-disable-next-line no-console
|
|
360
|
+
console.debug(
|
|
361
|
+
"[flows] FlowDashboardClaim render",
|
|
362
|
+
{
|
|
363
|
+
sessionId: session.id,
|
|
364
|
+
hasFlowState: !!flowState,
|
|
365
|
+
flowName: flowState?.flowName,
|
|
366
|
+
flowStatus: flowState?.status,
|
|
367
|
+
flowsCount: flowStates.size,
|
|
368
|
+
hasArchitect: !!architectState,
|
|
369
|
+
architectPhase: architectState?.phase,
|
|
370
|
+
},
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (!flowState) return null;
|
|
375
|
+
|
|
376
|
+
const flowControl = (action: string) =>
|
|
377
|
+
send({ type: "flow_control", sessionId: session.id, action });
|
|
378
|
+
|
|
379
|
+
return (
|
|
380
|
+
<FlowDashboard
|
|
381
|
+
flowState={flowState}
|
|
382
|
+
flowStates={flowStates as Map<string, FlowState>}
|
|
383
|
+
session={session}
|
|
384
|
+
sessionId={session.id}
|
|
385
|
+
onAbort={() => flowControl("abort")}
|
|
386
|
+
onToggleAutonomous={() => flowControl("toggle_autonomous")}
|
|
387
|
+
onDismiss={() => flowControl("dismiss_summary")}
|
|
388
|
+
onSendPrompt={(text: string, images?: ImageContent[]) =>
|
|
389
|
+
send({ type: "send_prompt", sessionId: session.id, text, images })
|
|
390
|
+
}
|
|
391
|
+
/>
|
|
392
|
+
);
|
|
393
|
+
}
|
package/src/client/FlowGraph.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React, { useMemo, useRef, useState, useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// useZoomPan is a HOOK — it cannot go through the registry (Rules of Hooks).
|
|
3
|
+
// Stays as a direct import. See add-plugin-ui-primitive-registry Decision 4.
|
|
4
|
+
import { useZoomPan } from "@blackbelt-technology/pi-dashboard-client-utils/useZoomPan";
|
|
5
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
6
|
+
import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
4
7
|
import { graphlib } from "dagre-d3-es";
|
|
5
8
|
import { layout as dagreLayout } from "dagre-d3-es/src/dagre/index.js";
|
|
6
9
|
import type { FlowState, ArchitectDagStep } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
@@ -398,6 +401,7 @@ export function FlowGraph({ steps }: { steps: FlowGraphStep[] }) {
|
|
|
398
401
|
}
|
|
399
402
|
}, [steps]);
|
|
400
403
|
|
|
404
|
+
const ZoomControls = useUiPrimitive(UI_PRIMITIVE_KEYS.zoomControls);
|
|
401
405
|
const { state: zoom, handlers, zoomIn, zoomOut, reset } = useZoomPan();
|
|
402
406
|
const [hovered, setHovered] = useState(false);
|
|
403
407
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import React, { useState, useRef, useEffect } from "react";
|
|
2
2
|
import { Icon } from "@mdi/react";
|
|
3
3
|
import { mdiPlay } from "@mdi/js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
5
|
+
import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
6
|
+
// GateSlot is a slot CONSUMER and aggregateGateState is a pure helper —
|
|
7
|
+
// neither qualifies as a primitive. Direct import. See add-plugin-ui-primitive-
|
|
8
|
+
// registry Decision 4.
|
|
9
|
+
import { GateSlot, aggregateGateState } from "@blackbelt-technology/pi-dashboard-client-utils/extension-ui/GateSlot";
|
|
6
10
|
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
7
11
|
|
|
12
|
+
// Registry lookup hoisted into the exported component below — see body.
|
|
8
13
|
export function FlowLaunchDialog({
|
|
9
14
|
flowName,
|
|
10
15
|
description,
|
|
@@ -19,6 +24,7 @@ export function FlowLaunchDialog({
|
|
|
19
24
|
/** Phase-2 decorator host — used to gate the Run button when an extension declares the flow unavailable. */
|
|
20
25
|
session?: Pick<DashboardSession, "uiDecorators">;
|
|
21
26
|
}) {
|
|
27
|
+
const DialogPortal = useUiPrimitive(UI_PRIMITIVE_KEYS.dialogPortal);
|
|
22
28
|
// Phase-2 (`add-extension-ui-decorations`): aggregate any `gate` decorators
|
|
23
29
|
// targeting this flowId. Most-restrictive-wins: any `available: false`
|
|
24
30
|
// disables the Run button and renders the reason inline.
|
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
import React, { useState } from "react";
|
|
17
|
+
import { Icon } from "@mdi/react";
|
|
18
|
+
import { mdiClose, mdiHelpCircleOutline } from "@mdi/js";
|
|
19
|
+
|
|
20
|
+
export interface FlowQuestionCardProps {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
promptId: string;
|
|
23
|
+
flowId: string;
|
|
24
|
+
stepId: string;
|
|
25
|
+
question: string;
|
|
26
|
+
type: "select" | "input" | "confirm" | "editor" | "multiselect";
|
|
27
|
+
options?: string[];
|
|
28
|
+
defaultValue?: string;
|
|
29
|
+
/** Number of queued questions for this flow (head + queue). 0 or 1 hides the badge. */
|
|
30
|
+
queueDepth: number;
|
|
31
|
+
/** Dispatch `prompt_response`. */
|
|
32
|
+
onSubmit: (answer: string) => void;
|
|
33
|
+
/** Dispatch `prompt_cancel`. */
|
|
34
|
+
onDismiss: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function FlowQuestionCard({
|
|
38
|
+
question,
|
|
39
|
+
type,
|
|
40
|
+
options,
|
|
41
|
+
defaultValue,
|
|
42
|
+
queueDepth,
|
|
43
|
+
onSubmit,
|
|
44
|
+
onDismiss,
|
|
45
|
+
}: FlowQuestionCardProps) {
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
data-testid="flow-question-card"
|
|
49
|
+
className="mt-2 mb-2 p-3 border border-purple-500/40 bg-purple-500/5 rounded"
|
|
50
|
+
>
|
|
51
|
+
<div className="flex items-start gap-2 mb-2">
|
|
52
|
+
<Icon path={mdiHelpCircleOutline} size={0.7} className="text-purple-400 flex-shrink-0 mt-0.5" />
|
|
53
|
+
<div className="flex-1 min-w-0">
|
|
54
|
+
<div className="text-sm text-[var(--text-primary)] font-medium">{question}</div>
|
|
55
|
+
</div>
|
|
56
|
+
{queueDepth > 1 && (
|
|
57
|
+
<span className="text-[10px] text-purple-300 bg-purple-500/20 px-1.5 py-0.5 rounded flex-shrink-0">
|
|
58
|
+
+{queueDepth - 1} more queued
|
|
59
|
+
</span>
|
|
60
|
+
)}
|
|
61
|
+
<button
|
|
62
|
+
onClick={onDismiss}
|
|
63
|
+
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] flex-shrink-0"
|
|
64
|
+
title="Dismiss"
|
|
65
|
+
>
|
|
66
|
+
<Icon path={mdiClose} size={0.6} />
|
|
67
|
+
</button>
|
|
68
|
+
</div>
|
|
69
|
+
<FlowQuestionInput
|
|
70
|
+
type={type}
|
|
71
|
+
options={options}
|
|
72
|
+
defaultValue={defaultValue}
|
|
73
|
+
onSubmit={onSubmit}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function FlowQuestionInput({
|
|
80
|
+
type,
|
|
81
|
+
options,
|
|
82
|
+
defaultValue,
|
|
83
|
+
onSubmit,
|
|
84
|
+
}: {
|
|
85
|
+
type: FlowQuestionCardProps["type"];
|
|
86
|
+
options?: string[];
|
|
87
|
+
defaultValue?: string;
|
|
88
|
+
onSubmit: (answer: string) => void;
|
|
89
|
+
}) {
|
|
90
|
+
if (type === "confirm") return <ConfirmRow onSubmit={onSubmit} />;
|
|
91
|
+
if (type === "select") return <SelectRow options={options ?? []} onSubmit={onSubmit} />;
|
|
92
|
+
if (type === "multiselect") return <MultiselectRow options={options ?? []} onSubmit={onSubmit} />;
|
|
93
|
+
return <InputRow defaultValue={defaultValue} onSubmit={onSubmit} />;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function ConfirmRow({ onSubmit }: { onSubmit: (answer: string) => void }) {
|
|
97
|
+
return (
|
|
98
|
+
<div className="flex gap-2 justify-end">
|
|
99
|
+
<button
|
|
100
|
+
onClick={() => onSubmit("no")}
|
|
101
|
+
className="px-3 py-1 text-xs rounded border border-[var(--border-primary)] hover:bg-[var(--bg-surface)]"
|
|
102
|
+
>
|
|
103
|
+
No
|
|
104
|
+
</button>
|
|
105
|
+
<button
|
|
106
|
+
onClick={() => onSubmit("yes")}
|
|
107
|
+
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600"
|
|
108
|
+
>
|
|
109
|
+
Yes
|
|
110
|
+
</button>
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function SelectRow({
|
|
116
|
+
options,
|
|
117
|
+
onSubmit,
|
|
118
|
+
}: {
|
|
119
|
+
options: string[];
|
|
120
|
+
onSubmit: (answer: string) => void;
|
|
121
|
+
}) {
|
|
122
|
+
return (
|
|
123
|
+
<div className="flex flex-wrap gap-1.5">
|
|
124
|
+
{options.map((opt) => (
|
|
125
|
+
<button
|
|
126
|
+
key={opt}
|
|
127
|
+
onClick={() => onSubmit(opt)}
|
|
128
|
+
className="px-2.5 py-1 text-xs rounded border border-[var(--border-primary)] hover:bg-purple-500/10 hover:border-purple-500/40"
|
|
129
|
+
>
|
|
130
|
+
{opt}
|
|
131
|
+
</button>
|
|
132
|
+
))}
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function MultiselectRow({
|
|
138
|
+
options,
|
|
139
|
+
onSubmit,
|
|
140
|
+
}: {
|
|
141
|
+
options: string[];
|
|
142
|
+
onSubmit: (answer: string) => void;
|
|
143
|
+
}) {
|
|
144
|
+
const [picked, setPicked] = useState<Set<string>>(new Set());
|
|
145
|
+
const toggle = (opt: string) =>
|
|
146
|
+
setPicked((prev) => {
|
|
147
|
+
const next = new Set(prev);
|
|
148
|
+
if (next.has(opt)) next.delete(opt);
|
|
149
|
+
else next.add(opt);
|
|
150
|
+
return next;
|
|
151
|
+
});
|
|
152
|
+
return (
|
|
153
|
+
<div className="space-y-2">
|
|
154
|
+
<div className="flex flex-wrap gap-1.5">
|
|
155
|
+
{options.map((opt) => (
|
|
156
|
+
<button
|
|
157
|
+
key={opt}
|
|
158
|
+
onClick={() => toggle(opt)}
|
|
159
|
+
className={`px-2.5 py-1 text-xs rounded border ${
|
|
160
|
+
picked.has(opt)
|
|
161
|
+
? "bg-purple-500/20 border-purple-500"
|
|
162
|
+
: "border-[var(--border-primary)] hover:bg-purple-500/10 hover:border-purple-500/40"
|
|
163
|
+
}`}
|
|
164
|
+
>
|
|
165
|
+
{opt}
|
|
166
|
+
</button>
|
|
167
|
+
))}
|
|
168
|
+
</div>
|
|
169
|
+
<div className="flex justify-end">
|
|
170
|
+
<button
|
|
171
|
+
onClick={() => onSubmit(JSON.stringify(Array.from(picked)))}
|
|
172
|
+
disabled={picked.size === 0}
|
|
173
|
+
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
174
|
+
>
|
|
175
|
+
Submit ({picked.size})
|
|
176
|
+
</button>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function InputRow({
|
|
183
|
+
defaultValue,
|
|
184
|
+
onSubmit,
|
|
185
|
+
}: {
|
|
186
|
+
defaultValue?: string;
|
|
187
|
+
onSubmit: (answer: string) => void;
|
|
188
|
+
}) {
|
|
189
|
+
const [val, setVal] = useState(defaultValue ?? "");
|
|
190
|
+
return (
|
|
191
|
+
<form
|
|
192
|
+
onSubmit={(e) => {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
onSubmit(val);
|
|
195
|
+
}}
|
|
196
|
+
className="flex gap-2"
|
|
197
|
+
>
|
|
198
|
+
<input
|
|
199
|
+
autoFocus
|
|
200
|
+
type="text"
|
|
201
|
+
value={val}
|
|
202
|
+
onChange={(e) => setVal(e.target.value)}
|
|
203
|
+
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"
|
|
204
|
+
/>
|
|
205
|
+
<button
|
|
206
|
+
type="submit"
|
|
207
|
+
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600"
|
|
208
|
+
>
|
|
209
|
+
Submit
|
|
210
|
+
</button>
|
|
211
|
+
</form>
|
|
212
|
+
);
|
|
213
|
+
}
|