@timbal-ai/timbal-react 0.8.2 → 1.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 (43) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +100 -6
  3. package/dist/app.cjs +2538 -1262
  4. package/dist/app.d.cts +11 -6
  5. package/dist/app.d.ts +11 -6
  6. package/dist/app.esm.js +43 -6
  7. package/dist/{button-ClSgD6OF.d.cts → button-BoyX5pM_.d.cts} +1 -1
  8. package/dist/{button-ClSgD6OF.d.ts → button-BoyX5pM_.d.ts} +1 -1
  9. package/dist/{chart-artifact-Bl67kre7.d.ts → chart-artifact-BZp7nmaf.d.ts} +430 -14
  10. package/dist/{chart-artifact-BzcvblDe.d.cts → chart-artifact-CX-rh9nq.d.cts} +430 -14
  11. package/dist/{chat-Bed4FQSl.d.cts → chat-DCms8pJ_.d.cts} +31 -4
  12. package/dist/{chat-Bed4FQSl.d.ts → chat-DCms8pJ_.d.ts} +31 -4
  13. package/dist/chat.cjs +1111 -776
  14. package/dist/chat.d.cts +1 -1
  15. package/dist/chat.d.ts +1 -1
  16. package/dist/chat.esm.js +3 -3
  17. package/dist/{chunk-QVAUCVQA.esm.js → chunk-4AKJ6FKE.esm.js} +277 -4
  18. package/dist/chunk-6HWMJNZT.esm.js +3439 -0
  19. package/dist/{chunk-VWHHKAHN.esm.js → chunk-FRZOEYBO.esm.js} +4 -4
  20. package/dist/chunk-JEAUF54A.esm.js +52 -0
  21. package/dist/{chunk-OISVICYF.esm.js → chunk-P3KDAYX6.esm.js} +1 -1
  22. package/dist/{chunk-6YVKCVEP.esm.js → chunk-TK2AGIME.esm.js} +1106 -298
  23. package/dist/{chunk-CFU3YDTV.esm.js → chunk-XCM3V6RK.esm.js} +5 -5
  24. package/dist/{chunk-5ZKLPWVN.esm.js → chunk-YXZ22OJN.esm.js} +849 -667
  25. package/dist/index.cjs +6070 -1605
  26. package/dist/index.d.cts +8 -6
  27. package/dist/index.d.ts +8 -6
  28. package/dist/index.esm.js +427 -11
  29. package/dist/pill-segmented-tabs-Ba5q0feL.d.cts +500 -0
  30. package/dist/pill-segmented-tabs-Ba5q0feL.d.ts +500 -0
  31. package/dist/studio.cjs +1333 -998
  32. package/dist/studio.d.cts +2 -2
  33. package/dist/studio.d.ts +2 -2
  34. package/dist/studio.esm.js +5 -5
  35. package/dist/styles.css +220 -0
  36. package/dist/ui.cjs +3592 -89
  37. package/dist/ui.d.cts +72 -96
  38. package/dist/ui.d.ts +72 -96
  39. package/dist/ui.esm.js +400 -6
  40. package/dist/{welcome-COOb05a5.d.cts → welcome-CRqOPKMp.d.cts} +1 -1
  41. package/dist/{welcome-DE08m9ca.d.ts → welcome-DlHUa3OL.d.ts} +1 -1
  42. package/package.json +9 -3
  43. package/dist/chunk-P4SN7M67.esm.js +0 -435
