@gugacoder/agentic-chat 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.
Files changed (187) hide show
  1. package/dist/components/Chat.d.ts +21 -0
  2. package/dist/components/Chat.js +13 -0
  3. package/dist/components/ErrorNote.d.ts +5 -0
  4. package/dist/components/ErrorNote.js +6 -0
  5. package/dist/components/LazyRender.d.ts +8 -0
  6. package/dist/components/LazyRender.js +22 -0
  7. package/dist/components/Markdown.d.ts +5 -0
  8. package/dist/components/Markdown.js +65 -0
  9. package/dist/components/MessageBubble.d.ts +10 -0
  10. package/dist/components/MessageBubble.js +39 -0
  11. package/dist/components/MessageInput.d.ts +19 -0
  12. package/dist/components/MessageInput.js +214 -0
  13. package/dist/components/MessageList.d.ts +12 -0
  14. package/dist/components/MessageList.js +68 -0
  15. package/dist/components/StreamingIndicator.d.ts +1 -0
  16. package/dist/components/StreamingIndicator.js +9 -0
  17. package/dist/conversations/CollapsibleGroup.d.ts +11 -0
  18. package/dist/conversations/CollapsibleGroup.js +9 -0
  19. package/dist/conversations/ConversationBar.d.ts +27 -0
  20. package/dist/conversations/ConversationBar.js +53 -0
  21. package/dist/conversations/ConversationList.d.ts +33 -0
  22. package/dist/conversations/ConversationList.js +48 -0
  23. package/dist/conversations/ConversationListItem.d.ts +20 -0
  24. package/dist/conversations/ConversationListItem.js +22 -0
  25. package/dist/conversations/DeleteDialog.d.ts +13 -0
  26. package/dist/conversations/DeleteDialog.js +8 -0
  27. package/dist/conversations/RenameDialog.d.ts +15 -0
  28. package/dist/conversations/RenameDialog.js +15 -0
  29. package/dist/conversations/index.d.ts +9 -0
  30. package/dist/conversations/index.js +5 -0
  31. package/dist/conversations/types.d.ts +21 -0
  32. package/dist/conversations/types.js +1 -0
  33. package/dist/conversations/useConversations.d.ts +19 -0
  34. package/dist/conversations/useConversations.js +102 -0
  35. package/dist/conversations/utils.d.ts +8 -0
  36. package/dist/conversations/utils.js +134 -0
  37. package/dist/display/AlertRenderer.d.ts +2 -0
  38. package/dist/display/AlertRenderer.js +13 -0
  39. package/dist/display/CarouselRenderer.d.ts +2 -0
  40. package/dist/display/CarouselRenderer.js +41 -0
  41. package/dist/display/ChartRenderer.d.ts +2 -0
  42. package/dist/display/ChartRenderer.js +76 -0
  43. package/dist/display/ChoiceButtonsRenderer.d.ts +6 -0
  44. package/dist/display/ChoiceButtonsRenderer.js +23 -0
  45. package/dist/display/CodeBlockRenderer.d.ts +2 -0
  46. package/dist/display/CodeBlockRenderer.js +17 -0
  47. package/dist/display/ComparisonTableRenderer.d.ts +2 -0
  48. package/dist/display/ComparisonTableRenderer.js +26 -0
  49. package/dist/display/DataTableRenderer.d.ts +2 -0
  50. package/dist/display/DataTableRenderer.js +74 -0
  51. package/dist/display/FileCardRenderer.d.ts +2 -0
  52. package/dist/display/FileCardRenderer.js +31 -0
  53. package/dist/display/GalleryRenderer.d.ts +2 -0
  54. package/dist/display/GalleryRenderer.js +11 -0
  55. package/dist/display/ImageViewerRenderer.d.ts +2 -0
  56. package/dist/display/ImageViewerRenderer.js +15 -0
  57. package/dist/display/LinkPreviewRenderer.d.ts +2 -0
  58. package/dist/display/LinkPreviewRenderer.js +20 -0
  59. package/dist/display/MapViewRenderer.d.ts +2 -0
  60. package/dist/display/MapViewRenderer.js +20 -0
  61. package/dist/display/MetricCardRenderer.d.ts +2 -0
  62. package/dist/display/MetricCardRenderer.js +12 -0
  63. package/dist/display/PriceHighlightRenderer.d.ts +2 -0
  64. package/dist/display/PriceHighlightRenderer.js +13 -0
  65. package/dist/display/ProductCardRenderer.d.ts +2 -0
  66. package/dist/display/ProductCardRenderer.js +23 -0
  67. package/dist/display/ProgressStepsRenderer.d.ts +2 -0
  68. package/dist/display/ProgressStepsRenderer.js +14 -0
  69. package/dist/display/SourcesListRenderer.d.ts +2 -0
  70. package/dist/display/SourcesListRenderer.js +5 -0
  71. package/dist/display/SpreadsheetRenderer.d.ts +2 -0
  72. package/dist/display/SpreadsheetRenderer.js +32 -0
  73. package/dist/display/StepTimelineRenderer.d.ts +2 -0
  74. package/dist/display/StepTimelineRenderer.js +21 -0
  75. package/dist/display/index.d.ts +21 -0
  76. package/dist/display/index.js +20 -0
  77. package/dist/display/registry.d.ts +5 -0
  78. package/dist/display/registry.js +50 -0
  79. package/dist/hooks/ChatProvider.d.ts +10 -0
  80. package/dist/hooks/ChatProvider.js +14 -0
  81. package/dist/hooks/useBackboneChat.d.ts +37 -0
  82. package/dist/hooks/useBackboneChat.js +121 -0
  83. package/dist/hooks/useIsMobile.d.ts +1 -0
  84. package/dist/hooks/useIsMobile.js +12 -0
  85. package/dist/index.d.ts +47 -0
  86. package/dist/index.js +40 -0
  87. package/dist/lib/utils.d.ts +2 -0
  88. package/dist/lib/utils.js +5 -0
  89. package/dist/parts/PartRenderer.d.ts +40 -0
  90. package/dist/parts/PartRenderer.js +97 -0
  91. package/dist/parts/ReasoningBlock.d.ts +6 -0
  92. package/dist/parts/ReasoningBlock.js +18 -0
  93. package/dist/parts/ToolActivity.d.ts +11 -0
  94. package/dist/parts/ToolActivity.js +52 -0
  95. package/dist/parts/ToolResult.d.ts +7 -0
  96. package/dist/parts/ToolResult.js +38 -0
  97. package/dist/styles.css +2 -0
  98. package/dist/ui/alert.d.ts +12 -0
  99. package/dist/ui/alert.js +28 -0
  100. package/dist/ui/badge.d.ts +9 -0
  101. package/dist/ui/badge.js +20 -0
  102. package/dist/ui/button.d.ts +11 -0
  103. package/dist/ui/button.js +31 -0
  104. package/dist/ui/card.d.ts +8 -0
  105. package/dist/ui/card.js +21 -0
  106. package/dist/ui/collapsible.d.ts +1 -0
  107. package/dist/ui/collapsible.js +2 -0
  108. package/dist/ui/dialog.d.ts +19 -0
  109. package/dist/ui/dialog.js +23 -0
  110. package/dist/ui/dropdown-menu.d.ts +11 -0
  111. package/dist/ui/dropdown-menu.js +15 -0
  112. package/dist/ui/input.d.ts +3 -0
  113. package/dist/ui/input.js +6 -0
  114. package/dist/ui/progress.d.ts +7 -0
  115. package/dist/ui/progress.js +9 -0
  116. package/dist/ui/scroll-area.d.ts +5 -0
  117. package/dist/ui/scroll-area.js +12 -0
  118. package/dist/ui/separator.d.ts +4 -0
  119. package/dist/ui/separator.js +8 -0
  120. package/dist/ui/skeleton.d.ts +3 -0
  121. package/dist/ui/skeleton.js +6 -0
  122. package/dist/ui/table.d.ts +10 -0
  123. package/dist/ui/table.js +27 -0
  124. package/package.json +53 -0
  125. package/src/components/Chat.tsx +80 -0
  126. package/src/components/ErrorNote.tsx +32 -0
  127. package/src/components/LazyRender.tsx +42 -0
  128. package/src/components/Markdown.tsx +114 -0
  129. package/src/components/MessageBubble.tsx +102 -0
  130. package/src/components/MessageInput.tsx +421 -0
  131. package/src/components/MessageList.tsx +139 -0
  132. package/src/components/StreamingIndicator.tsx +19 -0
  133. package/src/conversations/CollapsibleGroup.tsx +41 -0
  134. package/src/conversations/ConversationBar.tsx +200 -0
  135. package/src/conversations/ConversationList.tsx +234 -0
  136. package/src/conversations/ConversationListItem.tsx +123 -0
  137. package/src/conversations/DeleteDialog.tsx +55 -0
  138. package/src/conversations/RenameDialog.tsx +74 -0
  139. package/src/conversations/index.ts +14 -0
  140. package/src/conversations/types.ts +17 -0
  141. package/src/conversations/useConversations.ts +148 -0
  142. package/src/conversations/utils.ts +159 -0
  143. package/src/display/AlertRenderer.tsx +27 -0
  144. package/src/display/CarouselRenderer.tsx +141 -0
  145. package/src/display/ChartRenderer.tsx +195 -0
  146. package/src/display/ChoiceButtonsRenderer.tsx +114 -0
  147. package/src/display/CodeBlockRenderer.tsx +49 -0
  148. package/src/display/ComparisonTableRenderer.tsx +132 -0
  149. package/src/display/DataTableRenderer.tsx +144 -0
  150. package/src/display/FileCardRenderer.tsx +55 -0
  151. package/src/display/GalleryRenderer.tsx +65 -0
  152. package/src/display/ImageViewerRenderer.tsx +114 -0
  153. package/src/display/LinkPreviewRenderer.tsx +74 -0
  154. package/src/display/MapViewRenderer.tsx +75 -0
  155. package/src/display/MetricCardRenderer.tsx +29 -0
  156. package/src/display/PriceHighlightRenderer.tsx +44 -0
  157. package/src/display/ProductCardRenderer.tsx +112 -0
  158. package/src/display/ProgressStepsRenderer.tsx +59 -0
  159. package/src/display/SourcesListRenderer.tsx +47 -0
  160. package/src/display/SpreadsheetRenderer.tsx +86 -0
  161. package/src/display/StepTimelineRenderer.tsx +75 -0
  162. package/src/display/index.ts +21 -0
  163. package/src/display/registry.ts +81 -0
  164. package/src/hooks/ChatProvider.tsx +22 -0
  165. package/src/hooks/useBackboneChat.ts +148 -0
  166. package/src/hooks/useIsMobile.ts +15 -0
  167. package/src/index.ts +80 -0
  168. package/src/lib/utils.ts +6 -0
  169. package/src/parts/PartRenderer.tsx +198 -0
  170. package/src/parts/ReasoningBlock.tsx +41 -0
  171. package/src/parts/ToolActivity.tsx +79 -0
  172. package/src/parts/ToolResult.tsx +79 -0
  173. package/src/styles.css +2 -0
  174. package/src/ui/alert.tsx +77 -0
  175. package/src/ui/badge.tsx +36 -0
  176. package/src/ui/button.tsx +54 -0
  177. package/src/ui/card.tsx +68 -0
  178. package/src/ui/collapsible.tsx +7 -0
  179. package/src/ui/dialog.tsx +122 -0
  180. package/src/ui/dropdown-menu.tsx +76 -0
  181. package/src/ui/input.tsx +24 -0
  182. package/src/ui/progress.tsx +36 -0
  183. package/src/ui/scroll-area.tsx +48 -0
  184. package/src/ui/separator.tsx +31 -0
  185. package/src/ui/skeleton.tsx +9 -0
  186. package/src/ui/table.tsx +114 -0
  187. package/tsconfig.json +17 -0
