@aigentyc/chat-sdk 0.1.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.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/dist/JsonRenderResult-Ftw4AKwb.d.cts +18 -0
  4. package/dist/JsonRenderResult-Ftw4AKwb.d.ts +18 -0
  5. package/dist/JsonRenderResult-GQOYPLVH.cjs +15 -0
  6. package/dist/JsonRenderResult-GQOYPLVH.cjs.map +1 -0
  7. package/dist/JsonRenderResult-ZFJ6VWMS.js +6 -0
  8. package/dist/JsonRenderResult-ZFJ6VWMS.js.map +1 -0
  9. package/dist/SlotsContext-CBtt36al.d.ts +148 -0
  10. package/dist/SlotsContext-CHvISDJT.d.cts +148 -0
  11. package/dist/VisualizationRenderer-FNFYNN66.js +5 -0
  12. package/dist/VisualizationRenderer-FNFYNN66.js.map +1 -0
  13. package/dist/VisualizationRenderer-VKMZXRUX.cjs +20 -0
  14. package/dist/VisualizationRenderer-VKMZXRUX.cjs.map +1 -0
  15. package/dist/ai-elements.cjs +4608 -0
  16. package/dist/ai-elements.cjs.map +1 -0
  17. package/dist/ai-elements.d.cts +897 -0
  18. package/dist/ai-elements.d.ts +897 -0
  19. package/dist/ai-elements.js +4363 -0
  20. package/dist/ai-elements.js.map +1 -0
  21. package/dist/chunk-3MP2EGEJ.cjs +270 -0
  22. package/dist/chunk-3MP2EGEJ.cjs.map +1 -0
  23. package/dist/chunk-3RW7O444.js +26 -0
  24. package/dist/chunk-3RW7O444.js.map +1 -0
  25. package/dist/chunk-42ARGQXE.js +51 -0
  26. package/dist/chunk-42ARGQXE.js.map +1 -0
  27. package/dist/chunk-4FBVV64J.js +257 -0
  28. package/dist/chunk-4FBVV64J.js.map +1 -0
  29. package/dist/chunk-4QT25AXI.js +21 -0
  30. package/dist/chunk-4QT25AXI.js.map +1 -0
  31. package/dist/chunk-525KS5HM.cjs +30 -0
  32. package/dist/chunk-525KS5HM.cjs.map +1 -0
  33. package/dist/chunk-5F3O3ZJH.js +299 -0
  34. package/dist/chunk-5F3O3ZJH.js.map +1 -0
  35. package/dist/chunk-5QSXB6UL.cjs +259 -0
  36. package/dist/chunk-5QSXB6UL.cjs.map +1 -0
  37. package/dist/chunk-5T4FJ2SR.js +664 -0
  38. package/dist/chunk-5T4FJ2SR.js.map +1 -0
  39. package/dist/chunk-7BNYTOTE.cjs +67 -0
  40. package/dist/chunk-7BNYTOTE.cjs.map +1 -0
  41. package/dist/chunk-AWAJOSFP.cjs +96 -0
  42. package/dist/chunk-AWAJOSFP.cjs.map +1 -0
  43. package/dist/chunk-BKDV2H6Z.js +224 -0
  44. package/dist/chunk-BKDV2H6Z.js.map +1 -0
  45. package/dist/chunk-FQN6OBGN.cjs +171 -0
  46. package/dist/chunk-FQN6OBGN.cjs.map +1 -0
  47. package/dist/chunk-FYPJSHCL.js +190 -0
  48. package/dist/chunk-FYPJSHCL.js.map +1 -0
  49. package/dist/chunk-J2H6MLQF.cjs +680 -0
  50. package/dist/chunk-J2H6MLQF.cjs.map +1 -0
  51. package/dist/chunk-J2K7EJYP.cjs +198 -0
  52. package/dist/chunk-J2K7EJYP.cjs.map +1 -0
  53. package/dist/chunk-JI5KCSOI.cjs +23 -0
  54. package/dist/chunk-JI5KCSOI.cjs.map +1 -0
  55. package/dist/chunk-JOO6C3XT.cjs +44 -0
  56. package/dist/chunk-JOO6C3XT.cjs.map +1 -0
  57. package/dist/chunk-KBGPBUTI.cjs +78 -0
  58. package/dist/chunk-KBGPBUTI.cjs.map +1 -0
  59. package/dist/chunk-MT2AMINB.js +75 -0
  60. package/dist/chunk-MT2AMINB.js.map +1 -0
  61. package/dist/chunk-MZQKGNWF.js +4 -0
  62. package/dist/chunk-MZQKGNWF.js.map +1 -0
  63. package/dist/chunk-NG7OTWXQ.cjs +226 -0
  64. package/dist/chunk-NG7OTWXQ.cjs.map +1 -0
  65. package/dist/chunk-NPJKLYLV.js +68 -0
  66. package/dist/chunk-NPJKLYLV.js.map +1 -0
  67. package/dist/chunk-NW2ESHRV.js +685 -0
  68. package/dist/chunk-NW2ESHRV.js.map +1 -0
  69. package/dist/chunk-NWF735F5.js +1631 -0
  70. package/dist/chunk-NWF735F5.js.map +1 -0
  71. package/dist/chunk-NYQSM3EB.cjs +305 -0
  72. package/dist/chunk-NYQSM3EB.cjs.map +1 -0
  73. package/dist/chunk-OU7OROOE.cjs +1643 -0
  74. package/dist/chunk-OU7OROOE.cjs.map +1 -0
  75. package/dist/chunk-PS3U7T37.js +42 -0
  76. package/dist/chunk-PS3U7T37.js.map +1 -0
  77. package/dist/chunk-Q7T3VAJV.cjs +687 -0
  78. package/dist/chunk-Q7T3VAJV.cjs.map +1 -0
  79. package/dist/chunk-QYCEHFAB.js +265 -0
  80. package/dist/chunk-QYCEHFAB.js.map +1 -0
  81. package/dist/chunk-RPDJXB3U.js +676 -0
  82. package/dist/chunk-RPDJXB3U.js.map +1 -0
  83. package/dist/chunk-UKEL7FWS.js +64 -0
  84. package/dist/chunk-UKEL7FWS.js.map +1 -0
  85. package/dist/chunk-VS3NZ7FX.js +164 -0
  86. package/dist/chunk-VS3NZ7FX.js.map +1 -0
  87. package/dist/chunk-WZLWAVSS.cjs +73 -0
  88. package/dist/chunk-WZLWAVSS.cjs.map +1 -0
  89. package/dist/chunk-X5YEOOPK.cjs +758 -0
  90. package/dist/chunk-X5YEOOPK.cjs.map +1 -0
  91. package/dist/chunk-X7R334SB.cjs +5 -0
  92. package/dist/chunk-X7R334SB.cjs.map +1 -0
  93. package/dist/chunk-XXNDL5SJ.cjs +432 -0
  94. package/dist/chunk-XXNDL5SJ.cjs.map +1 -0
  95. package/dist/chunk-YQELMJW5.js +429 -0
  96. package/dist/chunk-YQELMJW5.js.map +1 -0
  97. package/dist/components.cjs +551 -0
  98. package/dist/components.cjs.map +1 -0
  99. package/dist/components.d.cts +181 -0
  100. package/dist/components.d.ts +181 -0
  101. package/dist/components.js +483 -0
  102. package/dist/components.js.map +1 -0
  103. package/dist/core.cjs +283 -0
  104. package/dist/core.cjs.map +1 -0
  105. package/dist/core.d.cts +455 -0
  106. package/dist/core.d.ts +455 -0
  107. package/dist/core.js +241 -0
  108. package/dist/core.js.map +1 -0
  109. package/dist/hooks.cjs +324 -0
  110. package/dist/hooks.cjs.map +1 -0
  111. package/dist/hooks.d.cts +163 -0
  112. package/dist/hooks.d.ts +163 -0
  113. package/dist/hooks.js +277 -0
  114. package/dist/hooks.js.map +1 -0
  115. package/dist/i18n.cjs +26 -0
  116. package/dist/i18n.cjs.map +1 -0
  117. package/dist/i18n.d.cts +50 -0
  118. package/dist/i18n.d.ts +50 -0
  119. package/dist/i18n.js +5 -0
  120. package/dist/i18n.js.map +1 -0
  121. package/dist/index.cjs +466 -0
  122. package/dist/index.cjs.map +1 -0
  123. package/dist/index.d.cts +80 -0
  124. package/dist/index.d.ts +80 -0
  125. package/dist/index.js +438 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/interaction-tracker-D9P1Oq4j.d.cts +83 -0
  128. package/dist/interaction-tracker-D9P1Oq4j.d.ts +83 -0
  129. package/dist/json-render.cjs +23 -0
  130. package/dist/json-render.cjs.map +1 -0
  131. package/dist/json-render.d.cts +857 -0
  132. package/dist/json-render.d.ts +857 -0
  133. package/dist/json-render.js +6 -0
  134. package/dist/json-render.js.map +1 -0
  135. package/dist/live-chat-transport-4XLOIPOE.js +4 -0
  136. package/dist/live-chat-transport-4XLOIPOE.js.map +1 -0
  137. package/dist/live-chat-transport-ALVRGWX7.cjs +13 -0
  138. package/dist/live-chat-transport-ALVRGWX7.cjs.map +1 -0
  139. package/dist/select-B4l9yoyn.d.cts +99 -0
  140. package/dist/select-B4l9yoyn.d.ts +99 -0
  141. package/dist/styles.css +2 -0
  142. package/dist/theme.cjs +18 -0
  143. package/dist/theme.cjs.map +1 -0
  144. package/dist/theme.d.cts +55 -0
  145. package/dist/theme.d.ts +55 -0
  146. package/dist/theme.js +5 -0
  147. package/dist/theme.js.map +1 -0
  148. package/dist/tools.cjs +32 -0
  149. package/dist/tools.cjs.map +1 -0
  150. package/dist/tools.d.cts +117 -0
  151. package/dist/tools.d.ts +117 -0
  152. package/dist/tools.js +11 -0
  153. package/dist/tools.js.map +1 -0
  154. package/dist/types-DKJ_-nbG.d.cts +349 -0
  155. package/dist/types-DKJ_-nbG.d.ts +349 -0
  156. package/dist/ui.cjs +667 -0
  157. package/dist/ui.cjs.map +1 -0
  158. package/dist/ui.d.cts +95 -0
  159. package/dist/ui.d.ts +95 -0
  160. package/dist/ui.js +414 -0
  161. package/dist/ui.js.map +1 -0
  162. package/package.json +255 -0
