@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.
Files changed (35) hide show
  1. package/package.json +39 -4
  2. package/src/__tests__/FlowsSessionStateContext.test.tsx +260 -0
  3. package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
  4. package/src/__tests__/flowsAvailability.test.ts +92 -0
  5. package/src/__tests__/manifest-discoverability.test.ts +97 -0
  6. package/src/__tests__/render-actions.test.ts +63 -0
  7. package/src/bridge/flow-question-adapter.ts +93 -0
  8. package/src/bridge/index.ts +30 -0
  9. package/src/client/FlowActivityBadge.tsx +36 -9
  10. package/src/client/FlowAgentCard.tsx +180 -41
  11. package/src/client/FlowAgentDetail.tsx +95 -154
  12. package/src/client/FlowAgentPopoutClaim.tsx +66 -0
  13. package/src/client/FlowAgentPopoutPage.tsx +177 -0
  14. package/src/client/FlowArchitect.tsx +297 -220
  15. package/src/client/FlowArchitectPopoutClaim.tsx +52 -0
  16. package/src/client/FlowArchitectPopoutPage.tsx +133 -0
  17. package/src/client/FlowDashboard.tsx +194 -31
  18. package/src/client/FlowGraph.tsx +6 -2
  19. package/src/client/FlowLaunchDialog.tsx +8 -2
  20. package/src/client/FlowQuestionCard.tsx +213 -0
  21. package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
  22. package/src/client/FlowSummary.tsx +43 -21
  23. package/src/client/FlowYamlPopoverButton.tsx +109 -0
  24. package/src/client/FlowYamlPreview.tsx +65 -0
  25. package/src/client/FlowsCommandRoutes.tsx +237 -0
  26. package/src/client/FlowsSessionStateContext.tsx +161 -0
  27. package/src/client/FlowsUiStateContext.tsx +169 -0
  28. package/src/client/SessionFlowActions.tsx +96 -5
  29. package/src/client/flowsAvailability.ts +103 -0
  30. package/src/client/index.tsx +94 -7
  31. package/src/client/popout-url.ts +59 -0
  32. package/src/client/shouldRender.ts +26 -0
  33. package/src/server/index.ts +87 -0
  34. package/src/server/render-actions.ts +88 -0
  35. package/src/server/state-store.ts +85 -0
@@ -0,0 +1,58 @@
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,14 +1,17 @@
1
1
  import React, { useState, type ReactNode } from "react";
2
2
  import { Icon } from "@mdi/react";
