@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.
- package/package.json +25 -16
- 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 +2 -39
- 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 +51 -64
- package/src/__tests__/node-kind-reducer.test.ts +135 -0
- package/src/__tests__/plugin-action-handler.test.ts +54 -0
- package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
- package/src/bridge/AGENTS.md +8 -0
- package/src/client/AGENTS.md +32 -0
- package/src/client/FlowActivityBadge.tsx +8 -5
- package/src/client/FlowAgentCard.tsx +231 -110
- package/src/client/FlowAgentDetail.tsx +20 -12
- package/src/client/FlowAgentsToolRenderer.tsx +228 -0
- package/src/client/FlowAuthorPromptDialog.tsx +92 -0
- package/src/client/FlowDashboard.tsx +88 -23
- package/src/client/FlowGraph.tsx +420 -275
- package/src/client/FlowInputWiring.tsx +243 -0
- package/src/client/FlowLaunchDialog.tsx +48 -54
- package/src/client/FlowQuestionCard.tsx +6 -3
- package/src/client/FlowSummary.tsx +252 -69
- package/src/client/FlowWriteToolRenderer.tsx +127 -0
- package/src/client/FlowYamlPopoverButton.tsx +26 -25
- package/src/client/FlowYamlPreview.tsx +9 -7
- package/src/client/FlowsSessionStateContext.tsx +14 -33
- package/src/client/FlowsSettings.tsx +68 -0
- package/src/client/SessionFlowActions.tsx +92 -76
- 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 +28 -87
- package/src/client/index.tsx +27 -32
- package/src/client/shouldRender.ts +24 -12
- 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 +93 -9
- package/src/server/state-store.ts +3 -14
- 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/FlowAgentPopoutClaim.tsx +0 -66
- package/src/client/FlowAgentPopoutPage.tsx +0 -177
- package/src/client/FlowArchitect.tsx +0 -699
- package/src/client/FlowArchitectPopoutClaim.tsx +0 -52
- package/src/client/FlowArchitectPopoutPage.tsx +0 -133
- package/src/client/popout-url.ts +0 -59
package/src/architect-reducer.ts
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Architect state machine reducer.
|
|
3
|
-
* Handles all architect_* events and returns updated ArchitectState.
|
|
4
|
-
*/
|
|
5
|
-
import type {
|
|
6
|
-
DashboardEvent,
|
|
7
|
-
ArchitectState,
|
|
8
|
-
ArchitectAgentEntry,
|
|
9
|
-
ArchitectDagStep,
|
|
10
|
-
ArchitectParsedFlow,
|
|
11
|
-
ArchitectPrompt,
|
|
12
|
-
FlowRecentTool,
|
|
13
|
-
FlowDetailEntry,
|
|
14
|
-
} from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
15
|
-
|
|
16
|
-
const MAX_RECENT_TOOLS = 3;
|
|
17
|
-
|
|
18
|
-
/** Extract a short input preview for tool call display */
|
|
19
|
-
function extractInputPreview(toolName: string, input: unknown): string {
|
|
20
|
-
if (!input || typeof input !== "object") return "";
|
|
21
|
-
const inp = input as Record<string, unknown>;
|
|
22
|
-
switch (toolName.toLowerCase()) {
|
|
23
|
-
case "read":
|
|
24
|
-
case "write":
|
|
25
|
-
case "edit":
|
|
26
|
-
return String(inp.file_path || inp.path || "").split("/").pop() || "";
|
|
27
|
-
case "grep":
|
|
28
|
-
return String(inp.pattern || "").slice(0, 20);
|
|
29
|
-
case "bash":
|
|
30
|
-
return String(inp.command || "").slice(0, 20);
|
|
31
|
-
case "flow_write":
|
|
32
|
-
return String(inp.name || "");
|
|
33
|
-
case "agent_write":
|
|
34
|
-
return extractAgentName(inp);
|
|
35
|
-
default:
|
|
36
|
-
return JSON.stringify(input).slice(0, 20);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Extract agent name from agent_write tool input */
|
|
41
|
-
function extractAgentName(input: Record<string, unknown>): string {
|
|
42
|
-
if (input.path) {
|
|
43
|
-
const seg = String(input.path).split("/").pop() || "";
|
|
44
|
-
return seg.replace(/\.md$/, "") || "unknown";
|
|
45
|
-
}
|
|
46
|
-
if (input.content) {
|
|
47
|
-
const m = String(input.content).match(/^name:\s*(.+)$/m);
|
|
48
|
-
if (m) return m[1].trim();
|
|
49
|
-
}
|
|
50
|
-
return "unknown";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Extract step IDs from flow YAML content via regex (approximate, for live progress) */
|
|
54
|
-
function extractStepsFromYaml(content: string): ArchitectDagStep[] {
|
|
55
|
-
const steps: ArchitectDagStep[] = [];
|
|
56
|
-
// Match step entries: " - id: <name>"
|
|
57
|
-
const idMatches = content.matchAll(/^\s+-\s*id:\s*(.+)$/gm);
|
|
58
|
-
for (const m of idMatches) {
|
|
59
|
-
const id = m[1].trim();
|
|
60
|
-
steps.push({ id, blockedBy: [] });
|
|
61
|
-
}
|
|
62
|
-
// Try to extract fields for each step (simple regex, may miss complex cases)
|
|
63
|
-
const stepBlocks = content.split(/^\s+-\s*id:/m).slice(1);
|
|
64
|
-
for (let i = 0; i < stepBlocks.length && i < steps.length; i++) {
|
|
65
|
-
const block = stepBlocks[i];
|
|
66
|
-
const agentMatch = block.match(/^\s+agent:\s*(.+)$/m);
|
|
67
|
-
if (agentMatch) steps[i].agentName = agentMatch[1].trim();
|
|
68
|
-
const blockedMatch = block.match(/^\s+blockedBy:\s*\[([^\]]*)\]/m);
|
|
69
|
-
if (blockedMatch) {
|
|
70
|
-
steps[i].blockedBy = blockedMatch[1].split(",").map(s => s.trim().replace(/^["']|["']$/g, "")).filter(Boolean);
|
|
71
|
-
}
|
|
72
|
-
const stepTypeMatch = block.match(/^\s+stepType:\s*(.+)$/m);
|
|
73
|
-
if (stepTypeMatch) steps[i].stepType = stepTypeMatch[1].trim() as ArchitectDagStep["stepType"];
|
|
74
|
-
const loopTargetMatch = block.match(/^\s+loop_target:\s*(.+)$/m);
|
|
75
|
-
if (loopTargetMatch) steps[i].loopTarget = loopTargetMatch[1].trim();
|
|
76
|
-
const exitTargetMatch = block.match(/^\s+exit_target:\s*(.+)$/m);
|
|
77
|
-
if (exitTargetMatch) steps[i].exitTarget = exitTargetMatch[1].trim();
|
|
78
|
-
}
|
|
79
|
-
return steps;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Extract flow name from flow YAML content */
|
|
83
|
-
function extractFlowName(content: string): string {
|
|
84
|
-
const m = content.match(/^name:\s*(.+)$/m);
|
|
85
|
-
return m ? m[1].trim() : "";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Returns true if the event type is an architect event handled by this reducer.
|
|
90
|
-
*/
|
|
91
|
-
export function isArchitectEvent(eventType: string): boolean {
|
|
92
|
-
return eventType.startsWith("architect_");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Reduce an architect event into the current ArchitectState.
|
|
97
|
-
* Returns null to clear the state (e.g., on complete/cancelled).
|
|
98
|
-
*/
|
|
99
|
-
export function reduceArchitectEvent(
|
|
100
|
-
state: ArchitectState | null,
|
|
101
|
-
event: DashboardEvent,
|
|
102
|
-
): ArchitectState | null {
|
|
103
|
-
const data = event.data;
|
|
104
|
-
|
|
105
|
-
switch (event.eventType) {
|
|
106
|
-
case "architect_prompt_request": {
|
|
107
|
-
if (!state) return null;
|
|
108
|
-
const prompt: ArchitectPrompt = {
|
|
109
|
-
id: data.id as string,
|
|
110
|
-
type: (data.promptType as "select" | "input" | "confirm") || "select",
|
|
111
|
-
question: (data.question as string) || "",
|
|
112
|
-
options: data.options as string[] | undefined,
|
|
113
|
-
defaultValue: data.defaultValue as string | undefined,
|
|
114
|
-
};
|
|
115
|
-
return { ...state, pendingPrompt: prompt };
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
case "architect_context_generating": {
|
|
119
|
-
return {
|
|
120
|
-
phase: "context",
|
|
121
|
-
architectMode: (data.mode as "new" | "edit") || "new",
|
|
122
|
-
flowName: "",
|
|
123
|
-
agents: [],
|
|
124
|
-
dagSteps: [],
|
|
125
|
-
parsedFlows: [],
|
|
126
|
-
lastToolCall: null,
|
|
127
|
-
recentTools: [],
|
|
128
|
-
detailHistory: [],
|
|
129
|
-
iteration: 1,
|
|
130
|
-
pendingPrompt: null,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
case "architect_started": {
|
|
135
|
-
const mode = (data.mode as "new" | "edit") || "new";
|
|
136
|
-
const iteration = (data.iteration as number) || 1;
|
|
137
|
-
const resolvedModel = data.resolvedModel as string | undefined;
|
|
138
|
-
const modelAlias = data.modelAlias as string | undefined;
|
|
139
|
-
// If we already have state (from context_generating), just update phase
|
|
140
|
-
if (state) {
|
|
141
|
-
return {
|
|
142
|
-
...state,
|
|
143
|
-
phase: "designing",
|
|
144
|
-
architectMode: mode,
|
|
145
|
-
iteration,
|
|
146
|
-
resolvedModel,
|
|
147
|
-
modelAlias,
|
|
148
|
-
pendingPrompt: null,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
phase: "designing",
|
|
153
|
-
architectMode: mode,
|
|
154
|
-
flowName: "",
|
|
155
|
-
resolvedModel,
|
|
156
|
-
modelAlias,
|
|
157
|
-
agents: [],
|
|
158
|
-
dagSteps: [],
|
|
159
|
-
parsedFlows: [],
|
|
160
|
-
lastToolCall: null,
|
|
161
|
-
recentTools: [],
|
|
162
|
-
detailHistory: [],
|
|
163
|
-
iteration,
|
|
164
|
-
pendingPrompt: null,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
case "architect_tool_call": {
|
|
169
|
-
if (!state) return null;
|
|
170
|
-
const toolName = data.toolName as string;
|
|
171
|
-
const input = data.input as Record<string, unknown> | undefined;
|
|
172
|
-
const next = { ...state };
|
|
173
|
-
|
|
174
|
-
const inputPreview = extractInputPreview(toolName, input);
|
|
175
|
-
|
|
176
|
-
// Update last tool call for display
|
|
177
|
-
next.lastToolCall = { toolName, inputPreview };
|
|
178
|
-
|
|
179
|
-
// Append to recent tools (rolling window)
|
|
180
|
-
next.recentTools = [...state.recentTools, { toolName, inputPreview } as FlowRecentTool].slice(-MAX_RECENT_TOOLS);
|
|
181
|
-
|
|
182
|
-
// Append to detail history
|
|
183
|
-
next.detailHistory = [...state.detailHistory, { kind: "tool", toolName, input, isError: false } as FlowDetailEntry];
|
|
184
|
-
|
|
185
|
-
switch (toolName) {
|
|
186
|
-
case "agent_catalog":
|
|
187
|
-
next.catalogSummary = "Reading catalog…";
|
|
188
|
-
break;
|
|
189
|
-
|
|
190
|
-
case "agent_write": {
|
|
191
|
-
const name = input ? extractAgentName(input) : "unknown";
|
|
192
|
-
const source = input ? String(input.content || "") : "";
|
|
193
|
-
const agents = [...next.agents];
|
|
194
|
-
const existing = agents.find(a => a.name === name);
|
|
195
|
-
if (existing) {
|
|
196
|
-
existing.type = "custom";
|
|
197
|
-
existing.status = "creating";
|
|
198
|
-
existing.statusText = "Writing…";
|
|
199
|
-
if (source) existing.source = source;
|
|
200
|
-
} else {
|
|
201
|
-
agents.push({ name, type: "custom", status: "creating", statusText: "Writing…", ...(source ? { source } : {}) });
|
|
202
|
-
}
|
|
203
|
-
next.agents = agents;
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
case "flow_write": {
|
|
208
|
-
if (input?.content) {
|
|
209
|
-
const content = String(input.content);
|
|
210
|
-
const name = extractFlowName(content);
|
|
211
|
-
if (name) next.flowName = name;
|
|
212
|
-
const steps = extractStepsFromYaml(content);
|
|
213
|
-
if (steps.length > 0) {
|
|
214
|
-
next.dagSteps = steps;
|
|
215
|
-
// Register agents from steps that aren't already in the list
|
|
216
|
-
const agents = [...next.agents];
|
|
217
|
-
for (const step of steps) {
|
|
218
|
-
const agentName = step.agentName || step.id;
|
|
219
|
-
if (!agents.find(a => a.name === agentName)) {
|
|
220
|
-
agents.push({ name: agentName, type: "built-in", status: "done" });
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
next.agents = agents;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return next;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
case "architect_tool_result": {
|
|
234
|
-
if (!state) return null;
|
|
235
|
-
const toolName = data.toolName as string;
|
|
236
|
-
const isError = (data.isError as boolean) || false;
|
|
237
|
-
const next = { ...state };
|
|
238
|
-
|
|
239
|
-
// Update last tool entry in detail history with output
|
|
240
|
-
const detailHistory = [...state.detailHistory];
|
|
241
|
-
for (let i = detailHistory.length - 1; i >= 0; i--) {
|
|
242
|
-
const entry = detailHistory[i];
|
|
243
|
-
if (entry.kind === "tool" && entry.output === undefined) {
|
|
244
|
-
detailHistory[i] = { ...entry, output: data.output, isError };
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
next.detailHistory = detailHistory;
|
|
249
|
-
|
|
250
|
-
switch (toolName) {
|
|
251
|
-
case "agent_catalog": {
|
|
252
|
-
// Parse catalog output for summary
|
|
253
|
-
try {
|
|
254
|
-
const output = data.output;
|
|
255
|
-
const catalog = typeof output === "string" ? JSON.parse(output) : output;
|
|
256
|
-
if (Array.isArray(catalog)) {
|
|
257
|
-
next.catalogSummary = `Catalog: ${catalog.length} agents`;
|
|
258
|
-
}
|
|
259
|
-
} catch {
|
|
260
|
-
next.catalogSummary = "Catalog loaded";
|
|
261
|
-
}
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
case "flow_write": {
|
|
266
|
-
// The tool result output is { written: boolean, path, diagnostics? }
|
|
267
|
-
// Already parsed by execution.ts (JSON.parse on content[0].text)
|
|
268
|
-
const output = data.output;
|
|
269
|
-
if (output && typeof output === "object" && "written" in output) {
|
|
270
|
-
next.flowWriteStatus = output.written ? "written" : "validation-error";
|
|
271
|
-
} else if (isError) {
|
|
272
|
-
next.flowWriteStatus = "validation-error";
|
|
273
|
-
}
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
case "agent_write": {
|
|
278
|
-
// Find the agent that was being created and mark done/error
|
|
279
|
-
const agents = [...next.agents];
|
|
280
|
-
const creating = agents.find(a => a.status === "creating");
|
|
281
|
-
if (creating) {
|
|
282
|
-
creating.status = isError ? "error" : "done";
|
|
283
|
-
creating.statusText = isError ? "Failed" : undefined;
|
|
284
|
-
}
|
|
285
|
-
next.agents = agents;
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return next;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
case "architect_text": {
|
|
294
|
-
if (!state) return null;
|
|
295
|
-
const kind = data.kind as string;
|
|
296
|
-
const text = data.text as string;
|
|
297
|
-
if (!text) return state;
|
|
298
|
-
const entry: FlowDetailEntry = kind === "thinking"
|
|
299
|
-
? { kind: "thinking", text }
|
|
300
|
-
: { kind: "text", text };
|
|
301
|
-
return {
|
|
302
|
-
...state,
|
|
303
|
-
detailHistory: [...state.detailHistory, entry],
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
case "architect_preview": {
|
|
308
|
-
if (!state) return null;
|
|
309
|
-
const parsedFlows = data.parsedFlows as ArchitectParsedFlow[] | undefined;
|
|
310
|
-
// Store raw YAML content for the YAML viewer
|
|
311
|
-
const flows = data.flows as Array<{ name: string; content: string }> | undefined;
|
|
312
|
-
const next: ArchitectState = {
|
|
313
|
-
...state,
|
|
314
|
-
phase: "preview",
|
|
315
|
-
flowYamlContent: flows?.[0]?.content,
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
if (parsedFlows && parsedFlows.length > 0) {
|
|
319
|
-
next.parsedFlows = parsedFlows;
|
|
320
|
-
// Use first flow's data for display
|
|
321
|
-
const first = parsedFlows[0];
|
|
322
|
-
if (first.name) next.flowName = first.name;
|
|
323
|
-
if (first.steps.length > 0) next.dagSteps = first.steps;
|
|
324
|
-
// Register agents from parsed steps
|
|
325
|
-
const agents = [...next.agents];
|
|
326
|
-
for (const flow of parsedFlows) {
|
|
327
|
-
for (const step of flow.steps) {
|
|
328
|
-
const agentName = step.agentName || step.id;
|
|
329
|
-
if (!agents.find(a => a.name === agentName)) {
|
|
330
|
-
agents.push({ name: agentName, type: "built-in", status: "done" });
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
next.agents = agents;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return next;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
case "architect_replan": {
|
|
341
|
-
const iteration = (data.iteration as number) || ((state?.iteration ?? 1) + 1);
|
|
342
|
-
return {
|
|
343
|
-
phase: "designing",
|
|
344
|
-
architectMode: state?.architectMode || "new",
|
|
345
|
-
flowName: state?.flowName || "",
|
|
346
|
-
agents: [],
|
|
347
|
-
dagSteps: [],
|
|
348
|
-
parsedFlows: [],
|
|
349
|
-
lastToolCall: null,
|
|
350
|
-
recentTools: [],
|
|
351
|
-
detailHistory: [],
|
|
352
|
-
iteration,
|
|
353
|
-
pendingPrompt: null,
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
case "architect_complete":
|
|
358
|
-
case "architect_cancelled": {
|
|
359
|
-
return null;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
case "architect_error": {
|
|
363
|
-
if (!state) return null;
|
|
364
|
-
const summary = (data.summary as string) || (data.error as string) || "Unknown error";
|
|
365
|
-
return { ...state, error: summary };
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
case "architect_saved": {
|
|
369
|
-
// Keep state alive — architect_complete will clear it
|
|
370
|
-
return state;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
case "architect_run_handoff": {
|
|
374
|
-
// Flow execution is about to start — clear architect state
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
case "architect_context_ready": {
|
|
379
|
-
// Context generation finished, architect will start soon
|
|
380
|
-
return state;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
default:
|
|
384
|
-
return state;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FlowAgentPopoutClaim — slot-claim wrapper for the `shell-overlay-route`
|
|
3
|
-
* registration `/session/:sid/flow/:flowId/agent/:agentId`.
|
|
4
|
-
*
|
|
5
|
-
* Self-derived from the slot props:
|
|
6
|
-
* - Reads `params.sid` / `params.flowId` (URL-decoded) / `params.agentId`.
|
|
7
|
-
* - Receives `session: DashboardSession | undefined` from the slot consumer.
|
|
8
|
-
* - Cold-open subscribes to the parent session via `usePluginSend`.
|
|
9
|
-
* - Reads flow state via `useFlowsSessionState(params.sid)`.
|
|
10
|
-
* - Renders the existing `FlowAgentPopoutPage` body.
|
|
11
|
-
*
|
|
12
|
-
* See change: add-flow-agent-popout.
|
|
13
|
-
*/
|
|
14
|
-
import React, { useEffect, useRef } from "react";
|
|
15
|
-
import {
|
|
16
|
-
usePluginSend,
|
|
17
|
-
useShellConnectionStatus,
|
|
18
|
-
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
19
|
-
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
20
|
-
import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
|
|
21
|
-
import { FlowAgentPopoutPage } from "./FlowAgentPopoutPage.js";
|
|
22
|
-
|
|
23
|
-
export interface FlowAgentPopoutClaimProps {
|
|
24
|
-
params: Record<string, string>;
|
|
25
|
-
session?: DashboardSession;
|
|
26
|
-
onBack: () => void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function FlowAgentPopoutClaim({ params, session, onBack }: FlowAgentPopoutClaimProps) {
|
|
30
|
-
const sessionId = params.sid ?? "";
|
|
31
|
-
const flowId = params.flowId ?? "";
|
|
32
|
-
const agentId = params.agentId ?? "";
|
|
33
|
-
const send = usePluginSend();
|
|
34
|
-
const { flowStates } = useFlowsSessionState(sessionId);
|
|
35
|
-
const connectionStatus = useShellConnectionStatus();
|
|
36
|
-
|
|
37
|
-
// Cold-open subscribe exactly once, AFTER the WebSocket is open.
|
|
38
|
-
// See change: fix-flows-plugin-polish (popout cold-open subscribe).
|
|
39
|
-
const subscribedRef = useRef(false);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (!sessionId || subscribedRef.current) return;
|
|
42
|
-
if (connectionStatus !== "connected") return;
|
|
43
|
-
subscribedRef.current = true;
|
|
44
|
-
send({ type: "subscribe", sessionId, lastSeq: 0 });
|
|
45
|
-
}, [sessionId, send, connectionStatus]);
|
|
46
|
-
|
|
47
|
-
// The popout page's empty-state ladder evaluates loading → no session →
|
|
48
|
-
// no flow → no agent. We forward `flowStates` via the lightweight shape
|
|
49
|
-
// FlowAgentPopoutPage expects.
|
|
50
|
-
const subscriptionResolved = !!session || flowStates.size > 0;
|
|
51
|
-
const sessionLike = session || flowStates.size > 0
|
|
52
|
-
? { flowStates }
|
|
53
|
-
: undefined;
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<FlowAgentPopoutPage
|
|
57
|
-
sessionId={sessionId}
|
|
58
|
-
flowId={flowId}
|
|
59
|
-
agentId={agentId}
|
|
60
|
-
session={sessionLike}
|
|
61
|
-
subscriptionResolved={subscriptionResolved}
|
|
62
|
-
parentLabel={session?.cwd}
|
|
63
|
-
onBack={onBack}
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FlowAgentPopoutPage — fullscreen route content for
|
|
3
|
-
* `/session/:sid/flow/:flowId/agent/:agentId`.
|
|
4
|
-
*
|
|
5
|
-
* Mounts `FlowAgentDetail` in popout mode plus a chrome header. Graceful
|
|
6
|
-
* empty-state ladder:
|
|
7
|
-
* 1. Subscription not yet resolved → "Loading parent session…"
|
|
8
|
-
* 2. Parent session not found → close-tab CTA
|
|
9
|
-
* 3. Flow not present on parent session → "Flow not found"
|
|
10
|
-
* 4. Agent not present in flow → "Agent not found"
|
|
11
|
-
*
|
|
12
|
-
* Mirrors `SubagentPopoutPage` structurally; both popouts share the same
|
|
13
|
-
* four-tier empty-state contract.
|
|
14
|
-
*
|
|
15
|
-
* See change: add-flow-agent-popout.
|
|
16
|
-
*/
|
|
17
|
-
import React, { useEffect } from "react";
|
|
18
|
-
import { Icon } from "@mdi/react";
|
|
19
|
-
import { mdiArrowLeft, mdiClose } from "@mdi/js";
|
|
20
|
-
import type { FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
21
|
-
import { FlowAgentDetail } from "./FlowAgentDetail.js";
|
|
22
|
-
|
|
23
|
-
/** Minimal session-state shape this page consumes. */
|
|
24
|
-
export interface FlowAgentPopoutSessionLike {
|
|
25
|
-
// Read-only: page only calls `.get(flowId)`. ReadonlyMap allows passing the
|
|
26
|
-
// frozen map returned by `useFlowsSessionState` directly.
|
|
27
|
-
flowStates?: ReadonlyMap<string, FlowState>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface FlowAgentPopoutPageProps {
|
|
31
|
-
sessionId: string;
|
|
32
|
-
flowId: string;
|
|
33
|
-
agentId: string;
|
|
34
|
-
/** Parent session state (or undefined if not yet subscribed). */
|
|
35
|
-
session: FlowAgentPopoutSessionLike | undefined;
|
|
36
|
-
/** True once the parent session's subscription has resolved. */
|
|
37
|
-
subscriptionResolved: boolean;
|
|
38
|
-
/** Optional parent-session display label (e.g. cwd basename) for the breadcrumb. */
|
|
39
|
-
parentLabel?: string;
|
|
40
|
-
onBack?: () => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function FlowAgentPopoutPage({
|
|
44
|
-
sessionId,
|
|
45
|
-
flowId,
|
|
46
|
-
agentId,
|
|
47
|
-
session,
|
|
48
|
-
subscriptionResolved,
|
|
49
|
-
parentLabel,
|
|
50
|
-
onBack,
|
|
51
|
-
}: FlowAgentPopoutPageProps) {
|
|
52
|
-
const flow = session?.flowStates?.get(flowId);
|
|
53
|
-
const agent = flow?.agents.get(agentId);
|
|
54
|
-
const agentName = agent?.label || agent?.agentName || agentId;
|
|
55
|
-
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
document.title = `${agentName} · ${flowId} · ${parentLabel ?? sessionId} · pi`;
|
|
58
|
-
return () => {
|
|
59
|
-
document.title = "pi";
|
|
60
|
-
};
|
|
61
|
-
}, [agentName, flowId, parentLabel, sessionId]);
|
|
62
|
-
|
|
63
|
-
// (1) Loading: subscription has not resolved yet.
|
|
64
|
-
if (!subscriptionResolved) {
|
|
65
|
-
return (
|
|
66
|
-
<div
|
|
67
|
-
data-testid="flow-agent-popout-loading"
|
|
68
|
-
className="flex flex-col h-full items-center justify-center text-sm text-[var(--text-muted)] gap-2"
|
|
69
|
-
>
|
|
70
|
-
<div>Loading parent session…</div>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// (2) Parent session not found.
|
|
76
|
-
if (!session) {
|
|
77
|
-
return (
|
|
78
|
-
<div
|
|
79
|
-
data-testid="flow-agent-popout-no-session"
|
|
80
|
-
className="flex flex-col h-full items-center justify-center text-sm text-[var(--text-muted)] gap-3 px-6 text-center"
|
|
81
|
-
>
|
|
82
|
-
<div className="text-base text-[var(--text-primary)]">Parent session not found</div>
|
|
83
|
-
<div className="max-w-md">
|
|
84
|
-
It may have been archived or deleted. Close this tab — the session
|
|
85
|
-
this flow was launched from is no longer available in the dashboard.
|
|
86
|
-
</div>
|
|
87
|
-
<button
|
|
88
|
-
onClick={() => window.close()}
|
|
89
|
-
className="text-xs text-[var(--text-tertiary)] hover:text-[var(--text-primary)] inline-flex items-center gap-1 mt-2 px-3 py-1 border border-[var(--border-primary)] rounded"
|
|
90
|
-
>
|
|
91
|
-
<Icon path={mdiClose} size={0.5} /> Close tab
|
|
92
|
-
</button>
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// (3) Flow not found on parent session.
|
|
98
|
-
if (!flow) {
|
|
99
|
-
return (
|
|
100
|
-
<div data-testid="flow-agent-popout-no-flow" className="flex flex-col h-full overflow-hidden">
|
|
101
|
-
<div className="px-3 py-2 border-b border-[var(--border-subtle)] bg-[var(--bg-secondary)] flex items-center gap-2 flex-shrink-0">
|
|
102
|
-
{onBack && (
|
|
103
|
-
<button
|
|
104
|
-
onClick={onBack}
|
|
105
|
-
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
|
|
106
|
-
title="Back"
|
|
107
|
-
>
|
|
108
|
-
<Icon path={mdiArrowLeft} size={0.7} />
|
|
109
|
-
</button>
|
|
110
|
-
)}
|
|
111
|
-
<span className="text-sm text-[var(--text-primary)]">
|
|
112
|
-
Flow · {parentLabel ?? sessionId}
|
|
113
|
-
</span>
|
|
114
|
-
</div>
|
|
115
|
-
<div className="flex-1 flex items-center justify-center text-sm text-[var(--text-muted)] px-6 text-center">
|
|
116
|
-
Flow “{flowId}” is no longer active on this session.
|
|
117
|
-
</div>
|
|
118
|
-
</div>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// (4) Agent not found in flow.
|
|
123
|
-
if (!agent) {
|
|
124
|
-
return (
|
|
125
|
-
<div data-testid="flow-agent-popout-no-agent" className="flex flex-col h-full overflow-hidden">
|
|
126
|
-
<div className="px-3 py-2 border-b border-[var(--border-subtle)] bg-[var(--bg-secondary)] flex items-center gap-2 flex-shrink-0">
|
|
127
|
-
{onBack && (
|
|
128
|
-
<button
|
|
129
|
-
onClick={onBack}
|
|
130
|
-
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
|
|
131
|
-
title="Back"
|
|
132
|
-
>
|
|
133
|
-
<Icon path={mdiArrowLeft} size={0.7} />
|
|
134
|
-
</button>
|
|
135
|
-
)}
|
|
136
|
-
<span className="text-sm text-[var(--text-primary)]">
|
|
137
|
-
{parentLabel ?? sessionId} › {flowId}
|
|
138
|
-
</span>
|
|
139
|
-
</div>
|
|
140
|
-
<div className="flex-1 flex items-center justify-center text-sm text-[var(--text-muted)] px-6 text-center">
|
|
141
|
-
Agent “{agentId}” not found in this flow — it may have been cleared.
|
|
142
|
-
</div>
|
|
143
|
-
</div>
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// (5) Found — render the detail view with a chrome header.
|
|
148
|
-
return (
|
|
149
|
-
<div data-testid="flow-agent-popout" className="flex flex-col h-full overflow-hidden">
|
|
150
|
-
<div className="px-3 py-2 border-b border-[var(--border-primary)] bg-[var(--bg-primary)] flex items-center gap-2 flex-shrink-0">
|
|
151
|
-
{onBack && (
|
|
152
|
-
<button
|
|
153
|
-
onClick={onBack}
|
|
154
|
-
className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
|
|
155
|
-
title="Back"
|
|
156
|
-
>
|
|
157
|
-
<Icon path={mdiArrowLeft} size={0.7} />
|
|
158
|
-
</button>
|
|
159
|
-
)}
|
|
160
|
-
<span className="text-[11px] text-[var(--text-tertiary)] truncate flex-shrink-0">
|
|
161
|
-
{parentLabel ?? sessionId} › {flowId} ›
|
|
162
|
-
</span>
|
|
163
|
-
<span className="text-sm font-medium text-[var(--text-primary)] truncate flex-1 min-w-0">
|
|
164
|
-
{agentName}
|
|
165
|
-
</span>
|
|
166
|
-
</div>
|
|
167
|
-
{/* `min-h-0` required so body scrolls instead of overflowing.
|
|
168
|
-
See change: fix-flows-plugin-polish (scrollbar fix). */}
|
|
169
|
-
<div className="flex-1 min-h-0 overflow-hidden">
|
|
170
|
-
{/* FlowAgentDetail's own header carries status/model/tokens; the chrome
|
|
171
|
-
above carries breadcrumb + back nav. We omit `onBack` so the inner
|
|
172
|
-
header does not render a duplicate back arrow. */}
|
|
173
|
-
<FlowAgentDetail agent={agent} sessionId={sessionId} />
|
|
174
|
-
</div>
|
|
175
|
-
</div>
|
|
176
|
-
);
|
|
177
|
-
}
|