@@ -0,0 +1,141 @@
1
+ import type { DisplayCarousel } from "@gugacoder/agentic-sdk";
2
+ import useEmblaCarousel from "embla-carousel-react";
3
+ import { ChevronLeft, ChevronRight } from "lucide-react";
4
+ import { useCallback, useEffect, useState } from "react";
5
+ import { Badge } from "../ui/badge";
6
+ import { Button } from "../ui/button";
7
+ import { Card, CardContent } from "../ui/card";
8
+ import { cn } from "../lib/utils";
9
+
10
+ function formatPrice(value: number, currency: string): string {
11
+ return new Intl.NumberFormat("pt-BR", { style: "currency", currency }).format(value);
12
+ }
13
+
14
+ export function CarouselRenderer({ title, items }: DisplayCarousel) {
15
+ const [emblaRef, emblaApi] = useEmblaCarousel({ loop: false, dragFree: false });
16
+ const [selectedIndex, setSelectedIndex] = useState(0);
17
+ const [canScrollPrev, setCanScrollPrev] = useState(false);
18
+ const [canScrollNext, setCanScrollNext] = useState(false);
19
+
20
+ const onSelect = useCallback(() => {
21
+ if (!emblaApi) return;
22
+ setSelectedIndex(emblaApi.selectedScrollSnap());
23
+ setCanScrollPrev(emblaApi.canScrollPrev());
24
+ setCanScrollNext(emblaApi.canScrollNext());
25
+ }, [emblaApi]);
26
+
27
+ useEffect(() => {
28
+ if (!emblaApi) return;
29
+ onSelect();
30
+ emblaApi.on("select", onSelect);
31
+ emblaApi.on("reInit", onSelect);
32
+ return () => {
33
+ emblaApi.off("select", onSelect);
34
+ emblaApi.off("reInit", onSelect);
35
+ };
36
+ }, [emblaApi, onSelect]);
37
+
38
+ const scrollPrev = useCallback(() => emblaApi?.scrollPrev(), [emblaApi]);
39
+ const scrollNext = useCallback(() => emblaApi?.scrollNext(), [emblaApi]);
40
+
41
+ return (
42
+ <div className="flex flex-col gap-3">
43
+ {title && <p className="text-sm font-medium text-foreground">{title}</p>}
44
+
45
+ <div className="flex items-center gap-2">
46
+ <Button
47
+ variant="outline"
48
+ size="icon"
49
+ className="rounded-full shrink-0"
50
+ onClick={scrollPrev}
51
+ disabled={!canScrollPrev}
52
+ aria-label="Anterior"
53
+ type="button"
54
+ >
55
+ <ChevronLeft className="h-4 w-4" />
56
+ </Button>
57
+
58
+ <div className="overflow-hidden flex-1" ref={emblaRef}>
59
+ <div className="flex">
60
+ {items.map((item, index) => (
61
+ <div key={index} className="flex-[0_0_80%] min-w-0 pl-3 first:pl-0">
62
+ {item.url ? (
63
+ <a href={item.url} target="_blank" rel="noopener noreferrer" className="block">
64
+ <CarouselCard item={item} />
65
+ </a>
66
+ ) : (
67
+ <CarouselCard item={item} />
68
+ )}
69
+ </div>
70
+ ))}
71
+ </div>
72
+ </div>
73
+
74
+ <Button
75
+ variant="outline"
76
+ size="icon"
77
+ className="rounded-full shrink-0"
78
+ onClick={scrollNext}
79
+ disabled={!canScrollNext}
80
+ aria-label="Próximo"
81
+ type="button"
82
+ >
83
+ <ChevronRight className="h-4 w-4" />
84
+ </Button>
85
+ </div>
86
+
87
+ {items.length > 1 && (
88
+ <div className="flex items-center justify-center gap-1.5" role="tablist" aria-label="Slides">
89
+ {items.map((_, index) => (
90
+ <button
91
+ key={index}
92
+ className={cn(
93
+ "w-2 h-2 rounded-full transition-colors",
94
+ index === selectedIndex ? "bg-primary" : "bg-muted"
95
+ )}
96
+ onClick={() => emblaApi?.scrollTo(index)}
97
+ role="tab"
98
+ aria-selected={index === selectedIndex}
99
+ aria-label={`Slide ${index + 1}`}
100
+ type="button"
101
+ />
102
+ ))}
103
+ </div>
104
+ )}
105
+ </div>
106
+ );
107
+ }
108
+
109
+ type CarouselItem = DisplayCarousel["items"][number];
110
+
111
+ function CarouselCard({ item }: { item: CarouselItem }) {
112
+ return (
113
+ <Card className="overflow-hidden">
114
+ {item.image && (
115
+ <div className="aspect-video overflow-hidden">
116
+ <img src={item.image} alt={item.title} loading="lazy" className="w-full h-full object-cover" />
117
+ </div>
118
+ )}
119
+ <CardContent className="p-3 space-y-1">
120
+ <p className="font-medium text-sm text-foreground">{item.title}</p>
121
+ {item.subtitle && (
122
+ <p className="text-xs text-muted-foreground">{item.subtitle}</p>
123
+ )}
124
+ {item.price && (
125
+ <p className="text-sm font-bold text-foreground">
126
+ {formatPrice(item.price.value, item.price.currency)}
127
+ </p>
128
+ )}
129
+ {item.badges && item.badges.length > 0 && (
130
+ <div className="flex flex-wrap gap-1 pt-1">
131
+ {item.badges.map((badge, i) => (
132
+ <Badge key={i} variant={(badge.variant as string) === "destructive" ? "destructive" : (badge.variant as string) === "secondary" ? "secondary" : "default"}>
133
+ {badge.label}
134
+ </Badge>
135
+ ))}
136
+ </div>
137
+ )}
138
+ </CardContent>
139
+ </Card>
140
+ );
141
+ }
@@ -0,0 +1,195 @@
1
+ import type { DisplayChart } from "@gugacoder/agentic-sdk";
2
+ import {
3
+ AreaChart,
4
+ Area,
5
+ BarChart,
6
+ Bar,
7
+ LineChart,
8
+ Line,
9
+ PieChart,
10
+ Pie,
11
+ Cell,
12
+ CartesianGrid,
13
+ Tooltip,
14
+ ResponsiveContainer,
15
+ XAxis,
16
+ YAxis,
17
+ } from "recharts";
18
+ import { Card } from "../ui/card";
19
+
20
+ const CHART_COLORS = [
21
+ "var(--chart-1)",
22
+ "var(--chart-2)",
23
+ "var(--chart-3)",
24
+ "var(--chart-4)",
25
+ "var(--chart-5)",
26
+ ];
27
+
28
+ const AXIS_PROPS = {
29
+ stroke: "var(--border)",
30
+ tick: { fill: "var(--muted-foreground)", fontSize: 12 },
31
+ };
32
+
33
+ const TOOLTIP_STYLE = {
34
+ contentStyle: {
35
+ background: "var(--card)",
36
+ border: "1px solid var(--border)",
37
+ color: "var(--card-foreground)",
38
+ borderRadius: "0.375rem",
39
+ fontSize: "0.75rem",
40
+ },
41
+ };
42
+
43
+ function formatValue(value: number, format?: DisplayChart["format"]): string {
44
+ if (!format) return String(value);
45
+ const locale = format.locale ?? "pt-BR";
46
+ const prefix = format.prefix ?? "";
47
+ const suffix = format.suffix ?? "";
48
+ if (prefix.includes("R$") || prefix.includes("$") || prefix.includes("€")) {
49
+ const currencyMap: Record<string, string> = {
50
+ "R$": "BRL",
51
+ "$": "USD",
52
+ "€": "EUR",
53
+ };
54
+ const currency = Object.keys(currencyMap).find(k => prefix.includes(k));
55
+ if (currency) {
56
+ return new Intl.NumberFormat(locale, { style: "currency", currency: currencyMap[currency] }).format(value);
57
+ }
58
+ }
59
+ if (suffix.includes("%")) {
60
+ return new Intl.NumberFormat(locale, { style: "percent", maximumFractionDigits: 1 }).format(value / 100);
61
+ }
62
+ const formatted = new Intl.NumberFormat(locale).format(value);
63
+ return `${prefix}${formatted}${suffix}`;
64
+ }
65
+
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ function makeTooltipFormatter(format?: DisplayChart["format"]): any {
68
+ return (value: number | string | undefined): [string, string] => [
69
+ typeof value === "number" ? formatValue(value, format) : String(value ?? ""),
70
+ "",
71
+ ];
72
+ }
73
+
74
+ export function ChartRenderer({ type, title, data, format }: DisplayChart) {
75
+ const chartData = data.map((d) => ({ name: d.label, value: d.value, color: d.color }));
76
+ const tooltipFormatter = makeTooltipFormatter(format);
77
+
78
+ const sharedProps = {
79
+ data: chartData,
80
+ margin: { top: 4, right: 8, left: 8, bottom: 4 },
81
+ };
82
+
83
+ return (
84
+ <Card className="p-4">
85
+ {title && <p className="text-sm font-medium text-foreground mb-4">{title}</p>}
86
+ <div className="min-h-[200px]">
87
+ <ResponsiveContainer width="100%" height={200}>
88
+ {renderChart(type, chartData, sharedProps, tooltipFormatter)}
89
+ </ResponsiveContainer>
90
+ </div>
91
+ </Card>
92
+ );
93
+ }
94
+
95
+ function renderChart(
96
+ type: DisplayChart["type"],
97
+ data: Array<{ name: string; value: number; color?: string }>,
98
+ sharedProps: { data: typeof data; margin: { top: number; right: number; left: number; bottom: number } },
99
+ tooltipFormatter: (v: number | string | undefined) => [string, string]
100
+ ) {
101
+ switch (type) {
102
+ case "bar":
103
+ return (
104
+ <BarChart {...sharedProps}>
105
+ <CartesianGrid strokeDasharray="3 3" stroke="var(--border)" />
106
+ <XAxis dataKey="name" {...AXIS_PROPS} />
107
+ <YAxis width={48} {...AXIS_PROPS} />
108
+ <Tooltip formatter={tooltipFormatter} {...TOOLTIP_STYLE} />
109
+ <Bar dataKey="value" radius={[4, 4, 0, 0]}>
110
+ {data.map((entry, index) => (
111
+ <Cell key={index} fill={entry.color ?? CHART_COLORS[index % CHART_COLORS.length]} />
112
+ ))}
113
+ </Bar>
114
+ </BarChart>
115
+ );
116
+
117
+ case "line":
118
+ return (
119
+ <LineChart {...sharedProps}>
120
+ <CartesianGrid strokeDasharray="3 3" stroke="var(--border)" />
121
+ <XAxis dataKey="name" {...AXIS_PROPS} />
122
+ <YAxis width={48} {...AXIS_PROPS} />
123
+ <Tooltip formatter={tooltipFormatter} {...TOOLTIP_STYLE} />
124
+ <Line
125
+ type="monotone"
126
+ dataKey="value"
127
+ stroke={CHART_COLORS[0]}
128
+ strokeWidth={2}
129
+ dot={{ r: 4, fill: CHART_COLORS[0] }}
130
+ />
131
+ </LineChart>
132
+ );
133
+
134
+ case "area":
135
+ return (
136
+ <AreaChart {...sharedProps}>
137
+ <CartesianGrid strokeDasharray="3 3" stroke="var(--border)" />
138
+ <XAxis dataKey="name" {...AXIS_PROPS} />
139
+ <YAxis width={48} {...AXIS_PROPS} />
140
+ <Tooltip formatter={tooltipFormatter} {...TOOLTIP_STYLE} />
141
+ <Area
142
+ type="monotone"
143
+ dataKey="value"
144
+ stroke={CHART_COLORS[0]}
145
+ fill={CHART_COLORS[0]}
146
+ fillOpacity={0.2}
147
+ strokeWidth={2}
148
+ />
149
+ </AreaChart>
150
+ );
151
+
152
+ case "pie":
153
+ return (
154
+ <PieChart>
155
+ <Tooltip formatter={tooltipFormatter} {...TOOLTIP_STYLE} />
156
+ <Pie
157
+ data={data}
158
+ dataKey="value"
159
+ nameKey="name"
160
+ cx="50%"
161
+ cy="50%"
162
+ outerRadius="70%"
163
+ label={({ name }) => name}
164
+ labelLine={{ stroke: "var(--muted-foreground)" }}
165
+ >
166
+ {data.map((entry, index) => (
167
+ <Cell key={index} fill={entry.color ?? CHART_COLORS[index % CHART_COLORS.length]} />
168
+ ))}
169
+ </Pie>
170
+ </PieChart>
171
+ );
172
+
173
+ case "donut":
174
+ return (
175
+ <PieChart>
176
+ <Tooltip formatter={tooltipFormatter} {...TOOLTIP_STYLE} />
177
+ <Pie
178
+ data={data}
179
+ dataKey="value"
180
+ nameKey="name"
181
+ cx="50%"
182
+ cy="50%"
183
+ innerRadius="40%"
184
+ outerRadius="70%"
185
+ label={({ name }) => name}
186
+ labelLine={{ stroke: "var(--muted-foreground)" }}
187
+ >
188
+ {data.map((entry, index) => (
189
+ <Cell key={index} fill={entry.color ?? CHART_COLORS[index % CHART_COLORS.length]} />
190
+ ))}
191
+ </Pie>
192
+ </PieChart>
193
+ );
194
+ }
195
+ }
@@ -0,0 +1,114 @@
1
+ import type { DisplayChoices } from "@gugacoder/agentic-sdk";
2
+ import { useState } from "react";
3
+ import { Button } from "../ui/button.js";
4
+ import { Card } from "../ui/card.js";
5
+ import { cn } from "../lib/utils.js";
6
+
7
+ type ChoiceButtonsProps = DisplayChoices & {
8
+ onChoiceSelect?: (value: string) => void;
9
+ };
10
+
11
+ export function ChoiceButtonsRenderer({
12
+ question,
13
+ choices,
14
+ layout,
15
+ onChoiceSelect,
16
+ }: ChoiceButtonsProps) {
17
+ const [selected, setSelected] = useState<string | null>(null);
18
+
19
+ function handleSelect(id: string) {
20
+ setSelected(id);
21
+ onChoiceSelect?.(id);
22
+ }
23
+
24
+ return (
25
+ <div className="space-y-3 w-fit">
26
+ {question && <p className="text-sm font-medium text-foreground">{question}</p>}
27
+
28
+ <div
29
+ className={cn(
30
+ layout === "buttons" && "flex flex-wrap gap-2",
31
+ layout === "cards" && "grid grid-cols-1 sm:grid-cols-2 gap-2",
32
+ layout === "list" && "flex flex-col gap-1"
33
+ )}
34
+ role="group"
35
+ aria-label={question ?? "Escolha uma opção"}
36
+ >
37
+ {choices.map((choice) => {
38
+ const isSelected = selected === choice.id;
39
+
40
+ if (layout === "buttons") {
41
+ return (
42
+ <Button
43
+ key={choice.id}
44
+ variant="outline"
45
+ size="sm"
46
+ onClick={() => handleSelect(choice.id)}
47
+ aria-pressed={isSelected}
48
+ className={cn(isSelected && "ring-2 ring-ring")}
49
+ >
50
+ {choice.icon && (
51
+ <span aria-hidden="true">{choice.icon}</span>
52
+ )}
53
+ {choice.label}
54
+ </Button>
55
+ );
56
+ }
57
+
58
+ if (layout === "cards") {
59
+ return (
60
+ <Card
61
+ key={choice.id}
62
+ className={cn(
63
+ "p-3 cursor-pointer hover:bg-muted/50 transition-colors",
64
+ isSelected && "ring-2 ring-ring"
65
+ )}
66
+ onClick={() => handleSelect(choice.id)}
67
+ role="button"
68
+ aria-pressed={isSelected}
69
+ >
70
+ {choice.icon && (
71
+ <span className="text-base" aria-hidden="true">{choice.icon}</span>
72
+ )}
73
+ <span className="block font-medium text-sm text-foreground">{choice.label}</span>
74
+ {choice.description && (
75
+ <span className="block text-xs text-muted-foreground mt-1">{choice.description}</span>
76
+ )}
77
+ </Card>
78
+ );
79
+ }
80
+
81
+ // list
82
+ return (
83
+ <button
84
+ key={choice.id}
85
+ className={cn(
86
+ "flex items-center gap-3 w-full rounded-md px-3 py-2 text-sm text-left hover:bg-muted transition-colors",
87
+ isSelected && "bg-muted ring-1 ring-ring"
88
+ )}
89
+ onClick={() => handleSelect(choice.id)}
90
+ aria-pressed={isSelected}
91
+ >
92
+ <span
93
+ className={cn(
94
+ "w-4 h-4 rounded-full border-2 border-input flex-shrink-0",
95
+ isSelected && "border-primary bg-primary"
96
+ )}
97
+ aria-hidden="true"
98
+ />
99
+ <span className="flex items-center gap-2 flex-1 min-w-0">
100
+ {choice.icon && (
101
+ <span aria-hidden="true">{choice.icon}</span>
102
+ )}
103
+ <span className="font-medium text-foreground">{choice.label}</span>
104
+ {choice.description && (
105
+ <span className="text-xs text-muted-foreground ml-auto">{choice.description}</span>
106
+ )}
107
+ </span>
108
+ </button>
109
+ );
110
+ })}
111
+ </div>
112
+ </div>
113
+ );
114
+ }
@@ -0,0 +1,49 @@
1
+ import type { DisplayCode } from "@gugacoder/agentic-sdk";
2
+ import { Check, Copy } from "lucide-react";
3
+ import { useState } from "react";
4
+ import { Button } from "../ui/button.js";
5
+ import { cn } from "../lib/utils.js";
6
+
7
+ export function CodeBlockRenderer({ language, code, title, lineNumbers }: DisplayCode) {
8
+ const [copied, setCopied] = useState(false);
9
+
10
+ async function handleCopy() {
11
+ await navigator.clipboard.writeText(code);
12
+ setCopied(true);
13
+ setTimeout(() => setCopied(false), 2000);
14
+ }
15
+
16
+ const displayLines = lineNumbers
17
+ ? code.split("\n").map((line, i) => (
18
+ <span key={i} className="flex gap-4">
19
+ <span className="select-none text-muted-foreground w-6 text-right shrink-0">{i + 1}</span>
20
+ <span>{line}</span>
21
+ </span>
22
+ ))
23
+ : code;
24
+
25
+ return (
26
+ <div className={cn("rounded-md border border-border bg-muted/30 overflow-hidden")}>
27
+ <div className="flex items-center justify-between px-3 py-1.5 border-b border-border">
28
+ <span className="text-xs text-muted-foreground font-mono">{title ?? language}</span>
29
+ <Button
30
+ variant="ghost"
31
+ size="sm"
32
+ onClick={handleCopy}
33
+ aria-label={copied ? "Copiado!" : "Copiar código"}
34
+ className="h-7 gap-1.5"
35
+ >
36
+ {copied ? <Check className="h-3 w-3" /> : <Copy className="h-3 w-3" />}
37
+ <span className="text-xs">{copied ? "Copiado!" : "Copiar"}</span>
38
+ </Button>
39
+ </div>
40
+ <pre className="p-4 overflow-x-auto font-mono text-sm">
41
+ {lineNumbers ? (
42
+ <code>{displayLines}</code>
43
+ ) : (
44
+ <code>{code}</code>
45
+ )}
46
+ </pre>
47
+ </div>
48
+ );
49
+ }
@@ -0,0 +1,132 @@
1
+ import { useState } from "react";
2
+ import type { DisplayComparison } from "@gugacoder/agentic-sdk";
3
+ import { CheckCircle } from "lucide-react";
4
+ import { ScrollArea, ScrollBar } from "../ui/scroll-area.js";
5
+ import {
6
+ Table,
7
+ TableBody,
8
+ TableCell,
9
+ TableHead,
10
+ TableHeader,
11
+ TableRow,
12
+ } from "../ui/table.js";
13
+ import { cn } from "../lib/utils.js";
14
+
15
+ function formatMoney(value: number, currency = "BRL") {
16
+ return new Intl.NumberFormat("pt-BR", { style: "currency", currency }).format(value);
17
+ }
18
+
19
+ export function ComparisonTableRenderer({ title, items, attributes }: DisplayComparison) {
20
+ const [bestIdx, setBestIdx] = useState<number | null>(null);
21
+
22
+ // Auto-detect best value by lowest price if no manual selection
23
+ const lowestPriceIdx = items.reduce<number | null>((acc, item, i) => {
24
+ if (!item.price) return acc;
25
+ if (acc === null) return i;
26
+ const best = items[acc]?.price;
27
+ return best && item.price.value < best.value ? i : acc;
28
+ }, null);
29
+
30
+ const highlightIdx = bestIdx ?? lowestPriceIdx;
31
+
32
+ return (
33
+ <div className="space-y-2">
34
+ {title && <h3 className="text-sm font-semibold text-foreground">{title}</h3>}
35
+
36
+ <ScrollArea className="w-full">
37
+ <Table>
38
+ <TableHeader>
39
+ <TableRow>
40
+ <TableHead className="font-semibold text-center">Atributo</TableHead>
41
+ {items.map((item, i) => (
42
+ <TableHead
43
+ key={i}
44
+ className={cn(
45
+ "font-semibold text-center",
46
+ i === highlightIdx && "bg-muted"
47
+ )}
48
+ >
49
+ <button
50
+ className="flex flex-col items-center gap-0.5 w-full cursor-pointer hover:opacity-80"
51
+ onClick={() => setBestIdx(i === bestIdx ? null : i)}
52
+ title="Marcar como melhor"
53
+ >
54
+ {i === highlightIdx && (
55
+ <CheckCircle className="h-3.5 w-3.5 text-primary" />
56
+ )}
57
+ <span className="font-semibold">{item.title}</span>
58
+ {item.price && (
59
+ <span className="text-xs text-muted-foreground font-normal">
60
+ {formatMoney(item.price.value, item.price.currency)}
61
+ </span>
62
+ )}
63
+ </button>
64
+ </TableHead>
65
+ ))}
66
+ </TableRow>
67
+ </TableHeader>
68
+
69
+ <TableBody>
70
+ {attributes && attributes.length > 0 ? (
71
+ attributes.map((attr, ri) => (
72
+ <TableRow key={ri}>
73
+ <TableCell className="font-medium">{attr.label}</TableCell>
74
+ {items.map((item, ci) => {
75
+ const val = (item as Record<string, unknown>)[attr.key];
76
+ return (
77
+ <TableCell
78
+ key={ci}
79
+ className={cn(
80
+ "text-center",
81
+ ci === highlightIdx && "bg-muted/50"
82
+ )}
83
+ >
84
+ {val === true ? "✓" : val === false ? "✗" : val != null ? String(val) : "—"}
85
+ </TableCell>
86
+ );
87
+ })}
88
+ </TableRow>
89
+ ))
90
+ ) : (
91
+ <>
92
+ {items.some((i) => i.rating) && (
93
+ <TableRow>
94
+ <TableCell className="font-medium">Avaliação</TableCell>
95
+ {items.map((item, ci) => (
96
+ <TableCell
97
+ key={ci}
98
+ className={cn(
99
+ "text-center",
100
+ ci === highlightIdx && "bg-muted/50"
101
+ )}
102
+ >
103
+ {item.rating ? `${item.rating.score}/5 (${item.rating.count})` : "—"}
104
+ </TableCell>
105
+ ))}
106
+ </TableRow>
107
+ )}
108
+ {items.some((i) => i.description) && (
109
+ <TableRow>
110
+ <TableCell className="font-medium">Descrição</TableCell>
111
+ {items.map((item, ci) => (
112
+ <TableCell
113
+ key={ci}
114
+ className={cn(
115
+ "text-center",
116
+ ci === highlightIdx && "bg-muted/50"
117
+ )}
118
+ >
119
+ {item.description ?? "—"}
120
+ </TableCell>
121
+ ))}
122
+ </TableRow>
123
+ )}
124
+ </>
125
+ )}
126
+ </TableBody>
127
+ </Table>
128
+ <ScrollBar orientation="horizontal" />
129
+ </ScrollArea>
130
+ </div>
131
+ );
132
+ }