@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
|
@@ -1,173 +1,122 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* FlowAgentDetail — thin adapter shim over `MinimalChatView`.
|
|
3
|
+
*
|
|
4
|
+
* Maps `FlowAgentState` → `MinimalChatViewProps`. Preserves the existing
|
|
5
|
+
* public API (`agent`, `onBack`) so `FlowAgentCard`'s eye-button detail
|
|
6
|
+
* dialog keeps working without change.
|
|
7
|
+
*
|
|
8
|
+
* See change: extract-minimal-chat-view.
|
|
9
|
+
*/
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
import { useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
12
|
+
import {
|
|
13
|
+
type MinimalChatEntry,
|
|
14
|
+
type MinimalChatStatus,
|
|
15
|
+
MinimalChatView,
|
|
16
|
+
} from "@blackbelt-technology/pi-dashboard-client-utils/minimal-chat";
|
|
17
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
18
|
+
import type {
|
|
19
|
+
FlowAgentState,
|
|
20
|
+
FlowAgentStatus,
|
|
21
|
+
FlowDetailEntry,
|
|
22
|
+
} from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
23
|
+
import React from "react";
|
|
24
|
+
import { formatCost } from "./FlowAgentCard.js";
|
|
16
25
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
case "
|
|
22
|
-
|
|
23
|
-
case "
|
|
24
|
-
return
|
|
25
|
-
case "
|
|
26
|
-
return
|
|
27
|
-
case "
|
|
28
|
-
return
|
|
29
|
-
default:
|
|
30
|
-
|
|
26
|
+
function mapFlowStatus(status: FlowAgentStatus): MinimalChatStatus {
|
|
27
|
+
switch (status) {
|
|
28
|
+
case "pending":
|
|
29
|
+
return "pending";
|
|
30
|
+
case "running":
|
|
31
|
+
return "running";
|
|
32
|
+
case "complete":
|
|
33
|
+
return "complete";
|
|
34
|
+
case "error":
|
|
35
|
+
return "error";
|
|
36
|
+
case "blocked":
|
|
37
|
+
return "blocked";
|
|
38
|
+
default: {
|
|
39
|
+
const _exhaustive: never = status;
|
|
40
|
+
void _exhaustive;
|
|
41
|
+
return "pending";
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
45
|
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
);
|
|
46
|
+
function mapFlowEntries(detailHistory: FlowDetailEntry[]): MinimalChatEntry[] {
|
|
47
|
+
return detailHistory.map((e) => {
|
|
48
|
+
switch (e.kind) {
|
|
49
|
+
case "tool":
|
|
50
|
+
return {
|
|
51
|
+
kind: "tool",
|
|
52
|
+
toolName: e.toolName,
|
|
53
|
+
input: e.input,
|
|
54
|
+
output: e.output,
|
|
55
|
+
isError: e.isError,
|
|
56
|
+
};
|
|
57
|
+
case "text":
|
|
58
|
+
return { kind: "text", text: e.text };
|
|
59
|
+
case "thinking":
|
|
60
|
+
return { kind: "thinking", text: e.text };
|
|
61
|
+
case "error":
|
|
62
|
+
return { kind: "error", text: e.text };
|
|
63
|
+
default: {
|
|
64
|
+
const _exhaustive: never = e;
|
|
65
|
+
void _exhaustive;
|
|
66
|
+
return { kind: "error", text: "(unknown entry)" };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
90
70
|
}
|
|
91
71
|
|
|
92
72
|
export function FlowAgentDetail({
|
|
93
73
|
agent,
|
|
94
74
|
onBack,
|
|
75
|
+
sessionId,
|
|
95
76
|
}: {
|
|
96
77
|
agent: FlowAgentState;
|
|
97
|
-
onBack
|
|
78
|
+
onBack?: () => void;
|
|
79
|
+
/** Forwarded to MinimalChatView so per-tool renderers can build session-scoped links. */
|
|
80
|
+
sessionId?: string;
|
|
98
81
|
}) {
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
: agent.status === "running" ? mdiCircle
|
|
106
|
-
: mdiCircleOutline;
|
|
82
|
+
const t = useT();
|
|
83
|
+
const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
|
|
84
|
+
const title = agent.label || agent.agentName;
|
|
85
|
+
const status = mapFlowStatus(agent.status);
|
|
86
|
+
const isComplete =
|
|
87
|
+
agent.status === "complete" || agent.status === "error" || agent.status === "blocked";
|
|
107
88
|
|
|
108
|
-
const
|
|
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)]";
|
|
89
|
+
const entries = mapFlowEntries(agent.detailHistory);
|
|
113
90
|
|
|
114
|
-
|
|
115
|
-
<div className="
|
|
116
|
-
{
|
|
117
|
-
<
|
|
118
|
-
|
|
119
|
-
|
|
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>
|
|
91
|
+
const footer = agent.summary ? (
|
|
92
|
+
<div className="mt-3 pt-2 border-t border-[var(--border-subtle)]">
|
|
93
|
+
<div className="text-[11px] text-[var(--text-muted)] mb-1">{t("summary", undefined, "Summary")}</div>
|
|
94
|
+
<MarkdownContent content={agent.summary} />
|
|
95
|
+
</div>
|
|
96
|
+
) : undefined;
|
|
135
97
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
)}
|
|
98
|
+
const emptyMessage =
|
|
99
|
+
agent.status === "pending"
|
|
100
|
+
? t("waitingToStart", undefined, "Waiting to start...")
|
|
101
|
+
: t("noActivityYet", undefined, "No activity yet");
|
|
162
102
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
103
|
+
return (
|
|
104
|
+
<MinimalChatView
|
|
105
|
+
title={title}
|
|
106
|
+
status={status}
|
|
107
|
+
entries={entries}
|
|
108
|
+
mode="popout"
|
|
109
|
+
onBack={onBack}
|
|
110
|
+
sessionId={sessionId}
|
|
111
|
+
hideToolStatusIcon
|
|
112
|
+
meta={{
|
|
113
|
+
modelName: agent.model,
|
|
114
|
+
tokens: agent.tokens,
|
|
115
|
+
cost: agent.cost != null && agent.cost > 0 ? formatCost(agent.cost) : undefined,
|
|
116
|
+
durationMs: isComplete ? agent.duration : undefined,
|
|
117
|
+
}}
|
|
118
|
+
emptyMessage={emptyMessage}
|
|
119
|
+
footer={footer}
|
|
120
|
+
/>
|
|
172
121
|
);
|
|
173
122
|
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool renderer for the `flow_agents` authoring tool (main-session timeline).
|
|
3
|
+
*
|
|
4
|
+
* Renders from the real tool contract:
|
|
5
|
+
* op:"list" → result is a catalog array `[{ name, description, … }]`.
|
|
6
|
+
* op:"write" → result is `{ written, name, path, diagnostics[] }` /
|
|
7
|
+
* `{ written:false, error }`.
|
|
8
|
+
* The agent markdown body for the "view agent file" sub-row comes from the
|
|
9
|
+
* tool ARGS (`toolInput.content`), not the result.
|
|
10
|
+
*
|
|
11
|
+
* See change: rework-flows-plugin-for-new-pi-flows.
|
|
12
|
+
*/
|
|
13
|
+
import React, { useState } from "react";
|
|
14
|
+
|
|
15
|
+
// A per-agent catalog entry. All fields optional/duck-typed: pi-flows may add
|
|
16
|
+
// or drop fields, and text-parsed entries nest `architect.use_when`. The
|
|
17
|
+
// renderer renders whatever is present. See change: flow-agents-readable-list.
|
|
18
|
+
interface AgentListEntry {
|
|
19
|
+
name?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
source_type?: string;
|
|
22
|
+
source_path?: string;
|
|
23
|
+
tools?: string[];
|
|
24
|
+
inputs?: string[];
|
|
25
|
+
outputs?: Array<string | { name?: string }>;
|
|
26
|
+
use_when?: string;
|
|
27
|
+
architect?: { use_when?: string };
|
|
28
|
+
}
|
|
29
|
+
interface AgentWriteResult {
|
|
30
|
+
written?: boolean;
|
|
31
|
+
name?: string;
|
|
32
|
+
path?: string;
|
|
33
|
+
diagnostics?: Array<{ message?: string } | string>;
|
|
34
|
+
error?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function diagText(d: { message?: string } | string): string {
|
|
38
|
+
return typeof d === "string" ? d : (d.message ?? JSON.stringify(d));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Display truncation marker prepended by the host when a tool result exceeds
|
|
42
|
+
// the line cap (see client event-reducer TRUNCATION_MARKER_PREFIX). Matched as
|
|
43
|
+
// the full header so a raw result that merely starts with "«" is not misread.
|
|
44
|
+
const TRUNCATION_MARKER_RE = /^«\d+ earlier lines hidden»\n/;
|
|
45
|
+
|
|
46
|
+
function normalizeEntry(e: AgentListEntry): AgentListEntry {
|
|
47
|
+
return { ...e, use_when: e.use_when ?? e.architect?.use_when ?? e.description };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function outputNames(outputs: AgentListEntry["outputs"]): string[] {
|
|
51
|
+
if (!Array.isArray(outputs)) return [];
|
|
52
|
+
return outputs
|
|
53
|
+
.map((o) => (typeof o === "string" ? o : o?.name))
|
|
54
|
+
.filter((n): n is string => typeof n === "string");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Derive the `op:"list"` catalog entries from the most authoritative
|
|
59
|
+
* non-truncated source. Fallback order (design Decision 2):
|
|
60
|
+
* 1. `toolDetails.agents` structured catalog (never line-truncated),
|
|
61
|
+
* 2. valid-JSON parse of the `result` text,
|
|
62
|
+
* 3. truncation-marker guard → entries empty, truncated:true (never report 0),
|
|
63
|
+
* 4. genuine empty array → 0 agents.
|
|
64
|
+
* `count` is carried through so a details count survives even when entries are
|
|
65
|
+
* not enumerable.
|
|
66
|
+
*/
|
|
67
|
+
function deriveListCatalog(
|
|
68
|
+
result: string | undefined,
|
|
69
|
+
toolDetails: unknown,
|
|
70
|
+
): { entries: AgentListEntry[]; truncated: boolean; count?: number } {
|
|
71
|
+
// 1. toolDetails.agents (duck-typed; pi-flows may not emit it on older builds)
|
|
72
|
+
const td = toolDetails as { agents?: unknown; count?: unknown } | AgentListEntry[] | undefined;
|
|
73
|
+
const detailsAgents = Array.isArray(td) ? td : (td && typeof td === "object" ? td.agents : undefined);
|
|
74
|
+
if (Array.isArray(detailsAgents) && detailsAgents.length > 0) {
|
|
75
|
+
const entries = (detailsAgents as AgentListEntry[]).map(normalizeEntry);
|
|
76
|
+
return { entries, truncated: false, count: entries.length };
|
|
77
|
+
}
|
|
78
|
+
const detailsCount =
|
|
79
|
+
td && typeof td === "object" && !Array.isArray(td) && typeof td.count === "number"
|
|
80
|
+
? td.count
|
|
81
|
+
: undefined;
|
|
82
|
+
|
|
83
|
+
// 3. truncation-marker guard (before parse: the marker is never valid JSON)
|
|
84
|
+
if (typeof result === "string" && TRUNCATION_MARKER_RE.test(result)) {
|
|
85
|
+
return { entries: [], truncated: true, count: detailsCount };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 2. valid-JSON parse of the (untruncated) result text
|
|
89
|
+
let parsed: unknown = null;
|
|
90
|
+
try { if (result) parsed = JSON.parse(result); } catch { parsed = null; }
|
|
91
|
+
const catalog = Array.isArray(parsed) ? (parsed as AgentListEntry[]) : [];
|
|
92
|
+
const entries = catalog
|
|
93
|
+
.filter((a) => typeof a?.name === "string")
|
|
94
|
+
.map(normalizeEntry);
|
|
95
|
+
return { entries, truncated: false, count: entries.length };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function FlowAgentsToolRenderer({
|
|
99
|
+
toolInput,
|
|
100
|
+
status,
|
|
101
|
+
result,
|
|
102
|
+
toolDetails,
|
|
103
|
+
}: {
|
|
104
|
+
toolName: string;
|
|
105
|
+
toolInput: Record<string, unknown>;
|
|
106
|
+
sessionId: string;
|
|
107
|
+
status?: "running" | "complete" | "error";
|
|
108
|
+
result?: string;
|
|
109
|
+
toolDetails?: unknown;
|
|
110
|
+
}) {
|
|
111
|
+
const [showFile, setShowFile] = useState(false);
|
|
112
|
+
const [expanded, setExpanded] = useState<Set<string>>(() => new Set());
|
|
113
|
+
const op = toolInput.op === "write" ? "write" : "list";
|
|
114
|
+
const content = typeof toolInput.content === "string" ? toolInput.content : "";
|
|
115
|
+
|
|
116
|
+
let parsed: unknown = null;
|
|
117
|
+
try { if (result) parsed = JSON.parse(result); } catch { parsed = null; }
|
|
118
|
+
|
|
119
|
+
// ── list ──
|
|
120
|
+
if (op === "list") {
|
|
121
|
+
const { entries, truncated, count } = deriveListCatalog(result, toolDetails);
|
|
122
|
+
const shownCount = entries.length > 0 ? entries.length : (typeof count === "number" ? count : 0);
|
|
123
|
+
const toggle = (name: string) =>
|
|
124
|
+
setExpanded((prev) => {
|
|
125
|
+
const next = new Set(prev);
|
|
126
|
+
if (next.has(name)) next.delete(name); else next.add(name);
|
|
127
|
+
return next;
|
|
128
|
+
});
|
|
129
|
+
return (
|
|
130
|
+
<div className="border border-[var(--border-primary)] rounded-md bg-[var(--bg-secondary)] p-3 text-xs">
|
|
131
|
+
<div className="flex items-center gap-2">
|
|
132
|
+
<span className="text-purple-400">⊙</span>
|
|
133
|
+
<span className="font-semibold">flow_agents</span>
|
|
134
|
+
{truncated && entries.length === 0 ? (
|
|
135
|
+
<span className="text-[var(--text-muted)]">list · output truncated — expand</span>
|
|
136
|
+
) : (
|
|
137
|
+
<span className="text-[var(--text-muted)]">list · {shownCount} agents</span>
|
|
138
|
+
)}
|
|
139
|
+
</div>
|
|
140
|
+
{entries.length > 0 && (
|
|
141
|
+
<div className="mt-2">
|
|
142
|
+
{entries.map((a) => {
|
|
143
|
+
const name = a.name ?? "";
|
|
144
|
+
const isOpen = expanded.has(name);
|
|
145
|
+
const detailRows: Array<[string, string]> = [];
|
|
146
|
+
if (a.tools && a.tools.length > 0) detailRows.push(["tools", a.tools.join(", ")]);
|
|
147
|
+
if (a.inputs && a.inputs.length > 0) detailRows.push(["inputs", a.inputs.join(", ")]);
|
|
148
|
+
const outs = outputNames(a.outputs);
|
|
149
|
+
if (outs.length > 0) detailRows.push(["outputs", outs.join(", ")]);
|
|
150
|
+
if (a.use_when) detailRows.push(["use_when", a.use_when]);
|
|
151
|
+
return (
|
|
152
|
+
<div key={name} className="border-t border-[var(--border-subtle)] first:border-t-0">
|
|
153
|
+
<button
|
|
154
|
+
type="button"
|
|
155
|
+
onClick={() => toggle(name)}
|
|
156
|
+
className="flex items-baseline gap-2 w-full text-left py-1 hover:text-[var(--text-primary)]"
|
|
157
|
+
>
|
|
158
|
+
<span className="text-[var(--text-muted)] w-3 shrink-0">{isOpen ? "▾" : "▸"}</span>
|
|
159
|
+
<span className="font-mono font-semibold text-[var(--text-primary)]">{name}</span>
|
|
160
|
+
{a.description && (
|
|
161
|
+
<span className="text-[var(--text-secondary)] flex-1">{a.description}</span>
|
|
162
|
+
)}
|
|
163
|
+
{a.source_type && (
|
|
164
|
+
<span className="ml-auto shrink-0 text-[10px] text-[var(--text-tertiary)] bg-[var(--bg-surface)] rounded px-1.5 py-0.5">
|
|
165
|
+
{a.source_type}
|
|
166
|
+
</span>
|
|
167
|
+
)}
|
|
168
|
+
</button>
|
|
169
|
+
{isOpen && detailRows.length > 0 && (
|
|
170
|
+
<div className="ml-5 mb-2 p-2 bg-[var(--bg-code)] border border-[var(--border-subtle)] rounded">
|
|
171
|
+
{detailRows.map(([k, v]) => (
|
|
172
|
+
<div key={k} className="flex gap-2">
|
|
173
|
+
<span className="text-[var(--text-tertiary)] w-16 shrink-0">{k}</span>
|
|
174
|
+
<span className="font-mono text-[var(--text-secondary)]">{v}</span>
|
|
175
|
+
</div>
|
|
176
|
+
))}
|
|
177
|
+
</div>
|
|
178
|
+
)}
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
})}
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ── write ──
|
|
189
|
+
const wr = (parsed && typeof parsed === "object" ? parsed : {}) as AgentWriteResult;
|
|
190
|
+
const written = wr.written === true;
|
|
191
|
+
const isError = status === "error" || wr.written === false;
|
|
192
|
+
const diagnostics = (wr.diagnostics ?? []).map(diagText);
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<div className="border border-[var(--border-primary)] rounded-md bg-[var(--bg-secondary)] p-3 text-xs">
|
|
196
|
+
<div className="flex items-center gap-2">
|
|
197
|
+
<span className="text-purple-400">⊙</span>
|
|
198
|
+
<span className="font-semibold">flow_agents</span>
|
|
199
|
+
<span className="text-[var(--text-muted)]">write</span>
|
|
200
|
+
{written && wr.name && <span className="font-mono text-green-400">{wr.name}</span>}
|
|
201
|
+
{written && <span className="text-[var(--text-muted)]">saved</span>}
|
|
202
|
+
{isError && <span className="text-red-400">not written</span>}
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
{isError && (
|
|
206
|
+
<pre className="mt-2 font-mono text-[11px] text-red-400 whitespace-pre-wrap">
|
|
207
|
+
{diagnostics.length > 0 ? diagnostics.join("\n") : (wr.error ?? "Unknown error")}
|
|
208
|
+
</pre>
|
|
209
|
+
)}
|
|
210
|
+
|
|
211
|
+
{content && (
|
|
212
|
+
<div className="mt-2">
|
|
213
|
+
<button
|
|
214
|
+
onClick={() => setShowFile((v) => !v)}
|
|
215
|
+
className="text-[11px] text-[var(--text-tertiary)] hover:text-blue-400 font-mono"
|
|
216
|
+
>
|
|
217
|
+
{showFile ? "▾" : "▸"} View agent file {wr.path ? `· ${wr.path.split("/").pop()}` : ""}
|
|
218
|
+
</button>
|
|
219
|
+
{showFile && (
|
|
220
|
+
<pre className="mt-1 font-mono text-[11px] bg-[var(--bg-surface)] border border-[var(--border-subtle)] rounded p-2 overflow-auto max-h-[260px] whitespace-pre">
|
|
221
|
+
{content}
|
|
222
|
+
</pre>
|
|
223
|
+
)}
|
|
224
|
+
</div>
|
|
225
|
+
)}
|
|
226
|
+
</div>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect } from "react";
|
|
2
|
+
import { Icon } from "@mdi/react";
|
|
3
|
+
import { mdiPencil } from "@mdi/js";
|
|
4
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
5
|
+
import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Intent-capture step for the manage-flows authoring launcher.
|
|
9
|
+
* Mirrors FlowLaunchDialog's two-step pattern: after the user picks "+ New flow"
|
|
10
|
+
* or an existing flow, this dialog asks what the flow should do (new) or what to
|
|
11
|
+
* change (edit) before the skill is launched. The text is forwarded to the
|
|
12
|
+
* `/skill:manage-flows` prompt so the agent starts with stated intent.
|
|
13
|
+
*
|
|
14
|
+
* New mode requires a description (the whole point is to seed intent); edit mode
|
|
15
|
+
* leaves the instruction optional.
|
|
16
|
+
*/
|
|
17
|
+
export function FlowAuthorPromptDialog({
|
|
18
|
+
mode,
|
|
19
|
+
flowName,
|
|
20
|
+
onSubmit,
|
|
21
|
+
onCancel,
|
|
22
|
+
}: {
|
|
23
|
+
mode: "new" | "edit";
|
|
24
|
+
/** Present for edit mode; the flow being changed. */
|
|
25
|
+
flowName?: string;
|
|
26
|
+
onSubmit: (instruction: string) => void;
|
|
27
|
+
onCancel: () => void;
|
|
28
|
+
}) {
|
|
29
|
+
const Dialog = useUiPrimitive(UI_PRIMITIVE_KEYS.dialog);
|
|
30
|
+
const [instruction, setInstruction] = useState("");
|
|
31
|
+
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
inputRef.current?.focus();
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
const isNew = mode === "new";
|
|
38
|
+
const trimmed = instruction.trim();
|
|
39
|
+
const canSubmit = isNew ? trimmed.length > 0 : true;
|
|
40
|
+
|
|
41
|
+
const handleSubmit = (e: React.FormEvent) => {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (!canSubmit) return;
|
|
44
|
+
onSubmit(trimmed);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Dialog
|
|
49
|
+
open
|
|
50
|
+
onClose={onCancel}
|
|
51
|
+
title={isNew ? "New flow" : `Edit flow: ${flowName}`}
|
|
52
|
+
size="md"
|
|
53
|
+
testId="flow-author-prompt-dialog"
|
|
54
|
+
>
|
|
55
|
+
<p className="text-[11px] text-[var(--text-tertiary)]">
|
|
56
|
+
{isNew
|
|
57
|
+
? "Describe what the flow should do. The agent uses this to author it."
|
|
58
|
+
: "Describe what to change. Leave blank to open the flow without a specific instruction."}
|
|
59
|
+
</p>
|
|
60
|
+
<form onSubmit={handleSubmit} className="space-y-3">
|
|
61
|
+
<textarea
|
|
62
|
+
ref={inputRef}
|
|
63
|
+
value={instruction}
|
|
64
|
+
onChange={(e) => setInstruction(e.target.value)}
|
|
65
|
+
rows={4}
|
|
66
|
+
placeholder={
|
|
67
|
+
isNew
|
|
68
|
+
? "e.g. Research an invoice, extract line items, and draft a summary email…"
|
|
69
|
+
: "e.g. Add a review step after extraction…"
|
|
70
|
+
}
|
|
71
|
+
className="w-full px-3 py-2 text-sm bg-[var(--bg-tertiary)] border border-[var(--border-subtle)] rounded-lg text-[var(--text-primary)] placeholder:text-[var(--text-muted)] focus:outline-none focus:border-purple-500/50 resize-y"
|
|
72
|
+
/>
|
|
73
|
+
<Dialog.Footer>
|
|
74
|
+
<Dialog.Cancel onClick={onCancel} />
|
|
75
|
+
<button
|
|
76
|
+
type="submit"
|
|
77
|
+
disabled={!canSubmit}
|
|
78
|
+
className={`text-xs px-3 py-1.5 rounded transition-colors ${
|
|
79
|
+
canSubmit
|
|
80
|
+
? "bg-[var(--accent-primary)] text-white hover:opacity-90"
|
|
81
|
+
: "bg-[var(--bg-tertiary)] text-[var(--text-muted)] cursor-not-allowed"
|
|
82
|
+
}`}
|
|
83
|
+
data-testid="flow-author-submit"
|
|
84
|
+
>
|
|
85
|
+
<Icon path={mdiPencil} size={0.45} className="inline mr-0.5" />
|
|
86
|
+
{isNew ? "Create" : "Edit"}
|
|
87
|
+
</button>
|
|
88
|
+
</Dialog.Footer>
|
|
89
|
+
</form>
|
|
90
|
+
</Dialog>
|
|
91
|
+
);
|
|
92
|
+
}
|