@invergent/agent-chat-react 1.5.2 → 1.5.4
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/dist/artifact-chart-X53FKRDZ.js +153 -0
- package/dist/artifact-chart-X53FKRDZ.js.map +1 -0
- package/dist/chunk-QSC4UIVT.js +11 -0
- package/dist/chunk-QSC4UIVT.js.map +1 -0
- package/dist/index.cjs +795 -241
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +542 -185
- package/dist/index.js.map +1 -1
- package/package.json +5 -7
- package/dist/artifact-chart-7J6GOR4M.js +0 -88
- package/dist/artifact-chart-7J6GOR4M.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@invergent/agent-chat-react",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "Reusable React chat UI and runtime for Surogates agent sessions.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"homepage": "https://github.com/invergent-ai/surogates/tree/master/sdk/agent-chat-react#readme",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"react-dom": "^19.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@radix-ui/react-use-controllable-state": "^1.2.2",
|
|
42
41
|
"@radix-ui/react-checkbox": "^1.3.3",
|
|
43
42
|
"@radix-ui/react-label": "^2.1.8",
|
|
44
43
|
"@radix-ui/react-select": "^2.2.6",
|
|
45
44
|
"@radix-ui/react-separator": "^1.1.8",
|
|
46
45
|
"@radix-ui/react-slot": "^1.2.4",
|
|
46
|
+
"@radix-ui/react-use-controllable-state": "^1.2.2",
|
|
47
47
|
"@streamdown/cjk": "^1.0.3",
|
|
48
48
|
"@streamdown/code": "^1.1.1",
|
|
49
49
|
"@streamdown/math": "^1.0.2",
|
|
@@ -53,23 +53,21 @@
|
|
|
53
53
|
"class-variance-authority": "^0.7.1",
|
|
54
54
|
"clsx": "^2.1.1",
|
|
55
55
|
"cmdk": "^1.1.1",
|
|
56
|
+
"chart.js": "^4.5.1",
|
|
56
57
|
"date-fns": "^4.1.0",
|
|
57
58
|
"diff": "^8.0.4",
|
|
58
59
|
"lucide-react": "^1.8.0",
|
|
59
60
|
"nanoid": "^5.1.7",
|
|
60
61
|
"next-themes": "^0.4.6",
|
|
62
|
+
"pdfjs-dist": "^5.7.284",
|
|
61
63
|
"radix-ui": "^1.4.3",
|
|
62
|
-
"react-vega": "^8.0.0",
|
|
63
64
|
"recharts": "^3.8.0",
|
|
64
65
|
"shiki": "^4.0.2",
|
|
65
66
|
"streamdown": "2.5.0",
|
|
66
67
|
"tailwind-merge": "^3.5.0",
|
|
67
68
|
"tokenlens": "^1.3.1",
|
|
68
69
|
"tw-shimmer": "^0.4.6",
|
|
69
|
-
"use-stick-to-bottom": "^1.1.3"
|
|
70
|
-
"vega": "^6.2.0",
|
|
71
|
-
"vega-embed": "^7.1.0",
|
|
72
|
-
"vega-lite": "^6.4.0"
|
|
70
|
+
"use-stick-to-bottom": "^1.1.3"
|
|
73
71
|
},
|
|
74
72
|
"devDependencies": {
|
|
75
73
|
"@types/node": "^24.10.1",
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { useRef, useState, useEffect, useMemo } from 'react';
|
|
2
|
-
import { VegaEmbed } from 'react-vega';
|
|
3
|
-
import { useTheme } from 'next-themes';
|
|
4
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
-
|
|
6
|
-
// src/components/chat/artifacts/artifact-chart.tsx
|
|
7
|
-
var VEGA_LITE_SCHEMA = "https://vega.github.io/schema/vega-lite/v5.json";
|
|
8
|
-
var DEFAULT_CHART_HEIGHT = 320;
|
|
9
|
-
var MIN_CHART_WIDTH = 120;
|
|
10
|
-
var LIGHT_CONFIG = {
|
|
11
|
-
background: "transparent",
|
|
12
|
-
axis: {
|
|
13
|
-
labelColor: "#444",
|
|
14
|
-
titleColor: "#111",
|
|
15
|
-
gridColor: "#e5e7eb",
|
|
16
|
-
domainColor: "#d1d5db",
|
|
17
|
-
tickColor: "#d1d5db"
|
|
18
|
-
},
|
|
19
|
-
view: { stroke: "transparent" },
|
|
20
|
-
legend: { labelColor: "#444", titleColor: "#111" }
|
|
21
|
-
};
|
|
22
|
-
var DARK_CONFIG = {
|
|
23
|
-
background: "transparent",
|
|
24
|
-
axis: {
|
|
25
|
-
labelColor: "#cbd5e1",
|
|
26
|
-
titleColor: "#f1f5f9",
|
|
27
|
-
gridColor: "#374151",
|
|
28
|
-
domainColor: "#4b5563",
|
|
29
|
-
tickColor: "#4b5563"
|
|
30
|
-
},
|
|
31
|
-
view: { stroke: "transparent" },
|
|
32
|
-
legend: { labelColor: "#cbd5e1", titleColor: "#f1f5f9" }
|
|
33
|
-
};
|
|
34
|
-
function ArtifactChart({ spec }) {
|
|
35
|
-
const { resolvedTheme } = useTheme();
|
|
36
|
-
const isDark = resolvedTheme === "dark";
|
|
37
|
-
const containerRef = useRef(null);
|
|
38
|
-
const [width, setWidth] = useState(null);
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
const el = containerRef.current;
|
|
41
|
-
if (!el) return;
|
|
42
|
-
const observer = new ResizeObserver((entries) => {
|
|
43
|
-
const w = entries[0]?.contentRect.width ?? el.offsetWidth;
|
|
44
|
-
if (w >= MIN_CHART_WIDTH) setWidth(Math.floor(w));
|
|
45
|
-
});
|
|
46
|
-
observer.observe(el);
|
|
47
|
-
if (el.offsetWidth >= MIN_CHART_WIDTH) setWidth(el.offsetWidth);
|
|
48
|
-
return () => observer.disconnect();
|
|
49
|
-
}, []);
|
|
50
|
-
const [error, setError] = useState(null);
|
|
51
|
-
const merged = useMemo(() => {
|
|
52
|
-
if (width == null) return null;
|
|
53
|
-
const base = spec.vega_lite ?? {};
|
|
54
|
-
const themeConfig = isDark ? DARK_CONFIG : LIGHT_CONFIG;
|
|
55
|
-
return {
|
|
56
|
-
$schema: VEGA_LITE_SCHEMA,
|
|
57
|
-
width,
|
|
58
|
-
height: DEFAULT_CHART_HEIGHT,
|
|
59
|
-
...base,
|
|
60
|
-
config: {
|
|
61
|
-
...themeConfig,
|
|
62
|
-
...base.config ?? {}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}, [spec.vega_lite, isDark, width]);
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
setError(null);
|
|
68
|
-
}, [spec.vega_lite]);
|
|
69
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
70
|
-
/* @__PURE__ */ jsx("div", { ref: containerRef, className: "w-full", children: merged && /* @__PURE__ */ jsx(
|
|
71
|
-
VegaEmbed,
|
|
72
|
-
{
|
|
73
|
-
spec: merged,
|
|
74
|
-
options: { actions: false, renderer: "svg" },
|
|
75
|
-
onError: (e) => setError(e instanceof Error ? e.message : String(e))
|
|
76
|
-
}
|
|
77
|
-
) }),
|
|
78
|
-
error && /* @__PURE__ */ jsxs("p", { className: "text-xs text-destructive", children: [
|
|
79
|
-
"Chart error: ",
|
|
80
|
-
error
|
|
81
|
-
] }),
|
|
82
|
-
spec.caption && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: spec.caption })
|
|
83
|
-
] });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { ArtifactChart };
|
|
87
|
-
//# sourceMappingURL=artifact-chart-7J6GOR4M.js.map
|
|
88
|
-
//# sourceMappingURL=artifact-chart-7J6GOR4M.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/chat/artifacts/artifact-chart.tsx"],"names":[],"mappings":";;;;;;AAeA,IAAM,gBAAA,GAAmB,iDAAA;AAKzB,IAAM,oBAAA,GAAuB,GAAA;AAI7B,IAAM,eAAA,GAAkB,GAAA;AAMxB,IAAM,YAAA,GAAe;AAAA,EACnB,UAAA,EAAY,aAAA;AAAA,E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SAAA;AAAA,MAAA;AAAA,QACC,IAAA,EAAM,MAAA;AAAA,QACN,OAAA,EAAS,EAAE,OAAA,EAAS,KAAA,EAAO,UAAU,KAAA,EAAM;AAAA,QAC3C,OAAA,EAAS,CAAC,CAAA,KAAM,QAAA,CAAS,CAAA,YAAa,QAAQ,CAAA,CAAE,OAAA,GAAU,MAAA,CAAO,CAAC,CAAC;AAAA;AAAA,KACrE,EAEJ,CAAA;AAAA,IACC,KAAA,oBACC,IAAA,CAAC,GAAA,EAAA,EAAE,SAAA,EAAU,0BAAA,EAA2B,QAAA,EAAA;AAAA,MAAA,eAAA;AAAA,MAAc;AAAA,KAAA,EAAM,CAAA;AAAA,IAE7D,KAAK,OAAA,oBACJ,GAAA,CAAC,OAAE,SAAA,EAAU,+BAAA,EAAiC,eAAK,OAAA,EAAQ;AAAA,GAAA,EAE/D,CAAA;AAEJ","file":"artifact-chart-7J6GOR4M.js","sourcesContent":["// Copyright (c) 2026, Invergent SA, developed by Flavius Burca\n// SPDX-License-Identifier: AGPL-3.0-only\n//\n// Chart artifact renderer — embeds a Vega-Lite spec via react-vega.\n// Respects the app's dark/light theme and resizes with the thread column.\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { VegaEmbed } from \"react-vega\";\nimport type { VisualizationSpec } from \"vega-embed\";\nimport { useTheme } from \"next-themes\";\nimport type { ChartArtifactSpec } from \"../../../types\";\n\n// Vega-Lite JSON schema identifier. Injected when the LLM-emitted spec\n// is missing one so ``VegaEmbed`` picks the Vega-Lite grammar instead\n// of falling back to base Vega.\nconst VEGA_LITE_SCHEMA = \"https://vega.github.io/schema/vega-lite/v5.json\";\n\n// Fallback height when the spec doesn't supply one. Width is measured\n// from the container; height only needs a sensible default because\n// Vega-Lite's internal default (200) is often too short for line charts.\nconst DEFAULT_CHART_HEIGHT = 320;\n\n// Minimum width we'll bother rendering at — guards against the rare\n// layout flash where ResizeObserver reports 0 before the parent lays out.\nconst MIN_CHART_WIDTH = 120;\n\n// Minimal theme overrides so charts sit on dark and light backgrounds\n// without manual colour tuning in every generated spec. Vega-Lite's\n// ``config`` is merged with the user's spec — the spec always wins on\n// an explicit collision.\nconst LIGHT_CONFIG = {\n background: \"transparent\",\n axis: {\n labelColor: \"#444\",\n titleColor: \"#111\",\n gridColor: \"#e5e7eb\",\n domainColor: \"#d1d5db\",\n tickColor: \"#d1d5db\",\n },\n view: { stroke: \"transparent\" },\n legend: { labelColor: \"#444\", titleColor: \"#111\" },\n};\n\nconst DARK_CONFIG = {\n background: \"transparent\",\n axis: {\n labelColor: \"#cbd5e1\",\n titleColor: \"#f1f5f9\",\n gridColor: \"#374151\",\n domainColor: \"#4b5563\",\n tickColor: \"#4b5563\",\n },\n view: { stroke: \"transparent\" },\n legend: { labelColor: \"#cbd5e1\", titleColor: \"#f1f5f9\" },\n};\n\nexport function ArtifactChart({ spec }: { spec: ChartArtifactSpec }) {\n const { resolvedTheme } = useTheme();\n const isDark = resolvedTheme === \"dark\";\n\n // Measure the container so Vega gets an explicit numeric width. The\n // `width: \"container\"` mode depends on the parent having a layout\n // width before vega-embed measures it; inside `flex`/`min-w-0`/\n // `overflow-auto` chains it reports zero and the chart renders into\n // a 0-wide box. Passing a measured number sidesteps the problem.\n const containerRef = useRef<HTMLDivElement>(null);\n const [width, setWidth] = useState<number | null>(null);\n\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n const observer = new ResizeObserver((entries) => {\n const w = entries[0]?.contentRect.width ?? el.offsetWidth;\n if (w >= MIN_CHART_WIDTH) setWidth(Math.floor(w));\n });\n observer.observe(el);\n // Seed with the first measurement synchronously.\n if (el.offsetWidth >= MIN_CHART_WIDTH) setWidth(el.offsetWidth);\n return () => observer.disconnect();\n }, []);\n\n const [error, setError] = useState<string | null>(null);\n\n const merged = useMemo<VisualizationSpec | null>(() => {\n if (width == null) return null;\n const base = (spec.vega_lite ?? {}) as Record<string, unknown>;\n const themeConfig = isDark ? DARK_CONFIG : LIGHT_CONFIG;\n return {\n $schema: VEGA_LITE_SCHEMA,\n width,\n height: DEFAULT_CHART_HEIGHT,\n ...base,\n config: {\n ...themeConfig,\n ...((base.config as Record<string, unknown>) ?? {}),\n },\n } as VisualizationSpec;\n }, [spec.vega_lite, isDark, width]);\n\n // Clear any prior error when the spec changes.\n useEffect(() => {\n setError(null);\n }, [spec.vega_lite]);\n\n return (\n <div className=\"flex flex-col gap-2\">\n <div ref={containerRef} className=\"w-full\">\n {merged && (\n <VegaEmbed\n spec={merged}\n options={{ actions: false, renderer: \"svg\" }}\n onError={(e) => setError(e instanceof Error ? e.message : String(e))}\n />\n )}\n </div>\n {error && (\n <p className=\"text-xs text-destructive\">Chart error: {error}</p>\n )}\n {spec.caption && (\n <p className=\"text-xs text-muted-foreground\">{spec.caption}</p>\n )}\n </div>\n );\n}\n"]}
|