@timbal-ai/timbal-react 1.0.0 → 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 (40) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +45 -4
  3. package/dist/app.cjs +1996 -1183
  4. package/dist/app.d.cts +8 -4
  5. package/dist/app.d.ts +8 -4
  6. package/dist/app.esm.js +23 -6
  7. package/dist/{chart-artifact-CBo9x8Ch.d.ts → chart-artifact-BZp7nmaf.d.ts} +253 -12
  8. package/dist/{chart-artifact-DOkwSTjQ.d.cts → chart-artifact-CX-rh9nq.d.cts} +253 -12
  9. package/dist/{chat-Bed4FQSl.d.cts → chat-DCms8pJ_.d.cts} +31 -4
  10. package/dist/{chat-Bed4FQSl.d.ts → chat-DCms8pJ_.d.ts} +31 -4
  11. package/dist/chat.cjs +1088 -775
  12. package/dist/chat.d.cts +1 -1
  13. package/dist/chat.d.ts +1 -1
  14. package/dist/chat.esm.js +3 -3
  15. package/dist/{chunk-FOD67Z6G.esm.js → chunk-4AKJ6FKE.esm.js} +235 -4
  16. package/dist/{chunk-YEFBANNF.esm.js → chunk-6HWMJNZT.esm.js} +242 -288
  17. package/dist/{chunk-C6IXFM4T.esm.js → chunk-FRZOEYBO.esm.js} +4 -4
  18. package/dist/chunk-JEAUF54A.esm.js +52 -0
  19. package/dist/{chunk-AYHOVAMI.esm.js → chunk-P3KDAYX6.esm.js} +1 -1
  20. package/dist/{chunk-GLPOVYEA.esm.js → chunk-TK2AGIME.esm.js} +662 -274
  21. package/dist/{chunk-RZ6QC6RG.esm.js → chunk-XCM3V6RK.esm.js} +2 -2
  22. package/dist/{chunk-SNLXVG7H.esm.js → chunk-YXZ22OJN.esm.js} +849 -665
  23. package/dist/index.cjs +2558 -1789
  24. package/dist/index.d.cts +5 -5
  25. package/dist/index.d.ts +5 -5
  26. package/dist/index.esm.js +29 -11
  27. package/dist/pill-segmented-tabs-Ba5q0feL.d.cts +500 -0
  28. package/dist/pill-segmented-tabs-Ba5q0feL.d.ts +500 -0
  29. package/dist/studio.cjs +1310 -997
  30. package/dist/studio.d.cts +2 -2
  31. package/dist/studio.d.ts +2 -2
  32. package/dist/studio.esm.js +5 -5
  33. package/dist/styles.css +26 -0
  34. package/dist/ui.cjs +275 -37
  35. package/dist/ui.d.cts +71 -491
  36. package/dist/ui.d.ts +71 -491
  37. package/dist/ui.esm.js +22 -6
  38. package/dist/{welcome-COOb05a5.d.cts → welcome-CRqOPKMp.d.cts} +1 -1
  39. package/dist/{welcome-DE08m9ca.d.ts → welcome-DlHUa3OL.d.ts} +1 -1
  40. package/package.json +7 -3
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-RZ6QC6RG.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-SNLXVG7H.esm.js";
28
- import "./chunk-FOD67Z6G.esm.js";
27
+ } from "./chunk-YXZ22OJN.esm.js";
28
+ import "./chunk-4AKJ6FKE.esm.js";
29
29
  export {
30
30
  Composer,
31
31
  ComposerAddAttachment,
@@ -571,13 +571,237 @@ function AvatarFallback({
571
571
  );
572
572
  }
573
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
+
574
798
  // src/ui/shimmer.tsx
575
799
  import { motion } from "motion/react";
576
800
  import {
577
801
  memo,
578
- useMemo
802
+ useMemo as useMemo2
579
803
  } from "react";
580
- import { jsx as jsx6 } from "react/jsx-runtime";
804
+ import { jsx as jsx7 } from "react/jsx-runtime";
581
805
  var ShimmerComponent = ({
582
806
  children,
583
807
  as: Component = "p",
@@ -588,11 +812,11 @@ var ShimmerComponent = ({
588
812
  const MotionComponent = motion.create(
589
813
  Component
590
814
  );
591
- const dynamicSpread = useMemo(
815
+ const dynamicSpread = useMemo2(
592
816
  () => (children?.length ?? 0) * spread,
593
817
  [children, spread]
594
818
  );
595
- return /* @__PURE__ */ jsx6(
819
+ return /* @__PURE__ */ jsx7(
596
820
  MotionComponent,
597
821
  {
598
822
  animate: { backgroundPosition: "0% center" },
@@ -653,5 +877,12 @@ export {
653
877
  Avatar,
654
878
  AvatarImage,
655
879
  AvatarFallback,
880
+ useChart,
881
+ ChartContainer,
882
+ ChartStyle,
883
+ ChartTooltip,
884
+ ChartTooltipContent,
885
+ ChartLegend,
886
+ ChartLegendContent,
656
887
  Shimmer
657
888
  };