@@ -0,0 +1,676 @@
1
+ "use client";
2
+ import { VisualizationRenderer } from './chunk-5T4FJ2SR.js';
3
+ import { defineRegistry, JSONUIProvider, Renderer, useStateValue, useValidation } from '@json-render/react';
4
+ import { useMemo, useRef, useCallback, useEffect } from 'react';
5
+ import { shadcnComponents } from '@json-render/shadcn';
6
+ import { defineCatalog } from '@json-render/core';
7
+ import { schema } from '@json-render/react/schema';
8
+ import { shadcnComponentDefinitions } from '@json-render/shadcn/catalog';
9
+ import { z } from 'zod';
10
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
+
12
+ var seriesSchema = z.object({
13
+ dataKey: z.string(),
14
+ label: z.string(),
15
+ color: z.string().nullable().optional(),
16
+ type: z.enum(["line", "bar", "area"]).nullable().optional()
17
+ });
18
+ var chartConfigSchema = z.object({
19
+ xAxis: z.string().nullable().optional(),
20
+ series: z.array(seriesSchema),
21
+ showGrid: z.boolean().nullable().optional(),
22
+ showLegend: z.boolean().nullable().optional(),
23
+ stacked: z.boolean().nullable().optional(),
24
+ valueFormatter: z.enum(["currency", "percent", "number", "compact"]).nullable().optional()
25
+ });
26
+ var chartBaseProps = {
27
+ title: z.string().nullable().optional(),
28
+ description: z.string().nullable().optional(),
29
+ data: z.array(z.record(z.string(), z.unknown())),
30
+ config: chartConfigSchema,
31
+ height: z.number().nullable().optional()
32
+ };
33
+ var catalog = defineCatalog(schema, {
34
+ components: {
35
+ // ── Layout ──────────────────────────────────────────────
36
+ Card: shadcnComponentDefinitions.Card,
37
+ Stack: shadcnComponentDefinitions.Stack,
38
+ Grid: shadcnComponentDefinitions.Grid,
39
+ Separator: shadcnComponentDefinitions.Separator,
40
+ Tabs: shadcnComponentDefinitions.Tabs,
41
+ Accordion: shadcnComponentDefinitions.Accordion,
42
+ Collapsible: shadcnComponentDefinitions.Collapsible,
43
+ Dialog: shadcnComponentDefinitions.Dialog,
44
+ Drawer: shadcnComponentDefinitions.Drawer,
45
+ Carousel: shadcnComponentDefinitions.Carousel,
46
+ // ── Typography ──────────────────────────────────────────
47
+ Heading: shadcnComponentDefinitions.Heading,
48
+ Text: shadcnComponentDefinitions.Text,
49
+ Badge: shadcnComponentDefinitions.Badge,
50
+ Link: shadcnComponentDefinitions.Link,
51
+ Alert: shadcnComponentDefinitions.Alert,
52
+ // ── Media ───────────────────────────────────────────────
53
+ Image: shadcnComponentDefinitions.Image,
54
+ Avatar: shadcnComponentDefinitions.Avatar,
55
+ // ── Data ────────────────────────────────────────────────
56
+ Table: shadcnComponentDefinitions.Table,
57
+ // ── Charts & Visualization ────────────────────────────
58
+ LineChart: {
59
+ props: z.object(chartBaseProps),
60
+ description: "Line chart for trends over time. Provide data array + config.xAxis + config.series.",
61
+ example: {
62
+ title: "Monthly Sales",
63
+ data: [{ month: "Jan", sales: 100 }, { month: "Feb", sales: 150 }],
64
+ config: { xAxis: "month", series: [{ dataKey: "sales", label: "Sales" }] }
65
+ }
66
+ },
67
+ BarChart: {
68
+ props: z.object(chartBaseProps),
69
+ description: "Bar chart for comparing categories. Provide data array + config.xAxis + config.series.",
70
+ example: {
71
+ title: "Product Comparison",
72
+ data: [{ product: "A", revenue: 500 }, { product: "B", revenue: 300 }],
73
+ config: { xAxis: "product", series: [{ dataKey: "revenue", label: "Revenue" }] }
74
+ }
75
+ },
76
+ PieChart: {
77
+ props: z.object({
78
+ title: z.string().nullable().optional(),
79
+ description: z.string().nullable().optional(),
80
+ data: z.array(z.record(z.string(), z.unknown())),
81
+ dataKey: z.string(),
82
+ nameKey: z.string().nullable().optional(),
83
+ height: z.number().nullable().optional()
84
+ }),
85
+ description: "Pie chart for proportional breakdown. Each data item needs a name and a value field.",
86
+ example: {
87
+ title: "Market Share",
88
+ data: [{ name: "Product A", value: 60 }, { name: "Product B", value: 40 }],
89
+ dataKey: "value",
90
+ nameKey: "name"
91
+ }
92
+ },
93
+ AreaChart: {
94
+ props: z.object(chartBaseProps),
95
+ description: "Area chart for cumulative values over time with gradient fills.",
96
+ example: {
97
+ title: "Traffic Volume",
98
+ data: [{ day: "Mon", visits: 200 }, { day: "Tue", visits: 350 }],
99
+ config: { xAxis: "day", series: [{ dataKey: "visits", label: "Visits" }] }
100
+ }
101
+ },
102
+ MetricCards: {
103
+ props: z.object({
104
+ title: z.string().nullable().optional(),
105
+ metrics: z.array(
106
+ z.object({
107
+ label: z.string(),
108
+ value: z.string(),
109
+ unit: z.string().nullable().optional(),
110
+ trend: z.string().nullable().optional(),
111
+ trendDirection: z.enum(["up", "down", "neutral"]).nullable().optional(),
112
+ description: z.string().nullable().optional()
113
+ })
114
+ )
115
+ }),
116
+ description: "KPI metric cards grid with big numbers and optional trend indicators.",
117
+ example: {
118
+ metrics: [
119
+ { label: "Revenue", value: "$1.2M", trend: "+12%", trendDirection: "up" },
120
+ { label: "Users", value: "45K", trend: "-3%", trendDirection: "down" }
121
+ ]
122
+ }
123
+ },
124
+ ComparisonTable: {
125
+ props: z.object({
126
+ title: z.string().nullable().optional(),
127
+ items: z.array(
128
+ z.object({
129
+ name: z.string(),
130
+ highlight: z.boolean().nullable().optional(),
131
+ features: z.record(z.string(), z.union([z.string(), z.boolean(), z.number()]))
132
+ })
133
+ ),
134
+ fields: z.array(
135
+ z.object({
136
+ key: z.string(),
137
+ label: z.string(),
138
+ type: z.enum(["text", "boolean", "rating"]).nullable().optional()
139
+ })
140
+ )
141
+ }),
142
+ description: "Side-by-side comparison table. Items are columns, fields are rows.",
143
+ example: {
144
+ title: "Plan Comparison",
145
+ items: [
146
+ { name: "Basic", features: { price: "$9/mo", storage: "10GB", support: true } },
147
+ { name: "Pro", highlight: true, features: { price: "$29/mo", storage: "100GB", support: true } }
148
+ ],
149
+ fields: [
150
+ { key: "price", label: "Price", type: "text" },
151
+ { key: "storage", label: "Storage", type: "text" },
152
+ { key: "support", label: "Support", type: "boolean" }
153
+ ]
154
+ }
155
+ },
156
+ Timeline: {
157
+ props: z.object({
158
+ title: z.string().nullable().optional(),
159
+ events: z.array(
160
+ z.object({
161
+ date: z.string().nullable().optional(),
162
+ title: z.string(),
163
+ description: z.string().nullable().optional(),
164
+ status: z.enum(["completed", "current", "upcoming"]).nullable().optional()
165
+ })
166
+ )
167
+ }),
168
+ description: "Vertical timeline for chronological events or process steps.",
169
+ example: {
170
+ events: [
171
+ { title: "Order Placed", date: "Jan 1", status: "completed" },
172
+ { title: "Shipped", date: "Jan 3", status: "current" },
173
+ { title: "Delivered", status: "upcoming" }
174
+ ]
175
+ }
176
+ },
177
+ ProgressBars: {
178
+ props: z.object({
179
+ title: z.string().nullable().optional(),
180
+ goals: z.array(
181
+ z.object({
182
+ label: z.string(),
183
+ current: z.number(),
184
+ target: z.number(),
185
+ unit: z.string().nullable().optional()
186
+ })
187
+ )
188
+ }),
189
+ description: "Progress bars for goal tracking with current/target values.",
190
+ example: {
191
+ goals: [
192
+ { label: "Revenue", current: 75e3, target: 1e5, unit: "$" },
193
+ { label: "Users", current: 800, target: 1e3 }
194
+ ]
195
+ }
196
+ },
197
+ // ── Form ────────────────────────────────────────────────
198
+ Input: shadcnComponentDefinitions.Input,
199
+ Textarea: shadcnComponentDefinitions.Textarea,
200
+ Select: shadcnComponentDefinitions.Select,
201
+ Checkbox: shadcnComponentDefinitions.Checkbox,
202
+ Radio: shadcnComponentDefinitions.Radio,
203
+ Switch: shadcnComponentDefinitions.Switch,
204
+ Slider: shadcnComponentDefinitions.Slider,
205
+ Button: shadcnComponentDefinitions.Button,
206
+ ButtonGroup: shadcnComponentDefinitions.ButtonGroup,
207
+ Toggle: shadcnComponentDefinitions.Toggle,
208
+ ToggleGroup: shadcnComponentDefinitions.ToggleGroup,
209
+ DropdownMenu: shadcnComponentDefinitions.DropdownMenu,
210
+ // ── Feedback ────────────────────────────────────────────
211
+ Progress: shadcnComponentDefinitions.Progress,
212
+ Spinner: shadcnComponentDefinitions.Spinner,
213
+ Skeleton: shadcnComponentDefinitions.Skeleton,
214
+ Tooltip: shadcnComponentDefinitions.Tooltip,
215
+ Popover: shadcnComponentDefinitions.Popover,
216
+ // ── Navigation ──────────────────────────────────────────
217
+ Pagination: shadcnComponentDefinitions.Pagination
218
+ },
219
+ actions: {
220
+ navigate_url: {
221
+ params: z.object({
222
+ url: z.string(),
223
+ target: z.enum(["_self", "_blank"]).default("_blank")
224
+ }),
225
+ description: "Open a URL in a new tab or the current tab."
226
+ },
227
+ send_message: {
228
+ params: z.object({
229
+ message: z.string()
230
+ }),
231
+ description: "Send a follow-up chat message on behalf of the user."
232
+ },
233
+ call_api: {
234
+ params: z.object({
235
+ endpoint: z.string(),
236
+ method: z.enum(["GET", "POST", "PUT", "DELETE"]).default("POST"),
237
+ body: z.record(z.string(), z.unknown()).optional()
238
+ }),
239
+ description: "Make a proxied API call through the platform backend."
240
+ }
241
+ }
242
+ });
243
+ var { registry, handlers: createActionHandlers } = defineRegistry(
244
+ catalog,
245
+ {
246
+ components: {
247
+ // ── Layout ──────────────────────────────────────────────
248
+ Card: (p) => /* @__PURE__ */ jsx("div", { className: "w-full [&>div]:border-0 [&>div]:shadow-none", children: shadcnComponents.Card(p) }),
249
+ Stack: shadcnComponents.Stack,
250
+ Grid: shadcnComponents.Grid,
251
+ Separator: shadcnComponents.Separator,
252
+ Tabs: shadcnComponents.Tabs,
253
+ Accordion: shadcnComponents.Accordion,
254
+ Collapsible: shadcnComponents.Collapsible,
255
+ Dialog: shadcnComponents.Dialog,
256
+ Drawer: shadcnComponents.Drawer,
257
+ Carousel: shadcnComponents.Carousel,
258
+ // ── Typography ──────────────────────────────────────────
259
+ Heading: shadcnComponents.Heading,
260
+ Text: shadcnComponents.Text,
261
+ Badge: shadcnComponents.Badge,
262
+ Link: shadcnComponents.Link,
263
+ Alert: shadcnComponents.Alert,
264
+ // ── Media ───────────────────────────────────────────────
265
+ Image: shadcnComponents.Image,
266
+ Avatar: shadcnComponents.Avatar,
267
+ // ── Data ────────────────────────────────────────────────
268
+ Table: shadcnComponents.Table,
269
+ // ── Charts & Visualization ────────────────────────────
270
+ LineChart: ({ props }) => /* @__PURE__ */ jsx(
271
+ VisualizationRenderer,
272
+ {
273
+ spec: {
274
+ type: "line_chart",
275
+ title: props.title ?? void 0,
276
+ description: props.description ?? void 0,
277
+ data: props.data,
278
+ config: {
279
+ xAxis: props.config?.xAxis ?? void 0,
280
+ series: props.config?.series?.map((s) => ({
281
+ dataKey: s.dataKey,
282
+ label: s.label,
283
+ color: s.color ?? void 0
284
+ })),
285
+ showGrid: props.config?.showGrid ?? void 0,
286
+ showLegend: props.config?.showLegend ?? void 0,
287
+ stacked: props.config?.stacked ?? void 0,
288
+ valueFormatter: props.config?.valueFormatter ?? void 0
289
+ }
290
+ }
291
+ }
292
+ ),
293
+ BarChart: ({ props }) => /* @__PURE__ */ jsx(
294
+ VisualizationRenderer,
295
+ {
296
+ spec: {
297
+ type: "bar_chart",
298
+ title: props.title ?? void 0,
299
+ description: props.description ?? void 0,
300
+ data: props.data,
301
+ config: {
302
+ xAxis: props.config?.xAxis ?? void 0,
303
+ series: props.config?.series?.map((s) => ({
304
+ dataKey: s.dataKey,
305
+ label: s.label,
306
+ color: s.color ?? void 0
307
+ })),
308
+ showGrid: props.config?.showGrid ?? void 0,
309
+ showLegend: props.config?.showLegend ?? void 0,
310
+ stacked: props.config?.stacked ?? void 0,
311
+ valueFormatter: props.config?.valueFormatter ?? void 0
312
+ }
313
+ }
314
+ }
315
+ ),
316
+ PieChart: ({ props }) => /* @__PURE__ */ jsx(
317
+ VisualizationRenderer,
318
+ {
319
+ spec: {
320
+ type: "pie_chart",
321
+ title: props.title ?? void 0,
322
+ description: props.description ?? void 0,
323
+ data: props.data,
324
+ config: {
325
+ series: [{ dataKey: props.dataKey, label: props.dataKey }]
326
+ }
327
+ }
328
+ }
329
+ ),
330
+ AreaChart: ({ props }) => /* @__PURE__ */ jsx(
331
+ VisualizationRenderer,
332
+ {
333
+ spec: {
334
+ type: "area_chart",
335
+ title: props.title ?? void 0,
336
+ description: props.description ?? void 0,
337
+ data: props.data,
338
+ config: {
339
+ xAxis: props.config?.xAxis ?? void 0,
340
+ series: props.config?.series?.map((s) => ({
341
+ dataKey: s.dataKey,
342
+ label: s.label,
343
+ color: s.color ?? void 0
344
+ })),
345
+ showGrid: props.config?.showGrid ?? void 0,
346
+ showLegend: props.config?.showLegend ?? void 0,
347
+ stacked: props.config?.stacked ?? void 0,
348
+ valueFormatter: props.config?.valueFormatter ?? void 0
349
+ }
350
+ }
351
+ }
352
+ ),
353
+ MetricCards: ({ props }) => /* @__PURE__ */ jsx(
354
+ VisualizationRenderer,
355
+ {
356
+ spec: {
357
+ type: "metric_cards",
358
+ title: props.title ?? void 0,
359
+ metrics: props.metrics?.map((m) => ({
360
+ label: m.label,
361
+ value: m.value,
362
+ unit: m.unit ?? void 0,
363
+ trend: m.trend ?? void 0,
364
+ trendDirection: m.trendDirection ?? void 0,
365
+ description: m.description ?? void 0
366
+ }))
367
+ }
368
+ }
369
+ ),
370
+ ComparisonTable: ({ props }) => /* @__PURE__ */ jsx(
371
+ VisualizationRenderer,
372
+ {
373
+ spec: {
374
+ type: "comparison",
375
+ title: props.title ?? void 0,
376
+ items: props.items?.map((item) => ({
377
+ name: item.name,
378
+ highlight: item.highlight ?? void 0,
379
+ features: item.features
380
+ })),
381
+ comparisonFields: props.fields?.map((f) => ({
382
+ key: f.key,
383
+ label: f.label,
384
+ type: f.type ?? void 0
385
+ }))
386
+ }
387
+ }
388
+ ),
389
+ Timeline: ({ props }) => /* @__PURE__ */ jsx(
390
+ VisualizationRenderer,
391
+ {
392
+ spec: {
393
+ type: "timeline",
394
+ title: props.title ?? void 0,
395
+ events: props.events?.map((e) => ({
396
+ date: e.date ?? void 0,
397
+ title: e.title,
398
+ description: e.description ?? void 0,
399
+ status: e.status ?? void 0
400
+ }))
401
+ }
402
+ }
403
+ ),
404
+ ProgressBars: ({ props }) => /* @__PURE__ */ jsx(
405
+ VisualizationRenderer,
406
+ {
407
+ spec: {
408
+ type: "progress",
409
+ title: props.title ?? void 0,
410
+ goals: props.goals?.map((g) => ({
411
+ label: g.label,
412
+ current: g.current,
413
+ target: g.target,
414
+ unit: g.unit ?? void 0
415
+ }))
416
+ }
417
+ }
418
+ ),
419
+ // ── Form (wrapped with w-full for proper layout) ────────
420
+ Input: (p) => /* @__PURE__ */ jsx("div", { className: "w-full", children: shadcnComponents.Input(p) }),
421
+ Textarea: (p) => /* @__PURE__ */ jsx("div", { className: "w-full", children: shadcnComponents.Textarea(p) }),
422
+ Select: (p) => /* @__PURE__ */ jsx("div", { className: "w-full", children: shadcnComponents.Select(p) }),
423
+ Checkbox: shadcnComponents.Checkbox,
424
+ Radio: shadcnComponents.Radio,
425
+ Switch: shadcnComponents.Switch,
426
+ Slider: shadcnComponents.Slider,
427
+ Button: shadcnComponents.Button,
428
+ ButtonGroup: shadcnComponents.ButtonGroup,
429
+ Toggle: shadcnComponents.Toggle,
430
+ ToggleGroup: shadcnComponents.ToggleGroup,
431
+ DropdownMenu: shadcnComponents.DropdownMenu,
432
+ // ── Feedback ────────────────────────────────────────────
433
+ Progress: shadcnComponents.Progress,
434
+ Spinner: shadcnComponents.Spinner,
435
+ Skeleton: shadcnComponents.Skeleton,
436
+ Tooltip: shadcnComponents.Tooltip,
437
+ Popover: shadcnComponents.Popover,
438
+ // ── Navigation ──────────────────────────────────────────
439
+ Pagination: shadcnComponents.Pagination
440
+ },
441
+ actions: {
442
+ navigate_url: async (params) => {
443
+ if (params?.url) {
444
+ window.open(params.url, params.target ?? "_blank");
445
+ }
446
+ },
447
+ send_message: async (params) => {
448
+ console.log("[json-render] send_message action:", params?.message);
449
+ },
450
+ call_api: async (params) => {
451
+ const p = params;
452
+ const url = p?.endpoint || p?.url;
453
+ if (!url) {
454
+ console.warn("[json-render] call_api: missing endpoint/url");
455
+ return;
456
+ }
457
+ const method = (params?.method || "POST").toUpperCase();
458
+ try {
459
+ const res = await fetch(url, {
460
+ method,
461
+ headers: { "Content-Type": "application/json" },
462
+ ...method !== "GET" && params?.body ? { body: JSON.stringify(params.body) } : {}
463
+ });
464
+ const data = await res.json().catch(() => null);
465
+ console.log("[json-render] call_api response:", res.status, data);
466
+ return data;
467
+ } catch (err) {
468
+ console.error("[json-render] call_api error:", err);
469
+ }
470
+ }
471
+ }
472
+ }
473
+ );
474
+ function normalizeSpec(raw) {
475
+ if (typeof raw.root === "string" && raw.elements) {
476
+ return raw;
477
+ }
478
+ const elements = {};
479
+ for (const [key, value] of Object.entries(raw)) {
480
+ if (value && typeof value === "object" && "type" in value) {
481
+ elements[key] = value;
482
+ }
483
+ }
484
+ return { root: "root", elements };
485
+ }
486
+ function extractSpecState(raw) {
487
+ const state = raw.state;
488
+ if (!state || typeof state !== "object") return {};
489
+ const result = {};
490
+ function walk(obj, prefix) {
491
+ for (const [key, value] of Object.entries(obj)) {
492
+ const path = `${prefix}/${key}`;
493
+ result[path] = value;
494
+ if (value && typeof value === "object" && !Array.isArray(value)) {
495
+ walk(value, path);
496
+ }
497
+ }
498
+ }
499
+ walk(state, "");
500
+ return result;
501
+ }
502
+ function deepResolve(value, stateMap) {
503
+ if (value === null || value === void 0) return value;
504
+ if (typeof value === "object" && !Array.isArray(value)) {
505
+ const obj = value;
506
+ if (Object.keys(obj).length === 1 && typeof obj.$state === "string") {
507
+ return stateMap[obj.$state];
508
+ }
509
+ const resolved = {};
510
+ for (const [key, val] of Object.entries(obj)) {
511
+ resolved[key] = deepResolve(val, stateMap);
512
+ }
513
+ return resolved;
514
+ }
515
+ if (Array.isArray(value)) {
516
+ return value.map((item) => deepResolve(item, stateMap));
517
+ }
518
+ return value;
519
+ }
520
+ function JsonRenderResult({
521
+ spec: rawSpec,
522
+ data,
523
+ onSendMessage,
524
+ className,
525
+ conversationMessages,
526
+ apiKey
527
+ }) {
528
+ const rawSpecObj = rawSpec;
529
+ const spec = useMemo(() => normalizeSpec(rawSpecObj), [rawSpecObj]);
530
+ const formConfig = useMemo(
531
+ () => rawSpecObj._formConfig || null,
532
+ [rawSpecObj]
533
+ );
534
+ const initialState = useMemo(() => {
535
+ const specState = extractSpecState(rawSpecObj);
536
+ return {
537
+ "/data": data,
538
+ ...conversationMessages ? { "/conversationMessages": conversationMessages } : {},
539
+ ...specState
540
+ };
541
+ }, [data, rawSpecObj, conversationMessages]);
542
+ const stateRef = useRef(initialState);
543
+ const validateRef = useRef(null);
544
+ const handleStateChange = useCallback(
545
+ (changes) => {
546
+ for (const { path, value } of changes) {
547
+ stateRef.current[path] = value;
548
+ }
549
+ },
550
+ []
551
+ );
552
+ const handlers = useMemo(
553
+ () => ({
554
+ navigate_url: async (params) => {
555
+ if (params?.url) {
556
+ window.open(
557
+ params.url,
558
+ params.target ?? "_blank"
559
+ );
560
+ }
561
+ },
562
+ send_message: async (params) => {
563
+ if (onSendMessage && params?.message && typeof params.message === "string") {
564
+ onSendMessage(params.message);
565
+ }
566
+ },
567
+ call_api: async (params) => {
568
+ if (validateRef.current) {
569
+ const isValid = validateRef.current();
570
+ if (!isValid) {
571
+ throw new Error("Validation failed");
572
+ }
573
+ }
574
+ const resolved = deepResolve(
575
+ params,
576
+ stateRef.current
577
+ );
578
+ const url = resolved?.endpoint || resolved?.url;
579
+ if (!url) {
580
+ throw new Error("Missing endpoint/url in call_api params");
581
+ }
582
+ const method = (resolved?.method || "POST").toUpperCase();
583
+ const headers = {
584
+ "Content-Type": "application/json"
585
+ };
586
+ if (apiKey) {
587
+ headers.Authorization = `Bearer ${apiKey}`;
588
+ }
589
+ const res = await fetch(url, {
590
+ method,
591
+ headers,
592
+ credentials: "include",
593
+ ...method !== "GET" && resolved?.body ? { body: JSON.stringify(resolved.body) } : {}
594
+ });
595
+ if (!res.ok) {
596
+ const errBody = await res.text().catch(() => "");
597
+ throw new Error(
598
+ errBody || `Request failed with status ${res.status}`
599
+ );
600
+ }
601
+ const responseData = await res.json().catch(() => null);
602
+ return responseData;
603
+ }
604
+ }),
605
+ [onSendMessage, apiKey]
606
+ );
607
+ return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsxs(
608
+ JSONUIProvider,
609
+ {
610
+ registry,
611
+ initialState,
612
+ handlers,
613
+ onStateChange: handleStateChange,
614
+ children: [
615
+ /* @__PURE__ */ jsx(ValidationBridge, { validateRef }),
616
+ formConfig ? /* @__PURE__ */ jsx(FormFeedbackWrapper, { formConfig, children: /* @__PURE__ */ jsx(Renderer, { spec, registry }) }) : /* @__PURE__ */ jsx(Renderer, { spec, registry })
617
+ ]
618
+ }
619
+ ) });
620
+ }
621
+ function FormFeedbackWrapper({
622
+ formConfig,
623
+ children
624
+ }) {
625
+ const formSubmitted = useStateValue("/formSubmitted");
626
+ const formError = useStateValue("/formError");
627
+ const isSubmitted = formSubmitted === true;
628
+ const hasError = !!formError && formError !== "" && formError !== false;
629
+ if (isSubmitted && formConfig.hideFormAfter) {
630
+ return /* @__PURE__ */ jsx(
631
+ "div",
632
+ {
633
+ className: "rounded-lg border border-green-200 bg-green-50 p-4 dark:border-green-800 dark:bg-green-950/30",
634
+ role: "alert",
635
+ children: /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-green-800 dark:text-green-200", children: formConfig.successMessage || "Submitted successfully!" })
636
+ }
637
+ );
638
+ }
639
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
640
+ isSubmitted && formConfig.successMessage && /* @__PURE__ */ jsx(
641
+ "div",
642
+ {
643
+ className: "rounded-lg border border-green-200 bg-green-50 p-3 mb-3 dark:border-green-800 dark:bg-green-950/30",
644
+ role: "alert",
645
+ children: /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-green-800 dark:text-green-200", children: formConfig.successMessage })
646
+ }
647
+ ),
648
+ hasError && formConfig.errorMessage && /* @__PURE__ */ jsx(
649
+ "div",
650
+ {
651
+ className: "rounded-lg border border-red-200 bg-red-50 p-3 mb-3 dark:border-red-800 dark:bg-red-950/30",
652
+ role: "alert",
653
+ children: /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-red-800 dark:text-red-200", children: formConfig.errorMessage })
654
+ }
655
+ ),
656
+ children
657
+ ] });
658
+ }
659
+ function ValidationBridge({
660
+ validateRef
661
+ }) {
662
+ const validation = useValidation();
663
+ useEffect(() => {
664
+ if (validation?.validateAll) {
665
+ validateRef.current = () => validation.validateAll();
666
+ }
667
+ return () => {
668
+ validateRef.current = null;
669
+ };
670
+ }, [validation, validateRef]);
671
+ return null;
672
+ }
673
+
674
+ export { JsonRenderResult, catalog, registry };
675
+ //# sourceMappingURL=chunk-RPDJXB3U.js.map
676
+ //# sourceMappingURL=chunk-RPDJXB3U.js.map