@heroui/agent 0.2.0-beta.1 → 0.2.0-beta.2
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 +10 -0
- package/dist/chart-content-USUK4ZM5.js +2696 -0
- package/dist/chunk-AEUPMIPT.js +577 -0
- package/dist/{chunk-RQCTC4JB.js → chunk-EXFDD3K3.js} +1 -1
- package/dist/{chunk-GDDNN2XY.js → chunk-Y6Y6ILXP.js} +2 -2
- package/dist/{component-renderer-IBJDNXSO.js → component-renderer-EOOT6ONY.js} +739 -414
- package/dist/contracts.d.ts +67 -8
- package/dist/contracts.js +224 -4
- package/dist/css/index.css +1 -1
- package/dist/{embed-runtime-XOPQY7Z5.js → embed-runtime-QOATFAS7.js} +170 -95
- package/dist/{identity-NYCXY1mT.d.ts → identity-hIGFpObN.d.ts} +3 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.js +2 -2
- package/dist/server.d.ts +1 -1
- package/dist/server.js +6 -1
- package/package.json +25 -26
- package/dist/chart-content-VZ66GD22.js +0 -1391
- package/dist/chunk-DW4AQRM5.js +0 -297
package/dist/chunk-DW4AQRM5.js
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveOverlayPortalContainer
|
|
3
|
-
} from "./chunk-TOOT6SZ2.js";
|
|
4
|
-
|
|
5
|
-
// ../agent-ui/src/types.ts
|
|
6
|
-
function componentActionFromSpec(componentId, action) {
|
|
7
|
-
if (action.toolCall) {
|
|
8
|
-
return {
|
|
9
|
-
actionId: action.id,
|
|
10
|
-
args: action.toolCall.arguments,
|
|
11
|
-
componentId,
|
|
12
|
-
label: action.label,
|
|
13
|
-
prompt: action.prompt,
|
|
14
|
-
toolName: action.toolCall.name,
|
|
15
|
-
type: "tool"
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
if (action.prompt) {
|
|
19
|
-
return { componentId, label: action.label, prompt: action.prompt, type: "followup" };
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
function createComponentSelection(component, datum) {
|
|
24
|
-
return { componentId: component.id, componentTitle: component.title, datum };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// ../agent-ui/src/utils/formatters.ts
|
|
28
|
-
var numberFormatters = /* @__PURE__ */ new Map();
|
|
29
|
-
function supportedLocale(locale) {
|
|
30
|
-
try {
|
|
31
|
-
return Intl.NumberFormat.supportedLocalesOf([locale])[0] ?? "en";
|
|
32
|
-
} catch {
|
|
33
|
-
return "en";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function formatNumber(value, format, locale = "en") {
|
|
37
|
-
const resolvedLocale = supportedLocale(locale);
|
|
38
|
-
if (!format) return value.toLocaleString(resolvedLocale);
|
|
39
|
-
const options = {
|
|
40
|
-
...format.style === "currency" ? { currency: format.currency, style: "currency" } : {},
|
|
41
|
-
...format.style === "percent" ? { style: "percent" } : {},
|
|
42
|
-
...format.style === "percent" && format.maximumFractionDigits !== void 0 ? { maximumFractionDigits: format.maximumFractionDigits } : {},
|
|
43
|
-
...format.style !== "percent" && format.compact ? { notation: "compact" } : {}
|
|
44
|
-
};
|
|
45
|
-
const cacheKey = `${resolvedLocale}:${JSON.stringify(options)}`;
|
|
46
|
-
let formatter = numberFormatters.get(cacheKey);
|
|
47
|
-
if (!formatter) {
|
|
48
|
-
formatter = new Intl.NumberFormat(resolvedLocale, options);
|
|
49
|
-
numberFormatters.set(cacheKey, formatter);
|
|
50
|
-
}
|
|
51
|
-
return formatter.format(value);
|
|
52
|
-
}
|
|
53
|
-
function formatAxisValue(value, locale = "en") {
|
|
54
|
-
const resolvedLocale = supportedLocale(locale);
|
|
55
|
-
const absolute = Math.abs(value);
|
|
56
|
-
if (absolute >= 1e6)
|
|
57
|
-
return `${(value / 1e6).toLocaleString(resolvedLocale, { maximumFractionDigits: 1 })}M`;
|
|
58
|
-
if (absolute >= 1e3)
|
|
59
|
-
return `${(value / 1e3).toLocaleString(resolvedLocale, { maximumFractionDigits: 1 })}K`;
|
|
60
|
-
return value.toLocaleString(resolvedLocale, { maximumFractionDigits: 1 });
|
|
61
|
-
}
|
|
62
|
-
function formatDelta(value, options = {}, locale = "en") {
|
|
63
|
-
const formatter = new Intl.NumberFormat(supportedLocale(locale), {
|
|
64
|
-
maximumFractionDigits: options.maximumFractionDigits ?? 2,
|
|
65
|
-
signDisplay: "always",
|
|
66
|
-
style: options.style === "percent" ? "percent" : "decimal"
|
|
67
|
-
});
|
|
68
|
-
return formatter.format(value);
|
|
69
|
-
}
|
|
70
|
-
function formatCell(value, format, locale = "en") {
|
|
71
|
-
return typeof value === "number" ? formatNumber(value, format, locale) : String(value ?? "");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ../agent-ui/src/components/component-actions/export-actions.tsx
|
|
75
|
-
import { Ellipsis } from "@gravity-ui/icons";
|
|
76
|
-
import { Button, Dropdown, Label } from "@heroui/react";
|
|
77
|
-
import { useCallback, useRef, useState } from "react";
|
|
78
|
-
|
|
79
|
-
// ../agent-ui/src/components/component-actions/export-utils.ts
|
|
80
|
-
function filename(title, extension) {
|
|
81
|
-
const stem = title.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 80);
|
|
82
|
-
return `${stem || "agent-ui"}.${extension}`;
|
|
83
|
-
}
|
|
84
|
-
function download(data, type, name) {
|
|
85
|
-
if (typeof document === "undefined" || typeof URL.createObjectURL !== "function") return;
|
|
86
|
-
const url = URL.createObjectURL(new Blob([data], { type }));
|
|
87
|
-
const anchor = document.createElement("a");
|
|
88
|
-
anchor.download = name;
|
|
89
|
-
anchor.href = url;
|
|
90
|
-
anchor.click();
|
|
91
|
-
URL.revokeObjectURL(url);
|
|
92
|
-
}
|
|
93
|
-
function csvCell(value) {
|
|
94
|
-
const text = String(value ?? "");
|
|
95
|
-
return /[",\r\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
|
96
|
-
}
|
|
97
|
-
function componentToCsv(component) {
|
|
98
|
-
let rows;
|
|
99
|
-
let keys;
|
|
100
|
-
if (component.kind === "data-table") {
|
|
101
|
-
rows = component.rows;
|
|
102
|
-
keys = component.columns.map((column) => column.key);
|
|
103
|
-
} else if (component.kind === "line-chart" || component.kind === "area-chart" || component.kind === "bar-chart" || component.kind === "composed-chart" || component.kind === "pie-chart" || component.kind === "donut-chart" || component.kind === "radar-chart" || component.kind === "radial-chart" || component.kind === "scatter-chart" || component.kind === "heatmap") {
|
|
104
|
-
rows = component.data;
|
|
105
|
-
keys = [...new Set(rows.flatMap((row) => Object.keys(row)))];
|
|
106
|
-
}
|
|
107
|
-
if (!rows || !keys?.length) return null;
|
|
108
|
-
return [
|
|
109
|
-
keys.map(csvCell).join(","),
|
|
110
|
-
...rows.map((row) => keys.map((key) => csvCell(row[key])).join(","))
|
|
111
|
-
].join("\n");
|
|
112
|
-
}
|
|
113
|
-
var SVG_STYLE_TOKENS = [
|
|
114
|
-
"--accent",
|
|
115
|
-
"--border",
|
|
116
|
-
"--chart-1",
|
|
117
|
-
"--chart-2",
|
|
118
|
-
"--chart-3",
|
|
119
|
-
"--chart-4",
|
|
120
|
-
"--chart-5",
|
|
121
|
-
"--foreground",
|
|
122
|
-
"--muted",
|
|
123
|
-
"--surface"
|
|
124
|
-
];
|
|
125
|
-
function svgMarkup(button) {
|
|
126
|
-
const card = button.closest('[data-slot="agent-ui-card"]');
|
|
127
|
-
const svg = card?.querySelector("svg");
|
|
128
|
-
if (!(card instanceof HTMLElement) || !(svg instanceof SVGElement)) return null;
|
|
129
|
-
const clone = svg.cloneNode(true);
|
|
130
|
-
const styles = getComputedStyle(card);
|
|
131
|
-
const variables = SVG_STYLE_TOKENS.map((token) => `${token}:${styles.getPropertyValue(token)}`).filter((entry) => !entry.endsWith(":")).join(";");
|
|
132
|
-
clone.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
133
|
-
clone.setAttribute("style", [clone.getAttribute("style"), variables].filter(Boolean).join(";"));
|
|
134
|
-
return new XMLSerializer().serializeToString(clone);
|
|
135
|
-
}
|
|
136
|
-
async function exportPng(button, title) {
|
|
137
|
-
const markup = svgMarkup(button);
|
|
138
|
-
if (!markup || typeof Image === "undefined" || typeof URL.createObjectURL !== "function") return;
|
|
139
|
-
const source = URL.createObjectURL(new Blob([markup], { type: "image/svg+xml;charset=utf-8" }));
|
|
140
|
-
const image = new Image();
|
|
141
|
-
await new Promise((resolve, reject) => {
|
|
142
|
-
image.onload = () => resolve();
|
|
143
|
-
image.onerror = () => reject(new Error("Unable to render component image"));
|
|
144
|
-
image.src = source;
|
|
145
|
-
});
|
|
146
|
-
const canvas = document.createElement("canvas");
|
|
147
|
-
const scale = Math.max(1, window.devicePixelRatio || 1);
|
|
148
|
-
canvas.width = Math.max(1, image.width) * scale;
|
|
149
|
-
canvas.height = Math.max(1, image.height) * scale;
|
|
150
|
-
const context = canvas.getContext("2d");
|
|
151
|
-
context?.scale(scale, scale);
|
|
152
|
-
context?.drawImage(image, 0, 0);
|
|
153
|
-
URL.revokeObjectURL(source);
|
|
154
|
-
const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"));
|
|
155
|
-
if (blob) download(blob, "image/png", filename(title, "png"));
|
|
156
|
-
}
|
|
157
|
-
function exportComponent(button, component, format) {
|
|
158
|
-
if (format === "csv") {
|
|
159
|
-
const csv = componentToCsv(component);
|
|
160
|
-
if (csv) download(csv, "text/csv;charset=utf-8", filename(component.title, "csv"));
|
|
161
|
-
} else if (format === "svg") {
|
|
162
|
-
const markup = svgMarkup(button);
|
|
163
|
-
if (markup) download(markup, "image/svg+xml;charset=utf-8", filename(component.title, "svg"));
|
|
164
|
-
} else {
|
|
165
|
-
void exportPng(button, component.title);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// ../agent-ui/src/components/component-actions/export-actions.tsx
|
|
170
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
171
|
-
var FORMAT_LABELS = {
|
|
172
|
-
csv: "Export as CSV",
|
|
173
|
-
png: "Export as PNG",
|
|
174
|
-
svg: "Export as SVG"
|
|
175
|
-
};
|
|
176
|
-
function ComponentExportActions({
|
|
177
|
-
component,
|
|
178
|
-
formats = [],
|
|
179
|
-
onAction
|
|
180
|
-
}) {
|
|
181
|
-
const triggerRef = useRef(null);
|
|
182
|
-
const [portalContainer, setPortalContainer] = useState();
|
|
183
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
184
|
-
const pointerOpenAt = useRef(0);
|
|
185
|
-
const handleOpenChange = (nextOpen) => {
|
|
186
|
-
if (!nextOpen && Date.now() - pointerOpenAt.current < 350) return;
|
|
187
|
-
setIsOpen(nextOpen);
|
|
188
|
-
};
|
|
189
|
-
const captureTrigger = useCallback((node) => {
|
|
190
|
-
triggerRef.current = node;
|
|
191
|
-
setPortalContainer(resolveOverlayPortalContainer(node));
|
|
192
|
-
}, []);
|
|
193
|
-
const supported = formats.filter((format) => format !== "csv" || componentToCsv(component));
|
|
194
|
-
if (supported.length === 0) return null;
|
|
195
|
-
return /* @__PURE__ */ jsx("div", { className: "aui-export-actions", "data-slot": "agent-ui-export-actions", children: /* @__PURE__ */ jsxs(Dropdown, { isOpen, onOpenChange: handleOpenChange, children: [
|
|
196
|
-
/* @__PURE__ */ jsx(
|
|
197
|
-
Button,
|
|
198
|
-
{
|
|
199
|
-
ref: captureTrigger,
|
|
200
|
-
isIconOnly: true,
|
|
201
|
-
"aria-label": `Export options for ${component.title}`,
|
|
202
|
-
size: "sm",
|
|
203
|
-
variant: "ghost",
|
|
204
|
-
onPointerDown: () => {
|
|
205
|
-
pointerOpenAt.current = Date.now();
|
|
206
|
-
},
|
|
207
|
-
children: /* @__PURE__ */ jsx(Ellipsis, {})
|
|
208
|
-
}
|
|
209
|
-
),
|
|
210
|
-
/* @__PURE__ */ jsx(Dropdown.Popover, { placement: "bottom end", UNSTABLE_portalContainer: portalContainer, children: /* @__PURE__ */ jsx(
|
|
211
|
-
Dropdown.Menu,
|
|
212
|
-
{
|
|
213
|
-
onAction: (key) => {
|
|
214
|
-
const format = key;
|
|
215
|
-
if (triggerRef.current) exportComponent(triggerRef.current, component, format);
|
|
216
|
-
onAction?.({ componentId: component.id, format, type: "export" });
|
|
217
|
-
setIsOpen(false);
|
|
218
|
-
},
|
|
219
|
-
children: supported.map((format) => /* @__PURE__ */ jsx(Dropdown.Item, { id: format, textValue: FORMAT_LABELS[format], children: /* @__PURE__ */ jsx(Label, { children: FORMAT_LABELS[format] }) }, format))
|
|
220
|
-
}
|
|
221
|
-
) })
|
|
222
|
-
] }) });
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// ../agent-ui/src/components/data-visualization/trend-change/trend-change.tsx
|
|
226
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
227
|
-
function TrendArrow({ direction }) {
|
|
228
|
-
return /* @__PURE__ */ jsx2(
|
|
229
|
-
"svg",
|
|
230
|
-
{
|
|
231
|
-
"aria-hidden": "true",
|
|
232
|
-
className: "aui-change__indicator",
|
|
233
|
-
fill: "none",
|
|
234
|
-
stroke: "currentColor",
|
|
235
|
-
strokeLinecap: "round",
|
|
236
|
-
strokeLinejoin: "round",
|
|
237
|
-
strokeWidth: "2",
|
|
238
|
-
viewBox: "0 0 24 24",
|
|
239
|
-
children: direction === "up" ? /* @__PURE__ */ jsx2("path", { d: "M12 19V5m-5 5 5-5 5 5" }) : /* @__PURE__ */ jsx2("path", { d: "M12 5v14m5-5-5 5-5-5" })
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
function TrendChange({ slot, value }) {
|
|
244
|
-
return /* @__PURE__ */ jsxs2(
|
|
245
|
-
"span",
|
|
246
|
-
{
|
|
247
|
-
className: "aui-change",
|
|
248
|
-
"data-slot": slot,
|
|
249
|
-
"data-trend": value > 0 ? "up" : value < 0 ? "down" : "neutral",
|
|
250
|
-
children: [
|
|
251
|
-
value === 0 ? null : /* @__PURE__ */ jsx2(TrendArrow, { direction: value > 0 ? "up" : "down" }),
|
|
252
|
-
formatDelta(value),
|
|
253
|
-
"%"
|
|
254
|
-
]
|
|
255
|
-
}
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// ../agent-ui/src/components/data-visualization/charts/chart-colors.ts
|
|
260
|
-
var COLORS = [
|
|
261
|
-
"var(--chart-3, var(--accent))",
|
|
262
|
-
"var(--chart-1, oklch(from var(--accent) calc(l - 0.24) c h))",
|
|
263
|
-
"var(--chart-4, oklch(from var(--accent) calc(l + 0.12) c h))",
|
|
264
|
-
"var(--chart-2, oklch(from var(--accent) calc(l - 0.12) c h))",
|
|
265
|
-
"var(--chart-5, oklch(from var(--accent) calc(l + 0.24) c h))"
|
|
266
|
-
];
|
|
267
|
-
var CHART_COLOR_TOKENS = {
|
|
268
|
-
accent: "var(--accent)",
|
|
269
|
-
"chart-1": "var(--chart-1, oklch(from var(--accent) calc(l - 0.24) c h))",
|
|
270
|
-
"chart-2": "var(--chart-2, oklch(from var(--accent) calc(l - 0.12) c h))",
|
|
271
|
-
"chart-3": "var(--chart-3, var(--accent))",
|
|
272
|
-
"chart-4": "var(--chart-4, oklch(from var(--accent) calc(l + 0.12) c h))",
|
|
273
|
-
"chart-5": "var(--chart-5, oklch(from var(--accent) calc(l + 0.24) c h))",
|
|
274
|
-
danger: "var(--danger)",
|
|
275
|
-
default: "var(--default-foreground, var(--foreground))",
|
|
276
|
-
success: "var(--success)",
|
|
277
|
-
warning: "var(--warning)"
|
|
278
|
-
};
|
|
279
|
-
function resolveChartColor(color, index) {
|
|
280
|
-
return color ? CHART_COLOR_TOKENS[color] : COLORS[index % COLORS.length];
|
|
281
|
-
}
|
|
282
|
-
function paletteChartColor(index) {
|
|
283
|
-
return COLORS[index % COLORS.length];
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export {
|
|
287
|
-
componentActionFromSpec,
|
|
288
|
-
createComponentSelection,
|
|
289
|
-
formatNumber,
|
|
290
|
-
formatAxisValue,
|
|
291
|
-
formatCell,
|
|
292
|
-
ComponentExportActions,
|
|
293
|
-
TrendChange,
|
|
294
|
-
CHART_COLOR_TOKENS,
|
|
295
|
-
resolveChartColor,
|
|
296
|
-
paletteChartColor
|
|
297
|
-
};
|