@blackbelt-technology/pi-dashboard-flows-plugin 0.0.0-test-darwin-x64.1

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.
@@ -0,0 +1,173 @@
1
+ import React from "react";
2
+ import { Icon } from "@mdi/react";
3
+ import { mdiArrowLeft, mdiCheckCircle, mdiCloseCircle, mdiAlertCircle, mdiCircle, mdiCircleOutline } from "@mdi/js";
4
+ import type { FlowAgentState, FlowDetailEntry } from "@blackbelt-technology/pi-dashboard-shared/types.js";
5
+ import { MarkdownContent } from "../../../client/src/components/MarkdownContent.js";
6
+
7
+ function formatTokens(n: number): string {
8
+ if (n < 1000) return String(n);
9
+ return Math.round(n / 1000) + "k";
10
+ }
11
+
12
+ function formatDuration(ms: number): string {
13
+ const sec = ms / 1000;
14
+ return sec < 60 ? `${sec.toFixed(1)}s` : `${Math.floor(sec / 60)}m ${Math.floor(sec % 60)}s`;
15
+ }
16
+
17
+ function extractInputPreview(toolName: string, input: unknown): string {
18
+ if (!input || typeof input !== "object") return "";
19
+ const inp = input as Record<string, unknown>;
20
+ switch (toolName.toLowerCase()) {
21
+ case "read":
22
+ case "write":
23
+ case "edit":
24
+ return String(inp.file_path || inp.path || "");
25
+ case "bash":
26
+ return String(inp.command || "").slice(0, 80);
27
+ case "grep":
28
+ return String(inp.pattern || "").slice(0, 40);
29
+ default:
30
+ return JSON.stringify(input).slice(0, 60);
31
+ }
32
+ }
33
+
34
+ function ToolCallEntry({ entry }: { entry: FlowDetailEntry & { kind: "tool" } }) {
35
+ const preview = extractInputPreview(entry.toolName, entry.input);
36
+ const hasOutput = entry.output !== undefined;
37
+ const [expanded, setExpanded] = React.useState(false);
38
+
39
+ return (
40
+ <div className={`border-l-2 pl-3 py-1.5 ${entry.isError ? "border-red-500/50" : "border-blue-500/30"}`}>
41
+ <div
42
+ className="flex items-center gap-1.5 cursor-pointer"
43
+ onClick={() => hasOutput && setExpanded(!expanded)}
44
+ >
45
+ <span className={`text-xs font-mono ${entry.isError ? "text-red-400" : "text-blue-400"}`}>
46
+ {entry.toolName}
47
+ </span>
48
+ <span className="text-xs text-[var(--text-tertiary)] truncate">{preview}</span>
49
+ {hasOutput && (
50
+ <span className="text-[10px] text-[var(--text-muted)] ml-auto flex-shrink-0">
51
+ {expanded ? "▾" : "▸"}
52
+ </span>
53
+ )}
54
+ </div>
55
+ {expanded && hasOutput && (
56
+ <pre className="text-[11px] text-[var(--text-secondary)] mt-1 overflow-x-auto max-h-48 overflow-y-auto whitespace-pre-wrap break-words bg-[var(--bg-tertiary)] rounded p-2">
57
+ {typeof entry.output === "string" ? entry.output : JSON.stringify(entry.output, null, 2)}
58
+ </pre>
59
+ )}
60
+ </div>
61
+ );
62
+ }
63
+
64
+ function TextEntry({ text }: { text: string }) {
65
+ return (
66
+ <div className="py-1.5 pl-3">
67
+ <MarkdownContent content={text} />
68
+ </div>
69
+ );
70
+ }
71
+
72
+ function ThinkingEntry({ text }: { text: string }) {
73
+ const [expanded, setExpanded] = React.useState(false);
74
+ return (
75
+ <div className="py-1 pl-3">
76
+ <div
77
+ className="flex items-center gap-1 cursor-pointer text-[11px] text-purple-400/70"
78
+ onClick={() => setExpanded(!expanded)}
79
+ >
80
+ <span>{expanded ? "▾" : "▸"}</span>
81
+ <span>Thinking</span>
82
+ </div>
83
+ {expanded && (
84
+ <pre className="text-[11px] text-[var(--text-muted)] mt-1 whitespace-pre-wrap break-words max-h-64 overflow-y-auto">
85
+ {text}
86
+ </pre>
87
+ )}
88
+ </div>
89
+ );
90
+ }
91
+
92
+ export function FlowAgentDetail({
93
+ agent,
94
+ onBack,
95
+ }: {
96
+ agent: FlowAgentState;
97
+ onBack: () => void;
98
+ }) {
99
+ const displayName = agent.label || agent.agentName;
100
+ const isComplete = agent.status === "complete" || agent.status === "error" || agent.status === "blocked";
101
+
102
+ const statusIconPath = agent.status === "complete" ? mdiCheckCircle
103
+ : agent.status === "error" ? mdiCloseCircle
104
+ : agent.status === "blocked" ? mdiAlertCircle
105
+ : agent.status === "running" ? mdiCircle
106
+ : mdiCircleOutline;
107
+
108
+ const statusColor = agent.status === "complete" ? "text-green-400"
109
+ : agent.status === "error" ? "text-red-400"
110
+ : agent.status === "blocked" ? "text-orange-400"
111
+ : agent.status === "running" ? "text-yellow-400"
112
+ : "text-[var(--text-tertiary)]";
113
+
114
+ return (
115
+ <div className="flex flex-col h-full overflow-hidden">
116
+ {/* Header */}
117
+ <div className="px-3 py-2 border-b border-[var(--border-subtle)] bg-[var(--bg-secondary)] flex items-center gap-2">
118
+ <button
119
+ onClick={onBack}
120
+ className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
121
+ >
122
+ <Icon path={mdiArrowLeft} size={0.7} />
123
+ </button>
124
+ <span className={`${statusColor} inline-flex`}><Icon path={statusIconPath} size={0.6} /></span>
125
+ <span className="text-sm font-medium text-[var(--text-primary)]">{displayName}</span>
126
+ {agent.model && (
127
+ <span className="text-[11px] text-[var(--text-tertiary)]">{agent.model}</span>
128
+ )}
129
+ {isComplete && agent.tokens && (
130
+ <span className="text-[11px] text-[var(--text-muted)] ml-auto">
131
+ ↑{formatTokens(agent.tokens.input)} ↓{formatTokens(agent.tokens.output)} · {formatDuration(agent.duration ?? 0)}
132
+ </span>
133
+ )}
134
+ </div>
135
+
136
+ {/* Detail history */}
137
+ <div className="flex-1 overflow-y-auto px-3 py-2 space-y-0.5">
138
+ {agent.detailHistory.length === 0 ? (
139
+ <div className="text-sm text-[var(--text-muted)] py-4 text-center">
140
+ {agent.status === "pending" ? "Waiting to start..." : "No activity yet"}
141
+ </div>
142
+ ) : (
143
+ agent.detailHistory.map((entry, i) => {
144
+ switch (entry.kind) {
145
+ case "tool":
146
+ return <ToolCallEntry key={i} entry={entry} />;
147
+ case "text":
148
+ return <TextEntry key={i} text={entry.text} />;
149
+ case "thinking":
150
+ return <ThinkingEntry key={i} text={entry.text} />;
151
+ case "error":
152
+ return (
153
+ <div key={i} className="py-1.5 pl-3 text-sm text-red-400">
154
+ {entry.text}
155
+ </div>
156
+ );
157
+ default:
158
+ return null;
159
+ }
160
+ })
161
+ )}
162
+
163
+ {/* Summary at bottom */}
164
+ {agent.summary && (
165
+ <div className="mt-3 pt-2 border-t border-[var(--border-subtle)]">
166
+ <div className="text-[11px] text-[var(--text-muted)] mb-1">Summary</div>
167
+ <MarkdownContent content={agent.summary} />
168
+ </div>
169
+ )}
170
+ </div>
171
+ </div>
172
+ );
173
+ }