@blackbelt-technology/pi-dashboard-flows-plugin 0.5.3 → 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.
- package/package.json +48 -4
- package/src/AGENTS.md +8 -0
- package/src/__tests__/FlowGraph.test.ts +151 -5
- package/src/__tests__/FlowInputWiring.test.tsx +97 -0
- package/src/__tests__/FlowSummary.test.tsx +331 -0
- package/src/__tests__/FlowYamlPreview.test.tsx +75 -0
- package/src/__tests__/FlowsSessionStateContext.test.tsx +223 -0
- package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
- package/src/__tests__/authoring-renderers.test.tsx +190 -0
- package/src/__tests__/automation-actions.test.ts +117 -0
- package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
- package/src/__tests__/flow-agent-cost.test.tsx +160 -0
- package/src/__tests__/flow-agent-error.test.ts +60 -0
- package/src/__tests__/flow-collapse-storage.test.ts +90 -0
- package/src/__tests__/flow-edges.test.ts +195 -0
- package/src/__tests__/flow-inputs.test.ts +69 -0
- package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
- package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
- package/src/__tests__/flow-yaml-parse.test.ts +124 -0
- package/src/__tests__/flows-for-cwd.test.ts +51 -0
- package/src/__tests__/flowsAvailability.test.ts +79 -0
- package/src/__tests__/manifest-discoverability.test.ts +97 -0
- package/src/__tests__/node-kind-reducer.test.ts +135 -0
- package/src/__tests__/plugin-action-handler.test.ts +54 -0
- package/src/__tests__/render-actions.test.ts +63 -0
- package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
- package/src/bridge/AGENTS.md +8 -0
- package/src/bridge/flow-question-adapter.ts +93 -0
- package/src/bridge/index.ts +30 -0
- package/src/client/AGENTS.md +32 -0
- package/src/client/FlowActivityBadge.tsx +41 -11
- package/src/client/FlowAgentCard.tsx +321 -61
- package/src/client/FlowAgentDetail.tsx +103 -154
- package/src/client/FlowAgentsToolRenderer.tsx +228 -0
- package/src/client/FlowAuthorPromptDialog.tsx +92 -0
- package/src/client/FlowDashboard.tsx +271 -43
- package/src/client/FlowGraph.tsx +425 -276
- package/src/client/FlowInputWiring.tsx +243 -0
- package/src/client/FlowLaunchDialog.tsx +52 -52
- package/src/client/FlowQuestionCard.tsx +216 -0
- package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
- package/src/client/FlowSummary.tsx +285 -80
- package/src/client/FlowWriteToolRenderer.tsx +127 -0
- package/src/client/FlowYamlPopoverButton.tsx +110 -0
- package/src/client/FlowYamlPreview.tsx +67 -0
- package/src/client/FlowsCommandRoutes.tsx +237 -0
- package/src/client/FlowsSessionStateContext.tsx +142 -0
- package/src/client/FlowsSettings.tsx +68 -0
- package/src/client/FlowsUiStateContext.tsx +169 -0
- package/src/client/SessionFlowActions.tsx +172 -65
- package/src/client/flow-collapse-storage.ts +79 -0
- package/src/client/flow-edges.ts +173 -0
- package/src/client/flow-yaml-parse.ts +140 -0
- package/src/client/flowsAvailability.ts +44 -0
- package/src/client/index.tsx +95 -13
- package/src/client/shouldRender.ts +38 -0
- package/src/configSchema.json +14 -0
- package/src/flow-reducer.ts +94 -13
- package/src/i18n.ts +90 -0
- package/src/reducer.ts +5 -5
- package/src/server/AGENTS.md +10 -0
- package/src/server/automation-actions.ts +162 -0
- package/src/server/flow-inputs.ts +58 -0
- package/src/server/index.ts +171 -0
- package/src/server/render-actions.ts +88 -0
- package/src/server/state-store.ts +74 -0
- package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
- package/src/__tests__/architect-reducer.test.ts +0 -307
- package/src/architect-reducer.ts +0 -386
- package/src/client/FlowArchitect.tsx +0 -622
|
@@ -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,10 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
1
|
+
import { useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
2
|
+
// GateSlot is a slot CONSUMER and aggregateGateState is a pure helper —
|
|
3
|
+
// neither qualifies as a primitive. Direct import. See add-plugin-ui-primitive-
|
|
4
|
+
// registry Decision 4.
|
|
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";
|
|
6
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";
|
|
7
12
|
|
|
13
|
+
// Registry lookup hoisted into the exported component below — see body.
|
|
8
14
|
export function FlowLaunchDialog({
|
|
9
15
|
flowName,
|
|
10
16
|
description,
|
|
@@ -19,6 +25,8 @@ export function FlowLaunchDialog({
|
|
|
19
25
|
/** Phase-2 decorator host — used to gate the Run button when an extension declares the flow unavailable. */
|
|
20
26
|
session?: Pick<DashboardSession, "uiDecorators">;
|
|
21
27
|
}) {
|
|
28
|
+
const t = useT();
|
|
29
|
+
const Dialog = useUiPrimitive(UI_PRIMITIVE_KEYS.dialog);
|
|
22
30
|
// Phase-2 (`add-extension-ui-decorations`): aggregate any `gate` decorators
|
|
23
31
|
// targeting this flowId. Most-restrictive-wins: any `available: false`
|
|
24
32
|
// disables the Run button and renders the reason inline.
|
|
@@ -36,52 +44,44 @@ export function FlowLaunchDialog({
|
|
|
36
44
|
};
|
|
37
45
|
|
|
38
46
|
return (
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
>
|
|
79
|
-
<Icon path={mdiPlay} size={0.45} className="inline mr-0.5" />Run
|
|
80
|
-
</button>
|
|
81
|
-
</div>
|
|
82
|
-
</form>
|
|
83
|
-
</div>
|
|
84
|
-
</div>
|
|
85
|
-
</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>
|
|
86
86
|
);
|
|
87
87
|
}
|
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
|
|
17
|
+
import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
18
|
+
import { mdiClose, mdiHelpCircleOutline } from "@mdi/js";
|
|
19
|
+
import { Icon } from "@mdi/react";
|
|
20
|
+
import React, { useState } from "react";
|
|
21
|
+
|
|
22
|
+
export interface FlowQuestionCardProps {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
promptId: string;
|
|
25
|
+
flowId: string;
|
|
26
|
+
stepId: string;
|
|
27
|
+
question: string;
|
|
28
|
+
type: "select" | "input" | "confirm" | "editor" | "multiselect";
|
|
29
|
+
options?: string[];
|
|
30
|
+
defaultValue?: string;
|
|
31
|
+
/** Number of queued questions for this flow (head + queue). 0 or 1 hides the badge. */
|
|
32
|
+
queueDepth: number;
|
|
33
|
+
/** Dispatch `prompt_response`. */
|
|
34
|
+
onSubmit: (answer: string) => void;
|
|
35
|
+
/** Dispatch `prompt_cancel`. */
|
|
36
|
+
onDismiss: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function FlowQuestionCard({
|
|
40
|
+
question,
|
|
41
|
+
type,
|
|
42
|
+
options,
|
|
43
|
+
defaultValue,
|
|
44
|
+
queueDepth,
|
|
45
|
+
onSubmit,
|
|
46
|
+
onDismiss,
|
|
47
|
+
}: FlowQuestionCardProps) {
|
|
48
|
+
const t = useT();
|
|
49
|
+
return (
|
|
50
|
+
<div
|
|
51
|
+
data-testid="flow-question-card"
|
|
52
|
+
className="mt-2 mb-2 p-3 border border-purple-500/40 bg-purple-500/5 rounded"
|
|
53
|
+
>
|
|
54
|
+
<div className="flex items-start gap-2 mb-2">
|
|
55
|
+
<Icon path={mdiHelpCircleOutline} size={0.7} className="text-purple-400 flex-shrink-0 mt-0.5" />
|
|
56
|
+
<div className="flex-1 min-w-0">
|
|
57
|
+
<div className="text-sm text-[var(--text-primary)] font-medium">{question}</div>
|
|
58
|
+
</div>
|
|
59
|
+
{queueDepth > 1 && (
|
|
60
|
+
<span className="text-[10px] text-purple-300 bg-purple-500/20 px-1.5 py-0.5 rounded flex-shrink-0">
|
|
61
|
+
+{queueDepth - 1} more queued
|
|
62
|
+
</span>
|
|
63
|
+
)}
|
|
64
|
+
<button
|
|
65
|
+
onClick={onDismiss}
|
|
66
|
+
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] flex-shrink-0"
|
|
67
|
+
title={t("dismiss", undefined, "Dismiss")}
|
|
68
|
+
>
|
|
69
|
+
<Icon path={mdiClose} size={0.6} />
|
|
70
|
+
</button>
|
|
71
|
+
</div>
|
|
72
|
+
<FlowQuestionInput
|
|
73
|
+
type={type}
|
|
74
|
+
options={options}
|
|
75
|
+
defaultValue={defaultValue}
|
|
76
|
+
onSubmit={onSubmit}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function FlowQuestionInput({
|
|
83
|
+
type,
|
|
84
|
+
options,
|
|
85
|
+
defaultValue,
|
|
86
|
+
onSubmit,
|
|
87
|
+
}: {
|
|
88
|
+
type: FlowQuestionCardProps["type"];
|
|
89
|
+
options?: string[];
|
|
90
|
+
defaultValue?: string;
|
|
91
|
+
onSubmit: (answer: string) => void;
|
|
92
|
+
}) {
|
|
93
|
+
if (type === "confirm") return <ConfirmRow onSubmit={onSubmit} />;
|
|
94
|
+
if (type === "select") return <SelectRow options={options ?? []} onSubmit={onSubmit} />;
|
|
95
|
+
if (type === "multiselect") return <MultiselectRow options={options ?? []} onSubmit={onSubmit} />;
|
|
96
|
+
return <InputRow defaultValue={defaultValue} onSubmit={onSubmit} />;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function ConfirmRow({ onSubmit }: { onSubmit: (answer: string) => void }) {
|
|
100
|
+
return (
|
|
101
|
+
<div className="flex gap-2 justify-end">
|
|
102
|
+
<button
|
|
103
|
+
onClick={() => onSubmit("no")}
|
|
104
|
+
className="px-3 py-1 text-xs rounded border border-[var(--border-primary)] hover:bg-[var(--bg-surface)]"
|
|
105
|
+
>
|
|
106
|
+
No
|
|
107
|
+
</button>
|
|
108
|
+
<button
|
|
109
|
+
onClick={() => onSubmit("yes")}
|
|
110
|
+
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600"
|
|
111
|
+
>
|
|
112
|
+
Yes
|
|
113
|
+
</button>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function SelectRow({
|
|
119
|
+
options,
|
|
120
|
+
onSubmit,
|
|
121
|
+
}: {
|
|
122
|
+
options: string[];
|
|
123
|
+
onSubmit: (answer: string) => void;
|
|
124
|
+
}) {
|
|
125
|
+
return (
|
|
126
|
+
<div className="flex flex-wrap gap-1.5">
|
|
127
|
+
{options.map((opt) => (
|
|
128
|
+
<button
|
|
129
|
+
key={opt}
|
|
130
|
+
onClick={() => onSubmit(opt)}
|
|
131
|
+
className="px-2.5 py-1 text-xs rounded border border-[var(--border-primary)] hover:bg-purple-500/10 hover:border-purple-500/40"
|
|
132
|
+
>
|
|
133
|
+
{opt}
|
|
134
|
+
</button>
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function MultiselectRow({
|
|
141
|
+
options,
|
|
142
|
+
onSubmit,
|
|
143
|
+
}: {
|
|
144
|
+
options: string[];
|
|
145
|
+
onSubmit: (answer: string) => void;
|
|
146
|
+
}) {
|
|
147
|
+
const [picked, setPicked] = useState<Set<string>>(new Set());
|
|
148
|
+
const toggle = (opt: string) =>
|
|
149
|
+
setPicked((prev) => {
|
|
150
|
+
const next = new Set(prev);
|
|
151
|
+
if (next.has(opt)) next.delete(opt);
|
|
152
|
+
else next.add(opt);
|
|
153
|
+
return next;
|
|
154
|
+
});
|
|
155
|
+
return (
|
|
156
|
+
<div className="space-y-2">
|
|
157
|
+
<div className="flex flex-wrap gap-1.5">
|
|
158
|
+
{options.map((opt) => (
|
|
159
|
+
<button
|
|
160
|
+
key={opt}
|
|
161
|
+
onClick={() => toggle(opt)}
|
|
162
|
+
className={`px-2.5 py-1 text-xs rounded border ${
|
|
163
|
+
picked.has(opt)
|
|
164
|
+
? "bg-purple-500/20 border-purple-500"
|
|
165
|
+
: "border-[var(--border-primary)] hover:bg-purple-500/10 hover:border-purple-500/40"
|
|
166
|
+
}`}
|
|
167
|
+
>
|
|
168
|
+
{opt}
|
|
169
|
+
</button>
|
|
170
|
+
))}
|
|
171
|
+
</div>
|
|
172
|
+
<div className="flex justify-end">
|
|
173
|
+
<button
|
|
174
|
+
onClick={() => onSubmit(JSON.stringify(Array.from(picked)))}
|
|
175
|
+
disabled={picked.size === 0}
|
|
176
|
+
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
177
|
+
>
|
|
178
|
+
Submit ({picked.size})
|
|
179
|
+
</button>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function InputRow({
|
|
186
|
+
defaultValue,
|
|
187
|
+
onSubmit,
|
|
188
|
+
}: {
|
|
189
|
+
defaultValue?: string;
|
|
190
|
+
onSubmit: (answer: string) => void;
|
|
191
|
+
}) {
|
|
192
|
+
const [val, setVal] = useState(defaultValue ?? "");
|
|
193
|
+
return (
|
|
194
|
+
<form
|
|
195
|
+
onSubmit={(e) => {
|
|
196
|
+
e.preventDefault();
|
|
197
|
+
onSubmit(val);
|
|
198
|
+
}}
|
|
199
|
+
className="flex gap-2"
|
|
200
|
+
>
|
|
201
|
+
<input
|
|
202
|
+
autoFocus
|
|
203
|
+
type="text"
|
|
204
|
+
value={val}
|
|
205
|
+
onChange={(e) => setVal(e.target.value)}
|
|
206
|
+
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"
|
|
207
|
+
/>
|
|
208
|
+
<button
|
|
209
|
+
type="submit"
|
|
210
|
+
className="px-3 py-1 text-xs rounded bg-purple-500 text-white hover:bg-purple-600"
|
|
211
|
+
>
|
|
212
|
+
Submit
|
|
213
|
+
</button>
|
|
214
|
+
</form>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -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
|
+
}
|