@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,140 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flow-event probe backing part of flows-plugin's `shouldRenderFlowsSubcard`
|
|
3
|
+
* predicate.
|
|
4
|
+
*
|
|
5
|
+
* The former per-session availability cache (populated from `commandsList` via a
|
|
6
|
+
* module-level subscriber) is retired: the gate now reads live per-session-data
|
|
7
|
+
* + plugin config directly in `shouldRender.ts`, so a mirrored cache is no
|
|
8
|
+
* longer needed. Only the flow-event memo survives here.
|
|
9
|
+
*
|
|
10
|
+
* See change: fix-empty-flows-subcard.
|
|
11
|
+
*/
|
|
12
|
+
import { getSessionEvents } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
13
|
+
import { isFlowEvent } from "../reducer.js";
|
|
14
|
+
|
|
15
|
+
// Per-session memo for "has this session seen any flow event?". Keyed on the
|
|
16
|
+
// session-events array reference (stable until the next publish) so the scan
|
|
17
|
+
// runs only when the event list grows; once true it stays true (flow events
|
|
18
|
+
// are append-only). Lets the FLOWS subcard reattach on cold load after replay,
|
|
19
|
+
// where the `flowsList`/`commandsList` availability signal is NOT replayed and
|
|
20
|
+
// is closed-by-default. See change: replay-persisted-flow-runs (task 5.5).
|
|
21
|
+
const flowEventMemo = new Map<string, { ref: readonly unknown[]; has: boolean }>();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* True when the session's replayed/live event stream contains any `flow_*`
|
|
25
|
+
* event. Synchronous, cheap (ref-memoized + sticky-true), safe to call from
|
|
26
|
+
* the `shouldRenderFlowsSubcard` predicate.
|
|
27
|
+
*/
|
|
28
|
+
export function sessionHasFlowEvents(sessionId: string): boolean {
|
|
29
|
+
const events = getSessionEvents(sessionId);
|
|
30
|
+
const cached = flowEventMemo.get(sessionId);
|
|
31
|
+
if (cached && (cached.has || cached.ref === events)) return cached.has;
|
|
32
|
+
const has = events.some((e) => isFlowEvent((e as { eventType: string }).eventType));
|
|
33
|
+
flowEventMemo.set(sessionId, { ref: events, has });
|
|
34
|
+
return has;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Test-only: clear the flow-event memo so cases start from a clean slate.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export function __resetFlowsAvailabilityForTests(): void {
|
|
43
|
+
flowEventMemo.clear();
|
|
44
|
+
}
|
package/src/client/index.tsx
CHANGED
|
@@ -7,23 +7,105 @@
|
|
|
7
7
|
* Also exports the `hasActiveFlow` predicate consumed by the
|
|
8
8
|
* `pi-dashboard-plugin` manifest's `session-card-badge` claim.
|
|
9
9
|
*/
|
|
10
|
-
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
// Existing presentation components — still used directly by App.tsx
|
|
13
|
+
// during the cutover (Part H removes those call sites).
|
|
14
|
+
// i18n catalog — merged under `plugin.flows.*` by the shell via the
|
|
15
|
+
// manifest's `i18nCatalog: "catalog"` declaration. See change: make-all-ui-text-i18n.
|
|
16
|
+
export { catalog } from "../i18n.js";
|
|
17
|
+
export { FlowActivityBadge } from "./FlowActivityBadge.js";
|
|
13
18
|
export { FlowAgentCard } from "./FlowAgentCard.js";
|
|
14
19
|
export { FlowAgentDetail } from "./FlowAgentDetail.js";
|
|
15
|
-
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
export { FlowAgentsToolRenderer } from "./FlowAgentsToolRenderer.js";
|
|
21
|
+
// Slot-claim wrappers — the plugin's manifest references these.
|
|
22
|
+
// Each derives state from the plugin-internal contexts and dispatches
|
|
23
|
+
// via pluginContext.send. See change: pluginize-flows-via-registry.
|
|
24
|
+
// FlowActivityBadgeClaim removed in fix-flows-plugin-polish (A5) — the
|
|
25
|
+
// session-card-badge claim was dropped because the badge belongs in the
|
|
26
|
+
// FLOWS subcard, not WORKSPACE. SessionFlowActions now renders the badge
|
|
27
|
+
// directly via the FlowActivityBadge component.
|
|
28
|
+
export { FlowDashboard, FlowDashboardClaim } from "./FlowDashboard.js";
|
|
29
|
+
export { computeLayout, FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
|
|
30
|
+
// Input-wiring editor claimed into automation-plugin's `automation-action-editor`
|
|
31
|
+
// slot for `flows.run`. See change: wire-flow-inputs-in-automation.
|
|
32
|
+
export { FlowInputWiring, FlowInputWiringClaim } from "./FlowInputWiring.js";
|
|
19
33
|
export { FlowLaunchDialog } from "./FlowLaunchDialog.js";
|
|
34
|
+
export { FlowSummary, FlowSummaryClaim } from "./FlowSummary.js";
|
|
35
|
+
export type { FlowsPluginConfig } from "./FlowsSettings.js";
|
|
36
|
+
|
|
37
|
+
// Settings section (global edit-mode default) — manifest `settings-section` claim.
|
|
38
|
+
export { FlowsSettings } from "./FlowsSettings.js";
|
|
20
39
|
export { FlowTabBar } from "./FlowTabBar.js";
|
|
21
|
-
|
|
40
|
+
// Authoring tool-renderers (main-session timeline) — referenced by the
|
|
41
|
+
// manifest's `tool-renderer` claims. See change: rework-flows-plugin-for-new-pi-flows.
|
|
42
|
+
export { FlowWriteToolRenderer } from "./FlowWriteToolRenderer.js";
|
|
43
|
+
export { FlowYamlPreviewClaim } from "./FlowYamlPreview.js";
|
|
44
|
+
export { SessionFlowActions, SessionFlowActionsClaim } from "./SessionFlowActions.js";
|
|
22
45
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
// Manifest-level shouldRender predicate for the `session-card-flows` claim.
|
|
47
|
+
// See change: add-flows-subcard.
|
|
48
|
+
export { shouldRenderFlowsSubcard } from "./shouldRender.js";
|
|
49
|
+
|
|
50
|
+
// Flow slash commands (`/flows`, `/flows:new`, `/flows:edit`, `/flows:delete`)
|
|
51
|
+
// are no longer claimed by the dashboard plugin manifest. Flow operations
|
|
52
|
+
// surface through buttons only (`SessionFlowActions`, `FlowLaunchDialog`,
|
|
53
|
+
// `FlowDashboard` Abort). pi-flows itself continues to register the slash
|
|
54
|
+
// commands for TUI users. See change: fix-pi-flows-end-to-end (Group 8).
|
|
55
|
+
//
|
|
56
|
+
// The FlowsCommandRoutes module is no longer exported from this barrel.
|
|
57
|
+
// Restore the exports here if/when the dashboard re-introduces command-route
|
|
58
|
+
// claims for flows.
|
|
59
|
+
|
|
60
|
+
export type { FlowsSessionState } from "./FlowsSessionStateContext.js";
|
|
61
|
+
// Plugin-internal state hooks. Components consume these in place of
|
|
62
|
+
// props that previously came from App.tsx. See change:
|
|
63
|
+
// pluginize-flows-via-registry.
|
|
64
|
+
export {
|
|
65
|
+
reduceFlowsSessionState,
|
|
66
|
+
useFlowsSessionState,
|
|
67
|
+
} from "./FlowsSessionStateContext.js";
|
|
68
|
+
|
|
69
|
+
import { registerPromptComponent } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
70
|
+
import { getFlowsUiStateSnapshot } from "./FlowsUiStateContext.js";
|
|
71
|
+
|
|
72
|
+
// Register the `flow-question` prompt component type so the shell knows to
|
|
73
|
+
// route flow-tagged prompts to the widget-bar placement instead of inline
|
|
74
|
+
// chat. Idempotent under HMR — `registerPromptComponent` replaces prior
|
|
75
|
+
// entries without throwing. See change: route-flow-asks-to-upper-slot.
|
|
76
|
+
registerPromptComponent({ type: "flow-question", placement: "widget-bar" });
|
|
77
|
+
|
|
78
|
+
export type { FlowsUiActions, FlowsUiState } from "./FlowsUiStateContext.js";
|
|
79
|
+
export {getFlowsUiStateSnapshot,
|
|
80
|
+
useFlowsUiActions,
|
|
81
|
+
useFlowsUiState
|
|
82
|
+
} from "./FlowsUiStateContext.js";
|
|
83
|
+
|
|
84
|
+
// hasActiveFlow predicate removed: the manifest no longer references
|
|
85
|
+
// it because FlowActivityBadgeClaim self-gates inside the component
|
|
86
|
+
// body via useFlowsSessionState. See change:
|
|
87
|
+
// pluginize-flows-via-registry.
|
|
88
|
+
|
|
89
|
+
// ── content-view claim predicates ─────────────────────────────────
|
|
90
|
+
//
|
|
91
|
+
// Each `content-view` claim in the manifest references one of these
|
|
92
|
+
// predicates via the `predicate` field. The slot consumer calls the
|
|
93
|
+
// predicate at render time; the first claim (priority order) whose
|
|
94
|
+
// predicate returns `true` renders. If none return `true`, the slot
|
|
95
|
+
// renders nothing and the shell's fallback shows the chat.
|
|
96
|
+
//
|
|
97
|
+
// Each predicate reads the plugin's UI-state store imperatively (via
|
|
98
|
+
// `getFlowsUiStateSnapshot` — not a hook, safe outside React) so it
|
|
99
|
+
// can run from the slot-registry filter. The `_session` argument is
|
|
100
|
+
// passed by the slot system per the predicate contract
|
|
101
|
+
// (`(props) => boolean`) but is unused here because activation lives
|
|
102
|
+
// in plugin state, not session state.
|
|
103
|
+
//
|
|
104
|
+
// See change: pluginize-flows-via-registry (design.md Decision 3
|
|
105
|
+
// RECONSIDERED — predicates over routes).
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
export function isFlowYamlPreviewActive(_session?: unknown): boolean {
|
|
110
|
+
return getFlowsUiStateSnapshot().flowYamlPreview !== null;
|
|
29
111
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifest-level `shouldRender` callback for flows-plugin's
|
|
3
|
+
* `session-card-flows` claim (`SessionFlowActionsClaim`).
|
|
4
|
+
*
|
|
5
|
+
* Returns the SAME boolean the claim uses to decide it renders content:
|
|
6
|
+
* `flowsList non-empty OR edit mode on OR a flow event exists`. This keeps the
|
|
7
|
+
* subcard's visibility gate and the claim's render condition in lockstep, so the
|
|
8
|
+
* shell's `FlowsSubcard` wrapper (which gates on `useSlotHasClaimsForSession`,
|
|
9
|
+
* consulting this predicate) never paints an empty panel when the claim would
|
|
10
|
+
* render `null`.
|
|
11
|
+
*
|
|
12
|
+
* Must be synchronous and side-effect-free (manifest-level `shouldRender`
|
|
13
|
+
* contract). Reads live per-session-data (`getSessionData`) + plugin config
|
|
14
|
+
* (`getPluginConfig`) directly — the same synchronous sources the claim reads —
|
|
15
|
+
* instead of a mirrored availability cache. Closed-by-default holds: on cold
|
|
16
|
+
* boot `flowsList` is empty, edit mode off, no events → `false` → hidden, then
|
|
17
|
+
* visible once flows populate (the acceptable hidden→visible direction).
|
|
18
|
+
*
|
|
19
|
+
* See change: fix-empty-flows-subcard.
|
|
20
|
+
*/
|
|
21
|
+
import { getSessionData } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
22
|
+
import { getPluginConfig } from "@blackbelt-technology/dashboard-plugin-runtime/context";
|
|
23
|
+
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
24
|
+
import type { FlowInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
25
|
+
import { sessionHasFlowEvents } from "./flowsAvailability.js";
|
|
26
|
+
|
|
27
|
+
export function shouldRenderFlowsSubcard(
|
|
28
|
+
session: DashboardSession | null | undefined,
|
|
29
|
+
): boolean {
|
|
30
|
+
if (!session) return false;
|
|
31
|
+
const flows = getSessionData<FlowInfo[]>(session.id, "flowsList");
|
|
32
|
+
const editMode = (getPluginConfig("flows") as { editFlow?: boolean }).editFlow ?? false;
|
|
33
|
+
return (
|
|
34
|
+
(Array.isArray(flows) && flows.length > 0) ||
|
|
35
|
+
editMode ||
|
|
36
|
+
sessionHasFlowEvents(session.id)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Flows plugin configuration",
|
|
4
|
+
"description": "Per-plugin (global) configuration for the flows-plugin. The edit-mode default is reconciled down to each session (via flow:set-edit-mode) when that session's flows plugin becomes available. See change: rework-flows-plugin-for-new-pi-flows.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"editFlow": {
|
|
9
|
+
"type": "boolean",
|
|
10
|
+
"default": false,
|
|
11
|
+
"description": "Global default for pi-flows `flows.editFlow`. When on, the main session sees the edit-flow skill and the flow_agents / flow_write authoring tools."
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/flow-reducer.ts
CHANGED
|
@@ -4,13 +4,34 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type {
|
|
6
6
|
DashboardEvent,
|
|
7
|
+
FlowAgentCardConfig,
|
|
7
8
|
FlowAgentState,
|
|
8
9
|
FlowDetailEntry,
|
|
9
10
|
FlowRecentTool,
|
|
10
11
|
FlowState,
|
|
11
|
-
|
|
12
|
+
NodeKind,
|
|
12
13
|
} from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
13
14
|
|
|
15
|
+
/** Map a flow-config stepType to a NodeKind for provisional pre-listing at
|
|
16
|
+
* flow_started. The authoritative nodeKind arrives on the started event. */
|
|
17
|
+
function stepTypeToNodeKind(stepType: string | undefined): NodeKind | undefined {
|
|
18
|
+
switch (stepType) {
|
|
19
|
+
case "agent":
|
|
20
|
+
case "agent-decision":
|
|
21
|
+
case "code":
|
|
22
|
+
case "code-decision":
|
|
23
|
+
case "fork":
|
|
24
|
+
return stepType;
|
|
25
|
+
default:
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Step kinds that render as a card (have no agent but still get a node card). */
|
|
31
|
+
function isCardableNonAgentKind(nodeKind: NodeKind | undefined): boolean {
|
|
32
|
+
return nodeKind === "code" || nodeKind === "code-decision";
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
/** Extract a short input preview for tool call display */
|
|
15
36
|
function extractToolInputPreview(toolName: string, input: unknown): string {
|
|
16
37
|
if (!input || typeof input !== "object") return "";
|
|
@@ -82,20 +103,23 @@ export function reduceFlowEvent(
|
|
|
82
103
|
stepType: string;
|
|
83
104
|
agent?: string;
|
|
84
105
|
blockedBy?: string[];
|
|
85
|
-
|
|
86
|
-
|
|
106
|
+
branches?: Record<string, string>;
|
|
107
|
+
onComplete?: string;
|
|
108
|
+
onError?: string;
|
|
87
109
|
}> | undefined;
|
|
88
110
|
const agents = new Map<string, FlowAgentState>();
|
|
89
111
|
if (steps) {
|
|
90
112
|
for (const step of steps) {
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
113
|
+
const nodeKind = stepTypeToNodeKind(step.stepType);
|
|
114
|
+
// Pre-list a pending card for agent-bearing steps AND for code/
|
|
115
|
+
// code-decision steps (which have no agent but still render a card).
|
|
116
|
+
// Keeps the grid consistent live and on replay (task 2.6).
|
|
117
|
+
if (step.agent || isCardableNonAgentKind(nodeKind)) {
|
|
95
118
|
agents.set(step.id, {
|
|
96
|
-
agentName: step.agent,
|
|
119
|
+
agentName: step.agent || step.id,
|
|
97
120
|
stepId: step.id,
|
|
98
121
|
stepType: step.stepType,
|
|
122
|
+
nodeKind,
|
|
99
123
|
status: "pending",
|
|
100
124
|
blockedBy: step.blockedBy || [],
|
|
101
125
|
recentTools: [],
|
|
@@ -104,14 +128,20 @@ export function reduceFlowEvent(
|
|
|
104
128
|
}
|
|
105
129
|
}
|
|
106
130
|
}
|
|
107
|
-
// Store all steps for DAG graph (including non-agent types)
|
|
131
|
+
// Store all steps for DAG graph (including non-agent types). `branches`
|
|
132
|
+
// carries decision routing so the live graph can draw branch/loop edges;
|
|
133
|
+
// `onComplete`/`onError` carry forward/error routing so on_complete-wired
|
|
134
|
+
// flows draw `route` edges live (not just in the static Mermaid). Absent
|
|
135
|
+
// fields (older pi-flows) → no route edges, same as before.
|
|
136
|
+
// See change: fix-flow-ui-graph-zoom-summary.
|
|
108
137
|
const dagSteps = steps?.map(step => ({
|
|
109
138
|
id: step.id,
|
|
110
139
|
stepType: step.stepType,
|
|
111
140
|
agent: step.agent,
|
|
112
141
|
blockedBy: step.blockedBy || [],
|
|
113
|
-
|
|
114
|
-
|
|
142
|
+
branches: step.branches,
|
|
143
|
+
onComplete: step.onComplete,
|
|
144
|
+
onError: step.onError,
|
|
115
145
|
}));
|
|
116
146
|
|
|
117
147
|
return {
|
|
@@ -144,6 +174,11 @@ export function reduceFlowEvent(
|
|
|
144
174
|
}),
|
|
145
175
|
...(isRerun ? { recentTools: [], detailHistory: [] } : {}),
|
|
146
176
|
status: "running",
|
|
177
|
+
// nodeKind is decided ONCE here at started (surface-node-kind contract).
|
|
178
|
+
// Fall back to the provisional kind from flow_started, else "agent".
|
|
179
|
+
nodeKind: (data.nodeKind as NodeKind | undefined) ?? existing?.nodeKind ?? "agent",
|
|
180
|
+
// Resolved handler target for code / code-decision nodes (started only).
|
|
181
|
+
codeTarget: (data.target as string | undefined) ?? existing?.codeTarget,
|
|
147
182
|
label: config?.card?.label,
|
|
148
183
|
model: config?.model,
|
|
149
184
|
resolvedModel: (data.resolvedModel as string) || undefined,
|
|
@@ -164,18 +199,31 @@ export function reduceFlowEvent(
|
|
|
164
199
|
summary?: string;
|
|
165
200
|
files?: string[];
|
|
166
201
|
tokens?: { input: number; output: number };
|
|
202
|
+
cost?: number;
|
|
167
203
|
duration?: number;
|
|
204
|
+
outcome?: "success" | "soft" | "hard";
|
|
205
|
+
typedOutputs?: Record<string, string>;
|
|
168
206
|
} | undefined;
|
|
169
207
|
const agents = new Map(flowState.agents);
|
|
170
208
|
const [key, existing] = findAgent(agents, agentName, stepId);
|
|
171
209
|
if (key && existing) {
|
|
210
|
+
const typedOutputs = result?.typedOutputs;
|
|
211
|
+
// outcome may ride on the result or the event data; default success.
|
|
212
|
+
const outcome =
|
|
213
|
+
result?.outcome ?? (data.outcome as "success" | "soft" | "hard" | undefined) ??
|
|
214
|
+
(result?.success ? "success" : "soft");
|
|
172
215
|
agents.set(key, {
|
|
173
216
|
...existing,
|
|
174
217
|
status: result?.status === "blocked" ? "blocked" : result?.success ? "complete" : "error",
|
|
175
218
|
tokens: result?.tokens,
|
|
219
|
+
cost: result?.cost,
|
|
176
220
|
duration: result?.duration,
|
|
177
221
|
summary: result?.summary,
|
|
178
222
|
files: result?.files,
|
|
223
|
+
outcome,
|
|
224
|
+
typedOutputs,
|
|
225
|
+
// code-decision exposes the chosen branch via typedOutputs.branch.
|
|
226
|
+
branch: typedOutputs?.branch ?? (data.branch as string | undefined) ?? existing.branch,
|
|
179
227
|
});
|
|
180
228
|
}
|
|
181
229
|
return { ...flowState, agents };
|
|
@@ -264,6 +312,26 @@ export function reduceFlowEvent(
|
|
|
264
312
|
return { ...flowState, agents };
|
|
265
313
|
}
|
|
266
314
|
|
|
315
|
+
case "flow_agent_error": {
|
|
316
|
+
if (!flowState) return null;
|
|
317
|
+
const agentName = data.agentName as string;
|
|
318
|
+
const stepId = data.stepId as string | undefined;
|
|
319
|
+
const text = data.text as string;
|
|
320
|
+
if (!text) return flowState;
|
|
321
|
+
const agents = new Map(flowState.agents);
|
|
322
|
+
const [key, existing] = findAgent(agents, agentName, stepId);
|
|
323
|
+
if (key && existing) {
|
|
324
|
+
// Append an error entry to the agent timeline. Status is owned by
|
|
325
|
+
// flow_agent_complete — do not change it here.
|
|
326
|
+
const detailHistory: FlowDetailEntry[] = [
|
|
327
|
+
...existing.detailHistory,
|
|
328
|
+
{ kind: "error", text },
|
|
329
|
+
];
|
|
330
|
+
agents.set(key, { ...existing, detailHistory });
|
|
331
|
+
}
|
|
332
|
+
return { ...flowState, agents };
|
|
333
|
+
}
|
|
334
|
+
|
|
267
335
|
case "flow_loop_iteration": {
|
|
268
336
|
if (!flowState) return null;
|
|
269
337
|
const loopTarget = data.loopTarget as string;
|
|
@@ -288,10 +356,23 @@ export function reduceFlowEvent(
|
|
|
288
356
|
|
|
289
357
|
case "flow_complete": {
|
|
290
358
|
if (!flowState) return null;
|
|
291
|
-
const status = (data.status as string) || "success";
|
|
359
|
+
const status = ((data.status as string) || "success") as FlowState["status"];
|
|
360
|
+
// When the flow ends non-successfully (error / aborted / interrupted),
|
|
361
|
+
// downgrade any step left running/pending so its card does not spin
|
|
362
|
+
// forever (task 3.6; covers the synthesized interrupted terminal).
|
|
363
|
+
let agents = flowState.agents;
|
|
364
|
+
if (status !== "success") {
|
|
365
|
+
agents = new Map(flowState.agents);
|
|
366
|
+
for (const [k, a] of agents) {
|
|
367
|
+
if (a.status === "running" || a.status === "pending") {
|
|
368
|
+
agents.set(k, { ...a, status: "error", outcome: a.outcome ?? "hard" });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
292
372
|
return {
|
|
293
373
|
...flowState,
|
|
294
|
-
status
|
|
374
|
+
status,
|
|
375
|
+
agents,
|
|
295
376
|
flowResult: data as Record<string, unknown>,
|
|
296
377
|
};
|
|
297
378
|
}
|
package/src/i18n.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flows plugin i18n catalog — UNPREFIXED leaf keys.
|
|
3
|
+
*
|
|
4
|
+
* The generated plugin registry imports the `catalog` named export (declared
|
|
5
|
+
* as `i18nCatalog` in package.json's `pi-dashboard-plugin` manifest) and the
|
|
6
|
+
* shell merges it under `plugin.flows.*`. Component code resolves keys via the
|
|
7
|
+
* scoped `useT()` hook, which auto-prefixes `plugin.flows.`.
|
|
8
|
+
*
|
|
9
|
+
* zh-CN and hu MUST keep parity (identical key sets). {var} placeholders are
|
|
10
|
+
* preserved verbatim so `t(key, vars)` can interpolate.
|
|
11
|
+
*
|
|
12
|
+
* See change: make-all-ui-text-i18n.
|
|
13
|
+
*/
|
|
14
|
+
export const catalog = {
|
|
15
|
+
"zh-CN": {
|
|
16
|
+
abort: "中止",
|
|
17
|
+
delete: "删除",
|
|
18
|
+
run: "运行",
|
|
19
|
+
abortRunningFlow: "中止正在运行的流程",
|
|
20
|
+
back: "返回",
|
|
21
|
+
expandGraph: "展开图表",
|
|
22
|
+
flowGraph: "流程图",
|
|
23
|
+
result: "结果",
|
|
24
|
+
inputs: "输入",
|
|
25
|
+
dismiss: "关闭",
|
|
26
|
+
flowsHeading: "流程",
|
|
27
|
+
editModeLabel: "编辑模式",
|
|
28
|
+
runFlowTitle: "运行流程:{flowName}",
|
|
29
|
+
taskPlaceholder: "描述任务(可选)…",
|
|
30
|
+
summary: "摘要",
|
|
31
|
+
waitingToStart: "等待开始…",
|
|
32
|
+
noActivityYet: "暂无活动",
|
|
33
|
+
closeAgentDetail: "关闭 {name} 详情",
|
|
34
|
+
viewAgentDetail: "查看 {name} 详情",
|
|
35
|
+
details: "详情",
|
|
36
|
+
stepsCount: "{done}/{total} 个步骤",
|
|
37
|
+
toggleAutonomousMode: "切换自主模式",
|
|
38
|
+
abortFlow: "中止流程",
|
|
39
|
+
newFlowOption: "+ 新建流程",
|
|
40
|
+
newFlowOptionDesc: "使用 edit-flow 技能创建新流程",
|
|
41
|
+
runFlowButton: "运行流程…",
|
|
42
|
+
newEditButton: "新建 / 编辑…",
|
|
43
|
+
runFlowDialogTitle: "运行流程",
|
|
44
|
+
searchFlows: "搜索流程…",
|
|
45
|
+
noFlowsAvailable: "没有可用的流程",
|
|
46
|
+
newEditFlowTitle: "新建 / 编辑流程",
|
|
47
|
+
pickFlowToEdit: "选择要编辑的流程,或 + 新建流程…",
|
|
48
|
+
noFlowsYet: "还没有流程 — 选择 + 新建流程",
|
|
49
|
+
deleteFlowTitle: "删除流程",
|
|
50
|
+
deleteFlowConfirm: '删除流程 "{name}"?这将移除流程文件及所有关联的代理。',
|
|
51
|
+
},
|
|
52
|
+
hu: {
|
|
53
|
+
abort: "Megszakítás",
|
|
54
|
+
delete: "Törlés",
|
|
55
|
+
run: "Futtatás",
|
|
56
|
+
abortRunningFlow: "Futó folyamat megszakítása",
|
|
57
|
+
back: "Vissza",
|
|
58
|
+
expandGraph: "Gráf kibontása",
|
|
59
|
+
flowGraph: "Folyamatgráf",
|
|
60
|
+
result: "Eredmény",
|
|
61
|
+
inputs: "Bemenetek",
|
|
62
|
+
dismiss: "Bezárás",
|
|
63
|
+
flowsHeading: "Folyamatok",
|
|
64
|
+
editModeLabel: "Szerkesztő mód",
|
|
65
|
+
runFlowTitle: "Folyamat futtatása: {flowName}",
|
|
66
|
+
taskPlaceholder: "Írd le a feladatot (opcionális)…",
|
|
67
|
+
summary: "Összefoglaló",
|
|
68
|
+
waitingToStart: "Indulásra vár…",
|
|
69
|
+
noActivityYet: "Még nincs tevékenység",
|
|
70
|
+
closeAgentDetail: "{name} részleteinek bezárása",
|
|
71
|
+
viewAgentDetail: "{name} részleteinek megtekintése",
|
|
72
|
+
details: "Részletek",
|
|
73
|
+
stepsCount: "{done}/{total} lépés",
|
|
74
|
+
toggleAutonomousMode: "Autonóm mód váltása",
|
|
75
|
+
abortFlow: "Folyamat megszakítása",
|
|
76
|
+
newFlowOption: "+ Új folyamat",
|
|
77
|
+
newFlowOptionDesc: "Új folyamat készítése az edit-flow készséggel",
|
|
78
|
+
runFlowButton: "Folyamat futtatása…",
|
|
79
|
+
newEditButton: "Új / Szerkesztés…",
|
|
80
|
+
runFlowDialogTitle: "Folyamat futtatása",
|
|
81
|
+
searchFlows: "Folyamatok keresése…",
|
|
82
|
+
noFlowsAvailable: "Nincs elérhető folyamat",
|
|
83
|
+
newEditFlowTitle: "Új / Folyamat szerkesztése",
|
|
84
|
+
pickFlowToEdit: "Válassz folyamatot szerkesztésre, vagy + Új folyamat…",
|
|
85
|
+
noFlowsYet: "Még nincs folyamat — válaszd a + Új folyamat lehetőséget",
|
|
86
|
+
deleteFlowTitle: "Folyamat törlése",
|
|
87
|
+
deleteFlowConfirm:
|
|
88
|
+
'Törlöd a(z) "{name}" folyamatot? Ez eltávolítja a folyamatfájlt és a hozzá tartozó ügynököket.',
|
|
89
|
+
},
|
|
90
|
+
};
|
package/src/reducer.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reducer barrel for the flows plugin.
|
|
3
3
|
*
|
|
4
|
-
* Re-exports the flow
|
|
5
|
-
* `packages/client/src/lib/event-reducer.ts` can import
|
|
6
|
-
* `@blackbelt-technology/pi-dashboard-flows-plugin/reducer
|
|
7
|
-
*
|
|
4
|
+
* Re-exports the flow reducer so that
|
|
5
|
+
* `packages/client/src/lib/event-reducer.ts` can import it via
|
|
6
|
+
* `@blackbelt-technology/pi-dashboard-flows-plugin/reducer`.
|
|
7
|
+
* Architect reducer removed (flow-architect deleted upstream).
|
|
8
|
+
* See change: rework-flows-plugin-for-new-pi-flows.
|
|
8
9
|
*/
|
|
9
10
|
export { isFlowEvent, reduceFlowEvent } from "./flow-reducer.js";
|
|
10
|
-
export { isArchitectEvent, reduceArchitectEvent } from "./architect-reducer.js";
|