package/dist/chat.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { c as ChatAttachment, d as ChatMessage, e as Composer, f as ComposerProps, g as ContentPart, S as SendOptions, h as Suggestions, i as SuggestionsComponent, j as SuggestionsSlotProps, k as SuggestionsSource, l as TextContentPart, m as ThinkingContentPart, n as Thread, o as ThreadArtifactsConfig, p as ThreadComponents, q as ThreadProps, r as ThreadSuggestion, s as ThreadSuggestionsProps, T as ThreadVariant, t as ThreadWelcomeConfig, u as ThreadWelcomeProps, a as TimbalChat, b as TimbalChatProps, v as TimbalRuntimeProvider, w as TimbalRuntimeProviderProps, x as TimbalStreamApi, y as ToolCallContentPart, U as UseTimbalStreamOptions, z as useResolvedSuggestions, A as useTimbalRuntime, B as useTimbalStream } from './chat-Bed4FQSl.cjs';
1
+ export { d as ChatAttachment, e as ChatMessage, f as Composer, g as ComposerProps, h as ContentPart, S as SendOptions, i as Suggestions, j as SuggestionsComponent, k as SuggestionsSlotProps, l as SuggestionsSource, m as TextContentPart, n as ThinkingContentPart, o as Thread, p as ThreadArtifactsConfig, q as ThreadComponents, r as ThreadProps, s as ThreadSuggestion, t as ThreadSuggestionsProps, T as ThreadVariant, u as ThreadWelcomeConfig, v as ThreadWelcomeProps, b as TimbalChat, c as TimbalChatProps, w as TimbalRuntimeProvider, x as TimbalRuntimeProviderProps, y as TimbalStreamApi, z as ToolCallContentPart, U as UseTimbalStreamOptions, A as useResolvedSuggestions, B as useTimbalRuntime, D as useTimbalStream } from './chat-DCms8pJ_.cjs';
2
2
  export { M as MarkdownText, T as THREAD_DEFAULT_MAX_WIDTH, a as ToolFallback, b as TooltipIconButton, c as TooltipIconButtonProps, W as WorkforceSelector, d as WorkforceSelectorProps, e as assistantMessageContentClass, f as assistantMessageRootClass, t as threadMessageColumnClass, u as useToolRunning, g as userMessageRootClass } from './layout-C2G-FcER.cjs';
3
3
  import { FC } from 'react';
4
4
  import 'react/jsx-runtime';
package/dist/chat.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { c as ChatAttachment, d as ChatMessage, e as Composer, f as ComposerProps, g as ContentPart, S as SendOptions, h as Suggestions, i as SuggestionsComponent, j as SuggestionsSlotProps, k as SuggestionsSource, l as TextContentPart, m as ThinkingContentPart, n as Thread, o as ThreadArtifactsConfig, p as ThreadComponents, q as ThreadProps, r as ThreadSuggestion, s as ThreadSuggestionsProps, T as ThreadVariant, t as ThreadWelcomeConfig, u as ThreadWelcomeProps, a as TimbalChat, b as TimbalChatProps, v as TimbalRuntimeProvider, w as TimbalRuntimeProviderProps, x as TimbalStreamApi, y as ToolCallContentPart, U as UseTimbalStreamOptions, z as useResolvedSuggestions, A as useTimbalRuntime, B as useTimbalStream } from './chat-Bed4FQSl.js';
1
+ export { d as ChatAttachment, e as ChatMessage, f as Composer, g as ComposerProps, h as ContentPart, S as SendOptions, i as Suggestions, j as SuggestionsComponent, k as SuggestionsSlotProps, l as SuggestionsSource, m as TextContentPart, n as ThinkingContentPart, o as Thread, p as ThreadArtifactsConfig, q as ThreadComponents, r as ThreadProps, s as ThreadSuggestion, t as ThreadSuggestionsProps, T as ThreadVariant, u as ThreadWelcomeConfig, v as ThreadWelcomeProps, b as TimbalChat, c as TimbalChatProps, w as TimbalRuntimeProvider, x as TimbalRuntimeProviderProps, y as TimbalStreamApi, z as ToolCallContentPart, U as UseTimbalStreamOptions, A as useResolvedSuggestions, B as useTimbalRuntime, D as useTimbalStream } from './chat-DCms8pJ_.js';
2
2
  export { M as MarkdownText, T as THREAD_DEFAULT_MAX_WIDTH, a as ToolFallback, b as TooltipIconButton, c as TooltipIconButtonProps, W as WorkforceSelector, d as WorkforceSelectorProps, e as assistantMessageContentClass, f as assistantMessageRootClass, t as threadMessageColumnClass, u as useToolRunning, g as userMessageRootClass } from './layout-BTJyU8wd.js';
3
3
  import { FC } from 'react';
4
4
  import 'react/jsx-runtime';
