@blackbelt-technology/pi-dashboard-flows-plugin 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/package.json +25 -16
  2. package/src/AGENTS.md +8 -0
  3. package/src/__tests__/FlowGraph.test.ts +151 -5
  4. package/src/__tests__/FlowInputWiring.test.tsx +97 -0
  5. package/src/__tests__/FlowSummary.test.tsx +331 -0
  6. package/src/__tests__/FlowYamlPreview.test.tsx +75 -0
  7. package/src/__tests__/FlowsSessionStateContext.test.tsx +2 -39
  8. package/src/__tests__/authoring-renderers.test.tsx +190 -0
  9. package/src/__tests__/automation-actions.test.ts +117 -0
  10. package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
  11. package/src/__tests__/flow-agent-cost.test.tsx +160 -0
  12. package/src/__tests__/flow-agent-error.test.ts +60 -0
  13. package/src/__tests__/flow-collapse-storage.test.ts +90 -0
  14. package/src/__tests__/flow-edges.test.ts +195 -0
  15. package/src/__tests__/flow-inputs.test.ts +69 -0
  16. package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
  17. package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
  18. package/src/__tests__/flow-yaml-parse.test.ts +124 -0
  19. package/src/__tests__/flows-for-cwd.test.ts +51 -0
  20. package/src/__tests__/flowsAvailability.test.ts +51 -64
  21. package/src/__tests__/node-kind-reducer.test.ts +135 -0
  22. package/src/__tests__/plugin-action-handler.test.ts +54 -0
  23. package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
  24. package/src/bridge/AGENTS.md +8 -0
  25. package/src/client/AGENTS.md +32 -0
  26. package/src/client/FlowActivityBadge.tsx +8 -5
  27. package/src/client/FlowAgentCard.tsx +231 -110
  28. package/src/client/FlowAgentDetail.tsx +20 -12
  29. package/src/client/FlowAgentsToolRenderer.tsx +228 -0
  30. package/src/client/FlowAuthorPromptDialog.tsx +92 -0
  31. package/src/client/FlowDashboard.tsx +88 -23
  32. package/src/client/FlowGraph.tsx +420 -275
  33. package/src/client/FlowInputWiring.tsx +243 -0
  34. package/src/client/FlowLaunchDialog.tsx +48 -54
  35. package/src/client/FlowQuestionCard.tsx +6 -3
  36. package/src/client/FlowSummary.tsx +252 -69
  37. package/src/client/FlowWriteToolRenderer.tsx +127 -0
  38. package/src/client/FlowYamlPopoverButton.tsx +26 -25
  39. package/src/client/FlowYamlPreview.tsx +9 -7
  40. package/src/client/FlowsSessionStateContext.tsx +14 -33
  41. package/src/client/FlowsSettings.tsx +68 -0
  42. package/src/client/SessionFlowActions.tsx +92 -76
  43. package/src/client/flow-collapse-storage.ts +79 -0
  44. package/src/client/flow-edges.ts +173 -0
  45. package/src/client/flow-yaml-parse.ts +140 -0
  46. package/src/client/flowsAvailability.ts +28 -87
  47. package/src/client/index.tsx +27 -32
  48. package/src/client/shouldRender.ts +24 -12
  49. package/src/configSchema.json +14 -0
  50. package/src/flow-reducer.ts +94 -13
  51. package/src/i18n.ts +90 -0
  52. package/src/reducer.ts +5 -5
  53. package/src/server/AGENTS.md +10 -0
  54. package/src/server/automation-actions.ts +162 -0
  55. package/src/server/flow-inputs.ts +58 -0
  56. package/src/server/index.ts +93 -9
  57. package/src/server/state-store.ts +3 -14
  58. package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
  59. package/src/__tests__/architect-reducer.test.ts +0 -307
  60. package/src/architect-reducer.ts +0 -386
  61. package/src/client/FlowAgentPopoutClaim.tsx +0 -66
  62. package/src/client/FlowAgentPopoutPage.tsx +0 -177
  63. package/src/client/FlowArchitect.tsx +0 -699
  64. package/src/client/FlowArchitectPopoutClaim.tsx +0 -52
  65. package/src/client/FlowArchitectPopoutPage.tsx +0 -133
  66. package/src/client/popout-url.ts +0 -59
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Input-wiring editor for the `flows.run` automation action.
3
+ *
4
+ * Claimed into the automation-plugin's `automation-action-editor` slot
5
+ * (keyed by `config.actionId: "flows.run"`). The create-automation dialog
6
+ * renders it additively below the generic flow + task form.
7
+ *
8
+ * Reads the selected flow's declared `inputs:` schema read-only from
9
+ * `GET /api/plugins/flows/flow-inputs?cwd=&flow=` and renders one wiring row
10
+ * per declared input. Each row binds either a typed literal or the trigger's
11
+ * fired value (`${{trigger}}`). Writes ONLY `payload.inputs` back via
12
+ * `onChange`; never writes a `flow.yaml`.
13
+ *
14
+ * UX: collapsible disclosure, collapsed by default (only flow + task surface
15
+ * initially). Auto-expands when a required input is unbound so a run is never
16
+ * silently blocked.
17
+ *
18
+ * See change: wire-flow-inputs-in-automation.
19
+ */
20
+
21
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
22
+ import type React from "react";
23
+ import { useEffect, useMemo, useRef, useState } from "react";
24
+
25
+ /** The canonical trigger-binding token (mirrors pi-flows `${{…}}` syntax). */
26
+ const TRIGGER_TOKEN = "${{trigger}}";
27
+
28
+ type FlowInputType = "string" | "number" | "boolean" | "object" | "array";
29
+ interface FlowInputField {
30
+ name: string;
31
+ type: FlowInputType;
32
+ required: boolean;
33
+ }
34
+
35
+ export interface FlowInputWiringProps {
36
+ /** Current action payload. `payload.flow` selects the flow; `payload.inputs` holds wired values. */
37
+ payload: Record<string, unknown>;
38
+ /** Persist an updated payload (only `payload.inputs` is mutated here). */
39
+ onChange: (payload: Record<string, unknown>) => void;
40
+ /** Run cwd — scopes the read-only flow-inputs discovery. */
41
+ cwd?: string;
42
+ }
43
+
44
+ /** Read `payload.inputs` as a plain object (else `{}`). */
45
+ function readInputs(payload: Record<string, unknown>): Record<string, unknown> {
46
+ const inp = payload.inputs;
47
+ return inp && typeof inp === "object" && !Array.isArray(inp)
48
+ ? { ...(inp as Record<string, unknown>) }
49
+ : {};
50
+ }
51
+
52
+ /** Coerce a raw string literal to the input's declared type (D4). */
53
+ function coerceLiteral(raw: string, type: FlowInputType): unknown {
54
+ switch (type) {
55
+ case "number": {
56
+ if (raw.trim() === "") return "";
57
+ const n = Number(raw);
58
+ return Number.isNaN(n) ? raw : n;
59
+ }
60
+ case "boolean":
61
+ return raw === "true";
62
+ case "object":
63
+ case "array":
64
+ try {
65
+ return JSON.parse(raw);
66
+ } catch {
67
+ return raw;
68
+ }
69
+ default:
70
+ return raw;
71
+ }
72
+ }
73
+
74
+ /** A value is "unbound" when absent or an empty string literal. */
75
+ function isUnbound(v: unknown): boolean {
76
+ return v === undefined || v === null || v === "";
77
+ }
78
+
79
+ export function FlowInputWiring({ payload, onChange, cwd }: FlowInputWiringProps): React.ReactElement | null {
80
+ const t = useT();
81
+ const flow = typeof payload.flow === "string" ? payload.flow : "";
82
+ const [fields, setFields] = useState<FlowInputField[]>([]);
83
+ const [loading, setLoading] = useState(false);
84
+ // `null` = follow the auto-expand heuristic; a boolean = the user's choice.
85
+ const [openOverride, setOpenOverride] = useState<boolean | null>(null);
86
+
87
+ const inputs = readInputs(payload);
88
+ // Keep the latest payload/onChange in a ref so the fetch effect can prune
89
+ // orphan keys without listing them as deps (avoids a re-fetch loop).
90
+ const latest = useRef({ payload, onChange });
91
+ latest.current = { payload, onChange };
92
+
93
+ useEffect(() => {
94
+ if (!flow) {
95
+ setFields([]);
96
+ return;
97
+ }
98
+ let cancelled = false;
99
+ setLoading(true);
100
+ const qs = new URLSearchParams({ flow, ...(cwd ? { cwd } : {}) }).toString();
101
+ fetch(`/api/plugins/flows/flow-inputs?${qs}`)
102
+ .then((r) => (r.ok ? r.json() : { inputs: [] }))
103
+ .then((data: { inputs?: FlowInputField[] }) => {
104
+ if (cancelled) return;
105
+ const next = Array.isArray(data.inputs) ? data.inputs : [];
106
+ setFields(next);
107
+ // Drop wired keys the new flow no longer declares (6.4), with a warning.
108
+ const declared = new Set(next.map((f) => f.name));
109
+ const cur = readInputs(latest.current.payload);
110
+ const dropped = Object.keys(cur).filter((k) => !declared.has(k));
111
+ if (dropped.length > 0) {
112
+ // eslint-disable-next-line no-console
113
+ console.warn(`[flows] dropping orphan wired inputs not declared by ${flow}: ${dropped.join(", ")}`);
114
+ const pruned: Record<string, unknown> = {};
115
+ for (const [k, v] of Object.entries(cur)) if (declared.has(k)) pruned[k] = v;
116
+ latest.current.onChange({ ...latest.current.payload, inputs: pruned });
117
+ }
118
+ })
119
+ .catch(() => {
120
+ if (!cancelled) setFields([]);
121
+ })
122
+ .finally(() => {
123
+ if (!cancelled) setLoading(false);
124
+ });
125
+ return () => {
126
+ cancelled = true;
127
+ };
128
+ }, [flow, cwd]);
129
+
130
+ const boundCount = useMemo(
131
+ () => fields.filter((f) => inputs[f.name] === TRIGGER_TOKEN).length,
132
+ [fields, inputs],
133
+ );
134
+ const requiredUnbound = fields.some((f) => f.required && isUnbound(inputs[f.name]));
135
+ const open = openOverride ?? requiredUnbound;
136
+
137
+ function setInput(name: string, value: unknown): void {
138
+ const next = readInputs(payload);
139
+ if (value === "" || value === undefined) delete next[name];
140
+ else next[name] = value;
141
+ onChange({ ...payload, inputs: next });
142
+ }
143
+
144
+ if (!flow || (fields.length === 0 && !loading)) return null;
145
+
146
+ return (
147
+ <details
148
+ className="mt-2 border-t border-[var(--border-secondary)] pt-2"
149
+ open={open}
150
+ onToggle={(e) => setOpenOverride((e.currentTarget as HTMLDetailsElement).open)}
151
+ data-testid="flow-input-wiring"
152
+ >
153
+ <summary className="flex cursor-pointer select-none items-center gap-2 text-[11px] text-[var(--text-secondary)]">
154
+ <span>{t("inputs", undefined, "Inputs")}</span>
155
+ <span className="rounded-full border border-[var(--border-secondary)] px-1.5 text-[9px] font-mono text-[var(--text-muted)]">
156
+ {fields.length}
157
+ </span>
158
+ <span className="ml-auto font-mono text-[9.5px] text-[var(--text-muted)]" data-testid="flow-input-wiring-hint">
159
+ from {flow}
160
+ {boundCount > 0 ? ` · ${boundCount} bound to trigger` : ""}
161
+ </span>
162
+ </summary>
163
+
164
+ <div className="mt-2 space-y-2" data-testid="flow-input-wiring-rows">
165
+ {fields.map((f) => {
166
+ const raw = inputs[f.name];
167
+ const boundToTrigger = raw === TRIGGER_TOKEN;
168
+ return (
169
+ <label key={f.name} className="block text-xs text-[var(--text-secondary)]">
170
+ <span className="mb-0.5 block">
171
+ {f.name}
172
+ <span className="ml-1.5 font-mono text-[9px] text-[var(--text-muted)]">{f.type}</span>
173
+ {f.required && <span className="text-[var(--danger,#ef4444)]"> *</span>}
174
+ </span>
175
+ <div className="flex items-stretch gap-1.5">
176
+ <div className="inline-flex overflow-hidden rounded border border-[var(--border-secondary)]">
177
+ <button
178
+ type="button"
179
+ data-testid={`flow-input-${f.name}-mode-literal`}
180
+ onClick={() => setInput(f.name, f.type === "boolean" ? false : "")}
181
+ className={`px-2 text-[10px] ${
182
+ boundToTrigger
183
+ ? "text-[var(--text-secondary)]"
184
+ : "bg-[var(--accent,#6366f1)] text-white"
185
+ }`}
186
+ >
187
+ literal
188
+ </button>
189
+ <button
190
+ type="button"
191
+ data-testid={`flow-input-${f.name}-mode-trigger`}
192
+ onClick={() => setInput(f.name, TRIGGER_TOKEN)}
193
+ className={`border-l border-[var(--border-secondary)] px-2 text-[10px] ${
194
+ boundToTrigger
195
+ ? "bg-[var(--accent,#6366f1)] text-white"
196
+ : "text-[var(--text-secondary)]"
197
+ }`}
198
+ >
199
+ trigger
200
+ </button>
201
+ </div>
202
+ {boundToTrigger ? (
203
+ <span
204
+ className="flex flex-1 items-center rounded border border-[#0d425c] bg-[#06283a] px-2 font-mono text-[11.5px] text-[var(--cyan,#22d3ee)]"
205
+ data-testid={`flow-input-${f.name}-trigger`}
206
+ >
207
+ {TRIGGER_TOKEN} · the file that fired
208
+ </span>
209
+ ) : f.type === "boolean" ? (
210
+ <select
211
+ value={raw === true ? "true" : "false"}
212
+ onChange={(e) => setInput(f.name, e.target.value === "true")}
213
+ data-testid={`flow-input-${f.name}`}
214
+ className="input flex-1"
215
+ >
216
+ <option value="false">false</option>
217
+ <option value="true">true</option>
218
+ </select>
219
+ ) : (
220
+ <input
221
+ type={f.type === "number" ? "number" : "text"}
222
+ value={raw == null ? "" : String(raw)}
223
+ onChange={(e) => setInput(f.name, coerceLiteral(e.target.value, f.type))}
224
+ placeholder={f.type === "object" || f.type === "array" ? "JSON" : ""}
225
+ data-testid={`flow-input-${f.name}`}
226
+ className="input flex-1 font-mono"
227
+ />
228
+ )}
229
+ </div>
230
+ </label>
231
+ );
232
+ })}
233
+ <p className="text-[9.5px] text-[var(--text-muted)]">
234
+ Bind <b>trigger</b> to pass the fired file path · <b>literal</b> for a fixed typed value · leave an optional
235
+ input blank to skip it.
236
+ </p>
237
+ </div>
238
+ </details>
239
+ );
240
+ }
241
+
242
+ /** Slot-claim export referenced by the flows-plugin manifest. */
243
+ export const FlowInputWiringClaim = FlowInputWiring;
@@ -1,13 +1,14 @@
1
- import React, { useState, useRef, useEffect } from "react";
2
- import { Icon } from "@mdi/react";
3
- import { mdiPlay } from "@mdi/js";
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";
1
+ import { useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
6
2
  // GateSlot is a slot CONSUMER and aggregateGateState is a pure helper —
7
3
  // neither qualifies as a primitive. Direct import. See add-plugin-ui-primitive-
8
4
  // registry Decision 4.
9
- import { GateSlot, aggregateGateState } from "@blackbelt-technology/pi-dashboard-client-utils/extension-ui/GateSlot";
5
+ import { aggregateGateState, GateSlot } from "@blackbelt-technology/pi-dashboard-client-utils/extension-ui/GateSlot";
6
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
10
7
  import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
8
+ import { mdiPlay } from "@mdi/js";
9
+ import { Icon } from "@mdi/react";
10
+ import type React from "react";
11
+ import { useEffect, useRef, useState } from "react";
11
12
 
12
13
  // Registry lookup hoisted into the exported component below — see body.
13
14
  export function FlowLaunchDialog({
@@ -24,7 +25,8 @@ export function FlowLaunchDialog({
24
25
  /** Phase-2 decorator host — used to gate the Run button when an extension declares the flow unavailable. */
25
26
  session?: Pick<DashboardSession, "uiDecorators">;
26
27
  }) {
27
- const DialogPortal = useUiPrimitive(UI_PRIMITIVE_KEYS.dialogPortal);
28
+ const t = useT();
29
+ const Dialog = useUiPrimitive(UI_PRIMITIVE_KEYS.dialog);
28
30
  // Phase-2 (`add-extension-ui-decorations`): aggregate any `gate` decorators
29
31
  // targeting this flowId. Most-restrictive-wins: any `available: false`
30
32
  // disables the Run button and renders the reason inline.
@@ -42,52 +44,44 @@ export function FlowLaunchDialog({
42
44
  };
43
45
 
44
46
  return (
45
- <DialogPortal>
46
- <div className="fixed inset-0 z-[60] flex items-center justify-center">
47
- <div className="absolute inset-0 bg-[var(--bg-overlay)]" onClick={onCancel} />
48
- <div className="relative bg-[var(--bg-secondary)] rounded-xl border border-[var(--border-subtle)] shadow-2xl p-4 w-[90vw] max-w-md">
49
- <h3 className="text-sm font-medium text-[var(--text-primary)] mb-1">
50
- Run Flow: {flowName}
51
- </h3>
52
- {description && (
53
- <p className="text-[11px] text-[var(--text-tertiary)] mb-3">{description}</p>
54
- )}
55
- {/* Phase-2 gate decorator slot. See change: add-extension-ui-decorations. */}
56
- <GateSlot session={session} flowId={flowName} />
57
- <form onSubmit={handleSubmit}>
58
- <input
59
- ref={inputRef}
60
- type="text"
61
- value={task}
62
- onChange={(e) => setTask(e.target.value)}
63
- placeholder="Describe the task (optional)..."
64
- className="w-full px-3 py-2 text-sm bg-[var(--bg-tertiary)] border border-[var(--border-subtle)] rounded-lg text-[var(--text-primary)] placeholder:text-[var(--text-muted)] focus:outline-none focus:border-blue-500/50"
65
- />
66
- <div className="flex justify-end gap-2 mt-3">
67
- <button
68
- type="button"
69
- onClick={onCancel}
70
- className="text-xs px-3 py-1.5 rounded-lg border border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"
71
- >
72
- Cancel
73
- </button>
74
- <button
75
- type="submit"
76
- disabled={!gateState.available}
77
- title={gateState.available ? undefined : gateState.reason}
78
- className={`text-xs px-3 py-1.5 rounded-lg ${
79
- gateState.available
80
- ? "bg-blue-600 text-white hover:bg-blue-500"
81
- : "bg-[var(--bg-tertiary)] text-[var(--text-muted)] cursor-not-allowed"
82
- }`}
83
- data-testid="flow-launch-run"
84
- >
85
- <Icon path={mdiPlay} size={0.45} className="inline mr-0.5" />Run
86
- </button>
87
- </div>
88
- </form>
89
- </div>
90
- </div>
91
- </DialogPortal>
47
+ <Dialog
48
+ open
49
+ onClose={onCancel}
50
+ title={t("runFlowTitle", { flowName }, `Run Flow: ${flowName}`)}
51
+ size="md"
52
+ testId="flow-launch-dialog"
53
+ >
54
+ {description && (
55
+ <p className="text-[11px] text-[var(--text-tertiary)]">{description}</p>
56
+ )}
57
+ {/* Phase-2 gate decorator slot. See change: add-extension-ui-decorations. */}
58
+ <GateSlot session={session} flowId={flowName} />
59
+ <form onSubmit={handleSubmit} className="space-y-3">
60
+ <input
61
+ ref={inputRef}
62
+ type="text"
63
+ value={task}
64
+ onChange={(e) => setTask(e.target.value)}
65
+ placeholder={t("taskPlaceholder", undefined, "Describe the task (optional)...")}
66
+ className="w-full px-3 py-2 text-sm bg-[var(--bg-tertiary)] border border-[var(--border-subtle)] rounded-lg text-[var(--text-primary)] placeholder:text-[var(--text-muted)] focus:outline-none focus:border-blue-500/50"
67
+ />
68
+ <Dialog.Footer>
69
+ <Dialog.Cancel onClick={onCancel} />
70
+ <button
71
+ type="submit"
72
+ disabled={!gateState.available}
73
+ title={gateState.available ? undefined : gateState.reason}
74
+ className={`text-xs px-3 py-1.5 rounded transition-colors ${
75
+ gateState.available
76
+ ? "bg-[var(--accent-primary)] text-white hover:opacity-90"
77
+ : "bg-[var(--bg-tertiary)] text-[var(--text-muted)] cursor-not-allowed"
78
+ }`}
79
+ data-testid="flow-launch-run"
80
+ >
81
+ <Icon path={mdiPlay} size={0.45} className="inline mr-0.5" />{t("run", undefined, "Run")}
82
+ </button>
83
+ </Dialog.Footer>
84
+ </form>
85
+ </Dialog>
92
86
  );
93
87
  }
@@ -13,9 +13,11 @@
13
13
  *
14
14
  * See change: route-flow-asks-to-upper-slot.
15
15
  */
16
- import React, { useState } from "react";
17
- import { Icon } from "@mdi/react";
16
+
17
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
18
18
  import { mdiClose, mdiHelpCircleOutline } from "@mdi/js";
19
+ import { Icon } from "@mdi/react";
20
+ import React, { useState } from "react";
19
21
 
20
22
  export interface FlowQuestionCardProps {
21
23
  sessionId: string;
@@ -43,6 +45,7 @@ export function FlowQuestionCard({
43
45
  onSubmit,
44
46
  onDismiss,
45
47
  }: FlowQuestionCardProps) {
48
+ const t = useT();
46
49
  return (
47
50
  <div
48
51
  data-testid="flow-question-card"
@@ -61,7 +64,7 @@ export function FlowQuestionCard({
61
64
  <button
62
65
  onClick={onDismiss}
63
66
  className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] flex-shrink-0"
64
- title="Dismiss"
67
+ title={t("dismiss", undefined, "Dismiss")}
65
68
  >
66
69
  <Icon path={mdiClose} size={0.6} />
67
70
  </button>