3
- import { mdiCloseCircleOutline, mdiCheckCircle, mdiAlertCircle, mdiStopCircle, mdiCloseCircle, mdiCircleOutline, mdiChevronRight, mdiChevronDown, mdiFileDocumentOutline } from "@mdi/js";
4
- import type { FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
3
+ import { mdiCloseCircleOutline, mdiCheckCircle, mdiAlertCircle, mdiStopCircle, mdiCloseCircle, mdiCircleOutline, mdiChevronRight, mdiChevronDown } from "@mdi/js";
4
+ import type { DashboardSession, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
5
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
6
+ import { useUiPrimitive, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime";
5
7
  import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
8
+ import { FlowYamlPopoverButton } from "./FlowYamlPopoverButton.js";
9
+ import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
10
+
11
+
12
+ // formatDuration moved to registry primitive lookup inside FlowSummary
13
+ // (PH-2 fix from validation report).
6
14
 
7
- function formatDuration(ms: number): string {
8
- const sec = Math.floor(ms / 1000);
9
- const min = Math.floor(sec / 60);
10
- return min > 0 ? `${min}m ${sec % 60}s` : `${sec}s`;
11
- }
12
15
 
13
16
  const statusConfig: Record<string, { icon: ReactNode; label: string; color: string }> = {
14
17
  success: { icon: <Icon path={mdiCheckCircle} size={0.55} />, label: "complete", color: "text-green-400" },
@@ -18,17 +21,14 @@ const statusConfig: Record<string, { icon: ReactNode; label: string; color: stri
18
21
 
19
22
  export function FlowSummary({
20
23
  flowState,
21
- onAgentClick,
22
24
  onDismiss,
23
25
  onSendPrompt,
24
- onViewYaml,
25
26
  }: {
26
27
  flowState: FlowState;
27
- onAgentClick: (agentName: string) => void;
28
28
  onDismiss: () => void;
29
29
  onSendPrompt?: (text: string) => void;
30
- onViewYaml?: () => void;
31
30
  }) {
31
+ const formatDuration = useUiPrimitive(UI_PRIMITIVE_KEYS.formatDuration);
32
32
  const [collapsed, setCollapsed] = useState(false);
33
33
  const agents = Array.from(flowState.agents.values());
34
34
  const { icon, label, color } = statusConfig[flowState.status] ?? statusConfig.success;
@@ -69,15 +69,12 @@ export function FlowSummary({
69
69
  <FlowGraph
70
70
  steps={flowStateToGraphSteps(flowState)}
71
71
  />
72
- {onViewYaml && (
72
+ {flowState.flowSource && (
73
73
  <div className="mt-1">
74
- <button
75
- onClick={onViewYaml}
76
- className="text-[var(--text-tertiary)] hover:text-blue-400 transition-colors p-0.5 rounded hover:bg-[var(--bg-surface)] inline-flex items-center"
77
- title="View flow YAML"
78
- >
79
- <Icon path={mdiFileDocumentOutline} size={0.5} />
80
- </button>
74
+ <FlowYamlPopoverButton
75
+ flowSource={flowState.flowSource}
76
+ flowName={flowState.flowName}
77
+ />
81
78
  </div>
82
79
  )}
83
80
 
@@ -97,8 +94,7 @@ export function FlowSummary({
97
94
  return (
98
95
  <div
99
96
  key={agent.stepId || agent.agentName}
100
- onClick={() => onAgentClick(agent.stepId || agent.agentName)}
101
- className="flex items-center gap-1.5 text-[11px] cursor-pointer hover:bg-[var(--bg-tertiary)] rounded px-1 py-0.5"
97
+ className="flex items-center gap-1.5 text-[11px] hover:bg-[var(--bg-tertiary)] rounded px-1 py-0.5"
102
98
  >
103
99
  <span className={`${agentColor} inline-flex`}><Icon path={agentIconPath} size={0.45} /></span>
104
100
  <span className="text-[var(--text-primary)]">{agent.label || agent.stepId || agent.agentName}</span>
@@ -135,3 +131,29 @@ export function FlowSummary({
135
131
  </div>
136
132
  );
137
133
  }
134
+
135
+ /**
136
+ * Slot-consumer wrapper for the `content-inline-footer` claim. Self-
137
+ * derives flow state, dispatches dismissal via pluginContext.send,
138
+ * navigates agent detail via the plugin-internal UI state context.
139
+ * Returns null when no flow is active. See change:
140
+ * pluginize-flows-via-registry.
141
+ */
142
+ export function FlowSummaryClaim({ session }: { session: DashboardSession }) {
143
+ const { flowState } = useFlowsSessionState(session.id);
144
+ const send = usePluginSend();
145
+
146
+ if (!flowState) return null;
147
+
148
+ return (
149
+ <FlowSummary
150
+ flowState={flowState}
151
+ onDismiss={() =>
152
+ send({ type: "flow_control", sessionId: session.id, action: "dismiss_summary" })
153
+ }
154
+ onSendPrompt={(text) =>
155
+ send({ type: "send_prompt", sessionId: session.id, text })
156
+ }
157
+ />
158
+ );
159
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * FlowYamlPopoverButton — paper-icon button that opens a popover anchored
3
+ * to itself, fetches the flow's YAML at `/api/pi-resource-file?path=...`,
4
+ * and renders it inside the popover via the `ui:markdown-content` primitive
5
+ * (wrapped in a `yaml` code fence for syntax highlighting).
6
+ *
7
+ * Used by `FlowDashboard` (live flow) and `FlowSummary` (completed flow).
8
+ *
9
+ * The flow's YAML path is emitted by pi-flows in the `flow:flow-started`
10
+ * event (see `packages/pi-flows/extensions/flow-engine/flow-tui.ts:487` —
11
+ * `source: flow.source`) and stored on `FlowState.flowSource` by the flow
12
+ * reducer.
13
+ *
14
+ * See change: add-ui-popover-primitive.
15
+ */
16
+ import React, { useEffect, useRef, useState } from "react";
17
+ import { Icon } from "@mdi/react";
18
+ import { mdiFileDocumentOutline } from "@mdi/js";
19
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
20
+ import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
21
+
22
+ type YamlFetchState =
23
+ | { kind: "idle" }
24
+ | { kind: "loading" }
25
+ | { kind: "loaded"; content: string }
26
+ | { kind: "error"; error: string };
27
+
28
+ export function FlowYamlPopoverButton({
29
+ flowSource,
30
+ flowName,
31
+ }: {
32
+ flowSource: string;
33
+ flowName: string;
34
+ }) {
35
+ const Popover = useUiPrimitive(UI_PRIMITIVE_KEYS.popover);
36
+ const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
37
+ const ref = useRef<HTMLButtonElement | null>(null);
38
+ const [open, setOpen] = useState(false);
39
+ const [state, setState] = useState<YamlFetchState>({ kind: "idle" });
40
+
41
+ // Deps include only `open` + `flowSource`. Including state.kind would
42
+ // cause cleanup to fire on the idle→loading transition, self-cancelling
43
+ // the fetch. Same pattern as `usePiResourceFileFetch` in the client.
44
+ useEffect(() => {
45
+ if (!open) return;
46
+ let cancelled = false;
47
+ setState({ kind: "loading" });
48
+ fetch(`/api/pi-resource-file?path=${encodeURIComponent(flowSource)}`)
49
+ .then(async (r) => {
50
+ const json = await r.json();
51
+ if (cancelled) return;
52
+ if (json?.success && typeof json?.data?.content === "string") {
53
+ setState({ kind: "loaded", content: json.data.content });
54
+ } else {
55
+ setState({
56
+ kind: "error",
57
+ error: typeof json?.error === "string" ? json.error : "Failed to read flow YAML",
58
+ });
59
+ }
60
+ })
61
+ .catch((err) => {
62
+ if (!cancelled) setState({ kind: "error", error: String(err) });
63
+ });
64
+ return () => {
65
+ cancelled = true;
66
+ };
67
+ }, [open, flowSource]);
68
+
69
+ return (
70
+ <>
71
+ <button
72
+ ref={ref}
73
+ onClick={(e) => {
74
+ e.stopPropagation();
75
+ setOpen((prev) => !prev);
76
+ }}
77
+ className={`transition-colors p-0.5 rounded inline-flex items-center ${
78
+ open
79
+ ? "text-blue-400 bg-blue-400/10"
80
+ : "text-[var(--text-tertiary)] hover:text-blue-400 hover:bg-[var(--bg-surface)]"
81
+ }`}
82
+ title={open ? "Close flow YAML" : `View ${flowName} YAML`}
83
+ >
84
+ <Icon path={mdiFileDocumentOutline} size={0.5} />
85
+ </button>
86
+ {open && ref.current && (
87
+ <Popover anchorEl={ref.current} onDismiss={() => setOpen(false)}>
88
+ <div
89
+ className="w-[640px] max-w-[90vw] max-h-[70vh] overflow-auto bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-xl p-3"
90
+ onClick={(e) => e.stopPropagation()}
91
+ >
92
+ <div className="text-[11px] text-[var(--text-tertiary)] mb-2 font-mono truncate" title={flowSource}>
93
+ {flowSource}
94
+ </div>
95
+ {state.kind === "loading" && (
96
+ <div className="text-xs text-[var(--text-muted)]">Loading…</div>
97
+ )}
98
+ {state.kind === "error" && (
99
+ <div className="text-xs text-red-400">⚠ {state.error}</div>
100
+ )}
101
+ {state.kind === "loaded" && (
102
+ <MarkdownContent content={"```yaml\n" + state.content + "\n```"} />
103
+ )}
104
+ </div>
105
+ </Popover>
106
+ )}
107
+ </>
108
+ );
109
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Content-view claim renderer for the flow YAML preview, gated by the
3
+ * `isFlowYamlPreviewActive` predicate.
4
+ *
5
+ * Replaces the shell's `flowYamlPreview` state + MarkdownPreviewView
6
+ * call site that App.tsx used to have. The content (yaml string +
7
+ * title) is set by the plugin's UI-state actions (see Part F.4 / F.5
8
+ * callbacks) when the user clicks "view yaml" or "view agent source".
9
+ *
10
+ * See change: pluginize-flows-via-registry (design.md Decision 3
11
+ * RECONSIDERED — predicates over routes).
12
+ */
13
+ import React from "react";
14
+ import { Icon } from "@mdi/react";
15
+ import { mdiArrowLeft } from "@mdi/js";
16
+ import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
17
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
18
+ import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
19
+ import { useFlowsUiState, useFlowsUiActions } from "./FlowsUiStateContext.js";
20
+
21
+ /**
22
+ * Slot-consumer wrapper for the `content-view` claim. Reads the
23
+ * preview content from the plugin's internal UI-state context. On
24
+ * dismiss, clears `flowYamlPreview` and `sourceOpenAgent` and calls
25
+ * the slot's `onClose`.
26
+ */
27
+ export function FlowYamlPreviewClaim({
28
+ onClose,
29
+ }: {
30
+ // session prop is part of the slot contract but unused here \u2014 the
31
+ // preview content is already in the plugin's UI-state context.
32
+ session: DashboardSession;
33
+ routeParams: Record<string, string>;
34
+ onClose: () => void;
35
+ }) {
36
+ const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
37
+ const { flowYamlPreview } = useFlowsUiState();
38
+ const actions = useFlowsUiActions();
39
+
40
+ if (!flowYamlPreview) return null;
41
+
42
+ const handleBack = () => {
43
+ actions.setFlowYamlPreview(null);
44
+ actions.setSourceOpenAgent(null);
45
+ onClose();
46
+ };
47
+
48
+ return (
49
+ <div className="flex flex-col h-full overflow-hidden">
50
+ <div className="px-3 py-2 border-b border-[var(--border-subtle)] bg-[var(--bg-secondary)] flex items-center gap-2">
51
+ <button
52
+ onClick={handleBack}
53
+ className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
54
+ title="Back"
55
+ >
56
+ <Icon path={mdiArrowLeft} size={0.7} />
57
+ </button>
58
+ <div className="font-medium text-sm truncate">{flowYamlPreview.title}</div>
59
+ </div>
60
+ <div className="flex-1 overflow-auto p-3">
61
+ <MarkdownContent content={flowYamlPreview.content} />
62
+ </div>
63
+ </div>
64
+ );
65
+ }
@@ -0,0 +1,237 @@
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
+
28
+ // ── Helpers ────────────────────────────────────────────────────────
29
+
30
+ function dispatchFlowAction(
31
+ send: (msg: unknown) => void,
32
+ sessionId: string,
33
+ action: string,
34
+ opts?: { flowName?: string; task?: string; description?: string },
35
+ ): void {
36
+ send({
37
+ type: "flow_management",
38
+ sessionId,
39
+ action,
40
+ flowName: opts?.flowName,
41
+ task: opts?.task,
42
+ description: opts?.description,
43
+ });
44
+ }
45
+
46
+ interface RouteProps {
47
+ session: DashboardSession;
48
+ routeParams: Record<string, string>;
49
+ onClose: () => void;
50
+ }
51
+
52
+ // ── /flows — main picker ───────────────────────────────────────────
53
+
54
+ /**
55
+ * Three-state machine: pick → launch (taskRequired) | direct-run.
56
+ * When the user picks a flow, either run it (no task required) and
57
+ * close, or open the launch dialog to capture a task.
58
+ */
59
+ export function FlowsListRoute({ session, onClose }: RouteProps) {
60
+ const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
61
+ const send = usePluginSend();
62
+ const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
63
+ const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
64
+ const [launchTarget, setLaunchTarget] = useState<FlowInfo | null>(null);
65
+
66
+ const hasFlowsNew = commands.some((c) => c.name === "flows:new");
67
+ const hasFlowsEdit = commands.some((c) => c.name === "flows:edit");
68
+ const hasFlowsDelete = commands.some((c) => c.name === "flows:delete");
69
+
70
+ if (launchTarget) {
71
+ return (
72
+ <FlowLaunchDialog
73
+ flowName={launchTarget.name}
74
+ description={launchTarget.description}
75
+ session={session}
76
+ onSubmit={(task) => {
77
+ dispatchFlowAction(send, session.id, "run", {
78
+ flowName: launchTarget.name,
79
+ task: task || undefined,
80
+ });
81
+ onClose();
82
+ }}
83
+ onCancel={() => {
84
+ setLaunchTarget(null);
85
+ onClose();
86
+ }}
87
+ />
88
+ );
89
+ }
90
+
91
+ const flowOptions: SelectOption[] = [
92
+ ...(hasFlowsNew
93
+ ? [{ value: "__new__", label: "+ New Flow", description: "Design a new flow with the Flow Architect" }]
94
+ : []),
95
+ ...(hasFlowsEdit && flows.length > 0
96
+ ? [{ value: "__edit__", label: "\u270E\uFE0E Edit Flow...", description: "Edit an existing flow" }]
97
+ : []),
98
+ ...(hasFlowsDelete && flows.length > 0
99
+ ? [{ value: "__delete__", label: "\u00D7 Delete Flow...", description: "Delete a saved flow" }]
100
+ : []),
101
+ ...flows.map((f) => ({ value: f.name, label: f.name, description: f.description })),
102
+ ];
103
+
104
+ return (
105
+ <SearchableSelectDialog
106
+ title="Flows"
107
+ options={flowOptions}
108
+ placeholder="Search flows..."
109
+ emptyMessage="No flows available"
110
+ onSelect={(value) => {
111
+ if (value === "__new__") {
112
+ // Send the user to the /flows:new route via pluginRouter.
113
+ // Until pluginRouter wiring lands, just open the new dialog
114
+ // inline by closing this and dispatching the new command.
115
+ send({ type: "send_prompt", sessionId: session.id, text: "/flows:new" });
116
+ onClose();
117
+ return;
118
+ }
119
+ if (value === "__edit__") {
120
+ send({ type: "send_prompt", sessionId: session.id, text: "/flows:edit" });
121
+ onClose();
122
+ return;
123
+ }
124
+ if (value === "__delete__") {
125
+ send({ type: "send_prompt", sessionId: session.id, text: "/flows:delete" });
126
+ onClose();
127
+ return;
128
+ }
129
+ const flow = flows.find((f) => f.name === value);
130
+ if (!flow) {
131
+ onClose();
132
+ return;
133
+ }
134
+ if (flow.taskRequired) {
135
+ setLaunchTarget(flow);
136
+ return;
137
+ }
138
+ dispatchFlowAction(send, session.id, "run", { flowName: flow.name });
139
+ onClose();
140
+ }}
141
+ onCancel={onClose}
142
+ />
143
+ );
144
+ }
145
+
146
+ // ── /flows:new ─────────────────────────────────────────────────────
147
+
148
+ export function FlowsNewRoute({ session, onClose }: RouteProps) {
149
+ const send = usePluginSend();
150
+ return (
151
+ <FlowLaunchDialog
152
+ flowName="flows:new"
153
+ description="Design a new flow with the Flow Architect"
154
+ onSubmit={(task) => {
155
+ if (task.trim()) {
156
+ dispatchFlowAction(send, session.id, "new", { description: task.trim() });
157
+ }
158
+ onClose();
159
+ }}
160
+ onCancel={onClose}
161
+ />
162
+ );
163
+ }
164
+
165
+ // ── /flows:edit ────────────────────────────────────────────────────
166
+
167
+ export function FlowsEditRoute({ session, onClose }: RouteProps) {
168
+ const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
169
+ const send = usePluginSend();
170
+ const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
171
+ const [editTarget, setEditTarget] = useState<string | null>(null);
172
+
173
+ if (editTarget) {
174
+ return (
175
+ <FlowLaunchDialog
176
+ flowName={editTarget}
177
+ description="Describe how this flow should be updated"
178
+ onSubmit={(desc) => {
179
+ if (desc.trim()) {
180
+ dispatchFlowAction(send, session.id, "edit", {
181
+ flowName: editTarget,
182
+ description: desc.trim(),
183
+ });
184
+ }
185
+ onClose();
186
+ }}
187
+ onCancel={onClose}
188
+ />
189
+ );
190
+ }
191
+
192
+ return (
193
+ <SearchableSelectDialog
194
+ title="Edit Flow"
195
+ options={flows.map((f) => ({ value: f.name, label: f.name, description: f.description }))}
196
+ placeholder="Search flows..."
197
+ emptyMessage="No flows available"
198
+ onSelect={(value) => setEditTarget(value)}
199
+ onCancel={onClose}
200
+ />
201
+ );
202
+ }
203
+
204
+ // ── /flows:delete ──────────────────────────────────────────────────
205
+
206
+ export function FlowsDeleteRoute({ session, onClose }: RouteProps) {
207
+ const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
208
+ const ConfirmDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.confirmDialog);
209
+ const send = usePluginSend();
210
+ const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
211
+ const [deleteTarget, setDeleteTarget] = useState<string | null>(null);
212
+
213
+ if (deleteTarget) {
214
+ return (
215
+ <ConfirmDialog
216
+ message={`Delete flow "${deleteTarget}"? This will remove the flow file and any associated agents.`}
217
+ confirmLabel="Delete"
218
+ onConfirm={() => {
219
+ dispatchFlowAction(send, session.id, "delete", { flowName: deleteTarget });
220
+ onClose();
221
+ }}
222
+ onCancel={onClose}
223
+ />
224
+ );
225
+ }
226
+
227
+ return (
228
+ <SearchableSelectDialog
229
+ title="Delete Flow"
230
+ options={flows.map((f) => ({ value: f.name, label: f.name, description: f.description }))}
231
+ placeholder="Search flows..."
232
+ emptyMessage="No flows available"
233
+ onSelect={(value) => setDeleteTarget(value)}
234
+ onCancel={onClose}
235
+ />
236
+ );
237
+ }