package/dist/chat.esm.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-KC5QLVUG.esm.js";
8
8
  import {
9
9
  WorkforceSelector
10
- } from "./chunk-CFU3YDTV.esm.js";
10
+ } from "./chunk-XCM3V6RK.esm.js";
11
11
  import {
12
12
  Composer,
13
13
  ComposerAddAttachment,
@@ -24,8 +24,8 @@ import {
24
24
  useTimbalRuntime,
25
25
  useTimbalStream,
26
26
  useToolRunning
27
- } from "./chunk-5ZKLPWVN.esm.js";
28
- import "./chunk-QVAUCVQA.esm.js";
27
+ } from "./chunk-YXZ22OJN.esm.js";
28
+ import "./chunk-4AKJ6FKE.esm.js";
29
29
  export {
30
30
  Composer,
31
31
  ComposerAddAttachment,
@@ -311,6 +311,39 @@ function Button({
311
311
  );
312
312
  }
313
313
 
314
+ // src/design/control-surface.ts
315
+ var CONTROL_SIZE = {
316
+ sm: "h-9 px-3",
317
+ default: "h-10 px-3"
318
+ };
319
+ var CONTROL_SHAPE = {
320
+ field: "rounded-lg",
321
+ pill: "rounded-full"
322
+ };
323
+ var controlSurfaceClass = cn(
324
+ TIMBAL_V2_SECONDARY_CHROME,
325
+ "text-sm text-foreground outline-none",
326
+ "placeholder:text-muted-foreground/70",
327
+ "focus-visible:ring-2 focus-visible:ring-foreground/10",
328
+ "focus-within:ring-2 focus-within:ring-foreground/10",
329
+ "disabled:cursor-not-allowed disabled:opacity-50",
330
+ "data-[placeholder]:text-muted-foreground"
331
+ );
332
+ function controlClass(options = {}, className) {
333
+ const { size = "default", shape = "field" } = options;
334
+ return cn(controlSurfaceClass, CONTROL_SIZE[size], CONTROL_SHAPE[shape], className);
335
+ }
336
+ var overlayAnimationClass = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2";
337
+ var overlaySurfaceClass = cn(
338
+ "z-[80] border border-border bg-popover text-popover-foreground shadow-card",
339
+ overlayAnimationClass
340
+ );
341
+ var overlayListPanelClass = cn(
342
+ overlaySurfaceClass,
343
+ "overflow-hidden rounded-lg p-0 outline-hidden"
344
+ );
345
+ var overlayItemClass = "relative flex cursor-default items-center gap-2 rounded-md px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground";
346
+
314
347
  // src/ui/tooltip.tsx
315
348
  import { Tooltip as TooltipPrimitive } from "radix-ui";
316
349
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
@@ -538,13 +571,237 @@ function AvatarFallback({
538
571
  );
539
572
  }
540
573
 
574
+ // src/ui/chart.tsx
575
+ import * as React2 from "react";
576
+ import * as RechartsPrimitive from "recharts";
577
+ import { Fragment, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
578
+ var THEMES = { light: "", dark: ".dark" };
579
+ var ChartContext = React2.createContext(null);
580
+ function useChart() {
581
+ const context = React2.useContext(ChartContext);
582
+ if (!context) {
583
+ throw new Error("useChart must be used within a <ChartContainer />");
584
+ }
585
+ return context;
586
+ }
587
+ function ChartContainer({
588
+ id,
589
+ className,
590
+ children,
591
+ config,
592
+ ...props
593
+ }) {
594
+ const uniqueId = React2.useId();
595
+ const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
596
+ return /* @__PURE__ */ jsx6(ChartContext.Provider, { value: { config }, children: /* @__PURE__ */ jsxs4(
597
+ "div",
598
+ {
599
+ "data-slot": "chart",
600
+ "data-chart": chartId,
601
+ className: cn(
602
+ "[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
603
+ className
604
+ ),
605
+ ...props,
606
+ children: [
607
+ /* @__PURE__ */ jsx6(ChartStyle, { id: chartId, config }),
608
+ /* @__PURE__ */ jsx6(RechartsPrimitive.ResponsiveContainer, { children })
609
+ ]
610
+ }
611
+ ) });
612
+ }
613
+ var ChartStyle = ({ id, config }) => {
614
+ const colorConfig = Object.entries(config).filter(
615
+ ([, c]) => c.theme || c.color
616
+ );
617
+ if (!colorConfig.length) {
618
+ return null;
619
+ }
620
+ return /* @__PURE__ */ jsx6(
621
+ "style",
622
+ {
623
+ dangerouslySetInnerHTML: {
624
+ __html: Object.entries(THEMES).map(
625
+ ([theme, prefix]) => `
626
+ ${prefix} [data-chart=${id}] {
627
+ ${colorConfig.map(([key, itemConfig]) => {
628
+ const color = itemConfig.theme?.[theme] || itemConfig.color;
629
+ return color ? ` --color-${key}: ${color};` : null;
630
+ }).join("\n")}
631
+ }
632
+ `
633
+ ).join("\n")
634
+ }
635
+ }
636
+ );
637
+ };
638
+ var ChartTooltip = RechartsPrimitive.Tooltip;
639
+ function ChartTooltipContent({
640
+ active,
641
+ payload,
642
+ className,
643
+ indicator = "dot",
644
+ hideLabel = false,
645
+ hideIndicator = false,
646
+ label,
647
+ labelFormatter,
648
+ labelClassName,
649
+ formatter,
650
+ color,
651
+ nameKey,
652
+ labelKey
653
+ }) {
654
+ const { config } = useChart();
655
+ const tooltipLabel = React2.useMemo(() => {
656
+ if (hideLabel || !payload?.length) {
657
+ return null;
658
+ }
659
+ const [item] = payload;
660
+ const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
661
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
662
+ const value = !labelKey && typeof label === "string" ? config[label]?.label || label : itemConfig?.label;
663
+ if (labelFormatter) {
664
+ return /* @__PURE__ */ jsx6("div", { className: cn("font-medium", labelClassName), children: labelFormatter(value, payload) });
665
+ }
666
+ if (!value) {
667
+ return null;
668
+ }
669
+ return /* @__PURE__ */ jsx6("div", { className: cn("font-medium", labelClassName), children: value });
670
+ }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
671
+ if (!active || !payload?.length) {
672
+ return null;
673
+ }
674
+ const nestLabel = payload.length === 1 && indicator !== "dot";
675
+ return /* @__PURE__ */ jsxs4(
676
+ "div",
677
+ {
678
+ className: cn(
679
+ "border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
680
+ "animate-in fade-in-0 zoom-in-95 duration-150",
681
+ className
682
+ ),
683
+ children: [
684
+ !nestLabel ? tooltipLabel : null,
685
+ /* @__PURE__ */ jsx6("div", { className: "grid gap-1.5", children: payload.filter((item) => item.type !== "none").map((item, index) => {
686
+ const key = `${nameKey || item.name || item.dataKey || "value"}`;
687
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
688
+ const indicatorColor = color || item.payload?.fill || item.color;
689
+ return /* @__PURE__ */ jsx6(
690
+ "div",
691
+ {
692
+ className: cn(
693
+ "[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
694
+ indicator === "dot" && "items-center"
695
+ ),
696
+ children: formatter && item?.value !== void 0 && item.name ? formatter(item.value, item.name, item, index, item.payload) : /* @__PURE__ */ jsxs4(Fragment, { children: [
697
+ itemConfig?.icon ? /* @__PURE__ */ jsx6(itemConfig.icon, {}) : !hideIndicator && /* @__PURE__ */ jsx6(
698
+ "div",
699
+ {
700
+ className: cn(
701
+ "shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
702
+ {
703
+ "h-2.5 w-2.5": indicator === "dot",
704
+ "w-1": indicator === "line",
705
+ "w-0 border-[1.5px] border-dashed bg-transparent": indicator === "dashed",
706
+ "my-0.5": nestLabel && indicator === "dashed"
707
+ }
708
+ ),
709
+ style: {
710
+ "--color-bg": indicatorColor,
711
+ "--color-border": indicatorColor
712
+ }
713
+ }
714
+ ),
715
+ /* @__PURE__ */ jsxs4(
716
+ "div",
717
+ {
718
+ className: cn(
719
+ "flex flex-1 justify-between leading-none",
720
+ nestLabel ? "items-end" : "items-center"
721
+ ),
722
+ children: [
723
+ /* @__PURE__ */ jsxs4("div", { className: "grid gap-1.5", children: [
724
+ nestLabel ? tooltipLabel : null,
725
+ /* @__PURE__ */ jsx6("span", { className: "text-muted-foreground", children: itemConfig?.label || item.name })
726
+ ] }),
727
+ item.value != null && /* @__PURE__ */ jsx6("span", { className: "text-foreground font-mono font-medium tabular-nums", children: typeof item.value === "number" ? item.value.toLocaleString() : String(item.value) })
728
+ ]
729
+ }
730
+ )
731
+ ] })
732
+ },
733
+ `${item.dataKey ?? index}`
734
+ );
735
+ }) })
736
+ ]
737
+ }
738
+ );
739
+ }
740
+ var ChartLegend = RechartsPrimitive.Legend;
741
+ function ChartLegendContent({
742
+ className,
743
+ hideIcon = false,
744
+ payload,
745
+ verticalAlign = "bottom",
746
+ nameKey
747
+ }) {
748
+ const { config } = useChart();
749
+ if (!payload?.length) {
750
+ return null;
751
+ }
752
+ return /* @__PURE__ */ jsx6(
753
+ "div",
754
+ {
755
+ className: cn(
756
+ "flex items-center justify-center gap-4",
757
+ verticalAlign === "top" ? "pb-3" : "pt-3",
758
+ className
759
+ ),
760
+ children: payload.filter((item) => item.type !== "none").map((item, index) => {
761
+ const key = `${nameKey || item.dataKey || "value"}`;
762
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
763
+ return /* @__PURE__ */ jsxs4(
764
+ "div",
765
+ {
766
+ className: "[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3",
767
+ children: [
768
+ itemConfig?.icon && !hideIcon ? /* @__PURE__ */ jsx6(itemConfig.icon, {}) : /* @__PURE__ */ jsx6(
769
+ "div",
770
+ {
771
+ className: "h-2 w-2 shrink-0 rounded-[2px]",
772
+ style: { backgroundColor: item.color }
773
+ }
774
+ ),
775
+ itemConfig?.label
776
+ ]
777
+ },
778
+ `${item.value ?? index}`
779
+ );
780
+ })
781
+ }
782
+ );
783
+ }
784
+ function getPayloadConfigFromPayload(config, payload, key) {
785
+ if (typeof payload !== "object" || payload === null) {
786
+ return void 0;
787
+ }
788
+ const payloadPayload = "payload" in payload && typeof payload.payload === "object" && payload.payload !== null ? payload.payload : void 0;
789
+ let configLabelKey = key;
790
+ if (key in payload && typeof payload[key] === "string") {
791
+ configLabelKey = payload[key];
792
+ } else if (payloadPayload && key in payloadPayload && typeof payloadPayload[key] === "string") {
793
+ configLabelKey = payloadPayload[key];
794
+ }
795
+ return configLabelKey in config ? config[configLabelKey] : config[key];
796
+ }
797
+
541
798
  // src/ui/shimmer.tsx
542
799
  import { motion } from "motion/react";
543
800
  import {
544
801
  memo,
545
- useMemo
802
+ useMemo as useMemo2
546
803
  } from "react";
547
- import { jsx as jsx6 } from "react/jsx-runtime";
804
+ import { jsx as jsx7 } from "react/jsx-runtime";
548
805
  var ShimmerComponent = ({
549
806
  children,
550
807
  as: Component = "p",
@@ -555,11 +812,11 @@ var ShimmerComponent = ({
555
812
  const MotionComponent = motion.create(
556
813
  Component
557
814
  );
558
- const dynamicSpread = useMemo(
815
+ const dynamicSpread = useMemo2(
559
816
  () => (children?.length ?? 0) * spread,
560
817
  [children, spread]
561
818
  );
562
- return /* @__PURE__ */ jsx6(
819
+ return /* @__PURE__ */ jsx7(
563
820
  MotionComponent,
564
821
  {
565
822
  animate: { backgroundPosition: "0% center" },
@@ -587,13 +844,22 @@ var Shimmer = memo(ShimmerComponent);
587
844
  export {
588
845
  cn,
589
846
  TIMBAL_V2_ELEVATED_GRADIENT,
847
+ TIMBAL_V2_MODAL_SURFACE,
590
848
  TIMBAL_V2_SWITCH_TRACK_OFF,
591
849
  TIMBAL_V2_SWITCH_THUMB,
592
850
  TIMBAL_V2_ELEVATED_SURFACE,
593
851
  TIMBAL_V2_SECONDARY_CHROME,
594
852
  TIMBAL_V2_LOGO_TILE,
595
853
  TimbalV2Button,
854
+ buttonVariants,
596
855
  Button,
856
+ CONTROL_SIZE,
857
+ controlSurfaceClass,
858
+ controlClass,
859
+ overlayAnimationClass,
860
+ overlaySurfaceClass,
861
+ overlayListPanelClass,
862
+ overlayItemClass,
597
863
  TooltipProvider,
598
864
  Tooltip,
599
865
  TooltipTrigger,
@@ -611,5 +877,12 @@ export {
611
877
  Avatar,
612
878
  AvatarImage,
613
879
  AvatarFallback,
880
+ useChart,
881
+ ChartContainer,
882
+ ChartStyle,
883
+ ChartTooltip,
884
+ ChartTooltipContent,
885
+ ChartLegend,
886
+ ChartLegendContent,
614
887
  Shimmer
615
888
  };