@blackbelt-technology/pi-dashboard-client-utils 0.5.3
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 +103 -0
- package/src/ActionList.tsx +97 -0
- package/src/AgentCardShell.tsx +56 -0
- package/src/ConfirmDialog.tsx +37 -0
- package/src/DialogPortal.tsx +20 -0
- package/src/Popover.tsx +153 -0
- package/src/SearchableSelectDialog.tsx +133 -0
- package/src/StatusPill.tsx +83 -0
- package/src/ZoomControls.tsx +45 -0
- package/src/__tests__/ActionList.test.tsx +53 -0
- package/src/__tests__/DialogPortal.test.tsx +58 -0
- package/src/__tests__/StatusPill.test.tsx +44 -0
- package/src/__tests__/useMobile.test.tsx +92 -0
- package/src/__tests__/useZoomPan.test.ts +64 -0
- package/src/agent-card-utils.ts +42 -0
- package/src/extension-ui/AgentMetricSlot.tsx +45 -0
- package/src/extension-ui/BreadcrumbSlot.tsx +63 -0
- package/src/extension-ui/GateSlot.tsx +65 -0
- package/src/extension-ui/decorator-utils.ts +23 -0
- package/src/minimal-chat/MinimalChatView.tsx +381 -0
- package/src/minimal-chat/__tests__/MinimalChatView.test.tsx +232 -0
- package/src/minimal-chat/index.ts +16 -0
- package/src/minimal-chat/types.ts +90 -0
- package/src/useMediaQuery.ts +23 -0
- package/src/useMobile.tsx +30 -0
- package/src/useZoomPan.ts +157 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Icon } from "@mdi/react";
|
|
3
|
+
import { mdiMagnifyPlusOutline, mdiMagnifyMinusOutline, mdiArrowExpandAll } from "@mdi/js";
|
|
4
|
+
// Shared zoom controls — used by MermaidBlock and FlowGraph
|
|
5
|
+
|
|
6
|
+
export function ZoomControls({
|
|
7
|
+
onZoomIn,
|
|
8
|
+
onZoomOut,
|
|
9
|
+
onReset,
|
|
10
|
+
scale,
|
|
11
|
+
}: {
|
|
12
|
+
onZoomIn: () => void;
|
|
13
|
+
onZoomOut: () => void;
|
|
14
|
+
onReset: () => void;
|
|
15
|
+
scale: number;
|
|
16
|
+
}) {
|
|
17
|
+
const btnClass =
|
|
18
|
+
"w-7 h-7 flex items-center justify-center rounded " +
|
|
19
|
+
"bg-[var(--bg-surface)]/80 hover:bg-[var(--bg-surface)] " +
|
|
20
|
+
"border border-[var(--border-subtle)] " +
|
|
21
|
+
"text-[var(--text-secondary)] hover:text-[var(--text-primary)] " +
|
|
22
|
+
"transition-colors cursor-pointer select-none";
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div
|
|
26
|
+
className="absolute top-2 right-2 z-10 flex flex-col gap-1"
|
|
27
|
+
onPointerDown={(e) => e.stopPropagation()}
|
|
28
|
+
>
|
|
29
|
+
<button className={btnClass} onClick={onZoomIn} title="Zoom in">
|
|
30
|
+
<Icon path={mdiMagnifyPlusOutline} size={0.6} />
|
|
31
|
+
</button>
|
|
32
|
+
<button className={btnClass} onClick={onZoomOut} title="Zoom out">
|
|
33
|
+
<Icon path={mdiMagnifyMinusOutline} size={0.6} />
|
|
34
|
+
</button>
|
|
35
|
+
<button className={btnClass} onClick={onReset} title="Reset zoom">
|
|
36
|
+
<Icon path={mdiArrowExpandAll} size={0.6} />
|
|
37
|
+
</button>
|
|
38
|
+
{scale !== 1 && (
|
|
39
|
+
<div className="text-[10px] text-[var(--text-muted)] text-center tabular-nums">
|
|
40
|
+
{Math.round(scale * 100)}%
|
|
41
|
+
</div>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
3
|
+
import { render, fireEvent, cleanup } from "@testing-library/react";
|
|
4
|
+
import { ActionList } from "../ActionList.js";
|
|
5
|
+
|
|
6
|
+
afterEach(() => cleanup());
|
|
7
|
+
|
|
8
|
+
describe("ActionList", () => {
|
|
9
|
+
it("renders nothing for empty actions", () => {
|
|
10
|
+
const { container } = render(<ActionList actions={[]} />);
|
|
11
|
+
expect(container.firstChild).toBeNull();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("renders each action as a button", () => {
|
|
15
|
+
const { getAllByRole } = render(
|
|
16
|
+
<ActionList
|
|
17
|
+
actions={[
|
|
18
|
+
{ label: "Run A" },
|
|
19
|
+
{ label: "Run B" },
|
|
20
|
+
]}
|
|
21
|
+
/>,
|
|
22
|
+
);
|
|
23
|
+
const buttons = getAllByRole("button");
|
|
24
|
+
expect(buttons).toHaveLength(2);
|
|
25
|
+
expect(buttons[0].textContent).toContain("Run A");
|
|
26
|
+
expect(buttons[1].textContent).toContain("Run B");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("clicking calls onClick", () => {
|
|
30
|
+
const onClick = vi.fn();
|
|
31
|
+
const { getByRole } = render(
|
|
32
|
+
<ActionList actions={[{ label: "Run", onClick }]} />,
|
|
33
|
+
);
|
|
34
|
+
fireEvent.click(getByRole("button"));
|
|
35
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("disabled buttons do not trigger onClick", () => {
|
|
39
|
+
const onClick = vi.fn();
|
|
40
|
+
const { getByRole } = render(
|
|
41
|
+
<ActionList actions={[{ label: "Run", onClick, disabled: true }]} />,
|
|
42
|
+
);
|
|
43
|
+
fireEvent.click(getByRole("button"));
|
|
44
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("tooltip is set from `tooltip` prop", () => {
|
|
48
|
+
const { getByRole } = render(
|
|
49
|
+
<ActionList actions={[{ label: "Run", tooltip: "Run flow X" }]} />,
|
|
50
|
+
);
|
|
51
|
+
expect(getByRole("button").getAttribute("title")).toBe("Run flow X");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
+
import { render, cleanup } from "@testing-library/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { DialogPortal } from "../DialogPortal.js";
|
|
5
|
+
|
|
6
|
+
afterEach(() => cleanup());
|
|
7
|
+
|
|
8
|
+
describe("DialogPortal", () => {
|
|
9
|
+
it("renders children at document.body", () => {
|
|
10
|
+
const { baseElement } = render(
|
|
11
|
+
<div id="app-root">
|
|
12
|
+
<DialogPortal>
|
|
13
|
+
<div data-testid="dialog-content">Hello</div>
|
|
14
|
+
</DialogPortal>
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
// Child should be in body, not inside #app-root
|
|
18
|
+
const content = baseElement.querySelector("[data-testid='dialog-content']");
|
|
19
|
+
expect(content).toBeTruthy();
|
|
20
|
+
expect(content!.textContent).toBe("Hello");
|
|
21
|
+
// Should NOT be inside #app-root
|
|
22
|
+
const appRoot = baseElement.querySelector("#app-root");
|
|
23
|
+
expect(appRoot!.querySelector("[data-testid='dialog-content']")).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("sets document.body overflow to hidden on mount", () => {
|
|
27
|
+
document.body.style.overflow = "";
|
|
28
|
+
render(
|
|
29
|
+
<DialogPortal>
|
|
30
|
+
<div>Dialog</div>
|
|
31
|
+
</DialogPortal>
|
|
32
|
+
);
|
|
33
|
+
expect(document.body.style.overflow).toBe("hidden");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("restores document.body overflow on unmount", () => {
|
|
37
|
+
document.body.style.overflow = "auto";
|
|
38
|
+
const { unmount } = render(
|
|
39
|
+
<DialogPortal>
|
|
40
|
+
<div>Dialog</div>
|
|
41
|
+
</DialogPortal>
|
|
42
|
+
);
|
|
43
|
+
expect(document.body.style.overflow).toBe("hidden");
|
|
44
|
+
unmount();
|
|
45
|
+
expect(document.body.style.overflow).toBe("auto");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("restores empty overflow on unmount when originally empty", () => {
|
|
49
|
+
document.body.style.overflow = "";
|
|
50
|
+
const { unmount } = render(
|
|
51
|
+
<DialogPortal>
|
|
52
|
+
<div>Dialog</div>
|
|
53
|
+
</DialogPortal>
|
|
54
|
+
);
|
|
55
|
+
unmount();
|
|
56
|
+
expect(document.body.style.overflow).toBe("");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
3
|
+
import { render, cleanup } from "@testing-library/react";
|
|
4
|
+
import { StatusPill } from "../StatusPill.js";
|
|
5
|
+
|
|
6
|
+
afterEach(() => cleanup());
|
|
7
|
+
|
|
8
|
+
describe("StatusPill", () => {
|
|
9
|
+
it("renders the text", () => {
|
|
10
|
+
const { getByText } = render(<StatusPill state="running" text="Working" />);
|
|
11
|
+
expect(getByText("Working")).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("sets data-status-pill attribute to state", () => {
|
|
15
|
+
const { container } = render(<StatusPill state="error" text="Failed" />);
|
|
16
|
+
expect(container.firstChild).toHaveProperty("dataset");
|
|
17
|
+
const el = container.querySelector("[data-status-pill]");
|
|
18
|
+
expect(el?.getAttribute("data-status-pill")).toBe("error");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("each state renders with state-specific styling", () => {
|
|
22
|
+
const states: Array<"running" | "success" | "error" | "info" | "warn" | "muted"> = [
|
|
23
|
+
"running",
|
|
24
|
+
"success",
|
|
25
|
+
"error",
|
|
26
|
+
"info",
|
|
27
|
+
"warn",
|
|
28
|
+
"muted",
|
|
29
|
+
];
|
|
30
|
+
for (const state of states) {
|
|
31
|
+
const { container, unmount } = render(<StatusPill state={state} text={state} />);
|
|
32
|
+
const el = container.querySelector(`[data-status-pill="${state}"]`);
|
|
33
|
+
expect(el).toBeTruthy();
|
|
34
|
+
unmount();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("tooltip is set from `tooltip` prop", () => {
|
|
39
|
+
const { container } = render(
|
|
40
|
+
<StatusPill state="running" text="X" tooltip="Currently running" />,
|
|
41
|
+
);
|
|
42
|
+
expect(container.firstChild?.parentElement?.getAttribute("title") ?? container.querySelector("[title]")?.getAttribute("title")).toBe("Currently running");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { renderHook } from "@testing-library/react";
|
|
4
|
+
import { MobileProvider, useMobile } from "../useMobile.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Mocks `window.matchMedia` so it answers any query string the way a browser
|
|
8
|
+
* with the given viewport (vw, vh) would: parses `(max-width: Npx)` and
|
|
9
|
+
* `(max-height: Npx)` clauses, treats commas as OR. This mirrors what
|
|
10
|
+
* `useMediaQuery` consumes — the comma-OR semantics is the actual contract
|
|
11
|
+
* we want to pin in `useMobile`.
|
|
12
|
+
*/
|
|
13
|
+
function installMatchMediaForViewport(vw: number, vh: number): void {
|
|
14
|
+
Object.defineProperty(window, "matchMedia", {
|
|
15
|
+
writable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
value: vi.fn().mockImplementation((query: string) => {
|
|
18
|
+
const clauses = query.split(",").map((c) => c.trim());
|
|
19
|
+
const matches = clauses.some((clause) => {
|
|
20
|
+
const w = clause.match(/\(\s*max-width:\s*(\d+)px\s*\)/);
|
|
21
|
+
if (w) return vw <= Number(w[1]);
|
|
22
|
+
const h = clause.match(/\(\s*max-height:\s*(\d+)px\s*\)/);
|
|
23
|
+
if (h) return vh <= Number(h[1]);
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
matches,
|
|
28
|
+
media: query,
|
|
29
|
+
onchange: null,
|
|
30
|
+
addListener: vi.fn(),
|
|
31
|
+
removeListener: vi.fn(),
|
|
32
|
+
addEventListener: vi.fn(),
|
|
33
|
+
removeEventListener: vi.fn(),
|
|
34
|
+
dispatchEvent: vi.fn(),
|
|
35
|
+
};
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function wrapper({ children }: { children: React.ReactNode }) {
|
|
41
|
+
return <MobileProvider>{children}</MobileProvider>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe("useMobile — width-or-height predicate", () => {
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
vi.restoreAllMocks();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("portrait phone (375x812) is mobile (width arm)", () => {
|
|
50
|
+
installMatchMediaForViewport(375, 812);
|
|
51
|
+
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
52
|
+
expect(result.current).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("landscape phone (844x390) is mobile (height arm) — the iPhone 14 case", () => {
|
|
56
|
+
installMatchMediaForViewport(844, 390);
|
|
57
|
+
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
58
|
+
expect(result.current).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("landscape phone (915x412) is mobile (height arm) — the Pixel 8 case", () => {
|
|
62
|
+
installMatchMediaForViewport(915, 412);
|
|
63
|
+
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
64
|
+
expect(result.current).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("tablet portrait (768x1024) is NOT mobile", () => {
|
|
68
|
+
installMatchMediaForViewport(768, 1024);
|
|
69
|
+
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
70
|
+
expect(result.current).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("tablet landscape (1024x768) is NOT mobile", () => {
|
|
74
|
+
installMatchMediaForViewport(1024, 768);
|
|
75
|
+
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
76
|
+
expect(result.current).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("desktop (1440x900) is NOT mobile", () => {
|
|
80
|
+
installMatchMediaForViewport(1440, 900);
|
|
81
|
+
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
82
|
+
expect(result.current).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("desktop short window (1200x500) flips to mobile (documented side effect)", () => {
|
|
86
|
+
// Pinned regression: shrinking a desktop window vertically below 600px
|
|
87
|
+
// intentionally enters mobile mode. See design.md decision 1 alternatives.
|
|
88
|
+
installMatchMediaForViewport(1200, 500);
|
|
89
|
+
const { result } = renderHook(() => useMobile(), { wrapper });
|
|
90
|
+
expect(result.current).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import { useZoomPan } from "../useZoomPan.js";
|
|
4
|
+
|
|
5
|
+
describe("useZoomPan", () => {
|
|
6
|
+
it("starts at scale 1 with zero translate", () => {
|
|
7
|
+
const { result } = renderHook(() => useZoomPan());
|
|
8
|
+
expect(result.current.state).toEqual({ scale: 1, translateX: 0, translateY: 0 });
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("zoomIn increases scale by step", () => {
|
|
12
|
+
const { result } = renderHook(() => useZoomPan({ zoomStep: 1.2 }));
|
|
13
|
+
act(() => result.current.zoomIn());
|
|
14
|
+
expect(result.current.state.scale).toBeCloseTo(1.2);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("zoomOut decreases scale by step", () => {
|
|
18
|
+
const { result } = renderHook(() => useZoomPan({ zoomStep: 1.2 }));
|
|
19
|
+
act(() => result.current.zoomOut());
|
|
20
|
+
expect(result.current.state.scale).toBeCloseTo(1 / 1.2);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("clamps scale at maxScale", () => {
|
|
24
|
+
const { result } = renderHook(() => useZoomPan({ maxScale: 2, zoomStep: 2 }));
|
|
25
|
+
act(() => result.current.zoomIn()); // 2
|
|
26
|
+
act(() => result.current.zoomIn()); // clamped to 2
|
|
27
|
+
expect(result.current.state.scale).toBe(2);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("clamps scale at minScale", () => {
|
|
31
|
+
const { result } = renderHook(() => useZoomPan({ minScale: 0.5, zoomStep: 2 }));
|
|
32
|
+
act(() => result.current.zoomOut()); // 0.5
|
|
33
|
+
act(() => result.current.zoomOut()); // clamped to 0.5
|
|
34
|
+
expect(result.current.state.scale).toBe(0.5);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("reset restores initial state", () => {
|
|
38
|
+
const { result } = renderHook(() => useZoomPan());
|
|
39
|
+
act(() => result.current.zoomIn());
|
|
40
|
+
act(() => result.current.zoomIn());
|
|
41
|
+
expect(result.current.state.scale).not.toBe(1);
|
|
42
|
+
act(() => result.current.reset());
|
|
43
|
+
expect(result.current.state).toEqual({ scale: 1, translateX: 0, translateY: 0 });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("double-click resets state", () => {
|
|
47
|
+
const { result } = renderHook(() => useZoomPan());
|
|
48
|
+
act(() => result.current.zoomIn());
|
|
49
|
+
act(() => result.current.handlers.onDoubleClick());
|
|
50
|
+
expect(result.current.state).toEqual({ scale: 1, translateX: 0, translateY: 0 });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("exposes all expected handler keys", () => {
|
|
54
|
+
const { result } = renderHook(() => useZoomPan());
|
|
55
|
+
const keys = Object.keys(result.current.handlers);
|
|
56
|
+
expect(keys).toContain("onWheel");
|
|
57
|
+
expect(keys).toContain("onPointerDown");
|
|
58
|
+
expect(keys).toContain("onPointerMove");
|
|
59
|
+
expect(keys).toContain("onPointerUp");
|
|
60
|
+
expect(keys).toContain("onTouchMove");
|
|
61
|
+
expect(keys).toContain("onTouchEnd");
|
|
62
|
+
expect(keys).toContain("onDoubleClick");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for agent card rendering.
|
|
3
|
+
* Used by FlowAgentCard (flows) and AgentToolRenderer (subagents).
|
|
4
|
+
*/
|
|
5
|
+
import React, { type ReactNode } from "react";
|
|
6
|
+
import { Icon } from "@mdi/react";
|
|
7
|
+
import { mdiCircleOutline, mdiLoading, mdiCheckCircle, mdiCloseCircle, mdiAlertCircle, mdiStop, mdiPause } from "@mdi/js";
|
|
8
|
+
|
|
9
|
+
/** Format a token count compactly: 500 → "500", 12000 → "12k" */
|
|
10
|
+
export function formatTokens(n: number): string {
|
|
11
|
+
if (n < 1000) return String(n);
|
|
12
|
+
return Math.round(n / 1000) + "k";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Format milliseconds as human-readable duration */
|
|
16
|
+
export function formatDuration(ms: number): string {
|
|
17
|
+
const sec = ms / 1000;
|
|
18
|
+
return sec < 60 ? `${sec.toFixed(1)}s` : `${Math.floor(sec / 60)}m ${Math.floor(sec % 60)}s`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type AgentCardStatus = "pending" | "running" | "complete" | "error" | "blocked" | "stopped" | "background";
|
|
22
|
+
|
|
23
|
+
export interface StatusIconDef {
|
|
24
|
+
icon: ReactNode;
|
|
25
|
+
color: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Status icon definitions for agent cards */
|
|
29
|
+
export const statusIconDefs: Record<string, StatusIconDef> = {
|
|
30
|
+
pending: { icon: React.createElement(Icon, { path: mdiCircleOutline, size: 0.55 }), color: "text-[var(--text-tertiary)]" },
|
|
31
|
+
running: { icon: React.createElement(Icon, { path: mdiLoading, size: 0.55, className: "animate-spin" }), color: "text-yellow-400" },
|
|
32
|
+
complete: { icon: React.createElement(Icon, { path: mdiCheckCircle, size: 0.55 }), color: "text-green-400" },
|
|
33
|
+
error: { icon: React.createElement(Icon, { path: mdiCloseCircle, size: 0.55 }), color: "text-red-400" },
|
|
34
|
+
blocked: { icon: React.createElement(Icon, { path: mdiAlertCircle, size: 0.55 }), color: "text-orange-400" },
|
|
35
|
+
stopped: { icon: React.createElement(Icon, { path: mdiStop, size: 0.55 }), color: "text-[var(--text-tertiary)]" },
|
|
36
|
+
background: { icon: React.createElement(Icon, { path: mdiPause, size: 0.55 }), color: "text-blue-400" },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Get status icon + color, with fallback to pending */
|
|
40
|
+
export function getStatusIcon(status: string): StatusIconDef {
|
|
41
|
+
return statusIconDefs[status] ?? statusIconDefs.pending;
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase-2 slot: agent-metric.
|
|
3
|
+
*
|
|
4
|
+
* Renders all `kind: "agent-metric"` descriptors whose `payload.agentId`
|
|
5
|
+
* matches the agent rendered by the parent `FlowAgentCard`. Mounted inside
|
|
6
|
+
* `FlowAgentCard.tsx`. Descriptors targeting an unknown agentId are
|
|
7
|
+
* silently ignored (no orphan rendering).
|
|
8
|
+
*
|
|
9
|
+
* See change: add-extension-ui-decorations, design.md §6.
|
|
10
|
+
*/
|
|
11
|
+
import React from "react";
|
|
12
|
+
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
13
|
+
import { decoratorsOfKind } from "./decorator-utils.js";
|
|
14
|
+
|
|
15
|
+
export function AgentMetricSlot({
|
|
16
|
+
session,
|
|
17
|
+
agentId,
|
|
18
|
+
}: {
|
|
19
|
+
session: Pick<DashboardSession, "uiDecorators"> | undefined;
|
|
20
|
+
agentId: string;
|
|
21
|
+
}) {
|
|
22
|
+
if (!session) return null;
|
|
23
|
+
const metrics = decoratorsOfKind(session.uiDecorators, "agent-metric").filter(
|
|
24
|
+
(d) => d.payload.agentId === agentId,
|
|
25
|
+
);
|
|
26
|
+
if (metrics.length === 0) return null;
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
className="text-[10px] text-[var(--text-secondary)] mt-0.5 truncate"
|
|
30
|
+
data-testid="agent-metric-slot"
|
|
31
|
+
>
|
|
32
|
+
{metrics.map((d, i) => (
|
|
33
|
+
<span
|
|
34
|
+
key={`${d.namespace}:${d.id}`}
|
|
35
|
+
title={d.payload.tooltip}
|
|
36
|
+
className="inline-block"
|
|
37
|
+
data-testid={`agent-metric:${d.namespace}:${d.id}`}
|
|
38
|
+
>
|
|
39
|
+
{i > 0 && <span className="mx-1 text-[var(--text-tertiary)]"> │ </span>}
|
|
40
|
+
{d.payload.text}
|
|
41
|
+
</span>
|
|
42
|
+
))}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase-2 slot: breadcrumb.
|
|
3
|
+
*
|
|
4
|
+
* Renders the most-recently-cached `kind: "breadcrumb"` descriptor as a
|
|
5
|
+
* horizontal step indicator at the top of `FlowDashboard`. When multiple
|
|
6
|
+
* breadcrumbs are pushed (rare; collision case), the last one in iteration
|
|
7
|
+
* order wins — matches the spec contract documented in design.md §11.
|
|
8
|
+
*
|
|
9
|
+
* Step rendering:
|
|
10
|
+
* - status: "active" — highlighted (or matches `payload.current`)
|
|
11
|
+
* - status: "done" — dimmed with check
|
|
12
|
+
* - status: "error" — red
|
|
13
|
+
* - status: "pending" — neutral
|
|
14
|
+
*
|
|
15
|
+
* See change: add-extension-ui-decorations.
|
|
16
|
+
*/
|
|
17
|
+
import React from "react";
|
|
18
|
+
import { Icon } from "@mdi/react";
|
|
19
|
+
import { mdiCheck, mdiAlertCircle } from "@mdi/js";
|
|
20
|
+
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
21
|
+
import { decoratorsOfKind } from "./decorator-utils.js";
|
|
22
|
+
|
|
23
|
+
export function BreadcrumbSlot({ session }: { session: Pick<DashboardSession, "uiDecorators"> | undefined }) {
|
|
24
|
+
if (!session) return null;
|
|
25
|
+
const breadcrumbs = decoratorsOfKind(session.uiDecorators, "breadcrumb");
|
|
26
|
+
if (breadcrumbs.length === 0) return null;
|
|
27
|
+
// Last-write-wins on collision (most recently cached entry).
|
|
28
|
+
const bc = breadcrumbs[breadcrumbs.length - 1]!;
|
|
29
|
+
const { steps, current } = bc.payload;
|
|
30
|
+
const activeId = current ?? steps.find((s) => s.status === "active")?.id;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
className="flex items-center gap-1 text-[11px] mb-2 flex-wrap"
|
|
35
|
+
data-testid="breadcrumb-slot"
|
|
36
|
+
>
|
|
37
|
+
{steps.map((s, i) => {
|
|
38
|
+
const isActive = s.id === activeId;
|
|
39
|
+
const cls =
|
|
40
|
+
s.status === "error"
|
|
41
|
+
? "text-red-400"
|
|
42
|
+
: s.status === "done"
|
|
43
|
+
? "text-[var(--text-tertiary)]"
|
|
44
|
+
: isActive
|
|
45
|
+
? "text-blue-400 font-medium"
|
|
46
|
+
: "text-[var(--text-secondary)]";
|
|
47
|
+
return (
|
|
48
|
+
<React.Fragment key={s.id}>
|
|
49
|
+
<span
|
|
50
|
+
className={`inline-flex items-center gap-0.5 ${cls}`}
|
|
51
|
+
data-testid={`breadcrumb-step:${s.id}`}
|
|
52
|
+
>
|
|
53
|
+
{s.status === "done" && <Icon path={mdiCheck} size={0.4} />}
|
|
54
|
+
{s.status === "error" && <Icon path={mdiAlertCircle} size={0.4} />}
|
|
55
|
+
{s.label}
|
|
56
|
+
</span>
|
|
57
|
+
{i < steps.length - 1 && <span className="text-[var(--text-tertiary)]">›</span>}
|
|
58
|
+
</React.Fragment>
|
|
59
|
+
);
|
|
60
|
+
})}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase-2 slot: gate.
|
|
3
|
+
*
|
|
4
|
+
* Renders gate state for a single flow inside `FlowLaunchDialog`. When any
|
|
5
|
+
* `gate` descriptor for the matching `flowId` declares `available: false`,
|
|
6
|
+
* the slot exposes a most-restrictive aggregate banner (parent uses
|
|
7
|
+
* `useGateState` to disable the Run button + render the reason tooltip).
|
|
8
|
+
*
|
|
9
|
+
* See change: add-extension-ui-decorations, design.md §6 (most-restrictive-wins).
|
|
10
|
+
*/
|
|
11
|
+
import React from "react";
|
|
12
|
+
import { Icon } from "@mdi/react";
|
|
13
|
+
import { mdiAlertCircleOutline } from "@mdi/js";
|
|
14
|
+
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
15
|
+
import { decoratorsOfKind } from "./decorator-utils.js";
|
|
16
|
+
|
|
17
|
+
export interface GateState {
|
|
18
|
+
available: boolean;
|
|
19
|
+
/** Concatenated reasons from any `available: false` descriptors. */
|
|
20
|
+
reason?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Pure helper: aggregate gate descriptors for a `flowId` into a single state.
|
|
25
|
+
*
|
|
26
|
+
* Most-restrictive-wins: any `available: false` makes the aggregate
|
|
27
|
+
* unavailable; reasons from all contributing unavailable descriptors are
|
|
28
|
+
* concatenated (newline-joined). When no descriptors target this flowId,
|
|
29
|
+
* returns `{ available: true }` (fully open).
|
|
30
|
+
*/
|
|
31
|
+
export function aggregateGateState(
|
|
32
|
+
decorators: Record<string, import("@blackbelt-technology/pi-dashboard-shared/types.js").DecoratorDescriptor> | undefined,
|
|
33
|
+
flowId: string,
|
|
34
|
+
): GateState {
|
|
35
|
+
const gates = decoratorsOfKind(decorators, "gate").filter((d) => d.payload.flowId === flowId);
|
|
36
|
+
if (gates.length === 0) return { available: true };
|
|
37
|
+
const blocked = gates.filter((d) => d.payload.available === false);
|
|
38
|
+
if (blocked.length === 0) return { available: true };
|
|
39
|
+
const reasons = blocked.map((d) => d.payload.reason).filter((r): r is string => typeof r === "string" && r.length > 0);
|
|
40
|
+
return {
|
|
41
|
+
available: false,
|
|
42
|
+
reason: reasons.length > 0 ? reasons.join("\n") : undefined,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function GateSlot({
|
|
47
|
+
session,
|
|
48
|
+
flowId,
|
|
49
|
+
}: {
|
|
50
|
+
session: Pick<DashboardSession, "uiDecorators"> | undefined;
|
|
51
|
+
flowId: string;
|
|
52
|
+
}) {
|
|
53
|
+
const state = aggregateGateState(session?.uiDecorators, flowId);
|
|
54
|
+
if (state.available) return null;
|
|
55
|
+
return (
|
|
56
|
+
<div
|
|
57
|
+
className="flex items-start gap-1 text-[11px] text-amber-400 bg-amber-400/10 border border-amber-400/30 rounded px-2 py-1 mb-2"
|
|
58
|
+
title={state.reason}
|
|
59
|
+
data-testid="gate-slot"
|
|
60
|
+
>
|
|
61
|
+
<Icon path={mdiAlertCircleOutline} size={0.5} className="flex-shrink-0 mt-0.5" />
|
|
62
|
+
<span className="whitespace-pre-line">{state.reason ?? "Unavailable"}</span>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for Phase-2 decorator slot components.
|
|
3
|
+
*
|
|
4
|
+
* Decorators live on `DashboardSession.uiDecorators` keyed by
|
|
5
|
+
* `${kind}:${namespace}:${id}`. Slots filter by `kind` and (where relevant)
|
|
6
|
+
* by a payload field (`agentId`, `flowId`).
|
|
7
|
+
*
|
|
8
|
+
* See change: add-extension-ui-decorations.
|
|
9
|
+
*/
|
|
10
|
+
import type { DecoratorDescriptor, DecoratorKind } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
11
|
+
|
|
12
|
+
/** Type narrowing: extract descriptors of a specific kind from a record. */
|
|
13
|
+
export function decoratorsOfKind<K extends DecoratorKind>(
|
|
14
|
+
decorators: Record<string, DecoratorDescriptor> | undefined,
|
|
15
|
+
kind: K,
|
|
16
|
+
): Array<Extract<DecoratorDescriptor, { kind: K }>> {
|
|
17
|
+
if (!decorators) return [];
|
|
18
|
+
const out: Array<Extract<DecoratorDescriptor, { kind: K }>> = [];
|
|
19
|
+
for (const d of Object.values(decorators)) {
|
|
20
|
+
if (d.kind === kind) out.push(d as Extract<DecoratorDescriptor, { kind: K }>);
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|