@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.
Files changed (71) hide show
  1. package/README.md +5 -1
  2. package/package.json +23 -4
  3. package/src/bridge/flow-catalog-publisher.ts +138 -0
  4. package/src/bridge/flow-event-forward.ts +132 -0
  5. package/src/bridge/flow-files-reporter.ts +16 -14
  6. package/src/bridge/flow-open-tool.ts +124 -0
  7. package/src/bridge/flow-probe.ts +20 -0
  8. package/src/bridge/flow-tool-registry.ts +298 -0
  9. package/src/bridge/flow-tools-guideline.ts +52 -0
  10. package/src/bridge/index.ts +67 -10
  11. package/src/bridge/run-snapshot-reporter.ts +146 -0
  12. package/src/catalog-timings.ts +70 -0
  13. package/src/client/AskSession.tsx +82 -0
  14. package/src/client/FlowActionDialogs.tsx +143 -0
  15. package/src/client/FlowActivityBadge.tsx +42 -4
  16. package/src/client/FlowAgentCard.tsx +63 -8
  17. package/src/client/FlowAgentDetail.tsx +3 -5
  18. package/src/client/FlowDashboard.tsx +381 -273
  19. package/src/client/FlowEditMenu.tsx +69 -0
  20. package/src/client/FlowEditPopover.tsx +130 -0
  21. package/src/client/FlowGraph.tsx +127 -44
  22. package/src/client/FlowHeaderActions.tsx +83 -0
  23. package/src/client/FlowInputWiring.tsx +1 -1
  24. package/src/client/FlowOpenListener.tsx +82 -0
  25. package/src/client/FlowQuestionBlock.tsx +226 -0
  26. package/src/client/FlowStepCards.tsx +189 -0
  27. package/src/client/FlowSummary.tsx +72 -240
  28. package/src/client/FlowWriteToolRenderer.tsx +46 -17
  29. package/src/client/FlowYamlPopoverButton.tsx +2 -2
  30. package/src/client/FlowsContextGroup.tsx +156 -0
  31. package/src/client/FlowsSessionStateContext.tsx +202 -54
  32. package/src/client/FlowsSettings.tsx +145 -17
  33. package/src/client/SessionFlowActions.tsx +65 -10
  34. package/src/client/SessionFlowMenuClaim.tsx +48 -241
  35. package/src/client/ask-session-store.ts +243 -0
  36. package/src/client/flow-attach-store.ts +2 -0
  37. package/src/client/flow-card-grid.ts +2 -2
  38. package/src/client/flow-collapse-storage.ts +36 -6
  39. package/src/client/flow-edges.ts +91 -35
  40. package/src/client/flow-files.ts +16 -4
  41. package/src/client/flow-idle-state.ts +93 -37
  42. package/src/client/flowsActionsGate.ts +1 -1
  43. package/src/client/flowsAvailability.ts +8 -2
  44. package/src/client/index.tsx +13 -11
  45. package/src/client/shouldRender.ts +1 -1
  46. package/src/client/useEditModeState.ts +78 -0
  47. package/src/client/useFlowActions.tsx +191 -0
  48. package/src/client/useFlowCatalog.ts +69 -0
  49. package/src/client/useMinuteClock.ts +21 -0
  50. package/src/client/useRunReattach.ts +50 -0
  51. package/src/configSchema.json +37 -2
  52. package/src/flow-catalog-contract.ts +65 -0
  53. package/src/flow-questions.ts +138 -0
  54. package/src/flow-reducer.ts +434 -13
  55. package/src/flow-state-serialize.ts +132 -0
  56. package/src/i18n.ts +144 -6
  57. package/src/server/automation-actions.ts +4 -3
  58. package/src/server/edit-mode.ts +307 -0
  59. package/src/server/flow-catalog.ts +127 -0
  60. package/src/server/flow-control.ts +263 -0
  61. package/src/server/flow-files.ts +140 -14
  62. package/src/server/flow-open.ts +385 -0
  63. package/src/server/index.ts +112 -34
  64. package/src/server/render-actions.ts +3 -2
  65. package/src/server/state-store.ts +11 -5
  66. package/src/types.ts +180 -0
  67. package/src/bridge/flow-question-adapter.ts +0 -93
  68. package/src/client/FlowQuestionCard.tsx +0 -218
  69. package/src/client/FlowQuestionTranscriptPill.tsx +0 -58
  70. package/src/client/FlowsCommandRoutes.tsx +0 -245
  71. package/src/client/flow-yaml-parse.ts +0 -140
@@ -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
- }