@davincidreams/dynamic-canvas-react 0.1.0 → 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/README.md +261 -297
- package/dist/RendererFrame-ri9awAzI.cjs +1 -0
- package/dist/RendererFrame-w1obQvoH.js +25 -0
- package/dist/core/CanvasContainer.d.ts +23 -0
- package/dist/core/CanvasContainer.d.ts.map +1 -0
- package/dist/core/CanvasContext.d.ts +45 -0
- package/dist/core/CanvasContext.d.ts.map +1 -0
- package/dist/core/ComponentRegistry.d.ts +36 -0
- package/dist/core/ComponentRegistry.d.ts.map +1 -0
- package/dist/core/ErrorBoundary.d.ts +18 -0
- package/dist/core/ErrorBoundary.d.ts.map +1 -0
- package/dist/core/RendererResolver.d.ts +14 -0
- package/dist/core/RendererResolver.d.ts.map +1 -0
- package/dist/core/StreamProcessor.d.ts +34 -0
- package/dist/core/StreamProcessor.d.ts.map +1 -0
- package/dist/core/SurfaceManager.d.ts +36 -0
- package/dist/core/SurfaceManager.d.ts.map +1 -0
- package/dist/hooks/useA2UISurface.d.ts +41 -0
- package/dist/hooks/useA2UISurface.d.ts.map +1 -0
- package/dist/hooks/useStreamingContent.d.ts +17 -0
- package/dist/hooks/useStreamingContent.d.ts.map +1 -0
- package/dist/index.cjs +38 -0
- package/dist/index.d.ts +28 -302
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1096 -0
- package/dist/renderers/ArtifactRenderer.d.ts +6 -0
- package/dist/renderers/ArtifactRenderer.d.ts.map +1 -0
- package/dist/renderers/ArtifactRenderer.test.d.ts +2 -0
- package/dist/renderers/ArtifactRenderer.test.d.ts.map +1 -0
- package/dist/renderers/ChartRenderer.d.ts +20 -0
- package/dist/renderers/ChartRenderer.d.ts.map +1 -0
- package/dist/renderers/CodeRenderer.d.ts +16 -0
- package/dist/renderers/CodeRenderer.d.ts.map +1 -0
- package/dist/renderers/CustomRenderer.d.ts +14 -0
- package/dist/renderers/CustomRenderer.d.ts.map +1 -0
- package/dist/renderers/DocumentRenderer.d.ts +15 -0
- package/dist/renderers/DocumentRenderer.d.ts.map +1 -0
- package/dist/renderers/KnowledgeGraphRenderer.d.ts +6 -0
- package/dist/renderers/KnowledgeGraphRenderer.d.ts.map +1 -0
- package/dist/renderers/MapRenderer.d.ts +6 -0
- package/dist/renderers/MapRenderer.d.ts.map +1 -0
- package/dist/renderers/MediaRenderer.d.ts +6 -0
- package/dist/renderers/MediaRenderer.d.ts.map +1 -0
- package/dist/renderers/MediaRenderer.test.d.ts +2 -0
- package/dist/renderers/MediaRenderer.test.d.ts.map +1 -0
- package/dist/renderers/TimelineRenderer.d.ts +16 -0
- package/dist/renderers/TimelineRenderer.d.ts.map +1 -0
- package/dist/renderers/artifact.cjs +2 -0
- package/dist/renderers/artifact.js +35 -0
- package/dist/renderers/chart.cjs +1 -0
- package/dist/renderers/chart.js +121 -0
- package/dist/renderers/code.cjs +2 -0
- package/dist/renderers/code.js +100 -0
- package/dist/renderers/document.cjs +1 -0
- package/dist/renderers/document.js +46 -0
- package/dist/renderers/index.d.ts +15 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/knowledge-graph.cjs +1 -0
- package/dist/renderers/knowledge-graph.js +120 -0
- package/dist/renderers/map.cjs +1 -0
- package/dist/renderers/map.js +56 -0
- package/dist/renderers/media.cjs +1 -0
- package/dist/renderers/media.js +71 -0
- package/dist/renderers/shared/LazyWrapper.d.ts +9 -0
- package/dist/renderers/shared/LazyWrapper.d.ts.map +1 -0
- package/dist/renderers/shared/RendererFrame.d.ts +10 -0
- package/dist/renderers/shared/RendererFrame.d.ts.map +1 -0
- package/dist/renderers/timeline.cjs +1 -0
- package/dist/renderers/timeline.js +105 -0
- package/dist/schema/a2ui-envelope.d.ts +60 -0
- package/dist/schema/a2ui-envelope.d.ts.map +1 -0
- package/dist/schema/catalog-definition.d.ts +25 -0
- package/dist/schema/catalog-definition.d.ts.map +1 -0
- package/dist/schema/component-types.d.ts +28 -0
- package/dist/schema/component-types.d.ts.map +1 -0
- package/dist/schema/components/artifact.d.ts +18 -0
- package/dist/schema/components/artifact.d.ts.map +1 -0
- package/dist/schema/components/chart.d.ts +33 -0
- package/dist/schema/components/chart.d.ts.map +1 -0
- package/dist/schema/components/code.d.ts +15 -0
- package/dist/schema/components/code.d.ts.map +1 -0
- package/dist/schema/components/custom.d.ts +13 -0
- package/dist/schema/components/custom.d.ts.map +1 -0
- package/dist/schema/components/document.d.ts +13 -0
- package/dist/schema/components/document.d.ts.map +1 -0
- package/dist/schema/components/knowledge-graph.d.ts +35 -0
- package/dist/schema/components/knowledge-graph.d.ts.map +1 -0
- package/dist/schema/components/map.d.ts +35 -0
- package/dist/schema/components/map.d.ts.map +1 -0
- package/dist/schema/components/media.d.ts +20 -0
- package/dist/schema/components/media.d.ts.map +1 -0
- package/dist/schema/components/timeline.d.ts +28 -0
- package/dist/schema/components/timeline.d.ts.map +1 -0
- package/dist/schema/index.d.ts +12 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/validation.d.ts +15 -0
- package/dist/schema/validation.d.ts.map +1 -0
- package/dist/schema.cjs +1 -0
- package/dist/schema.d.ts +7 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +194 -0
- package/dist/themes/darkTheme.d.ts +3 -0
- package/dist/themes/darkTheme.d.ts.map +1 -0
- package/dist/themes/defaultTheme.d.ts +3 -0
- package/dist/themes/defaultTheme.d.ts.map +1 -0
- package/dist/themes/index.d.ts +9 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/lightTheme.d.ts +3 -0
- package/dist/themes/lightTheme.d.ts.map +1 -0
- package/dist/themes/types.d.ts +8 -0
- package/dist/themes/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +164 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/contentAnalyzer.d.ts +46 -0
- package/dist/utils/contentAnalyzer.d.ts.map +1 -0
- package/dist/utils/jsonPointer.d.ts +15 -0
- package/dist/utils/jsonPointer.d.ts.map +1 -0
- package/dist/utils/streaming.d.ts +10 -0
- package/dist/utils/streaming.d.ts.map +1 -0
- package/package.json +97 -15
- package/dist/dynamic-canvas.cjs.js +0 -65
- package/dist/dynamic-canvas.es.js +0 -966
- package/dist/dynamic-canvas.umd.js +0 -65
package/dist/index.js
ADDED
|
@@ -0,0 +1,1096 @@
|
|
|
1
|
+
import { jsx as l, jsxs as N, Fragment as G } from "react/jsx-runtime";
|
|
2
|
+
import H, { createContext as Y, useState as S, useRef as D, useEffect as A, useMemo as R, useContext as Q, Suspense as P, useCallback as w } from "react";
|
|
3
|
+
import { createStore as V } from "zustand/vanilla";
|
|
4
|
+
import { getMessageType as q, isA2UIMessage as X } from "./schema.js";
|
|
5
|
+
import { A2UI_COMPONENT_TYPES as $e, DYNAMIC_CANVAS_CATALOG as Oe, isA2UIComponent as We, validateComponent as Je, validateMessage as Le } from "./schema.js";
|
|
6
|
+
import { ChartRenderer as je } from "./renderers/chart.js";
|
|
7
|
+
import { TimelineRenderer as Ue } from "./renderers/timeline.js";
|
|
8
|
+
import { CodeRenderer as Be } from "./renderers/code.js";
|
|
9
|
+
import { DocumentRenderer as Fe } from "./renderers/document.js";
|
|
10
|
+
import { R as Z } from "./RendererFrame-w1obQvoH.js";
|
|
11
|
+
import { default as He } from "./renderers/media.js";
|
|
12
|
+
import { default as Qe } from "./renderers/artifact.js";
|
|
13
|
+
import { default as qe } from "./renderers/knowledge-graph.js";
|
|
14
|
+
import { default as Ze } from "./renderers/map.js";
|
|
15
|
+
import { useStore as I } from "zustand";
|
|
16
|
+
const g = {
|
|
17
|
+
colors: {
|
|
18
|
+
background: "#ffffff",
|
|
19
|
+
surface: "#f8fafc",
|
|
20
|
+
primary: "#0ea5e9",
|
|
21
|
+
secondary: "#6366f1",
|
|
22
|
+
text: "#0f172a",
|
|
23
|
+
muted: "#64748b",
|
|
24
|
+
border: "#e2e8f0",
|
|
25
|
+
highlight: "#f1f5f9"
|
|
26
|
+
},
|
|
27
|
+
spacing: {
|
|
28
|
+
xs: "4px",
|
|
29
|
+
sm: "8px",
|
|
30
|
+
md: "16px",
|
|
31
|
+
lg: "24px",
|
|
32
|
+
xl: "32px"
|
|
33
|
+
},
|
|
34
|
+
typography: {
|
|
35
|
+
font: "Inter, system-ui, -apple-system, sans-serif",
|
|
36
|
+
sizes: {
|
|
37
|
+
xs: "12px",
|
|
38
|
+
sm: "14px",
|
|
39
|
+
md: "16px",
|
|
40
|
+
lg: "18px",
|
|
41
|
+
xl: "20px"
|
|
42
|
+
},
|
|
43
|
+
weights: {
|
|
44
|
+
normal: 400,
|
|
45
|
+
medium: 500,
|
|
46
|
+
bold: 700
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
borderRadius: {
|
|
50
|
+
sm: "4px",
|
|
51
|
+
md: "8px",
|
|
52
|
+
lg: "12px",
|
|
53
|
+
xl: "16px"
|
|
54
|
+
},
|
|
55
|
+
shadows: {
|
|
56
|
+
sm: "0 1px 2px rgba(0, 0, 0, 0.05)",
|
|
57
|
+
md: "0 4px 6px rgba(0, 0, 0, 0.1)",
|
|
58
|
+
lg: "0 10px 15px rgba(0, 0, 0, 0.1)"
|
|
59
|
+
}
|
|
60
|
+
}, pe = {
|
|
61
|
+
...g,
|
|
62
|
+
colors: {
|
|
63
|
+
...g.colors,
|
|
64
|
+
background: "#ffffff",
|
|
65
|
+
surface: "#f8fafc",
|
|
66
|
+
text: "#0f172a",
|
|
67
|
+
muted: "#64748b",
|
|
68
|
+
border: "#e2e8f0",
|
|
69
|
+
highlight: "#f1f5f9"
|
|
70
|
+
}
|
|
71
|
+
}, me = {
|
|
72
|
+
...g,
|
|
73
|
+
colors: {
|
|
74
|
+
...g.colors,
|
|
75
|
+
background: "#0f172a",
|
|
76
|
+
surface: "#1e293b",
|
|
77
|
+
text: "#f8fafc",
|
|
78
|
+
muted: "#94a3b8",
|
|
79
|
+
border: "#334155",
|
|
80
|
+
highlight: "#1e293b"
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
function ee(s) {
|
|
84
|
+
return s.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
85
|
+
}
|
|
86
|
+
function he(s) {
|
|
87
|
+
return s.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
88
|
+
}
|
|
89
|
+
function j(s) {
|
|
90
|
+
if (s === "" || s === "/") return s === "/" ? [""] : [];
|
|
91
|
+
if (!s.startsWith("/"))
|
|
92
|
+
throw new Error(`Invalid JSON Pointer: "${s}" (must start with /)`);
|
|
93
|
+
return s.slice(1).split("/").map(ee);
|
|
94
|
+
}
|
|
95
|
+
function $(s, t) {
|
|
96
|
+
if (t === "") return s;
|
|
97
|
+
const e = j(t);
|
|
98
|
+
let r = s;
|
|
99
|
+
for (const n of e) {
|
|
100
|
+
if (r == null) return;
|
|
101
|
+
if (Array.isArray(r)) {
|
|
102
|
+
const o = n === "-" ? r.length : parseInt(n, 10);
|
|
103
|
+
if (isNaN(o) || o < 0 || o >= r.length) return;
|
|
104
|
+
r = r[o];
|
|
105
|
+
} else if (typeof r == "object")
|
|
106
|
+
r = r[n];
|
|
107
|
+
else
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
return r;
|
|
111
|
+
}
|
|
112
|
+
function z(s, t, e) {
|
|
113
|
+
if (t === "") return e;
|
|
114
|
+
const r = j(t), n = structuredClone(s ?? {});
|
|
115
|
+
let o = n;
|
|
116
|
+
for (let c = 0; c < r.length - 1; c++) {
|
|
117
|
+
const a = r[c], u = o[a];
|
|
118
|
+
if (u == null || typeof u != "object") {
|
|
119
|
+
const d = r[c + 1], p = /^\d+$/.test(d) || d === "-";
|
|
120
|
+
o[a] = p ? [] : {};
|
|
121
|
+
}
|
|
122
|
+
o = o[a];
|
|
123
|
+
}
|
|
124
|
+
const i = r[r.length - 1];
|
|
125
|
+
return Array.isArray(o) && i === "-" ? o.push(e) : o[i] = e, n;
|
|
126
|
+
}
|
|
127
|
+
function te(s, t, e) {
|
|
128
|
+
const r = $(s, t), n = Array.isArray(r) ? [...r, ...e] : e;
|
|
129
|
+
return z(s, t, n);
|
|
130
|
+
}
|
|
131
|
+
const W = {
|
|
132
|
+
surfaces: {},
|
|
133
|
+
activeSurfaceId: null
|
|
134
|
+
};
|
|
135
|
+
function U(s, t) {
|
|
136
|
+
const e = { ...s };
|
|
137
|
+
for (const r of Object.keys(t)) {
|
|
138
|
+
const n = t[r];
|
|
139
|
+
n === null ? delete e[r] : typeof n == "object" && !Array.isArray(n) && typeof e[r] == "object" && !Array.isArray(e[r]) ? e[r] = U(e[r], n) : e[r] = n;
|
|
140
|
+
}
|
|
141
|
+
return e;
|
|
142
|
+
}
|
|
143
|
+
function _() {
|
|
144
|
+
return V((s, t) => ({
|
|
145
|
+
...W,
|
|
146
|
+
processMessage(e) {
|
|
147
|
+
const r = q(e), n = Date.now();
|
|
148
|
+
switch (r) {
|
|
149
|
+
case "createSurface": {
|
|
150
|
+
const { surfaceId: o, catalogId: i, title: c, metadata: a } = e.createSurface;
|
|
151
|
+
s((u) => ({
|
|
152
|
+
surfaces: {
|
|
153
|
+
...u.surfaces,
|
|
154
|
+
[o]: {
|
|
155
|
+
surfaceId: o,
|
|
156
|
+
catalogId: i,
|
|
157
|
+
title: c,
|
|
158
|
+
metadata: a,
|
|
159
|
+
dataModel: {},
|
|
160
|
+
components: [],
|
|
161
|
+
createdAt: n,
|
|
162
|
+
updatedAt: n
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
activeSurfaceId: u.activeSurfaceId ?? o
|
|
166
|
+
}));
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case "destroySurface": {
|
|
170
|
+
const { surfaceId: o } = e.destroySurface;
|
|
171
|
+
s((i) => {
|
|
172
|
+
const { [o]: c, ...a } = i.surfaces;
|
|
173
|
+
return {
|
|
174
|
+
surfaces: a,
|
|
175
|
+
activeSurfaceId: i.activeSurfaceId === o ? null : i.activeSurfaceId
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case "updateDataModel": {
|
|
181
|
+
const { surfaceId: o, path: i, value: c } = e.updateDataModel;
|
|
182
|
+
s((a) => {
|
|
183
|
+
const u = a.surfaces[o];
|
|
184
|
+
return u ? {
|
|
185
|
+
surfaces: {
|
|
186
|
+
...a.surfaces,
|
|
187
|
+
[o]: {
|
|
188
|
+
...u,
|
|
189
|
+
dataModel: z(u.dataModel, i, c),
|
|
190
|
+
updatedAt: n
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} : a;
|
|
194
|
+
});
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "updateComponents": {
|
|
198
|
+
const { surfaceId: o, components: i } = e.updateComponents;
|
|
199
|
+
s((c) => {
|
|
200
|
+
const a = c.surfaces[o];
|
|
201
|
+
if (!a) return c;
|
|
202
|
+
const u = new Map(a.components.map((d) => [d.id, d]));
|
|
203
|
+
for (const d of i)
|
|
204
|
+
u.set(d.id, d);
|
|
205
|
+
return {
|
|
206
|
+
surfaces: {
|
|
207
|
+
...c.surfaces,
|
|
208
|
+
[o]: {
|
|
209
|
+
...a,
|
|
210
|
+
components: Array.from(u.values()),
|
|
211
|
+
updatedAt: n
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case "removeComponents": {
|
|
219
|
+
const { surfaceId: o, componentIds: i } = e.removeComponents;
|
|
220
|
+
s((c) => {
|
|
221
|
+
const a = c.surfaces[o];
|
|
222
|
+
if (!a) return c;
|
|
223
|
+
const u = new Set(i);
|
|
224
|
+
return {
|
|
225
|
+
surfaces: {
|
|
226
|
+
...c.surfaces,
|
|
227
|
+
[o]: {
|
|
228
|
+
...a,
|
|
229
|
+
components: a.components.filter((d) => !u.has(d.id)),
|
|
230
|
+
updatedAt: n
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case "appendData": {
|
|
238
|
+
const { surfaceId: o, path: i, items: c } = e.appendData;
|
|
239
|
+
s((a) => {
|
|
240
|
+
const u = a.surfaces[o];
|
|
241
|
+
return u ? {
|
|
242
|
+
surfaces: {
|
|
243
|
+
...a.surfaces,
|
|
244
|
+
[o]: {
|
|
245
|
+
...u,
|
|
246
|
+
dataModel: te(u.dataModel, i, c),
|
|
247
|
+
updatedAt: n
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} : a;
|
|
251
|
+
});
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case "patchDataModel": {
|
|
255
|
+
const { surfaceId: o, patch: i } = e.patchDataModel;
|
|
256
|
+
s((c) => {
|
|
257
|
+
const a = c.surfaces[o];
|
|
258
|
+
return a ? {
|
|
259
|
+
surfaces: {
|
|
260
|
+
...c.surfaces,
|
|
261
|
+
[o]: {
|
|
262
|
+
...a,
|
|
263
|
+
dataModel: U(a.dataModel, i),
|
|
264
|
+
updatedAt: n
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} : c;
|
|
268
|
+
});
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
processMessages(e) {
|
|
274
|
+
for (const r of e)
|
|
275
|
+
t().processMessage(r);
|
|
276
|
+
},
|
|
277
|
+
getSurface(e) {
|
|
278
|
+
return t().surfaces[e];
|
|
279
|
+
},
|
|
280
|
+
resolveData(e, r) {
|
|
281
|
+
const n = t().surfaces[e];
|
|
282
|
+
if (n)
|
|
283
|
+
return $(n.dataModel, r);
|
|
284
|
+
},
|
|
285
|
+
setActiveSurface(e) {
|
|
286
|
+
s({ activeSurfaceId: e });
|
|
287
|
+
},
|
|
288
|
+
getSurfaceIds() {
|
|
289
|
+
return Object.keys(t().surfaces);
|
|
290
|
+
},
|
|
291
|
+
reset() {
|
|
292
|
+
s(W);
|
|
293
|
+
}
|
|
294
|
+
}));
|
|
295
|
+
}
|
|
296
|
+
class re {
|
|
297
|
+
renderers = /* @__PURE__ */ new Map();
|
|
298
|
+
customRenderers = /* @__PURE__ */ new Map();
|
|
299
|
+
/** Register a built-in renderer (lazy-loaded) */
|
|
300
|
+
register(t, e) {
|
|
301
|
+
this.renderers.set(t, { factory: e });
|
|
302
|
+
}
|
|
303
|
+
/** Register a custom renderer by key */
|
|
304
|
+
registerCustom(t, e) {
|
|
305
|
+
this.customRenderers.set(t, { factory: e });
|
|
306
|
+
}
|
|
307
|
+
/** Register a custom renderer with an already-resolved component */
|
|
308
|
+
registerCustomSync(t, e) {
|
|
309
|
+
this.customRenderers.set(t, {
|
|
310
|
+
factory: async () => ({ default: e }),
|
|
311
|
+
resolved: e
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/** Get the renderer for a component type (lazy loads on first access) */
|
|
315
|
+
async resolve(t, e) {
|
|
316
|
+
if (t === "Custom" && e) {
|
|
317
|
+
const o = this.customRenderers.get(e);
|
|
318
|
+
if (!o) return null;
|
|
319
|
+
if (o.resolved) return o.resolved;
|
|
320
|
+
const i = await o.factory();
|
|
321
|
+
return o.resolved = i.default, o.resolved;
|
|
322
|
+
}
|
|
323
|
+
const r = this.renderers.get(t);
|
|
324
|
+
if (!r) return null;
|
|
325
|
+
if (r.resolved) return r.resolved;
|
|
326
|
+
const n = await r.factory();
|
|
327
|
+
return r.resolved = n.default, r.resolved;
|
|
328
|
+
}
|
|
329
|
+
/** Check if a component type has a registered renderer */
|
|
330
|
+
has(t) {
|
|
331
|
+
return this.renderers.has(t);
|
|
332
|
+
}
|
|
333
|
+
/** Check if a custom renderer key is registered */
|
|
334
|
+
hasCustom(t) {
|
|
335
|
+
return this.customRenderers.has(t);
|
|
336
|
+
}
|
|
337
|
+
/** Get all registered component types */
|
|
338
|
+
getRegisteredTypes() {
|
|
339
|
+
return Array.from(this.renderers.keys());
|
|
340
|
+
}
|
|
341
|
+
/** Get all registered custom renderer keys */
|
|
342
|
+
getCustomKeys() {
|
|
343
|
+
return Array.from(this.customRenderers.keys());
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function se() {
|
|
347
|
+
const s = new re();
|
|
348
|
+
return s.register("Chart", () => import("./renderers/chart.js")), s.register("Timeline", () => import("./renderers/timeline.js")), s.register("KnowledgeGraph", () => import("./renderers/knowledge-graph.js")), s.register("Map", () => import("./renderers/map.js")), s.register("Media", () => import("./renderers/media.js")), s.register("Document", () => import("./renderers/document.js")), s.register("Code", () => import("./renderers/code.js")), s.register("Artifact", () => import("./renderers/artifact.js")), s.register("Custom", () => Promise.resolve().then(() => oe)), s;
|
|
349
|
+
}
|
|
350
|
+
const B = Y(void 0), ge = ({
|
|
351
|
+
children: s,
|
|
352
|
+
initialTheme: t = g,
|
|
353
|
+
initialThemeMode: e = "light",
|
|
354
|
+
initialContent: r,
|
|
355
|
+
surfaceStore: n,
|
|
356
|
+
registry: o
|
|
357
|
+
}) => {
|
|
358
|
+
const [i, c] = S(t), [a, u] = S(e), [d, p] = S(r || null), [m, h] = S("side-by-side"), [v, C] = S(0.4), k = D(n ?? _()), M = D(o ?? se());
|
|
359
|
+
A(() => {
|
|
360
|
+
const y = () => {
|
|
361
|
+
const T = a === "dark" || a === "system" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
362
|
+
c(T ? {
|
|
363
|
+
...g,
|
|
364
|
+
colors: {
|
|
365
|
+
...g.colors,
|
|
366
|
+
background: "#0f172a",
|
|
367
|
+
surface: "#1e293b",
|
|
368
|
+
text: "#f8fafc",
|
|
369
|
+
muted: "#94a3b8",
|
|
370
|
+
border: "#334155",
|
|
371
|
+
highlight: "#1e293b"
|
|
372
|
+
}
|
|
373
|
+
} : {
|
|
374
|
+
...g,
|
|
375
|
+
colors: {
|
|
376
|
+
...g.colors,
|
|
377
|
+
background: "#ffffff",
|
|
378
|
+
surface: "#f8fafc",
|
|
379
|
+
text: "#0f172a",
|
|
380
|
+
muted: "#64748b",
|
|
381
|
+
border: "#e2e8f0",
|
|
382
|
+
highlight: "#f1f5f9"
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
if (y(), a === "system") {
|
|
387
|
+
const T = window.matchMedia("(prefers-color-scheme: dark)"), O = () => y();
|
|
388
|
+
return T.addEventListener("change", O), () => T.removeEventListener("change", O);
|
|
389
|
+
}
|
|
390
|
+
}, [a]);
|
|
391
|
+
const E = (y) => {
|
|
392
|
+
p(y);
|
|
393
|
+
}, f = (y) => {
|
|
394
|
+
h(y);
|
|
395
|
+
}, b = (y) => {
|
|
396
|
+
C(y);
|
|
397
|
+
}, x = R(() => ({
|
|
398
|
+
theme: i,
|
|
399
|
+
setTheme: c,
|
|
400
|
+
themeMode: a,
|
|
401
|
+
setThemeMode: u,
|
|
402
|
+
content: d,
|
|
403
|
+
setCanvasContent: E,
|
|
404
|
+
layout: m,
|
|
405
|
+
setCanvasLayout: f,
|
|
406
|
+
widthRatio: v,
|
|
407
|
+
setCanvasWidthRatio: b,
|
|
408
|
+
surfaceStore: k.current,
|
|
409
|
+
registry: M.current
|
|
410
|
+
}), [i, a, d, m, v]);
|
|
411
|
+
return /* @__PURE__ */ l(B.Provider, { value: x, children: s });
|
|
412
|
+
}, K = () => {
|
|
413
|
+
const s = Q(B);
|
|
414
|
+
if (s === void 0)
|
|
415
|
+
throw new Error("useCanvas must be used within a CanvasProvider");
|
|
416
|
+
return s;
|
|
417
|
+
}, be = () => {
|
|
418
|
+
const { content: s, setCanvasContent: t } = K();
|
|
419
|
+
return { content: s, setContent: t };
|
|
420
|
+
}, ye = () => {
|
|
421
|
+
const { layout: s, widthRatio: t, setCanvasLayout: e, setCanvasWidthRatio: r } = K();
|
|
422
|
+
return { layout: s, widthRatio: t, setLayout: e, setWidthRatio: r };
|
|
423
|
+
}, ve = ({
|
|
424
|
+
children: s,
|
|
425
|
+
theme: t,
|
|
426
|
+
className: e = ""
|
|
427
|
+
}) => {
|
|
428
|
+
const r = {
|
|
429
|
+
container: `
|
|
430
|
+
w-full h-full
|
|
431
|
+
bg-[${t.colors.background}]
|
|
432
|
+
border-[${t.colors.border}]
|
|
433
|
+
rounded-xl
|
|
434
|
+
overflow-hidden
|
|
435
|
+
${e}
|
|
436
|
+
`,
|
|
437
|
+
header: `
|
|
438
|
+
px-6 py-4
|
|
439
|
+
border-b-[1px]
|
|
440
|
+
border-[${t.colors.border}]
|
|
441
|
+
bg-[${t.colors.surface}]
|
|
442
|
+
`,
|
|
443
|
+
toolbar: `
|
|
444
|
+
flex items-center justify-between
|
|
445
|
+
px-6 py-3
|
|
446
|
+
border-b-[1px]
|
|
447
|
+
border-[${t.colors.border}]
|
|
448
|
+
bg-[${t.colors.surface}]
|
|
449
|
+
`
|
|
450
|
+
};
|
|
451
|
+
return /* @__PURE__ */ l("div", { className: r.container, children: s });
|
|
452
|
+
}, xe = ({
|
|
453
|
+
title: s,
|
|
454
|
+
description: t,
|
|
455
|
+
theme: e
|
|
456
|
+
}) => /* @__PURE__ */ N("div", { className: `
|
|
457
|
+
px-6 py-4
|
|
458
|
+
border-b-[1px]
|
|
459
|
+
border-[${e.colors.border}]
|
|
460
|
+
bg-[${e.colors.surface}]
|
|
461
|
+
`, children: [
|
|
462
|
+
s && /* @__PURE__ */ l("h2", { className: `text-xl font-bold text-[${e.colors.text}] mb-1`, children: s }),
|
|
463
|
+
t && /* @__PURE__ */ l("p", { className: `text-sm text-[${e.colors.muted}]`, children: t })
|
|
464
|
+
] }), Se = ({
|
|
465
|
+
children: s,
|
|
466
|
+
theme: t
|
|
467
|
+
}) => /* @__PURE__ */ l("div", { className: `
|
|
468
|
+
flex-1
|
|
469
|
+
overflow-y-auto
|
|
470
|
+
p-6
|
|
471
|
+
bg-[${t.colors.background}]
|
|
472
|
+
`, children: s }), Ce = ({
|
|
473
|
+
children: s,
|
|
474
|
+
theme: t
|
|
475
|
+
}) => /* @__PURE__ */ l("div", { className: `
|
|
476
|
+
flex items-center justify-between
|
|
477
|
+
px-6 py-3
|
|
478
|
+
border-b-[1px]
|
|
479
|
+
border-[${t.colors.border}]
|
|
480
|
+
bg-[${t.colors.surface}]
|
|
481
|
+
`, children: s }), J = ({
|
|
482
|
+
component: s,
|
|
483
|
+
data: t,
|
|
484
|
+
theme: e,
|
|
485
|
+
content: r
|
|
486
|
+
}) => {
|
|
487
|
+
const n = e?.colors?.text ?? "inherit";
|
|
488
|
+
if (r?.component) {
|
|
489
|
+
const i = r.component;
|
|
490
|
+
return /* @__PURE__ */ l("div", { className: "custom-renderer", style: { color: n }, children: /* @__PURE__ */ l(i, { ...r.props ?? {} }) });
|
|
491
|
+
}
|
|
492
|
+
const o = s?.title;
|
|
493
|
+
return /* @__PURE__ */ l(Z, { title: o, children: /* @__PURE__ */ l("div", { style: { padding: "16px", color: n }, children: t ? /* @__PURE__ */ l("pre", { style: { fontSize: "13px", margin: 0, whiteSpace: "pre-wrap" }, children: typeof t == "string" ? t : JSON.stringify(t, null, 2) }) : /* @__PURE__ */ N("p", { style: { opacity: 0.5 }, children: [
|
|
494
|
+
"Custom component: ",
|
|
495
|
+
s?.rendererKey ?? "unknown"
|
|
496
|
+
] }) }) });
|
|
497
|
+
}, oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
498
|
+
__proto__: null,
|
|
499
|
+
CustomRenderer: J,
|
|
500
|
+
default: J
|
|
501
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
502
|
+
class we {
|
|
503
|
+
/**
|
|
504
|
+
* Detect the content type from a string
|
|
505
|
+
*/
|
|
506
|
+
static detectType(t) {
|
|
507
|
+
const e = t.trim();
|
|
508
|
+
return e.includes("```") || /[\n\s]*\w+\s*=\s*\{/.test(e) ? "code" : e.includes("#") || e.includes("##") ? "document" : /\d{4}-\d{2}-\d{2}/.test(e) ? "timeline" : /\d+\s*%|\[\s*\d+\s*,\s*\d+\s*\]/.test(e) ? "chart" : "custom";
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Extract chart data from content
|
|
512
|
+
*/
|
|
513
|
+
static extractChartData(t) {
|
|
514
|
+
const e = t.match(/-?\d+(\.\d+)?/g);
|
|
515
|
+
if (!e) return null;
|
|
516
|
+
const r = e.map(Number), n = r.slice(0, Math.ceil(r.length / 2)), o = r.slice(Math.ceil(r.length / 2));
|
|
517
|
+
return {
|
|
518
|
+
labels: n,
|
|
519
|
+
values: o
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Extract timeline events from content
|
|
524
|
+
*/
|
|
525
|
+
static extractTimelineEvents(t) {
|
|
526
|
+
const e = t.split(`
|
|
527
|
+
`), r = [];
|
|
528
|
+
return e.forEach((n) => {
|
|
529
|
+
const o = n.match(/(\d{4}-\d{2}-\d{2})/);
|
|
530
|
+
o && r.push({
|
|
531
|
+
date: o[1],
|
|
532
|
+
title: n.replace(o[0], "").trim(),
|
|
533
|
+
description: ""
|
|
534
|
+
});
|
|
535
|
+
}), r.length > 0 ? r : null;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Extract code from content
|
|
539
|
+
*/
|
|
540
|
+
static extractCode(t) {
|
|
541
|
+
const e = t.match(/```(\w+)?\n([\s\S]*?)```/);
|
|
542
|
+
return e ? {
|
|
543
|
+
code: e[2],
|
|
544
|
+
language: e[1] || "text"
|
|
545
|
+
} : null;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Analyze content and return appropriate content object (legacy)
|
|
549
|
+
*/
|
|
550
|
+
static analyze(t) {
|
|
551
|
+
switch (this.detectType(t)) {
|
|
552
|
+
case "chart":
|
|
553
|
+
return {
|
|
554
|
+
type: "chart",
|
|
555
|
+
data: this.extractChartData(t) || { labels: [], values: [] }
|
|
556
|
+
};
|
|
557
|
+
case "timeline":
|
|
558
|
+
return {
|
|
559
|
+
type: "timeline",
|
|
560
|
+
events: this.extractTimelineEvents(t) || []
|
|
561
|
+
};
|
|
562
|
+
case "code": {
|
|
563
|
+
const r = this.extractCode(t);
|
|
564
|
+
return {
|
|
565
|
+
type: "code",
|
|
566
|
+
code: r?.code || t,
|
|
567
|
+
language: r?.language || "text"
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
case "document":
|
|
571
|
+
return {
|
|
572
|
+
type: "document",
|
|
573
|
+
content: t
|
|
574
|
+
};
|
|
575
|
+
default:
|
|
576
|
+
return {
|
|
577
|
+
type: "custom",
|
|
578
|
+
data: t
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Analyze content and emit A2UI messages for a surface
|
|
584
|
+
*/
|
|
585
|
+
static toA2UIMessages(t, e = "s1") {
|
|
586
|
+
const r = this.detectType(t), n = [
|
|
587
|
+
{ createSurface: { surfaceId: e, catalogId: "dynamic-canvas/v1" } }
|
|
588
|
+
];
|
|
589
|
+
switch (r) {
|
|
590
|
+
case "chart": {
|
|
591
|
+
const o = this.extractChartData(t);
|
|
592
|
+
n.push({
|
|
593
|
+
updateDataModel: {
|
|
594
|
+
surfaceId: e,
|
|
595
|
+
path: "/chart/data",
|
|
596
|
+
value: (o?.labels ?? []).map((i, c) => ({
|
|
597
|
+
label: String(i),
|
|
598
|
+
value: o?.values[c] ?? 0
|
|
599
|
+
}))
|
|
600
|
+
}
|
|
601
|
+
}), n.push({
|
|
602
|
+
updateComponents: {
|
|
603
|
+
surfaceId: e,
|
|
604
|
+
components: [{
|
|
605
|
+
id: "chart-1",
|
|
606
|
+
component: "Chart",
|
|
607
|
+
chartType: "bar",
|
|
608
|
+
data: "/chart/data"
|
|
609
|
+
}]
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
case "timeline": {
|
|
615
|
+
const o = this.extractTimelineEvents(t);
|
|
616
|
+
n.push({
|
|
617
|
+
updateDataModel: {
|
|
618
|
+
surfaceId: e,
|
|
619
|
+
path: "/timeline/events",
|
|
620
|
+
value: o ?? []
|
|
621
|
+
}
|
|
622
|
+
}), n.push({
|
|
623
|
+
updateComponents: {
|
|
624
|
+
surfaceId: e,
|
|
625
|
+
components: [{
|
|
626
|
+
id: "timeline-1",
|
|
627
|
+
component: "Timeline",
|
|
628
|
+
events: "/timeline/events"
|
|
629
|
+
}]
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
case "code": {
|
|
635
|
+
const o = this.extractCode(t);
|
|
636
|
+
n.push({
|
|
637
|
+
updateComponents: {
|
|
638
|
+
surfaceId: e,
|
|
639
|
+
components: [{
|
|
640
|
+
id: "code-1",
|
|
641
|
+
component: "Code",
|
|
642
|
+
code: o?.code ?? t,
|
|
643
|
+
language: o?.language ?? "text"
|
|
644
|
+
}]
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
break;
|
|
648
|
+
}
|
|
649
|
+
case "document": {
|
|
650
|
+
n.push({
|
|
651
|
+
updateComponents: {
|
|
652
|
+
surfaceId: e,
|
|
653
|
+
components: [{
|
|
654
|
+
id: "doc-1",
|
|
655
|
+
component: "Document",
|
|
656
|
+
content: t,
|
|
657
|
+
format: "markdown"
|
|
658
|
+
}]
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
663
|
+
default:
|
|
664
|
+
n.push({
|
|
665
|
+
updateComponents: {
|
|
666
|
+
surfaceId: e,
|
|
667
|
+
components: [{
|
|
668
|
+
id: "custom-1",
|
|
669
|
+
component: "Custom",
|
|
670
|
+
rendererKey: "default",
|
|
671
|
+
props: { content: t }
|
|
672
|
+
}]
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
return n;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function ke(s, t = "s1") {
|
|
680
|
+
const e = [
|
|
681
|
+
{ createSurface: { surfaceId: t, catalogId: "dynamic-canvas/v1" } }
|
|
682
|
+
];
|
|
683
|
+
switch (s.type) {
|
|
684
|
+
case "chart": {
|
|
685
|
+
const r = s.data;
|
|
686
|
+
if (r?.labels && r?.values) {
|
|
687
|
+
const n = r.labels.map((o, i) => ({
|
|
688
|
+
label: o,
|
|
689
|
+
value: r.values[i] ?? 0
|
|
690
|
+
}));
|
|
691
|
+
e.push({ updateDataModel: { surfaceId: t, path: "/chart/data", value: n } }), e.push({
|
|
692
|
+
updateComponents: {
|
|
693
|
+
surfaceId: t,
|
|
694
|
+
components: [{
|
|
695
|
+
id: "chart-1",
|
|
696
|
+
component: "Chart",
|
|
697
|
+
chartType: s.chartType ?? "bar",
|
|
698
|
+
data: "/chart/data",
|
|
699
|
+
title: s.title,
|
|
700
|
+
colors: s.options?.colors
|
|
701
|
+
}]
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
case "timeline": {
|
|
708
|
+
e.push({ updateDataModel: { surfaceId: t, path: "/timeline/events", value: s.events ?? [] } }), e.push({
|
|
709
|
+
updateComponents: {
|
|
710
|
+
surfaceId: t,
|
|
711
|
+
components: [{
|
|
712
|
+
id: "timeline-1",
|
|
713
|
+
component: "Timeline",
|
|
714
|
+
events: "/timeline/events",
|
|
715
|
+
title: s.title,
|
|
716
|
+
orientation: s.options?.orientation
|
|
717
|
+
}]
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
case "code": {
|
|
723
|
+
e.push({
|
|
724
|
+
updateComponents: {
|
|
725
|
+
surfaceId: t,
|
|
726
|
+
components: [{
|
|
727
|
+
id: "code-1",
|
|
728
|
+
component: "Code",
|
|
729
|
+
code: s.code ?? "",
|
|
730
|
+
language: s.language ?? "text",
|
|
731
|
+
filename: s.filename,
|
|
732
|
+
title: s.title
|
|
733
|
+
}]
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
case "document": {
|
|
739
|
+
e.push({
|
|
740
|
+
updateComponents: {
|
|
741
|
+
surfaceId: t,
|
|
742
|
+
components: [{
|
|
743
|
+
id: "doc-1",
|
|
744
|
+
component: "Document",
|
|
745
|
+
content: s.content ?? "",
|
|
746
|
+
format: s.format ?? "markdown",
|
|
747
|
+
title: s.title
|
|
748
|
+
}]
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
default:
|
|
754
|
+
e.push({
|
|
755
|
+
updateComponents: {
|
|
756
|
+
surfaceId: t,
|
|
757
|
+
components: [{
|
|
758
|
+
id: "custom-1",
|
|
759
|
+
component: "Custom",
|
|
760
|
+
rendererKey: "default",
|
|
761
|
+
props: s.props ?? { data: s.data }
|
|
762
|
+
}]
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
return e;
|
|
767
|
+
}
|
|
768
|
+
class ne {
|
|
769
|
+
onMessage;
|
|
770
|
+
onError;
|
|
771
|
+
batchWindow;
|
|
772
|
+
batchBuffer = [];
|
|
773
|
+
batchTimer = null;
|
|
774
|
+
abortController = null;
|
|
775
|
+
constructor(t) {
|
|
776
|
+
this.onMessage = t.onMessage, this.onError = t.onError ?? (() => {
|
|
777
|
+
}), this.batchWindow = t.batchWindow ?? 0;
|
|
778
|
+
}
|
|
779
|
+
/** Process a single parsed JSON object */
|
|
780
|
+
processJSON(t) {
|
|
781
|
+
if (Array.isArray(t)) {
|
|
782
|
+
for (const e of t)
|
|
783
|
+
this.processJSON(e);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
X(t) ? this.emit(t) : this.onError(new Error(`Invalid A2UI message: ${JSON.stringify(t).slice(0, 200)}`));
|
|
787
|
+
}
|
|
788
|
+
/** Process a JSONL string (newline-delimited JSON) */
|
|
789
|
+
processJSONL(t) {
|
|
790
|
+
const e = t.split(`
|
|
791
|
+
`);
|
|
792
|
+
for (const r of e) {
|
|
793
|
+
const n = r.trim();
|
|
794
|
+
if (n)
|
|
795
|
+
try {
|
|
796
|
+
const o = JSON.parse(n);
|
|
797
|
+
this.processJSON(o);
|
|
798
|
+
} catch {
|
|
799
|
+
this.onError(new Error(`Failed to parse JSONL line: ${n.slice(0, 100)}`));
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
/** Connect to an SSE endpoint (EventSource-compatible) */
|
|
804
|
+
connectSSE(t) {
|
|
805
|
+
const e = new EventSource(t);
|
|
806
|
+
return e.onmessage = (r) => {
|
|
807
|
+
try {
|
|
808
|
+
const n = JSON.parse(r.data);
|
|
809
|
+
this.processJSON(n);
|
|
810
|
+
} catch {
|
|
811
|
+
this.onError(new Error(`Failed to parse SSE data: ${r.data.slice(0, 100)}`));
|
|
812
|
+
}
|
|
813
|
+
}, e.onerror = () => {
|
|
814
|
+
this.onError(new Error("SSE connection error"));
|
|
815
|
+
}, () => e.close();
|
|
816
|
+
}
|
|
817
|
+
/** Connect to a fetch-based SSE stream (ReadableStream) */
|
|
818
|
+
async connectStream(t, e) {
|
|
819
|
+
this.abortController = new AbortController();
|
|
820
|
+
const r = this.abortController.signal;
|
|
821
|
+
try {
|
|
822
|
+
const n = await fetch(t, { ...e, signal: r });
|
|
823
|
+
if (!n.ok)
|
|
824
|
+
throw new Error(`HTTP ${n.status}: ${n.statusText}`);
|
|
825
|
+
if (!n.body)
|
|
826
|
+
throw new Error("Response has no body");
|
|
827
|
+
const o = n.body.getReader(), i = new TextDecoder();
|
|
828
|
+
let c = "";
|
|
829
|
+
(async () => {
|
|
830
|
+
for (; ; ) {
|
|
831
|
+
const { done: u, value: d } = await o.read();
|
|
832
|
+
if (u) break;
|
|
833
|
+
c += i.decode(d, { stream: !0 });
|
|
834
|
+
const p = c.split(`
|
|
835
|
+
`);
|
|
836
|
+
c = p.pop() ?? "";
|
|
837
|
+
for (const m of p) {
|
|
838
|
+
const h = m.trim();
|
|
839
|
+
if (!h) continue;
|
|
840
|
+
const v = h.startsWith("data: ") ? h.slice(6) : h;
|
|
841
|
+
try {
|
|
842
|
+
const C = JSON.parse(v);
|
|
843
|
+
this.processJSON(C);
|
|
844
|
+
} catch {
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (c.trim())
|
|
849
|
+
try {
|
|
850
|
+
const u = JSON.parse(c.trim());
|
|
851
|
+
this.processJSON(u);
|
|
852
|
+
} catch {
|
|
853
|
+
}
|
|
854
|
+
})().catch((u) => {
|
|
855
|
+
r.aborted || this.onError(u instanceof Error ? u : new Error(String(u)));
|
|
856
|
+
});
|
|
857
|
+
} catch (n) {
|
|
858
|
+
r.aborted || this.onError(n instanceof Error ? n : new Error(String(n)));
|
|
859
|
+
}
|
|
860
|
+
return () => this.abortController?.abort();
|
|
861
|
+
}
|
|
862
|
+
/** Connect to a WebSocket */
|
|
863
|
+
connectWebSocket(t) {
|
|
864
|
+
const e = new WebSocket(t);
|
|
865
|
+
return e.onmessage = (r) => {
|
|
866
|
+
try {
|
|
867
|
+
const n = JSON.parse(r.data);
|
|
868
|
+
this.processJSON(n);
|
|
869
|
+
} catch {
|
|
870
|
+
this.onError(new Error("Failed to parse WebSocket message"));
|
|
871
|
+
}
|
|
872
|
+
}, e.onerror = () => {
|
|
873
|
+
this.onError(new Error("WebSocket error"));
|
|
874
|
+
}, () => e.close();
|
|
875
|
+
}
|
|
876
|
+
/** Flush any batched messages */
|
|
877
|
+
flush() {
|
|
878
|
+
if (this.batchBuffer.length > 0) {
|
|
879
|
+
const t = this.batchBuffer;
|
|
880
|
+
this.batchBuffer = [];
|
|
881
|
+
for (const e of t)
|
|
882
|
+
this.onMessage(e);
|
|
883
|
+
}
|
|
884
|
+
this.batchTimer !== null && (clearTimeout(this.batchTimer), this.batchTimer = null);
|
|
885
|
+
}
|
|
886
|
+
/** Destroy the processor and clean up */
|
|
887
|
+
destroy() {
|
|
888
|
+
this.flush(), this.abortController?.abort();
|
|
889
|
+
}
|
|
890
|
+
emit(t) {
|
|
891
|
+
if (this.batchWindow <= 0) {
|
|
892
|
+
this.onMessage(t);
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
this.batchBuffer.push(t), this.batchTimer === null && (this.batchTimer = setTimeout(() => {
|
|
896
|
+
this.flush();
|
|
897
|
+
}, this.batchWindow));
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
class F extends H.Component {
|
|
901
|
+
constructor(t) {
|
|
902
|
+
super(t), this.state = { hasError: !1, error: null };
|
|
903
|
+
}
|
|
904
|
+
static getDerivedStateFromError(t) {
|
|
905
|
+
return { hasError: !0, error: t };
|
|
906
|
+
}
|
|
907
|
+
componentDidCatch(t, e) {
|
|
908
|
+
this.props.onError?.(t, e);
|
|
909
|
+
}
|
|
910
|
+
render() {
|
|
911
|
+
return this.state.hasError ? this.props.fallback ? this.props.fallback : /* @__PURE__ */ N("div", { style: { padding: "16px", color: "#ef4444", fontSize: "14px", border: "1px solid #fca5a5", borderRadius: "8px", background: "#fef2f2" }, children: [
|
|
912
|
+
/* @__PURE__ */ l("strong", { children: "Renderer Error" }),
|
|
913
|
+
/* @__PURE__ */ l("p", { style: { margin: "8px 0 0", opacity: 0.8 }, children: this.state.error?.message })
|
|
914
|
+
] }) : this.props.children;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const L = () => /* @__PURE__ */ l("div", { style: { padding: "16px", opacity: 0.5, fontSize: "14px" }, children: "Loading renderer..." }), Me = ({
|
|
918
|
+
component: s,
|
|
919
|
+
data: t,
|
|
920
|
+
registry: e,
|
|
921
|
+
theme: r,
|
|
922
|
+
onError: n,
|
|
923
|
+
loadingFallback: o
|
|
924
|
+
}) => {
|
|
925
|
+
const [i, c] = S(null), [a, u] = S(null);
|
|
926
|
+
return A(() => {
|
|
927
|
+
let d = !1;
|
|
928
|
+
const p = s.component === "Custom" ? s.rendererKey : void 0;
|
|
929
|
+
return e.resolve(s.component, p).then((m) => {
|
|
930
|
+
d || (m ? c(() => m) : u(new Error(`No renderer found for component type: ${s.component}${p ? ` (key: ${p})` : ""}`)));
|
|
931
|
+
}).catch((m) => {
|
|
932
|
+
d || u(m instanceof Error ? m : new Error(String(m)));
|
|
933
|
+
}), () => {
|
|
934
|
+
d = !0;
|
|
935
|
+
};
|
|
936
|
+
}, [s.component, e]), a ? /* @__PURE__ */ l("div", { style: { padding: "16px", color: "#ef4444", fontSize: "14px" }, children: a.message }) : i ? /* @__PURE__ */ l(F, { onError: n, children: /* @__PURE__ */ l(P, { fallback: o ?? /* @__PURE__ */ l(L, {}), children: /* @__PURE__ */ l(i, { component: s, data: t, theme: r }) }) }) : /* @__PURE__ */ l(G, { children: o ?? /* @__PURE__ */ l(L, {}) });
|
|
937
|
+
};
|
|
938
|
+
function Ee(s = {}) {
|
|
939
|
+
const {
|
|
940
|
+
sseUrl: t,
|
|
941
|
+
wsUrl: e,
|
|
942
|
+
streamUrl: r,
|
|
943
|
+
streamInit: n,
|
|
944
|
+
messages: o,
|
|
945
|
+
batchWindow: i = 50,
|
|
946
|
+
onError: c,
|
|
947
|
+
store: a
|
|
948
|
+
} = s, d = D(a ?? _()).current, p = I(d, (f) => f.surfaces), m = I(d, (f) => f.activeSurfaceId);
|
|
949
|
+
A(() => {
|
|
950
|
+
o && o.length > 0 && d.getState().processMessages(o);
|
|
951
|
+
}, [o, d]), A(() => {
|
|
952
|
+
const f = new ne({
|
|
953
|
+
onMessage: (x) => d.getState().processMessage(x),
|
|
954
|
+
onError: c,
|
|
955
|
+
batchWindow: i
|
|
956
|
+
}), b = [];
|
|
957
|
+
return t && b.push(f.connectSSE(t)), e && b.push(f.connectWebSocket(e)), r && f.connectStream(r, n).then((x) => {
|
|
958
|
+
b.push(x);
|
|
959
|
+
}), () => {
|
|
960
|
+
f.destroy();
|
|
961
|
+
for (const x of b) x();
|
|
962
|
+
};
|
|
963
|
+
}, [t, e, r, i, d, c, n]);
|
|
964
|
+
const h = m ? p[m] : void 0, v = w(
|
|
965
|
+
(f) => d.getState().setActiveSurface(f),
|
|
966
|
+
[d]
|
|
967
|
+
), C = w(
|
|
968
|
+
(f) => d.getState().processMessage(f),
|
|
969
|
+
[d]
|
|
970
|
+
), k = w(
|
|
971
|
+
(f) => d.getState().processMessages(f),
|
|
972
|
+
[d]
|
|
973
|
+
), M = w(
|
|
974
|
+
(f, b) => d.getState().resolveData(f, b),
|
|
975
|
+
[d]
|
|
976
|
+
), E = w(
|
|
977
|
+
(f) => d.getState().getSurface(f)?.components ?? [],
|
|
978
|
+
[d]
|
|
979
|
+
);
|
|
980
|
+
return R(() => ({
|
|
981
|
+
surfaces: p,
|
|
982
|
+
activeSurface: h,
|
|
983
|
+
setActiveSurface: v,
|
|
984
|
+
processMessage: C,
|
|
985
|
+
processMessages: k,
|
|
986
|
+
resolveData: M,
|
|
987
|
+
getComponents: E,
|
|
988
|
+
store: d
|
|
989
|
+
}), [p, h, v, C, k, M, E, d]);
|
|
990
|
+
}
|
|
991
|
+
function Te(s) {
|
|
992
|
+
const { store: t, surfaceId: e } = s, r = I(t, (a) => a.surfaces[e]), n = r?.components ?? [], o = r?.dataModel ?? {}, i = r?.updatedAt ?? 0, c = R(
|
|
993
|
+
() => (a) => $(o, a),
|
|
994
|
+
[o]
|
|
995
|
+
);
|
|
996
|
+
return R(() => ({
|
|
997
|
+
surface: r,
|
|
998
|
+
components: n,
|
|
999
|
+
dataModel: o,
|
|
1000
|
+
resolveData: c,
|
|
1001
|
+
updatedAt: i
|
|
1002
|
+
}), [r, n, o, c, i]);
|
|
1003
|
+
}
|
|
1004
|
+
const ae = () => /* @__PURE__ */ N("div", { style: {
|
|
1005
|
+
padding: "24px",
|
|
1006
|
+
display: "flex",
|
|
1007
|
+
alignItems: "center",
|
|
1008
|
+
justifyContent: "center",
|
|
1009
|
+
opacity: 0.4,
|
|
1010
|
+
fontSize: "14px",
|
|
1011
|
+
minHeight: "100px"
|
|
1012
|
+
}, children: [
|
|
1013
|
+
/* @__PURE__ */ l("div", { style: {
|
|
1014
|
+
width: "20px",
|
|
1015
|
+
height: "20px",
|
|
1016
|
+
border: "2px solid currentColor",
|
|
1017
|
+
borderTopColor: "transparent",
|
|
1018
|
+
borderRadius: "50%",
|
|
1019
|
+
animation: "spin 0.8s linear infinite",
|
|
1020
|
+
marginRight: "8px"
|
|
1021
|
+
} }),
|
|
1022
|
+
"Loading...",
|
|
1023
|
+
/* @__PURE__ */ l("style", { children: "@keyframes spin { to { transform: rotate(360deg); } }" })
|
|
1024
|
+
] }), Ae = ({
|
|
1025
|
+
children: s,
|
|
1026
|
+
fallback: t,
|
|
1027
|
+
onError: e
|
|
1028
|
+
}) => /* @__PURE__ */ l(F, { onError: e ? (r) => e(r) : void 0, children: /* @__PURE__ */ l(P, { fallback: t ?? /* @__PURE__ */ l(ae, {}), children: s }) });
|
|
1029
|
+
function Re(s, t) {
|
|
1030
|
+
let e = null;
|
|
1031
|
+
const r = (...n) => {
|
|
1032
|
+
e !== null && clearTimeout(e), e = setTimeout(() => {
|
|
1033
|
+
e = null, s(...n);
|
|
1034
|
+
}, t);
|
|
1035
|
+
};
|
|
1036
|
+
return r.cancel = () => {
|
|
1037
|
+
e !== null && (clearTimeout(e), e = null);
|
|
1038
|
+
}, r;
|
|
1039
|
+
}
|
|
1040
|
+
function Ne(s, t) {
|
|
1041
|
+
let e = [], r = null;
|
|
1042
|
+
return (n) => {
|
|
1043
|
+
e.push(n), r === null && (r = setTimeout(() => {
|
|
1044
|
+
const o = e;
|
|
1045
|
+
e = [], r = null, s(o);
|
|
1046
|
+
}, t));
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
export {
|
|
1050
|
+
$e as A2UI_COMPONENT_TYPES,
|
|
1051
|
+
Qe as ArtifactRenderer,
|
|
1052
|
+
ve as CanvasContainer,
|
|
1053
|
+
Se as CanvasContent,
|
|
1054
|
+
xe as CanvasHeader,
|
|
1055
|
+
ge as CanvasProvider,
|
|
1056
|
+
Ce as CanvasToolbar,
|
|
1057
|
+
je as ChartRenderer,
|
|
1058
|
+
Be as CodeRenderer,
|
|
1059
|
+
re as ComponentRegistry,
|
|
1060
|
+
we as ContentAnalyzer,
|
|
1061
|
+
J as CustomRenderer,
|
|
1062
|
+
Oe as DYNAMIC_CANVAS_CATALOG,
|
|
1063
|
+
Fe as DocumentRenderer,
|
|
1064
|
+
F as ErrorBoundary,
|
|
1065
|
+
qe as KnowledgeGraphRenderer,
|
|
1066
|
+
Ae as LazyWrapper,
|
|
1067
|
+
Ze as MapRenderer,
|
|
1068
|
+
He as MediaRenderer,
|
|
1069
|
+
Z as RendererFrame,
|
|
1070
|
+
Me as RendererResolver,
|
|
1071
|
+
ne as StreamProcessor,
|
|
1072
|
+
Ue as TimelineRenderer,
|
|
1073
|
+
te as appendAtPointer,
|
|
1074
|
+
Ne as batchCalls,
|
|
1075
|
+
ke as canvasContentToA2UI,
|
|
1076
|
+
se as createDefaultRegistry,
|
|
1077
|
+
_ as createSurfaceManager,
|
|
1078
|
+
me as darkTheme,
|
|
1079
|
+
Re as debounce,
|
|
1080
|
+
g as defaultTheme,
|
|
1081
|
+
he as escapeToken,
|
|
1082
|
+
q as getMessageType,
|
|
1083
|
+
We as isA2UIComponent,
|
|
1084
|
+
X as isA2UIMessage,
|
|
1085
|
+
pe as lightTheme,
|
|
1086
|
+
j as parsePointer,
|
|
1087
|
+
$ as resolvePointer,
|
|
1088
|
+
z as setPointer,
|
|
1089
|
+
Ee as useA2UISurface,
|
|
1090
|
+
K as useCanvas,
|
|
1091
|
+
be as useCanvasContent,
|
|
1092
|
+
ye as useCanvasLayout,
|
|
1093
|
+
Te as useStreamingContent,
|
|
1094
|
+
Je as validateComponent,
|
|
1095
|
+
Le as validateMessage
|
|
1096
|
+
};
|