@blackbelt-technology/pi-dashboard-flows-plugin 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +39 -4
- package/src/__tests__/FlowsSessionStateContext.test.tsx +260 -0
- package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
- package/src/__tests__/flowsAvailability.test.ts +92 -0
- package/src/__tests__/manifest-discoverability.test.ts +97 -0
- package/src/__tests__/render-actions.test.ts +63 -0
- package/src/bridge/flow-question-adapter.ts +93 -0
- package/src/bridge/index.ts +30 -0
- package/src/client/FlowActivityBadge.tsx +36 -9
- package/src/client/FlowAgentCard.tsx +180 -41
- package/src/client/FlowAgentDetail.tsx +95 -154
- package/src/client/FlowAgentPopoutClaim.tsx +66 -0
- package/src/client/FlowAgentPopoutPage.tsx +177 -0
- package/src/client/FlowArchitect.tsx +297 -220
- package/src/client/FlowArchitectPopoutClaim.tsx +52 -0
- package/src/client/FlowArchitectPopoutPage.tsx +133 -0
- package/src/client/FlowDashboard.tsx +194 -31
- package/src/client/FlowGraph.tsx +6 -2
- package/src/client/FlowLaunchDialog.tsx +8 -2
- package/src/client/FlowQuestionCard.tsx +213 -0
- package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
- package/src/client/FlowSummary.tsx +43 -21
- package/src/client/FlowYamlPopoverButton.tsx +109 -0
- package/src/client/FlowYamlPreview.tsx +65 -0
- package/src/client/FlowsCommandRoutes.tsx +237 -0
- package/src/client/FlowsSessionStateContext.tsx +161 -0
- package/src/client/FlowsUiStateContext.tsx +169 -0
- package/src/client/SessionFlowActions.tsx +96 -5
- package/src/client/flowsAvailability.ts +103 -0
- package/src/client/index.tsx +94 -7
- package/src/client/popout-url.ts +59 -0
- package/src/client/shouldRender.ts +26 -0
- package/src/server/index.ts +87 -0
- package/src/server/render-actions.ts +88 -0
- package/src/server/state-store.ts +85 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { renderSessionFlowActions } from "../server/render-actions.js";
|
|
3
|
+
import type { FlowInfo, CommandInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
4
|
+
|
|
5
|
+
const cmd = (name: string): CommandInfo => ({ name }) as CommandInfo;
|
|
6
|
+
const flow = (name: string, description = ""): FlowInfo =>
|
|
7
|
+
({ name, description }) as FlowInfo;
|
|
8
|
+
|
|
9
|
+
describe("renderSessionFlowActions", () => {
|
|
10
|
+
it("returns null when no flows and no /flows:new command", () => {
|
|
11
|
+
const result = renderSessionFlowActions({ flows: [], commands: [] });
|
|
12
|
+
expect(result).toBeNull();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("renders flows as action items with dataAction descriptors", () => {
|
|
16
|
+
const result = renderSessionFlowActions({
|
|
17
|
+
flows: [flow("alpha", "desc-a"), flow("beta", "desc-b")],
|
|
18
|
+
commands: [],
|
|
19
|
+
});
|
|
20
|
+
expect(result).not.toBeNull();
|
|
21
|
+
expect(result!.primitive).toBe("ui:action-list");
|
|
22
|
+
const actions = (result!.props as { actions: any[] }).actions;
|
|
23
|
+
expect(actions).toHaveLength(2);
|
|
24
|
+
expect(actions[0].label).toBe("alpha");
|
|
25
|
+
expect(actions[0].tooltip).toBe("desc-a");
|
|
26
|
+
expect(actions[0].dataAction).toEqual({
|
|
27
|
+
pluginId: "flows",
|
|
28
|
+
action: "flow.run",
|
|
29
|
+
payload: { flow: "alpha" },
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("appends + New Flow item when flows:new command is available", () => {
|
|
34
|
+
const result = renderSessionFlowActions({
|
|
35
|
+
flows: [flow("alpha")],
|
|
36
|
+
commands: [cmd("flows:new")],
|
|
37
|
+
});
|
|
38
|
+
const actions = (result!.props as { actions: any[] }).actions;
|
|
39
|
+
expect(actions).toHaveLength(2);
|
|
40
|
+
expect(actions[1].label).toBe("+ New Flow");
|
|
41
|
+
expect(actions[1].dataAction.action).toBe("flow.new");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("renders ONLY + New Flow when no flows but command available", () => {
|
|
45
|
+
const result = renderSessionFlowActions({
|
|
46
|
+
flows: [],
|
|
47
|
+
commands: [cmd("flows:new")],
|
|
48
|
+
});
|
|
49
|
+
const actions = (result!.props as { actions: any[] }).actions;
|
|
50
|
+
expect(actions).toHaveLength(1);
|
|
51
|
+
expect(actions[0].label).toBe("+ New Flow");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("returns null intent is JSON-serializable when not null", () => {
|
|
55
|
+
const result = renderSessionFlowActions({
|
|
56
|
+
flows: [flow("alpha")],
|
|
57
|
+
commands: [cmd("flows:new")],
|
|
58
|
+
});
|
|
59
|
+
expect(() => JSON.stringify(result)).not.toThrow();
|
|
60
|
+
const roundtrip = JSON.parse(JSON.stringify(result));
|
|
61
|
+
expect(roundtrip.primitive).toBe("ui:action-list");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlowQuestionAdapter — PromptBus adapter that claims prompts originating
|
|
3
|
+
* inside a running flow step (carrying `metadata.flowId`) so they render
|
|
4
|
+
* in the FlowDashboard's upper slot instead of the chat stream.
|
|
5
|
+
*
|
|
6
|
+
* Lives in the flows-plugin bridge entry. Auto-loaded by pi when the
|
|
7
|
+
* dashboard server registers the plugin's bridge path into pi's
|
|
8
|
+
* `settings.json#dashboardPluginBridges` + `packages[]` via the standard
|
|
9
|
+
* `discoverPlugins → registerAllPluginBridges` pipeline.
|
|
10
|
+
*
|
|
11
|
+
* Registration: the bridge entry (`./index.ts`) emits
|
|
12
|
+
* `pi.events.emit("prompt:register-adapter", new FlowQuestionAdapter())`.
|
|
13
|
+
* The main dashboard bridge listens for that event and calls
|
|
14
|
+
* `promptBus.registerAdapter(adapter)` (see `packages/extension/src/bridge.ts`
|
|
15
|
+
* around the `prompt:register-adapter` handler). PromptBus sorts adapters by
|
|
16
|
+
* `priority` (lower first); we use 100 so this adapter beats
|
|
17
|
+
* `DashboardDefaultAdapter` (priority 9999).
|
|
18
|
+
*
|
|
19
|
+
* See change: route-flow-asks-to-upper-slot.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// Structural typing — avoid a hard dep on the main bridge package. The shape
|
|
23
|
+
// matches `PromptAdapter` / `PromptRequest` / `PromptClaim` /
|
|
24
|
+
// `PromptResponse` in `packages/extension/src/prompt-bus.ts` byte-for-byte.
|
|
25
|
+
|
|
26
|
+
interface PromptRequest {
|
|
27
|
+
id: string;
|
|
28
|
+
pipeline: string;
|
|
29
|
+
type: "select" | "input" | "confirm" | "editor" | "multiselect";
|
|
30
|
+
question: string;
|
|
31
|
+
options?: string[];
|
|
32
|
+
defaultValue?: string;
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface PromptResponse {
|
|
37
|
+
id: string;
|
|
38
|
+
answer?: string;
|
|
39
|
+
cancelled?: boolean;
|
|
40
|
+
source: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface PromptComponent {
|
|
44
|
+
type: string;
|
|
45
|
+
props: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface PromptClaim {
|
|
49
|
+
component?: PromptComponent;
|
|
50
|
+
placement?: "widget-bar" | "inline" | "overlay";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface PromptAdapter {
|
|
54
|
+
name: string;
|
|
55
|
+
priority?: number;
|
|
56
|
+
onRequest(prompt: PromptRequest): PromptClaim | null | undefined | void;
|
|
57
|
+
onResponse(response: PromptResponse): void;
|
|
58
|
+
onCancel(id: string): void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class FlowQuestionAdapter implements PromptAdapter {
|
|
62
|
+
readonly name = "flow-question";
|
|
63
|
+
readonly priority = 100;
|
|
64
|
+
|
|
65
|
+
onRequest(prompt: PromptRequest): PromptClaim | null {
|
|
66
|
+
const flowId = prompt.metadata?.flowId;
|
|
67
|
+
if (typeof flowId !== "string" || flowId.length === 0) return null;
|
|
68
|
+
const stepId = typeof prompt.metadata?.stepId === "string" ? prompt.metadata.stepId : "";
|
|
69
|
+
return {
|
|
70
|
+
component: {
|
|
71
|
+
type: "flow-question",
|
|
72
|
+
props: {
|
|
73
|
+
flowId,
|
|
74
|
+
stepId,
|
|
75
|
+
question: prompt.question,
|
|
76
|
+
type: prompt.type,
|
|
77
|
+
options: prompt.options,
|
|
78
|
+
defaultValue: prompt.defaultValue,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
placement: "widget-bar",
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onResponse(_response: PromptResponse): void {
|
|
86
|
+
// No adapter-owned UI to dismiss — the client tears down the card on
|
|
87
|
+
// submit; the bus broadcasts `prompt_dismiss` for all listeners.
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onCancel(_id: string): void {
|
|
91
|
+
// No adapter-owned UI to dismiss.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flows-plugin · bridge entry.
|
|
3
|
+
*
|
|
4
|
+
* Auto-registered at `~/.pi/agent/settings.json#dashboardPluginBridges`
|
|
5
|
+
* (key: `dashboard-flows`) when the dashboard server discovers the plugin
|
|
6
|
+
* manifest and runs `registerAllPluginBridges`. The path is mirrored into
|
|
7
|
+
* the top-level `packages[]` array so pi-coding-agent loads it as a pi
|
|
8
|
+
* extension on the next session start.
|
|
9
|
+
*
|
|
10
|
+
* Behavior: on activation, emit a `prompt:register-adapter` event with
|
|
11
|
+
* a fresh `FlowQuestionAdapter`. The main dashboard bridge listens for
|
|
12
|
+
* that event and calls `promptBus.registerAdapter(adapter)` — see the
|
|
13
|
+
* existing handler in `packages/extension/src/bridge.ts`. PromptBus
|
|
14
|
+
* sorts adapters by `priority`; `FlowQuestionAdapter` (priority 100)
|
|
15
|
+
* therefore claims flow-tagged prompts before `DashboardDefaultAdapter`
|
|
16
|
+
* (priority 9999).
|
|
17
|
+
*
|
|
18
|
+
* No other behavior here — this entry is intentionally narrow.
|
|
19
|
+
*
|
|
20
|
+
* See change: route-flow-asks-to-upper-slot.
|
|
21
|
+
*/
|
|
22
|
+
import { FlowQuestionAdapter } from "./flow-question-adapter.js";
|
|
23
|
+
|
|
24
|
+
export default function activate(ctx: unknown): void {
|
|
25
|
+
const c = ctx as { pi?: { events?: { emit: (name: string, payload: unknown) => void } }; events?: unknown };
|
|
26
|
+
const pi = c?.pi ?? c;
|
|
27
|
+
const events = (pi as { events?: { emit: (name: string, payload: unknown) => void } })?.events;
|
|
28
|
+
if (!events || typeof events.emit !== "function") return;
|
|
29
|
+
events.emit("prompt:register-adapter", new FlowQuestionAdapter());
|
|
30
|
+
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlowActivityBadge — renderer for the running-flow status pill.
|
|
3
|
+
*
|
|
4
|
+
* Previously claimed the `session-card-badge` slot (which the shell
|
|
5
|
+
* mounts inside the WORKSPACE subcard — wrong place for flow status).
|
|
6
|
+
* The slot claim was dropped in `fix-flows-plugin-polish`; the badge
|
|
7
|
+
* is now consumed only by `SessionFlowActions` (rendered inside the
|
|
8
|
+
* `session-card-flows` slot, i.e. the FLOWS subcard).
|
|
9
|
+
*
|
|
10
|
+
* See change: fix-flows-plugin-polish (A5).
|
|
11
|
+
*/
|
|
1
12
|
import React, { type ReactNode } from "react";
|
|
2
13
|
import { Icon } from "@mdi/react";
|
|
3
|
-
import { mdiLoading, mdiCheckCircle, mdiAlertCircle, mdiStopCircle } from "@mdi/js";
|
|
14
|
+
import { mdiLoading, mdiCheckCircle, mdiAlertCircle, mdiStopCircle, mdiStop } from "@mdi/js";
|
|
4
15
|
import type { FlowStatus } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
5
16
|
|
|
6
17
|
const statusConfig: Record<string, { icon: ReactNode; color: string }> = {
|
|
@@ -10,24 +21,29 @@ const statusConfig: Record<string, { icon: ReactNode; color: string }> = {
|
|
|
10
21
|
aborted: { icon: <Icon path={mdiStopCircle} size={0.45} />, color: "text-orange-400" },
|
|
11
22
|
};
|
|
12
23
|
|
|
24
|
+
export interface FlowActivityBadgeProps {
|
|
25
|
+
flowName: string;
|
|
26
|
+
agentsDone?: number;
|
|
27
|
+
agentsTotal?: number;
|
|
28
|
+
status?: FlowStatus;
|
|
29
|
+
/** When provided AND status === "running", renders an "Abort" button after the badge. */
|
|
30
|
+
onAbort?: () => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
13
33
|
export function FlowActivityBadge({
|
|
14
34
|
flowName,
|
|
15
35
|
agentsDone,
|
|
16
36
|
agentsTotal,
|
|
17
37
|
status,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
agentsDone?: number;
|
|
21
|
-
agentsTotal?: number;
|
|
22
|
-
status?: FlowStatus;
|
|
23
|
-
}) {
|
|
38
|
+
onAbort,
|
|
39
|
+
}: FlowActivityBadgeProps) {
|
|
24
40
|
const { icon, color } = statusConfig[status ?? "running"] ?? statusConfig.running;
|
|
25
41
|
const isRunning = status === "running";
|
|
26
42
|
|
|
27
43
|
return (
|
|
28
|
-
<div className={`text-[11px]
|
|
44
|
+
<div className={`text-[11px] flex items-center gap-1 ${color}`}>
|
|
29
45
|
<span className="inline-flex">{icon}</span>
|
|
30
|
-
<span className="truncate">
|
|
46
|
+
<span className="truncate flex-1 min-w-0">
|
|
31
47
|
{flowName}
|
|
32
48
|
{isRunning && agentsTotal != null && agentsTotal > 0 && (
|
|
33
49
|
<span className="text-[var(--text-secondary)]"> · {agentsDone ?? 0}/{agentsTotal} agents</span>
|
|
@@ -36,6 +52,17 @@ export function FlowActivityBadge({
|
|
|
36
52
|
<span className="text-[var(--text-secondary)]"> · {status}</span>
|
|
37
53
|
)}
|
|
38
54
|
</span>
|
|
55
|
+
{isRunning && onAbort && (
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
onClick={(e) => { e.stopPropagation(); onAbort(); }}
|
|
59
|
+
className="inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] rounded border border-red-500/40 text-red-400 hover:bg-red-500/10 transition-colors flex-shrink-0"
|
|
60
|
+
title="Abort running flow"
|
|
61
|
+
>
|
|
62
|
+
<Icon path={mdiStop} size={0.4} />
|
|
63
|
+
Abort
|
|
64
|
+
</button>
|
|
65
|
+
)}
|
|
39
66
|
</div>
|
|
40
67
|
);
|
|
41
68
|
}
|
|
@@ -1,29 +1,107 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
2
|
import { Icon } from "@mdi/react";
|
|
3
|
-
import { mdiRefresh, mdiEyeOutline, mdiEyeOffOutline, mdiFileDocumentOutline } from "@mdi/js";
|
|
3
|
+
import { mdiRefresh, mdiEyeOutline, mdiEyeOffOutline, mdiFileDocumentOutline, mdiOpenInNew } from "@mdi/js";
|
|
4
4
|
import type { DashboardSession, FlowAgentState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
6
|
+
import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
7
|
+
// AgentMetricSlot is a slot CONSUMER (Phase-2 decorator slot), not a primitive
|
|
8
|
+
// — it stays as a direct import. See add-plugin-ui-primitive-registry Decision 4.
|
|
9
|
+
import { AgentMetricSlot } from "@blackbelt-technology/pi-dashboard-client-utils/extension-ui/AgentMetricSlot";
|
|
10
|
+
import { FlowAgentDetail } from "./FlowAgentDetail.js";
|
|
11
|
+
import { buildFlowAgentPopoutUrl } from "./popout-url.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* State of the agent-source fetch for the document-icon popover.
|
|
15
|
+
*
|
|
16
|
+
* Self-contained inside FlowAgentCard: when the user clicks the doc icon,
|
|
17
|
+
* we open a popover anchored to that button and fetch the agent's .md
|
|
18
|
+
* via `GET /api/pi-resource-file?path=<sourcePath>`. The bytes are then
|
|
19
|
+
* rendered with the `ui:markdown-content` primitive.
|
|
20
|
+
*
|
|
21
|
+
* See change: add-ui-popover-primitive.
|
|
22
|
+
*/
|
|
23
|
+
type AgentSourceState =
|
|
24
|
+
| { kind: "idle" }
|
|
25
|
+
| { kind: "loading" }
|
|
26
|
+
| { kind: "loaded"; content: string }
|
|
27
|
+
| { kind: "error"; error: string };
|
|
8
28
|
|
|
9
29
|
export function FlowAgentCard({
|
|
10
30
|
agent,
|
|
11
|
-
onClick,
|
|
12
|
-
onViewSource,
|
|
13
31
|
selected,
|
|
14
|
-
isDetailOpen,
|
|
15
|
-
isSourceOpen,
|
|
16
32
|
session,
|
|
33
|
+
sessionId,
|
|
34
|
+
flowId,
|
|
17
35
|
}: {
|
|
18
36
|
agent: FlowAgentState;
|
|
19
|
-
onClick?: () => void;
|
|
20
|
-
onViewSource?: () => void;
|
|
21
37
|
selected?: boolean;
|
|
22
|
-
isDetailOpen?: boolean;
|
|
23
|
-
isSourceOpen?: boolean;
|
|
24
38
|
/** Phase-2 decorator host — used for `agent-metric` filtering by agentId. */
|
|
25
39
|
session?: Pick<DashboardSession, "uiDecorators">;
|
|
40
|
+
/** Session id of the parent flow — required for the popout button. */
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
/** Flow name (acts as flow id in the URL) — required for the popout button. */
|
|
43
|
+
flowId?: string;
|
|
26
44
|
}) {
|
|
45
|
+
const popoutUrl = buildFlowAgentPopoutUrl(sessionId, flowId, agent.stepId);
|
|
46
|
+
const popoutEnabled = popoutUrl !== null;
|
|
47
|
+
const handlePopout = React.useCallback(
|
|
48
|
+
(e: React.MouseEvent) => {
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
if (popoutUrl) window.open(popoutUrl, "_blank", "noopener");
|
|
51
|
+
},
|
|
52
|
+
[popoutUrl],
|
|
53
|
+
);
|
|
54
|
+
const AgentCardShell = useUiPrimitive(UI_PRIMITIVE_KEYS.agentCard);
|
|
55
|
+
const formatTokens = useUiPrimitive(UI_PRIMITIVE_KEYS.formatTokens);
|
|
56
|
+
const formatDuration = useUiPrimitive(UI_PRIMITIVE_KEYS.formatDuration);
|
|
57
|
+
const Popover = useUiPrimitive(UI_PRIMITIVE_KEYS.popover);
|
|
58
|
+
const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
|
|
59
|
+
|
|
60
|
+
const sourceButtonRef = useRef<HTMLButtonElement | null>(null);
|
|
61
|
+
const [sourceOpen, setSourceOpen] = useState(false);
|
|
62
|
+
const [sourceState, setSourceState] = useState<AgentSourceState>({ kind: "idle" });
|
|
63
|
+
|
|
64
|
+
// Eye-button popover state: shows the FlowAgentDetail run-history view
|
|
65
|
+
// anchored to the eye button. Replaces the dormant content-view slot
|
|
66
|
+
// claim (FlowAgentDetailClaim) which took over the full chat pane.
|
|
67
|
+
// See change: add-ui-popover-primitive.
|
|
68
|
+
const detailButtonRef = useRef<HTMLButtonElement | null>(null);
|
|
69
|
+
const [detailOpen, setDetailOpen] = useState(false);
|
|
70
|
+
|
|
71
|
+
// Fetch the agent's .md when the popover opens. Mirrors the pattern of
|
|
72
|
+
// `usePiResourceFileFetch` in the dashboard client: deps include only
|
|
73
|
+
// open + path. Including state in deps causes the cleanup to fire on
|
|
74
|
+
// the idle→loading transition and self-cancel the fetch.
|
|
75
|
+
// See change: add-ui-popover-primitive.
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!sourceOpen) return;
|
|
78
|
+
if (!agent.sourcePath) {
|
|
79
|
+
setSourceState({ kind: "error", error: "No source path recorded for this agent." });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let cancelled = false;
|
|
83
|
+
setSourceState({ kind: "loading" });
|
|
84
|
+
fetch(`/api/pi-resource-file?path=${encodeURIComponent(agent.sourcePath)}`)
|
|
85
|
+
.then(async (r) => {
|
|
86
|
+
const json = await r.json();
|
|
87
|
+
if (cancelled) return;
|
|
88
|
+
if (json?.success && typeof json?.data?.content === "string") {
|
|
89
|
+
setSourceState({ kind: "loaded", content: json.data.content });
|
|
90
|
+
} else {
|
|
91
|
+
setSourceState({
|
|
92
|
+
kind: "error",
|
|
93
|
+
error: typeof json?.error === "string" ? json.error : "Failed to read source",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
.catch((err) => {
|
|
98
|
+
if (!cancelled) setSourceState({ kind: "error", error: String(err) });
|
|
99
|
+
});
|
|
100
|
+
return () => {
|
|
101
|
+
cancelled = true;
|
|
102
|
+
};
|
|
103
|
+
}, [sourceOpen, agent.sourcePath]);
|
|
104
|
+
|
|
27
105
|
const displayName = agent.label || agent.stepId || agent.agentName;
|
|
28
106
|
const displayRole = agent.cardRole || agent.model || "";
|
|
29
107
|
const isComplete = agent.status === "complete" || agent.status === "error" || agent.status === "blocked";
|
|
@@ -97,36 +175,97 @@ export function FlowAgentCard({
|
|
|
97
175
|
</div>
|
|
98
176
|
|
|
99
177
|
{/* View source / detail icons — bottom-right of card */}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
178
|
+
<div className="flex justify-end mt-auto pt-1 gap-1">
|
|
179
|
+
{agent.sourcePath && (
|
|
180
|
+
<>
|
|
181
|
+
<button
|
|
182
|
+
ref={sourceButtonRef}
|
|
183
|
+
onClick={(e) => { e.stopPropagation(); setSourceOpen((prev) => !prev); }}
|
|
184
|
+
className={`transition-colors p-0.5 rounded inline-flex items-center ${
|
|
185
|
+
sourceOpen
|
|
186
|
+
? "text-blue-400 bg-blue-400/10"
|
|
187
|
+
: "text-[var(--text-tertiary)] hover:text-blue-400 hover:bg-[var(--bg-surface)]"
|
|
188
|
+
}`}
|
|
189
|
+
title={sourceOpen ? `Close ${displayName} source` : `View ${displayName} source`}
|
|
190
|
+
>
|
|
191
|
+
<Icon path={mdiFileDocumentOutline} size={0.45} />
|
|
192
|
+
</button>
|
|
193
|
+
{sourceOpen && sourceButtonRef.current && (
|
|
194
|
+
<Popover
|
|
195
|
+
anchorEl={sourceButtonRef.current}
|
|
196
|
+
onDismiss={() => setSourceOpen(false)}
|
|
197
|
+
>
|
|
198
|
+
<div
|
|
199
|
+
className="w-[640px] max-w-[90vw] max-h-[70vh] overflow-auto bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-xl p-3"
|
|
200
|
+
onClick={(e) => e.stopPropagation()}
|
|
201
|
+
>
|
|
202
|
+
<div className="text-[11px] text-[var(--text-tertiary)] mb-2 font-mono truncate" title={agent.sourcePath}>
|
|
203
|
+
{agent.sourcePath}
|
|
204
|
+
</div>
|
|
205
|
+
{sourceState.kind === "loading" && (
|
|
206
|
+
<div className="text-xs text-[var(--text-muted)]">Loading…</div>
|
|
207
|
+
)}
|
|
208
|
+
{sourceState.kind === "error" && (
|
|
209
|
+
<div className="text-xs text-red-400">⚠ {sourceState.error}</div>
|
|
210
|
+
)}
|
|
211
|
+
{sourceState.kind === "loaded" && (
|
|
212
|
+
<MarkdownContent content={sourceState.content} />
|
|
213
|
+
)}
|
|
214
|
+
</div>
|
|
215
|
+
</Popover>
|
|
216
|
+
)}
|
|
217
|
+
</>
|
|
114
218
|
)}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
219
|
+
<button
|
|
220
|
+
type="button"
|
|
221
|
+
onClick={handlePopout}
|
|
222
|
+
disabled={!popoutEnabled}
|
|
223
|
+
data-testid="flow-agent-popout-button"
|
|
224
|
+
className={`transition-colors px-1.5 py-0.5 rounded text-[11px] inline-flex items-center gap-1 border ${
|
|
225
|
+
popoutEnabled
|
|
226
|
+
? "border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-blue-400 hover:border-blue-400/40 hover:bg-blue-400/10"
|
|
227
|
+
: "border-[var(--border-subtle)] text-[var(--text-muted)] opacity-50 cursor-not-allowed"
|
|
228
|
+
}`}
|
|
229
|
+
title={popoutEnabled ? `Open ${displayName} in new tab` : "Popout unavailable (no session context)"}
|
|
230
|
+
>
|
|
231
|
+
<Icon path={mdiOpenInNew} size={0.55} />
|
|
232
|
+
<span className="text-[10px]">Popout</span>
|
|
233
|
+
</button>
|
|
234
|
+
<button
|
|
235
|
+
ref={detailButtonRef}
|
|
236
|
+
onClick={(e) => { e.stopPropagation(); setDetailOpen((prev) => !prev); }}
|
|
237
|
+
className={`transition-colors px-1.5 py-0.5 rounded text-[11px] inline-flex items-center gap-1 border ${
|
|
238
|
+
detailOpen
|
|
239
|
+
? "text-blue-400 bg-blue-400/10 border-blue-400/40"
|
|
240
|
+
: "border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-blue-400 hover:border-blue-400/40 hover:bg-blue-400/10"
|
|
241
|
+
}`}
|
|
242
|
+
title={detailOpen ? `Close ${displayName} detail` : `View ${displayName} detail`}
|
|
243
|
+
>
|
|
244
|
+
<Icon path={detailOpen ? mdiEyeOffOutline : mdiEyeOutline} size={0.55} />
|
|
245
|
+
<span className="text-[10px]">Details</span>
|
|
246
|
+
</button>
|
|
247
|
+
{detailOpen && detailButtonRef.current && (
|
|
248
|
+
<Popover
|
|
249
|
+
anchorEl={detailButtonRef.current}
|
|
250
|
+
onDismiss={() => setDetailOpen(false)}
|
|
251
|
+
>
|
|
252
|
+
<div
|
|
253
|
+
// `h-[70vh]` (not max-h) gives MinimalChatView's `h-full`
|
|
254
|
+
// popout mode a concrete height to fill, so its inner body
|
|
255
|
+
// scrolls instead of overflowing the popover.
|
|
256
|
+
// See change: fix-flows-plugin-polish (scrollbar fix).
|
|
257
|
+
className="w-[640px] max-w-[90vw] h-[70vh] overflow-hidden bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-xl"
|
|
258
|
+
onClick={(e) => e.stopPropagation()}
|
|
124
259
|
>
|
|
125
|
-
<
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
260
|
+
<FlowAgentDetail
|
|
261
|
+
agent={agent}
|
|
262
|
+
onBack={() => setDetailOpen(false)}
|
|
263
|
+
sessionId={sessionId}
|
|
264
|
+
/>
|
|
265
|
+
</div>
|
|
266
|
+
</Popover>
|
|
267
|
+
)}
|
|
268
|
+
</div>
|
|
130
269
|
</div>
|
|
131
270
|
</AgentCardShell>
|
|
132
271
|
);
|