@heigin/ui 0.1.1 → 0.2.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/CHANGELOG.md +12 -1
- package/dist/components/crm/agent-decision-tree.d.ts +82 -0
- package/dist/components/crm/agent-decision-tree.js +580 -0
- package/dist/components/crm/agent-decision-tree.module.js +113 -0
- package/dist/components/crm/agent-task-trail.d.ts +56 -0
- package/dist/components/crm/agent-task-trail.js +419 -0
- package/dist/components/crm/agent-thinking.d.ts +36 -0
- package/dist/components/crm/agent-thinking.js +443 -0
- package/dist/components/crm/agent-thinking.module.js +33 -0
- package/dist/components/crm/agent.module.js +81 -0
- package/dist/components/crm/crm.module.js +44 -4
- package/dist/components/crm/record-header.d.ts +2 -2
- package/dist/components/crm/workspace-switcher.d.ts +49 -0
- package/dist/components/crm/workspace-switcher.js +205 -0
- package/dist/components/ui/avatar.d.ts +9 -1
- package/dist/components/ui/avatar.js +61 -4
- package/dist/components/ui/avatar.module.js +4 -2
- package/dist/components/ui/breadcrumb.d.ts +10 -0
- package/dist/components/ui/breadcrumb.js +48 -0
- package/dist/components/ui/breadcrumb.module.js +19 -0
- package/dist/components/ui/heigin-mark.d.ts +11 -0
- package/dist/components/ui/heigin-mark.js +41 -0
- package/dist/components/ui/loader.d.ts +21 -0
- package/dist/components/ui/loader.js +45 -0
- package/dist/components/ui/table.d.ts +9 -1
- package/dist/components/ui/table.js +136 -89
- package/dist/components/ui/table.module.js +13 -1
- package/dist/components/ui/thinking-orb.d.ts +27 -0
- package/dist/components/ui/thinking-orb.js +27 -0
- package/dist/components/ui/type-motion.d.ts +31 -0
- package/dist/components/ui/type-motion.js +394 -0
- package/dist/components/ui/type-motion.module.js +31 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -1
- package/dist/styles.css +1732 -7
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@heigin/ui` are recorded here. This project follows [Semantic Versioning](https://semver.org).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 0.2.0 — 2026-11-18
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `AgentTaskTrail`: a live timeline of an agent working through a task, with service icons, ticking timers, sub-steps on a branching rail and an approval gate (`onApprove` / `onDecline`).
|
|
10
|
+
- `AgentDecisionTree`: a queue of decisions an agent needs from a person, drawn as a tree with follow-up options, consequences, the agent's pick, an agent's note, "Other…" free text and the agent's reply. Number keys work only while focus is inside it. Stacks below a 760px container.
|
|
11
|
+
- `AgentThinking`: a thinking timer, the steps as they happen and a dithered dot visual (raymarched, Bayer-dithered canvas) that reshapes per step, then the answer. The visual pauses offscreen and shows a still frame under reduced motion.
|
|
12
|
+
- `TypeMotion`: a headline whose letters turn into artwork under the pointer, with eight effects (lens, pop, shuffle, word, bubble, swell, sticker, burst). Ships HeiGin orbs, symbols and the mark as default artwork; pass `artwork` for your own images or elements.
|
|
13
|
+
- `Loader`: one loading indicator with `variant="orb"` (the thinking orb, default) or `"spinner"`. The three agent components take the same choice through their `loader` prop.
|
|
14
|
+
- `HeiGinMark`: the HeiGin mark, on its tile or bare in `currentColor`. The agent components use it as the default agent icon.
|
|
15
|
+
- `ThinkingOrb`: a dotted orb for agent activity with nine states at 64, 32 and 20px. Wraps the MIT-licensed [`thinking-orbs`](https://github.com/Jakubantalik/thinking-orbs) package by Jakub Antalik, which is now a dependency.
|
|
16
|
+
- `NativeSelect` is exported from the package root. It was documented but missing from the entry point.
|
|
6
17
|
|
|
7
18
|
## 0.1.1 — 2026-10-11
|
|
8
19
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type LoaderVariant } from "../ui/loader.js";
|
|
3
|
+
export interface DecisionOption {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
icon?: React.ReactNode;
|
|
7
|
+
/** Quiet second line: cost, timing, scope. */
|
|
8
|
+
detail?: React.ReactNode;
|
|
9
|
+
/** A consequence worth flagging; shown in the warning tone instead of `detail`. */
|
|
10
|
+
warning?: React.ReactNode;
|
|
11
|
+
/** Small marks for the services this option touches. */
|
|
12
|
+
apps?: React.ReactNode[];
|
|
13
|
+
/** Context the agent wants you to see before choosing (a policy, a limit). */
|
|
14
|
+
note?: {
|
|
15
|
+
text: React.ReactNode;
|
|
16
|
+
source?: React.ReactNode;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface DecisionBranch {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
icon?: React.ReactNode;
|
|
23
|
+
/** Follow-up question; pair it with `options`. */
|
|
24
|
+
question?: string;
|
|
25
|
+
options?: DecisionOption[];
|
|
26
|
+
/** The option the agent would pick. */
|
|
27
|
+
recommendedOption?: string;
|
|
28
|
+
/** For a branch with no follow-up: what happens if you pick it. */
|
|
29
|
+
outcome?: React.ReactNode;
|
|
30
|
+
apps?: React.ReactNode[];
|
|
31
|
+
}
|
|
32
|
+
export interface AgentDecision {
|
|
33
|
+
id: string;
|
|
34
|
+
agent: {
|
|
35
|
+
name: string;
|
|
36
|
+
model?: string;
|
|
37
|
+
icon?: React.ReactNode;
|
|
38
|
+
};
|
|
39
|
+
risk?: "high" | "medium" | "low";
|
|
40
|
+
question: string;
|
|
41
|
+
context?: React.ReactNode;
|
|
42
|
+
branches: DecisionBranch[];
|
|
43
|
+
/** The branch the agent would pick. */
|
|
44
|
+
recommended?: string;
|
|
45
|
+
/** Offer an "Other…" branch with a free-text instruction. Default true. */
|
|
46
|
+
allowOther?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export type DecisionChoice = {
|
|
49
|
+
kind: "option";
|
|
50
|
+
branch: DecisionBranch;
|
|
51
|
+
option: DecisionOption;
|
|
52
|
+
} | {
|
|
53
|
+
kind: "outcome";
|
|
54
|
+
branch: DecisionBranch;
|
|
55
|
+
} | {
|
|
56
|
+
kind: "other";
|
|
57
|
+
text: string;
|
|
58
|
+
};
|
|
59
|
+
export interface AgentDecisionTreeProps {
|
|
60
|
+
/** The queue, oldest first. Decided items move on by themselves. */
|
|
61
|
+
decisions: AgentDecision[];
|
|
62
|
+
/**
|
|
63
|
+
* Called when a person commits a choice. Return a Promise to show the loader until it settles.
|
|
64
|
+
* For an "Other…" instruction, resolve with the agent's reply to show it. A rejection leaves the
|
|
65
|
+
* decision open and says it could not be sent.
|
|
66
|
+
*/
|
|
67
|
+
onDecide: (decision: AgentDecision, choice: DecisionChoice) => void | string | Promise<void | string>;
|
|
68
|
+
/** Indicator while a decision is being sent: the thinking orb (default) or a spinner. */
|
|
69
|
+
loader?: LoaderVariant;
|
|
70
|
+
title?: string;
|
|
71
|
+
/** Number keys pick a branch or option while focus is inside the tree. Default true. */
|
|
72
|
+
hotkeys?: boolean;
|
|
73
|
+
/** Shown once every decision is made. */
|
|
74
|
+
empty?: React.ReactNode;
|
|
75
|
+
className?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A queue of decisions an agent needs from a person, drawn as a tree: the question, the branches it
|
|
79
|
+
* considered, follow-up options with their consequences, and the agent's own pick. One click (or a
|
|
80
|
+
* number key) commits; the next decision slides in.
|
|
81
|
+
*/
|
|
82
|
+
export declare function AgentDecisionTree({ decisions, onDecide, loader, title, hotkeys, empty, className, }: AgentDecisionTreeProps): React.JSX.Element;
|
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
import { cn } from "../../lib/cn.js";
|
|
4
|
+
import { Button } from "../ui/button.js";
|
|
5
|
+
import { Kbd } from "../ui/kbd.js";
|
|
6
|
+
import { Loader } from "../ui/loader.js";
|
|
7
|
+
import { HeiGinMark } from "../ui/heigin-mark.js";
|
|
8
|
+
import { VisuallyHidden } from "../ui/visually-hidden.js";
|
|
9
|
+
import agent_decision_tree_module_default from "./agent-decision-tree.module.js";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { ArrowRight, ArrowUpRight, Check, GitFork, TriangleAlert } from "lucide-react";
|
|
13
|
+
//#region src/components/crm/agent-decision-tree.tsx
|
|
14
|
+
var RISK_LABEL = {
|
|
15
|
+
high: "High risk",
|
|
16
|
+
medium: "Medium risk",
|
|
17
|
+
low: "Low risk"
|
|
18
|
+
};
|
|
19
|
+
function Apps({ items }) {
|
|
20
|
+
if (!items?.length) return null;
|
|
21
|
+
return /* @__PURE__ */ jsx("span", {
|
|
22
|
+
className: agent_decision_tree_module_default.dtApps,
|
|
23
|
+
"aria-hidden": "true",
|
|
24
|
+
children: items.map((a, i) => /* @__PURE__ */ jsx("span", { children: a }, i))
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A queue of decisions an agent needs from a person, drawn as a tree: the question, the branches it
|
|
29
|
+
* considered, follow-up options with their consequences, and the agent's own pick. One click (or a
|
|
30
|
+
* number key) commits; the next decision slides in.
|
|
31
|
+
*/
|
|
32
|
+
function AgentDecisionTree({ decisions, onDecide, loader = "orb", title = "Decisions", hotkeys = true, empty, className }) {
|
|
33
|
+
const headingId = React.useId();
|
|
34
|
+
const uid = React.useId();
|
|
35
|
+
const [decided, setDecided] = React.useState(() => /* @__PURE__ */ new Set());
|
|
36
|
+
const [cursor, setCursor] = React.useState(0);
|
|
37
|
+
const [chosen, setChosen] = React.useState(null);
|
|
38
|
+
const [hover, setHover] = React.useState(null);
|
|
39
|
+
const [phase, setPhase] = React.useState("choosing");
|
|
40
|
+
const [picked, setPicked] = React.useState(null);
|
|
41
|
+
const [reply, setReply] = React.useState(null);
|
|
42
|
+
const [otherText, setOtherText] = React.useState("");
|
|
43
|
+
const [failed, setFailed] = React.useState(false);
|
|
44
|
+
const stageRef = React.useRef(null);
|
|
45
|
+
const wiresRef = React.useRef(null);
|
|
46
|
+
const otherRef = React.useRef(null);
|
|
47
|
+
const open = decisions.filter((d) => !decided.has(d.id));
|
|
48
|
+
const current = open.length ? open[Math.min(cursor, open.length - 1)] : void 0;
|
|
49
|
+
const branches = current ? [...current.branches, ...current.allowOther === false ? [] : [{
|
|
50
|
+
id: "__other",
|
|
51
|
+
label: "Other…"
|
|
52
|
+
}]] : [];
|
|
53
|
+
const chosenBranch = branches.find((b) => b.id === chosen);
|
|
54
|
+
const focusBranch = chosen ?? hover ?? current?.recommended ?? null;
|
|
55
|
+
const reset = React.useCallback(() => {
|
|
56
|
+
setChosen(null);
|
|
57
|
+
setHover(null);
|
|
58
|
+
setPhase("choosing");
|
|
59
|
+
setPicked(null);
|
|
60
|
+
setReply(null);
|
|
61
|
+
setOtherText("");
|
|
62
|
+
setFailed(false);
|
|
63
|
+
}, []);
|
|
64
|
+
React.useEffect(() => reset(), [current?.id, reset]);
|
|
65
|
+
const commit = async (choice, pickedId) => {
|
|
66
|
+
if (!current || phase !== "choosing") return;
|
|
67
|
+
setPicked(pickedId);
|
|
68
|
+
setPhase("sending");
|
|
69
|
+
setFailed(false);
|
|
70
|
+
let result;
|
|
71
|
+
try {
|
|
72
|
+
result = await onDecide(current, choice);
|
|
73
|
+
} catch {
|
|
74
|
+
setPicked(null);
|
|
75
|
+
setPhase("choosing");
|
|
76
|
+
setFailed(true);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeof result === "string") setReply(result);
|
|
80
|
+
setPhase("sent");
|
|
81
|
+
window.setTimeout(() => {
|
|
82
|
+
setPhase("leaving");
|
|
83
|
+
window.setTimeout(() => setDecided((d) => new Set(d).add(current.id)), 320);
|
|
84
|
+
}, typeof result === "string" ? 2200 : 1100);
|
|
85
|
+
};
|
|
86
|
+
const choose = (branch) => {
|
|
87
|
+
if (phase !== "choosing") return;
|
|
88
|
+
setChosen(branch.id);
|
|
89
|
+
setHover(null);
|
|
90
|
+
if (branch.id === "__other") window.setTimeout(() => otherRef.current?.focus(), 30);
|
|
91
|
+
};
|
|
92
|
+
const skip = () => {
|
|
93
|
+
if (open.length < 2 || phase !== "choosing") return;
|
|
94
|
+
setCursor((c) => (Math.min(c, open.length - 1) + 1) % open.length);
|
|
95
|
+
};
|
|
96
|
+
const onKeyDown = (e) => {
|
|
97
|
+
if (!hotkeys || !current || e.metaKey || e.ctrlKey || e.altKey) return;
|
|
98
|
+
if (e.target.tagName === "INPUT") {
|
|
99
|
+
if (e.key === "Escape") reset();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const n = Number.parseInt(e.key, 10);
|
|
103
|
+
if (!Number.isNaN(n) && n > 0) {
|
|
104
|
+
if (!chosenBranch) {
|
|
105
|
+
const b = branches[n - 1];
|
|
106
|
+
if (b) {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
choose(b);
|
|
109
|
+
}
|
|
110
|
+
} else if (chosenBranch.options) {
|
|
111
|
+
const o = chosenBranch.options[n - 1];
|
|
112
|
+
if (o) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
commit({
|
|
115
|
+
kind: "option",
|
|
116
|
+
branch: chosenBranch,
|
|
117
|
+
option: o
|
|
118
|
+
}, o.id);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} else if (e.key === "Escape" && chosen && phase === "choosing") {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
reset();
|
|
124
|
+
} else if (e.key === "ArrowRight" && !chosen) {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
skip();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const draw = React.useCallback(() => {
|
|
130
|
+
const stage = stageRef.current;
|
|
131
|
+
const svg = wiresRef.current;
|
|
132
|
+
if (!stage || !svg) return;
|
|
133
|
+
if (getComputedStyle(svg).display === "none") return;
|
|
134
|
+
const sb = stage.getBoundingClientRect();
|
|
135
|
+
const rel = (el) => {
|
|
136
|
+
const r = el.getBoundingClientRect();
|
|
137
|
+
return {
|
|
138
|
+
l: r.left - sb.left,
|
|
139
|
+
r: r.right - sb.left,
|
|
140
|
+
t: r.top - sb.top,
|
|
141
|
+
b: r.bottom - sb.top,
|
|
142
|
+
cy: r.top - sb.top + r.height / 2,
|
|
143
|
+
h: r.height
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
const root = stage.querySelector("[data-dt-root]");
|
|
147
|
+
if (!root) return;
|
|
148
|
+
const rr = rel(root);
|
|
149
|
+
const R = 8;
|
|
150
|
+
const elbow = (x1, y1, xm, x2, y2) => {
|
|
151
|
+
if (Math.abs(y2 - y1) < 1) return `M${x1} ${y1} H${x2}`;
|
|
152
|
+
const s = y2 > y1 ? 1 : -1;
|
|
153
|
+
const r = Math.min(R, Math.abs(y2 - y1) / 2, Math.abs(xm - x1), Math.abs(x2 - xm));
|
|
154
|
+
return `M${x1} ${y1} H${xm - r} Q${xm} ${y1} ${xm} ${y1 + s * r} V${y2 - s * r} Q${xm} ${y2} ${xm + r} ${y2} H${x2}`;
|
|
155
|
+
};
|
|
156
|
+
let out = "";
|
|
157
|
+
stage.querySelectorAll("[data-dt-lane]").forEach((lane) => {
|
|
158
|
+
if (lane.getBoundingClientRect().height < 4) return;
|
|
159
|
+
const hot = lane.dataset.dtLane === lane.closest("[data-focus]")?.getAttribute("data-focus");
|
|
160
|
+
const dim = lane.dataset.dim === "true";
|
|
161
|
+
const cls = cn(hot ? agent_decision_tree_module_default.dtWireHot : agent_decision_tree_module_default.dtWire, dim && agent_decision_tree_module_default.dtWireDim);
|
|
162
|
+
const br = lane.querySelector("[data-dt-branch]");
|
|
163
|
+
if (!br) return;
|
|
164
|
+
const b = rel(br);
|
|
165
|
+
out += `<path class="${cls}" d="${elbow(rr.r, rr.cy, rr.r + 22, b.l, b.cy)}"/>`;
|
|
166
|
+
const ask = lane.querySelector("[data-dt-ask]");
|
|
167
|
+
if (ask) {
|
|
168
|
+
const a = rel(ask);
|
|
169
|
+
out += `<path class="${cls}" d="${elbow(b.r, b.cy, b.r + 18, a.l, a.cy)}"/>`;
|
|
170
|
+
const x = a.l + 13;
|
|
171
|
+
lane.querySelectorAll("[data-dt-opt], [data-dt-pill]").forEach((o) => {
|
|
172
|
+
const r = rel(o);
|
|
173
|
+
const y = r.t + Math.min(19, r.h / 2);
|
|
174
|
+
out += `<path class="${o.hasAttribute("data-dt-pill") ? agent_decision_tree_module_default.dtWireHot : cls}" d="M${x} ${a.b} V${y - R} Q${x} ${y} ${x + R} ${y} H${r.l}"/>`;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const oc = lane.querySelector("[data-dt-outcome]");
|
|
178
|
+
if (oc) out += `<path class="${cls}" d="M${b.r} ${b.cy} H${rel(oc).l}"/>`;
|
|
179
|
+
const pill = !ask ? lane.querySelector("[data-dt-pill]") : null;
|
|
180
|
+
if (pill) {
|
|
181
|
+
const p = rel(pill);
|
|
182
|
+
out += `<path class="${agent_decision_tree_module_default.dtWireHot}" d="${elbow(b.r, b.cy, b.r + 18, p.l, p.cy)}"/>`;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
svg.innerHTML = out;
|
|
186
|
+
}, []);
|
|
187
|
+
React.useLayoutEffect(() => {
|
|
188
|
+
let raf = 0;
|
|
189
|
+
const until = performance.now() + 700;
|
|
190
|
+
const loop = () => {
|
|
191
|
+
draw();
|
|
192
|
+
if (performance.now() < until) raf = requestAnimationFrame(loop);
|
|
193
|
+
};
|
|
194
|
+
loop();
|
|
195
|
+
return () => cancelAnimationFrame(raf);
|
|
196
|
+
}, [
|
|
197
|
+
draw,
|
|
198
|
+
current?.id,
|
|
199
|
+
chosen,
|
|
200
|
+
hover,
|
|
201
|
+
phase,
|
|
202
|
+
reply
|
|
203
|
+
]);
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
const stage = stageRef.current;
|
|
206
|
+
if (!stage || typeof ResizeObserver === "undefined") return;
|
|
207
|
+
const ro = new ResizeObserver(() => draw());
|
|
208
|
+
ro.observe(stage);
|
|
209
|
+
return () => ro.disconnect();
|
|
210
|
+
}, [draw, current?.id]);
|
|
211
|
+
const pill = phase === "sending" || phase === "sent" || phase === "leaving" ? reply ? /* @__PURE__ */ jsxs("div", {
|
|
212
|
+
className: agent_decision_tree_module_default.dtReply,
|
|
213
|
+
"data-dt-pill": true,
|
|
214
|
+
role: "status",
|
|
215
|
+
children: [/* @__PURE__ */ jsxs("b", { children: [
|
|
216
|
+
/* @__PURE__ */ jsx(ArrowUpRight, {
|
|
217
|
+
"aria-hidden": "true",
|
|
218
|
+
strokeWidth: 1.8
|
|
219
|
+
}),
|
|
220
|
+
"Sent to the ",
|
|
221
|
+
current?.agent.name.toLowerCase()
|
|
222
|
+
] }), /* @__PURE__ */ jsx("p", { children: reply })]
|
|
223
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
224
|
+
className: agent_decision_tree_module_default.dtPill,
|
|
225
|
+
"data-dt-pill": true,
|
|
226
|
+
role: "status",
|
|
227
|
+
children: [
|
|
228
|
+
phase === "sending" ? /* @__PURE__ */ jsx(Loader, {
|
|
229
|
+
variant: loader,
|
|
230
|
+
size: "sm",
|
|
231
|
+
label: null
|
|
232
|
+
}) : /* @__PURE__ */ jsx(Check, {
|
|
233
|
+
"aria-hidden": "true",
|
|
234
|
+
strokeWidth: 2
|
|
235
|
+
}),
|
|
236
|
+
/* @__PURE__ */ jsx("b", { children: phase === "sending" ? "Sending" : "Approved" }),
|
|
237
|
+
/* @__PURE__ */ jsxs("span", { children: ["· ", phase === "sending" ? "telling the agent" : "running"] })
|
|
238
|
+
]
|
|
239
|
+
}) : null;
|
|
240
|
+
const waiting = open.length;
|
|
241
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
242
|
+
className: cn(agent_decision_tree_module_default.dt, className),
|
|
243
|
+
"aria-labelledby": headingId,
|
|
244
|
+
onKeyDown,
|
|
245
|
+
children: [
|
|
246
|
+
/* @__PURE__ */ jsxs("header", {
|
|
247
|
+
className: agent_decision_tree_module_default.dtTop,
|
|
248
|
+
children: [
|
|
249
|
+
/* @__PURE__ */ jsx(GitFork, {
|
|
250
|
+
className: agent_decision_tree_module_default.dtLogo,
|
|
251
|
+
"aria-hidden": "true",
|
|
252
|
+
strokeWidth: 1.8
|
|
253
|
+
}),
|
|
254
|
+
/* @__PURE__ */ jsx("h3", {
|
|
255
|
+
id: headingId,
|
|
256
|
+
className: agent_decision_tree_module_default.dtTitle,
|
|
257
|
+
children: title
|
|
258
|
+
}),
|
|
259
|
+
/* @__PURE__ */ jsx("span", {
|
|
260
|
+
className: agent_decision_tree_module_default.dtWaiting,
|
|
261
|
+
children: waiting ? `${waiting} waiting for you` : `${decisions.length} of ${decisions.length} decided`
|
|
262
|
+
}),
|
|
263
|
+
waiting > 0 && /* @__PURE__ */ jsxs("span", {
|
|
264
|
+
className: agent_decision_tree_module_default.dtPager,
|
|
265
|
+
children: [
|
|
266
|
+
/* @__PURE__ */ jsx("span", {
|
|
267
|
+
className: agent_decision_tree_module_default.dtDots,
|
|
268
|
+
"aria-hidden": "true",
|
|
269
|
+
children: open.map((d) => /* @__PURE__ */ jsx("i", { "data-on": d.id === current?.id }, d.id))
|
|
270
|
+
}),
|
|
271
|
+
Math.min(cursor, open.length - 1) + 1,
|
|
272
|
+
" of ",
|
|
273
|
+
open.length
|
|
274
|
+
]
|
|
275
|
+
})
|
|
276
|
+
]
|
|
277
|
+
}),
|
|
278
|
+
!current ? /* @__PURE__ */ jsx("div", {
|
|
279
|
+
className: agent_decision_tree_module_default.dtEmpty,
|
|
280
|
+
role: "status",
|
|
281
|
+
children: empty ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
282
|
+
/* @__PURE__ */ jsx("span", {
|
|
283
|
+
className: agent_decision_tree_module_default.dtEmptyIcon,
|
|
284
|
+
"aria-hidden": "true",
|
|
285
|
+
children: /* @__PURE__ */ jsx(Check, { strokeWidth: 2 })
|
|
286
|
+
}),
|
|
287
|
+
/* @__PURE__ */ jsx("b", { children: "All decided" }),
|
|
288
|
+
/* @__PURE__ */ jsx("p", { children: "New decisions from your agents show up here." })
|
|
289
|
+
] })
|
|
290
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
291
|
+
className: agent_decision_tree_module_default.dtScroll,
|
|
292
|
+
children: /* @__PURE__ */ jsxs("article", {
|
|
293
|
+
ref: stageRef,
|
|
294
|
+
className: agent_decision_tree_module_default.dtStage,
|
|
295
|
+
"data-phase": phase,
|
|
296
|
+
"data-focus": focusBranch ?? void 0,
|
|
297
|
+
"aria-labelledby": `${uid}-q`,
|
|
298
|
+
children: [
|
|
299
|
+
/* @__PURE__ */ jsx("svg", {
|
|
300
|
+
ref: wiresRef,
|
|
301
|
+
className: agent_decision_tree_module_default.dtWires,
|
|
302
|
+
"aria-hidden": "true"
|
|
303
|
+
}),
|
|
304
|
+
/* @__PURE__ */ jsxs("div", {
|
|
305
|
+
className: agent_decision_tree_module_default.dtRoot,
|
|
306
|
+
children: [current.risk && /* @__PURE__ */ jsx("span", {
|
|
307
|
+
className: agent_decision_tree_module_default.dtRisk,
|
|
308
|
+
"data-risk": current.risk,
|
|
309
|
+
children: RISK_LABEL[current.risk]
|
|
310
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
311
|
+
className: agent_decision_tree_module_default.dtRootCard,
|
|
312
|
+
"data-dt-root": true,
|
|
313
|
+
children: [
|
|
314
|
+
/* @__PURE__ */ jsxs("div", {
|
|
315
|
+
className: agent_decision_tree_module_default.dtAgent,
|
|
316
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
317
|
+
className: agent_decision_tree_module_default.dtMark,
|
|
318
|
+
children: current.agent.icon ?? /* @__PURE__ */ jsx(HeiGinMark, { size: 16 })
|
|
319
|
+
}), /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("b", { children: current.agent.name }), current.agent.model && /* @__PURE__ */ jsx("small", { children: current.agent.model })] })]
|
|
320
|
+
}),
|
|
321
|
+
/* @__PURE__ */ jsx("p", {
|
|
322
|
+
id: `${uid}-q`,
|
|
323
|
+
className: agent_decision_tree_module_default.dtQuestion,
|
|
324
|
+
children: current.question
|
|
325
|
+
}),
|
|
326
|
+
current.context && /* @__PURE__ */ jsx("p", {
|
|
327
|
+
className: agent_decision_tree_module_default.dtContext,
|
|
328
|
+
children: current.context
|
|
329
|
+
})
|
|
330
|
+
]
|
|
331
|
+
})]
|
|
332
|
+
}),
|
|
333
|
+
/* @__PURE__ */ jsx("ol", {
|
|
334
|
+
className: agent_decision_tree_module_default.dtLanes,
|
|
335
|
+
"aria-label": "Options",
|
|
336
|
+
children: branches.map((b, i) => {
|
|
337
|
+
const isChosen = chosen === b.id;
|
|
338
|
+
const gone = chosen !== null && !isChosen;
|
|
339
|
+
const dim = chosen === null && hover !== null && hover !== b.id;
|
|
340
|
+
const isOther = b.id === "__other";
|
|
341
|
+
const recommended = current.recommended === b.id;
|
|
342
|
+
return /* @__PURE__ */ jsx("li", {
|
|
343
|
+
className: agent_decision_tree_module_default.dtLane,
|
|
344
|
+
"data-dt-lane": b.id,
|
|
345
|
+
"data-gone": gone,
|
|
346
|
+
"data-dim": dim,
|
|
347
|
+
"aria-hidden": gone || void 0,
|
|
348
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
349
|
+
className: agent_decision_tree_module_default.dtLaneInner,
|
|
350
|
+
children: [
|
|
351
|
+
isOther && isChosen ? /* @__PURE__ */ jsxs("form", {
|
|
352
|
+
className: agent_decision_tree_module_default.dtBranch,
|
|
353
|
+
"data-dt-branch": true,
|
|
354
|
+
"data-hot": "true",
|
|
355
|
+
onSubmit: (e) => {
|
|
356
|
+
e.preventDefault();
|
|
357
|
+
const text = otherText.trim();
|
|
358
|
+
if (text) commit({
|
|
359
|
+
kind: "other",
|
|
360
|
+
text
|
|
361
|
+
}, "__other");
|
|
362
|
+
},
|
|
363
|
+
children: [
|
|
364
|
+
/* @__PURE__ */ jsxs("label", {
|
|
365
|
+
htmlFor: `${uid}-other`,
|
|
366
|
+
className: agent_decision_tree_module_default.srOnly,
|
|
367
|
+
children: [
|
|
368
|
+
"Tell the ",
|
|
369
|
+
current.agent.name.toLowerCase(),
|
|
370
|
+
" what to do instead"
|
|
371
|
+
]
|
|
372
|
+
}),
|
|
373
|
+
/* @__PURE__ */ jsx("input", {
|
|
374
|
+
ref: otherRef,
|
|
375
|
+
id: `${uid}-other`,
|
|
376
|
+
className: agent_decision_tree_module_default.dtOtherInput,
|
|
377
|
+
value: otherText,
|
|
378
|
+
disabled: phase !== "choosing",
|
|
379
|
+
placeholder: "Tell the agent what to do instead…",
|
|
380
|
+
onChange: (e) => setOtherText(e.target.value)
|
|
381
|
+
}),
|
|
382
|
+
/* @__PURE__ */ jsx("button", {
|
|
383
|
+
type: "submit",
|
|
384
|
+
className: agent_decision_tree_module_default.dtSend,
|
|
385
|
+
disabled: !otherText.trim() || phase !== "choosing",
|
|
386
|
+
"aria-label": "Send instruction",
|
|
387
|
+
children: /* @__PURE__ */ jsx(ArrowRight, {
|
|
388
|
+
"aria-hidden": "true",
|
|
389
|
+
strokeWidth: 1.8
|
|
390
|
+
})
|
|
391
|
+
})
|
|
392
|
+
]
|
|
393
|
+
}) : /* @__PURE__ */ jsxs("button", {
|
|
394
|
+
type: "button",
|
|
395
|
+
className: cn(agent_decision_tree_module_default.dtBranch, isOther && agent_decision_tree_module_default.dtBranchOther),
|
|
396
|
+
"data-dt-branch": true,
|
|
397
|
+
"data-hot": focusBranch === b.id,
|
|
398
|
+
"aria-expanded": b.options || isOther ? isChosen : void 0,
|
|
399
|
+
"aria-pressed": !b.options && !isOther ? isChosen : void 0,
|
|
400
|
+
tabIndex: gone ? -1 : void 0,
|
|
401
|
+
onMouseEnter: () => chosen === null && setHover(b.id),
|
|
402
|
+
onMouseLeave: () => chosen === null && setHover(null),
|
|
403
|
+
onFocus: () => chosen === null && setHover(b.id),
|
|
404
|
+
onBlur: () => chosen === null && setHover(null),
|
|
405
|
+
onClick: () => isChosen ? void 0 : choose(b),
|
|
406
|
+
children: [
|
|
407
|
+
/* @__PURE__ */ jsx("span", {
|
|
408
|
+
className: agent_decision_tree_module_default.dtNum,
|
|
409
|
+
"aria-hidden": "true",
|
|
410
|
+
children: i + 1
|
|
411
|
+
}),
|
|
412
|
+
b.icon && /* @__PURE__ */ jsx("span", {
|
|
413
|
+
className: agent_decision_tree_module_default.dtIco,
|
|
414
|
+
"aria-hidden": "true",
|
|
415
|
+
children: b.icon
|
|
416
|
+
}),
|
|
417
|
+
/* @__PURE__ */ jsx("span", {
|
|
418
|
+
className: agent_decision_tree_module_default.dtLbl,
|
|
419
|
+
children: b.label
|
|
420
|
+
}),
|
|
421
|
+
recommended && /* @__PURE__ */ jsx("span", {
|
|
422
|
+
className: agent_decision_tree_module_default.dtPick,
|
|
423
|
+
children: "Agent’s pick"
|
|
424
|
+
})
|
|
425
|
+
]
|
|
426
|
+
}),
|
|
427
|
+
b.question && b.options && /* @__PURE__ */ jsxs("div", {
|
|
428
|
+
className: agent_decision_tree_module_default.dtSub,
|
|
429
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
430
|
+
className: agent_decision_tree_module_default.dtAsk,
|
|
431
|
+
"data-dt-ask": true,
|
|
432
|
+
children: b.question
|
|
433
|
+
}), /* @__PURE__ */ jsx("ul", {
|
|
434
|
+
className: agent_decision_tree_module_default.dtOpts,
|
|
435
|
+
children: b.options.map((o, k) => {
|
|
436
|
+
const noteId = o.note ? `${uid}-${b.id}-${o.id}-note` : void 0;
|
|
437
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsxs("li", {
|
|
438
|
+
className: agent_decision_tree_module_default.dtOptItem,
|
|
439
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
440
|
+
type: "button",
|
|
441
|
+
className: agent_decision_tree_module_default.dtOpt,
|
|
442
|
+
"data-dt-opt": true,
|
|
443
|
+
"data-faded": picked !== null && picked !== o.id,
|
|
444
|
+
"aria-describedby": noteId,
|
|
445
|
+
tabIndex: isChosen ? void 0 : -1,
|
|
446
|
+
disabled: phase !== "choosing",
|
|
447
|
+
onClick: () => {
|
|
448
|
+
if (!isChosen) choose(b);
|
|
449
|
+
commit({
|
|
450
|
+
kind: "option",
|
|
451
|
+
branch: b,
|
|
452
|
+
option: o
|
|
453
|
+
}, o.id);
|
|
454
|
+
},
|
|
455
|
+
children: [
|
|
456
|
+
/* @__PURE__ */ jsx("span", {
|
|
457
|
+
className: agent_decision_tree_module_default.dtNum,
|
|
458
|
+
"aria-hidden": "true",
|
|
459
|
+
"data-show": isChosen,
|
|
460
|
+
children: k + 1
|
|
461
|
+
}),
|
|
462
|
+
/* @__PURE__ */ jsxs("span", {
|
|
463
|
+
className: agent_decision_tree_module_default.dtOptTitle,
|
|
464
|
+
children: [
|
|
465
|
+
o.icon && /* @__PURE__ */ jsx("span", {
|
|
466
|
+
className: agent_decision_tree_module_default.dtIco,
|
|
467
|
+
"aria-hidden": "true",
|
|
468
|
+
children: o.icon
|
|
469
|
+
}),
|
|
470
|
+
o.label,
|
|
471
|
+
b.recommendedOption === o.id && /* @__PURE__ */ jsx("em", { children: "Agent’s pick" })
|
|
472
|
+
]
|
|
473
|
+
}),
|
|
474
|
+
/* @__PURE__ */ jsxs("span", {
|
|
475
|
+
className: agent_decision_tree_module_default.dtOptMeta,
|
|
476
|
+
children: [o.warning ? /* @__PURE__ */ jsx("span", {
|
|
477
|
+
className: agent_decision_tree_module_default.dtWarn,
|
|
478
|
+
children: o.warning
|
|
479
|
+
}) : o.detail, /* @__PURE__ */ jsx(Apps, { items: o.apps })]
|
|
480
|
+
})
|
|
481
|
+
]
|
|
482
|
+
}), o.note && /* @__PURE__ */ jsxs("span", {
|
|
483
|
+
className: agent_decision_tree_module_default.dtNote,
|
|
484
|
+
id: noteId,
|
|
485
|
+
role: "note",
|
|
486
|
+
children: [
|
|
487
|
+
/* @__PURE__ */ jsxs("small", { children: [/* @__PURE__ */ jsx(TriangleAlert, {
|
|
488
|
+
"aria-hidden": "true",
|
|
489
|
+
strokeWidth: 2
|
|
490
|
+
}), "Agent’s note"] }),
|
|
491
|
+
/* @__PURE__ */ jsx("span", {
|
|
492
|
+
className: agent_decision_tree_module_default.dtNoteText,
|
|
493
|
+
children: o.note.text
|
|
494
|
+
}),
|
|
495
|
+
o.note.source && /* @__PURE__ */ jsx("span", {
|
|
496
|
+
className: agent_decision_tree_module_default.dtNoteSrc,
|
|
497
|
+
children: o.note.source
|
|
498
|
+
})
|
|
499
|
+
]
|
|
500
|
+
})]
|
|
501
|
+
}), isChosen && picked === o.id && pill && /* @__PURE__ */ jsx("li", {
|
|
502
|
+
className: agent_decision_tree_module_default.dtOptItem,
|
|
503
|
+
children: pill
|
|
504
|
+
})] }, o.id);
|
|
505
|
+
})
|
|
506
|
+
})]
|
|
507
|
+
}),
|
|
508
|
+
b.outcome !== void 0 && /* @__PURE__ */ jsxs("div", {
|
|
509
|
+
className: agent_decision_tree_module_default.dtOutcome,
|
|
510
|
+
"data-dt-outcome": true,
|
|
511
|
+
children: [/* @__PURE__ */ jsx("span", { children: b.outcome }), /* @__PURE__ */ jsx(Apps, { items: b.apps })]
|
|
512
|
+
}),
|
|
513
|
+
isChosen && b.outcome !== void 0 && phase === "choosing" && /* @__PURE__ */ jsx(Button, {
|
|
514
|
+
size: "sm",
|
|
515
|
+
touch: false,
|
|
516
|
+
onClick: () => commit({
|
|
517
|
+
kind: "outcome",
|
|
518
|
+
branch: b
|
|
519
|
+
}, b.id),
|
|
520
|
+
children: "Confirm"
|
|
521
|
+
}),
|
|
522
|
+
isChosen && !b.options && pill
|
|
523
|
+
]
|
|
524
|
+
})
|
|
525
|
+
}, b.id);
|
|
526
|
+
})
|
|
527
|
+
})
|
|
528
|
+
]
|
|
529
|
+
}, current.id)
|
|
530
|
+
}),
|
|
531
|
+
current && /* @__PURE__ */ jsx("footer", {
|
|
532
|
+
className: agent_decision_tree_module_default.dtFoot,
|
|
533
|
+
children: !chosenBranch ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("span", { children: [
|
|
534
|
+
"Pick a branch ",
|
|
535
|
+
/* @__PURE__ */ jsx(Kbd, { children: "1" }),
|
|
536
|
+
" – ",
|
|
537
|
+
/* @__PURE__ */ jsx(Kbd, { children: branches.length })
|
|
538
|
+
] }), open.length > 1 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
539
|
+
"aria-hidden": "true",
|
|
540
|
+
children: "·"
|
|
541
|
+
}), /* @__PURE__ */ jsxs("button", {
|
|
542
|
+
type: "button",
|
|
543
|
+
className: agent_decision_tree_module_default.dtLink,
|
|
544
|
+
onClick: skip,
|
|
545
|
+
children: ["Next ", /* @__PURE__ */ jsx(Kbd, {
|
|
546
|
+
"aria-hidden": "true",
|
|
547
|
+
children: "→"
|
|
548
|
+
})]
|
|
549
|
+
})] })] }) : phase === "choosing" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
550
|
+
failed && /* @__PURE__ */ jsx("span", {
|
|
551
|
+
className: agent_decision_tree_module_default.dtFailed,
|
|
552
|
+
role: "alert",
|
|
553
|
+
children: "Couldn’t send that to the agent. Try again."
|
|
554
|
+
}),
|
|
555
|
+
/* @__PURE__ */ jsx("span", { children: chosenBranch.options ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
556
|
+
"Then ",
|
|
557
|
+
/* @__PURE__ */ jsx(Kbd, { children: "1" }),
|
|
558
|
+
" – ",
|
|
559
|
+
/* @__PURE__ */ jsx(Kbd, { children: chosenBranch.options.length })
|
|
560
|
+
] }) : chosenBranch.id === "__other" ? "Type your instruction, then press Enter" : "Confirm to send it" }),
|
|
561
|
+
/* @__PURE__ */ jsx("span", {
|
|
562
|
+
"aria-hidden": "true",
|
|
563
|
+
children: "·"
|
|
564
|
+
}),
|
|
565
|
+
/* @__PURE__ */ jsxs("button", {
|
|
566
|
+
type: "button",
|
|
567
|
+
className: agent_decision_tree_module_default.dtLink,
|
|
568
|
+
onClick: reset,
|
|
569
|
+
children: ["Back ", /* @__PURE__ */ jsx(Kbd, {
|
|
570
|
+
"aria-hidden": "true",
|
|
571
|
+
children: "esc"
|
|
572
|
+
})]
|
|
573
|
+
})
|
|
574
|
+
] }) : /* @__PURE__ */ jsx(VisuallyHidden, { children: "Sending your decision" })
|
|
575
|
+
})
|
|
576
|
+
]
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
//#endregion
|
|
580
|
+
export { AgentDecisionTree };
|